Skip to content

Commit

Permalink
Add some ZUtil/Land/Fold.v lemmas (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross authored and OwenConoly committed Nov 13, 2022
1 parent c1d2772 commit 9bb2e2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Util/ZUtil.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Require Crypto.Util.ZUtil.Hints.PullPush.
Require Crypto.Util.ZUtil.Hints.ZArith.
Require Crypto.Util.ZUtil.Hints.Ztestbit.
Require Crypto.Util.ZUtil.Land.
Require Crypto.Util.ZUtil.Land.Fold.
Require Crypto.Util.ZUtil.LandLorBounds.
Require Crypto.Util.ZUtil.LandLorShiftBounds.
Require Crypto.Util.ZUtil.Lor.
Expand Down
25 changes: 25 additions & 0 deletions src/Util/ZUtil/Land/Fold.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Require Import Coq.ZArith.ZArith.
Require Import Coq.micromega.Lia.
Require Import Coq.Lists.List.
Require Import Crypto.Util.ZUtil.Land.
Require Import Crypto.Util.ZUtil.Hints.Core.
Local Open Scope bool_scope. Local Open Scope Z_scope.

Module Z.
Lemma fold_right_land_m1_cps v ls
: fold_right Z.land v ls
= Z.land (fold_right Z.land (-1) ls) v.
Proof.
induction ls as [|?? IH]; cbn [fold_right].
{ now rewrite Z.land_m1'_l. }
{ rewrite <- !Z.land_assoc, IH; reflexivity. }
Qed.

Lemma fold_right_land_ones_id sz ls
: Z.land (fold_right Z.land (Z.ones sz) ls) (Z.ones sz)
= Z.land (fold_right Z.land (-1) ls) (Z.ones sz).
Proof.
rewrite fold_right_land_m1_cps, <- Z.land_assoc, Z.land_diag.
reflexivity.
Qed.
End Z.

0 comments on commit 9bb2e2a

Please sign in to comment.