Metamath Proof Explorer


Theorem 4sqlem12

Description: Lemma for 4sq . For any odd prime P , there is a k < P such that k P - 1 is a sum of two squares. (Contributed by Mario Carneiro, 15-Jul-2014)

Ref Expression
Hypotheses 4sq.1
|- S = { n | E. x e. ZZ E. y e. ZZ E. z e. ZZ E. w e. ZZ n = ( ( ( x ^ 2 ) + ( y ^ 2 ) ) + ( ( z ^ 2 ) + ( w ^ 2 ) ) ) }
4sq.2
|- ( ph -> N e. NN )
4sq.3
|- ( ph -> P = ( ( 2 x. N ) + 1 ) )
4sq.4
|- ( ph -> P e. Prime )
4sqlem11.5
|- A = { u | E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) }
4sqlem11.6
|- F = ( v e. A |-> ( ( P - 1 ) - v ) )
Assertion 4sqlem12
|- ( ph -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) )

Proof

Step Hyp Ref Expression
1 4sq.1
 |-  S = { n | E. x e. ZZ E. y e. ZZ E. z e. ZZ E. w e. ZZ n = ( ( ( x ^ 2 ) + ( y ^ 2 ) ) + ( ( z ^ 2 ) + ( w ^ 2 ) ) ) }
2 4sq.2
 |-  ( ph -> N e. NN )
3 4sq.3
 |-  ( ph -> P = ( ( 2 x. N ) + 1 ) )
4 4sq.4
 |-  ( ph -> P e. Prime )
5 4sqlem11.5
 |-  A = { u | E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) }
6 4sqlem11.6
 |-  F = ( v e. A |-> ( ( P - 1 ) - v ) )
7 1 2 3 4 5 6 4sqlem11
 |-  ( ph -> ( A i^i ran F ) =/= (/) )
8 n0
 |-  ( ( A i^i ran F ) =/= (/) <-> E. j j e. ( A i^i ran F ) )
9 7 8 sylib
 |-  ( ph -> E. j j e. ( A i^i ran F ) )
10 vex
 |-  j e. _V
11 eqeq1
 |-  ( u = j -> ( u = ( ( m ^ 2 ) mod P ) <-> j = ( ( m ^ 2 ) mod P ) ) )
12 11 rexbidv
 |-  ( u = j -> ( E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) <-> E. m e. ( 0 ... N ) j = ( ( m ^ 2 ) mod P ) ) )
13 10 12 5 elab2
 |-  ( j e. A <-> E. m e. ( 0 ... N ) j = ( ( m ^ 2 ) mod P ) )
14 abid
 |-  ( j e. { j | E. v e. A j = ( ( P - 1 ) - v ) } <-> E. v e. A j = ( ( P - 1 ) - v ) )
15 5 rexeqi
 |-  ( E. v e. A j = ( ( P - 1 ) - v ) <-> E. v e. { u | E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) } j = ( ( P - 1 ) - v ) )
16 oveq1
 |-  ( m = n -> ( m ^ 2 ) = ( n ^ 2 ) )
17 16 oveq1d
 |-  ( m = n -> ( ( m ^ 2 ) mod P ) = ( ( n ^ 2 ) mod P ) )
18 17 eqeq2d
 |-  ( m = n -> ( u = ( ( m ^ 2 ) mod P ) <-> u = ( ( n ^ 2 ) mod P ) ) )
19 18 cbvrexvw
 |-  ( E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) <-> E. n e. ( 0 ... N ) u = ( ( n ^ 2 ) mod P ) )
20 eqeq1
 |-  ( u = v -> ( u = ( ( n ^ 2 ) mod P ) <-> v = ( ( n ^ 2 ) mod P ) ) )
21 20 rexbidv
 |-  ( u = v -> ( E. n e. ( 0 ... N ) u = ( ( n ^ 2 ) mod P ) <-> E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) ) )
22 19 21 syl5bb
 |-  ( u = v -> ( E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) <-> E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) ) )
