|
| 1 | +/- |
| 2 | +Copyright (c) 2022 Yury Kudryashov. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Yury Kudryashov |
| 5 | +-/ |
| 6 | +import Mathlib.Algebra.Order.Ring.Defs |
| 7 | +import Mathlib.Algebra.Ring.InjSurj |
| 8 | + |
| 9 | +/-! |
| 10 | +# Algebraic structures on the set of positive numbers |
| 11 | +
|
| 12 | +In this file we define various instances (`AddSemigroup`, `OrderedCommMonoid` etc) on the |
| 13 | +type `{x : R // 0 < x}`. In each case we try to require the weakest possible typeclass |
| 14 | +assumptions on `R` but possibly, there is a room for improvements. |
| 15 | +-/ |
| 16 | + |
| 17 | + |
| 18 | +open Function |
| 19 | + |
| 20 | +namespace Positive |
| 21 | + |
| 22 | +variable {M R K : Type _} |
| 23 | + |
| 24 | +section AddBasic |
| 25 | + |
| 26 | +variable [AddMonoid M] [Preorder M] [CovariantClass M M (· + ·) (· < ·)] |
| 27 | + |
| 28 | +instance : Add { x : M // 0 < x } := |
| 29 | + ⟨fun x y => ⟨x + y, add_pos x.2 y.2⟩⟩ |
| 30 | + |
| 31 | +@[simp, norm_cast] |
| 32 | +theorem coe_add (x y : { x : M // 0 < x }) : ↑(x + y) = (x + y : M) := |
| 33 | + rfl |
| 34 | +#align positive.coe_add Positive.coe_add |
| 35 | + |
| 36 | +instance addSemigroup : AddSemigroup { x : M // 0 < x } := |
| 37 | + Subtype.coe_injective.addSemigroup _ coe_add |
| 38 | +#align subtype.add_semigroup Positive.addSemigroup |
| 39 | + |
| 40 | +instance addCommSemigroup {M : Type _} [AddCommMonoid M] [Preorder M] |
| 41 | + [CovariantClass M M (· + ·) (· < ·)] : AddCommSemigroup { x : M // 0 < x } := |
| 42 | + Subtype.coe_injective.addCommSemigroup _ coe_add |
| 43 | +#align subtype.add_comm_semigroup Positive.addCommSemigroup |
| 44 | + |
| 45 | +instance addLeftCancelSemigroup {M : Type _} [AddLeftCancelMonoid M] [Preorder M] |
| 46 | + [CovariantClass M M (· + ·) (· < ·)] : AddLeftCancelSemigroup { x : M // 0 < x } := |
| 47 | + Subtype.coe_injective.addLeftCancelSemigroup _ coe_add |
| 48 | +#align subtype.add_left_cancel_semigroup Positive.addLeftCancelSemigroup |
| 49 | + |
| 50 | +instance addRightCancelSemigroup {M : Type _} [AddRightCancelMonoid M] [Preorder M] |
| 51 | + [CovariantClass M M (· + ·) (· < ·)] : AddRightCancelSemigroup { x : M // 0 < x } := |
| 52 | + Subtype.coe_injective.addRightCancelSemigroup _ coe_add |
| 53 | +#align subtype.add_right_cancel_semigroup Positive.addRightCancelSemigroup |
| 54 | + |
| 55 | +instance covariantClass_add_lt : |
| 56 | + CovariantClass { x : M // 0 < x } { x : M // 0 < x } (· + ·) (· < ·) := |
| 57 | + ⟨fun _ y z hyz => Subtype.coe_lt_coe.1 <| add_lt_add_left (show (y : M) < z from hyz) _⟩ |
| 58 | +#align positive.covariant_class_add_lt Positive.covariantClass_add_lt |
| 59 | + |
| 60 | +instance covariantClass_swap_add_lt [CovariantClass M M (swap (· + ·)) (· < ·)] : |
| 61 | + CovariantClass { x : M // 0 < x } { x : M // 0 < x } (swap (· + ·)) (· < ·) := |
| 62 | + ⟨fun _ y z hyz => Subtype.coe_lt_coe.1 <| add_lt_add_right (show (y : M) < z from hyz) _⟩ |
| 63 | +#align positive.covariant_class_swap_add_lt Positive.covariantClass_swap_add_lt |
| 64 | + |
| 65 | +instance contravariantClass_add_lt [ContravariantClass M M (· + ·) (· < ·)] : |
| 66 | + ContravariantClass { x : M // 0 < x } { x : M // 0 < x } (· + ·) (· < ·) := |
| 67 | + ⟨fun _ _ _ h => Subtype.coe_lt_coe.1 <| lt_of_add_lt_add_left h⟩ |
| 68 | +#align positive.contravariant_class_add_lt Positive.contravariantClass_add_lt |
| 69 | + |
| 70 | +instance contravariantClass_swap_add_lt [ContravariantClass M M (swap (· + ·)) (· < ·)] : |
| 71 | + ContravariantClass { x : M // 0 < x } { x : M // 0 < x } (swap (· + ·)) (· < ·) := |
| 72 | + ⟨fun _ _ _ h => Subtype.coe_lt_coe.1 <| lt_of_add_lt_add_right h⟩ |
| 73 | +#align positive.contravariant_class_swap_add_lt Positive.contravariantClass_swap_add_lt |
| 74 | + |
| 75 | +instance contravariantClass_add_le [ContravariantClass M M (· + ·) (· ≤ ·)] : |
| 76 | + ContravariantClass { x : M // 0 < x } { x : M // 0 < x } (· + ·) (· ≤ ·) := |
| 77 | + ⟨fun _ _ _ h => Subtype.coe_le_coe.1 <| le_of_add_le_add_left h⟩ |
| 78 | +#align positive.contravariant_class_add_le Positive.contravariantClass_add_le |
| 79 | + |
| 80 | +instance contravariantClass_swap_add_le [ContravariantClass M M (swap (· + ·)) (· ≤ ·)] : |
| 81 | + ContravariantClass { x : M // 0 < x } { x : M // 0 < x } (swap (· + ·)) (· ≤ ·) := |
| 82 | + ⟨fun _ _ _ h => Subtype.coe_le_coe.1 <| le_of_add_le_add_right h⟩ |
| 83 | +#align positive.contravariant_class_swap_add_le Positive.contravariantClass_swap_add_le |
| 84 | + |
| 85 | +end AddBasic |
| 86 | + |
| 87 | +instance covariantClass_add_le [AddMonoid M] [PartialOrder M] |
| 88 | + [CovariantClass M M (· + ·) (· < ·)] : |
| 89 | + CovariantClass { x : M // 0 < x } { x : M // 0 < x } (· + ·) (· ≤ ·) := |
| 90 | + ⟨@fun _ _ _ h₁ => StrictMono.monotone (fun _ _ h => add_lt_add_left h _) h₁⟩ |
| 91 | +#align positive.covariant_class_add_le Positive.covariantClass_add_le |
| 92 | + |
| 93 | +section Mul |
| 94 | + |
| 95 | +variable [StrictOrderedSemiring R] |
| 96 | + |
| 97 | +instance : Mul { x : R // 0 < x } := |
| 98 | + ⟨fun x y => ⟨x * y, mul_pos x.2 y.2⟩⟩ |
| 99 | + |
| 100 | +@[simp] |
| 101 | +theorem val_mul (x y : { x : R // 0 < x }) : ↑(x * y) = (x * y : R) := |
| 102 | + rfl |
| 103 | +#align positive.coe_mul Positive.val_mul |
| 104 | + |
| 105 | +instance : Pow { x : R // 0 < x } ℕ := |
| 106 | + ⟨fun x n => ⟨(x : R) ^ n , pow_pos x.2 n⟩⟩ |
| 107 | + |
| 108 | +@[simp] |
| 109 | +theorem val_pow (x : { x : R // 0 < x }) (n : ℕ) : |
| 110 | + (x ^ n : R) = (x : R) ^ n := |
| 111 | + rfl |
| 112 | +#align positive.coe_pow Positive.val_pow |
| 113 | + |
| 114 | +instance : Semigroup { x : R // 0 < x } := |
| 115 | + Subtype.coe_injective.semigroup Subtype.val val_mul |
| 116 | + |
| 117 | +instance : Distrib { x : R // 0 < x } := |
| 118 | + Subtype.coe_injective.distrib _ coe_add val_mul |
| 119 | + |
| 120 | +instance [Nontrivial R] : One { x : R // 0 < x } := |
| 121 | + ⟨⟨1, one_pos⟩⟩ |
| 122 | + |
| 123 | +@[simp] |
| 124 | +theorem val_one [Nontrivial R] : ((1 : { x : R // 0 < x }) : R) = 1 := |
| 125 | + rfl |
| 126 | +#align positive.coe_one Positive.val_one |
| 127 | + |
| 128 | +instance [Nontrivial R] : Monoid { x : R // 0 < x } := |
| 129 | + Subtype.coe_injective.monoid _ val_one val_mul val_pow |
| 130 | + |
| 131 | +end Mul |
| 132 | + |
| 133 | +section mul_comm |
| 134 | + |
| 135 | +instance orderedCommMonoid [StrictOrderedCommSemiring R] [Nontrivial R] : |
| 136 | + OrderedCommMonoid { x : R // 0 < x } := |
| 137 | + { Subtype.instPartialOrderSubtype _, |
| 138 | + Subtype.coe_injective.commMonoid (Subtype.val) val_one val_mul val_pow with |
| 139 | + mul_le_mul_left := fun _ _ hxy c => |
| 140 | + Subtype.coe_le_coe.1 <| mul_le_mul_of_nonneg_left hxy c.2.le } |
| 141 | +#align subtype.ordered_comm_monoid Positive.orderedCommMonoid |
| 142 | + |
| 143 | +/-- If `R` is a nontrivial linear ordered commutative semiring, then `{x : R // 0 < x}` is a linear |
| 144 | +ordered cancellative commutative monoid. -/ |
| 145 | +instance linearOrderedCancelCommMonoid [LinearOrderedCommSemiring R] : |
| 146 | + LinearOrderedCancelCommMonoid { x : R // 0 < x } := |
| 147 | + { Subtype.instLinearOrderSubtype _, Positive.orderedCommMonoid with |
| 148 | + le_of_mul_le_mul_left := fun a _ _ h => Subtype.coe_le_coe.1 <| (mul_le_mul_left a.2).1 h } |
| 149 | +#align subtype.linear_ordered_cancel_comm_monoid Positive.linearOrderedCancelCommMonoid |
| 150 | + |
| 151 | +end mul_comm |
| 152 | + |
| 153 | +end Positive |
0 commit comments