Function: ev (expr, arg_1, ..., arg_n)
Evaluates the expression expr
in the environment specified by the arguments arg_1, ..., arg_n.
The arguments are switches (Boolean flags), assignments, equations, and
functions. ev returns the result (another expression) of the evaluation.
The evaluation is carried out in steps, as follows.
1. First the environment is set up by scanning the arguments which may be any or all of the following.
o
simp causes expr to be simplified regardless of the setting of
the switch simp which inhibits simplification if false.
o
noeval supresses the evaluation phase of ev (see step (4) below).
This is useful in conjunction with the other switches and in causing expr
to be resimplified without being reevaluated.
o
nouns causes the evaluation of noun forms (typically unevaluated functions
such as 'integrate or 'diff) in expr.
o
expand causes expansion.
o
expand (m, n) causes
expansion, setting the values of maxposex and maxnegex to m
and n respectively.
o
detout causes any matrix inverses computed in expr to have their
determinant kept outside of the inverse rather than dividing through each
element.
o
diff causes all differentiations indicated in expr to be
performed.
o
derivlist (x, y, z, ...) causes only
differentiations with respect to the indicated variables.
o
float causes non-integral rational numbers to be converted to floating
point.
o
numer causes some mathematical functions (including exponentiation) with
numerical arguments to be evaluated in floating point. It causes variables in expr
which have been given numervals to be replaced by their values. It also sets
the float switch on.
o
pred causes predicates (expressions which evaluate to true or false) to be
evaluated.
o
eval causes an extra post-evaluation of expr to occur. (See step
(5) below.) eval may occur multiple times. For each instance of eval, the
expression is evaluated again.
o
A where A is an atom declared to be an evaluation flag (see evflag) causes A to be bound to true during the
evaluation of expr.
o
V: expression (or alternately V=expression) causes V to be bound to the value of expression during the
evaluation of expr. Note that if V is a Maxima option, then
expression is used for its value during the evaluation of expr. If
more than one argument to ev is of this type then the binding is done in parallel. If V is a non-atomic
expression then a substitution rather than a binding is performed.
o
F where F, a function name, has been declared to be an evaluation function (see evfun) causes F to be applied to
expr.
o
Any other function names (e.g., sum) cause
evaluation of occurrences of those names in expr as though they were
verbs.
o
In addition a function occurring in expr
(say F(x)) may be defined locally for the purpose of this evaluation of expr
by giving F(x) :=
expression as an argument to ev.
o
If an atom not mentioned above or a subscripted
variable or subscripted expression was given as an argument, it is evaluated
and if the result is an equation or assignment then the indicated binding or
substitution is performed. If the result is a list then the members of the list
are treated as if they were additional arguments given to ev. This permits a
list of equations to be given (e.g. [X=1, Y=A**2]) or a list
of names of equations (e.g., [%t1,
%t2] where %t1 and %t2 are equations)
such as that returned by solve.
The arguments of ev may be given in
any order with the exception of substitution equations which are handled in
sequence, left to right, and evaluation functions which are composed, e.g., ev (expr, ratsimp, realpart) is handled as realpart
(ratsimp (expr)).
The simp, numer, float, and pred switches may
also be set locally in a block, or globally in Maxima so that they will remain
in effect until being reset.
If expr is a canonical
rational expression (CRE), then the expression returned by ev is also a CRE,
provided the numer and float switches are not both true.
2. During step (1), a list is made of the non-subscripted variables
appearing on the left side of equations in the arguments or in the value of
some arguments if the value is an equation. The variables (subscripted
variables which do not have associated array functions as well as
non-subscripted variables) in the expression expr are replaced by
their global values, except for those appearing in this list. Usually, expr
is just a label or % (as in %i2 in the example below), so this step simply retrieves the expression
named by the label, so that ev may work on it.
3. If any substitutions are indicated by the arguments, they are carried out now.
4. The resulting expression is then re-evaluated (unless one of the
arguments was noeval) and simplified according to the arguments. Note that any function
calls in expr will be carried out after the variables in it are
evaluated and that ev(F(x)) thus may behave like F(ev(x)).
5. For each instance of eval in the arguments, steps (3) and (4) are repeated.
Examples
|
|
(%i1) sin(x) + cos(y) + (w+1)^2 + 'diff (sin(w), w); d 2(%o1) cos(y) + sin(x) + -- (sin(w)) + (w + 1) dw(%i2) ev (%, sin, expand, diff, x=2, y=1); 2(%o2) cos(w) + w + 2 w + cos(1) + 1.909297426825682 |
An alternate top level syntax has
been provided for ev, whereby one may just type in its arguments, without the ev(). That is, one
may write simply
|
|
expr, arg_1, ..., arg_n |
This is not permitted as part of another expression, e.g., in functions, blocks, etc.
Notice the parallel binding process in the following example.
|
|
(%i3) programmode: false;(%o3) false(%i4) x+y, x: a+y, y: 2;(%o4) y + a + 2(%i5) 2*x - 3*y = 3$(%i6) -3*x + 2*y = -4$(%i7) solve ([%o5, %o6]);Solution 1(%t7) y = - - 5 6(%t8) x = - 5(%o8) [[%t7, %t8]](%i8) %o6, %o8;(%o8) - 4 = - 4(%i9) x + 1/x > gamma (1/2); 1(%o9) x + - > sqrt(%pi) x(%i10) %, numer, x=1/2;(%o10) 2.5 > 1.772453850905516(%i11) %, pred;(%o11) true |
When a symbol x has the evflag property,
the expressions ev(expr, x) and expr, x
(at the interactive prompt) are equivalent to ev(expr, x = true). That is, x
is bound to true while expr is evaluated.
The expression declare(x, evflag) gives
the evflag property to the variable x.
The flags which have the evflag property by
default are the following: algebraic, cauchysum, demoivre, dotscrules, %emode, %enumer, exponentialize, exptisolate, factorflag, float, halfangles, infeval, isolate_wrt_times, keepfloat, letrat, listarith, logabs, logarc, logexpand, lognegint, lognumer, m1pbranch, numer_pbranch, programmode, radexpand, ratalgdenom, ratfac, ratmx, ratsimpexpons, simp, simpsum, sumexpand, and trigexpand.
Examples:
|
|
(%i1) sin (1/2); 1(%o1) sin(-) 2(%i2) sin (1/2), float;(%o2) 0.479425538604203(%i3) sin (1/2), float=true;(%o3) 0.479425538604203(%i4) simp : false;(%o4) false(%i5) 1 + 1;(%o5) 1 + 1(%i6) 1 + 1, simp;(%o6) 2(%i7) simp : true;(%o7) true(%i8) sum (1/k^2, k, 1, inf); inf ==== \ 1(%o8) > -- / 2 ==== k k = 1(%i9) sum (1/k^2, k, 1, inf), simpsum; 2 %pi(%o9) ---- 6(%i10) declare (aa, evflag);(%o10) done(%i11) if aa = true then YES else NO;(%o11) NO(%i12) if aa = true then YES else NO, aa;(%o12) YES |
When a function F has the evfun property,
the expressions ev(expr, F) and expr, F
(at the interactive prompt) are equivalent to F(ev(expr)).
If two or more evfun functions F,
G, etc., are specified, the functions are applied in the order that
they are specified.
The expression declare(F, evfun) gives the
evfun property to the function F.
The functions which have the evfun property by
default are the following: bfloat, factor, fullratsimp, logcontract, polarform, radcan, ratexpand, ratsimp, rectform, rootscontract, trigexpand, and trigreduce.
Examples:
|
|
(%i1) x^3 - 1; 3(%o1) x - 1(%i2) x^3 - 1, factor; 2(%o2) (x - 1) (x + x + 1)(%i3) factor (x^3 - 1); 2(%o3) (x - 1) (x + x + 1)(%i4) cos(4 * x) / sin(x)^4; cos(4 x)(%o4) -------- 4 sin (x)(%i5) cos(4 * x) / sin(x)^4, trigexpand; 4 2 2 4 sin (x) - 6 cos (x) sin (x) + cos (x)(%o5) ------------------------------------- 4 sin (x)(%i6) cos(4 * x) / sin(x)^4, trigexpand, ratexpand; 2 4 6 cos (x) cos (x)(%o6) - --------- + ------- + 1 2 4 sin (x) sin (x)(%i7) ratexpand (trigexpand (cos(4 * x) / sin(x)^4)); 2 4 6 cos (x) cos (x)(%o7) - --------- + ------- + 1 2 4 sin (x) sin (x)(%i8) declare ([F, G], evfun);(%o8) done(%i9) (aa : bb, bb : cc, cc : dd);(%o9) dd(%i10) aa;(%o10) bb(%i11) aa, F;(%o11) F(cc)(%i12) F (aa);(%o12) F(bb)(%i13) F (ev (aa));(%o13) F(cc)(%i14) aa, F, G;(%o14) G(F(cc))(%i15) G (F (ev (aa)));(%o15) G(F(cc)) |
Enables "infinite
evaluation" mode. ev repeatedly evaluates an expression until it stops changing. To prevent
a variable, say X, from being evaluated away in this mode, simply include X='X as an
argument to ev. Of course expressions such as ev (X, X=X+1, infeval)
will generate an infinite loop.