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
impl Clause
Sourcepub fn from_literals(literals: Vec<Literal>) -> Self
pub fn from_literals(literals: Vec<Literal>) -> Self
Create a new clause from a list of literals.
Sourcepub fn is_len_zero(&self) -> bool
pub fn is_len_zero(&self) -> bool
Check if clause is empty (different from is_empty which checks for contradiction).
Sourcepub fn subsumes(&self, other: &Clause) -> bool
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:
- For each literal in C, try to unify it with some literal in D
- Check if all substitutions are consistent
- 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
impl Clause
Sourcepub fn is_tautology(&self) -> bool
pub fn is_tautology(&self) -> bool
Check if this clause is tautology (contains complementary literals).
Sourcepub fn apply_substitution(&self, subst: &Substitution) -> Clause
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.
Sourcepub fn rename_variables(&self, suffix: &str) -> Clause
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");