Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
aa:lab:12 [2022/01/25 10:56] dmihai |
aa:lab:12 [2025/01/23 14:09] (current) dmihai |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Structural Induction ===== | + | ====== TDA-uri și inducție structurală ====== |
+ | | ||
- | Recall the ADTs defined in the [[aa:lab:11|previous lab]] and lecture (together with their operators): | + | 1. Definiți axiome pentru următorii operatori pe tipul ''List'': |
- | * Binary Tree | + | |
- | * List | + | |
- | * Nat | + | |
- | And the following definition of ''reverse'': | + | * ''reverse'' (inversează elementele dintr-o listă) |
+ | * ''filterEven'' (elimină elementele impare dintr-o listă) | ||
- | $math[reverse : List \rightarrow List] | + | 2. Definiți axiome pentru următorii operatori pe tipul ''BTree'': |
- | $math[reverse(Empty) = Empty] | + | * ''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) | ||
- | $math[reverse(Cons(x, xs)) = append(reverse(xs), Cons(x, Empty))] | + | 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ă) | ||
- | 1. Prove the following properties are true, using structural induction: | + | 4. Demonstrați următoarele propoziții, folosind inducție structurală: |
- | * $math[\forall t \in \texttt{Tree}. size(t) = size(mirror(t))] | + | * $math[\forall t \in \texttt{BTree}. size(t) = size(mirror(t))] |
- | * $math[\forall t \in \texttt{Tree}. size(t) = length(flatten(t))] | + | * $math[\forall t \in \texttt{BTree}. size(t) = length(flatten(t))] |
- | * $math[\forall a, b, c \in \texttt{Nat}. add(a, add(b, c)) = add(add(a, b), c)] | + | |
* $math[\forall l \in \texttt{List}. append(l, Empty) = l] | * $math[\forall l \in \texttt{List}. append(l, Empty) = l] | ||
- | * $math[\forall l1, l2, l3 \in \texttt{List}. append(l1, append(l2, l3)) = append(append(l1, l2), l3))] | + | * $math[\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))] |
- | * $math[\forall l1, l2 \in \texttt{List}. length(append(l1, l2)) = length(append(l2, l1))] | + | * $math[\forall l_1, l_2 \in \texttt{List}. length(append(l_1, l_2)) = length(append(l_2, l_1))] |
- | * $math[\forall l1, l2 \in \texttt{List}. reverse(append(l1, l2)) = append(reverse(l2), reverse(l1))]. | + | * $math[\forall l_1, l_2 \in \texttt{List}. reverse(append(l_1, l_2)) = append(reverse(l_2), reverse(l_1))]. |
+ | |||
+ | |||
+ | |||
+ | <note> | ||
+ | Soluțiile acestui laborator se găsesc [[https://ocw.cs.pub.ro/ppcarte/doku.php?id=aa:lab:sol:12|aici]] | ||
+ | </note> | ||