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
  · 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)
    · contrapose!
      

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, ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)) →
    ∃ a, ¬BoundedFormula.Realize φ default (Fin.snoc xs a)

Next tactic:
rintro ⟨a, ha⟩
/-- 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)
    · contrapose!
      rintro ⟨a, ha⟩
      

Proof state:
case h.refine'_5.refine'_2.intro
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
ha : ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
⊢ ∃ a, ¬BoundedFormula.Realize φ default (Fin.snoc xs a)

Next tactic:
obtain ⟨b, hb⟩ := htv n φ.not xs a (by
          rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
          exact ha)
/-- 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)
    · contrapose!
      rintro ⟨a, ha⟩
      obtain ⟨b, hb⟩ := htv n φ.not xs a (by
          

Proof state:
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
ha : ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
⊢ BoundedFormula.Realize (∼φ) default (Fin.snoc (⇑f ∘ xs) a)

Next tactic:
rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
/-- 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)
    · contrapose!
      rintro ⟨a, ha⟩
      obtain ⟨b, hb⟩ := htv n φ.not xs a (by
          rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
          

Proof state:
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
ha : ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
⊢ ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)

Next tactic:
exact ha
/-- 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)
    · contrapose!
      rintro ⟨a, ha⟩
      obtain ⟨b, hb⟩ := htv n φ.not xs a (by
          rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
          exact ha)
      · 

Proof state:
case h.refine'_5.refine'_2.intro.intro
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
ha : ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
b : M
hb : BoundedFormula.Realize (∼φ) default (Fin.snoc (⇑f ∘ xs) (f b))
⊢ ∃ a, ¬BoundedFormula.Realize φ default (Fin.snoc xs a)

Next tactic:
refine' ⟨b, fun h => hb (Eq.mp _ ((ih _).2 h))⟩
/-- 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)
    · contrapose!
      rintro ⟨a, ha⟩
      obtain ⟨b, hb⟩ := htv n φ.not xs a (by
          rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
          exact ha)
      · refine' ⟨b, fun h => hb (Eq.mp _ ((ih _).2 h))⟩
        

Proof state:
case h.refine'_5.refine'_2.intro.intro
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
ha : ¬BoundedFormula.Realize φ (⇑f ∘ default) (Fin.snoc (⇑f ∘ xs) a)
b : M
hb : BoundedFormula.Realize (∼φ) default (Fin.snoc (⇑f ∘ xs) (f b))
h : BoundedFormula.Realize φ default (Fin.snoc xs b)
⊢ BoundedFormula.Realize φ (⇑f ∘ default) (⇑f ∘ Fin.snoc xs b) =
    BoundedFormula.Realize φ default (Fin.snoc (⇑f ∘ xs) (f b))

Next tactic:
rw [Unique.eq_default (f ∘ default), Fin.comp_snoc]
/-- A first-order equivalence is also an elementary embedding. -/
def toElementaryEmbedding (f : M ≃[L] N) : M ↪ₑ[L] N where
  toFun := f
  map_formula' n φ x := by 

Proof state:
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
n : ℕ
φ : Formula L (Fin n)
x : Fin n → M
⊢ Formula.Realize φ (⇑f ∘ x) ↔ Formula.Realize φ x

Next tactic:
aesop
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ star (star x) = x

Next tactic:
unfold Star.star
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ { star := MulOpposite.unop ∘ ⇑((lift R) (MulOpposite.op ∘ ι R)) }.1
      ({ star := MulOpposite.unop ∘ ⇑((lift R) (MulOpposite.op ∘ ι R)) }.1 x) =
    x

Next tactic:
simp only [Function.comp_apply]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) x))) = x

Next tactic:
refine' FreeAlgebra.induction R X _ _ _ _ x
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · 

Proof state:
case refine'_1
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ ∀ (r : R),
    MulOpposite.unop
        (((lift R) (MulOpposite.op ∘ ι R))
          (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) ((algebraMap R (FreeAlgebra R X)) r)))) =
      (algebraMap R (FreeAlgebra R X)) r

Next tactic:
intros
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      

Proof state:
case refine'_1
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
r✝ : R
⊢ MulOpposite.unop
      (((lift R) (MulOpposite.op ∘ ι R))
        (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) ((algebraMap R (FreeAlgebra R X)) r✝)))) =
    (algebraMap R (FreeAlgebra R X)) r✝

