\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{breqn}
\usepackage{enumitem}
\usepackage{tcolorbox}
\usepackage{hyperref}
\title{Notes on Quantum Complexity}
\author{S.G. Schoeman}
\date{August, 2021}
\usepackage{physics}
\usepackage{amsfonts}
\newtheorem{definition}{Definition}
\newtheorem{fact}[definition]{Fact}
\newtheorem{formula}[definition]{Formula}
\newtheorem{equations}[definition]{Equations}
\newtheorem{External Info}[definition]{External Info}
\newtheorem{treatment}[definition]{Treatment}
\begin{document}

\maketitle

\begin{tcolorbox}[title=Definition: Linear Vector Space]\begin{definition}[Linear Vector Space]\label{0}There are these axioms, you see...

 This definition has no references is thus rank $0$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Field]\begin{definition}[Field]\label{1}A field is the numbers over which a vector space is defined.

 This definition references: (\ref{0}), and is thus rank 1.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Linear Independence of Vectors]\begin{definition}[Linear Independence of Vectors]\label{2}A set of vectors $\mathbb{V}$ is said to be linearly independent if the only such
linear relation $$a_1v_1+a_2v_2+\ldots+a_nv_n=0,$$ where all $v_i\in\mathbb{V}$ and all
$a_i\in\mathbb{C}$, is the trivial one with all $a_i = 0$. If the set of vectors
is not linearly independent, we say they are linearly dependent.

 This definition references: (\ref{0}), and is thus rank 1.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Vector Space Dimension]\begin{definition}[Vector Space Dimension]\label{3}The dimension of a vector space is equal to the minimum number of linearly independent vectors it requires to be spanned.

 This definition references: (\ref{0}), (\ref{2}), and is thus rank 2.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Fact]\begin{fact}[]\label{4}Any vector $\ket{V}$ in an $n$-dimensional space can be written as a
linear combination of $n$ linearly independent vectors $\ket{1}\ldots\ket{n}$.

 This fact references: (\ref{0}), (\ref{2}), (\ref{3}), and is thus rank 3.\end{fact}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Vector Basis]\begin{definition}[Vector Basis]\label{5}A set of $n$ linearly independent vectors in an $n$-dimensional space
 is called a basis.

 This definition references: (\ref{0}), (\ref{2}), (\ref{3}), and is thus rank 3.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Coordinates of a Vector w.r.t. a Basis]\begin{definition}[Coordinates of a Vector w.r.t. a Basis]\label{6}The coordinates of a vector $\ket{v}$ in a basis $\{\ket{j_i}:i\in I\}$
 are the cooefficients of the expansion $$\ket{v}=v_1\ket{j_1}+\ldots+v_n\ket{j_n}$$
 of $\ket{v}$ in that basis.

 This definition references: (\ref{5}), (\ref{4}), and is thus rank 4.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Fact]\begin{fact}[]\label{7}The Hamiltonian $H$ of a spring-mass harmonic oscillator is given by\begin{equation}H=\frac{p^2}{2m}+\frac{\omega^2x^2}{2}\end{equation}
 where $\omega^2=k/m$ is the classical frequency of the oscillating system.

 This fact has no references is thus rank $0$.\end{fact}\end{tcolorbox}
\begin{tcolorbox}[title=Fact]\begin{fact}[]\label{8}The inverted harmonic oscillator changes the sign of the harmonic oscillator,
 so it has Hamiltonian\begin{equation}H=\frac{p^2}{2m}-\frac{\omega^2x^2}{2}\end{equation}
 where $\omega^2=k/m$ is the classical frequency of the oscillating system.

 This fact references: (\ref{7}), and is thus rank 1.\end{fact}\end{tcolorbox}
\begin{tcolorbox}[title=Fact]\begin{fact}[]\label{9}Put $\omega^2=m^2-\lambda$, then $\lambda<m^2$ describes the
 regular harmonic oscillator and $\lambda>m^2$ describes the inverted one, while
 $m^2=\lambda$ is simply a free particle; that is, a particle such that its potential energy
 is independent of its position.

 This fact references: (\ref{7}), (\ref{8}), and is thus rank 2.\end{fact}\end{tcolorbox}
\begin{tcolorbox}[title=Formula]\begin{formula}[]\label{10}Consider with the following system.
 $$\psi(x,t)=\mathcal{N}(t)\exp\left(-\frac{1}{2}\omega_r x^2\right)$$
 with initial conditions $\psi(x,0)=\psi_0,~\mathcal{N}(0)=\mathcal{N}_0$,
 and where $\omega_r=m$.

 This formula has no references is thus rank $0$.\end{formula}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Hermition Operator]\begin{definition}[Hermition Operator]\label{11}A Hermitian operator is an operator that is equal
 to its own conjugate transpose.

 This definition has no references is thus rank $0$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Hermition Matrix]\begin{definition}[Hermition Matrix]\label{12}A Hermitian matrix is a complex square
 matrix that is equal to its own conjugate transpose.

 This definition has no references is thus rank $0$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Equations]\begin{equations}[]\label{13}The equations of motion for the oscillator are $$\dot{x}=
 \frac{\partial H}{\partial p}=\frac{p}{m},~~~~\dot{p}=-\frac{\partial H}{\partial x}=
 -m\omega^2 x$$ which, through elimination of $\dot{p}$, becomes
 $$\ddot{x}=-\omega^2x$$ which easily solves by
 $$x(t)=A\cos(\omega t+\phi)$$ where $x_0=x(0)=A\cos(\phi)$. Note then that
 $$E=T+V=\frac{1}{2}m\dot{x}^2+\frac{1}{2}m\omega^2x^2=\frac{1}{2}mA^2\omega^2$$
 where $E$ is the energy of the classical system.

 This equations references: (\ref{7}), and is thus rank 1.\end{equations}\end{tcolorbox}
\begin{tcolorbox}[title=Fact]\begin{fact}[]\label{14}The equation for a quantum oscillator with state $\ket{\psi}$ is
 $$i\hbar\frac{d}{dt}\ket{\psi}=H\ket{\psi}$$

 This fact has no references is thus rank $0$.\end{fact}\end{tcolorbox}
