# ==============================================================================
# 1. High-Level 2-protobit Relational and Arithmetic Operators
# ==============================================================================
# Each 2-protobit register has 4 states (0, 1, 2, 3).
# Pairing two 2-protobit registers yields 4 protobits (16 input states from 0000 to 1111).
# Relational operators evaluate as 16x1 constraint filter matrices.
# Operator: Greater-Than (A > B)
# Yields 1 only when 2-bit value A strictly exceeds 2-bit value B.
greater_than = TransitionMatrix([
[0], [0], [0], [0], # A = 0: 0>0, 0>1, 0>2, 0>3 (all False)
[1], [0], [0], [0], # A = 1: 1>0 (True), 1>1, 1>2, 1>3 (False)
[1], [1], [0], [0], # A = 2: 2>0, 2>1 (True), 2>2, 2>3 (False)
[1], [1], [1], [0] # A = 3: 3>0, 3>1, 3>2 (True), 3>3 (False)
])
# Operator: Less-Than (A < C)
# Yields 1 only when 2-protobit value A is strictly less than 2-protobit value C.
less_than = TransitionMatrix([
[0], [1], [1], [1], # A = 0: 0<0 (False), 0<1, 0<2, 0<3 (True)
[0], [0], [1], [1], # A = 1: 1<0, 1<1 (False), 1<2, 1<3 (True)
[0], [0], [0], [1], # A = 2: 2<0, 2<1, 2<2 (False), 2<3 (True)
[0], [0], [0], [0] # A = 3: 3<0, 3<1, 3<2, 3<3 (all False)
])
# Operator: Equality (X == Y)
# Yields 1 only when two 2-protobit values are identical.
equal = TransitionMatrix([
[1], [0], [0], [0], # 0 == 0
[0], [1], [0], [0], # 1 == 1
[0], [0], [1], [0], # 2 == 2
[0], [0], [0], [1] # 3 == 3
])
# Operator: Bitwise Invert (2-protobit NOT)
# Inverts both protobits of a 2-protobit bus (e.g., 00 -> 11 (0 -> 3), 01 -> 10 (1 -> 2))
invert = (negate**2)
# Operator: 2-protobit Adder (Modulo 4 addition)
# Maps 4 input protobits (A, B) to a 2-protobit sum (4 output states).
# Note: Only shown here if someone wants to experiment with it.
add = TransitionMatrix([
[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], # 0 + {0,1,2,3}
[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], # 1 + {0,1,2,3}
[0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0], # 2 + {0,1,2,3}
[0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0] # 3 + {0,1,2,3}
])
# ==============================================================================
# 2. Sequential Constraint Pipeline Compilation
# ==============================================================================
# System state: 6 protobits representing three 2-bit registers (A, B, C).
# Initial state: Full superposition across all 64 possible register combinations.
# --- Apply Constraint 1: A > B ---
# 1. Tap registers A and B using split operators.
# 2. Permute tapped lines to feed into the 4-bit greater_than comparator.
# 3. Contract and normalize to filter out violating configurations.
constraints = (
(random**6)
@ (split**4 ^ identity**2)
@ permute([0, 2, 4, 6, 8, 9, 1, 3, 5, 7])
@ (identity**6 ^ greater_than)
).normalize()
# --- Apply Constraint 2: A < C ---
# 1. Tap registers A and C.
# 2. Route tapped channels into the less_than comparator.
# 3. Contract and normalize the joint state.
constraints = (
constraints
@ (split**2 ^ identity**2 ^ split**2)
@ permute([0, 2, 4, 5, 6, 8, 1, 3, 7, 9])
@ (identity**6 ^ less_than)
).normalize()
# --- Apply Constraint 3: C == NOT(B) ---
# 1. Tap register B, pass through 2-bit invert, and compare with register C via equal.
# 2. Final contraction filters down to the mutually consistent ground-state manifold.
constraints = (
constraints
@ (identity**2 ^ split**2 ^ identity**2)
@ permute([0, 1, 2, 4, 6, 7, 3, 5])
@ (identity**6 ^ invert)
@ (identity**4 ^ split**2 ^ identity**2)
@ permute([0, 1, 2, 3, 4, 6, 8, 9, 5, 7])
@ (identity**6 ^ equal)
).normalize()
# ==============================================================================
# 3. Physical State Readout (Sampling the Feasible Manifold)
# ==============================================================================
# Collapse the 6-protobit state vector into a single measured bitstring.
measured_bitstring = constraints.measure()
# Slice bitstring into the three 2-protobit registers (A, B, C)
bin_a = measured_bitstring[0:2]
bin_b = measured_bitstring[2:4]
bin_c = measured_bitstring[4:6]
# Convert binary strings to integers (0 to 3)
val_a = int(bin_a, 2)
val_b = int(bin_b, 2)
val_c = int(bin_c, 2)
# Display the sampled solution in LaTeX format
display_inline(
r"\text{Measured State: }",
r"\mathbf{A} =", str(val_a),
r",\quad \mathbf{B} =", str(val_b),
r",\quad \mathbf{C} =", str(val_c)
)