\chapter{Introduction}
The discovery of calculus was one of the most important and exciting
achievements in the history of intellectual progress.
Virtually every field which deals with quantities
has benefited from calculus.
It allowed Sir Isaac Newton to derive the laws of planetary motion,
Albert Einstein to derive relativity,
many an economist to model and analyze
market variables, and countless other achievements.
In particular, it is reasonable to estimate that physics would
be centuries behind its present maturity were it not for the
availability of calculus.

Despite the technicalities involved in the lofty fields already
mentioned, the fundamental principles of calculus are quite
accessible, especially now that the subject
has been distilled into a more  coherent form in the
passing of
centuries since its initial discoveries.  Generations of
researchers and authors have refined the presentations
to be understandable to motivated college students with
a variety of  interests. Some larger universities
have separate
calculus courses specifically for majors in business, agriculture,
forestry, and even English, as well as the mainstays
of mathematics, engineering and science.
%It is a priviledge of every calculus author
%and professor to continue this tradition of refinement, and
%to pass this knowledge to the next generation.
Calculus is the marquee mathematical subject
for many of these programs of study, particularly science
and engineering.
Its importance can not be overstated.
Even the algebra-trigonometry courses at our
institutions have been fashioned largely to groom
students for eventual study of calculus.

So what is calculus?  The short answer is that it is
the field of mathematics which deals with change,
both instantaneous and cumulative.  Respectively,
this means calculus is mainly---but certainly not exclusively---interested
in solving the following two problems:
\begin{enumerate}[(1)]
\item given algebraic relationships among variables, compute
      their rates of change with respect to each other;
\item given the rates of change of variables with respect to
      each other, find the algebraic relationships
      among the variables.
\end{enumerate}
Indeed the second is simply the first in reverse.  For a simple,
though abstract example, consider the following questions:
\begin{enumerate}[(i)]
\item If we know the position $s$ of an object at every time $t$,
      can we know the velocity $v$ of the object at every time $t$?
\item If we know the velocity $v$ of an object at every time $t$,
      can we know the position $s$ of the object at every time $t$?
\end{enumerate}
Now velocity is ultimately
just the measure of how the position $s$ is changing with  time $t$,
so indeed (i) and (ii) are examples of (1) and (2) above.
The answer to (i) is ``yes,'' and the answer to (ii) is ``almost.''
In fact, for (ii) we need some more information, like
where the object is (i.e., $s$) for a particular time $t$,
and then we can usually ``pin down'' the position $s$ for all time $t$.

Problems of type (1) are part of the {\it differential calculus},
also known as calculus of {\it derivatives}.  Problems of type
(2) are part of {\it integral calculus} where, perhaps
predictably, we will compute many {\it antiderivatives}.
Problems of this second type tend to be more (sometimes much more)
difficult than problems of the first type.

Before we even begin to work in the differential or integral calculus, we
will need some preliminaries.  We will begin with a
chapter on symbolic logic so that we can employ that language throughout
the text.  Next we exercise that logic on some algebraic preliminaries.
Our first preliminaries specific to calculus are the concepts
of continuity
and limits, which together form much of the
theoretical foundation of the calculus, and so we will spend
considerable effort on these.  The bulk of our
work is then contained in the
chapters on differential calculus and integral calculus.
A final major topic is series, which finishes our work here.
This last topic will require much of its own foundational
development, but is a very important aspect of the classical
calculus.  Within that study are the answers to questions
such as how a calculator can find $\sin78^\circ$ to ten digits
of accuracy, but that is only a very small sample of the usefulness
of that theory.

Throughout the text we will see other applications of
limits, derivatives, antiderivatives and series, and we will
explore as many of those as reasonable for a text of this scope.
The development of the analytical tools is our main goal.  The
student well-versed in the mechanics of those tools will surely
(and, it is hoped, easily) find
numerous other uses for the methods developed here.

\chapter{Reading this Book}

The main body of the book is organized into Chapters 1, 2, 3, and so on.
Chapters are then organized into sections, so for
instance Chapter~1 is
divided into Sections 1.1, 1.2, 1.3, etc.
Most sections correspond to the amount of material a college professor
should be able to introduce in a one or two hour lecture, not including
time spent answering homework questions.
Sections are themselves sometimes divided, so Section 5.2
(i.e., the second section of Chapter 5) may
be divided into Subsections 5.2.1, 5.2.2, and so on.
This is done to maintain a type of outline format,
with each chapter, section and subsection given a
title so that it is clear which topic (or subtopic, or sub-subtopic)
is being developed at any particular location in the text.
Because there are numerous tangential points and clarifications
to be made, numbered footnotes---some
quite lengthy---are employed extensively so that the regular flow
of the text need not be interrupted.\footnote{%%
%%% FOOTNOTE
This is an example of a footnote.
%%% END FOOTNOTE
}

While all this heierarchy and
numbering may at first seem excessive, it
has become standard practice, and does help to mark where
a particular topic is developed.
As mentioned in the preface, this book attempts to be a stand-in for
an actual professor lecturing at a chalkboard in a calculus class.
It is reasonable for students to expect the professor to write
the main points on the board in an outline form.  Textbook styles,
however, differ from the usual lecture-notes outline form,
which includes major headings (here chapters), Roman numerals (sections),
upper-case Latin letters (subsections), Persian-Arabic numerals (definitions,
examples, steps in the general explanation), and so on.  But the
basic idea of an outline, branching from general to specific,
is the same.  Of course it is not uncommon for the professor to stand
away from the board from time to time and verbally elaborate on
various points, or to mention relevant external topics which do not
fit neatly into the flow of the outline and indeed may distract
from the strictly-defined purposes of the course if included in
the written outline.  Nonetheless such points can do much to
clarify the material, especially by importing relevance to outside
topics.  The footnotes provide the author of the textbook
the same chance,
to figuratively step away from the main flow of the text,
clarify the discussion and connect it to the rest of the world.

This text also uses numerical labels for equations, theorems,
corollaries, definitions,
tables and figures.  When a particular equation warrants,
it is given  a sequentially-assigned label based
upon the chapter number for easy reference.
For instance, Equation (7.23) would be the twenty-third such equation
in Chapter~7.  Theorems, definitions and figures are
similarly numbered.  (The exception is that each chapter's
footnote labels reset to 1, so that Chapter~1 has footnotes
numbered
1, 2, 3, etc., as do Chapters~2, 3, and so on.)
These are all standard,
formal styles of labeling found in much of the technical literature.
This calculus text presents perhaps an ideal opportunity for
a first introduction to its extensive use.

The text, while not strictly linear,
is mostly cumulative, with new topics constantly referring to
earlier topics.  Thus the material should be read in the
order it is presented, with few exceptions possible
(and then best chosen by an instructor).

It may not always be possible for the student to master each topic
as it is presented.  Nonethless,
it is very important to work as hard as possible
to become as proficient as possible in
the topics as they are first encountered.  This may sometimes
require a very slow and deliberate approach to the exercises
and explanations.  However,
it may occasionally be necessary to ``table'' a
confusing topic, in order to return to it after seeing
how it fits into the greater scheme.
This is natural, and in fact even a topic seemingly
``mastered'' will undoubtedly
benefit from a revisit. Still, strong efforts on all
topics will continually pay returns as one's
intuition for calculus as a whole is nurtured.

There are numerous comments within the text explaining
the importance of the various topics, and relating how
difficult particular topics have historically proven
to students.  Again, all topics are important, but such
comments are provided to indicate where particularly strong effort
may be required.  Comments regarding
common mistakes are also common within the text.

\chapter{Table of Greek Letters}
We often use Greek letters in this text, as is standard for
technical writing.  In calculus, $\Delta$, $\delta$, $\epsilon$ and
$\Sigma$  have particularly special roles,
as do $\theta$ and $\phi$, among others, in trigonometry.
We will also use other Greek letters when they are either
appropriate stand-ins for their English counterparts, or when
we want them to be conspicuous  in mathematical
expressions.  Finally, a reasonably informed student
in any technical discipline is expected to eventually know
all the members of the Greek alphabet.  For these reasons
we include a table of Greek letters below.

%\begin{center}
%{\Large Table of Greek Letters}
%\bigskip
%\end{center}
\vfill

\begin{alignat*}{3}
&A&\qquad&\alpha&\qquad\qquad&\text{alpha}\\
&B&&\beta&&\text{beta}\\
&\Gamma&&\gamma&&\text{gamma}\\
&\Delta&&\delta&&\text{delta}\\
&E&&\epsilon&&\text{epsilon}\\
&Z&&\zeta&&\text{zeta}\\
&H&&\eta&&\text{eta}\\
&\Theta&&\theta&&\text{theta}\\
&I&&\iota&&\text{iota}\\
&K&&\kappa&&\text{kappa}\\
&\Lambda&&\lambda&&\text{lambda}\\
&M&&\mu&&\text{mu}\\
&N&&\nu&&\text{nu}\\
&\Xi&&\xi&&\text{xi}\\
&O&&o&&\text{omicron}\\
&\Pi&&\pi&&\text{pi}\\
&P&&\rho&&\text{rho}\\
&\Sigma&&\sigma&&\text{sigma}\\
&T&&\tau&&\text{tau}\\
&Y&&\upsilon&&\text{upsilon}\\
&\Phi&&\phi&&\text{phi}\\
&X&&\chi&&\text{chi}\\
&\Psi&&\psi&&\text{psi}\\
&\Omega&&\omega&&\text{omega}
\end{alignat*}
\vfill\eject


\input{../../templates/assignment.tex}

\title{
\normalfont \normalsize
\textsc{Norwegian University of Science and Technology\\TDT4200 -- Parallel Computing} \\ [25pt]
\horrule{0.5pt} \\[0.4cm]
\huge Problem Set 2:\\ CUDA Intro -- Addendum\\
\horrule{2pt} \\[0.5cm]
}

\author{Per Magnus Veierland\\permve@stud.ntnu.no}

\setlist[enumerate,1]{label=\emph{\alph*})}
\setlist[enumerate,2]{label=\roman*)}
\setlist[enumerate,3]{label=\arabic*)}

\date{\normalsize\today}

\begin{document}
\maketitle

\subsection*{Problem 2: CUDA GPGPUs}

\begin{enumerate}
\setcounter{enumi}{2}
\item \textbf{Which of \texttt{kernel1()} and \texttt{kernel2()} will execute fastest, given that $X$ and $Y$ are \textit{gridDim} and \textit{blockDim} respectively, containing $3$ integers with positive powers of $2$ higher than $2^4$?}

The kernels will both compute the same amount of effective work, i.e. they will both call the \texttt{some\_other\_task()} function the same number of times. When comparing the time it takes to execute one warp in \texttt{kernel1} where the \texttt{some\_other\_task()} function is called with the time it takes to execute one warp from \texttt{kernel2} in which the \texttt{some\_other\_task()} function is called, these will be the same.

The important difference between the kernels is in how they utilize the available hardware. For \texttt{kernel1} only a low number of threads in a warp will effectively do work, while the rest of the threads are wasted for the duration of the computation. The ratio of threads within each thread block which will be used effectively is given by:

\begin{displaymath}
\frac{4 \cdot 32 + 4 \cdot 32 - 4 \cdot 4}{32 \cdot 32} \approx 0.234375
\end{displaymath}

In the case of \texttt{kernel2}, the branching occurs on block boundaries which means that a full block will either be calling \texttt{some\_other\_task()}, or immediately completing. This means that 32 out of 32 threads in a warp will be used productively, and in the cases where there is no computation to be done, the warp will immediately complete -- leaving room for new warps.

Given an infinite number of streaming multiprocessors, both \texttt{kernel1} and \texttt{kernel2} would take the same amount of time to complete. However in reality there is a limited number of multiprocessors, and only a given number of warps can run at a time.

