{VERSION 5 0 "IBM INTEL NT" "5.0" }
{USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0
1 0 0 0 0 1 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading
1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }1 0 0
0 8 4 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 2" 3 4 1 {CSTYLE "" -1 -1 ""
1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 8 2 0 0 0 0 0 0 -1 0 }
{PSTYLE "Title" 0 18 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 1 0 0 0 0
0 0 0 }3 0 0 -1 12 12 0 0 0 0 0 0 19 0 }{PSTYLE "Normal" -1 256 1
{CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0
0 1 0 1 0 2 2 0 1 }}
{SECT 0 {PARA 18 "" 0 "" {TEXT -1 20 "Programming in Maple" }}{PARA
256 "" 0 "" {TEXT -1 97 "Roger Kraft\nDepartment of Mathematics, Compu
ter Science, and Statistics\nPurdue University Calumet" }}{PARA 256 "
" 0 "" {TEXT -1 24 "roger@calumet.purdue.edu" }}{PARA 0 "" 0 "" {TEXT
-1 0 "" }}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 44 "1.4. Expressions vs. fu
nctions: Some puzzles" }}{PARA 0 "" 0 "" {TEXT -1 349 "The following e
xamples are meant to show that there are still a lot of subtle things \+
to learn about variables and functions and how Maple handles them. Do \+
not expect to fully understand these examples now. You should return t
o these examples after you have gone through the chapter on Maple's ev
aluation rules and the chapter on procedures in Maple." }}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{SECT 1 {PARA 4 "" 0 "" {TEXT
-1 8 "Puzzle 1" }}{PARA 0 "" 0 "" {TEXT -1 150 "Here is a subtle examp
le of a difference between an expression and a function. First we defi
ne a couple of expressions. The first is an expression in " }{TEXT 0
1 "x" }{TEXT -1 36 " and the second is an expression in " }{TEXT 0 1 "
y" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "f1 := x
^2+1;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "f2 := y^2+1;" }}}{PARA 0 "
" 0 "" {TEXT -1 76 "Now we add these two expressions and get an expres
sion in the two variables " }{TEXT 0 1 "x" }{TEXT -1 5 " and " }{TEXT
0 1 "y" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "f3
:= f1 + f2;" }}}{PARA 0 "" 0 "" {TEXT -1 145 " Now let us define a co
uple of Maple functions equivalent to the above expressions. Each of t
he next two functions is a function of one variable." }}{EXCHG {PARA
0 "> " 0 "" {MPLTEXT 1 0 17 "g1 := x -> x^2+1;" }}{PARA 0 "> " 0 ""
{MPLTEXT 1 0 17 "g2 := y -> y^2+1;" }}}{PARA 0 "" 0 "" {TEXT -1 50 "No
w add these two Maple functions. What do we get?" }}{EXCHG {PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 47 "g3 := g1 + g2; # What kind of function is g3
?" }}}{PARA 0 "" 0 "" {TEXT -1 4 "Is " }{TEXT 0 2 "g3" }{TEXT -1 34 "
a function of two variables like " }{TEXT 0 2 "f3" }{TEXT -1 118 " i
s an expression in two variables? Or is it a function of one variable?
The following command shows the formula for " }{TEXT 0 2 "g3" }{TEXT
-1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "g3(x);" }}}{PARA
0 "" 0 "" {TEXT -1 12 "So in fact, " }{TEXT 0 2 "g3" }{TEXT -1 41 " is
not a function of two variables like " }{TEXT 0 2 "f3" }{TEXT -1 35 "
is an expression in two unknowns; " }{TEXT 0 2 "g3" }{TEXT -1 150 " i
s a function of one variable. This shows that Maple functions and Mapl
e expressions handle unassigned variables in different ways. Let us \+
look at " }{TEXT 0 2 "g3" }{TEXT -1 51 " again. Here is another way to
see the formula for " }{TEXT 0 2 "g3" }{TEXT -1 1 "." }}{EXCHG {PARA
0 "> " 0 "" {MPLTEXT 1 0 6 "g3(y);" }}}{PARA 0 "" 0 "" {TEXT -1 19 "If
we try to treat " }{TEXT 0 2 "g3" }{TEXT -1 33 " as a function of two
variables, " }{TEXT 0 2 "g3" }{TEXT -1 34 " just ignores the second v
ariable." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "g3(w,z);" }}}
{PARA 0 "" 0 "" {TEXT -1 26 "Why is it that the sum of " }{TEXT 0 2 "f
1" }{TEXT -1 5 " and " }{TEXT 0 2 "f2" }{TEXT -1 40 " has two variable
s in it but the sum of " }{TEXT 0 2 "g1" }{TEXT -1 5 " and " }{TEXT 0
2 "g2" }{TEXT -1 10 " does not?" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT
1 0 0 "" }}}}{SECT 1 {PARA 4 "" 0 "" {TEXT -1 8 "Puzzle 2" }}{PARA 0 "
" 0 "" {TEXT -1 164 "There are two ways that a Maple expression can be
converted into a Maple function but these two ways are not equivalent
. Here is an example. First, make sure that " }{TEXT 0 1 "x" }{TEXT
-1 24 " is unassigned and give " }{TEXT 0 1 "a" }{TEXT -1 2 ", " }
{TEXT 0 1 "b" }{TEXT -1 6 ", and " }{TEXT 0 1 "c" }{TEXT -1 8 " values
." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "x:='x': a:=1: b:=2: c:=
3:" }}}{PARA 0 "" 0 "" {TEXT -1 22 "Here is an expression." }}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "a*x^2+b*x+c;" }}}{PARA 0 "" 0 ""
{TEXT -1 65 "Here is one way to convert this expression into a Maple f
unction." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "f := unapply( a*
x^2+b*x+c, x );" }}}{PARA 0 "" 0 "" {TEXT -1 90 "Here is another way. \+
Just use the expression on the right hand side of the arrow operator.
" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "g := x -> a*x^2+b*x+c;"
}}}{PARA 0 "" 0 "" {TEXT -1 12 "Notice that " }{TEXT 0 1 "f" }{TEXT
-1 29 " does not have the constants " }{TEXT 0 1 "a" }{TEXT -1 2 ", "
}{TEXT 0 1 "b" }{TEXT -1 6 ", and " }{TEXT 0 1 "c" }{TEXT -1 24 " in i
ts definition, but " }{TEXT 0 1 "g" }{TEXT -1 44 " does! Let us try ev
aluating both functions." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "
f(x); g(x);" }}}{PARA 0 "" 0 "" {TEXT -1 34 "Now they both have the va
lues for " }{TEXT 0 1 "a" }{TEXT -1 2 ", " }{TEXT 0 1 "b" }{TEXT -1 6
", and " }{TEXT 0 1 "c" }{TEXT -1 62 " in them. Let us try to differen
tiate each of these functions." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1
0 11 "D(f); D(g);" }}}{PARA 0 "" 0 "" {TEXT -1 30 "Notice that the der
ivative of " }{TEXT 0 1 "g" }{TEXT -1 59 " has the unevaluated constan
ts in it but the derivative of " }{TEXT 0 1 "f" }{TEXT -1 30 " has the
constants evaluated. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 ""
0 "" {TEXT -1 64 "Let us try changing one of the \"constants\". Change
the value of " }{TEXT 0 1 "c" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> "
0 "" {MPLTEXT 1 0 8 "c := 15;" }}}{PARA 0 "" 0 "" {TEXT -1 33 "Now eva
luate the functions again." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0
11 "f(x); g(x);" }}}{PARA 0 "" 0 "" {TEXT -1 31 " Notice that the defi
nition of " }{TEXT 0 1 "f" }{TEXT -1 39 " did not change, but the defi
nition of " }{TEXT 0 1 "g" }{TEXT -1 22 " did, when we changed " }
{TEXT 0 1 "c" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0
0 "" }}}}{SECT 1 {PARA 4 "" 0 "" {TEXT -1 8 "Puzzle 3" }}{PARA 0 "" 0
"" {TEXT -1 32 "First, let us give the variable " }{TEXT 0 1 "x" }
{TEXT -1 9 " a value." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "x :=
5;" }{TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 31 "Now try to plot th
e expression " }{TEXT 0 3 "x^2" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> "
0 "" {MPLTEXT 1 0 23 "plot( x^2, x=-10..10 );" }}}{PARA 0 "" 0 ""
{TEXT -1 61 "Maple returned an error (why?). Now try to plot the funct
ion " }{TEXT 0 6 "x->x^2" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 24 "plot( x->x^2, -10..10 );" }}}{PARA 0 "" 0 "" {TEXT
-1 56 "There is no problem with this, even though the variable " }
{TEXT 0 1 "x" }{TEXT -1 19 " still has a value." }}{EXCHG {PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 2 "x;" }}}{PARA 0 "" 0 "" {TEXT -1 147 "This shows
once again that there are subtle differences in the way that Maple tr
eats variables used in expressions and variables used in functions." }
}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 4 "" 0 "
" {TEXT -1 8 "Puzzle 4" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "res
tart;" }}}{PARA 0 "" 0 "" {TEXT -1 4 "Let " }{TEXT 0 1 "f" }{TEXT -1
31 " be the name for an expression." }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 9 "f := x^2;" }}}{PARA 0 "" 0 "" {TEXT -1 8 "Now use " }
{TEXT 0 1 "f" }{TEXT -1 13 " to redefine " }{TEXT 0 1 "f" }{TEXT -1 1
"." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "f := x*f;" }}}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "f;" }}}{PARA 0 "" 0 "" {TEXT -1 55 "
Let us try to do something similar with functions. Let " }{TEXT 0 1 "g
" }{TEXT -1 42 " be the name for a function equivalent to " }{TEXT 0
1 "f" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "g :=
x -> x^2;" }}}{PARA 0 "" 0 "" {TEXT -1 8 "Now use " }{TEXT 0 1 "g" }
{TEXT -1 13 " to redefine " }{TEXT 0 1 "g" }{TEXT -1 1 "." }}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "g := (x->x)*g;" }}}{EXCHG {PARA 0 "
> " 0 "" {MPLTEXT 1 0 5 "g(x);" }}}{PARA 0 "" 0 "" {TEXT -1 36 "Let us
try a slightly different way." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1
0 9 "g := 'g';" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "g := x -> x^2;" }
}}{PARA 0 "" 0 "" {TEXT -1 8 "Now use " }{TEXT 0 1 "g" }{TEXT -1 13 " \+
to redefine " }{TEXT 0 1 "g" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "
" {MPLTEXT 1 0 17 "g := x -> x*g(x);" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 5 "g(x);" }}}{PARA 0 "" 0 "" {TEXT -1 34 "There was no pr
oblem when we used " }{TEXT 0 1 "f" }{TEXT -1 13 " to redefine " }
{TEXT 0 1 "f" }{TEXT -1 20 ", but we cannot use " }{TEXT 0 1 "g" }
{TEXT -1 13 " to redefine " }{TEXT 0 1 "g" }{TEXT -1 128 ". This shows
that there are subtle differences in the way that Maple treats the na
mes of expressions and the names of functions." }}{EXCHG {PARA 0 "> "
0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 4 "" 0 "" {TEXT -1 8 "Puzzle \+
5" }}{PARA 0 "" 0 "" {TEXT -1 32 "Here is an anonymous expression." }}
{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "3-x^2;" }}}{PARA 0 "" 0 ""
{TEXT -1 26 "Now let us give it a name." }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 7 "f := %;" }}}{PARA 0 "" 0 "" {TEXT -1 50 "Now graph the
expression by referring to its name." }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 19 "plot( f, x=-3..3 );" }}}{PARA 0 "" 0 "" {TEXT -1 101
"Now let us try to do something similar with a Maple function. Here is
the anonymous expression again." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT
1 0 6 "3-x^2;" }}}{PARA 0 "" 0 "" {TEXT -1 56 "Use the anonymous expre
ssion to define a Maple function." }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 12 "g := x -> %;" }}}{PARA 0 "" 0 "" {TEXT -1 37 "But now
the following graph is empty." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1
0 17 "plot( g, -3..3 );" }}}{PARA 0 "" 0 "" {TEXT -1 63 "In this seque
nce of commands we used the last result variable, " }{TEXT 0 1 "%" }
{TEXT -1 59 ", twice. But the last result variable in the definition o
f " }{TEXT 0 1 "f" }{TEXT -1 76 " has a different meaning from the las
t result variable in the definition of " }{TEXT 0 1 "g" }{TEXT -1 33 "
, which is why the definition of " }{TEXT 0 1 "g" }{TEXT -1 214 " does
not work the way we might (reasonably) expect it to. Once again this \+
shows that we need to understand the details of exactly how Maple inte
rprets different kinds of variables in different kinds of situations.
" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 ""
{TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}}
{MARK "4 2 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1
2 33 1 1 }