@@ -14,7 +14,7 @@ import tactic.omega
14
14
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` in the special
15
15
case that `d = a ^ 2 - 1`. This is then applied to prove Matiyasevic's theorem that the power
16
16
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
17
- problem.
17
+ problem. For the definition of Diophantine function, see `dioph.lean`.
18
18
19
19
## Main definition
20
20
@@ -113,8 +113,10 @@ section
113
113
def is_pell : ℤ√d → Prop | ⟨x, y⟩ := x*x - d*y*y = 1
114
114
115
115
theorem is_pell_nat {x y : ℕ} : is_pell ⟨x, y⟩ ↔ x*x - d*y*y = 1 :=
116
- ⟨λh, int.coe_nat_inj (by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
117
- λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1 , by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩
116
+ ⟨λh, int.coe_nat_inj
117
+ (by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
118
+ λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1 ,
119
+ by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩
118
120
119
121
theorem is_pell_norm : Π {b : ℤ√d}, is_pell b ↔ b * b.conj = 1
120
122
| ⟨x, y⟩ := by simp [zsqrtd.ext, is_pell, mul_comm]; ring
@@ -151,7 +153,7 @@ section
151
153
have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw ← this ; exact nat.lt_succ_self _),
152
154
have (n+1 )*(n+1 ) ≤ n*n + 1 , by rw this ; exact nat.mul_self_le_mul_self na,
153
155
have n+n ≤ 0 , from @nat.le_of_add_le_add_right (n*n + 1 ) _ _ (by ring at this ⊢; assumption),
154
- ne_of_gt d_pos $ by rw nat.eq_zero_of_le_zero (le_trans (nat.le_add_left _ _) this ) at h; exact h⟩
156
+ ne_of_gt d_pos $ by rwa nat.eq_zero_of_le_zero ((nat.le_add_left _ _).trans this ) at h⟩
155
157
156
158
theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n
157
159
| 0 := le_refl 1
@@ -450,7 +452,8 @@ section
450
452
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
451
453
(λh, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this )
452
454
(λh, by rw h; exact this ),
453
- by rw [nat.mod_eq_of_lt (x_increasing _ (nat.lt_of_succ_lt jn)), nat.mod_eq_of_lt (x_increasing _ jn)];
455
+ by rw [nat.mod_eq_of_lt (x_increasing _ (nat.lt_of_succ_lt jn)),
456
+ nat.mod_eq_of_lt (x_increasing _ jn)];
454
457
exact x_increasing _ (nat.lt_succ_self _)
455
458
456
459
theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1 )) : a = 2 ∧ n = 0 :=
@@ -487,23 +490,25 @@ section
487
490
cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein,
488
491
{ rw nat.mod_eq_of_lt (x_increasing _ lin),
489
492
have ll : xn a1 (n-1 ) + xn a1 (n-1 ) ≤ xn a1 n,
490
- { rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1 +1 ), by rw [nat.sub_add_cancel npos], xn_succ],
493
+ { rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1 +1 ),
494
+ by rw [nat.sub_add_cancel npos], xn_succ],
491
495
exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) },
492
496
have npm : (n-1 ).succ = n := nat.succ_pred_eq_of_pos npos,
493
- have il : i ≤ n - 1 := by apply nat.le_of_succ_le_succ; rw npm; exact lin,
497
+ have il : i ≤ n - 1 , { apply nat.le_of_succ_le_succ, rw npm, exact lin } ,
494
498
cases lt_or_eq_of_le il with ill ile,
495
499
{ exact lt_of_lt_of_le (nat.add_lt_add_left (x_increasing a1 ill) _) ll },
496
500
{ rw ile,
497
501
apply lt_of_le_of_ne ll,
498
502
rw ← two_mul,
499
503
exact λe, ntriv $
500
- let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1 ) (by rw [nat.sub_add_cancel npos]; exact e ) in
504
+ let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1 ) (by rwa [nat.sub_add_cancel npos]) in
501
505
have n1 : n = 1 , from le_antisymm (nat.le_of_sub_eq_zero s1) npos,
502
506
by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } },
503
507
{ rw [ein, nat.mod_self, add_zero],
504
508
exact x_increasing _ (nat.pred_lt $ ne_of_gt npos) } })
505
509
(λ (jn : j > n),
506
- have lem1 : j ≠ n → xn j % xn n < xn (j + 1 ) % xn n → xn i % xn n < xn (j + 1 ) % xn n, from λjn s,
510
+ have lem1 : j ≠ n → xn j % xn n < xn (j + 1 ) % xn n → xn i % xn n < xn (j + 1 ) % xn n,
511
+ from λjn s,
507
512
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
508
513
(λh, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ λ⟨a1, n1, i0, j2⟩,
509
514
by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s)
@@ -533,10 +538,11 @@ section
533
538
i = j :=
534
539
(le_total i j).elim
535
540
(λij, eq_of_xn_modeq_le npos ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2)
536
- (λij, (eq_of_xn_modeq_le npos ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩, (ntriv a2 n1).right i2 j0).symm)
541
+ (λij, (eq_of_xn_modeq_le npos ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩,
542
+ (ntriv a2 n1).right i2 j0).symm)
537
543
538
- theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn j ≡ xn i [MOD xn n]) :
539
- j = i ∨ j + i = 4 * n :=
544
+ theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n)
545
+ (h : xn j ≡ xn i [MOD xn n]) : j = i ∨ j + i = 4 * n :=
540
546
have i2n : i ≤ 2 *n, by apply le_trans hin; rw two_mul; apply nat.le_add_left,
541
547
have npos : 0 < n, from lt_of_lt_of_le ipos hin,
542
548
(le_or_gt j (2 * n)).imp
@@ -549,7 +555,8 @@ section
549
555
exact nat.add_le_add_left (le_of_lt j2n) _,
550
556
eq_of_xn_modeq npos i2n j42n
551
557
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [nat.sub_sub_self j4n] at t)
552
- (λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by rw[n1, i2] at hin; exact absurd hin dec_trivial⟩))
558
+ (λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by { rw [n1, i2] at hin,
559
+ exact absurd hin dec_trivial }⟩))
553
560
554
561
theorem modeq_of_xn_modeq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn j ≡ xn i [MOD xn n]) :
555
562
j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] :=
0 commit comments