Skip to main content

Clause

Struct Clause 

Source
pub struct Clause {
    pub literals: Vec<Literal>,
}
Expand description

A clause is a disjunction of literals: L₁ ∨ L₂ ∨ ... ∨ Lₙ.

Special cases:

  • Empty clause (∅): contradiction, no literals
  • Unit clause: single literal
  • Horn clause: at most one positive literal

Fields§

§literals: Vec<Literal>

The literals in this clause (disjunction)

Implementations§

Source§

impl Clause

Source

pub fn from_literals(literals: Vec<Literal>) -> Self

Create a new clause from a list of literals.

Source

pub fn empty() -> Self

Create an empty clause (contradiction).

Source

pub fn unit(literal: Literal) -> Self

Create a unit clause (single literal).

Source

pub fn is_empty(&self) -> bool

Check if this is the empty clause (contradiction).

Source

pub fn is_unit(&self) -> bool

Check if this is a unit clause (single literal).

Source

pub fn is_horn(&self) -> bool

Check if this is a Horn clause (at most one positive literal).

Source

pub fn len(&self) -> usize

Get the number of literals in this clause.

Source

pub fn is_len_zero(&self) -> bool

Check if clause is empty (different from is_empty which checks for contradiction).

Source

pub fn free_vars(&self) -> HashSet<String>

Get all free variables in this clause.

Source

pub fn subsumes(&self, other: &Clause) -> bool

Check if this clause subsumes another (is more general).

Theta-Subsumption: Clause C subsumes D (C ⪯ D) if there exists a substitution θ such that Cθ ⊆ D.

This means C is more general than D. For example:

  • {P(x)} subsumes {P(a), Q(a)} with θ = {x/a}
  • {P(x), Q(x)} subsumes {P(a), Q(a), R(a)} with θ = {x/a}
§Implementation

We try to find a substitution by:

  1. For each literal in C, try to unify it with some literal in D
  2. Check if all substitutions are consistent
  3. If successful, C subsumes D
§Examples
use tensorlogic_ir::{TLExpr, Term, Literal, Clause};

// {P(x)} subsumes {P(a)}
let c = Clause::unit(Literal::positive(TLExpr::pred("P", vec![Term::var("x")])));
let d = Clause::unit(Literal::positive(TLExpr::pred("P", vec![Term::constant("a")])));
assert!(c.subsumes(&d));

// {P(a)} does not subsume {P(x)} (x is more general than a)
assert!(!d.subsumes(&c));
Source§

impl Clause

Source

pub fn is_tautology(&self) -> bool

Check if this clause is tautology (contains complementary literals).

Source

pub fn apply_substitution(&self, subst: &Substitution) -> Clause

Apply a substitution to this clause.

This creates a new clause with the substitution applied to all literals.

Source

pub fn rename_variables(&self, suffix: &str) -> Clause

Rename all variables in this clause with a suffix.

This is used for standardizing apart clauses before resolution to avoid variable name conflicts.

§Example
use tensorlogic_ir::{TLExpr, Term, Literal, Clause};

// P(x) ∨ Q(x)
let p_x = Literal::positive(TLExpr::pred("P", vec![Term::var("x")]));
let q_x = Literal::positive(TLExpr::pred("Q", vec![Term::var("x")]));
let clause = Clause::from_literals(vec![p_x, q_x]);

// Rename to P(x_1) ∨ Q(x_1)
let renamed = clause.rename_variables("1");

Trait Implementations§

Source§

impl Clone for Clause

Source§

fn clone(&self) -> Clause

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 Clause

Source§

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

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

impl<'de> Deserialize<'de> for Clause

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Clause

Source§

fn eq(&self, other: &Clause) -> 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 Serialize for Clause

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Clause

Auto Trait Implementations§

§

impl Freeze for Clause

§

impl RefUnwindSafe for Clause

§

impl Send for Clause

§

impl Sync for Clause

§

impl Unpin for Clause

§

impl UnwindSafe for Clause

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,