Maxima – 32 – Espressioni – 1

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.99.

Introduzione
There are a number of reserved words which should not 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.

(%i5) y: (x: 1, for i from 1 thru 10 do (x: x*i))$

(%i6) y;
(%o6)                                done

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

(%i7) y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$

(%i8) y;
(%o8)                               3628800

Nomi e verbi
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.

(%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;
(%o8)                               bar(52)
(%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)

Nota per me: continuando a inserire comandi in Maxima senza uscire avevo ottenuto un errore in integrate. Conviene rilanciare Maxima per liberarsi da conflitti da istruzioni precedenti.

A volte la versione grafica wxMaxima ha la sua utilità:

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: