\section{Clause-containment learning for E-MAJSAT}
\label{sect:erssat-technique}

Consider an E-MAJSAT formula $\Qf = \exists X,\random{} Y.\pf$.
To obtain the satisfying probability of $\Qf$,
it suffices to enumerate every assignment $\as$ over $X$ and calculate the corresponding conditional satisfying probability $\spb{\pcf{\Qf}{\as}}$.
Clearly, the above brute-force approach is computationally expensive.
Motivated by the idea of clause selection discussed above,
we propose \textit{clause-containment learning} to prune the search space.
The proposed learning technique deduces useful information after each trial of an assignment $\as$ over $X$.
The learnt information is recorded as blocking clauses to avoid wasteful exploration and thus accelerates the search process.
The proposed learning technique is based on the following key observation.

\begin{proposition}
    \label{prop:erssat-contain}
    Given an E-MAJSAT formula $\Qf=\exists X,\random{} Y.\pf(X,Y)$ and two assignments $\as_1,\as_2$ over $X$,
    we have:
    \begin{align*}
        (\pcf{\pf}{\as_2}\limply\pcf{\pf}{\as_1})\limply\spb{\pcf{\Qf}{\as_2}}\leq\spb{\pcf{\Qf}{\as_1}}.
    \end{align*}
\end{proposition}

Inspired by~\cref{prop:erssat-contain},
we propose clause-containment learning based on clause selection.
After cofactoring $\pf$ with an arbitrary assignment $\as_1$ over $X$,
a set $\pcf{\pf}{\as_1}$ of clauses is selected.
For any other assignment $\as_2$ selecting all clauses from $\pcf{\pf}{\as_1}$,
i.e., $\pcf{\pf}{\as_1}\subseteq\pcf{\pf}{\as_2}$,
we have $\pcf{\pf}{\as_2}\limply\pcf{\pf}{\as_1}$.
Therefore, $\spb{\pcf{\Qf}{\as_2}}\leq\spb{\pcf{\Qf}{\as_1}}$ holds according to~\cref{prop:erssat-contain}.
Since the satisfying probability $\spb{\pcf{\Qf}{\as_2}}$ is not greater than $\spb{\pcf{\Qf}{\as_1}}$,
the assignment $\as_2$ is not worth trying.
For all such assignments,
they should be blocked after $\as_1$ has been explored.

The core concept of the clause-containment learning is to avoid every unexplored assignment $\as_2$ that selects a clause set $\pcf{\pf}{\as_2}$ containing another clause set $\pcf{\pf}{\as_1}$ selected by an explored assignment $\as_1$.
To block the assignment $\as_2$,
we enforce at least one of the clauses in $\pcf{\pf}{\as_1}$ to be deselected.
Recall that the selection variable $\sv{C}$ of clause $C$ valuates to $\bot$ if and only if $C$ is deselected.
Therefore, the disjunction of the negation of the selection variables for the clauses in $\pcf{\pf}{\as_1}$ is deduced as a learnt clause to record this information.
The above idea gives rise to~\cref{alg:erssat} for solving E-MAJSAT formulas.
(\Cref{code:erssat-subsume-table,code:erssat-minimal-clauses,code:erssat-subsume-clauses,code:erssat-discard-literals} describe the clause-strengthening heuristics of the proposed algorithm, which will be discussed later.)

