Skip to content
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

[ add ] Module ⊆-Reasoning for Data.List.Relation.Binary.Sublist.* #2527

Merged
merged 13 commits into from
Jan 3, 2025
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ Additions to existing modules
* In `Data.List.Relation.Binary.Sublist.Heterogeneous.Properties`:
```agda
Sublist-[]-universal : Universal (Sublist R [])

module ⊆-Reasoning (≲ : Preorder a e r)
```

* In `Data.List.Relation.Binary.Sublist.Propositional.Properties`:
Expand All @@ -429,8 +431,11 @@ Additions to existing modules
```agda
[]⊆-universal : Universal ([] ⊆_)

concat⁺ : Sublist _⊆_ ass bss → concat ass ⊆ concat bss
all⊆concat : (xss : List (List A)) → All (Sublist._⊆ concat xss) xss
module ⊆-Reasoning

concat⁺ : Sublist _⊆_ ass bss → concat ass ⊆ concat bss
xs∈xss⇒xs⊆concat[xss] : xs ∈ xss → xs ⊆ concat xss
all⊆concat : (xss : List (List A)) → All (_⊆ concat xss) xss
```

* In `Data.List.Relation.Binary.Subset.Propositional.Properties`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ open import Relation.Binary.Definitions
open import Relation.Binary.Structures
using (IsPreorder; IsPartialOrder; IsDecPartialOrder)
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
import Relation.Binary.Reasoning.Preorder as ≲-Reasoning
open import Relation.Binary.Reasoning.Syntax

private
variable
Expand Down Expand Up @@ -470,6 +472,20 @@ decPoset ER-poset = record
{ isDecPartialOrder = isDecPartialOrder ER.isDecPartialOrder
} where module ER = DecPoset ER-poset

------------------------------------------------------------------------
-- Reasoning over sublists
------------------------------------------------------------------------

module ⊆-Reasoning (≲ : Preorder a e r) where

open Preorder ≲ using (module Eq)

open ≲-Reasoning (preorder ≲) public
renaming (≲-go to ⊆-go; ≈-go to ≋-go)

open ⊆-syntax _IsRelatedTo_ _IsRelatedTo_ ⊆-go public
open ≋-syntax _IsRelatedTo_ _IsRelatedTo_ ≋-go (Pw.symmetric Eq.sym) public

------------------------------------------------------------------------
-- Properties of disjoint sublists

Expand Down
18 changes: 15 additions & 3 deletions src/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ open import Function.Base
open import Function.Bundles using (_⇔_; _⤖_)
open import Level
open import Relation.Binary.Definitions using () renaming (Decidable to Decidable₂)
import Relation.Binary.Properties.Setoid as SetoidProperties
open import Relation.Binary.PropositionalEquality.Core as ≡
using (_≡_; refl; sym; cong; cong₂)
import Relation.Binary.Reasoning.Preorder as ≲-Reasoning
open import Relation.Binary.Reasoning.Syntax
open import Relation.Binary.Structures using (IsDecTotalOrder)
open import Relation.Unary using (Pred; Decidable; Universal; Irrelevant)
open import Relation.Nullary.Negation using (¬_)
Expand All @@ -42,6 +45,7 @@ import Data.List.Membership.Setoid as SetoidMembership
open Setoid S using (_≈_; trans) renaming (Carrier to A; refl to ≈-refl)
open SetoidEquality S using (_≋_; ≋-refl; ≋-reflexive; ≋-setoid)
open SetoidSublist S hiding (map)
open SetoidProperties S using (≈-preorder)


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


------------------------------------------------------------------------
-- Reasoning over sublists
------------------------------------------------------------------------

module ⊆-Reasoning = HeteroProperties.⊆-Reasoning ≈-preorder

------------------------------------------------------------------------
-- Various functions' outputs are sublists
------------------------------------------------------------------------
Expand Down Expand Up @@ -196,9 +206,11 @@ module _ where
renaming (map to map-≋; from∈ to from∈-≋)

xs∈xss⇒xs⊆concat[xss] : xs ∈ xss → xs ⊆ concat xss
xs∈xss⇒xs⊆concat[xss] {xs = xs} xs∈xss
= ⊆-trans (⊆-reflexive (≋-reflexive (sym (++-identityʳ xs))))
(concat⁺ (map-≋ ⊆-reflexive (from∈-≋ xs∈xss)))
xs∈xss⇒xs⊆concat[xss] {xs = xs} {xss = xss} xs∈xss = begin
xs ≈⟨ ≋-reflexive (++-identityʳ xs) ⟨
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

xs ++ [] ⊆⟨ concat⁺ (map-≋ ⊆-reflexive (from∈-≋ xs∈xss)) ⟩
concat xss ∎
where open ⊆-Reasoning

all⊆concat : (xss : List (List A)) → All (_⊆ concat xss) xss
all⊆concat _ = tabulateₛ ≋-setoid xs∈xss⇒xs⊆concat[xss]
Expand Down
Loading