{"id":16310814,"url":"https://github.com/pi8027/stablesort","last_synced_at":"2025-03-16T14:30:46.764Z","repository":{"id":43468158,"uuid":"350921474","full_name":"pi8027/stablesort","owner":"pi8027","description":"Stable sort algorithms and their stability proofs in Coq","archived":false,"fork":false,"pushed_at":"2025-02-25T17:03:18.000Z","size":5458,"stargazers_count":22,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T10:09:38.511Z","etag":null,"topics":["coq","insertion-sort","mathcomp","mergesort","sorting-algorithms","ssreflect"],"latest_commit_sha":null,"homepage":"https://doi.org/10.48550/arXiv.2403.08173","language":"Coq","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pi8027.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-24T02:28:19.000Z","updated_at":"2025-02-25T17:03:22.000Z","dependencies_parsed_at":"2024-02-17T17:29:46.902Z","dependency_job_id":"f6ac4015-0b76-43b8-86aa-6061e768c950","html_url":"https://github.com/pi8027/stablesort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pi8027%2Fstablesort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pi8027%2Fstablesort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pi8027%2Fstablesort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pi8027%2Fstablesort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pi8027","download_url":"https://codeload.github.com/pi8027/stablesort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818192,"owners_count":20352629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coq","insertion-sort","mathcomp","mergesort","sorting-algorithms","ssreflect"],"created_at":"2024-10-10T21:42:59.052Z","updated_at":"2025-03-16T14:30:46.405Z","avatar_url":"https://github.com/pi8027.png","language":"Coq","funding_links":[],"categories":["Projects"],"sub_categories":["Verified Software"],"readme":"\u003c!---\nThis file was generated from `meta.yml`, please do not edit manually.\nFollow the instructions on https://github.com/coq-community/templates to regenerate.\n---\u003e\n# Stable sort algorithms in Coq\n\n[![Docker CI][docker-action-shield]][docker-action-link]\n\n[docker-action-shield]: https://github.com/pi8027/stablesort/actions/workflows/docker-action.yml/badge.svg?branch=master\n[docker-action-link]: https://github.com/pi8027/stablesort/actions/workflows/docker-action.yml\n\n\n\n\nThis library provides a generic and modular way to prove the correctness,\nincluding stability, of several mergesort functions. The correctness lemmas in\nthis library are overloaded using a canonical structure\n(`StableSort.function`). This structure characterizes stable mergesort\nfunctions, say `sort`, by its abstract version `asort` parameterized over the\ntype of sorted lists and its operators such as merge, the relational\nparametricity of `asort`, and two equational properties that `asort`\ninstantiated with merge and concatenation are `sort` and the identity\nfunction, respectively, which intuitively mean that replacing merge with\nconcatenation turns `sort` into the identity function.\nFrom this characterization, we derive an induction principle over\ntraces—binary trees reflecting the underlying divide-and-conquer structure of\nmergesort—to reason about the relation between the input and output of\n`sort`, and the naturality of `sort`. These two properties are sufficient to\ndeduce several correctness results of mergesort, including stability. Thus,\none may prove the stability of a new sorting function by defining its abstract\nversion, proving the relational parametricity of the latter using the\nparametricity translation (the Paramcoq plugin), and manually providing the\nequational properties.\n\nAs an application of the above proof methodology, this library provides two\nkinds of optimized mergesorts.\nThe first kind is non-tail-recursive mergesort. In call-by-need evaluation,\nthey allow us to compute the first k smallest elements of a list of length n\nin the optimal O(n + k log k) time complexity of the partial and incremental\nsorting problems. However, the non-tail-recursive merge function linearly\nconsumes the call stack and triggers a stack overflow in call-by-value\nevaluation.\nThe second kind is tail-recursive mergesorts and thus solves the above issue\nin call-by-value evaluation. However, it does not allow us to compute the\noutput incrementally regardless of the evaluation strategy.\nTherefore, there is a performance trade-off between non-tail-recursive and\ntail-recursive mergesorts, and the best mergesort function for lists depends\non the situation, in particular, the evaluation strategy and whether it should\nbe incremental or not.\nIn addition, each of the above two kinds of mergesort functions has a smooth\n(also called natural) variant of mergesort, which takes advantage of sorted\nslices in the input.\n\n## Meta\n\n- Author(s):\n  - Kazuhiko Sakaguchi (initial)\n  - Cyril Cohen\n- License: [CeCILL-B Free Software License Agreement](CeCILL-B)\n- Compatible Coq versions: 8.13 or later\n- Additional dependencies:\n  - [MathComp](https://math-comp.github.io) 1.13.0 or later\n  - [Paramcoq](https://github.com/coq-community/paramcoq) 1.1.3 or later\n  - [Mczify](https://github.com/math-comp/mczify) (required only for the test suite)\n  - [Equations](https://github.com/mattam82/Coq-Equations) (required only for the test suite)\n- Coq namespace: `stablesort`\n- Related publication(s):\n  - [A bargain for mergesorts (functional pearl) — How to prove your mergesort correct and stable, almost for free](https://arxiv.org/abs/2403.08173) doi:[10.48550/arXiv.2403.08173](https://doi.org/10.48550/arXiv.2403.08173)\n\n## Building and installation instructions\nThe easiest way to install the development version of Stable sort algorithms in Coq\nis via [OPAM](https://opam.ocaml.org/doc/Install.html):\n``` shell\ngit clone https://github.com/pi8027/stablesort.git\ncd stablesort\nopam repo add coq-released https://coq.inria.fr/opam/released\nopam install ./coq-stablesort.opam\n```\n\n## Credits\nThe mergesort functions and the stability proofs provided in this library are\nmostly based on ones in the `path` library of Mathematical Components.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpi8027%2Fstablesort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpi8027%2Fstablesort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpi8027%2Fstablesort/lists"}