\begin{algorithm}[p]
    \caption{Solving exist-random quantified SSAT (E-MAJSAT) formulas}
    \label{alg:erssat}
    \begin{algorithmic}[1]
        \REQUIRE $\Qf=\exists X,\random{} Y.\pf(X,Y)$
        \ENSURE $\spb{\Qf}$
        \STATE $\select(X,S) := \bigwedge\limits_{C\in\pf}(\sv{C}\equiv\lnot\cx)\land\bigwedge\limits_{\text{pure }l: \vl{l}\in X}l$\label{code:erssat-init-select}
        \STATE $prob := 0$
        \STATE $\texttt{s-table} := \texttt{BuildSubsumptionTable}(\pf)$\label{code:erssat-subsume-table}
        \WHILE{($\sat{\select}$)}
        \STATE $\as := \model{\select}$ (discarding the selection variables)
        \IF{($\sat{\pcf{\pf}{\as}}$)}
        \STATE $\as' := \texttt{SelectMinimalClauses}(\pf,\select)$\label{code:erssat-minimal-clauses}
        \STATE $\varphi := \texttt{RemoveSubsumedClauses}(\pcf{\pf}{\as'},\texttt{s-table})$\label{code:erssat-subsume-clauses}
        \STATE $prob := \max\{prob,\texttt{ComputeWeight}(\random{} Y.\varphi)\}$\label{code:erssat-wmc}
        \STATE $C_S := \bigvee\limits_{C\in\varphi}\lnot\sv{C}$
        \STATE $C_L := \texttt{DiscardLiterals}(\pf,C_S,prob)$\label{code:erssat-discard-literals}
        \ELSE
        \STATE $C_L := \texttt{MinimalConflicting}(\pf,\as)$
        \ENDIF
        \STATE $\select := \select \land C_L$
        \ENDWHILE
        \RETURN $prob$
    \end{algorithmic}
\end{algorithm}

The algorithm employs two SAT solvers:
one works on the matrix $\pf(X,Y)$ of the input formula,
and the other works on the selection relation $\select(X,S)$ for clauses in $\pf(X,Y)$.
Using the definition of selection variables,
we initialize the selection relation and assert the literals of pure $X$ variables in~\cref{code:erssat-init-select}.
If a variable $e$ in $X$ is pure in $\pf$,
assigning the literals of $e$ to $\top$ deselects the clauses containing $e$,
and does not affect other clauses.
Because the conditional satisfying probability is greater if less clauses are selected,
we can safely assert pure $X$ variables without missing the optimal solution.

The selection relation is used to select different assignments $\as$ over $X$.
If $\pcf{\pf}{\as}$ is satisfiable,
a weighted model counter is called to compute the conditional satisfying probability $\spb{\random{} Y.\pcf{\pf}{\as}}$.
The blocking clause $C_L$ derived from the containment-learning technique is then conjoined with $\select$ to prevent clauses in $\pcf{\pf}{\as}$ from being simultaneously selected again.

On the other hand, suppose $\pcf{\pf}{\as}$ is unsatisfiable.
We can deduce a conjunction of literals from $\as$ responsible for the conflict by using a SAT solver to analyze the conflict~\cite{Een2003Solver,Een2003Incremental}.
In general, the conjunction of literals may not be minimal,
meaning that some literals can be discarded and the conflict remains unaffected.
The subroutine $\texttt{MinimalConflicting}$ makes the conjunction of literals responsible for the conflict minimal as follows.
For each literal $l$ in the conjunction,
temporarily drop $l$ and check whether $\pf(X,Y)$ is still unsatisfiable.
If it is unsatisfiable, discard $l$; otherwise, keep $l$ in the conjunction.
Repeating the above process for every literal makes the conjunction minimal.
Complementing the minimal conjunction of literals yields a learnt clause,
which is then conjoined with the selection relation to block assignments that make $\pf$ unsatisfiable.

When the selection relation becomes unsatisfiable,
it indicates that the space spanned by variables $X$ has been completely searched.
The algorithm will return the encountered maximum conditional satisfying probability,
which equals the satisfying probability of the input E-MAJSAT formula.

\begin{example}
    \label{ex:erssat-basic}
    \begin{table}[t]
        \centering
        \caption{Solving process of~\cref{alg:erssat} on~\cref{ex:erssat-basic}}
        \label{tbl:erssat-solve-example}
        \small
        \begin{tabular}{c|c|c|c|c}
            Assignment                            & Selected Clauses & $\spb{\pcf{\Qf}{\as}}$ & Learnt Clause                & LB     \\
            \hline
            $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$ & $\{C_1,C_2\}$    & $0.75$                 & $(\lnot s_1 \lor \lnot s_2)$ & $0.75$ \\
            $\as_2=\lnot e_1 e_2 \lnot e_3$       & $\{C_1\}$        & $0.75$                 & $(\lnot s_1)$                & $0.75$ \\
            $\as_3=e_1 e_2 \lnot e_3$             & $\{C_4\}$        & $0.5$                  & $(\lnot s_4)$                & $0.75$ \\
            $\as_4=e_1 e_2 e_3$                   & $\{C_3\}$        & $0.75$                 & $(\lnot s_3)$                & $0.75$ \\
            $\as_5=e_1 \lnot e_2 e_3$             & $\{\}$           & $1$                    & $()$                         & $1$
        \end{tabular}
    \end{table}

    Continuing~\cref{ex:erssat-select},
    we show how~\cref{alg:erssat} (without the clause-strengthening heuristics) solves the E-MAJSAT instance
    \begin{align*}
        \Qf=\exists e_1,\exists e_2,\exists e_3,\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pf.
    \end{align*}

    The solving process is summarized in~\cref{tbl:erssat-solve-example}.
    We first explore $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$, which selects $C_1$ and $C_2$.
    The algorithm derives $\spb{\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pcf{\pf}{\as_1}}=0.75$ by invoking a weighted model counter in~\cref{code:erssat-wmc}.
    The learnt clause $C_L=(\lnot s_1 \lor \lnot s_2)$ is conjoined with $\select$ to prevent $C_1$ and $C_2$ from being selected simultaneously again.

    Suppose the second explored assignment $\as_2$ is $\lnot e_1 e_2 \lnot e_3$,
    which selects $C_1$.
    The weighted model counter returns $\spb{\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pcf{\pf}{\as_2}}=0.75$,
    and the learnt clause $C_L=(\lnot s_1)$ is conjoined with $\select$ to prevent $C_1$ from being selected again.

    Let the third tried assignment $\as_3$ be $e_1 e_2 \lnot e_3$,
    which selects $C_4$.
    The weighted model counter gives $\spb{\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pcf{\pf}{\as_3}}=0.5$,
    and the learnt clause $C_L=(\lnot s_4)$ is conjoined with $\select$ to prevent $C_4$ from being selected again.

    Let the fourth tried assignment $\as_4$ be $e_1 e_2 e_3$,
    which selects $C_3$.
    The conditional satisfying probability $\spb{\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pcf{\pf}{\as_4}}$ equals $0.75$,
    and the learnt clause $C_L=(\lnot s_3)$ is conjoined with $\select$ to prevent $C_3$ from being selected again.

    Suppose the fifth tried assignment $\as_5$ is $e_1 \lnot e_2 e_3$,
    which deselects every clause, making $\pcf{\pf}{\as_5}=\top$ and
    $\spb{\random{0.5} r_1,\random{0.5} r_2,\random{0.5} r_3.\pcf{\pf}{\as_5}}=1$.
    Since there is no selected clause,
    the learnt clause $C_L$ is empty,
    and the selection relation becomes unsatisfiable after being conjoined with an empty clause.
    The unsatisfiability of the selection relation reveals that the space spanned by variables $X$ has been exhaustively searched,
    and the algorithm returns the satisfying probability, which equals $1$, of the E-MAJSAT instance.

    For approximate SSAT solving, suppose the procedure is forced to terminate right after $\as_3^+$ is explored.
    Although the space spanned by variables $X$ has not been fully searched yet,
    we can conclude that the satisfying probability is at least $0.75$ because $\as_1$ or $\as_2$ is a witness.
\end{example}

\subsection{Clause-strengthening heuristics}
The efficiency of~\cref{alg:erssat} is greatly affected by the strength of the learnt clauses.
We introduce three heuristics,
\textit{minimal clause selection},
\textit{clause subsumption}, and
\textit{partial assignment pruning},
to strengthen the learnt clauses deduced by the proposed learning technique.
In~\cref{alg:erssat},
the clause-strengthening heuristics are executed by subroutines
$\texttt{SelectMinimalClauses}$ (in~\cref{code:erssat-minimal-clauses}),
$\texttt{RemoveSubsumedClauses}$ (in~\cref{code:erssat-subsume-clauses}), and
$\texttt{DiscardLiterals}$ (in~\cref{code:erssat-discard-literals}),
to be detailed in the following three parts, respectively.
%Examples~\ref{ex:minimal},~\ref{ex:subsume}, and ~\ref{ex:partial} will be used to explain the three techniques.
%(Please refer to Examples~\ref{ex:minimal},~\ref{ex:subsume},~\ref{ex:partial} in the supplement.)

\subsubsection{Minimal clause selection}
As discussed before,
the selection relation $\select(X,S)$ is in charge of choosing an assignment $\as$ over variables $X$ and thus selects a set of clauses from the matrix $\pf(X,Y)$.
However, the set of selected clauses may not be minimal,
meaning that it is possible for another assignment $\as'$ to select a set of clauses contained in that selected by $\as$, i.e., $\pcf{\pf}{\as'}\subset\pcf{\pf}{\as}$.
Notice that the length of a learnt clause equals the number of selected clauses.
Therefore, selecting fewer clauses gives a stronger learnt clause,
as well as a higher conditional satisfying probability.

Starting from a set $\pcf{\pf}{\as}$ of initially selected clauses,
the first heuristic \textit{minimal clause selection} decreases the number of selected clauses by making the set of initially selected clauses minimal as follows.
A learnt clause $C_S=\bigvee\limits_{C\in\pcf{\pf}{\as}}\lnot\sv{C}$ is conjoined with the selection relation $\select(X,S)$ to avoid clauses in $\pcf{\pf}{\as}$ from being selected simultaneously again.
A SAT solver is invoked to solve $\select\land C_S$ under an assumption $\mu=\bigwedge\limits_{C\notin\pcf{\pf}{\as}}\lnot\sv{C}$.
The assumption $\mu$ prevents originally deselected clauses from being selected.
If $\select\land C_S$ under the assumption $\mu$ is satisfied by some assignment $\as'$ over $X$,
the set of clauses selected by $\as'$ must be a proper subset of that selected by $\as$.
On the other hand, if $\select\land C_S$ under the assumption $\mu$ is unsatisfiable,
then the set of selected clauses is minimal.
To make the set of initially selected clauses minimal,
the above operation is repeated until the selection relation becomes unsatisfiable.

The subroutine $\texttt{SelectMinimalClauses}$ for the technique is described in~\cref{alg:erssat-minimal}.
The following example illustrates how this technique improves the solving efficiency.

\begin{algorithm}[ht]
    \caption{Subroutine of~\cref{alg:erssat}: \texttt{SelectMinimalClauses}}
    \label{alg:erssat-minimal}
    \begin{algorithmic}[1]
        \REQUIRE The matrix $\pf(X,Y)$ and selection relation $\select(X,S)$
        \ENSURE An assignment $\as'$ that selects a minimal set of clauses from $\pf$
        \REPEAT
        \STATE $\as' := \model{\select}$ (discarding the selection variables)
        \STATE $C_S := \bigvee\limits_{C\in\pcf{\pf}{\as'}}\lnot\sv{C}$
        \STATE $\select := \select \land C_S$
        \STATE $\mu := \bigwedge\limits_{C\notin\pcf{\pf}{\as'}}\lnot\sv{C}$
        \UNTIL{($\unsat{\pcf{\select}{\mu}}$)}
        \RETURN $\as'$
    \end{algorithmic}
\end{algorithm}

\begin{example}
    \label{ex:erssat-minimal}
    Continue~\cref{ex:erssat-basic}.
    The first tried assignment $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$ selects $C_1$ and $C_2$.
    The set of selected clauses is made minimal as follows.
    The subroutine $\texttt{SelectMinimalClauses}$ conjoins the selection relation with a learnt clause $(\lnot \sv{1} \lor \lnot \sv{2})$,
    which prevents clauses $C_1$ and $C_2$ from being simultaneously selected again.
    The satisfiability of the selection relation $\select\land(\lnot \sv{1} \lor \lnot \sv{2})$ is tested under an assumption $\lnot \sv{3} \lnot \sv{4}$,
    which avoids the originally deselected clause $C_3$ and $C_4$ from being selected.
    The formula is satisfied by the assignment $\as_2=\lnot e_1 e_2 \lnot e_3$, which only selects $C_1$.
    By repeating the above operation again,
    the assignment $\as_5=e_1 \lnot e_2 e_3$ is found,
    since it selects no clause.
    The conditional satisfying probability under $\as_5$, which equals $1$,
    is derived without invoking a weighted model counter.
    Compared to~\ref{ex:erssat-basic} where five assignments over $X$ were explored,
    the algorithm with the minimal clause selection technique
    finds the optimal assignment from $\as_1$ with two additional SAT calls,
    thus greatly improves the computation efficiency.
\end{example}

\subsubsection{Clause subsumption}
The second heuristic, named \textit{clause subsumption},
decreases the length of a learnt clause via examining the subsumption relation among the selected clauses.
Recall that clause $C_1$ \textit{subsumes} clause $C_2$ if every literal appears in $C_1$ also appears in $C_2$.
Consider a CNF formula $C_1 \land C_2$ with $C_2$ subsumed by $C_1$.
It can be simplified to $C_1$ because $C_2$ is implied by $C_1$ due to the subsumption relation.

The subsumption relation among sub-clauses consisting of variables in $Y$ is constructed as a lookup table by the subroutine $\mathtt{BuildSubsumeTable}$.
The subroutine $\texttt{RemoveSubsumedClauses}$ simplifies the set $\pcf{\pf}{\as}$ of selected clauses by removing subsumed clauses.
A clause $C$ is removed from the set $\pcf{\pf}{\as}$ of selected clauses if $C^Y$ is subsumed by other selected sub-clauses.
We emphasize that, without cofactoring $\pf$ with the assignment $\as$,
the original clauses may not have the subsumption relation.
Cofactoring $\pf$ with the assignment $\as$ over variables in $X$ induces the subsumption relation between sub-clauses consisting of variables in $Y$.

The procedure $\texttt{RemoveSubsumedClauses}$ for the technique is outlined in~\cref{alg:erssat-subsume}.
It takes a set of selected clauses and a lookup table of subsumption relation as input,
and removes every subsumed clause via subroutine $\texttt{CheckNotSubsumed}$.
The following example explains how the subsumption relation shortens a learnt clause.

\begin{algorithm}[ht]
    \caption{Subroutine of~\cref{alg:erssat}: \texttt{RemoveSubsumedClauses}}
    \label{alg:erssat-subsume}
    \begin{algorithmic}[1]
        \REQUIRE The selected clauses $\pcf{\pf}{\as}$ and a subsumption table \texttt{s-table}
        \ENSURE A simplified clause set $\varphi$ without subsumed clauses
        \STATE $\varphi := \top$
        \FOR{($C\in\pcf{\pf}{\as}$)}
        \IF{($\texttt{CheckNotSubsumed}(C,\texttt{s-table})$)}
        \STATE $\varphi := \varphi \land C$
        \ENDIF
        \ENDFOR
        \RETURN $\varphi$
    \end{algorithmic}
\end{algorithm}

\begin{example}
    \label{ex:erssat-subsume}
    Continue~\cref{ex:erssat-basic}.
    Recall that the first tried assignment is $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$.
    It selects $C_1$ and $C_2$.
    Because $C_1^Y$ subsumes $C_2^Y$,
    $C_2$ is removed from $\pcf{\pf}{\as_1}$, yielding $\varphi=C_1$.
    A weighted model counter computes $\spb{\random{0.5}Y.\varphi}=0.75$,
    and the learnt clause $C_L=(\lnot \sv{1})$ is conjoined with $\select$ to prevent $C_1$ from being selected again.
    Compared to~\cref{ex:erssat-basic}, with the help of clause subsumption,
    the learnt clause $(\lnot s_1)$ deduced from $\as_1$ is stronger than its counterpart $(\lnot s_1 \lor \lnot s_2)$ in~\cref{ex:erssat-basic},
    and therefore avoids a fruitless trail of the assignment $\as_2=\lnot e_1 e_2 \lnot e_3$.
\end{example}

\subsubsection{Partial assignment pruning}
To illustrate the third heuristic \textit{partial assignment pruning},
we first take a closer look at a learnt clause deduced by the proposed clause-containment learning.
Given a matrix $\pf(X,Y)$ and an assignment $\as$ over $X$,
a learnt clause is a disjunction of the negated selection variables of the selected clauses.
For each selected clause $C$,
if the selection variable $\sv{C}$ is substituted by its definition $\sv{C}\equiv\lnot\cx$,
the learnt clause $C_L$ becomes a disjunction of the sub-clauses $\cx$,
i.e., $C_L=\bigvee\limits_{C\in\pcf{\pf}{\as}}\cx$.

For instance, in~\cref{ex:erssat-basic},
the learnt clause deduced from the assignment $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$,
which selects clauses $C_1$ and $C_2$,
is $(\lnot s_1 \lor \lnot s_2)=(e_1 \lor e_2)$,
and the current maximum satisfying probability equals $0.75$.
This learnt clause blocks two assignments, $\as_1$ and $\lnot e_1 \lnot e_2 e_3$.
The assignment $\lnot e_1 \lnot e_2 e_3$ is blocked
because it selects clauses $C_1$, $C_2$, and $C_4$,
and clauses $C_1$ and $C_2$ have been selected previously.

A learnt clause can be strengthened if some literal in the clause is discarded.
In the above example,
the learnt clause $(e_1 \lor e_2)$ can be strengthened by discarding literal $e_2$.
The resulted learnt clause $(e_1)$ blocks any assignment assigning $e_1$ to $\bot$.
To see why these assignments are blocked,
observe that assigning $e_1$ to $\bot$ selects clause $C_1$.
Although the set $\{C_1\}$ does not contain the set $\{C_1,C_2\}$,
the conditional satisfying probability is bounded from above by the probability of the sub-clause $(r_1 \lor r_2)$,
which equals $0.75$.
Since the current maximum satisfying probability equals $0.75$ already,
it is fruitless to explore assignments whose conditional satisfying probabilities are no greater than $0.75$. Therefore, $e_1$ is forced to be $\top$.

On the other hand,
literal $e_1$ cannot be discarded from the learnt clause $(e_1 \lor e_2)$.
If $e_1$ is discarded,
the resulted learnt clause $(e_2)$ blocks any assignment assigning $e_2$ to $\bot$.
However, assigning $e_2$ to $\bot$ selects no clause,
and hence the upper bound of the conditional satisfying probability equals $1$.
Since $1$ is greater than the current maximum satisfying probability $0.75$,
we have to explore assignments that map $e_2$ to $\bot$.
In fact, there exists an assignment $e_1 \lnot e_2 \lnot e_3$ whose conditional satisfying probability equals $1$,
greater than the current maximum satisfying probability.
As a result, $e_1$ cannot be discarded.

From the above illustration,
we observe that a learnt clause can be strengthened as follows.
First, temporarily discard some literal $l$ from a learnt clause.
Second, invoke a weighted model counter to compute the conditional satisfying probability contributed by the selected clauses.
Third, compare the probability to the current maximum satisfying probability.
If the probability is no greater, discard literal $l$;
otherwise, keep $l$ in the learnt clause.
Fourth, repeat the above steps for other literals.

The subroutine $\texttt{DiscardLiterals}$ for the technique to discard literals from a learnt clause is outlined in~\cref{alg:erssat-partial}.
It substitutes selection variables in a learnt clause $C_S$ by their definitions in~\cref{code:erssat-partial-replace}.
Then it iterates through each literal $l \in C_L$ and invokes a weighted model counter to check whether literal $l$ can be discarded in~\crefrange{code:erssat-partial-drop-start}{code:erssat-partial-drop-end}.
Notice that the current maximum satisfying probability is \textit{not} updated by the value obtained by weighted model counting,
because the value only reflects an upper bound for satisfying probabilities under the partial assignment $\nu$.

\begin{algorithm}[ht]
    \caption{Subroutine of~\cref{alg:erssat}: \texttt{DiscardLiterals}}
    \label{alg:erssat-partial}
    \begin{algorithmic}[1]
        \REQUIRE The matrix $\phi$, a learnt clause $C_S$, and the current maximum $prob$
        \ENSURE A strengthened learnt clause $C_L$
        \STATE $C_L := \bigvee\limits_{\sv{C}\in C_S}\cx$\label{code:erssat-partial-replace}
        \FOR{($l\in C_L$)}\label{code:erssat-partial-drop-start}
        \STATE $\nu := \bigwedge\limits_{k\in C_L\setminus\{l\}}\lnot k$
        \IF{($\texttt{ComputeWeight}(\random{}Y.\pcf{\pf}{\nu})\leq prob$)}
        \STATE $C_L := C_L \setminus \{l\}$\label{code:erssat-partial-drop-end}
        \ENDIF
        \ENDFOR
        \RETURN $C_L$
    \end{algorithmic}
\end{algorithm}

\begin{example}
    \label{ex:erssat-partial}
    Continue~\cref{ex:erssat-basic}.
    As discussed above, the learnt clause $(e_1 \lor e_2)$ deduced from the assignment $\as_1=\lnot e_1 \lnot e_2 \lnot e_3$ is strengthen to $(e_1)$ by the partial assignment pruning technique,
    and thus prevents a fruitless trail of the assignment $\as_2=\lnot e_1 e_2 \lnot e_3$.
\end{example}

To summarize, the above three clause-strengthening heuristics are designed based on different reasoning strategies:
the minimal clause selection technique strengthens the learnt clause by invoking additional SAT calls to solve the selection relation to select a minimal set of clauses;
the clause subsumption technique builds a lookup table to record the subsumption relation and removes subsumed clauses;
the partial assignment pruning technique utilizes the current maximum conditional satisfying probability,
and invokes extra calls to a weighted model counter to test whether it is feasible to discard some literal in a learnt clause.
Benefiting from the three clause-strengthening heuristics,
the efficiency of the proposed algorithm is improved over certain formulas,
as will be shown in our experiments.

We emphasize two more strengths of the proposed algorithm.
First, during the computation,
the proposed algorithm keeps deriving lower bounds for the satisfying probability,
and the bounds gradually converge to the final answer.
Therefore, in contrast to previous DPLL-based methods~\cite{Majercik1998,Majercik2003,Majercik2005},
the proposed algorithm can be easily modified to solve \textit{approximate SSAT} by returning the greatest encountered lower bound upon timeout, as explained in~\cref{ex:erssat-basic}.
Second, the proposed algorithm is efficient in memory usage,
since it stores the learnt information compactly via selection variables,
and the weighted model counting is invoked on selected clauses,
whose sizes are typically much smaller than that of the original matrix.

\subsection{Implementation details}
We discuss some details about our implementation of the proposed algorithm.
\Cref{alg:erssat} involves satisfiability testing and weighted model counting.
In principle, any SAT solver and exact weighted model counter can be plugged into the procedure.
Therefore, \cref{alg:erssat} may benefit directly from the advancement of SAT solving and model counting.

Specifically in our implementation,
we adopt \texttt{Minisat-2.2}~\cite{Een2003Solver} for SAT solving.
We experimented with \cachet~\cite{Sang2004,Sang2005ModelCounting} for weighted model counting,
but the overall performance was not satisfactory.
Because the clauses selected by different assignments typically share a portion of identical sub-formulas,
the results of these sub-formulas should be cached to avoid repeated computations.
Ideally, this improvement can be achieved by tightly integrating \cachet into our implementation,
instead of treating it as a black box.
However, we resort to \textit{binary decision diagram} (BDD) for our weighted model counting to achieve the \textit{formula caching} effect.

The selected clauses in a formula are first transformed into a two-level circuit by \disjoin-ing literals in each clause and \conjoin-ing the outputs of each \disjoin gate.
A BDD is then constructed based on the resultant circuit.
Weighted model counting of the original formula is done by traversing the BDD~\cite{Darwiche2002KnowledgeCompilation}.
We use the well-developed BDD package \cudd~\cite{CUDD},
which caches BDD nodes during building BDDs for different formulas.
Thus the formula caching effect as well as garbage collection,
which removes unreferenced nodes, is automatically achieved by \cudd.

Our implementation was integrated in the \abc~\cite{ABC} environment,
which provides all the facilities including SAT solving, circuit construction, and BDD computation mentioned above.


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Thursday\\ 2020-5-7, \\ compiled \\ \today}

Using the decaying mode is a mathematical trick.

\todo[inline]{Understand this better.}

As we saw last time, the length in \(\nu \) can be interpreted as the thickness of the pancakes.

We have gotten an equation with no nonlinear terms: the Fokker-Planck equation,
%
\begin{align}
\pdv{U}{\tau } = \nu \nabla^2 U
\,.
\end{align}

If we change \(\tau \) to \(i \tau \), this is the Schrödinger equation.
We solve it by separation of variables.

In Fourier space, we get
%
\begin{align}
E_{k} g_{\vec{k}} = - \nu k^2 g_{\vec{k}}
\,.
\end{align}

This is a linear ODE, a general solution will be a superposition of eigenstates:
%
\begin{align}
U(\vec{x}, \tau ) = \int \frac{\dd[3]{k}}{(2 \pi )^3} e^{- \nu k^2 \tau } g_{\vec{k}} e^{i \vec{k} \cdot \vec{x}}
\,,
\end{align}
%
and we just need to impose boundary conditions.

We look at the kernel: the ``impulse response'' of our function.
We call it
%
\begin{align}
K ( \hat{x}, \tau | \hat{q}, 0)
\,,
\end{align}
%
which is indeed a conditional probability amplitude: as \(\tau \to 0\) it approaches \(\delta (\hat{x} - \hat{q})\).

This is a probability, not a probability amplitude.

We can integrate to find it: it is
%
\begin{align}
K (\hat{x}, \tau | \hat{q}, 0) = \qty(4 \pi \nu \tau )^{-3/2} \exp( -\frac{(\hat{x} - \hat{q})}{4 \nu \tau })
\,.
\end{align}

We find this by marginalizing.

This yields an equation which is basically the Hamilton-Jacobi one,
%
\begin{align}
\pdv{S}{\tau } + \frac{1}{2} \qty(\nabla S)^2 = 0
\,.
\end{align}

This yields an expression for the full (Eulerian) velocity.
We are interested in the limit \(\nu \to 0 \). Only the minima of the action matter, and we can perform Gaussian integrals. We expand \(S\) around the absolute minima: we find
%
\begin{subequations}
\begin{align}
U(\hat{x}, \tau ) &= (4 \pi \nu \tau )^{-3/2} e^{-S / 2 \nu }
\int \dd[3]{ \delta q} \exp(- \frac{1}{4 \nu } \pdv[2]{S}{q_{i} q^{j} \delta q^{i} \delta q_{j}})  \\
&= \det \dots
\,.
\end{align}
\end{subequations}

So, we are saying that the velocity is given by
%
\begin{align}
\vec{u} (\vec{x}, \tau ) = \sum _{s} \frac{\vec{x} - \vec{q}_{s}}{\tau } w_{s} (\vec{x}, \vec{q}, \tau )
\,.
\end{align}

It is a superposition of different solutions, weighted by the \(w_{s}\).

\section{Schrödinger equation approach for LSS formation}

Madelung proposed a hydrodynamical approach to QM: a decomposition
%
\begin{align}
\psi (\vec{x}, t) = R (\vec{x}, t) e^{- \frac{S(\vec{x},t)}{i \hbar}}
\,,
\end{align}
%
which we can substitute into the Schrödinger equation
%
\begin{align}
i \pdv{\psi }{t} = - \frac{\nabla^2}{2m} \psi + V \psi
\,,
\end{align}
%
which yields two separate equations for the real and imaginary parts: we get
%
\begin{align}
- \nabla \qty( \frac{R^2}{2m} \nabla S) = \pdv{}{t} R^2
\,,
\end{align}
%
so if we define the usual probability current
%
\begin{align}
j = \frac{\hbar}{2 m i} \qty(\psi^{*} \nabla \psi - \psi \nabla \psi^{*}) = \frac{R^2}{2m} \nabla S
\,,
\end{align}
%
so we get the equation
%
\begin{align}
\pdv{\rho }{t} + \nabla \cdot \qty(\rho \vec{v}) = 0
\,
\end{align}
%
for the imaginary part of the equation.

For the real part of the equation, instead, we find
%
\begin{align}
\pdv{S}{t} + \frac{1}{2m} \qty(\nabla S)^2 = - (V + Q )
\,,
\end{align}
%
where
%
\begin{align}
Q ( \vec{x}, t) = - \frac{\hbar^2}{2m} \frac{1}{R} \nabla^2 R
\,
\end{align}
%
a part we must include in the potential to account for quantum effects.
This is the effectively the Bernoulli equation!

After the Madelung transformation, then, we get hydrodynamic equations.
We cna also do this backward: we start from the Bernoulli equation and continuity:
%
\begin{subequations}
\begin{align}
\pdv{\rho }{t} + \nabla \cdot \qty(\rho \vec{v}) &= 0  \\
\pdv{\phi }{t} + \frac{1}{2} \qty(\nabla \phi )^2 &= -V
\,,
\end{align}
\end{subequations}
%
and associate it with Schrödinger, using \(\nu \) instead of \(\hbar\).
We then get Schrödinger, with a different potential:
%
\begin{align}
i \nu \pdv{\Psi }{t} = - \frac{\nu^2}{2 } \nabla^2 \Psi + \qty(V + \frac{\nu^2}{2} \frac{\nabla^2 R}{R}) \Psi
\,.
\end{align}

We apply this procedure in cosmology: we get
%
\begin{subequations}
\begin{align}
\pdv{\eta }{\tau } + \nabla \cdot \qty(\eta \vec{u}) = 0   \\
\pdv{\Phi  }{\tau } + \frac{1}{2} \qty(\nabla \Phi )^2 &= - \frac{3}{2 \tau } \qty(\Phi + \varphi )  \\
\nabla^2 \varphi &= \frac{\delta}{\tau }
\,.
\end{align}
\end{subequations}

\end{document}


% Lecture for ph2a Caltech 2017: Vibrations and Waves
\documentclass[pdf,hideothersubsections]{beamer}
\usepackage{beamerthemeshadow}
\mode<presentation>
  {
    \usefonttheme{structuresmallcapsserif}
    \usetheme{CambridgeUS}
    \usecolortheme{seahorse}

  }

\usepackage{svg}
\usepackage{xmpmulti}

\usepackage{hyperref}
\hypersetup{
    pdffitwindow=true,     % window fit to page when opened
    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=orange,          % color of internal links (change box color with linkbordercolor)
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=blue           % color of external links
}

% Fonts/encoding
\renewcommand{\UrlFont}{\tiny}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[sc,medium,raggedright]{titlesec}
\usepackage{newtxmath}
%\usepackage{libertine}
\usepackage[osf]{ebgaramond}

\graphicspath{{Figures/}}

\begin{document}
\title{Periodic Motion}
\author{Caltech: ph2a}
\date{26 - Sep - 2017}
%\logo{\includegraphics[height=0.5cm]{../caltech_logo.png}}

\frame{\titlepage}

\frame{\frametitle{Table of contents}\tableofcontents}

\setbeamerfont{footnote}{size=\tiny}

\section{Class Overview}
\frame{\frametitle{Overview}
\begin{enumerate}
\item All info on class website\footnotemark
\item Lectures are Tuesday and Thursday
\item try out different sections; problems solving is key!
\item Use piazza for group chat / anon discussions, feedback
\item HWK due every Wed. Quizzes every other Tuesday. Final in Dec.

\end{enumerate}

\footnotetext[1]{\url{https://piazza.com/caltech/fall2017/ph2a}}
}

\section{Simple Harmonic Oscillator}
\frame{\frametitle{The Simple Harmonic Oscillator}
\includegraphics[height=3cm]{Mass-spring-system.png}

\begin{itemize}
\item Covered in ph1a (mass-spring, pendulums) \pause
\item Covered in ph1b/c (RLC Circuits) \pause
\item Extremely useful in engineering / sciences \pause
\item ``Just'' the study of 2$^{nd}$ order differential equations
\end{itemize}

}

\subsection{Demo: Ball on Spring}
\begin{frame}
\frametitle{Interactive Demo}
\centering
\includegraphics[height=3cm]{2015416-94550395-2754-sshm.png}
\begin{itemize}
\item \url{https://phet.colorado.edu/en/simulation/mass-spring-lab}
\item \url{http://demonstrations.wolfram.com/DrivenDampedOscillator/}
\item \url{http://demonstrations.wolfram.com/SimpleHarmonicMotionForASpring/}
\end{itemize}
\end{frame}

\subsection{General Solution}
\frame{\frametitle{Harmonic Oscillator Equations}
\centering
\includegraphics[height = 4cm]{Hookeslawb.png} \\ \pause
\begin{align*}
  \onslide<1->{F &= m \frac{d^2x}{dt^2} \\}
  \onslide<2->{- k x &= m \ddot{x}}
\end{align*}
}

\frame{\frametitle{Solution I:}
The Diff Eq we want to solve (for x(t)): $- k x = m \ddot{x}$
\pause
\begin{align*}
  \onslide<2->{x(t) &= A cos(\omega t) + B sin(\omega t) \\}
  \onslide<3->{\frac{dx}{dt} &= -\omega A sin(\omega t) + \omega B cos(\omega t) \\}
  \onslide<4->{\frac{d^2x}{dt^2} &= -\omega^2 \left[A cos(\omega t) + B sin(\omega t)\right] \\}
                    \onslide<5->{&= -\omega^2 x(t)}
\end{align*}

\onslide<5->{Therefore, $\omega = \sqrt{k/m}$. Define $\omega_0 \equiv \sqrt{k/m}$}

}

\frame{\frametitle{Solution II:}
Use a phase shift in the cosine instead of sine and cosine:
\pause
\begin{align*}
  \onslide<2->{x(t) &= D~cos(\omega t + \phi_0) \\}
  \onslide<3->{\frac{dx}{dt} &= -\omega D sin(\omega t + \phi_0) \\}
  \onslide<4->{\frac{d^2x}{dt^2} &= -\omega^2 D cos(\omega t + \phi_0) \\}
                 \onslide<4->{&= -\omega^2 x(t)}
\end{align*}
}

\frame{\frametitle{Boundary Conditions}
In both cases, there are two free constants (A \& B, or D \& $\phi_0$). \\
\pause
These constants are set to force the solution to match any 'Boundary' conditions: \pause
\begin{itemize}
\item initial displacement \pause
\item initial velocity \pause
\item e.g., mass is released at t=0 with x = x$_0$
\end{itemize}

}

\subsection{Damping / Friction}
\frame{\frametitle{SHO + Damping}
What about adding some frictional damping?
\pause
\begin{itemize}
\item Friction = force proportional to velocity
\pause
\item Mechanical: $m \ddot{x} + b \dot{x} + k x = 0$
\pause
\item Electrical (demo): $L \ddot{q} + R \dot{q} + (1/C) q = 0$
\end{itemize}
\pause

\begin{block}{Damping}
Resistance is the electrical equivalent of friction.
\end{block}

\pause
\centering
\includegraphics[width=5cm]{damped_sine_wave.pdf}
}

\section{Differential Equations}
\subsection{Types}
\frame{\frametitle{Types of Diff. Eq.}
\centering
\begin{tabular}{l|c|c|c|}
\hline
Name/Type  & \textbf{Variables} & \textbf{Order} & \textbf{Linearity} \\
\hline \pause
Ordinary & 1 & 1+ & Yes  \\
\hline \pause
Partial & 2+ & 1+ & Yes ? \\
\hline \pause
Linear & 1+ & 1+ & Yes \\
\hline \pause
Non-Linear & 1+ & 1+ & No \\
\hline
\end{tabular}
}

\frame{\frametitle{Diff Eq Examples}
\begin{block}{Harmonic Oscillator: Damped mass on spring}
a \emph{linear}, 2$^{nd}$ order, ordinary differential equation \\
$m \ddot{x} + b \dot{x} + k x = 0$
\end{block}
\pause
\begin{exampleblock}{Harmonic Oscillator: RLC Circuit}
a \emph{linear}, 2$^{nd}$ order, ordinary differential equation \\
$L \ddot{q} + R \dot{q} + (1/C) q = 0$
\end{exampleblock}
\pause
\begin{alertblock}{Driven Harmonic Oscillator}
a \emph{linear}, 2$^{nd}$ order, ordinary differential equation \\
$m \ddot{x} + b \dot{x} + k x =  F_0 sin(\omega t)$
\end{alertblock}

}

\section{Harmonic Oscillator + Complex Math}
\subsection{Complex Numbers}
\frame{\frametitle{Complex Numbers}
\begin{itemize}
\item See \href{https://piazza.com/caltech/fall2017/ph2a/resources}{Handout} on complex numbers on course website.
\pause
\item Differing notations: $i = \sqrt{-1}$ or $(j = \sqrt{-1})$
\pause
\item Complex Variables:
\end{itemize}
\pause

\begin{align*}
  \onslide<3->{\tilde{z} &= x + i y \\}
  \onslide<4->{        &= Re\left\{\tilde{z}\right\} + i\,Im\left\{\tilde{z}\right\} \\}
  \onslide<5->{\tilde{z}^{*} &= x - i y (\rm complex~conjugate)}
\end{align*}

\begin{align*}
  \onslide<6->{|\tilde{z}|^2 &= \tilde{z}^{*}\tilde{z} \\}
  \onslide<7->{              &= (x + i y)(x - i y) \\}
  \onslide<8->{              &= x^2 + y^2 }
\end{align*}
}

\subsection{Euler's Formula}
\begin{frame}
\frametitle{Euler's Formula}

\begin{block}{\href{http://mathworld.wolfram.com/EulerFormula.html}{Euler's Formula}}
$e^{i \phi} = \cos{\phi} + \mathrm{i} \sin{\phi}$
\end{block}
\pause
\includegraphics[width=3cm]{Euler-formula.png}
\pause
\begin{itemize}
\item $|e^{i \phi}| = 1$
\pause
\item $1 + e^{i \pi} = 0$
\end{itemize}

Mesmerizing GIF: \url{http://i.imgur.com/BI1zPwO.gif}

\end{frame}

\subsection{Complex Solutions to SHO}
\begin{frame}
\frametitle{Complex Solutions}
\begin{itemize}
\item Complex exponentials make D.E. solving much easier
\pause
\item Actual displacement is not imaginary; this is book-keeping
\pause
\end{itemize}
Guess: $\tilde{x}(t) = A e^{i (\omega t + \phi_0)}$ \\
\pause
$\ddot{x} = -(k/m) x$ \\
\pause
$\dot{x} = i \omega x$ \\
\pause
$\ddot{x} = -\omega^2 x$ \\
Plug in the guess into the differential equation:
\begin{align*}
-\omega^2 x &= (-k/m) x \\
\omega &= \sqrt{k/m} \\
x(t) &= A e^{i (\sqrt{k/m} t + \phi_0)}
\end{align*}
\pause
Taking the real part, we get: \\
\pause
$x(t) = Re\left\{\tilde{x}(t)\right\} = A cos(\omega t + \phi_o)$

\end{frame}

\section{Damped Harmonic Oscillator}
\begin{frame}
\frametitle{Complex approach to damped SHO}
Use the same approach as before:
\begin{itemize}
\item $m \ddot{x} + b \dot{x} + k x = 0$
\pause
\item $\tilde{x}(t) = A e^{i (\omega t + \phi_0)}$
\pause
\item $-m \omega^2 \tilde{x} + i \omega b \tilde{x} + k \tilde{x} = 0$
\end{itemize}
\pause
Dividing by $m$, we get a quadratic equation for $\omega$: \\
\pause
$\omega = \sqrt{\omega_0^2 - (\frac{b}{2 m})^2} + i \frac{b}{2 m}$ \\
\pause
Let's call the real part $\omega$ and plug back into the guess for x(t):
\pause
$\tilde{x} = A e^{i (\omega t + \phi_0)} e^{-(b/2 m) t}$\\
\pause
Taking the real part, we find there is an oscillatory component multiplied by a decaying exponential (the damping): \\
\pause
$Re\left\{\tilde{x}\right\} = x = A \cos(\omega t + \phi_o) e^{-(b/2 m) t}$

\end{frame}

\begin{frame}
\frametitle{Decaying Oscillation}

\centering
\includegraphics[width=8cm]{damped_sine_wave.pdf}

\end{frame}

\section{Summary}
\begin{frame}
\frametitle{Summary}
\begin{itemize}
\item Many physical systems involving small vibrations can be represented as a Simple Harmonic Oscillator.
\pause
\item Complex exponentials can be used to solve oscillator problems.
\pause
\item Guess solutions; set constants by setting (Dirichlet, Neumann, Cauchy) boundary conditions.
\pause
\item Imaginary part of the complex frequency corresponds to damping.
\end{itemize}
\end{frame}

\end{document}


\section{Broadcast}
\label{sec:prop-pres-case-studies:broadcast}
Broadcast is a system of fifteen processes communicating via three-party broadcast, i.e.\ three processes at a time synchronize simultaneously.
Figure~\ref{fig:prop-pres-case-studies:broadcast-network} shows two pairs of three such processes.
For each group of three processes, there is a synchronization rule that states that actions \action{a1}, \action{a2}, and \action{a3} synchronize.

\begin{figure}[hbt]
\centering
\includegraphics[scale=0.18]{prop-pres-case-studies/figs/broadcast-network}
\caption{Groups of three processes that communicate via broadcast}
\label{fig:prop-pres-case-studies:broadcast-network}
\end{figure}

Due to restrictions imposed by an implementation platform, a transformation that breaks this down into a series of two-party synchronization might be desired.
Three transformation rules that refine a model in this way are shown in Figure~\ref{fig:prop-pres-case-studies:faulty-broadcast-rules}.
After transformation, new synchronization rules are introduced that define that \action{a1'} and \action{a2'}, and  \action{a2''} and \action{a3'} synchronize.
This naive refinement does not preserve properties.

\begin{figure}[hbt]
\centering
\includegraphics[scale=0.2]{prop-pres-case-studies/figs/faulty-broadcast-rules}
\caption{Transformation rules that replace a three-party broadcast by pairwise communication}
\label{fig:prop-pres-case-studies:faulty-broadcast-rules}
\end{figure}

Improved versions of these transformation rules are shown in Figure~\ref{fig:prop-pres-case-studies:broadcast-rules}.
Actions~\action{a2} and \action{a3} are replaced by \action{a2'} and \action{a3'}, respectively, to make the rule system terminating and confluent.
After transformation, new synchronization rules are introduced that define that
\begin{itemize*}
\item \action{m1a1} and \action{m2a1},
\item \action{c1a1} and \action{c2a1},
\item \action{a1a1} and \action{a2a1}, and
\item \action{a2'} and \action{a3'}
\end{itemize*}
synchronize.
The dashed $\tau$-transitions in Figure~\ref{fig:prop-pres-case-studies:broadcast-rules} indicate that this transformation is only property preserving if state~$i$ is matched on states that are diverging.

\begin{figure}[hbt]
\centering
\includegraphics[scale=0.2]{prop-pres-case-studies/figs/broadcast-rules}
\caption{Three improved transformation rules that replace a three-party broadcast by pairwise communication}
\label{fig:prop-pres-case-studies:broadcast-rules}
\end{figure}

To check whether the transformation rules of Figure~\ref{fig:prop-pres-case-studies:broadcast-rules} preserve properties, a number of checks have to be performed.
Figure~\ref{fig:prop-pres-case-studies:broadcast-lhs} show some of the LTSs that are used for these checks.
The LTSs in Figure~\ref{fig:prop-pres-case-studies:broadcast-lhs} are created from the left-hand sides of the three transformation rules in Figure~\ref{fig:prop-pres-case-studies:broadcast-rules}.
The tools \EXPOPEN and \ltscompare of the \mCRLTwo toolkit cannot handle LTSs with multiple initial states.
To be able to use these tools to perform the checks, one initial state is added to each of the LTSs, as well as $\tau$-transitions to the original initial states.
Figure~\ref{fig:prop-pres-case-studies:broadcast-lhs} also show the $\kappa$-loops that are added to the original initial states.
Each of the checks determines whether a network consisting of a combination of LTSs created from the left-hand sides of transformation rules is divergence-sensitive branching bisimilar with the network consisting of the corresponding LTSs created from the right-hand sides, after hiding the appropriate actions in both networks.

\begin{figure}[hbt]
  \begin{minipage}[b]{4cm}
    \centering
    \includegraphics[scale=0.2]{prop-pres-case-studies/figs/broadcast-rule1-lhs}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{4cm}
    \centering
    \includegraphics[scale=0.2]{prop-pres-case-studies/figs/broadcast-rule2-lhs}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{4cm}
    \centering
    \includegraphics[scale=0.2]{prop-pres-case-studies/figs/broadcast-rule3-lhs}
  \end{minipage}
  \caption{Process LTSs of the left-hand sides of the transformation rules in Figure~\ref{fig:prop-pres-case-studies:broadcast-rules}}
  \label{fig:prop-pres-case-studies:broadcast-lhs}
\end{figure}


%!TEX program = xelatex
\documentclass[times,namecite]{goose-article}

\title{%
  ElastoPlasticQPot -- An implementation for an elasto-plastic continuum model based on a manifold of quadratic potentials
}

\author{T.W.J.~de~Geus}

\contact{%
  $^*$Contact: %
  \href{mailto:tom@geus.me}{tom@geus.me} %
  \hspace{1mm}--\hspace{1mm} %
  \href{http://www.geus.me}{www.geus.me}%
  \hspace{1mm}--\hspace{1mm} %
  \href{https://github.com/tdegeus/ElastoPlasticQPot}{https://github.com/tdegeus/ElastoPlasticQPot}%
}

\hypersetup{pdfauthor={T.W.J. de Geus}}

\header{%
  \href{https://github.com/tdegeus/ElastoPlasticQPot}{ElastoPlasticQPot} -- \href{http://www.geus.me}{T.W.J.\ de Geus}%
}

\newcommand\leftstar[1]{\hspace*{-.3em}~^\star\!#1}

\newcommand\T[1]{\underline{\bm{{#1}}}}

\newcommand\TT[1]{\underline{\mathbb{{#1}}}}

\begin{document}

\maketitle

\begin{abstract}
A microscopic continuum model of plasticity in amorphous solids is proposed. This model uses a strain energy with multiple minima to capture the effect of plasticity. This model is inspired on the work of \citet{Jagla2017}.
\end{abstract}

\keywords{elasto-plasticity; linear elasticity}

\setcounter{tocdepth}{3}
\tableofcontents

\vfill\newpage
\section{General model}

The model is constructed such that it behaves linear elastically in the volumetric stress response. The same holds for the deviatoric stress response, whereby plasticity is modelled such that the material starts flowing once a critical strain is reached. After a period of flow, the deviatoric stress response is again linear elastic.

Below underlined bold symbols $\T{A}$ are tensors, while normal symbols $A$ are scalars. Strains are denoted by $\varepsilon$ while stresses are denoted by $\sigma$. Subscripts $(.)_\mathrm{m}$ and $(.)_\mathrm{d}$ are used to indicate the volumetric and deviatoric part of the strains and stress. Furthermore, the elastic moduli and the equivalent stress and strain are defined such (i) that the model is equivalent regardless of the number of dimensions, $d$; (ii) for simple shear the equivalent deviatoric strain is equal to $\varepsilon_\mathrm{xy}$; (iii) $\sigma_\mathrm{xy} = G \varepsilon_\mathrm{xy}$, with $G$ the shear modulus. To retrieve another common definition for linear elasticity in $d = 3$, one simply has to rescale the parameters. See the appendices for the full nomenclature, including the parameter transformation.

The model is based on a strain energy $W$ that is composed of two parts, a hydrostatic (or volumetric) part $U$ related to the hydrostatic strain $\varepsilon_\mathrm{m}$, and a deviatoric (or shear) part $V$ related to the equivalent shear strain $\varepsilon_\mathrm{d}$, i.e.\
\begin{equation}
  W ( \T{\varepsilon} ) = U ( \varepsilon_\mathrm{m} ) + V ( \varepsilon_\mathrm{d} )
\end{equation}
The stress response $\T{\sigma}$ is the derivative of this energy with respect to the strain tensor $\T{\varepsilon}$. Before specialising $U$ and $V$ we can already say that
\begin{equation}\label{eq:dU-dV:elas}
  \T{\sigma}
  =
  \frac{\partial W}{\partial \T{\varepsilon}}
  =
  \frac{\partial U}{\partial \varepsilon_\mathrm{m}} \;
  \frac{\partial \varepsilon_\mathrm{m}}{\partial \T{\varepsilon}}
  +
  \frac{\partial V}{\partial \varepsilon_\mathrm{d}} \;
  \frac{\partial \varepsilon_\mathrm{d}}{\partial \T{\varepsilon}}
  =
  \frac{\partial U}{\partial \varepsilon_\mathrm{m}} \;
  \frac{1}{d} \T{I}
  +
  \frac{\partial V}{\partial \varepsilon_\mathrm{d}} \;
  \frac{1}{2} \frac{\T{\varepsilon}_\mathrm{d}}{\varepsilon_\mathrm{d}}
  =
  \frac{1}{d} \;
  \frac{\partial U}{\partial \varepsilon_\mathrm{m}} \;
  \T{I}
  +
  \frac{1}{2}
  \frac{\partial V}{\partial \varepsilon_\mathrm{d}} \;
  \T{N}_\mathrm{d}
\end{equation}
Below, both $U(\varepsilon_\mathrm{m})$ and $V(\varepsilon_\mathrm{d})$ will be defined by slowly increasing complexity, departing from linear elasticity.

\subsection{Linear elasticity}

We start simple by considering linear elasticity. In this case the volumetric strain energy $U$ and the shear strain energy $V$ read
\begin{equation}\label{eq:W:elas}
  U ( \varepsilon_\mathrm{m}  ) = \frac{d}{2} \, K \, \varepsilon_\mathrm{m}^2
  \;, \qquad
  V ( \varepsilon_\mathrm{d} ) = G \, \varepsilon_\mathrm{d}^2
\end{equation}
The two potentials are plotted in Fig.~\ref{fig:U-V:elas} (only $\varepsilon_\mathrm{d} \geq 0$ is shown, as it is by definition non-negative). It is trivial to obtain that
\begin{equation}
  \frac{\partial U}{\partial \varepsilon_\mathrm{m}}
  =
  d \, K \, \varepsilon_\mathrm{m}
  \;, \qquad
  \frac{\partial V}{\partial \varepsilon_\mathrm{d}}
  =
  2 \, G \, \varepsilon_\mathrm{d}
\end{equation}
(plotted in Fig.~\ref{fig:dU-dV:elas}). From which we obtain the following expression for the stress
\begin{equation}\label{eq:sig-elas}
  \T{\sigma} ( \T{\varepsilon} )
  =
  K \, \varepsilon_\mathrm{m} \, \T{I}
  +
  G \, \varepsilon_\mathrm{d} \, \T{N}_\mathrm{d}
  =
  K \, \varepsilon_\mathrm{m} \, \T{I}
  +
  G \, \T{\varepsilon}_\mathrm{d}
\end{equation}
where the direction of shear is contained in
\begin{equation}
  \T{N}_\mathrm{d} \equiv \frac{\T{\varepsilon}_\mathrm{d}}{\varepsilon_\mathrm{d}}
\end{equation}
Note that
\begin{equation}
  \sqrt{ \tfrac{1}{2} \T{N}_\mathrm{d} : \T{N}_\mathrm{d} } = 1,
  \qquad
  \frac{\partial \varepsilon_\mathrm{d}}{\partial \T{\varepsilon}_\mathrm{d}} = \tfrac{1}{2} \T{N}_\mathrm{d}
\end{equation}
(see Appendix~\ref{sec:nomenclature:derivatives}).

\begin{figure}[htp]
  \centering
  \includegraphics[width=1.\textwidth]{figures/potential_U-V_elas}
  \caption{Strain energy $W ( \T{\varepsilon} ) = U ( \varepsilon_\mathrm{m} ) + V ( \varepsilon_\mathrm{d} )$ for linear elasticity.}
  \label{fig:U-V:elas}
\end{figure}

\begin{figure}[htp]
  \centering
  \includegraphics[width=1.\textwidth]{figures/potential_dU-dV_elas}
  \caption{Derivative of the hydrostatic strain energy $U$ and the deviatoric strain energy $V$ w.r.t.\ respectively the hydrostatic strain $\varepsilon_\mathrm{m}$ and the equivalent shear strain $\varepsilon_\mathrm{d}$.}
  \label{fig:dU-dV:elas}
\end{figure}

\subsection{Plastic potential -- Parabolic potential with multiple minima}

The model is now extended to account for plasticity. The model is defined such that the material responds volumetrically purely elastic, while in shear the model is governed by multiple minima. These minima have the effect that when the material reaches a certain yield stress, it jumps to the next minimum. Around this minimum the elasticity is always the same. When loading is continued the the material again jumps to a new minimum when the next yield stress is reached. The magnitude of the jumps and of the yield stress are thereby related.

As described, the volumetric behaviour is simply elastic; whereby the potential is given by Eq.~(\ref{eq:W:elas}a) and is plotted in Fig.~\ref{fig:U-V:elas}(a). To attain the desired behaviour in shear, the equivalent shear strain space is divided in a finite number of yield strains $\varepsilon_\mathrm{y}^{(0)}, \varepsilon_\mathrm{y}^{(1)}, \varepsilon_\mathrm{y}^{(2)}, ...$. A parabolic potential is then defined between each pair ($[ \varepsilon_\mathrm{y}^{(0)}, \varepsilon_\mathrm{y}^{(1)} )$, $[ \varepsilon_\mathrm{y}^{(1)}, \varepsilon_\mathrm{y}^{(2)} )$, ...).

The shear strain energy is then composed of a manifold of quadratic contributions
\begin{equation}\label{eq:V-plas}
  V \big(
    \varepsilon_\mathrm{y}^{(i)} \leq \varepsilon_\mathrm{d} < \varepsilon_\mathrm{y}^{(i+1)}
  \big)
  =
  V^{(i)}
  =
  G \, \bigg[\,
    \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]^2
    -
    \Big[\, \Delta \varepsilon_\mathrm{y}^{(i)} \,\Big]^2
  \,\bigg]
\end{equation}
where the mean of $\varepsilon_\mathrm{y}^{(i)}$ and $\varepsilon_\mathrm{y}^{(i+1)}$ is
\begin{equation}
  \varepsilon_\mathrm{min}^{(i)}
  =
  \tfrac{1}{2} \Big[\, \varepsilon_\mathrm{y}^{(i+1)} + \varepsilon_\mathrm{y}^{(i)} \,\Big]
\end{equation}
which is also the equivalent shear strain at which the shear strain energy reaches its minimum. From this minimum, the distance to $\varepsilon_\mathrm{y}^{(i)}$ and $\varepsilon_\mathrm{y}^{(i+1)}$ is
\begin{equation}
  \Delta \varepsilon_\mathrm{y}^{(i)}
  =
  \tfrac{1}{2} \Big[\, \varepsilon_\mathrm{y}^{(i+1)} - \varepsilon_\mathrm{y}^{(i)} \,\Big]
\end{equation}
The resulting shear strain energy is plotted in Fig.~\ref{fig:V:plas}(a).

The stress response is obtained from
\begin{equation}\label{eq:dV-plas}
  \frac{\partial V^{(i)}}{\partial \varepsilon_\mathrm{d}}
  =
  2 \, G \, \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
\end{equation}
(see Fig.~\ref{fig:dV:plas}(a)). From which it can be observed that in elasticity the behaviour is identical to above (cf.~(\ref{eq:dU-dV:elas}b)). For the case that $\varepsilon_\mathrm{y}^{(0)} = - \varepsilon_\mathrm{y}^{(1)}$ the responses are even identical until initial yield stress is reached. For completeness, the stress reads
\begin{equation}
  \T{\sigma} ( \T{\varepsilon} )
  =
  K \, \varepsilon_\mathrm{m} \, \T{I}
  +
  G \, \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big] \;
  \T{N}_\mathrm{d}
  \qquad
  \mathrm{for}
  \;
  \varepsilon_\mathrm{y}^{(i)} \leq \varepsilon_\mathrm{d} < \varepsilon_\mathrm{y}^{(i+1)}
\end{equation}
whereby one has to assume that when $\varepsilon_\mathrm{d} = 0$ also $\T{\sigma}_\mathrm{d} = \T{0}$ in order to avoid zero division. The response is plotted in Fig.~\ref{fig:dV:plas}(a), from which it is observed that it exhibits stress jumps between different parabola in the potential, because of the discontinuity in the second derivative of the elastic potential. This can be remedied, such as in the model presented below.

\subsection{Plastic potential -- Smooth parabolic potential with multiple minima}

The remedy the discontinuity in the second derivative of the potential, it is smoothened as follows:
\begin{equation}\label{eq:V-plas-smooth}
  V \big(
    \varepsilon_\mathrm{y}^{(i)} \leq \varepsilon_\mathrm{d} < \varepsilon_\mathrm{y}^{(i+1)}
  \big)
  =
  V^{(i)}
  =
  - 2 \, G \,
  \left[ \frac{\Delta \varepsilon_\mathrm{y}^{(i)}}{\pi} \right]^2
  \left[
    1
    +
    \cos \left(
      \frac{ \pi }{ \Delta \varepsilon_\mathrm{y}^{(i)} }
      \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
    \right)
  \right]
\end{equation}
which is plotted in Fig.~\ref{fig:V:plas}(b). In this case the stress is obtained from
\begin{equation}\label{eq:dV-plas-smooth}
  \frac{\partial V^{(i)}}{\partial \varepsilon_\mathrm{d}}
  =
  2 \, G \,
  \left[ \frac{\Delta \varepsilon_\mathrm{y}^{(i)}}{\pi} \right]
  \sin \left(
    \frac{ \pi }{ \Delta \varepsilon_\mathrm{y}^{(i)} }
    \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
  \right)
\end{equation}
(see Fig.~\ref{fig:dV:plas}(b)). Which is to the first order equal to linear elasticity around its minimum $\varepsilon_\mathrm{min}^{(i)}$. Indeed, the first order Taylor series of Eq.~\eqref{eq:dV-plas-smooth} around $\varepsilon_\mathrm{d} = \varepsilon_\mathrm{min}^{(i)}$,
\begin{equation}
  \frac{\partial V^{(i)}}{\partial \varepsilon_\mathrm{d}}
  \approx
  2 \, G \, \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
\end{equation}
is identical to Eq.~\eqref{eq:dV-plas}.

For completeness, also in case the expression for the entire stress tensor
\begin{equation}
  \T{\sigma} ( \T{\varepsilon} )
  =
  K \, \varepsilon_\mathrm{m} \, \T{I}
  +
  G \,
  \left[ \frac{\Delta \varepsilon_\mathrm{y}^{(i)}}{\pi} \right]
  \sin \left(
    \frac{ \pi }{ \Delta \varepsilon_\mathrm{y}^{(i)} }
    \Big[\, \varepsilon_\mathrm{d} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
  \right)
  \T{N}_\mathrm{d}
  \qquad
  \mathrm{for}
  \;
  \varepsilon_\mathrm{y}^{(i)} \leq \varepsilon_\mathrm{d} < \varepsilon_\mathrm{y}^{(i+1)}
\end{equation}
whereby, again, one has to assume that when $\varepsilon_\mathrm{d} = 0$ also $\T{\sigma}_\mathrm{d} = \T{0}$ in order to avoid zero division.

\begin{figure}[htp]
  \centering
  \includegraphics[width=1.\textwidth]{figures/potential_V-plas}
  \caption{The multi-minima shear strain energy, $V ( \varepsilon_\mathrm{d} )$, that models the effect of plasticity. The multi-parabolic shear strain energy is shown in (a), while its smoothened equivalent is shown in (b).}
  \label{fig:V:plas}
\end{figure}

\begin{figure}[htp]
  \centering
  \includegraphics[width=1.\textwidth]{figures/potential_dV-plas}
  \caption{Derivative of the shear strain energy $V$.}
  \label{fig:dV:plas}
\end{figure}

\section{Specialized model -- planar shear}

\subsection{Motivation}

The model as proposed above treats all shear modes equally (because $V$ is function of $\varepsilon_\mathrm{d}$). Consequently it is isotropic. There are, however, cases for which an anisotropic model is more realistic. Below a model is proposed in which the plasticity can only occur along a specific plane. Before that, the claim of isotropy is further motivated in two dimensions. In that case the strain tensor has three independent modes, illustrated in Fig.~\ref{fig:strain-modes:2d}.

\begin{figure}[htp]
  \centering
  \includegraphics[width=.7\textwidth]{figures/strain-modes_2d}
  \caption{The three independent modes described by a 2-d stain tensor $\T{\varepsilon}$.}
  \label{fig:strain-modes:2d}
\end{figure}

The first shear mode, in Fig.~\ref{fig:strain-modes:2d}(b), corresponds to a strain tensor of the following structure
\begin{equation} \label{eq:strain-modes:basic}
  \underline{\underline{\varepsilon}}
  =
  \begin{bmatrix}
    0      & \gamma \\
    \gamma &  0
  \end{bmatrix}
\end{equation}
The second shear mode, in Figure~\ref{fig:strain-modes:2d}(c), corresponds to the same shear deformation rotated by $-\pi/4$. It is therefore of the structure
\begin{equation}
  \underline{\underline{\varepsilon}}
  =
  \begin{bmatrix}
    \gamma &  0      \\
     0     & -\gamma
  \end{bmatrix}
\end{equation}

In terms of the equivalent shear strain, both modes result in $\varepsilon_\mathrm{d} = | \gamma |$. This is further illustrated by rotating the strain tensor from Eq.~\eqref{eq:strain-modes:basic} by an angle $\theta$:
\begin{equation}
  \underline{\underline{\varepsilon}}^\prime
  =
  \underline{\underline{R}} \,
  \underline{\underline{\varepsilon}} \,
  \underline{\underline{R}}^T
\end{equation}
where the rotation matrix depends on the rotation angle $\theta$ as follows
\begin{equation}
  \underline{\underline{R}}
  =
  \begin{bmatrix}
    \cos \theta & - \sin \theta \\
    \sin \theta &   \cos \theta
  \end{bmatrix}
\end{equation}
Trivially $\varepsilon_\mathrm{d} = | \gamma |$, independent of $\theta$ -- as plotted in Fig~\ref{fig:shear-modes:epseq} in black. The contributions of the two shear modes are examined by examining $\varepsilon^\prime_{xy}$, representative of the first shear mode in Fig.~\ref{fig:strain-modes:2d}(b), and $\varepsilon^\prime_{xx}$, representative of the second shear mode in Fig.~\ref{fig:strain-modes:2d}(c). These contributions are plotted in Fig.~\ref{fig:shear-modes:epseq} respectively in green and red. Indeed, the contributions of the two shear modes vary with $\theta$, while $\varepsilon_\mathrm{d}$ it is oblivious to this rotation.

\begin{figure}[htp]
  \centering
  \includegraphics[width=.5\textwidth]{figures/strain-modes_2d_epseq}
  \caption{Comparison between the equivalent shear strain $\varepsilon_\mathrm{d}^\prime$ the strain along the $x$-plane, $\varepsilon_\mathrm{s}^\prime = \varepsilon_{xy}^\prime = \vec{e}_x \cdot \T{\varepsilon}^\prime \cdot \vec{e}_y$, and the strain perpendicular to it, $\varepsilon_\mathrm{n}^\prime = \varepsilon_{xx}^\prime = \vec{e}_x \cdot \T{\varepsilon}^\prime \cdot \vec{e}_x$. For a 2-d simple shear strain tensor that is rotated by $\theta$ with respect to the $x$-axis, and normal $\vec{n} = \vec{e}_y$.}
  \label{fig:shear-modes:epseq}
\end{figure}

\subsection{Model}

In this model, the plasticity will be localised on a plane with normal $\vec{n}$ (which has unit length $||\, \vec{n} \,|| \equiv 1$), see Fig.~\ref{fig:strain-vector-planar}. To do so, the strain deviator $\T{\varepsilon}_\mathrm{d}$ is decomposed in two parts, the strain along the plastic (`weak') plane $\T{\varepsilon}_\mathrm{s}$, and the remaining strain $\T{\varepsilon}_\mathrm{n}$. I.e.
\begin{equation}\label{eq:planar:strain:decomposition}
  \T{\varepsilon}_\mathrm{d} = \T{\varepsilon}_\mathrm{s} + \T{\varepsilon}_\mathrm{n}
\end{equation}
To compute the former, planar strain tensor $\T{\varepsilon}_\mathrm{s}$, first the direction of the deviatoric stain tensor projected on the plane is determined as
\begin{equation}
  \vec{s}_\mathrm{n} =
  \frac{
    \T{\varepsilon}_\mathrm{d} \cdot \vec{n}
  }
  {
    ||\, \T{\varepsilon}_\mathrm{d} \cdot \vec{n} \,||
  }
\end{equation}
The strain direction along the plane is now found by projecting $\vec{s}_\mathrm{n}$ on it:
\begin{equation}
  \vec{s} =
  \frac{
    \vec{s}_\mathrm{n} - ( \vec{s}_\mathrm{n} \cdot \vec{n} )\, \vec{n}
  }
  {
    ||\, \vec{s}_\mathrm{n} - ( \vec{s}_\mathrm{n} \cdot \vec{n} )\, \vec{n} \,||
  }
\end{equation}
The amount of strain in this direction is finally found to be
\begin{equation}
  \varepsilon_\mathrm{s} = \vec{s} \cdot \T{\varepsilon}_\mathrm{d} \cdot \vec{n}
\end{equation}
Note that $\varepsilon_\mathrm{s}$ is by definition non-negative, i.e.\ it is oblivious to rotations about $\vec{n}$.

The planar deviatoric strain tensor can now be constructed:
\begin{equation}
  \T{\varepsilon}_\mathrm{s} = \varepsilon_\mathrm{s}
  \big(
    \vec{s} \otimes \vec{n} + \vec{n} \otimes \vec{s}
  \big)
\end{equation}
From this it is obvious that $\varepsilon_\mathrm{s}$ is the equivalent shear strain of this tensor, i.e.
\begin{equation}
  \varepsilon_\mathrm{s}
  \equiv
  \sqrt{ \tfrac{1}{2} \T{\varepsilon}_\mathrm{s} : \T{\varepsilon}_\mathrm{s} }
\end{equation}
(To show this one has to use that $\vec{n} \cdot \vec{n} \equiv 1$ and $\vec{s} \cdot \vec{s} \equiv 1$ while $\vec{n} \cdot \vec{s} \equiv 0$).

\begin{figure}[htp]
  \centering
  \includegraphics[width=.35\textwidth]{figures/strain-vector-planar}
  \caption{Strain along a plane defined by its normal $\vec{n}$: the strain vector $\vec{s}_\mathrm{n}$ and its planar projection $\vec{s}$.}
  \label{fig:strain-vector-planar}
\end{figure}

The remaining strain can now be trivially obtained from Eq.~\eqref{eq:planar:strain:decomposition} as
\begin{equation}
  \T{\varepsilon}_\mathrm{n} = \T{\varepsilon}_\mathrm{d} - \T{\varepsilon}_\mathrm{s}
\end{equation}
Its equivalent shear strain reads
\begin{equation}
  \varepsilon_\mathrm{n} = \sqrt{ \tfrac{1}{2} \T{\varepsilon}_\mathrm{n} : \T{\varepsilon}_\mathrm{n} }
\end{equation}

For plasticity to occur only along the `weak' plane, the shear strain energy is further decomposed in a planar part $V_\mathrm{s}$ that will be plastic, and a non-planar part $V_\mathrm{n}$ that will be elastic:
\begin{equation}
  V
  =
  V_\mathrm{s} ( \varepsilon_\mathrm{s} )
  +
  V_\mathrm{n} ( \varepsilon_\mathrm{n} )
\end{equation}
Based on the definitions of the elastic and plastic potentials the following expression for the stress is obtained
\begin{equation}
  \T{\sigma} ( \T{\varepsilon} )
  =
  K \, \varepsilon_\mathrm{m} \, \T{I}
  +
  G \, \T{\varepsilon}_\mathrm{n}
  +
  G \,
  \left[ \frac{\Delta \varepsilon_\mathrm{y}^{(i)}}{\pi} \right]
  \sin \left(
    \frac{ \pi }{ \Delta \varepsilon_\mathrm{y}^{(i)} }
    \Big[\, \varepsilon_\mathrm{s} - \varepsilon_\mathrm{min}^{(i)} \,\Big]
  \right)
  \frac{\T{\varepsilon}_\mathrm{s}}{\varepsilon_\mathrm{s}}
  \quad
  \mathrm{for}
  \;
  \varepsilon_\mathrm{y}^{(i)} \leq \varepsilon_\mathrm{s} < \varepsilon_\mathrm{y}^{(i+1)}
\end{equation}

\appendix

\vfill\newpage
\section{Tensors and tensor products}
\label{sec:nomenclature:tensor}

\begin{itemize}
%
\item Second order tensor
\begin{equation}
  \T{A} = A_{ij} \vec{e}_i \vec{e}_j
\end{equation}
%
\item Dyadic tensor product
\begin{align}
  \T{C} &= \vec{a} \otimes \vec{b} \\
  C_{ij} &= a_{i} \, b_{j}
\end{align}
%
\item Double tensor contraction
\begin{align}
  C &= \T{A} : \T{B} = \mathrm{tr} \left( \T{A} \cdot \T{B} \right) \\
    &= A_{ij} \, B_{ji}
\end{align}
%
\end{itemize}

\section{Unit tensors}
\label{sec:nomenclature:unit}

\begin{itemize}
%
\item Second order unit tensor
\begin{equation}
  \T{I} = \delta_{ij} \vec{e}_i \vec{e}_j
\end{equation}
It is easy to show that it has the property that
\begin{equation}
  \T{I} : \T{A} = \mathrm{tr} ( \bm{A} )
\end{equation}
%
\item Fourth order unit tensor:
\begin{equation}
  \TT{I} : \T{A} \equiv \T{A}
\end{equation}
i.e.
\begin{equation}
  \delta_{il} \delta_{jk} A_{lk} = A_{ij}
\end{equation}
hence
\begin{equation}
  \TT{I} = \delta_{il} \delta_{jk} \vec{e}_i \vec{e}_j \vec{e}_k \vec{e}_l
\end{equation}
%
\item Deviatoric projection
\begin{equation}
  \TT{I}_\mathrm{d} : \T{A} \equiv \T{A} - \tfrac{1}{d} \mathrm{tr} ( \bm{A} ) \T{I}
\end{equation}
hence
\begin{equation}
  \TT{I}_\mathrm{d} = \TT{I} - \tfrac{1}{d} \T{I} \otimes \T{I}
  = \left( \delta_{il} \delta_{jk} - \tfrac{1}{d} \delta_{ij} \delta_{kl} \right) \vec{e}_i \vec{e}_j \vec{e}_k \vec{e}_l
\end{equation}
%
\end{itemize}

\section{Strain measures}
\label{sec:nomenclature::strain}

\begin{itemize}
%
\item Volumetric strain (in $d$ dimensions)
\begin{equation}
  \varepsilon_\mathrm{m}
  = \tfrac{1}{d} \, \mathrm{tr} ( \T{\varepsilon} )
  = \tfrac{1}{d} \, \T{\varepsilon} : \T{I}
\end{equation}
%
\item Strain deviator
\begin{equation}
  \T{\varepsilon}_\mathrm{d}
  = \T{\varepsilon} - \tfrac{1}{d} \, \mathrm{tr} ( \T{\varepsilon} ) \, \T{I}
  = \T{\varepsilon} - \varepsilon_\mathrm{m} \, \T{I}
  = \TT{I}_\mathrm{d} : \T{\varepsilon}
\end{equation}
%
\item Equivalent shear strain
\begin{equation}
  \varepsilon_\mathrm{d}
  = \; \sqrt{
    \tfrac{1}{2} \, \T{\varepsilon}_\mathrm{d} : \T{\varepsilon}_\mathrm{d}
  }
\end{equation}
%
\end{itemize}

\section{Stress measures}
\label{sec:nomenclature::stress}

\begin{itemize}
%
\item Hydrostatic stress (in $d$ dimensions)
%
\begin{equation}
\sigma_\mathrm{m}
= \tfrac{1}{d} \, \mathrm{tr} ( \T{\sigma} )
= \tfrac{1}{d} \, \T{\sigma} : \T{I}
\end{equation}
%
\item Stress deviator
%
\begin{equation}
  \T{\sigma}_\mathrm{d}
  = \T{\sigma} - \tfrac{1}{d} \, \mathrm{tr} ( \T{\sigma} ) \, \T{I}
  = \T{\sigma} - \sigma_\mathrm{m} \, \T{I}
  = \TT{I}_\mathrm{d} : \T{\sigma}
\end{equation}
%
\item Equivalent shear stress
\begin{equation}
\sigma_\mathrm{d} = \sqrt{ 2 \, \T{\sigma}_\mathrm{d} : \T{\sigma}_\mathrm{d} }
\end{equation}
%
\end{itemize}

\section{Derivatives}
\label{sec:nomenclature:derivatives}

\begin{itemize}
%
\item Trace of the strain
\begin{equation}
  \frac{ \partial \, \mathrm{tr} ( \T{\varepsilon} ) }{ \partial \T{\varepsilon} }
  =
  \frac{ \partial }{ \partial \T{\varepsilon} } \left( \T{\varepsilon} : \T{I} \right)
  =
  \frac{ \partial \T{\varepsilon} }{ \partial \T{\varepsilon} } : \T{I}
  =
  \TT{I} : \T{I}
  =
  \T{I}
\end{equation}
%
\item Strain deviator
\begin{equation}
  \frac{\partial \T{\varepsilon}_\mathrm{d}}{\partial \T{\varepsilon}}
  =
  \frac{ \partial }{ \partial \T{\varepsilon} } \left( \T{\varepsilon} - \tfrac{1}{d} \mathrm{tr} ( \T{\varepsilon} ) \T{I} \right)
  =
  \TT{I} - \tfrac{1}{d} \T{I} \otimes \T{I}
  =
  \TT{I}_\mathrm{d}
\end{equation}
%
\item Equivalent shear strain
\begin{equation}
  \frac{ \partial \varepsilon_\mathrm{d} }{ \partial \T{\varepsilon} }
  =
  \frac{\partial}{\partial \T{\varepsilon}} \sqrt{\tfrac{1}{2}\, \T{\varepsilon}_\mathrm{d} : \T{\varepsilon}_\mathrm{d}}
  =
  \frac{1}{2 \varepsilon_\mathrm{d}}
  \frac{1}{2}
  \left[\, \frac{\partial \T{\varepsilon}_\mathrm{d}}{\partial \T{\varepsilon}} : \T{\varepsilon}_\mathrm{d} + \T{\varepsilon}_\mathrm{d} : \frac{\partial \T{\varepsilon}_\mathrm{d}}{\partial \T{\varepsilon}} \,\right]
  =
  \frac{1}{4 \varepsilon_\mathrm{d}}
  \big[\, \TT{I}_\mathrm{d} : \T{\varepsilon}_\mathrm{d} + \T{\varepsilon}_\mathrm{d} : \TT{I}_\mathrm{d} \,\big]
  =
  \frac{1}{2}
  \frac{\T{\varepsilon}_\mathrm{d}}{\varepsilon_\mathrm{d}}
  \equiv
  \tfrac{1}{2}
  \T{N}_d
\end{equation}
%
\end{itemize}

\section{Conversion to common parameters for linear elasticity}

The parameters are confronted to their common definitions (denoted here with a tilde) for linear elasticity in $d = 3$:

\begin{itemize}
  \item Bulk modulus
  \begin{equation}
    \kappa = K / 3
  \end{equation}
  \item Shear modulus
  \begin{equation}
    \mu = G / 2
  \end{equation}
\end{itemize}
This results in a stress response
\begin{equation}
  \T{\sigma} ( \T{\varepsilon} )
  =
  \kappa \, \mathrm{tr} ( \T{\varepsilon} ) \T{I}
  +
  2 \mu \left[ \T{\varepsilon} - \tfrac{1}{3} \mathrm{tr} ( \T{\varepsilon} ) \T{I} \right]
  =
  \kappa \, \mathrm{tr} ( \T{\varepsilon} ) \T{I}
  +
  2 \mu \, \T{\varepsilon}_\mathrm{d}
\end{equation}

\bibliography{library}

\end{document}


\chapter{Table}

\section{LoRa: Bit rate and data rate}

\begin{table}[h!]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
BW (kHz) & SF & bit rate (bits/sec) \\ \midrule
125     & 7 & 6836 \\
125     & 8 & 3906 \\
125     & 9 & 2197 \\
125     & 10 & 1220 \\
125     & 11 & 671 \\
125     & 12 & 366 \\
250     & 7 & 13671 \\
250     & 8 & 7812 \\
250     & 9 & 4394 \\
250     & 10 & 2441 \\
250     & 11 & 1342 \\
250     & 12 & 732 \\ \bottomrule
\end{tabular}
\caption{Bit rates depending on BW, and SF\label{table:bitrate}}
\end{table}

\begin{table}[h!]
\centering
\begin{tabular}{@{}lllll@{}}
\toprule
CR & BW (kHz) & SF7 (bits/sec) & SF8 (bits/sec) & SF10 (bits/sec) \\ \midrule
\multirow{2}{*}{$\frac{4}{5}$} & 125000   & 5469           & 3125           & 976             \\
  & 250000   & 10937          & 6250           & 1953            \\
\multirow{2}{*}{$\frac{4}{6}$} & 125000   & 4557           & 2604           & 813             \\
  & 250000   & 9114           & 5208           & 1627            \\
\multirow{2}{*}{$\frac{4}{8}$} & 125000   & 3417           & 1954           & 660             \\
  & 250000   & 6835           & 3906           & 1220            \\ \bottomrule
\end{tabular}
\caption{Data rates depending on CR, BW, and SF\label{table:datarate}}
\end{table}

\section{RN2483 Timing Measurements and Predictions}

\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}Bytes} & Time ($\mu s$) & Prediction ($\mu s$) \\ \midrule
1                                                   & 3080      & 3021       \\
4                                                   & 3560      & 3528       \\
8                                                   & 4200      & 4204       \\
16                                                  & 5550      & 5556       \\
32                                                  & 8280      & 8260       \\
64                                                  & 13680     & 13668      \\
110                                                 & 21430     & 21442      \\ \bottomrule
\end{tabular}
\caption{Transmission Time\label{table:measurementtx}}
\end{table}

\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}Bytes} & Time ($\mu s$) & Prediction ($\mu s$) \\ \midrule
1                                                   & 820       & 898        \\
4                                                   & 2350      & 2332       \\
8                                                   & 4240      & 4244       \\
16                                                  & 8160      & 8068       \\
32                                                  & 15600     & 15716      \\
64                                                  & 31100     & 31012      \\
110                                                 & 53200     & 53000      \\ \bottomrule
\end{tabular}
\caption{Reception Spreading Factor 7\label{table:rxsf7}}
\end{table}

\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}Bytes} & Time ($\mu s$) & Prediction ($\mu s$) \\ \midrule
1                                                   & 1500      & 1529       \\
4                                                   & 3240      & 2963       \\
8                                                   & 5060      & 4875       \\
16                                                  & 8840      & 8699       \\
32                                                  & 16700     & 16347      \\
64                                                  & 31700     & 31643      \\
110                                                 & 53300     & 53631      \\ \bottomrule
\end{tabular}
\caption{Reception Spreading Factor 8\label{table:rxsf8}}
\end{table}

\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}Bytes} & Time ($\mu s$) & Prediction ($\mu s$) \\ \midrule
1                                                   & 3160      & 3287       \\
4                                                   & 4560      & 4721       \\
8                                                   & 6500      & 6633       \\
16                                                  & 10120     & 10457      \\
32                                                  & 17900     & 18105      \\
64                                                  & 33200     & 33401      \\
110                                                 & 55200     & 55389      \\ \bottomrule
\end{tabular}
\caption{Reception Spreading Factor 9\label{table:rxsf9}}
\end{table}

\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}Bytes} & Time ($\mu s$) & Prediction ($\mu s$) \\ \midrule
1                                                   & 6100      & 6235       \\
4                                                   & 7400      & 7669       \\
8                                                   & 9660      & 9581       \\
16                                                  & 13560     & 13405      \\
32                                                  & 21040     & 21053      \\
64                                                  & 36400     & 36349      \\
110                                                 & 58400     & 58337      \\ \bottomrule
\end{tabular}
\caption{Reception Spreading Factor 10\label{table:rxsf10}}
\end{table}

\chapter{Code}

\section{Driver implementation structure\label{appendix:driver}}

My implementation structure took inspiration from the work
in~\cite{8847137} and the \emph{RIOT-OS}
project\footnote{\url{https://github.com/RIOT-OS/RIOT}}.

Following is a listing of the different files I created and their
usage. % \improvement{I don't like this phrase}

\begin{description}
  \item[lora] LoRa radio specific functions declaration, and configuration.
    This includes functions used to calculate the time-on-air and
    LoRa PHY configuration structure and parameters.
  \item[rn2483-include] contains the declaration both needed by
    \lstinline{rn2483-uart} and \lstinline{rn2483} to avoid cycling inclusion
    that mess with the compiler.
  \item[rn2483-uart] Lower level implementation of the function to directly
    communicate with the module via UART\@.
    It contains hardware-specific implementation for the UART\@.
  \item[rn2483-api] Complete coverage of the RN2483 commands. Using functions
    from this file allows the user of the driver to not write
    each command by hand and use standard structure instead.
  \item[rn2483] Implementation of the Contiki radio device driver.
    It contains the standardized way of Contiki to use and configure radio
    devices.
    All the radio drivers in Contiki share this structure.
\end{description}

\subsection{The RN2483 Shell\label{appendix:shell}}

The \emph{RN2483 shell} available in
\lstinline{/example/platform-specific/lora/rn2483}
is a tool to interact directly with the module.

This tool extends the existing shell available in Contiki by writing a set
of commands to test and interact with the RN2483 via UART\@.
It was used during the development of the driver as a way to test parameters
as well as the synchronous communication implementation.

Here is the list of the added commands to the Contiki shell.

\begin{lstlisting}[language=none]
'> sys': Send a 'system' command to the RN2483 Module.
'> mac': Send a 'mac' command to the RN2483 Module.
'> radio': Send a 'radio' command to the RN2483 Module.
'> tx': Transmit a radio message with the RN2483.
'> sleep': Put RN2483 into sleep mode.
'> wakeup': Force wakeup of RN2483.
'> rn2483_reset': Hardware Reset of the RN2483 Module.
'> help': Shows this help.
\end{lstlisting}

Each project is bundled with a \lstinline{project-conf.h}
configuration file in which we can define the parameters of our project.
To set my LoRa driver as the physical layer implementation we must add the
following line to change the NETSTACK configuration.

\begin{lstlisting}
#define NETSTACK_CONF_RADIO rn2483_radio_driver
\end{lstlisting}

To compile and upload the project go to the
\lstinline{/example/platform-specific/lora/rn2483}
folder and then run.

\begin{lstlisting}
make TARGET=zoul BOARD=remote-revb PORT=/dev/ttyUSBx test-rn2483.upload
\end{lstlisting}

And run the following command to access the shell.

\begin{lstlisting}
make TARGET=zoul BOARD=remote-revb PORT=/dev/ttyUSBx login
\end{lstlisting}

\section{Packet timestamp implementation\label{code:timestampimpl}}

\begin{lstlisting}[language=c]
static radio_result_t
rn2483_get_object(radio_param_t param, void *dest, size_t size)
{
  switch(param) {
  case RADIO_PARAM_LAST_PACKET_TIMESTAMP:
    if(size != sizeof(rtimer_clock_t) || !dest) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    *(rtimer_clock_t *)dest = RN2483_DEV.packet_timestamp
      - US_TO_RTIMERTICKS_64(
          RX_RECEIVING_DELAY_US(RN2483_DEV.rx_len)
          + t_packet(&(RN2483_DEV.radio), RN2483_DEV.rx_len)
          + TRANSMISSION_TIME_US(RX_CMD_LENGTH(RN2483_DEV.rx_len))
      );
    return RADIO_RESULT_OK;
  }
}
\end{lstlisting}

\section{Custom Schedule Code\label{code:customsched}}

\begin{lstlisting}
static linkaddr_t node_1_address = {{
  0x00, 0x12, 0x4b, 0x00, 0x14, 0xd5, 0x2f, 0x2a
}};
static linkaddr_t node_2_address = {{
  0x00, 0x12, 0x4b, 0x00, 0x14, 0xd5, 0x2d, 0xac
}};
static linkaddr_t node_3_address = {{
  0x00, 0x12, 0x4b, 0x00, 0x14, 0xd5, 0x2d, 0xbc
}};
static linkaddr_t node_4_address = {{
  0x00, 0x12, 0x4b, 0x00, 0x14, 0xd5, 0x2f, 0x09
}};

void
tsch_schedule_custom(void)
{
  struct tsch_slotframe *sf_custom;
  tsch_schedule_remove_all_slotframes();
  sf_custom = tsch_schedule_add_slotframe(0, TSCH_SCHEDULE_DEFAULT_LENGTH);
  tsch_schedule_add_link(sf_custom,
      LINK_OPTION_RX | LINK_OPTION_TX | LINK_OPTION_SHARED | LINK_OPTION_TIME_KEEPING,
      LINK_TYPE_ADVERTISING, &tsch_broadcast_address,
      0, 0);

  if (linkaddr_node_addr.u8[7] == node_1_address.u8[7]) {
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_2_address, 1, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_3_address, 2, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_3_address, 4, 0);
  } else if (linkaddr_node_addr.u8[7] == node_2_address.u8[7]) {
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_1_address, 1, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_3_address, 3, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_4_address, 5, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_4_address, 6, 0);
  } else if (linkaddr_node_addr.u8[7] == node_3_address.u8[7]) {
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_1_address, 2, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_2_address, 3, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_1_address, 4, 0);
  } else if (linkaddr_node_addr.u8[7] == node_4_address.u8[7]) {
    tsch_schedule_add_link(sf_custom, LINK_OPTION_TX, LINK_TYPE_NORMAL, &node_2_address, 5, 0);
    tsch_schedule_add_link(sf_custom, LINK_OPTION_RX, LINK_TYPE_NORMAL, &node_2_address, 6, 0);
  }
}
\end{lstlisting}


\appendix

\chapter{CDs and Symbols handled by the Interface}

\begin{tabular}{p{2in} p{2in}}

{\bf alg1} & {\tt one, zero}\\ \\

{\bf arith1 } & {\tt abs, conjugate, divide, minus, plus, power, product, root, sum, times, unary\_minus}\\ \\

{\bf arith2 } & {\tt arg, inverse, times}\\ \\

{\bf calculus1} & {\tt defint, diff, int, partialdiff}\\ \\

{\bf fns1 }& {\tt inverse, lambda}\\ \\

{\bf integer1 }& {\tt factorial, gcd , quotient, rem}\\ \\

{\bf interval1 }& {\tt integer\_interval, interval, interval\_cc, interval\_co, interval\_oc, interval\_oo}\\ \\

{\bf limit1 }& {\tt both\_sides, above, below, limit, null}\\ \\

{\bf linalg1 }& {\tt matrix, outerproduct, scalarproduct, vector, vectorproduct}\\ \\

\end{tabular}

\begin{tabular}{p{2in} p{2in}}

{\bf linalg2 }& {\tt vector}\\ \\

{\bf linalg3 }& {\tt determinant, matrix\_selector, selector, size, transpose, vector\_selector}\\ \\

{\bf list1 }& {\tt list}\\ \\

{\bf logic1 }& {\tt and, false, implies, not, or, true, xor}\\ \\

{\bf logic2 }& {\tt equivalent}\\ \\

{\bf minmax1 }& {\tt max, min}\\ \\

{\bf multiset1 }& {\tt in, intersect, multiset, notin, notprsubset, notsubset, prsubset, set, setdiff, subset, union}\\ \\

{\bf nums1 }& {\tt based\_integer, complex\_cartesian, complex\_polar, e, gamma, i, imaginary, infinity, nan, pi, rational,
real}\\ \\

{\bf omtypes }& {\tt float, integer}\\ \\

{\bf quant1 }& {\tt exists, forall}\\ \\

{\bf relation1 }& {\tt eq, geq, gt, leq, lt, neq}\\ \\

{\bf relation2 }& {\tt approx}\\ \\

{\bf set1 }& {\tt in, intersect, notin, notprsubset, notsubset, prsubset, set, setdiff, subset, union}\\ \\

{\bf stats1 }& {\tt mean, median, mode, moment, sdev, variance}\\ \\

\end{tabular}

\begin{tabular}{p{2in} p{2in}}

{\bf transc1 }& {\tt arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, cos,
cosh, cot, coth, csc, csch, exp, ln, log, sec, sech, sin, sinh, tan, tanh}\\ \\

{\bf transc2 }& {\tt arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsinh, arctanh}\\ \\

{\bf typmml }& {\tt complex\_cartesian\_type, complex\_polar\_type, constant\_type, fn\_type, integer\_type, list\_type,
matrix\_type, rational\_type, real\_type, set\_type, type, vector\_type}\\ \\

{\bf veccalc1 }& {\tt curl, divergence, grad, laplacian}\\ \\

\end{tabular}


% !TEX root =main.tex

%\section{Further Remarks on SO-PoR Protocol}\label{SO-PoR-discussion}

\begin{remark}
 In each verification, e.g. $j\text{\small{-th}}$ one, it is required that the server can: (a) learn the random challenges, (b) compute a proof, and (c) record it in the smart contract, before it is able to learn key $l_{\scriptscriptstyle j}$; otherwise, (i.e. if it learns $l_{\scriptscriptstyle j}$ before sending and registering the proof), it can tamper with the data and pass the verification. Because by knowing $l_{\scriptscriptstyle j}$ it can construct valid tags for the data that has been tampered with. That is why, in the protocol, it is required: $t'_{\scriptscriptstyle j}\geq t_{\scriptscriptstyle j}+\Delta_{\scriptscriptstyle 1}+\Delta_{\scriptscriptstyle 2}$
\end{remark}

\begin{remark}
The way disposable tags are generated in SO-PoR  differs from those computed  in traditional/outsourced PoR schemes, in spite of having similarities structure-wise. Specifically, (unlike existing protocols, e.g. \cite{DBLP:conf/asiacrypt/ShachamW08,armknecht2014outsourced}) in SO-PoR, each random value, $r_{\scriptscriptstyle b,j}$, utilised to generate a disposable tag of a  block (for $j\text{\small{-th}}$ verification), is not derived from the block index. Instead, it depends on (a  fresh secret key for $j\text{\small{-th}}$ verification and) the total number of blocks challenged in each verification that is a public value. This means, the verifier does not need to know and verify each challenged block's index in the verification phase, which leads to a lower cost.
\end{remark}

\begin{remark}
With minor adjustments, we can reduce the smart contract storage cost from $O(z)$ to constant, $O(1)$ and offload the cost to the server. The idea is that the client after computing the commitmnet vector: $\vv{\bm{h}}=[h_{\scriptscriptstyle 1},...h_{\scriptscriptstyle z}]$,  in step \ref{Gen-Puzzles-}, it preserves the ordering of the elements (i.e. $h_{\scriptscriptstyle j}$ is associated with $j\text{\small{-th}}$ verification) and constructs a  Merkle tree  on top of them. It stores the tree and the vector on the server, and stores only the tree's  root: $R$, on the contract. In this case,  the server in step \ref{fully-recover-l} after recovering $\ddot{p}_{\scriptscriptstyle j}= (l_{\scriptscriptstyle j}, d_{\scriptscriptstyle j})$,  computes: $h_{\scriptscriptstyle j}=\mathtt{H}(l_{\scriptscriptstyle j}||d_{\scriptscriptstyle j})$, and sends a Merkle tree proof (that $h_{\scriptscriptstyle j}$ corresponds to  $R$) along with $\ddot{p}_{\scriptscriptstyle j}$ to the contract. In step \ref{check-hash}, the contract: (a) checks if $h_{\scriptscriptstyle j}=\mathtt{H}(l_{\scriptscriptstyle j}||d_{\scriptscriptstyle j})$, and  (b) verifies the Merkle tree proof.  The rest  remains unchanged.  As a result, the number of values stored in the contract is now $O(1)$. This adjustment comes with an added communication cost: $O(|h_{\scriptscriptstyle j}|\log z)$ for each verification. Nevertheless, the added cost is small and independent of the file size.   For instance, when  $z=10^{\scriptscriptstyle 6}$ and $|h_{\scriptscriptstyle j}|=256$, the  added communication cost is only about $5.1$ kilobit.

\end{remark}

\begin{remark}
One might be willing to use a combination of existing publicly verifiable PoR and smart contract, such that the contract performs the verification on the client's behalf. However, this approach would have a higher computation or communication cost (especially in the verification phase) than our protocol. Specifically,  there exist two publicly verifiable PoR schemes, based on either (a) BLS signatures, e.g. \cite{DBLP:conf/asiacrypt/ShachamW08}, or (b) Merkle tree, e.g. \cite{MillerPermacoin}. The former approach, in total, requires  $zc$ exponentiations in the verification phase, whereas SO-PoR requires no exponentiations in this phase. Also, the BLS signature-based scheme takes a very long time to encode  a file, as the required number of exponentiations is  $O(|{\bm{F}}|)$. For instance, as measured in \cite{armknecht2014outsourced}, it takes about $55$ minutes to encode a  $64$-MB file,  meaning  it would take about $14$ hours to encode a $1$-GB file. But, in SO-PoR the number of exponentiations, in the store phase, is independent of and much fewer than the file size. On the other hand, the proof size in the Merkle tree-based approach is logarithmic with the file size, i.e. $256zc\log |{\bm{F}}|$ bits, that leads to a high server-side's communication cost. By contrast,  the proof size in SO-PoR is  independent of the file size, and is much shorter, i.e. $884z$ bits.

\end{remark}


\chapter*{About our approach}
\label{ch:our_approach}
\addcontentsline{toc}{chapter}{\nameref{ch:our_approach}}
\vspace{0.8cm}

The results published in this paper have been achieved with an interdisciplinary approach. Not surprisingly, we applied classic mathematical theory and reasoning. Since we are convinced that the Collatz problem cannot be solved with classical maths alone, we furthermore used techniques and tools of modern data science. We combined the two fields in different ways. Firstly, we analyzed Collatz sequences and related features empirically, to derive new formulas and theorems. On the other hand, we used data science to challenge our proofs. As suggested by Karl Popper, we tried to falsify them with counterexamples. In the course of our work, we have learned that the combination of the two fields leads to a very efficient working mode.

Our main data science tool was a Python-API, which implements the theorems of this article and is optimized for processing arbitrarily big integers \cite{Ref_Koch_Github}:

\par\bigskip
\textcolor{wisogreen}\faExternalLink~~\url{https://github.com/c4ristian/collatz}

\par\bigskip\noindent
After the generated data has been exported into a comma-separated values (CSV) file, a Java tool reads that file and carries out the visualization of the corresponding Collatz trees \cite{Ref_Sultanow_Github_Java}:

\par\bigskip
\textcolor{wisogreen}\faExternalLink~~\url{https://github.com/Sultanow/collatz_java}

\par\bigskip
For quick experiments or retracing the transformation chain as per figure~\ref{fig:tree_transformations} some notebooks may provide an efficient playground \cite{Ref_Sultanow_Github}, but it should be noted that these are not designed for large amounts of data and professional use like Christian's API does:

\par\bigskip
\textcolor{wisogreen}\faExternalLink~~\url{https://github.com/Sultanow/collatz}