Sunday, January 06, 2008

DP: Insertion Sort

foldr ins [] xs
where
ins x [] = [x]
ins x (z:zs) = min x z : ins (max x z) zs

toterm [] = []
toterm (x:xs) = I x p n f : toterm xs

sem [] = []
sem (I x p n f : ts) = ins x (sem ts)
sem (C x p n f : ts) = x : sem ts

I x p n f
=> C x p' n' f' if n = Nil
=> I x p' n' f' if n = I _ _ _ _
=> C (min x y) p' n' f' if n = C y _ _ _

C x p n f
=> C x p' n' f' if p = Nil
=> I (max x y) p' n' f' if p = I y _ _ _
=> C x p' n' f' if p = C _ _ _ _

foldr ins [] xs = sem $ (map (=>) ) ^ n $ toterm $ xs

foldr ins [] [10,1,5,2]
= ins 10 (ins 1 (ins 5 (ins 2 [])))
= ins 10 (ins 1 (ins 5 (cons 2 [])))
= ins 10 (ins 1 (cons 2 (ins 5 [])))
= ins 10 (cons 1 (ins 2 (cons 5 [])))
= cons 1 (ins 10 (cons 2 (ins 5 [])))
= cons 1 (cons 2 (ins 10 (cons 5 [])))
= cons 1 (cons 2 (cons 5 (ins 10 [])))
= cons 1 (cons 2 (cons 5 (cons 10 [])))

* 방향
- 병렬성이나 Lazy Evaluation이 연관된 증명이 매우 어려워 보임.
- 우선 Equational Equality를 보이는데 중점.
- 병렬성은 map 함수로 설명
- pure functional context는 lazy evaluation으로 설명

1 comment:

choikwanghoon2002 said...

* A parallel reduction by induction on the structure of lambda terms (without referring to residuals or other auxiliary notions)

x => x

e => e'
-------------------
lam x.e => lam x.e'

e1 => e1' e2 => e2'
----------------------
e1 e2 => e1' e2'

e1 => e1' e2 => e2' FV(e2') \cap Capt_x(e1') = empty
-------------------------------------------------------
(lam x.e1) e2 => e1' [x:=e2']


* Capt_x (y) = \emptyset
Capt_x (e1 e2) = Capt_x (e1) \cup Capt_x (e2)
Capt_x (lam y.e) = {y} \cup Capt_x (e) if x \in FV (\lam y.e)
= \emptyset otherwise