vampire
Safe Rust bindings to the Vampire theorem prover for first-order logic with equality.
Overview
This crate provides a high-level, safe Rust interface to Vampire, a state-of-the-art automated theorem prover. Vampire can prove theorems, check satisfiability, and find counterexamples in various mathematical domains including:
- Propositional and first-order logic
- Equality reasoning
- Group theory and algebra
- Graph properties
- Program verification
- Mathematical proofs
Quick Start
use ;
// Create predicates
let is_mortal = new;
let is_man = new;
// Create a universal statement: ∀x. man(x) → mortal(x)
let men_are_mortal = forall;
// Create a constant
let socrates = constant;
// Build and solve the problem
let result = new
.with_axiom // Socrates is a man
.with_axiom // All men are mortal
.conjecture // Therefore, Socrates is mortal
.solve;
assert_eq!;
Core Concepts
Terms
Terms represent objects in first-order logic:
use ;
// Constants (0-ary functions)
let zero = constant;
let socrates = constant;
// Variables
let x = new_var;
let y = new_var;
// Function applications
let succ = new;
let one = succ.with;
let add = new;
let sum = add.with;
Note: Function and predicate symbols are interned. Calling Function::new or Predicate::new with the same name and arity multiple times will return the same symbol. It's safe to use the same name with different arities - they will be treated as distinct symbols.
Formulas
Formulas are logical statements:
use ;
let p = new;
let q = new;
let x = constant;
// Atomic formulas
let px = p.with;
let qx = q.with;
// Logical connectives
let both = px & qx; // P(x) ∧ Q(x) - conjunction
let either = px | qx; // P(x) ∨ Q(x) - disjunction
let implies = px >> qx; // P(x) → Q(x) - implication
let not_px = !px; // ¬P(x) - negation
let equiv = px.iff; // P(x) ↔ Q(x) - biconditional
// Quantifiers
let all = forall; // ∀x. P(x)
let some = exists; // ∃x. P(x)
Equality
Equality is a built-in predicate:
use ;
let f = new;
let x = constant;
// Direct equality
let eq1 = x.eq; // x = x
// Equality in quantified formulas
let reflexive = forall; // ∀x. x = x
Examples
Graph Reachability
Prove that a path exists in a graph using transitivity:
use ;
let edge = new;
let path = new;
// Create nodes
let a = constant;
let b = constant;
let c = constant;
let d = constant;
// Axiom: Edges are paths
let edges_are_paths = forall;
// Axiom: Paths are transitive
let transitivity = forall;
// Prove there's a path from a to d
let result = new
.with_axiom
.with_axiom
.with_axiom
.with_axiom
.with_axiom
.conjecture
.solve;
assert_eq!;
Group Theory
Prove the left identity from the standard group axioms:
use ;
let mult = new;
let inv = new;
let one = constant;
let mul = ;
// Group axioms
let right_identity = forall;
let right_inverse = forall;
let associativity = forall;
// Prove left identity
let left_identity = forall;
let result = new
.with_axiom
.with_axiom
.with_axiom
.conjecture
.solve;
assert_eq!;
Set Theory
Prove properties about sets:
use ;
let member = new;
let subset = new;
// Define subset: A ⊆ B ↔ ∀x. x ∈ A → x ∈ B
let subset_def = forall;
// Prove subset is reflexive: ∀A. A ⊆ A
let reflexive = forall;
let result = new
.with_axiom
.conjecture
.solve;
assert_eq!;
Operators
The crate provides convenient operators for logical connectives:
| Operator | Logic | Example |
|---|---|---|
& |
Conjunction (AND) | p & q |
| |
Disjunction (OR) | p | q |
>> |
Implication | p >> q |
! |
Negation (NOT) | !p |
.iff() |
Biconditional (IFF) | p.iff(q) |
.eq() |
Equality | x.eq(y) |
Proof Results
When you call Problem::solve(), you get one of three results:
ProofRes::Proved- The conjecture was successfully proved from the axiomsProofRes::Unprovable- The axioms are insufficient to prove the conjecture (note: the conjecture could still be true or false, but the given axioms cannot establish it)ProofRes::Unknown(reason)- Vampire could not determine if the axioms imply the conjecture:UnknownReason::Timeout- Time limit exceededUnknownReason::MemoryLimit- Memory limit exceededUnknownReason::Incomplete- Problem uses incomplete logicUnknownReason::Unknown- Unknown reason
Thread Safety
Important: The underlying Vampire library is not thread-safe. This crate protects all operations with a global mutex, so while you can safely use the library from multiple threads, all proof operations will be serialized. Only one proof can execute at a time.
License
Rust Bindings
This Rust crate is 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.
Vampire Theorem Prover
The underlying Vampire theorem prover library is licensed under the BSD 3-Clause License. See the Vampire LICENCE file for details.
When distributing applications using this crate, you must comply with both the Rust bindings license (your choice of MIT or Apache-2.0) and the Vampire BSD 3-Clause license requirements.