cana.primes.util module

Shared helpers for expression→prime conversion (nesting, pysat).

Named-cube ↔ one-symbol adapters live on cana.function_outputs.one_symbol and are re-exported here for backward compatibility.

cana.primes.util.paren_nesting_depth(expr)[source]

Return the maximum () nesting depth in expr.

Parameters:

expr (str)

Return type:

int

cana.primes.util.refuse_extreme_nesting(expr, *, limit=None)[source]

Raise RecursionError if parenthesis nesting exceeds limit.

Default limit is min(MAX_SAFE_PAREN_DEPTH, getrecursionlimit() - 50). Pass a backend-specific cap (e.g. MAX_PRIMER_PAREN_DEPTH) when the parser’s stack cost is known.

Parameters:
  • expr (str)

  • limit (int | None)

Return type:

None

cana.primes.util.expr_to_pysat_formula(expr)[source]

Parse a symbolic & / | / ! expression into a pysat Formula.

Precedence: ! > & > |; parentheses override. Identifiers are [A-Za-z_][A-Za-z0-9_]*. Constants 0 / 1 / True / False are accepted. Raises ImportError if pysat is missing, ValueError on syntax errors.

Parameters:

expr (str)

cana.primes.util.primes_to_one_symbol(on_primes, off_primes, *, input_names=None, k=None)[source]

Convert named ON/OFF prime cubes to positional one-symbol schemata.

input_names defaults to positional_names(k). When k is omitted it is inferred from input_names, else from the union of prime keys (sorted).

Parameters:
  • on_primes (List[Dict[str, bool]])

  • off_primes (List[Dict[str, bool]])

  • input_names (Sequence[str] | None)

  • k (int | None)

Return type:

Dict[int, Set[str]]

cana.primes.util.one_symbol_to_primes(schemata, input_names)[source]

Convert one-symbol schemata to named ON/OFF prime-cube lists.

Parameters:
  • schemata (Dict[int, Set[str]])

  • input_names (Sequence[str])

Return type:

Tuple[List[Dict[str, bool]], List[Dict[str, bool]]]