2020-05-11 03:46:11 +02:00
|
|
|
|
mod proof_direction;
|
2020-05-11 03:11:10 +02:00
|
|
|
|
mod section_kind;
|
2020-05-13 03:16:51 +02:00
|
|
|
|
mod statement;
|
2020-05-11 03:11:10 +02:00
|
|
|
|
|
2020-05-11 03:46:11 +02:00
|
|
|
|
pub use proof_direction::ProofDirection;
|
2020-05-13 03:16:51 +02:00
|
|
|
|
pub(crate) use section_kind::SectionKind;
|
|
|
|
|
pub(crate) use statement::{ProofStatus, Statement, StatementKind};
|
2020-05-05 19:40:57 +02:00
|
|
|
|
|
2020-05-06 21:38:48 +02:00
|
|
|
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
2020-05-05 19:40:57 +02:00
|
|
|
|
pub enum ProofResult
|
|
|
|
|
{
|
|
|
|
|
Proven,
|
|
|
|
|
NotProven,
|
|
|
|
|
Disproven,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type VariableDeclarationIDs
|
|
|
|
|
= std::collections::BTreeMap::<std::rc::Rc<foliage::VariableDeclaration>, usize>;
|
|
|
|
|
|
2020-05-11 03:48:14 +02:00
|
|
|
|
type InputConstantDeclarationDomains
|
|
|
|
|
= std::collections::BTreeMap<std::rc::Rc<foliage::FunctionDeclaration>, crate::Domain>;
|
|
|
|
|
|
2020-05-13 07:41:01 +02:00
|
|
|
|
type VariableDeclarationDomains
|
|
|
|
|
= std::collections::BTreeMap<std::rc::Rc<foliage::VariableDeclaration>, crate::Domain>;
|
|
|
|
|
|
2020-05-05 19:40:57 +02:00
|
|
|
|
struct FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
pub program_variable_declaration_ids: std::cell::RefCell<VariableDeclarationIDs>,
|
|
|
|
|
pub integer_variable_declaration_ids: std::cell::RefCell<VariableDeclarationIDs>,
|
2020-05-11 03:48:14 +02:00
|
|
|
|
pub input_constant_declaration_domains: &'a InputConstantDeclarationDomains,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
pub variable_declaration_domains: &'b VariableDeclarationDomains,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Problem
|
|
|
|
|
{
|
|
|
|
|
function_declarations: std::cell::RefCell<foliage::FunctionDeclarations>,
|
|
|
|
|
pub predicate_declarations: std::cell::RefCell<foliage::PredicateDeclarations>,
|
|
|
|
|
|
|
|
|
|
statements: std::cell::RefCell<std::collections::BTreeMap<SectionKind, Vec<Statement>>>,
|
|
|
|
|
|
|
|
|
|
pub input_constant_declarations: std::cell::RefCell<foliage::FunctionDeclarations>,
|
2020-05-11 03:48:14 +02:00
|
|
|
|
pub input_constant_declaration_domains: std::cell::RefCell<InputConstantDeclarationDomains>,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
pub input_predicate_declarations: std::cell::RefCell<foliage::PredicateDeclarations>,
|
2020-05-12 05:27:51 +02:00
|
|
|
|
pub output_predicate_declarations: std::cell::RefCell<foliage::PredicateDeclarations>,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
// TODO: clean up as variable declarations are dropped
|
|
|
|
|
variable_declaration_domains: std::cell::RefCell<VariableDeclarationDomains>,
|
2020-05-12 04:25:49 +02:00
|
|
|
|
|
|
|
|
|
shell: std::cell::RefCell<crate::output::Shell>,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Problem
|
|
|
|
|
{
|
|
|
|
|
pub fn new() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self
|
|
|
|
|
{
|
|
|
|
|
function_declarations: std::cell::RefCell::new(foliage::FunctionDeclarations::new()),
|
|
|
|
|
predicate_declarations: std::cell::RefCell::new(foliage::PredicateDeclarations::new()),
|
|
|
|
|
|
|
|
|
|
statements: std::cell::RefCell::new(std::collections::BTreeMap::new()),
|
|
|
|
|
|
|
|
|
|
input_constant_declarations:
|
|
|
|
|
std::cell::RefCell::new(foliage::FunctionDeclarations::new()),
|
|
|
|
|
input_constant_declaration_domains:
|
2020-05-11 03:48:14 +02:00
|
|
|
|
std::cell::RefCell::new(InputConstantDeclarationDomains::new()),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
input_predicate_declarations:
|
|
|
|
|
std::cell::RefCell::new(foliage::PredicateDeclarations::new()),
|
2020-05-12 05:27:51 +02:00
|
|
|
|
output_predicate_declarations:
|
|
|
|
|
std::cell::RefCell::new(foliage::PredicateDeclarations::new()),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
variable_declaration_domains:
|
|
|
|
|
std::cell::RefCell::new(VariableDeclarationDomains::new()),
|
2020-05-12 04:25:49 +02:00
|
|
|
|
|
|
|
|
|
shell: std::cell::RefCell::new(crate::output::Shell::from_stdout()),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 03:16:51 +02:00
|
|
|
|
pub(crate) fn add_statement(&self, section_kind: SectionKind, statement: Statement)
|
2020-05-05 19:40:57 +02:00
|
|
|
|
{
|
|
|
|
|
let mut statements = self.statements.borrow_mut();
|
|
|
|
|
let section = statements.entry(section_kind).or_insert(vec![]);
|
|
|
|
|
|
|
|
|
|
section.push(statement);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 07:41:01 +02:00
|
|
|
|
pub(crate) fn restrict_to_output_predicates(&mut self) -> Result<(), crate::Error>
|
|
|
|
|
{
|
|
|
|
|
let predicate_declarations = self.predicate_declarations.borrow();
|
|
|
|
|
let input_predicate_declarations = self.input_predicate_declarations.borrow();
|
|
|
|
|
let output_predicate_declarations = self.output_predicate_declarations.borrow();
|
|
|
|
|
|
|
|
|
|
// If no output statements were provided, show all predicates by default
|
|
|
|
|
if output_predicate_declarations.is_empty()
|
|
|
|
|
{
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let hidden_predicate_declarations =
|
|
|
|
|
predicate_declarations.iter().filter(|x| !output_predicate_declarations.contains(*x)
|
|
|
|
|
&& !input_predicate_declarations.contains(*x));
|
|
|
|
|
|
|
|
|
|
let mut statements = self.statements.borrow_mut();
|
|
|
|
|
|
|
|
|
|
for hidden_predicate_declaration in hidden_predicate_declarations
|
|
|
|
|
{
|
|
|
|
|
let matches_completed_definition =
|
|
|
|
|
|(_, statement): &(_, &Statement)| match statement.kind
|
|
|
|
|
{
|
|
|
|
|
StatementKind::CompletedDefinition(ref predicate_declaration) =>
|
|
|
|
|
predicate_declaration == hidden_predicate_declaration,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let completed_definitions = match statements.get_mut(&SectionKind::CompletedDefinitions)
|
|
|
|
|
{
|
|
|
|
|
Some(completed_definitions) => completed_definitions,
|
|
|
|
|
None => return Ok(()),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let completed_definition = match completed_definitions.iter().enumerate()
|
|
|
|
|
.find(matches_completed_definition)
|
|
|
|
|
{
|
|
|
|
|
Some((completed_definition_index, _)) =>
|
|
|
|
|
completed_definitions.remove(completed_definition_index).formula,
|
|
|
|
|
None => return Err(crate::Error::new_no_completed_definition_found(
|
|
|
|
|
std::rc::Rc::clone(hidden_predicate_declaration))),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
drop(completed_definitions);
|
|
|
|
|
|
|
|
|
|
for (_, statements) in statements.iter_mut()
|
|
|
|
|
{
|
|
|
|
|
for statement in statements.iter_mut()
|
|
|
|
|
{
|
|
|
|
|
crate::utils::replace_predicate_in_formula_with_completed_definition(
|
|
|
|
|
&mut statement.formula, &completed_definition, self)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
fn print_step_title(&self, step_title: &str, color: &termcolor::ColorSpec)
|
|
|
|
|
{
|
|
|
|
|
let longest_possible_key = " Finished";
|
|
|
|
|
|
|
|
|
|
self.shell.borrow_mut().print(
|
|
|
|
|
&format!("{:>step_title_width$} ", step_title,
|
|
|
|
|
step_title_width = longest_possible_key.chars().count()),
|
|
|
|
|
color);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 03:46:11 +02:00
|
|
|
|
pub fn prove(&self, proof_direction: ProofDirection) -> Result<(), crate::Error>
|
2020-05-05 19:40:57 +02:00
|
|
|
|
{
|
2020-05-11 03:46:11 +02:00
|
|
|
|
if proof_direction == ProofDirection::Forward
|
|
|
|
|
|| proof_direction == ProofDirection::Both
|
2020-05-05 19:40:57 +02:00
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
self.print_step_title("Started",
|
|
|
|
|
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)));
|
2020-05-13 02:24:13 +02:00
|
|
|
|
self.shell.borrow_mut().println(&"verification of assertions from translated program",
|
2020-05-12 04:25:49 +02:00
|
|
|
|
&termcolor::ColorSpec::new());
|
2020-05-05 19:40:57 +02:00
|
|
|
|
|
|
|
|
|
let mut statements = self.statements.borrow_mut();
|
|
|
|
|
|
|
|
|
|
// Initially reset all proof statuses
|
2020-05-11 03:11:10 +02:00
|
|
|
|
for (_, statements) in statements.iter_mut()
|
2020-05-05 19:40:57 +02:00
|
|
|
|
{
|
|
|
|
|
for statement in statements.iter_mut()
|
|
|
|
|
{
|
|
|
|
|
match statement.kind
|
|
|
|
|
{
|
|
|
|
|
StatementKind::Axiom
|
|
|
|
|
| StatementKind::Assumption
|
2020-05-13 02:24:13 +02:00
|
|
|
|
| StatementKind::CompletedDefinition(_)
|
|
|
|
|
| StatementKind::IntegrityConstraint =>
|
2020-05-11 03:11:10 +02:00
|
|
|
|
statement.proof_status = ProofStatus::AssumedProven,
|
2020-05-11 03:46:11 +02:00
|
|
|
|
StatementKind::Lemma(ProofDirection::Backward) =>
|
2020-05-07 17:19:42 +02:00
|
|
|
|
statement.proof_status = ProofStatus::Ignored,
|
2020-05-06 21:38:48 +02:00
|
|
|
|
_ => statement.proof_status = ProofStatus::ToProveLater,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop(statements);
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
let proof_result = self.prove_unproven_statements()?;
|
2020-05-05 19:40:57 +02:00
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
let mut step_title_color = termcolor::ColorSpec::new();
|
|
|
|
|
step_title_color.set_bold(true);
|
|
|
|
|
|
|
|
|
|
match proof_result
|
|
|
|
|
{
|
|
|
|
|
ProofResult::Proven => step_title_color.set_fg(Some(termcolor::Color::Green)),
|
|
|
|
|
ProofResult::NotProven => step_title_color.set_fg(Some(termcolor::Color::Yellow)),
|
|
|
|
|
ProofResult::Disproven => step_title_color.set_fg(Some(termcolor::Color::Red)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.print_step_title("Finished", &step_title_color);
|
2020-05-13 02:24:13 +02:00
|
|
|
|
println!("verification of assertions from translated program");
|
2020-05-11 05:03:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if proof_direction == ProofDirection::Both
|
|
|
|
|
{
|
|
|
|
|
println!("");
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
2020-05-11 03:46:11 +02:00
|
|
|
|
if proof_direction == ProofDirection::Backward
|
|
|
|
|
|| proof_direction == ProofDirection::Both
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
self.print_step_title("Started",
|
|
|
|
|
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)));
|
2020-05-13 02:24:13 +02:00
|
|
|
|
self.shell.borrow_mut().println(&"verification of translated program from assertions",
|
2020-05-12 04:25:49 +02:00
|
|
|
|
&termcolor::ColorSpec::new());
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
|
|
|
|
let mut statements = self.statements.borrow_mut();
|
|
|
|
|
|
|
|
|
|
// Initially reset all proof statuses
|
2020-05-11 03:11:10 +02:00
|
|
|
|
for (_, statements) in statements.iter_mut()
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
|
|
|
|
for statement in statements.iter_mut()
|
|
|
|
|
{
|
|
|
|
|
match statement.kind
|
|
|
|
|
{
|
|
|
|
|
StatementKind::Axiom
|
2020-05-07 02:53:48 +02:00
|
|
|
|
| StatementKind::Assumption
|
2020-05-07 17:19:42 +02:00
|
|
|
|
| StatementKind::Assertion =>
|
2020-05-11 03:11:10 +02:00
|
|
|
|
statement.proof_status = ProofStatus::AssumedProven,
|
2020-05-11 03:46:11 +02:00
|
|
|
|
StatementKind::Lemma(ProofDirection::Forward) =>
|
2020-05-07 17:19:42 +02:00
|
|
|
|
statement.proof_status = ProofStatus::Ignored,
|
2020-05-06 21:38:48 +02:00
|
|
|
|
_ => statement.proof_status = ProofStatus::ToProveLater,
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop(statements);
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
let proof_result = self.prove_unproven_statements()?;
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
let mut step_title_color = termcolor::ColorSpec::new();
|
|
|
|
|
step_title_color.set_bold(true);
|
|
|
|
|
|
|
|
|
|
match proof_result
|
|
|
|
|
{
|
|
|
|
|
ProofResult::Proven => step_title_color.set_fg(Some(termcolor::Color::Green)),
|
|
|
|
|
ProofResult::NotProven => step_title_color.set_fg(Some(termcolor::Color::Yellow)),
|
|
|
|
|
ProofResult::Disproven => step_title_color.set_fg(Some(termcolor::Color::Red)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.print_step_title("Finished", &step_title_color);
|
2020-05-13 02:24:13 +02:00
|
|
|
|
println!("verification of translated program from assertions");
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
2020-05-06 21:38:48 +02:00
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn next_unproven_statement_do_mut<F, G>(&self, mut functor: F) -> Option<G>
|
|
|
|
|
where
|
2020-05-13 03:16:51 +02:00
|
|
|
|
F: FnMut(&mut Statement) -> G,
|
2020-05-06 21:38:48 +02:00
|
|
|
|
{
|
|
|
|
|
for section in self.statements.borrow_mut().iter_mut()
|
|
|
|
|
{
|
|
|
|
|
for statement in section.1.iter_mut()
|
|
|
|
|
{
|
|
|
|
|
if statement.proof_status == ProofStatus::ToProveNow
|
|
|
|
|
|| statement.proof_status == ProofStatus::ToProveLater
|
|
|
|
|
{
|
2020-05-13 03:16:51 +02:00
|
|
|
|
return Some(functor(statement));
|
2020-05-06 21:38:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
fn prove_unproven_statements(&self) -> Result<ProofResult, crate::Error>
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
2020-05-13 07:41:01 +02:00
|
|
|
|
let display_statement = |statement: &Statement|
|
2020-05-11 03:11:10 +02:00
|
|
|
|
{
|
2020-05-11 05:03:59 +02:00
|
|
|
|
let step_title = match statement.proof_status
|
2020-05-11 03:11:10 +02:00
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
ProofStatus::AssumedProven => format!("Established"),
|
|
|
|
|
ProofStatus::Proven => format!("Verified"),
|
|
|
|
|
ProofStatus::NotProven
|
|
|
|
|
| ProofStatus::Disproven
|
|
|
|
|
| ProofStatus::ToProveNow => format!("Verifying"),
|
|
|
|
|
ProofStatus::ToProveLater => format!("Skipped"),
|
|
|
|
|
ProofStatus::Ignored => format!("Ignored"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut step_title_color = termcolor::ColorSpec::new();
|
|
|
|
|
step_title_color.set_bold(true);
|
|
|
|
|
|
|
|
|
|
match statement.proof_status
|
|
|
|
|
{
|
|
|
|
|
ProofStatus::AssumedProven
|
|
|
|
|
| ProofStatus::Proven => step_title_color.set_fg(Some(termcolor::Color::Green)),
|
|
|
|
|
ProofStatus::NotProven => step_title_color.set_fg(Some(termcolor::Color::Yellow)),
|
|
|
|
|
ProofStatus::Disproven => step_title_color.set_fg(Some(termcolor::Color::Red)),
|
|
|
|
|
_ => step_title_color.set_fg(Some(termcolor::Color::Cyan)),
|
2020-05-11 03:11:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
self.print_step_title(&step_title, &step_title_color);
|
|
|
|
|
|
2020-05-13 03:16:51 +02:00
|
|
|
|
self.shell.borrow_mut().print(&format!("{}: ", statement.kind),
|
2020-05-12 04:25:49 +02:00
|
|
|
|
&termcolor::ColorSpec::new());
|
2020-05-11 05:03:59 +02:00
|
|
|
|
|
2020-05-13 07:41:01 +02:00
|
|
|
|
let format_context = FormatContext
|
2020-05-11 03:11:10 +02:00
|
|
|
|
{
|
2020-05-13 07:41:01 +02:00
|
|
|
|
program_variable_declaration_ids:
|
|
|
|
|
std::cell::RefCell::new(VariableDeclarationIDs::new()),
|
|
|
|
|
integer_variable_declaration_ids:
|
|
|
|
|
std::cell::RefCell::new(VariableDeclarationIDs::new()),
|
|
|
|
|
input_constant_declaration_domains: &self.input_constant_declaration_domains.borrow(),
|
|
|
|
|
variable_declaration_domains: &self.variable_declaration_domains.borrow(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
print!("{}", foliage::format::display_formula(&statement.formula, &format_context));
|
2020-05-11 03:11:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Show all statements that are assumed to be proven
|
2020-05-13 03:16:51 +02:00
|
|
|
|
for (_, statements) in self.statements.borrow_mut().iter_mut()
|
2020-05-11 03:11:10 +02:00
|
|
|
|
{
|
|
|
|
|
for statement in statements.iter_mut()
|
|
|
|
|
.filter(|statement| statement.proof_status == ProofStatus::AssumedProven)
|
|
|
|
|
{
|
2020-05-13 07:41:01 +02:00
|
|
|
|
display_statement(statement);
|
2020-05-12 04:25:49 +02:00
|
|
|
|
println!("");
|
2020-05-11 03:11:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 21:38:48 +02:00
|
|
|
|
loop
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
2020-05-06 21:38:48 +02:00
|
|
|
|
match self.next_unproven_statement_do_mut(
|
2020-05-13 03:16:51 +02:00
|
|
|
|
|statement|
|
2020-05-06 21:38:48 +02:00
|
|
|
|
{
|
|
|
|
|
statement.proof_status = ProofStatus::ToProveNow;
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
print!("\x1b[s");
|
2020-05-13 07:41:01 +02:00
|
|
|
|
display_statement(statement);
|
2020-05-12 04:25:49 +02:00
|
|
|
|
print!("\x1b[u");
|
|
|
|
|
|
|
|
|
|
use std::io::Write as _;
|
|
|
|
|
std::io::stdout().flush();
|
2020-05-06 21:38:48 +02:00
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Some(_) => (),
|
2020-05-11 03:11:10 +02:00
|
|
|
|
// If there are no more unproven statements left, we’re done
|
2020-05-06 21:38:48 +02:00
|
|
|
|
None => break,
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 00:13:43 +02:00
|
|
|
|
let mut tptp_problem_to_prove_next_statement = "".to_string();
|
|
|
|
|
|
|
|
|
|
self.write_tptp_problem_to_prove_next_statement(
|
|
|
|
|
&mut tptp_problem_to_prove_next_statement)
|
|
|
|
|
.map_err(|error| crate::Error::new_write_tptp_program(error))?;
|
|
|
|
|
|
2020-05-07 17:19:42 +02:00
|
|
|
|
log::trace!("TPTP program:\n{}", &tptp_problem_to_prove_next_statement);
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
2020-05-06 21:38:48 +02:00
|
|
|
|
// TODO: make configurable again
|
|
|
|
|
let (proof_result, proof_time_seconds) =
|
|
|
|
|
run_vampire(&tptp_problem_to_prove_next_statement,
|
2020-05-13 07:41:01 +02:00
|
|
|
|
Some(&["--mode", "casc", "--cores", "8", "--time_limit", "300"]))?;
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
match self.next_unproven_statement_do_mut(
|
2020-05-13 03:16:51 +02:00
|
|
|
|
|statement|
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
statement.proof_status = match proof_result
|
|
|
|
|
{
|
|
|
|
|
ProofResult::Proven => ProofStatus::Proven,
|
|
|
|
|
ProofResult::NotProven => ProofStatus::NotProven,
|
|
|
|
|
ProofResult::Disproven => ProofStatus::Disproven,
|
|
|
|
|
};
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
self.shell.borrow_mut().erase_line();
|
2020-05-06 21:38:48 +02:00
|
|
|
|
|
2020-05-13 07:41:01 +02:00
|
|
|
|
display_statement(statement);
|
2020-05-06 21:38:48 +02:00
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
match proof_result
|
|
|
|
|
{
|
|
|
|
|
ProofResult::Proven => (),
|
|
|
|
|
ProofResult::NotProven => print!(" (not proven)"),
|
|
|
|
|
ProofResult::Disproven => print!(" (disproven)"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(proof_time_seconds) = proof_time_seconds
|
|
|
|
|
{
|
|
|
|
|
self.shell.borrow_mut().print(&format!(" in {} seconds", proof_time_seconds),
|
|
|
|
|
termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Black)).set_intense(true));
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-05-06 21:38:48 +02:00
|
|
|
|
{
|
|
|
|
|
Some(_) => (),
|
2020-05-12 04:25:49 +02:00
|
|
|
|
None => unreachable!(),
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
self.shell.borrow_mut().println(&"", &termcolor::ColorSpec::new());
|
|
|
|
|
|
|
|
|
|
if proof_result != ProofResult::Proven
|
2020-05-06 21:38:48 +02:00
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
return Ok(proof_result);
|
2020-05-06 21:38:48 +02:00
|
|
|
|
}
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 04:25:49 +02:00
|
|
|
|
Ok(ProofResult::Proven)
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 00:13:43 +02:00
|
|
|
|
fn write_tptp_problem_to_prove_next_statement(&self, formatter: &mut String) -> std::fmt::Result
|
|
|
|
|
{
|
|
|
|
|
use std::fmt::Write as _;
|
|
|
|
|
|
|
|
|
|
let format_context = FormatContext
|
|
|
|
|
{
|
|
|
|
|
program_variable_declaration_ids:
|
|
|
|
|
std::cell::RefCell::new(VariableDeclarationIDs::new()),
|
|
|
|
|
integer_variable_declaration_ids:
|
|
|
|
|
std::cell::RefCell::new(VariableDeclarationIDs::new()),
|
|
|
|
|
input_constant_declaration_domains: &self.input_constant_declaration_domains.borrow(),
|
|
|
|
|
variable_declaration_domains: &self.variable_declaration_domains.borrow(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let write_title = |formatter: &mut String, title, section_separator| -> std::fmt::Result
|
|
|
|
|
{
|
|
|
|
|
write!(formatter, "{}{}", section_separator, "%".repeat(72))?;
|
|
|
|
|
write!(formatter, "\n% {}", title)?;
|
|
|
|
|
writeln!(formatter, "\n{}", "%".repeat(72))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut section_separator = "";
|
|
|
|
|
|
|
|
|
|
write_title(formatter, "anthem types", section_separator)?;
|
|
|
|
|
section_separator = "\n";
|
|
|
|
|
|
|
|
|
|
let tptp_preamble_anthem_types
|
|
|
|
|
= include_str!("output/tptp/preamble_types.tptp").trim_end();
|
|
|
|
|
writeln!(formatter, "{}", tptp_preamble_anthem_types)?;
|
|
|
|
|
|
|
|
|
|
write_title(formatter, "anthem axioms", section_separator)?;
|
|
|
|
|
|
|
|
|
|
let tptp_preamble_anthem_types
|
|
|
|
|
= include_str!("output/tptp/preamble_axioms.tptp").trim_end();
|
|
|
|
|
writeln!(formatter, "{}", tptp_preamble_anthem_types)?;
|
|
|
|
|
|
|
|
|
|
if !self.predicate_declarations.borrow().is_empty()
|
|
|
|
|
|| !self.function_declarations.borrow().is_empty()
|
|
|
|
|
{
|
|
|
|
|
write_title(formatter, "types", section_separator)?;
|
|
|
|
|
|
|
|
|
|
if !self.predicate_declarations.borrow().is_empty()
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "% predicate types")?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for predicate_declaration in self.predicate_declarations.borrow().iter()
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "tff(type, type, {}).",
|
|
|
|
|
crate::output::tptp::display_predicate_declaration(predicate_declaration))?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !self.function_declarations.borrow().is_empty()
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "% function types")?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for function_declaration in self.function_declarations.borrow().iter()
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "tff(type, type, {}).",
|
|
|
|
|
crate::output::tptp::display_function_declaration(function_declaration,
|
|
|
|
|
&format_context))?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let function_declarations = self.function_declarations.borrow();
|
|
|
|
|
let symbolic_constants = function_declarations.iter().filter(
|
|
|
|
|
|x| !self.input_constant_declaration_domains.borrow().contains_key(*x));
|
|
|
|
|
|
|
|
|
|
let mut last_symbolic_constant: Option<std::rc::Rc<foliage::FunctionDeclaration>> =
|
|
|
|
|
None;
|
|
|
|
|
|
2020-05-13 01:28:25 +02:00
|
|
|
|
// TODO: put in axioms section
|
2020-05-06 00:13:43 +02:00
|
|
|
|
for (i, symbolic_constant) in symbolic_constants.enumerate()
|
|
|
|
|
{
|
|
|
|
|
// Order axioms are only necessary with two or more symbolic constants
|
|
|
|
|
if i == 1
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "% axioms for order of symbolic constants")?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if symbolic_constant.arity > 0
|
|
|
|
|
{
|
|
|
|
|
// TODO: refactor
|
|
|
|
|
unimplemented!("n-ary function declarations aren’t supported");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(last_symbolic_constant) = last_symbolic_constant
|
|
|
|
|
{
|
|
|
|
|
writeln!(formatter, "tff(symbolic_constant_order, axiom, p__less__({}, {})).",
|
|
|
|
|
last_symbolic_constant.name, symbolic_constant.name)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_symbolic_constant = Some(std::rc::Rc::clone(symbolic_constant));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (section_kind, statements) in self.statements.borrow().iter()
|
|
|
|
|
{
|
|
|
|
|
if statements.is_empty()
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let title = match section_kind
|
|
|
|
|
{
|
|
|
|
|
SectionKind::CompletedDefinitions => "completed definitions",
|
|
|
|
|
SectionKind::IntegrityConstraints => "integrity constraints",
|
|
|
|
|
SectionKind::Axioms => "axioms",
|
|
|
|
|
SectionKind::Assumptions => "assumptions",
|
|
|
|
|
SectionKind::Lemmas => "lemmas",
|
|
|
|
|
SectionKind::Assertions => "assertions",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
write_title(formatter, title, section_separator)?;
|
|
|
|
|
section_separator = "\n";
|
|
|
|
|
|
|
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
|
|
for statement in statements.iter()
|
|
|
|
|
{
|
2020-05-13 03:16:51 +02:00
|
|
|
|
if let StatementKind::CompletedDefinition(_) = statement.kind
|
2020-05-06 00:13:43 +02:00
|
|
|
|
{
|
2020-05-13 03:16:51 +02:00
|
|
|
|
writeln!(formatter, "% {}", statement.kind)?;
|
2020-05-06 00:13:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let name = match &statement.name
|
|
|
|
|
{
|
|
|
|
|
// TODO: refactor
|
|
|
|
|
Some(name) => name.clone(),
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
i += 1;
|
|
|
|
|
format!("statement_{}", i)
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let statement_type = match statement.proof_status
|
|
|
|
|
{
|
2020-05-12 04:25:49 +02:00
|
|
|
|
ProofStatus::AssumedProven
|
|
|
|
|
| ProofStatus::Proven => "axiom",
|
|
|
|
|
ProofStatus::NotProven
|
|
|
|
|
| ProofStatus::Disproven => unreachable!(),
|
2020-05-06 21:38:48 +02:00
|
|
|
|
ProofStatus::ToProveNow => "conjecture",
|
|
|
|
|
// Skip statements that will be proven later
|
|
|
|
|
ProofStatus::ToProveLater => continue,
|
|
|
|
|
// Skip statements that are not part of this proof
|
|
|
|
|
ProofStatus::Ignored => continue,
|
2020-05-06 00:13:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: add proper statement type
|
|
|
|
|
writeln!(formatter, "tff({}, {}, {}).", name, statement_type,
|
|
|
|
|
crate::output::tptp::display_formula(&statement.formula, &format_context))?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2020-05-05 19:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl foliage::FindOrCreateFunctionDeclaration for Problem
|
|
|
|
|
{
|
|
|
|
|
fn find_or_create_function_declaration(&self, name: &str, arity: usize)
|
|
|
|
|
-> std::rc::Rc<foliage::FunctionDeclaration>
|
|
|
|
|
{
|
|
|
|
|
let mut function_declarations = self.function_declarations.borrow_mut();
|
|
|
|
|
|
|
|
|
|
match function_declarations.iter().find(|x| x.name == name && x.arity == arity)
|
|
|
|
|
{
|
|
|
|
|
Some(declaration) => std::rc::Rc::clone(&declaration),
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
let declaration = foliage::FunctionDeclaration
|
|
|
|
|
{
|
|
|
|
|
name: name.to_string(),
|
|
|
|
|
arity,
|
|
|
|
|
};
|
|
|
|
|
let declaration = std::rc::Rc::new(declaration);
|
|
|
|
|
|
|
|
|
|
function_declarations.insert(std::rc::Rc::clone(&declaration));
|
|
|
|
|
|
|
|
|
|
log::debug!("new function declaration: {}/{}", name, arity);
|
|
|
|
|
|
|
|
|
|
declaration
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl foliage::FindOrCreatePredicateDeclaration for Problem
|
|
|
|
|
{
|
|
|
|
|
fn find_or_create_predicate_declaration(&self, name: &str, arity: usize)
|
|
|
|
|
-> std::rc::Rc<foliage::PredicateDeclaration>
|
|
|
|
|
{
|
|
|
|
|
let mut predicate_declarations = self.predicate_declarations.borrow_mut();
|
|
|
|
|
|
|
|
|
|
match predicate_declarations.iter().find(|x| x.name == name && x.arity == arity)
|
|
|
|
|
{
|
|
|
|
|
Some(declaration) => std::rc::Rc::clone(&declaration),
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
let declaration = foliage::PredicateDeclaration
|
|
|
|
|
{
|
|
|
|
|
name: name.to_string(),
|
|
|
|
|
arity,
|
|
|
|
|
};
|
|
|
|
|
let declaration = std::rc::Rc::new(declaration);
|
|
|
|
|
|
|
|
|
|
predicate_declarations.insert(std::rc::Rc::clone(&declaration));
|
|
|
|
|
|
|
|
|
|
log::debug!("new predicate declaration: {}/{}", name, arity);
|
|
|
|
|
|
|
|
|
|
declaration
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl crate::traits::AssignVariableDeclarationDomain for Problem
|
|
|
|
|
{
|
|
|
|
|
fn assign_variable_declaration_domain(&self,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>, domain: crate::Domain)
|
|
|
|
|
{
|
|
|
|
|
let mut variable_declaration_domains = self.variable_declaration_domains.borrow_mut();
|
|
|
|
|
|
|
|
|
|
match variable_declaration_domains.get(variable_declaration)
|
|
|
|
|
{
|
|
|
|
|
Some(current_domain) => assert_eq!(*current_domain, domain,
|
|
|
|
|
"inconsistent variable declaration domain"),
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
variable_declaration_domains
|
|
|
|
|
.insert(std::rc::Rc::clone(variable_declaration).into(), domain);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 07:41:01 +02:00
|
|
|
|
impl crate::traits::VariableDeclarationDomain for Problem
|
|
|
|
|
{
|
|
|
|
|
fn variable_declaration_domain(&self,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
|
|
|
|
|
-> Option<crate::Domain>
|
|
|
|
|
{
|
|
|
|
|
self.variable_declaration_domains.borrow().iter().find_map(
|
|
|
|
|
|(x, domain)|
|
|
|
|
|
match x == variable_declaration
|
|
|
|
|
{
|
|
|
|
|
true => Some(*domain),
|
|
|
|
|
false => None,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 19:40:57 +02:00
|
|
|
|
impl<'a, 'b> FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
fn variable_declaration_id(&self,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
|
|
|
|
|
-> usize
|
|
|
|
|
{
|
|
|
|
|
let mut variable_declaration_ids = match self.variable_declaration_domains
|
|
|
|
|
.get(variable_declaration)
|
|
|
|
|
{
|
|
|
|
|
Some(crate::Domain::Program) => self.program_variable_declaration_ids.borrow_mut(),
|
|
|
|
|
Some(crate::Domain::Integer) => self.integer_variable_declaration_ids.borrow_mut(),
|
|
|
|
|
None => unreachable!("all variables should be declared at this point"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match variable_declaration_ids.get(variable_declaration)
|
|
|
|
|
{
|
|
|
|
|
Some(id) => *id,
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
let id = variable_declaration_ids.len();
|
|
|
|
|
variable_declaration_ids.insert(std::rc::Rc::clone(variable_declaration).into(), id);
|
|
|
|
|
id
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b> crate::traits::InputConstantDeclarationDomain for FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
fn input_constant_declaration_domain(&self,
|
|
|
|
|
declaration: &std::rc::Rc<foliage::FunctionDeclaration>) -> crate::Domain
|
|
|
|
|
{
|
|
|
|
|
// Assume the program domain if not specified otherwise
|
|
|
|
|
self.input_constant_declaration_domains.get(declaration).map(|x| *x)
|
|
|
|
|
.unwrap_or(crate::Domain::Program)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b> crate::traits::VariableDeclarationDomain for FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
fn variable_declaration_domain(&self,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
|
|
|
|
|
-> Option<crate::Domain>
|
|
|
|
|
{
|
|
|
|
|
self.variable_declaration_domains.get(variable_declaration)
|
|
|
|
|
.map(|x| *x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b> crate::traits::VariableDeclarationID for FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
fn variable_declaration_id(&self,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
|
|
|
|
|
-> usize
|
|
|
|
|
{
|
|
|
|
|
use crate::traits::VariableDeclarationDomain;
|
|
|
|
|
|
|
|
|
|
let mut variable_declaration_ids = match self.variable_declaration_domain(
|
|
|
|
|
variable_declaration)
|
|
|
|
|
{
|
|
|
|
|
Some(crate::Domain::Program) => self.program_variable_declaration_ids.borrow_mut(),
|
|
|
|
|
Some(crate::Domain::Integer) => self.integer_variable_declaration_ids.borrow_mut(),
|
|
|
|
|
None => panic!("all variables should be declared at this point"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match variable_declaration_ids.get(variable_declaration)
|
|
|
|
|
{
|
|
|
|
|
Some(id) =>
|
|
|
|
|
{
|
|
|
|
|
*id
|
|
|
|
|
}
|
|
|
|
|
None =>
|
|
|
|
|
{
|
|
|
|
|
let id = variable_declaration_ids.len();
|
|
|
|
|
variable_declaration_ids.insert(std::rc::Rc::clone(variable_declaration).into(), id);
|
|
|
|
|
id
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b> foliage::format::Format for FormatContext<'a, 'b>
|
|
|
|
|
{
|
|
|
|
|
fn display_variable_declaration(&self, formatter: &mut std::fmt::Formatter,
|
|
|
|
|
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
|
|
|
|
|
-> std::fmt::Result
|
|
|
|
|
{
|
|
|
|
|
let id = self.variable_declaration_id(variable_declaration);
|
|
|
|
|
let domain = self.variable_declaration_domains.get(variable_declaration)
|
|
|
|
|
.expect("unspecified variable domain");
|
|
|
|
|
|
|
|
|
|
let prefix = match domain
|
|
|
|
|
{
|
|
|
|
|
crate::Domain::Integer => "N",
|
|
|
|
|
crate::Domain::Program => "X",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
write!(formatter, "{}{}", prefix, id + 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-06 21:38:48 +02:00
|
|
|
|
|
|
|
|
|
fn run_vampire<I, S>(input: &str, arguments: Option<I>)
|
|
|
|
|
-> Result<(ProofResult, Option<f32>), crate::Error>
|
|
|
|
|
where
|
|
|
|
|
I: IntoIterator<Item = S>, S: AsRef<std::ffi::OsStr>,
|
|
|
|
|
{
|
|
|
|
|
let mut vampire = std::process::Command::new("vampire");
|
|
|
|
|
|
|
|
|
|
let vampire = match arguments
|
|
|
|
|
{
|
|
|
|
|
Some(arguments) => vampire.args(arguments),
|
|
|
|
|
None => &mut vampire,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut vampire = vampire
|
|
|
|
|
.stdin(std::process::Stdio::piped())
|
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
|
.spawn()
|
|
|
|
|
.map_err(|error| crate::Error::new_run_vampire(error))?;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
use std::io::Write as _;
|
|
|
|
|
|
|
|
|
|
let vampire_stdin = vampire.stdin.as_mut().unwrap();
|
|
|
|
|
vampire_stdin.write_all(input.as_bytes())
|
|
|
|
|
.map_err(|error| crate::Error::new_run_vampire(error))?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let output = vampire.wait_with_output()
|
|
|
|
|
.map_err(|error| crate::Error::new_run_vampire(error))?;
|
|
|
|
|
|
|
|
|
|
let stdout = std::str::from_utf8(&output.stdout)
|
|
|
|
|
.map_err(|error| crate::Error::new_run_vampire(error))?;
|
|
|
|
|
|
|
|
|
|
let stderr = std::str::from_utf8(&output.stderr)
|
|
|
|
|
.map_err(|error| crate::Error::new_run_vampire(error))?;
|
|
|
|
|
|
|
|
|
|
if !output.status.success()
|
|
|
|
|
{
|
|
|
|
|
let proof_not_found_regex = regex::Regex::new(r"% \(\d+\)Proof not found in time").unwrap();
|
|
|
|
|
|
|
|
|
|
if proof_not_found_regex.is_match(stdout)
|
|
|
|
|
{
|
|
|
|
|
return Ok((ProofResult::NotProven, None));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Err(crate::Error::new_prove_program(output.status.code(), stdout.to_string(),
|
|
|
|
|
stderr.to_string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let proof_time_regex = regex::Regex::new(r"% \(\d+\)Success in time (\d+(?:\.\d+)?) s").unwrap();
|
|
|
|
|
|
|
|
|
|
let proof_time = proof_time_regex.captures(stdout)
|
|
|
|
|
.map(|captures| captures.get(1).unwrap().as_str().parse::<f32>().ok())
|
|
|
|
|
.unwrap_or(None);
|
|
|
|
|
|
|
|
|
|
let refutation_regex = regex::Regex::new(r"% \(\d+\)Termination reason: Refutation").unwrap();
|
|
|
|
|
|
|
|
|
|
if refutation_regex.is_match(stdout)
|
|
|
|
|
{
|
|
|
|
|
return Ok((ProofResult::Proven, proof_time));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: support disproven result
|
|
|
|
|
|
|
|
|
|
Err(crate::Error::new_parse_vampire_output(stdout.to_string(), stderr.to_string()))
|
|
|
|
|
}
|