@@ -5,63 +5,64 @@ Require Import base64.monomorphic.
55(** This module provides helpers to show the equality to debug [reflexivity] when it is too long or
66 failing *)
77Module Eq.
8- Lemma LowLet {A : Set} (e e' : LowM.t A) k k'
8+ Lemma LowLet {A : Set} (e e' : LowM.t A) k k'
99 (H_e : e = e')
1010 (H_k : forall x, k x = k' x) :
11- LowM.Let e k = LowM.Let e' k'.
11+ LowM.Let e k = LowM.Let e' k'.
1212 Proof .
1313 rewrite H_e.
1414 replace k with k' by now apply functional_extensionality.
1515 reflexivity.
1616 Qed .
1717
18- Fixpoint LetMinus {A : Set} (e1 e1' : LowM.t A) (e2 e2' : A -> LowM.t A)
18+ Lemma LetMinus {A : Set} (e1 e1' : LowM.t A) (e2 e2' : A -> LowM.t A)
1919 (H_e1 : e1 = e1')
20- (H_e2 : forall x, e2 x = e2' x)
21- {struct e1} :
22- LowM.let_ e1 e2 = LowM.let_ e1' e2'.
20+ (H_e2 : forall x, e2 x = e2' x) :
21+ LowM.let_ e1 e2 = LowM.let_ e1' e2'.
2322 Proof .
24- destruct e1; rewrite <- H_e1; simpl.
25- { apply H_e2. }
26- { f_equal.
27- apply functional_extensionality; intro x.
28- now rewrite LetMinus with (e1' := k x) (e2' := e2').
29- }
30- { f_equal.
31- apply functional_extensionality; intro x.
32- now rewrite LetMinus with (e1' := k x) (e2' := e2').
33- }
34- { f_equal.
35- apply functional_extensionality; intro x.
36- now rewrite LetMinus with (e1' := k x) (e2' := e2').
37- }
38- { reflexivity. }
23+ rewrite H_e1.
24+ replace e2 with e2' by now apply functional_extensionality.
25+ reflexivity.
3926 Qed .
4027
4128 Lemma LetStar e1 e1' e2 e2'
4229 (H_e1 : e1 = e1')
4330 (H_e2 : forall x, e2 x = e2' x) :
44- M.let_ e1 e2 = M.let_ e1' e2'.
31+ M.let_ e1 e2 = M.let_ e1' e2'.
4532 Proof .
46- apply LetMinus; hauto lq: on.
33+ rewrite H_e1.
34+ replace e2 with e2' by now apply functional_extensionality.
35+ reflexivity.
4736 Qed .
4837
4938 Lemma LetTilde e1 e1' e2 e2'
5039 (H_e1 : e1 = e1')
5140 (H_e2 : forall x, e2 x = e2' x) :
52- M.let_strong e1 e2 = M.let_strong e1' e2'.
41+ M.let_strong e1 e2 = M.let_strong e1' e2'.
5342 Proof .
54- apply LowLet; hauto lq: on.
43+ rewrite H_e1.
44+ replace e2 with e2' by now apply functional_extensionality.
45+ reflexivity.
5546 Qed .
5647
5748 Lemma If e e' t t' f f'
5849 (H_e : e = e')
5950 (H_t : t = t')
6051 (H_f : f = f') :
61- M.if_ e t f = M.if_ e' t' f'.
52+ M.if_ e t f = M.if_ e' t' f'.
6253 Proof .
6354 f_equal; assumption.
6455 Qed .
56+
57+ Ltac tactic :=
58+ repeat (
59+ intro ||
60+ apply LowLet ||
61+ apply LetMinus ||
62+ apply LetStar ||
63+ apply LetTilde ||
64+ apply If
65+ ).
6566End Eq.
6667
6768Module Field .
@@ -92,7 +93,7 @@ Module Field.
9293 | _ => M.impossible "wrong number of arguments"
9394 end .
9495
95- Lemma eq_to_be_radix₁ : get_function "to_be_radix" 1 = closure (to_be_radix (U32.Build_t 40) ).
96+ Lemma eq_to_be_radix₁ : get_function "to_be_radix" 1 = closure (to_be_radix {| Integer.value := 40 |} ).
9697 Proof .
9798 autorewrite with get_function; f_equal.
9899 Qed .
@@ -101,7 +102,7 @@ End Field.
101102
102103Module Base64EncodeBE.
103104 Record t : Set := {
104- table : Array.t U8.t (U32.Build_t 64) ;
105+ table : Array.t U8.t {| Integer.value := 64 |} ;
105106 }.
106107
107108 Definition new (α : list Value.t) : M.t :=
@@ -231,7 +232,7 @@ Definition base64_encode_elements (InputElements : U32.t) (α : list Value.t) :
231232 |) ]] in
232233 let ~ result := [[ M.copy_mutable (|
233234 M.alloc (Value.Array (
234- List.repeat (Value.Integer IntegerKind.U8 0) (Z.to_nat (Integer.to_Z InputElements ))
235+ List.repeat (Value.Integer IntegerKind.U8 0) (Z.to_nat InputElements. (Integer.value ))
235236 ))
236237 |) ]] in
237238 do~ [[
@@ -270,7 +271,7 @@ Definition base64_encode_elements (InputElements : U32.t) (α : list Value.t) :
270271 end .
271272
272273Lemma eq_base64_encode_elements₀ :
273- get_function "base64_encode_elements" 0 = closure (base64_encode_elements (U32.Build_t 118) ).
274+ get_function "base64_encode_elements" 0 = closure (base64_encode_elements {| Integer.value := 118 |} ).
274275Proof .
275276 autorewrite with get_function; apply f_equal.
276277 apply functional_extensionality; intro α.
@@ -288,7 +289,7 @@ Definition base64_encode (InputBytes OutputElements : U32.t) (α : list Value.t)
288289 let ~ result := [[ M.copy_mutable (|
289290 M.alloc (Value.Array (List.repeat
290291 (Value.Integer IntegerKind.U8 0)
291- (Z.to_nat (Integer.to_Z OutputElements ))
292+ (Z.to_nat OutputElements. (Integer.value ))
292293 ))
293294 |) ]] in
294295 let ~ BASE64_ELEMENTS_PER_CHUNK := [[ M.copy (|
@@ -371,7 +372,7 @@ Definition base64_encode (InputBytes OutputElements : U32.t) (α : list Value.t)
371372 ]] in
372373 let ~ slice_base64_chunks := [[ M.copy (|
373374 M.alloc (M.call_closure (|
374- closure (Field .to_be_radix (U32.Build_t 30) ),
375+ closure (Field .to_be_radix {| Integer.value := 30 |} ),
375376 [
376377 M.read (| slice |);
377378 Value.Integer IntegerKind.U32 64
@@ -478,7 +479,7 @@ Definition base64_encode (InputBytes OutputElements : U32.t) (α : list Value.t)
478479 ]] in
479480 let ~ slice_base64_chunks := [[ M.copy (|
480481 M.alloc (M.call_closure (|
481- closure (Field .to_be_radix (U32.Build_t 30) ),
482+ closure (Field .to_be_radix {| Integer.value := 30 |} ),
482483 [
483484 M.read (| slice |);
484485 Value.Integer IntegerKind.U32 64
@@ -529,7 +530,7 @@ Definition base64_encode (InputBytes OutputElements : U32.t) (α : list Value.t)
529530 M.alloc (M.write (|
530531 result,
531532 M.call_closure (|
532- closure (base64_encode_elements (U32.Build_t 118) ),
533+ closure (base64_encode_elements {| Integer.value := 118 |} ),
533534 [
534535 M.read (| result |)
535536 ]
@@ -547,44 +548,14 @@ Definition base64_encode (InputBytes OutputElements : U32.t) (α : list Value.t)
547548 end .
548549
549550Lemma eq_base64_encode₀ :
550- get_function "base64_encode" 0 = closure (base64_encode (U32.Build_t 88) (U32.Build_t 118) ).
551+ get_function "base64_encode" 0 = closure (base64_encode {| Integer.value := 88 |} {| Integer.value := 118 |} ).
551552Proof .
552553 autorewrite with get_function; apply f_equal.
553554 apply functional_extensionality; intro α.
554555 unfold base64_encode₀.
555556 autorewrite with get_function_eq.
556557 destruct α as [|input α]; [reflexivity|].
557558 destruct α; [|reflexivity].
558- apply Eq.LetStar; [|reflexivity].
559- apply Eq.LetTilde; [reflexivity|intro result].
560- apply Eq.LetTilde; [reflexivity|intro BASE64_ELEMENTS_PER_CHUNK].
561- apply Eq.LetTilde; [reflexivity|intro BYTES_PER_CHUNK].
562- apply Eq.LetTilde; [reflexivity|intro num_chunks].
563- apply Eq.LetTilde. {
564- apply Eq.LetStar; [reflexivity|intro v].
565- apply Eq.If; [reflexivity | | reflexivity].
566- apply Eq.LetTilde. {
567- reflexivity.
568- }
569- intro.
570- apply Eq.LetTilde; [reflexivity|intro bytes_in_final_chunk].
571- apply Eq.LetTilde; [reflexivity|intro slice].
572- apply Eq.LetTilde. {
573- reflexivity.
574- }
575- intro.
576- apply Eq.LetTilde. {
577- reflexivity.
578- }
579- intro.
580- apply Eq.LetTilde; [reflexivity|intro slice_base64_chunks].
581- apply Eq.LetTilde; [reflexivity|intro num_elements_in_final_chunk].
582- apply Eq.LetTilde. {
583- reflexivity.
584- }
585- intro.
586- reflexivity.
587- }
588- intro.
559+ apply Eq.LetStar; [reflexivity|intro result].
589560 reflexivity.
590561Qed .
0 commit comments