A21-FunctionsAlgebraOff(x).mws

High School Modules > Algebra by Gregory A. Moore

     The Algebra of Functions


Combining functions by sums, products, differences, quotients, and compostion.

[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]

0. Code

>    restart; with(plots):

Warning, the name changecoords has been redefined

>    FuncOps  :=  proc( f, g, a, b )
     local N, M, P, i,j,k, A, p ;
     
     A := array( [seq( [
                  seq( ` `, j = 1..7 )
                       ],   i = a..b+1 )           ]);
     
     A[1,1] := `x`;   A[1,2] := `f(x)`;     A[1,3] := `g(x)`;
     A[1,4] := `f(x)+g(x)`;     A[1,5] := `f(x)-g(x)`;
     A[1,6] := `f(x)*g(x)`;     A[1,7] := `f(x)/g(x)`;
     
    for i from a to b do  A[i+1, 1] := i; od;
    for i from a to b do  A[i+1, 2] := f(i); od;
    for i from a to b do  A[i+1, 3] := g(i); od;
    for i from a to b do  A[i+1, 4] := f(i)+g(i); od;
    for i from a to b do  A[i+1, 5] := f(i)-g(i); od;
    for i from a to b do  A[i+1, 6] := f(i)*g(i); od;
    for i from a to b do  
        if( g(i) = 0) then A[i+1, 7] := `undef`;
                      else A[i+1, 7] := f(i)/g(i); fi; od;
       
     print(A);

 end proc:

>    FuncComp  :=  proc( f, g, a, b )
     local N, M, P, i,j,k, A, p ;
     
     A := array( [seq( [
                  seq( ` `, j = 1..3 )
                       ],   i = a..b+1 )           ]);
     
     A[1,1] := `x`;   A[1,2] := `g(x)`;     A[1,3] := `f(g(x))`;
     
     
    for i from a to b do  A[i+1, 1] := i; od;
    for i from a to b do  A[i+1, 2] := g(i); od;
    for i from a to b do  A[i+1, 3] := f(g(i)); od;
    
     print(A);

 end proc:

1. Arithmetic Operations on Functions - Algebraically


The four basic arithmetic operations of adding, subtracting, multiplying, and dividing, can be performed on functions in the same way one would perform these operations on numbers or expressons. Its pretty straight forward. When adding and subtracting you combine like terms.

>    f := x -> 3*x + 2;
g := x -> 8*x - 7;
`f(x) + g(x)` = f(x) + g(x);
`f(x) - g(x)` = f(x) - g(x);
`f(x) * g(x)` = f(x) * g(x);
`f(x) / g(x)` = f(x) / g(x);

f := proc (x) options operator, arrow; 3*x+2 end proc

g := proc (x) options operator, arrow; 8*x-7 end proc

`f(x) + g(x)` = 11*x-5

`f(x) - g(x)` = -5*x+9

`f(x) * g(x)` = (3*x+2)*(8*x-7)

`f(x) / g(x)` = (3*x+2)/(8*x-7)

>    f := x -> x;
g := x -> 1/x;
`f(x) + g(x)` = f(x) + g(x);
`f(x) - g(x)` = f(x) - g(x);
`f(x) * g(x)` = f(x) * g(x);
`f(x) / g(x)` = f(x) / g(x);

f := proc (x) options operator, arrow; x end proc

g := proc (x) options operator, arrow; 1/x end proc

`f(x) + g(x)` = x+1/x

`f(x) - g(x)` = x-1/x

`f(x) * g(x)` = 1

`f(x) / g(x)` = x^2

>    f := x -> x^2 - 6*x + 13;
g := x -> x^2 + 9*x - 22;
`f(x) + g(x)` = f(x) + g(x);
`f(x) - g(x)` = f(x) - g(x);
`f(x) * g(x)` = f(x) * g(x);
`f(x) / g(x)` = f(x) / g(x);

f := proc (x) options operator, arrow; x^2-6*x+13 end proc

g := proc (x) options operator, arrow; x^2+9*x-22 end proc

`f(x) + g(x)` = 2*x^2+3*x-9

`f(x) - g(x)` = -15*x+35