\begin{tcolorbox}[title=External Info: AdS/CFT correspondence]\begin{External Info}[AdS/CFT correspondence]\label{15}

 This External Info references: \{\href{https://en.wikipedia.org/wiki/AdS/CFT_correspondence}{link}\}, [\ref{3}], and is thus rank $\infty$.\end{External Info}\end{tcolorbox}
\begin{tcolorbox}[title=External Info: Einstein-Rosen Bridge (Wormhole)]\begin{External Info}[Einstein-Rosen Bridge (Wormhole)]\label{16}

 This External Info references: \{\href{https://en.wikipedia.org/wiki/Wormhole}{link}\}, [\ref{3}], and is thus rank $\infty$.\end{External Info}\end{tcolorbox}
\begin{tcolorbox}[title=External Info: Complexity Equals Action]\begin{External Info}[Complexity Equals Action]\label{17}

 This External Info references: [\ref{5}], and is thus rank $\infty$.\end{External Info}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Vector Space]\begin{definition}[Vector Space]\label{18}A vector space (also called a linear space) is a set of objects called vectors, which may be added together and multiplied ("scaled") by numbers, called scalars. They obey specific axioms...

 This definition references: (\ref{0}), \{\href{https://en.wikipedia.org/wiki/Vector_space}{link}\}, and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Binary Operation]\begin{definition}[Binary Operation]\label{19}In mathematics, a binary operation or dyadic operation is a calculation that combines two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two.

 This definition references: \{\href{https://en.wikipedia.org/wiki/Binary_operation}{link}\}, and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Inner Product Space]\begin{definition}[Inner Product Space]\label{20}An inner product space, or a Hausdorff pre-Hilbert space, is a vector space with a binary operation called an inner product.

 This definition references: (\ref{18}), (\ref{19}), \{\href{https://en.wikipedia.org/wiki/Inner_product_space}{link}\}, and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Complete Metric Space]\begin{definition}[Complete Metric Space]\label{21}In mathematical analysis, a metric space M is called complete (or a Cauchy space) if every Cauchy sequence of points in M has a limit that is also in M.

 This definition references: \{\href{https://en.wikipedia.org/wiki/Complete_metric_space}{link}\}, and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Hilbert Space]\begin{definition}[Hilbert Space]\label{22}A Hilbert space H is a real or complex inner product space that is also a complete metric space with respect to the distance function induced by the inner product.

 This definition references: (\ref{20}), (\ref{21}), \{\href{https://en.wikipedia.org/wiki/Hilbert_space#Definition_and_illustration}{link}\}, and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Definition: Unitary Operator]\begin{definition}[Unitary Operator]\label{23}In functional analysis, a unitary operator is a surjective bounded operator on a Hilbert space preserving the inner product. Unitary operators are usually taken as operating on a Hilbert space, but the same notion serves to define the concept of isomorphism between Hilbert spaces.

 This definition references: \{\href{https://en.wikipedia.org/wiki/Unitary_operator}{link}\}, (\ref{22}), (\ref{20}), and is thus rank $\infty$.\end{definition}\end{tcolorbox}
\begin{tcolorbox}[title=Treatment: Quantum Treatment of an Inverted Harmonic Oscillator (IHO)]\begin{treatment}[Quantum Treatment of an Inverted Harmonic Oscillator (IHO)]\label{24}A reference state $\ket{\psi_R}$ is transformed, via a unitary operator $\hat{\mathcal{U}}$, into target state $\ket{\psi_T}$: $$\ket{\psi_T}=\hat{\mathcal{U}}\ket{\psi_R}$ Now, say that the operator is but an evolving operator $\hat{\mathcal{U}}=e^{-iHt}$, so $$\ket{\psi_T}=e^{-iHt}\ket{\psi_R}$$

 This treatment references: (\ref{23}), and is thus rank $\infty$.\end{treatment}\end{tcolorbox}
\section*{External References}
\begin{enumerate}[label={[\arabic*]}]\item A. Bhattacharyya, S. Das, S.S. Haque, B. Underwood. \begin{textit}Cosmological Complexity. \end{textit}(2020). arXiv:2001.08664
\item R. Jefferson, R.C. Myers. \begin{textit}Circuit complexity in quantum field theory. \end{textit}(2017). arXiv:1707.08570
\item T. Ali, A. Bhattacharyya, S.S. Haque, E.H. Kim, N. Moynihan, J. Murugan. \begin{textit}Chaos and Complexity in Quantum Mechanics. \end{textit}(2020). arXiv:1905.13534
\item T. Ali, A. Bhattacharyya, S.S. Haque, E.H. Kim, N. Moynihan. \begin{textit}Time Evolution of Complexity: A Critique of Three Methods. \end{textit}(2019). arXiv:1810.02734
\item S.S. Haque, C. Jana, B. Underwood. \begin{textit}Saturation of Thermal Complexity of Purification. \end{textit}(2021). arXiv:2107.08969
\item A.R. Brown, D.A. Roberts, L. Susskind, B. Swingle, Y. Zhao. \begin{textit}Complexity Equals Action. \end{textit}(2016). arXiv:1509.07876
\end{enumerate}
\end{document}


\section{Solving probabilistic property evaluation}
\label{sect:prob-solutions}

We propose different solutions to the MPPE and PPE problems.
For the former, we resort to SSAT solving.
For the latter, in addition to SSAT solving,
we present solutions based on signal probability calculation,
weighted model counting,
and probabilistic model checking.

\subsection{Solving MPPE and PPE via SSAT}
Note that the entire miter SPBN can be directly converted to a CNF formula by Tseitin transformation~\cite{Tseitin1983}
since all vertices except for those in $X,Z,W$ are error-free after the standardization.
In the following,
let $\pf_M$ be the CNF formula converted from the miter SPBN $G_M$,
which contains vertex sets
$X=\{x_1,\ldots,x_n\}$,
$Y=\{y_1,\ldots,y_m\}$,
$Z=\{z_1,\ldots,z_l\}$, and
$W=\{w_1,\ldots,w_q\}$ as shown in~\cref{fig:prob-spbn-miter}.
Observe that $X \cup Z \cup W$ is a base set for $\pf_M$.
Given a parameter assignment $\pi$ to $X$,
we define the corresponding weighting function $\wt:X\cup Z\cup W\mapsto[0,1]$ for $\pf_M$ as
$\wt(x_i)=\pi(x_i)$,
$\wt(y_j)=p_{y_j}$, and
$\wt(w_k)=p_{w_k}$ for all
$x_i \in X$,
$y_j \in Y$, and
$w_k \in W$.
The weighting function $\wt$ will be used throughout our discussion.

\begin{theorem}
    \label{thm:prob-ppe-ssat}
    The probabilistic property evaluation (PPE) of $\pf_M$ under a parameter assignment $\pi$ can be expressed
    by the following SSAT formula $\Qf_\mathrm{PPE}(\pi)$:
    \begin{align}
        \label{eq:prob-ppe-ssat}
        \random{\pi(x_1)}x_1,\ldots,\random{\pi(x_n)}x_n,
        \random{p_{z_1}}z_1,\ldots,\random{p_{z_l}}z_l,
        \random{p_{w_1}}w_1,\ldots,\random{p_{w_q}}w_q,
        \exists y_1,\ldots,\exists y_m.
        \pf_M.
    \end{align}
\end{theorem}
\begin{proof}
    Let $A$ be the event $\pf_M=\top$ and $\Lambda=\av{X \cup Z \cup W}$.
    By the law of total probability,
    $\Pr[A]=\sum\limits_{\as\in\Lambda}\Pr[\as]\Pr[A\mid\as]$,
    where $\Pr[\as]=\wt(\as)$ ($\wt$ is the weighting function defined previously) and
    $\Pr[A\mid\as]$ is the conditional probability of event $A$ under the assignment $\as$.
    Notice that $\Pr[A\mid\as]=\pcf{\pf_M}{\as}$ since
    $X \cup Z \cup W$ is a base set for $\pf_M$.
    As a result,
    $\Pr[A]=\sum\limits_{\as\in\Lambda}\wt(\as)\pcf{\pf_M}{\as}$,
    which equals the satisfying probability of the SSAT formula $\Qf_\mathrm{PPE}(\pi)$.
\end{proof}

\begin{theorem}
    \label{thm:prob-mppe-ssat}
    The maximum probabilistic property evaluation (MPPE) of $\pf_M$ can be expressed
    by the following SSAT formula $\Qf_\mathrm{MPPE}$:
    \begin{align}
        \label{eq:prob-mppe-ssat}
        \exists x_1,\ldots,\exists x_n,
        \random{p_{z_1}}z_1,\ldots,\random{p_{z_l}}z_l,
        \random{p_{w_1}}w_1,\ldots,\random{p_{w_q}}w_q,
        \exists y_1,\ldots,\exists y_m.
        \pf_M.
    \end{align}
\end{theorem}
\begin{proof}
    By the same argument in the proof of~\cref{thm:prob-ppe-ssat},
    given an assignment $\as_X$ over $X$,
    the SSAT formula:
    \begin{align*}
        \Qf_\mathrm{MPPE}(\as_X)=
        \random{p_{z_1}}{z_1},\ldots,\random{p_{z_l}}{z_l},
        \random{p_{w_1}}{w_1},\ldots,\random{p_{w_q}}{w_q},
        \exists y_1,\ldots,\exists y_m.
        \pcf{\pf_M}{\as_X}
    \end{align*}
    computes the satisfying probability of the miter under the assignment $\as_X$.
    According to the SSAT semantics,
    the outermost existential quantification of primary inputs $X$
    ensures to find an optimal assignment $\as_X^*$
    such that the satisfying probability of $\Qf_\mathrm{MPPE}(\as_X^*)$ is maximized.
    Hence the SSAT formula $\Qf_\mathrm{MPPE}$ computes the maximum satisfying probability of the miter.
\end{proof}

Note that the only difference between $\Qf_\mathrm{MPPE}$ and $\Qf_\mathrm{PPE}$
lies in the quantification for the primary inputs $X$.
Although SSAT provides a convenient language for expressing both MPPE and PPE problems,
its solvers to date remain immature to handle formulas of practical sizes in our considered application.
One of the main inefficiencies can be attributed to representing $\pf_M$ in CNF,
which results in the additional quantification of the intermediate circuit variables $Y=\{y_1,\ldots,y_m\}$.
It motivates the development of a new SSAT solver as we present below.

\subsubsection{BDD-based SSAT solving}

\begin{algorithm}[t]
    \caption{BDD-based SSAT solving: \texttt{BddSsatSolve}}
    \label{alg:bddssat}
    \begin{algorithmic}[1]
        \REQUIRE $\Qf=Q_1 v_1,\ldots,Q_n v_n.\pf$
        \ENSURE $\spb{\Qf}$
        \STATE $N := \texttt{BuildReducedOrderedBdd}(\pf,(v_1,\ldots,v_n))$\label{code:bddssat-build-bdd}
        \STATE $Q := Q_1 v_1,\ldots,Q_n v_n$
        \RETURN $\texttt{BddSsatRecur}(N,Q)$\label{code:bddssat-recursive}
    \end{algorithmic}
\end{algorithm}

\begin{algorithm}[t]
    \caption{The recursive step of \texttt{BddSsatSolve}: \texttt{BddSsatRecur}}
    \label{alg:bddssat-recursive}
    \begin{algorithmic}[1]
        \REQUIRE An ROBDD node $N$ and a prefix $Q$
        \ENSURE $\spb{N=\top}$ under $Q$
        \IF{($N$ is a terminal node)}\label{code:bddssat-recursive-constant-start}
        \RETURN $\nodesp{N}$\label{code:bddssat-recursive-constant-end}
        \ENDIF
        \IF{($\nodevisit{N}=\false$)}
        \IF{($Q(\nodevar{N})=\random{p}$)}
        \STATE $\nodesp{N}:=(1-p)\cdot\texttt{BddSsatRecur}(\nodeelse{N},Q)+p\cdot\texttt{BddSsatRecur}(\nodethen{N},Q)$
        \label{code:bddssat-recursive-random}
        \ELSE
        \STATE $\nodesp{N}:=\max\{\texttt{BddSsatRecur}(\nodeelse{N},Q),\texttt{BddSsatRecur}(\nodethen{N},Q)\}$
        \label{code:bddssat-recursive-exist}
        \ENDIF
        \STATE $\nodevisit{N} := \true$
        \ENDIF
        \RETURN $\nodesp{N}$
    \end{algorithmic}
\end{algorithm}

We propose a BDD-based solver to enhance the scalability of SSAT solving.
The procedure \texttt{BddSsatSolve} is outlined in~\cref{alg:bddssat},
which takes as input an SSAT formula $\Qf=Q_1 v_1,\ldots,Q_n v_n.\pf$.
At~\cref{code:bddssat-build-bdd},
a \textit{reduced ordered BDD} (ROBDD) of $\pf$ is built with a variable ordering following the quantification order.
At~\cref{code:bddssat-recursive},
a recursive procedure \texttt{BddSsatRecur},
sketched in~\cref{alg:bddssat-recursive},
is called to calculate the satisfying probability of $\Qf$.
In the pseudo code, for an ROBDD node $N$,
$\nodethen{N}$ and $\nodeelse{N}$ denote its $\mathrm{then}$- and $\mathrm{else}$-child, respectively;
$\nodeval{N}$ equals 0 (resp. 1) if $N$ is a 0-terminal (resp. 1-terminal) node;
$\nodevisit{N}$ is a flag initialized to \false and records whether $N$ has been processed;
$\nodevar{N}$ and $\nodesp{N}$ denote the control variable and the satisfying probability of node $N$, respectively.
In~\cref{alg:bddssat-recursive},
\crefrange{code:bddssat-recursive-constant-start}{code:bddssat-recursive-constant-end} implement the first and second computation rules of SSAT in~\cref{sect:background-ssat};
\Cref{code:bddssat-recursive-random} and \cref{code:bddssat-recursive-exist} implement the third and fourth rules corresponding to the randomized and existential quantification of the variable, respectively.

Note that \texttt{BddSsatSolve} runs in time linear to the number of BDD nodes (as each node is processed only once).
Therefore the computation complexity is dominated by constructing the ROBDD of $\pf$.
Note also that if the outermost variables in the quantification order are existentially quantified, e.g.,
those in $\Qf_\mathrm{MPPE}$ of~\cref{thm:prob-mppe-ssat},
the corresponding assignments to the existentially quantified variables
to maximize the satisfying probability of $\pf$ can be obtained.
Specifically,
the assignment to an outermost existential variable $\nodevar{N}$ can be derived by recording which of
\texttt{BddSsatRecur}($\nodeelse{N},Q$) and
\texttt{BddSsatRecur}($\nodethen{N},Q$)
contributes to the maximum probability in~\cref{code:bddssat-recursive-exist} of~\cref{alg:bddssat-recursive}.

\subsubsection{Signal probability with BDD-based SSAT}
We exploit the developed BDD-based SSAT solver to compute signal probabilities as defined in~\cref{def:prob-signal-prob,def:prob-signal-prob-max}.
Given an SPBN $G=(V,E)$,
the satisfying probability of any $v \in V$ can be obtained by first encoding the problem into an SSAT instance
and then solving the SSAT formula by \texttt{BddSsatSolve}.

Notice that formula $\pf$ needs not be represented in CNF for \texttt{BddSsatSolve}.
In the application of circuit verification,
formula $\pf$ can be directly input to \texttt{BddSsatSolve} as a circuit.
Without Tseitin transformation from circuit to CNF formula,
the algorithm avoids introducing extra variables.
Consequently, the innermost existential quantification $\exists y_1,\ldots,\exists y_m$
in~\cref{eq:prob-ppe-ssat} of~\cref{thm:prob-ppe-ssat}
and~\cref{eq:prob-mppe-ssat} of~\cref{thm:prob-mppe-ssat} is removed.
The utilization of circuit structures makes the calculation of signal probability
(and therefore the computation of PPE and MPPE) on an SPBN more efficient and scalable
using the proposed BDD-based SSAT solver.
Empirical evidence suggests our proposed SSAT solver outperforms and is much scalable than other CNF-based SSAT solvers.

We note that the signal probability calculation via BDD is used for power estimation of integrated circuits~\cite{Najm1994}.
As we formulate PPE as a signal probability problem on SPBN,
any prior method for signal probability calculation can be used to solve PPE.
However, it is worth emphasizing that prior methods for signal probability calculation,
such as Monte Carlo simulation, cannot solve MPPE.
The BDD-based method has its unique value over other previous endeavors for signal probability calculation
because of its generality of solving both PPE and MPPE.
On the other hand,
since we established the connections of MPPE and PPE to SSAT formulations,
SSAT solvers can also be applied to calculate the maximum signal probability as well as signal probability.

BDD is a well-studied data structure but known for its memory limitation.
Techniques have been highly developed in the 1990s to extend its scalability.
Practical experience suggests that BDD-based computation remains competitive to other formulations
due to the fact that other tools,
such as SSAT and model counting,
are still in their early development.
In our experiments over ISCAS\,'85~\cite{ISCAS85-benchmark} and EPFL~\cite{EPFL-benchmark} benchmark suites,
the BDD-based approach stands as the most scalable one over other formulations to be discussed.

\subsubsection{Generalization to dependent random variables}
The proposed BDD-based SSAT solver is advantageous over other SSAT solvers for its ability to handle randomly quantified variables whose probability distributions are mutually dependent.
Note that according to the SSAT syntax,
there is no support to describe the joint behavior among randomly quantified variables.
That is, every randomly quantified variable acts independently of each other.
This assumption limits the expressiveness of SSAT.
In this paper, we combine our BDD-based SSAT solver with previous methods~\cite{Marculescu1998,Miskov-Zivanov2006}
to represent joint probability distribution of random variables,
and propose a novel SSAT solver that is capable of expressing mutual dependence among randomly quantified variables.
A joint probability distribution of random variables is represented as an algebraic decision diagram (ADD)~\cite{Marculescu1998,Miskov-Zivanov2006}.
After such an ADD representing joint probability distribution is constructed,
the original BDD (which is also an ADD) of the Boolean formula $\pf$ is conjoined with the ADD.
Finally, the value of the SSAT formula can be calculated by traversing the merged ADD similar to the prior independent counterpart.

Following the above strategy,
now we explain how to extend the proposed PPE and MPPE framework to approach PBNs whose random variables are mutually dependent.
After the distillation operation,
the mutually dependent random variables on erroneous vertices are converted to correlated AIs.
Given the joint probability distribution of random variables,
an ADD is built to represent the mutual dependence among AIs.
Similarly, if PIs are correlated,
another ADD can be built to describe their correlation.
After multiplying the ADDs with the BDD of the circuit under evaluation,
the average (PPE) or the maximum (MPPE) violating probability can be computed through traversing the product ADD.
Therefore, the proposed PPE framework is generalized to dependent PBNs,
whose random variables have mutual dependent probability distribution.

\subsection{Solving PPE via weighted model counting}
The following theorem states that an SSAT formula of the form
in~\cref{thm:prob-ppe-ssat} is equivalent to a weighted model counting instance.
\begin{theorem}
    The SSAT formula:
    \begin{align*}
        \Qf=
        \random{p_{x_1}}x_1,\ldots,\random{p_{x_n}}x_n,
        \exists y_1,\ldots,\exists y_m.\pf,
    \end{align*}
    where $X=\{x_1,\ldots,x_n\}$ is a base set for $\pf$,
    is equivalent to a weighted model counting instance of $\pf$
    under a weighting function $\wt$ such that
    $\wt(x_i)=p_{x_i}$ for every $x_i\in X$.
\end{theorem}
\begin{proof}
    Let $A$ be the event that $\pf=\top$.
    According to~\cref{thm:prob-ppe-ssat},
    we have $\Pr[A]=\sum\limits_{\as\in\av{X}}\wt(\as)\pcf{\pf}{\as}$.
    Since $X$ is a base set for $\pf$,
    $\Pr[A]$ can be simplified to $\sum\limits_{\as\models\pf}\wt(\as)$,
    which is the weight of $\pf$.
\end{proof}
By the above theorem, weighted model counting is clearly applicable to PPE.

\begin{algorithm}[p]
    \caption{Formula rewriting for unweighted model counting: \texttt{WmcRewriting}}
    \label{alg:wmcrewriting}
    \begin{algorithmic}[1]
        \REQUIRE A formula $\pf$, a base set $\base$ for $\pf$,
        a wt. func. $\wt$ s.t. $\forall x\in\base.\wt(x)=\frac{k}{2^n}$
        \ENSURE A formula $\pf'$, a base set $\base'$ for $\pf'$,
        a wt. func. $\wt'$ s.t. $\forall x\in\base'.\wt'(x)=\frac{1}{2}$
        \STATE $\pf':=\pf,\base':=\base$
        \FORALL{($x\in\base$)}
        \STATE $var:=x,wt:=\wt(x)$
        \WHILE{($wt\neq\frac{1}{2}$)}
        \STATE $inv:=\bot$
        \IF{($wt>\frac{1}{2}$)}
        \STATE $wt:=1-wt,inv:=\top$
        \ENDIF
        \STATE $\pf':=\pf'\land((inv \oplus var) \equiv (y_{var} \land z_{var}))$
        \STATE $\base':=\base'\setminus\{var\}\cup\{y_{var}\}$
        \STATE $\wt'(y_{var})=\frac{1}{2}$
        \STATE $var=z_{var},wt=2 \cdot wt$
        \ENDWHILE
        \STATE $\base':=\base'\cup\{var\},\wt'(var)=\frac{1}{2}$
        \ENDFOR
        \RETURN $(\pf',\base',\wt')$
    \end{algorithmic}
\end{algorithm}

While exact model counting can be extended to the weighted version at little extra cost,
more effort is required to achieve approximate weighted model counting~\cite{SATHandbook-ModelCounting}.
To enhance the scalability of solving PPE via model counting,
we show how to rewrite a weighted model counting instance into an equivalent unweighted formula.
The rewriting procedure \texttt{WmcRewriting} is outlined in~\cref{alg:wmcrewriting}.

The following lemma explains the rationale behind \texttt{WmcRewriting}.
\begin{lemma}
    \label{lemma:prob-rewrite}
    Let $\pf$ be a Boolean formula with a base set $\base$ and
    a weighting function $\wt$ over $\base$.
    Given an arbitrary variable $x\in\base$,
    we construct $\base'$, $\pf'$, and $\wt'$ as follows.
    Let $\base'=\base\setminus\{x\}\cup\{y_x,z_x\}$ with
    $y_x,z_x$ being newly introduced fresh variables.
    Let $\pf'=\pf \land ((inv \oplus x) \equiv (y_x \land z_x))$,
    where $inv$ is either $\top$ or $\bot$ to determine the sign of $x$.
    If $inv=\bot$, let $\wt'(y_x)\wt'(z_x)=\wt(x)$;
    else, let $\wt'(y_x)\wt'(z_x)=1-\wt(x)$.
    For any other variable $v\in\base'$,
    $\wt'(v)=\wt(v)$.
    After this construction, $\base'$ is a base set for $\pf'$, and $\wt'(\pf')=\wt(\pf)$.
\end{lemma}
\begin{proof}
    First, we show that $\base'$ is a base set for $\pf'$.
    Clearly any assignment $\as'$ over $\base'$ can be transformed into
    an assignment $\as$ over $\base$ by substituting $\as'(y_x),\as'(z_x)$ into the formula
    $((inv \oplus x) \equiv y_x \land z_x)$ to derive the truth value of $x$.
    The fact that $\base$ being a base set for $\pf$ implies $\base'$ being a base set for $\pf'$.

    Second, we prove that $\wt'(\pf')=\wt(\pf)$.
    We only show the case for $inv=\bot$,
    since the other case can be established similarly.
    Consider any $\as$ over $\base$.
    There are two cases: $\as(x)=1$ and $\as(x) = 0$.
    In both cases, we derive corresponding assignments $\as'$ such that
    $\pcf{\pf}{\as}=\pcf{\pf'}{\as'}$ and
    $\wt(\as)=\sum\wt'(\as')$.
    In the first case $\as(x)=1$,
    the corresponding $\as'$ over $\base'$ is obtained by assigning
    $(\as'(y_x),\as'(z_x))$ to $(1,1)$ and
    $\as'(v)=\as(v)$ for any other $v\in\base'$.
    Obviously $\pcf{\pf}{\as}=\pcf{\pf'}{\as'}$,
    and $\wt(\as)=\wt'(\as')$ because $\wt(x)=\wt'(y_x)\wt'(z_x)$.
    In the second case $\as(x)=0$,
    there are three possible assignments $\as'$ over $\base'$,
    namely $(\as'(y_x),\as'(z_x))=(0,0),(0,1),(1,0)$,
    and $\as'(v)=\as(v)$ for any other $v\in\base'$.
    Denote the three assignments by $\as_1',\as_2',\as_3'$.
    Note that $\pcf{\pf}{\as}=\pcf{\pf'}{\as_1'}=\pcf{\pf'}{\as_2'}=\pcf{\pf'}{\as_2'}$,
    and $\wt(\as)=\wt'(\as_1')+\wt'(\as_2')+\wt'(\as_3')$.

    The above analysis shows that any $\as\models\pf$ can be transformed into one or multiple $\as'$
    such that $\as'\models\pf'$ and $\wt(\as)=\sum\wt'(\as')$.
    As a result, $\wt'(\pf')=\wt(\pf)$.
\end{proof}

\begin{theorem}
    \label{thm:prob-rewrite}
    Given a weighted model counting instance $\pf$ and
    a weighting function $\wt$ over a base set $\base$ of $\pf$ such that
    for any $x\in\base$, $\wt(x)$ has the form of $k/2^n$
    for some $n\in\mathbb{N}$,
    $k$ an odd integer,
    and $k < 2^n$,
    \texttt{WmcRewriting} in~\cref{alg:wmcrewriting} derives
    $\pf'$ and $\wt'$ over $\base'$ such that $\base'$ is a base set for $\pf'$,
    $\wt'(\pf')=\wt(\pf)$,
    and $\wt'(x)=\frac{1}{2}$ for every $x\in\base'$.
\end{theorem}
\begin{proof}
    To show the correctness of \texttt{WmcRewriting},
    we divide the task into two parts.
    First, we show that \texttt{WmcRewriting} always terminates.
    Second, we prove that when it terminates, the claimed properties hold.

    Consider a variable $x\in\base$ with $\wt(x)=\frac{k}{2^n}$.
    Observe that the loop invariant of the \textsc{while} loop is $wt=\frac{h}{2^m}$,
    for some $m\in\mathbb{N}$, $h$ an odd integer, and $h<2^m$.
    Moreover, after an iteration, the denominator of $wt$ will be halved,
    while the numerator remains an odd integer.
    As a result, $wt$ equals $1/2$ after $n-1$ iterations and the \textsc{while} loop terminates.

    Inside the \textsc{while} loop,
    the truth value of $inv$ is decided by comparing $wt$ with $\frac{1}{2}$,
    and the corresponding formula rewriting and weight assignments are made as described in~\cref{lemma:prob-rewrite}.
    According to~\cref{lemma:prob-rewrite},
    $\base'$ is a base set for $\pf'$ and $\wt'(\pf')=\wt(\pf)$.
    Furthermore, $\wt'(x)=\frac{1}{2}$ for every $x\in\base'$ as assigned in the algorithm.
\end{proof}
By the above theorem,
a weighted model counting instance whose weighting function is specialized as above
can be rewritten and solved by any (either exact or approximate) unweighted model counting engine,
since $\wt(\pf)=\wt'(\pf')=\sum\limits_{\as\models\pf'}\wt'(\as)=\#\pf'/2^{|\base'|}$,
where $|\base'|$ is the cardinality of the set $\base'$.
We remark that, given a variable $x$ and its weight $p=k/2^n$,
the cost, in terms of the number of added variables and clauses,
of \texttt{WmcRewriting} is linear to $n$.
In a way, $n$ can be interpreted as the degree of precision
if we attempt to apply \texttt{WmcRewriting} to approximate any arbitrary probability.

\subsection{Solving PPE via probabilistic model checking}
Probabilistic model checking (PMC) verifies stochastic systems modeled by the variants of Markov chains, e.g.,
discrete-time Markov chains (DTMCs),
continuous-time Markov chains,
and Markov decision processes,
against properties specified in probabilistic temporal logics.
We show how to calculate signal probability with the probabilistic model checker \prism~\cite{Kwiatkowska2002PRISM},
which provides a high level modeling language to specify probabilistic systems.

We convert an SPBN to a DTMC and encode the calculation of signal probabilities
by probabilistic computation tree logic (PCTL)~\cite{Hansson1989}.
To illustrate, we briefly introduce the syntax of \prism.
The basic components in \prism are \texttt{modules}.
A module consists of two parts: \texttt{variables} and \texttt{commands}.
Variables describe possible states of a module,
while commands describe its state transitions.
A command is composed of a \texttt{guard} and some \texttt{updates}.
For example, ``$x=0 \rightarrow 0.8:(x'=0) + 0.2:(x'=1);$''
is a command with a guard ``$x=0$'' and an update rule ``$0.8:(x'=0) + 0.2:(x'=1)$''.
When the guard is met, i.e., $x=0$ at the current time slot,
$x$ will remain at value $0$ with probability $0.8$ or change to $1$ with probability $0.2$ at the next time slot.

If the guards of multiple commands are met simultaneously at the same time slot,
\prism will choose exactly one of them to execute uniformly at random.
However, the vertices of an SPBN $G=(V,E)$ operate concurrently.
That is, at one time slot, multiple vertices have to be executed,
provided that every fanin of those vertices is evaluated.
Without proper control, \prism will randomly choose one of these vertices to execute,
and may bias the probabilities specified by the SPBN.
To prevent such bias, we introduce a fresh variable for each vertex
to enforce an topological execution order of logic gates in the SPBN.
This construction eliminates the possibility of the multi-vertex execution at one time slot,
and thus preserving the probability specified in the update rules.
Since $G$ is a combinational design,
this enforcement of ordering will not affect the system behavior.

Given an SPBN $G=(V,E)$ with a parameter assignment $\pi$ to $V_I$,
the procedure to compute the signal probability of an arbitrary vertex with \prism is as follows.
\begin{enumerate}
    \item Sort $V$ into a topological order.
    \item For each vertex $v\in V$, create a module with two Boolean variables:
          $x_v$ represents the output variable of vertex $v$,
          and $y_v$ enforces the execution order in the DTMC.
          Both variables are initialized to $0$.
          Let $u$ be the vertex preceding $v$ in the topological order.
    \item If $v\in V_I$, add a command:
          ``$(y_u=1 \enskip\&\enskip y_v=0) \rightarrow
              \pi(v):(x_v'=1 \enskip\&\enskip y_v'=1)+
              1-\pi(v):(x_v'=0 \enskip\&\enskip y_v'=1)$''
          to the module of $v$.
    \item If $v\in V\setminus V_I$, add a command:
          ``$(y_u=1 \enskip\&\enskip y_v=0) \rightarrow
              p_v:(x_v'=\neg f_v \enskip\&\enskip y_v'=1)+
              1-p_v:(x_v'=f_v \enskip\&\enskip y_v'=1)$''
          to the module of $v$.
    \item Compute the signal probability of any $v\in V$ by specifying a PCTL formula $P_{=?}(F(x_v=1))$.
\end{enumerate}

The added commands describe the probabilistic behavior of a vertex.
Observe that in both commands,
a vertex $v$ is executed only after its preceding vertex $u$ is executed,
and this order in enforced by the variable $y_v$.
After the execution of $v$,
$y_v$ is set to 1 to trigger its successive executions.
The PCTL formula $P_{=?}(F(x_v=1))$ computes the probability of $x_v=1$ in the future.
Since in our DTMC, each node is executed only once,
the PCTL formula computes the signal probability of $v$.

We remark that this transformation brutally encodes each gate into a module in the DTMC and suffers from the state-space explosion problem.
It remains future investigation to search for better encoding.


\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\usepackage{hyperref}

%opening
\title{GPGPU Prac 2: The Mandelbrot Set}
\author{Antonio Peters}

\begin{document}

\maketitle

\section{The Mandelbrot Set}
The Mandelbrot Set is a collection of complex numbers $c$ such that iterating the equation
\begin{equation}
  z_{i+1} = z_i^2 + c, \qquad z_0=0
\end{equation}
does not tend to infinity.
\linebreak
For this to hold true, firstly the number must be within radius $2$ of the origin, $0$. The set generated can be seen in Figure \ref{mandelimg}
\begin{figure}[H] \label{mandelimg}
\includegraphics[width=\textwidth]{Mandelset_hires.png}
\caption{The Mandelbrot Set}
\end{figure}
The most interesting notion about this is the fact that the pattern generated by the Mandelbrot Set is recursive, each node on the surface of the main lobe has on its surface a replicate set of nodes and similarly for these subnodes extending infinitely. In order to study this however we need to reduce this amount, we do this by setting the size of the image being generated and setting an upper limit to the number of iterations the set goes through. In the case of this task these particular settings were set to $4096$x$4096$ for the image size and $10000$ for the maximum number of iterations.

\section{CPU Implementation}
The code used to generate a CPU implementation of the Mandelbrot Set was originally taken from \url{https://rosettacode.org/wiki/Mandelbrot_set#C}, the code was then re-factored to be better ported to a GPU such that the only differences between them were the essential elements being timed. The code works by nesting two for-loops and iterating over the X- and Y-axis and calculating the whether or not the point, scaled to fit on the $(-2,-2i) to (2,2i)$ plane, is in the Mandelbrot Set for the given number of iterations. This linear method generated the set in $115453.000000$ milliseconds, setting a baseline for the GPU implementation to work on.

\section{Naive GPU Implementation}
The GPU implementation was created by taking the general algorithm of the CPU implementation and assigning a thread to each point of the set, further divided into blocks and grids. Since the the 10000 iterations for set inclusion rely on each other, this could not be parallelized. Once calculated, the data is then transferred back to the CPU, to be written to a file in the exact same manner as the CPU implementation to minimize the differences between them to only that of the actual algorithm implementation. The time taken by this method is $5341.878418$ milliseconds, a fraction of the time of that of the CPU time. However, further analysis through the NVIDIA Visual Profiler shows that this too can be improved on. Although the process uses $100\%$ of its computation capacity, it does not use any computation/memory transfer capabilities to overlap data transfers.

\section{Optimized GPU Implementation}
Due to the nature of the Mandelbrot Set code, no data is read in to be used, it simply takes generates an x,y-coordinate using the threads data and then scales it before computing the point so there are no reads which need optimizing and there is only one transfer of data, namely from the GPU to the CPU, so this is the only way in which memory can be optimized. Therefore, streams were introduced to allow for asynchronous data transfers. Using two streams an execution time of $5335.469727$ milliseconds, a very minor speed up, but it also alludes to the fact that with larger data sets, the overhead cost of having streams can be made up for with the ability to asynchronously transfer data.
\linebreak
\linebreak
Although compute occupancy could not be increased, an approach with fewer threads was looked at with data iterations in the kernel, meaning each thread calculates more than one point value. This was tested with two calculations per thread for a time of $5309.734863$, again only a minor speed up given that the data set is large with an unparallizable loop of $10000$ iterations but it is the only way to increase the computational optimization of the program.
\linebreak
\linebreak
Since there is only one kernel and no kernel memory reads, there is no possibility for latency optimization other that the streams, which have already been explored.
\linebreak
\linebreak
By utilizing both streams, asynchronous data transfers, and multiple iterations per thread we get a compounded speed up with an execution time of $5273.914551$, which is faster than either of the optimizations on their own.

\end{document}


%!TEX root = ../thesis.tex
\chapter{Future Work}
\label{future_work}

\section{Publicly verifiable zero knowledge proof}
\label{future_work:zkp_ver}

In the scheme presented in Chapter~\ref{solution}, only the requestor can verify the proof produced by the data processor crafted for her request. The output of the processing must be remain private. For that reason, is stored encrypted in the blockchain. As the output is a crucial input to the verification algorithm, only the requestor can validate the proof. This gives the requestor an opportunity to defy data processor's legitimacy and validity forcing the data processor to resort to a third part trusted entity that will enforce the data requestor to disclose the output of the process. To eliminate this, the verification algorithm must be run on the blockchain, where anyone can validate the proof, without revealing the output of the processing. The input of the verification algorithm must be encrypted. To achieve this, the proof generation algorithm must include the encryption procedure that encrypts the output. This ensures that the ciphertext corresponds to the output of the processing. Implementing the verification algorithm in the blockchain eliminates, also, the need of the salt (§~\ref{solution:proof}). The output is encrypted and an adversary cannot brute-force it efficiently.

\section{Secure Multi party computation}
\label{future_work:mpc}

In the setting of \textit{multiparty computation}~\cite{Ben-Or:1988:CTN:62212.62213}, sets of two or more parties with private inputs wish to jointly compute some (predetermined) function of their inputs~\cite{mpc}. Secure multiparty computation assume malicious behavior by a subset of participant entities.

The two important requirements of any secure computation protocol are \textit{privacy} and \textit{correctness}. The privacy requirement states that the parties should not learn anything else than the output of the computation and the correctness requirement states that each party should receive its correct output~\cite{mpc}.

Informally, consider $n$ parties with private inputs $x_1, x_2, \dots, x_n$. The parties want to compute the outcome of the function $f(x_1, x_2, \dots, x_n)$ where the respective inputs remain private.

The first secure multiparty computation problem was described by Yao in~\cite{Yao:1982:PSC:1398511.1382751} and is called the \textit{Yao's Millionaires' problem}. The problem discusses two millionaires, Alice and Bob, who are interested in knowing which of them is richer without revealing their actual wealth. Specifically, Yao’s millionaires’ problem is the problem of computing the predicate, $a \geq b$ where $a$ is Alice's holding and $b$ is Bob's holding, without disclosing anything more than the result to either party~\cite{mpc_ioannidis}.

Multi-party computation protocols have a wide range of applications. They can be used in voting systems where each party votes for a candidate and they want to compute the winner of the voting without revealing their vote. Another use case it that of auctions. Several parties are bidding for a product where the winning party and maximum bid should be determined, without revealing bids of other parties

Most MPC protocols make use of \textit{secret sharing}. A secret sharing scheme allows a value to be shared among $n$ parties where some of the parts or all of them are needed in order to reconstruct the secret~\cite{Kamm:2015:ASM:2836836}. Usually, there is a threshold $t$ so that at least $t$ part of the secret are needed to reconstruct the original secret.

Using an MPC protocol based on secret sharing eliminates the need of symmetric key exchange and dataset decryption and exposition (§~\ref{solution:flow:pr_req}, §~\ref{solution:flow:pr_data}). Data queries can be computed in a distributed way with the use of an MPC cluster of data processors. In addition, datasets can be split between data processors without them having access to the data in its entirety~\cite{DBLP:journals/corr/ZyskindNP15}. This way, the need for a trusted processor is eliminated as the data processors do not have access to the unciphered dataset.

\section{Fees}
\label{future_work:fees}

As discussed in~\ref{solution:treat_model:mrequestor} a malicious requestor can threat the system by overflowing the network with multiple requests aiming to prevent other request to be fulfilled. A scalable \textit{payment system} could be used as a countermeasure to this type of attacks where a requestor pays a fixed price per byte processed. The price can decrease as the data size increases.

A payment system helps to prevent DDoS attacks as each request has a cost and the attack becomes more expensive as the requests are increasing. A rational malicious requestor has to significantly gain more than the cost of the attack to be profitable. Moreover, a payment system will incentivize the data processors to follow the protocol honestly and contribute to the prosperity of the network.

\section{Privacy Preserving Queries}
\label{future_work:ppq}

The algorithms (queries) the system supports are not privacy-preserving. The privacy of the individuals in the dataset must be protected with various privacy-preserving techniques such as differential privacy~\cite{differential_privacy}, k-anonymity~\cite{Samarati98protectingprivacy} and l-diversity~\cite{Aggarwal2008}. This techniques can be either applied by the data controllers before handing over the dataset to the processor or by the processors themselves where a requestor wants the de-identification of the dataset as a processing procedure.

\section{Reputation system}
\label{future_work:ranking_system}

A \textit{decentralized reputation system}~\cite{trust_is_risk}, resilient to Sybil attacks, could eliminate the need of a centralized trust model of a public key infrastructure (PKI), which relies on a trusted entity to authenticate, identify and verify the participants of the system. The users in such systems built trust relationships among them and measure trustworthiness in a setting where assets can be exchanged between them~\cite{trust_is_risk}. The benefits of such systems are \textit{pseudonymity} of the participants, truly decentralization and the increasing trust for the system itself.

A data controller, whom its dataset are of bad quality or fabricated with malicious intents, could be identified by the users of the system and gain bad reputation. It is evident, that the users of the network should choose datasets where their owners have high trust. The same applies to data processors and even the requestor themselves.

\section{Analytics}
\label{future_work:analytics}

The activity of the system could be analyzed by various tools to measure the functionality and the prosperity of the system. To achieve that, blockchain should be indexed and be monitored constantly by an analytic node that stores in a database all the needed information. Various charts and results can be derived by such analysis. For example:

\begin{itemize}
  \item Transaction chart
  \item Address growth chart
  \item Hash rate growth chart
  \item Block difficulty
  \item Pending transactions per minute
  \item Network transaction fees
  \item Total dataset processing requests
  \item Total datasets
  \item Total processors
  \item Total data controllers
  \item Most trusted processors or controllers
  \item Most used datasets
  \item Most used algorithms
  \item Top 10 charts
\end{itemize}

\section{Consent}
\label{future_work:consent}

A key aspect that is missing from the current solution is the implementation of \textit{dynamic consent} which can empower the data owners. With the use of smart contracts data access policies could be implemented where data controllers are obligate to comply to them. That way, data owners have total control over their data and can decide when and by whom their data are accessed.

Modeling dynamic consent in smart contracts should be carefully analyzed taking into account design issues that are related to smart contracts lifecycle, required state variables for storing contract’s information, and access restrictions to those variables.

Neisse et al.~\cite{DBLP:journals/corr/NeisseSF17} proposed the following three models for data accountability and provenance tracking that comply with the GDPR(§~\ref{problem:regulations}):

\begin{enumerate}
  \item Contract for a specific controller: A contract where the data subject creates a contract tailored for each data controller
  \item Contract for specific data: A contract where each subject’s data instance is shared among all data controllers
  \item Contract for multiple data subjects: A contract where the data controller specifies how the data from all subjects are treated from the controller
\end{enumerate}

The first contract is more adequate for sensitive data~\cite{DBLP:journals/corr/NeisseSF17}, such as health data, since a subject-controller relationship~\cite{Azaria2016} is being created where each patient has a different contract for each controller accessing their data, providing fine grained access control and provenance information. On the other hand, it has the highest cardinality among the others two types~\cite{DBLP:journals/corr/NeisseSF17}. The second contract suffers from direct linkability as a unique subject address is needed compromising patients’ privacy~\cite{DBLP:journals/corr/NeisseSF17}. Lastly, the third one has the lowest cardinality among the others but also has the lower level of customization due to the limited number of contract options~\cite{DBLP:journals/corr/NeisseSF17}.


% Standard Article Definition
\documentclass[]{article}

% Page Formatting
\usepackage[margin=1in]{geometry}
\setlength\parindent{0pt}

% Graphics
\usepackage{graphicx}

% Math Packages
\usepackage{physics}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{mathtools}

% Extra Packages
\usepackage{listings}
\usepackage{hyperref}

% Section Heading Settings
\usepackage{enumitem}
\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand*{\thesection}{Problem \arabic{section}}
\renewcommand*{\thesubsection}{\alph{subsection})}
\renewcommand*{\thesubsubsection}{\quad \quad \roman{subsubsection})}

%Custom Commands
\newcommand{\Rel}{\mathcal{R}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}

\newcommand{\toI}{\xrightarrow{\textsf{\tiny I}}}
\newcommand{\toS}{\xrightarrow{\textsf{\tiny S}}}
\newcommand{\toB}{\xrightarrow{\textsf{\tiny B}}}

\newcommand{\divisible}{ \ \vdots \ }
\newcommand{\st}{\ : \ }

% Theorem Definition
\newtheorem{definition}{Definition}
\newtheorem{assumption}{Assumption}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}

%opening
\title{MATH 5301 Elementary Analysis - Homework 10}
\author{Jonas Wagner}
\date{2021, November 12\textsuperscript{th}}

\begin{document}

\maketitle

% Problem 1 ----------------------------------------------
\section{}
Compute the derivatives of the following functions:

% Derivative
\begin{definition}
    Let $f : (a,b) \to \R$ be a function.
    \begin{enumerate}
        \item The \emph{\underline{derivative of the function at point $x_0$}} is defined as
        \[
            f'(x_0) := \lim_{x \to x_0} \cfrac{f(x) - f(x_0)}{x - x_0}
        \]
        \item If the derivative is defined at $x_0$, then it is \emph{\underline{differentiable at $x_0$}}.
        \item If the derivative is defined for all $x_0 \in (a,b)$, then the function $f$ is said to be \emph{\underline{differentialble}}.
        \item When $f$ is differentiable, the \underline{\emph{derivative}} of $f(x)$ is defined as:
        \[
            f'(x) := \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}
        \]
    \end{enumerate}
\end{definition}

%Part a
\subsection{
    $x^2 \sin{\frac{1}{x}}$
}
Let
\[
    f(x) = x^2 \sin{\frac{1}{x}}
\]
Then, by definition, the derivative of $f(x)$ is calculated as
\begin{align*}
    f'(x)
    &= \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            (x + h)^2 \sin(\frac{1}{x + h}) - x^2 \sin(\frac{1}{x})
            }{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            \dv{h}\qty((x + h)^2 \sin(\frac{1}{x + h}) - x^2 \sin(\frac{1}{x}))
            }{
                \dv{h} h
            }\\
    &= \lim_{h \to 0}
        \cfrac{
            2 (x + h) \sin(\frac{1}{x + h}) + (x + h)^2 \qty(\frac{-1}{(x+h)^2}) \cos(\frac{1}{x + h})
            }{1}\\
    &= \lim_{h \to 0} 2 (x + h) \sin(\frac{1}{x + h}) - \cos(\frac{1}{x + h})\\
    \Aboxed{
        f'(x)
        &= 2 x \sin(\frac{1}{x}) - \cos(\frac{1}{x})
        }
\end{align*}

%Part b
\subsection{
    $\cfrac{e^x + e^{-x}}{2}$
}
Let
\[
    f(x) = \cosh(x) = \cfrac{e^x + e^{-x}}{2}
\]
Then, by definition, the derivative of $f(x)$ is calculated as
\begin{align*}
    f'(x)
    &= \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            \cfrac{e^{(x+h)} + e^{-(x + h))}}{2} + \cfrac{e^x + e^{-x}}{2}
            }{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x + h} + e^{-x - h} + e^{x} + e^{-x}
        }{
            2 h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x} e^{h} + e^{-x} e^{-h} + e^{x} + e^{-x}
        }{
            2 h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            \dv{h} \qty(e^{x} e^{h} + e^{-x} e^{-h} + e^{x} + e^{-x})
        }{
            \dv{h} 2 h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x} e^{h} - e^{-x} e^{-h}
        }{
            2
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x + h} - e^{-x - h}
        }{
            2
        }\\
    \Aboxed{
        f'(x)
        &= \cfrac{e^{x} - e^{-x}}{2} = \sinh(x)
        }
