annotate automaton-in-agda/src/root2.agda @ 253:012f79b51dba

... prime version
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 29 Jun 2021 23:24:03 +0900
parents 9d2cba39b33c
children 24c721da4f27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module root2 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
3 open import Data.Nat
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
4 open import Data.Nat.Properties
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Empty
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
6 open import Data.Unit using (⊤ ; tt)
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Binary.PropositionalEquality
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
9 open import Relation.Binary.Definitions
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
148
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
11 open import gcd
159
5530b3789e0c add even
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 148
diff changeset
12 open import even
142
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
13 open import nat
231
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
14 open import logic
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
15
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
16 record Rational : Set where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
17 field
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
18 i j : ℕ
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
19 coprime : gcd i j ≡ 1
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
231
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
21 open _∧_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
23 open import prime
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
24
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
25 -- equlid : ( n m k : ℕ ) → 1 < k → 1 < n → Prime k → Dividable k ( n * m ) → Dividable k n ∨ Dividable k m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
26 -- equlid = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 199
diff changeset
27
233
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 231
diff changeset
28 divdable^2 : ( n k : ℕ ) → 1 < k → 1 < n → Prime k → Dividable k ( n * n ) → Dividable k n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 231
diff changeset
29 divdable^2 zero zero () 1<n pk dn2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 231
diff changeset
30 divdable^2 (suc n) (suc k) 1<k 1<n pk dn2 with decD {suc k} {suc n} 1<k
159
5530b3789e0c add even
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 148
diff changeset
31 ... | yes y = y
250
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 233
diff changeset
32 ... | no non with gcd-euclid (suc k) (suc n) (suc n) 1<k (<-trans a<sa 1<n) (<-trans a<sa 1<n) (Prime.isPrime pk) dn2
233
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 231
diff changeset
33 ... | case1 dn = dn
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 231
diff changeset
34 ... | case2 dm = dm
159
5530b3789e0c add even
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 148
diff changeset
35
199
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 198
diff changeset
36 -- gcd-div : ( i j k : ℕ ) → (if : Dividable k i) (jf : Dividable k j )
186
08f4ec41ea93 even→gcd
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
37 -- → Dividable k ( gcd i j )
08f4ec41ea93 even→gcd
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
38
253
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
39 root-prime-irrational : ( n m p : ℕ ) → n > 1 → Prime (suc p) → m > 1 → (suc p) * n * n ≡ m * m → ¬ (gcd n m ≡ 1)
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
40 root-prime-irrational n m p n>1 pn m>1 pnm = rot13 ( gcd-div n m (suc p) 1<sp dn dm ) where
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
41 1<sp : 1 < suc p
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
42 1<sp = Prime.p>1 pn
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
43 rot13 : {m : ℕ } → Dividable (suc p) m → m ≡ 1 → ⊥
185
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
44 rot13 d refl with Dividable.factor d | Dividable.is-factor d
253
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
45 ... | zero | () -- gcd 0 m ≡ 1
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
46 ... | suc n | x = ⊥-elim ( nat-≡< (sym x) rot17 ) where -- x : (suc n * suc p + 0) ≡ 1
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
47 rot17 : suc n * suc p + 0 > 1
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
48 rot17 = begin
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
49 2 ≡⟨ refl ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
50 suc (1 * 1 ) ≤⟨ {!!} ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
51 suc (1 * suc p ) <⟨ {!!} ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
52 suc (0 + n * suc p ) ≤⟨ {!!} ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
53 suc (p + n * suc p ) ≡⟨ +-comm 0 _ ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
54 suc n * suc p + 0 ∎ where open ≤-Reasoning
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
55 dm : Dividable (suc p) m
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
56 dm = divdable^2 m (suc p) 1<sp m>1 pn record { factor = n * n ; is-factor = begin
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
57 (n * n) * (suc p) + 0 ≡⟨ +-comm _ 0 ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
58 (n * n) * (suc p) ≡⟨ *-comm (n * n) (suc p) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
59 (suc p) * (n * n) ≡⟨ sym (*-assoc (suc p) n n) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
60 (suc p * n) * n ≡⟨ pnm ⟩
250
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 233
diff changeset
61 m * m ∎ } where open ≡-Reasoning
253
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
62 -- (suc p) * n * n = 2m' 2m'
251
9d2cba39b33c root2 done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 250
diff changeset
63 -- n * n = m' 2m'
250
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 233
diff changeset
64 df = Dividable.factor dm
253
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
65 dn : Dividable (suc p) n
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
66 dn = divdable^2 n (suc p) 1<sp n>1 pn record { factor = df * df ; is-factor = begin
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
67 df * df * (suc p) + 0 ≡⟨ *-cancelʳ-≡ _ _ {p} ( begin
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
68 (df * df * (suc p) + 0) * (suc p) ≡⟨ cong (λ k → k * (suc p)) (+-comm (df * df * (suc p)) 0) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
69 ((df * df) * (suc p)) * (suc p) ≡⟨ cong (λ k → k * (suc p)) (*-assoc df df (suc p) ) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
70 (df * (df * (suc p))) * (suc p) ≡⟨ cong (λ k → (df * k ) * (suc p)) (*-comm df (suc p)) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
71 (df * ((suc p) * df)) * (suc p) ≡⟨ sym ( cong (λ k → k * (suc p)) (*-assoc df (suc p) df ) ) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
72 ((df * (suc p)) * df) * (suc p) ≡⟨ *-assoc (df * (suc p)) df (suc p) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
73 (df * (suc p)) * (df * (suc p)) ≡⟨ cong₂ (λ j k → j * k ) (+-comm 0 (df * (suc p))) (+-comm 0 _) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
74 (df * (suc p) + 0) * (df * (suc p) + 0) ≡⟨ cong₂ (λ j k → j * k) (Dividable.is-factor dm ) (Dividable.is-factor dm )⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
75 m * m ≡⟨ sym pnm ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
76 (suc p) * n * n ≡⟨ cong (λ k → k * n) (*-comm (suc p) n) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
77 n * (suc p) * n ≡⟨ *-assoc n (suc p) n ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
78 n * (suc p * n) ≡⟨ cong (λ k → n * k) (*-comm (suc p) n) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
79 n * (n * suc p) ≡⟨ sym (*-assoc n n (suc p)) ⟩
012f79b51dba ... prime version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 251
diff changeset
80 n * n * (suc p) ∎ ) ⟩
250
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 233
diff changeset
81 n * n ∎ } where open ≡-Reasoning
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
185
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
83