`f(x) * g(x)` = (x^2-6*x+13)*(x^2+9*x-22)

`f(x) / g(x)` = (x^2-6*x+13)/(x^2+9*x-22)

2. Arithmetic Operations on Functions - Numerically


Lets look at how these operations affect the the numerical values.

>    f := x -> 2*x ; g := x -> 3*x;
FuncOps(f, g, 1, 5);


f := proc (x) options operator, arrow; 2*x end proc

g := proc (x) options operator, arrow; 3*x end proc

matrix([[x, `f(x)`, `g(x)`, `f(x)+g(x)`, `f(x)-g(x)`, `f(x)*g(x)`, `f(x)/g(x)`], [1, 2, 3, 5, -1, 6, 2/3], [2, 4, 6, 10, -2, 24, 2/3], [3, 6, 9, 15, -3, 54, 2/3], [4, 8, 12, 20, -4, 96, 2/3], [5, 10, 1...

>    f := x -> 2*x + 3 ; g := x -> -4*x + 20;   FuncOps(f, g, 1, 5);

f := proc (x) options operator, arrow; 2*x+3 end proc

g := proc (x) options operator, arrow; -4*x+20 end proc

matrix([[x, `f(x)`, `g(x)`, `f(x)+g(x)`, `f(x)-g(x)`, `f(x)*g(x)`, `f(x)/g(x)`], [1, 5, 16, 21, -11, 80, 5/16], [2, 7, 12, 19, -5, 84, 7/12], [3, 9, 8, 17, 1, 72, 9/8], [4, 11, 4, 15, 7, 44, 11/4], [5,...

>    f := x -> x ; g := x -> 1/x;   FuncOps(f, g, 1, 6);

f := proc (x) options operator, arrow; x end proc

g := proc (x) options operator, arrow; 1/x end proc

matrix([[x, `f(x)`, `g(x)`, `f(x)+g(x)`, `f(x)-g(x)`, `f(x)*g(x)`, `f(x)/g(x)`], [1, 1, 1, 2, 0, 1, 1], [2, 2, 1/2, 5/2, 3/2, 1, 4], [3, 3, 1/3, 10/3, 8/3, 1, 9], [4, 4, 1/4, 17/4, 15/4, 1, 16], [5, 5,...

>    f := x -> x^2 + 3*x + 2 ; g := x -> x^2 -5*x + 7;   FuncOps(f, g, 1, 6);

f := proc (x) options operator, arrow; x^2+3*x+2 end proc

g := proc (x) options operator, arrow; x^2-5*x+7 end proc

matrix([[x, `f(x)`, `g(x)`, `f(x)+g(x)`, `f(x)-g(x)`, `f(x)*g(x)`, `f(x)/g(x)`], [1, 6, 3, 9, 3, 18, 2], [2, 12, 1, 13, 11, 12, 12], [3, 20, 1, 21, 19, 20, 20], [4, 30, 3, 33, 27, 90, 10], [5, 42, 7, 4...

>    f := x -> abs(x-3) ; g := x -> abs(x-5);   FuncOps(f, g, 1, 7);

f := proc (x) options operator, arrow; abs(x-3) end proc

g := proc (x) options operator, arrow; abs(x-5) end proc

matrix([[x, `f(x)`, `g(x)`, `f(x)+g(x)`, `f(x)-g(x)`, `f(x)*g(x)`, `f(x)/g(x)`], [1, 2, 4, 6, -2, 8, 1/2], [2, 1, 3, 4, -2, 3, 1/3], [3, 0, 2, 2, -2, 0, 0], [4, 1, 1, 2, 0, 1, 1], [5, 2, 0, 2, 2, 0, un...

3. Arithmetic Operations on Functions - Graphically


Just for fun, lets look at how these operations affect the graphs.

Example 1


Here are two functions. We will graph the functions along with their sums, differences, product, and quotient.

>    f := x -> 20;
g := x -> x;

f := 20

g := proc (x) options operator, arrow; x end proc

>    r := y = -30..30:
A := plot( { f(x), g(x) },  x = -5..5, r, color = black, thickness = 1):
Bp := plot( f(x)+g(x),  x = -5..5, r,  color = blue, thickness = 2):
Bm := plot( {f(x)-g(x), g(x)-f(x)},  x = -5..5, r,  color = green, thickness = 2):
Cp := plot( f(x)*g(x),  x = -5..5, r, color = red, thickness = 2):
Cm := plot( f(x)/g(x),  x = -5..5, r, color = gold, thickness = 2, discont = true):


The origial functions are in black and thin. The sum is blued, and differences, f-g and g-f are  green.

>    plots[display](A,Bp,Bm);

[Maple Plot]


The origial functions are in black and thin. The product is red, and quotient is gold.

>    plots[display](A,Cp,Cm);

[Maple Plot]

Example 2


Here are two functions. We will graph the functions along with their sums, differences, product, and quotient.

>    f := x -> 3*x;
g := x -> 2*x;

f := proc (x) options operator, arrow; 3*x end proc

g := proc (x) options operator, arrow; 2*x end proc

>    r := y = -20..20:
A := plot( { f(x), g(x) },  x = -5..5, r, color = black, thickness = 1):
Bp := plot( f(x)+g(x),  x = -5..5, r,  color = blue, thickness = 2):
Bm := plot( {f(x)-g(x), g(x)-f(x)},  x = -5..5, r,  color = green, thickness = 2):
Cp := plot( f(x)*g(x),  x = -5..5, r, color = red, thickness = 2):
Cm := plot( f(x)/g(x),  x = -5..5, r, color = gold, thickness = 2, discont = true):


The origial functions are in black and thin. The sum is blued, and differences, f-g and g-f are  green.

>    plots[display](A,Bp,Bm);

[Maple Plot]


The origial functions are in black and thin. The product is red, and quotient is gold.

>    plots[display](A,Cp,Cm);

[Maple Plot]

Example 3


Here are two functions. We will graph the functions along with their sums, differences, product, and quotient.

>    f := x -> x;
g := x -> floor(x);

f := proc (x) options operator, arrow; x end proc

g := floor

>    r := y = -10..10:
A := plot( { f(x), g(x) },  x = -5..5, r, color = black, thickness = 1):
Bp := plot( f(x)+g(x),  x = -5..5, r,  color = blue, thickness = 2):
Bm := plot( {f(x)-g(x), g(x)-f(x)},  x = -5..5, r,  color = green, thickness = 2):
Cp := plot( f(x)*g(x),  x = -5..5, r, color = red, thickness = 2):
Cm := plot( f(x)/g(x),  x = -5..5, r, color = gold, thickness = 2, discont = true):


The origial functions are in black and thin. The sum is blued, and differences, f-g and g-f, are  green.

>    plots[display](A,Bp,Bm);

[Maple Plot]


The origial functions are in black and thin. The product is red, and quotient is gold.

>    plots[display](A,Cp,Cm);

[Maple Plot]

Example 4


Here are two functions. We will graph the functions along with their sums, differences, product, and quotient.

>    f := x -> 11*x^2 - 6*x + 13;
g := x -> 8*x^2 + 19*x - 41;

f := proc (x) options operator, arrow; 11*x^2-6*x+13 end proc

g := proc (x) options operator, arrow; 8*x^2+19*x-41 end proc

>    r := y = -60..80:
A := plot( { f(x), g(x) },  x = -5..5, r, color = black, thickness = 1):
Bp := plot( f(x)+g(x),  x = -5..5, r,  color = blue, thickness = 2):
Bm := plot( {f(x)-g(x), g(x)-f(x)},  x = -5..5, r,  color = green, thickness = 2):
Cp := plot( f(x)*g(x),  x = -5..5, r, color = red, thickness = 2):
Cm := plot( f(x)/g(x),  x = -5..5, r, color = gold, thickness = 2, discont = true):


The origial functions are in black and thin. The sum is blued, and differences, f-g and g-f are  green.

>    plots[display](A,Bp,Bm);

[Maple Plot]


The origial functions are in black and thin. The product is red, and quotient is gold.

>    plots[display](A,Cp,Cm);

[Maple Plot]

4. Composite Functions - Numeric & Algebraic Approach


    The Idea of Composite Functions

To compose functions means to evaluate one function, and then take that output as the input for the next function. In a sense, the functions are applied serially. This is not an arithmetic operation. In the operations of addition, subtraction, multiplication, and division we looked above, the values of each function were computed and then the operation performed. In this case, its as though one function is embedded into the other.

>    f := x -> 2*x  + 1; g := x -> 3*x - 7;

f := proc (x) options operator, arrow; 2*x+1 end proc

g := proc (x) options operator, arrow; 3*x-7 end proc

>    g(1);

-4

>    f(%);

-7

>    `f(g(1))` = f(g(1));

`f(g(1))` = -7


We find f(g(10)) by computing g(10) = 23, and then computing f(23). Lets try some more examples.

>    f := x -> 2*x  + 1; g := x -> 3*x - 7;
g( 0 ); `g(0)` = %; `f(g(0))` = f(%%);

f := proc (x) options operator, arrow; 2*x+1 end proc

g := proc (x) options operator, arrow; 3*x-7 end proc

-7

`g(0)` = -7

`f(g(0))` = -13

>    f := x -> 13*x + 7; g := x -> 1/(x+2);
g( 4 ); `g(4)` = %; `f(g(4))` = f(%%);

f := proc (x) options operator, arrow; 13*x+7 end proc

g := proc (x) options operator, arrow; 1/(x+2) end proc

1/6

`g(4)` = 1/6

`f(g(4))` = 55/6


    The Idea of Composite Functions - Tables



To compose functions means to evaluate one function, and then take that output as the input for the other. In a sense, the functions are applied serially. This is not an arithmetic operation. In the operations of addition, subtraction, multiplication, and division

>    f:= x->3*x;       g:= x-> 2*x;   FuncComp( f,g, 1,10);

f := proc (x) options operator, arrow; 3*x end proc

g := proc (x) options operator, arrow; 2*x end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 2, 6], [2, 4, 12], [3, 6, 18], [4, 8, 24], [5, 10, 30], [6, 12, 36], [7, 14, 42], [8, 16, 48], [9, 18, 54], [10, 20, 60]])

>    f:= x-> 4*x - 7;  g:= x-> 3*x + 2;   FuncComp( f,g, 1,10);

f := proc (x) options operator, arrow; 4*x-7 end proc

g := proc (x) options operator, arrow; 3*x+2 end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 5, 13], [2, 8, 25], [3, 11, 37], [4, 14, 49], [5, 17, 61], [6, 20, 73], [7, 23, 85], [8, 26, 97], [9, 29, 109], [10, 32, 121]])

>    f:= x-> 10*x;       g:= x-> x^2 ;   FuncComp( f,g, 1,8);

f := proc (x) options operator, arrow; 10*x end proc

g := proc (x) options operator, arrow; x^2 end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 1, 10], [2, 4, 40], [3, 9, 90], [4, 16, 160], [5, 25, 250], [6, 36, 360], [7, 49, 490], [8, 64, 640]])

>   

 
   Simplifying Composite Functions


When composing functions, its often necessary to do a little algebra to simplify the result.

>    f := x -> (x+1)^2 ; g := x -> 4 + 7/x;
f(g(x)): % = expand(%);

f := proc (x) options operator, arrow; (x+1)^2 end proc

g := proc (x) options operator, arrow; 4+7/x end proc

(5+7/x)^2 = 25+70/x+49/x^2

>    f := x -> x^2 + 2 ; g := x -> 5*x + 11;
f(g(x)): % = expand(%);

f := proc (x) options operator, arrow; x^2+2 end proc

g := proc (x) options operator, arrow; 5*x+11 end proc

(5*x+11)^2+2 = 25*x^2+110*x+123


   Self-Composite Functions


When you compose two functions, there is nothing stopping you from composing a function with itself!

>    f := x -> 20*x - 33;
f(f(x));

f := proc (x) options operator, arrow; 20*x-33 end proc

400*x-693

>    g := x -> (x+1)/(x+2);
g(g(x)); simplify( expand(%));

g := proc (x) options operator, arrow; (x+1)/(x+2) end proc

((x+1)/(x+2)+1)/((x+1)/(x+2)+2)

(2*x+3)/(3*x+5)


 

5. Composition is NOT Commuative (in general)


Addition and multiplication of functions is commutative - which means that a different order gives the same results.

>    f := x -> 5*x + 11 ; g := x -> (x-2)/(x+7);
`(f+g)(1)`=f(1) + g(1),   `(g+f)(1)`=g(1) + f(1);
`(f*g)(1)`=f(1) * g(1),   `(g*f)(1)`=g(1) * f(1);

f := proc (x) options operator, arrow; 5*x+11 end proc

g := proc (x) options operator, arrow; (x-2)/(x+7) end proc

`(f+g)(1)` = 127/8, `(g+f)(1)` = 127/8

`(f*g)(1)` = -2, `(g*f)(1)` = -2


However, composition of functions is usually NOT commutative. If you change the order of composition from f(g(x)) to g(f(x)), you usually get different values. Lets try out some numbers.

>    `f(g(1))` = f(g(1));       `g(f(1))` = g(f(1));  

`f(g(1))` = 83/8

`g(f(1))` = 14/23

>    `(f+g)(3)`=f(3) + g(3),   `(g+f)(3)`=g(3) + f(3);
`(f*g)(3)`=f(3) * g(3),   `(g*f)(3)`=g(3) * f(3);
`f(g(3))` = f(g(3)),      `g(f(3))` = g(f(3));

`(f+g)(3)` = 261/10, `(g+f)(3)` = 261/10

`(f*g)(3)` = 13/5, `(g*f)(3)` = 13/5

`f(g(3))` = 23/2, `g(f(3))` = 8/11

>    `(f+g)(0)`=f(0) + g(0),   `(g+f)(3)`=g(0) + f(0);
`(f*g)(0)`=f(0) * g(0),  `(g*f)(3)`=g(0) * f(0);
`f(g(0))` = f(g(0)),      `g(f(0))` = g(f(0));  

`(f+g)(0)` = 75/7, `(g+f)(3)` = 75/7

`(f*g)(0)` = -22/7, `(g*f)(3)` = -22/7

`f(g(0))` = 67/7, `g(f(0))` = 1/2


Compare these two tables - same two functions, same domain. But the final results are different!

>    f:= x-> 10*x;       g:= x-> x^2 ;   
FuncComp( f,g, 1,8);   FuncComp( g,f, 1,8);   

f := proc (x) options operator, arrow; 10*x end proc

g := proc (x) options operator, arrow; x^2 end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 1, 10], [2, 4, 40], [3, 9, 90], [4, 16, 160], [5, 25, 250], [6, 36, 360], [7, 49, 490], [8, 64, 640]])

matrix([[x, `g(x)`, `f(g(x))`], [1, 10, 100], [2, 20, 400], [3, 30, 900], [4, 40, 1600], [5, 50, 2500], [6, 60, 3600], [7, 70, 4900], [8, 80, 6400]])

>    f:= x-> x^2;       g:= x-> x + 10 ;   
FuncComp( f,g, 1,8);   FuncComp( g,f, 1,8);

f := proc (x) options operator, arrow; x^2 end proc

g := proc (x) options operator, arrow; x+10 end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 11, 121], [2, 12, 144], [3, 13, 169], [4, 14, 196], [5, 15, 225], [6, 16, 256], [7, 17, 289], [8, 18, 324]])

