\chapter[Detailed examples of tactics]{Detailed examples of tactics\label{Tactics-examples}}

This chapter presents detailed examples of certain tactics, to
illustrate their behavior.

\section[\tt dependent induction]{\tt dependent induction\label{dependent-induction-example}}
\def\depind{{\tt dependent induction}~}
\def\depdestr{{\tt dependent destruction}~}

The tactics \depind and \depdestr are another solution for inverting
inductive predicate instances and potentially doing induction at the
same time. It is based on the \texttt{BasicElim} tactic of Conor McBride which
works by abstracting each argument of an inductive instance by a variable
and constraining it by equalities afterwards. This way, the usual
{\tt induction} and {\tt destruct} tactics can be applied to the
abstracted instance and after simplification of the equalities we get
the expected goals.

The abstracting tactic is called {\tt generalize\_eqs} and it takes as
argument an hypothesis to generalize. It uses the {\tt JMeq} datatype
defined in {\tt Coq.Logic.JMeq}, hence we need to require it before.
For example, revisiting the first example of the inversion documentation above:

\begin{coq_example*}
Require Import Coq.Logic.JMeq.
\end{coq_example*}
\begin{coq_eval}
Require Import Coq.Program.Equality.
\end{coq_eval}

\begin{coq_eval}
Inductive Le : nat -> nat -> Set :=
  | LeO : forall n:nat, Le 0 n
  | LeS : forall n m:nat, Le n m -> Le (S n) (S m).
Variable P : nat -> nat -> Prop.
Variable Q : forall n m:nat, Le n m -> Prop.
\end{coq_eval}

\begin{coq_example*}
Goal forall n m:nat, Le (S n) m -> P n m.
intros n m H.
\end{coq_example*}
\begin{coq_example}
generalize_eqs H.
\end{coq_example}

The index {\tt S n} gets abstracted by a variable here, but a
corresponding equality is added under the abstract instance so that no
information is actually lost. The goal is now almost amenable to do induction
or case analysis. One should indeed first move {\tt n} into the goal to
strengthen it before doing induction, or {\tt n} will be fixed in
the inductive hypotheses (this does not matter for case analysis).
As a rule of thumb, all the variables that appear inside constructors in
the indices of the hypothesis should be generalized. This is exactly
what the \texttt{generalize\_eqs\_vars} variant does:

\begin{coq_eval}
Undo 1.
\end{coq_eval}
\begin{coq_example}
generalize_eqs_vars H.
induction H.
\end{coq_example}

As the hypothesis itself did not appear in the goal, we did not need to
use an heterogeneous equality to relate the new hypothesis to the old
one (which just disappeared here). However, the tactic works just as well
in this case, e.g.:

\begin{coq_eval}
Admitted.
\end{coq_eval}

\begin{coq_example}
Goal forall n m (p : Le (S n) m), Q (S n) m p.
intros n m p ; generalize_eqs_vars p.
\end{coq_example}

One drawback of this approach is that in the branches one will have to
substitute the equalities back into the instance to get the right
assumptions. Sometimes injection of constructors will also be needed to
recover the needed equalities. Also, some subgoals should be directly
solved because of inconsistent contexts arising from the constraints on
indexes. The nice thing is that we can make a tactic based on
discriminate, injection and variants of substitution to automatically
do such simplifications (which may involve the K axiom).
This is what the {\tt simplify\_dep\_elim} tactic from
{\tt Coq.Program.Equality} does. For example, we might simplify the
previous goals considerably:
% \begin{coq_eval}
% Abort.
% Goal forall n m:nat, Le (S n) m -> P n m.
% intros n m H ; generalize_eqs_vars H.
% \end{coq_eval}

\begin{coq_example}
induction p ; simplify_dep_elim.
\end{coq_example}

The higher-order tactic {\tt do\_depind} defined in {\tt
  Coq.Program.Equality} takes a tactic and combines the
building blocks we have seen with it: generalizing by equalities
calling the given tactic with the
generalized induction hypothesis as argument and cleaning the subgoals
with respect to equalities. Its most important instantiations are
\depind and \depdestr that do induction or simply case analysis on the
generalized hypothesis. For example we can redo what we've done manually
with \depdestr:

\begin{coq_eval}
Abort.
\end{coq_eval}
\begin{coq_example*}
Require Import Coq.Program.Equality.
Lemma ex : forall n m:nat, Le (S n) m -> P n m.
intros n m H.
\end{coq_example*}
\begin{coq_example}
dependent destruction H.
\end{coq_example}
\begin{coq_eval}
Abort.
\end{coq_eval}

This gives essentially the same result as inversion. Now if the
destructed hypothesis actually appeared in the goal, the tactic would
still be able to invert it, contrary to {\tt dependent
 inversion}. Consider the following example on vectors:

\begin{coq_example*}
Require Import Coq.Program.Equality.
Set Implicit Arguments.
Variable A : Set.
Inductive vector : nat -> Type :=
| vnil : vector 0
| vcons : A -> forall n, vector n -> vector (S n).
Goal forall n, forall v : vector (S n),
  exists v' : vector n, exists a : A, v = vcons a v'.
  intros n v.
\end{coq_example*}
\begin{coq_example}
  dependent destruction v.
\end{coq_example}
\begin{coq_eval}
Abort.
\end{coq_eval}

In this case, the {\tt v} variable can be replaced in the goal by the
generalized hypothesis only when it has a type of the form {\tt vector
 (S n)}, that is only in the second case of the {\tt destruct}. The
first one is dismissed because {\tt S n <> 0}.

\subsection{A larger example}

Let's see how the technique works with {\tt induction} on inductive
predicates on a real example. We will develop an example application to the
theory of simply-typed lambda-calculus formalized in a dependently-typed style:

\begin{coq_example*}
Inductive type : Type :=
| base : type
| arrow : type -> type -> type.
Notation " t --> t' " := (arrow t t') (at level 20, t' at next level).
Inductive ctx : Type :=
| empty : ctx
| snoc : ctx -> type -> ctx.
Notation " G , tau " := (snoc G tau) (at level 20, tau at next level).
Fixpoint conc (G D : ctx) : ctx :=
  match D with
    | empty => G
    | snoc D' x => snoc (conc G D') x
  end.
Notation " G ; D " := (conc G D) (at level 20).
Inductive term : ctx -> type -> Type :=
| ax : forall G tau, term (G, tau) tau
| weak : forall G tau,
  term G tau -> forall tau', term (G, tau') tau
| abs : forall G tau tau',
  term (G , tau) tau' -> term G (tau --> tau')
| app : forall G tau tau',
  term G (tau --> tau') -> term G tau -> term G tau'.
\end{coq_example*}

We have defined types and contexts which are snoc-lists of types. We
also have a {\tt conc} operation that concatenates two contexts.
The {\tt term} datatype represents in fact the possible typing
derivations of the calculus, which are isomorphic to the well-typed
terms, hence the name. A term is either an application of:
\begin{itemize}
\item the axiom rule to type a reference to the first variable in a context,
\item the weakening rule to type an object in a larger context
\item the abstraction or lambda rule to type a function
\item the application to type an application of a function to an argument
\end{itemize}

Once we have this datatype we want to do proofs on it, like weakening:

\begin{coq_example*}
Lemma weakening : forall G D tau, term (G ; D) tau ->
  forall tau', term (G , tau' ; D) tau.
\end{coq_example*}
\begin{coq_eval}
  Abort.
\end{coq_eval}

The problem here is that we can't just use {\tt induction} on the typing
derivation because it will forget about the {\tt G ; D} constraint
appearing in the instance. A solution would be to rewrite the goal as:
\begin{coq_example*}
Lemma weakening' : forall G' tau, term G' tau ->
  forall G D, (G ; D) = G' ->
  forall tau', term (G, tau' ; D) tau.
\end{coq_example*}
\begin{coq_eval}
  Abort.
\end{coq_eval}

With this proper separation of the index from the instance and the right
induction loading (putting {\tt G} and {\tt D} after the inducted-on
hypothesis), the proof will go through, but it is a very tedious
process. One is also forced to make a wrapper lemma to get back the
more natural statement. The \depind tactic alleviates this trouble by
doing all of this plumbing of generalizing and substituting back automatically.
Indeed we can simply write:

\begin{coq_example*}
Require Import Coq.Program.Tactics.
Lemma weakening : forall G D tau, term (G ; D) tau ->
  forall tau', term (G , tau' ; D) tau.
Proof with simpl in * ; simpl_depind ; auto.
  intros G D tau H. dependent induction H generalizing G D ; intros.
\end{coq_example*}

This call to \depind has an additional arguments which is a list of
variables appearing in the instance that should be generalized in the
goal, so that they can vary in the induction hypotheses. By default, all
variables appearing inside constructors (except in a parameter position)
of the instantiated hypothesis will be generalized automatically but
one can always give the list explicitly.

\begin{coq_example}
  Show.
\end{coq_example}

The {\tt simpl\_depind} tactic includes an automatic tactic that tries
to simplify equalities appearing at the beginning of induction
hypotheses, generally using trivial applications of
reflexivity. In cases where the equality is not between constructor
forms though, one must help the automation by giving
some arguments, using the {\tt specialize} tactic for example.

\begin{coq_example*}
destruct D... apply weak ; apply ax. apply ax.
destruct D...
\end{coq_example*}
\begin{coq_example}
Show.
\end{coq_example}
\begin{coq_example}
  specialize (IHterm G0 empty eq_refl).
\end{coq_example}

Once the induction hypothesis has been narrowed to the right equality,
it can be used directly.

\begin{coq_example}
  apply weak, IHterm.
\end{coq_example}

If there is an easy first-order solution to these equations as in this subgoal, the
{\tt specialize\_eqs} tactic can be used instead of giving explicit proof
terms:

\begin{coq_example}
  specialize_eqs IHterm.
\end{coq_example}
This concludes our example.
\SeeAlso The induction \ref{elim}, case \ref{case} and inversion \ref{inversion} tactics.

\section[\tt autorewrite]{\tt autorewrite\label{autorewrite-example}}

Here are two examples of {\tt autorewrite} use. The first one ({\em Ackermann
function}) shows actually a quite basic use where there is no conditional
rewriting. The second one ({\em Mac Carthy function}) involves conditional
rewritings and shows how to deal with them using the optional tactic of the
{\tt Hint~Rewrite} command.

\firstexample
\example{Ackermann function}
%Here is a basic use of {\tt AutoRewrite} with the Ackermann function:

\begin{coq_example*}
Reset Initial.
Require Import Arith.
Variable Ack :
           nat -> nat -> nat.
Axiom Ack0 :
        forall m:nat, Ack 0 m = S m.
Axiom Ack1 : forall n:nat, Ack (S n) 0 = Ack n 1.
Axiom Ack2 : forall n m:nat, Ack (S n) (S m) = Ack n (Ack (S n) m).
\end{coq_example*}

\begin{coq_example}
Hint Rewrite Ack0 Ack1 Ack2 : base0.
Lemma ResAck0 :
 Ack 3 2 = 29.
autorewrite with base0 using try reflexivity.
\end{coq_example}

\begin{coq_eval}
Reset Initial.
\end{coq_eval}

\example{Mac Carthy function}
%The Mac Carthy function shows a more complex case:

\begin{coq_example*}
Require Import Omega.
Variable g :
           nat -> nat -> nat.
Axiom g0 :
        forall m:nat, g 0 m = m.
Axiom
  g1 :
    forall n m:nat,
      (n > 0) -> (m > 100) -> g n m = g (pred n) (m - 10).
Axiom
  g2 :
    forall n m:nat,
      (n > 0) -> (m <= 100) -> g n m = g (S n) (m + 11).
\end{coq_example*}

\begin{coq_example}
Hint Rewrite g0 g1 g2 using omega : base1.
Lemma Resg0 :
 g 1 110 = 100.
autorewrite with base1 using reflexivity || simpl.
\end{coq_example}

\begin{coq_eval}
Abort.
\end{coq_eval}

\begin{coq_example}
Lemma Resg1 : g 1 95 = 91.
autorewrite with base1 using reflexivity || simpl.
\end{coq_example}

\begin{coq_eval}
Reset Initial.
\end{coq_eval}

\section[\tt quote]{\tt quote\tacindex{quote}
\label{quote-examples}}

