[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Expressions


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Introduction to Expressions

There are a number of reserved words which cannot be used as variable names. Their use would cause a possibly cryptic syntax error.

 
integrate            next           from                 diff            
in                   at             limit                sum             
for                  and            elseif               then            
else                 do             or                   if              
unless               product        while                thru            
step                                                                     

Most things in Maxima are expressions. A sequence of expressions can be made into an expression by separating them by commas and putting parentheses around them. This is similar to the C comma expression.

 
(%i1) x: 3$
(%i2) (x: x+1, x: x^2);
(%o2)                          16
(%i3) (if (x > 17) then 2 else 4);
(%o3)                           4
(%i4) (if (x > 17) then x: 2 else y: 4, y+x);
(%o4)                          20

Even loops in Maxima are expressions, although the value they return is the not too useful done.

 
(%i1) y: (x: 1, for i from 1 thru 10 do (x: x*i))$
(%i2) y;
(%o2)                         done

whereas what you really want is probably to include a third term in the comma expression which actually gives back the value.

 
(%i3) y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$
(%i4) y;
(%o4)                        3628800

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Assignment

There are two assignment operators in Maxima, : and ::. E.g., a: 3 sets the variable a to 3. :: assigns the value of the expression on its right to the value of the quantity on its left, which must evaluate to an atomic variable or subscripted variable.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Complex

A complex expression is specified in Maxima by adding the real part of the expression to %i times the imaginary part. Thus the roots of the equation x^2 - 4*x + 13 = 0 are 2 + 3*%i and 2 - 3*%i. Note that simplification of products of complex expressions can be effected by expanding the product. Simplification of quotients, roots, and other functions of complex expressions can usually be accomplished by using the realpart, imagpart, rectform, polarform, abs, carg functions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 Nouns and Verbs

Maxima distinguishes between operators which are "nouns" and operators which are "verbs". A verb is an operator which can be executed. A noun is an operator which appears as a symbol in an expression, without being executed. By default, function names are verbs. A verb can be changed into a noun by quoting the function name or applying the nounify function. A noun can be changed into a verb by applying the verbify function. The evaluation flag nouns causes ev to evaluate nouns in an expression.

The verb form is distinguished by a leading dollar sign $ on the corresponding Lisp symbol. In contrast, the noun form is distinguished by a leading percent sign % on the corresponding Lisp symbol. Some nouns have special display properties, such as 'integrate and 'derivative (returned by diff), but most do not. By default, the noun and verb forms of a function are identical when displayed. The global flag noundisp causes Maxima to display nouns with a leading quote mark '.

See also noun, nouns, nounify, and verbify.

Examples:

 
(%i1) foo (x) := x^2;
                                     2
(%o1)                     foo(x) := x
(%i2) foo (42);
(%o2)                         1764
(%i3) 'foo (42);
(%o3)                        foo(42)
(%i4) 'foo (42), nouns;
(%o4)                         1764
(%i5) declare (bar, noun);
(%o5)                         done
(%i6) bar (x) := x/17;
                                     x
(%o6)                    ''bar(x) := --
                                     17
(%i7) bar (52);
(%o7)                        bar(52)
(%i8) bar (52), nouns;
                               52
(%o8)                          --
                               17
(%i9) integrate (1/x, x, 1, 42);
(%o9)                        log(42)
(%i10) 'integrate (1/x, x, 1, 42);
                             42
                            /
                            [   1
(%o10)                      I   - dx
                            ]   x
                            /
                             1
(%i11) ev (%, nouns);
(%o11)                       log(42)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Identifiers

Maxima identifiers may comprise alphabetic characters, plus the numerals 0 through 9, plus any special character preceded by the backslash \ character.

A numeral may be the first character of an identifier if it is preceded by a backslash. Numerals which are the second or later characters need not be preceded by a backslash.

A special character may be declared alphabetic by the declare function. If so declared, it need not be preceded by a backslash in an identifier. The alphabetic characters are initially A through Z, a through z, %, and _.

Maxima is case-sensitive. The identifiers foo, FOO, and Foo are distinct. See Lisp and Maxima for more on this point.

A Maxima identifier is a Lisp symbol which begins with a dollar sign $. Any other Lisp symbol is preceded by a question mark ? when it appears in Maxima. See Lisp and Maxima for more on this point.

Examples:

 
(%i1) %an_ordinary_identifier42;
(%o1)               %an_ordinary_identifier42
(%i2) embedded\ spaces\ in\ an\ identifier;
(%o2)           embedded spaces in an identifier
(%i3) symbolp (%);
(%o3)                         true
(%i4) [foo+bar, foo\+bar];
(%o4)                 [foo + bar, foo+bar]
(%i5) [1729, \1729];
(%o5)                     [1729, 1729]
(%i6) [symbolp (foo\+bar), symbolp (\1729)];
(%o6)                     [true, true]
(%i7) [is (foo\+bar = foo+bar), is (\1729 = 1729)];
(%o7)                    [false, false]
(%i8) baz\~quux;
(%o8)                       baz~quux
(%i9) declare ("~", alphabetic);
(%o9)                         done
(%i10) baz~quux;
(%o10)                      baz~quux
(%i11) [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
(%o11)                [false, false, false]
(%i12) :lisp (defvar *my-lisp-variable* '$foo)
*MY-LISP-VARIABLE*
(%i12) ?\*my\-lisp\-variable\*;
(%o12)                         foo

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6 Inequality

Maxima has the inequality operators <, <=, >=, >, #, and notequal. See if for a description of conditional expressions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7 Syntax

It is possible to define new operators with specified precedence, to undefine existing operators, or to redefine the precedence of existing operators. An operator may be unary prefix or unary postfix, binary infix, n-ary infix, matchfix, or nofix. "Matchfix" means a pair of symbols which enclose their argument or arguments, and "nofix" means an operator which takes no arguments. As examples of the different types of operators, there are the following.

unary prefix

negation - a

unary postfix

factorial a!

binary infix

exponentiation a^b

n-ary infix

addition a + b

matchfix

list construction [a, b]

(There are no built-in nofix operators; for an example of such an operator, see nofix.)

The mechanism to define a new operator is straightforward. It is only necessary to declare a function as an operator; the operator function might or might not be defined.

An example of user-defined operators is the following. Note that the explicit function call "dd" (a) is equivalent to dd a, likewise "<-" (a, b) is equivalent to a <- b. Note also that the functions "dd" and "<-" are undefined in this example.

 
(%i1) prefix ("dd");
(%o1)                          dd
(%i2) dd a;
(%o2)                         dd a
(%i3) "dd" (a);
(%o3)                         dd a
(%i4) infix ("<-");
(%o4)                          <-
(%i5) a <- dd b;
(%o5)                      a <- dd b
(%i6) "<-" (a, "dd" (b));
(%o6)                      a <- dd b

The Maxima functions which define new operators are summarized in this table, stating the default left and right binding powers (lbp and rbp, respectively). (Binding power determines operator precedence. However, since left and right binding powers can differ, binding power is somewhat more complicated than precedence.) Some of the operation definition functions take additional arguments; see the function descriptions for details.

prefix

rbp=180

postfix

lbp=180

infix

lbp=180, rbp=180

nary

lbp=180, rbp=180

matchfix

(binding power not applicable)

nofix

(binding power not applicable)

For comparison, here are some built-in operators and their left and right binding powers.

 
Operator   lbp     rbp

  :        180     20 
  ::       180     20 
  :=       180     20 
  ::=      180     20 
  !        160
  !!       160
  ^        140     139 
  .        130     129 
  *        120
  /        120     120 
  +        100     100 
  -        100     134 
  =        80      80 
  #        80      80 
  >        80      80 
  >=       80      80 
  <        80      80 
  <=       80      80 
  not              70 
  and      65
  or       60
  ,        10
  $        -1
  ;        -1

remove and kill remove operator properties from an atom. remove ("a", op) removes only the operator properties of a. kill ("a") removes all properties of a, including the operator properties. Note that the name of the operator must be enclosed in quotation marks.

 
(%i1) infix ("@");
(%o1)                           @
(%i2) "@" (a, b) := a^b;
                                     b
(%o2)                      a @ b := a
(%i3) 5 @ 3;
(%o3)                          125
(%i4) remove ("@", op);
(%o4)                         done
(%i5) 5 @ 3;
Incorrect syntax: @ is not an infix operator
5 @
 ^
(%i5) "@" (5, 3);
(%o5)                          125
(%i6) infix ("@");
(%o6)                           @
(%i7) 5 @ 3;
(%o7)                          125
(%i8) kill ("@");
(%o8)                         done
(%i9) 5 @ 3;
Incorrect syntax: @ is not an infix operator
5 @
 ^
(%i9) "@" (5, 3);
(%o9)                        @(5, 3)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8 Definitions for Expressions

Function: at (expr, [eqn_1, ..., eqn_n])
Function: at (expr, eqn)

Evaluates the expression expr with the variables assuming the values as specified for them in the list of equations [eqn_1, ..., eqn_n] or the single equation eqn.

If a subexpression depends on any of the variables for which a value is specified but there is no atvalue specified and it can't be otherwise evaluated, then a noun form of the at is returned which displays in a two-dimensional form.

at carries out multiple substitutions in series, not parallel.

See also atvalue. For other functions which carry out substitutions, see also subst and ev.

Examples:

 
(%i1) atvalue (f(x,y), [x = 0, y = 1], a^2);
                                2
(%o1)                          a
(%i2) atvalue ('diff (f(x,y), x), x = 0, 1 + y);
(%o2)                        @2 + 1
(%i3) printprops (all, atvalue);
                                !
                  d             !
                 --- (f(@1, @2))!       = @2 + 1
                 d@1            !
                                !@1 = 0

                                     2
                          f(0, 1) = a

(%o3)                         done
(%i4) diff (4*f(x, y)^2 - u(x, y)^2, x);
                  d                          d
(%o4)  8 f(x, y) (-- (f(x, y))) - 2 u(x, y) (-- (u(x, y)))
                  dx                         dx
(%i5) at (%, [x = 0, y = 1]);
                                         !
              2              d           !
(%o5)     16 a  - 2 u(0, 1) (-- (u(x, y))!            )
                             dx          !
                                         !x = 0, y = 1
Function: box (expr)
Function: box (expr, a)

Returns expr enclosed in a box. The return value is an expression with box as the operator and expr as the argument. A box is drawn on the display when display2d is true.

box (expr, a) encloses expr in a box labelled by the symbol a. The label is truncated if it is longer than the width of the box.

A boxed expression does not evaluate to its content, so boxed expressions are effectively excluded from computations.

boxchar is the character used to draw the box in box and in the dpart and lpart functions.

Examples:

 
(%i1) box (a^2 + b^2);
             """""""""
             " 2   2 "
(%o1)        "b  + a "
             """""""""
(%i2) box (a^2 + b^2, term_1);
             term_1"""
             " 2   2 "
(%o2)        "b  + a "
             """""""""
(%i3) 1729 - box (1729);
                  """"""
(%o3)      1729 - "1729"
                  """"""
(%i4) boxchar: "-";
(%o4)            -
(%i5) box (sin(x) + cos(y));
                -----------------
(%o5)           -COS(y) + SIN(x)-
                -----------------
(%i6) 
Option variable: boxchar

Default value: "

boxchar is the character used to draw the box in the box and in the dpart and lpart functions.

All boxes in an expression are drawn with the current value of boxchar; the drawing character is not stored with the box expression.

Function: carg (z)

Returns the complex argument of z. The complex argument is an angle theta in (-%pi, %pi] such that r exp (theta %i) = z where r is the magnitude of z.

carg is a computational function, not a simplifying function.

carg ignores the declaration declare (x, complex), and treats x as a real variable. This is a bug.

See also abs (complex magnitude), polarform, rectform, realpart, and imagpart.

Examples:

 
(%i1) carg (1);
(%o1)                           0
(%i2) carg (1 + %i);
                               %pi
(%o2)                          ---
                                4
(%i3) carg (exp (%i));
(%o3)                           1
(%i4) carg (exp (%pi * %i));
(%o4)                          %pi
(%i5) carg (exp (3/2 * %pi * %i));
                                %pi
(%o5)                         - ---
                                 2
(%i6) carg (17 * exp (2 * %i));
(%o6)                           2
Special operator: constant

declare (a, constant) declares a to be a constant. See declare.

Function: constantp (expr)

Returns true if expr is a constant expression, otherwise returns false.

An expression is considered a constant expression if its arguments are numbers (including rational numbers, as displayed with /R/), symbolic constants such as %pi, %e, and %i, variables bound to a constant or declared constant by declare, or functions whose arguments are constant.

constantp evaluates its arguments.

Examples:

 
(%i1) constantp (7 * sin(2));
(%o1) 				     TRUE
(%i2) constantp (rat (17/29));
(%o2) 				     TRUE
(%i3) constantp (%pi * sin(%e));
(%o3) 				     TRUE
(%i4) constantp (exp (x));
(%o4) 				     FALSE
(%i5) declare (x, constant);
(%o5) 				     DONE
(%i6) constantp (exp (x));
(%o6) 				     TRUE
(%i7) constantp (foo (x) + bar (%e) + baz (2));
(%o7) 				     FALSE
(%i8) 
Function: declare (a_1, f_1, a_2, f_2, ...)

Assigns the atom a_i the flag f_i. The a_i's and f_i's may also be lists of atoms and flags respectively in which case each of the atoms gets all of the properties.

declare quotes its arguments. declare always returns done.

The possible flags and their meanings are:

constant makes a_i a constant as is %pi.

mainvar makes a_i a mainvar. The ordering scale for atoms: numbers < constants (e.g. %e, %pi) < scalars < other variables < mainvars.

scalar makes a_i a scalar.

nonscalar makes a_i behave as does a list or matrix with respect to the dot operator.

noun makes the function a_i a noun so that it won't be evaluated automatically.

evfun makes a_i known to the ev function so that it will get applied if its name is mentioned. See evfun.

evflag makes a_i known to the ev function so that it will be bound to true during the execution of ev if it is mentioned. See evflag.

bindtest causes a_i to signal an error if it ever is used in a computation unbound.

Maxima currently recognizes and uses the following features of objects:

 
even, odd, integer, rational, irrational, real, imaginary,
and complex

The useful features of functions include:

 
increasing,
decreasing, oddfun (odd function), evenfun (even function),
commutative (or symmetric), antisymmetric, lassociative and
rassociative

The a_i and f_i may also be lists of objects or features.

featurep (object, feature) determines if object has been declared to have feature.

See also features.

Function: disolate (expr, x_1, ..., x_n)

is similar to isolate (expr, x) except that it enables the user to isolate more than one variable simultaneously. This might be useful, for example, if one were attempting to change variables in a multiple integration, and that variable change involved two or more of the integration variables. This function is autoloaded from `simplification/disol.mac'. A demo is available by demo("disol")$.

Function: dispform (expr)

Returns the external representation of expr with respect to its main operator. This should be useful in conjunction with part which also deals with the external representation. Suppose expr is -A . Then the internal representation of expr is "*"(-1,A), while the external representation is "-"(A). dispform (expr, all) converts the entire expression (not just the top-level) to external format. For example, if expr: sin (sqrt (x)), then freeof (sqrt, expr) and freeof (sqrt, dispform (expr)) give true, while freeof (sqrt, dispform (expr, all)) gives false.

Function: distrib (expr)

Distributes sums over products. It differs from expand in that it works at only the top level of an expression, i.e., it doesn't recurse and it is faster than expand. It differs from multthru in that it expands all sums at that level.

Examples:

 
(%i1) distrib ((a+b) * (c+d));
(%o1)                 b d + a d + b c + a c
(%i2) multthru ((a+b) * (c+d));
(%o2)                 (b + a) d + (b + a) c
(%i3) distrib (1/((a+b) * (c+d)));
                                1
(%o3)                    ---------------
                         (b + a) (d + c)
(%i4) expand (1/((a+b) * (c+d)), 1, 0);
                                1
(%o4)                 ---------------------
                      b d + a d + b c + a c
Function: dpart (expr, n_1, ..., n_k)

Selects the same subexpression as part, but instead of just returning that subexpression as its value, it returns the whole expression with the selected subexpression displayed inside a box. The box is actually part of the expression.

 
(%i1) dpart (x+y/z^2, 1, 2, 1);
                             y
(%o1)                       ---- + x
                               2
                            """
                            "z"
                            """
Function: exp (x)

Represents the exponential function. Instances of exp (x) in input are simplified to %e^x; exp does not appear in simplified expressions.

demoivre if true causes %e^(a + b %i) to simplify to %e^(a (cos(b) + %i sin(b))) if b is free of %i. See demoivre.

%emode, when true, causes %e^(%pi %i x) to be simplified. See %emode.

%enumer, when true causes %e to be replaced by 2.718... whenever numer is true. See %enumer.

Option variable: %emode

Default value: true

When %emode is true, %e^(%pi %i x) is simplified as follows.

%e^(%pi %i x) simplifies to cos (%pi x) + %i sin (%pi x) if x is an integer or a multiple of 1/2, 1/3, 1/4, or 1/6, and then further simplified.

For other numerical x, %e^(%pi %i x) simplifies to %e^(%pi %i y) where y is x - 2 k for some integer k such that abs(y) < 1.

When %emode is false, no special simplification of %e^(%pi %i x) is carried out.

Option variable: %enumer

Default value: false

When %enumer is true, %e is replaced by its numeric value 2.718... whenever numer is true.

When %enumer is false, this substitution is carried out only if the exponent in %e^x evaluates to a number.

See also ev and numer.

Option variable: exptisolate

Default value: false

exptisolate, when true, causes isolate (expr, var) to examine exponents of atoms (such as %e) which contain var.

Option variable: exptsubst

Default value: false

exptsubst, when true, permits substitutions such as y for %e^x in %e^(a x).

Function: freeof (x_1, ..., x_n, expr)

freeof (x_1, expr) Returns true if no subexpression of expr is equal to x_1 or if x_1 occurs only as a dummy variable in expr, and returns false otherwise.

freeof (x_1, ..., x_n, expr) is equivalent to freeof (x_1, expr) and ... and freeof (x_n, expr).

The arguments x_1, ..., x_n may be names of functions and variables, subscripted names, operators (enclosed in double quotes), or general expressions. freeof evaluates its arguments.

freeof operates only on expr as it stands (after simplification and evaluation) and does not attempt to determine if some equivalent expression would give a different result. In particular, simplification may yield an equivalent but different expression which comprises some different elements than the original form of expr.

A variable is a dummy variable in an expression if it has no binding outside of the expression. Dummy variables recognized by freeof are the index of a sum or product, the limit variable in limit, the integration variable in the definite integral form of integrate, the original variable in laplace, formal variables in at expressions, and arguments in lambda expressions. Local variables in block are not recognized by freeof as dummy variables; this is a bug.

The indefinite form of integrate is not free of its variable of integration.

Function: genfact (x, y, z)

Returns the generalized factorial, defined as x (x-z) (x - 2 z) ... (x - (y - 1) z). Thus, for integral x, genfact (x, x, 1) = x! and genfact (x, x/2, 2) = x!!.

Function: imagpart (expr)

Returns the imaginary part of the expression expr.

imagpart is a computational function, not a simplifying function.

See also abs, carg, polarform, rectform, and realpart.

Function: infix (op)
Function: infix (op, lbp, rbp)
Function: infix (op, lbp, rbp, lpos, rpos, pos)

Declares op to be an infix operator. An infix operator is a function of two arguments, with the name of the function written between the arguments. For example, the subtraction operator - is an infix operator.

infix (op) declares op to be an infix operator with default binding powers (left and right both equal to 180) and parts of speech (left and right both equal to any).

infix (op, lbp, rbp) declares op to be an infix operator with stated left and right binding powers and default parts of speech (left and right both equal to any).

infix (op, lbp, rbp, lpos, rpos, pos) declares op to be an infix operator with stated left and right binding powers and parts of speech.

The precedence of op with respect to other operators derives from the left and right binding powers of the operators in question. If the left and right binding powers of op are both greater the left and right binding powers of some other operator, then op takes precedence over the other operator. If the binding powers are not both greater or less, some more complicated relation holds.

The associativity of op depends on its binding powers. Greater left binding power (lbp) implies an instance of op is evaluated before other operators to its left in an expression, while greater right binding power (rbp) implies an instance of op is evaluated before other operators to its right in an expression. Thus greater lbp makes op right-associative, while greater rbp makes op left-associative. If lbp is equal to rbp, op is left-associative.

See also Syntax.

Examples:

 
(%i1) "@"(a, b) := sconcat("(", a, ",", b, ")")$
(%i2) :lisp (get '$+ 'lbp)
100
(%i2) :lisp (get '$+ 'rbp)
100
(%i2) infix ("@", 101, 101)$
(%i3) 1 + a@b + 2;
(%o3)                       (a,b) + 3
(%i4) infix ("@", 99, 99)$
(%i5) 1 + a@b + 2;
(%o5)                       (a+1,b+2)
 
(%i1) "@"(a, b) := sconcat("(", a, ",", b, ")")$
(%i2) infix ("@", 100, 99)$
(%i3) foo @ bar @ baz;
(%o3)                    (foo,(bar,baz))
(%i4) infix ("@", 100, 101)$
(%i5) foo @ bar @ baz;
(%o5)                    ((foo,bar),baz)
Option variable: inflag

Default value: false

When inflag is true, functions for part extraction inspect the internal form of expr.

Note that the simplifier re-orders expressions. Thus first (x + y) returns x if inflag is true and y if inflag is false. (first (y + x) gives the same results.)

Also, setting inflag to true and calling part or substpart is the same as calling inpart or substinpart.

Functions affected by the setting of inflag are: part, substpart, first, rest, last, length, the for ... in construct, map, fullmap, maplist, reveal and pickapart.

Function: inpart (expr, n_1, ..., n_k)

is similar to part but works on the internal representation of the expression rather than the displayed form and thus may be faster since no formatting is done. Care should be taken with respect to the order of subexpressions in sums and products (since the order of variables in the internal form is often different from that in the displayed form) and in dealing with unary minus, subtraction, and division (since these operators are removed from the expression). part (x+y, 0) or inpart (x+y, 0) yield +, though in order to refer to the operator it must be enclosed in "s. For example ... if inpart (%o9,0) = "+" then ....

Examples:

 
(%i1) x + y + w*z;
(%o1)                      w z + y + x
(%i2) inpart (%, 3, 2);
(%o2)                           z
(%i3) part (%th (2), 1, 2);
(%o3)                           z
(%i4) 'limit (f(x)^g(x+1), x, 0, minus);
                                  g(x + 1)
(%o4)                 limit   f(x)
                      x -> 0-
(%i5) inpart (%, 1, 2);
(%o5)                       g(x + 1)
Function: isolate (expr, x)

Returns expr with subexpressions which are sums and which do not contain var replaced by intermediate expression labels (these being atomic symbols like %t1, %t2, ...). This is often useful to avoid unnecessary expansion of subexpressions which don't contain the variable of interest. Since the intermediate labels are bound to the subexpressions they can all be substituted back by evaluating the expression in which they occur.

exptisolate (default value: false) if true will cause isolate to examine exponents of atoms (like %e) which contain var.

isolate_wrt_times if true, then isolate will also isolate wrt products. See isolate_wrt_times.

Do example (isolate) for examples.

Option variable: isolate_wrt_times

Default value: false

When isolate_wrt_times is true, isolate will also isolate wrt products. E.g. compare both settings of the switch on

 
(%i1) isolate_wrt_times: true$
(%i2) isolate (expand ((a+b+c)^2), c);

(%t2)                          2 a


(%t3)                          2 b


                          2            2
(%t4)                    b  + 2 a b + a

                     2
(%o4)               c  + %t3 c + %t2 c + %t4
(%i4) isolate_wrt_times: false$
(%i5) isolate (expand ((a+b+c)^2), c);
                     2
(%o5)               c  + 2 b c + 2 a c + %t4
Option variable: listconstvars

Default value: false

When listconstvars is true, it will cause listofvars to include %e, %pi, %i, and any variables declared constant in the list it returns if they appear in the expression listofvars is called on. The default is to omit these.

Option variable: listdummyvars

Default value: true

When listdummyvars is false, "dummy variables" in the expression will not be included in the list returned by listofvars. (The meaning of "dummy variables" is as given in freeof. "Dummy variables" are mathematical things like the index of a sum or product, the limit variable, and the definite integration variable.) Example:

 
(%i1) listdummyvars: true$
(%i2) listofvars ('sum(f(i), i, 0, n));
(%o2)                        [i, n]
(%i3) listdummyvars: false$
(%i4) listofvars ('sum(f(i), i, 0, n));
(%o4)                          [n]
Function: listofvars (expr)

Returns a list of the variables in expr.

listconstvars if true causes listofvars to include %e, %pi, %i, and any variables declared constant in the list it returns if they appear in expr. The default is to omit these.

 
(%i1) listofvars (f (x[1]+y) / g^(2+a));
(%o1)                     [g, a, x , y]
                                  1
Function: lfreeof (list, expr)

For each member m of list, calls freeof (m, expr). It returns false if any call to freeof does and true otherwise.

Function: lopow (expr, x)

Returns the lowest exponent of x which explicitly appears in expr. Thus

 
(%i1) lopow ((x+y)^2 + (x+y)^a, x+y);
(%o1)                       min(a, 2)
Function: lpart (label, expr, n_1, ..., n_k)

is similar to dpart but uses a labelled box. A labelled box is similar to the one produced by dpart but it has a name in the top line.

Function: multthru (expr)
Function: multthru (expr_1, expr_2)

Multiplies a factor (which should be a sum) of expr by the other factors of expr. That is, expr is f_1 f_2 ... f_n where at least one factor, say f_i, is a sum of terms. Each term in that sum is multiplied by the other factors in the product. (Namely all the factors except f_i). multthru does not expand exponentiated sums. This function is the fastest way to distribute products (commutative or noncommutative) over sums. Since quotients are represented as products multthru can be used to divide sums by products as well.

multthru (expr_1, expr_2) multiplies each term in expr_2 (which should be a sum or an equation) by expr_1. If expr_1 is not itself a sum then this form is equivalent to multthru (expr_1*expr_2).

 
(%i1) x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
                      1        x         f(x)
(%o1)             - ----- + -------- - --------
                    x - y          2          3
                            (x - y)    (x - y)
(%i2) multthru ((x-y)^3, %);
                           2
(%o2)             - (x - y)  + x (x - y) - f(x)
(%i3) ratexpand (%);
                           2
(%o3)                   - y  + x y - f(x)
(%i4) ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
                        10  2              2  2
                 (b + a)   s  + 2 a b s + a  b
(%o4)            ------------------------------
                                  2
                             a b s
(%i5) multthru (%);  /* note that this does not expand (b+a)^10 */
                                        10
                       2   a b   (b + a)
(%o5)                  - + --- + ---------
                       s    2       a b
                           s
(%i6) multthru (a.(b+c.(d+e)+f));
(%o6)            a . f + a . c . (e + d) + a . b
(%i7) expand (a.(b+c.(d+e)+f));
(%o7)         a . f + a . c . e + a . c . d + a . b
Function: nounify (f)

Returns the noun form of the function name f. This is needed if one wishes to refer to the name of a verb function as if it were a noun. Note that some verb functions will return their noun forms if they can't be evaluated for certain arguments. This is also the form returned if a function call is preceded by a quote.

Function: nterms (expr)

Returns the number of terms that expr would have if it were fully expanded out and no cancellations or combination of terms occurred. Note that expressions like sin (expr), sqrt (expr), exp (expr), etc. count as just one term regardless of how many terms expr has (if it is a sum).

Function: op (expr)

Returns the main operator of the expression expr. op (expr) is equivalent to part (expr, 0).

op returns a string if the main operator is a built-in or user-defined prefix, binary or n-ary infix, postfix, matchfix, or nofix operator. Otherwise op returns a symbol.

op observes the value of the global flag inflag.

op evaluates it argument.

See also args.

Examples:

 
(%i1) ?stringdisp: true$
(%i2) op (a * b * c);
(%o2)                          "*"
(%i3) op (a * b + c);
(%o3)                          "+"
(%i4) op ('sin (a + b));
(%o4)                          sin
(%i5) op (a!);
(%o5)                          "!"
(%i6) op (-a);
(%o6)                          "-"
(%i7) op ([a, b, c]);
(%o7)                          "["
(%i8) op ('(if a > b then c else d));
(%o8)                         "if"
(%i9) op ('foo (a));
(%o9)                          foo
(%i10) prefix (foo);
(%o10)                        "foo"
(%i11) op (foo a);
(%o11)                        "foo"
Function: operatorp (expr, op)
Function: operatorp (expr, [op_1, ..., op_n])

operatorp (expr, op) returns true if op is equal to the operator of expr.

operatorp (expr, [op_1, ..., op_n]) returns true if some element op_1, ..., op_n is equal to the operator of expr.

Function: optimize (expr)

Returns an expression that produces the same value and side effects as expr but does so more efficiently by avoiding the recomputation of common subexpressions. optimize also has the side effect of "collapsing" its argument so that all common subexpressions are shared. Do example (optimize) for examples.

Option variable: optimprefix

Default value: %

optimprefix is the prefix used for generated symbols by the optimize command.

Function: ordergreat (v_1, ..., v_n)

Sets up aliases for the variables v_1, ..., v_n such that v_1 > v_2 > ... > v_n, and v_n > any other variable not mentioned as an argument.

See also orderless.

Function: ordergreatp (expr_1, expr_2)

Returns true if expr_2 precedes expr_1 in the ordering set up with the ordergreat function.

Function: orderless (v_1, ..., v_n)

Sets up aliases for the variables v_1, ..., v_n such that v_1 < v_2 < ... < v_n, and v_n < any other variable not mentioned as an argument.

Thus the complete ordering scale is: numerical constants < declared constants < declared scalars < first argument to orderless < ... < last argument to orderless < variables which begin with A < ... < variables which begin with Z < last argument to ordergreat < ... < first argument to ordergreat < declared mainvars.

See also ordergreat and mainvar.

Function: orderlessp (expr_1, expr_2)

Returns true if expr_1 precedes expr_2 in the ordering set up by the orderless command.

Function: part (expr, n_1, ..., n_k)

Returns parts of the displayed form of expr. It obtains the part of expr as specified by the indices n_1, ..., n_k. First part n_1 of expr is obtained, then part n_2 of that, etc. The result is part n_k of ... part n_2 of part n_1 of expr.

part can be used to obtain an element of a list, a row of a matrix, etc.

If the last argument to a part function is a list of indices then several subexpressions are picked out, each one corresponding to an index of the list. Thus part (x + y + z, [1, 3]) is z+x.

piece holds the last expression selected when using the part functions. It is set during the execution of the function and thus may be referred to in the function itself as shown below.

If partswitch is set to true then end is returned when a selected part of an expression doesn't exist, otherwise an error message is given.

Example: part (z+2*y, 2, 1) yields 2.

example (part) displays additional examples.

Function: partition (expr, x)

Returns a list of two expressions. They are (1) the factors of expr (if it is a product), the terms of expr (if it is a sum), or the list (if it is a list) which don't contain var and, (2) the factors, terms, or list which do.

 
(%i1) partition (2*a*x*f(x), x);
(%o1)                     [2 a, x f(x)]
(%i2) partition (a+b, x);
(%o2)                      [b + a, 0]
(%i3) partition ([a, b, f(a), c], a); 
(%o3)                  [[b, c], [a, f(a)]]
Option variable: partswitch

Default value: false

When partswitch is true, end is returned when a selected part of an expression doesn't exist, otherwise an error message is given.

Function: pickapart (expr, n)

Assigns intermediate expression labels to subexpressions of expr at depth n, an integer. Subexpressions at greater or lesser depths are not assigned labels. pickapart returns an expression in terms of intermediate expressions equivalent to the original expression expr.

See also part, dpart, lpart, inpart, and reveal.

Examples:

 
(%i1) expr: (a+b)/2 + sin (x^2)/3 - log (1 + sqrt(x+1));
                                          2
                                     sin(x )   b + a
(%o1)       - log(sqrt(x + 1) + 1) + ------- + -----
                                        3        2
(%i2) pickapart (expr, 0);

                                          2
                                     sin(x )   b + a
(%t2)       - log(sqrt(x + 1) + 1) + ------- + -----
                                        3        2

(%o2)                          %t2
(%i3) pickapart (expr, 1);

(%t3)                - log(sqrt(x + 1) + 1)


                                  2
                             sin(x )
(%t4)                        -------
                                3


                              b + a
(%t5)                         -----
                                2

(%o5)                    %t5 + %t4 + %t3
(%i5) pickapart (expr, 2);

(%t6)                 log(sqrt(x + 1) + 1)


                                  2
(%t7)                        sin(x )


(%t8)                         b + a

                         %t8   %t7
(%o8)                    --- + --- - %t6
                          2     3
(%i8) pickapart (expr, 3);

(%t9)                    sqrt(x + 1) + 1


                                2
(%t10)                         x

                  b + a              sin(%t10)
(%o10)            ----- - log(%t9) + ---------
                    2                    3
(%i10) pickapart (expr, 4);

(%t11)                     sqrt(x + 1)

                      2
                 sin(x )   b + a
(%o11)           ------- + ----- - log(%t11 + 1)
                    3        2
(%i11) pickapart (expr, 5);

(%t12)                        x + 1

                   2
              sin(x )   b + a
(%o12)        ------- + ----- - log(sqrt(%t12) + 1)
                 3        2
(%i12) pickapart (expr, 6);
                  2
             sin(x )   b + a
(%o12)       ------- + ----- - log(sqrt(x + 1) + 1)
                3        2
System variable: piece

Holds the last expression selected when using the part functions. It is set during the execution of the function and thus may be referred to in the function itself.

Function: polarform (expr)

Returns an expression r %e^(%i theta) equivalent to expr, such that r and theta are purely real.

Function: powers (expr, x)

Gives the powers of x occuring in expr.

load (powers) loads this function.

Function: product (expr, i, i_0, i_1)

Represents a product of the values of expr as the index i varies from i_0 to i_1. The noun form 'product is displayed as an uppercase letter pi.

product evaluates expr and lower and upper limits i_0 and i_1, product quotes (does not evaluate) the index i.

If the upper and lower limits differ by an integer, expr is evaluated for each value of the index i, and the result is an explicit product.

Otherwise, the range of the index is indefinite. Some rules are applied to simplify the product. When the global variable simpproduct is true, additional rules are applied. In some cases, simplification yields a result which is not a product; otherwise, the result is a noun form 'product.

See also nouns and evflag.

Examples:

 
(%i1) product (x + i*(i+1)/2, i, 1, 4);
(%o1)           (x + 1) (x + 3) (x + 6) (x + 10)
(%i2) product (i^2, i, 1, 7);
(%o2)                       25401600
(%i3) product (a[i], i, 1, 7);
(%o3)                 a  a  a  a  a  a  a
                       1  2  3  4  5  6  7
(%i4) product (a(i), i, 1, 7);
(%o4)          a(1) a(2) a(3) a(4) a(5) a(6) a(7)
(%i5) product (a(i), i, 1, n);
                             n
                           /===\
                            ! !
(%o5)                       ! !  a(i)
                            ! !
                           i = 1
(%i6) product (k, k, 1, n);
                               n
                             /===\
                              ! !
(%o6)                         ! !  k
                              ! !
                             k = 1
(%i7) product (k, k, 1, n), simpproduct;
(%o7)                          n!
(%i8) product (integrate (x^k, x, 0, 1), k, 1, n);
                             n
                           /===\
                            ! !    1
(%o8)                       ! !  -----
                            ! !  k + 1
                           k = 1
(%i9) product (if k <= 5 then a^k else b^k, k, 1, 10);
                              15  40
(%o9)                        a   b
Function: realpart (expr)

Returns the real part of expr. realpart and imagpart will work on expressions involving trigonometic and hyperbolic functions, as well as square root, logarithm, and exponentiation.

Function: rectform (expr)

Returns an expression a + b %i equivalent to expr, such that a and b are purely real.

Function: rembox (expr, unlabelled)
Function: rembox (expr, label)
Function: rembox (expr)

Removes boxes from expr.

rembox (expr, unlabelled) removes all unlabelled boxes from expr.

rembox (expr, label) removes only boxes bearing label.

rembox (expr) removes all boxes, labelled and unlabelled.

Boxes are drawn by the box, dpart, and lpart functions.

Examples:

 
(%i1) expr: (a*d - b*c)/h^2 + sin(%pi*x);
                                  a d - b c
(%o1)                sin(%pi x) + ---------
                                      2
                                     h
(%i2) dpart (dpart (expr, 1, 1), 2, 2);
                        """""""    a d - b c
(%o2)               sin("%pi x") + ---------
                        """""""      """"
                                     " 2"
                                     "h "
                                     """"
(%i3) expr2: lpart (BAR, lpart (FOO, %, 1), 2);
                  FOO"""""""""""   BAR""""""""
                  "    """"""" "   "a d - b c"
(%o3)             "sin("%pi x")" + "---------"
                  "    """"""" "   "  """"   "
                  """"""""""""""   "  " 2"   "
                                   "  "h "   "
                                   "  """"   "
                                   """""""""""
(%i4) rembox (expr2, unlabelled);
                                  BAR""""""""
                   FOO"""""""""   "a d - b c"
(%o4)              "sin(%pi x)" + "---------"
                   """"""""""""   "    2    "
                                  "   h     "
                                  """""""""""
(%i5) rembox (expr2, FOO);
                                  BAR""""""""
                       """""""    "a d - b c"
(%o5)              sin("%pi x") + "---------"
                       """""""    "  """"   "
                                  "  " 2"   "
                                  "  "h "   "
                                  "  """"   "
                                  """""""""""
(%i6) rembox (expr2, BAR);
                   FOO"""""""""""
                   "    """"""" "   a d - b c
(%o6)              "sin("%pi x")" + ---------
                   "    """"""" "     """"
                   """"""""""""""     " 2"
                                      "h "
                                      """"
(%i7) rembox (expr2);
                                  a d - b c
(%o7)                sin(%pi x) + ---------
                                      2
                                     h
Function: sum (expr, i, i_0, i_1)

Represents a summation of the values of expr as the index i varies from i_0 to i_1. The noun form 'sum is displayed as an uppercase letter sigma.

sum evaluates its summand expr and lower and upper limits i_0 and i_1, sum quotes (does not evaluate) the index i.

If the upper and lower limits differ by an integer, the summand expr is evaluated for each value of the summation index i, and the result is an explicit sum.

Otherwise, the range of the index is indefinite. Some rules are applied to simplify the summation. When the global variable simpsum is true, additional rules are applied. In some cases, simplification yields a result which is not a summation; otherwise, the result is a noun form 'sum.

When the evflag (evaluation flag) cauchysum is true, a product of summations is expressed as a Cauchy product, in which the index of the inner summation is a function of the index of the outer one, rather than varying independently.

The global variable genindex is the alphabetic prefix used to generate the next index of summation, when an automatically generated index is needed.

gensumnum is the numeric suffix used to generate the next index of summation, when an automatically generated index is needed. When gensumnum is false, an automatically-generated index is only genindex with no numeric suffix.

See also sumcontract, intosum, bashindices, niceindices, nouns, evflag, and zeilberger.

Examples:

 
(%i1) sum (i^2, i, 1, 7);
(%o1)                          140
(%i2) sum (a[i], i, 1, 7);
(%o2)           a  + a  + a  + a  + a  + a  + a
                 7    6    5    4    3    2    1
(%i3) sum (a(i), i, 1, 7);
(%o3)    a(7) + a(6) + a(5) + a(4) + a(3) + a(2) + a(1)
(%i4) sum (a(i), i, 1, n);
                            n
                           ====
                           \
(%o4)                       >    a(i)
                           /
                           ====
                           i = 1
(%i5) sum (2^i + i^2, i, 0, n);
                          n
                         ====
                         \       i    2
(%o5)                     >    (2  + i )
                         /
                         ====
                         i = 0
(%i6) sum (2^i + i^2, i, 0, n), simpsum;
                              3      2
                   n + 1   2 n  + 3 n  + n
(%o6)             2      + --------------- - 1
                                  6
(%i7) sum (1/3^i, i, 1, inf);
                            inf
                            ====
                            \     1
(%o7)                        >    --
                            /      i
                            ====  3
                            i = 1
(%i8) sum (1/3^i, i, 1, inf), simpsum;
                                1
(%o8)                           -
                                2
(%i9) sum (i^2, i, 1, 4) * sum (1/i^2, i, 1, inf);
                              inf
                              ====
                              \     1
(%o9)                      30  >    --
                              /      2
                              ====  i
                              i = 1
(%i10) sum (i^2, i, 1, 4) * sum (1/i^2, i, 1, inf), simpsum;
                                  2
(%o10)                       5 %pi
(%i11) sum (integrate (x^k, x, 0, 1), k, 1, n);
                            n
                           ====
                           \       1
(%o11)                      >    -----
                           /     k + 1
                           ====
                           k = 1
(%i12) sum (if k <= 5 then a^k else b^k, k, 1, 10));
Incorrect syntax: Too many )'s
else b^k, k, 1, 10))
                  ^
(%i12) linenum:11;
(%o11)                         11
(%i12) sum (integrate (x^k, x, 0, 1), k, 1, n);
                            n
                           ====
                           \       1
(%o12)                      >    -----
                           /     k + 1
                           ====
                           k = 1
(%i13) sum (if k <= 5 then a^k else b^k, k, 1, 10);
          10    9    8    7    6    5    4    3    2
(%o13)   b   + b  + b  + b  + b  + a  + a  + a  + a  + a
Function: lsum (expr, x, L)

Represents the sum of expr for each element x in L.

A noun form 'lsum is returned if the argument L does not evaluate to a list.

Examples:

 
(%i1) lsum (x^i, i, [1, 2, 7]);
                            7    2
(%o1)                      x  + x  + x
(%i2) lsum (i^2, i, rootsof (x^3 - 1));
                     ====
                     \      2
(%o2)                 >    i
                     /
                     ====
                                   3
                     i in rootsof(x  - 1)
Function: verbify (f)

Returns the verb form of the function name f.

See also verb, noun, and nounify.

Examples:

 
(%i1) verbify ('foo);
(%o1)                          foo
(%i2) :lisp $%
$FOO
(%i2) nounify (foo);
(%o2)                          foo
(%i3) :lisp $%
%FOO

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on March, 19 2006 using texi2html 1.76.