annotate automaton-in-agda/src/non-regular.agda @ 395:cd81e0869fac

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 03 Aug 2023 14:55:14 +0900
parents d860e357fe5f
children f26444eb0275
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
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
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
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
28 list-eq (i1 ∷ s) (i1 ∷ s1) = list-eq s s1
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
29
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
30 input-addi0 : ( n : ℕ ) → List In2 → List In2
385
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
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
34 input-addi1 : ( n : ℕ ) → List In2
385
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
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
38 inputnn0 : ( n : ℕ ) → List In2
385
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) ⟫
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
52 inputnn1-i0 i (i0 ∷ x) = inputnn1-i0 (suc i) x
385
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 _
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
100 nn07 (suc j) x eq = trans (nn07 j (suc x) (trans (cong (λ k → k + j) (+-comm 1 _ )) (trans (+-assoc x _ _) eq)) )
385
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
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
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
393
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
115 half : (x : List In2) → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
116 half [] = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
117 half (x ∷ []) = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
118 half (x ∷ x₁ ∷ x₂) = suc (half x₂)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
119
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
120 top-is-i0 : (x : List In2) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
121 top-is-i0 [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
122 top-is-i0 (i0 ∷ _) = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
123 top-is-i0 (i1 ∷ _) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
124
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
125 nn02 : (x : List In2) → inputnn1 x ≡ true → x ≡ inputnn0 (half x)
395
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
126 nn02 x eq = nn08 x eq where
394
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
127 nn07 : (i : ℕ) → (x : List In2) → inputnn1-i1 i x ≡ true → x ≡ input-addi1 i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
128 nn07 zero [] eq = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
129 nn07 zero (i0 ∷ x₁) ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
130 nn07 zero (i1 ∷ x₁) ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
131 nn07 (suc i) (i1 ∷ x₁) eq = cong (λ k → i1 ∷ k) (nn07 i x₁ eq)
395
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
132 nn08 : (x : List In2 ) → inputnn1-i1 (proj1 (inputnn1-i0 0 x)) (proj2 (inputnn1-i0 0 x)) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
133 → x ≡ input-addi0 (half x) (input-addi1 (half x))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
134 nn08 [] eq = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
135 nn08 (i1 ∷ t) eq = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
136 nn08 (i0 ∷ []) eq = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
137 nn08 (i0 ∷ i1 ∷ t) eq = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
138 nn08 (i0 ∷ t @ (i0 ∷ _)) eq = ? where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
139 nn20 : top-is-i0 t ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
140 nn20 = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
141 y : List In2 → List In2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
142 y [] = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
143 y (x ∷ []) = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
144 y (x ∷ t ∷ z ) = x ∷ y (t ∷ z)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
145 nn15 : ( x y : List In2) → length x ≡ suc (suc (length y)) → half x ≡ suc (half y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
146 nn15 (x ∷ x₁ ∷ []) [] eq = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
147 nn15 (x ∷ x₁ ∷ x₃ ∷ []) (x₂ ∷ []) eq = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
148 nn15 (x ∷ x₁ ∷ x₃ ∷ x₅ ∷ []) (x₂ ∷ x₄ ∷ []) eq = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
149 nn15 (x ∷ x₁ ∷ x₃ ∷ x₅) (x₂ ∷ x₄ ∷ x₆ ∷ y₁) eq = cong suc (nn15 (x₃ ∷ x₅) (x₆ ∷ y₁) (cong pred (cong pred eq)) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
150 nn13 : (z : List In2) → half (i0 ∷ i0 ∷ z) ≡ suc (half (y (i0 ∷ z)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
151 nn13 z = nn15 (i0 ∷ i0 ∷ z) (y (i0 ∷ z)) ? where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
152 nn17 : {x : In2} (z : List In2) → length (y (i0 ∷ z)) ≡ length (y (x ∷ z))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
153 nn17 [] = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
154 nn17 (x ∷ []) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
155 nn17 (x ∷ x₁ ∷ z) = cong suc ( nn17 {x} (x₁ ∷ z))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
156 nn16 : (z : List In2 ) → length (i0 ∷ i0 ∷ z) ≡ suc (suc (length (y (i0 ∷ z))))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
157 nn16 [] = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
158 nn16 (x ∷ z) = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
159 length (i0 ∷ i0 ∷ x ∷ z) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
160 suc (length (i0 ∷ i0 ∷ z)) ≡⟨ cong suc (nn16 z) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
161 suc (suc (suc (length (y (i0 ∷ z))))) ≡⟨ cong suc (cong suc ( cong suc (nn17 z))) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
162 suc (suc (suc (length (y (x ∷ z))))) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
163 suc (suc (length (i0 ∷ y (x ∷ z)))) ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
164 nn11 : (t : List In2) → inputnn1-i1 (proj1 (inputnn1-i0 1 t)) (proj2 (inputnn1-i0 1 t)) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
165 → t ++ (i1 ∷ []) ≡ y t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
166 nn11 t eq = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
167 nn10 : (y : List In2 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
168 → inputnn1-i1 (proj1 (inputnn1-i0 0 y)) (proj2 (inputnn1-i0 0 y)) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
169 → y ≡ input-addi0 (half y) (input-addi1 (half y))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
170 nn10 y eq = nn08 y eq
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
171 nn14 : inputnn1-i1 (proj1 (inputnn1-i0 0 (y t))) (proj2 (inputnn1-i0 0 (y t))) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
172 nn14 = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
173 nn12 : i0 ∷ t ≡ input-addi0 (half (i0 ∷ t)) (input-addi1 (half (i0 ∷ t)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
174 nn12 = ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
175
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
176
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
177 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
178 -- 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
179 -- The function is determinted by inputs,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
180 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
181
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
182 open RegularLanguage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
183 open Automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
184
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
185 open _∧_
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
187
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
188 open RegularLanguage
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
189 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
190 open import Data.List.Properties
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
191 open import nat
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
192
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
193 lemmaNN : (r : RegularLanguage In2 ) → ¬ ( (s : List In2) → isRegular inputnn1 s r )
332
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 320
diff changeset
194 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
195 (tr-accept→ (automaton r) _ (astart r) (TA.trace-xyyz TAnn) ) where
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
196 n : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
197 n = suc (finite (afin r))
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
198 nn = inputnn0 n
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
199 nn03 : accept (automaton r) (astart r) nn ≡ true
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
200 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n)
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
201 nn09 : (n m : ℕ) → n ≤ n + m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
202 nn09 zero m = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
203 nn09 (suc n) m = s≤s (nn09 n m)
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
204 nn04 : Trace (automaton r) nn (astart r)
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
205 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
206 nntrace = tr→qs (automaton r) nn (astart r) nn04
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
207 nn07 : (n : ℕ) → length (inputnn0 n ) ≡ n + n
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
208 nn07 i = nn19 i where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
209 nn17 : (i : ℕ) → length (input-addi1 i) ≡ i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
210 nn17 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
211 nn17 (suc i)= cong suc (nn17 i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
212 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
213 nn18 i zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
214 nn18 i (suc j)= cong suc (nn18 i j)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
215 nn19 : (i : ℕ) → length (input-addi0 i ( input-addi1 i )) ≡ i + i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
216 nn19 i = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
217 length (input-addi0 i ( input-addi1 i )) ≡⟨ nn18 i i ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
218 i + length (input-addi1 i) ≡⟨ cong (λ k → i + k) ( nn17 i) ⟩
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
219 i + i ∎ where open ≡-Reasoning
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
220 nn05 : length nntrace > finite (afin r)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
221 nn05 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
222 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
223 n + n ≡⟨ sym (nn07 n) ⟩
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
224 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
225 length nntrace ∎ where open ≤-Reasoning
315
25ae77240238 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
226 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
227 nn06 = dup-in-list>n (afin r) nntrace nn05
332
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 320
diff changeset
228
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
229 TAnn : TA (automaton r) (astart r) nn
317
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
230 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
231
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
232 open import Tactic.MonoidSolver using (solve; solve-macro)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
233
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
234 -- there is a counter example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
235 --
317
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
236 tann : {x y z : List In2} → ¬ y ≡ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
237 → x ++ y ++ z ≡ nn
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
238 → 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
239 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
240 count0 : (x : List In2) → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
241 count0 [] = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
242 count0 (i0 ∷ x) = suc (count0 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
243 count0 (i1 ∷ x) = count0 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
244 count1 : (x : List In2) → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
245 count1 [] = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
246 count1 (i1 ∷ x) = suc (count1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
247 count1 (i0 ∷ x) = count1 x
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
248 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
249 -- prove some obvious fact
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
250 --
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
251 c0+1=n : (x : List In2 ) → count0 x + count1 x ≡ length x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
252 c0+1=n [] = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
253 c0+1=n (i0 ∷ t) = cong suc ( c0+1=n t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
254 c0+1=n (i1 ∷ t) = begin
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
255 count0 t + suc (count1 t) ≡⟨ sym (+-assoc (count0 t) _ _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
256 (count0 t + 1 ) + count1 t ≡⟨ cong (λ k → k + count1 t) (+-comm _ 1 ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
257 suc (count0 t + count1 t) ≡⟨ cong suc ( c0+1=n t ) ⟩
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
258 suc (length t) ∎ where open ≡-Reasoning
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
259 --
386
6ef927ac832c bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 385
diff changeset
260 nn15 : (x : List In2 ) → inputnn1 x ≡ true → count0 x ≡ count1 x
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
261 nn15 x eq = nn18 where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
262 nn17 : (x : List In2 ) → (count0 x ≡ proj1 (inputnn1-i0 0 x) + count0 (proj2 (inputnn1-i0 0 x)))
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
263 ∧ (count1 x ≡ 0 + count1 (proj2 (inputnn1-i0 0 x)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
264 nn17 [] = ⟪ refl , refl ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
265 nn17 (i0 ∷ t ) with nn17 t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
266 ... | ⟪ eq1 , eq2 ⟫ = ⟪ begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
267 suc (count0 t ) ≡⟨ cong suc eq1 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
268 suc (proj1 (inputnn1-i0 0 t) + count0 (proj2 (inputnn1-i0 0 t))) ≡⟨ cong₂ _+_ (sym (nn31 t 0)) (cong count0 (sym (nn30 t 0))) ⟩
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
269 proj1 (inputnn1-i0 1 t) + count0 (proj2 (inputnn1-i0 1 t)) ∎
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
270 , trans eq2 (cong count1 (sym (nn30 t 0))) ⟫ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
271 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
272 nn20 : proj2 (inputnn1-i0 1 t) ≡ proj2 (inputnn1-i0 0 t)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
273 nn20 = nn30 t 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
274 nn17 (i1 ∷ x₁) = ⟪ refl , refl ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
275 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
276 nn19 zero [] eq = ⟪ refl , refl ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
277 nn19 zero (i0 ∷ y) ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
278 nn19 zero (i1 ∷ y) ()
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
279 nn19 (suc i) (i1 ∷ y) eq with nn19 i y eq
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
280 ... | t = ⟪ proj1 t , cong suc (proj2 t ) ⟫
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
281 nn18 : count0 x ≡ count1 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
282 nn18 = begin
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
283 count0 x ≡⟨ proj1 (nn17 x) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
284 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: 391
diff changeset
285 (proj1 (nn19 (proj1 (inputnn1-i0 0 x)) (proj2 (inputnn1-i0 0 x)) eq)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
286 proj1 (inputnn1-i0 0 x) + 0 ≡⟨ +-comm _ 0 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
287 0 + proj1 (inputnn1-i0 0 x) ≡⟨ cong (λ k → 0 + k) (sym (proj2 (nn19 _ _ eq))) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
288 0 + count1 (proj2 (inputnn1-i0 0 x)) ≡⟨ sym (proj2 (nn17 x)) ⟩
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
289 count1 x ∎ where open ≡-Reasoning
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
290 distr0 : (x y : List In2 ) → count0 (x ++ y ) ≡ count0 x + count0 y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
291 distr0 [] y = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
292 distr0 (i0 ∷ x) y = cong suc (distr0 x y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
293 distr0 (i1 ∷ x) y = distr0 x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
294 distr1 : (x y : List In2 ) → count1 (x ++ y ) ≡ count1 x + count1 y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
295 distr1 [] y = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
296 distr1 (i1 ∷ x) y = cong suc (distr1 x y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
297 distr1 (i0 ∷ x) y = distr1 x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
298 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
299 -- i0 .. i0 ∷ i1 .. i1 sequece does not contains i1 → i0 transition
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
300 --
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
301 record i1i0 (z : List In2) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
302 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
303 a b : List In2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
304 i10 : z ≡ a ++ (i1 ∷ i0 ∷ b )
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
305 nn12 : (x : List In2 ) → inputnn1 x ≡ true → ¬ i1i0 x
391
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
306 nn12 x eq = nn17 x 0 eq where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
307 nn17 : (x : List In2 ) → (i : ℕ)
391
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
308 → inputnn1-i1 (proj1 (inputnn1-i0 i x)) (proj2 (inputnn1-i0 i x)) ≡ true → ¬ i1i0 x
390
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 389
diff changeset
309 nn17 [] i eq li with i1i0.a li | i1i0.i10 li
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
310 ... | [] | ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
311 ... | x ∷ s | ()
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
312 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
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
313 ; i10 = nn19 (i1i0.a li) (i1i0.i10 li) } where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
314 -- first half
391
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
315 nn18 : (a : List In2 ) → i0 ∷ x₁ ≡ a ++ ( i1 ∷ i0 ∷ i1i0.b li) → List In2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
316 nn18 (i0 ∷ t) eq = t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
317 nn19 : (a : List In2 ) → (eq : i0 ∷ x₁ ≡ a ++ ( i1 ∷ i0 ∷ i1i0.b li) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
318 → x₁ ≡ nn18 a eq ++ i1 ∷ i0 ∷ i1i0.b li
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
319 nn19 (i0 ∷ a) eq = cons-inject eq
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
320 nn17 (i1 ∷ x₁) i eq li = nn20 (i1 ∷ x₁) i eq li where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
321 -- second half
391
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 390
diff changeset
322 nn20 : (x : List In2) → (i : ℕ) → inputnn1-i1 i x ≡ true → i1i0 x → ⊥
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
323 nn20 x i eq li = nn21 (i1i0.a li) x i eq (i1i0.i10 li) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
324 nn21 : (a x : List In2) → (i : ℕ) → inputnn1-i1 i x ≡ true → x ≡ a ++ i1 ∷ i0 ∷ i1i0.b li → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
325 nn21 [] [] zero eq1 ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
326 nn21 (i0 ∷ a) [] zero eq1 ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
327 nn21 (i1 ∷ a) [] zero eq1 ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
328 nn21 a (i0 ∷ x₁) zero () eq0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
329 nn21 [] (i0 ∷ x₁) (suc i) () eq0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
330 nn21 (x ∷ a) (i0 ∷ x₁) (suc i) () eq0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
331 nn21 [] (i1 ∷ i0 ∷ x₁) (suc zero) () eq0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
332 nn21 [] (i1 ∷ i0 ∷ x₁) (suc (suc i)) () eq0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
333 nn21 (i1 ∷ a) (i1 ∷ x₁) (suc i) eq1 eq0 = nn21 a x₁ i eq1 (cons-inject eq0)
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
334 nn11 : (x y z : List In2 ) → ¬ y ≡ [] → inputnn1 (x ++ y ++ z) ≡ true → ¬ ( inputnn1 (x ++ y ++ y ++ z) ≡ true )
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
335 nn11 x y z ny xyz xyyz = ⊥-elim ( nn12 (x ++ y ++ y ++ z ) xyyz record { a = x ++ i1i0.a (bb23 bb22 )
388
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 387
diff changeset
336 ; b = i1i0.b (bb23 bb22) ++ z ; i10 = bb24 } ) where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
337 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
338 -- we need simple calcuraion to obtain count0 y ≡ count1 y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
339 --
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
340 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
341 nn21 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
342 (count0 x + count0 y + count0 y) + count0 z ≡⟨ solve +-0-monoid ⟩
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
343 count0 x + (count0 y + (count0 y + count0 z)) ≡⟨ sym (cong (λ k → count0 x + (count0 y + k)) (distr0 y _ )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
344 count0 x + (count0 y + count0 (y ++ z)) ≡⟨ sym (cong (λ k → count0 x + k) (distr0 y _ )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
345 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
346 count0 (x ++ y ++ y ++ z) ≡⟨ nn15 (x ++ y ++ y ++ z) xyyz ⟩
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
347 count1 (x ++ y ++ y ++ z) ≡⟨ distr1 x _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
348 count1 x + (count1 (y ++ y ++ z)) ≡⟨ cong (λ k → count1 x + k) (distr1 y _ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
349 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
350 count1 x + (count1 y + (count1 y + count1 z)) ≡⟨ solve +-0-monoid ⟩
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
351 count1 x + count1 y + count1 y + count1 z ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
352 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
353 nn20 = begin
6ef927ac832c bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 385
diff changeset
354 count0 x + count0 y + count0 z ≡⟨ solve +-0-monoid ⟩
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
355 count0 x + (count0 y + count0 z) ≡⟨ cong (λ k → count0 x + k) (sym (distr0 y z)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
356 count0 x + (count0 (y ++ z)) ≡⟨ sym (distr0 x _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
357 count0 (x ++ (y ++ z)) ≡⟨ nn15 (x ++ y ++ z) xyz ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
358 count1 (x ++ (y ++ z)) ≡⟨ distr1 x _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
359 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
360 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
361 count1 x + count1 y + count1 z ∎ where open ≡-Reasoning
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
362 -- this takes very long time to check and needs 10GB
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
363 bb22 : count0 y ≡ count1 y
393
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 392
diff changeset
364 bb22 = ?
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
365 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
366 -- y contains i0 and i1 , so we have i1 → i0 transition in y ++ y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
367 --
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
368 bb23 : count0 y ≡ count1 y → i1i0 (y ++ y)
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
369 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
370 bb26 : 0 < count1 y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
371 bb26 with <-cmp 0 (count1 y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
372 ... | tri< a ¬b ¬c = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
373 ... | tri≈ ¬a b ¬c = ⊥-elim (nat-≡< (sym bb27 ) (0<ly y ny) ) where
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
374 0<ly : (y : List In2) → ¬ y ≡ [] → 0 < length y
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
375 0<ly [] ne = ⊥-elim ( ne refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
376 0<ly (x ∷ y) ne = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
377 bb27 : length y ≡ 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
378 bb27 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
379 length y ≡⟨ sym (c0+1=n y) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
380 count0 y + count1 y ≡⟨ cong (λ k → k + count1 y ) eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
381 count1 y + count1 y ≡⟨ cong₂ _+_ (sym b) (sym b) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
382 0 ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
383 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
384 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
385 ... | 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
386 bb25 (i1 ∷ []) y 0<x 0<y = bb27 y 0<y where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
387 bb27 : (y : List In2 ) → 0 < count0 y → i1i0 (i1 ∷ y )
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
388 bb27 (i0 ∷ y) 0<y = record { a = [] ; b = y ; i10 = refl }
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
389 bb27 (i1 ∷ y) 0<y with bb27 y 0<y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
390 ... | 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
391 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
392 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
393 ... | 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
394 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
395 bb24 = begin
386
6ef927ac832c bb22 takes 10GB and 5 min
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 385
diff changeset
396 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
397 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
398 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
399 (++-assoc (i1i0.a (bb23 bb22)) (i1 ∷ i0 ∷ i1i0.b (bb23 bb22)) z ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
400 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
401 (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
402
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
403 nn10 : (x y z : List In2 ) → ¬ y ≡ [] → inputnn1 (x ++ y ++ z) ≡ true → inputnn1 (x ++ y ++ y ++ z) ≡ false
392
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 391
diff changeset
404 nn10 x y z my eq with inputnn1 (x ++ y ++ y ++ z) | inspect inputnn1 (x ++ y ++ y ++ z)
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 386
diff changeset
405 ... | 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
406 ... | false | _ = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
407
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
408
385
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
409
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
410
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
411
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
412