CS389R Recursion and Induction
Homework #1
You can discuss the problems with your fellow students, but the final
solutions that you submit must be yours. Also, following standard
scholarly practice, if you have discussed the problem with others
(other than the instructors) then you should acknowledge them in your
submission. If you obtained the key idea from an Internet source or a
book or paper, other than the class lecture materials then that source
should be cited. (If no such source was consulted, you should state
that in your submission.)
The submission should be a directory containing Lisp files, together
with an optional README. The solution to each problem must be in a
separate file. The file containing the solution to problem i should
be named prob-i.lisp. If other files are necessary to process your
solution (for example, a separate file of auxiliary definition and
lemmas) then you should include these in your submission. However,
the final solution (definition, theorem, program) must be in the file
prob-i.lisp. Please add as much documentation as you need to make the
solutions understandable. The README file should be an ASCII text
file containing the declaration of collaboration above together with
any other remarks that you wish to bring to our attention.
There are 6 problems. Each problem is worth 5 points. Additionally,
5 points are allocated for documentation. Partial credit for each
problem will be given at the discretion of the grader.
Problems 1 and 2 are programming problems. You can write them in
program mode in ACL2.
Problem 1: Bubble sort is a simple sorting algorithm that works by
repeatedly stepping through the list to be sorted, comparing each pair
of adjacent items and swapping them if they are in the wrong order.
The pass through the list is repeated until no swaps are needed, which
indicates that the list is sorted.
Define a function bubble-sort, which takes a list l and returns a
sorted list l' using the bubble sort algorithm.
You can consult an algorithms book (or wikipedia or any other place on
the Web) for a description of bubble sort.
Problem 2: A Matrix is a two-dimensional array that you can represent
with a list of lists. This problem is about formalizing matrix
algebra in ACL2.
- Find a representation of matrix of rational numbers in ACL2.
Formalize this by defining a predicate matrix-p that takes a single
argument and returns T if the argument is (your
representation of) such a matrix, otherwise NIL.
- Define functions matrix+, matrix-* and matrix-T that respectively
compute sum, product, and transpose of matrices. Note that matrix+
needs to take two matrices of equal dimensions, and matrix-* needs
the number of rows of one to be the same as the number of columns of
other. You can choose how to handle the case when the arguments to
your functions do not satisfy such requirements.
Problems 3 and 4 ask you to state a theorem, not prove it. You need
to write a term that, if proven by ACL2, will let you claim that you
have proven the theorem. You are free to use any function (without
defining it) if that function is available in ACL2's boot-strap
theory. (For example, there is a function expt that takes two numbers
x and n and computes the value of x^n. You can use this function for
solving Problem 3.) However, any other function you use must be
defined and the definitions accepted. There is no credit or penalty
for using your own definitions or the built-in ones. So in case you
don't know whether there is a built-in function to do something but
you can figure out how to define the function on your own, please feel
free to use your own definition.
Problem 3: Fermat's last theorem can be informally stated as follows.
"Let x, y, and z be any natural numbers. There is no natural number n
> 2 such that x^n + y ^n = z^n.
How do you state Fermat's last theorem in the ACL2 logic?
Problem 4: The uniqueness of prime factorization
theorem can be stated as follows. Let l and m be any two lists of
numbers, such that each number in l and m is a prime number.
Furthermore, let the product of numbers in l is the same as the
product of the numbers in m. Then the list l and the list m are
permutations of each other.
State the uniqueness of prime factorization theorem in the ACL2 logic.
You will need to define the concepts of (1) primeness, (2) list of
numbers, (3) product of numbers in a list, and (4) the notion of two
lists being permutations of each other. Feel free to define any
number of functions as you need them.
Problems 5 and 6 ask you to prove theorems. The theorems must all be
successfully processed by ACL2.
Problem 5: Define a function compress that removes adjacent duplicates
in a list. That is, (compress '(x y y z 1 2 1 1 1 x)) should return
'(x y z 1 2 1 x). Define a function rev that reverses a list. Then
formalize and prove the following theorem:
(i) If you compress a list and then compress it again then you get the
same result as compressing the list once.
(ii) If you reverse a list and then compress it that is the same as
first compressing the list and then reversing it.
Problem 6: Formalize and prove the following identity. The sum of the
first n natural numbers (starting from 1) is the same as n(n+1)/2.
You may need to use arithmetic facts for proving the above. If you
need to, feel free to include one of the distributed arithmetic book.
One such book is arithmetic/top-with-meta. If you wish to include
that book you can do so with the command
(include-book "arithmetic/top-with-meta" :dir :system)