interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / docs / TEACH_OMEGA.md

196 lines · 11121 bytes Raw Blame History Rendered
1# One small Omega program: source, executable, and the identity boundary
2
3This lesson follows the existing seeded `.om` forward-call fixture. It also
4explains where the older semantic-identity machinery lives **without pretending
5that the two pipelines are integrated**. It is a bounded contribution to
6[#619](https://github.com/aien-dev/omega-mv/issues/619), not its closure.
7
8## What problem is being solved?
9
10The [2026-09-29 decision record](adr/OMEGA-SYSTEMS-CORE-0000.md)
11sets the goal: replace convention-dependent C/assembly with explicit machine
12semantics, reproducible compilation, and separate semantic, runtime, wire and
13device layouts. The later seed work makes compiler ancestry inspectable: explicit
14instruction words build small translators, then a compiler written in Omega.
15See the existing [seed-birth walkthrough](https://github.com/aien-dev/omega-mv/blob/b30ba6cf729eb9295c7f8883cfff0519b90a63e1/docs/SEED_BIRTH.md)
16and its [recorded replay](https://github.com/aien-dev/omega-mv/blob/b30ba6cf729eb9295c7f8883cfff0519b90a63e1/evidence/seed-birth-20261022/README.md).
17Those are development-branch documents, not files already integrated on `main`.
18
19Published Arm instruction and ELF formats are upstream specifications, not
20Omega inventions. The seed notes attribute them. Existing Linux, the shell and
21host utilities remain dependencies. [CONTRIBUTORS](../CONTRIBUTORS.md) attributes
22project implementation to AI models orchestrated by Drake Stapleton; this lesson
23does not invent a personal account of who typed the compiler.
24
25## Pin and prerequisites
26
27Use the teaching pin `29b12760f4c962606411d6bf25032aedef063301`, the R5
28compiler described by the existing replay above. This is **not the newest compiler,
29a production recommendation, or a combined profile**. Later native-host and
30device work has separate review and qualification, including
31[PR #678](https://github.com/aien-dev/omega-mv/pull/678) and
32[PR #676](https://github.com/aien-dev/omega-mv/pull/676).
33Do not substitute one profile's compiler hash or evidence for another's.
34
35Execution requires **AArch64 Linux**, Git, a POSIX shell, and ordinary utilities
36used by the bootstrap (`printf`, `tr`, `cat`, `sed`, GNU-compatible `stat`, `cmp`,
37`chmod`, `mkdir`, `cp`, `wc`, `cut`, `grep`, `sha256sum`). No model, GPU, CUDA
38installation, physics checkout, or package download is part of this example.
39Cloning needs network access; after checkout the recipe is offline. An x86 host
40can inspect source but cannot natively execute these AArch64 binaries.
41
42Use a disposable checkout: the bootstrap writes `build/seed/birth`, `seed/out`,
43and rung-4 generated files, including a measured-size field in `om4.s`.
44Inspect the [bootstrap](https://github.com/aien-dev/omega-mv/blob/29b12760f4c962606411d6bf25032aedef063301/seed/omega-from-seed.sh)
45and [rung-4 builder](https://github.com/aien-dev/omega-mv/blob/29b12760f4c962606411d6bf25032aedef063301/seed/rung4/mk4.sh)
46before executing them. Never run historical receipt-writing gates in a checkout
47whose evidence you intend to preserve.
48
49## Follow the source
50
51The unchanged input is
52[`seed/rung4/tests/r5b_fwd.om`](https://github.com/aien-dev/omega-mv/blob/29b12760f4c962606411d6bf25032aedef063301/seed/rung4/tests/r5b_fwd.om):
53
54```text
55fn main to int
56ret later
57end
58fn later to int
59ret 7
60end
61```
62
63`main` returns the result of `later`, even though its declaration follows the
64call. The expected observable result is **process exit 7**, not printed text.
65A nonzero program result is not automatically a compiler/test failure.
66
67In the pinned
68[`seed/omc/omc.om`](https://github.com/aien-dev/omega-mv/blob/29b12760f4c962606411d6bf25032aedef063301/seed/omc/omc.om),
69follow these function names:
70
71| Stage | Implementation and intermediate representation |
72| --- | --- |
73| Read source | `main` reads stdin into bounded `inp`; `tok` scans tokens. |
74| Discover/check names | `prescan` and `namescan` collect declarations; `stmt`, `s_name`, `s_assign` and expression readers enforce this subset's rules. This is not a claim of the full OSC contract system. |
75| Emit and resolve | Statement/expression handlers emit instruction words into `out`; `resolve` fills call offsets after addresses are known. |
76| Make the executable | `eof_prog` constructs the entry/exit sequence; `elfhdr` writes the ELF64 little-endian AArch64 header; `writeout` sends the image to stdout. |
77| Run | Linux loads that ELF; the generated entry calls `main` and passes its result to the Linux exit syscall. |
78
79There is no C compilation or linking step in this construction path. The
80bootstrap's fixed-point comparisons establish self-consistency of the tested
81compiler builds, not general semantic correctness or diverse-compilation trust.
82
83## Replay on a suitable CPU host
84
85These are **expected results derived from source and the linked historical
86replay**, not a claim that this lesson's author reran them. Execute each block
87in order in the same shell. Each block fails closed on an unexpected result.
88
89```sh
90set -eu
91git clone https://github.com/aien-dev/omega-mv.git omega-teaching-replay
92cd omega-teaching-replay
93git checkout --detach 29b12760f4c962606411d6bf25032aedef063301
94test "$(git rev-parse HEAD)" = 29b12760f4c962606411d6bf25032aedef063301
95sh seed/omega-from-seed.sh
96printf '%s %s\n' \
97 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 \
98 seed/out/omc | sha256sum -c -
99mkdir build/teaching
100seed/out/omc < seed/rung4/tests/r5b_fwd.om > build/teaching/fwd
101chmod +x build/teaching/fwd
102rc=0
103build/teaching/fwd > build/teaching/fwd.stdout || rc=$?
104test "$rc" -eq 7
105test ! -s build/teaching/fwd.stdout
106printf 'forward-call exit=%s\n' "$rc"
107```
108
109Expected: bootstrap exits 0 and prints `RC=0`; hash check prints
110`seed/out/omc: OK`; compilation exits 0; program exits 7 with no stdout;
111the last line is `forward-call exit=7` and the block exits 0.
112
113### A meaning-preserving change
114
115Rename the internal function consistently; keep the externally required `main`.
116This changes source bytes but not the intended call/result. Byte equality is a
117stronger, implementation-specific expectation for this exact rename, **not a
118universal test of semantic equivalence** and not a `SEMANTIC_ID` computation.
119
120```sh
121sed 's/later/after/g' seed/rung4/tests/r5b_fwd.om > build/teaching/renamed.om
122seed/out/omc < build/teaching/renamed.om > build/teaching/renamed
123cmp build/teaching/fwd build/teaching/renamed
124chmod +x build/teaching/renamed
125rc=0
126build/teaching/renamed > build/teaching/renamed.stdout || rc=$?
127test "$rc" -eq 7
128test ! -s build/teaching/renamed.stdout
129printf 'renamed exit=%s\n' "$rc"
130```
131
132Expected: compiler and `cmp` exit 0, program exit 7, no program stdout,
133`renamed exit=7`. The new rename experiment is **NOT_RUN** here; if comparison
134fails, preserve its output and report FAIL rather than changing expected bytes.
135
136### A safe refusal already in the bootstrap
137
138[`r5b_assign.om`](https://github.com/aien-dev/omega-mv/blob/29b12760f4c962606411d6bf25032aedef063301/seed/rung4/tests/r5b_assign.om)
139tries `later = 2` where `later` is a function. The names pass makes that an
140invalid assignment, rather than silently treating the function name as a variable.
141
142```sh
143rc=0
144seed/out/omc < seed/rung4/tests/r5b_assign.om \
145 > build/teaching/refused.bin 2> build/teaching/refused.stderr || rc=$?
146test "$rc" -eq 7
147grep -q 'error 7' build/teaching/refused.stderr
148printf 'invalid-assignment compiler-exit=%s\n' "$rc"
149```
150
151Expected: compiler exit 7, diagnostic containing `error 7`, final line
152`invalid-assignment compiler-exit=7`. **Do not execute refused.bin.** The
153bootstrap already asserts this exact exit and diagnostic. The program result 7
154above and compiler refusal 7 here are different events from different processes.
155
156## Where semantic identity and receipts fit: and do not yet fit
157
158The seeded fixture above does **not** travel through the legacy C
159`OmegaProgram` pipeline. No canonical semantic encoding, `SEMANTIC_ID`,
160`REALIZATION_ID`, or signed qualification receipt is emitted by this recipe.
161A SHA-256 of the executable is an artifact fingerprint, not semantic identity.
162For this lesson, the missing native integration is **MISSING_IMPLEMENTATION**,
163not an invitation to revive the legacy C path as the permanent foundation.
164
165The existing legacy implementation supplies a precise comparison and source map:
166
167| Concept | Existing source, format and test |
168| --- | --- |
169| Parse/check a restricted unary function | `omega_language_parse_line` and `omega_language_lower_program`, exercised by `lower_fn` in [test_program_id.c](../tests/program/test_program_id.c). This is a different source grammar from `.om`. |
170| Bind meaning, not spelling/cost | [program identity v2](../spec/program-identity.md): `omega_program_compute_id` hashes a domain tag, canonical body-root id, input/output type ids and pre/postcondition ids. [omega_program.c](../src/omega_program.c) and [omega_canonical.c](../src/omega_canonical.c) implement it. |
171| Inspect intermediate bytes | [canonical object encoding](../spec/canonical-encoding.md) and [program IR layout](../src/omega_program_ir.h); [IR tests](../tests/test_omega_program_ir.c) exercise round trips and refusals. These are distinct encodings, not the emitted ELF. |
172| Realize and compare | [program realization V0](../spec/program-realization.md) links `omega_program_realize_check`, scheduling, emission and `omega_realization_verify_program`; unsupported bodies and stale ids fail closed. Native comparison requires AArch64. |
173| Receipt binding | [omega_receipt.h](../src/omega_receipt.h) defines receipt canonicalization/identity; an execution log alone does not satisfy that schema or establish qualification. |
174
175For example, the identity test compares `fn f(x: u64) -> u64 { x + 1 }`
176with changed names/representation and separately with `x + 2`. Equality is
177about the supported canonical body and contract, **not every mathematically
178equivalent arbitrary program**. The documented v1 failure was omission of the
179body from the hash, allowing different programs to share an id; v2 fixes that.
180The realization design also records the earlier error of emitting `3x - 2`
181regardless of the requested program. These are attributed design records, not
182newly reproduced failures or claims that all compiler defects are solved.
183
184## Evidence and remaining work
185
186- Historical AArch64 bootstrap replay: linked above, exact R5 pin and compiler
187 fingerprint; not a fresh run of this whole lesson.
188- This documentation pass: source/path/snippet and shell-syntax inspection only.
189 Execution, the new rename comparison, and repository judges: **NOT_RUN**.
190- Full #619 acceptance still needs an independent fresh CPU replay with revision,
191 OS/architecture, commands, stdout/stderr and exit statuses, plus an honestly
192 scoped native identity/receipt story. Preserve failures and never rewrite old
193 receipts to make the example pass.
194- GB10/device/model qualification is outside this CPU lesson. It requires its own
195 exact compiler/profile, hardware, operator scheduling and evidence; a host pass
196 cannot establish it. No hardware extension is necessary to learn this example.