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
|
|
16 _::_ : A -> List A -> List A
|
|
17
|
|
18
|
|
19 infixl 30 _++_
|
130
|
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
|
30
|
30 leaf : A -> Node A
|
|
31 node : Node A -> Node A -> Node A
|
|
32
|
130
|
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
|
130
|
43 data _==_ {A : Set } : List A -> List A -> Set where
|
15
|
44 reflection : {x : List A} -> x == x
|
19
|
45
|
130
|
46 cong1 : {A : Set } { B : Set } ->
|
19
|
47 ( f : List A -> List B ) -> {x : List A } -> {y : List A} -> x == y -> f x == f y
|
|
48 cong1 f reflection = reflection
|
|
49
|
130
|
50 eq-cons : {A : Set } {x y : List A} ( a : A ) -> x == y -> ( a :: x ) == ( a :: y )
|
19
|
51 eq-cons a z = cong1 ( \x -> ( a :: x) ) z
|
|
52
|
130
|
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
|
130
|
57 ==-to-≡ : {A : Set } {x y : List A} -> x == y -> x ≡ y
|
19
|
58 ==-to-≡ reflection = refl
|
15
|
59
|
|
60 list-id-l : { A : Set } -> { x : List A} -> [] ++ x == x
|
|
61 list-id-l = reflection
|
|
62
|
|
63 list-id-r : { A : Set } -> ( x : List A ) -> x ++ [] == x
|
|
64 list-id-r [] = reflection
|
19
|
65 list-id-r (x :: xs) = eq-cons x ( list-id-r xs )
|
15
|
66
|
|
67 list-assoc : {A : Set } -> ( xs ys zs : List A ) ->
|
|
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
|
|
75 infixr 2 _∎
|
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
|
130
|
99 lemma11 : (A : Set ) ( x : List A ) -> x == x
|
19
|
100 lemma11 A x = let open ==-Reasoning A in
|
18
|
101 begin x ∎
|
|
102
|
130
|
103 ++-assoc : (L : Set ) ( xs ys zs : List L ) -> (xs ++ ys) ++ zs == xs ++ (ys ++ zs)
|
19
|
104 ++-assoc A [] ys zs = let open ==-Reasoning A in
|
17
|
105 begin -- to prove ([] ++ ys) ++ zs == [] ++ (ys ++ zs)
|
15
|
106 ( [] ++ ys ) ++ zs
|
17
|
107 ==⟨ reflection ⟩
|
15
|
108 ys ++ zs
|
17
|
109 ==⟨ reflection ⟩
|
15
|
110 [] ++ ( ys ++ zs )
|
|
111 ∎
|
17
|
112
|
19
|
113 ++-assoc A (x :: xs) ys zs = let open ==-Reasoning A in
|
17
|
114 begin -- to prove ((x :: xs) ++ ys) ++ zs == (x :: xs) ++ (ys ++ zs)
|
15
|
115 ((x :: xs) ++ ys) ++ zs
|
17
|
116 ==⟨ reflection ⟩
|
15
|
117 (x :: (xs ++ ys)) ++ zs
|
17
|
118 ==⟨ reflection ⟩
|
15
|
119 x :: ((xs ++ ys) ++ zs)
|
19
|
120 ==⟨ cong1 (_::_ x) (++-assoc A xs ys zs) ⟩
|
15
|
121 x :: (xs ++ (ys ++ zs))
|
17
|
122 ==⟨ reflection ⟩
|
15
|
123 (x :: xs) ++ (ys ++ zs)
|
|
124 ∎
|
|
125
|
|
126
|
153
|
127
|
|
128 --data Bool : Set where
|
|
129 -- true : Bool
|
|
130 -- false : Bool
|
|
131
|
|
132
|
|
133 --postulate Obj : Set
|
|
134
|
|
135 --postulate Hom : Obj -> Obj -> Set
|
|
136
|
|
137
|
|
138 --postulate id : { a : Obj } -> Hom a a
|
|
139
|
|
140
|
|
141 --infixr 80 _○_
|
|
142 --postulate _○_ : { a b c : Obj } -> Hom b c -> Hom a b -> Hom a c
|
|
143
|
|
144 -- postulate axId1 : {a b : Obj} -> ( f : Hom a b ) -> f == id ○ f
|
|
145 -- postulate axId2 : {a b : Obj} -> ( f : Hom a b ) -> f == f ○ id
|
|
146
|
|
147 --assoc : { a b c d : Obj } ->
|
|
148 -- (f : Hom c d ) -> (g : Hom b c) -> (h : Hom a b) ->
|
|
149 -- (f ○ g) ○ h == f ○ ( g ○ h)
|
|
150
|
|
151
|
|
152 --a = Set
|
|
153
|
|
154 -- ListObj : {A : Set} -> List A
|
|
155 -- ListObj = List Set
|
|
156
|
|
157 -- ListHom : ListObj -> ListObj -> Set
|
|
158
|