%
% $Id: graeve.tex,v 1.8 2001/03/09 11:01:31 cibrario Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[a4paper,10pt,DIV10]{scrartcl}
%\textwidth 11,8 cm
%\textheight 17 cm
%\def\@evenhead{\thepage\hfill{\footnotesize\textit{\leftmark}}}
%\def\@oddhead{\footnotesize{\textit{\rightmark}}\hfill\thepage}
%\usepackage{hp}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ae}
% \usepackage{times,mathptmx} % Times for text and math
\usepackage[english]{babel}
\usepackage{latexsym}
\usepackage{makeidx}
\usepackage[]{hyperref}
\hypersetup{pdftitle = {HP49 CAS},%
pdfcreator = {pdfTeX},%
pdfauthor = {},%
pdfsubject = {},%
pdfkeywords = {CAS, HP49},%
pdfproducer = {},%
%pdflinkmargin = 5pt,%
%pdfborder = 0,%
%colorlinks = true,%
%linkcolor = blue,%
linktocpage =true,% Linkbereich nur um Seitennummer!
%bookmarks = false,%
%bookmarksopen = false,%
%bookmarksopenlevel = 0,%
pdfstartview = FitH,% <---------- hier steht es!
%pdfpagemode = UseOutlines,%
%plainpages = false%
}%
\title {Calcul formel \\et \\ Math\'ematiques\\ avec\\ la HP49G \\en mode
alg\'ebrique}
\author{Ren\'ee De Graeve\\ Ma\^itre de Conf\'erence \`a Grenoble I}
\date{}
\makeindex
\begin{document}
\maketitle
{\bf \centerline{Remerciements}}
\vspace{1cm}
Je remercie:
\begin{itemize}
\item Bernard Parisse pour ses pr\'ecieux conseils et ses remarques
sur ce texte,
\item Sylvain Daud\'e pour sa relecture,
\item Jean Tavenas pour l'int\'er\^et port\'e \`a l'ach\`evement de ce
guide,
\item les \'el\`eves de Terminale du lyc\'ee Notre-Dame des Victoires
de Voiron, ainsi que leur professeur Jean Marc Paucod, pour leur
participation au test du sujet de bac avec la HP49.
\end{itemize}
\vfill
\copyright\ 09/1999 Ren\'ee De Graeve,
\verb|degraeve@fourier.ujf-grenoble.fr|
\footnote{Translation \copyright 03/2001 Ivan Cibrario Bertolotti.\\
Subject to the same licensing terms and conditions as the original.}\\
Reproduction, translation and redistribution of this document either
stored on an electronic support or written on paper are granted for
non-commercial purposes only.
Any commercial use of this document is prohibited without prior
written permission of the copyright holder.
This documentation is provided ``as is'', without warranty of any kind.
In no event the copyright holder will be liable for
damages arising out of the use of this document.\\
Its contents don't imply in any event the responsibility of either
the Hewlett-Packard Company or its distributors.
This document is also available at the following Internet address:\\
\begin{verbatim}
http://www-fourier.ujf-grenoble.fr/~degraeve/usflan.pdf
\end{verbatim}
\newpage
{\bf \centerline{Foreword}}
\vspace{1cm}
Sometimes, I am asked this question: why put symbolic manipulation
capabilities into a calculator, while specialized computer software
for this is now either cheap, or available for free?
In my opinion, a calculator is the most effective way to integrate
calculation aids with the teaching of mathematics, because it is both
easy to carry out with you and to use in a classroom.
However, using a symbolic manipulation software package is not
as simple as its interface could suggest\ldots Therefore, having
an adequate documentation for it is important. The HP49G user guide
describes the computer algebra system very briefly, so this manual
is its essential complement:
it describes the HP49G from the point of view of someone
that ``wants to do maths''.
In fact, readers interested in maths can read only this book as well,
because the author starts with an introduction to the calculator,
describes in more detail the computer algebra system
commands arranged by purpose (the index allows the reader to
find all commands in alphabetical order), and then focuses
on programming the calculator in algebraic mode.
Each command is demonstrated by an example, and many of them are
leveraged to solve a ``baccalaureat'' problem. The programming
section has several programs, arithmetic programs in particular.
Briefly, this is the manual I should have written if I had enough patience!
I thank Ren\'ee for carrying it out.
\vspace{1cm}
Bernard Parisse\\
Ma\^itre de Conf\'erences \`a l'Universit\'e de Grenoble I\\
Author of the Computer Algebra System of the HP49G
\section{Getting started}
\subsection{Introduction}
\subsubsection{Turning on the calculator}
Press the {\tt ON} key.\\
When the calculator is turned on, the same key exits an application:
it acts as either {\tt EXIT} or {\tt CANCEL}.\\
To turn off the calculator, press {\tt red-shift} and then {\tt ON}.\\
If the calculator does not respond in despite of several {\tt ON}
({\tt CANCEL}), press both {\tt ON} and {\tt F3} simultaneously to
reinitialize it.
\subsubsection{What am I looking at?}
From top to bottom, you can see:\\
1. the screen\\
1.a the calculator status\\
1.b the calculation history\\
1.c a menu containing some commands\\
2. the keyboard
\vspace{1cm}
\noindent 1. The screen:\\
1.a The calculator status describes the current calculator modes:
\begin{itemize}
\item {\tt RAD} if the calculator is working in radians, {\tt DEG} if
it is working in degrees.
\item {\tt XYZ} shows that rectangular coordinates are in use.
\item {\tt HEX} shows that binary integers prefixed by
{\tt \#} are displayed in base 16.
\item {\tt R} if the calculator is in REAL mode, {\tt C} if it is
in COMPLEX mode.
\item {\tt =} if the calculator is in EXACT mode (symbolic calculations),
${\tt \sim}$ if the calculator is in APPROXIMATE mode (numeric calculations).
\item {\tt 'X'} denotes the name of the current variable stored in
{\tt VX}: usually it is {\tt 'X'}.
\item {\tt ALG} if the calculator is in ALGEBRAIC mode, {\tt RPN} if it
is in RPN mode.
\item {\tt \{HOME\}} or {\tt \{HOME ESSAI\}} to show the name of the
current directory (for example, the main directory
HOME or the ESSAI subdirectory).
\end{itemize}
1.b The calculation history:\\
General principle: on the screen, the input expression
(prefixed by {\tt :}) is displayed left-justified,
and the result is right-justified.
1.c The menu:\\
Menu commands are accessed using the following keys:\\
{\tt F1 F2 F3 F4 F5 F6}.\\
When the menu has more than 6 commands, press the {\tt NXT} key
to display the next portion of the menu. The menu can also contain
subdirectories (which, in turn, contain a set of commands): they
can be recognized because their menu item has
a small bar across the upper-left corner.
To execute a menu command, simply press the corresponding
{\tt Fi} key. \\
2. The keyboard:\\
You should find:
\begin{itemize}
\item the {\tt ON} key, to turn on the calculator, and to interrupt a
calculation while it is in progress. To turn off the calculator,
press {\tt red-shift} and then {\tt ON}.
\item two ``shift'' keys, one blue and one red; they allow
a single key to have more than one function.
\item the {\tt ALPHA} key, to enter alphabetical characters (uppercase
by default). To keep alphabetic mode active for more than one
subsequent keystroke, it is necessary to press {\tt ALPHA} twice.
To exit this mode, press {\tt ALPHA} again. To toggle between
uppercase and lowercase alphabetic entry modes, press {\tt
blue-shift} {\tt ALPHA} while the calculator is in alphabetic
entry mode.
\item the {\tt ENTER} key; it either enters or confirms a command.
\item four arrow keys (left, right, up, down); they move the cursor
when you are either in the editor or in a command list.
\end{itemize}
\subsection{Calculator modes}
The calculator can work in several modes.\\
You can choose:
-algebraic or reverse poland notation mode ({\tt ALG} or {\tt RPN})\\
-real or complex mode (${\tt R}$ or ${\tt C}$)\\
-exact or approximate mode (${\tt =}$ or ${\tt \sim}$)\index{\tt = $\sim$}\\
-immediate or step-by-step mode...\\
{\sc Warning}: this book assumes that the calculator is in algebraic,
real, exact, immediate mode (${\tt R\ =\ ALG}$).\\
Type: {\tt CASCFG}\index{CASCFG} (Computer Algebra System ConFiG) to
set the calculator in real, exact, immediate mode. While working,
you can type {\tt CASCFG} to restore this configuration
(the calculator automatically changes mode -asking you for
a permission- when it is appropriate!).\\
{\sc Check}\\
Check now that your calculator is indeed in algebraic,
real, exact mode. In order to do this:
press {\tt MODE} to check that the operating mode really is
{\tt algebraic}; if it is not, select {\tt algebraic} either with
the {\tt choos} menu item, or pressing the ${\tt ^+/_-}$ key.
While you are in the {\tt MODE} screen, activate the {\tt cas}
menu item and check that neither
{\tt numeric}, nor {\tt approx}, nor {\tt complex} are enabled.
If one ore more of these modes are enabled, disable them all
using the {\tt chk} menu item.\\
Notice:
for pedagogic applications, it is often interesting to enable
the {\tt step/step} mode, to make the calculator execute its calculations
step by step.
Now select the {\tt ok} menu item to confirm all changes made
in {\tt cas}, and then {\tt ok} again to confirm the choices you
made in {\tt MODE}.
Now you are in algebraic, real, exact mode.\\
{\sc Warning:\\ this book assumes that the calculator is in this mode}.
You are now in the {\tt HOME} directory.
You can simply type in the calculation you want executed, for example:
$1+1$, and then press {\tt ENTER}
The result is displayed (right justified), and the
input expression $1+1$, preceded by
${\tt :}$, goes up in the history area (left justified).
It is possible to copy this expression in the command line by pressing
the {\tt HIST} key (the up arrow allows you to select the expression
to copy, and the {\tt echo } menu item copies and simplifies it).
It is also possible to reuse the last result (denoted {\tt ANS(1)})
using the {\tt ANS (red-shift ENTER)} key, as well as previous results
(denoted {\tt ANS(2)}) and so on.
You can do both exact calculations and approximate ones; for example:
$\sqrt 2$
followed by {\tt ENTER} does not evaluate $\sqrt 2$ and keeps
the result exact, but the same expression followed by
{\tt red-shift ENTER ($\rightarrow$NUM)} returns the
approximate value of $\sqrt 2$ with 12 significant digits,
keeping the calculator in exact mode.
Of course, if you want to do only numeric calculations, you can
enable {\tt approx} mode ({\tt MODE} key, and then {\tt cas} menu item);
in this mode, the {\tt ENTER} key does the calculation numerically,
evaluating both constants and variables.\\
\subsection{Notation}
In this book, the four arrow keys are represented by
the following four triangles:
$$\triangle\ \lhd \ \rhd \ \bigtriangledown $$
\index{$ \triangle\ \lhd \ \rhd \ \bigtriangledown$}
The delete arrow (deletion of the character to the left of the cursor)
is represented by:
$$\Leftarrow$$\index{$\Leftarrow$}
The red arrow over the 0 (zero) key is represented by:
$$\rightarrow$$\index{$\rightarrow$}
The {\tt STO} key is represented, in a program, by:
$$ {\tt STO\triangleright \mbox{ or }\triangleright}$$
\index{$\triangleright$ {\tt STO}$\triangleright$ }
The carriage return (in red, over the decimal point key),
is represented by:
$$\hookleftarrow$$\index{$\hookleftarrow$}
\subsection{Flags}\label{sec:flag}
The vary majority of commands takes system flags into account.\\
Each flag has its own unique number, and has a default value.
If you want to change the value of a flag, you can do it by pressing
the {\tt MODE} key, then {\tt F1} to select the {\tt flags}
menu item and enter the flag management screen.
When you toggle the flag you want changed, its new function
appears on the screen.
If you know in advance the flag number, you can also change its value
with the {\tt SF}\index{SF} and {\tt CF}\index{CF} commands.
For example, to change flag number $-117$ (that is, the flag
controlling the display of menus), you type:\\
{\tt SF(-117)} (most menus are now displayed across the bottom of
the screen, instead of using pop-up command lists).
After this command:\\
{\tt FS?(-117)}\index{FS?} returns {\tt 1.} and {\tt FC?(-117)}\index{FC?}
is {\tt 0.}\\
To have most menus displayed using pop-up command lists again, you type:\\
{\tt CF(-117)} ({\tt FS?(-117)} is now {\tt 0.} and {\tt FC?(-117)}
is {\tt 1.}).\\
\section{Important keys}
\subsection{The APPS key}
This key, when pressed, displays a list of all calculator's application.
\subsubsection{Plot functions}
This command list has the following items:\\
{\tt Equation entry}. This item acts the same as the key sequence
{\tt blue-shift F1 (Y=3D)}.\\
{\tt Plot window}. This item acts the same as the key sequence
{\tt blue-shift F2 (WIN)}.\\
{\tt Graph display}. This item acts the same as the key sequence
{\tt blue-shift F3 (GRAPH)}.\\
{\tt Plot setup}. This item acts the same as the key sequence
{\tt blue-shift F4 (2D/3D)}.\\
{\tt Table setup}. This item acts the same as the key sequence
{\tt blue-shift F5 (TBLSET)}.\\
{\tt Table display}. This item acts the same as the key sequence
{\tt blue-shift F6 (TABLE)}.\\
For more information, refer to chapter \ref{sec:graph}.
\subsubsection{I/O functions}
This list contains the commands that allow your calculator
to interface with a computer.\\
For example, the fifth item is: {\tt Transfer}.\\
If you press 5, and then {\tt ok},
the calculator opens the {\tt Transfer} window and displays:\\
Port : Wire\\
Type : Kermit (or XModem)\\
This window allows you to transfer a file interactively. You can do
the same thing from the command line, too; for example, these are the
steps you should follow to use the Linux {\tt kermit} program:\\
-Connect both the calculator and the computer to the serial link cable.\\
-On the computer, type:\\
{\tt kermit}\\
and then {\tt serv}\\
-On the {\tt HP49G} type:\\
{\tt SEND('NOM')}\\
to copy the {\tt NOM} variable from your {\tt HP49G} to your computer.\\
-Or else,\\
On the {\tt HP49G} type:\\
{\tt KGET('NOM')}\\
to copy the {\tt NOM} variable from your computer to your {\tt HP49G}.
\subsubsection{Constants library}
This item displays a list of 40 physical constants.\\
These constants are denoted by their symbol and either their name
or their value (if the {\tt value} menu item is selected).\\
They are followed by their measurement units,
if the {\tt unit} menu item is selected.\\
They can also be copied on the command line,
by pressing the {\tt ->stk} menu key.
\subsubsection{Numeric solver}
This item acts the same as the sequence of keys:
{\tt red-shift 7 (NUM.SLV)}.
\subsubsection{Time \& date}
This item acts the same as the sequence of key:
{\tt red-shift 9 (TIME)}.
\subsubsection{Equation writer}
This item acts the same as the
{\tt EQW} key.\\
See section \ref{sec:eqw} for more details.
\subsubsection{File manager}
This item acts the same as the sequence of keys:
{\tt blue-shift APPS (FILES)}.\\
See section \ref{sec:rep} for more details.
\subsubsection{Matrix writer}
This item acts the same as the sequence of keys:
{\tt blue-shift EQW (MTRW)}.\\
See section \ref{sec:mtrw} for more details.
\subsubsection{Text editor}
This item opens the command line: notice that it is possible
to write on more than one line (by pressing
${\tt red-shift\ \bullet\ (\hookleftarrow)}$ to open a new line).
\subsubsection{Math menu}
This item acts the same as the sequence of keys:
{\tt blue-shift SYMB (MTH)}.
\subsubsection{CAS menu}
This item opens a command list with the following entries:\\
{\tt 1.ARITHMETIC} corresponding to the {\tt blue-shift 1 (ARIT)} menu\\
{\tt 2.ALGEBRA} corresponding to the {\tt red-shift 4 (ALG)} menu\\
{\tt 3.COMPLEX} corresponding to the {\tt red-shift 1 (CMPLX)} menu\\
{\tt 4.CALCULUS} corresponding to the {\tt blue-shift 4 (CALC)} menu\\
{\tt 5.EXP\&LN} corresponding to the {\tt blue-shift 8 (EXP\&LN)} menu\\
{\tt 6.SYMBOLIC SOLVER} corresponding to the {\tt blue-shift 7 (S.SLV)} menu\\
{\tt 7.MATRICES} corresponding to the {\tt blue-shift 5 (MATRICES)} menu\\
{\tt 8.CONVERT} corresponding to the {\tt blue-shift 6 (CONVERT)} menu\\
{\tt 9.TRIGONOMETRIC} corresponding to the {\tt red-shift 8 (TRIG)} menu\\
Refer to chapter \ref{sec:cas} for more information.
\subsection{The MODE key}
This key allows you to tune the operating mode of your calculator:
{\tt Algebraic} or {\tt RPN} mode, to examine and change the
calculator's {\tt flags} ({\tt F1} key),
to tune the {\tt cas} ({\tt F3} key), and to
change the way your calculator displays data on the screen
with {\tt disp} ({\tt F4} key).\\
For example (see also page \pageref{sec:flag}) the {\tt flag -117}
can be either:\\
{\tt choose boxes} to have the calculator display its menus
using popup windows\\
or\\
{\tt soft menu} to have the calculator display its menus across
the bottom of the screen.\\
\subsection{The TOOL key}
This key displays a menu containing:\\
{\tt edit}, to edit the first line of the history (or the highlighted line).\\
{\tt view}, to view the first line of the history (or the highlighted line).\\
{\tt rcl}, the same as the key sequence
${\tt blue-shift\ STO \triangleright\ (RCL)}$ (see page \pageref{sec:rcl}).\\
{\tt sto $\triangleright$ } the same as the key
${\tt STO \triangleright}$.\\
{\tt purge}, the same as the command {\tt PURGE}
(see page \pageref{sec:purge}).\\
{\tt clear}, to delete the current command line, leaving the cursor
at the beginning of the line
(this isn't the same as {\tt CANCEL} that kills the current command line!).\\
Beware, when the command line is not active, {\tt clear} deletes the
whole history; in this case, it is the same as
${\tt red-shift\ \leftarrow (CLEAR)}$.
\subsection{The UNDO key (red-shift HIST)}
This key is very useful, because it undoes the last command executed.
\subsection{The VAR key}
This key displays, across the bottom of the screen, a menu
containing the names of all variables in the current directory
(press {\tt NXT} to view them all!).\\
See section \ref{sec:var} for more information.
\subsection{The EQW key}
This key invokes the equation editor.\\
It can always be used, even in the matrix editor.\\
Also, from the equation editor it is possible to access the history
(see \ref{sec:hist}).
For more information, see section \ref{sec:eqw}.
\subsection{The MTRW key (blue-shift EQW)}
This key invokes the matrix editor, to enter a matrix.
If you want to enter a vector instead, make sure that the {\tt vect}
menu option is selected.\\
To enter a matrix:\\
you enter the first line, then you move the cursor to the beginning
of the next line; when you finish entering the following lines, the cursor
automatically wraps around.\\
See section \ref{sec:mtrw} for more details.
\subsection{The SYMB key}
This key opens a menu containing the most basic symbolic functions,
divided by category.\\
The sub-menus contain the {\tt cas} functions an high-school student
usually needs. These functions, and many others,
can be found in the corresponding {\tt cas} menus, too.\\
Example:\\
The {\tt SYMBOLIC ARITH MENU} is a portion of the {\tt INTEGER} sub-menu
of {\tt ARITH (blue-shift 1)}.
\subsection{The MTH (blue-shift SYMB) key}
This key opens the mathematics functions menu.\\
There are:\\
The hyperbolic functions (sub-menu 4), like:\\
{\tt SINH ASINH COSH ACOSH TANH ATANH}\\
The functions:\\
{\tt EXPM(X)=EXP(X)-1 LNP1(X)=LN(X+1)}\\
and some functions used on real numbers (sub-menu 5), like:\\
{\tt FLOOR(X)}, returning the largest integral value not grater than {\tt X}.\\
{\tt CEIL(X)}, returning the smallest integral value not less than {\tt X}.\\
{\tt RND(X,n)}, that rounds {\tt X} to {\tt n} decimal digits.\\
{\tt TRNC(X,n)}, that truncates {\tt X} to {\tt n} decimal digits.
\subsection{The UNITS (red-shift 6) key}
The {\tt UNITS } menu has 127 measurement units, divided by category.\\
To use a measurement unit, you must write the unit preceded by
{\tt \_} ({\tt red-shift -}).\\
You can convert from one measurement unit to another using the
{\tt CONVERT} function
(you can find it into the {\tt Tools} sub-menu of the {\tt UNITS} menu).\\
Example:\\
Enter:\\
{\tt CONVERT(12\_cm,1\_m)}\\
The result is:\\
{\tt 0.12\_m}
\subsection{The HIST key}\label{sec:hist}
This key allows you to access the history while you are typing a
command. The same key allows also to access the history from inside
either the equation editor, or the matrix editor.\\
It is important to know that the object copied from the history is
both copied AND evaluated.\\
If you want to use a result again without reevaluating it,
you must use:\\
{\tt ANS(1)} or {\tt ANS(2)}...({\tt red-shift ENTER (ANS(1)}).\\
If you want to reuse a command, you can also press {\tt blue-shift
HIST (CMD)}; this key gives you a list containing the last commmands
you used.
\section{Data entry}
\subsection{The equation editor}\label{sec:eqw}
\subsubsection{Entering the equation writer}
The {\tt EQW} key (EQuationWriter) allows you to enter
the equation editor at any time, from the command line.
It is a very efficient editor useful to write, simplify and work on
mathematical expressions.
While you are in the equation editor you can type expressions in,
knowing that any operator you type always operates either on the
expression next to the cursor, on on the selected expression.
You must not be worried about entering parentheses, you
simply select!\\
You must imagine that mathematical expressions are like a tree,
(not necessarily a binary one), and understand that the four arrow
keys allow you to visit the tree in a natural way
(the right and left keys allow you to go from a sub-tree to another,
the up and down keys allow you to go up and down in the tree hierarchy,
the ``shifted'' right and left keys allow you to accomplish
various selections; see the second example on page \pageref{sec:exemple2}).
\subsubsection{How to select?}
You can enter selection mode in two ways:
\begin{itemize}
\item
The $\triangle$ key enters selection mode and selects the
expression element next to the cursor.\\
Then, you can enlarge the selection to the sub-tree located immediately
to the right of your present selection, by pressing $\rhd$.
\item
The $\rhd$ key enters selection mode and selects the sub-tree
next to the cursor.
\item
Warning: if you are entering a function with more than one argument,
(like, for example, $\sum$, $\int$ or {\tt AND}),
the $\rhd$ arrow allows you go from one argument to another.
Therefore, you must always use the $\triangle$ key to start
selection mode in this case (see \ref{sec:sum}).
\end{itemize}
Equation writer examples:
\begin{itemize}
\item Example 1\\
Type: $${\tt 2\ +\ X\ *\ 3 \ -\ X }$$
You obtain:
$${\tt 2+X \cdot 3-X}$$
{\tt ENTER} {\tt ENTER} gives the following result:
$${\tt 2+2 \cdot X}$$
Type: $${\tt 2\ +\ X \ \rhd\ * \ 3 \ -\ X}$$
You obtain:
$${\tt (2+X) \cdot 3-X}$$
{\tt ENTER} {\tt ENTER} gives the following result:
$${\tt 6+2 \cdot X}$$
Type:
$${\tt 2\ +\ X\ \rhd\ *\ 3\ \triangle\ -\ X }$$
You obtain:
$${\tt (2+X) \cdot (3-X)}$$
{\tt ENTER} {\tt ENTER} gives the following result:
$${\tt-(X^2-X-6)}$$
\item Example 2 \label{sec:exemple2}\\
If you want to enter:
$${\tt X^2-3 \cdot X+1}$$
You type:
$${\tt X \ y^x \ 2 \ \rhd \ - \ 3 \ X \ + \ 1 }$$
\item Example 3\\ %\label{sec:exemple3}
You want to enter:
$$\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}$$
Here, the root of the tree is a $+$, and there are four sub-trees;
each sub-tree has a $\div$ as root, and has two leaves.
First of all, you must press {\tt EQW}, and then you enter the
first sub-tree:
$${\tt1 \div 2} $$
Then, you select this sub-tree with $$ \rhd$$
press $$+$$ and enter the second sub-tree:
$${\tt 1 \div 3}$$
Then, you select this sub-tree with $$ \rhd$$
press $$+$$ and enter the third sub-tree:
$${\tt 1 \div 4}$$
Then, you select this sub-tree with $$ \rhd$$
press $$+$$ and enter the fourth sub-tree:
$${\tt 1 \div 5}$$
Last, press $$ \rhd$$ again to select the last sub-tree you entered.
Now, the expression you want:
$${\tt \frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}}$$
has been entered into the equation writer, and ${\tt \frac{1}{5}}$
is selected.
Visit the tree to select:
$${\tt\frac{1}{3}+\frac{1}{4}}$$
You must press $$ \lhd$$ to select ${\tt \frac{1}{4}}$;
next, $${\tt red-shift \lhd}$$ allows you to extend the selection
to two contiguous sub-trees, in this example:
$${\tt \frac{1}{3}+\frac{1}{4}}$$
Notice that:
You can evaluate the selected portion of the expression with:
$${\tt red-shift \ SYMB\ (EVAL)}$$
You obtain:
$${\tt \frac{1}{2}+\frac{7}{12}+\frac{1}{5}}$$
Now, if you want to evaluate $$\frac{1}{2}+\frac{1}{5}$$
first of all you must do a permutation in order to make
${\tt \frac{1}{2}}$ and ${\tt \frac{1}{5}}$ adjacent,
pressing
$${\tt blue-shift \lhd} $$
thus exchanging the selected element with his left neighbor.
You obtain:
$${\tt \frac{7}{12}+\frac{1}{2}+\frac{1}{5}}$$
and ${\tt \frac{7}{12}}$ is selected. Then,
$${\tt \rhd red-shift \rhd}$$
selects $${\tt \frac{1}{2}+\frac{1}{5}}$$
You can now do {\tt EVAL} again.
\end{itemize}
\subsubsection{How to modify an expression}
To replace the selection with another expression, you can
directly type the new expression. \\
To remove a selection without deleting the selected expression,
press:
$${\tt \Leftarrow}$$
To delete the selected expression, press:
$${\tt red-shift\ \Leftarrow \ \ (CLEAR)}$$
To delete the unary operator at the root of the selected sub-tree,
press:
$${\tt blue-shift\ \Leftarrow \ \ (DEL)} $$
For example, to replace $\sin(expr)$ with $\cos(expr)$,
you delete $\sin$ (selecting $\sin(expr)$ and pressing
${\tt blue-shift\ \Leftarrow} $), then you enter:
$\cos$.\\
To delete a binary operatoy, you must use the {\tt edit} menu option,
make the correction in the command-line editor, and return to
the equation writer with {\tt ENTER}.\\
The {\tt HIST} key (when used inside the equation editor) allows you
to enter the history and to copy a history element into the equation
writer with the {\tt echo} menu option.
\subsubsection{How to enter {\tt AND}, $\int$ and $\sum$} \label{sec:sum}
To enter {\tt AND}, you type it in {\tt alpha} mode and you press $\rhd$.
To enter the $\int$ symbol, you press:
$${\tt red-shift\ TAN \ (\int) }$$
To enter the $\sum$ symbol, you press:
$${\tt red-shift\ SIN \ (\sum) }$$
The cursor automatically moves where input is required, and you
can move it using $${\tt \rhd}$$
The expressions you enter follow the selection rules explained above,
but you must use $\triangle$ to enter selection mode.
Warning: do not use the index variable $i$ in summations, because
$i$ denotes the complex number that solves the equation $x^2+1=0$.
You must also understand that
$\sum $ is able to calculate symbolically the
summations of rational fractions, and the hypergeometric series
admitting a discrete primitive (starting from ROM version 1.11).\\
In numeric mode, $\sum $ performs approximate calculations
(for example, $\sum_{k=0}^4 \frac{1}{k!}=2.70833333334$, instead of
$1+\frac{1}{1!}+\frac{1}{2!}+\frac{1}{3!}+\frac{1}{4!}=\frac{65}{24}$)
(the $!$ symbol can be typed in pressing ${\tt alpha\ red-shift\ 2}$).
\subsubsection{Cursor mode}
Cursor mode allows you to select a big expression fast:\\
press {\tt red-shift EQW (')} to enter cursor mode
(or press on the {\tt curs} menu option). Next,
use the arrows to enclose your selection in a box and press
{\tt ENTER} to select the box contents, or {\tt CANCEL}
to cancel the operation.
\subsubsection{To view all}
Pressing on the {\tt big} menu option, you make the font
used to display the expression either bigger or smaller:
sometimes, making the font smaller
allows you to view a big expression as a whole on the screen.\\
If this is not yet enough, select the {\tt view} option of the
{\tt TOOL} menu.
\subsection{The matrix writer}\label{sec:mtrw}
To invoke the matrix writer, press: {\tt blue-shift EQW (MTRW)}.\\
You can then enter the elements belonging to the first line
of the matrix by pressing
{\tt ENTER} after each entry (you can use the equation editor
to write them, too!). Next, you move the cursor to the
beginning of the second line with the arrow keys (the cursor
automatically wraps around when you finish entering the following lines).\\
To enter a negative number, for example $-2$, enter $^+/_-\ 2$.\\
If you want to enter a vector, make sure that the
{\tt vect} menu option is selected.\\
Notice that in {\tt Algebraic} mode you must enter the matrix
elements one at a time (pressing {\tt ENTER} after each element),
but in {\tt RPN} mode you can write more than one element separating
them with spaces; pressing {\tt ENTER} then enters them all.
\subsection{The text editor}
This is the line that opens under the history to type a command in.\\
It is a full-fledged text editor, where you can:
select an expression (with {\tt BEGIN END}), either cut it ({\tt CUT})
or copy it ({\tt COPY}) into a buffer, and then paste it at the
current cursor position ({\tt PASTE}).\\
Notice also that these commands work in {\tt EQW} and
{\tt MTRW}, too.
\subsubsection{\tt BEGIN END}
Move the cursor on the first character of the text you want
to select, then press:
{\tt red-shift APPS (BEGIN)}.\\
Then, move the cursor on the character that follows the last character
to select, and press:
\\ {\tt red-shift MODE (END)}.\\
Your selection will be highlighted.
\subsubsection{\tt COPY}\index{COPY}
{\tt red-shift VAR (COPY)} copies the selection into a buffer.
\subsubsection{\tt CUT}\index{CUT}
{\tt red-shift STO (CUT)} copies the selection into a buffer,
and deletes it from the command line.
\subsubsection{\tt PASTE}\index{PASTE}
{\tt red-shift NXT (PASTE)} pastes the contents of the buffer
at the current cursor position (you must have previously done
either {\tt COPY}, or {\tt CUT}, to put something into the buffer).
\subsection{Variables}\label{sec:var}
You can store objects into variables, and reference them using
the variable name.\\
Be sure to notice the difference between {\tt A} et {\tt 'A'} :\\
{\tt A} is evaluated (it denotes the execution of variable contents),
while {\tt 'A'} is not (it denotes the variable name).\\
For example:\\
{\tt STO(B,'A')}: stores the contents of {\tt B} into {\tt A}.\\
{\tt STO('B','A')}: means that {\tt B} and {\tt A} will have
the same contents from now on.\\
{\tt VAR} displays a menu listing all variables you have created
in the current directory, as well as all its subdirectories (you can
distinguish variables from subdirectories because subdirectories
have a small bar across the upper-left corner of their menu item).
The {\tt blue-shift APPS (FILES)} application displays
the whole variable tree starting from {\tt HOME}, as well as
the archive memory, and greatly simplifies variable management.
\subsubsection{\tt STO}\index{STO}
{\tt STO} allows you to create a variable and to store an object
into it.\\
{\sc Warning}: {\tt STO} is prefixed if you type it in alpha mode,
and is infixed if you use the {\tt STO} key.
(from now on, this key will be denoted by either
${\tt STO\triangleright}$ or ${\tt \triangleright}$).\\
Examples:\\
Type:\\
{\tt STO(1,'A')}\\
or\\
use the ${\tt STO\triangleright}$ key, displayed on screen with
${\tt \triangleright}$ :\\
to enter:\\
${\tt 1\ STO\triangleright\ A}$ (${\tt 1\ \triangleright\ A}$).\\
Notice that, in the latter case, you don't put {\tt ' '} around
{\tt A}.\\
The variable {\tt A} is created, and it contains 1.\\
Enter:\\
${\tt \ll 12 \gg\ STO\triangleright\ P}$\\
{\tt P} is a varialbe containing the program ${\tt \ll 12 \gg\ }$, that
displays {\tt 12}.\\
\subsubsection{\tt RCL}\index{RCL}\label{sec:rcl}
{\tt RCL} takes a variable name, surrounded by {\tt ' }, as argument,
and displays the variable contents.\\
To recall the contents of a variable, entering the variable name
is enough, {\sc unless} the variable contains a program (because,
in the latter case, the program is executed).\\
In the last examples:\\
{\tt A} displays 1 and {\tt P} displays 12 \\
but:\\
{\tt RCL('A')} displays 1 and {\tt RCL('P')} displays ${\tt \ll 12 \gg\ }$.
\subsubsection{\tt PURGE}\index{PURGE}\label{sec:purge}
{\tt PURGE} allows you to delete a variable and its contents.\\
You can find {\tt PURGE} in the {\tt TOOL} menu.\\
Example:\\
{\tt PURGE('A')}
\subsubsection{Predefined variables}
The name of the current symbolic variable is stored in {\tt VX}
(and it will usually be {\tt X}), therefore you should either not
use {\tt X} as an ordinary variable, or purge {\tt X}
before doing symbolic calculations.\\
{\tt EPS} holds the value of epsilon used by the
{\tt EPSX0} command (see \ref{sec:epsx0}).\\
{\tt EQ} holds the last equation you plotted.\\
{\tt MATRIX} holds the last matrix used as argument to
either {\tt JORDAN, EGV} or {\tt EGVL}.\\
{\tt MODULO} holds the value of $p$ when you do symbolic calculations in
the $Z/p.Z$ ring.\\
{\tt PERIOD} holds the period of the function of which you
want to calculate the Fourier coefficients
(see \ref{sec:fourier}).\\
{\tt PRIMIT} holds the antiderivative of the last function you
asked the calculator to integrate.\\
{\tt REALASSUME} holds the names of the symbolic variables
you want the calculator assume to be reals
(by default, {\tt X, t} and all auxiliary integration variables used).\\
{\tt SYSTEM} holds the last system of equations used as argument to
either {\tt rref} or {\tt RREF}, if the system has at least a parameter.\\
\subsection{Directories}\label{sec:rep}
At the beginning, you only have the {\tt HOME} directory; it is the
ancestor of any other directory you will create in the future.
\subsubsection{Creating a directory}
Press {\tt blue-shift APPS (FILES)} to display the tree structure of
your directories.\\
Select the directory you want to be the parent directory
(for example {\tt HOME}) and press {\tt ok}.\\
A menu containing {\tt edit copy move...} is displayed;
press {\tt NXT} and select {\tt new} (new variable or directory )
with {\tt F3}.\\
Do not fill the {\tt Object} field, but fill {\tt Name} instead
(to do this, simply type the name you chose, and then press {\tt ok}
of the menu.\\
Then, select {\tt Directory} with {\tt F3 (chk)}, and press {\tt ok}
of the menu.\\
Last, press {\tt CANCEL} to return in {\tt HOME}.\\
Check, by pressing {\tt VAR}, that your directory has actually been created.\\
You can also create a directory with the {\tt CRDIR} command.\\
You make the parent directory current, and then type:\\
{\tt CRDIR('NOMREP')}\\
to create a subdirectory named {\tt NOMREP}.
\subsubsection{Working in a directory}
Working in a directory is simple: simply press
{\tt VAR} to display the subdirectory names in the menu area,
and then open the subdirectory you want by pressing on the
{\tt Fi} corresponding to its name, followed by {\tt ENTER}.\\
To climb up in the directory tree, press:\\
{\tt blue-shift VAR (UPDIR)}
\subsubsection{Deleting, renaming, moving a directory}
Press {\tt blue-shift APPS (FILES)} to display your directory tree.\\
Select the directory you want to delete, rename, move, and
press the {\tt ok} menu key.\\
A menu containing
{\tt edit copy move...purge rename...} is displayed.\\
{\tt purge} deletes the directory, if it is empty.
{\tt rename } gives the directory a new name.
{\tt copy} copies the directory (the arrow keys are used to
indicate the destination, and {\tt ok} confirms).
{\tt move} moves the directory (the arrow keys are used to
indicate the destination, and {\tt ok} confirms).
\section{Plotting graphs}\label{sec:graph}
\subsection{Plot windows}
\subsubsection{Equation entry}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F1 (Y=)}.
It allows you to define the equation to be plotted.
\subsubsection{Plot window}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F2 (WIN)}.\\
It allows you to define the plot window and to enter the lower and
upper boundaries of the independent plot variable.\\
If boundaries are set to {\tt Default}, they are assumed to
be equal to the horizontal size of the plot window.\\
To reset a parameter to {\tt Default}, you must press {\tt NXT},
and then press the {\tt reset} menu key.
\subsubsection{Graph display}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F3 (GRAPH)}.\\
It allows you to draw the plot when you have set all its parameters.
\subsubsection{Plot setup}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F4 (2D/3D)}.\\
It allows you to choose the plot type, the equation to be plotted
and the plot variables.
\subsubsection{Table setup}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F5 (TBLSET)}.\\
It allows you to initialize a table.
\subsubsection{Table display}
This window is activated with the following sequence of keys:\\
{\tt blue-shift F6 (TABLE)}.\\
It displays the table you initialized with
{\tt TBLSET}.
\subsection{Plot setup}
\subsubsection{Plot type}
You can select the plot type using the {\tt choos} menu key of the
{\tt PLOT SETUP (blue-shift F4 (2D/3D))} window.\\
Here, the most common plot types will be described, such as:\\
{\tt Function} to plot a function in cartesian coordinates.\\
{\tt Polar} to plot a function in polar coordinates.\\
{\tt Parametric} to plot a parametric function.\\
{\tt Truth} to plot the solutions of an equation
(the pixel at (x,y) is turned on
iff {\tt EQ} is true).
{\tt Diff Eq} to plot the solutions of the differential equation
$y'=f(x,y)$.\\
You can plot the solution satisfying $y(x_0)=y_0$ on the
interval [$a,b$].\\
To do this, put in {\tt H-View} the values of $a$ and $b$, then $x_0$
into {\tt Init} and $y_0$ into {\tt Init-Soln}.\\
The solution is plotted in two steps:
first, set {\tt Final} to $b$ to plot the solution on [$x_0,=b$],
draw the plot,
then set {\tt Final} to $a$ to plot the solution on [$a,x_0$]
and draw the plot again.\\
{\tt Slopefield} to draw the slope field of the differential equation
$y'=f(x,y)$.\\
{\tt Fast3D} to plot a surface defined by
$z=f(x,y)$.\\
The plot can be rotated using {\tt NXT}, {\tt TOOL} and the arrow
$\triangle\ \lhd \ \rhd \ \bigtriangledown $ keys, to have a good view
of the surface.
\subsubsection{The equation}
You can enter the equation in many ways:\\
-you can store it into the {\tt EQ} variable.\\
-you can enter it in the window opened by {\tt blue-shift F1 (Y=)}.\\
-you can enter it in the {\tt EQ} field of the {\tt PLOT SETUP}
window, opened by {\tt blue-shift F4 (2D/3D)}.\\
-you can also use the {\tt cas} function {\tt PLOT}\index{PLOT}.
It has a functions as argument, stores it into
{\tt EQ} and opens the {\tt PLOT SETUP} window.\\
Notice that {\tt EQ} can be a list of equations;
in this case, all of them will be plotted on the same graphic.\\
You can also add en equation to the list of equations stored
in {\tt EQ}, with the aid of the {\tt cas} function
{\tt PLOTADD}\index{PLOTADD}.
\subsubsection{Independent variable and equation types}
The equation type depends on the plot type you have selected
and on the independent variable you chose.\\
Depending on this, you enter an equation of type:\\
${\tt f(x)}$ to plot $y=f(x)$ in cartesian coordinates,
if ${\tt x}$ is the independent variable and the plot type is
{\tt Function}.\\
${\tt f(t)}$ to plot $r=f(t)$ in polar coordinates,
if ${\tt t}$ is the independent variable and the plot type is
{\tt Polar}.\\
${\tt x(t)+i.y(t)}$ to plot $(x=x(t),y=y(t))$ in parametric
coordinates, if ${\tt t}$ is the independent variable and
the plot type is
{\tt Parametric}.\\
${\tt f(x,y)>0}$ to highlight the corresponding portion of the
$x,y$ plane, if
${\tt x}$ and ${\tt y}$ are the independent variables
and the plot type is {\tt Truth}.\\
${\tt f(t,y)}$ to plot the solutions of the differential equation
$y'=f(t,y)$ if ${\tt t}$ is the independent variable,
${\tt y}$ is the solution variable and the plot type
is {\tt Diff Eq}.\\
${\tt f(t,y)}$ to plot the slope field
of the differential equation
$y'=f(t,y)$, if ${\tt t}$ is the independent variable,
${\tt y}$ is the solution variable and the plot type
is {\tt Slopefield}.\\
${\tt f(x,y)}$ to plot the surface defined by
$z=f(x,y)$ if
${\tt x}$ and ${\tt y}$ are the independent variables
and the plot type is
{\tt Fast3D}.\\
Sometimes, the name of the second independent variable can
be changed; by default its name is ${\tt y}$. This name
is always tagged by {\tt Depend}, even if it does
correspond to an independent variable! Do not take
the word {\tt Depend} into account in this case.
\subsection{Drawing the plot}
Before drawing a plot, you must set up many parameters.\\
When you have set all parameters up, to draw a plot
press on:\\
{\tt erase draw} (if tou want to erase the last plot you made) or\\
{\tt draw} (if you want yo keep the last plot you made). \\
Using the menu of one of the following windows:\\
{\tt PLOT SETUP (blue-shift F4 (2D/3D))} \\
{\tt PLOT (blue-shift F1 (Y=3D))} \\
{\tt PLOT WINDOW (blue-shift F2 (WIN))}.\\
You can also press:\\
{\tt blue-shift F3 (GRAPH)} to draw the new plot
without erasing the previous one.\\
You can review the last plot you made by pressing on
${\tt \lhd}$.
\section{Symbolic calculations}\label{sec:cas}
\subsection{Integers (and Gauss integers)}
In this chapter, all integers can be freely replaced by
Gauss integers, as an argument for all functions described here.\\
\subsubsection{Infinite-precision integers}
The calculator can handle infinite-precision integers, for example:
$$100!$$
\indent The symbol \ $!$ \ can be obtained either pressing
${\tt alpha\ red-shift\ 2}$,
or using {\tt red-shift CAT (CHARS)}.
In the latter case, you select
\ $!$ \ in {\tt CHARS} (with the arrow keys),
and then copy it into the command line using
the {\tt echo1} menu key.
Since the decimal representation of
$100!$ is very long, you can view the result using the
{\tt TOOL} key, followed by the {\tt view } menu key.\\
The {\tt HIST} and the up arrow keys allow you to climb up through the
history, and the {\tt view } menu key allows you to review previous
results.
\subsubsection{\tt DEFINE}\index{DEFINE}
Consider the following exercise:\\
Calculate the first six Fermat numbers
$F_k=2^{2^k}+1$ for $k=1..6$, and check whether they are prime.
Type the expression:
$$2^{2^2}+1$$
to find 17, then invoke the
{\tt ISPRIME?()}\index{ISPRIME?} command with {\tt ANS(1)}
as argument.
You can find this command in the
{\tt ARITH (blue-shift 1)} menu, sub-menu
{\tt 1 INTEGER} (or you can type it in $\alpha$ mode).
The answer is {\tt 1.}, meaning {\tt true}.
With the aid of the history,
({\tt HIST}) you can copy the expression
$2^{2^2}+1$
into the command line, and modify it to read as:
$$2^{2^3}+1$$
Otherwise, you can type the expression
{\tt $2^{2^K}+1$ STO FK}, then do {\tt 3 STO K}, and so on...\\
Otherwise, and it is the better choice,
you can define the function
{\tt F(K)} with the aid of
{\tt DEF (blue-shift 2)}, entering:
$${\tt DEFINE(F(K)=2^{2^K}+1)}$$
The result is
{\tt NOVAL} and {\tt F} is added to the variables
(press on {\tt VAR} to check this). \\
For $K=5$ you enter:
$${\tt F(5)}$$
obtaining:
$$4294967297$$
You can factorize $F_5 $ with {\tt FACTOR }; you find it
in the
{\tt ALG (red-shift 4)} menu.\\
Type:
$${\tt FACTOR( F(5))}$$
You obtain: $$641 \cdot 6700417$$
For ${\tt F(6)}$ you find:
$$18446744073709551617$$
Factorizing the result with {\tt FACTOR}, the result is:
$$274177 \cdot 67280421310721$$
Notice the difference in notation between:
$$2.5 =\frac{5}{2}$$
and $$2 \cdot 5=10$$
\subsubsection{\tt GCD}\index{GCD}
{\tt GCD} denotes the greatest common divisor of two integers
(or of two lists of integers with the same size).\\
Enter:
$${\tt GCD(18,15) }$$
You obtain:
$${\tt 3}$$
Enter:
$${\tt GCD(\{18,28\},\{15,21\}) }$$
You obtain:
$${\tt \{3,7\}}$$
because ${\tt GCD(18,15)=3 }$ and ${\tt GCD(28,21)=7 }$.
\subsubsection{\tt LGCD}\index{LGCD}
{\tt LGCD} denotes the greatest common divisor of a
list of integers.\\
Enter:
$${\tt LGCD(\{18,15,21,36\}) }$$
You obtain:
$${\tt 3}$$
\subsubsection{\tt SIMP2}\index{SIMP2} \label{sec:simp2}
{\tt SIMP2} has two integers as arguments (or two lists of integers).
These integers are assumed to represent a fraction: the first
element of the list is the fraction's numerator, the second is
the denominator.
{\tt SIMP2} returns a list of two integers representing, under
the same assumptions, the input fraction simplified.\\
Enter:
$${\tt SIMP2(18,15) }$$
You obtain:
$${\tt \{6,5\}}$$
Enter:
$${\tt SIMP2(\{18,28\},\{15,21\}) }$$
You obtain:
$${\tt \{6,5,4,3\}}$$
\subsubsection{\tt LCM}\index{LCM}
{\tt LCM} denotes the least common multiple of two integers
(or of two lists of integers).\\
Enter:
$${\tt LCM(18,15) }$$
You obtain:
$${\tt 90}$$
\subsubsection{\tt FACTOR }\index{FACTOR}
{\tt FACTOR} factorizes its argument into a product
of prime factors.\\
Enter:
$${\tt FACTOR(90) }$$
You obtain:
$${\tt 2.3^2.5}$$
\subsubsection{\tt FACTORS }\index{FACTORS}
{\tt FACTORS} does the same, but the result is given as
a list, containing the prime factors and their exponents.\\
Type:
$${\tt FACTORS(90) }$$
You obtain:
$${\tt \{2,1.,3,2.,5,1.\} }$$
\subsubsection{\tt DIVIS} \index{DIVIS}
{\tt DIVIS} returns a list containing all divisors of a given integer.\\
Type:
$${\tt DIVIS(36) }$$
You obtain:
$${\tt \{1,3,9,2,6,18,4,12,36 \} }$$
\subsubsection{\tt IQUOT}\index{IQUOT}
{\tt IQUOT} returns the integer quotient of the euclidean division
of two integers.\\
Type:
$${\tt IQUOT(148,5) }$$
You obtain:
$${\tt 29}$$
\subsubsection{\tt IREMAINDER\protect\index{IREMAINDER} MOD\protect\index{MOD}}
{\tt IREMAINDER} returns the integer remainder of the euclidean
division of two integers.\\
You type:
$${\tt IREMAINDER(148,5) }$$
or
$${\tt 148\ MOD\ 5 }$$
You obtain:
$${\tt 3}$$
The difference between {\tt IREMAINDER} and {\tt MOD} is that
the former works with both integers and Gauss integers.\\
Try:
$${\tt IREMAINDER(148!,5!+2 )}$$
(you obtain $!$ with {\tt alpha red-shift 2}).
\subsubsection{\tt IDIV2}\index{IDIV2}
{\tt IDIV2} returns a list containing the quotient and the remainder
of the euclidean division between two integers, in that order.\\
Type:
$${\tt IDIV2(148,5) }$$
You obtain:
$${\tt \{29,3\} }$$
In step-by-step mode, the calculator shows the division process
like it is taught at school.
\subsubsection{\tt ISPRIME?}\index{ISPRIME?}
{\tt ISPRIME?(N)} returns {\tt 1.} (true) if {\tt N} is pseudo-prime,
and returns {\tt 0.} (false) if {\tt N} is not prime.\\
Definition: For all integers less than $10^{14}$ pseudo-primality
and primality are the same! ...beyond $10^{14}$ a pseudo-prime
integer has a very high probability to be prime
(see the Rabin algorithm in section \ref{sec:rabin}).\\
Type:
$${\tt ISPRIME?(13) }$$
You obtain:$${\tt 1.}$$
Type:
$${\tt ISPRIME?(14) }$$
You obtain:
$${\tt 0.}$$
\subsubsection{\tt NEXTPRIME}\index{NEXTPRIME}
{\tt NEXTPRIME(N)} returns the smallest pseudo-prime number
greater than ${\tt N}$.\\
Type:
$${\tt NEXTPRIME(75) }$$
You obtain:
$${\tt 79}$$
\subsubsection{\tt PREVPRIME}\index{PREVPRIME}
{\tt PREVPRIME(N)} returns the largest pseudo-prime number
less than ${\tt N}$.\\
Type:
$${\tt PREVPRIME(75)}$$
You obtain:
$${\tt 73}$$
\subsubsection{\tt IEGCD}\index{IEGCD}
{\tt IEGCD(A,B)} returns the extended GCD
(B\'ezout identity) of two integers, that is,
{\tt IEGCD(A,B)} returns {\tt \{D,U,V\}} so that {\tt AU+BV=D} and
{\tt D=GCD(A,B)}.\\
Type:
$${\tt IEGCD(48,30) }$$
You obtain:
$${\tt \{6,2,-3\}}$$
In fact:
$$2 \cdot 48+ (-3) \cdot 30 = 6$$
\subsubsection{\tt IABCUV}\index{IABCUV}
{\tt IABCUV(A,B,C)} returns {\tt \{U ,V\}} so that {\tt AU+BV=C}.\\
{\tt C} must be a multiple of {\tt GCD(A,B)} for a solution to exist.\\
Type:
$${\tt IABCUV(48,30,18) }$$
You obtain:
$${\tt \{6,-9\}}$$
\subsubsection{\tt ICHINREM}\index{ICHINREM}
{\tt ICHINREM([A,P],[B,Q])} returns a vector {\tt [X, N]} so that:\\
{\tt X=A (mod P)} and {\tt X=B (mod Q)}.\\
The solution {\tt X} exists if {\tt P} and {\tt Q} are mutually prime,
and all solutions are congruent modulo ${\tt N=P \cdot Q}$\\
Example: \\
Solve:
$${\tt \left
\{ \begin{array}{rl} X=&3\ (\bmod\ 5)\\ X=&9\ (\bmod\ 13)\end{array}
\right.}$$
Type:
$${\tt ICHINREM([3,5],[9,13])}$$
You obtain:
$${\tt [-147,65] }$$
that is, {\tt X=-147 (mod 65)}
\subsubsection{\tt PA2B2}\index{PA2B2}
{\tt PA2B2} decomposes a prime integer $p$,
congruent to 1 modulo 4, as follows:
$p=a^2+b^2$. The calculator returns the result as $a+b \cdot i$\\
Type:
$${\tt PA2B2(17)}$$
You obtain:
$${\tt 4+i }$$
that is, $17=4^2+1^2$
\subsubsection{\tt EULER}\index{EULER}
{\tt EULER} denotes the Euler's totient function of an integer.\\
EULER(n) is the number of integers less than
$n$ and prime with $n$.\\
Type:
$${\tt EULER(21)}$$
you obtain:
$${\tt 12}$$
In fact, the set:\\
E=\{2,4,5,7,8,10,11,13,15,16,17,19\} is the set of integers less
than 21 and prime with 21, and it has 12 elements.
\subsection{Rationals}
Type:
$$\frac{123}{12}+\frac{57}{21}$$
and then {\tt ENTER}; the answer is:
$$\frac{363}{28}$$
with {\tt red-shift ENTER ($\rightarrow$NUM)} the answer is:
$$12.9642857143$$
If you mix both representations, for example:
$$\frac{1}{2}+0.5$$
the calculator demands to enable {\tt approx} mode to carry out the
calculation; you should answer {\tt yes} to obtain:
$$1.$$
Now, return to exact mode
({\tt MODE cas} menu keys, and so on...).
\subsubsection{\tt PROPFRAC}\index{PROPFRAC}
${\tt PROPFRAC(A / B)}$ rewrites the fraction $\frac{A}{B}$ as:
$$Q+\frac{R}{B}\ \ with \ \ 0\leq R**2$, the limit when $x$ approaches 0 of:
$$ \frac{n\times \tan(x)-\tan(n\times x)}{\sin(n\times x)-n\times \sin(x)}$$
You can use the {\tt LIMIT} command, found in the menu:\\
{\tt CALC (blue-shift 4)}, sub-menu 2 {\tt LIMIT \& SERIES}
(or you can type it in $\alpha$ mode).\\
Type:
$${\tt LIMIT \left( \frac{N \cdot TAN(X)-TAN(N \cdot X)}{SIN(N \cdot X)-N
\cdot SIN(X)}, 0 \right)}$$
You obtain:
$${\tt 2 }$$
Find the limit, when $x$ approaches $+\infty$, of:
$$\sqrt{x+\sqrt{x+\sqrt x}}-\sqrt x$$
Type:
$${\tt LIMIT (\sqrt{X+\sqrt{X+\sqrt{X}}}-\sqrt{X}, +\infty)} $$
After a moment, you obtain:
$$\frac{1}{2}$$
Notice that you obtain ${\tt {+\infty}}$ pressing:
$${\tt { \ ^+/_- \ \ ^+/_- \; \; \infty}\ (blue-shift\ 0)\ }$$
\subsubsection{\tt LIMIT\protect\index{LIMIT} and $\int$}
Find the limit, when $a$ approaches $+\infty$, of:
$$ \int _2^a (\frac {x}{x^2-1}+\ln(\frac {x+1}{x-1}))\ dx$$
In the {\tt equation writer}, type:
$${\tt \int _2^{+\infty} (\frac {X}{X^2-1}+LN(\frac {X+1}{X-1}))\ dX} $$
Notice that tou obtain ${\tt {+\infty}}$ pressing:
$${\tt { \ ^+/_- \ \ ^+/_- \; \; \infty}\ (blue-shift\ 0)\ }$$
You obtain:
$${\tt +\infty-\frac{7.LN(3)}{2} }$$
and, after simplification:
$$+\infty$$
\subsubsection{\tt IBP}\index{IBP}
{\tt IBP} has two arguments: an expression you can write as $u(x) \cdot v'(x)$
and $v(x)$.\\
{\tt IBP} returns a list containing $u(x) \cdot v(x)$ and $-v(x) \cdot u'(x)$,
that is, the two terms you must calculate when doing an
integration by parts.\\
You must then integrate the second term and add the result
to the first term to obtain an antiderivative of $u(x) \cdot v'(x)$
(this is handy in {\tt RPN} mode!).\\
Type:
$${\tt IBP(LN(X),X) }$$
You obtain:
$${\tt \{X.LN(X),-1\}}$$
Notice: If the first argument of {\tt IBP} is a list of two elements,
{\tt IBP} only operates on the last element of the list, and adds the
integration result to the first element
(so that it is easy to invoke {\tt IBP} multiple times in
algebraic mode).
\subsubsection{\tt RISCH}\index{RISCH}
{\tt RISCH} has two arguments: an expression and the name of a variable.\\
{\tt RISCH} returns an antiderivative of the first argument with respect
to the variable given as the second argument.\\
Type:
$${\tt RISCH((2 \cdot X^2+1) \cdot EXP(X^2+1),X) }$$
You obtain:
$${\tt X \cdot EXP(X^2+1)}$$
\subsection{Trigonometric expressions}
\subsubsection{\tt TEXPAND}\index{TEXPAND}
{\tt TEXPAND} has a trigonometric expression as argument.\\
{\tt TEXPAND} expands this expression with respect to $\sin(x)$ and
$\cos(x)$.\\
Example 1:\\
Type:\\
$${\tt TEXPAND( COS(X+Y))}$$
You obtain:\\
$${\tt COS(Y) \cdot COS(X)-SIN(Y) \cdot SIN(X)}$$
Example 2:\\
Type:\\
$${\tt TEXPAND( COS(3 \cdot X))}$$
You obtain:\\
$${\tt 4 \cdot {COS(X)}^3-3 \cdot COS(X)}$$
Example 3:\\
Type:\\
$${\tt TEXPAND( \frac{SIN(3 \cdot X)+SIN(7 \cdot X)}{SIN(5 \cdot X)})}$$
You obtain, after one simplification step (${\tt\triangle \ ENTER}$) :\\
$${\tt 4 \cdot {COS(X)}^2-2}$$
\subsubsection{\tt TLIN}\index{TLIN}
{\tt TLIN} has a trigonometric expression as argument.\\
{\tt TLIN} linearizes this expression in function of
$\sin(n \cdot x)$ and $\cos(n \cdot x)$.\\
Example:\\
Type:\\
$${\tt TLIN(COS(X) \cdot COS(Y))}$$
You obtain:\\
$${\tt \frac{1}{2} \cdot COS(X-Y)+\frac{1}{2} \cdot COS(X+Y)}$$
Example 2:\\
Type:\\
$${\tt TLIN({COS(X)}^3)}$$
You obtain:\\
$${\tt \frac{1}{4} \cdot COS(3 \cdot X)+\frac{3}{4} \cdot COS(X)}$$
Example 3:\\
Type:\\
$${\tt TLIN(4 \cdot {COS(X)}^2-2)}$$
You obtain:\\
$${\tt 2 \cdot COS(2 \cdot X)}$$
\subsubsection{\tt TCOLLECT}\index{TCOLLECT}
{\tt TCOLLECT} has a trigonometric expression as argument.\\
{\tt TCOLLECT} linearizes this expression in function of
$\sin(n \cdot x)$ and $\cos(n \cdot x)$, then collects in {\tt real} mode
sines and cosines of the same angle.\\
Type:\\
$${\tt TCOLLECT(SIN(X)+COS(X))}$$
You obtain:\\
$${\tt \sqrt2 \cdot COS(X-\frac{\pi}{4})}$$
\subsubsection{\tt ACOS2S}\index{ACOS2S}
{\tt ACOS2S} has a trigonometric expression as argument.\\
{\tt ACOS2S} rewrites this expression replacing
$\arccos(x)$ with $\frac{\pi}{2}-\arcsin(x)$.\\
Type:\\
$${\tt ACOS2S(ACOS(X)+ASIN(X))}$$
You obtain:\\
$${\tt \frac{\pi}{2}}$$
\subsubsection{\tt ASIN2C}\index{ASIN2C}
{\tt ASIN2C} has a trigonometric expression as argument.\\
{\tt ASIN2C} rewrites this expression replacing
$\arcsin(x)$ with $\frac{\pi}{2}-\arccos(x)$.\\
Type:\\
$${\tt ASIN2C(ACOS(X)+ASIN(X))}$$
You obtain:\\
$${\tt \frac{\pi}{2}}$$
\subsubsection{\tt ASIN2T}\index{ASIN2T}
{\tt ASIN2T} has a trigonometric expression as argument.\\
{\tt ASIN2T} rewrites this expression replacing
$\arcsin(x)$ with $\arctan(\frac{x}{\sqrt{1-x^2}})$.\\
Type:\\
$${\tt ASIN2T(ASIN(X))}$$
You obtain:\\
$${\tt ATAN(\frac{X}{\sqrt{1-X^2}})}$$
\subsubsection{\tt ATAN2S}\index{ATAN2S}
{\tt ATAN2S} has a trigonometric expression as argument.\\
{\tt ATAN2S} rewrites this expression replacing
$\arctan(x)$ with $\arcsin(\frac{x}{\sqrt{1+x^2}})$.\\
Type:\\
$${\tt ATAN2S(ATAN(X))}$$
You obtain:\\
$${\tt ASIN(\frac{X}{\sqrt{X^2+1}})}$$
\subsubsection{\tt SINCOS\protect\index{SINCOS}}
{\tt SINCOS} accepts as argument an expression containing
complex exponentials.\\
{\tt SINCOS} rewrites this expression in function of
$\sin(x)$ and $\cos(x)$.\\
Type:\\
$${\tt SINCOS(EXP(i.X))}$$
You obtain:\\
$${\tt COS(X)+i.SIN(X)}$$
\subsubsection{\tt TAN2SC}\index{TAN2SC}
{\tt TAN2SC} has a trigonometric expression as argument.\\
{\tt TAN2SC} rewrites this expression replacing
$\tan(x)$ with $\frac{\sin(x)}{\cos(x)}$.\\
Type:\\
$${\tt TAN2SC(TAN(X))}$$
You obtain:\\
$${\tt \frac{SIN(X)}{COS(X)}}$$
\subsubsection{\tt TAN2SC2}\index{TAN2SC2}
{\tt TAN2SC2} has a trigonometric expression as argument.\\
{\tt TAN2SC2} rewrites this expression replacing
$\tan(x)$ with $\frac{\sin(2 \cdot x)}{1+\cos(2 \cdot x)}$
(or with $\frac{1-\cos(2 \cdot x)}{\sin(2 \cdot x)}$
if you prefer sines, that is, when flag -116
is set to {\tt Prefer sin()}; see \ref{sec:flag} for more details).\\
Type:\\
$${\tt TAN2SC2(TAN(X))}$$
You obtain:\\
$${\tt \frac{SIN(2 \cdot X)}{1+COS(2 \cdot X)}}$$
\subsubsection{\tt HALFTAN}\index{HALFTAN}
{\tt HALFTAN} has a trigonometric expression as argument.\\
{\tt HALFTAN} rewrites $\sin(x)$, $\cos(x)$ and $ \tan(x)$ terms
of the expression in function of $\tan(\frac{x}{2})$.\\
Type:\\
$${\tt HALFTAN(\frac{SIN(2 \cdot X)}{1+COS(2 \cdot X)})}$$
You obtain, after simplification:\\
$${\tt TAN(X)}$$
Type:\\
$${\tt HALFTAN( SIN(X)^2+COS(X)^2)}$$
You obtain (${\tt SQ(X)= X^2}$):\\
$${\tt {\left(\frac{2 \cdot TAN(\frac{X}{2})}
{SQ(TAN(\frac{X}{2}))+1}\right)}^2
+ {\left(\frac{1-SQ(TAN(\frac{X}{2}))}{SQ(TAN(\frac{X}{2}))+1}\right)}^2}$$
You obtain, after simplification:\\
$${\tt 1}$$
\subsubsection{\tt TRIG}\index{TRIG}
{\tt TRIG} has a trigonometric expression as argument.\\
{\tt TRIG} simplifies this expression using the identity:
$\sin(x)^2+\cos(x)^2=1$.\\
Type:\\
$${\tt TRIG(SIN(X)^2+COS(X)^2+1)}$$
You obtain:\\
$${\tt 2}$$
\subsubsection{\tt TRIGSIN}\index{TRIGSIN}
{\tt TRIGSIN} has a trigonometric expression as argument.\\
{\tt TRIGSIN} simplifies this expression using the identity:
$\sin(x)^2+\cos(x)^2=1$, privileging and preserving $\sin(x)$ terms.\\
Type:\\
$${\tt TRIGSIN(SIN(X)^4+COS(X)^2+1)}$$
You obtain:\\
$${\tt SIN(X)^4-SIN(X)^2+2}$$
\subsubsection{\tt TRIGCOS}\index{TRIGCOS}
{\tt TRIGCOS} has a trigonometric expression as argument.\\
{\tt TRIGCOS} simplifies this expression using the identity:
$\sin(x)^2+\cos(x)^2=1$, privileging and preserving $\cos(x)$ terms.\\
Type:\\
$${\tt TRIGCOS(SIN(X)^4+COS(X)^2+1)}$$
You obtain:\\
$${\tt COS(X)^4-COS(X)^2+2}$$
\subsubsection{\tt TRIGTAN}\index{TRIGTAN}
{\tt TRIGTAN} has a trigonometric expression as argument.\\
{\tt TRIGTAN} simplifies this expression using the identity:
$\sin(x)^2+\cos(x)^2=1$, privileging and preserving $\tan(x)$ terms.\\
Type:\\
$${\tt TRIGTAN(SIN(X)^4+COS(X)^2+1)}$$
You obtain:\\
$${\tt \frac{2 \cdot TAN(X)^4+3 \cdot TAN(X)^2+2}
{TAN(X)^4+2 \cdot TAN(X)^2+1}}$$
\subsubsection{\tt FOURIER}\index{FOURIER}\label{sec:fourier}
{\tt FOURIER} has two arguments: an expression $f(x)$ and
an integer $n$.\\
{\tt FOURIER} returns the Fourier coefficient $c_n$ of $f(x)$.
$f(x)$ is assumed to be a periodic function defined on the interval
$[0,T]$, with period $T$.
($T$ is the current value of the {\tt PERIOD} variable).\\
If $f$ is piecewise continuous:
$$f(x)=\sum _{n=-\infty}^{+\infty} c_n e^\frac{2inx\pi}{T}$$
Example:
Find the Fourier coefficients of the function $f$;
the period of $f$ is $2.\pi$, and $f$ is defined on $[0\ 2.\pi[$
as $f(x)=x^2$.\\
Type:
$${\tt 2 \cdot \pi\ \ STO\triangleright \ PERIOD}$$
$${\tt FOURIER(X^2,N)}$$
You obtain after simplification:
$${\tt \frac{2 \cdot i \cdot N \cdot \pi+2}{N^2}}$$
So, if $n \neq 0$:
$$c_n=\frac{2 \cdot i \cdot N \cdot \pi+2}{N^2}$$
Then, type:
$${\tt FOURIER(X^2,0)}$$
You obtain:
$${\tt \frac{4 \cdot {\pi}^2}{3} }$$
So, if $n=0$:
$$c_0=\frac{4 \cdot {\pi}^2}{3}$$
\subsection{Exponentials and Logarithms}
\subsubsection{\tt EXPLN}\index{EXPLN}
{\tt EXPLN} has a trigonometric expression as argument.\\
{\tt EXPLN} rewrites the trigonometric expression in terms of exponentials
and logarithms {\sc without} linearization.\\
{\tt EXPLN} demands to put the calculator in {\tt complex} mode.\\
Type:\\
$${\tt EXPLN(SIN(X))}$$
You obtain:\\
$${\tt \frac{EXP(i \cdot X)-\frac{1}{EXP(i \cdot X)}}{2 \cdot i}}$$
\subsubsection{\tt LIN}\index{LIN}
{\tt LIN} has an expression containing exponentials and trigonometric
functions as argument.\\
{\tt LIN} linearizes the expression (that is, it rewrites the expression
in terms of $\exp(n \cdot x)$).\\
{\tt LIN} demands to put the calculator in {\tt complex} mode when
the input expression contains trigonometric functions.\\
Example 1 :\\
Type:\\
$${\tt LIN((SIN(X))}$$
You obtain:\\
$${\tt -(\frac{i}{2} \cdot EXP(i \cdot X))+
\frac{i}{2} \cdot EXP(-(i \cdot X))}$$
Example 2 :\\
Type:\\
$${\tt LIN((COS(X)^2)}$$
You obtain:\\
$${\tt -(\frac{1}{4} \cdot EXP(2 \cdot i \cdot X))+
\frac{1}{2}+\frac{1}{4} \cdot EXP(-(2 \cdot i \cdot X))}$$
Example 3 :\\
Type:\\
$${\tt LIN((EXP(X)+1)^3)}$$
You obtain:\\
$${\tt 3 \cdot EXP(X)+1+3 \cdot EXP(2 \cdot X)+EXP(3 \cdot X)}$$
\subsubsection{\tt LNCOLLECT}\index{LNCOLLECT}
{\tt LNCOLLECT} has an expression containing logarithms as argument.\\
{\tt LNCOLLECT} collects the logarithmic terms. Therefore,
it is better to use it on a factorized expression
(using {\tt FACTOR} beforehand).\\
Type:\\
$${\tt LNCOLLECT(LN(X+1)+LN(X-1))}$$
You obtain:\\
$${\tt LN((X+1)(X-1))}$$
\subsubsection{\tt TSIMP}\index{TSIMP}
{\tt TSIMP} has an expression as argument; it
simplifies the expression rewriting it in function of
complex exponentials (enabling {\tt complex} mode in the process),
and then reducing the number of variables
as returned by {\tt LVAR} (see section \ref{sec:lvar}).\\
Use {\tt TSIMP} only as a last resort.\\
Type:\\
$${\tt TSIMP(\frac{SIN(3 \cdot X)+SIN(7 \cdot X)}{SIN(5 \cdot X)})}$$
You obtain after simplification (that is, after copying the result 2 times):\\
$${\tt \frac{EXP(i \cdot X)^4+1}{EXP(i \cdot X)^2}}$$
\subsection{Polynomials}
\subsubsection{\tt GCD}\index{GCD}
{\tt GCD} returns the gcd (greatest common divisor)
of two polynomials (or of two lists of polynomials with the same length).\\
Type:
$${\tt GCD(X^2+2 \cdot X+1, X^2-1 )}$$
You obtain:
$${\tt X+1 }$$
Type:
$${\tt GCD(\{X^2+2 \cdot X+1,X^3-1\} ,\{X^2-1,X^2+X-2 \})}$$
You obtain:
$${\tt \{ X+1, X-1 \} }$$
\subsubsection{\tt LGCD}\index{LGCD}
{\tt LGCD} denotes the gcd (greatest common divisor)
of a list of polynomials.\\
{\tt LGCD} returns a list containing the given list of polynomials
and the {\tt GCD} of all polynomials of the list.\\
Type:
$${\tt LGCD(\{X^2+2 \cdot X+1,X^3+1 ,X^2-1,X^2+X \})}$$
You obtain:
$${\tt \{\{X^2+2 \cdot X+1,X^3+1 ,X^2-1,X^2+X \}\ ,\ X+1 \}}$$
\subsubsection{\tt SIMP2}
{\tt SIMP2} has two polynomials (or two lists of polynomials\
with the same length) as arguments.
These two polynomials are considered as representing a rational
fraction. {\tt SIMP2} returns the simplified rational fraction, represented
as a list of two polynomials.\\
Type:
$${\tt SIMP2(X^3-1,X^2-1) }$$
You obtain:
$${\tt \{X^2+X+1,X+1\}}$$
\subsubsection{\tt LCM\protect\index{LCM} }
{\tt LCM} returns the lcm (least common multiple) of two
polynomials (or of two lists of polynomials with the same length).\\
Type:
$${\tt LCM(X^2+2 \cdot X+1 ,X^2-1 )}$$
You obtain:
$${\tt (X^2+2 \cdot X+1) \cdot (X-1)}$$
\subsubsection{\tt FACTOR\protect\index{FACTOR}}
{\tt FACTOR} has either a polynomal or a list of polynomials as argument.\\
{\tt FACTOR} factors its input.\\
Type:
$${\tt FACTOR(X^2+2\cdot X+1)}$$
You obtain:
$${\tt (X+1)^2}$$
Type:
$${\tt FACTOR(X^4-2.X^2+1)}$$
You obtain:
$${\tt (X-1)^2.(X+1) ^2}$$
Type:
$${\tt FACTOR(\{X^3-2.X^2+1,X^2-X\})}$$
You obtain:
$${\tt \{\frac{(X-1) \cdot (2 \cdot X+-1+\sqrt5) \cdot
(2 \cdot X-(1+\sqrt5))}{4}\ ,\ X \cdot (X-1)\}}$$
\subsubsection{\tt FACTORS\protect\index{FACTORS}}
{\tt FACTORS} has either a polynomial or a list of polynomials as argument.\\
{\tt FACTORS} returns a list containing the factors of the polynomial
and their exponents.\\
Type:
$${\tt FACTORS(X^2+2 \cdot X+1)}$$
you obtain:
$${\tt \{X+1,2.\}}$$
Type:
$${\tt FACTORS(X^4-2 \cdot X^2+1)}$$
You obtain:
$${\tt \{X-1,2.\ ,\ X+1 ,2.\}}$$
Type:
$${\tt FACTORS(\{X^3-2 \cdot X^2+1,X^2-X\})}$$
You obtain:
$${\tt \{\{X-1,1.\ ,\ 2 \cdot X+-1+\sqrt5 ,1.\ ,
\ 2 \cdot X-(1+\sqrt5) ,1.\ ,\ 4, -1.\},}$$
$${\tt \{X, 1.\ ,\ X-1,1.\}\}}$$
\subsubsection{\tt DIVIS}\index{DIVIS}
{\tt DIVIS} has either a polynomial or a list of polynomials as argument,
and returns the list of its divisors.\\
Type:
$${\tt DIVIS(X^4-1)}$$
You obtain:
$${\tt \{1,X^2+1,X-1,X^3-X^2+X-1,X+1,X^3+X^2+X+1,X^2-1,X^4-1\}}$$
\subsubsection{\tt QUOT}\index{QUOT}
{\tt QUOT} returns the quotient of the division between two polynomials.\\
Type:
$${\tt QUOT(X^2+2\cdot X +1 ,X )}$$
You obtain:
$${\tt X+2}$$
\subsubsection{\tt REMAINDER}\index{REMAINDER}
{\tt REMAINDER} returns the remainder of the division between
two polynomials.\\
Type:
$${\tt REMAINDER(X^3-1 ,X^2-1 )}$$
you obtain:
$${\tt X-1}$$
\subsubsection{\tt DIV2}\index{DIV2}
Returns a list containing both the quotient and the remainder of
the division between two polynomials.\\
Type:
$${\tt DIV2(X^2+2\cdot X+1 ,X )}$$
You obtain:
$${\tt \{X+2,1\}}$$
The step-by-step mode can be of interest here, because it displays
the intermediate steps of the division process.\\
\subsubsection{\tt EGCD}\index{EGCD}
This command applies the B\'ezout identity (Extended Greatest Common Divisor).
${\tt EGCD(A[X],B[X] )}$ returns ${\tt \{ D[X],U[X],V[X] \}}$,
where $D,U,V$ satisfy the following relation:
$${\tt {D[X]=U[X]*A[X]+V[X]*B[X]}}$$
Type:
$${\tt EGCD(X^2+2 \cdot X+1 ,X^2-1 )}$$
You obtain:
$${\tt \{2 \cdot X+2,1,-1\}}$$
\subsubsection{\tt ABCUV}\index{ABCUV}
This command applies the B\'ezout identity like {\tt EGCD} but, now,
the arguments are three polynomials,
$A, B, C$ (C must be a multiple of GCD(A,B)):\\
${\tt ABCUV(A[X],B[X],C[X])}$ returns ${\tt \{ U[X],V[X] \}}$,
where $U,V$ satisfy the following:
$${\tt {C[X]=U[X]*A[X]+V[X]*B[X]}}$$
Type:
$${\tt ABCUV(X^2+2 \cdot X+1 ,X^2-1,X+1 )}$$
You obtain:
$${\tt \{\frac{1}{2},\frac{-1}{2}\}}$$
Type:
$${\tt ABCUV(X^2+2 \cdot X+1 ,X^2-1,X^3+1 )}$$
You obtain:
$${\tt \{ \frac{X^2-X+1}{2},-\frac{X^2-X+1}{2}\}}$$
\subsubsection{\tt HORNER}\index{HORNER}
{\tt HORNER} has two arguments: a polynomial $P[X]$ and a number
$a$; it returns a list containing $Q[X]$ (quotient of $P[X]$
divided by $X-a$), $a$, and $P[a]$.\\
Type:
$${\tt HORNER(X^4+2 \cdot X^3-3 \cdot X^2+X-2,1)}$$
You obtain:
$${\tt \{X^3+3 \cdot X^2+1\ ,\ 1\ ,\ -1 \}}$$
\subsubsection{\tt PTAYL}\index{PTAYL}
Rewrites a polynomial $P[X]$ in function of the powers of $X-a$.\\
{\tt PTAYL} has two arguments: a polynomial P and a number $a$.\\
Type:
$${\tt PTAYL(X^2+2\cdot X +1 , 2)}$$
you obtain the polynomial $Q[X]$:
$${\tt X^2+6\cdot X +9 }$$
Warning, notice that:
$${\tt P(X)=Q(X-2)}$$
\subsubsection{\tt ZEROS}\index{ZEROS}
{\tt ZEROS} has two arguments: a polynomial $P$ and a variable name.\\
{\tt ZEROS} returns a list containing the zeros of $P$ with respect
to the given variable, {\sc without} their multiplicity.\\
Type:
$${\tt ZEROS(X^4-1,X)}$$
You obtain:\\
-in real mode
$${\tt \{-1\ ,\ 1\}}$$
-in complex mode
$${\tt \{ -1\ ,\ 1\ ,\ -i\ ,\ i\}}$$
\subsubsection{\tt PROOT\protect\index{PROOT}}
{\tt PROOT} is the numeric command of the HP48.\\
{\tt PROOT} has a vector containing the coefficients
of a monovariate polynomial (ordered by decreasing powers of the
polynomial's variable) as argument.\\
{\tt PROOT} returns a vector whose elements are the roots of
the polynomial.\\
To find the roots of $P[x]=x^5-2 \cdot x^4+x^3$,
type:
$${\tt PROOT([1,-2,1,0,0,0]) }$$
You obtain:
$${\tt [0.,0.,0.,1.,1.]}$$
The result means that $0$ is a triple root, and
$1$ is a double root of $P[x]$.
\subsubsection{\tt FROOTS}\index{FROOTS}
{\tt FROOTS} has a rational function $F[x]$ as argument.\\
{\tt FROOTS} returns a vector whose components are the roots and the poles
of $F[x]$, followed by their multiplicity.\\
Type:
$${\tt FROOTS(\frac{X^5-2 \cdot X^4+X^3}{X-2}) }$$
You obtain:
$${\tt [2,-1.,0,3.,1,2.]}$$
The result means that: $2$ is a pole of order 1, $0$ is a triple root,
and $1$ is a double root of $F[x]=\frac{x^5-2 \cdot x^4+x^3}{x-2}$.
\subsubsection{\tt PCOEF}\index{PCOEF}
{\tt PCOEF} is the numeric command of the HP48.\\
{\tt PCOEF} has a vector containing the roots of a polynomial
$P[x]$ as argument.\\
{\tt PCOEF} returns a vector whose components are the coefficients
of the polynomial $P[x]$ (ordered by decreasing powers of
the polynomial's variable).\\
Type:
$${\tt PCOEF([1,2,0,0,3])}$$
You obtain:
$${\tt [1.,-6.,11.,-6.,0.,0.]}$$
This means that
$P[x]=(x-1) \cdot (x-2) \cdot x \cdot x \cdot (x-3)$
is equal to:\\$x^5-6 \cdot x^4+11 \cdot x^3-6 \cdot x^2$.
\subsubsection{\tt FCOEF}\index{FCOEF}
{\tt FCOEF} has as argument a vector
whose components are the roots and poles of a rational function
$F[x]$, followed by their multiplicity.\\
{\tt FCOEF} returns the rational function $F[x]$.\\
Type:
$${\tt FCOEF([1,2,0,3,2,-1]) }$$
You obtain:
$${\tt \frac{X^5-2 \cdot X^4+X^3}{X-2}}$$
since $(x-1)^2 \cdot x^3=x^5-2 \cdot x^4+x^3$
\subsubsection{\tt CHINREM}\index{CHINREM}
{\tt CHINREM} has two vectors as arguments; each vector has
two polynomials as components.\\
{\tt CHINREM} returns a vector with two polynomials as components.\\
{\tt CHINREM([A[X],R[X]],[B[X],Q[X]])} finds the polyonimals {\tt P[X]} and
{\tt S[X]} satisfying the following relations:\\
${\tt S[X]=R[X] \cdot Q[X]}$,\\
${\tt P[X]=A[X] (mod R[X])}$ and ${\tt P[X]=B[X] (mod Q[X])}$. \\
There always is a solution
{\tt P[X]} if {\tt R[X]} and {\tt Q[X]} are mutually primes,
and all solutions are congruent modulo ${\tt S[X]=R[X] \cdot Q[X]}$.\\
Find the solutions $P[X]$ of:
$${\tt \left \{
\begin{array}{rl}
P[X]=&X\ (\bmod\ X^2+1)\\ P[X]=&X-1\ (\bmod\ X^2-1)
\end{array}\right.}$$
Type:
$${\tt CHINREM([X,X^2+1],[X-1,X^2-1])}$$
You obtain:
$${\tt [-\frac{X^2-2 \cdot X+1}{2},-\frac{X^4-1}{2}]}$$
that is, $P[X]=-\frac{X^2-2 \cdot X+1}{2} \ (\bmod-\frac{X^4-1}{2})$
\subsubsection{\tt TRUNC}\index{TRUNC}
{\tt TRUNC} truncates a polynomial to a given order.\\
{\tt TRUNC} has two arguments: a polynomial and $ X^n$.\\
{\tt TRUNC} returns the polynomial truncated to order
$n-1$ (no terms of order $\geq X^n$).\\
Type:
$${\tt TRUNC({(1+X+\frac{1}{2} \cdot X^2)}^3\ ,\ X^4)}$$
You obtain:
$${\tt 4 \cdot X^3+\frac{9}{2} \cdot X^2+3 \cdot X+1}$$
\subsubsection{\tt LAGRANGE}\index{LAGRANGE}
{\tt LAGRANGE} has as argument a matrix with two rows and
$n$ columns:\\
the first row corresponds to the abscissa values $x_i$, and the second row
corresponds to ordinate values $y_i$ ($i=1..n$).\\
{\tt LAGRANGE} returns the polynomial $P$ of degree $n-1$,
so that $P(x_i)=y_i$.\\
Type:
$${\tt LAGRANGE([[1,3],[0,1]])}$$
You obtain:
$${\tt \frac{X-1}{2}}$$
in fact $\frac{x-1}{2}=0 $ for $x=1$ and $\frac{x-1}{2}=1$ for $x=3$
\subsubsection{\tt LEGENDRE}\index{LEGENDRE}
{\tt LEGENDRE} has as argument an integer value $n$.\\
{\tt LEGENDRE} returns the non trivial polynomial solution of the
differential equation:
$$(x^2-1) \cdot y''-2 \cdot x \cdot y'-n(n+1) \cdot y=0$$
Type:
$${\tt LEGENDRE(4)}$$
You obtain:
$${\tt \frac{35 \cdot X^4-30 \cdot X^2+3}{8}}$$
\subsubsection{\tt HERMITE}\index{HERMITE}
{\tt HERMITE} has as argument an integer value $n$.\\
{\tt HERMITE} returns the Hermite polynomial of degree $n$.\\
Type:
$${\tt HERMITE(6)}$$
You obtain:
$${\tt 64 \cdot X^6-480 \cdot X^4+720 \cdot X^2-120}$$
\subsubsection{\tt TCHEBYCHEFF}\index{TCHEBYCHEFF}
{\tt TCHEBYCHEFF} has as argument an integer value $n$.\\
If $n>0$, {\tt TCHEBYCHEFF} returns the polynomial $T_n$:\\
$$T_n[x]= \cos(n \cdot \arccos(x))$$\\
If $n<0$ {\tt TCHEBYCHEFF} returns the the polynomial $T_n$:\\
$$T_n[x]=\frac{\sin(n \cdot \arccos(x))}{\sin(\arccos(x))}$$\\
Type:
$${\tt TCHEBYCHEFF(4)}$$
You obtain:
$${\tt 8 \cdot X^4-8 \cdot X^2+1}$$
in fact:\\
$\cos(4 \cdot x)=Re((\cos(x)+i \cdot \sin(x))^4)$\\
$\cos(4 \cdot x)=\cos(x)^4-6 \cdot \cos(x)^2 \cdot
(1-\cos(x)^2)+((1-\cos(x)^2)^2$.\\
$\cos(4 \cdot x)=T_4(\cos(x))$.\\
Type:
$${\tt TCHEBYCHEFF(-4)}$$
You obtain:
$${\tt 8 \cdot X^3-4 \cdot X}$$
in fact:\\
$\sin(4 \cdot x)=\sin(x) \cdot (8 \cdot \cos(x)^3-4 \cdot \cos(x))$.
\subsubsection{\tt REORDER}\index{REORDER}
{\tt REORDER} has two arguments: an expression and
a vector containing an ordered list of variables.\\
{\tt REORDER} reorders the input expression following the order of
variables given by its second argument.\\
Type:
$${\tt REORDER(X^2+2 \cdot X \cdot A+A^2+Z^2-X \cdot Z,[A,X,Z])}$$
You obtain:
$${\tt A^2+2 \cdot X \cdot A+X^2-Z \cdot X+Z^2}$$
\subsection{Rational fractions}
\subsubsection{\tt FXND}\index{FXND}
{\tt FXND} has a rational fraction as argument, and returns a list
containing the simplified numerator and denominator of this fraction.\\
Type:
$${\tt FXND(\frac{X^2-1}{X-1}) }$$
You obtain:
$${\tt \{X+1,1\}}$$
\subsubsection{\tt SIMP2}\index{SIMP2}
{\tt SIMP2} has two polynomials (or two lists of polynomials with
the same length) as arguments.
These two polynomials are considered as representing a rational fraction.\\
{\tt SIMP2} simplifies the rational fraction and returns the result
as a list of two polynomials.\\
Type:
$${\tt SIMP2(X^3-1,X^2-1) }$$
You obtain:
$${\tt \{X^2+X+1,X+1\}}$$
\subsubsection{\tt PROPFRAC}\index{PROPFRAC}
{\tt PROPFRAC} has a rational fraction as argument.\\
{\tt PROPFRAC} rewrites the rational fraction to put its
integer part in evidence and returns the result.
In other words, ${\tt PROPFRAC(A(X) / B(X))}$ rewrites
the rational fraction $\frac{A[X]}{B[X]}$ as:
$$Q[X]+\frac{R[X]}{B[X]}$$\ \ where \ $R[X]=0$ or
\ $0\leq deg(R[X])a$,
and a negative real number (for example -4.) to do
an unidirectional expansion about $x=a$ with $ \ x0$ must be taken into account
(when $x<0$ the calculator assumes $\ln(x)$ exists, and has a complex value).
\item b) $u(x)=0$ has an unique solution $\alpha$ in $[2,\ 3]$.\\
From a) $u$ increases in $]0,\ +\infty[$.\\
We type:
$${\tt U(2)\ red-shift\ ENTER}$$
answer $-0.306...$\\
then,
$${\tt U(3)\ red-shift \ ENTER}$$
answer $1.098...$\\
Thereafter, we calculate:
$${\tt U(2.20)\ red-shift\ ENTER}$$
answer $-0.306...$\\
and
$${\tt U(2.21)\ red-shift \ ENTER}$$
answer $-0.306...$\\
From the theorem of intermediate values ($u$ is both increasing and
continuous in $[2, 3]$, therefore $u$ zeroes itself exactly once between
$2$ et $3$ (since $u(2)<0$ and $u(3)>0$)).\\
So, if we call $\alpha$ the unique zero of $u$ in $[2,\ 3]$, we have:
$$2.20< \alpha <2.21$$
since $u(2.20)<0$ and $u(2.21)>0$.
\item c) Sign of $u(x)$ in $]0, \ +\infty[$\\
The sign of $u(x)$ can be deducted from the variation table of $u$; we have:
$$\left \{ \begin{array} {rl} u(x)<0 &\mbox{ for } x<\alpha\\
u(x)=0 & \mbox{ for } x=\alpha\\
u(x)>0 & \mbox{ for } x>\alpha
\end{array}\right.$$
\end{itemize}
\item
\begin{itemize}
\item a) Variations of $f$.\\
We must do the variation table by hand, because the derivative of $f$
is not a rational function... and the calculator is not yet able to
handle this case!\\
Since the sign of $f'(x)$ is the same as of $u(x)$, we have:
$$\begin{array}{|c|ccccc|} \hline f'(x) & 0 & - & \alpha & + & +\infty\\
\hline
f(x) & +\infty & \downarrow & \frac{\alpha-1}{\alpha}(ln( \alpha)-2) &
\uparrow & +\infty\\ \hline
\end{array}$$
\item b)$f(\alpha)=-\frac{(\alpha-1)^2}{\alpha}$\\
We have:\\$u(\alpha)=0$, so $\ln(\alpha)=3-\alpha$\\
We type in the equation writer:
$${\tt (1-\frac{1}{ A})(LN(A)-2)}$$
then we highlight ${\tt LN(A)}$,\\
open the {\tt ALG (red-shift 4)} menu,\\
press the ${\tt (SUBST)}$ key\\
to complete the command ${\tt\ SUBST(LN(A),LN(A)=3-A)}$,\\
and press {\tt ENTER ENTER}.\\
We obtain:
$${\tt -\frac{A^2-2 \cdot A+1}{A}}$$
Now,
$${\tt FACTOR (-\frac{A^2-2 \cdot A+1}{A})}$$
returns
$${\tt -\frac{(A-1)^2}{A}}$$
We type:
$${\tt DERIV( -\frac{(A-1)^2}{A},A)}$$
We obtain:
$${\tt -\frac{(A^2-1)}{A^2}} $$
So, the function $v(x)= -\frac{(x-1)^2}{x}$ decreases for $x>=1$.\\
We obtain a bounded approximation of $f(\alpha)$ calculating:\\
$v(2.21)$ and $v(2.20)$.\\
We type:
$${\tt -\frac{(1.21)^2}{2.21}\ red-shift\ ENTER} $$
answer $-0.662488 $\\
$${\tt -\frac{(1.2)^2}{2.2}\ red-shift\ ENTER}$$
answer $-0.65454... $\\
so, we have: $$-0.663 EVAL 'A' STO}
\subsubsection{Translation for the HP49G in Algebraic mode}
To input a value into a local variable {\tt A}, you type:\\
${\tt ....0\ \rightarrow \ A \ll\ PROMPTSTO('A')... \gg}$ or\\
$ {\tt....0\ \rightarrow \ A \ll \ PROMPTSTO('A');0\ \rightarrow \ B \ll
PROMPTSTO('B').....\gg \ \gg}$\\
If you enter only:\\
{\tt ...PROMPTSTO('A')}, {\tt A} is then a global variable, or\\
{\tt ...PROMPTSTO('A'); PROMPTSTO('B')}, {\tt A} and {\tt B} are then
global variables.\\
You can use {\tt INPUT}\index{INPUT}, too. For example, if a local
variable {\tt A} must contain a character string, you can enter:
$${\tt INPUT(''A='',''\ '')\ \rightarrow\ A}$$
or, if {\tt A} must contain a number:\\
${\tt .....INPUT(''A='',''\ '')\rightarrow A}$\\
${\tt \ll OBJ\rightarrow(A)\ \rightarrow\ A}$\\
${\tt \ll .....\gg }$\\
${\tt \gg }$
\subsection{Data output}
\subsubsection{Translation in algorithmic language}
In algorithmic language, you write:\\
{\tt print "A=",A}
\subsubsection{Translation for the HP49G in RPN mode}
Usually it is enough to push results into the stack, so that you
can reuse them; if this is the case, you simply write:\\
{\tt A B}\\
You can also tag the result, as follows:\\
{\tt A "A=" ->TAG}\\
{\tt HALT} halts the program.
\subsubsection{Translation for the HP49G in Algebraic mode}
Only the last result is written into the history.\\
To display intermediate results, you can use either:
$$ {\tt DISP("A="+A,3)}$$\index{DISP}
here, {\tt 3} is the line number on which the result is displayed,
or:
$${\tt MSGBOX( "A="+\rightarrow STR(A))}$$\index{MSGBOX}
{\tt CLEAR} clears the screen.\index{CLEAR}\\
{\tt FREEZE(7)} stops the program and freezes the screen so that
you can see the results you have previously written on it.\index{FREEZE}
\subsection{Sequence of instructions, or ``block''}
A ``block'' is a sequence of one or more instructions.
\subsubsection{Translation in algorithmic language}
In algorithmic language, you can use either the space or a newline
to terminate an instruction.
\subsubsection{Translation for the HP49G in RPN mode}
Like the algorithmic language, spaces and newlines act as instruction
separators.
\subsubsection{Translation for the HP49G int algebraic mode}
When the {\tt HP49G} works in algebraic mode, {\tt\ ;\ } acts
as instruction separator.\\
You can type {\tt\ ;\ } pressing {\tt red-shift SPC} simultaneously.
\subsection{Store instruction}
The store instruction is used to store a value or an expression
into a variable.
\subsubsection{Translation in Algorithmic language}
In algorithmic language, the store operation is denoted, for example, by:\\
{\tt 2*A->B}
to store {\tt 2*A} into {\tt B}.
\subsubsection{Translation for the HP49G in RPN mode}
When the {\tt HP49G} works in RPN mode, you must use the postfix notation
and the
{\tt STO} command:\\
{\tt 2 A * 'B' STO}
\subsubsection{Translation for the HP49G in Algebraic mode}
when the {\tt HP49G} works in algebraic mode, you use the
${\tt STO}$ key, that is displayed on the calculator screen as:
$ \triangleright $ (and will be denoted here by ${\tt STO\triangleright}$).
\subsection{Conditional branch instructions}
\subsubsection{Translation in algorithmic language}
{\tt if \emph{condition} then
\emph{action}
end if}\\
{\tt if \emph{condition} then
\emph{action1} else
\emph{action2}
end if}\\
Example :\\
{\tt if A = 10 or A < B then B-A->B else A-B->A end if}
\subsubsection{Translation for the HP49G in RPN mode}
{\tt IF \emph{condition} THEN
\emph{action}
END}
{\tt IF \emph{condition} THEN
\emph{action1}
\emph{action2}
END}
Warning : you must use the postfix notation and {\tt ==}
to denote the equality test operator.
The above mentioned example can be written as:
{\tt IF A 10 == A B < OR THEN
B A - 'B' STO
ELSE A B - 'A' STO END}
you can also write:
{\tt IF 'A==10' 'A < B' OR THEN ...}
\subsubsection{Translation for the HP49G in Algebraic mode}
{\tt IF \emph{condition} THEN
\emph{action}
END}\\
{\tt IF \emph{condition} THEN
\emph{action1} ELSE
\emph{action2}
END}\\
Example :
Pay attention to always use {\tt ==} to denote the equality test!\\
{\tt IF A == 10 OR A < B THEN B-A STO$\triangleright$ B ELSE A-B
STO$\triangleright$ A END}
\subsection{``For'' loops}
\subsubsection{Translation in algorithmic language}
{\tt for I from A to B do \emph{action} end for}\\
{\tt for I from A to B (step P) do \emph{action} end for}
\subsubsection{Translation for the HP49G in RPN mode}
{\tt A B FOR I \emph{action} NEXT}
{\tt A B FOR I \emph{action} P STEP}
\subsubsection{Translation for the HP49G in Algebraic mode}
{\tt FOR (I , A , B) \emph{action} NEXT}
{\tt FOR (I , A , B ) \emph{action} STEP P}\\
It is not necessary to declare the loop variable
{\tt I} in advance.\\
{\tt I} is automatically declared and initialized by:
{\tt FOR (I,.,.)...}
\subsection{``While'' loops}
\subsubsection{Translation in algorithmic language}
{\tt while \emph{condition} do
\emph{action}
end while}
\subsubsection{Translation for the HP49G in RPN mode}
{\tt WHILE \emph{condition} REPEAT
\emph{action}
END}
\subsubsection{Translation for the HP49G in Algebraic mode}
{\tt WHILE \emph{condition} REPEAT
\emph{action}
END}
\subsection{Boolean (or conditional) expressions}
A boolean (or conditional) expression is a function having a boolean
value, that is, either {\tt true} or {\tt false}.
\subsubsection{Translation in algorithmic language}
To express a simple condition you use the following operators:
{\tt = < > $\leq$ $\geq$ $\neq$}
\subsubsection{Translation for the HP49G in RPN mode}
Warning, you must use the postfix notation and {\tt ==} to denote
the equality test operator.
\subsubsection{Translation for the HP49G in Algebraic mode}
Warning, for the {\tt HP49G}, the equality test operator is denoted by:
{\tt ==}
\subsection{Logical operators}
\subsubsection{Translation in algorithmic language}
To express complex conditions, you can use the following
logical operators:
{\tt or}, {\tt and}, and {\tt not}.
\subsubsection{Translation for the HP49G in RPN mode}
Warning, you must use the postfix notation.\\
{\tt or}, {\tt and}, and {\tt not} are denoted, respectively,
by {\tt OR}, {\tt AND}, and {\tt NOT}.
\subsubsection{Translation for the HP49G in Algebraic mode}
{\tt or}, {\tt and}, and {\tt not} are denoted on the
{\tt HP49G} by {\tt OR}, {\tt AND}, and {\tt NOT}.
\subsection{Functions}
In a function, you do not perform data entry explicitly:\\ instead,
you use function parameters, that are automatically initialized when
the function is called.\\
In a function, you must be able to reuse the result at will:\\
in algorithmic language, you use the {\tt return} command instead
of {\tt print}.
\subsubsection{Translation in algorithmic language}
You can write, for example:
\begin{verbatim}
function addition(A,B)
return A+B
end function
\end{verbatim}
This means that:
\begin{itemize}
\item The result of the function will be displayed when the function
is executed.
\item The function can be used in an expression.
\end{itemize}
\subsubsection{Translation for the HP49G in RPN mode}
When the {\tt HP49G} works in RPN mode, it is assumed that
function arguments are on the stack when the function is invoked.
Inside the function, the arguments become local variables
initialized with the topmost elements of the stack. The result
of the function is pushed on the stack.\\
The example above can be written as:\\
${\tt \ll \rightarrow\ A\ B}$\\
${\tt \ \ \ll\ A\ B\ +\ \gg}$\\
${\tt \gg}$\\
{\tt 'ADDITION' STO}\\
To invoke the function you must push the intended values of {\tt A} and {\tt B}
on stack levels 2 and 1; after the execution of {\tt ADDITION} their
sum will be on stack level 1.
\subsubsection{Translation for the HP49G in Algebraic mode}
The example above can be written as:
${\tt \ll \rightarrow\ A\ B} $\\
${\tt \ \ \ll A +B \gg}$\\
${\tt \gg}$\\
${\tt STO\triangleright\ ADDITION}$\\
To invoke the function, you enter: $${\tt ADDITION(4,5)}$$
\subsection{Lists}
\subsubsection{Translation in algorithmic language}
In the algorithmic language, \{ and \} are used as list delimiters.\\
For example, \{\} denotes the empty list, and \{1, 2, 3\} is a list
of 3 elements.\\
The {\tt +} operator can be used to concatenate two lists together or a list
with an element:\\
{\tt \{1, 2, 3\}->TAB}\\
{\tt TAB + 4 ->TAB} (now {\tt TAB} contains \{1, 2, 3, 4\}) \\
{\tt TAB[2]} denotes the second element of {\tt TAB}, 2 in this example.
\subsubsection{Translation for the HP49G in RPN mode}
It is not necessary to declare the maximum length of a list in advance.\\
The list delimiters are \{ and \}.
For example \{1 2 3\} is a list of 3 elements, and \{\} is an empty list.\\
You can retrieve the {\tt P}-th element of list {\tt L} and put it on
the stack using:\\
{\tt L P GET} or {\tt 'L' P GET}\\
To update the {\tt P}-th element of {\tt L} (for example, set it to 0)
you must enter:\\
{\tt 'L' P 0 PUT} or {\tt L P 0 PUT 'L' STO}\\
Actually, {\tt L P 0 PUT} leaves the updated list on the stack,
and:\\
{\tt 'L' P 0 PUT}
updates list {\tt L} in-place instead.\\
The {\tt +} operator can be used to concatenate two lists together or a list
with an element.
\subsubsection{Translation for the HP49G in algebraic mode}
It is not necessary to declare the maximum length of a list in advance.\\
The list delimiters are \{ and \}.
For example \{1 2 3\} is a list of 3 elements, and \{\} is an empty list.\\
You can retrieve the {\tt P}-th element of list {\tt L } using:\\
{\tt L[P]} or
{\tt GET (L, P )}\index{GET}\\
To update the {\tt P}-th element of {\tt L} (for example, set it to 0)
you must enter:\\
{\tt PUT(L, P, 0) STO$\triangleright$ L }\index{PUT}\\
or\\
{\tt PUT('L', P, 0)}\\
Actually, {\tt PUT(L, P, 0)} returns the updated list,
and:\\
{\tt PUT ('L', P, 0)}
updates list {\tt L} in-place instead.\\
The {\tt +} operator can be used to concatenate two lists together or a list
with an element.
The {\tt SEQ}\index{SEQ} command allows you to create a list;
for example, if you type:
$${\tt SEQ('X*X','X',4,10,1)}$$
you obtain:
$${\tt \{16,25,36,49,64,81,100\}}$$
\subsection{Example: The sieve of Erastothenes}
\subsubsection{Description}
To find the prime numbers less than or equal to $N$ :
\begin{enumerate}
\item Put the numbers from 1 to $N$ into a list.
\item Mark 1 and store 2 into the variable $P$.
If $P \cdot P \leq N$ we must process all elements from $P$ to $N$.
\item Mark all multiples of $P$ starting from $P \cdot P$.
\item Increment $P$ by 1
If $P \cdot P$ is less than or equal to $N$, we must process the non-marked
elements from $P$ to $N$.
\item Store into $P$ the smallest non-marked elements of the list.
\item Repeat steps 3, 4 and 5 while $P \cdot P$ is less than or equal to $N$.
\end{enumerate}
\subsubsection{Algorithmic language}
\begin{verbatim}
function crible(N)
local TAB PREM I P
// TAB and PREM are lists
{} ->TAB
{} ->PREM
for I from 2 to N do
TAB+I -> TAB
end for
0 +TAB -> TAB
2 -> P
// Done steps 1 and 2
// marking has been implemented replacing the element to be marked with 0
// TAB is the list 0 2 3 4 ...N \end{verbatim}
{\tt while P*P $\leq$ N do}\begin{verbatim}
for I from P to int(N/P) do
0 -> TAB[I*P]
end for
// We marked all multiples of P starting from P*P
P+1 -> P
// We search the smallest number <= N, not marked, between P and N
\end{verbatim}
{\tt {\ } while (P*P $\leq$ N) and (TAB[P]=0) do}
\begin{verbatim}
P+1 -> P
end while
end while
// We copy the result into PREM
for I from 2 to N do\end{verbatim}
{\tt {\ } if TAB[I] $\neq$ 0 then}
\begin{verbatim}
PREM +I -> PREM
end if
end for
return PREM
\end{verbatim}
\subsubsection{HP49G, RPN mode}
This is the program {\tt CRIBLE}:
{\tt N} is the parameter whose actual value must be on the stack.
The local variables are:
{\tt P} and {\tt I} (integers),
{\tt TA} and {\tt PREM} (lists).\\
\%\%HP: T(3)A(R)F(.);
${\tt \ll \ \{\}\ \{\}\ 2\ 1\ \rightarrow\ N \ TA\ PREM\ P\ I }$\\
\hspace*{0.5cm}${\tt \ll\ 0\ 'X'\ 'X'\ 2\ N\ 1\ SEQ\ +\ 'TA'\ STO}$\\
\hspace*{1cm}{\tt WHILE P P * N $\leq$ REPEAT \\
\hspace*{1.5cm} P N P / FLOOR FOR I \\
\hspace*{2cm} TA I P * 0 PUT 'TA' STO\\
\hspace*{1.5cm} NEXT\\
\hspace*{1.5cm} 1 'P' STO+\\
\hspace*{1.5cm} WHILE P P * N $\leq$ TA P GET 0 == AND REPEAT \\
\hspace*{2cm} 1 'P' STO+\\
\hspace*{1.5cm} END\\
\hspace*{1cm} END \\
\hspace*{1cm} 2 N FOR I\\
\hspace*{1.5cm} IF TA I GET 0 $\neq$ THEN\\
\hspace*{2cm} I 'PREM' STO+\\
\hspace*{1.5cm} END\\
\hspace*{1cm} NEXT \\
\hspace*{1cm} PREM} \\
\hspace*{.5cm}${\tt \gg}$\\
${\tt \gg}$
\subsubsection{HP49G, Algebraic mode}
This is the program {\tt CRIBLE};
the user must type, for example:\\
{\tt CRIBLE(100)}, to execute it.\\
\noindent
${\tt \ll \ \rightarrow\ N \ }$\\
\hspace*{0.5cm}${\tt \ll}${\tt\ 0+SEQ('I','I',1,N,1) $\rightarrow$ TA}\\
\hspace*{1cm}${\tt \ll \ 2\ \rightarrow\ P}$\\
\hspace*{1.5cm}${\tt \ll WHILE\ P*P \leq N\ REPEAT}$\\
\hspace*{2cm}{\tt FOR (I , P , FLOOR(N/P))}\\
\hspace*{2.5cm}{\tt PUT('TA',I*P,0)}\\
\hspace*{2cm}{\tt NEXT;}\\
\hspace*{2cm} ${\tt P+1\ STO\triangleright P;}$\\
\hspace*{2cm}{\tt WHILE P*P $\leq $ N AND GET(TA,P) == 0 REPEAT}\\
\hspace*{2.5cm} ${\tt P+1\ STO \triangleright \ P}$\\
\hspace*{2cm}{\tt END}\\
\hspace*{1.5cm}{\tt END;}\\
\hspace*{1.5cm}${\tt \{2\} \ \rightarrow\ PREM}$\\
\hspace*{2cm}${\tt \ll FOR\ (I,3 , N) }$\\
\hspace*{2.5cm}{\tt {\ }IF TA(I) $\neq$ 0 THEN}\\
\hspace*{3cm} $ {\tt PREM+I \ STO\triangleright PREM;}$\\
\hspace*{2.5cm} {\tt END}\\
\hspace*{2cm}{\tt NEXT;}\\
\hspace*{2cm}{\tt PREM }\\
\hspace*{2cm}${\tt \gg}$\\
\hspace*{1.5cm}${\tt \gg}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ CRIBLE}$
\section{Arithmetic programs}
\subsection{Calculating the GCD using the Euclide's algorithm}
This algorithm is rooted on the recursive definition of GCD:
\begin{eqnarray*}
GCD(A,0) & = & A \\
GCD(A,B) & = & GCD(B,A \ mod \ B) \ if \ B \neq 0
\end{eqnarray*}
The algorithm can be described as follows:\\
we carry out this sequence of euclidean divisions:
\begin{eqnarray*}
A=& B \times Q_1+R_1 & 0 \leq R_1 < B \\
B=& R_1 \times Q_2+R_2 & 0 \leq R_2 < R_1 \\
R_1=& R_2 \times Q_3+R_3 & 0 \leq R_3 < R_2 \\
.......
\end{eqnarray*}
After a finite number of steps, it exists an integer $n$ so that:
$R_n = 0.$ \\
We obtain then:\\
$GCD(A,B)= GCD(B,R_1) =...$\\
$GCD(R_{n-1},R_n) = GCD(R_{n-1},0) = R_{n-1}$
\subsubsection{Algorithmic language}
\begin{itemize}
\item Iterative implementation\\
If B $\neq$ 0 we calculate R=A mod B then, using B instead of A
(storing B into A) and R instead of B ( storing R into B)
we repeat the process until B=0; when this happens, the GCD is A.
\begin{verbatim}
function GCD(A,B)
local R\end{verbatim}
{\tt while B $\neq$ 0 do}\begin{verbatim}
A mod B->R
B->A
R->B
end while
return A
end function
\end{verbatim}
\item Recursive implementation\\
We simply write out the recursive definition given above.
\begin{verbatim}
function GCD(A,B)\end{verbatim}
{\tt if B $\neq$ 0 then}\begin{verbatim}
return GCD(B,A mod B)
else
return A
end if
end function\end{verbatim}
\end{itemize}
\subsubsection{HP49G, RPN mode}
\begin{itemize}
\item Iterative implementation\\
${\tt \ll \ 0 \rightarrow\ A\ B\ R}$ \\
\hspace*{0.5cm}${\tt \ll WHILE\ B\ 0 \ \neq REPEAT}$\\
\hspace*{1.5cm}{\tt A B MOD 'R' STO}\\
\hspace*{1.5cm}{\tt B 'A' STO}\\
\hspace*{1.5cm}{\tt R 'B' STO}\\
\hspace*{1cm}{\tt END}\\
\hspace*{1cm}{\tt A}\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg}$\\
\item Recursive implementation\\
${\tt \ll \ 0 \rightarrow\ A\ B\ }$\\
\hspace*{0.5cm}${\tt \ll IF\ B\ 0\ \neq\ THEN}$\\
\hspace*{1.5cm}{\tt B A B MOD PGCDR}\\
\hspace*{1cm}{\tt ELSE}\\
\hspace*{1.5cm}{\tt A}\\
\hspace*{1cm}{\tt END}\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg}$\\
The program must be stored into variable {\tt PGCDR}.
\end{itemize}
\subsubsection{HP49G, Algebraic mode}
\begin{itemize}
\item Iterative implementation\\
\noindent
${\tt \ll \ \rightarrow\ A,B \ }$\\
\hspace*{0.5cm}${\tt \ll 0\ \rightarrow\ R}$\\
\hspace*{1cm}${\tt \ll \ WHILE \ B\ \neq \ 0 \ REPEAT}$\\
\hspace*{2cm}${\tt A\ MOD \ B \ STO \triangleright R;}$\\
\hspace*{2cm}${\tt B \ STO \triangleright A;}$\\
\hspace*{2cm}${\tt R \ STO \triangleright B}$\\
\hspace*{1.5cm}${\tt END;}$\\
\hspace*{1.5cm}${\tt A}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ PGCD}$\\
To execute the program you enter, for example, {\tt PGCD(45,75)}.\\
\item Recursive implementation\\
\noindent
${\tt \ll \ \rightarrow\ A,B \ }$\\
\hspace*{0.5cm}${\tt \ll IF \ B \ \neq \ 0\ THEN}$\\
\hspace*{1.5cm}${\tt PGCDR(B,A\ MOD \ B)}$\\
\hspace*{1cm}${\tt ELSE }$\\
\hspace*{1.5cm}${\tt A}$\\
\hspace*{1cm}${\tt END}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ PGCDR}$\\
To execute the program you enter, for example, {\tt PGCDR(45,75)}.\\
Notice:\\
If you use the symbolic function
{\tt IREMAINDER} instead of {\tt MOD} in the programs above,
{\tt PGCD} (or {\tt PGCDR})
can then have Gauss integers as arguments, too.
\end{itemize}
\subsection{B\'ezout identity using the Euclide's algorithm}
In this section, the function
{\tt Bezout(A,B)} returns the list \{U, V, GCD(A,B)\},
where {\tt U} and {\tt V} satisfy:
$ A \times U + B \times V = GCD(A,B). $
\subsubsection{Iterative implementation without lists}
The Euclide's algorithm allows us to find a pair U and V satisfying:\\
$ A \times U + B \times V= GCD(A,B) $\\
Actually, if we denote $A_0$ and $B_0$ the starting values of $A$ and $B$,
we have:
\begin{eqnarray*}
A & =A_0 \times U+B_0 \times V \ \mbox{ with }\ U=1 \ \mbox{ and }\
V=0 \\
B & =A_0 \times W+B_0 \times X \ \mbox{ with }\ W=0 \ \mbox{ and }\
X=1
\end{eqnarray*}
Next, we make
$A$, $B$, $U$, $V$, $W$, $X$ evolve so that the above relations
continue to be satisfied.\\
If:\\
$ A=B \times Q+R \ \ \ 0 \leq R < B \ \ ( R = A \ mod \ B \ and \
Q= E(A / B )) $\\
We can write:
\begin{eqnarray*}
R=A-B \times Q=A_0 \times (U-W \times Q)+B_0 \times (V-X \times Q)=\\
A_0 \times S+B_0 \times T \ \mbox{ with } \ S=U-W \times Q \ \mbox{ and } \
T=V-X \times Q
\end{eqnarray*}
We must now repeat the process with B in place of A
(B->A\ W->U \ X->V) and R in place of B (R->B \ S->W \ T->X ).
We can write the whole algorithm as follows:
\begin{verbatim}
function Bezout (A,B)
local U,V,W,X,S,T,Q,R
1->U 0->V 0->W 1->X\end{verbatim}
{\tt while B $\neq$ 0 do}\begin{verbatim}
A mod B->R
E(A/B)->Q
//R=A-B*Q
U-W*Q->S
V-X*Q->T
B->A W->U X->V
R->B S->W T->X
end while
return {U, V, A}
end function
\end{verbatim}
\subsubsection{Iterative implementation with lists}
The algorithm above can be simplified using less variables: in order
to do this, we introduce the lists LA, LB, and LR to store the terns
\{U, V, A\}, \{W, X, B\} and \{S, T, R\}.
\begin{verbatim}
function Bezout (A,B)
local LA LB LR
{1, 0, A}->LA
{0, 1, B}->LB\end{verbatim}
{\tt while LB[3] $\neq$ 0 do}\begin{verbatim}
LA-LB*E(LA[3]/LB[3])->LR
LB->LA
LR->LB
end while
return LA
end function
\end{verbatim}
\subsubsection{Recursive version with lists}
The Bezout function can be defined recursively by:
$ Bezout(A,0)=\{1,\ 0,\ A\} $
If $ B \neq 0 $ we must define $ Bezout(A,B)$ in function of
$ Bezout(B,R)$, where
$ R=A-B \times Q \ \mbox{ and } \ Q=E(A/B).$
We have:
\begin{eqnarray*} Bezout(B,R)=LT=\{W, X, gcd(B,R)\} \\
\mbox{ with }\ W \times B+X \times R=gcd(B,R)
\end{eqnarray*}
Therefore:
\begin{eqnarray*}
W \times B+X \times (A-B \times Q) & = & gcd(B,R) \ \mbox{ or, again,
} \\
X \times A+(W-X \times Q) \times B & = & gcd(A,B).
\end{eqnarray*}
So, if $B \neq 0$ and $ Bezout(B,R)=LT$ we have:
$ Bezout(A,B)=\{LT[2],\ LT[1]-LT[2] \times Q,\ LT[3]\}.$\\
\begin{verbatim}
function Bezout (A,B)
local LT Q R\end{verbatim}
{\tt if B $\neq$ 0 do}\begin{verbatim}
E(A/B)->Q
A-B*Q->R
Bezout(B,R)->LT
return {LT[2], LT[1]-LT[2]*Q, LT[3]}
else return {1, 0, A}
end if
end function
\end{verbatim}
\subsubsection{HP49G, RPN mode}
\begin{itemize}
\item Iterative implementation with lists.\\
At the very beginning,
A et B contain the two numbers for which we are seeking the B\'ezout
identity, later they denote the lists LA and LB mentioned in the algorithm.\\
\%\%HP: T(3)A(R)F(.);
${\tt \ll \{\}\ \rightarrow\ A\ B\ R}$\\
\hspace*{0.5cm}${\tt \ll \{1\ 0\}\ 'A'\ STO+}$\\
\hspace*{1cm}${\tt \{0\ 1\}\ 'B'\ STO+}$\\
\hspace*{1cm}${\tt WHILE\ B\ 3\ GET\ 0\ \neq\ REPEAT}$\\
\hspace*{1.5cm}{\tt A B A 3 GET B 3 GET / FLOOR * - 'R' STO}\\
\hspace*{1.5cm}{\tt B 'A' STO}\\
\hspace*{1.5cm}{\tt R 'B' STO}\\
\hspace*{1cm}{\tt END}\\
\hspace*{1cm}{\tt A}\\
\hspace*{1.5cm}${\tt \gg}$\\
${\tt \gg}$\\
\item Recursive implementation with lists\\
\%\%HP: T(3)A(R)F(.);
${\tt \ll \{\}\ \rightarrow\ A\ B\ T}$\\
\hspace*{0.5cm}${\tt \ll IF\ B\ 0\ \neq THEN}$\\
\hspace*{1.5cm}{\tt B A B MOD BEZOUR 'T' STO}\\
\hspace*{1.5cm}{\tt T 2 GET DUP A B / FLOOR *}\\
\hspace*{1.5cm}{\tt T 1 GET SWAP -}\\
\hspace*{1.5cm}{\tt T 3 GET {} + + +}\\
\hspace*{1cm}{\tt ELSE}\\
\hspace*{1.5cm}{\tt \{1 0\} A +}\\
\hspace*{1cm}{\tt END}\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg}$\\
This program must be stored into the variable {\tt BEZOUR}.
\end{itemize}
\subsubsection{HP49G, Algebraic mode}
\begin{itemize}
\item Iterative implementation with lists.\\
At the very beginning,
A et B contain the two numbers for which we are seeking the B\'ezout
identity, later they denote the lists LA and LB mentioned in the algorithm.\\
\noindent
${\tt \ll \ \rightarrow\ A,B \ }$\\
\hspace*{0.5cm}${\tt \ll \{\}\ \rightarrow\ R}$\\
\hspace*{1cm}${\tt \ll \{1,0,A\}\ STO \triangleright \ A;}$\\
\hspace*{1.5cm}${\tt \{0,1,B\}\ STO \triangleright \ B;}$\\
\hspace*{1.5cm}${\tt WHILE \ B[3]\ \neq \ 0 \ REPEAT}$\\
\hspace*{2cm}${\tt A-B*FLOOR(A[3]/B[3])\ STO \triangleright \ R;}$\\
\hspace*{2cm}${\tt B\ STO \triangleright \ A;}$\\
\hspace*{2cm}${\tt R\ STO \triangleright \ B}$\\
\hspace*{1.5cm}${\tt END}$\\
\hspace*{1.5cm}${\tt A}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ BEZOUT}$\\
To execute the program you type, for example, {\tt BEZOUT(45,75)}.\\
\item Recursive implementation with lists\\
\noindent
${\tt \ll \ \rightarrow\ A,B \ }$\\
\hspace*{0.5cm}${\tt \ll \{\}\ \rightarrow\ T}$\\
\hspace*{1cm}${\tt \ll IF \ B \ \neq \ 0 \ THEN}$\\
\hspace*{2cm}${\tt BEZOUR(B,A \ MOD \ B)\ STO \triangleright \ T;}$\\
\hspace*{2cm}${\tt \{T[2],T[1]-T[2]*FLOOR(A/B),T[3]\}}$\\
\hspace*{1.5cm}${\tt ELSE}$\\
\hspace*{2cm}${\tt \{1,0,A\}}$\\
\hspace*{1.5cm}${\tt END}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ BEZOUR}$\\
To execute the program you type, for example, {\tt BEZOUR(45,75)}.\\
Notice :\\
If you use the symbolic function
{\tt IREMAINDER} instead of {\tt MOD} in the programs above,
{\tt PGCD} (or {\tt PGCDR})
can then have Gauss integers as arguments, too.
\end{itemize}
\subsection{Factorization}
\subsubsection{Algorithms and their translations}
\begin{itemize}
\item First algorithm\\
We check, for all integers D from 2 to N, whether N is divided by D.\\
If D divides N, we search the factors of N/D ... and so on.\\
All factors are stored into the list FACT.
\begin{verbatim}
function facprem(N)
local D FACT
2 -> D
{} -> FACT\end{verbatim}
{\tt while N $\neq$ 1 do}
\begin{verbatim} if N mod D = 0 then
FACT + D -> FACT
N/D -> N
else
D+1 -> D
end if
end while
return FACT
end function
\end{verbatim}
\item First improvement\\
We only check potential factors between 2 and $E(\sqrt N).$
\begin{verbatim}
function facprem(N)
local D FACT
2 -> D
{} -> FACT\end{verbatim}
{\tt while D*D $\leq$ N do}
\begin{verbatim} if N mod D = 0 then
FACT + D -> FACT
N/D-> N
else
D+1 -> D
end if
end while
FACT + N -> FACT
return FACT
end function
\end{verbatim}
\item Second improvement\\
We check if 2 divides N, then we check only odd
potential factors D between 3 and $E(\sqrt N).$\\
In the FACT list, each factor is now followed by its exponent:\\
facprem(12)=\{2,2,3,1\}.
\begin{verbatim}
function facprem(N)
local K D FACT
{}->FACT
0 -> K
while N mod 2 = 0 do
K+1 -> K
N/2 -> N
end while\end{verbatim}
{\tt if K $\neq$0 then}
\begin{verbatim} FACT + {2 K} -> FACT
end if
3 ->D \end{verbatim}
{\tt while D*D $\leq$ N do}
\begin{verbatim} 0 -> K
while N mod D = 0 do
K+1 -> K
N/D -> N
end while\end{verbatim}
{\tt \ \ if K $\neq$0 then}
\begin{verbatim} FACT + {D K} -> FACT
end if
D+2 -> D
end while\end{verbatim}
{\tt if N $ \neq 1$ then}
\begin{verbatim}FACT + {N 1} -> FACT
end if
return FACT
end function
\end{verbatim}
\end{itemize}
\subsubsection{HP49G, RPN mode}
\%\%HP: T(1)A(R)F(.);
This is the translation of the second improvement:\\
${\tt \ll 0\ 3\ \{\}\ \rightarrow\ N\ K\ D\ FACT}$\\
\hspace*{0.5cm}${\tt \ll\ WHILE\ N\ 2\ MOD\ 0\ ==\ REPEAT}$\\
\hspace*{1.5cm} {\tt 1 'K' STO+ \\
\hspace*{1.5cm} 'N' 2 STO/\\
\hspace*{1cm} END\\
\hspace*{1cm} IF K 0 $\neq$ THEN\\
\hspace*{1.5cm} \{2 K\} 'FACT' STO\\
\hspace*{1cm} END\\
\hspace*{1cm} WHILE N D D * $\geq$ REPEAT\\
\hspace*{1.5cm} 0 'K' STO \\
\hspace*{1.5cm} WHILE N D MOD 0 == REPEAT\\
\hspace*{2cm} 1 'K' STO+\\
\hspace*{2cm} 'N' D STO/\\
\hspace*{1.5cm} END \\
\hspace*{1.5cm} IF K 0 $\neq$ THEN\\
\hspace*{2cm} \{D K\} 'FACT' STO+\\
\hspace*{1.5cm} END \\
\hspace*{1.5cm} 2 'D' STO+\\
\hspace*{1cm} END\\
\hspace*{1cm} IF N 1 $\neq$ THEN\\
\hspace*{1.5cm} \{N 1\} 'FACT' STO+\\
\hspace*{1cm} END}\\
${\tt \ \ \ \gg}$\\
${\tt \gg}$
\subsubsection{HP49G, algebraic mode}
\noindent
${\tt \ll \ \rightarrow\ N \ }$\\
\hspace*{0.5cm}${\tt \ll 0 \ \rightarrow\ K}$\\
\hspace*{1cm}${\tt \ll WHILE \ N\ MOD\ 2 \ ==\ 0 \ REPEAT}$\\
\hspace*{2cm}${\tt K+1 \ STO \triangleright \ K;}$\\
\hspace*{2cm}${\tt N/2\ STO \triangleright \ N}$\\
\hspace*{1.5cm}${\tt END;}$\\
\hspace*{1.5cm}${\tt \{\} \ \rightarrow\ FACTO}$\\
\hspace*{2cm}${\tt \ll IF \ K \neq \ 0\ THEN}$\\
\hspace*{3cm}${\tt FACTO+\{2,K\} \ STO \triangleright \ FACTO}$\\
\hspace*{2.5cm}${\tt END;}$\\
\hspace*{2.5cm}${\tt 3 \ \rightarrow\ D}$\\
\hspace*{3cm}${\tt \ll WHILE\ D*D \leq N \ REPEAT}$\\
\hspace*{4cm}${\tt 0 \ STO \triangleright \ K;}$\\
\hspace*{4cm}${\tt WHILE\ N \ MOD \ D\ == 0 \ REPEAT}$\\
\hspace*{4.5cm}${\tt K+1 \ STO \triangleright \ K;}$\\
\hspace*{4.5cm}${\tt N/D \ STO \triangleright \ N;}$\\
\hspace*{4cm}${\tt END;}$\\
\hspace*{4cm}${\tt IF \ K \neq \ 0\ THEN}$\\
\hspace*{4.5cm}${\tt FACTO+\{D,K\} \ STO \triangleright \ FACTO}$\\
\hspace*{4cm}${\tt END;}$\\
\hspace*{4cm}${\tt D+2 \ STO \triangleright \ D}$\\
\hspace*{3.5cm}${\tt END;}$\\
\hspace*{3.5cm}${\tt IF \ N \neq \ 1\ THEN}$\\
\hspace*{4cm}${\tt FACTO+\{N,1\} \ STO \triangleright \ FACTO}$\\
\hspace*{3.5cm}${\tt END;}$\\
\hspace*{3.5cm}${\tt FACTO;}$\\
\hspace*{3cm}${\tt \gg}$\\
\hspace*{2cm}${\tt \gg}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ FACTEUR}$\\
To execute the program you type, for example, {\tt FACTEUR(45)}.\\
\subsection{Calculation of $ A^P \ mod\ N$}\label{sec:puimod}
\subsubsection{Algorithmic language}
\begin{itemize}
\item First algorithm\\
We use local variables PUIS et I.\\
We make an iterative program so that at each step,
PUIS represents $A^I \ (\bmod \ N)$.
\begin{verbatim}
function puismod (A, P, N)
local PUIS, I
1->PUIS
for I from 1 to P do
A*PUIS mod N ->PUIS
end for
return PUIS
end function
\end{verbatim}
\item Second algorithm\\
We use only one local variable, PUI, but we update P so that
at each iteration step we always have:\\
$ result= PUI * A^P \ (\bmod \ N) $
\begin{verbatim}
function puismod (A, P, N)
local PUI
1->PUI
while P>0 do
A*PUI mod N ->PUI
P-1->P
end while
return PUI
end function
\end{verbatim}
\item Third algorithm\\
We can improve the previous program by noticing that:\\
$A^{2*P} = (A*A)^P $.\\
So, when P is even, the following is true:\\
$PUI*A^P = PUI*(A*A)^{P/2} \ (\bmod \ N)$\\
and when P is odd, the following is true:\\
$PUI*A^P = PUI*A*A^{P-1}\ (\bmod \ N)$.\\
The result is a fast algorithm to compute $ A^P \ (\bmod \ N) $.
\begin{verbatim}
function puismod (A, P, N)
local PUI
1->PUI
while P>0 do
if P mod 2 =0 then
P/2->P
A*A mod N->A
else
A*PUI mod N ->PUI
P-1->P
end if
end while
return PUI
end function
\end{verbatim}
We can also notice that if P is odd, then P-1 is even.\\
We can write:
\begin{verbatim}
function puismod (A, P, N)
local PUI
1->PUI
while P>0 do
if P mod 2 =1 then
A*PUI mod N ->PUI
P-1->P
end if
P/2->P
A*A mod N->A
end while
return PUI
end functions
\end{verbatim}
\item Recursive program\\
We can leverage the following recurrence relation:\\
$A^0=1\ \
A^{P+1} \ (\bmod \ N) =(A^P \ (\bmod\ N))*A \ (\bmod \ N)$
\begin{verbatim}
function puimod(A, P, N)
if P>0 then
return puimod(A, P-1, N)*A mod N
else
return 1
end if
end function
\end{verbatim}
\item Fast, recursive program\\
\begin{verbatim}
function puimod(A, P, N)
if P>0 then
if P mod 2 =0 then
return puimod(A*A, P/2, N)
else
return puimod(A, P-1, N)*A mod N
end if
else
return 1
end if
end function
\end{verbatim}
\end{itemize}
\subsubsection{HP49G, RPN mode}
The user must push on the stack :\\
A, P, N to obtain $A^P mod\ N$.\\
This is the translation of the fast, iterative algorithm:\\
${\tt \ll\ 1\ \rightarrow\ A\ P\ N\ PUI }$\\
\hspace*{0.5cm}${\tt \ll \ WHILE\ P\ 0\ >\ REPEAT}$\\
\hspace*{1.5cm} {\tt IF P 2 MOD 1 == THEN\\
\hspace*{2cm} A PUI * N MOD 'PUI' STO\\
\hspace*{2cm} 'P' STO- \\
\hspace*{1.5cm} END\\
\hspace*{1.5cm} P 2 / 'P' STO\\
\hspace*{1.5cm} A A * N MOD 'A' STO\\
\hspace*{1cm} END\\
\hspace*{1cm} PUI}\\
${\tt \ \ \ \gg}$\\
${\tt \gg}$
We can store the program into PUIMOD (using 'PUIMOD' STO).
\subsubsection{HP49G, Algebraic mode}
This is the translation of the fast, iterative algorithm:\\
${\tt \ll \ \rightarrow\ A\ P\ N \ }$\\
\hspace*{0.5cm}${\tt \ll 1 \ \rightarrow\ PUI}$\\
\hspace*{1cm}${\tt \ll WHILE \ P > 0 \ REPEAT}$\\
\hspace*{2cm}${\tt IF \ P\ MOD\ 2\ == 1\ THEN}$\\
\hspace*{2.5cm}${\tt A*PUI\ MOD\ N \ STO \triangleright \ PUI}$\\
\hspace*{2.5cm}${\tt P-1 \ STO \triangleright \ P;}$\\
\hspace*{2cm}${\tt END;}$\\
\hspace*{2cm}${\tt P/2 \ STO \triangleright \ P;}$\\
\hspace*{2cm}${\tt A*A \ MOD \ N \ STO \triangleright \ A;}$\\
\hspace*{1.5cm}${\tt END;}$\\
\hspace*{1.5cm}${\tt PUI}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ PUIMOD}$\\
We can type, for example, {\tt PUIMOD(45,32,13)} to execute it.\\
\subsection{The function ``isprime''}
\subsubsection{Algorithmic language}
\begin{itemize}
\item First algorithm
We are about to write a boolean function of N, returning TRUE if
N is prime, and FALSE if it is not.
In order to do this, we check whether N has a factor
$\neq$ 1 and $\leq$ $E(\sqrt{N})$ (integer part of the square root of N).
The special case $N=1$ is handled separately!
We use a boolean variable PREM, initially set to TRUE and changed
to be FALSE when we find a factor of N.
\begin{verbatim}
function isprime(N)
local PREM, I, J\end{verbatim}
{\tt E($\sqrt{N}$) ->J}
\begin{verbatim}if N = 1 then
FALSE->PREM
else
TRUE->PREM
end if
2->I\end{verbatim}
{\tt while PREM and I $\leq$J do}
\begin{verbatim} if N mod I = 0 then
FALSE->PREM
else
I+1->I
end if
end while
return PREM
end function
\end{verbatim}
\item First improvement
We notice that first of all, we can check if N is even and, if it is not,
only check whether it has odd factors.
\begin{verbatim}
function iswprime(N)
local PREM, I, J\end{verbatim}
{\tt E($\sqrt{N}$) ->J \\
if (N = 1) or (N mod 2 = 0) and N$\neq$2 then}\begin{verbatim}
FALSE->PREM
else
TRUE->PREM
end if
3->I\end{verbatim}
{\tt while PREM and I $\leq$J do}
\begin{verbatim} if N mod I = 0 then
FALSE->PREM
else
I+2->I
end if
end while
return PREM
end function
\end{verbatim}
\item Second improvement
We check if N cen be divided by 2 or by 3, else we check whether N
has a factor that can be expressed as either $6 \times k-1 $ or $6
\times k+1 $.
\begin{verbatim}
function isprime(N)
local PREM, I, J\end{verbatim}
{\tt E($\sqrt{N}$) ->J}
\begin{verbatim}if (N = 1) or (N mod 2 = 0) or ( N mod 3 = 0) then
FALSE->PREM
else
TRUE->PREM
end if
if N=2 or N=3 then
TRUE->PREM
end if
5->I\end{verbatim}
{\tt while PREM and I $\leq$J do}
\begin{verbatim} if (N mod I = 0) or (N mod I+2 =0) then
FALSE->PREM
else
I+6->I
end if
end while
return PREM
end function
\end{verbatim}
\end{itemize}
\subsubsection{HP49G, RPN mode}
We translate the last algorithm listed above: the result is either
0 (false) or 1 (true).\\
${\tt \ll\ DUP\ \sqrt{\ }\ FLOOR\ 0\ 5\ \rightarrow\ N\ J\ PREM\ I}$\\
${\tt \ \ \ll\ IF\ N\ 1\ ==\ N\ 2\ MOD\ 0\ =3D=3D\ OR\ N\ 3\ MOD\ 0\ ==\
OR\ THEN}$\\
\hspace*{1cm}{\tt 0 'PREM' STO\\
\hspace*{0.5cm} ELSE\\
\hspace*{1cm} 1 'PREM' STO\\
\hspace*{0.5cm} END\\
\hspace*{0.5cm} IF N 2 == N 3 == OR THEN\\
\hspace*{1cm} 1 'PREM' STO\\
\hspace*{0.5cm} END\\
\hspace*{0.5cm} WHILE PREM I J $\leq$ AND REPEAT\\
\hspace*{1cm} IF N I MOD 0 == N I 2 + MOD 0 == OR THEN\\
\hspace*{1.5cm} 0 'PREM' STO\\
\hspace*{1cm} ELSE \\
\hspace*{1.5cm} I 6 + 'I' STO\\
\hspace*{1cm} END\\
\hspace*{0.5cm}END\\
\hspace*{0.5cm}PREM}\\
${\tt \ \ \gg}$\\
${\tt \gg}$
\subsubsection{HP49G. Algebraic mode}
\noindent
${\tt \ll \ \rightarrow\ N \ }$\\
\hspace*{0.5cm}${\tt \ll 0 \ \rightarrow\ P}$\\
\hspace*{1cm}${\tt \ll IF \ N\ MOD\ 2\ == 0\ OR \ N\ MOD\ 3\ ==
0\ OR \ N==1 THEN}$\\
\hspace*{2cm}${\tt 0 \ STO \triangleright \ P}$\\
\hspace*{1.5cm}${\tt ELSE;}$\\
\hspace*{2cm}${\tt 1 \ STO \triangleright \ P;}$\\
\hspace*{1.5cm}${\tt END;}$\\
\hspace*{1.5cm}${\tt IF \ N == 2\ OR \ N == 3\ THEN}$\\
\hspace*{2cm}${\tt 1 \ STO \triangleright \ P;}$\\
\hspace*{1.5cm}${\tt END;}$\\
\hspace*{1.5cm}${\tt FLOOR( \sqrt N ) \ \rightarrow\ J}$\\
\hspace*{2cm}${\tt \ll 5 \ \rightarrow\ I}$\\
\hspace*{2.5cm}${\tt \ll WHILE \ I \leq J \ AND\ P \ REPEAT}$\\
\hspace*{3.5cm}${\tt IF \ N\ MOD\ I\ == 0 \ OR\ N\ MOD\ (I+2)\ ==
0 \ \ THEN}$\\
\hspace*{4cm}${\tt 0 \ STO \triangleright \ P;}$\\
\hspace*{3.5cm}${\tt ELSE;}$\\
\hspace*{4cm}${\tt I+6 \ STO \triangleright \ I;}$\\
\hspace*{3.5cm}${\tt END;}$\\
\hspace*{3cm}${\tt END;}$\\
\hspace*{3cm}${\tt P}$\\
\hspace*{2.5cm}${\tt \gg}$\\
\hspace*{2cm}${\tt \gg}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ PREM?}$\\
to execute this program you type, for example, {\tt PREM?(45789)}.\\
\subsection{Rabin's probabilistic method}\label{sec:rabin}
If N is prime, all integers K less that N are prime with N;
therefore, applying the Fermat theorem we can state that:
$ K^{N-1} = 1 \ (\bmod\ N)$
for all integers K less than N.
Instead, if N is not prime, integer values K satisfying:
$ K^{N-1} = 1 \ (\bmod\ N)$
are rare.\\
To be more precise, it can be shown that if
$ N>4 $, the probabilty to randomly find such an integer K
is less than 0.25.\\
An integer N satisfying $ K^{N-1} = 1 \ (\bmod\ N)$ for 20 random
trials of K is a preudo-prime integer.
The Rabin's probabilistic method consists of randomly generate
an integer K ($1< K < N $) and calculate :
$ K^{N-1} \ (\bmod\ N)$
If $ K^{N-1} = 1 \ (\bmod\ N)$ we repeat the process with a different
value of K; if, instead,
$ K^{N-1} \neq 1 \ (\bmod\ N)$ we are sure that N is not prime.
If $ K^{N-1} = 1 \ (\bmod\ N)$ for 20 random trials of K
we can state that N is prime with a small probability of error,
less than $0.25^{20}$, that is about $10^{-12}$.
Of course, this method is very fast, and is widely used to check
whether very big integers are pseudo-prime.
\subsubsection{Algorithmic language}
We assume that:
Hasard(N) returns a random integer between 0 and N-1.
We calculate:
$ K^{N-1} \ mod\ N$
using the fast power algorithm described above
(see page \pageref{sec:puimod}).
We denote as:
puismod(K, P, N) the function calculating and returning $ K^P \ mod\ N$.
\begin{verbatim}
function isprime(N)
local K, I, P
1->I
1->P
while P = 1 and I < 20 do
hasard(N-2)+2->K
puismod(K, N-1, N)->P
I+1->I
end while
if P =1 then
return TRUE
else
return FALSE
end if
end function
\end{verbatim}
\subsubsection{HP49G, RPN mode}
\%\%HP: T(3)A(R)F(.);
We assume that the function
PUIMOD, taking from the stack three arguments
A, K, N, and returning $A^K mod \ N$ is already available.\\
${\tt \ll\ 1\ 0\ 1\ \rightarrow\ N\ I\ K\ P}$\\
${\tt \ \ \ll\ 0\ RDZ}$\\
\hspace*{0.5cm}{\tt WHILE P 1 == 20 I > AND REPEAT\\
\hspace*{1cm} 1 'I' STO+\\
\hspace*{1cm}RAND N 2 - * FLOOR 2 + 'K' STO\\
\hspace*{1cm}K N 1 - N PUIMOD 'P' STO\\
\hspace*{0.5cm}END \\
\hspace*{0.5cm}IF P 1 == THEN\\
\hspace*{1cm} 1\\
\hspace*{0.5cm} ELSE\\
\hspace*{1cm} 0\\
\hspace*{0.5cm}END}\\
${\tt \ \ \gg}$\\
${\tt \gg}$
\subsubsection{HP49G, Algebraic mode}
\noindent
${\tt \ll \ \rightarrow\ N \ }$\\
\hspace*{0.5cm}${\tt \ll 1 \ \rightarrow\ I}$\\
\hspace*{1cm}${\tt \ll 0 \ \rightarrow\ K}$\\
\hspace*{1.5cm}${\tt \ll 1 \ \rightarrow\ P}$\\
\hspace*{2cm}${\tt \ll RDZ(0);}$\\
\hspace*{2.5cm}${\tt WHILE \ P == 0 \ AND \ I<20 \ REPEAT}$\\
\hspace*{3cm}${\tt 1+I \ STO \triangleright \ I;}$\\
\hspace*{3cm}${\tt FLOOR((N-2)*RAND)+2 \ STO \triangleright \ K;}$\\
\hspace*{3cm}${\tt PUIMOD(K,N-1,N) \ STO \triangleright \ P;}$\\
\hspace*{2.5cm}${\tt END;}$\\
\hspace*{2.5cm}${\tt IF \ P == 1\ THEN}$\\
\hspace*{3cm}${\tt 1}$\\
\hspace*{2.5cm}${\tt ELSE}$\\
\hspace*{3cm}${\tt 0}$\\
\hspace*{2.5cm}${\tt END;}$\\
\hspace*{2.5cm}${\tt P}$\\
\hspace*{2cm}${\tt \gg}$\\
\hspace*{1.5cm}${\tt \gg}$\\
\hspace*{1cm}${\tt \gg}$\\
\hspace*{0.5cm}${\tt \gg}$\\
${\tt \gg \ STO \triangleright \ RABIN}$\\
To execute this program you can type, for example,
{\tt RABIN(45313)}.\\
Notice: \\
We can also use the built-in command {\tt POWMOD} and write:\\
\begin{itemize}
\item In {\tt RPN} mode:\\
{\tt N MODSTO\\
K N 1 - POWMOD 'P' STO}\\
instead of:\\
{\tt K N 1 - N PUIMOD 'P' STO}\\
\item In {\tt Algebraic mode} :\\
{\tt MODSTO(N);\\
POWMOD(K,N-1) STO$\triangleright$ P}\\
instead of:\\
{\tt PUIMOD(K,N-1,N) STO$\triangleright$ P}\\
\end{itemize}
\newpage
\printindex
\newpage
\tableofcontents
\end{document}
**