%
% $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<B$$
Type:
$${\tt  PROPFRAC(43 \div 12)}$$
You obtain:
$${\tt 3+\frac{7}{12}}$$

\subsubsection{\tt FXND}\index{FXND}
{\tt FXND} has a fraction as argument, and returns a list containing
the fraction's numerator and denominator simplified.\\
Type:
$${\tt  FXND(42 \div 12)}$$
You obtain:
$${\tt \{7,2\}}$$

\subsubsection{\tt SIMP2}\index{SIMP2}
{\tt SIMP2} (see \ref{sec:simp2}) has a list of two integers
representing a fraction as argument and, like {\tt FXND},
returns a list containing
the fraction's numerator and denominator simplified.\\
Type:
$${\tt  SIMP2(\{42 , 12\})}$$
You obtain:
$${\tt \{7,2\}}$$


\subsection{Reals}
Type:
$${\tt EXP(\pi*\sqrt{20})}$$
followed by {\tt ENTER}; the answer is:
$${\tt EXP(2*\sqrt5*\pi)}$$
with {\tt red-shift ENTER ($\rightarrow$NUM)} the answer is:
$$1263794.7537$$


\subsection{Complex numbers}
Type:
$${\tt (1+2.i)^2}$$
follower by {\tt ENTER}.

If you aren't in {\tt complex} mode, the calculator asks for a mode
change: you should answer  {\tt yes} to obtain the answer:
$${\tt -(3-4 \cdot i)}$$

Notice that this expression is not simplified beforehand
(all results always put in evidence complex numbers with
a positive real part in exact mode).\\

In the {\tt red-shift 1 (CMPLX)} menu you will find the
following functions, having a complex-valued expression
as argument:\\
{\tt ARG}\index{ARG} returns the argument of its input.\\
{\tt ABS}\index{ABS} returns the modulo of its argument.\\
{\tt CONJ}\index{CONJ} returns the conjugate of its argument.\\
{\tt RE}\index{RE} returns the real part of its argument.\\
{\tt IM}\index{IM} returns the imaginary part of its argument.\\
{\tt NEG}\index{NEG} returns the opposite of its argument.\\
{\tt SIGN}\index{SIGN} returns the quotient between its argument
and its argument's modulo.\\
For example:\\
Type:\\
$${\tt ARG(3+4 \cdot i)}$$
you obtain:\\
$${\tt ATAN(\frac{4}{3})}$$


\subsection{Algebraic expressions}
\subsubsection{\tt FACTOR}\index{FACTOR}
{\tt FACTOR} factorizes the expression given as argument.\\
Example:\\
Factorize
$$x^4+1$$
Type:
$${\tt FACTOR(X^4+1)}$$
You can find {\tt FACTOR} in the {\tt ALG \ (red-shift 4)} menu
(or you can type it in $\alpha$ mode).\\
In real mode, the answer is:
$${\tt (X^2+\sqrt2 \cdot X+1) \cdot (X^2-\sqrt2 \cdot X+1)} $$
In complex mode (to enable this mode, press
{\tt MODE}, then the {\tt cas} menu key, then check the {\tt complex}
field with {\tt chk} and press {\tt ok ok}) the answer is:
$${\tt \frac{ (2 \cdot X+(1+i) \cdot \sqrt 2) \cdot
(2 \cdot X-(1+i) \cdot \sqrt 2) \cdot (2 \cdot X+(1-i) \cdot \sqrt 2) \cdot
(2 \cdot X-(1-i) \cdot \sqrt 2)}{16}}$$

\subsubsection{\tt EXPAND\protect\index{EXPAND} EVAL\protect\index{EVAL}}
{\tt EXPAND} and {\tt EVAL} have an expression as argument;
they expand and simplify their input.\\
Example:\\
Doing ${\tt EXPAND(ANS(1))}$, you obtain again $${\tt X^4+1}.$$

\subsubsection{\tt SUBST}\index{SUBST}
{\tt SUBST} has two arguments: an expression depending on a parameter,
and an equality (parameter=substitution value).\\
{\tt SUBST} does the commanded substitution in the input expression,
and returns the result.\\
Type:\\
$${\tt SUBST(A^2+1,A=2)}$$
You obtain:\\
$$2^2+1$$

\subsubsection{\tt PREVAL}\index{PREVAL}
{\tt PREVAL} has three arguments: an expression ({\tt F(VX)})
depending on the variable stored in {\tt VX}
and two expressions: {\tt A } and {\tt B }.\\
{\tt PREVAL} evaluates {\tt F(B)-F(A)}.\\
{\tt PREVAL} is useful to compute a definite integral given an
antiderivative: you evaluate the antiderivative between the upper and
lower limits of the integral.\\
Type:\\
$${\tt PREVAL(X^2+X,2,3)} $$
You obtain:\\
$$12-6$$


\subsection{Functions}
\subsubsection{\tt  DERVX}\index{DERVX}
Let $f(x)$ be: $$f(x)=\frac {x}{x^2-1}+\ln(\frac {x+1}{x-1})$$
Determine the derivative of $f$.

You can find {\tt DERVX} in the menu:\\
{\tt CALC \ (blue-shift 4)}, sub-menu
{\tt 1.DERIV. \& INT...}, third position
(or you can type it in mode $\alpha$).\\

Type either:
$${\tt DERVX(\frac {X}{X^2-1}+LN(\frac {X+1}{X-1}))} $$
or, if you have previosuly stored $ f(x)$ into {\tt F}:
$${\tt DERVX(F) }$$
or, if you have defined $ F(X)$ using {\tt DEFINE}:
(${\tt DEFINE (F(X)=\frac {X}{X^2-1}+LN(\frac {X+1}{X-1}))}$)
$${\tt DERVX(F(X)) }$$

The result is an involved expression that you can simplify
by copying it into the command line
(${\tt \triangle\  ENTER\ ENTER)}$).\\
You obtain:
$${\tt -\frac {3 \cdot X^2-1}{X^4-2 \cdot X^2+1}} $$

\subsubsection{\tt  DERIV}\index{DERIV}
{\tt  DERIV} has two arguments: an expression (or a functions),
and a variable (or a vector containing more than one variable name)
(see multivariate functions, paragraph \ref{sec:deriv}).\\
{\tt  DERIV} returns the derivative of the expression
(or function) with respect to the given variable(s) (useful
to calculate partial derivatives!).\\
Example: \\
Suppose you should calculate:
$$\frac {\partial (x \cdot y^2 \cdot z^3+x \cdot y)}{\partial z}$$
Type:
$${\tt  DERIV(X \cdot Y^2 \cdot Z^3+X \cdot Y\ ,\ Z)}$$
You obtain:
$${\tt 3 \cdot X \cdot Y^2 \cdot Z^2}$$

\subsubsection{\tt  INTVX}\index{INTVX}
Let $f(x)$ be: $$f(x)=\frac {x}{x^2-1}+\ln(\frac {x+1}{x-1})$$
Determine an antiderivative of $f$.\\
You can find {\tt INTVX} in the {\tt CALC \ (blue-shift 4)} menu,
{\tt 1. DERIV. \& INT...} sub-menu, eighth position
(or you can type it in $\alpha$ mode).\\
You type either:
$${\tt INTVX(\frac {X}{X^2-1}+LN(\frac {X+1}{X-1}))} $$
or, if you have previously stored $f(x)$ into {\tt F}:
$${\tt INTVX(F)} $$
or, if you have defined $ F(X)$ using {\tt DEFINE}
 ($ {\tt DEFINE (F(X)=\frac {X}{X^2-1}+LN(\frac {X+1}{X-1})}$):
$${\tt INTVX(F(X)) }$$
You obtain:
$$ {\tt X \cdot LN(\frac {X+1}{X-1})+ \frac{3}{2} \cdot LN(|X-1|)+\frac{3=
}{2} \cdot LN(|X+1|)} $$
Exercise 1\\
Calculate:
$$\int \frac {2}{x^6+2 \cdot x^4+x^2} \ dx $$
Type:
$${\tt INTVX(\frac {2}{X^6+2 \cdot X^4+X^2})}$$
You obtain:
$${\tt -3 \cdot ATAN(X)-\frac {2}{X}-\frac {X}{X^2+1}} $$
Notice:\\
 You can also enter the expression using the equation writer
({\tt EQW} key):
$${\tt \int_1^X \frac {2}{X^6+2 \cdot X^4+X^2} \ dX} $$
This gives the same result, barring an integration constant
equal to 
$$\frac{3 \cdot \pi+10}{4}$$
Exercise 2\\
Calculate:
$$\int \frac {1}{\sin(x)+\sin(2 \cdot x )} \ dx $$
Type:
$${\tt INTVX(\frac {1}{SIN(X)+SIN(2 \cdot X )})}$$
You find:
 $${\tt -\frac {1}{6} \cdot LN(|COS(X)-1|)+\frac {1}{2} \cdot LN(|COS(X)+
1|)+\frac {-2}{3} \cdot LN(|2 \cdot COS(X)+1|)-LN(2)} $$

\subsubsection{\tt  LIMIT}\index{LIMIT}
Find, for $n>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])<deg(B[X])$.\\
Type:
$${\tt  PROPFRAC(\frac{(5 \cdot X+3) \cdot (X-1)}{X+2})}$$
You obtain:
$${\tt 5 \cdot X-12+\frac{21}{X+2}}$$

\subsubsection{\tt PARTFRAC}\index{PARTFRAC}
To decompose into partial fractions a rational fraction like
$$\frac{x^5-2 \times x^3+1}{x^4-2\times x^3+2\times x^2-2\times x+1}$$
you can use the {\tt PARTFRAC} command.\\
You can find this command in the
{\tt ARITH (blue-shift 1)} menu, sub-menu {\tt 2.POLYNOMIAL...},
position 14 (or you can type it in $\alpha$ mode).\\
Type:
$${\tt PARTFRAC(\frac{X^5-2*X^3+1}{X^4-2*X^3+2*X^2-2*X+1})}$$
In real mode, you obtain:
$${\tt X+2+\frac{\frac{-1}{2}}{X-1}+\frac{\frac{X-3}{2}}{X^2+1} }$$
In complex mode, you obtain instead:
$${\tt X+2+\frac{\frac{1-3.i}{4}}{X+i}+
\frac{\frac{-1}{2}}{X-1}+\frac{\frac{1+3.i}{4}}{X-i} }$$


\subsection{Modular calculations}
You can do calculations ``modulo {\tt p}'', that is,
in either $Z/pZ$ or $Z/pZ[X]$.\\
Warning: for some commands,  {\tt p} must be a prime number.\\
The calculator uses the symmetrical representation of elements
(-1 instead of 6 modulo 7).\\
The value of {\tt p} must be stored into the
{\tt MODULO} variable in the {\tt HOME} directory.\\
{\sc All the following examples assume that {\tt p=13}}.

\subsubsection{\tt MODSTO}\index{MODSTO}
To store into {\tt MODULO} the value of {\tt p} (for example {\tt p=13})
you can use either:\\
{\tt MODE cas MODULO ...}, or
${\tt 13\  STO\triangleright MODULO}$
(if the current directory is {\tt HOME}), or {\tt MODSTO(13)}.\\
{\tt MODSTO} allows you to change the value of the {\tt MODULO}
variable in the {\tt HOME} directory.\\
For example, you will type:
${\tt MODSTO(5)}$ or ${\tt 5\  STO\triangleright  MODULO}$
to do your calculations modulo 5.\\
{\sc All the following examples assume that {\tt p=13}}.

\subsubsection{\tt ADDTMOD}\index{ADDTMOD}
{\tt ADDTMOD} performs an addition in $Z/pZ[X]$.\\
Type:
$${\tt ADDTMOD(11X+5,8X+6)}$$
You obtain:
$${\tt 6X-2}$$

\subsubsection{\tt SUBTMOD}\index{SUBTMOD}
{\tt SUBTMOD} peforms a subtraction in $Z/pZ[X]$.\\
Type:
$${\tt SUBTMOD(11X+5,8X+6)}$$
You obtain:
$${\tt 3X-1}$$

\subsubsection{\tt MULTMOD}\index{MULTMOD}
{\tt MULTMOD} performs a multiplication in $Z/pZ[X]$.\\
Type:
$${\tt MULTMOD(11X+5,8X+6)}$$
You obtain:
$${\tt -(3X^2-2X-4)}$$

\subsubsection{\tt DIV2MOD}\index{DIV2MOD }
The arguments of {\tt DIV2MOD} are two polynomials $A[X]$ and $ B[X]$.
The result is a list containing both
the quotient and the remainder of the euclidean division
of $A[X]$ by $B[X]$ in $Z/pZ[X]$.\\
Type:
$${\tt DI2VMOD(X^3+X^2+1,2X^2+4)}$$
Since:
$$X^3+X^2+1=(2X^2+4) \cdot (\frac{X+1}{2})+\frac{5X-4}{4}$$
you obtain:
$${\tt \{ \frac{X+1}{2} \ ,\  \frac{5X-4}{4}\}} $$
Then, with $${\tt EXPANDMOD( \{ \frac{X+1}{2} \ , \ \frac{5X-4}{4}\})}$$
you obtain:
$${\tt \{-(6X+6)\ ,\  -(2X+1)\}}$$

\subsubsection{\tt DIVMOD}\index{DIVMOD}
The arguments of {\tt DIVMOD} are two polynomials $A[X]$ and $ B[X]$.
The result is the rational fraction $\frac{A[X]}{B[X]}$
simplified in $Z/pZ[X]$.\\
Type:
$${\tt DIVMOD(2X^2+5,5X^2+2X-3)}$$
You obtain:
$${\tt \frac{5X+3}{6X+6}} $$

\subsubsection{\tt POWMOD}\index{POWMOD}
{\tt POWMOD(X,N)} returns {\tt X} raised to {\tt N} in $Z/pZ[X]$.\\
The current value ${\tt p}$ of {\tt MODULO} must be a prime number
less than 100.\\
Type:
$${\tt POWMOD(2X+1,5)}$$
You obtain:
$${\tt 6 \cdot X^5+2 \cdot X^4+2 \cdot X^3+X^2-3 \cdot X+1}$$
because:\\
 $10=-3 \ (\bmod\ 13) \ \  40=1\ (\bmod\ 13)\ \   80=2 \ (\bmod\ 13=
)\ \ 32=6\ (\bmod\ 13)$.

\subsubsection{\tt INVMOD}\index{INVMOD}
{\tt INVMOD} has an integer as argument.\\
{\tt INVMOD} returns the reciprocal of this integer in $Z/pZ$.\\
Type:
$${\tt INVMOD(5)}$$
You obtain (since $5\times-5=-25=1\ (\bmod\ 13)$) :
$${\tt -5}$$

\subsubsection{\tt GCDMOD}\index{GCDMOD}
{\tt GCDMOD} has two polynomials as arguments.\\
{\tt GCDMOD} returns the GCD of the polynomials in $Z/pZ[X]$.\\
Type:
$${\tt GCDMOD(2X^2+5,5X^2+2X-3)}$$
You obtain:
$${\tt -(4X-5)}$$

\subsubsection{\tt EXPANDMOD}\index{EXPANDMOD}
{\tt EXPANDMOD} has a polynomial expression as argument.\\
{\tt EXPANDMOD} expands this expression in $Z/pZ[X]$.\\
Type:
 $${\tt EXPANDMOD(( 2X^2+12).( 5X-4))}$$
You obtain:
$${\tt -(3X^3-5X^2+5X-4)}$$

