A sophisticated synchronization system implementing three-phase periodic scheduling with XOR-of-the-other-2 training over a hypergraph structure. The system acts as a high-pass/novelty filter, canceling persistent patterns while emphasizing phase-specific fluctuations.
XOR3N implements:
- 3 Sync Phases (A, B, C) with individual cadences (i, j, k)
- LCM-aligned Supercycle: T = LCM(i, j, k) + t₀
- Periodic Scheduling over hypergraph structure
- XOR-of-the-Other-2 Training: Each phase trains on XOR of the other two
- Phase A ← (B XOR C)
- Phase B ← (A XOR C)
- Phase C ← (A XOR B)
- High-Pass/Novelty Filter: Persistent/common signals get canceled (low-frequency), while fluctuating/phase-specific signals become salient (high-frequency)
The XOR operation creates a natural novelty detection mechanism:
- Persistent patterns (signals common across phases) → Canceled (XOR eliminates common bits)
- Fluctuating patterns (phase-specific signals) → Emphasized (XOR highlights differences)
Each phase activates on its own cadence, creating complex temporal patterns where different combinations of phases are active. The supercycle T = LCM(i, j, k) ensures the pattern repeats periodically.
No dependencies required - pure Python implementation.
git clone https://github.com/ZoneCog/xor3n.git
cd xor3nfrom xor3n import create_xor3n
# Create system with cadences 2, 3, 5
xor3n = create_xor3n(cadence_a=2, cadence_b=3, cadence_c=5)
# The supercycle is LCM(2, 3, 5) = 30
print(f"Supercycle: {xor3n.supercycle}") # Output: 30
# Run a single step with signals
xor3n.step(0, signal_a=1, signal_b=0, signal_c=1)
# Check training signals (XOR of the other two)
print(xor3n.phase_a.training_history[0]) # B XOR C = 0 XOR 1 = 1
print(xor3n.phase_b.training_history[0]) # A XOR C = 1 XOR 1 = 0
print(xor3n.phase_c.training_history[0]) # A XOR B = 1 XOR 0 = 1from xor3n import XOR3N
xor3n = XOR3N(2, 3, 5)
# Scenario 1: All phases same (persistent signal)
xor3n.step(0, signal_a=1, signal_b=1, signal_c=1)
# Training signals: (0, 0, 0) - common signal canceled!
# Scenario 2: Phase-specific signal (novelty)
xor3n.step(1, signal_a=1, signal_b=0, signal_c=0)
# Training signals: (0, 1, 1) - B and C detect novelty in A!# Get the periodic schedule
schedule = xor3n.get_schedule(30) # One full supercycle
for t, active_phases in schedule[:10]:
print(f"t={t}: {', '.join(active_phases) or 'none'}")
# Output shows which phases are active at each time:
# t=0: A, B, C (all synchronized)
# t=1: none
# t=2: A
# t=3: B
# t=4: A
# t=5: C
# ...# Define a signal generator
def signal_gen(t, phase_name):
return (t + ord(phase_name)) % 2 # Different pattern per phase
# Run for multiple steps
xor3n.run_cycle(num_steps=30, signal_generator=signal_gen)
# Analyze the novelty filter behavior
analysis = xor3n.analyze_novelty_filter(30)
print(f"Active counts: {analysis['active_counts']}")Main class implementing the three-phase synchronization system.
Methods:
step(t, signal_a, signal_b, signal_c)- Execute one time steprun_cycle(num_steps, signal_generator)- Run multiple stepscompute_xor_training(t)- Compute XOR training signalsget_active_phases(t)- Get phases active at time tget_schedule(num_steps)- Get periodic scheduleanalyze_novelty_filter(num_steps)- Analyze filter behavior
Represents a single phase in the system.
Methods:
is_active(t)- Check if phase is active at time tget_signal(t)- Get signal value at time tset_signal(t, value)- Set signal value at time trecord_training(t, value)- Record training value
lcm(a, b)- Calculate LCM of two numberslcm_multiple(numbers)- Calculate LCM of multiple numberscreate_xor3n(cadence_a, cadence_b, cadence_c, t0)- Factory function
Run the included examples:
python examples.pyThis demonstrates:
- Basic usage and supercycle calculation
- XOR-of-the-other-2 training mechanism
- High-pass/novelty filter effect
- Supercycle analysis for different cadences
- Hypergraph periodic scheduling patterns
Run the test suite:
python -m unittest test_xor3n -vAll 21 tests validate:
- LCM calculations
- Phase activation patterns
- XOR operations
- Training signal computation
- Novelty filter behavior
- Schedule generation
For cadences (i, j, k), the system repeats every T = LCM(i, j, k) steps.
Example cadences and their supercycles:
- (2, 3, 5) → T = 30
- (3, 4, 6) → T = 12
- (7, 11, 13) → T = 1001
For any signals a, b, c:
- a XOR a = 0 (self-cancellation)
- a XOR 0 = a (identity)
- (a XOR b) XOR c = a XOR (b XOR c) (associativity)
This creates the novelty detection:
- When all phases equal: all training signals = 0 (canceled)
- When phases differ: training signals highlight differences
- Temporal pattern detection in multi-stream data
- Novelty detection in synchronized systems
- Differential signal processing with automatic common-mode rejection
- Hypergraph edge scheduling with periodic constraints
- Multi-phase training where each phase learns from others' differences
See LICENSE file for details.
Contributions welcome! Please ensure all tests pass before submitting PRs.
This implementation is based on concepts from:
- LCM-based periodic scheduling
- XOR-based novelty detection
- Hypergraph temporal synchronization
- Differential training in multi-agent systems