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

5. Operators


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

5.1 nary

An nary operator is used to denote a function of any number of arguments, each of which is separated by an occurrence of the operator, e.g. A+B or A+B+C. The nary("x") function is a syntax extension function to declare x to be an nary operator. Functions may be declared to be nary. If declare(j,nary); is done, this tells the simplifier to simplify, e.g. j(j(a,b),j(c,d)) to j(a, b, c, d).

See also syntax.


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

5.2 nofix

nofix operators are used to denote functions of no arguments. The mere presence of such an operator in a command will cause the corresponding function to be evaluated. For example, when one types "exit;" to exit from a Maxima break, "exit" is behaving similar to a nofix operator. The function nofix("x") is a syntax extension function which declares x to be a nofix operator.

See also syntax.


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

5.3 operator

See operators.


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

5.4 postfix

postfix operators like the prefix variety denote functions of a single argument, but in this case the argument immediately precedes an occurrence of the operator in the input string, e.g. 3! . The postfix("x") function is a syntax extension function to declare x to be a postfix operator.

See also syntax.


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

5.5 prefix

A prefix operator is one which signifies a function of one argument, which argument immediately follows an occurrence of the operator. prefix("x") is a syntax extension function to declare x to be a prefix operator.

See also syntax.


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

5.6 Definitions for Operators

Operator: "!"

The factorial operator. For any complex number x (including integer, rational, and real numbers) except for negative integers, x! is defined as gamma(x+1).

For an integer x, x! simplifies to the product of the integers from 1 to x inclusive. 0! simplifies to 1. For a floating point number x, x! simplifies to the value of gamma (x+1). For x equal to n/2 where n is an odd integer, x! simplifies to a rational factor times sqrt (%pi) (since gamma (1/2) is equal to sqrt (%pi)). If x is anything else, x! is not simplified.

The variables factlim, minfactorial, and factcomb control the simplification of expressions containing factorials.

The functions gamma, bffac, and cbffac are varieties of the gamma function. makegamma substitutes gamma for factorials and related functions.

See also binomial.

Operator: "!!"

The double factorial operator.

For an integer, float, or rational number n, n!! evaluates to the product n (n-2) (n-4) (n-6) ... (n - 2 (k-1)) where k is equal to entier (n/2), that is, the largest integer less than or equal to n/2. Note that this definition does not coincide with other published definitions for arguments which are not integers.

For an even (or odd) integer n, n!! evaluates to the product of all the consecutive even (or odd) integers from 2 (or 1) through n inclusive.

For an argument n which is not an integer, float, or rational, n!! yields a noun form genfact (n, n/2, 2).

Operator: "#"

Represents the negation of syntactic equality =.

Note that because of the rules for evaluation of predicate expressions (in particular because not expr causes evaluation of expr), not a = b is not equivalent to a # b in some cases.

