summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luacas/doc/reference/ref_algebra
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/latex/luacas/doc/reference/ref_algebra')
-rw-r--r--macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra.tex336
-rw-r--r--macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_classes/ref_algebra_classes.tex977
-rw-r--r--macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_methods/ref_algebra_methods.tex1305
3 files changed, 2618 insertions, 0 deletions
diff --git a/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra.tex b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra.tex
new file mode 100644
index 0000000000..0e9bd011e8
--- /dev/null
+++ b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra.tex
@@ -0,0 +1,336 @@
+\documentclass{article}
+
+\usepackage{luacas}
+\usepackage{amsmath}
+\usepackage{amssymb}
+
+\usepackage[margin=1in]{geometry}
+\usepackage[shortlabels]{enumitem}
+
+\usepackage{pgfplots}
+\pgfplotsset{compat=1.18}
+\usetikzlibrary{positioning,calc}
+\usepackage{forest}
+\usepackage{minted}
+\usemintedstyle{pastie}
+\usepackage[hidelinks]{hyperref}
+\usepackage{parskip}
+\usepackage{multicol}
+\usepackage[most]{tcolorbox}
+ \tcbuselibrary{xparse,documentation}
+\usepackage{microtype}
+\usepackage{makeidx}
+
+\usepackage[
+backend=biber,
+style=numeric,
+]{biblatex}
+\addbibresource{sources.bib}
+
+\definecolor{rose}{RGB}{128,0,0}
+\definecolor{roseyellow}{RGB}{222,205,99}
+\definecolor{roseblue}{RGB}{167,188,214}
+\definecolor{rosenavy}{RGB}{79,117,139}
+\definecolor{roseorange}{RGB}{232,119,34}
+\definecolor{rosegreen}{RGB}{61,68,30}
+\definecolor{rosewhite}{RGB}{223,209,167}
+\definecolor{rosebrown}{RGB}{108,87,27}
+\definecolor{rosegray}{RGB}{84,88,90}
+
+\definecolor{codegreen}{HTML}{49BE25}
+
+\newtcolorbox{codebox}[1][sidebyside]{
+ enhanced,skin=bicolor,
+ #1,
+ arc=1pt,
+ colframe=brown,
+ colback=brown!15,colbacklower=white,
+ boxrule=1pt,
+ notitle
+}
+
+\newtcolorbox{codehead}[1][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1
+}
+
+\usepackage{varwidth}
+
+\newtcolorbox{newcodehead}[2][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1,
+ fonttitle=\bfseries\ttfamily\footnotesize,
+ coltitle=rosegray,
+ attach boxed title to top text right,
+ boxed title style={frame hidden,
+ size=small,
+ bottom=-1mm,
+ interior style={fill=none,
+ top color=white,
+ bottom color=white}
+ },
+ title={#2}
+}
+
+\makeindex
+
+\newcommand{\coderef}[2]{%
+\begin{codehead}[sidebyside,segmentation hidden]%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{codehead}%
+}
+
+\newcommand{\newcoderef}[3]{%
+\begin{newcodehead}[sidebyside,segmentation hidden]{#3}%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{newcodehead}%
+}
+
+\usetikzlibrary{shapes.multipart}
+\useforestlibrary{edges}
+
+\def\error{\color{red}}
+\def\self{\color{gray}}
+\def\call{$\star$ }
+
+\begin{document}
+\thispagestyle{empty}
+
+\section{Algebra}
+ This section contains reference materials for the algebra functionality of \texttt{luacas}. The classes in this module are diagramed below according to inheritance along with the methods/functions one can call upon them.
+ \begin{itemize}
+ \item {\error\ttfamily\itshape method}: an abstract method;
+ \item {\self\ttfamily\itshape method}: a method that returns the expression unchanged;
+ \item {\ttfamily\itshape method}: method that is either unique, implements an abstract method, or overrides an abstract
+method;
+ \item {\tikz[baseline=-0.5ex]\node[fill=rose!30] {\ttfamily\bfseries Class};}: a concrete class.
+ \end{itemize}
+Here is an inhertiance diagram of the classes in the algebra module that are derived from the \texttt{AtomicExpression} branch of classes. However, not all of them are proper {\ttfamily ConstantExpression}s, so some of them override the {\ttfamily isconstant()} method. Most methods are stated, but some were omitted (because they inherit in the obvious way, they are auxiliary and not likely to be interesting to the end-user, etc).
+ \vfill
+\forestset{
+rectcore/.style = {rectangle split,
+ rectangle split parts=2,
+ draw = {rosenavy,thick},
+ rounded corners = 1pt,
+ font = \ttfamily\bfseries,
+ fill = roseblue!#1
+ },
+rectalg/.style = {rectangle split,
+ rectangle split parts=2,
+ draw = {rose,thick},
+ rounded corners = 1pt,
+ font = \ttfamily\bfseries,
+ fill = rose!#1
+ }
+}
+\forestset{
+ multiple directions/.style={
+ for tree={#1},
+ phantom,
+ for relative level=1{
+ no edge,
+ delay={
+ !c.content/.pgfmath=content("!u")},
+ before computing xy={l=0,s=0}
+ }
+ },
+ multiple directions/.default={},
+ grow subtree/.style={for tree={grow=#1}},
+ grow' subtree/.style={for tree={grow'=#1}}}
+\tikzset{
+ every two node part/.style={font=\ttfamily\itshape\footnotesize}
+}
+\begin{center}
+ \begin{forest}
+ for tree = {node options={align=left},
+ edge = {-stealth}
+ },
+ forked edges
+ [Expression\nodepart{two}$\cdots$,rectcore={0}
+ [AtomicExpression\nodepart{two}$\cdots$,rectcore={0}
+ [SymbolExpression\nodepart{two}$\cdots$,rectcore={50}]
+ [ConstantExpression\nodepart{two}$\cdots$,rectcore={0}
+ [Ring\nodepart{two}\begin{minipage}{0.45\textwidth}\begin{multicols}{3}
+ {\error :getring}\\
+ {\error :inring(ring)}\\
+ {\error :iscommutative}\\
+ {\error :add(b)}\\
+ :sub(b)\\
+ {\error :neg(b)}\\
+ {\error :mul(b)}\\
+ :pow(n)\\
+ {\error :eq(b)}\\
+ {\error :lt(b)}\\
+ {\error :le(b)}\\
+ {\error :zero()}\\
+ {\error :one()}\\
+ {\error .makering}\\
+ .resultantring
+ \end{multicols}\end{minipage}
+ ,rectalg={0}
+ [PolynomialRing\nodepart{two}
+ .makering\\
+ .R\\
+ .gcd\\
+ .extendedgcd\\
+ .resultant\\
+ .resultantmulti\\
+ .monicgcdremainders\\
+ .partialfractions\\
+ %:isatomic\\
+ :new\\
+ .mul{\textunderscore}rec\\
+ :divremainder\\
+ :psuedodivide\\
+ :isconstant\\
+ :isatomic\\
+ :freeof\\
+ :tocompoundexpression\\
+ :evaluateat\\
+ :derivative\\
+ :squarefreefactorization\\
+ :factor\\
+ :rationalroots\\
+ :roots\\
+ $\cdots$
+ ,rectalg={30}]
+ [EuclideanDomain\nodepart{two}
+ {\error :divremainder}\\
+ :iscommutative
+ ,rectalg={0}
+ [Integer\nodepart{two}
+ .gcd\\
+ .extendedgcd\\
+ .max\\
+ .min\\
+ .ceillog\\
+ .powmod\\
+ :new\\
+ :divremainder\\
+ :asnumber\\
+ :divisors\\
+ :primefactorization\\
+ :findafactor\\
+ :isprime\\
+ :abs\\
+ $\cdots$
+ ,rectalg={30}]
+ [Field\nodepart{two}
+ :div
+ ,rectalg={0}
+ [Rational\nodepart{two}
+ :new\\
+ :reduce\\
+ :isconstant\\
+ :tocompoundexpression\\
+ :asnumber\\
+ :div
+ ,rectalg={30}]
+ [IntegerModN\nodepart{two}
+ :new
+ ,rectalg={30}]
+ ]
+ ]
+ ]
+ ]
+ ]
+ ]
+ \end{forest}
+\end{center}
+\vfill
+
+\newpage
+
+Here is an inhertiance diagram of the classes in the algebra module that are derived from the \texttt{CompoundExpression} branch of classes. Again, most methods are stated, but some were omitted (because they inherit in the obvious way, they are auxiliary and not likely to be interesting to the end-user, etc).
+\vfill
+\begin{center}
+ \begin{forest}
+ for tree = {node options={align=left},
+ grow = south,
+ edge = {-stealth},
+ child anchor = west
+ },
+ forked edges
+ [Expression\nodepart{two}$\cdots$,
+ rectcore={0}
+ [CompoundExpression\nodepart{two}
+ $\cdots$,
+ rectcore={0},
+ calign = first,
+ for tree = {node options = {anchor = west},
+ grow' = east}
+ [BinaryOperation\nodepart{two}
+ $\cdots$,
+ rectcore={50}]
+ [FunctionExpression\nodepart{two}
+ $\cdots$,
+ rectcore={50}
+ [TrigExpression\nodepart{two}
+ :new
+ ,rectalg={30}]
+ ]
+ [AbsExpression\nodepart{two}
+ :new
+ ,rectalg={30}]
+ [SqrtExpression\nodepart{two}
+ :new\\
+ :topower
+ ,rectalg={30}]
+ [RootExpression\nodepart{two}
+ :new
+ ,rectalg={30}]
+ [FactorialExpression\nodepart{two}
+ :new
+ ,rectalg={30}]
+ [Logarithm\nodepart{two}
+ :new
+ ,rectalg={30}]
+ [Equation\nodepart{two}
+ :new\\
+ :solvefor()
+ ,rectalg={30}]
+ ]
+ ]
+ \end{forest}
+\end{center}
+\vfill
+\end{document}
+
diff --git a/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_classes/ref_algebra_classes.tex b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_classes/ref_algebra_classes.tex
new file mode 100644
index 0000000000..58d9b69f84
--- /dev/null
+++ b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_classes/ref_algebra_classes.tex
@@ -0,0 +1,977 @@
+\documentclass{article}
+
+\usepackage{luacas}
+\usepackage{amsmath}
+\usepackage{amssymb}
+
+\usepackage[margin=1in]{geometry}
+\usepackage[shortlabels]{enumitem}
+
+\usepackage{pgfplots}
+\pgfplotsset{compat=1.18}
+\usetikzlibrary{positioning,calc}
+\usepackage{forest}
+\usepackage{minted}
+\usemintedstyle{pastie}
+\usepackage[hidelinks]{hyperref}
+\usepackage{parskip}
+\usepackage{multicol}
+\usepackage[most]{tcolorbox}
+ \tcbuselibrary{xparse,documentation}
+\usepackage{microtype}
+\usepackage{makeidx}
+\usepackage{fontawesome}
+
+\usepackage[
+backend=biber,
+style=numeric,
+]{biblatex}
+\addbibresource{sources.bib}
+
+\definecolor{rose}{RGB}{128,0,0}
+\definecolor{roseyellow}{RGB}{222,205,99}
+\definecolor{roseblue}{RGB}{167,188,214}
+\definecolor{rosenavy}{RGB}{79,117,139}
+\definecolor{roseorange}{RGB}{232,119,34}
+\definecolor{rosegreen}{RGB}{61,68,30}
+\definecolor{rosewhite}{RGB}{223,209,167}
+\definecolor{rosebrown}{RGB}{108,87,27}
+\definecolor{rosegray}{RGB}{84,88,90}
+
+\definecolor{codegreen}{HTML}{49BE25}
+
+\newtcolorbox{codebox}[1][sidebyside]{
+ enhanced,skin=bicolor,
+ #1,
+ arc=1pt,
+ colframe=brown,
+ colback=brown!15,colbacklower=white,
+ boxrule=1pt,
+ notitle
+}
+
+\newtcolorbox{codehead}[1][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1
+}
+
+\usepackage{varwidth}
+
+\newtcolorbox{newcodehead}[2][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1,
+ fonttitle=\bfseries\ttfamily\footnotesize,
+ coltitle=rosegray,
+ attach boxed title to top text right,
+ boxed title style={frame hidden,size=small,bottom=-1mm,
+ interior style={fill=none,
+ top color=white,
+ bottom color=white}},
+ title={#2}
+}
+
+\makeindex
+
+\newcommand{\coderef}[2]{%
+\begin{codehead}[sidebyside,segmentation hidden]%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{codehead}%
+}
+
+\newcommand{\newcoderef}[3]{%
+\begin{newcodehead}[sidebyside,segmentation hidden]{#3}%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{newcodehead}%
+}
+
+\begin{document}
+\setdescription{style=multiline,
+ topsep=10pt,
+ leftmargin=5cm,
+ }
+
+\subsection{Algebra Classes}
+
+The algebra package contains functionality for arbitrary-precision arithmetic, polynomial arithmetic and factoring, symbolic root finding, and logarithm and trigonometric expression classes. It requires the core package to be loaded.
+
+The abstract classes in the algebra module all inherit from the \texttt{ConstantExpression} branch in the inheritance tree:
+
+\begin{itemize}
+ \item \texttt{Ring}
+ \item \texttt{EuclideanDomain}
+ \item \texttt{Field}
+\end{itemize}
+
+The {\ttfamily EuclideanDomain} class is a sub-class to the {\ttfamily Ring} class, and the {\ttfamily Field} class is a sub-class to the {\ttfamily EuclideanDomain} class.
+
+The following concrete classes inherit from the {\ttfamily Ring} class (or one of the sub-classes mentioned above). However, not all of them are proper {\ttfamily ConstantExpression}s, so some of them override the {\ttfamily isconstant()} method.
+
+\begin{itemize}
+ \item {\ttfamily Integer}
+ \item {\ttfamily IntegerModN}
+ \item {\ttfamily Rational}
+ \item {\ttfamily PolynomialRing}
+\end{itemize}
+
+The other concrete classes in the Algebra package do not inherit from the {\ttfamily Ring} interface, instead they inherit from the {\ttfamily CompoundExpression} interface:
+
+\begin{multicols}{2}
+\begin{itemize}
+ \item {\ttfamily AbsExpression}
+ \item {\ttfamily Logarithm}
+ \item {\ttfamily FactorialExpression}
+ \item {\ttfamily SqrtExpression}
+ \item {\ttfamily TrigExpression}
+ \item {\ttfamily RootExpression}
+ \item {\ttfamily Equation}
+\end{itemize}
+\end{multicols}
+
+\newcoderef{function Integer:new(n)}{return Integer}{n number|string|Integer}
+\index{Algebra!Classes!\texttt{SymbolExpression}}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer}
+
+Takes a \texttt{string}, \texttt{number}, or {\ttfamily Integer} input and constructs an \texttt{Integer} expression. The \texttt{Integer} class allows us to perform exact arithmetic on integers. Indeed, since Lua can only store integers exactly up to a certain point, it is recommended to use strings to build large integers.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+a = Integer(-12435)
+b = Integer('-12435')
+tex.print('\\[',a:tolatex(),
+ '=',
+ b:tolatex(),
+ '\\]')
+\end{minted}
+\tcblower
+\directlua{
+ a = Integer(-12435)
+ b = Integer('-12435')
+ tex.print('\\[',a:tolatex(),
+ '=',
+ b:tolatex(),
+ '\\]')
+}
+\end{codebox}
+An {\ttfamily Integer} is a table 1-indexed by Lua numbers consisting of Lua numbers. For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+tex.print(tostring(b[1]))
+\end{minted}
+\tcblower
+\directlua{
+ tex.print(tostring(b[1]))
+}
+\end{codebox}
+Whereas:
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{lua}
+c = Integer('7240531360949381947528131508')
+tex.print('The first 14 digits of c:', tostring(c[1]),'. ')
+tex.print('The last 14 digits of c:', tostring([2]),'.')
+\end{minted}
+\tcblower
+\directlua{
+ c = Integer('7240531360949381947528131508')
+ tex.print('The first 14 digits of c:', tostring(c[1]),'. ')
+ tex.print('The last 14 digits of c:', tostring(c[2]),'.')
+}
+\end{codebox}
+
+The global field {\ttfamily DIGITSIZE} is set to \texttt{14} so that exact arithmetic on {\ttfamily Integer}s can be done as efficiently as possible while respecting Lua's limitations.
+
+\subsubsection*{Fields}
+{\ttfamily Integer}s have a {\ttfamily .sign} field which contains the Lua number {\ttfamily 1} or {\ttfamily -1} depending on whether \texttt{Integer} is positive or negative.
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{lua}
+tex.print('The sign of',tostring(b),'is:',tostring(b.sign))
+\end{minted}
+\tcblower
+\directlua{
+ tex.print('The sign of',
+ tostring(b),
+ 'is:',
+ tostring(b.sign))
+}
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The contents of the environment \mintinline{latex}{\begin{CAS}..\end{CAS}} are wrapped in the argument of a function \mintinline{lua}{CASparse()} which, among other things, seeks out digit strings intended to represent integers, and wraps those in \texttt{Integer('...')}.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ c = 7240531360949381947528131508
+\end{CAS}
+\directlua{
+ tex.print(tostring(c[1]))
+}
+\end{minted}
+\tcblower
+\begin{CAS}
+ c = 7240531360949381947528131508
+\end{CAS}
+\directlua{
+ tex.print(tostring(c[1]))
+}
+\end{codebox}
+
+\newcoderef{function IntegerModN:new(i,n)}{return IntegerModN}{i Integer, n Integer}
+\index{Algebra!Classes!\texttt{IntegerModN}}
+\addcontentsline{toc}{subsubsection}{\ttfamily IntegerModN}
+
+Takes an {\ttfamily Integer i} and {\ttfamily Integer n} and constructs an element in the ring $\mathbf{Z}/n\mathbf{Z}$, the integers modulo $n$.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{lua}
+i = Integer(143)
+n = Integer(57)
+a = IntegerModN(i,n)
+tex.print('\\[',i:tolatex(),'\\equiv',a:tolatex(true),'\\]')
+\end{minted}
+\tcblower
+\luaexec{
+ i = Integer(143)
+ n = Integer(57)
+ a = IntegerModN(i,n)
+ tex.print('\\[',i:tolatex(),'\\equiv',a:tolatex(true),'\\]')
+}
+\end{codebox}
+
+\subsubsection*{Fields}
+
+{\ttfamily IntegerModN}s have two fields: {\ttfamily .element} and {\ttfamily .modulus}. The reduced input \texttt{i} is stored in {\ttfamily .element} while the input \texttt{n} is stored in {\ttfamily .modulus}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+tex.print(a.element:tolatex(),'\\newline')
+tex.print(a.modulus:tolatex())
+\end{minted}
+\tcblower
+\luaexec{
+ tex.print(a.element:tolatex(),'\\newline')
+ tex.print(a.modulus:tolatex())
+}
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \texttt{Mod(,)} is a shortcut for \texttt{IntegerModN(,)}:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ i = 143
+ n = 57
+ a = Mod(i,n)
+\end{CAS}
+\[\print{i}\equiv\print{a}\bmod{\print{n}}\]
+\end{minted}
+\tcblower
+\begin{CAS}
+ i = 143
+ n = 57
+ a = Mod(i,n)
+\end{CAS}
+\[ \print{i} \equiv \print{a} \bmod{\print{n}}\]
+\end{codebox}
+
+\newcoderef{function PolynomialRing:new(coefficients, symbol, degree)}{return PolynomialRing}{coefficients table<number,Ring>, symbol string|SymbolExpression, degree Integer}
+\index{Algebra!Classes!\texttt{PolynomialRing}}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing}
+
+Takes a table of {\ttfamily coefficients}, not all necessarily in the same ring, and a {\ttfamily symbol} to create a polynomial in $\mathtt{R[x]}$ where $\mathtt{x}$ is {\ttfamily symbol} and $\mathtt{R}$ is the smallest {\ttfamily Ring} possible given the coefficients. If {\ttfamily degree} is omitted, it will calculate the degree of the polynomial automatically. The list can either be one-indexed or zero-indexed, but if it is one-indexed, the internal list of coefficients will still be zero-indexed.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = PolynomialRing({0,1/3,-1/2,1/6},'t')
+\end{CAS}
+\[ \print{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = PolynomialRing({0,1/3,-1/2,1/6},'t')
+\end{CAS}
+\[ \print{f} \]
+\end{codebox}
+The \texttt{PolynomialRing} class overwrites the \mintinline{lua}{isatomic()} and \mintinline{lua}{isconstant()} inheritances from the abstract class \texttt{ConstantExpression}.
+\subsubsection*{Fields}
+
+\begin{multicols}{2}
+{\ttfamily PolynomialRing}s have several fields:
+\begin{itemize}
+ \item {\ttfamily f.coefficients} stores the 0-indexed table of coefficients of {\ttfamily f};
+ \item {\ttfamily f.degree} stores the {\ttfamily Integer} that represents the degree of {\ttfamily f};
+ \item {\ttfamily f.symbol} stores the {\ttfamily string} representing the variable or {\ttfamily symbol} of {\ttfamily f}.
+ \item {\ttfamily f.ring} stores the \texttt{RingIdentifier} for the ring of coefficients.
+\end{itemize}
+
+\columnbreak
+
+\parseshrub{f}
+\bracketset{action character = @}
+\begin{center}
+\begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners = 1pt,
+ fill=gray!20,
+ s sep = 1.5cm,
+ l sep = 2cm}
+ @\shrubresult
+\end{forest}
+\end{center}
+\end{multicols}
+For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+for i=0,f.degree:asnumber() do
+ tex.print('\\[',
+ f.coefficients[i]:tolatex(),
+ f.symbol,
+ '^{',
+ tostring(i),
+ '}\\]')
+end
+if f.ring == Rational.getring() then
+ tex.print('Rational coefficients')
+end
+\end{minted}
+\tcblower
+\luaexec{
+for i=0,f.degree:asnumber() do
+ tex.print(
+ '\\[',
+ f.coefficients[i]:tolatex(),
+ f.symbol,
+ '^{',
+ tostring(i),
+ '}\\]'
+ )
+ end
+ if f.ring == Rational.getring() then
+ tex.print('Rational coefficients')
+ end
+}
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{Poly()} is a shortcut for \mintinline{lua}{PolynomialRing:new()}. If the second argument \texttt{symbol} is omitted, then the default is \texttt{'x'}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({0,1/3,-1/2,1/6})
+\end{CAS}
+\[ \print{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({0,1/3,-1/2,1/6})
+\end{CAS}
+\[ \print{f} \]
+\end{codebox}
+
+Alternatively, one could typeset the polynomial naturally and use the \texttt{topoly()} function. This is the same as the \texttt{topolynomial()} method except that the \texttt{autosimplify()} method is automatically called first:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = 1/3*x - 1/2*x^2 + 1/6*x^3
+ f = topoly(f)
+\end{CAS}
+\[ \print{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = 1/3*x - 1/2*x^2 + 1/6*x^3
+ f = topoly(f)
+\end{CAS}
+\[ \print{f} \]
+\end{codebox}
+
+\newcoderef{function Rational:new(n,d,keep)}{return Rational}{n Ring, d Ring, keep bool}
+\index{Algebra!Classes!\texttt{Rational}}
+\addcontentsline{toc}{subsubsection}{\ttfamily Rational}
+
+Takes a numerator {\ttfamily n} and denominator {\ttfamily d} in the same {\ttfamily Ring} and constructs a rational expression in the field of fractions over that ring. For the integers, this is the ring of rational numbers. If the {\ttfamily keep} flag is omitted, the constructed object will be simplified to have smallest possible denominator, possibly returning an object in the original {\ttfamily Ring}. Typically, the {\ttfamily Ring} will be either {\ttfamily Integer} or {\ttfamily PolynomialRing}, so {\ttfamily Rational} can be viewed as a constructor for either a rational number or a rational function.
+
+For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+a = Integer(6)
+b = Integer(10)
+c = Rational(a,b)
+tex.print('\\[',c:tolatex(),'\\]')
+\end{minted}
+\tcblower
+\luaexec{
+ a = Integer(6)
+ b = Integer(10)
+ c = Rational(a,b)
+ tex.print('\\[',c:tolatex(),'\\]')
+}
+\end{codebox}
+But also:
+\begin{codebox}
+ \begin{minted}{lua}
+a = Poly({Integer(2),Integer(3)})
+b = Poly({Integer(4),Integer(1)})
+c = Rational(a,b)
+tex.print('\\[',c:tolatex(),'\\]')
+\end{minted}
+\tcblower
+\luaexec{
+a = Poly({Integer(2),Integer(3)})
+b = Poly({Integer(4),Integer(1)})
+c = Rational(a,b)
+tex.print('\\[',c:tolatex(),'\\]')
+}
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\texttt{Rational}s naturally have the two fields: \texttt{numerator}, \texttt{denominator}. These fields store precisely what you think. \texttt{Rational}s also have a \texttt{ring} field which stores the \texttt{RingIdentifier} to which the numerator and denominator belong. (This is $\mathbb{Z}$ for the rational numbers.)
+
+If \texttt{numerator} or \texttt{denominator} are \texttt{PolynomialRing}s, then the constructed \texttt{Rational} will have an additional field: \texttt{symbol}. This stores the symbol the polynomial rings are constructed over.
+
+\begin{codebox}[]
+ \begin{minted}{lua}
+if c.ring == PolynomialRing.getring() then
+ tex.print('$',c:tolatex(),'$ is a Rational Function in the variable',c.symbol)
+end
+\end{minted}
+\tcblower
+\luaexec{
+if c.ring == PolynomialRing.getring() then
+ tex.print('$',c:tolatex(),'$ is a Rational Function in the variable',c.symbol)
+end
+}
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+\texttt{Raional}s are constructed naturally using the \texttt{/} operator:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = Poly({2,3})
+ b = Poly({4,1})
+ c = a/b
+\end{CAS}
+\[ \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = Poly({2,3})
+ b = Poly({4,1})
+ c = a/b
+\end{CAS}
+\[ \print{c} \]
+\end{codebox}
+
+\coderef{function AbsExpression:new(expression)}{return AbsExpression}
+\addcontentsline{toc}{subsubsection}{\ttfamily AbsExpression}
+
+Creates a new absolute value expression with the given expression.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({1,1})
+ g = Poly({-1,1})
+ h = AbsExpression(f/g)
+\end{CAS}
+\[ h = \print{h} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({1,1})
+ g = Poly({-1,1})
+ h = AbsExpression(f/g)
+\end{CAS}
+\[ h = \print{h} \]
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\texttt{AbsExpression}s have only one field: \texttt{.expression}. This field simply holds the \texttt{Expression} inside the absolute value:
+\begin{multicols}{2}
+\begin{codebox}[]
+\begin{minted}[fontsize=\small]{lua}
+tex.print('\\[',
+ h.expression:tolatex(),
+ '\\]')
+\end{minted}
+\tcblower
+\directlua{
+ tex.print('\\[',h.expression:tolatex(),'\\]')
+}
+\end{codebox}
+\parseshrub{h}
+\bracketset{action character = @}
+\begin{center}
+\begin{forest}
+ for tree = {font=\ttfamily,
+ draw,
+ rounded corners=1pt,
+ fill=gray!20,
+ l sep =1.5cm}
+ @\shrubresult
+\end{forest}
+\end{center}
+\end{multicols}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{abs()} is a shortcut to \mintinline{lua}{AbsExpression:new()}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({1,1})
+ g = Poly({-1,1})
+ h = abs(f/g)
+\end{CAS}
+\[ h = \print{h} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({1,1})
+ g = Poly({-1,1})
+ h = abs(f/g)
+\end{CAS}
+\[ h = \print{h} \]
+\end{codebox}
+
+\newcoderef{function Logarithm:new(base,arg)}{return Logarithm}{base Expression, arg Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily Logarithm}
+
+Creates a new \texttt{Logarithm} expression with the given \texttt{base} and \texttt{arg}ument. Some basic simplification rules are known to \texttt{autosimplify()}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('b','x','y')
+ f = Logarithm(b,x^y)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('b','x','y')
+ f = Logarithm(b,x^y)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\begin{multicols}{2}
+\texttt{Logarithm}s have two fields: \texttt{base} and \texttt{expression}; \texttt{base} naturally stores the base of the logarithm (i.e., the first argument of \texttt{Logarithm}) while \texttt{expression} stores the argument of the logarithm (i.e., the second argument of \texttt{Logarithm}).
+
+\begin{center}
+ \parseshrub{f}
+ \bracketset{action character = @}
+ \begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners=1pt,
+ fill = gray!20,
+ s sep = 1.5cm}
+ @\shrubresult
+ \end{forest}
+\end{center}
+\end{multicols}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{log()} is a shortcut to \texttt{Logarithm}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('b')
+ f = log(b,b)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('b')
+ f = log(b,b)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{codebox}
+
+There is also a \mintinline{lua}{ln()} function to shortcut \texttt{Logarithm} where the base is \texttt{e}, the natural exponent.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = ln(e)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = ln(e)
+\end{CAS}
+\[ \print{f} = \print*{f} \]
+\end{codebox}
+
+\newcoderef{function FactorialExpression:new(expression)}{return FactorialExpression}{expression Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily FactorialExpression}
+
+Creates a new \texttt{FactorialExpression} with the given \texttt{expression}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = FactorialExpression(5)
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = FactorialExpression(5)
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+The \texttt{evaluate()} method will compute factorials of nonnegative \texttt{Integer}s:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = FactorialExpression(5)
+\end{CAS}
+\[ \print{a} = \print{a:evaluate()} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = FactorialExpression(5)
+\end{CAS}
+\[ \print{a} = \print{a:evaluate()} \]
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\texttt{FactorialExpression}s have only one field: \texttt{expression}. This field stores the argument of \texttt{FactorialExpression()}.
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{factorial()} is a shortcut to \texttt{FactorialExpression()}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = factorial(5)
+\end{CAS}
+\[ \print{a} = \print{a:evaluate()} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = factorial(5)
+\end{CAS}
+\[ \print{a} = \print{a:evaluate()} \]
+\end{codebox}
+
+\newcoderef{function SqrtExpression:new(expression, root)}{return SqrtExpression}{expression Expression, root Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily SqrtExpression}
+
+Creates a new \texttt{SqrtExpression} with the given \texttt{expression} and \texttt{root}. Typically, \texttt{expression} is an \texttt{Integer} or \texttt{Rational}, and \texttt{SqrtExpression} is intended to represent a positive real number. If \texttt{root} is omitted, then \texttt{root} defaults to \mintinline{lua}{Integer(2)}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+a = SqrtExpression(Integer(8))
+b = SqrtExpression(Integer(8),Integer(3))
+c = a+b
+tex.print('\\[',c:tolatex(),'\\]')
+\end{minted}
+\tcblower
+\directlua{
+ a = SqrtExpression(Integer(8))
+b = SqrtExpression(Integer(8),Integer(3))
+c = a+b
+tex.print('\\[',c:tolatex(),'\\]')
+}
+\end{codebox}
+When \texttt{expression} and \texttt{root} are of the \texttt{Integer} or \texttt{Rational} types, then \texttt{autosimplify()} does a couple things. For example, with \texttt{a,b} as above, we get:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+c = c:autosimplify()
+tex.print('\\[',c:tolatex(),'\\]')
+\end{minted}
+\tcblower
+\directlua{
+c = c:autosimplify()
+tex.print('\\[',c:tolatex(),'\\]')
+}
+\end{codebox}
+On the other hand, if \texttt{root} or \texttt{expression} are not constants, then typically \mintinline{lua}{autosimplify()} will convert \texttt{SqrtExpression} to the appropriate \texttt{BinaryOperation}. For example:
+
+\directlua{
+ vars('x')
+ a = SqrtExpression(x,Integer(3))
+ b = a:autosimplify()
+}
+
+\begin{multicols}{2}
+ \begin{center}
+ \underline{Tree for \texttt{a}}
+
+\parseshrub{a}
+\bracketset{action character = @}
+\begin{forest}
+ for tree = {s sep=2cm,
+ font=\ttfamily,
+ draw,
+ rounded corners = 1pt,
+ fill=gray!20}
+ @\shrubresult
+\end{forest}
+
+ \underline{Tree for \texttt{a:autosimplify()}}
+
+\parseshrub{a:autosimplify()}
+\bracketset{action character = @}
+\begin{forest}
+ for tree = {s sep=2cm,
+ font=\ttfamily}
+ @\shrubresult
+\end{forest}
+\end{center}
+\end{multicols}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{sqrt()} shortcuts \texttt{SqrtExpression()}:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = sqrt(1/9)
+ b = sqrt(27/16,3)
+ c = a+b
+\end{CAS}
+\[ \print{c} = \print*{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = sqrt(1/9)
+ b = sqrt(27/16,3)
+ c = a+b
+\end{CAS}
+\[ \print{c} = \print*{c} \]
+\end{codebox}
+
+\newcoderef{function TrigExpression:new(name,expression)}{return TrigExpression}{name string|SymbolExpression, expression Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily TrigExpression}
+
+Creates a new trig expression with the given \texttt{name} and \texttt{expression}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+vars('x')
+f = TrigExpression('sin',x)
+tex.print('\\[',f:tolatex(),'\\]')
+\end{minted}
+\tcblower
+\directlua{
+ vars('x')
+ f = TrigExpression('sin',x)
+ tex.print('\\[',f:tolatex(),'\\]')
+}
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\begin{multicols}{2}
+
+\texttt{TrigExpression}s have many fields:
+\begin{itemize}
+ \item \mintinline{lua}{TrigExpression.name} stores the string \texttt{name}, i.e. the first argument of \mintinline{lua}{TrigExpression()};
+ \item \mintinline{lua}{TrigExpression.expression} stores the \texttt{Expression} \texttt{expression}, i.e. the second argument of \mintinline{lua}{TrigExpression()};
+ \item and all fields inherited from \texttt{FunctionExpression} (e.g. \mintinline{lua}{TrigExpression.derivatives} which defaults to \mintinline{lua}{Integer.zero()}).
+\end{itemize}
+
+\columnbreak
+
+\begin{center}
+\parseshrub{f}
+\bracketset{action character = @}
+\begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners = 1pt,
+ fill = gray!20,
+ l sep = 2cm}
+ @\shrubresult
+\end{forest}
+\end{center}
+\end{multicols}
+
+\subsubsection*{Parsing}
+
+The usual trigonometric functions have the anticipated shortcut names. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = arctan(x^2)
+\end{CAS}
+\[ \print{f} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = arctan(x^2)
+\end{CAS}
+\[ \print{f} \]
+\end{codebox}
+
+\newcoderef{function RootExpression:new(expression)}{return RootExpression}{expression Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily RootExpression}
+
+Creates a new \texttt{RootExpression} with the given \texttt{expression}. The method \mintinline{lua}{RootExpression:autosimplify()} attempts to return a list of zeros of \texttt{expression}. If no such set can be found, then
+
+\mintinline{lua}{RootExpression(expression:autosimplify())}
+
+is returned instead. At the moment, \texttt{expression} must be a univariate polynomial of degree $0,1,2$ or $3$ in order for the \texttt{autosimplify()} method to return anything interesting. Of course, \texttt{luacas} can find roots of higher degree polynomials, but this involves more machinery/methods within the \texttt{PolynomialRing} class.
+
+\subsubsection*{Fields}
+\texttt{RootExpression}s have only one field: \texttt{.expression}. For example:
+\begin{multicols}{2}
+ \begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({3,2,1})
+ r = RootExpression(f)
+\end{CAS}
+\[ \print{r} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({3,2,1})
+ r = RootExpression(f)
+\end{CAS}
+\[ \print{r} \]
+\end{codebox}
+
+\begin{center}
+\parseshrub{r}
+\bracketset{action character = @}
+\begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners=1pt,
+ fill=gray!20,
+ l sep = 2cm}
+ @\shrubresult
+\end{forest}
+\end{center}
+\end{multicols}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{roots()} essentially shortcuts \texttt{RootExpression()}, but when \texttt{expression} is of the \texttt{PolynomialRing}-type, then \texttt{PolynomialRing:roots()} is returned.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ r = roots(f)
+\end{CAS}
+\[ \print{r[1]} \qquad \print{r[2]} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ r = roots(f)
+\end{CAS}
+\[ \print{r[1]} \qquad \print{r[2]} \]
+\end{codebox}
+
+
+\newcoderef{function Equation:new(lhs, rhs)}{return Equation}{lhs Expression, rhs Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily Equation}
+
+Creates a new \texttt{Equation} expression with the given \texttt{lhs} (left hand side) and \texttt{rhs} (right hand side). If both sides of the equation are constants, or structurally identical, \texttt{autosimplify()} will return a boolean:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x','y')
+ f = Equation(sin(x-y),sin(x-y))
+ g = f:autosimplify()
+\end{CAS}
+\[ \print{f} \to \print{g} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x','y')
+ f = Equation(sin(x-y),sin(x-y))
+ g = f:autosimplify()
+\end{CAS}
+\[ \print{f} \to true \]
+\end{codebox}
+
+\subsubsection*{Fields}
+
+\begin{multicols}{2}
+\texttt{Equation}s have two fields: \texttt{lhs} and \texttt{rhs}; which store the expressions on the left and right sides of the equation.
+
+\begin{center}
+ \parseshrub{f}
+ \bracketset{action character = @}
+ \begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners=1pt,
+ fill = gray!20,
+ s sep = 1.5cm}
+ @\shrubresult
+ \end{forest}
+\end{center}
+\end{multicols}
+
+\end{document} \ No newline at end of file
diff --git a/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_methods/ref_algebra_methods.tex b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_methods/ref_algebra_methods.tex
new file mode 100644
index 0000000000..b576cdc1a3
--- /dev/null
+++ b/macros/luatex/latex/luacas/doc/reference/ref_algebra/ref_algebra_methods/ref_algebra_methods.tex
@@ -0,0 +1,1305 @@
+\documentclass{article}
+
+\usepackage{luacas}
+\usepackage{amsmath}
+\usepackage{amssymb}
+
+\usepackage[margin=1in]{geometry}
+\usepackage[shortlabels]{enumitem}
+
+\usepackage{pgfplots}
+\pgfplotsset{compat=1.18}
+\usetikzlibrary{positioning,calc}
+\usepackage{forest}
+\usepackage{minted}
+\usemintedstyle{pastie}
+\usepackage[hidelinks]{hyperref}
+\usepackage{parskip}
+\usepackage{multicol}
+\usepackage[most]{tcolorbox}
+ \tcbuselibrary{xparse,documentation}
+\usepackage{microtype}
+\usepackage{makeidx}
+\usepackage{fontawesome5}
+
+\usepackage[
+backend=biber,
+style=numeric,
+]{biblatex}
+\addbibresource{sources.bib}
+
+\definecolor{rose}{RGB}{128,0,0}
+\definecolor{roseyellow}{RGB}{222,205,99}
+\definecolor{roseblue}{RGB}{167,188,214}
+\definecolor{rosenavy}{RGB}{79,117,139}
+\definecolor{roseorange}{RGB}{232,119,34}
+\definecolor{rosegreen}{RGB}{61,68,30}
+\definecolor{rosewhite}{RGB}{223,209,167}
+\definecolor{rosebrown}{RGB}{108,87,27}
+\definecolor{rosegray}{RGB}{84,88,90}
+
+\definecolor{codegreen}{HTML}{49BE25}
+
+\newtcolorbox{codebox}[1][sidebyside]{
+ enhanced,skin=bicolor,
+ #1,
+ arc=1pt,
+ colframe=brown,
+ colback=brown!15,colbacklower=white,
+ boxrule=1pt,
+ notitle
+}
+
+\newtcolorbox{codehead}[1][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1
+}
+
+\DeclareTotalTCBox{\lilcoderef}{O{} m m}{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ enhanced,
+ nobeforeafter,
+ tcbox raise base,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=1mm,
+ right=1mm,
+ top=1mm,
+ bottom=1mm,
+ oversize,
+ #1
+}{\mintinline{lua}{#2} \mintinline{lua}{#3}}
+
+\usepackage{varwidth}
+
+\newtcolorbox{newcodehead}[2][]{
+ enhanced,
+ frame hidden,
+ colback=rosegray!15,
+ boxrule=0mm,
+ leftrule=5mm,
+ rightrule=5mm,
+ boxsep=0mm,
+ arc=0mm,
+ outer arc=0mm,
+ left=3mm,
+ right=3mm,
+ top=1mm,
+ bottom=1mm,
+ toptitle=1mm,
+ bottomtitle=1mm,
+ oversize,
+ #1,
+ fonttitle=\bfseries\ttfamily\footnotesize,
+ coltitle=rosegray,
+ attach boxed title to top text right,
+ boxed title style={frame hidden,size=small,bottom=-1mm,
+ interior style={fill=none,
+ top color=white,
+ bottom color=white}},
+ title={#2}
+}
+
+\makeindex
+
+\newcommand{\coderef}[2]{%
+\begin{codehead}[sidebyside,segmentation hidden]%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{codehead}%
+}
+
+\newcommand{\newcoderef}[3]{%
+\begin{newcodehead}[sidebyside,segmentation hidden]{#3}%
+ \mintinline{lua}{#1}%
+ \tcblower%
+ \begin{flushright}%
+ \mintinline{lua}{#2}%
+ \end{flushright}%
+\end{newcodehead}%
+}
+\usepackage{marginnote}
+
+\begin{document}
+\setdescription{style=multiline,
+ topsep=10pt,
+ leftmargin=6.5cm,
+ }
+
+\subsection{Algebra Methods}
+
+Many classes in the algebra package inherit from the {\ttfamily Ring} interface. The {\ttfamily Ring} interface requires the following arithmetic operations, which have corresponding abstract metamethods listed below. Of course, these abstract methods get passed to the appropriate concrete methods in the concrete classes that inherit from {\ttfamily Ring}.
+
+For {\ttfamily Ring} objects {\ttfamily a} and {\ttfamily b}:
+
+\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}
+\begin{description}%[labelwidth = 6.5cm,align=parright]
+ \item[\lilcoderef{function a:add(b)}{return a + b}] Adds two ring elements.
+ \item[\lilcoderef{function a:sub(b)}{return a - b}] Subtracts one ring element from another. Subtraction has a default implementation in {\ttfamily Ring.lua} as adding the additive inverse, but this can be overwritten if a faster performance method is available.
+ \item[\lilcoderef{function a:neg()}{return -a}] Returns the additive inverse of a ring element.
+ \item[\lilcoderef{function a:mul(b)}{return a * b}] Multiplies two ring elements.
+ \item[\lilcoderef{function a:pow(n)}{return a ^ n}] Raises one ring element to the power of an integer. Exponentiation has a default implementation as repeated multiplication, but this can (and probably should) be overwritten for faster performance.
+ \item[\lilcoderef{function a:eq(b)}{return a == b}] Tests if two ring elements are the same.
+ \item[\lilcoderef{function a:lt(b)}{return a < b}] Tests if one ring element is less than another under some total order. If the ring does not have a natural total order, this method does not need to be implemented.
+ \item[\lilcoderef{function a:le(b)}{return a <= b}] Tests if one ring element is less than or equal to another under some total order. If the ring does not have a natural total order, this method does not need to be implemented.
+ \item[\lilcoderef{function a:zero()}{return Ring}] Returns the additive identity of the ring to which \texttt{a} belongs.
+ \item[\lilcoderef{function a:one()}{return Ring}] Returns the multiplicative identity of the ring to which \texttt{a} belongs.
+\end{description}
+
+\reversemarginpar
+Arithmetic\marginnote{\color{rose}\large\faHandPointRight} of {\ttfamily Ring} elements will (generally) not form a {\ttfamily BinaryOperation}. Instead, the appropriate \mintinline{lua}{__RingOperation} is called which then passes the arithmetic to a specific ring, if possible. For example:
+\begin{codebox}
+ \begin{minted}[breaklines,fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({2,1})
+ g = Poly({2,5})
+ h = f+g
+\end{CAS}
+\[ (\print{f}) + (\print{g}) = \print{h} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({2,1})
+ g = Poly({2,5})
+ h = f+g
+\end{CAS}
+\[ (\print{f}) + (\print{g}) = \print{h} \]
+\end{codebox}
+So why have the {\ttfamily Ring} class to begin with? Many of the rings in the algebra package are subsets of one another. For instance, integers are subsets of rationals, which are subsets of polynomial rings over the rationals, etc. To smoothly convert objects from one ring to another, it's good to have a class like {\ttfamily Ring} to handle all the ``traffic.''
+
+For example, the {\ttfamily RingIdentifier} object acts as a pseudo-class that stores information about the exact ring of an object, including the symbol the ring has if it's a polynomial ring. To perform operations on two elements of different rings, the CAS does the following:
+
+To get the generic {\ttfamily RingIdentifier} from a class, it uses the static method:
+\coderef{function Ring.makering()}{return RingIdentifier}
+
+To get the {\ttfamily RingIdentifier} from a specific instance (element) of a ring, it uses the method:
+
+\coderef{function Ring:getring()}{return RingIdentifier}
+
+So, for example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+a = Integer(2)/Integer(3)
+ring = a:getring()
+if ring == Integer.makering() then
+ tex.print('same rings')
+else
+ tex.print('different rings')
+end
+\end{minted}
+\tcblower
+\luaexec{
+a = Integer(2)/Integer(3)
+ring = a:getring()
+if ring == Integer.makering() then
+ tex.print('same rings')
+else
+ tex.print('different rings')
+end
+}
+\end{codebox}
+
+From there, the CAS computes the smallest {\ttfamily RingIdentifier} that contains the two {\ttfamily RingIdentifier}s as subsets using the static method:
+
+\newcoderef{function Ring.resultantring(ring1,ring2)}{return RingIdentifier}{ring1 RingIdentifier, ring2 RingIdentifier}
+
+So, for example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+a = Poly({Integer(2),Integer(1)})
+b = Integer(3)
+ring1 = a:getring()
+ring2 = b:getring()
+ring = Ring.resultantring(ring1,ring2)
+if ring == a:getring() then
+ tex.print('polynomial ring')
+end
+\end{minted}
+\tcblower
+\luaexec{
+ a = Poly({Integer(2),Integer(1)})
+ b = Integer(3)
+ ring1 = a:getring()
+ ring2 = b:getring()
+ ring = Ring.resultantring(ring1,ring2)
+ if ring == a:getring() then
+ tex.print('polynomial ring')
+ end
+}
+\end{codebox}
+
+Finally, the CAS converts both objects into the resultant {\ttfamily RingIdentifier}, if possible, using the method:
+
+\coderef{function Ring:inring(ring)}{return Ring}
+
+So, for example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{lua}
+b = b:inring(ring)
+if b:type() == PolynomialRing then
+ tex.print('b is a polynomial now')
+end
+\end{minted}
+\tcblower
+\luaexec{
+ b = b:inring(ring)
+ if b:type() == PolynomialRing then
+ tex.print('b is a polynomial now')
+ end
+}
+\end{codebox}
+
+Finally, the CAS is able to perform the operation with the correct \mintinline{lua}{__RingOperation}. This all happens within the hierarchy of \texttt{Ring} classes automatically:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = Poly({1/2,3,1})
+ b = 1/2
+ c = a+b
+\end{CAS}
+\[ \print{a} + \print{b} = \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = Poly({1/2,3,1})
+ b = 2/3
+ c = a+b
+\end{CAS}
+\[ \print{a} + \print{b} = \print{c} \]
+\end{codebox}
+
+
+To add another class that implements {\ttfamily Ring} and has proper conversion abilities, the {\ttfamily resultantring} method needs to be updated to include all possible resultant rings constructed from the new ring and existing rings. The other three methods need to be implemented as well.
+
+\hrulefill
+
+We now discuss the more arithmetic methods included in the algebra package beginning with the \texttt{PolynomialRing} class.
+
+\coderef{function PolynomialRing:decompose()}{return table<number, PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:decompose}
+
+Returns a list of polynomials that form a complete decomposition of the given polynomial. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({5,-4,5,-2,1})
+ d = f:decompose()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({5,-4,5,-2,1})
+ d = f:decompose()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{codebox}
+In particular, the code:
+\begin{minted}{lua}
+g = d[2]:evaluateat(d[1])
+tex.print('\\[', g:tolatex(), '\\]')
+\end{minted}
+recovers $f$:
+\luaexec{
+ g = d[2]:evaluateat(d[1])
+ tex.print('\\[', g:tolatex(), '\\]')
+}
+
+
+
+\coderef{function PolynomialRing:derivative()}{return PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:derivative}
+
+Returns the formal derivative of the given polynomial. For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({1,1,1/2,1/6})
+ g = f:derivative()
+\end{CAS}
+\[ \print{f} \xrightarrow{d/dx}
+ \print{g} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({1,1,1/2,1/6})
+ g = f:derivative()
+\end{CAS}
+\[ \print{f} \xrightarrow{d/dx}
+ \print{g} \]
+\end{codebox}
+
+\coderef{function PolynomialRing:divisors()}{return table<number, PolynomialRing>}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:divisors}
+
+Returns a list of all monic divisors of positive degree of the polynomial, assuming the polynomial ring is a Euclidean Domain. For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly(x^4 - 2*x^3 - x + 2)
+ d = f:divisors()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly(x^4 - 2*x^3 - x + 2)
+ d = f:divisors()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{codebox}
+
+\newcoderef{function PolynomialRing:divremainder(poly1)}{return poly2,poly3}{poly1 PolynomialRing,..., poly3 PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:divremainder}
+
+Uses synthetic division to return the quotient (\texttt{poly2}) and remainder (\texttt{poly3}) of \texttt{self/poly1}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({2,2,1})
+ g = Poly({1,1})
+ q,r = f:divremainder(g)
+\end{CAS}
+\[ \print{f} = (\print{g})(\print{q})
+ + \print{r} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({2,2,1})
+ g = Poly({1,1})
+ q,r = f:divremainder(g)
+\end{CAS}
+\[ \print{f} = (\print{g})(\print{q})
+ + \print{r} \]
+\end{codebox}
+
+\newcoderef{function PolynomialRing.extendedgcd(poly1,poly2)}{return poly3, poly4, poly5}{poly1 PolynomialRing, poly2 PolynomialRing, ..., poly5 PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:extendedgcd}
+
+Given two \texttt{PolynomialRing} elements \texttt{poly1,poly2} returns:
+\begin{itemize}
+ \item \texttt{poly3}: the gcd of \texttt{poly1,poly2};
+ \item \texttt{poly4,poly5}: the coefficients from Bezout's lemma via the extended gcd.
+\end{itemize}
+For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly((x-1)*(x-2)*(x-3))
+ g = topoly((x-1)*(x+2)*(x+3))
+ h,a,b = PolynomialRing.extendedgcd(f,g)
+\end{CAS}
+\[ \print{f*a+g*b} = (\print{f})\left( \print{a} \right) +
+ (\print{g})\left(\print{b} \right)\]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly((x-1)*(x-2)*(x-3))
+ g = topoly((x-1)*(x+2)*(x+3))
+ h,a,b = PolynomialRing.extendedgcd(f,g)
+\end{CAS}
+\[ \print{f*a+g*b} = (\print{f})\left( \print{a} \right) +
+ (\print{g})\left(\print{b} \right)\]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \texttt{gcdext()} is a shortcut to \texttt{Polynomial.extendedgcd()}:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly((x+2)*(x-3))
+ g = topoly((x+4)*(x-3))
+ h,a,b = gcdext(f,g)
+\end{CAS}
+\[ \print{h} = (\print{f}) \left( \print{a} \right) +
+ (\print{g})\left( \print{b} \right). \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly((x+2)*(x-3))
+ g = topoly((x+4)*(x-3))
+ h,a,b = gcdext(f,g)
+\end{CAS}
+\[ \print{h} = (\print{f}) \left( \print{a} \right) + (\print{g})\left( \print{b} \right). \]
+\end{codebox}
+
+\coderef{function PolynomialRing:evaluateat(Expression)}{return Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:evaluateat}
+
+Uses Horner's rule to evaluate a polynomial at \texttt{Expression}. Typically, the input \texttt{Expression} is an \texttt{Integer} or \texttt{Rational}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({2,2,1})
+ p = f:evaluateat(1/2)
+\end{CAS}
+\[ \left. \print{f} \right|_{x=1/2}
+ = \print{p} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({2,2,1})
+ p = f:evaluateat(1/2)
+\end{CAS}
+\[ \left. \print{f} \right|_{x=1/2}
+ = \print{p} \]
+\end{codebox}
+
+\coderef{function PolynomialRing:factor()}{return BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:factor}
+
+Factors the given polynomial into irreducible terms over the polynomial ring to which the coefficients belong. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({8,24,32,24,10,2})
+ a = f:factor()
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({8,24,32,24,10,2})
+ a = f:factor()
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+
+On the other hand:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({Mod(1,5),Mod(0,5),Mod(1,5)})
+ a = f:factor()
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({Mod(1,5),Mod(0,5),Mod(1,5)})
+ a = f:factor()
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+
+The syntax \mintinline{lua}{f = Poly({Mod(1,5),Mod(0,5),Mod(1,5)})} is awkward. Alternatively, one can use the following instead:
+\begin{codebox}
+ \begin{minted}{latex}
+\begin{CAS}
+ f = Mod(Poly({1,0,1}),5)
+ a = f:factor()
+\end{CAS}
+\[ \print{f} = \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Mod(Poly({1,0,1}),5)
+ a = f:factor()
+\end{CAS}
+\[ \print{f} = \print{a} \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{factor()} shortcuts \mintinline{lua}{PolynomialRing:factor()}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({8,24,32,24,10,2})
+ a = factor(f)
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({8,24,32,24,10,2})
+ a = factor(f)
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+
+\newcoderef{function PolynomialRing:freeof(symbol)}{return bool}{symbol SymbolExpression}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:freeof}
+
+Checks the value of the field \mintinline{lua}{PolynomialRing.symbol} against \texttt{symbol}; returns \mintinline{lua}{true} if these symbols are not equal, and returns \mintinline{lua}{false} otherwise.
+
+Recall: the default symbol for \texttt{Poly} is \texttt{'x'}. So, for example:
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = Poly({2,2,1})
+ vars('t')
+ if f:freeof(t) then
+ tex.print('$',f:tolatex(),'$ is free of $',t:tolatex(),'$')
+ else
+ tex.print('$',f:tolatex(),'$ is bound by $',t:tolatex(),'$')
+ end
+\end{CAS}
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = Poly({2,2,1})
+ vars('t')
+ if f:freeof(t) then
+ tex.print('$',f:tolatex(),'$ is free of $',t:tolatex(),'$')
+ else
+ tex.print('$',f:tolatex(),'$ is bound by $',t:tolatex(),'$')
+ end
+\end{CAS}
+\end{codebox}
+
+\newcoderef{function PolynomialRing.gcd(poly1,poly2)}{return poly3}{poly1 PolynomialRing,..., poly3 PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing.gcd}
+
+Returns the greatest common divisor of two polynomials in a ring (assuming \texttt{poly1,poly2} belong to a Euclidean domain). For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly((x^2+1)*(x-1))
+ g = topoly((x^2+1)*(x+2))
+ h = PolynomialRing.gcd(f,g)
+\end{CAS}
+\[ \gcd(\print{f},\print{g}) = \print{h} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly((x^2+1)*(x-1))
+ g = topoly((x^2+1)*(x+2))
+ h = PolynomialRing.gcd(f,g)
+\end{CAS}
+\[ \gcd(\print{f},\print{g}) = \print{h} \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{gcd()} shortcuts \mintinline{lua}{PolynomialRing.gcd()}. For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly(x^3 - x^2 + x - 1)
+ g = topoly(x^3 + 2*x^2 + x + 2)
+ h = gcd(f,g)
+\end{CAS}
+\[ \gcd(\print{f},\print{g}) = \print{h}.\]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly(x^3 - x^2 + x - 1)
+ g = topoly(x^3 + 2*x^2 + x + 2)
+ h = gcd(f,g)
+\end{CAS}
+\[ \gcd(\print{f},\print{g}) = \print{h}.\]
+\end{codebox}
+
+\coderef{function PolynomialRing:isatomic()}{return false}
+\coderef{function PolynomialRing:isconstant()}{return false}
+
+The inheritances from \texttt{ConstantExpression} are overridden for the \texttt{PolynomialRing} class.
+
+\newcoderef{function PolynomialRing.monicgcdremainders(poly1,poly2)}{return table<number, Ring>}{poly1 PolynomialRing, poly2 PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing.monicgcdremainders}
+
+Given two polynomials \texttt{poly1} and \texttt{poly2}, returns a list of the remainders generated by the monic Euclidean algorithm.
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly(x^13-1)
+ g = topoly(x^8-1)
+ r = PolynomialRing.monicgcdremainders(f,g)
+\end{CAS}
+\luaexec{
+ for i=1,\#r do
+ tex.print('\\[', r[i]:tolatex(), '\\]')
+ end
+}
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly(x^13-1)
+ g = topoly(x^8-1)
+ r = PolynomialRing.monicgcdremainders(f,g)
+\end{CAS}
+\luaexec{
+ for i=1,\#r do
+ tex.print('\\[', r[i]:tolatex(), '\\]')
+ end
+}
+\end{codebox}
+
+\coderef{function PolynomialRing.mul_rec(poly1,poly2)}{return PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing.mul{\textunderscore}rec}
+
+Performs Karatsuba multiplication without constructing new polynomials recursively. But grade-school multiplication of polynomials is actually faster here up to a very large polynomial size due to Lua's overhead.
+
+\newcoderef{function PolynomialRing.partialfractions(g,f,ffactors)}{return BinaryOperation}{g PolynomialRing, f PolynomialRing, ffactors BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing.partialfractions}
+
+Returns the partial fraction decomposition of the rational function \texttt{g/f} given \texttt{PolynomialRing}s \texttt{g, f}, and some (not necessarily irreducible) factorization \texttt{ffactors} of \texttt{f}. If the factorization is omitted, the irreducible factorization is used. The degree of \texttt{g} must be less than the degree of \texttt{f}.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ g = topoly(4*x^2+2*x+2)
+ f = topoly((x^2+1)^2*(x+1))
+ a = PolynomialRing.partialfractions(g,f)
+\end{CAS}
+\[ \print{g/f} = \print*{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ g = topoly(4*x^2+2*x+2)
+ f = topoly((x^2+1)^2*(x+1))
+ a = PolynomialRing.partialfractions(g,f)
+\end{CAS}
+\[ \print{g/f} = \print*{a} \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{parfrac()} shortcuts the more long winded \mintinline{lua}{PolynomialRing.partialfractions()}. Additionally, the \texttt{parfrac} function will automatically try to convert the first two arguments to the \texttt{PolynomialRing} type via \mintinline{lua}{topoly()}.
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ g = 4*x^2+2*x+2
+ f = (x^2+1)^2*(x+1)
+ a = parfrac(g,f)
+\end{CAS}
+\[ \print{g/f} = \print*{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ g = 4*x^2+2*x+2
+ f = (x^2+1)^2*(x+1)
+ a = parfrac(g,f)
+\end{CAS}
+\[ \print{g/f} = \print*{a} \]
+\end{codebox}
+
+\newcoderef{function PolynomialRing:rationalroots()}{return remaining, roots}{remaining PolynomialRing, roots table<number,PolynomialRing>}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:rationalroots}
+
+This method finds the factors of \texttt{PolynomialRing} (up to multiplicity) that correspond to rational roots; these factors are stored in a table \texttt{roots} and returned in the second output of the method. Those factors are then divided out of \texttt{Polynomialring}; the \texttt{PolynomialRing} that remains is returned in the first output of the method. For example:
+
+\begin{codebox}
+ \begin{minted}[breaklines,fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly((x-1)^2*(x+1)*(x^2+1))
+ g,r = f:rationalroots()
+\end{CAS}
+The factors of $f$ corresponding to rational roots are:
+\luaexec{
+ for i =1, \#r do
+ tex.print('\\[', r[i]:tolatex(), '\\]')
+ end
+}
+The part of $f$ that remains after dividing out these linear terms is:
+\[ \print{g} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly((x-1)^2*(x+1)*(x^2+1))
+ g,r = f:rationalroots()
+ \end{CAS}
+ The factors of $f$ corresponding to rational roots are:
+ \luaexec{
+ for i =1, \#r do
+ tex.print('\\[', r[i]:tolatex(), '\\]')
+ end
+ }
+ The part of $f$ that remains after dividing out these linear terms is:
+ \[ \print{g} \]
+\end{codebox}
+
+\coderef{function PolynomialRing:roots()}{return table<number, Expression}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:roots}
+
+Returns a list of roots of \texttt{PolynomialRing}, simplified up to cubics. For example:
+
+\begin{codebox}[]
+ \begin{minted}[breaklines,fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly(x^6 + 3*x^5 + 6*x^4 + 7*x^3 + 6*x^2 + 3*x + 2)
+ r = f:roots()
+\end{CAS}
+$ \left\{ \lprint{r} \right\}$
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly(x^6 + 3*x^5 + 6*x^4 + 7*x^3 + 6*x^2 + 3*x + 2)
+ r = f:roots()
+\end{CAS}
+$ \left\{ \lprint{r} \right\}$
+\end{codebox}
+If the decomposition of \texttt{PolynomialRing} (or a factor thereof) is not a chain of cubics or lesser degree polynomials, then \texttt{RootExpression} is returned instead. For example:
+
+\begin{codebox}[]
+ \begin{minted}[breaklines,fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly(x^6 + x^5 - x^4 + 2*x^3 + 4*x^2 - 2)
+ r = f:roots()
+\end{CAS}
+\[ \left\{ \lprint{r} \right\} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly(x^6 + x^5 - x^4 + 2*x^3 + 4*x^2 - 2)
+ r = f:roots()
+\end{CAS}
+\[ \left\{ \lprint{r} \right\} \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{roots()} shortcuts \mintinline{lua}{PolynomialRing:roots()}. Also, the function \texttt{roots} attempts to cast the argument as a polynomial automatically using \mintinline{lua}{topoly()}. For example:
+
+\begin{codebox}
+ \begin{minted}[breaklines,fontsize=\small]{latex}
+\begin{CAS}
+ f = x^6+x^5-x^4+2*x^3+4*x^2-2
+ r = roots(f)
+\end{CAS}
+$ \left\{ \lprint{r} \right\}$
+\end{minted}
+\tcblower
+ \begin{CAS}
+ f = x^6 + x^5 - x^4 + 2*x^3 + 4*x^2 - 2
+ r = roots(f)
+ \end{CAS}
+ $ \left\{ \lprint{r} \right\}$
+\end{codebox}
+
+\newcoderef{function PolynomialRing.resultant(a,b)}{return Field}{a PolynomialRing, b PolynomialRing}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing.resultant}
+
+Returns the resultant of two polynomials \texttt{a,b} in the same ring, whose coefficients are all part of a field. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly(x^2-2*x+1)
+ g = topoly(x^2+2*x-3)
+ r = PolynomialRing.resultant(f,g)
+\end{CAS}
+\[ \operatorname{res}(f,g) = \print{r} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly(x^2-2*x+1)
+ g = topoly(x^2+2*x-3)
+ r = PolynomialRing.resultant(f,g)
+\end{CAS}
+\[ \operatorname{res}(f,g) = \print{r} \]
+\end{codebox}
+
+\coderef{function PolynomialRing:squarefreefactorization()}{return BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily PolynomialRing:squarefreefactorization}
+
+Returns the square-free factorization of a polynomial defined over the rationals.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars('x')
+ f = topoly(x^7 - 13*x^6 + 66*x^5 - 158*x^4 + 149*x^3 + 63*x^2 - 216*x + 108)
+ s = f:squarefreefactorization()
+\end{CAS}
+\[ \print{s} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars('x')
+ f = topoly(x^7 - 13*x^6 + 66*x^5 - 158*x^4 + 149*x^3 + 63*x^2 - 216*x + 108)
+ s = f:squarefreefactorization()
+\end{CAS}
+\[ \print{s} \]
+\end{codebox}
+
+If the polynomial is defined over $\mathbf{Z}/p\mathbf{Z}$ (where $p$ is prime), then the method \texttt{modularsquarefreefactorization()} should be used.
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{factor()} has an optional boolean argument that if set to \mintinline{lua}{true} returns \texttt{squarefreefactorization()} or \texttt{modularsquarefreefactorization()} (as appropriate). For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly(x^6 + 2*x^5 + 4*x^4 + 4*x^3 + 5*x^2 + 2*x + 2)
+ s = factor(f,true)
+\end{CAS}
+\[ \print{s} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly(x^6 + 2*x^5 + 4*x^4 + 4*x^3 + 5*x^2 + 2*x + 2)
+ s = factor(f,true)
+\end{CAS}
+\[ \print{s} \]
+\end{codebox}
+And also:
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ f = topoly(x^6 + 2*x^5 + 4*x^4 + 4*x^3 + 5*x^2 + 2*x + 2)
+ f = Mod(f,5)
+ s = factor(f,true)
+\end{CAS}
+\[ \print{s} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ f = topoly(x^6 + 2*x^5 + 4*x^4 + 4*x^3 + 5*x^2 + 2*x + 2)
+ f = Mod(f,5)
+ s = factor(f,true)
+\end{CAS}
+\[ \print{s} \]
+\end{codebox}
+
+\newcoderef{function Integer.gcd(a,b)}{return Integer}{a Integer, b Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Ingeger.gcd}
+
+Returns the greatest common divisor of \texttt{a,b}. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ b = 252
+ c = Integer.gcd(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ b = 252
+ c = Integer.gcd(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{gcd()} shortcuts \texttt{Integer.gcd()}. For example:
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ b = 252
+ c = gcd(a,b)
+\[ \gcd(a,b) = \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ b = 252
+ c = gcd(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} \]
+\end{codebox}
+
+
+\newcoderef{function Integer.extendedgcd(a,b)}{return Integer, Integer, Integer}{a Integer, b Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer.extendedgcd}
+
+Returns the greatest common divisor of \texttt{a,b} as well as Bezout's coefficients via extended gcd. For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ b = 252
+ c,x,y = Integer.extendedgcd(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} = \print{a}(\print{x}) + \print{b}(\print{y}) \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ b = 252
+ c,x,y = Integer.extendedgcd(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} = \print{a}(\print{x}) + \print{b}(\print{y}) \]
+\end{codebox}
+
+\subsubsection*{Parsing}
+
+The function \mintinline{lua}{gcdext()} shortcuts \mintinline{lua}{Integer.extendedgcd()}. For example:
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ b = 252
+ c,x,y = gcdext(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} = \print{a}(\print{x}) + \print{b}(\print{y}) \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ b = 252
+ c,x,y = gcdext(a,b)
+\end{CAS}
+\[ \gcd(a,b) = \print{c} = \print{a}(\print{x}) + \print{b}(\print{y}) \]
+\end{codebox}
+
+\newcoderef{function Integer.max(a,b)}{return Integer, Integer}{a Integer, b Integer}
+\newcoderef{function Integer.min(a,b)}{return Integer, Integer}{a Integer, b Integer}
+\addcontentsline{toc}{subsubsection}{{\ttfamily Integer.max} and {\ttfamily Integer.min}}
+
+Returns the max/min of \texttt{a,b}; the second output is the min/max (respectively).
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 8
+ b = 7
+ c = Integer.max(a,b)
+\end{CAS}
+\[ \max(\print{a},\print{b}) = \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 8
+ b = 7
+ c = Integer.max(a,b)
+\end{CAS}
+\[ \max(\print{a},\print{b}) = \print{c} \]
+\end{codebox}
+
+
+\newcoderef{function Integer.absmax(a,b)}{return Integer, Integer, number}{a Integer, b Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer.absmax}
+
+Methods for computing the larger magnitude of two integers. Also returns the other integer for sorting purposes, and the number -1 if the two values were swapped, 1 if not.
+
+
+\newcoderef{function Integer.ceillog(a,base)}{return Integer}{a Integer, base Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer.ceillog}
+
+Returns the ceiling of the log base (defaults to 10) of a. In other words, returns the least n such that $\mathtt{(base)^n > a}$.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 101
+ b = 10
+ c = Integer.ceillog(a,b)
+\end{CAS}
+\[ \print{c} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 101
+ b = 10
+ c = Integer.ceillog(a,b)
+\end{CAS}
+\[ \print{c} \]
+\end{codebox}
+
+\newcoderef{function Integer.powmod(a,b,n)}{return Integer}{a Integer,..., n Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer.powmod}
+
+Returns the \texttt{Integer} $c$ such that $c \equiv a^b \bmod{n}$. This should be used when $a^b$ is potentially large.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 12341
+ b = 2^16+1
+ p = 62501
+ c = Integer.powmod(a,b,p)
+\end{CAS}
+\[ \print{c} \equiv \print{a}^{\print{b}} \bmod{\print{p}} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 12341
+ b = 2^16+1
+ p = 62501
+ c = Integer.powmod(a,b,p)
+\end{CAS}
+\[ \print{c} \equiv \print{a}^{\print{b}} \bmod{\print{p}} \]
+\end{codebox}
+
+\newcoderef{function Integer:divremainder(b)}{return Integer, Integer}{b Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer:divremainder}
+
+Returns the quotient and remainder over the integers. Uses the standard base 10 long division algorithm.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ b = 252
+ q,r = Integer.divremainder(a,b)
+\end{CAS}
+\[ \print{a} = \print{b} \cdot \print{q} + \print{r} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ b = 252
+ q,r = Integer.divremainder(a,b)
+\end{CAS}
+\[ \print{a} = \print{b} \cdot \print{q} + \print{r} \]
+\end{codebox}
+
+\coderef{function Integer:asnumber()}{return number}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer:asnumber}
+
+Returns the integer as a floating point number. Can only approximate the value of large integers.
+
+\coderef{function Integer:divisors()}{return table<number, Integer>}
+
+Returns all positive divisors of the integer. Not guaranteed to be in any order.
+
+\begin{codebox}[]
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ d = a:divisors()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ d = a:divisors()
+\end{CAS}
+\[ \left\{ \lprint{d} \right\} \]
+\end{codebox}
+
+\coderef{function Integer:primefactorization()}{return BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer:primefactorization}
+
+Returns the prime factorization of the integer as a \texttt{BinaryOperation}.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 408
+ pf = a:primefactorization()
+\end{CAS}
+\[ \print{pf} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 408
+ pf = a:primefactorization()
+\end{CAS}
+\[ \print{pf} \]
+\end{codebox}
+
+\coderef{function Integer:findafactor()}{return Integer}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer:findafactor}
+
+Return a non-trivial factor of {\ttfamily Integer} via Pollard Rho, or returns {\ttfamily Integer} if {\ttfamily Integer} is prime.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 4199
+ f = a:findafactor()
+\end{CAS}
+\[ \print{f} \mid \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 4199
+ f = a:findafactor()
+\end{CAS}
+\[ \print{f} \mid \print{a} \]
+\end{codebox}
+
+
+\coderef{function Integer:isprime()}{return bool}
+\addcontentsline{toc}{subsubsection}{\ttfamily Integer:isprime}
+
+Uses Miller-Rabin to determine whether {\ttfamily Integer} is prime up to a very large number.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ p = 7038304939
+ if p:isprime() then
+ tex.print(p:tolatex(), "is prime!")
+ end
+\end{CAS}
+\end{minted}
+\tcblower
+\begin{CAS}
+ p = 7038304939
+ if p:isprime() then
+ tex.print(p:tolatex(), "is prime!")
+ end
+\end{CAS}
+\end{codebox}
+
+\coderef{function Rational:reduce()}{return Rational}
+\addcontentsline{toc}{subsubsection}{\ttfamily Rational:reduce}
+
+Reduces a rational expression of integers to standard form. This method is called automatically when a new \texttt{Rational} expression is constructed:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = Rational(8,6)
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = Rational(8,6)
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+
+
+\coderef{function Rational:tocompoundexpression()}{return BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily Rational:tocompoundexpression}
+
+Converts a \texttt{Rational} expression into the corresponding \texttt{BinaryOperation} expression.
+
+\coderef{function Rational:asnumber()}{return number}
+\addcontentsline{toc}{subsubsection}{\ttfamily Rational:asnumber}
+
+Returns the given rational as an approximate floating point number. Going the other way, the parser in \mintinline{latex}{\begin{CAS}..\end{CAS}} will convert decimals (as written) to fractions. For example:
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ a = 0.375
+\end{CAS}
+\[ \print{a} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ a = 0.375
+\end{CAS}
+\[ \print{a} \]
+\end{codebox}
+
+\coderef{function SqrtExpression:topower()}{return BinaryOperation}
+\addcontentsline{toc}{subsubsection}{\ttfamily SqrtExpression:topower}
+
+Converts a \texttt{SqrtExpression} to the appropriate \texttt{BinaryOperation}. For example, consider:
+\begin{minted}{latex}
+\begin{CAS}
+ a = sqrt(3)
+ b = a:topower()
+\end{CAS}
+\end{minted}
+\begin{CAS}
+ a = sqrt(3)
+ b = a:topower()
+\end{CAS}
+Then:
+\begin{multicols}{2}
+ \begin{center}
+ \underline{Expression shrub for \texttt{a}:}
+
+ \parseshrub{a}
+ \bracketset{action character = @}
+ \begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners = 1pt,
+ fill = gray!20,
+ s sep = 1cm}
+ @\shrubresult
+ \end{forest}
+
+ \columnbreak
+
+ \underline{Expression shrub for \texttt{b}:}
+
+ \parseshrub{b}
+ \bracketset{action character = @}
+ \begin{forest}
+ for tree = {font = \ttfamily,
+ draw,
+ rounded corners = 1pt,
+ fill = gray!20,
+ s sep = 1.75cm}
+ @\shrubresult
+ \end{forest}
+ \end{center}
+\end{multicols}
+
+\newcoderef{function Equation:solvefor(var)}{return Equation}{var SymbolExpression}
+\addcontentsline{toc}{subsubsection}{\ttfamily Equation:solvefor}
+
+Attempts to solve the equation for a particular variable.
+
+\begin{codebox}
+ \begin{minted}[fontsize=\small]{latex}
+\begin{CAS}
+ vars("x", "y", "z")
+ lhs = e ^ (x^2 * y)
+ rhs = z + 1
+ eq = Equation(lhs, rhs):autosimplify()
+ eqx = eq:solvefor(x)
+\end{CAS}
+\[ \print{eq} \to \print{eqx} \]
+\end{minted}
+\tcblower
+\begin{CAS}
+ vars("x", "y", "z")
+ lhs = e ^ (x^2 * y)
+ rhs = z + 1
+ eq = Equation(lhs, rhs):autosimplify()
+ eqx = eq:solvefor(x)
+\end{CAS}
+\[ \print{eq} \to \print{eqx} \]
+\end{codebox}
+
+\end{document} \ No newline at end of file