home *** CD-ROM | disk | FTP | other *** search
- 7. Examples
-
- In the following examples, a line of "Input:" means that
- typing the program in the Editor, then leaving the Editor by <Esc>,
- finally running the program by the command "Run", while a line of
- "Output:" means outputs in the "Output" window. # is a comment
- statement. All examples should be terminated by the end statement,
- but the end statement may omit in the output of the following examples.
-
-
- 7.1 Simplification and Assumption
-
- SymbMath automatically simplifies the output expression.
- Users can further simplify it by using the built-in variable "last"
- in a singe line again and again until they are happy.
-
- Example 7.1.1. Reduce sqrt(x^2).
- Input:
- sqrt(x^2)
- end
- Output:
- x*sgn(x)
- end
-
- A first way to reduce this output expression is to substitute
- sgn(x) by 1 if x is positive.
- Input:
- sqrt(x^2)
- subs(last, sgn(x)=1)
- end
- Output:
- x*sgn(x)
- x
- end
- A second way to reduce the output expression is to assume
- x>0 before evaluation. On this way, all x is affected. The first
- method is local simplification, but the second method is global
- simplification. If users declare the variable x is positive or
- negative by
-
- assume(x > 0)
- assume(x < 0)
-
- the output expression is simpler than that if users do not declare it.
-
- Example 7.1.2. Assume x>0 before reduce sqrt(x^2).
- Input:
- assume(x >0)
- sqrt(x^2)
- end
- Output:
- assumed
- x
- end
-
- Users can assume the variable b is even, odd, integer, real
- number, positive or negative by
-
- iseven(b) := 1 # assume b is even
- isodd(b) := 1 # assume b is odd
- isinteger(b) := 1 # assume b is integer
- isreal(b) := 1 # assume b is real
- isnumber(b) := 1 # assume b is number
- islist(b) := 1 # assume b is a list
- isfree(y,x) := 1 # assume y is free of x
- sgn(b) := 1 # assume b is positive
- sgn(b) := -1 # assume b is negative
-
- All variables are complex by default.
-
- Example 7.1.3.
- Input:
- isreal(b) := 1
- sqrt(b^2)
- end
- Output:
- isreal(b) := 1
- abs(b)
- end
-
- Example 7.1.4. Set f1=x^2+y^3, then put f1 into sin(f1)+
- cos(2*f1) and assign the last output to f2.
- Input:
- f1=x^2+y^3
- sin(f1)+cos(2*f1)
- f2=last
- end
- Output:
- f1 = x^2 + y^3
- sin(x^2 + y^3) + cos(2 (x^2 + y^3))
- f2 = sin(x^2 + y^3) + cos(2*(x^2 + y^3))
- end
-
- where a special word "last" stands for the last output, e.g. here
- "last" is sin(x^2+y^3)+cos(2*(x^2+y^3)).
-