Section lagrange_prelim_odd.
Variable (p n : nat) (Hp1 : prime p) (Hp2 : p = 2*n+1).
Let Hn : 0 < n.
Let Hp : p <> 0.
(* Let us defined two injective functions from [0,n] to Z/Z(2n+1)  f := x => x² g := x => -(1+x²)  *)
Let f x := nat2Zp Hp (x*x).
Let g y := Zp_opp Hp (Zp_plus Hp (Zp_one Hp) (f y)).
Let Hf x y : In x l -> In y l -> f x = f y -> x = y.
Let Hg x y : In x l -> In y l -> g x = g y -> x = y.
(* Since |map f l| = n+1 and |map g l| = n+1 and the domain has cardinal 2*n+1, they must intersect *)
Let intersection : exists y, In y (map f l) /\ In y (map g l).
Local Lemma lagrange_prelim_odd :
exists a b, divides p (1+a*a+b*b)
/\ 2*a <= p-1
/\ 2*b <= p-1.
End lagrange_prelim_odd.
(* Preliminary lemma : any prime p has a (small) multiple n*p of the form 1+a²+b² with 0 < n < p *)
Local Notation four_squares := (fun a b c d => a*a+b*b+c*c+d*d)%Z.
Fact Euler_squares x y a1 b1 c1 d1 a2 b2 c2 d2 :
(x = four_squares a1 b1 c1 d1
-> y = four_squares a2 b2 c2 d2
-> x*y = four_squares (a1*a2+b1*b2+c1*c2+d1*d2)
(a1*b2-b1*a2+d1*c2-c1*d2)
(a1*c2-c1*a2+b1*d2-d1*b2)
(a1*d2-d1*a2+c1*b2-b1*c2))%Z.
End lagrange_prime_step.
Let lagrange_prime_step m : 1 < m < p -> P m -> exists r, 1 <= r < m /\ P r.
(* Now that P 1 holfs ie p is sum of 4 squares *)

Lemma lagrange_prime : exists a b c d, Z.of_nat p = (a*a+b*b+c*c+d*d)%Z.