diff --git a/.github/workflows/ci-ubuntu.yml b/.github/workflows/ci-ubuntu.yml index 93c23f6fe7..56b4c88637 100644 --- a/.github/workflows/ci-ubuntu.yml +++ b/.github/workflows/ci-ubuntu.yml @@ -32,7 +32,7 @@ on: ## To be experimented with again in the future to see if things have ## gotten better. ## -## We use `v1-install` rather than `install` as Agda as a community +## We mostly use `v1-install` rather than `install` as Agda as a community ## hasn't figured out how to manage dependencies with the new local ## style builds (see agda/agda#4627 for details). Once this is resolved ## we should upgrade to `install`. @@ -50,8 +50,8 @@ on: env: GHC_VERSION: 9.8.2 CABAL_VERSION: 3.10.3.0 - CABAL_INSTALL: cabal v1-install --ghc-options='-O1 +RTS -M6G -RTS' - # CABAL_INSTALL: cabal install --overwrite-policy=always --ghc-options='-O1 +RTS -M6G -RTS' + CABAL_V1_INSTALL: cabal v1-install --ghc-options='-O1 +RTS -M6G -RTS' + CABAL_INSTALL: cabal install --overwrite-policy=always --ghc-options='-O1 +RTS -M6G -RTS' AGDA: agda -Werror +RTS -M5G -H3.5G -A128M -RTS -i. -isrc -idoc jobs: @@ -121,13 +121,15 @@ jobs: cabal-update: true - name: Put cabal programs in PATH - run: echo "~/.cabal/bin" >> "${GITHUB_PATH}" + run: echo ~/.cabal/bin >> "${GITHUB_PATH}" - name: Install alex & happy if: steps.cache-cabal.outputs.cache-hit != 'true' run: | ${{ env.CABAL_INSTALL }} alex ${{ env.CABAL_INSTALL }} happy + # happy>=2.0 cannot be v1-installed: https://github.com/haskell/happy/issues/315 + # Since we only need the executable, it is fine to use v2-install here. - name: Download and install Agda from github if: steps.cache-cabal.outputs.cache-hit != 'true' @@ -137,7 +139,7 @@ jobs: git checkout ${{ env.AGDA_COMMIT }} mkdir -p doc touch doc/user-manual.pdf - ${{ env.CABAL_INSTALL }} + ${{ env.CABAL_V1_INSTALL }} cd .. ######################################################################## @@ -167,7 +169,7 @@ jobs: - name: Golden testing run: | - ${{ env.CABAL_INSTALL }} clock + ${{ env.CABAL_V1_INSTALL }} clock make testsuite INTERACTIVE='' AGDA_EXEC='~/.cabal/bin/agda' diff --git a/CHANGELOG.md b/CHANGELOG.md index af16162afa..45e612b514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,13 @@ Deprecated names normalise-correct ↦ Algebra.Solver.Monoid.Normal.correct ``` +* In `Data.List.Relation.Binary.Permutation.Setoid.Properties`: + ```agda + split ↦ ↭-split + ``` + with a more informative type (see below). + ``` + * In `Data.Vec.Properties`: ```agda ++-assoc _ ↦ ++-assoc-eqFree @@ -98,6 +105,11 @@ New modules Data.List.Relation.Unary.All.Properties.Core ``` +* `Data.List.Relation.Binary.Disjoint.Propositional.Properties`: + Propositional counterpart to `Data.List.Relation.Binary.Disjoint.Setoid.Properties` + +* `Data.List.Relation.Binary.Permutation.Propositional.Properties.WithK` + Additions to existing modules ----------------------------- @@ -120,19 +132,62 @@ Additions to existing modules * In `Data.List.Membership.Setoid.Properties`: ```agda - Any-∈-swap : Any (_∈ ys) xs → Any (_∈ xs) ys - All-∉-swap : All (_∉ ys) xs → All (_∉ xs) ys + ∉⇒All[≉] : x ∉ xs → All (x ≉_) xs + All[≉]⇒∉ : All (x ≉_) xs → x ∉ xs + Any-∈-swap : Any (_∈ ys) xs → Any (_∈ xs) ys + All-∉-swap : All (_∉ ys) xs → All (_∉ xs) ys + ∈-map∘filter⁻ : y ∈₂ map f (filter P? xs) → ∃[ x ] x ∈₁ xs × y ≈₂ f x × P x + ∈-map∘filter⁺ : f Preserves _≈₁_ ⟶ _≈₂_ → + ∃[ x ] x ∈₁ xs × y ≈₂ f x × P x → + y ∈₂ map f (filter P? xs) + ∈-concatMap⁺ : Any ((y ∈_) ∘ f) xs → y ∈ concatMap f xs + ∈-concatMap⁻ : y ∈ concatMap f xs → Any ((y ∈_) ∘ f) xs + ∉[] : x ∉ [] + deduplicate-∈⇔ : _≈_ Respectsʳ (flip R) → z ∈ xs ⇔ z ∈ deduplicate R? xs + ``` + +* In `Data.List.Membership.Propositional.Properties`: + ```agda + ∈-AllPairs₂ : AllPairs R xs → x ∈ xs → y ∈ xs → x ≡ y ⊎ R x y ⊎ R y x + ∈-map∘filter⁻ : y ∈ map f (filter P? xs) → (∃[ x ] x ∈ xs × y ≡ f x × P x) + ∈-map∘filter⁺ : (∃[ x ] x ∈ xs × y ≡ f x × P x) → y ∈ map f (filter P? xs) + ∈-concatMap⁺ : Any ((y ∈_) ∘ f) xs → y ∈ concatMap f xs + ∈-concatMap⁻ : y ∈ concatMap f xs → Any ((y ∈_) ∘ f) xs + ++-∈⇔ : v ∈ xs ++ ys ⇔ (v ∈ xs ⊎ v ∈ ys) + []∉map∷ : [] ∉ map (x ∷_) xss + map∷-decomp∈ : (x ∷ xs) ∈ map (y ∷_) xss → x ≡ y × xs ∈ xss + map∷-decomp : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × y ∷ ys ≡ xs + ∈-map∷⁻ : xs ∈ map (x ∷_) xss → x ∈ xs + ∉[] : x ∉ [] + deduplicate-∈⇔ : z ∈ xs ⇔ z ∈ deduplicate _≈?_ xs + ``` + +* In `Data.List.Membership.Propositional.Properties.WithK`: + ```agda + unique∧set⇒bag : Unique xs → Unique ys → xs ∼[ set ] ys → xs ∼[ bag ] ys ``` * In `Data.List.Properties`: ```agda - product≢0 : All NonZero ns → NonZero (product ns) - ∈⇒≤product : All NonZero ns → n ∈ ns → n ≤ product ns + product≢0 : All NonZero ns → NonZero (product ns) + ∈⇒≤product : All NonZero ns → n ∈ ns → n ≤ product ns + concatMap-++ : concatMap f (xs ++ ys) ≡ concatMap f xs ++ concatMap f ys ``` -* In `Data.List.Relation.Unary.All`: +* In `Data.List.Relation.Unary.Any.Properties`: ```agda - search : Decidable P → ∀ xs → All (∁ P) xs ⊎ Any P xs + concatMap⁺ : Any (Any P ∘ f) xs → Any P (concatMap f xs) + concatMap⁻ : Any P (concatMap f xs) → Any (Any P ∘ f) xs + ``` + +* In `Data.List.Relation.Unary.Unique.Setoid.Properties`: + ```agda + Unique[x∷xs]⇒x∉xs : Unique S (x ∷ xs) → x ∉ xs + ``` + +* In `Data.List.Relation.Unary.Unique.Propositional.Properties`: + ```agda + Unique[x∷xs]⇒x∉xs : Unique (x ∷ xs) → x ∉ xs ``` * In `Data.List.Relation.Binary.Equality.Setoid`: @@ -141,12 +196,105 @@ Additions to existing modules ++⁺ˡ : ∀ zs → ws ≋ xs → ws ++ zs ≋ xs ++ zs ``` +* In `Data.List.Relation.Binary.Permutation.Homogeneous`: + ```agda + steps : Permutation R xs ys → ℕ + ``` + +* In `Data.List.Relation.Binary.Permutation.Propositional`: + constructor aliases + ```agda + ↭-refl : Reflexive _↭_ + ↭-prep : ∀ x → xs ↭ ys → x ∷ xs ↭ x ∷ ys + ↭-swap : ∀ x y → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys + ``` + and properties + ```agda + ↭-reflexive-≋ : _≋_ ⇒ _↭_ + ↭⇒↭ₛ : _↭_ ⇒ _↭ₛ_ + ↭ₛ⇒↭ : _↭ₛ_ ⇒ _↭_ + ``` + where `_↭ₛ_` is the `Setoid (setoid _)` instance of `Permutation` + +* In `Data.List.Relation.Binary.Permutation.Propositional.Properties`: + ```agda + Any-resp-[σ∘σ⁻¹] : (σ : xs ↭ ys) (iy : Any P ys) → + Any-resp-↭ (trans (↭-sym σ) σ) iy ≡ iy + ∈-resp-[σ∘σ⁻¹] : (σ : xs ↭ ys) (iy : y ∈ ys) → + ∈-resp-↭ (trans (↭-sym σ) σ) iy ≡ iy + product-↭ : product Preserves _↭_ ⟶ _≡_ + ``` + +* In `Data.List.Relation.Binary.Permutation.Setoid`: + ```agda + ↭-reflexive-≋ : _≋_ ⇒ _↭_ + ↭-transˡ-≋ : LeftTrans _≋_ _↭_ + ↭-transʳ-≋ : RightTrans _↭_ _≋_ + ↭-trans′ : Transitive _↭_ + ``` + +* In `Data.List.Relation.Binary.Permutation.Setoid.Properties`: + ```agda + ↭-split : xs ↭ (as ++ [ v ] ++ bs) → + ∃₂ λ ps qs → xs ≋ (ps ++ [ v ] ++ qs) × (ps ++ qs) ↭ (as ++ bs) + drop-∷ : x ∷ xs ↭ x ∷ ys → xs ↭ ys + ``` + * In `Data.List.Relation.Binary.Pointwise`: ```agda ++⁺ʳ : Reflexive R → ∀ xs → (xs ++_) Preserves (Pointwise R) ⟶ (Pointwise R) ++⁺ˡ : Reflexive R → ∀ zs → (_++ zs) Preserves (Pointwise R) ⟶ (Pointwise R) ``` +* In `Data.List.Relation.Unary.All`: + ```agda + search : Decidable P → ∀ xs → All (∁ P) xs ⊎ Any P xs + +* In `Data.List.Relation.Binary.Subset.Setoid.Properties`: + ```agda + ∷⊈[] : x ∷ xs ⊈ [] + ⊆∷⇒∈∨⊆ : xs ⊆ y ∷ ys → y ∈ xs ⊎ xs ⊆ ys + ⊆∷∧∉⇒⊆ : xs ⊆ y ∷ ys → y ∉ xs → xs ⊆ ys + ``` + +* In `Data.List.Relation.Binary.Subset.Propositional.Properties`: + ```agda + ∷⊈[] : x ∷ xs ⊈ [] + ⊆∷⇒∈∨⊆ : xs ⊆ y ∷ ys → y ∈ xs ⊎ xs ⊆ ys + ⊆∷∧∉⇒⊆ : xs ⊆ y ∷ ys → y ∉ xs → xs ⊆ ys + ``` + +* In `Data.List.Relation.Binary.Subset.Propositional.Properties`: + ```agda + concatMap⁺ : xs ⊆ ys → concatMap f xs ⊆ concatMap f ys + ``` + +* In `Data.List.Relation.Binary.Sublist.Heterogeneous.Properties`: + ```agda + Sublist-[]-universal : Universal (Sublist R []) + ``` + +* In `Data.List.Relation.Binary.Sublist.Setoid.Properties`: + ```agda + []⊆-universal : Universal ([] ⊆_) + ``` + +* In `Data.List.Relation.Binary.Disjoint.Setoid.Properties`: + ```agda + deduplicate⁺ : Disjoint S xs ys → Disjoint S (deduplicate _≟_ xs) (deduplicate _≟_ ys) + ``` + +* In `Data.List.Relation.Binary.Disjoint.Propositional.Properties`: + ```agda + deduplicate⁺ : Disjoint xs ys → Disjoint (deduplicate _≟_ xs) (deduplicate _≟_ ys) + ``` + +* In `Data.List.Relation.Binary.Permutation.Propositional.Properties.WithK`: + ```agda + dedup-++-↭ : Disjoint xs ys → + deduplicate _≟_ (xs ++ ys) ↭ deduplicate _≟_ xs ++ deduplicate _≟_ ys + ``` + * In `Data.Maybe.Properties`: ```agda maybe′-∘ : ∀ f g → f ∘ (maybe′ g b) ≗ maybe′ (f ∘ g) (f b) @@ -188,6 +336,17 @@ Additions to existing modules ∃-≡ : ∀ (P : A → Set b) {x} → P x ↔ (∃[ y ] y ≡ x × P y) ``` +* In `Relation.Binary.Construct.Interior.Symmetric`: + ```agda + decidable : Decidable R → Decidable (SymInterior R) + ``` + and for `Reflexive` and `Transitive` relations `R`: + ```agda + isDecEquivalence : Decidable R → IsDecEquivalence (SymInterior R) + isDecPartialOrder : Decidable R → IsDecPartialOrder (SymInterior R) R + decPoset : Decidable R → DecPoset _ _ _ + ``` + * In `Relation.Nullary.Decidable`: ```agda does-⇔ : A ⇔ B → (a? : Dec A) → (b? : Dec B) → does a? ≡ does b? diff --git a/src/Data/List/Membership/Propositional/Properties.agda b/src/Data/List/Membership/Propositional/Properties.agda index 03e31d8aae..39204f19e2 100644 --- a/src/Data/List/Membership/Propositional/Properties.agda +++ b/src/Data/List/Membership/Propositional/Properties.agda @@ -24,16 +24,16 @@ open import Data.List.Relation.Unary.Any.Properties open import Data.Nat.Base using (ℕ; suc; s≤s; _≤_; _<_; _≰_) open import Data.Nat.Properties using (suc-injective; m≤n⇒m≤1+n; _≤?_; <⇒≢; ≰⇒>) -open import Data.Product.Base using (∃; ∃₂; _×_; _,_) +open import Data.Product.Base using (∃; ∃₂; _×_; _,_; ∃-syntax; -,_; map₂) open import Data.Product.Properties using (×-≡,≡↔≡) open import Data.Product.Function.NonDependent.Propositional using (_×-cong_) import Data.Product.Function.Dependent.Propositional as Σ open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂) open import Effect.Monad using (RawMonad) -open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_) +open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_; _∋_) open import Function.Definitions using (Injective) import Function.Related.Propositional as Related -open import Function.Bundles using (_↔_; _↣_; Injection) +open import Function.Bundles using (_↔_; _↣_; Injection; _⇔_; mk⇔) open import Function.Related.TypeIsomorphisms using (×-comm; ∃∃↔∃∃) open import Function.Construct.Identity using (↔-id) open import Level using (Level) @@ -55,6 +55,9 @@ private variable ℓ : Level A B C : Set ℓ + x y v : A + xs ys : List A + xss : List (List A) ------------------------------------------------------------------------ -- Publicly re-export properties from Core @@ -64,10 +67,10 @@ open import Data.List.Membership.Propositional.Properties.Core public ------------------------------------------------------------------------ -- Equality -∈-resp-≋ : ∀ {x : A} → (x ∈_) Respects _≋_ +∈-resp-≋ : (x ∈_) Respects _≋_ ∈-resp-≋ = Membership.∈-resp-≋ (≡.setoid _) -∉-resp-≋ : ∀ {x : A} → (x ∉_) Respects _≋_ +∉-resp-≋ : (x ∉_) Respects _≋_ ∉-resp-≋ = Membership.∉-resp-≋ (≡.setoid _) ------------------------------------------------------------------------ @@ -96,14 +99,14 @@ map-mapWith∈ = Membership.map-mapWith∈ (≡.setoid _) module _ (f : A → B) where - ∈-map⁺ : ∀ {x xs} → x ∈ xs → f x ∈ map f xs + ∈-map⁺ : x ∈ xs → f x ∈ map f xs ∈-map⁺ = Membership.∈-map⁺ (≡.setoid A) (≡.setoid B) (cong f) - ∈-map⁻ : ∀ {y xs} → y ∈ map f xs → ∃ λ x → x ∈ xs × y ≡ f x + ∈-map⁻ : y ∈ map f xs → ∃ λ x → x ∈ xs × y ≡ f x ∈-map⁻ = Membership.∈-map⁻ (≡.setoid A) (≡.setoid B) - map-∈↔ : ∀ {y xs} → (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ map f xs - map-∈↔ {y} {xs} = + map-∈↔ : (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ map f xs + map-∈↔ {xs} {y} = (∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Any↔ ⟩ Any (λ x → y ≡ f x) xs ↔⟨ map↔ ⟩ y ∈ List.map f xs ∎ @@ -114,7 +117,7 @@ module _ (f : A → B) where module _ {v : A} where - ∈-++⁺ˡ : ∀ {xs ys} → v ∈ xs → v ∈ xs ++ ys + ∈-++⁺ˡ : v ∈ xs → v ∈ xs ++ ys ∈-++⁺ˡ = Membership.∈-++⁺ˡ (≡.setoid A) ∈-++⁺ʳ : ∀ xs {ys} → v ∈ ys → v ∈ xs ++ ys @@ -123,10 +126,13 @@ module _ {v : A} where ∈-++⁻ : ∀ xs {ys} → v ∈ xs ++ ys → (v ∈ xs) ⊎ (v ∈ ys) ∈-++⁻ = Membership.∈-++⁻ (≡.setoid A) + ++-∈⇔ : v ∈ xs ++ ys ⇔ (v ∈ xs ⊎ v ∈ ys) + ++-∈⇔ = mk⇔ (∈-++⁻ _) Sum.[ ∈-++⁺ˡ , ∈-++⁺ʳ _ ] + ∈-insert : ∀ xs {ys} → v ∈ xs ++ [ v ] ++ ys ∈-insert xs = Membership.∈-insert (≡.setoid A) xs refl - ∈-∃++ : ∀ {xs} → v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs + ∈-∃++ : v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs ∈-∃++ v∈xs with ys , zs , _ , refl , eq ← Membership.∈-∃++ (≡.setoid A) v∈xs = ys , zs , ≋⇒≡ eq @@ -136,7 +142,7 @@ module _ {v : A} where module _ {v : A} where - ∈-concat⁺ : ∀ {xss} → Any (v ∈_) xss → v ∈ concat xss + ∈-concat⁺ : Any (v ∈_) xss → v ∈ concat xss ∈-concat⁺ = Membership.∈-concat⁺ (≡.setoid A) ∈-concat⁻ : ∀ xss → v ∈ concat xss → Any (v ∈_) xss @@ -151,8 +157,7 @@ module _ {v : A} where let xs , v∈xs , xs∈xss = Membership.∈-concat⁻′ (≡.setoid A) xss v∈c in xs , v∈xs , Any.map ≋⇒≡ xs∈xss - concat-∈↔ : ∀ {xss : List (List A)} → - (∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss + concat-∈↔ : (∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss concat-∈↔ {xss} = (∃ λ xs → v ∈ xs × xs ∈ xss) ↔⟨ Σ.cong (↔-id _) $ ×-comm _ _ ⟩ (∃ λ xs → xs ∈ xss × v ∈ xs) ↔⟨ Any↔ ⟩ @@ -160,6 +165,19 @@ module _ {v : A} where v ∈ concat xss ∎ where open Related.EquationalReasoning +------------------------------------------------------------------------ +-- concatMap + +module _ (f : A → List B) {xs y} where + + private Sᴬ = ≡.setoid A; Sᴮ = ≡.setoid B + + ∈-concatMap⁺ : Any ((y ∈_) ∘ f) xs → y ∈ concatMap f xs + ∈-concatMap⁺ = Membership.∈-concatMap⁺ Sᴬ Sᴮ + + ∈-concatMap⁻ : y ∈ concatMap f xs → Any ((y ∈_) ∘ f) xs + ∈-concatMap⁻ = Membership.∈-concatMap⁻ Sᴬ Sᴮ + ------------------------------------------------------------------------ -- cartesianProductWith @@ -246,12 +264,25 @@ module _ {n} {f : Fin n → A} where module _ {p} {P : A → Set p} (P? : Decidable P) where - ∈-filter⁺ : ∀ {x xs} → x ∈ xs → P x → x ∈ filter P? xs + ∈-filter⁺ : x ∈ xs → P x → x ∈ filter P? xs ∈-filter⁺ = Membership.∈-filter⁺ (≡.setoid A) P? (≡.resp P) - ∈-filter⁻ : ∀ {v xs} → v ∈ filter P? xs → v ∈ xs × P v + ∈-filter⁻ : v ∈ filter P? xs → v ∈ xs × P v ∈-filter⁻ = Membership.∈-filter⁻ (≡.setoid A) P? (≡.resp P) +------------------------------------------------------------------------ +-- map∘filter + +module _ (f : A → B) {p} {P : A → Set p} (P? : Decidable P) {f xs y} where + + private Sᴬ = ≡.setoid A; Sᴮ = ≡.setoid B; respP = ≡.resp P + + ∈-map∘filter⁻ : y ∈ map f (filter P? xs) → (∃[ x ] x ∈ xs × y ≡ f x × P x) + ∈-map∘filter⁻ = Membership.∈-map∘filter⁻ Sᴬ Sᴮ P? respP + + ∈-map∘filter⁺ : (∃[ x ] x ∈ xs × y ≡ f x × P x) → y ∈ map f (filter P? xs) + ∈-map∘filter⁺ = Membership.∈-map∘filter⁺ Sᴬ Sᴮ P? respP (cong f) + ------------------------------------------------------------------------ -- derun and deduplicate @@ -268,8 +299,13 @@ module _ (_≈?_ : DecidableEquality A) where ∈-derun⁺ : ∀ {xs z} → z ∈ xs → z ∈ derun _≈?_ xs ∈-derun⁺ z∈xs = Membership.∈-derun⁺ (≡.setoid A) _≈?_ (flip trans) z∈xs + private resp≈ = λ {c b a : A} (c≡b : c ≡ b) (a≡b : a ≡ b) → trans a≡b (sym c≡b) + ∈-deduplicate⁺ : ∀ {xs z} → z ∈ xs → z ∈ deduplicate _≈?_ xs - ∈-deduplicate⁺ z∈xs = Membership.∈-deduplicate⁺ (≡.setoid A) _≈?_ (λ c≡b a≡b → trans a≡b (sym c≡b)) z∈xs + ∈-deduplicate⁺ z∈xs = Membership.∈-deduplicate⁺ (≡.setoid A) _≈?_ resp≈ z∈xs + + deduplicate-∈⇔ : ∀ {xs z} → z ∈ xs ⇔ z ∈ deduplicate _≈?_ xs + deduplicate-∈⇔ = Membership.deduplicate-∈⇔ (≡.setoid A) _≈?_ resp≈ ------------------------------------------------------------------------ -- _>>=_ @@ -310,13 +346,13 @@ module _ (_≈?_ : DecidableEquality A) where ------------------------------------------------------------------------ -- length -∈-length : ∀ {x : A} {xs} → x ∈ xs → 0 < length xs +∈-length : x ∈ xs → 0 < length xs ∈-length = Membership.∈-length (≡.setoid _) ------------------------------------------------------------------------ -- lookup -∈-lookup : ∀ {xs : List A} i → lookup xs i ∈ xs +∈-lookup : ∀ i → lookup xs i ∈ xs ∈-lookup {xs = xs} i = Membership.∈-lookup (≡.setoid _) xs i ------------------------------------------------------------------------ @@ -337,7 +373,7 @@ module _ {_•_ : Op₂ A} where ------------------------------------------------------------------------ -- inits -[]∈inits : ∀ {a} {A : Set a} (as : List A) → [] ∈ inits as +[]∈inits : (as : List A) → [] ∈ inits as []∈inits _ = here refl ------------------------------------------------------------------------ @@ -401,3 +437,39 @@ there-injective-≢∈ : ∀ {xs} {x y z : A} {x∈xs : x ∈ xs} {y∈xs : y there {x = z} x∈xs ≢∈ there y∈xs → x∈xs ≢∈ y∈xs there-injective-≢∈ neq refl eq = neq refl (≡.cong there eq) + +------------------------------------------------------------------------ +-- AllPairs + +open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_) +import Data.List.Relation.Unary.All as All + +module _ {R : A → A → Set ℓ} where + ∈-AllPairs₂ : ∀ {xs x y} → AllPairs R xs → x ∈ xs → y ∈ xs → x ≡ y ⊎ R x y ⊎ R y x + ∈-AllPairs₂ (_ ∷ _) (here refl) (here refl) = inj₁ refl + ∈-AllPairs₂ (p ∷ _) (here refl) (there y∈) = inj₂ $ inj₁ $ All.lookup p y∈ + ∈-AllPairs₂ (p ∷ _) (there x∈) (here refl) = inj₂ $ inj₂ $ All.lookup p x∈ + ∈-AllPairs₂ (_ ∷ ps) (there x∈) (there y∈) = ∈-AllPairs₂ ps x∈ y∈ + +------------------------------------------------------------------------ +-- nested lists + +[]∉map∷ : (List A ∋ []) ∉ map (x ∷_) xss +[]∉map∷ {xss = _ ∷ _} (there p) = []∉map∷ p + +map∷-decomp∈ : (List A ∋ x ∷ xs) ∈ map (y ∷_) xss → x ≡ y × xs ∈ xss +map∷-decomp∈ {xss = _ ∷ _} = λ where + (here refl) → refl , here refl + (there p) → map₂ there $ map∷-decomp∈ p + +map∷-decomp : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × y ∷ ys ≡ xs +map∷-decomp {xss = _ ∷ _} (here refl) = -, here refl , refl +map∷-decomp {xs = []} {xss = _ ∷ _} (there xs∈) = contradiction xs∈ []∉map∷ +map∷-decomp {xs = x ∷ xs} {xss = _ ∷ _} (there xs∈) = + let eq , p = map∷-decomp∈ xs∈ + in -, there p , cong (_∷ _) (sym eq) + +∈-map∷⁻ : xs ∈ map (x ∷_) xss → x ∈ xs +∈-map∷⁻ {xss = _ ∷ _} = λ where + (here refl) → here refl + (there p) → ∈-map∷⁻ p diff --git a/src/Data/List/Membership/Propositional/Properties/Core.agda b/src/Data/List/Membership/Propositional/Properties/Core.agda index 5c77e40b96..65485abb0e 100644 --- a/src/Data/List/Membership/Propositional/Properties/Core.agda +++ b/src/Data/List/Membership/Propositional/Properties/Core.agda @@ -12,7 +12,7 @@ module Data.List.Membership.Propositional.Properties.Core where -open import Data.List.Base using (List) +open import Data.List.Base using (List; []) open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any as Any using (Any; here; there) open import Data.Product.Base as Product using (_,_; ∃; _×_) @@ -30,6 +30,12 @@ private x : A xs : List A +------------------------------------------------------------------------ +-- Basics + +∉[] : x ∉ [] +∉[] () + ------------------------------------------------------------------------ -- find satisfies a simple equality when the predicate is a -- propositional equality. diff --git a/src/Data/List/Membership/Propositional/Properties/WithK.agda b/src/Data/List/Membership/Propositional/Properties/WithK.agda index a86f23a8ea..656ec11dae 100644 --- a/src/Data/List/Membership/Propositional/Properties/WithK.agda +++ b/src/Data/List/Membership/Propositional/Properties/WithK.agda @@ -9,17 +9,31 @@ module Data.List.Membership.Propositional.Properties.WithK where +open import Level using (Level) +open import Function.Bundles using (Equivalence) open import Data.List.Base open import Data.List.Relation.Unary.Unique.Propositional open import Data.List.Membership.Propositional import Data.List.Membership.Setoid.Properties as Membership +open import Data.List.Relation.Binary.BagAndSetEquality using (_∼[_]_; set; bag) +open import Data.Product using (_,_) open import Relation.Unary using (Irrelevant) open import Relation.Binary.PropositionalEquality.Properties as ≡ -open import Relation.Binary.PropositionalEquality.WithK +open import Relation.Binary.PropositionalEquality.WithK using (≡-irrelevant) + +private + variable + a : Level + A : Set a + xs ys : List A ------------------------------------------------------------------------ -- Irrelevance -unique⇒irrelevant : ∀ {a} {A : Set a} {xs : List A} → - Unique xs → Irrelevant (_∈ xs) +unique⇒irrelevant : Unique xs → Irrelevant (_∈ xs) unique⇒irrelevant = Membership.unique⇒irrelevant (≡.setoid _) ≡-irrelevant + +unique∧set⇒bag : Unique xs → Unique ys → xs ∼[ set ] ys → xs ∼[ bag ] ys +unique∧set⇒bag p p′ eq = record + { Equivalence eq + ; inverse = (λ _ → unique⇒irrelevant p′ _ _) , (λ _ → unique⇒irrelevant p _ _) } diff --git a/src/Data/List/Membership/Setoid/Properties.agda b/src/Data/List/Membership/Setoid/Properties.agda index 76bbd8beaf..988c01a07e 100644 --- a/src/Data/List/Membership/Setoid/Properties.agda +++ b/src/Data/List/Membership/Setoid/Properties.agda @@ -1,4 +1,4 @@ ------------------------------------------------------------------------- +----------------------------------------------------------------------- -- The Agda standard library -- -- Properties related to setoid list membership @@ -21,11 +21,11 @@ import Data.List.Relation.Unary.All.Properties.Core as All import Data.List.Relation.Unary.Any.Properties as Any import Data.List.Relation.Unary.Unique.Setoid as Unique open import Data.Nat.Base using (suc; z>=-∈↔; ⊛-∈↔; ⊗-∈↔) import Data.List.Relation.Binary.Subset.Setoid.Properties as Subset open import Data.List.Relation.Binary.Subset.Propositional - using (_⊆_; _⊇_) + using (_⊆_; _⊇_; _⊈_) open import Data.List.Relation.Binary.Permutation.Propositional using (_↭_; ↭-sym; ↭-isEquivalence) import Data.List.Relation.Binary.Permutation.Propositional.Properties as Permutation open import Data.Nat.Base using (ℕ; _≤_) import Data.Product.Base as Product -import Data.Sum.Base as Sum +open import Data.Sum.Base as Sum using (_⊎_) open import Effect.Monad open import Function.Base using (_∘_; _∘′_; id; _$_) open import Function.Bundles using (_↔_; Inverse; Equivalence) @@ -52,8 +52,19 @@ private a b p q : Level A : Set a B : Set b + x y : A ws xs ys zs : List A +------------------------------------------------------------------------ +-- Basics +------------------------------------------------------------------------ + +∷⊈[] : x ∷ xs ⊈ [] +∷⊈[] = Subset.∷⊈[] (setoid _) + +⊆[]⇒≡[] : ∀ {A : Set a} → (_⊆ []) ⋐ (_≡ []) +⊆[]⇒≡[] {A = A} = Subset.⊆[]⇒≡[] (setoid A) + ------------------------------------------------------------------------ -- Relational properties with _≋_ (pointwise equality) ------------------------------------------------------------------------ @@ -150,6 +161,12 @@ xs⊆x∷xs = Subset.xs⊆x∷xs (setoid _) ∈-∷⁺ʳ : ∀ {x} → x ∈ ys → xs ⊆ ys → x ∷ xs ⊆ ys ∈-∷⁺ʳ = Subset.∈-∷⁺ʳ (setoid _) +⊆∷⇒∈∨⊆ : xs ⊆ y ∷ ys → y ∈ xs ⊎ xs ⊆ ys +⊆∷⇒∈∨⊆ = Subset.⊆∷⇒∈∨⊆ (setoid _) + +⊆∷∧∉⇒⊆ : xs ⊆ y ∷ ys → y ∉ xs → xs ⊆ ys +⊆∷∧∉⇒⊆ = Subset.⊆∷∧∉⇒⊆ (setoid _) + ------------------------------------------------------------------------ -- _++_ @@ -179,6 +196,12 @@ module _ {xss yss : List (List A)} where Product.map₂ (Product.map₂ xss⊆yss) ∘ Inverse.from concat-∈↔ +------------------------------------------------------------------------ +-- concatMap + +concatMap⁺ : ∀ (f : A → List B) → xs ⊆ ys → concatMap f xs ⊆ concatMap f ys +concatMap⁺ _ = concat⁺ ∘ map⁺ _ + ------------------------------------------------------------------------ -- applyUpTo diff --git a/src/Data/List/Relation/Binary/Subset/Setoid/Properties.agda b/src/Data/List/Relation/Binary/Subset/Setoid/Properties.agda index 0d0d685a27..901ee8b942 100644 --- a/src/Data/List/Relation/Binary/Subset/Setoid/Properties.agda +++ b/src/Data/List/Relation/Binary/Subset/Setoid/Properties.agda @@ -22,7 +22,8 @@ import Data.List.Relation.Binary.Equality.Setoid as Equality import Data.List.Relation.Binary.Permutation.Setoid as Permutation import Data.List.Relation.Binary.Permutation.Setoid.Properties as Permutationₚ open import Data.Product.Base using (_,_) -open import Function.Base using (_∘_; _∘₂_; _$_) +open import Data.Sum.Base using (_⊎_; inj₁; inj₂) +open import Function.Base using (_∘_; _∘₂_; _$_; case_of_) open import Level using (Level) open import Relation.Nullary using (¬_; does; yes; no) open import Relation.Nullary.Negation using (contradiction) @@ -34,6 +35,7 @@ open import Relation.Binary.Bundles using (Setoid; Preorder) open import Relation.Binary.Structures using (IsPreorder) import Relation.Binary.Reasoning.Preorder as ≲-Reasoning open import Relation.Binary.Reasoning.Syntax +open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) open Setoid using (Carrier) @@ -41,6 +43,22 @@ private variable a b p q r ℓ : Level +------------------------------------------------------------------------ +-- Basics +------------------------------------------------------------------------ + +module _ (S : Setoid a ℓ) where + + open Setoid S using (refl) + open Subset S + + ∷⊈[] : ∀ {x xs} → x ∷ xs ⊈ [] + ∷⊈[] p = Membershipₚ.∉[] S $ p (here refl) + + ⊆[]⇒≡[] : (_⊆ []) ⋐ (_≡ []) + ⊆[]⇒≡[] {x = []} _ = ≡.refl + ⊆[]⇒≡[] {x = _ ∷ _} p with () ← ∷⊈[] p + ------------------------------------------------------------------------ -- Relational properties with _≋_ (pointwise equality) ------------------------------------------------------------------------ @@ -161,12 +179,14 @@ module _ (S : Setoid a ℓ) where ------------------------------------------------------------------------ -- Properties of list functions +------------------------------------------------------------------------ + ------------------------------------------------------------------------ -- ∷ module _ (S : Setoid a ℓ) where - open Setoid S + open Setoid S renaming (Carrier to A) open Subset S open Membership S open Membershipₚ @@ -174,14 +194,31 @@ module _ (S : Setoid a ℓ) where xs⊆x∷xs : ∀ xs x → xs ⊆ x ∷ xs xs⊆x∷xs xs x = there - ∷⁺ʳ : ∀ {xs ys} x → xs ⊆ ys → x ∷ xs ⊆ x ∷ ys + private variable + x y : A + xs ys : List A + + ∷⁺ʳ : ∀ x → xs ⊆ ys → x ∷ xs ⊆ x ∷ ys ∷⁺ʳ x xs⊆ys (here p) = here p ∷⁺ʳ x xs⊆ys (there p) = there (xs⊆ys p) - ∈-∷⁺ʳ : ∀ {xs ys x} → x ∈ ys → xs ⊆ ys → x ∷ xs ⊆ ys + ∈-∷⁺ʳ : x ∈ ys → xs ⊆ ys → x ∷ xs ⊆ ys ∈-∷⁺ʳ x∈ys _ (here v≈x) = ∈-resp-≈ S (sym v≈x) x∈ys ∈-∷⁺ʳ _ xs⊆ys (there x∈xs) = xs⊆ys x∈xs + ⊆∷⇒∈∨⊆ : xs ⊆ y ∷ ys → y ∈ xs ⊎ xs ⊆ ys + ⊆∷⇒∈∨⊆ {xs = []} []⊆y∷ys = inj₂ λ () + ⊆∷⇒∈∨⊆ {xs = _ ∷ _} x∷xs⊆y∷ys with ⊆∷⇒∈∨⊆ $ x∷xs⊆y∷ys ∘ there + ... | inj₁ y∈xs = inj₁ $ there y∈xs + ... | inj₂ xs⊆ys with x∷xs⊆y∷ys (here refl) + ... | here x≈y = inj₁ $ here (sym x≈y) + ... | there x∈ys = inj₂ (∈-∷⁺ʳ x∈ys xs⊆ys) + + ⊆∷∧∉⇒⊆ : xs ⊆ y ∷ ys → y ∉ xs → xs ⊆ ys + ⊆∷∧∉⇒⊆ xs⊆y∷ys y∉xs with ⊆∷⇒∈∨⊆ xs⊆y∷ys + ... | inj₁ y∈xs = contradiction y∈xs y∉xs + ... | inj₂ xs⊆ys = xs⊆ys + ------------------------------------------------------------------------ -- ++ diff --git a/src/Data/List/Relation/Unary/Any/Properties.agda b/src/Data/List/Relation/Unary/Any/Properties.agda index 836e73d4a4..6f1df8cbcc 100644 --- a/src/Data/List/Relation/Unary/Any/Properties.agda +++ b/src/Data/List/Relation/Unary/Any/Properties.agda @@ -461,6 +461,17 @@ module _ {P : A → Set p} where concat↔ : ∀ {xss} → Any (Any P) xss ↔ Any P (concat xss) concat↔ {xss} = mk↔ₛ′ concat⁺ (concat⁻ xss) (concat⁺∘concat⁻ xss) concat⁻∘concat⁺ +------------------------------------------------------------------------ +-- concatMap + +module _ (f : A → List B) {p} {P : Pred B p} where + + concatMap⁺ : Any (Any P ∘ f) xs → Any P (concatMap f xs) + concatMap⁺ = concat⁺ ∘ map⁺ + + concatMap⁻ : Any P (concatMap f xs) → Any (Any P ∘ f) xs + concatMap⁻ = map⁻ ∘ concat⁻ _ + ------------------------------------------------------------------------ -- cartesianProductWith diff --git a/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda b/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda index bcd7df1176..8852bdd704 100644 --- a/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda +++ b/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda @@ -8,9 +8,12 @@ module Data.List.Relation.Unary.Unique.Propositional.Properties where -open import Data.List.Base using (map; _++_; concat; cartesianProductWith; - cartesianProduct; drop; take; applyUpTo; upTo; applyDownFrom; downFrom; - tabulate; allFin; filter) +open import Data.List.Base + using ( List; _∷_; map; _++_; concat; cartesianProductWith + ; cartesianProduct; drop; take; applyUpTo; upTo; applyDownFrom; downFrom + ; tabulate; allFin; filter + ) +open import Data.List.Membership.Propositional using (_∉_) open import Data.List.Relation.Binary.Disjoint.Propositional using (Disjoint) open import Data.List.Relation.Unary.All as All using (All; []; _∷_) @@ -35,6 +38,9 @@ open import Relation.Nullary.Negation using (¬_) private variable a b c p : Level + A : Set a + x y : A + xs : List A ------------------------------------------------------------------------ -- Introduction (⁺) and elimination (⁻) rules for list operations @@ -154,3 +160,9 @@ module _ {A : Set a} {P : Pred _ p} (P? : Decidable P) where filter⁺ : ∀ {xs} → Unique xs → Unique (filter P? xs) filter⁺ = Setoid.filter⁺ (setoid A) P? + +------------------------------------------------------------------------ +-- ∷ + +Unique[x∷xs]⇒x∉xs : Unique (x ∷ xs) → x ∉ xs +Unique[x∷xs]⇒x∉xs = Setoid.Unique[x∷xs]⇒x∉xs (setoid _) diff --git a/src/Data/List/Relation/Unary/Unique/Setoid/Properties.agda b/src/Data/List/Relation/Unary/Unique/Setoid/Properties.agda index ffb587018a..0dc7027c79 100644 --- a/src/Data/List/Relation/Unary/Unique/Setoid/Properties.agda +++ b/src/Data/List/Relation/Unary/Unique/Setoid/Properties.agda @@ -9,9 +9,11 @@ module Data.List.Relation.Unary.Unique.Setoid.Properties where open import Data.List.Base +import Data.List.Membership.Setoid as Membership open import Data.List.Membership.Setoid.Properties open import Data.List.Relation.Binary.Disjoint.Setoid open import Data.List.Relation.Binary.Disjoint.Setoid.Properties +open import Data.List.Relation.Unary.Any using (here; there) open import Data.List.Relation.Unary.All as All using (All; []; _∷_) open import Data.List.Relation.Unary.All.Properties using (All¬⇒¬Any) open import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs) @@ -156,3 +158,21 @@ module _ (S : Setoid a ℓ) {P : Pred _ p} (P? : Decidable P) where filter⁺ : ∀ {xs} → Unique S xs → Unique S (filter P? xs) filter⁺ = AllPairs.filter⁺ P? + +------------------------------------------------------------------------ +-- ∷ + +module _ (S : Setoid a ℓ) where + + open Setoid S renaming (Carrier to A) + open Membership S using (_∉_) + + private + variable + x y : A + xs : List A + + Unique[x∷xs]⇒x∉xs : Unique S (x ∷ xs) → x ∉ xs + Unique[x∷xs]⇒x∉xs ((x≉ ∷ x∉) ∷ _ ∷ uniq) = λ where + (here x≈) → x≉ x≈ + (there x∈) → Unique[x∷xs]⇒x∉xs (x∉ AllPairs.∷ uniq) x∈ diff --git a/src/Relation/Binary/Construct/Interior/Symmetric.agda b/src/Relation/Binary/Construct/Interior/Symmetric.agda index a954dc99ec..50b75b309d 100644 --- a/src/Relation/Binary/Construct/Interior/Symmetric.agda +++ b/src/Relation/Binary/Construct/Interior/Symmetric.agda @@ -8,15 +8,18 @@ module Relation.Binary.Construct.Interior.Symmetric where -open import Function.Base using (flip) -open import Level +open import Data.Bool.Base using (_∧_) +open import Function.Base using (flip; _∘_) +open import Level using (Level) open import Relation.Binary +open import Relation.Nullary.Decidable.Core +open import Relation.Nullary.Reflects private variable - a b c ℓ r s t : Level + a ℓ : Level A : Set a - R S T : Rel A r + R S T : Rel A ℓ ------------------------------------------------------------------------ -- Definition @@ -56,28 +59,59 @@ transitive tr = trans tr tr asymmetric⇒empty : Asymmetric R → Empty (SymInterior R) asymmetric⇒empty asym (r , r′) = asym r r′ +-- Decidability +decidable : Decidable R → Decidable (SymInterior R) +does (decidable R? x y) = does (R? x y) ∧ does (R? y x) +proof (decidable R? x y) = proof (R? x y) reflects proof (R? y x) + where + _reflects_ : ∀ {bxy byx} → Reflects (R x y) bxy → Reflects (R y x) byx → + Reflects (SymInterior R x y) (bxy ∧ byx) + ofʸ rxy reflects ofʸ ryx = of (rxy , ryx) + ofʸ rxy reflects ofⁿ ¬ryx = of (¬ryx ∘ rhs≤lhs) + ofⁿ ¬rxy reflects _ = of (¬rxy ∘ lhs≤rhs) + -- A reflexive transitive relation _≤_ gives rise to a poset in which the -- equivalence relation is SymInterior _≤_. -isEquivalence : Reflexive R → Transitive R → IsEquivalence (SymInterior R) -isEquivalence refl trans = record - { refl = reflexive refl - ; sym = symmetric - ; trans = transitive trans - } - -isPartialOrder : Reflexive R → Transitive R → IsPartialOrder (SymInterior R) R -isPartialOrder refl trans = record - { isPreorder = record - { isEquivalence = isEquivalence refl trans +module _ {R : Rel A ℓ} (refl : Reflexive R) (trans : Transitive R) where + + isEquivalence : IsEquivalence (SymInterior R) + isEquivalence = record + { refl = reflexive refl + ; sym = symmetric + ; trans = transitive trans + } + + isPreorder : IsPreorder (SymInterior R) R + isPreorder = record + { isEquivalence = isEquivalence ; reflexive = lhs≤rhs ; trans = trans } - ; antisym = _,_ - } - -poset : ∀ {a} {A : Set a} {R : Rel A ℓ} → Reflexive R → Transitive R → Poset a ℓ ℓ -poset {R = R} refl trans = record - { _≤_ = R - ; isPartialOrder = isPartialOrder refl trans - } + + isPartialOrder : IsPartialOrder (SymInterior R) R + isPartialOrder = record + { isPreorder = isPreorder + ; antisym = _,_ + } + + poset : Poset _ ℓ ℓ + poset = record { isPartialOrder = isPartialOrder } + + module _ (R? : Decidable R) where + + isDecEquivalence : IsDecEquivalence (SymInterior R) + isDecEquivalence = record + { isEquivalence = isEquivalence + ; _≟_ = decidable R? + } + + isDecPartialOrder : IsDecPartialOrder (SymInterior R) R + isDecPartialOrder = record + { isPartialOrder = isPartialOrder + ; _≟_ = decidable R? + ; _≤?_ = R? + } + + decPoset : DecPoset _ ℓ ℓ + decPoset = record { isDecPartialOrder = isDecPartialOrder }