Repository navigation
Expand file tree
/
Copy pathrelational_return_geometry.py
More file actions
184 lines (155 loc) · 6.54 KB
/
Copy pathrelational_return_geometry.py
File metadata and controls
184 lines (155 loc) · 6.54 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
"""Static acute geometry for two C5 rings with a supplied return path.
The mathematical existence/uniqueness and recovery claims belong to
theory/nodal/RELATIONAL_PATTERN_MEMORY.md. This instrument encloses the
opposite-winding root, reconstructs rational witnesses and evaluates the
native field once per witness. It advances no time and executes no live event.
"""
from __future__ import annotations
import argparse
import math
from dataclasses import dataclass
from fractions import Fraction as Q
import networkx as nx
from tnfr.dynamics.relational import (
RelationalExchangeField,
RelationalExchangeModel,
evaluate_relational_exchange,
)
from tnfr.mathematics._rational_interval import (
I,
cos,
pi_interval,
sin,
)
from tnfr.physics.phase_cycle_geometry import (
PhaseChordExtension,
PhaseCycleState,
)
from tnfr.physics.phase_cycle_geometry import PhaseRootBracket as RootBracket
from tnfr.physics.phase_cycle_geometry import (
_enclose_decreasing_phase_root,
_return_path_nodal_affine_coefficients,
_return_path_storage_residual,
derive_phase_chord_extension,
derive_phase_cycle_geometry,
reconstruct_phase_cycle_state,
)
MODEL = RelationalExchangeModel(1.0)
RING_EDGES = tuple(
(offset + i, offset + (i + 1) % 5) for offset in (0, 5) for i in range(5)
)
MEDIATED_EDGES = RING_EDGES + ((0, 10), (10, 5))
RETURN_EDGE = (1, 6)
NAMED_CYCLES = ((0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (0, 10, 5, 6, 1))
CONNECTING_EDGES = ((0, 10), (10, 5), (6, 1))
@dataclass(frozen=True)
class GeometryWitness:
"""Exact circular witness plus a separate rounded native observation."""
state: PhaseCycleState
named_periods: tuple[Q, ...]
connecting_turns: tuple[Q, ...]
minimum_acute_margin_turns: Q
native_field: RelationalExchangeField
status: str
@property
def maximum_native_rate(self):
return max(map(abs, self.native_field.form_rate + self.native_field.phase_rate))
@dataclass(frozen=True)
class ReturnGeometryReport:
extension: PhaseChordExtension
opposite_root: RootBracket
same: GeometryWitness
opposite: GeometryWitness
opposite_phase_storage_excess: I
scope: str = "static_supplied_support_no_event_or_trajectory"
def root_residual(turns: Q | I) -> I:
"""Enclose F(t)=cos(t/4)-sin(t)-sin(2t/3), with t=2*pi*turns."""
return _return_path_storage_residual(turns, Q(0))
def enclose_opposite_root(*, refinements=40) -> RootBracket:
"""Bisect with strict outward-interval signs, rejecting unresolved signs.
The 1..64 refinement budget is numerical policy, not a model parameter.
No rounded transcendental sign or residual tolerance selects an endpoint.
"""
return _enclose_decreasing_phase_root(
root_residual, lower=Q(1, 12), upper=Q(1, 8), refinements=refinements
)
def opposite_nodal_turns(s: Q) -> tuple[Q, ...]:
"""Affine circular family; sine balance additionally requires F(2*pi*s)=0."""
if not isinstance(s, Q) or not Q(1, 12) <= s <= Q(1, 8):
raise ValueError("opposite parameter must be an exact turn in [1/12, 1/8]")
return tuple(a + b * s for a, b in _return_path_nodal_affine_coefficients())
def _gap(turns, left, right):
return (turns[right] - turns[left] + Q(1, 2)) % 1 - Q(1, 2)
def _witness(graph, geometry, turns, *, status):
state = reconstruct_phase_cycle_state(
geometry, edge_turns=tuple(_gap(turns, i, j) for i, j in geometry.edges)
)
periods = tuple(
sum((_gap(turns, i, j) for i, j in zip(cycle, cycle[1:] + cycle[:1])), Q(0))
for cycle in NAMED_CYCLES
)
# Native binary64 radians and measured residuals are separate evidence
# from the exact-turn state and certified ideal root interval.
native = graph.copy()
for node in native:
native.nodes[node].update(
EPI=0.0, nu_f=1.0, theta=math.tau * float(state.nodal_turns[node])
)
return GeometryWitness(
state=state,
named_periods=periods,
connecting_turns=tuple(_gap(turns, i, j) for i, j in CONNECTING_EDGES),
minimum_acute_margin_turns=Q(1, 4) - max(map(abs, state.edge_turns)),
native_field=evaluate_relational_exchange(native, model=MODEL),
status=status,
)
def analyze_return_geometry(*, refinements=40) -> ReturnGeometryReport:
"""Reconstruct both sectors on held unit support without a time step."""
root = enclose_opposite_root(refinements=refinements)
before = nx.Graph()
before.add_nodes_from(range(11))
before.add_edges_from(MEDIATED_EDGES, weight=1.0)
after = before.copy()
after.add_edge(*RETURN_EDGE, weight=1.0)
old_geometry = derive_phase_cycle_geometry(before)
geometry = derive_phase_cycle_geometry(after)
extension = derive_phase_chord_extension(old_geometry, geometry)
same_turns = tuple(Q(node % 5, 5) if node < 10 else Q(0) for node in range(11))
angle = 2 * pi_interval() * I(root.lower, root.upper)
# Ideal structural storage, not physical energy or an occurrence law.
opposite_storage = (
8 * (1 - sin(angle / 4)) + 2 * (1 - cos(angle)) + 3 * (1 - cos(2 * angle / 3))
)
same_storage = 10 * (1 - cos(2 * pi_interval() / 5))
return ReturnGeometryReport(
extension=extension,
opposite_root=root,
same=_witness(
after, geometry, same_turns, status="exact_turn_sine_balance_by_oddness"
),
opposite=_witness(
after,
geometry,
opposite_nodal_turns(root.midpoint),
status="rational_midpoint_not_an_exact_equilibrium",
),
opposite_phase_storage_excess=opposite_storage - same_storage,
)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--refinements", type=int, default=40)
report = analyze_return_geometry(refinements=parser.parse_args().refinements)
root = report.opposite_root
print(f"Certified root turns: [{root.lower}, {root.upper}]")
print(f"Root midpoint radians (rounded): {math.tau * float(root.midpoint):.16g}")
excess = report.opposite_phase_storage_excess
print(f"Certified opposite phase-storage excess: [{excess.lo}, {excess.hi}]")
for name, witness in (("same", report.same), ("opposite", report.opposite)):
print(f"{name}: {witness.status}; periods={witness.named_periods}")
print(f" connecting turns: {witness.connecting_turns}")
print(f" native maximum rate: {witness.maximum_native_rate:.8g}")
print(
f" native phase storage: {float(witness.native_field.phase_storage):.16g}"
)
if __name__ == "__main__":
main()