pub struct Literal {
pub atom: TLExpr,
pub polarity: bool,
}Expand description
A literal is an atomic formula or its negation.
Fields§
§atom: TLExprThe underlying atomic formula
polarity: boolTrue if positive literal, false if negative
Implementations§
Source§impl Literal
impl Literal
Sourcepub fn is_complementary(&self, other: &Literal) -> bool
pub fn is_complementary(&self, other: &Literal) -> bool
Check if this literal is complementary to another (same atom, opposite polarity).
For ground literals (no variables), this checks exact equality.
Sourcepub fn try_unify(&self, other: &Literal) -> Option<Substitution>
pub fn try_unify(&self, other: &Literal) -> Option<Substitution>
Attempt to unify this literal with another for resolution.
Returns the most general unifier (MGU) if the atoms can be unified and the polarities are opposite.
This is used for first-order resolution with variables.
§Examples
use tensorlogic_ir::{TLExpr, Term, Literal};
// P(x) and ¬P(a) can be unified with {x/a}
let p_x = Literal::positive(TLExpr::pred("P", vec![Term::var("x")]));
let not_p_a = Literal::negative(TLExpr::pred("P", vec![Term::constant("a")]));
let mgu = p_x.try_unify(¬_p_a);
assert!(mgu.is_some());Sourcepub fn apply_substitution(&self, subst: &Substitution) -> Literal
pub fn apply_substitution(&self, subst: &Substitution) -> Literal
Apply a substitution to this literal.
This creates a new literal with the substitution applied to all terms.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if this is a positive literal.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if this is a negative literal.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Literal
impl<'de> Deserialize<'de> for Literal
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more