Add Properties of List actions on Bools#3005
Conversation
|
It looks as though I added a note to Would it be better to refactor this PR to make use of the properties defined there? And perhaps to do that prior refactoring? |
|
I'm okay with I would probably be fine with adding these as-is, and refactoring later when more general proofs exist. |
Fine by me. FTR, I think that the converse directions to the |
|
Yes, it requires there are no "zero divisors" in the monoid, which is not the case in, for example, the monoid of integers modulo 6 under multiplication, where 2 * 3 = 0 |
|
Add a |
|
OK, so I experimented with my proposed refactoring, and surprise surprise not all was plain sailing...
So I'll write a cut-down review, and then let's merge this as-is, and figure out the mess afterwards! |
jamesmckinna
left a comment
There was a problem hiding this comment.
All but the CHANGELOG typo are optional.
But my general meta-comment for the library going forward ought perhaps to be that we try to 'take the high road', ie. reuse all the abstraction machinery we have developed, rather than taking the 'low' road of proving things directly by pattern-matching, which otherwise is too 'easy'/'tempting' in cases like these?
|
|
||
| -- and | ||
|
|
||
| and-++ : ∀ bs cs → and (bs ++ cs) ≡ and bs ∧ and cs |
There was a problem hiding this comment.
This (morally) should have the proof and-++ bs cs = ++-homo ∧-monoid id bs {cs} but doesn't, for reasons given.
| ∨-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)) |
There was a problem hiding this comment.
These two however, should be rewritten in terms of Data.List.Properties.foldr-map, given the definition of all as a foldr (and) followed by a map? Or is the ergonomics of doing such similarly too tortured to be worth the effort?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
|
|
||
| -- or | ||
|
|
||
| or-++ : ∀ bs cs → or (bs ++ cs) ≡ or bs ∨ or cs |
There was a problem hiding this comment.
Ditto. or-++ bs cs = ++-homo ∨-monoid id bs {cs}, or... should be, modulo blah blah blah.
| ∧-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)) |
There was a problem hiding this comment.
Ditto. foldr-map instances?
That's a serious omission that should definitely be fixed! |
Requested changes have now been made, so I can approve.
jamesmckinna
left a comment
There was a problem hiding this comment.
All fine by me now, and I think the one approval should suffice!
|
A last thought here, but one which should perhaps be revisited: we define |
I'm not sure of the name for
and-locateandor-locate, but they're the whole reason I ended up making this PR...