This difference can easily be verified in benchmarks. Using a test case with a grid size of 32 by 32 and a block size of 32 by 32 performing some arbitrary work -- the time spent by \texttt{kernel1} was 1440822~us, while the time spent by \texttt{kernel2} was 335491 us. This fits well with the ratio of threads used effectively in a thread block by \texttt{kernel1}:

\begin{displaymath}
\frac{335491\text{~us}}{0.234375} \approx 1431428\text{~us}
\end{displaymath}

Hence it is clear that \texttt{kernel2} will execute the fastest.

\end{enumerate}

\end{document}


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%
% #ifdef PTEX2TEX_EXPLANATION
%%
%% The file follows the ptex2tex extended LaTeX format, see
%% ptex2tex: https://code.google.com/p/ptex2tex/
%%
%% Run
%%      ptex2tex myfile
%% or
%%      doconce ptex2tex myfile
%%
%% to turn myfile.p.tex into an ordinary LaTeX file myfile.tex.
%% (The ptex2tex program: https://code.google.com/p/ptex2tex)
%% Many preprocess options can be added to ptex2tex or doconce ptex2tex
%%
%%      ptex2tex -DMINTED myfile
%%      doconce ptex2tex myfile envir=minted
%%
%% ptex2tex will typeset code environments according to a global or local
%% .ptex2tex.cfg configure file. doconce ptex2tex will typeset code
%% according to options on the command line (just type doconce ptex2tex to
%% see examples). If doconce ptex2tex has envir=minted, it enables the
%% minted style without needing -DMINTED.
% #endif

% #define PREAMBLE

% #ifdef PREAMBLE
%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE
% #endif

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
PHY321: Classical Mechanics 1
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf Second midterm project, due Sunday April 18${}^{}$} \\ [0mm]
\end{center}

\begin{center}
% List of all institutions:
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Apr 14, 2021
\end{center}
% --- end date ---

\vspace{1cm}

\paragraph{Practicalities about  homeworks and projects.}
\begin{enumerate}
\item You can work in groups (optimal groups are often 2-3 people) or by yourself. If you work as a group you can hand in one answer only if you wish. \textbf{Remember to write your name(s)}!

\item How do I(we)  hand in?  Due to the extraordinary situation we are in now, the midterm should be handed in fully via D2L. You can scan your handwritten notes and upload to D2L or you can hand in everything (if you are ok with typing mathematical formulae using say Latex) as a jupyter notebook at D2L. The numerical part should always be handed in as a jupyter notebook.
\end{enumerate}

\noindent
\paragraph{Introduction to the second midterm project, total score 100 points.}
In this midterm we will attempt at writing a program that simulates
the solar system. We start with the Earth-Sun system we studied in
homeworks 5 and 6 and study elliptical orbits and their properties. We test
also elliptical orbits and their dependence on powers $\beta$ of
$r^{\beta}$. We will test other aspects of the Earth-Sun system and
link these to the theoretical discussion on two-body problems with
central forces.

Thereafter we will add Jupiter to our system before we move on to including all planets of the solar system.
attempt at making a code which simulates the solar system.

The relevant reading background is
\begin{enumerate}
\item chapter 8 of  Taylor.