Next tactic:
simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · 

Proof state:
case refine'_2
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ ∀ (x : X),
    MulOpposite.unop
        (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (ι R x)))) =
      ι R x

Next tactic:
intros
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      

Proof state:
case refine'_2
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
x✝ : X
⊢ MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (ι R x✝)))) =
    ι R x✝

Next tactic:
simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · 

Proof state:
case refine'_3
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ ∀ (a b : FreeAlgebra R X),
    MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) a))) = a →
      MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) b))) =
          b →
        MulOpposite.unop
            (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (a * b)))) =
          a * b

Next tactic:
intros
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · intros
      

Proof state:
case refine'_3
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x a✝² b✝ : FreeAlgebra R X
a✝¹ :
  MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) a✝²))) = a✝²
a✝ : MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) b✝))) = b✝
⊢ MulOpposite.unop
      (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (a✝² * b✝)))) =
    a✝² * b✝

Next tactic:
simp only [*, map_mul, MulOpposite.unop_mul]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · intros
      simp only [*, map_mul, MulOpposite.unop_mul]
    · 

Proof state:
case refine'_4
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : FreeAlgebra R X
⊢ ∀ (a b : FreeAlgebra R X),
    MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) a))) = a →
      MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) b))) =
          b →
        MulOpposite.unop
            (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (a + b)))) =
          a + b

Next tactic:
intros
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · intros
      simp only [*, map_mul, MulOpposite.unop_mul]
    · intros
      

Proof state:
case refine'_4
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x a✝² b✝ : FreeAlgebra R X
a✝¹ :
  MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) a✝²))) = a✝²
a✝ : MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) b✝))) = b✝
⊢ MulOpposite.unop
      (((lift R) (MulOpposite.op ∘ ι R)) (MulOpposite.unop (((lift R) (MulOpposite.op ∘ ι R)) (a✝² + b✝)))) =
    a✝² + b✝

Next tactic:
simp only [*, map_add, MulOpposite.unop_add]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · intros
      simp only [*, map_mul, MulOpposite.unop_mul]
    · intros
      simp only [*, map_add, MulOpposite.unop_add]
  star_mul a b := by 

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
a b : FreeAlgebra R X
⊢ star (a * b) = star b * star a

Next tactic:
simp only [Function.comp_apply, map_mul, MulOpposite.unop_mul]
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
  star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
  star_involutive x := by
    unfold Star.star
    simp only [Function.comp_apply]
    refine' FreeAlgebra.induction R X _ _ _ _ x
    · intros
      simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
    · intros
      simp only [lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
    · intros
      simp only [*, map_mul, MulOpposite.unop_mul]
    · intros
      simp only [*, map_add, MulOpposite.unop_add]
  star_mul a b := by simp only [Function.comp_apply, map_mul, MulOpposite.unop_mul]
  star_add a b := by 

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
a b : FreeAlgebra R X
⊢ star (a + b) = star a + star b

Next tactic:
simp only [Function.comp_apply, map_add, MulOpposite.unop_add]
@[simp]
theorem star_ι (x : X) : star (ι R x) = ι R x := by 

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
x : X
⊢ star (ι R x) = ι R x

Next tactic:
simp [star, Star.star]
@[simp]
theorem star_algebraMap (r : R) : star (algebraMap R (FreeAlgebra R X) r) = algebraMap R _ r := by
  

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
r : R
⊢ star ((algebraMap R (FreeAlgebra R X)) r) = (algebraMap R (FreeAlgebra R X)) r

Next tactic:
simp [star, Star.star]
/-- `star` as an `AlgEquiv` -/
def starHom : FreeAlgebra R X ≃ₐ[R] (FreeAlgebra R X)ᵐᵒᵖ :=
  { starRingEquiv with commutes' := fun r => by 

Proof state:
R : Type u_1
inst✝ : CommSemiring R
X : Type u_2
src✝ : FreeAlgebra R X ≃+* (FreeAlgebra R X)ᵐᵒᵖ := starRingEquiv
r : R
⊢ Equiv.toFun src✝.toEquiv ((algebraMap R (FreeAlgebra R X)) r) = (algebraMap R (FreeAlgebra R X)ᵐᵒᵖ) r

Next tactic:
simp [star_algebraMap]