Skip to content

Commit 4a8cd32

Browse files
[ add ] Module ⊆-Reasoning for Data.List.Relation.Binary.Sublist.* (agda#2527)
* add: `⊆-Reasoning` on the model of `Subset` * fix title comment * add: `Heterogeneous.Properties.⊆-Reasoning` * fixed `CHANGELOG` * fixed `CHANGELOG`: added missing lemma name from agda#2517 * oops: fixed `import` * reduce code duplication * refactor: pick the correct `preorder` * do not hide the useful reasoning combinators. Also the ≋-syntax needed a 4th argument. * tidied up symmetry proof * `fix-whitespace` --------- Co-authored-by: Jacques Carette <[email protected]>
1 parent 11d0a33 commit 4a8cd32

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ Additions to existing modules
418418
* In `Data.List.Relation.Binary.Sublist.Heterogeneous.Properties`:
419419
```agda
420420
Sublist-[]-universal : Universal (Sublist R [])
421+
422+
module ⊆-Reasoning (≲ : Preorder a e r)
421423
```
422424

423425
* In `Data.List.Relation.Binary.Sublist.Propositional.Properties`:
@@ -429,8 +431,11 @@ Additions to existing modules
429431
```agda
430432
[]⊆-universal : Universal ([] ⊆_)
431433
432-
concat⁺ : Sublist _⊆_ ass bss → concat ass ⊆ concat bss
433-
all⊆concat : (xss : List (List A)) → All (Sublist._⊆ concat xss) xss
434+
module ⊆-Reasoning
435+
436+
concat⁺ : Sublist _⊆_ ass bss → concat ass ⊆ concat bss
437+
xs∈xss⇒xs⊆concat[xss] : xs ∈ xss → xs ⊆ concat xss
438+
all⊆concat : (xss : List (List A)) → All (_⊆ concat xss) xss
434439
```
435440

436441
* In `Data.List.Relation.Binary.Subset.Propositional.Properties`:

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ open import Relation.Binary.Definitions
3939
open import Relation.Binary.Structures
4040
using (IsPreorder; IsPartialOrder; IsDecPartialOrder)
4141
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
42+
import Relation.Binary.Reasoning.Preorder as ≲-Reasoning
43+
open import Relation.Binary.Reasoning.Syntax
4244

4345
private
4446
variable
@@ -470,6 +472,20 @@ decPoset ER-poset = record
470472
{ isDecPartialOrder = isDecPartialOrder ER.isDecPartialOrder
471473
} where module ER = DecPoset ER-poset
472474

475+
------------------------------------------------------------------------
476+
-- Reasoning over sublists
477+
------------------------------------------------------------------------
478+
479+
module ⊆-Reasoning (≲ : Preorder a e r) where
480+
481+
open Preorderusing (module Eq)
482+
483+
open ≲-Reasoning (preorder ≲) public
484+
renaming (≲-go to ⊆-go; ≈-go to ≋-go)
485+
486+
open ⊆-syntax _IsRelatedTo_ _IsRelatedTo_ ⊆-go public
487+
open ≋-syntax _IsRelatedTo_ _IsRelatedTo_ ≋-go (Pw.symmetric Eq.sym) public
488+
473489
------------------------------------------------------------------------
474490
-- Properties of disjoint sublists
475491

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ open import Function.Base
2424
open import Function.Bundles using (_⇔_; _⤖_)
2525
open import Level
2626
open import Relation.Binary.Definitions using () renaming (Decidable to Decidable₂)
27+
import Relation.Binary.Properties.Setoid as SetoidProperties
2728
open import Relation.Binary.PropositionalEquality.Core as ≡
2829
using (_≡_; refl; sym; cong; cong₂)
30+
import Relation.Binary.Reasoning.Preorder as ≲-Reasoning
31+
open import Relation.Binary.Reasoning.Syntax
2932
open import Relation.Binary.Structures using (IsDecTotalOrder)
3033
open import Relation.Unary using (Pred; Decidable; Universal; Irrelevant)
3134
open import Relation.Nullary.Negation using (¬_)
@@ -42,6 +45,7 @@ import Data.List.Membership.Setoid as SetoidMembership
4245
open Setoid S using (_≈_; trans) renaming (Carrier to A; refl to ≈-refl)
4346
open SetoidEquality S using (_≋_; ≋-refl; ≋-reflexive; ≋-setoid)
4447
open SetoidSublist S hiding (map)
48+
open SetoidProperties S using (≈-preorder)
4549

4650

4751
private
@@ -102,6 +106,12 @@ module _ (≈-assoc : ∀ {w x y z} (p : w ≈ x) (q : x ≈ y) (r : y ≈ z)
102106
⊆-trans-assoc [] [] [] = refl
103107

104108

109+
------------------------------------------------------------------------
110+
-- Reasoning over sublists
111+
------------------------------------------------------------------------
112+
113+
module ⊆-Reasoning = HeteroProperties.⊆-Reasoning ≈-preorder
114+
105115
------------------------------------------------------------------------
106116
-- Various functions' outputs are sublists
107117
------------------------------------------------------------------------
@@ -196,9 +206,11 @@ module _ where
196206
renaming (map to map-≋; from∈ to from∈-≋)
197207

198208
xs∈xss⇒xs⊆concat[xss] : xs ∈ xss xs ⊆ concat xss
199-
xs∈xss⇒xs⊆concat[xss] {xs = xs} xs∈xss
200-
= ⊆-trans (⊆-reflexive (≋-reflexive (sym (++-identityʳ xs))))
201-
(concat⁺ (map-≋ ⊆-reflexive (from∈-≋ xs∈xss)))
209+
xs∈xss⇒xs⊆concat[xss] {xs = xs} {xss = xss} xs∈xss = begin
210+
xs ≈⟨ ≋-reflexive (++-identityʳ xs) ⟨
211+
xs ++ [] ⊆⟨ concat⁺ (map-≋ ⊆-reflexive (from∈-≋ xs∈xss)) ⟩
212+
concat xss ∎
213+
where open ⊆-Reasoning
202214

203215
all⊆concat : (xss : List (List A)) All (_⊆ concat xss) xss
204216
all⊆concat _ = tabulateₛ ≋-setoid xs∈xss⇒xs⊆concat[xss]

0 commit comments

Comments
 (0)