23 22 rexab
 |-  ( E. v e. { u | E. m e. ( 0 ... N ) u = ( ( m ^ 2 ) mod P ) } j = ( ( P - 1 ) - v ) <-> E. v ( E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
24 14 15 23 3bitri
 |-  ( j e. { j | E. v e. A j = ( ( P - 1 ) - v ) } <-> E. v ( E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
25 6 rnmpt
 |-  ran F = { j | E. v e. A j = ( ( P - 1 ) - v ) }
26 25 eleq2i
 |-  ( j e. ran F <-> j e. { j | E. v e. A j = ( ( P - 1 ) - v ) } )
27 rexcom4
 |-  ( E. n e. ( 0 ... N ) E. v ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> E. v E. n e. ( 0 ... N ) ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
28 r19.41v
 |-  ( E. n e. ( 0 ... N ) ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> ( E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
29 28 exbii
 |-  ( E. v E. n e. ( 0 ... N ) ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> E. v ( E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
30 27 29 bitri
 |-  ( E. n e. ( 0 ... N ) E. v ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> E. v ( E. n e. ( 0 ... N ) v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
31 24 26 30 3bitr4i
 |-  ( j e. ran F <-> E. n e. ( 0 ... N ) E. v ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) )
32 ovex
 |-  ( ( n ^ 2 ) mod P ) e. _V
33 oveq2
 |-  ( v = ( ( n ^ 2 ) mod P ) -> ( ( P - 1 ) - v ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
34 33 eqeq2d
 |-  ( v = ( ( n ^ 2 ) mod P ) -> ( j = ( ( P - 1 ) - v ) <-> j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) )
35 32 34 ceqsexv
 |-  ( E. v ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
36 35 rexbii
 |-  ( E. n e. ( 0 ... N ) E. v ( v = ( ( n ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - v ) ) <-> E. n e. ( 0 ... N ) j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
37 31 36 bitri
 |-  ( j e. ran F <-> E. n e. ( 0 ... N ) j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
38 13 37 anbi12i
 |-  ( ( j e. A /\ j e. ran F ) <-> ( E. m e. ( 0 ... N ) j = ( ( m ^ 2 ) mod P ) /\ E. n e. ( 0 ... N ) j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) )
39 elin
 |-  ( j e. ( A i^i ran F ) <-> ( j e. A /\ j e. ran F ) )
40 reeanv
 |-  ( E. m e. ( 0 ... N ) E. n e. ( 0 ... N ) ( j = ( ( m ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) <-> ( E. m e. ( 0 ... N ) j = ( ( m ^ 2 ) mod P ) /\ E. n e. ( 0 ... N ) j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) )
41 38 39 40 3bitr4i
 |-  ( j e. ( A i^i ran F ) <-> E. m e. ( 0 ... N ) E. n e. ( 0 ... N ) ( j = ( ( m ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) )
42 eqtr2
 |-  ( ( j = ( ( m ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
43 4 3ad2ant1
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. Prime )
44 prmnn
 |-  ( P e. Prime -> P e. NN )
45 43 44 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. NN )
46 nnm1nn0
 |-  ( P e. NN -> ( P - 1 ) e. NN0 )
47 45 46 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P - 1 ) e. NN0 )
48 47 nn0red
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P - 1 ) e. RR )
49 45 nnrpd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. RR+ )
50 47 nn0ge0d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 <_ ( P - 1 ) )
51 45 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. RR )
52 51 ltm1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P - 1 ) < P )
53 modid
 |-  ( ( ( ( P - 1 ) e. RR /\ P e. RR+ ) /\ ( 0 <_ ( P - 1 ) /\ ( P - 1 ) < P ) ) -> ( ( P - 1 ) mod P ) = ( P - 1 ) )
54 48 49 50 52 53 syl22anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( P - 1 ) mod P ) = ( P - 1 ) )
55 54 oveq1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( P - 1 ) mod P ) - ( ( n ^ 2 ) mod P ) ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
56 simp2r
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> n e. ( 0 ... N ) )
57 56 elfzelzd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> n e. ZZ )
58 zsqcl2
 |-  ( n e. ZZ -> ( n ^ 2 ) e. NN0 )
59 57 58 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( n ^ 2 ) e. NN0 )
60 59 nn0red
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( n ^ 2 ) e. RR )
61 modlt
 |-  ( ( ( n ^ 2 ) e. RR /\ P e. RR+ ) -> ( ( n ^ 2 ) mod P ) < P )
62 60 49 61 syl2anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( n ^ 2 ) mod P ) < P )
63 zsqcl
 |-  ( n e. ZZ -> ( n ^ 2 ) e. ZZ )
64 57 63 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( n ^ 2 ) e. ZZ )
65 64 45 zmodcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( n ^ 2 ) mod P ) e. NN0 )
66 65 nn0zd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( n ^ 2 ) mod P ) e. ZZ )
67 prmz
 |-  ( P e. Prime -> P e. ZZ )
