Skip to content

Commit a8916ba

Browse files
jamesmckinnaandreasabel
authored andcommitted
#453: added Dense relations and DenseLinearOrder (#2111)
1 parent e292334 commit a8916ba

File tree

8 files changed

+148
-28
lines changed

8 files changed

+148
-28
lines changed

CHANGELOG.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Non-backwards compatible changes
308308
Data.Sum.Function.Setoid
309309
Data.Sum.Function.Propositional
310310
```
311-
311+
312312
* Additionally the following proofs now use the new definitions instead of the old ones:
313313
* `Algebra.Lattice.Properties.BooleanAlgebra`
314314
* `Algebra.Properties.CommutativeMonoid.Sum`
@@ -388,8 +388,8 @@ Non-backwards compatible changes
388388
* The module `Function.Definitions` no longer has two equalities as module arguments, as
389389
they did not interact as intended with the re-exports from `Function.Definitions.(Core1/Core2)`.
390390
The latter have been removed and their definitions folded into `Function.Definitions`.
391-
392-
* In `Function.Definitions` the types of `Surjective`, `Injective` and `Surjective`
391+
392+
* In `Function.Definitions` the types of `Surjective`, `Injective` and `Surjective`
393393
have been changed from:
394394
```
395395
Surjective f = ∀ y → ∃ λ x → f x ≈₂ y
@@ -404,16 +404,16 @@ Non-backwards compatible changes
404404
```
405405
This is for several reasons: i) the new definitions compose much more easily, ii) Agda
406406
can better infer the equalities used.
407-
407+
408408
To ease backwards compatibility:
409-
- the old definitions have been moved to the new names `StrictlySurjective`,
410-
`StrictlyInverseˡ` and `StrictlyInverseʳ`.
411-
- The records in `Function.Structures` and `Function.Bundles` export proofs
412-
of these under the names `strictlySurjective`, `strictlyInverseˡ` and
413-
`strictlyInverseʳ`,
409+
- the old definitions have been moved to the new names `StrictlySurjective`,
410+
`StrictlyInverseˡ` and `StrictlyInverseʳ`.
411+
- The records in `Function.Structures` and `Function.Bundles` export proofs
412+
of these under the names `strictlySurjective`, `strictlyInverseˡ` and
413+
`strictlyInverseʳ`,
414414
- Conversion functions have been added in both directions to
415-
`Function.Consequences(.Propositional)`.
416-
415+
`Function.Consequences(.Propositional)`.
416+
417417
#### Proofs of non-zeroness/positivity/negativity as instance arguments
418418

419419
* Many numeric operations in the library require their arguments to be non-zero,
@@ -800,14 +800,14 @@ Non-backwards compatible changes
800800
### Changes to triple reasoning interface
801801

802802
* The module `Relation.Binary.Reasoning.Base.Triple` now takes an extra proof that the strict
803-
relation is irreflexive.
804-
803+
relation is irreflexive.
804+
805805
* This allows the following new proof combinator:
806806
```agda
807807
begin-contradiction : (r : x IsRelatedTo x) → {s : True (IsStrict? r)} → A
808808
```
809809
that takes a proof that a value is strictly less than itself and then applies the principle of explosion.
810-
810+
811811
* Specialised versions of this combinator are available in the following derived modules:
812812
```
813813
Data.Nat.Properties
@@ -1442,6 +1442,11 @@ Deprecated names
14421442
*-rawMonoid ↦ *-1-rawMonoid
14431443
```
14441444
1445+
* In `Data.Rational.Unnormalised.Properties`:
1446+
```
1447+
≤-steps ↦ p≤q⇒p≤r+q
1448+
```
1449+
14451450
* In `Data.Sum.Properties`:
14461451
```agda
14471452
[,]-∘-distr ↦ [,]-∘
@@ -1491,7 +1496,7 @@ Deprecated names
14911496
take-distr-map ↦ take-map
14921497
drop-distr-zipWith ↦ drop-zipWith
14931498
drop-distr-map ↦ drop-map
1494-
1499+
14951500
updateAt-id-relative ↦ updateAt-id-local
14961501
updateAt-compose-relative ↦ updateAt-∘-local
14971502
updateAt-compose ↦ updateAt-∘
@@ -2375,7 +2380,7 @@ Additions to existing modules
23752380
23762381
length-isMagmaHomomorphism : (A : Set a) → IsMagmaHomomorphism (++-rawMagma A) +-rawMagma length
23772382
length-isMonoidHomomorphism : (A : Set a) → IsMonoidHomomorphism (++-[]-rawMonoid A) +-0-rawMonoid length
2378-
2383+
23792384
take-map : take n (map f xs) ≡ map f (take n xs)
23802385
drop-map : drop n (map f xs) ≡ map f (drop n xs)
23812386
head-map : head (map f xs) ≡ Maybe.map f (head xs)
@@ -3058,6 +3063,7 @@ Additions to existing modules
30583063

