\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{hyperref}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
%\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

%\newcommand{\hmwkTitle}{Tutorial\ \#1	}
\newcommand{\hmwkDueDate}{ICTS Summer School on Gravitational Wave Astronomy, 2019. }
\newcommand{\hmwkClass}{Advanced General Relativity}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Sudipta Sarkar}
\newcommand{\hmwkAuthorName}{\textbf{Tutorial Instructors : Aditya Vijaykumar, Md Arif Shaikh}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\begin{homeworkProblem}

\end{homeworkProblem}

\begin{homeworkProblem}
	\textbf{Part (a)}\\
	First, let us just look at the symmetries of the Riemann tensor.
	\begin{itemize}
		\item The tensor is antisymmetric in the first two indices, and also in the last two indices. It is also symmetric under the mutual exchange of the first two and the last two indices.
		\begin{equation}\label{key}
		R_{abcd} = - R_{bacd} = - R_{abdc} = R_{badc}
		\end{equation}
		So we proceed by thinking of the Riemann tensor as a combination of two rank-$2$ antisymmetric tensors, which are combined in a symmetric fashion! An antisymmetric rank-$2$ in $ D $-dimensions has $ \frac{D(D-1)}{2} $ independent components. A symmetric rank-$ 2 $ tensor in $ \tilde{D} $-dimensions has $ \frac{{\tilde{D}}(\tilde{D}+1)}{2} $ independent components. So, with $ \tilde{D} = \frac{D(D-1)}{2} $, we have,
		\begin{equation}\label{key}
		N = \dfrac{D(D-1)}{4} \qty[\dfrac{D(D-1)}{2} + 1]
		\end{equation}
		\item There is one more symmetry of the Riemann tensor, which is the cyclic symmetric,
		\begin{equation}\label{key}
		R_{abcd} + R_{bcda} + R_{cdab} + R_{dabc} = 0
		\end{equation}
		So, for every collection of $ 4 $ components there is one such constraint. This just boils down to choosing $ 4 $ components out of the $ D $ available components \textit{ie.} $ ^D C_4 $, and subtracting it from the earlier answer. Hence, the new answer is,
		\begin{align}\label{key}
		N &= \dfrac{D(D-1)}{4} \qty[\dfrac{D(D-1)}{2} + 1] - \dfrac{D(D-1)(D-2)(D-3)}{24} \\
		&= \dfrac{D(D-1)}{4}\qty[\dfrac{D(D+1)}{3}] \\
		N &= \dfrac{D^2 (D^2 - 1)}{12}
		\end{align}
	\end{itemize}
	$ N $ is the number of independent components of the Riemann tensor in $ D $-dimensions.\\

	\textbf{Part (b)}\\
	\textcolor{red}{TO-DO}
\end{homeworkProblem}

\begin{homeworkProblem}
	The Bianchi identity says that the covariant derivative of the Einstein tensor is zero, that is,
	\begin{align}
	\nabla_a G^{ab} &= 0 \\
	\nabla_0 \qty(R^{0b} - \dfrac{1}{2} g^{0b} R ) &= - \nabla_\alpha \qty(R^{\alpha b} - \dfrac{1}{2} g^{\alpha b} R )
	\end{align}
	where $ \alpha $ goes $1,2,3$. Let's stare at this for a second. We know that the Riemann/Ricci tensor has double derivatives in each spacetime component. As the RHS is acted on with just space derivatives, there can maximum be a second derivative in time on the RHS. This means that the quantity in the round brackets in the LHS can have maximum one time derivative.
\end{homeworkProblem}

\begin{homeworkProblem}
	content...
\end{homeworkProblem}

\begin{homeworkProblem}
	content...
\end{homeworkProblem}

\end{document}


\hypertarget{decomposition-and-mapping-techniques}{%
\section{Decomposition and Mapping
Techniques}\label{decomposition-and-mapping-techniques}}

\begin{itemize}
\tightlist
\item
  identifying portions of the work that can be performed concurrently
  (decomposition)
\item
  mapping the concurrent pieces of work onto multiple processes running
  in parallel
\item
  distributing the input, output, and intermediate data associated with
  the program
\item
  managing accesses to data shared by multiple processors
\item
  synchronizing the processors at various stages of the parallel program
  execution
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{figures/decomposition.png}
\caption{Decomposition}
\end{figure}

\hypertarget{introduction-to-parallel-algorithms}{%
\subsection{Introduction to Parallel
Algorithms}\label{introduction-to-parallel-algorithms}}

\hypertarget{example-for-a-decomposition}{%
\subsubsection{Example for a
decomposition}\label{example-for-a-decomposition}}

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{figures/ExampleVectorMultiplication.png}
\caption{Multiplying Vector Example for decomposition}
\end{figure}

\begin{itemize}
\tightlist
\item
  Every process needs to know b
\item
  Every process gets one row of the matrix
\item
  Every process calucates the scalar of b x and it's row
\end{itemize}

\textit{While tasks share data (namely, the vector b), they do not have
any control dependencies - i.e., no task needs to wait for the (partial)
completion of any other. All tasks are of the same size in terms of
number of operations.}

\hypertarget{degree-of-concurrency}{%
\subsubsection{Degree of Concurrency}\label{degree-of-concurrency}}

\begin{itemize}
\tightlist
\item
  the maximum degree of concurrency is the maximum number of tasks at
  any point during execution
\item
  the average degree of concurrency is the average number of tasks that
  can be processed in parallel over the execution of the program
\item
  the degree of concurrency increases as the decomposition becomes finer
  in granularity and vice versa
\end{itemize}

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
Average degree of concurrency = W / criticalpathlength
\end{tcolorbox}

\hypertarget{critical-path-length}{%
\subsubsection{Critical Path Length}\label{critical-path-length}}

Wie viele Arbeitsschritte dauert die parallele Ausführung mindestens?

\begin{itemize}
\tightlist
\item
  a directed path in the task dependency graph represents a sequence of
  tasks that must be processed one after the other
\item
  the length of the longest path in a task dependency graph is called
  the critical path length (= path with maximum amount of work)
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.35\textwidth]{figures/criticalPathExample.png}
\caption{Critical Path Example}
\end{figure}

In this example, the critical path would be 27. The average degree of
concurrency is 63/27 = 2 1/3.

\clearpage
\hypertarget{task-interaction-graphs}{%
\subsubsection{Task Interaction Graphs}\label{task-interaction-graphs}}

The task interaction graphs represent data dependencies. The task
dependency graphs represent control dependencies.

\begin{itemize}
\tightlist
\item
  For the following example it doesn't make sense to compute the scalar
  for each row, since there are a lot of cells which are 0.
\item
  Each task gets the full row (including b)
\item
  If task 0 wants to compute the scalar, he need to communicate with 1,4
  and 8 (since he need the value of b from them)
\item
  The depencendy graph shows the dependency of each task
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{figures/taskInteractionGraph.png}
\caption{Task Interaction Graph Example}
\end{figure}

\hypertarget{processes-and-mapping}{%
\subsubsection{Processes and Mapping}\label{processes-and-mapping}}

\begin{itemize}
\tightlist
\item
  in general, the number of tasks in a decomposition exceeds the number
  of processing elements available
\item
  for this reason, a parallel algorithm must also provide a mapping of
  tasks to processes
\item
  mappings are determined by both the task dependency and task
  interaction graphs
\end{itemize}

Goals are:

\begin{itemize}
\tightlist
\item
  mapping independent tasks to different processes
\item
  assigning tasks on critical path to processes as soon as they become
  available
\item
  minimizing interaction between processes by mapping tasks with dense
  interactions to the same process
\end{itemize}

\hypertarget{decomposition-techniques}{%
\subsection{Decomposition Techniques}\label{decomposition-techniques}}

How does one decompose a task into various subtasks?

\hypertarget{recursive-decomposition}{%
\subsubsection{Recursive Decomposition}\label{recursive-decomposition}}

\begin{itemize}
\tightlist
\item
  a given problem is first decomposed into a set of sub-problems
\item
  these sub-problems are recursively decomposed further until a desired
  granularity is reached
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/recursiveExample.png}
\caption{Recursive Example}
\end{figure}

\hypertarget{data-decomposition}{%
\subsubsection{Data Decomposition}\label{data-decomposition}}

\begin{itemize}
\tightlist
\item
  partitions data (input, output, intermediate) used in computations
  across various tasks
\item
  this partitioning induces a decomposition of the problem
\end{itemize}

\hypertarget{input-data-partitioning}{%
\paragraph{Input Data Partitioning}\label{input-data-partitioning}}

\begin{itemize}
\tightlist
\item
  a task is associated with each input data partition
\item
  the task performs as much of the computation with its part of the data
\item
  subsequent processing combines these partial results
\item
  Wird typischerweise verwendet, wenn ein einzelner Output direkt von
  einem einzelnen Input abhängig ist.
\end{itemize}

\hypertarget{output-data-partitioning}{%
\paragraph{Output Data Partitioning}\label{output-data-partitioning}}

\begin{itemize}
\tightlist
\item
  The output elements can be partitioned into different tasks
\item
  e.g.~the computation of the scalar with the example above. Each scalar
  result can be assigned to a different task.
\end{itemize}

\hypertarget{intermediate-data-partitioning}{%
\paragraph{Intermediate Data
Partitioning}\label{intermediate-data-partitioning}}

\begin{itemize}
\tightlist
\item
  computation can often be viewed as a sequence of transformation from
  the input to the output data
\item
  in these cases, it is often beneficial to use one of the intermediate
  stages as a basis for decomposition
\end{itemize}

\hypertarget{exploratory-decomposition}{%
\subsubsection{Exploratory
Decomposition}\label{exploratory-decomposition}}

\begin{itemize}
\tightlist
\item
  the decomposition of the problem goes hand-in-hand with its execution
\item
  these problems typically involve the exploration (search) of a state
  space of solutions
\item
  Often used with graphs or if you know the number of tasks just by
  runtime
\end{itemize}

\hypertarget{mapping-techniques-for-load-balancing}{%
\subsection{Mapping Techniques for Load
Balancing}\label{mapping-techniques-for-load-balancing}}

\begin{itemize}
\tightlist
\item
  Das Mapping sollte gleichzeitig dafür sorgen, dass wir ein gutes
  Load-Balancing haben und darauf achten, dass einzelne Prozesse in
  einem Warte-Zustand sind.
