TDA-uri și inducție structurală
1. Definiți axiome pentru următorii operatori pe tipul List
:
append
(concatenarea unei liste la o alta;append(Cons(8, Cons(12, Empty)), Cons(3, Cons(6, Empty))) = Cons(8, Cons(12, Cons(3, Cons(6, Empty))))
)reverse
(inversează elementele dintr-o listă)
2. Definiți axiome pentru următorii operatori pe tipul BTree
:
mirror : BTree → BTree
(arborele oglindit pe verticală, i.e. pentru orice nod, copilul stâng devine copilul drept și vice-versa)flatten : BTree → List
(lista cu toate elementele din arbore; observați că există mai multe ordini posibile)
3. Definiți axiome pentru următorii operatori pe tipul Map
:
update : Map × K × V → Map
(un Map cu o nouă asociere cheie:element)delete : Map × K → Map
(șterge cheia și valoarea asociată)
4. Demonstrați următoarele propoziții, folosind inducție structurală:
- $ \forall t \in \texttt{BTree}. size(t) = size(mirror(t))$
- $ \forall t \in \texttt{BTree}. size(t) = length(flatten(t))$
- $ \forall l \in \texttt{List}. append(l, Empty) = l$
- $ \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))$
- $ \forall l_1, l_2 \in \texttt{List}. length(append(l_1, l_2)) = length(append(l_2, l_1))$
- $ \forall l_1, l_2 \in \texttt{List}. reverse(append(l_1, l_2)) = append(reverse(l_2), reverse(l_1))$ .
Soluțiile acestui laborator se găsesc aici