Functions
It's a brand-new day at the cube-painting factory! But, unfortunately, the company just bought a new machine that does the work much faster. The process of using this machine is simple:
- A cube is put on its belt
- The machine's internals paint the cube
- The painted cube comes out

The cube is an input to the machine. The machine performs an internal process and then outputs the painted cube.
This simple example illustrates the concept of a function: a mathematical representation of a “process”. Functions are broad and can be used to describe a wide variety of things:
seed -> plant(seed) -> tree
dough -> bake(dough) -> bread
...
Or, more generally, in mathematics, a function (or process) receives an input and produces an output .
given the input
such that and
Composition
But now, imagine that we want to upgrade the simplicity of our process with automated texturing of the cubes, how can our machine do that? With another machine! The company just bought a new texturing machine that will:
- Pick the painted cube
- The machine's internals drill a texture in it
- The painted and textured cube comes out

By adding this new machine sequentially after the first one our product just became better, and, talking about functions, this means that functions can be used for composition:
given the input , a function and a second function
first
and then
or, this is better represented by
Notice that g(f(x)) means “apply f first, then apply g to the result.”
And compositions are really powerful. A big problem can be broken down into a sequence of smaller and more specialized functions, like a real factory!
Want to build an airplane? There's a bunch of steps that need to be made.
Gather the material, Do a blueprint, Create the parts, assemble, do tests and then fly
or written in more function-like notation:
fly ( test ( assemble ( create ( blueprint ( gather ( idea ) )))))
A similar process can be made with functions
It's better to specialize at each step rather than try to do it all together
Multi-variables
Functions can also take more than one input.
Imagine that our machine receives some paint color (orange, blue, ...) and a type of object (cube, sphere, ...). For each combination it must perform its task accordingly:
The number of inputs can theoretically be infinite, but in practice, functions usually have a finite number of inputs, which can vary depending on the task.
Coding
Most programming languages take advantage of the concept of functions because they provide abstraction and make code more reusable, speeding up the development process.
If you want to add two values, you can simply create a function and reuse it as many times as needed:
function add(a, b):
return a + b
even composition is easy to use
function sub(a, b):
b = -b
return add(a, b)
This is fundamental for computer science.
But what if we want to create functions that can solve much more complex problems (understand and generate language, classify an image, ...) or solve problems where we don't even know all the rules ourselves?
That's where AI and machine learning come in.