l3lab/ntp-mathlib huggingface dataset:
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · 

Proof state:
case h.refine'_2
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
⊢ ∀ {n : ℕ} (t₁ t₂ : Term L (Empty ⊕ Fin n)) (xs : Fin n → M),
    BoundedFormula.Realize (BoundedFormula.equal t₁ t₂) (⇑f ∘ default) (⇑f ∘ xs) ↔
      BoundedFormula.Realize (BoundedFormula.equal t₁ t₂) default xs

Next tactic:
intros
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    

Proof state:
case h.refine'_2
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
n✝ : ℕ
t₁✝ t₂✝ : Term L (Empty ⊕ Fin n✝)
xs✝ : Fin n✝ → M
⊢ BoundedFormula.Realize (BoundedFormula.equal t₁✝ t₂✝) (⇑f ∘ default) (⇑f ∘ xs✝) ↔
    BoundedFormula.Realize (BoundedFormula.equal t₁✝ t₂✝) default xs✝

Next tactic:
simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · 

Proof state:
case h.refine'_3
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
⊢ ∀ {n l : ℕ} (R : Relations L l) (ts : Fin l → Term L (Empty ⊕ Fin n)) (xs : Fin n → M),
    BoundedFormula.Realize (BoundedFormula.rel R ts) (⇑f ∘ default) (⇑f ∘ xs) ↔
      BoundedFormula.Realize (BoundedFormula.rel R ts) default xs

Next tactic:
intros
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    

Proof state:
case h.refine'_3
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
n✝ l✝ : ℕ
R✝ : Relations L l✝
ts✝ : Fin l✝ → Term L (Empty ⊕ Fin n✝)
xs✝ : Fin n✝ → M
⊢ BoundedFormula.Realize (BoundedFormula.rel R✝ ts✝) (⇑f ∘ default) (⇑f ∘ xs✝) ↔
    BoundedFormula.Realize (BoundedFormula.rel R✝ ts✝) default xs✝

Next tactic:
simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    

Proof state:
case h.refine'_3
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
n✝ l✝ : ℕ
R✝ : Relations L l✝
ts✝ : Fin l✝ → Term L (Empty ⊕ Fin n✝)
xs✝ : Fin n✝ → M
⊢ (RelMap R✝ fun i => f (Term.realize (Sum.elim default xs✝) (ts✝ i))) ↔
    RelMap R✝ fun i => Term.realize (Sum.elim default xs✝) (ts✝ i)

Next tactic:
erw [map_rel f]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · 

