\documentclass[t,usenames,dvipsnames]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, tcolorbox, bm, tikz, pgfplots}
\pgfplotsset{compat = 1.16}

\everymath{\displaystyle}

\title{Radical Equations and Inequalities}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
    \maketitle
\end{frame}

\section{Solve radical equations}

\begin{frame}{Solving Radical Equations}
When solving radical equations, we want to try our best to isolate the radical on one side of the equation (if possible). \newline\\	\pause

Then we can raise both sides to the power that is the root of the radical.    \newline\\	\pause

However, sometimes you may end up with extraneous solutions.
\end{frame}

\begin{frame}{Example 1}
Solve each. Remember to check for extraneous solutions.	\newline\\
(a) \quad $\sqrt{5x+1} = 4$
\begin{align*}
\onslide<2->{\sqrt{5x+1} &= 4} \\[6pt]
\onslide<3->{\left(\sqrt{5x+1}\right)^2 &= 4^2} \\[6pt]
\onslide<4->{5x+1 &= 16} \\[6pt]
\onslide<5->{x &= 3}
\end{align*}
\onslide<6->{Check: $\sqrt{5(3)+1} = 4?$}
\onslide<7->{\quad Yes}
\end{frame}

\begin{frame}{Example 1}
(b) \quad $\sqrt{8-x} + 7 = 10$
\begin{align*}
\onslide<2->{\sqrt{8-x} + 7 &= 10} \\[6pt]
\onslide<3->{\sqrt{8-x} &= 3} \\[6pt]
\onslide<4->{8-x &= 9} \\[6pt]
\onslide<5->{x &= -1}
\end{align*}
\onslide<6->{Check: $\sqrt{8-(-1)} + 7 = 10?$}
\onslide<7->{\quad Yes}
\end{frame}

\begin{frame}{Example 1}
(c) \quad $\sqrt[3]{x-10} = 3$
\begin{align*}
\onslide<2->{\sqrt[3]{x-10} &= 3} \\[6pt]
\onslide<3->{\left(\sqrt[3]{x-10}\right)^3 &= 3^3} \\[6pt]
\onslide<4->{x - 10 &= 27} \\[6pt]
\onslide<5->{x &= 37}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(d) \quad $3\sqrt{x}+12=9$
\begin{align*}
\onslide<2->{3\sqrt{x}+12 &= 9} \\[6pt]
\onslide<3->{3\sqrt{x} &= -3} \\[6pt]
\onslide<4->{\sqrt{x} &= -1} \\[6pt]
\onslide<5->{x &= 1}
\end{align*}
\onslide<6->{Check: $3\sqrt{1}+12=9?$}
\onslide<7->{\quad No}	\newline\\
\onslide<8->{No Solution $\varnothing$}
\end{frame}

\begin{frame}{Example 1}
(e) \quad $\sqrt{2x-7}=\sqrt{3x-12}$
\begin{align*}
\onslide<2->{\sqrt{2x-7} &= \sqrt{3x-12}} \\[6pt]
\onslide<3->{2x - 7 &= 3x - 12} \\[6pt]
\onslide<4->{x &= 5}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(f) \quad $x-3=\sqrt{x-1}$
\begin{align*}
\onslide<2->{x-3 &= \sqrt{x-1}} \\[6pt]
\onslide<3->{(x-3)^2 &= \left(\sqrt{x-1}\right)^2} \\[6pt]
\onslide<4->{x^2-6x+9 &= x-1} \\[6pt]
\onslide<5->{x^2 - 7x + 10 &= 0} \\[6pt]
\onslide<6->{(x-2)(x-5) &= 0} \\[6pt]
\onslide<7->{x &= 2, 5}
\end{align*}
\end{frame}

\begin{frame}{Example 1 \quad $x-3=\sqrt{x-1}$}
\[x = 2 \quad x=5\]
Check:	\newline\\
\onslide<2->{$x=2$ is extraneous} \newline\\
\onslide<3->{$x=5$ is valid} \newline\\
\onslide<4->{Final answer: $x=5$}
\end{frame}

\section{Solve equations with rational exponents}

\begin{frame}{Equations with Rational Exponents}
When dealing with rational exponents, recall that raising a power to a power will result in multiplying the exponents together. \newline\\	\pause

Using this knowledge, we can isolate the radicand by raising both sides of the equation to the \underline{reciprocal} of the exponent.
\end{frame}

\begin{frame}{Example 2}
Solve each of the following. Remember to check for extraneous solutions.	\newline\\
(a) 	\quad $x^{2/3} = 3$
\begin{align*}
\onslide<2->{x^{2/3} &= 3} \\[8pt]
\onslide<3->{\left(x^{2/3}\right)^{3/2} &= 3^{3/2}} \\[8pt]
\onslide<4->{x &= 3^{3/2}} \\[8pt]
\onslide<5->{&= \sqrt{27}} \\[8pt]
\onslide<6->{&= 3\sqrt{3}}
\end{align*}
\end{frame}

\begin{frame}{Example 2}
(b) 	\quad $\left(x-1\right)^{-2/3} = 1$
\begin{align*}
\onslide<2->{\left(x-1\right)^{-2/3} &= 1} \\[8pt]
\onslide<3->{\left(\left(x-1\right)^{-2/3}\right)^{-3/2} &= 1^{-3/2}} \\[8pt]
\onslide<4->{x-1 &= 1} \\[8pt]
\onslide<5->{x &= 2}
\end{align*}
\end{frame}

\begin{frame}{Example 2}
(c) 	\quad $\left(x+2\right)^{3/2} = -1$
\begin{align*}
\onslide<2->{\left(x+2\right)^{3/2} &= -1} \\[8pt]
\onslide<3->{\left(\left(x+2\right)^{3/2}\right)^{2/3} &= (-1)^{2/3}} \\[8pt]
\onslide<4->{x+2 &= 1} \\[8pt]
\onslide<5->{x &= -1}
\end{align*}
\onslide<6->{\[\text{No solution } \varnothing \]}
\end{frame}

\section{Solve radical inequalities}

\begin{frame}{Solving Radical Inequalities}
When solving inequalities, use the same techniques as solving the equations, then use number lines and test values to solve inequalities.  \newline\\	\pause

This gives us the advantage of solving any inequality after learning how to solve its equation form.	\newline\\	\pause

\alert{\textbf{Important: }} Remember, when dealing with \textbf{even roots}, the domain of the radicand is $\geq 0$.
\end{frame}

\begin{frame}{Example 3}
Solve each of the following and graph your solution on a number line.	\newline\\
(a)	\quad	$\sqrt{x-3} - 3 < 4$
\begin{align*}
\onslide<2->{\sqrt{x-3} - 3 &= 4} \\[6pt]
\onslide<3->{\sqrt{x-3} &= 7} \\[6pt]
\onslide<4->{x-3 &= 49} \\[6pt]
\onslide<5->{x &= 52}
\end{align*}
\end{frame}

\begin{frame}{Example 3	\quad	$\sqrt{x-3} - 3 < 4$}
Critical value of $x$ is 52.	\newline\\
\onslide<2->{For $\sqrt{x-3}$, $x-3$ must be $\geq 0$, so $x \geq 3$}	\newline\\
\onslide<3->{
\begin{center}
\begin{tikzpicture}
\draw [<->] (-2,0) -- (2,0);
\draw (1,0.15) -- (1,-0.15) node [below] {$52$};
\draw (-1,0.15) -- (-1,-0.15) node [below] {$3$};
\onslide<4->{\draw[color=blue,fill=white] (1,0) circle [radius=2.5pt];
\draw[fill=blue,color=blue] (-1,0) circle [radius=2.5pt];}
\onslide<5->{\draw[color=blue, ultra thick, shorten >= 2.5pt, shorten >= 2.5pt] (-1,0) -- (1,0);}
\end{tikzpicture}
\end{center}
}
\onslide<6->{\[3 \leq x < 52\]}
\end{frame}

\begin{frame}{Example 3}
(b)	\quad	$\sqrt[3]{2x+3} \geq \sqrt[3]{x+12}$
\begin{align*}
\onslide<2->{\sqrt[3]{2x+3} &= \sqrt[3]{x+12}} \\[6pt]
\onslide<3->{2x+3 &= x+12} \\[6pt]
\onslide<4->{x &= 9}
\end{align*}
\onslide<5->{
\begin{center}
\begin{tikzpicture}
\draw [<->] (-2,0) -- (2,0);
\draw (0,0.15) -- (0,-0.15) node [below] {$9$};
\onslide<6->{\draw[color=blue,fill=blue] (0,0) circle [radius=2.5pt];}
\onslide<7->{\draw[color=blue,ultra thick, ->] (0,0) -- (2,0);}
\end{tikzpicture}
\end{center}
}
\onslide<8->{\[x \geq 9 \]}
\end{frame}

\begin{frame}{Example 3}
(c)	\quad	$\sqrt{2x-1} \leq 2x-1$
\begin{align*}
\onslide<2->{\sqrt{2x-1} &= 2x-1} \\[6pt]
\onslide<3->{\left(\sqrt{2x-1}\right)^2 &= (2x-1)^2} \\[6pt]
\onslide<4->{2x-1 &= 4x^2 - 4x + 1} \\[6pt]
\onslide<5->{4x^2 - 6x + 2 &= 0} \\[6pt]
\onslide<6->{x &= \frac{1}{2}, \quad 1}
\end{align*}
\end{frame}

\begin{frame}{Example 3 \quad $\sqrt{2x-1} \leq 2x-1$}
\begin{center}
\begin{tikzpicture}
\draw[<->] (-2.5,0) -- (2.5,0);
\draw (-1,0.15) -- (-1,-0.15) node [below] {$\frac{1}{2}$};
\draw (1,0.15) -- (1,-0.15) node [below] {$1$};
\onslide<2->{\draw[color=blue,fill=blue] (-1,0) circle [radius=2.5pt];
					\draw[color=blue,fill=blue] (1,0) circle [radius=2.5pt];
}
\onslide<3->{\draw[color=blue, ultra thick, ->] (1,0) -- (2.5,0);}
\end{tikzpicture}
\end{center}
\onslide<4->{\[x = \frac{1}{2} \quad \text{or} \quad x \geq 1\]}
\end{frame}

\end{document}


