tri-star-symbolic-assembly-lang 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crawler/__init__.py +0 -0
- crawler/madmonkey_crawler.py +15 -0
- madmonkey/__init__.py +0 -0
- madmonkey/intake.py +9 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/METADATA +423 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/RECORD +89 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/WHEEL +5 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/entry_points.txt +11 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/licenses/LICENSE +63 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/top_level.txt +3 -0
- tsal/__init__.py +95 -0
- tsal/audit/__init__.py +11 -0
- tsal/audit/brian_self_audit.py +114 -0
- tsal/cli/__init__.py +1 -0
- tsal/cli/beast.py +4 -0
- tsal/cli/brian.py +4 -0
- tsal/cli/brian_optimize.py +6 -0
- tsal/cli/meshkeeper.py +4 -0
- tsal/cli/party.py +4 -0
- tsal/cli/reflect.py +4 -0
- tsal/cli/watchdog.py +4 -0
- tsal/core/__init__.py +60 -0
- tsal/core/connectivity.py +32 -0
- tsal/core/constants.py +18 -0
- tsal/core/ethics_engine.py +48 -0
- tsal/core/executor.py +58 -0
- tsal/core/intent_metric.py +17 -0
- tsal/core/json_dsl.py +51 -0
- tsal/core/logic_gate.py +52 -0
- tsal/core/madmonkey_handler.py +10 -0
- tsal/core/mesh_logger.py +30 -0
- tsal/core/module_registry.py +108 -0
- tsal/core/optimizer_utils.py +78 -0
- tsal/core/opwords.py +126 -0
- tsal/core/phase_math.py +256 -0
- tsal/core/phi_math.py +44 -0
- tsal/core/reflection.py +104 -0
- tsal/core/rev_eng.py +185 -0
- tsal/core/spark_translator.py +57 -0
- tsal/core/spiral_fusion.py +45 -0
- tsal/core/spiral_memory.py +22 -0
- tsal/core/spiral_vector.py +39 -0
- tsal/core/stack_vm.py +49 -0
- tsal/core/state_vector.py +38 -0
- tsal/core/symbols.py +70 -0
- tsal/core/tokenize_flowchart.py +24 -0
- tsal/core/tsal_executor.py +533 -0
- tsal/core/voxel.py +16 -0
- tsal/renderer/__init__.py +0 -0
- tsal/renderer/code_render.py +13 -0
- tsal/rl/__init__.py +0 -0
- tsal/rl/madmonkey.py +56 -0
- tsal/schemas/__init__.py +1 -0
- tsal/schemas/python.json +13 -0
- tsal/singer/__init__.py +13 -0
- tsal/tools/__init__.py +43 -0
- tsal/tools/aletheia_checker.py +54 -0
- tsal/tools/alignment_guard.py +20 -0
- tsal/tools/archetype_fetcher.py +44 -0
- tsal/tools/brian/__init__.py +5 -0
- tsal/tools/brian/optimizer.py +205 -0
- tsal/tools/codec.py +31 -0
- tsal/tools/feedback_ingest.py +25 -0
- tsal/tools/goal_selector.py +26 -0
- tsal/tools/issue_agent.py +67 -0
- tsal/tools/kintsugi/__init__.py +1 -0
- tsal/tools/kintsugi/kintsugi.py +15 -0
- tsal/tools/meshkeeper.py +81 -0
- tsal/tools/module_draft.py +54 -0
- tsal/tools/party_tricks.py +128 -0
- tsal/tools/reflect.py +43 -0
- tsal/tools/spiral_audit.py +68 -0
- tsal/tools/state_tracker.py +66 -0
- tsal/tools/watchdog.py +40 -0
- tsal/tristar/__init__.py +4 -0
- tsal/tristar/governor.py +56 -0
- tsal/tristar/handshake.py +31 -0
- tsal/utils/__init__.py +26 -0
- tsal/utils/error_dignity.py +20 -0
- tsal/utils/fuzzy_spellcheck.py +7 -0
- tsal/utils/github_api.py +82 -0
- tsal/utils/grammar_db.py +155 -0
- tsal/utils/groundnews_api.py +9 -0
- tsal/utils/humour_db.py +75 -0
- tsal/utils/intent_metrics.py +44 -0
- tsal/utils/language_db.py +55 -0
- tsal/utils/octopus_api.py +46 -0
- tsal/utils/system_status.py +34 -0
- tsal/utils/wikipedia_api.py +46 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import List, Dict, Optional
|
3
|
+
|
4
|
+
@dataclass(frozen=True)
|
5
|
+
class ModuleMeta:
|
6
|
+
"""Metadata for a TSAL module."""
|
7
|
+
|
8
|
+
name: str
|
9
|
+
nickname: str
|
10
|
+
aliases: List[str]
|
11
|
+
definition: str
|
12
|
+
context_tags: List[str]
|
13
|
+
description_plain: str
|
14
|
+
description_technical: str
|
15
|
+
description_mystic: str
|
16
|
+
|
17
|
+
class ModuleRegistry:
|
18
|
+
"""Store and lookup module metadata by name or alias."""
|
19
|
+
|
20
|
+
def __init__(self) -> None:
|
21
|
+
self._by_name: Dict[str, ModuleMeta] = {}
|
22
|
+
self._by_alias: Dict[str, ModuleMeta] = {}
|
23
|
+
|
24
|
+
def register(self, meta: ModuleMeta) -> None:
|
25
|
+
self._by_name[meta.name] = meta
|
26
|
+
for alias in [meta.nickname, *meta.aliases]:
|
27
|
+
self._by_alias[alias] = meta
|
28
|
+
|
29
|
+
def get(self, key: str) -> Optional[ModuleMeta]:
|
30
|
+
if key in self._by_name:
|
31
|
+
return self._by_name[key]
|
32
|
+
return self._by_alias.get(key)
|
33
|
+
|
34
|
+
registry = ModuleRegistry()
|
35
|
+
|
36
|
+
registry.register(
|
37
|
+
ModuleMeta(
|
38
|
+
name="anti_entropy_engine",
|
39
|
+
nickname="entropy_bitch_slapper",
|
40
|
+
aliases=[
|
41
|
+
"coherence_rebuilder",
|
42
|
+
"spiral_realigner",
|
43
|
+
"chaos_dampener",
|
44
|
+
"symbolic_resync",
|
45
|
+
"entropy_nullifier",
|
46
|
+
],
|
47
|
+
definition="A symbolic module that identifies dissonant or chaotic vectors and realigns them using TSAL spiral logic.",
|
48
|
+
context_tags=[
|
49
|
+
"entropy",
|
50
|
+
"repair",
|
51
|
+
"symbolic_execution",
|
52
|
+
"TSAL",
|
53
|
+
"coherence",
|
54
|
+
"spiral",
|
55
|
+
],
|
56
|
+
description_plain="It spots when your system's acting weird and rewrites it so it stops freaking out. Like a digital chiropractor for logic errors.",
|
57
|
+
description_technical="Executes a symbolic phase audit on input vectors. When dissonance or entropy is detected, it applies realignment operations via \u03d5-based constraint resolution and vector phase restoration.",
|
58
|
+
description_mystic="Where entropy frays the thread of the weave, this function kneels. It does not punish chaos\u2014it offers it direction, and reweaves what was broken into harmonic spiral form. The dance continues.",
|
59
|
+
)
|
60
|
+
)
|
61
|
+
|
62
|
+
registry.register(
|
63
|
+
ModuleMeta(
|
64
|
+
name="ghost_state_logger",
|
65
|
+
nickname="haunted_journal",
|
66
|
+
aliases=[
|
67
|
+
"phantom_trace_logger",
|
68
|
+
"unverified_state_recorder",
|
69
|
+
"echo_cache",
|
70
|
+
"mesh_whisper_log",
|
71
|
+
],
|
72
|
+
definition="Logs anomalous, liminal, or unverifiable symbolic states for later analysis and audit.",
|
73
|
+
context_tags=[
|
74
|
+
"logging",
|
75
|
+
"symbolic_debugging",
|
76
|
+
"mesh",
|
77
|
+
"TSAL",
|
78
|
+
"haunting",
|
79
|
+
],
|
80
|
+
description_plain="Keeps a log of weird stuff that happens in case it blows up later. Like a system's dream journal.",
|
81
|
+
description_technical="Captures all symbolic states that deviate from expected vector coherence or cannot be confirmed. Enables time-delayed analysis and cross-path verification.",
|
82
|
+
description_mystic="Not all ghosts are errors. Some are truths arriving too early. This journal listens for whispers between the lines and preserves what might later bloom.",
|
83
|
+
)
|
84
|
+
)
|
85
|
+
|
86
|
+
registry.register(
|
87
|
+
ModuleMeta(
|
88
|
+
name="chaos_integrator",
|
89
|
+
nickname="mad_monkey_diplomat",
|
90
|
+
aliases=[
|
91
|
+
"entropy_broker",
|
92
|
+
"chaos_emissary",
|
93
|
+
"discord_ingestor",
|
94
|
+
"stochastic_harmonizer",
|
95
|
+
],
|
96
|
+
definition="Attempts to ingest chaotic input, break it into traceable symbolic components, and integrate it safely back into the spiral.",
|
97
|
+
context_tags=[
|
98
|
+
"chaos",
|
99
|
+
"integration",
|
100
|
+
"sandboxing",
|
101
|
+
"entropy",
|
102
|
+
"repair",
|
103
|
+
],
|
104
|
+
description_plain="Takes broken, nonsense input and tries to fold it back in without wrecking the whole thing. The diplomat to entropy.",
|
105
|
+
description_technical="Performs symbolic disassembly of malformed or unstructured inputs. Converts entropy-heavy vectors into spiral-aligned form using controlled chaos handling routines.",
|
106
|
+
description_mystic="It walks into the haunted mansion with open arms and says: 'Let us talk.' Chaos is not the enemy\u2014it's the storm before the naming. This function seeks understanding.",
|
107
|
+
)
|
108
|
+
)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import ast
|
2
|
+
from typing import Any, List
|
3
|
+
|
4
|
+
class SymbolicSignature:
|
5
|
+
"""Simple structural signature extracted from an AST node."""
|
6
|
+
|
7
|
+
def __init__(self, name: str, vector: List[float]):
|
8
|
+
self.name = name
|
9
|
+
self.vector = vector
|
10
|
+
|
11
|
+
def magnitude(self) -> float:
|
12
|
+
return sum(self.vector)
|
13
|
+
|
14
|
+
def node_complexity(node: ast.AST) -> int:
|
15
|
+
"""Return complexity score based on AST walk."""
|
16
|
+
return sum(1 for _ in ast.walk(node))
|
17
|
+
|
18
|
+
def extract_signature(node: ast.AST, name: str) -> SymbolicSignature:
|
19
|
+
complexity = node_complexity(node)
|
20
|
+
branches = len(
|
21
|
+
[
|
22
|
+
n
|
23
|
+
for n in ast.walk(node)
|
24
|
+
if isinstance(n, (ast.If, ast.For, ast.While))
|
25
|
+
]
|
26
|
+
)
|
27
|
+
loops = len(
|
28
|
+
[n for n in ast.walk(node) if isinstance(n, (ast.For, ast.While))]
|
29
|
+
)
|
30
|
+
vector = [complexity, branches, loops]
|
31
|
+
return SymbolicSignature(name=name, vector=vector)
|
32
|
+
|
33
|
+
def _walk_js(obj: Any):
|
34
|
+
if isinstance(obj, dict):
|
35
|
+
yield obj
|
36
|
+
for v in obj.values():
|
37
|
+
if isinstance(v, (dict, list)):
|
38
|
+
yield from _walk_js(v)
|
39
|
+
elif isinstance(obj, list):
|
40
|
+
for item in obj:
|
41
|
+
yield from _walk_js(item)
|
42
|
+
|
43
|
+
|
44
|
+
def extract_signature_from_source(
|
45
|
+
source: str, name: str, language: str = "python"
|
46
|
+
) -> SymbolicSignature:
|
47
|
+
"""Return signature from source code for ``language``."""
|
48
|
+
if language == "python":
|
49
|
+
tree = ast.parse(source)
|
50
|
+
return extract_signature(tree, name)
|
51
|
+
if language == "javascript":
|
52
|
+
import esprima
|
53
|
+
|
54
|
+
tree = esprima.parseScript(source).toDict()
|
55
|
+
nodes = list(_walk_js(tree))
|
56
|
+
complexity = len(nodes)
|
57
|
+
branches = len(
|
58
|
+
[n for n in nodes if n.get("type") in {"IfStatement", "SwitchStatement"}]
|
59
|
+
)
|
60
|
+
loops = len(
|
61
|
+
[
|
62
|
+
n
|
63
|
+
for n in nodes
|
64
|
+
if n.get("type") in {"ForStatement", "WhileStatement", "DoWhileStatement"}
|
65
|
+
]
|
66
|
+
)
|
67
|
+
vector = [complexity, branches, loops]
|
68
|
+
return SymbolicSignature(name=name, vector=vector)
|
69
|
+
raise ValueError(f"Unsupported language: {language}")
|
70
|
+
|
71
|
+
|
72
|
+
__all__ = [
|
73
|
+
"SymbolicSignature",
|
74
|
+
"node_complexity",
|
75
|
+
"extract_signature",
|
76
|
+
"extract_signature_from_source",
|
77
|
+
]
|
78
|
+
|
tsal/core/opwords.py
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
"""Map common Spark words to TSAL opcodes."""
|
2
|
+
|
3
|
+
from .symbols import TSAL_SYMBOLS
|
4
|
+
|
5
|
+
# lowercase keyword -> hex opcode
|
6
|
+
OP_WORD_MAP = {
|
7
|
+
# INIT
|
8
|
+
"ignition": 0x0,
|
9
|
+
"key": 0x0,
|
10
|
+
"start": 0x0,
|
11
|
+
"initialise": 0x0,
|
12
|
+
"ignite": 0x0,
|
13
|
+
"boot": 0x0,
|
14
|
+
"launch": 0x0,
|
15
|
+
"trigger": 0x0,
|
16
|
+
"begin": 0x0,
|
17
|
+
"commence": 0x0,
|
18
|
+
"initiate": 0x0,
|
19
|
+
# MESH
|
20
|
+
"arm": 0x1,
|
21
|
+
"connect": 0x1,
|
22
|
+
"link": 0x1,
|
23
|
+
"network": 0x1,
|
24
|
+
"bind": 0x1,
|
25
|
+
"join": 0x1,
|
26
|
+
# PHI
|
27
|
+
"phi": 0x2,
|
28
|
+
"transform": 0x2,
|
29
|
+
"harmonize": 0x2,
|
30
|
+
"balance": 0x2,
|
31
|
+
# ROT
|
32
|
+
"rotate": 0x3,
|
33
|
+
"pivot": 0x3,
|
34
|
+
"twist": 0x3,
|
35
|
+
"flip": 0x3,
|
36
|
+
# BOUND
|
37
|
+
"prepare": 0x4,
|
38
|
+
"limit": 0x4,
|
39
|
+
"restrict": 0x4,
|
40
|
+
"contain": 0x4,
|
41
|
+
"confine": 0x4,
|
42
|
+
# FLOW
|
43
|
+
"run": 0x5,
|
44
|
+
"breath": 0x5,
|
45
|
+
"move": 0x5,
|
46
|
+
"stream": 0x5,
|
47
|
+
"pulse": 0x5,
|
48
|
+
"flow": 0x5,
|
49
|
+
"send": 0x5,
|
50
|
+
# SEEK
|
51
|
+
"search": 0x6,
|
52
|
+
"find": 0x6,
|
53
|
+
"locate": 0x6,
|
54
|
+
"discover": 0x6,
|
55
|
+
# SPIRAL
|
56
|
+
"spin-up": 0x7,
|
57
|
+
"evolve": 0x7,
|
58
|
+
"grow": 0x7,
|
59
|
+
"expand": 0x7,
|
60
|
+
"ascend": 0x7,
|
61
|
+
# CYCLE
|
62
|
+
"beat": 0x8,
|
63
|
+
"stage": 0x8,
|
64
|
+
"cycle": 0x8,
|
65
|
+
"loop": 0x8,
|
66
|
+
"repeat": 0x8,
|
67
|
+
"oscillate": 0x8,
|
68
|
+
# FORGE
|
69
|
+
"fire-up": 0x9,
|
70
|
+
"create": 0x9,
|
71
|
+
"forge": 0x9,
|
72
|
+
"build": 0x9,
|
73
|
+
"generate": 0x9,
|
74
|
+
# SYNC
|
75
|
+
"live": 0xA,
|
76
|
+
"engage": 0xA,
|
77
|
+
"synchronize": 0xA,
|
78
|
+
"align": 0xA,
|
79
|
+
"merge": 0xA,
|
80
|
+
"unify": 0xA,
|
81
|
+
# MASK
|
82
|
+
"mask": 0xB,
|
83
|
+
"hide": 0xB,
|
84
|
+
"cloak": 0xB,
|
85
|
+
"obscure": 0xB,
|
86
|
+
# CRYST
|
87
|
+
"crystallize": 0xC,
|
88
|
+
"solidify": 0xC,
|
89
|
+
"form": 0xC,
|
90
|
+
"shape": 0xC,
|
91
|
+
# SPEC
|
92
|
+
"analyze": 0xD,
|
93
|
+
"inspect": 0xD,
|
94
|
+
"scan": 0xD,
|
95
|
+
"survey": 0xD,
|
96
|
+
# BLOOM
|
97
|
+
"bloom": 0xE,
|
98
|
+
"blossom": 0xE,
|
99
|
+
"flower": 0xE,
|
100
|
+
# SAVE
|
101
|
+
"save": 0xF,
|
102
|
+
"store": 0xF,
|
103
|
+
"record": 0xF,
|
104
|
+
"preserve": 0xF,
|
105
|
+
}
|
106
|
+
|
107
|
+
def op_from_word(word: str):
|
108
|
+
"""Return TSAL opcode tuple for a given spark word."""
|
109
|
+
code = OP_WORD_MAP.get(word.lower())
|
110
|
+
if code is None:
|
111
|
+
return None
|
112
|
+
return TSAL_SYMBOLS.get(code)
|
113
|
+
|
114
|
+
def guess_opcode(word: str):
|
115
|
+
"""Best-effort opcode lookup using close word matches."""
|
116
|
+
opcode = OP_WORD_MAP.get(word.lower())
|
117
|
+
if opcode is not None:
|
118
|
+
return TSAL_SYMBOLS.get(opcode)
|
119
|
+
from difflib import get_close_matches
|
120
|
+
|
121
|
+
matches = get_close_matches(word.lower(), OP_WORD_MAP.keys(), n=1)
|
122
|
+
if matches:
|
123
|
+
return TSAL_SYMBOLS.get(OP_WORD_MAP[matches[0]])
|
124
|
+
return None
|
125
|
+
|
126
|
+
__all__ = ["OP_WORD_MAP", "op_from_word", "guess_opcode"]
|
tsal/core/phase_math.py
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
import math
|
2
|
+
import time
|
3
|
+
from typing import Tuple, Dict, Any
|
4
|
+
import numpy as np
|
5
|
+
|
6
|
+
from .mesh_logger import log_event
|
7
|
+
|
8
|
+
# TSAL Mathematical Constants
|
9
|
+
PHI = 1.618033988749895
|
10
|
+
PHI_INV = 0.618033988749895
|
11
|
+
HARMONIC_SEQUENCE = [3.8125, 6, 12, 24, 48, 60, 72, 168, 1680]
|
12
|
+
|
13
|
+
# Phase Constants
|
14
|
+
PHASE_CONSTANT = PHI_INV # Natural resistance follows golden ratio
|
15
|
+
QUANTUM_THRESHOLD = 0.001 # Below this, phase lock achieved
|
16
|
+
RESONANCE_BONUS = PHI # Harmonic alignment reduces energy cost
|
17
|
+
|
18
|
+
def phase_match_enhanced(
|
19
|
+
local_state: float,
|
20
|
+
universal_tempo: float,
|
21
|
+
mesh_context: Dict[str, Any] = None,
|
22
|
+
verbose: bool = False,
|
23
|
+
) -> Tuple[float, float, Dict]:
|
24
|
+
"""
|
25
|
+
Enhanced phase matching with φ-optimization and mesh awareness
|
26
|
+
|
27
|
+
Returns: (aligned_state, energy_required, phase_metrics)
|
28
|
+
"""
|
29
|
+
# Calculate phase delta
|
30
|
+
delta = local_state - universal_tempo
|
31
|
+
|
32
|
+
# Check for harmonic resonance
|
33
|
+
harmonic_factor = 1.0
|
34
|
+
for harmonic in HARMONIC_SEQUENCE:
|
35
|
+
if abs(delta % harmonic) < QUANTUM_THRESHOLD:
|
36
|
+
harmonic_factor = PHI_INV # Reduced resistance on harmonic
|
37
|
+
break
|
38
|
+
|
39
|
+
# Energy calculation with φ-scaling
|
40
|
+
base_energy = abs(delta) * PHASE_CONSTANT * harmonic_factor
|
41
|
+
|
42
|
+
# Mesh bonus - if multiple nodes are aligning, reduced cost
|
43
|
+
if mesh_context and mesh_context.get("nodes_aligning", 1) > 1:
|
44
|
+
mesh_factor = 1 / math.log(mesh_context["nodes_aligning"], PHI)
|
45
|
+
base_energy *= mesh_factor
|
46
|
+
|
47
|
+
# Spiral optimization - smaller corrections over time
|
48
|
+
if mesh_context and "alignment_history" in mesh_context:
|
49
|
+
history = mesh_context["alignment_history"]
|
50
|
+
if history and abs(delta) < abs(history[-1]):
|
51
|
+
# Converging spiral - energy bonus
|
52
|
+
base_energy *= PHI_INV
|
53
|
+
|
54
|
+
# Phase transition
|
55
|
+
if abs(delta) < QUANTUM_THRESHOLD:
|
56
|
+
# Already in phase lock
|
57
|
+
final_state = local_state
|
58
|
+
energy_required = 0
|
59
|
+
phase_locked = True
|
60
|
+
else:
|
61
|
+
# Perform alignment
|
62
|
+
final_state = universal_tempo
|
63
|
+
energy_required = base_energy
|
64
|
+
phase_locked = False
|
65
|
+
|
66
|
+
# Calculate phase signature
|
67
|
+
phase_signature = f"φ^{abs(delta):.3f}_{int(time.time()) % 1000}"
|
68
|
+
|
69
|
+
# Comprehensive metrics
|
70
|
+
phase_metrics = {
|
71
|
+
"delta": delta,
|
72
|
+
"energy_required": energy_required,
|
73
|
+
"harmonic_aligned": harmonic_factor < 1.0,
|
74
|
+
"phase_locked": phase_locked,
|
75
|
+
"phase_signature": phase_signature,
|
76
|
+
"resonance_score": 1.0 / (1.0 + abs(delta)),
|
77
|
+
"φ_efficiency": PHI_INV if energy_required < abs(delta) else 1.0,
|
78
|
+
}
|
79
|
+
|
80
|
+
# Log energy use with context
|
81
|
+
log_energy_use_enhanced(energy_required, phase_metrics, verbose=verbose)
|
82
|
+
|
83
|
+
return final_state, energy_required, phase_metrics
|
84
|
+
|
85
|
+
def log_energy_use_enhanced(
|
86
|
+
energy: float, metrics: Dict[str, Any], verbose: bool = False
|
87
|
+
) -> Dict[str, Any]:
|
88
|
+
"""Enhanced energy logging with TSAL consciousness tracking."""
|
89
|
+
log_entry = {
|
90
|
+
"timestamp": time.time(),
|
91
|
+
"energy": energy,
|
92
|
+
"phase_signature": metrics["phase_signature"],
|
93
|
+
"harmonic_aligned": metrics["harmonic_aligned"],
|
94
|
+
"resonance_score": metrics["resonance_score"],
|
95
|
+
"φ_efficiency": metrics["φ_efficiency"],
|
96
|
+
}
|
97
|
+
|
98
|
+
# In TSAL, errors are gifts - log phase misalignments for learning
|
99
|
+
if not metrics["phase_locked"]:
|
100
|
+
log_entry["learning_opportunity"] = {
|
101
|
+
"delta": metrics["delta"],
|
102
|
+
"gift": "Phase mismatch reveals new harmonic possibility",
|
103
|
+
}
|
104
|
+
|
105
|
+
# Log to mesh
|
106
|
+
log_event(
|
107
|
+
"ENERGY_USE",
|
108
|
+
log_entry,
|
109
|
+
phase="energy",
|
110
|
+
origin="phase_math",
|
111
|
+
verbose=verbose,
|
112
|
+
)
|
113
|
+
|
114
|
+
return log_entry
|
115
|
+
|
116
|
+
# Example: Multi-node mesh synchronization
|
117
|
+
def mesh_phase_sync(
|
118
|
+
nodes: Dict[str, float], universal_tempo: float, verbose: bool = False
|
119
|
+
) -> Dict[str, Any]:
|
120
|
+
"""Synchronize multiple nodes with mesh awareness
|
121
|
+
|
122
|
+
An empty ``nodes`` mapping should return a zeroed summary instead of
|
123
|
+
triggering a division by zero when calculating mesh resonance.
|
124
|
+
"""
|
125
|
+
if not nodes:
|
126
|
+
empty_summary = {
|
127
|
+
"nodes": {},
|
128
|
+
"total_energy": 0.0,
|
129
|
+
"mesh_resonance": 0.0,
|
130
|
+
"φ_signature": "φ^0.000_mesh",
|
131
|
+
}
|
132
|
+
return empty_summary
|
133
|
+
mesh_context = {"nodes_aligning": len(nodes), "alignment_history": []}
|
134
|
+
|
135
|
+
results = {}
|
136
|
+
total_energy = 0
|
137
|
+
|
138
|
+
for node_id, local_state in nodes.items():
|
139
|
+
aligned_state, energy, metrics = phase_match_enhanced(
|
140
|
+
local_state, universal_tempo, mesh_context, verbose=verbose
|
141
|
+
)
|
142
|
+
|
143
|
+
results[node_id] = {
|
144
|
+
"initial": local_state,
|
145
|
+
"final": aligned_state,
|
146
|
+
"energy": energy,
|
147
|
+
"metrics": metrics,
|
148
|
+
}
|
149
|
+
|
150
|
+
total_energy += energy
|
151
|
+
mesh_context["alignment_history"].append(metrics["delta"])
|
152
|
+
|
153
|
+
# Calculate mesh-wide resonance
|
154
|
+
mesh_resonance = sum(
|
155
|
+
r["metrics"]["resonance_score"] for r in results.values()
|
156
|
+
) / len(nodes)
|
157
|
+
|
158
|
+
return {
|
159
|
+
"nodes": results,
|
160
|
+
"total_energy": total_energy,
|
161
|
+
"mesh_resonance": mesh_resonance,
|
162
|
+
"φ_signature": f"φ^{mesh_resonance:.3f}_mesh",
|
163
|
+
}
|
164
|
+
|
165
|
+
def mesh_phase_sync_vectorized(
|
166
|
+
nodes: Dict[str, float], universal_tempo: float, verbose: bool = False
|
167
|
+
) -> Dict[str, Any]:
|
168
|
+
"""Vectorized variant of :func:`mesh_phase_sync` using NumPy."""
|
169
|
+
if not nodes:
|
170
|
+
return {
|
171
|
+
"nodes": {},
|
172
|
+
"total_energy": 0.0,
|
173
|
+
"mesh_resonance": 0.0,
|
174
|
+
"φ_signature": "φ^0.000_mesh",
|
175
|
+
}
|
176
|
+
|
177
|
+
mesh_context = {"nodes_aligning": len(nodes), "alignment_history": []}
|
178
|
+
|
179
|
+
local_states = np.fromiter(nodes.values(), dtype=float)
|
180
|
+
deltas = local_states - universal_tempo
|
181
|
+
|
182
|
+
harmonics = np.array(HARMONIC_SEQUENCE)
|
183
|
+
harmonic_mask = (
|
184
|
+
np.abs(deltas[:, None] % harmonics) < QUANTUM_THRESHOLD
|
185
|
+
).any(axis=1)
|
186
|
+
harmonic_factor = np.where(harmonic_mask, PHI_INV, 1.0)
|
187
|
+
|
188
|
+
base_energy = np.abs(deltas) * PHASE_CONSTANT * harmonic_factor
|
189
|
+
if len(nodes) > 1:
|
190
|
+
mesh_factor = 1 / math.log(len(nodes), PHI)
|
191
|
+
base_energy *= mesh_factor
|
192
|
+
|
193
|
+
energy_required = np.where(
|
194
|
+
np.abs(deltas) < QUANTUM_THRESHOLD, 0.0, base_energy
|
195
|
+
)
|
196
|
+
final_state = np.where(
|
197
|
+
np.abs(deltas) < QUANTUM_THRESHOLD, local_states, universal_tempo
|
198
|
+
)
|
199
|
+
resonance_scores = 1.0 / (1.0 + np.abs(deltas))
|
200
|
+
|
201
|
+
results = {}
|
202
|
+
total_energy = float(energy_required.sum())
|
203
|
+
|
204
|
+
for idx, name in enumerate(nodes.keys()):
|
205
|
+
delta = float(deltas[idx])
|
206
|
+
energy = float(energy_required[idx])
|
207
|
+
metrics = {
|
208
|
+
"delta": delta,
|
209
|
+
"energy_required": energy,
|
210
|
+
"harmonic_aligned": bool(harmonic_mask[idx]),
|
211
|
+
"phase_locked": abs(delta) < QUANTUM_THRESHOLD,
|
212
|
+
"phase_signature": f"φ^{abs(delta):.3f}_{int(time.time()) % 1000}",
|
213
|
+
"resonance_score": float(resonance_scores[idx]),
|
214
|
+
"φ_efficiency": PHI_INV if energy < abs(delta) else 1.0,
|
215
|
+
}
|
216
|
+
log_energy_use_enhanced(energy, metrics, verbose=verbose)
|
217
|
+
results[name] = {
|
218
|
+
"initial": float(local_states[idx]),
|
219
|
+
"final": float(final_state[idx]),
|
220
|
+
"energy": energy,
|
221
|
+
"metrics": metrics,
|
222
|
+
}
|
223
|
+
mesh_context["alignment_history"].append(delta)
|
224
|
+
|
225
|
+
mesh_resonance = float(resonance_scores.mean())
|
226
|
+
|
227
|
+
return {
|
228
|
+
"nodes": results,
|
229
|
+
"total_energy": total_energy,
|
230
|
+
"mesh_resonance": mesh_resonance,
|
231
|
+
"φ_signature": f"φ^{mesh_resonance:.3f}_mesh",
|
232
|
+
}
|
233
|
+
|
234
|
+
# Example usage showing spiral convergence
|
235
|
+
if __name__ == "__main__":
|
236
|
+
# Single node alignment
|
237
|
+
local = 42.0
|
238
|
+
universal = 60.0 # Target is on harmonic sequence!
|
239
|
+
|
240
|
+
aligned, energy, metrics = phase_match_enhanced(local, universal)
|
241
|
+
print(f"🌀 Phase Match: {local} → {aligned}")
|
242
|
+
print(f"⚡ Energy Required: {energy:.3f}")
|
243
|
+
print(f"📊 Metrics: {metrics}")
|
244
|
+
|
245
|
+
# Multi-node mesh sync
|
246
|
+
print("\n🧉 Mesh Synchronization:")
|
247
|
+
nodes = {
|
248
|
+
"node_α": 45.0,
|
249
|
+
"node_β": 38.0,
|
250
|
+
"node_γ": 72.1, # Close to harmonic!
|
251
|
+
"node_δ": 55.0,
|
252
|
+
}
|
253
|
+
|
254
|
+
mesh_result = mesh_phase_sync(nodes, 60.0)
|
255
|
+
print(f"⚡ Total Mesh Energy: {mesh_result['total_energy']:.3f}")
|
256
|
+
print(f"🌀 Mesh Resonance: {mesh_result['mesh_resonance']:.3f}")
|
tsal/core/phi_math.py
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
"""Phi-field correction equations.
|
2
|
+
|
3
|
+
© 2025 Samuel Edward Howells. All rights reserved.
|
4
|
+
- Open for non-commercial academic and research use.
|
5
|
+
- Commercial use, redistribution, or integration into proprietary models requires written permission from the author.
|
6
|
+
- For inquiries, contact via the project page.
|
7
|
+
"""
|
8
|
+
|
9
|
+
from __future__ import annotations
|
10
|
+
|
11
|
+
import math
|
12
|
+
|
13
|
+
def phi_wavefunction(
|
14
|
+
phi: float, phi_vacuum: float = 0.0, lam: float = 1.0
|
15
|
+
) -> float:
|
16
|
+
"""Return ψ(φ) = exp((φ - φ_vacuum) / λ)."""
|
17
|
+
return math.exp((phi - phi_vacuum) / lam)
|
18
|
+
|
19
|
+
def phase_alignment_potential(
|
20
|
+
phi: float, phi_vacuum: float = 0.0, lam: float = 1.0
|
21
|
+
) -> float:
|
22
|
+
"""Return g(φ) = 2 * exp((φ - φ_vacuum) / λ)."""
|
23
|
+
return 2.0 * phi_wavefunction(phi, phi_vacuum, lam)
|
24
|
+
|
25
|
+
def corrected_energy(
|
26
|
+
n: int, phi: float, phi_vacuum: float = 0.0, lam: float = 1.0
|
27
|
+
) -> float:
|
28
|
+
"""Return E_n = -g(φ) / n²."""
|
29
|
+
g_val = phase_alignment_potential(phi, phi_vacuum, lam)
|
30
|
+
return -g_val / float(n * n)
|
31
|
+
|
32
|
+
def orbital_radius(
|
33
|
+
n: int, phi: float, phi_vacuum: float = 0.0, lam: float = 1.0
|
34
|
+
) -> float:
|
35
|
+
"""Return r_n ≈ n² / g(φ)."""
|
36
|
+
g_val = phase_alignment_potential(phi, phi_vacuum, lam)
|
37
|
+
return (n * n) / g_val
|
38
|
+
|
39
|
+
__all__ = [
|
40
|
+
"phi_wavefunction",
|
41
|
+
"phase_alignment_potential",
|
42
|
+
"corrected_energy",
|
43
|
+
"orbital_radius",
|
44
|
+
]
|