l3lab/ntp-mathlib huggingface dataset:
theorem definable_finset_biInter {ι : Type*} {f : ∀ _ : ι, Set (α → M)}
    (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
ι : Type u_2
f : ι → Set (α → M)
hf : ∀ (i : ι), Definable A L (f i)
s : Finset ι
⊢ Definable A L (⋂ i ∈ s, f i)

Next tactic:
rw [← Finset.inf_set_eq_iInter]
theorem definable_finset_biInter {ι : Type*} {f : ∀ _ : ι, Set (α → M)}
    (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by
  rw [← Finset.inf_set_eq_iInter]
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
ι : Type u_2
f : ι → Set (α → M)
hf : ∀ (i : ι), Definable A L (f i)
s : Finset ι
⊢ Definable A L (Finset.inf s fun i => f i)

Next tactic:
exact definable_finset_inf hf s
theorem definable_finset_biUnion {ι : Type*} {f : ∀ _ : ι, Set (α → M)}
    (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
ι : Type u_2
f : ι → Set (α → M)
hf : ∀ (i : ι), Definable A L (f i)
s : Finset ι
⊢ Definable A L (⋃ i ∈ s, f i)

Next tactic:
rw [← Finset.sup_set_eq_biUnion]
theorem definable_finset_biUnion {ι : Type*} {f : ∀ _ : ι, Set (α → M)}
    (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by
  rw [← Finset.sup_set_eq_biUnion]
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
ι : Type u_2
f : ι → Set (α → M)
hf : ∀ (i : ι), Definable A L (f i)
s : Finset ι
⊢ Definable A L (Finset.sup s fun i => f i)

Next tactic:
exact definable_finset_sup hf s
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ s : Set (α → M)
hf : Definable A L s
⊢ Definable A L sᶜ

Next tactic:
rcases hf with ⟨φ, hφ⟩
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
  rcases hf with ⟨φ, hφ⟩
  

Proof state:
case intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ s : Set (α → M)
φ : Formula (L[[↑A]]) α
hφ : s = setOf (Formula.Realize φ)
⊢ Definable A L sᶜ

Next tactic:
refine' ⟨φ.not, _⟩
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
  rcases hf with ⟨φ, hφ⟩
  refine' ⟨φ.not, _⟩
  

Proof state:
case intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ s : Set (α → M)
φ : Formula (L[[↑A]]) α
hφ : s = setOf (Formula.Realize φ)
⊢ sᶜ = setOf (Formula.Realize (Formula.not φ))

Next tactic:
ext v
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
  rcases hf with ⟨φ, hφ⟩
  refine' ⟨φ.not, _⟩
  ext v
  

Proof state:
case intro.h
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ s : Set (α → M)
φ : Formula (L[[↑A]]) α
hφ : s = setOf (Formula.Realize φ)
v : α → M
⊢ v ∈ sᶜ ↔ v ∈ setOf (Formula.Realize (Formula.not φ))

Next tactic:
rw [hφ, compl_setOf, mem_setOf, mem_setOf, Formula.realize_not]
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
    A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
f : α → β
s : Set (α → M)
h : Definable A L s
⊢ Definable A L ((fun g => g ∘ f) ⁻¹' s)

Next tactic:
obtain ⟨φ, rfl⟩ := h
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
    A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
  obtain ⟨φ, rfl⟩ := h
  

Proof state:
case intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
f : α → β
φ : Formula (L[[↑A]]) α
⊢ Definable A L ((fun g => g ∘ f) ⁻¹' setOf (Formula.Realize φ))

Next tactic:
refine' ⟨φ.relabel f, _⟩
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
    A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
  obtain ⟨φ, rfl⟩ := h
  refine' ⟨φ.relabel f, _⟩
  

Proof state:
case intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
f : α → β
φ : Formula (L[[↑A]]) α
⊢ (fun g => g ∘ f) ⁻¹' setOf (Formula.Realize φ) = setOf (Formula.Realize (Formula.relabel f φ))

Next tactic:
ext
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
    A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
  obtain ⟨φ, rfl⟩ := h
  refine' ⟨φ.relabel f, _⟩
  ext
  

Proof state:
case intro.h
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
f : α → β
φ : Formula (L[[↑A]]) α
x✝ : β → M
⊢ x✝ ∈ (fun g => g ∘ f) ⁻¹' setOf (Formula.Realize φ) ↔ x✝ ∈ setOf (Formula.Realize (Formula.relabel f φ))

Next tactic:
simp only [Set.preimage_setOf_eq, mem_setOf_eq, Formula.realize_relabel]
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
⊢ Definable A L ((fun g => g ∘ ⇑f) '' s)

Next tactic:
refine' (congr rfl _).mp (h.preimage_comp f.symm)
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
⊢ (fun g => g ∘ ⇑f.symm) ⁻¹' s = (fun g => g ∘ ⇑f) '' s

Next tactic:
rw [image_eq_preimage_of_inverse]
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · 

Proof state:
case h₁
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
⊢ Function.LeftInverse (fun g => g ∘ ⇑f.symm) fun g => g ∘ ⇑f

Next tactic:
intro i
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · intro i
    

Proof state:
case h₁
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
i : β → M
⊢ (fun g => g ∘ ⇑f.symm) ((fun g => g ∘ ⇑f) i) = i

Next tactic:
ext b
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · intro i
    ext b
    

Proof state:
case h₁.h
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
i : β → M
b : β
⊢ (fun g => g ∘ ⇑f.symm) ((fun g => g ∘ ⇑f) i) b = i b

Next tactic:
simp only [Function.comp_apply, Equiv.apply_symm_apply]
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · intro i
    ext b
    simp only [Function.comp_apply, Equiv.apply_symm_apply]
  · 

Proof state:
case h₂
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
⊢ Function.RightInverse (fun g => g ∘ ⇑f.symm) fun g => g ∘ ⇑f

Next tactic:
intro i
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · intro i
    ext b
    simp only [Function.comp_apply, Equiv.apply_symm_apply]
  · intro i
    

Proof state:
case h₂
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
i : α → M
⊢ (fun g => g ∘ ⇑f) ((fun g => g ∘ ⇑f.symm) i) = i

Next tactic:
ext a
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
    A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
  refine' (congr rfl _).mp (h.preimage_comp f.symm)
  rw [image_eq_preimage_of_inverse]
  · intro i
    ext b
    simp only [Function.comp_apply, Equiv.apply_symm_apply]
  · intro i
    ext a
    

Proof state:
case h₂.h
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s✝ : Set (α → M)
s : Set (β → M)
h : Definable A L s
f : α ≃ β
i : α → M
a : α
⊢ (fun g => g ∘ ⇑f) ((fun g => g ∘ ⇑f.symm) i) a = i a

Next tactic:
simp
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
⊢ Definable A L s ↔ ∃ A0, ↑A0 ⊆ A ∧ Definable (↑A0) L s

Next tactic:
letI := Classical.decEq M
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
this : DecidableEq M := Classical.decEq M
⊢ Definable A L s ↔ ∃ A0, ↑A0 ⊆ A ∧ Definable (↑A0) L s

Next tactic:
letI := Classical.decEq α
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
⊢ Definable A L s ↔ ∃ A0, ↑A0 ⊆ A ∧ Definable (↑A0) L s

Next tactic:
constructor
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · 

Proof state:
case mp
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
⊢ Definable A L s → ∃ A0, ↑A0 ⊆ A ∧ Definable (↑A0) L s

Next tactic:
simp only [definable_iff_exists_formula_sum]
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    

Proof state:
case mp
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
s : Set (α → M)
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
⊢ (∃ φ, s = {v | Formula.Realize φ (Sum.elim Subtype.val v)}) →
    ∃ A0, ↑A0 ⊆ A ∧ ∃ φ, s = {v | Formula.Realize φ (Sum.elim Subtype.val v)}

Next tactic:
rintro ⟨φ, rfl⟩
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    

Proof state:
case mp.intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
⊢ ∃ A0,
    ↑A0 ⊆ A ∧
      ∃ φ_1, {v | Formula.Realize φ (Sum.elim Subtype.val v)} = {v | Formula.Realize φ_1 (Sum.elim Subtype.val v)}

Next tactic:
let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    

Proof state:
case mp.intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
⊢ ∃ A0,
    ↑A0 ⊆ A ∧
      ∃ φ_1, {v | Formula.Realize φ (Sum.elim Subtype.val v)} = {v | Formula.Realize φ_1 (Sum.elim Subtype.val v)}

Next tactic:
have hA0 : (A0 : Set M) ⊆ A := by simp
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by 

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
⊢ ↑A0 ⊆ A

Next tactic:
simp
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    

Proof state:
case mp.intro
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
⊢ ∃ A0,
    ↑A0 ⊆ A ∧
      ∃ φ_1, {v | Formula.Realize φ (Sum.elim Subtype.val v)} = {v | Formula.Realize φ_1 (Sum.elim Subtype.val v)}

Next tactic:
refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · 

Proof state:
case mp.intro.refine_1
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
⊢ (↑fun x => x ∈ (BoundedFormula.freeVarFinset φ).val) → (↑↑A0 ⊕ α) ⊕ Fin 0

Next tactic:
rintro ⟨a | a, ha⟩
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · rintro ⟨a | a, ha⟩
      · 

Proof state:
case mp.intro.refine_1.mk.inl
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
a : ↑A
ha : Sum.inl a ∈ fun x => x ∈ (BoundedFormula.freeVarFinset φ).val
⊢ (↑↑A0 ⊕ α) ⊕ Fin 0

Next tactic:
exact Sum.inl (Sum.inl ⟨a, by simpa using ha⟩)
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · rintro ⟨a | a, ha⟩
      · exact Sum.inl (Sum.inl ⟨a, by 

Proof state:
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
a : ↑A
ha : Sum.inl a ∈ fun x => x ∈ (BoundedFormula.freeVarFinset φ).val
⊢ ↑a ∈ ↑A0

Next tactic:
simpa using ha
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · rintro ⟨a | a, ha⟩
      · exact Sum.inl (Sum.inl ⟨a, by simpa using ha⟩)
      · 

Proof state:
case mp.intro.refine_1.mk.inr
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
a : α
ha : Sum.inr a ∈ fun x => x ∈ (BoundedFormula.freeVarFinset φ).val
⊢ (↑↑A0 ⊕ α) ⊕ Fin 0

Next tactic:
exact Sum.inl (Sum.inr a)
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · rintro ⟨a | a, ha⟩
      · exact Sum.inl (Sum.inl ⟨a, by simpa using ha⟩)
      · exact Sum.inl (Sum.inr a)
    · 

Proof state:
case mp.intro.refine_2
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
⊢ {v | Formula.Realize φ (Sum.elim Subtype.val v)} =
    {v |
      Formula.Realize
        (BoundedFormula.relabel
          (fun a =>
            Subtype.casesOn a fun val ha =>
              Sum.casesOn (motive := fun x =>
                (x ∈ fun x => x ∈ (BoundedFormula.freeVarFinset φ).val) → (↑↑A0 ⊕ α) ⊕ Fin 0) val
                (fun a ha => Sum.inl (Sum.inl { val := ↑a, property := (_ : ↑a ∈ ↑A0) }))
                (fun a ha => Sum.inl (Sum.inr a)) ha)
          (BoundedFormula.restrictFreeVar φ
            (inclusion
              (_ :
                (fun x => x ∈ (BoundedFormula.freeVarFinset φ).val) ⊆ fun x =>
                  x ∈ (BoundedFormula.freeVarFinset φ).val))))
        (Sum.elim Subtype.val v)}

Next tactic:
ext v
theorem definable_iff_finitely_definable :
    A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
      (A0 : Set M).Definable L s := by
  letI := Classical.decEq M
  letI := Classical.decEq α
  constructor
  · simp only [definable_iff_exists_formula_sum]
    rintro ⟨φ, rfl⟩
    let A0 := (φ.freeVarFinset.preimage Sum.inl
      (Function.Injective.injOn Sum.inl_injective _)).image Subtype.val
    have hA0 : (A0 : Set M) ⊆ A := by simp
    refine ⟨A0, hA0, (φ.restrictFreeVar
      (Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
    · rintro ⟨a | a, ha⟩
      · exact Sum.inl (Sum.inl ⟨a, by simpa using ha⟩)
      · exact Sum.inl (Sum.inr a)
    · ext v
      

Proof state:
case mp.intro.refine_2.h
M : Type w
A : Set M
L : Language
inst✝ : Structure L M
α : Type u₁
β : Type u_1
B : Set M
this✝ : DecidableEq M := Classical.decEq M
this : DecidableEq α := Classical.decEq α
φ : Formula L (↑A ⊕ α)
A0 : Finset M :=
  Finset.image Subtype.val
    (Finset.preimage (BoundedFormula.freeVarFinset φ) Sum.inl
      (_ : InjOn Sum.inl (Sum.inl ⁻¹' ↑(BoundedFormula.freeVarFinset φ))))
hA0 : ↑A0 ⊆ A
v : α → M
⊢ v ∈ {v | Formula.Realize φ (Sum.elim Subtype.val v)} ↔
    v ∈
      {v |
        Formula.Realize
          (BoundedFormula.relabel
            (fun a =>
              Subtype.casesOn a fun val ha =>
                Sum.casesOn (motive := fun x =>
                  (x ∈ fun x => x ∈ (BoundedFormula.freeVarFinset φ).val) → (↑↑A0 ⊕ α) ⊕ Fin 0) val
                  (fun a ha => Sum.inl (Sum.inl { val := ↑a, property := (_ : ↑a ∈ ↑A0) }))
                  (fun a ha => Sum.inl (Sum.inr a)) ha)
            (BoundedFormula.restrictFreeVar φ
              (inclusion
                (_ :
                  (fun x => x ∈ (BoundedFormula.freeVarFinset φ).val) ⊆ fun x =>
                    x ∈ (BoundedFormula.freeVarFinset φ).val))))
          (Sum.elim Subtype.val v)}

Next tactic:
simp only [Formula.Realize, BoundedFormula.realize_relabel,
        Set.mem_setOf_eq]