l3lab/ntp-mathlib huggingface dataset:
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · 

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
⊢ Formula.Realize (toFormula (∀'f✝)) v ↔ Realize (∀'f✝) (v ∘ Sum.inl) (v ∘ Sum.inr)

Next tactic:
rw [toFormula, Formula.Realize, realize_all, realize_all]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
⊢ (∀ (a : M),
      Realize (relabel (Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ ⇑finSumFinEquiv.symm)) (toFormula f✝)) v
        (snoc default a)) ↔
    ∀ (a : M), Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)

Next tactic:
refine' forall_congr' fun a => _
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
⊢ Realize (relabel (Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ ⇑finSumFinEquiv.symm)) (toFormula f✝)) v
      (snoc default a) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)

Next tactic:
have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a) ∘ Sum.inl)
      (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a) ∘ Sum.inr)
⊢ Realize (relabel (Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ ⇑finSumFinEquiv.symm)) (toFormula f✝)) v
      (snoc default a) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)

Next tactic:
simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
⊢ Realize (relabel (Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ ⇑finSumFinEquiv.symm)) (toFormula f✝)) v
      (snoc default a) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)

Next tactic:
rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
⊢ Realize (toFormula f✝)
      (Sum.elim v (snoc default a ∘ castAdd 0) ∘
        Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ ⇑finSumFinEquiv.symm))
      (snoc default a ∘ natAdd 1) =
    Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) default

Next tactic:
simp only [Function.comp]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    

Proof state:
case all
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
⊢ (Realize (toFormula f✝)
      (fun x =>
        Sum.elim v (fun x => snoc default a (castAdd 0 x))
          (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x)) x))
      fun x => snoc default a (natAdd 1 x)) =
    Realize (toFormula f✝) (Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a)) default

Next tactic:
congr with x
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · 

Proof state:
case all.e__v.h
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : α ⊕ Fin (n✝ + 1)
⊢ Sum.elim v (fun x => snoc default a (castAdd 0 x))
      (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x)) x) =
    Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a) x

Next tactic:
cases' x with _ x
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · 

Proof state:
case all.e__v.h.inl
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
val✝ : α
⊢ Sum.elim v (fun x => snoc default a (castAdd 0 x))
      (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x)) (Sum.inl val✝)) =
    Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a) (Sum.inl val✝)

Next tactic:
simp
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · 

Proof state:
case all.e__v.h.inr
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ Sum.elim v (fun x => snoc default a (castAdd 0 x))
      (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x)) (Sum.inr x)) =
    Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a) (Sum.inr x)

Next tactic:
refine' Fin.lastCases _ _ x
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · refine' Fin.lastCases _ _ x
        · 

Proof state:
case all.e__v.h.inr.refine'_1
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ Sum.elim v (fun x => snoc default a (castAdd 0 x))
      (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x))
        (Sum.inr (last n✝))) =
    Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a) (Sum.inr (last n✝))

Next tactic:
rw [Sum.elim_inr, Sum.elim_inr,
            finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · refine' Fin.lastCases _ _ x
        · rw [Sum.elim_inr, Sum.elim_inr,
            finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
          

Proof state:
case all.e__v.h.inr.refine'_1
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ snoc default a (castAdd 0 (id 0)) = snoc (fun x => v (Sum.inr x)) a (last n✝)

Next tactic:
simp [Fin.snoc]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · refine' Fin.lastCases _ _ x
        · rw [Sum.elim_inr, Sum.elim_inr,
            finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
          simp [Fin.snoc]
        · 

Proof state:
case all.e__v.h.inr.refine'_2
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ ∀ (i : Fin n✝),
    Sum.elim v (fun x => snoc default a (castAdd 0 x))
        (Sum.elim (fun x => Sum.inl (Sum.inl x)) (fun x => Sum.map Sum.inr id (finSumFinEquiv.symm x))
          (Sum.inr (castSucc i))) =
      Sum.elim (fun x => v (Sum.inl x)) (snoc (fun x => v (Sum.inr x)) a) (Sum.inr (castSucc i))

Next tactic:
simp only [castSucc, Function.comp_apply, Sum.elim_inr,
            finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · refine' Fin.lastCases _ _ x
        · rw [Sum.elim_inr, Sum.elim_inr,
            finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
          simp [Fin.snoc]
        · simp only [castSucc, Function.comp_apply, Sum.elim_inr,
            finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl]
          

Proof state:
case all.e__v.h.inr.refine'_2
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ ∀ (i : Fin n✝), v (Sum.inr i) = snoc (fun x => v (Sum.inr x)) a (castAdd 1 i)

Next tactic:
rw [← castSucc]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) :
    φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
  induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
  · rfl
  · simp [BoundedFormula.Realize]
  · simp [BoundedFormula.Realize]
  · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
      realize_imp]
  · rw [toFormula, Formula.Realize, realize_all, realize_all]
    refine' forall_congr' fun a => _
    have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
    simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
    rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
    simp only [Function.comp]
    congr with x
    · cases' x with _ x
      · simp
      · refine' Fin.lastCases _ _ x
        · rw [Sum.elim_inr, Sum.elim_inr,
            finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
          simp [Fin.snoc]
        · simp only [castSucc, Function.comp_apply, Sum.elim_inr,
            finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl]
          rw [← castSucc]
          

Proof state:
case all.e__v.h.inr.refine'_2
L : Language
L' : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
γ : Type u_3
n : ℕ
T : Theory L
n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih3 : ∀ (v : α ⊕ Fin (n✝ + 1) → M), Formula.Realize (toFormula f✝) v ↔ Realize f✝ (v ∘ Sum.inl) (v ∘ Sum.inr)
v : α ⊕ Fin n✝ → M
a : M
h :
  Formula.Realize (toFormula f✝) (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) ↔
    Realize f✝ (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)
x : Fin (n✝ + 1)
⊢ ∀ (i : Fin n✝), v (Sum.inr i) = snoc (fun x => v (Sum.inr x)) a (castSucc i)

Next tactic:
simp