From: Thomas Walker Lynch Date: Mon, 9 Feb 2026 09:31:29 +0000 (+0000) Subject: working TM·Array_SR_ND, revamping Symbol X-Git-Url: https://git.reasoningtechnology.com/sitemap.xml?a=commitdiff_plain;h=e5fc6c7e36e12b3415e7b832fcbb5d7fa1fdcffd;p=Epimetheus%2F.git working TM·Array_SR_ND, revamping Symbol --- diff --git a/developer/authored/DiscreteFunction.py b/developer/authored/DiscreteFunction.py deleted file mode 100755 index f11ad4d..0000000 --- a/developer/authored/DiscreteFunction.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -from SymbolSpace import SymbolSpace - -# ========================================== -# THE GRAPH (Discrete Function) -# ========================================== - -class DiscreteFunction: - """ - The Knowledge Store. - Supports 'Smart Postings' to Parent Symbols. - """ - def __init__(self): - self._rev = {} # reverse map: Symbol -> Set of Objects - - def _add_posting(self ,sym ,obj): - if sym not in self._rev: self._rev[sym] = set() - self._rev[sym].add(obj) - - def set(self ,obj_sym ,prop_sym): - """ - Assigns a property. Updates indexes for the specific property - AND its namespace (Parent). - """ - # 1. Index Specific (e.g., #105 'Red') - self._add_posting(prop_sym ,obj_sym) - - # 2. Index General (e.g., #50 'Color') - parent = SymbolSpace.get_parent(prop_sym) - if parent: - self._add_posting(parent ,obj_sym) - - def find(self ,sym): - """Returns the set of objects associated with this symbol.""" - return self._rev.get(sym ,set()) - -# --- Work Function --- - -def verify_graph(): - print("--- DiscreteFunction Verification ---") - # 1. Create Symbols - sym_obj = SymbolSpace.alloc() - sym_prop = SymbolSpace.alloc() - sym_parent = SymbolSpace.alloc() - - # 2. Setup Hierarchy - SymbolSpace.set_parent(sym_prop, sym_parent) - - # 3. Set Fact - df = DiscreteFunction() - df.set(sym_obj, sym_prop) - - # 4. Check Smart Posting - print(f"Finding specific property: {len(df.find(sym_prop))} (Expected 1)") - print(f"Finding parent category: {len(df.find(sym_parent))} (Expected 1)") - -def CLI(): - verify_graph() - -if __name__ == "__main__": - CLI() diff --git a/developer/authored/SymbolSpace.py b/developer/authored/SymbolSpace.py deleted file mode 100755 index e363e3e..0000000 --- a/developer/authored/SymbolSpace.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python3 -from collections import deque as FIFO - -class SymbolSpace: - """ - The manager of the Epimetheus integer namespace. - """ - - _counter = 0 - _dealloc_queue = FIFO() - - # HIERARCHY SUPPORT (Added) - _parents = {} # Map: Child_Sym -> Parent_Sym - - class Instance: - """The handle for a symbol.""" - __slots__ = ('_value' ,) - - def __init__(self ,value): - self._value = value - - def __eq__(self ,other): - # Compare value, not identity - if isinstance(other ,SymbolSpace.Instance): return self._value == other._value - return False - - def __hash__(self): - return hash(self._value) - - def __repr__(self): - return f"" - - @classmethod - def alloc(cls) -> 'SymbolSpace.Instance': - val = 0 - if cls._dealloc_queue: - val = cls._dealloc_queue.popleft() - else: - cls._counter += 1 - val = cls._counter - return cls.Instance(val) - - @classmethod - def dealloc(cls ,sym: 'SymbolSpace.Instance'): - val = sym._value - if val == 0: raise ValueError("Null symbol (0) cannot be deallocated.") - - if val == cls._counter: - cls._counter -= 1 - while cls._counter > 0 and cls._counter in cls._dealloc_queue: - cls._dealloc_queue.remove(cls._counter) - cls._counter -= 1 - else: - cls._dealloc_queue.append(val) - - @classmethod - def get_null(cls) -> 'SymbolSpace.Instance': - return cls.Instance(0) - - # --- Hierarchy Methods --- - - @classmethod - def set_parent(cls ,child ,parent): - cls._parents[child] = parent - - @classmethod - def get_parent(cls ,child): - return cls._parents.get(child) - -def verify(): - print(f"Allocating 3 symbols...") - s1 = SymbolSpace.alloc() - s2 = SymbolSpace.alloc() - - # Test Hierarchy - SymbolSpace.set_parent(s2, s1) - assert SymbolSpace.get_parent(s2) == s1 - print("Hierarchy check passed.") - -def CLI(): - verify() - -if __name__ == "__main__": - CLI() diff --git a/developer/authored/Synbol.py b/developer/authored/Synbol.py new file mode 100644 index 0000000..8234e18 --- /dev/null +++ b/developer/authored/Synbol.py @@ -0,0 +1,66 @@ +class Symbol(set): + """ + Epimetheus Symbol. + + Properties: + 1. Identity: Each instance is unique (based on memory address). + 2. Container: It is a Set. Differentiation puts child symbols inside parents. + 3. Hashable: It uses id(self), allowing symbols to contain symbols. + """ + + def __hash__(self): + # The distinctness of the symbol is its memory address (Process Local ID) + return id(self) + + def __eq__(self, other): + # Symbols are only equal if they are the same object + return self is other + + def __repr__(self): + # Hex address is the standard Python way to represent opaque identity + return f"" + +# --- The Factory --- + +class Epimetheus: + @staticmethod + def symbol(): + """Mints a new, unique Symbol.""" + return Symbol() + + @staticmethod + def differentiate(parent_symbol): + """ + Creates a new symbol that is a differentiation of the parent. + The child is added to the parent's set. + """ + child = Symbol() + parent_symbol.add(child) + return child + +# --- Usage Example --- + +def test_symbols(): + # 1. Mint a Root Symbol + color = Epimetheus.symbol() + print(f"Root: {color}") + + # 2. Differentiate + red = Epimetheus.differentiate(color) + blue = Epimetheus.differentiate(color) + + print(f"Red: {red}") + print(f"Blue: {blue}") + + # 3. Verify Structure + print(f"Color contains Red? {red in color}") # True + print(f"Color contains Blue? {blue in color}") # True + print(f"Red is Blue? {red == blue}") # False + + # 4. Nested Differentiation (Hierarchical) + dark_red = Epimetheus.differentiate(red) + print(f"Red contains DarkRed? {dark_red in red}") # True + print(f"Color contains DarkRed? {dark_red in color}") # False (Direct containment only) + +if __name__ == "__main__": + test_symbols() diff --git a/developer/authored/TM.py b/developer/authored/TM.py index 9af7de4..3fff29a 100755 --- a/developer/authored/TM.py +++ b/developer/authored/TM.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import sys -from enum import Enum, auto try: import TM_module @@ -8,73 +7,9 @@ except ImportError: print("Error: Import failed. Run 'python3 setup.py build_ext --inplace'") sys.exit(1) -# ========================================== -# 1. Enums & Features -# ========================================== - class Features: - APPEND_RIGHT = "aR" - -class Status(Enum): - ABANDONED = auto() - ACTIVE = auto() - EMPTY = auto() - -class Topology(Enum): - CIRCLE = auto() - LINEAR_RIGHT = auto() - LINEAR_OPEN = auto() - NULL = auto() - SEGMENT = auto() - -# ========================================== -# 2. The Machine (Factory) -# ========================================== - -# TM is now the Factory Function from the C module -TM = TM_module.FastTM - -# ========================================== -# 3. Status Wrapper (TMS) -# ========================================== - -class TMS: - def __init__(self, data_obj=None, features=None): - """ - TMS Constructor. - Args: - data_obj: Initial data container (list). - features: List of feature symbols (e.g. [Features.APPEND_RIGHT]). - """ - if data_obj: - # Factory Call: C determines the underlying type based on features - self.tm = TM(data_obj, features) - self._stat = Status.ACTIVE - else: - self.tm = None - self._stat = Status.EMPTY - - # --- Base Methods (SR_ND) --- - def r(self): return self.tm.r() - def rn(self, n): return self.tm.rn(n) - def w(self, v): return self.tm.w(v) - def wn(self, v): return self.tm.wn(v) - def s(self): return self.tm.s() - def sn(self, n): return self.tm.sn(n) - - def address(self): return 0 if self.empty() else self.tm.address() - def len(self): return 0 if self.empty() else self.tm.len() - - # --- Feature Methods (Delegated) --- - # If the C-Type doesn't have these, Python raises AttributeError. - def aR(self, v): return self.tm.aR(v) - - # --- Meta --- - def e(self): - # Cloning preserves the underlying C-Type (and thus features) - return TMS(self.tm.e()) if not self.empty() else TMS(None) + # No features currently supported for Array TM + pass - def empty(self): return self._stat == Status.EMPTY - def rightmost(self): return True if self.empty() else self.tm.rightmost() - def leftmost(self): return True if self.empty() else (self.tm.head == 0) - def topology(self): return Topology.NULL if self.empty() else Topology.SEGMENT +# The First Order TM Factory +TM = TM_module.TM diff --git a/developer/authored/TM_module.c b/developer/authored/TM_module.c index b0e7524..4056135 100644 --- a/developer/authored/TM_module.c +++ b/developer/authored/TM_module.c @@ -2,8 +2,11 @@ TM_module.c CPython Extension: Tape Machine Factory Implements: - - TM_SR_ND (Base: Step Right, Non-Destructive) - - TM_SR_ND_AR (Feature: Append Right) + - TM·Array_SR_ND (Pointer-based, Solitary, Step Right, Non-Destructive) + + Style Note: + - RT Naming Convention: TM·Class·Method + - Uses UTF-8 center dot '·' for namespace separation. */ #define PY_SSIZE_T_CLEAN @@ -12,268 +15,188 @@ #include /* ========================================================= */ -/* 1. DATA LAYOUT (Shared) */ +/* 1. DATA LAYOUT */ /* ========================================================= */ typedef struct { PyObject_HEAD - PyObject* tape_obj; /* The Python List (Shared) */ - PyObject* peer_list; /* List of WeakRefs (Shared) */ - Py_ssize_t head; /* Raw Instruction Pointer */ - PyObject* weakreflist; /* Required for WeakRefs */ + PyObject* tape_obj; /* The Container (List) */ + PyObject** head_ptr; /* Current Cell */ + PyObject** start_ptr; /* Leftmost Cell (Cache) */ + PyObject** end_ptr; /* Rightmost Cell + 1 (Sentinel) */ } FastTM; static void FastTM_dealloc(FastTM* self){ - if( self->weakreflist != NULL ){ - PyObject_ClearWeakRefs((PyObject*)self); - } Py_XDECREF(self->tape_obj); - Py_XDECREF(self->peer_list); Py_TYPE(self)->tp_free((PyObject*)self); } -/* Helper: Register Entanglement */ -static int register_entanglement(FastTM* self, PyObject* existing_peer_list){ - PyObject* weak_ref = NULL; - if( existing_peer_list ){ - self->peer_list = existing_peer_list; - Py_INCREF(self->peer_list); - } else { - self->peer_list = PyList_New(0); - if( !self->peer_list ) return -1; - } - weak_ref = PyWeakref_NewRef((PyObject*)self, NULL); - if( !weak_ref ) return -1; - if( PyList_Append(self->peer_list, weak_ref) < 0 ){ - Py_DECREF(weak_ref); - return -1; - } - Py_DECREF(weak_ref); +/* Helper: Refresh Pointers (Used on Init) */ +static int refresh_pointers(FastTM* self){ + if (!PyList_Check(self->tape_obj)) return -1; + + Py_ssize_t len = PyList_GET_SIZE(self->tape_obj); + PyObject** items = ((PyListObject*)self->tape_obj)->ob_item; + + self->start_ptr = items; + self->end_ptr = items + len; + self->head_ptr = items; /* Initialize to start */ + return 0; } /* ========================================================= */ -/* 2. THE MIXIN LIBRARY (Static C Functions) */ +/* 2. TM·Array_SR_ND Methods (Static Implementation) */ /* ========================================================= */ -/* --- Navigation --- */ -static PyObject* mixin_s(FastTM* self){ - self->head++; +/* TM·Array_SR_ND·s: Step Right */ +static PyObject* TM·Array_SR_ND·s(FastTM* self){ + self->head_ptr++; Py_RETURN_NONE; } -static PyObject* mixin_sn(FastTM* self, PyObject* arg_tuple){ +/* TM·Array_SR_ND·sn: Step N */ +static PyObject* TM·Array_SR_ND·sn(FastTM* self, PyObject* arg_tuple){ Py_ssize_t n_val; if( !PyArg_ParseTuple(arg_tuple, "n", &n_val) ) return NULL; + if (n_val < 0) { - PyErr_SetString(PyExc_ValueError, "Machine supports positive steps only."); + PyErr_SetString(PyExc_ValueError, "Step Right machine supports positive steps only."); return NULL; } - self->head += n_val; + self->head_ptr += n_val; Py_RETURN_NONE; } -/* --- I/O --- */ -static PyObject* mixin_r(FastTM* self){ - PyObject* item_obj = PyList_GetItem(self->tape_obj, self->head); - if( !item_obj ) return NULL; - Py_INCREF(item_obj); - return item_obj; -} - -static PyObject* mixin_rn(FastTM* self, PyObject* arg_tuple){ - Py_ssize_t n_val; - if( !PyArg_ParseTuple(arg_tuple, "n", &n_val) ) return NULL; - return PyList_GetSlice(self->tape_obj, self->head, self->head + n_val); -} - -static PyObject* mixin_w(FastTM* self, PyObject* val_obj){ - Py_INCREF(val_obj); - if( PyList_SetItem(self->tape_obj, self->head, val_obj) < 0 ) return NULL; +/* TM·Array_SR_ND·LsR: Rewind */ +static PyObject* TM·Array_SR_ND·LsR(FastTM* self){ + self->head_ptr = self->start_ptr; Py_RETURN_NONE; } -static PyObject* mixin_wn(FastTM* self, PyObject* arg_tuple){ - PyObject* val_list; - if( !PyArg_ParseTuple(arg_tuple, "O", &val_list) ) return NULL; - Py_ssize_t len_val = PySequence_Size(val_list); - if( PyList_SetSlice(self->tape_obj, self->head, self->head + len_val, val_list) < 0 ) return NULL; - Py_RETURN_NONE; +/* TM·Array_SR_ND·r: Read */ +static PyObject* TM·Array_SR_ND·r(FastTM* self){ + PyObject* item = *(self->head_ptr); + Py_INCREF(item); + return item; } -/* --- Features --- */ - -/* Feature: aR (Append Right) */ -static PyObject* mixin_aR(FastTM* self, PyObject* val_obj){ - /* aR typically appends to the END of the tape, - regardless of head position, in non-destructive contexts? - Or at the head? - Standard definition: Append to end of container. */ - if( PyList_Append(self->tape_obj, val_obj) < 0 ) return NULL; +/* TM·Array_SR_ND·w: Write */ +static PyObject* TM·Array_SR_ND·w(FastTM* self, PyObject* val_obj){ + PyObject* old_val = *(self->head_ptr); + Py_INCREF(val_obj); + *(self->head_ptr) = val_obj; + Py_DECREF(old_val); Py_RETURN_NONE; } -/* --- Meta --- */ -static PyObject* mixin_e(FastTM* self){ - /* Factory-aware Entanglement: - We call the type's constructor. Since Py_TYPE(self) is the specific - machine type (e.g. TM_SR_ND_AR), the clone will inherit the same features. */ - PyObject* arg_tuple = PyTuple_Pack(1, self); - PyObject* new_obj = PyObject_CallObject((PyObject*)Py_TYPE(self), arg_tuple); - Py_DECREF(arg_tuple); - return new_obj; -} - -static PyObject* mixin_address(FastTM* self){ - return PyLong_FromSsize_t(self->head); -} - -static PyObject* mixin_len(FastTM* self){ - return PyLong_FromSsize_t(PyList_Size(self->tape_obj)); +/* TM·Array_SR_ND·qR: Query Rightmost */ +static PyObject* TM·Array_SR_ND·qR(FastTM* self){ + if( self->head_ptr >= (self->end_ptr - 1) ) Py_RETURN_TRUE; + Py_RETURN_FALSE; } -static PyObject* mixin_rightmost(FastTM* self){ - Py_ssize_t len = PyList_Size(self->tape_obj); - if( self->head >= len - 1 ) Py_RETURN_TRUE; - Py_RETURN_FALSE; +/* TM·Array_SR_ND·address: Get Index */ +static PyObject* TM·Array_SR_ND·address(FastTM* self){ + Py_ssize_t idx = self->head_ptr - self->start_ptr; + return PyLong_FromSsize_t(idx); } /* ========================================================= */ -/* 3. TYPE DEFINITIONS */ +/* 3. TM·Array_SR_ND Init */ /* ========================================================= */ -/* Generic Init (Used by all types) */ -static int GenericTM_init(FastTM* self, PyObject* args, PyObject* kwds){ +static int TM·Array_SR_ND·init(FastTM* self, PyObject* args, PyObject* kwds){ PyObject* input_obj = NULL; - PyObject* features_obj = NULL; /* Ignored here, consumed by Factory */ + PyObject* features_obj = NULL; if( !PyArg_ParseTuple(args, "O|O", &input_obj, &features_obj) ) return -1; - if( PyObject_TypeCheck(input_obj, Py_TYPE(self)) ){ - /* Clone/Entangle */ - FastTM* source_tm = (FastTM*)input_obj; - self->tape_obj = source_tm->tape_obj; - Py_INCREF(self->tape_obj); - self->head = source_tm->head; - if( register_entanglement(self, source_tm->peer_list) < 0 ) return -1; - } else { - /* New */ - if( PyList_Check(input_obj) ){ - self->tape_obj = input_obj; - Py_INCREF(self->tape_obj); - } else { - self->tape_obj = PySequence_List(input_obj); - if( !self->tape_obj ) return -1; - } - if (PyList_Size(self->tape_obj) == 0) { - PyErr_SetString(PyExc_ValueError, "First Order TM cannot be empty."); - return -1; - } - self->head = 0; - if( register_entanglement(self, NULL) < 0 ) return -1; + if( !PyList_Check(input_obj) ){ + PyErr_SetString(PyExc_TypeError, "Array TM requires a list data object."); + return -1; + } + + if (PyList_Size(input_obj) == 0) { + PyErr_SetString(PyExc_ValueError, "First Order TM cannot be empty."); + return -1; } + + self->tape_obj = input_obj; + Py_INCREF(self->tape_obj); + + refresh_pointers(self); + return 0; } -/* --- Type 1: TM_SR_ND (Base) --- */ -static PyMethodDef TM_SR_ND_methods[] = { - {"r", (PyCFunction)mixin_r, METH_NOARGS, ""}, - {"rn", (PyCFunction)mixin_rn, METH_VARARGS, ""}, - {"w", (PyCFunction)mixin_w, METH_O, ""}, - {"wn", (PyCFunction)mixin_wn, METH_VARARGS, ""}, - {"s", (PyCFunction)mixin_s, METH_NOARGS, ""}, - {"sn", (PyCFunction)mixin_sn, METH_VARARGS, ""}, - {"e", (PyCFunction)mixin_e, METH_NOARGS, ""}, - {"address", (PyCFunction)mixin_address, METH_NOARGS, ""}, - {"len", (PyCFunction)mixin_len, METH_NOARGS, ""}, - {"rightmost", (PyCFunction)mixin_rightmost, METH_NOARGS, ""}, - {NULL} -}; - -static PyTypeObject TM_SR_ND_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "TM_module.TM_SR_ND", - .tp_doc = "Step Right, Non-Destructive", - .tp_basicsize = sizeof(FastTM), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_new = PyType_GenericNew, - .tp_init = (initproc)GenericTM_init, - .tp_dealloc = (destructor)FastTM_dealloc, - .tp_methods = TM_SR_ND_methods, - .tp_weaklistoffset = offsetof(FastTM, weakreflist) -}; +/* ========================================================= */ +/* 4. TYPE DEFINITION */ +/* ========================================================= */ -/* --- Type 2: TM_SR_ND_AR (Base + aR) --- */ -static PyMethodDef TM_SR_ND_AR_methods[] = { - /* Copy Base Methods */ - {"r", (PyCFunction)mixin_r, METH_NOARGS, ""}, - {"rn", (PyCFunction)mixin_rn, METH_VARARGS, ""}, - {"w", (PyCFunction)mixin_w, METH_O, ""}, - {"wn", (PyCFunction)mixin_wn, METH_VARARGS, ""}, - {"s", (PyCFunction)mixin_s, METH_NOARGS, ""}, - {"sn", (PyCFunction)mixin_sn, METH_VARARGS, ""}, - {"e", (PyCFunction)mixin_e, METH_NOARGS, ""}, - {"address", (PyCFunction)mixin_address, METH_NOARGS, ""}, - {"len", (PyCFunction)mixin_len, METH_NOARGS, ""}, - {"rightmost", (PyCFunction)mixin_rightmost, METH_NOARGS, ""}, - /* Add Feature */ - {"aR", (PyCFunction)mixin_aR, METH_O, "Append Right"}, +static PyMethodDef TM·Array_SR_ND·methods[] = { + {"s", (PyCFunction)TM·Array_SR_ND·s, METH_NOARGS, "Step Right"}, + {"sn", (PyCFunction)TM·Array_SR_ND·sn, METH_VARARGS, "Step N"}, + {"r", (PyCFunction)TM·Array_SR_ND·r, METH_NOARGS, "Read"}, + {"w", (PyCFunction)TM·Array_SR_ND·w, METH_O, "Write"}, + {"qR", (PyCFunction)TM·Array_SR_ND·qR, METH_NOARGS, "Query Rightmost"}, + {"LsR", (PyCFunction)TM·Array_SR_ND·LsR, METH_NOARGS, "Rewind"}, + {"address", (PyCFunction)TM·Array_SR_ND·address, METH_NOARGS, "Get Index"}, {NULL} }; -static PyTypeObject TM_SR_ND_AR_Type = { +static PyTypeObject TM·Array_SR_ND·Type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "TM_module.TM_SR_ND_AR", - .tp_doc = "Step Right, Non-Destructive, Append Right", + .tp_name = "TM_module.TM_Array_SR_ND", + .tp_doc = "Array TM: Pointer-based, Solitary, SR, ND", .tp_basicsize = sizeof(FastTM), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_new = PyType_GenericNew, - .tp_init = (initproc)GenericTM_init, + .tp_init = (initproc)TM·Array_SR_ND·init, .tp_dealloc = (destructor)FastTM_dealloc, - .tp_methods = TM_SR_ND_AR_methods, - .tp_weaklistoffset = offsetof(FastTM, weakreflist) + .tp_methods = TM·Array_SR_ND·methods, }; /* ========================================================= */ -/* 4. THE FACTORY */ +/* 5. FACTORY */ /* ========================================================= */ -static PyObject* FastTM_Factory(PyObject* self, PyObject* args, PyObject* kwds){ +static PyObject* TM·Factory(PyObject* self, PyObject* args, PyObject* kwds){ PyObject* input_obj = NULL; PyObject* features_obj = NULL; if( !PyArg_ParseTuple(args, "O|O", &input_obj, &features_obj) ) return NULL; - /* Check for "aR" in features */ - int has_aR = 0; + /* Check Features (Reject incompatible ones) */ if( features_obj && PyList_Check(features_obj) ){ Py_ssize_t size = PyList_Size(features_obj); for( Py_ssize_t i=0; i Active + # We must assume implicit list container for now + self.tm = TM([v]) + self._stat = Status.ACTIVE + else: + self.tm.aR(v) + + # --- Meta --- + def e(self): + return TMS(self.tm.e()) if not self.empty() else TMS([]) + + def empty(self): return self._stat == Status.EMPTY + def rightmost(self): return True if self.empty() else self.tm.rightmost() + +# ========================================== +# 4. Region Machine +# ========================================== + +class RegionMachine: + def __init__(self, t_active): + """ + Constructs a Region Machine from a single Active TM. + Initializes Left/Right boundaries to the current Active position. + """ + self.t_active = t_active + self.t_left = t_active.e() # Left Boundary + self.t_right = t_active.e() # Right Boundary + + # --- Bounds Management --- + def qL(self): + return TM_workspace.head_on_same_cell(self.t_active, self.t_left) + + def qR(self): + return TM_workspace.head_on_same_cell(self.t_active, self.t_right) + + def sR(self): + # Cue to Right Boundary (Simulated via address copying or step loop) + # Since we lack random access 'cue' in SR_ND, we might need 's' loop + # or direct address manipulation if supported. + # For now, we rely on the implementation matching the head. + pass # Todo: Implement cue via delta steps + + # --- Navigation (Guarded) --- + def s(self): + if self.qR(): + raise RuntimeError("Region Boundary Violation: Cannot step past Right Bound.") + self.t_active.s() + + def r(self): + return self.t_active.r() diff --git a/developer/authored/build/temp.linux-x86_64-cpython-311/TM_module.o b/developer/authored/build/temp.linux-x86_64-cpython-311/TM_module.o new file mode 100644 index 0000000..948af5a Binary files /dev/null and b/developer/authored/build/temp.linux-x86_64-cpython-311/TM_module.o differ diff --git a/developer/authored/example_TM_SR_ND.py b/developer/authored/example_TM_SR_ND.py new file mode 100755 index 0000000..fcd591f --- /dev/null +++ b/developer/authored/example_TM_SR_ND.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from TM import TM + +def test_base_machine(): + print("--- TM·Array_SR_ND Verification ---") + + data = [10, 20, 30] + tm = TM(data) + print(f"Created TM. Data: {data}") + + # Forward Scan + print("\n[Forward Scan]") + while True: + print(f"Read: {tm.r()}") + if tm.qR(): break + tm.s() + + # Rewind + print("\n[Rewind]") + tm.LsR() + print(f"After LsR, Read: {tm.r()} (Expected: 10)") + + # Write + tm.w(999) + print(f"Wrote 999. Read: {tm.r()} (Expected: 999)") + +if __name__ == "__main__": + test_base_machine() diff --git a/developer/authored/example_TM_SR_ND_aR.py b/developer/authored/example_TM_SR_ND_aR.py new file mode 100755 index 0000000..290774a --- /dev/null +++ b/developer/authored/example_TM_SR_ND_aR.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +from TM import TMS, Features + +def test_ar_machine(): + print("--- TM_ARRAY_SR_ND_aR Verification ---") + + # 1. Initialization with Feature (Mandatory Data) + data = [10, 20, 30] + t = TMS(data, features=[Features.APPEND_RIGHT]) + + print(f"Created Machine t1. Len: {t.len()}") + + # 2. Test Append on t1 + t.s() # Step to 20 + print("Executing t1.aR(99)...") + t.aR(99) + print(f"t1 Len: {t.len()} (Expected: 4)") + print(f"t1 Content from Head: {t.rn(3)} (Expected: [20, 30, 99])") + + # 3. Test Entanglement (Shared Tape) + # --------------------------------------------------------- + t2 = t.e() + print("\nCreated entangled machine t2 from t1.") + + print("Executing t2.aR(100)...") + t2.aR(100) + + # Verify t2 (The actor) + print(f"t2 Len: {t2.len()} (Expected: 5)") + + # Verify t1 (The observer) - PROOF OF ENTANGLEMENT + # t1 should see the change immediately because the tape is shared. + print(f"t1 Len: {t.len()} (Expected: 5)") + + if t.len() == 5: + print(">> SUCCESS: t1 reflects change made by t2 (Tape is shared).") + else: + print("!! FAIL: t1 did not see the change (Tape is copied?).") + + # 4. Verify Base Restrictions + try: + t.ls() + print("!! FAIL: ls() succeeded") + except AttributeError: + print(">> SUCCESS: ls() blocked.") + +if __name__ == "__main__": + test_ar_machine() diff --git a/developer/authored/example_region.py b/developer/authored/example_region.py new file mode 100644 index 0000000..1ab3aba --- /dev/null +++ b/developer/authored/example_region.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +from TM import TMS, RegionMachine + +def test_region(): + print("--- Region Machine Verification ---") + + # Tape: [10, 20, 30, 40, 50] + t = TMS([10, 20, 30, 40, 50]) + + # Create Region. Initially Boundaries are at 0 (start). + # Region is [0, 0] (Single Cell). + rm = RegionMachine(t) + + print("Region Initialized [0, 0].") + print(f"qL: {rm.qL()} (Exp: True)") + print(f"qR: {rm.qR()} (Exp: True)") + + # Expand Region: Move Right Boundary to index 2 + print("Expanding Right Boundary to index 2...") + rm.t_right.sn(2) + + # Region is now [0, 2] (Indices 0, 1, 2) + print(f"qR (Active at 0): {rm.qR()} (Exp: False)") + + # Move Active Head + rm.s() # To 1 + print(f"Active at 1. Val: {rm.r()}") + rm.s() # To 2 + print(f"Active at 2. Val: {rm.r()}") + + print(f"qR (Active at 2): {rm.qR()} (Exp: True)") + + # Try to step out of region + print("Attempting to step past Right Boundary...") + try: + rm.s() + print("!! FAIL: Stepped out of region!") + except RuntimeError as e: + print(f">> SUCCESS: Blocked by Boundary. ({e})") + +if __name__ == "__main__": + test_region() + diff --git a/developer/old_code.tar b/developer/old_code.tar new file mode 100644 index 0000000..c8cf219 Binary files /dev/null and b/developer/old_code.tar differ