\end{align*}

%Part c
\subsection{
    $\cfrac{e^x - e^{-x}}{2}$
}
Let
\[
    f(x) = \sinh(x) = \cfrac{e^x - e^{-x}}{2}
\]
Then, by definition, the derivative of $f(x)$ is calculated as
\begin{align*}
    f'(x)
    &= \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            \cfrac{e^{(x+h)} - e^{-(x + h))}}{2} + \cfrac{e^x - e^{-x}}{2}
            }{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x + h} - e^{-x - h} + e^{x} - e^{-x}
        }{
            2 h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            \dv{h} \qty(e^{x + h} - e^{-x - h} + e^{x} - e^{-x})
        }{
            \dv{h} 2 h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x + h} + e^{-x - h}
        }{
            2
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            e^{x + h} + e^{-x - h}
        }{
            2
        }\\
    \Aboxed{
        f'(x)
        &= \cfrac{e^{x} + e^{-x}}{2} = \cosh(x)
        }
\end{align*}

%Part d
\subsection{
    $e^x + e^{e^x} + e^{e^{e^x}}$
}
Let
\[
    f(x) = e^x + e^{e^x} + e^{e^{e^x}}
\]
Then, by definition, the derivative of $f(x)$ is calculated as
\begin{align*}
    f'(x)
    &= \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}\\
    &= \lim_{h \to 0}
        \cfrac{e^{x+h} + e^{e^{x+h}} + e^{e^{e^{x+h}}} - \qty(e^x + e^{e^x} + e^{e^{e^x}})
            }{h}\\
    &= \lim_{h \to 0} \cfrac{e^{x+h} - e^x}{h}
        + \lim_{h \to 0} \cfrac{e^{e^{x + h}} - e^{e^x}}{h}
        + \lim_{h \to 0} \cfrac{e^{e^{e^{x + h}}} - e^{e^{e^x}}}{h}\\
    &= \lim_{h \to 0} \cfrac{
        \dv{h} \qty(e^{x+h} - e^x)
        }{\dv{h} h}
        + \lim_{h \to 0} \cfrac{
            \dv{h} \qty(e^{e^{x + h}} - e^{e^x})
            }{h}
        + \lim_{h \to 0} \cfrac{
            \dv{h} \qty(e^{e^{e^{x + h}}} - e^{e^{e^x}})
            }{\dv{h} h}\\
    &= \lim_{h \to 0}
            \cfrac{(1)e^{x+h}}{1}
        + \lim_{h \to 0}
            \cfrac{
                (1)(e^{x+h})(e^{e^{x+h}})
                }{1}
        + \lim_{h \to 0}
            \cfrac{
                (1)(e^{x+h})(e^{e^{x+h}})(e^{e^{e^{x+h}}})
                }{1}\\
    &= \lim_{h \to 0} e^{x+h}
        + \lim_{h \to 0} e^{x + h} e^{e^{x + h}}
        + \lim_{h \to 0} e^{x + h} e^{e^{x + h}} e^{e^{e^{x + h}}}\\
    \Aboxed{
        f'(x)
        &=  e^{x} + e^{x} e^{e^{x}} + e^{x} e^{e^{x}} e^{e^{e^{x}}}
        = e^{x} + e^{x + e^{x}} + e^{x + e^{x} + e^{e^{x}}}
    }