\subsubsection{\tt FACTORMOD}\index{FACTORMOD}
{\tt FACTORMOD} has a polynomial as argument.\\
{\tt FACTORMOD} factorizes the polynomial in $ Z/pZ[X]$
if $p \leq 97$ and $p$ is prime.\\
Type:
$${\tt FACTORMOD(-(3X^3-5X^2+5X-4))}$$
You obtain:
$${\tt -((3X-5)(X^2+6))}$$

\subsubsection{\tt RREFMOD}\index{RREFMOD}
{\tt RREFMOD} solves a system of linear equations
$AX=B$ in $Z/pZ$.\\
The argument is the matrix $A$ augmented with the vector $B$ as
its rightmost column.  The result is a matrix composed of $A1$ and $B1$,
where $A1$ has zeros both above and under its principal diagonal,
and the system $A1X=B1$ is equivalent to $AX=B$.\\
Type:
$${\tt RREFMOD([[1, 2, 9][3,10,0]])}$$
to solve
$$\left \{\begin{array}{lcr}\ \  x\ +\ \  2 \cdot y & = &9 \\3 \cdot x+10
\cdot y & =& 0 \end{array}\right.$$
You obtain:
$${\tt \left [ \begin{array}{rrr}2 & 0 & 6\\0 & 4 & -1 \end{array} \right]}$$
that is, ${\tt 2.X=6} $ and ${\tt 4.Y=-1}$ or, which is the same,
${\tt X=3 \ \ Y=3}$ (since $-4*3=1 \ (\bmod 13)$).

\subsection{Limited and asymptotic expansions}
\subsubsection{\tt DIVPC}\index{DIVPC}
{\tt DIVPC} has three arguments: two polynomials
${\tt A(X),\ B(X)}$ (with ${\tt B(0) \neq 0}$) and an integer ${\tt n}$.\\
{\tt DIVPC} returns the quotient ${\tt Q(X)}$ of the division of ${\tt A(X)}$
by ${\tt B(X)}$, with  deg${\tt (Q )\leq n}$ or ${\tt Q=0}$.\\
That is, $Q[X]$ is the series expansion, limited to order $n$,
of $\frac{A[X]}{B[X]}$ about $X=0$.\\
Type:
$${\tt DIVPC(1+X^2+X^3,1+X^2,5)}$$
You obtain:
$${\tt 1+X^3-X^5}$$
Warning: the calculator demands to enable the ``increasing powers'' mode;
answer {\tt yes} to proceed.

\subsubsection{\tt TAYLOR0}\index{TAYLOR0}
{\tt TAYLOR0} has only one argument: a function of $x$ to be expanded,
and returns its Taylor expansion, limited to relative order 4, about
$x=0$ (where $x$ is the current CAS variable).\\
Type:
$${\tt TAYLOR0(\frac{TAN(P \cdot X)-SIN(P \cdot X)}
{TAN(Q \cdot X)-SIN(Q \cdot X)}) }$$
You obtain:
$${\tt \frac{P^5-Q^2 \cdot P^3}{4 \cdot Q^3} \cdot X^2+\frac{P^3}{Q^3}}$$
Warning: ``relative order 4'' means to expand up to relative order 4
both numerator and denominator (here, absolute order 5 for both
numerator and denominator); this gives an expansion of
order 2 (5-3), because $X^3$ can be factored out in both the expanded
numerator and denominator.

\subsubsection{\tt TAYLR }\index{TAYLR }
Determine a limited Taylor expansion of order 2 near $x=0$ of:
$$ \frac{3\times \tan(x)-\tan(3\times x)}{x\times (1-\cos(3\times x))}$$

Since the denominator has order 3, to obtain a limited expansion of order
2 about $x=0$, it is necessary to expand the numerator near $x=0$
up to order 5. To do this, use the {\tt TAYLR} command; you can find it
in the {\tt CALC \ (blue-shift 4)} menu, sub-menu {\tt 2. LIMITS \& SER...}
at position 5 (or you can type it in $\alpha$ mode).\\
{\tt TAYLR} is compatible with the HP48.\\
Type:
$${\tt TAYLR( \frac{3 \cdot TAN(X)-TAN(3 \cdot X)}
{X \cdot (1-COS(3 \cdot X))} , X , 5)}$$
You obtain:
$${\tt -\frac{16}{9} \cdot (1+\frac{19}{4} \cdot X^2)  }$$

\subsubsection{\tt SERIES}\index{SERIES}
\begin{itemize}
\item expansion about {\tt x=a}\\
Example:\\
Determine a series expansion limited to order 4 about
$x=\frac{\pi}{6}$ of $\cos(2\times x)^2$.

You use the {\tt SERIES} command; you can find it
in the {\tt CALC \ (blue-shift 4)} menu, position 8
(or you can type it in $\alpha$ mode).

Type:
$${\tt SERIES( COS(2 \cdot X)^2 , X=\frac{\pi}{6} , 4 )}$$
You obtain:
$${\tt \{ \{Limit: \frac{1}{4} \ \ Equiv: \frac{1}{4} }$$
$${\tt Expans: \ (- \frac {8}{3}h^4+\frac {8 \sqrt {3}}{3}h^3+2h^2- \sqrt=
 3 h+ \frac{1}{4}})$$
$${\tt Remain: \  \frac  {h^5}{4} \} \ h=X- \frac{ \pi}{6}\}}$$

\item expansion about {\tt x=+$\infty$} or  {\tt x=-$\infty$}\\
Example 1:\\
Determine an expansion of $\arctan(x)$, of order 5, about
{\tt x=+$\infty$}, assuming $h=\frac{1}{x}$.\\
Type:
$${\tt SERIES(ATAN(X),X=+\infty,5)}$$
You obtain:
$${\tt \{ \{Limit: \frac{\pi}{2} \ Equiv: \frac{\pi}{2}}$$
$${\tt Expans:\ (\frac{\pi}{2}-h+\frac{h^3}{3}-\frac{h^5}{5})\ 
Remain: \frac{\pi h^6}{2}\}\ h=\frac{1}{X}\}}$$
Example 2 :\\
Determine an expansion of $(2x-1)e^\frac{1}{x-1}$, of order 2,
about {\tt x=+$\infty$}, assuming $h=\frac{1}{x}$.\\
Type:
$${\tt SERIES((2X-1) \cdot EXP(\frac{1}{X-1}),X=+\infty,3)}$$
You obtain:
$${\tt \{ \{Limit: +\infty \ Equiv: \frac{2}{h}}$$
$${\tt Expans:\ (\frac{2+h+2h^2+\frac{17h^3}{6}}{h})\ Remain: 2h^3\}\ 
h=\frac{1}{X}\}}$$
Example 3 :\\
Determine en expansion of $(2x-1)e^\frac{1}{x-1})$, of order 2,
about {\tt x=-$\infty$}, assuming $h=-\frac{1}{x}$.\\
Type:
$${\tt SERIES((2X-1) \cdot EXP(\frac{1}{X-1}),X=-\infty,3)}$$
You obtain:
$${\tt \{ \{Limit: -\infty \ Equiv: -\frac{2}{h}}$$
$${\tt Expans:\ (\frac{-2+h-2h^2+\frac{17h^3}{6}}{h})\ Remain: -2h^3\}\ 
h=-\frac{1}{X}\}}$$
\item unidirectional expansions\\
You must give a positive real number (for example 4.) as the order to do
an unidirectional expansion about the point $x=a$ with $ \ x>a$,
and a negative real number (for example -4.) to do
an unidirectional expansion about $x=a$ with $ \ x<a$ .\\
Example 1 :\\
Determine an expansion of
$\ \frac{(1+X)^\frac{1}{X}}{X^3}\ $, of order 2, about $X=0^+$.\\
Type:
$${\tt SERIES(\frac{(1+X)^\frac{1}{X}}{X^3} ,X,2.)}$$
You obtain:
$${\tt \{ \{Limit: +\infty \ Equiv: \frac{e}{h^3}\ Expans:\ 
(-\frac{e \cdot h-2 \cdot e}{2 \cdot h^3})\ Remain: \frac{e}{h}\}\  h=X\}}$$
Example 2:\\
Determine an expansion of
$\ \frac{(1+X)^\frac{1}{X}}{X^3}\ $, of order 2, about $X=0^-$.\\
Type:
$${\tt SERIES(\frac{(1+X)^\frac{1}{X}}{X^3} ,X,-2.)}$$
You obtain:
$${\tt \{ \{Limit: -\infty \ Equiv: \frac{e}{h^3}\ Expans:\ 
( -\frac{e \cdot h-2 \cdot e}{2 \cdot h^3})\ Remain: \frac{e}{h}\}\ h=X\}}$$
Example 3 :\\
Determine an expansion of $\ \frac{(1+X)^\frac{1}{X}}{X^3}\ $, of order 2,
about  $X=0$.\\
Type:
$${\tt SERIES(\frac{(1+X)^\frac{1}{X}}{X^3} ,X,2)}$$
You obtain:
$${\tt \{ \{Limit: \infty \ Equiv: \frac{e}{h^3}\ Expans:\ 
( -\frac{e \cdot h-2 \cdot e}{2 \cdot h^3})\ Remain: \frac{e}{h}\}\ h=X\}}$$
\end{itemize}

\subsubsection{\tt LIMIT}\index{LIMIT}
{\tt LIMIT} has as arguments an expression depending on a variable,
and an equality (the variable equated to the value at which you want
to calculate the limit of the expression).\\

Often, it is better to surrond the expression with quotes,
to avoid a preliminary transformation of the expression into normal
form (thus, avoiding a rational simplification) before the
limit computation actually takes place.\\
For example, type:
$${\tt LIMIT('(2X-1) \cdot EXP(\frac{1}{X-1})',X=+\infty)}$$
You obtain:
$$+\infty$$

\subsection{Matrices}
\subsubsection{\tt TRAN}\index{TRAN}
{\tt TRAN} has a matrix $A$ as argument.\\
{\tt TRAN} returns the input matrix $A$ transposed.\\
Type:
$${\tt TRAN(\left[\begin{array}{cc} 1& 2\\3&4\end{array}\right])}$$
You obtain:
$${\tt \left[\begin{array}{cc} 1& 3\\2&4\end{array}\right]}$$

\subsubsection{\tt TRN}\index{TRN}
{\tt TRN} has a matrix $A$ as argument.\\
{\tt TRN} returns the adjoint of $A$
(transpose of the conjugate) of $A$ (this is the HP48 command).\\
Type:
$${\tt TRN(\left[\begin{array}{cc} i& 1+i\\1&1-i\end{array}\right])}$$
After simplification, you obtain:
$${\tt \left[\begin{array}{cc} -i& 1\\1-i&1+i\end{array}\right]}$$

\subsubsection{\tt MAD}\index{MAD}
{\tt MAD } has a square matrix $A$, of order $n$, as argument.\\
{\tt MAD } returns a list containing
the determinant of $A$,
the inverse of $A$, 
a list containing the matrix coefficients of a polynomial $Q$,
and of the characteristic poloynomial $P$ of $A$.\\
We have:
$$P(x)=(-1)^n \cdot \det(A-x \cdot I)$$
The polynomial with matrix coefficients $P(A)-P(x) \cdot I$
is divisible by $A-x \cdot I$ (since its value is zero for $x=A$).
Let $Q(x)$ be their quotient.\\
Since $P(A)=0$, we have $\ P(A)-P(x) \cdot I\ =\ -P(x) \cdot I\ =\ 
(A-x \cdot I) \cdot Q(x)$.\\
Therefore, $Q(x)$ is also the co-matrix of $A-x \cdot I$
and the following holds:\\
$Q(x)\ =\ I \cdot x^{n-1}+...+B_0 $, where $B_0$ is the co-matrix of $A$
(with the sign exchanged if $n$ is even!).\\
Type:
$${\tt MAD(\left[\begin{array}{ccc} 4&1& -2\\1&2&-1\\2&1&0
\end{array}\right])}$$
You obtain:
$${\tt \{8,
\left[
\begin{array}{ccc}
\frac{1}{8}&-\frac{1}{4} &\frac{3}{8}\\
\frac{1}{4}&\frac{1}{2}&\frac{1}{4} \\
-\frac{3}{8}&-\frac{1}{4}&\frac{7}{8}
\end{array}
\right],}$$
$${\tt \{\left[
\begin{array}{ccc}
1&0& 0\\0&1&0\\0&0&1
\end{array}
\right],
\left[\begin{array}{ccc} -2&1& -2\\1&-4&-1\\2&1&-6 \end{array}\right],
\left[\begin{array}{ccc} 1&-2& 3\\-2&4&2\\-3&-2&7 \end{array}\right]\},}
$$
$${\tt X^3-6 \cdot X^2+12 \cdot X-8\}}$$

\subsubsection{\tt HADAMARD}\index{HADAMARD}
{\tt HADAMARD} has two matrices $A$ and $B$, with the same size,
as arguments.\\
{\tt HADAMARD} returns the element-by-element product between
$A$ and $B$.\\
Type:
$${\tt HADAMARD(\left[\begin{array}{cc} 1& 2\\3&4\end{array}\right],\left
[\begin{array}{cc} 5& 6\\7&8\end{array}\right])}$$
You obtain:
$${\tt \left[\begin{array}{cc} 5& 12\\21&32\end{array}\right]}$$

\subsubsection{\tt AXM}\index{AXM}
If given a symbolic matrix as argument,
{\tt AXM} returns an equivalent (but approximate) numeric matrix,
and vice versa.\\
Type:
$${\tt AXM([[1/2,2],[3,4]])}$$
You obtain:
$${\tt[[0.5,2],[3,4]]}$$

\subsubsection{\tt AXL}\index{AXL}
When {\tt AXL} is given a matrix as argument,
it returns the same matrix rewritten as a list of lists.
Vice versa, {\tt AXL} transforms a list of lists into a matrix.\\
Type:
$${\tt AXL([[1,2],[3,4]])}$$
You obtain:
$${\tt \{\{1,2\}\{3,4\}\}}$$
Type:
$${\tt AXL( \{\{1,2\}\{3,4\}\})}$$
You obtain:
$${\tt[[1,2],[3,4]]}$$

\subsubsection{\tt EGVL}\index{EGVL}
{\tt EGVL} has a matrix $A$, of order $n$, as argument.\\
{\tt EGVL} returns a vector containing the $n$ eigenvalues of $A$.\\
{\sc Notice}: If $A$ is a symbolic matrix, you will obtain only
the eigenvalues that the CAS is able to determine (because
it is necessary to symbolically factorize the characteristic polynomial!)\\
Type:
$${\tt EGV(\left[\begin{array}{ccc} 4&1& -2\\1&2&-1\\2&1&0 \end{array}
\right])}$$
You obtain:
$${\tt [2,2,2] }$$

\subsubsection{\tt EGV}\index{EGV}
{\tt EGV} has a matrix $A$, of order $n$, as argument.\\
{\tt EGV} returns a list containing the matrix of the $n$ column
eigenvectors of $A$ and the vector of the $n$ eigenvalues of $A$
(the same notice given for {\tt EGVL} is valid here, too).\\
Type:
$${\tt EGV(\left[\begin{array}{ccc} 4&1& -2\\1&2&-1\\2&1&0 \end{array}
\right])}$$
You obtain:
$${\tt \{\left[\begin{array}{ccc} 1&2& 1\\0&1&0\\1&2&0 \end{array}\right]
,[2,2,2] \}}$$

\subsubsection{\tt PCAR}\index{PCAR}
{\tt PCAR} has a matrix $A$, of order $n$, as argument.\\
{\tt PCAR} returns the characteristic polynomial $P $ of $A$
($P[x]=(-1)^n \cdot \det(A-x \cdot I))$
Type:
$${\tt PCAR (\left[\begin{array}{ccc} 4&1& -2\\1&2&-1\\2&1&0 \end{array}
\right])}$$
You obtain:
$${\tt X^3-6 \cdot X^2+12 \cdot X-8}$$

