Enum PropositionalFormula

Source
pub enum PropositionalFormula {
    Variable(Variable),
    Negation(Option<Box<PropositionalFormula>>),
    Conjunction(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>),
    Disjunction(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>),
    Implication(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>),
    Biimplication(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>),
}
Expand description

A propositional formula is defined inductively, conforming to the following BNF:

<formula>
    ::= <propositional-variable>
    | ( - <formula> )
    | ( <formula> ^ <formula>)
    | ( <formula> | <formula> )
    | ( <formula> -> <formula> )
    | ( <formula> <-> <formula> )

Notice the requirement for explicit parentheses around the unary and binary operators, which eliminates the requirement for operator precedence due to grammar ambiguity at the cost of being more verbose.

§Ownership, Interior Mutability and Optional Sub-formulas

Since we don’t need any fancy multiple-threading or multi-owner business, we’ll stick with the most trivial Box pointer indirection instead of the fancier alternatives:

  • Reference-counted smart pointer Rc
  • Atomically-reference-counted smart pointer Arc
  • Lifetime-bounded references &'a

We do not support interior mutability as we do not need it for our use cases with respect to the propositional formula AST.

We need sub-formulas to be wrapped in Option for construction purposes, so we can build a PropPropositionalFormula during parsing.

§No Default

We cannot soundly define a sane default for a PropositionalFormula – even in the base case of a single propositional variable, what would the default propositional variable be?

Variants§

§

Variable(Variable)

Base case: a single propositional variable.

§

Negation(Option<Box<PropositionalFormula>>)

Unary case: negated formula.

§

Conjunction(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>)

Binary formula with the main connective being the logical AND connective.

§

Disjunction(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>)

Binary formula with the main connective being the logical OR operator.

§

Implication(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>)

Binary formula with the main connective being the implication operator.

§

Biimplication(Option<Box<PropositionalFormula>>, Option<Box<PropositionalFormula>>)

Binary formula with the main connective being the biimplication operator.

Implementations§

Source§

impl PropositionalFormula

Source

pub fn variable(v: Variable) -> Self

Construct a new propositional formula from a propositional Variable.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let formula = PropositionalFormula::variable(Variable::new("a"));
println!("{:#?}", formula);
Source

pub fn negated(formula: Box<PropositionalFormula>) -> Self

Construct a new propositional formula from a sub propositional formula with negation.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let sub_formula = PropositionalFormula::variable(Variable::new("a"));
let formula = PropositionalFormula::negated(Box::new(sub_formula.clone()));
println!("{:#?}", formula);
Source

pub fn conjunction( left_sub_formula: Box<PropositionalFormula>, right_sub_formula: Box<PropositionalFormula>, ) -> Self

Construct a new propositional formula from two propositional sub-formulas with a conjunction main connective.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let sub_formula = PropositionalFormula::variable(Variable::new("a"));
let formula = PropositionalFormula::conjunction(Box::new(sub_formula.clone()), Box::new(sub_formula.clone()));
println!("{:#?}", formula);
Source

pub fn disjunction( left_sub_formula: Box<PropositionalFormula>, right_sub_formula: Box<PropositionalFormula>, ) -> Self

Construct a new propositional formula from two propositional sub-formulas with a disjunction main connective.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let sub_formula = PropositionalFormula::variable(Variable::new("a"));
let formula = PropositionalFormula::disjunction(Box::new(sub_formula.clone()), Box::new(sub_formula.clone()));
println!("{:#?}", formula);
Source

pub fn implication( left_sub_formula: Box<PropositionalFormula>, right_sub_formula: Box<PropositionalFormula>, ) -> Self

Construct a new propositional formula from two propositional sub-formulas with an implication main connective.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let sub_formula = PropositionalFormula::variable(Variable::new("a"));
let formula = PropositionalFormula::implication(Box::new(sub_formula.clone()), Box::new(sub_formula.clone()));
println!("{:#?}", formula);
Source

pub fn biimplication( left_sub_formula: Box<PropositionalFormula>, right_sub_formula: Box<PropositionalFormula>, ) -> Self

Construct a new propositional formula from two propositional sub-formulas with a biimplication main connective.

§Example
use libprop_sat_solver::formula::{PropositionalFormula, Variable};
let sub_formula = PropositionalFormula::variable(Variable::new("a"));
let formula = PropositionalFormula::biimplication(Box::new(sub_formula.clone()), Box::new(sub_formula.clone()));
println!("{:#?}", formula);
Source

pub fn is_literal(&self) -> bool

Checks if the given PropositionalFormula is a literal (either a propositional variable like p or its negation -p).

Trait Implementations§

Source§

impl Clone for PropositionalFormula

Source§

fn clone(&self) -> PropositionalFormula

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PropositionalFormula

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V> From<V> for PropositionalFormula
where V: Into<Variable>,

Source§

fn from(v: V) -> Self

Converts to this type from the input type.
Source§

impl Hash for PropositionalFormula

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PropositionalFormula

Source§

fn eq(&self, other: &PropositionalFormula) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PropositionalFormula

Source§

fn partial_cmp(&self, other: &PropositionalFormula) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for PropositionalFormula

Source§

impl StructuralPartialEq for PropositionalFormula

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.