\item Lecture notes on central forces and two-body problems, see also the Jupyter-Book at \href{{https://mhjensen.github.io/Physics321/doc/LectureNotes/_build/html/}}{\nolinkurl{https://mhjensen.github.io/Physics321/doc/LectureNotes/_build/html/}} and go \href{{https://mhjensen.github.io/Physics321/doc/LectureNotes/_build/html/chapter6.html}}{Two-body problems, from the Gravitational Force to Two-body Scattering}.

\item Homeworks 5-9
\end{enumerate}

\noindent
\paragraph{Part 1 (50pt), the inverse-square law and the stability of planetary orbits.}
In homework 9 we studied an attractive potential
\[
V(r)=-\alpha/r,
\]

where the quantity $r$ is the absolute value of the relative position
and $\alpha$ is a constant.

When we rewrote the equations of motion in polar coordinates, we found the
analytical solution to the radial equation of motion

\[
r(\phi) = \frac{c}{1+\epsilon\cos{(\phi)}},
\]
where $c=L^2/\mu\alpha$, with
the reduced mass $\mu$ and the angular momentum $L$, as
discussed during the lectures. With the transformation of a two-body
problem to the center-of-mass frame, the actual equations look like an
\emph{effective} one-body problem.

The quantity $\epsilon$ is what we called the eccentricity. Since we
will mainly study bounded orbits, we have $0 \le \epsilon < 1$.  For
the Earth, the orbit is indeed close to circular and at perihelion
(the closest distance to the Sun), the Earth's center is about 0.98329
astronomical units (AU) or 147,098,070 km from the Sun's center. For
Earth, the orbital eccentricity is $\epsilon\approx 0.0167$. The outer
planets have more elliptical orbits. For example, Mars has its
perihelion at 206,655,215 km and its apehelion at 249,232,432 km.

In this part we will limit ourselves to the Earth-Sun system we
studied in homeworks 5 and 6. You can reuse your code with either the
Velocity-Verlet or the Euler-Cromer algorithms from homework 5 or 6.

This means also that $\alpha=GM_{\odot}M_{\mathrm{Earth}}$. We will
use $\alpha$ as a shorthand in the equations here. Keep in mind that
in homework 5 you scaled $GM_{\odot}=4\pi^2$ in your code.

The exercises here are all based on you analyzing the results from your code from homeworks 5, 6, 7 and 8.

As a reminder, we list the equations we studied in homeworks 5 and 6.
Newton's law of gravitation is given by a force $F_G$ (we assume this
is the force acting on Earth from the Sun)

\[
F_G=-\frac{GM_{\odot}M_{\mathrm{Earth}}}{r^2},
\]

where $M_{\odot}$ is the mass of the Sun and $M_{\mathrm{Earth}}$ is
the mass of the Earth. The gravitational constant is $G$ and $r$ is
the distance between the Earth and the Sun.  We assumed that the Sun
has a mass which is much larger than that of the Earth. We could
therefore safely neglect the motion of the Sun.

In homeworks 5 and 6 we assumed that the orbit of the Earth around the Sun
was co-planar, and we took this to be the $xy$-plane.
Using Newton's second law of motion we got the following equations

\[
\frac{d^2x}{dt^2}=-\frac{F_{G,x}}{M_{\mathrm{Earth}}},
\]
and

\[
\frac{d^2y}{dt^2}=-\frac{F_{G,y}}{M_{\mathrm{Earth}}},
\]

where $F_{G,x}$ and $F_{G,y}$ are the $x$ and $y$ components of the
gravitational force.

You can obviously set $\alpha=GM_{\odot}M_{\mathrm{Earth}}$ as we did in homeworks 5 and 6.

\begin{itemize}
\item 1a (10pt) Use now your code from homework 5 (in cartesian coordinates). Start with a circular orbit (this corresponds to  setting $\epsilon=0$ for the equations in Polar coordinates), and plot $x$ versus $y$. How would you choose the initial conditions to obtain a circular orbit?  \textbf{Note} the your code will be run in Cartesian coordinates.

\item 1b (10pt) Check that for the case of a circular orbit that both the kinetic and the potential energies are conserved. Why do we expect such a result if we have a circular orbit?

\item 1c (10pt) With the same initial conditions (circular orbit) use Kepler's second law (see Taylor section 3.4) to show that angular momentum is conserved. Compare the value you get with the angular momentum you get from a circular orbit.

\item 1d (10pt) Till now we have assumed that we have an inverse-square force $F(r) = -\alpha/r^2$. Let us rewrite this force as $F(r) =-\alpha/r^{\beta}$ with $\beta=[2,2.01,2.10,2.5,3.0,3.5]$. \textbf{Note}: in your code you are setting the force in say for example the $x$-direction (the same applies to the $y$- and/or eventual $z$-directions to $F(r) = -(\alpha/r^3)x$. It means that when you study the dependence on the parameter $\beta$, you need to add $1$ to the power. Run your Sun-Earth code with these values of $\beta$ and plot $x$ versus $y$ (you can use the same initial conditions or switch to eliptical orbits). Discuss your results. Can you use the observations of planetary motion to determine by what amount Nature deviates from a perfect inverse-square law?

\item 1e (10pt) Consider now an elliptical orbit with an initial position 1 AU from the Sun and an initial  velocity of 5 AU/yr. Show that the total energy is a constant (the kinetic and potential energies will vary). Show also that the angular momentum is a constant. If you change the parameter $\beta$ in $F(r) = -\alpha/r^{\beta}$ from $\beta=2$ to $\beta=3$, are these quantities conserved?  Discuss your results. (Hint: relate your results to Kepler's laws).
\end{itemize}

\noindent
\paragraph{Part 2 (50pt), making a program for the solar system.}
Our final aim is to write a code which includes the known planets of the solar system.

We will, as before, use so-called astronomical units when rewriting our equations.
Using astronomical units (AU as abbreviation)it means that
one astronomical unit of length, known as 1 AU, is the average distance between the Sun and Earth, that is
$1$ AU = $1.5\times 10^{11}$ m.  It can also be convenient to use years instead of seconds since years match
better the time evolution of the solar system. The mass of the Sun is $M_{\mathrm{sun}}=M_{\odot}=2\times 10^{30}$ kg. The masses of all relevant planets and their distances from the sun are listed in the table here in kg and AU.

\begin{quote}
\begin{tabular}{ccc}
\hline
\multicolumn{1}{c}{ Planet } & \multicolumn{1}{c}{ Mass in kg } & \multicolumn{1}{c}{ Distance to  sun in AU } \\
\hline
Earth   & $M_{\mathrm{Earth}}=6\times 10^{24}$ kg     & 1AU                    \\
Jupiter & $M_{\mathrm{Jupiter}}=1.9\times 10^{27}$ kg & 5.20 AU                \\
Mars    & $M_{\mathrm{Mars}}=6.6\times 10^{23}$ kg    & 1.52 AU                \\
Venus   & $M_{\mathrm{Venus}}=4.9\times 10^{24}$ kg   & 0.72 AU                \\
Saturn  & $M_{\mathrm{Saturn}}=5.5\times 10^{26}$ kg  & 9.54 AU                \\
Mercury & $M_{\mathrm{Mercury}}=3.3\times 10^{23}$ kg & 0.39 AU                \\
Uranus  & $M_{\mathrm{Uranus}}=8.8\times 10^{25}$ kg  & 19.19 AU               \\
Neptun  & $M_{\mathrm{Neptun}}=1.03\times 10^{26}$ kg & 30.06 AU               \\
Pluto   & $M_{\mathrm{Pluto}}=1.31\times 10^{22}$ kg  & 39.53 AU               \\
\hline
\end{tabular}
\end{quote}

\noindent
Pluto is no longer considered a planet, but we add it here for
historical reasons. It is optional in this midterm project to include
Pluto and eventual moons.

In setting up the equations we can limit ourselves to a co-planar
motion and use only the $x$ and $y$ coordinates. But you should feel
free to extend your equations to three dimensions, it is not very
difficult and the data from NASA are all in three dimensions.
You find these data at the
\href{{http://www.nasa.gov/index.html}}{NASA} has an excellent site at \href{{http://ssd.jpl.nasa.gov/horizons.cgi#top}}{\nolinkurl{http://ssd.jpl.nasa.gov/horizons.cgi\#top}} site.

From there you can extract initial conditions in order to start your
differential equation solver.  At the above website you need to change
from \textbf{OBSERVER} to \textbf{VECTOR} and then write in the planet you are
interested in.  The generated data contain the $x$, $y$ and $z$ values
as well as their corresponding velocities. The velocities are in units
of AU per day.  Alternatively they can be obtained in terms of km and
km/s.

We will start with  the three-body problem, still with the Sun kept
fixed as the center of mass of the system but including Jupiter (the
most massive planet in the solar system, having a mass that is
approximately 1000 times smaller than that of the Sun) together with
the Earth. This leads to a three-body problem. Without Jupiter, the
Earth's motion is stable and unchanging with time. The aim here is to
find out first how much Jupiter alters the Earth's motion.

The program you have developed in homeworks 5 and 6 can easily be modified by
simply adding the magnitude of the force between the Earth and
Jupiter.

This force is given again by

\[
F_{\mathrm{Earth-Jupiter}}=-\frac{GM_{\mathrm{Jupiter}}M_{\mathrm{Earth}}}{r_{\mathrm{Earth-Jupiter}}^2},
\]

where $M_{\mathrm{Jupiter}}$ is the mass of Jupyter and
$M_{\mathrm{Earth}}$ is the mass of the Earth.  The gravitational constant
is $G$ and $r_{\mathrm{Earth-Jupiter}}$ is the distance between Earth
and Jupiter.

We assume again that the orbits of the two planets are co-planar, and
we take this to be the $xy$-plane (you can easily extend the equations
to three dimensions, feel free to run your calculations in two or three dimensions).

\begin{itemize}
\item 2a (20pt) Modify your coupled first-order differential equations from homework 5 in order to accomodate both the motion of the Earth and Jupiter by taking into account the distance in $x$ and $y$ between the Earth and Jupiter. Write out the differential equations for  Earth and Jupyter, keeping the Sun at rest (mass center of the system). Scale these equations in terms of Astronomical Units.

\item 2b (10pt) Use either the Euler-Cromer or Velocity-Verlet algorithms to compute the positions of the Earth and Jupiter. Repeat the calculations by increasing the mass of Jupiter by a factor of 10, 100 and 1000 and plot the position of the Earth.  Discuss your results and study the stability of this three-body system as function of the chosen
\end{itemize}

\noindent
masses for Jupiter.

\begin{itemize}
\item 2c (20pt) Since the Sun is much more massive than all the other planets, we will define the Sun as our center of mass and set its velocity and position to zero.  Our final task is to add the remaining known planets and simulate the solar system asfunction of time. Add gradually one planet at the time. Develop a code which simulates the solar system with the above planets and plot their orbits. Discuss your results.
\end{itemize}

\noindent
\paragraph{Classical Mechanics Extra Credit Assignment: Scientific Writing and attending Talks.}
The following gives you an opportunity to earn \textbf{five extra credit
points} on each of the remaining homeworks and \textbf{ten extra credit points}
on the midterms and finals.  This assignment also covers an aspect of
the scientific process that is not taught in most undergraduate
programs: scientific writing.  Writing scientific reports is how
scientist communicate their results to the rest of the field.  Knowing
how to assemble a well written scientific report will greatly benefit
you in you upper level classes, in graduate school, and in the work
place.

The full information on extra credits is found at \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}{\nolinkurl{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}. There you will also find examples on how to write a scientific article.
Below you can also find a description on how to gain extra credits by attending scientific talks.

This assignment allows you to gain extra credit points by practicing
your scientific writing.  For each of the remaining homeworks you can
submit the specified section of a scientific report (written about the
numerical aspect of the homework) for five extra credit points on the
assignment.  For the two midterms and the final, submitting a full
scientific report covering the numerical analysis problem will be
worth ten extra points.  For credit the grader must be able to tell
that you put effort into the assignment (i.e.~well written, well
formatted, etc.).  If you are unfamiliar with writing scientific
reports, \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/IntroductionScientificWriting.md}}{see the information here}

The following table explains what aspect of a scientific report is due
with which homework.  You can submit the assignment in any format you
like, in the same document as your homework, or in a different one.
Remember to cite any external references you use and include a
reference list.  There are no length requirements, but make sure what
you turn in is complete and through.  If you have any questions,
please contact Julie Butler at butler@frib.msu.edu.

\begin{quote}
\begin{tabular}{ccc}
\hline
\multicolumn{1}{c}{ HW/Project } & \multicolumn{1}{c}{ Due Date } & \multicolumn{1}{c}{ Extra Credit Assignment } \\
\hline
HW 3               & 2-8           & Abstract                   \\
HW 4               & 2-15          & Introduction               \\
HW 5               & 2-22          & Methods                    \\
HW 6               & 3-1           & Results and Discussion     \\
\textbf{Midterm 1} & \textbf{3-12} & \emph{Full Written Report} \\
HW 7               & 3-22          & Abstract                   \\
HW 8               & 3-29          & Introduction               \\
HW 9               & 4-5           & Results and Discussion     \\
\textbf{Midterm 2} & \textbf{4-16} & \emph{Full Written Report} \\
HW 10              & 4-26          & Abstract                   \\
\textbf{Final}     & \textbf{4-30} & \emph{Full Written Report} \\
\hline
\end{tabular}
\end{quote}

\noindent

You can also gain extra credits if you attend scientific talks.
This is described here.

\paragraph{Integrating Classwork With Research.}
This opportunity will allow you to earn up to 5 extra credit points on a Homework per week. These points can push you above 100\% or help make up for missed exercises.
In order to earn all points you must:

\begin{enumerate}
\item Attend an MSU research talk (recommended research oriented Clubs is  provided below)

\item Summarize the talk using at least 150 words

\item Turn in the summary along with your Homework.
\end{enumerate}

\noindent
Approved talks:
Talks given by researchers through the following clubs:
\begin{itemize}
\item Research and Idea Sharing Enterprise (RAISE): Meets Wednesday Nights Society for Physics Students (SPS): Meets Monday Nights

\item Astronomy Club: Meets Monday Nights

\item Facility For Rare Isotope Beam (FRIB) Seminars: Occur multiple times a week
\end{itemize}

\noindent
If you have any questions please consult Jeremy Rebenstock, rebensto@msu.edu.

All the material on extra credits is at \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}{\nolinkurl{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}.

% ------------------- end of main content ---------------

% #ifdef PREAMBLE
\end{document}
% #endif


\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}

\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\km}{\mathrm{km}}
\newcommand{\s}{\mathrm{s}}
\renewcommand{\min}{\mathrm{min}}
\newcommand{\ms}{\mathrm{ms}}
\newcommand{\N}{\mathrm{N}}
\newcommand{\vs}{\emph{vs}}
\newcommand{\abs}[1]{\left|{#1}\right|}

\newcounter{problem}
\stepcounter{problem}
\newcounter{answer}[problem]
\newenvironment{problem}{\noindent\begin{minipage}{\textwidth}\sloppy\sloppypar\raggedright\textbf{\theproblem.}\refstepcounter{problem}\stepcounter{answer}---}{\end{minipage}\vspace{2ex}}
\newcommand{\source}[1]{[{#1}]}
\newenvironment{answers}{\\}{}
\newcommand{\answer}[1]{\mbox{\textbf{\Alph{answer}:}\refstepcounter{answer}~{#1}\hspace{3ex}}}
\begin{document}

\section*{NYU General Physics 1---Term Exam 1}

\begin{problem}
  \source{from lecture 2011-09-03} How long does it take a heavy
  bucket to fall three stories?
  \begin{answers}
    \answer{about a microsecond}
    \answer{about a millisecond}
    \answer{about a tenth of a second}
    \answer{about a second}
  \end{answers}
\end{problem}

%% \begin{problem}
%%   \source{from lecture 2011-09-05} What is the mass of a pint of beer?
%%   \begin{answers}
%%     \answer{$0.05\,\kg$}
%%     \answer{$0.5\,\kg$}
%%     \answer{$5\,\kg$}
%%   \end{answers}
%% \end{problem}

\begin{problem}
  \source{from lecture 2011-09-05} What is the radius of the Earth, roughly?
  \begin{answers}
    \answer{$6,000\,\m$}
    \answer{$200\,\km$}
    \answer{$6,000\,\km$}
    \answer{$200,000\,\km$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-10} We analyzed a stone thrown from a
  cliff, ignoring air resistance.  The velocity changes continuously
  with time.  What aspect of the velocity \emph{stays the same} throughout
  the trajectory?
  \begin{answers}
    \answer{the magnitude}
    \answer{the direction}
    \answer{the vertical component (or projection)}
    \answer{the horizontal component (or projection)}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-12} You are driving in the positive-$x$
  direction.  You hit the brakes.  As you are braking, what is the
  ``kinematic state'' of the vehicle?
  \begin{answers}
    \answer{$v_x > 0$, $a_x > 0$}
    \answer{$v_x > 0$, $a_x < 0$}
    \answer{$v_x < 0$, $a_x > 0$}
    \answer{$v_x < 0$, $a_x < 0$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-17} What does ``frictionless'' mean?
  \begin{answers}
    \answer{no contact force parallel to the surface}
    \answer{no contact force perpendicular to the surface}
    \answer{no contact force from the surface}
    \answer{perfectly smooth}
    \answer{perfectly rigid}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-17} For the problem of the block of
  mass $m$ on the frictionless, inclined plane (inclined at an angle
  $\theta$ to the horizontal), what is a possibly reasonable formula
  for the magnitude of the normal force?
  \begin{answers}
    \answer{$\abs{\vec{N}} = m\,\abs{\vec{g}}\,\cos\theta$}
    \answer{$\abs{\vec{N}} = m\,\abs{\vec{g}}\,\sin\theta$}
    \answer{$\abs{\vec{N}} = \frac{m\,\abs{\vec{g}}}{\cos\theta}$}
    \answer{$\abs{\vec{N}} = \frac{m\,\abs{\vec{g}}}{\sin\theta}$}
    \answer{none of those is reasonable}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-17}  For the problem of the block of
  mass $m$ on the frictionless, inclined plane (inclined at an angle
  $\theta$ to the horizontal), what simplifying assumption did we \emph{not need to make}?
  \begin{answers}
    \answer{The plane is frictionless.}
    \answer{The block will accelerate parallel to the plane.}
    \answer{Air resistance is negligible (can be ignored).}
    \answer{The block was released from rest (zero velocity).}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-19} Two masses $m_1$ and $m_2$ hang by
  a light, inextensible string over a pulley.  What is a
  \emph{possible and reasonable} formula for the magnitude of the
  acceleration of mass $m_1$?
  \begin{answers}
    \answer{$\displaystyle\abs{\vec{a}} = \abs{\frac{(m_1 - m_2)}{(m_1 + m_2)}\,\vec{g}}$}
    \answer{$\displaystyle\abs{\vec{a}} = \abs{\frac{(m_1 + m_2)}{(m_1 - m_2)}\,\vec{g}}$}
    \answer{$\displaystyle\abs{\vec{a}} = \abs{(m_1 - m_2)\,\vec{g}}$}
    \answer{$\displaystyle\abs{\vec{a}} = \abs{(m_1 + m_2)\,\vec{g}}$}
    \answer{these are all unreasonable}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 1, problem 1} What, roughly, is the mass of
  a single dollar bill?
  \begin{answers}
    \answer{$0.00003\,\kg$}
    \answer{$0.001\,\kg$}
    \answer{$0.03\,\kg$}
    \answer{$1\,\kg$}
    \answer{$3\,\kg$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 1, problem 2} You computed a ``power'' for
  air resistance, involving speed, density, and area.  If one car is
  going twice as fast as another car, but the two cars are identical
  in every other respect (same size and shape and mass), how much
  larger is this air-resistance power for the faster-moving car?
  \begin{answers}
    \answer{not larger; in fact exactly the same}
    \answer{larger by a factor of $2$}
    \answer{larger by a factor of $4$}
    \answer{larger by a factor of $8$}
    \answer{none of the above}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 1, problem 3} You computed an approximate
  settling velocity for particles in a centrifuge (and you used the
  units of dynamic viscosity, $\kg\,\m^{-1}\,\s^{-1}$). If you hold
  density and gravitational acceleration fixed, how does the settling
  velocity depend on particle size?
  \begin{answers}
    \answer{larger velocity for larger particles}
    \answer{velocity doesn't depend on particle size}
    \answer{smaller velocity for larger particles}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 1} What is a reasonable value
  for the mean acceleration of a dragster in a drag race, very
  roughly?
  \begin{answers}
    \answer{$0.03\,\m\,\s^{-2}$}
    \answer{$1\,\m\,\s^{-2}$}
    \answer{$30\,\m\,\s^{-2}$}
    \answer{$1000\,\m\,\s^{-2}$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 2} You drew a graph of the
  position $y$ (height) as a function of time for a rock that is
  thrown precisely upwards at $3~\mathrm{m\,s^{-1}}$ at time $t=0$.
  What is the maximum height to which the rock rose, above the
  starting point?  Use $\abs{\vec{g}}=10\,\m\,\s^{-2}$ to answer this.
  \begin{answers}
    \answer{$0.45\,\m$}
    \answer{$0.9\,\m$}
    \answer{$2\,\m$}
    \answer{$3\,\m$}
    \answer{$30\,\m$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 2} You drew a graph of the
  acceleration $a_y$ (vertical acceleration) as a function of time for
  a rock that is thrown upwards.  What happens to the acceleration
  \vs\ time graph at the exact moment that the rock gets to maximum
  height?
  \begin{answers}
    \answer{nothing special at all}
    \answer{the acceleration is undefined}
    \answer{the acceleration is zero}
    \answer{the acceleration changes sign}
    \answer{the slope of the $a_y$ \vs\ $t$ graph changes sign}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 3} You integrated this velocity
  curve:\\ \includegraphics{../py/vx_vs_t.pdf}\\ What is the position
  $x$ at $t=35\,\s$?  Assume that $x=0$ at $t=0$.
  \begin{answers}
    \answer{$5\,\m$}
    \answer{$175\,\m$}
    \answer{$412.5\,\m$}
    \answer{$425\,\m$}
    \answer{$525\,\m$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 3, problem 1} If the acceleration due to
  gravity $g$ were \emph{doubled} (to, say, $20\,\m\,\s^{-2}$), but
  everything \emph{else} about the Earth (radius especially) remained
  the same, what (roughly) would be the orbital period of the Space
  Shuttle?
  \begin{answers}
    \answer{$45\,\min$}
    \answer{$66\,\min$}
    \answer{$90\,\min$}
    \answer{$126\,\min$}
    \answer{$180\,\min$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 3, problem 2} You solved for the tension
  $T$ in this
  problem:\\ \includegraphics{../py/stringblocks.pdf}\\ Now imagine
  that the mass $m_2$ is much, much smaller than the mass $m_1$.  What
  is the tension $T$ in the (light, inextensible) string in this
  special case?
  \begin{answers}
    \answer{very close to zero}
    \answer{very close to $F$}
    \answer{very close to $\frac{F}{m_1}$}
    \answer{very close to $\frac{F}{m_2}$}
    \answer{not close to any of these answers}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 3, problem 3} A block of mass $m=7\,\kg$
  lies on a horizontal table.  It is stationary relative to the table,
  which is accelerating upwards (in, say, an elevator).  You found the
  normal force $N$ between the table and the block when the table is
  accelerating upwards at $0.9\,\m\,\s^{-2}$.  If you reduced this
  upwards acceleration to $0.3\,\m\,\s^{-2}$, what would happen to
  the magnitude of the normal force?
  \begin{answers}
    \answer{it would get smaller by a factor of three}
    \answer{it would get smaller by about five percent}
    \answer{it would stay the same}
    \answer{it would get larger by about five percent}
    \answer{it would get larger by a factor of three}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from \textit{Motion 1} lab} If your plot of position
  \vs\ time looks like a straight line, what does that mean, in
  general?
  \begin{answers}
    \answer{the object isn't moving}
    \answer{the object is moving in the positive direction}
    \answer{the object is moving at constant speed}
    \answer{the object is accelerating at constant acceleration}
    \answer{none of the above}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from \textit{Motion 2} lab} When you measure
  accelerations of gliders of different masses on a track at a
  constant angle $\theta$, what is the expectation?
  \begin{answers}
    \answer{more massive things should have substantially higher accelerations}
    \answer{everything should accelerate at the pretty much same rate}
    \answer{more massive things should have substantially lower accelerations}
  \end{answers}
