cana.function_properties.unate module

Unate and monotone-increasing checks: semantic (LUT) and syntactic (NNF).

Semantic predicates inspect a dense BitLut. An input idx is positive unate when flipping it from 0 to 1 never decreases the output, and negative unate when that flip never increases the output. A function is monotone increasing when every input is positive unate, and unate when every input is purely positive or purely negative (sign frozenset({1}) or frozenset({-1})).

Syntactic unate means every identifier appears only positively or only negatively after negation is pushed to the leaves (NNF). A variable that occurs both ways is binate. Same-polarity repeats (e.g. a & a) are still unate; that is distinct from syntactic ROF (single occurrence). Named or positional expression IR both work (identifiers are tokens).

The string path is a single left-to-right NNF scan with an explicit polarity stack (iterative; deep nesting cannot blow the call stack). It always stops at the first binate variable. binate in the return dict is empty or a one-element list; positive / negative reflect only what was seen before stopping when the formula is not unate. n_unique_variables is always a full unique-identifier count. is_unate means syntactic unate.

An optional AST leaf-polarity walk (check_syntactic_unate_ast()) is available when a tree already exists; the string API does not parse to an AST.

Naming (semantic): - is_input_* / input_sign — one variable (input index) of the LUT. - input_signs — one sign per input (not a single whole-function flag). - is_function_* — a property of the whole LUT / Boolean function.

Interaction-sign vocabulary (frozenset[int]; PyBoolNet-shaped): - SIGN_POSITIVE = frozenset({1}) — pure activating - SIGN_NEGATIVE = frozenset({-1}) — pure inhibiting - SIGN_BINATE = frozenset({1, -1}) — dual-sign / non-unate - SIGN_IRRELEVANT = frozenset() — no influence (both-unate / unused) - On graphs only, None means signs were not computed

cana.function_properties.unate.is_input_positive_unate(lut, idx)[source]

Return whether input idx is positive unate (activating).

Parameters:
Return type:

bool

cana.function_properties.unate.is_input_negative_unate(lut, idx)[source]

Return whether input idx is negative unate (inhibiting).

Parameters:
Return type:

bool

cana.function_properties.unate.input_sign(lut, idx)[source]

Return the interaction sign of input idx as a frozenset.

  • SIGN_POSITIVE ({1}): positive unate only

  • SIGN_NEGATIVE ({-1}): negative unate only

  • SIGN_BINATE ({1, -1}): neither pure direction (dual-sign)

  • SIGN_IRRELEVANT (frozenset()): both unate (no influence)

Parameters:
Return type:

frozenset

cana.function_properties.unate.input_signs(lut)[source]

Return the sign of each input of lut (length lut.k).

Parameters:

lut (BitLut)

Return type:

List[frozenset]

cana.function_properties.unate.is_function_monotone_increasing(lut)[source]

Return whether the whole function is monotone increasing.

True when every input is positive unate (isotone / monotone up).

Parameters:

lut (BitLut)

Return type:

bool

cana.function_properties.unate.is_function_unate(lut)[source]

Return whether the whole function is unate.

True when every input is purely positive or purely negative (SIGN_POSITIVE or SIGN_NEGATIVE). Irrelevant and binate inputs make the function not unate.

Parameters:

lut (BitLut)

Return type:

bool

cana.function_properties.unate.check_syntactic_unate(expr)[source]

Return syntactic-unate stats for expression expr.

Single-pass NNF polarity scan. Stops at the first binate variable (binate has at most one name). n_unique_variables is always a full count (not truncated by early stop). Constants / empty expressions are vacuously unate. Does not parse to an AST.

Parameters:

expr (str)

Return type:

Dict[str, bool | int | List[str]]

cana.function_properties.unate.check_syntactic_unate_ast(node)[source]

Return syntactic-unate stats for an AST node (leaf polarity walk).

Convenience when a tree already exists; enumerates all leaves (no early stop). Prefer check_syntactic_unate() for expression strings.

Parameters:

node (LogicNode | None)

Return type:

Dict[str, bool | int | List[str]]

cana.function_properties.unate.require_syntactic_unate(expr)[source]

Raise if expr is not syntactically unate.

Rejects formulas that might only be unate after simplification; this check never rewrites. Stops at the first binate.

Parameters:

expr (str)

Return type:

None

cana.function_properties.unate.require_syntactic_unate_ast(node)[source]

Raise if node is not syntactically unate.

Parameters:

node (LogicNode | None)

Return type:

None

cana.function_properties.unate.syntactic_input_signs(expr, input_names)[source]

Return per-input signs if expr is syntactically unate; else None.

Uses the NNF string scan. SIGN_POSITIVE / SIGN_NEGATIVE come from the positive / negative sets keyed by input_names; inputs absent from the expression get SIGN_IRRELEVANT. Returns None when not syntactically unate so callers can fall through to a LUT-based check (syntactic binate does not imply semantic binate).

Parameters:
  • expr (str)

  • input_names (Sequence[str])

Return type:

List[frozenset] | None