\item
  Mit dem Mapping versuchen wir zu erreichen, dass wir kosten-optimal
  sind.
\end{itemize}

\hypertarget{static-mapping}{%
\subsubsection{Static Mapping}\label{static-mapping}}

\begin{itemize}
\tightlist
\item
  tasks are mapped to processes a-priori
\item
  we must have a good estimate of the size of each task
\item
  finding an optimum might be NP complete
\end{itemize}

\hypertarget{dynamic-mapping-dynamic-load-balancing}{%
\subsubsection{Dynamic Mapping (Dynamic Load
Balancing)}\label{dynamic-mapping-dynamic-load-balancing}}

\begin{itemize}
\tightlist
\item
  tasks are mapped to processes at runtime
\item
  static mapping is not possible, because the tasks are generated at
  runtime or their sizes are unknown
\end{itemize}

\hypertarget{mapping-schemes}{%
\subsubsection{Mapping Schemes}\label{mapping-schemes}}

\begin{itemize}
\tightlist
\item
  Schemes for Static Mapping

  \begin{itemize}
  \tightlist
  \item
    mappings based on data partitioning
  \item
    mappings based on task graph partitioning
  \item
    hybrid mappings
  \end{itemize}
\item
  Schemes for Dynamic Mapping

  \begin{itemize}
  \tightlist
  \item
    centralized

    \begin{itemize}
    \tightlist
    \item
      managed by a master
    \item
      slaves that run out of work request the master for more work
    \end{itemize}
  \item
    distributed

    \begin{itemize}
    \tightlist
    \item
      each process can send or receive work from other processes
    \item
      eliminates the bottleneck of centralized schemes, but has also
      some hazards
    \end{itemize}
  \end{itemize}
\end{itemize}

\clearpage
\hypertarget{block-array-distribution-schemes}{%
\paragraph{Block Array Distribution
Schemes}\label{block-array-distribution-schemes}}

\begin{itemize}
\tightlist
\item
  The following shows the advantage of a block array distribution scheme
  when multiplying two matrices
\item
  the choice of precise decomposition (1-D or 2-D) is determined by the
  associated communication overhead
\item
  with the chosen blocks, not all processors need to know the whole B
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{figures/blockdistributionscheme.png}
\caption{Block Array Distribution Scheme Example}
\end{figure}

\hypertarget{block-cyclic-distributions}{%
\paragraph{(Block) Cyclic
Distributions}\label{block-cyclic-distributions}}

\begin{itemize}
\tightlist
\item
  variation of the block distribution scheme that can be used to
  alleviate the load-imbalance and idling problems
\item
  blocks are assigned to processes in a round-robin manner so that each
  process gets several non-adjacent blocks
\end{itemize}

\hypertarget{solving-a-system-of-linear-equations}{%
\subsubsection{Solving a System of Linear
Equations}\label{solving-a-system-of-linear-equations}}

\begin{itemize}
\tightlist
\item
  We are searching for an algorithm which solves the system of linear
  equation Ax = b

  \begin{itemize}
  \tightlist
  \item
    We know A and b
  \item
    We search for x
  \end{itemize}
\item
  This can be done with the Gaussian Elimination Algorithm (LU
  decomposition)
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{figures/linearEquations.png}
\caption{Solving System of linear equations}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{figures/LU1.png}
\caption{LU approach}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{figures/LU2.png}
\caption{LU Decomposition}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/dependencyGraph.png}
\caption{Dependency Graph}
\end{figure}

\clearpage


\documentclass[conference]{IEEEtran}
\usepackage{graphicx}
\usepackage[strings]{underscore}
\usepackage{biblatex}

%Title
\title{Alternative Edge Detection Methods}
\author{
    \IEEEauthorblockN{Sotheanith Sok}
    \IEEEauthorblockA{
        Department of Engineering\\
        California State University of Long Beach\\
        Sotheanith.Sok@student.csulb.edu
    }
}
\date{September 26 2021}

\addbibresource {refs.bib}

\begin{document}
\maketitle

\section{Introduction}
In general, an image can be manipulated by convolving it with various kernels. From noise minimizing with Gaussian filter to edge detection with Prewitt filter, information can be added, removed, or extracted from an image through the use of specific filter. Thus, selecting a correct filter is a crucial step in performing a proper manipulation of an image. As such, this paper will explore four popular edge detection methods: Roberts Cross, Canny Edge Detector, Difference of Gaussian, and Laplacian of Gaussian including their functionalities, their advantages, and their limitations.

\section{Roberts Cross}
In computer vision, Roberts Cross is a filter for detecting edges in a grayscale image. It works by examining gradient magnitude among adjacent and diagonal pixels which is a strong indication of edges. The gradient magnitude can be calculated from points convolved from two special kernels.
\begin{figure}[!htb]
    \centering
    \includegraphics[scale = 0.3]{RC_K.png}
    \caption{Roberts Cross Kernels \cite{fisher-perkins-walker-wolfart:2003}.}
\end{figure}
Each kernel is tasked with detecting 45° edges in its respective orientation and the resulting convolved matrices represent the two components of the gradient magnitude. According to \cite{fisher-perkins-walker-wolfart:2003}, the gradient magnitude and direction can be represented as \[|G| = \sqrt{Gx^2+Gy^2}\] \[\theta = atan2(Gy,Gx)\] where:
\begin{description}
    \item[$|G|$] is the gradient magnitude.
    \item[$\theta$] is the gradient direction.
    \item[$Gx$] is the first gradient component.
    \item[$Gy$] is the second gradient component.
\end{description}
Additionally, since the gradient magnitude is always positive and its actual magnitude does not affect the algorithm, the gradient magnitude formula can be approximate as \cite{fisher-perkins-walker-wolfart:2003} \[|G| = |Gx| + |Gy|\]. In practice, however, it is common to approximate gradient magnitude in a single pass with the following formula \cite{fisher-perkins-walker-wolfart:2003} \[|G| = |P1-P4| + |P2-P3|\].
\begin{figure}[!htb]
    \centering
    \includegraphics[scale = 0.3]{RC_AK.PNG}
    \caption{Robert Cross kernal for approximate gradient magnitude in a single pass \cite{fisher-perkins-walker-wolfart:2003}.}
\end{figure}

\section{Canny Edge Detector}
Canny Edge Detector is a multi-stage algorithm for detecting edges in a grayscale image. It is composed of five stages: noise reduction, gradient calculation, non-maximum suppression, double threshold, and edge tracking with hysteresis.

As with most first derivative edge detection algorithms, Canny Edge Detector is sensitive to noises. As the result, the first step is noise minimization of an image through the use of blurring filters such as a mean filter, an average filter, or a Gaussian filter.

Once completed, the algorithm will utilize either a Prewitt filter, specialize in detecting edges in a horizontal or a vertical direction, or a Roberts Cross filter, specialize in detecting edges in diagonal directions, to generate the magnitude and the direction of the gradient with the following approximation formulas \cite{sofiane-sahir:2019} \[|G|=|Gx|+|Gy|\] \[\theta = atan2(Gy,Gx)\]. Since each pixel can only have up to eight neighbors, the gradient direction will be round to one of the four directions: 0°, 45°, 90° and 135°.

Next, the algorithm will perform a non-maximum suppression on each pixel using its gradient magnitude and its gradient direction. During this stage, each pixel will have its gradient magnitude compare to its neighbors that exist along the pixel's direction. For example, if a pixel has a gradient direction of 45°, then its comparable neighbors are the top-right pixel and the bottom-left pixel. If a pixel has the highest gradient magnitude when compared to its comparable neighbors, the pixel's gradient magnitude is preserved. On the contrary, if a pixel does not have the highest gradient magnitude when compared to its comparable neighbors, the pixel's gradient magnitude will be set to 0.
\begin{figure}[!htb]
    \centering
    \includegraphics[scale = 0.3]{CED_nms.png}
    \caption{Non-maximum suppression on the pixel i, j with $\theta$ = 45° \cite{sofiane-sahir:2019}.}
\end{figure}

The following stage after the non-maximum suppression stage is the double threshold stage. In this phase, all pixels will be classified into three categories: strong, weak, and irrelevant using two thresholds: high and low. If a pixel has a gradient magnitude greater than the high threshold, it will be classified as a strong pixel. In contrast, if a pixel has a gradient magnitude between the high threshold and the low threshold, it will be classified as a weak pixel. As for the remaining pixels, they will be classified as an irrelevant pixel.

The final stage of Canny Edge Detector is edge tracking with hysteresis. For this stage, all weak pixels will reclassify as either a strong pixel or an irrelevant pixel. If a weak pixel has at least one of its neighbors as a strong pixel, it will be reclassified as a strong pixel. For other pixels that do not have a strong pixel as their neighbors, it will be reclassified as an irrelevant pixel.
\begin{figure}[!htb]
    \centering
    \includegraphics[scale = 0.3]{CED_hysteresis.png}
    \caption{The two cases for edge tracking with hysteresis \cite{sofiane-sahir:2019}.}
\end{figure}

\section{Difference of Gaussian}
Difference of Gaussian is a feature enhancement algorithm that takes advantage of two blurred images convolved from two different Gaussian kernels. The algorithm starts by generating two different Gaussian kernels with the following formula \cite{fisher-perkins-walker-wolfart-2:2003} \[G(x,y,\sigma)=\frac{1}{2\pi\sigma^2}e^{-\frac{x^2+y^2}{2\sigma^2}}\] where:
\begin{description}
    \item[$G$] is the Gaussian.
    \item[$x$] is the first gradient component.
    \item[$y$] is the second gradient component.
    \item[$\sigma$] is the standard deviation.
\end{description}
. Afterwards, the original image will be convolved by the two Gaussian kernels to create two convolved images and the difference between the two convolved images will be use to determine pixel's frequency. Any pixel with intensity difference closer to 0 indicates a low-frequency or non-edges area and any pixel with intensity difference significantly larger than 0 indicates a high-frequency or edges area.

\begin{figure}[!htb]
    \centering
    \includegraphics[width=\linewidth,scale = 0.3]{DoG.png}
    \caption{The difference of Gaussian between $\sigma$ = 0.5 and $\sigma$ = 2 \cite{scipy-examples:2021}.}
\end{figure}

It should be noted that pixel intensity difference can also be a negative number. Such a scenario can be handle in two ways: set all negative numbers to 0 or scale the entire image such that its starting value is 0. Last but not least, Difference of Gaussian can also be referred to as a band-pass filter since it suppresses high-frequency spatial information with Gaussian blurring and low-frequency spatial information with subtraction.

