Library QedkConcrete.swucomplex
SWU coordinates over the generated BLS extension arithmetic
From Stdlib Require Import ZArith Lia Field.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Curve
QedkConcrete.nativecomplexbounds QedkConcrete.nativefieldbounds
QedkConcrete.primefieldarith QedkConcrete.blscomplexsqrt
QedkConcrete.blscomplexresidues QedkConcrete.complexswumath
QedkConcrete.complexresiduefield.
Set Default Goal Selector "!".
Module Bls := Ec.Bls12_381.
Module SWU := Ec.Curve.SWU_method.
Module QR := QuadraticResidue.
Section Map.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation field := (@blscomplexresidues.field).
Local Notation complex := (@blscomplexresidues.complex).
Local Notation elt := (@Complex.t _ complex).
Local Notation p := (@PF.modulus (@blscomplexresidues.field)).
Local Notation bounded := (@complexBound _ complex (@primeFieldBound field)).
Local Notation residue := (@blsComplexResidue).
Local Notation mul := (@Complex.op_star _ complex).
Local Notation add := (@Complex.op_plus _ complex).
Local Notation sub := (@Complex.op_minus _ complex).
Local Notation divide := (@Complex.op_div _ complex).
Local Notation equal := (@Complex.op_eq _ complex).
Local Definition zero := @Complex.zero _ complex.
Local Definition one := @Complex.op_tildedollar _ complex 1%Z.
Local Notation "0" := (QR.zero p).
Local Notation "1" := (QR.one p).
Local Infix "+" := (QR.add p).
Local Infix "×" := (QR.mul p).
Local Notation "- x" := (QR.opp p x).
Local Infix "-" := (QR.sub p).
Local Infix "/" := (QR.divide p).
Variables a b z : elt.
Variable sqrtRatio : elt → elt → bool × elt.
Variable sign : elt → bool.
Definition swuComplexApply {Result : Type} (finish : elt → elt → Result) u :=
let t := mul z (mul u u) in
let w := add (mul t t) t in
let n := mul b (add w one) in
let d := mul a (if equal w zero then z else sub zero w) in
let d2 := mul d d in
let d3 := mul d2 d in
let gnum := add (mul (add (mul n n) (mul a d2)) n) (mul b d3) in
let '(square, root) := sqrtRatio gnum d3 in
let x := divide (if square then n else mul t n) d in
let y := if square then root else mul (mul t u) root in
finish x (if Bool.eqb (sign u) (sign y) then y else sub zero y).
Definition swuComplexCoordinates := swuComplexApply (fun x y ⇒ (x,y)).
Hypotheses (Hanz : residue a ≠ 0) (Hznz : residue z ≠ 0).
Hypothesis HratioBound : ∀ top bottom, bounded (snd (sqrtRatio top bottom)).
Hypothesis HratioCorrect : ∀ top bottom,
let '(square, root) := sqrtRatio top bottom in
mul root root = if square then divide top bottom else mul z (divide top bottom).
Hypothesis Hexceptional :
let n := mul b (add zero one) in
let d := mul a z in
let d2 := mul d d in
let d3 := mul d2 d in
fst (sqrtRatio (add (mul (add (mul n n) (mul a d2)) n) (mul b d3)) d3) = true.
Local Definition prime := @blsprimality.bls_generated_modulus_prime .
Local Definition four := @legendretests.bls_modulus_three_mod_four .
Add Field extension_field : (QR.quadratic_field p prime four).
Local Lemma equal_true x y : equal x y = true ↔ x = y.
Proof.
destruct x as [xr xi], y as [yr yi].
change ((@PF.op_eq field xr yr && @PF.op_eq field xi yi)%bool = true ↔
@Complex.t.Build _ complex xr xi = @Complex.t.Build _ complex yr yi).
rewrite Bool.andb_true_iff, !prime_eq_true.
split; [intros [-> ->]; reflexivity|intro H; inversion H; auto].
Qed.
Local Ltac bounds := repeat first [assumption | match goal with
| |- bounded (mul _ _) ⇒ exact (@bls_complex_mul_bound _ _)
| |- bounded (add _ _) ⇒ apply complex_add_bound;
[exact (@bls_complex_base_closed)| |]
| |- bounded (sub _ _) ⇒ apply complex_sub_bound;
[exact (@bls_complex_base_closed)| |]
end].
Theorem swu_complex_coordinates_valid u :
let '(x,y) := swuComplexCoordinates u in
bounded x ∧ bounded y ∧
residue y × residue y = residue x × (residue x × residue x + residue a) + residue b.
Proof.
unfold swuComplexCoordinates, swuComplexApply.
set (t := mul z (mul u u)).
set (w := add (mul t t) t).
set (n := mul b (add w one)).
set (d := mul a (if equal w zero then z else sub zero w)).
set (d2 := mul d d).
set (d3 := mul d2 d).
set (gnum := add (mul (add (mul n n) (mul a d2)) n) (mul b d3)).
assert (H0 : bounded zero) by
(apply complex_zero_bound; exact (@bls_complex_base_closed)).
assert (H1 : bounded one) by
(apply complex_int_bound; exact (@bls_complex_base_closed)).
assert (Hzero : residue zero = 0) by apply (@bls_complex_residue_zero).
assert (Hone : residue one = 1) by apply (@bls_complex_residue_one).
assert (Ht : bounded t) by (unfold t; bounds).
assert (Hw : bounded w) by (unfold w; bounds).
assert (Hn : bounded n) by (unfold n; bounds).
assert (Hd : bounded d) by (unfold d; bounds).
assert (Hd2 : bounded d2) by (unfold d2; bounds).
assert (Hd3 : bounded d3) by (unfold d3; bounds).
assert (Hnum : bounded gnum) by (unfold gnum; bounds).
assert (Hdnz : residue d ≠ 0).
{ unfold d. rewrite (@bls_complex_residue_mul).
apply complex_product_nonzero; [exact prime|exact four|exact Hanz|].
destruct (equal w zero) eqn:Htest; [exact Hznz|].
rewrite (@bls_complex_residue_sub) by assumption. rewrite Hzero.
intro H. change (0-residue w = 0) in H.
assert (Heq : w = zero).
{ apply (@bls_complex_residue_injective); [exact Hw|exact H0|].
rewrite Hzero. replace (residue w) with (-(0-residue w)) by ring.
rewrite H. reflexivity. }
apply equal_true in Heq. congruence. }
assert (Hd3nz : residue d3 ≠ 0).
{ unfold d3, d2. rewrite !(@bls_complex_residue_mul).
apply (complex_product_nonzero p prime four);
[apply (complex_product_nonzero p prime four)|]; assumption. }
assert (HtR : residue t = residue z × residue u × residue u).
{ unfold t. rewrite !(@bls_complex_residue_mul). ring. }
assert (HwR : residue w = residue t × residue t + residue t).
{ unfold w. rewrite (@bls_complex_residue_add) by bounds.
rewrite (@bls_complex_residue_mul). reflexivity. }
assert (HnR : residue n = residue b × (residue w + 1)).
{ unfold n. rewrite (@bls_complex_residue_mul), (@bls_complex_residue_add) by bounds.
rewrite Hone. reflexivity. }
assert (HqR : residue (divide gnum d3) =
(residue n / residue d) ×
((residue n / residue d) × (residue n / residue d) + residue a) + residue b).
{ rewrite (@bls_complex_residue_div) by assumption. unfold gnum, d3, d2.
repeat first [rewrite (@bls_complex_residue_add) by bounds | rewrite (@bls_complex_residue_mul)].
replace ((residue n × residue n + residue a × (residue d × residue d)) × residue n +
residue b × (residue d × residue d × residue d)) with
(residue n × residue n × residue n + residue a × residue n × (residue d × residue d) +
residue b × (residue d × residue d × residue d)) by ring.
apply (complex_swu_first_candidate p prime four); exact Hdnz. }
pose proof (HratioBound gnum d3) as HrootBound.
pose proof (HratioCorrect gnum d3) as HrootSquare.
destruct (sqrtRatio gnum d3) as [square root] eqn:Hratio.
cbn [snd] in HrootBound.
assert (Hspecial : equal w zero = true → square = true).
{ intro Htest. pose proof ((proj1 (equal_true w zero)) Htest) as Hwzero.
assert (Hfirst : fst (sqrtRatio gnum d3) = true).
{ unfold gnum, n, d3, d2, d. rewrite Htest, Hwzero. exact Hexceptional. }
rewrite Hratio in Hfirst. exact Hfirst. }
set (x := divide (if square then n else mul t n) d).
set (y := if square then root else mul (mul t u) root).
change (let finalY := if Bool.eqb (sign u) (sign y) then y else sub zero y in
bounded x ∧ bounded finalY ∧ residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
assert (Hx : bounded x) by (apply (@bls_complex_mul_bound)).
assert (Hy : bounded y) by (unfold y; destruct square; bounds).
assert (HcurveR : residue y × residue y =
residue x × (residue x × residue x + residue a) + residue b).
{ apply (f_equal residue) in HrootSquare.
destruct square.
- unfold x, y. rewrite (@bls_complex_residue_div) by assumption.
rewrite <- HqR, <- (@bls_complex_residue_mul). exact HrootSquare.
- assert (Htest : equal w zero = false).
{ destruct (equal w zero); [|reflexivity]. specialize (Hspecial eq_refl). discriminate. }
assert (HwRnz : residue t × residue t + residue t ≠ 0).
{ rewrite <- HwR. intro H.
assert (Heq : w = zero).
{ apply (@bls_complex_residue_injective); [exact Hw|exact H0|]. rewrite Hzero. exact H. }
apply equal_true in Heq. congruence. }
assert (HdR : residue d = -residue a × (residue t × residue t + residue t)).
{ unfold d. rewrite Htest, (@bls_complex_residue_mul), (@bls_complex_residue_sub) by assumption.
rewrite Hzero, HwR. ring. }
assert (Hscale :
(residue t × (residue n / residue d)) ×
((residue t × (residue n / residue d)) ×
(residue t × (residue n / residue d)) + residue a) + residue b =
(residue t × residue t × residue t) ×
((residue n / residue d) ×
((residue n / residue d) × (residue n / residue d) + residue a) + residue b)).
{ rewrite HnR, HwR, HdR. apply (complex_swu_second_candidate p prime four); assumption. }
unfold x, y. rewrite (@bls_complex_residue_div) by assumption.
rewrite !(@bls_complex_residue_mul).
replace ((residue t × residue n) / residue d) with
(residue t × (residue n / residue d)) by (unfold QR.divide; ring).
rewrite Hscale, <- HqR, HtR.
apply complex_swu_scaled_root; [exact prime|exact four|].
rewrite !(@bls_complex_residue_mul) in HrootSquare. exact HrootSquare. }
clearbody x y.
set (finalY := if Bool.eqb (sign u) (sign y) then y else sub zero y).
assert (Hfinal : bounded finalY) by (unfold finalY; destruct (Bool.eqb _ _); bounds).
assert (HfinalR : residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
{ unfold finalY. destruct (Bool.eqb _ _); [exact HcurveR|].
rewrite (@bls_complex_residue_sub) by assumption. rewrite Hzero.
replace ((0-residue y)*(0-residue y)) with (residue y×residue y) by ring.
exact HcurveR. }
change (bounded x ∧ bounded finalY ∧ residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
split; [exact Hx|]. split; assumption.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Curve
QedkConcrete.nativecomplexbounds QedkConcrete.nativefieldbounds
QedkConcrete.primefieldarith QedkConcrete.blscomplexsqrt
QedkConcrete.blscomplexresidues QedkConcrete.complexswumath
QedkConcrete.complexresiduefield.
Set Default Goal Selector "!".
Module Bls := Ec.Bls12_381.
Module SWU := Ec.Curve.SWU_method.
Module QR := QuadraticResidue.
Section Map.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation field := (@blscomplexresidues.field).
Local Notation complex := (@blscomplexresidues.complex).
Local Notation elt := (@Complex.t _ complex).
Local Notation p := (@PF.modulus (@blscomplexresidues.field)).
Local Notation bounded := (@complexBound _ complex (@primeFieldBound field)).
Local Notation residue := (@blsComplexResidue).
Local Notation mul := (@Complex.op_star _ complex).
Local Notation add := (@Complex.op_plus _ complex).
Local Notation sub := (@Complex.op_minus _ complex).
Local Notation divide := (@Complex.op_div _ complex).
Local Notation equal := (@Complex.op_eq _ complex).
Local Definition zero := @Complex.zero _ complex.
Local Definition one := @Complex.op_tildedollar _ complex 1%Z.
Local Notation "0" := (QR.zero p).
Local Notation "1" := (QR.one p).
Local Infix "+" := (QR.add p).
Local Infix "×" := (QR.mul p).
Local Notation "- x" := (QR.opp p x).
Local Infix "-" := (QR.sub p).
Local Infix "/" := (QR.divide p).
Variables a b z : elt.
Variable sqrtRatio : elt → elt → bool × elt.
Variable sign : elt → bool.
Definition swuComplexApply {Result : Type} (finish : elt → elt → Result) u :=
let t := mul z (mul u u) in
let w := add (mul t t) t in
let n := mul b (add w one) in
let d := mul a (if equal w zero then z else sub zero w) in
let d2 := mul d d in
let d3 := mul d2 d in
let gnum := add (mul (add (mul n n) (mul a d2)) n) (mul b d3) in
let '(square, root) := sqrtRatio gnum d3 in
let x := divide (if square then n else mul t n) d in
let y := if square then root else mul (mul t u) root in
finish x (if Bool.eqb (sign u) (sign y) then y else sub zero y).
Definition swuComplexCoordinates := swuComplexApply (fun x y ⇒ (x,y)).
Hypotheses (Hanz : residue a ≠ 0) (Hznz : residue z ≠ 0).
Hypothesis HratioBound : ∀ top bottom, bounded (snd (sqrtRatio top bottom)).
Hypothesis HratioCorrect : ∀ top bottom,
let '(square, root) := sqrtRatio top bottom in
mul root root = if square then divide top bottom else mul z (divide top bottom).
Hypothesis Hexceptional :
let n := mul b (add zero one) in
let d := mul a z in
let d2 := mul d d in
let d3 := mul d2 d in
fst (sqrtRatio (add (mul (add (mul n n) (mul a d2)) n) (mul b d3)) d3) = true.
Local Definition prime := @blsprimality.bls_generated_modulus_prime .
Local Definition four := @legendretests.bls_modulus_three_mod_four .
Add Field extension_field : (QR.quadratic_field p prime four).
Local Lemma equal_true x y : equal x y = true ↔ x = y.
Proof.
destruct x as [xr xi], y as [yr yi].
change ((@PF.op_eq field xr yr && @PF.op_eq field xi yi)%bool = true ↔
@Complex.t.Build _ complex xr xi = @Complex.t.Build _ complex yr yi).
rewrite Bool.andb_true_iff, !prime_eq_true.
split; [intros [-> ->]; reflexivity|intro H; inversion H; auto].
Qed.
Local Ltac bounds := repeat first [assumption | match goal with
| |- bounded (mul _ _) ⇒ exact (@bls_complex_mul_bound _ _)
| |- bounded (add _ _) ⇒ apply complex_add_bound;
[exact (@bls_complex_base_closed)| |]
| |- bounded (sub _ _) ⇒ apply complex_sub_bound;
[exact (@bls_complex_base_closed)| |]
end].
Theorem swu_complex_coordinates_valid u :
let '(x,y) := swuComplexCoordinates u in
bounded x ∧ bounded y ∧
residue y × residue y = residue x × (residue x × residue x + residue a) + residue b.
Proof.
unfold swuComplexCoordinates, swuComplexApply.
set (t := mul z (mul u u)).
set (w := add (mul t t) t).
set (n := mul b (add w one)).
set (d := mul a (if equal w zero then z else sub zero w)).
set (d2 := mul d d).
set (d3 := mul d2 d).
set (gnum := add (mul (add (mul n n) (mul a d2)) n) (mul b d3)).
assert (H0 : bounded zero) by
(apply complex_zero_bound; exact (@bls_complex_base_closed)).
assert (H1 : bounded one) by
(apply complex_int_bound; exact (@bls_complex_base_closed)).
assert (Hzero : residue zero = 0) by apply (@bls_complex_residue_zero).
assert (Hone : residue one = 1) by apply (@bls_complex_residue_one).
assert (Ht : bounded t) by (unfold t; bounds).
assert (Hw : bounded w) by (unfold w; bounds).
assert (Hn : bounded n) by (unfold n; bounds).
assert (Hd : bounded d) by (unfold d; bounds).
assert (Hd2 : bounded d2) by (unfold d2; bounds).
assert (Hd3 : bounded d3) by (unfold d3; bounds).
assert (Hnum : bounded gnum) by (unfold gnum; bounds).
assert (Hdnz : residue d ≠ 0).
{ unfold d. rewrite (@bls_complex_residue_mul).
apply complex_product_nonzero; [exact prime|exact four|exact Hanz|].
destruct (equal w zero) eqn:Htest; [exact Hznz|].
rewrite (@bls_complex_residue_sub) by assumption. rewrite Hzero.
intro H. change (0-residue w = 0) in H.
assert (Heq : w = zero).
{ apply (@bls_complex_residue_injective); [exact Hw|exact H0|].
rewrite Hzero. replace (residue w) with (-(0-residue w)) by ring.
rewrite H. reflexivity. }
apply equal_true in Heq. congruence. }
assert (Hd3nz : residue d3 ≠ 0).
{ unfold d3, d2. rewrite !(@bls_complex_residue_mul).
apply (complex_product_nonzero p prime four);
[apply (complex_product_nonzero p prime four)|]; assumption. }
assert (HtR : residue t = residue z × residue u × residue u).
{ unfold t. rewrite !(@bls_complex_residue_mul). ring. }
assert (HwR : residue w = residue t × residue t + residue t).
{ unfold w. rewrite (@bls_complex_residue_add) by bounds.
rewrite (@bls_complex_residue_mul). reflexivity. }
assert (HnR : residue n = residue b × (residue w + 1)).
{ unfold n. rewrite (@bls_complex_residue_mul), (@bls_complex_residue_add) by bounds.
rewrite Hone. reflexivity. }
assert (HqR : residue (divide gnum d3) =
(residue n / residue d) ×
((residue n / residue d) × (residue n / residue d) + residue a) + residue b).
{ rewrite (@bls_complex_residue_div) by assumption. unfold gnum, d3, d2.
repeat first [rewrite (@bls_complex_residue_add) by bounds | rewrite (@bls_complex_residue_mul)].
replace ((residue n × residue n + residue a × (residue d × residue d)) × residue n +
residue b × (residue d × residue d × residue d)) with
(residue n × residue n × residue n + residue a × residue n × (residue d × residue d) +
residue b × (residue d × residue d × residue d)) by ring.
apply (complex_swu_first_candidate p prime four); exact Hdnz. }
pose proof (HratioBound gnum d3) as HrootBound.
pose proof (HratioCorrect gnum d3) as HrootSquare.
destruct (sqrtRatio gnum d3) as [square root] eqn:Hratio.
cbn [snd] in HrootBound.
assert (Hspecial : equal w zero = true → square = true).
{ intro Htest. pose proof ((proj1 (equal_true w zero)) Htest) as Hwzero.
assert (Hfirst : fst (sqrtRatio gnum d3) = true).
{ unfold gnum, n, d3, d2, d. rewrite Htest, Hwzero. exact Hexceptional. }
rewrite Hratio in Hfirst. exact Hfirst. }
set (x := divide (if square then n else mul t n) d).
set (y := if square then root else mul (mul t u) root).
change (let finalY := if Bool.eqb (sign u) (sign y) then y else sub zero y in
bounded x ∧ bounded finalY ∧ residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
assert (Hx : bounded x) by (apply (@bls_complex_mul_bound)).
assert (Hy : bounded y) by (unfold y; destruct square; bounds).
assert (HcurveR : residue y × residue y =
residue x × (residue x × residue x + residue a) + residue b).
{ apply (f_equal residue) in HrootSquare.
destruct square.
- unfold x, y. rewrite (@bls_complex_residue_div) by assumption.
rewrite <- HqR, <- (@bls_complex_residue_mul). exact HrootSquare.
- assert (Htest : equal w zero = false).
{ destruct (equal w zero); [|reflexivity]. specialize (Hspecial eq_refl). discriminate. }
assert (HwRnz : residue t × residue t + residue t ≠ 0).
{ rewrite <- HwR. intro H.
assert (Heq : w = zero).
{ apply (@bls_complex_residue_injective); [exact Hw|exact H0|]. rewrite Hzero. exact H. }
apply equal_true in Heq. congruence. }
assert (HdR : residue d = -residue a × (residue t × residue t + residue t)).
{ unfold d. rewrite Htest, (@bls_complex_residue_mul), (@bls_complex_residue_sub) by assumption.
rewrite Hzero, HwR. ring. }
assert (Hscale :
(residue t × (residue n / residue d)) ×
((residue t × (residue n / residue d)) ×
(residue t × (residue n / residue d)) + residue a) + residue b =
(residue t × residue t × residue t) ×
((residue n / residue d) ×
((residue n / residue d) × (residue n / residue d) + residue a) + residue b)).
{ rewrite HnR, HwR, HdR. apply (complex_swu_second_candidate p prime four); assumption. }
unfold x, y. rewrite (@bls_complex_residue_div) by assumption.
rewrite !(@bls_complex_residue_mul).
replace ((residue t × residue n) / residue d) with
(residue t × (residue n / residue d)) by (unfold QR.divide; ring).
rewrite Hscale, <- HqR, HtR.
apply complex_swu_scaled_root; [exact prime|exact four|].
rewrite !(@bls_complex_residue_mul) in HrootSquare. exact HrootSquare. }
clearbody x y.
set (finalY := if Bool.eqb (sign u) (sign y) then y else sub zero y).
assert (Hfinal : bounded finalY) by (unfold finalY; destruct (Bool.eqb _ _); bounds).
assert (HfinalR : residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
{ unfold finalY. destruct (Bool.eqb _ _); [exact HcurveR|].
rewrite (@bls_complex_residue_sub) by assumption. rewrite Hzero.
replace ((0-residue y)*(0-residue y)) with (residue y×residue y) by ring.
exact HcurveR. }
change (bounded x ∧ bounded finalY ∧ residue finalY × residue finalY =
residue x × (residue x × residue x + residue a) + residue b).
split; [exact Hx|]. split; assumption.
Qed.
Pass the coordinates directly to the generated point constructor.
Theorem swu_complex_apply_valid {Result : Type} (finish : elt → elt → Result)
(P : Result → Prop) u :
(∀ x y, bounded x → bounded y →
residue y × residue y = residue x × (residue x × residue x + residue a) + residue b →
P (finish x y)) → P (swuComplexApply finish u).
Proof.
intro Hfinish. pose proof (swu_complex_coordinates_valid u) as Hvalid.
unfold swuComplexCoordinates, swuComplexApply in ×.
match goal with |- context [sqrtRatio ?top ?bottom] ⇒
destruct (sqrtRatio top bottom) as [square root] end.
destruct Hvalid as [Hx [Hy Heq]]. apply Hfinish; assumption.
Qed.
End Map.
(P : Result → Prop) u :
(∀ x y, bounded x → bounded y →
residue y × residue y = residue x × (residue x × residue x + residue a) + residue b →
P (finish x y)) → P (swuComplexApply finish u).
Proof.
intro Hfinish. pose proof (swu_complex_coordinates_valid u) as Hvalid.
unfold swuComplexCoordinates, swuComplexApply in ×.
match goal with |- context [sqrtRatio ?top ?bottom] ⇒
destruct (sqrtRatio top bottom) as [square root] end.
destruct Hvalid as [Hx [Hy Heq]]. apply Hfinish; assumption.
Qed.
End Map.
Normalize the generated functor before substituting the BLS operations.
Section Generated.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation complex := (@blscomplexresidues.complex).
Local Notation elt := (@Complex.t _ complex).
Context {Point : Set} {S : @SWU.FArgs elt Point}
{UX : elt} {UP : Point}.
Hypotheses
(Hmul : (@SWU.F _ _ S).(Algebra.FIELD.op_star) = @Complex.op_star _ complex)
(Hadd : (@SWU.F _ _ S).(Algebra.FIELD.op_plus) = @Complex.op_plus _ complex)
(Hsub : (@SWU.F _ _ S).(Algebra.FIELD.op_minus) = @Complex.op_minus _ complex)
(Hdiv : (@SWU.F _ _ S).(Algebra.FIELD.op_div) = @Complex.op_div _ complex)
(Heq : (@SWU.F _ _ S).(Algebra.FIELD.op_eq) = @Complex.op_eq _ complex)
(Hzero : (@SWU.F _ _ S).(Algebra.FIELD.zero) = @Complex.zero _ complex)
(Hone : (@SWU.F _ _ S).(Algebra.FIELD.one) = @Complex.op_tildedollar _ complex 1%Z).
Lemma swu_complex_generated_apply u :
@SWU.map_to_curve_simple_swu _ _ S UX UP u =
@swuComplexApply (@SWU.a_value _ _ S) (@SWU.b_value _ _ S)
(@SWU.P _ _ S).(Ec.Curve.SWU_method_P_signature.z_value)
(@SWU.sqrt_ratio _ _ S UX)
(@SWU.P _ _ S).(Ec.Curve.SWU_method_P_signature.sgn0)
Point (fun x y ⇒ @MonadVM.Option.get _ UP
((@SWU.C _ _ S).(Ec.Curve.SIG.of_coords) x y)) u.
Proof.
destruct S as [C P] in ×.
destruct C as [ops ca cb cg Point' cz cis cp cm cc ccoords] in ×.
destruct ops in ×.
change (op_star = @Complex.op_star _ complex) in Hmul.
change (op_plus = @Complex.op_plus _ complex) in Hadd.
change (op_minus = @Complex.op_minus _ complex) in Hsub.
change (op_div = @Complex.op_div _ complex) in Hdiv.
change (op_eq = @Complex.op_eq _ complex) in Heq.
change (zero0 = @Complex.zero _ complex) in Hzero.
change (one0 = @Complex.op_tildedollar _ complex 1%Z) in Hone.
subst. reflexivity.
Qed.
End Generated.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation complex := (@blscomplexresidues.complex).
Local Notation elt := (@Complex.t _ complex).
Context {Point : Set} {S : @SWU.FArgs elt Point}
{UX : elt} {UP : Point}.
Hypotheses
(Hmul : (@SWU.F _ _ S).(Algebra.FIELD.op_star) = @Complex.op_star _ complex)
(Hadd : (@SWU.F _ _ S).(Algebra.FIELD.op_plus) = @Complex.op_plus _ complex)
(Hsub : (@SWU.F _ _ S).(Algebra.FIELD.op_minus) = @Complex.op_minus _ complex)
(Hdiv : (@SWU.F _ _ S).(Algebra.FIELD.op_div) = @Complex.op_div _ complex)
(Heq : (@SWU.F _ _ S).(Algebra.FIELD.op_eq) = @Complex.op_eq _ complex)
(Hzero : (@SWU.F _ _ S).(Algebra.FIELD.zero) = @Complex.zero _ complex)
(Hone : (@SWU.F _ _ S).(Algebra.FIELD.one) = @Complex.op_tildedollar _ complex 1%Z).
Lemma swu_complex_generated_apply u :
@SWU.map_to_curve_simple_swu _ _ S UX UP u =
@swuComplexApply (@SWU.a_value _ _ S) (@SWU.b_value _ _ S)
(@SWU.P _ _ S).(Ec.Curve.SWU_method_P_signature.z_value)
(@SWU.sqrt_ratio _ _ S UX)
(@SWU.P _ _ S).(Ec.Curve.SWU_method_P_signature.sgn0)
Point (fun x y ⇒ @MonadVM.Option.get _ UP
((@SWU.C _ _ S).(Ec.Curve.SIG.of_coords) x y)) u.
Proof.
destruct S as [C P] in ×.
destruct C as [ops ca cb cg Point' cz cis cp cm cc ccoords] in ×.
destruct ops in ×.
change (op_star = @Complex.op_star _ complex) in Hmul.
change (op_plus = @Complex.op_plus _ complex) in Hadd.
change (op_minus = @Complex.op_minus _ complex) in Hsub.
change (op_div = @Complex.op_div _ complex) in Hdiv.
change (op_eq = @Complex.op_eq _ complex) in Heq.
change (zero0 = @Complex.zero _ complex) in Hzero.
change (one0 = @Complex.op_tildedollar _ complex 1%Z) in Hone.
subst. reflexivity.
Qed.
End Generated.