[−][src]Enum razor_fol::syntax::Formula
Is an abstract syntax tree (AST) for first-order formulae.
Variants
Is logical Top (⊤) or Truth
Is logical Bottom (⟘) or Falsehood
Is an atomic formula, made by applying predicate
on a list of terms
.
Represents an equality between two terms.
Note: Equality is a special type of atomic formula.
Makes the negation of the formula
that it holds.
Makes a conjunction of the left
and right
formulae that it holds.
Makes a disjunction of left
and right
formulae that it holds.
Makes an implication between left
and right
formulae that it holds.
Makes a bi-implication between left
and right
formulae that it holds.
Makes an existentially quantified formula with the bound variables
and the formula
that
it holds.
Makes a universally quantified formula with the bound variables
and the formula
that
it holds.
Methods
impl Formula
[src]
pub fn and(self, formula: Self) -> Self
[src]
Returns a conjunction of the receiver and formula
.
pub fn or(self, formula: Self) -> Self
[src]
Returns a disjunction of the receiver and formula
.
pub fn implies(self, formula: Self) -> Self
[src]
Returns an implication between the receiver and formula
.
pub fn iff(self, formula: Self) -> Self
[src]
Returns a bi-implication between the receiver and formula
.
pub fn free_vars(&self) -> Vec<&V>
[src]
Returns a list of free variable symbols in the receiver formula.
Note: In the list of free variables, each variable symbol appears only once even if it is present at multiple positions of the receiver formula.
Example:
// `x`, `y` and `z` are variable symbols: let x = V::from("x"); let y = V::from("y"); let z = V::from("z"); // (P(x) ∧ Q(x, f(g(x), y))) ∨ ('c = g(z)) let formula: Formula = "(P(x) & Q(x, f(g(x), y))) | 'c = g(z)".parse().unwrap(); assert_eq!(vec![&x, &y, &z].iter().sorted(), formula.free_vars().iter().sorted()); // ∀ x. P(x, y) let formula: Formula = "forall x. P(x, y)".parse().unwrap(); // notice that the bound variable `x` is not in the list of free variables of `formula` assert_eq!(vec![&y], formula.free_vars()); // ∃ x. P(x, y) let formula: Formula = "exists x. P(x, y)".parse().unwrap(); assert_eq!(vec![&y], formula.free_vars());
impl Formula
[src]
pub fn pnf(&self) -> Formula
[src]
Returns a Prenex Normal Form (PNF) equivalent to the receiver.
Hint: A PNF is a formula with all quantifiers (existential and universal) and bound variables at the front, followed by a quantifier-free part.
Example:
let formula: Formula = "Q(x, y) → ∃ x, y. P(x, y)".parse().unwrap(); assert_eq!("∃ x`, y`. (Q(x, y) → P(x`, y`))", formula.pnf().to_string());
pub fn snf(&self) -> Formula
[src]
Returns a Skolem Normal Form (SNF) equivalent to the receiver.
Hint: An SNF is a PNF with only universal quantifiers (see: https://en.wikipedia.org/wiki/Skolem_normal_form).
Example:
let formula: Formula = "∃ y. P(x, y)".parse().unwrap(); assert_eq!("P(x, sk#0(x))", formula.snf().to_string());
pub fn snf_with(&self, generator: &mut SkolemGenerator) -> Formula
[src]
Is similar to Formula::snf
but uses an existing SkolemGenerator
to avoid collision
when generating Skolem function names (including Skolem constants).
Example:
use razor_fol::transform::SkolemGenerator; let mut generator = SkolemGenerator::from("skolem"); let formula: Formula = "∃ y. P(x, y)".parse().unwrap(); assert_eq!("P(x, skolem0(x))", formula.snf_with(&mut generator).to_string());
pub fn nnf(&self) -> Formula
[src]
Returns an Negation Normal Form (NNF) equivalent to the receiver.
Hint: An NNF is a formula where negation is only applied to its atomic (including equations) sub-formulae.
Example:
let formula: Formula = "not (P(x) iff Q(y))".parse().unwrap(); assert_eq!("(P(x) ∧ (¬Q(y))) ∨ ((¬P(x)) ∧ Q(y))", formula.nnf().to_string());
pub fn cnf(&self) -> Formula
[src]
Returns a Conjunctive Normal Form (CNF) equivalent to the receiver.
Hint: A CNF is a formula that is a conjunction of zero or more clauses. A clause is a disjunction of atomic formulae (including equations).
Note: All free variables are assumed to be universally quantified.
Example:
let formula: Formula = "P(x) <=> Q(y)".parse().unwrap(); assert_eq!("((¬P(x)) ∨ Q(y)) ∧ ((¬Q(y)) ∨ P(x))", formula.cnf().to_string());
pub fn cnf_with(&self, generator: &mut SkolemGenerator) -> Formula
[src]
Is similar to Formula::cnf
but uses an existing SkolemGenerator
to avoid collision
when generating Skolem function names (including Skolem constants).
Note: The CNF transformation includes Skolemization.
Example:
use razor_fol::transform::SkolemGenerator; let mut generator = SkolemGenerator::from("s%"); let formula: Formula = "exists x. ((forall y. P(y) & Q(x, y)) -> R(x))".parse().unwrap(); assert_eq!("((¬P(\'s%1)) ∨ (¬Q(\'s%0, \'s%1))) ∨ R(\'s%0)", formula.cnf_with(&mut generator).to_string());
pub fn dnf(&self) -> Formula
[src]
Returns a Disjunctive Normal Form (DNF) equivalent to the receiver.
Hint: A DNF is a formula that is a disjunction of zero or more conjuncts. A conjunct is a conjunction of atomic formulae (including equations).
Note: All of the free variables are assumed to be universally quantified.
Example:
let formula: Formula = "P(x) iff Q(y)".parse().unwrap(); assert_eq!("(((¬P(x)) ∧ (¬Q(y))) ∨ ((¬P(x)) ∧ P(x))) ∨ ((Q(y) ∧ (¬Q(y))) ∨ (Q(y) ∧ P(x)))", formula.dnf().to_string());
pub fn dnf_with(&self, generator: &mut SkolemGenerator) -> Formula
[src]
Is similar to Formula::dnf
but uses an existing SkolemGenerator
to avoid collision
when generating Skolem function names (including Skolem constants).
Note: The DNF transformation includes Skolemization.
Example:
use razor_fol::transform::SkolemGenerator; let mut generator = SkolemGenerator::from("s%"); let formula: Formula = "!y. (!x. (P(y, x) | Q(x)) -> Q(y))".parse().unwrap(); assert_eq!("((¬P(y, s%0(y))) ∧ (¬Q(s%0(y)))) ∨ Q(y)", formula.dnf_with(&mut generator).to_string());
pub fn simplify(&self) -> Formula
[src]
Applies a number of syntactic transformations to simplify the receiver formula.
Example:
let formula: Formula = "not (not P())".parse().unwrap(); assert_eq!("P()", formula.simplify().to_string()); let formula: Formula = "forall x. (P() and true) | (Q(x) or false)".parse().unwrap(); assert_eq!("∀ x. (P() ∨ Q(x))", formula.simplify().to_string());
pub fn gnf(&self) -> Vec<Formula>
[src]
Returns a list of formulae in Geometric Normal Form (GNF), equivalent to the receiver.
Hint: For mor information about GNF, see Geometric Logic in Computer Science by Steve Vickers.
Example:
let formula: Formula = "P(x) & (Q(x) | R(x))".parse().unwrap(); let gnf_to_string: Vec<String> = formula.gnf().iter().map(|f| f.to_string()).collect(); assert_eq!(vec!["⊤ → P(x)", "⊤ → (Q(x) ∨ R(x))"], gnf_to_string);
pub fn gnf_with(&self, generator: &mut SkolemGenerator) -> Vec<Formula>
[src]
Is similar to Formula::gnf
but uses an existing SkolemGenerator
to avoid collision
when generating Skolem function names (including Skolem constants).
Note: The GNF transformation includes Skolemization.
Example:
use razor_fol::transform::SkolemGenerator; let mut generator = SkolemGenerator::from("s%"); let formula: Formula = "P(y) -> exists x. P(x) & Q(y)".parse().unwrap(); let gnf_to_string: Vec<String> = formula.gnf().iter().map(|f| f.to_string()).collect(); assert_eq!(vec!["P(y) → P(sk#0(y))", "P(y) → Q(y)"], gnf_to_string);
Trait Implementations
impl Clone for Formula
[src]
impl Debug for Formula
[src]
impl Display for Formula
[src]
impl Eq for Formula
[src]
impl FromStr for Formula
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Formula
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Formula
[src]
fn cmp(&self, other: &Formula) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Formula> for Formula
[src]
impl PartialOrd<Formula> for Formula
[src]
fn partial_cmp(&self, other: &Formula) -> Option<Ordering>
[src]
fn lt(&self, other: &Formula) -> bool
[src]
fn le(&self, other: &Formula) -> bool
[src]
fn gt(&self, other: &Formula) -> bool
[src]
fn ge(&self, other: &Formula) -> bool
[src]
impl StructuralEq for Formula
[src]
impl StructuralPartialEq for Formula
[src]
impl TermBased for Formula
[src]
fn transform(&self, f: &impl Fn(&Term) -> Term) -> Self
[src]
fn rename_vars(&self, renaming: &impl VariableRenaming) -> Self
[src]
Note: Applies a VariableRenaming
on the free variables of the formula, keeping
the bound variables unchanged.
fn substitute(&self, substitution: &impl Substitution) -> Self
[src]
Note: Applies a Substitution
on the free variables of the formula, keeping the
bound variables unchanged.
Auto Trait Implementations
impl RefUnwindSafe for Formula
impl Send for Formula
impl Sync for Formula
impl Unpin for Formula
impl UnwindSafe for Formula
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,