17
|
1 module list-nat where
|
|
2
|
|
3 open import Level
|
15
|
4
|
|
5
|
130
|
6 postulate A : Set
|
15
|
7
|
130
|
8 postulate a : A
|
|
9 postulate b : A
|
|
10 postulate c : A
|
153
|
11
|
15
|
12
|
|
13 infixr 40 _::_
|
130
|
14 data List (A : Set ) : Set where
|
15
|
15 [] : List A
|
300
|
16 _::_ : A → List A → List A
|
15
|
17
|
|
18
|
|
19 infixl 30 _++_
|
300
|
20 _++_ : {A : Set } → List A → List A → List A
|
15
|
21 [] ++ ys = ys
|
|
22 (x :: xs) ++ ys = x :: (xs ++ ys)
|
|
23
|
|
24 l1 = a :: []
|
|
25 l2 = a :: b :: a :: c :: []
|
|
26
|
|
27 l3 = l1 ++ l2
|
|
28
|
130
|
29 data Node ( A : Set ) : Set where
|
300
|
30 leaf : A → Node A
|
|
31 node : Node A → Node A → Node A
|
30
|
32
|
300
|
33 flatten : { A : Set } → Node A → List A
|
30
|
34 flatten ( leaf a ) = a :: []
|
|
35 flatten ( node a b ) = flatten a ++ flatten b
|
|
36
|
|
37 n1 = node ( leaf a ) ( node ( leaf b ) ( leaf c ))
|
|
38
|
18
|
39 open import Relation.Binary.PropositionalEquality
|
|
40
|
15
|
41 infixr 20 _==_
|
|
42
|
300
|
43 data _==_ {A : Set } : List A → List A → Set where
|
|
44 reflection : {x : List A} → x == x
|
19
|
45
|
300
|
46 cong1 : {A : Set } { B : Set } →
|
|
47 ( f : List A → List B ) → {x : List A } → {y : List A} → x == y → f x == f y
|
19
|
48 cong1 f reflection = reflection
|
|
49
|
300
|
50 eq-cons : {A : Set } {x y : List A} ( a : A ) → x == y → ( a :: x ) == ( a :: y )
|
|
51 eq-cons a z = cong1 ( λ x → ( a :: x) ) z
|
19
|
52
|
300
|
53 trans-list : {A : Set } {x y z : List A} → x == y → y == z → x == z
|
19
|
54 trans-list reflection reflection = reflection
|
18
|
55
|
|
56
|
300
|
57 ==-to-≡ : {A : Set } {x y : List A} → x == y → x ≡ y
|
19
|
58 ==-to-≡ reflection = refl
|
15
|
59
|
300
|
60 list-id-l : { A : Set } → { x : List A} → [] ++ x == x
|
15
|
61 list-id-l = reflection
|
|
62
|
300
|
63 list-id-r : { A : Set } → ( x : List A ) → x ++ [] == x
|
15
|
64 list-id-r [] = reflection
|
19
|
65 list-id-r (x :: xs) = eq-cons x ( list-id-r xs )
|
15
|
66
|
300
|
67 list-assoc : {A : Set } → ( xs ys zs : List A ) →
|
15
|
68 ( ( xs ++ ys ) ++ zs ) == ( xs ++ ( ys ++ zs ) )
|
|
69 list-assoc [] ys zs = reflection
|
19
|
70 list-assoc (x :: xs) ys zs = eq-cons x ( list-assoc xs ys zs )
|
15
|
71
|
18
|
72
|
130
|
73 module ==-Reasoning (A : Set ) where
|
17
|
74
|
606
|
75 infix 3 _∎
|
30
|
76 infixr 2 _==⟨_⟩_ _==⟨⟩_
|
17
|
77 infix 1 begin_
|
15
|
78
|
|
79
|
19
|
80 data _IsRelatedTo_ (x y : List A) :
|
130
|
81 Set where
|
18
|
82 relTo : (x≈y : x == y ) → x IsRelatedTo y
|
17
|
83
|
19
|
84 begin_ : {x : List A } {y : List A} →
|
18
|
85 x IsRelatedTo y → x == y
|
17
|
86 begin relTo x≈y = x≈y
|
|
87
|
19
|
88 _==⟨_⟩_ : (x : List A ) {y z : List A} →
|
17
|
89 x == y → y IsRelatedTo z → x IsRelatedTo z
|
19
|
90 _ ==⟨ x≈y ⟩ relTo y≈z = relTo (trans-list x≈y y≈z)
|
18
|
91
|
30
|
92 _==⟨⟩_ : (x : List A ) {y : List A}
|
|
93 → x IsRelatedTo y → x IsRelatedTo y
|
|
94 _ ==⟨⟩ x≈y = x≈y
|
|
95
|
20
|
96 _∎ : (x : List A ) → x IsRelatedTo x
|
18
|
97 _∎ _ = relTo reflection
|
17
|
98
|
300
|
99 lemma11 : (A : Set ) ( x : List A ) → x == x
|
19
|
100 lemma11 A x = let open ==-Reasoning A in
|
18
|
101 begin x ∎
|
|
102
|
606
|
103
|
300
|
104 ++-assoc : (L : Set ) ( xs ys zs : List L ) → (xs ++ ys) ++ zs == xs ++ (ys ++ zs)
|
19
|
105 ++-assoc A [] ys zs = let open ==-Reasoning A in
|
17
|
106 begin -- to prove ([] ++ ys) ++ zs == [] ++ (ys ++ zs)
|
15
|
107 ( [] ++ ys ) ++ zs
|
17
|
108 ==⟨ reflection ⟩
|
15
|
109 ys ++ zs
|
17
|
110 ==⟨ reflection ⟩
|
15
|
111 [] ++ ( ys ++ zs )
|
|
112 ∎
|
17
|
113
|
19
|
114 ++-assoc A (x :: xs) ys zs = let open ==-Reasoning A in
|
17
|
115 begin -- to prove ((x :: xs) ++ ys) ++ zs == (x :: xs) ++ (ys ++ zs)
|
15
|
116 ((x :: xs) ++ ys) ++ zs
|
17
|
117 ==⟨ reflection ⟩
|
15
|
118 (x :: (xs ++ ys)) ++ zs
|
17
|
119 ==⟨ reflection ⟩
|
15
|
120 x :: ((xs ++ ys) ++ zs)
|
19
|
121 ==⟨ cong1 (_::_ x) (++-assoc A xs ys zs) ⟩
|
15
|
122 x :: (xs ++ (ys ++ zs))
|
17
|
123 ==⟨ reflection ⟩
|
15
|
124 (x :: xs) ++ (ys ++ zs)
|
|
125 ∎
|
|
126
|
|
127
|
153
|
128
|
|
129 --data Bool : Set where
|
|
130 -- true : Bool
|
|
131 -- false : Bool
|
|
132
|
|
133
|
|
134 --postulate Obj : Set
|
|
135
|
300
|
136 --postulate Hom : Obj → Obj → Set
|
153
|
137
|
|
138
|
300
|
139 --postulate id : { a : Obj } → Hom a a
|
153
|
140
|
|
141
|
|
142 --infixr 80 _○_
|
300
|
143 --postulate _○_ : { a b c : Obj } → Hom b c → Hom a b → Hom a c
|
153
|
144
|
300
|
145 -- postulate axId1 : {a b : Obj} → ( f : Hom a b ) → f == id ○ f
|
|
146 -- postulate axId2 : {a b : Obj} → ( f : Hom a b ) → f == f ○ id
|
153
|
147
|
300
|
148 --assoc : { a b c d : Obj } →
|
|
149 -- (f : Hom c d ) → (g : Hom b c) → (h : Hom a b) →
|
153
|
150 -- (f ○ g) ○ h == f ○ ( g ○ h)
|
|
151
|
|
152
|
|
153 --a = Set
|
|
154
|
300
|
155 -- ListObj : {A : Set} → List A
|
153
|
156 -- ListObj = List Set
|
|
157
|
300
|
158 -- ListHom : ListObj → ListObj → Set
|
153
|
159
|