{VERSION 2 3 "SUN SPARC SOLARIS" "2.3" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "Hyperlink" -1 17 "" 0 1 0 128 128 1 0 0 1 0 0 0 0 0 0 } {CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "2 D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 0 21 "" 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 }{CSTYLE "Help Heading" -1 26 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 }{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 -1 -1 -1 0 0 0 0 0 0 -1 0 } {PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 0 }1 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 }1 0 0 0 6 6 0 0 0 0 0 0 -1 0 }{PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Error" 7 8 1 {CSTYLE "" -1 -1 "" 0 1 255 0 255 1 0 0 0 0 0 0 0 0 0 } 0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {PARA 0 "" 0 "" {TEXT -1 0 "" }}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 8 "Advice: " }{TEXT -1 36 "Singularities in piecewise functions" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 140 "With few exceptions, Maple evaluates the arguments to a function before the fu nction itself is called. In particular, this happens for the " } {MPLTEXT 0 21 9 "piecewise" }{TEXT -1 131 " function. Thus, even thou gh the result is only the first case corresponding to a true condition , all the cases will be evaluated." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 109 "One situation where this behaviour can c ause errors is when one of the cases has a singularity. For example: " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "f:= x -> piecewise(x < 1 , 1, 1/x):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(0);" }} {PARA 8 "" 1 "" {TEXT -1 30 "Error, (in f) division by zero" }}}{PARA 0 "" 0 "" {TEXT -1 3 "At " }{XPPEDIT 18 0 "x=0" "/%\"xG\"\"!" }{TEXT -1 15 " the condition " }{XPPEDIT 18 0 "x < 1" "2%\"xG\"\"\"" }{TEXT -1 13 " is true, so " }{MPLTEXT 0 21 4 "f(0)" }{TEXT -1 51 " might be \+ expected to evaluate to 1. However, the " }{MPLTEXT 0 21 3 "1/x" } {TEXT -1 25 " is still evaluated with " }{MPLTEXT 0 21 1 "x" }{TEXT -1 13 " replaced by " }{MPLTEXT 0 21 1 "0" }{TEXT -1 77 ", and this pr oduces the error. One way to work around the problem is to use " } {MPLTEXT 0 21 9 "traperror" }{TEXT -1 24 " to intercept the error." }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "f:= x -> piecewise(x < 1, 1, traperror(1/x)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(0);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{PARA 0 "" 0 "" {TEXT -1 99 "This may not be a completely satisfactory solution, however. It i s still not possible to evaluate " }{MPLTEXT 0 21 4 "f(x)" }{TEXT -1 21 " and then substitute " }{MPLTEXT 0 21 3 "x=0" }{TEXT -1 10 ", beca use " }{MPLTEXT 0 21 4 "f(x)" }{TEXT -1 14 " evaluates to " }{XPPEDIT 18 0 "piecewise(x < 1, 1, 1/x)" "-%*piecewiseG6%2%\"xG\"\"\"\"\"\"*&\" \"\"\"\"\"F&!\"\"" }{TEXT -1 6 " (the " }{MPLTEXT 0 21 3 "1/x" }{TEXT -1 36 " evaluates without an error, and so " }{MPLTEXT 0 21 9 "traperr or" }{TEXT -1 209 " has no effect). Moreover, this method won't help \+ if you really want to avoid evaluating all the cases (e.g. if the calc ulations involved would be very time-consuming). An alternative is to avoid the use of " }{MPLTEXT 0 21 9 "piecewise" }{TEXT -1 40 ", inste ad defining a procedure using an " }{MPLTEXT 0 21 2 "if" }{TEXT -1 14 " statement. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 75 "f:= x -> \+ if not type(x,constant) then 'f(x)' elif x < 1 then 1 else 1/x fi:" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(0);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{PARA 0 "" 0 "" {TEXT -1 30 "Note that the f irst condition " }{MPLTEXT 0 21 20 "not type(x,constant)" }{TEXT -1 31 " is needed to allow the use of " }{MPLTEXT 0 21 4 "f(x)" }{TEXT -1 6 " when " }{MPLTEXT 0 21 1 "x" }{TEXT -1 53 " is a symbolic variab le or expression, for which the " }{MPLTEXT 0 21 5 "x < 1" }{TEXT -1 34 " test would not return a value of " }{XPPEDIT 18 0 "true" "I%trueG 6\"" }{TEXT -1 4 " or " }{XPPEDIT 18 0 "false" "I&falseG6\"" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(x);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%\"fG6#%\"xG" }}}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{PARA 3 "" 0 "" {TEXT -1 0 "" }}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 9 "See also:" }{TEXT -1 1 " " }{HYPERLNK 17 "if" 2 "if" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "piecewise" 2 "piecewise" "" }{TEXT -1 2 ", " } {HYPERLNK 17 "traperror" 2 "traperror" "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 24 "Maple Advisor Database, " }{TEXT -1 15 " R. Israel 1997" }}}}{MARK "1 10 12" 198 }{VIEWOPTS 1 1 0 3 2 1804 }