{"id":19357184,"url":"https://github.com/uds-psl/autosubst-ocaml","last_synced_at":"2025-04-23T10:33:14.988Z","repository":{"id":99562702,"uuid":"368416802","full_name":"uds-psl/autosubst-ocaml","owner":"uds-psl","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-31T13:12:13.000Z","size":4289,"stargazers_count":13,"open_issues_count":4,"forks_count":11,"subscribers_count":6,"default_branch":"coq-8.20","last_synced_at":"2025-04-02T14:21:32.477Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Coq","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/uds-psl.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}},"created_at":"2021-05-18T05:56:43.000Z","updated_at":"2024-10-31T06:01:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"e4ebe10f-b55c-4b38-9eac-94dee053f3c3","html_url":"https://github.com/uds-psl/autosubst-ocaml","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uds-psl%2Fautosubst-ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uds-psl%2Fautosubst-ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uds-psl%2Fautosubst-ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uds-psl%2Fautosubst-ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uds-psl","download_url":"https://codeload.github.com/uds-psl/autosubst-ocaml/tar.gz/refs/heads/coq-8.20","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250417018,"owners_count":21427117,"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":[],"created_at":"2024-11-10T07:06:34.487Z","updated_at":"2025-04-23T10:33:09.972Z","avatar_url":"https://github.com/uds-psl.png","language":"Coq","funding_links":[],"categories":["Projects","Recently Updated"],"sub_categories":["Tools","[Who Wants to Be a Millionare](https://www.boardgamecapital.com/who-wants-to-be-a-millionaire-rules.htm)"],"readme":"# Autosubst 2, OCaml implementation\n\n## Meta\n\n- Authors:\n  - Adrian Dapprich\n- Contributors:\n  - Andrej Dudenhefner\n  - Yannick Forster\n  - Meven Lennon-Bertrand\n  - Audrey Seo\n  - Chris Lam\n  - Ana Borges\n- Maintainer:\n  - Yannick Forster ([**@yforster**](https://github.com/yforster))\n- License: [MIT License](LICENSE)\n- Compatible Coq versions: 8.19.0\n- Related publication(s):\n  - Adrian Dapprich's [bachelor thesis](https://www.ps.uni-saarland.de/~dapprich/bachelor.php) (Advisor: Andrej Dudenhefner, Supervisor: Gert Smolka)\n\n## Description\n\nThis is an OCaml reimplementation of the [Autosubst 2 code generator](https://github.com/uds-psl/autosubst2) by Stark, Schäfer and Kaiser, which was the main focus of Stark's [doctoral dissertation](https://www.ps.uni-saarland.de/~kstark/thesis/). Autosubst 2 in turn is based on previous work on [Autosubst](https://github.com/coq-community/autosubst) by Schäfer, Tebbi and Smolka.\n\nIf you ever were in the situation of looking at metatheorems of languages modelled in Coq (e.g. progress and preservation of lambda calculi) and were bothered by the tediousness of formalizing substitution of de Bruijn indices again, this tool might be for you.\nAutosubst is a tool that allows you to quickly generate boilerplate code to handle substitutions in languages with binders.\n\nThe output is Coq source code that contains \n1. an implementation of the language via (mutual) inductive types and de Bruijn indices for variables,\n2. definitions for capture avoiding substitution and renaming on de Bruijn indices,\n3. lemmas about the behavior and interaction of renaming and substitution,\n4. and a tactic to solve assumption-free substitution equations.\n\nLike Autosubst 2, the OCaml reimplementation supports well-scoped \u0026 unscoped syntax as well as variadic \u0026 polyadic syntax \u0026 functors.\nIt does not support Autosubst 2's modular syntax.\nHowever, the lemmas generated by the OCaml implementation do not use functional extensionality.\n\nBeing implemented in OCaml, it uses Coq as a library to construct and pretty-print the code it generates.\n\nNote that there is also a [reimplementation of Autosubst 2 in the form of a MetaCoq plugin](https://github.com/uds-psl/autosubst-metacoq), but it has less features than the OCaml version.\n\n## Example\nFor a language like System F which we represent with a signature like the following\n```\nty : Type\ntm : Type\nvl : Type\n\narr : ty -\u003e ty -\u003e ty\nall : (bind ty in ty) -\u003e ty\n\napp  : tm -\u003e tm -\u003e tm\ntapp : tm -\u003e ty -\u003e tm\nvt   : vl -\u003e tm\n\nlam  : ty -\u003e (bind vl in tm) -\u003e vl\ntlam : (bind ty in tm) -\u003e vl\n```\n\nAutosubst Ocaml can generate inductive types without scopes to represent the language.\n```\nInductive ty : Type :=\n  | var_ty : nat -\u003e ty\n  | arr : ty -\u003e ty -\u003e ty\n  | all : ty -\u003e ty.\n\nInductive tm : Type :=\n  | app : tm -\u003e tm -\u003e tm\n  | tapp : tm -\u003e ty -\u003e tm\n  | vt : vl -\u003e tm\nwith vl : Type :=\n  | var_vl : nat -\u003e vl\n  | lam : ty -\u003e tm -\u003e vl\n  | tlam : tm -\u003e vl.\n```\n\nand also with scopes, which designate the upper bound of free variables in a term. Note the increased scope level in a `lam` or `tlam` constructor.\n```\nInductive ty (n_ty : nat) : Type :=\n  | var_ty : fin n_ty -\u003e ty n_ty\n  | arr : ty n_ty -\u003e ty n_ty -\u003e ty n_ty\n  | all : ty (S n_ty) -\u003e ty n_ty.\n\nInductive tm (n_ty n_vl : nat) : Type :=\n  | app : tm n_ty n_vl -\u003e tm n_ty n_vl -\u003e tm n_ty n_vl\n  | tapp : tm n_ty n_vl -\u003e ty n_ty -\u003e tm n_ty n_vl\n  | vt : vl n_ty n_vl -\u003e tm n_ty n_vl\nwith vl (n_ty n_vl : nat) : Type :=\n  | var_vl : fin n_vl -\u003e vl n_ty n_vl\n  | lam : ty n_ty -\u003e tm n_ty (S n_vl) -\u003e vl n_ty n_vl\n  | tlam : tm (S n_ty) n_vl -\u003e vl n_ty n_vl.\n```\n\nOptionally, users can control the name of the variable constructor using the syntax `ty(var_ty) : Type`.\n\nAdditionally, Autosubst generates a number of lemmas describing the behavior of substitutions of free variables and the composition of substitutions, e.g. that instantiation with extensionally equal substitutions yields the same term.\n\n```\nFixpoint ext_ty (sigma_ty : nat -\u003e ty) (tau_ty : nat -\u003e ty) (Eq_ty : forall x, sigma_ty x = tau_ty x) (s : ty) :\n    subst_ty sigma_ty s = subst_ty tau_ty s\n```\n\nFinally, it generates a tactic `asimpl` that uses these lemmas as a rewriting system to simplify and solve assumption free equations between terms containing substitutions, which often appear during proofs of metatheorems.\nFor example the following says that we can first substitute a term `t` for variable 0 and then substitute with `σ`, or do it the other way around (where we must also substitute `σ` in `t`).\n```\ns[t · id][σ] = s[⇑ σ][t[σ] · id]\n```\nFor more examples and an extended explanation as well as an explanation of the notation we refer to Adrian's bachelor thesis or Stark's doctoral dissertation linked above.\n\n## Setup\n### Opam \nFirst, install opam following the [directions for your operating system](https://opam.ocaml.org/doc/Install.html).\n\nIt is best practice to create a new opam switch to not cause conflicts with any of your other installed packages.\nWe will also need to add the Coq repository and then we can install the `coq-autosubst-ocaml` package.\n```bash\n$ opam switch create autosubst-ocaml ocaml-base-compiler.4.11.1\n$ eval $(opam env)\n$ opam repo add coq-released https://coq.inria.fr/opam/released\n$ opam install coq-autosubst-ocaml\n```\n\nThis installs the package along with all dependencies.\nAn implicit dependency is the [monad library by Denommus](https://github.com/Denommus/monadic) which is not on opam, so we include the sources in the repo.\n\n## Run\nIf you have installed the program, you can use `autosubst` in the following. Otherwise you can also follow the drections in the \"Build \u0026 Run\" section below.\n\nTo display the help, use\n```bash\n$ autosubst --help\n```\n\nEn example invocation that shows how to generate code for the untyped lambda calculus.\n```bash\n$ autosubst signatures/utlc.sig -o output/utlc.v -s ucoq\n```\n\n### Signatures\nYou specify the input language using our input syntax.\nThe syntax is described in my thesis at https://www.ps.uni-saarland.de/~dapprich/bachelor.php\nExample signature files are in the ./signatures directory.\n\nThe following example contains all possible rules.\n```\n-- comments are like in Haskell\ntm(var_tm) : Type -- sort declarations\nnat : Type -- preexisting sort declaration, it must not have any constructors\n\nlist : Functor -- functor declarations, only \"list\", \"prod\", \"cod\" and \"option\" are allowed\n\n-- declaring some constructors for ty\narr : ty -\u003e ty -\u003e ty\nall : (bind ty in ty) -\u003e ty -- this declares \"all\" as constructor with a binder that binds a new \"ty\" variable in a \"ty\" argument and results in a \"ty\"\n-- declaring some constructos for tm\napp : tm -\u003e list (tm) -\u003e tm               -- application of the list functor to the sort \"tm\"\nlam (p: nat) : (bind \u003cp, tm\u003e in tm) -\u003e tm -- this declares \"lam\" as a constructor with parameter \"p\" which is then used in a variadic binder (i.e. it binds p-many values of \"tm\")\npair : tm -\u003e (bind tm in \"option\" (tm)) -\u003e tm -\u003e tm -\u003e tm -- string syntax to include arbitrary functors\nconst : nat -\u003e tm\n```\n\n## Development\n### Dev Dependencies\nSome dependencies for developing in emacs.\n```bash\n$ opam install merlin utop ocp-indent ocamlformat\n$ opam user-setup install\n```\n\n### Build \u0026 Run\nCreate the switch, install the dependencies, and then:\n```bash\n$ dune build\n$ dune exec -- bin/main.exe --help\n# e.g. to generate code for the untyped lambda calculus\n$ dune exec -- bin/main.exe signatures/utlc.sig -o output/utlc.v -s ucoq\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuds-psl%2Fautosubst-ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuds-psl%2Fautosubst-ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuds-psl%2Fautosubst-ocaml/lists"}