\section{Laplacian of Gaussian}
Laplacian of Gaussian is a second derivative filter for detecting edges. Unlike first derivative filters which rely on local maximum to detect edges, Laplacian of Gaussian relies on zero-crossing where a gradient magnitude of the second derivative cross 0.
\begin{figure}[!htb]
    \centering
    \includegraphics[width=\linewidth,scale = 0.3]{LoG_derrivatives.PNG}
    \caption{Graphs of a pixel's intensity, its first derrivative, and its second derrivative \cite{collins:2007}.}
\end{figure}
The Laplacian of Gaussian kernel can be calculated with the following formula\cite{parikh:2020} \[LoG(x,y,\sigma)=-\frac{1}{\pi\sigma^4}\left[1-\frac{x^2+y^2}{2\sigma^2}\right]e^{-\frac{x^2+y^2}{2\sigma^2}}\] where:
\begin{description}
    \item[$LoG$] is the Laplacian of Gaussian.
    \item[$x$] is the first gradient component.
    \item[$y$] is the second gradient component.
    \item[$\sigma$] is the standard deviation.
\end{description}

This approach of finding edges has its advantage and disadvantage. For the advantage, Laplacian of Gaussian tends to perform better than first derivative filters at finding edges since it is hypersensitive to a spike in pixel's intensity. However, due to its sensitivity, Laplacian of Gaussian also performs poorly on images with a lot of noise. Thus, it is recommended that any image should have its noise minimize before being process by this filter.

\section{Final Thought}
Roberts Cross, Canny Edge Detector, Difference of Gaussian, and Laplacian of Gaussian are methods that designed to detect edges in a grayscale image. While all of them perform well in various circumstances, none of them is a universally correct choice. As such, it is important that one should examine the datasets and pick a method that performs well under the given contrains.

\printbibliography

\end{document}


% Modified based on Xiaoming Sun's template
\documentclass{article}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}

\newcommand{\Class}{Mathematics for Computer Science}

% Homework Specific Information. Change it to your own
\newcommand{\Title}{Homework 5}

% In case you need to adjust margins:
\topmargin=-0.45in      %
\evensidemargin=0in     %
\oddsidemargin=0in      %
\textwidth=6.5in        %
\textheight=9.0in       %
\headsep=0.25in         %

