2 * Introduction to Expressions::
6 * Functions and Variables for Expressions::
9 @c -----------------------------------------------------------------------------
10 @node Introduction to Expressions, Nouns and Verbs, Expressions, Expressions
11 @section Introduction to Expressions
12 @c -----------------------------------------------------------------------------
14 There are a number of reserved words which should not be used as variable names.
15 Their use would cause a possibly cryptic syntax error.
18 integrate next from diff
22 unless product while thru
26 Most things in Maxima are expressions. A sequence of expressions
27 can be made into an expression by separating them by commas and
28 putting parentheses around them. This is similar to the @b{C}
34 @c (if (x > 17) then 2 else 4);
35 @c (if (x > 17) then x: 2 else y: 4, y+x);
39 (%i2) (x: x+1, x: x^2);
41 (%i3) (if (x > 17) then 2 else 4);
43 (%i4) (if (x > 17) then x: 2 else y: 4, y+x);
47 Even loops in Maxima are expressions, although the value they
48 return is the not too useful @code{done}.
51 @c y: (x: 1, for i from 1 thru 10 do (x: x*i))$
55 (%i1) y: (x: 1, for i from 1 thru 10 do (x: x*i))$
60 Whereas what you really want is probably to include a third
61 term in the @i{comma expression} which actually gives back the value.
64 @c y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$
68 (%i3) y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$
73 @c -----------------------------------------------------------------------------
74 @node Nouns and Verbs, Identifiers, Introduction to Expressions, Expressions
75 @section Nouns and Verbs
76 @c -----------------------------------------------------------------------------
78 Maxima distinguishes between operators which are "nouns" and operators which are
79 "verbs". A verb is an operator which can be executed. A noun is an operator
80 which appears as a symbol in an expression, without being executed. By default,
81 function names are verbs. A verb can be changed into a noun by quoting the
82 function name or applying the @mref{nounify} function. A noun can be changed
83 into a verb by applying the @mref{verbify} function. The evaluation flag
84 @mref{nouns} causes @mref{ev} to evaluate nouns in an expression.
86 The verb form is distinguished by a leading dollar sign @code{$} on the
87 corresponding Lisp symbol. In contrast, the noun form is distinguished by a
88 leading percent sign @code{%} on the corresponding Lisp symbol. Some nouns have
89 special display properties, such as @code{'integrate} and @code{'derivative}
90 (returned by @mref{diff}), but most do not. By default, the noun and verb forms
91 of a function are identical when displayed. The global flag @mref{noundisp}@w{}
92 causes Maxima to display nouns with a leading quote mark @code{'}.
94 See also @mrefcomma{noun} @mrefcomma{nouns} @mrefcomma{nounify} and
104 @c declare (bar, noun);
108 @c integrate (1/x, x, 1, 42);
109 @c 'integrate (1/x, x, 1, 42);
114 (%i1) foo (x) := x^2;
127 (%i4) 'foo (42), nouns;
131 (%i5) declare (bar, noun);
135 (%i6) bar (x) := x/17;
145 (%i8) bar (52), nouns;
149 (%i9) integrate (1/x, x, 1, 42);
153 (%i10) 'integrate (1/x, x, 1, 42);
163 (%i11) ev (%, nouns);
168 @opencatbox{Categories:}
169 @category{Evaluation}
170 @category{Nouns and verbs}
173 @c -----------------------------------------------------------------------------
174 @node Identifiers, Inequality, Nouns and Verbs, Expressions
176 @c -----------------------------------------------------------------------------
178 Maxima identifiers may comprise alphabetic characters, plus the numerals 0
179 through 9, plus any other character preceded by the backslash @code{\}
182 A numeral may be the first character of an identifier if it is preceded by a
183 backslash. Numerals which are the second or later characters need not be
184 preceded by a backslash.
186 The alphabetic characters are initially @code{%}, @code{_},
187 and all characters for which the Lisp function
188 @url{http://www.lispworks.com/documentation/HyperSpec/Body/f_alpha_.htm,
189 @code{ALPHA-CHAR-P}} returns @code{true}.
190 Characters may be declared alphabetic by the @code{declare} function.
191 If so declared, they need not be preceded by a backslash in an identifier.
193 Maxima is case-sensitive. The identifiers @code{foo}, @code{FOO}, and
194 @code{Foo} are distinct. See @ref{Lisp and Maxima} for more on this point.
196 A Maxima identifier is a Lisp symbol which begins with a dollar sign @code{$}.
197 Any other Lisp symbol is preceded by a question mark @code{?} when it appears
198 in Maxima. See @ref{Lisp and Maxima} for more on this point.
203 @c %an_ordinary_identifier42;
204 @c embedded\ spaces\ in\ an\ identifier;
206 @c [foo+bar, foo\+bar];
208 @c [symbolp (foo\+bar), symbolp (\1729)];
209 @c [is (foo\+bar = foo+bar), is (\1729 = 1729)];
211 @c declare ("~", alphabetic);
213 @c [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
214 @c :lisp (defvar *my-lisp-variable* '$foo)
215 @c ?\*my\-lisp\-variable\*;
219 (%i1) %an_ordinary_identifier42;
220 (%o1) %an_ordinary_identifier42
223 (%i2) embedded\ spaces\ in\ an\ identifier;
224 (%o2) embedded spaces in an identifier
231 (%i4) [foo+bar, foo\+bar];
232 (%o4) [foo + bar, foo+bar]
239 (%i6) [symbolp (foo\+bar), symbolp (\1729)];
243 (%i7) [is (foo\+bar = foo+bar), is (\1729 = 1729)];
251 (%i9) declare ("~", alphabetic);
259 (%i11) [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
260 (%o11) [false, false, false]
263 (%i12) :lisp (defvar *my-lisp-variable* '$foo)
267 (%i12) ?\*my\-lisp\-variable\*;
272 @opencatbox{Categories:}
276 @c -----------------------------------------------------------------------------
277 @node Inequality, Functions and Variables for Expressions, Identifiers, Expressions
279 @c -----------------------------------------------------------------------------
281 Maxima has the inequality operators @code{<}, @code{<=}, @code{>=}, @code{>},
282 @code{#}, and @code{notequal}. @xref{if} for a description of conditional
285 @c -----------------------------------------------------------------------------
286 @node Functions and Variables for Expressions, , Inequality, Expressions
287 @section Functions and Variables for Expressions
288 @c -----------------------------------------------------------------------------
290 @c NEEDS WORK, ESPECIALLY EXAMPLES
292 @c -----------------------------------------------------------------------------
294 @deffn {Function} alias (@var{new_name_1}, @var{old_name_1}, @dots{}, @var{new_name_n}, @var{old_name_n})
296 provides an alternate name for a (user or system) function, variable, array,
297 etc. Any even number of arguments may be used.
299 @opencatbox{Categories:}
300 @category{Declarations and inferences}
304 @c -----------------------------------------------------------------------------
306 @defvr {System variable} aliases
307 Default value: @code{[]}
309 @code{aliases} is the list of atoms which have a user defined alias (set up by
310 the @mrefcomma{alias} @mrefcomma{ordergreat} @mref{orderless} functions or by
311 declaring the atom a @mref{noun} with @mrefdot{declare})
313 @opencatbox{Categories:}
314 @category{Declarations and inferences}
315 @category{Global variables}
319 @c NEEDS TO BE REWORKED. NOT CONVINCED THIS SYMBOL NEEDS ITS OWN ITEM
320 @c (SHOULD BE DESCRIBED IN CONTEXT OF EACH FUNCTION WHICH RECOGNIZES IT)
322 @c -----------------------------------------------------------------------------
324 @defvr {Keyword} allbut
326 works with the @code{part} commands (i.e. @mrefcomma{part}@w{}
327 @mrefcomma{inpart} @mrefcomma{substpart} @mrefcomma{substinpart}@w{}
328 @mrefcomma{dpart} and @mref{lpart}).
332 @c expr : e + d + c + b + a;
333 @c part (expr, [2, 5]);
337 (%i1) expr : e + d + c + b + a;
338 (%o1) e + d + c + b + a
341 (%i2) part (expr, [2, 5]);
349 @c expr : e + d + c + b + a;
350 @c part (expr, allbut (2, 5));
354 (%i1) expr : e + d + c + b + a;
355 (%o1) e + d + c + b + a
358 (%i2) part (expr, allbut (2, 5));
363 @code{allbut} is also recognized by @mrefdot{kill}
366 @c [aa : 11, bb : 22, cc : 33, dd : 44, ee : 55];
367 @c kill (allbut (cc, dd));
372 (%i1) [aa : 11, bb : 22, cc : 33, dd : 44, ee : 55];
373 (%o1) [11, 22, 33, 44, 55]
376 (%i2) kill (allbut (cc, dd));
380 (%i1) [aa, bb, cc, dd];
381 (%o1) [aa, bb, 33, 44]
385 @code{kill(allbut(@var{a_1}, @var{a_2}, ...))} has the effect of
386 @code{kill(all)} except that it does not kill the symbols @var{a_1}, @var{a_2},
390 @c -----------------------------------------------------------------------------
392 @deffn {Function} args (@var{expr})
394 Returns the list of arguments of @code{expr}, which may be any kind of
395 expression other than an atom. Only the arguments of the top-level operator
396 are extracted; subexpressions of @code{expr} appear as elements or
397 subexpressions of elements of the list of arguments.
399 The order of the items in the list may depend on the global flag
402 @code{args (@var{expr})} is equivalent to @code{substpart ("[", @var{expr}, 0)}.
403 See also @mrefcomma{substpart} @mrefcomma{apply} @mrefcomma{funmake} and @mrefdot{op}
405 How to convert a matrix to a nested list:
408 @c M:matrix([1,2],[3,4]);
413 (%i1) M:matrix([1,2],[3,4]);
420 (%o2) [[1, 2], [3, 4]]
424 Since maxima internally treats a sum of @code{n} terms as a summation command
425 with @code{n} arguments args() can extract the list of terms in a sum:
444 @opencatbox{Categories:}
445 @category{Expressions}
450 @c SPLIT OFF EXAMPLES INTO EXAMPLE SECTION
452 @c -----------------------------------------------------------------------------
454 @deffn {Function} atom (@var{expr})
456 Returns @code{true} if @var{expr} is atomic (i.e. a number, name or string) else
457 @code{false}. Thus @code{atom(5)} is @code{true} while @code{atom(a[1])} and
458 @code{atom(sin(x))} are @code{false} (assuming @code{a[1]} and @code{x} are
461 @opencatbox{Categories:}
462 @category{Expressions}
463 @category{Predicate functions}
467 @c -----------------------------------------------------------------------------
469 @deffn {Function} box @
470 @fname{box} (@var{expr}) @
471 @fname{box} (@var{expr}, @var{a})
473 Returns @var{expr} enclosed in a box. The return value is an expression with
474 @code{box} as the operator and @var{expr} as the argument. A box is drawn on
475 the display when @mref{display2d} is @code{true}.
477 @code{box (@var{expr}, @var{a})} encloses @var{expr} in a box labelled by the
478 symbol @var{a}. The label is truncated if it is longer than the width of the
481 @code{box} evaluates its argument. However, a boxed expression does not
482 evaluate to its content, so boxed expressions are effectively excluded from
483 computations. @mref{rembox} removes the box again.
485 @mref{boxchar} is the character used to draw the box in @code{box} and in the
486 @mref{dpart} and @mref{lpart} functions.
488 See also @mrefcomma{rembox} @mref{dpart} and @mrefdot{lpart}
497 @c box (a^2 + b^2, term_1);
498 @c 1729 - box (1729);
500 @c box (sin(x) + cos(y));
504 (%i1) box (a^2 + b^2);
519 (%i4) box (a^2 + b^2);
522 (%o4) "(c - d) + 1522756"
526 (%i5) box (a^2 + b^2, term_1);
529 (%o5) "(c - d) + 1522756"
533 (%i6) 1729 - box (1729);
543 (%i8) box (sin(x) + cos(y));
545 (%o8) -cos(y) + sin(x)-
550 @opencatbox{Categories:}
551 @category{Expressions}
555 @c -----------------------------------------------------------------------------
557 @defvr {Option variable} boxchar
558 Default value: @code{"}
560 @code{boxchar} is the character used to draw the box in the @mref{box}@w{}
561 and in the @mref{dpart} and @mref{lpart} functions.
563 @code{boxchar} is only used when @code{display2d_unicode} is @code{false}.
565 All boxes in an expression are drawn with the current value of @code{boxchar};
566 the drawing character is not stored with the box expression.
568 @opencatbox{Categories:}
569 @category{Expressions}
573 @c NEEDS CLARIFICATION !!!
575 @c -----------------------------------------------------------------------------
577 @deffn {Function} collapse (@var{expr})
579 Collapses @var{expr} by causing all of its common (i.e., equal) subexpressions
580 to share (i.e., use the same cells), thereby saving space. (@code{collapse} is
581 a subroutine used by the @mref{optimize} command.) Thus, calling
582 @code{collapse} may be useful after loading in a @mref{save} file. You can
583 collapse several expressions together by using
584 @code{collapse ([@var{expr_1}, ..., @var{expr_n}])}. Similarly, you can
585 collapse the elements of the array @code{A} by doing
586 @code{collapse (listarray ('A))}.
588 @opencatbox{Categories:}
589 @category{Expressions}
593 @c -----------------------------------------------------------------------------
595 @deffn {Function} copy (@var{e})
597 Return a copy of the Maxima expression @var{e}. Although @var{e} can be any
598 Maxima expression, the copy function is the most useful when @var{e} is either
599 a list or a matrix; consider:
622 Let's try the same experiment, but this time let @var{mm} be a copy of @var{m}
645 This time, the assignment to @var{mm} does not change the value of @var{m}.
647 @opencatbox{Categories:}
648 @category{Expressions}
654 @c -----------------------------------------------------------------------------
656 @deffn {Function} disolate (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
658 is similar to @mref{isolate}@code{ (@var{expr}, @var{x})} except that it enables the
659 user to isolate more than one variable simultaneously. This might be useful,
660 for example, if one were attempting to change variables in a multiple
661 integration, and that variable change involved two or more of the integration
662 variables. This function is autoloaded from @file{simplification/disol.mac}.
663 A demo is available by @code{demo("disol")$}.
665 @opencatbox{Categories:}
666 @category{Expressions}
670 @c -----------------------------------------------------------------------------
672 @deffn {Function} dispform @
673 @fname{dispform} (@var{expr}) @
674 @fname{dispform} (@var{expr}, all)
676 Returns the external representation of @var{expr}.
678 @code{dispform(@var{expr})} returns the external representation with respect to
679 the main (top-level) operator. @code{dispform(@var{expr}, all)} returns the
680 external representation with respect to all operators in @var{expr}.
682 See also @mrefcomma{part} @mrefcomma{inpart} and @mrefdot{inflag}
686 The internal representation of @code{- x} is "negative one times @code{x}"
687 while the external representation is "minus @code{x}".
691 @c ?format (true, "~S~%", %);
693 @c ?format (true, "~S~%", %);
701 (%i2) ?format (true, "~S~%", %);
702 ((MTIMES SIMP) -1 $X)
706 (%i3) dispform (- x);
710 (%i4) ?format (true, "~S~%", %);
716 The internal representation of @code{sqrt(x)} is "@code{x} to the power 1/2"
717 while the external representation is "square root of @code{x}".
721 @c ?format (true, "~S~%", %);
722 @c dispform (sqrt (x));
723 @c ?format (true, "~S~%", %);
731 (%i2) ?format (true, "~S~%", %);
732 ((MEXPT SIMP) $X ((RAT SIMP) 1 2))
736 (%i3) dispform (sqrt (x));
740 (%i4) ?format (true, "~S~%", %);
746 Use of the optional argument @code{all}.
749 @c expr : sin (sqrt (x));
750 @c freeof (sqrt, expr);
751 @c freeof (sqrt, dispform (expr));
752 @c freeof (sqrt, dispform (expr, all));
756 (%i1) expr : sin (sqrt (x));
760 (%i2) freeof (sqrt, expr);
764 (%i3) freeof (sqrt, dispform (expr));
768 (%i4) freeof (sqrt, dispform (expr, all));
773 @opencatbox{Categories:}
774 @category{Expressions}
780 @c -----------------------------------------------------------------------------
782 @deffn {Function} dpart (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
784 Selects the same subexpression as @mrefcomma{part} but instead of just returning
785 that subexpression as its value, it returns the whole expression with the
786 selected subexpression displayed inside a box. The box is actually part of the
790 @c dpart (x+y/z^2, 1, 2, 1);
793 (%i1) dpart (x+y/z^2, 1, 2, 1);
802 @opencatbox{Categories:}
803 @category{Expressions}
807 @c -----------------------------------------------------------------------------
809 @defvr {Option variable} exptisolate
810 Default value: @code{false}
812 @c WHAT DOES THIS MEAN EXACTLY ??
813 @code{exptisolate}, when @code{true}, causes @code{isolate (expr, var)} to
814 examine exponents of atoms (such as @code{%e}) which contain @code{var}.
816 @c NEED EXAMPLES HERE
817 @opencatbox{Categories:}
818 @category{Expressions}
822 @c -----------------------------------------------------------------------------
824 @defvr {Option variable} exptsubst
825 Default value: @code{false}
827 @code{exptsubst}, when @code{true}, permits substitutions such as @code{y}
828 for @code{%e^x} in @code{%e^(a x)}.
833 @c subst(y, %e^x, %e^(a*x));
834 @c exptsubst: not exptsubst;
835 @c subst(y, %e^x, %e^(a*x));
848 (%i3) subst(y, %e^x, %e^(a*x));
853 (%i4) exptsubst: not exptsubst;
857 (%i5) subst(y, %e^x, %e^(a*x));
863 @opencatbox{Categories:}
864 @category{Exponential and logarithm functions}
865 @category{Expressions}
869 @c -----------------------------------------------------------------------------
871 @deffn {Function} freeof (@var{x_1}, @dots{}, @var{x_n}, @var{expr})
873 @code{freeof (@var{x_1}, @var{expr})} returns @code{true} if no subexpression of
874 @var{expr} is equal to @var{x_1} or if @var{x_1} occurs only as a dummy variable
875 in @var{expr}, or if @var{x_1} is neither the noun nor verb form of any operator
876 in @var{expr}, and returns @code{false} otherwise.
878 @code{freeof (@var{x_1}, ..., @var{x_n}, @var{expr})} is equivalent to
879 @code{freeof (@var{x_1}, @var{expr}) and ... and freeof (@var{x_n},
882 The arguments @var{x_1}, @dots{}, @var{x_n} may be names of functions and
883 variables, subscripted names, operators (enclosed in double quotes), or general
884 expressions. @code{freeof} evaluates its arguments.
886 @code{freeof} operates only on @var{expr} as it stands (after simplification and
887 evaluation) and does not attempt to determine if some equivalent expression
888 would give a different result. In particular, simplification may yield an
889 equivalent but different expression which comprises some different elements than
890 the original form of @var{expr}.
892 A variable is a dummy variable in an expression if it has no binding outside of
893 the expression. Dummy variables recognized by @code{freeof} are the index of a
894 sum or product, the limit variable in @mrefcomma{limit} the integration variable
895 in the definite integral form of @mref{integrate}, the original variable in
896 @mrefcomma{laplace} formal variables in @mref{at} expressions, and arguments in
897 @mref{lambda} expressions.
899 The indefinite form of @code{integrate} is @i{not} free of its variable of
904 Arguments are names of functions, variables, subscripted names, operators, and
905 expressions. @code{freeof (a, b, expr)} is equivalent to
906 @code{freeof (a, expr) and freeof (b, expr)}.
909 @c expr: z^3 * cos (a[1]) * b^(c+d);
911 @c freeof (cos, expr);
912 @c freeof (a[1], expr);
913 @c freeof (cos (a[1]), expr);
914 @c freeof (b^(c+d), expr);
915 @c freeof ("^", expr);
916 @c freeof (w, sin, a[2], sin (a[2]), b*(c+d), expr);
919 (%i1) expr: z^3 * cos (a[1]) * b^(c+d);
923 (%i2) freeof (z, expr);
925 (%i3) freeof (cos, expr);
927 (%i4) freeof (a[1], expr);
929 (%i5) freeof (cos (a[1]), expr);
931 (%i6) freeof (b^(c+d), expr);
933 (%i7) freeof ("^", expr);
935 (%i8) freeof (w, sin, a[2], sin (a[2]), b*(c+d), expr);
939 @code{freeof} evaluates its arguments.
949 (%i3) freeof (c, expr);
953 @code{freeof} does not consider equivalent expressions.
954 Simplification may yield an equivalent but different expression.
960 @c freeof (a+b, expr);
962 @c freeof (exp, exp (x));
968 (%o2) b + 5 a b + 10 a b + 10 a b + 5 a b + a
969 (%i3) freeof (a+b, %);
971 (%i4) freeof (a+b, expr);
976 (%i6) freeof (exp, exp (x));
980 A summation or definite integral is free of its dummy variable.
981 An indefinite integral is not free of its variable of integration.
984 @c freeof (i, 'sum (f(i), i, 0, n));
985 @c freeof (x, 'integrate (x^2, x, 0, 1));
986 @c freeof (x, 'integrate (x^2, x));
989 (%i1) freeof (i, 'sum (f(i), i, 0, n));
991 (%i2) freeof (x, 'integrate (x^2, x, 0, 1));
993 (%i3) freeof (x, 'integrate (x^2, x));
997 @opencatbox{Categories:}
998 @category{Expressions}
1002 @c -----------------------------------------------------------------------------
1004 @defvr {Option variable} inflag
1005 Default value: @code{false}
1007 When @code{inflag} is @code{true}, functions for part extraction inspect the
1008 internal form of @code{expr}.
1010 Note that the simplifier re-orders expressions. Thus @code{first (x + y)}
1011 returns @code{x} if @code{inflag} is @code{true} and @code{y} if @code{inflag}
1012 is @code{false}. (@code{first (y + x)} gives the same results.)
1014 Also, setting @code{inflag} to @code{true} and calling @mref{part} or
1015 @mref{substpart} is the same as calling @mref{inpart} or @mrefdot{substinpart}
1017 Functions affected by the setting of @code{inflag} are: @mrefcomma{part}@w{}
1018 @mrefcomma{substpart} @mrefcomma{first} @mrefcomma{rest} @mrefcomma{last}@w{}
1019 @mrefcomma{length} the @mref{for} @dots{} @code{in} construct,
1020 @mrefcomma{map} @mrefcomma{fullmap} @mrefcomma{maplist} @mref{reveal} and
1023 @c NEED EXAMPLES HERE
1024 @opencatbox{Categories:}
1025 @category{Expressions}
1031 @c -----------------------------------------------------------------------------
1033 @deffn {Function} inpart (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
1035 is similar to @mref{part} but works on the internal representation of the
1036 expression rather than the displayed form and thus may be faster since no
1037 formatting is done. Care should be taken with respect to the order of
1038 subexpressions in sums and products (since the order of variables in the
1039 internal form is often different from that in the displayed form) and in dealing
1040 with unary minus, subtraction, and division (since these operators are removed
1041 from the expression). @code{part (x+y, 0)} or @code{inpart (x+y, 0)} yield
1042 @code{+}, though in order to refer to the operator it must be enclosed in "s.
1043 For example @code{... if inpart (%o9,0) = "+" then ...}.
1049 @c inpart (%, 3, 2);
1050 @c part (%th (2), 1, 2);
1051 @c 'limit (f(x)^g(x+1), x, 0, minus);
1052 @c inpart (%, 1, 2);
1057 (%i2) inpart (%, 3, 2);
1059 (%i3) part (%th (2), 1, 2);
1061 (%i4) 'limit (f(x)^g(x+1), x, 0, minus);
1065 (%i5) inpart (%, 1, 2);
1069 @opencatbox{Categories:}
1070 @category{Expressions}
1076 @c -----------------------------------------------------------------------------
1078 @deffn {Function} isolate (@var{expr}, @var{x})
1080 Returns @var{expr} with subexpressions which are sums and which do not contain
1081 @var{var} replaced by intermediate expression labels (these being atomic symbols
1082 like @code{%t1}, @code{%t2}, @dots{}). This is often useful to avoid
1083 unnecessary expansion of subexpressions which don't contain the variable of
1084 interest. Since the intermediate labels are bound to the subexpressions they
1085 can all be substituted back by evaluating the expression in which they occur.
1087 @mref{exptisolate} (default value: @code{false}) if @code{true} will cause
1088 @code{isolate} to examine exponents of atoms (like @code{%e}) which contain
1091 @code{isolate_wrt_times} if @code{true}, then @code{isolate} will also isolate
1092 with respect to products. See @mrefdot{isolate_wrt_times} See also @mrefdot{disolate}
1095 Do @code{example (isolate)} for examples.
1097 @opencatbox{Categories:}
1098 @category{Expressions}
1104 @c -----------------------------------------------------------------------------
1105 @anchor{isolate_wrt_times}
1106 @defvr {Option variable} isolate_wrt_times
1107 Default value: @code{false}
1109 When @code{isolate_wrt_times} is @code{true}, @code{isolate} will also isolate
1110 with respect to products. E.g. compare both settings of the switch on
1113 (%i1) isolate_wrt_times: true$
1114 (%i2) isolate (expand ((a+b+c)^2), c);
1125 (%o4) c + %t3 c + %t2 c + %t4
1126 (%i4) isolate_wrt_times: false$
1127 (%i5) isolate (expand ((a+b+c)^2), c);
1129 (%o5) c + 2 b c + 2 a c + %t4
1132 @opencatbox{Categories:}
1133 @category{Expressions}
1139 @c -----------------------------------------------------------------------------
1140 @anchor{listconstvars}
1141 @defvr {Option variable} listconstvars
1142 Default value: @code{false}
1144 When @code{listconstvars} is @code{true} the list returned by
1145 @code{listofvars} contains constant variables, such as @code{%e},
1146 @code{%pi}, @code{%i} or any variables declared as constant that
1147 occur in @var{expr}. A variable is declared as @code{constant}
1148 type via @mref{declare}, and @mref{constantp} returns @code{true}
1149 for all variables declared as @code{constant}. The default is to
1150 omit constant variables from @code{listofvars} return value.
1152 @opencatbox{Categories:}
1153 @category{Expressions}
1157 @c -----------------------------------------------------------------------------
1158 @anchor{listdummyvars}
1159 @defvr {Option variable} listdummyvars
1160 Default value: @code{true}
1162 When @code{listdummyvars} is @code{false}, "dummy variables" in the expression
1163 will not be included in the list returned by @mrefdot{listofvars} (The meaning
1164 of "dummy variables" is as given in @mrefdot{freeof} "Dummy variables" are
1165 mathematical things like the index of a sum or product, the limit variable,
1166 and the definite integration variable.)
1171 @c listdummyvars: true$
1172 @c listofvars ('sum(f(i), i, 0, n));
1173 @c listdummyvars: false$
1174 @c listofvars ('sum(f(i), i, 0, n));
1177 (%i1) listdummyvars: true$
1178 (%i2) listofvars ('sum(f(i), i, 0, n));
1180 (%i3) listdummyvars: false$
1181 (%i4) listofvars ('sum(f(i), i, 0, n));
1185 @opencatbox{Categories:}
1186 @category{Expressions}
1192 @c -----------------------------------------------------------------------------
1194 @deffn {Function} listofvars (@var{expr})
1196 Returns a list of the variables in @var{expr}.
1198 @mref{listconstvars} if @code{true} causes @code{listofvars} to include
1199 @code{%e}, @code{%pi}, @code{%i}, and any variables declared constant in the
1200 list it returns if they appear in @var{expr}. The default is to omit these.
1202 See also the option variable @mref{listdummyvars} to exclude or include
1203 "dummy variables" in the list of variables.
1206 @c listofvars (f (x[1]+y) / g^(2+a));
1209 (%i1) listofvars (f (x[1]+y) / g^(2+a));
1214 @opencatbox{Categories:}
1215 @category{Expressions}
1221 @c -----------------------------------------------------------------------------
1223 @deffn {Function} lfreeof (@var{list}, @var{expr})
1225 For each member @var{m} of @var{list}, calls
1226 @code{freeof (@var{m}, @var{expr})}. It returns @code{false} if any call to
1227 @mref{freeof} does and @code{true} otherwise.
1232 @c lfreeof ([ a, x], x^2+b);
1233 @c lfreeof ([ b, x], x^2+b);
1234 @c lfreeof ([ a, y], x^2+b);
1238 (%i1) lfreeof ([ a, x], x^2+b);
1242 (%i2) lfreeof ([ b, x], x^2+b);
1246 (%i3) lfreeof ([ a, y], x^2+b);
1251 @opencatbox{Categories:}
1252 @category{Expressions}
1258 @c -----------------------------------------------------------------------------
1260 @deffn {Function} lpart (@var{label}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
1262 is similar to @mref{dpart} but uses a labelled box. A labelled box is similar
1263 to the one produced by @code{dpart} but it has a name in the top line.
1265 @opencatbox{Categories:}
1266 @category{Expressions}
1270 @c NEEDS CLARIFICATION, EXAMPLES
1272 @c -----------------------------------------------------------------------------
1274 @defvr {Property} mainvar
1276 You may declare variables to be @code{mainvar}. The ordering scale for atoms is
1277 essentially: numbers @code{<} constants (e.g., @code{%e}, @code{%pi}) @code{<} scalars @code{<} other
1278 variables @code{<} mainvars. E.g., compare @code{expand ((X+Y)^4)} with
1279 @code{(declare (x, mainvar), expand ((x+y)^4))}. (Note: Care should be taken if
1280 you elect to use the above feature. E.g., if you subtract an expression in
1281 which @code{x} is a @code{mainvar} from one in which @code{x} isn't a
1282 @code{mainvar}, resimplification e.g. with @code{ev (expr, simp)} may be
1283 necessary if cancellation is to occur. Also, if you save an expression in which
1284 @code{x} is a @code{mainvar}, you probably should also save @code{x}.)
1286 @opencatbox{Categories:}
1287 @category{Declarations and inferences}
1288 @category{Expressions}
1292 @c NEEDS CLARIFICATION, EXAMPLES
1294 @c -----------------------------------------------------------------------------
1296 @defvr {Property} noun
1298 @code{noun} is one of the options of the @mref{declare} command. It makes a
1299 function so declared a "noun", meaning that it won't be evaluated
1305 @c factor (12345678);
1306 @c declare (factor, noun);
1307 @c factor (12345678);
1312 (%i1) factor (12345678);
1317 (%i2) declare (factor, noun);
1321 (%i3) factor (12345678);
1322 (%o3) factor(12345678)
1331 @opencatbox{Categories:}
1332 @category{Nouns and verbs}
1336 @c NEEDS CLARIFICATION, EXAMPLES
1338 @c -----------------------------------------------------------------------------
1340 @defvr {Option variable} noundisp
1341 Default value: @code{false}
1343 When @code{noundisp} is @code{true}, nouns display with
1344 a single quote. This switch is always @code{true} when displaying function
1347 @opencatbox{Categories:}
1348 @category{Display flags and variables}
1349 @category{Nouns and verbs}
1355 @c -----------------------------------------------------------------------------
1357 @deffn {Function} nounify (@var{f})
1359 Returns the noun form of the function name @var{f}. This is
1360 needed if one wishes to refer to the name of a verb function as if it
1361 were a noun. Note that some verb functions will return their noun
1362 forms if they can't be evaluated for certain arguments. This is also
1363 the form returned if a function call is preceded by a quote.
1365 See also @mrefdot{verbify}
1367 @opencatbox{Categories:}
1368 @category{Nouns and verbs}
1374 @c -----------------------------------------------------------------------------
1376 @deffn {Function} nterms (@var{expr})
1378 Returns the number of terms that @var{expr} would have if it were fully
1379 expanded out and no cancellations or combination of terms occurred.
1380 Note that expressions like @code{sin (@var{expr})}, @code{sqrt (@var{expr})},
1381 @code{exp (@var{expr})}, etc. count as just one term regardless of how many
1382 terms @var{expr} has (if it is a sum).
1384 @opencatbox{Categories:}
1385 @category{Expressions}
1391 @c -----------------------------------------------------------------------------
1393 @deffn {Function} op (@var{expr})
1395 Returns the main operator of the expression @var{expr}.
1396 This is equivalent to @code{part (@var{expr}, 0)} with @code{partswitch} set
1399 @code{op} returns a string if the main operator is a built-in or user-defined
1400 prefix, binary or n-ary infix, postfix, matchfix, or nofix operator.
1401 Otherwise, if @var{expr} is a subscripted function expression, @code{op}
1402 returns the subscripted function; in this case the return value is not an atom.
1403 Otherwise, @var{expr} is a @mref{memoizing function} or ordinary function expression,
1404 and @code{op} returns a symbol.
1406 @code{op} observes the value of the global flag @mrefdot{inflag}
1408 @code{op} evaluates it argument.
1410 See also @mrefdot{args}
1415 @c stringdisp: true$
1418 @c op ('sin (a + b));
1422 @c op ('(if a > b then c else d));
1426 @c op (F [x, y] (a, b, c));
1427 @c op (G [u, v, w]);
1430 (%i1) stringdisp: true$
1432 (%i2) op (a * b * c);
1436 (%i3) op (a * b + c);
1440 (%i4) op ('sin (a + b));
1452 (%i7) op ([a, b, c]);
1456 (%i8) op ('(if a > b then c else d));
1460 (%i9) op ('foo (a));
1464 (%i10) prefix (foo);
1472 (%i12) op (F [x, y] (a, b, c));
1477 (%i13) op (G [u, v, w]);
1482 @opencatbox{Categories:}
1483 @category{Expressions}
1484 @category{Operators}
1490 @c -----------------------------------------------------------------------------
1492 @deffn {Function} operatorp @
1493 @fname{operatorp} (@var{expr}, @var{op}) @
1494 @fname{operatorp} (@var{expr}, [@var{op_1}, @dots{}, @var{op_n}])
1496 @code{operatorp (@var{expr}, @var{op})} returns @code{true}
1497 if @var{op} is equal to the operator of @var{expr}.
1499 @code{operatorp (@var{expr}, [@var{op_1}, ..., @var{op_n}])} returns
1500 @code{true} if some element @var{op_1}, @dots{}, @var{op_n} is equal to the
1501 operator of @var{expr}.
1503 @code{operatorp} observes the value of the global flag @mrefdot{inflag}
1505 @opencatbox{Categories:}
1506 @category{Operators}
1507 @category{Predicate functions}
1511 @c NEEDS CLARIFICATION, EXAMPLES
1513 @c -----------------------------------------------------------------------------
1514 @anchor{option_opsubst}
1515 @defvr {Option variable} opsubst
1516 Default value: @code{true}
1518 When @code{opsubst} is @code{false}, @mref{subst} does not attempt to
1519 substitute into the operator of an expression. E.g.,
1520 @code{(opsubst: false, subst (x^2, r, r+r[0]))} will work.
1525 @c subst (x^2, r, r+r[0]);
1526 @c opsubst: not opsubst;
1527 @c subst (x^2, r, r+r[0]);
1540 (%i3) subst (x^2, r, r+r[0]);
1546 (%i4) opsubst: not opsubst;
1550 (%i5) subst (x^2, r, r+r[0]);
1557 @opencatbox{Categories:}
1558 @category{Expressions}
1564 @c -----------------------------------------------------------------------------
1566 @deffn {Function} optimize (@var{expr})
1568 Returns an expression that produces the same value and
1569 side effects as @var{expr} but does so more efficiently by avoiding the
1570 recomputation of common subexpressions. @code{optimize} also has the side
1571 effect of "collapsing" its argument so that all common subexpressions
1572 are shared. Do @code{example (optimize)} for examples.
1574 @opencatbox{Categories:}
1575 @category{Expressions}
1580 @c -----------------------------------------------------------------------------
1581 @anchor{optimprefix}
1582 @defvr {Option variable} optimprefix
1583 Default value: @code{%}
1585 @code{optimprefix} is the prefix used for generated symbols by
1586 the @mref{optimize} command.
1588 @opencatbox{Categories:}
1589 @category{Expressions}
1593 @c -----------------------------------------------------------------------------
1596 @deffn {Function} ordergreat (@var{v_1}, @dots{}, @var{v_n})
1597 @deffnx {Function} orderless (@var{v_1}, @dots{}, @var{v_n})
1599 @code{ordergreat} changes the canonical ordering of Maxima expressions
1600 such that @var{v_1} succeeds @var{v_2} succeeds @dots{} succeeds @var{v_n},
1601 and @var{v_n} succeeds any other symbol not mentioned as an argument.
1603 @code{orderless} changes the canonical ordering of Maxima expressions
1604 such that @var{v_1} precedes @var{v_2} precedes @dots{} precedes @var{v_n},
1605 and @var{v_n} precedes any other variable not mentioned as an argument.
1607 The order established by @code{ordergreat} and @code{orderless} is dissolved
1608 by @mrefdot{unorder} @code{ordergreat} and @code{orderless} can be called only
1609 once each, unless @code{unorder} is called; only the last call to
1610 @code{ordergreat} and @code{orderless} has any effect.
1612 See also @mrefdot{ordergreatp}
1614 @opencatbox{Categories:}
1615 @category{Expressions}
1619 @c -----------------------------------------------------------------------------
1620 @anchor{ordergreatp}
1622 @deffn {Function} ordergreatp (@var{expr_1}, @var{expr_2})
1623 @deffnx {Function} orderlessp (@var{expr_1}, @var{expr_2})
1625 @code{ordergreatp} returns @code{true} if @var{expr_1} succeeds @var{expr_2} in
1626 the canonical ordering of Maxima expressions, and @code{false} otherwise.
1628 @code{orderlessp} returns @code{true} if @var{expr_1} precedes @var{expr_2} in
1629 the canonical ordering of Maxima expressions, and @code{false} otherwise.
1631 All Maxima atoms and expressions are comparable under @code{ordergreatp} and
1632 @code{orderlessp}, although there are isolated examples of expressions for which
1633 these predicates are not transitive; that is a bug.
1635 The canonical ordering of atoms (symbols, literal numbers, and strings) is the
1638 (integers and floats) precede (bigfloats) precede
1639 (declared constants) precede (strings) precede (declared scalars)
1640 precede (first argument to @mref{orderless}) precedes @dots{} precedes
1641 (last argument to @code{orderless}) precedes (other symbols) precede
1642 (last argument to @mref{ordergreat}) precedes @dots{} precedes
1643 (first argument to @code{ordergreat}) precedes (declared main variables)
1645 For non-atomic expressions, the canonical ordering is derived from the ordering
1646 for atoms. For the built-in @code{+} @code{*} and @code{^} operators,
1647 the ordering is not easily summarized. For other built-in operators and all
1648 other functions and operators, expressions are ordered by their arguments
1649 (beginning with the first argument), then by the name of the operator or
1650 function. In the case of subscripted expressions, the subscripted symbol is
1651 considered the operator and the subscript is considered an argument.
1653 The canonical ordering of expressions is modified by the functions
1654 @mref{ordergreat} and @mrefcomma{orderless} and the @mrefcomma{mainvar}@w{}
1655 @mrefcomma{constant} and @code{scalar} declarations.
1657 See also @mrefdot{sort}
1661 Ordering ordinary symbols and constants.
1662 Note that @code{%pi} is not ordered according to its numerical value.
1665 @c stringdisp : true;
1666 @c sort ([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
1670 (%i1) stringdisp : true;
1674 (%i2) sort ([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
1675 (%o2) [3, 3.0, 4, 4.0, 3.0b0, 4.0b0, %pi, "bar", "foo", X, a, x]
1679 Effect of @code{ordergreat} and @code{orderless} functions.
1682 @c sort ([M, H, K, T, E, W, G, A, P, J, S]);
1683 @c ordergreat (S, J);
1684 @c orderless (M, H);
1685 @c sort ([M, H, K, T, E, W, G, A, P, J, S]);
1689 (%i1) sort ([M, H, K, T, E, W, G, A, P, J, S]);
1690 (%o1) [A, E, G, H, J, K, M, P, S, T, W]
1693 (%i2) ordergreat (S, J);
1697 (%i3) orderless (M, H);
1701 (%i4) sort ([M, H, K, T, E, W, G, A, P, J, S]);
1702 (%o4) [M, H, A, E, G, K, P, T, W, J, S]
1706 Effect of @code{mainvar}, @code{constant}, and @code{scalar} declarations.
1709 @c sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1710 @c declare (aa, mainvar);
1711 @c declare ([baz, quux], constant);
1712 @c declare ([A1, B1], scalar);
1713 @c sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1717 (%i1) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1718 (%o1) [A1, B1, C1, aa, bar, baz, bb, cc, dd, foo, quux]
1721 (%i2) declare (aa, mainvar);
1725 (%i3) declare ([baz, quux], constant);
1729 (%i4) declare ([A1, B1], scalar);
1733 (%i5) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1734 (%o5) [baz, quux, A1, B1, C1, bar, bb, cc, dd, foo, aa]
1738 Ordering non-atomic expressions.
1741 @c sort ([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n),
1743 @c sort ([foo(1), X[1], X[k], foo(k), 1, k]);
1747 (%i1) sort ([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n),
1749 (%o1) [1, 2, f(1), g(1), g(1, 2), f(2), f(2, 1), n, g(n),
1753 (%i2) sort ([foo(1), X[1], X[k], foo(k), 1, k]);
1754 (%o2) [1, X , foo(1), k, X , foo(k)]
1759 @opencatbox{Categories:}
1760 @category{Expressions}
1761 @category{Predicate functions}
1767 @c -----------------------------------------------------------------------------
1769 @deffn {Function} part (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
1771 Returns parts of the displayed form of @code{expr}. It obtains the part of
1772 @code{expr} as specified by the indices @var{n_1}, @dots{}, @var{n_k}. First
1773 part @var{n_1} of @code{expr} is obtained, then part @var{n_2} of that, etc.
1774 The result is part @var{n_k} of @dots{} part @var{n_2} of part @var{n_1} of
1775 @code{expr}. If no indices are specified @code{expr} is returned.
1777 @code{part} can be used to obtain an element of a list, a row of a matrix, etc.
1779 @c "If the last argument to a part function" => FOLLOWING APPLIES TO OTHER FUNCTIONS ??
1780 @c ATTEMPT TO VERIFY; IF SO, COPY THIS COMMENTARY TO DESCRIPTIONS OF OTHER FUNCTIONS
1781 If the last argument to a @code{part} function is a list of indices then
1782 several subexpressions are picked out, each one corresponding to an
1783 index of the list. Thus @code{part (x + y + z, [1, 3])} is @code{z+x}.
1785 @mref{piece} holds the last expression selected when using the @code{part}
1786 functions. It is set during the execution of the function and thus
1787 may be referred to in the function itself as shown below.
1789 If @mref{partswitch} is set to @code{true} then @code{end} is returned when a
1790 selected part of an expression doesn't exist, otherwise an error message is
1793 See also @mrefcomma{inpart} @mrefcomma{substpart} @mrefcomma{substinpart}@w{}
1794 @mrefcomma{dpart} and @mrefdot{lpart}
1800 @c part(z+2*y+a,[1,3]);
1801 @c part(z+2*y+a,2,1);
1805 (%i1) part(z+2*y+a,2);
1809 (%i2) part(z+2*y+a,[1,3]);
1813 (%i3) part(z+2*y+a,2,1);
1818 @code{example (part)} displays additional examples.
1820 @opencatbox{Categories:}
1821 @category{Expressions}
1827 @c -----------------------------------------------------------------------------
1829 @deffn {Function} partition (@var{expr}, @var{x})
1831 Returns a list of two expressions. They are (1) the factors of @var{expr}
1832 (if it is a product), the terms of @var{expr} (if it is a sum), or the list
1833 (if it is a list) which don't contain @var{x} and, (2) the factors, terms,
1839 @c partition (2*a*x*f(x), x);
1840 @c partition (a+b, x);
1841 @c partition ([a, b, f(a), c], a);
1844 (%i1) partition (2*a*x*f(x), x);
1846 (%i2) partition (a+b, x);
1848 (%i3) partition ([a, b, f(a), c], a);
1849 (%o3) [[b, c], [a, f(a)]]
1852 @opencatbox{Categories:}
1853 @category{Expressions}
1859 @c -----------------------------------------------------------------------------
1861 @defvr {Option variable} partswitch
1862 Default value: @code{false}
1864 When @code{partswitch} is @code{true}, @code{end} is returned
1865 when a selected part of an expression doesn't exist, otherwise an
1866 error message is given.
1868 @opencatbox{Categories:}
1869 @category{Expressions}
1873 @c -----------------------------------------------------------------------------
1875 @deffn {Function} pickapart (@var{expr}, @var{n})
1877 Assigns intermediate expression labels to subexpressions of @var{expr} at depth
1878 @var{n}, an integer. Subexpressions at greater or lesser depths are not
1879 assigned labels. @code{pickapart} returns an expression in terms of
1880 intermediate expressions equivalent to the original expression @var{expr}.
1882 See also @mrefcomma{part} @mrefcomma{dpart} @mrefcomma{lpart}@w{}
1883 @mrefcomma{inpart} and @mrefdot{reveal}
1888 (%i1) expr: (a+b)/2 + sin (x^2)/3 - log (1 + sqrt(x+1));
1891 (%o1) - log(sqrt(x + 1) + 1) + ------- + -----
1893 (%i2) pickapart (expr, 0);
1897 (%t2) - log(sqrt(x + 1) + 1) + ------- + -----
1901 (%i3) pickapart (expr, 1);
1903 (%t3) - log(sqrt(x + 1) + 1)
1916 (%o5) %t5 + %t4 + %t3
1917 (%i5) pickapart (expr, 2);
1919 (%t6) log(sqrt(x + 1) + 1)
1929 (%o8) --- + --- - %t6
1931 (%i8) pickapart (expr, 3);
1933 (%t9) sqrt(x + 1) + 1
1940 (%o10) ----- - log(%t9) + ---------
1942 (%i10) pickapart (expr, 4);
1948 (%o11) ------- + ----- - log(%t11 + 1)
1951 (%i11) pickapart (expr, 5);
1957 (%o12) ------- + ----- - log(sqrt(%t12) + 1)
1959 (%i12) pickapart (expr, 6);
1962 (%o12) ------- + ----- - log(sqrt(x + 1) + 1)
1966 @opencatbox{Categories:}
1967 @category{Expressions}
1973 @c -----------------------------------------------------------------------------
1975 @defvr {System variable} piece
1977 Holds the last expression selected when using the @mref{part} functions.
1978 @c WHAT DOES THIS MEAN EXACTLY ??
1979 It is set during the execution of the function and thus may be referred to in
1980 the function itself.
1982 @c NEED "SEE ALSO" TO POINT TO LIST OF ALL RELEVANT FUNCTIONS
1984 @opencatbox{Categories:}
1985 @category{Expressions}
1989 @c -----------------------------------------------------------------------------
1991 @deffn {Function} psubst @
1992 @fname{psubst} (@var{list}, @var{expr}) @
1993 @fname{psubst} (@var{a}, @var{b}, @var{expr})
1995 @code{psubst(@var{a}, @var{b}, @var{expr})} is similar to @code{subst}. See
1998 In distinction from @code{subst} the function @code{psubst} makes parallel
1999 substitutions, if the first argument @var{list} is a list of equations.
2001 See also @mref{sublis} for making parallel substitutions and @mref{let} and
2002 @mref{letsimp} for others ways to do substitutions.
2006 The first example shows parallel substitution with @code{psubst}. The second
2007 example shows the result for the function @code{subst}, which does a serial
2011 @c psubst ([a^2=b, b=a], sin(a^2) + sin(b));
2012 @c subst ([a^2=b, b=a], sin(a^2) + sin(b));
2016 (%i1) psubst ([a^2=b, b=a], sin(a^2) + sin(b));
2017 (%o1) sin(b) + sin(a)
2020 (%i2) subst ([a^2=b, b=a], sin(a^2) + sin(b));
2025 @opencatbox{Categories:}
2026 @category{Expressions}
2030 @c -----------------------------------------------------------------------------
2032 @deffn {Function} rembox @
2033 @fname{rembox} (@var{expr}, unlabelled) @
2034 @fname{rembox} (@var{expr}, @var{label}) @
2035 @fname{rembox} (@var{expr})
2037 Removes boxes from @var{expr}.
2039 @code{rembox (@var{expr}, unlabelled)} removes all unlabelled boxes from
2042 @code{rembox (@var{expr}, @var{label})} removes only boxes bearing @var{label}.
2044 @code{rembox (@var{expr})} removes all boxes, labelled and unlabelled.
2046 Boxes are drawn by the @mrefcomma{box} @mrefcomma{dpart} and @mref{lpart}@w{}
2052 @c expr: (a*d - b*c)/h^2 + sin(%pi*x);
2053 @c dpart (dpart (expr, 1, 1), 2, 2);
2054 @c expr2: lpart (BAR, lpart (FOO, %, 1), 2);
2055 @c rembox (expr2, unlabelled);
2056 @c rembox (expr2, FOO);
2057 @c rembox (expr2, BAR);
2062 (%i1) expr: (a*d - b*c)/h^2 + sin(%pi*x);
2064 (%o1) sin(%pi x) + ---------
2069 (%i2) dpart (dpart (expr, 1, 1), 2, 2);
2070 dpart: fell off the end.
2071 -- an error. To debug this try: debugmode(true);
2074 (%i3) expr2: lpart (BAR, lpart (FOO, %, 1), 2);
2076 FOO""""""""" "a d - b c"
2077 (%o3) "sin(%pi x)" + "---------"
2083 (%i4) rembox (expr2, unlabelled);
2085 FOO""""""""" "a d - b c"
2086 (%o4) "sin(%pi x)" + "---------"
2092 (%i5) rembox (expr2, FOO);
2095 (%o5) sin(%pi x) + "---------"
2101 (%i6) rembox (expr2, BAR);
2102 FOO""""""""" a d - b c
2103 (%o6) "sin(%pi x)" + ---------
2108 (%i7) rembox (expr2);
2110 (%o7) sin(%pi x) + ---------
2116 @opencatbox{Categories:}
2117 @category{Expressions}
2121 @c -----------------------------------------------------------------------------
2123 @deffn {Function} reveal (@var{expr}, @var{depth})
2125 Replaces parts of @var{expr} at the specified integer @var{depth}
2126 with descriptive summaries.
2130 Sums and differences are replaced by @code{Sum(@var{n})}
2131 where @var{n} is the number of operands of the sum.
2133 Products are replaced by @code{Product(@var{n})}
2134 where @var{n} is the number of operands of the product.
2136 Exponentials are replaced by @code{Expt}.
2138 Quotients are replaced by @code{Quotient}.
2140 Unary negation is replaced by @code{Negterm}.
2142 Lists are replaced by @code{List(@var{n})} where @var{n} is the number of
2143 elements of the list.
2146 When @var{depth} is greater than or equal to the maximum depth of @var{expr},
2147 @code{reveal (@var{expr}, @var{depth})} returns @var{expr} unmodified.
2149 @code{reveal} evaluates its arguments.
2150 @code{reveal} returns the summarized expression.
2155 @c e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
2164 (%i1) e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
2167 (%o1) -------------------------
2170 (%i2) reveal (e, 1);
2172 (%i3) reveal (e, 2);
2176 (%i4) reveal (e, 3);
2178 Expt + Negterm + Expt
2179 (%o4) ------------------------
2180 Product(2) + Expt + Expt
2182 (%i5) reveal (e, 4);
2185 (%o5) ------------------------------------
2186 Product(2) Product(2)
2188 (%i6) reveal (e, 5);
2191 (%o6) --------------------------
2194 (%i7) reveal (e, 6);
2197 (%o7) -------------------------
2202 @opencatbox{Categories:}
2203 @category{Expressions}
2204 @category{Display functions}
2208 @c -----------------------------------------------------------------------------
2210 @deffn {Function} sqrtdenest (@var{expr})
2211 Denests @code{sqrt} of simple, numerical, binomial surds, where possible. E.g.
2214 @c sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
2219 (%i1) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
2223 (%o1) ---------------------
2224 sqrt(11 sqrt(2) - 12)
2227 (%i2) sqrtdenest(%);
2237 Sometimes it helps to apply @code{sqrtdenest} more than once, on such as
2238 @code{(19601-13860 sqrt(2))^(7/4)}.
2240 @opencatbox{Categories:}
2241 @category{Expressions}
2246 @c NEEDS EXPANSION, CLARIFICATION, MORE EXAMPLES
2248 @c -----------------------------------------------------------------------------
2250 @deffn {Function} sublis (@var{list}, @var{expr})
2252 Makes multiple parallel substitutions into an expression. @var{list} is a list
2253 of equations. The left hand side of the equations must be an atom.
2255 The variable @mref{sublis_apply_lambda} controls simplification after
2258 See also @mref{psubst} for making parallel substitutions.
2263 @c sublis ([a=b, b=a], sin(a) + cos(b));
2267 (%i1) sublis ([a=b, b=a], sin(a) + cos(b));
2268 (%o1) sin(b) + cos(a)
2272 @opencatbox{Categories:}
2273 @category{Expressions}
2277 @c -----------------------------------------------------------------------------
2278 @anchor{sublis_apply_lambda}
2279 @defvr {Option variable} sublis_apply_lambda
2280 Default value: @code{true}
2282 Controls whether @code{lambda}'s substituted are applied in simplification after
2283 @code{sublis} is used or whether you have to do an @mref{ev} to get things to
2284 apply. @code{true} means do the application.
2286 @opencatbox{Categories:}
2287 @category{Expressions}
2291 @c -----------------------------------------------------------------------------
2293 @defvr {Option variable} subnumsimp
2294 Default value: @code{false}
2296 If @code{true} then the functions @mref{subst} and @mref{psubst} can substitute
2297 a subscripted variable @code{f[x]} with a number, when only the symbol @code{f}
2300 See also @mrefdot{subst}
2303 @c subst(100,g,g[x]+2);
2304 @c subst(100,g,g[x]+2),subnumsimp:true;
2307 (%i1) subst(100,g,g[x]+2);
2309 subst: cannot substitute 100 for operator g in expression g
2311 -- an error. To debug this try: debugmode(true);
2313 (%i2) subst(100,g,g[x]+2),subnumsimp:true;
2317 @opencatbox{Categories:}
2318 @category{Expressions}
2322 @c NEEDS CLARIFICATION, MORE EXAMPLES
2324 @c -----------------------------------------------------------------------------
2326 @deffn {Function} subst (@var{a}, @var{b}, @var{c})
2328 Substitutes @var{a} for @var{b} in @var{c}. @var{b} must be an atom or a
2329 complete subexpression of @var{c}. For example, @code{x+y+z} is a complete
2330 subexpression of @code{2*(x+y+z)/w} while @code{x+y} is not. When @var{b} does
2331 not have these characteristics, one may sometimes use @mref{substpart} or
2332 @mref{ratsubst} (see below). Alternatively, if @var{b} is of the form
2333 @code{e/f} then one could use @code{subst (a*f, e, c)} while if @var{b} is of
2334 the form @code{e^(1/f)} then one could use @code{subst (a^f, e, c)}. The
2335 @code{subst} command also discerns the @code{x^y} in @code{x^-y} so that
2336 @code{subst (a, sqrt(x), 1/sqrt(x))} yields @code{1/a}. @var{a} and @var{b}
2337 may also be operators of an expression enclosed in double-quotes @code{"} or
2338 they may be function names. If one wishes to substitute for the independent
2339 variable in derivative forms then the @code{at} function (see below) should be
2342 @c UMM, REVERSE THIS AND MOVE IT TO substitute ??
2343 @code{subst} is an alias for @code{substitute}.
2345 The commands @code{subst (@var{eq_1}, @var{expr})} or
2346 @code{subst ([@var{eq_1}, ..., @var{eq_k}], @var{expr})} are other permissible
2347 forms. The @var{eq_i} are equations indicating substitutions to be made.
2348 For each equation, the right side will be substituted for the left in the
2349 expression @var{expr}. The equations are substituted in serial from left to
2350 right in @var{expr}. See the functions @code{sublis} and @code{psubst} for
2351 making parallel substitutions.
2353 @mref{exptsubst} if @code{true} permits substitutions
2354 like @code{y} for @code{%e^x} in @code{%e^(a*x)} to take place.
2356 @c WHAT IS THIS ABOUT ??
2357 When @code{opsubst} is @code{false},
2358 @code{subst} will not attempt to substitute into the operator of an expression.
2359 E.g. @code{(opsubst: false, subst (x^2, r, r+r[0]))} will work.
2361 See also @mrefcomma{at} @mref{ev} and @mrefcomma{psubst} as well as @mref{let}
2362 and @mrefdot{letsimp}
2367 @c subst (a, x+y, x + (x+y)^2 + y);
2368 @c subst (-%i, %i, a + b*%i);
2372 (%i1) subst (a, x+y, x + (x+y)^2 + y);
2377 (%i2) subst (-%i, %i, a + b*%i);
2382 The substitution is done in serial for a list of equations. Compare this with
2383 a parallel substitution:
2386 @c subst([a=b, b=c], a+b);
2387 @c sublis([a=b, b=c], a+b);
2391 (%i1) subst([a=b, b=c], a+b);
2395 (%i2) sublis([a=b, b=c], a+b);
2400 Single-character Operators like @code{+} and @code{-} have to be quoted in
2401 order to be replaced by subst. It is to note, though, that @code{a+b-c}
2402 might be expressed as @code{a+b+(-1*c)} internally.
2405 @c subst(["+"="-"],a+b-c);
2408 (%i3) subst(["+"="-"],a+b-c);
2412 The difference between @code{subst} and @code{at} can be seen in the
2415 @c g1:y(t)=a*x(t)+b*diff(x(t),t);
2416 @c subst('diff(x(t),t)=1,g1);
2417 @c at(g1,'diff(x(t),t)=1);
2421 (%i1) g1:y(t)=a*x(t)+b*diff(x(t),t);
2423 (%o1) y(t) = b (-- (x(t))) + a x(t)
2427 (%i2) subst('diff(x(t),t)=1,g1);
2428 (%o2) y(t) = a x(t) + b
2431 (%i3) at(g1,'diff(x(t),t)=1);
2434 (%o3) y(t) = b (-- (x(t))! ) + a x(t)
2442 For further examples, do @code{example (subst)}.
2444 @opencatbox{Categories:}
2445 @category{Expressions}
2449 @c NEEDS CLARIFICATION
2451 @c ----------------------------------------------------------------------------
2452 @anchor{substinpart}
2453 @deffn {Function} substinpart (@var{x}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
2455 Similar to @mrefcomma{substpart} but @code{substinpart} works on the
2456 internal representation of @var{expr}.
2461 @c x . 'diff (f(x), x, 2);
2462 @c substinpart (d^2, %, 2);
2463 @c substinpart (f1, f[1](x + 1), 0);
2467 (%i1) x . 'diff (f(x), x, 2);
2470 (%o1) x . (--- (f(x)))
2475 (%i2) substinpart (d^2, %, 2);
2480 (%i3) substinpart (f1, f[1](x + 1), 0);
2485 If the last argument to a @code{part} function is a list of indices then
2486 several subexpressions are picked out, each one corresponding to an
2487 index of the list. Thus
2490 @c part (x + y + z, [1, 3]);
2494 (%i1) part (x + y + z, [1, 3]);
2499 @mref{piece} holds the value of the last expression selected when using the
2500 @code{part} functions. It is set during the execution of the function and
2501 thus may be referred to in the function itself as shown below.
2502 If @mref{partswitch} is set to @code{true} then @code{end} is returned when a
2503 selected part of an expression doesn't exist, otherwise an error
2507 @c expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
2508 @c part (expr, 2, [1, 3]);
2510 @c substpart (factor (piece), expr, [1, 2, 3, 5]);
2511 @c expr: 1/x + y/x - 1/z;
2512 @c substpart (xthru (piece), expr, [2, 3]);
2516 (%i1) expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
2518 (%o1) 27 y + 54 x y + 36 x y + y + 8 x + x + 1
2521 (%i2) part (expr, 2, [1, 3]);
2526 (%i3) sqrt (piece/54);
2530 (%i4) substpart (factor (piece), expr, [1, 2, 3, 5]);
2532 (%o4) (3 y + 2 x) + y + x + 1
2535 (%i5) expr: 1/x + y/x - 1/z;
2541 (%i6) substpart (xthru (piece), expr, [2, 3]);
2548 Also, setting the option @mref{inflag} to @code{true} and calling @mref{part}
2549 or @mref{substpart} is the same as calling @mref{inpart} or @code{substinpart}.
2551 @opencatbox{Categories:}
2552 @category{Expressions}
2556 @c NEEDS CLARIFICATION
2558 @c -----------------------------------------------------------------------------
2560 @deffn {Function} substpart (@var{x}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
2562 Substitutes @var{x} for the subexpression picked out by the rest of the
2563 arguments as in @mrefdot{part} It returns the new value of @var{expr}. @var{x}
2564 may be some operator to be substituted for an operator of @var{expr}. In some
2565 cases @var{x} needs to be enclosed in double-quotes @code{"} (e.g.
2566 @code{substpart ("+", a*b, 0)} yields @code{b + a}).
2572 @c substpart (3/2, %, 2, 1, 2);
2574 @c substpart ("+", %, 1, 0);
2585 (%i2) substpart (3/2, %, 2, 1, 2);
2592 (%i3) a*x + f(b, y);
2596 (%i4) substpart ("+", %, 1, 0);
2597 (%o4) x + f(b, y) + a
2601 Also, setting the option @mref{inflag} to @code{true} and calling @mref{part}
2602 or @code{substpart} is the same as calling @code{inpart} or
2603 @mrefdot{substinpart}
2605 @opencatbox{Categories:}
2606 @category{Expressions}
2610 @c -----------------------------------------------------------------------------
2612 @deffn {Function} symbolp (@var{expr})
2614 Returns @code{true} if @var{expr} is a symbol, else @code{false}.
2616 @c FOLLOWING REALLY WANTS TO BE @xref{Identiifers} BUT THAT
2617 @c LEAVES THE UNPLEASANT RESIDUE *Note ...:: IN THE OUTPUT OF describe
2618 See also @ref{Identifiers}.
2620 @opencatbox{Categories:}
2621 @category{Predicate functions}
2625 @c -----------------------------------------------------------------------------
2627 @deffn {Function} unorder ()
2629 Disables the aliasing created by the last use of the ordering commands
2630 @code{ordergreat} and @code{orderless}. @code{ordergreat} and @code{orderless}
2631 may not be used more than one time each without calling @code{unorder}.
2632 @code{unorder} does not substitute back in expressions the original symbols for
2633 the aliases introduced by @code{ordergreat} and @code{orderless}. Therefore,
2634 after execution of @code{unorder} the aliases appear in previous expressions.
2636 See also @code{ordergreat} and @code{orderless}.
2640 @code{ordergreat(a)} introduces an alias for the symbol @code{a}. Therefore,
2641 the difference of @code{%o2} and @code{%o4} does not vanish. @code{unorder}
2642 does not substitute back the symbol @code{a} and the alias appears in the
2665 (%i3) ordergreat (a);
2685 @opencatbox{Categories:}
2686 @category{Expressions}
2690 @c -----------------------------------------------------------------------------
2692 @deffn {Function} verbify (@var{f})
2694 Returns the verb form of the function name @var{f}.
2695 See also @code{verb}, @code{noun}, and @code{nounify}.
2707 (%i1) verbify ('foo);
2715 (%i2) nounify (foo);
2724 @opencatbox{Categories:}
2725 @category{Nouns and verbs}