Theorem: Turing.TM1to1.stepAux_write
File: Mathlib/Computability/TuringMachine.lean

tactic: simp only [trTape', ListBlank.cons_bind]
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
a b : Γ
L R : ListBlank Γ
⊢ stepAux (write (Vector.toList (enc a)) q) v (trTape' enc0 L (ListBlank.cons b R)) =
    stepAux q v (trTape' enc0 (ListBlank.cons a L) R)

tactic: suffices ∀ {L' R'} (l₁ l₂ l₂' : List Bool) (_ : l₂'.length = l₂.length),
    stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
    stepAux q v (Tape.mk' (L'.append (List.reverseAux l₂ l₁)) R') by
  refine' this [] _ _ ((enc b).2.trans (enc a).2.symm)
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
a b : Γ
L R : ListBlank Γ
⊢ stepAux (write (Vector.toList (enc a)) q) v
      (Tape.mk'
        (ListBlank.bind L (fun x => List.reverse (Vector.toList (enc x)))
          (_ : ∃ n_1, (fun x => List.reverse (Vector.toList (enc x))) default = List.replicate n_1 default))
        (ListBlank.append (Vector.toList (enc b))
          (ListBlank.bind R (fun x => Vector.toList (enc x))
            (_ : ∃ n_1, (fun x => Vector.toList (enc x)) default = List.replicate n_1 default)))) =
    stepAux q v
      (Tape.mk'
        (ListBlank.append (List.reverse (Vector.toList (enc a)))
          (ListBlank.bind L (fun x => List.reverse (Vector.toList (enc x)))
            (_ : ∃ n_1, (fun x => List.reverse (Vector.toList (enc x))) default = List.replicate n_1 default)))
        (ListBlank.bind R (fun x => Vector.toList (enc x))
          (_ : ∃ n_1, (fun x => Vector.toList (enc x)) default = List.replicate n_1 default)))

tactic: clear a b L R
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
a b : Γ
L R : ListBlank Γ
⊢ ∀ {L' R' : ListBlank Bool} (l₁ l₂ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')

tactic: intro L' R' l₁ l₂ l₂' e
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
⊢ ∀ {L' R' : ListBlank Bool} (l₁ l₂ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')

tactic: induction' l₂ with a l₂ IH generalizing l₁ l₂'
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁ l₂ l₂' : List Bool
e : List.length l₂' = List.length l₂
⊢ stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
    stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')

tactic: cases' l₂' with b l₂' <;> simp only [List.length_nil, List.length_cons, Nat.succ_inj'] at e
state_before: case cons
Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁✝ l₂✝ l₂'✝ : List Bool
e✝ : List.length l₂'✝ = List.length l₂✝
a : Bool
l₂ : List Bool
IH :
  ∀ (l₁ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')
l₁ l₂' : List Bool
e : List.length l₂' = List.length (a :: l₂)
⊢ stepAux (write (a :: l₂) q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
    stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux (a :: l₂) l₁) L') R')

tactic: rw [List.reverseAux, ← IH (a :: l₁) l₂' e]
state_before: case cons.cons
Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁✝ l₂✝ l₂'✝ : List Bool
e✝ : List.length l₂'✝ = List.length l₂✝
a : Bool
l₂ : List Bool
IH :
  ∀ (l₁ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')
l₁ : List Bool
b : Bool
l₂' : List Bool
e : List.length l₂' = List.length l₂
⊢ stepAux (write (a :: l₂) q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append (b :: l₂') R')) =
    stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux (a :: l₂) l₁) L') R')

tactic: simp only [stepAux, ListBlank.append, Tape.write_mk', Tape.move_right_mk', ListBlank.head_cons,
  ListBlank.tail_cons]
state_before: case cons.cons
Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁✝ l₂✝ l₂'✝ : List Bool
e✝ : List.length l₂'✝ = List.length l₂✝
a : Bool
l₂ : List Bool
IH :
  ∀ (l₁ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')
l₁ : List Bool
b : Bool
l₂' : List Bool
e : List.length l₂' = List.length l₂
⊢ stepAux (write (a :: l₂) q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append (b :: l₂') R')) =
    stepAux (write l₂ q) v (Tape.mk' (ListBlank.append (a :: l₁) L') (ListBlank.append l₂' R'))

tactic: refine' this [] _ _ ((enc b).2.trans (enc a).2.symm)
state_before: Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
a b : Γ
L R : ListBlank Γ
this :
  ∀ {L' R' : ListBlank Bool} (l₁ l₂ l₂' : List Bool),
    List.length l₂' = List.length l₂ →
      stepAux (write l₂ q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
        stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux l₂ l₁) L') R')
⊢ stepAux (write (Vector.toList (enc a)) q) v
      (Tape.mk'
        (ListBlank.bind L (fun x => List.reverse (Vector.toList (enc x)))
          (_ : ∃ n_1, (fun x => List.reverse (Vector.toList (enc x))) default = List.replicate n_1 default))
        (ListBlank.append (Vector.toList (enc b))
          (ListBlank.bind R (fun x => Vector.toList (enc x))
            (_ : ∃ n_1, (fun x => Vector.toList (enc x)) default = List.replicate n_1 default)))) =
    stepAux q v
      (Tape.mk'
        (ListBlank.append (List.reverse (Vector.toList (enc a)))
          (ListBlank.bind L (fun x => List.reverse (Vector.toList (enc x)))
            (_ : ∃ n_1, (fun x => List.reverse (Vector.toList (enc x))) default = List.replicate n_1 default)))
        (ListBlank.bind R (fun x => Vector.toList (enc x))
          (_ : ∃ n_1, (fun x => Vector.toList (enc x)) default = List.replicate n_1 default)))

tactic: cases List.length_eq_zero.1 e
state_before: case nil
Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁✝ l₂ l₂'✝ : List Bool
e✝ : List.length l₂'✝ = List.length l₂
l₁ l₂' : List Bool
e : List.length l₂' = List.length []
⊢ stepAux (write [] q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append l₂' R')) =
    stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux [] l₁) L') R')

tactic: rfl
state_before: case nil.refl
Γ : Type u_3
inst✝² : Inhabited Γ
Λ : Type u_2
inst✝¹ : Inhabited Λ
σ : Type u_1
inst✝ : Inhabited σ
n : ℕ
enc : Γ → Vector Bool n
dec : Vector Bool n → Γ
enc0 : enc default = Vector.replicate n false
M : Λ → Stmt₁
q : Stmt Bool Λ' σ
v : σ
L' R' : ListBlank Bool
l₁✝ l₂ l₂' : List Bool
e✝ : List.length l₂' = List.length l₂
l₁ : List Bool
e : List.length [] = List.length []
⊢ stepAux (write [] q) v (Tape.mk' (ListBlank.append l₁ L') (ListBlank.append [] R')) =
    stepAux q v (Tape.mk' (ListBlank.append (List.reverseAux [] l₁) L') R')