APOLOGY: This question is asked by someone foreign to math, with the expectation that math.stackexchange can be a resource to (among other things) understand math concepts.
I'm a self-taught project-of programmer. I would like to understand "projection", beacuse it's used in functional programming (related to lamda calculus I hear), and in a database called MongoDB.
For the math term of projection Wikipedia links to "function composition", whose page in turn links to "pointwise".
The question is: What is “pointwise”, in the context of function composition?
So that (from wikipedia's "projection")
"In mathematics, a projection is a mapping of a set (or other mathematical structure) into a subset (or sub-structure), which is equal to its square for mapping composition (or, in other words, which is idempotent)."
Can be understood once (from wikipedia's "function composition"):
In mathematics, function composition is the pointwise application of one function to the result of another to produce a third function.
Is understood...
Thanks in advance.
Also, resources to material that can help with this kind of doubts are very much welcome
It means that the composition of $f$ and $g$ is defined as
$$(f \circ g)(x) = f\big(g(x)\big)$$
where $f$ is applied to the result of $g$ separately for each $x$, rather than applying $f$ globally to $g$ itself like this:
$$x \mapsto \big(f(g)\big)(x).$$
To give you an example, let $f(h) = x \mapsto \langle h(x), h(x) \rangle$ and define $g$ as $$ g(x) = \begin{cases} y \mapsto y+2 & \text{if } x = 0, \\ y \mapsto y\cdot 2 & \text{otherwise}. \end{cases} $$ Then $$(f \circ g)(x) = \begin{cases} y \mapsto \langle y+2, y+2 \rangle & \text{if } x = 0, \\ y \mapsto \langle y\cdot 2, y \cdot 2\rangle & \text{otherwise}, \end{cases} $$ while $$\big(f(g)\big)(x) = \begin{cases} \langle y \mapsto y+2, y \mapsto y+2 \rangle& \text{if } x = 0, \\ \langle y \mapsto y\cdot 2, y \mapsto y\cdot 2 \rangle & \text{otherwise}. \end{cases} $$
I hope this helps $\ddot\smile$
Edit: For programmers (in Python):
Now
compose(f, g)is equivalent tofg_compose, andf(g)is equivalent tofg_apply, that is, under most circumstancescompose(f,g)(x)should give you the same result asfg_compose(x), andf(g)(x)should give you same result asfg_apply(x).That being said, in programming few objects are pure, and while the corresponding ideal mathematical functions are equal, the execution paths in whatever language you are using are probably different, and so the final results might sometimes fail to match (the easiest example that comes to mind is that
compose(f,g)(x)probably uses more memory thanfg_compose(x)and so in the rightly contrived circumstances the former will fail while the latter might still work).