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)andfunction.k.- function / BooleanFunction
Multi-representation update rule on
function. Peer slots:bit_lut,positional_expression,one_symbol_schemata,two_symbol_schemata.- bit_lut
Dense
BitLuttruth table.- outputs (bits)
Values
f(0) … f(2^k - 1). Constructor sugaroutputs=[…]builds aBooleanFunctionfrom that column; do not call a node an “output.”- positional expression
BooleanFunctionpeer IR overx0…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
sourceis an input oftarget.- 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 adict).- detached rule
DetachedRule— name +input_names+ positionalBooleanFunction, 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:
objectOne update rule, detached from any network hub.
functionholds a positional expression peer.input_names[i]is the input for positionalxi(MSB =input_names[0]). Networkid/ integerinputsare not set.- Parameters:
name (str)
input_names (Tuple[str, ...])
function (BooleanFunction)
- name: str
- input_names: Tuple[str, ...]
- function: BooleanFunction
- property k: int
- 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 viainput_names_in_expression()).- Parameters:
name (str)
named_expression (str)
input_names (Sequence[str] | None)
- Return type:
- cana.nodes_builder.detached_rule_to_node(rule, *, id, inputs)[source]
Wire a
DetachedRuleinto a hubBooleanNode.- Parameters:
rule (DetachedRule)
id (int)
inputs (Sequence[int])
- Return type:
- 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 emptyinputsand positionalTrue/False.Each node’s
functionstores 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_idin LUT bit order.- Parameters:
nodes (Sequence[BooleanNode])
node_id (int)
- 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
BooleanNetworkor aSequence[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, …]]]