Status: ✅ ACTIVE - Complete operator specifications
Version: 3.0.0 (Operator contracts centralized in operator_contracts.py)
Last Updated: June 17, 2026
This document formalizes the structural invariants and API contracts for key TNFR functions, inspired by the 13 canonical structural operators. Each contract specifies preconditions, postconditions, and the structural effects on the Primary Information Structure (EPI), structural frequency (νf), phase (θ), and internal reorganization operator (ΔNFR).
tnfr.operators: Structural operators implementing TNFR canonical grammartnfr.utils: Utility functions for caching, graph operations, and data normalizationtnfr.dynamics: Evolution and dynamics computationtnfr.structural: Node creation and network initializationSingle source of truth. The canonical contract of every operator is owned by
tnfr.operators.operator_contracts(OPERATOR_CONTRACTS), derived from the nodal-equation ground-truth effect of each glyph plus TNFR.pdf §2.2.1. The proactive audit (tnfr.physics.integrity.audit_operator_contracts), the reactive monitor (POSTCONDITIONS), and the introspection metadata all derive from / are pinned to this spec. This table is a generated view; do not hand-edit contracts here — change the spec.
At the public level the English structural-operator name is canonical (Emission, Reception, …); the glyph code (AL, EN, …) is the internal symbol.
Each operator's primary effect lands on exactly one nodal-equation channel
(∂EPI/∂t = νf · ΔNFR). This channel partition simultaneously is the
dual-lever (examples 37/130), the tetrad driver (example 39), and the
number-theory grading (example 147). A second, orthogonal scale axis
(grammar rule U5, operational fractality) separates the twelve node-scale
operators from the single network-scale operator, Recursivity (REMESH).
| # | Operator | Glyph | Channel | Scale | Direction | Postcondition |
|---|---|---|---|---|---|---|
| 1 | Emission | AL | EPI (form) | node | increase | EPI not decreased (∂EPI/∂t ≥ 0) |
| 2 | Reception | EN | EPI (form) | node | reorganize | C(t) not decreased (coherent integration) |
| 3 | Resonance | RA | EPI (form) | node | reorganize | EPI structural identity (sign/kind) preserved |
| 4 | Silence | SHA | νf (capacity) | node | decrease | νf not increased (freeze) |
| 5 | Expansion | VAL | νf (capacity) | node | increase | νf not decreased (capacity added) |
| 6 | Contraction | NUL | νf (capacity) | node | decrease | νf not increased (capacity removed) |
| 7 | Coupling | UM | θ (phase) | node | reorganize | |
| 8 | Mutation | ZHIR | θ (phase) | node | transform | θ transformed (θ → θ') |
| 9 | Coherence | IL | ΔNFR (pressure) | node | decrease | |
| 10 | Dissonance | OZ | ΔNFR (pressure) | node | increase | |
| 11 | SelfOrganization | THOL | ΔNFR (pressure) | node | increase | C(t) not catastrophic (≥ 90%, global form preserved) |
| 12 | Transition | NAV | ΔNFR (pressure) | node | reorganize | state changed (νf, θ, or ΔNFR) |
| 13 |
tnfr.operators.definitions.EmissionA'L ⇒ ∂EPI/∂t > 0, νf ≈ ν₀⁺tnfr.operators.definitions.ReceptionE'N ⇒ input coherente → modulación de Wᵢ(t)tnfr.operators.definitions.ResonanceR'A ⇒ propagación de EPI con νf amplificadatnfr.operators.definitions.SilenceSH'A ⇒ νf → 0 ⇒ ∂EPI/∂t → 0tnfr.operators.definitions.ExpansionVA'L ⇒ νf ↑ (complejidad estructural)tnfr.operators.definitions.ContractionNU'L ⇒ νf ↓, ΔNFR densificadatnfr.operators.definitions.CouplingU'M ⇒ φᵢ(t) → φⱼ(t) (sincronización de fase)tnfr.operators.definitions.MutationZ'HIR ⇒ θ → θ' cuando ΔEPI/Δt > ξtnfr.operators.definitions.CoherenceI'L ⇒ ∂Wᵢ/∂t → 0, νf = consttnfr.operators.definitions.DissonanceO'Z ⇒ |ΔNFR| ↑ (puede gatillar ∂²EPI/∂t² > τ)tnfr.operators.definitions.SelfOrganizationT'HOL ⇒ ΔNFR += κ·∂²EPI/∂t² (sub-EPIs)tnfr.operators.definitions.TransitionNA'V ⇒ ΔNFR → νf-aligned (transición de régimen)tnfr.operators.definitions.RecursivityRE'MESH ⇒ EPI_new = (1-α)²·EPI(t) + α(1-α)·EPI(t-τ_l) + α·EPI(t-τ_g)tnfr.utils.cache.cached_node_listPurpose: Return cached node list with version tracking.
Contract:
G implements GraphLike protocoltnfr.utils.graph.mark_dnfr_prep_dirtyPurpose: Invalidate ΔNFR preparation cache.
Contract:
G has graph metadata accessibleG.graph["_dnfr_prep_dirty"] = Truetnfr.utils.numeric.clampPurpose: Constrain value within bounds.
Contract:
value, min_val, max_val are comparablemin_val ≤ max_valresult = max(min_val, min(value, max_val))min_val ≤ result ≤ max_valclamp(clamp(x, a, b), a, b) = clamp(x, a, b)These invariants apply across all TNFR operations:
from tnfr.operators.definitions import Emission, Coherence, Coupling
from tnfr.structural import create_nfr, run_sequence
# Create a node with initial conditions
G, node = create_nfr("seed", epi=0.1, vf=1.0, theta=0.0)
# Apply operators respecting structural invariants
sequence = [
Emission(), # ✓ Increases EPI, preserves νf, θ, ΔNFR
Coherence(), # ✓ Dampens ΔNFR, increases C(t)
Coupling(), # ✓ Synchronizes phase with neighbors
]
run_sequence(G, node, sequence)
# Verify invariants
assert G.nodes[node]["epi"] >= 0.1 # Emission increased EPI
assert abs(G.nodes[node]["dnfr"]) < 1.0 # Coherence dampened ΔNFRAll contracts should be validated by:
See tests/integration/test_additional_critical_paths.py for examples.
The tnfr.utils package exhibits a well-structured dependency hierarchy with no circular runtime dependencies:
init.py (foundational - logging, lazy imports)
↓
numeric.py, chunks.py (pure mathematical functions, no TNFR imports)
↓
data.py (depends on: numeric, init)
↓
graph.py (depends on: types only)
↓
io.py (depends on: init)
↓
cache.py (depends on: locking, types, init, graph, io)
↓
callbacks.py (depends on: constants, locking, init, data, types)Verified No Circular Imports: Analysis confirmed no runtime circular dependencies. The apparent bidirectional reference between init.py and cache.py uses TYPE_CHECKING guards, preventing runtime circular import issues.
cache.py → graph.py:
get_graph(), mark_dnfr_prep_dirty()cache.py → init.py:
get_logger(), get_numpy()cache.py → io.py:
json_dumps()data.py → numeric.py:
kahan_sum_nd()callbacks.py → data.py:
is_non_string_sequence()Assessment: All cross-module imports serve specific structural purposes aligned with TNFR invariants. No unnecessary coupling detected.
callback_utils.py: Deprecated compatibility shim that redirects to utils.callbacks. This module:
DeprecationWarning on import| Module | Internal Imports | External TNFR Imports | Coupling Score |
|---|---|---|---|
numeric.py | 0 | 0 | Low ✓ |
chunks.py | 0 | 0 | Low ✓ |
init.py | 1 (cache - TYPE_CHECKING only) | 0 | Low ✓ |
graph.py | 0 | 2 (types) | Low ✓ |
io.py | 4 (init) | 0 | Low ✓ |
data.py | 3 (numeric, init) | 0 | Moderate ✓ |
callbacks.py | 2 (init, data) | 3 (constants, locking, types) | Moderate ✓ |
cache.py | 5 (graph, init, io) | 2 (locking, types) | Moderate ✓ |
✓ All coupling levels are appropriate for module responsibilities.
Flake8 analysis identified only minor style issues:
No structural anti-patterns, circular imports, or dangerous coupling detected.
callback_utils.py: After deprecation period expiresPurpose: Transform unstable or problematic sequences into stable therapeutic patterns.
Template:
# Before: Unstable transformation (health ≈ 0.60)
unstable = [EMISSION, DISSONANCE, MUTATION, COHERENCE]
# After: Full therapeutic cycle (health ≈ 0.89)
therapeutic = [
EMISSION, # AL: Initialize therapeutic space
RECEPTION, # EN: Gather contextual information
COHERENCE, # IL: Establish baseline stability
DISSONANCE, # OZ: Controlled destabilization
SELF_ORGANIZATION, # THOL: Emergent reorganization
COHERENCE, # IL: Consolidate transformation
SILENCE # SHA: Integration period
]Key Improvements:
Purpose: Upgrade basic activation patterns with resonant amplification.
Template:
# Before: Basic activation (health ≈ 0.66)
basic = [EMISSION, RECEPTION, COHERENCE, SILENCE]
# After: Enhanced with resonance (health ≈ 0.85)
enhanced = [
EMISSION, # AL: Seed activation
RECEPTION, # EN: Information gathering
COHERENCE, # IL: Baseline stability
RESONANCE, # RA: Amplify coherent patterns
SILENCE # SHA: Preserve amplified state
]Key Improvements:
Purpose: Enable safe exploration through controlled destabilization and recovery.
Template:
controlled_exploration = [
EMISSION, # AL: Initialize exploration space
RECEPTION, # EN: Gather environmental context
COHERENCE, # IL: Establish safety baseline
EXPANSION, # VAL: Increase exploration volume
COHERENCE, # IL: Stabilize expansion (U2)
DISSONANCE, # OZ: First exploration wave
MUTATION, # ZHIR: Alternative trajectory (U4b)
COHERENCE, # IL: Checkpoint stability
DISSONANCE, # OZ: Second exploration wave
SELF_ORGANIZATION, # THOL: Emergent structure (U4a)
COHERENCE, # IL: Final consolidation
SILENCE # SHA: Integration
]Key Features:
Purpose: Establish coherent coupling across network nodes with phase verification.
Template:
network_sync = [
EMISSION, # AL: Initialize local coherence
RECEPTION, # EN: Sense network state
COHERENCE, # IL: Local stabilization
COUPLING, # UM: Form phase-verified links (U3)
RESONANCE, # RA: Network-wide amplification
COUPLING, # UM: Strengthen synchronization
RESONANCE, # RA: Reinforce coherent patterns
COHERENCE, # IL: Network consolidation
SILENCE # SHA: Maintain synchrony
]Critical Requirements:
Purpose: Simplify complex structures while preserving essential information.
Template:
compression = [
EMISSION, # AL: Initialize from complex state
RECEPTION, # EN: Understand full complexity
COHERENCE, # IL: Baseline stability
EXPANSION, # VAL: Temporarily increase complexity
COHERENCE, # IL: Stabilize expansion (U2)
CONTRACTION, # NUL: First compression wave
COHERENCE, # IL: Stabilize compression
CONTRACTION, # NUL: Second compression wave
COHERENCE, # IL: Final consolidation
SILENCE # SHA: Preserve essence
]Key Features:
def optimize_by_health(sequence, target_health=0.80):
"""Iterative health improvement strategy."""
current = sequence.copy()
while compute_health(current) < target_health:
# 1. Check grammar violations
violations = validate_grammar(current)
if violations:
current = fix_grammar_violations(current, violations)
continue
# 2. Apply common improvements
if needs_stabilization(current):
current = add_stabilizers(current)
elif lacks_amplification(current):
current = add_resonance(current)
elif missing_closure(current):
current = fix_closure(current)
else:
break # No obvious improvements
return currentdef enhance_with_patterns(sequence):
"""Upgrade sequences using canonical patterns."""
pattern_type = classify_sequence(sequence)
if pattern_type == "basic_activation":
return upgrade_to_enhanced_activation(sequence)
elif pattern_type == "unstable_transformation":
return convert_to_therapeutic(sequence)
elif pattern_type == "incomplete_exploration":
return complete_exploration_cycle(sequence)
else:
return apply_generic_improvements(sequence)def grammar_compliant_optimization(sequence):
"""Ensure grammar compliance while optimizing."""
# 1. Fix U1 violations (initiation/closure)
if not starts_with_generator(sequence):
sequence = [EMISSION] + sequence
if not ends_with_closure(sequence):
sequence = sequence + [SILENCE]
# 2. Fix U2 violations (convergence/boundedness)
sequence = balance_destabilizers(sequence)
# 3. Fix U3 violations (resonant coupling)
sequence = verify_phase_compatibility(sequence)
# 4. Fix U4 violations (bifurcation dynamics)
sequence = handle_bifurcation_triggers(sequence)
return sequencecompute_si(G, inplace=True)TNFR_CACHE_ENABLED=1OperatorMetrics collectionBackend selection: Choose appropriate backend for network size
Operator composition: Combine compatible operators to reduce overhead
Sequence caching: Cache validated sequences to avoid re-validation
Topology awareness: Choose operators based on network topology
Load balancing: Distribute operations across high-degree nodes
Hierarchical processing: Use operational fractality for multi-scale networks
To add new operators while maintaining canonicity:
from tnfr.operators import Operator
from tnfr.operators.glyphs import Glyph
class CustomOperator(Operator):
"""Custom operator following TNFR physics."""
name: ClassVar[str] = "custom_name"
glyph: ClassVar[Glyph] = Glyph.CUSTOM # Define new glyph
def _validate_preconditions(self, G, node):
"""Validate custom preconditions."""
# Implement physics-based validation
pass
def _apply_operation(self, G, node):
"""Apply custom structural transformation."""
# Must preserve nodal equation: ∂EPI/∂t = νf · ΔNFR
pass
def _collect_metrics(self, G, node, state_before):
"""Collect custom metrics."""
# Return metrics dict
passNew operators must be classified in grammar rules:
All new operators must pass:
AGENTS.md: Agent instructions for maintaining TNFR fidelityTNFR.pdf: Base paradigm documenttnfr.operators: Operator implementationstnfr.validation: Grammar and precondition checking| Recursivity |
| REMESH |
| EPI (form) |
| network |
| reorganize |
| node-level advisory; network effect = EPI mixed toward temporal/multi-scale history |