Mercurial > hg > Members > kono > Proof > automaton
annotate automaton-in-agda/src/non-regular.agda @ 412:b85402051cdb
add mul
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Apr 2024 13:38:20 +0900 |
parents | af8f630b7e60 |
children |
rev | line source |
---|---|
405 | 1 {-# OPTIONS --cubical-compatible --safe #-} |
2 | |
141 | 3 module non-regular where |
4 | |
5 open import Data.Nat | |
274 | 6 open import Data.Empty |
141 | 7 open import Data.List |
278
e89957b99662
dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
277
diff
changeset
|
8 open import Data.Maybe hiding ( map ) |
141 | 9 open import Relation.Binary.PropositionalEquality hiding ( [_] ) |
10 open import logic | |
11 open import automaton | |
274 | 12 open import automaton-ex |
278
e89957b99662
dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
277
diff
changeset
|
13 open import finiteSetUtil |
141 | 14 open import finiteSet |
392 | 15 open import Relation.Nullary |
274 | 16 open import regular-language |
306 | 17 open import nat |
385 | 18 open import pumping |
306 | 19 |
141 | 20 |
274 | 21 open FiniteSet |
22 | |
385 | 23 list-eq : List In2 → List In2 → Bool |
24 list-eq [] [] = true | |
25 list-eq [] (x ∷ s1) = false | |
26 list-eq (x ∷ s) [] = false | |
27 list-eq (i0 ∷ s) (i0 ∷ s1) = false | |
28 list-eq (i0 ∷ s) (i1 ∷ s1) = false | |
29 list-eq (i1 ∷ s) (i0 ∷ s1) = false | |
392 | 30 list-eq (i1 ∷ s) (i1 ∷ s1) = list-eq s s1 |
385 | 31 |
392 | 32 input-addi0 : ( n : ℕ ) → List In2 → List In2 |
385 | 33 input-addi0 zero x = x |
34 input-addi0 (suc i) x = i0 ∷ input-addi0 i x | |
35 | |
392 | 36 input-addi1 : ( n : ℕ ) → List In2 |
385 | 37 input-addi1 zero = [] |
38 input-addi1 (suc i) = i1 ∷ input-addi1 i | |
274 | 39 |
392 | 40 inputnn0 : ( n : ℕ ) → List In2 |
385 | 41 inputnn0 n = input-addi0 n (input-addi1 n) |
42 | |
412 | 43 -- |
44 -- using count of i0 and i1 makes the proof easier | |
45 -- | |
385 | 46 inputnn1-i1 : (i : ℕ) → List In2 → Bool |
47 inputnn1-i1 zero [] = true | |
48 inputnn1-i1 (suc _) [] = false | |
49 inputnn1-i1 zero (i1 ∷ x) = false | |
50 inputnn1-i1 (suc i) (i1 ∷ x) = inputnn1-i1 i x | |
51 inputnn1-i1 zero (i0 ∷ x) = false | |
52 inputnn1-i1 (suc _) (i0 ∷ x) = false | |
53 | |
54 inputnn1-i0 : (i : ℕ) → List In2 → ℕ ∧ List In2 | |
55 inputnn1-i0 i [] = ⟪ i , [] ⟫ | |
56 inputnn1-i0 i (i1 ∷ x) = ⟪ i , (i1 ∷ x) ⟫ | |
392 | 57 inputnn1-i0 i (i0 ∷ x) = inputnn1-i0 (suc i) x |
385 | 58 |
59 open _∧_ | |
60 | |
61 inputnn1 : List In2 → Bool | |
62 inputnn1 x = inputnn1-i1 (proj1 (inputnn1-i0 0 x)) (proj2 (inputnn1-i0 0 x)) | |
274 | 63 |
64 t1 = inputnn1 ( i0 ∷ i1 ∷ [] ) | |
65 t2 = inputnn1 ( i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] ) | |
277 | 66 t3 = inputnn1 ( i0 ∷ i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] ) |
274 | 67 |
385 | 68 t4 : inputnn1 ( inputnn0 5 ) ≡ true |
274 | 69 t4 = refl |
70 | |
291 | 71 t5 : ( n : ℕ ) → Set |
385 | 72 t5 n = inputnn1 ( inputnn0 n ) ≡ true |
73 | |
405 | 74 import Level |
75 | |
76 cons-inject : {n : Level.Level } (A : Set n) { a b : A } {x1 x2 : List A} → a ∷ x1 ≡ b ∷ x2 → x1 ≡ x2 | |
77 cons-inject _ refl = refl | |
385 | 78 |
79 append-[] : {A : Set} {x1 : List A } → x1 ++ [] ≡ x1 | |
80 append-[] {A} {[]} = refl | |
81 append-[] {A} {x ∷ x1} = cong (λ k → x ∷ k) (append-[] {A} {x1} ) | |
82 | |
83 open import Data.Nat.Properties | |
84 open import Relation.Binary.Definitions | |
85 open import Relation.Binary.PropositionalEquality | |
291 | 86 |
388 | 87 nn30 : (y : List In2) → (j : ℕ) → proj2 (inputnn1-i0 (suc j) y) ≡ proj2 (inputnn1-i0 j y ) |
88 nn30 [] _ = refl | |
89 nn30 (i0 ∷ y) j = nn30 y (suc j) | |
90 nn30 (i1 ∷ y) _ = refl | |
91 | |
92 nn31 : (y : List In2) → (j : ℕ) → proj1 (inputnn1-i0 (suc j) y) ≡ suc (proj1 (inputnn1-i0 j y )) | |
93 nn31 [] _ = refl | |
94 nn31 (i0 ∷ y) j = nn31 y (suc j) | |
95 nn31 (i1 ∷ y) _ = refl | |
96 | |
385 | 97 nn01 : (i : ℕ) → inputnn1 ( inputnn0 i ) ≡ true |
98 nn01 i = subst₂ (λ j k → inputnn1-i1 j k ≡ true) (sym (nn07 i 0 refl)) (sym (nn09 i)) (nn04 i) where | |
99 nn07 : (j x : ℕ) → x + j ≡ i → proj1 ( inputnn1-i0 x (input-addi0 j (input-addi1 i))) ≡ x + j | |
405 | 100 nn07 zero x eq with input-addi1 i in eq1 |
101 ... | [] = +-comm 0 _ | |
102 ... | i0 ∷ t = ⊥-elim ( nn08 i eq1 ) where | |
385 | 103 nn08 : (i : ℕ) → ¬ (input-addi1 i ≡ i0 ∷ t ) |
104 nn08 zero () | |
105 nn08 (suc i) () | |
405 | 106 ... | i1 ∷ t = +-comm 0 _ |
392 | 107 nn07 (suc j) x eq = trans (nn07 j (suc x) (trans (cong (λ k → k + j) (+-comm 1 _ )) (trans (+-assoc x _ _) eq)) ) |
385 | 108 (trans (+-assoc 1 x _) (trans (cong (λ k → k + j) (+-comm 1 _) ) (+-assoc x 1 _) )) |
109 nn09 : (x : ℕ) → proj2 ( inputnn1-i0 0 (input-addi0 x (input-addi1 i))) ≡ input-addi1 i | |
405 | 110 nn09 zero with input-addi1 i in eq1 |
111 ... | [] = refl | |
112 ... | i0 ∷ t = ⊥-elim ( nn08 i eq1 ) where | |
385 | 113 nn08 : (i : ℕ) → ¬ (input-addi1 i ≡ i0 ∷ t ) |
114 nn08 zero () | |
115 nn08 (suc i) () | |
405 | 116 ... | i1 ∷ t = refl |
392 | 117 nn09 (suc j) = trans (nn30 (input-addi0 j (input-addi1 i)) 0) (nn09 j ) |
385 | 118 nn04 : (i : ℕ) → inputnn1-i1 i (input-addi1 i) ≡ true |
119 nn04 zero = refl | |
120 nn04 (suc i) = nn04 i | |
121 | |
393 | 122 half : (x : List In2) → ℕ |
123 half [] = 0 | |
124 half (x ∷ []) = 0 | |
125 half (x ∷ x₁ ∷ x₂) = suc (half x₂) | |
126 | |
127 top-is-i0 : (x : List In2) → Bool | |
128 top-is-i0 [] = true | |
129 top-is-i0 (i0 ∷ _) = true | |
130 top-is-i0 (i1 ∷ _) = false | |
131 | |
397 | 132 -- if this is easy, we may have an easy proof |
133 -- nn02 : (x : List In2) → inputnn1 x ≡ true → x ≡ inputnn0 (half x) | |
395 | 134 |
274 | 135 -- |
136 -- if there is an automaton with n states , which accespt inputnn1, it has a trasition function. | |
137 -- The function is determinted by inputs, | |
138 -- | |
139 | |
140 open RegularLanguage | |
141 open Automaton | |
142 | |
143 open _∧_ | |
141 | 144 |
277 | 145 |
280 | 146 open RegularLanguage |
294 | 147 open import Data.Nat.Properties |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
148 open import Data.List.Properties |
294 | 149 open import nat |
280 | 150 |
392 | 151 lemmaNN : (r : RegularLanguage In2 ) → ¬ ( (s : List In2) → isRegular inputnn1 s r ) |
332 | 152 lemmaNN r Rg = tann {TA.x TAnn} (TA.non-nil-y TAnn ) (TA.xyz=is TAnn) (tr-accept→ (automaton r) _ (astart r) (TA.trace-xyz TAnn) ) |
317 | 153 (tr-accept→ (automaton r) _ (astart r) (TA.trace-xyyz TAnn) ) where |
280 | 154 n : ℕ |
155 n = suc (finite (afin r)) | |
392 | 156 nn = inputnn0 n |
280 | 157 nn03 : accept (automaton r) (astart r) nn ≡ true |
294 | 158 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n) |
304 | 159 nn09 : (n m : ℕ) → n ≤ n + m |
160 nn09 zero m = z≤n | |
161 nn09 (suc n) m = s≤s (nn09 n m) | |
295 | 162 nn04 : Trace (automaton r) nn (astart r) |
392 | 163 nn04 = tr-accept← (automaton r) nn (astart r) nn03 |
315 | 164 nntrace = tr→qs (automaton r) nn (astart r) nn04 |
392 | 165 nn07 : (n : ℕ) → length (inputnn0 n ) ≡ n + n |
385 | 166 nn07 i = nn19 i where |
167 nn17 : (i : ℕ) → length (input-addi1 i) ≡ i | |
168 nn17 zero = refl | |
169 nn17 (suc i)= cong suc (nn17 i) | |
170 nn18 : (i j : ℕ) → length (input-addi0 j (input-addi1 i)) ≡ j + length (input-addi1 i ) | |
171 nn18 i zero = refl | |
172 nn18 i (suc j)= cong suc (nn18 i j) | |
173 nn19 : (i : ℕ) → length (input-addi0 i ( input-addi1 i )) ≡ i + i | |
174 nn19 i = begin | |
175 length (input-addi0 i ( input-addi1 i )) ≡⟨ nn18 i i ⟩ | |
176 i + length (input-addi1 i) ≡⟨ cong (λ k → i + k) ( nn17 i) ⟩ | |
392 | 177 i + i ∎ where open ≡-Reasoning |
294 | 178 nn05 : length nntrace > finite (afin r) |
179 nn05 = begin | |
180 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩ | |
181 n + n ≡⟨ sym (nn07 n) ⟩ | |
385 | 182 length (inputnn0 n ) ≡⟨ tr→qs=is (automaton r) (inputnn0 n ) (astart r) nn04 ⟩ |
294 | 183 length nntrace ∎ where open ≤-Reasoning |
315 | 184 nn06 : Dup-in-list ( afin r) (tr→qs (automaton r) nn (astart r) nn04) |
304 | 185 nn06 = dup-in-list>n (afin r) nntrace nn05 |
332 | 186 |
304 | 187 TAnn : TA (automaton r) (astart r) nn |
317 | 188 TAnn = pumping-lemma (automaton r) (afin r) (astart r) (Dup-in-list.dup nn06) nn nn04 (Dup-in-list.is-dup nn06) |
332 | 189 |
385 | 190 open import Tactic.MonoidSolver using (solve; solve-macro) |
191 | |
392 | 192 -- there is a counter example |
193 -- | |
317 | 194 tann : {x y z : List In2} → ¬ y ≡ [] |
195 → x ++ y ++ z ≡ nn | |
196 → accept (automaton r) (astart r) (x ++ y ++ z) ≡ true → ¬ (accept (automaton r) (astart r) (x ++ y ++ y ++ z) ≡ true ) | |
387 | 197 tann {x} {y} {z} ny eq axyz axyyz = ¬-bool (nn10 x y z ny (trans (Rg (x ++ y ++ z)) axyz ) ) (trans (Rg (x ++ y ++ y ++ z)) axyyz ) where |
385 | 198 count0 : (x : List In2) → ℕ |
199 count0 [] = 0 | |
200 count0 (i0 ∷ x) = suc (count0 x) | |
201 count0 (i1 ∷ x) = count0 x | |
202 count1 : (x : List In2) → ℕ | |
203 count1 [] = 0 | |
204 count1 (i1 ∷ x) = suc (count1 x) | |
205 count1 (i0 ∷ x) = count1 x | |
392 | 206 -- |
207 -- prove some obvious fact | |
208 -- | |
387 | 209 c0+1=n : (x : List In2 ) → count0 x + count1 x ≡ length x |
210 c0+1=n [] = refl | |
211 c0+1=n (i0 ∷ t) = cong suc ( c0+1=n t ) | |
212 c0+1=n (i1 ∷ t) = begin | |
392 | 213 count0 t + suc (count1 t) ≡⟨ sym (+-assoc (count0 t) _ _) ⟩ |
214 (count0 t + 1 ) + count1 t ≡⟨ cong (λ k → k + count1 t) (+-comm _ 1 ) ⟩ | |
215 suc (count0 t + count1 t) ≡⟨ cong suc ( c0+1=n t ) ⟩ | |
387 | 216 suc (length t) ∎ where open ≡-Reasoning |
392 | 217 -- |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
218 nn15 : (x : List In2 ) → inputnn1 x ≡ true → count0 x ≡ count1 x |
388 | 219 nn15 x eq = nn18 where |
392 | 220 nn17 : (x : List In2 ) → (count0 x ≡ proj1 (inputnn1-i0 0 x) + count0 (proj2 (inputnn1-i0 0 x))) |
388 | 221 ∧ (count1 x ≡ 0 + count1 (proj2 (inputnn1-i0 0 x))) |
222 nn17 [] = ⟪ refl , refl ⟫ | |
223 nn17 (i0 ∷ t ) with nn17 t | |
224 ... | ⟪ eq1 , eq2 ⟫ = ⟪ begin | |
225 suc (count0 t ) ≡⟨ cong suc eq1 ⟩ | |
226 suc (proj1 (inputnn1-i0 0 t) + count0 (proj2 (inputnn1-i0 0 t))) ≡⟨ cong₂ _+_ (sym (nn31 t 0)) (cong count0 (sym (nn30 t 0))) ⟩ | |
392 | 227 proj1 (inputnn1-i0 1 t) + count0 (proj2 (inputnn1-i0 1 t)) ∎ |
388 | 228 , trans eq2 (cong count1 (sym (nn30 t 0))) ⟫ where |
229 open ≡-Reasoning | |
230 nn20 : proj2 (inputnn1-i0 1 t) ≡ proj2 (inputnn1-i0 0 t) | |
231 nn20 = nn30 t 0 | |
232 nn17 (i1 ∷ x₁) = ⟪ refl , refl ⟫ | |
233 nn19 : (n : ℕ) → (y : List In2 ) → inputnn1-i1 n y ≡ true → (count0 y ≡ 0) ∧ (count1 y ≡ n) | |
234 nn19 zero [] eq = ⟪ refl , refl ⟫ | |
235 nn19 zero (i0 ∷ y) () | |
236 nn19 zero (i1 ∷ y) () | |
392 | 237 nn19 (suc i) (i1 ∷ y) eq with nn19 i y eq |
388 | 238 ... | t = ⟪ proj1 t , cong suc (proj2 t ) ⟫ |
239 nn18 : count0 x ≡ count1 x | |
240 nn18 = begin | |
392 | 241 count0 x ≡⟨ proj1 (nn17 x) ⟩ |
242 proj1 (inputnn1-i0 0 x) + count0 (proj2 (inputnn1-i0 0 x)) ≡⟨ cong (λ k → proj1 (inputnn1-i0 0 x) + k) | |
243 (proj1 (nn19 (proj1 (inputnn1-i0 0 x)) (proj2 (inputnn1-i0 0 x)) eq)) ⟩ | |
244 proj1 (inputnn1-i0 0 x) + 0 ≡⟨ +-comm _ 0 ⟩ | |
245 0 + proj1 (inputnn1-i0 0 x) ≡⟨ cong (λ k → 0 + k) (sym (proj2 (nn19 _ _ eq))) ⟩ | |
246 0 + count1 (proj2 (inputnn1-i0 0 x)) ≡⟨ sym (proj2 (nn17 x)) ⟩ | |
388 | 247 count1 x ∎ where open ≡-Reasoning |
392 | 248 distr0 : (x y : List In2 ) → count0 (x ++ y ) ≡ count0 x + count0 y |
249 distr0 [] y = refl | |
250 distr0 (i0 ∷ x) y = cong suc (distr0 x y) | |
251 distr0 (i1 ∷ x) y = distr0 x y | |
252 distr1 : (x y : List In2 ) → count1 (x ++ y ) ≡ count1 x + count1 y | |
253 distr1 [] y = refl | |
254 distr1 (i1 ∷ x) y = cong suc (distr1 x y) | |
255 distr1 (i0 ∷ x) y = distr1 x y | |
256 -- | |
257 -- i0 .. i0 ∷ i1 .. i1 sequece does not contains i1 → i0 transition | |
258 -- | |
385 | 259 record i1i0 (z : List In2) : Set where |
260 field | |
261 a b : List In2 | |
262 i10 : z ≡ a ++ (i1 ∷ i0 ∷ b ) | |
388 | 263 nn12 : (x : List In2 ) → inputnn1 x ≡ true → ¬ i1i0 x |
391 | 264 nn12 x eq = nn17 x 0 eq where |
392 | 265 nn17 : (x : List In2 ) → (i : ℕ) |
391 | 266 → inputnn1-i1 (proj1 (inputnn1-i0 i x)) (proj2 (inputnn1-i0 i x)) ≡ true → ¬ i1i0 x |
390 | 267 nn17 [] i eq li with i1i0.a li | i1i0.i10 li |
388 | 268 ... | [] | () |
269 ... | x ∷ s | () | |
392 | 270 nn17 (i0 ∷ x₁) i eq li = nn17 x₁ (suc i) eq record { a = nn18 (i1i0.a li) (i1i0.i10 li) ; b = i1i0.b li |
391 | 271 ; i10 = nn19 (i1i0.a li) (i1i0.i10 li) } where |
392 | 272 -- first half |
391 | 273 nn18 : (a : List In2 ) → i0 ∷ x₁ ≡ a ++ ( i1 ∷ i0 ∷ i1i0.b li) → List In2 |
274 nn18 (i0 ∷ t) eq = t | |
275 nn19 : (a : List In2 ) → (eq : i0 ∷ x₁ ≡ a ++ ( i1 ∷ i0 ∷ i1i0.b li) ) | |
276 → x₁ ≡ nn18 a eq ++ i1 ∷ i0 ∷ i1i0.b li | |
405 | 277 nn19 (i0 ∷ a) eq = cons-inject In2 eq |
391 | 278 nn17 (i1 ∷ x₁) i eq li = nn20 (i1 ∷ x₁) i eq li where |
392 | 279 -- second half |
391 | 280 nn20 : (x : List In2) → (i : ℕ) → inputnn1-i1 i x ≡ true → i1i0 x → ⊥ |
392 | 281 nn20 x i eq li = nn21 (i1i0.a li) x i eq (i1i0.i10 li) where |
282 nn21 : (a x : List In2) → (i : ℕ) → inputnn1-i1 i x ≡ true → x ≡ a ++ i1 ∷ i0 ∷ i1i0.b li → ⊥ | |
283 nn21 [] [] zero eq1 () | |
284 nn21 (i0 ∷ a) [] zero eq1 () | |
285 nn21 (i1 ∷ a) [] zero eq1 () | |
286 nn21 a (i0 ∷ x₁) zero () eq0 | |
287 nn21 [] (i0 ∷ x₁) (suc i) () eq0 | |
288 nn21 (x ∷ a) (i0 ∷ x₁) (suc i) () eq0 | |
289 nn21 [] (i1 ∷ i0 ∷ x₁) (suc zero) () eq0 | |
290 nn21 [] (i1 ∷ i0 ∷ x₁) (suc (suc i)) () eq0 | |
405 | 291 nn21 (i1 ∷ a) (i1 ∷ x₁) (suc i) eq1 eq0 = nn21 a x₁ i eq1 (cons-inject In2 eq0) |
387 | 292 nn11 : (x y z : List In2 ) → ¬ y ≡ [] → inputnn1 (x ++ y ++ z) ≡ true → ¬ ( inputnn1 (x ++ y ++ y ++ z) ≡ true ) |
392 | 293 nn11 x y z ny xyz xyyz = ⊥-elim ( nn12 (x ++ y ++ y ++ z ) xyyz record { a = x ++ i1i0.a (bb23 bb22 ) |
388 | 294 ; b = i1i0.b (bb23 bb22) ++ z ; i10 = bb24 } ) where |
392 | 295 -- |
296 -- we need simple calcuraion to obtain count0 y ≡ count1 y | |
297 -- | |
385 | 298 nn21 : count0 x + count0 y + count0 y + count0 z ≡ count1 x + count1 y + count1 y + count1 z |
299 nn21 = begin | |
300 (count0 x + count0 y + count0 y) + count0 z ≡⟨ solve +-0-monoid ⟩ | |
392 | 301 count0 x + (count0 y + (count0 y + count0 z)) ≡⟨ sym (cong (λ k → count0 x + (count0 y + k)) (distr0 y _ )) ⟩ |
302 count0 x + (count0 y + count0 (y ++ z)) ≡⟨ sym (cong (λ k → count0 x + k) (distr0 y _ )) ⟩ | |
303 count0 x + (count0 (y ++ y ++ z)) ≡⟨ sym (distr0 x _ ) ⟩ | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
304 count0 (x ++ y ++ y ++ z) ≡⟨ nn15 (x ++ y ++ y ++ z) xyyz ⟩ |
392 | 305 count1 (x ++ y ++ y ++ z) ≡⟨ distr1 x _ ⟩ |
306 count1 x + (count1 (y ++ y ++ z)) ≡⟨ cong (λ k → count1 x + k) (distr1 y _ ) ⟩ | |
307 count1 x + (count1 y + count1 (y ++ z)) ≡⟨ (cong (λ k → count1 x + (count1 y + k)) (distr1 y _ )) ⟩ | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
308 count1 x + (count1 y + (count1 y + count1 z)) ≡⟨ solve +-0-monoid ⟩ |
385 | 309 count1 x + count1 y + count1 y + count1 z ∎ where open ≡-Reasoning |
310 nn20 : count0 x + count0 y + count0 z ≡ count1 x + count1 y + count1 z | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
311 nn20 = begin |
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
312 count0 x + count0 y + count0 z ≡⟨ solve +-0-monoid ⟩ |
392 | 313 count0 x + (count0 y + count0 z) ≡⟨ cong (λ k → count0 x + k) (sym (distr0 y z)) ⟩ |
314 count0 x + (count0 (y ++ z)) ≡⟨ sym (distr0 x _) ⟩ | |
315 count0 (x ++ (y ++ z)) ≡⟨ nn15 (x ++ y ++ z) xyz ⟩ | |
316 count1 (x ++ (y ++ z)) ≡⟨ distr1 x _ ⟩ | |
317 count1 x + count1 (y ++ z) ≡⟨ cong (λ k → count1 x + k) (distr1 y z) ⟩ | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
318 count1 x + (count1 y + count1 z) ≡⟨ solve +-0-monoid ⟩ |
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
319 count1 x + count1 y + count1 z ∎ where open ≡-Reasoning |
387 | 320 -- this takes very long time to check and needs 10GB |
385 | 321 bb22 : count0 y ≡ count1 y |
403 | 322 bb22 = begin |
405 | 323 count0 y ≡⟨ ? ⟩ |
324 -- count0 y ≡⟨ sym ( +-cancelʳ-≡ (count1 z + count0 x + count0 y + count0 z) (count1 y) (count0 y) (+-cancelˡ-≡ _ (count1 x + count1 y) ( | |
325 -- begin | |
326 -- count1 x + count1 y + (count1 y + (count1 z + count0 x + count0 y + count0 z)) ≡⟨ solve +-0-monoid ⟩ | |
327 -- (count1 x + count1 y + count1 y + count1 z) + (count0 x + count0 y + count0 z) ≡⟨ sym (cong₂ _+_ nn21 (sym nn20)) ⟩ | |
328 -- (count0 x + count0 y + count0 y + count0 z) + (count1 x + count1 y + count1 z) ≡⟨ +-comm _ (count1 x + count1 y + count1 z) ⟩ | |
329 -- (count1 x + count1 y + count1 z) + (count0 x + count0 y + count0 y + count0 z) ≡⟨ solve +-0-monoid ⟩ | |
330 -- count1 x + count1 y + (count1 z + (count0 x + count0 y)) + count0 y + count0 z | |
331 -- ≡⟨ cong (λ k → count1 x + count1 y + (count1 z + k) + count0 y + count0 z) (+-comm (count0 x) _) ⟩ | |
332 -- count1 x + count1 y + (count1 z + (count0 y + count0 x)) + count0 y + count0 z ≡⟨ solve +-0-monoid ⟩ | |
333 -- count1 x + count1 y + ((count1 z + count0 y) + count0 x) + count0 y + count0 z | |
334 -- ≡⟨ cong (λ k → count1 x + count1 y + (k + count0 x) + count0 y + count0 z ) (+-comm (count1 z) _) ⟩ | |
335 -- count1 x + count1 y + (count0 y + count1 z + count0 x) + count0 y + count0 z ≡⟨ solve +-0-monoid ⟩ | |
336 -- count1 x + count1 y + (count0 y + (count1 z + count0 x + count0 y + count0 z)) ∎ ))) ⟩ | |
403 | 337 count1 y ∎ where open ≡-Reasoning |
392 | 338 -- |
339 -- y contains i0 and i1 , so we have i1 → i0 transition in y ++ y | |
340 -- | |
385 | 341 bb23 : count0 y ≡ count1 y → i1i0 (y ++ y) |
387 | 342 bb23 eq = bb25 y y bb26 (subst (λ k → 0 < k ) (sym eq) bb26) where |
343 bb26 : 0 < count1 y | |
344 bb26 with <-cmp 0 (count1 y) | |
345 ... | tri< a ¬b ¬c = a | |
346 ... | tri≈ ¬a b ¬c = ⊥-elim (nat-≡< (sym bb27 ) (0<ly y ny) ) where | |
392 | 347 0<ly : (y : List In2) → ¬ y ≡ [] → 0 < length y |
387 | 348 0<ly [] ne = ⊥-elim ( ne refl ) |
349 0<ly (x ∷ y) ne = s≤s z≤n | |
350 bb27 : length y ≡ 0 | |
351 bb27 = begin | |
352 length y ≡⟨ sym (c0+1=n y) ⟩ | |
353 count0 y + count1 y ≡⟨ cong (λ k → k + count1 y ) eq ⟩ | |
354 count1 y + count1 y ≡⟨ cong₂ _+_ (sym b) (sym b) ⟩ | |
355 0 ∎ where open ≡-Reasoning | |
356 bb25 : (x y : List In2 ) → 0 < count1 x → 0 < count0 y → i1i0 (x ++ y) | |
357 bb25 (i0 ∷ x₁) y 0<x 0<y with bb25 x₁ y 0<x 0<y | |
358 ... | t = record { a = i0 ∷ i1i0.a t ; b = i1i0.b t ; i10 = cong (i0 ∷_) (i1i0.i10 t) } | |
359 bb25 (i1 ∷ []) y 0<x 0<y = bb27 y 0<y where | |
360 bb27 : (y : List In2 ) → 0 < count0 y → i1i0 (i1 ∷ y ) | |
392 | 361 bb27 (i0 ∷ y) 0<y = record { a = [] ; b = y ; i10 = refl } |
387 | 362 bb27 (i1 ∷ y) 0<y with bb27 y 0<y |
363 ... | t = record { a = i1 ∷ i1i0.a t ; b = i1i0.b t ; i10 = cong (i1 ∷_) (i1i0.i10 t) } | |
364 bb25 (i1 ∷ i0 ∷ x₁) y 0<x 0<y = record { a = [] ; b = x₁ ++ y ; i10 = refl } | |
365 bb25 (i1 ∷ i1 ∷ x₁) y (s≤s z≤n) 0<y with bb25 (i1 ∷ x₁) y (s≤s z≤n) 0<y | |
366 ... | t = record { a = i1 ∷ i1i0.a t ; b = i1i0.b t ; i10 = cong (i1 ∷_) (i1i0.i10 t) } | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
367 bb24 : x ++ y ++ y ++ z ≡ (x ++ i1i0.a (bb23 bb22)) ++ i1 ∷ i0 ∷ i1i0.b (bb23 bb22) ++ z |
385 | 368 bb24 = begin |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
369 x ++ y ++ y ++ z ≡⟨ solve (++-monoid In2) ⟩ |
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
370 x ++ (y ++ y) ++ z ≡⟨ cong (λ k → x ++ k ++ z) (i1i0.i10 (bb23 bb22)) ⟩ |
387 | 371 x ++ (i1i0.a (bb23 bb22) ++ i1 ∷ i0 ∷ i1i0.b (bb23 bb22)) ++ z ≡⟨ cong (λ k → x ++ k) -- solver does not work here |
372 (++-assoc (i1i0.a (bb23 bb22)) (i1 ∷ i0 ∷ i1i0.b (bb23 bb22)) z ) ⟩ | |
373 x ++ (i1i0.a (bb23 bb22) ++ (i1 ∷ i0 ∷ i1i0.b (bb23 bb22) ++ z)) ≡⟨ sym (++-assoc x _ _ ) ⟩ | |
386
6ef927ac832c
bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
385
diff
changeset
|
374 (x ++ i1i0.a (bb23 bb22)) ++ i1 ∷ i0 ∷ i1i0.b (bb23 bb22) ++ z ∎ where open ≡-Reasoning |
385 | 375 |
387 | 376 nn10 : (x y z : List In2 ) → ¬ y ≡ [] → inputnn1 (x ++ y ++ z) ≡ true → inputnn1 (x ++ y ++ y ++ z) ≡ false |
405 | 377 nn10 x y z my eq with inputnn1 (x ++ y ++ y ++ z) in eq1 |
378 ... | true = ⊥-elim ( nn11 x y z my eq eq1 ) | |
379 ... | false = refl | |
385 | 380 |
304 | 381 |
385 | 382 |
383 | |
384 | |
385 |