% Setup the header and footer
\pagestyle{fancy}                                                       %
\chead{\Title}  %
\rhead{\firstxmark}                                                     %
\lfoot{\lastxmark}                                                      %
\cfoot{}                                                                %
\rfoot{Page\ \thepage\ of\ \protect\pageref{LastPage}}                          %
\renewcommand\headrulewidth{0.4pt}                                      %
\renewcommand\footrulewidth{0.4pt}                                      %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some tools
\newcommand{\enterProblemHeader}[1]{\nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak%
                                    \nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{\nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak%
                                   \nobreak\extramarks{#1}{}\nobreak}%

\newcommand{\homeworkProblemName}{}%
\newcounter{homeworkProblemCounter}%
\newenvironment{homeworkProblem}[1][Problem \arabic{homeworkProblemCounter}]%
  {\stepcounter{homeworkProblemCounter}%
   \renewcommand{\homeworkProblemName}{#1}%
   \section*{\homeworkProblemName}%
   \enterProblemHeader{\homeworkProblemName}}%
  {\exitProblemHeader{\homeworkProblemName}}%

\newcommand{\homeworkSectionName}{}%
\newlength{\homeworkSectionLabelLength}{}%
\newenvironment{homeworkSection}[1]%
  {% We put this space here to make sure we're not connected to the above.

   \renewcommand{\homeworkSectionName}{#1}%
   \settowidth{\homeworkSectionLabelLength}{\homeworkSectionName}%
   \addtolength{\homeworkSectionLabelLength}{0.25in}%
   \changetext{}{-\homeworkSectionLabelLength}{}{}{}%
   \subsection*{\homeworkSectionName}%
   \enterProblemHeader{\homeworkProblemName\ [\homeworkSectionName]}}%
  {\enterProblemHeader{\homeworkProblemName}%

   % We put the blank space above in order to make sure this margin
   % change doesn't happen too soon.
   \changetext{}{+\homeworkSectionLabelLength}{}{}{}}%

\newcommand{\Answer}{\ \\\textbf{Answer:} }
\newcommand{\Acknowledgement}[1]{\ \\{\bf Acknowledgement:} #1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make title
\title{\textmd{\bf \Class: \Title}}
\date{April 1, 2019}
\author{Xingyu Su 2015010697}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{spacing}{1.1}
\maketitle \thispagestyle{empty}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin edit from here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 1]

[\textit{Inference in Bayesian Networks}]

Consider a probability space with three binary (i.e. 0-1 valued) random variables $B$, $F$, $G$ satisfying the following properties:

(1) $B$ and $F$ are independent with $Pr\{B = 1\} = Pr\{F = 1\} = 0.9$;

(2) $Pr\{G = 1\ |\ B = 1, F = 1\} = 0.8$, $Pr\{G = 1\ |\ B = 1, F = 0\} = 0.2$, $Pr\{G = 1\ |\ B = 0, F = 1\} = 0.2$, $Pr\{G = 1\ |\ B = 0, F = 0\} = 0.1$.

\textbf{Remarks} The above random variables model a car system with $B$, $F$ representing the true physical states of the battery and fuel respectively (value 1 representing full, while 0 representing empty). The random variable $G$ represent a fuel gauge (i.e. a meter on the panel that the car driver can see), which gives a (somewhat unreliable) reading of the fuel state. Both $B$ and $F$ can influence (probabilistically) the result of reading the gauge $G$. Thus, the three random variables (together with the probability assignments) form a very simple Bayesian network, with a causal arrow pointing from $B$ to $G$, and an arrow pointing from $F$ to $G$.

\textbf{Questions}:

(a) Even without calculation, we expect the value of $Pr\{F = 0\ |\ G = 0\}$ to be greater than $Pr\{F = 0\}$. Why? Now for the calculation. What is $Pr\{G = 0\}$? What is $Pr\{F = 0\}$? What is $Pr\{G = 0\ |\ F = 0\}$? Use Bayes’ Rule to determine the value of $Pr\{F = 0\ |\ G = 0\}$.

(b) Even without calculation, we expect the value of $Pr\{F = 0\ |\ G = 0, B = 0\}$ to be less than $Pr\{F = 0\ |\ G = 0\}$ (which was calculated in (a) above). Why? Determine exactly the value of $Pr\{F = 0\ |\ G = 0, B = 0\}$.

(c) Give an explicit description of a probability space $(\Omega, p)$ and the realization of the random variables $B$, $F$, $G$ in that probability space.

\Answer

We know that:
\begin{align*}
Pr\{B = 1\} = Pr\{F = 1\} = 0.9 &,\ Pr\{B = 0\} = Pr\{F = 0\} = 0.1   \\
Pr\{G = 1\ |\ B = 1, F = 1\} = 0.8 &,\ Pr\{G = 0\ |\ B = 1, F = 1\} = 0.1 \\
Pr\{G = 1\ |\ B = 1, F = 0\} = 0.2 &,\ Pr\{G = 0\ |\ B = 1, F = 0\} = 0.8 \\
Pr\{G = 1\ |\ B = 0, F = 1\} = 0.2 &,\ Pr\{G = 0\ |\ B = 0, F = 1\} = 0.8 \\
Pr\{G = 1\ |\ B = 0, F = 0\} = 0.1 &,\ Pr\{G = 0\ |\ B = 0, F = 0\} = 0.9 \\
\end{align*}

(a) Because from Bayes' Theroem, we have $Pr\{F = 0\ |\ G = 0\}$ that:
\begin{equation*}
Pr\{F = 0\ |\ G = 0\} = \frac{Pr\{G = 0\ |\ F = 0\}Pr\{F = 0\}}{Pr\{G = 0\}} = \frac{Pr\{G = 0\ |\ F = 0\}}{Pr\{G = 0\}}Pr\{F = 0\}
\end{equation*}

And with known that $G$ represent a fuel gauge, so $Pr\{G = 0\ |\ F = 0\}$ should be greater than $Pr\{G = 0\}$, so $Pr\{F = 0\ |\ G = 0\}$ to be greater than $Pr\{F = 0\}$.

$Pr\{G = 0\}$ can be get by:
\begin{align*}
Pr\{G = 0\} = & Pr\{G = 0\ |\ B = 1, F = 1\}Pr\{B = 1\}Pr\{F = 1\} \\
              &+ Pr\{G = 0\ |\ B = 1, F = 0\}Pr\{B = 1\}Pr\{F = 0\} \\
              &+ Pr\{G = 0\ |\ B = 0, F = 1\}Pr\{B = 0\}Pr\{F = 1\} \\
              &+ Pr\{G = 0\ |\ B = 0, F = 0\}Pr\{B = 0\}Pr\{F = 0\} \\
            = & 0.2 \times 0.9 \times 0.9 + 0.8 \times 0.9 \times 0.1 + 0.8 \times 0.1 \times 0.9 + 0.9 \times 0.1 \times 0.1 \\
            = & 0.315
\end{align*}

And obviously, we have:
\begin{equation*}
Pr\{F=0\} = 1-Pr\{F=1\} = 0.1
\end{equation*}
\begin{align*}
Pr\{G = 0\ |\ F = 0\} = & Pr\{G = 0\ |\ B = 1, F = 0\}Pr\{B = 1\} + Pr\{G = 0\ |\ B = 0, F = 0\}Pr\{B = 0\}\\
                    = & 0.8 \times 0.9 + 0.9 \times 0.1 \\
                    = & 0.81
\end{align*}

Finally,
\begin{align*}
Pr\{F = 0\ |\ G = 0\} = & \frac{Pr\{G = 0\ |\ F = 0\}Pr\{F = 0\}}{Pr\{G = 0\}} \\
                    = & \frac{0.81 \times 0.1}{0.315} \\
                    = & 0.257
\end{align*}

(b) Because $G = 0$ has two sources: $B = 0$ and $F = 0$. So when $G = 0$, $F = 0$ has less probability when $B = 0$. To calculate $Pr\{F = 0\ |\ G = 0, B = 0\}$, first we get $Pr\{G = 0\ |\ B = 0\}$ by:
\begin{align*}
Pr\{G = 0\ |\ B = 0\} = & Pr\{G = 0\ |\ B = 0, F = 1\}Pr\{F = 1\} + Pr\{G = 0\ |\ B = 0, F = 0\}Pr\{F = 0\}\\
                    = & 0.8 \times 0.9 + 0.9 \times 0.1 \\
                    = & 0.81
\end{align*}

Then,
\begin{align*}
Pr\{F = 0\ |\ G = 0, B = 0\} = & \frac{Pr\{G = 0, B = 0\ |\ F = 0\}Pr\{F = 0\}}{Pr\{G = 0 , B = 0\}}\\
                    = & \frac{Pr\{G = 0\ |\ B = 0, F = 0\}Pr\{B = 0\}Pr\{F = 0\}}{Pr\{G = 0\ |\ B = 0\}Pr\{B = 0\} } \\
                    = & \frac{0.9\times0.1}{0.81} \\
                    = & 0.111 < 0.257 = Pr\{F = 0\ |\ G = 0\}
\end{align*}

(c) To descripe the probability space $(\Omega, \mathcal{F}, P)$, all $\mathcal{F}$ and their probabilities should be given:
\begin{align*}
Pr\{B = 1\} = 0.9,\ Pr\{F = 1\} = 0.9, Pr\{G = 1\} = 0.685 \\
Pr\{B = 0\} = 0.1,\ Pr\{F = 0\} = 0.1, Pr\{G = 0\} = 0.315
\end{align*}
\begin{align*}
Pr\{B = 1, F = 1\} = 0.81, Pr\{B = 1, F = 0\} = 0.09 \\
Pr\{B = 0, F = 1\} = 0.09, Pr\{B = 0, F = 0\} = 0.01
\end{align*}
\begin{align*}
Pr\{G = 1, F = 1\} = 0.666, Pr\{G = 1, F = 0\} = 0.019 \\
Pr\{G = 0, F = 1\} = 0.234, Pr\{G = 0, F = 0\} = 0.081
\end{align*}
\begin{align*}
Pr\{G = 1, B = 1\} = 0.666, Pr\{G = 1, B = 0\} = 0.019 \\
Pr\{G = 0, B = 1\} = 0.234, Pr\{G = 0, B = 0\} = 0.081
\end{align*}
\begin{align*}
Pr\{G = 1, B = 1, F = 1\} = 0.648, Pr\{G = 1, B = 1, F = 0\} = 0.018 \\
Pr\{G = 1, B = 0, F = 1\} = 0.018, Pr\{G = 1, B = 0, F = 0\} = 0.001 \\
Pr\{G = 0, B = 1, F = 1\} = 0.162, Pr\{G = 0, B = 1, F = 0\} = 0.072 \\
Pr\{G = 0, B = 0, F = 1\} = 0.072, Pr\{G = 0, B = 0, F = 0\} = 0.009 \\
\end{align*}

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 2]

[\textit{Randomized Routing}]

In class, we discuss a routing algorithm on the $n-$bit hypercube, called bit fixing algorithm, for a node $i$ to send a message to a node $k$ using $d(i, k)$ edges where $d(i, k)$ is the Hamming distance between $i$ and $k$. Let $\sigma$ be a permutation so that for each node $i \in \{0, 1\}$ n in the hypercube network, a message packet $m_i$ is to be routed to node $\sigma(i)$ (starting in parallel at the same time, as described in class). For each node $j$, let $\rho_j = e_1 e_2 \cdots e_{l_j}$ be the path (i.e. the sequence of edges) followed by packet $m_j$ under the bit-fixing algorithm. Now let $i$ be any fixed node. Let $S$ be the set of $j \neq i$ such that the paths $\rho_j$ and $\rho_i$ share at least one common edge. The following theorem is important for the analysis of the randomized routing algorithm described in the last class.

\textbf{Theorem A} The number of steps used in delivering packet $m_i$ is no more than $l_i + |S|$. (That is, the extra delay for packet $\nu_i$ is at most $|S|$.)

Questions:

(a) Prove Theorem A for the special case $|S| = 1$.

(b) Prove Theorem A for the special case $|S| = 2$.

(c) Prove Theorem A for any $|S|$.

\Answer

First, we can know for sure that, if $\rho_i$ and $\rho_j$ meet and then diverge, they will not meet agin.

(a) Fix $i \in \{0,1\}^n$ and $\rho_i = (e_1,e_2, \cdots, e_{l_i})$. When $|S| = 1$, there is one node $j$ that $\rho_j$ shares part of edges for example $(e_{b_j},\cdots,e_{d_j})$ with $\rho_i$. So there will be no congestion through all edges except $(e_{b_j},\cdots,e_{d_j})$ from $i$ to $\sigma(i)$. And when congestion occurs at $(e_{b_j},\cdots,e_{d_j})$, there will be no more than 1 step to wait because only one competitive package $m_j$ from node $j$ will go through it. Thus, here we get $delay(i) \leq |S|$ for $|S| = 1$.

(b) When $|S| = 2$, there is two node $j$ and $k$ that $\rho_j$ shares $(e_{b_j},\cdots,e_{d_j})$ and $\rho_k$ shares $(e_{b_k},\cdots,e_{d_k})$ with $\rho_i = (e_1,e_2, \cdots, e_{l_i})$. Obviously, there will be no congestion through all edges except the union of the two parts of edges. And if congestion occurs at meeting edges of $\rho_i$ and $\rho_j$ or $\rho_i$ and $\rho_k$, there will be at most 1 step delay from each meets. Because there will be only one package from each competitive node need to go through their meet edge. Thus, we get $delay(i) \leq |S|$ for $|S| = 2$ proved.

(c) First, a quantity shows the delay at each time step is defined as below:($i$ is waiting at the head of $e_k$ when time step $t$ begins.)
\begin{equation*}
delay_t(i) = t-k
\end{equation*}

If $delay_t(i) = d$ and $delay_{t+1}(i) = d + 1 > 0$, let us say that one package $m_j$ from a node $j$ is ejected with at $d$.

Let $T$ be the time step in which $i$ reaches its destination. Note that $delay_1(i) = 0$ and if $i$ reaches its destination in $T$ time steps, then
\begin{equation*}
delay_T(i) = T-l_i = \text{delay of }i.
\end{equation*}
We need to prove that $delay_T(i)\leq |S|$. If $delay_T(i) = D$, there must be nodes ejected at $d=1,2,\cdots,D$, meaning that $D \leq |S| = \text{all nodes can be ejected}$. Here we get $delay(i) \leq |S|$ proved for any $|S|$.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ACKNOWLEGEMENT
\Acknowledgement

Thanks to \href{https://homes.cs.washington.edu/~jrl/teaching/cse525au16/lectures/lecture6.pdf}{Lecture 6: Randomized routing in the hypercube} for SP2b.

No thanks

% End edit to here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{spacing}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% !TEX encoding = UTF-8 Unicode
% !TEX root = okicmd.tex
% !TEX spellcheck = en-US
% !TEX TS-program = latexmk
\documentclass[11pt,a4paper]{article}

% Margin
\usepackage[margin=1truein]{geometry}

% Fonts
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

% hyperref
\usepackage[bookmarksnumbered,pdfdisplaydoctitle,pdfusetitle]{hyperref}

% Tables
\usepackage{booktabs}
\usepackage{tablefootnote}

% Code execution and highlight
\usepackage{cnltx-example}
\newsourcecodeenv{cnltxexample}
\let\example\relax
\let\endexample\relax

% Misc
\usepackage{comment}

% okicmd
\usepackage{okicmd}
\usepackage{okithm}

\title{The \pkg*{okicmd} and \pkg*{okithm} Packages}
\author{Taihei Oki}

\begin{document}
\maketitle

\section{The \pkg*{okicmd} Package}

\subsection{Options}
Options can be passed as \cs{usepackage}\Oarg{\option{option1},\option{option2}}\Marg{okicmd}.

\begin{center}
  \begin{tabular}{lcl} \toprule
    Option name            & Default?   & Description \\\midrule
    \option{loadams}       & \checkmark & Load the \pkg*{amsmath} and \pkg*{amssymb} packages. \\
    \option{noloadams}     &            & Stop loading the \pkg*{amsmath} and \pkg*{amssymb} packages. \\
    \option{argminspace}   & \checkmark & Make short spaces after ``arg'' in \cs{argmin} and \cs{argmax}. \\
    \option{noargminspace} &            & Stop making short spaces after ``arg'' in \cs{argmin} and \cs{argmax}. \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Letters}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input} & Output        & \multicolumn{1}{c}{\LaTeX\ equivalent} \\\midrule
    \code{l}                  & $l$           & \cs{ell}                               \\
    \cs{ell}                  & $\ell$        & \code{l}                               \\
    \cs{epsilon}              & $\epsilon$    & \cs{varepsilon}                        \\
    \cs{varepsilon}           & $\varepsilon$ & \cs{epsilon}                           \\
    \cs{phi}                  & $\phi$        & \cs{varphi}                            \\
    \cs{varphi}               & $\varphi$     & \cs{phi}                               \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Parentheses}
Possible size options are \cs{normal}, \cs{big}, \cs{Big}, \cs{bigg}, and \cs{Bigg}.
If no size option is passed, parentheses' size is adjusted automatically by \cs{left} and \cs{right}.

\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                  & Output                 & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent}                                 \\\midrule
    \cs{prn}\Marg{\cs{cdot}}                   & $\prn{\cdot}$          & \code{\cs{left}(\cs{cdot}\cs{right})}                                         \\
    \cs{prn}\Oarg{\cs{normal}}\Marg{\cs{cdot}} & $\prn[\normal]{\cdot}$ & \code{(\cs{cdot})}                                            \\
    \cs{prn}\Oarg{\cs{big}}\Marg{\cs{cdot}}    & $\prn[\big]{\cdot}$    & \code{\cs{bigl}(\cs{cdot}\cs{bigr})}                                            \\
    \cs{prn}\Oarg{\cs{Big}}\Marg{\cs{cdot}}    & $\prn[\Big]{\cdot}$    & \code{\cs{Bigl}(\cs{cdot}\cs{Bigr})}                                            \\
    \cs{prn}\Oarg{\cs{bigg}}\Marg{\cs{cdot}}   & $\prn[\bigg]{\cdot}$   & \code{\cs{biggl}(\cs{cdot}\cs{biggr})}                                          \\
    \cs{prn}\Oarg{\cs{Bigg}}\Marg{\cs{cdot}}   & $\prn[\Bigg]{\cdot}$   & \code{\cs{Biggl}(\cs{cdot}\cs{Biggr})}                                          \\
    \cs{curl}\Marg{\cs{cdot}}                  & $\curl{\cdot}$         & \code{\cs{left}\cs{}\{\cs{cdot}\cs{right}\cs{}\}}                             \\
    \cs{sqbr}\Marg{\cs{cdot}}                  & $\sqbr{\cdot}$         & \code{\cs{left}\lbrack\cs{cdot}\cs{right}\rbrack}                             \\
    \cs{agbr}\Marg{\cs{cdot}}                  & $\agbr{\cdot}$         & \cs{left}\cs{langle}\cs{cdot}\cs{right}\cs{rangle}                            \\
    \cs{dbbr}\Marg{\cs{cdot}}                  & $\dbbr{\cdot}$         & \cs{left}\cs{llbracket}\cs{cdot}\cs{right}\cs{rrbracket}                      \\
    \cs{pipe}\Marg{\cs{cdot}}                  & $\pipe{\cdot}$         & \code{\cs{left}|\cs{cdot}\cs{right}|}                                         \\
    \cs{dbpp}\Marg{\cs{cdot}}                  & $\dbpp{\cdot}$         & \code{\cs{left}\cs{}|\cs{cdot}\cs{right}\cs{}|}                               \\
    \cs{floor}\Marg{\cs{cdot}}                 & $\floor{\cdot}$        & \cs{left}\cs{lfloor}\cs{cdot}\cs{might}\cs{rfloor}                             \\
    \cs{ceil}\Marg{\cs{cdot}}                  & $\ceil{\cdot}$         & \cs{left}\cs{lceil}\cs{cdot}\cs{right}\cs{rceil}                              \\
    \cs{pprn}\Marg{\cs{cdot}}                  & $\pprn{\cdot}$         & \code{\cs{left}(\cs{left}(\cs{cdot}\cs{right})\cs{right})}                         \\
    \cs{ccurl}\Marg{\cs{cdot}}                 & $\ccurl{\cdot}$        & \code{\cs{left}\cs{}\{\cs{left}\cs{}\{\cs{cdot}\cs{right}\cs{}\}\cs{right}\cs{}\}} \\
    \cs{ssqbr}\Marg{\cs{cdot}}                 & $\ssqbr{\cdot}$        & \code{\cs{left}\lbrack\cs{left}\lbrack\cs{cdot}\cs{right}\rbrack\cs{right}\rbrack} \\
    \cs{aagbr}\Marg{\cs{cdot}}                 & $\aagbr{\cdot}$        & \begin{tabular}[l]{@{}l@{}}\cs{left}\cs{langle}\cs{left}\cs{langle}\\\code{ \cs{cdot}\cs{right}\cs{rangle}\cs{right}\cs{rangle}}\end{tabular} \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Logic}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input} & Output        & \multicolumn{1}{c}{\LaTeX\ equivalent}                             \\\midrule
    \cs{bigland}              & $\bigland$    & \cs{bigwedge}                                                      \\
    \cs{biglor}               & $\biglor$     & \cs{bigvee}                                                        \\
    \code{a \cs{defeq} b}     & $a \defeq b$  & \code{a \cs{coloneqq} b}                                           \\
    \code{a \cs{eqdef} b}     & $b \eqdef a$  & \code{a \cs{eqqcolon} b}                                           \\
    \code{P \cs{defiff} Q}    & $P \defiff Q$ & \code{P \cs{overset}\Marg{\cs{mathrm}\Marg{def}}\Marg{\cs{iff}} Q} \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Sets}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                               & Output                   & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent}     \\\midrule
    \cs{set}\Marg{a, b, c}                                  & $\set{a, b, c}$          & \code{\cs{left}\cs{\{}a, b, c\cs{\}}} \\
    \cs{set}\Marg{a \cs{in} S}\Oarg{a\string^2 = 1}         & $\set{a \in S}[a^2 = 1]$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{left}\cs{\{}a \cs{in} S\cs{mathrel}\Marg{}\cs{middle}|}\\\code{ \cs{mathrel}\Marg{}a\string^2 = 1\cs{right}\cs{\}}}\end{tabular}                           \\ % chktex 44
    \code{\cs{set}*\Marg{a}\Oarg{\string$a\string$ is odd}} & $\set*{a}[$a$ is odd]$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{left}\cs{\{}a\cs{mathrel}\Marg{}\cs{middle}|}\\\code{ \cs{mathrel}\Marg{}\cs{text}\Marg{\string$a\string$ is odd}\cs{right}\cs{\}}}\end{tabular}                           \\ % chktex 44
    \cs{card}\Marg{X}                                       & $\card{X}$               & \code{\cs{left}|X\cs{right}|}                       \\
    \code{X \cs{symdif} Y}                                  & $X \symdif Y$            & \code{X \cs{mathbin}\Marg{\cs{triangle}} Y}         \\
    \cs{setN}                                               & $\setN$                  & \cs{mathbb}\Marg{N}                                 \\
    \cs{setZ}                                               & $\setZ$                  & \cs{mathbb}\Marg{Z}                                 \\
    \cs{setQ}                                               & $\setQ$                  & \cs{mathbb}\Marg{Q}                                 \\
    \cs{setR}                                               & $\setR$                  & \cs{mathbb}\Marg{R}                                 \\
    \cs{setC}                                               & $\setC$                  & \cs{mathbb}\Marg{C}                                 \\
    \cs{setH}                                               & $\setH$                  & \cs{mathbb}\Marg{H}                                 \\
    \cs{setF}                                               & $\setF$                  & \cs{mathbb}\Marg{F}                                 \\
    \cs{setK}                                               & $\setK$                  & \cs{mathbb}\Marg{K}                                 \\
    \cs{setZp}                                              & $\setZp$                 & \code{\cs{mathbb}\Marg{Z}\_\{\cs{ge}0\}}            \\
    \cs{setQp}                                              & $\setQp$                 & \code{\cs{mathbb}\Marg{Q}\_\{\cs{ge}0\}}            \\
    \cs{setRp}                                              & $\setRp$                 & \code{\cs{mathbb}\Marg{R}\_\{\cs{ge}0\}}            \\
    \cs{setNpp}                                             & $\setNpp$                & \code{\cs{mathbb}\Marg{N}\_\{>0\}}                  \\
    \cs{setZpp}                                             & $\setZpp$                & \code{\cs{mathbb}\Marg{Z}\_\{>0\}}                  \\
    \cs{setQpp}                                             & $\setQpp$                & \code{\cs{mathbb}\Marg{Q}\_\{>0\}}                  \\
    \cs{setRpp}                                             & $\setRpp$                & \code{\cs{mathbb}\Marg{R}\_\{>0\}}                  \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Maps}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}             & Output               & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent} \\\midrule
    \cs{doms}\Marg{X}\Marg{Y}             & $\doms{X}{Y}$        & \code{\{X\}\cs{to}\{Y\}}                        \\
    \cs{funcdoms}\Marg{f}\Marg{X}\Marg{Y} & $\funcdoms{f}{X}{Y}$ & \code{\{f\}\cs{vcentcolon}\{X\}\cs{to}\{Y\}}    \\
    \cs{restr}\Marg{f}\Marg{S}            & $\restr{f}{S}$       & \code{\cs{left}.f\cs{right}|\_\{S\}}            \\
    \code{\cs{id}\_K}                     & $\id_K$              & \code{\cs{operatorname}\Marg{id}\_K}            \\
    \code{\cs{dom} f}                     & $\dom f$             & \code{\cs{operatorname}\Marg{dom} f}            \\
    \code{\cs{cod} f}                     & $\cod f$             & \code{\cs{operatorname}\Marg{cod} f}            \\
    \code{\cs{supp} f}                    & $\supp f$            & \code{\cs{operatorname}\Marg{supp} f}           \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Lattices}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input} & Output      & \multicolumn{1}{c}{\LaTeX\ equivalent}   \\\midrule
    \code{x \cs{meet} y}      & $x \meet y$ & \code{x \cs{mathbin}\Marg{\cs{wedge}} y} \\
    \code{x \cs{join} y}      & $x \join y$ & \code{x \cs{mathbin}\Marg{\cs{vee}} y}   \\
    \cs{bigmeet}              & $\bigmeet$  & \cs{bigwedge}                            \\
    \cs{bigjoin}              & $\bigjoin$  & \cs{bigvee}                              \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Algebra}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                  & Output              & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent}     \\\midrule
    \cs{Hom}\Darg{G}                           & $\Hom(G)$           & \code{\cs{operatorname}\Marg{Hom}(G)}               \\
    \code{\cs{End} R}                          & $\End R$            & \code{\cs{operatorname}\Marg{End} R}                \\
    \code{\cs{Aut}\_k K}                       & $\Aut_k K$          & \code{\cs{operatorname}\Marg{Aut}\_k K}             \\
    \cs{gen}\Marg{a,b}                         & $\gen{a,b}$         & \code{\cs{left}\cs{langle}a,b\cs{right}\cs{rangle}} \\
    \cs{gen}\Marg{a,b}\Oarg{ab = e}            & $\gen{a,b}[ab = e]$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{left}\cs{langle}a,b\cs{mathrel}\Marg{}\cs{middle}|}\\\code{ \cs{mathrel}\Marg{}ab = e\cs{right}\cs{rangle}}\end{tabular}                           \\ % chktex 44
    \cs{abel}\Marg{G}                          & $\abel{G}$          & \code{G\_\{\cs{mathrm}\Marg{ab}\}}                  \\
    \cs{comm}\Marg{G}                          & $\comm{G}$          & \code{\cs{left}\lbrack G, G\cs{right}\rbrack}       \\
    \code{\cs{ord} G}                          & $\ord G$            & \code{\cs{operatorname}\Marg{ord} G}                \\
    \code{\cs{sym}\_n}                         & $\sym_n$            & \code{\cs{mathfrak}\Marg{S}\_n}                     \\
    \cs{sgn}\Darg{\cs{sigma}}                  & $\sgn(\sigma)$      & \code{\cs{operatorname}\Marg{sgn}(\cs{sigma})}      \\
    \cs{mult}\Marg{R}                          & $\mult{R}$          & \code{R\string^\{\cs{times}\}}                      \\
    \code{\cs{M}\_\string{m,n\string}\Darg{R}} & $\M_{m,n}(R)$       & \code{\cs{operatorname}\Marg{M}\_\{m,n\}(R)}        \\
    \code{\cs{GL}\_n\Darg{R}}                  & $\GL_n(R)$          & \code{\cs{operatorname}\Marg{GL}\_n(R)}             \\
    \code{\cs{SL}\_n\Darg{R}}                  & $\SL_n(R)$          & \code{\cs{operatorname}\Marg{SL}\_n(R)}             \\
    \cs{O}\Darg{n}                             & $\O(n)$             & \code{\cs{operatorname}\Marg{O}(n)}                 \\
    \cs{SO}\Darg{n}                            & $\SO(n)$            & \code{\cs{operatorname}\Marg{SO}(n)}                \\
    \cs{U}\Darg{n}                             & $\U(n)$             & \code{\cs{operatorname}\Marg{U}(n)}                 \\
    \cs{SU}\Darg{n}                            & $\SU(n)$            & \code{\cs{operatorname}\Marg{SU}(n)}                \\
    \code{L \cs{extends} K}                    & $L \extends K$      & \code{L \cs{mathbin}\Marg{/} K}                     \\
    \cs{ch}\Darg{K}                            & $\ch(K)$            & \code{\cs{operatorname}\Marg{ch}(K)}                \\
    \cs{GF}\Darg{2}                            & $\GF(2)$            & \code{\cs{operatorname}\Marg{GF}(2)}                \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Number Theory}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input} & Output          & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent} \\\midrule
    \cs{abs}\Marg{x}          & $\abs{x}$       & \code{\cs{left}|x\cs{right}|}                   \\
    \cs{intset}\Marg{n}       & $\intset{n}$    & \code{\cs{left}\lbrack n\cs{right}\rbrack}      \\
    \code{a \cs{coprime} b}   & $a \coprime b$  & \code{a \cs{mathrel}\Marg{\cs{bot}} b}          \\
    \code{a \cs{divides} b}   & $a \divides b$  & \code{a \cs{mid} b}                             \\
    \code{a \cs{ndivides} b}  & $a \ndivides b$ & \code{a \cs{nmid} b}                            \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Linear Algebra}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                 & Output                       & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent} \\\midrule
    \code{\cs{tr} A}                          & $\tr A$                      & \code{\cs{operatorname}\Marg{tr} A}             \\
    \code{\cs{rank} A}                        & $\rank A$                    & \code{\cs{operatorname}\Marg{rank} A}           \\
    \code{\cs{trank} A}                       & $\trank A$                   & \code{\cs{operatorname}\Marg{t-rank} A}         \\
    \code{\cs{Det} A}                         & $\Det A$                     & \code{\cs{operatorname}\Marg{Det} A}            \\
    \code{\cs{Pf} A}                          & $\Pf A$                      & \code{\cs{operatorname}\Marg{Pf} A}             \\
    \code{\cs{perm} A}                        & $\perm A$                    & \code{\cs{operatorname}\Marg{perm} A}           \\
    \code{\cs{Hf} A}                          & $\Hf A$                      & \code{\cs{operatorname}\Marg{Hf} A}             \\
    \cs{diag}\Darg{a\_1,\cs{dotsc},a\_n}      & $\diag(a_1,\dotsc,a_n)$      & \begin{tabular}[l]{@{}l@{}}\code{\cs{operatorname}\Marg{diag}}\\\code{ (a\_1,\cs{dotsc},a\_n)}\end{tabular}                      \\
    \cs{blockdiag}\Darg{A\_1,\cs{dotsc},A\_n} & $\blockdiag(A_1,\dotsc,A_n)$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{operatorname}\Marg{block-diag}}\\\code{ (A\_1,\cs{dotsc},A\_n)}\end{tabular}                      \\
    \cs{vectorize}\Darg{A}                    & $\vectorize(A)$              & \code{\cs{operatorname}\Marg{vectorize}(A)}     \\
    \cs{Row}\Darg{A}                          & $\Row(A)$                    & \code{\cs{operatorname}\Marg{Row}(A)}           \\
    \cs{Col}\Darg{A}                          & $\Col(A)$                    & \code{\cs{operatorname}\Marg{Col}(A)}           \\
    \cs{trsp}\Marg{A}                         & $\trsp{A}$                   & \code{A\string^\cs{top}}                        \\
    \cs{adjo}\Marg{A}                         & $\adjo{A}$                   & \code{A\string^*}                               \\
    \cs{onevec}                               & $\onevec$                    & \code{\cs{mathds}\Marg{1}}                      \\
    \cs{norm}\Marg{x}                         & $\norm{x}$                   & \code{\cs{left}\cs{}|x\cs{right}\cs{}|} \\
    \cs{inpr}\Marg{x}\Marg{y}                 & $\inpr{x}{y}$                & \begin{tabular}[l]{@{}l@{}}\code{\cs{left}\cs{langle}\{x\},\{y\}}\\\code{ \cs{right}\cs{rangle}}\end{tabular}                      \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Analysis}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}  & Output         & \multicolumn{1}{c}{\LaTeX\ (almost) equivalent}                           \\\midrule
    \cs{intoo}\Marg{a,b}       & $\intoo{a,b}$  & \code{\cs{left}\lparen a,b\cs{right}\rparen}                              \\
    \cs{intoc}\Marg{a,b}       & $\intoc{a,b}$  & \code{\cs{left}\lparen a,b\cs{right}\rbrack}                              \\
    \cs{intco}\Marg{a,b}       & $\intco{a,b}$  & \code{\cs{left}\lbrack a,b\cs{right}\rparen}                              \\
    \cs{intcc}\Marg{a,b}       & $\intcc{a,b}$  & \code{\cs{left}\lbrack a,b\cs{right}\rbrack}                              \\
    \cs{e}                     & $\e$           & \code{\cs{mathrm}\Marg{e}}                                                \\
    \cs{d}                     & $\d$           & \code{\cs{mathrm}\Marg{d}}                                                \\
    \cs{dif}\Marg{f}\Marg{x}   & $\dif{f}{x}$   & \code{\cs{frac}\Marg{\cs{mathrm}\Marg{d} f}\Marg{\cs{mathrm}\Marg{d} x}}  \\
    \cs{pdif}\Marg{f}\Marg{x}  & $\pdif{f}{x}$  & \code{\cs{frac}\Marg{\cs{partial} f}\Marg{\cs{partial} x}}                \\
    \cs{ddif}\Marg{f}\Marg{x}  & $\ddif{f}{x}$  & \code{\cs{dfrac}\Marg{\cs{mathrm}\Marg{d} f}\Marg{\cs{mathrm}\Marg{d} x}} \\
    \cs{dpdif}\Marg{f}\Marg{x} & $\dpdif{f}{x}$ & \code{\cs{dfrac}\Marg{\cs{partial} f}\Marg{\cs{partial} x}}               \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Complex Analysis}
