boofun.core.representations.dnf_form

Disjunctive Normal Form (DNF) representation for Boolean functions.

DNF represents a Boolean function as a disjunction (OR) of conjunctions (AND) of literals (variables or their negations).

Example: f(x₁,x₂,x₃) = (x₁ ∧ ¬x₂) ∨ (¬x₁ ∧ x₂ ∧ x₃)

Functions

create_dnf_from_minterms(minterms, n_vars)

Create DNF from list of minterm indices.

dnf_to_cnf(dnf)

Convert DNF to CNF using distribution laws.

minimize_dnf(dnf)

Minimize DNF using Quine-McCluskey algorithm (simplified).

Classes

DNFFormula(terms, n_vars)

DNF formula as a list of terms.

DNFRepresentation()

DNF representation for Boolean functions.

DNFTerm(positive_vars, negative_vars)

A single term (minterm) in DNF form.

class boofun.core.representations.dnf_form.DNFTerm(positive_vars: Set[int], negative_vars: Set[int])[source]

A single term (minterm) in DNF form.

positive_vars

Set of variables that appear positively

Type:

Set[int]

negative_vars

Set of variables that appear negatively

Type:

Set[int]

positive_vars: Set[int]
negative_vars: Set[int]
evaluate(x: List[int] | ndarray) bool[source]

Evaluate this DNF term.

Parameters:

x – Binary input vector

Returns:

Boolean result of this term

get_variables() Set[int][source]

Get all variables in this term.

to_string(var_names: List[str] | None = None) str[source]

Convert term to string representation.

Parameters:

var_names – Optional variable names, defaults to x₀, x₁, …

Returns:

String representation of the term

to_dict() Dict[str, Any][source]

Export term to dictionary.

classmethod from_dict(data: Dict[str, Any]) DNFTerm[source]

Create term from dictionary.

__init__(positive_vars: Set[int], negative_vars: Set[int]) None
class boofun.core.representations.dnf_form.DNFFormula(terms: List[DNFTerm], n_vars: int)[source]

DNF formula as a list of terms.

terms

List of DNF terms

Type:

List[boofun.core.representations.dnf_form.DNFTerm]

n_vars

Number of variables

Type:

int

terms: List[DNFTerm]
n_vars: int
evaluate(x: List[int] | ndarray) bool[source]

Evaluate DNF formula.

Parameters:

x – Binary input vector

Returns:

Boolean result (OR of all terms)

add_term(term: DNFTerm) None[source]

Add a term to the DNF formula.

simplify() DNFFormula[source]

Simplify DNF by removing redundant terms.

Returns:

Simplified DNF formula

to_string(var_names: List[str] | None = None) str[source]

Convert DNF to string representation.

Parameters:

var_names – Optional variable names

Returns:

String representation of DNF

to_dict() Dict[str, Any][source]

Export DNF to dictionary.

classmethod from_dict(data: Dict[str, Any]) DNFFormula[source]

Create DNF from dictionary.

__init__(terms: List[DNFTerm], n_vars: int) None
class boofun.core.representations.dnf_form.DNFRepresentation[source]

DNF representation for Boolean functions.

evaluate(inputs: ndarray, data: DNFFormula, space: Space, n_vars: int) bool | ndarray[source]

Evaluate DNF representation.

Parameters:
  • inputs – Input values (integer indices or binary vectors)

  • data – DNF formula

  • space – Evaluation space

  • n_vars – Number of variables

Returns:

Boolean result(s)

dump(data: DNFFormula, space=None, **kwargs) Dict[str, Any][source]

Export DNF representation.

convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) DNFFormula[source]

Convert from another representation to DNF.

Uses truth table method to generate minterms.

convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]

Convert DNF to another representation.

create_empty(n_vars: int, **kwargs) DNFFormula[source]

Create empty DNF (constant False).

is_complete(data: DNFFormula) bool[source]

Check if DNF is complete.

time_complexity_rank(n_vars: int) Dict[str, int][source]

Return time complexity for DNF operations.

get_storage_requirements(n_vars: int) Dict[str, int][source]

Return storage requirements for DNF representation.

boofun.core.representations.dnf_form.create_dnf_from_minterms(minterms: List[int], n_vars: int) DNFFormula[source]

Create DNF from list of minterm indices.

Parameters:
  • minterms – List of minterm indices where function is True

  • n_vars – Number of variables

Returns:

DNF formula

boofun.core.representations.dnf_form.minimize_dnf(dnf: DNFFormula) DNFFormula[source]

Minimize DNF using Quine-McCluskey algorithm (simplified).

Parameters:

dnf – DNF formula to minimize

Returns:

Minimized DNF formula