\subsubsection{\tt JORDAN}\index{JORDAN}
{\tt JORDAN} has a matrix $A$, of order $n$, as argument.\\
{\tt JORDAN} returns a list composed by the minimal polynomial $M $
of $A$, the characteristic polynomial $P $ of $A$,
the list of the eigenvectors and characteristic vectors
(each vector is preceded by its characteristic value),
and the vector of the $n$ eigenvalues of $A$.\\
Type:
$${\tt JORDAN(\left[\begin{array}{ccc} 4&1& -2\\1&2&-1\\2&1&0 \end{array}
\right])}$$
You obtain:
\begin{eqnarray*}
{\tt \{X^3-6X^2+12X-8, X^3-6X^2+12X-8,}\\
{\tt \{Char:2:[1,0,0], Char:2:[2,1,2],Eigen:2:[1,0,1]\}, [2,2,2]\} }
\end{eqnarray*}

\subsubsection{\tt HILBERT}\index{HILBERT}
{\tt HILBERT} has an integer $n$ as argument.\\
{\tt HILBERT} returns the square Hilbert matrix of order $n$
whose elements are given by:\\
 $$a_{i,j}=\frac{1}{i+j-1}$$
Type:
$${\tt HILBERT(4)}$$
You obtain:
$${\tt \left[\begin{array}{cccc} 1&\frac{1}{2}&\frac{1}{3} &\frac{1}{4}\\
\frac{1}{2}&\frac{1}{3}&\frac{1}{4} &\frac{1}{5}\\\frac{1}{3}&\frac{1}{4}
&\frac{1}{5} &\frac{1}{6}\\\frac{1}{4}&\frac{1}{5}&\frac{1}{6} &\frac{1}{
7}\\  \end{array}\right] }$$

\subsubsection{\tt VANDERMONDE}\index{VANDERMONDE}
{\tt VANDERMONDE} has as argument a vector whose components are
denoted by $x_i$.\\
{\tt VANDERMONDE} returns the corresponding Vandermonde matrix
(the $k$-th row of the matrix is the vector whose components are
$x_i^{k-1}$).\\
Type:
$${\tt VANDERMONDE([A,B,C])}$$
You obtain:
$${\tt  \left[\begin{array}{ccc} 1& 1&1\\ {\tt A}&{\tt B}&{\tt C}\\{\tt A
^2}&{\tt B^2}&{\tt C^2} \end{array}\right]}$$

\subsubsection{\tt LCXM}\index{LCXM}
{\tt LCXM} has as arguments two integers, $n$ and $p$,
and a program accepting as arguments {\tt i} (a row number)
and {\tt j} (a column number) and yielding the value of $a_{i,j}$.\\
{\tt LCXM} returns a $n \cdot p$ matrix having coefficients $a_{i,j}$.
Type:
$${\tt LCXM(2,3,\ll \rightarrow I\ J\ \ll I+J \gg\ \gg)}$$
You obtain:
$${\tt \left[\begin{array}{ccc} 2& 3&4\\3&4&5 \end{array}\right]}$$

\subsection{Vectors}
In the {\tt blue-shift SYMB (MTH)} menu, you can find
the functions to compute:\\
-the absolute value of a vector: {\tt ABS}\index{ABS}\\
-the dot product of two vectors: {\tt DOT}\index{DOT} \\
-the cross product of two vectors: {\tt CROSS}\index{CROSS} \\

\subsection{Quadratic forms}
\subsubsection{\tt QXA}\index{QXA}
{\tt QXA} has two arguments: a quadratic form $q$
and a vector whose components are the form's variables.\\
{\tt QXA} returns a list of two elements:
the matrix $A$ associated with $q$ and the
vector denoting the variables of the quadratic form.\\
Type:
$${\tt QXA(2 \cdot X \cdot Y\ ,\ [X,Y])}$$
You obtain:
$${\tt  \{ \left[\begin{array}{cc} 0& 1\\ 1&0 \end{array}\right]\ ,\ 
[X,Y]\}}$$

\subsubsection{\tt AXQ}\index{AXQ}
{\tt AXQ} has two arguments:
a symmetric matrix $A$ representing a quadratic form  $q$
and a vector whose components are the quadratic form's variables.\\
{\tt AXQ} returns a list of two elements:
the quadratic form $q$ and the vector
denoting the form's variables.\\
Type:
$${\tt AXQ([[0,1],[1,0]]\ ,\ [X,Y])}$$
You obtain:
$${\tt \{ 2 \cdot X \cdot Y \  ,\ [X,Y]\}}$$

\subsubsection{\tt GAUSS}\index{GAUSS}
{\tt GAUSS} has two arguments: a quadratic form $q$
and a vector whose components are the quadratic form's variables.\\
{\tt GAUSS} returns a list of 4 elements:
the diagonal elements of a diagonal matrix
$B$ (obtained expressing $q$ as a sum of squares),
the matrix of change of base $Q$,
$q$ expressed as a sum of squares, and the vector
denoting the form's variables.\\
We have  (if we denote as $A$ the matrix associated with $q$) :
$$ ^tQ \cdot B \cdot Q=A$$
Type:
$${\tt GAUSS(2 \cdot X \cdot Y\ ,\ [X,Y])}$$
You obtain:
$${\tt  \{[\frac{1}{2},-2]\ ,\ \left[\begin{array}{cc} 1& 1\\-\frac{1}{2}
 &\frac{1}{2} \end{array}\right]\ ,\ -2.(\frac{Y-X}{2})^2+\frac{1}{2}.(Y+
X)^2\ ,\ [X,Y]\}}$$

\subsubsection{\tt SYLVESTER}\index{SYLVESTER}
{\tt SYLVESTER} has one argument: a symmetric matrix representing
a quadratic form $q$.\\
{\tt  SYLVESTER} returns a list of two elements:
the diagonal elements of the diagonal matrix $B$
(obtained expressing $q$ as a sum of squares)
and the matrix of change of base $Q$.\\
We have:
 $$ ^tQ \cdot B \cdot Q=A$$
Type:
$${\tt SYLVESTER([[0,1],[1,0]])}$$
You obtain:
$${\tt \{[\frac{1}{2},-2]\ ,\ \left[\begin{array}{cc} 1& 1\\-\frac{1}{2} 
&\frac{1}{2} \end{array}\right]\}}$$


\subsection{Functions of multiple variables}
\subsubsection{\tt DERIV}\index{DERIV}\label{sec:deriv}
{\tt DERIV} has two arguments: an application $F$ from $R^n $ in $R$
and a vector of $R^n$ denoting the variable names.\\
{\tt DERIV} returns the gradient of $F$ ($[\frac{\partial F}{\partial X},
\frac{\partial F}{\partial Y},\frac{\partial F}{\partial Z}]$ if $n=3$).\\
Type:
$${\tt DERIV(2 \cdot X^2 \cdot Y-X \cdot Z^3,[X,Y,Z])}$$
After simplification, you obtain:
$${\tt [4 \cdot Y \cdot X-Z^3,2 \cdot X^2,-(3 \cdot Z^2 \cdot X)]}$$

\subsubsection{\tt LAPL}\index{LAPL}
{\tt LAPL} has two arguments: an application $F$ from $R^n $ in $R$
and a vector of $R^n$ denoting the variable names.\\
{\tt LAPL} returns the laplacian of $F$ ($\frac{\partial^2 F}{\partial X^2
}+\frac{\partial^2 F}{\partial Y^2}+\frac{\partial^2 F}{\partial Z^2}$
if $n=3$).\\
Type:
$${\tt LAPL(2.X^2.Y-X.Z^3\ ,\ [X,Y,Z])}$$
You obtain:
$${\tt 4.Y-6.X.Z}$$

\subsubsection{\tt HESS}\index{HESS}
{\tt HESS} has two arguments: an applications $F$ from $R^n $ in $R$
and a vector of $R^n$ denoting the variable names.\\
{\tt HESS} returns a list containing the hessian of $F$, the
gradient of $F$ and the vector of the variable names.\\
Type:
$${\tt HESS(2.X^2.Y-X.Z\ ,\ [X,Y,Z])}$$
You obtain:
$$ \{ \left[\begin{array}{ccc} {\tt 4.Y}& {\tt4.X}& -1\\ {\tt4.X}&0&0 \\
-1&0&0 \end{array}\right]{\tt \ ,\ [4.X.Y-Z,2.X^2,-X]\ ,\ [X,Y,Z]\}
}$$
Now, to obtain the critical points of $F$,
in {\tt RPN} mode you can type:\\
$${\tt SOLVE}$$ directly, because on the stack you have:
 ${\tt [4.X.Y-Z,2.X^2,-X] \mbox{ and }  [X,Y,Z]} $\\
In {\tt ALGEBRAIC} mode, you must enter instead:
$${\tt SOLVE( [4.X.Y-Z,2.X^2,-X]\ ,\ [X,Y,Z])}$$

\subsubsection{\tt DIV}\index{DIV}
{\tt DIV} has two arguments: a vectorial function $F$ (application
from $R^n $ in $R^n$) and a vector of $R^n$ denoting the variable names.\\
{\tt DIV} returns the divergence of $F$.
 $${\tt DIV([A,B,C],[X,Y,Z])=\frac{\partial A}{\partial X}+\frac{
\partial B}{\partial Y}+\frac{\partial C}{\partial Z}} \mbox{  
(here } n=3)$$\\
Type:
$${\tt DIV([X \cdot Z,-Y^2,2 \cdot X^Y],[X,Y,Z])}$$
You obtain:
$${\tt Z-2 \cdot Y}$$

\subsubsection{\tt CURL}\index{CURL}
Here $n=3$.\\
{\tt CURL} has two arguments: a vectorial function $F$ (application
from $R^3 $ in $R^3$) and a vector of $R^3$ denoting the variable names.\\
{\tt CURL} returns the rotor of $F$.
$${\tt CURL([A,B,C],[X,Y,Z])=[\frac{\partial C}{\partial Y}-\frac{
\partial B}{\partial Z},\frac{\partial A}{\partial Z}-\frac{\partial C}
{\partial X},\frac{\partial B}{\partial X}-\frac{\partial A}{\partial Y}]}$$
Type:
$${\tt CURL([X.Z,-Y^2,2.X^Y],[X,Y,Z])}$$
You obtain:
$${\tt [2.X^2,X-2.Y.2X,0]}$$

\subsection{Equations}
\subsubsection{\tt EXLR}\index{EXLR}
{\tt EXLR} has an equation as argument.\\
{\tt EXLR} returns a list containing the left and right hand sides
of the equation.\\
Type:\\
$${\tt EXLR(A=B)}$$
You obtain:\\
$${\tt \{ A,B\}}$$

\subsubsection{\tt SOLVEVX}\index{SOLVEVX}
{\tt SOLVEVX} has as argument either an equation between two expression
of the variable stored in {\tt VX}, or an expression
({\tt =0 } is assumed then). \\
{\tt SOLVEVX} solves the equation.\\
Example 1:\\
Type:\\
$${\tt  SOLVEVX(X^4-1=3)}$$
In real mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2\}}$$
In complex mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2 ,\ X=-(i \cdot \sqrt2),\ X=i \cdot \sqrt2\}}$$
Example 2:\\
Type:\\
$${\tt  SOLVEVX((X-2).SIN(X))}$$
In real mode, you obtain:\\
$${\tt \{X=-(2 \cdot \pi \cdot n_1) ,\ X=2 \cdot \pi \cdot n_1,\ X=2\}}$$

\subsubsection{\tt SOLVE}\index{SOLVE}
{\tt SOLVE} has as argument either an equation between two
expressions or an expression ({\tt =0 } is assumed then),
and the name of a variable. \\
{\tt SOLVE} can also solve a system of equations:
to do this, put the equations into a vector and the variable names
into another vector.\\
{\tt SOLVE} solves either the equation or the system of equations.\\
Example 1:\\
Type:\\
$${\tt  SOLVE(X^4-1=3,X)}$$
In real mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2\}}$$
In complex mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2 ,\ X=-(i \cdot \sqrt2),\ X=i \cdot \sqrt2\}}$$
Example 2:\\
Type:\\
$${\tt  SOLVE([X+Y=1,X-Y],[X,Y])}$$
You obtain:\\
$${\tt \{[X=\frac{1}{2},\ Y=\frac{1}{2}]\} }$$

\subsubsection{\tt ISOL}\index{ISOL}
{\tt ISOL} isolates a variable in an expression or equation
(the variable must appear only once).
This command is the same as the HP48 one.\\
{\tt ISOL} has two arguments: either an expression or an equation,
and the name of the variable to isolate.\\
Type:\\
$${\tt  ISOL(X^4-1=3,X)}$$
In real mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2\}}$$
In complex mode, you obtain:\\
$${\tt \{X=-\sqrt2 ,\ X=\sqrt2 ,\ X=-(i \cdot \sqrt2),\ X=i \cdot \sqrt2\}}$$
Warning: if flag 01 ({\tt Principal value}) is set, {\tt ISOL}
always returns only one solution.

\subsection{Linear systems}
In this paragraph, we call ``augmented matrix'' of the system
$A \cdot X=B$ (or matrix ``representing'' the system $A \cdot X=B$),
the matrix obtained augmenting the matrix $A$ to the right
with the column vector $B$.

