%References:
%\begin{description}
%	\item [Generalities] \cite{piegl}, \cite{Greiner1997a},
%	\item [Parametrization] \cite{Floater2005a}, \cite{Floater2000}
%	\item [Meshless] \cite{Pottmann2003}
%	\item [Interpolation]
%	\item [Geometric-Interpolation] \cite{Xiong2012}
%	\item [Iterative-Interpolation] \cite{Lin2010a, Lin2011, Lin2012}
%	\item [Approximation] \cite{Greiner1996a}, \cite{Juttler1997}, \cite{Liu2008}, \cite{Golitschek90a}
%	\item [Minimal energy surfaces] \cite{Fasshauer1996a}
%	\item [Free-form] \cite{Bo2012}
%	\item [Interproximation] \cite{Wang1997a}, \cite{Conti2001a}, \cite{Pechstein2006a}
%\end{description}

We start this section by recalling some basic properies about B-splines curves and surfaces. We also recall some fundamental algorithms (knot insertion and degree elevation). Later, those algorithms will be used to develop a two grids solver for the Monge-Amp\`ere equation.
\\
For a basic introduction to the subject, we refer to the book \cite{piegl}.

A B-Splines family, $(N_i)_{ 1 \leqslant i \leqslant n}$ of order $k$, can be generated using a non-decreasing sequence of knots $T=(t_i)_{1\leqslant i \leqslant n + k}$.
\begin{definition}[B-Splines series]
The j-th B-Spline of order $k$ is defined by the recurrence relation:
$$
N_j^k = w_j^k N_j^{k-1} + ( 1 - w_{j+1}^k ) N_{j+1}^{k-1}
$$
where,
$$
w_j^k (x) = \frac{x-t_j}{t_{j+k-1}-t_{j}} \hspace{2cm} N_j^1(x) = \chi_{ \left[ t_j, t_{j+1} \right[ }(x)
$$
for $k \geq 1$ and $1 \leq j \leq n$.
\end{definition}
%
%\subsection{B-splines properties}
We note some important properties of a B-splines basis:

\begin{itemize}
\item B-splines are piecewise polynomial of degree $p=k-1$,
\item Compact support; the support of $N_j^k$ is contained in $\left[ t_j, t_{j+k} \right] $,
\item If $x \in~ ] t_j,t_{j+1} [ $, then only the \textit{B-splines} $\{ N_{j-k+1}^k,\cdots,N_{j}^k \}$ are non vanishing at $x$,
\item Positivity: $\forall j \in \{1,\cdots,n \}~~N_j(x) >0, ~~\forall x \in ] t_j, t_{j+k} [ $,
\item Partition of unity : $\sum_{i=1}^n N_i^{k}(x) = 1, \forall x \in \mathbb{R}$,
\item Local linear independence,
\item If a knot $t_i$ has a multiplicity $m_i$ then the B-spline is $\mathcal{C}^{(p-m_i)}$ at $t_i$.
\end{itemize}
%
\begin{definition}[B-Spline curve]
The B-spline curve in $\mathbb{R}^d$ associated to knots vector $T=(t_i)_{1\leqslant i \leqslant n + k}$ and the control polygon $(\mathbf{P}_i)_{ 1 \leqslant i \leqslant n}$ is defined by :
$$
\mathcal{C}(t) = \sum_{i=1}^n N_i^k(t) \textbf{P}_i
$$
\end{definition}
In (Fig. \ref{figBSplineCurve}), we give an example of a quadratic B-Spline curve, and its corresponding knot vector and control points.

\begin{figure}[!ht]
\begin{center}
\begin{tabular}{l l}
\includegraphics[width=9cm,height=9cm]{\RepFigures/courbe_bsplines.png} &
\includegraphics[width=8cm,height=8cm]{\RepFigures/basis_fct_p2_N5.png}
\end{tabular}
\caption{(left) A quadratic B-Spline curve and its control points using the knot vector $T = \{ 000~  \frac{1}{2}~ \frac{3}{4} \frac{3}{4}~ 1 1 1 \}$, (right) the corresponding B-Splines.}
\label{figBSplineCurve}
\end{center}
\end{figure}

%\subsection{B-splines curves properties}
We have the following properties for a \textit{B-spline} curve:
\begin{itemize}
\item If $n=k$, then $\mathcal{C}$ is just a B\'ezier-curve,
\item $\mathcal{C}$ is a piecewise polynomial curve,
\item The curve interpolates its extremas if the associated multiplicity of the first and the last knot are maximum (\textit{i.e.} equal to $k$), \textit{i.e.} open knot vector,
\item Invariance with respect to affine transformations,
\item Strong convex-hull property:

if $t_i \leq t \leq t_{i+1}$, then $\mathcal{C}(t)$ is inside the convex-hull associated to the control points $\mathbf{P}_{i-p},\cdots,\mathbf{P}_{i}$,

\item Local modification : moving the $i^{th}$ control point $\mathbf{P}_{i}$ affects $\mathcal{C}(t)$, only in the interval $[t_i,t_{i+k}]$,
\item The control polygon approaches the behavior of the curve.
\end{itemize}
\begin{remark}
In order to model a singular curve, we can use multiple control points : $\mathbf{P}_{i}=\mathbf{P}_{i+1}$.
\end{remark}

\subsection{Fundamental geometric operations }
By inserting new knots into the knot vector, we add new control points without changing the shape of the B-Spline curve. This can be done using the DeBoor algorithm \cite{DeBoor_Book2001}. We can also elevate the degree of the B-Spline family and keep unchanged the curve \cite{qi}. In (Fig. \ref{refinement_curve_B_Spline}), we apply these algorithms on a quadratic B-Spline curve and we show the position of the new control points.
\\
\paragraph{Knot insertion.}~
\label{subsubsec:knot_insert}
After modification, we denote by $\widetilde{n}, \widetilde{k}, \widetilde{T} $ the new parameters. $(\textbf{Q}_i)$ are the new control points.
\\
One can insert a new knot $t$, where $ t_j \leqslant t < t_{j+1}$. For this purpose we use the DeBoor algorithm \cite{DeBoor_Book2001}:
$$\widetilde{n} = n+1$$
$$\widetilde{k} = k$$
$$ \widetilde{T} = \{ t_1,.., t_j, t, t_{j+1},.., t_{n+k}\}$$
$$
\alpha_i = \left\{\begin{array}{cc}1 & 1 \leqslant i \leqslant j-k+1 \\\frac{t-t_i}{t_{i+k-1}-t_i} & j-k+2 \leqslant i \leqslant j \\0 & j+1 \leqslant i \end{array}\right.
$$
$$
\textbf{Q}_i = \alpha_i \textbf{P}_i + (1-\alpha_i) \textbf{P}_{i-1}
$$
Many other algorithms exist, like blossoming for fast insertion algorithm. For more details about this topic, we refer to \cite{goldman_lyche_book}.
% TODO : inserer figures d'exemple d'insertion de noeuds
%\subsubsection{Order elevation}
%We can elevate the order of the basis, without changing the curve. Several algorithms exist for this purpose. We used the one by Huang et al. \cite{prautzsch,qi}:

\todo{TODO: figure a refaire avec les points de controle affiches}
%
\begin{figure}[!ht]
\begin{center}
\begin{tabular}{cc}
\includegraphics[width=8cm,height=8cm]{\RepFigures/curve} &
\includegraphics[width=8cm,height=8cm]{\RepFigures/curve_p0_n9}
\\
(a) & (b)
\\
\includegraphics[width=8cm,height=8cm]{\RepFigures/curve_p2_n0} &
\includegraphics[width=8cm,height=8cm]{\RepFigures/curve_p0_n3_bezier}
\\
(c) & (d)
\end{tabular}
\caption{(a) A quadratic B-spline curve and its control points. The knot vector is $T = \{ 000, \frac{1}{4}, \frac{1}{2}, \frac{3}{4}, 1 1 1 \}$.
(b) The curve after a h-refinement by inserting the knots $\{ 0.15, 0.35\}$ while the degree is kept equal to $2$.
(c) The curve after a p-refinement, the degree was raised by $1$ (using cubic B-splines).
(d) The curve after duplicating the multiplicity of the internal knots $\{ \frac{1}{4}, \frac{1}{2}, \frac{3}{4} \}$,
this leads to a B\'ezier description. We can then, split the curve into $4$ pieces (sub-domains), each one will corresponds to a quadratic B\'ezier curve.}
\label{refinement_curve_B_Spline}
\end{center}
\end{figure}

\subsection{Deriving a B-spline curve}
\label{subDerivCurve}
The derivative of a B-spline curve is obtained as:
\begin{equation}
\mathcal{C}^{\prime}(t) = \sum_{i=1}^{n} {N_{i}^{k}}^{\prime}(t) \mathbf{P}_i = \sum_{i=1}^{n} \left(\frac{p}{t_{i+p}-t_{i}}N_{i}^{k-1}(t) \mathbf{P}_i - \frac{p}{t_{i+1+p}-t_{i+1}}N_{i+1}^{k-1}(t) \mathbf{P}_i \right)
= \sum_{i=1}^{n-1} {N_{i}^{k-1}}^{\ast}(t) \mathbf{Q}_i
\end{equation}
where $\mathbf{Q}_i = p \frac{\mathbf{P}_{i+1} - \mathbf{P}_i}{t_{i+1+p}-t_{i+1}}$, and $\{{N_{i}^{k-1}}^{\ast},~~1 \leq i \leq n-1\}$ are generated using the knot vector $T^{\ast}$ % = \{ 0\cdots 0, \cdots \cdots, 1\cdots 1 \}$,
which is obtained from $T$ by reducing by one the multiplicity of the first and the last knot (in the case of open knot vector), \textit{i.e.} by removing the first and the last knot.
\\
More generally, by introducing the B-splines family $\{ {N_{i}^{k-j}}^{\ast}, 1 \leq i \leq n-j \}$ generated by the knots vector $T^{j^{\ast}}$ obtained from $T$ by removing the first and the last knot $j$ times, we have the following result:
\begin{proposition} The $j^{th}$ derivative of the curve $\mathcal{C}$ is given by
$$
\mathcal{C}^{(j)}(t) = \sum_{i=1}^{n-j} {N_{i}^{k-j}}^{\ast}(t) \mathbf{P}_i^{(j)}
$$
where, for $j>0$,
$$
\mathbf{P}_i^{(j)} = \frac{p-j+1}{t_{i+p+1}-t_{i+j}} \left( \mathbf{P}_{i+1}^{(j-1)} - \mathbf{P}_i^{(j-1)} \right)
$$
and $\mathbf{P}_i^{(0)} = \mathbf{P}_i$.
\end{proposition}
By denoting $\mathcal{C}^{\prime}$ and $\mathcal{C}^{\prime\prime}$ the first and second derivative of the B-spline curve $\mathcal{C}$, it is easy to show that:
\begin{proposition}
We have,
\begin{itemize}
 \item $\mathcal{C}^{\prime}(0) = \frac{p}{t_{p+2}} \left(\mathbf{P}_{2} - \mathbf{P}_1\right)$,
 \item $\mathcal{C}^{\prime}(1) = \frac{p}{1-t_{n}} \left(\mathbf{P}_{n} - \mathbf{P}_{n-1}\right)$,
 \item $\mathcal{C}^{\prime\prime}(0) = \frac{p(p-1)}{t_{p+2}} \left( \frac{1}{t_{p+2}}\mathbf{P}_{1}
- \{ \frac{1}{t_{p+2}} + \frac{1}{t_{p+3}} \} \mathbf{P}_2 + \frac{1}{t_{p+3}}\mathbf{P}_{3} \right)$,
 \item $\mathcal{C}^{\prime\prime}(1) = \frac{p(p-1)}{1-t_{n}} \left( \frac{1}{1-t_{n}}\mathbf{P}_{n}
- \{ \frac{1}{1-t_{n}} + \frac{1}{1-t_{n-1}} \} \mathbf{P}_{n-1} + \frac{1}{1-t_{n-1}}\mathbf{P}_{n-2} \right)$.
\end{itemize}
\end{proposition}
%TODO diagramme a inserer : mettre accolade pour montrer la multiplicte des noeuds extremaux qui passe a k-1 au lieu de k
\paragraph{Example:}
Let us consider the quadratic B-spline curve associated to the knots vector $T=\{000~\frac{2}{5}~\frac{3}{5}~111 \}$ and the control points $\{ P_i, 1 \leq i \leq 5 \}$:

$$
\mathcal{C}(t) = \sum_{i=1}^{5} {N_{i}^{3}}^{\prime}(t) \mathbf{P}_i
$$
we have,
$$
\mathcal{C}^{\prime}(t) = \sum_{i=1}^{4} {N_{i}^{2}}^{\ast}(t) \mathbf{Q}_i
$$
where
$$
\mathbf{Q}_1 = 5 \{\mathbf{P}_{2} - \mathbf{P}_1\}, ~~~~\mathbf{Q}_2 = \frac{10}{3} \{ \mathbf{P}_{3} - \mathbf{P}_2\},
$$
$$
\mathbf{Q}_3 = \frac{10}{3} \{ \mathbf{P}_{4} - \mathbf{P}_3\},~~~~\mathbf{Q}_4 = 5 \{\mathbf{P}_{5} - \mathbf{P}_4\}.
$$
The \textit{B-splines} $\{ {N_{i}^{2}}^{\ast},~~1 \leq i \leq 4\}$ are associated to the knot vector $T^{\ast}=\{00~\frac{2}{5}~\frac{3}{5}~11 \}$.

\subsection{Intersection of two spline curves}
\todo{TODO}

\subsection{Multivariate tensor product splines}
Let us consider $d$ knot vectors $ \mathcal{T} = \{T^1,T^2,\cdots,T^d\}$. For simplicity, we consider that these knot vectors are open, which means that $k$ knots on each side are duplicated so that the spline is interpolating on the boundary, and of bounds $0$ and $1$. In the sequel we will use the notation $I=[0,1]$.
Each knot vector $T^i$, will generate a basis for a Schoenberg space, $\mathcal{S}_{k_{i}}(T^i,I)$. The tensor product of all these spaces is also a Schoenberg space, namely $\mathcal{S}_{\mathbf{k}}(\mathcal{T})$, where $\mathbf{k}=\{k_1,\cdots,k_d\}$. The cube $\mathcal{P}=I^d=[0,1]^d$, will be referred to as a patch.
\\
The basis for $\mathcal{S}_{\mathbf{k}}(\mathcal{T})$ is defined by a tensor product :
$$
N_{\mathbf{i}}^{\mathbf{k}} := N_{i_1}^{k_1} \otimes N_{i_2}^{k_2} \otimes \cdots \otimes N_{i_d}^{k_d}
$$
where, $\mathbf{i}=\{i_1,\cdots , i_d \}$.
\\
A typical cell from $\mathcal{P}$ is a cube of the form : $Q_{\mathbf{i}}=[\xi_{i_1}, \xi_{i_1+1}] \otimes \cdots \otimes [\xi_{i_d}, \xi_{i_d+1}]$. %To any cell $Q$, we will associate its extension $\widetilde{Q}$, which is the union of the supports of basis functions, that intersects $Q$.


 % PrivateMsg

  \section{Proof of Lemma \ref{lem:recursive}}\label{app:recursive}

  \begin{proof}
    First, to facilitate readability of the proof, we assume that $R = \beta = 1$ with no loss of generality. Our goal is to prove that $V({m}_{t}) \in CC$ if $V_{t+1}({a}_{t} + {y}_{t+1}) \in CC$ for all realizations of ${y}_{t+1}$. The proof proceeds in two steps. First, we show that property CC is preserved through the expectation operator (vertical aggregation), i.e.\ that $\Omega({a}_{t}) = \Ex_t[V_{t+1}({a}_{t} + {y}_{t+1})] \in CC$ if $V_{t+1}({a}_{t} + {y}_{t+1}) \in CC$ for all realizations of ${y}_{t+1}$. Second, we show that property CC is preserved through the value function operator (horizontal aggregation), i.e.\ that $V({m}_{t}) = \max_{s} u(c_t({m}_{t} - s)) + \Omega(s) \in CC$ if $\Omega(s) \in CC$. Throughout the proof, the first order condition holds with equality since no liquidity constraint applies at the end of period $t$.

    \bigskip
    \noindent \textbf{Step 1: Vertical aggregation} \\
    \noindent We show that consumption concavity is preserved under vertical aggregation for three cases of the HARA utility function with $u''' \geq 0$ ($\alpha_1  \geq -1$) and non-increasing absolute prudence ($\alpha_1  \notin (-1,0)$). The three cases are
    \begin{equation}\label{eq:HARAmu}u'(c) = \begin{cases} \left(\alpha_1 c + b\right)^{-1/\alpha_1 } & \alpha_1  \in (0,\infty) \text{ (CRRA)} \\
	e^{-c/b} & \alpha_1  = 0 \text{ (CARA)}\\
	\alpha_1 c + b & \alpha_1  = -1 \text{ (Quadratic)}\end{cases} \end{equation}

    \bigskip
    \noindent \textbf{Case I ($\alpha_1  > 0$, CRRA.)} 	We will show that concavity is preserved under vertical aggregation for $c^{-1/\alpha_1 }$ to avoid clutter, but the results hold for all affine transformations, $\alpha_1 c + b$, with $\alpha_1 >0$. Concavity of $c_{t+1}({a}_{t} + {y}_{t+1})$ implies that
    \begin{equation}c_{t+1}({a}_{t} + {y}_{t+1}) \geq pc_{t+1}({a}_1 + {y}_{t+1}) + (1-p) c_{t+1}({a}_2 + {y}_{t+1}) \label{eq:vert_crra_conc}\end{equation}
    for all ${y}_{t+1} \in [\underline{y},\bar{y}]$ if ${a}_{t} = p{a}_1 + (1-p){a}_2$ with $p \in [0,1]$. Since this holds for all ${y}_{t+1}$, we know that
    \[\left\{\Ex_t\left[c_{t+1}({a}_{t} + {y}_{t+1})^{-\frac{1}{a}}\right]\right\}^{-a} \geq \left\{\Ex_t\left[\left\{pc_{t+1}({a}_1 + {y}_{t+1}) + (1-p) c_{t+1}({a}_2 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1}}\right]\right\}^{-\alpha_1}\]
    We now apply Minkowski's inequality (see e.g.\ \citealp[Theorem 3]{beckenbach1983inequalities}) which says that for $u,v \geq 0$ and a scalar $k < 1\ (k \neq 0)$
    \[\left\{\Ex[(u + v)^{k}]\right\}^{1/k} \geq \left\{\Ex[u^{k}]\right\}^{1/k} + \left\{\Ex[v^{k}]\right\}^{1/k}.\]
    %
    %
    %	\[\left\{\Ex[(u + v)^{-k}]\right\}^{-1/k} \geq \left\{\Ex[u^{-k}]\right\}^{-1/k} + \left\{\Ex[v^{-k}]\right\}^{-1/k}.\]
    This implies that for $\alpha_1  \in (0,\infty)$ (CRRA)
    \[\left\{\Ex[(u + v)^{-\frac{1}{\alpha_1 }}]\right\}^{-\alpha_1 } \geq \left\{\Ex[u^{-\frac{1}{\alpha_1 }}]\right\}^{-\alpha_1 } + \left\{\Ex[v^{-\frac{1}{\alpha_1 }}]\right\}^{-\alpha_1 }\]
    if $u\geq 0$ and $v\geq 0$. Thus
    \begin{align*}
      &\left\{ \Ex_t \left[\left\{pc_{t+1}({a}_1 + {y}_{t+1}) + (1-p) c_{t+1}({a}_2 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1 }}\right]\right\}^{-\alpha_1 } \\ & \geq \left\{ \Ex_t \left[\left\{pc_{t+1}({a}_1 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1 }}\right]\right\}^{-\alpha_1 } + \left\{ \Ex_t \left[\left\{(1-p) c_{t+1}({a}_2 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1 }}\right]\right\}^{-\alpha_1 } \\
      & = p\left\{ \Ex_t \left[\left\{c_{t+1}({a}_1 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1 }}\right]\right\}^{-\alpha_1 } +(1-p) \left\{ \Ex_t \left[\left\{ c_{t+1}({a}_2 + {y}_{t+1})\right\}^{-\frac{1}{\alpha_1 }}\right]\right\}^{-\alpha_1 } \\ & = p(\Omega'({a}_1))^{-\alpha_1 } + (1-p)(\Omega'({a}_2))^{-\alpha_1 }
    \end{align*}
    which implies that
    \[ (\Omega'({a}_{t}))^{-\alpha_1 } \geq p(\Omega'({a}_1))^{-\alpha_1 } + (1-p)(\Omega'({a}_2))^{-\alpha_1 }\]
    Thus, defining
    $\chi_{t}({a}_{t}) = \{\Omega_{t}^{'}({a}_{t})\}^{-\alpha_1 }$, we get
    \begin{align*}
      \chi_{t}({a}_{t}) \geq p \chi_{t}({a}_{1}) + (1-p) \chi_{t}({a}_{2})
    \end{align*}
    for all ${a}_{t}$, where the inequality is strict if $c_{t+1}$ is strictly concave for at least one realization of ${y}_{t+1}$.

    \bigskip

    \noindent \textbf{Case II ($a = 0$, CARA)}. For the exponential case, property CC holds at ${a}_{t}$ if
    \begin{eqnarray*}
      \exp(-\chi_{t}({a}_{t})/b) & = & \Ex_{t}[ \exp(-c_{t+1}({a}_{t}+{y}_{t+1})/b)]
    \end{eqnarray*}
    for some $\chi_{t}({a}_{t})$ which is strictly concave at ${a}_{t}$. We set $b = 1$ to reduce clutter, but results hold for $b \neq 1$. Consider first a case where $c_{t+1}$ is linear over the range of possible values of ${a}_{t}+{y}_{t+1}$, then
    \begin{eqnarray}
      \chi_{t}({a}_{t}) & = & -\log \Ex_{t}[e^{-c_{t+1}({a}_{t}+{y}_{t+1})}] \nonumber
      \\& = & -\log \Ex_{t}[e^{-(c_{t+1}({a}_{t}+\bar{y})+({y}_{t+1}-\bar{y})c_{t+1}^{'})}] \nonumber
      \\ & = & c_{t+1}({a}_{t}+\bar{y}) - \log \Ex_{t}[e^{-({y}_{t+1}-\bar{y}) c_{t+1}^{'}}] \label{eq:expcdrops}
    \end{eqnarray}
    which is linear in ${a}_{t}$ since the second term is a constant.

    Now consider a value of ${a}_{t}$ for which $c_{t+1}({a}_{t}+{y}_{t+1})$ is strictly concave for at least one realization of ${y}_{t+1}$. Global weak concavity of $c_{t+1}$ tells us that for every ${y}_{t+1}$
    \begin{eqnarray}
      -c_{t+1}({a}_{t}+{y}_{t+1}) & \leq & -((1-p)c_{t+1}({a}_1+{y}_{t+1})+pc_{t+1}({a}_{2}+{y}_{t+1})) \nonumber
      \\ \Ex_{t}[e^{-c_{t+1}({a}_{t}+{y}_{t+1})}] & \leq & \Ex_{t}[e^{-((1-p)c_{t+1}({a}_1+{y}_{t+1})+pc_{t+1}({a}_{2}+{y}_{t+1}))}]. \label{eq:expconc}
    \end{eqnarray}

    Meanwhile, the arithmetic-geometric mean inequality states that for positive $u$ and $v$, if $\bar u = \Ex_t [ u]$ and $\bar v = \Ex_t [ v]$, then
    \begin{equation*}
      \Ex_t\left[( u/\bar u)^p ( v/\bar v)^{1-p}\right]
      \leq \Ex_t \left[p ( u/\bar u)+(1-p)( v/\bar v)\right] = 1,
    \end{equation*}
    implying that
    \begin{equation*}
      \Ex_t [ u^p  v^{1-p}] \leq \bar u^p \bar v^{1-p},
    \end{equation*}
    where the expression holds with equality only if $v$ is proportional to $u$.  Substituting in $u= e^{-c_{t+1}({a}_1 + {y}_{t+1})}$ and $v = e^{-c_{t+1}({a}_2 + {y}_{t+1})}$, this means that
    \begin{eqnarray*}
      \Ex_t [e^{-p c_{t+1}({a}_1 + {y}_{t+1}) - (1-p)c_{t+1}({a}_2 + {y}_{t+1})}] & \leq &
                                                                                \left\{ \Ex_t  [e^{- c_{t+1}({a}_1 + {y}_{t+1})} ] \right\}^p \left\{ \Ex_t  [e^{- c_{t+1}({a}_2 + {y}_{t+1})} ] \right\}^{1-p}
    \end{eqnarray*}
    and we can substitute for the LHS from \eqref{eq:expconc}, obtaining
    \begin{eqnarray}
      \Ex_{t}[e^{-c_{t+1}({a}_{t}+{y}_{t+1})}] & \leq &
                                                        \left\{ \Ex_t  [e^{- c_{t+1}({a}_1 + {y}_{t+1})} ] \right\}^p 	\left\{ \Ex_t  [e^{- c_{t+1}({a}_2 + {y}_{t+1})} ] \right\}^{1-p} \nonumber
      \\
      \log \Ex_{t}[e^{-c_{t+1}({a}_{t}+{y}_{t+1})}] &\leq &
                                                            p \log \Ex_t  [e^{-c_{t+1}({a}_1 + {y}_{t+1})} ]
                                                            + (1-p) \log \Ex_t  [e^{-c_{t+1}({a}_2 + {y}_{t+1})} ]  \label{eq:expineq2}
    \end{eqnarray}
    which holds with equality only when $e^{-c_{t+1}({a}_{1}+{y}_{t+1})}/e^{-c_{t+1}({a}_{2}+{y}_{t+1})}$ is a constant. This will only happen if 	$c_{t+1}({a}_{1}+{y}_{t+1})-c_{t+1}({a}_{2}+{y}_{t+1})$ is constant, which (given that the MPC is strictly positive everywhere) requires 	$c_{t+1}({a}_{t}+{y}_{t+1})$ to be linear for ${y}_{t+1} \in (\underline{y},\bar{y})$. Hence,
    \begin{eqnarray*}
      \chi_{t}({a}_{t}) & \geq & p \chi_{t}({a}_{1}) + (1-p) \chi_{t}({a}_{2}).
    \end{eqnarray*}
    where the inequality is strict for an ${a}_{t}$ from which $c_{t+1}$ is strictly concave for some realization of ${y}_{t+1}$.

    \bigskip

    \noindent \textbf{Case III ($a = -1$, Quadratic)}.
    In the quadratic case, linearity of marginal utility implies that
    \begin{eqnarray*}
      u'(\chi_{t}({a}_{t})) & = & \Ex_{t}[u'(c_{t+1}({a}_{t}+{y}_{t+1}))]
      \\   \chi_{t}({a}_{t}) & = & \Ex_{t}[c_{t+1}({a}_{t}+{y}_{t+1})]
    \end{eqnarray*}
    so $\chi_{t}$ is simply the weighted sum of a set of
    concave functions where the weights correspond to the probabilities of the various possible outcomes for ${y}_{t+1}$. The sum of concave functions is itself concave. And if additionally the consumption function is strictly concave at any point, the weighted sum is also strictly concave.

    \bigskip
    \noindent \textbf{Step 2: Horizontal aggregation:} \\
    We now proceed with horizontal aggregation, namely how concavity is preserved through the value function operation. Assume that $\Omega_t({a}_{t}) \in CC$ at point ${a}_{t}$, then the first order condition implies that
    \[\Omega_t'({a}_{t}) = u'(\chi_t({a}_{t}))\]
    for some monotonically increasing $\chi_t({a}_{t})$ that satisfies
    \begin{align}
      \chi_t(p{a}_1 + (1-p){a}_2) \geq p\chi_t({a}_1) + (1-p)\chi_t({a}_2) \label{eq:hor_conc}
    \end{align}
    for any $0 < p < 1$, and ${a}_1 < {a}_{t} < {a}_2$. % ($|{a}_2 - {a}_1|< \delta$ for any $\delta > 0$).

    In addition, we know that the first order condition holds with equality such that $\Omega_t'({a}_{t}) = u'(c_t({m}_{t})) = u'(\chi_t({a}_{t}))$ which implies that ${a}_{t} = \chi_t^{-1}(c_t)$. Using this equation, we get
    \begin{align*}
      \chi_t(p{a}_1 + (1-p){a}_2) &\geq p\chi_t({a}_1) + (1-p)\chi_t({a}_2) \\
      p{a}_1 + (1-p){a}_2 &\geq \chi_t^{-1}(p\chi_t({a}_1) + (1-p)\chi_t({a}_2)) \\
      p\chi_t^{-1}(c_1) + (1-p)\chi_t^{-1}(c_2) &\geq \chi_t^{-1}(pc_1 + (1-p)c_2)
    \end{align*}
    which implies that $\chi_t^{-1}$ is a convex function.

    Use the budget constraint to define
    \begin{align*}
      {m}_{t} &= {a}_{t} + c_t \\
      \wAlt(c_t) & = \chi^{-1}(c_t) + c_t
    \end{align*}
    Now, since $\chi_t^{-1}$ is a convex function, and $\wAlt(c_t)$ is the sum of a convex and a linear function, it is also a convex function satisfying
    \begin{align}
      p\wAlt(c_1) + (1-p)\wAlt(c_2) &\geq \wAlt(pc_1 + (1-p)c_2) \nonumber \\
      \wAlt^{-1}(p\wAlt(c_1) + (1-p)\wAlt(c_2)) &\geq pc_1 + (1-p)c_2 \nonumber \\
      c(p{m}_1 + (1-p){m}_2) &\geq pc({m}_1) + (1-p)c({m}_2) \label{eq:hor_conc2}
    \end{align}
    so $c$ is concave.

    Note that the proof of horizontal aggregation works for any utility function with $u' > 0$ and $u'' < 0$ when $R$ = $\beta$ = 1. However, for the more general case where $R$ or $\beta$ are not equal to one, we need the HARA property that multiplying $u'$ by a constant corresponds to a linear transformation of $c$.

    \bigskip
    \noindent \textbf{Strict Consumption Concavity.}
    When $V_{t+1}({m}_{t+1})$ exhibits the property strict CC for at least one ${m}_{t+1} \in [R{a}_{t} + \underline{y}, R{a}_{t} + \bar{y}]$, we know that $\chi_t({a}_{t})$ also exhibits the property strict CC from the proof of vertical aggregation. Then, equation \eqref{eq:hor_conc} holds with strict inequality, and this strict inequality goes through the proof of horizontal aggregation, implying that equation \eqref{eq:hor_conc2} holds with strict inequality. Hence, $c_t({m}_{t})$ is strictly concave if $c_{t+1}({a}_{t} + {y}_{t+1})$ is concave for all realizations of ${y}_{t+1}$ and strictly concave for at least one realization of ${y}_{t+1}$.
  \end{proof}

  \section{Proof of Lemma \ref{lem:counterclockwise}} \label{app:counterclockwise}
  \begin{proof} First, condition 2 and 4 in Definition \ref{defn:cconcavification} imply that $\hat{c}'({m}) > c'({m})$ for ${m} = {m}^{\#} - \epsilon$ for a small $\epsilon > 0$. Condition 3 then ensures that $\lim_{\mu \uparrow {m}} \hat{c}'(\mu) > \lim_{\mu \uparrow {m}} c'(\mu)$ holds for all ${m} \leq {m}^{\#}-\epsilon$ (equivalently ${m} < {m}^{\#}$). Second, condition 1 and the fact that $\lim_{\mu \uparrow {m}} \hat{c}'(\mu) > \lim_{\mu \uparrow {m}} c'(\mu)$ for ${m} < {m}^{\#}$ implies that $\lim_{\mu \uparrow {m}} \hat{c}(\mu) < \lim_{\mu \uparrow {m}}c(\mu)$ for ${m} < {m}^{\#}$. Third, condition 3 in Definition \ref{defn:cconcavification} implies that $$\lim_{\mu \uparrow {m}}\hat{c}''(\mu) \leq \lim_{\mu \uparrow {m}} c''(\mu)\frac{\hat{c}'(\mu)}{c'(\mu)}$$ for ${m} < {m}^{\#}$. Then $$\lim_{\mu \uparrow {m}} \hat{c}''(\mu) \leq \lim_{\mu \uparrow {m}} c''(\mu)$$ since $\lim_{\mu \uparrow {m}}\hat{c}'(\mu) > \lim_{\mu \uparrow {m}} c'(\mu)$ for ${m} < {m}^{\#}$. Note that the inequality is not strict since $c''(\mu)$ could be 0.
  \end{proof}

  \section{Proof of Lemma \ref{lem:CCToPrud}} \label{app:CCToPrud}
  \begin{proof}
    By the envelope theorem, we know that
    \[ V'({m}) = u'(c({m}))\]
    Differentiating with respect to ${m}$ yields
    \begin{equation}\label{eq:diff2}
      V''({m}) = u''(c({m}))c'({m})
    \end{equation}
    Since $c({m})$ is concave, it has left-hand and right-hand derivatives at every point, though the left-hand and right-hand derivatives may not be equal. Equation \eqref{eq:diff2} should be interpreted as applying the left-hand and right-hand derivatives separately. (Reading \eqref{eq:diff2} in this way implies that $c'({m}^-) \geq c'({m}^+)$; therefore $V''({m}^-) \leq V''({m}^+)$). Taking another derivative can run afoul of the possible discontinuity in $c'({m})$ that we will show below can arise from liquidity constraints. We therefore consider two cases: (i) $c''({m})$ exists and (ii) $c''({m})$ does not exist.

    \bigskip
    \noindent \textbf{\textit{Case I:}} ($c''({m})$ exists.)\\
    In the case where $c''({m})$ exists, we can take another derivative
    \[V'''({m}) = u'''(c({m}))[c'({m})]^2 + u''(c({m}))c''({m})\]
    Absolute prudence of the value function is thus defined as
    \begin{align}-\frac{V'''({m})}{V''({m})} &= -\frac{u'''(c({m}))[c'({m})]^2 + u''(c({m}))c''({m})}{u''(c({m}))c'({m})} \nonumber \\
      -\frac{V'''({m})}{V''({m})} &= -\frac{u'''(c({m}))}{u''(c({m}))}c'({m}) - \frac{c''({m})}{c'({m})}\label{eq:absprudence}\end{align}
    From the assumption that $\hat{c}({m})$ is a counterclockwise concavification of $c({m})$, we know from Lemma \ref{lem:counterclockwise} that  $\hat{c}({m}) \leq c({m})$ and $\hat{c}'({m}) \geq c'({m})$. Furthermore, since $-\frac{u'''(c({m}))}{u''(c({m}))}$ is non-increasing, we know that $-\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))} \geq -\frac{u'''(c({m}))}{u''(c({m}))}$. As a result, $-\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))}\hat{c}'({m}) \geq -\frac{u'''(c({m}))}{u''(c({m}))}c'({m})$.

    The second part of the absolute prudence expression, $-\frac{c''({m})}{c'({m})}$, is a measure of the curvature of the consumption function. Since the consumption function is concave, $-\frac{c''({m})}{c'({m})}$ is a measure of the degree of concavity. Formally, if one has two functions, $f(x)$ and $g(x)$, that are both increasing and concave functions, then the concave transformation $g(f(x))$ always has more curvature than $f$.\footnote{To see this, compute \[-\frac{\frac{d^2}{dx^2} g(f(x))}{\frac{d}{dx}g(f(x))} = - \frac{g''f'}{g'} - \frac{f''}{f'} \geq - \frac{f''}{f'}\] where the inequality holds since $f' \geq 0$, $g' \geq 0$, and $g'' \leq 0$.} A counterclockwise concavification is an example of such a $g$. Hence, $-\frac{\hat{c}''({m})}{\hat{c}'({m})} \geq -\frac{c''({m})}{c'({m})}$. Then
    \begin{align*}
      -\frac{\hat{V}'''({m})}{\hat{V}''({m})} &= -\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))}\hat{c}'({m}) - \frac{\hat{c}''({m})}{\hat{c}'({m})} \\
                                              &\geq -\frac{u'''(c({m}))}{u''(c({m}))}c'({m}) - \frac{c''({m})}{c'({m})} = -\frac{V'''({m})}{V''({m})}
    \end{align*}

    \bigskip

    \noindent \textbf{\textit{Case II:}} ($c''({m})$ does not exist.)\\
    Informally, if nonexistence is caused by a constraint binding at ${m}$, the effect will be a discrete decline in the marginal propensity to consume at ${m}$, which can be thought of as $c''({m}) = -\infty$, implying positive infinite prudence at that point (see \eqref{eq:absprudence}). Formally, if $c''({m})$ does not exist, greater prudence of $\hat{V}$ than $V$ is given by $\frac{\hat{V}''({m})}{V''({m})}$ being a decreasing function of ${m}$. This is defined as
    \[\frac{\hat{V}''({m})}{V''({m})} \equiv
      \left(\frac{u''(\hat c({m}))}{u''(c({m}))} \right)
      \left(\frac{\hat{c}'({m})}{c'({m})}\right)\]
    The second factor, $\frac{\hat{c}'({m})}{c'({m})}$, is weakly decreasing in ${m}$ by the property of a counterclockwise concavification. At any specific value of ${m}$ where
    $\hat{c}''({m})$ does not exist because the left and right hand
    values of $\hat{c}'$ are different, we say that $\hat{c}'$
    is decreasing if
    \begin{eqnarray}
      \lim_{{m}^{-} \rightarrow {m}} \hat{c}'({m}) & > & \lim_{{m}^{+} \rightarrow {m}} \hat{c}'({m}).
    \end{eqnarray}

    As for the first factor, note that nonexistence of 	$\hat{V}'''({m})$ and/or $\hat{c}''({m})$ do not spring from nonexistence of either $u'''(c)$ or $\lim_{{m} \uparrow {m}} \hat{c}'({m})$ (for our purposes, when the left and right derivatives of $\hat{c}({m})$ differ at a point, the relevant derivative is the one coming from the left; rather than carry around the cumbersome limit notation, read the following derivation as applying to the left derivative).  To discover whether $\frac{\hat {V}''({m})}{V''({m})}$ is decreasing we differentiate $\log\left(\frac{u''(\hat{c}({m}))}{ u''(c({m}))}\right)$ (recall that the log is a monotonically decreasing transformation so the derivative of the log of a function always has the same sign as the derivative of the function):
    \begin{align*}
      \frac{d}{d {m}}\left( \log(u''(\hat{c}({m})) - \log(u''(c({m})))\right) = \frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))}\hat{c}'({m}) -  \frac{u'''(c({m}))}{u''(c({m}))}c'({m}).
    \end{align*}
    This will be negative if
    \begin{align}
      \frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))}\hat{c}'({m}) & \leq  \frac{u'''(c({m}))}{u''(c({m}))}c'({m}) \nonumber
      \\ \Rightarrow  -\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))}\hat{c}'({m}) & \geq  -\frac{u'''(c({m}))}{u''(c({m}))} c'({m}) \label{eq:prudcond} .
    \end{align}

    Recall from Lemma \ref{lem:counterclockwise} that $\hat{c}'({m}) \geq c'({m})$ and $\hat{c}({m}) \leq c({m})$ so non-increasing absolute prudence of the utility function ensures that $-\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m}))} \geq  -\frac{u'''(c({m}))}{u''(c({m}))}$. Hence the LHS is always greater or equal to the RHS of equation \eqref{eq:prudcond}.

  \end{proof}

  \section{Proof of Lemma \ref{lem:ccandstrictprud}} \label{app:ccandstrictprud}
  \begin{proof}
    We prove each statement in Lemma \ref{lem:ccandstrictprud} separately.

    \bigskip

    \noindent \textbf{\textit{Case I:}} ($ u ''' > 0$.) \\
    If $u''' > 0$, a counterclockwise concavification around ${m}^{\#}$ implies that $\hat{c}({m}) < c({m})$ and $\hat{c}'({m}) > c'({m})$ for all ${m} < {m}^{\#}$. Then \[-\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m})}\hat{c}'({m}) > -\frac{u'''({c}({m}))}{u''({c}({m}))}{c}'({m}) \text{ for } {m} < {m}^{\#} \]
    Note that this condition is sufficient to prove Lemma \ref{lem:ccandstrictprud} for the case where $c''({m})$ does not exist since it then satisfies \eqref{eq:prudcond}. In the case where $c''({m})$ does exist, we know that
    \[-\frac{\hat{c}''({m})}{\hat{c}'({m})} \geq -\frac{{c}''({m})}{{c}'({m})} \text{ for } {m} < {m}^{\#}\]
    from the proof of Lemma \ref{lem:CCToPrud}. Hence,
    \begin{align*}- \frac{\hat{V}'''({m})}{\hat{V}''({m})} &= -\frac{u'''(\hat{c}({m}))}{u''(\hat{c}({m})}\hat{c}'({m}) - \frac{\hat{c}''({m})}{\hat{c}'({m})}
      \\
                                                           & > -\frac{u'''({c}({m}))}{u''({c}({m}))}{c}'({m}) - \frac{{c}''({m})}{{c}'({m})} = - \frac{{V}'''({m})}{{V}''({m})} \text{ for } {m} < {m}^{\#}
    \end{align*}
    and Lemma \ref{lem:ccandstrictprud} holds in the case with $u''' > 0$ and ${m} < {m}^{\#}$.

    \bigskip

    \noindent \textbf{\textit{Case II:}} ($u''' = 0$.) \\
    The quadratic case requires a different approach. Note first that the conditions in Lemma \ref{lem:ccandstrictprud} hold only below the bliss point for quadratic utility. In addition, since $u'''(\cdot) = 0$, strict inequality between the prudence of $\hat{V}$ and the prudence of $V$ hold only at those points where $\hat{c}(\cdot)$ is strictly concave.

    Recall from the proof of Lemma \ref{lem:CCToPrud} that greater prudence of $\hat{V}({m})$ than $V({m})$ occurs if  $\frac{\hat{V}''({m})}{V''({m})}$ is decreasing in ${m}$. In the quadratic case
    \begin{equation}
      \frac{\hat{V}''({m})}{V''({m})} = \frac{u''(\hat{c}({m}))}{u''(c({m}))} \frac{\hat{c}'({m})}{c'({m})} = \frac{\hat{c}'({m})}{c'({m})}
    \end{equation}
    where the second equality follows since $u''(\cdot)$ is constant with quadratic utility. Thus, prudence is strictly greater in the modified case only if $ \frac{\hat{c}'({m})}{c'({m})}$ strictly declines in ${m}$.
  \end{proof}

  \section{Proof of Lemma \ref{lem:LcAndCc}}\label{app:pfclc}
  We prove Lemma \ref{lem:LcAndCc} by induction in two steps. First, we show that all results in Lemma \ref{lem:LcAndCc} hold when we add the first constraint. The second step is then to show that the results hold when we go from $n$ to $n+1$ constraints.

  \begin{lemma}\textit{$(c_{t}' < c_{t+1}')$} \\
    Consider an agent who has a utility function with $u' > 0$ and $u'' < 0$, faces constant income, is impatient ($\beta R < 1$), and has a finite life. Then $c_{t}' < c_{t+1}'$.
  \end{lemma}

  \begin{proof}
    The marginal propensity to consume in period $t$ can be obtained from the MPC in period $t+1$ from the Euler equation
    \begin{eqnarray*}
      u'(c_{t}({m}_{t})) & =  & \beta R u'(c_{t+1}(R({m}_{t}-c_{t}({m}_{t}))+{y})).
    \end{eqnarray*}
    Differentiating both sides with respect to ${m}_{t}$ and omitting arguments to reduce
    clutter we obtain
    \begin{eqnarray*}
      u^{\prime\prime}(c_{t})c_{t}^{\prime} & =  & \beta R u^{\prime\prime}(c_{t+1})c_{t+1}^{\prime}R(1-c_{t}^{\prime}) \nonumber
      \\ \nonumber (u^{\prime\prime}(c_{t}) + \beta R u^{\prime\prime}(c_{t+1})c_{t+1}^{\prime}R)c_{t}^{\prime} & = & \beta R u^{\prime\prime}(c_{t+1})Rc_{t+1}^{\prime}
      \\ \frac{c_{t+1}^{\prime}}{c_{t}^{\prime}}   & = & \frac{u^{\prime\prime}(c_{t}) + \beta R u^{\prime\prime}(c_{t+1})c_{t+1}^{\prime}R}{\beta R u^{\prime\prime}(c_{t+1})R} \label{eq:mpcPF} \\
      \frac{c_{t+1}^{\prime}}{c_{t}^{\prime}}   & = & \frac{u^{\prime\prime}(c_{t})}{\beta R u^{\prime\prime}(c_{t+1})R} + c_{t+1}^{\prime} %\\ \frac{c_{t+1}^{\prime}}{c_{t}^{\prime}} & > &  1
    \end{eqnarray*}
    Since $\beta R < 1$ ensures that $c_{t} > c_{t+1}$, we know that
    \[\frac{u^{\prime\prime}(c_{t})}{\beta R u^{\prime\prime}(c_{t+1})R} \geq  \frac{u^{\prime\prime}(c_{t+1})}{\beta R u^{\prime\prime}(c_{t+1})R} = \frac{1}{\beta R R} > \frac{1}{R}\]
    Furthermore, we know that
    \[c_{t}^{\prime} \geq \frac{R-1}{R}\]
    since $\frac{R-1}{R}$ is the MPC for an infinitely-lived agent with $\beta R = 1$. Hence,
    \[\frac{c_{t+1}^{\prime}}{c_{t}^{\prime}} = \left(\frac{u^{\prime\prime}(c_{t})}{\beta R u^{\prime\prime}(c_{t+1})R} + c_{t}^{\prime} \right) > \frac{1}{R} + \frac{R-1}{R} = 1\]
    and it follows that $c_{t}^{\prime} <  c_{t+1}^{\prime}$.
  \end{proof}

  \begin{lemma}\label{lem:pfclc}(Consumption with one Liquidity Constraint.) \\
    Consider an agent who has a utility function with $u'> 0 $ and $u'' < 0$, faces constant income, ${y}$, and is impatient, $\beta R < 1$. Assume that the agent faces a set $\mathcal{T}$ of one relevant constraint. Then $c_{t,1}({m})$ is a counterclockwise concavification of $c_{t,0}({m})$ around $\wAlt_{t,1}$.
  \end{lemma}

  \begin{proof}
    We now prove Lemma \ref{lem:pfclc} by first showing that the consumption function including the constraint at the end of period $\tau$ is a counterclockwise concavification of the unconstrained consumption function in period $\tau$. Next, we show how the constraint further implies that the consumption function including the constraint is a counterclockwise concavification of the unconstrained consumption function in periods prior to $\tau$.

    We first define $\tau = \mathcal{T}[1]$ as the time period of the constraint. Note first that consumption is unaffected by the constraint for all periods after $\tau$, i.e. $c_{\tau+k,1}=c_{\tau+k,0}$ for any $k > 0$. For period $\tau$, we can calculate the level of consumption at which the constraint binds by realizing that a consumer for whom the constraint binds will save nothing and therefore arrive in the next period with no wealth. Further, the maximum amount of consumption at which the constraint binds will satisfy the Euler equation (only points where the constraint is strictly binding violate the Euler equation; the point on the cusp does not). Thus, we define $c_{\tau,1}^{\#}$ as the maximum level of consumption in period $\tau$ at which the agent leaves no wealth for the next period, i.e.\ the constraint stops binding:
    \begin{eqnarray*}
      \label{eq:ctau1}
      u'(c_{\tau,1}^{\#})   & = & \beta R u'(c_{\tau+1,0}({y}))
      \\   c_{\tau,1}^{\#}       & = & (u')^{-1}\left(\beta R u'(c_{\tau+1,0}({y}))\right),
    \end{eqnarray*}
    and the level of wealth at which the constraint stops binding can be obtained from
    \begin{eqnarray}
      \label{eq:omegaFromc}
      \wAlt_{\tau,1} & = & \left(V'_{\tau,1}\right)^{-1}(u'(c_{\tau,1}^{\#}))  .
    \end{eqnarray}

    Below this level of wealth, we have $c_{\tau,1}({m}) = {m}$ so the MPC is one, while above it we have $c_{\tau,1}({m}) = c_{\tau,0}({m})$ where the MPC equals the constant MPC for an unconstrained perfect foresight optimization problem with a horizon of $T-\tau$. Thus, $c_{\tau,1}$ satisfies our definition of a counterclockwise concavification of $c_{\tau,0}$ around $\wAlt_{\tau,1}$.

    Further, we can obtain the value of period $\tau-1$ consumption at which the period $\tau$ constraint stops impinging on period $\tau-1$ behavior from
    \begin{eqnarray*}
      u'(c_{\tau-1,1}^{\#})   & = & \beta R u'(c_{\tau,1}^{\#}) \label{eq:ctaum1}
    \end{eqnarray*}
    and we can obtain $\wAlt_{\tau-1,1}$ via the analogue to \eqref{eq:omegaFromc}. Iteration generates the remaining $c_{.,1}^{\#}$ and $\wAlt_{.,1}$ values back to period $t$.

    Now consider the behavior of a consumer in period $\tau-1$ with a level of wealth ${m}<\wAlt_{\tau-1,1}$.  This consumer knows he will be constrained and will spend all of his resources next period, so at ${m}$ his behavior will be identical to the behavior of a consumer whose entire horizon ends at time $\tau$.  As shown in step I, the MPC always declines with horizon. The MPC for this consumer is therefore strictly greater than the MPC of the unconstrained consumer whose horizon ends at $T > \tau$.  Thus, in each period before $\tau+1$, the consumption function $c_{.,1}$ generated by imposition of the constraint constitutes a counterclockwise concavification of the unconstrained consumption function around the kink point $\wAlt_{.,1}$.
  \end{proof}

  We have now shown the results in Lemma \ref{lem:LcAndCc} for $n = 0$. The last step is to show that they also hold for $n+1$ when they hold strictly for $n$. Consider imposing the $n+1$'st constraint and suppose for concreteness that it applies at the end of period $\tau$. It will stop binding at a level of consumption defined by
  $$u'(c_{\tau,n+1}^{\#}) = \beta R u'(c_{\tau+1,n}({y})) = \beta Ru'(y)$$
  where the second equality follows because a consumer with total resources $y$, constant income, and $\beta R < 1$ will be constrained. But note that by the definition of $c^{\#}_{\tau,n}$, we obtain
  $$	u'(c_{\tau,n}^{\#})  =  (R \beta)^{\mathcal{T}[n]-\tau} u'({y})  <  R \beta u'({y}) = u'(c_{\tau,n+1}^{\#})$$
  where $\mathcal{T}[n]-\tau$ denotes the time remaining to the $n$'th constraint. From the assumption of decreasing marginal utility, we therefore know that
  \begin{eqnarray*}
    c_{\tau,n}^{\#} & \geq & c_{\tau,n+1}^{\#}.
  \end{eqnarray*}
  This means that the constraint is relevant: The pre-existing constraint $n$ does not force the consumer to do so much saving in period $\tau$ that the $n+1$'st constraint fails to bind.

  The prior-period levels of consumption and wealth at which constraint $n+1$ stops impinging on consumption can again be calculated recursively from
  \begin{eqnarray*}
    u'(c_{\tau,n+1}^{\#}) & = & R\beta u'(c_{\tau+1,n}({y}))
    \\  \wAlt_{\tau,n+1} & = & \left(V'_{\tau,n}\right)^{-1}(u'(c_{\tau,n+1}^{\#})).
  \end{eqnarray*}

  Furthermore, once again we can think of the constraint as terminating
  the horizon of a finite-horizon consumer in an earlier period than it
  is terminated for the less-constrained consumer, with the implication
  that the MPC below $\wAlt_{\tau,n+1}$ is strictly greater than the MPC
  above $\wAlt_{\tau,n+1}$.  Thus, the consumption function $c_{\tau,n+1}$
  constitutes a counterclockwise concavification of the consumption
  function $c_{\tau,n}$ around the kink point $\wAlt_{\tau,n+1}$.

  \section{Proof of Theorem \ref{thm:riskandconstraints}}\label{app:riskandconstraints}

  \begin{proof}

    Our proof proceeds by constructing the behavior of consumers facing the risk from the behavior of the corresponding perfect foresight consumers.  We consider matters from the perspective of some level of wealth ${{m}}$ for the perfect foresight consumers.  Because the same marginal utility function $u'$ applies to all four consumption rules, the Compensating Precautionary Premia, $\kappa_{t,n}$ and $\kappa_{t,n+1}$, associated with the introduction of the risk $\zeta_{t+1}$  must satisfy
    \begin{eqnarray}
      c_{t,n}({{m}}) & = & \tilde{c}_{t,n}({{m}}+\kappa_{t,n}) \label{eq:hateqtildehat2}
      \\ c_{t,n+1}({{m}}) & = & \tilde{c}_{t,n+1}({{m}}+\kappa_{t,n+1}). \label{eq:hateqtildehat}\end{eqnarray}
    Define the amounts of precautionary saving induced by the risk $\zeta_{t+1}$ at an arbitrary level of wealth ${m}$ in the two cases as
    \begin{eqnarray}
      \psi_{t,n}({m}) & = & c_{t,n}({m})-\tilde{c}_{t,n}({m})
      \\   \psi_{t,n+1}({m}) & = & c_{t,n+1}({m})-\tilde{c}_{t,n+1}({m})
    \end{eqnarray}
    where the mnemonic is that the first two letters of the Greek letter psi stand
    for {\bf p}recautionary {\bf s}aving.

    We can rewrite \eqref{eq:hateqtildehat} (resp. \eqref{eq:hateqtildehat2}) as
    \begin{eqnarray*}
      c_{t,n+1}({m}) = c_{t,n+1}({{m}}+\kappa_{t,n+1})+\int_{{{m}}+\kappa_{t,n+1}}^{{{m}}} c_{t,n+1}^{\prime}(\mu) d\mu  = \tilde{c}_{t,n+1}({{m}}+\kappa_{t,n+1})
      \psi_{t,2}({{m}}+\kappa_{t,2}) \equiv
    \end{eqnarray*}
    which implies that
    \begin{eqnarray*}
      \psi_{t,n+1}({{m}}+\kappa_{t,n+1}) & = &
                                               c_{t,n+1}({{m}}+\kappa_{t,n+1})-\tilde{c}_{t,n+1}({{m}}+\kappa_{t,n+1}) = \int^{{{m}}+\kappa_{t,n+1}}_{{{m}}} c_{t,n+1}^{\prime}(\mu) d\mu,
      \\ %\psi_{t,1}({{m}}+\kappa_{t,1}) \equiv
      \psi_{t,n}({{m}}+\kappa_{t,n}) & = &  c_{t,n}({{m}}+\kappa_{t,n})-\tilde{c}_{t,n}({{m}}+\kappa_{t,n}) = \int^{{{m}}+\kappa_{t,n}}_{{{m}}} c_{t,n}^{\prime}(\mu) d\mu
    \end{eqnarray*}
    and
    \begin{eqnarray}
      \psi_{t,n}({{m}}+\kappa_{t,n+1}) & = &
                                             \psi_{t,n}({{m}}+\kappa_{t,n}) - \int^{{{m}}+\kappa_{t,n+1}}_{{{m}}+\kappa_{t,n}} (\tilde{c}_{t,n}^{\prime}(\mu)-c_{t,n}^{\prime}(\mu)) d\mu \nonumber
    \end{eqnarray}
    so the difference between precautionary saving for the consumer facing $n$ constraints and the one facing $n+1$ constraints at ${{m}}+\kappa_{t,n+1}$ is
    \begin{align}
      \psi_{t,n+1}&({{m}}+\kappa_{t,n+1}) - \psi_{t,n}({{m}}+\kappa_{t,n+1}) = \nonumber\\
                  &= \psi_{t,n+1}({{m}}+\kappa_{t,n+1}) - \psi_{t,n}({{m}}+\kappa_{t,n}) + \psi_{t,n}({{m}}+\kappa_{t,n})- \psi_{t,n}({{m}}+\kappa_{t,n+1}) \nonumber
      \\ &=\int_{{{m}}}^{{{m}}+\kappa_{t,n+1}} c_{t,n+1}^{\prime}(\mu)d\mu - \int^{{{m}}+\kappa_{t,n}}_{{{m}}} c_{t,n}^{\prime}(\mu) d\mu + \int^{{{m}}+\kappa_{t,n+1}}_{{{m}}+\kappa_{t,n}} (\tilde{c}_{t,n}^{\prime}(\mu)-c_{t,n}^{\prime}(\mu)) d\mu \nonumber\\
      % &=\int_{{{m}}}^{{{m}}+\kappa_{t,n}} (c_{t,n+1}^{\prime}(\mu)-c_{t,n}^{\prime}(\mu))d\mu+\int^{{{m}}+\kappa_{t,n+1}}_{{{m}}+\kappa_{t,n}} \left(c_{t,n+1}^{\prime}(\mu)+(\tilde{c}_{t,n}^{\prime}(\mu)-c_{t,n}^{\prime}(\mu)) \right) d\mu \nonumber \\
                  &= \int_{{{m}}}^{{{m}}+\kappa_{t,n+1}}
                    (c_{t,n+1}^{\prime}(\mu)-c_{t,n}^{\prime}(\mu))d\mu +\int^{{{m}}+\kappa_{t,n+1}}_{{{m}}+\kappa_{t,n}}
                    \tilde{c}_{t,n}^{\prime}(\mu) d\mu \label{eq:psidiffint}
    \end{align}

    If we can show that \eqref{eq:psidiffint} is a positive
    number for all feasible levels of ${{m}}$ satisfying ${{m}} < {\bar{\wAlt}}_{t,n+1}$, then we have proven Theorem \ref{thm:riskandconstraints}. We know that the marginal propensity to consume is always strictly positive and that $\kappa_{t,n+1} \geq \kappa_{t,n} \geq 0$\footnote{Since we know that liquidity constraints increase prudence (Corollary \ref{cor:lcip}) and that prudence results in a positive precautionary premium (Lemma \ref{lemma:kimpratt}).} so to prove that \eqref{eq:psidiffint} is strictly positive, we need to show one of two sufficient conditions:
    \begin{enumerate}
    \item $\kappa_{t,n+1} > 0$ and $c_{t,n+1}'(\mu) > c_{t,n}'(\mu)$
    \item $\kappa_{t,n+1} > \kappa_{t,n}$
    \end{enumerate}
    Now, since $u'''>0$, we know that $\kappa_{t,n} > 0$ from Jensen's inequality. Hence, $\kappa_{t,n+1} > 0$ since $\kappa_{t,n+1} \geq \kappa_{t,n}$. The first integral in \eqref{eq:psidiffint} is therefore strictly positive as long as $c_{t,n+1}' > c_{t,n}'$, which is true for ${{m}} < \wAlt_{t,n+1}$ by Lemma \ref{lem:LcAndCc}.

    For ${{m}} \geq \wAlt_{t,n+1}$, we know that $c_{t,n+1}' = c_{t,n}'$ so the first integral in \eqref{eq:psidiffint} is always zero. For the second integral in \eqref{eq:psidiffint} to be strictly positive, we need to show that $\kappa_{t,n+1} > \kappa_{t,n}$.

                    %                     First define $\hat{\zeta}$ as the realization of $\zeta$ such that
                    %                     $$ {a}_{t,n+1} + y + \kappa_{t,n+1} + \zeta = \omega_{t,n+1}.$$
                    %                     In words, $\hat{\zeta}$ is the value of $\zeta$ that cancels the values of ${a}_{t,n+1}$ and $\kappa_{t,n+1}$ relative to the $n+1$'st constraint in the sense that given the level of savings and precautionary premia, a draw if $\zeta = \hat{\zeta}$ restores wealth to exactly the value at which constraint $n+1$ stops binding.
                    %                     XXXXX

    First define the perfect foresight consumption functions as
    \begin{eqnarray}
      c(\kappa_{t,n}+\zeta) & = & c_{t+1,n}(\overbrace{{s}_{t,n}}^{={a}_{t,n+1}}+{y}+\kappa_{t,n}+\zeta) \label{eq:cnoconstr}
      \\  {c}(\kappa_{t,n+1}+\zeta) & = & c_{t+1,n+1}({s}_{t,n+1}+{y}+\kappa_{t,n+1}+\zeta)\label{eq:gravecnoconstr}.
    \end{eqnarray}
    where ${a}_{t,n} = {a}_{t,n+1}$ since ${m} \geq \wAlt_{t,n+1}$. Recall also the definitions of $\kappa_{t,n}$ and $\kappa_{t,n+1}$:
    \begin{eqnarray*}
      u'({c}_{t,n}) & = & \Ex_{t}[u'(c(\kappa_{t,n}+\zeta))]
      \\  u'({c}_{t,n+1}) & = & \Ex_{t}[u'({c}(\kappa_{t,n+1}+\zeta))].
    \end{eqnarray*}

    Now recall that Lemma~\ref{lemma:kimpratt} tells us that if absolute prudence of $u'(c(\kappa_{t,n}+\zeta))$ is identical to absolute prudence of $u'({c}(\kappa_{t,n+1}+\zeta))$ for every realization of $\zeta$, then $\kappa_{t,n}=\kappa_{t,n+1}$. This is true if ${m}_{t+1} \geq \wAlt_{t+1,n+1}$ for all possible realizations of $\zeta \in (\underline{\zeta}, \bar{\zeta})$, i.e. that the agent is unconstrained for all realizations of the risk. We defined this limit as ${m}_{t+1} \geq {\bar{\wAlt}}_{t+1,n+1}$. We therefore know that $\kappa_{t,n+1}  = \kappa_{t,n}$ if ${{m}} \geq {\bar{\wAlt}}_{t+1,n+1}$.

    For all levels of wealth below this limit (${{m}} < {\bar{\wAlt}}_{t+1,n+1}$), there exist realizations of $\zeta$ such that constraint $n+1$ will bind in period $t+1$. The agent will require a higher precautionary premia when facing constraint $n+1$ in addition to the $n$ constraints already in the set, implying that $\kappa_{t,n+1} > \kappa_{t,n}$. Equation \eqref{eq:psidiffint} is therefore strictly positive if ${{m}} < {\bar{\wAlt}}_{t+1,n+1}$ and we have proven Theorem \ref{thm:riskandconstraints}.
  \end{proof}

  \section{Resemblance Between Precautionary Saving and a Liquidity Constraint} \label{app:similar}

  This appendix repeats an illustration from appendix G of \cite{BufferStockTheory}.  (We make no claim to novelty of this point; it is here only to aid the intuition of the reader).

  In this appendix, we provide an example where the introduction of risk resembles the introduction of a constraint. Consider the second-to-last period of life for two risk-averse CRRA utility consumers and assume for simplicity that $R=\beta=1$.

  The first consumer is subject to a liquidity constraint $c_{T-1} \geq {m}_{T-1}$, and earns non-stochastic income of ${y}=1$ in period $T$. This consumer's saving rule will be
  \begin{equation*}
    {a}_{T-1,1}({m}_{T-1}) =
    \begin{cases}
      0   & \mbox{if ${m}_{T-1} \leq 1$}
      \\    ({m}_{T-1}-1)/2 & \mbox{if ${m}_{T-1} > 1$}.
    \end{cases}
  \end{equation*}

  The second consumer is not subject to a liquidity constraint, but
  faces a stochastic income process,
  \begin{equation*}
    y_{T} =
    \begin{cases}
      0 & \mbox{with probability $p$}
      \\ \frac{1}{1-p} & \mbox{with probability $(1-p)$}.
    \end{cases}
  \end{equation*}

  If we write the consumption rule for the unconstrained consumer facing the risk as $\tilde{s}_{T-1,0},$ the key result is that in the limit as $p \downarrow 0$, behavior of the two consumers becomes the same. That is, defining $\tilde{s}_{T-1,0}({m})$ as the optimal saving rule for the consumer facing the risk,
  \begin{equation*}
    \lim_{p \downarrow 0} \tilde{s}_{T-1,0}({m}_{T-1}) = {a}_{T-1,1}({m}_{T-1}) \label{eq:lim0}
  \end{equation*}
  for every ${m}_{T-1}$.

  To see this, start with the Euler equations for the two consumers given wealth ${m}$,
  \begin{eqnarray}
    u'({m}-{a}_{T-1,1}({m})) & = & u'({a}_{T-1,1}({m})+1) \label{eq:euler1}
    \\   u'({m}-\tilde{s}_{T-1,0}({m})) & = & p u'(\tilde{s}_{T-1,0}({m}))+(1-p) u'(\tilde{s}_{T-1,0}({m})+1). \label{eq:euler2}
  \end{eqnarray}

  Consider first the case where ${m}$ is large enough that the constraint does not bind for the constrained consumer, ${m}>1$.  In this case the limit of the Euler equation for the second consumer is identical to the Euler equation for the first consumer (because for ${m}>1$ savings are positive for the consumer facing the risk, implying that the limit of the first $u'$ term on the RHS of \eqref{eq:euler2} is finite). Thus the limit of \eqref{eq:euler2} is \eqref{eq:euler1} for ${m}>1$.

  Now consider the case where ${m} < 1$ so that the first consumer would be constrained.  This consumer spends her entire resources ${m}$, and by the definition of the constraint we know that
  \begin{eqnarray}
    u'({m}) > u'(1). \label{eq:upw}
  \end{eqnarray}

  Now consider the consumer facing the risk. If this consumer were to save exactly zero and then experienced the bad shock in period $T$, she would have an infinite marginal utility (the Inada condition). This cannot satisfy the Euler-equation as long as ${m}>0$. Therefore we know that for any $p>0$ and any ${m}>0$ the consumer will save some positive amount. For a fixed ${m}$, hypothesize that there is some $\delta>0$ such that no matter how small $p$ became the consumer would always choose to save at least $\delta$. But for any $\delta$, the limit of the RHS of \eqref{eq:euler2} is $u'(1+\delta)$. We know from concavity of the utility function that $u'(1+\delta) < u'(1)$ and we know from~\eqref{eq:upw} that $u'({m}) > u'(1) > u'(1+\delta)$, so as $p \downarrow 0$ there must always come a point at which the consumer can improve her total utility by shifting some resources from the future to the present, i.e. by saving less.  Since this argument holds for any $\delta>0$ it demonstrates that as $p$ goes to zero there is no positive level of saving that would make the consumer better off. But saving of zero or a negative amount is ruled out by the Inada condition at $u'(0)$.  Hence saving must approach, but never equal, zero as $p \downarrow 0$.

  Thus, we have shown that for ${m} \leq 1 $ and for ${m} > 1$ in the limit as $p \downarrow 0$ the consumer facing the risk but no constraint behaves identically to the consumer facing the constraint but no risk. This argument can be generalized to show that for the CRRA utility consumer, spending must always be strictly less than the sum of current wealth and the minimum possible value of human wealth.  Thus, the addition of a risk to the problem can rule out certain levels of wealth as feasible, and can also render either future or past constraints irrelevant, just as the imposition of a new constraint can.

  \section{Proof of Theorem \ref{thm:CCandPS}}\label{app:CCandPS}

  \begin{proof}
    To simplify notation and without loss of generality, we assume that when an agent faces $n$ constraints and $m$ risks, there are one constraint and one risk for each time period. For example, if $c_{t,n}^{m}$ faces $m$ future risks and $n$ future constraints, then the next period consumption function is $c_{t+1,n-1}^{m-1}$ (and $m = n$). Note that we can transform any problem into this notation by filling in with degenerate risks and non-binding constraints. However, for Theorem \ref{thm:CCandPS} to hold with strict inequality, we need to assume that there is at least one relevant future risk and one relevant constraint.

    We know that either the introduction of risk or a introduction of a constraint results in a counterclockwise concavification of the original consumption function. However, this is only true when we introduce risks in the absence of constraints (Lemma \ref{lem:ccrisk}) and when we introduce constraints in the absence of risk (see Theorem \ref{thm:lcip2}). In this proof, we therefore need to show that the introduction of all risks and constraints is a counterclockwise concavification of the linear case with no risks and constraints.

    Here is our proof strategy. We define a set
    \begin{align}
      \mathcal{P}_{t,n}^{m-1} = \{ {m} | c_{t,n}^{m-1}({m})-c_{t,n}^{m}({m})>c_{t,0}({m})-c^{1}_{t,0}({m}) \} \label{eq:whatcanbesaid_proof}
    \end{align}
    where Theorem \ref{thm:CCandPS} holds in period $t$ when we introduce a risk at the beginning of period $t+1$. This is defined as the set where precautionary saving induced by a risk that is realized at the beginning of period $t+1$ is greater in the presence of all risks and constraints than in the unconstrained case.

    In order to show that the set $\mathcal{P}_{t,n}^{m-1}$ is non-empty, we build it up recursively, starting from period $T$ and adding one constraint or one risk  for each time period. The key to the proof is to understand that the introduction of risks or constraints will never fully reverse the effects of all other risks and constraints, even though they sometimes reduce absolute prudence for some levels of wealth because risks and constraints can mask the effects of future risks and constraints. Hence, the new consumption function must still be a counterclockwise concavification of the consumption function with no risks and constraints for some levels of wealth.

    Since a counterclockwise concavification increases prudence by Lemma \ref{lem:CCToPrud}, and higher prudence increases precautionary saving by Lemma \ref{lemma:kimpratt}, our required set can be redefined as
    \begin{align*} \mathcal{P}_{t,n}^{m-1} = \{{m} | c_{t,n}^{m-1}({m}) \text{ is a counterclockwise concavification of } c_{t,0}({m}) \text{ and } c_{t,n}^{m-1}({m}) >
      {m} 	\}\end{align*}
    where we add the last condition, $c_{t,n}^{m-1}({m}) > w$ to avoid the possibility that some constraint binds such that the agent does not increase precautionary saving. In words: $\mathcal{P}_{t,n}^{m-1}$ is the set where the consumption function is a counterclockwise concavification of $c_{t,0}({m})$ and no constraint is strictly binding. We construct the set recursively for two different cases: CARA and all other type of utility functions. We start with the non-CARA utility functions.

    First add the last constraint. The set $\mathcal{P}^{0}_{T,1}$ is then
    \[\mathcal{P}^{0}_{T,1} = \emptyset \] %\[\left\{ w| {m} < \omega_{T,1}  \right\}\]
    since we know that $c_{T,1}({m})$ is a counterclockwise concavification of $c_{T,0}({m})$ around $\wAlt_{T,1}$ but that the consumer is constrained below this point.

    We next add the risk at the beginning of period $T$. To construct the new set, we note three things. First, by Lemma \ref{lem:recursive},  (strict) consumption concavity is recursively propagated for all values of wealth where there is a positive probability that the constraint can bind, i.e.
    \[\{{m}_{T-1} | \wAlt_{T-1,1} \in \left[{m}_{T-1} - c_{T-1,1}^1({m}_{T-1}) + {y}_{T} + \underline{\zeta} ,{m}_{T-1} - c_{T-1,1}^1({m}_{T-1}) + {y}_{T} + \bar{\zeta}\right] \}\]
    has property strict CC, while it has non-strict property $CC$ for all possible values of ${m}_{T-1}$. Further, we know from Theorem \ref{thm:riskandconstraints} (rearrange equation \eqref{eq:ineq}) that
    \begin{align*}{c}_{T-1,1}^1({m})  & \leq c_{T-1,1}({m}) - c_{T-1,0}({m}) + {c}_{T-1,0}^1({m}) \\ &\leq c_{T-1,0}({m}) - c_{T-1,0}({m}) + c_{T-1,0}({m}) = c_{T-1,0}({m}).\end{align*}
    Third, we know that $c_{T-1,1}^{1}({m})' \geq c_{T-1,0}'({m})$ since ${c}_{T-1,1}^1({m}) < c_{T-1,0}({m})$ for ${m} \leq \wAlt_{T-1,1}^1$, $\lim_{{m}\rightarrow \infty} c_{T-1,1}^1({m}) - c_{T-1,0}({m}) = 0$, and that $c_{t,1}^1({m})$ is concave while $c_{t,0}({m})$ is linear. Hence, $c_{T-1,1}^1$ is a counterclockwise concavification of $c_{T-1,0}$ around the minimum value of wealth when the constraint will never bind and the new set is
    \begin{align*}\mathcal{P}_{T-1,1}^1 = \{{m}_{T-1} | \wAlt_{T-1,1} \in \left[{m}_{T-1} - c_{T-1,1}^1({m}_{T-1}) + {y}_{T} + \underline{\zeta}, {m}_{T-1} - c_{T-1,1}^1({m}_{T-1}) + {y}_{T} + \bar{\zeta}\right]   \\ \wedge c_{T-1,1}^1({m}) > {m}_{T-1}\}.\end{align*}

    We can now add the next constraint. The consumption function now has two kink points, $\wAlt_{T-1,1}^1$ and $\wAlt_{T-1,2}^1$. We know again from Lemma \ref{lem:recursive} that consumption concavity is preserved when we add a constraint, and strict consumption concavity is preserved for all values of wealth at which a future constraint might bind. Further, we know from Theorem \ref{thm:riskandconstraints} that
    \begin{align*}c_{T-1,2}^1({m}) &\leq c_{T-1,2}({m}) - c_{T-1,1}({m}) + c_{T-1,1}^1({m}) \\ &\leq c_{T-1,1}({m}) - c_{T-1,1}({m}) + c_{T-1,1}({m}) = c_{T-1,1}({m}) \leq c_{T-1,0}({m}). \end{align*}
    Third, $c_{T-1,2}^1({m}) < c_{T-1,0}({m})$,  $\lim_{{m}\rightarrow\infty} c_{T-1,2}^1({m}) - c_{T-1,0}({m}) = 0$, and we know that if $c_{T-1,2}^1({m})$ is concave while $c_{T-1,0}({m})$ is linear, then $c_{T-1,2}'^{1}({m}) \geq c_{T-1,0}'({m})$. $c_{T-1,2}^1({m})$ which is a counterclockwise concavification of $c_{T-1,0}({m})$ around the minimum level of wealth at which the first constraint will never impinge on time $T-1$ consumption, $\bar{\wAlt}_{T-1,1}^1$, and the new set is
    \[\mathcal{P}_{T-1,2}^1 = \{{m}_{T-1}| {m}_{T-1} \leq \bar{\wAlt}_{T-1,1}^1 \wedge c_{T-1,2}^1({m}) > {m}_{T-1} \}.\]

    It is now time to add the next risk. The argument is similar. We still know that (strict) consumption concavity is recursively propagated and that $\lim_{{m}\rightarrow \infty} c_{T-2,2}^2({m}) - c_{T-2,0}({m}) = 0$. Further, we can think of the addition of two risks over two periods as adding one risk that is realized over two periods. Hence, the results from Theorem \ref{thm:riskandconstraints} must hold also for the addition of multiple risks so we have
    \begin{align*}c_{T-2,2}^2({m}) &\leq c_{T-2,2}({m}) - c_{T-2,1}({m}) + c_{T-2,1}^2({m}) \\ &\leq c_{T-2,1}({m}) - c_{T-2,1}({m}) + c_{T-2,1}({m}) = c_{T-2,1}({m}) \leq c_{T-2,0}({m}). \end{align*}
    Hence, we again know that $c_{T-2,2}'^{2}({m}) \geq c_{T-2,0}'({m})$. $c_{T-2,2}^2({m})$ is thus a counterclockwise concavification of $c_{T-2,0}({m})$ around the level of wealth at minimum value of wealth when the last constraint will never bind. The new set is therefore
    \[\mathcal{P}_{T-2,2}^2 = \{{m}_{T-2} | {m}_{T-2} - c_{T-2,2}^2({m}_{T-2}) + {y}_{T-1} + \zeta_{T-1} \in \mathcal{P}_{T-1,2}^1 \wedge c_{T-2,2}^{2}({m}) < {m} \}.\]

    Doing this recursively and defining $\bar{\wAlt}_{t,1}^{m-1}$ as the minimum value of wealth beyond which constraint $1$ will never bind, the set of wealth levels at which Theorem \ref{thm:CCandPS} holds can be defined as
    \[\mathcal{P}_{t,n}^{m-1} = \{{m}_{t} | {m}_{t} \leq \bar{\wAlt}_{t,1}^{m-1} \wedge c_{t,n}^{m-1}({m}) > {m} \}\]
    In words, precautionary saving is higher if there is a positive probability that some future constraint could bind and the consumer is not constrained today.

    The last requirement is to define the set also for the CARA utility function. The problem with CARA utility is that $\lim_{{m}\rightarrow \infty} c_{t,n}^{m-1}({m}) - c_{t,0}({m}) = - k^{m-1} \leq 0$ where $k^{m-1}$ is some positive constant. We can therefore not use the same arguments as in the preceding proof. However, by realizing that equation \eqref{eq:ineq} in the CARA case can be defined as
    \begin{align*}
      c_{t,n+1}({m}) - \tilde{c}_{t,n+1}({m}) - \tilde{k} &\geq c_{t,n}({m})-\tilde{c}_{t,n}({m}) -  \tilde{k} \geq 0
    \end{align*}
    where the last inequality follows since precautionary saving is always higher than in the constant limit in the presence of constraints. We can therefore rearrange to get
    \begin{align*}
      \tilde{c}_{t,n+1}({m})  &\leq c_{t,n+1}({m}) - \tilde{k} \leq c_{t,n}({m}) - \tilde{k} \leq c_{t,0} - \tilde{k}	\end{align*}
    which implies that the arguments in the preceding section goes through also for CARA utility with this slight modification.

  \end{proof}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                      %
% GLE - Graphics Layout Engine <http://www.gle-graphics.org/>          %
%                                                                      %
% Modified BSD License                                                 %
%                                                                      %
% Copyright (C) 2009 GLE.                                              %
%                                                                      %
% Redistribution and use in source and binary forms, with or without   %
% modification, are permitted provided that the following conditions   %
% are met:                                                             %
%                                                                      %
%    1. Redistributions of source code must retain the above copyright %
% notice, this list of conditions and the following disclaimer.        %
%                                                                      %
%    2. Redistributions in binary form must reproduce the above        %
% copyright notice, this list of conditions and the following          %
% disclaimer in the documentation and/or other materials provided with %
% the distribution.                                                    %
%                                                                      %
%    3. The name of the author may not be used to endorse or promote   %
% products derived from this software without specific prior written   %
% permission.                                                          %
%                                                                      %
% THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR   %
% IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED       %
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE   %
% ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY       %
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL   %
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE    %
% GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS        %
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER %
% IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR      %
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN  %
% IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                        %
%                                                                      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Fitz}
\index{fitz} \label{fitz:sec}

{\sf FITZ} fits smooth curves based on a set of 3D data points. E.g., given some data points (note that each line has three values: an x, y, and z coordinate):
\begin{verbatim}
x	y	z
---- data file testf.dat -----
1 	1 	1
1 	2 	1
2 	2	1
2 	1	1
1.5 	1.5 	2
------------------------------
\end{verbatim}

Fitz creates a ".z" file that can be used in a surface block, a colormap or contour plot. The following example illustrates this.

\begin{minipage}[c]{8cm}
\begin{Verbatim}
begin fitz
   data "fitz.dat"
   x from 0 to 5 step 0.2
   y from 0 to 5 step 0.2
   ncontour 6
end fitz

begin surface
   size 7 7
   data "fitz.z"
   top color blue
   xaxis min 0 max 5 step 1
   yaxis min 0 max 5 step 1
   points "fitz.dat"
   droplines lstyle 1
   marker circle
   view 2.5 3 0.3
   harray 5000
end surface
\end{Verbatim}
\end{minipage}
\hfill
\begin{minipage}[c]{7cm}
\mbox{\includegraphics{utilities/fig/fitz1}}
\end{minipage}


% \newcommand\rectyp{\FinTy{\tnat}}

\newcommand\factyp{\typ}

\section{Implementation in \toolname}\label{sec:haskell}

We have implemented \declang in \toolname.
%
In \S~\ref{sec:termination} we saw real world termination checks.
%
Here claim soundness of \toolname's termination checker,
as the checker derives as a the transition from \declang to \lhaskell.

\subsection{Termination}

%Let ${\factyp \defeq \tfunbasic{\FinTy{\tnat}}{\FinTy{\tnat}}}$.
Haskell's recursive functions of type ${\tfunbasic{\FinTy{\tnat}}{\typ}}$
are represented, in GHC's Core \cite{SulzmannCJD07} as
${\mathtt{let\ rec}\ f = \ \efun{n}{}{e}}$ that is operationally
equivalent to ${\mathtt{let}\ f = \ \etfix{\typ}\ (\efun{n}{}{\efun{f}{}{e}})}$.
Given the type of $\etfix{\typ}$, checking that $f$ has
type $\tfunbasic{\FinTy{\tnat}}{\typ}$ reduces to checking
$e$ in a \emph{termination-weakened environment} where
$$\tbind{f}{\tfunbasic{\tref{v}{\tnat}{\finite}{v < n}}{\typ}}$$
%
Thus, \toolname proves termination just as \declang
does: by checking the body in the above environment,
where the recursive binder is called with $\tnat$
inputs that are strictly smaller than $n$.

\mypara{Default Metric}
For example, \toolname proves that
%
\begin{code}
  fac n = if n == 0 then 1 else n * fac (n-1)
\end{code}
%
has type $\tfunbasic{\FinTy{\tnat}}{\FinTy{\tnat}}$
by typechecking the body of @fac@
in a termination-weakened environment
${\mathtt{fac}\ : \tfunbasic{\tref{\ttv}{\tnat}{\finite}{\ttv < \ttn}}{\FinTy{\tnat}}}$.
The recursive call generates the query:
\begin{align*}
\tbind{\ttn}{\{0 \leq \ttn\}}, \lnot (\ttn = 0) \vdash_D &\  \subt{\ttref{v=n-1}}{\ttref{0 \leq v \wedge v < n}}\\
%\tlref{n}{\tint}{\finite}{0 \leq n}, \lnot (n = 0) \vdash_D &\  \subt{\ttref{v=n-1}}{\ttref{0 \leq v \wedge v < n}}\\
\intertext{Which reduces to the valid VC:}
0 \leq \ttn \wedge \lnot (\ttn = 0) \Rightarrow &\   (\ttv = \ttn-1) \Rightarrow (0 \leq \ttv \wedge \ttv < \ttn)
\end{align*}
%
proving that $\mathtt{fac}$ terminates, in essence because the
\emph{first parameter} forms a \emph{well-founded decreasing metric}.

\mypara{Refinements Enable Termination}
Consider Euclid's GCD:
%
\begin{code}
  gcd :: a:Nat -> {v:Nat | v < a} -> Nat
  gcd a 0 = a
  gcd a b = gcd b (a `mod` b)
\end{code}
%
Here, the first parameter is decreasing, but this requires
the fact that the second parameter is smaller than the first
and that @mod@ returns results smaller than its second
parameter. Both facts are easily expressed as refinements,
but elude non-extensible checkers~\cite{Giesl11}.

\mypara{Explicit Termination Metrics}
The indexed-fixpoint combinator technique is easily extended to
cases where some parameter \emph{other} than the first is the
well-founded metric. For example, consider:
% As an example, consider the tail-recursive factorial:
%
\begin{code}
  tfac     :: Nat -> n:Nat -> Nat / [n]
  tfac x n | n == 0    = x
           | otherwise = tfac (n*x) (n-1)
\end{code}
%
We specify that the \emph{last parameter} is decreasing by
specifying an explicit termination metric @/ [n]@ in the
type signature.
%
\toolname \emph{desugars} the
termination metric into a new $\tnat$-valued \emph{ghost parameter} @d@
whose value is always equal to the termination metric @n@:
\begin{code}
  tfac :: d:Nat -> Nat -> {n:Nat | d = n} -> Nat
  tfac d x n | n == 0    = x
             | otherwise = tfac (n-1) (n*x) (n-1)
\end{code}
%
Type checking, as before, checks the body in an environment where
the first argument of @tfac@ is weakened, \ie, requires proving @d > n-1@.
%
So, the system needs to know that the ghost argument @d@
represents the decreasing metric.
%
We capture this information in the type signature of @tfac@ where the \emph{last}
argument exactly specifies that @d@ is the termination metric @n@, \ie, @d = n@.
%
Note that since the termination metric can depend on any argument,
it is important to refine the last argument,
so that all arguments are in scope, with the fact that @d@ is the termination metric.

To generalize, desugaring of termination metrics proceeds as follows.
Let $f$ be a recursive function with parameters $\overline{x}$ and
termination metric $\mu(\overline{x})$. Then \toolname will
\begin{itemize}
\item add a $\tnat$-valued ghost first parameter $d$ in the definition of $f$,
\item weaken the last argument of $f$ with the refinement $d = \mu(\overline{x})$, %and
\item at each recursive call of $f\ \overline{e}$,
apply $\mu(\overline{e})$ as the first argument.
\end{itemize}
%
%%As will shall see this technique can be used
%%when the termination metric is any logical expression.

\mypara{Explicit Termination Expressions}
Let us now apply the previous technique in a function where
none of the parameters themselves decrease across recursive calls,
but there is some \emph{expression} that forms the decreasing metric.
%
%Sometimes, none of the parameters themselves decrease across recursive calls,
%but there is some \emph{expression} that forms the decreasing metric.
%
Consider @range lo hi@ (as in~\S~\ref{sec:termination}), which returns the list of
@Int@s from @lo@ to @hi@:
%
We generalize the explicit metric specification to
\emph{expressions} like @hi-lo@. \toolname \emph{desugars} the
expression into a new $\tnat$-valued \emph{ghost parameter}
whose value is always equal to @hi-lo@, that is:
\begin{code}
  range :: lo:Nat -> {hi:Nat | hi >= lo} -> [Nat] / [hi-lo]
  range lo hi
    | lo < hi = lo : range (lo + 1) hi
    | _       = []
\end{code}
%
Here, neither parameter is decreasing (indeed, the first one
is \emph{increasing}) but @hi-lo@ decreases across each call.
%
We generalize the explicit metric specification to
\emph{expressions} like @hi-lo@. \toolname \emph{desugars} the
expression into a new $\tnat$-valued \emph{ghost parameter}
whose value is always equal to @hi-lo@, that is:
%
\begin{code}
  range lo hi = go (hi-lo) lo hi
    where
      go :: d:Nat -> lo:Nat -> {hi:Nat | d = hi - lo} -> [Nat]
      go d lo hi
       | lo < hi = l : go (hi-(lo+1)) (lo+1) hi
       | _       = []
\end{code}
%
After which, it proves @go@ terminating, by showing
that the first argument @d@ is a \tnat that decreases across each
recursive call (as in @fac@ and @tfac@).

\mypara{Recursion over Data Types}
The above strategy generalizes easily to functions that recurse
over (finite) data structures like arrays, lists, and trees.
In these cases, we simply use \emph{measures} to project the
structure onto \tnat, thereby reducing the verification to
the previously seen cases. For each user defined type, \eg
%
\begin{code}
  data L [sz] a = N | C a (L a)
\end{code}
%
we can define a \emph{measure}
%
\begin{code}
  measure sz  :: L a -> Nat
    sz (C x xs) = 1 + (sz xs)
    sz N        = 0
\end{code}
%
We prove that @map@ terminates using the type:
%
\begin{code}
  map :: (a -> b) -> xs:L a -> L b / [sz xs]
  map f (C x xs) = C (f x) (map f xs)
  map f N        = N
\end{code}
%
That is, by simply using @(sz xs)@  as the
decreasing metric.

\mypara{Generalized Metrics Over Datatypes}
Finally, in many functions there is no single argument
whose (measure) provably decreases. For example, consider:
%
\begin{code}
  merge :: xs:L a -> ys:L a -> L a / [sz xs + sz ys]
  merge (C x xs) (C y ys)
    | x < y     = x `C` (merge xs  (y `C` ys))
    | otherwise = y `C` (merge (x `C` xs)  ys)
\end{code}
%
from the homonymous sorting routine. Here, neither parameter
decreases, but the \emph{sum} of their sizes does.
%
As before \toolname desugars the decreasing expression into
a ghost parameter and thereby proves termination (assuming,
of course, that the inputs were finite lists, \ie
$\FinTy{\mathtt{L}}\ a$).

\mypara{Automation: Default Size Measures}
Structural recursion on the first argument is a common pattern
in \lhaskell code.
%
\toolname automates termination proofs for this common case,
by allowing users to specify a \emph{size measure}
for each data type, (\eg @sz@ for @L a@).
%
Now, if \emph{no} termination metric is given, by default
\toolname assumes that the \emph{first} argument whose type
has an associated size measure decreases.
%
Thus, in the above, we need not specify metrics for @fac@
or @gcd@ or @map@ as the size measure is automatically
used to prove termination.
%
This simple heuristic allows us to {automatically}
prove 67\% of recursive functions terminating.

%%% \mypara{Summary}
%%% To sum up,
%%% %
%%% \begin{itemize}
%%% \item No termination check for functions marked @lazy@,
%%% \item If no explicit termination metrice, then first
%%%       argument with size measure used by default,
%%% \item Otherwise, explicit termination metric desugared
%%%       into ghost @nat@ parameter that is used to prove
%%%       termination.
%%% \end{itemize}

\subsection{Non-termination}

By default, \toolname checks that every function is
terminating. We show in \Sref{sec:refinedhaskell:evaluation} that
this is in fact the overwhelmingly common case in practice.
%
However, annotating a function as @lazy@ deactivates
\toolname's termination check (and marks the result as a
\Div type).
%
This allows us to check functions that are
non-terminating, and allows \toolname to prove safety
properties of programs that manipulate \emph{infinite}
data, such as streams, which arise idiomatically with
Haskell's lazy semantics.
%
For example, consider the classic @repeat@ function:
%
\begin{code}
  repeat x = x `C` repeat x
\end{code}
%
We cannot use the $\etfix{}$ combinators to
represent this kind of recursion, and hence,
use the non-terminating $\efix{}$ combinator
instead.
%
I \toolname, we use the @lazy@ keyword to denote
potentially diverging definitions
defined using the non-terminating $\efix{}$ combinator.

\begin{comment}
Abstract Streams

Let us see how we can use refinements to statically
distinguish between finite and infinite streams.
The direct, \emph{global} route of using a measure
%
\begin{code}
  measure inf    :: L a -> Prop
    inf (C x xs) = inf xs
    inf N        = false
\end{code}
%
to describe infinite lists is unavailable as such
a measure, and hence, the corresponding refinement
would be non-terminating.
%
Instead, we describe infinite lists in \emph{local}
fashion, by stating that each \emph{tail} is non-empty.

\mypara{Step 1: Abstract Refinements}
We can parametrize a datatype with abstract
refinements that relate sub-parts of the
structure \cite{vazou13}.
For example, we parameterize the list type as:
%
\begin{code}
  data L a <p :: L a -> Prop>
    = N | C a {v: L<p> a | (p v)}
\end{code}
%
which parameterizes the list with a refinement
@p@ which holds \emph{for each} tail of the list,
\ie holds for each of the second arguments to
the @C@ constructor in each sub-list.

\mypara{Step 2: Measuring Emptiness} Now, we can write a measure that
states when a list is \emph{empty}
%
\begin{code}
  measure emp  :: L a -> Prop
    emp N        = true
    emp (C x xs) = false
\end{code}
%
As described in \Sref{sec:typing}, \toolname translates the
abstract refinements and measures into refined types for
@N@ and @C@.

\mypara{Step 3: Specification \& Verification}
Finally, we can use the abstract refinements and measures to
write a type alias describing a refined version of @L a@
representing infinite streams:
%
\begin{code}
  type Stream a =
    {xs: L <{\v -> not(emp v)}> a | not(emp xs)}
\end{code}
%
We can now type @repeat@ as:
%
\begin{code}
  lazy repeat :: a -> Stream a
  repeat x    = x `C` repeat x
\end{code}
%
The @lazy@ keyword \emph{deactivates} termination checking, and
marks the output as a \Div type.
%
Even more interestingly, we can prove safety properties of
infinite lists, for example:
%
\begin{code}
  take            :: Nat -> Stream a -> L a
  take 0 _        = N
  take n (C x xs) = x `C` take (n-1) xs
  take _ N        = error "never happens"
\end{code}
%
\toolname proves, similar to the @head@ example from
\Sref{sec:refinedhaskell:overview}, that we never match a @N@ when
the input is a @Stream@.

\mypara{Finite vs. Infinite Lists}
%
Thus, the combination of refinements
and labels allows our stratified type
system to specify and verify whether
a list is finite or infinite.
%
Note that:
%
$\FinTy{\mathtt{L}}\ a$ represents
\emph{finite} lists \ie those
produced using the (inductive)
terminating fixpoint combinators,
%
$\WnfTy{\mathtt{L}}\ a$ represents
(potentially) infinite lists which
are guaranteed to reduce to values,
\ie non-diverging computations that
yield finite or infinite lists,
and
$\DivTy{\mathtt{L}}\ a$ represents
computations that may diverge or
produce a finite or infinite list.

\end{comment}

\subsection{User Specifications and Type Inference}

In program verification it is common that the user provides functional
specification that the code should satisfy.
In \toolname these specifications can be provided as type signatures
for @let@-bound variables.
%
Consider the typechecking rules of Figure~\ref{fig:typing}
that is used by \declang.
%
$$
\inference{
	\hastype{\Gamma}{e_x}{\tau_{x}} &&
	\hastype{\Gamma,\tbind{x}{\tau_x}}{e}{\tau} &&
	\iswellformed{\Gamma}{\tau}
}{
	\hastype{\Gamma}{\elet{x}{e_x}{e}}{\tau}
}[\rtlet]
$$
%
Note that \rtlet \emph{guesses} an appropriate type $\tau_x$
for $e_x$ and binds it to $x$ to typecheck $e$.

\toolname allows the user to specify the type $\tau_x$ for top level bindings.
%
For every binding \elet{x}{e_x}{\dots}, if the user provides a type specification $\tau_x$,
\toolname checks using the appropriate environment
(1)~that the specified type is well-formed and
(2)~that the expression $e_x$ typechecks under the specification $\tau_x$.
%
For the other top level bindings, \ie those without user-provided specifications,
as well as all local bindings, \toolname uses the Liquid Types~\citep{LiquidPLDI08}
framework to infer refinement types, thus greatly reducing the number of annotations
required from the user.


\documentclass[a4paper,twocolumn]{article}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{dsfont}
\usepackage{graphicx}
\usepackage{color}

\newcommand{\N}{\mathbf{N}}
\newcommand{\Z}{\mathbf{Z}}
\newcommand{\Q}{\mathbf{Q}}
\newcommand{\R}{\mathbf{R}}
\newcommand{\C}{\mathbf{C}}

\author{Florian Fontan}
\title{Advanced Models and Methods in Operations Research \\ Project: Batch scheduling}
\date{2021--2022}

\begin{document}

\maketitle

For each problem considered, instances and a code skeleton containing an instance parser and a solution checker are provided in the \texttt{data/} and \texttt{python/} folders of the project.

The algorithms must be implemented in the provided files between the tags \texttt{TODO START} and \texttt{TODO END}.

They must be tested on all the provided instances with the command:
\texttt{python3 problem.py -i instance.json -c certificate.json}

And each solution file must be validated by the provided checker:
\texttt{python3 problem.py -a checker -i instance.json -c certificate.json}

The results must be reproducible.

\bigskip

The delivrable must contain:
\begin{itemize}
  \item A \emph{short} report describing and justifying the proposed algorithms
  \item The code implementing the algorithms
  \item The solution files obtained on the provided instances
\end{itemize}

\section{Dynamic Programming}

We consider the Knapsack problem with width:
\begin{itemize}
  \item Input:
    \begin{itemize}
      \item $n$ items; for each item $j = 1, \dots, n$
        \begin{itemize}
          \item a weight $w_j \in \N^+$
          \item a width $l_j \in \N^+$
          \item a profit $p_j \in \N^+$
        \end{itemize}
      \item a capacity $C \in \N^+$
    \end{itemize}
  \item Problem: select a subset of items such that
    \begin{itemize}
      \item the total weight of the selected items does not exceed the knapsack capacity
    \end{itemize}
  \item Objective: maximize the total profit of the selected items minus the maximum width among the selected items
\end{itemize}

Propose and implement an algorithm based on Dynamic Programming for this problem.

\section{Heuristic Tree Search}

We consider the Knapsack problem with width and conflicts:
\begin{itemize}
  \item Input:
    \begin{itemize}
      \item $n$ items; for each item $j = 1, \dots, n$
        \begin{itemize}
          \item a weight $w_j \in \N^+$
          \item a width $l_j \in \N^+$
          \item a profit $p_j \in \N^+$
        \end{itemize}
      \item a capacity $C \in \N^+$
      \item a graph $G$ such that each node corresponds to an item
    \end{itemize}
  \item Problem: select a subset of items such that
    \begin{itemize}
      \item the total weight of the selected items does not exceed the knapsack capacity
      \item if there exists an edge between vertex $j_1$ and $j_2$ in $G$, then item $j_1$ and item $j_2$ must not be both selected
    \end{itemize}
  \item Objective: maximize the total profit of the selected items minus the maximum width among the selected items
\end{itemize}

Propose and implement an algorithm based on Heuristic Tree Search with Dynamic Programming for this problem.

\section{Column Generation \\ + Dynamic Programming}

We consider the Single machine batch scheduling problem with Makespan objective:
\begin{itemize}
  \item Input:
    \begin{itemize}
      \item $n$ jobs; for each job $j = 1, \dots, n$, a processing time $p_j \in \N^+$ and a size $s_j \in \N^+$
      \item a batch capacity $Q \in \N^+$
    \end{itemize}
  \item Problem: partition the jobs into batches and sequence the batches such that:
    \begin{itemize}
      \item each job must be in exactly one of the batches
      \item the processing time of a batch is equal to the longest processing time among all jobs it contains
      \item the total size of the jobs in a batch does not exceed its capacity
    \end{itemize}
  \item Objective: minimize the makespan of the schedule
\end{itemize}

Propose an exponential formulation and implement an algorithm based on a Column Generation heuristic for this problem.

\section{Column Generation \\ + Heuristic Tree Search}

We consider the Single machine batch scheduling problem with conflicts and Makespan objective:
\begin{itemize}
  \item Input:
    \begin{itemize}
      \item $n$ jobs; for each job $j = 1, \dots, n$, a processing time $p_j \in \N^+$ and a size $s_j \in \N^+$
      \item a batch capacity $Q \in \N^+$
      \item a graph $G$ such that each node corresponds to a job
    \end{itemize}
  \item Problem: partition the jobs into batches and sequence the batches such that:
    \begin{itemize}
      \item each job must be in exactly one of the batches
      \item the processing time of a batch is equal to the longest processing time among all jobs it contains
      \item the total size of the jobs in a batch does not exceed its capacity
      \item if there exists an edge between vertex $j_1$ and vertex $j_2$ in $G$, then job $j_1$ and job $j_2$ must not be in the same batch
    \end{itemize}
  \item Objective: minimize the makespan of the schedule
\end{itemize}

Propose an exponential formulation and implement an algorithm based on a Column Generation heuristic for this problem.

\end{document}

2021-2022 - M2 ORCO - Advanced OR/Projects/Batch scheduling/subject/main.tex