Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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ă)
  
-1Prove the following properties are trueusing structural ​induction:+4Demonstrați următoarele propozițiifolosind 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 ​l1l2l3 \in \texttt{List}. append(l1, append(l2l3)) = append(append(l1l2), l3))] +  * $math[\forall ​l_1l_2l_3 \in \texttt{List}. append(l_1, append(l_2l_3)) = append(append(l_1l_2), l_3))] 
-  * $math[\forall ​l1l2 \in \texttt{List}. length(append(l1l2)) = length(append(l2l1))] +  * $math[\forall ​l_1l_2 \in \texttt{List}. length(append(l_1l_2)) = length(append(l_2l_1))] 
-  * $math[\forall ​l1l2 \in \texttt{List}. reverse(append(l1l2)) = append(reverse(l2), reverse(l1))].+  * $math[\forall ​l_1l_2 \in \texttt{List}. reverse(append(l_1l_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>​