Skip to content

Commit c49854d

Browse files
Revamp of Data.List.Relation.Binary.Subset (#1355)
1 parent c61b159 commit c49854d

File tree

7 files changed

+657
-371
lines changed

7 files changed

+657
-371
lines changed

CHANGELOG.md

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Bug-fixes
2121
* The binary relation `_≉_` exposed by records in `Relation.Binary.Bundles` now has
2222
the correct infix precedence.
2323

24+
* Fixed the fixity of the reasoning combinators in
25+
`Data.List.Relation.Binary.Subset.(Propositional/Setoid).Properties`so that they
26+
compose properly.
27+
2428
* Added version to library name
2529

2630
Non-backwards compatible changes
@@ -33,24 +37,28 @@ Non-backwards compatible changes
3337
* The module `Algebra.Construct.Zero` and `Algebra.Module.Construct.Zero`
3438
are now level-polymorphic, each taking two implicit level parameters.
3539

36-
* Previously the definition of `_⊖_` in `Data.Integer.Base` was defined
37-
inductively as:
40+
* Previously `_⊖_` in `Data.Integer.Base` was defined inductively as:
3841
```agda
3942
_⊖_ : ℕ → ℕ → ℤ
4043
m ⊖ ℕ.zero = + m
4144
ℕ.zero ⊖ ℕ.suc n = -[1+ n ]
4245
ℕ.suc m ⊖ ℕ.suc n = m ⊖ n
4346
```
44-
which meant that the unary arguments had to be evaluated. To make it
45-
much faster it's definition has been changed to use operations on ``
46-
that are backed by builtin operations:
47+
which meant that it had to recursively evaluate its unary arguments.
48+
The definition has been changed as follows to use operations on `` that are backed
49+
by builtin operations, greatly improving its performance:
4750
```agda
4851
_⊖_ : ℕ → ℕ → ℤ
4952
m ⊖ n with m ℕ.<ᵇ n
5053
... | true = - + (n ℕ.∸ m)
5154
... | false = + (m ℕ.∸ n)
5255
```
5356

57+
* The proofs `↭⇒∼bag` and `∼bag⇒↭` have been moved from
58+
`Data.List.Relation.Binary.Permutation.Setoid.Properties`
59+
to `Data.List.Relation.Binary.BagAndSetEquality` as their current location
60+
were causing cyclic import dependencies.
61+
5462
Deprecated modules
5563
------------------
5664

@@ -97,6 +105,24 @@ Deprecated names
97105
Plus′ ↦ TransClosure
98106
```
99107

108+
* In `Data.List.Relation.Binary.Subset.Propositional.Properties`:
109+
```agda
110+
mono ↦ Any-resp-⊆
111+
map-mono ↦ map⁺
112+
concat-mono ↦ concat⁺
113+
>>=-mono ↦ >>=⁺
114+
_⊛-mono_ ↦ ⊛⁺
115+
_⊗-mono_ ↦ ⊗⁺
116+
any-mono ↦ any⁺
117+
map-with-∈-mono ↦ map-with-∈⁺
118+
filter⁺ ↦ filter-⊆
119+
```
120+
121+
* In `Data.List.Relation.Binary.Subset.Setoid.Properties`:
122+
```agda
123+
filter⁺ ↦ filter-⊆
124+
```
125+
100126
New modules
101127
-----------
102128

@@ -236,6 +262,60 @@ Other minor additions
236262
m-n≡m⊖n : + m + (- + n) ≡ m ⊖ n
237263
```
238264

265+
* Added new relations in `Data.List.Relation.Binary.Subset.(Propositional/Setoid)`:
266+
```agda
267+
xs ⊇ ys = ys ⊆ xs
268+
xs ⊉ ys = ¬ xs ⊇ ys
269+
```
270+
271+
* Added new proofs in `Data.List.Relation.Binary.Subset.Propositional.Properties`:
272+
```agda
273+
⊆-respʳ-≋ : _⊆_ Respectsʳ _≋_
274+
⊆-respˡ-≋ : _⊆_ Respectsˡ _≋_
275+
276+
↭⇒⊆ : _↭_ ⇒ _⊆_
277+
⊆-respʳ-↭ : _⊆_ Respectsʳ _↭_
278+
⊆-respˡ-↭ : _⊆_ Respectsˡ _↭_
279+
⊆-↭-isPreorder : IsPreorder _↭_ _⊆_
280+
⊆-↭-preorder : Preorder _ _ _
281+
282+
Any-resp-⊆ : P Respects _≈_ → (Any P) Respects _⊆_
283+
All-resp-⊇ : P Respects _≈_ → (All P) Respects _⊇_
284+
285+
xs⊆xs++ys : xs ⊆ xs ++ ys
286+
xs⊆ys++xs : xs ⊆ ys ++ xs
287+
++⁺ʳ : xs ⊆ ys → zs ++ xs ⊆ zs ++ ys
288+
++⁺ˡ : xs ⊆ ys → xs ++ zs ⊆ ys ++ zs
289+
++⁺ : ws ⊆ xs → ys ⊆ zs → ws ++ ys ⊆ xs ++ zs
290+
```
291+
292+
* Added new proofs in `Data.List.Relation.Binary.Subset.Propositional.Properties`:
293+
```agda
294+
↭⇒⊆ : _↭_ ⇒ _⊆_
295+
⊆-respʳ-↭ : _⊆_ Respectsʳ _↭_
296+
⊆-respˡ-↭ : _⊆_ Respectsˡ _↭_
297+
⊆-↭-isPreorder : IsPreorder _↭_ _⊆_
298+
⊆-↭-preorder : Preorder _ _ _
299+
300+
Any-resp-⊆ : (Any P) Respects _⊆_
301+
All-resp-⊇ : (All P) Respects _⊇_
302+
303+
xs⊆xs++ys : xs ⊆ xs ++ ys
304+
xs⊆ys++xs : xs ⊆ ys ++ xs
305+
++⁺ʳ : xs ⊆ ys → zs ++ xs ⊆ zs ++ ys
306+
++⁺ˡ : xs ⊆ ys → xs ++ zs ⊆ ys ++ zs
307+
```
308+
309+
* Added new proof in `Data.List.Relation.Binary.Permutation.Propositional.Properties`:
310+
```agda
311+
++↭ʳ++ : xs ++ ys ↭ xs ʳ++ ys
312+
```
313+
314+
* Added new proof in `Data.List.Relation.Binary.Permutation.Setoi.Properties`:
315+
```agda
316+
++↭ʳ++ : xs ++ ys ↭ xs ʳ++ ys
317+
```
318+
239319
* Added new definition in `Data.Nat.Base`:
240320
```agda
241321
_≤ᵇ_ : (m n : ℕ) → Bool

src/Data/List/Relation/Binary/BagAndSetEquality.agda

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ open import Data.List.Base
1717
open import Data.List.Categorical using (monad; module MonadProperties)
1818
import Data.List.Properties as LP
1919
open import Data.List.Relation.Unary.Any using (Any; here; there)
20-
open import Data.List.Relation.Unary.Any.Properties
20+
open import Data.List.Relation.Unary.Any.Properties hiding (++-comm)
2121
open import Data.List.Membership.Propositional using (_∈_)
2222
open import Data.List.Relation.Binary.Subset.Propositional.Properties
2323
using (⊆-preorder)
24+
open import Data.List.Relation.Binary.Permutation.Propositional
25+
open import Data.List.Relation.Binary.Permutation.Propositional.Properties
2426
open import Data.Product as Prod hiding (map)
2527
import Data.Product.Function.Dependent.Propositional as Σ
2628
open import Data.Sum.Base as Sum hiding (map)
@@ -558,3 +560,48 @@ drop-cons {A = A} {x} {xs} {ys} x∷xs≈x∷ys =
558560
open Inverse
559561
open P.≡-Reasoning
560562
... | ()
563+
564+
565+
566+
------------------------------------------------------------------------
567+
-- Relationships to other relations
568+
569+
module _ {a} {A : Set a} where
570+
571+
↭⇒∼bag : _↭_ ⇒ _∼[ bag ]_
572+
↭⇒∼bag xs↭ys {v} = inverse (to xs↭ys) (from xs↭ys) (from∘to xs↭ys) (to∘from xs↭ys)
573+
where
574+
to : {xs ys} xs ↭ ys v ∈ xs v ∈ ys
575+
to xs↭ys = Any-resp-↭ {A = A} xs↭ys
576+
577+
from : {xs ys} xs ↭ ys v ∈ ys v ∈ xs
578+
from xs↭ys = Any-resp-↭ (↭-sym xs↭ys)
579+
580+
from∘to : {xs ys} (p : xs ↭ ys) (q : v ∈ xs) from p (to p q) ≡ q
581+
from∘to refl v∈xs = refl
582+
from∘to (prep _ _) (here refl) = refl
583+
from∘to (prep _ p) (there v∈xs) = P.cong there (from∘to p v∈xs)
584+
from∘to (swap x y p) (here refl) = refl
585+
from∘to (swap x y p) (there (here refl)) = refl
586+
from∘to (swap x y p) (there (there v∈xs)) = P.cong (there ∘ there) (from∘to p v∈xs)
587+
from∘to (trans p₁ p₂) v∈xs
588+
rewrite from∘to p₂ (Any-resp-↭ p₁ v∈xs)
589+
| from∘to p₁ v∈xs = refl
590+
591+
to∘from : {xs ys} (p : xs ↭ ys) (q : v ∈ ys) to p (from p q) ≡ q
592+
to∘from p with from∘to (↭-sym p)
593+
... | res rewrite ↭-sym-involutive p = res
594+
595+
∼bag⇒↭ : _∼[ bag ]_ ⇒ _↭_
596+
∼bag⇒↭ {[]} eq with empty-unique {A = A} (Inv.sym eq)
597+
... | refl = refl
598+
∼bag⇒↭ {x ∷ xs} eq with ∈-∃++ (to ⟨$⟩ (here P.refl))
599+
where open Inv.Inverse (eq {x})
600+
... | zs₁ , zs₂ , p rewrite p = begin
601+
x ∷ xs <⟨ ∼bag⇒↭ (drop-cons (Inv._∘_ (comm zs₁ (x ∷ zs₂)) eq)) ⟩
602+
x ∷ (zs₂ ++ zs₁) <⟨ ++-comm zs₂ zs₁ ⟩
603+
x ∷ (zs₁ ++ zs₂) ↭˘⟨ shift x zs₁ zs₂ ⟩
604+
zs₁ ++ x ∷ zs₂ ∎
605+
where
606+
open CommutativeMonoid (commutativeMonoid bag A)
607+
open PermutationReasoning

0 commit comments

Comments
 (0)