boofun.core.io
File I/O for Boolean functions.
Supports multiple formats: - JSON: Full representation with metadata - .bf: Scott Aaronson’s Boolean Function Wizard format - DIMACS CNF: Standard SAT solver format
- Usage:
from boofun.core.io import load, save
# Load from file (format auto-detected) f = load(“function.json”) f = load(“function.bf”) f = load(“function.cnf”)
# Save to file save(f, “output.json”) save(f, “output.bf”) save(f, “output.cnf”)
Functions
|
Detect file format from extension or content. |
|
Load a Boolean function from file. |
|
Load Boolean function from .bf file (Aaronson format). |
|
Load Boolean function from DIMACS CNF file. |
|
Load Boolean function from JSON file. |
|
Save a Boolean function to file. |
|
Save Boolean function to .bf file (Aaronson format). |
|
Save Boolean function to DIMACS CNF file. |
|
Save Boolean function to JSON file. |
Exceptions
|
Error during file I/O operations. |
- boofun.core.io.load(path: str | Path, format: str | None = None, **kwargs) BooleanFunction[source]
Load a Boolean function from file.
- Parameters:
path – Path to the file
format – Optional format override (“json”, “bf”, “dimacs_cnf”)
**kwargs – Format-specific options
- Returns:
BooleanFunction instance
- Raises:
FileIOError – If file cannot be loaded
FileNotFoundError – If file does not exist
- boofun.core.io.save(func: BooleanFunction, path: str | Path, format: str | None = None, **kwargs) None[source]
Save a Boolean function to file.
- Parameters:
func – BooleanFunction to save
path – Destination path
format – Optional format override (“json”, “bf”, “dimacs_cnf”)
**kwargs – Format-specific options
- Raises:
FileIOError – If file cannot be saved
- boofun.core.io.load_json(path: str | Path, **kwargs) BooleanFunction[source]
Load Boolean function from JSON file.
JSON format stores the full representation including metadata.
- Parameters:
path – Path to JSON file
- Returns:
BooleanFunction instance
- boofun.core.io.save_json(func: BooleanFunction, path: str | Path, representation: str = 'truth_table', pretty: bool = True, **kwargs) None[source]
Save Boolean function to JSON file.
- Parameters:
func – BooleanFunction to save
path – Destination path
representation – Which representation to save
pretty – Whether to format with indentation
- boofun.core.io.load_bf(path: str | Path, **kwargs) BooleanFunction[source]
Load Boolean function from .bf file (Aaronson format).
- Format:
n (number of variables) 00…0 v₀ (optional input string, then output value) 00…1 v₁ … 11…1 v_{2^n-1}
Values can be 0, 1, or -1 (partial function, undefined).
- Parameters:
path – Path to .bf file
- Returns:
BooleanFunction instance
- boofun.core.io.save_bf(func: BooleanFunction, path: str | Path, include_inputs: bool = True, **kwargs) None[source]
Save Boolean function to .bf file (Aaronson format).
- Parameters:
func – BooleanFunction to save
path – Destination path
include_inputs – Whether to include input bit strings
- boofun.core.io.load_dimacs_cnf(path: str | Path, **kwargs) BooleanFunction[source]
Load Boolean function from DIMACS CNF file.
- DIMACS CNF is the standard format for SAT solvers:
c comment line p cnf <n_vars> <n_clauses> 1 -2 3 0 (clause: x1 OR NOT x2 OR x3) -1 2 0 (clause: NOT x1 OR x2) …
Positive integers are positive literals, negative are negated. Each clause ends with 0.
- Parameters:
path – Path to .cnf file
- Returns:
BooleanFunction with CNF representation
- boofun.core.io.save_dimacs_cnf(func: BooleanFunction, path: str | Path, comment: str | None = None, **kwargs) None[source]
Save Boolean function to DIMACS CNF file.
Note: Converts function to CNF if not already in that representation.
- Parameters:
func – BooleanFunction to save
path – Destination path
comment – Optional comment to include