\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                      & Output            & \multicolumn{1}{c}{\LaTeX\ equivalent}            \\\midrule
    \cs{i}                                         & $\i$              & \code{\cs{mathrm}\Marg{i}}                        \\
    \code{\cs{Re} z}                               & $\Re z$           & \code{\cs{operatorname}\Marg{Re} z}               \\
    \code{\cs{Im} z}                               & $\Im z$           & \code{\cs{operatorname}\Marg{Im} z}               \\
    \code{\cs{Arg} z}                              & $\Arg z$          & \code{\cs{operatorname}\Marg{Arg} z}              \\
    \code{\cs{Log} z}                              & $\Log z$          & \code{\cs{operatorname}\Marg{Log} z}              \\
    \code{\cs{Sin} z}                              & $\Sin z$          & \code{\cs{operatorname}\Marg{Sin} z}              \\
    \code{\cs{Cos} z}                              & $\Cos z$          & \code{\cs{operatorname}\Marg{Cos} z}              \\
    \code{\cs{Tan} z}                              & $\Tan z$          & \code{\cs{operatorname}\Marg{Tan} z}              \\
    \code{\cs{Res}\_\string{z=0\string} f\Darg{z}} & $\Res_{z=0} f(z)$ & \code{\cs{operatorname*}\Marg{Res}\_\{z=0\} f(z)} \\
    \bottomrule
  \end{tabular}
