\hypertarget{optimize_8cc}{}\doxysection{optimize.\+cc File Reference}
\label{optimize_8cc}\index{optimize.cc@{optimize.cc}}
{\ttfamily \#include $<$vector$>$}\newline
{\ttfamily \#include $<$stack$>$}\newline
{\ttfamily \#include $<$algorithm$>$}\newline
{\ttfamily \#include $<$set$>$}\newline
{\ttfamily \#include $<$map$>$}\newline
{\ttfamily \#include $<$climits$>$}\newline
{\ttfamily \#include $<$cmath$>$}\newline
{\ttfamily \#include $<$string$>$}\newline
{\ttfamily \#include $<$iostream$>$}\newline
{\ttfamily \#include $<$tr1/unordered\+\_\+map$>$}\newline
{\ttfamily \#include $<$tr1/unordered\+\_\+set$>$}\newline
{\ttfamily \#include \char`\"{}form3.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}mytime.\+h\char`\"{}}\newline
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
class \mbox{\hyperlink{classtree__node}{tree\+\_\+node}}
\item 
struct \mbox{\hyperlink{structCSEHash}{CSEHash}}
\item 
struct \mbox{\hyperlink{structCSEEq}{CSEEq}}
\item 
struct \mbox{\hyperlink{structnode}{node}}
\item 
struct \mbox{\hyperlink{structNodeHash}{Node\+Hash}}
\item 
struct \mbox{\hyperlink{structNodeEq}{Node\+Eq}}
\item 
class \mbox{\hyperlink{classoptimization}{optimization}}
\end{DoxyCompactItemize}
\doxysubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{optimize_8cc_adcce2ad1d5c8ca216a02505517168316}\label{optimize_8cc_adcce2ad1d5c8ca216a02505517168316}} 
typedef struct \mbox{\hyperlink{structnode}{node}} {\bfseries NODE}
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{optimize_8cc_aa62d63886ab915072922b1f23b0851a7}\label{optimize_8cc_aa62d63886ab915072922b1f23b0851a7}} 
void {\bfseries print\+\_\+instr} (const vector$<$ WORD $>$ \&instr, WORD num)
\item 
{\footnotesize template$<$class Random\+Access\+Iterator $>$ }\\void \mbox{\hyperlink{optimize_8cc_adefbae07efcb5278e0fed2653443eab3}{my\+\_\+random\+\_\+shuffle}} (PHEAD Random\+Access\+Iterator fr, Random\+Access\+Iterator to)
\item 
LONG \mbox{\hyperlink{optimize_8cc_abcc71a308991ae8dc729fb69c6222cf8}{get\+\_\+expression}} (int exprnr)
\item 
vector$<$ vector$<$ WORD $>$ $>$ \mbox{\hyperlink{optimize_8cc_adae1c48384d6b3d171c1b5e2bf2953d7}{get\+\_\+brackets}} ()
\item 
int \mbox{\hyperlink{optimize_8cc_a6021663b5861197cb619dfbf0b61c98f}{count\+\_\+operators}} (const WORD $\ast$expr, bool print=false)
\item 
int \mbox{\hyperlink{optimize_8cc_a6ed4fa10a3e861decd68281769e77ded}{count\+\_\+operators}} (const vector$<$ WORD $>$ \&instr, bool print=false)
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_ab193934e627fad1810f2844c63ecb139}{occurrence\+\_\+order}} (const WORD $\ast$expr, bool rev)
\item 
WORD \mbox{\hyperlink{optimize_8cc_af0fd473fa3804ea755fca497f7d89f6a}{getpower}} (const WORD $\ast$term, int var, int pos)
\item 
void \mbox{\hyperlink{optimize_8cc_acf3f8c95c8f6b3d1b06bedce470afe97}{fixarg}} (UWORD $\ast$t, WORD \&n)
\item 
\mbox{\Hypertarget{optimize_8cc_a05d1608e0dd2f21122a5fac16bef8fc5}\label{optimize_8cc_a05d1608e0dd2f21122a5fac16bef8fc5}} 
void {\bfseries Gcd\+Long\+\_\+fix\+\_\+args} (PHEAD UWORD $\ast$a, WORD na, UWORD $\ast$b, WORD nb, UWORD $\ast$c, WORD $\ast$nc)
\item 
\mbox{\Hypertarget{optimize_8cc_a313eb973f69c08d949385c53e19a2c7e}\label{optimize_8cc_a313eb973f69c08d949385c53e19a2c7e}} 
void {\bfseries Div\+Long\+\_\+fix\+\_\+args} (UWORD $\ast$a, WORD na, UWORD $\ast$b, WORD nb, UWORD $\ast$c, WORD $\ast$nc, UWORD $\ast$d, WORD $\ast$nd)
\item 
void \mbox{\hyperlink{optimize_8cc_acea6d5654ede742b4d4b9da416116f5d}{build\+\_\+\+Horner\+\_\+tree}} (const WORD $\ast$$\ast$terms, int numterms, int var, int maxvar, int pos, vector$<$ WORD $>$ $\ast$res)
\item 
bool \mbox{\hyperlink{optimize_8cc_add58d2f1e0422685a10f31a3a0a16b57}{term\+\_\+compare}} (const WORD $\ast$a, const WORD $\ast$b)
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_a274a87bfb03189ac75814d90d5e68701}{Horner\+\_\+tree}} (const WORD $\ast$expr, const vector$<$ WORD $>$ \&order)
\item 
\mbox{\Hypertarget{optimize_8cc_a12c175d3af7d1212f5e4c44d9a2c125a}\label{optimize_8cc_a12c175d3af7d1212f5e4c44d9a2c125a}} 
void {\bfseries print\+\_\+tree} (const vector$<$ WORD $>$ \&\mbox{\hyperlink{structtree}{tree}})
\item 
\mbox{\Hypertarget{optimize_8cc_ad2d40508034b7fabd464faefeed95fee}\label{optimize_8cc_ad2d40508034b7fabd464faefeed95fee}} 
{\footnotesize template$<$typename T $>$ }\\size\+\_\+t {\bfseries hash\+\_\+range} (T $\ast$array, int size)
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_a2d7b65dcb6f75e092976b87f6ffc13f5}{generate\+\_\+instructions}} (const vector$<$ WORD $>$ \&\mbox{\hyperlink{structtree}{tree}}, bool do\+\_\+\+CSE)
\item 
int \mbox{\hyperlink{optimize_8cc_abab9eca226619182e82960044cee4be4}{count\+\_\+operators\+\_\+cse}} (const vector$<$ WORD $>$ \&\mbox{\hyperlink{structtree}{tree}})
\item 
\mbox{\Hypertarget{optimize_8cc_afa80cf157ecf9fe6e0576f80448d3aec}\label{optimize_8cc_afa80cf157ecf9fe6e0576f80448d3aec}} 
\mbox{\hyperlink{structnode}{NODE}} $\ast$ {\bfseries build\+Tree} (vector$<$ WORD $>$ \&\mbox{\hyperlink{structtree}{tree}})
\item 
\mbox{\Hypertarget{optimize_8cc_a44711030e302db551d5970aff3ccca25}\label{optimize_8cc_a44711030e302db551d5970aff3ccca25}} 
int {\bfseries count\+\_\+operators\+\_\+cse\+\_\+topdown} (vector$<$ WORD $>$ \&\mbox{\hyperlink{structtree}{tree}})
\item 
\mbox{\Hypertarget{optimize_8cc_a3609756bbdfe04bc3a58021e709f6bf4}\label{optimize_8cc_a3609756bbdfe04bc3a58021e709f6bf4}} 
vector$<$ WORD $>$ {\bfseries simulated\+\_\+annealing} ()
\item 
\mbox{\Hypertarget{optimize_8cc_aebb06a6c8e0e95ed8b73a01f0b343a09}\label{optimize_8cc_aebb06a6c8e0e95ed8b73a01f0b343a09}} 
void {\bfseries find\+\_\+\+Horner\+\_\+\+MCTS\+\_\+expand\+\_\+tree} ()
\item 
void \mbox{\hyperlink{optimize_8cc_a895adb819258c8f5a95d3635bb608575}{find\+\_\+\+Horner\+\_\+\+MCTS}} ()
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_ad898f09d5c8951bc139dae96b1121648}{merge\+\_\+operators}} (const vector$<$ WORD $>$ \&all\+\_\+instr, bool move\+\_\+coeff)
\item 
vector$<$ \mbox{\hyperlink{classoptimization}{optimization}} $>$ \mbox{\hyperlink{optimize_8cc_a38297edbfede135a1fb148b10635500d}{find\+\_\+optimizations}} (const vector$<$ WORD $>$ \&instr)
\item 
bool \mbox{\hyperlink{optimize_8cc_ac21af0c2bd95ce022dd1aa04ef3c87ed}{do\+\_\+optimization}} (const \mbox{\hyperlink{classoptimization}{optimization}} optim, vector$<$ WORD $>$ \&instr, int newid)
\item 
int \mbox{\hyperlink{optimize_8cc_ac3e43a3ac83c7fbe414e9dd75db0073a}{partial\+\_\+factorize}} (vector$<$ WORD $>$ \&instr, int n, int improve)
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_af6764fac1ab2ccb3c7d881bf6679865f}{optimize\+\_\+greedy}} (vector$<$ WORD $>$ instr, LONG time\+\_\+limit)
\item 
vector$<$ WORD $>$ \mbox{\hyperlink{optimize_8cc_a5fbca64500fa79eb561dc30d3392fc27}{recycle\+\_\+variables}} (const vector$<$ WORD $>$ \&all\+\_\+instr)
\item 
void \mbox{\hyperlink{optimize_8cc_a9bdc03e040f8c452701cb70c679209cd}{optimize\+\_\+expression\+\_\+given\+\_\+\+Horner}} ()
\item 
VOID \mbox{\hyperlink{optimize_8cc_ac75fb7b35eb6a8db734a9609b300dc57}{generate\+\_\+output}} (const vector$<$ WORD $>$ \&instr, int exprnr, int extraoffset, const vector$<$ vector$<$ WORD $>$ $>$ \&brackets)
\item 
WORD \mbox{\hyperlink{optimize_8cc_ab2817d97c0cf037f1c1bb7b0f6fb71a4}{generate\+\_\+expression}} (WORD exprnr)
\item 
VOID \mbox{\hyperlink{optimize_8cc_a99cd604c80a3f0b23fa5ec7f1e1446e7}{optimize\+\_\+print\+\_\+code}} (int print\+\_\+expr)
\item 
int \mbox{\hyperlink{optimize_8cc_ae04aeacaac92dd6eb6e2d17daf981d3c}{Optimize}} (WORD exprnr, int do\+\_\+print)
\item 
int \mbox{\hyperlink{optimize_8cc_a44b8879feddd8be746e5104265fe3155}{Clear\+Optimize}} ()
\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{optimize_8cc_a565ed9955394dfa29ba653459e0b344b}\label{optimize_8cc_a565ed9955394dfa29ba653459e0b344b}} 
const WORD {\bfseries OPER\+\_\+\+ADD} = -\/1
\item 
\mbox{\Hypertarget{optimize_8cc_a8fa558f0d9beb8ef6d2dff6379cae809}\label{optimize_8cc_a8fa558f0d9beb8ef6d2dff6379cae809}} 
const WORD {\bfseries OPER\+\_\+\+MUL} = -\/2
\item 
\mbox{\Hypertarget{optimize_8cc_a1a2cd460594376079b6154e9c71c88c0}\label{optimize_8cc_a1a2cd460594376079b6154e9c71c88c0}} 
const WORD {\bfseries OPER\+\_\+\+COMMA} = -\/3
\item 
\mbox{\Hypertarget{optimize_8cc_a7fb8b934f94e6df92e68786acf0f09aa}\label{optimize_8cc_a7fb8b934f94e6df92e68786acf0f09aa}} 
WORD $\ast$ {\bfseries optimize\+\_\+expr}
\item 
\mbox{\Hypertarget{optimize_8cc_a05a5d9c60b46342f733a622e17db9315}\label{optimize_8cc_a05a5d9c60b46342f733a622e17db9315}} 
vector$<$ vector$<$ WORD $>$ $>$ {\bfseries optimize\+\_\+best\+\_\+\+Horner\+\_\+schemes}
\item 
\mbox{\Hypertarget{optimize_8cc_ac6fd717ddea70ee6635c44185c529a29}\label{optimize_8cc_ac6fd717ddea70ee6635c44185c529a29}} 
int {\bfseries optimize\+\_\+num\+\_\+vars}
\item 
\mbox{\Hypertarget{optimize_8cc_af6987b3db641144d6222d09807f4e1d4}\label{optimize_8cc_af6987b3db641144d6222d09807f4e1d4}} 
int {\bfseries optimize\+\_\+best\+\_\+num\+\_\+oper}
\item 
\mbox{\Hypertarget{optimize_8cc_a6fa011944f1e78226dccf7800ebd649c}\label{optimize_8cc_a6fa011944f1e78226dccf7800ebd649c}} 
vector$<$ WORD $>$ {\bfseries optimize\+\_\+best\+\_\+instr}
\item 
\mbox{\Hypertarget{optimize_8cc_a565e07c9653f144b0cd7bc84bab77c84}\label{optimize_8cc_a565e07c9653f144b0cd7bc84bab77c84}} 
vector$<$ WORD $>$ {\bfseries optimize\+\_\+best\+\_\+vars}
\item 
\mbox{\Hypertarget{optimize_8cc_ab8fb6d524fe5f0a704d4fdb5e19dbad7}\label{optimize_8cc_ab8fb6d524fe5f0a704d4fdb5e19dbad7}} 
bool {\bfseries mcts\+\_\+factorized}
\item 
\mbox{\Hypertarget{optimize_8cc_a6b99cab292459b172e95b23117f95905}\label{optimize_8cc_a6b99cab292459b172e95b23117f95905}} 
bool {\bfseries mcts\+\_\+separated}
\item 
\mbox{\Hypertarget{optimize_8cc_a1de4c2f99ababf79fde8bfe106fed7d4}\label{optimize_8cc_a1de4c2f99ababf79fde8bfe106fed7d4}} 
vector$<$ WORD $>$ {\bfseries mcts\+\_\+vars}
\item 
\mbox{\Hypertarget{optimize_8cc_afc3afe3e2b40da2e695b1e0352938f46}\label{optimize_8cc_afc3afe3e2b40da2e695b1e0352938f46}} 
\mbox{\hyperlink{classtree__node}{tree\+\_\+node}} {\bfseries mcts\+\_\+root}
\item 
\mbox{\Hypertarget{optimize_8cc_abec871687bca84694e46f791e30490a9}\label{optimize_8cc_abec871687bca84694e46f791e30490a9}} 
int {\bfseries mcts\+\_\+expr\+\_\+score}
\item 
\mbox{\Hypertarget{optimize_8cc_a95fb96ae59b34b283fe839e0dbb084d8}\label{optimize_8cc_a95fb96ae59b34b283fe839e0dbb084d8}} 
set$<$ pair$<$ int, vector$<$ WORD $>$ $>$ $>$ {\bfseries mcts\+\_\+best\+\_\+schemes}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
experimental routines for the optimization of FORTRAN or C output. 