68 43 67 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. ZZ )
69 zltlem1
 |-  ( ( ( ( n ^ 2 ) mod P ) e. ZZ /\ P e. ZZ ) -> ( ( ( n ^ 2 ) mod P ) < P <-> ( ( n ^ 2 ) mod P ) <_ ( P - 1 ) ) )
70 66 68 69 syl2anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( n ^ 2 ) mod P ) < P <-> ( ( n ^ 2 ) mod P ) <_ ( P - 1 ) ) )
71 62 70 mpbid
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( n ^ 2 ) mod P ) <_ ( P - 1 ) )
72 71 54 breqtrrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( n ^ 2 ) mod P ) <_ ( ( P - 1 ) mod P ) )
73 modsubdir
 |-  ( ( ( P - 1 ) e. RR /\ ( n ^ 2 ) e. RR /\ P e. RR+ ) -> ( ( ( n ^ 2 ) mod P ) <_ ( ( P - 1 ) mod P ) <-> ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) = ( ( ( P - 1 ) mod P ) - ( ( n ^ 2 ) mod P ) ) ) )
74 48 60 49 73 syl3anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( n ^ 2 ) mod P ) <_ ( ( P - 1 ) mod P ) <-> ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) = ( ( ( P - 1 ) mod P ) - ( ( n ^ 2 ) mod P ) ) ) )
75 72 74 mpbid
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) = ( ( ( P - 1 ) mod P ) - ( ( n ^ 2 ) mod P ) ) )
76 simp3
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) )
77 55 75 76 3eqtr4rd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) mod P ) = ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) )
78 simp2l
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> m e. ( 0 ... N ) )
79 78 elfzelzd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> m e. ZZ )
80 zsqcl
 |-  ( m e. ZZ -> ( m ^ 2 ) e. ZZ )
81 79 80 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m ^ 2 ) e. ZZ )
82 47 nn0zd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P - 1 ) e. ZZ )
83 82 64 zsubcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( P - 1 ) - ( n ^ 2 ) ) e. ZZ )
84 moddvds
 |-  ( ( P e. NN /\ ( m ^ 2 ) e. ZZ /\ ( ( P - 1 ) - ( n ^ 2 ) ) e. ZZ ) -> ( ( ( m ^ 2 ) mod P ) = ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) <-> P || ( ( m ^ 2 ) - ( ( P - 1 ) - ( n ^ 2 ) ) ) ) )
85 45 81 83 84 syl3anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) mod P ) = ( ( ( P - 1 ) - ( n ^ 2 ) ) mod P ) <-> P || ( ( m ^ 2 ) - ( ( P - 1 ) - ( n ^ 2 ) ) ) ) )
86 77 85 mpbid
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P || ( ( m ^ 2 ) - ( ( P - 1 ) - ( n ^ 2 ) ) ) )
87 zsqcl2
 |-  ( m e. ZZ -> ( m ^ 2 ) e. NN0 )
88 79 87 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m ^ 2 ) e. NN0 )
89 88 nn0cnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m ^ 2 ) e. CC )
90 47 nn0cnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P - 1 ) e. CC )
91 59 nn0cnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( n ^ 2 ) e. CC )
92 89 90 91 subsub3d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) - ( ( P - 1 ) - ( n ^ 2 ) ) ) = ( ( ( m ^ 2 ) + ( n ^ 2 ) ) - ( P - 1 ) ) )
93 88 59 nn0addcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) e. NN0 )
94 93 nn0cnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) e. CC )
95 45 nncnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P e. CC )
96 1cnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 1 e. CC )
97 94 95 96 subsub3d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) - ( P - 1 ) ) = ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) - P ) )
98 92 97 eqtrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) - ( ( P - 1 ) - ( n ^ 2 ) ) ) = ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) - P ) )
99 86 98 breqtrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P || ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) - P ) )
100 nn0p1nn
 |-  ( ( ( m ^ 2 ) + ( n ^ 2 ) ) e. NN0 -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. NN )
