|
| 1 | +# The OMC-unique surface: things an LLM would reach for OMC for that |
| 2 | +# Python/NumPy/JAX simply can't do. |
| 3 | +# |
| 4 | +# Each section starts with a one-line "why this is OMC-only" so an LLM |
| 5 | +# reading the output understands the differentiator. |
| 6 | + |
| 7 | +fn show(label, v) { |
| 8 | + print(concat_many(label, " = ", to_string(v))); |
| 9 | +} |
| 10 | + |
| 11 | +fn main() { |
| 12 | + print("=== OMC unique-primitive showcase ==="); |
| 13 | + print("Run via: omc examples/demos/llm_showcase.omc"); |
| 14 | + print(""); |
| 15 | + |
| 16 | + # ---------------------------------------------------------------- |
| 17 | + # 1. Substrate metadata on every integer. |
| 18 | + # Python's i64 is a raw value. OMC's HInt carries φ-resonance |
| 19 | + # and HIM scores reflecting Fibonacci-attractor alignment. |
| 20 | + # ---------------------------------------------------------------- |
| 21 | + print("[1] Substrate metadata on integers (no NumPy equivalent)"); |
| 22 | + show(" is_attractor(8) ", is_attractor(8)); # 1 (Fib) |
| 23 | + show(" is_attractor(7) ", is_attractor(7)); # 0 |
| 24 | + show(" attractor_distance(7) ", attractor_distance(7)); # 1 |
| 25 | + show(" res(8) ", res(8)); # 1.0 |
| 26 | + show(" res(7) ", res(7)); # < 1.0 |
| 27 | + print(""); |
| 28 | + |
| 29 | + # ---------------------------------------------------------------- |
| 30 | + # 2. Substrate-typed array library. Resonance/HIM survive every op. |
| 31 | + # ---------------------------------------------------------------- |
| 32 | + print("[2] Substrate-typed array ops"); |
| 33 | + h fib = [0, 1, 2, 3, 5, 8, 13, 21]; |
| 34 | + show(" arr_resonance_vec(fib) ", arr_resonance_vec(fib)); |
| 35 | + show(" arr_fold_all([7,100,9,22])", arr_fold_all([7, 100, 9, 22])); |
| 36 | + print(""); |
| 37 | + |
| 38 | + # ---------------------------------------------------------------- |
| 39 | + # 3. Matrix multiplication preserves substrate metadata. |
| 40 | + # Every output cell of an int matmul carries its own resonance. |
| 41 | + # ---------------------------------------------------------------- |
| 42 | + print("[3] Substrate-preserving matmul"); |
| 43 | + h A = [[1, 2], [3, 5]]; # Fibonacci-shaped |
| 44 | + h B = [[2, 3], [5, 8]]; |
| 45 | + h C = arr_matmul(A, B); # 2x2 result, each cell HInt |
| 46 | + show(" A @ B[0] ", arr_get(C, 0)); |
| 47 | + show(" A @ B[1] ", arr_get(C, 1)); |
| 48 | + print(""); |
| 49 | + |
| 50 | + # ---------------------------------------------------------------- |
| 51 | + # 4. Substrate-distance attention. The attention KERNEL itself |
| 52 | + # uses Fibonacci-distance scoring instead of dot products. |
| 53 | + # ---------------------------------------------------------------- |
| 54 | + print("[4] Substrate-distance attention"); |
| 55 | + h Q = [[1, 2]]; # single query |
| 56 | + h K = [[1, 2], [100, 200]]; # close key + far key |
| 57 | + h V = [[5.0, 5.0], [99.0, 99.0]]; # close V + far V |
| 58 | + h out = arr_substrate_attention(Q, K, V); |
| 59 | + show(" attention(Q,K,V)[0] ", arr_get(out, 0)); |
| 60 | + print(" → strongly weighted toward V[0] because Q matches K[0] in substrate-space"); |
| 61 | + print(""); |
| 62 | + |
| 63 | + # ---------------------------------------------------------------- |
| 64 | + # 5. Reverse-mode autograd that preserves substrate metadata on |
| 65 | + # forward values. Python autograd hands you plain f64. |
| 66 | + # ---------------------------------------------------------------- |
| 67 | + print("[5] Autograd that keeps substrate metadata on forward path"); |
| 68 | + tape_reset(); |
| 69 | + h x = tape_var(3); |
| 70 | + h y = tape_var(5); |
| 71 | + h s = tape_add(x, y); # 8 — Fibonacci attractor |
| 72 | + h sq = tape_mul(s, s); # 64 — close to 55 attractor |
| 73 | + tape_backward(sq); |
| 74 | + show(" forward value at s ", tape_value(s)); # substrate-annotated 8 |
| 75 | + show(" forward value at sq ", tape_value(sq)); |
| 76 | + show(" d(sq)/dx ", tape_grad(x)); # 2*8 = 16 |
| 77 | + show(" d(sq)/dy ", tape_grad(y)); # 2*8 = 16 |
| 78 | + print(""); |
| 79 | + |
| 80 | + # ---------------------------------------------------------------- |
| 81 | + # 6. Lazy substrate Fibonacci generator — streams forever in O(1) |
| 82 | + # memory. Each yielded value already carries resonance=1.0. |
| 83 | + # ---------------------------------------------------------------- |
| 84 | + print("[6] Lazy substrate Fibonacci stream (O(1) memory)"); |
| 85 | + h collected = []; |
| 86 | + gen_substrate_fib( |
| 87 | + fn(v) { |
| 88 | + arr_push(collected, v); |
| 89 | + return 1; |
| 90 | + }, |
| 91 | + 100 |
| 92 | + ); |
| 93 | + show(" Fibs <= 100 ", collected); |
| 94 | + print(""); |
| 95 | + |
| 96 | + # ---------------------------------------------------------------- |
| 97 | + # 7. The introspection layer itself. LLMs read this at runtime. |
| 98 | + # ---------------------------------------------------------------- |
| 99 | + print("[7] Self-describing runtime"); |
| 100 | + show(" builtin count ", arr_len(omc_list_builtins())); |
| 101 | + show(" category count ", arr_len(omc_categories())); |
| 102 | + show(" OMC-unique builtin count ", arr_len(omc_unique_builtins())); |
| 103 | + show(" curated error pattern count", omc_error_count()); |
| 104 | + print(""); |
| 105 | + print(" An LLM can call omc_help(\"<name>\") for any of these."); |
| 106 | + print(" Errors come with did_you_mean suggestions + omc_explain_error."); |
| 107 | + |
| 108 | + print(""); |
| 109 | + print("=== These are the primitives Python/NumPy cannot replicate. ==="); |
| 110 | +} |
| 111 | + |
| 112 | +main(); |
0 commit comments