\doxysubsection{Function Documentation}
\mbox{\Hypertarget{optimize_8cc_adefbae07efcb5278e0fed2653443eab3}\label{optimize_8cc_adefbae07efcb5278e0fed2653443eab3}} 
\index{optimize.cc@{optimize.cc}!my\_random\_shuffle@{my\_random\_shuffle}}
\index{my\_random\_shuffle@{my\_random\_shuffle}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{my\_random\_shuffle()}{my\_random\_shuffle()}}
{\footnotesize\ttfamily template$<$class Random\+Access\+Iterator $>$ \\
void my\+\_\+random\+\_\+shuffle (\begin{DoxyParamCaption}\item[{PHEAD Random\+Access\+Iterator}]{fr,  }\item[{Random\+Access\+Iterator}]{to }\end{DoxyParamCaption})}

Random shuffle\hypertarget{optimize_8cc_autotoc_md0}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md0}
Randomly permutes elements in the range \mbox{[}fr,to). Functionality is the same as C++\textquotesingle{}s \char`\"{}random\+\_\+shuffle\char`\"{}, but it uses Form\textquotesingle{}s \char`\"{}wranf\char`\"{}. 

Definition at line 180 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_abcc71a308991ae8dc729fb69c6222cf8}\label{optimize_8cc_abcc71a308991ae8dc729fb69c6222cf8}} 
\index{optimize.cc@{optimize.cc}!get\_expression@{get\_expression}}
\index{get\_expression@{get\_expression}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{get\_expression()}{get\_expression()}}
{\footnotesize\ttfamily LONG get\+\_\+expression (\begin{DoxyParamCaption}\item[{int}]{exprnr }\end{DoxyParamCaption})}

