annotate automaton-in-agda/src/non-regular.agda @ 388:227f1f8f9c93

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