What is the difference between functions in math and functions in programming?

In functional programming you have Referential Transparency, which means that you can replace a function with its value without altering the program. This is true in Math too, but this is not always true in Imperative languages.

A math function is defined by: a relationship that maps elements from one set (A) to another (B), mapping each element of the first set with only one of the other set.
In C (as in other programming languages) this is also true, you have your input set, and your output set (which is almost always only ONE).

The main difference, is, then, that if you call f(x) in math, you will ALWAYS get the same answer, but if you call f'(x) in C, the answer may not be the same – the same arguments don’t always return the same output. A function in non-functional languages may not depend solely on the arguments you give them, but on other things in the program (enclosing scope, globals, builtins, state if you’re using object orientation).

Another difference between math and C functions, is that in Math you can’t make a function that goes from a non-empty set to an empty set (in C this would be: You aren’t requiered to always return something with your function). Also, not all function are computable (I don’t know if there’s something similiar to this in math..). You don’t have functions for infinite sets (you have finite memory, so the set of the possible input parameters must be finite), but in math, you can define a function for infinite sets (like f: N -> N) and for uncountable sets (like f: R -> R) (In C you have floating point numbers, but they only represent a reduced set of real numbers, which is finite).

Summarizing:

In C you don’t always have Referential Transparency. Your functions may not always give the same output for the same input parameters. You can have Math functions that defined for an infinite set of inputs, but in C functions your input is finite. In C functions you can have functions that returns nothing, but in Math you can’t have that (if you have a function that has a non empty input set, you must map each element with one of another set).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)