Library QedkConcrete.complexswumath

SWU identities in the quadratic extension

These are field identities, independent of BLS parameters. The parameter-specific exceptional branch is checked separately.
From Stdlib Require Import ZArith Lia Field.
Require Import QedkConcrete.complexresiduefield.
Set Default Goal Selector "!".
Module QR := QuadraticResidue.

Section Algebra.
Variable p : Z.
Hypotheses (Hprime : Z.prime p) (Hfour : (p mod 4 = 3)%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.divide p).
Add Field extension_field : (QR.quadratic_field p Hprime Hfour).

Lemma complex_product_nonzero (x y : QR.t p) :
  x ≠ 0 → y ≠ 0 → x×y ≠ 0.
Proof.
  intros Hx Hy Heq. apply Hy.
  assert (Hcancel : (x×y)/x = y) by (field; exact Hx).
  rewrite Heq in Hcancel. rewrite <- Hcancel. field; exact Hx.
Qed.

Lemma complex_swu_first_candidate (a b n d : QR.t p) : d ≠ 0 →
  (n×n×n + a×n*(d×d) + b*(d×d×d)) / (d×d×d) =
  (n/d)*((n/d)*(n/d)+a)+b.
Proof. intro Hd. field; exact Hd. Qed.

Lemma complex_swu_second_candidate (a b t : QR.t p) :
  a ≠ 0 → t×t+t ≠ 0 →
  let x := (b*(t×t+t+1))/(-a*(t×t+t)) in
  (t×x)*((t×x)*(t×x)+a)+b = (t×t×t)*(x*(x×x+a)+b).
Proof.
  intros Ha Ht. cbv zeta. field. split; [exact Ht|].
  intro H. apply Ha. apply (f_equal (QR.opp p)) in H.
  replace (- -a) with a in H by ring.
  replace (-0) with 0 in H by ring. exact H.
Qed.

Lemma complex_swu_scaled_root (z u q root : QR.t p) :
  root×root = z×q →
  let t := z×u×u in (t×u×root)*(t×u×root) = (t×t×t)*q.
Proof.
  intro Hroot. cbv zeta.
  replace ((z×u×u×u×root)*(z×u×u×u×root))
    with ((z×u×u×u)*(z×u×u×u)*(root×root)) by ring.
  rewrite Hroot. ring.
Qed.
End Algebra.