-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric non-zero equivalents/Redesign of Almost*
properties in Algebra.Definitions
#2117
base: master
Are you sure you want to change the base?
Changes from all commits
44163ba
9c50a21
04a9c00
367dfa7
849e706
5e8a45d
ef3eb2b
b86aaef
7a6392c
f89a163
2373404
2ec9bc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
open import Relation.Binary.Core using (Rel; _Preserves_⟶_; _Preserves₂_⟶_⟶_) | ||
open import Relation.Nullary.Negation.Core using (¬_) | ||
|
||
module Algebra.Definitions | ||
{a ℓ} {A : Set a} -- The underlying set | ||
|
@@ -26,21 +25,122 @@ module Algebra.Definitions | |
open import Algebra.Core using (Op₁; Op₂) | ||
open import Data.Product.Base using (_×_; ∃-syntax) | ||
open import Data.Sum.Base using (_⊎_) | ||
open import Function.Base using (flip; id; _∘_; _on_) | ||
open import Relation.Nullary.Negation.Core using (¬_) | ||
open import Relation.Unary using (Pred) | ||
|
||
------------------------------------------------------------------------ | ||
-- Properties of operations | ||
|
||
------------------------------------------------------------------------ | ||
-- A generalisation: because not everything can be defined in terms of | ||
-- a single relation _≈_, AND because the corresponding definitions in | ||
-- `Relation.Binary.Core` use *implicit* quantification... so there is | ||
-- plenty of potential for later/downstream refactoring of this design | ||
|
||
module Monotonicity {ℓ₁ ℓ₂} (_≤₁_ : Rel A ℓ₁) (_≤₂_ : Rel A ℓ₂) where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've probably realized this, but so it doesn't get forgotten: these definitions don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, and I had, indeed, overlooked this aspect of the design, in favour of trying to work out in eg |
||
|
||
Monotone₁ : Op₁ A → Set _ | ||
Monotone₁ f = ∀ x y → x ≤₁ y → (_≤₂_ on f) x y | ||
|
||
Monotone₂ : Op₂ A → Set _ | ||
Monotone₂ _∙_ = ∀ x y u v → x ≤₁ y → u ≤₁ v → (x ∙ u) ≤₂ (y ∙ v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks very similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, you're correct, of course, but this is precisely because the But the general point: we almost never use So I would pleased if this specimen design prompts a wider rethink. There are a number of outstanding issues even in the v2.0 milestone which I think could be tackled with a design along these lines, if we could only think about it enough and agree... so this contribution is offered up towards such an end. |
||
|
||
MonotoneAt : A → Op₂ A → Set _ | ||
MonotoneAt x f = Monotone₁ (f x) | ||
|
||
LeftMonotone : Op₂ A → Set _ | ||
LeftMonotone _∙_ = ∀ x → MonotoneAt x _∙_ | ||
|
||
RightMonotone : Op₂ A → Set _ | ||
RightMonotone _∙_ = ∀ x → MonotoneAt x (flip _∙_) | ||
|
||
AlmostLeftMonotone : (Pred A ℓ) → Op₂ A → Set _ | ||
AlmostLeftMonotone P _∙_ = ∀ {x} → P x → MonotoneAt x _∙_ | ||
|
||
AlmostRightMonotone : (Pred A ℓ) → Op₂ A → Set _ | ||
AlmostRightMonotone P _∙_ = ∀ {x} → P x → MonotoneAt x (flip _∙_) | ||
|
||
------------------------------------------------------------------------ | ||
-- A second generalisation: this could be expressed, less efficiently, | ||
-- in terms of Monotonicity (I think) | ||
|
||
module Cancellativity {ℓ₁ ℓ₂} (_≤₁_ : Rel A ℓ₁) (_≤₂_ : Rel A ℓ₂) where | ||
|
||
Cancellative₁ : Op₁ A → Set _ | ||
Cancellative₁ f = ∀ x y → (_≤₁_ on f) x y → x ≤₂ y | ||
|
||
Cancellative₂ : Op₂ A → Set _ | ||
Cancellative₂ _∙_ = ∀ x y u v → (x ∙ u) ≤₁ (y ∙ v) → x ≤₂ y × u ≤₂ v | ||
|
||
CancellativeAt : A → Op₂ A → Set _ | ||
CancellativeAt x f = Cancellative₁ (f x) | ||
|
||
LeftCancellative : Op₂ A → Set _ | ||
LeftCancellative _∙_ = ∀ x → CancellativeAt x _∙_ | ||
|
||
RightCancellative : Op₂ A → Set _ | ||
RightCancellative _∙_ = ∀ x → CancellativeAt x (flip _∙_) | ||
|
||
AlmostLeftCancellative : (Pred A ℓ) → Op₂ A → Set _ | ||
AlmostLeftCancellative P _∙_ = ∀ {x} → P x → CancellativeAt x _∙_ | ||
|
||
AlmostRightCancellative : (Pred A ℓ) → Op₂ A → Set _ | ||
AlmostRightCancellative P _∙_ = ∀ {x} → P x → CancellativeAt x (flip _∙_) | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- Properties of operations | ||
|
||
-- (Anti)Monotonicity | ||
|
||
open Monotonicity _≈_ _≈_ public | ||
hiding (Monotone₂; MonotoneAt) | ||
renaming (Monotone₁ to Monotone) | ||
|
||
open Monotonicity _≈_ (flip _≈_) public | ||
hiding (Monotone₂; MonotoneAt) | ||
renaming (Monotone₁ to AntiMonotone; | ||
LeftMonotone to LeftAntiMonotone; | ||
RightMonotone to RightAntiMonotone; | ||
AlmostLeftMonotone to AlmostLeftAntiMonotone; | ||
AlmostRightMonotone to AlmostRightAntiMonotone) | ||
|
||
-- Cancellativity | ||
|
||
open Cancellativity _≈_ _≈_ public | ||
hiding (Cancellative₁; Cancellative₂; CancellativeAt; | ||
AlmostLeftCancellative; | ||
AlmostRightCancellative) | ||
|
||
Cancellative : Op₂ A → Set _ | ||
Cancellative _•_ = (LeftCancellative _•_) × (RightCancellative _•_) | ||
|
||
AlmostLeftCancellative : A → Op₂ A → Set _ | ||
AlmostLeftCancellative e | ||
= Cancellativity.AlmostLeftCancellative _≈_ _≈_ λ x → ¬ x ≈ e | ||
|
||
AlmostRightCancellative : A → Op₂ A → Set _ | ||
AlmostRightCancellative e | ||
= Cancellativity.AlmostRightCancellative _≈_ _≈_ λ x → ¬ x ≈ e | ||
|
||
AlmostCancellative : A → Op₂ A → Set _ | ||
AlmostCancellative e _•_ = AlmostLeftCancellative e _•_ × AlmostRightCancellative e _•_ | ||
|
||
------------------------------------------------------------------------ | ||
-- The 'usual' algebraic properties | ||
|
||
Congruent₁ : Op₁ A → Set _ | ||
Congruent₁ f = f Preserves _≈_ ⟶ _≈_ | ||
|
||
Congruent₂ : Op₂ A → Set _ | ||
Congruent₂ ∙ = ∙ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_ | ||
|
||
LeftCongruent : Op₂ A → Set _ | ||
LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_ | ||
LeftCongruent _∙_ = ∀ {x} → Congruent₁ (x ∙_) | ||
|
||
RightCongruent : Op₂ A → Set _ | ||
RightCongruent _∙_ = ∀ {x} → (_∙ x) Preserves _≈_ ⟶ _≈_ | ||
RightCongruent _∙_ = ∀ {x} → Congruent₁ (_∙ x) | ||
|
||
Associative : Op₂ A → Set _ | ||
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z)) | ||
|
@@ -136,24 +236,6 @@ SelfInverse f = ∀ {x y} → f x ≈ y → f y ≈ x | |
Involutive : Op₁ A → Set _ | ||
Involutive f = ∀ x → f (f x) ≈ x | ||
|
||
LeftCancellative : Op₂ A → Set _ | ||
LeftCancellative _•_ = ∀ x y z → (x • y) ≈ (x • z) → y ≈ z | ||
|
||
RightCancellative : Op₂ A → Set _ | ||
RightCancellative _•_ = ∀ x y z → (y • x) ≈ (z • x) → y ≈ z | ||
|
||
Cancellative : Op₂ A → Set _ | ||
Cancellative _•_ = (LeftCancellative _•_) × (RightCancellative _•_) | ||
|
||
AlmostLeftCancellative : A → Op₂ A → Set _ | ||
AlmostLeftCancellative e _•_ = ∀ x y z → ¬ x ≈ e → (x • y) ≈ (x • z) → y ≈ z | ||
|
||
AlmostRightCancellative : A → Op₂ A → Set _ | ||
AlmostRightCancellative e _•_ = ∀ x y z → ¬ x ≈ e → (y • x) ≈ (z • x) → y ≈ z | ||
|
||
AlmostCancellative : A → Op₂ A → Set _ | ||
AlmostCancellative e _•_ = AlmostLeftCancellative e _•_ × AlmostRightCancellative e _•_ | ||
|
||
Interchangable : Op₂ A → Op₂ A → Set _ | ||
Interchangable _∘_ _∙_ = ∀ w x y z → ((w ∙ x) ∘ (y ∙ z)) ≈ ((w ∘ y) ∙ (x ∘ z)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,12 @@ nonNegative : ∀ {i} → i ≥ 0ℤ → NonNegative i | |
nonNegative {+0} _ = _ | ||
nonNegative {+[1+ n ]} _ = _ | ||
|
||
-- Destructors -- mostly see `Data.Integer.Properties` | ||
|
||
≢-nonZero⁻¹ : ∀ i → .{{NonZero i}} → i ≢ 0ℤ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
≢-nonZero⁻¹ +0 ⦃ () ⦄ | ||
≢-nonZero⁻¹ +[1+ n ] () | ||
Comment on lines
+189
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This being the only instance where there is more than one clause to consider... |
||
|
||
------------------------------------------------------------------------ | ||
-- A view of integers as sign + absolute value | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ normalize m n = mkℚ+ (m ℕ./ gcd m n) (n ℕ./ gcd m n) (coprime-/gcd m n) | |
g≢0 = ℕ.≢-nonZero (gcd[m,n]≢0 m n (inj₂ (ℕ.≢-nonZero⁻¹ n))) | ||
n/g≢0 = ℕ.≢-nonZero (n/gcd[m,n]≢0 m n {{gcd≢0 = g≢0}}) | ||
|
||
-- A constructor for ℚ that (unlike mkℚ) automatically normalises it's | ||
-- A constructor for ℚ that (unlike mkℚ) automatically normalises its | ||
-- arguments. See the constants section below for how to use this operator. | ||
|
||
infixl 7 _/_ | ||
|
@@ -202,6 +202,11 @@ nonPositive {p@(mkℚ _ _ _)} (*≤* p≤q) = ℚᵘ.nonPositive {toℚᵘ p} ( | |
nonNegative : ∀ {p} → p ≥ 0ℚ → NonNegative p | ||
nonNegative {p@(mkℚ _ _ _)} (*≤* p≤q) = ℚᵘ.nonNegative {toℚᵘ p} (ℚᵘ.*≤* p≤q) | ||
|
||
-- Destructor -- mostly see `Data.Rational.Properties` | ||
|
||
≢-nonZero⁻¹ : ∀ p → .{{NonZero p}} → p ≢ 0ℚ | ||
≢-nonZero⁻¹ _ ⦃ () ⦄ refl | ||
Comment on lines
+207
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good example of why/how |
||
|
||
------------------------------------------------------------------------ | ||
-- Operations on rationals | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,13 @@ mkℚ+-pos (suc n) (suc d) = _ | |
... | refl with ℤ.*-cancelʳ-≡ n₁ n₂ (+ suc d₁) eq | ||
... | refl = refl | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- Properties of NonZero: destructor | ||
|
||
≄-nonZero⁻¹ : ∀ p → .{{NonZero p}} → ¬ (p ≃ 0ℚ) | ||
≄-nonZero⁻¹ p eq = ≢-nonZero⁻¹ p (≃⇒≡ eq) | ||
Comment on lines
+172
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Infectively so. |
||
|
||
------------------------------------------------------------------------ | ||
-- Properties of ↥ | ||
------------------------------------------------------------------------ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,11 @@ nonNegative : ∀ {p} → p ≥ 0ℚᵘ → NonNegative p | |
nonNegative {mkℚᵘ +0 _} (*≤* _) = _ | ||
nonNegative {mkℚᵘ +[1+ n ] _} (*≤* _) = _ | ||
|
||
-- Destructors -- mostly see `Data.Rational.Properties` | ||
|
||
≢-nonZero⁻¹ : ∀ p → .{{NonZero p}} → p ≢ 0ℚᵘ | ||
≢-nonZero⁻¹ _ ⦃ () ⦄ refl | ||
Comment on lines
+195
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
------------------------------------------------------------------------ | ||
-- Operations on rationals | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the existing text regarding
Almost*Cancellative
, in the absence of a stable story emerging about how it should be replaced. But this comment is a placeholder TODO so...