101 93 100 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. NN )
102 101 nnzd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. ZZ )
103 dvdssubr
 |-  ( ( P e. ZZ /\ ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. ZZ ) -> ( P || ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) <-> P || ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) - P ) ) )
104 68 102 103 syl2anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P || ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) <-> P || ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) - P ) ) )
105 99 104 mpbird
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P || ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) )
106 45 nnne0d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P =/= 0 )
107 dvdsval2
 |-  ( ( P e. ZZ /\ P =/= 0 /\ ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. ZZ ) -> ( P || ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) <-> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ ) )
108 68 106 102 107 syl3anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P || ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) <-> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ ) )
109 105 108 mpbid
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ )
110 nnrp
 |-  ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. NN -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. RR+ )
111 nnrp
 |-  ( P e. NN -> P e. RR+ )
112 rpdivcl
 |-  ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. RR+ /\ P e. RR+ ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. RR+ )
113 110 111 112 syl2an
 |-  ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. NN /\ P e. NN ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. RR+ )
114 101 45 113 syl2anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. RR+ )
115 114 rpgt0d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 < ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) )
116 elnnz
 |-  ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. NN <-> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ /\ 0 < ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) ) )
117 109 115 116 sylanbrc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. NN )
118 117 nnge1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 1 <_ ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) )
119 93 nn0red
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) e. RR )
120 2nn
 |-  2 e. NN
121 2 3ad2ant1
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> N e. NN )
122 nnmulcl
 |-  ( ( 2 e. NN /\ N e. NN ) -> ( 2 x. N ) e. NN )
123 120 121 122 sylancr
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. N ) e. NN )
124 123 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. N ) e. RR )
125 124 resqcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( 2 x. N ) ^ 2 ) e. RR )
126 nnmulcl
 |-  ( ( 2 e. NN /\ ( 2 x. N ) e. NN ) -> ( 2 x. ( 2 x. N ) ) e. NN )
127 120 123 126 sylancr
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( 2 x. N ) ) e. NN )
128 127 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( 2 x. N ) ) e. RR )
129 125 128 readdcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) e. RR )
130 1red
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 1 e. RR )
131 121 nnsqcld
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( N ^ 2 ) e. NN )
132 nnmulcl
 |-  ( ( 2 e. NN /\ ( N ^ 2 ) e. NN ) -> ( 2 x. ( N ^ 2 ) ) e. NN )
133 120 131 132 sylancr
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( N ^ 2 ) ) e. NN )
134 133 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( N ^ 2 ) ) e. RR )
135 88 nn0red
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m ^ 2 ) e. RR )
136 131 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( N ^ 2 ) e. RR )
137 79 zred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> m e. RR )
138 elfzle1
 |-  ( m e. ( 0 ... N ) -> 0 <_ m )
139 78 138 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 <_ m )
140 121 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> N e. RR )
141 elfzle2
 |-  ( m e. ( 0 ... N ) -> m <_ N )
142 78 141 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> m <_ N )
143 le2sq2
 |-  ( ( ( m e. RR /\ 0 <_ m ) /\ ( N e. RR /\ m <_ N ) ) -> ( m ^ 2 ) <_ ( N ^ 2 ) )
144 137 139 140 142 143 syl22anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m ^ 2 ) <_ ( N ^ 2 ) )
145 57 zred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> n e. RR )
146 elfzle1
 |-  ( n e. ( 0 ... N ) -> 0 <_ n )
147 56 146 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 <_ n )
148 elfzle2
 |-  ( n e. ( 0 ... N ) -> n <_ N )
149 56 148 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> n <_ N )
150 le2sq2
 |-  ( ( ( n e. RR /\ 0 <_ n ) /\ ( N e. RR /\ n <_ N ) ) -> ( n ^ 2 ) <_ ( N ^ 2 ) )
