pub struct Problem { /* private fields */ }Expand description
A theorem proving problem consisting of axioms and an optional conjecture.
A Problem is constructed by adding axioms (assumed to be true) and optionally
a conjecture (the statement to be proved). The problem is then solved by calling
Problem::solve, which invokes the Vampire theorem prover.
§Examples
§Basic Usage
use vampire_prover::{Function, Predicate, Problem, ProofRes, Options, forall};
let mortal = Predicate::new("mortal", 1);
let human = Predicate::new("human", 1);
let socrates = Function::constant("socrates");
let result = Problem::new(Options::new())
.with_axiom(human.with(socrates))
.with_axiom(forall(|x| human.with(x) >> mortal.with(x)))
.conjecture(mortal.with(socrates))
.solve();
assert_eq!(result, ProofRes::Proved);§Without Conjecture
You can also create problems without a conjecture to check satisfiability:
use vampire_prover::{Function, Predicate, Problem, Options};
let p = Predicate::new("P", 1);
let x = Function::constant("x");
let result = Problem::new(Options::new())
.with_axiom(p.with(x))
.with_axiom(!p.with(x)) // Contradiction
.solve();
// This should be unsatisfiableImplementations§
Source§impl Problem
impl Problem
Sourcepub fn new(options: Options) -> Self
pub fn new(options: Options) -> Self
Creates a new empty problem with the given options.
§Arguments
options- Configuration options for the prover
§Examples
use vampire_prover::{Problem, Options};
use std::time::Duration;
// Default options
let problem = Problem::new(Options::new());Examples found in repository?
3fn main() {
4 let x1 = Function::new("x", 0);
5 let x2 = Function::new("x", 0);
6
7 dbg!(x1, x2);
8 dbg!(x1 == x2);
9
10 let y1 = Function::new("y", 0);
11 let y2 = Function::new("y", 1);
12
13 dbg!(y1, y2);
14
15 let z1 = Function::new("z", 0);
16 let z2 = Predicate::new("z", 0);
17
18 dbg!(z1, z2);
19
20 let solution = Problem::new(Options::new())
21 .with_axiom(y1.with(&[]).eq(y2.with(&[y1.with(&[])])))
22 .solve();
23
24 dbg!(solution);
25}More examples
113fn run_proof(i: usize) -> ProofRes {
114 // Prove that every subgroup of index 2 is normal.
115 let mult = Function::new(&format!("mult{i}"), 2);
116 let inv = Function::new(&format!("inv{i}"), 1);
117 let one = Function::constant(&format!("1{i}"));
118
119 // Helper to make multiplication more readable
120 let mul = |x: Term, y: Term| -> Term { mult.with(&[x, y]) };
121
122 // Group Axiom 1: Right identity - ∀x. x * 1 = x
123 let right_identity = forall(|x| mul(x, one).eq(x));
124
125 // Group Axiom 2: Right inverse - ∀x. x * inv(x) = 1
126 let right_inverse = forall(|x| {
127 let inv_x = inv.with(&[x]);
128 mul(x, inv_x).eq(one)
129 });
130
131 // Group Axiom 3: Associativity - ∀x,y,z. (x * y) * z = x * (y * z)
132 let associativity = forall(|x| forall(|y| forall(|z| mul(mul(x, y), z).eq(mul(x, mul(y, z))))));
133
134 // Describe the subgroup
135 let h = Predicate::new("h", 1);
136
137 // Any subgroup contains the identity
138 let h_ident = h.with(&[one]);
139
140 // And is closed under multiplication
141 let h_mul_closed =
142 forall(|x| forall(|y| (h.with(&[x]) & h.with(&[y])) >> h.with(&[mul(x, y)])));
143
144 // And is closed under inverse
145 let h_inv_closed = forall(|x| h.with(&[x]) >> h.with(&[inv.with(&[x])]));
146
147 // H specifically is of order 2
148 let h_index_2 = exists(|x| {
149 // an element not in H
150 let not_in_h = !h.with(&[x]);
151 // but everything is in H or x H
152 let class = forall(|y| h.with(&[y]) | h.with(&[mul(inv.with(&[x]), y)]));
153
154 not_in_h & class
155 });
156
157 // Conjecture: H is normal
158 let h_normal = forall(|x| {
159 let h_x = h.with(&[x]);
160 let conj_x = forall(|y| {
161 let y_inv = inv.with(&[y]);
162 h.with(&[mul(mul(y, x), y_inv)])
163 });
164 h_x.iff(conj_x)
165 });
166
167 Problem::new(Options::new())
168 .with_axiom(right_identity)
169 .with_axiom(right_inverse)
170 .with_axiom(associativity)
171 .with_axiom(h_ident)
172 .with_axiom(h_mul_closed)
173 .with_axiom(h_inv_closed)
174 .with_axiom(h_index_2)
175 .conjecture(h_normal)
176 .solve()
177}Sourcepub fn with_axiom(&mut self, f: Formula) -> &mut Self
pub fn with_axiom(&mut self, f: Formula) -> &mut Self
Adds an axiom to the problem.
Axioms are formulas assumed to be true. The prover will use these axioms to attempt to prove the conjecture (if one is provided).
This method consumes self and returns a new Problem, allowing for
method chaining.
§Arguments
f- The axiom formula to add
§Examples
use vampire_prover::{Function, Predicate, Problem, Options, forall};
let p = Predicate::new("P", 1);
let q = Predicate::new("Q", 1);
let problem = Problem::new(Options::new())
.with_axiom(forall(|x| p.with(x)))
.with_axiom(forall(|x| p.with(x) >> q.with(x)));Examples found in repository?
3fn main() {
4 let x1 = Function::new("x", 0);
5 let x2 = Function::new("x", 0);
6
7 dbg!(x1, x2);
8 dbg!(x1 == x2);
9
10 let y1 = Function::new("y", 0);
11 let y2 = Function::new("y", 1);
12
13 dbg!(y1, y2);
14
15 let z1 = Function::new("z", 0);
16 let z2 = Predicate::new("z", 0);
17
18 dbg!(z1, z2);
19
20 let solution = Problem::new(Options::new())
21 .with_axiom(y1.with(&[]).eq(y2.with(&[y1.with(&[])])))
22 .solve();
23
24 dbg!(solution);
25}More examples
113fn run_proof(i: usize) -> ProofRes {
114 // Prove that every subgroup of index 2 is normal.
115 let mult = Function::new(&format!("mult{i}"), 2);
116 let inv = Function::new(&format!("inv{i}"), 1);
117 let one = Function::constant(&format!("1{i}"));
118
119 // Helper to make multiplication more readable
120 let mul = |x: Term, y: Term| -> Term { mult.with(&[x, y]) };
121
122 // Group Axiom 1: Right identity - ∀x. x * 1 = x
123 let right_identity = forall(|x| mul(x, one).eq(x));
124
125 // Group Axiom 2: Right inverse - ∀x. x * inv(x) = 1
126 let right_inverse = forall(|x| {
127 let inv_x = inv.with(&[x]);
128 mul(x, inv_x).eq(one)
129 });
130
131 // Group Axiom 3: Associativity - ∀x,y,z. (x * y) * z = x * (y * z)
132 let associativity = forall(|x| forall(|y| forall(|z| mul(mul(x, y), z).eq(mul(x, mul(y, z))))));
133
134 // Describe the subgroup
135 let h = Predicate::new("h", 1);
136
137 // Any subgroup contains the identity
138 let h_ident = h.with(&[one]);
139
140 // And is closed under multiplication
141 let h_mul_closed =
142 forall(|x| forall(|y| (h.with(&[x]) & h.with(&[y])) >> h.with(&[mul(x, y)])));
143
144 // And is closed under inverse
145 let h_inv_closed = forall(|x| h.with(&[x]) >> h.with(&[inv.with(&[x])]));
146
147 // H specifically is of order 2
148 let h_index_2 = exists(|x| {
149 // an element not in H
150 let not_in_h = !h.with(&[x]);
151 // but everything is in H or x H
152 let class = forall(|y| h.with(&[y]) | h.with(&[mul(inv.with(&[x]), y)]));
153
154 not_in_h & class
155 });
156
157 // Conjecture: H is normal
158 let h_normal = forall(|x| {
159 let h_x = h.with(&[x]);
160 let conj_x = forall(|y| {
161 let y_inv = inv.with(&[y]);
162 h.with(&[mul(mul(y, x), y_inv)])
163 });
164 h_x.iff(conj_x)
165 });
166
167 Problem::new(Options::new())
168 .with_axiom(right_identity)
169 .with_axiom(right_inverse)
170 .with_axiom(associativity)
171 .with_axiom(h_ident)
172 .with_axiom(h_mul_closed)
173 .with_axiom(h_inv_closed)
174 .with_axiom(h_index_2)
175 .conjecture(h_normal)
176 .solve()
177}Sourcepub fn conjecture(&mut self, f: Formula) -> &mut Self
pub fn conjecture(&mut self, f: Formula) -> &mut Self
Sets the conjecture for the problem.
The conjecture is the statement that the prover will attempt to prove from the axioms. A problem can have at most one conjecture.
This method consumes self and returns a new Problem, allowing for
method chaining.
§Arguments
f- The conjecture formula
§Examples
use vampire_prover::{Function, Predicate, Problem, Options, forall};
let p = Predicate::new("P", 1);
let q = Predicate::new("Q", 1);
let problem = Problem::new(Options::new())
.with_axiom(forall(|x| p.with(x) >> q.with(x)))
.conjecture(forall(|x| q.with(x))); // Try to prove thisExamples found in repository?
113fn run_proof(i: usize) -> ProofRes {
114 // Prove that every subgroup of index 2 is normal.
115 let mult = Function::new(&format!("mult{i}"), 2);
116 let inv = Function::new(&format!("inv{i}"), 1);
117 let one = Function::constant(&format!("1{i}"));
118
119 // Helper to make multiplication more readable
120 let mul = |x: Term, y: Term| -> Term { mult.with(&[x, y]) };
121
122 // Group Axiom 1: Right identity - ∀x. x * 1 = x
123 let right_identity = forall(|x| mul(x, one).eq(x));
124
125 // Group Axiom 2: Right inverse - ∀x. x * inv(x) = 1
126 let right_inverse = forall(|x| {
127 let inv_x = inv.with(&[x]);
128 mul(x, inv_x).eq(one)
129 });
130
131 // Group Axiom 3: Associativity - ∀x,y,z. (x * y) * z = x * (y * z)
132 let associativity = forall(|x| forall(|y| forall(|z| mul(mul(x, y), z).eq(mul(x, mul(y, z))))));
133
134 // Describe the subgroup
135 let h = Predicate::new("h", 1);
136
137 // Any subgroup contains the identity
138 let h_ident = h.with(&[one]);
139
140 // And is closed under multiplication
141 let h_mul_closed =
142 forall(|x| forall(|y| (h.with(&[x]) & h.with(&[y])) >> h.with(&[mul(x, y)])));
143
144 // And is closed under inverse
145 let h_inv_closed = forall(|x| h.with(&[x]) >> h.with(&[inv.with(&[x])]));
146
147 // H specifically is of order 2
148 let h_index_2 = exists(|x| {
149 // an element not in H
150 let not_in_h = !h.with(&[x]);
151 // but everything is in H or x H
152 let class = forall(|y| h.with(&[y]) | h.with(&[mul(inv.with(&[x]), y)]));
153
154 not_in_h & class
155 });
156
157 // Conjecture: H is normal
158 let h_normal = forall(|x| {
159 let h_x = h.with(&[x]);
160 let conj_x = forall(|y| {
161 let y_inv = inv.with(&[y]);
162 h.with(&[mul(mul(y, x), y_inv)])
163 });
164 h_x.iff(conj_x)
165 });
166
167 Problem::new(Options::new())
168 .with_axiom(right_identity)
169 .with_axiom(right_inverse)
170 .with_axiom(associativity)
171 .with_axiom(h_ident)
172 .with_axiom(h_mul_closed)
173 .with_axiom(h_inv_closed)
174 .with_axiom(h_index_2)
175 .conjecture(h_normal)
176 .solve()
177}Sourcepub fn solve(&mut self) -> ProofRes
pub fn solve(&mut self) -> ProofRes
Solves the problem using the Vampire theorem prover.
This method consumes the problem and invokes Vampire to either prove the conjecture from the axioms, find a counterexample, or determine that the result is unknown.
§Returns
A ProofRes indicating whether the conjecture was proved, found to be
unprovable, or whether the result is unknown (due to timeout, memory limits,
or incompleteness).
§Examples
use vampire_prover::{Function, Predicate, Problem, ProofRes, Options, forall};
let p = Predicate::new("P", 1);
let x = Function::constant("x");
let result = Problem::new(Options::new())
.with_axiom(p.with(x))
.conjecture(p.with(x))
.solve();
assert_eq!(result, ProofRes::Proved);Examples found in repository?
3fn main() {
4 let x1 = Function::new("x", 0);
5 let x2 = Function::new("x", 0);
6
7 dbg!(x1, x2);
8 dbg!(x1 == x2);
9
10 let y1 = Function::new("y", 0);
11 let y2 = Function::new("y", 1);
12
13 dbg!(y1, y2);
14
15 let z1 = Function::new("z", 0);
16 let z2 = Predicate::new("z", 0);
17
18 dbg!(z1, z2);
19
20 let solution = Problem::new(Options::new())
21 .with_axiom(y1.with(&[]).eq(y2.with(&[y1.with(&[])])))
22 .solve();
23
24 dbg!(solution);
25}More examples
113fn run_proof(i: usize) -> ProofRes {
114 // Prove that every subgroup of index 2 is normal.
115 let mult = Function::new(&format!("mult{i}"), 2);
116 let inv = Function::new(&format!("inv{i}"), 1);
117 let one = Function::constant(&format!("1{i}"));
118
119 // Helper to make multiplication more readable
120 let mul = |x: Term, y: Term| -> Term { mult.with(&[x, y]) };
121
122 // Group Axiom 1: Right identity - ∀x. x * 1 = x
123 let right_identity = forall(|x| mul(x, one).eq(x));
124
125 // Group Axiom 2: Right inverse - ∀x. x * inv(x) = 1
126 let right_inverse = forall(|x| {
127 let inv_x = inv.with(&[x]);
128 mul(x, inv_x).eq(one)
129 });
130
131 // Group Axiom 3: Associativity - ∀x,y,z. (x * y) * z = x * (y * z)
132 let associativity = forall(|x| forall(|y| forall(|z| mul(mul(x, y), z).eq(mul(x, mul(y, z))))));
133
134 // Describe the subgroup
135 let h = Predicate::new("h", 1);
136
137 // Any subgroup contains the identity
138 let h_ident = h.with(&[one]);
139
140 // And is closed under multiplication
141 let h_mul_closed =
142 forall(|x| forall(|y| (h.with(&[x]) & h.with(&[y])) >> h.with(&[mul(x, y)])));
143
144 // And is closed under inverse
145 let h_inv_closed = forall(|x| h.with(&[x]) >> h.with(&[inv.with(&[x])]));
146
147 // H specifically is of order 2
148 let h_index_2 = exists(|x| {
149 // an element not in H
150 let not_in_h = !h.with(&[x]);
151 // but everything is in H or x H
152 let class = forall(|y| h.with(&[y]) | h.with(&[mul(inv.with(&[x]), y)]));
153
154 not_in_h & class
155 });
156
157 // Conjecture: H is normal
158 let h_normal = forall(|x| {
159 let h_x = h.with(&[x]);
160 let conj_x = forall(|y| {
161 let y_inv = inv.with(&[y]);
162 h.with(&[mul(mul(y, x), y_inv)])
163 });
164 h_x.iff(conj_x)
165 });
166
167 Problem::new(Options::new())
168 .with_axiom(right_identity)
169 .with_axiom(right_inverse)
170 .with_axiom(associativity)
171 .with_axiom(h_ident)
172 .with_axiom(h_mul_closed)
173 .with_axiom(h_inv_closed)
174 .with_axiom(h_index_2)
175 .conjecture(h_normal)
176 .solve()
177}