I'm not a user of SPARK. I'm just trying to understand the capabilities of the language.
Can SPARK be used to prove, for example, that Quicksort actually sorts the array given to it?
(Would love to see an example, assuming this is simple)
I'm not a user of SPARK. I'm just trying to understand the capabilities of the language.
Can SPARK be used to prove, for example, that Quicksort actually sorts the array given to it?
(Would love to see an example, assuming this is simple)
Copyright © 2021 Jogjafile Inc.
Yes, it can, though I'm not particularly good at SPARK-proving (yet). Here's how quick-sort works:
0or1in length, then you are sorted; if2then check and possibly-correct the ordering and they are sorted; otherwise continue on.Less– Swap with the first item in theGreaterpartition.Greater– Null-op.Equal— Swap with the first item ofLess, the swap with the first item ofGreater.Less&Greaterpartitions.Less&Equal&Greater, if a procedure re-arrange thein outinput to that ordering.Here's how you would go about doing things:
0and1cases as true,2items,(L,E,G)which are the count of the elements less-than/equal-to/greater-than the pivot [this is probably a ghost-subprogram],L+E+Gequals the length of your collection,(L,E,G)tuple, the output conforms toLitems less-than the pivot followed byEitems which are equal, and thenGitems that are greater.And that should do it. [IIUC]