\end{align*}

\newpage
%Part e
\subsection{
    $x^{x^{x^x}}$
}
Let
\[
    f(x) = x^{x^{x^{x}}}
\]
Then, by definition, the derivative of $f(x)$ is calculated as
\begin{align*}
    f'(x)
    &= \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}\\
    &= \lim_{h \to 0}
        \cfrac{
            (x + h)^{(x + h)^{(x + h)^{(x + h)}}} - x^{x^{x^{x}}}
        }{
            h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            \dv{h} \qty((x + h)^{(x + h)^{(x + h)^{(x + h)}}} - x^{x^{x^{x}}})
        }{
            \dv{h} h
        }\\
    &= \lim_{h \to 0}
        \cfrac{
            \dv{h} \qty((x + h)^{(x + h)^{(x + h)^{(x + h)}}})
        }{
            1
        }
    \intertext{
        Exponent Rule: $a^b = e^{b \ln{a}}$
    }
    &= \lim_{h \to 0} \dv{h} \qty(
        e^{\qty(
            (x + h)^{(x + h)^{(x + h)}}
            \ln(x + h)
        )}
    )
    \intertext{
        Chain Rule: $\dv{f}{x} = \dv{f}{u} \dv{u}{x}$
    }
    &= \lim_{h \to 0}
        \dv{e^{u}}{u}\dv{u}{h}
    \intertext{
        with $u = (x + h)^{(x + h)^{(x + h)}} \ln(x + h)$
    }
    &= \lim_{h \to 0} e^{u} \dv{h} \qty(
        (x + h)^{(x + h)^{(x + h)}} \ln(x + h)
    )\\
    &= \lim_{h \to 0} e^{u} \Big[
        \qty((x + h)^{(x + h)^{(x + h)}}) \frac{1}{x + h}\\
        &\quad + \ln(x + h) \dv{h} e^{
            (x + h)^{(x + h)}
            \ln(x + h)
        }
    ]\\
    &\vdots\\
    &= \lim_{h \to 0}
        (x + h)^{(x + h)^{(x + h)^{(x + h)}}} \\
        &\qquad \Bigg[(x + h)^{(x + h)^{(x + h)}-1}\\
            &\qquad \qquad + \Bigg(
                (x + h)^{(x + h)^{(x + h)}} \ln(x + h) \Big(
                    (x + h)^{h + x - 1}\\
                    &\qquad \qquad \qquad \qquad
                    + (x + h)^{x + h} \ln(x + h) \qty(
                        1 + \ln(x + h)
                    )
                \Big)
            \Bigg)
        \Bigg]