\subsubsection{\tt REF}\index{REF}
{\tt REF} solves a linear system of equations written in
matrix form:
$${\tt A\cdot X=B}$$
The {\tt REF} command is in the {\tt MATRICES (blue-shift 5)} menu,
{\tt 5 LINEAR SYST...} sub-menu.\\
The argument of {\tt REF} is the augmented matrix of the system
(the matrix obtained augmenting matrix {\tt A} to the right with
the column vector {\tt B}).\\
The result is a matrix {\tt [A1,B1]} : {\tt A1} has zeros
under its principal diagonal, and the solutions of:
$${\tt A1\cdot X=B1}$$ are the same as:
$${\tt A\cdot X=B}$$
For example, to solve the system:
$$\left \{\begin{array}{lcr} 3 \cdot x + y & = &-2 \\3 \cdot x +2 \cdot
 y & =& 2 \end{array}\right.$$\\
Type  (using  {\tt blue-shift EQW (MTRW)} to enter the matrix):
$${\tt REF([[3,  1, -2] [3, 2, 2]])}$$
You obtain:
$$\left [ \begin{array}{rrr}1 & \frac{1}{3} & \frac{-2}{3}\\0 & 1 & 4 
\end{array} \right]$$

\subsubsection{\tt rref}\index{rref}
{\tt rref} solves a linear system of equations written in
matrix form:
$${\tt A\cdot X=B}$$
The {\tt rref} command is in the {\tt MATRICES (blue-shift 5)} menu,
{\tt 5 LINEAR SYST...} sub-menu.\\
The argument of {\tt rref} is the augmented matrix of the system
(the matrix obtained augmenting matrix {\tt A} to the right with
the column vector {\tt B}).\\
The result is a list containing the list of pivot elements used
by the command and a matrix {\tt [A1,B1]} : {\tt A1} has zeros
both above and under its principal diagonal, and the solutions of:
$${\tt A1\cdot X=B1}$$ are the same as:
$${\tt A\cdot X=B}$$
It is interesting to use {\tt rref} in step-by-step mode,
setting the {\tt Step/Step (MODE cas chk)} flag.\\
For example, to solve the system:
$$\left \{
\begin{array}{lcr} 3 \cdot x + y & = &-2 \\3 \cdot x +2 \cdot y & =& 
2 \end{array}\right.$$

Type (using {\tt blue-shift EQW (MTRW)} to enter the matrix) :
$${\tt rref([[3,  1, -2][3, 2, 2]])}$$
You obtain:
$${\tt \left\{ Pivots: \{1\  1.\}\left [ \begin{array}{rrr}3 & 0 & -6\\0
& 1 & 4 \end{array} \right]\right\}}$$

\subsubsection{\tt RREF}\index{RREF}
{\tt RREF} is the same as {\tt rref}, but it does not return the pivots.\\
{\tt RREF} is the HP48 command; this is its result in step-by-step
mode, on the HP49, to solve the system:
$$\left \{
\begin{array}{lcr} 3 \cdot x + y & = &-2 \\3 \cdot x +2 \cdot y & =&
2 \end{array}\right.$$
Type (using {\tt blue-shift EQW (MTRW)} to enter the matrix):
$${\tt RREF([[3,  1, -2][3, 2, 2]])}$$
You obtain:\\

${\tt L_2=L_2-L_1}$\\

$ \left[\begin{array}{ccc}3&1&-2\\3&2 &2 \end{array}\right] $\\

after {\tt ok}:\\

${\tt L_1=L_1-L_2}$\\

$ \left[\begin{array}{cccc}3&1&-2\\0&1&4 \end{array}\right] $\\

after {\tt ok}:\\

Reduction result:\\

$ \left[\begin{array}{cccc}3&0&-6\\0&1&4 \end{array}\right] $\\

after {\tt ok}
the result (with all $1$ on the diagonal of $A1$) is stored in the history:
$$\left [ \begin{array}{rrr}1 & 0 & -2 \\0 & 1 & 4 \end{array} \right]$$

\subsubsection{\tt LINSOLVE}\index{LINSOLVE}
{\tt LINSOLVE} solves a linear system of equations.\\
The {\tt LINSOLVE} command is in the {\tt MATRICES (blue-shift 5)},
{\tt 5.LINEAR SYST...} sub-menu, position 1.\\
Type:
$${\tt LINSOLVE()}$$
Then, enter {\tt MATRIXWRITER} by pressing {\tt blue-shift EQW (MTRW)}
(with the cursor positioned between the two parentheses of {\tt LINSOLVE}).

Set the {\tt vect} menu option (if it isn't already set),
and enter the equations (possibly with the help of {\tt EQW}).
$${\tt 2 \cdot X+Y+Z=1\ ENTER}$$
$${\tt  X+Y+ 2 \cdot Z=1\ ENTER}$$
$${\tt   X+2 \cdot Y+Z=4\ ENTER}$$
{\tt ENTER}\\
Then, enter the unknown variables:
$${\tt [X \ Y \ Z]}$$
and {\tt  \  ENTER}\\

If step-by-step mode is enabled ({\tt MODE cas Step/Step}), you obtain:\\
{\tt L2=2L2-L1}\\
$ \left[\begin{array}{cccc}2&1&1&-1\\1&1&2 &-1\\1&2&1&-4 \end{array}\right] $\\
after {\tt ok}:\\
{\tt L3=2L3-L1}\\
$ \left[\begin{array}{cccc}2&1&1&-1\\0&1&3 &-1\\1&2&1&-4 \end{array}\right] $\\
an so on... Last, you obtain:
{\tt Result}\\
$ \left[\begin{array}{cccc}8&0&0&4\\0&8&0 &-20\\0&0&8&-4 \end{array}\right] $\\
after {\tt ok},\\
$${\tt \{ X=-\frac{1}{2}\  Y=\frac{5}{2}\ Z=-\frac{1}{2}\}}$$
is stored into the history.


\subsection{Differential equations}
\subsubsection{\tt LDEC}\index{LDEC}
{\tt LDEC} directly solves linear differential equations;
in order to do this, {\tt LAP} and {\tt ILAP} (see \ref{sec:lap})
are used internally.\\

For second order linear equations, the arguments are
the second member of the equation and the characteristic equation.\\

For first order systems of linear equations, the arguments
are the second member of the equation (a vector)
and the matrix of the system.\\
Example 1:\\

Solve:\\
$$y\prime \prime -6 \cdot y\prime+9 \cdot y \ =\ x \cdot e^{3 \cdot x}$$
Type:
$${\tt LDEC(X \cdot EXP(3 \cdot X),X^2-6 \cdot X+9)}$$
You obtain:
$${\tt ( \frac{X^3}{6}-(3 \cdot C0-C1) \cdot X+C0) \cdot EXP(3 \cdot X)}$$
{\tt C0} and {\tt C1} are arbitrary integration constants
(${\tt y(0)=C0,\ y\prime(0)=C1}$).\\
Example 2:\\
Solve:\\
$$Z' = \left[
\begin{array}{cc}
 0&1\\-9&6 \end{array}\right].Z+
\left[
\begin{array}{c}
 0\\X.EXP(3.X) \end{array}\right]
$$
This is the same example as before, with $Z=[y , y\prime]$.\\
Type:
$${\tt LDEC([0,X \cdot EXP(3 \cdot X)],[[0,1][-9,6]])}$$
You obtain:
\begin{eqnarray*}
{\tt [( \frac{X^3}{6}-(3 \cdot V1-V2) \cdot X+V1) \cdot EXP(3 \cdot X)} ,\\
{\tt (\frac{X^3}{2}+\frac{X^2}{2}
-(9 \cdot V1-3 \cdot V2) \cdot X+V2) \cdot EXP(3 \cdot X)]}
\end{eqnarray*}
{\tt V1} and {\tt V2} are arbitrary integration constants
(${\tt Z(0)=[V1 ,V2]}$).\\

\subsubsection{\tt DESOLVE\protect\index{DESOLVE} and SUBST\protect\index{SUBST}}
The {\tt DESOLVE} command is in the {\tt S.SLV (blue-shift 7)} menu,
at position 1, or in the {\tt CALC (blue-shift 4)} menu,
{\tt DIFFERENTIAL EQNS...} sub-menu.\\
{\tt DESOLVE} solves other types of differential equations.\\
Its arguments are:
the differential equation (here $y \prime$ is written as ${\tt d1Y(X)}$
and $y$ is written as {\tt Y(X)}).\\
Example 1 :\\
Solve:
$$y''+y=\cos (x) \; \; y(0)=c_0 \; \; y'(0)=c_1$$
Type:
$${\tt DESOLVE(d1d1Y(X)+Y(X)=COS(X),Y(X))}$$
You obtain:
$${\tt Y(X)=C0\cdot COS(X)+ \frac {X+2 \cdot C1}{2}\cdot SIN(X)}$$
Now, you can assign a value to the integration constants, using
the {\tt SUBST} command; you can find it in the {\tt ALG (red-shift 4)}
menu, at position 6.
If you want the solutions that satisfy $y(0)=1$, you type:
$${\tt SUBST ( Y(X)=C0\cdot COS(X)+ \frac {X+2 \cdot C1}{2}\cdot SIN(X),
C0=1)}$$
You obtain:
$${\tt Y(X)=\frac {2\cdot COS(X)+  (X+2 \cdot C1)\cdot SIN(X)}{2}} $$

Example 2 :\\
Solve:
$$y''+y=\cos (x) \; \; y(0)=1 \; \; y'(0)=c_1$$
To have the solutions satisfying $y(0)=1$ you can also directly type:
$${\tt DESOLVE([d1d1Y(X)+Y(X)=COS(X),Y(0)=1],Y(X))}$$
In this case, you obtain:
$${\tt Y(X)= COS(X)+ \frac {X+2 \cdot C1}{2}\cdot SIN(X)}$$

\subsubsection{\tt LAP\protect\index{LAP} ILAP\protect\index{ILAP}}\label{sec:lap}
You can find these commands in the {\tt CALC \ (blue-shift 4)} menu,
{\tt 3.DIFFERENTIAL...} sub-menu, at positions 2 and 3.
Laplace tranform (${\tt LAP}$) and inverse Laplace transform
(${\tt ILAP}$) are useful to solve linear differential equations
with constant coefficients, for example:
$$y \prime \prime +p. y \prime+q. y \ =\ f(x)\; \;  y(0)=a \; \; y\prime(0)=b$$
The following relations hold:
$${\tt LAP(Y)(P)=\int_0^{+\infty}e^{-P.X}Y(X)dX} $$
$${\tt ILAP(F)(T)=\frac{1}{2.i.\pi}\int_C e^{Z.T}dZ}$$
where ${\tt C}$ is a closed contour enclosing the poles of ${\tt F}$\\
The following property is used:
$${\tt LAP(Y')(P)=-Y(0)+P \cdot LAP(Y)(P)}$$
The solution is then:
$${\tt ILAP(\frac{LAP(F(X))+(X+P) \cdot A +B}{X^2+P \cdot X+Q})}$$
Example:\\
Solve:
$$y\prime \prime -6 \cdot y\prime+9 \cdot y \ =\ x \cdot e^{3 \cdot x}$$
$$y(0)=a$$
$$y\prime(0)=b$$
Type:
$${\tt LAP(X \cdot EXP(3 \cdot X))\ ENTER}$$
You obtain:
$${\tt \frac {1}{X^2-6 \cdot X+9}}$$
Type:
$${\tt ILAP(\frac {ANS(1)+(X-6) \cdot A+B}{X^2-6 \cdot X+9})}$$
You obtain the solution $y$ :
$${\tt ( \frac{X^3}{6}-(3 \cdot A-B) \cdot X+A) \cdot EXP(3 \cdot X)}$$


\subsection{Other functions}
\subsubsection{\tt EPSX0}\index{EPSX0}\label{sec:epsx0}
{\tt EPSX0} has as argument an expression; in the expression, it
replaces all numeric values whose magnitude is smaller than {\tt EPS}
with zero and returns the result.\\
Type:
$${\tt EPSX0(0.001+X)}$$
You obtain (when {\tt EPS=0.01}) :
$${\tt 0+X}$$
You obtain (when {\tt EPS=0.0001}) :
$${\tt .001+X}$$

\subsubsection{\tt LVAR}\index{LVAR}\label{sec:lvar}
{\tt LVAR} has an expression as argument, and returns a list
containing the expression and a vector whose components are
the independent variables of the expression.\\
Type:
$${\tt LVAR(X.Y.SIN(X))}$$
You obtain:
$${\tt \{X.Y.SIN(X),[SIN(X),X,Y]\}}$$

\subsubsection{\tt LNAME}\index{LNAME}
{\tt LNAME} has an expression as argument, and returns a
vector whose components are the symbolic variable names
the expression contains.\\
Type:
$${\tt LNAME(X.Y.SIN(X))}$$
You obtain:
$${\tt [X,Y]}$$

\subsubsection{\tt XNUM}\index{XNUM}
{\tt XNUM} has either an expression or an array as argument.\\
{\tt XNUM} enables approximate mode and returns the numeric approximation
of its argument.\\
Type:
$${\tt XNUM(\sqrt2)}$$
You obtain:
$${\tt 1.41421356237}$$

\subsubsection{\tt XQ}\index{XQ}
{\tt XQ} has a real numeric expression as argument.\\
{\tt XQ} enables exact mode and returns either a rational or
a real approximation of the expression.\\
Type:
$${\tt XQ(1.41422)}$$
You obtain:
$${\tt \frac{66441}{46981}}$$
Type:
$${\tt XQ(1.414213562)}$$
You obtain:
$${\tt \sqrt2}$$

% 1.8, cibrario, 9-Mar-2001
% From graeve_new.tex
\subsection{New commands}

\subsubsection{\tt qr}\index{qr}
{\tt qr} has a square matrix as argument.\\
{\tt qr} factors the matrix as Q*R, where Q is an orthogonal matrix
and R is a triangular matrix.\\
For example, enter:
$${\tt qr(\left[\begin{array}{rr}3 & 5\\4&5\end{array}\right])}$$
You obtain:
$${\tt \{\left[\begin{array}{rr}\frac{3}{5} & \frac{4}{5}\\\frac{4}{5}&-\frac{3}{5}\end{array}\right],\left[\begin{array}{rr}5 & 7\\0&1\end{array}\right]\}}$$

\subsubsection{\tt GRAMSCHMIDT}\index{GRAMSCHMIDT}
{\tt GRAMSCHMIDT} has two arguments: a vector representing a base of
a vectorial space and the definition of a scalar product in that space,
expressed as a function.\\
{\tt GRAMSCHMIDT} returns an orthonormal base of the vectorial space
with respect to the given scalar product.\\ 
Example:\\
In the vectorial space of polynomials of degree less than 2, we
consider the scalar product defined by:
$$P \cdot Q=\int_{-1}^1P(x) \cdot Q(x)dx $$
We first express the scalar product as a function named {\tt PS} :\\
${\tt \ll \rightarrow P\ Q
\ll PREVAL(INTVX(P*Q),-1,1)
\gg\ \gg STO\triangleright PS}$\\
Next, we type:
 $${\tt GRAMSCHMIDT([1,1+X],RCL('PS'))}$$
We obtain:
$${\tt [\frac{1}{\sqrt 2},\ \frac{\sqrt 6 \cdot X}{2}]}$$

\subsubsection{\tt SYST2MAT}\index{SYST2MAT}

{\tt SYST2MAT} has two arguments: a vector containing a system of
linear equations, and a vector whose elements are the system's
variables.\\
{\tt SYST2MAT} rewrites the system in matrix notation, and returns
the matrix.\\
For example, type:\\
$${\tt SYST2MAT([X+Y,X-Y=2],[X,Y])}$$
You obtain:
$${\tt \left[\begin{array}{rrr}1 & 1&0\\1&-1&-2\end{array}\right]}$$
Warning: you must purge the system's variables ({\tt X} and {\tt Y}
in this example) beforehand.

\subsubsection{\tt CHOLESKY}\index{CHOLESKY}
{\tt CHOLESKY} has as argument a square matrix {\tt M}, positive
by definition.\\
{\tt CHOLESKY} returns an upper triangular matrix {\tt P} so that:\\
${\tt ^tP*P=M}$\\
For example, type:
$${\tt CHOLESKY(\left[\begin{array}{rr}1 & 1\\1&5\end{array}\right])}$$
You obtain:
$${\tt \left[\begin{array}{rr}1 & 1\\0&2\end{array}\right]}$$

\subsubsection{\tt DIAGMAP}\index{DIAGMAP}
{\tt DIAGMAP} has two arguments: a diagonalizable matrix and
a function defining an holomorphic operator.\\
{\tt DIAGMAP} applies the operator to the matrix, and returns the result.\\
Warning! The matrix must be diagonalizable.\\
For example, we define the function {\tt PH} as follows :\\
${\tt \ll \rightarrow M
\ll EXP(M)
\gg\ \gg STO\triangleright PH}$\\
Next, we type:
$${\tt DIAGMAP(\left[\begin{array}{rr}1 & 1\\0&2\end{array}\right], \ll \rightarrow M
\ll EXP(M)
\gg \gg)}$$
or :\\
$${\tt DIAGMAP(\left[\begin{array}{rr}1 & 1\\0&2\end{array}\right],RCL('PH'))}$$
We obtain:
$${\tt \left[\begin{array}{cc}{\tt EXP}(1)& -{\tt EXP}(1)+{\tt EXP}(2)\\0&{\tt EXP}(2)\end{array}\right]}$$

\subsubsection{\tt ISOM}\index{ISOM}
{\tt ISOM} has as argument a matrix representing a two or three-dimensional
linear isometry.\\
{\tt ISOM} returns the list of the isometry's characteristics elements
and either {\tt +1} (for direct isometries) or {\tt -1} (for
indirect isometries).\\
For example, type:
$${\tt ISOM(\left[\begin{array}{rrr}0&0&1\\0 & 1&0\\1&0&0\end{array}\right])}$$
You obtain:
$${\tt \{[1\ 0\ -1]\ -1\}}$$
This result means that the isometry is a simmetry with respect to
the plane $x\ -\ z\ =\ 0$.\\ 
If you type:
$${\tt ISOM(\frac{\sqrt2}{2}\left[\begin{array}{rr}1 & -1\\1&1\end{array}\right])}$$
You obtain:
$${\tt \{\frac{\pi}{4},1\}}$$
therefore, this isometry is a rotation of $ \displaystyle \frac{\pi}{4}$
radians.

\subsubsection{\tt MKISOM}\index{MKISOM}
In a three-dimensional space,
{\tt MKISOM} has the list of the characteristics elements
of an isometry, and either {\tt +1} (denoting a direct isometry)
or {\tt -1} (denoting an indirect isometry) as arguments,\\
In a two-dimensional space,
{\tt MKISOM} has the characteristic element of an isometry
(either an angle or a vector) and either {\tt +1} (denoting a direct isometry)
or {\tt -1} (denoting an indirect isometry) as arguments.\\
{\tt MKISOM} returns the matrix representing the given isometry.\\
For example, type:
$${\tt MKISOM(\{[-1,2,-1],\pi \},1)}$$
You obtain the matrix of a rotation with axis $[-1,2,-1]$ and angle $\pi$:
$${\tt \frac{1}{3}\left[\begin{array}{rrr}-2 & -2&1\\-2&1&-2\\1&-2&-2\end{array}\right]}$$
For example, type:
$${\tt MKISOM(\{\pi \},-1)}$$
You obtain the matrix of a symmetry with respect to the origin:
$${\tt \left[\begin{array}{rrr}-1 & 0&0\\0&-1&0\\0&0&-1\end{array}\right]}$$
Type:
$${\tt MKISOM(\{[1,1,1],\frac{\pi}{3} \},-1)}$$
You obtain the matrix of a rotation with axis $[1,1,1]$ and angle
$\frac{\pi}{3}$ combined with a symmetry with respect to the plane $x+y+z=0$:
$${\tt \left[\begin{array}{rrr}0 & -1&0\\0&0&-1\\-1&0&0\end{array}\right]}$$
Type:
$${\tt MKISOM( \frac{\pi}{2},1)}$$
You obtain the matrix of a rotation
of $\frac{\pi}{2}$ radians in two dimensions:
$${\tt \left[\begin{array}{rr} 0 & -1\\1&0\end{array}\right]}$$
Type:
$${\tt MKISOM([1,1],-1)}$$
You obtain the matrix of a symmetry with respect to $y=x$ in two dimensions:
$${\tt \left[\begin{array}{rr} 0 & -1\\-1&0\end{array}\right]}$$

\subsubsection{\tt KER}\index{KER}
{\tt KER} has as argument a matrix representing a linear application $f$
in terms of the standard basis.\\
{\tt KER} returns a list of vectors; they are a basis of
the kernel of $f$.\\
For example, type:
$${\tt KER(\left[\begin{array}{rrr}1&1&2\\2 & 1&3\\3&1&4\end{array}\right])}$$
You obtain:
$${\tt \{[1,1,-1] \}}$$

\subsubsection{\tt IMAGE}\index{IMAGE}
{\tt IMAGE} has as argument a matrix representing a linear application $f$
in terms of the standard basis.\\
{\tt IMAGE} returns a list of vectors; they are a basis of
the image of $f$.\\
For example, type:
$${\tt IMAGE(\left[\begin{array}{rrr}1&1&2\\2 & 1&3\\3&1&4\end{array}\right])}$$
You obtain:
$${\tt \{[1,0,-1],[1,1,2] \}}$$

\subsubsection{\tt IBASIS}\index{IBASIS}
{\tt IBASIS} has as arguments two lists of vectors, defining two vectorial
spaces.\\
{\tt IBASIS} returns a list containing the vectors of a basis of
the intersection between these two vectorial spaces.\\
For example, type:
$${\tt IBASIS(\{[1,2]\},\{[2,4]\})}$$
You obtain:
$${\tt \{[1,2]\}}$$

\subsubsection{\tt BASIS}\index{BASIS}
{\tt BASIS} has as argument a list of vectors, defining a vectorial
subspace of $R^n$.\\
{\tt BASIS} returns a list containing the vectors of a basis
of the vectorial subspace.\\
For example, type:
$${\tt BASIS(\{[1,2,3],[1,1,1],[2,3,4]\})}$$
You obtain:
$${\tt \{[1,0,-1],\ [0,1,2]\}}$$

\subsubsection{\tt AUGMENT}\index{AUGMENT}
{\tt AUGMENT} has as arguments two vectors, or two lists, or a list
and an element.\\
{\tt AUGMENT} concatenates its arguments.\\
For example, type:
$${\tt AUGMENT(\{1,2\},3)}$$
You obtain:
$${\tt \{ 1\ 2\ 3 \}}$$

\subsubsection{\tt CYCLOTOMIC}\index{CYCLOTOMIC}
{\tt CYCLOTOMIC} has an integer $n$ as argument.\\
{\tt CYCLOTOMIC} returns the cyclotomic polynomial of order $n$.  This
is a polynomial having the $n$-th pritmitive roots of the unity
as zeros.\\
For example, when $n=4$ the fourth roots of the unity are:
$\{ 1,i,-1,-i\}$;\\ 
among them, the primitive roots are: $\{i,-i\}$.\\
Therefore, the cyclotomic polynomial of order $4$ is $(X-i).(X+i)=X^2+1$.\\
Another example; if you type:
$${\tt CYCLOTOMIC(20)}$$
You obtain:
$${\tt X^8-X^6+X^4-X^2+1}$$

\subsubsection{\tt STURM}\index{STURM}
{\tt STURM} has a polynomial $P$ as argument.\\
{\tt STURM} returns a list containing the Sturm's sequences of $P$ and their
multiplicities.\\
The Sturm sequence $R_1,R_2,...$ can be obtained from a square-free
factor $F$ of $P$ as follows:\\
$R_1$ is the opposite of the remainder of the euclidean division of
$F$ by $F'$;\\
then, $R_2$ is the opposite of the remainder of the euclidean division of
$F'$ by $R_1$,\\
and so on, until $R_k=0$.\\
For example, type:
$${\tt STURM(X^3+1)}$$
You obtain:
$${\tt \{[1],\ -1.,\ [X^3+1,\ -3X^2 -1],\ 1.\}}$$
The first element of the list denotes that the denominator of $P$
(that is, the element with $-1$ power), is 1.

% \subsubsection{\tt STURMAB HP40G}
% {\tt STURMAB} a trois paramètres : un polyn\^ome et deux nombres $a$ et $b$\\
% {\tt STURMAB} renvoie le nombres de zéros de $P$ sur $[a;b[$.\\
% On tape :
% $${\tt STURMAB(X^3+2,-2,0)}$$
% On obtient :
% $${\tt 1}$$

%\subsubsection{\tt STURMAB HP49G}
\subsubsection{\tt STURMAB}\index{STURMAB}
{\tt STURMAB} has three arguments: a polynomial $P$ and two numbers:
$a$ and $b$.\\
{\tt STURMAB} returns a list containing an element with the same sign
as $P(a)$ and the number of zeros of $P$ in $[a,b[$.\\
For example, type:
$${\tt STURMAB(X^2 \cdot (X^3+2),-2,0)}$$
You obtain:
$${\tt \{-6,\ 1\}}$$

\subsubsection{\tt P2C}\index{P2C}
Permutations are defined with the image list $\{P(1),P(2)...P(n)\}$.\\
For example, definining the permutation $P$ as $P =\{3,2,1\}$ means that:\\
$P(1)=3,\ P(2)=2,\  P(3)=1$.\\
A cycle is denoted with a list containing the images of an element through
the cycle; for example, defining a cycle $C$ as $C=\{3,2,1\}$ means that:\\ 
$C(3)=2,\ C(2)=1,\ C(1)=3$.\\ 
Accordingly, a decomposition into cycles is denoted with
a list of lists.\\
{\tt P2C} has a permutation as argument.\\
{\tt P2C} returns its decomposition into cycles and its signature.\\
For example, type:
$${\tt P2C(\{3,4,5,2,1\})}$$
You obtain:
$${\tt\{\{\{1,3,5\},\{2,4\}\},-1\}}$$

\subsubsection{\tt C2P}\index{C2P}
%Les permutations $P$ de $\{ 1,2...n\}$ sont données par la liste des images 
%$\{P(1),P(2)...P(n)\}$.\\
%Par exemple la permutation $P =\{3,2,1\}$ veut dire que :\\
 %$P(1)=3,\ P(2)=2,\ P(3)=1$.\\
%Un cycle est donné par la liste des images successives d'un élément :\\
%Par exemple $C=\{3,2,1\}$ veut dire que :\\ 
%$C(3)=2,\ C(2)=1,\ C(1)=3$.\\ 
{\tt C2P} has a list of cycles as argument.\\
{\tt C2P} returns the permutation having the input list as
decomposition into cycles (see also {\tt P2C}).\\
For example, type:
$${\tt C2P(\{\{1,3,5\},\{2,4\}\})}$$
You obtain:
$${\tt\{3,4,5,2,1\}}$$

\subsubsection{\tt CIRC}\index{CIRC}
{\tt CIRC} has two permutations as arguments.\\
{\tt CIRC} returns the permutation obtained by composition:
($1^{\mbox{st}}\mbox{argument} \circ 2^{\mbox{nd}} \mbox{argument}$).\\ 
For example, type:
$${\tt CIRC(\{3,4,5,2,1\},\{2,1,4,3,5\})}$$
You obtain:
$${\tt \{4,3,2,5,1\}}$$

\subsubsection{\tt FDISTRIB}\index{FDISTRIB}
{\tt FDISTRIB} performs a full distribution of multiplication with respect
to addition in a single step.\\
For example, type:
$${\tt FDISTRIB((X+1)\cdot(X+2)\cdot(X+3))}$$
You obtain:
$${\tt X^3+6\cdot X^2+11\cdot X+6 }$$

\subsubsection{\tt DISTRIB}\index{DISTRIB}
{\tt DISTRIB} applies the distributive property of multiplication
with respect to addition once.\\ 
{\tt DISTRIB}, when invoked multiple times, allows you to perform
a full distribution of multiplication with respect to addition
step-by-step.\\
For example, type:
$${\tt DISTRIB((X+1)\cdot(X+2)\cdot(X+3))}$$
You obtain:
$${\tt X\cdot(X+2)\cdot(X+3)+1\cdot(X+2)\cdot(X+3) }$$

\subsubsection{\tt POWEXPAND}\index{POWEXPAND}
{\tt POWEXPAND} rewrites a power as a product.\\
For example, type:
$${\tt  POWEXPAND((X+1)^3)}$$
You obtain:
$${\tt (X+1)*(X+1)*(X+1)}$$
You can also expand $(x+1)^3$ step-by-step,
by invoking {\tt DISTRIB} many times on the result obtained above.

\subsubsection{\tt SIMPLIFY}\index{SIMPLIFY}
{\tt SIMPLIFY} attempts to simplify the expression
given as argument automatically.\\
Like all other automatic simplification tools, you should not
demand miracles to this command.
For example, type:\\
$${\tt SIMPLIFY(\frac{SIN(3 \cdot X)+SIN(7 \cdot X)}{SIN(5 \cdot X)})}$$
After simplification, you obtain:\\
$${\tt 4 \cdot COS(X)^2-2}$$

\subsubsection{\tt EXP2POW}\index{EXP2POW}
{\tt  EXP2POW} rewrites an expression like\\
$$\exp(n \times \ln(x))$$
as a power of $x$.\\
For example, type:
$${\tt  EXP2POW(EXP(N*LN(X))) }$$
You obtain:
$${\tt X^N}$$
Notice the difference with respect to {\tt  LNCOLLECT} :\\
We have:\\
${\tt  LNCOLLECT(EXP(N*LN(X))) = EXP(N*LN(X)) }$\\
${\tt  LNCOLLECT(EXP(LN(X)/3))\ =\ EXP(LN(X)/3) }$\\
But:\\
${\tt  EXP2POW(EXP(LN(X)/3))\ = \ X^\frac{1}{3} }$\\

\subsubsection{\tt MSLV}\index{MSLV}
{\tt MSLV} solves numerically a system of non-polynomial equations.\\
{\tt MSLV} has three vectors as arguments: a vector containing the equations,
a vector containing the system's variables, and a vector containing
an initial guess for the solution.\\
{\tt MSLV} returns a vector containing an approximate solution
of the given system of equations.\\
While the command is running, the first display line shows the
last estimate $\overrightarrow V$, and the second line shows the
modulo of $\Delta \overrightarrow V$\\
For example, type:
$${\tt MSLV(['SIN(X)+Y','X+SIN(Y)=1'],[X,Y],[0,0])}$$
You obtain:
$${\tt [1.82384112611,\  -.968154636174]}$$

\subsubsection{\tt PMINI}\index{PMINI}
{\tt PMINI} has a matrix $A$ as argument.\\
{\tt PMINI} returns another matrix, whose first ``non-zero row''
is the minimal polynomial of $A$.\\
For example, type:
$${\tt PMINI([[1,0],[0,1]])}$$
In step-by-step mode, you obtain:\\
{\tt L2=L2-L1}\\
$\left[\begin{array}{rrrrr}1&0&0&1&1\\1&0&0 & 1&X\\1&0&0&1&X^2\end{array}\right]$\\

{\tt L3=L3-L1}\\
$\left[\begin{array}{rrrrr}1&0&0&1&1\\0&0&0 & 0&X-1\\1&0&0&1&X^2\end{array}\right]$\\

{\tt Reduction result}\\
$\left[\begin{array}{rrrrr}1&0&0&1&1\\0&0&0 & 0&X-1\\0&0&0&0&X^2-1\end{array}\right]$\\

So, the minimal polynomial of $A$:
$\left[\begin{array}{rr}1&0\\0 & 1\end{array}\right]$
is:
$${\tt X-1}$$

\subsubsection{\tt IBERNOULLI}\index{IBERNOULLI}
{\tt IBERNOULLI} has an integer $n$ as argument.\\
{\tt IBERNOULLI} returns the $n^{ty}$ Bernoulli's number $B(n)$.\\
The following relation holds:
$$\frac{t}{e^t-1}=\sum_{n=0}^{+\infty} \frac{B(n)}{n!}t^n$$
Remember that the Bernoulli's polynomials $B_k$ are defined as:
$$B_0=1$$
$$B_k{'}(x)=kB_{k-1}(x)$$
$$\int_0^1B_k(x)dx=0$$
Bernoulli's numbers are defined as:\\
$B(n)=B_n(0)$\\
For example, type:
$${\tt IBERNOULLI(6)}$$
You obtain:
$${\tt \frac{1}{42}}$$

%\subsubsection{\tt MENUXY}
%On tape :
%On obtient :

\subsubsection{\tt GAMMA}\index{GAMMA}
Returns the value of the $\Gamma$ function at the given point.\\
The $\Gamma$ function is defined as:\\
$$\Gamma(x)=\int_0^{+\infty}e^{-t}t^{x-1}dt$$
We have: $$\Gamma(1)=1$$
$$ \Gamma(x+1)=x \cdot \Gamma(x)$$
For example, type:
$${\tt GAMMA(5)}$$
You obtain:
$${\tt 24}$$
Type:
$${\tt GAMMA(\frac{1}{2})}$$
You obtain:
$${\tt \sqrt\pi}$$

\subsubsection{\tt PSI}\index{PSI}
{\tt PSI} has two numbers $a$ and $n$ as arguments.\\ 
{\tt PSI} returns the value of the $n$-th derivative of the Digamma
function at $a$. The Digamma function is defined as the derivative
of $\ln(\Gamma(x))$.\\
For example, type:
$${\tt PSI(3,1)}$$
You obtain:
$${\tt -\frac{5}{4}+\frac{1}{6}.\pi^2}$$

\subsubsection{\tt Psi}\index{Psi}
{\tt Psi} has as argument a number, $a$.\\
{\tt Psi} returns the value of the Digamma function at $a$.\\ 
The Digamma function is defined as the derivative of $\ln(\Gamma(x))$, so
we have:
{\tt PSI(a,0)=Psi(a)}.\\
For example, type:
$${\tt Psi(3)}$$
You obtain:
$${\tt .922784335098}$$

\subsubsection{\tt RESULTANT}\index{RESULTANT}
{\tt RESULTANT} has two polynomials as arguments.\\
{\tt RESULTANT} returns the resultant of the two polynomials.
The resultant of two polynomials is the last non-null remainder of
the Euclide algorithm, and is also the determinant of their
Sylvester matrix $S$.\\
The Sylvester matrix $S$ of two polynomials $A[X]=\sum_{i=0}^{i=n} a_iX^i$
and $B[X]=\sum_{i=0}^{i=m} a_iX^i$
is a square matrix with $m+n$ rows and columns; its first $m$ rows
are made from the coefficients of $A[X]$:
$$\left(\begin{array}{ccccccc}
s_{11}=a_n & s_{12}=a_{n-1}& \cdots & s_{1(n+1)}=a_0 & 0 & \cdots & 0\\
s_{21}=0 & s_{22}=a_{n}& \cdots & s_{2(n+1)}=a_1 & s_{2(n+2)}=a_0 & \cdots & 0\\
\vdots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots\\
s_{m1}=0 & s_{m2}=0& \cdots & s_{m(n+1)}=a_{m-1} & s_{m(n+2)}=a_{m-2} & \cdots&a_0 
\end{array}\right)$$
and the following $n$ rows are made in the same way from the
coefficients of $B[X]$:
$$\left(\begin{array}{ccccccc}
s_{(m+1)1}=b_m & s_{(m+1)2}=b_{m-1}& \cdots & s_{(m+1)(m+1)}=b_0 & 0 & \cdots & 0\\
\vdots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots\\
\end{array}\right)$$
For example, type:
$${\tt RESULTANT(X^3-p*X+q,3X^2-p)}$$
You obtain:
$${\tt -4p^3+27q^2}$$

\subsubsection{\tt SEVAL}\index{SEVAL}
{\tt SEVAL} has an expression as argument.\\
{\tt SEVAL} simplifies the expression, operating on all but
the top-level operator of the expression.\\
For example, type:
$${\tt SEVAL(SIN(3 \cdot X-X)+SIN(X+X))}$$
You obtain:
$${\tt SIN(2 \cdot X)+SIN(2 \cdot X)}$$

\subsubsection{\tt SIGMA}\index{SIGMA}
{\tt SIGMA} has two arguments: the first argument is a function $f(x)$ of a
variable $x$ given as the second argument.
{\tt SIGMA} returns the discrete antiderivative of the input function,
that is, the function $G$ that satisfies the relation: $G(x+1)-G(x)=f(x)$.\\ 
For example, type:
$${\tt SIGMA(X \cdot X!,X)}$$
You obtain:
$${\tt X!}$$

\subsubsection{\tt SIGMAVX}\index{SIGMAVX}
{\tt SIGMAVX} has as argument a function $f$ of the current
variable {\tt VX}.\\
{\tt SIGMAVX} returns the discrete antiderivative of the input function,
that is a function $G$ that satisfies the relation: $G(x+1)-G(x)=f(x)$.\\ 
For example, type:
$${\tt SIGMAVX(X^2)}$$
You obtain:
$${\tt \frac{2.X^3-3.X^2+X}{6}}$$

\subsubsection{\tt VER}\index{VER}
{\tt VER} returns the version number of your {\tt CAS}.\\
Type:\\
{\tt VER}\\
You obtain:
$${\tt 4.20000124}$$
This result means that you have a version 4 {\tt CAS},
dated 24 January 2000.\\
Instead, {\tt VERSION} returns the version number of the calculator's
{\tt ROM} as a whole.\\
Type:\\
{\tt VERSION}\\
You obtain:
$${\tt \{``Version \ HP49-B\hookleftarrow Revision\ \#1.17-4''\ ``Copyright\ HP \ 1999''\}}$$ 

\subsubsection{\tt TABVAR}\index{TABVAR}
{\tt TABVAR} has as argument an expression whose derivative is rational.\\
{\tt TABVAR} returns the variation table of the expression with respect to
the current variable.\\
Type:
$${\tt TABVAR(LN(X)+X)} $$
In step-by-step mode you obtain:\\
${\tt F=:(LN(X)+X)}$\\
${\tt F'=:\displaystyle (\frac{1}{X}+1)}$\\
${\tt \rightarrow :\displaystyle \frac{X+1}{X}} $\\
{\tt Variation table } :\\
$$\left[\begin{array}{cccccc}
-\infty & ?  & 0 & + & +\infty & X\\
? & ?  & -\infty & \uparrow & +\infty & F \end{array}\right]$$

\subsubsection{\tt SIGNTAB}\index{SIGNTAB}
{\tt SIGNTAB} has a rational expression as argument.\\
{\tt SIGNTAB} returns the sign table of the expression with respect
to the current variable.\\
Type:
$${\tt SIGNTAB(X^2+X)}$$
You obtain:
$${\tt \{-\infty\ +\ -1\ -\ 0\ +\ +\infty\}}$$

\subsubsection{\tt TABVAL}\index{TABVAL}
{\tt TABVAL} has an expression and a list of numbers as arguments.\\
{\tt TABVAL} stores the input expression into the {\tt EQ} variable
and returns a list.  This list holds the expression itself and a list
of values; the latter list contains the value the expression assumes
when the current CAS variable is replaced by the list of numbers
given as input.\\
For example, type:
$${\tt TABVAL(X^2+X,\{1,2,3\})}$$
You obtain: 
$${\tt \{X^2+X,\{\{1,2,3\},\{2,6,12\}\}\}}$$

\subsubsection{\tt PLOT}\index{PLOT}
{\tt PLOT} has an expression as argument.\\ 
{\tt PLOT} stores the input expression into the {\tt EQ} variable
and opens the {\tt PLOT SETUP} window.\\
For example, type:
$${\tt PLOT(X^2+X)}$$
Now, by pressing {\tt ERASE DRAW}, you obtain the plot of the expression stored
in {\tt EQ}, and $${\tt X^2+X}$$ is stored into the history.

\subsubsection{\tt PLOTADD}\index{PLOTADD}
{\tt PLOTADD} has an expression as argument.\\ 
{\tt PLOTADD} appends this expression to the list of equations currently
stored in {\tt EQ} and opens the {\tt PLOT SETUP} window.\\
Type:
$${\tt PLOTADD(X^2-X)}$$
Now, by pressing {\tt ERASE DRAW}, you draw the plots of all expressions
stored in {\tt EQ} one over another, and $${\tt X^2-X}$$ is stored
into the history.

\subsubsection{\tt SCROLL}\index{SCROLL}
{\tt SCROLL} has a graphics object as argument.\\
{\tt SCROLL} displays the graphics object, without touching {\tt PICT}.\\
For example, suppose you have just plotted the function ${\tt F(X)}$.
The plot is automatically stored into the reserved variable
{\tt PICT}.\\
Therefore, {\tt PICT} contains the current graphics variable.
You can save its contents, typing:\\
$${\tt RCL(PICT)\  STO\triangleright\ GRF}$$ 
Next, if you type:
$${\tt SCROLL(GRF)}$$
you display the plot of ${\tt F(X)}$ again.\\

\subsubsection{\tt GROBADD}\index{GROBADD}
{\tt GROBADD} has two graphics objects as arguments.\\
{\tt GROBADD} concatenates its arguments and returns the result.\\
For example, if you previously saved the plot of ${\tt F(X)}$ into {\tt GRF},
and the plot of ${\tt H(X)}$ into {\tt GRH}, you can type:
$${\tt GROBADD(GRF,GRH)\ STO\triangleright\  GRFH}$$
This command stores into {\tt GRFH} a graphics object containing
the plots of both ${\tt F(X)}$ and ${\tt H(X)}$, one below the other.\\

% End of graeve_new.tex

\section{Bac 99 and HP49G}
\subsection{Introduction}
First of all, enter {\tt CASCFG} (Computer Algebra System ConFiG)
to put the calculator in algebraic mode and to initialize it.\\
The commands you will use can be found in the menu displayed by the
{\tt SYMB} key, and in the following sub-menus:\\
{\tt ALGEBRA (FACTOR LIN SUBST)}\\
{\tt ARITHMETIC (IEGCD ISPRIME? PROPFRAC)}\\
{\tt CALCULUS (DERIVX DERIV INTVX INT LIMIT)}\\
{\tt GRAPH (SIGNTAB TABVAR)}\\
{\tt TRIGONOMETR (TEXPAND)}\\
and in the {\tt red-shift 1 (CMPLX)} menu:\\
{\tt  RE IM }\\
Remember that after entering each command, it is necessary to press
{\tt ENTER} to execute it; this notice will often be omitted in
the following.\\

Here, you find the mathematics test of the ``Bac''\footnote{Translator's
note: In France, the ``Bac'' (short form of ``Baccalaur\'eat'')
certificate is awarded to students that successfully complete the
upper secondary school course, at about age 18.} 1999 test (S series) solved.\\
Effort has been made to leverage the HP49G capabilities as much as
possible, but you will notice that it is still the student's duty to
explain and justify his/her calculations, and to make a bit of
reasoning.

\subsection{Exercise 1}
The goal of this exercise is to plot the curve
$\Gamma$ represented by $M: \frac{1}{2}\cdot z^2-z$ when $m$,
represented by $z$, is a circle \textit{C} of center O and radius 1.
Let $t$ be a real in $[-\pi , \pi]$ and $m$ the point of \textit{C}
corresponding to $z=e^{i \cdot t}$.

\begin{enumerate}
\item Calculation of the coordinates of $M$ :\\
With the help of {\tt EQW}, we enter the expression
$\frac{1}{2}\cdot z^2-z $.\\
We type:\\
$${\tt EQW \ alpha \ Z \ y^x \ 2 \ \rhd\ \div\  2\ \rhd\ -\ alpha \ Z\ ENTER}$$
The expression is now in the command line, and we store it into
the variable {\tt M}:
$${\tt STO\triangleright\ M}$$
Since $z=e^{i \cdot t}$ we type:
$${\tt SUBST(M,Z=EXP(i\times t))}$$
the answer is:
$${\tt \frac{EXP(i\cdot t)^2 -2 \cdot EXP(i\cdot t)}{2}} $$
Now, we linearize the expression, using the history to copy
the previous expression down:
$${\tt LIN(HIST\  ENTER)\ ENTER}$$
the answer is:
$${\tt \frac{1}{2} \cdot EXP(2\cdot i\cdot t)+-1\cdot EXP(i\cdot t) }$$
Notice that by copying the expression down, the calculator simplifies it, too:
$${\tt \triangle\ ENTER\  ENTER }$$
gives:
$${\tt \frac{ EXP(2\cdot i \cdot t)-2\cdot EXP(i\cdot t)}{2}}$$
\begin{itemize}
\item
Now we want to look at the real part of this expression:
$${\tt RE(\ HIST\ ENTER)\ ENTER} $$
the answer is:
$${\tt \frac {COS ( t\cdot 2)-2\cdot COS(t)}{2}}$$
At this point, we can define the function $x(t)$, by typing:
$${\tt DEFINE\ (X(t) = \ HIST\ ENTER)\ ENTER}$$
\item
Then, we calculate the imaginary part
(we must climb up in the history to retrieve
the original expression
${\tt \frac{ EXP(2\cdot i \cdot t)-2\cdot EXP(i\cdot t)}{2}}$), typing:
$${\tt IM( HIST\ \triangle\ \triangle\ \triangle\ \triangle\ ENTER)\ ENTER} $$
the answer is:
$${\tt \frac {SIN ( t\cdot 2)-2\cdot SIN(t)}{2}}$$
To define the function $y(t)$, we must now type:
$${\tt DEFINE( Y(t) = \ HIST\ ENTER) ENTER}$$
\end{itemize}
\item To determine an axis of symmetry of  $\Gamma$,
we want to calculate $x(-t)$ and $y(-t)$; for this, we type:
$${\tt X(-t)\ ENTER}$$
the answer is:
$${\tt \frac {COS ( t\cdot 2)-2\cdot COS(t)}{2}}$$
Therefore: $x(-t)\ =\ x(t)$\\
after this, we type:
$${\tt Y(-t)\ ENTER}$$
the answer is:
$${\tt \frac {-SIN ( t\cdot 2)+2\cdot SIN(t)}{2}}$$
Therefore: $ y(-t)\ =\ -y(t)$\\
If $M_1 (x(t), y(t))$ is on $\Gamma, \ M_2 (x(-t),y(-t)$ is on
 $\Gamma$, too. \\
We have just showed that $M_1 $ and $M_2$ are symmetric
with respect to $Ox$; from this we conclude that the
$Ox$ axis is an axis of symmetry of $\Gamma$.
\item Calculation of $x'(t)$ :\\
We type:
$${\tt DERIV (X(t) ,t)}$$
the answer is:
$${\tt \frac {2 \cdot (-2 \cdot SIN ( t\cdot 2))-2\cdot(- SIN(t))}{4}}$$
that is, after simplification (${\tt \triangle \ ENTER \ ENTER} $):
$${\tt -(SIN ( t\cdot 2)- SIN(t))}$$
We now expand the expression
(transformation of ${\tt SIN(2 \cdot t)}$); we type:
$${\tt TEXPAND(\ HIST \ ENTER) \ ENTER}$$
the answer is:
$${\tt -(SIN ( t)\cdot 2 \cdot COS(t)- SIN(t))}$$
Now we factorize:
$${\tt FACTOR(\ HIST \ ENTER) \ ENTER} $$
the answer is:
 $${\tt -SIN ( t)\cdot (2 \cdot COS(t)- 1)}$$
At last, we can define $x'(t)$ by typing:
$${\tt DEFINE(\ X1(t)=\ HIST \ ENTER) \ ENTER}$$
\item Calculation of $y'(t)$ :\\
We type:
$${\tt DERIV (Y(t) ,t)}$$
the answer is:
$${\tt \frac {2 \cdot (2 \cdot COS( t\cdot 2))-2\cdot COS(t)}{4}}$$
that is, after simplification (${\tt \triangle \ ENTER \ ENTER} $):
$${\tt COS ( t\cdot 2)- COS(t)}$$
We now expand the expression (transformation of ${\tt COS(2 \cdot t)}$);
we type:
$${\tt TEXPAND(\ HIST \ ENTER) \ ENTER}$$
the answer is:
$${\tt  2 \cdot COS(t)^2-1- COS(t))}$$
Now we factorize:
$${\tt FACTOR(\ HIST \ ENTER) \ ENTER} $$
the answer is:
 $${\tt (COS ( t)-1)\cdot (2 \cdot COS(t)+1)}$$
At last, we can define $y'(t)$  by typing:
$${\tt DEFINE(\ Y1(t)=\ HIST \ ENTER) \ ENTER}$$
\item Variations of $x(t)$ and $y(t)$\\
To do this we draw on the same plot both
$x(t)$ and $y(t)$; we type:\\
{\tt  blue-shift F4 (2D/3D)}: the {\tt PLOT SETUP} window opens.\\
We choose {\tt function} as plot type, with the help of the
{\tt choos} menu key.\\
Then, we enter
$${\tt \{ X(t),Y(t)\} }$$ into the equation ({\tt EQ}) field, and
{\tt t} as independent variable, followed by {\tt ENTER}.\\
Afterwards, we type
{\tt blue-shift F2 (WIN)}, to set the plot window parameters.\\
\item Trace of $\Gamma$:
\begin{itemize}
\item Values of $x(t)$ and $y(t)$\\
We calculate the values of $x(t)$ and $y(t)$ for
$t=0,\frac{\pi}{3},\frac{2 \cdot \pi}{3},\pi$, by typing:
$${\tt X(0) \ ENTER}$$
answer: $\frac{-1}{2}$
$${\tt X(\pi \div 3) \ ENTER}$$
answer: $\frac{-3}{4}$
$${\tt X(2 \times \pi \div 3) \ ENTER}$$
answer: $\frac{1}{4}$
$${\tt X(\pi) \ ENTER}$$
answer: $\frac{3}{2}$
$${\tt Y(0) \ ENTER}$$
answer: $0$
$${\tt Y(\pi \div 3) \ ENTER}$$
answer: $\frac{-\sqrt3}{4}$
$${\tt Y(2 \times \pi \div 3) \ ENTER}$$
answer: $\frac{-3 \cdot \sqrt 3}{4}$
$${\tt Y(\pi) \ ENTER}$$
answer: $0$
\item Slope of tangents ( $m=\frac{y'(t)}{x'(t)}$)\\
We calculate the values of
$\frac{y'(t)}{x'(t)}$ for
$t=0,\frac{\pi}{3},\frac{2 \cdot \pi}{3},\pi$, by typing:
$${\tt LIMIT(\ Y1(t)/ X1(t),t=0) \ ENTER}$$
answer: $0$
$${\tt  LIMIT(\ Y1(t)/ X1(t),t=\pi \div 3) \ ENTER}$$
answer: $\infty$
$${\tt  LIMIT(\ Y1(t)/ X1(t),t=2 \times \pi \div 3) \ ENTER}$$
answer: $0$
$${\tt LIMIT(\ Y1(t)/ X1(t),t=\pi) \ ENTER}$$
answer: $\infty$\\
These are the variations of $x(t)$ and $y(t)$
$$\begin{array}{|c|ccccccc|}
\hline t & 0 & & \frac{\pi}{3} & & \frac{2\pi}{3} & &\pi \\\hline
x'(t)&0&-&0&+&?&+&0\\\hline
x(t)&\frac{-1}{2} & \downarrow & \frac{-3}{4} & \uparrow &\frac{1}{4} &
\uparrow &\frac{3}{2}\\\hline
y(t)&0&\downarrow & \frac{\sqrt3}{4} &\downarrow & \frac{-3\sqrt3}{4} &
\uparrow & 0\\\hline
y'(t)&0&-&?&-&0&+&?\\\hline
m &0&&\infty&&0&&\infty\\\hline
\end{array}$$

\item Plotting $\Gamma $:\\
We now plot the parametric curve.\\
We type:\\
{\tt  blue-shift F4 (2D/3D)} and the {\tt PLOT SETUP} opens up.\\
We choose the {\tt parametric} plot type,
with the help of the {\tt choos} menu key.
Then, we enter $${\tt X(t)+i \times Y(t)}$$ into the equation ({\tt EQ})
field and {\tt t} as independent variable, followed by {\tt ENTER}.\\
We then press
{\tt blue-shift F2 (WIN)} to set the plot window parameters.
\end{itemize}
\end{enumerate}

\subsection{Exercise 2 (specialized)}
Let be, for a natural $n$:
$$a_n=4 \times 10^n-1,\  b_n=2 \times 10^n-1 \mbox{ and } c_n=2 \times 10^n+1$$
We type:
$${\tt DEFINE(A(N)=4 \cdot 10^N-1)} $$
$${\tt DEFINE(B(N)=2 \cdot 10^N-1)} $$
$${\tt DEFINE(C(N)=2 \cdot 10^N+1)} $$
\begin{enumerate}
\item
\begin{itemize}
\item a) Calculate $a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3$ :\\
It suffices to type:
$${\tt A(1)}$$
answer 39
$${\tt B(1)}$$
answer 19
$${\tt C(1)}$$
answer 21
$${\tt A(2)}$$
answer 399
$${\tt B(2)}$$
answer 199
$${\tt C(2)}$$
answer 201
$${\tt A(3)}$$
answer 3999
$${\tt B(3)}$$
answer 1999
$${\tt C(3)}$$
answer 2001\\
\item b) number of digits and divisibility\\
Here, the calculator is useful only to do some evaluation trials
for different values of $n$...\\
We know that integers $n$ satisfying:
$$10^n \leq n < 10^{n+1} $$
have $(n+1)$ digits when they are written using the decimal representation.\\
We have:
$$3 \cdot 10^n\ <\ a_n\ < \ 4 \cdot 10^n$$
$$ 10^n\ <\ b_n\ < \ 2 \cdot 10^n$$
$$2 \cdot 10^n\ <\ c_n\ < \ 3 \cdot 10^n$$
so the decimal representation of $a_n,\ b_n,\ c_n$ has $(n+1)$ digits.\\

Moreover, $d_n=10^n-1$ is divisible by 9, since all digits of
its decimal representation are 9.\\
We have
$$a_n=3 \cdot 10^n\ +\ d_n$$
and $$c_n=3 \cdot 10^n\ -\ d_n$$
so $a_n$ and $c_n$ are divisible by 3.
\item c) $b_3$ is prime\\
We type:
$${\tt ISPRIME? (B(3))}$$
the answer is:
$${\tt 1.}$$
that means {\tt true}\\
To show that $b_3=1999$ actually is prime,
we only have to test if 1999 is divisible by all prime numbers
less than or equal to $\sqrt{1999}$.\\
Since $1999<2025=45^2$, we check the divisibility of 1999 with
$n=2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41$. \\
Since 1999 is not divisible by any of these numbers, we conclude
that 1999 actually is prime.
\item d)  $a_n=b_n \times c_n$\\
We type:
$${\tt B(N)\cdot C(N)}$$
The answer is:
$${\tt 4 \cdot {(10^N)}^2-1}$$
that is the same value as $a_n$\\
Factorization of $a_6$ into prime factors\\
We type:
$${\tt FACTOR(A(6))}$$
The answer is:
$${\tt 3 \cdot 23 \cdot 29 \cdot 1999}$$
\item e) $b_n \mbox{ et } c_n $ are mutually prime.\\
Here, the calculator is useful only to do some evaluation trials for
different values of $n$... \\
To show that $c_n$ and $b_n$ are mutually prime,
we observe that:
$$c_n=b_n+2$$
So, the common divisors of $c_n$ and $b_n$ are the
common divisors of $b_n $ and $2$, and are the
common divisors of $c_n$ and $2$, too.
$b_n $ and $2$ are mutually prime, because $b_n$ is a prime number
not equal to $2$. Therefore,
$$GCD(c_n,\ b_n)=GCD(c_n,\ 2)=GCD(b_n,\ 2)=1$$
\end{itemize}
\item Consider the equation:
$$b_3 \cdot x + c_3 \cdot y =1$$
\begin{itemize}
\item a) There is at least a solution, because we can apply
the B\'ezout identity.
In fact, the B\'ezout theorem states that:\\
If $a$ and $b$ are mutually prime, two values $x$ and $y$ do exist so that:
$$a \cdot x + b \cdot y =1$$
Therefore, the equation:
$$b_3 \cdot x + c_3 \cdot y =1$$ has at least a solution.\\
\item b)We type:
$${\tt IEGCD(B(3),C(3))}$$
the answer is:
$${\tt \{ 1,1000,-999\}}$$
this means that:
$$1=b_3 \times 1000 +c_3 \times (- 999)$$
so, we have just found a (particular) solution: \\
$x=1000, \ y=-999$.\\
By hand, we write:\\
$ c_3\ =\ b_3\ +\ 2$ and $b_3\ =\ 999\ \times \ 2 \ +\ 1$\\
so,  $b_3\ =\ 999\ \times \ (c_3 \ -\ b_3) \ +\ 1$
and:
$$b_3 \times 1000 +c_3 \times (- 999)\ =\ 1$$
\item c)
Here, the calculator cannot find the general solution.\\
We have:
$$b_3 \cdot x + c_3 \cdot y\ =\ 1$$
and
$$b_3 \times 1000 +c_3 \times (- 999)\ =\ 1$$
subtracting the second equation from the first, we have:
$$b_3 \cdot (x-1000 )+ c_3 \cdot (y+999)\ =\ 0$$
and then:
$$b_3 \cdot (x-1000 )\ =\ - c_3 \cdot (y+999)\ $$
Applying the Gauss theorem: $c_3$ is prime with $b_3$, so
$c_3$ divides $(x-1000)$.\\
Therefore, it exists $ k\ \in Z$ so that:
$$(x-1000)=k \times c_3 $$
and
$$-(y+999)=k \times b_3$$
Reciprocally, let be:
 $$x\ =\ 1000\ +\ k \times\ c_3$$
and
$$y\ =\ -999\ -\ k \times\ b_3 \ \mbox{   for   }\ k\ \in Z$$ \\
We have:
$$b_3 \cdot x+ c_3 \cdot y =b_3 \times 1000 +c_3 \times (- 999)\ =\ 1$$
The general solution therefore is: $\mbox{for any } k\ \in Z$ :
$$x\ =\ 1000\ +\ k \times\ c_3$$
$$y\ =\ -999\ -\ k \times\ b_3$$
\end{itemize}
\end{enumerate}

\subsection{Exercise 2 (not specialized)}
Let us consider the succession
$$u_n=\int _0 ^2\ \frac{2x+3}{x+2}\ e^\frac{x}{n}\ dx$$
\begin{enumerate}
\item
\begin{itemize}
\item a) Variations of $g(x)=\frac{2x+3}{x+2} \mbox{ for } x\in [0,2]$\\
We type:
$${\tt DEFINE(G(X)=\frac{2X+3}{X+2})}$$
then, we type:
$${\tt TABVAR(G(X))}$$
We obtain:
$$\begin{array}{cccccc} -\infty & + & -2 & + & +\infty & X\\
 2 & \uparrow & \infty & \uparrow & 2 & F
\end{array}$$
The first line gives the sign of  {\tt f'(x)} depending on $x$,
and the second one gives the variations of {\tt f(x)}.

From this result, we conclude that
$g(x)$ increases in the interval $[0,2]$.\\
Notice that if the calculator is in step-by-step mode
(to enable this mode, you must press on
{\tt MODE}, then on the {\tt cas} menu key, and set {\tt Step/Step}
using the {\tt chk} menu key followed by
{\tt ok ok}), we obtain (the input function is denoted by {\tt F}):
$${\tt F:= \frac{2 \cdot X+3}{X+2}}$$
After pressing the {\tt ok} menu key, we obtain:
$${\tt F':=\frac{2 \cdot (X+2)-(2 \cdot X+3)}{SQ(X+2)}}$$
and, using the $\bigtriangledown$ arrow key to
scroll the screen:
$${\tt \rightarrow \frac{1}{(X+2)^2}}$$
At last, pressing the {\tt ok} menu key again displays the variation table.\\

If the step-by-step mode is disabled, it is possible to calculate
the derivative with:
$${\tt DERVX(G(X))}$$

We want to calculate $g(0)$ and $g(2)$; to do this we type:
$${\tt G(0)}$$
answer $\frac{3}{2}$
$${\tt G(2)}$$
answer $\frac{7}{4}$\\

$$\frac{3}{2} \leq g(x) \leq \frac{7}{4} \ \mbox{ for } x\in [0,2]$$

\item b) Here the calculator is not useful at all... it is enough
to notice that:
$$e^\frac{x}{n} \geq 0 \ \mbox{   for } x\in [0,2] $$
to show that, for $x\in [0,2]$, we have:
$$\frac{3}{2}e^\frac{x}{n}\leq g(x)e^\frac{x}{n} \leq
\frac{7}{4}e^\frac{x}{n}$$

\item c) We integrate the inequality written above, typing:
$${\tt \int _0^2\  e^\frac{X}{N}\ dX} $$
We obtain:
$${\tt N \cdot e^\frac{2}{N} -N } $$
From this, we conclude that:
$$\frac{3}{2}(n e^\frac{2}{n}-n) \leq u_n \leq \frac{7}{4}(ne^\frac{2}{n}-n)$$
To justify the previous calculation, we must also say that
a primitive of
$ e^\frac{x}{n}$ is $n \cdot e^\frac{x}{n}$.\\
If we don't know this, we can always type:
$${\tt INTVX(EXP(X \div N))}$$
and the answer is: ${\tt N \cdot e^\frac{X}{N}}$

\item d)
We look for the limit of $(n e^\frac{2}{n}-n)$ when $n \rightarrow +\infty$:
$${\tt LIMIT(N \cdot EXP(2 \div N) -N\ ,\ N=+\infty)}$$
We obtain:
$${\tt 2}$$
To explain this result, we must say that:
$$\lim_{x \rightarrow 0}\frac{e^x-1}{x}=1$$
and, as a consequence:
$$\lim_{n \rightarrow +\infty}\frac{e^\frac{2}{n}-1}{\frac{2}{n}}=1$$
or, also:$$\lim_{n \rightarrow +\infty}(e^\frac{2}{n}-1)\cdot n=2$$
If $L$ does exist, letting $n$ go towards $+\infty$
in the inequalities of point 1b), we obtain:
$$\frac{3}{2} \cdot 2 \leq L \leq \frac{7}{4} \cdot 2$$
\end{itemize}

\item
\begin{itemize}
\item a) $g(x)=2-\frac{1}{x+2}$ and calculation of $I= \int _0 ^2 g(x)dx$\\
We type:
$${\tt PROPFRAC(G(X))}$$
We obtain:
$${\tt 2-\frac{1}{X+2}}$$
To calculate $I$, we type in the equation editor ({\tt EQW} key):
$${\tt \int _0 ^2 G(X)dX}$$
We obtain:
$${\tt -(LN(2)-4)}$$
Doing it by hand, we have $2x+3=2(x+2)-1$, so $$g(x)=2-\frac{1}{x+2}$$
We now integrate term by term between $0 $ et $2$, obtaining:
$$\int_0^2 g(x)dx=[2x-\ln(x+2)]_{x=0}^{x=2}$$
that is, since $\ln4=2\ln2$:
$$\int_0^2 g(x)dx=4- \ln2$$

\item b) Here, the calculator is not useful... it is enough to notice that
$e^\frac{x}{n}$ increases for $x \in [0,2]$, to obtain the inequality:
$$1 \ \leq \ e^\frac{x}{n} \ \leq e^\frac{2}{n} $$
then, since $g(x)$ is positive on $[0,2]$, we have:
$$g(x)\ \leq \ g(x)e^\frac{x}{n}\ \leq g(x)e^\frac{2}{n}  $$
integrating we have:
$$I \ \leq u_n \ \leq \ e^\frac{2}{n}I $$