Get expression\hypertarget{optimize_8cc_autotoc_md1}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md1}
Reads an expression from the input file into a buffer (called optimize\+\_\+expr). This buffer is used during the optimization process. Non-\/symbols are removed by Convert\+To\+Poly and are put in temporary symbols.

The return value is the length of the expression in WORDs, or a negative number if it failed. 

Definition at line 204 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_adae1c48384d6b3d171c1b5e2bf2953d7}\label{optimize_8cc_adae1c48384d6b3d171c1b5e2bf2953d7}} 
\index{optimize.cc@{optimize.cc}!get\_brackets@{get\_brackets}}
\index{get\_brackets@{get\_brackets}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{get\_brackets()}{get\_brackets()}}
{\footnotesize\ttfamily vector$<$vector$<$WORD$>$ $>$ get\+\_\+brackets (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}

Get brackets\hypertarget{optimize_8cc_autotoc_md2}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md2}
Checks whether the input expression (stored in optimize\+\_\+expr) contains brackets. If so, this method replaces terms outside brackets by powers of SEPERATESYMBOL (equal brackets have equal powers) and the brackets are returned. If not, the result is empty.

Brackets are used for simultaneous optimization. The symbol SEPARATESYMBOL is always the first one used in a Horner scheme. 

Definition at line 281 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a6021663b5861197cb619dfbf0b61c98f}\label{optimize_8cc_a6021663b5861197cb619dfbf0b61c98f}} 
\index{optimize.cc@{optimize.cc}!count\_operators@{count\_operators}}
\index{count\_operators@{count\_operators}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{count\_operators()}{count\_operators()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily int count\+\_\+operators (\begin{DoxyParamCaption}\item[{const WORD $\ast$}]{expr,  }\item[{bool}]{print = {\ttfamily false} }\end{DoxyParamCaption})}

Count operators\hypertarget{optimize_8cc_autotoc_md3}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md3}
Counts the number of operators in a Form-\/style expression. 