\end{align*}

Then
\[\boxed{
    f'(x) = x^{x^{x^{x}}} \qty(
        x^{x^{x}}\ln(x) \qty(
            x^{x}\ln(x) \qty(\ln(x) + 1) + x^{x^{x - 1}}
        )
        +x^{x^{x} - 1}
    )
}\]

% Problem 2
\newpage
\section{}

% Differentiable Function
\begin{definition}
    A \emph{\underline{differentiable function}} over $(a,b)$ is a function $f$ so that $f'(x)$ exists for all $x \in (a,b)$.
\end{definition}

% Bounded Function
\begin{definition}
    A \emph{\underline{bounded function}} is a function so that
    \[
        \exists_{N \in \R} \st \forall_{x \in (a,b)} \abs{f(x)} < N
    \]
\end{definition}

% Unbounded Function
\begin{definition}
    An \emph{\underline{unbounded function}} is a function that is not bounded.
\end{definition}

\begin{definition}
    A function $f : X \to Y$ is \emph{\underline{Uniformly Continous}} if
    \[
        \forall_{\epsilon > 0} \exists_{\delta(\epsilon) > 0} \st \forall_{x,y \in X} \norm{x - y} < \delta \implies \norm{f(x) - f(y)} < \epsilon
    \]
    Note: this is stricter then continuity itself with the only difference that $\exists_{\delta}$ is constant $\forall_{x,y \in X}$; whereas a \emph{\underline{Continous}} function only requires that this is true for some $\delta$ dependent on $\epsilon$, $x$, and $y$:
    \[
        \forall_{\epsilon > 0} \forall_{x,y \in X} \exists_{\delta(\epsilon,x,y) > 0} \st \norm{x - y} < \delta \implies \norm{f(x) - f(y)} < \epsilon
    \]