\item c) Convergence of $u_n$\\
We look for the limit of $e^\frac{2}{n}$ when $n \rightarrow +\infty$ :
$${\tt LIMIT(EXP(2 \div N)\ , \ N=+\infty)}$$
We obtain:
$${\tt 1}$$
Actually, $\frac{2}{n}$ goes towards 0 when $n$ goes towards $+\infty$, so
$e^\frac{2}{n}$ goes towards $e^0=1$ when $n$ goes towards $+\infty$.\\
When $n$ goes towards $+\infty$, $u_n$ stays between $I$ and a
quantity that goes towards $I$ (see the inequalities in point 2b)).\\
Therefore, $u_n$ converges and its limit is $I$.\\
We have shown that:$$L=I=4- \ln2$$
\end{itemize}

\end{enumerate}
\subsection{Problem}
\textbf{Part A}\\
Let a function $f$ be defined on $]0,\ +\infty[$ as
$$f(x)=\left( 1-\frac{1}{x}\right)(\ln x-2)$$
We type (using the Equation Writer):
$${\tt DEFINE(F(X)=(1-1 \div X)\times (LN(X)-2))}$$
This is, in detail, the sequence of keys we must press
($\triangleleft$ represents the cursor):
$${\tt DEFINE( F(X)=\triangleleft ) }$$
To enter the expression that follows, using the equation editor,
we press the {\tt EQW} key.\\
We now are in the equation editor; we type:
$${\tt 1 \ - \ 1 \ \div \ X \rhd \ \rhd \ \rhd \ \times\ LN(X) \ \rhd \ -
 \ 2 \ ENTER} $$
In the command line, we have:
$${\tt DEFINE(F(X)=(1-\frac{1}{ X})\cdot (LN(X)-2))}$$
At this point, we press {\tt ENTER} to execute it.\\
${\tt F}$ is added to the variable's menu and {\tt NOVAL} is displayed
in the screen.\\
To check our work, we type ${\tt F(X)}$; we should obtain:
$${\tt \frac{(X-1)\cdot LN(X)-(2\cdot X-2)}{X}}$$

\begin{enumerate}
\item Limit of $f$ in $+\infty$ and $0$.\\
We type:
$${\tt LIMIT (F(X),+\infty)}$$
answer\  $+\infty$\\
then,
$${\tt LIMIT (F(X),0)}$$
answer $\infty$
\item Calculation of $f'(x)$.\\
We type:
$${\tt DERVX(F(X))}$$
We obtain:
$${\tt \frac{LN(X)+X-3}{X^2}}$$
\item $u(x)=\ln x+x-3$\\
Now, we type:
$${\tt DEFINE(U(X)= LN(X)+X-3)}$$
\begin{itemize}
\item a) Variations of $u$.\\
We type:
$${\tt TABVAR(U(X))}$$
The calculator asks to enable complex mode: answer
{\tt YES}.\\
We obtain:
$$\begin{array}{cccccccc} -\infty & + & -1 & - & 0 & + & +\infty &X\\
 -\infty  & \uparrow & i\pi-4 & \downarrow& -\infty& \uparrow &  +\infty&
