Spaces:
Runtime error
Runtime error
File size: 5,790 Bytes
6d3aa82 |
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 |
#!/usr/bin/env python
"""
SYNAPTIC BRIDGE TEST (Protocol 39 - Genesis of [13])
The Math of Connection:
- Synapse = Atom_A Γ Atom_B Γ 13 (RELATE factor)
- Traceability: If synapse % atom == 0, atom is connected
- Dissolution: synapse / 13 = raw pair
This proves LOGOS can build a Knowledge Graph where:
- Links are mathematical properties (not external strings)
- The "Link" contains the "Target"
- You cannot break a link without changing the number
"""
from logos.mtl.interpreter import MTLInterpreter
mtl = MTLInterpreter()
print('=' * 60)
print(' SYNAPTIC BRIDGE TEST (Genesis of [13] - RELATE)')
print('=' * 60)
# ============================================
# PHASE 1: CREATE THE SYNAPSE
# ============================================
print('\n[PHASE 1] Creating Synaptic Link')
print('-' * 40)
image_atom = 17 # IMAGE
text_atom = 19 # TEXT
rel_prime = 13 # RELATE
print(f' Image Atom: [{image_atom}]')
print(f' Text Atom: [{text_atom}]')
print(f' Relate Factor: [{rel_prime}]')
# Create the synapse using MTL
synapse_id = mtl.execute(f'(relate [{image_atom}] [{text_atom}])')
print(f'\n Synapse ID: {image_atom} Γ {text_atom} Γ {rel_prime} = [{synapse_id}]')
expected = image_atom * text_atom * rel_prime
assert synapse_id == expected, f'Expected {expected}, got {synapse_id}'
print(f' β
Synapse Created: [{synapse_id}]')
# Store in Relationship Domain [1300]
mtl.execute('(domain [1300])')
mtl.execute(f'(store caption_link {synapse_id})')
print(f' π Stored in RELATIONSHIP Domain [1300]')
# ============================================
# PHASE 2: TRACEABILITY (Reverse Lookup)
# ============================================
print('\n[PHASE 2] Traceability Check')
print('-' * 40)
# Retrieve the synapse
retrieved = mtl.execute('(fetch caption_link)')
print(f' Retrieved Synapse: [{retrieved}]')
# Trace back to Image
trace_img = mtl.execute(f'(trace {retrieved} [{image_atom}])')
if trace_img == image_atom:
print(f' β
Synapse contains IMAGE [{image_atom}]')
else:
print(f' β IMAGE traceability failed')
# Trace back to Text
trace_txt = mtl.execute(f'(trace {retrieved} [{text_atom}])')
if trace_txt == text_atom:
print(f' β
Synapse contains TEXT [{text_atom}]')
else:
print(f' β TEXT traceability failed')
# Trace RELATE factor
trace_rel = mtl.execute(f'(trace {retrieved} [{rel_prime}])')
if trace_rel == rel_prime:
print(f' β
Synapse contains RELATE [{rel_prime}]')
else:
print(f' β RELATE traceability failed')
# ============================================
# PHASE 3: LINK DISSOLUTION
# ============================================
print('\n[PHASE 3] Link Dissolution')
print('-' * 40)
# Dissolve the link (remove [13])
raw_pair = mtl.execute(f'(dissolve-link {retrieved})')
expected_pair = image_atom * text_atom # 17 * 19 = 323
print(f' Dissolved Link: [{retrieved}] / 13 = [{raw_pair}]')
print(f' Expected: 17 Γ 19 = [{expected_pair}]')
assert raw_pair == expected_pair, f'Expected {expected_pair}, got {raw_pair}'
print(f' β
Dissolution Verified: Raw pair is [{raw_pair}] (IMAGE Γ TEXT)')
# ============================================
# PHASE 4: GET LINKED ATOM
# ============================================
print('\n[PHASE 4] Reverse Navigation (Get Linked)')
print('-' * 40)
# Given the synapse and the image, find the text
found_text = mtl.execute(f'(get-linked {retrieved} [{image_atom}])')
print(f' Query: "What is linked to IMAGE [{image_atom}]?"')
print(f' Result: [{found_text}]')
assert found_text == text_atom, f'Expected {text_atom}, got {found_text}'
print(f' β
Found TEXT [{found_text}]')
# Given the synapse and the text, find the image
found_image = mtl.execute(f'(get-linked {retrieved} [{text_atom}])')
print(f' Query: "What is linked to TEXT [{text_atom}]?"')
print(f' Result: [{found_image}]')
assert found_image == image_atom, f'Expected {image_atom}, got {found_image}'
print(f' β
Found IMAGE [{found_image}]')
# ============================================
# PHASE 5: COMPLEX SYNAPSE CHAIN
# ============================================
print('\n[PHASE 5] Multi-Node Relationship Graph')
print('-' * 40)
# Create a chain: Image -> Text -> Audio
audio_atom = 23
synapse_text_audio = mtl.execute(f'(relate [{text_atom}] [{audio_atom}])')
mtl.execute(f'(store text_audio_link {synapse_text_audio})')
print(f' Created: TEXT [{text_atom}] <-> AUDIO [{audio_atom}] = [{synapse_text_audio}]')
# Now we have a graph:
# Image <--> Text <--> Audio
# Can we traverse it?
# From Image, find Text
linked_to_img = mtl.execute(f'(get-linked {synapse_id} [{image_atom}])')
print(f' From IMAGE, found: TEXT [{linked_to_img}]')
# From Text, find Audio
linked_to_txt = mtl.execute(f'(get-linked {synapse_text_audio} [{text_atom}])')
print(f' From TEXT, found: AUDIO [{linked_to_txt}]')
print(f' β
Graph traversal: IMAGE -> TEXT -> AUDIO')
# ============================================
# SUMMARY
# ============================================
print('\n' + '=' * 60)
print('β
SYNAPTIC BRIDGE VERIFIED')
print('=' * 60)
print('''
The Knowledge Graph Properties:
| Operation | MTL Command | Result |
|----------------|--------------------------|------------------|
| Create Link | (relate A B) | A Γ B Γ 13 |
| Trace | (trace synapse atom) | atom if present |
| Dissolve | (dissolve-link synapse) | synapse / 13 |
| Navigate | (get-linked synapse A) | B (the other end)|
Key Insight:
- Links ARE the numbers (not external metadata)
- Traceability is O(1) via modulo check
- Graph traversal is arithmetic division
''')
# Show domain state
print('RELATIONSHIP Domain [1300]:')
print(f' {mtl.domains.get(1300, {})}')
|