\end{center}

\subsection{Computer Science, Optimization}
Spaces after ``arg'' in \cs{argmin} and \cs{argmax} are omitted by passing the \option{noargminspace} option.

\begin{center}
  \begin{tabular}{lcl} \toprule
    \multicolumn{1}{c}{Input}                                 & Output                   & \multicolumn{1}{c}{\LaTeX\ equivalent} \\\midrule
    \code{\cs{argmin}\_\string{x \cs{in} S\string} f\Darg{x}} & $\argmin_{x \in S} f(x)$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{operatorname*}\Marg{arg\string~min}}\\\code{ \_\{x \cs{in} S\} f(x)}\end{tabular}             \\
    \code{\cs{argmax}\_\string{x \cs{in} S\string} f\Darg{x}} & $\argmax_{x \in S} f(x)$ & \begin{tabular}[l]{@{}l@{}}\code{\cs{operatorname*}\Marg{arg\string~max}}\\\code{ \_\{x \cs{in} S\} f(x)}\end{tabular}             \\
    \cs{Order}\Darg{n}                                        & $\Order(n)$              & \code{\cs{mathrm}\Marg{O}(n)}          \\
    \cs{order}\Darg{n}                                        & $\order(n)$              & \code{\cs{mathrm}\Marg{o}(n)}          \\
    \cs{poly}\Darg{n}                                         & $\poly(n)$               & \code{\cs{operatorname}\Marg{poly}(n)}       \\
    \cs{polylog}\Darg{n}                                      & $\polylog(n)$            & \code{\cs{operatorname}\Marg{polylog}(n)}    \\
    \bottomrule
  \end{tabular}
\end{center}

\section{The \pkg*{okithm} Package}
\subsection{Theorems}

If the language is set to Japanese like by \cs{usepackage}\Oarg{\keyis-{main}{japanese}}\Marg{\pkg{babel}}, \pkg{okithm} will translate all the environment titles (Theorem, Definition, etc.) into Japanese.
You can disable theorems by giving the option \option{notheorem} to \pkg{okicmd}.