Definition at line 401 of file optimize.\+cc.



Referenced by optimize\+\_\+greedy().

\mbox{\Hypertarget{optimize_8cc_a6ed4fa10a3e861decd68281769e77ded}\label{optimize_8cc_a6ed4fa10a3e861decd68281769e77ded}} 
\index{optimize.cc@{optimize.cc}!count\_operators@{count\_operators}}
\index{count\_operators@{count\_operators}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{count\_operators()}{count\_operators()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily int count\+\_\+operators (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{instr,  }\item[{bool}]{print = {\ttfamily false} }\end{DoxyParamCaption})}

Count operators\hypertarget{optimize_8cc_autotoc_md4}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md4}
Counts the number of operators in a vector of instructions 

Definition at line 455 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ab193934e627fad1810f2844c63ecb139}\label{optimize_8cc_ab193934e627fad1810f2844c63ecb139}} 
\index{optimize.cc@{optimize.cc}!occurrence\_order@{occurrence\_order}}
\index{occurrence\_order@{occurrence\_order}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{occurrence\_order()}{occurrence\_order()}}
{\footnotesize\ttfamily vector$<$WORD$>$ occurrence\+\_\+order (\begin{DoxyParamCaption}\item[{const WORD $\ast$}]{expr,  }\item[{bool}]{rev }\end{DoxyParamCaption})}

Occurrence order\hypertarget{optimize_8cc_autotoc_md5}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md5}
Extracts all variables from an expression and sorts them with most occurring first (or last, with rev=true) 

Definition at line 498 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_af0fd473fa3804ea755fca497f7d89f6a}\label{optimize_8cc_af0fd473fa3804ea755fca497f7d89f6a}} 
\index{optimize.cc@{optimize.cc}!getpower@{getpower}}
\index{getpower@{getpower}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{getpower()}{getpower()}}
{\footnotesize\ttfamily WORD getpower (\begin{DoxyParamCaption}\item[{const WORD $\ast$}]{term,  }\item[{int}]{var,  }\item[{int}]{pos }\end{DoxyParamCaption})}

Horner tree building\hypertarget{optimize_8cc_autotoc_md6}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md6}
Given a Form-\/style expression (in a buffer in memory), this builds an expression tree. The tree is determined by a multivariate Horner scheme, i.\+e., something of the form\+:

1+y+x$\ast$(2+y$\ast$(1+y)+x$\ast$(3-\/y$\ast$(...)))

The order of the variables is given to the method \char`\"{}\+Horner\+\_\+tree\char`\"{}, which renumbers ad reorders the terms of the expression. Next, the recursive method \char`\"{}build\+\_\+\+Horner\+\_\+tree\char`\"{} does the actual tree construction.

The tree is represented in postfix notation. Tokens are of the following forms\+:


\begin{DoxyItemize}
\item SNUMBER tokenlength num den coefflength
\item SYMBOL tokenlength variable power
\item OPER\+\_\+\+ADD or OPER\+\_\+\+MUL
\end{DoxyItemize}\hypertarget{optimize_8cc_autotoc_md7}{}\doxysubsection{Note}\label{optimize_8cc_autotoc_md7}
Sets AN.\+poly\+\_\+num\+\_\+vars and allocates AN.\+poly\+\_\+vars. The latter should be freed later. Get power of variable (helper function for build\+\_\+\+Horner\+\_\+tree)\hypertarget{optimize_8cc_autotoc_md8}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md8}
Returns the power of the variable \char`\"{}var\char`\"{}, which is at position \char`\"{}pos\char`\"{} in this term, if it is present. 

Definition at line 579 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_acf3f8c95c8f6b3d1b06bedce470afe97}\label{optimize_8cc_acf3f8c95c8f6b3d1b06bedce470afe97}} 
\index{optimize.cc@{optimize.cc}!fixarg@{fixarg}}
\index{fixarg@{fixarg}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{fixarg()}{fixarg()}}
{\footnotesize\ttfamily void fixarg (\begin{DoxyParamCaption}\item[{UWORD $\ast$}]{t,  }\item[{WORD \&}]{n }\end{DoxyParamCaption})}

Call Gcd\+Long/\+Div\+Long with leading zeroes\hypertarget{optimize_8cc_autotoc_md9}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md9}
These method remove leading zeroes, so that Gcd\+Long and Div\+Long can safely be called. 

Definition at line 593 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_acea6d5654ede742b4d4b9da416116f5d}\label{optimize_8cc_acea6d5654ede742b4d4b9da416116f5d}} 
\index{optimize.cc@{optimize.cc}!build\_Horner\_tree@{build\_Horner\_tree}}
\index{build\_Horner\_tree@{build\_Horner\_tree}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{build\_Horner\_tree()}{build\_Horner\_tree()}}
{\footnotesize\ttfamily void build\+\_\+\+Horner\+\_\+tree (\begin{DoxyParamCaption}\item[{const WORD $\ast$$\ast$}]{terms,  }\item[{int}]{numterms,  }\item[{int}]{var,  }\item[{int}]{maxvar,  }\item[{int}]{pos,  }\item[{vector$<$ WORD $>$ $\ast$}]{res }\end{DoxyParamCaption})}