151 145 147 140 149 150 syl22anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( n ^ 2 ) <_ ( N ^ 2 ) )
152 135 60 136 136 144 151 le2addd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) <_ ( ( N ^ 2 ) + ( N ^ 2 ) ) )
153 131 nncnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( N ^ 2 ) e. CC )
154 153 2timesd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( N ^ 2 ) ) = ( ( N ^ 2 ) + ( N ^ 2 ) ) )
155 152 154 breqtrrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) <_ ( 2 x. ( N ^ 2 ) ) )
156 2lt4
 |-  2 < 4
157 2re
 |-  2 e. RR
158 157 a1i
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 2 e. RR )
159 4re
 |-  4 e. RR
160 159 a1i
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 4 e. RR )
161 131 nngt0d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 < ( N ^ 2 ) )
162 ltmul1
 |-  ( ( 2 e. RR /\ 4 e. RR /\ ( ( N ^ 2 ) e. RR /\ 0 < ( N ^ 2 ) ) ) -> ( 2 < 4 <-> ( 2 x. ( N ^ 2 ) ) < ( 4 x. ( N ^ 2 ) ) ) )
163 158 160 136 161 162 syl112anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 < 4 <-> ( 2 x. ( N ^ 2 ) ) < ( 4 x. ( N ^ 2 ) ) ) )
164 156 163 mpbii
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( N ^ 2 ) ) < ( 4 x. ( N ^ 2 ) ) )
165 2cn
 |-  2 e. CC
166 121 nncnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> N e. CC )
167 sqmul
 |-  ( ( 2 e. CC /\ N e. CC ) -> ( ( 2 x. N ) ^ 2 ) = ( ( 2 ^ 2 ) x. ( N ^ 2 ) ) )
168 165 166 167 sylancr
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( 2 x. N ) ^ 2 ) = ( ( 2 ^ 2 ) x. ( N ^ 2 ) ) )
169 sq2
 |-  ( 2 ^ 2 ) = 4
170 169 oveq1i
 |-  ( ( 2 ^ 2 ) x. ( N ^ 2 ) ) = ( 4 x. ( N ^ 2 ) )
171 168 170 eqtrdi
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( 2 x. N ) ^ 2 ) = ( 4 x. ( N ^ 2 ) ) )
172 164 171 breqtrrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( N ^ 2 ) ) < ( ( 2 x. N ) ^ 2 ) )
173 119 134 125 155 172 lelttrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) < ( ( 2 x. N ) ^ 2 ) )
174 127 nnrpd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. ( 2 x. N ) ) e. RR+ )
175 125 174 ltaddrpd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( 2 x. N ) ^ 2 ) < ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) )
176 119 125 129 173 175 lttrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( m ^ 2 ) + ( n ^ 2 ) ) < ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) )
177 119 129 130 176 ltadd1dd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) < ( ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) + 1 ) )
178 3 3ad2ant1
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> P = ( ( 2 x. N ) + 1 ) )
179 178 oveq1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P ^ 2 ) = ( ( ( 2 x. N ) + 1 ) ^ 2 ) )
180 95 sqvald
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P ^ 2 ) = ( P x. P ) )
181 123 nncnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( 2 x. N ) e. CC )
182 binom21
 |-  ( ( 2 x. N ) e. CC -> ( ( ( 2 x. N ) + 1 ) ^ 2 ) = ( ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) + 1 ) )
183 181 182 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( 2 x. N ) + 1 ) ^ 2 ) = ( ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) + 1 ) )
184 179 180 183 3eqtr3d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( P x. P ) = ( ( ( ( 2 x. N ) ^ 2 ) + ( 2 x. ( 2 x. N ) ) ) + 1 ) )
185 177 184 breqtrrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) < ( P x. P ) )
186 101 nnred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. RR )
187 45 nngt0d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> 0 < P )
188 ltdivmul
 |-  ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. RR /\ P e. RR /\ ( P e. RR /\ 0 < P ) ) -> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) < P <-> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) < ( P x. P ) ) )
189 186 51 51 187 188 syl112anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) < P <-> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) < ( P x. P ) ) )
190 185 189 mpbird
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) < P )
191 1z
 |-  1 e. ZZ
192 elfzm11
 |-  ( ( 1 e. ZZ /\ P e. ZZ ) -> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ( 1 ... ( P - 1 ) ) <-> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ /\ 1 <_ ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) /\ ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) < P ) ) )
