One Fixed Effective Numeric Interface for Native Programs
DefinitionMonodromy_NativeIODefines source-independent integer input labels and a total natural-number output readout. Inputs use a fixed finite tape alphabet and prime-three tape coding; outputs extract the bounded prime-three exponent of one memory label and decode its tape symbols. A finite entry prefix connects this interface to the native Turing compiler and yields complete numeric-graph correctness.
-- Generated by Lean-fact skeleton subtraction; original source is frozen in imports/monodromy/source.
module
public import Definitions.Def_Monodromy_CanonicalIO
public import Definitions.Def_Monodromy_Effectiveness
public import Lean.Elab.Tactic.Omega
public import Mathlib.Analysis.Analytic.Constructions
public import Mathlib.Analysis.Analytic.IsolatedZeros
public import Mathlib.Analysis.Analytic.Linear
public import Mathlib.Analysis.Calculus.DSlope
public import Mathlib.Analysis.Calculus.Deriv.Add
public import Mathlib.Analysis.Calculus.Deriv.Comp
public import Mathlib.Analysis.Calculus.Deriv.Mul
public import Mathlib.Analysis.Calculus.Deriv.Pow
public import Mathlib.Analysis.Complex.Basic
public import Mathlib.Analysis.Complex.CoveringMap
public import Mathlib.Analysis.Real.Pi.Bounds
public import Mathlib.Analysis.SpecialFunctions.Complex.Analytic
public import Mathlib.Analysis.SpecialFunctions.Complex.Circle
public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Sinc
public import Mathlib.Computability.PartrecCode
public import Mathlib.Computability.Primrec.Basic
public import Mathlib.Computability.Primrec.List
public import Mathlib.Computability.StateTransition
public import Mathlib.Computability.TuringMachine.PostTuringMachine
public import Mathlib.Computability.TuringMachine.ToPartrec
public import Mathlib.Data.Fin.Basic
public import Mathlib.Data.Fintype.Card
public import Mathlib.Data.Fintype.EquivFin
public import Mathlib.Data.Fintype.Sets
public import Mathlib.Data.Int.ModEq
public import Mathlib.Data.Nat.Digits.Lemmas
public import Mathlib.Data.Nat.Factorization.Basic
public import Mathlib.Logic.Equiv.Fin.Basic
public import Mathlib.Logic.Equiv.Fin.Rotate
public import Mathlib.Logic.Function.Basic
public import Mathlib.Logic.Function.Conjugate
public import Mathlib.RingTheory.RootsOfUnity.Complex
public import Mathlib.Tactic.FieldSimp
public import Mathlib.Tactic.FinCases
public import Mathlib.Tactic.FunProp
public import Mathlib.Tactic.Linarith
public import Mathlib.Tactic.Ring
public import Mathlib.Topology.Homotopy.Lifting
@[expose] public section
/-!
# A fixed numeric interface
One primitive-recursive preparation and readout serve every finite native
program. A static prefix supplies the initial head symbol to the compiled
Turing table. Complete results are obtained by actual covering-space lifts;
the numeric readout recovers the right tape from its prime-three exponent.
-/
@[expose] public section
noncomputable section
namespace Monodromy.NativeInterface
open Turing CoupledContinuation
abbrev Alphabet := CanonicalIO.Alphabet
abbrev letters : ℕ := Fintype.card Alphabet
def word (input : ℕ) : List (Fin letters) :=
(FormalCompilation.tapeData [input]).map (FiniteRenaming.toFin Alphabet)
def rightCode (input : ℕ) : ℕ := TapeCode.Readout.wordCode letters (word input).tail
/-- This preparation uses only the numeric argument and the fixed tape alphabet. -/
def inputLabels (input : ℕ) : Labels :=
((Int.ofNat (3 ^ rightCode input), 0), 3 * ((word input).headI.val : ℤ))
def read (letter : Fin letters) (value : ℕ) : ℕ :=
CanonicalIO.readSymbol value (FiniteRenaming.fromFin Alphabet letter)
/-- The total output map ignores every control address and the workspace counter. -/
def outputLabels (labels : Labels) : ℕ :=
TapeCode.Readout.decode read (PrimeReadout.exponent 3 labels.1.1.toNat)
variable (source : ToPartrec.Code)
abbrev FiniteControl : Type := (FormalCompilation.finiteSupport source).Control
abbrev controls : ℕ := Fintype.card (FiniteControl source)
def table : TM0.Machine (Fin letters) (Fin (controls source)) :=
FiniteRenaming.machine (FormalCompilation.finiteSupport source).restrict
abbrev bodySize : ℕ := Counter.Compression.size
(NativeTuring.source3 letters (controls source) (table source))
def body : Counter.Program 2 (bodySize source) :=
NativeTuring.source2 letters (controls source) (table source)
def entries (letter : Fin letters) : Fin (bodySize source) :=
Counter.Compression.dispatch
(NativeTuring.source3 letters (controls source) (table source))
(Counter.TuringCompiler.dispatch letters (controls source) (0, letter))
def counterProgram : Counter.Program 2 (letters + bodySize source) :=
Counter.EntryDispatch.program (body source) (entries source)
instance prefix_nonempty : NeZero (letters + bodySize source) := by
have positive : 0 < letters := Fintype.card_pos
exact ⟨by omega⟩
/-- The only added source rows are one static entry jump for each input-head letter. -/
def program : CoupledContinuation.Program ((letters + bodySize source) * 3) :=
CounterContinuation.compile (counterProgram source)
def initial (input : ℕ) : Counter.Configuration 2 (letters + bodySize source) :=
Counter.EntryDispatch.entryState (word input).headI ![3 ^ rightCode input, 0]
/-- Integer labels describe the native encoding of an ordinary two-counter state. -/
def counterLabels {m : ℕ} (state : Counter.Configuration 2 m) : Labels :=
(((state.counters 0 : ℤ), (state.counters 1 : ℤ)), CounterContinuation.label state.pc 0)
def resultLabels (state : TM0.Cfg (Fin letters) (Fin (controls source))) : Labels :=
counterLabels (Counter.mapConfiguration (Fin.natAdd letters)
(Counter.Compression.encode
(NativeTuring.source3 letters (controls source) (table source))
(Counter.TuringCompiler.encode letters (controls source) state)))
def rawOutput (state : TM0.Cfg Alphabet (FormalCompilation.Control0 source)) : ℕ :=
CanonicalIO.decodeTape state.Tape.right
end Monodromy.NativeInterface
Read-back
What the Lean code literally says, in plain math · OpenAI Codex (independent agent)
Write . The memory space consists of triples with and ; the integer-labelled point is with principal complex logarithms. The fixed numeric interface uses the four symbols and four tracks main, reverse, auxiliary and stack; its alphabet is a Boolean marker paired with an optional symbol on each track, blank meaning false marker and all tracks empty. To encode a list of naturals, encode each number in binary least-significant-bit first (zero as an empty bit list), append after each number, reverse the resulting symbol list, put its symbols on the main track alone, and set the first letter's marker true (an empty list gives one marked blank). Choose the specified finite alphabet bijection to taking blank to , where is its cardinality, and let be this numeric word for the singleton list . Put and , using a default-zero head for an empty word. To read an alphabet letter from an accumulator , use for main-track , for main-track , and otherwise, ignoring the marker and other tracks. For any integer label triple , let and be the greatest with (so if ). The output starts with and performs exactly iterations of taking the first component modulo , dividing that component by , and applying the corresponding letter-read operation to the accumulator; the unused residue is interpreted as blank , and the final accumulator is the output. Thus this total readout ignores the right and control labels, and negative left labels give output . This bundle fixes that alphabet, its cardinality , the word , its tail code, preparation labels, finite-letter reader, and output labels as total maps independent of a source program. For each code in the specified list-function partial-recursive language, its compiled Post-Turing machine has a finite closed control support; restrict to that subtype and rename alphabet and controls by finite bijections taking defaults to , obtaining a table with letters and controls. Let be its three-counter Turing compilation and its ordinary two-counter prime compression, with body size . For each input-head letter , the entry address is the ordinary-compression dispatch of the three-counter (initial-control ,head ) dispatch. The counterProgram prepends rows to , one at each letter address, and each such row tests the second counter and, if it is nonzero, decrements it by one, while sending either branch to that body's shifted entry address; body addresses are shifted by . A nonzero-size instance is supplied for . The native program is the three-phase counter-to-native compilation, of degree , and the initial ordinary two-counter configuration is the prefix row with values . For any natural and any ordinary two-counter configuration with address and values , counterLabels is with integer casts, including all natural counter values; if there is no such configuration. resultLabels of a configuration of the renamed finite Post-Turing machine applies its three-counter encoding, then its ordinary two-counter encoding, shifts its address by , and applies counterLabels. The three-counter tape codes use base , and the ordinary compression encodes them using primes with workspace zero. rawOutput of a configuration of the unrestricted compiled machine applies the canonical main-track bit-reading fold to its right half-tape modulo trailing blanks. These interfaces include every natural input, every integer label triple for total output, and arbitrary configurations of the specified machine types; their definitions do not themselves assert that resultLabels are reached by execution.
Confirmed by the mission captain (proposal self-audit).