boofun.core.representations.cnf_form
Conjunctive Normal Form (CNF) representation for Boolean functions.
CNF represents a Boolean function as a conjunction (AND) of disjunctions (OR) of literals (variables or their negations).
Example: f(x₁,x₂,x₃) = (x₁ ∨ ¬x₂) ∧ (¬x₁ ∨ x₂ ∨ x₃)
Functions
|
Convert CNF to DNF using distribution laws. |
|
Create CNF from list of maxterm indices. |
|
Check if CNF formula is satisfiable (SAT problem). |
Classes
|
A single clause in CNF form. |
|
CNF formula as a list of clauses. |
CNF representation for Boolean functions. |
- class boofun.core.representations.cnf_form.CNFClause(positive_vars: Set[int], negative_vars: Set[int])[source]
A single clause in CNF form.
- evaluate(x: List[int] | ndarray) bool[source]
Evaluate this CNF clause.
- Parameters:
x – Binary input vector
- Returns:
Boolean result of this clause (OR of all literals)
- class boofun.core.representations.cnf_form.CNFFormula(clauses: List[CNFClause], n_vars: int)[source]
CNF formula as a list of clauses.
- clauses
List of CNF clauses
- Type:
- evaluate(x: List[int] | ndarray) bool[source]
Evaluate CNF formula.
- Parameters:
x – Binary input vector
- Returns:
Boolean result (AND of all clauses)
- simplify() CNFFormula[source]
Simplify CNF by removing tautologies and redundant clauses.
- Returns:
Simplified CNF formula
- class boofun.core.representations.cnf_form.CNFRepresentation[source]
CNF representation for Boolean functions.
- evaluate(inputs: ndarray, data: CNFFormula, space: Space, n_vars: int) bool | ndarray[source]
Evaluate CNF representation.
- Parameters:
inputs – Input values (integer indices or binary vectors)
data – CNF formula
space – Evaluation space
n_vars – Number of variables
- Returns:
Boolean result(s)
- convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) CNFFormula[source]
Convert from another representation to CNF.
Uses truth table method to generate maxterms.
- convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert CNF to another representation.
- create_empty(n_vars: int, **kwargs) CNFFormula[source]
Create empty CNF (constant True).
- is_complete(data: CNFFormula) bool[source]
Check if CNF is complete.
- boofun.core.representations.cnf_form.create_cnf_from_maxterms(maxterms: List[int], n_vars: int) CNFFormula[source]
Create CNF from list of maxterm indices.
- Parameters:
maxterms – List of maxterm indices where function is False
n_vars – Number of variables
- Returns:
CNF formula
- boofun.core.representations.cnf_form.is_satisfiable(cnf: CNFFormula) bool[source]
Check if CNF formula is satisfiable (SAT problem).
This is a simplified check - full SAT solving is NP-complete.