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
impl Clause
Sourcepub fn unit(literal: Literal) -> Self
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
Sourcepub fn binary(a: Literal, b: Literal) -> Self
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 literalb- The second literal
Sourcepub fn ternary(a: Literal, b: Literal, c: Literal) -> Self
pub fn ternary(a: Literal, b: Literal, c: Literal) -> Self
Creates a ternary clause (three literals).
§Arguments
a- The first literalb- The second literalc- The third literal
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this clause has no literals.
An empty clause is always unsatisfied.
Sourcepub fn is_satisfied(&self, assignment: &[bool]) -> bool
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