Library QedkConcrete.swumath

Algebra behind the simplified SWU map

The first candidate has curve value equal to the quotient tested for a square root. If that quotient is nonsquare, scaling x by z*u*u and the alternative root by z*u*u*u gives the second candidate. The exceptional zero denominator choice must use the first candidate.
From Stdlib Require Import ZArith Lia Field Zmod.Zmod.
Set Default Goal Selector "!".

Section PrimeField.
Variable modulus : Z.
Variable Hprime : Z.prime modulus.
Add Field residue_field : (Zmod.field_theory modulus Hprime).
Local Open Scope Zmod_scope.
Local Infix "/" := Zmod.mdiv : Zmod_scope.

Lemma swu_first_candidate (a b n d : Zmod modulus) : 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 swu_second_candidate (a b t : Zmod modulus) :
  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 Zmod.opp) in H.
  replace (- -a) with a in H by ring. rewrite Zmod.opp_0 in H. exact H.
Qed.

Lemma swu_scaled_root (z u q root : Zmod modulus) :
  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 PrimeField.