This practice set is a graded sequence of exercises that ask you to
state and prove a theorem. You must use the ACL2 theorem prover to do
your proofs.
There is no due date for this assignment. But it is critical that you
learn how to use ACL2 on such problems. The best way to learn ACL2 or
any other mechanized reasoning tool is to use it repeatedly.
We will post our solutions to these exercises in a few days. But we
strongly encourage you to do the problem without looking at our
solutions.
Problem 1: Do the problems suggested in Practice Exercise 1 with ACL2.
(Remember that the Practice Exercise 1 asked you to do proofs by
hand.)
Problem 2: This problem is about formalizing elementary set theory.
We will treat lists as sets by ignoring duplicates. Thus, we will
treat both the list (1 1 2 3) and (1 2 3) as the same set {1, 2, 3}.
(a) Define a function subset such that (subset x y) returns T if each
member of list x is a member of list y. (Hint: you can use the
function mem shown in class.)
(b) Define functions set-intersect and set-union to return the
intersection and union of sets.
(c) Prove that the intersection of sets x and y is a subset of both x
and y. Also prove that x and y are both subsets of their union.
Problem 3: This problem asks you to reason about sorting.
(a) Define a function insertion-sort such that if given a list x of
natural numbers, (insertion-sort x) returns a sorted list using the
insertion sort algorithm. Show that if x is a list of natural numbers
(insertion-sort x) returns an ordered permutation of x.
(b) Define a mergesort function. In mergesort, we divide the list in
two parts, recursively sort each half and then merge the resulting
lists. You can look up a description of mergesort in any textbook on
Design and Analysis of Algorithms or on the Web.
(c) Prove that if x is a list of natural numbers (mergesort x) returns
an ordered permutation of x.
(d) Prove that for any list x of natural numbers (insertion-sort x)
and (mergesort x) return the same value.
(e) Prove that if you apply insertion-sort on a list x of natural
numbers and then apply it again, then the result is the same as
applying insertion-sort once on x.
Problem 4: This exercise is about tautology checking. This exercise
is a bit more elaborate and subtle than the previous ones.
We will consider a language which we will call the ITE language. The
language has one ternary operator which we will call ite (for
if-then-else). It also contains variables, and the symbols T and nil.
(Any symbol other than T or nil will be considered a variable in this
language.) So a legal expression in this language is: '(ite x (ite t
y z) (ite nil x t)). Another legal expression is
'(ite (ite x y nil) x (ite x z t)).
We will consider giving meaning to expressions in the ITE
language. Suppose a be a list of pairs associating variables in the
language to either T or NIL. For example, '((x . T) (y . NIL) (z
. NIL)) is one such association list. Given an expression and an
association list, we will think of the "value" of the expression as
follows. Replace the variables in the expression with their values in
the association list, treat the resulting expression (which now has no
variable) as an if-then-else, and evaluate the if-then-else. For
example the value of the expression '(ite x (ite t y z) (ite nil x t))
under the association list '((x . T) (y . NIL) (z . NIL)) is the same
as the value of the expression '(ite T (ite t NIL NIL) (ite nil t
nil)) which, when interpreted as an if-then-else, yields NIL.
We will say that an expression x is a tautology if it evaluates to T
under every association list. For example the expression '(ite x (ite
y x t) (ite z z t)) is a tautology. (Can you see why?)
(a) Define a function correct-ite-p such that (correct-ite-p x)
returns T if x is a legal expression for the ITE language.
(b) Define a function evaluate-ite such that (evaluate-ite x a)
returns the value of the expression x using association list a.
(c) Define a function ite-tautology such that (ite-tautology x)
returns T if the value of the expression x is T under any association
list, NIL otherwise. Prove that it is a Boolean, that is, always
returns T or NIL.
(d) State and prove the theorem that if (ite-tautology x) returns T
then x is a tautology.
(e) State and prove the converse of the theorem above. That is, show
that if x is a tautology then (ite-tautology x) returns T.