Build the Horner tree\hypertarget{optimize_8cc_autotoc_md10}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md10}
Constructs the Horner tree. The method processes one variable and continues recursively until the Horner scheme is completed.

\char`\"{}terms\char`\"{} is a pointer to the starts of the terms. \char`\"{}numterms\char`\"{} is the number of terms to be processed. \char`\"{}var\char`\"{} is the next variable to be processed (index between 0 and \#maxvar) and \char`\"{}maxvar\char`\"{} is the last variable to be processed, so that partial Horner trees can also be constructed. \char`\"{}pos\char`\"{} is the position that the power of \char`\"{}var\char`\"{} should be in (one level further in the recursion, \char`\"{}pos\char`\"{} has increased by 0 or 1 depending on whether the previous power was 0 or not). The result is written at the pointer \char`\"{}res\char`\"{}.

This method also factors out gcds of the coefficients. The result should end with \char`\"{}gcd OPER\+\_\+\+MUL\char`\"{} at all times, so that one level higher gcds can be extracted again. 

Definition at line 631 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_add58d2f1e0422685a10f31a3a0a16b57}\label{optimize_8cc_add58d2f1e0422685a10f31a3a0a16b57}} 
\index{optimize.cc@{optimize.cc}!term\_compare@{term\_compare}}
\index{term\_compare@{term\_compare}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{term\_compare()}{term\_compare()}}
{\footnotesize\ttfamily bool term\+\_\+compare (\begin{DoxyParamCaption}\item[{const WORD $\ast$}]{a,  }\item[{const WORD $\ast$}]{b }\end{DoxyParamCaption})}

Term compare (helper function for Horner\+\_\+tree)\hypertarget{optimize_8cc_autotoc_md11}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md11}
Compares two terms of the form \char`\"{}\+L SYM 4 x n coeff\char`\"{} or \char`\"{}\+L coeff\char`\"{}. Lower powers of lower-\/indexed symbols come first. This is used to sort the terms in correct order. 

Definition at line 831 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a274a87bfb03189ac75814d90d5e68701}\label{optimize_8cc_a274a87bfb03189ac75814d90d5e68701}} 
\index{optimize.cc@{optimize.cc}!Horner\_tree@{Horner\_tree}}
\index{Horner\_tree@{Horner\_tree}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{Horner\_tree()}{Horner\_tree()}}
{\footnotesize\ttfamily vector$<$WORD$>$ Horner\+\_\+tree (\begin{DoxyParamCaption}\item[{const WORD $\ast$}]{expr,  }\item[{const vector$<$ WORD $>$ \&}]{order }\end{DoxyParamCaption})}

Prepare Horner tree building\hypertarget{optimize_8cc_autotoc_md12}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md12}
This method renumbers the variables to 0...\#vars-\/1 according to the specified order. Next, it stored pointer to individual terms and sorts the terms with higher power first. Then the sorted lists of power is used for the construction of the Horner tree. 

Definition at line 852 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a2d7b65dcb6f75e092976b87f6ffc13f5}\label{optimize_8cc_a2d7b65dcb6f75e092976b87f6ffc13f5}} 
\index{optimize.cc@{optimize.cc}!generate\_instructions@{generate\_instructions}}
\index{generate\_instructions@{generate\_instructions}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{generate\_instructions()}{generate\_instructions()}}
{\footnotesize\ttfamily vector$<$WORD$>$ generate\+\_\+instructions (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{tree,  }\item[{bool}]{do\+\_\+\+CSE }\end{DoxyParamCaption})}

Generate instructions\hypertarget{optimize_8cc_autotoc_md13}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md13}
Converts the expression tree to a list of instructions that directly translate to code. Instructions are of the form\+:

expr.\+nr operator length \mbox{[}operands\mbox{]}+ trailing.\+zero

The operands are of the form\+:

length \mbox{[}(EXTRA)SYMBOL length variable power\mbox{]} coeff

This method only generates binary operators. Merging is done later. The method also checks for common subexpressions and eliminates them and the flag \char`\"{}do\+\_\+\+CSE\char`\"{} is set.\hypertarget{optimize_8cc_autotoc_md14}{}\doxysubsection{Implementation details}\label{optimize_8cc_autotoc_md14}
The map \char`\"{}\+ID\char`\"{} keeps track of which subexpressions already exist. The key is formatted as one of the following\+:

SYMBOL x n SNUMBER coeff OPERATOR LHS RHS

with LHS/\+RHS formatted as one of the following\+:

SNUMBER idx 0 (EXTRA)SYMBOL x n

ID\mbox{[}symbol\mbox{]} or ID\mbox{[}operator\mbox{]} equals a subexpression number. ID\mbox{[}coeff\mbox{]} equals the position of the number in the input.

The stack s is used the process the postfix expression tree. Three-\/word tokens of the form\+:

SNUMBER idx.\+of.\+coeff 0 SYMBOL x n EXTRASYMBOL x 1

are pushed onto it. Operators pop two operands and push the resulting expression.

(Extra)symbols are 1-\/indexed, because -\/X is also needed to represent -\/1 times this term.

There is currently a bug. The notation cannot tell if there is a single bracket and then ignores the bracket.

TODO\+: check if this method performs properly if do\+\_\+\+CSE=false 

Definition at line 1086 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_abab9eca226619182e82960044cee4be4}\label{optimize_8cc_abab9eca226619182e82960044cee4be4}} 
\index{optimize.cc@{optimize.cc}!count\_operators\_cse@{count\_operators\_cse}}
\index{count\_operators\_cse@{count\_operators\_cse}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{count\_operators\_cse()}{count\_operators\_cse()}}
{\footnotesize\ttfamily int count\+\_\+operators\+\_\+cse (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{tree }\end{DoxyParamCaption})}

