l3lab/ntp-mathlib huggingface dataset:
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by intros; ext; simp [Seq.seq]
    seqLeft_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqLeft.seqLeft]
    seqRight_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqRight.seqRight]
    pure_seq := by 

Proof state:
src✝ : Monad Erased := Erased.Monad
⊢ ∀ {α β : Type ?u.5425} (g : α → β) (x : Erased α), (Seq.seq (pure g) fun x_1 => x) = g <$> x

Next tactic:
intros
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by intros; ext; simp [Seq.seq]
    seqLeft_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqLeft.seqLeft]
    seqRight_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqRight.seqRight]
    pure_seq := by intros; 

Proof state:
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
g✝ : α✝ → β✝
x✝ : Erased α✝
⊢ (Seq.seq (pure g✝) fun x => x✝) = g✝ <$> x✝

Next tactic:
ext
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by intros; ext; simp [Seq.seq]
    seqLeft_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqLeft.seqLeft]
    seqRight_eq := by intros; ext; simp [Seq.seq, Functor.mapConst, SeqRight.seqRight]
    pure_seq := by intros; ext; 

Proof state:
case h
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
g✝ : α✝ → β✝
x✝ : Erased α✝
⊢ out (Seq.seq (pure g✝) fun x => x✝) = out (g✝ <$> x✝)

Next tactic:
simp [Seq.seq, Functor.mapConst, SeqRight.seqRight]
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by 

Proof state:
src✝ : Monad Erased := Erased.Monad
⊢ ∀ {α β : Type ?u.5425} (f : α → β) (x : Erased α),
    (do
        let a ← x
        pure (f a)) =
      f <$> x

Next tactic:
intros
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; 

Proof state:
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
f✝ : α✝ → β✝
x✝ : Erased α✝
⊢ (do
      let a ← x✝
      pure (f✝ a)) =
    f✝ <$> x✝

Next tactic:
ext
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; 

Proof state:
case h
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
f✝ : α✝ → β✝
x✝ : Erased α✝
⊢ (out do
      let a ← x✝
      pure (f✝ a)) =
    out (f✝ <$> x✝)

Next tactic:
simp
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by 

Proof state:
src✝ : Monad Erased := Erased.Monad
⊢ ∀ {α β : Type ?u.5425} (f : Erased (α → β)) (x : Erased α),
    (do
        let x_1 ← f
        x_1 <$> x) =
      Seq.seq f fun x_1 => x

Next tactic:
intros
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by intros; 

Proof state:
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
f✝ : Erased (α✝ → β✝)
x✝ : Erased α✝
⊢ (do
      let x ← f✝
      x <$> x✝) =
    Seq.seq f✝ fun x => x✝

Next tactic:
ext
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; simp
    bind_pure_comp := by intros; ext; simp
    bind_map := by intros; ext; 

Proof state:
case h
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
f✝ : Erased (α✝ → β✝)
x✝ : Erased α✝
⊢ (out do
      let x ← f✝
      x <$> x✝) =
    out (Seq.seq f✝ fun x => x✝)

Next tactic:
simp [Seq.seq]
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by 

Proof state:
src✝ : Monad Erased := Erased.Monad
⊢ ∀ {α β : Type ?u.5425} (x : α) (f : α → Erased β), pure x >>= f = f x

Next tactic:
intros
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; 

Proof state:
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
x✝ : α✝
f✝ : α✝ → Erased β✝
⊢ pure x✝ >>= f✝ = f✝ x✝

Next tactic:
ext
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; 

Proof state:
case h
src✝ : Monad Erased := Erased.Monad
α✝ β✝ : Type ?u.5425
x✝ : α✝
f✝ : α✝ → Erased β✝
⊢ out (pure x✝ >>= f✝) = out (f✝ x✝)

Next tactic:
simp
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by 

Proof state:
src✝ : Monad Erased := Erased.Monad
⊢ ∀ {α β γ : Type ?u.5425} (x : Erased α) (f : α → Erased β) (g : β → Erased γ),
    x >>= f >>= g = x >>= fun x => f x >>= g

