-
Notifications
You must be signed in to change notification settings - Fork 1
/
C2W.agda
89 lines (75 loc) · 2.5 KB
/
C2W.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module C2W where
data Nat : Set where
ze : Nat
su : Nat -> Nat
data _<=_ : Nat -> Nat -> Set where
`0_ : forall {n m} -> n <= m -> n <= su m
`1_ : forall {n m} -> n <= m -> su n <= su m
[] : ze <= ze
infixr 20 `0_ `1_
infix 10 _/x\_
data _/x\_ : forall {l n m} ->
l <= m -> n <= m -> Set where
[] : [] /x\ []
rr_ : forall {l n m}{th : l <= m}{ph : n <= m}
-> th /x\ ph -> `0 th /x\ `1 ph
ll_ : forall {l n m}{th : l <= m}{ph : n <= m}
-> th /x\ ph -> `1 th /x\ `0 ph
data Vec (X : Set) : Nat -> Set where
[] : Vec X ze
_,-_ : forall {n} -> X -> Vec X n -> Vec X (su n)
infixr 20 _,-_
vec : forall {S T n} -> (S -> T)
-> Vec S n -> Vec T n
vec f [] = []
vec f (s ,- ss) = f s ,- vec f ss
riffle : forall {X l n m}{th : l <= m}{ph : n <= m}
-> Vec X l -> th /x\ ph -> Vec X n
-> Vec X m
riffle ls [] rs = []
riffle ls (rr p) (x ,- rs) = x ,- riffle ls p rs
riffle (x ,- ls) (ll p) rs = x ,- riffle ls p rs
data Two : Set where
ff tt : Two
record _><_ (S : Set)(T : S -> Set) : Set where
constructor _,_
field
fst : S
snd : T fst
data Riffled {T : Two -> Set}{m : Nat}
: Vec (Two >< T) m -> Set where
riffling :
forall {l}{n}{th : l <= m}{ph : n <= m}
(ffs : Vec (T ff) l)
(p : th /x\ ph)
(tts : Vec (T tt) n)
-> Riffled (riffle (vec (ff ,_) ffs)
p
(vec (tt ,_) tts))
riffled : forall (T : Two -> Set){m : Nat}
(bts : Vec (Two >< T) m)
-> Riffled bts
riffled T [] = riffling [] [] []
riffled T ((b , t) ,- bts) with riffled T bts
riffled T ((ff , f) ,- .(riffle (vec (ff ,_) ffs) p (vec (tt ,_) tts))) | riffling ffs p tts =
riffling (f ,- ffs ) (ll p) tts
riffled T ((tt , t) ,- .(riffle (vec (ff ,_) ffs) p (vec (tt ,_) tts))) | riffling ffs p tts =
riffling ffs (rr p) (t ,- tts)
data _~_ {X : Set}(x : X) : X -> Set where
r~ : x ~ x
{-# BUILTIN EQUALITY _~_ #-}
riffle1 : forall (T : Two -> Set){m : Nat}
{l}{n}{th : l <= m}{ph : n <= m}
(ffs : Vec (T ff) l)
(p : th /x\ ph)
(tts : Vec (T tt) n)
-> riffled T (riffle (vec (ff ,_) ffs) p (vec (tt ,_) tts)) ~ riffling ffs p tts
riffle1 T ffs (rr p) (t ,- tts)
with riffled T (riffle (vec (ff ,_) ffs) p (vec (tt ,_) tts))
| riffle1 T ffs p tts
... | z | w rewrite w = r~
riffle1 T (f ,- ffs) (ll p) tts
with riffled T (riffle (vec (ff ,_) ffs) p (vec (tt ,_) tts))
| riffle1 T ffs p tts
... | z | w rewrite w = r~
riffle1 T [] [] [] = r~