\vssub
\subsection{~Simple ice blocking ({\code IC0})} \label{sub:num_ice}
\opthead{IC0}{\ws}{H. L. Tolman} %\conthead{\ws}{H. L. Tolman}

\noindent
Ice covered sea is considered as `land' in \ws, assuming zero wave energy and
boundary conditions at ice edges are identical to boundary conditions at shore
lines. Grid points are taken out of the calculation if the ice concentration
becomes larger than a user-defined concentration. If the ice concentration
drops below its critical value, the corresponding grid point is
`re-activated'. The spectrum is then initialized with a PM spectrum based on
the local wind direction with a peak frequency corresponding to the
second-highest discrete frequency in the grid. A low energy spectrum is used to
assure that spectra are realistic, even for shallow coastal points.

The above discontinuous ice treatment represents the default model setting in
\ws. In the framework of the modeling of unresolved obstacles as discussed in
\para\ref{sub:num_obst}, a continuous method is also available, as given by
\cite{tol:OMOD03a}. In this method, a user-defined critical ice concentration
at which obstruction begins ($\epsilon_{c,0}$) and is complete
($\epsilon_{c,n}$) are given (defaults are $\epsilon_{c,0} = \epsilon_{c,n} =
0.5$, i.e., discontinuous treatment of ice). From these critical
concentrations, corresponding decay length scales are calculated as

\begin{equation}
l_0 = \epsilon_{c,0} \min ( \Delta x , \Delta y )
, \label{eq:l0}
\end{equation}
\begin{equation}
l_n = \epsilon_{c,n} \min ( \Delta x , \Delta y )
, \label{eq:ln}
\end{equation}

\noindent
from which cell transmissions in $x$ and $y$ ($\alpha_x$ and $\alpha_y$,
respectively) are calculated as

