aboutsummaryrefslogtreecommitdiff
path: root/src/ModularArithmetic
diff options
context:
space:
mode:
authorGravatar jadep <jade.philipoom@gmail.com>2016-11-02 00:23:24 -0400
committerGravatar jadep <jade.philipoom@gmail.com>2016-11-02 15:23:46 -0400
commit99077ade35acba69fd31932ffdb8c35b863bcb11 (patch)
tree4e914265c46e566a590a5e571363ed1d5cf3f0d9 /src/ModularArithmetic
parent13834f7089bc166949b6ae1ec833dd16b71a5b49 (diff)
Lift conversion correctness proofs to ModularBaseSystem by providing [pack_rep] and [unpack_rep] lemmas
Diffstat (limited to 'src/ModularArithmetic')
-rw-r--r--src/ModularArithmetic/ModularBaseSystemProofs.v39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ModularArithmetic/ModularBaseSystemProofs.v b/src/ModularArithmetic/ModularBaseSystemProofs.v
index b454daab6..59a6f33db 100644
--- a/src/ModularArithmetic/ModularBaseSystemProofs.v
+++ b/src/ModularArithmetic/ModularBaseSystemProofs.v
@@ -1095,3 +1095,42 @@ Section SquareRootProofs.
End Sqrt5mod8.
End SquareRootProofs.
+
+Section ConversionProofs.
+ Context `{prm :PseudoMersenneBaseParams}.
+ Context {target_widths}
+ (target_widths_nonneg : forall x, In x target_widths -> 0 <= x)
+ (bits_eq : sum_firstn limb_widths (length limb_widths) =
+ sum_firstn target_widths (length target_widths)).
+ Local Notation target_base := (base_from_limb_widths target_widths).
+
+ Lemma pack_rep : forall w,
+ bounded limb_widths (to_list _ w) ->
+ bounded target_widths (to_list _ w) ->
+ rep w (F.of_Z modulus
+ (BaseSystem.decode
+ target_base
+ (to_list _ (pack target_widths_nonneg bits_eq w)))).
+ Proof.
+ intros; cbv [pack ModularBaseSystemList.pack rep].
+ rewrite Tuple.to_list_from_list.
+ apply F.eq_to_Z_iff.
+ rewrite F.to_Z_of_Z.
+ rewrite <-Conversion.convert_correct; auto using length_to_list.
+ Qed.
+
+ Lemma unpack_rep : forall w,
+ bounded target_widths (to_list _ w) ->
+ rep (unpack target_widths_nonneg bits_eq w)
+ (F.of_Z modulus (BaseSystem.decode target_base (to_list _ w))).
+ Proof.
+ intros; cbv [unpack ModularBaseSystemList.unpack rep].
+ apply F.eq_to_Z_iff.
+ rewrite <-from_list_default_eq with (d := 0).
+ rewrite <-decode_mod_Fdecode by apply Conversion.length_convert.
+ rewrite F.to_Z_of_Z.
+ rewrite <-Conversion.convert_correct; auto using length_to_list.
+ Qed.
+
+
+End ConversionProofs.