
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

HW 12 Prof. Caldwell Due: 9 October 2008 COSC 3015
Exercise 1.1. Read chapter 6 of the Bird text. Recall the BTree datatype and it’s structural induction principle for finite BTrees.
data BTree a = Leaf a | Fork (BTree a) (BTree a) deriving (Show,Eq)
(∀x : a. P [Leaf x] ∧ ∀x : a. ∀t 1 , t 2 : (BTree a). (P [t 1 ] ∧ P [t 2 ]) ⇒ P [Fork(t 1 , yt 2 )]) ⇒ ∀t : (BTree a). P [t]
Exercise 1.2. Here is a data-type declaration for a type of tree that can store two different types of values in it’s nodes.
data ABTree a b = Leaf | ANode a (ABTree a b) (ABTree a b) | BNode b (ABTree a b) (ABTree a b) deriving (Show,Eq)
Write the structural induction principle for this data-type.
Exercise 1.3.
i.) Write an recursive datatype declaration (of your choice) for another tree-like data type and,
ii.) write the structural induction principle for properties of finite instanes of your data-type.
Exercise 1.4. consider the following:
size (Leaf x) = 1 size (Fork xt yt) = (size xt) + (size yt)
height (Leaf x) = 0 height (Fork xt yt) = 1 + (height xt ‘max‘ height yt)
perfect (Leaf x) = True perfect (Fork xt yt) = (height xt == height yt) && perfect xt && perfect yt
Prove^1 the following theorem hold for all finite BTrees by structural induction.
Theorem 1.1. ∀t : BTree a. (perfect t) ⇒ size t = 2(height^ t)
(^1) Hints will be given in class on Thursday.