   Mathematics and Programming: Are they related in some way?
  You know about functions in mathematics:f(x) = x^2 + 3x + 2.Suppose, the f is a function name in a program language (C, C++, Java, C#, J#, F#, whatever you name it). The x stands for the parameter of the function f. And the formula that equals the function f in mathematics is the scope of the function in programming.Is this how Ada Lovelace convinced us the beginning of programming? Is mathematics such as this the origins of structured programming syntax?And that IF...THEN...ELSE logical summarization from the logics in mathematics also like how functions were set?And that variables are variables, arrays are arrays, 2D is two arrays used together, 3D = 3 arrays, etc.?And that the correlations between mathematics and programming are fundamental and the same?I'm just curious. Thanks in advance for your replies.   
  Programming is a branch of mathematics.At most fundamental level, the programming models and the way CPUs work, today's models are Turing machines or Finite state machines, as well as boolean algebra. Alternate model is Lambda calculus.Everything else is just abstraction for convenience of programmers.Quote:Is mathematics such as this the origins of structured programming syntax?Not in any particular way, structured programming was introduced merely for readability. It is not required in any way, nor does it bring any particular benefits to computers. Language syntax are just very high abstractions over FSMs, since billion-term boolean expressions are hard to read.   ;  I see some light of understanding in your eye, but you have a long journey yet to make, grasshopper....There is an entire branch of mathematics called "computer science" on which much to do with computer programming is based.Generally, an recognized expert in a specialized topic (a "Ph.D." which is the abbreviation for philosophiae doctor, a latin phrase meaning "teacher of philosophy") must first master the subject broadly (earning the recognition with a "Master's Degree").  In the case of computer science, the candidate would have to study a broad range of mathematical topics, including algebra.  It is no surprise, then, that when higher-level computer programming languages were invented in the 1950s some of them used algebraic notation to express basic concepts.The first high-level computer programming language, FORTRAN, was conceived mostly for the purpose of scientific number crunching (the language name is an acronym for FORmula TRANslator).  Many of the modern-day computer programming languages, including the C family (C, C++, C#, Java, &#106avascript, Python, etc) are descendants of FORTRAN.  The original FORTRAN did not have structured programming syntax, that came through a descendant known as Algol (an acronym for ALGOrithmic Language) developed by computer scientists in the 1960s.The second high-level computer programming language, LISP (an initialism for Lots of Idiotic Stupid Parentheses, or maybe an acronym for LISt Processing) is based on Church's lambda calculus.  It does not use algebraic notation at all.  It does not have if--then--else constructs or variables and arrays.  It is highly mathematical, but it turns out that there are multiple ways in mathematics to express exactly the same ideas.  That's OK, because there is generally a linear ontological function to transform one expression into another.  Programmers call those functions "compilers."Anyways, this is really the topic for one or more university-level courses and maybe there is a thesis lurking in it somewhere.   ;Quote:Original post by tom_mai78101Suppose, the f is a function name in a program languageImperative "functions" can be used to compute mathematical functions, but they can also have side-effects, which is impossible in mathematics. For example, the "function" printf makes no sense in mathematics.Quote:Original post by tom_mai78101And that variables are variablesMathematical variables are names for values. Imperative "variables" are names for memory locations. You can change imperative "variables" via assignment which is impossible in mathematics. From a mathematical perspective, x = x + 1 makes no sense whatsoever.Note that in purely functional programming languages like Haskell, the notions of "variable" and "function" correspond more or less to the mathematical ideas. You cannot change variables in Haskell, and functions cannot have side-effects in Haskell.   ;  To Bregma:I'm about to become a Computer Science freshman. But I have no idea that this field involves a lot of mathematics and stuffs...I thought that this (Computer Science) only teaches how to program and what to program and stuffs...:(   ;Quote:Original post by DevFredFrom a mathematical perspective, x = x + 1 makes no sense whatsoever.I once tried to explain this to a mathematician, and the only way to make him understand it was to define a variable as a sequence, and to interpret `x = x + 1' as `x_{n+1} = x_n + 1', and `a_{n+1} = a_n' for all other variables `a'. Although that's a bit verbose, a mathematician can understand it perfectly well.;Quote:Original post by tom_mai78101To Bregma:I'm about to become a Computer Science freshman. But I have no idea that this field involves a lot of mathematics and stuffs...I thought that this (Computer Science) only teaches how to program and what to program and stuffs...:("Computer Science" at many colleges is a catch-all name, and the contents of that major are usually samplings from various disciplines that an engineering school might make separate majors, such as:Software Engineering (closest to your concept of "learning how to program")Computer Engineering (more like an Electrical Engineering discipline, this is studies closer to the wire/board/chip...you may have some sort of digital circuits course)Computer Science (pure theory, math, and design: study of languages, AI, elegant solutions to mathematical problems, etc)What's your math background?  My department requires 2 semesters of calculus, a discrete math course, linear algebra, and two semesters of probability/statistics courses.  Though it stands to reason that when many Computer Science departments are subsections of the school's Math department, you'll get a few math courses :)   ;Quote:Original post by tom_mai78101To Bregma:I'm about to become a Computer Science freshman. But I have no idea that this field involves a lot of mathematics and stuffs...I thought that this (Computer Science) only teaches how to program and what to program and stuffs...:(Most of the time a strong ground in mathematics is very helpful. Soo from my experience the mathematics in the education is essential to a developer to become a professional. Since programming solves a problem that quite often is mathematically based one has to have at least an understanding of maths either to develop the solution one self, or be able to adapt existing solutions.;Quote:Original post by tom_mai78101To Bregma:I'm about to become a Computer Science freshman. But I have no idea that this field involves a lot of mathematics and stuffs...I thought that this (Computer Science) only teaches how to program and what to program and stuffs...:(I'm doing Computing (MEng) at university and had to get A in maths to get in. Of the 12 courses we've had this first year 5 have been on maths, logic and algorithms, and 4 have been on learning programming (Haskell, Java, Prolog and C).All schools are going to be different, and yours may have very less maths but don't go in expecting no maths at all.   ;Quote:Original post by alvaroQuote:Original post by DevFredFrom a mathematical perspective, x = x + 1 makes no sense whatsoever.I once tried to explain this to a mathematician, and the only way to make him understand it was to define a variable as a sequence, and to interpret `x = x + 1' as `x_{n+1} = x_n + 1', and `a_{n+1} = a_n' for all other variables `a'. Although that's a bit verbose, a mathematician can understand it perfectly well.Monads are a much more succinct and accurate solution for formally describing side effects.   