F
\end{array}$$
Warning!!!!\\
Only the portion of table in which $x>0$ 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<f(\alpha)<-0.654$$
This is an approximation with tolerance
$9\cdot 10^{-3} \mbox{( since 
} 0.663-0.654=9\cdot 10^{-3})$\\
or, again:$$-0.67<f(\alpha)<-0.65$$
that is an approximation with tolerance $2\cdot 10^{-2} \mbox{( since }
0.67-0.65=2\cdot 10^{-2})$

\end{itemize}

\item
\begin{itemize}
\item a) Sign of $f$\\
We notice that $f(1)=0$ and that $f(e^2)=0$\\
We type:
$${\tt F(1)}$$
answer : 0
$${\tt F(EXP(2))}$$
answer : 0\\
These are the variations of $f$ and the sign of $f(x)$ :
$$\begin{array}{|c|ccccccccc|} \hline f'(x) & 0 & -& 1 &- & \alpha
& +&e^2&+ & +\infty\\ \hline
f(x) & +\infty & \downarrow&0&\downarrow & \frac{\alpha-1}{\alpha}(ln( 
\alpha)-2) & \uparrow & 0& \uparrow & +\infty\\
\hline
f(x)& +\infty &+&0&-&\simeq-0.66&-&0&+& +\infty\\ \hline
\end{array}$$

