-
Notifications
You must be signed in to change notification settings - Fork 271
Add Properties of List actions on Bools #3005
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
Changes from all commits
b81cd4e
2d7edc8
2c2efdb
184924c
e172c9a
558cf17
a624cbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Booleans: properties of conjunction and disjunction of lists | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --without-K --safe #-} | ||
|
|
||
| module Data.Bool.ListAction.Properties where | ||
|
|
||
| open import Data.Bool.Base | ||
| open import Data.Bool.Properties | ||
| open import Data.Bool.ListAction | ||
| open import Data.List.Base hiding (and; or; all; any) | ||
| open import Data.List.Membership.Propositional using (_∈_) | ||
| open import Data.List.Relation.Binary.Permutation.Propositional using (_↭_; ↭⇒↭ₛ) | ||
| import Data.List.Relation.Binary.Permutation.Propositional.Properties as ↭ | ||
| open import Data.List.Relation.Binary.Permutation.Setoid.Properties | ||
| open import Data.List.Relation.Unary.Any using (here; there) | ||
| open import Function.Base using (_∘′_) | ||
| open import Relation.Binary.Core using (_Preserves_⟶_) | ||
| open import Relation.Binary.PropositionalEquality.Core | ||
| open import Relation.Binary.PropositionalEquality.Properties | ||
| using (module ≡-Reasoning) | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Properties | ||
|
|
||
| -- and | ||
|
|
||
| and-++ : ∀ bs cs → and (bs ++ cs) ≡ and bs ∧ and cs | ||
| and-++ [] cs = refl | ||
| and-++ (b ∷ bs) cs = begin | ||
| b ∧ and (bs ++ cs) ≡⟨ cong (b ∧_) (and-++ bs cs) ⟩ | ||
| b ∧ (and bs ∧ and cs) ≡⟨ ∧-assoc b (and bs) (and cs) ⟨ | ||
| (b ∧ and bs) ∧ and cs ∎ | ||
| where open ≡-Reasoning | ||
|
|
||
| ∨-distribˡ-and : ∀ b cs → b ∨ and cs ≡ all (b ∨_) cs | ||
| ∨-distribˡ-and b [] = ∨-zeroʳ b | ||
| ∨-distribˡ-and b (c ∷ cs) = trans (∨-distribˡ-∧ b c (and cs)) (cong ((b ∨ c) ∧_) (∨-distribˡ-and b cs)) | ||
|
|
||
| ∨-distribʳ-and : ∀ b cs → and cs ∨ b ≡ all (_∨ b) cs | ||
| ∨-distribʳ-and b [] = ∨-zeroˡ b | ||
| ∨-distribʳ-and b (c ∷ cs) = trans (∨-distribʳ-∧ b c (and cs)) (cong ((c ∨ b) ∧_) (∨-distribʳ-and b cs)) | ||
|
Comment on lines
+39
to
+45
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two however, should be rewritten in terms of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was my best effort: ∨-distribˡ-and : ∀ b cs → b ∨ and cs ≡ all (b ∨_) cs
∨-distribˡ-and b cs = begin
b ∨ foldr _∧_ true cs ≡⟨ foldr-fusion (b ∨_) true (∨-distribˡ-∧ b) cs ⟩
foldr (b ∨_ -⟨ _∧_ ∣) (b ∨ true) cs ≡⟨ foldr-map _∧_ (b ∨_) (b ∨ true) cs ⟨
foldr _∧_ (b ∨ true) (map (b ∨_) cs) ≡⟨ cong (λ e → foldr _∧_ e (map (b ∨_) cs)) (∨-zeroʳ b) ⟩
foldr _∧_ true (map (b ∨_) cs) ∎
where open ≡-ReasoningI personally don't think it's worth it, but maybe I'm missing a trick
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you're right... I managed ∨-distribˡ-and b cs = begin
b ∨ and cs ≡⟨ foldr-fusion (b ∨_) true (∨-distribˡ-∧ b) cs ⟩
foldr g (b ∨ true) cs ≡⟨ foldr-cong (λ _ _ → refl) (∨-zeroʳ b) cs ⟩
foldr g true cs ≡⟨ foldr-map _∧_ (b ∨_) true cs ⟨
all (b ∨_) cs ∎
where
open ≡-Reasoning
g : Bool → Bool → Bool
g z = (b ∨ z) ∧_which isn't much better, but is more 'abstract'? I won't fight you for this though! |
||
|
|
||
| and-↭ : and Preserves _↭_ ⟶ _≡_ | ||
| and-↭ p = foldr-commMonoid ≡-setoid ∧-isCommutativeMonoid (↭⇒↭ₛ p) | ||
|
jamesmckinna marked this conversation as resolved.
|
||
|
|
||
| and-locate : ∀ bs → and bs ≡ false → false ∈ bs | ||
| and-locate (false ∷ bs) p = here refl | ||
| and-locate (true ∷ bs) p = there (and-locate bs p) | ||
|
|
||
| -- or | ||
|
|
||
| or-++ : ∀ bs cs → or (bs ++ cs) ≡ or bs ∨ or cs | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
| or-++ [] cs = refl | ||
| or-++ (b ∷ bs) cs = begin | ||
| b ∨ or (bs ++ cs) ≡⟨ cong (b ∨_) (or-++ bs cs) ⟩ | ||
| b ∨ (or bs ∨ or cs) ≡⟨ ∨-assoc b (or bs) (or cs) ⟨ | ||
| (b ∨ or bs) ∨ or cs ∎ | ||
| where open ≡-Reasoning | ||
|
|
||
| ∧-distribˡ-or : ∀ b cs → b ∧ or cs ≡ any (b ∧_) cs | ||
| ∧-distribˡ-or b [] = ∧-zeroʳ b | ||
| ∧-distribˡ-or b (c ∷ cs) = trans (∧-distribˡ-∨ b c (or cs)) (cong ((b ∧ c) ∨_) (∧-distribˡ-or b cs)) | ||
|
|
||
| ∧-distribʳ-or : ∀ b cs → or cs ∧ b ≡ any (_∧ b) cs | ||
| ∧-distribʳ-or b [] = ∧-zeroˡ b | ||
| ∧-distribʳ-or b (c ∷ cs) = trans (∧-distribʳ-∨ b c (or cs)) (cong ((c ∧ b) ∨_) (∧-distribʳ-or b cs)) | ||
|
Comment on lines
+64
to
+70
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
|
||
| or-↭ : or Preserves _↭_ ⟶ _≡_ | ||
| or-↭ p = foldr-commMonoid ≡-setoid ∨-isCommutativeMonoid (↭⇒↭ₛ p) | ||
|
jamesmckinna marked this conversation as resolved.
|
||
|
|
||
| or-locate : ∀ bs → or bs ≡ true → true ∈ bs | ||
| or-locate (false ∷ bs) p = there (or-locate bs p) | ||
| or-locate (true ∷ bs) p = here p | ||
|
|
||
| -- all | ||
|
|
||
| all-↭ : ∀ {a} {A : Set a} (p : A → Bool) → all p Preserves _↭_ ⟶ _≡_ | ||
| all-↭ p = and-↭ ∘′ ↭.map⁺ p | ||
|
|
||
| -- any | ||
|
|
||
| any-↭ : ∀ {a} {A : Set a} (p : A → Bool) → any p Preserves _↭_ ⟶ _≡_ | ||
| any-↭ p = or-↭ ∘′ ↭.map⁺ p | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (morally) should have the proof
and-++ bs cs = ++-homo ∧-monoid id bs {cs}but doesn't, for reasons given.