Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. 1. (APP1) append(Empty, l) = l (APP2) append(Cons(x, xs), l) = Cons(x, append(xs, l)) (REV1) reverse(Empty) = Empty (REV2) reverse(Cons(x, xs)) = append(reverse(xs), Cons(x, Empty)) 2. (M1) mirror(Nil) = Nil (M2) mirror(Node(e, l, r)) = Node(e, mirror(r), mirror(l)) (F1) flatten(Nil) = Empty (F2) flatten(Node(e, l, r)) = Cons(e, append(flatten(l), flatten(r))) 3. (UPD1) update(MEmpty, k, v) = Insert((k, v), MEmpty) (UPD2) update(Insert((k, v), m), k', v') = if k = k' then Insert((k, v'), m) else Insert((k, v), update(m, k', v')) (DEL1) delete(MEmpty, k) = MEmpty (DEL2) delete(Insert((k, v), m), k') = if k = k' then m else Insert((k, v), delete(m, k')) 4. * $ \forall t \in \texttt{BTree}. size(t) = size(mirror(t)) $ cazul de baza: mirror(Nil) = Nil (M1) => size(Nil) = size(mirror(Nil)) ipoteza inductiei: size(l) = size(mirror(l)), size(r) = size(mirror(r)) size(Node(e, l, r)) = 1 + size(l) + size(r) (S2) = 1 + size(r) + size(l) (comutativitatea adunării) = 1 + size(mirror(r)) + size(mirror(l)) (ipoteza inductiei) = size(Node(e, mirror(r), mirror(l))) (S2) = size(mirror(Node(e, l, r)) (M2) * $ \forall t \in \texttt{BTree}. size(t) = length(flatten(t)) $ cazul de baza: size(Nil) = (S1) = 0 = (L1) = length(Empty) = (F1) = length(flatten(Nil)) ipoteza inductiei: size(l) = length(flatten(l)), size(r) = length(flatten(r)) size(Node(e, l, r)) = 1 + size(l) + size(r) (S2) = 1 + length(flatten(l)) + length(flatten(r)) (ipoteza inductiei) = 1 + length(append(flatten(l), flatten(r)) (vom demonstra) = length(Cons(e, append(flatten(l), flatten(r))) (L2) = length(flatten(Node(e, l, r))) (F2) mai trebuie sa demonstram pasul intermediar: demonstram ca length(append(a, b)) = length(a) + length(b) (LAPP) prin inductie dupa a cazul de baza: length(append(Empty, b)) = length(b) (APP1) = 0 + length(b) = length(Empty) + length(b) ipoteza inductiei: length(append(xs, b)) = length(xs) + length(b) pasul inductiei: length(append(Cons(x, xs), b)) = length(Cons(x, append(xs, b))) (APP2) = 1 + length(append(xs, b)) (L2) = 1 + length(xs) + length(b) (ip. inductiei) = length(xs) + 1 + length(b) (comutativitatea adunării) = length(Cons(x, xs)) + length(b) (L2) * $ \forall l \in \texttt{List}. append(l, Empty) = l $ cazul de baza: append(Empty, Empty) = Empty (APP1) ipoteza inductiei: append(xs, Empty) = s append(Cons(x, xs), Empty) = Cons(x, append(xs, Empty)) (APP2) = Cons(x, s) (ip. inductiei) * $ \forall l_1, l_2, l_3 \in \texttt{List}. append(l_1, append(l_2, l_3)) = append(append(l_1, l_2), l_3) $ facem inductie structurala dupa l_1. Vom nota append(a, b) cu a ++ b ca sa ne fie mai usor cazul de baza: Empty ++ (l_2 ++ l_3)) = l_2 ++ l_3 (APP1) = (Empty ++ l_2) ++ l_3 (APP1) ipoteza inductiei: l_1 ++ (l_2 ++ l_3) = (l_1 ++ l_2) ++ l_3 pasul inductiei: Cons(x, l_1) ++ (l_2 ++ l_3) = Cons(x, l_1 ++ (l_2 ++ l_3)) (APP2) = Cons(x, (l_1 ++ l_2) ++ l_3) (ip. inductiei) = Cons(x, l_1 ++ l_2) ++ l_3 (APP2) = (Cons(x, l_1) ++ l_2) ++ l_3 (APP2) * $ \forall l_1, l_2 \in \texttt{List}. length(append(l_1, l_2)) = length(append(l_2, l_1)) $ facem inductie structurala dupa l_1 cazul de baza: length(append(Empty, l_2)) = length(l_2) (APP1) = length(append(l_2, Empty)) (4.c) ipoteza inductiei: length(append(l_1, l_2)) = length(append(l_2, l_1)) pasul inductiei: length(append(Cons(x, l_1), l_2)) = length(Cons(x, append(l_1, l_2))) (APP2) = 1 + length(append(l_1, l_2)) (L2) = 1 + length(l_1) + length(l_2) (LAPP) = length(l_2) + 1 + length(l_1) (comutativitatea adunării) = length(l_2) + length(Cons(x, l_1)) (L2) = length(append(l_2, Cons(x, l_1))) (LAPP) * $ \forall l_1, l_2 \in \texttt{List}. reverse(append(l_1, l_2)) = append(reverse(l_2), reverse(l_1)) $. facem inductie structurala dupa l_1 cazul de baza: reverse(append(Empty, l_2)) = reverse(l_2) (APP1) = append(reverse(l_2), Empty) (4.c) = append(reverse(l_2), reverse(Empty)) (REV1) ipoteza inductiei: reverse(append(l_1, l_2)) = append(reverse(l_2), reverse(l_1)) pasul inductiei: reverse(append(Cons(x, l_1), l_2)) = reverse(Cons(x, append(l_1, l_2))) (APP2) = append(reverse(append(l_1, l_2)), Cons(x, Empty)) (REV2) = append(append(reverse(l_2), reverse(l_1)), Cons(x, Empty)) (ip. inductivă) = append(reverse(l_2), append(reverse(l_1), Cons(x, Empty))) (4.d) = append(reverse(l_2), reverse(Cons(x, l_1))) (REV2)