comparison agda/gcd.agda @ 154:ba7d4cc92e60

... gcd (i + j) j ≡ gcd i j
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 02 Jan 2021 04:29:20 +0900
parents d78fc1951c26
children 4b6063ad6de2
comparison
equal deleted inserted replaced
153:d78fc1951c26 154:ba7d4cc92e60
83 record Comp ( m n : ℕ ) : Set where 83 record Comp ( m n : ℕ ) : Set where
84 field 84 field
85 non-1 : 1 < m 85 non-1 : 1 < m
86 comp : ℕ 86 comp : ℕ
87 is-comp : n * comp ≡ m 87 is-comp : n * comp ≡ m
88
89 gcd27 : (n m i : ℕ) → 1 < m → gcd n i ≡ m → Comp m n ∨ Comp m i
90 gcd27 n m i 1<m gn = gcd271 n n i i gn where
91 gcd271 : (n n0 i i0 : ℕ ) → gcd1 n n0 i i0 ≡ m → Comp m n0 ∨ Comp m i0
92 gcd271 zero n0 zero i0 eq with <-cmp n0 i0
93 ... | tri< a ¬b ¬c = case2 (record { non-1 = 1<m ; comp = 1 ; is-comp = subst (λ k → k ≡ m) {!!} eq })
94 ... | tri≈ ¬a refl ¬c = case1 (record { non-1 = 1<m ; comp = 1 ; is-comp = subst (λ k → k ≡ m) {!!} eq })
95 ... | tri> ¬a ¬b c = case1 (record { non-1 = 1<m ; comp = 1 ; is-comp = subst (λ k → k ≡ m) {!!} eq })
96 gcd271 zero n0 (suc zero) i0 eq = ⊥-elim ( nat-≡< eq 1<m )
97 gcd271 zero zero (suc (suc i)) i0 eq = case2 (record { non-1 = 1<m ; comp = 1 ; is-comp = subst (λ k → k ≡ m) {!!} eq })
98 gcd271 zero (suc n0) (suc (suc i)) i0 eq with gcd271 n0 (suc n0) (suc i) (suc (suc i)) eq
99 ... | case1 t = case1 t
100 -- t : Comp m (suc (suc i)), (suc n0) + (suc (suc i)) ≡ i0
101 ... | case2 t = case1 (gcd272 t) where
102 gcd272 : Comp m (suc (suc i)) → Comp m (suc n0)
103 gcd272 = {!!}
104 gcd271 (suc zero) n0 zero i0 eq = ⊥-elim ( nat-≡< eq 1<m )
105 gcd271 (suc (suc n)) n0 zero zero eq = case2 (record { non-1 = 1<m ; comp = n0 ; is-comp = subst (λ k → k ≡ m) {!!} eq })
106 gcd271 (suc (suc n)) n0 zero (suc i0) eq = {!!}
107 gcd271 (suc n) n0 (suc i) i0 eq = gcd271 n n0 i i0 (trans (sym (gcd22 n n0 i i0)) eq )
108
109 gcd26 : (n m i : ℕ) → 1 < n → 1 < m → gcd n i ≡ m → ¬ ( gcd n m ≡ 1 )
110 gcd26 n m i 1<n 1<m gi g1 = gcd261 n n m m i i 1<n 1<m gi g1 where
111 gcd261 : (n n0 m m0 i i0 : ℕ) → 1 < n → 1 < m0 → gcd1 n n0 i i0 ≡ m0 → ¬ ( gcd1 n n0 m m0 ≡ 1 )
112 gcd261 zero n0 m m0 i i0 () 1<m gi g1
113 -- gi : gcd1 (suc n) n0 zero i0 ≡ m0
114 -- g1 : gcd1 (suc n) n0 m m0 ≡ 1
115 gcd261 (suc zero) n0 m m0 zero i0 1<n 1<m gi g1 = ⊥-elim ( nat-≡< gi 1<m )
116 gcd261 (suc (suc n)) n0 zero m0 zero zero 1<n 1<m gi g1 = {!!}
117 gcd261 (suc (suc n)) n0 zero m0 zero (suc i0) 1<n 1<m gi g1 = {!!}
118 gcd261 (suc (suc n)) n0 (suc zero) m0 zero i0 1<n 1<m gi g1 = {!!}
119 gcd261 (suc (suc n)) n0 (suc (suc m)) m0 zero zero 1<n 1<m gi g1 = {!!}
120 gcd261 (suc (suc n)) n0 (suc (suc m)) m0 zero (suc i0) 1<n 1<m gi g1 = {!!}
121 -- gi : gcd1 (suc n) n0 (suc i) i0 ≡ m0
122 -- g1 : gcd1 (suc n) n0 zero m0 ≡ 1
123 gcd261 (suc n) n0 zero m0 (suc i) i0 1<n 1<m gi g1 = {!!}
124 gcd261 (suc zero) n0 (suc m) m0 (suc i) i0 1<n 1<m gi g1 = ⊥-elim ( nat-<≡ 1<n )
125 gcd261 (suc (suc zero)) n0 (suc m) m0 (suc zero) i0 1<n 1<m gi g1 = ⊥-elim ( nat-≡< gi 1<m )
126 -- gi : gcd1 0 n0 i i0 ≡ m0
127 gcd261 (suc (suc zero)) n0 (suc zero) m0 (suc (suc i)) i0 1<n 1<m gi refl = {!!}
128 -- gi : gcd1 0 n0 i i0 ≡ m0
129 -- g1 : gcd1 0 n0 m m0 ≡ 1
130 gcd261 (suc (suc zero)) n0 (suc (suc m)) m0 (suc (suc i)) i0 1<n 1<m gi g1 = {!!}
131 gcd261 (suc (suc (suc n))) n0 (suc m) m0 (suc i) i0 1<n 1<m gi g1 =
132 gcd261 (suc (suc n)) n0 m m0 i i0 (s≤s (s≤s z≤n)) 1<m gi g1
133 88
134 gcdsym2 : (i j : ℕ) → gcd1 zero i zero j ≡ gcd1 zero j zero i 89 gcdsym2 : (i j : ℕ) → gcd1 zero i zero j ≡ gcd1 zero j zero i
135 gcdsym2 i j with <-cmp i j | <-cmp j i 90 gcdsym2 i j with <-cmp i j | <-cmp j i
136 ... | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim (nat-<> a a₁) 91 ... | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim (nat-<> a a₁)
137 ... | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim (nat-≡< (sym b) a) 92 ... | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim (nat-≡< (sym b) a)
173 gcd1 (i + suc j1) (i0 + suc j) (suc j1) j0 ≡⟨ cong (λ k → gcd1 k (i0 + suc j) (suc j1) j0 ) (gcd202 i j1) ⟩ 128 gcd1 (i + suc j1) (i0 + suc j) (suc j1) j0 ≡⟨ cong (λ k → gcd1 k (i0 + suc j) (suc j1) j0 ) (gcd202 i j1) ⟩
174 gcd1 (suc (i + j1)) (i0 + suc j) (suc j1) j0 ≡⟨ gcd22 (i + j1) (i0 + suc j) j1 j0 ⟩ 129 gcd1 (suc (i + j1)) (i0 + suc j) (suc j1) j0 ≡⟨ gcd22 (i + j1) (i0 + suc j) j1 j0 ⟩
175 gcd1 (i + j1) (i0 + suc j) j1 j0 ≡⟨ gcd201 i i0 j j0 j1 ⟩ 130 gcd1 (i + j1) (i0 + suc j) j1 j0 ≡⟨ gcd201 i i0 j j0 j1 ⟩
176 gcd1 i (i0 + suc j) zero j0 ∎ where open ≡-Reasoning 131 gcd1 i (i0 + suc j) zero j0 ∎ where open ≡-Reasoning
177 gcd200 : (i i0 j j0 : ℕ) → gcd1 (i + j) (i0 + j) j j0 ≡ gcd1 i i j0 j0 132 gcd200 : (i i0 j j0 : ℕ) → gcd1 (i + j) (i0 + j) j j0 ≡ gcd1 i i j0 j0
178 -- gcd200 i i0 zero j0 = subst₂ (λ m k → gcd1 m k zero j0 ≡ gcd1 i i0 zero j0 ) (+-comm zero i) (+-comm zero i0) refl
179 gcd200 i i0 zero j0 = {!!} 133 gcd200 i i0 zero j0 = {!!}
180 gcd200 (suc (suc i)) i0 (suc j) (suc j0) = gcd201 (suc (suc i)) i0 j (suc j0) (suc j) 134 gcd200 (suc (suc i)) i0 (suc j) (suc j0) = gcd201 (suc (suc i)) i0 j (suc j0) (suc j)
181 gcd200 zero zero (suc zero) j0 = {!!} 135 gcd200 zero zero (suc zero) j0 = {!!}
182 gcd200 zero zero (suc (suc j)) j0 = {!!} 136 gcd200 zero zero (suc (suc j)) j0 = {!!}
183 gcd200 zero (suc i0) (suc j) j0 = {!!} 137 gcd200 zero (suc i0) (suc j) j0 = {!!}
184 gcd200 (suc zero) i0 (suc j) j0 = {!!} 138 gcd200 (suc zero) i0 (suc j) j0 = {!!}
185 gcd200 (suc (suc i)) i0 (suc j) zero = ? 139 gcd200 (suc (suc i)) i0 (suc j) zero = {!!}
140
141 gcd4 : ( n k : ℕ ) → gcd n k ≡ k → k ≤ n
142 gcd4 n k gn = gcd40 n n k k gn where
143 gcd40 : (i i0 j j0 : ℕ) → gcd1 i i0 j j0 ≡ j0 → j0 ≤ i0
144 gcd40 zero i0 zero j0 gn = {!!}
145 gcd40 zero i0 (suc j) j0 gn = {!!}
146 gcd40 (suc i) i0 zero j0 gn = {!!}
147 gcd40 (suc i) i0 (suc j) j0 gn = gcd40 i i0 j j0 (subst (λ k → k ≡ j0) (gcd22 i i0 j j0) gn)
148
149 gcd3 : ( n k : ℕ ) → n ≤ k + k → gcd n k ≡ k → n ≡ k
150 gcd3 n k n<2k gn = {!!}
151
152 gcd23 : ( n m k : ℕ) → gcd n k ≡ k → gcd m k ≡ k → k ≤ gcd n m
153 gcd23 = {!!}
186 154
187 gcd24 : { n m k : ℕ} → n > 1 → m > 1 → k > 1 → gcd n k ≡ k → gcd m k ≡ k → ¬ ( gcd n m ≡ 1 ) 155 gcd24 : { n m k : ℕ} → n > 1 → m > 1 → k > 1 → gcd n k ≡ k → gcd m k ≡ k → ¬ ( gcd n m ≡ 1 )
188 gcd24 {n} {m} {k} 1<n 1<m 1<k gn gm gnm = gcd21 n n m m k k 1<n 1<m 1<k gn gm gnm where 156 gcd24 {n} {m} {k} 1<n 1<m 1<k gn gm gnm = ⊥-elim ( nat-≡< (sym gnm) (≤-trans 1<k (gcd23 n m k gn gm )))
189 gcd23 : {i0 j0 : ℕ } → 1 < i0 → 1 < j0 → 1 < gcd1 zero i0 zero j0
190 gcd23 {i0} {j0} 1<i 1<j with <-cmp i0 j0
191 ... | tri< a ¬b ¬c = 1<j
192 ... | tri≈ ¬a refl ¬c = 1<i
193 ... | tri> ¬a ¬b c = 1<i
194 1<ss : {j : ℕ} → 1 < suc (suc j)
195 1<ss = s≤s (s≤s z≤n)
196 gcd21 : ( i i0 j j0 o o0 : ℕ ) → 1 < i0 → 1 < j0 → 1 < o0 → gcd1 i i0 o o0 ≡ k → gcd1 j j0 o o0 ≡ k → gcd1 i i0 j j0 ≡ 1 → ⊥
197 gcd21 zero i0 zero j0 o o0 1<i 1<j 1<o refl gm gnm = nat-≡< (sym gnm) (gcd23 1<i 1<j)
198 gcd21 zero i0 (suc j) j0 zero o0 1<i 1<j 1<o refl gm gnm = gcd25 i0 o0 j j0 1<o 1<i 1<k gm (subst (λ k → k ≡ 1) (gcdsym1 zero _ (suc j) _) gnm) where
199 -- gcd1 (suc j) (suc (suc j)) (suc o0) (suc (suc o0)) ≡ suc (suc i0) , gcd1 (suc j) (suc (suc j)) (suc i0) (suc (suc i0)) ≡ 1
200 gcd25 : (i0 o0 j j0 : ℕ) → 1 < o0 → 1 < i0
201 → 1 < gcd1 zero i0 zero o0
202 → ( gm : gcd1 (suc j) j0 zero o0 ≡ gcd1 zero i0 zero o0 ) → (gnm : gcd1 (suc j) j0 zero i0 ≡ 1) → ⊥
203 gcd25 i0 o0 zero j0 1<o 1<i 1<k gm refl with <-cmp i0 o0
204 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< gm 1<o )
205 ... | tri≈ ¬a refl ¬c = ⊥-elim ( nat-≡< gm 1<o )
206 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< gm 1<i )
207 -- gm : gcd1 (suc j) (suc (suc j)) (suc o0) (suc (suc o0)) ≡ (gcd1 zero (suc i0) zero (suc (suc o0))
208 -- gcd1 j (suc (suc j)) o0 (suc (suc o0))
209 -- gnm : gcd1 (suc j) (suc (suc j)) i0 (suc i0) ≡ 1
210 gcd25 i0 (suc zero) (suc j) j0 1<o 1<i 1<k gm gnm = {!!} -- ⊥-elim ( nat-≤> (subst (λ k → k ≤ 1 ) gm (gcd27 (suc j) (suc (suc j)))) 1<k )
211 gcd25 (suc zero) (suc (suc o0)) (suc j) j0 1<o 1<i 1<k gm gnm = {!!}
212 -- (suc (suc i0)) > (suc (suc o0)) → gm = gnm → (suc (suc i0)) ≡ 1
213 -- (suc (suc i0)) < (suc (suc o0)) → ? gcd1 (suc j) (suc (suc j)) (suc o0) (suc (suc o0)) ≡ (suc (suc o0))
214 -- gcd1 (suc j) (suc (suc j)) (suc i0) (suc (suc i0)) ≡ 1
215 gcd25 (suc (suc i0)) (suc (suc o0)) (suc j) j0 1<o 1<i 1<k gm gnm with <-cmp (suc (suc i0)) (suc (suc o0))
216 ... | tri< a ¬b ¬c = {!!}
217 ... | tri≈ ¬a b ¬c = {!!}
218 ... | tri> ¬a ¬b c = gcd26 {!!} {!!} {!!} {!!} {!!} {!!} {!!}
219 gcd21 zero i0 (suc j) j0 (suc zero) o0 1<i 1<j 1<o refl gm gnm = nat-<≡ 1<k
220 gcd21 zero (suc i0) (suc j) j0 (suc (suc o)) o0 1<i 1<j 1<o gn gm gnm =
221 gcd21 i0 {!!} (suc j) j0 (suc o) (suc (suc o)) 1<i 1<j {!!} gn {!!} {!!}
222 gcd21 (suc i) i0 zero j0 o o0 1<i 1<j 1<o gn gm gnm = {!!}
223 gcd21 (suc i) i0 (suc j) j0 zero o0 1<i 1<j 1<o gn gm gnm = {!!}
224 gcd21 (suc i) i0 (suc j) j0 (suc o) o0 1<i 1<j 1<o gn gm gnm =
225 gcd21 i i0 j j0 o o0 1<i 1<j 1<o (subst (λ m → m ≡ k) (gcd22 i i0 _ _ ) gn)
226 (subst (λ m → m ≡ k) (gcd22 j j0 _ _ ) gm) (subst (λ k → k ≡ 1) (gcd22 i i0 _ _ ) gnm)
227 157
228 record Even (i : ℕ) : Set where 158 record Even (i : ℕ) : Set where
229 field 159 field
230 j : ℕ 160 j : ℕ
231 is-twice : i ≡ 2 * j 161 is-twice : i ≡ 2 * j