annotate automaton-in-agda/src/chap0.agda @ 392:23db567b4098

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 27 Jul 2023 09:03:13 +0900
parents 3fa72793620b
children af8f630b7e60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module chap0 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Data.List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Nat hiding (_⊔_)
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
5 -- open import Data.Integer hiding (_⊔_ ; _≟_ ; _+_ )
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Product
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 A : List ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 A = 1 ∷ 2 ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 data Literal : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 x : Literal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 y : Literal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 z : Literal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 B : List Literal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 B = x ∷ y ∷ z ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ListProduct : {A B : Set } → List A → List B → List ( A × B )
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
21 ListProduct = {!!}
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 ex05 : List ( ℕ × Literal )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 ex05 = ListProduct A B -- (1 , x) ∷ (1 , y) ∷ (1 , z) ∷ (2 , x) ∷ (2 , y) ∷ (2 , z) ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 ex06 : List ( ℕ × Literal × ℕ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 ex06 = ListProduct A (ListProduct B A)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 ex07 : Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 ex07 = ℕ × ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 data ex08-f : ℕ → ℕ → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 ex08f0 : ex08-f 0 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 ex08f1 : ex08-f 1 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ex08f2 : ex08-f 2 3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 ex08f3 : ex08-f 3 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 ex08f4 : ex08-f 4 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 data ex09-g : ℕ → ℕ → ℕ → ℕ → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 ex09g0 : ex09-g 0 1 2 3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 ex09g1 : ex09-g 1 2 3 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 ex09g2 : ex09-g 2 3 0 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 ex09g3 : ex09-g 3 0 1 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 open import Data.Nat.DivMod
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 open import Relation.Binary.PropositionalEquality
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
47 open import Relation.Binary.Core
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
48 open import Data.Nat.Properties
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
49
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
50 -- _%_ : ℕ → ℕ → ℕ
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
51 -- _%_ a b with <-cmp a b
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
52 -- _%_ a b | tri< a₁ ¬b ¬c = a
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
53 -- _%_ a b | tri≈ ¬a b₁ ¬c = 0
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
54 -- _%_ a b | tri> ¬a ¬b c = _%_ (a - b) b
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 _≡7_ : ℕ → ℕ → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 n ≡7 m = (n % 7) ≡ (m % 7 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 refl7 : { n : ℕ} → n ≡7 n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 refl7 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 sym7 : { n m : ℕ} → n ≡7 m → m ≡7 n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 sym7 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 trans7 : { n m o : ℕ} → n ≡7 m → m ≡7 o → n ≡7 o
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 trans7 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 open import Level renaming ( zero to Zero ; suc to Suc )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 record Graph { v v' : Level } : Set (Suc v ⊔ Suc v' ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 vertex : Set v
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 edge : vertex → vertex → Set v'
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
75 open Graph
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
76
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
77 -- open import Data.Fin hiding ( _≟_ )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
78 open import Data.Empty
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
79 open import Relation.Nullary
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
80 open import Data.Unit hiding ( _≟_ )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
81
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
82
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
83 -- data Dec (P : Set) : Set where
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
84 -- yes : P → Dec P
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
85 -- no : ¬ P → Dec P
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
86 --
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
87 -- _≟_ : (s t : ℕ ) → Dec ( s ≡ t )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
88
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
89 -- ¬ A = A → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
90
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
91 _n≟_ : (s t : ℕ ) → Dec ( s ≡ t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
92 zero n≟ zero = yes refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
93 zero n≟ suc t = no (λ ())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
94 suc s n≟ zero = no (λ ())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
95 suc s n≟ suc t with s n≟ t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
96 ... | yes refl = yes refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
97 ... | no n = no (λ k → n (tt1 k) ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
98 tt1 : suc s ≡ suc t → s ≡ t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
99 tt1 refl = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
100
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
101 open import Data.Bool hiding ( _≟_ )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
102
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
103 conn : List ( ℕ × ℕ ) → ℕ → ℕ → Bool
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
104 conn [] _ _ = false
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
105 conn ((n1 , m1 ) ∷ t ) n m with n ≟ n1 | m ≟ m1
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
106 conn ((n1 , m1) ∷ t) n m | yes refl | yes refl = true
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
107 conn ((n1 , m1) ∷ t) n m | _ | _ = conn t n m
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
108
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
109 list012a : List ( ℕ × ℕ )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
110 list012a = (1 , 2) ∷ (2 , 3) ∷ (3 , 4) ∷ (4 , 5) ∷ (5 , 1) ∷ []
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
112 graph012a : Graph {Zero} {Zero}
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
113 graph012a = record { vertex = ℕ ; edge = λ s t → (conn list012a s t) ≡ true }
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 data edge012b : ℕ → ℕ → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 e012b-1 : edge012b 1 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 e012b-2 : edge012b 1 3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 e012b-3 : edge012b 1 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 e012b-4 : edge012b 2 3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 e012b-5 : edge012b 2 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 e012b-6 : edge012b 3 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
123 edge? : (E : ℕ → ℕ → Set) → ( a b : ℕ ) → Set
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
124 edge? E a b = Dec ( E a b )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
125
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
126 lemma3 : ( a b : ℕ ) → edge? edge012b a b
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
127 lemma3 1 2 = yes e012b-1
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
128 lemma3 1 3 = yes e012b-2
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
129 lemma3 1 4 = yes e012b-3
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
130 lemma3 2 3 = yes e012b-4
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
131 lemma3 2 4 = yes e012b-5
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
132 lemma3 3 4 = yes e012b-6
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
133 lemma3 1 1 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
134 lemma3 2 1 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
135 lemma3 2 2 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
136 lemma3 3 1 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
137 lemma3 3 2 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
138 lemma3 3 3 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
139 lemma3 0 _ = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
140 lemma3 _ 0 = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
141 lemma3 _ (suc (suc (suc (suc (suc _))))) = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
142 lemma3 (suc (suc (suc (suc _)))) _ = no ( λ () )
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
143
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 graph012b : Graph {Zero} {Zero}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 graph012b = record { vertex = ℕ ; edge = edge012b }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 data connected { V : Set } ( E : V -> V -> Set ) ( x y : V ) : Set where
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
148 direct : E x y → connected E x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
149 indirect : ( z : V ) -> E x z → connected {V} E z y → connected E x y
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
150
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
151 lemma1 : connected ( edge graph012a ) 1 2
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
152 lemma1 = direct refl where
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
154 lemma1-2 : connected ( edge graph012a ) 1 3
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
155 lemma1-2 = indirect 2 refl (direct refl )
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
157 lemma2 : connected ( edge graph012b ) 1 2
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
158 lemma2 = direct e012b-1
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 reachable : { V : Set } ( E : V -> V -> Set ) ( x y : V ) -> Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 reachable {V} E X Y = Dec ( connected {V} E X Y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 dag : { V : Set } ( E : V -> V -> Set ) -> Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 dag {V} E = ∀ (n : V) → ¬ ( connected E n n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
166 open import Function
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
167
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
168 lemma4 : ¬ ( dag ( edge graph012a) )
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
169 lemma4 neg = neg 1 $ indirect 2 refl $ indirect 3 refl $ indirect 4 refl $ indirect 5 refl $ direct refl
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
170
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
171 dgree : List ( ℕ × ℕ ) → ℕ → ℕ
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
172 dgree [] _ = 0
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
173 dgree ((e , e1) ∷ t) e0 with e0 ≟ e | e0 ≟ e1
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
174 dgree ((e , e1) ∷ t) e0 | yes _ | _ = 1 + (dgree t e0)
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
175 dgree ((e , e1) ∷ t) e0 | _ | yes p = 1 + (dgree t e0)
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
176 dgree ((e , e1) ∷ t) e0 | no _ | no _ = dgree t e0
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
178 dgree-c : {t : Set} → List ( ℕ × ℕ ) → ℕ → (ℕ → t) → t
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
179 dgree-c {t} [] e0 next = next 0
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
180 dgree-c {t} ((e , e1) ∷ tail ) e0 next with e0 ≟ e | e0 ≟ e1
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
181 ... | yes _ | _ = dgree-c tail e0 ( λ n → next (n + 1 ))
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
182 ... | _ | yes _ = dgree-c tail e0 ( λ n → next (n + 1 ))
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
183 ... | no _ | no _ = dgree-c tail e0 next
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
184
55
ba5ee7eb2866 fix graph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
185 lemma6 = dgree list012a 2
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
186 lemma7 = dgree-c list012a 2 ( λ n → n )
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
187
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
188 even2 : (n : ℕ ) → n % 2 ≡ 0 → (n + 2) % 2 ≡ 0
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
189 even2 0 refl = refl
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
190 even2 1 ()
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
191 even2 (suc (suc n)) eq = trans ([a+n]%n≡a%n n _) eq -- [a+n]%n≡a%n : ∀ a n → (a + suc n) % suc n ≡ a % suc n
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
192
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
193 sum-of-dgree : ( g : List ( ℕ × ℕ )) → ℕ
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
194 sum-of-dgree [] = 0
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
195 sum-of-dgree ((e , e1) ∷ t) = 2 + sum-of-dgree t
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
196
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
197 dgree-even : ( g : List ( ℕ × ℕ )) → sum-of-dgree g % 2 ≡ 0
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
198 dgree-even [] = refl
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
199 dgree-even ((e , e1) ∷ t) = begin
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
200 sum-of-dgree ((e , e1) ∷ t) % 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
201 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
202 (2 + sum-of-dgree t ) % 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
203 ≡⟨ cong ( λ k → k % 2 ) ( +-comm 2 (sum-of-dgree t) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
204 (sum-of-dgree t + 2) % 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
205 ≡⟨ [a+n]%n≡a%n (sum-of-dgree t) _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
206 sum-of-dgree t % 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
207 ≡⟨ dgree-even t ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
208 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
209 ∎ where open ≡-Reasoning
56
fe5304e06228 even dgree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
210