#header-inner {background-position: right !important; width: 100% !important;}

## 11/14/14

### What is a Function?

in Mathematics:

Let X,Y be any nonempty sets.

X is called function's domain, Y is called function's codomain.

def. function is assignment for each element in X an exactly one element in Y.

in Computer Sciences:

functions take n-arguments, which can be represented as one object (tuple), then assign returned value to this tuple of values.

all possible values of n-argument tuple are domain of a function, all possible returned values are codomain of a function.

if function's value also depends on other factors such as global variables, these factors can be assumed to be part of input of n-arguments.

- are Computer Sciences part of Mathematics?
- i think yes.

Function notations.

1. Mathematical formula.

y = x2, for x∈ {-2, -1, 0, 1, 2, 3, 4}.

2. Words.

There are sets X = { -2, -1, 0, 1, 2, 3, 4 }, Y = { 0, 1, 4, 9, 16 }. Then for each number from set X we assign a square of that a number.

3. Table.

 x -2 -1 0 1 2 3 4 y 4 1 0 1 4 9 16

4. Graph.

5. Ordered pairs set.

{(-2,4), (-1,1), (0,0), (1,1), (2,4), (3,9), (4,16)}.

in the above example of 'a function of the garden', pairs are: (coordinates, object).

6. Graph.

7. Computer program code.

int square(int x) {
if (inDomain(x) == false) { throw new RuntimeException("x = " + x + " not in domain"); };
return x * x;
};

boolean inDomain(int x) {
return ((x >= -2) && (x <= 4));
};

i think that 'Ola AH' programming language should have following syntax features:
- elegant domain clauses (because of function domains in Mathematics & functional programming paradigm, because of invariants & contract, perhaps more),
- optional 'function' keyword before function's signature line,
- multiple argument tuples both in return values, as well as in passed arguments.

code would look like:

function int square(int x) {
cd x inX; // cd is short for 'check domain'
return x * x;
};

dc inX(int x) { // dc is short for 'domain check'
return ((x >= -2) && (x <= 4));
};

another example:

function (int, int) myFunc (int x0, int x1) {
cd x0 inX; // cd is short for 'check domain'
cd x1 inX;
return (x0 * x1, -(x1 * x1));
};

Function equality.

Two functions f and g are equal when and only when their domains are equal, and when for the same arguments they are assigned equal values.

(to be elaborated, perhaps).

Source: [42], my partial education (unfinished MIM UW), my programming experience.

1. (EN) domain = (PL) dziedzina.
(EN) codomain = (PL) przeciwdziedzina.

2. (EN) tuple = (PL) krotka.

3. there is a problem:
all possible values of n-argument tuple are domain of a function, all possible returned values are codomain of a function.

it should be:
function's arguments and the current stack, heap, read data from os , interaction with other programs & threads, current time is the domain,
return value and the updated stack, heap, written data to os and other programs is the codomain.

there's a difference between math function and computer function. the functions you want to write in your programs are "effectively computable" (μ-recursive).

furthermore in computers science there's a notion of function time complexity.
you can easily describe with math's e.g a 3sat solver function. but in practice this function is slow for large inputs.

4. @Anonymous:

'all possible values of n-argument tuple are domain of a function, all possible returned values are codomain of a function.

it should be:
function's arguments and the current stack, heap, read data from os , interaction with other programs & threads, current time is the domain,
return value and the updated stack, heap, written data to os and other programs is the codomain.'

i've handled this in line:

'if function's value also depends on other factors such as global variables, these factors can be assumed to be part of input of n-arguments.'

let's note that returned value can also be n-argument tuple object.

5. @Anonymous:

if this is true:

'In mathematical logic and computer science, the μ-recursive functions are a class of partial functions from natural numbers to natural numbers that are "computable" in an intuitive sense. '

then i disagree with:

'the functions you want to write in your programs are "effectively computable" (μ-recursive).'

in Object Oriented Programming, any value, not only numbers can be function's arguments, as well as a return value. n-argument tuple is just a way of encapsulating them in one object which can be written as a 0-1 number string, for example using serialization.

6. @Anonymous:

'furthermore in computers science there's a notion of function time complexity.'

indeed.

there is difference, but in my opinion it's still useful to think in terms of Mathematics when Programming. but i am not sure (yet) about how this looks like from Mathematician's viewpoint.