eigenmath/doc/manual/symbols.tex

152 lines
2.6 KiB
TeX
Raw Permalink Normal View History

2009-01-01 21:36:38 +01:00
\subsection{Defining symbols}
2009-01-02 00:58:36 +01:00
As we saw earlier, Eigenmath uses the same syntax as dear old Fortran.
2009-01-01 21:36:38 +01:00
\medskip
\verb$N=212^17$
\medskip
\noindent
No result is printed when a symbol is defined.
To see a symbol's value, just evaluate it.
\medskip
\verb$N$
$$3529471145760275132301897342055866171392$$
\medskip
\noindent
Beyond its prosaic syntax, Eigenmath does have a few tricks up its sleeve.
For example, a symbol can have a subscript.
\medskip
\verb$NA=6.02214*10^23$
\verb$NA$
$$N_A=6.02214\times10^{23}$$
\medskip
\noindent
A symbol can be the name of a Greek letter.
\medskip
\verb$xi=1/2$
\verb$xi$
$$\xi=\hbox{$1\over2$}$$
\medskip
\noindent
Since xi is $\xi$, how is $x_i$ entered?
Well, that is an issue that may get resolved in the future.
For now, xi is always $\xi$.
\medskip
\noindent
2009-01-02 00:54:29 +01:00
Greek letters can appear in the subscript too.
\medskip
\verb$Amu=2.0$
\verb$Amu$
$$A_\mu=2.0$$
2009-01-01 21:36:38 +01:00
2009-01-01 22:39:28 +01:00
\medskip
2009-01-02 00:54:29 +01:00
\noindent
The general rule is this.
Eigenmath scans the entire symbol looking for Greek letters.
\medskip
\verb$alphamunu$
$$\alpha_{\mu\nu}$$
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
\newpage
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
\medskip
\noindent
Let us turn now to what happens when a symbolic expression is evaluated.
The most important point is that
Eigenmath exhaustively evaluates symbolic subexpressions.
\medskip
\verb$A=B$
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
\verb$B=C$
2009-01-01 22:39:28 +01:00
\verb$C=D$
2009-01-02 00:54:29 +01:00
\verb$sin(A)$
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
$$\sin(D)$$
2009-01-01 22:39:28 +01:00
\medskip
\noindent
2009-01-02 00:54:29 +01:00
In the above example, evaluating $\sin(A)$ yields $\sin(D)$ because Eigenmath
resolves $A$ as far as it can, in this case down to $D$.
However, internally the binding of $A$ is still $B$, as can be seen with
the $binding$ function.
2009-01-01 22:39:28 +01:00
\medskip
\verb$binding(A)$
2009-01-02 00:54:29 +01:00
$$B$$
2009-01-01 22:39:28 +01:00
\medskip
\noindent
2009-01-02 00:54:29 +01:00
Let us return to symbolic definitions for a moment.
It should be kept in mind that the right hand side of the definition is an
expression that is evaluated before the binding is done.
For example,
2009-01-01 22:39:28 +01:00
\medskip
2009-01-02 00:54:29 +01:00
\verb$B=1$
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
\verb$A=B$
2009-01-01 22:39:28 +01:00
\verb$binding(A)$
2009-01-02 00:54:29 +01:00
$$1$$
2009-01-01 22:39:28 +01:00
\medskip
\noindent
2009-01-02 00:54:29 +01:00
The binding of $A$ is 1 and not $B$ because $B$ was already defined before
the $A=B$ occurred.
The $quote$ function can be used to give a literal binding.
2009-01-01 22:39:28 +01:00
\medskip
2009-01-02 00:54:29 +01:00
\verb$A=quote(B)$
2009-01-01 22:39:28 +01:00
\verb$binding(A)$
2009-01-02 00:54:29 +01:00
$$B$$
2009-01-01 22:39:28 +01:00
2009-01-02 00:54:29 +01:00
\newpage
2009-01-01 22:39:28 +01:00
\noindent
2009-01-02 00:54:29 +01:00
What this all means is that symbols have a dual nature.
A symbol has a binding which may be different from its evaluation.
Normally this difference is not important.
2009-01-01 22:39:28 +01:00
The functions $quote$ and $binding$ are mentioned here mainly to provide insight
into what is happening belowdecks.
Normally you should not really need to use these functions.
However, one notable exception is the use of $quote$ to clear a symbol.
\medskip
\verb$x=3$
\verb$x$
$$x=3$$
\verb$x=quote(x)$
\verb$x$
$$x$$
2009-01-01 21:36:38 +01:00