Skip to content

Commit 9727486

Browse files
committed
refactor: turn posPart into a notation class again (#17426)
1 parent a003b0e commit 9727486

File tree

5 files changed

+79
-28
lines changed

5 files changed

+79
-28
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ import Mathlib.Algebra.MvPolynomial.Rename
543543
import Mathlib.Algebra.MvPolynomial.Supported
544544
import Mathlib.Algebra.MvPolynomial.Variables
545545
import Mathlib.Algebra.NeZero
546+
import Mathlib.Algebra.Notation
546547
import Mathlib.Algebra.Opposites
547548
import Mathlib.Algebra.Order.AbsoluteValue
548549
import Mathlib.Algebra.Order.AddGroupWithTop

Mathlib/Algebra/Notation.lean

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/-
2+
Copyright (c) 2024 Jireh Loreaux. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jireh Loreaux
5+
-/
6+
import Mathlib.Tactic.ToAdditive
7+
8+
/-!
9+
# Notations for operations involving order and algebraic structure
10+
11+
## Notations
12+
13+
* `a⁺ᵐ = a ⊔ 1`: *Positive component* of an element `a` of a multiplicative lattice ordered group
14+
* `a⁻ᵐ = a⁻¹ ⊔ 1`: *Negative component* of an element `a` of a multiplicative lattice ordered group
15+
* `a⁺ = a ⊔ 0`: *Positive component* of an element `a` of a lattice ordered group
16+
* `a⁻ = (-a) ⊔ 0`: *Negative component* of an element `a` of a lattice ordered group
17+
-/
18+
19+
/-- A notation class for the *positive part* function: `a⁺`. -/
20+
class PosPart (α : Type*) where
21+
/-- The *positive part* of an element `a`. -/
22+
posPart : α → α
23+
24+
/-- A notation class for the *positive part* function (multiplicative version): `a⁺ᵐ`. -/
25+
@[to_additive]
26+
class OneLePart (α : Type*) where
27+
/-- The *positive part* of an element `a`. -/
28+
oneLePart : α → α
29+
30+
/-- A notation class for the *negative part* function: `a⁻`. -/
31+
class NegPart (α : Type*) where
32+
/-- The *negative part* of an element `a`. -/
33+
negPart : α → α
34+
35+
/-- A notation class for the *negative part* function (multiplicative version): `a⁻ᵐ`. -/
36+
@[to_additive]
37+
class LeOnePart (α : Type*) where
38+
/-- The *negative part* of an element `a`. -/
39+
leOnePart : α → α
40+
41+
export OneLePart (oneLePart)
42+
export LeOnePart (leOnePart)
43+
export PosPart (posPart)
44+
export NegPart (negPart)
45+
46+
@[inherit_doc] postfix:max "⁺ᵐ " => OneLePart.oneLePart
47+
@[inherit_doc] postfix:max "⁻ᵐ" => LeOnePart.leOnePart
48+
@[inherit_doc] postfix:max "⁺" => PosPart.posPart
49+
@[inherit_doc] postfix:max "⁻" => NegPart.negPart

Mathlib/Algebra/Order/Group/PosPart.lean

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Christopher Hoskin, Yaël Dillies
55
-/
66
import Mathlib.Algebra.Order.Group.Unbundled.Abs
7+
import Mathlib.Algebra.Notation
78

89
/-!
910
# Positive & negative parts
@@ -12,22 +13,15 @@ Mathematical structures possessing an absolute value often also possess a unique
1213
elements into "positive" and "negative" parts which are in some sense "disjoint" (e.g. the Jordan
1314
decomposition of a measure).
1415
15-
This file defines `posPart` and `negPart`, the positive and negative parts of an element in a
16-
lattice ordered group.
16+
This file provides instances of `PosPart` and `NegPart`, the positive and negative parts of an
17+
element in a lattice ordered group.
1718
1819
## Main statements
1920
2021
* `posPart_sub_negPart`: Every element `a` can be decomposed into `a⁺ - a⁻`, the difference of its
2122
positive and negative parts.
2223
* `posPart_inf_negPart_eq_zero`: The positive and negative parts are coprime.
2324
24-
## Notations
25-
26-
* `a⁺ᵐ = a ⊔ 1`: *Positive component* of an element `a` of a multiplicative lattice ordered group
27-
* `a⁻ᵐ = a⁻¹ ⊔ 1`: *Negative component* of an element `a` of a multiplicative lattice ordered group
28-
* `a⁺ = a ⊔ 0`: *Positive component* of an element `a` of a lattice ordered group
29-
* `a⁻ = (-a) ⊔ 0`: *Negative component* of an element `a` of a lattice ordered group
30-
3125
## References
3226
3327
* [Birkhoff, Lattice-ordered Groups][birkhoff1942]
@@ -54,20 +48,21 @@ variable [Group α] {a b : α}
5448
/-- The *positive part* of an element `a` in a lattice ordered group is `a ⊔ 1`, denoted `a⁺ᵐ`. -/
5549
@[to_additive
5650
"The *positive part* of an element `a` in a lattice ordered group is `a ⊔ 0`, denoted `a⁺`."]
57-
def oneLePart (a : α) : α := a ⊔ 1
51+
instance instOneLePart : OneLePart α where
52+
oneLePart a := a ⊔ 1
5853

5954
/-- The *negative part* of an element `a` in a lattice ordered group is `a⁻¹ ⊔ 1`, denoted `a⁻ᵐ `.
6055
-/
6156
@[to_additive
6257
"The *negative part* of an element `a` in a lattice ordered group is `(-a) ⊔ 0`, denoted `a⁻`."]
63-
def leOnePart (a : α) : α := a⁻¹ ⊔ 1
58+
instance instLeOnePart : LeOnePart α where
59+
leOnePart a := a⁻¹ ⊔ 1
60+
61+
@[to_additive] lemma leOnePart_def (a : α) : a⁻ᵐ = a⁻¹ ⊔ 1 := rfl
6462

65-
@[inherit_doc] postfix:max "⁺ᵐ " => oneLePart
66-
@[inherit_doc] postfix:max "⁻ᵐ" => leOnePart
67-
@[inherit_doc] postfix:max "⁺" => posPart
68-
@[inherit_doc] postfix:max "⁻" => negPart
63+
@[to_additive] lemma oneLePart_def (a : α) : a⁺ᵐ = a ⊔ 1 := rfl
6964

70-
@[to_additive] lemma oneLePart_mono : Monotone (oneLePart : α → α) :=
65+
@[to_additive] lemma oneLePart_mono : Monotone (·⁺ᵐ : α → α) :=
7166
fun _a _b hab ↦ sup_le_sup_right hab _
7267

7368
@[to_additive (attr := simp)] lemma oneLePart_one : (1 : α)⁺ᵐ = 1 := sup_idem _
@@ -124,8 +119,8 @@ lemma leOnePart_eq_one : a⁻ᵐ = 1 ↔ 1 ≤ a := by simp [leOnePart_eq_one']
124119

125120
-- Bourbaki A.VI.12 Prop 9 a)
126121
@[to_additive (attr := simp)] lemma oneLePart_div_leOnePart (a : α) : a⁺ᵐ / a⁻ᵐ = a := by
127-
rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul, leOnePart, mul_sup, mul_one, mul_inv_cancel, sup_comm,
128-
oneLePart]
122+
rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul, leOnePart_def, mul_sup, mul_one, mul_inv_cancel,
123+
sup_comm, oneLePart_def]
129124

