-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
76 lines (57 loc) · 2.57 KB
/
engine.py
File metadata and controls
76 lines (57 loc) · 2.57 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
"""
VectorOracle Engine — Ternary Vector Computation
Takes birth date (year/month/day/hour) + anchor number + quarter salt
→ produces a 6D ternary vector (-1, 0, 1)
→ triggers LLM rendering to natural-language architecture diagnosis.
Structure: lower 3 positions = birth (inner trigram, 地盘)
upper 3 positions = anchor + time (outer trigram, 天盘+人盘)
combined = full hexagram
"""
import hashlib
from datetime import datetime
from typing import List, Tuple
def _hash_to_ternary(seed: str, n: int = 3) -> List[int]:
"""Hash a seed string into N ternary values (-1, 0, 1)."""
digest = hashlib.sha256(seed.encode()).digest()
vals = []
for i in range(n):
byte_val = digest[i] ^ digest[i + n] # XOR for spread
mod_val = byte_val % 3
vals.append(mod_val - 1) # 0→-1, 1→0, 2→1
return vals
def quarter_salt() -> str:
"""Return a salt based on current year + quarter."""
now = datetime.utcnow()
return f"{now.year}-Q{(now.month - 1) // 3 + 1}"
def birth_vector(year: int, month: int, day: int, hour: int) -> List[int]:
"""Compute inner trigram (地盘) from birth date."""
seed = f"{year:04d}:{month:02d}:{day:02d}:{hour:02d}"
return _hash_to_ternary(seed, n=3)
def observation_vector(anchor: int) -> List[int]:
"""Compute outer trigram (天盘+人盘) from anchor number + time salt."""
seed = f"{anchor}:{quarter_salt()}"
return _hash_to_ternary(seed, n=3)
def compute_hexagram(year: int, month: int, day: int, hour: int, anchor: int) -> List[int]:
"""Full 6D ternary vector (hexagram). Lower=birth, upper=observation."""
inner = birth_vector(year, month, day, hour)
outer = observation_vector(anchor)
return inner + outer
def ternary_display(vec: List[int]) -> str:
"""Convert ternary vector to display symbols: ● ○ —"""
symbols = {1: "●", 0: "○", -1: "—"}
return " ".join(symbols[v] for v in vec)
def moving_positions(vec: List[int]) -> List[int]:
"""Return 1-indexed positions where value is 0 (stress points / 动爻)."""
return [i + 1 for i, v in enumerate(vec) if v == 0]
def vector_label(pos: int, val: int) -> str:
"""Label a single position with layer name and state."""
layers = {
1: "Foundation/Core",
2: "Relations/Coupling",
3: "Resources/Energy",
4: "Structure/Stability",
5: "Expression/Output",
6: "Interface/External",
}
states = {1: "stable (●)", 0: "superposition/stress (○)", -1: "contracting (—)"}
return f"Layer {pos} ({layers[pos]}): {states[val]}"