\end{definition}

%Part a
\subsection{Prove the following:}
\begin{theorem}
    If $f \st (-1,1) \to \R$ is a differentiable unbounded function, then $f'$ is also unbounded on $[-1,1]$.
    \begin{proof}
        When $f$ is unbounded,
        \[
            \forall_{N \in \R} \exists_{x \in (-1,1)} \st \abs{f(x)} \geq N
        \]
        then $f'$ is defined by
        \[
            f'(x) := \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}
        \]
        Since the derivative is an instantaneous 'rise' over 'run', in order for no bound to exists within a bounded interval $(-1,1)$, the differentiable (and therefore continuous) function must have an asymptote at the boundaries. This implies that within the closed interval, the derivative must also be unbounded to obtain the the asymptote on the boundary.
    \end{proof}
\end{theorem}

%Part b
\subsection{
    Provide an example of bounded differentiable function on $[-1,1]$ with an unbounded derivative.
}
\begin{theorem}
    $f(x) = \sqrt{x + 1}$ is a bounded differentiable function on $[-1,1]$, but has an unbounded derivative.
    \begin{proof}
        Clearly, $f(x)$ is fully defined and bounded on $[-1,1]$.
        The domain of $\sqrt{x + 1}$ is $\{x \in \R \st x \geq -1\}$ while the range for $x \in [-1,1]$ is $\{y \in [0,\sqrt(3)]\}$.

        The derivative of $f$ is defined as
        \[
            f'(x) = \cfrac{1}{2 \sqrt{x + 1}}
        \]
        which is actually bounded on $x \in (-1,1]$, but an asymptote exists at $x = -1$ in which
        \[
            \lim_{x \to -1^+} \cfrac{1}{2 \sqrt{x + 1}} = + \infty
        \]
        and is clearly unbounded.
    \end{proof}
\end{theorem}

%Part c
\subsection{Prove the following:}
\begin{theorem}
    If $f \st (-1,1) \to \R$ is a differentiable function, such that $f'$ is bounded on $[-1,1]$, then $f$ is uniformly continuous.
    \begin{proof}
        $f$ differentiable on $x \in (-1,1)$ means
        \[
            \exists f'(x) = \lim_{h \to 0} \cfrac{f(x + h) - f(x)}{h}
        \]
        $f'$ bounded on $x \in [-1,1]$ means $f'(x)$ is bounded on $x \in (-1, 1)$ and that the following is bounded:
        \[
            \lim_{h \to 0^{+/-}} \cfrac{f(x + h) - f(x)}{h}
        \]
        which is equivalent to saying that these two limits exists and are bounded.
        \[
            \lim_{x \to (+/-)1^{+/-}} f(x)
        \]
        Since it is already known that $f$ is differentiable on $x \in (-1,1)$, this implies that $f$ is continuous, i.e:
        \[
            \forall_{\epsilon > 0} \forall_{x,y \in (-1,1)} \exists_{\delta(\epsilon,x,y) > 0} \st \norm{x - y} < \delta \implies \norm{f(x) - f(y)} < \epsilon
        \]
        and since $f'$ is bounded on the entire closed domain, a constant finite bound $\delta$ will exist to bound the 'run' ($\norm{x - y}$) for an arbitrary 'rise' ($\norm{f(x) - f(y)}$).
        Additionally, the lack of asymptotes at the boundaries also implies that continuity of the open domain will extend to the closed domain.
        Therefore $f$ is uniformly continuous, i.e:
        \[
            \forall_{\epsilon > 0} \exists_{\delta(\epsilon) > 0} \st \forall_{x,y \in [-1,1]} \norm{x - y} < \delta \implies \norm{f(x) - f(y)} < \epsilon
        \]
    \end{proof}
\end{theorem}

% Problem 3
\newpage
\section{}
Find $f^{(n)}(0)$ for the following functions:

% n-th Derivative
\begin{definition}
    Let $f : (a,b) \to \R$ be a differentiable function.
    \begin{enumerate}
        \item If $f' : (a,b) \to \R$ is also differentiable, $f$ is called \emph{\underline{twice differentiable}}.
        \item The derivative of $f'$ is then denoted as $f''$ and is called the \emph{\underline{Secound Derivative}}.
        \item The \emph{\underline{n-th Derivative}}, denoted by $f^{(n)} : (a,b) \to \R, n \in \N$, is defined by repeating differentiation on the next derivative:
        \begin{enumerate}
            \item $n = 0, \ f^{(0)} = f$
            \item If $f^{(n)}$ is defined, for $n \geq 0$, then $f^{(n+1)} = \dv{x} (f^{(n)})$.
        \end{enumerate}
        \item If $f$ has derivatives up until the order $n, n \geq 1$, then $f$ is \emph{\underline{n-times differentiable}}.
        \item If $f^{(n)}$ is continuous, the $f$ is \emph{\underline{n-times continously differentiable}}; which is also known as $f$ is of class $C^n$.
    \end{enumerate}
\end{definition}

% Leibnitz Formula
\begin{theorem}
    \textbf{Leibnitz Formula:}
    Let $f,g : (a,b) \to \R$ be n-differentiable functions.
    Then for $1\leq m \leq n$, the m-th derivative of $f(x)g(x)$ is given by:
    \[
        \dv[m]{x}\qty(f(x) g(x)) = \sum_{k=0}^m \mqty(m \\ k) f^{(m-k)}(x) g^{(k)}(x)
    \]
    \begin{proof}
        Proof provided in the lecture notes: Theorem 6.20
    \end{proof}
\end{theorem}

%Part a
\subsection{
    $\sin(ax)\cos(bx)$
}
It is known, and can be proven using Euler's identity, that the derivatives of sinusoidal functions follow the following progression:
    \begin{enumerate}
        \item $\dv{x} \cos(x) = - \sin(x)$
        \item $\dv{x} -\sin(x) = - \cos(x)$
        \item $\dv{x} -\cos(x) = \sin(x)$
        \item $\dv{x} \sin(x) = \cos(x)$
    \end{enumerate}
Additionally, from the chain rule, the m-th derivative of a domain scaled function, $f(a x)$ will be given by
\[
    \dv[m]{x} f(a x) = a^{m} f^{(m)}(u), \ u = a x
\]

Let $f_1(x) = \sin(ax)$ and $f_2(x) = \cos(bx)$, by Euler's formula,
\[
    f_1(x) = \sin(ax) = \cfrac{e^{j a x} - e^{- j a x}}{2 j}
\]
and
\[
    f_2(x) = \cos(bx) = \cfrac{e^{j b x} + e^{-j b x}}{2}
\]

The m-th derivatives can be defined in many ways, but the following begins by recognizing that $g(x) = a^{-1} f'(x) = a^{-1} f^{(1)}(x)$; and additionally, $g^{(m)}(x) = a^{-m - 1} b^{m} f^{(m + 1)}(\frac{b}{a}x)$.

The m-th derivatives of $f$ and $g$ are then clearly given as:
\[
    f_1^{(m)}(x)
    = a^m (j)^{m} \cfrac{e^{j a x} - (-1)^{m} e^{- j a x}}{j 2}
    = a^m (j)^{m - 1} \cfrac{e^{j a x} + (-1)^{m - 1} e^{- j a x}}{2}
\]
and
\[
    f_2^{(m)}(x)
    = b^m (j)^{m} \cfrac{e^{j b x} + (-1)^{m} e^{- j b x}}{2}
\]