The tactic \texttt{quote} allows using Barendregt's so-called
2-level approach without writing any ML code. Suppose you have a
language \texttt{L} of
'abstract terms' and a type \texttt{A} of 'concrete terms'
and a function \texttt{f : L -> A}. If \texttt{L} is a simple
inductive datatype and \texttt{f} a simple fixpoint, \texttt{quote f}
will replace the head of current goal by a convertible term of the form
\texttt{(f t)}. \texttt{L} must have a constructor of type: \texttt{A
  -> L}.

Here is an example:

\begin{coq_example}
Require Import Quote.
Parameters A B C : Prop.
Inductive formula : Type :=
  | f_and : formula -> formula -> formula (* binary constructor *)
  | f_or : formula -> formula -> formula
  | f_not : formula -> formula (* unary constructor *)
  | f_true : formula (* 0-ary constructor *)
  | f_const : Prop -> formula (* constructor for constants *).
Fixpoint interp_f (f:
                   formula) : Prop :=
  match f with
  | f_and f1 f2 => interp_f f1 /\ interp_f f2
  | f_or f1 f2 => interp_f f1 \/ interp_f f2
  | f_not f1 => ~ interp_f f1
  | f_true => True
  | f_const c => c
  end.
Goal A /\ (A \/ True) /\ ~ B /\ (A <-> A).
quote interp_f.
\end{coq_example}

The algorithm to perform this inversion is: try to match the
term with right-hand sides expression of \texttt{f}. If there is a
match, apply the corresponding left-hand side and call yourself
recursively on sub-terms. If there is no match, we are at a leaf:
return the corresponding constructor (here \texttt{f\_const}) applied
to the term.

\begin{ErrMsgs}
\item \errindex{quote: not a simple fixpoint} \\
  Happens when \texttt{quote} is not able to perform inversion properly.
\end{ErrMsgs}

\subsection{Introducing variables map}

The normal use of \texttt{quote} is to make proofs by reflection: one
defines a function \texttt{simplify : formula -> formula} and proves a
theorem \texttt{simplify\_ok: (f:formula)(interp\_f (simplify f)) ->
  (interp\_f f)}. Then, one can simplify formulas by doing:
\begin{verbatim}
   quote interp_f.
   apply simplify_ok.
   compute.
\end{verbatim}
But there is a problem with leafs: in the example above one cannot
write a function that implements, for example, the logical simplifications
$A \land A \ra A$ or $A \land \lnot A \ra \texttt{False}$. This is
because the \Prop{} is impredicative.

It is better to use that type of formulas:

\begin{coq_eval}
Reset formula.
\end{coq_eval}
\begin{coq_example}
Inductive formula : Set :=
  | f_and : formula -> formula -> formula
  | f_or : formula -> formula -> formula
  | f_not : formula -> formula
  | f_true : formula
  | f_atom : index -> formula.
\end{coq_example*}

\texttt{index} is defined in module \texttt{quote}. Equality on that
type is decidable so we are able to simplify $A \land A$ into $A$ at
the abstract level.

When there are variables, there are bindings, and \texttt{quote}
provides also a type \texttt{(varmap A)} of bindings from
\texttt{index} to any set \texttt{A}, and a function
\texttt{varmap\_find} to search in such maps. The interpretation
function has now another argument, a variables map:

\begin{coq_example}
Fixpoint interp_f (vm:
                    varmap Prop) (f:formula) {struct f} : Prop :=
  match f with
  | f_and f1 f2 => interp_f vm f1 /\ interp_f vm f2
  | f_or f1 f2 => interp_f vm f1 \/ interp_f vm f2
  | f_not f1 => ~ interp_f vm f1
  | f_true => True
  | f_atom i => varmap_find True i vm
  end.
\end{coq_example}

\noindent\texttt{quote} handles this second case properly:

\begin{coq_example}
Goal A /\ (B \/ A) /\ (A \/ ~ B).
quote interp_f.
\end{coq_example}

It builds \texttt{vm} and \texttt{t} such that \texttt{(f vm t)} is
convertible with the conclusion of current goal.

\subsection{Combining variables and constants}

One can have both variables and constants in abstracts terms; that is
the case, for example, for the \texttt{ring} tactic (chapter
\ref{ring}). Then one must provide to \texttt{quote} a list of
\emph{constructors of constants}. For example, if the list is
\texttt{[O S]} then closed natural numbers will be considered as
constants and other terms as variables.

Example:

\begin{coq_eval}
Reset formula.
\end{coq_eval}
\begin{coq_example*}
Inductive formula : Type :=
  | f_and : formula -> formula -> formula
  | f_or : formula -> formula -> formula
  | f_not : formula -> formula
  | f_true : formula
  | f_const : Prop -> formula (* constructor for constants *)
  | f_atom : index -> formula.
Fixpoint interp_f
 (vm:            (* constructor for variables *)
  varmap Prop) (f:formula) {struct f} : Prop :=
  match f with
  | f_and f1 f2 => interp_f vm f1 /\ interp_f vm f2
  | f_or f1 f2 => interp_f vm f1 \/ interp_f vm f2
  | f_not f1 => ~ interp_f vm f1
  | f_true => True
  | f_const c => c
  | f_atom i => varmap_find True i vm
  end.
Goal
A /\ (A \/ True) /\ ~ B /\ (C <-> C).
\end{coq_example*}

\begin{coq_example}
quote interp_f [ A B ].
Undo.
  quote interp_f [ B C iff ].
\end{coq_example}

\Warning Since function inversion
is undecidable in general case, don't expect miracles from it!

\begin{Variants}

\item {\tt quote {\ident} in {\term} using {\tac}}

  \tac\ must be a functional tactic (starting with {\tt fun x =>})
  and will be called with the quoted version of \term\ according to
  \ident.

\item {\tt quote {\ident} [ \ident$_1$ \dots\ \ident$_n$ ] in {\term} using {\tac}}

  Same as above, but will use \ident$_1$, \dots, \ident$_n$ to
  chose which subterms are constants (see above).

\end{Variants}

% \SeeAlso file \texttt{theories/DEMOS/DemoQuote.v}

\SeeAlso comments of source file \texttt{plugins/quote/quote.ml}

\SeeAlso the \texttt{ring} tactic (Chapter~\ref{ring})

\section{Using the tactical language}

\subsection{About the cardinality of the set of natural numbers}

A first example which shows how to use the pattern matching over the proof
contexts is the proof that natural numbers have more than two elements. The
proof of such a lemma can be done as %shown on Figure~\ref{cnatltac}.
follows:
%\begin{figure}
%\begin{centerframe}
\begin{coq_eval}
Reset Initial.
Require Import Arith.
Require Import List.
\end{coq_eval}
\begin{coq_example*}
Lemma card_nat :
 ~ (exists x : nat, exists y : nat, forall z:nat, x = z \/ y = z).
Proof.
red; intros (x, (y, Hy)).
elim (Hy 0); elim (Hy 1); elim (Hy 2); intros;
 match goal with
 | [_:(?a = ?b),_:(?a = ?c) |- _ ] =>
     cut (b = c); [ discriminate | transitivity a; auto ]
 end.
Qed.
\end{coq_example*}
%\end{centerframe}
%\caption{A proof on cardinality of natural numbers}
%\label{cnatltac}
%\end{figure}

We can notice that all the (very similar) cases coming from the three
eliminations (with three distinct natural numbers) are successfully solved by
a {\tt match goal} structure and, in particular, with only one pattern (use
of non-linear matching).

\subsection{Permutation on closed lists}

Another more complex example is the problem of permutation on closed lists. The
aim is to show that a closed list is a permutation of another one.

First, we define the permutation predicate as shown in table~\ref{permutpred}.

\begin{figure}
\begin{centerframe}
\begin{coq_example*}
Section Sort.
Variable A : Set.
Inductive permut : list A -> list A -> Prop :=
  | permut_refl   : forall l, permut l l
  | permut_cons   :
      forall a l0 l1, permut l0 l1 -> permut (a :: l0) (a :: l1)
  | permut_append : forall a l, permut (a :: l) (l ++ a :: nil)
  | permut_trans  :
      forall l0 l1 l2, permut l0 l1 -> permut l1 l2 -> permut l0 l2.
End Sort.
\end{coq_example*}
\end{centerframe}
\caption{Definition of the permutation predicate}
\label{permutpred}
\end{figure}

A more complex example is the problem of permutation on closed lists.
The aim is to show that a closed list is a permutation of another one.
First, we define the permutation predicate as shown on
Figure~\ref{permutpred}.

\begin{figure}
\begin{centerframe}
\begin{coq_example}
Ltac Permut n :=
  match goal with
  | |- (permut _ ?l ?l) => apply permut_refl
  | |- (permut _ (?a :: ?l1) (?a :: ?l2)) =>
      let newn := eval compute in (length l1) in
      (apply permut_cons; Permut newn)
  | |- (permut ?A (?a :: ?l1) ?l2) =>
      match eval compute in n with
      | 1 => fail
      | _ =>
          let l1' := constr:(l1 ++ a :: nil) in
          (apply (permut_trans A (a :: l1) l1' l2);
            [ apply permut_append | compute; Permut (pred n) ])
      end
  end.
Ltac PermutProve :=
  match goal with
  | |- (permut _ ?l1 ?l2) =>
      match eval compute in (length l1 = length l2) with
      | (?n = ?n) => Permut n
      end
  end.
\end{coq_example}
\end{centerframe}
\caption{Permutation tactic}
\label{permutltac}
\end{figure}

Next, we can write naturally the tactic and the result can be seen on
Figure~\ref{permutltac}. We can notice that we use two toplevel
definitions {\tt PermutProve} and {\tt Permut}. The function to be
called is {\tt PermutProve} which computes the lengths of the two
lists and calls {\tt Permut} with the length if the two lists have the
same length. {\tt Permut} works as expected.  If the two lists are
equal, it concludes. Otherwise, if the lists have identical first
elements, it applies {\tt Permut} on the tail of the lists.  Finally,
if the lists have different first elements, it puts the first element
of one of the lists (here the second one which appears in the {\tt
  permut} predicate) at the end if that is possible, i.e., if the new
first element has been at this place previously. To verify that all
rotations have been done for a list, we use the length of the list as
an argument for {\tt Permut} and this length is decremented for each
rotation down to, but not including, 1 because for a list of length
$n$, we can make exactly $n-1$ rotations to generate at most $n$
distinct lists. Here, it must be noticed that we use the natural
numbers of {\Coq} for the rotation counter. On Figure~\ref{ltac}, we
can see that it is possible to use usual natural numbers but they are
only used as arguments for primitive tactics and they cannot be
handled, in particular, we cannot make computations with them. So, a
natural choice is to use {\Coq} data structures so that {\Coq} makes
the computations (reductions) by {\tt eval compute in} and we can get
the terms back by {\tt match}.

With {\tt PermutProve}, we can now prove lemmas as
% shown on Figure~\ref{permutlem}.
follows:
%\begin{figure}
%\begin{centerframe}

\begin{coq_example*}
Lemma permut_ex1 :
  permut nat (1 :: 2 :: 3 :: nil) (3 :: 2 :: 1 :: nil).
Proof. PermutProve. Qed.
Lemma permut_ex2 :
  permut nat
    (0 :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: nil)
    (0 :: 2 :: 4 :: 6 :: 8 :: 9 :: 7 :: 5 :: 3 :: 1 :: nil).
Proof. PermutProve. Qed.
\end{coq_example*}
%\end{centerframe}
%\caption{Examples of {\tt PermutProve} use}
%\label{permutlem}
%\end{figure}

\subsection{Deciding intuitionistic propositional logic}

\begin{figure}[b]
\begin{centerframe}
\begin{coq_example}
Ltac Axioms :=
  match goal with
  | |- True => trivial
  | _:False |- _  => elimtype False; assumption
  | _:?A |- ?A  => auto
  end.
\end{coq_example}
\end{centerframe}
\caption{Deciding intuitionistic propositions (1)}
\label{tautoltaca}
\end{figure}

\begin{figure}
\begin{centerframe}
\begin{coq_example}
Ltac DSimplif :=
  repeat
   (intros;
    match goal with
     | id:(~ _) |- _ => red in id
     | id:(_ /\ _) |- _ =>
         elim id; do 2 intro; clear id
     | id:(_ \/ _) |- _ =>
         elim id; intro; clear id
     | id:(?A /\ ?B -> ?C) |- _ =>
         cut (A -> B -> C);
          [ intro | intros; apply id; split; assumption ]
     | id:(?A \/ ?B -> ?C) |- _ =>
         cut (B -> C);
          [ cut (A -> C);
             [ intros; clear id
             | intro; apply id; left; assumption ]
          | intro; apply id; right; assumption ]
     | id0:(?A -> ?B),id1:?A |- _ =>
         cut B; [ intro; clear id0 | apply id0; assumption ]
     | |- (_ /\ _) => split
     | |- (~ _) => red
     end).
Ltac TautoProp :=
  DSimplif;
   Axioms ||
     match goal with
     | id:((?A -> ?B) -> ?C) |- _ =>
          cut (B -> C);
          [ intro; cut (A -> B);
             [ intro; cut C;
                [ intro; clear id | apply id; assumption ]
             | clear id ]
          | intro; apply id; intro; assumption ]; TautoProp
     | id:(~ ?A -> ?B) |- _ =>
         cut (False -> B);
          [ intro; cut (A -> False);
             [ intro; cut B;
                [ intro; clear id | apply id; assumption ]
             | clear id ]
          | intro; apply id; red; intro; assumption ]; TautoProp
     | |- (_ \/ _) => (left; TautoProp) || (right; TautoProp)
     end.
\end{coq_example}
\end{centerframe}
\caption{Deciding intuitionistic propositions (2)}
\label{tautoltacb}
\end{figure}

The pattern matching on goals allows a complete and so a powerful
backtracking when returning tactic values. An interesting application
is the problem of deciding intuitionistic propositional logic.
Considering the contraction-free sequent calculi {\tt LJT*} of
Roy~Dyckhoff (\cite{Dyc92}), it is quite natural to code such a tactic
using the tactic language as shown on Figures~\ref{tautoltaca}
and~\ref{tautoltacb}. The tactic {\tt Axioms} tries to conclude using
usual axioms. The tactic {\tt DSimplif} applies all the reversible
rules of Dyckhoff's system. Finally, the tactic {\tt TautoProp} (the
main tactic to be called) simplifies with {\tt DSimplif}, tries to
conclude with {\tt Axioms} and tries several paths using the
backtracking rules (one of the four Dyckhoff's rules for the left
implication to get rid of the contraction and the right or).