Count number of operators in a binary tree, while removing CSEs on the fly. The instruction set is not created, which makes this method slightly faster.

A hash is created on the fly and is passed through the stack. TODO\+: find better hash functions 

Definition at line 1295 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a895adb819258c8f5a95d3635bb608575}\label{optimize_8cc_a895adb819258c8f5a95d3635bb608575}} 
\index{optimize.cc@{optimize.cc}!find\_Horner\_MCTS@{find\_Horner\_MCTS}}
\index{find\_Horner\_MCTS@{find\_Horner\_MCTS}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{find\_Horner\_MCTS()}{find\_Horner\_MCTS()}}
{\footnotesize\ttfamily void find\+\_\+\+Horner\+\_\+\+MCTS (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}

Find best Horner schemes using MCTS\hypertarget{optimize_8cc_autotoc_md17}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md17}
The method governs the MCTS for the best Horner schemes. It does some pre-\/processing, calls \char`\"{}find\+\_\+\+Horner\+\_\+\+MCTS\+\_\+expand\+\_\+tree\char`\"{} a number of times and does some post-\/processing. 

Definition at line 2208 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ad898f09d5c8951bc139dae96b1121648}\label{optimize_8cc_ad898f09d5c8951bc139dae96b1121648}} 
\index{optimize.cc@{optimize.cc}!merge\_operators@{merge\_operators}}
\index{merge\_operators@{merge\_operators}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{merge\_operators()}{merge\_operators()}}
{\footnotesize\ttfamily vector$<$WORD$>$ merge\+\_\+operators (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{all\+\_\+instr,  }\item[{bool}]{move\+\_\+coeff }\end{DoxyParamCaption})}

Merge operators\hypertarget{optimize_8cc_autotoc_md18}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md18}
The input instructions form a binary DAG. This method merges expressions like

Z1 = a+b; Z2 = Z1+c;

into

Z2 = a+b+c;

An instruction is merged iff it only has one parent and the operator equals its parent\textquotesingle{}s operator.

This still leaves some freedom\+: where should the coefficients end up in cases as\+:

Z1 = Z2 + x $<$=$>$ Z1 = 2$\ast$\+Z2 + x Z2 = 2$\ast$x$\ast$y Z2 = x$\ast$y

Both are relevant, e.\+g. for CSE of the form \char`\"{}2$\ast$x\char`\"{} and \char`\"{}2$\ast$\+Z2\char`\"{}. The flag \char`\"{}move\+\_\+coeff\char`\"{} moves coefficients from LHS-\/like expressions to RHS-\/like expressions.

Furthermore, this method removes empty equation (Z1=0), that are introduced by some \char`\"{}optimize\+\_\+greedy\char`\"{} substitutions.\hypertarget{optimize_8cc_autotoc_md19}{}\doxysubsection{Implementation details}\label{optimize_8cc_autotoc_md19}
Expressions are mostly traversed via a stack, so that parents are evaluated before their children.

With \char`\"{}move\+\_\+coeff\char`\"{} set coefficients are moved, but this leads to some tricky cases, e.\+g.

Z1 = Z2 + x Z2 = 2$\ast$y

Here Z2 reduces to the trivial equation Z2=y, which should be eliminated. Here the array skip\mbox{[}i\mbox{]} comes in.

Furthermore in the case

Z1 = Z2 + x Z2 = 2$\ast$\+Z3 Z3 = x$\ast$\+Z4 Z4 = y$\ast$z

after substituting Z1 = 2$\ast$\+Z3 + x, the parent expression for Z4 becomes Z3 instead of Z2. This is where renum\+\_\+par\mbox{[}i\mbox{]} comes in.

Finally, once a coefficient has been moved, skip\+\_\+coeff\mbox{[}i\mbox{]} is set and this coefficient is copied into the new expression anymore. 

Definition at line 2356 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a38297edbfede135a1fb148b10635500d}\label{optimize_8cc_a38297edbfede135a1fb148b10635500d}} 
\index{optimize.cc@{optimize.cc}!find\_optimizations@{find\_optimizations}}
\index{find\_optimizations@{find\_optimizations}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{find\_optimizations()}{find\_optimizations()}}
{\footnotesize\ttfamily vector$<$\mbox{\hyperlink{classoptimization}{optimization}}$>$ find\+\_\+optimizations (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{instr }\end{DoxyParamCaption})}

Find optimizations\hypertarget{optimize_8cc_autotoc_md21}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md21}
This method find all optimization of the form described in \char`\"{}class \+Optimization\char`\"{}. It process every equation, looking for possible optimizations and stores them in a fast-\/access data structure to count the total improvement of an optimization. 

Definition at line 2651 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ac21af0c2bd95ce022dd1aa04ef3c87ed}\label{optimize_8cc_ac21af0c2bd95ce022dd1aa04ef3c87ed}} 
\index{optimize.cc@{optimize.cc}!do\_optimization@{do\_optimization}}
\index{do\_optimization@{do\_optimization}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{do\_optimization()}{do\_optimization()}}
{\footnotesize\ttfamily bool do\+\_\+optimization (\begin{DoxyParamCaption}\item[{const \mbox{\hyperlink{classoptimization}{optimization}}}]{optim,  }\item[{vector$<$ WORD $>$ \&}]{instr,  }\item[{int}]{newid }\end{DoxyParamCaption})}

Do optimization\hypertarget{optimize_8cc_autotoc_md22}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md22}
This method performs an optimization. It scans through the equations of \char`\"{}optim.\+eqnidxs\char`\"{} and looks in which this optimization can still be performed (due to other performed optimizations this isn\textquotesingle{}t always the case). If possible, it substitutes the common subexpression by a new extra symbol numbered \char`\"{}newid\char`\"{}. Finally, the new extrasymbol is defined accordingly.

Substitutions may lead to trivial equations of the form \char`\"{}\+Zi=\+Zj\char`\"{}, but these are removed in the end of the method. The method returns whether the substitution has been done once or more (or not). 