\item b) Plot $\textit{C}$ of $f$\\
We open the {\tt PLOT SETUP (blue$\_$shift \ F4) } menu,
we choose {\tt function } and  {\tt F(X)} for {\tt EQ}, then
we set the window parameters in {\tt WIN (blue$\_$shift \ F2) }
\end{itemize}
\end{enumerate}

\textbf{Part B}\\
Let $H$ be the antiderivative of $f$ in $]0, \ +\infty[$ and $\Gamma $ its
plot.\\
Be careful with the notations; they are not the same as those of the
textbook!\\

\begin{enumerate}
\item
\begin{itemize}
\item a) Variations of $H$\\
Since $H'(x)=f(x)$ we have the following variation table:
$$\begin{array}{c|ccccccc}
f(x) & 0 & + & 1 & - & e^2 & + &+\infty\\ \hline
H(x) & ? & \uparrow\ & 0 & \downarrow & ? & \uparrow & ?
\end{array}$$
\item b) Tangent lines for $x=1$ and $x=e^2$\\
It is $f(1)=0$ and  $f(e^2)=0$. The tangents of $\Gamma$ for
the abscissas $1$ and $e^2$ have a zero slope, and
are therefore horizontal.
\end{itemize}

\item Calculation of $H(x)$  \\
\begin{itemize}
\item a) Calculation of $\int _1^x \ln tdt$\\
In the equation editor, we type:
$${\tt \int _1^X LN (T)dT}$$
We obtain:
$${\tt X \cdot LN(X)-(X-1)}$$
We can also ask for the antiderivative of
$\ln x$, we type:
$${\tt INTVX(LN(X))}$$
We obtain:
$${\tt X \cdot LN(X)-X}$$
By hand, we set $u=\ln(t)$ and $ dv=dt$, so $du=\frac{dt}{t} $
and $ v=t$ we have:
$$\int_1^x \ln t \ dt= [t \cdot \ln t ]_{t=1}^{t=x}-\int_1^x t
\cdot\frac{dt}{t} =x \cdot \ln x - \int_1^x dt=x \cdot \ln x - (x-1)$$

