Represent quantified formulas consistently

Existential and universal quantification used redundant data
representations, while they actually share the same structure. This
unifies both into a single QuantifiedFormula type.
This commit is contained in:
Patrick Lühne 2020-04-13 22:05:09 +02:00
parent 7566fdaa29
commit 7d22e47ba1
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF

View File

@ -246,31 +246,13 @@ impl Compare
} }
} }
pub struct Exists pub struct QuantifiedFormula
{ {
pub parameters: std::rc::Rc<VariableDeclarations>, pub parameters: std::rc::Rc<VariableDeclarations>,
pub argument: Box<Formula>, pub argument: Box<Formula>,
} }
impl Exists impl QuantifiedFormula
{
pub fn new(parameters: std::rc::Rc<VariableDeclarations>, argument: Box<Formula>) -> Self
{
Self
{
parameters,
argument,
}
}
}
pub struct ForAll
{
pub parameters: std::rc::Rc<VariableDeclarations>,
pub argument: Box<Formula>,
}
impl ForAll
{ {
pub fn new(parameters: std::rc::Rc<VariableDeclarations>, argument: Box<Formula>) -> Self pub fn new(parameters: std::rc::Rc<VariableDeclarations>, argument: Box<Formula>) -> Self
{ {
@ -449,8 +431,8 @@ pub enum Formula
And(Formulas), And(Formulas),
Boolean(bool), Boolean(bool),
Compare(Compare), Compare(Compare),
Exists(Exists), Exists(QuantifiedFormula),
ForAll(ForAll), ForAll(QuantifiedFormula),
IfAndOnlyIf(Formulas), IfAndOnlyIf(Formulas),
Implies(Implies), Implies(Implies),
Not(Box<Formula>), Not(Box<Formula>),
@ -483,7 +465,7 @@ impl Formula
{ {
assert!(!parameters.is_empty()); assert!(!parameters.is_empty());
Self::Exists(Exists::new(parameters, argument)) Self::Exists(QuantifiedFormula::new(parameters, argument))
} }
pub fn equal(left: Box<Term>, right: Box<Term>) -> Self pub fn equal(left: Box<Term>, right: Box<Term>) -> Self
@ -500,7 +482,7 @@ impl Formula
{ {
assert!(!parameters.is_empty()); assert!(!parameters.is_empty());
Self::ForAll(ForAll::new(parameters, argument)) Self::ForAll(QuantifiedFormula::new(parameters, argument))
} }
pub fn greater(left: Box<Term>, right: Box<Term>) -> Self pub fn greater(left: Box<Term>, right: Box<Term>) -> Self