This directory contains modified OCaml source files from Coq 8.11 that enable structured information extraction during compilation and proof checking.
These modifications allow the Coq system to output detailed structural information including:
- All declarations and definitions in Coq files
- Complete type information for definitions
- Proof state transitions during verification
- AST structure for theorem proving applications
This directory contains only the modified files, not a complete Coq installation. Due to the complexity of distributing a full modified Coq build, we provide only the changed source files that need to be applied to a clean Coq 8.11 installation.
- Git
- OCaml compiler (compatible with Coq 8.11)
- Standard build tools (make, etc.)
Coq 8.11 requires OCaml version 4.07.0 to 4.10.0. We strongly recommend using OPAM (OCaml Package Manager) to manage OCaml versions and dependencies, as it ensures proper version compatibility and dependency resolution.
On Ubuntu/Debian:
# Install OPAM
sudo apt-get update
sudo apt-get install opam build-essential
# Initialize OPAM (creates ~/.opam directory)
# For Docker environments:
opam init --disable-sandboxing -y
# For regular systems:
# opam init -y
eval $(opam env)
# Create and switch to OCaml 4.10.0 environment
opam switch create coq-8.11 4.10.0
eval $(opam env)
# Verify OCaml installation
ocaml -version
# Should output: The OCaml toplevel, version 4.10.0On macOS:
# Install OPAM via Homebrew
brew install opam
# Initialize OPAM
# For Docker environments:
opam init --disable-sandboxing -y
# For regular systems:
# opam init -y
eval $(opam env)
opam switch create coq-8.11 4.10.0
eval $(opam env)After setting up OCaml, install the required build dependencies:
# Essential build tools
opam install dune num ocamlfind
# Additional dependencies for Coq 8.11
opam install camlp5Important Notes:
- Always run
eval $(opam env)after switching OPAM environments - The
coq-8.11switch name is recommended to avoid conflicts with other projects - Docker users: Must use
--disable-sandboxingflag when initializing OPAM, as Docker containers don't support OPAM's sandboxing features - Regular systems: Use
opam init -ywithout the disable-sandboxing flag for better security - If you encounter permission issues, ensure OPAM was initialized properly
-
Clone Coq 8.11 source:
git clone --branch V8.11.2 https://github.com/coq/coq.git coq-8.11 cd coq-8.11 -
Apply our patches using the provided script:
# From the src/ directory ./patch.sh coq-8.11 /path/to/installThis script will:
- Copy our modified files to the correct locations in the Coq source tree
- Display the exact build commands you need to run
- Show the final binary locations after installation
Follow the script's output carefully - it provides complete build instructions and tells you where the binaries will be installed.
-
Manual patching (alternative): If you prefer manual control over file replacement:
# Copy files to their correct locations in Coq source # (see patch.sh for complete file mappings) cp src/names.ml coq-8.11/kernel/names.ml cp src/names.mli coq-8.11/kernel/names.mli cp src/pretyping.ml coq-8.11/pretyping/pretyping.ml cp src/typeops.ml coq-8.11/kernel/typeops.ml # ... and so on for all modified files # Then build as above cd coq-8.11 ./configure -prefix /path/to/install make -j $(nproc) make install
After installation, use the modified Coq compiler:
export PATH=/path/to/install/bin:$PATH
coqc your_file.v # Will output structured informationThe modified compiler will output additional structured data that can be consumed by the theorem proving framework.
Note: Using coqc directly requires complex dependencies and build setup. For easier usage, we provide Python implementations in the /root/coqc.py that wrap the modified Coq functionality and are more convenient to call from machine learning workflows.
Standard Coq Libraries: Normal Coq (distributed through OCaml/opam) can directly install existing libraries through the OCaml package manager. Our modified Coq can also be linked with OCaml to use these libraries, but this is not recommended due to potential compatibility issues.
Recommended Approach: We handle library dependencies by cloning source code directly and building from source, which provides better control over the compilation process with our modifications.
Due to our kernel-level modifications, some compilation issues may occur. This is one of the main reasons we plan to transition to a plugin architecture in the future.
Common Problem: Some theorems may fail to compile due to our structural analysis modifications.
Solution: Use Unset Linear Execution. before problematic theorems and Set Linear Execution. after completion:
(* Before a problematic theorem *)
Unset Linear Execution.
Theorem problematic_theorem : forall n : nat, n + 0 = n.
Proof.
intro n.
induction n as [| n' IHn'].
- reflexivity.
- simpl. rewrite IHn'. reflexivity.
Qed.
(* Restore normal execution *)
Set Linear Execution.
(* Continue with other definitions *)
Definition next_function := ...This workaround disables certain internal optimizations that may conflict with our structural extraction, allowing the theorem to compile successfully.
The modified files span multiple components of Coq:
typeops.ml- Kernel type operations with structural extractionpretyping.ml- Pretyping phase modificationsnames.ml,names.mli- Name handling with metadata
cLexer.ml- Lexical analysis modificationsprinter.ml- Enhanced proof term printingpp*.ml- Pretty printing with structural infodetyping.ml- Type inference reverse operations
com*.ml- Command handling (definitions, inductives, etc.)vernacentries.ml- Vernacular command processingvernacinterp.ml- Vernacular interpretation
proof_global.ml- Global proof state managementtacinterp.ml- Tactic interpretationtacentries.ml- Tactic registration
globEnv.ml- Global environment extensionsnametab.ml- Name table modificationsconstrintern.ml- Term internalization
These modifications are specifically designed for Coq 8.11.2. Using them with other Coq versions may require additional porting work due to API changes between versions.
The structured information output by this modified Coq is consumed by the Python machine learning framework in the data_extraction directory. The integration points include:
- Proof state extraction for training neural tactic generators
- Definition parsing for building semantic embeddings
- Type information for context-aware proof search
For details on using the ML framework with this modified Coq, see the main project documentation.
Note: The current approach is highly invasive, requiring direct modification of Coq's source code. This creates maintenance challenges and limits compatibility to a specific Coq version.
Future Plan: We plan to refactor this system into a Coq plugin architecture. This would provide several advantages:
- Version Compatibility: Support for multiple Coq versions without source modifications
- Plug-and-Play: Easy installation and usage without rebuilding Coq
- Maintenance: Reduced coupling with Coq internals
- Distribution: Simpler packaging and deployment
The plugin approach would use Coq's official plugin API to hook into the compilation process and extract the same structural information currently obtained through source modifications. This will make the tool much more accessible and maintainable for the broader Coq community.