Martin Escardo & Paulo Oliva, Fri 24-25 Feb 2017

Conversion of dialogue trees to Brouwer trees.

\begin{code}

{-# OPTIONS --safe --without-K #-}

module EffectfulForcing.MFPSAndVariations.Dialogue-to-Brouwer where

open import MLTT.Spartan
open import EffectfulForcing.MFPSAndVariations.Dialogue

\end{code}

Dialogue trees represent functions (ℕ → ℕ) → ℕ.

\begin{code}

Dialogue = B 

deval : Dialogue  (  )  
deval = dialogue

\end{code}

Brouwer trees.

\begin{code}

data Brouwer : Set where
 η :   Brouwer
 δ : (  Brouwer)  Brouwer

\end{code}

We use φ to range over forests of dialogue trees, that is,
functions ℕ → D.

We use γ to range over forests of Brower trees.

Brouwer trees represent functions (ℕ → ℕ) → ℕ too:

\begin{code}

beval : Brouwer  (  )  
beval (η k) α = k
beval (δ γ) α = beval (γ (α 0))  i  α (succ i))

\end{code}

Conversion from dialogue to Brouwer trees, with two auxiliary
functions follow and β':

\begin{code}

follow :   Brouwer  Brouwer
follow n (η k) = η k
follow n (δ γ) = γ n

\end{code}

The function β' simulates the constructor β in Brouwer trees:

\begin{code}

β' : (  Brouwer)    Brouwer
β' γ 0        = δ  i  follow i (γ i))
β' γ (succ n) = δ  i  β'  j  follow i (γ j)) n)

\end{code}

Conversion is the unique homomorphism w.r.t. dialogue structure:

\begin{code}

convert : Dialogue  Brouwer
convert (η k)   = η k
convert (β φ n) = β'  i  convert (φ i)) n

\end{code}

The correctness proof of the function convert uses two lemmas, one
for the function follow and the other for the function β':

By cases on b:

\begin{code}

follow-lemma : (b : Brouwer) (α :   )
              beval b α  beval (follow (α 0) b)  i  α (succ i))
follow-lemma (η k) α = refl
follow-lemma (δ φ) α = refl

\end{code}

By induction on n, using follow-lemma both in the base case and the
induction step:

\begin{code}

β'-lemma : (n : ) (φ :   Brouwer) (α :   )
          beval (φ (α n)) α  beval (β' φ n) α

β'-lemma 0 φ α =
 beval (φ (α 0)) α                                 =⟨ I 
 beval (follow (α 0) (φ (α 0)))  i  α (succ i)) =⟨ refl 
 beval (δ  i  follow i (φ i))) α                =⟨ refl 
 beval (β' φ 0) α                                  
  where
   I = follow-lemma (φ (α 0)) α

β'-lemma (succ n) φ α =
 beval (φ (α (succ n))) α                                   =⟨ I 
 beval (follow (α 0) (φ (α (succ n))))  i  α (succ i))   =⟨ II 
 beval (β'  j  follow (α 0) (φ j)) n)  i  α (succ i)) =⟨ refl 
 beval (δ  i  β'  j  follow i (φ j)) n)) α            =⟨ refl 
 beval (β' φ (succ n)) α                                    
  where
   I  = follow-lemma (φ (α (succ n))) α
   II = β'-lemma n  j  follow (α 0) (φ j))  i  α (succ i))

\end{code}

By induction on d, using β'-lemma in the induction step:

\begin{code}

convert-correctness : (d : Dialogue) (α :   )  deval d α  beval (convert d) α
convert-correctness (η k)   α = refl
convert-correctness (β φ n) α =
 deval (φ (α n)) α                      =⟨ convert-correctness (φ(α n)) α 
 beval (convert (φ (α n))) α            =⟨ β'-lemma n  i  convert (φ i)) α 
 beval (β'  i  convert (φ i)) n) α   

\end{code}