// This file defines some functions that we ask you to prove lemmas about. // Please don't modify it or turn it in. module Defs { datatype List = Nil | Cons(head: T, tail: List) function Length(l: List): nat { match l case Nil => 0 case Cons(_, l') => 1 + Length(l') } type Binary = List datatype BTrie = Leaf(included: bool) | Node(included: bool, left: BTrie, right: BTrie) predicate Member(b: Binary, t: BTrie) { match t case Leaf(inc) => inc && b == Nil case Node(inc, left, right) => match b case Nil => inc case Cons(false, b') => Member(b', left) case Cons(true, b') => Member(b', right) } datatype Option = None | Some(value: T) // Here is a generic version of tries, identical to BTrie save for the type of // value associated with a key. The prior version implicitly represented sets // as dictionaries mapping to Booleans. datatype GTrie = GLeaf(value: T) | GNode(value: T, left: GTrie, right: GTrie) function Or(a: bool, b: bool): bool { a || b } function Max(a: nat, b: nat): nat { if a < b then b else a } function Depth(gt: GTrie): nat { match gt case GLeaf(_) => 0 case GNode(_, gt1, gt2) => 1 + Max(Depth(gt1), Depth(gt2)) } function FuncComposition(x: (T -> T), y: (T -> T)): (T -> T) { z => y(x(z)) } }