Metamath Proof Explorer


Theorem prmdiv

Description: Show an explicit expression for the modular inverse of A mod P . (Contributed by Mario Carneiro, 24-Jan-2015)

Ref Expression
Hypothesis prmdiv.1 R = A P 2 mod P
Assertion prmdiv P A ¬ P A R 1 P 1 P A R 1

Proof

Step Hyp Ref Expression
1 prmdiv.1 R = A P 2 mod P
2 nprmdvds1 P ¬ P 1
3 2 3ad2ant1 P A ¬ P A ¬ P 1
4 prmz P P
5 4 3ad2ant1 P A ¬ P A P
6 simp2 P A ¬ P A A
7 phiprm P ϕ P = P 1
8 7 3ad2ant1 P A ¬ P A ϕ P = P 1
9 prmnn P P
10 9 3ad2ant1 P A ¬ P A P
11 nnm1nn0 P P 1 0
12 10 11 syl P A ¬ P A P 1 0
13 8 12 eqeltrd P A ¬ P A ϕ P 0
14 zexpcl A ϕ P 0 A ϕ P
15 6 13 14 syl2anc P A ¬ P A A ϕ P
16 1z 1
17 zsubcl A ϕ P 1 A ϕ P 1
18 15 16 17 sylancl P A ¬ P A A ϕ P 1
19 prmuz2 P P 2
20 19 3ad2ant1 P A ¬ P A P 2
21 uznn0sub P 2 P 2 0
22 20 21 syl P A ¬ P A P 2 0
23 zexpcl A P 2 0 A P 2
24 6 22 23 syl2anc P A ¬ P A A P 2
25 24 zred P A ¬ P A A P 2
26 25 10 nndivred P A ¬ P A A P 2 P
27 26 flcld P A ¬ P A A P 2 P
28 6 27 zmulcld P A ¬ P A A A P 2 P
29 5 28 zmulcld P A ¬ P A P A A P 2 P
30 6 5 gcdcomd P A ¬ P A A gcd P = P gcd A
31 coprm P A ¬ P A P gcd A = 1
32 31 biimp3a P A ¬ P A P gcd A = 1
33 30 32 eqtrd P A ¬ P A A gcd P = 1
34 eulerth P A A gcd P = 1 A ϕ P mod P = 1 mod P
35 10 6 33 34 syl3anc P A ¬ P A A ϕ P mod P = 1 mod P
36 1zzd P A ¬ P A 1
37 moddvds P A ϕ P 1 A ϕ P mod P = 1 mod P P A ϕ P 1
38 10 15 36 37 syl3anc P A ¬ P A A ϕ P mod P = 1 mod P P A ϕ P 1
39 35 38 mpbid P A ¬ P A P A ϕ P 1
40 dvdsmul1 P A A P 2 P P P A A P 2 P
41 5 28 40 syl2anc P A ¬ P A P P A A P 2 P
42 5 18 29 39 41 dvds2subd P A ¬ P A P A ϕ P - 1 - P A A P 2 P
43 6 zcnd P A ¬ P A A
44 24 zcnd P A ¬ P A A P 2
45 5 27 zmulcld P A ¬ P A P A P 2 P
46 45 zcnd P A ¬ P A P A P 2 P
47 43 44 46 subdid P A ¬ P A A A P 2 P A P 2 P = A A P 2 A P A P 2 P
48 10 nnrpd P A ¬ P A P +
49 modval A P 2 P + A P 2 mod P = A P 2 P A P 2 P
50 25 48 49 syl2anc P A ¬ P A A P 2 mod P = A P 2 P A P 2 P
51 1 50 eqtrid P A ¬ P A R = A P 2 P A P 2 P
52 51 oveq2d P A ¬ P A A R = A A P 2 P A P 2 P
53 2m1e1 2 1 = 1
54 53 oveq2i P 2 1 = P 1
55 8 54 eqtr4di P A ¬ P A ϕ P = P 2 1
56 10 nncnd P A ¬ P A P
57 2cnd P A ¬ P A 2
58 1cnd P A ¬ P A 1
59 56 57 58 subsubd P A ¬ P A P 2 1 = P - 2 + 1
60 55 59 eqtrd P A ¬ P A ϕ P = P - 2 + 1
61 60 oveq2d P A ¬ P A A ϕ P = A P - 2 + 1
62 43 22 expp1d P A ¬ P A A P - 2 + 1 = A P 2 A
63 44 43 mulcomd P A ¬ P A A P 2 A = A A P 2
64 61 62 63 3eqtrd P A ¬ P A A ϕ P = A A P 2
65 27 zcnd P A ¬ P A A P 2 P
66 56 43 65 mul12d P A ¬ P A P A A P 2 P = A P A P 2 P
67 64 66 oveq12d P A ¬ P A A ϕ P P A A P 2 P = A A P 2 A P A P 2 P
68 47 52 67 3eqtr4d P A ¬ P A A R = A ϕ P P A A P 2 P
69 68 oveq1d P A ¬ P A A R 1 = A ϕ P - P A A P 2 P - 1
70 15 zcnd P A ¬ P A A ϕ P
71 29 zcnd P A ¬ P A P A A P 2 P
72 70 71 58 sub32d P A ¬ P A A ϕ P - P A A P 2 P - 1 = A ϕ P - 1 - P A A P 2 P
73 69 72 eqtrd P A ¬ P A A R 1 = A ϕ P - 1 - P A A P 2 P
74 42 73 breqtrrd P A ¬ P A P A R 1
75 oveq2 R = 0 A R = A 0
76 75 oveq1d R = 0 A R 1 = A 0 1
77 76 breq2d R = 0 P A R 1 P A 0 1
78 74 77 syl5ibcom P A ¬ P A R = 0 P A 0 1
79 43 mul01d P A ¬ P A A 0 = 0
80 79 oveq1d P A ¬ P A A 0 1 = 0 1
81 df-neg 1 = 0 1
82 80 81 eqtr4di P A ¬ P A A 0 1 = 1
83 82 breq2d P A ¬ P A P A 0 1 P -1
84 dvdsnegb P 1 P 1 P -1
85 5 16 84 sylancl P A ¬ P A P 1 P -1
86 83 85 bitr4d P A ¬ P A P A 0 1 P 1
87 78 86 sylibd P A ¬ P A R = 0 P 1
88 3 87 mtod P A ¬ P A ¬ R = 0
89 zmodfz A P 2 P A P 2 mod P 0 P 1
90 24 10 89 syl2anc P A ¬ P A A P 2 mod P 0 P 1
91 1 90 eqeltrid P A ¬ P A R 0 P 1
92 nn0uz 0 = 0
93 12 92 eleqtrdi P A ¬ P A P 1 0
94 elfzp12 P 1 0 R 0 P 1 R = 0 R 0 + 1 P 1
95 93 94 syl P A ¬ P A R 0 P 1 R = 0 R 0 + 1 P 1
96 91 95 mpbid P A ¬ P A R = 0 R 0 + 1 P 1
97 96 ord P A ¬ P A ¬ R = 0 R 0 + 1 P 1
98 88 97 mpd P A ¬ P A R 0 + 1 P 1
99 1e0p1 1 = 0 + 1
100 99 oveq1i 1 P 1 = 0 + 1 P 1
101 98 100 eleqtrrdi P A ¬ P A R 1 P 1
102 101 74 jca P A ¬ P A R 1 P 1 P A R 1