matrix([[x, `g(x)`, `f(g(x))`], [1, 1, 11], [2, 4, 14], [3, 9, 19], [4, 16, 26], [5, 25, 35], [6, 36, 46], [7, 49, 59], [8, 64, 74]])

>    f:= x-> 10;       g:= x-> x^2 ;   
FuncComp( f,g, 1,8);   FuncComp( g,f, 1,8);

f := 10

g := proc (x) options operator, arrow; x^2 end proc

matrix([[x, `g(x)`, `f(g(x))`], [1, 1, 10], [2, 4, 10], [3, 9, 10], [4, 16, 10], [5, 25, 10], [6, 36, 10], [7, 49, 10], [8, 64, 10]])

matrix([[x, `g(x)`, `f(g(x))`], [1, 10, 100], [2, 10, 100], [3, 10, 100], [4, 10, 100], [5, 10, 100], [6, 10, 100], [7, 10, 100], [8, 10, 100]])



We can see this algebraically also.

>    f := x -> 5*x + 11 ; g := x -> (x-2)/(x+7);
f(g(x)):  `f(g(x))` = %; simplify( expand( %%) );
g(f(x)):  `g(f(x))` = %; simplify( expand( %%) );

f := proc (x) options operator, arrow; 5*x+11 end proc

g := proc (x) options operator, arrow; (x-2)/(x+7) end proc

