% File: tree.pl % Author: Dilian Gurov, KTH CSC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Föreläsning 3a: Induktiva datatyper: Träd (inte inbyggd) % % - Prologtermer % - Binära träd utan data % - Strukturell induktion över binära träd utan data % - Binära träd med data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 2.1 Binära träd utan data % % Vi kan lägga till trädet som faktum och ställa frågor om den: isTree(branch(leaf, branch(branch(leaf, leaf), leaf))). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Exempel: height(T, N) max(X, Y, X) :- Y