next up previous index
Next: Forcing Floating Point Evaluation Up: Numbers Previous: Numbers

Simple Arithmetic

You  can use all three systems as a calculator. For example, Maxima (note that at this stage I'll quit Bill Shelter's book mode and switch directly to the Maxima buffer):

(C1) 23 * 11 - 252.52;
(D1)                          0.47999999999998977
And now the same in Maple:
> 23 * 11 - 252.52;
                                      .48

>
and in Mathematica:
In[2]:= 23 * 11 - 252.52

Out[2]= 0.48

In[3]:=

Mathematica and Maple sensibly round the result to give the same number of decimal digits as used in the input. Maxima, interestingly, shows you the whole truth, i.e., you can see the rounding error that always accompanies floating point  computations.

Factorials: Maxima first:

\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}(C3) 200!;...
...0000000000000000000000000
(C4)\end{verbatim}\end{tex2html_preform}}
\end{figure}

Now Maple:
\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}> 200!;
78...
...00000000\
0000000000000000>\end{verbatim}\end{tex2html_preform}}
\end{figure}

$\ldots$ and Mathematica:
\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}In[3]:= 20...
...
> 000000000000000000In[4]:=\end{verbatim}\end{tex2html_preform}}
\end{figure}

In Maple  and in Mathematica we can now factor this very long integer as follows:

Maple:

\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}> ifactor(...
...81) (191) (193) (197) (199)>\end{verbatim}\end{tex2html_preform}}
\end{figure}

$\ldots$ and Mathematica:
\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}In[4]:= Fa...
...> {197, 1}, {199, 1}}In[5]:=\end{verbatim}\end{tex2html_preform}}
\end{figure}

In all three systems, the percent symbol, %, brings back  the last computed expression.

Maxima, unfortunately, does not provide a precooked function for doing this. In general, although Maxima does provide some support for number theory, it lags behind her two sisters in a few places. But$\ldots$ watch this space! You are going to address this shortcoming and write ifactor for Maxima yourself at some stage!

In Maple the expression obtained by ifactoring 200! can be put back into a single number with 

\begin{figure}
{\footnotesize
\begin{tex2html_preform}\begin{verbatim}> expand(%...
...00000000\
0000000000000000>\end{verbatim}\end{tex2html_preform}}
\end{figure}

because ifactor returns a single numerical expression. But since Mathematica's FactorInteger returns a list, we would have to write a simple Mathematica program in order to wind that list back into 200!.

When it comes to arithmetic all three try to compute things as accurately as possible, i.e., they will try not to convert results of integer division and other algebraic operations into floating point numbers, unless specifically requested. This is Maxima trying to compute $2^{30} \sqrt{3} / 3^{20}$:

\begin{figure}
\begin{tex2html_preform}\begin{verbatim}(C38) (2^30/3^20) * sqrt(...
...--------------
3486784401
(C39)\end{verbatim}\end{tex2html_preform}\end{figure}

Maple does much the same:
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}> (2^30/3^20) * sqrt(3);
...
...1/2
---------- 3
3486784401>\end{verbatim}\end{tex2html_preform}\end{figure}

Mathematica returns a result, which looks different, but only because it used one of the 3-s in the denominator to move $\sqrt{3}$ downstairs:
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}In[8]:= (2^30/3^20) Sqrt[...
...---
1162261467 Sqrt[3]In[9]:=\end{verbatim}\end{tex2html_preform}\end{figure}


next up previous index
Next: Forcing Floating Point Evaluation Up: Numbers Previous: Numbers
Zdzislaw Meglicki
2001-02-26