This project provides several programs:
patch to patch HOL-Light to dump proofsunpatch to unpatch HOL-Lighthol2dk to generate Dedukti or Lambdapi files from dumped proofsHOL-Light is proof assistant based on higher-order logic, aka simple type theory.
Dedukti is a proof format based on the λΠ-calculus modulo rewriting (λ-calculus + simple types + dependent types + implicit type equivalence modulo user-defined rewriting rules).
Lambdapi is a proof assistant based on the λΠ-calculus modulo rewriting that can read and generate Dedukti proofs.
Coq is a proof assistant based on the Calculus of Inductive Constructions.
Requirements:
Find other potential working ocaml-camlp5 pairs on https://github.com/jrh13/hol-light/pull/71 .
If you don't have HOL-Light already installed, you can install it by using the following commands:
cd $HOME
sudo apt-get install -y libipc-system-simple-perl libstring-shellquote
-perl opam
opam init
opam switch create ocaml.4.14.1
eval `opam env`
opam install ocamlfind num camlp5
git clone --depth 1 -b master https://github.com/jrh13/hol-light
make -C hol-light$HOL2DK_DIRFor some commands to have access to files in hol2dk sources, you need to set the following environment variable:
export HOL2DK_DIR=$hol2dk_dirwhere $hol2dk_dir is the absolute path to the directory where the hol2dk sources are.
cd $hol2dk-dir
./patch $hol-light-dirThis script slightly modifies a few HOL-Light files in order to dump proofs:
fusion.ml: the HOL-Light kernel file defining types, terms, theorems, proofs and proof rulesbool.ml: HOL-Light file defining basic tactics corresponding to introduction and elimination rules of connectivesTo unpatch HOL-Light, simply do:
$hol2dk-dir
./unpatch $hol-light-dirRequirements:
cd $hol2dk-dir
dune build && dune installcompiles and installs hol2dk.
Get it by running hol2dk without arguments.
cd $hol-light-dir
hol2dk dump file.mlgenerates the files file.sig, file.prf and file.thm.
file.ml should at least require hol.ml until the line loads "fusion.ml";;.
WARNING: it is important to run hol2dk dump in the HOL-Light directory so as to compute the list of named theorems properly.
The base theory in which HOL-Light proofs are translated is described in the files theory_hol.lp and theory_hol.dk.
You first need to generate file.pos and file.use with:
hol2dk pos file
hol2dk use fileYou can then generate file.dk with:
hol2dk file.dkAnd file.lp with:
hol2dk file.lpIt is possible to get the proof of a single theorem by giving its number as additional argument (useful for debugging):
hol2dk file.lp $theorem_numberDk/lp file generation is linear in the size of dumped files. For big dumped files, we provide a command to do file generation in parallel using make.
You first generate file.dg and file.mk with:
hol2dk dg $nb_parts file
hol2dk mk-part filewhere $nb_parts is the number of files in which you want to split the proofs.
You add links to hol2dk files:
ln -s $HOL2DK_DIR/theory_hol.dk
ln -s $HOL2DK_DIR/theory_hol.lp
ln -s $HOL2DK_DIR/lambdapi.pkg
ln -s $HOL2DK_DIR/coq.v
ln -s $HOL2DK_DIR/_CoqProjectYou can then generate file.dk with:
make -j $jobs -f file.mk dkAnd file.lp with:
make -j $jobs -f file.mk lpRequirement: lambdapi >= 2.3.0, dedukti >= 2.7 or kocheck
To check the generated dk file with dkcheck, do:
dk check file.dkTo check the generated dk file with the current version of kocheck, you need to slightly change the generated file:
sed -e 's/^injective /def /g' file.dk > file-for-kocheck.dk
kocheck -j 7 file-for-kocheck.dkRequirement: lambdapi >= 2.3.0 for single-threaded generated files, lambdapi master branch for multi-threaded generated files
To check the generated lp files with lambdapi, do:
lambdapi check --map-dir hol-light:. file.lpor create a file lambdapi.pkg:
package_name = hol-light
root_path = hol-lightand simply do:
lambdapi check file.lpRemark: In case hol-light and dkcheck/lambdapi do not use the same ocaml versions, it is convenient to use different switches in each directory:
Xterm 1 (for HOL-Light):
cd hol-light
opam switch link 4.02.3
eval `opam env`Xterm 2 (for checking dk/lp files):
opam switch link 4.14.1
eval `opam env`Requirement: lambdapi master branch
Once HOL-Light files have been translated to Lambdapi files, it is possible to translate Lambdapi files into Coq files using the Coq export feature of Lambdapi.
If your Lambdapi files have been generated using file.mk, you can simply do:
make -j $jobs -f file.mk v # to generate Coq files
make -j $jobs -f file.mk vo # to check the generated Coq filesTo indicate a specific lambdapi command, do:
make -j $jobs -f file.mk LAMBAPI=$lambdapi v # to generate Coq filesOtherwise, you need to translate Lambdapi files one by one by hand or using a script:
lambdapi export -o stt_coq --encoding $(HOL2DK_DIR)/encoding.lp --erasing $(HOL2DK_DIR)/erasing.lp --renaming $(HOL2DK_DIR)/renaming.lp --requiring $(HOL2DK_DIR)/coq.v file.lp | sed -e 's/hol-light\.//g' > file.vYou can then check the generated Coq files as follows:
echo coq.v theory_hol.v file*.v > _CoqProject
coq_makefile -f _CoqProject -o Makefile.coq
make -j $jobs -f Makefile.coqDumping of hol.ml:
rule | % |
|---|---|
refl | 29 |
eqmp | 19 |
comb | 17 |
term_subst | 12 |
trans | 6 |
type_subst | 3 |
beta | 3 |
abs | 2 |
spec | 2 |
Single-threaded translation to Lambdapi:
Single-threaded translation to Dedukti:
Multi-threaded translation to Lambdapi with mk 100 and -j 28:
Multi-threaded translation to Dedukti with mk 100:
Results for hol.ml up to arith.ml (by commenting from loads "wf.ml" to the end) with mk 7 and -j 7 :
-c)Hol2dk instruments basic HOL-Light tactics corresponding to introduction and elimination rules of connectives to get smaller proofs and proofs closer to natural deduction proofs. It is however possible to generate full Q0 proofs by doing after patching:
cd $hol-light-dir
sed -i -e 's/.*Q0.*//' -e 's/START_ND*)//' -e 's/(*END_ND//' fusion.ml bool.ml equal.mlResults on hol.ml upto arith.ml (by commenting from loads "wf.ml" to the end):
Results on hol.ml:
rule | % |
|---|---|
refl | 26 |
eqmp | 21 |
term_subst | 15 |
trans | 11 |
comb | 10 |
deduct | 7 |
type_subst | 4 |
abs | 2 |
beta | 2 |
assume | 2 |
Modified HOL-Light files:
lib.ml: provides functions on lists, etc. required by fusion.ml. A few lines are commented out so that it compiles with ocamlc.fusion.ml: defines types, terms, theorems, proofs and elementary proof rules.bool.ml: defines basic tactics corresponding to introduction and elimination rules of connectives.equal.ml: defines basic tactic(al)s on equality including alpha and beta-reduction. These files contain special comments that are removed to patch hol-light.Additional files required for hol2dk:
main.ml: main program of Hol2dk.xprelude.ml: provides a few basic definitions.xlib.ml: functions on types, terms and other data structures.xproof.ml: functions for accessing proofs.xlp.ml: translation to Lambdapi of types, terms and proofs.xdk.ml: translation to Dedukti of types, terms and proofs.xfiles.ml: functions to compute dependencies and theorems of HOL-Light files.xnames.ml: functions for dumping the index of named theorems.xci.ml: slightly truncated version of the HOL-Light file hol.ml used for testing.Note 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.
Files necessary for the export to Coq: encoding.lp, erasing.lp, renaming.lp, coq.v.
HOL-Light proof recording follows ProofTrace developed by Stanislas Polu in 2019.