Skip to main content

Cnf

Struct Cnf 

Source
pub struct Cnf { /* private fields */ }
Expand description

A CNF formula under construction: a variable table (atoms canonicalised so a = b and b = a share a variable) plus the accumulating clause set. Clone so a prepared premise CNF can be reused per goal — the of-pair Tseitin work is done once, then each cell only adds its ¬goal unit (incremental solving, the IPASIR pattern).

Implementations§

Source§

impl Cnf

Source

pub fn new() -> Self

Source

pub fn from_premises(premises: &[ProofExpr]) -> Option<Cnf>

Clausify a fixed premise set ONCE (the expensive of-pair Tseitin work), so many goals can be checked against it by cloning + adding ¬goal. None if any premise is not encodable. This is the incremental entry for solving a whole puzzle (16+ cells) without re-grounding or re-clausifying the shared premises every time.

Source

pub fn num_vars(&self) -> usize

Number of CDCL variables allocated (atoms + Tseitin auxiliaries).

Source

pub fn num_atoms(&self) -> usize

Number of distinct ATOM variables (the rest are Tseitin auxiliaries).

Source

pub fn clauses(&self) -> &[Vec<Lit>]

The accumulated clauses.

Source

pub fn atom_value(&self, e: &ProofExpr, model: &[bool]) -> Option<bool>

The Boolean value of atom e under a SAT model (a crate::cdcl::SolveResult::Sat assignment, indexed by variable), or None if e is not a recognised atom or was never encoded into this CNF. This decodes a model back to source atoms (e.g. signal@t), skipping the Tseitin auxiliaries that carry no source meaning.

Source

pub fn encode(&mut self, e: &ProofExpr) -> Option<Lit>

Tseitin-encode e, returning a literal whose truth equals e’s, and emitting the defining clauses for any auxiliary variables. Returns None if e is not a quantifier-free propositional formula over recognisable atoms (so the caller can fall back to another engine rather than silently mis-encode).

Source

pub fn assert(&mut self, e: &ProofExpr) -> Option<()>

Assert e as CNF, introducing auxiliary variables ONLY for genuinely non-clausal structure (a disjunct that is itself a conjunction — e.g. an of-pair disjunct). A top-level conjunction splits into separate clauses; a disjunction or implication flattens into ONE clause; a literal stays a literal. So a closure A∨B∨C∨D becomes a single clause with ZERO aux variables instead of a Tseitin spine. This structure-aware clausification (Plaisted & Greenbaum, 1986) is what keeps the CNF — and therefore the solve and the RUP replay — small. None if e is not encodable.

Source

pub fn assert_neg(&mut self, e: &ProofExpr) -> Option<()>

Assert the NEGATION of e (used to refute the goal). A literal goal becomes a unit clause; a compound goal asserts its De-Morgan dual, clause by clause.

Source

pub fn into_solver(self) -> Solver

Hand the accumulated CNF to a fresh CDCL solver.

Source

pub fn into_solver_with_atoms(self) -> (Solver, HashMap<String, Var>)

Like into_solver but also hands back the atom→variable map (moved, not cloned). Callers that need to decode a SAT model can do so from this small map instead of cloning the entire clause database just to keep the table alive.

Trait Implementations§

Source§

impl Clone for Cnf

Source§

fn clone(&self) -> Cnf

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Cnf

Source§

fn default() -> Cnf

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Cnf

§

impl RefUnwindSafe for Cnf

§

impl Send for Cnf

§

impl Sync for Cnf

§

impl Unpin for Cnf

§

impl UnsafeUnpin for Cnf

§

impl UnwindSafe for Cnf

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.