Skip to content

Commit 8c70a9b

Browse files
authored
New property merge-is-superlist (#1950)
1 parent 3b0f908 commit 8c70a9b

File tree

3 files changed

+84
-36
lines changed

3 files changed

+84
-36
lines changed

CHANGELOG.md

+34-27
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ Non-backwards compatible changes
606606
* It was very difficult to use the `Relation.Nullary` modules, as `Relation.Nullary`
607607
contained the basic definitions of negation, decidability etc., and the operations and
608608
proofs were smeared over `Relation.Nullary.(Negation/Product/Sum/Implication etc.)`.
609-
609+
610610
* In order to fix this:
611611
- the definition of `Dec` and `recompute` have been moved to `Relation.Nullary.Decidable.Core`
612612
- the definition of `Reflects` has been moved to `Relation.Nullary.Reflects`
@@ -623,11 +623,11 @@ Non-backwards compatible changes
623623
have been deprecated and their contents moved to `Relation.Nullary.(Negation/Reflects/Decidable)`
624624
however all their contents is re-exported by `Relation.Nullary` which is the easiest way to access
625625
it now.
626-
626+
627627
* In order to facilitate this reorganisation the following breaking moves have occured:
628628
- `¬?` has been moved from `Relation.Nullary.Negation.Core` to `Relation.Nullary.Decidable.Core`
629629
- `¬-reflects` has been moved from `Relation.Nullary.Negation.Core` to `Relation.Nullary.Reflects`.
630-
- `decidable-stable`, `excluded-middle` and `¬-drop-Dec` have been moved from `Relation.Nullary.Negation`
630+
- `decidable-stable`, `excluded-middle` and `¬-drop-Dec` have been moved from `Relation.Nullary.Negation`
631631
to `Relation.Nullary.Decidable`.
632632
- `fromDec` and `toDec` have been mvoed from `Data.Sum.Base` to `Data.Sum`.
633633
@@ -773,7 +773,7 @@ Non-backwards compatible changes
773773
```
774774
NB. It is not possible to rename or deprecate `syntax` declarations, so Agda will
775775
only issue a "Could not parse the application `begin ...` when scope checking"
776-
warning if the old combinators are used.
776+
warning if the old combinators are used.
777777

778778
* The types of the proofs `pos⇒1/pos`/`1/pos⇒pos` and `neg⇒1/neg`/`1/neg⇒neg` in
779779
`Data.Rational(.Unnormalised).Properties` have been switched, as the previous
@@ -1073,7 +1073,7 @@ Deprecated names
10731073

10741074
* In `Data.Fin.Induction`:
10751075
```
1076-
≺-Rec
1076+
≺-Rec
10771077
≺-wellFounded
10781078
≺-recBuilder
10791079
≺-rec
@@ -1082,7 +1082,7 @@ Deprecated names
10821082
As with Issue #1726 above: the deprecation of relation `_≺_` means that these definitions
10831083
associated with wf-recursion are deprecated in favour of their `_<_` counterparts.
10841084
But it's not quite sensible to say that these definiton should be *renamed* to *anything*,
1085-
least of all those counterparts... the type confusion would be intolerable.
1085+
least of all those counterparts... the type confusion would be intolerable.
10861086

10871087
* In `Data.Fin.Properties`:
10881088
```
@@ -1163,14 +1163,14 @@ Deprecated names
11631163
11641164
^-semigroup-morphism ↦ ^-isMagmaHomomorphism
11651165
^-monoid-morphism ↦ ^-isMonoidHomomorphism
1166-
1166+
11671167
pos-distrib-* ↦ pos-*
11681168
pos-+-commute ↦ pos-+
11691169
abs-*-commute ↦ abs-*
1170-
1170+
11711171
+-isAbelianGroup ↦ +-0-isAbelianGroup
11721172
```
1173-
1173+
11741174
* In `Data.List.Properties`:
11751175
```agda
11761176
map-id₂ ↦ map-id-local
@@ -1661,7 +1661,7 @@ New modules
16611661
```
16621662
Algebra.Properties.Quasigroup
16631663
```
1664-
1664+
16651665
* Properties of MiddleBolLoop
16661666
```
16671667
Algebra.Properties.MiddleBolLoop
@@ -1828,7 +1828,7 @@ Other minor changes
18281828
_MiddleFourExchange_ : Op₂ A → Op₂ A → Set _
18291829
18301830
SelfInverse : Op₁ A → Set _
1831-
1831+
18321832
LeftDividesˡ : Op₂ A → Op₂ A → Set _
18331833
LeftDividesʳ : Op₂ A → Op₂ A → Set _
18341834
RightDividesˡ : Op₂ A → Op₂ A → Set _
@@ -1864,7 +1864,7 @@ Other minor changes
18641864
_^ᵗ_ : A → ℕ → A
18651865
```
18661866

1867-
* `Algebra.Properties.Magma.Divisibility` now re-exports operations
1867+
* `Algebra.Properties.Magma.Divisibility` now re-exports operations
18681868
`_∣ˡ_`, `_∤ˡ_`, `_∣ʳ_`, `_∤ʳ_` from `Algebra.Definitions.Magma`.
18691869

18701870
* Added new proofs to `Algebra.Properties.CommutativeSemigroup`:
@@ -2046,7 +2046,7 @@ Other minor changes
20462046
* Added new functions in `Data.Integer.Base`:
20472047
```
20482048
_^_ : ℤ → ℕ → ℤ
2049-
2049+
20502050
+-0-rawGroup : Rawgroup 0ℓ 0ℓ
20512051
20522052
*-rawMagma : RawMagma 0ℓ 0ℓ
@@ -2164,7 +2164,7 @@ Other minor changes
21642164
_! : ℕ → ℕ
21652165
21662166
parity : ℕ → Parity
2167-
2167+
21682168
+-rawMagma : RawMagma 0ℓ 0ℓ
21692169
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
21702170
*-rawMagma : RawMagma 0ℓ 0ℓ
@@ -2409,10 +2409,10 @@ Other minor changes
24092409
* Added new proof to `Data.Product.Relation.Binary.Lex.Strict`
24102410
```agda
24112411
×-respectsʳ : Transitive _≈₁_ →
2412-
_<₁_ Respectsʳ _≈₁_ → _<₂_ Respectsʳ _≈₂_ → _<ₗₑₓ_ Respectsʳ _≋_
2412+
_<₁_ Respectsʳ _≈₁_ → _<₂_ Respectsʳ _≈₂_ → _<ₗₑₓ_ Respectsʳ _≋_
24132413
×-respectsˡ : Symmetric _≈₁_ → Transitive _≈₁_ →
2414-
_<₁_ Respectsˡ _≈₁_ → _<₂_ Respectsˡ _≈₂_ → _<ₗₑₓ_ Respectsˡ _≋_
2415-
×-wellFounded' : Symmetric _≈₁_ → Transitive _≈₁_ → _<₁_ Respectsʳ _≈₁_ →
2414+
_<₁_ Respectsˡ _≈₁_ → _<₂_ Respectsˡ _≈₂_ → _<ₗₑₓ_ Respectsˡ _≋_
2415+
×-wellFounded' : Symmetric _≈₁_ → Transitive _≈₁_ → _<₁_ Respectsʳ _≈₁_ →
24162416
WellFounded _<₁_ → WellFounded _<₂_ → WellFounded _<ₗₑₓ_
24172417
```
24182418

@@ -2565,7 +2565,7 @@ Other minor changes
25652565
∀ {m n} → _Respectsˡ_ (_<_ {m} {n}) _≋_
25662566
<-respectsʳ : IsPartialEquivalence _≈_ → _≺_ Respectsʳ _≈_ →
25672567
∀ {m n} → _Respectsʳ_ (_<_ {m} {n}) _≋_
2568-
<-wellFounded : Symmetric _≈_ → Transitive _≈_ → _≺_ Respectsʳ _≈_ → WellFounded _≺_ →
2568+
<-wellFounded : Symmetric _≈_ → Transitive _≈_ → _≺_ Respectsʳ _≈_ → WellFounded _≺_ →
25692569
∀ {n} → WellFounded (_<_ {n})
25702570
```
25712571

@@ -3184,14 +3184,21 @@ This is a full list of proofs that have changed form to use irrelevant instance
31843184
↭-reverse : (xs : List A) → reverse xs ↭ xs
31853185
```
31863186

3187-
* Added new file `Relation.Binary.Reasoning.Base.Apartness`
3188-
3189-
This is how to use it:
3187+
* Added new proofs to `Data.List.Relation.Binary.Sublist.Setoid.Properties`
3188+
and `Data.List.Relation.Unary.Sorted.TotalOrder.Properties`.
31903189
```agda
3191-
_ : a # d
3192-
_ = begin-apartness
3193-
a ≈⟨ a≈b ⟩
3194-
b #⟨ b#c ⟩
3195-
c ≈⟨ c≈d ⟩
3196-
d ∎
3190+
⊆-mergeˡ : ∀ xs ys → xs ⊆ merge _≤?_ xs ys
3191+
⊆-mergeʳ : ∀ xs ys → ys ⊆ merge _≤?_ xs ys
31973192
```
3193+
3194+
* Added new file `Relation.Binary.Reasoning.Base.Apartness`
3195+
3196+
This is how to use it:
3197+
```agda
3198+
_ : a # d
3199+
_ = begin-apartness
3200+
a ≈⟨ a≈b ⟩
3201+
b #⟨ b#c ⟩
3202+
c ≈⟨ c≈d ⟩
3203+
d ∎
3204+
```

src/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda

+27-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{-# OPTIONS --cubical-compatible --safe #-}
88

9-
open import Relation.Binary using (Setoid; _⇒_; _Preserves_⟶_)
9+
open import Relation.Binary using (Rel; Setoid; _⇒_; _Preserves_⟶_)
1010

1111
module Data.List.Relation.Binary.Sublist.Setoid.Properties
1212
{c ℓ} (S : Setoid c ℓ) where
@@ -20,10 +20,12 @@ open import Data.Product using (∃; _,_; proj₂)
2020
open import Function.Base
2121
open import Function.Bundles using (_⇔_; _⤖_)
2222
open import Level
23+
open import Relation.Binary using () renaming (Decidable to Decidable₂)
2324
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
25+
open import Relation.Binary.Structures using (IsDecTotalOrder)
2426
open import Relation.Unary using (Pred; Decidable; Irrelevant)
2527
open import Relation.Nullary.Negation using (¬_)
26-
open import Relation.Nullary.Decidable using (¬?)
28+
open import Relation.Nullary.Decidable using (¬?; yes; no)
2729

2830
import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
2931
import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist
@@ -203,6 +205,29 @@ module _ {as bs : List A} where
203205
reverse⁻ : reverse as ⊆ reverse bs as ⊆ bs
204206
reverse⁻ = HeteroProperties.reverse⁻
205207

208+
------------------------------------------------------------------------
209+
-- merge
210+
211+
module _ {ℓ′} {_≤_ : Rel A ℓ′} (_≤?_ : Decidable₂ _≤_) where
212+
213+
⊆-mergeˡ : xs ys xs ⊆ merge _≤?_ xs ys
214+
⊆-mergeˡ [] ys = minimum ys
215+
⊆-mergeˡ (x ∷ xs) [] = ⊆-refl
216+
⊆-mergeˡ (x ∷ xs) (y ∷ ys)
217+
with x ≤? y | ⊆-mergeˡ xs (y ∷ ys)
218+
| ⊆-mergeˡ (x ∷ xs) ys
219+
... | yes x≤y | rec | _ = ≈-refl ∷ rec
220+
... | no x≰y | _ | rec = y ∷ʳ rec
221+
222+
⊆-mergeʳ : xs ys ys ⊆ merge _≤?_ xs ys
223+
⊆-mergeʳ [] ys = ⊆-refl
224+
⊆-mergeʳ (x ∷ xs) [] = minimum (merge _≤?_ (x ∷ xs) [])
225+
⊆-mergeʳ (x ∷ xs) (y ∷ ys)
226+
with x ≤? y | ⊆-mergeʳ xs (y ∷ ys)
227+
| ⊆-mergeʳ (x ∷ xs) ys
228+
... | yes x≤y | rec | _ = x ∷ʳ rec
229+
... | no x≰y | _ | rec = ≈-refl ∷ rec
230+
206231
------------------------------------------------------------------------
207232
-- Inversion lemmas
208233
------------------------------------------------------------------------

src/Data/List/Relation/Unary/Sorted/TotalOrder/Properties.agda

+23-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ open import Data.List.Relation.Unary.AllPairs using (AllPairs)
1414
open import Data.List.Relation.Unary.Linked as Linked
1515
using (Linked; []; [-]; _∷_; _∷′_; head′; tail)
1616
import Data.List.Relation.Unary.Linked.Properties as Linked
17+
import Data.List.Relation.Binary.Sublist.Setoid as Sublist
18+
import Data.List.Relation.Binary.Sublist.Setoid.Properties as SublistProperties
1719
open import Data.List.Relation.Unary.Sorted.TotalOrder hiding (head)
20+
1821
open import Data.Maybe.Base using (just; nothing)
1922
open import Data.Maybe.Relation.Binary.Connected using (Connected; just)
2023
open import Data.Nat.Base using (ℕ; zero; suc; _<_)
24+
2125
open import Level using (Level)
2226
open import Relation.Binary hiding (Decidable)
2327
import Relation.Binary.Properties.TotalOrder as TotalOrderProperties
2428
open import Relation.Unary using (Pred; Decidable)
2529
open import Relation.Nullary.Decidable using (yes; no)
30+
2631
private
2732
variable
2833
a b p ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level
@@ -101,30 +106,41 @@ module _ (O : TotalOrder a ℓ₁ ℓ₂) where
101106
-- merge
102107

103108
module _ (DO : DecTotalOrder a ℓ₁ ℓ₂) where
104-
open DecTotalOrder DO renaming (totalOrder to O)
109+
open DecTotalOrder DO using (_≤_; _≤?_) renaming (totalOrder to O)
105110
open TotalOrderProperties O using (≰⇒≥)
106111

107112
private
108113
merge-con : {v xs ys}
109114
Connected _≤_ (just v) (head xs)
110115
Connected _≤_ (just v) (head ys)
111116
Connected _≤_ (just v) (head (merge _≤?_ xs ys))
112-
merge-con {xs = []} {[]} cxs cys = cys
113-
merge-con {xs = []} {y ∷ ys} cxs cys = cys
117+
merge-con {xs = []} cxs cys = cys
114118
merge-con {xs = x ∷ xs} {[]} cxs cys = cxs
115119
merge-con {xs = x ∷ xs} {y ∷ ys} cxs cys with x ≤? y
116120
... | yes x≤y = cxs
117121
... | no x≰y = cys
118122

119123
merge⁺ : {xs ys} Sorted O xs Sorted O ys Sorted O (merge _≤?_ xs ys)
120-
merge⁺ {[]} {[]} rxs rys = []
121-
merge⁺ {[]} {x ∷ ys} rxs rys = rys
124+
merge⁺ {[]} rxs rys = rys
122125
merge⁺ {x ∷ xs} {[]} rxs rys = rxs
123-
merge⁺ {x ∷ xs} {y ∷ ys} rxs rys with x ≤? y |
124-
merge⁺ (Linked.tail rxs) rys | merge⁺ rxs (Linked.tail rys)
126+
merge⁺ {x ∷ xs} {y ∷ ys} rxs rys
127+
with x ≤? y | merge⁺ (Linked.tail rxs) rys
128+
| merge⁺ rxs (Linked.tail rys)
125129
... | yes x≤y | rec | _ = merge-con (head′ rxs) (just x≤y) ∷′ rec
126130
... | no x≰y | _ | rec = merge-con (just (≰⇒≥ x≰y)) (head′ rys) ∷′ rec
127131

132+
-- Reexport ⊆-mergeˡʳ
133+
134+
S = Preorder.Eq.setoid (DecTotalOrder.preorder DO)
135+
open Sublist S using (_⊆_)
136+
module SP = SublistProperties S
137+
138+
⊆-mergeˡ : xs ys xs ⊆ merge _≤?_ xs ys
139+
⊆-mergeˡ = SP.⊆-mergeˡ _≤?_
140+
141+
⊆-mergeʳ : xs ys ys ⊆ merge _≤?_ xs ys
142+
⊆-mergeʳ = SP.⊆-mergeʳ _≤?_
143+
128144
------------------------------------------------------------------------
129145
-- filter
130146

0 commit comments

Comments
 (0)