By the Leibnitz Formula, the m-th derivative of $f_1(x) f_2(x)$ can be calculated as follows:
\[
    \dv[m]{x}\qty(f_1(x) g_2(x))
    = \sum_{k=0}^m \mqty(m \\ k) f_1^{(m-k)}(x) f_2^{(k)}(x)
\]
\begin{align*}
    \dv[m]{x}\qty(\sin(ax) \cos(bx))
        &= \sum_{k=0}^m \mqty(m \\ k)
            \qty(a^{m - k} (j)^{m - k - 1} \cfrac{e^{j a x} + (-1)^{m - k - 1} e^{- j a x}}{2})
            \qty(b^k (j)^{k} \cfrac{e^{j b x} + (-1)^{k} e^{- j b x}}{2})\\
    \Aboxed{
    \dv[m]{x}\qty(\sin(ax) \cos(bx))
        &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k)
            \qty((j)^{m - k - 1} \cfrac{e^{j a x} + (-1)^{m - k - 1} e^{- j a x}}{2})
            \qty((j)^{k} \cfrac{e^{j b x} + (-1)^{k} e^{- j b x}}{2})
    }\\
\end{align*}
Which, using Euler's formula again, can be converted back into many different configurations of sinusoidal forms, but regardless, this can be evaluated for $f^{(m)}(0)$ within this complex exponential form:
\begin{align*}
    f^{(m)} (0)
    &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k)
        \qty((j)^{m - k - 1} \cfrac{e^{j a (0)} + (-1)^{m - k - 1} e^{- j a (0)}}{2})
        \qty((j)^{k} \cfrac{e^{j b (0)} + (-1)^{k} e^{- j b (0)}}{2})\\
    &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k)
        \qty((j)^{m - k - 1} \cfrac{(1) + (-1)^{m - k - 1} (1)}{2})
        \qty((j)^{k} \cfrac{(1) + (-1)^{k} (1)}{2})\\
    &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k)
        \qty((j)^{m - k - 1 + k} \cfrac{(1) + (-1)^{m - k - 1}}{2})
        \qty[\begin{cases}
            \qty(\cfrac{(1) + (-1)^{k}}{2})
            &k \divisible 2\\
            \qty(\cfrac{(1) + (-1)^{k}}{2})
            &(k - 1) \divisible 2
        \end{cases}]
    \intertext{
        Clearly, when $(k-1) \divisible 2$, $\frac{1 + (-1)^k}{2} = 0$,
        otherwise, $\frac{1 + (-1)^k}{2} = 1$.
    }
    &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k)
        \qty((j)^{m - 1} \cfrac{(1) + (-1)^{m - k - 1}}{2})
        \qty[\begin{cases}
            (1)
            &k \divisible 2\\
            (0)
            &(k - 1) \divisible 2
        \end{cases}]\\
    &= \sum_{k=0}^m \mqty(m \\ k) \qty(a^{m - k} b^k (j)^{m - 1})
        \qty[\begin{cases}
            \cfrac{1 - 1}{2} = 0
            &(k \divisible 2) \land (m - k \divisible 2)\\
            \cfrac{1 + 1}{2} = 1
            &(k \divisible 2) \land (m - k - 1 \divisible 2)\\
            0
            &(k - 1) \divisible 2
        \end{cases}]
    \intertext{
        Since $m - 1 \divisible 2 \implies (k \divisible 2) \land (m - k - 1 \divisible 2)$,
    }
    &= \begin{cases}
        \sum_{k=0}^m \mqty(m \\ k)
        \qty[\begin{cases}
            a^{m - k} b^k (j)^{m - 1}
            &k \divisible 2\\
            0
            &(k - 1) \divisible 2
        \end{cases}]
        & m - 1 \divisible 2\\
        0 & m \divisible 2
    \end{cases}
\end{align*}
Ultimately this means that
\[
    f^{(n)}(0) = \begin{cases}
        \sum_{k = 1}^{m/2} a^{m - 2 k} b^{2 k}
        &(m  - 1 \divisible 2) \land \lnot (m \divisible 4)\\
        - \sum_{k = 1}^{m/2} a^{m - 2 k} b^{2 k}
        &(m - 1 \divisible 2) \land (m - 1 \divisible 4)\\
        0
        & m \divisible 2
    \end{cases}
\]

%Part b
\subsection{
    $x^k \sin{\frac{1}{x}}$
}
Assuming that $k \in \N$, Let
\[
    f(x) = x^k \sin{\frac{1}{x}}
\]

Let $f_1(x) = x^k$ and $f_2(x) = \sin(\frac{1}{x})$.

By Leibnitz Formula, the m-th derivative of $f_1(x) f_2(x)$ can be calculated as follows:
\[
    \dv[m]{x}\qty(f_1(x) g_2(x))
    = \sum_{k=0}^m \mqty(m \\ k) f_1^{(m-k)}(x) f_2^{(k)}(x)
\]
Therefore,
\[
    \dv[m]{x} x^k \sin(\frac{1}{x})
        = \sum_{l = 0}^m \mqty(m \\ l)
            \dv[m - l]{x} x^k
            \dv[l]{x} \sin(\frac{1}{x})
\]

It is known by the power rule, that
\[
    \dv[m]{x} x^k = \begin{cases}
        k^{m} x^{k - m} &m \leq k\\
        0 &m > k
    \end{cases}
\]

Since $f^{m}(0)$ will always let $x = 0$,
\[
    \dv[m]{x} x^k = 0 \forall_{m}
\]

Therefore,
\begin{align*}
    \dv[m]{x} x^k \sin(\frac{1}{x})
        &= \sum_{l = 0}^m \mqty(m \\ l)
            \dv[m - l]{x} x^k
            \dv[l]{x} \sin(\frac{1}{x})\\
        &= \sum_{l = 0}^m \mqty(m \\ l)
            (0)
            \dv[l]{x} \sin(\frac{1}{x})
\end{align*}
\[
    \boxed{f^{m}(0) = 0}
\]

\newpage
%Part c
\subsection{
    $f(x) =
    \begin{cases}
        e^{-\frac{1}{x^2}}, &x > 0\\
        0,                  &x \leq 0
    \end{cases}$
}

Since $\lim_{x \to 0^+} - \frac{1}{x^2} = - \infty$,
\[
    \lim_{x \to 0^+} e^{-\frac{1}{x^2}} = 0
\]

Therefore, the function is smooth and differentiable on all $\R$.

Additionally, since $\forall_{x \leq 0} f(x) = 0$,
\[
    \forall_{x \leq 0} f'(x) = 0
\]

By the Chain rule,
\[
    \forall_{x \leq 0} \ \dv{x} e^{- \frac{1}{x^2}} = \frac{2}{x^3} e^{-\frac{1}{x^2}}
\]
Similarly, by the chain rule and product rule,
\[
    \forall_{x \leq 0} \ \dv[2]{x} e^{- \frac{1}{x^2}}
    = \dv{x} \frac{2}{x^3} e^{-\frac{1}{x^2}}
    = \frac{-6}{x^4} e^{-\frac{1}{x^2}} + \frac{2}{x^3} \frac{2}{x^3} e^{-\frac{1}{x^2}}
    = \frac{2}{x^6} (2 - 3 x^2) e^{-\frac{1}{x^2}}
\]
This can then be expanded further with Leibnitz rule,
to show that
\[
    \forall_{x \leq 0} \ \dv[m]{x} e^{- \frac{1}{x^2}}
    = \sum_{k = 0}^m \mqty(m \\ k) \qty(\frac{2}{x^3})^k e^{-\frac{1}{x^2}}
\]
and since $\lim_{x \to 0^+} e^{-\frac{1}{x^2}} = 0$,
\[
    \lim_{x \to 0^+} \dv[m]{x} e^{- \frac{1}{x^2}} = 0
\]
And therefore $f^{(n)}(0) = 0$ since the two limits are the same.
Although technically, the understanding of the smoothness of $f(x)$ and the fact that $f(0) = 0$ should have been enough to demonstrate this...

% Problem 4
\newpage
\section{}
Construct an example of infinitely many times differentiable function $f(x)$ such that $f(x) = 0$ for $x \leq 0$, $f(x) = 1$ for $x \geq 1$ and $f(x)$ is strictly monotone on the interval $(0,1)$.

Using such function you could construct, for example, a monotone function $g(x)$ such that $\lim_{x \to +\infty} g(x) = 0$ but $\lim_{x \to +\infty} g'(x) \neq 0$. (How?)

\begin{definition}
    Let $f : \R \to \R$ be defined as
    \[
        f(x) := \begin{cases}
            0   &x \leq 0\\
            \frac{1 - \cos(\pi x)}{2} & x \in (0,1)\\
            1   &x \geq 1
        \end{cases}
    \]
\end{definition}

\begin{theorem}
    $f$ is a strictly monotone function over $(0,1)$, is infinitely differentiable function, has $f(x) = 0$ for $x \leq 0$ and $f(x) = 1$ for $x \geq 1$.
    \begin{proof}
        \begin{enumerate}
            \item $f$ is strictly monotone over $(0,1)$ means
                \[
                    \forall_{x \in (0,1)} \ f'(x) > 0
                \]
                Since within the interval $(0,1)$,
                $f(x) = cos(\pi x)$,
                \[
                    f'(x) = \pi \sin(\pi x)
                \]
                which is strictly positive over $(0,1)$ implying $f(x)$ is strictly increasing.
                By the definition of a monotone, $f$ is therefore a monotone function.
            \item $f$ being infinitely differentiable means that the n-th derivative is defined over the entire interval forall $n \in \N$.

                The nth derivative is in fact defined defined by the following,
                \[
                    f^{(n)}(x) = \begin{cases}
                        0 & x \in (-\infty, 0] \cup [1,\infty)\\
                        \begin{cases}
                            \pi^n \cos(\pi x) &n \divisible 4\\
                            -\pi^n \sin(\pi x) &n + 1 \divisible 4\\
                            -\pi^n \cos(\pi x) &n + 2 \divisible 4\\
                            \pi^n \sin(\pi x) &n + 3 \divisible 4
                        \end{cases}
                        &0 < x < 1
                    \end{cases}
                \]
            \item $f(x) = 0$ for $x \leq 0$ is true by the piecewise definition of $f(x)$
            \item $f(x) = 1$ for $x \leq 1$ is true by the piecewise definition of $f(x)$
        \end{enumerate}
    \end{proof}
\end{theorem}

Perhaps it is possible to complete use such a function to construct the desired function $g(x)$ using one of the monotone functions on that region, but my guess is that such a function will be monotone forall $x$ instead of only within the region as described like I did with the cosine function.
Perhaps a sigmoid variant would be useful, but I believe that any variation based on the cosine function with the piecewise will not satisfy that condition (at least with all real-values).

% \newpage
% \begin{definition}
%     Let $g : (0,\infty) \to \R$ be defined in terms of $f$ as:
%     \[
%         g(x) := x\cfrac{f(x) - 1}
%         = \begin{cases}
%             \cfrac{e^{x}(-1 - \cos(\pi x))}{2x}
%             & 0 < x < 1\\
%             0 & x \geq 0
%         \end{cases}
%     \]
% \end{definition}

% \begin{theorem}
%     The function $g(x)$ converges to 0,
%     \[
%         \lim_{x \to +\infty} g(x) = 0
%     \]
%     but the same is not the case for $g'(x)$:
%     \[
%         \lim_{x \to +\infty} \neq 0
%     \]
%     \begin{proof}
%         \begin{enumerate}
%             \item Clearly, by definition of $g(x)$, $g(x)$ converges to 0.
%             \item The derivative does not converge to zero:
%                 \begin{align*}
%                     g'(x) = \begin{cases}

