------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to Any ------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Data.List.Relation.Unary.Any.Properties where open import Data.Bool.Base using (Bool; false; true; T) open import Data.Bool.ListAction using (any) open import Data.Bool.Properties using (T-∨; T-≡) open import Data.Empty using (⊥) open import Data.Fin.Base using (Fin; zero; suc) open import Data.List.Base as List hiding (find; and; or; all; any) open import Data.List.Effectful as List using (monad) open import Data.List.Relation.Unary.Any as Any using (Any; here; there) open import Data.List.Membership.Propositional open import Data.List.Membership.Propositional.Properties.Core using (Any↔; find∘map; map∘find; lose∘find) open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_) open import Data.Nat.Base using (zero; suc; _<_; z>=_ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where >>=↔ : Any (Any P ∘ f) xs ↔ Any P (xs >>= f) >>=↔ {xs = xs} = Any (Any P ∘ f) xs ↔⟨ map↔ ⟩ Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩ Any P (xs >>= f) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _⊛_ ⊛↔ : ∀ {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} → Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs) ⊛↔ {P = P} {fs} {xs} = Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → pure↔) (_ ∎)) (_ ∎) ⟩ Any (λ f → Any (Any P ∘ pure ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩ Any (λ f → Any P (xs >>= pure ∘ f)) fs ↔⟨ >>=↔ ⟩ Any P (fs >>= λ f → xs >>= λ x → pure (f x)) ≡⟨ cong (Any P) (List.Applicative.unfold-⊛ fs xs) ⟨ Any P (fs ⊛ xs) ∎ where open Related.EquationalReasoning -- An alternative introduction rule for _⊛_ ⊛⁺′ : ∀ {P : Pred A ℓ} {Q : Pred B ℓ} {fs : List (A → B)} {xs} → Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs) ⊛⁺′ pq p = Inverse.to ⊛↔ (Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq) ------------------------------------------------------------------------ -- _⊗_ ⊗↔ : {P : A × B → Set ℓ} {xs : List A} {ys : List B} → Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys) ⊗↔ {P = P} {xs} {ys} = Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ pure↔ ⟩ Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (pure _,_) ↔⟨ ⊛↔ ⟩ Any (λ x, → Any (P ∘ x,) ys) (pure _,_ ⊛ xs) ↔⟨ ⊛↔ ⟩ Any P (pure _,_ ⊛ xs ⊛ ys) ≡⟨ cong (Any P ∘′ (_⊛ ys)) (List.Applicative.unfold-<$> _,_ xs) ⟨ Any P (xs ⊗ ys) ∎ where open Related.EquationalReasoning ⊗↔′ : {P : A → Set ℓ} {Q : B → Set ℓ} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys) ⊗↔′ {P = P} {Q} {xs} {ys} = (Any P xs × Any Q ys) ↔⟨ ×↔ ⟩ Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩ Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎ where open Related.EquationalReasoning map-with-∈⁺ = mapWith∈⁺ {-# WARNING_ON_USAGE map-with-∈⁺ "Warning: map-with-∈⁺ was deprecated in v2.0. Please use mapWith∈⁺ instead." #-} map-with-∈⁻ = mapWith∈⁻ {-# WARNING_ON_USAGE map-with-∈⁻ "Warning: map-with-∈⁻ was deprecated in v2.0. Please use mapWith∈⁻ instead." #-} map-with-∈↔ = mapWith∈↔ {-# WARNING_ON_USAGE map-with-∈↔ "Warning: map-with-∈↔ was deprecated in v2.0. Please use mapWith∈↔ instead." #-}