\graphicspath{{Pics/combi/algo/}}

\newpage\section{Algorithmic}

\faka
\begin{myitemize}{}
\item \href{https://people.bath.ac.uk/masgcs/algorithms.pdf}{Handout by Cody Johnson}
\end{myitemize}
\faka

\subsection{Data Structures}

\dstruct{http://opendatastructures.org/versions/edition-0.1d/ods-java/node52.html}{Binary
    Heap\label{problem:binary_heap}}{Segment tree where, node \texttt{n} has
    children \texttt{2n+1, 2n+2}.
    %\fig{.8}{BinaryHeap}{Binary Heap}
}
\figdf{.5}{asfoiha}{aoshd}

\begin{enumerate}
    \iref{problem:binary_heap_1}{timus 1862,}{Sum of operations}{}
\end{enumerate}

\dstruct{http://www.shafaetsplanet.com/?p=763}{Disjoint Set}{This data
structure keeps track of connectivity by assigning a representative to a
connected subset. And for any two nodes, \texttt{u, v} they are connected iff
they have the same representative.}

\subsection{Minimal Spanning Tree}

\den{Minimum Spanning Tree}{A minimum spanning tree or minimum weight spanning
    tree is a subset of the edges of a connected, edge-weighted (un)directed
    graph that connects all the vertices's together, without any cycles and
    with the minimum possible total edge weight.
    \fig{.4}{minimum_spanning_tree}{Minimal Spanning Tree}
}

\lem{MST Cut}{For any \hrf{definition:cut_graph_theory}{cut} of the graph, the
lightest edge in that cut-set is in evey MST of the graph.}

\algorithm{https://en.wikipedia.org/wiki/Kruskal's_algorithm}{Kruskal's
Algorithm}{Kruskal's algorithm is a `minimum-spanning-tree algorithm' which
finds an edge of the least possible weight that connects any two trees in the
forest. It is a greedy algorithm in graph theory as it finds a minimum
spanning tree for a connected weighted graph adding increasing cost arcs at
each step.}

\solu{To optimize this algorithm, Disjoint Set DS is used.}

\algorithm{https://en.wikipedia.org/wiki/Prim's_algorithm}{Prim's
Algorithm}{Greedily build the tree by adding edges one by one. At one step we
add the minimal cost edge that connects the tree to the vertices's that are
not in the tree.}

\subsection{Shortest Path Problem}

\den{Shortest Path Problem}{Finding the shortest path between two nodes in a
weighted or unweighted graph.}

\algorithm{https://en.wikipedia.org/wiki/Breadth-first_search}{Breadth-First
Search}{This algo runs from a node and ``levelizes'' the other nodes.}

\algorithm{https://en.wikipedia.org/wiki/Dijkstra's_algorithm}{Dijkstra's
Algorithm}{It picks the unvisited vertex with the lowest distance, calculates
the distance through it to each unvisited neighbor, and updates the neighbor's
distance if smaller.}

\subsection{Other CP Tricks}

\theo{}{Swap Sort}{In any swap sorting algorithm, the number of swaps needed
has the same parity.}\label{theorem:swap_sort_steps_parity}

\algorithm{https://wcipeg.com/wiki/Convex_hull_trick}{Convex Hull Trick}{Given
a lot of lines on the plane, and a lot of queries each asking for the smallest
value for $ y $ among the lines for a given $ x $, the optimal strategy is to
sort the lines according to their slopes, and adding them to a stack, checking
if they are relevant to the `minimal' convex hull of those lines.}

\fig{.5}{Convex_hull_trick1}{Convex Hull Trick}

\subsection{Fast Fourier Transform}

Let $ A(x) = a_0 + a_1x + \dots a_{n-1}x^{n-1} $ be a polinomial and let $
\w^n = 1 $ be a $ n $th root of unity. We use \textbf{FFT} to multiply two
polynomials in $ n\log n $ time.

\den{DFT Matrix}{Let $\w$ be a $n$th root of unity. The \textbf{DFT Matrix} is
    a $ n\times n $ matrix given by:
    \[W = \begin{pmatrix}
        1 & 1 & 1 & \dots & 1\\
        1 & \w & \w^2 & \dots & \w^{n-1}\\
        1 & \w^2 & \w^4 & \dots & \w^{2(n-1)}\\
        \vdots & \vdots & \vdots & \vdots & \vdots\\
        1 & \w^{n-1} & \w^{2(n-1)} & \dots & \w^{(n-1)^2}\\
    \end{pmatrix}\]
    And its inverse is given by:
    \[W^{-1} = \frac{1}{n}
        \begin{pmatrix}
            1 & 1 & 1 & \dots & 1\\
            1 & \w^{-1} & \w^{-2} & \dots & \w^{-(n-1)}\\
            1 & \w^{-2} & \w^{-4} & \dots & \w^{-2(n-1)}\\
            \vdots & \vdots & \vdots & \vdots & \vdots\\
            1 & \w^{-(n-1)} & \w^{-2(n-1)} & \dots & \w^{-(n-1)^2}\\
        \end{pmatrix}\]
    }

\den{Discrete Fourier Transform}{The \textbf{Discrete Fourier transform} (DFT)
    of the polynomial $A(x)$ (or equivalently the vector of coefficients
    $\left(a_{0}, a_{1}, \ldots, a_{n-1}\right)$ is defined as the values of
    the polynomial at the points $x=\w_n^k,$ i.e. it is the vector:
    \begin{align*}
        \operatorname{DFT}\left(a_{0}, a_{1}, \ldots, a_{n-1}\right)
        &=\left(y_{0}, y_{1}, \ldots,
        y_{n-1}\right)=\left(A\left(\w_{n}^{0}\right),
        A\left(\w_{n}^{1}\right), \ldots, A\left(\w_{n}^{n-1}\right)\right)
    \end{align*}

    In other words, we can write $ \operatorname{DFT}(A) $ as:

    \[\operatorname{DFT}(A)=
        \begin{pmatrix}
            y_0\\
            y_1\\
            y_2\\
            \vdots\\
            y_n
        \end{pmatrix} =
        \begin{pmatrix}
            1 & 1 & 1 & \dots & 1\\
            1 & \w & \w^2 & \dots & \w^{n-1}\\
            1 & \w^2 & \w^4 & \dots & \w^{2(n-1)}\\
            \vdots & \vdots & \vdots & \vdots & \vdots\\
            1 & \w^{n-1} & \w^{2(n-1)} & \dots & \w^{(n-1)^2}\\
        \end{pmatrix}
        \begin{pmatrix}
            a_0\\
            a_1\\
            a_2\\
            \vdots\\
            a_n
        \end{pmatrix}\]
    }

\den{Inverse Discrete Fourier Transform}{The \textbf{Inverse Discrete Fourier Transform}
    of values of the polynomial $\left(y_{0}, y_{1}, \ldots,
        y_{n-1}\right)$ are the coefficients of the polynomial $\left(a_{0}, a_{1},
    \ldots, a_{n-1}\right)$
    \[\text { InverseDFT }\left(y_{0}, y_{1}, \ldots, y_{n-1}\right)=\left(a_{0},
    a_{1}, \ldots, a_{n-1}\right)\]
}

Thus, if a direct DFT computes the values of the polynomial at the points at
the $n$ -th roots, the inverse DFT can restore the coefficients of the
polynomial using those values.

\begin{algo}[Multiplication of two polynomials]
    Say we have $A, B$ two polynomials, and we want to compute $(A\cdot
    B)(x)$. Then we first component-wise multiply $ \operatorname{DFT}(A) $
    and $ \operatorname{DFT}(B) $, and then retrieve the coefficients of $
    A\cdot B $ by applying the Inverse DFT.
\end{algo}

\begin{algo}[Fast Fourier Transform]
    We want to compute the DFT$ (A) $ in $ n\log n $ time. Suppose $ n $ is a
    power of $ 2 $, $ \w^n = 1 $, and $ A(x) = a_{0} x^{0}+a_{1}
    x^{1}+\cdots+a_{n-1} x^{n-1} $. We use divide and conquer by considering:
    \begin{align*}
        A_{0}(x)&=a_{0} x^{0}+a_{2} x^{1}+\cdots+a_{n-2} x^{\frac{n}{2}-1} \\
        A_{1}(x)&=a_{1} x^{0}+a_{3} x^{1}+\cdots+a_{n-1} x^{\frac{n}{2}-1}\\[.5em]
        \and A(x) &= A_0(x^2) + xA_1(x^2)
    \end{align*}

    After we have computed $ \text{DFT}(A_0) = (y^0_i)^{\frac{n}{2} - 1}_{i=0}
    $ and $ \text{DFT}(A_0) = (y^1_i)^{\frac{n}{2} - 1}_{i=0} $, we can
    compute $ (y_i)^{n-1}_{i=0} $ by:
    \[y_k =
        \left\{\begin{array}{ll}
                y^0_k + \w^ky^1_k, &\text{ for } k < \dfrac{n}{2}\\[1em]
                y^0_k - \w^ky^1_k, &\text{ for } k \ge \dfrac{n}{2}
        \end{array}\right.\]
\end{algo}

\begin{algo}[Inverse FFT]
    Since by definition we know $ \operatorname{DFT}(A) = W\times A $, we
    have:
\end{algo}

\newpage
\subsection{Problems}

\prob{https://artofproblemsolving.com/community/c6h1623516p10168885}{Iran TST
    2018 P1}{E}{Let $A_1, A_2, ... , A_k$ be the subsets of
    $\left\{1,2,3,...,n\right\}$ such that for all $1\leq i,j\leq k$:$A_i\cap
    A_j \neq \varnothing$. Prove that there are $n$ distinct positive integers
$x_1,x_2,...,x_n$ such that for each $1\leq j\leq k$: \[lcm_{i \in
A_j}\left\{x_i\right\}>lcm_{i \notin A_j}\left\{x_i\right\}\]}

\solu{Apply induction on either $ k $ or $ n $.}

\prob{https://artofproblemsolving.com/community/c6h1480687p8639246}{ISL 2016
C1}{TE}{The leader of an IMO team chooses positive integers $ n $ and $ k $
with $ n > k $ , and announces them to the deputy leader and a contestant. The
leader then secretly tells the deputy leader an $ n $ -digit binary string,
and the deputy leader writes down all $ n $ -digit binary strings which differ
from the leader’s in exactly $ k $ positions. (For example, if $ n = 3 $ and $
k = 1 $ , and if the leader chooses $ 101 $ , the deputy leader would write
down $ 001, 111 $ and $ 100 $.) The contestant is allowed to look at the
strings written by the deputy leader and guess the leader’s string. What is
the minimum number of guesses (in terms of $ n $ and $ k $ ) needed to
guarantee the correct answer?}\label{problem:constructive_algo_10}

\solu{Small cases check.}

\prob{https://artofproblemsolving.com/community/c6h44479p281572}{ISL 2005
C2}{E}{Let $a_1,a_2,\ldots$ be a sequence of integers with infinitely many
positive and negative terms. Suppose that for every positive integer $n$ the
numbers $a_1,a_2,\ldots,a_n$ leave $n$ different remainders upon division by
$n$. Prove that every integer occurs exactly once in the sequence
$a_1,a_2,\ldots$.}\label{problem:constructive_algo_22}

\solu{Constructing for the beginning.}

\prob{http://ioi2017.org/tasks/practice/coins.pdf}{IOI Practice 2017}{M}{ $ C
    $ plays a game with $ A $ and $ B $. There's a room with a table. First $
    C $ goes in the room and puts $ 64 $ coins on the table in a row. Each
    coin is facing either heads or tails. Coins are identical to one another,
    but one of them is cursed. $ C $ decides to put that coin in position $ c
    $. Then he calls in $ A $ and shows him the position of the cursed coin.
    Now he allows $ A $ to flip some coins if he wants (he can't move any coin
    to other positions). After that $ A $ and $ C $ leave the room and sends
    in $ B $. If $ B $ can identify the cursed coin then $ C $ loses,
    otherwise $ C $ wins.

    The rules of the game are explained to $ A $ and $ B $ beforehand, so they
    can discuss their strategy before entering the room. Find the minimum
    number $ k $ of coin flips required by $ A $ so that no matter what
    configuration of $ 64 $ coins C gives them and where he puts the cursed
    coin, $ A $ and $ B $ can win with $ A $ flipping at most $ k $ coins.

Find constructions for $ k=32, 8, 6, 3, 2, 1 $ }\label{problem:binary_1}

\solu{XOR XOR XOR \hrf{binary}{binary representation}}

\prob{http://codeforces.com/contest/987/problem/E}{Codeforces 987E}{E}{Petr
    likes to come up with problems about randomly generated data. This time
    problem is about random permutation. He decided to generate a random
    permutation this way: he takes identity permutation of numbers from $ 1 $
    to $ n $ and then $ 3n $ times takes a random pair of different elements
    and swaps them. Alex envies Petr and tries to imitate him in all kind of
    things. Alex has also come up with a problem about random permutation. He
    generates a random permutation just like Petr but swaps elements $ 7n+1 $
    times instead of $ 3n $ times. Because it is more random, OK?!\\

You somehow get a test from one of these problems and now you want to know
from which one.}

\solu{\hrf{theorem:swap_sort_steps_parity}{This theorem} kills this problem
instantly.}\label{problem:invariant_rules_of_thumb_10}

\prob{https://artofproblemsolving.com/community/c6h53673p336210}{USAMO 2013
P6}{H}{At the vertices's of a regular hexagon are written six nonnegative
integers whose sum is $ 2003^{2003} $. Bert is allowed to make moves of the
following form: he may pick a vertex and replace the number written there by
the absolute value of the difference between the numbers written at the two
neighboring vertices. Prove that Bert can make a sequence of moves, after
which the number $ 0 $ appears at all six
vertices.}\label{problem:monotonicity_with_constraints_1}

\solu{Firstly what comes into mind is to decrease the maximum value, but since
this is a P6, there must be some mistakes. Surely, we can't follow this algo
in the case $ (k, k, 0, k, k, 0) $. But this time, the sum becomes even. So we
have to slowly minimize the maximum,
\hrf{monotonicity_with_constraints}{keeping the sum odd}. And since only odd
number on the board is the easiest to handle, we solve that case first, and
the other cases can be easly handled with an additional algo.}

\prob{https://artofproblemsolving.com/community/c6h546168p3160559}{ISL 2012
C1}{E}{Several positive integers are written in a row. Iteratively, Alice
chooses two adjacent numbers $ x $ and $ y $ such that $ x>y $ and $ x $ is to
the left of $ y $ , and replaces the pair $ (x,y) $ by either $ (y+1,x) $ or $
(x-1,x) $. Prove that she can perform only finitely many such
iterations.}\label{problem:invariant_rules_of_thumb_2}

\solu{Easy invariant.}

\prob{https://artofproblemsolving.com/community/q1h588238p3482449}{AoPS}{E}{There
is a number from the set $ \lbrace 1,-1\rbrace $ written in each of the
vertices's of a regular do-decagon ( $ 12 $ -gon). In a single turn we select
$ 3 $ numbers going in the row and change their signs. In the beginning all
numbers, except one are equal to $ 1 $. Can we transfer the only $ -1 $ into
adjacent vertex after a finite number of
turns?}\label{problem:invariant_rules_of_thumb_6}

\solu{Algo+Proof $ \Longrightarrow $ Invariant.}

\prob{https://artofproblemsolving.com/community/c6h57329p352820}{ISL 1994
C3}{EH}{Peter has three accounts in a bank, each with an integral number of
dollars. He is only allowed to transfer money from one account to another so
that the amount of money in the latter is doubled. Prove that Peter can always
transfer all his money into two accounts. Can Peter always transfer all his
money into one account?}\label{problem:invariant_rules_of_thumb_9}

\solu{Since we want to decrease the minimum, and one of the most simple way is
to consider Euclidean algorithm. So we sort the accounts, $ A < B < C $, and
write $ B = qA+r $, and do some experiment to turn $ B $ into $ r $.}

\prob{https://artofproblemsolving.com/community/c6h225457p1251792}{MEMO 2008,
Team, P6}{M}{On a blackboard there are $ n \geq 2, n \in \mathbb{Z}^{+}$
numbers. In each step we select two numbers from the blackboard and replace
both of them by their sum. Determine all numbers $ n$ for which it is possible
to yield $ n$ identical number after a finite number of
steps.}\label{problem:monotonicity_with_constraints_2}

\solu{The pair thing rules out the case of odds. For evens, we make two
identical sets, and focus on only one of the sets, with an additional move $ x
\rightarrow 2x $ available to use. Since we can now change the powers of $ 2 $
at out will at any time, we only focus on the greatest odd divisors. Our aim
is to slowly decrease the largest odd divisor.}

\prob{https://artofproblemsolving.com/community/c6h1176476p5679356}{USA Dec
    TST 2016, P1}{E}{Let $S = \{1, \dots, n\}$. Given a bijection $f : S \to
    S$ an orbit of $f$ is a set of the form $\{x, f(x), f(f(x)), \dots \}$ for
    some $x \in S$. We denote by $c(f)$ the number of distinct orbits of $f$.
    For example, if $n=3$ and $f(1)=2$, $f(2)=1$, $f(3)=3$, the two orbits are
    $\{1,2\}$ and $\{3\}$, hence $c(f)=2$.\\

Given $k$ bijections $f_1$, $\ldots$, $f_k$ from $S$ to itself, prove that \[
c(f_1) + \dots + c(f_k) \le n(k-1) + c(f) \]where $f : S \to S$ is the
composed function $f_1 \circ \dots \circ
f_k$.}\label{problem:induction_type1_32}

\solu{Induction reduces the problem to the case of $ k=2 $. Then another
inuction on $ c(f_1) $ solves the problem. The later induction works on the
basis of the fact that a ``swap'' in the bijection changes the number of
cycles by $ 1 $ (either adds $ +1 $ or $ -1 $).}

\prob{}{Cody Johnson}{E}{Consider a set of $ 6 $ integers $ S = \{a_1\dots a_6
\} $. At on step, you can add $ +1 $ or $ -1 $ to all of the $ 6 $ integers.
Prove that you can make a finite number of moves so that after the moves, you
have $ a_1a_5a_6 = a_2a_4a_6 = a_3a_4a_5 $}

\prob{https://artofproblemsolving.com/community/c6h596930p3542095}{ISL 2014
A1}{E}{Let $a_0 < a_1 < a_2 \ldots$ be an infinite sequence of positive
integers. Prove that there exists a unique integer $n\geq 1$ such that \[a_n <
\frac{a_0+a_1+a_2+\cdots+a_n}{n} \leq
a_{n+1}.\]}\label{problem:constructive_algo_21}

\solu{My idea was to construct the sequence with the assumtion that the
condition is false. It leads to either all of the right ineq false or the
condition being true.}

\solu{The magical solution: defining $b_n=(a_n-a_{n-1})+\dots+(a_n-a_1)$ which
eases the inequlity.}

\solu{\hrf{http://artofproblemsolving.com/community/c6h596930p3542145}{The
beautiful solution}: defining $ \delta_i $ as $ a_n = a_0 + \Delta_1 +
\Delta_2 + ... + \Delta_n $ for all $ n, i $.}

\solu{Another idea is to first prove the existence and then to prove the
uniqueness.}

\prob{https://artofproblemsolving.com/community/c6h597093p3543144}{ISL 2014
N3}{EM}{For each positive integer $n$, the Bank of Cape Town issues coins of
denomination $\frac1n$. Given a finite collection of such coins (of not
necessarily different denominations) with total value at most most
$99+\frac12$, prove that it is possible to split this collection into $100$ or
fewer groups, such that each group has total value at most
$1$.}\label{problem:greedy_algorithm_1}\label{problem:extremal_case_whole_11}

\solu{Notice that the sum of the geometric series $ S = \dfrac 1 2 + \dfrac{ 1
}{2^2} + \dfrac{ 1 }{2^3} \dots $ is $ 1 $. And in another problem we
partitioned the set of integers into subsets with each subset starting with an
odd number $ k $ and every other elements of the subset being $ 2^i*k $. We do
similarly in this problem, and partition the set of the coins in a similar
way. Then we take the first $ 100 $ sets whose sum is less than $ 1 $ and
insert the other left coins in these sets, with the condition that the sum of
all of the coins is $ 99 + \dfrac 1 2 $.
\hrf{http://artofproblemsolving.com/community/c6h597093p3543181}{Solu}}

\solu{Replacing $ 100 $ by $ n $, we show that for all $ n $ the codition is
valid. Assume otherwise. Take the minimal $ n $ for which the condition does
not work. Ta-Da! We can show that if $ n $ does not work, so doesn't $ n-1 $.
\hrf{http://artofproblemsolving.com/community/c6h597093p3543194}{Solu}}

\solu{Or just be an EChen and prove the result for at most $k -
\dfrac{k}{2k+1}$ with $k$ groups.}

\solu{Very similar to \hrf{problem:greedy_algorithm_2}{this} problem}

\prob{https://artofproblemsolving.com/community/c6h97506p550634}{China TST
2006}{E}{Given positive integer $n$, find the biggest real number $C$ which
satisfy the condition that if the sum of the reciprocals ($ \frac 1 n $ is the
reciprocal of $ n $) of a set of integers (They can be the same.) that are
greater than $1$ is less than $C$, then we can divide the set of numbers into
no more than $n$ groups so that the sum of reciprocals of every group is less
than $1$.}\label{problem:greedy_algorithm_2}

\prob{}{}{E}{In a $ n*n $ grid, every cell is either black or white. A
    `command' is a pair of integers, $ i, j \le n $, after which all of the
    cells in the $ i^{th} $ row and the $ j^{th} $ column (meaning a total of
    $ 2n-1 $ cells) will switch the state. Our goal is to make every cell of
    the same state.

    \begin{enumerate} \item Prove that if it can be done, it can be done in
less than $ \frac{n^2}{2} $ commands.  \item Prove that it can always be done
if $ n $ is even.  \item Prove or disprove for odd $ n $.
\end{enumerate}}\label{problem:constructive_algo_23}

\solu{(a) is really easy, just take into account that flipping all cells
result in the switch of all of the cells. And the question did not ask for an
algorithm.}

\solu{(b) is also easy, notice that we can pair the columns and then make them
look like the same, with a compound command. A better algo is to take the
original algo and to modify it like, take one cell, then do the original move
on all cells in the row and column of this cell.}

\solu{(c) uses Linear Algebra, which I dont know yet, or... use double
counting to build the criteria of the fucntion $ f:\text{states} \rightarrow
\text{subset of moves} $ being bijective.}

\prob{}{OIM 1994, PSMiC}{E}{In every square of an $ n\times n $ board there is
a lamp. Initially all the lamps are turned off. Touching a lamp changes the
state of all the lamps in its row and its column (including the lamp that was
touched). Prove that we can always turn on all the lamps and find the minimum
number of lamps we have to touch to do this.}

\prob{https://atcoder.jp/contests/agc043/tasks/agc043_b}{AtCoder GC043
    B}{M}{Given is a sequence of $ N $ digits $ a_1, a_2\ldots a_N $, where
    each element is $ 1, 2 $, or $ 3 $. Let $ x_{i,j} $ defined as follows:

    \begin{itemize} \item $ x_{1,j} := a_j \quad (1 \leq j \leq N) $ \item $
    x_{i,j} := | x_{i-1,j} - x_{i-1,j+1}| \quad (2 \leq i \leq N \text{ and }
    1 \leq j \leq N+1-i) $ \end{itemize}

Find $ x_{N,1} $.}

\solu{Since $ |x-y| \equiv x+y (\mod\ 2) $, we can determine the parity of $
X_{N,1} $ using binomial coefficient. Which in turn we can get in $ O(n) $
with bitwise operator. Now we have to distinguish between $ 0, 2 $. For $ 2 $,
all of the rows starting with the second one should have only $ 2 $ and $ 0 $.
Where we can apply the same algorithm as before and find whether the final
digit is $ 2 $ or $ 0 $.}

\prob{acm.timus.ru/problem.aspx?space=1&num=1578}{Timus 1578}{E}{The very last
    mammoth runs away from a group of primeval hunters. The hunters are
    fierce, hungry and are armed with bludgeons and stone axes. In order to
    escape from his pursuers, the mammoth tries to foul the trail. Its path is
    a polyline (not necessarily simple). Besides, all the pairs of adjacent
    segments of the polyline form acute angles (an angle of 0 degrees is also
    considered acute).\\

After the mammoth vanished, it turned out that it had made exactly N turns
while running away. The points where the mammoth turned, as well as the points
where the pursuit started and where the pursuit ended, are known. You are to
determine one if the possible paths of the
mammoth.}\label{problem:greedy_algorithm_3}

\prob{http://codeforces.com/contest/744/problem/B}{CodeForces 744B}{E}{Given a
hidden matrix of $ n\times n,\ n\leq1000 $ where for every $ i $ , $ M_{(i, i)
= 0} $ , Luffy's task is to find the minimum value in the $ n $ rows, formarly
spoken, he has to find values $ \min_{j=1\dots n,\ j\not=i} M_{(i, j)} $. To
do this he can ask the computer questions of following types: In one question,
Luffy picks up a set, $ {a_1, a_2\dots a_k} $ with $ a_i, k \leq n $. And
gives the computer this set. The computer will respond with $ n $ integers.
The $ i $ -th integer will contain the minimum value of $ \min_{j=1\dots k}
M_{(i, a_j)}$ . And on top of this, he can only ask $ 20 $ questions. Luffy
being the stupid he is, doesn't even have any clue how to do this, you have to
help him solving this
problem.}\label{problem:divide_and_conquer_2}\label{problem:binary_query_1}

\solu{If we draw the diagonal in the matrix, we see that we can fit boxes of $
2^i \times 2^i $ in there depending on the $ i $ 's value. Now after we have
decomposed the matrix into such boxes, we can choose several from them to ask
a question. The trick is that for every row, there must be questions asked
from each of the boxes this row covers and no question from here must contain
the $ (i, i) $ cell.}

%\fig{.3}{CF744B}{}

\solu{The \hrf{problem:binary_query_1}{magical solution} goes as following:
For $ i\leq 10 $ , for every $ k=1\dots n $ , include $ k $ in the question if
the $ i $ th bit of $ k $ 's binary form is $ 0 $. And then for the second
round include $ k $ in the question if the $ i $ th bit of $ k $ 's binary
form is $ 1 $.}

\prob{}{}{E}{Alice wants to add an edge $ (u, v) $ in a graph. You want to
know what this edge is. So, you can ask some questions to Alice. For each
question, you will give Alice $ 2 $ non-empty disjoint sets $ S $ and $ T $ to
Alice, and Alice will answer "true" iff $ u $ and $ v $ belongs to different
sets. You can ask atmost $ 3 * \ceil{log_2|V|} $ questions to Alice. Describe
a strategy to find the edge $ (u, v)
$.}\label{problem:binary_query_2}\label{problem:divide_and_conquer_3}

\solu{First find one true answer in $ \ceil{log_2|V|} $ questions, and then
get the result out of these two sets in $ 2*\ceil{log_2|V|} $ questions.}

\solu{The \hrf{problem:binary_query_2}{magical solution} goes as following: In
the $ i^{th} $ question, $ S = {x : i^{th} \text{ bit of } x \text{ is } 0} ,\
T = {x : i^{th} \text{ bit of } x \text{ is } 1} $ }

\prob{https://artofproblemsolving.com/community/c5h1083477p4774079}{USAMO 2015
    P4}{E}{Steve is piling $m\geq 1$ indistinguishable stones on the squares
    of an $n\times n$ grid. Each square can have an arbitrarily high pile of
    stones. After he finished piling his stones in some manner, he can then
    perform stone moves, defined as follows. Consider any four grid squares,
    which are corners of a rectangle, i.e. in positions $(i, k), (i, l), (j,
    k), (j, l)$ for some $1\leq i, j, k, l\leq n$, such that $i<j$ and $k<l$.
    A stone move consists of either removing one stone from each of $(i, k)$
    and $(j, l)$ and moving them to $(i, l)$ and $(j, k)$ respectively,j or
    removing one stone from each of $(i, l)$ and $(j, k)$ and moving them to
    $(i, k)$ and $(j, l)$ respectively.\\

    Two ways of piling the stones are equivalent if they can be obtained from
    one another by a sequence of stone moves.\\

How many different non-equivalent ways can Steve pile the stones on the
grid?}\label{problem:constructive_algo_24}\label{problem:invariant_rules_of_thumb_12}

\solu{Building an invariant, we see that only the sum of the columns is not
sufficient. So to get more control, we take the row sums into account as
well.}

\prob{https://artofproblemsolving.com/community/c6h5758p18993}{ISL 2003
    C4}{E}{Let $x_1,\ldots, x_n$ and $y_1,\ldots, y_n$ be real numbers. Let $A =
    (a_{ij})_{1\leq i,j\leq n}$ be the matrix with entries \[a_{ij} =
        \begin{cases}1,&\text{if }x_i + y_j\geq 0;\\0,&\text{if }x_i + y_j <
        0.\end{cases}\]Suppose that $B$ is an $n\times n$ matrix with entries $0$, $1$
        such that the sum of the elements in each row and each column of $B$ is equal
        to the corresponding sum for the matrix $A$. Prove that
    $A=B$.}\label{problem:constructive_algo_25}

    \solu{If done after \hrf{problem:constructive_algo_24}{this} problem, this
    problem seems straigthforward.}

    \prob{https://artofproblemsolving.com/community/c6h1557188p9502889}{India
        TST 2017 D1 P3}{E}{Let $n \ge 1$ be a positive integer. An $n \times
        n$ matrix is called \textit{good} if each entry is a non-negative
        integer, the sum of entries in each row and each column is equal. A
        \textit{permutation} matrix is an $n \times n$ matrix consisting of
        $n$ ones and $n(n-1)$ zeroes such that each row and each column has
        exactly one non-zero entry.\\

        Prove that any \textit{good} matrix is a sum of finitely many
    \textit{permutation} matrices.}

    \solu{Same algo as \hrf{problem:constructive_algo_24}{above}. Either
    distributing uniformly or gathering all in a diagonal}

    \prob{https://artofproblemsolving.com/community/c6h1388469p7730613}{Tournament
        of Towns 2015F S7}{MH}{$N$ children no two of the same height stand in a
        line. The following two-step procedure is applied: first, the line is split
        into the least possible number of groups so that in each group all children
        are arranged from the left to the right in ascending order of their heights (a
        group may consist of a single child). Second, the order of children in each
        group is reversed, so now in each group the children stand in descending order
        of their heights. Prove that in result of applying this procedure $N - 1$
        times the children in the line would stand from the left to the right in
    descending order of their heights.}

    \solu{It's obvious that we need to find some invariant or mono-variant.
        Now, an idea, we need to show that for any $ i $, for it to be on it's
        rightful place, it doesn't need more than $ N-1 $ moves. How do we show that?
        Another idea, think about the bad bois on either of its sides. Now,
    observation, `junctions' decrease with each move. Find the `junctions'.}

    \prob{https://main.edu.pl/en/archive/oi/2/sze}{Polish OI}{E}{Given $ n $
        jobs, indexed from $ 1, 2\dots n $. Given two sequences of reals, $
        \{a_i\}^n_{i=1}, \{b_i\}^n_{i=1} $ where, $ 0 \leq a_i, b_i \leq 1 $. If job $
        i $ starts at time $ t $ , then the job takes $ h_i(t) = a_it+b_i $ time to
        finish. Order the jobs in a way such that the total time taken by all of the
        jobs is the
    minimum.}\label{problem:forget_and_focus_2}\label{problem:swapping_1}

    \solu{Example of a problem which is solved by investigating two adjacent
    objects in the optimal arrangement.}

    \prob{http://codeforces.com/problemset/problem/960/C}{CodeForces
        960/C}{E}{Pikachu had an array with him. He wrote down all the
        non-empty subsequences of the array on paper. Note that an array of
        size $ n $ has $ 2^n - 1 $ non-empty subsequences in it.\\

        Pikachu being mischievous as he always is, removed all the
        subsequences in which \[ \text{Maximum element of the subsequence} -
        \text{Minimum element of subsequence} \geq d \]

        Pikachu was finally left with $ X $ subsequences. \\

        However, he lost the initial array he had, and now is in serious
        trouble. He still remembers the numbers $ X $ and $ d $. He now wants
        you to construct any such array which will satisfy the above
        conditions. All the numbers in the final array should be positive
        integers less than $ 10^{18} $.\\

        Note the number of elements in the output array should not be more than
        $10^4$. If no answer is possible, print  $ -1
    $.}\label{problem:constructive_algo_3}

    \prob{https://artofproblemsolving.com/community/c6h35318p220230}{ARO 2005
        P10.3, P11.2}{M}{Given $ 2005 $ distinct numbers $
        a_1,\,a_2,\dots,a_{2005} $. By one question, we may take three different
        indices $ 1\le i<j<k\le 2005 $ and find out the set of numbers  $
        \{a_i,\,a_j,\,a_k\} $ (unordered, of course). Find the minimal number of
        questions, which are necessary to find out all numbers $ a_i
    $.}\label{problem:constructive_algo_4}

    \solu{The key idea is to ask questions such that it is connected to
        multiple other questions, and each question uniquely finds out multiple
        elements together. One by itself immediately after the question has been
        asked, and one after the next question which is related to this one has been
        asked. As we find out three elements' values after one question, first,
        second, third, so, let us find first from the previous question, second from
    the current question, third from the next question.}

    \prob{https://wcipeg.com/problem/ioi0713}{IOI 2007 P3}{M}{You are given
        two sets of integers $ A=\{a_1, a_2 \dots a_n\} $ and $ B=\{b_1, b_2 \dots
        b_n\} $ such that $ a_i \geq b_i $. At move $ i $ you have to pick $ b_i $
        distinct integers from the set $ A_i = \{1, 2, \dots a_i\} $. In total, $ (b_1
        + b_2 +\dots + b_n) $ integers are selected, but not all of these are
        distinct. Suppose $ k $ distinct integers have been selected, with
        multiplicities $ c_1, c_2, c_3 \dots c_k $. Your score is defined as
        \[\sum^k_{i=1}c_i(c_i-1)\] Give an efficient algorithm to select numbers in
        order to ``minimize'' your
    score.}\label{problem:constructive_algo_5}\label{problem:swapping_2}

    \solu{Some investigation shows that if $ c_i > c_j + 1 $ and $ i > j $ ,
        then we can always minimize the score. and if $ i < j $ , then we can
        minimize the score only when $ i, j \in A_k $ but $ i $ has been taken at move
        $ k $ , but $ j $ hasn't. So in the minimal state, either both $ i, j $ has
        been taken at move $ k $ , or $ a_k < j $. So the idea is to take elements
        from $ A_i $ as large as possible, and then taking smaller values after wards
        if the $ c_i $ value of a big element gets more than that of a small element.
        In this algorithm, we see that we greedily manipulate $ c_i $. So it is a good
    idea to greedily choose $ c_i $ 's from the very beginning.}

    \solu{\textbf{Solution Algo:} at step $ i $ , take the set $ \{c_1, c_2
        \dots c_{a_i}\} $ and take the smallest $ b_i $ from this set, and add $ 1
        $ to each of them (in other words, take their index numbers as the numbers to
    take).}

    \prob{}{}{E}{Given $ n $ numbers $ \{a_1, a_2, ..., a_n\} $ in arbitrary
        order, you have to select $ k $ of them such that no two consecutive
        numbers are selected and their sum is
    maximized.}\label{problem:constructive_algo_6}\label{problem:swapping_3}

    \solu{Notice that if $ a_i $ is the maximum value, and if $ a_i $ is not
        counted in the optimal solution, then both of $ a_{i-1}, a_{i+1} $ must be
        in the optimal solution, and $ a_{i-1} + a_{i+1} > a_i $. And if $ a_i $ is
        counted in the optimal solution, then none of $ a_{i-1}, a_{i+1} $ can be
        counted in the optimal solution. So either way, we can remove these three and
        replace them by a single element to use induction. So remove $ a_{i-1},
    a_{i+1} $ and replace $ a_i $ by $ a_{i-1} + a_{i+1} - a_i $.}

    \prob{https://artofproblemsolving.com/community/c5h347285p1860777}{USAMO
        2010 P2}{EM}{There are $n$ students standing in a circle, one behind the
        other. The students have heights $h_1<h_2<\dots <h_n$. If a student with
        height $h_k$ is standing directly behind a student with height $h_{k-2}$ or
        less, the two students are permitted to switch places. Prove that it is not
        possible to make more than $\binom{n}{3}$ such switches before reaching a
    position in which no further switches are possible.}

    \prob{https://artofproblemsolving.com/community/c6h1070674p4655727}{Serbia
        TST 2015 P3}{H}{We have $2015$ prisinoers. The king gives everyone a hat
        coloured in one of $5$ colors. Everyone sees all hats expect his own. Now,the
        King orders them in a line(a prisioner can see all guys behind and in front of
        him). The king asks the prisinoers one by one does he know the color of his
        hat.If he answers NO,then he is killed.If he answers YES,then answers which
        color is his hat,if his answers is true,he goes to freedom,if not,he is
        killed.All the prisinors can hear did he answer YES or NO,but if he answered
        YES,they don't know what did he answered(he is killed in public).They can
        think of a strategy before the King comes,but after that they can't
        comunicate.What is the largest number of prisinors we can guarentee that can
    survive?}

    \prob{https://artofproblemsolving.com/community/c6h1113653p5087465}{Taiwan
        TST 2015 R3D1P1}{E}{A plane has several seats on it, each with its own
        price, as shown below. $2n-2$ passengers wish to take this plane, but
        none of them wants to sit with any other passenger in the same column
        or row. The captain realize that, no matter how he arranges the
        passengers, the total money he can collect is the same. Proof this
        fact, and compute how much money the captain can collect.
    \fig{.5}{TaiwanTST2015R3D1P1}{} }

    \prob{https://artofproblemsolving.com/community/c6h1113195p5083566}{ISL
        2014 N1}{E}{Let $n \ge 2$ be an integer, and let $A_n$ be the set \[A_n =
        \{2^n - 2^k\mid k \in \mathbb{Z},\, 0 \le k < n\}.\] Determine the largest
        positive integer that cannot be written as the sum of one or more (not
    necessarily distinct) elements of $A_n$ .}

    \solu{Inductive approach}

    \prob{https://codeforces.com/contest/330/problem/D}{Codeforces
    330D}{E}{Biridian Forest}

    \solu{Generalize the condition for a meet-up.}

    \prob{https://codeforces.com/contest/1270/problem/F}{Codeforces
        1270F}{E}{Let's call a binary string $ s $ awesome, if it has at least
        $ 1 $ symbol \texttt{1} and length of the string is divisible by the
        number of \texttt{1} in it. In particular, \texttt{1}, \texttt{1010},
        \texttt{111} are awesome, but \texttt{0}, \texttt{110}, \texttt{01010}
        aren't.\\

        You are given a binary string $ s $ of size $ \le 2\times10^5 $. Count the
    number of its awesome substrings.}

    \solu{The constraint tells us the algorithm should be of complexity $
        O(n\sqrt{n}) $. Playing with the funtion $ f(i) $ and the divisibility
        condition gives us some ground to work with. Since we need $ \le
        c\times\sqrt{n} $ queries around the full string, we remember the prime sieve
    trick.}

    \prob{https://artofproblemsolving.com/community/c6h60773p366562}{IMO 1986
        P3}{M}{To each vertex of a regular pentagon an integer is assigned, so
        that the sum of all five numbers is positive. If three consecutive vertices
        are assigned the numbers $x,y,z$ respectively, and $y<0$, then the following
        operation is allowed: $x,y,z$ are replaced by $x+y,-y,z+y$ respectively. Such
        an operation is performed repeatedly as long as at least one of the five
        numbers is negative. Determine whether this procedure necessarily comes to an
    end after a finite number of steps.}

    \solu{Notice how starting from one negative and moving to consective
    number on one side moves the number by one vertex nicely.}

\newpage
\subsection{Algorithm Analysis}

\prob{https://artofproblemsolving.com/community/c6h2112349}{GQMO 2020
    P4}{MH}{Prove that, for all sufficiently large integers $n$, there exists
    $n$ numbers $a_1, a_2, \dots, a_n$ satisfying the following three
    conditions:

    Each number $a_i$ is equal to either $-1, 0$ or $1$.  At least
    $\dfrac{2n}{5}$ of the numbers $a_1, a_2, \dots, a_n$ are non-zero.  The
sum $\dfrac{a_1}{1} + \dfrac{a_2}{2} + \dots + \dfrac{a_n}{n}$ is $0$.}

\newpage
\subsection{Covering Area with Squares}

\begin{myitemize} \item
\href{https://artofproblemsolving.com/community/c301601h1551769_cover_story_squares}{A
nice blog post by ankogonit} \end{myitemize}

\prob{https://artofproblemsolving.com/community/c301601h1551769_cover_story_squares}{Brazilian
MO 2002, ARO 1979}{E}{Given a finite collection of squares with total area at
least $4$, prove that you can cover a unit square completely with these
squares (with overlapping allowed, of course).}

\solu{Maybe motivated by the number $ 4 $ and how nice it would be if all the
squares had $ 2 $'s power side lengths, the idea is to shrink every square to
a side with side of $ 2 $'s power.}

\prob{}{ARO 1979's Sharper Version}{E}{Given a finite collection of squares
with total area at least $3$, prove that you can cover a unit square
completely with these squares (with overlapping allowed).}

\solu{The idea is to greedily cover the unit square by covering the lowest row
uncovered. And then using boundings to prove that it is possible.}

\prob{}{}{E}{Prove that a finite collection of squares of total area
$\frac{1}{2} $ can be placed inside a unit square without overlap.}

\solu{The same idea as before.}

\prob{}{Tournament of Towns Spring 2012 S7}{EM}{We attempt to cover the plane
    with an infinite sequence of rectangles, overlapping allowed.
    \begin{enumerate} \item Is the task always possible if the area of the
        $n-$th rectangle is $n^2$ for each $n$?  \item Is the task always
        possible if each rectangle is a square, and for any number $N$, there
        exist squares with total area greater than $N$?  \end{enumerate}}

\solu{Identical algo and proving technique as above.}

\solu{Using the first problem in this subsection to find a better algo.}

\prob{https://artofproblemsolving.com/community/c6h155700p875004}{ISL 2006
    C6}{E}{A holey triangle is an upward equilateral triangle of side length
    $n$ with $n$ upward unit triangular holes cut out. A diamond is a
    $60^\circ-120^\circ$ unit rhombus.\\

Prove that a holey triangle $T$ can be tiled with diamonds if and only if the
following condition holds: Every upward equilateral triangle of side length
$k$ in $T$ contains at most $k$ holes, for $1\leq k\leq n$.}

\solu{Think of induction and how you can deal with that.}

\prob{https://artofproblemsolving.com/community/c7h442824p2494271}{Putnam 2002
A3}{E}{Let $N$ be an integer greater than $1$ and let $T_n$ be the number of
non empty subsets $S$ of $\{1,2,.....,n\}$ with the property that the average
of the elements of $S$ is an integer. Prove that $T_n - n$ is always even.}

\solu{Try to show an bijection between the sets with average $n$ which has $k$
elements (Here $k$ is an even integer) and the sets with average $n$ but with
number of elements $k+1$. This implies that the number of such sets is even.}

\prob{https://artofproblemsolving.com/community/c6h55343p343870}{USAMO
1998}{E}{Prove that for each $n\geq 2$, there is a set $S$ of $n$ integders
such that $(a-b)^2$ divides $ab$ for every distinct $a,b \in
S$.}\label{problem:sets_scp_1}

\solu{Induction comes to the rescue. Trying to find a way to get from $n$ to
$n+1$, we see that we can \emph{shift} the integers by any integer $k$. So
after shifting, what stays the same, and what changes?}

combi/sec4_algo (M Ahsan Al Mahir's conflicted copy 2020-07-28).tex


\subsection{N}

The is the size of the sample.


\documentclass[twoside]{MATH77}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\begin{document}
\begmath 13.1 Numerical Evaluation of Integrals Over One Dimension

\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology, \thisyear \ Math \`a la Carte, Inc.}

\subsection{Purpose}

This collection of subprograms estimates the value of the integral%
\begin{equation*}
\int_a^bf(x)\,dx
\end{equation*}
where the integrand $f(x)$ and the limits $a$ and $b$ are supplied by the
user.

\subsection{Usage}

Described below under B.1 through B.5 are:

\begin{tabular*}{3.3in}{@{}l@{~~}l}
B.1 & \hspace{-20pt} Program Prototype, Single Precision\dotfill \pageref{PPSP}\\
\quad B.1.a & The Calling Routine\dotfill \pageref{Calling}\\
\quad B.1.b & Argument Definitions for SINT1\dotfill
\pageref{ArgDef}\\
\quad B.1.c & The User-supplied Integrand\\
 & Subroutine SINTF\dotfill
\pageref{SINTF}\\
\quad B.1.d & Argument Definitions for SINTF\dotfill \pageref{ArgSINTF}\\
\quad B.1.e & Passing Extra Information into SINTF\dotfill \pageref{ExSINTF}\\
B.2 & \hspace{-20pt}  Program Prototype, Single Precision,\\
 & \hspace{-20pt} Reverse Communication\dotfill
\pageref{PPRC}\\
\quad B.2.a & The Calling Routine\dotfill \pageref{CallingRC}\\
\quad B.2.b & Argument Definitions\dotfill \pageref{ArgDefRC}\\
B.3 & \hspace{-20pt} Methods to Request Unusual Usage Through
\rule{.3in}{0pt}\\
 & \hspace{-20pt} the Arguments IOPT and WORK\dotfill \pageref{UnusualUse}\\
B.4 & \hspace{-20pt} Changing the Selection of Some Options\\
 &\hspace{-20pt} During the Computation\dotfill \pageref{ChangeSel}\\
B.5 & \hspace{-20pt} Modifications for Double Precision Usage\dotfill \pageref{DPuse}\\
\end{tabular*}

\subsubsection{Program Prototype, Single Precision.\label{PPSP}}

\paragraph{The Calling Routine\label{Calling}}

{\bf REAL} {\bf A, B, ANSWER, WORK$(\geq k_1)$}
[$k_1$ depends on options used ($\geq 1$).]

{\bf INTEGER} {\bf IOPT$(\geq k_2)$} [$k_2$ depends on options used
($\geq 2$).]

Assign values to A and B.

Assign values to IOPT() and elements of WORK() referenced using options (see
Section B.3). For simplest usage, set

\hspace{.2in}IOPT$(2)=0$%
$$
\fbox{{\bf CALL SINT1(A,B,ANSWER,WORK,IOPT)}}
$$
If the computation is successful (indicated by IOPT$(1)<0)$ the result is in
ANSWER and the estimate of the error in the result is in WORK(1).

\vspace{20pt}
\paragraph{Argument Definitions for SINT1\label{ArgDef}}

\begin{description}
\item[A]  [in] Lower limit of integration.

\item[B]  [in] Upper limit of integration. The relative values of A and B
are interpreted properly.  Thus if one exchanges A and B, the sign of
the answer is changed.  When the integrand is positive, the sign of
the result is the same as the sign of B $-$ A.

\item[ANSWER]  [out] Estimate of the integral.

\item[WORK()]  [inout] On completion, WORK(1) contains an estimate of the
upper bound of the magnitude of the difference between ANSWER and the
true value of the integral. Other elements of WORK may be referenced by
the option vector IOPT as described below and in Section B.3, and to pass
parameters to SINTF as described in Section B.1.e.

\item[IOPT()]  [inout] Used to return status information to the user, to
allow the selection of options, and to pass parameters to SINTF as described
in Section B.1.e. IOPT(1) returns a status indicator with the possible
values:

\begin{itemize}
\item[$-1$]  Normal termination with either the absolute or relative error
tolerance criteria satisfied (see option~3 in Section~B.3).

\item[$-2$]  Normal termination with neither the absolute nor relative error
tolerance criteria satisfied, but the error tolerance based on the locally
achievable precision is satisfied. (See option~3 in Section~B.3).
This is the normal status value when no tolerances are specified.

\item[$-3$]  Normal termination with none of the error tolerance criteria
satisfied. (See option~3 in Section~B.3).
\item[$+4$]  Bad value for an element of IOPT.

\item[$+5$]  Too many function values needed (see option~9 in
Section~B.3).

\item[$+6$]  The integrand apparently contains a nonintegrable singularity.\
The abscissa of the singularity is near ANSWER. WORK(1) contains a large
number.
\end{itemize}

The remainder of IOPT may be used to select options and to pass parameters
to SINTF. If no options are selected, set IOPT$(2)=0.$

See Section B.3 for a detailed description of options and the following
table for an overview.
\end{description}

\newpage\ \centerline{{\bf Table of Options for SINT1}\hspace{.5in}}
\ {\bf Option}\newline
{\bf Number\hspace{.4in}Brief Description}\vspace{-3pt}
\begin{itemize}
\item[0]  No more options.

\item[1]  No effect. Reserved for future use. Do not use option~1.

\item[2]  Select level of diagnostic output.

\item[3]  Specify error tolerances.

\item[4]  Specify an a posteriori estimate of the absolute error in the
calculated value of the integrand.

\item[5]  Specify an a priori estimate of relative error expected in the
calculated values of integrands.

\item[6]  Use reverse communication.

\item[7]  Specify minimum index of quadrature formula.

\item[8]  No effect. The parameter may provide information to SINTF.

\item[9]  Specify maximum number of integrand evaluations allowed.

\item[10]  Return number of integrand evaluations used.

\item[11]  Specify location of singularity or discontinuity in integrand.

\item[12]  Specify absolute errors in the limits.

\item[13]  Used for multi-dimensional integration. See Chapter~13.2.
\end{itemize}

\paragraph{The User-Supplied Integrand Subroutine SINTF\label{SINTF}}

SINT1 requires that the user provide values of the integrand. In the case
of simple usage these values are provided by a user-supplied subroutine of
the form:

{\tt \begin{tabbing}
SUBROUTINE SINTF(ANSWER, X, IFLAG)\\
REAL \ ANSWER, X\\
INTEGER \ IFLAG\\
ANSWER $=$ value of integrand at X\\
RETURN\\
END
\end{tabbing}}

\paragraph{Argument Definitions for SINTF\label{ArgSINTF}}

\begin{description}
\item[ANSWER]  \ [out] set by SINTF to be the value of the integrand at X.

\item[X]  \ [in] contains the abscissa at which the integrand is to be
evaluated. X may also be used to pass extra information into SINTF, as
described in Section B.1.e.

\item[IFLAG]  \ [in] is not needed for simple usage, but may be used to pass
extra information into SINTF, as described in Section B.1.e.
\end{description}

Most mathematical software that requires user defined function
information allows the user to pass in the name of a subprogram for
evaluating the function.  The approach used here has the advantage of not
requiring the user to declare his subprogram in an external statement
(It's not unusual for this to be forgotten.), and of giving a meaningful
diagnostic when no such routine is provided.  If one is solving different
problems with different programs, one can use different file names for the
different function subprograms, all of which would use the same entry
name.  The linker must then be told which of these function subprograms
should be used in forming the executable file.  If one wants to solve
several different problems in the same program, one should code the
separate cases in one subprogram and select the one desired by passing a
``case'' variable into the routine.  This can either be done as part of
IFLAG as mentioned above, or can be done through the use of named
common.  One can also use reverse communication and call subprograms with
different names for the different cases.

\paragraph{Passing Extra Information into SINTF\label{ExSINTF}}

The argument X of SINTF is the first element of the WORK vector passed from
the user's calling routine to SINT1. Elements of WORK other than the first
may be referenced by options, as described in Section B.3, or used to pass
extra floating point information to SINTF. If X is used in this way it must
be declared to be an array instead of a scalar.

The argument IFLAG of SINTF is the first element of the IOPT() vector
passed from the users calling routine to SINT1. Elements of IOPT
(after the first) that are not used for options as described in
Section B.3 may be used to pass integer valued information into
SINTF. In addition, the parameter of option~8 described in Section
B.3 may be examined by SINTF. If IFLAG is used in this way it must be
declared to be an array instead of a scalar.
\subsubsection{Program Prototype, Single Precision, Reverse Communication.%
\label{PPRC}}
\paragraph{The Calling Routine\label{CallingRC}}
\begin{description}
\item[REAL]  \ {\bf A, B, ANSWER, WORK$(\geq 1)$}
\item[INTEGER]  \ {\bf IOPT$(\geq 3)$}
\end{description}
Assign values to A, B, IOPT and elements of WORK referenced by options.
Option~6 must be selected (see Section~B.3). For simple usage, set
\begin{tabbing}
\hspace{.2in}\=IOPT$(2) = 6$\\
\>IOPT$(3) = 0$
\end{tabbing}
\begin{center}\vspace{-5pt}
\fbox{\begin{tabular}{@{\bf }c}
CALL SINT1 (A, B, ANSWER,\\
WORK, IOPT)
\end{tabular}}
\end{center}\vspace{-5pt}
\hspace{.2in}DO
$$
\quad \fbox{{\bf CALL SINTA (ANSWER, WORK, IOPT)}}
$$\vspace{-20pt}
\begin{tabbing}
\hspace{.2in}\=\ \ \ \ \=IF (IOPT(1) .NE.\ 0) EXIT\\
\>\>ANSWER $=$ value of integrand at $x$, where\\
\>\>\ \ \ \ \=$x =$ WORK(1)\\
\>END DO\\
\>$\{$ Integration is complete. $\}$
\end{tabbing}
\paragraph{Argument Definitions\label{ArgDefRC}}
\begin{description}
\item[A, B]  \ Used as described in Section B.1.b.
\item[ANSWER]  \ [inout] During integration, ANSWER provides a value of the
integrand to SINTA. On completion, ANSWER contains an estimate of the
integral.
\item[WORK()]  \ [inout] Used as described in Section B.1.b, except that
during the integration WORK(1) is the abscissa at which the integrand is to
be evaluated.
\item[IOPT()]  \ [inout] Used as described in Section B.1.b, except IOPT(1)
has additional uses. If IOPT$(1)=0$, then evaluate the integrand at the
abscissa specified in WORK(1) and put the result in ANSWER. If IOPT$(1)\neq
0$, integration has been completed. Refer to Section B.1 for the meaning of
nonzero values of IOPT(1).
\end{description}

\subsubsection{Methods to Request Unusual Usage Through the Arguments IOPT
and WORK\label{UnusualUse}}

Options are identified by codes ranging from~0 to~12. Options 0 and~6 have
no arguments, while the other options each require one integer argument. An
option is selected by placing its code in the array IOPT() with the
following element of the array containing its argument if it requires one.\
The option codes, with space for their arguments as required, must be stored
as a contiguous sequence beginning in IOPT(2) and ending with the option
code~0.

If a nonzero option code appears more than once, only the last occurrence
will be effective.

Depending on the option, an argument may be a location where an
integer value is provided or returned, or it may be an index into the
array WORK() indicating the location of a floating point datum or the
beginning of a sequence of floating point data.

If options involving indexes into WORK() are used, the index must exceed 1,
and WORK() must be dimensioned sufficiently large.

All unselected options are assigned default values.

The options are defined as follows:
\begin{itemize}
\item[0]  (No argument) Terminates the sequence of selected options.
\item[1]  (Argument K1) No effect. Reserved for future use. Do not use
option~1.
\item[2]  (Argument K2) K2 selects the level of diagnostic output:
\begin{itemize}
\item[0]  No printing.
\item[1]  Minimum printing --- error messages (default value).
\item[2]  Panel boundaries and error estimates in addition to (1).
\item[3]  Error estimates for each quadrature formula in addition to (2).
\item[4]  Maximum detail.
\end{itemize}
\item[3]  (Argument K3) K3 is an index into WORK(). The user provides the
absolute error tolerance in WORK(K3), the error tolerance T based on
the locally achievable precision in WORK(K3$+1)$, and the error tolerance
relative to the value of the integral in WORK(K3$+2)$. The error tolerance
T should be assigned a value $\epsilon ^f$, where $\epsilon $ is the
smallest number such that computing $1.0 + \epsilon $ gives a number
different from~1.0 ($\epsilon $ is the precision of the machine
arithmetic) and $f$ is the fraction (number of correct digits desired)
/ (digits of achievable precision).  (This
latter number is discussed in Section D where the method for
computing the error estimate is described.)  The internal value for T
is bounded between $\epsilon $ and $\sqrt {\epsilon }$, that is
$\frac 12 \leq f \leq 1$.  If this option is not selected, the
absolute error tolerance and the tolerance relative to the value of
the integral are both set to zero, and T is set using an $f$ of~3/4,
$i.e.$ T = $\epsilon ^{3/4}$. The default values usually provide
all the accuracy that can be obtained efficiently.

The error tolerance relative to the value of the integral is applied
globally (over the entire region of integration) rather than locally (one
step at a time). This policy provides true control of error relative to the
value of the integral when the integrand is not sign definite, as well as
when the integrand is sign definite. To apply the criterion of error
tolerance relative to the value of the integral, the value of the integral
over the entire region, estimated without refinement of the region, is used
to derive an absolute error tolerance that may be applied locally. If the
preliminary estimate of the value of the integral is significantly in error,
and the least restrictive error tolerance is relative to the value of the
integral, the cost of computing the integral will be larger than the cost of
computing the integral to the same degree of accuracy using appropriate
values of either of the other error tolerance criteria. The preliminary
estimate of the integral may be significantly in error if the integrand is
not sign definite or has large variation.

\item[4]  (Argument K4) In WORK(K4) the user provides an a posteriori
estimate of the absolute value of the error committed while evaluating the
integrand. This value may be computed during evaluation of the integrand.\
The default value is zero.

\item[5]  (Argument K5) In WORK(K5) the user provides an a priori estimate
of the relative error expected to be committed while evaluating integrands.\
Changes to this value are not detected during evaluation of the integral.\
The default value is the machine precision.

\item[6]  (No argument) Selects use of reverse communication. See Section
B.2.

\item[7]  (Argument K7) K7 specifies the minimum index of quadrature formula
used before SINTA does a more detailed analysis to determine whether a
higher order formula should be used or the interval subdivided. The default
value for this minimum index is~3. The number of integrand samples used for
a formula of index $k$ is $2^k-1$, and the algebraic order is $3/2$ the
number of samples. If the user knows from analysis or experience with this
program that an integral can only be computed to the desired accuracy by
using a formula of higher index than~3, some efficiency may be gained by so
notifying the program.

\item[8]  (Argument K8) No effect. K8 may be used to pass information to
SINTF.

\item[9]  (Argument K9) K9 specifies the maximum number of function values
to use to compute the integral. If this option is not selected, or if K9 $%
\leq $ 0, the number of function values is not bounded.

\item[10]  (Argument K10) On return the number of function values used to
calculate the integral is stored in K10.

\item[11]  (Argument K11) K11 is a signed index providing a means for the
user to give the subroutines information about the location and type of any
known singularities of the integrand. When an integrand appears to have
singular behavior at the end of the interval, a transformation of the
variable of integration is applied to reduce the strength of the
singularity. When an integrand appears to have singular behavior inside the
interval, the abscissa of the singularity is determined as precisely as
necessary, depending on the error tolerance, and the interval is subdivided.

The discovery of singular behavior and determination of the abscissa of
singular behavior are expensive. If the user knows of the existence
of a singularity, the efficiency of computation of the integral may be
improved by requesting an immediate transformation of the independent
variable or subdivision of the interval. In WORK($|$K11$|$) the user
provides the real part of the abscissa of a singularity or discontinuity
in the integrand. It is recommended that the user select this option for
all singularities, even those outside [A, B].

For singularities having a leading term of the form $x^\alpha $ where $%
\alpha $ is not an integer, if $\alpha $ is ``large'' or has the form $%
\alpha =(2n-1)/2$ where $n$ is a nonnegative integer, or the singularity is
well outside the interval, make K11 positive. Otherwise, make K11 negative.\
The meaning of ``large'' depends on the rest of the integrand and the length
of the interval. ``Large'' is probably about~2 for the typical case. For a
singularity of the form $x^\alpha \log \ x$ use the above rule, even if $%
\alpha $ is an integer. For other types of singularity make a reasonable
guess based on the above. If several similar integrals are to be computed,
some experimentation may be useful.

When K11 $>0$, a transformation of the form T $=$ TA $+$ (X $-$ TA$)^2/$ (TB
$-$ TA) is applied, where TA is the abscissa of the singularity and TB is
the end of the interval. If TA is outside the interval, TB will be the end
of the interval farthest from TA. If TA is inside the interval, the
interval will immediately be subdivided at TA, and both parts will be
separately integrated with TB equal to each end of the original interval,
respectively. When K11 $<0$, a transformation of the form T $=$ TA $+$ (X $-
$ TA$)^4/($TB $-$ TA$)^3$ is applied, with TA and TB as above.

If the integrand has singularities at more than one abscissa within the
region, or more than one pole near the real axis such that the real parts
are within the region of integration, the interval should be subdivided at
the abscissae of the singularities or the real parts of the poles, the
integrals should be computed as separate problems, and the answers summed.

\item[12]  (Argument K12) The user provides the error in the lower limit in
WORK(K12), and the error in the upper limit in WORK(K12$+1)$. Suppose the lower
limit $a$ is a function of several quantities $y_j$. Then WORK(K12) should
be $\Sigma \ |\partial a/\partial y_j|\ E(y_j)$, where E($y_j)$ is the error
in $y_j$. The error in the integral due to error in the limit is the error
in the limit times the integrand evaluated near the limit. WORK(K12$+1)$
should be evaluated similarly for the upper limit. If this option is not
selected, or K12 $=0$, then the limits will be assumed to be exact.
\end{itemize}

\subsubsection{Changing the Selection of Some Options During the Computation%
\label{ChangeSel}}

It is possible to change the selection of options 1, 2, 6, 7, and~9
during the integration. To do this, construct an option vector exactly as
for the initial call to SINT1. Then
$$
\fbox{{\bf CALL SINTOP (IOPT, WORK)}}
$$
IF (IOPT(1) .GT.\ 0) GO TO [Bad IOPT value routine]

This call does not result in any option selections being set to their
default values. Otherwise, the action of each option is as described in
Section B.3.

\subsubsection{Modifications for Double Precision Usage\label{DPuse}}

For double precision usage, change all REAL type statements to DOUBLE
PRECISION and change the prefix of all subroutine names from SINT to
DINT.

\subsection{Examples and Remarks}

See DRSINT1F and ODSINT1F for an example of the use of SINT1 to compute%
\begin{equation*}
\int_0^\pi \sin x\,dx-2=0
\end{equation*}

\subsection{Functional Description}

The integral is estimated using quadrature formulae due to T.  N.  L.
Patterson \cite{Patterson:1968:TOA}.  Patterson described a family of
formulae in which the $ k^{th} $ formula used all the integrand values
used in the $k-1^{st}$ formula, and added $2^{k-1}$ new integrand values
in an optimal way.  The first formula is the midpoint rule, the second is
the three point Gauss formula, and the third is the seven point Kronrod
formula.  Formulae of this family of higher degree had not previously been
described.  This program uses formulae up to $k=8.$

An error estimate is obtained by comparing the values of the integral
estimated by two adjacent formulae, examining differences up to the
fifteenth order, integrating round-off error, integrating error declared to
have been committed during computation of the integrand, integrating a
first order estimate of the effect round-off error in the abscissae has on
integrand values, and including errors in the limits. The latter four
methods are also used to derive a bound on the achievable precision.

If the integral over an interval cannot be estimated with sufficient
accuracy the interval is subdivided. The difference table is used to
discover whether the integral is difficult to compute because the integrand
is too complex or has singular behavior. In the former case, the estimated
error, requested error tolerance, and difference table are used to choose a
step size.

In the latter case, the difference table is used in a search algorithm to
find the abscissa of the singular behavior. If the singular behavior is
discovered on the end of an interval, a change of independent variable is
applied to reduce the strength of the singularity.

The program also uses the difference table to detect nonintegrable
singularities, jump discontinuities, and computational noise.

The extensive test results given in \cite{Krogh:1974:PTR} and
\cite{Krogh:1977:TRQI} suggest that SINT1 is more reliable and requires
fewer function evaluations than seven other generally available single
precision quadrature subprograms, and DINT1 is more reliable and requires
fewer function evaluations than three other generally available double
precision quadrature subprograms.

\bibliography{math77}
\bibliographystyle{math77}

\subsection{Error Procedures and Restrictions}

Error messages are printed using the extended error message processor
described in Chapter~19.3. If an error does not result in a ``stop,'' error
signals are returned to the user by values of the status flag in IOPT(1).\
Printing, when enabled by Option~2, is executed in subroutines SINTO for
single precision and DINTO for double precision. Both of these programs also
use the message processor described in Chapter~19.3. One can change the
action on errors and parameters affecting the output of messages, by calling
the message/error routine MESS before calling this routine.

\subsection{Supporting Information}

\begin{tabular}{@{\bf}l@{\hspace{5pt}}l}
Entry & \hspace{.35in} {\bf Required Files}\vspace{2pt} \\
DINT1 & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, DINT1, DINTA, DINTDL, DINTDU, DINTF, DINTNS, DINTO, DINTOP,
 DINTSM, DMESS, MESS\rule[-5pt]{0pt}{8pt}}\\
DINTA & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, DINTA, DINTDL, DINTDU, DINTF, DINTNS, DINTO, DINTSM, DMESS,
 MESS\rule[-5pt]{0pt}{8pt}}\\
DINTOP & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, DINTOP, MESS\rule[-5pt]{0pt}{8pt}}\\
SINT1 & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, MESS, SINT1, SINTA, SINTDL, SINTDU, SINTF, SINTNS,SINTO, SINTOP,
 SINTSM, SMESS\rule[-5pt]{0pt}{8pt}}\\
SINTA & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, MESS, SINTA, SINTDL, SINTDU, SINTF, SINTNS, SINTO, SINTSM,
 SMESS\rule[-5pt]{0pt}{8pt}}\\
SINTOP & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
      AMACH, MESS, SINTOP\rule[-5pt]{0pt}{8pt}}\\
\end{tabular}

The source language in ANSI Fortran 77.  Common blocks referenced: SINTC
and SINTEC in the single precision versions, and DINTC and DINTEC in the
double precision versions.  SINTC and DINTC are written using several
COMMON statements, for maintenance purposes.  This usage conforms to the
ANSI Fortran-77 standard, but at least one compiler interprets it
improperly.  If you experience inscrutable errors, try re-writing the
COMMON statements for SINTC (or DINTC) into a single statement.

Designed by Fred T.\ Krogh and W.\ Van Snyder, JPL, 1977. Programmed by W.\
Van Snyder, 1977.\\Revised by W. Van Snyder, 1986, 1988.\\
Error/Message handling revised by F. T. Krogh, March~1992.

Two demonstration drivers are shown below, with the output they produced
when run on an IBM PC/AT with an 80287 floating point coprocessor. The first
demonstrates forward communication usage; the second demonstrates reverse
communication usage.

\begcode

\medskip\
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}

\centerline{\bf \large DRSINT1F}\vspace{10pt}
\lstinputlisting{\codeloc{sint1f}}

\vspace{30pt}\centerline{\bf \large ODSINT1F}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{sint1f}}
\newpage

\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}
\centerline{\bf \large DRSINT1R}\vspace{10pt}
\lstinputlisting{\codeloc{sint1r}}

\vspace{10pt}\centerline{\bf \large ODSINT1R}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{sint1r}}
\end{document}


%auto-ignore
\providecommand{\MainFolder}{..}
\documentclass[\MainFolder/Text.tex]{subfiles}

\begin{document}

\section{Consequences for IBL-infinity theory}\label{Section:FuncIBL}

Consider the construction $\dIBL^\MC(\CycC(\cdot))$ on cyclic $\DGA$'s ($=$\,differential Poincar\'e duality algebras) from Section~\ref{Sec:Alg3}. We first need the following technical result.

\begin{Proposition}[Functoriality of $\dIBL^\MC$-construction up to homotopy]\label{Prop:Functorialityo}
Suppose that $V_1$ and~$V_2$ are differential Poincar\'e duality algebras, and let $f: V_1 \rightarrow V_2$ be a $\PDGA$-quasi-isomorphism.
Then there is an $\IBLInfty$-quasi-isomorphism $\HTP: \dIBL(\CycC(V_2)) \rightarrow \dIBL(\CycC(V_1))$ which is also an $\IBLInfty$-quasi-isomorphism $\HTP: \dIBL^\MC(\CycC(V_2)) \rightarrow \dIBL^\MC(\CycC(V_1))$ and satisfies $\HTP_{110} = f^*$.
\end{Proposition}

\begin{proof}
Lemma~\ref{Lem:PomLemma} implies that $f$ is injective, and hence we can consider the case when $V_1\subset V_2$ is a dg-subalgebra and $f=\iota: V_1 \hookrightarrow V_2$ is the inclusion.
In the proof of Lemma~\ref{Eq:LemSmallSub} it was argued that there are Hodge decompositions $V_1 = \Harm \oplus \Dd C_1 \oplus C_1$ and $V_1^\perp = \Dd C_2 \oplus C_2$ such that $V_2 = \Harm \oplus (\Dd C_1 \oplus \Dd C_2) \oplus (C_1 \oplus C_2)$ is a Hodge decomposition of $V$.
Define $\Prpg: V_2 \rightarrow V_2$ by
\[
 \Prpg(\Dd c_2) \coloneqq - c_2\quad\text{for all }c_2\in C_2
\]
and by $0$ on other direct summands.
Let $\pi: V_2 \rightarrow V_1$ be the canonical projection induced by $V_2 = V_1 \oplus V_1^\perp$.
For $v$, $v'\in V_2$, write $v = h + \Dd c_{11} + c_{12} + \Dd c_{21} + c_{22}$, $v'=h' + \Dd c_{11}' + c_{12}' + \Dd c_{21}' + c_{22}'$ for $h$, $h'\in \Harm$, $c_{11}$, $c_{11}'$, $c_{12}$, $c_{12}'\in C_1$, $c_{21}$, $c_{21}'$, $c_{22}$, $c_{22}'\in C_2$ and compute
\begin{align*}
 (\Prpg \circ \Dd + \Dd\circ\Prpg)(v) &= \Prpg(\Dd c_{21}) + \Dd\Prpg(\Dd c_{22}) \\
 & = - c_{21} - \Dd c_{22} \\
 & = (\pi - \Id)(v)
\end{align*}
and
\begin{align*}
	\langle \Prpg v, v' \rangle &= \langle - c_{21},\Dd c_{22}'\rangle \\
	& = (-1)^{\deg c_{21}} \langle \Dd c_{21}, c_{22}' \rangle \\
	& = (-1)^{\deg c_{21} + 1} \langle \Dd c_{21}, \Prpg v' \rangle \\
	& = (-1)^{\deg v} \langle v, \Prpg v' \rangle.
\end{align*}
These are conditions (11.2), resp.~(11.3) from the beginning of \cite[Section~11]{Cieliebak2015}.
We can now apply \cite[Theorem~11.3]{Cieliebak2015} to obtain an $\IBLInfty$-quasi-isomorphism $\HTP: \dIBL(\CycC(V_1)) \rightarrow \dIBL(\CycC(V_2))$ with $\HTP_{110} = \iota^*$.
Because $\iota$ is a morphism of algebras, $\iota^*$ commutes also with the Hochschild differential, i.e., with $\OPQ_{110}^\MC$.
The claim follows because $\dIBL = (\OPQ_{110},\OPQ_{210},\OPQ_{120})$ and $\dIBL^\MC = (\OPQ_{110}^\MC,\OPQ_{210},\OPQ_{120})$.
%is a quasi-isomorphism also with respect to the Hochschild differential $\OPQ_{110}^\MC$. We hope to use the obstruction theory from \cite[Section~3]{Cieliebak2015} to find $\GTP$ or prove that $\HTP_*\MC^{V_1}$ and~$\MC^{V_2}$, where $\MC^{V_i}$ are the canonical Maurer-Cartan elements for $\dIBL(\CycC(V_i))$ for $i=1$, $2$, are gauge equivalent Maurer-Cartan elements. The Homological Perturbation Lemma mentioned in Section~\ref{Sec:HPL} might give an alternative proof in the $\BV$-formalism.
%Note that if $V_2\subset V_1$ is an ideal, then $\pi: V_1 = V_2\oplus V_2^\perp \rightarrow V_2$ is a pairing preserving $\DGA$-quasi-isomorphism which satisfies $\pi^* \OPQ^{V_2}_{210} = \OPQ_{210}^{V_1}(\pi^*\otimes\pi^*)$ and $(\pi^*\otimes \pi^*)\OPQ^{V_2}_{120} = \OPQ_{210}^{V_1}\pi^*$, and hence $\Pi_{110}\coloneqq \pi^*$, $\Pi_{klg}\coloneqq 0$ for $(k,l,g)\neq (1,1,0)$ IS NEVER AN IDEAL OTHERWISE DEGEN
\end{proof}

For any $\PDGA$ $(V,\dd,\wedge,\Or^\H)$ with $\H^0(V)=\R$ and $\H^1(V)=0$, we can pick its Poincar\'e duality model $\Model(V)$ and associate to it the $\dIBL$-algebra $\dIBL^\MC(\CycC(\Model(V)))$. This extends the domain of $\dIBL^\MC(\CycC(\cdot))$ to $\PDGA$'s. However, removing choices requires us to relax the codomain to $\IBLInfty$-homotopy equivalence classes.

\begin{Proposition}[Uniqueness of $\dIBL^\MC$ for $\PDGA$ up to homotopy]\label{Prop:ExteofDFS}
Let $V$ be a $\PDGA$ of degree $n$ with $\H^0(V)=\Span\{1\}$ and $\H^1(V)=0$.
Let $\Model_1$ and $\Model_2$ be two Poincar\'e duality models of $V$.
In addition, suppose that $\Model_1^1 = \Model_2^1 = 0$ if $n\ge 4$ and that $\H^2(V)=0$ if $n\ge 5$.
Then $\dIBL^\MC(\CycC(\Model_1))$ and $\dIBL^\MC(\CycC(\Model_2))$ are $\IBLInfty$-quasi-isomorphic.
\end{Proposition}
\begin{proof}
By Proposition~\ref{Prop:LambrechtUnique}, there is a differential Poincar\'e duality algebra~$V_3$ and $\PDGA$-quasi-isomorphisms $f_1: \Model_1\rightarrow V_3$ and $f_2: \Model_2\rightarrow V_3$.
Proposition~\ref{Prop:Functorialityo} gives $\IBLInfty$-quasi-isomorphisms $\HTP_1: \dIBL^\MC(\CycC(\Model_1)) \rightarrow \dIBL^\MC(\CycC(V_3))$ and $\HTP_2: \dIBL^\MC(\CycC(\Model_2)) \rightarrow \dIBL^\MC(\CycC(V_3))$ extending $f_1^*$ and $f_2^*$, respectively. Application of \cite[Theorem 1.2]{Cieliebak2015} (existence of $\IBLInfty$-homotopy inverses for $\IBLInfty$-quasi-isomorphisms) finishes the proof.
\end{proof}

\begin{Conjecture}\label{Conj:UniqModelFollow}
	The additional assumptions of Proposition~\ref{Prop:ExteofDFS} can be removed.
\end{Conjecture}

If we had the notion of a minimal Poincar\'e duality model $\Model_0(V)$ which is unique in every weak homotopy class of $\PDGA$'s (c.f., Questions~\ref{Q:QuestionsPonc}), we could associate to a weak homotopy equivalence class of a $\PDGA$ $V$ a canonical $\dIBL$-algebra $\dIBL^\MC(\CycC(\Model_0(V)))$ up to an $\IBLInfty$-isomorphism.\footnote{In order to think about functors, we would first have to find a canonical construction of an $\IBLInfty$-morphism induced by a $\PDGA$-morphism of cyclic $\DGA$'s. The construction of \cite[Section~11]{Cieliebak2015} applies only to quasi-isomorphisms, and even if we pick the standard Hodge propagator $\StdPrpg$, it still depends on the choice of the Hodge decomposition. Therefore, the best we can hope for is an assignment of $\PDGA$-morphisms to $\IBLInfty$-homotopy classes of $\IBLInfty$-morphisms.}

\begin{Definition}[$\IBLInfty$-formality]\label{Def:IBLFormality}
We say that a differential Poincar\'e duality algebra $V$ is \emph{$\IBLInfty$-formal} if $\dIBL^\MC(\CycC(V))$ and $\dIBL^\MC(\CycC(\H(V)))$ are weakly $\IBLInfty$-homotopy equivalent.
\end{Definition}

Due to the existence of homotopy inverses of quasi-isomorphisms in the $\IBLInfty$-category, being weakly $\IBLInfty$-homotopy equivalent (the existence of zig-zag of quasi-isomorphisms) is equivalent to being $\IBLInfty$-quasi-isomorphic (the existence of a~direct quasi-isomorphism), which is equivalent to being $\IBLInfty$-homotopy equivalent (the existence of a quasi-isomorphism with a homotopy inverse).

We formulate the following statement as a conjecture although a special case holds by Proposition~\ref{Prop:ExteofDFS}.
The proof might be easier than the proof of Conjecture~\ref{Conj:UniqModelFollow}.

\begin{Conjecture}[Algebraic formality conjecture]\label{Con:DGAIBLForm}
Let $V$ be a $\PDGA$ with $\H^0(V)=\Span\{1\}$ and $\H^1(V)=0$ which is formal as a $\DGA$.
Then any its Poincar\'e duality model $\Model(V)$ is $\IBLInfty$-formal.
\end{Conjecture}
\begin{proof}
By Proposition~\ref{Prop:PoincModelOfFormal}, $\DGA$-formality is equivalent to $\PDGA$-formality. Therefore,~$\H(V)$ is a Poincar\'e duality model of $V$. The rest follows from Conjecture~\ref{Conj:UniqModelFollow}.
\end{proof}

\begin{Remark}[$\IBLInfty$-formality of $V$ and $\CycC(V)$]\label{Rem:Intfor}
Let $\Operad$ be a dg-operad. If $V$ is an $\Operad$-algebra, then $\H(V)$ is an $\Operad$-algebra with zero differential. We say that $V$ is $\Operad$-formal if $V$ and $\H(V)$ are weakly homotopy equivalent as $\Operad$-algebras; i.e., if there is a zig-zag of $\Operad$-quasi-isomorphisms between $V$ and $\H(V)$.

Consider $\DGA$ and $\AInfty$. If a $\DGA$ $V$ is formal, then it is also $\AInfty$-formal because $\DGA$ is a subcategory of $\AInfty$.\footnote{Note that $\AInfty$, similarly as $\IBLInfty$, admits homotopy inverses of quasi-isomorphisms, and hence $\AInfty$-formality is equivalent to the existence of a direct $\AInfty$-quasi-isomorphism $V \rightarrow \H(V)$.} The converse is also true by the rectification procedure (see~\cite{MSE2719961}). Therefore, $\DGA$-formality and $\AInfty$-formality of a $\DGA$ $V$ are equivalent. This should be true for any suitable (pro)perad~$\Operad$ and its quasi-free resolution~$\Operad_\infty$.

In the spirit above, we can speak about $\dIBL$-, resp.~$\IBLInfty$-formality of the $\dIBL$-algebra $\dIBL^\MC(\CycC(V))$ on $\CycC(V)$, which is about the existence of zig-zags of $\dIBL$-, resp.~$\IBLInfty$-quasi-isomorphisms between $\CycC(V)$ and $\H(\CycC(V),\OPQ_{110}^\MC)$. These notions are most likely equivalent as in the case of $\DGA$- and $\AInfty$-formality.

On the other hand, $\IBLInfty$-formality of a differential Poincar\'e duality algebra $V$ from Definition~\ref{Def:IBLFormality} is a different notion because $V$ is not an $\IBLInfty$-algebra.

We conclude that the following three types of ``formalities'' might be interesting:
\begin{enumerate}[label=\arabic*)]
 \item $\DGA$-formality of a $\PDGA$ $V$,
 \item $\IBLInfty$-formality of a $\PDGA$ $V$ (resp.~of its Poincar\'e duality model),
 \item $\IBLInfty$-formality of $\CycC(V)$ as the $\dIBL$-algebra $\dIBL^\MC(\CycC(V))$.
\end{enumerate}
Except for the fact that (1) implies (2), we do not have any other guesses. Notions (1)--(3) should also be interpreted geometrically in the context of the String Topology Conjecture.
\end{Remark}

%In the same way, one can
%\begin{Remark}[$\Operad$-formality]
%We have $\AInfty$-formality for $\nnuCDGA$. Again, weak homotopies of $\AInfty$-algebras is the same as the actual $\AInfty$-homotopies.
%We can also define It is well-known that $\DGA$-formality is equivalent to $\AInfty$-formality which is equivalent to the existence of a direct $\AInfty$-quasi-isomorphism which is equivalent to $\AInfty$-homotopy equivalent.
%\end{Remark}

Let $M$ be a connected oriented closed $n$-manifold with $\HDR^1(M)=0$. We know that $\DR(M)$ is of Hodge type and that a Riemannian metric on $M$ induces a canonical Hodge decomposition $\DR(M) = \Harm \oplus \Im\Dd \oplus \Im\CoDd$, where $\Harm$ is the subspace of harmonic forms and~$\CoDd$ the codifferential. So, in this case, we have a canonical Poincar\'e duality model
$$ \Model(\DR(M)) = \VansQuotient(\VansSmall(\DR(M))). $$
Due to $\HDR^1(M)=0$, it is of finite type and hence finite-dimensional. Therefore, $\dIBL^\MC(\CycC(\Model(\DR(M))))$ is well-defined. Recall that $(\DR,\Dd,\wedge,\int)$ is not of finite type and $\dIBL^\MC(\CycC(\cdot))$ is not well-defined;
%\footnote{Is there perhaps a way to construct $\dIBL^\MC(\CycC(\cdot))$ on differential Poincar\'e duality algebras which are not of finite type but are of Hodge type like $\DR(M)$?}
that was the reason to define the Chern-Simons, aka formal pushforward, Maurer-Cartan element $\PMC$ for $\dIBL(\CycC(\HDR(M)))$ directly as a summation over Feynman integrals. The idea was that $\dIBL^\PMC(\CycC(\HDR(M)))$ is ``homotopy equivalent'' to ``$\dIBL^\MC(\CycC(\DR(M)))$''.

We conjecture the following:

\begin{Conjecture}[Equivalence of algebraic and geometric approach]\label{Conj:SmallSimplCon}
Let $M$ be a connected oriented closed Riemannian $n$-manifold with $\HDR^1(M) = 0$. Then there is an admissible Hodge propagator $\Prpg$ such that if we consider the Chern-Simons Maurer-Cartan element $\PMC$, then the $\IBLInfty$-algebras
$$\dIBL^\PMC(\CycC(\HDR(M)))\quad\text{and}\quad\dIBL^\MC(\CycC(\VansQuotient(\VansSmall(\DR(M))))) $$
are $\IBLInfty$-homotopy equivalent.
\end{Conjecture}
\begin{proof}[Comment on proof]
%The proof might require going into integrals and analytical results from \cite{Cieliebak2018}.
By the vanishing result from Theorem~\ref{IntroThm:B}, we can find $\Prpg$ such that the only non-zero component of $(\PMC_{lg})$ is $\PMC_{10}$.
It satisfies $\PMC_{10} = \sum \pm m_k^+$, where $m_k: \Harm^{\otimes k} \rightarrow \Harm$ are the $\AInfty$-operations obtained by homotopy transfer from $\DR$ (we use the canonical Hodge isomorphism $\HDR\simeq\Harm$).
By lifting the zig-zag of $\PDGA$'s to $\AInfty$, we obtain an $\IBLInfty$-quasi-isomorphism $\GTP: (\VansQuotient(\VansSmall(\DR)),\Dd,\wedge) \rightarrow (\HDR,(m_k))$.
The idea is to show that $\GTP_*\MC$ and $\PMC$, where $\MC$ is the canonical Maurer-Cartan element, are gauge equivalent Maurer-Cartan elements (see \cite[Definition~9.7]{Cieliebak2015}).
For this, it might be useful to describe a path object of the $\IBL$-algebra $\dIBL(\CycC(\HDR))$ (it is a $\dIBL$-algebra), how it arises from the path object of a $\DGA$, and how an overlying Maurer-Cartan element can be constructed from the $\AInfty$-morphism.
\end{proof}

The following is a consequence of Conjecture~\ref{Conj:SmallSimplCon}.
However, we formulate it separately as it might be easier to prove.

\begin{Conjecture}[Formality conjecture for geometric construction]\label{Cor:FormCorollary}
In the situation of Conjecture~\ref{Conj:SmallSimplCon}, suppose that~$M$ is formal. Then $\dIBL^\PMC(\CycC(\HDR(M)))$ is $\IBLInfty$-homotopy equivalent to $\dIBL^\MC(\CycC(\HDR(M)))$.
\end{Conjecture}
\begin{proof}[Comment on proof]
One has to prove the following. If there is an $\AInfty$-isomorphism $(f_i)$ of $(\HDR,\wedge)$ and $(\HDR,\wedge,m_3,\dotsc)$ with $f_1 = \Id$, then $\MC_{10}$ and $\PMC_{10} = \sum \pm \MC_k^+$ are gauge equivalent.
\end{proof}

Together with the String Topology Conjecture~\ref{Conj:StringTopology}, this gives a canonical chain model for the equivariant Chas-Sullivan string topology for formal $M$ with $\HDR^1(M)=0$.

%We see that by considering Poincar\'e duality models, we completely bypass the restriction to Fr\'echet $\dIBL$-algebras on cyclic cochains with smooth Schwarz kernel.
%
%
%\begin{Lemma}\label{Lem:DR}
%Let $f: V_1 \rightarrow V_2$ and $g: V_2 \rightarrow V_1$ be  chain maps of cochain complexes $(V_1,\Dd_1)$ and $(V_2,\Dd_2)$ over $\R$ such that $f$ is a quasi-isomorphism and $f\circ g = \Id$. Then $g \circ f$ is homotopic to $\Id$.
%\end{Lemma}
%\begin{proof}
%We have the decomposition
%\begin{equation}\label{Eq:DecompNM}
%V_1 = g(V_2) \oplus \Ker(f),
%\end{equation}
%where both $g(V_2)$ and $\Ker(f)$ are subcomplexes. Because $f$ is a quasi-isomorphism, a standard argument with the long exact sequence in homology associated to the short exact sequence $0\rightarrow \Ker f \rightarrow V_1 \rightarrow V_2 \rightarrow 0$ implies that $\Ker f$ is an acyclic subcomplex. Therefore, there exists a contraction $h: \Ker(f) \rightarrow \Ker(f)$. Recall that if we write $\Ker f = \Ker\Dd \oplus C$, then the contraction is given by $$ h(z,c):= \bigl(0,\bigl(\Restr{\Dd}{C}\bigr)^{-1}(z))\quad\text{for all }z\in \Ker \Dd, c \in C.  $$
%We extend~$h$ to a linear map $H: V_1 \rightarrow V_1$ by $\Restr{H}{g(V_2)}:= 0$. Using that \eqref{Eq:DecompNM} is a decomposition into subcomplexes, we compute
%$$ \Dd\circ H + H\circ \Dd = \pi_{\Ker(f)} = \Id - \pi_{g(V_2)} = \Id - g\circ f. $$
%This proves the lemma.
%\end{proof}
%\begin{Proposition}\label{Prop:BeerProblem}
%Let $f: V_1 \rightarrow V_2$ be a surjective quasi-isomorphism of cochain complexes $(V_1,\Dd_1)$ and $(V_2,\Dd_2)$ over $\R$. Then $f$ is a deformation retraction, i.e., there is a chain map $g: V_2 \rightarrow V_1$ and a degree $-1$ linear map $h: V_1 \rightarrow V_2$ such that $f\circ g = \Id$ and $\Id - g\circ f = \Dd\circ h + h\circ \Dd$.
%\end{Proposition}
%\begin{proof}
%We have the short exact sequence of cochain complexes
%\begin{equation}\label{Eq:SESInt}
%\begin{tikzcd}
%0 \arrow{r} & \Ker f \arrow[hook]{r}{\iota} & V_1 \arrow[two heads]{r}{f} & V_2 \arrow{r} & 0.
%\end{tikzcd}
%\end{equation}
%Since $\Ker f$ is acyclic, Lemma~\ref{Lem:Pom} gives a chain map $\pi: V_2 \rightarrow \Ker f$ with $\pi\circ \iota = \Id$. We then have $V_1 = \Ker f \oplus \Ker \pi$, and we can define
%$$ g:= \bigl(\Restr{f}{\Ker \pi}\bigr)^{-1} : V_2 \rightarrow V_1. $$
%It is easy to check that $g$ is a chain map and that $f \circ g = \Id$. The proof is finished by Lemma~\ref{Lem:DR}.
%\end{proof}
\end{document}


\documentclass[a4paper,12pt]{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{amsmath,amssymb,amsthm,algorithm,algorithmic,graphicx,yhmath,url,enumitem,lscape}
\usepackage{wrapfig,subfigure}

\newcounter{problem}
\newenvironment{problem}{\refstepcounter{problem} \noindent {\bf Problem \arabic{problem}}}{\vspace{0.5cm}}
\newenvironment{solution}{\vspace{0.3cm} \par \noindent {\bf Solution}}{}
\newenvironment{verification}{\vspace{0.3cm} \par \noindent {\bf Verification}}{}
\newenvironment{hint}{\vspace{0.3cm} \par {\bf Hint:}}{}

\newcounter{remark}
\newenvironment{remark}{\refstepcounter{remark} \vspace{0.3cm} \par \noindent {\bf Remark \arabic{remark}}}{\vspace{0.3cm}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Rn}{\mathbb{R}^n}
\newcommand{\Rnn}{\mathbb{R}^{n \times n}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\eps}{\epsilon}
\newcommand{\fl}{\text{fl}}

\title{Teknisk vetenskabliga ber{\"a}kningar, Fall 2018 \\ Lab Session 7}
\author{Carl Christian Kjelgaard Mikkelsen}

\begin{document}
\maketitle
\tableofcontents
\section{Introduction}

This note contains the list of problems for our lab session
\begin{center}
Wednesday, December 19th, (kl. 13.00-16.00), Room MA416-426.
\end{center}

\section{The problems}

\begin{problem}

    \begin{enumerate} \item Copy script {\tt rode\_mwe1} in {\tt work/l7p1.m} and adapt it to solving the initial value problem
    \bes
    y'(t) = 1 - y(t)^2, \quad y(0) = 0
    \ees
    for $t \in [0,2]$.
  \item For each value of $t$ examine Richardson's fraction. Are they behaving in a manner which is consistint with the existence of an asymptotic error expansion?
  \item Show that $y(t) = \tanh(t)$ is the solution of this initial value problem and include this information in your script.
  \item Is there good agreement between the error estimates and the true error?
  \end{enumerate}
\end{problem}

\begin{remark} The differential equation
  \be
  y'(t) = 1 - y(t)^2
  \ee
  may appear uninteresting. However, if $y$ is a solution, then $v(t) = a y(bt)$ solves the differential equation
  \be
  v'(t) = ab - \frac{b}{a} v(t)^2 = - g + k v(t)^2
  \ee
  provided $a = \sqrt{\frac{g}{k}}$ and $b = \sqrt{gk}$. This is the differential equation which corresponds to a rock falling straight down through a homogeneous atmosphere.
\end{remark}

\begin{problem} {\bf Implementing and testing new method}
  \begin{enumerate}
  \item Study the implementation of {\tt rk.m} and at least one of the dependencies, say, {\tt phi4.m} to the point were you can implement the method
\begin{align}
k_1 &= f(t_j,v_j)\\
k_2 &= f(t_j + \frac{1}{2} h, v_j + \frac{1}{2} h k_1),\\
k_3 &= f(t_j + h, v_j - h k_1 + 2 hk_2), \\
v_{j+1} &= v_j + \frac{1}{6} h \left( k_1 + 4 k_2 + k_3\right).
\end{align}
as {\tt work/psi.m}.
\item Develop a script {\tt work/l7p2.m} which demonstrates that the global error for this method is $O(h^3)$.
\item Compare the error estimates to the exact error for a differential equation where you know the solution. Can you trust the error estimates?
\end{enumerate}

\end{problem}

\begin{problem} {\bf The connection between regular integration and solving ordinary differential equations} Consider the problem of computing the standard normal distribution function, i.e
\be
F(t) = \frac{1}{\sqrt{2 \pi}} \int_{-\infty}^t e^{-\frac{1}{2} x^2} dx
\ee
\begin{enumerate}
\item Show that $t \rightarrow F(t)$ is the unique solution of the initial value problem
\begin{align}
y'(t) &= f(t,y), \\
y(0) &= \frac{1}{2},
\end{align}
where $f : \R \times \R \rightarrow \R$ given by
\be
f(t,y) = \frac{1}{\sqrt{2 \pi}} e^{-\frac{1}{2} t^2},
\ee
is independent of $y$.
\item Develop a script {\tt work/l7p3.m} which computes a table of $t \rightarrow F(t)$ for 21 equidistant points in the interval $[0,2]$. Your relative error must be less that $\tau = 10^{-7}$.
\item This goal can be accomplished using a smallest stepsize of $h=1/640$. Which stepsize did you use?
\end{enumerate}
\end{problem}

\begin{remark} At this point you can compute reliable error estimates. Regardless, the true solution is available in {\tt MATLAB} as {\tt sol=@(t)0.5*(1+erf(t/sqrt(2)))}, where {\tt erf} is {\tt MATLAB}'s implementation of the standard error function.
\end{remark}

\begin{problem} {\bf The SIR model of infectious diseases.} Infectious diseases such Ebola in can modelled using differential equations. In this problem we consider the standard SIR model for a epidemic from which everybody eventually recovers. It has three groups of people, susceptible (S), infected (I), and recovered (R). Susceptible people become infected at a rate which is proportional to the product of their number and the number of infected. Infected people recover at a constant rate and develop natural immunity. The corresponding system of ordinary differential equations is
\begin{align}
S' &= - \alpha I S, \\
I' &=  \alpha I S - \beta I, \\
R' &= \beta I,
\end{align}
where $\alpha, \beta > 0$ are constants which determine the rate of infection/rate of recovery.
\begin{enumerate}
\item Implement a function {\tt work/viral.m} similar to {\tt shell4.m} which models the above system of ordinary differential equations. The call sequence must be
\begin{verbatim}
y=viral(t,x)
\end{verbatim}
where
\begin{enumerate}
\item {\tt t} is a dummy variable which must be present in order for {\tt viral.m} to be compatible with the main program {\tt rk.m}.
\item {\tt x} is a column vector, such that {\tt x(1)} is the fraction of the population which is susceptible, {\tt x(2)} is the fraction of the population which is infected, {\tt x(3)} is the fraction of the population which has recovered and is immune.
\item {\tt y} is a column vector such that {\tt y(i)} is the time derivative of {\tt x(i)}.
\end{enumerate}
\item Develop a script {\tt work/l7p4.m} which simulates an epidemic for which $\alpha = 0.5 \text{ days}^{-1}$ and $\beta = 0.04 \text{ days}^{-1}$. Initially, $99 \%$ of the population is susceptible and $1 \%$ is infected. Track the disease using {\tt rk.m} for $60$ days. Verify, that more than $85 \%$ of the population has recovered by the end of the period.
\item An outbreak is said to be contained if the number of sick people is not increasing. Show that any outbreak will be contained if and only if $S(0) < \frac{\beta}{\alpha}$.
\item Return to example and verify that the number of infected peaked at the time $T$ where $S(T) = \frac{\beta}{\alpha}$. Verify that more than $70 \%$ of the population was ill at the time!
\item The purpose of vaccination is ensure that outbreaks are always contained. If a fraction $z$ of the population is immune to the disease, then the model changes to
\begin{align}
S' &= - \alpha I (1-z) S \\
I' &=  \alpha I (1-z) S - \beta I \\
R' &= \beta I
\end{align}
Change your implementation of {\tt viral} to contain a variable {\tt z} which specifies the fraction of the population which is immune to the disease.
\item (Herd immunity) Show that outbreaks are always contained if and only if $S(0) < \frac{1}{1 - z}\frac{\beta}{\alpha}$.
\item Return to the previous example, but assume that $95\%$ of the population has be vaccinated at birth and track the outbreak for $120$ days. Verify, that the disease can never threatend the fabric of society, because the sick are always so few in number that adequate care can be provide while normal functions continue.
\end{enumerate}
\end{problem}

\end{document}


\section{Codebase}\label{sec:code}
As a baseline we used the libDAI library \cite{Mooij_libDAI_10} which provides an implementation for LBP using the maximal residual updating scheme. With the library, it was simple to implement the recommendation system as proposed in  \cite{Ha:2012:TRT:2396761.2398636}.

\mypar{Code structure}
Figure \ref{overviewflow} shows a high-level overview of the code structure. After an initialization phase the BP algorithm is invoked which loops until a specified maximum number of iterations is reached, the maximum residual becomes zero or the change in the updated messages is smaller than the specified tolerance. In every iteration, \texttt{findMaxResidual} is called to determine the message that should be updated next by \texttt{updateMessage}. The actual update step is simple, because it only assigns \texttt{new\-Message} to message. The costly part of the algorithm is the re-computation of \texttt{newMessage} for all neighbouring nodes that are affected by the change. To do so, \texttt{calcNew\-Message} is called for every candidate, which first computes a product over all incoming messages (see \texttt{calc\-IncomingMessageProduct}) and then marginalizes this product of messages over all other variables (\texttt{margina\-lizeProductOntoMessage}).

%\lstset{basicstyle=\tiny\ttfamily}
%\begin{table}
%\begin{lstlisting}
%init()
%while (not done)
%   messageToUpdate <-- findMaxResidual;
%\end{lstlisting}
%\caption{Pseudo code for Residual BP}
%\end{table}

The methods that get called the most often are \texttt{update\-Residual}, \texttt{calcIncomingMessageProduct} and \linebreak\texttt{marginalizeProductMessage}. Hence, the optimizations will mostly focus on these.

\begin{figure}\centering
    \includegraphics[scale=0.5, trim={6.45cm 0cm 0 1.25cm},clip]{graphics/loopybp-compact.pdf}
  \caption{Flow (top to bottom) of our program. Arrows denote that a methods gets called from an other, BP is the namespace used for all functions that deal with belief propagation.\label{overviewflow}}
\end{figure}


\chapter*{Introduction}   \addcontentsline{toc}{chapter}{Introduction}

The Vienna Computing Library (\ViennaCL) is a scientific computing
library written in C++. It allows simple, high-level access
to the vast computing resources available on parallel architectures such as
GPUs and multi-core CPUs by using either a host-based computing backend, an {\OpenCL} computing backend, or {\CUDA}.
The primary focus is on common linear algebra
operations (BLAS levels 1, 2 and 3) and the solution of large sparse systems of equations by means of iterative
methods. In {\ViennaCLminorversion}, the following iterative solvers are
implemented (confer for example to the book of Y.~Saad \cite{saad-iterative-solution}):
\begin{itemize}
 \item Conjugate Gradient (CG)
 \item Stabilized BiConjugate Gradient (BiCGStab)
 \item Generalized Minimum Residual (GMRES)
\end{itemize}
A number of preconditioners is provided with {\ViennaCLversion} in order to improve convergence of these solvers, cf.~Chap.~\ref{chap:algorithms}.

The solvers and preconditioners can also be used with different
libraries due to their generic implementation. At present, it is possible to
use the solvers and preconditioners directly with types from the {\ublas} library, which is part of
{\Boost} \cite{boost}. The iterative solvers can directly be used with Eigen \cite{eigen} and MTL 4 \cite{mtl4}.

Under the hood, {\ViennaCL} uses a unified layer to access {\CUDA} \cite{nvidiacuda}, {\OpenCL} \cite{khronoscl}, and/or {\OpenMP} \cite{openmp} for accessing and
executing code on compute devices. Therefore, {\ViennaCL} is not tailored
to products from a particular vendor and can be used on many different
platforms. At present, {\ViennaCL} is known to work on all current CPUs and modern GPUs from NVIDIA
and AMD (see Tab.~\ref{tab:double-precision-GPUs}) as well as on CPUs
using either the AMD Accelerated Parallel Processing (APP) SDK (formerly ATI Stream SDK) or the Intel OpenCL SDK.

\NOTE{Double precision arithmetic on GPUs is only possible if it is provided by the GPU. There is no double precision emulation in {\ViennaCL}.}

\NOTE{Double precision arithmetic using the ATI Stream SDK or AMD APP SDK may not be fully
OpenCL-certified. Also, we have observed bugs in AMD APP SDKs 2.7 which effects some algorithms in {\ViennaCL} (e.g.~BiCGStab).}

\begin{table}[tb]
\begin{center}
\begin{tabular}{l|c|c}
Compute Device & float & double \\
\hline
\NVIDIA Geforce 86XX GT/GSO   & ok & - \\
\NVIDIA Geforce 88XX GTX/GTS  & ok & - \\
\NVIDIA Geforce 96XX GT/GSO   & ok & - \\
\NVIDIA Geforce 98XX GTX/GTS  & ok & - \\
\NVIDIA GT 230     & ok & - \\
\NVIDIA GT(S) 240  & ok & - \\
\NVIDIA GTS 250    & ok & - \\
\NVIDIA GTX 260    & ok & ok \\
\NVIDIA GTX 275    & ok & ok \\
\NVIDIA GTX 280    & ok & ok \\
\NVIDIA GTX 285    & ok & ok \\
\NVIDIA GTX 4XX    & ok & ok \\
\NVIDIA GTX 5XX    & ok & ok \\
\NVIDIA GTX 6XX    & ok & ok \\
\NVIDIA Quadro FX 46XX & ok & - \\
\NVIDIA Quadro FX 48XX & ok & ok \\
\NVIDIA Quadro FX 56XX & ok & - \\
\NVIDIA Quadro FX 58XX & ok & ok \\
\NVIDIA Tesla 870    & ok & - \\
\NVIDIA Tesla C10XX  & ok & ok \\
\NVIDIA Tesla C20XX  & ok & ok \\
\hline
ATI Radeon HD 4XXX   & ok & - \\
ATI Radeon HD 48XX   & ok & essentially ok \\
ATI Radeon HD 5XXX   & ok & - \\
ATI Radeon HD 58XX   & ok & essentially ok \\
ATI Radeon HD 59XX   & ok & essentially ok \\
ATI Radeon HD 68XX   & ok & - \\
ATI Radeon HD 69XX   & ok & essentially ok \\
ATI Radeon HD 77XX   & ok & - \\
ATI Radeon HD 78XX   & ok & - \\
ATI Radeon HD 79XX   & ok & essentially ok \\
ATI FireStream V92XX & ok & essentially ok \\
ATI FirePro V78XX    & ok & essentially ok \\
ATI FirePro V87XX    & ok & essentially ok \\
ATI FirePro V88XX    & ok & essentially ok \\
\end{tabular}
\caption{Available arithmetics in {\ViennaCL} provided by selected GPUs. At the
release of {\ViennaCLversion}, the Stream SDK (APP SDK) from AMD/ATI may not comply to
the {\OpenCL} standard for double precision extensions, and we have observed
problems with the APP SDK 2.7 on Linux in both single- and double-precision.}
\label{tab:double-precision-GPUs}
\end{center}
\end{table}