pub mod cnf;
pub mod common;
mod display;
pub mod fof;
pub mod tcf;
pub mod tff;
pub mod thf;
pub use cnf::*;
pub use common::*;
pub use fof::*;
pub use tcf::*;
pub use tff::*;
pub use thf::*;
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
pub struct TPTPProblem<'a> {
pub includes: Vec<Include<'a>>,
pub formulas: Vec<AnnotatedFormula<'a>>,
pub formula_comments: HashMap<&'a str, Vec<Comment<'a>>>,
}
impl<'a> Default for TPTPProblem<'a> {
fn default() -> Self {
Self::new()
}
}
impl<'a> TPTPProblem<'a> {
pub fn new() -> Self {
TPTPProblem {
includes: Vec::new(),
formulas: Vec::new(),
formula_comments: HashMap::new(),
}
}
pub fn formulas_by_role(
&self,
role: FormulaRole,
) -> impl Iterator<Item = &AnnotatedFormula<'a>> + '_ {
self.formulas.iter().filter(move |f| f.role() == role)
}
pub fn axioms(&self) -> impl Iterator<Item = &AnnotatedFormula<'a>> + '_ {
self.formulas_by_role(FormulaRole::Axiom)
}
pub fn conjectures(&self) -> impl Iterator<Item = &AnnotatedFormula<'a>> + '_ {
self.formulas_by_role(FormulaRole::Conjecture)
}
pub fn fof_formulas(&self) -> impl Iterator<Item = &FOFAnnotated<'a>> + '_ {
self.formulas.iter().filter_map(|f| f.as_fof())
}
pub fn tff_formulas(&self) -> impl Iterator<Item = &TFFAnnotated<'a>> + '_ {
self.formulas.iter().filter_map(|f| f.as_tff())
}
pub fn thf_formulas(&self) -> impl Iterator<Item = &THFAnnotated<'a>> + '_ {
self.formulas.iter().filter_map(|f| f.as_thf())
}
pub fn cnf_formulas(&self) -> impl Iterator<Item = &CNFAnnotated<'a>> + '_ {
self.formulas.iter().filter_map(|f| f.as_cnf())
}
pub fn tcf_formulas(&self) -> impl Iterator<Item = &TCFAnnotated<'a>> + '_ {
self.formulas.iter().filter_map(|f| f.as_tcf())
}
pub fn comments_for(&self, name: &str) -> &[Comment<'a>] {
self.formula_comments
.get(name)
.map(Vec::as_slice)
.unwrap_or(&[])
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Include<'a> {
pub file_name: &'a str,
pub selection: Option<Vec<common::Name<'a>>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Comment<'a> {
pub content: &'a str,
pub is_block: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AnnotatedFormula<'a> {
THF(THFAnnotated<'a>),
TFF(TFFAnnotated<'a>),
FOF(FOFAnnotated<'a>),
TCF(TCFAnnotated<'a>),
CNF(CNFAnnotated<'a>),
TPI(TPIAnnotated<'a>),
}
impl<'a> AnnotatedFormula<'a> {
pub fn name(&self) -> &'a str {
match self {
AnnotatedFormula::THF(f) => f.name.as_str(),
AnnotatedFormula::TFF(f) => f.name.as_str(),
AnnotatedFormula::FOF(f) => f.name.as_str(),
AnnotatedFormula::TCF(f) => f.name.as_str(),
AnnotatedFormula::CNF(f) => f.name.as_str(),
AnnotatedFormula::TPI(f) => f.name.as_str(),
}
}
pub fn role(&self) -> FormulaRole {
match self {
AnnotatedFormula::THF(f) => f.role,
AnnotatedFormula::TFF(f) => f.role,
AnnotatedFormula::FOF(f) => f.role,
AnnotatedFormula::TCF(f) => f.name_to_role(),
AnnotatedFormula::CNF(f) => f.role,
AnnotatedFormula::TPI(f) => f.role,
}
}
pub fn annotations(&self) -> Option<&Annotations<'a>> {
match self {
AnnotatedFormula::THF(f) => f.annotations.as_ref(),
AnnotatedFormula::TFF(f) => f.annotations.as_ref(),
AnnotatedFormula::FOF(f) => f.annotations.as_ref(),
AnnotatedFormula::TCF(f) => f.annotations.as_ref(),
AnnotatedFormula::CNF(f) => f.annotations.as_ref(),
AnnotatedFormula::TPI(f) => f.annotations.as_ref(),
}
}
pub fn as_fof(&self) -> Option<&FOFAnnotated<'a>> {
if let AnnotatedFormula::FOF(f) = self {
Some(f)
} else {
None
}
}
pub fn as_tff(&self) -> Option<&TFFAnnotated<'a>> {
if let AnnotatedFormula::TFF(f) = self {
Some(f)
} else {
None
}
}
pub fn as_thf(&self) -> Option<&THFAnnotated<'a>> {
if let AnnotatedFormula::THF(f) = self {
Some(f)
} else {
None
}
}
pub fn as_cnf(&self) -> Option<&CNFAnnotated<'a>> {
if let AnnotatedFormula::CNF(f) = self {
Some(f)
} else {
None
}
}
pub fn as_tcf(&self) -> Option<&TCFAnnotated<'a>> {
if let AnnotatedFormula::TCF(f) = self {
Some(f)
} else {
None
}
}
pub fn as_tpi(&self) -> Option<&TPIAnnotated<'a>> {
if let AnnotatedFormula::TPI(f) = self {
Some(f)
} else {
None
}
}
pub fn is_fof(&self) -> bool {
matches!(self, AnnotatedFormula::FOF(_))
}
pub fn is_tff(&self) -> bool {
matches!(self, AnnotatedFormula::TFF(_))
}
pub fn is_thf(&self) -> bool {
matches!(self, AnnotatedFormula::THF(_))
}
pub fn is_cnf(&self) -> bool {
matches!(self, AnnotatedFormula::CNF(_))
}
pub fn is_tcf(&self) -> bool {
matches!(self, AnnotatedFormula::TCF(_))
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct THFAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: thf::THFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TFFAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: tff::TFFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FOFAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: fof::FOFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TCFAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: tcf::TCFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
impl<'a> TCFAnnotated<'a> {
fn name_to_role(&self) -> FormulaRole {
self.role
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CNFAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: cnf::CNFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TPIAnnotated<'a> {
pub name: common::Name<'a>,
pub role: FormulaRole,
pub formula: fof::FOFStatement<'a>,
pub annotations: Option<Annotations<'a>>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FormulaRole {
Axiom,
AxiomLocal,
Hypothesis,
Definition,
Assumption,
Lemma,
Theorem,
Corollary,
Conjecture,
NegatedConjecture,
Plain,
Type,
Interpretation,
FiDomain,
FiFunctors,
FiPredicates,
Logic,
Unknown,
}
impl FormulaRole {
pub fn parse(s: &str) -> Option<FormulaRole> {
match s {
"axiom" => Some(FormulaRole::Axiom),
"axiom-local" => Some(FormulaRole::AxiomLocal),
"hypothesis" => Some(FormulaRole::Hypothesis),
"definition" => Some(FormulaRole::Definition),
"assumption" => Some(FormulaRole::Assumption),
"lemma" => Some(FormulaRole::Lemma),
"theorem" => Some(FormulaRole::Theorem),
"corollary" => Some(FormulaRole::Corollary),
"conjecture" => Some(FormulaRole::Conjecture),
"negated_conjecture" => Some(FormulaRole::NegatedConjecture),
"plain" => Some(FormulaRole::Plain),
"type" => Some(FormulaRole::Type),
"interpretation" => Some(FormulaRole::Interpretation),
"fi_domain" => Some(FormulaRole::FiDomain),
"fi_functors" => Some(FormulaRole::FiFunctors),
"fi_predicates" => Some(FormulaRole::FiPredicates),
"logic" => Some(FormulaRole::Logic),
"unknown" => Some(FormulaRole::Unknown),
_ => None,
}
}
pub fn as_str(&self) -> &'static str {
match self {
FormulaRole::Axiom => "axiom",
FormulaRole::AxiomLocal => "axiom-local",
FormulaRole::Hypothesis => "hypothesis",
FormulaRole::Definition => "definition",
FormulaRole::Assumption => "assumption",
FormulaRole::Lemma => "lemma",
FormulaRole::Theorem => "theorem",
FormulaRole::Corollary => "corollary",
FormulaRole::Conjecture => "conjecture",
FormulaRole::NegatedConjecture => "negated_conjecture",
FormulaRole::Plain => "plain",
FormulaRole::Type => "type",
FormulaRole::Interpretation => "interpretation",
FormulaRole::FiDomain => "fi_domain",
FormulaRole::FiFunctors => "fi_functors",
FormulaRole::FiPredicates => "fi_predicates",
FormulaRole::Logic => "logic",
FormulaRole::Unknown => "unknown",
}
}
pub fn is_axiom(self) -> bool {
matches!(self, FormulaRole::Axiom | FormulaRole::AxiomLocal)
}
pub fn is_hypothesis(self) -> bool {
self == FormulaRole::Hypothesis
}
pub fn is_assumption(self) -> bool {
self == FormulaRole::Assumption
}
pub fn is_definition(self) -> bool {
self == FormulaRole::Definition
}
pub fn is_lemma(self) -> bool {
self == FormulaRole::Lemma
}
pub fn is_theorem(self) -> bool {
self == FormulaRole::Theorem
}
pub fn is_corollary(self) -> bool {
self == FormulaRole::Corollary
}
pub fn is_conjecture(self) -> bool {
self == FormulaRole::Conjecture
}
pub fn is_negated_conjecture(self) -> bool {
self == FormulaRole::NegatedConjecture
}
pub fn is_type_declaration(self) -> bool {
self == FormulaRole::Type
}
pub fn is_goal(self) -> bool {
matches!(
self,
FormulaRole::Conjecture | FormulaRole::NegatedConjecture
)
}
pub fn is_premise(self) -> bool {
matches!(
self,
FormulaRole::Axiom
| FormulaRole::AxiomLocal
| FormulaRole::Hypothesis
| FormulaRole::Assumption
| FormulaRole::Definition
| FormulaRole::Lemma
| FormulaRole::Theorem
| FormulaRole::Corollary
)
}
pub fn is_derived(self) -> bool {
matches!(
self,
FormulaRole::Lemma | FormulaRole::Theorem | FormulaRole::Corollary
)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Annotations<'a> {
pub source: GeneralTerm<'a>,
pub useful_info: Option<Vec<GeneralTerm<'a>>>,
}