Next tactic:
intros
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; 

Proof state:
src✝ : Monad Erased := Erased.Monad
α✝ β✝ γ✝ : Type ?u.5425
x✝ : Erased α✝
f✝ : α✝ → Erased β✝
g✝ : β✝ → Erased γ✝
⊢ x✝ >>= f✝ >>= g✝ = x✝ >>= fun x => f✝ x >>= g✝

Next tactic:
ext
protected instance LawfulMonad : LawfulMonad Erased :=
  { Erased.Monad with
    id_map := by intros; ext; simp
    map_const := by intros; ext; simp [Functor.mapConst]
    pure_bind := by intros; ext; simp
    bind_assoc := by intros; ext; 

Proof state:
case h
src✝ : Monad Erased := Erased.Monad
α✝ β✝ γ✝ : Type ?u.5425
x✝ : Erased α✝
f✝ : α✝ → Erased β✝
g✝ : β✝ → Erased γ✝
⊢ out (x✝ >>= f✝ >>= g✝) = out (x✝ >>= fun x => f✝ x >>= g✝)

Next tactic:
simp
instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R]
    [StarOrderedRing R] : OrderedAddCommMonoid R where
  add_le_add_left := fun x y hle z ↦ by
    

Proof state:
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarOrderedRing R
x y : R
hle : x ≤ y
z : R
⊢ z + x ≤ z + y

Next tactic:
rw [StarOrderedRing.le_iff] at hle ⊢
instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R]
    [StarOrderedRing R] : OrderedAddCommMonoid R where
  add_le_add_left := fun x y hle z ↦ by
    rw [StarOrderedRing.le_iff] at hle ⊢
    

Proof state:
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarOrderedRing R
x y : R
hle : ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p
z : R
⊢ ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), z + y = z + x + p

Next tactic:
refine hle.imp fun s hs ↦ ?_
instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R]
    [StarOrderedRing R] : OrderedAddCommMonoid R where
  add_le_add_left := fun x y hle z ↦ by
    rw [StarOrderedRing.le_iff] at hle ⊢
    refine hle.imp fun s hs ↦ ?_
    

Proof state:
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarOrderedRing R
x y : R
hle : ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p
z s : R
hs : s ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ y = x + s
⊢ s ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ z + y = z + x + s

Next tactic:
rw [hs.2, add_assoc]
instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R]
    [StarOrderedRing R] : OrderedAddCommMonoid R where
  add_le_add_left := fun x y hle z ↦ by
    rw [StarOrderedRing.le_iff] at hle ⊢
    refine hle.imp fun s hs ↦ ?_
    rw [hs.2, add_assoc]
    

Proof state:
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarOrderedRing R
x y : R
hle : ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p
z s : R
hs : s ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ y = x + s
⊢ s ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ z + (x + s) = z + (x + s)

Next tactic:
exact ⟨hs.1, rfl⟩
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    

Proof state:
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
x y : R
⊢ x ≤ y ↔ ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p

Next tactic:
refine' ⟨fun h => _, _⟩
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · 

Proof state:
case refine'_1
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
x y : R
h : x ≤ y
⊢ ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p

Next tactic:
obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      

Proof state:
case refine'_1.intro
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
x y : R
h : x ≤ y
p : R
hp : y = x + star p * p
⊢ ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p

Next tactic:
exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · 

Proof state:
case refine'_2
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
x y : R
⊢ (∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p) → x ≤ y

Next tactic:
rintro ⟨p, hp, hpxy⟩
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      

Proof state:
case refine'_2.intro.intro
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
x y p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
hpxy : y = x + p
⊢ x ≤ y

Next tactic:
revert x y hpxy
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      

Proof state:
case refine'_2.intro.intro
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
⊢ ∀ (x y : R), y = x + p → x ≤ y

Next tactic:
refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
      · 

Proof state:
case refine'_2.intro.intro.refine'_1
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
⊢ ∀ x ∈ Set.range fun s => star s * s, ∀ (x_1 y : R), y = x_1 + x → x_1 ≤ y

