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 ALPHA-CHAR-P returns @code{true}.
188 Characters may be declared alphabetic by the @code{declare} function.
189 If so declared, they need not be preceded by a backslash in an identifier.
191 Maxima is case-sensitive. The identifiers @code{foo}, @code{FOO}, and
192 @code{Foo} are distinct. See @ref{Lisp and Maxima} for more on this point.
194 A Maxima identifier is a Lisp symbol which begins with a dollar sign @code{$}.
195 Any other Lisp symbol is preceded by a question mark @code{?} when it appears
196 in Maxima. See @ref{Lisp and Maxima} for more on this point.
201 @c %an_ordinary_identifier42;
202 @c embedded\ spaces\ in\ an\ identifier;
204 @c [foo+bar, foo\+bar];
206 @c [symbolp (foo\+bar), symbolp (\1729)];
207 @c [is (foo\+bar = foo+bar), is (\1729 = 1729)];
209 @c declare ("~", alphabetic);
211 @c [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
212 @c :lisp (defvar *my-lisp-variable* '$foo)
213 @c ?\*my\-lisp\-variable\*;
217 (%i1) %an_ordinary_identifier42;
218 (%o1) %an_ordinary_identifier42
221 (%i2) embedded\ spaces\ in\ an\ identifier;
222 (%o2) embedded spaces in an identifier
229 (%i4) [foo+bar, foo\+bar];
230 (%o4) [foo + bar, foo+bar]
237 (%i6) [symbolp (foo\+bar), symbolp (\1729)];
241 (%i7) [is (foo\+bar = foo+bar), is (\1729 = 1729)];
249 (%i9) declare ("~", alphabetic);
257 (%i11) [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
258 (%o11) [false, false, false]
261 (%i12) :lisp (defvar *my-lisp-variable* '$foo)
265 (%i12) ?\*my\-lisp\-variable\*;
270 @opencatbox{Categories:}
274 @c -----------------------------------------------------------------------------
275 @node Inequality, Functions and Variables for Expressions, Identifiers, Expressions
277 @c -----------------------------------------------------------------------------
279 Maxima has the inequality operators @code{<}, @code{<=}, @code{>=}, @code{>},
280 @code{#}, and @code{notequal}. See @code{if} for a description of conditional
283 @c -----------------------------------------------------------------------------
284 @node Functions and Variables for Expressions, , Inequality, Expressions
285 @section Functions and Variables for Expressions
286 @c -----------------------------------------------------------------------------
288 @c NEEDS WORK, ESPECIALLY EXAMPLES
290 @c -----------------------------------------------------------------------------
292 @deffn {Function} alias (@var{new_name_1}, @var{old_name_1}, @dots{}, @var{new_name_n}, @var{old_name_n})
294 provides an alternate name for a (user or system) function, variable, array,
295 etc. Any even number of arguments may be used.
297 @opencatbox{Categories:}
298 @category{Declarations and inferences}
302 @c -----------------------------------------------------------------------------
304 @defvr {System variable} aliases
305 Default value: @code{[]}
307 @code{aliases} is the list of atoms which have a user defined alias (set up by
308 the @mrefcomma{alias} @mrefcomma{ordergreat} @mref{orderless} functions or by
309 declaring the atom a @mref{noun} with @mrefdot{declare})
311 @opencatbox{Categories:}
312 @category{Declarations and inferences}
313 @category{Global variables}
317 @c NEEDS TO BE REWORKED. NOT CONVINCED THIS SYMBOL NEEDS ITS OWN ITEM
318 @c (SHOULD BE DESCRIBED IN CONTEXT OF EACH FUNCTION WHICH RECOGNIZES IT)
320 @c -----------------------------------------------------------------------------
322 @defvr {Keyword} allbut
324 works with the @code{part} commands (i.e. @mrefcomma{part}@w{}
325 @mrefcomma{inpart} @mrefcomma{substpart} @mrefcomma{substinpart}@w{}
326 @mrefcomma{dpart} and @mref{lpart}).
330 @c expr : e + d + c + b + a;
331 @c part (expr, [2, 5]);
335 (%i1) expr : e + d + c + b + a;
336 (%o1) e + d + c + b + a
339 (%i2) part (expr, [2, 5]);
347 @c expr : e + d + c + b + a;
348 @c part (expr, allbut (2, 5));
352 (%i1) expr : e + d + c + b + a;
353 (%o1) e + d + c + b + a
356 (%i2) part (expr, allbut (2, 5));
361 @code{allbut} is also recognized by @mrefdot{kill}
364 @c [aa : 11, bb : 22, cc : 33, dd : 44, ee : 55];
365 @c kill (allbut (cc, dd));
370 (%i1) [aa : 11, bb : 22, cc : 33, dd : 44, ee : 55];
371 (%o1) [11, 22, 33, 44, 55]
374 (%i2) kill (allbut (cc, dd));
378 (%i1) [aa, bb, cc, dd];
379 (%o1) [aa, bb, 33, 44]
383 @code{kill(allbut(@var{a_1}, @var{a_2}, ...))} has the effect of
384 @code{kill(all)} except that it does not kill the symbols @var{a_1}, @var{a_2},
388 @c -----------------------------------------------------------------------------
390 @deffn {Function} args (@var{expr})
392 Returns the list of arguments of @code{expr}, which may be any kind of
393 expression other than an atom. Only the arguments of the top-level operator
394 are extracted; subexpressions of @code{expr} appear as elements or
395 subexpressions of elements of the list of arguments.
397 The order of the items in the list may depend on the global flag
400 @code{args (@var{expr})} is equivalent to @code{substpart ("[", @var{expr}, 0)}.
401 See also @mrefcomma{substpart} @mrefcomma{apply} @mrefcomma{funmake} and @mrefdot{op}
403 How to convert a matrix to a nested list:
406 @c M:matrix([1,2],[3,4]);
411 (%i1) M:matrix([1,2],[3,4]);
418 (%o2) [[1, 2], [3, 4]]
422 Since maxima internally treats a sum of @code{n} terms as a summation command
423 with @code{n} arguments args() can extract the list of terms in a sum:
442 @opencatbox{Categories:}
443 @category{Expressions}
448 @c SPLIT OFF EXAMPLES INTO EXAMPLE SECTION
450 @c -----------------------------------------------------------------------------
452 @deffn {Function} atom (@var{expr})
454 Returns @code{true} if @var{expr} is atomic (i.e. a number, name or string) else
455 @code{false}. Thus @code{atom(5)} is @code{true} while @code{atom(a[1])} and
456 @code{atom(sin(x))} are @code{false} (assuming @code{a[1]} and @code{x} are
459 @opencatbox{Categories:}
460 @category{Expressions}
461 @category{Predicate functions}
465 @c -----------------------------------------------------------------------------
467 @deffn {Function} box @
468 @fname{box} (@var{expr}) @
469 @fname{box} (@var{expr}, @var{a})
471 Returns @var{expr} enclosed in a box. The return value is an expression with
472 @code{box} as the operator and @var{expr} as the argument. A box is drawn on
473 the display when @mref{display2d} is @code{true}.
475 @code{box (@var{expr}, @var{a})} encloses @var{expr} in a box labelled by the
476 symbol @var{a}. The label is truncated if it is longer than the width of the
479 @code{box} evaluates its argument. However, a boxed expression does not
480 evaluate to its content, so boxed expressions are effectively excluded from
481 computations. @mref{rembox} removes the box again.
483 @mref{boxchar} is the character used to draw the box in @code{box} and in the
484 @mref{dpart} and @mref{lpart} functions.
486 See also @mrefcomma{rembox} @mref{dpart} and @mrefdot{lpart}
495 @c box (a^2 + b^2, term_1);
496 @c 1729 - box (1729);
498 @c box (sin(x) + cos(y));
502 (%i1) box (a^2 + b^2);
517 (%i4) box (a^2 + b^2);
520 (%o4) "(c - d) + 1522756"
524 (%i5) box (a^2 + b^2, term_1);
527 (%o5) "(c - d) + 1522756"
531 (%i6) 1729 - box (1729);
541 (%i8) box (sin(x) + cos(y));
543 (%o8) -cos(y) + sin(x)-
548 @opencatbox{Categories:}
549 @category{Expressions}
553 @c -----------------------------------------------------------------------------
555 @defvr {Option variable} boxchar
556 Default value: @code{"}
558 @code{boxchar} is the character used to draw the box in the @mref{box}@w{}
559 and in the @mref{dpart} and @mref{lpart} functions.
561 All boxes in an expression are drawn with the current value of @code{boxchar};
562 the drawing character is not stored with the box expression.
564 @opencatbox{Categories:}
565 @category{Expressions}
569 @c NEEDS CLARIFICATION !!!
571 @c -----------------------------------------------------------------------------
573 @deffn {Function} collapse (@var{expr})
575 Collapses @var{expr} by causing all of its common (i.e., equal) subexpressions
576 to share (i.e., use the same cells), thereby saving space. (@code{collapse} is
577 a subroutine used by the @mref{optimize} command.) Thus, calling
578 @code{collapse} may be useful after loading in a @mref{save} file. You can
579 collapse several expressions together by using
580 @code{collapse ([@var{expr_1}, ..., @var{expr_n}])}. Similarly, you can
581 collapse the elements of the array @code{A} by doing
582 @code{collapse (listarray ('A))}.
584 @opencatbox{Categories:}
585 @category{Expressions}
589 @c -----------------------------------------------------------------------------
591 @deffn {Function} copy (@var{e})
593 Return a copy of the Maxima expression @var{e}. Although @var{e} can be any
594 Maxima expression, the copy function is the most useful when @var{e} is either
595 a list or a matrix; consider:
618 Let's try the same experiment, but this time let @var{mm} be a copy of @var{m}
641 This time, the assignment to @var{mm} does not change the value of @var{m}.
643 @opencatbox{Categories:}
644 @category{Expressions}
650 @c -----------------------------------------------------------------------------
652 @deffn {Function} disolate (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
654 is similar to @mref{isolate}@code{ (@var{expr}, @var{x})} except that it enables the
655 user to isolate more than one variable simultaneously. This might be useful,
656 for example, if one were attempting to change variables in a multiple
657 integration, and that variable change involved two or more of the integration
658 variables. This function is autoloaded from @file{simplification/disol.mac}.
659 A demo is available by @code{demo("disol")$}.
661 @opencatbox{Categories:}
662 @category{Expressions}
666 @c -----------------------------------------------------------------------------
668 @deffn {Function} dispform @
669 @fname{dispform} (@var{expr}) @
670 @fname{dispform} (@var{expr}, all)
672 Returns the external representation of @var{expr}.
674 @code{dispform(@var{expr})} returns the external representation with respect to
675 the main (top-level) operator. @code{dispform(@var{expr}, all)} returns the
676 external representation with respect to all operators in @var{expr}.
678 See also @mrefcomma{part} @mrefcomma{inpart} and @mrefdot{inflag}
682 The internal representation of @code{- x} is "negative one times @code{x}"
683 while the external representation is "minus @code{x}".
687 @c ?format (true, "~S~%", %);
689 @c ?format (true, "~S~%", %);
697 (%i2) ?format (true, "~S~%", %);
698 ((MTIMES SIMP) -1 $X)
702 (%i3) dispform (- x);
706 (%i4) ?format (true, "~S~%", %);
712 The internal representation of @code{sqrt(x)} is "@code{x} to the power 1/2"
713 while the external representation is "square root of @code{x}".
717 @c ?format (true, "~S~%", %);
718 @c dispform (sqrt (x));
719 @c ?format (true, "~S~%", %);
727 (%i2) ?format (true, "~S~%", %);
728 ((MEXPT SIMP) $X ((RAT SIMP) 1 2))
732 (%i3) dispform (sqrt (x));
736 (%i4) ?format (true, "~S~%", %);
742 Use of the optional argument @code{all}.
745 @c expr : sin (sqrt (x));
746 @c freeof (sqrt, expr);
747 @c freeof (sqrt, dispform (expr));
748 @c freeof (sqrt, dispform (expr, all));
752 (%i1) expr : sin (sqrt (x));
756 (%i2) freeof (sqrt, expr);
760 (%i3) freeof (sqrt, dispform (expr));
764 (%i4) freeof (sqrt, dispform (expr, all));
769 @opencatbox{Categories:}
770 @category{Expressions}
776 @c -----------------------------------------------------------------------------
778 @deffn {Function} dpart (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
780 Selects the same subexpression as @mrefcomma{part} but instead of just returning
781 that subexpression as its value, it returns the whole expression with the
782 selected subexpression displayed inside a box. The box is actually part of the
786 @c dpart (x+y/z^2, 1, 2, 1);
789 (%i1) dpart (x+y/z^2, 1, 2, 1);
798 @opencatbox{Categories:}
799 @category{Expressions}
803 @c -----------------------------------------------------------------------------
805 @defvr {Option variable} exptisolate
806 Default value: @code{false}
808 @c WHAT DOES THIS MEAN EXACTLY ??
809 @code{exptisolate}, when @code{true}, causes @code{isolate (expr, var)} to
810 examine exponents of atoms (such as @code{%e}) which contain @code{var}.
812 @c NEED EXAMPLES HERE
813 @opencatbox{Categories:}
814 @category{Expressions}
818 @c -----------------------------------------------------------------------------
820 @defvr {Option variable} exptsubst
821 Default value: @code{false}
823 @code{exptsubst}, when @code{true}, permits substitutions such as @code{y}
824 for @code{%e^x} in @code{%e^(a x)}.
829 @c subst(y, %e^x, %e^(a*x));
830 @c exptsubst: not exptsubst;
831 @c subst(y, %e^x, %e^(a*x));
844 (%i3) subst(y, %e^x, %e^(a*x));
849 (%i4) exptsubst: not exptsubst;
853 (%i5) subst(y, %e^x, %e^(a*x));
859 @opencatbox{Categories:}
860 @category{Exponential and logarithm functions}
861 @category{Expressions}
865 @c -----------------------------------------------------------------------------
867 @deffn {Function} freeof (@var{x_1}, @dots{}, @var{x_n}, @var{expr})
869 @code{freeof (@var{x_1}, @var{expr})} returns @code{true} if no subexpression of
870 @var{expr} is equal to @var{x_1} or if @var{x_1} occurs only as a dummy variable
871 in @var{expr}, or if @var{x_1} is neither the noun nor verb form of any operator
872 in @var{expr}, and returns @code{false} otherwise.
874 @code{freeof (@var{x_1}, ..., @var{x_n}, @var{expr})} is equivalent to
875 @code{freeof (@var{x_1}, @var{expr}) and ... and freeof (@var{x_n},
878 The arguments @var{x_1}, @dots{}, @var{x_n} may be names of functions and
879 variables, subscripted names, operators (enclosed in double quotes), or general
880 expressions. @code{freeof} evaluates its arguments.
882 @code{freeof} operates only on @var{expr} as it stands (after simplification and
883 evaluation) and does not attempt to determine if some equivalent expression
884 would give a different result. In particular, simplification may yield an
885 equivalent but different expression which comprises some different elements than
886 the original form of @var{expr}.
888 A variable is a dummy variable in an expression if it has no binding outside of
889 the expression. Dummy variables recognized by @code{freeof} are the index of a
890 sum or product, the limit variable in @mrefcomma{limit} the integration variable
891 in the definite integral form of @mref{integrate}, the original variable in
892 @mrefcomma{laplace} formal variables in @mref{at} expressions, and arguments in
893 @mref{lambda} expressions.
895 The indefinite form of @code{integrate} is @i{not} free of its variable of
900 Arguments are names of functions, variables, subscripted names, operators, and
901 expressions. @code{freeof (a, b, expr)} is equivalent to
902 @code{freeof (a, expr) and freeof (b, expr)}.
905 @c expr: z^3 * cos (a[1]) * b^(c+d);
907 @c freeof (cos, expr);
908 @c freeof (a[1], expr);
909 @c freeof (cos (a[1]), expr);
910 @c freeof (b^(c+d), expr);
911 @c freeof ("^", expr);
912 @c freeof (w, sin, a[2], sin (a[2]), b*(c+d), expr);
915 (%i1) expr: z^3 * cos (a[1]) * b^(c+d);
919 (%i2) freeof (z, expr);
921 (%i3) freeof (cos, expr);
923 (%i4) freeof (a[1], expr);
925 (%i5) freeof (cos (a[1]), expr);
927 (%i6) freeof (b^(c+d), expr);
929 (%i7) freeof ("^", expr);
931 (%i8) freeof (w, sin, a[2], sin (a[2]), b*(c+d), expr);
935 @code{freeof} evaluates its arguments.
945 (%i3) freeof (c, expr);
949 @code{freeof} does not consider equivalent expressions.
950 Simplification may yield an equivalent but different expression.
956 @c freeof (a+b, expr);
958 @c freeof (exp, exp (x));
964 (%o2) b + 5 a b + 10 a b + 10 a b + 5 a b + a
965 (%i3) freeof (a+b, %);
967 (%i4) freeof (a+b, expr);
972 (%i6) freeof (exp, exp (x));
976 A summation or definite integral is free of its dummy variable.
977 An indefinite integral is not free of its variable of integration.
980 @c freeof (i, 'sum (f(i), i, 0, n));
981 @c freeof (x, 'integrate (x^2, x, 0, 1));
982 @c freeof (x, 'integrate (x^2, x));
985 (%i1) freeof (i, 'sum (f(i), i, 0, n));
987 (%i2) freeof (x, 'integrate (x^2, x, 0, 1));
989 (%i3) freeof (x, 'integrate (x^2, x));
993 @opencatbox{Categories:}
994 @category{Expressions}
998 @c -----------------------------------------------------------------------------
1000 @defvr {Option variable} inflag
1001 Default value: @code{false}
1003 When @code{inflag} is @code{true}, functions for part extraction inspect the
1004 internal form of @code{expr}.
1006 Note that the simplifier re-orders expressions. Thus @code{first (x + y)}
1007 returns @code{x} if @code{inflag} is @code{true} and @code{y} if @code{inflag}
1008 is @code{false}. (@code{first (y + x)} gives the same results.)
1010 Also, setting @code{inflag} to @code{true} and calling @mref{part} or
1011 @mref{substpart} is the same as calling @mref{inpart} or @mrefdot{substinpart}
1013 Functions affected by the setting of @code{inflag} are: @mrefcomma{part}@w{}
1014 @mrefcomma{substpart} @mrefcomma{first} @mrefcomma{rest} @mrefcomma{last}@w{}
1015 @mrefcomma{length} the @mref{for} @dots{} @code{in} construct,
1016 @mrefcomma{map} @mrefcomma{fullmap} @mrefcomma{maplist} @mref{reveal} and
1019 @c NEED EXAMPLES HERE
1020 @opencatbox{Categories:}
1021 @category{Expressions}
1027 @c -----------------------------------------------------------------------------
1029 @deffn {Function} inpart (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
1031 is similar to @mref{part} but works on the internal representation of the
1032 expression rather than the displayed form and thus may be faster since no
1033 formatting is done. Care should be taken with respect to the order of
1034 subexpressions in sums and products (since the order of variables in the
1035 internal form is often different from that in the displayed form) and in dealing
1036 with unary minus, subtraction, and division (since these operators are removed
1037 from the expression). @code{part (x+y, 0)} or @code{inpart (x+y, 0)} yield
1038 @code{+}, though in order to refer to the operator it must be enclosed in "s.
1039 For example @code{... if inpart (%o9,0) = "+" then ...}.
1045 @c inpart (%, 3, 2);
1046 @c part (%th (2), 1, 2);
1047 @c 'limit (f(x)^g(x+1), x, 0, minus);
1048 @c inpart (%, 1, 2);
1053 (%i2) inpart (%, 3, 2);
1055 (%i3) part (%th (2), 1, 2);
1057 (%i4) 'limit (f(x)^g(x+1), x, 0, minus);
1061 (%i5) inpart (%, 1, 2);
1065 @opencatbox{Categories:}
1066 @category{Expressions}
1072 @c -----------------------------------------------------------------------------
1074 @deffn {Function} isolate (@var{expr}, @var{x})
1076 Returns @var{expr} with subexpressions which are sums and which do not contain
1077 @var{var} replaced by intermediate expression labels (these being atomic symbols
1078 like @code{%t1}, @code{%t2}, @dots{}). This is often useful to avoid
1079 unnecessary expansion of subexpressions which don't contain the variable of
1080 interest. Since the intermediate labels are bound to the subexpressions they
1081 can all be substituted back by evaluating the expression in which they occur.
1083 @mref{exptisolate} (default value: @code{false}) if @code{true} will cause
1084 @code{isolate} to examine exponents of atoms (like @code{%e}) which contain
1087 @code{isolate_wrt_times} if @code{true}, then @code{isolate} will also isolate
1088 with respect to products. See @mrefdot{isolate_wrt_times} See also @mrefdot{disolate}
1091 Do @code{example (isolate)} for examples.
1093 @opencatbox{Categories:}
1094 @category{Expressions}
1100 @c -----------------------------------------------------------------------------
1101 @anchor{isolate_wrt_times}
1102 @defvr {Option variable} isolate_wrt_times
1103 Default value: @code{false}
1105 When @code{isolate_wrt_times} is @code{true}, @code{isolate} will also isolate
1106 with respect to products. E.g. compare both settings of the switch on
1109 (%i1) isolate_wrt_times: true$
1110 (%i2) isolate (expand ((a+b+c)^2), c);
1121 (%o4) c + %t3 c + %t2 c + %t4
1122 (%i4) isolate_wrt_times: false$
1123 (%i5) isolate (expand ((a+b+c)^2), c);
1125 (%o5) c + 2 b c + 2 a c + %t4
1128 @opencatbox{Categories:}
1129 @category{Expressions}
1135 @c -----------------------------------------------------------------------------
1136 @anchor{listconstvars}
1137 @defvr {Option variable} listconstvars
1138 Default value: @code{false}
1140 When @code{listconstvars} is @code{true} the list returned by
1141 @code{listofvars} contains constant variables, such as @code{%e},
1142 @code{%pi}, @code{%i} or any variables declared as constant that
1143 occur in @var{expr}. A variable is declared as @code{constant}
1144 type via @mref{declare}, and @mref{constantp} returns @code{true}
1145 for all variables declared as @code{constant}. The default is to
1146 omit constant variables from @code{listofvars} return value.
1148 @opencatbox{Categories:}
1149 @category{Expressions}
1153 @c -----------------------------------------------------------------------------
1154 @anchor{listdummyvars}
1155 @defvr {Option variable} listdummyvars
1156 Default value: @code{true}
1158 When @code{listdummyvars} is @code{false}, "dummy variables" in the expression
1159 will not be included in the list returned by @mrefdot{listofvars} (The meaning
1160 of "dummy variables" is as given in @mrefdot{freeof} "Dummy variables" are
1161 mathematical things like the index of a sum or product, the limit variable,
1162 and the definite integration variable.)
1167 @c listdummyvars: true$
1168 @c listofvars ('sum(f(i), i, 0, n));
1169 @c listdummyvars: false$
1170 @c listofvars ('sum(f(i), i, 0, n));
1173 (%i1) listdummyvars: true$
1174 (%i2) listofvars ('sum(f(i), i, 0, n));
1176 (%i3) listdummyvars: false$
1177 (%i4) listofvars ('sum(f(i), i, 0, n));
1181 @opencatbox{Categories:}
1182 @category{Expressions}
1188 @c -----------------------------------------------------------------------------
1190 @deffn {Function} listofvars (@var{expr})
1192 Returns a list of the variables in @var{expr}.
1194 @mref{listconstvars} if @code{true} causes @code{listofvars} to include
1195 @code{%e}, @code{%pi}, @code{%i}, and any variables declared constant in the
1196 list it returns if they appear in @var{expr}. The default is to omit these.
1198 See also the option variable @mref{listdummyvars} to exclude or include
1199 "dummy variables" in the list of variables.
1202 @c listofvars (f (x[1]+y) / g^(2+a));
1205 (%i1) listofvars (f (x[1]+y) / g^(2+a));
1210 @opencatbox{Categories:}
1211 @category{Expressions}
1217 @c -----------------------------------------------------------------------------
1219 @deffn {Function} lfreeof (@var{list}, @var{expr})
1221 For each member @var{m} of @var{list}, calls
1222 @code{freeof (@var{m}, @var{expr})}. It returns @code{false} if any call to
1223 @mref{freeof} does and @code{true} otherwise.
1228 @c lfreeof ([ a, x], x^2+b);
1229 @c lfreeof ([ b, x], x^2+b);
1230 @c lfreeof ([ a, y], x^2+b);
1234 (%i1) lfreeof ([ a, x], x^2+b);
1238 (%i2) lfreeof ([ b, x], x^2+b);
1242 (%i3) lfreeof ([ a, y], x^2+b);
1247 @opencatbox{Categories:}
1248 @category{Expressions}
1254 @c -----------------------------------------------------------------------------
1256 @deffn {Function} lpart (@var{label}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
1258 is similar to @mref{dpart} but uses a labelled box. A labelled box is similar
1259 to the one produced by @code{dpart} but it has a name in the top line.
1261 @opencatbox{Categories:}
1262 @category{Expressions}
1266 @c NEEDS CLARIFICATION, EXAMPLES
1268 @c -----------------------------------------------------------------------------
1270 @defvr {Property} mainvar
1272 You may declare variables to be @code{mainvar}. The ordering scale for atoms is
1273 essentially: numbers @code{<} constants (e.g., @code{%e}, @code{%pi}) @code{<} scalars @code{<} other
1274 variables @code{<} mainvars. E.g., compare @code{expand ((X+Y)^4)} with
1275 @code{(declare (x, mainvar), expand ((x+y)^4))}. (Note: Care should be taken if
1276 you elect to use the above feature. E.g., if you subtract an expression in
1277 which @code{x} is a @code{mainvar} from one in which @code{x} isn't a
1278 @code{mainvar}, resimplification e.g. with @code{ev (expr, simp)} may be
1279 necessary if cancellation is to occur. Also, if you save an expression in which
1280 @code{x} is a @code{mainvar}, you probably should also save @code{x}.)
1282 @opencatbox{Categories:}
1283 @category{Declarations and inferences}
1284 @category{Expressions}
1288 @c NEEDS CLARIFICATION, EXAMPLES
1290 @c -----------------------------------------------------------------------------
1292 @defvr {Property} noun
1294 @code{noun} is one of the options of the @mref{declare} command. It makes a
1295 function so declared a "noun", meaning that it won't be evaluated
1301 @c factor (12345678);
1302 @c declare (factor, noun);
1303 @c factor (12345678);
1308 (%i1) factor (12345678);
1313 (%i2) declare (factor, noun);
1317 (%i3) factor (12345678);
1318 (%o3) factor(12345678)
1327 @opencatbox{Categories:}
1328 @category{Nouns and verbs}
1332 @c NEEDS CLARIFICATION, EXAMPLES
1334 @c -----------------------------------------------------------------------------
1336 @defvr {Option variable} noundisp
1337 Default value: @code{false}
1339 When @code{noundisp} is @code{true}, nouns display with
1340 a single quote. This switch is always @code{true} when displaying function
1343 @opencatbox{Categories:}
1344 @category{Display flags and variables}
1345 @category{Nouns and verbs}
1351 @c -----------------------------------------------------------------------------
1353 @deffn {Function} nounify (@var{f})
1355 Returns the noun form of the function name @var{f}. This is
1356 needed if one wishes to refer to the name of a verb function as if it
1357 were a noun. Note that some verb functions will return their noun
1358 forms if they can't be evaluated for certain arguments. This is also
1359 the form returned if a function call is preceded by a quote.
1361 See also @mrefdot{verbify}
1363 @opencatbox{Categories:}
1364 @category{Nouns and verbs}
1370 @c -----------------------------------------------------------------------------
1372 @deffn {Function} nterms (@var{expr})
1374 Returns the number of terms that @var{expr} would have if it were fully
1375 expanded out and no cancellations or combination of terms occurred.
1376 Note that expressions like @code{sin (@var{expr})}, @code{sqrt (@var{expr})},
1377 @code{exp (@var{expr})}, etc. count as just one term regardless of how many
1378 terms @var{expr} has (if it is a sum).
1380 @opencatbox{Categories:}
1381 @category{Expressions}
1387 @c -----------------------------------------------------------------------------
1389 @deffn {Function} op (@var{expr})
1391 Returns the main operator of the expression @var{expr}.
1392 @code{op (@var{expr})} is equivalent to @code{part (@var{expr}, 0)}.
1394 @code{op} returns a string if the main operator is a built-in or user-defined
1395 prefix, binary or n-ary infix, postfix, matchfix, or nofix operator.
1396 Otherwise, if @var{expr} is a subscripted function expression, @code{op}
1397 returns the subscripted function; in this case the return value is not an atom.
1398 Otherwise, @var{expr} is a @mref{memoizing function} or ordinary function expression,
1399 and @code{op} returns a symbol.
1401 @code{op} observes the value of the global flag @mrefdot{inflag}
1403 @code{op} evaluates it argument.
1405 See also @mrefdot{args}
1410 @c stringdisp: true$
1413 @c op ('sin (a + b));
1417 @c op ('(if a > b then c else d));
1421 @c op (F [x, y] (a, b, c));
1422 @c op (G [u, v, w]);
1425 (%i1) stringdisp: true$
1427 (%i2) op (a * b * c);
1431 (%i3) op (a * b + c);
1435 (%i4) op ('sin (a + b));
1447 (%i7) op ([a, b, c]);
1451 (%i8) op ('(if a > b then c else d));
1455 (%i9) op ('foo (a));
1459 (%i10) prefix (foo);
1467 (%i12) op (F [x, y] (a, b, c));
1472 (%i13) op (G [u, v, w]);
1477 @opencatbox{Categories:}
1478 @category{Expressions}
1479 @category{Operators}
1485 @c -----------------------------------------------------------------------------
1487 @deffn {Function} operatorp @
1488 @fname{operatorp} (@var{expr}, @var{op}) @
1489 @fname{operatorp} (@var{expr}, [@var{op_1}, @dots{}, @var{op_n}])
1491 @code{operatorp (@var{expr}, @var{op})} returns @code{true}
1492 if @var{op} is equal to the operator of @var{expr}.
1494 @code{operatorp (@var{expr}, [@var{op_1}, ..., @var{op_n}])} returns
1495 @code{true} if some element @var{op_1}, @dots{}, @var{op_n} is equal to the
1496 operator of @var{expr}.
1498 @opencatbox{Categories:}
1499 @category{Operators}
1500 @category{Predicate functions}
1504 @c NEEDS CLARIFICATION, EXAMPLES
1506 @c -----------------------------------------------------------------------------
1507 @anchor{option_opsubst}
1508 @defvr {Option variable} opsubst
1509 Default value: @code{true}
1511 When @code{opsubst} is @code{false}, @mref{subst} does not attempt to
1512 substitute into the operator of an expression. E.g.,
1513 @code{(opsubst: false, subst (x^2, r, r+r[0]))} will work.
1518 @c subst (x^2, r, r+r[0]);
1519 @c opsubst: not opsubst;
1520 @c subst (x^2, r, r+r[0]);
1533 (%i3) subst (x^2, r, r+r[0]);
1539 (%i4) opsubst: not opsubst;
1543 (%i5) subst (x^2, r, r+r[0]);
1550 @opencatbox{Categories:}
1551 @category{Expressions}
1557 @c -----------------------------------------------------------------------------
1559 @deffn {Function} optimize (@var{expr})
1561 Returns an expression that produces the same value and
1562 side effects as @var{expr} but does so more efficiently by avoiding the
1563 recomputation of common subexpressions. @code{optimize} also has the side
1564 effect of "collapsing" its argument so that all common subexpressions
1565 are shared. Do @code{example (optimize)} for examples.
1567 @opencatbox{Categories:}
1568 @category{Expressions}
1573 @c -----------------------------------------------------------------------------
1574 @anchor{optimprefix}
1575 @defvr {Option variable} optimprefix
1576 Default value: @code{%}
1578 @code{optimprefix} is the prefix used for generated symbols by
1579 the @mref{optimize} command.
1581 @opencatbox{Categories:}
1582 @category{Expressions}
1586 @c -----------------------------------------------------------------------------
1589 @deffn {Function} ordergreat (@var{v_1}, @dots{}, @var{v_n})
1590 @deffnx {Function} orderless (@var{v_1}, @dots{}, @var{v_n})
1592 @code{ordergreat} changes the canonical ordering of Maxima expressions
1593 such that @var{v_1} succeeds @var{v_2} succeeds @dots{} succeeds @var{v_n},
1594 and @var{v_n} succeeds any other symbol not mentioned as an argument.
1596 @code{orderless} changes the canonical ordering of Maxima expressions
1597 such that @var{v_1} precedes @var{v_2} precedes @dots{} precedes @var{v_n},
1598 and @var{v_n} precedes any other variable not mentioned as an argument.
1600 The order established by @code{ordergreat} and @code{orderless} is dissolved
1601 by @mrefdot{unorder} @code{ordergreat} and @code{orderless} can be called only
1602 once each, unless @code{unorder} is called; only the last call to
1603 @code{ordergreat} and @code{orderless} has any effect.
1605 See also @mrefdot{ordergreatp}
1607 @opencatbox{Categories:}
1608 @category{Expressions}
1612 @c -----------------------------------------------------------------------------
1613 @anchor{ordergreatp}
1615 @deffn {Function} ordergreatp (@var{expr_1}, @var{expr_2})
1616 @deffnx {Function} orderlessp (@var{expr_1}, @var{expr_2})
1618 @code{ordergreatp} returns @code{true} if @var{expr_1} succeeds @var{expr_2} in
1619 the canonical ordering of Maxima expressions, and @code{false} otherwise.
1621 @code{orderlessp} returns @code{true} if @var{expr_1} precedes @var{expr_2} in
1622 the canonical ordering of Maxima expressions, and @code{false} otherwise.
1624 All Maxima atoms and expressions are comparable under @code{ordergreatp} and
1625 @code{orderlessp}, although there are isolated examples of expressions for which
1626 these predicates are not transitive; that is a bug.
1628 The canonical ordering of atoms (symbols, literal numbers, and strings) is the
1631 (integers and floats) precede (bigfloats) precede
1632 (declared constants) precede (strings) precede (declared scalars)
1633 precede (first argument to @mref{orderless}) precedes @dots{} precedes
1634 (last argument to @code{orderless}) precedes (other symbols) precede
1635 (last argument to @mref{ordergreat}) precedes @dots{} precedes
1636 (first argument to @code{ordergreat}) precedes (declared main variables)
1638 For non-atomic expressions, the canonical ordering is derived from the ordering
1639 for atoms. For the built-in @code{+} @code{*} and @code{^} operators,
1640 the ordering is not easily summarized. For other built-in operators and all
1641 other functions and operators, expressions are ordered by their arguments
1642 (beginning with the first argument), then by the name of the operator or
1643 function. In the case of subscripted expressions, the subscripted symbol is
1644 considered the operator and the subscript is considered an argument.
1646 The canonical ordering of expressions is modified by the functions
1647 @mref{ordergreat} and @mrefcomma{orderless} and the @mrefcomma{mainvar}@w{}
1648 @mrefcomma{constant} and @code{scalar} declarations.
1650 See also @mrefdot{sort}
1654 Ordering ordinary symbols and constants.
1655 Note that @code{%pi} is not ordered according to its numerical value.
1658 @c stringdisp : true;
1659 @c sort ([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
1663 (%i1) stringdisp : true;
1667 (%i2) sort ([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
1668 (%o2) [3, 3.0, 4, 4.0, 3.0b0, 4.0b0, %pi, "bar", "foo", X, a, x]
1672 Effect of @code{ordergreat} and @code{orderless} functions.
1675 @c sort ([M, H, K, T, E, W, G, A, P, J, S]);
1676 @c ordergreat (S, J);
1677 @c orderless (M, H);
1678 @c sort ([M, H, K, T, E, W, G, A, P, J, S]);
1682 (%i1) sort ([M, H, K, T, E, W, G, A, P, J, S]);
1683 (%o1) [A, E, G, H, J, K, M, P, S, T, W]
1686 (%i2) ordergreat (S, J);
1690 (%i3) orderless (M, H);
1694 (%i4) sort ([M, H, K, T, E, W, G, A, P, J, S]);
1695 (%o4) [M, H, A, E, G, K, P, T, W, J, S]
1699 Effect of @code{mainvar}, @code{constant}, and @code{scalar} declarations.
1702 @c sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1703 @c declare (aa, mainvar);
1704 @c declare ([baz, quux], constant);
1705 @c declare ([A1, B1], scalar);
1706 @c sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1710 (%i1) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1711 (%o1) [A1, B1, C1, aa, bar, baz, bb, cc, dd, foo, quux]
1714 (%i2) declare (aa, mainvar);
1718 (%i3) declare ([baz, quux], constant);
1722 (%i4) declare ([A1, B1], scalar);
1726 (%i5) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
1727 (%o5) [baz, quux, A1, B1, C1, bar, bb, cc, dd, foo, aa]
1731 Ordering non-atomic expressions.
1734 @c sort ([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n),
1736 @c sort ([foo(1), X[1], X[k], foo(k), 1, k]);
1740 (%i1) sort ([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n),
1742 (%o1) [1, 2, f(1), g(1), g(1, 2), f(2), f(2, 1), n, g(n),
1746 (%i2) sort ([foo(1), X[1], X[k], foo(k), 1, k]);
1747 (%o2) [1, X , foo(1), k, X , foo(k)]
1752 @opencatbox{Categories:}
1753 @category{Expressions}
1754 @category{Predicate functions}
1760 @c -----------------------------------------------------------------------------
1762 @deffn {Function} part (@var{expr}, @var{n_1}, @dots{}, @var{n_k})
1764 Returns parts of the displayed form of @code{expr}. It obtains the part of
1765 @code{expr} as specified by the indices @var{n_1}, @dots{}, @var{n_k}. First
1766 part @var{n_1} of @code{expr} is obtained, then part @var{n_2} of that, etc.
1767 The result is part @var{n_k} of @dots{} part @var{n_2} of part @var{n_1} of
1768 @code{expr}. If no indices are specified @code{expr} is returned.
1770 @code{part} can be used to obtain an element of a list, a row of a matrix, etc.
1772 @c "If the last argument to a part function" => FOLLOWING APPLIES TO OTHER FUNCTIONS ??
1773 @c ATTEMPT TO VERIFY; IF SO, COPY THIS COMMENTARY TO DESCRIPTIONS OF OTHER FUNCTIONS
1774 If the last argument to a @code{part} function is a list of indices then
1775 several subexpressions are picked out, each one corresponding to an
1776 index of the list. Thus @code{part (x + y + z, [1, 3])} is @code{z+x}.
1778 @mref{piece} holds the last expression selected when using the @code{part}
1779 functions. It is set during the execution of the function and thus
1780 may be referred to in the function itself as shown below.
1782 If @mref{partswitch} is set to @code{true} then @code{end} is returned when a
1783 selected part of an expression doesn't exist, otherwise an error message is
1786 See also @mrefcomma{inpart} @mrefcomma{substpart} @mrefcomma{substinpart}@w{}
1787 @mrefcomma{dpart} and @mrefdot{lpart}
1793 @c part(z+2*y+a,[1,3]);
1794 @c part(z+2*y+a,2,1);
1798 (%i1) part(z+2*y+a,2);
1802 (%i2) part(z+2*y+a,[1,3]);
1806 (%i3) part(z+2*y+a,2,1);
1811 @code{example (part)} displays additional examples.
1813 @opencatbox{Categories:}
1814 @category{Expressions}
1820 @c -----------------------------------------------------------------------------
1822 @deffn {Function} partition (@var{expr}, @var{x})
1824 Returns a list of two expressions. They are (1) the factors of @var{expr}
1825 (if it is a product), the terms of @var{expr} (if it is a sum), or the list
1826 (if it is a list) which don't contain @var{x} and, (2) the factors, terms,
1832 @c partition (2*a*x*f(x), x);
1833 @c partition (a+b, x);
1834 @c partition ([a, b, f(a), c], a);
1837 (%i1) partition (2*a*x*f(x), x);
1839 (%i2) partition (a+b, x);
1841 (%i3) partition ([a, b, f(a), c], a);
1842 (%o3) [[b, c], [a, f(a)]]
1845 @opencatbox{Categories:}
1846 @category{Expressions}
1852 @c -----------------------------------------------------------------------------
1854 @defvr {Option variable} partswitch
1855 Default value: @code{false}
1857 When @code{partswitch} is @code{true}, @code{end} is returned
1858 when a selected part of an expression doesn't exist, otherwise an
1859 error message is given.
1861 @opencatbox{Categories:}
1862 @category{Expressions}
1866 @c -----------------------------------------------------------------------------
1868 @deffn {Function} pickapart (@var{expr}, @var{n})
1870 Assigns intermediate expression labels to subexpressions of @var{expr} at depth
1871 @var{n}, an integer. Subexpressions at greater or lesser depths are not
1872 assigned labels. @code{pickapart} returns an expression in terms of
1873 intermediate expressions equivalent to the original expression @var{expr}.
1875 See also @mrefcomma{part} @mrefcomma{dpart} @mrefcomma{lpart}@w{}
1876 @mrefcomma{inpart} and @mrefdot{reveal}
1881 (%i1) expr: (a+b)/2 + sin (x^2)/3 - log (1 + sqrt(x+1));
1884 (%o1) - log(sqrt(x + 1) + 1) + ------- + -----
1886 (%i2) pickapart (expr, 0);
1890 (%t2) - log(sqrt(x + 1) + 1) + ------- + -----
1894 (%i3) pickapart (expr, 1);
1896 (%t3) - log(sqrt(x + 1) + 1)
1909 (%o5) %t5 + %t4 + %t3
1910 (%i5) pickapart (expr, 2);
1912 (%t6) log(sqrt(x + 1) + 1)
1922 (%o8) --- + --- - %t6
1924 (%i8) pickapart (expr, 3);
1926 (%t9) sqrt(x + 1) + 1
1933 (%o10) ----- - log(%t9) + ---------
1935 (%i10) pickapart (expr, 4);
1941 (%o11) ------- + ----- - log(%t11 + 1)
1944 (%i11) pickapart (expr, 5);
1950 (%o12) ------- + ----- - log(sqrt(%t12) + 1)
1952 (%i12) pickapart (expr, 6);
1955 (%o12) ------- + ----- - log(sqrt(x + 1) + 1)
1959 @opencatbox{Categories:}
1960 @category{Expressions}
1966 @c -----------------------------------------------------------------------------
1968 @defvr {System variable} piece
1970 Holds the last expression selected when using the @mref{part} functions.
1971 @c WHAT DOES THIS MEAN EXACTLY ??
1972 It is set during the execution of the function and thus may be referred to in
1973 the function itself.
1975 @c NEED "SEE ALSO" TO POINT TO LIST OF ALL RELEVANT FUNCTIONS
1977 @opencatbox{Categories:}
1978 @category{Expressions}
1982 @c -----------------------------------------------------------------------------
1984 @deffn {Function} psubst @
1985 @fname{psubst} (@var{list}, @var{expr}) @
1986 @fname{psubst} (@var{a}, @var{b}, @var{expr})
1988 @code{psubst(@var{a}, @var{b}, @var{expr})} is similar to @code{subst}. See
1991 In distinction from @code{subst} the function @code{psubst} makes parallel
1992 substitutions, if the first argument @var{list} is a list of equations.
1994 See also @mref{sublis} for making parallel substitutions and @mref{let} and
1995 @mref{letsimp} for others ways to do substitutions.
1999 The first example shows parallel substitution with @code{psubst}. The second
2000 example shows the result for the function @code{subst}, which does a serial
2004 @c psubst ([a^2=b, b=a], sin(a^2) + sin(b));
2005 @c subst ([a^2=b, b=a], sin(a^2) + sin(b));
2009 (%i1) psubst ([a^2=b, b=a], sin(a^2) + sin(b));
2010 (%o1) sin(b) + sin(a)
2013 (%i2) subst ([a^2=b, b=a], sin(a^2) + sin(b));
2018 @opencatbox{Categories:}
2019 @category{Expressions}
2023 @c -----------------------------------------------------------------------------
2025 @deffn {Function} rembox @
2026 @fname{rembox} (@var{expr}, unlabelled) @
2027 @fname{rembox} (@var{expr}, @var{label}) @
2028 @fname{rembox} (@var{expr})
2030 Removes boxes from @var{expr}.
2032 @code{rembox (@var{expr}, unlabelled)} removes all unlabelled boxes from
2035 @code{rembox (@var{expr}, @var{label})} removes only boxes bearing @var{label}.
2037 @code{rembox (@var{expr})} removes all boxes, labelled and unlabelled.
2039 Boxes are drawn by the @mrefcomma{box} @mrefcomma{dpart} and @mref{lpart}@w{}
2045 @c expr: (a*d - b*c)/h^2 + sin(%pi*x);
2046 @c dpart (dpart (expr, 1, 1), 2, 2);
2047 @c expr2: lpart (BAR, lpart (FOO, %, 1), 2);
2048 @c rembox (expr2, unlabelled);
2049 @c rembox (expr2, FOO);
2050 @c rembox (expr2, BAR);
2055 (%i1) expr: (a*d - b*c)/h^2 + sin(%pi*x);
2057 (%o1) sin(%pi x) + ---------
2062 (%i2) dpart (dpart (expr, 1, 1), 2, 2);
2063 dpart: fell off the end.
2064 -- an error. To debug this try: debugmode(true);
2067 (%i3) expr2: lpart (BAR, lpart (FOO, %, 1), 2);
2069 FOO""""""""" "a d - b c"
2070 (%o3) "sin(%pi x)" + "---------"
2076 (%i4) rembox (expr2, unlabelled);
2078 FOO""""""""" "a d - b c"
2079 (%o4) "sin(%pi x)" + "---------"
2085 (%i5) rembox (expr2, FOO);
2088 (%o5) sin(%pi x) + "---------"
2094 (%i6) rembox (expr2, BAR);
2095 FOO""""""""" a d - b c
2096 (%o6) "sin(%pi x)" + ---------
2101 (%i7) rembox (expr2);
2103 (%o7) sin(%pi x) + ---------
2109 @opencatbox{Categories:}
2110 @category{Expressions}
2114 @c -----------------------------------------------------------------------------
2116 @deffn {Function} reveal (@var{expr}, @var{depth})
2118 Replaces parts of @var{expr} at the specified integer @var{depth}
2119 with descriptive summaries.
2123 Sums and differences are replaced by @code{Sum(@var{n})}
2124 where @var{n} is the number of operands of the sum.
2126 Products are replaced by @code{Product(@var{n})}
2127 where @var{n} is the number of operands of the product.
2129 Exponentials are replaced by @code{Expt}.
2131 Quotients are replaced by @code{Quotient}.
2133 Unary negation is replaced by @code{Negterm}.
2135 Lists are replaced by @code{List(@var{n})} where @var{n} is the number of
2136 elements of the list.
2139 When @var{depth} is greater than or equal to the maximum depth of @var{expr},
2140 @code{reveal (@var{expr}, @var{depth})} returns @var{expr} unmodified.
2142 @code{reveal} evaluates its arguments.
2143 @code{reveal} returns the summarized expression.
2148 @c e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
2157 (%i1) e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
2160 (%o1) -------------------------
2163 (%i2) reveal (e, 1);
2165 (%i3) reveal (e, 2);
2169 (%i4) reveal (e, 3);
2171 Expt + Negterm + Expt
2172 (%o4) ------------------------
2173 Product(2) + Expt + Expt
2175 (%i5) reveal (e, 4);
2178 (%o5) ------------------------------------
2179 Product(2) Product(2)
2181 (%i6) reveal (e, 5);
2184 (%o6) --------------------------
2187 (%i7) reveal (e, 6);
2190 (%o7) -------------------------
2195 @opencatbox{Categories:}
2196 @category{Expressions}
2197 @category{Display functions}
2201 @c -----------------------------------------------------------------------------
2203 @deffn {Function} sqrtdenest (@var{expr})
2204 Denests @code{sqrt} of simple, numerical, binomial surds, where possible. E.g.
2207 @c sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
2212 (%i1) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
2216 (%o1) ---------------------
2217 sqrt(11 sqrt(2) - 12)
2220 (%i2) sqrtdenest(%);
2230 Sometimes it helps to apply @code{sqrtdenest} more than once, on such as
2231 @code{(19601-13860 sqrt(2))^(7/4)}.
2233 @opencatbox{Categories:}
2234 @category{Expressions}
2239 @c NEEDS EXPANSION, CLARIFICATION, MORE EXAMPLES
2241 @c -----------------------------------------------------------------------------
2243 @deffn {Function} sublis (@var{list}, @var{expr})
2245 Makes multiple parallel substitutions into an expression. @var{list} is a list
2246 of equations. The left hand side of the equations must be an atom.
2248 The variable @mref{sublis_apply_lambda} controls simplification after
2251 See also @mref{psubst} for making parallel substitutions.
2256 @c sublis ([a=b, b=a], sin(a) + cos(b));
2260 (%i1) sublis ([a=b, b=a], sin(a) + cos(b));
2261 (%o1) sin(b) + cos(a)
2265 @opencatbox{Categories:}
2266 @category{Expressions}
2270 @c -----------------------------------------------------------------------------
2271 @anchor{sublis_apply_lambda}
2272 @defvr {Option variable} sublis_apply_lambda
2273 Default value: @code{true}
2275 Controls whether @code{lambda}'s substituted are applied in simplification after
2276 @code{sublis} is used or whether you have to do an @mref{ev} to get things to
2277 apply. @code{true} means do the application.
2279 @opencatbox{Categories:}
2280 @category{Expressions}
2284 @c -----------------------------------------------------------------------------
2286 @defvr {Option variable} subnumsimp
2287 Default value: @code{false}
2289 If @code{true} then the functions @mref{subst} and @mref{psubst} can substitute
2290 a subscripted variable @code{f[x]} with a number, when only the symbol @code{f}
2293 See also @mrefdot{subst}
2296 @c subst(100,g,g[x]+2);
2297 @c subst(100,g,g[x]+2),subnumsimp:true;
2300 (%i1) subst(100,g,g[x]+2);
2302 subst: cannot substitute 100 for operator g in expression g
2304 -- an error. To debug this try: debugmode(true);
2306 (%i2) subst(100,g,g[x]+2),subnumsimp:true;
2310 @opencatbox{Categories:}
2311 @category{Expressions}
2315 @c NEEDS CLARIFICATION, MORE EXAMPLES
2317 @c -----------------------------------------------------------------------------
2319 @deffn {Function} subst (@var{a}, @var{b}, @var{c})
2321 Substitutes @var{a} for @var{b} in @var{c}. @var{b} must be an atom or a
2322 complete subexpression of @var{c}. For example, @code{x+y+z} is a complete
2323 subexpression of @code{2*(x+y+z)/w} while @code{x+y} is not. When @var{b} does
2324 not have these characteristics, one may sometimes use @mref{substpart} or
2325 @mref{ratsubst} (see below). Alternatively, if @var{b} is of the form
2326 @code{e/f} then one could use @code{subst (a*f, e, c)} while if @var{b} is of
2327 the form @code{e^(1/f)} then one could use @code{subst (a^f, e, c)}. The
2328 @code{subst} command also discerns the @code{x^y} in @code{x^-y} so that
2329 @code{subst (a, sqrt(x), 1/sqrt(x))} yields @code{1/a}. @var{a} and @var{b}
2330 may also be operators of an expression enclosed in double-quotes @code{"} or
2331 they may be function names. If one wishes to substitute for the independent
2332 variable in derivative forms then the @code{at} function (see below) should be
2335 @c UMM, REVERSE THIS AND MOVE IT TO substitute ??
2336 @code{subst} is an alias for @code{substitute}.
2338 The commands @code{subst (@var{eq_1}, @var{expr})} or
2339 @code{subst ([@var{eq_1}, ..., @var{eq_k}], @var{expr})} are other permissible
2340 forms. The @var{eq_i} are equations indicating substitutions to be made.
2341 For each equation, the right side will be substituted for the left in the
2342 expression @var{expr}. The equations are substituted in serial from left to
2343 right in @var{expr}. See the functions @code{sublis} and @code{psubst} for
2344 making parallel substitutions.
2346 @mref{exptsubst} if @code{true} permits substitutions
2347 like @code{y} for @code{%e^x} in @code{%e^(a*x)} to take place.
2349 @c WHAT IS THIS ABOUT ??
2350 When @code{opsubst} is @code{false},
2351 @code{subst} will not attempt to substitute into the operator of an expression.
2352 E.g. @code{(opsubst: false, subst (x^2, r, r+r[0]))} will work.
2354 See also @mrefcomma{at} @mref{ev} and @mrefcomma{psubst} as well as @mref{let}
2355 and @mrefdot{letsimp}
2360 @c subst (a, x+y, x + (x+y)^2 + y);
2361 @c subst (-%i, %i, a + b*%i);
2365 (%i1) subst (a, x+y, x + (x+y)^2 + y);
2370 (%i2) subst (-%i, %i, a + b*%i);
2375 The substitution is done in serial for a list of equations. Compare this with
2376 a parallel substitution:
2379 @c subst([a=b, b=c], a+b);
2380 @c sublis([a=b, b=c], a+b);
2384 (%i1) subst([a=b, b=c], a+b);
2388 (%i2) sublis([a=b, b=c], a+b);
2393 Single-character Operators like @code{+} and @code{-} have to be quoted in
2394 order to be replaced by subst. It is to note, though, that @code{a+b-c}
2395 might be expressed as @code{a+b+(-1*c)} internally.
2398 @c subst(["+"="-"],a+b-c);
2401 (%i3) subst(["+"="-"],a+b-c);
2405 The difference between @code{subst} and @code{at} can be seen in the
2408 @c g1:y(t)=a*x(t)+b*diff(x(t),t);
2409 @c subst('diff(x(t),t)=1,g1);
2410 @c at(g1,'diff(x(t),t)=1);
2414 (%i1) g1:y(t)=a*x(t)+b*diff(x(t),t);
2416 (%o1) y(t) = b (-- (x(t))) + a x(t)
2420 (%i2) subst('diff(x(t),t)=1,g1);
2421 (%o2) y(t) = a x(t) + b
2424 (%i3) at(g1,'diff(x(t),t)=1);
2427 (%o3) y(t) = b (-- (x(t))! ) + a x(t)
2435 For further examples, do @code{example (subst)}.
2437 @opencatbox{Categories:}
2438 @category{Expressions}
2442 @c NEEDS CLARIFICATION
2444 @c ----------------------------------------------------------------------------
2445 @anchor{substinpart}
2446 @deffn {Function} substinpart (@var{x}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
2448 Similar to @mrefcomma{substpart} but @code{substinpart} works on the
2449 internal representation of @var{expr}.
2454 @c x . 'diff (f(x), x, 2);
2455 @c substinpart (d^2, %, 2);
2456 @c substinpart (f1, f[1](x + 1), 0);
2460 (%i1) x . 'diff (f(x), x, 2);
2463 (%o1) x . (--- (f(x)))
2468 (%i2) substinpart (d^2, %, 2);
2473 (%i3) substinpart (f1, f[1](x + 1), 0);
2478 If the last argument to a @code{part} function is a list of indices then
2479 several subexpressions are picked out, each one corresponding to an
2480 index of the list. Thus
2483 @c part (x + y + z, [1, 3]);
2487 (%i1) part (x + y + z, [1, 3]);
2492 @mref{piece} holds the value of the last expression selected when using the
2493 @code{part} functions. It is set during the execution of the function and
2494 thus may be referred to in the function itself as shown below.
2495 If @mref{partswitch} is set to @code{true} then @code{end} is returned when a
2496 selected part of an expression doesn't exist, otherwise an error
2500 @c expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
2501 @c part (expr, 2, [1, 3]);
2503 @c substpart (factor (piece), expr, [1, 2, 3, 5]);
2504 @c expr: 1/x + y/x - 1/z;
2505 @c substpart (xthru (piece), expr, [2, 3]);
2509 (%i1) expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
2511 (%o1) 27 y + 54 x y + 36 x y + y + 8 x + x + 1
2514 (%i2) part (expr, 2, [1, 3]);
2519 (%i3) sqrt (piece/54);
2523 (%i4) substpart (factor (piece), expr, [1, 2, 3, 5]);
2525 (%o4) (3 y + 2 x) + y + x + 1
2528 (%i5) expr: 1/x + y/x - 1/z;
2534 (%i6) substpart (xthru (piece), expr, [2, 3]);
2541 Also, setting the option @mref{inflag} to @code{true} and calling @mref{part}
2542 or @mref{substpart} is the same as calling @mref{inpart} or @code{substinpart}.
2544 @opencatbox{Categories:}
2545 @category{Expressions}
2549 @c NEEDS CLARIFICATION
2551 @c -----------------------------------------------------------------------------
2553 @deffn {Function} substpart (@var{x}, @var{expr}, @var{n_1}, @dots{}, @var{n_k})
2555 Substitutes @var{x} for the subexpression picked out by the rest of the
2556 arguments as in @mrefdot{part} It returns the new value of @var{expr}. @var{x}
2557 may be some operator to be substituted for an operator of @var{expr}. In some
2558 cases @var{x} needs to be enclosed in double-quotes @code{"} (e.g.
2559 @code{substpart ("+", a*b, 0)} yields @code{b + a}).
2565 @c substpart (3/2, %, 2, 1, 2);
2567 @c substpart ("+", %, 1, 0);
2578 (%i2) substpart (3/2, %, 2, 1, 2);
2585 (%i3) a*x + f(b, y);
2589 (%i4) substpart ("+", %, 1, 0);
2590 (%o4) x + f(b, y) + a
2594 Also, setting the option @mref{inflag} to @code{true} and calling @mref{part}
2595 or @code{substpart} is the same as calling @code{inpart} or
2596 @mrefdot{substinpart}
2598 @opencatbox{Categories:}
2599 @category{Expressions}
2603 @c -----------------------------------------------------------------------------
2605 @deffn {Function} symbolp (@var{expr})
2607 Returns @code{true} if @var{expr} is a symbol, else @code{false}.
2609 @c FOLLOWING REALLY WANTS TO BE @xref{Identiifers} BUT THAT
2610 @c LEAVES THE UNPLEASANT RESIDUE *Note ...:: IN THE OUTPUT OF describe
2611 See also @ref{Identifiers}.
2613 @opencatbox{Categories:}
2614 @category{Predicate functions}
2618 @c -----------------------------------------------------------------------------
2620 @deffn {Function} unorder ()
2622 Disables the aliasing created by the last use of the ordering commands
2623 @code{ordergreat} and @code{orderless}. @code{ordergreat} and @code{orderless}
2624 may not be used more than one time each without calling @code{unorder}.
2625 @code{unorder} does not substitute back in expressions the original symbols for
2626 the aliases introduced by @code{ordergreat} and @code{orderless}. Therefore,
2627 after execution of @code{unorder} the aliases appear in previous expressions.
2629 See also @code{ordergreat} and @code{orderless}.
2633 @code{ordergreat(a)} introduces an alias for the symbol @code{a}. Therefore,
2634 the difference of @code{%o2} and @code{%o4} does not vanish. @code{unorder}
2635 does not substitute back the symbol @code{a} and the alias appears in the
2658 (%i3) ordergreat (a);
2678 @opencatbox{Categories:}
2679 @category{Expressions}
2683 @c -----------------------------------------------------------------------------
2685 @deffn {Function} verbify (@var{f})
2687 Returns the verb form of the function name @var{f}.
2688 See also @code{verb}, @code{noun}, and @code{nounify}.
2700 (%i1) verbify ('foo);
2708 (%i2) nounify (foo);
2717 @opencatbox{Categories:}
2718 @category{Nouns and verbs}