From CS2800 wiki
Revision as of 16:57, 18 February 2018 by {{GENDER:Mdg39|[math]'"2}} [/math]'"7
(<math>1) </math>2 | <math>3 (</math>4) | <math>5 (</math>6)

One way to combine functions together to create new functions is by composing them:

Definition: Composition
Given a function [math]f : A \href{/cs2800/wiki/index.php/%E2%86%92}{→} B [/math] and a function [math]g : B \href{/cs2800/wiki/index.php/%E2%86%92}{→} C [/math], the composition of [math]g [/math] with [math]f [/math] (written [math]g \href{/cs2800/wiki/index.php/%E2%88%98}{∘} f [/math]) is the function [math]g \href{/cs2800/wiki/index.php/%5Ccirc}{\circ} f : A \href{/cs2800/wiki/index.php/%E2%86%92}{→} C [/math] given by [math](g \href{/cs2800/wiki/index.php/%5Ccirc}{\circ} f)(a) := g(f(a)) [/math].

Note that (with the domains and codomains described above), [math]f \href{/cs2800/wiki/index.php/%5Ccirc}{\circ} g [/math] is not defined; it is impossible to take outputs of [math]g [/math] (which live in the set [math]C [/math]) and pass them into [math]f [/math] (whose domain is [math]A [/math]).

For example, Composition.svg

Note that this picture is not backwards; we draw functions from left to right (the input is on the left, and the output is on the right) but we apply them with the input on the right. This means the symbolic composition looks backwards when you draw a picture.