130125
@[to_additive (attr := simp)] lemma leOnePart_div_oneLePart (a : α) : a⁻ᵐ / a⁺ᵐ = a⁻¹ := by
131126
rw [← inv_div, oneLePart_div_leOnePart]
@@ -148,16 +143,16 @@ variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
148143

149144
@[to_additive]
150145
lemma leOnePart_eq_inv_inf_one (a : α) : a⁻ᵐ = (a ⊓ 1)⁻¹ := by
151-
rw [leOnePart, ← inv_inj, inv_sup, inv_inv, inv_inv, inv_one]
146+
rw [leOnePart_def, ← inv_inj, inv_sup, inv_inv, inv_inv, inv_one]
152147

153148
-- Bourbaki A.VI.12 Prop 9 d)
154149
@[to_additive] lemma oneLePart_mul_leOnePart (a : α) : a⁺ᵐ * a⁻ᵐ = |a|ₘ := by
155-
rw [oneLePart, sup_mul, one_mul, leOnePart, mul_sup, mul_one, mul_inv_cancel, sup_assoc,
150+
rw [oneLePart_def, sup_mul, one_mul, leOnePart_def, mul_sup, mul_one, mul_inv_cancel, sup_assoc,
156151
← sup_assoc a, sup_eq_right.2 le_sup_right]
157152
exact sup_eq_left.2 <| one_le_mabs a
158153

159154
@[to_additive] lemma leOnePart_mul_oneLePart (a : α) : a⁻ᵐ * a⁺ᵐ = |a|ₘ := by
160-
rw [oneLePart, mul_sup, mul_one, leOnePart, sup_mul, one_mul, inv_mul_cancel, sup_assoc,
155+
rw [oneLePart_def, mul_sup, mul_one, leOnePart_def, sup_mul, one_mul, inv_mul_cancel, sup_assoc,
161156
← @sup_assoc _ _ a, sup_eq_right.2 le_sup_right]
162157
exact sup_eq_left.2 <| one_le_mabs a
163158

@@ -213,22 +208,22 @@ section LinearOrder
213208
variable [LinearOrder α] [Group α] {a b : α}
214209

215210
@[to_additive] lemma oneLePart_eq_ite : a⁺ᵐ = if 1 ≤ a then a else 1 := by
216-
rw [oneLePart, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
211+
rw [oneLePart_def, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
217212

218213
@[to_additive (attr := simp) posPart_pos_iff] lemma one_lt_oneLePart_iff : 1 < a⁺ᵐ ↔ 1 < a :=
219214
lt_iff_lt_of_le_iff_le <| (one_le_oneLePart _).le_iff_eq.trans oneLePart_eq_one
220215

221216
@[to_additive posPart_eq_of_posPart_pos]
222217
lemma oneLePart_of_one_lt_oneLePart (ha : 1 < a⁺ᵐ) : a⁺ᵐ = a := by
223-
rw [oneLePart, right_lt_sup, not_le] at ha; exact oneLePart_eq_self.2 ha.le
218+
rw [oneLePart_def, right_lt_sup, not_le] at ha; exact oneLePart_eq_self.2 ha.le
224219

225220
@[to_additive (attr := simp)] lemma oneLePart_lt : a⁺ᵐ < b ↔ a < b ∧ 1 < b := sup_lt_iff
226221

227222
section covariantmul
228223
variable [CovariantClass α α (· * ·) (· ≤ ·)]
229224

230225
@[to_additive] lemma leOnePart_eq_ite : a⁻ᵐ = if a ≤ 1 then a⁻¹ else 1 := by
231-
simp_rw [← one_le_inv']; rw [leOnePart, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
226+
simp_rw [← one_le_inv']; rw [leOnePart_def, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
232227

233228
@[to_additive (attr := simp) negPart_pos_iff] lemma one_lt_ltOnePart_iff : 1 < a⁻ᵐ ↔ a < 1 :=
234229
lt_iff_lt_of_le_iff_le <| (one_le_leOnePart _).le_iff_eq.trans leOnePart_eq_one

Mathlib/Tactic/Positivity/Basic.lean

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,11 @@ def evalRatDen : PositivityExt where eval {u α} _ _ e := do
500500

501501
/-- Extension for `posPart`. `a⁺` is always nonegative, and positive if `a` is. -/
502502
@[positivity _⁺]
503-
def evalPosPart : PositivityExt where eval zα pα e := do
503+
def evalPosPart : PositivityExt where eval {u α} zα pα e := do
504504
match e with
505-
| ~q(@posPart _ $instαlat $instαgrp $a) =>
505+
| ~q(@posPart _ $instαpospart $a) =>
506+
let _instαlat ← synthInstanceQ q(Lattice $α)
507+
let _instαgrp ← synthInstanceQ q(AddGroup $α)
506508
assertInstancesCommute
507509
-- FIXME: There seems to be a bug in `Positivity.core` that makes it fail (instead of returning
508510
-- `.none`) here sometimes. See eg the first test for `posPart`. This is why we need `catchNone`
@@ -513,9 +515,11 @@ def evalPosPart : PositivityExt where eval zα pα e := do
513515

514516
/-- Extension for `negPart`. `a⁻` is always nonegative. -/
515517
@[positivity _⁻]
516-
def evalNegPart : PositivityExt where eval _ _ e := do
518+
def evalNegPart : PositivityExt where eval {u α} _ _ e := do
517519
match e with
518-
| ~q(@negPart _ $instαlat $instαgrp $a) =>
520+
| ~q(@negPart _ $instαnegpart $a) =>
521+
let _instαlat ← synthInstanceQ q(Lattice $α)
522+
let _instαgrp ← synthInstanceQ q(AddGroup $α)
519523
assertInstancesCommute
520524
return .nonnegative q(negPart_nonneg $a)
521525
| _ => throwError "not `negPart`"

Mathlib/Tactic/ToAdditive/Frontend.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,8 @@ def fixAbbreviation : List String → List String
10481048
=> "function" :: "_" :: "semiconj" :: fixAbbreviation s
10491049
| "function" :: "_" :: "add" :: "Commute" :: s
10501050
=> "function" :: "_" :: "commute" :: fixAbbreviation s
1051+
| "Zero" :: "Le" :: "Part" :: s => "PosPart" :: fixAbbreviation s
1052+
| "Le" :: "Zero" :: "Part" :: s => "NegPart" :: fixAbbreviation s
10511053
| "zero" :: "Le" :: "Part" :: s => "posPart" :: fixAbbreviation s
10521054
| "le" :: "Zero" :: "Part" :: s => "negPart" :: fixAbbreviation s
10531055
| "Division" :: "Add" :: "Monoid" :: s => "SubtractionMonoid" :: fixAbbreviation s

0 commit comments

Comments
 (0)