193 191 68 192 sylancr
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ( 1 ... ( P - 1 ) ) <-> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ZZ /\ 1 <_ ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) /\ ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) < P ) ) )
194 109 118 190 193 mpbir3and
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ( 1 ... ( P - 1 ) ) )
195 gzreim
 |-  ( ( m e. ZZ /\ n e. ZZ ) -> ( m + ( _i x. n ) ) e. Z[i] )
196 79 57 195 syl2anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m + ( _i x. n ) ) e. Z[i] )
197 gzcn
 |-  ( ( m + ( _i x. n ) ) e. Z[i] -> ( m + ( _i x. n ) ) e. CC )
198 196 197 syl
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( m + ( _i x. n ) ) e. CC )
199 198 absvalsq2d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) = ( ( ( Re ` ( m + ( _i x. n ) ) ) ^ 2 ) + ( ( Im ` ( m + ( _i x. n ) ) ) ^ 2 ) ) )
200 137 145 crred
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( Re ` ( m + ( _i x. n ) ) ) = m )
201 200 oveq1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( Re ` ( m + ( _i x. n ) ) ) ^ 2 ) = ( m ^ 2 ) )
202 137 145 crimd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( Im ` ( m + ( _i x. n ) ) ) = n )
203 202 oveq1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( Im ` ( m + ( _i x. n ) ) ) ^ 2 ) = ( n ^ 2 ) )
204 201 203 oveq12d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( Re ` ( m + ( _i x. n ) ) ) ^ 2 ) + ( ( Im ` ( m + ( _i x. n ) ) ) ^ 2 ) ) = ( ( m ^ 2 ) + ( n ^ 2 ) ) )
205 199 204 eqtrd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) = ( ( m ^ 2 ) + ( n ^ 2 ) ) )
206 205 oveq1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) + 1 ) = ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) )
207 101 nncnd
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) e. CC )
208 207 95 106 divcan1d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) = ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) )
209 206 208 eqtr4d
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> ( ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) + 1 ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) )
210 oveq1
 |-  ( k = ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) -> ( k x. P ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) )
211 210 eqeq2d
 |-  ( k = ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) -> ( ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) <-> ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) ) )
212 fveq2
 |-  ( u = ( m + ( _i x. n ) ) -> ( abs ` u ) = ( abs ` ( m + ( _i x. n ) ) ) )
213 212 oveq1d
 |-  ( u = ( m + ( _i x. n ) ) -> ( ( abs ` u ) ^ 2 ) = ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) )
214 213 oveq1d
 |-  ( u = ( m + ( _i x. n ) ) -> ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) + 1 ) )
215 214 eqeq1d
 |-  ( u = ( m + ( _i x. n ) ) -> ( ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) <-> ( ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) + 1 ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) ) )
216 211 215 rspc2ev
 |-  ( ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) e. ( 1 ... ( P - 1 ) ) /\ ( m + ( _i x. n ) ) e. Z[i] /\ ( ( ( abs ` ( m + ( _i x. n ) ) ) ^ 2 ) + 1 ) = ( ( ( ( ( m ^ 2 ) + ( n ^ 2 ) ) + 1 ) / P ) x. P ) ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) )
217 194 196 209 216 syl3anc
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) /\ ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) )
218 217 3expia
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) ) -> ( ( ( m ^ 2 ) mod P ) = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) ) )
219 42 218 syl5
 |-  ( ( ph /\ ( m e. ( 0 ... N ) /\ n e. ( 0 ... N ) ) ) -> ( ( j = ( ( m ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) ) )
220 219 rexlimdvva
 |-  ( ph -> ( E. m e. ( 0 ... N ) E. n e. ( 0 ... N ) ( j = ( ( m ^ 2 ) mod P ) /\ j = ( ( P - 1 ) - ( ( n ^ 2 ) mod P ) ) ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) ) )
221 41 220 syl5bi
 |-  ( ph -> ( j e. ( A i^i ran F ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) ) )
222 221 exlimdv
 |-  ( ph -> ( E. j j e. ( A i^i ran F ) -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) ) )
223 9 222 mpd
 |-  ( ph -> E. k e. ( 1 ... ( P - 1 ) ) E. u e. Z[i] ( ( ( abs ` u ) ^ 2 ) + 1 ) = ( k x. P ) )