For example, with {\tt TautoProp}, we can prove tautologies like
 those:
% on Figure~\ref{tautolem}.
%\begin{figure}[tbp]
%\begin{centerframe}
\begin{coq_example*}
Lemma tauto_ex1 : forall A B:Prop, A /\ B -> A \/ B.
Proof. TautoProp. Qed.
Lemma tauto_ex2 :
   forall A B:Prop, (~ ~ B -> B) -> (A -> B) -> ~ ~ A -> B.
Proof. TautoProp. Qed.
\end{coq_example*}
%\end{centerframe}
%\caption{Proofs of tautologies with {\tt TautoProp}}
%\label{tautolem}
%\end{figure}

\subsection{Deciding type isomorphisms}

A more tricky problem is to decide equalities between types and modulo
isomorphisms. Here, we choose to use the isomorphisms of the simply typed
$\lb{}$-calculus with Cartesian product and $unit$ type (see, for example,
\cite{RC95}). The axioms of this $\lb{}$-calculus are given by
table~\ref{isosax}.

\begin{figure}
\begin{centerframe}
\begin{coq_eval}
Reset Initial.
\end{coq_eval}
\begin{coq_example*}
Open Scope type_scope.
Section Iso_axioms.
Variables A B C : Set.
Axiom Com : A * B = B * A.
Axiom Ass : A * (B * C) = A * B * C.
Axiom Cur : (A * B -> C) = (A -> B -> C).
Axiom Dis : (A -> B * C) = (A -> B) * (A -> C).
Axiom P_unit : A * unit = A.
Axiom AR_unit : (A -> unit) = unit.
Axiom AL_unit : (unit -> A) = A.
Lemma Cons : B = C -> A * B = A * C.
Proof.
intro Heq; rewrite Heq; reflexivity.
Qed.
End Iso_axioms.
\end{coq_example*}
\end{centerframe}
\caption{Type isomorphism axioms}
\label{isosax}
\end{figure}

A more tricky problem is to decide equalities between types and modulo
isomorphisms. Here, we choose to use the isomorphisms of the simply typed
$\lb{}$-calculus with Cartesian product and $unit$ type (see, for example,
\cite{RC95}). The axioms of this $\lb{}$-calculus are given on
Figure~\ref{isosax}.

\begin{figure}[ht]
\begin{centerframe}
\begin{coq_example}
Ltac DSimplif trm :=
  match trm with
  | (?A * ?B * ?C) =>
      rewrite <- (Ass A B C); try MainSimplif
  | (?A * ?B -> ?C) =>
      rewrite (Cur A B C); try MainSimplif
  | (?A -> ?B * ?C) =>
      rewrite (Dis A B C); try MainSimplif
  | (?A * unit) =>
      rewrite (P_unit A); try MainSimplif
  | (unit * ?B) =>
      rewrite (Com unit B); try MainSimplif
  | (?A -> unit) =>
      rewrite (AR_unit A); try MainSimplif
  | (unit -> ?B) =>
      rewrite (AL_unit B); try MainSimplif
  | (?A * ?B) =>
      (DSimplif A; try MainSimplif) || (DSimplif B; try MainSimplif)
  | (?A -> ?B) =>
      (DSimplif A; try MainSimplif) || (DSimplif B; try MainSimplif)
  end
 with MainSimplif :=
  match goal with
  | |- (?A = ?B) => try DSimplif A; try DSimplif B
  end.
Ltac Length trm :=
  match trm with
  | (_ * ?B) => let succ := Length B in constr:(S succ)
  | _ => constr:1
  end.
Ltac assoc := repeat rewrite <- Ass.
\end{coq_example}
\end{centerframe}
\caption{Type isomorphism tactic (1)}
\label{isosltac1}
\end{figure}

\begin{figure}[ht]
\begin{centerframe}
\begin{coq_example}
Ltac DoCompare n :=
  match goal with
  | [ |- (?A = ?A) ] => reflexivity
  | [ |- (?A * ?B = ?A * ?C) ] =>
      apply Cons; let newn := Length B in
                  DoCompare newn
  | [ |- (?A * ?B = ?C) ] =>
      match eval compute in n with
      | 1 => fail
      | _ =>
          pattern (A * B) at 1; rewrite Com; assoc; DoCompare (pred n)
      end
  end.
Ltac CompareStruct :=
  match goal with
  | [ |- (?A = ?B) ] =>
      let l1 := Length A
      with l2 := Length B in
      match eval compute in (l1 = l2) with
      | (?n = ?n) => DoCompare n
      end
  end.
Ltac IsoProve := MainSimplif; CompareStruct.
\end{coq_example}
\end{centerframe}
\caption{Type isomorphism tactic (2)}
\label{isosltac2}
\end{figure}

The tactic to judge equalities modulo this axiomatization can be written as
shown on Figures~\ref{isosltac1} and~\ref{isosltac2}. The algorithm is quite
simple. Types are reduced using axioms that can be oriented (this done by {\tt
MainSimplif}). The normal forms are sequences of Cartesian
products without Cartesian product in the left component. These normal forms
are then compared modulo permutation of the components (this is done by {\tt
CompareStruct}). The main tactic to be called and realizing this algorithm is
{\tt IsoProve}.

% Figure~\ref{isoslem} gives
Here are examples of what can be solved by {\tt IsoProve}.
%\begin{figure}[ht]
%\begin{centerframe}
\begin{coq_example*}
Lemma isos_ex1 :
  forall A B:Set, A * unit * B = B * (unit * A).
Proof.
intros; IsoProve.
Qed.

Lemma isos_ex2 :
  forall A B C:Set,
    (A * unit -> B * (C * unit)) =
    (A * unit -> (C -> unit) * C) * (unit -> A -> B).
Proof.
intros; IsoProve.
Qed.
\end{coq_example*}
%\end{centerframe}
%\caption{Type equalities solved by {\tt IsoProve}}
%\label{isoslem}
%\end{figure}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "Reference-Manual"
%%% End:


