{"id":51233561,"url":"https://github.com/joom/edit-distance","last_synced_at":"2026-06-28T18:30:45.279Z","repository":{"id":361602969,"uuid":"171542902","full_name":"joom/edit-distance","owner":"joom","description":"Verifying edit distance properties in Rocq.","archived":false,"fork":false,"pushed_at":"2026-05-31T11:53:54.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-31T13:19:46.803Z","etag":null,"topics":["c-verification","edit-distance","levenshtein-distance","rocq-prover","vst"],"latest_commit_sha":null,"homepage":"","language":"Rocq Prover","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-19T20:17:03.000Z","updated_at":"2026-05-31T11:53:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/joom/edit-distance","commit_stats":null,"previous_names":["joom/edit-distance"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/joom/edit-distance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fedit-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fedit-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fedit-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fedit-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joom","download_url":"https://codeload.github.com/joom/edit-distance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fedit-distance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34900367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-verification","edit-distance","levenshtein-distance","rocq-prover","vst"],"created_at":"2026-06-28T18:30:45.211Z","updated_at":"2026-06-28T18:30:45.274Z","avatar_url":"https://github.com/joom.png","language":"Rocq Prover","funding_links":[],"categories":[],"sub_categories":[],"readme":"# edit-distance\n\nFormal verification of the Levenshtein (edit) distance in [Rocq](https://rocq-prover.org/),\nincluding a proof that a C implementation refines a verified functional model using the\n[Verified Software Toolchain](http://vst.cs.princeton.edu/) (VST).\n\nThe development is structured in three layers, each proved equivalent to the next:\n\n1. an **intrinsically-correct recursive** model, whose dependently-typed definition\n   carries its own optimality proof;\n2. a **dynamic-programming** model in the Wagner–Fischer style, proved to compute\n   the same value as the recursive model; and\n3. a **C implementation** (`levenshtein.c`), proved with VST to refine the\n   dynamic-programming model.\n\n## What Is Proved\n\n### Recursive model\n\n`theories/Levenshtein_recursive.v` defines edit scripts as indexed Rocq types:\n\n- `edit s t` is one insertion, deletion, or non-equal-character update from\n  `s` to `t`.\n- `chain s t n` is an edit script from `s` to `t` with exactly `n` charged\n  edits; equal heads are skipped at no cost.\n- `levenshtein_chain s t` computes both a distance and a witness edit script.\n- `levenshtein_recursive s t` is the numeric distance extracted from that\n  witness.\n\nThe main theorem, `levenshtein_recursive_is_minimal`, proves that the computed\ndistance is minimal: for every edit script `chain s t n`,\n`levenshtein_recursive s t \u003c= n`.  Since `levenshtein_chain` also returns a\nwitness script with exactly that distance, the recursive model computes the true\nLevenshtein distance.\n\n### Dynamic-programming model\n\n`theories/Levenshtein_dp.v` defines `levenshtein_dp`, a Wagner-Fischer-style\ndynamic-programming implementation over Rocq strings.  It also contains\nindex-based cache and loop-state lemmas used by the C proof.\n\nThe main theorem, `levenshtein_dp_eq_levenshtein_recursive`, proves that for all\nstrings `s` and `t`, `levenshtein_dp s t = levenshtein_recursive s t`.  The DP\nproof first shows that the left-to-right cache traversal computes the recursive\nmodel on reversed inputs, then uses reversal invariance of the recursive\ndistance to remove the reversals.\n\n### C implementation\n\n`theories/Verif_levenshtein.v` proves the generated Clight body of `levenshtein_n`\nagainst a VST function specification.  The specification interprets the input\nbyte arrays as Rocq strings with `bytes_to_string`, requires the usual pointer\nand `size_t` bounds, and states that the returned `size_t` is exactly:\n\n```coq\nLevenshtein.levenshtein_recursive\n  (bytes_to_string a)\n  (bytes_to_string b)\n```\n\nThe proof connects the C loops to the DP cache model, then uses\n`levenshtein_dp_eq_levenshtein_recursive` to conclude that the C result is the\nintrinsic Levenshtein distance.\n\n## Files\n\n| File | Description |\n| --- | --- |\n| `theories/Levenshtein_recursive.v` | Intrinsic edit-script model and proof that `levenshtein_recursive` is minimal among all edit scripts. |\n| `theories/Levenshtein_dp.v` | Wagner-Fischer dynamic-programming model `levenshtein_dp`, proved equal to `levenshtein_recursive`. |\n| `levenshtein.c` | The C implementation that is verified. |\n| `theories/levenshtein.v` | CompCert Clight AST generated from `levenshtein.c` (via `clightgen`). |\n| `theories/Verif_levenshtein.v` | VST proof that `levenshtein_n` returns the intrinsic recursive distance for the input byte arrays. |\n\nAll `.v` files live under `theories/` and form the Coq theory `EditDistance`,\nso modules are referenced as `EditDistance.Levenshtein_dp`, etc.\n\n## Requirements\n\n- Rocq / `coq-core` ≥ 9.0\n- [VST](https://vst.cs.princeton.edu/) ≥ 2.16 (which bundles CompCert and Flocq)\n- dune ≥ 3.21\n\nThese can be installed with opam:\n\n```sh\nopam install dune coq-vst\n```\n\n## Building\n\nThe project is built with [dune](https://dune.build/); the `Makefile` is a thin\nfrontend to it.\n\n```sh\nmake          # dune build\nmake clean    # dune clean + git clean\nmake install  # dune install\n```\n\nEquivalently, run `dune build` directly. Build artifacts go under `_build/`.\n\n## Regenerating the Clight AST\n\n`theories/levenshtein.v` is generated from `levenshtein.c` and should not be edited by hand:\n\n```sh\nclightgen -normalize -o theories/levenshtein.v levenshtein.c\n```\n\n## Credit\n\nThis proof development was carried out with assistance from Claude and Codex. The [minimality proof](https://github.com/bloomberg/crane/pull/17) and the [dynamic programming implementation and proof](https://github.com/bloomberg/crane/pull/25) was done by [Charles C. Norton](https://github.com/CharlesCNorton).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoom%2Fedit-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoom%2Fedit-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoom%2Fedit-distance/lists"}