Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
mrs-tptp
A robust, zero-copy TPTP (Thousands of Problems for Theorem Provers) parser for Rust.
Overview
mrs-tptp provides a complete parser for the TPTP language, which is the standard input format for automated theorem provers. Built with winnow for efficient, zero-copy parsing — the AST borrows directly from the original input string.
Supported Dialects
- CNF - Clause Normal Form
- FOF - First-Order Form
- TFF - Typed First-order Form (including TXF/FOOL extensions)
- TCF - Typed Clause Form
- THF - Typed Higher-order Form
- NXF/NHF - Non-classical extensions (modal, temporal, epistemic)
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use parse_tptp;
Usage Examples
Parsing FOF (First-Order Form)
use parse_tptp;
let input = r#"
fof(human_socrates, axiom, human(socrates)).
fof(mortality, axiom, ![X]: (human(X) => mortal(X))).
fof(goal, conjecture, mortal(socrates)).
"#;
let problem = parse_tptp.unwrap;
for formula in &problem.formulas
Parsing CNF (Clause Normal Form)
use parse_tptp;
let input = r#"
cnf(clause1, axiom, p(X) | ~q(X, Y)).
cnf(clause2, axiom, q(a, b)).
cnf(goal, negated_conjecture, ~p(a)).
"#;
let problem = parse_tptp.unwrap;
assert_eq!;
Parsing TFF (Typed First-order Form)
use parse_tptp;
let input = r#"
tff(human_type, type, human: $i > $o).
tff(mortal_type, type, mortal: $i > $o).
tff(socrates_type, type, socrates: $i).
tff(axiom1, axiom, human(socrates)).
tff(axiom2, axiom, ![X: $i]: (human(X) => mortal(X))).
"#;
let problem = parse_tptp.unwrap;
Parsing THF (Typed Higher-order Form)
use parse_tptp;
let input = r#"
thf(p_type, type, p: $i > $o).
thf(q_type, type, q: ($i > $o) > $o).
thf(ax1, axiom, q @ (^[X: $i]: p @ X)).
"#;
let problem = parse_tptp.unwrap;
Handling Include Directives
use parse_tptp;
let input = r#"
include('Axioms/SET001+0.ax').
include('Axioms/SET001+1.ax', [subset_def, union_def]).
fof(my_theorem, conjecture, subset(a, union(a, b))).
"#;
let problem = parse_tptp.unwrap;
for include in &problem.includes
Inspecting Formula Structure
use ;
let input = "fof(ax1, axiom, ![X]: (p(X) => q(X))).";
let problem = parse_tptp.unwrap;
if let FOF = &problem.formulas
Streaming Parsing with TPTPIterator
For large files, use TPTPIterator to process one input at a time without collecting everything into a Vec:
use ;
let input = "fof(ax1, axiom, p). fof(ax2, axiom, q). fof(goal, conjecture, r).";
let mut iter = new;
for item in &mut iter
// Check for unconsumed input after iteration
assert!;
Display / Round-trip
All AST types implement Display, producing valid TPTP output that can be reparsed to an equivalent AST:
use parse_tptp;
let input = "fof(ax1, axiom, ![X]: (p(X) => q(X))).";
let problem = parse_tptp.unwrap;
for formula in &problem.formulas
Features
cancellation
Enable cooperative cancellation of long-running parses. Useful for timeout support in multi-threaded contexts:
[]
= { = "0.1", = ["cancellation"] }
use ;
use AtomicBool;
let flag = new;
set_cancel_flag;
// On another thread: flag.store(true, Ordering::Relaxed);
let result = parse_tptp;
clear_cancel_flag;
AST Types
Top-level types:
| Type | Description |
|---|---|
TPTPProblem<'a> |
A complete parsed TPTP file (includes, formulas, formula_comments) |
AnnotatedFormula<'a> |
One annotated formula — THF, TFF, FOF, TCF, CNF, or TPI variant |
TPTPInput<'a> |
A single streamed item — Formula or Include |
FormulaRole |
Role of a formula: Axiom, Conjecture, NegatedConjecture, Type, Definition, Lemma, Theorem, … |
Include<'a> |
An include(…) directive with file_name and optional selection |
Comment<'a> |
A % line or /* block */ comment |
Dialect-specific formula types:
| Type | Dialect |
|---|---|
FOFFormula<'a>, FOFTerm<'a> |
First-order logic |
CNFFormula<'a>, CNFLiteral<'a> |
Clause normal form |
TFFFormula<'a>, TFFTerm<'a>, TFFType<'a> |
Typed first-order |
TCFFormula<'a> |
Typed clause form |
THFFormula<'a>, THFType<'a> |
Typed higher-order |
Examples
The examples/ directory contains runnable programs:
# Parse and display a TPTP file
# Recursively parse all .p files in a folder (parallel, with optional timeout)
# Benchmark parse throughput
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.