1@menu 2* Functions and Variables for Evaluation:: 3@end menu 4 5@c ----------------------------------------------------------------------------- 6@node Functions and Variables for Evaluation, , Evaluation, Evaluation 7@section Functions and Variables for Evaluation 8@c ----------------------------------------------------------------------------- 9 10@c NEEDS EXAMPLES 11@c THIS ITEM IS VERY IMPORTANT !! 12 13@c ----------------------------------------------------------------------------- 14@anchor{quote} 15@deffn {Operator} ' 16@ifinfo 17@fnindex Quote operator 18@end ifinfo 19 20The single quote operator @code{'} prevents evaluation. 21 22Applied to a symbol, the single quote prevents evaluation of the symbol. 23 24Applied to a function call, the single quote prevents evaluation of the function 25call, although the arguments of the function are still evaluated (if evaluation 26is not otherwise prevented). The result is the noun form of the function call. 27 28Applied to a parenthesized expression, the single quote prevents evaluation of 29all symbols and function calls in the expression. 30@c DUNNO IF THESE EXAMPLES ARE STILL NEEDED -- COVERED BY ITEMS UNDER "Examples" 31E.g., @code{'(f(x))} means do not evaluate the expression @code{f(x)}. 32@code{'f(x)} (with the single quote applied to @code{f} instead of @code{f(x)}) 33means return the noun form of @code{f} applied to @code{[x]}. 34 35The single quote does not prevent simplification. 36 37When the global flag @mref{noundisp} is @code{true}, nouns display with a single 38quote. This switch is always @code{true} when displaying function definitions. 39 40See also the quote-quote operator @mxref{quote-quote, ''} and @mrefdot{nouns} 41 42Examples: 43 44Applied to a symbol, 45the single quote prevents evaluation of the symbol. 46 47@c ===beg=== 48@c aa: 1024; 49@c aa^2; 50@c 'aa^2; 51@c ''%; 52@c ===end=== 53@example 54(%i1) aa: 1024; 55(%o1) 1024 56(%i2) aa^2; 57(%o2) 1048576 58(%i3) 'aa^2; 59 2 60(%o3) aa 61(%i4) ''%; 62(%o4) 1048576 63@end example 64 65Applied to a function call, the single quote prevents evaluation of the function 66call. The result is the noun form of the function call. 67 68@c ===beg=== 69@c x0: 5; 70@c x1: 7; 71@c integrate (x^2, x, x0, x1); 72@c 'integrate (x^2, x, x0, x1); 73@c %, nouns; 74@c ===end=== 75@example 76(%i1) x0: 5; 77(%o1) 5 78(%i2) x1: 7; 79(%o2) 7 80(%i3) integrate (x^2, x, x0, x1); 81 218 82(%o3) --- 83 3 84(%i4) 'integrate (x^2, x, x0, x1); 85@group 86 7 87 / 88 [ 2 89(%o4) I x dx 90 ] 91 / 92 5 93@end group 94(%i5) %, nouns; 95 218 96(%o5) --- 97 3 98@end example 99 100Applied to a parenthesized expression, the single quote prevents evaluation of 101all symbols and function calls in the expression. 102 103@c ===beg=== 104@c aa: 1024; 105@c bb: 19; 106@c sqrt(aa) + bb; 107@c '(sqrt(aa) + bb); 108@c ''%; 109@c ===end=== 110@example 111(%i1) aa: 1024; 112(%o1) 1024 113(%i2) bb: 19; 114(%o2) 19 115(%i3) sqrt(aa) + bb; 116(%o3) 51 117(%i4) '(sqrt(aa) + bb); 118(%o4) bb + sqrt(aa) 119(%i5) ''%; 120(%o5) 51 121@end example 122 123The single quote does not prevent simplification. 124 125@c ===beg=== 126@c sin (17 * %pi) + cos (17 * %pi); 127@c '(sin (17 * %pi) + cos (17 * %pi)); 128@c ===end=== 129@example 130(%i1) sin (17 * %pi) + cos (17 * %pi); 131(%o1) - 1 132(%i2) '(sin (17 * %pi) + cos (17 * %pi)); 133(%o2) - 1 134@end example 135 136Maxima considers floating point operations by its in-built mathematical 137functions to be a simplification. 138 139@c ===beg=== 140@c sin(1.0); 141@c '(sin(1.0)); 142@c ===end=== 143@example 144(%i1) sin(1.0); 145(%o1) .8414709848078965 146(%i2) '(sin(1.0)); 147(%o2) .8414709848078965 148@end example 149 150When the global flag @mref{noundisp} is @code{true}, nouns display with a single 151quote. 152 153@c ===beg=== 154@c x:%pi; 155@c bfloat(x); 156@c sin(x); 157@c noundisp; 158@c 'bfloat(x); 159@c bfloat('x); 160@c sin(x); 161@c sin('x); 162@c noundisp : not noundisp; 163@c 'bfloat(x); 164@c bfloat('x); 165@c sin(x); 166@c sin('x); 167@c ===end=== 168@example 169(%i1) x:%pi; 170(%o1) %pi 171(%i2) bfloat(x); 172(%o2) 3.141592653589793b0 173(%i3) sin(x); 174(%o3) 0 175(%i4) noundisp; 176(%o4) false 177(%i5) 'bfloat(x); 178(%o5) bfloat(%pi) 179(%i6) bfloat('x); 180(%o6) x 181(%i7) 'sin(x); 182(%o7) 0 183(%i8) sin('x); 184(%o8) sin(x) 185(%i9) noundisp : not noundisp; 186(%o9) true 187(%i10) 'bfloat(x); 188(%o10) 'bfloat(%pi) 189(%i11) bfloat('x); 190(%o11) x 191(%i12) 'sin(x); 192(%o12) 0 193(%i13) sin('x); 194(%o13) sin(x) 195(%i14) 196@end example 197 198@opencatbox 199@category{Evaluation} 200@category{Operators} 201@closecatbox 202@end deffn 203 204@c ----------------------------------------------------------------------------- 205@anchor{quote-quote} 206@deffn {Operator} '' 207@ifinfo 208@fnindex Quote-quote operator 209@end ifinfo 210 211The quote-quote operator @code{'@w{}'} (two single quote marks) modifies 212evaluation in input expressions. 213 214Applied to a general expression @var{expr}, quote-quote causes the value of 215@var{expr} to be substituted for @var{expr} in the input expression. 216 217Applied to the operator of an expression, quote-quote changes the operator from 218a noun to a verb (if it is not already a verb). 219 220The quote-quote operator is applied by the input parser; it is not stored as 221part of a parsed input expression. The quote-quote operator is always applied 222as soon as it is parsed, and cannot be quoted. Thus quote-quote causes 223evaluation when evaluation is otherwise suppressed, such as in function 224definitions, lambda expressions, and expressions quoted by single quote 225@code{'}. 226 227Quote-quote is recognized by @mref{batch} and @mrefdot{load} 228 229See also @mrefcomma{ev} the single-quote operator @mxref{quote, '} and @mrefdot{nouns} 230 231Examples: 232 233Applied to a general expression @var{expr}, quote-quote causes the value of 234@var{expr} to be substituted for @var{expr} in the input expression. 235 236@c ===beg=== 237@c expand ((a + b)^3); 238@c [_, ''_]; 239@c [%i1, ''%i1]; 240@c [aa : cc, bb : dd, cc : 17, dd : 29]; 241@c foo_1 (x) := aa - bb * x; 242@c foo_1 (10); 243@c ''%; 244@c ''(foo_1 (10)); 245@c foo_2 (x) := ''aa - ''bb * x; 246@c foo_2 (10); 247@c [x0 : x1, x1 : x2, x2 : x3]; 248@c x0; 249@c ''x0; 250@c '' ''x0; 251@c ===end=== 252@example 253(%i1) expand ((a + b)^3); 254 3 2 2 3 255(%o1) b + 3 a b + 3 a b + a 256(%i2) [_, ''_]; 257 3 3 2 2 3 258(%o2) [expand((b + a) ), b + 3 a b + 3 a b + a ] 259(%i3) [%i1, ''%i1]; 260 3 3 2 2 3 261(%o3) [expand((b + a) ), b + 3 a b + 3 a b + a ] 262(%i4) [aa : cc, bb : dd, cc : 17, dd : 29]; 263(%o4) [cc, dd, 17, 29] 264(%i5) foo_1 (x) := aa - bb * x; 265(%o5) foo_1(x) := aa - bb x 266(%i6) foo_1 (10); 267(%o6) cc - 10 dd 268(%i7) ''%; 269(%o7) - 273 270(%i8) ''(foo_1 (10)); 271(%o8) - 273 272(%i9) foo_2 (x) := ''aa - ''bb * x; 273(%o9) foo_2(x) := cc - dd x 274(%i10) foo_2 (10); 275(%o10) - 273 276(%i11) [x0 : x1, x1 : x2, x2 : x3]; 277(%o11) [x1, x2, x3] 278(%i12) x0; 279(%o12) x1 280(%i13) ''x0; 281(%o13) x2 282(%i14) '' ''x0; 283(%o14) x3 284@end example 285 286Applied to the operator of an expression, quote-quote changes the operator from 287a noun to a verb (if it is not already a verb). 288 289@c ===beg=== 290@c declare (foo, noun); 291@c foo (x) := x - 1729; 292@c foo (100); 293@c ''foo (100); 294@c ===end=== 295@example 296(%i1) declare (foo, noun); 297(%o1) done 298(%i2) foo (x) := x - 1729; 299(%o2) ''foo(x) := x - 1729 300(%i3) foo (100); 301(%o3) foo(100) 302(%i4) ''foo (100); 303(%o4) - 1629 304@end example 305 306The quote-quote operator is applied by the input parser; it is not stored as 307part of a parsed input expression. 308 309@c ===beg=== 310@c [aa : bb, cc : dd, bb : 1234, dd : 5678]; 311@c aa + cc; 312@c display (_, op (_), args (_)); 313@c ''(aa + cc); 314@c display (_, op (_), args (_)); 315@c ===end=== 316@example 317(%i1) [aa : bb, cc : dd, bb : 1234, dd : 5678]; 318(%o1) [bb, dd, 1234, 5678] 319(%i2) aa + cc; 320(%o2) dd + bb 321(%i3) display (_, op (_), args (_)); 322 _ = cc + aa 323 324 op(cc + aa) = + 325 326 args(cc + aa) = [cc, aa] 327 328(%o3) done 329(%i4) ''(aa + cc); 330(%o4) 6912 331(%i5) display (_, op (_), args (_)); 332 _ = dd + bb 333 334 op(dd + bb) = + 335 336 args(dd + bb) = [dd, bb] 337 338(%o5) done 339@end example 340 341Quote-quote causes evaluation when evaluation is otherwise suppressed, such as 342in function definitions, lambda expressions, and expressions quoted by single 343quote @code{'}. 344 345@c ===beg=== 346@c foo_1a (x) := ''(integrate (log (x), x)); 347@c foo_1b (x) := integrate (log (x), x); 348@c dispfun (foo_1a, foo_1b); 349@c integrate (log (x), x); 350@c foo_2a (x) := ''%; 351@c foo_2b (x) := %; 352@c dispfun (foo_2a, foo_2b); 353@c F : lambda ([u], diff (sin (u), u)); 354@c G : lambda ([u], ''(diff (sin (u), u))); 355@c '(sum (a[k], k, 1, 3) + sum (b[k], k, 1, 3)); 356@c '(''(sum (a[k], k, 1, 3)) + ''(sum (b[k], k, 1, 3))); 357@c ===end=== 358@example 359(%i1) foo_1a (x) := ''(integrate (log (x), x)); 360(%o1) foo_1a(x) := x log(x) - x 361(%i2) foo_1b (x) := integrate (log (x), x); 362(%o2) foo_1b(x) := integrate(log(x), x) 363(%i3) dispfun (foo_1a, foo_1b); 364(%t3) foo_1a(x) := x log(x) - x 365 366(%t4) foo_1b(x) := integrate(log(x), x) 367 368(%o4) [%t3, %t4] 369(%i5) integrate (log (x), x); 370(%o5) x log(x) - x 371(%i6) foo_2a (x) := ''%; 372(%o6) foo_2a(x) := x log(x) - x 373(%i7) foo_2b (x) := %; 374(%o7) foo_2b(x) := % 375(%i8) dispfun (foo_2a, foo_2b); 376(%t8) foo_2a(x) := x log(x) - x 377 378(%t9) foo_2b(x) := % 379 380(%o9) [%t7, %t8] 381(%i10) F : lambda ([u], diff (sin (u), u)); 382(%o10) lambda([u], diff(sin(u), u)) 383(%i11) G : lambda ([u], ''(diff (sin (u), u))); 384(%o11) lambda([u], cos(u)) 385(%i12) '(sum (a[k], k, 1, 3) + sum (b[k], k, 1, 3)); 386(%o12) sum(b , k, 1, 3) + sum(a , k, 1, 3) 387 k k 388(%i13) '(''(sum (a[k], k, 1, 3)) + ''(sum (b[k], k, 1, 3))); 389(%o13) b + a + b + a + b + a 390 3 3 2 2 1 1 391@end example 392 393@opencatbox 394@category{Evaluation} 395@category{Operators} 396@closecatbox 397@end deffn 398 399@c NEEDS CLARIFICATION 400@c VERY IMPORTANT !! 401 402@c ----------------------------------------------------------------------------- 403@anchor{ev} 404@deffn {Function} ev (@var{expr}, @var{arg_1}, @dots{}, @var{arg_n}) 405 406Evaluates the expression @var{expr} in the environment specified by the 407arguments @var{arg_1}, @dots{}, @var{arg_n}. The arguments are switches 408(Boolean flags), assignments, equations, and functions. @code{ev} returns the 409result (another expression) of the evaluation. 410 411The evaluation is carried out in steps, as follows. 412 413@enumerate 414@item 415First the environment is set up by scanning the arguments which may 416be any or all of the following. 417 418@itemize @bullet 419@item 420@mref{simp} causes @var{expr} to be simplified regardless of the setting of the 421switch @code{simp} which inhibits simplification if @code{false}. 422@item 423@mref{noeval} suppresses the evaluation phase of @code{ev} (see step (4) below). 424This is useful in conjunction with the other switches and in causing 425@var{expr} to be resimplified without being reevaluated. 426@item 427@mref{nouns} causes the evaluation of noun forms (typically unevaluated 428functions such as @code{'integrate} or @code{'diff}) in @var{expr}. 429@item 430@mref{expand} causes expansion. 431@item 432@code{expand (@var{m}, @var{n})} causes expansion, setting the values of 433@mref{maxposex} and @mref{maxnegex} to @var{m} and @var{n} respectively. 434@item 435@mref{detout} causes any matrix inverses computed in @var{expr} to have their 436determinant kept outside of the inverse rather than dividing through 437each element. 438@item 439@mref{diff} causes all differentiations indicated in @var{expr} to be performed. 440@item 441@code{derivlist (@var{x}, @var{y}, @var{z}, ...)} causes only differentiations 442with respect to the indicated variables. See also @mrefdot{derivlist} 443@item 444@code{risch} causes integrals in @var{expr} to be evaluated using the Risch 445algorithm. See @mrefdot{risch} The standard integration routine is invoked 446when using the special symbol @mrefdot{nouns} 447@item 448@mref{float} causes non-integral rational numbers to be converted to floating 449point. 450@item 451@mref{numer} causes some mathematical functions (including exponentiation) 452with numerical arguments to be evaluated in floating point. It causes 453variables in @var{expr} which have been given numervals to be replaced by 454their values. It also sets the @mref{float} switch on. 455@item 456@mref{pred} causes predicates (expressions which evaluate to @code{true} or 457@code{false}) to be evaluated. 458@item 459@mref{eval} causes an extra post-evaluation of @var{expr} to occur. 460(See step (5) below.) 461@code{eval} may occur multiple times. For each instance of @code{eval}, the 462expression is evaluated again. 463@item 464@code{A} where @code{A} is an atom declared to be an evaluation flag 465@mref{evflag} causes @code{A} to be bound to @code{true} during the evaluation 466of @var{expr}. 467@item 468@code{V: expression} (or alternately @code{V=expression}) causes @code{V} to be 469bound to the value of @code{expression} during the evaluation of @var{expr}. 470Note that if @code{V} is a Maxima option, then @code{expression} is used for 471its value during the evaluation of @var{expr}. If more than one argument to 472@code{ev} is of this type then the binding is done in parallel. If @code{V} is 473a non-atomic expression then a substitution rather than a binding is performed. 474@item 475@code{F} where @code{F}, a function name, has been declared to be an evaluation 476function @mref{evfun} causes @code{F} to be applied to @var{expr}. 477@item 478Any other function names, e.g. @mrefcomma{sum} cause evaluation of occurrences 479of those names in @var{expr} as though they were verbs. 480@item 481In addition a function occurring in @var{expr} (say @code{F(x)}) may be defined 482locally for the purpose of this evaluation of @var{expr} by giving 483@code{F(x) := expression} as an argument to @code{ev}. 484@item 485If an atom not mentioned above or a subscripted variable or subscripted 486expression was given as an argument, it is evaluated and if the result is an 487equation or assignment then the indicated binding or substitution is performed. 488If the result is a list then the members of the list are treated as if they were 489additional arguments given to @code{ev}. This permits a list of equations to be 490given (e.g. @code{[X=1, Y=A**2]}) or a list of names of equations (e.g., 491@code{[%t1, %t2]} where @code{%t1} and @code{%t2} are equations) such as that 492returned by @mrefdot{solve} 493@end itemize 494 495The arguments of @code{ev} may be given in any order with the exception of 496substitution equations which are handled in sequence, left to right, and 497evaluation functions which are composed, e.g., @code{ev (@var{expr}, ratsimp, 498realpart)} is handled as @code{realpart (ratsimp (@var{expr}))}. 499 500The @mrefcomma{simp} @mrefcomma{numer} and @mref{float} switches may also be set 501locally in a block, or globally in Maxima so that they will remain in effect 502until being reset. 503 504If @var{expr} is a canonical rational expression (CRE), then the expression 505returned by @code{ev} is also a CRE, provided the @code{numer} and @code{float} 506switches are not both @code{true}. 507 508@item 509During step (1), a list is made of the non-subscripted variables appearing on 510the left side of equations in the arguments or in the value of some arguments 511if the value is an equation. The variables (subscripted variables which do not 512have associated @mref{memoizing functions} as well as non-subscripted variables) in the 513expression @var{expr} are replaced by their global values, except for those 514appearing in this list. Usually, @var{expr} is just a label or @code{%} (as in 515@code{%i2} in the example below), so this step simply retrieves the expression 516named by the label, so that @code{ev} may work on it. 517 518@item 519If any substitutions are indicated by the arguments, they are carried out now. 520 521@item 522The resulting expression is then re-evaluated (unless one of the arguments was 523@mref{noeval}) and simplified according to the arguments. Note that any 524function calls in @var{expr} will be carried out after the variables in it are 525evaluated and that @code{ev(F(x))} thus may behave like @code{F(ev(x))}. 526 527@item 528For each instance of @mref{eval} in the arguments, steps (3) and (4) are 529repeated. 530@end enumerate 531 532See also @mxrefcomma{quote-quote, ''} @mref{at} and @mrefdot{subst} 533 534Examples: 535 536@c ===beg=== 537@c sin(x) + cos(y) + (w+1)^2 + 'diff (sin(w), w); 538@c ev (%, numer, expand, diff, x=2, y=1); 539@c ===end=== 540@example 541(%i1) sin(x) + cos(y) + (w+1)^2 + 'diff (sin(w), w); 542 d 2 543(%o1) cos(y) + sin(x) + -- (sin(w)) + (w + 1) 544 dw 545(%i2) ev (%, numer, expand, diff, x=2, y=1); 546 2 547(%o2) cos(w) + w + 2 w + 2.449599732693821 548@end example 549 550An alternate top level syntax has been provided for @code{ev}, whereby one 551may just type in its arguments, without the @code{ev()}. That is, one may 552write simply 553 554@example 555@var{expr}, @var{arg_1}, ..., @var{arg_n} 556@end example 557 558This is not permitted as part of another expression, e.g., in functions, 559blocks, etc. 560 561Notice the parallel binding process in the following example. 562 563@example 564(%i3) programmode: false; 565(%o3) false 566(%i4) x+y, x: a+y, y: 2; 567(%o4) y + a + 2 568(%i5) 2*x - 3*y = 3$ 569(%i6) -3*x + 2*y = -4$ 570(%i7) solve ([%o5, %o6]); 571Solution 572 573 1 574(%t7) y = - - 575 5 576 577 6 578(%t8) x = - 579 5 580(%o8) [[%t7, %t8]] 581(%i8) %o6, %o8; 582(%o8) - 4 = - 4 583(%i9) x + 1/x > gamma (1/2); 584 1 585(%o9) x + - > sqrt(%pi) 586 x 587(%i10) %, numer, x=1/2; 588(%o10) 2.5 > 1.772453850905516 589(%i11) %, pred; 590(%o11) true 591@end example 592 593@opencatbox 594@category{Evaluation} 595@closecatbox 596@end deffn 597 598@c ----------------------------------------------------------------------------- 599@anchor{eval} 600@defvr {Special symbol} eval 601 602As an argument in a call to @code{ev (@var{expr})}, @code{eval} causes an extra 603evaluation of @var{expr}. See @mrefdot{ev} 604 605Example: 606 607@c ===beg=== 608@c [a:b,b:c,c:d,d:e]; 609@c a; 610@c ev(a); 611@c ev(a),eval; 612@c a,eval,eval; 613@c ===end=== 614@example 615(%i1) [a:b,b:c,c:d,d:e]; 616(%o1) [b, c, d, e] 617(%i2) a; 618(%o2) b 619(%i3) ev(a); 620(%o3) c 621(%i4) ev(a),eval; 622(%o4) e 623(%i5) a,eval,eval; 624(%o5) e 625@end example 626 627@opencatbox 628@category{Evaluation flags} 629@closecatbox 630@end defvr 631 632@c ----------------------------------------------------------------------------- 633@anchor{evflag} 634@defvr {Property} evflag 635 636When a symbol @var{x} has the @code{evflag} property, the expressions 637@code{ev(@var{expr}, @var{x})} and @code{@var{expr}, @var{x}} (at the 638interactive prompt) are equivalent to @code{ev(@var{expr}, @var{x} = true)}. 639That is, @var{x} is bound to @code{true} while @var{expr} is evaluated. 640 641The expression @code{declare(@var{x}, evflag)} gives the @code{evflag} property 642to the variable @var{x}. 643 644The flags which have the @code{evflag} property by default are the following: 645@c FOLLOWING LIST CONSTRUCTED FROM LIST UNDER (prog1 '(evflag properties) ...) 646@c NEAR LINE 2649 OF mlisp.lisp AT PRESENT (2004/11). 647 648@verbatim 649 algebraic cauchysum demoivre 650 dotscrules %emode %enumer 651 exponentialize exptisolate factorflag 652 float halfangles infeval 653 isolate_wrt_times keepfloat letrat 654 listarith logabs logarc 655 logexpand lognegint 656 m1pbranch numer_pbranch programmode 657 radexpand ratalgdenom ratfac 658 ratmx ratsimpexpons simp 659 simpproduct simpsum sumexpand 660 trigexpand 661@end verbatim 662 663Examples: 664 665@c ===beg=== 666@c sin (1/2); 667@c sin (1/2), float; 668@c sin (1/2), float=true; 669@c simp : false; 670@c 1 + 1; 671@c 1 + 1, simp; 672@c simp : true; 673@c sum (1/k^2, k, 1, inf); 674@c sum (1/k^2, k, 1, inf), simpsum; 675@c declare (aa, evflag); 676@c if aa = true then YES else NO; 677@c if aa = true then YES else NO, aa; 678@c ===end=== 679@example 680(%i1) sin (1/2); 681 1 682(%o1) sin(-) 683 2 684(%i2) sin (1/2), float; 685(%o2) 0.479425538604203 686(%i3) sin (1/2), float=true; 687(%o3) 0.479425538604203 688(%i4) simp : false; 689(%o4) false 690(%i5) 1 + 1; 691(%o5) 1 + 1 692(%i6) 1 + 1, simp; 693(%o6) 2 694(%i7) simp : true; 695(%o7) true 696(%i8) sum (1/k^2, k, 1, inf); 697 inf 698 ==== 699 \ 1 700(%o8) > -- 701 / 2 702 ==== k 703 k = 1 704(%i9) sum (1/k^2, k, 1, inf), simpsum; 705 2 706 %pi 707(%o9) ---- 708 6 709(%i10) declare (aa, evflag); 710(%o10) done 711(%i11) if aa = true then YES else NO; 712(%o11) NO 713(%i12) if aa = true then YES else NO, aa; 714(%o12) YES 715@end example 716 717@opencatbox 718@category{Evaluation flags} 719@category{Simplification flags and variables} 720@closecatbox 721@end defvr 722 723@c ----------------------------------------------------------------------------- 724@anchor{evfun} 725@defvr {Property} evfun 726 727When a function @var{F} has the @code{evfun} property, the expressions 728@code{ev(@var{expr}, @var{F})} and @code{@var{expr}, @var{F}} (at the 729interactive prompt) are equivalent to @code{@var{F}(ev(@var{expr}))}. 730 731If two or more @code{evfun} functions @var{F}, @var{G}, etc., are specified, 732the functions are applied in the order that they are specified. 733 734The expression @code{declare(@var{F}, evfun)} gives the @code{evfun} property 735to the function @var{F}. The functions which have the @code{evfun} property by 736default are the following: 737@c FOLLOWING LIST CONSTRUCTED FROM LIST UNDER (prog1 '(evfun properties) ...) 738@c NEAR LINE 2643 IN mlisp.lisp AT PRESENT (2004/11). 739 740@verbatim 741 bfloat factor fullratsimp 742 logcontract polarform radcan 743 ratexpand ratsimp rectform 744 rootscontract trigexpand trigreduce 745@end verbatim 746 747Examples: 748 749@c ===beg=== 750@c x^3 - 1; 751@c x^3 - 1, factor; 752@c factor (x^3 - 1); 753@c cos(4 * x) / sin(x)^4; 754@c cos(4 * x) / sin(x)^4, trigexpand; 755@c cos(4 * x) / sin(x)^4, trigexpand, ratexpand; 756@c ratexpand (trigexpand (cos(4 * x) / sin(x)^4)); 757@c declare ([F, G], evfun); 758@c (aa : bb, bb : cc, cc : dd); 759@c aa; 760@c aa, F; 761@c F (aa); 762@c F (ev (aa)); 763@c aa, F, G; 764@c G (F (ev (aa))); 765@c ===end=== 766@example 767(%i1) x^3 - 1; 768 3 769(%o1) x - 1 770(%i2) x^3 - 1, factor; 771 2 772(%o2) (x - 1) (x + x + 1) 773(%i3) factor (x^3 - 1); 774 2 775(%o3) (x - 1) (x + x + 1) 776(%i4) cos(4 * x) / sin(x)^4; 777@group 778 cos(4 x) 779(%o4) -------- 780 4 781 sin (x) 782@end group 783(%i5) cos(4 * x) / sin(x)^4, trigexpand; 784 4 2 2 4 785 sin (x) - 6 cos (x) sin (x) + cos (x) 786(%o5) ------------------------------------- 787 4 788 sin (x) 789(%i6) cos(4 * x) / sin(x)^4, trigexpand, ratexpand; 790 2 4 791 6 cos (x) cos (x) 792(%o6) - --------- + ------- + 1 793 2 4 794 sin (x) sin (x) 795(%i7) ratexpand (trigexpand (cos(4 * x) / sin(x)^4)); 796 2 4 797 6 cos (x) cos (x) 798(%o7) - --------- + ------- + 1 799 2 4 800 sin (x) sin (x) 801(%i8) declare ([F, G], evfun); 802(%o8) done 803(%i9) (aa : bb, bb : cc, cc : dd); 804(%o9) dd 805(%i10) aa; 806(%o10) bb 807(%i11) aa, F; 808(%o11) F(cc) 809(%i12) F (aa); 810(%o12) F(bb) 811(%i13) F (ev (aa)); 812(%o13) F(cc) 813(%i14) aa, F, G; 814(%o14) G(F(cc)) 815(%i15) G (F (ev (aa))); 816(%o15) G(F(cc)) 817@end example 818 819@opencatbox 820@category{Evaluation flags} 821@closecatbox 822@end defvr 823 824@c NEEDS WORK 825 826@c ----------------------------------------------------------------------------- 827@anchor{infeval} 828@defvr {Option variable} infeval 829 830Enables "infinite evaluation" mode. @mref{ev} repeatedly evaluates an 831expression until it stops changing. To prevent a variable, say @code{X}, from 832being evaluated away in this mode, simply include @code{X='X} as an argument to 833@code{ev}. Of course expressions such as @code{ev (X, X=X+1, infeval)} will 834generate an infinite loop. 835 836@opencatbox 837@category{Evaluation flags} 838@closecatbox 839@end defvr 840 841@c NEEDS CLARIFICATION, EXAMPLES 842@c NEED TO MENTION THIS IS AN evflag 843 844@c ----------------------------------------------------------------------------- 845@anchor{noeval} 846@defvr {Special symbol} noeval 847 848@code{noeval} suppresses the evaluation phase of @mrefdot{ev} This is useful in 849conjunction with other switches and in causing expressions 850to be resimplified without being reevaluated. 851 852@opencatbox 853@category{Evaluation flags} 854@closecatbox 855@end defvr 856 857@c NEEDS CLARIFICATION, EXAMPLES 858 859@c ----------------------------------------------------------------------------- 860@anchor{nouns} 861@defvr {Special symbol} nouns 862 863@code{nouns} is an @mrefdot{evflag} When used as an option to the @mref{ev}@w{} 864command, @code{nouns} converts all "noun" forms occurring in the expression 865being @code{ev}'d to "verbs", i.e., evaluates them. See also 866@mrefcomma{noun} @mrefcomma{nounify} @code{verb}, and @mrefdot{verbify} 867 868@opencatbox 869@category{Evaluation flags} 870@category{Nouns and verbs} 871@closecatbox 872@end defvr 873 874@c ----------------------------------------------------------------------------- 875@anchor{pred} 876@defvr {Special symbol} pred 877 878As an argument in a call to @code{ev (@var{expr})}, @code{pred} causes 879predicates (expressions which evaluate to @code{true} or @code{false}) to be 880evaluated. See @mrefdot{ev} 881 882Example: 883 884@c ===beg=== 885@c 1<2; 886@c 1<2,pred; 887@c ===end=== 888@example 889(%i1) 1<2; 890(%o1) 1 < 2 891(%i2) 1<2,pred; 892(%o2) true 893@end example 894 895@opencatbox 896@category{Evaluation flags} 897@closecatbox 898@end defvr 899 900