Theorem: FirstOrder.Language.ElementaryEmbedding.map_boundedFormula
File: Mathlib/ModelTheory/ElementaryMaps.lean

tactic: classical
  rw [← BoundedFormula.realize_restrictFreeVar Set.Subset.rfl, Set.inclusion_eq_id, iff_eq_eq]
  have h :=
    f.map_formula' ((φ.restrictFreeVar id).toFormula.relabel (Fintype.equivFin _))
      (Sum.elim (v ∘ (↑)) xs ∘ (Fintype.equivFin _).symm)
  simp only [Formula.realize_relabel, BoundedFormula.realize_toFormula, iff_eq_eq] at h
  rw [← Function.comp.assoc _ _ (Fintype.equivFin _).symm,
    Function.comp.assoc _ (Fintype.equivFin _).symm (Fintype.equivFin _),
    _root_.Equiv.symm_comp_self, Function.comp_id, Function.comp.assoc, Sum.elim_comp_inl,
    Function.comp.assoc _ _ Sum.inr, Sum.elim_comp_inr, ← Function.comp.assoc] at h
  refine h.trans ?_
  erw [Function.comp.assoc _ _ (Fintype.equivFin _), _root_.Equiv.symm_comp_self,
    Function.comp_id, Sum.elim_comp_inl, Sum.elim_comp_inr (v ∘ Subtype.val) xs,
    ← Set.inclusion_eq_id (s := (BoundedFormula.freeVarFinset φ : Set α)) Set.Subset.rfl,
    BoundedFormula.realize_restrictFreeVar Set.Subset.rfl]
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
⊢ φ.Realize (⇑f ∘ v) (⇑f ∘ xs) ↔ φ.Realize v xs
state_after: no goals

tactic: rw [← BoundedFormula.realize_restrictFreeVar Set.Subset.rfl, Set.inclusion_eq_id, iff_eq_eq]
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
⊢ φ.Realize (⇑f ∘ v) (⇑f ∘ xs) ↔ φ.Realize v xs
state_after: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs

tactic: have h :=
  f.map_formula' ((φ.restrictFreeVar id).toFormula.relabel (Fintype.equivFin _))
    (Sum.elim (v ∘ (↑)) xs ∘ (Fintype.equivFin _).symm)
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs
state_after: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (Formula.relabel (⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)))
          (φ.restrictFreeVar id).toFormula).Realize
      (↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ↔
    (Formula.relabel (⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)))
          (φ.restrictFreeVar id).toFormula).Realize
      (Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs

tactic: simp only [Formula.realize_relabel, BoundedFormula.realize_toFormula, iff_eq_eq] at h
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (Formula.relabel (⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)))
          (φ.restrictFreeVar id).toFormula).Realize
      (↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ↔
    (Formula.relabel (⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)))
          (φ.restrictFreeVar id).toFormula).Realize
      (Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs
state_after: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize
      (((↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs

tactic: rw [← Function.comp.assoc _ _ (Fintype.equivFin _).symm,
  Function.comp.assoc _ (Fintype.equivFin _).symm (Fintype.equivFin _),
  _root_.Equiv.symm_comp_self, Function.comp_id, Function.comp.assoc, Sum.elim_comp_inl,
  Function.comp.assoc _ _ Sum.inr, Sum.elim_comp_inr, ← Function.comp.assoc] at h
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize
      (((↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((↑f ∘ Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs
state_after: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize ((↑f ∘ v) ∘ Subtype.val) (↑f ∘ xs) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs

tactic: refine h.trans ?_
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize ((↑f ∘ v) ∘ Subtype.val) (↑f ∘ xs) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize ((⇑f ∘ v) ∘ Subtype.val) (⇑f ∘ xs) = φ.Realize v xs
state_after: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize ((↑f ∘ v) ∘ Subtype.val) (↑f ∘ xs) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr) =
    φ.Realize v xs

tactic: erw [Function.comp.assoc _ _ (Fintype.equivFin _), _root_.Equiv.symm_comp_self,
  Function.comp_id, Sum.elim_comp_inl, Sum.elim_comp_inr (v ∘ Subtype.val) xs,
  ← Set.inclusion_eq_id (s := (BoundedFormula.freeVarFinset φ : Set α)) Set.Subset.rfl,
  BoundedFormula.realize_restrictFreeVar Set.Subset.rfl]
state_before: L : Language
M : Type u_1
N : Type u_2
P : Type u_3
Q : Type u_4
inst✝³ : L.Structure M
inst✝² : L.Structure N
inst✝¹ : L.Structure P
inst✝ : L.Structure Q
f : M ↪ₑ[L] N
α : Type u_5
n : ℕ
φ : L.BoundedFormula α n
v : α → M
xs : Fin n → M
h :
  (φ.restrictFreeVar id).Realize ((↑f ∘ v) ∘ Subtype.val) (↑f ∘ xs) =
    (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr)
⊢ (φ.restrictFreeVar id).Realize
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inl)
      (((Sum.elim (v ∘ Subtype.val) xs ∘ ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n)).symm) ∘
          ⇑(Fintype.equivFin ({ x // x ∈ φ.freeVarFinset } ⊕ Fin n))) ∘
        Sum.inr) =
    φ.Realize v xs
state_after: no goals