Definition at line 2884 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ac3e43a3ac83c7fbe414e9dd75db0073a}\label{optimize_8cc_ac3e43a3ac83c7fbe414e9dd75db0073a}} 
\index{optimize.cc@{optimize.cc}!partial\_factorize@{partial\_factorize}}
\index{partial\_factorize@{partial\_factorize}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{partial\_factorize()}{partial\_factorize()}}
{\footnotesize\ttfamily int partial\+\_\+factorize (\begin{DoxyParamCaption}\item[{vector$<$ WORD $>$ \&}]{instr,  }\item[{int}]{n,  }\item[{int}]{improve }\end{DoxyParamCaption})}

Partial factorization of instructions\hypertarget{optimize_8cc_autotoc_md23}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md23}
This method performs partial factorization of instructions. In particular the following instructions

Z1 = x$\ast$a$\ast$b Z2 = x$\ast$c$\ast$d$\ast$e Z3 = 2$\ast$x + Z1 + Z2 + more

are replaced by

Z1 = a$\ast$b Z2 = c$\ast$d$\ast$e Z3 = Zj + more Zi = 2 + Z1 + Z2 Zj = x$\ast$\+Zi

Here it is necessary that no other equations refer to Z1 and Z2. The generation of trivial instructions (Zi=Zj or Zi=x) is prevented. 

Definition at line 3433 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_af6764fac1ab2ccb3c7d881bf6679865f}\label{optimize_8cc_af6764fac1ab2ccb3c7d881bf6679865f}} 
\index{optimize.cc@{optimize.cc}!optimize\_greedy@{optimize\_greedy}}
\index{optimize\_greedy@{optimize\_greedy}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{optimize\_greedy()}{optimize\_greedy()}}
{\footnotesize\ttfamily vector$<$WORD$>$ optimize\+\_\+greedy (\begin{DoxyParamCaption}\item[{vector$<$ WORD $>$}]{instr,  }\item[{LONG}]{time\+\_\+limit }\end{DoxyParamCaption})}

Optimize instructions greedily\hypertarget{optimize_8cc_autotoc_md24}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md24}
This method optimizes an expression greedily. It calls \char`\"{}find\+\_\+optimizations\char`\"{} to obtain candidates and performs the best one(s) by calling \char`\"{}do\+\_\+optimization\char`\"{}.

How many different optimization are done, before \char`\"{}find\+\_\+optimization\char`\"{} is called again, is determined by the settings \char`\"{}greedyminnum\char`\"{} and \char`\"{}greedymaxperc\char`\"{}.

During the optimization process, sequences of zeroes are introduced in the instructions, since moving all instructions when one gets optimized, is very costly. Therefore, in the end, the instructions are \char`\"{}compressed\char`\"{} again to remove these extra zeroes. 

Definition at line 3727 of file optimize.\+cc.



References count\+\_\+operators().

\mbox{\Hypertarget{optimize_8cc_a5fbca64500fa79eb561dc30d3392fc27}\label{optimize_8cc_a5fbca64500fa79eb561dc30d3392fc27}} 
\index{optimize.cc@{optimize.cc}!recycle\_variables@{recycle\_variables}}
\index{recycle\_variables@{recycle\_variables}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{recycle\_variables()}{recycle\_variables()}}
{\footnotesize\ttfamily vector$<$WORD$>$ recycle\+\_\+variables (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{all\+\_\+instr }\end{DoxyParamCaption})}

Recycle variables\hypertarget{optimize_8cc_autotoc_md25}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md25}
The current input uses many temporary variables. Many of them become obsolete at some point during the evaluation of the code, so can be recycled. This method renumbers the temporary variables, so that they are recycled. Furthermore, the input is order in depth-\/first order, so that the instructions can be performed consecutively.\hypertarget{optimize_8cc_autotoc_md26}{}\doxysubsection{Implementation details}\label{optimize_8cc_autotoc_md26}
First, for each sub\+DAG, an estimate for the number of variables needed is made. This is done by the following recursive formula\+:

\#vars(x) = max(\#vars(ch\+\_\+i(x)) + i),

with ch\+\_\+i(x) the i-\/th child of x, where the childs are ordered w.\+r.\+t. \#vars(ch\+\_\+i). This formula is exact if the input forms a tree, and otherwise gives a reasonable estimate.

Then, the instructions are reordered in a depth-\/first order with childs ordered w.\+r.\+t. \#vars. Next, the times that variables become obsolete are found. Each LHS of an instruction is renumbered to the lowest-\/numbered temporary variable that is available at that time. 

Definition at line 3867 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a9bdc03e040f8c452701cb70c679209cd}\label{optimize_8cc_a9bdc03e040f8c452701cb70c679209cd}} 
\index{optimize.cc@{optimize.cc}!optimize\_expression\_given\_Horner@{optimize\_expression\_given\_Horner}}
\index{optimize\_expression\_given\_Horner@{optimize\_expression\_given\_Horner}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{optimize\_expression\_given\_Horner()}{optimize\_expression\_given\_Horner()}}
{\footnotesize\ttfamily void optimize\+\_\+expression\+\_\+given\+\_\+\+Horner (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}

Optimize expression given a Horner scheme\hypertarget{optimize_8cc_autotoc_md27}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md27}
This method picks one Horner scheme from the list of best Horner schemes, applies this scheme to the expression and then, depending on optimize.\+settings, does a common subexpression elimination (CSE) or performs greedy optimizations.

CSE is fast, while greedy might be slow. CSE followed by greedy is faster than greedy alone, but typically results in slightly worse code (not proven; just observed). eventually do greedy optimations