`f(g(x))` = 5*(x-2)/(x+7)+11

(16*x+67)/(x+7)

`g(f(x))` = (5*x+9)/(5*x+18)

(5*x+9)/(5*x+18)

>    f := x -> x^2 + 10*x - 7 ; g := x -> x^2 -10*x + 7;
f(g(x)):  `f(g(x))` = %; simplify( expand( %%) );
g(f(x)):  `g(f(x))` = %; simplify( expand( %%) );

f := proc (x) options operator, arrow; x^2+10*x-7 end proc

g := proc (x) options operator, arrow; x^2-10*x+7 end proc

`f(g(x))` = (x^2-10*x+7)^2+10*x^2-100*x+63

x^4-20*x^3+124*x^2-240*x+112

`g(f(x))` = (x^2+10*x-7)^2-10*x^2-100*x+77

x^4+20*x^3+76*x^2-240*x+126

>    f := x -> x^3 + x ; g := x -> 1/(x+10);
f(g(x)):  `f(g(x))` = %; simplify( expand( %%) );
g(f(x)):  `g(f(x))` = %; simplify( expand( %%) );

f := proc (x) options operator, arrow; x^3+x end proc

g := proc (x) options operator, arrow; 1/(x+10) end proc

`f(g(x))` = 1/((x+10)^3)+1/(x+10)

