cana.nodes_builder module

Build and compare CANA networks as list[BooleanNode] hubs.

Invariant: for all i, nodes[i].id == i, and every inputs entry is an index into that list. Node sets are dense 0 .. N-1; CANA does not delete BN nodes after construction. Arity satisfies k == len(inputs) == function.k (with k == 0 and empty inputs for constants without wired inputs).

Glossary

inputs / input_names

Wired predecessors of a node (integer hub ids) and their names in LUT / expression bit order (inputs[0] is MSB).

k

Function arity; equals len(inputs) and function.k.

function / BooleanFunction

Multi-representation update rule on function. Peer slots: bit_lut, positional_expression, one_symbol_schemata, two_symbol_schemata.

bit_lut

Dense BitLut truth table.

outputs (bits)

Values f(0) … f(2^k - 1). Constructor sugar outputs=[…] builds a BooleanFunction from that column; do not call a node an “output.”

positional expression

BooleanFunction peer IR over x0…x{k-1}.

named expression

Gene-named formula string at the I/O boundary.

free inputs

Names that appear only as inputs on import; receive identity f(x) = x.

source_nodes

Network-level constants ∪ self-loop identity nodes (control-like set). Distinct from node.inputs. Alias: input_nodes.

source → target

Digraph edge endpoints; an edge exists when source is an input of target.

state

A node’s current binary value (dynamics), not the update rule.

polarity

Canalizing-map function-value polarity 0/1.

update rule

(name, named_expression) from a format line (often a dict).

detached rule

DetachedRule — name + input_names + positional BooleanFunction, not hub-wired (no free-input siblings).

See also the Hub invariant on BooleanNetwork.

class cana.nodes_builder.DetachedRule(name, input_names, function)[source]

Bases: object

One update rule, detached from any network hub.

function holds a positional expression peer. input_names[i] is the input for positional xi (MSB = input_names[0]). Network id / integer inputs are not set.

Parameters:
name: str
input_names: Tuple[str, ...]
function: BooleanFunction
property k: int
to_named_expression(style='symbolic')[source]

Reconstruct a named expression from positional IR + input names.

Parameters:

style (str)

Return type:

str

as_update_rule(style='symbolic')[source]

Return (name, named_expression).

Parameters:

style (str)

Return type:

Tuple[str, str]

cana.nodes_builder.named_expression_to_detached_rule(name, named_expression, *, input_names=None)[source]

Bind a named expression to a DetachedRule.

If input_names is None, inputs are unique identifiers in first-appearance order (single-rule / synthetic import). Otherwise the caller supplies order (full-model link uses the global name list via input_names_in_expression()).

Parameters:
  • name (str)

  • named_expression (str)

  • input_names (Sequence[str] | None)

Return type:

DetachedRule

cana.nodes_builder.detached_rule_to_node(rule, *, id, inputs)[source]

Wire a DetachedRule into a hub BooleanNode.

Parameters:
Return type:

BooleanNode

cana.nodes_builder.update_rules_to_nodes(update_rules, extra_names=None)[source]

Build a dense list[BooleanNode] from {target: named_expression}.

Names that appear only as inputs (free inputs) receive the identity update f(x) = x, matching BBM’s booleannet representation of inputs. Literal constants use empty inputs and positional True/False.

Each node’s function stores a positional expression without building a dense LUT at import time.

Parameters:
  • update_rules (Mapping[str, str])

  • extra_names (Iterable[str] | None)

Return type:

List[BooleanNode]

cana.nodes_builder.input_names(nodes, node_id)[source]

Return input names for node_id in LUT bit order.

Parameters:
Return type:

List[str]

cana.nodes_builder.name_keyed_luts(network_or_nodes)[source]

Return {name: (sorted_input_names, lut)} for equivalence checks.

Accepts a BooleanNetwork or a Sequence[BooleanNode]. Input order is canonicalized by sorting names; the LUT is reordered to match.

Parameters:

network_or_nodes (Any)

Return type:

Dict[str, Tuple[Tuple[str, …], Tuple[int, …]]]

cana.nodes_builder.equivalent_networks(a, b)[source]

True if two networks / node lists have the same name-keyed LUTs.

Parameters:
  • a (Any)

  • b (Any)

Return type:

bool