module Data.Int.Order where
Ordering integersπ
The usual partial order on the integers relies on the observation that the number line looks like two copies of the natural numbers, smashed end-to-end at the number zero. This is precisely the definition of the order we use:
data _β€_ : Int β Int β Type where negβ€neg : β {x y} β y Nat.β€ x β negsuc x β€ negsuc y posβ€pos : β {x y} β x Nat.β€ y β pos x β€ pos y negβ€pos : β {x y} β negsuc x β€ pos y
instance β€-neg-neg : β {x y} β¦ p : y Nat.β€ x β¦ β negsuc x β€ negsuc y β€-neg-neg β¦ p β¦ = negβ€neg p β€-pos-pos : β {x y} β¦ p : x Nat.β€ y β¦ β pos x β€ pos y β€-pos-pos β¦ p β¦ = posβ€pos p β€-neg-pos : β {x y} β negsuc x β€ pos y β€-neg-pos = negβ€pos
Note the key properties: the ordering between negative numbers is reversed, and every negative number is smaller than every positive number. This means that decomposes, as an order, into an ordinal sum
Basic propertiesπ
Proving that this is actually a partial order is a straightforward combination of case-bashing and appealing to the analogous properties for the ordering on natural numbers.
Β¬posβ€neg : β {x y} β pos x β€ negsuc y β β₯ Β¬posβ€neg () β€-is-prop : β {x y} β is-prop (x β€ y) β€-is-prop (negβ€neg p) (negβ€neg q) = ap negβ€neg (Nat.β€-is-prop p q) β€-is-prop (posβ€pos p) (posβ€pos q) = ap posβ€pos (Nat.β€-is-prop p q) β€-is-prop negβ€pos negβ€pos = refl β€-refl : β {x} β x β€ x β€-refl {x = pos x} = posβ€pos Nat.β€-refl β€-refl {x = negsuc x} = negβ€neg Nat.β€-refl β€-refl' : β {x y} β x β‘ y β x β€ y β€-refl' {pos x} {pos y} p = posβ€pos (Nat.β€-refl' (pos-injective p)) β€-refl' {pos x} {negsuc y} p = absurd (posβ negsuc p) β€-refl' {negsuc x} {pos y} p = absurd (negsucβ pos p) β€-refl' {negsuc x} {negsuc y} p = negβ€neg (Nat.β€-refl' (negsuc-injective (sym p))) β€-trans : β {x y z} β x β€ y β y β€ z β x β€ z β€-trans (negβ€neg p) (negβ€neg q) = negβ€neg (Nat.β€-trans q p) β€-trans (negβ€neg p) negβ€pos = negβ€pos β€-trans (posβ€pos p) (posβ€pos q) = posβ€pos (Nat.β€-trans p q) β€-trans negβ€pos (posβ€pos x) = negβ€pos β€-antisym : β {x y} β x β€ y β y β€ x β x β‘ y β€-antisym (negβ€neg p) (negβ€neg q) = ap negsuc (Nat.β€-antisym q p) β€-antisym (posβ€pos p) (posβ€pos q) = ap pos (Nat.β€-antisym p q) unposβ€pos : β {x y} β pos x β€ pos y β x Nat.β€ y unposβ€pos (posβ€pos p) = p unnegβ€neg : β {x y} β negsuc x β€ negsuc y β y Nat.β€ x unnegβ€neg (negβ€neg p) = p aposβ€apos : β {x y} β x Nat.β€ y β assign pos x β€ assign pos y aposβ€apos {x} {y} p = β€-trans (β€-refl' (assign-pos x)) (β€-trans (posβ€pos p) (β€-refl' (sym (assign-pos y)))) unaposβ€apos : β {x y} β assign pos x β€ assign pos y β x Nat.β€ y unaposβ€apos {x} {y} p = unposβ€pos (β€-trans (β€-refl' (sym (assign-pos x))) (β€-trans p (β€-refl' (assign-pos y))))
Totalityπ
The ordering on the integers is decidable, and moreover it is a total order. We show weak totality: if then
β€-is-weakly-total : β x y β Β¬ (x β€ y) β y β€ x β€-is-weakly-total (pos x) (pos y) p = posβ€pos $ Nat.β€-is-weakly-total x y (p β posβ€pos) β€-is-weakly-total (pos x) (negsuc y) p = negβ€pos β€-is-weakly-total (negsuc x) (pos y) p = absurd (p negβ€pos) β€-is-weakly-total (negsuc x) (negsuc y) p = negβ€neg $ Nat.β€-is-weakly-total y x (p β negβ€neg) instance Dec-β€ : β {x y} β Dec (x β€ y) Dec-β€ {pos x} {pos y} with holds? (x Nat.β€ y) ... | yes p = yes (posβ€pos p) ... | no Β¬p = no Ξ» { (posβ€pos p) β Β¬p p } Dec-β€ {negsuc x} {negsuc y} with holds? (y Nat.β€ x) ... | yes p = yes (negβ€neg p) ... | no Β¬p = no Ξ» { (negβ€neg p) β Β¬p p } Dec-β€ {pos x} {negsuc y} = no Β¬posβ€neg Dec-β€ {negsuc x} {pos y} = yes negβ€pos
Universal properties of maximum and minimumπ
This case bash shows that maxβ€
and minβ€
satisfy their universal properties.
maxβ€-β€l : (x y : Int) β x β€ maxβ€ x y maxβ€-β€l (pos x) (pos y) = posβ€pos (Nat.max-β€l x y) maxβ€-β€l (pos _) (negsuc _) = β€-refl maxβ€-β€l (negsuc _) (pos _) = negβ€pos maxβ€-β€l (negsuc x) (negsuc y) = negβ€neg (Nat.min-β€l x y) maxβ€-β€r : (x y : Int) β y β€ maxβ€ x y maxβ€-β€r (pos x) (pos y) = posβ€pos (Nat.max-β€r x y) maxβ€-β€r (pos _) (negsuc _) = negβ€pos maxβ€-β€r (negsuc _) (pos _) = β€-refl maxβ€-β€r (negsuc x) (negsuc y) = negβ€neg (Nat.min-β€r x y) maxβ€-univ : (x y z : Int) β x β€ z β y β€ z β maxβ€ x y β€ z maxβ€-univ _ _ _ (posβ€pos xβ€z) (posβ€pos yβ€z) = posβ€pos (Nat.max-univ _ _ _ xβ€z yβ€z) maxβ€-univ _ _ _ (posβ€pos xβ€z) negβ€pos = posβ€pos xβ€z maxβ€-univ _ _ _ negβ€pos (posβ€pos yβ€z) = posβ€pos yβ€z maxβ€-univ _ _ _ negβ€pos negβ€pos = negβ€pos maxβ€-univ _ _ _ (negβ€neg xβ₯z) (negβ€neg yβ₯z) = negβ€neg (Nat.min-univ _ _ _ xβ₯z yβ₯z) minβ€-β€l : (x y : Int) β minβ€ x y β€ x minβ€-β€l (pos x) (pos y) = posβ€pos (Nat.min-β€l x y) minβ€-β€l (pos _) (negsuc _) = negβ€pos minβ€-β€l (negsuc _) (pos _) = β€-refl minβ€-β€l (negsuc x) (negsuc y) = negβ€neg (Nat.max-β€l x y) minβ€-β€r : (x y : Int) β minβ€ x y β€ y minβ€-β€r (pos x) (pos y) = posβ€pos (Nat.min-β€r x y) minβ€-β€r (pos _) (negsuc _) = β€-refl minβ€-β€r (negsuc _) (pos _) = negβ€pos minβ€-β€r (negsuc x) (negsuc y) = negβ€neg (Nat.max-β€r x y) minβ€-univ : (x y z : Int) β z β€ x β z β€ y β z β€ minβ€ x y minβ€-univ _ _ _ (posβ€pos xβ₯z) (posβ€pos yβ₯z) = posβ€pos (Nat.min-univ _ _ _ xβ₯z yβ₯z) minβ€-univ _ _ _ negβ€pos negβ€pos = negβ€pos minβ€-univ _ _ _ negβ€pos (negβ€neg yβ€z) = negβ€neg yβ€z minβ€-univ _ _ _ (negβ€neg xβ€z) negβ€pos = negβ€neg xβ€z minβ€-univ _ _ _ (negβ€neg xβ€z) (negβ€neg yβ€z) = negβ€neg (Nat.max-univ _ _ _ xβ€z yβ€z)
Compatibility with the structureπ
The last case bash in this module will establish that the ordering on integers is compatible with the successor, predecessor, and negation. Since addition is equivalent to iterated application of the successor and predecessor, we get as a corollary that addition also respects the order.
suc-β€ : β x y β x β€ y β sucβ€ x β€ sucβ€ y suc-β€ (pos x) (pos y) (posβ€pos p) = posβ€pos (Nat.sβ€s p) suc-β€ (negsuc zero) (pos y) p = posβ€pos Nat.0β€x suc-β€ (negsuc zero) (negsuc zero) p = β€-refl suc-β€ (negsuc zero) (negsuc (suc y)) (negβ€neg ()) suc-β€ (negsuc (suc x)) (pos y) p = negβ€pos suc-β€ (negsuc (suc x)) (negsuc zero) p = negβ€pos suc-β€ (negsuc (suc x)) (negsuc (suc y)) (negβ€neg (Nat.sβ€s p)) = negβ€neg p pred-β€ : β x y β x β€ y β predβ€ x β€ predβ€ y pred-β€ posz posz p = β€-refl pred-β€ posz (possuc y) p = negβ€pos pred-β€ (possuc x) posz (posβ€pos ()) pred-β€ (possuc x) (possuc y) (posβ€pos (Nat.sβ€s p)) = posβ€pos p pred-β€ (negsuc x) posz p = negβ€neg Nat.0β€x pred-β€ (negsuc x) (possuc y) p = negβ€pos pred-β€ (negsuc x) (negsuc y) (negβ€neg p) = negβ€neg (Nat.sβ€s p) rotβ€β€l : β k x y β x β€ y β rotβ€ k x β€ rotβ€ k y rotβ€β€l posz x y p = p rotβ€β€l (possuc k) x y p = suc-β€ _ _ (rotβ€β€l (pos k) x y p) rotβ€β€l (negsuc zero) x y p = pred-β€ _ _ p rotβ€β€l (negsuc (suc k)) x y p = pred-β€ _ _ (rotβ€β€l (negsuc k) x y p) abstract +β€-preserves-β€l : β k x y β x β€ y β (k +β€ x) β€ (k +β€ y) +β€-preserves-β€l k x y p = transport (sym (apβ _β€_ (rot-is-add k x) (rot-is-add k y))) (rotβ€β€l k x y p) +β€-preserves-β€r : β k x y β x β€ y β (x +β€ k) β€ (y +β€ k) +β€-preserves-β€r k x y p = transport (apβ _β€_ (+β€-commutative k x) (+β€-commutative k y)) (+β€-preserves-β€l k x y p) negβ€-anti : β x y β x β€ y β negβ€ y β€ negβ€ x negβ€-anti posz posz xβ€y = xβ€y negβ€-anti posz (possuc y) _ = negβ€pos negβ€-anti (possuc x) (possuc y) (posβ€pos (Nat.sβ€s xβ€y)) = negβ€neg xβ€y negβ€-anti (negsuc _) posz _ = posβ€pos Nat.0β€x negβ€-anti (negsuc _) (possuc y) _ = negβ€pos negβ€-anti (negsuc x) (negsuc y) (negβ€neg xβ€y) = posβ€pos (Nat.sβ€s xβ€y) negβ€-anti-full : β x y β negβ€ y β€ negβ€ x β x β€ y negβ€-anti-full posz (pos y) _ = posβ€pos Nat.0β€x negβ€-anti-full posz (negsuc y) (posβ€pos ()) negβ€-anti-full (possuc x) (possuc y) (negβ€neg xβ€y) = posβ€pos (Nat.sβ€s xβ€y) negβ€-anti-full (negsuc x) (pos y) _ = negβ€pos negβ€-anti-full (negsuc x) (negsuc y) (posβ€pos (Nat.sβ€s yβ€x)) = negβ€neg yβ€x *β€-cancel-β€r : β {x y z} β¦ _ : Positive x β¦ β (y *β€ x) β€ (z *β€ x) β y β€ z *β€-cancel-β€r {possuc x} {y = pos y} {pos z} β¦ pos _ β¦ p = posβ€pos (Nat.*-cancel-β€r (suc x) (unaposβ€apos p)) *β€-cancel-β€r {possuc x} {y = pos y} {negsuc z} β¦ pos _ β¦ p = absurd (Β¬posβ€neg (β€-trans (β€-refl' (sym (assign-pos (y * suc x)))) p)) *β€-cancel-β€r {possuc x} {y = negsuc y} {pos z} β¦ pos _ β¦ p = negβ€pos *β€-cancel-β€r {possuc x} {y = negsuc y} {negsuc z} β¦ pos _ β¦ p = negβ€neg (Nat.*-cancel-β€r (suc x) (Nat.+-reflects-β€l (z * suc x) (y * suc x) x (unnegβ€neg p))) *β€-preserves-β€r : β {x y} z β¦ _ : Positive z β¦ β x β€ y β (x *β€ z) β€ (y *β€ z) *β€-preserves-β€r {pos x} {pos y} (possuc z) β¦ pos z β¦ p = aposβ€apos {x * suc z} {y * suc z} (Nat.*-preserves-β€r x y (suc z) (unposβ€pos p)) *β€-preserves-β€r {negsuc x} {pos y} (possuc z) β¦ pos z β¦ p = β€-trans negβ€pos (β€-refl' (sym (assign-pos (y * suc z)))) *β€-preserves-β€r {negsuc x} {negsuc y} (possuc z) β¦ pos z β¦ p = negβ€neg (Nat.+-preserves-β€l (y * suc z) (x * suc z) z (Nat.*-preserves-β€r y x (suc z) (unnegβ€neg p))) *β€-nonnegative : β {x y} β 0 β€ x β 0 β€ y β 0 β€ (x *β€ y) *β€-nonnegative {pos x} {pos y} (posβ€pos p) (posβ€pos q) = β€-trans (posβ€pos Nat.0β€x) (β€-refl' (sym (assign-pos (x * y)))) positiveβnonnegative : β {x} β Positive x β 0 β€ x positiveβnonnegative (pos x) = posβ€pos Nat.0β€x -β-nonnegative : β {x y} β y Nat.β€ x β 0 β€ (x β- y) -β-nonnegative {x} {y} Nat.0β€x = posβ€pos Nat.0β€x -β-nonnegative {suc x} {suc y} (Nat.sβ€s p) = -β-nonnegative p -β€-nonnegative : β {x y} β 0Β β€ x β 0 β€ y β y β€ x β 0 β€ (x -β€ y) -β€-nonnegative {posz} {posz} (posβ€pos p) (posβ€pos q) (posβ€pos r) = posβ€pos Nat.0β€x -β€-nonnegative {possuc x} {posz} (posβ€pos p) (posβ€pos q) (posβ€pos r) = posβ€pos Nat.0β€x -β€-nonnegative {possuc x} {possuc y} (posβ€pos p) (posβ€pos q) (posβ€pos r) = -β-nonnegative (Nat.β€-peel r)
The strict orderπ
data _<_ : Int β Int β Type where pos<pos : β {x y} β x Nat.< y β pos x < pos y neg<pos : β {x y} β negsuc x < pos y neg<neg : β {x y} β y Nat.< x β negsuc x < negsuc y instance H-Level-< : β {x y n} β H-Level (x < y) (suc n) H-Level-< = prop-instance Ξ» where (pos<pos x) (pos<pos y) β ap pos<pos (Nat.β€-is-prop x y) neg<pos neg<pos β refl (neg<neg x) (neg<neg y) β ap neg<neg (Nat.β€-is-prop x y) <-not-equal : β {x y} β x < y β x β y <-not-equal (pos<pos p) q = Nat.<-not-equal p (pos-injective q) <-not-equal neg<pos q = negsucβ pos q <-not-equal (neg<neg p) q = Nat.<-not-equal p (negsuc-injective (sym q)) <-irrefl : β {x y} β x β‘ y β Β¬ (x < y) <-irrefl p q = <-not-equal q p <-weaken : β {x y} β x < y β x β€ y <-weaken (pos<pos x) = posβ€pos (Nat.<-weaken x) <-weaken neg<pos = negβ€pos <-weaken (neg<neg x) = negβ€neg (Nat.<-weaken x) <-asym : β {x y} β x < y β Β¬ (y < x) <-asym (pos<pos x) (pos<pos y) = Nat.<-asym x y <-asym (neg<neg x) (neg<neg y) = Nat.<-asym x y β€-strengthen : β {x y} β x β€ y β (x β‘ y) β (x < y) β€-strengthen (negβ€neg x) with Nat.β€-strengthen x ... | inl x=y = inl (ap negsuc (sym x=y)) ... | inr x<y = inr (neg<neg x<y) β€-strengthen (posβ€pos x) with Nat.β€-strengthen x ... | inl x=y = inl (ap pos x=y) ... | inr x<y = inr (pos<pos x<y) β€-strengthen negβ€pos = inr neg<pos <-from-β€ : β {x y} β x β€ y β x β y β x < y <-from-β€ xβ€y xβ y with β€-strengthen xβ€y ... | inl x=y = absurd (xβ y x=y) ... | inr p = p <-dec : β x y β Dec (x < y) <-dec (pos x) (pos y) with Nat.β€-dec (suc x) y ... | yes x<y = yes (pos<pos x<y) ... | no Β¬x<y = no Ξ» { (pos<pos x<y) β Β¬x<y x<y } <-dec (pos x) (negsuc y) = no Ξ» () <-dec (negsuc x) (pos y) = yes neg<pos <-dec (negsuc x) (negsuc y) with Nat.β€-dec (suc y) x ... | yes y<x = yes (neg<neg y<x) ... | no Β¬y<x = no Ξ» { (neg<neg y<x) β Β¬y<x y<x } instance Dec-< : β {x y} β Dec (x < y) Dec-< {x} {y} = <-dec x y β€-from-not-< : β {x y} β Β¬ x < y β y β€ x β€-from-not-< {pos x} {pos y} Β¬x<y = posβ€pos (Nat.β€-from-not-< x y (Ξ» x<y β Β¬x<y (pos<pos x<y))) β€-from-not-< {pos x} {negsuc y} Β¬x<y = negβ€pos β€-from-not-< {negsuc x} {pos y} Β¬x<y = absurd (Β¬x<y neg<pos) β€-from-not-< {negsuc x} {negsuc y} Β¬x<y = negβ€neg (Nat.β€-from-not-< y x (Ξ» y<x β Β¬x<y (neg<neg y<x))) <-linear : β {x y} β Β¬ x < y β Β¬ y < x β x β‘ y <-linear {x} {y} Β¬x<y Β¬y<x = β€-antisym (β€-from-not-< Β¬y<x) (β€-from-not-< Β¬x<y) <-split : β x y β (x < y) β (x β‘ y) β (y < x) <-split x y with <-dec x y ... | yes x<y = inl x<y ... | no Β¬x<y with <-dec y x ... | yes y<x = inr (inr y<x) ... | no Β¬y<x = inr (inl (<-linear Β¬x<y Β¬y<x)) <-trans : β {x y z} β x < y β y < z β x < z <-trans (pos<pos p) (pos<pos q) = pos<pos (Nat.<-trans _ _ _ p q) <-trans neg<pos (pos<pos q) = neg<pos <-trans (neg<neg p) neg<pos = neg<pos <-trans (neg<neg p) (neg<neg q) = neg<neg (Nat.<-trans _ _ _ q p) <-β€-trans : β {x y z} β x < y β y β€ z β x < z <-β€-trans p q with β€-strengthen q ... | inl y=z = substβ _<_ refl y=z p ... | inr y<z = <-trans p y<z β€-<-trans : β {x y z} β x β€ y β y < z β x < z β€-<-trans p q with β€-strengthen p ... | inl x=y = substβ _<_ (sym x=y) refl q ... | inr x<y = <-trans x<y q abstract nat-diff-<-possuc : β k x β (k β- x) < possuc k nat-diff-<-possuc zero zero = pos<pos (Nat.sβ€s Nat.0β€x) nat-diff-<-possuc zero (suc x) = neg<pos nat-diff-<-possuc (suc k) zero = pos<pos Nat.β€-refl nat-diff-<-possuc (suc k) (suc x) = <-trans (nat-diff-<-possuc k x) (pos<pos Nat.β€-refl) nat-diff-<-pos : β k x β (k β- suc x) < pos k nat-diff-<-pos zero zero = neg<pos nat-diff-<-pos zero (suc x) = neg<pos nat-diff-<-pos (suc k) zero = pos<pos auto nat-diff-<-pos (suc k) (suc x) = nat-diff-<-possuc k (suc x) negsuc-<-nat-diff : β k x β negsuc k < (x β- k) negsuc-<-nat-diff zero zero = neg<pos negsuc-<-nat-diff zero (suc x) = neg<pos negsuc-<-nat-diff (suc k) zero = neg<neg auto negsuc-<-nat-diff (suc k) (suc x) = <-trans (neg<neg auto) (negsuc-<-nat-diff k x) negsuc-β€-nat-diff : β k x β negsuc k β€ (x β- suc k) negsuc-β€-nat-diff zero zero = negβ€neg Nat.0β€x negsuc-β€-nat-diff zero (suc x) = negβ€pos negsuc-β€-nat-diff (suc k) zero = negβ€neg auto negsuc-β€-nat-diff (suc k) (suc x) = β€-trans (negβ€neg Nat.β€-ascend) (negsuc-β€-nat-diff k x) nat-diff-preserves-<r : β k {x y} β y Nat.< x β (k β- x) < (k β- y) nat-diff-preserves-<r zero {suc zero} {zero} (Nat.sβ€s Nat.0β€x) = neg<pos nat-diff-preserves-<r zero {suc (suc x)} {zero} (Nat.sβ€s p) = neg<pos nat-diff-preserves-<r zero {suc (suc x)} {suc y} (Nat.sβ€s p) = neg<neg p nat-diff-preserves-<r (suc k) {suc x} {zero} (Nat.sβ€s p) = nat-diff-<-possuc k x nat-diff-preserves-<r (suc k) {suc x} {suc y} (Nat.sβ€s p) = nat-diff-preserves-<r k {x} {y} p nat-diff-preserves-<l : β k {x y} β x Nat.< y β (x β- k) < (y β- k) nat-diff-preserves-<l zero {zero} {suc y} (Nat.sβ€s p) = pos<pos (Nat.sβ€s Nat.0β€x) nat-diff-preserves-<l zero {suc x} {suc y} (Nat.sβ€s p) = pos<pos (Nat.sβ€s p) nat-diff-preserves-<l (suc k) {zero} {suc y} (Nat.sβ€s Nat.0β€x) = negsuc-<-nat-diff k y nat-diff-preserves-<l (suc k) {suc x} {suc y} (Nat.sβ€s p) = nat-diff-preserves-<l k {x} {y} p +β€-preserves-<r : β x y z β x < y β (x +β€ z) < (y +β€ z) +β€-preserves-<r x y (pos z) (pos<pos p) = pos<pos (Nat.+-preserves-<r _ _ z p) +β€-preserves-<r (negsuc x) (pos y) (pos z) neg<pos = let remβ : z Nat.β€ y + z remβ = Nat.β€-trans (Nat.+-β€l z y) (Nat.β€-refl' (Nat.+-commutative z y)) in <-β€-trans (nat-diff-<-pos z x) (posβ€pos remβ) +β€-preserves-<r x y (pos z) (neg<neg p) = nat-diff-preserves-<r z (Nat.sβ€s p) +β€-preserves-<r x y (negsuc z) (pos<pos p) = nat-diff-preserves-<l (suc z) p +β€-preserves-<r (negsuc x) (pos y) (negsuc z) neg<pos = let remβ : suc z Nat.β€ suc (x + z) remβ = Nat.β€-trans (Nat.+-β€l (suc z) x) (Nat.β€-refl' (ap suc (Nat.+-commutative z x))) in <-β€-trans (neg<neg remβ) (negsuc-β€-nat-diff z y) +β€-preserves-<r x y (negsuc z) (neg<neg p) = neg<neg (Nat.sβ€s (Nat.+-preserves-<r _ _ z p)) +β€-preserves-<l : β x y z β x < y β (z +β€ x) < (z +β€ y) +β€-preserves-<l x y z p = substβ _<_ (+β€-commutative x z) (+β€-commutative y z) (+β€-preserves-<r x y z p) +β€-preserves-< : β x y x' y' β x < y β x' < y' β (x +β€ x') < (y +β€ y') +β€-preserves-< x y x' y' p q = <-trans (+β€-preserves-<r x y x' p) (+β€-preserves-<l x' y' y q) *β€-cancel-<r : β {x y z} β¦ _ : Positive x β¦ β (y *β€ x) < (z *β€ x) β y < z *β€-cancel-<r {x} {y} {z} yx<zx = <-from-β€ (*β€-cancel-β€r {x} {y} {z} (<-weaken yx<zx)) Ξ» y=z β <-irrefl (ap (_*β€ x) y=z) yx<zx *β€-cancel-<l : β {x y z} β¦ _ : Positive x β¦ β (x *β€ y) < (x *β€ z) β y < z *β€-cancel-<l {x} {y} {z} xy<xz = *β€-cancel-<r {x} {y} {z} (substβ _<_ (*β€-commutative x y) (*β€-commutative x z) xy<xz) *β€-preserves-<r : β {x y} z β¦ _ : Positive z β¦ β x < y β (x *β€ z) < (y *β€ z) *β€-preserves-<r {x} {y} z x<y = <-from-β€ (*β€-preserves-β€r {x} {y} z (<-weaken x<y)) Ξ» xz=yz β <-irrefl (*β€-injectiver z x y (positiveβnonzero auto) xz=yz) x<y negβ€-anti-< : β {x y} β x < y β negβ€ y < negβ€ x negβ€-anti-< {posz} {pos y} (pos<pos (Nat.sβ€s p)) = neg<pos negβ€-anti-< {possuc x} {pos y} (pos<pos (Nat.sβ€s p)) = neg<neg p negβ€-anti-< {negsuc x} {posz} neg<pos = pos<pos (Nat.sβ€s Nat.0β€x) negβ€-anti-< {negsuc x} {possuc y} neg<pos = neg<pos negβ€-anti-< {negsuc x} {negsuc y} (neg<neg p) = pos<pos (Nat.sβ€s p) negβ€-anti-full-< : β {x y} β negβ€ x < negβ€ y β y < x negβ€-anti-full-< {x} {y} p = substβ _<_ (negβ€-negβ€ y) (negβ€-negβ€ x) (negβ€-anti-< p)