%$${\tt IBP(\int _1^X LN (t)dt,t)} $$
%on obtient :
%$${\tt X \cdot LN(X)-\int_1 ^X 1dt}$$
\item b) Expanding the expression of $f(x)$ we obtain:
$$f(x)=\ln x -\frac{\ln x}{x}+ \frac{2}{x}-2$$

\item c) Expression of $H(x)$\\
We type (using the equation writer):
$${\tt DEFINE(H(X)=\int_1^X F(T)dT)}$$
then,
$${\tt H(X) \ ENTER}$$

We obtain:
$${\tt -\frac{LN(X)^2-(2 \cdot X+4) \cdot LN(X) +6 \cdot X-6}{2}}$$
We do the calculation by hand, integrating term by term the
expression of $f(x)$ found in 2b); we have:
$$\int_1^x \ln t\ dt=x \ln x-x+1$$
$$-\int_1^x \frac{\ln t}{t}\ dt=- \frac{(\ln x)^2}{2}$$
$$\int_1^x \frac{2}{t}\ dt=2 \ln x$$
that's why:
$$H(x)=x \ln x-x+1 - \frac{(\ln x)^2}{2}+2 \ln x-2x+2 $$
$$H(x)= - \frac{(\ln x)^2}{2}+(x+2) \ln x-3x+3 $$
\end{itemize}

\item
\begin{itemize}
\item a)
We type
$${\tt LIMIT(LN(X)/X,X=0)}$$
answer 0\\
From the course, we know that
``$x$ dominates $\ln x$''; this explains the result!\\
We type:
$${\tt LIMIT(H(X),X=0)}$$
answer $-\infty$\\
We have: $$H(x)=x \ln x+\ln x \frac{(4-\ln x)}{2}-3x+3 $$
When $x$ goes towards 0, the first term of $H(x)$ goes towards 0,
its second term goes towards
$-\infty$ (because $\ln x $ goes towards  $-\infty$ when $x$
goes towards $0$), and the following terms go towards 3.\\ 
Threrefore, $$\lim_{x \rightarrow 0}H(x)=-\infty$$

\item b)
We type:
$${\tt LIMIT(H(X),X= +\infty)}$$
answer $+\infty $\\
We put in evidence $x \ln x$ at the beginning of $H(x)$, obtaining:
$$H(x)=x \ln x(1-\frac{\ln x}{2x}+\frac{2}{x}-\frac{3}{\ln x})+3$$
$$\lim_{x \rightarrow +\infty }x \ln x=+\infty$$
and the term within paretheses goes towards 1 when $x$ goes towards
$+\infty $, so
 $$\lim_{x \rightarrow+\infty }H(x)=+\infty$$

\item c) Variations of $H(x)$\\
We calculate $H(e^2)$\\
We type:
$${\tt H(EXP(2))}$$
The result is the expression obtained replacing, in
${\tt H(X)}$, {\tt X} with ${\tt EXP(2) }$.\\
We copy this expression to simplify it:
 (${\tt \triangle\ ENTER\ ENTER} $), obtaining:
$${\tt -(EXP(2)-5)}$$
then,
$${\tt\triangle\ ENTER \ red-shift\ ENTER} $$
answer\ \ -2.38905...\\
We have also an approximate value of $H(e^2)$.\\
We recall the table already worked out in 1a)
$$\begin{array}{c|ccccccc}
f(x) & 0 & + & 1 & - & e^2 & + &+\infty\\ \hline
H(x) &-\infty  & \uparrow & 0 & \downarrow & \simeq-2.39 & \uparrow & +\infty\
\end{array}$$

\item d) Plot $\textit{C}$ of $f$ and plot $\Gamma$ of $H$\\
We open the {\tt PLOT SETUP (blue$\_$shift \ F4) }window,
choose {\tt function } and put {\tt \{F(X),H(X)\}} in the {\tt EQ} field,
then we set the window parameters using {\tt WIN (blue$\_$shift \ F2) }.
\end{itemize}


\item Area calculation\\
We have calculated:
$$\int_1 ^{e^2} f(x)dx$$
obtaining:
$${\tt -(EXP(2)-5)} $$
this integral is negative because the function is below the $x$ axis
between $1$ and $e^2$.
Since the measurement unit is 2cm, the area expressed in cm$^2$
is therefore equal to $-4H(e^2)$cm$^2$, that is :
$$4\cdot{\tt (EXP(2)-5)}\ \mbox{ cm}^2$$
that is, $$A=( 4e^2-20)\ \mbox{ cm}^2$$
or
$$9.55\ \mbox{ cm}^2\ <\ A\ <\ 9.56\ \mbox{ cm}^2 $$
\end{enumerate}

\subsection{Conclusion}
We have showed that a good leverage of the HP49G calculator's
capabilities enabled us to solve a large portion of the problems...\\
However, we must also notice that for arithmetic problems, more
reasoning is needed: then, the calculator is useful to do checks and
verifications...

\section{Programming}
\subsection{Programming in algebraic mode}

\subsubsection{Entering a program}
You write a program in the command line, between delimiters
${\tt \ll}$ and ${\tt \gg}$

\subsubsection{Saving a program}
It is enough to append
$${\tt STO\triangleright \ NOMDUPROGRAMME}$$
after the last $\gg$ delimiter.

\subsubsection{Editing a program}
When entering a program, if the program syntax is bad, the calculator
automatically places the command line cursor where the compiler has
detected the error, so you can immediately fix it!!!

Instead, if the error is detected during program execution, you must
enter:\\
{\tt VISIT('NOMDUPROGRAMME')}\index{VISIT} to edit the program
stored in the {\tt NOMDUPROGRAMME} variable.\\
You can then edit it; {\tt ENTER} saves the edited program.

\subsubsection{Executing a program}
If the program has no parameters, you type its name in the command line;
if it has one or more parameters, the program name must be followed
by its arguments, enclosed in brackets and delimited by commas.

Example:
{\tt PGCD(45,75)}

\subsubsection{Modifying a program and saving it with another name}
You type:\\
{\tt RCL('NOMDUPROGRAMME')} and press the {\tt edit} menu key.\\

Then, you modify the program as you wish, and append
$${\tt STO\triangleright \ NOUVEAUNOM}$$
after the last $\gg$ delimiter.

\subsection{Program comments}
It is a good habit to put comments in programs.

In algorithmic language a comment starts with
{\tt // } and ends at the end of the line.

On the {\tt HP49G}, a comment starts with {\tt @} and ends at
the end of the line or when another {\tt @} is encountered.

You obtain the {\tt @} character by pressing {\tt red-shift ENTER}.

Warning!!! The compiler deletes all comments so, to preserve your
comments, you should store the program as a text string and then
compile it with ${\tt STR\rightarrow}$; this makes things a little
more difficult, though...

\subsection{Variables}
\subsubsection{Variable names}
Variables are places where you can store values, numbers,
expressions and any other object.

% Avec la {\tt HP49G}, on peut utiliser des noms ayant jusqu'=E0 8 caract=E8=
% res.

\subsubsection{Local variables}
The {\tt HP49G} has local variables. Local variables are both
declared and initialized (the initialization is mandatory!) with
\ ${\tt \ \rightarrow\ \ (red-shift \ 0)}$\\

In {\tt RPN} mode, you can define and initialize more than one
variable at once, for example:
$${\tt \ll 1\ 2\ \rightarrow\  A\ B \ll subprogram body \gg \gg }$$
In {\tt Algebraic} mode, each definition must be followed by
a subprogram (with delimiters
${\tt \ll \gg}$).\\

The arrow must be surrounded by spaces (these spaces are automatically
inserted when the calculator is not in $\alpha$ mode).\\
Example :
$${\tt \ll   3.14\  \rightarrow\  PI
\ll 2*PI*R \gg \gg STO\triangleright \  PER}$$
In this example, we have written a program named {\tt PER}.\\ {\tt PI}
is a local variable defined and initialized by the code fragment
${\tt 3.14 \ \rightarrow \ PI} $.  The scope of this variable
is limited to the subprogram that follows its definition
(here, ${\tt \ll 2*PI*R \gg}$). \\
On the other hand, {\tt R} is a global variable (it must exist
before the program {\tt PER} is executed).  If, during the execution
of a program, you want to store a value into a variable (either local
or global), you must use the ${\tt STO\triangleright}$ operator.

\subsubsection{Parameters}
When you define a function, it is possible to use parameters.\\
For example, if you want {\tt R} to be a parameter of function
{\tt PER}, you should write:
$${\tt \ll\ \rightarrow\ R \ll  3.14\ \rightarrow\ PI \ll 2*PI*R \gg \gg
\gg STO\triangleright \  PER}$$
Parameter {\tt R} behaves the same as local variables; the only
difference is that it is initialized when the function is invoked.\\
The invocation is done when, for example, you evaluate:
{\tt PER(5)}.\\
To define a function with two argument, the correct syntax,
in both {\tt RPN} and {\tt Algebraic} modes is:
$${\tt  \ll\ \ \rightarrow\ A \ B  \ll\ ...}$$

\subsection{Data input}

\subsubsection{Translation in algorithmic language}
To denote that the user enters a value into variable
{\tt A} during the execution of a program, in algorithmic language
you write: {\tt input A} \\
To input values into {\tt A} and {\tt B} you write: {\tt input A,B}

\subsubsection{Translation for the HP49G in RPN mode}
{\tt 'A' PROMPTSTO}\index{PROMPTSTO} \\
or\\
{\tt "A" "" INPUT STR-> 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}
