use super::common::*;
use super::fof::FOFTerm;
#[derive(Debug, Clone, PartialEq)]
pub enum CNFStatement<'a> {
Logical(CNFFormula<'a>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum CNFFormula<'a> {
Disjunction(Vec<CNFLiteral<'a>>),
Parens(Box<CNFFormula<'a>>),
}
impl<'a> CNFFormula<'a> {
pub fn disjunction(literals: Vec<CNFLiteral<'a>>) -> Self {
CNFFormula::Disjunction(literals)
}
pub fn literals(&self) -> Vec<&CNFLiteral<'a>> {
match self {
CNFFormula::Disjunction(lits) => lits.iter().collect(),
CNFFormula::Parens(inner) => inner.literals(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum CNFLiteral<'a> {
Positive(CNFAtomicFormula<'a>),
Negative(CNFAtomicFormula<'a>),
Equality(FOFTerm<'a>, FOFTerm<'a>),
Inequality(FOFTerm<'a>, FOFTerm<'a>),
}
impl<'a> CNFLiteral<'a> {
pub fn is_positive(&self) -> bool {
matches!(self, CNFLiteral::Positive(_) | CNFLiteral::Equality(_, _))
}
pub fn is_negative(&self) -> bool {
!self.is_positive()
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum CNFAtomicFormula<'a> {
Plain(AtomicWord<'a>, Vec<FOFTerm<'a>>),
Defined(DefinedWord<'a>, Vec<FOFTerm<'a>>),
System(SystemWord<'a>, Vec<FOFTerm<'a>>),
True,
False,
}
impl<'a> CNFAtomicFormula<'a> {
pub fn plain(predicate: AtomicWord<'a>, args: Vec<FOFTerm<'a>>) -> Self {
CNFAtomicFormula::Plain(predicate, args)
}
pub fn proposition(name: AtomicWord<'a>) -> Self {
CNFAtomicFormula::Plain(name, Vec::new())
}
}