152 lines
2.6 KiB
TeX
152 lines
2.6 KiB
TeX
|
|
\subsection{Defining symbols}
|
|
As we saw earlier, Eigenmath uses the same syntax as dear old Fortran.
|
|
|
|
\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
|
|
Greek letters can appear in the subscript too.
|
|
|
|
\medskip
|
|
\verb$Amu=2.0$
|
|
|
|
\verb$Amu$
|
|
|
|
$$A_\mu=2.0$$
|
|
|
|
\medskip
|
|
\noindent
|
|
The general rule is this.
|
|
Eigenmath scans the entire symbol looking for Greek letters.
|
|
|
|
\medskip
|
|
\verb$alphamunu$
|
|
|
|
$$\alpha_{\mu\nu}$$
|
|
|
|
\newpage
|
|
|
|
\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$
|
|
|
|
\verb$B=C$
|
|
|
|
\verb$C=D$
|
|
|
|
\verb$sin(A)$
|
|
|
|
$$\sin(D)$$
|
|
|
|
\medskip
|
|
\noindent
|
|
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.
|
|
|
|
\medskip
|
|
\verb$binding(A)$
|
|
|
|
$$B$$
|
|
|
|
\medskip
|
|
\noindent
|
|
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,
|
|
|
|
\medskip
|
|
\verb$B=1$
|
|
|
|
\verb$A=B$
|
|
|
|
\verb$binding(A)$
|
|
|
|
$$1$$
|
|
|
|
\medskip
|
|
\noindent
|
|
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.
|
|
|
|
\medskip
|
|
\verb$A=quote(B)$
|
|
|
|
\verb$binding(A)$
|
|
|
|
$$B$$
|
|
|
|
\newpage
|
|
|
|
\noindent
|
|
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.
|
|
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$$
|
|
|