Skip to content

Commit b92d742

Browse files
committed
chore (Order.Defs): reorder parents to simplify instances and avoid non-reducible defeq checks (leanprover-community#9034)
Currently, `OrderDual.orderedCommMonoid` unifies with `LinearOrderedAddCommMonoid.toOrderedAddCommMonoid` at instance transparency because of an extra eta expansion in its definition. The provided instances can be synthesized by Lean and deleted. This removes the extraneous eta expansion but causes defeq to fail at instance transparency. To fix this, we reorder the parents of `LinearOrderedAddCommMonoid`. We also do this for the non-`Add` version.
1 parent 0b290c7 commit b92d742

3 files changed

Lines changed: 33 additions & 36 deletions

File tree

Mathlib/Algebra/Order/Monoid/Defs.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,14 @@ set_option linter.deprecated false in
123123
#align bit0_pos bit0_pos
124124

125125
/-- A linearly ordered additive commutative monoid. -/
126-
class LinearOrderedAddCommMonoid (α : Type*) extends LinearOrder α, OrderedAddCommMonoid α
126+
class LinearOrderedAddCommMonoid (α : Type*) extends OrderedAddCommMonoid α, LinearOrder α
127127
#align linear_ordered_add_comm_monoid LinearOrderedAddCommMonoid
128128

129129
/-- A linearly ordered commutative monoid. -/
130130
@[to_additive]
131-
class LinearOrderedCommMonoid (α : Type*) extends LinearOrder α, OrderedCommMonoid α
131+
class LinearOrderedCommMonoid (α : Type*) extends OrderedCommMonoid α, LinearOrder α
132132
#align linear_ordered_comm_monoid LinearOrderedCommMonoid
133133

134-
attribute [to_additive existing] LinearOrderedCommMonoid.toOrderedCommMonoid
135-
136134
/-- A linearly ordered cancellative additive commutative monoid is an additive commutative monoid
137135
with a decidable linear order in which addition is cancellative and monotone. -/
138136
class LinearOrderedCancelAddCommMonoid (α : Type*) extends OrderedCancelAddCommMonoid α,

Mathlib/Algebra/Order/Monoid/OrderDual.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ instance covariantClass_swap_mul_lt [LT α] [Mul α]
8181

8282
@[to_additive]
8383
instance orderedCommMonoid [OrderedCommMonoid α] : OrderedCommMonoid αᵒᵈ :=
84-
{ OrderDual.instPartialOrder α, OrderDual.instCommMonoid with
85-
mul_le_mul_left := fun _ _ h c => mul_le_mul_left' h c }
84+
{ mul_le_mul_left := fun _ _ h c => mul_le_mul_left' h c }
8685
#align order_dual.ordered_comm_monoid OrderDual.orderedCommMonoid
8786
#align order_dual.ordered_add_comm_monoid OrderDual.orderedAddCommMonoid
8887

@@ -99,8 +98,7 @@ instance OrderedCancelCommMonoid.to_contravariantClass [OrderedCancelCommMonoid
9998

10099
@[to_additive]
101100
instance orderedCancelCommMonoid [OrderedCancelCommMonoid α] : OrderedCancelCommMonoid αᵒᵈ :=
102-
{ OrderDual.orderedCommMonoid, @OrderDual.instCancelCommMonoid α _ with
103-
le_of_mul_le_mul_left := fun _ _ _ : α => le_of_mul_le_mul_left' }
101+
{ le_of_mul_le_mul_left := fun _ _ _ : α => le_of_mul_le_mul_left' }
104102

105103
@[to_additive]
106104
instance linearOrderedCancelCommMonoid [LinearOrderedCancelCommMonoid α] :

Mathlib/RingTheory/Valuation/ValuationRing.lean

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected theorem le_total (a b : ValueGroup A K) : a ≤ b ∨ b ≤ a := by
126126

127127
-- Porting note: it is much faster to split the instance `LinearOrderedCommGroupWithZero`
128128
-- into two parts
129-
noncomputable instance : LinearOrder (ValueGroup A K) where
129+
noncomputable instance linearOrder : LinearOrder (ValueGroup A K) where
130130
le_refl := by rintro ⟨⟩; use 1; rw [one_smul]
131131
le_trans := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ ⟨e, rfl⟩ ⟨f, rfl⟩; use e * f; rw [mul_smul]
132132
le_antisymm := by
@@ -146,33 +146,34 @@ noncomputable instance : LinearOrder (ValueGroup A K) where
146146
decidableLE := by classical infer_instance
147147

148148
noncomputable instance linearOrderedCommGroupWithZero :
149-
LinearOrderedCommGroupWithZero (ValueGroup A K) where
150-
mul_assoc := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; apply Quotient.sound'; rw [mul_assoc]; apply Setoid.refl'
151-
one_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [one_mul]; apply Setoid.refl'
152-
mul_one := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_one]; apply Setoid.refl'
153-
mul_comm := by rintro ⟨a⟩ ⟨b⟩; apply Quotient.sound'; rw [mul_comm]; apply Setoid.refl'
154-
mul_le_mul_left := by
155-
rintro ⟨a⟩ ⟨b⟩ ⟨c, rfl⟩ ⟨d⟩
156-
use c; simp only [Algebra.smul_def]; ring
157-
zero_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [zero_mul]; apply Setoid.refl'
158-
mul_zero := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_zero]; apply Setoid.refl'
159-
zero_le_one := ⟨0, by rw [zero_smul]⟩
160-
exists_pair_ne := by
161-
use 0, 1
162-
intro c; obtain ⟨d, hd⟩ := Quotient.exact' c
163-
apply_fun fun t => d⁻¹ • t at hd
164-
simp only [inv_smul_smul, smul_zero, one_ne_zero] at hd
165-
inv_zero := by apply Quotient.sound'; rw [inv_zero]; apply Setoid.refl'
166-
mul_inv_cancel := by
167-
rintro ⟨a⟩ ha
168-
apply Quotient.sound'
169-
use 1
170-
simp only [one_smul, ne_eq]
171-
apply (mul_inv_cancel _).symm
172-
contrapose ha
173-
simp only [Classical.not_not] at ha ⊢
174-
rw [ha]
175-
rfl
149+
LinearOrderedCommGroupWithZero (ValueGroup A K) :=
150+
{ linearOrder .. with
151+
mul_assoc := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; apply Quotient.sound'; rw [mul_assoc]; apply Setoid.refl'
152+
one_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [one_mul]; apply Setoid.refl'
153+
mul_one := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_one]; apply Setoid.refl'
154+
mul_comm := by rintro ⟨a⟩ ⟨b⟩; apply Quotient.sound'; rw [mul_comm]; apply Setoid.refl'
155+
mul_le_mul_left := by
156+
rintro ⟨a⟩ ⟨b⟩ ⟨c, rfl⟩ ⟨d⟩
157+
use c; simp only [Algebra.smul_def]; ring
158+
zero_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [zero_mul]; apply Setoid.refl'
159+
mul_zero := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_zero]; apply Setoid.refl'
160+
zero_le_one := ⟨0, by rw [zero_smul]⟩
161+
exists_pair_ne := by
162+
use 0, 1
163+
intro c; obtain ⟨d, hd⟩ := Quotient.exact' c
164+
apply_fun fun t => d⁻¹ • t at hd
165+
simp only [inv_smul_smul, smul_zero, one_ne_zero] at hd
166+
inv_zero := by apply Quotient.sound'; rw [inv_zero]; apply Setoid.refl'
167+
mul_inv_cancel := by
168+
rintro ⟨a⟩ ha
169+
apply Quotient.sound'
170+
use 1
171+
simp only [one_smul, ne_eq]
172+
apply (mul_inv_cancel _).symm
173+
contrapose ha
174+
simp only [Classical.not_not] at ha ⊢
175+
rw [ha]
176+
rfl }
176177

177178
/-- Any valuation ring induces a valuation on its fraction field. -/
178179
def valuation : Valuation K (ValueGroup A K) where

0 commit comments

Comments
 (0)