From: Thomas Walker Lynch
Date: Fri, 13 Feb 2026 13:54:17 +0000 (+0000)
Subject: voici TMS
X-Git-Url: https://git.reasoningtechnology.com/sitemap.xml?a=commitdiff_plain;h=e8b95e2c24fac2bd480b6866a39c3ecc9ad317e0;p=Epimetheus%2F.git
voici TMS
---
diff --git a/developer/authored/Symbol.py b/developer/authored/Symbol.py
index e893c6f..75edb0f 100755
--- a/developer/authored/Symbol.py
+++ b/developer/authored/Symbol.py
@@ -5,205 +5,275 @@ from __future__ import annotations
import threading
import weakref
+from enum import Enum, auto
from typing import Optional, Sequence, Tuple
-class SymbolSpace:
- """
- A SymbolSpace provides:
- - A Null symbol (identity 0).
- - A ContextMap from symbol context keys to Factories.
- - Factories that issue symbols and reclaim identities on GC.
- """
+class Symbol:
+ __slots__ = (
+ "_identity"
+ ,"_factory_ref"
+ ,"_finalizer"
+ ,"_factory_id"
+ ,"__weakref__"
+ )
- class Symbol:
- __slots__ = (
- "_identity"
- ,"_factory_ref"
- ,"_finalizer"
- ,"_factory_id"
- ,"__weakref__"
- )
-
- def __init__(self ,identity: int ,factory: Optional["SymbolSpace.Factory"]):
- self._identity = int(identity)
-
- if(self._identity == 0):
- self._factory_ref = None
- self._finalizer = None
- self._factory_id = 0
- return
+ def __init__(self ,identity: int ,factory: Optional["FactoryS"]):
+ self._identity = int(identity)
- if(factory is None):
- raise ValueError("Non-null symbols require a factory.")
+ if(factory is None):
+ self._factory_id = 0
+ self._factory_ref = None
+ self._finalizer = None
+ return
- self._factory_id = factory.factory_id
- self._factory_ref = weakref.ref(factory)
+ self._factory_id = factory.factory_id
+ self._factory_ref = weakref.ref(factory)
- identity_copy = self._identity
- factory_ref = self._factory_ref
+ # Capture state for finalizer to avoid keeping strong ref to self
+ identity_copy = self._identity
+ factory_ref = self._factory_ref
+
+ def _finalize():
+ f = factory_ref()
+ if(f is None):
+ return
+ try:
+ f._reclaim_identity(identity_copy)
+ except Exception:
+ # Finalizers must never raise.
+ return
- def _finalize():
- f = factory_ref()
- if(f is None):
- return
- try:
- f._reclaim_identity(identity_copy)
- except Exception:
- # Finalizers must never raise.
- return
+ self._finalizer = weakref.finalize(self ,_finalize)
- self._finalizer = weakref.finalize(self ,_finalize)
+ @property
+ def identity(self) -> int:
+ return self._identity
- @property
- def identity(self) -> int:
- return self._identity
+ @property
+ def factory(self) -> Optional["FactoryS"]:
+ if(self._factory_ref is None):
+ return None
+ return self._factory_ref()
- def __repr__(self) -> str:
- if(self._identity == 0):
- return "Symbol(0)"
- return f"Symbol({self._identity} ,factory_id={self._factory_id})"
+ def __repr__(self) -> str:
+ return f"Symbol({self._identity} ,factory_id={self._factory_id})"
- def __hash__(self) -> int:
- return hash( (self._factory_id ,self._identity) )
+ def __hash__(self) -> int:
+ return hash( (self._factory_id ,self._identity) )
- def __eq__(self ,other: object) -> bool:
- if( not isinstance(other ,SymbolSpace.Symbol) ):
+ def __eq__(self ,other: object) -> bool:
+ if( not isinstance(other ,Symbol) ):
+ return False
+ return (self._factory_id == other._factory_id) and (self._identity == other._identity)
+
+
+class Factory:
+ """
+ Base First-Order Factory.
+ - created with a known context.
+ - strictly increases counter.
+ - manages free set.
+ """
+ __slots__ = (
+ "_lock"
+ ,"_counter"
+ ,"_free_set"
+ ,"_space"
+ ,"_context_key"
+ ,"factory_id"
+ )
+
+ def __init__(self ,space: "SymbolSpace" ,context_key: Tuple["Symbol" ,...] ,factory_id: int):
+ self._lock = threading.RLock()
+ self._counter = 0
+ self._free_set = set()
+ self._space = space
+ self._context_key = context_key
+ self.factory_id = int(factory_id)
+
+ def make(self ,wrapper: "FactoryS") -> "Symbol":
+ with self._lock:
+ if(self._free_set):
+ identity = min(self._free_set)
+ self._free_set.remove(identity)
+ return Symbol(identity ,wrapper)
+
+ identity = self._counter
+ self._counter += 1
+ return Symbol(identity ,wrapper)
+
+ def has(self ,symbol: "Symbol") -> bool:
+ # FactoryS handles the ID check; we handle logic.
+ with self._lock:
+ if(symbol.identity >= self._counter):
+ return False
+ if(symbol.identity in self._free_set):
return False
- return (self._factory_id == other._factory_id) and (self._identity == other._identity)
-
- class Factory:
- """
- Issues identities from a monotonically increasing counter and a free set.
-
- Reclaim policy (from the spec):
- - When a reclaimed identity equals counter, decrement counter.
- Continue decrementing while counter is in the free set.
- - Otherwise, add the identity to the free set.
- """
-
- __slots__ = (
- "_lock"
- ,"_counter"
- ,"_free_set"
- ,"_space"
- ,"_context_key"
- ,"factory_id"
- ,"__weakref__"
- )
-
- def __init__(self ,space: "SymbolSpace" ,context_key: Tuple["SymbolSpace.Symbol" ,...] ,factory_id: int):
- self._lock = threading.RLock()
- self._counter = 0 # 0 is reserved for space.null
- self._free_set = set() # Set[int]
- self._space = space
- self._context_key = context_key
- self.factory_id = int(factory_id)
-
- @property
- def counter(self) -> int:
- with self._lock:
- return self._counter
-
- @property
- def free_set_size(self) -> int:
- with self._lock:
- return len(self._free_set)
-
- def make(self) -> "SymbolSpace.Symbol":
- with self._lock:
- if(self._free_set):
- identity = min(self._free_set)
- self._free_set.remove(identity)
- return self._space.Symbol(identity ,self)
-
- self._counter += 1
- return self._space.Symbol(self._counter ,self)
-
- def _reclaim_identity(self ,identity: int) -> None:
- identity = int(identity)
- if(identity == 0):
- raise ValueError("Attempted to reclaim the null symbol identity 0.")
-
- with self._lock:
- if(identity > self._counter):
- raise ValueError(f"Attempted to reclaim identity {identity} above counter {self._counter}.")
-
- if(identity in self._free_set):
- raise ValueError(f"Identity {identity} already reclaimed.")
-
- if(identity == self._counter):
+ return True
+
+ def reclaim(self ,identity: int) -> None:
+ with self._lock:
+ if(identity >= self._counter):
+ raise ValueError(f"Identity {identity} not issued (counter {self._counter}).")
+
+ if(identity in self._free_set):
+ raise ValueError(f"Identity {identity} already reclaimed.")
+
+ if(identity == self._counter - 1):
+ self._counter -= 1
+ while( (self._counter > 0) and ((self._counter - 1) in self._free_set) ):
self._counter -= 1
- while(self._counter in self._free_set):
- self._free_set.remove(self._counter)
- self._counter -= 1
- return
-
- self._free_set.add(identity)
-
- class ContextMap:
- """
- Map: context_key -> Factory
- A context_key is an ordered list of symbols, represented as a tuple.
- """
-
- __slots__ = (
- "_space"
- ,"_lock"
- ,"_factory_map"
- ,"_factory_id_counter"
- )
-
- def __init__(self ,space: "SymbolSpace"):
- self._space = space
- self._lock = threading.RLock()
- self._factory_map = {} # Dict[Tuple[Symbol] ,Factory]
- self._factory_id_counter = 0
-
- def _normalize(self ,context_key: Optional[Sequence["SymbolSpace.Symbol"]]) -> Tuple["SymbolSpace.Symbol" ,...]:
- if(context_key is None):
- return tuple()
- if( isinstance(context_key ,tuple) ):
- ctx = context_key
- else:
- ctx = tuple(context_key)
-
- for s in ctx:
- if( not isinstance(s ,SymbolSpace.Symbol) ):
- raise TypeError("context_key entries must be SymbolSpace.Symbol values.")
-
- return ctx
-
- def read(self ,context_key: Optional[Sequence["SymbolSpace.Symbol"]] = None) -> Optional["SymbolSpace.Factory"]:
- ctx = self._normalize(context_key)
- with self._lock:
- return self._factory_map.get(ctx)
-
- def make(self ,context_key: Optional[Sequence["SymbolSpace.Symbol"]] = None) -> "SymbolSpace.Factory":
- ctx = self._normalize(context_key)
- with self._lock:
- if(ctx in self._factory_map):
- raise KeyError("Factory already exists for this context_key.")
-
- self._factory_id_counter += 1
- f = SymbolSpace.Factory(self._space ,ctx ,self._factory_id_counter)
- self._factory_map[ctx] = f
- return f
-
- def delete(self ,context_key: Optional[Sequence["SymbolSpace.Symbol"]] = None) -> None:
- ctx = self._normalize(context_key)
- with self._lock:
- if(ctx not in self._factory_map):
- raise KeyError("No factory exists for this context_key.")
- del self._factory_map[ctx]
-
- def __len__(self) -> int:
- with self._lock:
- return len(self._factory_map)
+ self._free_set.remove(self._counter)
+ return
+
+ self._free_set.add(identity)
+
+
+class FactoryS:
+ """
+ Factory with Status (Second Order).
+ Wraps the base Factory using VTable swapping.
+ """
+ __slots__ = (
+ "_space"
+ ,"_context_key"
+ ,"_factory_id"
+ ,"_base"
+ # VTable slots
+ ,"make"
+ ,"has"
+ ,"_reclaim_identity"
+ )
+
+ def __init__(self ,space: "SymbolSpace" ,context_key: Tuple["Symbol" ,...] ,factory_id: int):
+ self._space = space
+ self._context_key = context_key
+ self._factory_id = factory_id
+ self._base = None
+
+ # Initialize in Empty state
+ self._change_state_empty()
+
+ @property
+ def factory_id(self) -> int:
+ return self._factory_id
+
+ # --- State Transitions ---
+
+ def _change_state_empty(self):
+ self.make = self._make_empty
+ self.has = self._has_empty
+ self._reclaim_identity = self._reclaim_empty
+
+ def _change_state_active(self ,base_factory: "Factory"):
+ self._base = base_factory
+ # Hot-swap to active methods
+ self.make = self._make_active
+ self.has = self._has_active
+ self._reclaim_identity = self._reclaim_active
+
+ # --- Empty State Methods ---
+
+ def _make_empty(self) -> "Symbol":
+ # JIT creation of the base factory
+ base = Factory(self._space ,self._context_key ,self._factory_id)
+
+ # Transition to Active
+ self._change_state_active(base)
+
+ # Delegate to the new base (which will issue identity 0)
+ return base.make(self)
+
+ def _has_empty(self ,symbol: "Symbol") -> bool:
+ return False
+
+ def _reclaim_empty(self ,identity: int) -> None:
+ # Should not happen if logic is correct, as no symbols exist to be reclaimed.
+ raise RuntimeError("Attempted to reclaim symbol from an Empty FactoryS.")
+
+ # --- Active State Methods ---
+
+ def _make_active(self) -> "Symbol":
+ # Direct delegation
+ return self._base.make(self)
+
+ def _has_active(self ,symbol: "Symbol") -> bool:
+ if(symbol._factory_id != self._factory_id):
+ return False
+ return self._base.has(symbol)
+
+ def _reclaim_active(self ,identity: int) -> None:
+ self._base.reclaim(identity)
+
+
+class ContextMap:
+ """
+ Map: context_key -> FactoryS
+ """
+ __slots__ = (
+ "_space"
+ ,"_lock"
+ ,"_factory_map"
+ ,"_factory_id_counter"
+ )
+
+ def __init__(self ,space: "SymbolSpace"):
+ self._space = space
+ self._lock = threading.RLock()
+ self._factory_map = {}
+ self._factory_id_counter = 0
+
+ def _normalize(self ,context_key: Optional[Sequence["Symbol"]]) -> Tuple["Symbol" ,...]:
+ if(context_key is None):
+ return tuple()
+ if( isinstance(context_key ,tuple) ):
+ ctx = context_key
+ else:
+ ctx = tuple(context_key)
+
+ for s in ctx:
+ if( not isinstance(s ,Symbol) ):
+ raise TypeError("context_key entries must be Symbol values.")
+
+ return ctx
+
+ def read(self ,context_key: Optional[Sequence["Symbol"]] = None) -> Optional["FactoryS"]:
+ ctx = self._normalize(context_key)
+ with self._lock:
+ return self._factory_map.get(ctx)
+
+ def make(self ,context_key: Optional[Sequence["Symbol"]] = None) -> "FactoryS":
+ ctx = self._normalize(context_key)
+ with self._lock:
+ if(ctx in self._factory_map):
+ raise KeyError("FactoryS already exists for this context_key.")
+
+ self._factory_id_counter += 1
+ # Create FactoryS (starts Empty)
+ f = FactoryS(self._space ,ctx ,self._factory_id_counter)
+ self._factory_map[ctx] = f
+ return f
+
+ def delete(self ,context_key: Optional[Sequence["Symbol"]] = None) -> None:
+ ctx = self._normalize(context_key)
+ with self._lock:
+ if(ctx not in self._factory_map):
+ raise KeyError("No factory exists for this context_key.")
+ del self._factory_map[ctx]
+
+ def __len__(self) -> int:
+ with self._lock:
+ return len(self._factory_map)
- def __init__(self):
- self.null = SymbolSpace.Symbol(0 ,None)
- self.context_map = SymbolSpace.ContextMap(self)
- # Default root factory for empty context.
+class SymbolSpace:
+ """
+ Container for the ContextMap and Root FactoryS.
+ """
+ def __init__(self):
+ self.context_map = ContextMap(self)
+
+ # Create the root factory (empty context)
+ # Returns a FactoryS (in Empty state)
self.root_factory = self.context_map.make(tuple())
diff --git a/developer/authored/TMS.py b/developer/authored/TMS.py
new file mode 100644
index 0000000..c0a18d7
--- /dev/null
+++ b/developer/authored/TMS.py
@@ -0,0 +1,278 @@
+# TMS.py
+# RT format: 2-space indent, PascalCase type names, snake_case identifiers.
+
+from enum import Enum, auto
+
+class Status(Enum):
+ EMPTY_TYPED = auto() # No instance, knows type.
+ EMPTY_STASHED = auto() # Instance exists (1 zombie cell), logically empty.
+ PARKED = auto() # Instance exists, head virtual -1.
+ SINGLETON = auto() # Instance exists, size 1, Head at 0.
+ ACTIVE = auto() # Instance exists, size > 1 OR Head > 0.
+
+
+class TMS:
+ """
+ Turing Machine with Status (Second Order Machine).
+ - Projective Parked State (Connects to both ends).
+ - Late Binding & Zombie Cell optimization.
+ - Partial Direct Binding for performance.
+ """
+ __slots__ = (
+ "tm"
+ ,"tm_type"
+ ,"_status"
+ # VTable Methods
+ ,"s"
+ ,"Ls"
+ ,"r"
+ ,"w"
+ ,"d"
+ ,"append"
+ ,"cue_leftmost"
+ ,"cue_rightmost"
+ ,"park"
+ ,"dealloc"
+ ,"is_empty"
+ )
+
+ def __init__(self ,tm=None ,tm_type=None):
+ self.tm = None
+ self.tm_type = None
+
+ if(tm is not None):
+ self.tm = tm
+ self.tm_type = type(tm)
+ self._change_state(Status.PARKED)
+ elif(tm_type is not None):
+ self.tm_type = tm_type
+ self._change_state(Status.EMPTY_TYPED)
+ else:
+ self._change_state(Status.EMPTY_TYPED)
+
+ @property
+ def status(self):
+ return self._status
+
+ def _change_state(self ,new_status):
+ self._status = new_status
+
+ # ---------------------------------------------------------
+ # STATE: ACTIVE
+ # ---------------------------------------------------------
+ if(new_status == Status.ACTIVE):
+ # Direct Binding (Max Performance)
+ self.r = self.tm.r
+ self.w = self.tm.w
+ self.append = self._active_append
+
+ # Navigation: Wrapped Binding (Guarded)
+ self.s = self._active_s
+ self.Ls = self._active_Ls
+
+ self.d = self._active_d
+ self.cue_leftmost = self._active_cue_leftmost
+ self.cue_rightmost = self._active_cue_rightmost
+ self.park = self._active_park
+ self.dealloc = self._generic_dealloc
+ self.is_empty = self._return_false
+
+ # ---------------------------------------------------------
+ # STATE: SINGLETON (Size == 1, Head == 0)
+ # ---------------------------------------------------------
+ elif(new_status == Status.SINGLETON):
+ self.r = self.tm.r
+ self.w = self.tm.w
+
+ # Navigation
+ self.s = self._singleton_s # Falls off 0 -> Active
+ self.Ls = self._singleton_Ls # Falls off 0 -> Parked
+
+ self.d = self._singleton_d # Becomes Stashed
+ self.append = self._singleton_append
+
+ self.cue_leftmost = self._noop # Already at 0
+ self.cue_rightmost = self._noop # Already at 0 (Rightmost=Leftmost)
+ self.park = self._active_park
+ self.dealloc = self._generic_dealloc
+ self.is_empty = self._return_false
+
+ # ---------------------------------------------------------
+ # STATE: PARKED (Projective, Head Virtual)
+ # ---------------------------------------------------------
+ elif(new_status == Status.PARKED):
+ self.s = self._parked_s # Enter Left
+ self.Ls = self._parked_Ls # Enter Right (Projective)
+
+ self.r = self._error_io
+ self.w = self._error_io
+ self.d = self._parked_d
+ self.append = self._error_append
+
+ self.cue_leftmost = self._parked_cue_leftmost
+ self.cue_rightmost = self._parked_cue_rightmost
+ self.park = self._noop
+ self.dealloc = self._generic_dealloc
+ self.is_empty = self._return_false
+
+ # ---------------------------------------------------------
+ # STATE: EMPTY STASHED
+ # ---------------------------------------------------------
+ elif(new_status == Status.EMPTY_STASHED):
+ self.s = self._error_step
+ self.Ls = self._error_step
+ self.r = self._error_io
+ self.w = self._error_io
+ self.d = self._error_op
+
+ self.append = self._stashed_append
+
+ self.cue_leftmost = self._noop
+ self.cue_rightmost = self._noop
+ self.park = self._noop
+ self.dealloc = self._generic_dealloc
+ self.is_empty = self._return_true
+
+ # ---------------------------------------------------------
+ # STATE: EMPTY TYPED
+ # ---------------------------------------------------------
+ elif(new_status == Status.EMPTY_TYPED):
+ self.s = self._error_step
+ self.Ls = self._error_step
+ self.r = self._error_io
+ self.w = self._error_io
+ self.d = self._error_op
+
+ self.append = self._typed_append
+
+ self.cue_leftmost = self._noop
+ self.cue_rightmost = self._noop
+ self.park = self._noop
+ self.dealloc = self._noop
+ self.is_empty = self._return_true
+
+ # --- ACTIVE wrappers ---
+
+ def _active_s(self):
+ # Guard against stepping off the right end
+ if(self.tm.qR()):
+ raise RuntimeError("Cannot step right: At Rightmost cell.")
+ self.tm.s()
+
+ def _active_Ls(self):
+ # Guard: If at Leftmost, transition to Parked
+ if(self.tm.Lq()):
+ self._change_state(Status.PARKED)
+ else:
+ self.tm.Ls()
+
+ def _active_d(self):
+ self.tm.d()
+ if(self.tm.is_singleton()):
+ self._change_state(Status.SINGLETON)
+
+ def _active_append(self ,val):
+ self.tm.append(val)
+
+ def _active_cue_leftmost(self):
+ self.tm.cue_leftmost()
+
+ def _active_cue_rightmost(self):
+ self.tm.cue_rightmost()
+
+ def _active_park(self):
+ self.tm.cue_leftmost()
+ self._change_state(Status.PARKED)
+
+ # --- SINGLETON wrappers ---
+
+ def _singleton_s(self):
+ # Step Right from Singleton(0).
+ # If successful, we are no longer at 0 (or size > 1).
+ # Thus, we must transition to ACTIVE.
+ self.tm.s()
+ self._change_state(Status.ACTIVE)
+
+ def _singleton_Ls(self):
+ # Left of Singleton(0) is Parked
+ self._change_state(Status.PARKED)
+
+ def _singleton_d(self):
+ # Stash zombie
+ self._change_state(Status.EMPTY_STASHED)
+
+ def _singleton_append(self ,val):
+ self.tm.append(val)
+ self._change_state(Status.ACTIVE)
+
+ # --- PARKED wrappers ---
+
+ def _parked_s(self):
+ # Enter tape at Leftmost (0)
+ self.tm.cue_leftmost()
+ if(self.tm.is_singleton()):
+ self._change_state(Status.SINGLETON)
+ else:
+ self._change_state(Status.ACTIVE)
+
+ def _parked_Ls(self):
+ # Enter tape at Rightmost (Projective)
+ self.tm.cue_rightmost()
+ if(self.tm.is_singleton()):
+ self._change_state(Status.SINGLETON)
+ else:
+ self._change_state(Status.ACTIVE)
+
+ def _parked_d(self):
+ # Delete Leftmost (right neighbor)
+ self.tm.cue_leftmost()
+ if(self.tm.is_singleton()):
+ self._change_state(Status.EMPTY_STASHED)
+ else:
+ self.tm.d()
+ if(self.tm.is_singleton()):
+ self._change_state(Status.SINGLETON)
+ else:
+ self._change_state(Status.ACTIVE)
+
+ def _parked_cue_leftmost(self):
+ self._parked_s()
+
+ def _parked_cue_rightmost(self):
+ self._parked_Ls()
+
+ # --- SPECIAL APPENDS ---
+
+ def _stashed_append(self ,val):
+ self.tm.w(val)
+ self._change_state(Status.SINGLETON)
+
+ def _typed_append(self ,val):
+ if(self.tm_type is None):
+ raise RuntimeError("No TM type known.")
+ self.tm = self.tm_type(val)
+ self._change_state(Status.SINGLETON)
+
+ # --- GENERIC ---
+
+ def _generic_dealloc(self):
+ if(self.tm is not None):
+ self.tm_type = type(self.tm)
+ self.tm = None
+ self._change_state(Status.EMPTY_TYPED)
+
+ def _return_true(self): return True
+ def _return_false(self): return False
+ def _noop(self): pass
+
+ def _error_io(self ,*args):
+ raise RuntimeError(f"I/O illegal in {self._status.name} state.")
+
+ def _error_step(self):
+ raise RuntimeError(f"Stepping illegal in {self._status.name} state.")
+
+ def _error_op(self):
+ raise RuntimeError(f"Operation illegal in {self._status.name} state.")
+
+ def _error_append(self ,val):
+ raise RuntimeError(f"Cannot append in {self._status.name} state.")
diff --git a/developer/authored_2026-02-09.tar b/developer/authored_2026-02-09.tar
deleted file mode 100644
index 91a53ef..0000000
Binary files a/developer/authored_2026-02-09.tar and /dev/null differ
diff --git a/document/TMS.html b/document/TMS.html
new file mode 100644
index 0000000..7a5c064
--- /dev/null
+++ b/document/TMS.html
@@ -0,0 +1,160 @@
+
+
+
+
+ Tape Machine with Status
+
+
+
+
+
+
+
+
+
+
+
+
+ Introduction
+
+
+ The Tape Machine with Status (TMS) is a Second Order Machine . It wraps a standard First Order Tape Machine (TM) to provide state management and advanced lifecycle features.
+
+
+
+ While a First Order TM must always reside on a valid cell (the Head must be at a valid address), the TMS allows the machine to be:
+
+ Empty (containing no data)
+ Parked (the head is conceptually "off tape")
+ Active (functioning as a standard TM)
+
+
+
+
+ The TMS implementation uses the State Pattern (vtable swapping) to ensure that the Active state incurs zero overhead. Method calls in the active state are directly bound to the underlying First Order TM's methods.
+
+
+ States
+
+
+ The TMS manages five distinct states to handle lifecycle, late binding, and memory optimization.
+
+
+ 1. EmptyTyped
+
+ The machine is logically empty and has no underlying TM instance allocated. It holds a reference to a TM class type . This supports Late Binding , allowing the TMS to be created before data is available.
+
+
+ Transitions:
+
+ append(v) → Instantiates the TM with value v , transitions to Singleton .
+
+
+
+ 2. EmptyStashed
+
+ The machine is logically empty, but the underlying TM instance is preserved with exactly one "zombie" cell. This is a performance optimization to avoid deallocation and reallocation costs when a machine is cleared and immediately reused.
+
+
+ Transitions:
+
+ append(v) → Overwrites the zombie cell with v , transitions to Singleton .
+ dealloc() → Destroys the TM instance, transitions to EmptyTyped .
+
+
+
+ 3. Parked
+
+ The underlying TM exists, but the TMS Head is conceptually located "outside" the tape. This state is projective , meaning it connects to both ends of the tape.
+
+
+ Transitions:
+
+ s() (Step Right) → Enters the tape at the Leftmost cell. Transitions to Singleton or Active .
+ Ls() (Step Left) → Enters the tape at the Rightmost cell. Transitions to Singleton or Active .
+ d() → Deletes the "right neighbor" (the Leftmost cell). Logic handles degradation to Empty or Singleton.
+
+
+
+ 4. Singleton
+
+ The underlying TM has exactly one cell. The Head is at Address 0. In this state, the underlying TM reports both Lq (Left Query) and qR (Query Right) as true.
+
+
+ Transitions:
+
+ Ls() → Transitions to Parked (exits left).
+ s() → Transitions to Active (extends right) or raises error if bounded.
+ d() → Does not physically delete the cell. Transitions to EmptyStashed (preserving the zombie cell).
+
+
+
+ 5. Active
+
+ The underlying TM has more than one cell. Methods are directly bound to the underlying TM for maximum performance.
+
+
+ Transitions:
+
+ Ls() → If Lq is true (at Leftmost), transitions to Parked . Otherwise, steps left.
+ d() → If the size degrades to 1, transitions to Singleton .
+
+
+
+ Interface
+
+ Navigation
+
+ s() : Step Right.
+
+ In Parked : Lands on Leftmost cell.
+ In Active : Steps right (guarded by qR ).
+
+
+
+ Ls() : Step Left.
+
+ In Parked : Lands on Rightmost cell.
+ In Active : Steps left. If at Leftmost, exits to Parked .
+
+
+
+ park() : Explicitly moves the machine to the Parked state and cues the underlying TM to the leftmost cell.
+
+
+ I/O
+
+ r() and w(val) : Read and Write operations are passed directly to the underlying TM. These are valid only in Active or Singleton states.
+
+
+ Lifecycle
+
+ append(val) : Adds data to the end of the tape. Handles the transition from Empty states to Singleton.
+
+
+ d() : Delete. Removes the current cell.
+
+ In Active : Removes current cell.
+ In Parked : Removes the Leftmost cell.
+
+
+
+ dealloc() : Forces the release of the underlying TM instance, returning the TMS to the EmptyTyped state.
+
+
+
+
+
+
+
+
+
+