Examples:

 
(%i1) a = b;
(%o1)                         a = b
(%i2) is (a = b);
(%o2)                         false
(%i3) a # b;
(%o3)                         a # b
(%i4) not a = b;
(%o4)                         true
(%i5) is (a # b);
(%o5)                         true
(%i6) is (not a = b);
(%o6)                         true
Operator: "."

The dot operator, for matrix (non-commutative) multiplication. When "." is used in this way, spaces should be left on both sides of it, e.g. A . B. This distinguishes it plainly from a decimal point in a floating point number.

See also dot, dot0nscsimp, dot0simp, dot1simp, dotassoc, dotconstrules, dotdistrib, dotexptsimp, dotident, and dotscrules.

Operator: ":"

The assignment operator. E.g. A:3 sets the variable A to 3.

Operator: "::"

Assignment operator. :: 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.

Operator: "::="

Macro function definition operator. ::= defines a function (called a "macro" for historical reasons) which quotes its arguments, and the expression which it returns (called the "macro expansion") is evaluated in the context from which the macro was called. A macro function is otherwise the same as an ordinary function.

macroexpand returns a macro expansion (without evaluating it). macroexpand (foo (x)) followed by ''% is equivalent to foo (x) when foo is a macro function.

::= puts the name of the new macro function onto the global list macros. kill, remove, and remfunction unbind macro function definitions and remove names from macros.

fundef or dispfun return a macro function definition or assign it to a label, respectively.

Macro functions commonly contain buildq and splice expressions to construct an expression, which is then evaluated.

Examples

A macro function quotes its arguments, so message (1) shows y - z, not the value of y - z. The macro expansion (the quoted expression '(print ("(2) x is equal to", x)) is evaluated in the context from which the macro was called, printing message (2).

 
(%i1) x: %pi;
(%o1)                          %pi
(%i2) y: 1234;
(%o2)                         1234
(%i3) z: 1729 * w;
(%o3)                        1729 w
(%i4) printq1 (x) ::= block (print ("(1) x is equal to", x), '(print ("(2) x is equal to", x)));
(%o4) printq1(x) ::= block(print("(1) x is equal to", x), 
                                '(print("(2) x is equal to", x)))
(%i5) printq1 (y - z);
(1) x is equal to y - z 
(2) x is equal to %pi 
(%o5)                          %pi

An ordinary function evaluates is arguments, so message (1) shows the value of y - z. The return value is not evaluated, so message (2) is not printed until the explicit evaluation ''%.

 
(%i1) x: %pi;
(%o1)                          %pi
(%i2) y: 1234;
(%o2)                         1234
(%i3) z: 1729 * w;
(%o3)                        1729 w
(%i4) printe1 (x) := block (print ("(1) x is equal to", x), '(print ("(2) x is equal to", x)));
(%o4) printe1(x) := block(print("(1) x is equal to", x), 
                                '(print("(2) x is equal to", x)))
(%i5) printe1 (y - z);
(1) x is equal to 1234 - 1729 w 
(%o5)              print((2) x is equal to, x)
(%i6) ''%;
(2) x is equal to %pi 
(%o6)                          %pi

macroexpand returns a macro expansion. macroexpand (foo (x)) followed by ''% is equivalent to foo (x) when foo is a macro function.

 
(%i1) x: %pi;
(%o1)                          %pi
(%i2) y: 1234;
(%o2)                         1234
(%i3) z: 1729 * w;
(%o3)                        1729 w
(%i4) g (x) ::= buildq ([x], print ("x is equal to", x));
(%o4)    g(x) ::= buildq([x], print("x is equal to", x))
(%i5) macroexpand (g (y - z));
(%o5)              print(x is equal to, y - z)
(%i6) ''%;
x is equal to 1234 - 1729 w 
(%o6)                     1234 - 1729 w
(%i7) g (y - z);
x is equal to 1234 - 1729 w 
(%o7)                     1234 - 1729 w
Operator: ":="

The function definition operator. E.g. f(x):=sin(x) defines a function f.

Operator: "="

denotes an equation to Maxima. To the pattern matcher in Maxima it denotes a total relation that holds between two expressions if and only if the expressions are syntactically identical.

The negation of = is represented by #. Note that because of the rules for evaluation of predicate expressions (in particular because not expr causes evaluation of expr), not a = b is not equivalent to a # b in some cases.

Operator: and

The logical conjunction operator. and is an n-ary infix operator; its operands are Boolean expressions, and its result is a Boolean value.

and forces evaluation (like is) of one or more operands, and may force evaluation of all operands.

Operands are evaluated in the order in which they appear. and evaluates only as many of its operands as necessary to determine the result. If any operand is false, the result is false and no further operands are evaluated.

The global flag prederror governs the behavior of and when an evaluated operand cannot be determined to be true or false. and prints an error message when prederror is true. Otherwise, and returns unknown.

and is not commutative: a and b might not be equal to b and a due to the treatment of indeterminate operands.

Operator: or

The logical disjunction operator. or is an n-ary infix operator; its operands are Boolean expressions, and its result is a Boolean value.

or forces evaluation (like is) of one or more operands, and may force evaluation of all operands.

Operands are evaluated in the order in which they appear. or evaluates only as many of its operands as necessary to determine the result. If any operand is true, the result is true and no further operands are evaluated.

The global flag prederror governs the behavior of or when an evaluated operand cannot be determined to be true or false. or prints an error message when prederror is true. Otherwise, or returns unknown.

or is not commutative: a or b might not be equal to b or a due to the treatment of indeterminate operands.

Operator: not

The logical negation operator. not is a prefix operator; its operand is a Boolean expression, and its result is a Boolean value.

not forces evaluation (like is) of its operand.

The global flag prederror governs the behavior of not when its operand cannot be determined to be true or false. not prints an error message when prederror is true. Otherwise, not returns unknown.

Function: abs (expr)

Returns the absolute value expr. If expr is complex, returns the complex modulus of expr.

Keyword: additive

If declare(f,additive) has been executed, then:

(1) If f is univariate, whenever the simplifier encounters f applied to a sum, f will be distributed over that sum. I.e. f(y+x) will simplify to f(y)+f(x).

(2) If f is a function of 2 or more arguments, additivity is defined as additivity in the first argument to f, as in the case of sum or integrate, i.e. f(h(x)+g(x),x) will simplify to f(h(x),x)+f(g(x),x). This simplification does not occur when f is applied to expressions of the form sum(x[i],i,lower-limit,upper-limit).

Keyword: allbut

works with the part commands (i.e. part, inpart, substpart, substinpart, dpart, and lpart). For example,

 
(%i1) expr: e+d+c+b+a$
(%i2) part (expr, [2, 5]);
(%o2)                         d + a

while

 
(%i3) part (expr, allbut (2, 5));
(%o3)                       e + c + b

It also works with the kill command,

 
kill (allbut (name_1, ..., name_k))

will do a kill (all) except it will not kill the names specified. Note: name_i means a name such as function name such as u, f, foo, or g, not an infolist such as functions.

Declaration: antisymmetric

If declare(h,antisymmetric) is done, this tells the simplifier that h is antisymmetric. E.g. h(x,z,y) will simplify to - h(x, y, z). That is, it will give (-1)^n times the result given by symmetric or commutative, where n is the number of interchanges of two arguments necessary to convert it to that form.

Function: cabs (expr)

Returns the complex absolute value (the complex modulus) of expr.

Function: ceiling (x)

When x is a real number, return the least integer that is greater than or equal to x.

If x is a constant expression (10 * %pi, for example), ceiling evaluates x using big floating point numbers, and applies ceiling to the resulting big float. Because ceiling uses floating point evaluation, it's possible, although unlikely, that ceiling could return an erroneous value for constant inputs. To guard against errors, the floating point evaluation is done using three values for fpprec.

For non-constant inputs, ceiling tries to return a simplified value. Here are examples of the simplifications that ceiling knows about:

 
(%i1) ceiling(ceiling(x));
(%o1) ceiling(x)
(%i2) ceiling(floor(x));
(%o2) floor(x)
(%i3) declare(n,integer)$
(%i4) [ceiling(n), ceiling(abs(n)), ceiling(max(n,6))];
(%o4) [n, abs(n), max(n,6)]
(%i5) assume(x > 0, x < 1)$
(%i6) ceiling(x);
(%o6) 1
(%i7) tex(ceiling(a));
   $$\left \lceil a \right \rceil$$

The function ceiling does not automatically map over lists or matrices. Finally, for all inputs that are manifestly complex, ceiling returns a noun form.

If the range of a function is a subset of the integers, it can be declared to be integervalued. Both the ceiling and floor functions can use this information; for example:

 
(%i1) declare(f,integervalued)$
(%i2) floor(f(x));
(%o2) f(x)
(%i3) ceiling(f(x) -1);
(%o3) f(x)-1
Function: charfun (p)

Return 0 when the predicate p evaluates to false; return 1 when the predicate evaluates to true. When the predicate evaluates to something other than true or false (unknown), return a noun form.

Examples:

 
(%i1) charfun(x<1);
(%o1) charfun(x<1)
(%i2) subst(x=-1,%);
(%o2) 1
(%i3) e : charfun('"and"(-1 < x, x < 1))$
(%i4) [subst(x=-1,e), subst(x=0,e), subst(x=1,e)];
(%o4) [0,1,0]
Declaration: commutative

If declare(h,commutative) is done, this tells the simplifier that h is a commutative function. E.g. h(x,z,y) will simplify to h(x, y, z). This is the same as symmetric.

Function: compare (x, y)

Return a comparison operator op (<, <=, >, >=, =, or #) such that is (x op y) evaluates to true; when either x or y depends on %i and x # y, return notcomparable; when there is no such operator or Maxima isn't able to determine the operator, return unknown.

Examples:

 
(%i1) compare(1,2);
(%o1) <
(%i2) compare(1,x);
(%o2) unknown
(%i3) compare(%i,%i);
(%o3) =
(%i4) compare(%i,%i+1);
(%o4) notcomparable
(%i5) compare(1/x,0);
(%o5) #
(%i6) compare(x,abs(x));
(%o6) <=

The function compare doesn't try to determine whether the real domains of its arguments are nonempty; thus

 
(%i1) compare(acos(x^2+1), acos(x^2+1) + 1);
(%o1) <

The real domain of acos (x^2 + 1) is empty.

Function: entier (x)

Returns the largest integer less than or equal to x where x is numeric. fix (as in fixnum) is a synonym for this, so fix(x) is precisely the same.

Function: equal (expr_1, expr_2)

Used with an is, returns true (or false) if and only if expr_1 and expr_2 are equal (or not equal) for all possible values of their variables (as determined by ratsimp). Thus is (equal ((x + 1)^2, x^2 + 2*x + 1)) returns true whereas if x is unbound is ((x + 1)^2 = x^2 + 2*x + 1) returns false. Note also that is(rat(0)=0) yields false but is (equal (rat(0), 0)) yields true.

If a determination can't be made, then is (equal (a, b)) returns a simplified but equivalent expression, whereas is (a=b) always returns either true or false.

All variables occurring in expr_1 and expr_2 are presumed to be real valued.

The negation of equal is notequal. Note that because of the rules for evaluation of predicate expressions (in particular because not expr causes evaluation of expr), notequal is not equivalent to not equal in some cases.

ev (expr, pred) is equivalent to is (expr).

 
(%i1) is (x^2 >= 2*x - 1);
(%o1)                         true
(%i2) assume (a > 1);
(%o2)                        [a > 1]
(%i3) is (log (log (a+1) + 1) > 0 and a^2 + 1 > 2*a);
(%o3)                         true
Function: floor (x)

When x is a real number, return the largest integer that is less than or equal to x.

If x is a constant expression (10 * %pi, for example), floor evaluates x using big floating point numbers, and applies floor to the resulting big float. Because floor uses floating point evaluation, it's possible, although unlikely, that floor could return an erroneous value for constant inputs. To guard against errors, the floating point evaluation is done using three values for fpprec.

For non-constant inputs, floor tries to return a simplified value. Here are examples of the simplifications that floor knows about:

 
(%i1) floor(ceiling(x));
(%o1) ceiling(x)
(%i2) floor(floor(x));
(%o2) floor(x)
(%i3) declare(n,integer)$
(%i3) [floor(n), floor(abs(n)), floor(min(n,6))];
(%o4) [n,abs(n),min(n,6)]
(%i4) assume(x > 0, x < 1)$
(%i5) floor(x);
(%o5) 0
(%i6) tex(floor(a);
    $$\left \lfloor a \right \rfloor$$

The function floor does not automatically map over lists or matrices. Finally, for all inputs that are manifestly complex, floor returns a noun form.

If the range of a function is a subset of the integers, it can be declared to be integervalued. Both the ceiling and floor functions can use this information; for example:

 
(%i1) declare(f,integervalued)$
(%i2) floor(f(x));
(%o2) f(x)
(%i3) ceiling(f(x) -1);
(%o3) f(x)-1
Function: notequal (expr_1, expr_2)

Represents the negation of equal (expr_1, expr_2).

Note that because of the rules for evaluation of predicate expressions (in particular because not expr causes evaluation of expr), notequal is not equivalent to not equal in some cases.

Examples:

 
(%i1) equal (a, b);
(%o1)                      equal(a, b)
(%i2) maybe (equal (a, b));
(%o2)                        unknown
(%i3) notequal (a, b);
(%o3)                    notequal(a, b)
(%i4) not equal (a, b);
`macsyma' was unable to evaluate the predicate:
equal(a, b)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i5) maybe (notequal (a, b));
(%o5)                        unknown
(%i6) maybe (not equal (a, b));
(%o6)                        unknown
(%i7) assume (a > b);
(%o7)                        [a > b]
(%i8) equal (a, b);
(%o8)                      equal(a, b)
(%i9) maybe (equal (a, b));
(%o9)                         false
(%i10) notequal (a, b);
(%o10)                   notequal(a, b)
(%i11) not equal (a, b);
(%o11)                        true
(%i12) maybe (notequal (a, b));
(%o12)                        true
(%i13) maybe (not equal (a, b));
(%o13)                        true
Operator: eval

As an argument in a call to ev (expr), eval causes an extra evaluation of expr. See ev.

Function: evenp (expr)

Returns true if expr is an even integer. false is returned in all other cases.

Function: fix (x)

A synonym for entier (x).

Function: fullmap (f, expr_1, ...)

Similar to map, but fullmap keeps mapping down all subexpressions until the main operators are no longer the same.

fullmap is used by the Maxima simplifier for certain matrix manipulations; thus, Maxima sometimes generates an error message concerning fullmap even though fullmap was not explicitly called by the user.

 
(%i1) a + b*c$
(%i2) fullmap (g, %);
(%o2)                   g(b) g(c) + g(a)
(%i3) map (g, %th(2));
(%o3)                     g(b c) + g(a)
Function: fullmapl (f, list_1, ...)

Similar to fullmap, but fullmapl only maps onto lists and matrices.

 
(%i1) fullmapl ("+", [3, [4, 5]], [[a, 1], [0, -1.5]]);
(%o1)                [[a + 3, 4], [4, 3.5]]
Function: is (expr)

Attempts to determine whether the predicate expr is provable from the facts in the assume database.

If the predicate is provably true or false, is returns true or false, respectively. Otherwise, the return value is controlled by the global flag prederror. When prederror is false, is returns unknown for a predicate which cannot be proven nor disproven, and reports an error otherwise.

See also assume, facts, and maybe.

Examples:

is causes evaluation of predicates.

 
(%i1) %pi > %e;
(%o1)                       %pi > %e
(%i2) is (%pi > %e);
(%o2)                         true

is attempts to derive predicates from the assume database.

 
(%i1) assume (a > b);
(%o1)                        [a > b]
(%i2) assume (b > c);
(%o2)                        [b > c]
(%i3) is (a < b);
(%o3)                         false
(%i4) is (a > c);
(%o4)                         true
(%i5) is (equal (a, c));
(%o5)                         false

If is can neither prove nor disprove a predicate from the assume database, the global flag prederror governs the behavior of is.

 
(%i1) assume (a > b);
(%o1)                        [a > b]
(%i2) prederror: true$
(%i3) is (a > 0);
`macsyma' was unable to evaluate the predicate:
a > 0
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i4) prederror: false$
(%i5) is (a > 0);
(%o5)                        unknown
Function: maybe (expr)

Attempts to determine whether the predicate expr is provable from the facts in the assume database.

If the predicate is provably true or false, maybe returns true or false, respectively. Otherwise, maybe returns unknown.

maybe is functionally equivalent to is with prederror: false, but the result is computed without actually assigning a value to prederror.

See also assume, facts, and is.

Examples:

 
(%i1) maybe (x > 0);
(%o1)                        unknown
(%i2) assume (x > 1);
(%o2)                        [x > 1]
(%i3) maybe (x > 0);
(%o3)                         true
Function: isqrt (x)

Returns the "integer square root" of the absolute value of x, which is an integer.

Function: lmax (L)

When L is a list or a set, return apply ('max, args (L)). When L isn't a list or a set, signal an error.

Function: lmin (L)

When L is a list or a set, return apply ('min, args (L)). When L isn't a list or a set, signal an error.

Function: max (x_1, ..., x_n)

Return a simplified value for the maximum of the expressions x_1 through x_n. When get (trylevel, maxmin), is 2 or greater, max uses the simplification max (e, -e) --> |e|. When get (trylevel, maxmin) is 3 or greater, max tries to eliminate expressions that are between two other arguments; for example, max (x, 2*x, 3*x) --> max (x, 3*x). To set the value of trylevel to 2, use put (trylevel, 2, maxmin).

Function: min (x_1, ..., x_n)

Return a simplified value for the minimum of the expressions x_1 through x_n. When get (trylevel, maxmin), is 2 or greater, min uses the simplification min (e, -e) --> -|e|. When get (trylevel, maxmin) is 3 or greater, min tries to eliminate expressions that are between two other arguments; for example, min (x, 2*x, 3*x) --> min (x, 3*x). To set the value of trylevel to 2, use put (trylevel, 2, maxmin).

Function: polymod (p)
Function: polymod (p, m)

Converts the polynomial p to a modular representation with respect to the current modulus which is the value of the variable modulus.

polymod (p, m) specifies a modulus m to be used instead of the current value of modulus.

See modulus.

Function: mod (x, y)

If x and y are real numbers and y is nonzero, return x - y * floor(x / y). Further for all real x, we have mod (x, 0) = x. For a discussion of the definition mod (x, 0) = x, see Section 3.4, of "Concrete Mathematics," by Graham, Knuth, and Patashnik. The function mod (x, 1) is a sawtooth function with period 1 with mod (1, 1) = 0 and mod (0, 1) = 0.

To find the principal argument (a number in the interval (-%pi, %pi]) of a complex number, use the function x |-> %pi - mod (%pi - x, 2*%pi), where x is an argument.

When x and y are constant expressions (10 * %pi, for example), mod uses the same big float evaluation scheme that floor and ceiling uses. Again, it's possible, although unlikely, that mod could return an erroneous value in such cases.

For nonnumerical arguments x or y, mod knows several simplification rules:

 
(%i1) mod(x,0);
(%o1) x
(%i2) mod(a*x,a*y);
(%o2) a*mod(x,y)
(%i3) mod(0,x);
(%o3) 0
Function: oddp (expr)

is true if expr is an odd integer. false is returned in all other cases.

Operator: pred

As an argument in a call to ev (expr), pred causes predicates (expressions which evaluate to true or false) to be evaluated. See ev.

Function: make_random_state (n)
Function: make_random_state (s)
Function: make_random_state (true)
Function: make_random_state (false)

A random state object represents the state of the random number generator. The state comprises 627 32-bit words.

make_random_state (n) returns a new random state object created from an integer seed value equal to n modulo 2^32. n may be negative.

make_random_state (s) returns a copy of the random state s.

make_random_state (true) returns a new random state object, using the current computer clock time as the seed.

make_random_state (false) returns a copy of the current state of the random number generator.

Function: set_random_state (s)

Copies s to the random number generator state.

set_random_state always returns done.

Function: random (x)

Returns a pseudorandom number. If x is an integer, random (x) returns an integer from 0 through x - 1 inclusive. If x is a floating point number, random (x) returns a nonnegative floating point number less than x. random complains with an error if x is neither an integer nor a float, or if x is not positive.

The functions make_random_state and set_random_state maintain the state of the random number generator.

The Maxima random number generator is an implementation of the Mersenne twister MT 19937.

Examples:

 
(%i1) s1: make_random_state (654321)$
(%i2) set_random_state (s1);
(%o2)                         done
(%i3) random (1000);
(%o3)                          768
(%i4) random (9573684);
(%o4)                        7657880
(%i5) random (2^75);
(%o5)                11804491615036831636390
(%i6) s2: make_random_state (false)$
(%i7) random (1.0);
(%o7)                   .2310127244107132
(%i8) random (10.0);
(%o8)                   4.394553645870825
(%i9) random (100.0);
(%o9)                   32.28666704056853
(%i10) set_random_state (s2);
(%o10)                        done
(%i11) random (1.0);
(%o11)                  .2310127244107132
(%i12) random (10.0);
(%o12)                  4.394553645870825
(%i13) random (100.0);
(%o13)                  32.28666704056853
Function: rationalize (expr)

Convert all double floats and big floats in the Maxima expression expr to their exact rational equivalents. If you are not familiar with the binary representation of floating point numbers, you might be surprised that rationalize (0.1) does not equal 1/10. This behavior isn't special to Maxima - the number 1/10 has a repeating, not a terminating, binary representation.

 
(%i1) rationalize(0.5);
(%o1) 1/2
(%i2) rationalize(0.1);
(%o2) 3602879701896397/36028797018963968
(%i3) fpprec : 5$
(%i4) rationalize(0.1b0);
(%o4) 209715/2097152
(%i5) fpprec : 20$
(%i6) rationalize(0.1b0);
(%o6) 236118324143482260685/2361183241434822606848
(%i7) rationalize(sin(0.1 * x + 5.6));
(%o7) sin((3602879701896397*x)/36028797018963968+3152519739159347/562949953421312)

Example use:

 
unitfrac(r) := block([uf : [], q],
   if not(ratnump(r)) then error("The input to 'unitfrac' must be a rational number"),
   while r # 0 do (
        uf : cons(q : 1/ceiling(1/r), uf),
        r : r - q),
   reverse(uf)); 

(%i2) unitfrac(9/10);
(%o2) [1/2,1/3,1/15]
(%i3) apply("+",%);
(%o3) 9/10
(%i4) unitfrac(-9/10);
(%o4) [-1,1/10]
(%i5) apply("+",%);
(%o5) -9/10
(%i6) unitfrac(36/37);
(%o6) [1/2,1/3,1/8,1/69,1/6808]
(%i7) apply("+",%);
(%o7) 36/37   
Function: sign (expr)

Attempts to determine the sign of expr on the basis of the facts in the current data base. It returns one of the following answers: pos (positive), neg (negative), zero, pz (positive or zero), nz (negative or zero), pn (positive or negative), or pnz (positive, negative, or zero, i.e. nothing known).

Function: signum (x)

For numeric x, returns 0 if x is 0, otherwise returns -1 or +1 as x is less than or greater than 0, respectively.

If x is not numeric then a simplified but equivalent form is returned. For example, signum(-x) gives -signum(x).

Function: sort (list, p)
Function: sort (list)

Sorts list according to a predicate p of two arguments, such as "<" or orderlessp.

sort (list) sorts list according to Maxima's built-in ordering.

list may contain numeric or nonnumeric items, or both.

Function: sqrt (x)

The square root of x. It is represented internally by x^(1/2). See also rootscontract.

radexpand if true will cause nth roots of factors of a product which are powers of n to be pulled outside of the radical, e.g. sqrt(16*x^2) will become 4*x only if radexpand is true.

Option variable: sqrtdispflag

Default value: true

When sqrtdispflag is false, causes sqrt to display with exponent 1/2.

Function: sublis (list, expr)

Makes multiple parallel substitutions into an expression.

The variable sublis_apply_lambda controls simplification after sublis.

Example:

 
(%i1) sublis ([a=b, b=a], sin(a) + cos(b));
(%o1)                    sin(b) + cos(a)
Function: sublist (list, p)

Returns the list of elements of list for which the predicate p returns true.

Example:

 
(%i1) L: [1, 2, 3, 4, 5, 6]$
(%i2) sublist (L, evenp);
(%o2)                       [2, 4, 6]
Option variable: sublis_apply_lambda

Default value: true - controls whether lambda's substituted are applied in simplification after sublis is used or whether you have to do an ev to get things to apply. true means do the application.

Function: subst (a, b, c)

Substitutes a for b in c. b must be an atom or a complete subexpression of c. For example, x+y+z is a complete subexpression of 2*(x+y+z)/w while x+y is not. When b does not have these characteristics, one may sometimes use substpart or ratsubst (see below). Alternatively, if b is of the form e/f then one could use subst (a*f, e, c) while if b is of the form e^(1/f) then one could use subst (a^f, e, c). The subst command also discerns the x^y in x^-y so that subst (a, sqrt(x), 1/sqrt(x)) yields 1/a. a and b may also be operators of an expression enclosed in double-quotes " or they may be function names. If one wishes to substitute for the independent variable in derivative forms then the at function (see below) should be used.

subst is an alias for substitute.

subst (eq_1, expr) or subst ([eq_1, ..., eq_k], expr) are other permissible forms. The eq_i are equations indicating substitutions to be made. For each equation, the right side will be substituted for the left in the expression expr.

exptsubst if true permits substitutions like y for %e^x in %e^(a*x) to take place.

When opsubst is false, subst will not attempt to substitute into the operator of an expression. E.g. (opsubst: false, subst (x^2, r, r+r[0])) will work.

Examples:

 
(%i1) subst (a, x+y, x + (x+y)^2 + y);
                                    2
(%o1)                      y + x + a
(%i2) subst (-%i, %i, a + b*%i);
(%o2)                       a - %i b

For further examples, do example (subst).

Function: substinpart (x, expr, n_1, ..., n_k)

Similar to substpart, but substinpart works on the internal representation of expr.

 
(%i1) x . 'diff (f(x), x, 2);
                              2
                             D
(%o1)                    x . --- (f(x))
                               2
                             dx
(%i2) substinpart (d^2, %, 2);
                                  2
(%o2)                        x . d
(%i3) substinpart (f1, f[1](x+1), 0);
(%o3)                       f1(x + 1)

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

 
(%i1) part (x+y+z, [1, 3]);
(%o1)                         z + x

piece holds the value of 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.

 
(%i1) expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
              3         2       2            3
(%o1)     27 y  + 54 x y  + 36 x  y + y + 8 x  + x + 1
(%i2) part (expr, 2, [1, 3]);
                                  2
(%o2)                         54 y
(%i3) sqrt (piece/54);
(%o3)                        abs(y)
(%i4) substpart (factor (piece), expr, [1, 2, 3, 5]);
                               3
(%o4)               (3 y + 2 x)  + y + x + 1
(%i5) expr: 1/x + y/x - 1/z;
                             1   y   1
(%o5)                      - - + - + -
                             z   x   x
(%i6) substpart (xthru (piece), expr, [2, 3]);
                            y + 1   1
(%o6)                       ----- - -
                              x     z

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

Function: substpart (x, expr, n_1, ..., n_k)

Substitutes x for the subexpression picked out by the rest of the arguments as in part. It returns the new value of expr. x may be some operator to be substituted for an operator of expr. In some cases x needs to be enclosed in double-quotes " (e.g. substpart ("+", a*b, 0) yields b + a).

 
(%i1) 1/(x^2 + 2);
                               1
(%o1)                        ------
                              2
                             x  + 2
(%i2) substpart (3/2, %, 2, 1, 2);
                               1
(%o2)                       --------
                             3/2
                            x    + 2
(%i3) a*x + f (b, y);
(%o3)                     a x + f(b, y)
(%i4) substpart ("+", %, 1, 0);
(%o4)                    x + f(b, y) + a

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

Function: subvarp (expr)

Returns true if expr is a subscripted variable, for example a[i].

Function: symbolp (expr)

Returns true if expr is a symbol, else false. In effect, symbolp(x) is equivalent to the predicate atom(x) and not numberp(x).

See also Identifiers.

Function: unorder ()

Disables the aliasing created by the last use of the ordering commands ordergreat and orderless. ordergreat and orderless may not be used more than one time each without calling unorder. See also ordergreat and orderless.

 
(%i1) unorder();
(%o1)                          []
(%i2) b*x + a^2;
                                   2
(%o2)                       b x + a
(%i3) ordergreat (a);
(%o3)                         done
(%i4) b*x + a^2;
                             2
(%o4)                       a  + b x
(%i5) %th(1) - %th(3);
                              2    2
(%o5)                        a  - a
(%i6) unorder();
(%o6)                          [a]
Function: vectorpotential (givencurl)

Returns the vector potential of a given curl vector, in the current coordinate system. potentialzeroloc has a similar role as for potential, but the order of the left-hand sides of the equations must be a cyclic permutation of the coordinate variables.

Function: xthru (expr)

Combines all terms of expr (which should be a sum) over a common denominator without expanding products and exponentiated sums as ratsimp does. xthru cancels common factors in the numerator and denominator of rational expressions but only if the factors are explicit.

Sometimes it is better to use xthru before ratsimping an expression in order to cause explicit factors of the gcd of the numerator and denominator to be canceled thus simplifying the expression to be ratsimped.

 
(%i1) ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
                                20
                 1       (x + 2)   - 2 y       x
(%o1)        --------- + --------------- - ---------
                    19             20             20
             (y + x)        (y + x)        (y + x)
(%i2) xthru (%);
                                 20
                          (x + 2)   - y
(%o2)                     -------------
                                   20
                            (y + x)
Function: zeroequiv (expr, v)

Tests whether the expression expr in the variable v is equivalent to zero, returning true, false, or dontknow.

zeroequiv has these restrictions:

  1. Do not use functions that Maxima does not know how to differentiate and evaluate.
  2. If the expression has poles on the real line, there may be errors in the result (but this is unlikely to occur).
  3. If the expression contains functions which are not solutions to first order differential equations (e.g. Bessel functions) there may be incorrect results.
  4. The algorithm uses evaluation at randomly chosen points for carefully selected subexpressions. This is always a somewhat hazardous business, although the algorithm tries to minimize the potential for error.

For example zeroequiv (sin(2*x) - 2*sin(x)*cos(x), x) returns true and zeroequiv (%e^x + x, x) returns false. On the other hand zeroequiv (log(a*b) - log(a) - log(b), a) returns dontknow because of the presence of an extra parameter b.


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

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