\begin{cnltxexample}
  \begin{theorem}[Awesome theorem]
    The square root $\sqrt{2}$ of two is irrational.
  \end{theorem}

  \begin{definition}[Coprime]
    Integers $a$ and $b$ are said to be \emph{coprime} if their greatest common divisor is one.
  \end{definition}

  \begin{lemma}
    If $a$ and $b$ are coprime, so are $a^2$ and $b^2$.
  \end{lemma}

  \begin{proposition}
    If $\sqrt{2} = a/b$, then $a^2 = 2b^2$.
  \end{proposition}

  \begin{corollary}
    If $\sqrt{2} = a/b$ with $a$ and $b$ being coprime, then $a$ is even.
  \end{corollary}

  \begin{example}
    If $a = 2$ and $b = 1$, then $a$ is even but $\sqrt{2} \ne a/b$.
  \end{example}

  \begin{remark}
    Note that $a$ and $b$ must be integers.
  \end{remark}

  \begin{proof}[of Awesome theorem]
    Suppose to the contrary that $\sqrt{2} = a/b$ with coprime $a$ and $b$.
    Then both $a$ and $b$ are even, which contradicts the assumption.
  \end{proof}
\end{cnltxexample}

\subsection{Algorithms}

You can disable algorithms by setting the option \option{noalgorithm}.

\begin{cnltxexample}
  \begin{algorithmic}[1]
    \Input{$n \in \setN$}
    \Output{$n(n+1)/2$}
    \State{$s \gets 0$}
    \ForTo{$i = 1$}{$n$}
    \State{$s \gets s + i$}
    \EndFor
    \State{\Return $s$}
  \end{algorithmic}
\end{cnltxexample}

\subsection{Optimization Problems}

You can change \texttt{minimize}, \texttt{maximize} and \texttt{subject to} into \texttt{min}, \texttt{max} and \texttt{s.t.}, respectively, by setting the option \keyis-{optstyle}{short}.

\begin{comment}
\begin{cnltxexample}
  \Minimize[name={(P)}]{
    \sum_{\condit{x \in S}[x^2 = 1]} w (x) + \sum_{i=1}^n (p_i + q_i)
  }{
    S \subseteq V, \\
    p_i \ge 0 & (i = 1, \ldots, n), \\
    q_i \ge 0 & (i = 1, \ldots, n)
  }
\end{cnltxexample}
\end{comment}

\end{document}


\input{../common/header.tex}
\subtitle{Start programming in Python}
\date{2020-04-02}
\input{../common/title.tex}

\begin{frame}
	\tableofcontents
\end{frame}