30593064
* Added new definitions in `Relation.Binary.Definitions`:
30603065
```
3066+
Dense _<_ = ∀ {x y} → x < y → ∃[ z ] x < z × z < y
30613067
Cotransitive _#_ = ∀ {x y} → x # y → ∀ z → (x # z) ⊎ (z # y)
30623068
Tight _≈_ _#_ = ∀ x y → (¬ x # y → x ≈ y) × (x ≈ y → ¬ x # y)
30633069
@@ -3072,11 +3078,13 @@ Additions to existing modules
30723078

30733079
* Added new definitions in `Relation.Binary.Bundles`:
30743080
```
3081+
record DenseLinearOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
30753082
record ApartnessRelation c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
30763083
```
30773084

30783085
* Added new definitions in `Relation.Binary.Structures`:
30793086
```
3087+
record IsDenseLinearOrder (_<_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
30803088
record IsApartnessRelation (_#_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
30813089
```
30823090

@@ -3310,7 +3318,6 @@ This is a full list of proofs that have changed form to use irrelevant instance
33103318
negative<positive : ∀ {p q} → .(Negative p) → .(Positive q) → p < q
33113319
nonNeg∧nonPos⇒0 : ∀ {p} → .(NonNegative p) → .(NonPositive p) → p ≃ 0ℚᵘ
33123320
3313-
≤-steps : ∀ {p q r} → NonNegative r → p ≤ q → p ≤ r + q
33143321
p≤p+q : ∀ {p q} → NonNegative q → p ≤ p + q
33153322
p≤q+p : ∀ {p} → NonNegative p → ∀ {q} → q ≤ p + q
33163323
@@ -3468,6 +3475,13 @@ This is a full list of proofs that have changed form to use irrelevant instance
34683475
foldr-commMonoid : xs ↭ ys → foldr _∙_ ε xs ≈ foldr _∙_ ε ys
34693476
```
34703477

3478+
* Added new proof, structure, and bundle to `Data.Rational.Properties`
3479+
```agda
3480+
<-dense : Dense _<_
3481+
<-isDenseLinearOrder : IsDenseLinearOrder _≡_ _<_
3482+
<-denseLinearOrder : DenseLinearOrder 0ℓ 0ℓ 0ℓ
3483+
```
3484+
34713485
* Added new module to `Data.Rational.Unnormalised.Properties`
34723486
```agda
34733487
module ≃-Reasoning = SetoidReasoning ≃-setoid
@@ -3480,16 +3494,20 @@ This is a full list of proofs that have changed form to use irrelevant instance
34803494
≠-symmetric : Symmetric _≠_
34813495
≠-cotransitive : Cotransitive _≠_
34823496
≠⇒invertible : p ≠ q → Invertible _≃_ 1ℚᵘ _*_ (p - q)
3497+
3498+
<-dense : Dense _<_
34833499
```
34843500

34853501
* Added new structures to `Data.Rational.Unnormalised.Properties`
34863502
```agda
3503+
<-isDenseLinearOrder : IsDenseLinearOrder _≃_ _<_
34873504
+-*-isHeytingCommutativeRing : IsHeytingCommutativeRing _≃_ _≠_ _+_ _*_ -_ 0ℚᵘ 1ℚᵘ
34883505
+-*-isHeytingField : IsHeytingField _≃_ _≠_ _+_ _*_ -_ 0ℚᵘ 1ℚᵘ
34893506
```
34903507

34913508
* Added new bundles to `Data.Rational.Unnormalised.Properties`
34923509
```agda
3510+
<-denseLinearOrder : DenseLinearOrder 0ℓ 0ℓ 0ℓ
34933511
+-*-heytingCommutativeRing : HeytingCommutativeRing 0ℓ 0ℓ 0ℓ
34943512
+-*-heytingField : HeytingField 0ℓ 0ℓ 0ℓ
34953513
```

src/Data/Rational/Properties.agda

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ open import Function.Definitions using (Injective)
5151
open import Level using (0ℓ)
5252
open import Relation.Binary.Core using (_⇒_; _Preserves_⟶_; _Preserves₂_⟶_⟶_)
5353
open import Relation.Binary.Bundles
54-
using (Setoid; DecSetoid; TotalPreorder; DecTotalOrder; StrictPartialOrder; StrictTotalOrder)
54+
using (Setoid; DecSetoid; TotalPreorder; DecTotalOrder; StrictPartialOrder; StrictTotalOrder; DenseLinearOrder)
5555
open import Relation.Binary.Structures
56-
using (IsPreorder; IsTotalOrder; IsTotalPreorder; IsPartialOrder; IsDecTotalOrder; IsStrictPartialOrder; IsStrictTotalOrder)
56+
using (IsPreorder; IsTotalOrder; IsTotalPreorder; IsPartialOrder; IsDecTotalOrder; IsStrictPartialOrder; IsStrictTotalOrder; IsDenseLinearOrder)
5757
open import Relation.Binary.Definitions
58-
using (DecidableEquality; Reflexive; Transitive; Antisymmetric; Total; Decidable; Irrelevant; Irreflexive; Asymmetric; Trans; Trichotomous; tri<; tri>; tri≈; _Respectsʳ_; _Respectsˡ_; _Respects₂_)
58+
using (DecidableEquality; Reflexive; Transitive; Antisymmetric; Total; Decidable; Irrelevant; Irreflexive; Asymmetric; Dense; Trans; Trichotomous; tri<; tri>; tri≈; _Respectsʳ_; _Respectsˡ_; _Respects₂_)
5959
open import Relation.Binary.PropositionalEquality
6060
open import Relation.Binary.Morphism.Structures
6161
import Relation.Binary.Morphism.OrderMonomorphism as OrderMonomorphisms
@@ -614,6 +614,20 @@ toℚᵘ-isOrderMonomorphism-< = record
614614
<-asym : Asymmetric _<_
615615
<-asym (*<* p<q) (*<* q<p) = ℤ.<-asym p<q q<p
616616

617+
<-dense : Dense _<_
618+
<-dense {p} {q} p<q = let
619+
m , p<ᵘm , m<ᵘq = ℚᵘ.<-dense (toℚᵘ-mono-< p<q)
620+
621+
m≃m : m ≃ᵘ toℚᵘ (fromℚᵘ m)
622+
m≃m = ℚᵘ.≃-sym (toℚᵘ-fromℚᵘ m)
623+
624+
p<m : p < fromℚᵘ m
625+
p<m = toℚᵘ-cancel-< (ℚᵘ.<-respʳ-≃ m≃m p<ᵘm)
626+
627+
m<q : fromℚᵘ m < q
628+
m<q = toℚᵘ-cancel-< (ℚᵘ.<-respˡ-≃ m≃m m<ᵘq)
629+
in fromℚᵘ m , p<m , m<q
630+
617631
<-≤-trans : Trans _<_ _≤_ _<_
618632
<-≤-trans {p} {q} {r} (*<* p<q) (*≤* q≤r) = *<*
619633
(ℤ.*-cancelʳ-<-nonNeg _ (begin-strict
@@ -693,6 +707,12 @@ _>?_ = flip _<?_
693707
; compare = <-cmp
694708
}
695709

710+
<-isDenseLinearOrder : IsDenseLinearOrder _≡_ _<_
711+
<-isDenseLinearOrder = record
712+
{ isStrictTotalOrder = <-isStrictTotalOrder
713+
; dense = <-dense
714+
}
715+
696716
------------------------------------------------------------------------
697717
-- Bundles
698718

@@ -706,6 +726,11 @@ _>?_ = flip _<?_
706726
{ isStrictTotalOrder = <-isStrictTotalOrder
707727
}
708728

729+
<-denseLinearOrder : DenseLinearOrder 0ℓ 0ℓ 0ℓ
730+
<-denseLinearOrder = record
731+
{ isDenseLinearOrder = <-isDenseLinearOrder
732+
}
733+
709734
------------------------------------------------------------------------
710735
-- A specialised module for reasoning about the _≤_ and _<_ relations
711736
------------------------------------------------------------------------

src/Data/Rational/Unnormalised/Properties.agda

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
------------------------------------------------------------------------
1+
-----------------------------------------------------------------------
22
-- The Agda standard library
33
--
44
-- Properties of unnormalized Rational numbers
@@ -17,7 +17,6 @@ open import Algebra.Consequences.Propositional
1717
open import Algebra.Construct.NaturalChoice.Base
1818
import Algebra.Construct.NaturalChoice.MinMaxOp as MinMaxOp
1919
import Algebra.Lattice.Construct.NaturalChoice.MinMaxOp as LatticeMinMaxOp
20-
open import Data.Empty using (⊥-elim)
2120
open import Data.Bool.Base using (T; true; false)
2221
open import Data.Nat.Base as ℕ using (suc; pred)
2322
import Data.Nat.Properties as ℕ
@@ -36,11 +35,11 @@ import Relation.Nullary.Decidable as Dec
3635
open import Relation.Nullary.Negation using (contradiction; contraposition)
3736
open import Relation.Binary.Core using (_⇒_; _Preserves_⟶_; _Preserves₂_⟶_⟶_)
3837
open import Relation.Binary.Bundles
39-
using (Setoid; DecSetoid; Preorder; TotalPreorder; Poset; TotalOrder; DecTotalOrder; StrictPartialOrder; StrictTotalOrder)
38+
using (Setoid; DecSetoid; Preorder; TotalPreorder; Poset; TotalOrder; DecTotalOrder; StrictPartialOrder; StrictTotalOrder; DenseLinearOrder)
4039
open import Relation.Binary.Structures
41-
using (IsEquivalence; IsDecEquivalence; IsApartnessRelation; IsTotalPreorder; IsPreorder; IsPartialOrder; IsTotalOrder; IsDecTotalOrder; IsStrictPartialOrder; IsStrictTotalOrder)
40+
using (IsEquivalence; IsDecEquivalence; IsApartnessRelation; IsTotalPreorder; IsPreorder; IsPartialOrder; IsTotalOrder; IsDecTotalOrder; IsStrictPartialOrder; IsStrictTotalOrder; IsDenseLinearOrder)
4241
open import Relation.Binary.Definitions
43-
using (Reflexive; Symmetric; Transitive; Cotransitive; Tight; Decidable; Antisymmetric; Asymmetric; Total; Trans; Trichotomous; Irreflexive; Irrelevant; _Respectsˡ_; _Respectsʳ_; _Respects₂_; tri≈; tri<; tri>)
42+
using (Reflexive; Symmetric; Transitive; Cotransitive; Tight; Decidable; Antisymmetric; Asymmetric; Dense; Total; Trans; Trichotomous; Irreflexive; Irrelevant; _Respectsˡ_; _Respectsʳ_; _Respects₂_; tri≈; tri<; tri>)
4443
import Relation.Binary.Consequences as BC
4544
open import Relation.Binary.PropositionalEquality
4645
import Relation.Binary.Properties.Poset as PosetProperties
@@ -119,7 +118,7 @@ p ≃? q = Dec.map′ *≡* drop-*≡* (↥ p ℤ.* ↧ q ℤ.≟ ↥ q ℤ.*
119118
≠-cotransitive {x} {y} x≠y z with x ≃? z | z ≃? y
120119
... | no x≠z | _ = inj₁ x≠z
121120
... | yes _ | no z≠y = inj₂ z≠y
122-
... | yes x≃z | yes z≃y = ⊥-elim (x≠y (≃-trans x≃z z≃y))
121+
... | yes x≃z | yes z≃y = contradiction (≃-trans x≃z z≃y) x≠y
123122

124123
≃-isEquivalence : IsEquivalence _≃_
125124
≃-isEquivalence = record
@@ -412,6 +411,39 @@ drop-*<* (*<* pq<qp) = pq<qp
412411
<-asym : Asymmetric _<_
413412
<-asym (*<* x<y) = ℤ.<-asym x<y ∘ drop-*<*
414413

414+
<-dense : Dense _<_
415+
<-dense {p} {q} (*<* p<q) = m , p<m , m<q
416+
where
417+
open ℤ.≤-Reasoning
418+
m : ℚᵘ
419+
m = mkℚᵘ (↥ p ℤ.+ ↥ q) (pred (↧ₙ p ℕ.+ ↧ₙ q))
420+
421+
p<m : p < m
422+
p<m = *<* (begin-strict
423+
↥ p ℤ.* ↧ m
424+
≡⟨⟩
425+
↥ p ℤ.* (↧ p ℤ.+ ↧ q)
426+
≡⟨ ℤ.*-distribˡ-+ (↥ p) (↧ p) (↧ q) ⟩
427+
↥ p ℤ.* ↧ p ℤ.+ ↥ p ℤ.* ↧ q
428+
<⟨ ℤ.+-monoʳ-< (↥ p ℤ.* ↧ p) p<q ⟩
429+
↥ p ℤ.* ↧ p ℤ.+ ↥ q ℤ.* ↧ p
430+
≡˘⟨ ℤ.*-distribʳ-+ (↧ p) (↥ p) (↥ q) ⟩
431+
(↥ p ℤ.+ ↥ q) ℤ.* ↧ p
432+
≡⟨⟩
433+
↥ m ℤ.* ↧ p ∎)
434+
435+
m<q : m < q
436+
m<q = *<* (begin-strict
437+
↥ m ℤ.* ↧ q
438+
≡⟨ ℤ.*-distribʳ-+ (↧ q) (↥ p) (↥ q) ⟩
439+
↥ p ℤ.* ↧ q ℤ.+ ↥ q ℤ.* ↧ q
440+
<⟨ ℤ.+-monoˡ-< (↥ q ℤ.* ↧ q) p<q ⟩
441+
↥ q ℤ.* ↧ p ℤ.+ ↥ q ℤ.* ↧ q
442+
≡˘⟨ ℤ.*-distribˡ-+ (↥ q) (↧ p) (↧ q) ⟩
443+
↥ q ℤ.* (↧ p ℤ.+ ↧ q)
444+
≡⟨⟩
445+
↥ q ℤ.* ↧ m ∎)
446+
415447
≤-<-trans : Trans _≤_ _<_ _<_
416448
≤-<-trans {p} {q} {r} (*≤* p≤q) (*<* q<r) = *<* $
417449
ℤ.*-cancelʳ-<-nonNeg _ $ begin-strict
@@ -517,6 +549,12 @@ _>?_ = flip _<?_
517549
; compare = <-cmp
518550
}
519551

552+
<-isDenseLinearOrder : IsDenseLinearOrder _≃_ _<_
553+
<-isDenseLinearOrder = record
554+
{ isStrictTotalOrder = <-isStrictTotalOrder
555+
; dense = <-dense
556+
}
557+
520558
------------------------------------------------------------------------
521559
-- Bundles
522560

@@ -535,6 +573,11 @@ _>?_ = flip _<?_
535573
{ isStrictTotalOrder = <-isStrictTotalOrder
536574
}
537575

576+
<-denseLinearOrder : DenseLinearOrder 0ℓ 0ℓ 0ℓ
577+
<-denseLinearOrder = record
578+
{ isDenseLinearOrder = <-isDenseLinearOrder
579+
}
580+
538581
------------------------------------------------------------------------
539582
-- A specialised module for reasoning about the _≤_ and _<_ relations
540583
------------------------------------------------------------------------

src/Data/Tree/AVL/Indexed/WithK.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Data.Tree.AVL.Indexed.WithK
1515
{k r} (Key : Set k) {_<_ : Rel Key r}
1616
(isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_) where
1717

18+
strictTotalOrder : StrictTotalOrder _ _ _
1819
strictTotalOrder = record { isStrictTotalOrder = isStrictTotalOrder }
1920

2021
open import Data.Tree.AVL.Indexed strictTotalOrder as AVL hiding (Value)

src/Data/Tree/AVL/NonEmpty/Propositional.agda

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ module Data.Tree.AVL.NonEmpty.Propositional
1717

1818
open import Level
1919

20-
private strictTotalOrder = record { isStrictTotalOrder = isStrictTotalOrder}
20+
private
21+
strictTotalOrder : StrictTotalOrder _ _ _
22+
strictTotalOrder = record { isStrictTotalOrder = isStrictTotalOrder}
2123
open import Data.Tree.AVL.Value (StrictTotalOrder.Eq.setoid strictTotalOrder)
2224
import Data.Tree.AVL.NonEmpty strictTotalOrder as AVL⁺
2325

src/Relation/Binary/Bundles.agda

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,24 @@ record StrictTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) wh
299299
Please use Eq.decSetoid instead."
300300
#-}
301301

302+
record DenseLinearOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
303+
infix 4 _≈_ _<_
304+
field
305+
Carrier : Set c
306+
_≈_ : Rel Carrier ℓ₁
307+
_<_ : Rel Carrier ℓ₂
308+
isDenseLinearOrder : IsDenseLinearOrder _≈_ _<_
309+
310+
open IsDenseLinearOrder isDenseLinearOrder public
311+
using (isStrictTotalOrder; dense)
312+
313+
strictTotalOrder : StrictTotalOrder c ℓ₁ ℓ₂
314+
strictTotalOrder = record
315+
{ isStrictTotalOrder = isStrictTotalOrder
316+
}
317+
318+
open StrictTotalOrder strictTotalOrder public
319+
302320

303321
------------------------------------------------------------------------
304322
-- Apartness relations

src/Relation/Binary/Definitions.agda

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Relation.Binary.Definitions where
1313
open import Agda.Builtin.Equality using (_≡_)
1414

1515
open import Data.Maybe.Base using (Maybe)
16-
open import Data.Product.Base using (_×_)
16+
open import Data.Product.Base using (_×_; ∃-syntax)
1717
open import Data.Sum.Base using (_⊎_)
1818
open import Function.Base using (_on_; flip)
1919
open import Level
@@ -88,6 +88,11 @@ Irreflexive _≈_ _<_ = ∀ {x y} → x ≈ y → ¬ (x < y)
8888
Asymmetric : Rel A ℓ Set _
8989
Asymmetric _<_ = {x y} x < y ¬ (y < x)
9090

91+
-- Density
92+
93+
Dense : Rel A ℓ Set _
94+
Dense _<_ = {x y} x < y ∃[ z ] x < z × z < y
95+
9196
-- Generalised connex - exactly one of the two relations holds.
9297

9398
Connex : REL A B ℓ₁ REL B A ℓ₂ Set _

0 commit comments

Comments
 (0)