\end{problem}

\end{document}


\chapter{Programming Language Verification }
\graphicspath{ {./images/} }

Any computer programming language consists of type system to its core supported by data structures and control flow techniques. Any Programming language finally can be broken down to machine codes resulting in perfoming specified actions. The assembly level machine codes should theoretically represent the same semantics as implied by the higher order programming language. \textbf{Programming Language Verification} in the broader sense is checking that programs in one programming language is equivalent to the one in other. Generally this equaivalence is tested between a high order	language and a small low level C language. \\

The basic understanding of how the verification work can be thought as, say there are two programs e$_1$ and e$_2$ then to prove they are equivalent the must meet the following criteria :

\begin{itemize}

\item{
	Input Parameters as well as the context in which the program is being run is same. Input parameters can be thougt as some initial values to a program. Input parameters should necessarily be of same type. The context refers to same harware used as well as the scope of the program in consideration is maintained same. Context can then again be broken as a \textit{Global} context and a \textit{Local} context.
}

\item{
	The result should be same and should be of the same type. It is necessary that any program should not violate any of the bonding rules imposed by context.
}

\end{itemize}

How do we check this ?\\

Well the method used is called \textbf{Step-Indexing}\cite{step_indexing}. In this method we look for holes in a program. These holes represented by C$_i$ can be thought as a program's loop structure or the way conditional arguments have been put up. In any step of a program thus if we are able to show that at that point, C$_2$[e$_1$] termminates and C$_1$[e$_2$] termminates also producing same results then we have shown the programs are equal. The cardinality issues related to number of such possible holes in programs increases the complexity of verification proof. This method therefore says that we should unfold the program upto required N steps and consider the equivalence then.\\

The areas where this method stucks is where we are unable to predict N. This is the case of IO type functions. The work on this is going on and improved proofs are being generated.\\

\section{Verified Software Toolchain}
This project \cite{VST} led by Princeton University deals with verifying software programs and compilers. It is an advancement to Compcert. It uses multi layered kernels to securely verify the programs.

\begin{figure}[!htb]
\centering
  \includegraphics[width=\textwidth]{diagram}
  \caption{Flow diagram of CompCert C ( Source: Official Site)}
\end{figure}

The software toolchain includes static analyzers to check assertions about programs; optimizing compilers to translate programs to machine language operating systems and libraries to supply context for programs. Verified Software Toolchain verifies with machine-checked proofs that the assertions claimed at the top of the toolchain really hold in the machine-language program, running in the operating-system context, on a weakly-consistent-shared-memory ma-
chine.


\documentclass{article}

\usepackage{amsmath, amsthm, amssymb, amsfonts}
\usepackage{thmtools}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{float}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{framed}
\usepackage[dvipsnames]{xcolor}
\usepackage{tcolorbox}

\colorlet{LightGray}{White!90!Periwinkle}
\colorlet{LightOrange}{Orange!15}
\colorlet{LightGreen}{Green!15}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}

\declaretheoremstyle[name=Theorem,]{thmsty}
\declaretheorem[style=thmsty,numberwithin=section]{theorem}
\tcolorboxenvironment{theorem}{colback=LightGray}

\declaretheoremstyle[name=Proposition,]{prosty}
\declaretheorem[style=prosty,numberlike=theorem]{proposition}
\tcolorboxenvironment{proposition}{colback=LightOrange}

\declaretheoremstyle[name=Principle,]{prcpsty}
\declaretheorem[style=prcpsty,numberlike=theorem]{principle}
\tcolorboxenvironment{principle}{colback=LightGreen}

\setstretch{1.2}
\geometry{
    textheight=9in,
    textwidth=5.5in,
    top=1in,
    headheight=12pt,
    headsep=25pt,
    footskip=30pt
}

\begin{document}

% ------------------------------------------------------------------------------
% Cover Page and ToC
% ------------------------------------------------------------------------------

\title{ \normalsize \textsc{}
		\\ [2.0cm]
		\HRule{1.5pt} \\
		\LARGE \textbf{\uppercase{Information, Codes and Ciphers}
		\HRule{2.0pt} \\ [0.6cm] \LARGE{Course Summary Notes} \vspace*{10\baselineskip}}
		}
\date{}
\author{\textbf{Hao Ren} \\
		Computer Science Undergraduate Student \\
		University of New South Wales \\
		Course: MATH3411, 2020 Term 3}

\maketitle
\newpage

\tableofcontents
\newpage

% ------------------------------------------------------------------------------

\setcounter{section}{-1}

\section{All TODOs}

Updated when \emph{3.X Compression Coding} finished as Version 1.

\subsection{Unfinished Contents}

\begin{itemize}
    \item 3.1.3 Decision Trees
    \item 3.2.4 Extensions of Huffman Coding
    \item 3.3.3 Huffman Coding for Stationary Markov Sources
    \item 3.4.2 Decoding: add a list to show steps like the one in 3.4.2 part.
    \item 3.6.x Other types of Compression
\end{itemize}

\subsection{Examples and Diagrams}

\begin{itemize}
    \item 3.2.3 Eg and Dia: Radix $r$ Huffman Codes
    \item 3.3.1 Eg: Definition of Markov Sources
    \item 3.3.3 Eg: with Huffman coding for Markov Sources
    \item 3.4.x Eg: Arithmetic encoding and decoding
    \item 3.5.x Eg: Dictionary Methods
\end{itemize}

\subsection{Proofs}

\begin{itemize}
    \item Theorem 3.1 The Kraft-McMillan Theorem
    \item Theorem 3.2 Minimal UD-codes
    \item Theorem 3.3 Huffman Code Theorem
    \item Proposition 3.4 Knuth
\end{itemize}

\newpage

\setcounter{section}{2}

\section{Compression Coding}

\subsection{Variable Length Encoding}

\begin{align*}
    \text{a source } S \qquad &\text{ with } q \text{ source symbols} \qquad & s_{1},s_{2},\cdots,s_{q},\\
    &\text{ with probabilities} \qquad &  p_{1},p_{2},\cdots,p_{q},\\
    \text{encoded by a code } C \qquad &\text{ with } q \text{ codewords} \qquad & c_{1},c_{2},\cdots,c_{q},\\
    &\text{ of lengths} \qquad & l_{1},l_{2},\cdots,l_{q}.
\end{align*}

\begin{itemize}
    \item with a radix $r$ codewords,
    \item variable length codes,
    \item not channel noise for source coding.
\end{itemize}

\subsubsection{UD and I-code}

A code $C$ is

\begin{description}
    \item[UD] uniquely decodable codes if it can always be decoded unambiguously,
    \item[I-code] instantaneous if no codeword is the prefix of others.
\end{description}

\subsubsection{Comma Codes}

The standard comma code of length $n$ is

\begin{itemize}
    \item a code which every codeword has length $\leq n$,
    \item a code which every codeword contains at most one $0$,
    \item and if a codeword contains $0$ then $0$ must be the final symbol in the codeword.
\end{itemize}

\subsubsection{Decision Trees}

\subsubsection{The Kraft-McMillan Theorem}

\begin{theorem}[The Kraft-McMillan Theorem]
    \mbox{}\\
    A UD-code of radix $r$ with $q$ codewords $c_{1}, c_{2},\cdots,c_{q}$ of lengths $l_{1} \leq l_{2} \leq \cdots \leq l_{q}$ exists \\
    if and only if \qquad an I-code with the same parameters exists \\
    if and only if
    \[K=\sum_{i=1}^{q}\dfrac{1}{r^{l_{i}}}\leq1.\]
