Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidfstr/idris-insertion-sort
Provably correct implementation of insertion sort in Idris.
https://github.com/davidfstr/idris-insertion-sort
idris insertion-sort proof
Last synced: about 1 month ago
JSON representation
Provably correct implementation of insertion sort in Idris.
- Host: GitHub
- URL: https://github.com/davidfstr/idris-insertion-sort
- Owner: davidfstr
- License: mit
- Created: 2015-03-07T02:45:53.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-04-23T14:00:26.000Z (over 3 years ago)
- Last Synced: 2024-04-16T02:16:31.590Z (8 months ago)
- Topics: idris, insertion-sort, proof
- Language: Idris
- Size: 5.86 KB
- Stars: 28
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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