From 2167866c53aa7f9cbb52e776bfb64f53acf3fa2c Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sat, 2 Apr 2022 11:41:51 +0100 Subject: Add more properties for ordered structures. --- src/Helium/Algebra/Morphism/Structures.agda | 42 -- .../Algebra/Ordered/StrictTotal/Bundles.agda | 46 +- .../Algebra/Ordered/StrictTotal/Consequences.agda | 137 +++++ .../Ordered/StrictTotal/Morphism/Structures.agda | 98 ++++ .../StrictTotal/Properties/AbelianGroup.agda | 60 ++- .../StrictTotal/Properties/CommutativeRing.agda | 81 ++- .../Ordered/StrictTotal/Properties/Group.agda | 211 +++++++- .../Ordered/StrictTotal/Properties/Magma.agda | 89 ++++ .../Ordered/StrictTotal/Properties/Monoid.agda | 329 ++++++++++++ .../Ordered/StrictTotal/Properties/Ring.agda | 584 +++++++++++++++++++-- .../Ordered/StrictTotal/Properties/Semigroup.agda | 31 ++ src/Helium/Data/Pseudocode/Algebra.agda | 28 +- src/Helium/Data/Pseudocode/Algebra/Properties.agda | 281 +++++++++- .../Binary/Properties/StrictTotalOrder.agda | 122 +++++ src/Helium/Semantics/Axiomatic.agda | 11 +- src/Helium/Semantics/Axiomatic/Term.agda | 4 +- src/Helium/Semantics/Denotational/Core.agda | 6 +- 17 files changed, 1942 insertions(+), 218 deletions(-) delete mode 100644 src/Helium/Algebra/Morphism/Structures.agda create mode 100644 src/Helium/Algebra/Ordered/StrictTotal/Consequences.agda create mode 100644 src/Helium/Algebra/Ordered/StrictTotal/Morphism/Structures.agda create mode 100644 src/Helium/Algebra/Ordered/StrictTotal/Properties/Magma.agda create mode 100644 src/Helium/Algebra/Ordered/StrictTotal/Properties/Monoid.agda create mode 100644 src/Helium/Algebra/Ordered/StrictTotal/Properties/Semigroup.agda create mode 100644 src/Helium/Relation/Binary/Properties/StrictTotalOrder.agda (limited to 'src') diff --git a/src/Helium/Algebra/Morphism/Structures.agda b/src/Helium/Algebra/Morphism/Structures.agda deleted file mode 100644 index bf219ef..0000000 --- a/src/Helium/Algebra/Morphism/Structures.agda +++ /dev/null @@ -1,42 +0,0 @@ ------------------------------------------------------------------------- --- Agda Helium --- --- Redefine Ring monomorphisms to resolve problems with overloading. ------------------------------------------------------------------------- - -{-# OPTIONS --safe --without-K #-} - -module Helium.Algebra.Morphism.Structures where - -open import Algebra.Bundles using (RawRing) -open import Algebra.Morphism.Structures - hiding (IsRingHomomorphism; module RingMorphisms) -open import Level using (Level; _⊔_) - -private - variable - a b ℓ₁ ℓ₂ : Level - -module RingMorphisms (R₁ : RawRing a ℓ₁) (R₂ : RawRing b ℓ₂) where - module R₁ = RawRing R₁ renaming (Carrier to A) - module R₂ = RawRing R₂ renaming (Carrier to B) - open R₁ using (A) - open R₂ using (B) - - private - module +′ = GroupMorphisms R₁.+-rawGroup R₂.+-rawGroup - module *′ = MonoidMorphisms R₁.*-rawMonoid R₂.*-rawMonoid - - record IsRingHomomorphism (⟦_⟧ : A → B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where - field - +-isGroupHomomorphism : +′.IsGroupHomomorphism ⟦_⟧ - *-isMonoidHomomorphism : *′.IsMonoidHomomorphism ⟦_⟧ - - open +′.IsGroupHomomorphism +-isGroupHomomorphism public - renaming (homo to +-homo; ε-homo to 0#-homo; ⁻¹-homo to -‿homo) - - open *′.IsMonoidHomomorphism *-isMonoidHomomorphism public - hiding (⟦⟧-cong) - renaming (homo to *-homo; ε-homo to 1#-homo) - -open RingMorphisms public diff --git a/src/Helium/Algebra/Ordered/StrictTotal/Bundles.agda b/src/Helium/Algebra/Ordered/StrictTotal/Bundles.agda index 831f591..0f8df22 100644 --- a/src/Helium/Algebra/Ordered/StrictTotal/Bundles.agda +++ b/src/Helium/Algebra/Ordered/StrictTotal/Bundles.agda @@ -30,19 +30,6 @@ record RawMagma c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where _<_ : Rel Carrier ℓ₂ _∙_ : Op₂ Carrier - infix 4 _≉_ _≤_ _>_ _≥_ - _≉_ : Rel Carrier _ - x ≉ y = N.¬ x ≈ y - - _≤_ : Rel Carrier _ - x ≤ y = x < y ⊎ x ≈ y - - _>_ : Rel Carrier _ - _>_ = flip _<_ - - _≥_ : Rel Carrier _ - _≥_ = flip _≤_ - module Unordered where rawMagma : NoOrder.RawMagma c ℓ₁ rawMagma = record { _≈_ = _≈_ ; _∙_ = _∙_ } @@ -63,9 +50,6 @@ record Magma c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where rawMagma : RawMagma _ _ _ rawMagma = record { _≈_ = _≈_; _<_ = _<_; _∙_ = _∙_ } - open RawMagma rawMagma public - using (_≉_; _≤_; _>_; _≥_) - module Unordered where magma : NoOrder.Magma c ℓ₁ magma = record { isMagma = IsMagma.Unordered.isMagma isMagma } @@ -92,7 +76,7 @@ record Semigroup c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where magma = record { isMagma = isMagma } open Magma magma public - using (_≉_; _≤_; _>_; _≥_; rawMagma) + using (rawMagma) module Unordered where semigroup : NoOrder.Semigroup c ℓ₁ @@ -117,9 +101,6 @@ record RawMonoid c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where rawMagma : RawMagma c ℓ₁ ℓ₂ rawMagma = record { _≈_ = _≈_; _<_ = _<_; _∙_ = _∙_ } - open RawMagma rawMagma public - using (_≉_; _≤_; _>_; _≥_) - module Unordered where rawMonoid : NoOrder.RawMonoid c ℓ₁ rawMonoid = record { _≈_ = _≈_; _∙_ = _∙_; ε = ε } @@ -145,7 +126,7 @@ record Monoid c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where semigroup = record { isSemigroup = isSemigroup } open Semigroup semigroup public - using (_≉_; _≤_; _>_; _≥_; rawMagma; magma) + using (rawMagma; magma) rawMonoid : RawMonoid _ _ _ rawMonoid = record { _≈_ = _≈_; _<_ = _<_; _∙_ = _∙_; ε = ε} @@ -175,7 +156,7 @@ record RawGroup c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where rawMonoid = record { _≈_ = _≈_; _<_ = _<_; _∙_ = _∙_; ε = ε } open RawMonoid rawMonoid public - using (_≉_; _≤_; _>_; _≥_; rawMagma) + using (rawMagma) module Unordered where rawGroup : NoOrder.RawGroup c ℓ₁ @@ -207,7 +188,7 @@ record Group c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where monoid = record { isMonoid = isMonoid } open Monoid monoid public - using (_≉_; _≤_; _>_; _≥_; rawMagma; magma; semigroup; rawMonoid) + using (rawMagma; magma; semigroup; rawMonoid) module Unordered where group : NoOrder.Group c ℓ₁ @@ -239,8 +220,7 @@ record AbelianGroup c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where open Group group public using - ( _≉_; _≤_; _>_; _≥_ - ; magma; semigroup; monoid + ( magma; semigroup; monoid ; rawMagma; rawMonoid; rawGroup ) @@ -273,7 +253,7 @@ record RawRing c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where +-rawGroup = record { _≈_ = _≈_; _<_ = _<_; _∙_ = _+_; ε = 0#; _⁻¹ = -_ } open RawGroup +-rawGroup public - using ( _≉_; _≤_; _>_; _≥_ ) + using () renaming ( rawMagma to +-rawMagma ; rawMonoid to +-rawMonoid @@ -328,7 +308,7 @@ record Ring c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where +-abelianGroup = record { isAbelianGroup = +-isAbelianGroup } open AbelianGroup +-abelianGroup public - using ( _≉_; _≤_; _>_; _≥_ ) + using () renaming ( rawMagma to +-rawMagma ; rawMonoid to +-rawMonoid @@ -388,8 +368,7 @@ record CommutativeRing c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) whe open Ring ring public using - ( _≉_; _≤_; _>_; _≥_ - ; rawRing + ( rawRing ; +-rawMagma; +-rawMonoid; +-rawGroup ; +-magma; +-semigroup; +-monoid; +-group; +-abelianGroup ; *-rawMagma; *-rawMonoid @@ -447,8 +426,7 @@ record RawField c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where open RawRing rawRing public using - ( _≉_; _≤_; _>_; _≥_ - ; +-rawMagma; +-rawMonoid; +-rawGroup + ( +-rawMagma; +-rawMonoid; +-rawGroup ; *-rawMagma; *-rawMonoid ) @@ -514,8 +492,7 @@ record DivisionRing c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where open Ring ring public using - ( _≉_; _≤_; _>_; _≥_ - ; rawRing + ( rawRing ; +-rawMagma; +-rawMonoid; +-rawGroup ; +-magma; +-semigroup; +-monoid; +-group; +-abelianGroup ; *-rawMagma; *-rawMonoid @@ -570,8 +547,7 @@ record Field c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where open DivisionRing divisionRing public using - ( _≉_; _≤_; _>_; _≥_ - ; rawRing; rawField; ring + ( rawRing; rawField; ring ; +-rawMagma; +-rawMonoid; +-rawGroup ; +-magma; +-semigroup; +-monoid; +-group; +-abelianGroup ; *-rawMagma; *-rawMonoid; *-rawAlmostGroup diff --git a/src/Helium/Algebra/Ordered/StrictTotal/Consequences.agda b/src/Helium/Algebra/Ordered/StrictTotal/Consequences.agda new file mode 100644 index 0000000..7696f98 --- /dev/null +++ b/src/Helium/Algebra/Ordered/StrictTotal/Consequences.agda @@ -0,0 +1,137 @@ +------------------------------------------------------------------------ +-- Agda Helium +-- +-- Relations between algebraic properties of ordered structures +------------------------------------------------------------------------ + +{-# OPTIONS --safe --without-K #-} + +open import Relation.Binary + +module Helium.Algebra.Ordered.StrictTotal.Consequences + {a ℓ₁ ℓ₂} + (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂) + where + +open StrictTotalOrder strictTotalOrder + renaming + ( Carrier to A + ; trans to <-trans + ; irrefl to <-irrefl + ; asym to <-asym + ) + +open import Helium.Relation.Binary.Properties.StrictTotalOrder strictTotalOrder +open import Relation.Binary.Reasoning.StrictPartialOrder strictPartialOrder + +open import Algebra.Core +open import Algebra.Definitions +open import Data.Product using (_,_) +open import Data.Sum using (inj₁; inj₂) +open import Function using (_∘_) +open import Function.Definitions +open import Helium.Algebra.Ordered.Definitions +open import Relation.Nullary using (¬_) + +---- +-- Consequences for a single unary operation +module _ {f : Op₁ A} where + cong₁+mono₁-<⇒mono₁-≤ : Congruent₁ _≈_ f → Congruent₁ _<_ f → Congruent₁ _≤_ f + cong₁+mono₁-<⇒mono₁-≤ cong mono (inj₁ x_ → f Preserves _≤_ ⟶ _≥_ + cong₁+anti-mono₁-<⇒anti-mono₁-≤ cong anti-mono (inj₁ x (<⇒≱ fx (<⇒≱ x_ → Injective _≤_ _≥_ f + anti-mono₁-<⇒anti-cancel₁-≤ anti-mono fx≥fy = ≮⇒≥ (≤⇒≯ fx≥fy ∘ anti-mono) + + anti-mono₁-≤⇒anti-cancel₁-< : f Preserves _≤_ ⟶ _≥_ → Injective _<_ _>_ f + anti-mono₁-≤⇒anti-cancel₁-< anti-mono fx>fy = ≰⇒> (<⇒≱ fx>fy ∘ anti-mono) + + mono₁-<⇒cancel₁ : Congruent₁ _<_ f → Injective _≈_ _≈_ f + mono₁-<⇒cancel₁ mono fx≈fy = ≮∧≯⇒≈ (<-irrefl fx≈fy ∘ mono) (<-irrefl (Eq.sym fx≈fy) ∘ mono) + + anti-mono₁-<⇒cancel₁ : f Preserves _<_ ⟶ _>_ → Injective _≈_ _≈_ f + anti-mono₁-<⇒cancel₁ anti-mono fx≈fy = ≮∧≯⇒≈ + (<-irrefl (Eq.sym fx≈fy) ∘ anti-mono) + (<-irrefl fx≈fy ∘ anti-mono) + +---- +-- Consequences for a single binary operation +module _ {_∙_ : Op₂ A} where + invariant⇒mono-< : Invariant _<_ _∙_ → Congruent₂ _<_ _∙_ + invariant⇒mono-< (invˡ , invʳ) {x} {y} {u} {v} x⇒≉; ≈⇒≯; <⇒≉; ≈⇒≮; ≤∧≉⇒<; ≥∧≉⇒>; x_ -⁻¹-anti-mono {x} {y} xε⇒x∙y>ε; x>ε∧y≥ε⇒x∙y>ε + ; x≤ε∧y<ε⇒x∙y<ε; x<ε∧y≤ε⇒x∙y<ε + ; x≥ε∧y≥ε⇒x∙y≥ε; x≤ε∧y≤ε⇒x∙y≤ε + -- _∙_ resp signs + ; x≤ε∧x∙y>ε⇒y>ε; x≤ε∧y∙x>ε⇒y>ε + ; x<ε∧x∙y≥ε⇒y>ε; x<ε∧y∙x≥ε⇒y>ε + ; x≥ε∧x∙y<ε⇒y<ε; x≥ε∧y∙x<ε⇒y<ε + ; x>ε∧x∙y≤ε⇒y<ε; x>ε∧y∙x≤ε⇒y<ε + ; x≤ε∧x∙y≥ε⇒y≥ε; x≤ε∧y∙x≥ε⇒y≥ε + ; x≥ε∧x∙y≤ε⇒y≤ε; x≥ε∧y∙x≤ε⇒y≤ε + + ; ×-zeroˡ; ×-zeroʳ + ; ×-identityˡ + + ; n≢0⇒×-monoˡ-<; x>ε⇒×-monoʳ-<; x<ε⇒×-anti-monoʳ-< + ; ×-monoˡ-≤; x≥ε⇒×-monoʳ-≤; x≤ε⇒×-anti-monoʳ-≤ + + ; ×-cancelˡ-<; x≥ε⇒×-cancelʳ-<; x≤ε⇒×-anti-cancelʳ-< + ; n≢0⇒×-cancelˡ-≤; x>ε⇒×-cancelʳ-≤; x<ε⇒×-anti-cancelʳ-≤ + -- _×_ pres signs + ; n≢0∧x>ε⇒n×x>ε; n≢0∧x<ε⇒n×x<ε + ; x≥ε⇒n×x≥ε; x≤ε⇒n×x≤ε + -- _×_ resp signs + ; n×x>ε⇒x>ε; n×x<ε⇒x<ε + ; n≢0∧n×x≥ε⇒x≥ε; n≢0∧n×x≤ε⇒x≤ε + + ; ⁻¹-anti-mono-<; ⁻¹-anti-mono-≤ + + ; ⁻¹-cancel; ⁻¹-anti-cancel-<; ⁻¹-anti-cancel-≤ + + ; x<ε⇒x⁻¹>ε; x>ε⇒x⁻¹<ε + ; x≤ε⇒x⁻¹≥ε; x≥ε⇒x⁻¹≤ε + + ; x⁻¹<ε⇒x>ε; x⁻¹>ε⇒x<ε + ; x⁻¹≤ε⇒x≥ε; x⁻¹≥ε⇒x≤ε + + ; x0∧y>0⇒x*y>0 + ) open import Algebra.Properties.Ring Unordered.ring public renaming (-0#≈0# to -0≈0) open import Algebra.Properties.Semiring.Mult.TCOptimised Unordered.semiring public open import Algebra.Properties.CommutativeSemiring.Exp.TCOptimised Unordered.commutativeSemiring public +open import Helium.Relation.Binary.Properties.StrictTotalOrder strictTotalOrder public open import Helium.Algebra.Ordered.StrictTotal.Properties.Ring ring public using - ( <⇒≱; ≤⇒≯; >⇒≉; ≈⇒≯; <⇒≉; ≈⇒≮; ≤∧≉⇒<; ≥∧≉⇒> - ; x0⇒x+y>0 ; x>0∧y≥0⇒x+y>0 + ; x≤0∧y<0⇒x+y<0 ; x<0∧y≤0⇒x+y<0 + ; x≥0∧y≥0⇒x+y≥0 ; x≤0∧y≤0⇒x+y≤0 + + ; x≤0∧x+y>0⇒y>0 ; x≤0∧y+x>0⇒y>0 ; x<0∧x+y≥0⇒y>0 ; x<0∧y+x≥0⇒y>0 + ; x≥0∧x+y<0⇒y<0 ; x≥0∧y+x<0⇒y<0 ; x>0∧x+y≤0⇒y<0 ; x>0∧y+x≤0⇒y<0 + ; x≤0∧x+y≥0⇒y≥0 ; x≤0∧y+x≥0⇒y≥0 + ; x≥0∧x+y≤0⇒y≤0 ; x≥0∧y+x≤0⇒y≤0 + + ; ×-zeroˡ; ×-zeroʳ + ; ×-identityˡ + + ; n≢0⇒×-monoˡ-< ; x>0⇒×-monoʳ-< ; x<0⇒×-anti-monoʳ-< + ; ×-monoˡ-≤; x≥0⇒×-monoʳ-≤; x≤0⇒×-anti-monoʳ-≤ + + ; ×-cancelˡ-<; x≥0⇒×-cancelʳ-<; x≤0⇒×-anti-cancelʳ-< + ; n≢0⇒×-cancelˡ-≤ ; x>0⇒×-cancelʳ-≤ ; x<0⇒×-anti-cancelʳ-≤ + + ; n≢0∧x>0⇒n×x>0; n≢0∧x<0⇒n×x<0 + ; x≥0⇒n×x≥0; x≤0⇒n×x≤0 + + ; n×x>0⇒x>0; n×x<0⇒x<0 + ; n≢0∧n×x≥0⇒x≥0; n≢0∧n×x≤0⇒x≤0 + + ; -‿anti-mono-<; -‿anti-mono-≤ + ; -‿cancel; -‿anti-cancel-<; -‿anti-cancel-≤ + + ; x<0⇒-x>0; x>0⇒-x<0; x≤0⇒-x≥0; x≥0⇒-x≤0 + ; -x<0⇒x>0; -x>0⇒x<0; -x≤0⇒x≥0; -x≥0⇒x≤0 + + ; x0⇒*-monoˡ-<; x>0⇒*-monoʳ-<; x<0⇒*-anti-monoˡ-<; x<0⇒*-anti-monoʳ-< + ; x≥0⇒*-monoˡ-≤; x≥0⇒*-monoʳ-≤; x≤0⇒*-anti-monoˡ-≤; x≤0⇒*-anti-monoʳ-≤ + + ; x≥0⇒*-cancelˡ-<; x≥0⇒*-cancelʳ-<; x≤0⇒*-anti-cancelˡ-<; x≤0⇒*-anti-cancelʳ-< + ; x>0⇒*-cancelˡ-≤; x>0⇒*-cancelʳ-≤; x<0⇒*-anti-cancelˡ-≤; x<0⇒*-anti-cancelʳ-≤ + + ; x≈0⇒x*y≈0; x≈0⇒y*x≈0 + + ; -x*-y≈x*y + ; x>0∧y<0⇒x*y<0; x<0∧y>0⇒x*y<0; x<0∧y<0⇒x*y>0 + ; x≥0∧y≥0⇒x*y≥0; x≥0∧y≤0⇒x*y≤0; x≤0∧y≥0⇒x*y≤0; x≤0∧y≤0⇒x*y≥0 + + ; x>1∧y≥1⇒x*y>1; x≥1∧y>1⇒x*y>1; 0≤x<1∧y≤1⇒x*y<1; x≤1∧0≤y<1⇒x*y<1 + ; x≥1∧y≥1⇒x*y≥1; 0≤x≤1∧y≤1⇒x*y≤1; x≤1∧0≤y≤1⇒x*y≤1 + + ; x*x≥0 + + ; ^-zeroˡ; ^-zeroʳ + ; ^-identityʳ + + ; n≢0⇒0^n≈0 + ; x>1⇒^-monoˡ-<; 00⇒x^n>0 + ; x≥0⇒x^n≥0 + + ; x>1∧n≢0⇒x^n>1; 0≤x<1∧n≢0⇒x^n<1 + ; x≥1⇒x^n≥1; 0≤x≤1⇒x^n≤1 + ) diff --git a/src/Helium/Algebra/Ordered/StrictTotal/Properties/Group.agda b/src/Helium/Algebra/Ordered/StrictTotal/Properties/Group.agda index c0723b3..d72ae10 100644 --- a/src/Helium/Algebra/Ordered/StrictTotal/Properties/Group.agda +++ b/src/Helium/Algebra/Ordered/StrictTotal/Properties/Group.agda @@ -14,46 +14,205 @@ module Helium.Algebra.Ordered.StrictTotal.Properties.Group where open Group group + renaming + ( trans to <-trans + ; irrefl to <-irrefl + ; asym to <-asym + ) -open import Data.Sum using (inj₂; [_,_]′; fromInj₁) -open import Function using (_∘_; flip) -open import Relation.Binary using (tri<; tri≈; tri>) +open import Algebra.Definitions +open import Function using (_∘_; flip; Injective) +open import Relation.Binary.Core open import Relation.Binary.Reasoning.StrictPartialOrder strictPartialOrder -open import Relation.Nullary using (¬_) -open import Relation.Nullary.Negation using (contradiction) open import Algebra.Properties.Group Unordered.group public open import Algebra.Properties.Monoid.Mult.TCOptimised Unordered.monoid public +open import Helium.Algebra.Ordered.StrictTotal.Properties.Monoid monoid public + using + ( ∙-mono-<; ∙-monoˡ-<; ∙-monoʳ-< + ; ∙-mono-≤; ∙-monoˡ-≤; ∙-monoʳ-≤ -<⇒≱ : ∀ {x y} → x < y → ¬ x ≥ y -<⇒≱ {x} {y} x x≮y _ _ = x≮y xε⇒x∙y>ε; x>ε∧y≥ε⇒x∙y>ε + ; x≤ε∧y<ε⇒x∙y<ε; x<ε∧y≤ε⇒x∙y<ε + ; x≥ε∧y≥ε⇒x∙y≥ε; x≤ε∧y≤ε⇒x∙y≤ε + -- _∙_ resp signs + ; x≤ε∧x∙y>ε⇒y>ε; x≤ε∧y∙x>ε⇒y>ε + ; x<ε∧x∙y≥ε⇒y>ε; x<ε∧y∙x≥ε⇒y>ε + ; x≥ε∧x∙y<ε⇒y<ε; x≥ε∧y∙x<ε⇒y<ε + ; x>ε∧x∙y≤ε⇒y<ε; x>ε∧y∙x≤ε⇒y<ε + ; x≤ε∧x∙y≥ε⇒y≥ε; x≤ε∧y∙x≥ε⇒y≥ε + ; x≥ε∧x∙y≤ε⇒y≤ε; x≥ε∧y∙x≤ε⇒y≤ε -≤⇒≯ : ∀ {x y} → x ≤ y → ¬ x > y -≤⇒≯ = flip <⇒≱ + ; ×-zeroˡ; ×-zeroʳ + ; ×-identityˡ ->⇒≉ : ∀ {x y} → x > y → x ≉ y ->⇒≉ x>y = <⇒≱ x>y ∘ inj₂ + ; n≢0⇒×-monoˡ-<; x>ε⇒×-monoʳ-<; x<ε⇒×-anti-monoʳ-< + ; ×-monoˡ-≤; x≥ε⇒×-monoʳ-≤; x≤ε⇒×-anti-monoʳ-≤ -≈⇒≯ : ∀ {x y} → x ≈ y → ¬ x > y -≈⇒≯ = flip >⇒≉ + ; ×-cancelˡ-<; x≥ε⇒×-cancelʳ-<; x≤ε⇒×-anti-cancelʳ-< + ; n≢0⇒×-cancelˡ-≤; x>ε⇒×-cancelʳ-≤; x<ε⇒×-anti-cancelʳ-≤ + -- _×_ pres signs + ; n≢0∧x>ε⇒n×x>ε; n≢0∧x<ε⇒n×x<ε + ; x≥ε⇒n×x≥ε; x≤ε⇒n×x≤ε + -- _×_ resp signs + ; n×x>ε⇒x>ε; n×x<ε⇒x<ε + ; n≢0∧n×x≥ε⇒x≥ε; n≢0∧n×x≤ε⇒x≤ε + ) +open import Helium.Relation.Binary.Properties.StrictTotalOrder strictTotalOrder public -<⇒≉ : ∀ {x y} → x < y → x ≉ y -<⇒≉ x⇒≉ x : ∀ {x y} → x ≥ y → x ≉ y → x > y -≥∧≉⇒> x≥y x≉y = ≤∧≉⇒< x≥y (x≉y ∘ Eq.sym) +⁻¹-anti-mono-< : _⁻¹ Preserves _<_ ⟶ _>_ +⁻¹-anti-mono-< {x} {y} x_ _⁻¹ +⁻¹-anti-cancel-< x⁻¹>y⁻¹ = ≰⇒> (<⇒≱ x⁻¹>y⁻¹ ∘ ⁻¹-anti-mono-≤) + +-- _≤_ + +⁻¹-anti-cancel-≤ : Injective _≤_ _≥_ _⁻¹ +⁻¹-anti-cancel-≤ x⁻¹≥y⁻¹ = ≮⇒≥ (≤⇒≯ x⁻¹≥y⁻¹ ∘ ⁻¹-anti-mono-<) + +---- Preserves signs + +-- _<_ + +x<ε⇒x⁻¹>ε : ∀ {x} → x < ε → x ⁻¹ > ε +x<ε⇒x⁻¹>ε {x} x<ε = begin-strict + ε ≈˘⟨ ε⁻¹≈ε ⟩ + ε ⁻¹ <⟨ ⁻¹-anti-mono-< x<ε ⟩ + x ⁻¹ ∎ + +x>ε⇒x⁻¹<ε : ∀ {x} → x > ε → x ⁻¹ < ε +x>ε⇒x⁻¹<ε {x} x>ε = begin-strict + x ⁻¹ <⟨ ⁻¹-anti-mono-< x>ε ⟩ + ε ⁻¹ ≈⟨ ε⁻¹≈ε ⟩ + ε ∎ + +-- _≤_ + +x≤ε⇒x⁻¹≥ε : ∀ {x} → x ≤ ε → x ⁻¹ ≥ ε +x≤ε⇒x⁻¹≥ε {x} x≤ε = begin + ε ≈˘⟨ ε⁻¹≈ε ⟩ + ε ⁻¹ ≤⟨ ⁻¹-anti-mono-≤ x≤ε ⟩ + x ⁻¹ ∎ + +x≥ε⇒x⁻¹≤ε : ∀ {x} → x ≥ ε → x ⁻¹ ≤ ε +x≥ε⇒x⁻¹≤ε {x} x≥ε = begin + x ⁻¹ ≤⟨ ⁻¹-anti-mono-≤ x≥ε ⟩ + ε ⁻¹ ≈⟨ ε⁻¹≈ε ⟩ + ε ∎ + +---- Respects signs + +-- _<_ + +x⁻¹<ε⇒x>ε : ∀ {x} → x ⁻¹ < ε → x > ε +x⁻¹<ε⇒x>ε {x} x⁻¹<ε = begin-strict + ε <⟨ x<ε⇒x⁻¹>ε x⁻¹<ε ⟩ + x ⁻¹ ⁻¹ ≈⟨ ⁻¹-involutive x ⟩ + x ∎ + +x⁻¹>ε⇒x<ε : ∀ {x} → x ⁻¹ > ε → x < ε +x⁻¹>ε⇒x<ε {x} x⁻¹>ε = begin-strict + x ≈˘⟨ ⁻¹-involutive x ⟩ + x ⁻¹ ⁻¹ <⟨ x>ε⇒x⁻¹<ε x⁻¹>ε ⟩ + ε ∎ + +-- _≤_ + +x⁻¹≤ε⇒x≥ε : ∀ {x} → x ⁻¹ ≤ ε → x ≥ ε +x⁻¹≤ε⇒x≥ε {x} x⁻¹≤ε = begin + ε ≤⟨ x≤ε⇒x⁻¹≥ε x⁻¹≤ε ⟩ + x ⁻¹ ⁻¹ ≈⟨ ⁻¹-involutive x ⟩ + x ∎ + +x⁻¹≥ε⇒x≤ε : ∀ {x} → x ⁻¹ ≥ ε → x ≤ ε +x⁻¹≥ε⇒x≤ε {x} x⁻¹≥ε = begin + x ≈˘⟨ ⁻¹-involutive x ⟩ + x ⁻¹ ⁻¹ ≤⟨ x≥ε⇒x⁻¹≤ε x⁻¹≥ε ⟩ + ε ∎ + +-- ---- Infer signs + +-- -- _≈_ + +-- x⁻¹≈x⇒x≈ε : ∀ {x} → x ⁻¹ ≈ x → x ≈ ε +-- x⁻¹≈x⇒x≈ε {x} x⁻¹≈x = ≮∧≯⇒≈ +-- (λ x<ε → <-asym x<ε (begin-strict +-- ε <⟨ x<ε⇒x⁻¹>ε x<ε ⟩ +-- x ⁻¹ ≈⟨ x⁻¹≈x ⟩ +-- x ∎)) +-- (λ x>ε → <-asym x>ε (begin-strict +-- x ≈˘⟨ x⁻¹≈x ⟩ +-- x ⁻¹ <⟨ x>ε⇒x⁻¹<ε x>ε ⟩ +-- ε ∎)) + +-- -- _<_ + +-- x⁻¹ε : ∀ {x} → x ⁻¹ < x → x > ε +-- x⁻¹ε x⁻¹ (<⇒≱ x⁻¹x⇒x<ε : ∀ {x} → x ⁻¹ > x → x < ε +-- x⁻¹>x⇒x<ε x⁻¹>x = ≰⇒> (<⇒≱ x⁻¹>x ∘ λ x≥ε → ≤-trans (x≥ε⇒x⁻¹≤ε x≥ε) x≥ε) + +-- -- _≤_ + +---- Miscellaneous + +xε⇒x∙y>ε : ∀ {x y} → x ≥ ε → y > ε → x ∙ y > ε +x≥ε∧y>ε⇒x∙y>ε {x} {y} x≥ε y>ε = begin-strict + ε ≈˘⟨ identity² ⟩ + ε ∙ ε <⟨ ∙-monoˡ-< y>ε ⟩ + ε ∙ y ≤⟨ ∙-monoʳ-≤ x≥ε ⟩ + x ∙ y ∎ + +x>ε∧y≥ε⇒x∙y>ε : ∀ {x y} → x > ε → y ≥ ε → x ∙ y > ε +x>ε∧y≥ε⇒x∙y>ε {x} {y} x>ε y≤ε = begin-strict + ε ≈˘⟨ identity² ⟩ + ε ∙ ε ≤⟨ ∙-monoˡ-≤ y≤ε ⟩ + ε ∙ y <⟨ ∙-monoʳ-< x>ε ⟩ + x ∙ y ∎ + +x≤ε∧y<ε⇒x∙y<ε : ∀ {x y} → x ≤ ε → y < ε → x ∙ y < ε +x≤ε∧y<ε⇒x∙y<ε {x} {y} x≤ε y<ε = begin-strict + x ∙ y ≤⟨ ∙-monoʳ-≤ x≤ε ⟩ + ε ∙ y <⟨ ∙-monoˡ-< y<ε ⟩ + ε ∙ ε ≈⟨ identity² ⟩ + ε ∎ + +x<ε∧y≤ε⇒x∙y<ε : ∀ {x y} → x < ε → y ≤ ε → x ∙ y < ε +x<ε∧y≤ε⇒x∙y<ε {x} {y} x<ε y≤ε = begin-strict + x ∙ y <⟨ ∙-monoʳ-< x<ε ⟩ + ε ∙ y ≤⟨ ∙-monoˡ-≤ y≤ε ⟩ + ε ∙ ε ≈⟨ identity² ⟩ + ε ∎ + +-- _≤_ + +x≥ε∧y≥ε⇒x∙y≥ε : ∀ {x y} → x ≥ ε → y ≥ ε → x ∙ y ≥ ε +x≥ε∧y≥ε⇒x∙y≥ε {x} {y} x≥ε y≥ε = begin + ε ≈˘⟨ identity² ⟩ + ε ∙ ε ≤⟨ ∙-mono-≤ x≥ε y≥ε ⟩ + x ∙ y ∎ + +x≤ε∧y≤ε⇒x∙y≤ε : ∀ {x y} → x ≤ ε → y ≤ ε → x ∙ y ≤ ε +x≤ε∧y≤ε⇒x∙y≤ε {x} {y} x≥ε y≥ε = begin + x ∙ y ≤⟨ ∙-mono-≤ x≥ε y≥ε ⟩ + ε ∙ ε ≈⟨ identity² ⟩ + ε ∎ + +---- Respects signs + +-- _<_ + +x≤ε∧x∙y>ε⇒y>ε : ∀ {x y} → x ≤ ε → x ∙ y > ε → y > ε +x≤ε∧x∙y>ε⇒y>ε x≤ε x∙y>ε = ≰⇒> (<⇒≱ x∙y>ε ∘ x≤ε∧y≤ε⇒x∙y≤ε x≤ε) + +x≤ε∧y∙x>ε⇒y>ε : ∀ {x y} → x ≤ ε → y ∙ x > ε → y > ε +x≤ε∧y∙x>ε⇒y>ε x≤ε y∙x>ε = ≰⇒> (<⇒≱ y∙x>ε ∘ flip x≤ε∧y≤ε⇒x∙y≤ε x≤ε) + +x<ε∧x∙y≥ε⇒y>ε : ∀ {x y} → x < ε → x ∙ y ≥ ε → y > ε +x<ε∧x∙y≥ε⇒y>ε x<ε x∙y≥ε = ≰⇒> (≤⇒≯ x∙y≥ε ∘ x<ε∧y≤ε⇒x∙y<ε x<ε) + +x<ε∧y∙x≥ε⇒y>ε : ∀ {x y} → x < ε → y ∙ x ≥ ε → y > ε +x<ε∧y∙x≥ε⇒y>ε x<ε y∙x≥ε = ≰⇒> (≤⇒≯ y∙x≥ε ∘ flip x≤ε∧y<ε⇒x∙y<ε x<ε) + +x≥ε∧x∙y<ε⇒y<ε : ∀ {x y} → x ≥ ε → x ∙ y < ε → y < ε +x≥ε∧x∙y<ε⇒y<ε x≥ε x∙y<ε = ≰⇒> (<⇒≱ x∙y<ε ∘ x≥ε∧y≥ε⇒x∙y≥ε x≥ε) + +x≥ε∧y∙x<ε⇒y<ε : ∀ {x y} → x ≥ ε → y ∙ x < ε → y < ε +x≥ε∧y∙x<ε⇒y<ε x≥ε y∙x<ε = ≰⇒> (<⇒≱ y∙x<ε ∘ flip x≥ε∧y≥ε⇒x∙y≥ε x≥ε) + +x>ε∧x∙y≤ε⇒y<ε : ∀ {x y} → x > ε → x ∙ y ≤ ε → y < ε +x>ε∧x∙y≤ε⇒y<ε x>ε x∙y≤ε = ≰⇒> (≤⇒≯ x∙y≤ε ∘ x>ε∧y≥ε⇒x∙y>ε x>ε) + +x>ε∧y∙x≤ε⇒y<ε : ∀ {x y} → x > ε → y ∙ x ≤ ε → y < ε +x>ε∧y∙x≤ε⇒y<ε x>ε y∙x≤ε = ≰⇒> (≤⇒≯ y∙x≤ε ∘ flip x≥ε∧y>ε⇒x∙y>ε x>ε) + +-- _≤_ + +x≤ε∧x∙y≥ε⇒y≥ε : ∀ {x y} → x ≤ ε → x ∙ y ≥ ε → y ≥ ε +x≤ε∧x∙y≥ε⇒y≥ε x≤ε x∙y≥ε = ≮⇒≥ (≤⇒≯ x∙y≥ε ∘ x≤ε∧y<ε⇒x∙y<ε x≤ε) + +x≤ε∧y∙x≥ε⇒y≥ε : ∀ {x y} → x ≤ ε → y ∙ x ≥ ε → y ≥ ε +x≤ε∧y∙x≥ε⇒y≥ε x≤ε y∙x≥ε = ≮⇒≥ (≤⇒≯ y∙x≥ε ∘ flip x<ε∧y≤ε⇒x∙y<ε x≤ε) + +x≥ε∧x∙y≤ε⇒y≤ε : ∀ {x y} → x ≥ ε → x ∙ y ≤ ε → y ≤ ε +x≥ε∧x∙y≤ε⇒y≤ε x≥ε x∙y≤ε = ≮⇒≥ (≤⇒≯ x∙y≤ε ∘ x≥ε∧y>ε⇒x∙y>ε x≥ε) + +x≥ε∧y∙x≤ε⇒y≤ε : ∀ {x y} → x ≥ ε → y ∙ x ≤ ε → y ≤ ε +x≥ε∧y∙x≤ε⇒y≤ε x≥ε y∙x≤ε = ≮⇒≥ (≤⇒≯ y∙x≤ε ∘ flip x>ε∧y≥ε⇒x∙y>ε x≥ε) + +-- ---- Infer signs + +-- -- _≈_ + +-- x∙y≈x⇒y≈ε : ∀ {x y} → x ∙ y ≈ x → y ≈ ε +-- x∙y≈x⇒y≈ε {x} {y} x∙y≈x = ∙-cancelˡ x (Eq.trans x∙y≈x (Eq.sym (identityʳ x))) + +-- x∙y≈y⇒x≈ε : ∀ {x y} → x ∙ y ≈ y → x ≈ ε +-- x∙y≈y⇒x≈ε {x} {y} x∙y≈y = ∙-cancelʳ x ε (Eq.trans x∙y≈y (Eq.sym (identityˡ y))) + +-- -- _<_ + +-- x∙yx⇒y>ε : ∀ {x y} → x ∙ y > x → y > ε +-- x∙y>x⇒y>ε {x} {y} x∙y>x = ∙-cancelˡ-< x (<-respˡ-≈ (Eq.sym (identityʳ x)) x∙y>x) + +-- x∙y>y⇒x>ε : ∀ {x y} → x ∙ y > y → x > ε +-- x∙y>y⇒x>ε {x} {y} x∙y>y = ∙-cancelʳ-< ε x (<-respˡ-≈ (Eq.sym (identityˡ y)) x∙y>y) + +-- -- _≤_ + +-- x∙y≤x⇒y≤ε : ∀ {x y} → x ∙ y ≤ x → y ≤ ε +-- x∙y≤x⇒y≤ε {x} {y} x∙y≤x = ∙-cancelˡ-≤ x (≤-respʳ-≈ (Eq.sym (identityʳ x)) x∙y≤x) + +-- x∙y≤y⇒x≤ε : ∀ {x y} → x ∙ y ≤ y → x ≤ ε +-- x∙y≤y⇒x≤ε {x} {y} x∙y≤y = ∙-cancelʳ-≤ x ε (≤-respʳ-≈ (Eq.sym (identityˡ y)) x∙y≤y) + +-- x∙y≥x⇒y≥ε : ∀ {x y} → x ∙ y ≥ x → y ≥ ε +-- x∙y≥x⇒y≥ε {x} {y} x∙y≥x = ∙-cancelˡ-≤ x (≤-respˡ-≈ (Eq.sym (identityʳ x)) x∙y≥x) + +-- x∙y≥y⇒x≥ε : ∀ {x y} → x ∙ y ≥ y → x ≥ ε +-- x∙y≥y⇒x≥ε {x} {y} x∙y≥y = ∙-cancelʳ-≤ ε x (≤-respˡ-≈ (Eq.sym (identityˡ y)) x∙y≥y) + +-- -------------------------------------------------------------------------------- +---- Properties of _×_ + +---- Zero + +×-zeroˡ : ∀ x → 0 × x ≈ ε +×-zeroˡ x = Eq.refl + +×-zeroʳ : ∀ n → n × ε ≈ ε +×-zeroʳ 0 = Eq.refl +×-zeroʳ (suc n) = begin-equality + suc n × ε ≈⟨ 1+× n ε ⟩ + ε ∙ n × ε ≈⟨ ∙-congˡ (×-zeroʳ n) ⟩ + ε ∙ ε ≈⟨ identity² ⟩ + ε ∎ + +---- Identity + +×-identityˡ : ∀ x → 1 × x ≈ x +×-identityˡ x = Eq.refl + +---- Preserves signs + +-- _≤_ + +x≥ε⇒n×x≥ε : ∀ n {x} → x ≥ ε → n × x ≥ ε +x≥ε⇒n×x≥ε 0 {x} x≥ε = ≤-refl +x≥ε⇒n×x≥ε (suc n) {x} x≥ε = begin + ε ≤⟨ x≥ε∧y≥ε⇒x∙y≥ε x≥ε (x≥ε⇒n×x≥ε n x≥ε) ⟩ + x ∙ n × x ≈˘⟨ 1+× n x ⟩ + suc n × x ∎ + +x≤ε⇒n×x≤ε : ∀ n {x} → x ≤ ε → n × x ≤ ε +x≤ε⇒n×x≤ε 0 {x} x≤ε = ≤-refl +x≤ε⇒n×x≤ε (suc n) {x} x≤ε = begin + suc n × x ≈⟨ 1+× n x ⟩ + x ∙ n × x ≤⟨ x≤ε∧y≤ε⇒x∙y≤ε x≤ε (x≤ε⇒n×x≤ε n x≤ε) ⟩ + ε ∎ + +-- _<_ + +n≢0∧x>ε⇒n×x>ε : ∀ n {x} → ⦃ NonZero n ⦄ → x > ε → n × x > ε +n≢0∧x>ε⇒n×x>ε (suc n) {x} x>ε = begin-strict + ε <⟨ x>ε∧y≥ε⇒x∙y>ε x>ε (x≥ε⇒n×x≥ε n (<⇒≤ x>ε)) ⟩ + x ∙ n × x ≈˘⟨ 1+× n x ⟩ + suc n × x ∎ + +n≢0∧x<ε⇒n×x<ε : ∀ n {x} → ⦃ NonZero n ⦄ → x < ε → n × x < ε +n≢0∧x<ε⇒n×x<ε (suc n) {x} x<ε = begin-strict + suc n × x ≈⟨ 1+× n x ⟩ + x ∙ n × x <⟨ x<ε∧y≤ε⇒x∙y<ε x<ε (x≤ε⇒n×x≤ε n (<⇒≤ x<ε)) ⟩ + ε ∎ + +---- Congruences + +-- _≤_ + +×-monoˡ-≤ : ∀ n → Congruent₁ _≤_ (n ×_) +×-monoˡ-≤ 0 x≤y = ≤-refl +×-monoˡ-≤ (suc n) {x} {y} x≤y = begin + suc n × x ≈⟨ 1+× n x ⟩ + x ∙ n × x ≤⟨ ∙-mono-≤ x≤y (×-monoˡ-≤ n x≤y) ⟩ + y ∙ n × y ≈˘⟨ 1+× n y ⟩ + suc n × y ∎ + +x≥ε⇒×-monoʳ-≤ : ∀ {x} → x ≥ ε → (_× x) Preserves ℕ._≤_ ⟶ _≤_ +x≥ε⇒×-monoʳ-≤ {x} x≥ε {.0} {n} ℕ.z≤n = x≥ε⇒n×x≥ε n x≥ε +x≥ε⇒×-monoʳ-≤ {x} x≥ε {.suc m} {.suc n} (ℕ.s≤s m≤n) = begin + suc m × x ≈⟨ 1+× m x ⟩ + x ∙ m × x ≤⟨ ∙-monoˡ-≤ (x≥ε⇒×-monoʳ-≤ x≥ε m≤n) ⟩ + x ∙ n × x ≈˘⟨ 1+× n x ⟩ + suc n × x ∎ + +x≤ε⇒×-anti-monoʳ-≤ : ∀ {x} → x ≤ ε → (_× x) Preserves ℕ._≤_ ⟶ _≥_ +x≤ε⇒×-anti-monoʳ-≤ {x} x≤ε {.0} {n} ℕ.z≤n = x≤ε⇒n×x≤ε n x≤ε +x≤ε⇒×-anti-monoʳ-≤ {x} x≤ε {.suc m} {.suc n} (ℕ.s≤s m≤n) = begin + suc n × x ≈⟨ 1+× n x ⟩ + x ∙ n × x ≤⟨ ∙-monoˡ-≤ (x≤ε⇒×-anti-monoʳ-≤ x≤ε m≤n) ⟩ + x ∙ m × x ≈˘⟨ 1+× m x ⟩ + suc m × x ∎ + +-- _<_ + +n≢0⇒×-monoˡ-< : ∀ n → ⦃ NonZero n ⦄ → Congruent₁ _<_ (n ×_) +n≢0⇒×-monoˡ-< (suc n) {x} {y} xε⇒×-monoʳ-< : ∀ {x} → x > ε → (_× x) Preserves ℕ._<_ ⟶ _<_ +x>ε⇒×-monoʳ-< {x} x>ε {m} {.suc n} (ℕ.s≤s m≤n) = begin-strict + m × x ≈˘⟨ identityˡ (m × x) ⟩ + ε ∙ m × x ≤⟨ ∙-monoˡ-≤ (x≥ε⇒×-monoʳ-≤ (<⇒≤ x>ε) m≤n) ⟩ + ε ∙ n × x <⟨ ∙-monoʳ-< x>ε ⟩ + x ∙ n × x ≈˘⟨ 1+× n x ⟩ + suc n × x ∎ + +x<ε⇒×-anti-monoʳ-< : ∀ {x} → x < ε → (_× x) Preserves ℕ._<_ ⟶ _>_ +x<ε⇒×-anti-monoʳ-< {x} x<ε {m} {.suc n} (ℕ.s≤s m≤n) = begin-strict + suc n × x ≈⟨ 1+× n x ⟩ + x ∙ n × x <⟨ ∙-monoʳ-< x<ε ⟩ + ε ∙ n × x ≤⟨ ∙-monoˡ-≤ (x≤ε⇒×-anti-monoʳ-≤ (<⇒≤ x<ε) m≤n) ⟩ + ε ∙ m × x ≈⟨ identityˡ (m × x) ⟩ + m × x ∎ + +---- Cancellative + +-- _<_ + +×-cancelˡ-< : ∀ n → Injective _<_ _<_ (n ×_) +×-cancelˡ-< n = mono₁-≤⇒cancel₁-< (×-monoˡ-≤ n) + +x≥ε⇒×-cancelʳ-< : ∀ {x} → x ≥ ε → Injective ℕ._<_ _<_ (_× x) +x≥ε⇒×-cancelʳ-< x≥ε m×x (<⇒≱ m×x_ (_× x) +x≤ε⇒×-anti-cancelʳ-< x≤ε m×x>n×x = ℕₚ.≰⇒> (<⇒≱ m×x>n×x ∘ x≤ε⇒×-anti-monoʳ-≤ x≤ε) + +-- _≤_ + +n≢0⇒×-cancelˡ-≤ : ∀ n → ⦃ NonZero n ⦄ → Injective _≤_ _≤_ (n ×_) +n≢0⇒×-cancelˡ-≤ n = mono₁-<⇒cancel₁-≤ (n≢0⇒×-monoˡ-< n) + +x>ε⇒×-cancelʳ-≤ : ∀ {x} → x > ε → Injective ℕ._≤_ _≤_ (_× x) +x>ε⇒×-cancelʳ-≤ x>ε m×x≤n×x = ℕₚ.≮⇒≥ (≤⇒≯ m×x≤n×x ∘ x>ε⇒×-monoʳ-< x>ε) + +x<ε⇒×-anti-cancelʳ-≤ : ∀ {x} → x < ε → Injective ℕ._≤_ _≥_ (_× x) +x<ε⇒×-anti-cancelʳ-≤ x<ε m×x≥n×x = ℕₚ.≮⇒≥ (≤⇒≯ m×x≥n×x ∘ x<ε⇒×-anti-monoʳ-< x<ε) + +---- Respects signs + +-- _<_ + +n×x>ε⇒x>ε : ∀ {n x} → n × x > ε → x > ε +n×x>ε⇒x>ε {n} n×x>ε = ≰⇒> (<⇒≱ n×x>ε ∘ x≤ε⇒n×x≤ε n) + +n×x<ε⇒x<ε : ∀ {n x} → n × x < ε → x < ε +n×x<ε⇒x<ε {n} n×x<ε = ≰⇒> (<⇒≱ n×x<ε ∘ x≥ε⇒n×x≥ε n) + +-- _≥_ + +n≢0∧n×x≥ε⇒x≥ε : ∀ {n x} → ⦃ NonZero n ⦄ → n × x ≥ ε → x ≥ ε +n≢0∧n×x≥ε⇒x≥ε {n} n×x≥ε = ≮⇒≥ (≤⇒≯ n×x≥ε ∘ n≢0∧x<ε⇒n×x<ε n) + +n≢0∧n×x≤ε⇒x≤ε : ∀ {n x} → ⦃ NonZero n ⦄ → n × x ≤ ε → x ≤ ε +n≢0∧n×x≤ε⇒x≤ε {n} n×x≤ε = ≮⇒≥ (≤⇒≯ n×x≤ε ∘ n≢0∧x>ε⇒n×x>ε n) + +-- ---- Infer signs + +-- -- _≈_ + +-- n≢0∧n×x≈x⇒x≈ε : ∀ n {x} → ⦃ NonZero n ⦄ → n × x ≈ x → x ≈ ε +-- n≢0∧n×x≈x⇒x≈ε n n×x≈x = ≮∧≯⇒≈ +-- (λ x<ε → <-irrefl n×x≈x (<-trans (n≢0∧x<ε⇒n×x<ε {!!} {!!}) {!!})) +-- (λ x>ε → {!!}) diff --git a/src/Helium/Algebra/Ordered/StrictTotal/Properties/Ring.agda b/src/Helium/Algebra/Ordered/StrictTotal/Properties/Ring.agda index 484143c..5e51e89 100644 --- a/src/Helium/Algebra/Ordered/StrictTotal/Properties/Ring.agda +++ b/src/Helium/Algebra/Ordered/StrictTotal/Properties/Ring.agda @@ -14,68 +14,542 @@ module Helium.Algebra.Ordered.StrictTotal.Properties.Ring where open Ring ring + renaming + ( trans to <-trans + ; irrefl to <-irrefl + ; asym to <-asym + ; 00∧y>0⇒x*y>0 + ) -open import Agda.Builtin.FromNat -open import Agda.Builtin.FromNeg -open import Data.Nat using (suc; NonZero) +open import Algebra.Definitions +open import Data.Nat as ℕ using (suc; NonZero) open import Data.Sum using (inj₁; inj₂) -open import Data.Unit.Polymorphic using (⊤) -open import Relation.Binary using (tri<; tri≈; tri>) +open import Function using (_∘_) +open import Function.Definitions +open import Helium.Algebra.Ordered.StrictTotal.Consequences strictTotalOrder +open import Relation.Binary.Core +open import Relation.Binary.Definitions using (tri<; tri≈; tri>) open import Relation.Binary.Reasoning.StrictPartialOrder strictPartialOrder open import Algebra.Properties.Ring Unordered.ring public renaming (-0#≈0# to -0≈0) + open import Algebra.Properties.Semiring.Mult.TCOptimised Unordered.semiring public open import Algebra.Properties.Semiring.Exp.TCOptimised Unordered.semiring public +open import Helium.Relation.Binary.Properties.StrictTotalOrder strictTotalOrder public open import Helium.Algebra.Ordered.StrictTotal.Properties.AbelianGroup +-abelianGroup public - using (<⇒≱; ≤⇒≯; >⇒≉; ≈⇒≯; <⇒≉; ≈⇒≮; ≤∧≉⇒<; ≥∧≉⇒>) + using + ( ×-zeroˡ; ×-zeroʳ + ; ×-identityˡ + ; n≢0⇒×-monoˡ-<; ×-monoˡ-≤ + ; ×-cancelˡ-<; n≢0⇒×-cancelˡ-≤ + ) renaming - ( x _ _ 0>1 = inj₁ (begin-strict - 0 <⟨ 01 ⟩ - -1 ∎ - -1≉0+n≉0⇒0<+n : 1 ≉ 0 → ∀ n → {{NonZero n}} → 0 < fromNat n -1≉0+n≉0⇒0<+n 1≉0 (suc 0) = ≥∧≉⇒> 0≤1 1≉0 -1≉0+n≉0⇒0<+n 1≉0 (suc (suc n)) = begin-strict - 0 ≈˘⟨ +-identity² ⟩ - 0 + 0 <⟨ +-invariantˡ 0 (≥∧≉⇒> 0≤1 1≉0) ⟩ - 0 + 1 <⟨ +-invariantʳ 1 (1≉0+n≉0⇒0<+n 1≉0 (suc n)) ⟩ - fromNat (suc n) + 1 ∎ - -1≉0+n≉0⇒-n<0 : 1 ≉ 0 → ∀ n → {{NonZero n}} → fromNeg n < 0 -1≉0+n≉0⇒-n<0 1≉0 n = begin-strict - - fromNat n <⟨ -‿anti-mono (1≉0+n≉0⇒0<+n 1≉0 n) ⟩ - - 0 ≈⟨ -0≈0 ⟩ - 0 ∎ + ( ∙-mono-< to +-mono-< + ; ∙-monoˡ-< to +-monoˡ-< + ; ∙-monoʳ-< to +-monoʳ-< + ; ∙-mono-≤ to +-mono-≤ + ; ∙-monoˡ-≤ to +-monoˡ-≤ + ; ∙-monoʳ-≤ to +-monoʳ-≤ + + ; ∙-cancelˡ-< to +-cancelˡ-< + ; ∙-cancelʳ-< to +-cancelʳ-< + ; ∙-cancel-< to +-cancel-< + ; ∙-cancelˡ-≤ to +-cancelˡ-≤ + ; ∙-cancelʳ-≤ to +-cancelʳ-≤ + ; ∙-cancel-≤ to +-cancel-≤ + -- _∙_ pres signs + ; x≥ε∧y>ε⇒x∙y>ε to x≥0∧y>0⇒x+y>0 + ; x>ε∧y≥ε⇒x∙y>ε to x>0∧y≥0⇒x+y>0 + ; x≤ε∧y<ε⇒x∙y<ε to x≤0∧y<0⇒x+y<0 + ; x<ε∧y≤ε⇒x∙y<ε to x<0∧y≤0⇒x+y<0 + ; x≥ε∧y≥ε⇒x∙y≥ε to x≥0∧y≥0⇒x+y≥0 + ; x≤ε∧y≤ε⇒x∙y≤ε to x≤0∧y≤0⇒x+y≤0 + -- _∙_ resp signs + ; x≤ε∧x∙y>ε⇒y>ε to x≤0∧x+y>0⇒y>0 + ; x≤ε∧y∙x>ε⇒y>ε to x≤0∧y+x>0⇒y>0 + ; x<ε∧x∙y≥ε⇒y>ε to x<0∧x+y≥0⇒y>0 + ; x<ε∧y∙x≥ε⇒y>ε to x<0∧y+x≥0⇒y>0 + ; x≥ε∧x∙y<ε⇒y<ε to x≥0∧x+y<0⇒y<0 + ; x≥ε∧y∙x<ε⇒y<ε to x≥0∧y+x<0⇒y<0 + ; x>ε∧x∙y≤ε⇒y<ε to x>0∧x+y≤0⇒y<0 + ; x>ε∧y∙x≤ε⇒y<ε to x>0∧y+x≤0⇒y<0 + ; x≤ε∧x∙y≥ε⇒y≥ε to x≤0∧x+y≥0⇒y≥0 + ; x≤ε∧y∙x≥ε⇒y≥ε to x≤0∧y+x≥0⇒y≥0 + ; x≥ε∧x∙y≤ε⇒y≤ε to x≥0∧x+y≤0⇒y≤0 + ; x≥ε∧y∙x≤ε⇒y≤ε to x≥0∧y+x≤0⇒y≤0 + + ; x>ε⇒×-monoʳ-< to x>0⇒×-monoʳ-< + ; x<ε⇒×-anti-monoʳ-< to x<0⇒×-anti-monoʳ-< + ; x≥ε⇒×-monoʳ-≤ to x≥0⇒×-monoʳ-≤ + ; x≤ε⇒×-anti-monoʳ-≤ to x≤0⇒×-anti-monoʳ-≤ + + ; x≥ε⇒×-cancelʳ-< to x≥0⇒×-cancelʳ-< + ; x≤ε⇒×-anti-cancelʳ-< to x≤0⇒×-anti-cancelʳ-< + ; x>ε⇒×-cancelʳ-≤ to x>0⇒×-cancelʳ-≤ + ; x<ε⇒×-anti-cancelʳ-≤ to x<0⇒×-anti-cancelʳ-≤ + -- _×_ pres signs + ; n≢0∧x>ε⇒n×x>ε to n≢0∧x>0⇒n×x>0 + ; n≢0∧x<ε⇒n×x<ε to n≢0∧x<0⇒n×x<0 + ; x≥ε⇒n×x≥ε to x≥0⇒n×x≥0 + ; x≤ε⇒n×x≤ε to x≤0⇒n×x≤0 + -- _×_ resp signs + ; n×x>ε⇒x>ε to n×x>0⇒x>0 + ; n×x<ε⇒x<ε to n×x<0⇒x<0 + ; n≢0∧n×x≥ε⇒x≥ε to n≢0∧n×x≥0⇒x≥0 + ; n≢0∧n×x≤ε⇒x≤ε to n≢0∧n×x≤0⇒x≤0 + + ; ⁻¹-anti-mono-< to -‿anti-mono-< + ; ⁻¹-anti-mono-≤ to -‿anti-mono-≤ + + ; ⁻¹-cancel to -‿cancel + ; ⁻¹-anti-cancel-< to -‿anti-cancel-< + ; ⁻¹-anti-cancel-≤ to -‿anti-cancel-≤ + + ; x<ε⇒x⁻¹>ε to x<0⇒-x>0 + ; x>ε⇒x⁻¹<ε to x>0⇒-x<0 + ; x≤ε⇒x⁻¹≥ε to x≤0⇒-x≥0 + ; x≥ε⇒x⁻¹≤ε to x≥0⇒-x≤0 + + ; x⁻¹<ε⇒x>ε to -x<0⇒x>0 + ; x⁻¹>ε⇒x<ε to -x>0⇒x<0 + ; x⁻¹≤ε⇒x≥ε to -x≤0⇒x≥0 + ; x⁻¹≥ε⇒x≤ε to -x≥0⇒x≤0 + + ; x0⇒*-monoˡ-< : ∀ {x} → x > 0# → Congruent₁ _<_ (x *_) +x>0⇒*-monoˡ-< {x} x>0 {y} {z} y0⇒-x<0 (x>0∧y>0⇒x*y>0 x>0 (x0⇒*-monoʳ-< : ∀ {x} → x > 0# → Congruent₁ _<_ (_* x) +x>0⇒*-monoʳ-< {x} x>0 {y} {z} y0⇒-x<0 (x>0∧y>0⇒x*y>0 (x0)) ⟩ + z * x + 0# ≈⟨ +-identityʳ (z * x) ⟩ + z * x ∎ + +x<0⇒*-anti-monoˡ-< : ∀ {x} → x < 0# → (x *_) Preserves _<_ ⟶ _>_ +x<0⇒*-anti-monoˡ-< {x} x<0 {y} {z} y0∧y>0⇒x*y>0 (x<0⇒-x>0 x<0) (x_ +x<0⇒*-anti-monoʳ-< {x} x<0 {y} {z} y0∧y>0⇒x*y>0 (x0 x<0)) ⟩ + z * x + (z - y) * - x ≈⟨ +-congˡ (distribʳ (- x) z (- y)) ⟩ + z * x + (z * - x + - y * - x) ≈˘⟨ +-assoc (z * x) (z * - x) (- y * - x) ⟩ + z * x + z * - x + - y * - x ≈˘⟨ +-congʳ (+-congˡ (-‿distribʳ-* z x)) ⟩ + z * x - z * x + - y * - x ≈⟨ +-cong (-‿inverseʳ (z * x)) (-x*-y≈x*y y x) ⟩ + 0# + y * x ≈⟨ +-identityˡ (y * x) ⟩ + y * x ∎ + +-- _≤_ + +x≥0⇒*-monoˡ-≤ : ∀ {x} → x ≥ 0# → Congruent₁ _≤_ (x *_) +x≥0⇒*-monoˡ-≤ (inj₁ x>0) y≤z = cong₁+mono₁-<⇒mono₁-≤ *-congˡ (x>0⇒*-monoˡ-< x>0) y≤z +x≥0⇒*-monoˡ-≤ {x} (inj₂ 0≈x) {y} {z} y≤z = ≤-reflexive (begin-equality + x * y ≈˘⟨ *-congʳ 0≈x ⟩ + 0# * y ≈⟨ zeroˡ y ⟩ + 0# ≈˘⟨ zeroˡ z ⟩ + 0# * z ≈⟨ *-congʳ 0≈x ⟩ + x * z ∎) + +x≥0⇒*-monoʳ-≤ : ∀ {x} → x ≥ 0# → Congruent₁ _≤_ (_* x) +x≥0⇒*-monoʳ-≤ (inj₁ x>0) y≤z = cong₁+mono₁-<⇒mono₁-≤ *-congʳ (x>0⇒*-monoʳ-< x>0) y≤z +x≥0⇒*-monoʳ-≤ {x} (inj₂ 0≈x) {y} {z} y≤z = ≤-reflexive (begin-equality + y * x ≈˘⟨ *-congˡ 0≈x ⟩ + y * 0# ≈⟨ zeroʳ y ⟩ + 0# ≈˘⟨ zeroʳ z ⟩ + z * 0# ≈⟨ *-congˡ 0≈x ⟩ + z * x ∎) + +x≤0⇒*-anti-monoˡ-≤ : ∀ {x} → x ≤ 0# → (x *_) Preserves _≤_ ⟶ _≥_ +x≤0⇒*-anti-monoˡ-≤ (inj₁ x<0) y≤z = cong₁+anti-mono₁-<⇒anti-mono₁-≤ *-congˡ (x<0⇒*-anti-monoˡ-< x<0) y≤z +x≤0⇒*-anti-monoˡ-≤ {x} (inj₂ x≈0) {y} {z} y≤z = ≤-reflexive (begin-equality + x * z ≈⟨ *-congʳ x≈0 ⟩ + 0# * z ≈⟨ zeroˡ z ⟩ + 0# ≈˘⟨ zeroˡ y ⟩ + 0# * y ≈˘⟨ *-congʳ x≈0 ⟩ + x * y ∎) + +x≤0⇒*-anti-monoʳ-≤ : ∀ {x} → x ≤ 0# → (_* x) Preserves _≤_ ⟶ _≥_ +x≤0⇒*-anti-monoʳ-≤ (inj₁ x<0) y≤z = cong₁+anti-mono₁-<⇒anti-mono₁-≤ *-congʳ (x<0⇒*-anti-monoʳ-< x<0) y≤z +x≤0⇒*-anti-monoʳ-≤ {x} (inj₂ x≈0) {y} {z} y≤z = ≤-reflexive (begin-equality + z * x ≈⟨ *-congˡ x≈0 ⟩ + z * 0# ≈⟨ zeroʳ z ⟩ + 0# ≈˘⟨ zeroʳ y ⟩ + y * 0# ≈˘⟨ *-congˡ x≈0 ⟩ + y * x ∎) + +---- Cancellative + +-- _≈_ + +x>0⇒*-cancelˡ : ∀ {x} → x > 0# → Injective _≈_ _≈_ (x *_) +x>0⇒*-cancelˡ x>0 = mono₁-<⇒cancel₁ (x>0⇒*-monoˡ-< x>0) + +x>0⇒*-cancelʳ : ∀ {x} → x > 0# → Injective _≈_ _≈_ (_* x) +x>0⇒*-cancelʳ x>0 = mono₁-<⇒cancel₁ (x>0⇒*-monoʳ-< x>0) + +x<0⇒*-cancelˡ : ∀ {x} → x < 0# → Injective _≈_ _≈_ (x *_) +x<0⇒*-cancelˡ x<0 = anti-mono₁-<⇒cancel₁ (x<0⇒*-anti-monoˡ-< x<0) + +x<0⇒*-cancelʳ : ∀ {x} → x < 0# → Injective _≈_ _≈_ (_* x) +x<0⇒*-cancelʳ x<0 = anti-mono₁-<⇒cancel₁ (x<0⇒*-anti-monoʳ-< x<0) + +-- _<_ + +x≥0⇒*-cancelˡ-< : ∀ {x} → x ≥ 0# → Injective _<_ _<_ (x *_) +x≥0⇒*-cancelˡ-< = mono₁-≤⇒cancel₁-< ∘ x≥0⇒*-monoˡ-≤ + +x≥0⇒*-cancelʳ-< : ∀ {x} → x ≥ 0# → Injective _<_ _<_ (_* x) +x≥0⇒*-cancelʳ-< = mono₁-≤⇒cancel₁-< ∘ x≥0⇒*-monoʳ-≤ + +x≤0⇒*-anti-cancelˡ-< : ∀ {x} → x ≤ 0# → Injective _<_ _>_ (x *_) +x≤0⇒*-anti-cancelˡ-< = anti-mono₁-≤⇒anti-cancel₁-< ∘ x≤0⇒*-anti-monoˡ-≤ + +x≤0⇒*-anti-cancelʳ-< : ∀ {x} → x ≤ 0# → Injective _<_ _>_ (_* x) +x≤0⇒*-anti-cancelʳ-< = anti-mono₁-≤⇒anti-cancel₁-< ∘ x≤0⇒*-anti-monoʳ-≤ + +-- _≤_ + +x>0⇒*-cancelˡ-≤ : ∀ {x} → x > 0# → Injective _≤_ _≤_ (x *_) +x>0⇒*-cancelˡ-≤ = mono₁-<⇒cancel₁-≤ ∘ x>0⇒*-monoˡ-< + +x>0⇒*-cancelʳ-≤ : ∀ {x} → x > 0# → Injective _≤_ _≤_ (_* x) +x>0⇒*-cancelʳ-≤ = mono₁-<⇒cancel₁-≤ ∘ x>0⇒*-monoʳ-< + +x<0⇒*-anti-cancelˡ-≤ : ∀ {x} → x < 0# → Injective _≤_ _≥_ (x *_) +x<0⇒*-anti-cancelˡ-≤ = anti-mono₁-<⇒anti-cancel₁-≤ ∘ x<0⇒*-anti-monoˡ-< + +x<0⇒*-anti-cancelʳ-≤ : ∀ {x} → x < 0# → Injective _≤_ _≥_ (_* x) +x<0⇒*-anti-cancelʳ-≤ = anti-mono₁-<⇒anti-cancel₁-≤ ∘ x<0⇒*-anti-monoʳ-< + +---- Preserves signs + +-- _≈_ + +x≈0⇒x*y≈0 : ∀ {x} → x ≈ 0# → ∀ y → x * y ≈ 0# +x≈0⇒x*y≈0 {x} x≈0 y = begin-equality + x * y ≈⟨ *-congʳ x≈0 ⟩ + 0# * y ≈⟨ zeroˡ y ⟩ + 0# ∎ + +x≈0⇒y*x≈0 : ∀ {x} → x ≈ 0# → ∀ y → y * x ≈ 0# +x≈0⇒y*x≈0 {x} x≈0 y = begin-equality + y * x ≈⟨ *-congˡ x≈0 ⟩ + y * 0# ≈⟨ zeroʳ y ⟩ + 0# ∎ + +-- _<_ + +-- Have x>0∧y>0⇒x*y>0 by ring + +x>0∧y<0⇒x*y<0 : ∀ {x y} → x > 0# → y < 0# → x * y < 0# +x>0∧y<0⇒x*y<0 {x} {y} x>0 y<0 = -x>0⇒x<0 (begin-strict + 0# <⟨ x>0∧y>0⇒x*y>0 x>0 (x<0⇒-x>0 y<0) ⟩ + x * - y ≈˘⟨ -‿distribʳ-* x y ⟩ + - (x * y) ∎) + +x<0∧y>0⇒x*y<0 : ∀ {x y} → x < 0# → y > 0# → x * y < 0# +x<0∧y>0⇒x*y<0 {x} {y} x<0 y>0 = -x>0⇒x<0 (begin-strict + 0# <⟨ x>0∧y>0⇒x*y>0 (x<0⇒-x>0 x<0) y>0 ⟩ + - x * y ≈˘⟨ -‿distribˡ-* x y ⟩ + - (x * y) ∎) + +x<0∧y<0⇒x*y>0 : ∀ {x y} → x < 0# → y < 0# → x * y > 0# +x<0∧y<0⇒x*y>0 {x} {y} x<0 y<0 = begin-strict + 0# <⟨ x>0∧y>0⇒x*y>0 (x<0⇒-x>0 x<0) (x<0⇒-x>0 y<0) ⟩ + - x * - y ≈⟨ -x*-y≈x*y x y ⟩ + x * y ∎ + +-- _≤_ + +x≥0∧y≥0⇒x*y≥0 : ∀ {x y} → x ≥ 0# → y ≥ 0# → x * y ≥ 0# +x≥0∧y≥0⇒x*y≥0 {x} {y} (inj₁ x>0) (inj₁ y>0) = <⇒≤ (x>0∧y>0⇒x*y>0 x>0 y>0) +x≥0∧y≥0⇒x*y≥0 {x} {y} (inj₁ x>0) (inj₂ 0≈y) = ≤-reflexive (Eq.sym (x≈0⇒y*x≈0 (Eq.sym 0≈y) x)) +x≥0∧y≥0⇒x*y≥0 {x} {y} (inj₂ 0≈x) y≥0 = ≤-reflexive (Eq.sym (x≈0⇒x*y≈0 (Eq.sym 0≈x) y)) + +x≥0∧y≤0⇒x*y≤0 : ∀ {x y} → x ≥ 0# → y ≤ 0# → x * y ≤ 0# +x≥0∧y≤0⇒x*y≤0 {x} {y} (inj₁ x>0) (inj₁ y<0) = <⇒≤ (x>0∧y<0⇒x*y<0 x>0 y<0) +x≥0∧y≤0⇒x*y≤0 {x} {y} (inj₁ x>0) (inj₂ y≈0) = ≤-reflexive (x≈0⇒y*x≈0 y≈0 x) +x≥0∧y≤0⇒x*y≤0 {x} {y} (inj₂ 0≈x) y≤0 = ≤-reflexive (x≈0⇒x*y≈0 (Eq.sym 0≈x) y) + +x≤0∧y≥0⇒x*y≤0 : ∀ {x y} → x ≤ 0# → y ≥ 0# → x * y ≤ 0# +x≤0∧y≥0⇒x*y≤0 {x} {y} (inj₁ x<0) (inj₁ y>0) = <⇒≤ (x<0∧y>0⇒x*y<0 x<0 y>0) +x≤0∧y≥0⇒x*y≤0 {x} {y} (inj₁ x<0) (inj₂ 0≈y) = ≤-reflexive (x≈0⇒y*x≈0 (Eq.sym 0≈y) x) +x≤0∧y≥0⇒x*y≤0 {x} {y} (inj₂ x≈0) y≥0 = ≤-reflexive (x≈0⇒x*y≈0 x≈0 y) + +x≤0∧y≤0⇒x*y≥0 : ∀ {x y} → x ≤ 0# → y ≤ 0# → x * y ≥ 0# +x≤0∧y≤0⇒x*y≥0 {x} {y} (inj₁ x<0) (inj₁ y<0) = <⇒≤ (x<0∧y<0⇒x*y>0 x<0 y<0) +x≤0∧y≤0⇒x*y≥0 {x} {y} (inj₁ x<0) (inj₂ y≈0) = ≤-reflexive (Eq.sym (x≈0⇒y*x≈0 y≈0 x)) +x≤0∧y≤0⇒x*y≥0 {x} {y} (inj₂ x≈0) y≤0 = ≤-reflexive (Eq.sym (x≈0⇒x*y≈0 x≈0 y)) + +---- Respects signs + +-- _<_ + +-- x>0∧x*y>0⇒y>0 +-- x>0∧x*y<0⇒y<0 +-- x>0∧y*x>0⇒y>0 +-- x>0∧y*x<0⇒y<0 +-- x<0∧x*y>0⇒y<0 +-- x<0∧x*y<0⇒y>0 +-- x<0∧y*x>0⇒y<0 +-- x<0∧y*x<0⇒y>0 + +-- _≤_ + +-- x>0∧x*y≥0⇒y≥0 +-- x>0∧x*y≤0⇒y≤0 +-- x>0∧y*x≥0⇒y≥0 +-- x>0∧y*x≤0⇒y≤0 +-- x<0∧x*y≥0⇒y≤0 +-- x<0∧x*y≤0⇒y≥0 +-- x<0∧y*x≥0⇒y≤0 +-- x<0∧y*x≤0⇒y≥0 + +-------------------------------------------------------------------------------- +---- Properties of 0 and 1 + +0≤1 : 0# ≤ 1# +0≤1 = ≮⇒≥ (λ 0>1 → <-asym 0>1 (begin-strict + 0# <⟨ x<0∧y<0⇒x*y>0 0>1 0>1 ⟩ + 1# * 1# ≈⟨ *-identity² ⟩ + 1# ∎)) + +1≈0⇒x≈y : ∀ {x y} → 1# ≈ 0# → x ≈ y +1≈0⇒x≈y {x} {y} 1≈0 = begin-equality + x ≈˘⟨ *-identityʳ x ⟩ + x * 1# ≈⟨ x≈0⇒y*x≈0 1≈0 x ⟩ + 0# ≈˘⟨ x≈0⇒y*x≈0 1≈0 y ⟩ + y * 1# ≈⟨ *-identityʳ y ⟩ + y ∎ + +x1∧y≥1⇒x*y>1 : ∀ {x y} → x > 1# → y ≥ 1# → x * y > 1# +x>1∧y≥1⇒x*y>1 {x} {y} x>1 y≥1 = begin-strict + 1# ≈˘⟨ *-identity² ⟩ + 1# * 1# <⟨ x>0⇒*-monoʳ-< (x1) x>1 ⟩ + x * 1# ≤⟨ x≥0⇒*-monoˡ-≤ (≤-trans 0≤1 (<⇒≤ x>1)) y≥1 ⟩ + x * y ∎ + +x≥1∧y>1⇒x*y>1 : ∀ {x y} → x ≥ 1# → y > 1# → x * y > 1# +x≥1∧y>1⇒x*y>1 {x} {y} x≥1 y>1 = begin-strict + 1# ≈˘⟨ *-identity² ⟩ + 1# * 1# <⟨ x>0⇒*-monoˡ-< (x1) y>1 ⟩ + 1# * y ≤⟨ x≥0⇒*-monoʳ-≤ (≤-trans 0≤1 (<⇒≤ y>1)) x≥1 ⟩ + x * y ∎ + +0≤x<1∧y≤1⇒x*y<1 : ∀ {x y} → 0# ≤ x → x < 1# → y ≤ 1# → x * y < 1# +0≤x<1∧y≤1⇒x*y<1 {x} {y} 0≤x x<1 y≤1 = begin-strict + x * y ≤⟨ x≥0⇒*-monoˡ-≤ 0≤x y≤1 ⟩ + x * 1# <⟨ x>0⇒*-monoʳ-< (x0⇒*-monoˡ-< (x0 x<0 x<0) +... | tri≈ _ x≈0 _ = ≤-reflexive (Eq.sym (x≈0⇒x*y≈0 x≈0 x)) +... | tri> _ _ x>0 = <⇒≤ (x>0∧y>0⇒x*y>0 x>0 x>0) + +-------------------------------------------------------------------------------- +---- Properties of _^_ + +---- Zero + +^-zeroˡ : ∀ n → 1# ^ n ≈ 1# +^-zeroˡ 0 = Eq.refl +^-zeroˡ (suc n) = begin-equality + 1# ^ suc n ≈⟨ ^-homo-* 1# 1 n ⟩ + 1# * 1# ^ n ≈⟨ *-congˡ (^-zeroˡ n) ⟩ + 1# * 1# ≈⟨ *-identity² ⟩ + 1# ∎ + +^-zeroʳ : ∀ x → x ^ 0 ≈ 1# +^-zeroʳ x = Eq.refl + +---- Identity + +^-identityʳ : ∀ x → x ^ 1 ≈ x +^-identityʳ x = Eq.refl + +---- Preserves sign + +-- _≤_ + +x≥0⇒x^n≥0 : ∀ {x} → x ≥ 0# → ∀ n → x ^ n ≥ 0# +x≥0⇒x^n≥0 {x} x≥0 0 = 0≤1 +x≥0⇒x^n≥0 {x} x≥0 (suc n) = begin + 0# ≤⟨ x≥0∧y≥0⇒x*y≥0 x≥0 (x≥0⇒x^n≥0 x≥0 n) ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +-- _<_ + +x>0⇒x^n>0 : ∀ {x} → x > 0# → ∀ n → x ^ n > 0# +x>0⇒x^n>0 {x} x>0 0 = x0 +x>0⇒x^n>0 {x} x>0 (suc n) = begin-strict + 0# <⟨ x>0∧y>0⇒x*y>0 x>0 (x>0⇒x^n>0 x>0 n) ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +---- Preserves size + +-- _≤_ + +x≥1⇒x^n≥1 : ∀ {x} → x ≥ 1# → ∀ n → x ^ n ≥ 1# +x≥1⇒x^n≥1 {x} x≥1 0 = ≤-refl +x≥1⇒x^n≥1 {x} x≥1 (suc n) = begin + 1# ≤⟨ x≥1∧y≥1⇒x*y≥1 x≥1 (x≥1⇒x^n≥1 x≥1 n) ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +0≤x≤1⇒x^n≤1 : ∀ {x} → 0# ≤ x → x ≤ 1# → ∀ n → x ^ n ≤ 1# +0≤x≤1⇒x^n≤1 {x} 0≤x x≤1 0 = ≤-refl +0≤x≤1⇒x^n≤1 {x} 0≤x x≤1 (suc n) = begin + x ^ suc n ≈⟨ ^-homo-* x 1 n ⟩ + x * x ^ n ≤⟨ 0≤x≤1∧y≤1⇒x*y≤1 0≤x x≤1 (0≤x≤1⇒x^n≤1 0≤x x≤1 n) ⟩ + 1# ∎ + +-- _<_ + +x>1∧n≢0⇒x^n>1 : ∀ {x} → x > 1# → ∀ n → ⦃ NonZero n ⦄ → x ^ n > 1# +x>1∧n≢0⇒x^n>1 {x} x>1 (suc n) = begin-strict + 1# <⟨ x>1∧y≥1⇒x*y>1 x>1 (x≥1⇒x^n≥1 (<⇒≤ x>1) n) ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +0≤x<1∧n≢0⇒x^n<1 : ∀ {x} → 0# ≤ x → x < 1# → ∀ n → ⦃ NonZero n ⦄ → x ^ n < 1# +0≤x<1∧n≢0⇒x^n<1 {x} 0≤x x<1 (suc n) = begin-strict + x ^ suc n ≈⟨ ^-homo-* x 1 n ⟩ + x * x ^ n <⟨ 0≤x<1∧y≤1⇒x*y<1 0≤x x<1 (0≤x≤1⇒x^n≤1 0≤x (<⇒≤ x<1) n) ⟩ + 1# ∎ + +---- Congruences + +-- _≈_ + +n≢0⇒0^n≈0 : ∀ n → ⦃ NonZero n ⦄ → 0# ^ n ≈ 0# +n≢0⇒0^n≈0 (suc n) = begin-equality + 0# ^ suc n ≈⟨ ^-homo-* 0# 1 n ⟩ + 0# * 0# ^ n ≈⟨ zeroˡ (0# ^ n) ⟩ + 0# ∎ + +-- _≤_ + +x≥1⇒^-monoˡ-≤ : ∀ {x} → x ≥ 1# → (x ^_) Preserves ℕ._≤_ ⟶ _≤_ +x≥1⇒^-monoˡ-≤ {x} x≥1 {.0} {n} ℕ.z≤n = x≥1⇒x^n≥1 x≥1 n +x≥1⇒^-monoˡ-≤ {x} x≥1 {.suc m} {.suc n} (ℕ.s≤s m≤n) = begin + x ^ suc m ≈⟨ ^-homo-* x 1 m ⟩ + x * x ^ m ≤⟨ x≥0⇒*-monoˡ-≤ (≤-trans 0≤1 x≥1) (x≥1⇒^-monoˡ-≤ x≥1 m≤n) ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +0≤x≤1⇒^-anti-monoˡ-≤ : ∀ {x} → 0# ≤ x → x ≤ 1# → (x ^_) Preserves ℕ._≤_ ⟶ _≥_ +0≤x≤1⇒^-anti-monoˡ-≤ {x} 0≤x x≤1 {.0} {n} ℕ.z≤n = 0≤x≤1⇒x^n≤1 0≤x x≤1 n +0≤x≤1⇒^-anti-monoˡ-≤ {x} 0≤x x≤1 {.suc m} {.suc n} (ℕ.s≤s m≤n) = begin + x ^ suc n ≈⟨ ^-homo-* x 1 n ⟩ + x * x ^ n ≤⟨ x≥0⇒*-monoˡ-≤ 0≤x (0≤x≤1⇒^-anti-monoˡ-≤ 0≤x x≤1 m≤n) ⟩ + x * x ^ m ≈˘⟨ ^-homo-* x 1 m ⟩ + x ^ suc m ∎ + +-- _<_ + +x>1⇒^-monoˡ-< : ∀ {x} → x > 1# → (x ^_) Preserves ℕ._<_ ⟶ _<_ +x>1⇒^-monoˡ-< {x} x>1 {m} {.suc n} (ℕ.s≤s m≤n) = begin-strict + x ^ m ≤⟨ x≥1⇒^-monoˡ-≤ (<⇒≤ x>1) m≤n ⟩ + x ^ n ≈˘⟨ *-identityˡ (x ^ n) ⟩ + 1# * x ^ n <⟨ x>0⇒*-monoʳ-< (x>0⇒x^n>0 (≤-<-trans 0≤1 x>1) n) x>1 ⟩ + x * x ^ n ≈˘⟨ ^-homo-* x 1 n ⟩ + x ^ suc n ∎ + +0_ +00⇒*-monoʳ-< (x>0⇒x^n>0 0) +open import Relation.Nullary.Negation using (contradiction) private module pseudocode = Pseudocode pseudocode + instance + numberℕ : Number ℕ + numberℕ = ℕₗ.number open pseudocode public hiding - (1≉0; module ℤ; module ℤ′; module ℝ; module ℝ′; module ℤ-Reasoning; module ℝ-Reasoning) + ( integerDiscrete; 1≉0; ⌊⌋-floor + ; module ℤ; module ℤ′; module ℤ-Reasoning + ; module ℝ; module ℝ′; module ℝ-Reasoning + ; module ⌊⌋ + ; module /1 + ) module ℤ where - open pseudocode.ℤ public hiding (ℤ; 0ℤ; 1ℤ) + open pseudocode.ℤ public + hiding (ℤ; 0ℤ; 1ℤ) + renaming + ( trans to <-trans + ; irrefl to <-irrefl + ; asym to <-asym + ; 00∧y>0⇒xy>0 + ) module Reasoning = pseudocode.ℤ-Reasoning open CommRingₚ integerRing public - hiding (1≉0+n≉0⇒0<+n; 1≉0+n≉0⇒-n<0) - 1≉0 : 1 ≉ 0 - 1≉0 = pseudocode.1≉0 + discrete : ∀ x y → y ≤ x ⊎ x + 1ℤ ≤ y + discrete = pseudocode.integerDiscrete - n≉0⇒0<+n : ∀ n → {{NonZero n}} → 0 < fromNat n - n≉0⇒0<+n = CommRingₚ.1≉0+n≉0⇒0<+n integerRing 1≉0 + 1≉0 : 1ℤ ≉ 0ℤ + 1≉0 = pseudocode.1≉0 - n≉0⇒-n<0 : ∀ n → {{NonZero n}} → fromNeg n < 0 - n≉0⇒-n<0 = CommRingₚ.1≉0+n≉0⇒-n<0 integerRing 1≉0 + x≤y0∧y>0⇒x*y>0 + ) module Reasoning = pseudocode.ℝ-Reasoning open CommRingₚ commutativeRing public hiding () - 1≉0 : 1 ≉ 0 + 1≉0 : 1ℝ ≉ 0ℝ 1≉0 1≈0 = ℤ.1≉0 (begin-equality - 1 ≈˘⟨ ⌊⌋∘/1≗id 1 ⟩ - ⌊ 1 /1 ⌋ ≈⟨ ⌊⌋.cong /1.1#-homo ⟩ - ⌊ 1 ⌋ ≈⟨ ⌊⌋.cong 1≈0 ⟩ - ⌊ 0 ⌋ ≈˘⟨ ⌊⌋.cong /1.0#-homo ⟩ - ⌊ 0 /1 ⌋ ≈⟨ ⌊⌋∘/1≗id 0 ⟩ - 0 ∎) + 1ℤ ≈˘⟨ ⌊x/1⌋≈x 1ℤ ⟩ + ⌊ 1ℤ /1 ⌋ ≈⟨ ⌊⌋.cong /1.1#-homo ⟩ + ⌊ 1ℝ ⌋ ≈⟨ ⌊⌋.cong 1≈0 ⟩ + ⌊ 0ℝ ⌋ ≈˘⟨ ⌊⌋.cong /1.0#-homo ⟩ + ⌊ 0ℤ /1 ⌋ ≈⟨ ⌊x/1⌋≈x 0ℤ ⟩ + 0ℤ ∎) + where + open ℤ.Reasoning + open pseudocode using (module /1; module ⌊⌋) + + x>0⇒x⁻¹>0 : ∀ {x} → (x≉0 : x ≉ 0ℝ) → x > 0ℝ → x≉0 ⁻¹ > 0ℝ + x>0⇒x⁻¹>0 {x} x≉0 x>0 = ≰⇒> (λ x⁻¹≤0 → <⇒≱ x>0 (begin + x ≈˘⟨ *-identityˡ x ⟩ + 1ℝ * x ≈˘⟨ *-congʳ (⁻¹-inverseˡ x≉0) ⟩ + x≉0 ⁻¹ * x * x ≤⟨ x≥0⇒*-monoʳ-≤ (<⇒≤ x>0) (x≤0⇒*-anti-monoˡ-≤ x⁻¹≤0 (<⇒≤ x>0)) ⟩ + x≉0 ⁻¹ * 0ℝ * x ≈⟨ *-congʳ (zeroʳ (x≉0 ⁻¹)) ⟩ + 0ℝ * x ≈⟨ zeroˡ x ⟩ + 0ℝ ∎)) + where open Reasoning + + record IsMonotoneContinuous (f : ℝ → ℝ) : Set (r₁ ⊔ r₂ ⊔ r₃) where + field + cong : f Preserves _≈_ ⟶ _≈_ + mono-≤ : f Preserves _≤_ ⟶ _≤_ + continuous-≤-< : ∀ {x y z} → f x ≤ z → z < f y → ∃ λ α → f α ≈ z × x ≤ α × α < y + continuous-<-≤ : ∀ {x y z} → f x < z → z ≤ f y → ∃ λ α → f α ≈ z × x < α × α ≤ y + continuous-<-< : ∀ {x y z} → f x < z → z < f y → ∃ λ α → f α ≈ z × x < α × α < y + + record MCHelper (f : ℝ → ℝ) : Set (r₁ ⊔ r₂ ⊔ r₃) where + field + cong : f Preserves _≈_ ⟶ _≈_ + mono-≤ : f Preserves _≤_ ⟶ _≤_ + continuous-<-< : ∀ {x y z} → f x < z → z < f y → ∃ λ α → f α ≈ z × x < α × α < y + + mcHelper : ∀ {f} → MCHelper f → IsMonotoneContinuous f + mcHelper {f} helper = record + { cong = cong + ; mono-≤ = mono-≤ + ; continuous-≤-< = continuous-≤-< + ; continuous-<-≤ = continuous-<-≤ + ; continuous-<-< = continuous-<-< + } + where + open MCHelper helper + cancel-< : ∀ {x y} → f x < f y → x < y + cancel-< fx (<⇒≱ fx (λ x≥y → ℤ.<⇒≱ ⌊x⌋<⌊y⌋ (mono-≤ x≥y)) + + floor : ∀ {x y} → x ℝ.< y /1 → ⌊ x ⌋ ℤ.< y + floor {x} {y} = pseudocode.⌊⌋-floor x y + + n≤x⇒n≤⌊x⌋ : ∀ {n x} → n /1 ℝ.≤ x → n ℤ.≤ ⌊ x ⌋ + n≤x⇒n≤⌊x⌋ {n} {x} n≤x = begin + n ≈˘⟨ ⌊x/1⌋≈x n ⟩ + ⌊ n /1 ⌋ ≤⟨ mono-≤ n≤x ⟩ + ⌊ x ⌋ ∎ + where open ℤ.Reasoning + + ⌊x⌋≤x : ∀ x → ⌊ x ⌋ /1 ℝ.≤ x + ⌊x⌋≤x x = ℝ.≮⇒≥ (λ x<⌊x⌋ → ℤ.<-asym (floor x<⌊x⌋) (floor x<⌊x⌋)) + + x<⌊x⌋+1 : ∀ x → x ℝ.< (⌊ x ⌋ ℤ.+ 1ℤ) /1 + x<⌊x⌋+1 x = ℝ.≰⇒> (λ x≥⌊x⌋+1 → ℤ.<⇒≱ (ℤ.≤∧≉⇒< ℤ.0≤1 (ℤ.1≉0 ∘ ℤ.Eq.sym)) (ℤ.+-cancelˡ-≤ ⌊ x ⌋ (begin + ⌊ x ⌋ ℤ.+ 1ℤ ≤⟨ n≤x⇒n≤⌊x⌋ x≥⌊x⌋+1 ⟩ + ⌊ x ⌋ ≈˘⟨ ℤ.+-identityʳ ⌊ x ⌋ ⟩ + ⌊ x ⌋ ℤ.+ 0ℤ ∎))) + where open ℤ.Reasoning + + n≤x0 : n ℤ.> 0) → + -- let n≉0 = ℤ.<⇒≉ n>0 ∘ ℤ.Eq.sym in + -- ⌊ ⌊ x ⌋ /1 ℝ.* m /1 ℝ.* n≉0 ℤ.⁻¹ ⌋ ℤ.≈ ⌊ x ℝ.* m /1 ℝ.* n≉0 ℤ.⁻¹ ⌋ + -- ⌊⌊x⌋+m/n⌋≈⌊x+m/n⌋ x m {n} n>0 = ℤ.≤∧≮⇒≈ {!!} {!!} + + f-monocont+int-preimage⇒⌊f⌊x⌋⌋≈⌊fx⌋ : + ∀ (f : ℝ → ℝ) → ℝ.IsMonotoneContinuous f → ℝ.IntegerPreimage f → + ∀ x → ⌊ f (⌊ x ⌋ /1) ⌋ ℤ.≈ ⌊ f x ⌋ + f-monocont+int-preimage⇒⌊f⌊x⌋⌋≈⌊fx⌋ f cont int-preimage x = + ℤ.≤∧≮⇒≈ (mono-≤ (cont.mono-≤ (⌊x⌋≤x x))) (×.uncurry ¬helper ∘ ×.proj₂ ∘ helper) + where + module cont = ℝ.IsMonotoneContinuous cont + module int-preimage = ℝ.IntegerPreimage int-preimage + + helper : ⌊ f (⌊ x ⌋ /1) ⌋ ℤ.< ⌊ f x ⌋ → ∃ λ y → ⌊ x ⌋ ℤ.< y × y /1 ℝ.≤ x + helper f⌊x⌋_ _≥_ + +_≉_ : Rel Carrier ℓ₁ +x ≉ y = ¬ x ≈ y + +_≮_ : Rel Carrier ℓ₂ +x ≮ y = ¬ x < y + +_≤_ : Rel Carrier _ +_≤_ = ToNonStrict._≤_ + +_≰_ : Rel Carrier _ +x ≰ y = ¬ x ≤ y + +_>_ : Rel Carrier ℓ₂ +_>_ = flip _<_ + +_≥_ : Rel Carrier _ +_≥_ = flip _≤_ + + +<-≤-trans : Trans _<_ _≤_ _<_ +<-≤-trans = ToNonStrict.<-≤-trans <-trans <-respʳ-≈ + +≤-<-trans : Trans _≤_ _<_ _<_ +≤-<-trans = ToNonStrict.≤-<-trans Eq.sym <-trans <-respˡ-≈ + + +≤-respˡ-≈ : _≤_ Respectsˡ _≈_ +≤-respˡ-≈ = ToNonStrict.≤-respˡ-≈ Eq.sym Eq.trans <-respˡ-≈ + +≤-respʳ-≈ : _≤_ Respectsʳ _≈_ +≤-respʳ-≈ = ToNonStrict.≤-respʳ-≈ Eq.trans <-respʳ-≈ + +≤-resp-≈ : _≤_ Respects₂ _≈_ +≤-resp-≈ = ToNonStrict.≤-resp-≈ Eq.isEquivalence <-resp-≈ + +≤-reflexive : _≈_ ⇒ _≤_ +≤-reflexive = ToNonStrict.reflexive + +≤-refl : Reflexive _≤_ +≤-refl = ≤-reflexive Eq.refl + +≤-trans : Transitive _≤_ +≤-trans = ToNonStrict.trans Eq.isEquivalence <-resp-≈ <-trans + +≤-antisym : Antisymmetric _≈_ _≤_ +≤-antisym = ToNonStrict.antisym Eq.isEquivalence <-trans <-irrefl + +≤-total : Total _≤_ +≤-total = ToNonStrict.total compare + + +<⇒≤ : _<_ ⇒ _≤_ +<⇒≤ = ToNonStrict.<⇒≤ + +<⇒≉ : Irreflexive _<_ _≈_ +<⇒≉ = flip <-irrefl + +≤∧≉⇒< : ∀ {x y} → x ≤ y → x ≉ y → x < y +≤∧≉⇒< (inj₁ xy) = <-asym xy +<⇒≱ x : _≰_ ⇒ _>_ +≰⇒> {x} {y} x≰y with compare x y +... | tri< x _ _ x>y = x>y + + +≤⇒≯ : Irreflexive _≤_ _>_ +≤⇒≯ = flip <⇒≱ + +≮⇒≥ : _≮_ ⇒ _≥_ +≮⇒≥ {x} {y} x≮y with compare x y +... | tri< x _ _ x>y = <⇒≤ x>y + +≮∧≯⇒≈ : ∀ {x y} → x ≮ y → y ≮ x → x ≈ y +≮∧≯⇒≈ {x} {y} x≮y x≯y with compare x y +... | tri< x _ _ x>y = contradiction x>y x≯y diff --git a/src/Helium/Semantics/Axiomatic.agda b/src/Helium/Semantics/Axiomatic.agda index dfac609..2fa3db1 100644 --- a/src/Helium/Semantics/Axiomatic.agda +++ b/src/Helium/Semantics/Axiomatic.agda @@ -15,11 +15,10 @@ module Helium.Semantics.Axiomatic open import Helium.Data.Pseudocode.Algebra.Properties pseudocode -open import Agda.Builtin.FromNat open import Data.Nat using (ℕ) -import Data.Nat.Literals as ℕₗ import Data.Unit open import Data.Vec using (Vec) +open import Function using (_∘_) open import Helium.Data.Pseudocode.Core import Helium.Semantics.Axiomatic.Core rawPseudocode as Core import Helium.Semantics.Axiomatic.Assertion rawPseudocode as Assertion @@ -36,12 +35,8 @@ open Term.Term public open Term public using (Term) -instance - numberℕ : Number ℕ - numberℕ = ℕₗ.number - -2≉0 : 2 ℝ.≉ 0 -2≉0 = ℝ.>⇒≉ (ℝ.n≉0⇒0<+n 2) +2≉0 : 2 ℝ.× 1ℝ ℝ.≉ 0ℝ +2≉0 = ℝ.<⇒≉ (ℝ.n≢0∧x>0⇒n×x>0 2 (ℝ.≤∧≉⇒< ℝ.0≤1 (ℝ.1≉0 ∘ ℝ.Eq.sym))) ∘ ℝ.Eq.sym HoareTriple : ∀ {o} {Σ : Vec Type o} {n} {Γ : Vec Type n} {m} {Δ : Vec Type m} → Assertion Σ Γ Δ → Code.Statement Σ Γ → Assertion Σ Γ Δ → Set _ HoareTriple = Triple.HoareTriple 2≉0 diff --git a/src/Helium/Semantics/Axiomatic/Term.agda b/src/Helium/Semantics/Axiomatic/Term.agda index eaefb89..c9ddd02 100644 --- a/src/Helium/Semantics/Axiomatic/Term.agda +++ b/src/Helium/Semantics/Axiomatic/Term.agda @@ -32,7 +32,7 @@ import Helium.Data.Pseudocode.Manipulate as M open import Helium.Semantics.Axiomatic.Core rawPseudocode open import Level using (_⊔_; lift; lower) open import Relation.Binary.PropositionalEquality hiding ([_]) renaming (subst to ≡-subst) -open import Relation.Nullary using (does; yes; no) +open import Relation.Nullary using (¬_; does; yes; no) open import Relation.Nullary.Decidable.Core using (True; toWitness) open import Relation.Nullary.Negation using (contradiction) @@ -216,7 +216,7 @@ cast τ eq = func₁ (cast′ τ eq) [ real ][ t ^ n ] = func₁ (lift ∘ (ℝ′._^′ n) ∘ lower) t 2≉0 : Set _ -2≉0 = 2 ℝ′.×′ 1ℝ ℝ.≉ 0ℝ +2≉0 = ¬ 2 ℝ′.×′ 1ℝ ℝ.≈ 0ℝ [_][_>>_] : 2≉0 → Term Σ Γ Δ int → ℕ → Term Σ Γ Δ int [ 2≉0 ][ t >> n ] = func₁ (lift ∘ ⌊_⌋ ∘ (ℝ._* 2≉0 ℝ.⁻¹ ℝ′.^′ n) ∘ _/1 ∘ lower) t diff --git a/src/Helium/Semantics/Denotational/Core.agda b/src/Helium/Semantics/Denotational/Core.agda index 090e0ba..07c71bd 100644 --- a/src/Helium/Semantics/Denotational/Core.agda +++ b/src/Helium/Semantics/Denotational/Core.agda @@ -33,7 +33,7 @@ import Induction as I import Induction.WellFounded as Wf open import Level using (Level; _⊔_; 0ℓ) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_; module ≡-Reasoning) -open import Relation.Nullary using (does) +open import Relation.Nullary using (does) renaming (¬_ to ¬′_) open import Relation.Nullary.Decidable.Core using (True; False; toWitness; fromWitness) ⟦_⟧ₗ : Type → Level @@ -196,12 +196,12 @@ pow : ∀ {t} → IsNumeric t → ⟦ t ⟧ₜ → ℕ → ⟦ t ⟧ₜ pow int x n = x ℤ′.^′ n pow real x n = x ℝ′.^′ n -shiftr : 2 ℝ′.×′ 1ℝ ℝ.≉ 0ℝ → ⟦ int ⟧ₜ → ℕ → ⟦ int ⟧ₜ +shiftr : ¬′ 2 ℝ′.×′ 1ℝ ℝ.≈ 0ℝ → ⟦ int ⟧ₜ → ℕ → ⟦ int ⟧ₜ shiftr 2≉0 x n = ⌊ x /1 ℝ.* 2≉0 ℝ.⁻¹ ℝ′.^′ n ⌋ module Expression {o} {Σ : Vec Type o} - (2≉0 : 2 ℝ′.×′ 1ℝ ℝ.≉ 0ℝ) + (2≉0 : ¬′ 2 ℝ′.×′ 1ℝ ℝ.≈ 0ℝ) where open Code Σ -- cgit v1.2.3