Repository navigation
Expand file tree
/
Copy pathoperator_contracts.py
More file actions
631 lines (563 loc) · 27.4 KB
/
Copy pathoperator_contracts.py
File metadata and controls
631 lines (563 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
"""TNFR Canonical Operator-Contract Specification — the single source of truth.
This module records the **contracts** of the 13 registered structural
operators: named event effects on node state and their declared postconditions.
Continuous intervals obey ``∂EPI/∂t = νf · ΔNFR`` separately. An event's finite
state change is not a continuous rate or a derivation of its occurrence.
It is the contract-layer companion of :mod:`grammar_canon` (which owns the U1-U6
*grammatical role* layer). Together they classify each operator; live admission,
secondary writes and atomic-stage scope remain execution-path contracts:
grammar_canon → U1-U6 roles (generator / stabilizer / destabilizer …)
operator_contracts → state effects (which nodal channel, which direction)
Executable evidence and historical references
----------------------------------------------
The executable ground truth of an operator contract is **the direct effect the
glyph has on the node state** — the deterministic mutation applied by the
``_op_*`` handlers in :mod:`tnfr.operators`. That mutation must remain
compatible with the declared hybrid execution; the nodal equation alone does
not determine all four state-channel updates. ``pdf_reference`` retains the
historical source. ``nodal_expression`` describes the current event and its
scope, rather than repeating a source formula as an unproved rate theorem.
Here a prime in an event expression denotes the post-event value, not a time
derivative. Auxiliary writes can differ between direct glyphs, public classes
and atomic stages; this metadata does not replace those path contracts.
The unifying structure (synergies)
-----------------------------------
The 13 operators distribute across the **four nodal-equation state channels**
(the structural triad EPI/νf/θ plus the pressure ΔNFR). This partition exposes:
* the **dual-lever** (examples 37/130): the νf channel = capacity lever,
the ΔNFR channel = pressure lever;
* the **tetrad read-out relation** (example 39): at fixed topology Φ_s is a
linear aggregation of ΔNFR, while θ determines |∇φ| and K_φ. ξ_C is a
nonlinear, state- and topology-dependent correlation estimate and has no
one-to-one primary operator channel;
* the **number-theory grading** (example 147): the ΔNFR/pressure channel is the
count-Ω arm, the νf/capacity channel is the size-log arm.
Channel partition (primary channel per operator)
------------------------------------------------
EPI (the form) : Emission, Reception, Resonance,
Recursivity
νf (frequency / mobility) : Silence, Expansion, Contraction
θ (phase → |∇φ|, K_φ) : Coupling, Mutation
ΔNFR (pressure → Φ_s) : Coherence, Dissonance,
SelfOrganization, Transition
Scale partition (U5 operational fractality)
-------------------------------------------
A second, orthogonal axis is the invocation/target **scale**. Recursivity is
registered at NETWORK scale; the other twelve use NODE targets. This does not
count all mutated nodes or monopolize operational fractality: THOL creates
nested forms, and bidirectional UM can modify neighboring state.
NODE : the twelve operators with a node target; their contracts may
include neighbor effects or child creation.
NETWORK : Recursivity (REMESH) — the multi-scale echo. Its node-level call
is advisory; its canonical effect is the network-scale temporal
EPI recurrence ``EPI_new = (1-α)²·EPI(t) + α(1-α)·EPI(t-τ_l) +
α·EPI(t-τ_g)`` (``apply_network_remesh``) plus topological
base-from-fiber regeneration (``apply_topological_remesh``). Its
fixed-parameter history surrogate has a conditional Cesàro
fixed-point projection (N15,
theory/REMESH_INFINITY_DERIVATION.md); this is not the literal
runtime τ_g→∞ limit of ``apply_network_remesh``. REMESH is an EPI
operator (it echoes the form across time/scale), distinguished
from Emission/Reception/Resonance only by its NETWORK scale —
a U5 implementation, not the whole U5 requirement. This connects the contract layer to the
base/fiber optic (examples 126-131): NODE operators act on the
fiber, the NETWORK operator regenerates the base.
Public naming
-------------
The lowercase English token is the canonical public executable identifier
(``emission``, ``reception``, ``coherence``, …). ``english_name`` stores the
title-case public display/class name (Emission, Reception, Coherence, …), while
``glyph`` stores the internal symbolic code (AL, EN, IL, …). Contract lookup
accepts all three layers without conflating their roles.
Self-consistency
----------------
:func:`verify_contract_consistency` asserts that the materialised contracts agree
with the canonical glyph↔name mapping in :mod:`grammar_types` and that the
primary-channel partition matches the dual-lever / nodal-channel structure.
The agreement is pinned by ``tests/operators/test_operator_contracts.py``.
"""
from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from ..config.operator_names import (
COHERENCE,
CONTRACTION,
COUPLING,
DISSONANCE,
EMISSION,
EXPANSION,
MUTATION,
RECEPTION,
RECURSIVITY,
RESONANCE,
SELF_ORGANIZATION,
SILENCE,
TRANSITION,
)
from .grammar_types import FUNCTION_TO_GLYPH
__all__ = [
"StateChannel",
"OperatorScale",
"EffectDirection",
"ContractContext",
"OperatorContract",
"ContractIdentifiabilityCertificate",
"OPERATOR_CONTRACTS",
"contract_for",
"iter_contracts",
"operators_in_channel",
"operators_at_scale",
"english_name",
"contract_identifiability_certificate",
"verify_contract_consistency",
]
class StateChannel(Enum):
"""A state variable of the nodal equation ``∂EPI/∂t = νf · ΔNFR``.
The structural triad (EPI form, νf frequency, θ phase) plus the structural
pressure ΔNFR. Every canonical operator's primary effect lands on exactly
one of these four channels.
"""
EPI = "EPI" # the form itself
NU_F = "nu_f" # structural frequency / mobility (capacity lever)
THETA = "theta" # phase → |∇φ| (1st order), K_φ (2nd order)
DELTA_NFR = "delta_nfr" # structural pressure → Φ_s (0th order)
class OperatorScale(Enum):
"""Invocation/target scale, orthogonal to the primary state channel.
REMESH alone is registered at NETWORK scale. NODE does not limit writes
to one node: UM can change neighbors and THOL can create children.
"""
NODE = "node" # invocation has a node target; auxiliary writes may extend it
NETWORK = "network" # multi-scale echo (REMESH): temporal + topological
class EffectDirection(Enum):
"""The canonical direction of an operator's primary channel effect."""
INCREASE = "increase" # ordered event effect; not a continuous rate
DECREASE = "decrease" # ordered event effect; not a continuous rate
PRESERVE = "preserve" # channel held at the event
REORGANIZE = "reorganize" # channel reshaped toward a target (mix/sync)
TRANSFORM = "transform" # channel crosses a threshold (θ → θ')
class ContractContext(Enum):
"""Declared observation scope of a registered postcondition.
Actual event writes and the selected read-out determine the check. A
stored-pressure postcondition need not survive constitutive refresh;
the context label is not a physical or dynamical theorem.
"""
NETWORK = "network" # declared network read-out, retaining refresh semantics
NODE = "node" # node-local channel (e.g. local OZ pressure)
IDENTITY = "identity" # structural identity (EPI sign/kind preserved)
PHASE = "phase" # phase channel (θ transformed)
STATE = "state" # any state variable changed (regime shift)
ADVISORY = "advisory" # verified at network scale elsewhere
# Diagnostic relation between each channel and the structural-field tetrad.
# ξ_C is deliberately absent from any one-to-one assignment: it depends on the
# complete pressure field, topology and the estimator branch.
_CHANNEL_TETRAD = {
StateChannel.EPI: "no unique tetrad component; effects require state recomputation",
StateChannel.NU_F: "no direct tetrad component; νf sets evolution rate",
StateChannel.THETA: "|∇φ| (1st), K_φ (2nd) — phase gradient/curvature",
StateChannel.DELTA_NFR: "Φ_s — linear source aggregation at fixed topology",
}
# Dual-lever arm each channel corresponds to (synergy with examples 37/130).
_CHANNEL_LEVER = {
StateChannel.EPI: "form",
StateChannel.NU_F: "capacity (νf lever)",
StateChannel.THETA: "phase",
StateChannel.DELTA_NFR: "pressure (ΔNFR lever)",
}
@dataclass(frozen=True, slots=True)
class OperatorContract:
"""Canonical contract of one structural operator.
Attributes
----------
name : str
Canonical lowercase public executable identifier (e.g. ``"emission"``).
english_name : str
Title-case public display/class name (e.g. ``"Emission"``).
glyph : str
Internal symbolic glyph code (e.g. ``"AL"``).
purpose : str
One-line canonical purpose of the operator.
primary_channel : StateChannel
The nodal-equation state channel the operator primarily acts on.
primary_direction : EffectDirection
The canonical direction of that primary effect.
scale : OperatorScale
The scale at which the operator acts (NODE for twelve operators,
NETWORK for the U5 fractality operator REMESH).
postcondition : str
The verifiable postcondition (the invariant form of the direct effect).
context : ContractContext
Where the contract canonically manifests (example 115).
nodal_expression : str
Current event effect with its scope; not a continuous-time theorem
or a verbatim historical quotation. A prime means post-event state.
pdf_reference : str
The TNFR.pdf section anchoring the operator.
"""
name: str
english_name: str
glyph: str
purpose: str
primary_channel: StateChannel
primary_direction: EffectDirection
scale: OperatorScale
postcondition: str
context: ContractContext
nodal_expression: str
pdf_reference: str
@property
def tetrad_field(self) -> str:
"""Describe the channel's scoped relation to tetrad diagnostics.
This compatibility property is descriptive. It does not assert that
the tetrad reconstructs an operator or the complete graph state.
"""
return _CHANNEL_TETRAD[self.primary_channel]
@property
def lever(self) -> str:
"""The dual-lever arm (examples 37/130) of the primary channel."""
return _CHANNEL_LEVER[self.primary_channel]
@dataclass(frozen=True, slots=True)
class ContractIdentifiabilityCertificate:
"""Equivalence classes induced by observable contract features.
This is a structural identifiability result for the declared feature set,
not an empirical classifier of engine trajectories.
"""
features: tuple[str, ...]
signature_groups: tuple[tuple[tuple[str, ...], tuple[str, ...]], ...]
uniquely_identifiable: tuple[str, ...]
ambiguous_groups: tuple[tuple[str, ...], ...]
all_operators_identifiable: bool
claim_status: str
# ════════════════════════════════════════════════════════════════════════════
# THE CANONICAL CONTRACTS — single source of truth (13 operators)
# Ground truth for executable effects: the direct ``_op_*`` state mutation,
# checked for compatibility with the nodal equation and anchored to TNFR.pdf
# §2.2.1 formal expressions. The handler is an operator realization, not the
# complete nodal dynamics. Contracts are ordered by their primary channel.
# ════════════════════════════════════════════════════════════════════════════
OPERATOR_CONTRACTS: dict[str, OperatorContract] = {
# ── EPI channel (the form): Emission, Reception, Resonance ──────────────
EMISSION: OperatorContract(
name=EMISSION,
english_name="Emission",
glyph="AL",
purpose="Activates an EPI from a latent state (founding emission).",
primary_channel=StateChannel.EPI,
primary_direction=EffectDirection.INCREASE,
scale=OperatorScale.NODE,
postcondition="EPI not decreased; νf, phase and ΔNFR unchanged",
context=ContractContext.NETWORK,
nodal_expression=(
"A'L: EPI' = clip(EPI + boost); νf, ΔNFR and phase unchanged; "
"no positive continuous-rate assertion"
),
pdf_reference="TNFR.pdf §2.2.1 (1) A'L — Emisión fundacional",
),
RECEPTION: OperatorContract(
name=RECEPTION,
english_name="Reception",
glyph="EN",
purpose="Blends local EPI with the current neighbour EPI field.",
primary_channel=StateChannel.EPI,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NODE,
postcondition=(
"Immediate operator-local C(t) unchanged; ΔNFR and dEPI unchanged"
),
context=ContractContext.NETWORK,
nodal_expression=(
"E'N: EPI' = clip((1-mix)·EPI + mix·neighbor_mean); "
"stored ΔNFR and dEPI unchanged"
),
pdf_reference="TNFR.pdf §2.2.1 (2) E'N — Recepción estructural",
),
RESONANCE: OperatorContract(
name=RESONANCE,
english_name="Resonance",
glyph="RA",
purpose="Propagates an EPI across couplings without altering identity.",
primary_channel=StateChannel.EPI,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NODE,
postcondition="EPI structural identity (sign/kind) preserved",
context=ContractContext.IDENTITY,
nodal_expression=(
"R'A: U3-compatible EPI blend preserving sign/kind; "
"direct-path νf amplification and phase writes are conditional"
),
pdf_reference="TNFR.pdf §2.2.1 R'A — Resonancia",
),
# ── νf channel (frequency/mobility, capacity arm): SHA, VAL, NUL ────────
SILENCE: OperatorContract(
name=SILENCE,
english_name="Silence",
glyph="SHA",
purpose="Attenuates νf while preserving EPI at the event (structural latency).",
primary_channel=StateChannel.NU_F,
primary_direction=EffectDirection.DECREASE,
scale=OperatorScale.NODE,
postcondition="νf not increased; EPI, ΔNFR and phase unchanged during SHA",
context=ContractContext.NETWORK,
nodal_expression=(
"SH'A: νf'=α νf, EPI'=EPI; later unforced ∂EPI/∂t=0 " "requires νf·ΔNFR=0"
),
pdf_reference="TNFR.pdf §2.2.1 SH'A — Silencio",
),
EXPANSION: OperatorContract(
name=EXPANSION,
english_name="Expansion",
glyph="VAL",
purpose="Scales reorganization capacity (νf) without a state-dimension claim.",
primary_channel=StateChannel.NU_F,
primary_direction=EffectDirection.INCREASE,
scale=OperatorScale.NODE,
postcondition="νf not decreased (capacity added)",
context=ContractContext.NETWORK,
nodal_expression="VA'L: νf' ≥ νf; no state-dimension increase follows",
pdf_reference="TNFR.pdf §2.2.1 VA'L — Expansión",
),
CONTRACTION: OperatorContract(
name=CONTRACTION,
english_name="Contraction",
glyph="NUL",
purpose="Reduces capacity and scales pressure magnitude under its configured map.",
primary_channel=StateChannel.NU_F,
primary_direction=EffectDirection.DECREASE,
scale=OperatorScale.NODE,
postcondition="νf not increased (capacity removed)",
context=ContractContext.NETWORK,
nodal_expression="NU'L: νf' ≤ νf; ΔNFR' = densification_factor·ΔNFR",
pdf_reference="TNFR.pdf §2.2.1 NU'L — Contracción",
),
# ── θ channel (phase → |∇φ|, K_φ): Coupling, Mutation ───────────────────
COUPLING: OperatorContract(
name=COUPLING,
english_name="Coupling",
glyph="UM",
purpose="Synchronizes phase with neighbours (φᵢ ≈ φⱼ), reducing pressure.",
primary_channel=StateChannel.THETA,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NODE,
postcondition="|ΔNFR| not increased (mutual stabilization)",
context=ContractContext.NETWORK,
nodal_expression="U'M ⇒ φᵢ(t) → φⱼ(t) (phase synchronization)",
pdf_reference="TNFR.pdf §2.2.1 U'M — Acoplamiento",
),
MUTATION: OperatorContract(
name=MUTATION,
english_name="Mutation",
glyph="ZHIR",
purpose="Transforms the phase regime θ → θ' at a structural threshold.",
primary_channel=StateChannel.THETA,
primary_direction=EffectDirection.TRANSFORM,
scale=OperatorScale.NODE,
postcondition="θ transformed (θ → θ')",
context=ContractContext.PHASE,
nodal_expression="Z'HIR ⇒ θ → θ' when ΔEPI/Δt > ξ",
pdf_reference="TNFR.pdf §2.2.1 Z'HIR — Mutación",
),
# ── ΔNFR channel (pressure → Φ_s, count arm): IL, OZ, THOL, NAV ─────────
COHERENCE: OperatorContract(
name=COHERENCE,
english_name="Coherence",
glyph="IL",
purpose="Stabilizes form by reducing |ΔNFR| (negative feedback).",
primary_channel=StateChannel.DELTA_NFR,
primary_direction=EffectDirection.DECREASE,
scale=OperatorScale.NODE,
postcondition="|ΔNFR| not increased and C(t) not decreased",
context=ContractContext.NETWORK,
nodal_expression=(
"I'L: ΔNFR' = factor·ΔNFR, 0 ≤ factor < 1; "
"no future-flow convergence assertion"
),
pdf_reference="TNFR.pdf §2.2.1 (3) I'L — Coherencia estructural",
),
DISSONANCE: OperatorContract(
name=DISSONANCE,
english_name="Dissonance",
glyph="OZ",
purpose="Injects controlled instability, raising |ΔNFR| (may bifurcate).",
primary_channel=StateChannel.DELTA_NFR,
primary_direction=EffectDirection.INCREASE,
scale=OperatorScale.NODE,
postcondition="|ΔNFR| not decreased",
context=ContractContext.NODE,
nodal_expression=(
"O'Z: local |ΔNFR| not decreased in amplification mode; "
"no continuous acceleration or bifurcation assertion"
),
pdf_reference="TNFR.pdf §2.2.1 O'Z — Disonancia",
),
SELF_ORGANIZATION: OperatorContract(
name=SELF_ORGANIZATION,
english_name="SelfOrganization",
glyph="THOL",
purpose="Autopoietic reorganization: forms sub-EPIs while preserving global form.",
primary_channel=StateChannel.DELTA_NFR,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NODE,
postcondition=(
"parent EPI, nu_f and phase fixed; DeltaNFR follows signed "
"acceleration; nested child creation preserves parent identity"
),
context=ContractContext.NETWORK,
nodal_expression=(
"T'HOL: ΔNFR' = ΔNFR + κ·a_history; "
"child creation is a separate configured public-operator path"
),
pdf_reference="TNFR.pdf §2.2.1 T'HOL — Autoorganización",
),
TRANSITION: OperatorContract(
name=TRANSITION,
english_name="Transition",
glyph="NAV",
purpose="Controlled regime shift, retargeting ΔNFR toward a νf-aligned state.",
primary_channel=StateChannel.DELTA_NFR,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NODE,
postcondition="state changed (νf, θ, or ΔNFR)",
context=ContractContext.STATE,
nodal_expression="NA'V ⇒ ΔNFR → νf-aligned (regime transition)",
pdf_reference="TNFR.pdf §2.2.1 NA'V — Transición",
),
# ── EPI channel at NETWORK scale (U5 fractality): Recursivity ──────────────
RECURSIVITY: OperatorContract(
name=RECURSIVITY,
english_name="Recursivity",
glyph="REMESH",
purpose="Echoes the form (EPI) across time and scale (operational "
"fractality, U5).",
primary_channel=StateChannel.EPI,
primary_direction=EffectDirection.REORGANIZE,
scale=OperatorScale.NETWORK,
postcondition="node-level advisory; network effect = EPI mixed toward "
"temporal/multi-scale history",
context=ContractContext.ADVISORY,
nodal_expression=(
"RE'MESH network map: EPI_raw = (1-α)²·EPI(t) "
"+ α(1-α)·EPI(t-τ_l) + α·EPI(t-τ_g); EPI'=clip(EPI_raw)"
),
pdf_reference="TNFR.pdf §2.2.1 RE'MESH — Recursividad",
),
}
# ════════════════════════════════════════════════════════════════════════════
# Contract accessors and display labels
# ════════════════════════════════════════════════════════════════════════════
def contract_for(identifier: str) -> OperatorContract:
"""Return the contract for an executable name, display name, or glyph.
Resolution order: lowercase public executable identifier → title-case
display/class name → internal glyph code.
Raises :class:`KeyError` if not found.
"""
c = OPERATOR_CONTRACTS.get(identifier)
if c is not None:
return c
for contract in OPERATOR_CONTRACTS.values():
if identifier in (contract.english_name, contract.glyph):
return contract
raise KeyError(identifier)
def iter_contracts() -> tuple[OperatorContract, ...]:
"""Iterate the 13 canonical contracts (channel-ordered)."""
return tuple(OPERATOR_CONTRACTS.values())
def operators_in_channel(channel: StateChannel) -> tuple[str, ...]:
"""Title-case display names for operators in ``channel``."""
return tuple(
c.english_name
for c in OPERATOR_CONTRACTS.values()
if c.primary_channel is channel
)
def operators_at_scale(scale: OperatorScale) -> tuple[str, ...]:
"""Title-case display names for operators at ``scale`` (the U5 axis)."""
return tuple(
c.english_name for c in OPERATOR_CONTRACTS.values() if c.scale is scale
)
def english_name(identifier: str) -> str:
"""Return the title-case public display/class name for an identifier."""
return contract_for(identifier).english_name
def contract_identifiability_certificate(
features: tuple[str, ...] = (
"primary_channel",
"primary_direction",
"scale",
"context",
),
) -> ContractIdentifiabilityCertificate:
"""Partition operators by a declared instantaneous contract signature.
Supported features are the four executable contract classifications. Two
operators in one returned group cannot be distinguished from these features
alone. Text descriptions, glyphs and names are excluded because including
an identifier would make the inverse problem tautological.
"""
allowed = {"primary_channel", "primary_direction", "scale", "context"}
if not features or len(set(features)) != len(features):
raise ValueError("features must be a nonempty tuple without duplicates")
unknown = set(features) - allowed
if unknown:
raise ValueError(f"unsupported contract features: {sorted(unknown)}")
grouped: dict[tuple[str, ...], list[str]] = {}
for contract in iter_contracts():
signature = tuple(getattr(contract, feature).value for feature in features)
grouped.setdefault(signature, []).append(contract.english_name)
groups = tuple(
(signature, tuple(names)) for signature, names in sorted(grouped.items())
)
unique = tuple(names[0] for _, names in groups if len(names) == 1)
ambiguous = tuple(names for _, names in groups if len(names) > 1)
return ContractIdentifiabilityCertificate(
features=tuple(features),
signature_groups=groups,
uniquely_identifiable=unique,
ambiguous_groups=ambiguous,
all_operators_identifiable=not ambiguous,
claim_status=(
"EXACT for declared contract features; trajectory and word "
"identification require temporal telemetry"
),
)
# ════════════════════════════════════════════════════════════════════════════
# Self-consistency
# ════════════════════════════════════════════════════════════════════════════
def verify_contract_consistency() -> None:
"""Assert the contracts agree with the canonical glyph↔name mapping and the
nodal-channel / dual-lever partition. Raises ``AssertionError`` on drift.
"""
# 1. All 13 canonical operators are covered exactly once.
names = set(OPERATOR_CONTRACTS)
expected = set(FUNCTION_TO_GLYPH)
assert names == expected, (
f"contract coverage drift: missing {expected - names}, "
f"extra {names - expected}"
)
# 2. glyph code matches the canonical grammar_types mapping.
for name, contract in OPERATOR_CONTRACTS.items():
canonical_glyph = FUNCTION_TO_GLYPH[name].value
assert (
contract.glyph == canonical_glyph
), f"{name}: glyph drift {contract.glyph} != {canonical_glyph}"
# 3. The primary-channel partition is exactly the canonical four-channel
# grouping. νf and ΔNFR form the dual lever; the tetrad remains a lossy
# diagnostic read-out rather than an operator-identification basis.
by_channel = {ch: set(operators_in_channel(ch)) for ch in StateChannel}
assert by_channel[StateChannel.EPI] == {
"Emission",
"Reception",
"Resonance",
"Recursivity",
}
assert by_channel[StateChannel.NU_F] == {"Silence", "Expansion", "Contraction"}
assert by_channel[StateChannel.THETA] == {"Coupling", "Mutation"}
assert by_channel[StateChannel.DELTA_NFR] == {
"Coherence",
"Dissonance",
"SelfOrganization",
"Transition",
}
# 4. The scale partition (U5 fractality): exactly one NETWORK-scale operator
# (REMESH), and NETWORK scale ⟺ advisory node-level context.
assert set(operators_at_scale(OperatorScale.NETWORK)) == {"Recursivity"}
assert len(operators_at_scale(OperatorScale.NODE)) == 12
for contract in OPERATOR_CONTRACTS.values():
is_network = contract.scale is OperatorScale.NETWORK
assert is_network == (
contract.context is ContractContext.ADVISORY
), f"{contract.name}: network-scale ⟺ advisory mismatch"