(101+x^2+20*x)/(x+10)^3

`g(f(x))` = 1/(x^3+x+10)

1/(x^3+x+10)

6. Composite Functions - Repeated Composition [Optional]


An interesting thing sometimes happens when you evaluate a function, then take the output and evaluate it again with the same function, over and over.

>    f := x -> x/3 + 7;

f := proc (x) options operator, arrow; 1/3*x+7 end proc

>    f(0); (f@f)(0); (f@@3)(0);

7

28/3

91/9


Look at what happens at 20 iterations of f(x) at x = 0. The values appear to approach a particular value.

>    for k from 1 to 20 do evalf( (f@@k)(0) ); od;

7.

9.333333333

10.11111111

10.37037037

10.45679012

10.48559671

10.49519890

10.49839963

10.49946654

10.49982218

10.49994073

10.49998024

10.49999341

10.49999780

10.49999927

10.49999976

10.49999992

10.49999997

10.49999999

10.50000000

>    f := x -> (x^2) - x + 2/3;
for k from 1 to 12 do evalf( (f@@k)(0) ); od;

f := proc (x) options operator, arrow; x^2-x+2/3 end proc

.6666666667

.4444444444

.4197530864

.4231062338

.4225793179

.4226606287

.4226480450

.4226499916

.4226496905

.4226497371

.4226497298

.4226497310


In other cases, the values bounce back and forth, or converge to two different values.

>    f := x -> (x^2) - 1;
for k from 1 to 10 do evalf( (f@@k)(0) ); od;

f := proc (x) options operator, arrow; x^2-1 end proc

-1.

0.

-1.

0.

-1.

0.

-1.

0.

-1.

0.

>    f := x -> (x^2) - 9/10;
for k from 1 to 12 do evalf( (f@@k)(0) ); od;

f := proc (x) options operator, arrow; x^2-9/10 end proc

-.9000000000

-.9000000000e-1

-.8919000000

-.1045143900

-.8890767423

-.1095425463

-.8880004305

-.1114552354

-.8875777305

-.1122057723

-.8874098647

-.1125037321


 


         © 2002 Waterloo Maple Inc