\subsection{canonical}
\label{labcanonical}
\noindent Name: \textbf{canonical}\\
\phantom{aaa}brings all polynomial subexpressions of an expression to canonical form or activates, deactivates or checks canonical form printing\\[0.2cm]
\noindent Library names:\\
\verb|   void sollya_lib_set_canonical_and_print(sollya_obj_t)|\\
\verb|   void sollya_lib_set_canonical(sollya_obj_t)|\\
\verb|   sollya_obj_t sollya_lib_canonical(sollya_obj_t)|\\
\verb|   sollya_obj_t sollya_lib_get_canonical()|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{canonical}(\emph{function}) : \textsf{function} $\rightarrow$ \textsf{function}\\
\textbf{canonical} = \emph{activation value} : \textsf{on$|$off} $\rightarrow$ \textsf{void}\\
\textbf{canonical} = \emph{activation value} ! : \textsf{on$|$off} $\rightarrow$ \textsf{void}\\
\end{center}
Parameters: 
\begin{itemize}
\item \emph{function} represents the expression to be rewritten in canonical form
\item \emph{activation value} represents \textbf{on} or \textbf{off}, i.e. activation or deactivation
\end{itemize}
\noindent Description: \begin{itemize}

\item The command \textbf{canonical} rewrites the expression representing the function
   \emph{function} in a way such that all polynomial subexpressions (or the
   whole expression itself, if it is a polynomial) are written in
   canonical form, i.e. as a sum of monomials in the canonical base. The
   canonical base is the base of the integer powers of the global free
   variable. The command \textbf{canonical} does not endanger the safety of
   computations even in \sollya's floating-point environment: the
   function returned is mathematically equal to the function \emph{function}.

\item An assignment \textbf{canonical} = \emph{activation value}, where \emph{activation value}
   is one of \textbf{on} or \textbf{off}, activates respectively deactivates the
   automatic printing of polynomial expressions in canonical form,
   i.e. as a sum of monomials in the canonical base. If automatic
   printing in canonical form is deactivated, automatic printing yields to
   displaying polynomial subexpressions in Horner form.
    
   If the assignment \textbf{canonical} = \emph{activation value} is followed by an
   exclamation mark, no message indicating the new state is
   displayed. Otherwise the user is informed of the new state of the
   global mode by an indication.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(canonical(1 + x * (x + 3 * x^2)));
1 + x^2 + 3 * x^3
> print(canonical((x + 1)^7));
1 + 7 * x + 21 * x^2 + 35 * x^3 + 35 * x^4 + 21 * x^5 + 7 * x^6 + x^7
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(canonical(exp((x + 1)^5) - log(asin(((x + 2) + x)^4 * (x + 1)) + x)));
exp(1 + 5 * x + 10 * x^2 + 10 * x^3 + 5 * x^4 + x^5) - log(asin(16 + 80 * x + 16
0 * x^2 + 160 * x^3 + 80 * x^4 + 16 * x^5) + x)
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> canonical;
off
> (x + 2)^9;
512 + x * (2304 + x * (4608 + x * (5376 + x * (4032 + x * (2016 + x * (672 + x *
 (144 + x * (18 + x))))))))
> canonical = on;
Canonical automatic printing output has been activated.
> (x + 2)^9;
512 + 2304 * x + 4608 * x^2 + 5376 * x^3 + 4032 * x^4 + 2016 * x^5 + 672 * x^6 +
 144 * x^7 + 18 * x^8 + x^9
> canonical;
on
> canonical = off!;
> (x + 2)^9;
512 + x * (2304 + x * (4608 + x * (5376 + x * (4032 + x * (2016 + x * (672 + x *
 (144 + x * (18 + x))))))))
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{horner} (\ref{labhorner}), \textbf{print} (\ref{labprint}), \textbf{autosimplify} (\ref{labautosimplify})