\end{theorem}

\subsubsection{Length and Variance}

The expected or \textbf{average length} of codewords is given by
    \[L=\sum_{i=1}^{q}p_{i}l_{i}\]
    and the \textbf{variance} is given by
    \[V=\sum_{i=1}^{q}p_{i}l_{i}^{2}-L^{2}.\]

Our aim is to minimise $L$ for a given source $S$ and, if more than one code $C$ gives this value, to minimise $V$.

\begin{theorem}[Minimal UD-codes]
    \mbox{}\\
    Let $C$ be a UD-code with minimal expected length $L$ for the given source $S$. Then, after permuting codewords of equally likely symbols if necessary,
    \begin{itemize}
        \item $l_{1} \leq l_{2} \leq \cdots \leq l_{q}$ and
        \item $l_{q-1}=l_{1}$.
    \end{itemize}
    Furthermore, if $C$ is instantaneous, then
    \begin{itemize}
        \item $c_{q-1}$ and $c_{q}$ differ only in their last place.
    \end{itemize}
    If $C$ is binary, then
    \begin{itemize}
        \item $K=\sum_{i=1}^{q}2^{-l_{i}}=1.$
    \end{itemize}
\end{theorem}

\subsection{Huffman's Algorithm}

\begin{quotation}
    Huffman’s algorithm for computing minimum-redundancy prefix-free codes has almost legendary status in the computing disciplines. Its elegant blend of simplicity and applicability has made it a favourite example in algorithms courses, and as a result, it is perhaps one of the most commonly implemented algorithmic techniques. \cite{Moffat_2019}
\end{quotation}

\subsubsection{Huffman Coding}

In 1952, David A. Huffman \cite{Huffman_1952} published a new lossless data compression method as an Sc.D student at MIT. Here is a demonstration to compute Huffman prefix-free code which is provided by Princeton University in the course COS226 \cite{princetonLec5.5}:

\begin{itemize}
    \item Count character frequencies $p_{s}$ for each symbol $s$ in file.
    \item Start with a forest of trees, each consisting of a single vertex corresponding to each symbol $s$ with weight $p_{s}$.
    \item Repeat:
        \begin{itemize}
            \item select two trees with min weight $p_{1}$ and $p_{2}$
            \item merge into single tree with weight $p_{1}+p_{2}$
        \end{itemize}
\end{itemize}

\begin{figure}[htbp]
    \center
    \includegraphics[scale=1.35]{img/C3_figure_1}
    \caption{Huffman Coding Diagram \cite{Huffman_1952}}
\end{figure}

\paragraph{Applications} JPEG, MP3, MPEG, PKZIP.

\begin{theorem}[Huffman Code Theorem]
    \mbox{}\\
    For the given source $S$, the Huffman algorithm produces a minimum average length UD-code which is an instantaneous code.
\end{theorem}

\begin{proposition}[Knuth]
    \mbox{}\\
    For a Huffman code created by the given algorithm, the average code word length is sum of all the probabilities at child nodes.
\end{proposition}

\subsubsection{Properties of Huffman Codes}

\begin{enumerate}
    \item The place high strategy always produces a minimum variance Huffman code .
    \item If there are $2^{n}$ equally likely source symbols then the Huffman code is a block code of length $n$.
    \item If for all $j$, $3p_{j} \geq 2 \sum_{k=j+1}^{q}p_{k}$ then the Huffman code is a comma code.
    \item Small changes in the pi can change the Huffman code substantially, but have little effect on the average length $L$. This effect is smaller with smaller variance.
\end{enumerate}

\subsubsection{Radix $r$ Huffman Codes}
For $r$ radix Huffman codes, which $r \geq 3$, we have a better strategy by adding some dummy variables \cite{cmuLec8}.

For a $r$ radix encoding, the procedure is similar except $r$ least probable symbols are merged at each step. Since the total number of symbols may not be enough to allow $r$ variables to be merged at each step, we might need to add some dummy symbols with $0$ probability before constructing the Huffman tree.

How many dummy symbols need to be added? Since the first iteration merges $r$ symbols and then each iteration combines $r-1$ symbols with a merged symbols, if the procedure is to last for $k$ (some integer number of) iterations, then the total number of source symbols needed is $1+k(r-1)$. So before beginning the Huffman procedure, we add enough dummy symbols so that the total number of symbols look like $1+k(r-1)$ for the smallest possible value of $k$.

\begin{enumerate}
    \item If more than two symbols have the same probability at any iteration, then the Huffman coding may not be unique (depending on the order in which they are merged). However, all Huffman codings on that alphabet are optimal in the sense they will yield the same expected code length.
    \item 	One might think of another alternate procedure to assign small code lengths by building a tree top-down instead, e.g. divide the symbols into two sets with almost equal probabilities and repeating. While intuitively appealing, this procedure is suboptimal and leads to a larger expected code length than the Huffman encoding. You should try this on the symbol distribution described above.
\end{enumerate}

\subsubsection{Extensions of Huffman Coding}

\subsection{Markov Sources}

\subsubsection{Introduction}

A finite-state Markov chain is a sequence $S_{0},S_{1}, \cdots$ of discrete random symbols from a finite alphabet, $S$. There is a probability mass function (pmf) $q_{0}(s), s \in S$ on $S_{0}$, and there is a conditional pmf $Q(s|s^{\prime})$ such that for all $m \geq 1$, all $s \in S$, and all $s^{\prime} \in S$,
    \[{\mathrm Pr}(S_{k}=s|S_{k-1}=s^{\prime})={\mathrm Pr}(S_{k}=s|S_{k-1}=s^{\prime},\cdots,S_{0}=s_{0})=Q(s|s^{\prime})\]
    There is said to be a \emph{transition} from $s^{\prime}$ to $s$, denoted $s^{\prime} \to S$, if $Q(s|s^{\prime})>0$. \cite{mitCh2}

\subsubsection{Transition Matrix}

The matrix $M = (p_{ij})$ is called the transition matrix of the Markov process, which could be displayed as $(\mathrm{from}\ s_{j}) \rightarrow (p_{ij}) \rightarrow (\mathrm{to}\ s_{i})$.

\begin{itemize}
    \item \quad $P(s_{1}|s{j}) + P(s_{2}|s{j}) + \cdots + P(s_{q}|s{j}) = 1$
    \item \quad $p_{1j} + p_{2j} + \cdots + p_{qj} = 1, \; \mathrm{for}\ j = 1, \cdots, q$
\end{itemize}

\[
\begin{bmatrix}
    p_{11} & p_{12} & \cdots & p_{1j} \\
    p_{21} & p_{22} & \cdots & p_{2j} \\
    \vdots & \vdots & \ddots & \vdots \\
    p_{i1} & p_{i2} & \cdots & p_{ij}
\end{bmatrix}
\]

\subsubsection{Huffman Coding for Stationary Markov Sources}

\subsection{Arithmetic Coding}

Arithmetic coding is very efficient and approaches the entropy limit faster than Huffman coding without any contradiction because the arithmetic coding is not a UD-code. The idea is to assign a subinterval of $[0, 1) \subseteq \mathbb{R}$ to the message and successively narrow this subinterval down as each symbol is encoded. The message must end with a stop symbol $\bullet$, which could be displayed as
    \[s_{a}s_{b}s_{c}s_{d}s_{e} \cdots s_{n} \bullet,\]
    and after the subinterval corresponding to the message plus $\bullet$ is found, then any suitable \emph{single number} in the subinterval is transmitted -- this is the actual code number or codeword.

\subsubsection{Encoding}

Firstly, to each symbol is associated a subinterval of $[0, 1)$ whose length is proportional to the relative frequency of the symbol. These subintervals are chosen so they do not overlap, but fill $[0, 1)$.

If the ``message so far'' subinterval is $[s, s+w)$ where $s$ is the start, $w$ is the width and the next symbol has associated subinterval $[s^{\prime}, s^{\prime}+w^{\prime})$ then the new message subinterval is the $[s^{\prime}, s^{\prime}+w^{\prime})$ part of $[s, s+w)$.

That is, the new message subinterval becomes \[[s+s^{\prime}w, (s+s^{\prime}w)+w^{\prime}w).\]

It could be shown as a list step by step:

\begin{itemize}
    \item \textbf{Crop} $[0, 1)$ as current interval.
    \item \textbf{Partition} the current interval $[0, 1)$ into subintervals of length $p_{1} \cdots p_{q}$, which $p_{q}$ is a stop symbol $\bullet$.
    \item \textbf{Crop} the $i_{1}^{\mathrm{th}}$ subinterval as the current interval.
    \item \textbf{Partition} the current interval $[\mathrm{new\ start}, \mathrm{new\ end})$ into subintervals of length $p_{1} \cdots p_{q}$, which $p_{q}$ is a stop symbol $\bullet$.
    \item \textbf{Crop} the $i_{2}^{\mathrm{th}}$ subinterval as the current interval, which is also a sub-subinterval of the initial interval $[0, 1)$.
    \item \textbf{Repeat} this process until the whole message has been encoded.
\end{itemize}

\begin{figure}[htbp]
    \center
    \includegraphics[scale=1.35]{img/C3_figure_2}
    \caption{Arithmetic Coding Diagram \cite{Langdon_1984}}
\end{figure}

\subsubsection{Decoding}

We reverse the above, by finding which of the symbol subintervals contains
the code number. This then gives the first symbol of the message.

The code number is then re-scaled to that interval as follows.
If $x$ is the code number and it lies in the subinterval $[s, s+w)$,
then the rescaled code number is $\dfrac{x-s}{w}$. The process is repeated until
the stop symbol $\bullet$ is encountered.

\begin{enumerate}
    \item Without the stop symbol, decoding would usually go on forever.
    \item It is possible to implement arithmetic coding and decoding using integer arithmetic, and if we use binary representation for the subintervals then it can actually be done using binary arithmetic.  Successive digits can be transmitted as soon as they are finalized; that is, when both start and end points of the interval agree to sufficiently many significant places.  Decoding can also be done as the digits arrive.  Hence arithmetic coding does not need much memory.
    \item We have described a static version of arithmetic coding.  But the process can also be made adaptive by continually adjusting the start/width values for symbols while decoding takes place.
\end{enumerate}

\subsection{Dictionary Methods}

\paragraph{Examples} \textbf{Ziv, LZ77, LZ78 and LZW} are four dictionary compressing methods.
Dictionary-based algorithms do not encode single symbols as variable-length bit strings; they encode variable-length strings of symbols as single tokens:

\begin{itemize}
    \item The tokens form an index into a phrase dictionary.
    \item If the tokens are smaller than the phrases they replace, compression occurs.
\end{itemize}

Consider the Random House Dictionary of the English Language, Second edition, Unabridged. Using this dictionary, the string
    \[\text{A good example of how dictionary based compression works}\]
can be coded as
    \[1/1 \quad 822/3 \quad 674/4 \quad 1343/60 \quad 928/75 \quad 550/32 \quad 173/46 \quad 421/2\]

\paragraph{Coding} Uses the dictionary as a simple lookup table.

\begin{itemize}
    \item Each word is coded as x/y, where, x gives the page in the dictionary and y gives the number of the word on that page.
    \item The dictionary has 2,200 pages with less than 256 entries per page: Therefore x requires 12 bits and y requires 8 bits, i.e., 20 bits per word (2.5 bytes per word).
    \item Using ASCII coding the above string requires 48 bytes, whereas our encoding requires only $20\ (2.5 \times 8)$ bytes: 50\% compression. \cite{utexasMbs}
\end{itemize}

\paragraph{Applications} GZIP, GIF, POSTSCRIPT.

\subsubsection{Encoding}

Start with an empty dictionary and set $r = m$. (Here $r$ is the part of the message which we have not yet encoded.) Let “$+$” denote concatenation of symbols. Repeat the following steps until $r$ is empty:
\begin{enumerate}
    \item Let s be the longest prefix of $r$ which corresponds to a dictionary entry. If there is no such prefix then set $s = \emptyset$. (By prefix we mean a subsequence of $r$ which begins at the first symbol.)
    \item Suppose that $s$ is in line $l$ of the dictionary, and put $l = 0$ if $s = \emptyset$. Add a new dictionary entry for $s + c$, where $c$ is the next symbol after $s$ in $r$. Output $(l, c)$ to the encoding and delete $s + c$ from $r$.
\end{enumerate}

\subsubsection{Decoding}

\begin{enumerate}
    \item Start with an empty dictionary.
    \item If the next code pair is $(l, c)$ then output $D(l) + c$ to the message, where $D(l)$ denotes entry $l$ of the dictionary and $D(0) = \emptyset$.
    \item Also add $D(l) + c$ to the dictionary. Repeat until all code pairs have been processed.
    \item The dictionary after the decoding process is exactly the same as the dictionary after the encoding process.
\end{enumerate}

\newpage

\setcounter{section}{6}

\section{Cryptography (Ciphers)}

\subsection{Introduction}

A \textbf{message} m from among a set $M$ of all possible messages is \textbf{encrypted} (or enciphered or encoded), using one of a set $\{E_{k}\}$ of \textbf{encryption functions} (or cryptographic transformations)
    \[E_{k}: M \rightarrow C\]
    into an \textbf{encrypted message} $c \in C$, where $C$ is the set of all possible encrypted messages.

The encryption function $E_{k}$ depends on the particular \textbf{key} $k$ chosen from a set $K$ of all possible keys.

The encrypted message $c$ is then transmitted to the receiver, who decrypts it using the decryption function
    \[D_{k}: C \rightarrow M\]
    using the same key $k$. Here Dk is the inverse of $E_{k}$, which means that
    \[D_{k}(c)=D_{k}(E_{k}(m))=m\]
We also call $m$ the \textbf{plaintext} and $c$ the \textbf{cipher text}.

\begin{figure}[htbp]
    \center
    \includegraphics[width=\textwidth]{img/C7_figure_1}
    \caption{Cryptography}
\end{figure}

\begin{principle}[Kerckhoffs's Principle of Cryptography \cite{Kerckhoffs_1883}]
    \mbox{}\\
    \begin{enumerate}
        \item The system must be practically, if not mathematically, indecipherable;
        \item It should not require secrecy, and it should not be a problem if it falls into enemy hands;
        \item It must be possible to communicate and remember the key without using written notes, and correspondents must be able to change or modify it at will;
        \item It must be applicable to telegraph communications;
        \item It must be portable, and should not require several persons to handle or operate;
        \item Lastly, given the circumstances in which it is to be used, the system must be easy to use and should not be stressful to use or require its users to know and comply with a long list of rules.
    \end{enumerate}
\end{principle}

Claude Shannon reformulated this principle as "one ought to design systems under the assumption that the enemy will immediately gain full familiarity with them", which called

\paragraph{Shannon's Maxim} "The enemy knows the system."

\subsection{Some Classical Cryptosystems}

\subsubsection{Caesar Cipher}

Cyclically shift each letter $k$ places forward, e.g. for $k = 3$, which is also used by Roman dictator Gaius Julius Caesar himself.

\begin{center}
    \texttt{
         plain \quad A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\\
        cipher \quad D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
    }
\end{center}

If letters are represented by $\mathbb{Z}_{26}$, then we have, for key $k$,

\begin{align*}
    E_{k}(i) &= i+k \pmod{26} \text{\quad for all } i\\
    \text{and \quad} D_{k}(j) &= j-k \pmod{26} \text{\quad for all } j.\\
\end{align*}

There are only 26 keys $k$, so this cipher is easily broken by simply trying all possible keys until it makes sense.

\subsubsection{Monoalphabetic Substitution Cipher}

Replace each letter by another character, such as

\begin{center}
    \texttt{
         plain \quad A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\\
        cipher \quad P Q S T U V W X Y Z C O D E B R A K I N G F H J L M
    }
\end{center}

The keyword \texttt{"CODEBREAKING"} starting at \texttt{K} leads to a more memorable permutation, but the code would be easier to break.

Let $\pi$ be the permutation of $\mathbb{Z}_{26}$ used, then

\begin{align*}
    E_{k}(i) &= \pi(i) \text{\quad\quad \,for all } i\\
    \text{and \quad} D_{k}(j) &= \pi^{-1}(j) \text{\quad for all } j.\\
\end{align*}

If we only use alphabetical characters as key $k$, there are still $26! \approx 4 \times 10^{26}$ possible keys so it is impossible to try them all.

\subsubsection{Transposition Cipher}

Mix up the order of the letters by dividing them up into blocks of length $l$ and applying a permutation $\pi \in \mathrm{Sym}(l)$ to the letter order. For example, with blocks of length $5$ we could use the permutation
    \[\pi =
    \begin{pmatrix}
        1 &2 &3 &4 &5\\
        3 &1 &4 &5 &2
    \end{pmatrix}
    \quad
    \text{map 1st letter} \to \text{3rd letter, 2nd} \to \text{1st, and so on.}
    \]

The $\text{Sym}(r)$ means the symmetric group. \cite{wiki:sym}

\begin{center}
    \texttt{
         plain \quad T H I S I \; S A N E X \; A M P L E\\
        cipher \quad H I T I S \; A X S N E \;  M E A P L
    }
\end{center}

Frequency counts of pairs or triples and common sense allow these ciphers to be easily broken.

\subsubsection{Combined Systems}

These use both a transposition and a substitution. They are much harder to break by hand but are still breakable using frequency counts.

\subsubsection{Vigenère Cipher}

\begin{center}
    \texttt{
        \ \ key \quad C W Q C W Q C W Q C W Q C W Q\\
        \ plain \quad P U R E A N D S O L I T U D E\\
         cipher \quad R Q H G W D F O E N E J W Z U
    }
\end{center}

\newpage

\bibliographystyle{IEEEtran}
\bibliography{References.bib}

\end{document}

# Mathematics/Information, Codes and Ciphers/Info_Codes_Ciphers.tex


% !TeX root = ../CI-Slides.tex
% \tableofcontents
% ---------------------------------------------------------%

\section{Introduction}
\subsection{Cryptocurrencies}
\begin{frame}{Cryptocurrencies}
	\begin{itemize}
	\item \cite{nakamoto_bitcoin:_2008}	laid the foundation of modern cryptocurrencies (scheme for trusted decentralized transactions)
	\item Transactions have inputs (references to previous outputs) and outputs
	\item Each output is issued to address of a user (public key)
	\item Recipient can spend outputs with private key
	\end{itemize}
\end{frame}

\begin{frame}{Blockchain}
	\resizebox{\textwidth}{!}{\input{./img/figBlock.tex}}
\end{frame}

\begin{frame}{Transaction}
	\resizebox{\textwidth}{!}{\input{./img/figTX.tex}}
\end{frame}

\subsection{Monero}
\begin{frame}{Monero}\label{sec:monero}
	\begin{itemize}
		\item Public nature of Bitcoin TX history prevents meaningful level of anonymity
		\item Monero (based on CryptoNote, \cite{van_saberhagen_cryptonote_2013}) addresses this issue with the following methods:
		\begin{itemize}[<+-|alert@+>]
			\item Stealth Addresses (hide recipient addr.) $\to$ unlinkability (p.~\ref{sec:mih})
			\item \alert<4->{Ring Signatures (obfuscate spent outputs) $\to$ untraceability}
			\item Confidential Transactions (hide amounts) $\to$ fungibility
		\end{itemize}
	\end{itemize}
\end{frame}

\subsection{Ring Signatures}
\begin{frame}{Ring Signatures \& Traceability}
	\vspace*{-10pt}
	\begin{itemize}[<+->]
		\item Each TX input references:
		\begin{itemize}
			\item Bitcoin: Output from older TX (TXO)
			\item Monero: Non-empty set of TXOs (a ring)
		\end{itemize}
		\item One ringmember is real, the others are decoys (mixins)
		\includegraphics[width=\textwidth]{./img/slides/cn-44.png}
{		\hspace*{90pt}\scriptsize Source: \url{https://cryptonote.org/inside/}}
		\item Decoys are sampled from set of eligible outputs
	\end{itemize}
\end{frame}
\section{Traceability Analysis}

\subsection{Traceability Methods I (ZMR \& IR)}
\begin{frame}{Zero Mixin Removal \& Intersection Removal}
	\resizebox{\textwidth}{!}{\input{./img/slides/zmr.tex}}
	\begin{itemize}
		\item Outputs O1-O4 are referenced in rings R1-R4
		\item<2-> R1 only references O1 $\implies$ must be the real input
		\item<3-> $I = \{R3,R4\}$ reference $O=\{O3,O4\}$  \\
		\qquad	$|I| = |O|$ $\implies$ O3 \& O4 spent in R3 \& R4
		\item<4-> $R2$ only has one non-mixin reference remaining.
	\end{itemize}
\end{frame}

\begin{frame}{Output Merging Heuristic (OMH)}
	\begin{itemize}
		\item Output merging mostly due to denomination splitting:
		\begin{itemize}
			\item Initially, amounts were disclosed on blockchain
			\item Ring signatures required multiple outputs with identical amounts
			\item Outputs were partitioned to facilitate this (7 $\to$ 5 + 2)
		\end{itemize}
	\end{itemize}
	\uncover<2->{
	\resizebox{\textwidth}{!}{\input{./img/slides/omh.tex}}
	\begin{itemize}
		\item TX4 has two inputs which reference a TXO from TX2
		\item<3-> OMH assumes that these outputs are real
	\end{itemize}}
\end{frame}

%\subsection{Previous Results}
\begin{frame}{Traceability Analysis}
	\cite{kumar_traceability_2017} and \cite{moser_empirical_2018} found:
	\begin{itemize}[<+->]
		\item Iteratively removing known spent outputs from rings allows identification of new spent outputs

		\begin{itemize}
			\item $\to$ identified majority of real spent outputs
		\end{itemize}
		\item TX outputs were partitioned into denominations (7 $\to$ 5 + 2)
		\begin{itemize}
			\item $\to$ guessing real inputs mostly correct
		\end{itemize}
		\item Temporal distribution of decoys and spent outputs don't match
		\begin{itemize}
			\item $\to$ Educated guessing based on output-age effective
		\end{itemize}
		\item Transaction protocol has been updated since
	\end{itemize}
\end{frame}

\begin{frame}{Improvements to the protocol}
	\begin{itemize}
		\item ZMR works like a chain reaction from an initial set of inputs without decoys.
		\begin{itemize}
			\item Since 2016, the mandatory minimum ringsize has been increased
			\item Minimum ringsizes + RingCT TX were effective
			\item Ringsize $\equiv 11$ since last update
		\end{itemize}
		\item Mixin sampling has been improved with different approaches
		\begin{itemize}
			\item Triangular distribution
			\item Recent zone: Force 25-50\% recent outputs
			\item Gamma distribution: Distribution based on empirical analysis
		\end{itemize}
	\end{itemize}
\end{frame}
\subsection{Traceability Methods II (Cross Chain Analysis)}
\begin{frame}{Currency hardforks}
	\begin{itemize}
		\item A cryptocurrency can be forked, resulting in two currencies.
		\item A fork can either start a new blockchain or continue the existing chain.
		\begin{center}
			\input{./img/slides/hardfork.tex}
		\end{center}
		\item Pre-fork funds can be spent on both chains
		\item This can be exploited for linking/tracing analysis
	\end{itemize}
\end{frame}

\begin{frame}{Cross Chain (Fork) Analysis}
\begin{itemize}[<+->]
	% \item Bitcoin \& Bitcoin Cash:
	% \begin{itemize}
	% 	\item Multiple Input Heuristic employed by GraphSense
	% 	\item If pre-fork funds are spent, addresses could be clustered on both post-fork branches
	% \end{itemize}
	% \item Monero:
	% \begin{itemize}
		\item Double spends are prevented with \emph{key images}
		\item Key image is derived from spent output and may occur at most once on the TX record
		\item Method to derive key image must be identical on all branches
		\item If two rings on two branches have the same key image, they spend the same TXO.
	% \end{itemize}
\end{itemize}
\end{frame}

\subsection{Contribution of this work}
\begin{frame}{Contribution of this work}
	\begin{itemize}
		\item Up to date evaluation of existing methods
		\begin{itemize}
			\item Previous studies published shortly after introduction of RingCT
			\item Changes to mixin sampling and ringsize in 09/2017 and 04/2018.
		\end{itemize}
		\item Quantify impact on traceability from recent Monero hardforks \begin{itemize}
			\item Monero Original: Continuation of Monero v6 (ASIC compatible)
			\item MoneroV: Fork with some changes to emission curve
		\end{itemize}
	\end{itemize}
\end{frame}

\section{Results}
\subsection{Dataset}
\begin{frame}{Dataset \& Method}
	\begin{enumerate}
		\item Exported Monero (XMR), MoneroV (XMV) and Monero Original (XMO) blockchain up to Aug. 31$^\text{th}$, 2018.
		\item Employed Zero Mixin Removal \& Intersection Removal
		\item Added fork data and applied cross chain analysis (+ZMR/IR)
		\item Applied heuristics from \cite{kumar_traceability_2017} and \cite{moser_empirical_2018}:
		\begin{itemize}
			\item Guess Newest Heuristic
			\item Output Merging Heuristic
		\end{itemize}
		\item Evaluated accuracy with ground truth (where possible) with results from steps 3.
	\end{enumerate}
\end{frame}

\begin{frame}{Monero Activity}
	\def\imgFile{./img/slides/txs.tex}
	\resizebox{\textwidth}{!}{\input{\imgFile}}
\end{frame}
\subsection{Results}
\begin{frame}{Traced Inputs}
	\def\imgFile{./img/slides/linked.tex}
	\input{\imgFile}
\end{frame}
\begin{frame}
	\pgfplotstableread{./data/ringsizes/ringsizesNontrivial.csv}\ringsizes
	\def\rsCSV{https://git.io/flUOZ}
	\def\imgFile{./img/slides/rsp1.tex}
	\resizebox{\textwidth}{!}{\input{\imgFile}}
\end{frame}
\begin{frame}
	\pgfplotstableread{./data/ringsizes/ringsizesNontrivial.csv}\ringsizes
	\def\rsCSV{https://git.io/flUOZ}
	\def\imgFile{./img/slides/rsp2.tex}
	\resizebox{\textwidth}{!}{\input{\imgFile}}
\end{frame}

\begin{frame}{Guess Newest Heuristic}
	\def\imgFile{./img/slides/guess_newest.tex}
	\input{\imgFile}
\end{frame}
\begin{frame}{Output Merging Heuristic}
	\def\imgFile{./img/slides/merge_stats.tex}
	\input{\imgFile}
\end{frame}
\begin{frame}{Inputs/Outputs (per TX)}
	\def\imgFile{./img/slides/inputs.tex}
	\input{\imgFile}
\end{frame}

\begin{frame}{Summary}
	\begin{itemize}[<+->]
		\item Nowadays, most Monero TXs are untraceable
		\item Guess Newest Heuristic does not work with current mixin sampling technique
		\item Impact from Cross Chain Analysis not very large
		\begin{enumerate}
			\item Forks didn't have a lot of traction
			\item Mandatory ringsize of 7 enough to prevent chain reactions
		\end{enumerate}
	\end{itemize}
\end{frame}

\begin{frame}[allowframebreaks]{References}
    \bibliographystyle{apalike-refs}
    \bibliography{cryptoPoster}
\end{frame}

\subsection{Appendix}
\begin{frame}{Bitcoin analytics}
	\begin{itemize}
		\item Analysis techniques impeded privacy of Bitcoin
		\item Sets of addresses belonging to a user can often be identified
		\begin{itemize}
			\item Multi Input Heuristic
			\item Change Heuristics
		\end{itemize}
		\item Simplified transaction graph allows further analysis
	\end{itemize}
\end{frame}

\begin{frame}{Multiple Input Heuristic (MIH)}\label{sec:mih}
	\resizebox{\textwidth}{!}{\input{./img/slides/multiInput.tex}}
	\begin{itemize}[<+->] % <+-| alert@+>
 		\item Transactions TX1-TX3 spend outputs belonging to A1-A3
		\item All outputs spent in a TX likely belong to the same person
		\item Overlapping clusters are merged
		% \item Scala library: \href{https://github.com/graphsense/graphsense-clustering}{github.com/graphsense/graphsense-clustering}
		% \qrcode{https://github.com/graphsense/graphsense-clustering}
	\end{itemize}
	\footnotetext{Back: \ref{sec:monero}}
\end{frame}
\begin{frame}{Address Clustering}
	\resizebox{\textwidth}{!}{\input{./img/slides/addressClustering.tex}}
	\begin{itemize}[<+->] % <+-| alert@+>
	\item Address graph shows addresses (1-6) and TXs (edges)
	\item Use information from e.g. MIH to label nodes
	\item Simplify graph: Address graph $\Rightarrow$ Entity graph
	\end{itemize}
	\footnotetext{Back: \ref{sec:monero}}
\end{frame}

% \subsection{Cross-Chain Traceability}
% \subsection{Accuracy OMH}
% \subsection{Accuracy GNH}
% \end{document}

2018-11-13 - Monero Cross Chain Traceability (Defensio)/sections/Slides.tex


\documentclass[12pt]{article}%
\usepackage{amsfonts}

\usepackage[utf8]{inputenc}
\usepackage{comment}

\usepackage{pgfplots}
%\pgfplotsset{width=10cm, compat=1.9}
%\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{datavisualization}

\usepackage{fancyhdr}
\usepackage{comment}
\usepackage[a4paper, top=2.2cm, bottom=2.5cm, left=2.2cm, right=2.2cm]%
{geometry}
\usepackage{times}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage{amssymb}
\usepackage{graphicx}%
\setcounter{MaxMatrixCols}{30}
\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\textbf{#1.} }{\ \rule{0.5em}{0.5em}}

\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}

\begin{document}

\title{MAT120: Integral Calculus and
Differential Equations \\
BRAC University}

\author{Syed Zuhair Hossain \\ St. ID - 19101573 \\ Section - 07 \\ Set-G}
\date{\today}
\maketitle

\section{Evaluate the following integrals by Integration by Parts}
%Given an experiment and a sample space $\mathcal{S}$, the objective of probability is to assign to each event $\textit{A}$ a number $P(A)$, called the probability of event $\textit{A}$, which will give a precise measure of the chance that $\textit{A}$ will occur.
%
\subsection{$\int x (tan^{-1}x)dx$}
\textbf{Solution}\\\\
%A computer consulting firm presently has bids out on three projects. Let $A_{i}$= \{awarded \ project \ i\}, for $i=1, 2, 3$, and suppose that $P(A_1)=.22$, $P(A_2)=0.25$, $P(A_3)=.28$, $P(A_1 \cap A_2)= .11$, $P(A_1\cap A_3)=0.05$, $P(A_2\cap A_3)=0.07$, $P(A_1\cap A_2 \cap A_3)=0.01$. Express in words each of the following events, and compute the probability of each event:%

Let, u = x
 \[v = tan^{-1}x\] \\
 du = x dx      \[dv = \frac{1}{x^{2}+1} dx\] \\
$u = \frac{x^{2}}{2}$ \\\\

According to integration by parts formula, we know that, \par \par
%line 1
$ \int u\:v\: dx = u\int vdx - \int \frac{du}{dx}(\int vdx) dx $ \\\\
%line 2
$\Rightarrow \int u\:v\:dx = \frac{x^{2}}{2} \int tan^{-1}x - \int \frac{x^2}{2(x^2+1)}dx $ \\\\
%line 3
$\Rightarrow \int u\:v\:dx = \frac{x^{2}}{2} \int tan^{-1}x - \frac{1}{2}\int (1-\frac{x^2}{2(x^2+1)}) dx $ \\\\
%line 4
$\Rightarrow \int u \:v\:dx = \frac{x^{2}}{2} \int tan^{-1}x - \frac{1}{2} \int 1 \: dx + \frac{1}{2} \int (\frac{1}{x^2+1}) dx$\\\\
%line 5
$\Rightarrow \int u \:v\:dx = \frac{x^{2}}{2} \int tan^{-1}(x) - \frac{x}{2} + \frac{1}{2} \: tan^{-1}\:(x) + c$  \ \ \ \ \ \ \ \ \  $\left [ \because \frac{1}{x^2+1}] = tan^{-1} \:(x) \right ]$\\\\
%line 6
$\therefore \: \: \int u \:v\:dx = \frac{1}{2} (x^2+1)tan^{-1}(x) - x +c \ \ \ \  \left[_{answer}\right]$ \\\\

\pagebreak

\subsection{$\int \sqrt{x} \: ln \: \sqrt{x}\:dx$}

\begin{flushleft}
    $=\int \sqrt{x} \: ln(x^{\frac{1}{2}})\: dx$\\
    $=\frac{1}{2}\int \sqrt{x} \: ln(x)\: dx$\\
\end{flushleft}

Let, \\\\
$u=ln(x)$ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $v= \sqrt{x}$ \\\\
$du = \frac{1}{x} \: dx$ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $v=\frac{2x^{\frac{3}{2}}}{3} \:dx$

\begin{flushleft}
    According \: to \ integration \ by \ parts \ formula, \ we \ know \ that,\\
    $\int u\:v\: dx &= u\int vdx - \int \frac{du}{dx}(\int vdx) dx$
\end{flushleft}

 $\int \sqrt{x} \: ln \: \sqrt{x} \: = ln(x)\: \frac{2}{3}\:(x^{\frac{3}{2}}) \: \frac{1}{3} \: \int \sqrt{x} \: dx $ \\

$\Rightarrow \int \sqrt{x} \: ln \: \sqrt{x} \: = \frac{1}{3} \: x^{\frac{3}{2}} \: ln(x) - \frac{2}{9} \:x^{\frac{3}{2}} + c$ \\

$\Rightarrow \int \sqrt{x} \: ln \: \sqrt{x} \: = \frac{1}{9} \: x^{\frac{3}{2}} \: (3\:ln(x) - 2) \: + c$ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [answer]\\

\section{Use reduction formula to evaluate: \ \ \ \ \ \
$\int_{0}^{\frac{\pi}{2}} cos^6 (x) \:dx$}

\begin{align*}
    According \: to \ &reduction \ formula \ we \ know \ that, \\
    \int cos^n(x) \: dx &= \frac{1}{n} \: cos^{n-1}(x) sin(x) \: + \frac{n-1}{n} \: \int cos^{n-2}(x) dx \\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6} (x)dx &= \frac{1}{6} \int_{0}^{\frac{\pi}{2}} cos ^{6-1}(x)\:sinx \:+  \frac{6-1}{6} \int_{0}^{\frac{\pi}{2}} cos^{6-2}(x)dx \\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6} (x) \: dx &= [\frac{1}{6} cos^{5}x\:sinx]_{0}^{\frac{\pi}{2}} \:+\: \frac{5}{6} \int_{0}^{\frac{\pi}{2}} cos^{4}x\:dx \\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= 0 + \frac{5}{6} \int_{0}^{\frac{\pi}{2}} cos^{4}(x) dx \ \ \ \ \ \ [\because \frac{1}{6} cos^{5}(\frac{\pi}{2}) \: sin(\frac{\pi}{2}) \: - \frac{1}{6} cos^{5}(0) sin(0)=0]\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6} (x)\: dx &= \frac{5}{6} (\frac{1}{4} cos^{4-1}x \: sinx +\frac{4-1}{4}\int_{\frac{\pi}{2}}^{0} cos^{4-2}x \:dx)  \ \ \ \ \ \ [\because \ applying \: reduction \: method]\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= \left [ \frac{5}{24} cos^{3}x\:sinx \right ]_{0}^{\frac{\pi}{2}} \: + \: \frac{5}{8} \int_{0}^{\frac{\pi}{2}} cos^{2}x \: dx\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6} (x)\: dx &= 0 + \frac{5}{8} \int_{0}^{\frac{\pi}{2}}cos^{2}(x)\:dx \ \ \ \ \ \ \left[\because \frac{5}{24} cos^3(\frac{\pi}{2})\:sin(\frac{\pi}{2}) - \frac{5}{24} cos^3(0)sin(0) = 0 \right]\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6} (x)\: dx &= \frac{5}{8} \int_{0}^{\frac{\pi}{2}}cos(2x) + \frac{1}{2} \int_{0}^{\frac{\pi}{2}}1\:dx\\
\end{align*}

\pagebreak

\begin{align*}
    let,\\
    u &= 2x \\
    \because du &= 2 \: dx \\
    So,\: we \: get \: &a \: new \: lower \: bound \: from \: here, \\
    u &=2 \times 0 \\
      &= 0\\
      and \: in \: &upper \: bound \\
      u &= 2 \times \frac{\pi}{2} \\
        &= \pi \\
        So,\\
        &\frac{5}{32} \int_{0}^{\pi} cos(u) du+ \frac{5}{16} \int_{0}^{\frac{\pi}{2}}1dx\\
\end{align*}

\begin{align*}
    Applying \ fundamental \ &theorem \ of \ calculus\\
    \left[\frac{5sin(u)}{32} \right]_{0}^{\pi} &= \frac{5sin(\pi)}{32} \: - \frac{5sin(0)}{32}\ \ \ \ \  \ \left[\therefore \int cos(u)\: = \: sin(u)\right]\\
    \left[\frac{5sin(u)}{32} \right]_{0}^{\pi} &=0\\
\end{align*}

\begin{align*}
    So, \ we \ get \ \ \ \ \ \ &\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= \frac{5}{16} \int_{0}^{\frac{\pi}{2}} \: 1 \: dx \\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= \left[ \frac{5x}{16}\right]_{0}^{\frac{\pi}{2}} \\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= \frac{5 \pi}{32} \: - \: \frac{5\times0}{32}\\
    \Rightarrow \int_{0}^{\frac{\pi}{2}} cos^{6}(x) \: dx &= \frac{5\pi}{32}  &  [answer]\\
\end{align*}

\pagebreak

\section{Evaluate the integral using appropriate substitution: \\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\int \frac{cos4\theta}{1+2sin\:4\theta} d\theta$}

\begin{align*}
    let, \ \ \ \ \ &\\
    u &= 4 \theta \\
    du &= 4\: d\theta\\
    So, \ we \ get \ \ \ \ &\\
    \frac{1}{4} &\int \frac{cos(u)}{1+2sin(u)}du\\
    y &= 2sin(u)+1\\
    dy &= 2cos(u)du\\
    So, we \ get\\
    \frac{1}{8} &\int \frac{1}{y} \ dy \\
    &= \frac{1}{8} \: \times \ ln(y) +c \\
    &= \frac{1}{8} \: ln(2sin(u)+1)+c \\
    &= \frac{1}{8} \: ln (2sin(4\theta)+1)+c & [answer]\\
\end{align*}

\section{Use Gamma Function to evaluate \ $\int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx$}

\begin{align*}
    let, \ \ \ \ \ \ \ &\\
    x^2 &= u \\
    \Rightarrow \frac{d}{dx} (x^2) &= \frac{d}{dx}(u)\\
    \Rightarrow 2x &= \frac{du}{dx} \\
    \Rightarrow x\:dx &= \frac{du}{2}\\
    \therefore dx &= \frac{du}{2x} = \frac{du}{2\sqrt{u}}\\\\
    So,  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \   &\\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &=  \int_{0}^{\infty} (\sqrt{u} \: )^5 \:\cdot e^{-u} \cdot \frac{du}{2\sqrt{u}}\\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &= \int_{0}^{\infty} u^{\frac{5}{2}} \cdot e^{-u} \cdot \frac{du}{2\:u^{\frac{1}{2}}} \\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &=  \frac{1}{2} \int_{0}^{\infty} e^{-u} \cdot u^{\frac{5-1}{2}}du\\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &=  \frac{1}{2} \int_{0}^{\infty} e^{-u} \cdot u^{2}\:du\\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &=  \frac{1}{2} \int_{0}^{\infty} e^{-u} \cdot u^{3-1}du\\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &= \frac{1}{2} \times \Gamma{3}\ \ \ \ \ \ \ \ \ \ \left[ \therefore \int_{0}^{\infty} \: e^{-u} \: u^{n-1} \: du \: = \Gamma{n}\right] \\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &= \frac{1}{2} \times 2! \\
    \int_{0}^{\infty} x^{5} \ e ^{-x^2} \ dx &= 1 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left[answer \right]\\
\end{align*}

\pagebreak

\section{Prove the Fundamental theorem of Calculus (It cannot be an exact copy from
any source. You can use references but it should be properly cited. Also, you
cannot copy paste directly. In that case you won’t receive any marks).}

\begin{parag}
    According to Fundamental Theorem of Calculus we know that, if there is a graph which occupies a place say, A under the graph of f which is continuous  [a,b] and F is an anti derivative of f, then\\
    \centering $\int _{a}^{b} f(x) dx = F(b) \: - \: F(a)$\\
\end{parag}

\begin{align*}
    Let, \ we \ are \ &given \ an \ \ function \ f(t) \\
    define \ the \ &function \ F(x) \ - \\
    F(x) &= \int_{a}^{x} f(t) dt\\
    \\
    Say, \ x_1 \ and \ \Delta x \ &are \ two \ values\ between \ [a+b] \\
    So, \ we \ get, \\
    F(x_1) &= \int_{a}^{x_1} \ f(t) \ dt;\\
    and\\
    F(x_1 + \Delta x) &= \int_{a}^{x_1 + \Delta x} f(t) dt\\
    If \ we \ substract, \ then \ we \ get, &\\
    \int_{a}^{x_1+ \Delta x} f(t)dt - \int_{a}^{x_1} f(t) dt &=  \int_{x_1}^{x_1+ \Delta x} f(t)dt\\
    F(x_1 + \Delta x) - F(x_1) &= \int_{x_1}^{x_1+ \Delta x} f(t)dt\\\\
    According \ to \ mean \ & value \ theorem,\\
    A \ real \ number \ exists \ &between \ r \in [x_1, x_1+\Delta] \\
    \int_{x_1}^{x_1+ \Delta x} f(t)dt &= f(r) \cdot \Delta x\\
    F(x_1 + \Delta x)- F(x_1) &= f(r) \cdot \Delta x\\
    \frac{F(x_1 + \Delta x)- F(x_1)}{\Delta x} &= f(r) \cdot \Delta x\\
    \lim_{\Delta x \to 0} \frac{F(x_1 + \Delta x)- F(x_1)}{\Delta x} &= \lim_{\Delta x \to 0} f(r) \\
    {F}'(x_1) &= \lim_{\Delta x \to 0} f(r) \ \ \ \ \ \ \ \left[\therefore \lim_{\Delta x \to 0} \frac{F(x_1 + \Delta x)- F(x_1)}{\Delta x}={F}'(x_1) \right]\\
\end{align*}

\newpage

\begin{align*}
    So, \lim_{\Delta x \to 0}x_1 \ &= x_1 \\
    and \lim_{\Delta x \to 0}x_1 + \Delta x \ &= x_1\\
   \therefore \lim_{\Delta x \to 0}r \ &= x_1\\
   We \ can \ now \ say \ that, \ & \ f \ is \ continuous \ at \ r,\\
   \therefore {F}'(x_1) = f(x_1)\\\\
   \textbf{[proved]}\\
\end{align*}

\begin{thebibliography}{9}
\bibitem{latexcompanion}
Howard A.,Iril B., Stephen D.,
\textit{Calculus}.
10th ed.,John Willey and Sons, United States of America, 2012.

\bibitem{Spivak}
Spivak, Michael (1980), Calculus (2nd ed.), Houston, Texas: Publish or Perish Inc.

\bibitem{Wikipedia}
Wikipedia : Fundamental Theorem of Calculus.
\\\texttt{https://en.wikipedia.org/wiki/Fundamental\_theorem\_of\_calculus}
\end{thebibliography}

\bigskip

\section{You are asked to integrate the following definite integrals,\\ $\int_{0}^{2\pi} sinx\:dx$}

\begin{align*}
    (a)\\
    \int_{0}^{2\pi} sinx\:dx &= \left[-cos\:x \right]_{0}^{2\pi}\\
                             &= -\:\left[cos\:x \right]_{0}^{2\pi}\\
                             &= -[cos2\pi \: - \: cos(0)]\\
                             &= -(1-1)\\
                             &= 0\\
\end{align*}

\begin{parag}
    According to Fundamental Theorem of Calculus  we know that, we will get an area after integration and area has a space which is obviously greater than zero.\\
    But, here we are getting zero, because the value of $cos2\pi$  is  positive and the value of cos(0) is negative. So,they are neglecting each other and we are getting a linear value which is zero.
\end{parag}

\centering
\pgfkeys{/pgfplots/Axis Style/.style={
    width=13.5cm, height=5cm,
    axis x line=center,
    axis y line=middle,
    samples=100,
    ymin=-1.5, ymax=1.5,
    xmin=-7.0, xmax=7.0,
    domain=-2*pi:2*pi
}}

%\begin{document}
\begin{tikzpicture}
\begin{axis}[
    Axis Style,
    xtick={
        -6.28318, -4.7123889, -3.14159, -1.5708,
        1.5708, 3.14159, 4.7123889, 6.28318
    },
    xticklabels={
        $-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$,
        $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$
    }
]
\addplot [mark=none, ultra thick, blue] {sin(deg(x))};
\addlegendentry{$sin(x)$}
\end{axis}
\end{tikzpicture}

\centering
\begin{align*}
    &\ \ \  \ \ \ (b)\\
    \int_{0}^{2\pi} \left | sinx \right |\:dx &= \int_{0}^{\pi} +\:sinx\:dx \: + \: \int_{\pi}^{2\pi} -\: sinx\:dx\ \ \ \ \ \ \ \ \ \ \ \ \left[ plotting \ the \ value \ in \ graph\right]\\
    &= \int_{0}^{\pi} \:sinx\:dx \: - \int_{\pi}^{2\pi} +\:sinx\:dx \\
    &= \left[-cosx\right]_{0}^{\pi} - \left[-cosx \right]_{\pi}^{2\pi}\\
    &= -\left[cosx\right]_{0}^{\pi} - \left[-cosx \right]_{\pi}^{2\pi}\\
    &= -\left[cos\pi \: - \: cos0\right] - \left[-cos2\pi \: - cos\pi \right]\\
    &= -\left[-1-1\right] + \left[1-(-1)\right]\\
    &= 2 \: + 2\\
    &= 4\\
    & \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [answer]\\
\end{align*}

\end{document}