Metamath Proof Explorer


Theorem 2sqmod

Description: Given two decompositions of a prime as a sum of two squares, show that they are equal. (Contributed by Thierry Arnoux, 2-Feb-2020)

Ref Expression
Hypotheses 2sqmod.1 φ P
2sqmod.2 φ A 0
2sqmod.3 φ B 0
2sqmod.4 φ C 0
2sqmod.5 φ D 0
2sqmod.6 φ A B
2sqmod.7 φ C D
2sqmod.8 φ A 2 + B 2 = P
2sqmod.9 φ C 2 + D 2 = P
Assertion 2sqmod φ A = C B = D

Proof

Step Hyp Ref Expression
1 2sqmod.1 φ P
2 2sqmod.2 φ A 0
3 2sqmod.3 φ B 0
4 2sqmod.4 φ C 0
5 2sqmod.5 φ D 0
6 2sqmod.6 φ A B
7 2sqmod.7 φ C D
8 2sqmod.8 φ A 2 + B 2 = P
9 2sqmod.9 φ C 2 + D 2 = P
10 6 adantr φ P A D + C B A B
11 4 nn0red φ C
12 11 adantr φ P A D + C B C
13 3 nn0red φ B
14 13 adantr φ P A D + C B B
15 4 nn0ge0d φ 0 C
16 15 adantr φ P A D + C B 0 C
17 3 nn0ge0d φ 0 B
18 17 adantr φ P A D + C B 0 B
19 4 nn0cnd φ C
20 19 sqcld φ C 2
21 20 adantr φ P A D + C B C 2
22 3 nn0cnd φ B
23 22 sqcld φ B 2
24 23 adantr φ P A D + C B B 2
25 2 nn0cnd φ A
26 25 sqcld φ A 2
27 5 nn0cnd φ D
28 27 sqcld φ D 2
29 8 9 eqtr4d φ A 2 + B 2 = C 2 + D 2
30 26 23 20 28 29 subaddeqd φ A 2 D 2 = C 2 B 2
31 30 adantr φ P A D + C B A 2 D 2 = C 2 B 2
32 2 nn0zd φ A
33 4 nn0zd φ C
34 dvdsmul1 A C A A C
35 32 33 34 syl2anc φ A A C
36 35 adantr φ P A D + C B A A C
37 25 19 mulcld φ A C
38 37 adantr φ P A D + C B A C
39 22 27 mulcld φ B D
40 39 adantr φ P A D + C B B D
41 2 nn0red φ A
42 41 11 remulcld φ A C
43 5 nn0red φ D
44 13 43 remulcld φ B D
45 42 44 resubcld φ A C B D
46 45 recnd φ A C B D
47 46 adantr φ P A D + C B A C B D
48 45 sqge0d φ 0 A C B D 2
49 3 nn0zd φ B
50 1 32 49 8 2sqn0 φ A 0
51 elnnne0 A A 0 A 0
52 2 50 51 sylanbrc φ A
53 5 nn0zd φ D
54 28 20 addcomd φ D 2 + C 2 = C 2 + D 2
55 54 9 eqtrd φ D 2 + C 2 = P
56 1 53 33 55 2sqn0 φ D 0
57 elnnne0 D D 0 D 0
58 5 56 57 sylanbrc φ D
59 52 58 nnmulcld φ A D
60 1 33 53 9 2sqn0 φ C 0
61 elnnne0 C C 0 C 0
62 4 60 61 sylanbrc φ C
63 23 26 addcomd φ B 2 + A 2 = A 2 + B 2
64 63 8 eqtrd φ B 2 + A 2 = P
65 1 49 32 64 2sqn0 φ B 0
66 elnnne0 B B 0 B 0
67 3 65 66 sylanbrc φ B
68 62 67 nnmulcld φ C B
69 59 68 nnaddcld φ A D + C B
70 69 nnsqcld φ A D + C B 2
71 70 nnred φ A D + C B 2
72 45 resqcld φ A C B D 2
73 71 72 addge02d φ 0 A C B D 2 A D + C B 2 A C B D 2 + A D + C B 2
74 48 73 mpbid φ A D + C B 2 A C B D 2 + A D + C B 2
75 8 9 oveq12d φ A 2 + B 2 C 2 + D 2 = P P
76 bhmafibid1 A B C D A 2 + B 2 C 2 + D 2 = A C B D 2 + A D + B C 2
77 41 13 11 43 76 syl22anc φ A 2 + B 2 C 2 + D 2 = A C B D 2 + A D + B C 2
78 75 77 eqtr3d φ P P = A C B D 2 + A D + B C 2
79 prmz P P
80 1 79 syl φ P
81 80 zcnd φ P
82 81 sqvald φ P 2 = P P
83 19 22 mulcomd φ C B = B C
84 83 oveq2d φ A D + C B = A D + B C
85 84 oveq1d φ A D + C B 2 = A D + B C 2
86 85 oveq2d φ A C B D 2 + A D + C B 2 = A C B D 2 + A D + B C 2
87 78 82 86 3eqtr4d φ P 2 = A C B D 2 + A D + C B 2
88 74 87 breqtrrd φ A D + C B 2 P 2
89 88 adantr φ P A D + C B A D + C B 2 P 2
90 32 53 zmulcld φ A D
91 33 49 zmulcld φ C B
92 90 91 zaddcld φ A D + C B
93 dvdssqim P A D + C B P A D + C B P 2 A D + C B 2
94 80 92 93 syl2anc φ P A D + C B P 2 A D + C B 2
95 zsqcl P P 2
96 80 95 syl φ P 2
97 dvdsle P 2 A D + C B 2 P 2 A D + C B 2 P 2 A D + C B 2
98 96 70 97 syl2anc φ P 2 A D + C B 2 P 2 A D + C B 2
99 94 98 syld φ P A D + C B P 2 A D + C B 2
100 99 imp φ P A D + C B P 2 A D + C B 2
101 96 zred φ P 2
102 71 101 letri3d φ A D + C B 2 = P 2 A D + C B 2 P 2 P 2 A D + C B 2
103 102 adantr φ P A D + C B A D + C B 2 = P 2 A D + C B 2 P 2 P 2 A D + C B 2
104 89 100 103 mpbir2and φ P A D + C B A D + C B 2 = P 2
105 87 adantr φ P A D + C B P 2 = A C B D 2 + A D + C B 2
106 104 105 eqtr2d φ P A D + C B A C B D 2 + A D + C B 2 = A D + C B 2
107 71 recnd φ A D + C B 2
108 72 recnd φ A C B D 2
109 107 107 108 subadd2d φ A D + C B 2 A D + C B 2 = A C B D 2 A C B D 2 + A D + C B 2 = A D + C B 2
110 109 adantr φ P A D + C B A D + C B 2 A D + C B 2 = A C B D 2 A C B D 2 + A D + C B 2 = A D + C B 2
111 106 110 mpbird φ P A D + C B A D + C B 2 A D + C B 2 = A C B D 2
112 107 subidd φ A D + C B 2 A D + C B 2 = 0
113 112 adantr φ P A D + C B A D + C B 2 A D + C B 2 = 0
114 111 113 eqtr3d φ P A D + C B A C B D 2 = 0
115 47 114 sqeq0d φ P A D + C B A C B D = 0
116 38 40 115 subeq0d φ P A D + C B A C = B D
117 36 116 breqtrd φ P A D + C B A B D
118 1 32 49 8 2sqcoprm φ A gcd B = 1
119 118 adantr φ P A D + C B A gcd B = 1
120 coprmdvds A B D A B D A gcd B = 1 A D
121 32 49 53 120 syl3anc φ A B D A gcd B = 1 A D
122 121 adantr φ P A D + C B A B D A gcd B = 1 A D
123 117 119 122 mp2and φ P A D + C B A D
124 dvdsle A D A D A D
125 32 58 124 syl2anc φ A D A D
126 125 adantr φ P A D + C B A D A D
127 123 126 mpd φ P A D + C B A D
128 52 nnrpd φ A +
129 128 rprege0d φ A 0 A
130 5 nn0ge0d φ 0 D
131 le2sq A 0 A D 0 D A D A 2 D 2
132 129 43 130 131 syl12anc φ A D A 2 D 2
133 132 adantr φ P A D + C B A D A 2 D 2
134 127 133 mpbid φ P A D + C B A 2 D 2
135 52 nnsqcld φ A 2
136 135 nnred φ A 2
137 zsqcl D D 2
138 53 137 syl φ D 2
139 138 zred φ D 2
140 136 139 suble0d φ A 2 D 2 0 A 2 D 2
141 140 adantr φ P A D + C B A 2 D 2 0 A 2 D 2
142 134 141 mpbird φ P A D + C B A 2 D 2 0
143 31 142 eqbrtrrd φ P A D + C B C 2 B 2 0
144 dvdsmul1 B D B B D
145 49 53 144 syl2anc φ B B D
146 145 adantr φ P A D + C B B B D
147 146 116 breqtrrd φ P A D + C B B A C
148 32 49 gcdcomd φ A gcd B = B gcd A
149 148 118 eqtr3d φ B gcd A = 1
150 149 adantr φ P A D + C B B gcd A = 1
151 coprmdvds B A C B A C B gcd A = 1 B C
152 49 32 33 151 syl3anc φ B A C B gcd A = 1 B C
153 152 adantr φ P A D + C B B A C B gcd A = 1 B C
154 147 150 153 mp2and φ P A D + C B B C
155 dvdsle B C B C B C
156 49 62 155 syl2anc φ B C B C
157 156 adantr φ P A D + C B B C B C
158 154 157 mpd φ P A D + C B B C
159 13 11 17 15 le2sqd φ B C B 2 C 2
160 159 adantr φ P A D + C B B C B 2 C 2
161 158 160 mpbid φ P A D + C B B 2 C 2
162 11 resqcld φ C 2
163 zsqcl B B 2
164 49 163 syl φ B 2
165 164 zred φ B 2
166 162 165 subge0d φ 0 C 2 B 2 B 2 C 2
167 166 adantr φ P A D + C B 0 C 2 B 2 B 2 C 2
168 161 167 mpbird φ P A D + C B 0 C 2 B 2
169 136 139 resubcld φ A 2 D 2
170 30 169 eqeltrrd φ C 2 B 2
171 0red φ 0
172 170 171 letri3d φ C 2 B 2 = 0 C 2 B 2 0 0 C 2 B 2
173 172 adantr φ P A D + C B C 2 B 2 = 0 C 2 B 2 0 0 C 2 B 2
174 143 168 173 mpbir2and φ P A D + C B C 2 B 2 = 0
175 21 24 174 subeq0d φ P A D + C B C 2 = B 2
176 12 14 16 18 175 sq11d φ P A D + C B C = B
177 10 176 breqtrrd φ P A D + C B A C
178 7 adantr φ P A D + C B C D
179 41 adantr φ P A D + C B A
180 43 adantr φ P A D + C B D
181 2 nn0ge0d φ 0 A
182 181 adantr φ P A D + C B 0 A
183 130 adantr φ P A D + C B 0 D
184 26 adantr φ P A D + C B A 2
185 28 adantr φ P A D + C B D 2
186 168 31 breqtrrd φ P A D + C B 0 A 2 D 2
187 169 171 letri3d φ A 2 D 2 = 0 A 2 D 2 0 0 A 2 D 2
188 187 adantr φ P A D + C B A 2 D 2 = 0 A 2 D 2 0 0 A 2 D 2
189 142 186 188 mpbir2and φ P A D + C B A 2 D 2 = 0
190 184 185 189 subeq0d φ P A D + C B A 2 = D 2
191 179 180 182 183 190 sq11d φ P A D + C B A = D
192 178 191 breqtrrd φ P A D + C B C A
193 41 11 letri3d φ A = C A C C A
194 193 adantr φ P A D + C B A = C A C C A
195 177 192 194 mpbir2and φ P A D + C B A = C
196 25 adantr φ P A D C B A
197 19 adantr φ P A D C B C
198 22 adantr φ P A D C B B
199 65 adantr φ P A D C B B 0
200 43 adantr φ P A D C B D
201 13 adantr φ P A D C B B
202 130 adantr φ P A D C B 0 D
203 17 adantr φ P A D C B 0 B
204 28 adantr φ P A D C B D 2
205 23 adantr φ P A D C B B 2
206 prmnn P P
207 1 206 syl φ P
208 207 nnne0d φ P 0
209 208 neneqd φ ¬ P = 0
210 209 adantr φ P A D C B ¬ P = 0
211 81 28 23 subdid φ P D 2 B 2 = P D 2 P B 2
212 81 28 mulcld φ P D 2
213 26 28 mulcld φ A 2 D 2
214 81 23 mulcld φ P B 2
215 20 23 mulcld φ C 2 B 2
216 23 28 mulcomd φ B 2 D 2 = D 2 B 2
217 8 oveq1d φ A 2 + B 2 - A 2 = P A 2
218 26 23 pncan2d φ A 2 + B 2 - A 2 = B 2
219 217 218 eqtr3d φ P A 2 = B 2
220 219 oveq1d φ P A 2 D 2 = B 2 D 2
221 9 oveq1d φ C 2 + D 2 - C 2 = P C 2
222 20 28 pncan2d φ C 2 + D 2 - C 2 = D 2
223 221 222 eqtr3d φ P C 2 = D 2
224 223 oveq1d φ P C 2 B 2 = D 2 B 2
225 216 220 224 3eqtr4d φ P A 2 D 2 = P C 2 B 2
226 81 26 28 subdird φ P A 2 D 2 = P D 2 A 2 D 2
227 81 20 23 subdird φ P C 2 B 2 = P B 2 C 2 B 2
228 225 226 227 3eqtr3d φ P D 2 A 2 D 2 = P B 2 C 2 B 2
229 212 213 214 215 228 subeqxfrd φ P D 2 P B 2 = A 2 D 2 C 2 B 2
230 211 229 eqtrd φ P D 2 B 2 = A 2 D 2 C 2 B 2
231 25 27 sqmuld φ A D 2 = A 2 D 2
232 19 22 sqmuld φ C B 2 = C 2 B 2
233 231 232 oveq12d φ A D 2 C B 2 = A 2 D 2 C 2 B 2
234 25 27 mulcld φ A D
235 19 22 mulcld φ C B
236 subsq A D C B A D 2 C B 2 = A D + C B A D C B
237 234 235 236 syl2anc φ A D 2 C B 2 = A D + C B A D C B
238 230 233 237 3eqtr2d φ P D 2 B 2 = A D + C B A D C B
239 238 adantr φ P A D C B P D 2 B 2 = A D + C B A D C B
240 234 adantr φ P A D C B A D
241 simpll φ P A D C B ¬ A D = C B φ
242 simpr φ P A D C B ¬ A D = C B ¬ A D = C B
243 242 neqned φ P A D C B ¬ A D = C B A D C B
244 90 91 zsubcld φ A D C B
245 dvdssqim P A D C B P A D C B P 2 A D C B 2
246 80 244 245 syl2anc φ P A D C B P 2 A D C B 2
247 246 imp φ P A D C B P 2 A D C B 2
248 247 adantr φ P A D C B ¬ A D = C B P 2 A D C B 2
249 96 adantr φ A D C B P 2
250 244 adantr φ A D C B A D C B
251 234 adantr φ A D C B A D
252 235 adantr φ A D C B C B
253 simpr φ A D C B A D C B
254 251 252 253 subne0d φ A D C B A D C B 0
255 250 254 znsqcld φ A D C B A D C B 2
256 dvdsle P 2 A D C B 2 P 2 A D C B 2 P 2 A D C B 2
257 249 255 256 syl2anc φ A D C B P 2 A D C B 2 P 2 A D C B 2
258 257 imp φ A D C B P 2 A D C B 2 P 2 A D C B 2
259 241 243 248 258 syl21anc φ P A D C B ¬ A D = C B P 2 A D C B 2
260 41 43 remulcld φ A D
261 11 13 remulcld φ C B
262 260 261 resubcld φ A D C B
263 262 resqcld φ A D C B 2
264 62 nnrpd φ C +
265 128 264 rpmulcld φ A C +
266 67 nnrpd φ B +
267 58 nnrpd φ D +
268 266 267 rpmulcld φ B D +
269 265 268 rpaddcld φ A C + B D +
270 2z 2
271 270 a1i φ 2
272 269 271 rpexpcld φ A C + B D 2 +
273 263 272 ltaddrp2d φ A D C B 2 < A C + B D 2 + A D C B 2
274 bhmafibid2 A B C D A 2 + B 2 C 2 + D 2 = A C + B D 2 + A D B C 2
275 41 13 11 43 274 syl22anc φ A 2 + B 2 C 2 + D 2 = A C + B D 2 + A D B C 2
276 75 275 eqtr3d φ P P = A C + B D 2 + A D B C 2
277 83 oveq2d φ A D C B = A D B C
278 277 oveq1d φ A D C B 2 = A D B C 2
279 278 oveq2d φ A C + B D 2 + A D C B 2 = A C + B D 2 + A D B C 2
280 276 279 eqtr4d φ P P = A C + B D 2 + A D C B 2
281 273 280 breqtrrd φ A D C B 2 < P P
282 281 82 breqtrrd φ A D C B 2 < P 2
283 241 282 syl φ P A D C B ¬ A D = C B A D C B 2 < P 2
284 263 101 ltnled φ A D C B 2 < P 2 ¬ P 2 A D C B 2
285 241 284 syl φ P A D C B ¬ A D = C B A D C B 2 < P 2 ¬ P 2 A D C B 2
286 283 285 mpbid φ P A D C B ¬ A D = C B ¬ P 2 A D C B 2
287 259 286 condan φ P A D C B A D = C B
288 240 287 subeq0bd φ P A D C B A D C B = 0
289 288 oveq2d φ P A D C B A D + C B A D C B = A D + C B 0
290 234 235 addcld φ A D + C B
291 290 mul01d φ A D + C B 0 = 0
292 291 adantr φ P A D C B A D + C B 0 = 0
293 239 289 292 3eqtrd φ P A D C B P D 2 B 2 = 0
294 28 23 subcld φ D 2 B 2
295 81 294 mul0ord φ P D 2 B 2 = 0 P = 0 D 2 B 2 = 0
296 295 adantr φ P A D C B P D 2 B 2 = 0 P = 0 D 2 B 2 = 0
297 293 296 mpbid φ P A D C B P = 0 D 2 B 2 = 0
298 297 ord φ P A D C B ¬ P = 0 D 2 B 2 = 0
299 210 298 mpd φ P A D C B D 2 B 2 = 0
300 204 205 299 subeq0d φ P A D C B D 2 = B 2
301 200 201 202 203 300 sq11d φ P A D C B D = B
302 301 oveq2d φ P A D C B A D = A B
303 302 287 eqtr3d φ P A D C B A B = C B
304 196 197 198 199 303 mulcan2ad φ P A D C B A = C
305 138 164 zsubcld φ D 2 B 2
306 dvdsmul1 P D 2 B 2 P P D 2 B 2
307 80 305 306 syl2anc φ P P D 2 B 2
308 307 238 breqtrd φ P A D + C B A D C B
309 euclemma P A D + C B A D C B P A D + C B A D C B P A D + C B P A D C B
310 1 92 244 309 syl3anc φ P A D + C B A D C B P A D + C B P A D C B
311 308 310 mpbid φ P A D + C B P A D C B
312 195 304 311 mpjaodan φ A = C
313 312 oveq1d φ A 2 = C 2
314 313 oveq2d φ P A 2 = P C 2
315 314 219 223 3eqtr3d φ B 2 = D 2
316 13 43 17 130 315 sq11d φ B = D
317 312 316 jca φ A = C B = D