Definition at line 4014 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ac75fb7b35eb6a8db734a9609b300dc57}\label{optimize_8cc_ac75fb7b35eb6a8db734a9609b300dc57}} 
\index{optimize.cc@{optimize.cc}!generate\_output@{generate\_output}}
\index{generate\_output@{generate\_output}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{generate\_output()}{generate\_output()}}
{\footnotesize\ttfamily VOID generate\+\_\+output (\begin{DoxyParamCaption}\item[{const vector$<$ WORD $>$ \&}]{instr,  }\item[{int}]{exprnr,  }\item[{int}]{extraoffset,  }\item[{const vector$<$ vector$<$ WORD $>$ $>$ \&}]{brackets }\end{DoxyParamCaption})}

Generate output\hypertarget{optimize_8cc_autotoc_md28}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md28}
This method prepares the instructions for printing. They are stored in Form format, so that they can be printed by \char`\"{}\+Print\+Extra\+Symbol\char`\"{}. The results are stored in the buffer AO.\+Optimize\+Result. 

Definition at line 4245 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ab2817d97c0cf037f1c1bb7b0f6fb71a4}\label{optimize_8cc_ab2817d97c0cf037f1c1bb7b0f6fb71a4}} 
\index{optimize.cc@{optimize.cc}!generate\_expression@{generate\_expression}}
\index{generate\_expression@{generate\_expression}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{generate\_expression()}{generate\_expression()}}
{\footnotesize\ttfamily WORD generate\+\_\+expression (\begin{DoxyParamCaption}\item[{WORD}]{exprnr }\end{DoxyParamCaption})}

Generate expression\hypertarget{optimize_8cc_autotoc_md29}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md29}
This method modifies the original optimized expression by an expression with extra symbols. This is used for \char`\"{}\#\+Optimize\char`\"{}. 

Definition at line 4394 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a99cd604c80a3f0b23fa5ec7f1e1446e7}\label{optimize_8cc_a99cd604c80a3f0b23fa5ec7f1e1446e7}} 
\index{optimize.cc@{optimize.cc}!optimize\_print\_code@{optimize\_print\_code}}
\index{optimize\_print\_code@{optimize\_print\_code}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{optimize\_print\_code()}{optimize\_print\_code()}}
{\footnotesize\ttfamily VOID optimize\+\_\+print\+\_\+code (\begin{DoxyParamCaption}\item[{int}]{print\+\_\+expr }\end{DoxyParamCaption})}

Print optimized code\hypertarget{optimize_8cc_autotoc_md30}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md30}
This method prints the optimized code via \char`\"{}\+Print\+Extra\+Symbol\char`\"{}. Depending on the flag, the original expression is printed (for \char`\"{}\+Print\char`\"{}) or not (for \char`\"{}\#\+Optimize / \#write \char`\"{}O"{}). 

Definition at line 4474 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_ae04aeacaac92dd6eb6e2d17daf981d3c}\label{optimize_8cc_ae04aeacaac92dd6eb6e2d17daf981d3c}} 
\index{optimize.cc@{optimize.cc}!Optimize@{Optimize}}
\index{Optimize@{Optimize}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{Optimize()}{Optimize()}}
{\footnotesize\ttfamily int Optimize (\begin{DoxyParamCaption}\item[{WORD}]{exprnr,  }\item[{int}]{do\+\_\+print }\end{DoxyParamCaption})}

Optimization of expression\hypertarget{optimize_8cc_autotoc_md31}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md31}
This method takes an input expression and generates optimized code to calculate its value. The following methods are called to do so\+:

(1) get\+\_\+expression \+: to read to expression

(2) get\+\_\+brackets \+: find brackets for simultaneous optimization

(3) occurrence\+\_\+order or find\+\_\+\+Horner\+\_\+\+MCTS \+: to determine (the) Horner scheme(s) to use; this depends on AO.\+optimize.\+horner

(4) optimize\+\_\+expression\+\_\+given\+\_\+\+Horner \+: to do the optimizations for each Horner scheme; this method does either CSE or greedy optimizations dependings on AO.\+optimize.\+method

(5) generate\+\_\+output \+: to format the output in Form notation and store it in a buffer

(6a) optimize\+\_\+print\+\_\+code \+: to print the expression (for \char`\"{}\+Print\char`\"{}) or (6b) generate\+\_\+expression \+: to modify the expression (for \char`\"{}\#\+Optimize\char`\"{})

On Par\+FORM, all the processes must call this function at the same time. Then

(1) Because only the master can access to the expression to be optimized, the master broadcast the expression to all the slaves after reading the expression (PF\+\_\+get\+\_\+expression).

(2) get\+\_\+brackets reads optimize\+\_\+expr as the input and it works also on the slaves. We leave it although the bracket information is not needed on the slaves (used in (5) on the master).

(3) and (4) find\+\_\+\+Horner\+\_\+\+MCTS and optimize\+\_\+expression\+\_\+given\+\_\+\+Horner are parallelized.

(5), (6a) and (6b) are needed only on the master. 

Definition at line 4587 of file optimize.\+cc.

\mbox{\Hypertarget{optimize_8cc_a44b8879feddd8be746e5104265fe3155}\label{optimize_8cc_a44b8879feddd8be746e5104265fe3155}} 
\index{optimize.cc@{optimize.cc}!ClearOptimize@{ClearOptimize}}
\index{ClearOptimize@{ClearOptimize}!optimize.cc@{optimize.cc}}
\doxysubsubsection{\texorpdfstring{ClearOptimize()}{ClearOptimize()}}
{\footnotesize\ttfamily int Clear\+Optimize (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}

Optimization of expression\hypertarget{optimize_8cc_autotoc_md32}{}\doxysubsection{Description}\label{optimize_8cc_autotoc_md32}
Clears the buffers that were used for optimization output. Clears the expression from the buffers (marks it to be dropped). Note\+: we need to use the expression by its name, because numbers may change if we drop other expressions between when we do the optimizations and clear the results (in \mbox{\hyperlink{execute_8c}{execute.\+c}}). Also this is not 100\% safe, because we could overwrite the optimized expression. But that can be done only in a Local or Global statement and hence we only have to test there that we might have to call Clear\+Optimize first. (in file \mbox{\hyperlink{comexpr_8c}{comexpr.\+c}}) 

Definition at line 4924 of file optimize.\+cc.

