40 likes | 192 Vues
Proof: A | C -- lemma :/++. ++:: [t] -> [t] -> [t] [] ++ y = y (x:xs) ++ y = x:(xs ++ y). (1) (2). da ++ A:. segue C:. (x:xs) ++ y = [x]++(xs ++ y). Lemma:/++. Proof: ( riduzione di termini uguali ) (x:zs) ++ ys = x:(zs++y) -- (2) ma, per ogni w:
E N D
Proof: A| C -- lemma :/++ ++:: [t] -> [t] -> [t] [] ++ y = y (x:xs) ++ y = x:(xs ++ y) (1) (2) da ++ A: segue C: (x:xs) ++ y = [x]++(xs ++ y) Lemma:/++ • Proof: (riduzione di termini uguali) • (x:zs) ++ ys = x:(zs++y) -- (2) ma, per ogni w: • [x]++w = (x:[])++w -- defs(:) • = x:([]++w) -- (2) • = x:w -- (1) • anche per w=(zs++y) Proof: (riduzione di termini uguali) [x]++(zs++y) = (x:[])++(zs++y) -- defs(:) = x:([]++(zs++y)) -- (2) = x:(zs++y) -- (1) = (x:zs)++y -- (2R)
Proof: A| C -- reverse 1 reverse:: [t] -> [t] reverse [] = [] reverse (x:xs) = reverse xs ++ [x] (1) (2) da A: segue Cxs,ys: reverse (xs ++ ys) = (reverse ys) ++ (reverse xs) Proof: (Induzione sulla size delle liste) base: |xs|=0 => xs=[] & xs++ys = ys => reverse ([]++ys) = reverse ys ++ reverse[] |xs|=1 => xs=[x] => reverse([x]++ys) = reverse(x:[]++ys) = reverse(x:ys) -- defs(:) = reverse ys ++ [x] ---(2) = reverse ys ++ reverse [x] ---lemma rev[] generale: ind.hyp k: xs: |xs|<k => Cxs,ys Sia xs: |xs| = k>1 => xs = x:zs per |zs|<k => => reverse(xs ++ ys) = reverse(x:zs ++ ys) = reverse([x] ++ (zs ++ ys)) ---lemma :/++ = reverse(zs ++ ys) ++ (reverse [x]) ---ind.hyp = (reverse ys) ++ (reverse zs) ++ (reverse [x]) ---ind.hyp = (reverse ys) ++ ((reverse zs) ++ (reverse [x])) ---ass++ = (reverse ys) ++ (reverse ([x]++zs)) ---ind.hyp = (reverse ys) ++ (reverse xs)
Proof: A| C--- reverse 2 reverse:: [t] -> [t] reverse [] = [] reverse (x:xs) = reverse xs ++ [x] (1) (2) da A: segue Cxs,ys: reverse (xs ++ ys) = (reverse ys) ++ (reverse xs) Proof: (Induzione sulla size delle liste) base: |xs|+|ys|=0 => xs=[]=ys & xs++ys=[] => reverse [] = reverse [] ++ reverse[] generale: induc-hyp: k: xs,ys: |xs|+|ys|<k => Cxs,ys Sia xs, ys: |xs|+|ys|=k>0 & |xs|≠0≠|ys| => xs = x:zs per |zs|+|ys|<k => => reverse(xs ++ ys) = reverse(x:zs ++ ys) = reverse(x:(zs ++ ys)) --- def(++(2)) = reverse(zs ++ ys) ++ [x] --- (2) = ((reverse ys) ++ (reverse zs)) ++ [x] ---ind.hyp. |zs|+|ys|<k = (reverse ys) ++ ((reverse zs) ++ [x]) --- lemma ass.++ = (reverse ys) ++ (reverse x:zs) ---(2R) = (reverse ys) ++ (reverse xs) Quando |xs|≠0&|ys|=0 ?
Proof: lemmi [] ++ ys = ys (x:xs) ++ ys = x:(xs++ys) reverse [] = [] reverse (x:xs) = reverse xs ++ [x] da A: segue: lemma ass.++ (xs ++ ys) ++ zs = xs ++ (ys++zs) lemma rev[] reverse[x] = [x]