Assignment 3

For your final project you can choose between three problems/algorithms:
  1. Mergesort
  2. Quicksort
  3. List permutations
In the first two you have to prove correctness of the sorting algorithm. The latter is a combinatorial problem. In all three problems you don't have to write any code. Moreover, if you follow the line of proof we had in mind, you will probably need no additional lemmas.

Instructions:

Copy PVS source files into your working directory.
  1. For Mergesort these are: ms.pvs, ms.prf, sorting.pvs and sorting.prf.
  2. For Quicksort: qs.pvs, qs.prf, sorting.pvs and sorting.prf.
  3. For List Permuations: perm.pvs and perm.prf.

Some explanations

The sorting algorithms share the file sorting.pvs containing specifications of basic notions and properties such as list permutation, sorted lists etc. There is also an induction principle called list_length_induction that can be used to prove properties about the quicksort function itself. All pvs-specifications are split up into several theories containing definitions that more or less belong together. It should not be hard to figure out what each of these theories is supposed to cover. The prepared project on permutations consists of a single pvs-file perm.pvs. In this file, the theory Perm contains a function perm that, when applied to a list, generates all permuations of that list. Herein, the auxiliary funtion insert is used that inserts an element in a list at all possible positions.

What to do?

  • Mergesort

    The main task is to prove the main theorem about mergesort ms_sorted. As warming up, you could start with proving the lemmas drop_take and nth_append. The first lemma is a straightforward property about the list functions drop and take; the second lemma is about the combination of the functions nth and append. Thereafter, your task will get more challenging: prove lemma merge_sorted. This lemma is indispensable for your main theorem. Although the property itself is quite straightformward, the proof is pretty complicated because it involves many non-trivial steps. After finishing this lemma, the main goal should be a piece of cake.

  • Quicksort

    The main task is to prove the main theorem about quicksort qs_sorted. As warming up, you could start with proving the lemma nth_append: a straightforward property about the combination of the functions nth and append. Then you should try the lemmas sorted_append and split_lwb_upb. Finally, try to prove the main goal.

  • List Permutations

    The main task is to prove that the number of permuations of a list with length n is n! (factorial of n) (lemma perm_fac). As a warming up, you could start with with proving the lemmas map_flatten, map_all and insert_sameLength. To prepare for the main goal, prove lemma perm_length. Think about what this lemma implies, and how you can use it in your final proof. Finally, prove perm_fac

    Notes and Hints: