Rename Statement to FormulaStatement

This commit is contained in:
Patrick Lühne 2019-11-07 01:12:26 -06:00
parent a206812d80
commit a802b9f8fd
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
5 changed files with 90 additions and 89 deletions

View File

@ -18,28 +18,28 @@ impl std::fmt::Display for crate::project::ProofDirection
} }
} }
impl std::fmt::Debug for crate::project::StatementKind impl std::fmt::Debug for crate::project::FormulaStatementKind
{ {
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{ {
match &self match &self
{ {
crate::project::StatementKind::Axiom => write!(format, "axiom"), crate::project::FormulaStatementKind::Axiom => write!(format, "axiom"),
crate::project::StatementKind::Completion( crate::project::FormulaStatementKind::Completion(
crate::project::CompletionTarget::Predicate(predicate_declaration)) crate::project::CompletionTarget::Predicate(predicate_declaration))
=> write!(format, "completion({}/{})", predicate_declaration.name, predicate_declaration.arity), => write!(format, "completion({}/{})", predicate_declaration.name, predicate_declaration.arity),
crate::project::StatementKind::Completion(crate::project::CompletionTarget::Constraint) crate::project::FormulaStatementKind::Completion(crate::project::CompletionTarget::Constraint)
=> write!(format, "completion(constraint)"), => write!(format, "completion(constraint)"),
crate::project::StatementKind::Assumption => write!(format, "assumption"), crate::project::FormulaStatementKind::Assumption => write!(format, "assumption"),
crate::project::StatementKind::Assertion => write!(format, "assertion"), crate::project::FormulaStatementKind::Assertion => write!(format, "assertion"),
crate::project::StatementKind::Lemma(None) => write!(format, "lemma"), crate::project::FormulaStatementKind::Lemma(None) => write!(format, "lemma"),
crate::project::StatementKind::Lemma(Some(crate::project::ProofDirection::Forward)) => write!(format, "lemma(forward)"), crate::project::FormulaStatementKind::Lemma(Some(crate::project::ProofDirection::Forward)) => write!(format, "lemma(forward)"),
crate::project::StatementKind::Lemma(Some(crate::project::ProofDirection::Backward)) => write!(format, "lemma(backward)"), crate::project::FormulaStatementKind::Lemma(Some(crate::project::ProofDirection::Backward)) => write!(format, "lemma(backward)"),
} }
} }
} }
impl std::fmt::Display for crate::project::StatementKind impl std::fmt::Display for crate::project::FormulaStatementKind
{ {
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{ {
@ -56,8 +56,8 @@ impl std::fmt::Debug for crate::Project
match block match block
{ {
crate::project::Block::Whitespace(ref text) => write!(format, "{}", text)?, crate::project::Block::Whitespace(ref text) => write!(format, "{}", text)?,
crate::project::Block::Statement(ref statement) => crate::project::Block::FormulaStatement(ref formula_statement) =>
write!(format, "{}", statement.original_text)?, write!(format, "{}", formula_statement.original_text)?,
} }
} }

View File

@ -4,52 +4,52 @@ pub trait DisplayTPTP<'a, DisplayType>
fn display_tptp(&'a self) -> DisplayType; fn display_tptp(&'a self) -> DisplayType;
} }
pub fn is_statement_axiom(statement: &crate::project::Statement, pub fn is_formula_statement_axiom(formula_statement: &crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection) -> bool proof_direction: crate::project::ProofDirection) -> bool
{ {
if statement.proven if formula_statement.proven
{ {
return true; return true;
} }
match (proof_direction, &statement.kind) match (proof_direction, &formula_statement.kind)
{ {
(_, crate::project::StatementKind::Axiom) => true, (_, crate::project::FormulaStatementKind::Axiom) => true,
(_, crate::project::StatementKind::Assumption) => true, (_, crate::project::FormulaStatementKind::Assumption) => true,
(crate::project::ProofDirection::Forward, crate::project::StatementKind::Completion(_)) => true, (crate::project::ProofDirection::Forward, crate::project::FormulaStatementKind::Completion(_)) => true,
(crate::project::ProofDirection::Backward, crate::project::StatementKind::Assertion) => true, (crate::project::ProofDirection::Backward, crate::project::FormulaStatementKind::Assertion) => true,
_ => false, _ => false,
} }
} }
pub fn is_statement_lemma(statement: &crate::project::Statement, pub fn is_formula_statement_lemma(formula_statement: &crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection) -> bool proof_direction: crate::project::ProofDirection) -> bool
{ {
if statement.proven if formula_statement.proven
{ {
return false; return false;
} }
match (proof_direction, &statement.kind) match (proof_direction, &formula_statement.kind)
{ {
(_, crate::project::StatementKind::Lemma(None)) => true, (_, crate::project::FormulaStatementKind::Lemma(None)) => true,
(proof_direction, crate::project::StatementKind::Lemma(Some(proof_direction_lemma))) => proof_direction == *proof_direction_lemma, (proof_direction, crate::project::FormulaStatementKind::Lemma(Some(proof_direction_lemma))) => proof_direction == *proof_direction_lemma,
_ => false, _ => false,
} }
} }
pub fn is_statement_theorem(statement: &crate::project::Statement, pub fn is_formula_statement_theorem(formula_statement: &crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection) -> bool proof_direction: crate::project::ProofDirection) -> bool
{ {
if statement.proven if formula_statement.proven
{ {
return false; return false;
} }
match (proof_direction, &statement.kind) match (proof_direction, &formula_statement.kind)
{ {
(crate::project::ProofDirection::Forward, crate::project::StatementKind::Assertion) => true, (crate::project::ProofDirection::Forward, crate::project::FormulaStatementKind::Assertion) => true,
(crate::project::ProofDirection::Backward, crate::project::StatementKind::Completion(_)) => true, (crate::project::ProofDirection::Backward, crate::project::FormulaStatementKind::Completion(_)) => true,
_ => false, _ => false,
} }
} }
@ -128,7 +128,7 @@ fn collect_predicate_declarations_in_project<'a>(project: &'a crate::Project)
match block match block
{ {
crate::project::Block::Whitespace(_) => None, crate::project::Block::Whitespace(_) => None,
crate::project::Block::Statement(ref statement) => Some(&statement.formula), crate::project::Block::FormulaStatement(ref formula_statement) => Some(&formula_statement.formula),
}); });
for formula in formulas for formula in formulas
@ -256,7 +256,7 @@ fn collect_symbolic_constants_in_project<'a>(project: &'a crate::Project)
match block match block
{ {
crate::project::Block::Whitespace(_) => None, crate::project::Block::Whitespace(_) => None,
crate::project::Block::Statement(ref statement) => Some(&statement.formula), crate::project::Block::FormulaStatement(ref formula_statement) => Some(&formula_statement.formula),
}); });
for formula in formulas for formula in formulas
@ -271,15 +271,15 @@ struct VariableDeclarationDisplay<'a>(&'a foliage::VariableDeclaration);
struct PredicateDeclarationDisplay<'a>(&'a foliage::PredicateDeclaration); struct PredicateDeclarationDisplay<'a>(&'a foliage::PredicateDeclaration);
struct TermDisplay<'a>(&'a foliage::Term); struct TermDisplay<'a>(&'a foliage::Term);
struct FormulaDisplay<'a>(&'a foliage::Formula); struct FormulaDisplay<'a>(&'a foliage::Formula);
struct StatementDisplay<'a> struct FormulaStatementDisplay<'a>
{ {
statement: &'a crate::project::Statement, formula_statement: &'a crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection, proof_direction: crate::project::ProofDirection,
} }
pub struct ProjectDisplay<'a> pub struct ProjectDisplay<'a>
{ {
project: &'a crate::project::Project, project: &'a crate::project::Project,
conjecture: &'a crate::project::Statement, conjecture: &'a crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection, proof_direction: crate::project::ProofDirection,
} }
@ -315,19 +315,19 @@ impl<'a> DisplayTPTP<'a, FormulaDisplay<'a>> for foliage::Formula
} }
} }
fn display_statement_tptp<'a>(statement: &'a crate::project::Statement, fn display_formula_statement_tptp<'a>(formula_statement: &'a crate::project::FormulaStatement,
proof_direction: crate::project::ProofDirection) proof_direction: crate::project::ProofDirection)
-> StatementDisplay<'a> -> FormulaStatementDisplay<'a>
{ {
StatementDisplay FormulaStatementDisplay
{ {
statement, formula_statement,
proof_direction, proof_direction,
} }
} }
pub fn display_project_with_conjecture_tptp<'a>(project: &'a crate::Project, pub fn display_project_with_conjecture_tptp<'a>(project: &'a crate::Project,
conjecture: &'a crate::project::Statement, proof_direction: crate::project::ProofDirection) conjecture: &'a crate::project::FormulaStatement, proof_direction: crate::project::ProofDirection)
-> ProjectDisplay<'a> -> ProjectDisplay<'a>
{ {
ProjectDisplay ProjectDisplay
@ -612,42 +612,42 @@ impl<'a> std::fmt::Display for FormulaDisplay<'a>
} }
} }
impl<'a> std::fmt::Debug for StatementDisplay<'a> impl<'a> std::fmt::Debug for FormulaStatementDisplay<'a>
{ {
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{ {
write!(format, "\ntff(")?; write!(format, "\ntff(")?;
let identifier = match &self.statement.kind let identifier = match &self.formula_statement.kind
{ {
crate::project::StatementKind::Axiom => "axiom", crate::project::FormulaStatementKind::Axiom => "axiom",
crate::project::StatementKind::Assumption => "assumption", crate::project::FormulaStatementKind::Assumption => "assumption",
crate::project::StatementKind::Completion(_) => "completion", crate::project::FormulaStatementKind::Completion(_) => "completion",
crate::project::StatementKind::Assertion => "assertion", crate::project::FormulaStatementKind::Assertion => "assertion",
crate::project::StatementKind::Lemma(_) => "lemma", crate::project::FormulaStatementKind::Lemma(_) => "lemma",
}; };
write!(format, "{}, ", identifier)?; write!(format, "{}, ", identifier)?;
if is_statement_theorem(&self.statement, self.proof_direction) if is_formula_statement_theorem(&self.formula_statement, self.proof_direction)
|| is_statement_lemma(&self.statement, self.proof_direction) || is_formula_statement_lemma(&self.formula_statement, self.proof_direction)
{ {
write!(format, "conjecture")?; write!(format, "conjecture")?;
} }
else if is_statement_axiom(&self.statement, self.proof_direction) else if is_formula_statement_axiom(&self.formula_statement, self.proof_direction)
{ {
write!(format, "axiom")?; write!(format, "axiom")?;
} }
else else
{ {
panic!("expected statement to be either theorem, lemma, or axiom, please report to bug tracker"); panic!("expected formula statement to be either theorem, lemma, or axiom, please report to bug tracker");
} }
write!(format, ", {:?}).", self.statement.formula.display_tptp()) write!(format, ", {:?}).", self.formula_statement.formula.display_tptp())
} }
} }
impl<'a> std::fmt::Display for StatementDisplay<'a> impl<'a> std::fmt::Display for FormulaStatementDisplay<'a>
{ {
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{ {
@ -700,22 +700,22 @@ impl<'a> std::fmt::Debug for ProjectDisplay<'a>
match block match block
{ {
crate::project::Block::Whitespace(_) => None, crate::project::Block::Whitespace(_) => None,
crate::project::Block::Statement(ref statement) => crate::project::Block::FormulaStatement(ref formula_statement) =>
match is_statement_axiom(&statement, self.proof_direction) match is_formula_statement_axiom(&formula_statement, self.proof_direction)
{ {
true => Some(statement), true => Some(formula_statement),
false => None, false => None,
} }
}); });
for axiom in axioms for axiom in axioms
{ {
write!(format, "\n{}", display_statement_tptp(&axiom, self.proof_direction))?; write!(format, "\n{}", display_formula_statement_tptp(&axiom, self.proof_direction))?;
} }
write_title(format, "\n\n", "assertion")?; write_title(format, "\n\n", "assertion")?;
write!(format, "\n{}", display_statement_tptp(&self.conjecture, self.proof_direction)) write!(format, "\n{}", display_formula_statement_tptp(&self.conjecture, self.proof_direction))
} }
} }

View File

@ -12,7 +12,7 @@ fn reset_proof_results<'a>(project: &'a mut ask_dracula::Project)
match block match block
{ {
ask_dracula::project::Block::Whitespace(_) => (), ask_dracula::project::Block::Whitespace(_) => (),
ask_dracula::project::Block::Statement(ref mut statement) => statement.proven = false, ask_dracula::project::Block::FormulaStatement(ref mut formula_statement) => formula_statement.proven = false,
} }
} }
} }
@ -128,10 +128,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
match block match block
{ {
ask_dracula::project::Block::Whitespace(_) => None, ask_dracula::project::Block::Whitespace(_) => None,
ask_dracula::project::Block::Statement(ref statement) => Some(statement), ask_dracula::project::Block::FormulaStatement(ref formula_statement) => Some(formula_statement),
} }
) )
.find(|statement| ask_dracula::format_tptp::is_statement_lemma(&statement, proof_direction)); .find(|formula_statement| ask_dracula::format_tptp::is_formula_statement_lemma(&formula_statement, proof_direction));
let conjecture = match conjecture let conjecture = match conjecture
{ {
@ -143,10 +143,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
match block match block
{ {
ask_dracula::project::Block::Whitespace(_) => None, ask_dracula::project::Block::Whitespace(_) => None,
ask_dracula::project::Block::Statement(ref statement) => Some(statement), ask_dracula::project::Block::FormulaStatement(ref formula_statement) => Some(formula_statement),
} }
) )
.find(|statement| ask_dracula::format_tptp::is_statement_theorem(&statement, proof_direction)), .find(|formula_statement| ask_dracula::format_tptp::is_formula_statement_theorem(&formula_statement, proof_direction)),
}; };
let conjecture = match conjecture let conjecture = match conjecture
@ -190,10 +190,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
match block match block
{ {
ask_dracula::project::Block::Whitespace(_) => None, ask_dracula::project::Block::Whitespace(_) => None,
ask_dracula::project::Block::Statement(ref mut statement) => Some(statement), ask_dracula::project::Block::FormulaStatement(ref mut formula_statement) => Some(formula_statement),
} }
) )
.find(|statement| ask_dracula::format_tptp::is_statement_lemma(&statement, proof_direction)); .find(|formula_statement| ask_dracula::format_tptp::is_formula_statement_lemma(&formula_statement, proof_direction));
let mut conjecture = match conjecture let mut conjecture = match conjecture
{ {
@ -205,10 +205,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
match block match block
{ {
ask_dracula::project::Block::Whitespace(_) => None, ask_dracula::project::Block::Whitespace(_) => None,
ask_dracula::project::Block::Statement(ref mut statement) => Some(statement), ask_dracula::project::Block::FormulaStatement(ref mut formula_statement) => Some(formula_statement),
} }
) )
.find(|statement| ask_dracula::format_tptp::is_statement_theorem(&statement, proof_direction)), .find(|formula_statement| ask_dracula::format_tptp::is_formula_statement_theorem(&formula_statement, proof_direction)),
}.unwrap(); }.unwrap();
conjecture.proven = true; conjecture.proven = true;

View File

@ -29,7 +29,7 @@ where
} }
} }
fn statement_kind(i: &str) -> IResult<&str, crate::project::StatementKind> fn formula_statement_kind(i: &str) -> IResult<&str, crate::project::FormulaStatementKind>
{ {
let foo = delimited let foo = delimited
( (
@ -39,12 +39,12 @@ fn statement_kind(i: &str) -> IResult<&str, crate::project::StatementKind>
map map
( (
tag("axiom:"), tag("axiom:"),
|_| crate::project::StatementKind::Axiom, |_| crate::project::FormulaStatementKind::Axiom,
), ),
map map
( (
tag("completion(constraint):"), tag("completion(constraint):"),
|_| crate::project::StatementKind::Completion(crate::project::CompletionTarget::Constraint), |_| crate::project::FormulaStatementKind::Completion(crate::project::CompletionTarget::Constraint),
), ),
map map
( (
@ -69,7 +69,7 @@ fn statement_kind(i: &str) -> IResult<&str, crate::project::StatementKind>
|(name, arity)| |(name, arity)|
match arity.parse::<usize>() match arity.parse::<usize>()
{ {
Ok(arity) => crate::project::StatementKind::Completion( Ok(arity) => crate::project::FormulaStatementKind::Completion(
crate::project::CompletionTarget::Predicate(foliage::PredicateDeclaration{name, arity})), crate::project::CompletionTarget::Predicate(foliage::PredicateDeclaration{name, arity})),
Err(error) => panic!("invalid arity “{}”: {}", arity, error), Err(error) => panic!("invalid arity “{}”: {}", arity, error),
} }
@ -77,27 +77,27 @@ fn statement_kind(i: &str) -> IResult<&str, crate::project::StatementKind>
map map
( (
tag("assumption:"), tag("assumption:"),
|_| crate::project::StatementKind::Assumption, |_| crate::project::FormulaStatementKind::Assumption,
), ),
map map
( (
tag("lemma(forward):"), tag("lemma(forward):"),
|_| crate::project::StatementKind::Lemma(Some(crate::project::ProofDirection::Forward)), |_| crate::project::FormulaStatementKind::Lemma(Some(crate::project::ProofDirection::Forward)),
), ),
map map
( (
tag("lemma(backward):"), tag("lemma(backward):"),
|_| crate::project::StatementKind::Lemma(Some(crate::project::ProofDirection::Backward)), |_| crate::project::FormulaStatementKind::Lemma(Some(crate::project::ProofDirection::Backward)),
), ),
map map
( (
tag("lemma:"), tag("lemma:"),
|_| crate::project::StatementKind::Lemma(None), |_| crate::project::FormulaStatementKind::Lemma(None),
), ),
map map
( (
tag("assertion:"), tag("assertion:"),
|_| crate::project::StatementKind::Assertion, |_| crate::project::FormulaStatementKind::Assertion,
), ),
)), )),
whitespace0, whitespace0,
@ -106,13 +106,13 @@ fn statement_kind(i: &str) -> IResult<&str, crate::project::StatementKind>
foo foo
} }
fn statement(i: &str) -> IResult<&str, (crate::project::StatementKind, foliage::Formula)> fn formula_statement(i: &str) -> IResult<&str, (crate::project::FormulaStatementKind, foliage::Formula)>
{ {
terminated terminated
( (
pair pair
( (
statement_kind, formula_statement_kind,
foliage::formula, foliage::formula,
), ),
preceded preceded
@ -123,12 +123,13 @@ fn statement(i: &str) -> IResult<&str, (crate::project::StatementKind, foliage::
)(i) )(i)
} }
fn statement_enclosed_by_whitespace(i: &str) -> IResult<&str, (&str, (&str, (crate::project::StatementKind, foliage::Formula)), &str)> fn formula_statement_enclosed_by_whitespace(i: &str)
-> IResult<&str, (&str, (&str, (crate::project::FormulaStatementKind, foliage::Formula)), &str)>
{ {
tuple tuple
(( ((
recognize(whitespace0), recognize(whitespace0),
recognize_and_keep(statement), recognize_and_keep(formula_statement),
recognize(whitespace0), recognize(whitespace0),
))(i) ))(i)
} }
@ -141,9 +142,9 @@ pub fn project(i: &str) -> IResult<&str, crate::Project>
loop loop
{ {
let i_ = statement_input.clone(); let i_ = statement_input.clone();
match statement_enclosed_by_whitespace(i_) match formula_statement_enclosed_by_whitespace(i_)
{ {
Ok((i, (whitespace_before, (statement_original_text, (statement_kind, formula)), whitespace_after))) => Ok((i, (whitespace_before, (formula_statement_original_text, (formula_statement_kind, formula)), whitespace_after))) =>
{ {
// Iteration must always consume input (to prevent infinite loops) // Iteration must always consume input (to prevent infinite loops)
if i == statement_input if i == statement_input
@ -156,15 +157,15 @@ pub fn project(i: &str) -> IResult<&str, crate::Project>
blocks.push(crate::project::Block::Whitespace(whitespace_before.to_string())); blocks.push(crate::project::Block::Whitespace(whitespace_before.to_string()));
} }
let statement = crate::project::Statement let formula_statement = crate::project::FormulaStatement
{ {
kind: statement_kind, kind: formula_statement_kind,
original_text: statement_original_text.to_string(), original_text: formula_statement_original_text.to_string(),
formula, formula,
proven: false, proven: false,
}; };
blocks.push(crate::project::Block::Statement(statement)); blocks.push(crate::project::Block::FormulaStatement(formula_statement));
if !whitespace_after.is_empty() if !whitespace_after.is_empty()
{ {

View File

@ -13,7 +13,7 @@ pub enum CompletionTarget
} }
#[derive(Eq, Hash, PartialEq)] #[derive(Eq, Hash, PartialEq)]
pub enum StatementKind pub enum FormulaStatementKind
{ {
Axiom, Axiom,
Completion(CompletionTarget), Completion(CompletionTarget),
@ -22,9 +22,9 @@ pub enum StatementKind
Assertion, Assertion,
} }
pub struct Statement pub struct FormulaStatement
{ {
pub kind: StatementKind, pub kind: FormulaStatementKind,
pub original_text: String, pub original_text: String,
pub formula: foliage::Formula, pub formula: foliage::Formula,
pub proven: bool, pub proven: bool,
@ -32,7 +32,7 @@ pub struct Statement
pub enum Block pub enum Block
{ {
Statement(Statement), FormulaStatement(FormulaStatement),
Whitespace(String), Whitespace(String),
} }