\section{Organizational matters}
\begin{frame}[fragile]{Organizational matters}
	\begin{itemize}
		\item Please participate in writing today's lecture notes:
            \href{https://yourpart.eu/p/lecture-scientific-computing03-notes}{https://yourpart.eu/p/lecture-scientific-computing03-notes}
        \item Glossary:\\
            \href{https://yourpart.eu/p/lecture-scientific-computing-glossary}{https://yourpart.eu/p/lecture-scientific-computing-glossary}
        \item Answers for Git questions from first homework:\\
            \href{https://yourpart.eu/p/lecture-scientific-computing}{https://yourpart.eu/p/lecture-scientific-computing}
	\end{itemize}
\end{frame}

\begin{frame}[fragile]{Comments on the last homework}
	\begin{itemize}
        \item Groups after last homework submission, today 11:30:
	        \begin{itemize}
                \item adob360 (4 members)
                \item aleks-cortijo  (4 members, but one without name)
                \item barbarakalous (5 members)
                \item Bokubst (3 members)
                \item fogerl (5 members)
	        \end{itemize}\pause
        \item Hint on placeholders:\\
	        If you see text enclosed in <> on our slides or in the notebook such as
	\begin{verbatim}
	<something here>
	\end{verbatim}
	it means that \verb|<something here>| should be replaced by some input from your side, removing
    the <> (hopefully obvious from the context). Anything else can just be copied.\pause
        \item Many Git accidents, in some repositories there is still personal data published. If
            you want, follow the
            \href{https://anchor.host/removing-sensitive-data-from-git-repos/}{instructions} for
            removing them (involves advanced Git tasks) or delete the fork on Github, then fork
            the homework repository again and commit the *.txt file with your names again (can be
            in one commit by one person).
	\end{itemize}
\end{frame}

\section{Leftover from last week}

\begin{frame}[fragile]{Using Jupyter Notebooks}

	If you want to use conda environments in your notebooks, do the following:
	\begin{itemize}
		\item Install \textit{ipykernel} in your environment

		\begin{verbatim}
		conda activate <conda-environment>
		conda install ipykernel
		conda deactivate
		\end{verbatim}
		\item Additionally, install \textit{nb\_conda\_kernels} in \textit{base} if you run your jupyter notebook from base:
		\begin{verbatim}
		conda activate base    # could be also some other environment
		conda install nb_conda_kernels
		\end{verbatim}
	\end{itemize}
\end{frame}

\section{Python introduction}

\begin{frame}[fragile]{Disclaimer}
	\begin{center}
		\includegraphics[height=0.6\textheight]{covid-19-expert.png}
	\end{center}

	\pause
	\textbf{Disclaimer:} Models used in this lecture are highly simplified and supposed to serve as examples
	to study Python. Don't use models as prediction. If you do your own data analysis on important
	topics, compare it with other published studies.

	If you are interested in real expertise, check e.g. the \href{https://www.ndr.de/nachrichten/info/Corona-Podcast-Alle-Folgen-in-der-Uebersicht,podcastcoronavirus134.html}{Drosten Podcast}

	{\tiny Source: \href{https://twitter.com/amrith/status/1242481942026530817}{https://twitter.com/amrith/status/1242481942026530817}}
\end{frame}

\begin{frame}[fragile]{Python introduction}
    See Jupyter notebook:\\
    \href{https://github.com/inwe-boku/lecture-scientific-computing/blob/master/lecture03-python-introduction/lecture03.ipynb}{lecture03.ipynb}
\end{frame}

\section{Homework assignment}

\begin{frame}[fragile]{Homework assignment}
	\begin{itemize}
		\item Fetch the latest changes from the upstream repository, to get the homework Notebook:
            {\scriptsize
            \begin{verbatim}
cd path/to/homework-scientific-computing
git pull --no-edit upstream master
git push\end{verbatim}
            }
        \item Start Jupyter and solve the exercises in the notebook:
            \href{https://github.com/inwe-boku/homework-scientific-computing/blob/master/homework03-python-introduction/homework03.ipynb}{homework03.ipynb}.
        \item Commit the notebook file and push it to your fork.
	\end{itemize}

    \bigskip
    Due on 29th of April, 17:00.

    \bigskip
    To avoid merge conflicts, you can either commit a copy of the notebook and add your Github name
    to the filename or solve the exercises together with your group members and \verb|git pull|
    before starting to work on the notebook and \verb|git push| before the next group member starts
    working on it.
\end{frame}

\end{document}


\subsection{
\label{compilerprac}
About Imp (in the {\tt Compiler} directory)}

The final group of exercises involve testing, tracing, fixing, specifying
and extending the Imp interpreter and compiler.

\paragraph{\nextex}
Recall the \QuickCheck{} congruence property
that should hold for the Imp compiler and the interpreter.
The version of the Imp system in the {\tt Compiler} directory
has been deliberately broken, so it does not satisfy this
property.  Indeed, it hardly works at all: try running it
on {\tt gcd.in}.
Use \QuickCheck{} and \Hat{} to find the two bugs we have introduced.
Fix them!
\hfill$\Box$

\paragraph{\nextex}
There are some functions in which we can apparently introduce as
many bugs as we want; the congruence property will still hold!
Which are these functions?
{\bf Hint:} Which functions are used both by the compiler and the
interpreter?
\hfill$\Box$

\paragraph{\nextex}
Random testing works best if it is applied at a fine grain! Therefore,
formulate a property that is only going to test
compilation and interpretation of
{\em expressions}.
{\bf Hint:} You can reuse the congruence property of programs, but generate
only programs that print a single expression (which cannot contain variables).
Is non-termination still an issue?
% Non-termination is not an issue as a {\tt print} statement always
% terminates.
\hfill$\Box$

\paragraph{\nextex}
Now investigate the test coverage of \QuickCheck{} for
your property. Insert a test data monitor that checks what kind of traces are
generated by the programs during test, and check the distribution.
What do you think of the distribution of
test data? Most generated expressions are type
incorrect! Adapt your property by using the implication operator {\tt ==>} to
discard this rather large amount of useless test data.

{\bf Note:} To show that without this fix, your property does not have good test
coverage, introduce the following bug: flip the order of the arguments of
binary operators in the expression compiler. Can your old property find the
bug? Can your new one?
\hfill$\Box$

\paragraph{\nextex}
The original congruence property for programs
has a similar problem; the whole program crashes if the condition in an {\tt
if} or {\tt while} statement is type incorrect, and this happens a lot during
testing. Adapt the program congruence property to overcome this problem.
\hfill$\Box$

\paragraph{\nextex}
Suppose the Imp language is extended by generalising assignments to
multiple assignments.  Instead of just one variable name on the left of
each {\tt :=} there are one or more, separated by commas, and on the right
an equal number of expressions, also separated by commas.
A multiple assignment is executed by first evaluating all the right-hand
expressions and then storing the results in corresponding left-hand
variables in left-to-right order.
Here is an example program ({\tt power.in}) which raises {\tt 3} to the
power {\tt 6}:
\begin{verbatim}
a, n, x := 3, 6, 1;
while 0 < n do
  if (n\2) = 1 then n, x := n-1, x*a else skip fi;
  a, n := a*a, n/2
od;
print x
\end{verbatim}
By making changes in the following places,
revise the Imp interpreter and compiler to work with
multiple assignments.
\begin{center}
\renewcommand{\arraystretch}{2.0}
\begin{tabular}{ll}
{\tt Syntax}   &
  \parbox[t]{3.5in}{Change the {\tt :=} construction in the {\tt Command} type.} \\
{\tt Parser}   &
  \parbox[t]{3.5in}{Change the final alternative in {\tt nonSeqCommand}. \\
     {\bf Hint:} define
     {\tt listOf :: Parser a -> Parser [a]}. } \\
{\tt Interpreter} &
  \parbox[t]{3.5in}{Change the {\tt :=} equation in
                    the definition of {\tt run}. \\
     {\bf Hint:} generalise the definition of {\tt update}.} \\
{\tt StackMap} &
  \parbox[t]{3.5in}{Change the {\tt :=} equation in
                    the definition of {\tt comVars}.} \\
{\tt Compiler} &
  \parbox[t]{3.5in}{Change the {\tt :=} equation in the
                    definition of {\tt compObey}. \\
          {\bf Hint:} none --- we hope you get it wrong!}
\end{tabular}
\renewcommand{\arraystretch}{1.0}
\end{center}
Test your extension first on {\tt power.in}, using \Hat{} to
investigate any faults.
% When you have an interpreter and compiler that work for this example
% program do you suppose it will work for all parallel-assignment programs?
Revise the program generator in the {\tt Properties.hs} so that the congruence
property is asserted over the extended language.  Apply \QuickCheck{} and
\Hat{} as necessary to achieve a solution that passes an appropriate range
of tests.
\hfill$\Box$

\paragraph{\nextex}
Compare the assignments:
\begin{alltt}
x, y := e1, e2         and          y, x := e2, e1
\end{alltt}
Under what conditions do these two assignments mean the same thing?
Formulate this conditional equivalence
as a \QuickCheck{} property and check that the property holds.
\hfill$\Box$


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{listings}
\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

% \lstset{
%  columns=fixed,
%  numbers=left,                                        % 在左侧显示行号
%  numberstyle=\small\color{gray},                       % 设定行号格式
%  frame=none,                                          % 不显示背景边框
%  backgroundcolor=\color[RGB]{245,245,244},            % 设定背景颜色
%  keywordstyle=\color[RGB]{40,40,255},                 % 设定关键字颜色
%  numberstyle=\footnotesize\color{darkgray},
%  commentstyle=\it\color[RGB]{0,96,96},                % 设置代码注释的格式
%  stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 设置字符串格式
%  showstringspaces=false,                              % 不显示字符串中的空格
%  language=c++,                                        % 设置语言
% }

% \usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\lstset{
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{mygreen},    % comment style
  deletekeywords={...},            % if you want to delete keywords from the given language
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  frame=single,                       % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{blue},       % keyword style
  language=Octave,                 % the language of the code
  morekeywords={*,...},            % if you want to add more keywords to the set
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{mymauve},     % string literal style
  tabsize=2,                       % sets default tabsize to 2 spaces
  title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for a
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Homework\ \#2}
\newcommand{\hmwkDueDate}{Jan. 31, 2019}
\newcommand{\hmwkClass}{CPSC8400}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Professor Dr.Brian Dean}
\newcommand{\hmwkAuthorName}{\textbf{Guoze Tang}}

%
% Title Page
%

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate\ at 12:25pm}\\
    \vspace{0.1in}\large{\textit{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\pagebreak

\begin{homeworkProblem}
\textbf{2-1. Property Testing.} Please do problem 15 (chapter 2). As a hint, the bounds on $(1 + x)^y$ on page 47 may end up being useful.

\textbf{Analyze}

This algorithm always gives us the correct output if the input array is sorted. So, we only need to think about the second situation (The array is "far" from sorted.): The input array is unsorted, but we give an incorrect answer. We only make the mistake when we choose a consistent element on each of the longest increasing sub-sequence, then we will get the incorrect output. And the algorithm runs binary searches to test consistency of $O(\frac{1}{\varepsilon}\log n)$, and its total running time is $O(\frac{1}{\varepsilon}\log^2n)$.  There are some conditions in this problem.

\textbf{Conditions}

\begin{enumerate}
    \item The longest increasing sub-sequence length $< (1-\varepsilon)n$
    \item The probability of randomly choosing one of the increasing sub-sequence is $ 1 - \varepsilon$
    \item If we make the mistake when we choose a consistent element is $O(\frac{1}{\varepsilon}\log n)$
\end{enumerate}
Base on these definitions,  we use $P(failure)$ as the probability of making a mistake. Then we can get the followed formula
\[
    \begin{split}
        P(failure) &\leq (1-\varepsilon)^{k}
    \end{split}
\]

From the page 47 of the textbook draft, we can use the result about $(1 + x)^y \leq e^{xy} $ to deal with the above result. We can change this formula to $(1 - x)^y \leq e^{-xy}$. And, we define the $k = \frac{m}{\varepsilon}\ln (n)$. Then use these definitions, we can get the followed formula.
\[
    \begin{split}
        P(failure) &\leq (1-\varepsilon)^{\frac{m}{\varepsilon}\ln (n)}
        \\
        &\leq e^{-\varepsilon * \frac{m}{\varepsilon}\ln (n)}
        \\
        &= e^{-m ln (n)} \\
        &= \frac{1}{n^m}
    \end{split}
\]

Now, we can change the $m$ to make the $ P(failure)$ is very low. As a result, we can get a high probability of success.

\end{homeworkProblem}

\pagebreak

\pagebreak

\begin{homeworkProblem}
% \textbf{2-2. A Priority Queue Built from Sorted Arrays}. Please do problem 93 (chapter 5)

\textbf{Requirements}
    \begin{enumerate}
        \item Prove both $insert$ and $remove$-$min$ run in only $O(\log n)$ amortized time.
        \item Is it possible to implement the remaining priority queue operations $decrease$-$key$, $increase$-$key$, and $delete$ in $O(\log n)$ amortized time?
    \end{enumerate}

\textbf{Definition}
    \begin{enumerate}
        \item Array $A_1$ and $A_2$ are two arrays in all the arrays which need to merge.
        \item $length(A_1)$ is the length for $A_1$ and $length(A_2)$ is the length for $A_2$. $length(A_1)\leq length(A_2)$, but $2*length(A_1) \geq length(A_2)$;
        \item $C_i$ is the number of the arrays which are longer than the array which contain the this element i.
        \item The number of all the arrays $\leq \log_2n$, n is the number of elements in this structure.
    \end{enumerate}

\textbf{Accounting Method:} When we want to insert a new element $i$, each inserts operation create a single array, this costs us \$1. In addition, we have to store another \$$3C_i \leq 3\log_2 n = \log n * \log_2n = O(\log n)$ in the bank. This saving will be used for merging arrays for this element in the future. For example, when we merge two arrays $A_1$ and $A_2$ and $length(A_1)\leq length(A_2)$. For each elements in the $A_1$, we need to pay with the \$3 associated with each element in the array $A_1$. So this merge cost is \$$3* length(A_1)$. We use this cost to pay for the merging cost $length(A_1) + length(A_2) \leq 3*length(A_1)$. And the total insert operation cost is  \$$3* length(A_1) + 1$. The element $i$ in the $A_1$ or $A_2$ have a new $C_i - 1$ which is less than $C_i$. As a result, when we insert an element, we need to spend \$1 for new this single array, and add extract \$$3(\log_2 n)$ credit for it. So, the \textit{insert} operation run in only $O(\log n)$ amortized time.
\\

\textbf{For the \textit{remove-min} operation}, in $O(\log n)$ time to find the root \textit{x} with the minimum value. After we delete this element, we use the surplus credit for this element to pay for the merging cost.
We didn't need to do anything because the saving for the element $i$ which when wants to delete has credit \$$3C_i$ which is enough for remove. This entire process took only $O(\log n)$ time.
\\

To implement the remaining priority queue operations $decrease$-$key$, $increase$-$key$, and \textit{delete} operation. For all of them, we need spent $(O(\log n))$ time to find them firstly. \textbf{For the \textit{decrease-key(A, x, k)}}, since the length for any array is $O(log n)$, this takes a most  $O(log n)$ because we use this element new value $k$ to compare with its parent and, if it's smaller, it is swapped upwards. \textbf{For the \textit{increase-key(A, x, k)}}, this process is similar with the \textit{decrease-key(A, x, k)}. We use this element new value $k$ to compare with its children and, if it's bigger, it is swapped downwards. As a result, both \textit{decrease-key} and \textit{increase-key} run in only $O(\log n)$ amortized time. \textbf{For the \textit{delete} operation}, we can do the lazy deletion in the algorithm. When an element is deleted, we just need to mark it as $deleted$ but we didn't really delete it at that time. We clean it when it moves to the front of an arrays and when some one call the \textit{remove-min} function. So, we need to add $O(\log n)$ credit to that element when we marked $deleted$ flag on that element. We spend this cost for the $remove\-min$ operation. \\

So, the entire process for \textit{insert}, \textit{remove-min}, \textit{decrease-key}, \textit{increase-key} and \textit{delete} took only $O(\log n)$ amortized time.

\end{homeworkProblem}

\pagebreak
\textbf{References}

\begin{enumerate}
    \item http://moais.imag.fr/membres/marc.tchiboukdjian/mosig/amortized.pdf
    \item http://home.cse.ust.hk/~golin/COMP572/Notes/Heaps.pdf
\end{enumerate}

\end{document}


\documentclass[12pt]{article}
\usepackage{graphics}
\begin{document}

\section*{NYU Physics 1---In-class Exam 3}

\vfill

\paragraph{Name:} ~

\paragraph{email:} ~

\vfill

This exam consists of two problems.  Write only in this booklet.  Be
sure to show your work.

\vfill ~

\clearpage

\section*{Problem 1}

\noindent~\hfill\includegraphics{../mp/rollinghill.eps}\hfill~

A thin hoop of mass $M$ and radius $R$ (with moment of inertia
$I=M\,R^2$) rolls without slipping along the hilly landscape shown.
If it was released from rest at point A, what is its speed $v$ at
point B?  Give your answer in terms of $h$, $g$, $M$, and $R$.  Use
conservation of energy, and recall that the kinetic energy $K$ of a
translating, rotating object is $K=(1/2)\,M\,v^2+(1/2)\,I\,\omega^2$.
Try to give your answer in terms of just $M$, $R$, $h$, and $g$.

\clearpage

\section*{Problem 2}

If you assume that air resistance comes from elastic collisions with
stationary air molecules (not a crazy assumption), then it turns out
that the air resistance force $F_\mathrm{air}$ acting on a moving car
can be computed simply from the density $\rho$ (mass per volume) of
air, the speed $v$ of the car, and the cross-sectional area $A$ of the
car.  Use either physical arguments or dimensional arguments to
estimate the air resistance force (in Newtons) acting on a typical car
driving at $55~\mathrm{mi\,hr^{-1}}$.  You will need to tell me what
you are assuming for the density of air $\rho$ and the cross-sectional
area $A$ of the car.  Reasonable estimates are preferred to
unreasonable ones!

\clearpage

[This page intentionally left blank for calculations or other work.]

\end{document}