Modularity

boolforge.modularity.merge_state_representation(x: int | Sequence[int], y: int | Sequence[int], num_nodes: int | Sequence[int]) int | Sequence[int][source]

Combine two state representations into a single decimal representation.

Parameters

xint or sequence of int

First state. Can be a single integer or a pair of integers.

yint or sequence of int

Second state. Can be a single integer or a pair of integers.

bint or sequence of int

Bit size of y. Must match the structure of y (int or pair of ints).

Returns

resultint or tuple of int

Combined state representation. Returns an int if both x and y are integers. Returns a tuple of two ints if either x or y is a tuple/list.

boolforge.modularity.get_product_of_attractors(attrs_1: Sequence[Sequence[int | Sequence[int]]], attrs_2: Sequence[Sequence[int | Sequence[int]]], bits: int | Sequence[int]) list[source]

Compute the product of two sets of attractors by combining their states.

Parameters

attrs_1sequence of sequences of int or sequence of sequences of pairs of ints

First set of attractors. Each attractor is a list of states.

attrs_2sequence of sequences of int or sequence of sequences of pairs of ints

Second set of attractors. Each attractor is a list of states.

bitsint or pair of ints

Bit size of states in attrs_2. Used when merging states.

Returns

resultsequence of sequences of int or sequence of sequences of pairs of ints

Product set of attractors obtained by merging each attractor from attrs_1 with each attractor from attrs_2.

boolforge.modularity.compress_trajectories(trajectories: tuple[Sequence[int], int], num_nodes: int) DiGraph[source]

Compress multiple trajectories into a single directed graph.

Each trajectory is represented by a prefix (non-periodic states) and a cycle (periodic states). Nodes are merged when identical prefixes or cycles occur across trajectories.

Parameters

trajectoriestuple of (sequence of int, int)

List of trajectories. Each trajectory is a tuple containing a list of decimal states and the length of its periodic cycle.

num_nodesint

Number of nodes in the network. Used to format node labels as binary strings.

Returns

Gnetworkx.DiGraph

Directed graph representing all merged trajectories.

boolforge.modularity.product_of_trajectories(compressed_trajectory_graph_1: DiGraph, compressed_trajectory_graph_2: DiGraph) DiGraph[source]

Compute the product of two compressed trajectory graphs, following the premise of equal reachability.

The resulting graph contains all combinations of nodes from the two input graphs, with edges representing all possible successor pairs.

Parameters

compressed_trajectory_graph_1networkx.DiGraph

First compressed trajectory graph.

compressed_trajectory_graph_2networkx.DiGraph

Second compressed trajectory graph.

Returns

Gnetworkx.DiGraph

Directed graph representing the product of the two input graphs.

boolforge.modularity.plot_trajectory(compressed_trajectory_graph: DiGraph, show: bool = True)[source]

Visualize a compressed trajectory graph using a layered layout.

Initial states are highlighted with a box. Layers are computed based on weakly connected components to improve readability.

Parameters

compressed_trajectory_graphnetworkx.DiGraph

Directed graph of compressed trajectories.

showbool, default=True

Whether to call plt.show() at the end.