Documentation

PnP2023.Lec_01_20.NatMin

Minimum of a list of natural numbers #

Our next example is an algorithm to find the minimum of a non-empty list of natural numbers, with a proof of correctness. The proof of correctness consists of two statements about the algorithm: (1) the minimum is in the list, and (2) the minimum is less than or equal to each element in the list.

To avoid name collisions we will use the name smallest

def smallest (l : List ) :
l []

The smallest element in a non-empty list of natural numbers

Equations
Instances For

    An example

    #eval smallest [7, 8, 1,2,3,4,5] (by decide)
    
    theorem smallest_in_list (l : List ) (hyp : l []) :
    smallest l hyp l

    the result of smallest applied to a list is a member of that list

    def egNat :

    An example of using left and right tactics.

    Instances For
      theorem smallest_le (l : List ) (hyp : l []) (m : ) :
      m lsmallest l hyp m

      smallest is less than or equal to each element in the list