crosslang/OctiveLean/Core/Syntax.lean
Maximus Gorog 567d3d1902 Add Tiny Octave Core (TOC) parallel to golang-lean's TGC.
OctiveLean/Core/ — the kernel-level formal layer that octive-lean's
existing surface BigStep didn't have. Six files:

  Syntax.lean       — Term, BinOp. Twelve constructors: ten shared
                      with TGC plus assign (var mutation in env) and
                      whileT (loop). No refs (Octave has no &/*).
  Semantics.lean    — Value, EnvList, BigStep. Signature
                      `BigStep : Env -> Term -> Value -> Env -> Prop`
                      threading env (vs TGC's `Heap x Env`).
  Determinism.lean  — BigStep.deterministic. Same case shapes as TGC
                      for the shared ten constructors. The whileFR/whileTR
                      cross-case mirrors TGC's ifTR/ifFR via Bool.noConfusion.
  Eval.lean         — fuel-bounded eval + eval_sound. whileT recursion
                      consumes one fuel unit per iteration. Function
                      calls discard the body's post-env (Octave/MATLAB
                      local-scope semantics).
  Types.lean        — Ty (no ref), TyEnv, HasType. Twelve typing rules
                      mirroring the constructors.
  TypeSoundness.lean — HasTypeV inductive, function-form HasTypeEnv.
                      vClos uses two-part formulation (he_dom + he_typed)
                      instead of nested existential — Lean's kernel rejects
                      the natural ∃-form due to nested-inductive parameter
                      restrictions. extend_typed (assign preservation) and
                      extend_letIn (letIn preservation) lemmas.

Cross-language symmetry surfaced this iteration:
  * Determinism proof: ten cases mirror TGC line-for-line. Two new
    cases (assign, while) follow the same three structural shapes.
  * Eval signature: state type differs (Env vs Heap×Env), constructors'
    eval recurrences are otherwise isomorphic.
  * Type system: Ty diverges (no ref vs no whileT/assign), but the
    typing-rule shapes are identical — variables, let, app, if, binop, seq.
  * Typing of runtime data is where the languages most diverge:
    TGC's structural HasTypeEnv works because env is scoped; TOC needs
    function-form because env mutates. This is the *real* asymmetry that
    a cross-language layer would have to abstract over.

Preservation deferred — has a soundness gap with letIn-shadowing-then-
assign that needs a freshness premise on letIn typing. To follow.

Zero sorries / axioms / admits. Full lake build clean (73 jobs).
2026-05-10 04:26:12 -06:00

33 lines
1.2 KiB
Text

namespace OctiveLean.Core
/-! # Tiny Octave Core (TOC) — abstract syntax.
Parallel to golang-lean's TGC. Shared kernel: ten constructors covering
λ-calculus core + conditionals + sequencing. Octave-specific extensions:
`assign` (variable mutation in the env) and `whileT` (loop until false).
What is *not* here: matrices, cell arrays, ranges, anonymous-function
captures with `@(x) expr` syntax, `printf`-family builtins. Those are
desugaring targets for the surface-Octave→TOC translator (later). -/
inductive BinOp where
| add | sub | mul
| eq | lt
deriving Repr, BEq, DecidableEq, Inhabited
inductive Term where
| unitT : Term
| intLit : Int → Term
| boolLit : Bool → Term
| var : String → Term
| lam : String → Term → Term -- λ x. e
| app : Term → Term → Term
| letIn : String → Term → Term → Term -- let x = e₁ in e₂ (lexical)
| ifte : Term → Term → Term → Term
| binop : BinOp → Term → Term → Term
| seq : Term → Term → Term
| assign : String → Term → Term -- x = e (mutates env)
| whileT : Term → Term → Term -- while c do b
deriving Repr, Inhabited
end OctiveLean.Core