Skip to content

Commit 3c49163

Browse files
Add proofs to Data.List.Properties (#2355)
* Add map commutation with other operations map commutes with most list operations in some way, and I initially made a section just for these proofs, but later decided to spread them into each section for consistency. * Add congruence to operations that miss it * Add flip & comm proofs to align[With] & [un]zip[With] For the case of zipWith, the existing comm proof can be provided in terms of cong and flip. For the case of unzip[With], the comm proof has little use and the flip proof is better named "swap". * Remove unbound parameter The alignWith section begins with a module _ {f g : These A B → C} where but g is only used by the first function. * Add properties for take * Proof of zip[With] and unzip[With] being inverses * fixup! don't put list parameters in modules * fixup! typo in changelog entry * fixup! use equational reasoning in place of trans * Add interaction with ++ in two more operations * fixup! foldl-cong: don't take d ≡ e * prove properties about catMaybes now that catMaybes is no longer defined in terms of mapMaybe, properties about mapMaybe need to be proven for catMaybe as well * move mapMaybe properties down see next commit (given that mapMaybe-concatMap now depends on map-concatMap, it has to be moved down) * simplify mapMaybe proofs since mapMaybe is now defined in terms of catMaybes and map, we can derive its proofs from the proofs of those rather than using induction directly --------- Co-authored-by: MatthewDaggitt <[email protected]>
1 parent 7cea0d1 commit 3c49163

File tree

2 files changed

+312
-41
lines changed

2 files changed

+312
-41
lines changed

CHANGELOG.md

+34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Bug-fixes
1616
* Module `Data.List.Relation.Ternary.Appending.Setoid.Properties` no longer
1717
exports the `Setoid` module under the alias `S`.
1818

19+
* Remove unbound parameter from `Data.List.Properties.length-alignWith`,
20+
`alignWith-map` and `map-alignWith`.
21+
1922
Non-backwards compatible changes
2023
--------------------------------
2124

@@ -330,6 +333,37 @@ Additions to existing modules
330333
reverse-upTo : reverse (upTo n) ≡ downFrom n
331334
reverse-applyDownFrom : reverse (applyDownFrom f n) ≡ applyUpTo f n
332335
reverse-downFrom : reverse (downFrom n) ≡ upTo n
336+
mapMaybe-map : mapMaybe f ∘ map g ≗ mapMaybe (f ∘ g)
337+
map-mapMaybe : map g ∘ mapMaybe f ≗ mapMaybe (Maybe.map g ∘ f)
338+
align-map : align (map f xs) (map g ys) ≡ map (map f g) (align xs ys)
339+
zip-map : zip (map f xs) (map g ys) ≡ map (map f g) (zip xs ys)
340+
unzipWith-map : unzipWith f ∘ map g ≗ unzipWith (f ∘ g)
341+
map-unzipWith : map (map g) (map h) ∘ unzipWith f ≗ unzipWith (map g h ∘ f)
342+
unzip-map : unzip ∘ map (map f g) ≗ map (map f) (map g) ∘ unzip
343+
splitAt-map : splitAt n ∘ map f ≗ map (map f) (map f) ∘ splitAt n
344+
uncons-map : uncons ∘ map f ≗ map (map f (map f)) ∘ uncons
345+
last-map : last ∘ map f ≗ map f ∘ last
346+
tail-map : tail ∘ map f ≗ map (map f) ∘ tail
347+
mapMaybe-cong : f ≗ g → mapMaybe f ≗ mapMaybe g
348+
zipWith-cong : (∀ a b → f a b ≡ g a b) → ∀ as → zipWith f as ≗ zipWith g as
349+
unzipWith-cong : f ≗ g → unzipWith f ≗ unzipWith g
350+
foldl-cong : (∀ x y → f x y ≡ g x y) → ∀ x → foldl f x ≗ foldl g x
351+
alignWith-flip : alignWith f xs ys ≡ alignWith (f ∘ swap) ys xs
352+
alignWith-comm : f ∘ swap ≗ f → alignWith f xs ys ≡ alignWith f ys xs
353+
align-flip : align xs ys ≡ map swap (align ys xs)
354+
zip-flip : zip xs ys ≡ map swap (zip ys xs)
355+
unzipWith-swap : unzipWith (swap ∘ f) ≗ swap ∘ unzipWith f
356+
unzip-swap : unzip ∘ map swap ≗ swap ∘ unzip
357+
take-take : take n (take m xs) ≡ take (n ⊓ m) xs
358+
take-drop : take n (drop m xs) ≡ drop m (take (m + n) xs)
359+
zip-unzip : uncurry′ zip ∘ unzip ≗ id
360+
unzipWith-zipWith : f ∘ uncurry′ g ≗ id → length xs ≡ length ys → unzipWith f (zipWith g xs ys) ≡ (xs , ys)
361+
unzip-zip : length xs ≡ length ys → unzip (zip xs ys) ≡ (xs , ys)
362+
mapMaybe-++ : mapMaybe f (xs ++ ys) ≡ mapMaybe f xs ++ mapMaybe f ys
363+
unzipWith-++ : unzipWith f (xs ++ ys) ≡ zip _++_ _++_ (unzipWith f xs) (unzipWith f ys)
364+
catMaybes-concatMap : catMaybes ≗ concatMap fromMaybe
365+
catMaybes-++ : catMaybes (xs ++ ys) ≡ catMaybes xs ++ catMaybes ys
366+
map-catMaybes : map f ∘ catMaybes ≗ catMaybes ∘ map (Maybe.map f)
333367
```
334368

335369
* In `Data.List.Relation.Unary.All.Properties`:

0 commit comments

Comments
 (0)