Algebra of functions

If you are familiar with mathematics, then this may be, in a sense, one of the newer topics. We have discussed algebraic expressions, but we can also perform function algebra. Recall that a function takes an argument and maps it to a value. For example, $\sin$ maps $\pi$ to the value $0$. Given two functions $f$ and $g$, we can define a new function $f + g$ where $(f + g)(x) = f(x) + g(x)$. What this says is that $f + g$ is a new function, and the value of this new function at a point $x$ is $f(x) + g(x)$. Similarly, we can define $fg$ to be the function such that $(fg)(x) = f(x) g(x)$ or $(3f)(x) = 3f(x)$.

Analogy with matrices

Recall that matrices are mappings of vectors onto vectors, and given a matrix $A:\mathcal{U} \rightarrow \mathcal{V}$ and a vector $\textbf{u} \in \mathcal{U}$, then the image is $A\textbf{u}$. The same way, if $f:\textbf{R} \rightarrow \textbf{R}$, then if $x \in \textbf{R}$ we denote the image as $f(x)$. Recall that we can perform matrix algebra: adding two matrices, multiplying a matrix by a scalar, and taking the composition of two matrices (the matrix-matrix product). We are looking at a similar algebra for functions, only in matrices, there is not a significance to an element-wise product of two vectors.

Function algebra

For example, we could now define a new function $f$ defined as $1 + sin^2$:

[> f := 1 + sin^2;

$f := sin^2 + 1$

[> f( 1 );

$sin(1)^2 + 1$

[> evalf( f( 1 ) );

$1.708073418$

Note that $fg$ is the product of the two functions, but you can also define composition:

[> g := (f@cos)*csc - 2;

$g := \left( \sin^2 + 1 \right )@\cos \csc - 2$

The @ operator implies composition of functions, just like $(f \circ g)(x) = f(g(x))$. Thus, $g(x)$ is the same as $f(\cos(x)) + csc(x) - 2$, and as $f$ has been previously defined as $\sin^2 + 1$, this evaluates to $(\sin(\cos(x)^2) + 1) \csc(x) - 2$:

[> g( 1.0 )

$-0.497152599$

[> evalf( (sin(cos(1))^2 + 1)*csc(1) - 2 );

$-0.497152599$

It is important to remember that $3$ is interpreted as an integer, but also as a function that maps any argument to the value $3$:

[> 3( Pi/2 );

$3$

This can and will cause confusion if you make a mistake in entering a product:

[> 3(x + 1)*(x + 2);

$3x + 6$

[> 3(x + 1)(x + 2);

$3$

In the first case, 3(x + 1) is interpreted as the constant function $3$ evaluated at $x + 1$, so we are left with 3*(x + 2), while in the second, after 3(x + 1) evaluates to $3$, then this becomes the function evaluated at $x + 2$.

Defining function

We can define a function in Maple using the right-arrow operator:

[> f := (x) -> x^3 + 4*x^2 + 3*x + 1;

$f := x \mapsto x^3 + 4x^2 + 3x + 1$

We can also define the identity function:

[> id := (x) -> x;

$f := x \mapsto x$

We can now define a polynomial using function algebra:

[> p := id^3 + 4*id^2 + 3*id + 1;

$p := id^3 + 4 id^2 + 3 id + 1$

[> p(1);

$9

You can also define multivariate functions:

[> saddle := (x, y) -> x*y;

$f := (x, y) \mapsto xy$