File size: 2,414 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
#!/usr/bin/env python
"""
LOGOS MTL Turing Completeness Validation Script

Run: python logos/tools/validate_mtl.py
"""
import os
import sys

# Ensure we can import from logos
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

def main():
    print('=' * 60)
    print('    LOGOS MTL TURING COMPLETENESS VALIDATION')
    print('=' * 60)

    from logos.mtl.interpreter import MTLInterpreter
    
    genesis_path = os.path.join(os.path.dirname(__file__), '..', 'mtl', 'genesis.json')
    mtl = MTLInterpreter(genesis_path)

    tests = [
        ('Mult [2]*[3]', '(mult [2] [3])', 6),
        ('Fractran Adder (72 -> 3125)', '(fractran [[5 2] [5 3]] 72)', 3125),
        ('If True (10 % 2 == 0)', '(if (divisible? 10 2) 1 0)', 1),
        ('If False (10 % 3 != 0)', '(if (divisible? 10 3) 1 0)', 0),
        ('Sub (10 - 3)', '(sub 10 3)', 7),
        ('Add (10 + 3)', '(add 10 3)', 13),
        ('Genesis Lookup', '(mult [MECHANISM] [RESULT])', 6),
    ]

    print('\n[1] CORE MTL TESTS')
    passed = 0
    for name, expr, expected in tests:
        try:
            result = mtl.execute(expr)
            status = 'βœ…' if result == expected else '❌'
            if result == expected: passed += 1
            print(f'    {status} {name}: => {result} (expected {expected})')
        except Exception as e:
            print(f'    ❌ {name}: ERROR - {e}')

    print('\n[2] DEFUN/RECURSION TEST')
    try:
        mtl.execute('(defun triple (x) (mult x 3))')
        result = mtl.execute('(triple 7)')
        expected = 21
        status = 'βœ…' if result == expected else '❌'
        if result == expected: passed += 1
        print(f'    {status} (triple 7) => {result} (expected {expected})')
    except Exception as e:
        print(f'    ❌ Defun Test: ERROR - {e}')

    print('\n[3] COND TEST')
    try:
        result = mtl.execute('(cond ((eq? 1 2) 100) ((eq? 2 2) 200) (1 300))')
        expected = 200
        status = 'βœ…' if result == expected else '❌'
        if result == expected: passed += 1
        print(f'    {status} cond => {result} (expected {expected})')
    except Exception as e:
        print(f'    ❌ Cond Test: ERROR - {e}')

    total = len(tests) + 2  # +2 for defun and cond
    print(f'\n[SUMMARY] {passed}/{total} tests passed')
    print('=' * 60)

    return 0 if passed == total else 1

if __name__ == '__main__':
    sys.exit(main())