## Maxima – 37 – Espressioni – 6 Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.111.

`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).

`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, if `expr` is a subscripted function expression, `op` returns the subscripted function; in this case the return value is not an atom. Otherwise, `expr` is an array function or ordinary function expression, and `op` returns a symbol.

`op` observes the value of the global flag `inflag`.

`op` evaluates it argument.

``````(%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"
(%i12) op (F [x, y] (a, b, c));
(%o12)                               F
x, y
(%i13) op (G [u, v, w]);
(%o13)                                 G``````

`operatorp (expr, op)`
`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`.

`opsubst`
Default value: `true`
When `opsubst` is `false`, `subst` does not attempt to substitute into the operator of an expression. E.g., `(opsubst: false, subst(x^2, r, r+r))` will work.

``````(%i14) r+r;
(%o14)                              r + r
0
(%i15) opsubst;
(%o15)                               true
(%i16) subst (x^2, r, r+r);
2     2
(%o16)                            x  + (x )
0
(%i17) opsubst: false;
(%o17)                               false
(%i18) subst (x^2, r, r+r);
2
(%o18)                              x  + r
0``````

`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.

``````(%i19) example(optimize);

(%i1)
(%i20) diff(exp(x^2+y)/(x+y),x,2)
2            2              2            2
2   y + x        y + x          y + x        y + x
4 x  %e         2 %e         4 x %e         2 %e
(%o20)      ------------- + ---------- - ------------ + ----------
y + x         y + x               2             3
(y + x)       (y + x)
(%i1)
(%i21) optimize(%)
2         y + %2       1
(%o21) block([%1, %2, %3, %4], %1 : y + x, %2 : x , %3 : %e      , %4 : --,
%1
4 x %3   2 %3
4 %2 %4 %3 + 2 %4 %3 - ------ + ----)
2       3
%1      %1
(%o21)                               done``````

`optimprefix`
Default value: `%`
`optimprefix` is the prefix used for generated symbols by the `optimize` command.

`ordergreat (v_1, ..., v_n)`
`orderless (v_1, ... , v_n)`
`ordergreat` changes the canonical ordering of Maxima expressions such that `v_1` succeeds `v_2` succeeds `...` succeeds `v_n`, and `v_n` succeeds any other symbol not mentioned as an argument.

`orderless` changes the canonical ordering of Maxima expressions such that `v_1` precedes `v_2` precedes `...` precedes `v_n`, and `v_n` precedes any other variable not mentioned as an argument.

The order established by `ordergreat` and `orderless` is dissolved by `unorder`.

`ordergreat` and `orderless` can be called only once each, unless `unorder` is called; only the last call to `ordergrea`t and `orderless` has any effect.

`ordergreatp (expr_1, expr_2)`
`orderlessp (expr_1, expr_2)`
`ordergreatp` returns `true` if `expr_1` succeeds `expr_2` in the canonical ordering of Maxima expressions, and `false` otherwise.

`orderlessp` returns `true` if `expr_1` precedes `expr_2` in the canonical ordering of Maxima expressions, and `false` otherwise.

All Maxima atoms and expressions are comparable under `ordergreatp` and `orderlessp`, although there are isolated examples of expressions for which these predicates are not transitive; that is a bug.

The canonical ordering of atoms (symbols, literal numbers, and strings) is the following: (integers and floats) precede (bigfloats) precede (declared constants) precede (strings) precede (declared scalars) precede (first argument to `orderless`) precedes `...` precedes (last argument to `orderless`) precedes (other symbols) precede (last argument to `ordergreat)` precedes `...` precedes (first argument to `ordergreat`) precedes (declared main variables).

For non-atomic expressions, the canonical ordering is derived from the ordering for atoms. For the built-in `+`, `*` and `^` operators, the ordering is not easily summarized.

For other built-in operators and all other functions and operators, expressions are ordered by their arguments (beginning with the first argument), then by the name of the operator or function. In the case of subscripted expressions, the subscripted symbol is considered the operator and the subscript is considered an argument.

The canonical ordering of expressions is modified by the functions `ordergreat` and `orderless`, and the `mainvar`, constant, and scalar declarations.

See also `sort`.

Ordering ordinary symbols and constants. Note that `%pi` is not ordered according to its numerical value.

``````(%i22) stringdisp : true;
(%o22)                               true
(%i23) sort ([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
(%o23)    [3, 3.0, 4, 4.0, 3.0b0, 4.0b0, %pi, "bar", "foo", X, a, x]``````

Effect of `ordergreat` and `orderless` functions.

``````(%i25) ordergreat (S, J);
(%o25)                               done
(%i26) orderless (M, H);
(%o26)                               done
(%i27) sort ([M, H, K, T, E, W, G, A, P, J, S]);
(%o27)                 [M, H, A, E, G, K, P, T, W, J, S]``````

Effect of `mainvar`, constant, and `scalar` declarations.

``````(%i1) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
(%o1)          [A1, B1, C1, aa, bar, baz, bb, cc, dd, foo, quux]
(%i2) declare (aa, mainvar);
(%o2)                                done
(%i3) declare ([A1, B1], scalar);
(%o3)                                done
(%i4) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
(%o4)          [A1, B1, C1, bar, baz, bb, cc, dd, foo, quux, aa]``````

Ordering non-atomic expressions.

``````(%i5) sort ([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n), f(n, 1)]);
(%o5)    [1, 2, f(1), g(1), g(1, 2), f(2), f(2, 1), n, g(n), f(n, 1)]
(%i6) sort ([foo(1), X, X[k], foo(k), 1, k]);
(%o6)                   [1, X , foo(1), k, X , foo(k)]
1              k``````

Posta un commento o usa questo indirizzo per il trackback.