\section{Yuyan's study of SGD and Full GD}
There is numerical tests for sgd of fgd, dataset is Mnist.
\begin{center}
	\resizebox{\textwidth}{!}{
		\begin{tabular}{|l|r|r|r|r|r|}
			\hline
			Model $\backslash$ batch-size  &128(60 epoches)	&10000(60 epoches) &10000(120 epoches)&60000(60 epoches)	& 60000(120 epoches)  \\\hline
			2layer DNN				     &92.57	&91.88	 &92.26	&90.08 &91.09  \\\hline
			ResNet18 (channel 4-8-16-32) &99.20	&96.13 &98.19 &- &- \\ \hline
			ResNet18 (channel 8-16-32-64)&99.40 &97.86 & 98.64 &- &-\\ \hline
			LeNet						 &99.25 &99.12 &99.25  &- &-\\ \hline
		\end{tabular}
	}
\end{center}


\documentclass{scrartcl}

%\usepackage{natbib}
\usepackage{latexrc/macros}

\addbibresource{biblio.bib}

\title{Metastability for the Contact Process on $\integer$}
\author{Owen Lynch \and Kacper Urbański}
\DeclareMathOperator{\expDist}{Exp}

\usepackage{interval}
\newcommand{\ep}{\varepsilon}
\intervalconfig{soft open fences}
\newcommand{\loi}[2]{\interval[open left]{#1}{#2}}
\newcommand{\roi}[2]{\interval[open right]{#1}{#2}}
\newcommand{\Ninf}{\roi{-N}{\infty}}
\newcommand{\infN}{\loi{-\infty}{N}}
\begin{document}

\maketitle
\begin{abstract}
    Metastability is the coexistence of an equilibrium and a ``quasi-equilibrium'' (metastable) state in a system. If we look at a metastable system in time domain, it
    initially appears to have stabilized in the ``quasi-equilibrium'' state,
    until it suddenly relaxes to the true equilibrium. Metastability is a common phenomenon in nature, with examples ranging from physics to economics and social sciences.
    This work is a summary of a paper by R. Schonmann \cite{schonmann}, which
    frames this phenomenon as a rigorous property of an abstract interacting particle system--the contact process on $\integer$.
\end{abstract}

\section{Overview} \label{overview}

\subsection{Metastability}

Let $\{ \xi_N(t) \}_{N\in\mathbb{N}}$ be a family of Markov processes. The essential idea behind metastability is that, if we were to discretize (``coarse-grain'') time, increasing $N$ would make the process under consideration look more and more like the Markov process in \fref{fig:metastability_nutshell}.

\begin{figure}[h!]
  \centering
  \includegraphics{presentation_owen/metastable_coarse_grain.pdf}
  \caption{Metastability in a Nutshell}
  \label{fig:metastability_nutshell}
\end{figure}

In other words, the system begins in a so-called ``metastable state'', and has a very small chance to move to the stable state at any time. The stable state is either absorbing, or close-to absorbing; in the case that we will talk about in this paper, the stable state is absorbing.

In order to make this ``coarse-graining'' happen, we need two things to be true asymptotically.

\begin{enumerate}
  \item The hitting time of the stable state is exponentially distributed.
  \item Up until the hitting time, temporal means of measurements made to the process converge to an expectation of those measurements with respect to some stationary distribution.
\end{enumerate}

Informally, these two properties allow us to approximate the entire process by sampling from the stationary distribution up until the hitting time, and then putting the system in the absorbing state.

The difficulty comes in stating these two properties precisely. To do this, suppose that $T_{N}$ is the hitting time of the absorbing state, $\mu$ is the stationary distribution,
and $R_{N}$ is a ``time scale'' parameter that satisfies $R_{N}/\E T_{N} \to 0$. Then we rewrite the two properties more formally as

\begin{enumerate}
  \item $T_{N} / \E T_{N} \to \expDist(1)$ in distribution as $N \to \infty$.
  \item For any $f$ cylindrical,
    \[ \int_{S}^{S + R_{N}} f(\xi_{N}(t)) dt \to \mu(f) \]
    as $N \to \infty$, for any $S + R_{N} < T_{N}$.
\end{enumerate}

This second statement is still very imprecise, and actually mathematically meaningless as currently posed. Also, it turns out that we want a much stronger statement than that. However, we hope that this first statement should ``innoculate'' the reader to the precise statement, which is fairly dense on its own.

\subsection{The Contact Process on $\integer$}

We will use the ``percolation structure'' definition of the contact process, which lends itself better to certain useful constructions.

This ``percolation structure'', consists of for each $x \in \integer$
\begin{enumerate}
  \item A Poisson process $P_{x}$ with rate 1, which we call the ``death'' process at $x$.
  \item A Poisson process $P_{x \to x+1}$ with rate $\lambda$, which we call the ``right infection'' process at $x$.
  \item A Poisson process $P_{x \to x-1}$ with rate $\lambda$, which we call the ``left infection'' process at $x$.
\end{enumerate}

We consider $P_{x}$ to be a random element of $\powerset(\real)$, i.e. $t \in P_{x}$ if and only if the Poisson process ``ticks'' at time $t$.

We define a ``path'' between $(x,s), (y,t) \in \integer \by \real$ with $s \leq t$ to be a sequence
$(z_{0},r_{0}), \ldots, (z_{n},r_{n})$ with $r_{i} \leq r_{i+1}$ such that for all $(z_{i},r_{i}),(z_{i+1},r_{i+1})$, either
\begin{enumerate}
  \item $r_{i} = r_{i+1}$, $\abs{z_{i} - z_{i+1}} = 1$, and $r_{i} \in P_{z_{i} \to z_{i+1}}$. In this case, we are jumping laterally by one line at a time of infection.
  \item $z_{i} = z_{i+1}$, and $[r_{i},r_{i+1}] \cap P_{z_{i}} = \emptyset$. In this case, we are moving along a vertical line, uninterrupted by any deaths.
\end{enumerate}

Define $\xi^{A}(t)$ to be the set of $y$ such that there is a path from $(x,0)$ to $(y,t)$ for some $x \in A$. If the superscript is omitted, then we assume $A = \integer$, i.e. $\xi(t) = \xi^{\integer}(t)$.

For any $A \ins B$, we define $\xi_{B}^{A}(t)$ to be the set of $y$ such that there is a path from $(x,0)$ to $(y,t)$ for some $x \in A$ that stays entirely within $B$. As a special case, we let $\xi_{N}^{A}(t) = \xi_{[-N,N]}^{A}$, for $N \in \natural$. Note that $\xi_{B}$ takes values exclusively in $\powerset(B)$.

One of the most important facts about the contact process is that there is a critical value of $\lambda$, $\lambda_{c}$. For $\lambda < \lambda_{c}$, $\xi(t)$ has a unique extremal invariant measure $\delta_{\emptyset}$. At $\lambda = \lambda_{c}$ the system undergoes a phase transition - for $\lambda > \lambda_{c}$, another extremal invariant measure $\mu$ appears, with the property that
\[ \mu(f) = \limas_{T \to \infty} \frac{1}{T} \int_{0}^{T} \E f(\xi(t)) \dd{t} \]
This measure is not concentrated at $\emptyset$.

For $\xi_{N}(t)$, the only invariant measure is $\delta_{\emptyset}$, because $\emptyset$ is a trap and $\xi_{N}$ takes values on a finite state space. However, as mentioned before, for $\lambda > \lambda_{c}$ an analogue of a phase transition takes place. The system starts being metastable, and stays distributed \emph{approximately} as $\mu$, before a sudden fluctuation takes it to $\emptyset$.

We assume that the reader has a general familiarity with the contact process, and thus we will use some properties later on in the proofs without explicitly discussing them here.

\subsection{Summary}

The object of this paper is to give an overview of the two conditions for metastability for the family of contact processes $\xi_{N}$, in the supercritical regime $\lambda > \lambda_{c}$.

\section{Main Theorems}

\subsection{Exponential Distribution of Hitting Time}

\begin{theorem}[from \cite{schonmann}]
  If $T_{N} = \inf\set{t > 0 \st \xi_{N}(t) \neq \emptyset}$, then
  \[ \frac{T_{N}}{\E T_{N}} \to \expDist(1) \]
  in distribution.
\end{theorem}

To prove this, we first replace $\E T_{N}$ by the unique (by monotonicity) $\beta_{N}$ such that $\Prob(T_{N} > \beta_{N}) = \e^{-1}$. At the end, we will show that $\frac{\E T_{N}}{\beta_{N}} \to 1$.

Let $G_{N}(t) = \Prob[\frac{T_{N}}{\beta_{N}} > t]$, the cumulative distribution function of $T_{N}/\beta_{N}$. Similarly, let $G_{N}^{A}(t) = \Prob[\frac{T^{A}_{N}}{\beta_{N}} > t]$. Note that $G_{N}^{A}(t) \leq G_{N}(t)$ To show that $T_{N}/\beta_{N}$ converges in distribution to $\expDist(1)$, we must show that $G_{N}(t) \to \e^{-t}$. This can be accomplished by showing that
\[ \limas_{N \to \infty} \abs{G_{N}(t+s) - G_{N}(t)G_{N}(s)} = 0 \]
for all $t,s > 0$.

%Note that $G_{N}(t) = \Prob[\xi_{N}(t) \neq \emptyset]$, as $\xi_{N}$ is ``alive'' at time $t$ if and only if $T_{N} > t$. Thus,
%
%\begin{align*}
%  G_{N}(t+s) &= \Prob[\xi_{N}(t+s) \neq \emptyset] \\
%             &= \sum_{A \neq \emptyset} \Prob[\xi_{N}(t+s) \neq \emptyset | \xi_{N}(t) = A] \Prob[\xi_{N}(t) = A] \\
%             &= \sum_{A \neq \emptyset} G_{N}^{A}(s) \Prob[\xi_{N}(t) = A] \\
%             &\leq G_{N}(s) \sum_{A \neq \emptyset} \Prob[\xi_{N}(t) = A] \\
%             &= G_{N}(s) G_{N}(t)
%\end{align*}
%
%Therefore, we are looking to show that $G_{N}(s) G_{N}(t) - G_{N}(t+s) \to 0$ (we can forget the absolute value signs).

It is at this point that we introduce a curious little construction, which seems to not make much sense at first but turns out to be the key to the entire proof. Define $F_{b}$ for $b > 0$ by
\[ F_{b} = \left\{A \ins \integer \st \frac{\abs{A \cap [-b,-1]}}{b} > \frac{\rho}{2}, \frac{\abs{A \cap [1,b]}}{b} > \frac{\rho}{2}\right\} \]
where $\rho = \mu(\set{\eta \st \eta(0) = 1})$.

It is not trivial to show that
\begin{align*}
  \abs{G_{N}(t)G_{N}(s) - G_{N}(t+s)} &\leq \Prob[\xi_{N}(\beta_{N}t) \neq \emptyset] - \min_{A \in F_{b}} \Prob[\xi_{N}^{A}(\beta_{N}t) \neq \emptyset] \\
  &\quad \quad + \Prob[\xi_{N}(\beta_{N}s) \neq \emptyset, \xi_{N}(\beta_{N}s) \notin F_{b}]
\end{align*}
However, the proof is not terribly interesting, and so we refer the reader to Schonman for the details.

The intuition for what this equation is claiming is that we can show that starting in $A \in F_{b}$ is not too different from starting in $[-N,N]$, and we can show that ending \emph{anywhere} non-empty is not too different from ending up somewhere in $F_{b}$. Then a typical process will have probability $G_{N}(t)$ to end up in $A \in F_{b}$ at time $\beta_{N}t$, and then probability $G_{N}(s)$ to end up anywhere non-empty at time $\beta_{N}(t+s)$, starting in some $A \in F_{b}$, so total probability to end up non-empty at time $\beta_{N}(t+s)$ is $G_{N}(t)G_{N}(s)$, as required.

We will have finished if for any $\ep > 0$, we can find $b(\ep)$ and $N(\ep) > b(\ep)$  such that for $N \geq N(\ep)$ and $A \in F_{b}$, we have both
\begin{align}
  \Prob[\xi_{N}(\beta_{N}t) \neq \emptyset] - \Prob[\xi_{N}^{A}(\beta_{N}t) \neq \emptyset] = G_{N}(t) - G_{N}^{A}(t) &< \ep \label{eq:firstineq} \\
  \Prob[\xi_{N}(\beta_{N}s) \neq \emptyset, \xi_{N}(\beta_{N}s) \notin F_{b}] &< \ep \label{eq:secondineq}
\end{align}

We tackle \eref{eq:firstineq} first. Remember that $\xi_{N}(t)$ and $\xi_{N}^{A}$ are defined on the same percolation structure. Therefore, $\xi_{N}(t) \supset \xi_{N}^{A}(t)$, so we have
\[ \Prob[\xi_{N}(\beta_{N} t) \neq \emptyset] - \Prob[\xi_{N}(\beta_{N} t) \neq \emptyset] = \Prob[\xi_{N}(\beta_{N} t) \neq \emptyset, \xi_{N}^{A}(\beta_{N} t) = \emptyset] \leq \Prob[T_{N} \neq T_{N}^{A}] \]

We discussed this proof in the presentation. In short, at a certain time $t$, $\xi_{N}(t) = \xi_{N}^{A}(t) \neq \emptyset$, and by picking $b$ large enough, we can ensure that the process is most likely still alive at this time. Then because of the percolation structure definition, for all $s > t$, $\xi_{N}(s) = \xi_{N}^{A}(s)$, whence $T_{N} = T_{N}^{A}$ with probability greater than $1 - \ep$.

Equation~\ref{eq:secondineq} also relies crucially on the percolation structure. Because of the percolation structure, as long as $\xi_{N}(t) \neq \emptyset$
\[ \xi_{N}(t) = \xi(t) \cap [\min \xi_{N}(t), \max \xi_{N}(t)] \]
To make use of this, we say that $\xi_{N}(t)$ is ``wide'' if $\min \xi_{N}(t) < -N + L$, $\max \xi_{N}(t) > N - L$, for some fixed $L$. Then as long as $[-b,b] \ins [-N+L, N-L]$, for wide $\xi_{N}(t)$, $\xi_{N}(t) \in F_{b}$ if and only if $\xi(t) \in F_{b}$. Now, let $D_{b} = F_{b}^{C} \setminus \set{\emptyset}$.
\begin{align*}
  \Prob[\xi_{N}(\beta_{N}s) \in D_{b}] \leq&\; \Prob[\xi_{N}(\beta_{N}s) \in D_{b}, \min \xi_{N}(\beta_{N}s) < -N + L, \max \xi_{N}(\beta_{N}s) > N - L] \\
                                &+ \Prob[\min \xi_{N}(\beta_{N}s) \geq -N + L, \xi_{N}(\beta_{N}s) \neq \emptyset] \\
                                &+ \Prob[\max \xi_{N}(\beta_{N}s) \leq N - L, \xi_{N}(\beta_{N}s) \neq \emptyset]
\end{align*}
By what we noted earlier, the first term is less than $\Prob(\xi(\beta_{N}s) \in D_{b})$, and we can pick $b$ such that this is less than $\frac{\ep}{3}$.

It remains to minimize the last two terms; by symmetry we only show how to minimize the first. Using a percolation structure argument, it is easy to show that as long as $\xi_{N}(\beta_{N}s) \neq \emptyset$, $\min \xi_{N}(t) = \min \xi_{\Ninf}$. Therefore,
\begin{align*}
  \Prob[\min \xi_{N}(\beta_{N}s) \geq -N + L, \xi_{N}(\beta_{N}) \neq \emptyset] &\geq \Prob[\min \xi_{\Ninf} \geq -N+L] \\
  &\geq \mu_{\Ninf}\set{A \in \Ninf \st A \cap [-N,-N+L-1] = \emptyset}
\end{align*}
We can pick $L$ large enough to make that last term less than $\frac{\ep}{3}$, and we have shown that everything can be made as small as we like, so we are done.

The last thing to do is to show that $\beta_{N}/\E T_{N} \to 1$; this follows from the above proof, as the unique $\beta$ such that $\Prob[\mathrm{Exp}(1) > \beta] = e^{-1}$ is $1 = \E[\mathrm{Exp}(1)]$.

\subsection{Quasi-stationarity up to the Hitting Time}

Recall our initial description of Quasi-stationarity in Section \ref{overview}. To make it more precise, we will define
\begin{description}
    \item[the intermediate timescale] to be a choice of $R_{N} \in \real_{+}$ with $R_{N}/\E[T_{N}] \to 0$
    \item[an observable quantity] to be a cylindrical (local) $f:\{0,1\}^\mathbb{Z} \rightarrow \mathbb{R}$
    \item[the temporal mean] of observable quantity $f$ to be
    \[
        A^N_{R_N}(s, f) := R_N^{-1}\int_s^{s+R_N}f(\xi_N(t))dt
    \]
    \item[the fixed probability distribution] to be $\mu$ (the upper invariant measure of $\xi(t)$)
\end{description}
Note that $A^N_{R_N}$ is a random variable. We will say that this quantity is \emph{close} to $\mu(f)$ if the two converge in probabilty when $N \rightarrow \infty$.

It seems like the definitions given above would be sufficient to make our natural language definition of metastability formal. However, it turns out that an additional technical
condition is needed. Define
    \[
        \Lambda(f) :=  \text{ smallest } B\subset \mathbb{Z} \text{ s.t. } f(A) = f(A\cap B) \ \forall A \subset \mathbb{Z}
    \]
    Although this is not strictly true, we can think of $\Lambda(f)$ as the ``support'' of $f$.

Our theorem will hold for a specific $L(\varepsilon, f) \in \mathbb{N}$, and we need to have that
\[
    L < N \text{~~and~~} \Lambda(f) \subset [-N+L, N-L]
\]
Notice that $L$ does not depend on $N$. Thus, since we chose to grow $N \rightarrow \infty$, having to choose this $L$ doesn't restrict our choice of $f$ - it merely sets the minimum
 $N$ we can consider.

 We're now ready to give a simplified formulation of what we mean by ``quasi-stationarity''
 \begin{theorem} [from \cite{schonmann}]
        If $\lambda > \lambda^*$ there is a sequence $\{R_N\}_{N \in \mathbb{N}} \subset \mathbb{R_+}$ such that:
        \begin{enumerate}[(a)]
            \item $R_N/\beta_N \rightarrow 0$ as $N\rightarrow \infty$
            \item For all $\varepsilon > 0$ and $f:\{0,1\}^\mathbb{Z} \rightarrow \mathbb{R}$ cylindrical,  $\exists L(\varepsilon, f) \in \mathbb{N}$ such that
                  \[
                      \mathbb{P}\left[ \max_{\mathbb{N}_0 \ni k < K_N}|A_{R_N}(kR_N, f) - \mu(f)| > \varepsilon\right] \rightarrow 0
                  \]
                  as $N \rightarrow \infty$, where $K_N = \max\{k \in \mathbb{N}_0: kR_N < T_N\}$ and $\Lambda(f) \subset [-N + L, N - L] \cap \mathbb{Z}$
        \end{enumerate}
    \end{theorem}

A full proof of this statement is beyond the scope of this article--we will merely give the reader some insight into its key points.

A central claim is that we can make the exceedance probability (given below) arbitrarily small.
\[
    \mathbb{P}\left[ |A_{R_N}(kR_N, f) - \mu(f)| > \varepsilon\right]
\]
We do so in a way which is uniform across all values of $K_N$ and $\mathbb{N}_0 \ni k < K_N$. We estimate this probabilty with a triangle inequality.
\footnotesize
\begin{equation}
    \mathbb{P}\left[ \left|R_N^{-1}\int_{kR_N}^{(k+1)R_N}f(\xi(t))dt - \mu(f)\right| > \varepsilon/2 \right] +
    \mathbb{P}\left[ \left|R_N^{-1}\int_{kR_N}^{(k+1)R_N}f(\xi_N(t)) - f(\xi(t))dt \right| > \varepsilon/2\right]
    \label{th2:alternative}
\end{equation}
\normalsize
The first term can be made arbitrarily small, as a consequence of $\xi(t) \rightharpoonup \mu(f)$ and exponentially decaying temporal correlations of $\xi(t)$.

To shrink the second term in (\ref{th2:alternative}) we make extensive use of the graphical model construction of the Contact Process. As before, we say $\xi_N(t)$ is \emph{wide} at $t$ if $\min \xi_N(t) < -N + L\ \land\ \max\xi_N(t) > N - L$.
By the fact that we construct all processes on the same percolation structure, and that interactions are between nearest neighbours, we have
\begin{lemma}[Shielding by a wide process]
    If $\xi_N(t)$ is wide at $t$, then \[\xi_N(t) = \xi(t)\text{ on }[-N + L, N - L] \cap \mathbb{Z}\]
    In particular, since $\Lambda(f) \subset [-N+L, N-L]$, we have $f(\xi_N(t)) = f(\xi(t))$
\end{lemma}
Thus, the second term of (\ref{th2:alternative}) will go to 0 if we're able to make it arbitrarily likely for $\xi_N$ to be wide. For any given $N$, it is clear that we can find such an $L$, but we must show that we can find a $L$ that works for all $N$.

To show this, we again make use of the percolation structure. Note that near $-N$, $\xi_N$ will ``look similar'' to $\xi_{\Ninf}$ (this is true as long as $\xi_N$ is alive). By the same reasoning, $\xi_N$ will ``look similar'' to $\xi_{\infN}$ near $N$.
Hence we set $L$ such that
    \[
        \mu_{\Ninf}\left( \left\{ A : A \cap [-N,-N+L] = \varnothing \right\} \right)  \leq \varepsilon/(16\norm{f})
    \]
This makes all possible states of $\xi_N$ that do not intersect $[-N, -N+L]$ very unlikely (by ``looking similar'' to $\xi_{\Ninf}$). By symmetry, this also makes states
that do not intersect $[N-L, N]$ very unlikely. As a final stroke, we use translation invariance to notice that we will get exactly the same effect if we set $L$
    \[
        \mu_{\roi{0}{\infty}}\left( \left\{ A : A \cap [0,L] = \varnothing \right\} \right) \leq \varepsilon/(16\norm{f})
    \]
This concludes our overview of the proof of Theorem 2.

\printbibliography

\end{document}


\subsection{\soarb{numeric-indifferent-mode}}
\label{numeric-indifferent-mode}
\index{numeric-indifferent-mode}
Select method for combining numeric preferences.
\subsubsection*{Synopsis}
numeric-indifferent-mode [-as]
\end{verbatim}
\subsubsection*{Options}
\hline
\soar{\soar{\soar{ -a, --avg, --average }}} & Use average mode (default).  \\
\hline
\soar{\soar{\soar{ -s, --sum }}} & Use sum mode.  \\
\hline
\end{tabular}
\subsubsection*{Description}
 The numeric-indifferent-mode command is used to select the method for combining numeric preferences. This command is only meaningful in indifferent-selection --random  mode.
 The default procedure is \textbf{--avg}
\item  If the operator has at least one numeric preference, assign it the value that is the average of all of its numeric preferences.
\item  If the operator has no numeric preferences (but has been included in the indifferent selection through some combination of non-numeric preferences), assign it the value 50.
\end{itemize}
 The intended range of numeric-preference values for \textbf{--avg}
 mode is 0-100.
 The other combination option \textbf{--sum}
\item  Add together any numeric preferences for the operator (defaulting to 0 if there are none).
\item  Assign the operator the value e\^{}\{PreferenceSum / AgentTemperature\}, where AgentTemperature is a compile-time constant currently set at 25.0.
\end{itemize}
 Any real-numbered preference may be used in \textbf{--sum}
 mode.
 Once a value has been computed for each operator, the next operator is selected probabilistically, with each candidate operator's chance weighted by its computed value.


%This is a LATEX document

%\documentstyle[leqno]{article}
\documentclass[a4paper, 11pt]{amsart}
\usepackage{color}
\usepackage{comment}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in}
\setlength{\textwidth}{6.5in}
\setlength{\topmargin}{0.0in}
\setlength{\textheight}{8.5in}
\renewcommand{\arraystretch}{1.5}

%\newcommand{\be}{\begin{equation}}
%\newcommand{\ee}{\end{equation}}

\newcommand{\calO}{{\cal O}}
\newcommand{\calL}{{\cal L}}
\newcommand{\calG}{{\cal G}}
\newcommand{\calH}{H }
\newcommand{\calM}{{\cal M}}
\newcommand{\calS}{{\cal S}}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollaire}[theorem]{Corollaire}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{question}{Question}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{definition and theorem}[theorem]{Definition and
Theorem}
\newtheorem{theoreme_et_definition}[theorem]{Th\'eor\`eme et d\'efinition}
\newtheorem{remarque}[theorem]{Remarque}
\newtheorem{remark}[theorem]{%$^* $
Remark}
\newtheorem{*remark}[theorem]{$^* $Remark}
\newtheorem{exercice}[theorem]{Exercice}
\newtheorem{*exercise}[theorem]{$^* $Exercise}
\newtheorem{**exercise}[theorem]{$^{** } $Exercise}
\newtheorem{exemple}[theorem]{Exemple}
\newtheorem{exemples}[theorem]{Exemples}
\newtheorem{propriertes}[theorem]{Propri\'ertes}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{spv}[theorem]{Sneak preview}
%\parindent0pt

\excludecomment{versionA}
%\includecomment{versionA}

\excludecomment{versionAA}
%\includecomment{versionAA}

\begin{document}

\title[IP for regime-switching stochastic vol models]{Inverse problems for derivative pricing in regime switching volatility models \\
    (hidden Markov model for volatility)
}

\author{Raymond Brummelhuis, Serge-Andr\'e Masson}

\maketitle

\section{\bf Introduction}

For local volatility models of option pricing (that is, models for which the instantaneous volatility is a function of the underlying asset and of time only) it has been known since Dupire \cite{Du} that knowledge, at some given date, of all European call options prices for all possible maturities and strikes allows one to reconstruct the local volatility function. It is natural to ask whether a similar result can be true for more general stochastic volatility models in which the volatility process has an independent component from the stochastic process which drives the stock price changes (or, if one prefers and in a Brownian motion setting, models for which volatility changes are not perfectly correlated with price changes). More generally, anticipating a possibly negative answer to this question, one can ask to what extend European call prices for all possible maturities and strikes determine the (parameters of the) volatility process. In this paper we examine this question for models in which the volatility is driven by a not directly observable finite state continuous-time Markov chain.

\section{\bf The model}

$\Rightarrow $ Literature-review: Elliott and co-authors, others (?) \textcolor{blue}{  - \`a faire}
\medskip

\subsection{The Regime-Switching Stochastic Vol or RSSV model} Let $(X_t )_{t \geq 0 } $ be a continuous time Markov chain with finite state space  $\{ 1, \ldots , N \} $, and risk-neutral transition probability rates $q_{ij } $ defined by
\begin{equation}
    \mathbb{P } (X_{t + dt } = j | X_t = i ) = \delta _{ij } + q_{ij } dt
\end{equation}
where $\mathbb{P } $ will denote the risk-neutral probability selected by the market for pricing traded assets.
\medskip

\textcolor{blue}{{\bf Commentaires}:
    \begin{itemize}
        \item Une fa\c con plus  propre de formuler ceci: $\mathbb{P } (X_{t + h } = j | X_t = i ) = \delta _{ij } + q_{ij }  h + o(h) $, $h \to 0 $
        \item Attention: changement de notation par rapport \`a celle utilis\'ee auparavant: $q_{ij } $ en lieu de $a_{ji } $
        \item Faire une r\'emarque sur les diff\'erentes probabilit\'es risque-neutres? Le mod\`ele (\ref{eq:RSSV_model}) avec un drift $\nu $ (plus un actif sans risque - compte en banque) n'est pas compl\`et.
    \end{itemize}
}
\medskip

We consider options written on a frictionlessly traded asset  whose risk-neutral price dynamics is given by
\begin{equation} \label{eq:RSSV_model}
    dS_t = r S_t dt + \sigma (X_t ) S_t dW_t ,
\end{equation}
where $r $ is the constant risk-free rate and $\sigma : \{ 1 , \ldots , N \} \to \mathbb{R } $ is some given function. We suppose that the Brownian motion $(W_t )_{t \geq 0 } $ is independent of the Markov chain $(X_t )_{t \geq 0 } . $
We note that the process $(S_t )_{t \geq 0 } $ has a.s. continuous trajectories (so we don't have to write $S_{t- } $ instead of $S_t $): the jumps are in the, not directly observable, instantaneous volatilities.

\begin{remark} \rm{We could also work directly with the Markov chain $\sigma _t  := \sigma (X_t ) $, whose state space is $\{ \sigma _1 , \ldots , \sigma _N \} $ where $\sigma _j = \sigma (j) \} $ and (infinitessimal) transition probabilities
        $$
            \mathbb{P } (\sigma _{t + dt } = \sigma _j | \sigma _t = \sigma _k ) = \delta _{ij } + q_{ij } dt .
        $$
        One advantage of using a hidden Markov process $X_t $ defined on an abstract state space is that the model then naturally extends to include for example stochastic risk-free interest rates, by specifying a second function $r : E \to \mathbb{R } $ and specifying price dynamics by
        $$
            dS_t = r(X_t ) S_t dt + \sigma (X_t) S_t dW_t .
        $$
        Similarly, one could add state-dependend dividend rates. As before, sample paths of $(S_t )_{t \geq 0 } $ are a.s. continuous: the jumps are in the (Ito-) derivatives of $S_t . $  For now we will take $r $ constant, and concentrate on the regime-switching stochastic volatilty model (\ref{eq:RSSV_model}).
    }
\end{remark}

\subsection{Derivative pricing in RSSV models} As explained in the introduction, we are interested in the inverse problem of determining the model parameters $\sigma _i $, $q_{ij } $ from observed European call option prices for all strikes and maturities. To that effect, we start by reviewing European option pricing in our model. The problem of option pricing in regime-switching models (not only models for stochastic volatility but also for example interest rate en credit risk models) has drawn a lot attention in the mathematical finance literature, notably in papers by Robert Elliott and his co-authors: see \textcolor{blue}{ [add string of references papers by Elliott et al]} and also \textcolor{blue}{[other papers?]}. The majority of these are concerned with the direct problem of computing option prices for a given set of parameters, though some papers also examine calibration issues: see for example Xi, Rodrigo and Mamo \cite{XRM} We will review the PDE approach to pricing, which for the model (\ref{eq:RSSV_model}) amounts to solving a system of PDEs for the option prices in the different Markov-chain states. We then, following an idea of \cite{XRM} derive a Dupire-type equation for call-option prices as function of strike and maturity.
\medskip

By risk-neutral pricing, a European derivative written on the asset $S_t $ and paying off an amount of $F(S_T ) $ at its maturity $T $ will have a time-$t $ price given by the discounted risk-neutral expectation
\begin{equation}
    V_t = \mathbb{E } \left(  e^{- r (T - t ) } F(S_T ) | \mathcal{F }^{S, X } _t \right) %\mathbb{E } \left( e^{- r (T - t ) } F(S_T ) | S_t = S, X_t = i \right) ,
\end{equation}
where $\mathcal{F }^{S, X } _t $ is the filtration generated by the process $(S_t, X_t )_{t \geq 0 } . $ Since the latter is Markov, we have that $V_t = V (S_t, X_t , t ) $, where
\begin{equation} \label{eq:European_option_price}
    V(S, i , t ) = \mathbb{E } \left( e^{- r (T - t ) } F(S_T ) | S_t = S, X_t = i \right) , i = 1, \ldots , N ,
\end{equation}
remembering that $X_t \in \{ 1 , \ldots , N \} . $ It will be convenient to collect these $N $ functions into a column vector
$$
    V(S, t ) := (V(S, 1 , t ) , \ldots , V(S, N , t )^T
$$
$^T $ standing for "transpose", and we will consequently write $V_i (S, t ) $ for $V(S, i , t ) . $
\medskip

The prices $V_i (S , t ) $ satisfy a system of PDEs.

\begin{theorem} \label{thm:Dynkin} Suppose that $f = f(S, X, t ) $ is a $C^{2, 1 } $-function\footnote{two times continuously differentiable with respect to $S $, once with respect to $t $} on $\mathbb{R } \times \{ 1 , \ldots , N \} \times \mathbb{R } . $ Then
    \begin{eqnarray} \label{eq:Dynkin}
        &&\mathbb{E } \left( df (S_t , X_t , t ) | S_t  = S , X_t = i \right) \\
        &=&= \left( \partial _t f (S , i , t ) + r S \partial _S f (S, i, t ) + \frac{1 }{2 } \sigma (i)^2 S ^2 \partial _S ^2 f (S, i , t ) + \sum _{j = 1 } ^N q_{ij }f (S , j , t ) \right) dt . \nonumber
    \end{eqnarray}
\end{theorem}

\noindent {\it Proof}. Conditioning first on the Markov chain at $t + dt $ and using that the Markov chain is, by assumption, independent of the Brownian motion, we have
\begin{eqnarray} \nonumber
    \mathbb{E } (f(S_{t + dt } , X_{t + dt }, t ) \, | S_t = S, X_t = i ) &=& \mathbb{E } \left( \mathbb{E } (f (S_{t + dt } , X_{t + dt } , t ) \,  | X_{t + dt } ) | S_t =S , X_t = i \right) \\
    &=& \mathbb{E } \left( \sum _{j = 1 } ^N f(S_{t + dt } , j , t ) (\delta _{ij } + q_{ij } dt ) \, | S_t = S \right) \nonumber \\
    &=& \sum _{j = 1 } ^N \mathbb{E } \left( f(S + r S dt + \sigma _j S dW_t , j ) \right) (\delta _{ij } + q_{ij } dt ) , \label{proof_Dynkin}
\end{eqnarray}
since to order $dt $ there can be at most on jump in $[t, t + dt ] . $ By Ito's lemma,
$$
    \mathbb{E } \left( f(S + r S dt + \sigma _j S dW_t , j , t ) \right) = f(S, j , t ) + \left( \partial _t f + r S \partial _S f + \frac{1 }{2 } \sigma _j ^2 \partial _S ^2 f \right) dt ,
$$
with $f $'s derivatives all evaluated in $(S, j, t ) . $ Substituting this into (\ref{proof_Dynkin}) and using that $ (dt)^2 = 0 $, we see that only the terms $f(S, j , t ) q_{ij } dt $ and $f(S , i , t ) + \left( \partial _t f + r S \partial _S f + \frac{1 }{2 } \sigma _j ^2 \partial _S ^2 f \right) dt $ remain which, after subtracting $f(S , i , t ) $, proves (\ref{eq:Dynkin}). \hfill $\Box $
\medskip

Assuming we would know that the $V _i (S, t ) $ are $C^{2, 1 } $ as a function of $S $ and $t $, the fact that $e^{-r t } V(S_t, X_t , t ) $ is a martingale, and therefore has drift 0, and theorem \ref{thm:Dynkin} applied to $e^{- r t } V_i (S, t ) $ immediately implies that they must satisfy the system of PDEs
\begin{equation} \label{eq:pricing_PDE}
    \partial _t V_i + \frac{1 }{2 } \sigma _i (S , t )^2 S^2 \partial _S ^2 V_i + r S \partial _S C + \sum _i q_{ij } V_j = r V_i , \ \ t < T ,
\end{equation}
with final condition $V(S, T ) = F(S) . $ It is possible to prove directly from (\ref{eq:European_option_price}) that the $V_i $'s are $C^{2 , 1 } $: see for example \cite{?}. Alternatively, one can use the theory of linear PDEs: the system (\ref{eq:pricing_PDE}) with the final condition $F $  has a unique smooth solution \textcolor{blue}{- reference? Friedman's book on parabolic PDE? - }. By theorem \ref{thm:Dynkin}, $e^{- r t } V(S_t , X_t , dt ) $ is a local martingale. If $F $ is for example bounded, then so is the solution $(V_i )_i $, which implies that the local martingale is a martingale, so that
$$
    e^{-r t } V(S_t , i,  t ) = \mathbb{E } \left( e^{- r T } F(S_T ) | S_t, X_t \right) ,
$$
and $V(S_t, X_t , t ) $ is the price of the derivative.
\medskip

\textcolor{blue}{Deux remarques:
    \begin{itemize}
        \item dernier argument \`a re-v\'erifier et \`a g\'en\'eraliser pour un call (dont le pay-off n'est pas born\'e)
        \item Le "payoff" $F $ peut en principe \'etre vectoriel, c'est \`a dire, d\'ependant de l'\'etat de la chaine de Markov \`a $T $, mais admettre de tels pay-off vectoriel impliqu\'erait que les \'etats de la chaine de Markov sont observables, ce qui n'est pas le cas pour notre mod\`ele, puisqu'on peut pas observer la volatilit\'e instantann\'ee $\sigma (X_T ) $ \`a $T $
    \end{itemize}
}
\medskip

We now specialize to European call options with (state-independent) pay-off $F(S_T ) = \max (S_T - K , 0 ) . $ We will denote the value of the call by $C(S , X , t ; K, T ) $ ($X \in \{ 1, \ldots , N \} $ and also as a column vector $C (S , t ; K , T ) = \left( C (S, 1, t ; K, T ) , \ldots , C (S, N, t ; K , T ) \right) ^T $, where $C_i (S, t ; K, T ) = C(S , i , t ; K, T ) . $ It will satisfy the system
\begin{equation} \label{eq:PDE_call}
    \partial _t C + \frac{1 }{2 } \Sigma ^2 \, S^2 \partial _S ^2 C + r S \partial _S C + Q C = r C ,
\end{equation}
where %$\Sigma := {\rm diag } ( \sigma _1 ^2 , \ldots , \sigma _N ^2 ) $,
\begin{equation}
    \Sigma ^2 = \begin{pmatrix} \sigma _1 ^2 & \      & \            \\
                \            & \ddots & \            \\
                \            & \      & \sigma _N ^2
    \end{pmatrix}
\end{equation}
is the diagonal matrix of the state-dependend volatilities, and $Q = (q_{ij } )_{1 \leq i, j \leq N } $ is the matrix of transition probability rates of the Markov chain. The matrix $Q $ is row-stochastic: if $\mathbf{1 } := (1, 1, \ldots , 1 )^T $, then
\begin{equation}
    Q \mathbf{1 } = 0
\end{equation}
Since the model is time-homogeneous, we can write $C (S , t ; K , T ) = C (S, K, T - t) $ (with a slight abuse of notation).
\medskip

The inverse problem we are interested in then is the following:

\begin{question} Suppose that at a given time $t_0 $ we observe all call prices $C_i (S_0 , t_0 ; K, T ) $ for arbitrary strike  $K > 0 $ and maturity $T > t_0 $, where $i $ is the state of the Markov chain in which we are in at time $t_0 . $ How much of the model parameters $N $ (the number of Markov states), $\sigma _i $ (the state-dependent volatilities) and $q_{ij } $ (the transition probability rates) can we reconstruct ?
\end{question}

We have a total of $1 + n + n^2 - n = n^2 + 1 $ parameters and a continuum of observed prices (in our idealized set-up), so the problem seems at first sight over-determined.
\medskip

\textcolor{blue}{{\bf Question}: is $2N - 2 = $ maximal size for which the matrix $\left( (A^j v , ^T A^k w ) \right) _{j, k } $ is of full rang? Here $A = z \Sigma + Q $ }

\subsection{Dupire's equation}

\begin{theorem} (Xi, Rodrigo and Mamon \cite{XRM}) Fix $S = S_0 , t = t_0 . $ Then as a function of $(K, T ) $, the vector of prices $C(S , t ; K, S ) $ satisfies the system of PDEs
    \begin{equation} \label{eq:Dupire}
        \partial _T C = \frac{1 }{2 } \Sigma ^2 \, K^2 \partial _K ^2 C - r K \partial _K C + Q C , \ \ T > 0 ,
    \end{equation}
    with initial value $C (S_0 , t_0 , K , 0 ) = \max (S_0 - K , 0 ) \mathbf{1 } . $
\end{theorem}

\begin{proof} Xi {\it et al.} \cite{XRM} first observe that $C $ is homogeneous of order 1 in $(K, S ) $ by showing that $C (\lambda S , t ; \lambda K , T ) $ and $\lambda C (S , t ; K , T ) $ both satisfy the $N \times N $-system (\ref{eq:PDE_call}), %system (\ref{eq:PDE_call}),
    since the (matrix-)coefficients of this system are constant. They both have the the same final value value $\lambda \max (S - K , 0 ) $ at $T $, and are therefore identical. The Euler relation
    $$
        S \partial _S C + K \partial _K C = C
    $$
    then allows to express derivatives with respect to $S $ in terms of derivatives with respect to $K $, and (\ref{eq:Dupire}) follows from (\ref{eq:PDE_call}). Alternatively, one can use the relation
    that $C (S, K , T - t_0 ) = S \, C (1 , K/S , T - t_0 ) $ to derive (\ref{eq:Dupire}).
\end{proof}

\noindent \textcolor{blue}{{\bf Interrogation}: la question se pose si c'est vraiement n\'ecessaire, pour notre probl\`eme inverse, d'utiliser une \'equation de Dupire, dans le sens qu'on peut d\'eduire, pour ce mod\`ele, une formule explicite pour la  transformation de Fourier du prix en r\'esolvant (\ref{eq:PDE_call}) dans l'espace de Fourier (apr\`es passage au prix logarithmique $x = \log S/S_0 $) comme on le fait pour Dupire ci-bas, formule qu'on peut ensuite manipuler en tant que fonction de $K $ ou de $\log (K/S_0 ) $ ($S_0 $ \'etant le prix du sous-jacent au moment de l'observation) et de $T . $ On peut peut-\^etre pour ce mod\`ele sp\'ecifique, en quelque sorte "court-circuiter" Dupire? \`A suivre.
}
\medskip

Passing to log-coordinates $x = \log K $ and letting $c (x, T ) := C (S_0 , e^x , T ) $ (suppressing the $S_0  $-dependence from the notions and taking welog $t_0 = 0 $) we find that
\begin{equation}
    \partial _T c = \frac{1 }{2 } \Sigma ^2 \partial _x ^2 c - \left(  \frac{1 }{2 } \Sigma ^2 + r \right) \partial _x c + Q c , \ \ T > 0
\end{equation}
with initial condition $c (x, 0 ) = c_0 (x) := \max ( S_0 - e^x , 0 ) \mathbf{1 } . $ It is natural to solve this using the Fourier transform: if we take $r = 0 $ to simplify, and if $\widehat{c }  (\xi , T ) $ is the Fourier transform with respect to the $x $-variable of the (vector-valued) call price function $c $, then
$$
    \partial _T \widehat{c } = - \left( \, \frac{1 }{2 } (\xi ^2 + i \xi ) \Sigma ^2 - Q \, \right) \widehat{c } ,
$$
with initial condition $\widehat{c } (\xi , 0 ) . $ If the initial condition would have been an integrable function, the solution is
\begin{equation} \label{eq: FT_call}
    c(\xi , T ) = e^{- T ( \frac{1 }{2 } (\xi ^2 + i \xi  )\Sigma ^2 - Q ) }\widehat{c } (\xi , 0 )  \mathbf{1 } ,
\end{equation}
%where we put $\zeta := \zeta (\xi ) := \frac{1 }{2 } (\xi ^2 + i \xi  ) $ and
where the exponential is a matrix exponential. In our case, $c (x, 0 ) $ is only a bounded function and thus a tempered distribution, as is its Fourier transform. To show that (\ref{eq: FT_call}) defines a tempered distribution we have to check that $\xi \to \exp ( - T ( \frac{1 }{2 } (\xi ^2 - i \xi ) \Sigma ^2 - Q ) ) $ belongs to the Schwarz-class of rapidly decreasing functions. While this is not in doubt, proving it is slightly technical since we are dealing with the exponential of a sum of two non-commuting matrices, and there are no simple opper bounds we are aware off of for example $|| e^{A + B } || $ en termes of $|| e^A || $ and $|| e^B || $ when $A $ and $B $ are non-commuting matrices.

\begin{lemma} \textcolor{blue}{ - lemme technique: peut \^etre saut\'e en premi\`ere lecture - } $\xi \in \exp ( - T ( \frac{1 }{2 } (\xi ^2 + i \xi ) \Sigma ^2 - Q ) ) $ is a rapidly decreasing function of $\xi $ (with values in the space of $N $-dimensional matrices), and (\ref{eq: FT_call}) is therefore well-defined as a tempered distribution, for ant tempered distribution $c(x, 0 ) . $
\end{lemma}

\begin{proof} We will exploit the fact that $P(t) := e^{t Q } $ is a row-stochastic non-negative matrix, since
    $$
        P_{ij } (t) = \mathbb{P } (X_t = j | X_0 = i ) ,
    $$
    and therefore $\sum _j P_{ij } (t ) = 1 . $
    If $|| v ||_{\infty } := \max _i |v_i | $ is the sup-norm on $\mathbb{C }^N $, then any non-negative row-stochastic matrix $P $ is a contraction with respect to this norm:
    $$
        || P v ||_{\infty } \leq || v ||_{\infty } ,
    $$
    as is easily checked\footnote{Since $P_{ij } \geq 0 $, $|| Pv ||_{\infty } = \max _i  | \sum _j P_{ij } |v_j | \leq \max _i \sum _j P_{ij } || v ||_{\infty } = || v ||_{\infty } $, since $\sum _j P_{ij } = 1 . $ }.

    Next, we recall Lie's formula \textcolor{blue}{(reference \cite{? })}:
    $$
        e^{A + B } = \lim _{n \to \infty } \left( e^{A/n } e^{B/n } \right)^n ,
    $$
    which implies that $|| e^{A + B } || \leq \lim _{n \to \infty } || e^{A/n } || ^n \, || e^{B / n } || ^n $ for any matrix-norm $|| A || $, and in particular for $|| A ||_{\infty } = \sup _{|| v ||_{\infty } = 1 } || A v ||_{\infty } . $ Applying this with $A = - T (\xi ^2 + i \xi ) \Sigma ^2 $ and $B = T Q $ and using that $|| e^{T Q / n } ||_{\infty } \leq 1 $ (in fact, equal to 1, since if $P $ is a stochastic matrix, $P \mathbf{1 } = \mathbf{1 } $, which shows that $\sup _{|| v ||_{\infty } = 1 } || P v ||_{\infty } = 1 $), we find that
    $$
        \left | \left | \, e^{- T(\xi ^2 + i \xi ) \Sigma ^2 + T Q } \, \right | \right | _{\infty } \leq \lim _{n \to \infty } \, \left | \left | \, e^{ - \frac{T }{n } (\xi ^2 + i \xi ) \Sigma ^2 } \, \right | \right | _{\infty } ^n
    $$
    If $\Lambda = {\rm diag} ( \lambda _1 , \ldots , \Lambda _N ) $ is diagonal, then $|| \Lambda ||_{\infty } \leq \max _i |\lambda _i | . $ Applying this to $\Lambda = \exp ( - \frac{T }{2n } (\xi ^2 + i \xi ) \Sigma ^2 ) $ with $\lambda _j = e^{- (T/2n ) (\xi ^2 + i \xi ) \sigma _j ^2 } $, we see that the right hand side equals
    $$
        \left | \left | \, e^{- T(\xi ^2 + i \xi ) \Sigma ^2 + T Q } \, \right | \right | _{\infty } \leq \lim _{n \to \infty } \left( e^{ - \frac{T }{2n } \xi ^2 \min _j \sigma _j ^2 } \right) ^n = e^{- T \xi ^2 (\min _j \sigma _j ^2 ) / 2 } ,
    $$
    which is rapidly decreasing in $\xi . $

    We next examine the derivatives with respect to $\xi \in \mathbb{R } $ of $e^{- T (\xi ^2 + i \xi ) \Sigma ^2 + T Q } . $ Again, there is no closed formula for the derivative with respect to $\xi $, since the matrices $\Sigma ^2 $ and $Q $ do not commute. We will use the following formula [Wilcox, R. M., Exponential operators and parameter differentiation in quantum physics, J. Math. Phys  (1967)]: if $A(\xi ) $ is a $C^1 $ matrix-valued function on $\mathbb{R } $, then
    $$
        \frac{d }{d \xi } e^{t A (\xi ) } = \int _0 ^t e^{(t - s ) A(\xi ) } A'(\xi ) e^{s A (\xi ) } ds .
    $$
    Applying this with $t = 1 $ to $A(\xi ) = - \frac{1 }{2 } T ((\xi ^2 + i \xi ) \Sigma ^2 - Q ) $ and using our estimate above for the norm of $e^{A(\xi ) } $ we find
    $$
        \left | \left | \frac{d }{d \xi } e^{A (\xi ) } \right | \right | _{\infty } \leq C (|\xi | + 1 ) \int _0 ^1 || e^{- s A (\xi ) } ||_{\infty } || e^{(1 - s ) A(\xi ) } ||_{\infty } ds \leq C (|\xi | + 1 ) e^{- T \xi ^2 (\min _j \sigma _j ^2 ) / 2 } ,
    $$
    with $C = T || \Sigma ^2 ||_{\infty } = T \max _j \sigma _j ^2 $, and where the $\ell ^{\infty } $-norm can of course be replaced by any other matrix norm. Higher order derivatives cab be treated by iterating Wilcox's formula, e.g.
    \begin{eqnarray*}
        \frac{d^2 }{d \xi ^2 } e^{t A (\xi ) } &=& \int _0 ^t e^{(t - s ) A } A''(\xi ) e^{s A } ds + \int _0 ^t \left( \int _0 ^{t - s } e^{(t - s - u ) A } A'(\xi ) e^{u  A } du \right) A'(\xi ) e^{s A } ds \\
        &\ & + \left( \int _0 ^t e^{(t - s ) A } A'(\xi ) \int _0 ^s e^{(s - u ) A } A'(\xi ) e^{u A } du \right) ds ;
    \end{eqnarray*}

\end{proof}

The fact that $\Sigma ^2 $ and $Q $ will never commute, except in trivial cases\footnote{if all $\sigma _i ^2 $ are distinct, then $[ \Sigma ^2 , Q ] = 0 $ with $Q \neq 0 $ implies that $Q $ is a permutation matrix \textcolor{blue}{(au moins, je crois)}. The row sums of a permutation matrix are all equal to 1, so $Q $ cannot be the generator of a Markov chain then.  If for example $\sigma _1 ^2 = \sigma _2 ^2 $, then $\Sigma ^2 $ can commute with non-zero generator matrices $Q $ whose non-zero elements correspond to transitions between states 1 and 2, but these will then have no effect on the volatility $S_t $} will be the cause of most of the technical problems in this paper, and makes the direct and inverse problem of option pricing in our hidden Markov model interesting and non-trivial, even in the simplest case of a two-state Markov chain.
\medskip

The (distributional) Fourier transform of $c(x, 0 ) = \max (S_0 - e^x , 0 ) $ can be computed explicitly, and is equal to
\begin{equation}
    \widehat{c } (\xi , 0 ) = i S_0 ^{1 - i \xi } \left( \frac{1 }{\xi + i 0 } - \frac{1 }{\xi + i } \right) ,
\end{equation}
where $(\xi + i 0 )^{-1 } := \lim _{\varepsilon \to 0+ } (\xi + \varepsilon )^{-1 }  = {\rm pv } (1 / \xi ) - i \pi \delta _0 (\xi ) . $
\medskip

\noindent \textcolor{blue}{{\bf D\'etails du calcul}: $c_0 (x) := \max (S_0 - e^x , 0 ) $ n'est pas int\'egrable, mais $c_{\varepsilon } (x) := e^{\varepsilon x } \max (S_0 - e^x , 0 ) $ l'est, pour tout $\varepsilon > 0 $, et $c_{\varepsilon } \to c_0 $ comme distributions temper\'ees, et donc $\widehat{c }_{\varepsilon } \to \widehat{c } . $ Or,
    \begin{eqnarray*}
        \widehat{c }_{\varepsilon } (\xi ) &=& \int _{\mathbb{R } } c_0 (x) e^{\varepsilon x - i x \xi } dx \\
        &=& \int _{- \infty } ^{\log S_0 } \left( S_0 e^{(\varepsilon - i \xi ) x } - e^{(\varepsilon + 1 - i \xi ) x } \right) dx \\
        &=& S_0 \cdot \frac{e^{(\varepsilon - i \xi ) \log S_0 } }{\varepsilon - i \xi } - \frac{e^{(\varepsilon + 1 - i \xi ) \log S_0 } }{\varepsilon + 1 - i \xi } \\
        &=& i S_0 ^{1 + \varepsilon - i \xi } \left( \frac{1 }{\xi + i \varepsilon } - \frac{1 }{\xi + i (1 + \varepsilon ) } \right) \\
        &\to & S_0 ^{1 - i \xi } \left( \frac{1 }{\xi + i 0 } - \frac{1 }{\xi + i } \right) .
    \end{eqnarray*}
}
Note that away from $\xi = 0 $, $\widehat{c } (\xi , 0 ) $ can be identified with a non-vanishing locally integrable function. It follows that if we would know all call prices $C_1 (S_0 , 0 ; K , T ) = (C(S_0 , 0 ; K, T ) , e_1 ) $, for all positive $K $ and $T $, assuming without essential loss of generality that at the time of observation $t = 0 $ we are in the hidden Markov state 1, then we would know the function $(c(x, T ) , e_1 ) $ and therefore its Fourier transform $(\widehat{c } (\xi , T ) , e_1 ) $ given by (\ref{eq: FT_call}). Since $\widehat{c } (\xi , 0 ) \neq 0 $ for all $\xi \neq 0 $, this implies that we would know the function
\begin{equation}
    \left( e^{ - T (\zeta \Sigma ^2 - Q ) } \mathbf{1 } , e_1 \right) ,   \ \ (\xi , T ) \in \mathbb{R } \times \mathbb{R }_{> 0 } ,
\end{equation}
where we put $\zeta = \zeta (\xi ) := \xi ^2 + i \xi $, to simplify notations. In particular, evaluating the derivatives $\partial _T ^k $ at $T = 0 $, we would know
\begin{equation} \label{eq:donn�es_Pb_Inv}
    \left( \, ( - \zeta \Sigma ^2 + Q ) ^k \mathbf{1 } , e_1 \right) , \ \ k = 0, 1, 2, \ldots
\end{equation}
and the inverse problem we study becomes

\begin{question} How much of the matrices $\Sigma ^2 $ and $Q $ can one reconstruct from knowledge of (\ref{eq:donn�es_Pb_Inv}) (under appropriate conitions on $\Sigma ^2 $ and on $Q $)?
\end{question}

We note in passing that since (\ref{eq:donn�es_Pb_Inv}) are polynomials in $\zeta $, if we know them for all $\zeta $ of the form $\zeta = \xi ^2 - i \xi $, we know them for all $\zeta \in \mathbb{C } $ (in fact, we only need to know their values on $k + 1 $ different points). %In particular, we can replace $- \zeta $ by $\zeta $, as we will sometimes do.
\medskip

\subsection{Relation between (\ref{eq:donn�es_Pb_Inv}) and observed option prices} We can take $S_0 = 1 $ without essential loss of generality. We first note that
$$
    (\xi ^2 + i \xi ) \widehat{c } (\xi , 0 ) =   \xi (\xi + i ) \cdot i \left( \frac{1 }{\xi + i 0 } - \frac{1 }{\xi + i } \right) = i ( (\xi + i ) - \xi ) = -1 ,
$$
(which is equivalent to $(\partial _x ^2 - \partial _x ) c(x, 0 ) = \delta _0 $). Therefore
$$
    (\xi ^2 + i \xi ) \widehat{c } (\xi , T ) %= c(\xi , T )
    = - e^{ T ( - \frac{1 }{2 } %(\xi ^2 + i \xi  )
            \zeta \Sigma ^2 + Q ) } \mathbf{1 } ,
$$
where $\zeta := \zeta (\xi ) := \xi ^2 + i \xi $, and
$$
    %\left( \,
    ( - \zeta \Sigma ^2 + Q ) ^k \mathbf{1 } %, e_1 \right)
    = - (\xi ^2 + i \xi ) \frac{\partial ^k }{\partial T ^k } %e^{- T ( \frac{1 }{2 } (\xi ^2 + i \xi  )\Sigma ^2 - Q ) }
    \widehat{c } (\xi , T ) |_{T = 0 } ,
$$
Now
$$
    ( - \zeta \Sigma ^2 + Q )^k = \sum _{j = 0 } ^k P^{(k) } _j (\Sigma ^2 , Q ) (-1 )^j \zeta ^j ,
$$
where $P^{(k) } _j (\Sigma ^2 , Q ) $ s a polynomial in the nonommuting (!) variables $\Sigma ^2 $ and $Q $: for example, $P^{(k)} _0 (\Sigma ^2 , Q ) = Q^k $, while
$$
    P^{(k)}  _1 (\Sigma ^2 , Q ) = Q^{k - 1 } \Sigma ^2 + Q^{k - 2 } \Sigma ^2 Q + \cdots + \Sigma ^2 Q^{k - 1 } .
$$
Note that since $Q \mathbf{1 } = 0 $,
$$
    \left( \, P^{(k) }  _1 (\Sigma ^2 , Q ) \mathbf{1 } , e_1 \, \right) = (Q^{k - 1 } \Sigma ^2 \mathbf{1 } , e_1 ) ,
$$
that is, only the first term survives when looking at the for us relevant matrix element.

Remembering that $\zeta = \xi ^2 + i \xi $, we therefore have
\begin{eqnarray*}
    P^{(k) } _j (\Sigma ^2 , Q ) &=& \frac{(-1 )^j }{(2j )! } \partial _{\xi } ^{2j } ( - \zeta \Sigma ^2 + Q )^k |_{\xi = 0 } \\
    &=& - \frac{(-1 )^j }{(2j )! } \partial _{\xi } ^{2j } \partial _T ^k \left( \, (\xi ^2 + i \xi ) \widehat{c } (\xi , T ) \right) |_{\xi = 0 , T = 0 }
\end{eqnarray*}
Now
$$
    - \partial _{\xi } ^{2j } (\xi ^2 + i \xi ) \widehat{c } (\xi , T ) = \mathcal{F }_{x \to \xi } \left( (ix )^{2j } (\partial _x ^2 - \partial _x ) c(x, T ) \right) ,
$$
so that we find that
\begin{equation} \label{eq:donn�es_IP_bis}
    p_{k, j } := \left( \, P^{(k) } _j (\Sigma ^2 , Q ) \mathbf{1 } , e_1 \, \right)  = \int _{\mathbb{R } } x^{2j } (\partial _x ^2 - \partial _x ) \partial _T ^k c_1 (x, T ) \big{\vert }_{T = 0 } dx
\end{equation}
Transforming variables back to $K = e^x $, we can also write this as
\begin{equation}
    %\left( \, p^k _j (\Sigma ^2 , Q ) \mathbf{1 } , e_1 \, \right) =
    p_{k, j } = \int _0 ^{\infty } (\log K )^{2j } \, \left( K^2 \partial _K ^2 \partial _T ^k C \right) (1 ; 0 , K, T ) \, \frac{dK }{K } \ \ (?)
\end{equation}
which can obviously be determined from observed option prices.

\section{\bf Inverse option pricing problem for a two-state Markov chain} In this subsection we show that if $N = 2 $, then (\ref{eq:donn�es_IP_bis}) with $k = 1, 2, 3 $ uniquely determine the $\sigma _k ^2 $  and the $q_{ij} . $ First of all, since the row-sums of $Q $ are 0 ($Q \mathbf{1 } = 0 $), we have
$$
    Q = \begin{pmatrix} - q_{12 } & q_{12 }    \\
                q_{21 }   & - q _{21 }
    \end{pmatrix}
$$
so $Q $ is determined by the two parameters $q_{12 } $ and $q_{21 } $ which, together with the two volatilies (squared) $\sigma _1 ^2 $ and $\sigma _2 ^2 $ makes for a total of 4 parameters to be determined. Next we look at $(- \zeta \Sigma ^2 + Q )^k $ which we expand for $k = 1 , 2 $ and $3 $: we put $\Sigma ^2 = V $, to simplify the appearance of the formulas and avoid confusion with the powers of $\Sigma $ which occur (which are forcibly even). For $k = 1 $ there is nothing to do, while for the other $k $'s we find
$$
    \begin{array}{cccc}
        (- \zeta V + Q )^2 & =  & \zeta ^2 V ^2 - (V Q + Q V) \zeta + Q^2            \\
        (- \zeta V + Q )^3 & =  & - \zeta ^3 V^3 + \zeta ^2 (V^2 Q + V Q V + Q V^2 ) \\
        \                  & \  & - \ \zeta (Q^2 V + QVQ + V Q^2 ) + Q^3
    \end{array}
$$
When applying this to the vector $\mathbf{1 } $, all terms starting with a $Q $ on the left will be 0, so (\ref{eq:donn�es_IP_bis}) will give us
$$
    p_{1, 1 } = (V \mathbf{1 } , e_1 ) = \sigma _1 ^2 , \ p_{2, 2 } = (V^2 \mathbf{1 } , e_1 ) = \sigma _1 ^4 ,  \ p_{3, 3 } = (V^2 \mathbf{1 } , e_1 ) = \sigma _1 ^6 ,
$$
which are all dependent. We already observed that $p_{1, 0 } = (Q \mathbf{1 } , e_1 ) = 0 $, and similarly for the other $p_{k, 0 } . $ Next,
\begin{equation} \label{eq:two_state_1}
    p_{2, 1 } = (Q V \mathbf{1 } , e_1 ) , \ p_{3, 2 } = ((V Q V + Q V^2 ) \mathbf{1 } , e_1 ) = \sigma _1 ^2 (Q V \mathbf{1 } , e_1 ) + (Q V^2 \mathbf{1 } , e_1 ) ,
\end{equation}
so that the last equation translates into
\begin{equation} \label{eq:two_state_2}
    (Q V^2 \mathbf{1 } , e_1 ) = p_{3, 2 } - \sigma _1 ^2 p_{2, 1 } = p_{3, 2 } - p_{1, 1 } p_{2, 1 } ,
\end{equation}
while finally
\begin{equation} \label{eq:two_state_3}
    p_{3, 1 } = (Q^2 V \mathbf{1 } , e_1 ) .
\end{equation}
Computing $Q V \mathbf{1 } = Q (\sigma _1 ^2 , \sigma _2 ^2 )^t $ and $Q V^2 \mathbf{1 } $, the first equation of (\ref{eq:two_state_1}) and (\ref{eq:two_state_2}) give
$$
    \begin{array}{ll}
        q_{12 } \, (\sigma _2 ^2 - \sigma _1 ^2 ) = p_{2, 1 } \\
        q_{12 } \, (\sigma _2 ^4 - \sigma _1 ^2 ) = p_{3, 2 } - p_{1, 1 } p_{2, 1 } .
    \end{array}
$$
Dividing the second equation by the first, we find $\sigma _2 ^2 + \sigma _1 ^2 = (p_{3 , 2 } - p_{1, 1 } p_{2, 1 } ) / p_{2, 1 } = (p_{3 , 2 } / p_{2, 1 } ) - p_{1, 1 }  $, so that
$$
    \sigma _2 ^2 = \frac{p_{3, 2 } }{p_{2, 1 } } - 2 p_{1, 1 } .
$$
The first equation then yields $q_{12 } $:
$$
    q_{12 } = \frac{p_{2, 1 } }{\sigma _2 ^2 - \sigma _1 ^2 } = \frac{(p_{2, 1 } )^2 }{p_{3, 2 } - 3 p_{1, 1 } p_{2, 1 } } .
$$
Finally (\ref{eq:two_state_3}) translates into
$$
    (\sigma _1 ^2 - \sigma _2 ^2 ) (q_{12 }^2 + q_{12 } q_{21 } ) = p_{3, 1 } ,
$$
with solution
$$
    q_{21 } = \frac{p_{3, 1 } + (\sigma _2 ^2 - \sigma _1 ^2 ) q_{12 } ^2 }{q_{12 } (\sigma _1 ^2 - \sigma _2 ^2 ) } = \frac{p_{3, 1 } }{q_{12 } (\sigma _1 ^2 - \sigma _2 ^2 ) } - q_{12 } = - \frac{p_{3, 1 } }{p_{2, 1 } } - q_{12 } .
$$
\textcolor{blue}{Calculs \`a v\'erifier encore; formuler tout ceci comme th\'eor\`eme;  }

\begin{theorem} Suppose all call-prices $C (S_0 = 1 , 0 ; K, T ) $ are known. If
    \begin{equation}
        %\left( \, p^k _j (\Sigma ^2 , Q ) \mathbf{1 } , e_1 \, \right) =
        p_{k, j } = \int _0 ^{\infty } (\log K )^{2j } \, \left( K^2 \partial _K ^2 \partial _T ^k C \right) (1 ; 0 , K, T ) \, \frac{dK }{K } ,
    \end{equation}
    then if $N = 2 $, the model parameters are given by ...
\end{theorem}

\begin{thebibliography}{article}

    \bibitem{XRM} X. Xi, M. Rodrigo and R.S. Mamon, 2012, Parameter estimation of a regime-switching model using an inverse Stieltjes moment approach?, In: {\it Stochastic Processes, Finance and Control (Festschrift in Honour of Robert Elliott's 70th Birthday)}, Advances in Statistics, Probability and Actuarial Science, Volume I , (eds.: Cohen, S., Madan, D., Siu, T. and Yang, H.), World Scientific, 549-569

\end{thebibliography}

\end{document}

\end{document}