GitXplorerGitXplorer
d

idris-insertion-sort

public
28 stars
4 forks
0 issues

Commits

List of commits on branch master.
Unverified
26b427a6d45b2e47ece48e89c7133ec23ef4f7b0

Add license.

ddavidfstr committed 4 years ago
Verified
bf1c39a8eb4cdbd6d6b8d9fda8797703c2082e4c

README: Revise recommended Idris version.

ddavidfstr committed 6 years ago
Unverified
30d8a0bb4a787f70f1dac76c1c3ab037cd7ec9f4

Update to compile under Idris v1

WWalkerCodeRanger committed 6 years ago
Unverified
136cb0f53b7dbc705e59e1ea1cb579cbd9e169e5

README: Explain how to see the proof term.

ddavidfstr committed 10 years ago
Unverified
88719f8347bf33a77cbe771913c055c9def8881c

Add (lack of) license.

ddavidfstr committed 10 years ago
Unverified
879b6a12e094e8c885512ba0bfc007bc43c2cd2c

Initial release.

ddavidfstr committed 10 years ago

README

The README file for this repository.

idris-insertion-sort

This is a provably correct implementation of insertion sort in Idris.

Specifically, it is an implementation of the following function definition:

insertionSort :
    Ord e =>
    (xs:Vect n e) ->
    (xs':Vect n e ** (IsSorted xs', ElemsAreSame xs xs'))

Given a list of elements, this function will return:

  1. an output list,
  2. an IsSorted proof that the output list is sorted, and
  3. an ElemsAreSame proof that the input list and output lists contain the same elements.

This program makes heavy use of proof terms, a special facility only available in dependently-typed programming languages like Idris.

Prerequisites

  • Idris 1.3.1 or later
    • Probably any Idris 1.x will work.
  • Make

How to Run

make run

Example Output

$ make run
idris -o InsertionSort InsertionSort.idr
./InsertionSort
Please type a space-separated list of integers: 
3 2 1
After sorting, the integers are: 
1 2 3

See the Proof Term!

Another way to run the program is to run it directly using the Idris interpreter. The advantage here is that you can see not just the resulting sorted output list but also the resulting proof terms of the algorithm.

$ idris --nobanner InsertionSort.idr
*InsertionSort> insertionSort [2,1]
MkSigma [1, 2]
        (IsSortedMany 1 2 [] Oh (IsSortedOne 2),
         SamenessIsTransitive (PrependXIsPrependX 2
                                                  (SamenessIsTransitive (PrependXIsPrependX 1
                                                                                            NilIsNil)
                                                                        (PrependXIsPrependX 1
                                                                                            NilIsNil)))
                              (PrependXYIsPrependYX 2
                                                    1
                                                    NilIsNil)) : Sigma (Vect 2
                                                                             Integer)
                                                                       (\xs' =>
                                                                          (IsSorted xs',
                                                                           ElemsAreSame [2,
                                                                                         1]
                                                                                        xs'))

License

Copyright (c) 2015 by David Foster