Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Provably correct implementation of insertion sort in Idris.

License

NotificationsYou must be signed in to change notification settings

davidfstr/idris-insertion-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. anIsSorted proof that the output list is sorted, and
  3. anElemsAreSame proof that the input list and output lists containthe same elements.

This program makes heavy use of proof terms, a special facility only availablein 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 runidris -o InsertionSort InsertionSort.idr./InsertionSortPlease type a space-separated list of integers: 3 2 1After sorting, the integers are: 1 2 3

See the Proof Term!

Another way to run the program is to run it directly using the Idrisinterpreter. The advantage here is that you can see not just the resultingsorted 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

About

Provably correct implementation of insertion sort in Idris.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp