Skip to main content

Clause

Struct Clause 

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

A clause is a disjunction (OR) of literals.

In CNF (Conjunctive Normal Form), a formula is a conjunction (AND) of clauses, where each clause is a disjunction (OR) of literals.

§Properties

  • An empty clause is always unsatisfied (represents false)
  • A clause is satisfied if at least one of its literals is satisfied
  • Unit clauses (single literal) are important for unit propagation

§Memory Layout

The clause stores literals in a Vec which allows efficient iteration and provides good cache locality for clause evaluation.

Fields§

§literals: Vec<Literal>

The literals in this clause.

Implementations§

Source§

impl Clause

Source

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

Creates a new clause from a vector of literals.

§Arguments
  • literals - The literals forming this disjunction
§Example
use xlog_solve::{Clause, Literal};
// Create clause: (x0 OR NOT x1)
let clause = Clause::new(vec![
    Literal::positive(0),
    Literal::negative(1),
]);
Source

pub fn unit(literal: Literal) -> Self

Creates a unit clause (single literal).

Unit clauses are important in SAT solving for unit propagation.

§Arguments
  • literal - The single literal in this clause
Source

pub fn binary(a: Literal, b: Literal) -> Self

Creates a binary clause (two literals).

Binary clauses are common in many SAT encodings (implications, at-most-one, etc.).

§Arguments
  • a - The first literal
  • b - The second literal
Source

pub fn ternary(a: Literal, b: Literal, c: Literal) -> Self

Creates a ternary clause (three literals).

§Arguments
  • a - The first literal
  • b - The second literal
  • c - The third literal
Source

pub fn len(&self) -> usize

Returns the number of literals in this clause.

Source

pub fn is_empty(&self) -> bool

Returns true if this clause has no literals.

An empty clause is always unsatisfied.

Source

pub fn is_satisfied(&self, assignment: &[bool]) -> bool

Checks if this clause is satisfied by the given assignment.

A clause is satisfied if at least one of its literals evaluates to true. An empty clause is never satisfied.

§Arguments
  • assignment - A slice of boolean values for each variable
§Returns

true if the clause is satisfied, false otherwise.

§Example
use xlog_solve::{Clause, Literal};
let clause = Clause::new(vec![
    Literal::positive(0),
    Literal::negative(1),
]);
assert!(clause.is_satisfied(&[true, true]));  // x0=true satisfies
assert!(!clause.is_satisfied(&[false, true])); // neither satisfied
Source

pub fn count_satisfied(&self, assignment: &[bool]) -> usize

Counts how many literals in this clause are satisfied by the assignment.

This is useful for CLS solvers and MaxSAT evaluation.

§Arguments
  • assignment - A slice of boolean values for each variable
§Returns

The number of literals that evaluate to true.

Source

pub fn iter(&self) -> impl Iterator<Item = &Literal>

Returns an iterator over the literals in this clause.

Source

pub fn vars(&self) -> impl Iterator<Item = u32> + '_

Returns an iterator over the variable indices in this clause.

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 FromIterator<Literal> for Clause

Source§

fn from_iter<I: IntoIterator<Item = Literal>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Clause

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<'a> IntoIterator for &'a Clause

Source§

type Item = &'a Literal

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Literal>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Clause

Source§

type Item = Literal

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Literal>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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 Eq for Clause

Source§

impl StructuralPartialEq for Clause

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,