Skip to content
Snippets Groups Projects

Some map_zip/map_zip_with properties.

Merged Dan Frumin requested to merge dfrumin/coq-stdpp:map_properties into master
2 unresolved threads

These are some properties of map_zip_with that I am using so far. Perhaps you want me to port the whole thing first, to see what other functions/lemmas will I need?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1140 map_zip_with f = ∅.
1141 Proof.
1142 unfold map_zip_with. by rewrite merge_empty by done.
1143 Qed.
1144
1145 Lemma map_insert_zip_with {A B C} (f : A B C) m1 m2 i x y z :
1146 f y z = x
1147 <[i:=x]>(map_zip_with f m1 m2) = map_zip_with f (<[i:=y]>m1) (<[i:=z]>m2).
1148 Proof.
1149 intros Hf. unfold map_zip_with.
1150 erewrite insert_merge; [ auto | by compute | by rewrite Hf ].
1151 Qed.
1152
1153 Lemma map_fmap_zip_with {A' A B' B C} (f : A B C)
1154 (g1 : A' A) (g2 : B' B) m1 m2 :
1155 map_zip_with f (fmap g1 m1) (fmap g2 m2) = map_zip_with (fun x y => f (g1 x) (g2 y)) m1 m2.
  • I would except there to be three variants for the lemma:

    • With an fmap in the first argument, i.e. map_zip_with f (g1 <$> m1) m2
    • With an fmap in the second argument, i.e. map_zip_with f m1 (g <$> m2)
    • With an fmap on the outside, i.e. g <$> map_zip_with f m1 m2

    This lemma should follow from the first two lemmas that I mentioned.

    Nitpick, use the <$> notation and unicode lambdas.

  • Author Contributor

    I would except there to be three variants for the lemma:

    I actually use the first variant of the lemma, which follow from the "general" one + map_fmap_id. I guess there are multiple equiprovable sets of lemmas :)

  • Ah, right, of course!

    I still guess that my first lemma is easier to use, you don't first have to massage your goal using map_fmap_id first (which requires a rewrite in opposite direction and thus careful subterm selection).

  • Please register or sign in to reply
  • 1157 apply map_eq; intro i.
    1158 rewrite ?map_lookup_zip_with. rewrite ?lookup_fmap.
    1159 by destruct (m1 !! i), (m2 !! i).
    1160 Qed.
    1161
    1162 Lemma map_zip_with_map_zip {A B C} (f : A B C) m1 m2 :
    1163 map_zip_with f m1 m2 = curry f <$> map_zip m1 m2.
    1164 Proof.
    1165 apply map_eq; intro i.
    1166 rewrite lookup_fmap; rewrite ?map_lookup_zip_with; rewrite ?lookup_fmap.
    1167 by destruct (m1 !! i), (m2 !! i).
    1168 Qed.
    1169
    1170 Lemma map_fmap_zip {A' A B' B} (g1 : A' A) (g2 : B' B) m1 m2 :
    1171 map_zip (fmap g1 m1) (fmap g2 m2)
    1172 = (fun '(x,y) => (g1 x, g2 y)) <$> map_zip m1 m2.
  • Looks good! I only have some small comments.

  • Dan Frumin added 1 commit

    added 1 commit

    • cd0b7f48 - Some map_zip/map_zip_with properties.

    Compare with previous version

  • Author Contributor

    @robbertkrebbers What do you think of the changes now?

  • Merged, thank you very much!

  • Please register or sign in to reply
    Loading