| 1 |
From Coq Require Import ZArith Lia. |
| 2 |
From Coq Require Import List. |
| 3 |
Require Import Crypto.Algebra.Ring. |
| 4 |
Require Import Crypto.ArithmeticCPS.Core. |
| 5 |
Require Import Crypto.ArithmeticCPS.Freeze. |
| 6 |
Require Import Crypto.Arithmetic.Partition. |
| 7 |
Require Import Crypto.ArithmeticCPS.Saturated. |
| 8 |
Require Import Crypto.Arithmetic.UniformWeight. |
| 9 |
Require Import Crypto.Util.CPSUtil. |
| 10 |
Require Import Crypto.Util.CPSNotations. |
| 11 |
Require Import Crypto.Util.LetIn. |
| 12 |
Require Import Crypto.Util.ListUtil. |
| 13 |
Require Import Crypto.Util.Prod. |
| 14 |
Require Import Crypto.Util.Sigma. |
| 15 |
Require Import Crypto.Util.Tactics.SetEvars. |
| 16 |
Require Import Crypto.Util.Tactics.SubstEvars. |
| 17 |
Require Import Crypto.Util.ZUtil.Modulo Crypto.Util.ZUtil.Div. |
| 18 |
Require Import Crypto.Util.ZUtil.Definitions. |
| 19 |
Require Import Crypto.Util.ZUtil.EquivModulo. |
| 20 |
Require Import Crypto.Util.ZUtil.AddGetCarry Crypto.Util.ZUtil.MulSplit. |
| 21 |
Require Import Crypto.Util.ZUtil.Modulo.PullPush. |
| 22 |
Require Import Crypto.Util.ZUtil.Tactics.DivModToQuotRem. |
| 23 |
Require Import Crypto.Util.ZUtil.Tactics.LinearSubstitute. |
| 24 |
Require Import Crypto.Util.ZUtil.Tactics.LtbToLt. |
| 25 |
Require Import Crypto.Util.ZUtil.Tactics.PeelLe. |
| 26 |
Require Import Crypto.Util.ZUtil.Tactics.RewriteModSmall. |
| 27 |
Require Import Crypto.Util.ZUtil.Tactics.ZeroBounds. |
| 28 |
Require Import Crypto.Util.ZUtil.Tactics.PullPush.Modulo. |
| 29 |
|
| 30 |
Require Import Crypto.Util.Notations. |
| 31 |
Import ListNotations. Local Open Scope Z_scope. |
| 32 |
|
| 33 |
Import CPSBindNotations. |
| 34 |
Local Open Scope cps_scope. |
| 35 |
|
| 36 |
Module WordByWordMontgomery (Import RT : Runtime). |
| 37 |
Module Import Deps. |
| 38 |
Module Positional := Positional RT. |
| 39 |
Module Rows := Rows RT. |
| 40 |
Module Export FreezeModOps := FreezeModOps RT. |
| 41 |
Module Export RT_Extra := RT_Extra RT. |
| 42 |
End Deps. |
| 43 |
Section with_args. |
| 44 |
Context (lgr : Z) |
| 45 |
(m : Z). |
| 46 |
Local Notation weight := (uweight lgr). |
| 47 |
Let T (n : nat) := list Z. |
| 48 |
Let r := (2^lgr). |
| 49 |
Definition eval {n} : T n -> Z := Positional.eval weight n. |
| 50 |
Let zero {n} : T n := Positional.zeros n. |
| 51 |
Let divmod {n} : T (S n) -> T n * Z := Rows.divmod. |
| 52 |
Let scmul_cps {n} (c : Z) (p : T n) : ~> T (S n) (* uses double-output multiply *) |
| 53 |
:= (vc <- Rows.mul_cps weight r n (S n) (Positional.extend_to_length 1 n [c]) p; |
| 54 |
let '(v, c) := vc in |
| 55 |
return v). |
| 56 |
Let addT_cps {n} (p q : T n) : ~> T (S n) (* joins carry *) |
| 57 |
:= (vc <- Rows.add_cps weight n p q; |
| 58 |
let '(v, c) := vc in |
| 59 |
return (v ++ [c])). |
| 60 |
Let drop_high_addT'_cps {n} (p : T (S n)) (q : T n) : ~> T (S n) (* drops carry *) |
| 61 |
:= (pq <- Rows.add_cps weight (S n) p (Positional.extend_to_length n (S n) q); return (fst pq)). |
| 62 |
Let conditional_sub_cps {n} (arg : T (S n)) (N : T n) : ~> T n (* computes [arg - N] if [N <= arg], and drops high bit *) |
| 63 |
:= (v <- Rows.conditional_sub_cps weight (S n) arg (Positional.extend_to_length n (S n) N); return (Positional.drop_high_to_length n v)). |
| 64 |
Context (R_numlimbs : nat) |
| 65 |
(N : T R_numlimbs). (* encoding of m *) |
| 66 |
Let sub_then_maybe_add_cps (a b : T R_numlimbs) : ~> T R_numlimbs (* computes [a - b + if (a - b) <? 0 then N else 0] *) |
| 67 |
:= (v <- Rows.sub_then_maybe_add_cps weight R_numlimbs (r-1) a b N; return (fst v)). |
| 68 |
Local Opaque T. |
| 69 |
Section Iteration. |
| 70 |
Context (pred_A_numlimbs : nat) |
| 71 |
(B : T R_numlimbs) (k : Z) |
| 72 |
(A : T (S pred_A_numlimbs)) |
| 73 |
(S : T (S R_numlimbs)). |
| 74 |
(* Given A, B < R, we want to compute A * B / R mod N. R = bound 0 * ... * bound (n-1) *) |
| 75 |
|
| 76 |
Local Definition A'_S3_cps : ~> _ |
| 77 |
:= fun _ cont |
| 78 |
=> let '(A', a) := @divmod _ A in |
| 79 |
dlet_list A' := A' in |
| 80 |
dlet a := a in |
| 81 |
@scmul_cps _ a B _ (fun aB => |
| 82 |
@addT_cps _ S aB _ (fun S1 => |
| 83 |
dlet_list S1 := S1 in |
| 84 |
dlet s := snd (@divmod (Datatypes.S (Datatypes.S R_numlimbs)) S1) in |
| 85 |
dlet q := fst (RT_Z.mul_split r s k) in |
| 86 |
@scmul_cps _ q N _ (fun qN => |
| 87 |
@drop_high_addT'_cps _ S1 qN _ (fun S2 => |
| 88 |
dlet_list S2 := S2 in |
| 89 |
dlet_list S3 := fst (@divmod (Datatypes.S R_numlimbs) S2) in |
| 90 |
cont (A', S3))))). |
| 91 |
End Iteration. |
| 92 |
|
| 93 |
Section loop. |
| 94 |
Context (A_numlimbs : nat) |
| 95 |
(A : T A_numlimbs) |
| 96 |
(B : T R_numlimbs) |
| 97 |
(k : Z) |
| 98 |
(S' : T (S R_numlimbs)). |
| 99 |
|
| 100 |
Definition redc_body_cps {pred_A_numlimbs} : T (S pred_A_numlimbs) * T (S R_numlimbs) |
| 101 |
~> T pred_A_numlimbs * T (S R_numlimbs) |
| 102 |
:= fun '(A, S') => A'_S3_cps _ B k A S'. |
| 103 |
|
| 104 |
Definition redc_loop_cps (count : nat) : T count * T (S R_numlimbs) ~> T O * T (S R_numlimbs) |
| 105 |
:= nat_rect |
| 106 |
(fun count => T count * _ ~> _) |
| 107 |
(fun A_S => return A_S) |
| 108 |
(fun count' redc_loop_count' A_S |
| 109 |
=> A'_S' <- redc_body_cps A_S; redc_loop_count' A'_S') |
| 110 |
count. |
| 111 |
|
| 112 |
Definition pre_redc_cps : ~> T (S R_numlimbs) |
| 113 |
:= (v <- redc_loop_cps A_numlimbs (A, @zero (1 + R_numlimbs)%nat); return (snd v)). |
| 114 |
|
| 115 |
Definition redc_cps : ~> T R_numlimbs |
| 116 |
:= (pre_redc <- pre_redc_cps; conditional_sub_cps pre_redc N). |
| 117 |
End loop. |
| 118 |
|
| 119 |
Definition add_cps (A B : T R_numlimbs) : ~> T R_numlimbs |
| 120 |
:= (AB <- @addT_cps _ A B; conditional_sub_cps AB N). |
| 121 |
Definition sub_cps (A B : T R_numlimbs) : ~> T R_numlimbs |
| 122 |
:= sub_then_maybe_add_cps A B. |
| 123 |
Definition opp_cps (A : T R_numlimbs) : ~> T R_numlimbs |
| 124 |
:= sub_cps (@zero _) A. |
| 125 |
Definition nonzero (A : list Z) : Z |
| 126 |
:= fold_right Z.lor 0 A. |
| 127 |
End with_args. |
| 128 |
|
| 129 |
Section modops. |
| 130 |
Context (bitwidth : Z) |
| 131 |
(n : nat) |
| 132 |
(m : Z). |
| 133 |
Let r := 2^bitwidth. |
| 134 |
Local Notation weight := (uweight bitwidth). |
| 135 |
Local Notation eval := (@eval bitwidth n). |
| 136 |
Let m_enc := Partition.partition weight n m. |
| 137 |
Local Coercion Z.of_nat : nat >-> Z. |
| 138 |
Context (r' : Z) |
| 139 |
(m' : Z) |
| 140 |
(r'_correct : (r * r') mod m = 1) |
| 141 |
(m'_correct : (m * m') mod r = (-1) mod r) |
| 142 |
(bitwidth_big : 0 < bitwidth) |
| 143 |
(m_big : 1 < m) |
| 144 |
(n_nz : n <> 0%nat) |
| 145 |
(m_small : m < r^n). |
| 146 |
|
| 147 |
Definition mulmod_cps (a b : list Z) : ~> list Z := @redc_cps bitwidth n m_enc n a b m'. |
| 148 |
Definition squaremod_cps (a : list Z) : ~> list Z := mulmod_cps a a. |
| 149 |
Definition addmod_cps (a b : list Z) : ~> list Z := @add_cps bitwidth n m_enc a b. |
| 150 |
Definition submod_cps (a b : list Z) : ~> list Z := @sub_cps bitwidth n m_enc a b. |
| 151 |
Definition oppmod_cps (a : list Z) : ~> list Z := @opp_cps bitwidth n m_enc a. |
| 152 |
|
| 153 |
Definition mulmod (a b : list Z) : list Z := mulmod_cps a b _ id. |
| 154 |
Definition squaremod (a : list Z) : list Z := squaremod_cps a _ id. |
| 155 |
Definition addmod (a b : list Z) : list Z := addmod_cps a b _ id. |
| 156 |
Definition submod (a b : list Z) : list Z := submod_cps a b _ id. |
| 157 |
Definition oppmod (a : list Z) : list Z := oppmod_cps a _ id. |
| 158 |
|
| 159 |
Definition nonzeromod (a : list Z) : Z := @nonzero a. |
| 160 |
Definition to_bytesmod_cps (a : list Z) : ~> list Z := @to_bytesmod_cps bitwidth 1 n a. |
| 161 |
Definition to_bytesmod (a : list Z) : list Z := to_bytesmod_cps a _ id. |
| 162 |
Definition onemod : list Z := Partition.partition weight n 1. |
| 163 |
Definition R2mod : list Z := Partition.partition weight n ((r^n * r^n) mod m). |
| 164 |
Definition from_montgomerymod_cps (v : list Z) : ~> list Z |
| 165 |
:= mulmod_cps v onemod. |
| 166 |
Definition from_montgomerymod (v : list Z) : list Z := from_montgomerymod_cps v _ id. |
| 167 |
Definition encodemod_cps (v : Z) : ~> list Z |
| 168 |
:= mulmod_cps (Partition.partition weight n v) R2mod. |
| 169 |
Definition encodemod (v : Z) : list Z := encodemod_cps v _ id. |
| 170 |
End modops. |
| 171 |
End WordByWordMontgomery. |
| 172 |
|
| 173 |
(* |
| 174 |
Module Import RT_ExtraAx := RT_Extra RuntimeAxioms. |
| 175 |
Module Import WordByWordMontgomeryAx := WordByWordMontgomery RuntimeAxioms. |
| 176 |
|
| 177 |
Import List.ListNotations. |
| 178 |
Import RuntimeAxioms. |
| 179 |
|
| 180 |
Axiom hide : forall {T} {v : T}, True. |
| 181 |
Require Import Crypto.Util.ZUtil.ModInv. |
| 182 |
|
| 183 |
Time Compute @hide _ (fun a b => (let m := (2^256 - 2^224 + 2^192 + 2^96 - 1) in mulmod 64 4 m (Z.modinv (-m) (2^64)) (expand_list 0 a 4) (expand_list 0 b 4))). |
| 184 |
Time Eval lazy in @hide _ (fun a b => (let m := (2^256 - 2^224 + 2^192 + 2^96 - 1) in mulmod 64 4 m (Z.modinv (-m) (2^64)) (expand_list 0 a 4) (expand_list 0 b 4))). |
| 185 |
|
| 186 |
Goal forall (a b : list Z), True. |
| 187 |
intros. |
| 188 |
pose (let m := (2^256 - 2^224 + 2^192 + 2^96 - 1) in mulmod 64 4 m (Z.modinv (-m) (2^64)) (expand_list 0 a 4) (expand_list 0 b 4)) as e. |
| 189 |
cbv [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 190 |
set (k := Z.modinv _ _) in (value of e). |
| 191 |
vm_compute in k; subst k. |
| 192 |
cbv [expand_list expand_list_helper nat_rect] in e. |
| 193 |
cbv [mulmod mulmod_cps] in e. |
| 194 |
cbv [Partition.partition seq map] in e. |
| 195 |
cbv [uweight ModOps.weight] in e. |
| 196 |
cbv -[redc_cps] in e. |
| 197 |
cbv [redc_cps] in e. |
| 198 |
cbv [pre_redc_cps] in e. |
| 199 |
cbv [redc_loop_cps] in e. |
| 200 |
cbv [nat_rect] in e. |
| 201 |
cbv [Deps.Positional.zeros Nat.add] in e. |
| 202 |
cbv [cpscall cpsbind cpsreturn] in e. |
| 203 |
cbv [repeat] in e. |
| 204 |
cbv [redc_body_cps] in e. |
| 205 |
unfold WordByWordMontgomeryAx.A'_S3_cps in (value of e) at 1. |
| 206 |
cbv [Deps.Rows.divmod hd tl] in e. |
| 207 |
cbn [Deps.RT_Extra.dlet_nd_list] in e. |
| 208 |
cbv [Deps.Positional.extend_to_length] in e. |
| 209 |
cbv [Nat.sub Deps.Positional.zeros repeat] in e. |
| 210 |
cbn [List.app] in e. |
| 211 |
unfold Deps.Rows.mul_cps at 1 in (value of e). |
| 212 |
cbv [Deps.Rows.Deps.Positional.to_associational map seq] in e. |
| 213 |
cbn [combine] in e. |
| 214 |
set (uw := uweight 64) in (value of e). |
| 215 |
cbv [Deps.Rows.Deps.Associational.sat_mul_cps ] in e. |
| 216 |
cbv [flat_map_cps flat_map_cps_specialized] in e. |
| 217 |
cbv [Deps.Rows.Deps.Associational.sat_multerm_cps] in e; cbn [fst snd] in e. |
| 218 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 219 |
Arguments app _ !_ !_. |
| 220 |
cbn [app] in e. |
| 221 |
unfold Deps.Rows.from_associational_cps in (value of e) at 1; cbv [Deps.Rows.Deps.Columns.from_associational_cps] in e. |
| 222 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 223 |
Set Printing Depth 1000000. |
| 224 |
cbv [Deps.Rows.Deps.Columns.nils repeat Init.Nat.pred] in e. |
| 225 |
cbv [Deps.Rows.Deps.Columns.cons_to_nth] in e. |
| 226 |
cbv [fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step] in e. |
| 227 |
cbv [Deps.Rows.Deps.Columns.Deps.Positional.place] in e. |
| 228 |
cbv [nat_rect] in e. |
| 229 |
cbn [fst snd] in e. |
| 230 |
set (k := uw 0%nat) in (value of e); vm_compute in k; subst k. |
| 231 |
set (k := uw 1%nat) in (value of e); vm_compute in k; subst k. |
| 232 |
set (k := uw 2%nat) in (value of e); vm_compute in k; subst k. |
| 233 |
set (k := uw 3%nat) in (value of e); vm_compute in k; subst k. |
| 234 |
set (k := uw 4%nat) in (value of e); vm_compute in k; subst k. |
| 235 |
set (k := uw 5%nat) in (value of e); vm_compute in k; subst k. |
| 236 |
cbv [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 237 |
cbv [update_nth] in e. |
| 238 |
cbv [Deps.Rows.from_columns Deps.Rows.max_column_size Deps.Rows.from_columns' map List.repeat length Nat.max Deps.Rows.extract_row map hd tl List.app] in e. |
| 239 |
cbv delta [fold_right] in e. |
| 240 |
cbn [fst snd combine] in e. |
| 241 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps] in e. |
| 242 |
cbv [fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step] in e. |
| 243 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 244 |
cbn [fst snd] in e. |
| 245 |
unfold Deps.Rows.sum_rows_cps at 1 in (value of e). |
| 246 |
cbv [Deps.Rows.sum_rows'_cps rev] in e; cbn [app combine fst snd] in e. |
| 247 |
cbv [fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step] in e. |
| 248 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 249 |
cbn [fst snd combine app] in e. |
| 250 |
unfold Deps.Rows.sum_rows_cps at 1 in (value of e). |
| 251 |
cbv [Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e. |
| 252 |
cbn [fst snd combine app] in e. |
| 253 |
cbv [Deps.Rows.sum_rows_cps Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e; cbn [fst snd combine app] in e. |
| 254 |
unfold Deps.Rows.add_cps at 1 in (value of e). |
| 255 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e. |
| 256 |
cbn [fst snd] in e. |
| 257 |
cbv [Deps.Rows.sum_rows_cps Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e; cbn [fst snd combine app] in e. |
| 258 |
cbn [Deps.RT_Extra.dlet_nd_list] in e. |
| 259 |
cbv [Deps.Rows.mul_cps] in e. |
| 260 |
cbv [Deps.Rows.Deps.Positional.to_associational map seq] in e. |
| 261 |
cbn [combine] in e. |
| 262 |
cbv [Deps.Rows.Deps.Associational.sat_mul_cps flat_map_cps flat_map_cps_specialized Deps.Rows.Deps.Associational.sat_multerm_cps cpscall cpsbind cpsreturn id] in e; cbn [fst snd app combine] in e. |
| 263 |
unfold Deps.Rows.from_associational_cps in (value of e) at 1. |
| 264 |
cbv [Deps.Rows.Deps.Columns.from_associational_cps cpscall cpsbind cpsreturn id Deps.Rows.Deps.Columns.nils repeat Init.Nat.pred Deps.Rows.Deps.Columns.cons_to_nth fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step Deps.Rows.Deps.Columns.Deps.Positional.place nat_rect] in e; |
| 265 |
cbn [fst snd app combine] in e. |
| 266 |
set (k := uw 0%nat) in (value of e); vm_compute in k; subst k. |
| 267 |
set (k := uw 1%nat) in (value of e); vm_compute in k; subst k. |
| 268 |
set (k := uw 2%nat) in (value of e); vm_compute in k; subst k. |
| 269 |
set (k := uw 3%nat) in (value of e); vm_compute in k; subst k. |
| 270 |
set (k := uw 4%nat) in (value of e); vm_compute in k; subst k. |
| 271 |
set (k := uw 5%nat) in (value of e); vm_compute in k; subst k. |
| 272 |
cbv [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 273 |
cbv [update_nth Deps.Rows.from_columns Deps.Rows.max_column_size Deps.Rows.from_columns' map List.repeat length Nat.max Deps.Rows.extract_row map hd tl List.app] in e. |
| 274 |
cbv delta [fold_right] in e. |
| 275 |
cbn [fst snd combine app] in e. |
| 276 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e. |
| 277 |
cbn [fst snd combine app] in e. |
| 278 |
cbv [Deps.Rows.sum_rows_cps Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e; cbn [fst snd combine app] in e. |
| 279 |
unfold Deps.Rows.add_cps at 1 in (value of e). |
| 280 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e. |
| 281 |
cbv [Deps.Rows.sum_rows_cps Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e; cbn [fst snd combine app] in e. |
| 282 |
cbn [Deps.RT_Extra.dlet_nd_list] in e. |
| 283 |
cbv [update_nth] in e. |
| 284 |
unfold WordByWordMontgomeryAx.A'_S3_cps at 1 in (value of e). |
| 285 |
cbv -[Deps.Positional.drop_high_to_length Deps.Rows.conditional_sub_cps WordByWordMontgomeryAx.A'_S3_cps] in e. |
| 286 |
clear uw. |
| 287 |
set (uw := fun i : nat => _) in (value of e). |
| 288 |
cbv -[Deps.Positional.drop_high_to_length Deps.Rows.conditional_sub_cps] in e. |
| 289 |
clear uw. |
| 290 |
set (uw := fun i : nat => _) in (value of e). |
| 291 |
cbv [Deps.Rows.conditional_sub_cps] in e. |
| 292 |
change uw with (uweight 64) in (value of e). |
| 293 |
clear uw. |
| 294 |
set (uw := uweight 64) in (value of e). |
| 295 |
cbv [Deps.Rows.sub_cps] in e. |
| 296 |
cbv [map_cps2] in e. |
| 297 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 298 |
cbv [Deps.Rows.flatten_cps] in e. |
| 299 |
cbv [hd tl] in e. |
| 300 |
cbv [Deps.Rows.flatten'_cps] in e. |
| 301 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e. |
| 302 |
cbv [Deps.Rows.sum_rows_cps Deps.Rows.sum_rows'_cps rev fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step cpscall cpsbind cpsreturn id] in e; cbn [fst snd combine app] in e. |
| 303 |
cbv [Deps.Rows.Deps.Positional.select] in e. |
| 304 |
cbn [combine map] in e. |
| 305 |
Print Z.zselect. |
| 306 |
cbv -[Deps.Positional.drop_high_to_length] in e. |
| 307 |
clear uw. |
| 308 |
set (uw := fun i : nat => _) in (value of e). |
| 309 |
vm_compute in e. |
| 310 |
|
| 311 |
|
| 312 |
cbv [] in e. |
| 313 |
|
| 314 |
cbv [Deps.Rows.from_columns] |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
set (k := Deps.Rows.mul_cps _ _ _ _) in (value of e) at 1 |
| 319 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 320 |
cbv [List.app List.repeat] in e. |
| 321 |
subst k. |
| 322 |
cbv [Deps.Rows.mul_cps] in e. |
| 323 |
cbv [Deps.Rows.Deps.Positional.to_associational ] in e. |
| 324 |
set (k := map _ _) in (value of e). |
| 325 |
vm_compute in k; subst k. |
| 326 |
Arguments combine _ _ !_ !_. |
| 327 |
cbn [combine] in e. |
| 328 |
cbv [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 329 |
unfold Deps.Rows.Deps.Associational.sat_mul_cps in (value of e) at 1. |
| 330 |
cbv [flat_map_cps flat_map_cps_specialized] in e. |
| 331 |
cbv [Deps.Rows.Deps.Associational.sat_multerm_cps] in e. |
| 332 |
cbn [fst snd] in e. |
| 333 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 334 |
cbv [List.app] in e. |
| 335 |
cbv [Z.mul Z.add Pos.mul Pos.add] in e. |
| 336 |
unfold Deps.Rows.from_associational_cps in (value of e) at 1. |
| 337 |
cbv [Deps.Rows.Deps.Columns.from_associational_cps] in e. |
| 338 |
cbv [Deps.Rows.Deps.Columns.nils] in e. |
| 339 |
cbv [repeat fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step Init.Nat.pred] in e. |
| 340 |
cbv [Deps.Rows.Deps.Columns.Deps.Positional.place] in e. |
| 341 |
cbn [fst snd] in e. |
| 342 |
cbv [nat_rect] in e. |
| 343 |
cbv [cpscall cpsbind cpsreturn] in e. |
| 344 |
set (k := uw 0%nat) in (value of e); vm_compute in k; subst k. |
| 345 |
set (k := uw 1%nat) in (value of e); vm_compute in k; subst k. |
| 346 |
set (k := uw 2%nat) in (value of e); vm_compute in k; subst k. |
| 347 |
set (k := uw 3%nat) in (value of e); vm_compute in k; subst k. |
| 348 |
set (k := uw 4%nat) in (value of e); vm_compute in k; subst k. |
| 349 |
cbv [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 350 |
cbv [Deps.Rows.Deps.Columns.cons_to_nth] in e. |
| 351 |
cbv [update_nth] in e. |
| 352 |
cbv [Deps.Rows.from_columns Deps.Rows.max_column_size Deps.Rows.from_columns' map List.repeat length Nat.max] in e. |
| 353 |
unfold fold_right in (value of e) at 2. |
| 354 |
cbn [snd] in e. |
| 355 |
cbv [Deps.Rows.extract_row] in e. |
| 356 |
cbv [map hd tl List.app] in e. |
| 357 |
cbv delta [fold_right] in e. |
| 358 |
cbn [fst snd] in e. |
| 359 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps] in e. |
| 360 |
cbv [fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step] in e. |
| 361 |
cbv [cpsbind cpscall cpsreturn id] in e. |
| 362 |
cbn [fst snd] in e. |
| 363 |
unfold Deps.Rows.sum_rows_cps at 1 in (value of e). |
| 364 |
cbv [cpscall cpsbind cpsreturn id Deps.Rows.sum_rows'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step rev app] in e. |
| 365 |
cbn [combine fst snd] in e. |
| 366 |
cbv [Deps.Rows.sum_rows_cps cpscall cpsbind cpsreturn id Deps.Rows.sum_rows'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step rev app] in e. |
| 367 |
cbn [fst snd combine] in e. |
| 368 |
cbv [Deps.Rows.add_cps] in e. |
| 369 |
cbv [Deps.Rows.flatten_cps hd tl Deps.Rows.flatten'_cps] in e. |
| 370 |
cbv [fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step] in e. |
| 371 |
cbv [cpsbind cpscall cpsreturn id] in e. |
| 372 |
cbn [fst snd] in e. |
| 373 |
unfold Deps.Rows.sum_rows_cps at 1 in (value of e). |
| 374 |
cbv [cpscall cpsbind cpsreturn id Deps.Rows.sum_rows'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step rev app] in e. |
| 375 |
cbn [combine fst snd] in e. |
| 376 |
cbv [Deps.Rows.sum_rows_cps cpscall cpsbind cpsreturn id Deps.Rows.sum_rows'_cps fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step rev app] in e. |
| 377 |
cbn [fst snd combine] in e. |
| 378 |
cbv [add_cps] in e. |
| 379 |
cbv [Deps.Rows.Deps.Associational.sat_mul_cps] in e. |
| 380 |
cbv [flat_map_cps flat_map_cps_specialized] in e. |
| 381 |
cbv [Deps.Rows.Deps.Associational.sat_multerm_cps] in e. |
| 382 |
cbn [fst snd] in e. |
| 383 |
cbv [cpscall cpsbind cpsreturn id] in e. |
| 384 |
cbv [List.app] in e. |
| 385 |
cbv [Z.mul Z.add Pos.mul Pos.add] in e. |
| 386 |
cbv [Deps.Rows.from_associational_cps] in e. |
| 387 |
cbv [Deps.Rows.Deps.Columns.from_associational_cps] in e. |
| 388 |
cbv [Deps.Rows.Deps.Columns.nils] in e. |
| 389 |
cbv [Deps.Rows.Deps.Positional.zeros] in e. |
| 390 |
cbv [repeat cpsbind cpscall cpsreturn] in e. |
| 391 |
cbv [repeat fold_right_cps2 fold_right_cps2_specialized fold_right_cps2_specialized_step Init.Nat.pred] in e. |
| 392 |
cbv [Deps.Rows.Deps.Columns.Deps.Positional.place] in e. |
| 393 |
cbn [fst snd] in e. |
| 394 |
cbv [nat_rect] in e. |
| 395 |
cbv [cpscall cpsbind cpsreturn] in e. |
| 396 |
set (k := uw 0%nat) in (value of e); vm_compute in k; subst k. |
| 397 |
set (k := uw 1%nat) in (value of e); vm_compute in k; subst k. |
| 398 |
set (k := uw 2%nat) in (value of e); vm_compute in k; subst k. |
| 399 |
set (k := uw 3%nat) in (value of e); vm_compute in k; subst k. |
| 400 |
set (k := uw 4%nat) in (value of e); vm_compute in k; subst k. |
| 401 |
set (k := uw 5%nat) in (value of e); vm_compute in k; subst k. |
| 402 |
Arguments Z.pow !_ !_. |
| 403 |
Arguments Z.mul !_ !_. |
| 404 |
Arguments Z.sub !_ !_. |
| 405 |
Arguments Z.add !_ !_. |
| 406 |
|
| 407 |
cbn [Z.pow Pos.pow Init.Nat.pred nat_rect fst Z.of_nat Pos.of_succ_nat Pos.succ Z.mul Pos.mul Pos.add Pos.iter Z.opp Z.div Z.div_eucl Z.pos_div_eucl Z.leb Z.compare Pos.compare Pos.compare_cont Z.add Z.ltb Z.sub Z.pos_sub Z.succ_double Z.double Z.pow Z.pow_pos Z.modulo Z.eqb Pos.eqb Pos.compare snd Pos.pred_double Z.opp] in e. |
| 408 |
cbv [Deps.Rows.Deps.Columns.cons_to_nth] in e. |
| 409 |
cbv [update_nth] in e. |
| 410 |
cbv [Deps.Rows.from_columns Deps.Rows.max_column_size Deps.Rows.from_columns' map List.repeat length Nat.max] in e. |
| 411 |
cbn [snd] in e. |
| 412 |
cbv [Deps.Rows.extract_row map hd tl List.app] in e. |
| 413 |
cbv delta [fold_right] in e. |
| 414 |
cbn [fst snd] in e. |
| 415 |
cbn [fst snd combine] in e. |
| 416 |
cbv [List.app Lis |
| 417 |
vm_compute in e. |
| 418 |
unfold fold_right in (value of e) at 2.] i |
| 419 |
unfold fold_right in (value of e) at 1. |
| 420 |
|
| 421 |
cbn [fold_right] in e. |
| 422 |
Deps.Rows.Deps.Columns.cons_to_nth Deps.Rows.Deps.Columns.Deps.Positional.place] in e. |
| 423 |
vm_compute in e. |
| 424 |
|
| 425 |
Time Compute @hide _ (fun a b => let m := (2^256 - 2^224 + 2^192 + 2^96 - 1) in mulmod 64 4 m match Z.modinv (-m) (2^64) with |
| 426 |
| Some m' => m' |
| 427 |
| None => 0 |
| 428 |
end (expand_list 0 a 4) (expand_list 0 b 4)). |
| 429 |
Time Compute @hide _ (fun f g => ModOpsAx.carry_mulmod 51 2 (2^255) [(1,19)] 5 (List.seq 0 5 ++ [0; 1])%nat%list (expand_list 0 f 5) (expand_list 0 g 5)). |
| 430 |
Time Eval cbv in @hide _ (fun f g => ModOpsAx.carry_mulmod 51 2 (2^255) [(1,19)] 5 (List.seq 0 5 ++ [0; 1])%nat%list (expand_list 0 f 5) (expand_list 0 g 5)). |
| 431 |
Time Eval lazy in @hide _ (fun f g => ModOpsAx.carry_mulmod 51 2 (2^255) [(1,19)] 5 (List.seq 0 5 ++ [0; 1])%nat%list (expand_list 0 f 5) (expand_list 0 g 5)). |
| 432 |
|
| 433 |
|
| 434 |
*) |