Proof state:
case h.refine'_4
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
⊢ ∀ {n : ℕ} (f₁ f₂ : BoundedFormula L Empty n),
    (∀ (xs : Fin n → M), BoundedFormula.Realize f₁ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize f₁ default xs) →
      (∀ (xs : Fin n → M), BoundedFormula.Realize f₂ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize f₂ default xs) →
        ∀ (xs : Fin n → M),
          BoundedFormula.Realize (f₁ ⟹ f₂) (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize (f₁ ⟹ f₂) default xs

Next tactic:
intro _ _ _ ih1 ih2 _
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    

Proof state:
case h.refine'_4
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L Empty n✝
ih1 : ∀ (xs : Fin n✝ → M), BoundedFormula.Realize f₁✝ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize f₁✝ default xs
ih2 : ∀ (xs : Fin n✝ → M), BoundedFormula.Realize f₂✝ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize f₂✝ default xs
xs✝ : Fin n✝ → M
⊢ BoundedFormula.Realize (f₁✝ ⟹ f₂✝) (⇑f ∘ default) (⇑f ∘ xs✝) ↔ BoundedFormula.Realize (f₁✝ ⟹ f₂✝) default xs✝

Next tactic:
simp [ih1, ih2]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · 

Proof state:
case h.refine'_5
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n : ℕ
φ : BoundedFormula L Empty n
⊢ ∀ {n : ℕ} (f_1 : BoundedFormula L Empty (n + 1)),
    (∀ (xs : Fin (n + 1) → M),
        BoundedFormula.Realize f_1 (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize f_1 default xs) →
      ∀ (xs : Fin n → M),
        BoundedFormula.Realize (∀'f_1) (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize (∀'f_1) default xs

Next tactic:
intro n φ ih xs
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · intro n φ ih xs
    

Proof state:
case h.refine'_5
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n✝ : ℕ
φ✝ : BoundedFormula L Empty n✝
n : ℕ
φ : BoundedFormula L Empty (n + 1)
ih : ∀ (xs : Fin (n + 1) → M), BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize φ default xs
xs : Fin n → M
⊢ BoundedFormula.Realize (∀'φ) (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize (∀'φ) default xs

Next tactic:
simp only [BoundedFormula.realize_all]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · intro n φ ih xs
    simp only [BoundedFormula.realize_all]
    

Proof state:
case h.refine'_5
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n✝ : ℕ
φ✝ : BoundedFormula L Empty n✝
n : ℕ
φ : BoundedFormula L Empty (n + 1)
ih : ∀ (xs : Fin (n + 1) → M), BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize φ default xs
xs : Fin n → M
⊢ (∀ (a : N), BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)) ↔
    ∀ (a : M), BoundedFormula.Realize φ default (Fin.snoc xs a)

Next tactic:
refine' ⟨fun h a => _, _⟩
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · intro n φ ih xs
    simp only [BoundedFormula.realize_all]
    refine' ⟨fun h a => _, _⟩
    · 

Proof state:
case h.refine'_5.refine'_1
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n✝ : ℕ
φ✝ : BoundedFormula L Empty n✝
n : ℕ
φ : BoundedFormula L Empty (n + 1)
ih : ∀ (xs : Fin (n + 1) → M), BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize φ default xs
xs : Fin n → M
h : ∀ (a : N), BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
a : M
⊢ BoundedFormula.Realize φ default (Fin.snoc xs a)

Next tactic:
rw [← ih, Fin.comp_snoc]
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · intro n φ ih xs
    simp only [BoundedFormula.realize_all]
    refine' ⟨fun h a => _, _⟩
    · rw [← ih, Fin.comp_snoc]
      

Proof state:
case h.refine'_5.refine'_1
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n✝ : ℕ
φ✝ : BoundedFormula L Empty n✝
n : ℕ
φ : BoundedFormula L Empty (n + 1)
ih : ∀ (xs : Fin (n + 1) → M), BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize φ default xs
xs : Fin n → M
h : ∀ (a : N), BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
a : M
⊢ BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) (f a))

Next tactic:
exact h (f a)
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
    (htv :
      ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
        φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
          ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
    ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
  suffices h :
    ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
      φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs
  · intro n φ x
    refine' φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
  refine' fun n φ => φ.recOn _ _ _ _ _
  · exact fun {_} _ => Iff.rfl
  · intros
    simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
  · intros
    simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
    erw [map_rel f]
  · intro _ _ _ ih1 ih2 _
    simp [ih1, ih2]
  · intro n φ ih xs
    simp only [BoundedFormula.realize_all]
    refine' ⟨fun h a => _, _⟩
    · rw [← ih, Fin.comp_snoc]
      exact h (f a)
    · 

Proof state:
case h.refine'_5.refine'_2
L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : Structure L M
inst✝² : Structure L N
inst✝¹ : Structure L P
inst✝ : Structure L Q
f : M ↪[L] N
htv :
  ∀ (n : ℕ) (φ : BoundedFormula L Empty (n + 1)) (x : Fin n → M) (a : N),
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) a) →
      ∃ b, BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ x) (f b))
n✝ : ℕ
φ✝ : BoundedFormula L Empty n✝
n : ℕ
φ : BoundedFormula L Empty (n + 1)
ih : ∀ (xs : Fin (n + 1) → M), BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ xs) ↔ BoundedFormula.Realize φ default xs
xs : Fin n → M
⊢ (∀ (a : M), BoundedFormula.Realize φ default (Fin.snoc xs a)) →
    ∀ (a : N), BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)

Next tactic:
contrapose!