Mercurial > hg > Members > atton > agda > systemF
annotate systemF.agda @ 20:de9e05b25acf
Define List
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 10 Apr 2014 14:29:37 +0900 |
parents | 9eb6fcf6fc7d |
children | 25b62c46081b |
rev | line source |
---|---|
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 open import Level |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 open import Relation.Binary.PropositionalEquality |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
4 module systemF where |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 -- Bool |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 Bool = \{l : Level} -> {X : Set l} -> X -> X -> X |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 T : Bool |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 T = \{X : Set} -> \(x : X) -> \y -> x |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 F : Bool |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 F = \{X : Set} -> \x -> \(y : X) -> y |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 D : {X : Set} -> (U V : X) -> Bool -> X |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 D {X} u v bool = bool {X} u v |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 lemma-bool-t : {X : Set} -> {u v : X} -> D {X} u v T ≡ u |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 lemma-bool-t = refl |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 lemma-bool-f : {X : Set} -> {u v : X} -> D {X} u v F ≡ v |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 lemma-bool-f = refl |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 -- Product |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
27 _×_ : {l : Level} -> Set l -> Set l -> Set (suc l) |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
28 _×_ {l} U V = {X : Set l} -> (U -> V -> X) -> X |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
30 <_,_> : {l : Level} -> {U : Set l} -> {V : Set l} -> U -> V -> (U × V) |
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
31 <_,_> {l} {U} {V} u v = \{X : Set l} -> \(x : U -> V -> X) -> x u v |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
33 π1 : {l : Level} -> {U : Set l} -> {V : Set l} -> (U × V) -> U |
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
34 π1 {l} {U} {V} t = t {U} \(x : U) -> \(y : V) -> x |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
36 π2 : {l : Level} -> {U : Set l} -> {V : Set l} -> (U × V) -> V |
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
37 π2 {l} {U} {V} t = t {V} \(x : U) -> \(y : V) -> y |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 |
15
8c735b9ebf5a
Add lemma for Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
39 lemma-product : {l : Level} {U V : Set l} -> U -> V -> U × V |
8c735b9ebf5a
Add lemma for Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
40 lemma-product u v = < u , v > |
8c735b9ebf5a
Add lemma for Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
41 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
42 lemma-product-pi1 : {l : Level} {U V : Set l} -> {u : U} -> {v : V} -> π1 (< u , v >) ≡ u |
0
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 lemma-product-pi1 = refl |
b7c49383e386
Bool and Product in System F
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
45 lemma-product-pi2 : {l : Level} {U V : Set l} -> {u : U} -> {v : V} -> π2 (< u , v >) ≡ v |
2 | 46 lemma-product-pi2 = refl |
47 | |
48 -- Empty | |
49 | |
50 | |
51 -- Sum | |
52 | |
53 _+_ : {l : Level} -> Set l -> Set l -> Set (suc l) | |
54 _+_ {l} U V = {X : Set l} -> (U -> X) -> (V -> X) -> X | |
55 | |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
56 ι1 : {l : Level} {U V : Set l} -> U -> (U + V) |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
57 ι1 {l} {U} {V} u = \{X : Set l} -> \(x : U -> X) -> \(y : V -> X) -> x u |
2 | 58 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
59 ι2 : {l : Level} {U V : Set l} -> V -> (U + V) |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
60 ι2 {l} {U} {V} v = \{X : Set l} -> \(x : U -> X) -> \(y : V -> X) -> y v |
2 | 61 |
62 δ : {l : Level} -> {U V : Set l} -> {X : Set l} -> (U -> X) -> (V -> X) -> (U + V) -> X | |
63 δ {l} {U} {V} {X} u v t = t {X} u v | |
64 | |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
65 lemma-sum-iota1 : {l : Level} {U V X R : Set l} -> {u : U} -> {ux : (U -> X)} -> {vx : (V -> X)} -> δ ux vx (ι1 u) ≡ ux u |
2 | 66 lemma-sum-iota1 = refl |
67 | |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
68 lemma-sum-iota2 : {l : Level} {U V X R : Set l} -> {v : V} -> {ux : (U -> X)} -> {vx : (V -> X)} -> δ ux vx (ι2 v) ≡ vx v |
2 | 69 lemma-sum-iota2 = refl |
3
26cf9069f70a
Wrote Sigma in Existional
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
70 |
6 | 71 |
3
26cf9069f70a
Wrote Sigma in Existional
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
72 -- Existential |
26cf9069f70a
Wrote Sigma in Existional
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
73 |
5
63e982ff38a5
Rewrite Existential by data constructor
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
74 data V {l} (X : Set l) : Set l |
63e982ff38a5
Rewrite Existential by data constructor
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
75 where |
63e982ff38a5
Rewrite Existential by data constructor
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
76 v : X -> V X |
3
26cf9069f70a
Wrote Sigma in Existional
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
77 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
78 Σ_,_ : {l : Level} (X : Set l) -> V X -> Set (suc l) |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
79 Σ_,_ {l} U u = {Y : Set l} -> ({X : Set l} -> (V X) -> Y) -> Y |
5
63e982ff38a5
Rewrite Existential by data constructor
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
80 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
81 ⟨_,_⟩ : {l : Level} (U : Set l) -> (u : V U) -> Σ U , u |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
82 ⟨_,_⟩ {l} U u = \{Y : Set l} -> \(x : {X : Set l} -> (V X) -> Y) -> x {U} u |
6 | 83 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
84 ∇_,_,_ : {l : Level} {W : Set l} -> (X : Set l) -> { u : V X } -> X -> W -> Σ X , u -> W |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
85 ∇_,_,_ {l} {W} X {u} x w t = t {W} (\{X : Set l} -> \(x : V X) -> w) |
6 | 86 |
87 {- | |
7 | 88 lemma-nabla on proofs and types |
6 | 89 (∇ X , x , w ) ⟨ U , u ⟩ ≡ w |
7 | 90 w[U/X][u/x^[U/X]] |
6 | 91 -} |
92 | |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
93 lemma-nabla : {l : Level} {X W : Set l} -> {x : X} -> {w : W} -> (∇_,_,_ {l} {W} X {v x} x w) ⟨ X , (v x) ⟩ ≡ w |
6 | 94 lemma-nabla = refl |
8 | 95 |
96 | |
97 -- Int | |
98 | |
13
4977c5873660
Add lemma-it of Int, but has yellow
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
99 Int : {l : Level} -> {X : Set l} -> Set l |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
100 Int {l} {X} = X -> (X -> X) -> X |
8 | 101 |
13
4977c5873660
Add lemma-it of Int, but has yellow
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
102 O : {l : Level} -> {X : Set l} -> Int |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
103 O {l} {X} = \(x : X) -> \(y : X -> X) -> x |
8 | 104 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
105 S : {l : Level} -> {X : Set l} -> Int -> Int |
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
106 S {l} {X} t = \(x : X) -> \(y : X -> X) -> y (t x y) |
9
64182a3d9a49
Trying g of Int. but not completed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
107 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
108 It : {l : Level} {U : Set l} -> (u : U) -> (U -> U) -> Int -> U |
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
109 It {l} {U} u f t = t u f |
8 | 110 |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
111 lemma-it-o : {l : Level} {U : Set l} -> {u : U} -> {f : U -> U} -> It u f O ≡ u |
8 | 112 lemma-it-o = refl |
113 | |
14
491a08669724
Delete definition global Level
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
114 lemma-it-s-o : {l : Level} {U : Set l} -> {u : U} -> {f : U -> U} -> {t : Int} -> It u f (S t) ≡ f (It u f t) |
9
64182a3d9a49
Trying g of Int. but not completed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
115 lemma-it-s-o = refl |
64182a3d9a49
Trying g of Int. but not completed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
116 |
12
627da4867e5b
Delete multiple levels on Product
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
117 g : {l : Level} -> {U : Set l} -> {f : U -> Int {l} {U} -> U} -> (U × Int) -> (U × Int) |
13
4977c5873660
Add lemma-it of Int, but has yellow
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
118 g {l} {U} {f} = \x -> < (f (π1 x) (π2 x)) , S (π2 x) > |
4977c5873660
Add lemma-it of Int, but has yellow
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
119 |
16 | 120 -- cannot prove general Int |
121 -- lemma-it-n : {l : Level} {U : Set l} {u : U} {n : Int} {f : U -> Int -> U} -> g {l} {U} {f} < u , n > ≡ < f u n , S n > | |
122 -- lemma-it-n = refl | |
17 | 123 |
18 | 124 R : {l : Level} -> {U : Set l} -> U -> (U -> Int -> U) -> Int -> U |
125 R {l} {U} u f t = π1 (It {suc l} {U × Int} < u , O > (g {_} {_} {f}) t) | |
126 | |
127 lemma-R-O : {l : Level} {U : Set l} {u : U} {f : (U -> Int -> U)} -> R u f O ≡ u | |
128 lemma-R-O = refl | |
129 | |
130 lemma-R-n : {l : Level} {U : Set l} {u : U} {f : (U -> Int -> U)} {n : Int} -> R u f (S n) ≡ f (R u f n) (n < u , O > (g {l} {U} {f}) (\u n -> π2 < u , n > )) | |
131 lemma-R-n = refl | |
19 | 132 |
133 -- Proofs And Types Style lemma-R-n | |
134 -- lemma-R-n : {l : Level} {U : Set l} {u : U} {f : (U -> Int -> U)} {n : Int} -> R u f (S n) ≡ f (R u f n) n | |
135 -- n in (S n) and (R u f n) has (U × Int), but last n has Int. | |
136 -- regenerate same (n : Int) by used g, <_,_> | |
20 | 137 -- NOTE : Proofs And Types say "equation for recursion is satisfied by values only" |
19 | 138 |
139 | |
20 | 140 -- List |
19 | 141 |
20 | 142 List : {l : Level} -> (U : Set l) -> Set (suc l) |
143 List {l} U = {X : Set l} -> X -> (U -> X -> X) -> X | |
144 | |
145 nil : {l : Level} {U : Set l} -> List U | |
146 nil {l} {U} = \{X : Set l} -> \(x : X) -> \(y : U -> X -> X) -> x | |
147 | |
148 cons : {l : Level} {U : Set l} -> U -> List U -> List U | |
149 cons {l} {U} u t = \{X : Set l} -> \(x : X) -> \(y : U -> X -> X) -> y u (t {X} x y) | |
150 | |
151 ListIt : {l : Level} {U W : Set l} -> W -> (U -> W -> W) -> List U -> W | |
152 ListIt {l} {U} {W} w f t = t {W} w f | |
153 | |
154 lemma-list-it-nil : {l : Level} {U W : Set l} {w : W} {f : U -> W -> W} -> ListIt w f nil ≡ w | |
155 lemma-list-it-nil = refl | |
156 | |
157 lemma-list-it-cons : {l : Level} {U W : Set l} {u : U} {w : W} {f : U -> W -> W} {t : List U} -> ListIt w f (cons u t) ≡ f u (ListIt w f t) | |
158 lemma-list-it-cons = refl |