{"id":14966223,"url":"https://github.com/deducteam/hol2dk","last_synced_at":"2025-06-16T21:38:38.575Z","repository":{"id":100768830,"uuid":"605449199","full_name":"Deducteam/hol2dk","owner":"Deducteam","description":"HOL-Light to Dedukti/Lambdapi translator","archived":false,"fork":false,"pushed_at":"2025-03-12T16:47:51.000Z","size":633,"stargazers_count":6,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-04T00:06:59.435Z","etag":null,"topics":["coq","dedukti","hol-light","lambdapi","proof","translation"],"latest_commit_sha":null,"homepage":"","language":"Coq","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Deducteam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-23T07:11:54.000Z","updated_at":"2025-03-12T16:47:57.000Z","dependencies_parsed_at":"2024-02-14T21:33:26.868Z","dependency_job_id":"87fd81a1-f34b-4ead-8aaf-52de4e1938ec","html_url":"https://github.com/Deducteam/hol2dk","commit_stats":{"total_commits":177,"total_committers":4,"mean_commits":44.25,"dds":"0.29378531073446323","last_synced_commit":"f494e0d29eca7a8ad33fc34f5ac9755165b661f5"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Deducteam/hol2dk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deducteam%2Fhol2dk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deducteam%2Fhol2dk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deducteam%2Fhol2dk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deducteam%2Fhol2dk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Deducteam","download_url":"https://codeload.github.com/Deducteam/hol2dk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deducteam%2Fhol2dk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260246245,"owners_count":22980363,"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","dedukti","hol-light","lambdapi","proof","translation"],"created_at":"2024-09-24T13:36:02.197Z","updated_at":"2025-06-16T21:38:38.559Z","avatar_url":"https://github.com/Deducteam.png","language":"Coq","readme":"Export HOL-Light proofs to Dedukti, Lambdapi and Coq\n====================================================\n\nThis project provides a tool, hol2dk, to translate [HOL-Light](https://github.com/jrh13/hol-light) proofs to [Dedukti](https://github.com/Deducteam/Dedukti/), [Lambdapi](https://github.com/Deducteam/lambdapi) and [Coq](https://coq.inria.fr/).\n\n[HOL-Light](https://github.com/jrh13/hol-light) is a proof assistant\nbased on higher-order logic, aka simple type theory.\n\n[Dedukti](https://github.com/Deducteam/Dedukti/) is a proof format\nbased on the λΠ-calculus modulo rewriting (λ-calculus + simple types +\ndependent types + implicit type equivalence modulo user-defined\nrewriting rules).\n\n[Lambdapi](https://github.com/Deducteam/lambdapi) is a proof assistant\nbased on the λΠ-calculus modulo rewriting that can read and generate\nDedukti proofs.\n\n[Coq](https://coq.inria.fr/) is a proof assistant based on the\nCalculus of Inductive Constructions.\n\nUsability of translated libraries\n---------------------------------\n\nFor the obtained theorems to be readily usable in Coq, we need to\nalign the type and functions of HOL-Light with those used in the Coq\nstandard library. We already did this for various types and functions\n(see [With_N.lp](https://github.com/Deducteam/hol2dk/blob/main/With_N.lp)):\n\n- types: unit, prod, list, option, sum, ascii, N, R, Z\n- functions on N: pred, add, mul, pow, le, lt, ge, gt, max, min, sub, div, modulo\n- functions on list: app, rev, map, removelast, In, hd, tl\n- functions on R: Rle, Rplus, Rmult, Rinv, Ropp, Rabs, Rdiv, Rminus, Rge, Rgt, Rlt, Rmax, Rmin, IZR\n\nYour help is welcome to align more functions!\n\nThe correctness of the mappings for types defined before real\nnumbers (e.g. natural numbers and lists) is proved in\n[mappings_N.v](https://github.com/Deducteam/hol2dk/blob/main/mappings_N.v). The\ncorrectness of the mappings for the other types, including real\nnumbers, is proved here in\n[With_N.v](https://github.com/Deducteam/hol2dk/blob/main/With_N.v).\n\nThe resulting theorems are gathered in the Opam package\n[coq-hol-light](https://github.com/Deducteam/coq-hol-light) available\nin the Coq Opam repository [released](https://github.com/coq/opam). It\ncurrently contains a translation of the\n[Multivariate](https://github.com/jrh13/hol-light/blob/master/Multivariate/make_complex.ml)\nlibrary with more than 20,000 theorems on arithmetic, wellfounded\nrelations, lists, real numbers, integers, basic set theory,\npermutations, group theory, matroids, metric spaces, homology,\nvectors, determinants, topology, convex sets and functions, paths,\npolytopes, Brouwer degree, derivatives, Clifford algebra, integration,\nmeasure theory, complex numbers and analysis, transcendental numbers,\nreal analysis, complex line integrals, etc.\n\nCoq axioms used to encode HOL-Light proofs\n------------------------------------------\n\nHOL-Light is based on classical higher-order logic with functional and propositional extensionality. We use the following Coq axioms to encode them:\n```\nAxiom classic : forall P:Prop, P \\/ ~ P.\nAxiom constructive_indefinite_description : forall (A : Type) (P : A-\u003eProp), (exists x, P x) -\u003e { x : A | P x }.\nAxiom fun_ext : forall {A B : Type} {f g : A -\u003e B}, (forall x, (f x) = (g x)) -\u003e f = g.\nAxiom prop_ext : forall {P Q : Prop}, (P -\u003e Q) -\u003e (Q -\u003e P) -\u003e P = Q.\nAxiom proof_irrelevance : forall (P:Prop) (p1 p2:P), p1 = p2.\n```\n\nBibliography\n------------\n\n- [Translating HOL-Light proofs to Coq](https://files.inria.fr/blanqui/lpar24.pdf), Frédéric Blanqui, 4 April 2024\n\nInstalling HOL-Light sources\n----------------------------\n\n**Requirement:** hol_light \u003e= 3.0.0\n\n```\ngit clone https://github.com/jrh13/hol-light\nmake -C hol-light\n```\n\nInstalling hol2dk\n-----------------\n\n**Requirements:**\n- ocaml \u003e= 4.13\n- dune \u003e= 3.7\n\nhol2dk is available on [Opam](https://opam.ocaml.org/). To install it, simply do:\n```\nopam install hol2dk\n```\n\nYou can also install hol2dk from its sources as follows:\n```\ngit clone https://github.com/Deducteam/hol2dk.git\ncd hol2dk\ndune build \u0026\u0026 dune install\n```\n\nSetting the environment variables `$HOLLIGHT_DIR` and `$HOL2DK_DIR`\n----------------------------------------------------------------------\n\nFor some commands to have access to files in hol2dk sources, you need\nto set the following environment variables:\n```\nexport HOLLIGHT_DIR=   # absolute path to hol-light source directory\nexport HOL2DK_DIR=     # absolute path to hol2dk source directory\n```\n\nIn case you installed hol2dk using opam, write:\n```\nexport HOL2DK_DIR=$OPAM_SWITCH_PREFIX/share/hol2dk\n```\n\nSummary of hol2dk commands\n--------------------------\n\nGet it by running `hol2dk | less`.\n\nPatching HOL-Light sources\n--------------------------\n\nBy default, HOL-Light does not generate proofs that can be checked independently. Therefore, it must be patched so that proof steps are recorded:\n\n```\nhol2dk patch\n```\n\nThis command slightly modifies a few HOL-Light files in order to dump proofs:\n- `fusion.ml`: the HOL-Light kernel file defining types, terms, theorems, proofs and proof rules\n- `bool.ml`: HOL-Light file defining basic tactics corresponding to introduction and elimination rules of connectives\n- `equal.ml`: HOL-Light file defining basic tactics on equality\n\nThe patch also adds a file `xnames.ml`.\n\nBefore applying the patch, a copy of these files is created in `fusion-bak.ml`, `bool-bak.ml`, etc.\n\nTo restore HOL-Light files, simply do:\n```\nhol2dk unpatch\n```\n\nDumping HOL-Light proofs\n------------------------\n\nFor dumping the proofs of a HOL-Light file depending on `hol.ml` do:\n```\ncd $HOLLIGHT_DIR\nhol2dk dump-simp [$path/]file.ml\n```\n\nThis will generate the following files:\n- `[$path/]file.sig`: constants\n- `[$path/]file.prf`: theorems (proof steps)\n- `[$path/]file.thm`: named theorems\n- `[$path/]file.pos`: positions of proof steps in `file.prf`\n- `[$path/]file.use`: data about the use of theorems\n\nWARNING: it is important to run the command in `$HOLLIGHT_DIR` so as to compute the list of named theorems properly.\n\nFor dumping (a subset of) `hol.ml` do:\n```\ncd $HOLLIGHT_DIR\nhol2dk dump-simp-before-hol file.ml\n```\nwhere `file.ml` should at least contain the contents of `hol.ml` until the line `loads \"fusion.ml\";;`.\n\nThe command `dump-simp` (and similarly for `dump-simp-before-hol`) are actually the sequential composition of various lower level commands: `dump`, `pos`, `use`, `rewrite` and `purge`:\n\n**Simplifying dumped proofs.** HOL-Light proofs have many detours that can be simplified following simple rewrite rules. For instance, s(u)=s(u) is sometimes proved by MK_COMB from s=s and u=u, while it can be directly proved by REFL.\n\nThe command `rewrite` implements the following simplification rules:\n- SYM(REFL(t)) ⟶ REFL(t)\n- SYM(SYM(p)) ⟶ p\n- TRANS(REFL(t),p) ⟶ p\n- TRANS(p,REFL(t)) ⟶ p\n- CONJUNCT1(CONJ(p,_)) ⟶ p\n- CONJUNCT2(CONJ(_,p)) ⟶ p\n- MKCOMB(REFL(t),REFL(u)) ⟶ REFL(t(u))\n- EQMP(REFL _,p) ⟶ p\n\n**Purging dumped proofs.** Because HOL-Light tactics may fail, some theorems are generated but not used in the end, especially after simplification. Therefore, they do not need to be translated.\n\nThe command `purge` compute in `file.use` all the theorems that do not need to be translated. For instance, in the HOL-Light base library `hol.ml`, 60% of proof steps are useless after simplication.\n\nThe command `simp` is the sequential composition of `rewrite` and `purge`.\n\nTranslating HOL-Light proofs to Lambdapi and Coq\n------------------------------------------------\n\n**Requirements:**\n- lambdapi commit \u003e= 21ee7f3d (21/01/25)\n- coq \u003e= 8.19\n- [coq-hol-light-real-with-N](https://github.com/Deducteam/coq-hol-light-real-with-N)\n- [coq-fourcolor-reals](https://github.com/coq-community/fourcolor/blob/master/coq-fourcolor-reals.opam)\n\n**Procedure after dumping:**\n\n- create a directory where all files will be generated:\n```\nmkdir output\n```\n\n- configure the directory with all the required files:\n```\ncd output\nhol2dk config $hollight_file.ml $root_path [coq_file_or_module] ... [$mapping.mk] [$mapping.lp]\n```\nDo `hol2dk config` to get more details.\n\nFor instance, to translate the Multivariate library using the Coq type N for natural numbers, we use [CONFIG](https://github.com/Deducteam/coq-hol-light/blob/main/CONFIG).\n\n- You can then do in order:\n  * `make` to get the list of targets and variables\n  * `make split` to generate a file for each theorem\n  * `make -j$jobs lp` to translate HOL-Light proofs to Lambdapi\n  * `make -j$jobs lpo` to check Lambdapi files (optional)\n  * `make -j$jobs v` to translate Lambdapi files to Coq files\n  * `make -j$jobs spec` to merge all small spec files into a single one\n  * `make -j$jobs rm-empty-deps` to remove `theory_hol.v`, `${base}_types.v` and `${base}_axioms.v` (to use when these files are empty only)\n  * `make -j$jobs vo` to check Coq files\n\nTo speed up lp file generation for some theorems with very big proofs, you can write in a file named `BIG_FILES` a list of theorem names (lines starting with `#` are ignored). See for instance [BIG_FILES](https://github.com/Deducteam/hol2dk/blob/main/BIG_FILES). You can also change the default values of the options `--max-proof-size` and `--max-abbrev-size` as follows:\n- `make -j$jobs MAX_PROOF=500_000 MAX_ABBREV=2_000_000 lp`\n\n**Remark:** for the checking of generated Coq files to not fail because of lack of RAM, we generate for each theorem `${thm}.lp` one or several files for its proof, and a file `${thm}_spec.lp` declaring this theorem as an axiom. Moreover, each other theorem proof using `${thm}` requires `${thm}_spec` instead of `${thm}`.\n\nPerformances\n------------\n\nOn a machine with 32 processors i9-13950HX, 128 Gb RAM, Hol2dk master, HOL-Light 3.0.0, OCaml 5.2.1, Camlp5 8.03.01, Lambdapi 83cf0be2, Coq 8.20.0, using the Coq type N for HOL-Light natural numbers:\n\n| HOL-Light file               | dump  | size   | steps | thms  | lp  | v   | size  | vo (*) |\n|------------------------------|-------|--------|-------|-------|-----|-----|-------|--------|\n| hol.ml                       | 4m    | 3 Gb   | 3 M   | 5687  | 40s | 37s | 1 Gb  | 10m23s |\n| Multivariate/make_complex.ml | 2h30m | 135 Gb | 85 M  | 40728 | 45m | 24m | 91 Gb | 21h14m |\n\nusing `make -j32 lp`, `make -j32 v`, `make -j32 merge-spec-files; make -j32 rm-empty-deps; make -j32 -k v`.\n\nTranslating HOL-Light proofs to Dedukti\n---------------------------------------\n\n**Requirement:** dedukti 2.7\n\nThe Makefile commands above are not implemented for Dedukti yet. It is however possible to translate HOL-Light proofs to Dedukti in parallel by using the following older and less efficient commands:\n\n```\nhol2dk mk $nb_parts $base\nmake -f $base.mk -j$jobs dk\n```\nwhere `$base` is the base name of the library, e.g. `make` for `$HOLLIGHT_DIR/Logic/make`, which is also written in the file named `BASE` that is created when you do `hol2dk link Logic/make`.\n\nIt generates a single big Dedukti file `$base.dk`. To check it with [dkcheck](https://github.com/Deducteam/Dedukti/) version \u003e= 2.7, simply do:\n```\ndk check $base.dk\n```\nTo check it with [kocheck](https://github.com/01mf02/kontroli-rs), simply do:\n```\nkocheck -j$jobs file-for-kocheck.dk\n```\n\nPerformances: hol.dk can be checked by dkcheck in 4m11s.\n\nGetting statistics on proofs\n----------------------------\n\nIt is possible to get statistics on proofs by using the command `stat`. For instance, for `hol.ml`, after simplification, we get:\n\n| rule       |  % |\n|:-----------|---:|\n| comb       | 20 |\n| term_subst | 17 |\n| refl       | 16 |\n| eqmp       | 12 |\n| trans      |  9 |\n| conjunct1  |  6 |\n| abs        |  3 |\n| beta       |  3 |\n| mp         |  3 |\n| sym        |  2 |\n| deduct     |  2 |\n| type_subst |  2 |\n| assume     |  1 |\n| conjunct2  |  1 |\n| disch      |  1 |\n| spec       |  1 |\n| disj_cases |  1 |\n| conj       |  1 |\n\nExporting pure Q0 proofs\n------------------------\n\nHol2dk instruments basic HOL-Light tactics corresponding to\nintroduction and elimination rules of connectives to get smaller\nproofs and proofs closer to natural deduction proofs. It is however\npossible to generate full Q0 proofs by doing after patching:\n\n```\ncd $HOLLIGHT_DIR\nsed -i -e 's/.*Q0.*//' -e 's/START_ND*)//' -e 's/(*END_ND//' fusion.ml bool.ml equal.ml\n```\n\nThanks\n------\n\nHOL-Light proof recording improves\n[ProofTrace](https://github.com/jrh13/hol-light/tree/master/ProofTrace)\ndeveloped by Stanislas Polu in 2019.\n\nSource files\n------------\n\nModified HOL-Light files:\n- `lib.ml`: provides functions on lists, etc. required by `fusion.ml`. A few lines are commented out so that it compiles with ocamlc.\n- `fusion.ml`: defines types, terms, theorems, proofs and elementary proof rules.\n- `bool.ml`: defines basic tactics corresponding to introduction and elimination rules of connectives.\n- `equal.ml`: defines basic tactic(al)s on equality including alpha and beta-reduction.\nThese files contain special comments that are removed to patch hol-light.\n\nAdditional files required for `hol2dk`:\n- `main.ml`: main program of Hol2dk.\n- `xprelude.ml`: provides a few basic definitions.\n- `xlib.ml`: functions on types, terms and other data structures.\n- `xproof.ml`: functions for accessing proofs.\n- `xlp.ml`: translation to Lambdapi of types, terms and proofs.\n- `xdk.ml`: translation to Dedukti of types, terms and proofs.\n- `xfiles.ml`: functions to compute dependencies and theorems of HOL-Light files.\n- `xnames.ml`: functions for dumping the index of named theorems.\n\nNote that all these files can be used in the OCaml toplevel as well by removing the `open` instructions and by adding `unset_jrh_lexer;;` and `set_jrh_lexer;;` at the beginning and at the end of the file.\n\nFiles necessary for the export to Coq: all the lp and v files.\n\nGenerated file types\n--------------------\n\nb.prf: proof steps\n\nb.sig: signature (types, constants, axioms, definitions)\n\nb.thm: map from proof step index to theorem name\n\nb.thp: map every useful theorem index to its name and position (similar to f.thm but with position)\n\nf.nbp: number of proof steps\n\nf.pos: array providing the positions in b.prf of each proof step index\n\nf.use: array lastuse such that lastuse.(i) = 0 if i is a named theorem, the highest proof step index using i if there is one, and -1 otherwise\n\nn.sti: starting index (in f.prf) of theorem n\n\nn.siz: estimation of the size of the proof of n\n\n`n_part_k.idx`: min and max index (in n.prf) of part k proof steps\n\nn.max: array of max proof step indexes of each part of n\n\nn.typ: map from type expression strings to digests and number of type variables\n\nn.sed: sed script to replace type expression digests by type abbreviations\n\nn.brv: ordered list of pairs (term, term abbreviation number)\n\nn.brp: array of positions in the file n.brv\n\n`n_term_abbrevs_part_i.min`: min and max term abbreviation number of part i\n\n`f_types.lp`: types\n\n`f_type_abbrevs.lp`: type abbreviations\n\n`f_terms.lp`: function symbols (i.e. signature)\n\n`f_axioms.lp`: axioms\n\nmain hol2dk commands\n--------------------\n\ndump f.ml: generates an ml file and call ocaml on it to check f.ml and generates f.prf, f.nbp, f.sig and f.thm\n\ndump-simp f.ml: calls the commands dump f.ml, pos f, use f, and simp f\n\npos f: reads f.nbp and f.prf, and generates f.pos\n\nuse f: reads f.nbp, f.thm and f.prf, and generates f.use\n\nsimp f: calls the commands rewrite f and purge f\n\nrewrite f: reads f.pos, f.use and f.prf, and generates a new version of f.prf where proofs have been simplified\n\npurge f: reads f.pos, f.prf, f.thm and f.use, and generates a new file f.use where useless proof steps are mapped to -1\n\nsplit f: reads f.pos, f.use and f.thm, generates f.thp and, for each useful theorem n (if it has no user-defined name, we use its index as name), n.nbp, n.sti, n.pos, n.use\n\nthmsize f n.lp: reads f.prf, n.use, n.pos, n.sti, and generates n.siz\n\nthmsplit f n.lp: reads f.sig, f.thp, f.prf, n.use, n.sti, n.siz, n.pos, and generates the files `n_part_k.idx`, n.max and n.lp\n\nthmpart f `n_part_k.lp`: reads f.sig, f.thp, f.prf, n.pos, n.use, n.sti, n.max, `n_part_k.idx`, and generates `n_part_k.lp`, `n_part_k.brv`, `n_part_k.brp`, `n_part_k_term_abbrevs_part_i.min`, `n_part_k_subterms.lp`\n\ntheorem f n.lp: reads f.sig, f.thp, f.prf, n.pos, n.use, n.sti, and generates the files `n_part_k_proofs.lp`, `n_proofs.lp`, `n.typ`, `n_term_abbrevs.lp`, `n_subterm_abbrevs.lp`, `n_term_abbrevs.typ`, `n_part_k_deps.lp`, `n_part_k.lp`.\n\nabbrev f `n_term_abbrevs_part_i.lp`: reads f.sig, f.thp, n.brv, n.brp, `n_term_abbrevs_part_i.min`, and generates `n_term_abbrevs_part_i.typ` and `n_term_abbrevs_part_i.lp`\n\n`type_abbrevs` f: for each file n.typ in the current directory, reads n.typ and generates n.sed and `f_type_abbrevs.lp`\n\nMakefile targets for generating Lambdapi files\n----------------------------------------------\n\nsplit: calls hol2dk command split\n\nlp:\n- generates `f_types.lp`, `f_type_abbrevs.lp`, `f_terms.lp`, `f_axioms.lp`\n- for every big file n.lp, calls hol2dk thmsize f n.lp (generates the file n.siz) and hol2dk thmsplit f n.lp (generates the files `n_part_k.idx`, n.max and n.lp)\n- calls the Makefile target lp-proofs\n- calls the Makefile target lp-abbrevs\n- calls hol2dk type_abbrevs f\n- calls the Makefile target rename-abbrevs\n\nlp-proofs:\n- for each file `n_part_k.idx` (big file part), calls hol2dk thmpart f `n_part_k.lp`\n- for each file n.sti for which there is no file n.lp yet (small files), calls hol2dk theorem f n.lp\n\nlp-abbrevs: for each file n.min, calls hol2dk abbrev f n.lp\n\nrename-abbrevs: for each file n.sed, apply n.sed to n.lp\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeducteam%2Fhol2dk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeducteam%2Fhol2dk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeducteam%2Fhol2dk/lists"}