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