Mercurial > hg > Members > atton > delta_monad
annotate agda/delta.agda @ 104:ebd0d6e2772c
Trying redenition Delta with length constraints
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 26 Jan 2015 23:00:05 +0900 |
parents | dfe8c67390bd |
children | e6499a50ccbd |
rev | line source |
---|---|
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 open import list |
28
6e6d646d7722
Split basic functions to file
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
2 open import basic |
76 | 3 open import nat |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
4 open import revision |
87
6789c65a75bc
Split functor-proofs into delta.functor
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
5 open import laws |
29
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
6 |
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
7 open import Level |
27
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
8 open import Relation.Binary.PropositionalEquality |
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
9 open ≡-Reasoning |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
11 module delta where |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
13 data Delta {l : Level} (A : Set l) : (Rev -> (Set l)) where |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
14 mono : A -> Delta A init |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
15 delta : {v : Rev} -> A -> Delta A v -> Delta A (commit v) |
54
9bb7c9bee94f
Trying redefine delta for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
16 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
17 deltaAppend : {l : Level} {A : Set l} {n m : Rev} -> Delta A n -> Delta A m -> Delta A (merge n m) |
57
dfcd72dc697e
ReDefine Delta used non-empty-list for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
18 deltaAppend (mono x) d = delta x d |
dfcd72dc697e
ReDefine Delta used non-empty-list for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
19 deltaAppend (delta x d) ds = delta x (deltaAppend d ds) |
54
9bb7c9bee94f
Trying redefine delta for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
20 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
21 headDelta : {l : Level} {A : Set l} {n : Rev} -> Delta A n -> A |
70
18a20a14c4b2
Change prove method. use Int ...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
22 headDelta (mono x) = x |
18a20a14c4b2
Change prove method. use Int ...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
23 headDelta (delta x _) = x |
54
9bb7c9bee94f
Trying redefine delta for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
24 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
25 tailDelta : {l : Level} {A : Set l} {n : Rev} -> Delta A (commit n) -> Delta A n |
79 | 26 tailDelta (delta _ d) = d |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 |
76 | 28 |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
29 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
30 -- Functor |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
31 delta-fmap : {l : Level} {A B : Set l} {n : Rev} -> (A -> B) -> (Delta A n) -> (Delta B n) |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
32 delta-fmap f (mono x) = mono (f x) |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
33 delta-fmap f (delta x d) = delta (f x) (delta-fmap f d) |
57
dfcd72dc697e
ReDefine Delta used non-empty-list for infinite changes
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
34 |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
36 |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
37 -- Monad (Category) |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
38 delta-eta : {l : Level} {A : Set l} {v : Rev} -> A -> Delta A v |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
39 delta-eta {v = init} x = mono x |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
40 delta-eta {v = commit v} x = delta x (delta-eta {v = v} x) |
59
46b15f368905
Define bind and mu for Infinite Delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
41 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
42 delta-bind : {l : Level} {A B : Set l} {n : Rev} -> (Delta A n) -> (A -> Delta B n) -> Delta B n |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
43 delta-bind (mono x) f = f x |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
44 delta-bind (delta x d) f = delta (headDelta (f x)) (tailDelta (f x)) |
59
46b15f368905
Define bind and mu for Infinite Delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
45 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
46 delta-mu : {l : Level} {A : Set l} {n : Rev} -> (Delta (Delta A n) n) -> Delta A n |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
47 delta-mu d = delta-bind d id |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 |
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
33 | 50 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
51 {- |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
52 -- Monad (Haskell) |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
53 delta-return : {l : Level} {A : Set l} -> A -> Delta A (S O) |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
54 delta-return = delta-eta |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
55 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
56 _>>=_ : {l : Level} {A B : Set l} {n : Nat} -> |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
57 (x : Delta A n) -> (f : A -> (Delta B n)) -> (Delta B n) |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
58 d >>= f = delta-bind d f |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
59 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
60 -} |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
61 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
62 {- |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
63 -- proofs |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
64 |
76 | 65 -- sub-proofs |
66 | |
67 n-tail-plus : {l : Level} {A : Set l} -> (n : Nat) -> ((n-tail {l} {A} n) ∙ tailDelta) ≡ n-tail (S n) | |
79 | 68 n-tail-plus O = refl |
76 | 69 n-tail-plus (S n) = begin |
70 n-tail (S n) ∙ tailDelta ≡⟨ refl ⟩ | |
71 (tailDelta ∙ (n-tail n)) ∙ tailDelta ≡⟨ refl ⟩ | |
72 tailDelta ∙ ((n-tail n) ∙ tailDelta) ≡⟨ cong (\t -> tailDelta ∙ t) (n-tail-plus n) ⟩ | |
73 n-tail (S (S n)) | |
74 ∎ | |
75 | |
76 n-tail-add : {l : Level} {A : Set l} {d : Delta A} -> (n m : Nat) -> (n-tail {l} {A} n) ∙ (n-tail m) ≡ n-tail (n + m) | |
77 n-tail-add O m = refl | |
78 n-tail-add (S n) O = begin | |
79 n-tail (S n) ∙ n-tail O ≡⟨ refl ⟩ | |
77
4b16b485a4b2
Split nat definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
76
diff
changeset
|
80 n-tail (S n) ≡⟨ cong (\n -> n-tail n) (nat-add-right-zero (S n))⟩ |
76 | 81 n-tail (S n + O) |
82 ∎ | |
83 n-tail-add {l} {A} {d} (S n) (S m) = begin | |
84 n-tail (S n) ∙ n-tail (S m) ≡⟨ refl ⟩ | |
85 (tailDelta ∙ (n-tail n)) ∙ n-tail (S m) ≡⟨ refl ⟩ | |
86 tailDelta ∙ ((n-tail n) ∙ n-tail (S m)) ≡⟨ cong (\t -> tailDelta ∙ t) (n-tail-add {l} {A} {d} n (S m)) ⟩ | |
87 tailDelta ∙ (n-tail (n + (S m))) ≡⟨ refl ⟩ | |
88 n-tail (S (n + S m)) ≡⟨ refl ⟩ | |
89 n-tail (S n + S m) ∎ | |
90 | |
91 tail-delta-to-mono : {l : Level} {A : Set l} -> (n : Nat) -> (x : A) -> | |
92 (n-tail n) (mono x) ≡ (mono x) | |
79 | 93 tail-delta-to-mono O x = refl |
76 | 94 tail-delta-to-mono (S n) x = begin |
95 n-tail (S n) (mono x) ≡⟨ refl ⟩ | |
96 tailDelta (n-tail n (mono x)) ≡⟨ refl ⟩ | |
97 tailDelta (n-tail n (mono x)) ≡⟨ cong (\t -> tailDelta t) (tail-delta-to-mono n x) ⟩ | |
98 tailDelta (mono x) ≡⟨ refl ⟩ | |
99 mono x ∎ | |
100 | |
96
dfe8c67390bd
Unify Levels in delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
94
diff
changeset
|
101 head-delta-natural-transformation : {l : Level} {A B : Set l} |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
102 -> (f : A -> B) -> (d : Delta A) -> headDelta (delta-fmap f d) ≡ f (headDelta d) |
79 | 103 head-delta-natural-transformation f (mono x) = refl |
80 | 104 head-delta-natural-transformation f (delta x d) = refl |
79 | 105 |
96
dfe8c67390bd
Unify Levels in delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
94
diff
changeset
|
106 n-tail-natural-transformation : {l : Level} {A B : Set l} |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
107 -> (n : Nat) -> (f : A -> B) -> (d : Delta A) -> n-tail n (delta-fmap f d) ≡ delta-fmap f (n-tail n d) |
79 | 108 n-tail-natural-transformation O f d = refl |
109 n-tail-natural-transformation (S n) f (mono x) = begin | |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
110 n-tail (S n) (delta-fmap f (mono x)) ≡⟨ refl ⟩ |
79 | 111 n-tail (S n) (mono (f x)) ≡⟨ tail-delta-to-mono (S n) (f x) ⟩ |
112 (mono (f x)) ≡⟨ refl ⟩ | |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
113 delta-fmap f (mono x) ≡⟨ cong (\d -> delta-fmap f d) (sym (tail-delta-to-mono (S n) x)) ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
114 delta-fmap f (n-tail (S n) (mono x)) ∎ |
79 | 115 n-tail-natural-transformation (S n) f (delta x d) = begin |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
116 n-tail (S n) (delta-fmap f (delta x d)) ≡⟨ refl ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
117 n-tail (S n) (delta (f x) (delta-fmap f d)) ≡⟨ cong (\t -> t (delta (f x) (delta-fmap f d))) (sym (n-tail-plus n)) ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
118 ((n-tail n) ∙ tailDelta) (delta (f x) (delta-fmap f d)) ≡⟨ refl ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
119 n-tail n (delta-fmap f d) ≡⟨ n-tail-natural-transformation n f d ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
120 delta-fmap f (n-tail n d) ≡⟨ refl ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
121 delta-fmap f (((n-tail n) ∙ tailDelta) (delta x d)) ≡⟨ cong (\t -> delta-fmap f (t (delta x d))) (n-tail-plus n) ⟩ |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
122 delta-fmap f (n-tail (S n) (delta x d)) ∎ |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
123 -} |