Next tactic:
rintro _ ⟨s, rfl⟩ x y rfl
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
      · rintro _ ⟨s, rfl⟩ x y rfl
        

Proof state:
case refine'_2.intro.intro.refine'_1.intro
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
s x : R
⊢ x ≤ x + (fun s => star s * s) s

Next tactic:
exact (h_le_iff _ _).mpr ⟨s, rfl⟩
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
      · rintro _ ⟨s, rfl⟩ x y rfl
        exact (h_le_iff _ _).mpr ⟨s, rfl⟩
      · 

Proof state:
case refine'_2.intro.intro.refine'_2
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
⊢ ∀ (x y : R),
    (∀ (x_1 y : R), y = x_1 + x → x_1 ≤ y) →
      (∀ (x y_1 : R), y_1 = x + y → x ≤ y_1) → ∀ (x_1 y_1 : R), y_1 = x_1 + (x + y) → x_1 ≤ y_1

Next tactic:
rintro a b ha hb x y rfl
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
      · rintro _ ⟨s, rfl⟩ x y rfl
        exact (h_le_iff _ _).mpr ⟨s, rfl⟩
      · rintro a b ha hb x y rfl
        

Proof state:
case refine'_2.intro.intro.refine'_2
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
a b : R
ha : ∀ (x y : R), y = x + a → x ≤ y
hb : ∀ (x y : R), y = x + b → x ≤ y
x : R
⊢ x ≤ x + (a + b)

Next tactic:
rw [← add_assoc]
/-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if
`y = x + star s * s` for some `s : R`.

This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`)
and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances.

If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see
`StarOrderedRing.ofNonnegIff` for a more convenient version.
 -/
@[reducible]
def ofLEIff [NonUnitalSemiring R] [PartialOrder R] [StarRing R]
    (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where
  le_iff x y := by
    refine' ⟨fun h => _, _⟩
    · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h
      exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩
    · rintro ⟨p, hp, hpxy⟩
      revert x y hpxy
      refine' AddSubmonoid.closure_induction hp _ (fun x y h => add_zero x ▸ h.ge) _
      · rintro _ ⟨s, rfl⟩ x y rfl
        exact (h_le_iff _ _).mpr ⟨s, rfl⟩
      · rintro a b ha hb x y rfl
        rw [← add_assoc]
        

Proof state:
case refine'_2.intro.intro.refine'_2
R : Type u
inst✝² : NonUnitalSemiring R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_le_iff : ∀ (x y : R), x ≤ y ↔ ∃ s, y = x + star s * s
p : R
hp : p ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
a b : R
ha : ∀ (x y : R), y = x + a → x ≤ y
hb : ∀ (x y : R), y = x + b → x ≤ y
x : R
⊢ x ≤ x + a + b

Next tactic:
exact (ha _ _ rfl).trans (hb _ _ rfl)
/-- When `R` is a non-unital ring, to construct a `StarOrderedRing` instance it suffices to
show that the nonnegative elements are precisely those elements in the `AddSubmonoid` generated
by `star s * s` for `s : R`. -/
@[reducible]
def ofNonnegIff [NonUnitalRing R] [PartialOrder R] [StarRing R]
    (h_add : ∀ {x y : R}, x ≤ y → ∀ z, z + x ≤ z + y)
    (h_nonneg_iff : ∀ x : R, 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s : R => star s * s)) :
    StarOrderedRing R where
  le_iff x y := by
    

Proof state:
R : Type u
inst✝² : NonUnitalRing R
inst✝¹ : PartialOrder R
inst✝ : StarRing R
h_add : ∀ {x y : R}, x ≤ y → ∀ (z : R), z + x ≤ z + y
h_nonneg_iff : ∀ (x : R), 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s => star s * s)
x y : R
⊢ x ≤ y ↔ ∃ p ∈ AddSubmonoid.closure (Set.range fun s => star s * s), y = x + p

Next tactic:
haveI : CovariantClass R R (· + ·) (· ≤ ·) := ⟨fun _ _ _ h => h_add h _⟩