Submit your solution as a text file "hw3.sml". Include a header
(* Name: <your name here> *) (* PID: <your pid here> *) (* Homework 3 *)Also, precede each solution with the corresponding exercise number in comments. At the moment the plan is for the gta to grade the solutions by hand.
All problems involve using SML and are based on material discussed in class or in the online notes. If any auxillary functions are needed they are mentioned explicitly.
Problems to submit:
trans
that takes a list of pairs and
outputs a pair of lists. For instance, the input
[(1,"a"),(2,"b")]
would result in the output
([1,2],["a","b"])
.
Your function will need to be recursive, and you must
use pattern matching. The type of your function should be
val trans = fn : ('a * 'b) list -> 'a list * 'b list
.
You should not need to constraint any types if you setup the cases in the
function properly.
AND(OR(PROP("A"),NOT(PROP("C"))),NOT("D"))
.
eval(exp,truthlist)
that takes a
propositional expression exp
and a list of true
proposition symbols truthlist
, and determines whether the
expression is true. Assume that any symbol that does not occur in the
list is false. (You may find it useful to write or track down a list
member function.)
NOT(NOT(A)) = A
,
AND(A,A) = A
, and
OR(B,B) = B
.
Be careful of input such as
NOT(AND(NOT(PROP("a")),NOT(PROP("a"))))
,
which is not completely simplified if you take the naive approach.
Suggested exercises:
val x = split(cs)
and obtains the components by other
means.
fun split [] = ([],[]) | split [a] = ([a],[]) | split a::b::cs = let val (M,N) = split cs; in (a::M, b::N) end;
insert
to manage the tree as a binary search tree.
datatype 'a bintree = Empty | Leaf of 'a | Node of 'a * 'a bintree * 'a bintree;