-
Notifications
You must be signed in to change notification settings - Fork 159
Instances for Pseudolattice and OrderedCommRing
#1268
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
6fee884
add fast implementation of integers and their properties
hexwell 78890fa
move properties of min and max over `ℕ` to the appropriate file
LorenzoMolena ece58b1
reorganize and format code
LorenzoMolena 62ae02c
Merge branch 'agda:master' into fast-int
hexwell e89d311
remove `--safe` flag
LorenzoMolena 031af52
remove `--safe` flag
LorenzoMolena 56810c7
Fast int (#2)
LorenzoMolena ead0553
add fast implementation of integers and their properties
hexwell 99aeb91
move properties of min and max over `ℕ` to the appropriate file
LorenzoMolena 7ddc9bd
reorganize and format code
LorenzoMolena 80cf10b
remove `--safe` flag
LorenzoMolena af4df40
remove `--safe` flag
LorenzoMolena 4954b30
remove `--safe` flag
LorenzoMolena ab8bec0
Fast int (#2)
LorenzoMolena 08be7df
Merge branch 'fast-int' of https://github.com/LorenzoMolena/cubical i…
LorenzoMolena 20c3b5f
fix compatibility with the library
LorenzoMolena 1e37974
Merge branch 'agda:master' into fast-int
LorenzoMolena 931075b
fix compatibility after rebase, start proving properties of fast inte…
LorenzoMolena 2b2d23a
Merge branch 'agda:master' into fast-int
LorenzoMolena bc0973f
Merge branch 'agda:master' into fast-int
LorenzoMolena 89246b9
add instances of `Nat` and `Int` as `Pseudolattice`, and of `Int` as …
LorenzoMolena 0f6037e
fix typo, add better make from Posets to Pseudolattices
LorenzoMolena 4a415d5
update `makePseudolatticeFromPoset` and instances built using it
LorenzoMolena 561308e
move `maxLUB` and `minGLB` to `Data.Nat.Order`, remove unnecessary im…
LorenzoMolena 44cfa14
rewrite properties from `minAssoc` to `-max`, add temporary lemmas in…
LorenzoMolena d63b50c
fix naming clash on import
LorenzoMolena 8b60736
rewrite properties from `pos+posLposMin` to `·DistNegsucLMax`
LorenzoMolena 50a6d3a
start work on Order: adapt properties from `isProp≤` to `≤SumLeftPos`…
LorenzoMolena c7cfd31
use more efficient implementation of quotient and remainder in `Int.F…
LorenzoMolena e2ac053
Merge pull request #20 from LorenzoMolena/fast-int
LorenzoMolena d14b373
adapt properties from `pred-≤-pred` to `0≤o→≤-·o`, move import of `Bo…
LorenzoMolena be459af
adapt properties from `<-·o` to `predℤ-≤-predℤ`
LorenzoMolena 9f3d854
adapt properties from `¬m+posk<m` to `<-+pos-trans`
LorenzoMolena bd8a8f5
adapt properties from `<-pos+-trans` to `0<o→≤-·o-cancel`
LorenzoMolena 6ed800d
adapt properties from `≤-o·-cancel` to `≤→min` ; add conversions betw…
LorenzoMolena 23143d3
adapt properties from `≤MonotoneMin` to `_≟'_` ; add faster `_≟_` and…
LorenzoMolena ed85e07
edit `_≤'_` using recursive order, add `_≤ᵇ_` and `_≤''_`
LorenzoMolena 42c0212
update `minIdem`
LorenzoMolena 2484f5f
clean comments, reorganize `Fast` modules, add more properties in `In…
LorenzoMolena 47725ea
Merge branch 'fast-int-with-pl-and-ocr-instances' into ocr+pl-instances
LorenzoMolena 9b39beb
Revert "Merge branch 'fast-int-with-pl-and-ocr-instances' into ocr+pl…
LorenzoMolena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| module Cubical.Algebra.OrderedCommRing.Instances.Int where | ||
|
|
||
| open import Cubical.Foundations.Prelude | ||
| open import Cubical.Foundations.Function | ||
| open import Cubical.Foundations.Equiv | ||
|
|
||
| import Cubical.Functions.Logic as L | ||
|
|
||
| open import Cubical.Data.Sum | ||
| open import Cubical.Data.Empty as ⊥ | ||
|
|
||
| open import Cubical.HITs.PropositionalTruncation | ||
|
|
||
| open import Cubical.Data.Int as ℤ | ||
| renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_) | ||
| open import Cubical.Data.Int.Order | ||
| renaming (_<_ to _<ℤ_ ; _≤_ to _≤ℤ_) | ||
| open import Cubical.Data.Nat using (ℕ ; zero ; suc) | ||
|
|
||
| open import Cubical.Algebra.CommRing | ||
| open import Cubical.Algebra.CommRing.Instances.Int | ||
|
|
||
| open import Cubical.Algebra.OrderedCommRing | ||
|
|
||
| open import Cubical.Relation.Nullary | ||
|
|
||
| open import Cubical.Relation.Binary.Order.StrictOrder | ||
| open import Cubical.Relation.Binary.Order.StrictOrder.Instances.Int | ||
|
|
||
| open import Cubical.Relation.Binary.Order.Pseudolattice | ||
| open import Cubical.Relation.Binary.Order.Pseudolattice.Instances.Int | ||
|
|
||
| open CommRingStr | ||
| open OrderedCommRingStr | ||
| open PseudolatticeStr | ||
| open StrictOrderStr | ||
|
|
||
| private | ||
| lemma0<+ : ∀ x y → 0 <ℤ x +ℤ y → (0 <ℤ x) L.⊔′ (0 <ℤ y) | ||
| lemma0<+ (pos zero) (pos zero) = ⊥.rec ∘ isIrrefl< | ||
| lemma0<+ (pos zero) (pos (suc n)) = ∣_∣₁ ∘ inr ∘ subst (0 <ℤ_) (sym $ pos0+ _) | ||
| lemma0<+ (pos (suc m)) (pos n) = λ _ → ∣ inl (suc-≤-suc zero-≤pos) ∣₁ | ||
| lemma0<+ (pos zero) (negsuc n) = ⊥.rec ∘ ¬pos≤negsuc ∘ subst (0 <ℤ_) | ||
| (sym $ pos0+ (negsuc n)) | ||
| lemma0<+ (pos (suc m)) (negsuc n) = λ _ → ∣ inl (suc-≤-suc zero-≤pos) ∣₁ | ||
| lemma0<+ (negsuc m) (pos zero) = ⊥.rec ∘ ¬pos≤negsuc | ||
| lemma0<+ (negsuc m) (pos (suc n)) = λ _ → ∣ inr (suc-≤-suc zero-≤pos) ∣₁ | ||
| lemma0<+ (negsuc m) (negsuc n) = ⊥.rec ∘ ¬pos≤negsuc ∘ subst (0 <ℤ_) | ||
| (sym $ neg+ (suc m) (suc n)) | ||
|
|
||
| ℤOrderedCommRing : OrderedCommRing ℓ-zero ℓ-zero | ||
| fst ℤOrderedCommRing = ℤ | ||
| 0r (snd ℤOrderedCommRing) = 0 | ||
| 1r (snd ℤOrderedCommRing) = 1 | ||
| _+_ (snd ℤOrderedCommRing) = _+ℤ_ | ||
| _·_ (snd ℤOrderedCommRing) = _·ℤ_ | ||
| -_ (snd ℤOrderedCommRing) = -ℤ_ | ||
| _<_ (snd ℤOrderedCommRing) = _<ℤ_ | ||
| _≤_ (snd ℤOrderedCommRing) = _≤ℤ_ | ||
| isOrderedCommRing (snd ℤOrderedCommRing) = isOrderedCommRingℤ | ||
| where | ||
| open IsOrderedCommRing | ||
|
|
||
| isOrderedCommRingℤ : IsOrderedCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_ _<ℤ_ _≤ℤ_ | ||
| isOrderedCommRingℤ .isCommRing = ℤCommRing .snd .isCommRing | ||
| isOrderedCommRingℤ .isPseudolattice = ℤ≤Pseudolattice .snd .is-pseudolattice | ||
| isOrderedCommRingℤ .isStrictOrder = ℤ<StrictOrder .snd .isStrictOrder | ||
| isOrderedCommRingℤ .<-≤-weaken = λ _ _ → <-weaken | ||
| isOrderedCommRingℤ .≤≃¬> = λ x y → | ||
| propBiimpl→Equiv isProp≤ (isProp¬ (y <ℤ x)) | ||
| (λ x≤y y<x → isIrrefl< (≤<-trans x≤y y<x)) | ||
| (λ ¬y<x → case x ≟ y return (λ _ → x ≤ℤ y) of λ { | ||
| (lt x<y) → <-weaken x<y ; | ||
| (eq x≡y) → subst (x ≤ℤ_) x≡y isRefl≤ ; | ||
| (gt y<z) → ⊥.rec (¬y<x y<z) }) | ||
| isOrderedCommRingℤ .+MonoR≤ = λ _ _ z → ≤-+o {o = z} | ||
| isOrderedCommRingℤ .+MonoR< = λ _ _ z → <-+o {o = z} | ||
| isOrderedCommRingℤ .posSum→pos∨pos = lemma0<+ | ||
| isOrderedCommRingℤ .<-≤-trans = λ _ _ _ → <≤-trans | ||
| isOrderedCommRingℤ .≤-<-trans = λ _ _ _ → ≤<-trans | ||
| isOrderedCommRingℤ .·MonoR≤ = λ _ _ _ → 0≤o→≤-·o | ||
| isOrderedCommRingℤ .·MonoR< = λ _ _ _ → 0<o→<-·o | ||
| isOrderedCommRingℤ .0<1 = isRefl≤ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Cubical/Relation/Binary/Order/Pseudolattice/Instances/Int.agda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Cubical.Relation.Binary.Order.Pseudolattice.Instances.Int where | ||
|
|
||
| open import Cubical.Foundations.Prelude | ||
|
|
||
| open import Cubical.Data.Int | ||
| open import Cubical.Data.Int.Order renaming (_≤_ to _≤ℤ_) | ||
|
|
||
| open import Cubical.Relation.Binary.Order.Poset.Instances.Int | ||
| open import Cubical.Relation.Binary.Order.Pseudolattice | ||
|
|
||
| ℤ≤Pseudolattice : Pseudolattice ℓ-zero ℓ-zero | ||
| ℤ≤Pseudolattice = makePseudolatticeFromPoset ℤ≤Poset min max | ||
| min≤ | ||
| (λ {a b} → subst (_≤ℤ b) (minComm b a) min≤) | ||
| (λ {a b} x≤a x≤b → subst (_≤ℤ min a b) (minIdem _) (≤MonotoneMin x≤a x≤b)) | ||
| ≤max | ||
| (λ {a b} → subst (b ≤ℤ_) (maxComm b a) ≤max) | ||
| (λ {a b} a≤x b≤x → subst (max a b ≤ℤ_) (maxIdem _) (≤MonotoneMax a≤x b≤x)) |
18 changes: 18 additions & 0 deletions
18
Cubical/Relation/Binary/Order/Pseudolattice/Instances/Nat.agda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Cubical.Relation.Binary.Order.Pseudolattice.Instances.Nat where | ||
|
|
||
| open import Cubical.Foundations.Prelude | ||
|
|
||
| open import Cubical.Data.Nat | ||
| open import Cubical.Data.Nat.Order renaming (_≤_ to _≤ℕ_) | ||
|
|
||
| open import Cubical.Relation.Binary.Order.Poset.Instances.Nat | ||
| open import Cubical.Relation.Binary.Order.Pseudolattice | ||
|
|
||
| ℕ≤Pseudolattice : Pseudolattice ℓ-zero ℓ-zero | ||
| ℕ≤Pseudolattice = makePseudolatticeFromPoset ℕ≤Poset min max | ||
| min-≤-left | ||
| (λ {a b} → min-≤-right {a} {b}) | ||
| minGLB | ||
| left-≤-max | ||
| (λ {a b} → right-≤-max {b} {a}) | ||
| maxLUB |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
likewise for this lemma
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'm fine with making it public in
Data.Int.Order, but I'm not sure what would be the best name for it.It's quite a specific lemma only needed for one of the fields in the
IsOrderedCommRingrecord.Also, I noticed that in other modules (for example
Semilattice.Instances.NatMax) the required fields are proved locally when constructing the instance (even for something as basic asmaxAssoc).Other than that, I agree with the other comments and I will apply those changes.
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.
Upon closer inspection, this seems to be a special case of cotransitivity of
<ℤwhich would definitely be useful elsewhere and surprisingly does not already seem to be inCubical.Data.Int, so perhaps you could prove it in more generality there?Also, this is just my opinion, but I don't like having private lemmas, and I think
maxAssoc,maxRId, andmaxIdemshould not be in a private where-block in Semilattice.Instances.NatMaxThere 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.
Thank you for the suggestion, but I don't see how it follows from cotransitivity, as it seems to have the arguments in the opposite order.
After reasoning a bit about it, I found out that this is actually a consequence of weak linearity of
<ℤ:More in general, this field can be derived from:
isStrictOrderisCommRing+MonoR<The first provides
is-prop-valuedandweak linearity, while the other two allow deriving<-o+and<-o+-cancelfrom+MonoR<using easy algebraic manipulations, such as commutativity of +.I don't think we need to remove the field from the
IsOrderedCommRingrecord, as the defintion is adapted from a standard source: the definition of an Ordered Field from the HoTT Book (Definition 11.2.7), which includes both weak linearity and the condition 0 < x + y ⇒ 0 < x ∨ 0 < y.Still, if required, I have no objection to removing the field itself.
I could add a helper function to avoid filling in this redundant field manually in most cases, while still allowing it to be specified explicitly when convenient.
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.
Yes, I think the helper function would be useful, and it is also how its done for other algebraic structures.
Also, let me explain what I meant by "special case of cotransitivity": Suppose
0 < x + y. Then by cotransitivity we have either0 < xorx < x + y, and in the second case we can subtractxon both sides to get0 < y.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.
Oh wait I feel stupid 😅 What I was calling "cotransitivity" is what you were calling "weak linearity", my bad. I didn't notice they were two different things in
Relation.Binary.BaseThere 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 just found a preprint which says that
<on the reals is cotransitive (actually meaning weakly linear under the convention used in the Cubical Agda library), so it might be that the naming is not entirely standard, assuming of course that it's not just an error.Coming back to the helper function, Here it is shown more generally that the
posSum→pos∨posfield can be derived from the others, giving an alternativemakeIsOrderedCommRing', which is then used to build the instance ofIntas OCR.However, after talking with @marcinjangrzybowski, I was thinking it might be preferable to use
lemma0<+, as it is not inductive and therefore faster when deciding which of0 < xor0 < yis satisfied. The weak linearity proof, on the other hand, relies on the trichotomy of<, which is less efficient in the current implementation.If that sounds reasonable, I think this PR could be in good shape to merge as it is. I can add the helper later on, together with some additional properties for
OrderedCommRing, in a follow-up PR.What are the maintainers’ thoughts on this? @felixwellen @mortberg