Skip to content

Commit 2296a3d

Browse files
committed
Cleaned up PushButtonSynthesis/DettmanMultiplication.v
Replaced a bunch of references to (Z.log2_up s) with (Z.log2 s), since (in the dettman_multiplication_mod_ops module) we now stipulate that s is a power of 2.
1 parent a9d84a9 commit 2296a3d

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Arithmetic/DettmanMultiplication.v

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ Module dettman_multiplication_mod_ops.
312312
(last_limb_width : nat)
313313
(p_nz : s - Associational.eval c <> 0)
314314
(n_gteq_4 : (4 <= n)%nat)
315-
(last_limb_width_small : last_limb_width * n <= Z.log2_up s)
315+
(last_limb_width_small : last_limb_width * n <= Z.log2 s)
316316
(last_limb_width_big : 1 <= last_limb_width)
317317
(s_power_of_2 : 2 ^ (Z.log2 s) = s).
318318

319-
(* I do want to have Z.log2_up s, not Z.log2_up (s - c) below. We want to ensure that weight (n - 1) <= s <= weight limbs *)
320-
Local Notation limbwidth_num' := (Z.log2_up s - last_limb_width).
319+
(* I do want to have Z.log2 s, not Z.log2_up (s - c) below. We want to ensure that weight (n - 1) <= s <= weight limbs *)
320+
Local Notation limbwidth_num' := (Z.log2 s - last_limb_width).
321321
Local Notation limbwidth_den' := (n - 1). (* can't use Q here, or else reification doesn't work *)
322322

323323
Context
@@ -333,7 +333,7 @@ Module dettman_multiplication_mod_ops.
333333
Definition mulmod := mulmod s c register_width n weight.
334334
Definition squaremod := squaremod s c register_width n weight.
335335

336-
Lemma n_small : n - 1 <= Z.log2_up s - last_limb_width.
336+
Lemma n_small : n - 1 <= Z.log2 s - last_limb_width.
337337
Proof.
338338
replace (Z.of_nat n) with (Z.of_nat n - 1 + 1) in last_limb_width_small by lia.
339339
remember (Z.of_nat n - 1) as n'.
@@ -404,7 +404,7 @@ Module dettman_multiplication_mod_ops.
404404

405405
Lemma s_gt_0 : 0 < s.
406406
assert (H: s <= 0 \/ 0 < s) by lia. destruct H as [H|H].
407-
- apply Z.log2_up_nonpos in H. lia.
407+
- apply Z.log2_nonpos in H. lia.
408408
- assumption.
409409
Qed.
410410

src/PushButtonSynthesis/DettmanMultiplication.v

+8-9
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Section __.
112112
Local Instance no_select_size : no_select_size_opt := no_select_size_of_no_select machine_wordsize.
113113
Local Instance split_mul_to : split_mul_to_opt := split_mul_to_of_should_split_mul machine_wordsize possible_values.
114114
Local Instance split_multiret_to : split_multiret_to_opt := split_multiret_to_of_should_split_multiret machine_wordsize possible_values.
115-
115+
116116
(** Note: If you change the name or type signature of this
117117
function, you will need to update the code in CLI.v *)
118118
Definition check_args {T} (requests : list string) (res : Pipeline.ErrorT T)
@@ -122,26 +122,25 @@ Section __.
122122
(fun v => (true, v))
123123
[(negb (s - c =? 0), Pipeline.Values_not_provably_distinctZ "s - c <> 0" (s - c) 0)
124124
; (4 <=? n, Pipeline.Value_not_leZ "4 <= n" 3 n)
125-
; (last_limb_width * n <=? Z.log2_up s, Pipeline.Value_not_leZ "last_limb_width * n <= Z.log2_up s" (last_limb_width * n) (Z.log2_up s))
125+
; (last_limb_width * n <=? Z.log2 s, Pipeline.Value_not_leZ "last_limb_width * n <= Z.log2 s" (last_limb_width * n) (Z.log2 s))
126126
; (1 <=? last_limb_width, Pipeline.Value_not_leZ "1 <= last_limb_width" 1 last_limb_width)
127127
; (2 ^ (Z.log2 s) =? s, Pipeline.Values_not_provably_equalZ "2 ^ (Z.log2 s) = s" (2 ^ Z.log2 s) s)
128-
; (Z.log2_up s - last_limb_width <=? (Z.to_nat machine_wordsize) * (n - 1), Pipeline.Value_not_leZ "Z.log2_up s - last_limb_width <= (Z.to_nat machine_wordsize) * (n - 1)" (Z.log2_up s - last_limb_width) (Z.to_nat machine_wordsize * (n - 1)))
129-
; (Z.log2 s <=? n * (Z.log2_up s - last_limb_width) / (n - 1), Pipeline.Value_not_leZ "Z.log2 s <= n * (Z.log2_up s - last_limb_width) / (n - 1)" (Z.log2 s) (n * (Z.log2_up s - last_limb_width) / (n - 1)))
128+
; (Z.log2 s - last_limb_width <=? (Z.to_nat machine_wordsize) * (n - 1), Pipeline.Value_not_leZ "Z.log2 s - last_limb_width <= (Z.to_nat machine_wordsize) * (n - 1)" (Z.log2 s - last_limb_width) (Z.to_nat machine_wordsize * (n - 1)))
129+
; (Z.log2 s <=? n * (Z.log2 s - last_limb_width) / (n - 1), Pipeline.Value_not_leZ "Z.log2 s <= n * (Z.log2 s - last_limb_width) / (n - 1)" (Z.log2 s) (n * (Z.log2 s - last_limb_width) / (n - 1)))
130130
])
131131
res.
132132

133133
Context (requests : list string)
134134
(curve_good : check_args requests (Success tt) = Success tt).
135135

136-
(* should probably use limbwidth_num, limbwidth_den to make this less confusing-looking *)
137136
Lemma use_curve_good
138137
: s - c <> 0
139138
/\ (4 <= n)
140-
/\ last_limb_width * n <= Z.log2_up s
139+
/\ last_limb_width * n <= Z.log2 s
141140
/\ 1 <= last_limb_width
142141
/\ 2 ^ (Z.log2 s) = s
143-
/\ Z.log2_up s - last_limb_width <= (Z.to_nat machine_wordsize) * (n - 1)
144-
/\ Z.log2 s <= n * (Z.log2_up s - last_limb_width) / (n - 1).
142+
/\ Z.log2 s - last_limb_width <= (Z.to_nat machine_wordsize) * (n - 1)
143+
/\ Z.log2 s <= n * (Z.log2 s - last_limb_width) / (n - 1).
145144
Proof using curve_good. prepare_use_curve_good (). Qed.
146145

147146
Local Notation evalf := (eval weightf n).
@@ -157,7 +156,7 @@ Section __.
157156
summary
158157
correctness)
159158
(only parsing, at level 10, summary at next level, correctness at next level).
160-
159+
161160
Definition mul
162161
:= Pipeline.BoundsPipeline
163162
false (* subst01 *)

0 commit comments

Comments
 (0)