%                     \end{cases}
%                 \end{align*}
%         \end{enumerate}
%     \end{proof}
% \end{theorem}

% Problem 5
\newpage
\section{}
Find the following limits

Trigonometric Derivative Reference:
\begin{align*}
    \dv{x} \sin(x) &= \cos(x)\\
    \dv{x} \cos(x) &= -\sin(x)\\
    \dv{x} \tan(x) &= \secant^2(x)\\
    \dv{x} \sin[-1](x) &= \frac{1}{\sqrt{1-x^2}}\\
    \dv{x} \cos[-1](x) &= -\frac{1}{\sqrt{1-x^2}}\\
    \dv{x} \tan[-1](x) &= \frac{1}{1 + x^2}
\end{align*}

%Part a
\subsection{
    $\lim_{x \to 0} \frac{\tan{x} - x}{x^3}$
}

\begin{align*}
    \lim_{x \to 0} \frac{\tan{x} - x}{x^3}
        &= \lim_{x \to 0} \frac{\tan{x}}{x^3} - \frac{x}{x^2}\\
        &= \lim_{x \to 0}
            \frac{\dv{x} \tan{x} - x}{\dv{x} x^3}\\
        &= \lim_{x \to 0}
            \frac{\sec^2{x} - 1}{3 x^2}\\
        &= \lim_{x \to 0}
            \frac{2 \sec^2{x}\tan{x}}{6 x}\\
        &= \lim_{x \to 0}
            \frac{(4 \sin[2](x) + 2) \sec[4](x)}{6}\\
        &= \frac{(4 (0)^2 + 2) (1)^4}{6}\\
    \Aboxed{
        \lim_{x \to 0} \frac{\tan{x} - x}{x^3}
        &= \frac{2}{6} = \frac{1}{3}
    }
\end{align*}

\newpage
%Part b
\subsection{
    $\lim_{x \to 0} \frac{\arctan(\arcsin{x}) - \arcsin(\arctan{x})}{\sin{x} - \tan{x}}$
}

\begin{align*}
    \lim_{x \to 0} \frac{\arctan(\arcsin{x}) - \arcsin(\arctan{x})}{\sin{x} - \tan{x}}
    &= \lim_{x \to 0}
        \frac{
            \dv{x} \qty(\tan[-1](\sin[-1](x)) - \sin[-1](\tan[-1](x)))
        }{
            \dv{x} \qty(\sin(x) - \tan(x))
        }\\
    &= \lim_{x \to 0}
        \frac{
            \dv{\tan[-1](\sin[-1](x))}{\sin[-1](x)} \dv{\sin[-1](x)}{x}
            - \dv{\sin[-1](\tan[-1](x))}{\tan[-1](x)}\dv{\sin[-1](x)}{x}
        }{
            \dv{\sin(x)}{x} - \dv{\tan(x)}{x}
        }\\
    &= \lim_{x \to 0}
        \frac{
            \frac{1}{\sqrt{1-x^2} (1 + \sin[-1](x)^2)}
            - \frac{1}{\sqrt{1+x^2} (1 - \tan[-1](x)^2)}
        }{
            \cos(x) - \sin(x)
        }\\
    &= \lim_{x \to 0}
        \frac{
            \frac{
                - (\sqrt{1-x^2} (1 + \sin[-1](x)^2))
                + (\sqrt{1+x^2} (1 - \tan[-1](x)^2))
            }{
                (\sqrt{1-x^2} (1 + \sin[-1](x)^2))
                (\sqrt{1+x^2} (1 - \tan[-1](x)^2))
            }
        }{
            \cos(x) - \sin(x)
        }\\
    &= \frac{
            \frac{
                -(\sqrt{1 - (0)} (1 + (0)^2))
                +(\sqrt{1 + (0)} (1 - (0)^2))
            }{
                (\sqrt{1-0^2} (1 + (0)^2))
                (\sqrt{1+0^2} (1 - (0)^2))
            }
        }{
            (1) - (0)
        }\\
    &= \frac{
        \frac{
            -1 + 1
        }{
            (1)(1)
        }
    }{1}
\end{align*}
\begin{equation*}
    \centering
    \boxed{
        \lim_{x \to 0} \frac{\arctan(\arcsin{x}) - \arcsin(\arctan{x})}{\sin{x} - \tan{x}}
        = 0
    }
\end{equation*}

%Part c
\subsection{
    $\lim_{x \to +\infty} \frac{x^{\ln{x}}}{(\ln{x})^x}$
}

\begin{align*}
    \lim_{x \to +\infty} \frac{x^{\ln{x}}}{(\ln{x})^x}
    &= \lim_{x \to + \infty}
        x^{\ln(x)} \ln(x)^{-x}\\
    &= \lim_{x \to + \infty}
        e^{\ln(x^{\ln(x)})} e^{\ln(\ln(x)^{-x})}\\
    &= \lim_{x \to + \infty}
        e^{\ln(x) \ln(x)} e^{- x \ln(\ln(x))}\\
    &= \lim_{x \to + \infty}
        \frac{
            e^{(\ln(x))^2}
        }{
            e^{x \ln(\ln(x))}
        }\\
    &= \lim_{x \to + \infty}
        \frac{
            \dv{x} e^{(\ln(x))^2}
        }{
            \dv{x} e^{x \ln(\ln(x))}
        }\\
    &= \lim_{x \to + \infty}
        \frac{
            \frac{2 \ln(x)}{x} e^{(\ln(x))^2}
        }{
            \ln^x(x) \qty(\ln(\ln(x))+ \frac{1}{\ln(x)})
        }\\
    &= \lim_{x \to + \infty}
        \frac{
            2 \ln(x) e^{\ln^2(x)}
        }{
            x \ln^x(x) \qty(\ln(\ln(x))+ \frac{1}{\ln(x)})
        }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         \dv{x} x^{\ln{x}}
    %     }{
    %         \dv{x} (\ln{x})^x
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         \dv{x^{\ln{x}}}{\ln{x}}{x} \dv{\ln{x}}{x}
    %     }{
    %         \dv{x} e^{\ln{(\ln{x})^x}}
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         \ln{x} x^{\ln{x} - 1} \frac{1}{x}
    %     }{
    %         \dv{
    %             x \ln(\ln(x))
    %         }{x}
    %         e^{x \ln(\ln{x})}
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         \frac{\ln{x} x^{\ln{x} - 1}}{x}
    %     }{
    %         \qty(
    %             \ln(\ln(x))
    %             + \frac{1}{\ln(x)}
    %         )
    %         e^{
    %             x \ln(\ln{x})
    %         }
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         x^{\ln(x) - 2} \ln(x)
    %     }{
    %         \qty(\ln(x))^x
    %         \qty(
    %             \ln(\ln(x) + \frac{1}{\ln(x)})
    %         )
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \frac{
    %         \dv{x} x^{\ln(x) - 2} \ln(x)
    %     }{
    %         \dv{x} \qty(\ln(x))^x
    %         \qty(
    %             \ln(\ln(x) + \frac{1}{\ln(x)})
    %         )
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \cfrac{
    %         x^{\ln(x) - 3}
    %         \qty(
    %             2 (\ln(x))^2 - 2 \ln(x) + 1
    %         )
    %     }{
    %         x^{-1}
    %         (\ln(x))^{x - 2}
    %         \qty(
    %             x
    %             + x (\ln(x))^2 (\ln(\ln(x)))^2
    %             + 2 x \ln(x) \ln(\ln(x))
    %             + \ln(x)
    %             - 1
    %         )
    %     }\\
    % &= \lim_{x \to +\infty}
    %     \cfrac{
    %         x^{\ln(x)}
    %         (\ln(x))^2
    %         \qty(
    %             2 (\ln(x))^2 - 2 \ln(x) + 1
    %         )
    %     }{
    %         x^4
    %         (\ln(x))^{x}
    %         \qty(
    %             x
    %             + x (\ln(x))^2 (\ln(\ln(x)))^2
    %             + 2 x \ln(x) \ln(\ln(x))
    %             + \ln(x)
    %             - 1
    %         )
    %     }
\end{align*}

After a lot of manipulation I am making the assumption that with
$\lim_{x \to + \infty} \ln{x} = + \infty$
and since for large enough $x$,
$x^{\ln(x)} > (\ln(x))^x$
the resulting ratio will be unbounded and will tend to infinity.

It is also true that
$e^{\ln^2(x)} > \ln^x(x)$
and ultimately the original hypothesis is supported as well.

Therefore,
\[
    \lim_{x \to + \infty} \frac{x^{\ln(x)}}{(\ln(x))^x} = + \infty
        = \lim_{x \to + \infty}
            \frac{
                \frac{2 \ln(x)}{x} e^{(\ln(x))^2}
            }{
                \ln^x(x) \qty(\ln(\ln(x))+ \frac{1}{\ln(x)})
            }
\]

% Problem 6
\newpage
\section{}
Find the example of a function $f(x)$ which is continuous at every point of the interval $(0,1)$, but is not differentiable at every point $(0,1)$.

Read about the construction of the function, which is differentiable at every point of $(0,1)$ but whose derivative is discontinuous at every point of $(0,1)$.

\subsection*{Continuous but not differentiable}
This type of function is known as a fractal curve. An example of this is the \emph{Weierstrass function} which for $(0,1)$ can be defined as:
\begin{definition}
    Let $f : (0,1) \to \R$ be defined by
    \[
        f(x) := \sum_{n = 0}^{\infty} a^n \cos(b^n \pi x)
    \]
    where $0 < a < 1$,
    $b$ is a positive odd integer $\geq 7$,
    and
    \[
        ab > 1 + \frac{3}{2} \pi
    \]
\end{definition}
As proven by Weierstrass, the function $f$ is continuous everywhere, but is also not differentiable anywhere.

\subsection*{Differentiable function with a discontinuous derivative}
An example construction of a function which is discontinuous at every point of $(0,1)$ was found in \url{https://math.stackexchange.com/a/423279}

Reading through this example, the process involves using the differentiable function:
\[
    f(x) = \begin{cases}
        x^2 \sin(1/x) & x \neq 0\\
        0 & x = 0
    \end{cases}
\]
whose derivative is discontinuous at $x = 0$
\[
    f'(x) = \begin{cases}
        2 x \sin(\frac{1}{x}) - \cos(\frac{1}{x}) & x \neq 0\\
        0 & x = 0
    \end{cases}
\]

This function is then modified to add additional discontinuities,
like having discontinuous derivatives at $x = 0$ and $x = 1$:
\[
    f(x) = \begin{cases}
        x^2 (1 - x)^2 \sin(\frac{1}{\pi x (1-x)}) & 0 < x < 1\\
        0 & \text{else}
    \end{cases}
\]

This can then be expanded to have a bunch of discontinuities at $x_m$ and $x_n$ with $x_m < x_n$:
\[
    f_{m,n}(x) = \begin{cases}
        (x_m - x)^2 (x_n - x)^2 \sin(\frac{1}{\pi (x_m - x) (x_n - x)}) & x_m < x < x_n\\
        0 &\text{else}
    \end{cases}
\]

Finally, an sum of these functions can then be developed to achieve the goal of a continuous function with a fully discontinuous derivative
\[
    F_N(x) = \sum_{n = 1}^{N} \sum_{m=1}^{2^n} f_{m,n}(x)
\]
where the discontinuities for $x_k$ are selected from a sequence containing all values of $x \in (0,1)$.

The limit of this sum as $N \to \infty$ will essentially develop a similar function to that of the fractal sets, but with differentiability intact.

\end{document}