\begin{equation}
\alpha_x = \left \{ \begin{array}{ccl}
 1 & \mbox{for} & \epsilon \Delta x < l_0 \\
 0 & \mbox{for} & \epsilon \Delta x > l_n \\
\frac{l_n - \epsilon \Delta x}{l_n - l_0} & \multicolumn{2}{c}{\mbox{otherwise}}
\end{array} \right .
\:\:\: , \:\:\:
\alpha_y = \left \{ \begin{array}{ccl}
 1 & \mbox{for} & \epsilon \Delta y < l_0 \\
 0 & \mbox{for} & \epsilon \Delta y > l_n \\
\frac{l_n - \epsilon \Delta y}{l_n - l_0} & \multicolumn{2}{c}{\mbox{otherwise}}
\end{array} \right .
\:\:\: . \label{eq:ice_0}
\end{equation}

\noindent
Details of this model can be found in \cite{tol:OMOD03a}.

Updating of the ice map within the model takes place at the discrete model
time approximately half way in between the valid times of the old and new ice
maps. The map will not be updated, if the time stamps of both ice fields are
identical.

The above description pertains to the switch {\code IC0}. Note that either ice transmissions for propagation ({\code IC0}), or ice as a source term can be used ({\code IC1}, {\code IC2}, {\code IC3}), but not both approaches at the same time.


% -*- mode:Noweb; noweb-code-mode: sml-mode -*-% ===> this file was generated automatically by noweave --- better not edit it
\documentclass{article}
\usepackage{graphicx}
\usepackage{noweb}
\usepackage{hyperref}
\date{}
\author{}

\title{COL765 - Assignment 2}
\author{Nilaksh Agarwal \\
                2015PH10813}
\date{}
\begin{document}
\maketitle
\section{Introduction}
The purpose of this assignment was to develop a module to regenerate a Tree, given it's in-order traversal. I have used the document \href{http://www.cse.iitd.ernet.in/~sak/courses/ilfp/recover.pdf}{Rambling Through Woods on a Sunny Morning} for reference and also used the Binary Tree signature and structure given in the same.

\section{The complications with inorder traversal}

Unlike preorder or postorder traversals, inorder traversals have no structural information in them. For example, in a preorder traversal, all values occurring to the right of a given node, are the descendants of that node. Similarly, to the left for postorder traversals. \\

In an inorder traversal however, there is no such structural information available, and moreover, there is some noise added to this as well. \\

This is clearly visualized with the 3 following trees, which all have the same inorder traversal: \\[0.5cm]
\begin{center}
        \includegraphics[width=14cm]{Inorder_wrong.jpg}
\end{center}

\section{The Binary Tree Signature}

Here we define a basic datatype for bintree:

\nwfilename{2015PH10813.nw}\nwbegincode{1}\sublabel{NW6NVqj-4XyAA2-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-4XyAA2-1}}}\moddef{Node~{\nwtagstyle{}\subpageref{NW6NVqj-4XyAA2-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-4WBYwn-1}\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
        datatype 'a bintree =
                Empty
                | Node of 'a * 'a bintree * 'a bintree
\nwused{\\{NW6NVqj-4WBYwn-1}\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{2}\nwdocspar

We also define a option datatype, since we intend to store the empty Leaf nodes as well

\nwenddocs{}\nwbegincode{3}\sublabel{NW6NVqj-4JPyOG-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-4JPyOG-1}}}\moddef{Option~{\nwtagstyle{}\subpageref{NW6NVqj-4JPyOG-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-4WBYwn-1}\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
        datatype 'a option = NONE | SOME of 'a
\nwused{\\{NW6NVqj-4WBYwn-1}\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{4}\nwdocspar

We define our regular preorder \& postorder functions like in the \href{http://www.cse.iitd.ernet.in/~sak/courses/ilfp/recover.pdf}{document}. Here \textbf{'a option list} implies a list which can contain \textbf{NONE} in case of Empty subtree or \textbf{SOME of value}

\nwenddocs{}\nwbegincode{5}\sublabel{NW6NVqj-azPlp-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-azPlp-1}}}\moddef{PrePostSig~{\nwtagstyle{}\subpageref{NW6NVqj-azPlp-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-4WBYwn-1}}\nwenddeflinemarkup
        val preorder : 'a bintree ->  'a option list
        val postorder : 'a bintree -> 'a option list
\nwused{\\{NW6NVqj-4WBYwn-1}}\nwendcode{}\nwbegindocs{6}\nwdocspar

However, for inorder, this is not enough. We need some addition \textit{Cosmetic Sugar} to gain the missing structural information in this traversal. Hence, we include the depth of a node defined to be 0 for the root node, and the depth of any child is 1 + the depth of their parent. \\
So, our node now contains a Tuple (value, depth) which is returned from the inorder traversal. Now we can define the signatures of the inorder and inorderInverse

\nwenddocs{}\nwbegincode{7}\sublabel{NW6NVqj-2NTUdd-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2NTUdd-1}}}\moddef{InSig~{\nwtagstyle{}\subpageref{NW6NVqj-2NTUdd-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-4WBYwn-1}}\nwenddeflinemarkup
        val inorder : 'a bintree -> ('a option * int) list
        val inorderInverse : ('a option * int) list -> 'a bintree
\nwused{\\{NW6NVqj-4WBYwn-1}}\nwendcode{}\nwbegindocs{8}\nwdocspar

One last function we use to check if two given trees are equal. For this, we find their preorder and postorder traversals, and check their equality.
\nwenddocs{}\nwbegincode{9}\sublabel{NW6NVqj-3QvoFw-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-3QvoFw-1}}}\moddef{equalSig~{\nwtagstyle{}\subpageref{NW6NVqj-3QvoFw-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-4WBYwn-1}}\nwenddeflinemarkup
        val checkTrees : ''a bintree * ''a bintree -> bool
\nwused{\\{NW6NVqj-4WBYwn-1}}\nwendcode{}\nwbegindocs{10}\nwdocspar

Now we can put everything together in our Signature

\nwenddocs{}\nwbegincode{11}\sublabel{NW6NVqj-4WBYwn-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-4WBYwn-1}}}\moddef{bintreeSignature-complete~{\nwtagstyle{}\subpageref{NW6NVqj-4WBYwn-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
signature BINTREE =
sig
\LA{}Node~{\nwtagstyle{}\subpageref{NW6NVqj-4XyAA2-1}}\RA{}
\LA{}Option~{\nwtagstyle{}\subpageref{NW6NVqj-4JPyOG-1}}\RA{}
        exception Empty_bintree;
        exception InvalidTraversal;
\LA{}PrePostSig~{\nwtagstyle{}\subpageref{NW6NVqj-azPlp-1}}\RA{}
\LA{}InSig~{\nwtagstyle{}\subpageref{NW6NVqj-2NTUdd-1}}\RA{}
\LA{}equalSig~{\nwtagstyle{}\subpageref{NW6NVqj-3QvoFw-1}}\RA{}
end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{12}\nwdocspar

\section{The Binary Tree Structure}

Similarly to the \href{http://www.cse.iitd.ernet.in/~sak/courses/ilfp/recover.pdf}{document} we define the preorder \& postorder functions using the tail recursive forms. \\

We use \textbf{NONE} to indicate empty nodes and \textbf{SOME of val}
to indicate nodes with value \textbf{val}
\nwenddocs{}\nwbegincode{13}\sublabel{NW6NVqj-FYIyT-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-FYIyT-1}}}\moddef{preorder~{\nwtagstyle{}\subpageref{NW6NVqj-FYIyT-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
    local
        fun pre(Empty, Llist) = NONE::Llist
                | pre(Node(N,Ltree, Rtree),Llist) =
                let
                        val Mlist = pre(Rtree,Llist)
                        val Nlist = pre(Ltree,Mlist)
                in
                        SOME N :: Nlist
                end
        in
                fun preorder T = pre(T,[])
        end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{14}\nwdocspar

\nwenddocs{}\nwbegincode{15}\sublabel{NW6NVqj-2drSLa-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2drSLa-1}}}\moddef{postorder~{\nwtagstyle{}\subpageref{NW6NVqj-2drSLa-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
    local
        fun post(Empty, Llist) = NONE::Llist
                | post(Node(N,Ltree, Rtree),Llist) =
                let
                        val Mlist = post(Rtree,SOME N::Llist)
                        val Nlist = post(Ltree,Mlist)
                in
                        Nlist
                end
        in
                fun postorder T = post(T,[])
        end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{16}\nwdocspar

In inorder however, we need to store the depth of the node as well, since we are unable to figure out any strucural information from the traversal

\nwenddocs{}\nwbegincode{17}\sublabel{NW6NVqj-N7IVZ-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-N7IVZ-1}}}\moddef{inorder~{\nwtagstyle{}\subpageref{NW6NVqj-N7IVZ-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
        local
        fun ino(Empty, Llist,i) = (NONE,i)::Llist
                | ino(Node(N,Ltree, Rtree),Llist,i) =
                let
                        val Mlist = ino(Rtree,Llist,i+1)
                        val Nlist = ino(Ltree,(SOME N,i)::Mlist,i+1)
                in
                        Nlist
                end
        in
                fun inorder T = ino(T,[],0)
        end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{18}\nwdocspar

Here we store (value,depth) as a tuple in the node. \\

\subsection{The Inorder Inverse}

Before we start the inorder inverse function, we define some facts about our updated inorder Traversal (with heights)

\textit{\begin{enumerate}
    \item In any inorder traversal ($\bot$,\_) is the first and last element
    \item If any inorder traversal has more than 1 element, the tree is non-empty
    \item The descendants of a node always have a depth greater than the depth of the node. (\textbf{m},h1) \& (\textbf{n},h2) : n is a descendant of m if (h2 \textgreater h1)
    \item Any node m that has a height greater than a node l = (v,h) is either a descendant of l or a descendant of a sibling of l
    \item Any slice of the form [(\textbf{$\bot$},h+1), (\textbf{v},h), ($\neq \bot \neq$,h+1)] determines a unique leaf node in the tree with height h.
    \item Any slice of the form [(\textbf{$\bot$},h+2), (\textbf{m},h+1), (\textbf{$\bot$}, h+2), (\textbf{l},h), (\textbf{$\bot$},h+1)] where m $\neq \bot \neq$ l are values of the nodes, determines a unique subtree rooted at l whose left child is the leaf node m and the right child is empty
    \item Any slice of the form [(\textbf{$\bot$},h+1), (\textbf{l},h), (\textbf{$\bot$}, h+2), (\textbf{m},h+1), (\textbf{$\bot$},h+2)] where m $\neq \bot \neq$ l   are values of the nodes, determines a unique subtree rooted at l whose right
    child is the leaf node m and the left child is empty.
    \item Any slice of the form [(\textbf{T1},h+1), (\textbf{v},h), (\textbf{T2},h+1)] where T1  $\neq \bot \neq$ T2 are subtrees/leaf nodes determines a subtree rooted at v with T1 and T2 as it's left and right children
\end{enumerate}}

\textbf{Uniqueness of Inorder Traversal}: No two distinct binary trees can yield the same inorder traversal.
\textit{Proof:} The proof follows from the definition of inorder traversal and the previous facts (especially the if and only if
conditions) Further the statements yield an inductive proof along with a case analysis of the inductive step \\

Now we define some helper functions to create this inorder inverse. The first function converts a inorder traversal into a list of Bintree nodes.

\nwenddocs{}\nwbegincode{19}\sublabel{NW6NVqj-3s4e0t-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-3s4e0t-1}}}\moddef{Nodify~{\nwtagstyle{}\subpageref{NW6NVqj-3s4e0t-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-D88LJ-1}}\nwenddeflinemarkup
    fun  Nodify[] = []
                | Nodify (h::t) =
                Node(h,Empty,Empty)::Nodify(t)
\nwused{\\{NW6NVqj-D88LJ-1}}\nwendcode{}\nwbegindocs{20}\nwdocspar

The next function joins 3 nodes into a single node if the height of the middle node is one less than the other two.

\nwenddocs{}\nwbegincode{21}\sublabel{NW6NVqj-4eyur2-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-4eyur2-1}}}\moddef{joinNodes~{\nwtagstyle{}\subpageref{NW6NVqj-4eyur2-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-D88LJ-1}}\nwenddeflinemarkup
                fun joinNodes(T1 as Node((v1,h1),_,_), T2 as Node((v2,h2),_,_), T3 as Node((v3,h3),_,_)) =
                if(h1=h3 andalso (h1-1)=h2) then
                        [Node((v2,h2),T1,T3)]
                else
                        [T1,T2,T3]
                | joinNodes(T1,T2,T3) = raise InvalidTraversal
\nwused{\\{NW6NVqj-D88LJ-1}}\nwendcode{}\nwbegindocs{22}\nwdocspar

The next function goes over a list of notes and tries combining all the successive nodes triplets

\nwenddocs{}\nwbegincode{23}\sublabel{NW6NVqj-2W3UBo-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2W3UBo-1}}}\moddef{CombineIter~{\nwtagstyle{}\subpageref{NW6NVqj-2W3UBo-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-D88LJ-1}}\nwenddeflinemarkup
        fun combineIter(h1::h2::h3::[]) =
                        joinNodes(h1,h2,h3)
                | combineIter(L as h1::h2::h3::tl) =
                let
                        val M = joinNodes(h1,h2,h3) @ tl
                in
                        List.hd(M) :: combineIter(List.tl(M))
                end
                | combineIter (L as h1::h2::[]) = L
                | combineIter L = raise InvalidTraversal
\nwused{\\{NW6NVqj-D88LJ-1}}\nwendcode{}\nwbegindocs{24}\nwdocspar

Now, a function keeps calling the iterative joining function until only one node remains

\nwenddocs{}\nwbegincode{25}\sublabel{NW6NVqj-3BQdfV-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-3BQdfV-1}}}\moddef{Combine~{\nwtagstyle{}\subpageref{NW6NVqj-3BQdfV-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-D88LJ-1}}\nwenddeflinemarkup
                fun combine(hd::[]) = hd
                | combine L =
                let
                        val M = combineIter L
                in
                        combine M
                end
\nwused{\\{NW6NVqj-D88LJ-1}}\nwendcode{}\nwbegindocs{26}\nwdocspar

This tree created has Complete nodes even for Empty Leaf nodes. We need to clean this up and remove the extra Empty Nodes

\nwenddocs{}\nwbegincode{27}\sublabel{NW6NVqj-8c9SM-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-8c9SM-1}}}\moddef{treeClean~{\nwtagstyle{}\subpageref{NW6NVqj-8c9SM-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-D88LJ-1}}\nwenddeflinemarkup
                fun treeClean(Node((SOME v,_),Ltree,Rtree)) =
                let
                        val LClean = treeClean(Ltree)
                        val RClean = treeClean(Rtree)
                in
                        Node(v, LClean, RClean)
                end
                | treeClean(T) = Empty
\nwused{\\{NW6NVqj-D88LJ-1}}\nwendcode{}\nwbegindocs{28}\nwdocspar

Now we can put it all together in our inorderInverse

\nwenddocs{}\nwbegincode{29}\sublabel{NW6NVqj-D88LJ-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-D88LJ-1}}}\moddef{inorderInverse~{\nwtagstyle{}\subpageref{NW6NVqj-D88LJ-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
    local
        \LA{}Nodify~{\nwtagstyle{}\subpageref{NW6NVqj-3s4e0t-1}}\RA{}
        \LA{}joinNodes~{\nwtagstyle{}\subpageref{NW6NVqj-4eyur2-1}}\RA{}
        \LA{}CombineIter~{\nwtagstyle{}\subpageref{NW6NVqj-2W3UBo-1}}\RA{}
        \LA{}Combine~{\nwtagstyle{}\subpageref{NW6NVqj-3BQdfV-1}}\RA{}
        \LA{}treeClean~{\nwtagstyle{}\subpageref{NW6NVqj-8c9SM-1}}\RA{}
    in
        fun inorderInverse(L) =
                        treeClean (combine (Nodify L))

        end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{30}\nwdocspar

Having gotten a tree back from an inorder inverse, we would like to define a function to check if the tree is the same as our original tree. We can do the same by comparing their preorder \& postorder traversal. (Since in the \href{http://www.cse.iitd.ernet.in/~sak/courses/ilfp/recover.pdf}{document} the uniqueness of preorder/postorder traversals has been proved. For this we need to check if two lists generated by the traversals are the same

\nwenddocs{}\nwbegincode{31}\sublabel{NW6NVqj-2cpULM-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2cpULM-1}}}\moddef{checkList~{\nwtagstyle{}\subpageref{NW6NVqj-2cpULM-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-1Uzkdr-1}}\nwenddeflinemarkup
    fun checkList([],[]) = true
                | checkList([],_) = false
                | checkList(_,[]) = false
                | checkList(NONE::t1, NONE::t2) = checkList(t1,t2)
                | checkList(SOME h1::t1, SOME h2::t2) =
                if(h1=h2) then
                        checkList(t1,t2)
                else
                        false
                | checkList(_,_) = false
\nwused{\\{NW6NVqj-1Uzkdr-1}}\nwendcode{}\nwbegindocs{32}\nwdocspar

\nwenddocs{}\nwbegincode{33}\sublabel{NW6NVqj-1Uzkdr-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-1Uzkdr-1}}}\moddef{checkTrees~{\nwtagstyle{}\subpageref{NW6NVqj-1Uzkdr-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-2nTQtw-1}}\nwenddeflinemarkup
    local
                \LA{}checkList~{\nwtagstyle{}\subpageref{NW6NVqj-2cpULM-1}}\RA{}
        in
                fun checkTrees(T1,T2) =
                let
                        val pre1 = preorder(T1)
                        val pre2 = preorder(T2)
                        val pos1 = postorder(T1)
                        val pos2 = postorder(T2)
                in
                        if(checkList(pre1,pre2) andalso checkList(pos1,pos2)) then
                                true
                        else
                                false
                end
        end
\nwused{\\{NW6NVqj-2nTQtw-1}}\nwendcode{}\nwbegindocs{34}\nwdocspar

Now we put it all together into our Bintree structure

\nwenddocs{}\nwbegincode{35}\sublabel{NW6NVqj-2nTQtw-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2nTQtw-1}}}\moddef{bintreeStructure-complete~{\nwtagstyle{}\subpageref{NW6NVqj-2nTQtw-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
\LA{}bintreeSignature-complete~{\nwtagstyle{}\subpageref{NW6NVqj-4WBYwn-1}}\RA{}
structure Bintree : BINTREE =
struct
    \LA{}Node~{\nwtagstyle{}\subpageref{NW6NVqj-4XyAA2-1}}\RA{}
    \LA{}Option~{\nwtagstyle{}\subpageref{NW6NVqj-4JPyOG-1}}\RA{}

    exception Empty_bintree
        exception InvalidTraversal

        \LA{}preorder~{\nwtagstyle{}\subpageref{NW6NVqj-FYIyT-1}}\RA{}
        \LA{}postorder~{\nwtagstyle{}\subpageref{NW6NVqj-2drSLa-1}}\RA{}
        \LA{}inorder~{\nwtagstyle{}\subpageref{NW6NVqj-N7IVZ-1}}\RA{}
    \LA{}inorderInverse~{\nwtagstyle{}\subpageref{NW6NVqj-D88LJ-1}}\RA{}
    \LA{}checkTrees~{\nwtagstyle{}\subpageref{NW6NVqj-1Uzkdr-1}}\RA{}
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{36}\nwdocspar

\section{Test Cases}

We define the following test cases to check the performance of our inorderInverse

\begin{center}
        \includegraphics[width=14cm]{Test1.jpg}
        \\
        \includegraphics[width=14cm]{Test2.jpg}
\end{center}
\nwenddocs{}\nwbegincode{37}\sublabel{NW6NVqj-2obuBU-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2obuBU-1}}}\moddef{test1~{\nwtagstyle{}\subpageref{NW6NVqj-2obuBU-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t7 = Node (7, Empty, Empty);
        val t6 = Node (6, t7, Empty);
        val t5 = Node (5, Empty, Empty);
        val t4 = Node (4, Empty, Empty);
        val t3 = Node (3, t5, t6);
        val t2 = Node (2, Empty, t4);
in
        val test1 = Node (1, t2, t3);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{38}\nwdocspar
\nwenddocs{}\nwbegincode{39}\sublabel{NW6NVqj-PItlY-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-PItlY-1}}}\moddef{test2~{\nwtagstyle{}\subpageref{NW6NVqj-PItlY-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t15 = Node (15, Empty, Empty);
        val t14 = Node (14, Empty, Empty);
        val t13 = Node (13, Empty, Empty);
        val t12 = Node (12, Empty, Empty);
        val t11 = Node (11, Empty, Empty);
        val t10 = Node (10, Empty, Empty);
        val t9 = Node (9, Empty, Empty);
        val t8 = Node (8, Empty, Empty);
        val t7 = Node(7, t14, t15);
        val t6 = Node (6, t12, t13);
        val t5 = Node (5, t10, t11);
        val t4 = Node (4, t8, t9);
        val t3 = Node (3, t6, t7);
        val t2 = Node (2, t4, t5);
in
        val test2 = Node (1, t2, t3);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{40}\nwdocspar
\nwenddocs{}\nwbegincode{41}\sublabel{NW6NVqj-4A3yQS-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-4A3yQS-1}}}\moddef{test3~{\nwtagstyle{}\subpageref{NW6NVqj-4A3yQS-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t11 = Node (11, Empty, Empty);
        val t10 = Node (10, Empty, Empty);
        val t9 = Node (9, Empty, Empty);
        val t8 = Node (8, Empty, Empty);
        val t5 = Node (5, t10, t11);
        val t4 = Node (4, t8, t9);
        val t2 = Node (2, t4, t5);
in
        val test3 = Node (1, t2, Empty);
end

\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegincode{42}\sublabel{NW6NVqj-1UZpaq-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-1UZpaq-1}}}\moddef{test4~{\nwtagstyle{}\subpageref{NW6NVqj-1UZpaq-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t15 = Node (15, Empty, Empty);
        val t14 = Node (14, Empty, Empty);
        val t13 = Node (13, Empty, Empty);
        val t12 = Node (12, Empty, Empty);
        val t7 = Node(7, t14, t15);
        val t6 = Node (6, t12, t13);
        val t3 = Node (3, t6, t7);
in
        val test4 = Node (1, Empty, t3);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{43}\nwdocspar
\nwenddocs{}\nwbegincode{44}\sublabel{NW6NVqj-30oemG-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-30oemG-1}}}\moddef{test5~{\nwtagstyle{}\subpageref{NW6NVqj-30oemG-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t4 = Node (4, Empty, Empty);
        val t3 = Node (3, t4, Empty);
        val t2 = Node (2, t3, Empty);
in
        val test5 = Node (1, t2, Empty);
end

\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegincode{45}\sublabel{NW6NVqj-mrbYu-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-mrbYu-1}}}\moddef{test6~{\nwtagstyle{}\subpageref{NW6NVqj-mrbYu-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t4 = Node (4, Empty, Empty);
        val t3 = Node (3, Empty, t4);
        val t2 = Node (2, Empty, t3);
in
        val test6 = Node (1, Empty, t2);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{46}\nwdocspar
\nwenddocs{}\nwbegincode{47}\sublabel{NW6NVqj-446Oh6-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-446Oh6-1}}}\moddef{test7~{\nwtagstyle{}\subpageref{NW6NVqj-446Oh6-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t7 = Node (7, Empty, Empty);
        val t6 = Node (6, Empty, Empty);
        val t5 = Node (5, Empty, t7);
        val t4 = Node (4, t6, Empty);
        val t3 = Node (3, Empty, t5);
        val t2 = Node (2, t4, Empty);
in
        val test7 = Node (1, t2, t3);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{48}\nwdocspar
\nwenddocs{}\nwbegincode{49}\sublabel{NW6NVqj-25u5CK-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-25u5CK-1}}}\moddef{test8~{\nwtagstyle{}\subpageref{NW6NVqj-25u5CK-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
local
        val t7 = Node (7, Empty, Empty);
        val t6 = Node (6, Empty, Empty);
        val t5 = Node (5, Empty, t7);
        val t4 = Node (4, t6, Empty);
        val t3 = Node (3, t5, Empty);
        val t2 = Node (2, Empty, t4);
in
        val test8 = Node (1, t2, t3);
end
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{50}\nwdocspar

After this, to check if our inorderInverse works for each test case, we simply checkTrees between the inorderInverse generated tree and the original tree

\nwenddocs{}\nwbegincode{51}\sublabel{NW6NVqj-2UuN4Q-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-2UuN4Q-1}}}\moddef{testCheck~{\nwtagstyle{}\subpageref{NW6NVqj-2UuN4Q-1}}}\endmoddef\nwstartdeflinemarkup\nwusesondefline{\\{NW6NVqj-stHGb-1}}\nwenddeflinemarkup
val test1_check = checkTrees(inorderInverse(inorder(test1)),test1);
val test2_check = checkTrees(inorderInverse(inorder(test2)),test2);
val test3_check = checkTrees(inorderInverse(inorder(test3)),test3);
val test4_check = checkTrees(inorderInverse(inorder(test4)),test4);
val test5_check = checkTrees(inorderInverse(inorder(test5)),test5);
val test6_check = checkTrees(inorderInverse(inorder(test6)),test6);
val test7_check = checkTrees(inorderInverse(inorder(test7)),test7);
val test8_check = checkTrees(inorderInverse(inorder(test8)),test8);
\nwused{\\{NW6NVqj-stHGb-1}}\nwendcode{}\nwbegindocs{52}\nwdocspar

\nwenddocs{}\nwbegincode{53}\sublabel{NW6NVqj-stHGb-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW6NVqj-stHGb-1}}}\moddef{testCase-complete~{\nwtagstyle{}\subpageref{NW6NVqj-stHGb-1}}}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
\LA{}bintreeStructure-complete~{\nwtagstyle{}\subpageref{NW6NVqj-2nTQtw-1}}\RA{}
open Bintree;

\LA{}test1~{\nwtagstyle{}\subpageref{NW6NVqj-2obuBU-1}}\RA{}
\LA{}test2~{\nwtagstyle{}\subpageref{NW6NVqj-PItlY-1}}\RA{}
\LA{}test3~{\nwtagstyle{}\subpageref{NW6NVqj-4A3yQS-1}}\RA{}
\LA{}test4~{\nwtagstyle{}\subpageref{NW6NVqj-1UZpaq-1}}\RA{}
\LA{}test5~{\nwtagstyle{}\subpageref{NW6NVqj-30oemG-1}}\RA{}
\LA{}test6~{\nwtagstyle{}\subpageref{NW6NVqj-mrbYu-1}}\RA{}
\LA{}test7~{\nwtagstyle{}\subpageref{NW6NVqj-446Oh6-1}}\RA{}
\LA{}test8~{\nwtagstyle{}\subpageref{NW6NVqj-25u5CK-1}}\RA{}
\LA{}testCheck~{\nwtagstyle{}\subpageref{NW6NVqj-2UuN4Q-1}}\RA{}
\nwnotused{testCase-complete}\nwendcode{}

\nwixlogsorted{c}{{bintreeSignature-complete}{NW6NVqj-4WBYwn-1}{\nwixd{NW6NVqj-4WBYwn-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{bintreeStructure-complete}{NW6NVqj-2nTQtw-1}{\nwixd{NW6NVqj-2nTQtw-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{checkList}{NW6NVqj-2cpULM-1}{\nwixd{NW6NVqj-2cpULM-1}\nwixu{NW6NVqj-1Uzkdr-1}}}%
\nwixlogsorted{c}{{checkTrees}{NW6NVqj-1Uzkdr-1}{\nwixd{NW6NVqj-1Uzkdr-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{Combine}{NW6NVqj-3BQdfV-1}{\nwixd{NW6NVqj-3BQdfV-1}\nwixu{NW6NVqj-D88LJ-1}}}%
\nwixlogsorted{c}{{CombineIter}{NW6NVqj-2W3UBo-1}{\nwixd{NW6NVqj-2W3UBo-1}\nwixu{NW6NVqj-D88LJ-1}}}%
\nwixlogsorted{c}{{equalSig}{NW6NVqj-3QvoFw-1}{\nwixd{NW6NVqj-3QvoFw-1}\nwixu{NW6NVqj-4WBYwn-1}}}%
\nwixlogsorted{c}{{inorder}{NW6NVqj-N7IVZ-1}{\nwixd{NW6NVqj-N7IVZ-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{inorderInverse}{NW6NVqj-D88LJ-1}{\nwixd{NW6NVqj-D88LJ-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{InSig}{NW6NVqj-2NTUdd-1}{\nwixd{NW6NVqj-2NTUdd-1}\nwixu{NW6NVqj-4WBYwn-1}}}%
\nwixlogsorted{c}{{joinNodes}{NW6NVqj-4eyur2-1}{\nwixd{NW6NVqj-4eyur2-1}\nwixu{NW6NVqj-D88LJ-1}}}%
\nwixlogsorted{c}{{Node}{NW6NVqj-4XyAA2-1}{\nwixd{NW6NVqj-4XyAA2-1}\nwixu{NW6NVqj-4WBYwn-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{Nodify}{NW6NVqj-3s4e0t-1}{\nwixd{NW6NVqj-3s4e0t-1}\nwixu{NW6NVqj-D88LJ-1}}}%
\nwixlogsorted{c}{{Option}{NW6NVqj-4JPyOG-1}{\nwixd{NW6NVqj-4JPyOG-1}\nwixu{NW6NVqj-4WBYwn-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{postorder}{NW6NVqj-2drSLa-1}{\nwixd{NW6NVqj-2drSLa-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{preorder}{NW6NVqj-FYIyT-1}{\nwixd{NW6NVqj-FYIyT-1}\nwixu{NW6NVqj-2nTQtw-1}}}%
\nwixlogsorted{c}{{PrePostSig}{NW6NVqj-azPlp-1}{\nwixd{NW6NVqj-azPlp-1}\nwixu{NW6NVqj-4WBYwn-1}}}%
\nwixlogsorted{c}{{test1}{NW6NVqj-2obuBU-1}{\nwixd{NW6NVqj-2obuBU-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test2}{NW6NVqj-PItlY-1}{\nwixd{NW6NVqj-PItlY-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test3}{NW6NVqj-4A3yQS-1}{\nwixd{NW6NVqj-4A3yQS-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test4}{NW6NVqj-1UZpaq-1}{\nwixd{NW6NVqj-1UZpaq-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test5}{NW6NVqj-30oemG-1}{\nwixd{NW6NVqj-30oemG-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test6}{NW6NVqj-mrbYu-1}{\nwixd{NW6NVqj-mrbYu-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test7}{NW6NVqj-446Oh6-1}{\nwixd{NW6NVqj-446Oh6-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{test8}{NW6NVqj-25u5CK-1}{\nwixd{NW6NVqj-25u5CK-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{testCase-complete}{NW6NVqj-stHGb-1}{\nwixd{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{testCheck}{NW6NVqj-2UuN4Q-1}{\nwixd{NW6NVqj-2UuN4Q-1}\nwixu{NW6NVqj-stHGb-1}}}%
\nwixlogsorted{c}{{treeClean}{NW6NVqj-8c9SM-1}{\nwixd{NW6NVqj-8c9SM-1}\nwixu{NW6NVqj-D88LJ-1}}}%
\nwbegindocs{54}\nwdocspar

The reason to choose these particular test cases since it covers some particular ambiguous cases such as a fully dense tree (Test2), a highly skewed tree (Test5 and Test6) as well as a initially skewed and then dense tree (Test3 and Test4) or a highly hollow tree (Test7) as well as a tree containing alternative oriented children (Test8)

The checkTrees function checks the inorderInverse generated tree vs the original tree. For all these testcases, the output is true.

\end{document}
\nwenddocs{}


\setcounter{table}{0}
\setcounter{figure}{0}
\renewcommand{\thetable}{\mbox{E.\arabic{table}}}%
\renewcommand{\thefigure}{\mbox{E--\arabic{figure}}}%

\chapter{Operator Precedence Hierarchy}

\markboth{{\color{cyan}APPENDIX\,E\,\,$\bullet$\,\,}Operator Precedence Hierarchy}
{{\color{cyan}APPENDIX\,E\,\,$\bullet$\,\,}Operator Precedence Hierarchy}

%%\appendixright{E}{Operator Precedence Hierarchy}

\noindent Table E.1 summarizes the precedence and
associativity relationships for Java operators.   Within a single
expression, an operator of order {\it m} would be evaluated before an
operator of order {\it n} if $m < n$. Operators having the same order
are evaluated according to their association order.  For example, the
expression

\begin{jjjlisting}
\begin{lstlisting}
25 + 5 * 2 + 3
\end{lstlisting}
\end{jjjlisting}

\noindent would be evaluated in the order shown by the following
parenthesized expression:

\begin{jjjlisting}
\begin{lstlisting}
(25 + (5 * 2)) + 3   ==> (25 + 10) + 3 ==> 35 + 3  ==> 38
\end{lstlisting}
\end{jjjlisting}

\noindent In other words, because \verb|*| has higher precedence
than \verb|+|, the multiplication operation is done before either of
the addition operations.   And because addition associates from left to
right, addition operations are performed from left to right.

Most operators associate from left to right, but note that assignment
operators associate from right to left.   For example, consider the
following code segment:

\begin{jjjlisting}
\begin{lstlisting}
int i, j, k;
i = j = k = 100;     // Equivalent to i = (j = (k = 100));
\end{lstlisting}
\end{jjjlisting}

\begin{table}[h]
%\hphantom{\caption{Java operator precedence and associativity table.\index{precedence table}}}
\TBT{0pc}{Java operator precedence and associativity table.}
\hspace*{-6pt}\begin{tabular}{clll}
\multicolumn{4}{l}{\color{cyan}\rule{29pc}{1pt}}\\[2pt]
%%%%\TBCH{{\bf Order}} & \TBCH{{\bf Operator}} & \TBCH{{\bf Operation}} & \TBCH{{\bf Association}}
{\bf Order} & {\bf Operator} & {\bf Operation} & {\bf Association}
\\[-4pt]\multicolumn{4}{l}{\color{cyan}\rule{29pc}{0.5pt}}\\[2pt]
0 &\verb|(  )|&{\it Parentheses}\cr
1 &\verb|++   -- |$\;\cdot$&{\it Postincrement,  Postdecrement, Dot Operator}&{\it L to R}\cr
2 &\verb|++   --  +  -  !|&{\it Preincrement,  Predecrement, }&{\it R to L}\cr
  &&{\it Unary plus,  Unary minus,  Boolean NOT}&\cr
3 &\verb|(type)  new|&{\it Type  Cast, Object Instantiation}&{\it R to L}\cr
4 &\verb|*  /  %|&{\it Multiplication,  Division,  Modulus}&{\it L to R}\cr
5 &\verb|+ -  +|&{\it Addition,  Subtraction,  String Concatenation}&{\it L to R}\cr
6 &\verb|<  >  <=  >=|&{\it Relational  Operators}&{\it L to R}\cr
7 &\verb|==   !=|&{\it Equality  Operators}&{\it L to R}\cr
8 &$\wedge$&{\it Boolean  XOR}&{\it L to R}\cr
9 &\verb|&&|&{\it Boolean  AND}&{\it L to R}\cr
10&\verb||||&{\it Boolean  OR}&{\it L to R}\cr
11&\verb|= += -= *= /= %=|&{\it Assignment  Operators}&{\it R to L}
\\[-4pt]\multicolumn{4}{l}{\color{cyan}\rule{29pc}{1pt}}
\end{tabular}
\endTB
\end{table}

\noindent  In this case, each variable will be assigned 100 as its
value.  But it's important that this expression be evaluated from right
to left.  First, {\it k} is assigned 100. Then its value is assigned
to {\it j}. And finally {\it j}'s value is assigned to {\it i}.

For expressions containing mixed operators, it's always a good idea to
use parentheses to clarify the order of evaluation.  This will also
help avoid subtle syntax and semantic errors.


%!TEX root = <JHU-SIMPLEX_proposal.tex>
% \clearpage
\section{Statement of Work}
\label{sec:sow}
% \emph{The SOW must provide a detailed task breakdown, citing specific tasks and their connection to the interim milestones and metrics, as applicable. Each year of the project should be separately defined. The SOW must not include proprietary information. For each defined task/subtask, provide:
% %
% (1) A general description of the objective.
% (2) A detailed description of the approach to be taken to accomplish each defined task/subtask.
% (3) Identification of the primary organization responsible for task execution (prime contractor, subcontractor(s), consultant(s)), by name.
% (4) A measurable milestone, (e.g., a deliverable, demonstration, or other event/activity that marks task completion).
% (5) A definition of all deliverables (e.g., data, reports, software) to be provided to the Government in support of the proposed tasks/subtasks.}
%

\subsection{Phase I}

\subsubsection{Task 1: Mathematical Formalism}
\begin{compactitem}
\item \textbf{Goal:} \emph{RAG Embedding:} Completion of the theoretical development and associated data structures of our RAG representation system. This includes establishing baseline methods for embeddings RAGs and populations thereof.  Specifically, we will explore both JOFC and tensor factorization methodologies, to enable understanding of the computational and statistical advantages and disadvantages of each for embedding high-dimensional non-Euclidean RAGS.

\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstration that RAGs are able to meet TA1 goals, including encoding quantitative and qualitative knowledge, and express functional relationship among entities in complex systems.
\item \textbf{Deliverables:} Description of mathematical framework and preliminary benchmarks evaluating performance on open access data sets and simulations.
\end{compactitem}

\subsubsection{Task 2: Computational Infrastructure}
\begin{compactitem}
\item \textbf{Goal:} \emph{Data Management:} Implementation of baseline algorithms for context-aware reasoning and inference using the representation. Development of an initial computational and data management platform, including establishing common data formats, common methods and format for query and analysis of results, and a common API through which all domain-specific users will access the framework. We will also extend our dense spatial and semantic databases, as well as our graph data format to support time-varying data, along with multi-modal data.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Completion of Phase I prototype software and services.
\item \textbf{Deliverables:} Open source software and documentation for end-to-end prototype.
\end{compactitem}

\subsubsection{Task 3: Datafication}
\begin{compactitem}
\item \textbf{Goal:} \emph{Data Ingest:} Completion of data ingest techniques. Completion of research and design into microscopic and mesoscopic specific analysis tools.  Demonstration of auto-data ingestion and registration of multiple different modalities (functional to structural for both microscopic and mesoscopic data). More specifically, we will have ingested CLARITY, LFM, and M$^3$RI data into the same database schema; all M$^3$RI data will be co-registered.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstration of operational auto-ingestion and registration on two different use-cases.
\item \textbf{Deliverables:} Open source software and documentation for datafication techniques, as well as image datasets ingested and RAGs estimated from all different data modalities.
\end{compactitem}

\subsubsection{Task 4: Discovery}
\begin{compactitem}
\item \textbf{Goal:} \emph{RAG Construction:}
 Completion of research and design into microscopic and mesoscopic specific analysis tools, by designing metrics appropriate for the different data modalities.  This includes both the microscale and mesoscale functional time-series, converting into RAGs via utilizing qualitative information.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstration of RAG construction on both use cases.
\item \textbf{Deliverables:} Open source software and documentation RAG construction techniques, as well as the derived RAGs available via our Web-services.
\end{compactitem}

\subsubsection{Task 5: Program Management}
\begin{compactitem}
\item \textbf{Goal:} \emph{Phase I:} Ensure successful execution of the effort. Manage the proposed effort using a proven methodology for project planning, resource allocation, task specification, and monitoring. Establish a baseline project plan with a list of tasks, specifications, requirements, and timelines; update plan periodically; document updates to the plan and share them with the project team and DARPA PM.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Meet Phase I goals.
\item \textbf{Deliverables:}
(1) Comprehensive quarterly technical reports that include updates systems architecture and progress made on milestones for Phase I;
(2) Brief month reports, including preprints of technical reports;
(3) Final Technical Report;
(4) Monthly Financial Reports.
\end{compactitem}

\subsection{Phase II}

\subsubsection{Task 1: Mathematical Formalism}
\begin{compactitem}
\item \textbf{Goal:} \emph{FlashRAG:} Implementation of all embedding and construction methodologies in FlashGraph to enable scalable implementations and processing.  Moreover, all constructed RAGs will obtain multilevel representations.  We will build R bindings to enable easy use of FlashGraph for data scientists.  We will check that our implementations and bindings yield approximately the same answer as benchmark methods, on data sufficiently small that benchmark methods can run.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Fully operational FlashGraph and R bindings for embedding and constructing methodologies.
\item \textbf{Deliverables:} Open source software and documentation for end-to-end prototype for embedding and constructing RAGs. This includes an R package for FlashGraph.
\end{compactitem}

\subsubsection{Task 2: Computational Infrastructure}
\begin{compactitem}
\item \textbf{Goal:} \emph{Remote Access:} Implementation of prototype platform for remote access. This will include Web-services for uploading the raw data, and downloading the derived data products (RAGs and intermediate data products), as well as both 2D and 3D visualization and annotation tools, which will support multiple kinds of analytic overlays, all of which will support multiple data scales. Moreover, we will have made theoretical and practical refinements to the representation to enable scalable implementation of several foundational algorithms on RAGs, implementing the embedding methodologies developed in Task 1 of Phase I into our semi-external memory formalism.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Fully operational Web-services supporting uploading, visualizing, annotation, querying, downloading, and analyzing the data.
\item \textbf{Deliverables:} Open source software and documentation for end-to-end prototype. This includes an R package for FlashGraph which extends it capabilities to RAGs, rather than simply graphs.
\end{compactitem}

\subsubsection{Task 3: Datafication}
\begin{compactitem}
\item \textbf{Goal:} \emph{Data Register:} Integration of domain-specific computational models across modalities and scales. This includes completion of statistical multi-modal referencing, including alignment of structural and functional imaging data, for both microscopic and mesoscopic data sets.  We will also complete functional inference capabilities. We will align data both via scaling up multidimensional out-of-core image alignment algorithms, and RAG matching, which extends graph matching by incorporating attributes.  This will enable us to determine optimal alignments using data priors and known topological structure, rather than relying on images to align well.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstration of multi-modal registration for both microscopic and mesoscopic use cases.
\item \textbf{Deliverables:} Open source software and documentation for datafication techniques, as well as registered multi-modal image datasets ingested and aligned RAGs from both microscale and mesoscale.
\end{compactitem}

\subsubsection{Task 4: Discovery}
\begin{compactitem}
\item \textbf{Goal:} \emph{RAG Summary Statistics:} Utilize RAG knowledge representation to estimate population moments, motifs, and/or modes from both  micro- and meso-scale RAGs.  More specifically, we will utilize the various joint embedding methodologies developed in Task 1 to estimate these summary statistics.  The different approaches, JOFC versus tensor factorization, will enable incorporating different kinds of prior knowledge and constraints, so they will therefore lead to different bias/variance trade-offs.  We will explore these options empirical on the real data, to complement our experiments in Task 1, to discover both (i) the best methods for estimation these summary statistics, and (ii) the best estimates of the summary statistics for the two different scales.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstration utility of RAG representation of data for estimating summary statistics for multi-modal data.
\item \textbf{Deliverables:} Estimated summary statistics from micro- and meso-scale RAGs available for download in various formats, as well as open source code for the different estimators.
\end{compactitem}

% \subsubsection{Task 4: Discovery}
% \begin{compactitem}
% \item \textbf{Goal:} \emph{RAG Independence:} Instantiation of first-generation analysis tools, including tests for independence between connectivity and graph, vertex, and/or edge attributes, and application of those tools to both use cases. We will leverage the RAG representation system to discover whether mouse or human graph connectivity is independent of graph attributes. For both inference tasks, we will utilize and extending the scalable embedding methodologies developed in Task 2 of Phase II.
% \item \textbf{Primary Site:} JHU
% \item \textbf{Milestone:} Demonstration utility of RAG representation of data for multi-modal neuroscientific discoveries for both microscale and mesoscale.
% \item \textbf{Deliverables:} Discovered multi-modal motifs from microscale data and hypothesis testing results and visualizations from mesoscale data.
% \end{compactitem}

\subsubsection{Task 5: Program Management}
\begin{compactitem}
\item \textbf{Goal:} \emph{Phase II Goals:} Ensure successful execution of the effort. Manage the proposed effort using a proven methodology for project planning, resource allocation, task specification, and monitoring. Establish a baseline project plan with a list of tasks, specifications, requirements, and timelines; update plan periodically; document updates to the plan and share them with the project team and DARPA PM.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Meet Phase II goals.
\item \textbf{Deliverables:}
(1) Comprehensive quarterly technical reports that include updates systems architecture and progress made on milestones for Phase II;
(2) Brief month reports, including preprints of technical reports;
(3) Final Technical Report;
(4) Monthly Financial Reports.
\end{compactitem}

\subsection{Phase III}

\subsubsection{Task 1: Mathematical Formalism}
\begin{compactitem}
\item \textbf{Goal:} \emph{RAG Testing:} Demonstration of capabilities and objectives on both microscale and mesoscale data, as well as one additional SIMPLEX performer. To achieve this, we will extend our embedding methodologies, to derive provably approximately optimal embeddings for conducting one-sample and two-sample tests on RAGs; two fundamental testing procedures in statistics.  Our tests will leverage our ability to efficiently sample RAGs, as they will be resampling based tests, analogs to the classic parametric and non-parametric bootstrap.  We will apply these tests to test, for example, whether our data are sampled from relatively simple RAGs statistical models, and whether population means that we obtained in Phase I are significantly different from one another.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Demonstrate our mechanism for relating qualitative and quantitative knowledge, and relating multiple heterogeneous datasets, on both heterogeneous scales (use cases). Specifically, testing whether multiple heterogeneous datasets are statistically different from one another.
\item \textbf{Deliverables:} Description of capabilities, emphasizing generalizability to multiple use cases, open source code from implementing our tests, visualizations and numerical summaries of test results.
\end{compactitem}

% \subsubsection{Task 1: Mathematical Formalism}
% \begin{compactitem}
% \item \textbf{Goal:} \emph{RAG Learning:} Completion of mathematical tools for hypothesis generation, testing, and model validation using RAGs. This will include context aware algorithms capable of running in interactive time.  More specifically, we will extend the toolbox of inferential techniques to include unsupervised, semi-supervised, and fully supervised methods for clustering RAGs.  All these methods will utilize  the estimation and embedding strategies developed in the previous tasks for this proposal.  Moreover, we will extend such embedding methodologies to optimize them for the particular learning tasks.  Theoretical and numerical results will support the utility of these methodologies.
% \item \textbf{Primary Site:} JHU
% \item \textbf{Milestone:} Demonstration of the full suite of mathematical capabilities on RAGs, including estimating, testing, and un-/semi-/fully-supervised learning methodologies.
% \item \textbf{Deliverables:} Complete description of capabilities of RAGs, as well as open source code to run all analyses in R on commodity hardware.
% \end{compactitem}

\subsubsection{Task 2: Computational Infrastructure}
\begin{compactitem}
\item \textbf{Goal:} \emph{Local Analysis:} Completion of an integrated system on both heterogeneous scales (as well as additional domains).  This system ingests and registers imaging data and semantic and qualitative knowledge, converts them into RAGs, allows query and recall, visualization, hypothesis generation, and analysis. We will also release open source packages containing all of the key resources, such as an R package (which calls igraph or FlashGraph) containing all of the developed methods, and GPU optimized visualization and annotation tools. This will enable anybody to implement analyses locally by running the code on their machine.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Fully operation Web-services to auto-ingest, register, store in compact representation, and query, as well as operate locally.
\item \textbf{Deliverables:} Open source software and documentation for end-to-end prototype. including FlashGraphR and GPU optimized visualization and annotation tool.
\end{compactitem}

\subsubsection{Task 3: Datafication}
\begin{compactitem}
\item \textbf{Goal:} \emph{Quality Control:} Completion of quality control of all datasets.  For each different modality, and each different scale, we will have already converted the raw data into RAGs.  Now, we will build automatic quality controls, so that with each dataset, we automatically generate a quality control report, quantifying the key quality metrics appropriate for that data (see Table \ref{tab:qa}).
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} All datasets have been checked for quality.
\item \textbf{Deliverables:} Open source software and documentation for datafication techniques, including quality control scripts, and resulting outputs.
\end{compactitem}

\subsubsection{Task 4: Discovery}
\begin{compactitem}
\item \textbf{Goal:} \emph{RAG Prediction:} Completion of toolset for analysis, modeling, and data-driven hypothesis generation and testing in both microscale and mesoscale heterogeneous use cases. This will include multiscale prediction; prediction of mouse status from microscale RAGs, and human personality from human RAGs.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone:} Successful integration with TA1 technology and end-of-program demonstrations of our integrated system on both microscale and mesocale.
\item \textbf{Deliverables:} All data-derived products available for visualization utilizing our Web-services and quality control pages, as well as for download and further analysis using our open source code.
\end{compactitem}

\subsubsection{Task 5: Program Management}
\begin{compactitem}
\item \textbf{Goal:} \emph{Phase III:} Ensure successful execution of the effort. Manage the proposed effort using a proven methodology for project planning, resource allocation, task specification, and monitoring. Establish a baseline project plan with a list of tasks, specifications, requirements, and timelines; update plan periodically; document updates to the plan and share them with the project team and DARPA PM.
\item \textbf{Primary Site:} JHU
\item \textbf{Milestone} Meet Phase III goals.
\item \textbf{Deliverables:}
(1) Comprehensive quarterly technical reports that include updates systems architecture and progress made on milestones for Phase III;
(2) Brief month reports, including preprints of technical reports;
(3) Final Technical Report;
(4) Monthly Financial Reports.
\end{compactitem}


% Abstract ====================================================================

\pdfbookmark[1]{Abstract}{Abstract}
\chapter*{Abstract}

Data analysis and machine learning have become an integrative part of the
modern scientific methodology, offering automated procedures for the prediction
of a phenomenon based on past observations, unraveling underlying patterns in
data and providing insights about the problem. Yet, caution should
avoid using machine learning as a black-box tool, but rather consider it as a
methodology, with a rational thought process that is entirely dependent on the
problem under study. In particular, the use of algorithms
should ideally require a reasonable understanding of their
mechanisms, properties and limitations, in order to better apprehend and
interpret their results.

Accordingly, the goal of this thesis is to provide an in-depth
analysis of random forests, consistently calling into
question each and every part of the algorithm, in order to shed new light on
its learning capabilities, inner workings and interpretability. The first
part of this work studies the induction of decision trees and the construction of
ensembles of randomized trees, motivating their design and purpose whenever
possible. Our contributions follow with an original complexity
analysis of random forests, showing their good computational performance
and scalability, along with an in-depth discussion of their
implementation details, as contributed within Scikit-Learn.

In the second part of this work, we analyze and discuss the interpretability of
random forests in the eyes of variable importance measures. The core of our
contributions rests in the theoretical characterization of the Mean Decrease of
Impurity variable importance measure, from which we prove and derive some of
its properties in the case of multiway totally randomized trees and in
asymptotic conditions. In consequence of this work, our analysis  demonstrates
that variable importances as computed from non-totally randomized trees (e.g.,
standard Random Forest) suffer from a combination of defects, due to masking
effects, misestimations of node impurity or due to the binary structure of
decision trees.

Finally, the last part of this dissertation addresses limitations of random
forests in the context of large datasets. Through extensive experiments, we
show that subsampling both samples and features simultaneously provides on par
performance while lowering at the same time the memory requirements. Overall
this paradigm highlights an intriguing practical fact: there is often no need
to build single models over immensely large datasets. Good performance can
often be achieved by building models on (very) small random parts of the data
and then combining them all in an ensemble, thereby avoiding all practical
burdens of making large data fit into memory.


\RequirePackage[l2tabu, orthodox]{nag}
\documentclass{article}

\usepackage[letterpaper]{geometry}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage[binary-units=true]{siunitx}
\usepackage{tikz}

\title{ECE 487 Assignment 5}
\author{Michael Kwok}
\begin{document}

\maketitle
\subsection*{Stop and Wait ARQ}
Round trip time: \(\frac{600000}{3 \times 10^8} = 2 \times 10^{-3}\)
2 Timeouts: \(0.5 + 0.5\) seconds\\
1 Successful round trip: \(2 \times 10^{-3}\) \\
Total time: \(1.002\) seconds\\
Data sent: \(1000\) bits\\
Throughput: \( \frac{1000}{1.002} = \SI{998}{\bit\per\second}\)

\subsection*{ALOHA station throughput}
\(T_{fr} = \SI{0.4}{\milli\second}\)

\subsubsection*{Pure}
\(G = 0.5\) to get maximum throughput.\\
System frames per second: \( G \cdot \frac{1000}{0.4} = 1250 \text{Frames per Second} \) \\
50 stations, so average frames per second per station: \(\frac{1250}{50} = 25\)

\subsubsection*{Slotted}
\(G = 1\) to get maximum throughput.\\
System frames per second: \( G \cdot \frac{1000}{0.4} = 2500 \text{Frames per Second} \) \\
50 stations, so average frames per second per station: \(\frac{2500}{50} = 50\)

\subsection*{ALOHA system throughput}
\(T_{fr} = \frac{2000}{10^6} = \SI{2}{\milli\second}\)

\(G = \frac{500}{\frac{1000}{2}} = 1\)

\(50 \cdot 10 = 500\) Frames sent per second

\subsubsection*{Pure}
\(S = G \cdot e^{-2} = 0.135 \) \\
System throughput: \(500 \cdot 0.135 = 67.7\) Frames per second

\subsubsection*{Slotted}
\(S = G \cdot e^{-1} = 0.368 \) \\
System throughput: \(500 \cdot 0.368 = 183.9\) Frames per second

\subsection*{CSMA/CD}

\ifx\du\undefined
    \newlength{\du}
\fi
\setlength{\du}{15\unitlength}
\begin{tikzpicture}
    \pgftransformxscale{0.998158}
    \pgftransformyscale{-0.998158}
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
    \pgfsetfillcolor{dialinecolor}
    \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
    \pgfsetfillcolor{dialinecolor}
    \fill (13.000000\du,8.000000\du)--(13.000000\du,10.000000\du)--(17.000000\du,10.000000\du)--(17.000000\du,8.000000\du)--cycle;
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetmiterjoin
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \draw (13.000000\du,8.000000\du)--(13.000000\du,10.000000\du)--(17.000000\du,10.000000\du)--(17.000000\du,8.000000\du)--cycle;
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node at (15.000000\du,9.194053\du){A};
    \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
    \pgfsetfillcolor{dialinecolor}
    \fill (23.000000\du,8.000000\du)--(23.000000\du,10.000000\du)--(27.000000\du,10.000000\du)--(27.000000\du,8.000000\du)--cycle;
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetmiterjoin
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \draw (23.000000\du,8.000000\du)--(23.000000\du,10.000000\du)--(27.000000\du,10.000000\du)--(27.000000\du,8.000000\du)--cycle;
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node at (25.000000\du,9.194053\du){B};
    \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
    \pgfsetfillcolor{dialinecolor}
    \fill (33.000000\du,8.000000\du)--(33.000000\du,10.000000\du)--(37.000000\du,10.000000\du)--(37.000000\du,8.000000\du)--cycle;
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetmiterjoin
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \draw (33.000000\du,8.000000\du)--(33.000000\du,10.000000\du)--(37.000000\du,10.000000\du)--(37.000000\du,8.000000\du)--cycle;
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node at (35.000000\du,9.194053\du){C};
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (15.000000\du,10.000000\du)--(15.000000\du,20.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (25.000000\du,10.000000\du)--(25.000000\du,20.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (35.000000\du,10.000000\du)--(35.000000\du,20.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \pgfsetarrowsend{to}
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (15.000000\du,10.000000\du)--(35.000000\du,18.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \pgfsetarrowsend{to}
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (25.000000\du,12.000000\du)--(15.000000\du,16.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \pgfsetarrowsend{to}
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (25.000000\du,12.000000\du)--(35.000000\du,16.000000\du);
    }
    \pgfsetlinewidth{0.100000\du}
    \pgfsetdash{}{0pt}
    \pgfsetdash{}{0pt}
    \pgfsetbuttcap
    {
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetfillcolor{dialinecolor}
        % was here!!!
        \pgfsetarrowsend{to}
        \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
        \pgfsetstrokecolor{dialinecolor}
        \draw (35.000000\du,14.000000\du)--(15.000000\du,20.000000\du);
    }
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (14.000000\du,10.000000\du){};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (14.000000\du,10.000000\du){};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,10.000000\du){0uS};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,12.000000\du){1uS};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,14.000000\du){2uS};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,16.000000\du){3uS};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,18.000000\du){4uS};
    % setfont left to latex
    \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
    \pgfsetstrokecolor{dialinecolor}
    \node[anchor=west] at (27.000000\du,20.000000\du){5uS};
\end{tikzpicture}

Transmission rate: \(10\times 10 ^{6} \times 3 \times 10 ^{-6} = \SI{30}{\bit\per\second}\)\\
A will transmit for \SI{3}{\micro\second}, \SI{30}{\bit}\\
B will transmit for \SI{1}{\micro\second}, \SI{10}{\bit}\\
C will transmit for \SI{1}{\micro\second}, \SI{10}{\bit}

\end{document}


\subsection{KENN with multiloss function}
In previous experiments, it has been observed that the pre-KENN network adapts to the presence of KENN regardless of the parameters configuration. From these results comes the intuition to make the pre-KENN network more independent, with the purpose of exploiting the logical knowledge more effectively. To achieve this, the idea is to define a custom multiloss function to simultaneously improve the quality of the pre-KENN and post-KENN predictions.

%\subsubsection{Multiloss function}
The proposed multiloss function is computed by combining the Binary Cross-Entropy (BCE) loss values obtained from the pre-KENN and post-KENN preactivations. To make it possible, the model has been adapted to provide two outputs: one before and one after KENN's layer. The goal is to optimize the post-KENN predictions while preserving a discrete quality of pre-KENN predictions. The final loss is computed by the convex combination of the two losses whose influences are regulated by the parameter $ \alpha $. The resulting formula is the following:

% \begin{gather*}
%     L(y_{pred},y_{true}) = \alpha \cdot BCE(y_{prekenn}, y_{true}) + (1 - \alpha) \cdot BCE(y_{postkenn}, y_{true})
% \end{gather*}

\begin{gather*}
    L(Y, Y', Y_{t}) = \alpha \cdot BCE(Y, Y_{t}) + (1 - \alpha) \cdot BCE(Y', Y_{t})
\end{gather*}
where $Y$ denotes the pre-KENN predictions, $Y'$ the post-KENN predictions, and $Y_{t}$ the values of the ground truth.

\subsubsection{Setup}
The models involved in this experiment are trained following the \textit{Setup B}. The configuration of the other parameters is the following:
\begin{itemize}
    \item \textbf{KB modes:} Bottom Up and Top Down
    \item \textbf{initial clause weights:} 0.5 and variable\footnote{With the term ``variable" we mean that each clause can be initialized with a different value. The original implementation of KENN did not contemplate this possibility when setting clause weights as learnable parameters, so we introduced a small modification to make it possible.}
    \item \textbf{learnable clause weights}
    \item \textbf{encoder:} DistilBERT and BERT, with adapters
    \item \textbf{loss function:} multiloss with $\alpha = 0.5$
\end{itemize}
The total number of configurations obtained by varying these parameters is 8. Since the pre-KENN network is expected to be less influenced by KENN, the clause weights are set as learnable parameters with small initial values to start with a soft influence and let the network establish the relevance of each clause. Indeed, the choice of learnable clause weights allows us to study the weight evolution during the epochs and determine which are the most useful and the least useful clauses. Furthermore, for each clause, the types that are the antecedents of an implication rule (i.e., the types that propagate the information and uniquely characterize the used KBs) have been studied to look for some recurring behavioral patterns. The \textit{Hybrid} mode is excluded from this study because it involves the same clauses of \textit{Bottom Up} and \textit{Top Down}, but with the addition of noise due to the presence of conflicts. For this reason, it would not have been possible to carry out an accurate analysis.

\subsubsection{Results on FIGER}
\paragraph{DistilBERT}
The results obtained using DistilBERT as encoder show some very interesting behaviors of the clause weights. Starting from the Bottom Up, if we look at the distribution of final clause weights in Figure~\ref{fig:weight_distrib_distilbert_figer_bu_multiloss} we can see that almost every weight decreases its initial value. This attitude is not observable in Figure~\ref{fig:weight_distrib_distilbert_figer_bu_learnable} when using KENN with a standard loss and learnable weights. If we look at the figure, we can see widely different results since almost every weight increases its starting value. The same trend is detectable in the Top Down mode, as shown in Figure~\ref{fig:weight_distrib_distilbert_figer_td}.

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_distrib_distilbert_figer_bu_multiloss.png}
         \caption{Multiloss model - Epoch 55 (563K examples)}
         \label{fig:weight_distrib_distilbert_figer_bu_multiloss}
     \end{subfigure}
     \hspace{10px}
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_distrib_distilbert_figer_bu_learnable.png}
         \caption{Standard loss model - Epoch 42 (430K examples)}
         \label{fig:weight_distrib_distilbert_figer_bu_learnable}
     \end{subfigure}
    \caption{Distributions of the final learned clause weights for the Bottom Up KB mode using DistilBERT-based models - FIGER}
    \label{fig:weight_distrib_distilbert_figer_bu}
\end{figure}

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_distrib_distilbert_figer_td_multiloss.png}
         \caption{Multiloss model - Epoch 42 (430K examples)}
         \label{fig:weight_distrib_distilbert_figer_td_multiloss}
     \end{subfigure}
     \hspace{10px}
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_distrib_distilbert_figer_td_learnable.png}
         \caption{Standard loss model - Epoch 39 (399K examples)}
         \label{fig:weight_distrib_distilbert_figer_td_learnable}
     \end{subfigure}
    \caption{Distributions of the final learned clause weights for the Top Down KB mode using DistilBERT-based models - FIGER}
    \label{fig:weight_distrib_distilbert_figer_td}
\end{figure}

Moving on to the analysis of the types involved in the clauses we can observe an unexpected behavior. For both Bottom Up and Top Down modes, this study intercepts a remarkable fact: the more a type occurs in the training set, the lower the final weight of its clause. The few clauses that preserve a high weight are those whose antecedents are the rarest in the dataset. Starting from the Bottom Up mode, we can see in Figure~\ref{fig:weight_freq_distilbert_figer_bu_multiloss} a graph showing the relation between the final weight and the frequency of each type S. Looking at the figure, we can clearly observe that there is a strong correlation between weight and frequency. Indeed, the correlation coefficient is -0.77. The Top Down mode (Figure~\ref{fig:weight_freq_distilbert_figer_td_multiloss}) also presents a negative correlation, this time of -0.68 with respect to the frequencies of types F.
%This behavior may be explained by the fact that KENN introduces too much noise to types that the network can already predict discretely without the use of knowledge.

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_distilbert_figer_bu_multiloss.png}
         \caption{Bottom Up - Epoch 55 (563K examples)}
         \label{fig:weight_freq_distilbert_figer_bu_multiloss}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_distilbert_figer_td_multiloss.png}
         \caption{Top Down - Epoch 42 (430K examples)}
         \label{fig:weight_freq_distilbert_figer_td_multiloss}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using DistilBERT - FIGER}
    \label{fig:weight_freq_distilbert_figer}
\end{figure}

By inspecting the weight evolution over the epochs, it emerged that the clause weights keep decreasing until the last epoch, but it is not known for how long they would have continued. To observe in advance the effect of higher epochs and see if some clauses would have reached a weight close to zero, new models were trained starting from variable weights assigned with respect to the frequency of the antecedents of each clause. Clauses involving popular types were assigned a weight of 0.2, while the others kept a weight of 0.5. The weight assignment is based on a frequency threshold of 70K for Bottom Up and 50K for Top Down\footnote{the values are chosen by observing the graphs, without formalizing a mathematical criterion}. The results of these runs are shown in Figure~\ref{fig:weight_freq_distilbert_figer_bu_multiloss_variable} and Figure~\ref{fig:weight_freq_distilbert_figer_td_multiloss_variable} for Bottom Up and Top Down, respectively. As we can see, most clause weights decreased their values even when starting from lower initial values.
%However, by analyzing the weight evolution, it emerged that their decrease over the epochs was slowed down. The reason for this fact is that clauses now have less influence on the final prediction, so they are penalized in a minor way by the loss function.

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_distilbert_figer_bu_multiloss_variable.png}
         \caption{Bottom Up - Epoch 71 (727K examples)}
         \label{fig:weight_freq_distilbert_figer_bu_multiloss_variable}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_distilbert_figer_td_multiloss_variable.png}
         \caption{Top Down - Epoch 42 (430K examples)}
         \label{fig:weight_freq_distilbert_figer_td_multiloss_variable}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using DistilBERT and \textit{variable} clause weights - FIGER}
    \label{fig:weight_freq_distilbert_figer_variable}
\end{figure}

\paragraph{BERT}
The experiments performed using BERT showed an identical behavior. The results obtained with weights set to 0.5 for every clause are shown in Figure~\ref{fig:weight_freq_bert_figer}. The correlation between weight and frequency is similar (-0.76 in Bottom Up, -0.74 in Top Down) as well as the weight evolution during the epochs. The only difference with respect to DistilBERT is that BERT needs fewer epochs to converge, so its weights have decreased less as it performed fewer backward propagation operations. Much lower weights are reached when using the setup with variable weights as reported in Figure~\ref{fig:weight_freq_bert_figer_variable}.

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_figer_bu_multiloss.png}
         \caption{Bottom Up - Epoch 35 (358K training examples)}
         \label{fig:weight_freq_bert_figer_bu_multiloss}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_figer_td_multiloss.png}
         \caption{Top Down - Epoch 35 (358K training examples)}
         \label{fig:weight_freq_bert_figer_td_multiloss}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using BERT - FIGER}
    \label{fig:weight_freq_bert_figer}
\end{figure}

\begin{figure}[bth]
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_figer_bu_multiloss_variable.png}
         \caption{Bottom Up - Epoch 49 (501K training examples)}
         \label{fig:weight_freq_bert_figer_bu_multiloss_variable}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_figer_td_multiloss_variable.png}
         \caption{Top Down - Epoch 33 (337K training examples)}
         \label{fig:weight_freq_bert_figer_td_multiloss_variable}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using BERT and \textit{variable} clause weights - FIGER}
    \label{fig:weight_freq_bert_figer_variable}
\end{figure}

\subsubsection{Results on BBN}
The experiments on BBN were performed directly on BERT. In Figure~\ref{fig:weight_freq_bert_bbn} are represented the graphs of weights and frequencies using the same weight for each clause. The correlation coefficients of the Bottom Up and Top Down modes are -0.73 and -0.55, respectively. The results obtained after repeating the experiments using variable weights are shown in Figure~\ref{fig:weight_freq_bert_bbn_variable}. The weight assignment is based on a frequency threshold of 1700 for Bottom Up and 1500 for Top Down\footnote{the values are chosen by observing the graphs, without formalizing a mathematical criterion}. Looking at the graphs, it is possible to observe that most of the weights continued to decrease.

\begin{figure}
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_bbn_bu_multiloss.png}
         \caption{Bottom Up - Epoch 28 (286K training examples)}
         \label{fig:weight_freq_bert_bbn_bu_multiloss}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_bbn_td_multiloss.png}
         \caption{Top Down - Epoch 19 (194K training examples)}
         \label{fig:weight_freq_bert_bbn_td_multiloss}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using BERT - BBN}
    \label{fig:weight_freq_bert_bbn}
\end{figure}

\begin{figure}
     \centering
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_bbn_bu_multiloss_variable.png}
         \caption{Bottom Up - Epoch 19 (194K training examples)}
         \label{fig:weight_freq_bert_bbn_bu_multiloss_variable}
         \vspace{10px}
     \end{subfigure}
     \begin{subfigure}[b]{0.7\textwidth}
         \centering
         \includegraphics[width=\textwidth]{figures/weight_freq_bert_bbn_td_multiloss_variable.png}
         \caption{Top Down - Epoch 19 (194K training examples)}
         \label{fig:weight_freq_bert_bbn_td_multiloss_variable}
     \end{subfigure}
    \caption{Relation between types frequency (log scale) and final clause weights of multiloss models using BERT and \textit{variable} clause weights - BBN}
    \label{fig:weight_freq_bert_bbn_variable}
\end{figure}

\subsubsection{Conclusion}
The multiloss experiments showed that the pre-KENN network suffers the presence of some logical clauses when it is forced to not adapt its predictions to KENN. In particular, it has been possible to see that the learning process penalized clauses involving the most frequent types much more than the others. This behavior can be motivated by the fact that if a network sees a lot of instances labeled with some types, then it becomes able to correctly classify them without needing logical knowledge. For this reason, it seems that the action of KENN on frequent types is seen as noise added to the final predictions. Conversely, the enhancement of rarer types is not penalized by the learning process, so logical clauses seem to be helpful for the network when few examples labeled with those types are available. For this reason, using a multiloss setup could be a reasonable choice to exploit logical knowledge only where needed, thus avoiding having side effects on the types that are easier to predict.