<h1>Introduction</h1>
<p>
- A <RT-term>Tape Machine</RT-term> (TM) is an abstract mechanism for the manipulation of data found in sequences. Such sequences include lists, arrays, sets according to an ordering function, and maps also against an ordering function. Also included are linear traversals of more complex data structures. TM is discussed in detail in the <RT-term>TTCA</RT-term> book.
+ A <RT-term>Tape Machine</RT-term> (TM) is used to manipulation data found in a sequences. Such sequences include lists, arrays, sets according to an ordering function, and maps also against an ordering function. Also included are linear traversals of more complex data structures. TM is discussed in detail in the <RT-term>TTCA</RT-term> book.
</p>
<p>
</p>
<p>
- Thus each TM type has the nice property of encompassing both data and pointers within one structure.
+ Thus each TM type has the nice property of encompassing both data and pointers into that data within one structure.
</p>
<p>
<p>
When multiple machines share the same tape, we say the machines are <RT-term>entangled</RT-term>. For analysis to remain first order, when machines are entangled, we must be careful with destructive operations. There are multiple approaches to this, each corresponding to a different type of first order TM. One approach is the <RT-code>TM_ND</RT-code> which has no tape structure modifying operations. Another approach is the <RT-code>TM_SOLO</RT-code> which does not allow more than one machine on its tape. Yet another approach is the <RT-code>TM_EA</RT-code>, where <RT-term>EA</RT-term> means 'entanglement accounting'. With entanglement accounting all the machines that share a tape also share the catalog of entangled machines. Each destructive operation then checks the listed machines and their head positions to assure that no machine is structurally broken by the operation.
- For example, before deleting a cell, a machine checks that no machine has a head on the specified cell, and thus would become orphaned by the operation.
+ For example, before deleting a cell, a machine checks that no machine has a head on the specified cell, and thus would become orphaned when the cell is removed from the tape.
</p>
- <h1>Command reference (ND-TM)</h1>
+ <h1>Command reference for the ND-TM</h1>
<p>
- The following commands are available for the Non-Destructive First Order Machine. The notation uses strictly ASCII characters.
+ The following commands are available for the Nondestructive First Order Machine. In this version the notation uses strictly ASCII characters.
</p>
- <h2>Grammar</h2>
+ <h2>The grammar</h2>
<RT-code>
-statement :: [location]command+[quantifier]*[&contract]*[arg]*
-location :: l | L | R | ε
+statement :: [location]command+[quantifier]*[arg]*
+location :: l | L | R default is right cell
command :: r | w | s | q | e
-quantifier :: A | R | n
-contract :: hL | hR
+quantifier :: A | R | n default n is one, default A is the head position
</RT-code>
- <h2>Definitions</h2>
+ <h2>The definitions</h2>
- <h3>Location</h3>
+ <h3>The location</h3>
<ul>
- <li><RT-code>ε</RT-code> (Empty): Implicit Right / Forward / Plus.</li>
- <li><RT-code>l</RT-code>: <strong>l</strong>eft neighbor.</li>
- <li><RT-code>L</RT-code>: <strong>L</strong>eftmost.</li>
- <li><RT-code>R</RT-code>: <strong>R</strong>ightmost.</li>
+ <li><RT-code>ε</RT-code> (Empty) implies a step to the right, forward, or plus.</li>
+ <li><RT-code>l</RT-code> moves to the <strong>l</strong>eft neighbor.</li>
+ <li><RT-code>L</RT-code> moves to the <strong>L</strong>eftmost position.</li>
+ <li><RT-code>R</RT-code> moves to the <strong>R</strong>ightmost position.</li>
</ul>
- <h3>Command</h3>
+ <h3>The commands</h3>
<ul>
- <li><RT-code>r</RT-code>: <strong>r</strong>ead the cell under the head.</li>
- <li><RT-code>w</RT-code>: <strong>w</strong>rite the cell under the head.</li>
- <li><RT-code>s</RT-code>: <strong>s</strong>tep the head position.</li>
- <li><RT-code>q</RT-code>: <strong>q</strong>uery. Ask a question about the machine state.</li>
- <li><RT-code>e</RT-code>: <strong>e</strong>ntangle. Spawns a new head on the same tape.</li>
+ <li><RT-code>r</RT-code> <strong>r</strong>eads the cell under the head.</li>
+ <li><RT-code>w</RT-code> <strong>w</strong>rites to the cell under the head.</li>
+ <li><RT-code>s</RT-code> <strong>s</strong>teps the head position.</li>
+ <li><RT-code>q</RT-code> <strong>q</strong>ueries the machine state.</li>
+ <li><RT-code>e</RT-code> <strong>e</strong>ntangles and spawns a new head on the same tape.</li>
</ul>
- <h3>Quantifier</h3>
+ <h3>The quantifiers</h3>
<ul>
- <li><RT-code>A</RT-code>: <strong>A</strong>ddress (Head Index).</li>
- <li><RT-code>R</RT-code>: <strong>R</strong>ightmost Address (Extent).</li>
- <li><RT-code>n</RT-code>: Repeat <strong>n</strong> times (requires argument).</li>
+ <li><RT-code>A</RT-code> returns the <strong>A</strong>ddress or head index.</li>
+ <li><RT-code>R</RT-code> returns the <strong>R</strong>ightmost address or extent.</li>
+ <li><RT-code>n</RT-code> repeats <strong>n</strong> times.</li>
</ul>
- <h3>Contracts</h3>
- <p>
- Contracts assert the state of the machine before execution.
- </p>
- <ul>
- <li><RT-code>hL</RT-code>: Head is at <strong>L</strong>eftmost.</li>
- <li><RT-code>hR</RT-code>: Head is at <strong>R</strong>ightmost.</li>
- </ul>
-
- <h2>Examples</h2>
+ <h2>The examples</h2>
<RT-code>
ls ; Step to left neighbor
qA ; Query Address (What is the head index?)
</RT-code>
- <h1>Primitive method reference</h1>
+ <h1>The primitive method reference</h1>
<p>
This section details the actual methods exposed by the First Order TM implementation (Python/C). These primitives map directly to the command language.
</p>
- <h2>Navigation primitives</h2>
+ <h2>The navigation primitives</h2>
<ul>
- <li><RT-code>s()</RT-code>: Step right.</li>
- <li><RT-code>sn(n)</RT-code>: Step right <RT-math>n</RT-math> times.</li>
- <li><RT-code>ls()</RT-code>: Step left.</li>
- <li><RT-code>lsn(n)</RT-code>: Step left <RT-math>n</RT-math> times.</li>
- <li><RT-code>Ls()</RT-code>: Cue leftmost (Head = 0).</li>
- <li><RT-code>Rs()</RT-code>: Cue rightmost (Head = Extent).</li>
- <li><RT-code>Lsn(n)</RT-code>: Cue leftmost with offset <RT-math>n</RT-math> (Head = 0 + n).</li>
- <li><RT-code>Rsn(n)</RT-code>: Cue rightmost with offset <RT-math>n</RT-math> (Head = Extent - n).</li>
+ <li><RT-code>s()</RT-code> steps right.</li>
+ <li><RT-code>sn(n)</RT-code> steps right <RT-math>n</RT-math> times.</li>
+ <li><RT-code>ls()</RT-code> steps left.</li>
+ <li><RT-code>lsn(n)</RT-code> steps left <RT-math>n</RT-math> times.</li>
+ <li><RT-code>Ls()</RT-code> cues leftmost.</li>
+ <li><RT-code>Rs()</RT-code> cues rightmost.</li>
+ <li><RT-code>Lsn(n)</RT-code> cues leftmost with offset <RT-math>n</RT-math>.</li>
+ <li><RT-code>Rsn(n)</RT-code> cues rightmost with offset <RT-math>n</RT-math>.</li>
</ul>
- <h2>I/O primitives</h2>
+ <h2>The input and output primitives</h2>
<ul>
- <li><RT-code>r()</RT-code>: Read current cell.</li>
- <li><RT-code>rn(n)</RT-code>: Read <RT-math>n</RT-math> cells (Bulk read).</li>
- <li><RT-code>w(v)</RT-code>: Write value to current cell.</li>
- <li><RT-code>wn(list)</RT-code>: Write list of values (Bulk write).</li>
+ <li><RT-code>r()</RT-code> reads the current cell.</li>
+ <li><RT-code>rn(n)</RT-code> reads <RT-math>n</RT-math> cells.</li>
+ <li><RT-code>w(v)</RT-code> writes a value to the current cell.</li>
+ <li><RT-code>wn(list)</RT-code> writes a list of values.</li>
</ul>
- <h2>Query primitives</h2>
+ <h2>The query primitives</h2>
<p>
Introspection commands used to check machine state without side effects.
</p>
<ul>
- <li><RT-code>qA()</RT-code>: <strong>Query address</strong>. Return the current head index.</li>
+ <li><RT-code>qA()</RT-code> queries the address to return the current head index.</li>
</ul>
- <h2>Entanglement primitives</h2>
+ <h2>The entanglement primitives</h2>
<ul>
- <li><RT-code>e()</RT-code>: <strong>Entangle</strong>. Creates a new machine instance sharing the same tape and safety catalog. The new machine's head is initialized to the same position as the original machine.</li>
- <li><RT-code>es()</RT-code>: Entangle, step right.</li>
- <li><RT-code>esn(n)</RT-code>: Entangle, step right <RT-math>n</RT-math> times.</li>
- <li><RT-code>els()</RT-code>: Entangle, step left.</li>
- <li><RT-code>elsn(n)</RT-code>: Entangle, step left <RT-math>n</RT-math> times.</li>
- <li><RT-code>eLs()</RT-code>: Entangle, cue leftmost.</li>
- <li><RT-code>eRs()</RT-code>: Entangle, cue rightmost.</li>
- <li><RT-code>eLsn(n)</RT-code>: Entangle, cue leftmost with offset.</li>
- <li><RT-code>eRsn(n)</RT-code>: Entangle, cue rightmost with offset.</li>
+ <li><RT-code>e()</RT-code> entangles a new machine instance sharing the same tape and safety catalog.</li>
+ <li><RT-code>es()</RT-code> entangles and steps right.</li>
+ <li><RT-code>esn(n)</RT-code> entangles and steps right <RT-math>n</RT-math> times.</li>
+ <li><RT-code>els()</RT-code> entangles and steps left.</li>
+ <li><RT-code>elsn(n)</RT-code> entangles and steps left <RT-math>n</RT-math> times.</li>
+ <li><RT-code>eLs()</RT-code> entangles and cues leftmost.</li>
+ <li><RT-code>eRs()</RT-code> entangles and cues rightmost.</li>
+ <li><RT-code>eLsn(n)</RT-code> entangles and cues leftmost with an offset.</li>
+ <li><RT-code>eRsn(n)</RT-code> entangles and cues rightmost with an offset.</li>
</ul>
- <h1>Usage</h1>
+ <h1>The usage</h1>
- <h2>First order TM properties</h2>
+ <h2>The first order TM properties</h2>
<p>
For a first order TM these properties are always true.
the interval, and on an entangled machine on the rightmost cell of the interval.
</p>
- <h2>Contract with the programmer</h2>
+ <h2>The contract with the programmer</h2>
<p>
Some first order TM types rely upon the programmer to maintain a contract in order to maintain the first order TM properties. Such machines typically have debug variants that add contract checks. For some machines breaking the contract can limit the ability of the compiler to optimize code, for other machines breaking the contract can lead
+++ /dev/null
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>TM First Order</title>
- <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet">
-
- <script src="style/body_visibility_hidden.js"></script>
- <script>
- window.StyleRT.body_visibility_hidden();
- </script>
- </head>
- <body>
- <RT-article>
- <RT-title
- author="Thomas Walker Lynch"
- date="2026-02-04"
- title="TM First Order">
- </RT-title>
-
- <RT-TOC level="1"></RT-TOC>
-
- <h1>Introduction</h1>
-
- <p>
- The <RT-term>First Order Tape Machine</RT-term> (TM) is a high-performance mechanism for navigating and manipulating data sequences.
- </p>
-
- <p>
- If you are coming from standard programming, you are likely used to arrays (which just sit there) or iterators (which disappear after one use). A <strong>Tape Machine</strong> is different: it is a persistent agent that lives on your data. It has a "head" (a position) that stays where you put it until you tell it to move.
- </p>
-
- <p>
- Think of it like a cursor in a text editor, but for data. You can read what's under the cursor, overwrite it, move left or right, or even spawn a second cursor ("entangle") to work on the same text at the same time.
- </p>
-
- <h1>The First-Rest Pattern</h1>
-
- <p>
- To use a Tape Machine effectively, you must understand the <strong>First-Rest</strong> pattern. This is the fundamental way TMs view data recursion and iteration.
- </p>
-
- <p>
- At any moment, a Tape Machine divides the world into two parts:
- </p>
- <ol>
- <li><strong>First:</strong> The single cell currently under the head. This is the "Now."</li>
- <li><strong>Rest:</strong> Everything else to the right of the head. This is the "Future."</li>
- </ol>
-
- <p>
- The standard processing loop acts on the <em>First</em> item, and then checks if a <em>Rest</em> exists. Crucially, the programmer uses the query <RT-code>qR()</RT-code> (Query Rightmost) to <strong>protect</strong> the step command <RT-code>s()</RT-code>. If <RT-code>qR()</RT-code> is false, it is safe to step into the Rest.
- </p>
-
- <RT-code>
-# Example: Summing a list using First-Rest
-total = tm.r() # Process the "First"
-while not tm.qR(): # Guard: Is there a "Rest"?
- tm.s() # Safe to step
- total += tm.r() # Process the new "First"
- </RT-code>
-
- <h1>Contract with the Programmer</h1>
-
- <p>
- The Tape Machine is a precision tool. To achieve its speed and safety, it adheres to a strict contract.
- </p>
-
- <h2>The Machine Guarantees:</h2>
- <ul>
- <li><strong>Persistence:</strong> The head will never move unless you explicitly command it.</li>
- <li><strong>Bounds Safety:</strong> The machine will refuse to step off the edge of the tape (unless configured with a specific topology like <code>Circle</code>).</li>
- <li><strong>Non-Destructive Nature:</strong> This First Order machine will <strong>never</strong> structurally alter the tape. It cannot insert or delete cells. This ensures that addresses (indices) remain stable forever.</li>
- <li><strong>Entanglement Safety:</strong> If you spawn multiple heads (using <code>e</code>), they share the same underlying memory. Writing with one head is immediately visible to all others.</li>
- </ul>
-
- <h2>You Guarantee:</h2>
- <ul>
- <li><strong>Thread Discipline:</strong> While the machine supports entanglement across threads (via <code>t</code>), you must ensure that your application logic does not create race conditions on the data itself.</li>
- <li><strong>Initialization:</strong> You must provide a valid data container (like a List) or another TM to initialize the machine.</li>
- </ul>
-
- <h1>Command Reference</h1>
-
- <p>
- The Tape Machine is controlled via a formal command language. This section defines the abstract commands available to the machine. The notation uses strictly ASCII characters.
- </p>
-
- <h2>Grammar</h2>
- <RT-code>
-statement :: [location]command+[quantifier]*[arg]*
-location :: l | L | R | ε
-command :: r | w | s | q | e
-quantifier :: A | R | n
- </RT-code>
-
- <h2>Definitions</h2>
-
- <h3>Location</h3>
- <ul>
- <li><RT-code>ε</RT-code> (Empty): Implicit Right / Forward / Plus.</li>
- <li><RT-code>l</RT-code>: <strong>l</strong>eft neighbor.</li>
- <li><RT-code>L</RT-code>: <strong>L</strong>eftmost.</li>
- <li><RT-code>R</RT-code>: <strong>R</strong>ightmost.</li>
- </ul>
-
- <h3>Command</h3>
- <ul>
- <li><RT-code>r</RT-code>: <strong>r</strong>ead the cell under the head.</li>
- <li><RT-code>w</RT-code>: <strong>w</strong>rite the cell under the head.</li>
- <li><RT-code>s</RT-code>: <strong>s</strong>tep the head position.</li>
- <li><RT-code>q</RT-code>: <strong>q</strong>uery. Ask a question about the machine state.</li>
- <li><RT-code>e</RT-code>: <strong>e</strong>ntangle. Spawns a new head on the same tape.</li>
- </ul>
-
- <h3>Quantifier</h3>
- <ul>
- <li><RT-code>A</RT-code>: <strong>A</strong>ddress (Head Index).</li>
- <li><RT-code>R</RT-code>: <strong>R</strong>ightmost Address (Extent).</li>
- <li><RT-code>n</RT-code>: Repeat <strong>n</strong> times (requires argument).</li>
- </ul>
-
- <h2>Examples</h2>
-
- <RT-code>
-ls ; Step to left neighbor
-Ls ; Cue Leftmost (Go to index 0)
-Rs ; Cue Rightmost (Go to last index)
-qA ; Query Address (What is the head index?)
- </RT-code>
-
- <h1>Primitive Method Reference</h1>
-
- <p>
- This section details the actual methods exposed by the First Order TM implementation (Python/C). These primitives map directly to the command language.
- </p>
-
- <h2>Navigation Primitives</h2>
- <ul>
- <li><RT-code>s()</RT-code>: Step Right.</li>
- <li><RT-code>sn(n)</RT-code>: Step Right <RT-math>n</RT-math> times.</li>
- <li><RT-code>ls()</RT-code>: Step Left.</li>
- <li><RT-code>lsn(n)</RT-code>: Step Left <RT-math>n</RT-math> times.</li>
- <li><RT-code>Ls()</RT-code>: Cue Leftmost (Head = 0).</li>
- <li><RT-code>Rs()</RT-code>: Cue Rightmost (Head = Extent).</li>
- <li><RT-code>Lsn(n)</RT-code>: Cue Leftmost with Offset <RT-math>n</RT-math> (Head = 0 + n).</li>
- <li><RT-code>Rsn(n)</RT-code>: Cue Rightmost with Offset <RT-math>n</RT-math> (Head = Extent - n).</li>
- </ul>
-
- <h2>I/O Primitives</h2>
- <ul>
- <li><RT-code>r()</RT-code>: Read current cell.</li>
- <li><RT-code>rn(n)</RT-code>: Read <RT-math>n</RT-math> cells (Bulk Read).</li>
- <li><RT-code>w(v)</RT-code>: Write value to current cell.</li>
- <li><RT-code>wn(list)</RT-code>: Write list of values (Bulk Write).</li>
- </ul>
-
- <h2>Query Primitives</h2>
- <p>
- Introspection commands used to check machine state without side effects.
- </p>
- <ul>
- <li><RT-code>qA()</RT-code>: <strong>Query Address</strong>. Return the current head index.</li>
- </ul>
-
- <h2>Entanglement Primitives</h2>
- <ul>
- <li><RT-code>e()</RT-code>: <strong>Entangle</strong>. Creates a new machine instance sharing the same tape and safety catalog. The new machine's head is initialized to the same position as the original machine.</li>
- <li><RT-code>es()</RT-code>: Entangle, Step Right.</li>
- <li><RT-code>esn(n)</RT-code>: Entangle, Step Right <RT-math>n</RT-math> times.</li>
- <li><RT-code>els()</RT-code>: Entangle, Step Left.</li>
- <li><RT-code>elsn(n)</RT-code>: Entangle, Step Left <RT-math>n</RT-math> times.</li>
- <li><RT-code>eLs()</RT-code>: Entangle, Cue Leftmost.</li>
- <li><RT-code>eRs()</RT-code>: Entangle, Cue Rightmost.</li>
- <li><RT-code>eLsn(n)</RT-code>: Entangle, Cue Leftmost with Offset.</li>
- <li><RT-code>eRsn(n)</RT-code>: Entangle, Cue Rightmost with Offset.</li>
- </ul>
-
- <h1>Architecture</h1>
-
- <h2>Behavior Selection (Flags)</h2>
- <p>
- The First Order TM is designed to be flexible. When creating a machine, you can pass a set of <strong>Flags</strong> to the constructor to select specific behaviors or safety checks. This allows the core machine to remain fast (zero overhead) while providing options for debugging or specialized topologies.
- </p>
-
- <RT-code>
-# Example: Creating a machine with Safety Checks and Debug Messages
-tm = TM(data_list, flags={Debug.safe, Debug.message})
- </RT-code>
-
- <ul>
- <li><RT-code>Debug.safe</RT-code>: Enables extra runtime bounds checking and validation.</li>
- <li><RT-code>Debug.message</RT-code>: Prints a trace of operations to the console (useful for learning).</li>
- <li><RT-code>Topology.circle</RT-code>: Configures the machine to wrap around at the ends of the tape.</li>
- </ul>
-
- <h2>Entanglement</h2>
- <p>
- A critical feature of the TM is <RT-term>Entanglement</RT-term>. Multiple TMs can operate on the same underlying tape memory simultaneously.
- </p>
-
- <p>
- To ensure safety, the TM implements an <RT-neologism>Entanglement Catalog</RT-neologism> in the C layer. While structural modification (allocation/deletion) is disallowed in the First Order machine, the Catalog remains the system of record for tracking all active heads on a shared tape, providing the foundation for future synchronization primitives.
- </p>
-
- <script src="style/style_orchestrator.js"></script>
- <script>
- window.StyleRT.style_orchestrator();
- </script>
- </RT-article>
- </body>
-</html>
+++ /dev/null
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>TM First Order</title>
- <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet">
-
- <script src="style/body_visibility_hidden.js"></script>
- <script>
- window.StyleRT.body_visibility_hidden();
- </script>
- </head>
- <body>
- <RT-article>
- <RT-title
- author="Thomas Walker Lynch"
- date="2026-02-03"
- title="TM First Order">
- </RT-title>
-
- <RT-TOC level="1"></RT-TOC>
-
- <h1>Introduction</h1>
-
- <p>
- The <RT-term>First Order Tape Machine</RT-term> (TM) is a fundamental mechanism for sequence manipulation. It is a concrete implementation of the <RT-term>Tape Machine</RT-term> abstraction defined in the <RT-term>TTCA</RT-term>.
- </p>
-
- <p>
- While modern programming languages offer various containers (Lists, Arrays, Vectors), the <RT-term>First Order TM</RT-term> unifies them under a single <RT-term>interface</RT-term> that emphasizes <RT-term>positional state</RT-term>. Unlike a standard iterator which consumes data, a TM persists. Unlike a raw array which is stateless, a TM maintains a <RT-term>head</RT-term>.
- </p>
-
- <h1>Command Reference</h1>
-
- <p>
- The Tape Machine is controlled via a formal command language. This section defines the abstract commands available to the machine. The notation uses strictly ASCII characters.
- </p>
-
- <h2>Grammar</h2>
- <RT-code>
-statement :: [direction]command+[modifier][&contract]*[arg]*
-direction :: l | ε
-command :: r | w | s | a | d | q | m | e | t
-modifier :: L | R | A | AR | n
- </RT-code>
-
- <h2>Definitions</h2>
-
- <h3>Direction</h3>
- <ul>
- <li><RT-code>ε</RT-code> (Empty): Implicit Right / Forward / Plus.</li>
- <li><RT-code>l</RT-code>: Left / Backward / Minus.</li>
- </ul>
-
- <h3>Abstract Commands</h3>
- <ul>
- <li><RT-code>r</RT-code>: <strong>Read</strong> the cell under the head.</li>
- <li><RT-code>w</RT-code>: <strong>Write</strong> the cell under the head.</li>
- <li><RT-code>s</RT-code>: <strong>Step</strong> the head position.</li>
- <li><RT-code>a</RT-code>: <strong>Allocate</strong> (Add/Append) a new cell.</li>
- <li><RT-code>d</RT-code>: <strong>Deallocate</strong> (Drop/Delete) a cell.</li>
- <li><RT-code>q</RT-code>: <strong>Query</strong>. Ask a question about the machine state.</li>
- <li><RT-code>m</RT-code>: <strong>Move</strong>. No allocation or deallocation; requires fill.</li>
- <li><RT-code>e</RT-code>: <strong>Entangle</strong>. Spawns a new head on the same tape.</li>
- <li><RT-code>t</RT-code>: <strong>Thread</strong>. Entangle on a new thread.</li>
- </ul>
-
- <h3>Modifiers</h3>
- <ul>
- <li><RT-code>L</RT-code>: Operate on <strong>Leftmost</strong>.</li>
- <li><RT-code>R</RT-code>: Operate on <strong>Rightmost</strong>.</li>
- <li><RT-code>A</RT-code>: Operate on <strong>Address</strong> (Head Index).</li>
- <li><RT-code>AR</RT-code>: Operate on <strong>Address of Rightmost</strong> (Extent).</li>
- <li><RT-code>n</RT-code>: Repeat <strong>n</strong> times (requires argument).</li>
- </ul>
-
- <h3>Contracts</h3>
- <p>
- Contracts assert the state of the machine before execution.
- </p>
- <ul>
- <li><RT-code>hL</RT-code>: Head is at Leftmost.</li>
- <li><RT-code>hR</RT-code>: Head is at Rightmost.</li>
- </ul>
-
- <h2>Examples</h2>
-
- <RT-code>
-ls ; Step left
-aL ; Allocate (create) a new leftmost cell
-aR ; Allocate (append) to rightmost
-qA ; Query Address (What is the head index?)
-qAR ; Query Extent (What is the max index?)
- </RT-code>
-
- <h1>Primitive Method Reference</h1>
-
- <p>
- This section details the actual methods exposed by the First Order TM implementation (Python/C). These primitives map directly to the command language or provide optimized compound operations.
- </p>
-
- <h2>Navigation Primitives</h2>
- <ul>
- <li><RT-code>s()</RT-code>: Step Right.</li>
- <li><RT-code>sn(n)</RT-code>: Step Right <RT-math>n</RT-math> times.</li>
- <li><RT-code>ls()</RT-code>: Step Left.</li>
- <li><RT-code>lsn(n)</RT-code>: Step Left <RT-math>n</RT-math> times.</li>
- </ul>
-
- <h2>I/O Primitives</h2>
- <ul>
- <li><RT-code>r()</RT-code>: Read current cell.</li>
- <li><RT-code>rn(n)</RT-code>: Read <RT-math>n</RT-math> cells (Bulk Read).</li>
- <li><RT-code>w(v)</RT-code>: Write value to current cell.</li>
- <li><RT-code>wn(list)</RT-code>: Write list of values (Bulk Write).</li>
- </ul>
-
- <h2>Allocation Primitives</h2>
- <ul>
- <li><RT-code>aL(v)</RT-code>: Allocate Left (Prepend).</li>
- <li><RT-code>aR(v)</RT-code>: Allocate Right (Append).</li>
- </ul>
-
- <h2>Deletion Primitives</h2>
- <ul>
- <li><RT-code>d()</RT-code>: Delete current cell.</li>
- <li><RT-code>dn(n)</RT-code>: Delete <RT-math>n</RT-math> cells starting at current.</li>
- </ul>
-
- <h2>Compound Primitives</h2>
- <p>
- These methods combine multiple abstract commands into a single atomic C-operation for performance and safety.
- </p>
- <ul>
- <li><RT-code>esd()</RT-code>: <strong>Entangle-Step-Delete</strong>. Equivalent to <RT-code>e</RT-code> → <RT-code>s</RT-code> → <RT-code>d</RT-code>. Safely deletes the cell to the right of the head (the "neighbor").</li>
- <li><RT-code>esdn(n)</RT-code>: Delete <RT-math>n</RT-math> right neighbors.</li>
- </ul>
-
- <h2>Query Primitives</h2>
- <p>
- Introspection commands used to check machine state without side effects.
- </p>
- <ul>
- <li><RT-code>qA()</RT-code>: <strong>Query Address</strong>. Return the current head index.</li>
- <li><RT-code>qR()</RT-code>: <strong>Query Rightmost</strong>. Returns <RT-code>True</RT-code> if the head is at the rightmost cell.</li>
- <li><RT-code>qL()</RT-code>: <strong>Query Leftmost</strong>. Returns <RT-code>True</RT-code> if the head is at the leftmost cell (index 0).</li>
- <li><RT-code>qAR()</RT-code>: <strong>Query Address Rightmost</strong> (Extent). Returns the index of the rightmost cell (Length - 1). This ensures the return value always fits within the address space, unlike Length which is one greater than the maximum index.</li>
- </ul>
-
- <h2>Entanglement Primitives</h2>
- <ul>
- <li><RT-code>e()</RT-code>: <strong>Entangle</strong>. Creates a new machine instance sharing the same tape and safety catalog. The new machine's head is initialized to the same position as the original machine.</li>
- </ul>
-
- <h1>Architecture</h1>
-
- <h2>The Hybrid Model</h2>
- <p>
- For maximum performance in high-frequency loops, the First Order TM is implemented using a <RT-neologism>Direct Execution</RT-neologism> architecture.
- </p>
-
- <ul>
- <li><strong>Inner Loop (C-Extension):</strong> The core operations—reading, stepping, and writing—are implemented in C. This code directly manipulates the memory pointers of the underlying Python List, avoiding interpreter overhead.</li>
- <li><strong>Outer Loop (Python Wrapper):</strong> The Python layer handles initialization and interface compliance.</li>
- </ul>
-
- <h2>Entanglement Safety</h2>
- <p>
- A critical feature of the TM is <RT-term>Entanglement</RT-term>. Multiple TMs can operate on the same underlying tape memory simultaneously. This is efficient, but dangerous: if one machine deletes a cell that another machine is looking at, the system could crash or corrupt state.
- </p>
-
- <p>
- To prevent this, the TM implements an <RT-neologism>Entanglement Catalog</RT-neologism> in the C layer.
- </p>
-
- <RT-math>
- \text{Safe}(op) \iff \forall \text{peer} \in \text{Catalog}, \text{Head}(\text{peer}) \notin \text{VictimRange}(op)
- </RT-math>
-
- <p>
- Before any destructive operation (like delete), the machine checks the catalog. If any peer's head is currently positioned on a cell scheduled for deletion, the operation is blocked with a <RT-code>RuntimeError</RT-code>.
- </p>
-
- <script src="style/style_orchestrator.js"></script>
- <script>
- window.StyleRT.style_orchestrator();
- </script>
- </RT-article>
- </body>
-</html>
+++ /dev/null
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>02 - The First Order Tape Machine</title>
- <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet">
-
- <script src="style/body_visibility_hidden.js"></script>
- <script>
- window.StyleRT.body_visibility_hidden();
- </script>
- </head>
- <body>
- <RT-article>
- <RT-title
- author="Thomas Walker Lynch"
- date="2026-02-03"
- title="02 - The First Order Tape Machine">
- </RT-title>
-
- <RT-TOC level="1"></RT-TOC>
-
- <h1>Introduction</h1>
-
- <p>
- The <RT-term>First Order Tape Machine</RT-term> (TM) is the foundational mechanism for sequence manipulation. It is a concrete implementation of the <RT-term>Tape Machine</RT-term> abstraction defined in the TTCA.
- </p>
-
- <p>
- While modern programming languages offer various containers (Lists, Arrays, Vectors), the <RT-term>First Order TM</RT-term> unifies them under a single <RT-term>interface</RT-term> that emphasizes <RT-term>positional state</RT-term>. Unlike a standard iterator which consumes data, a TM persists. Unlike a raw array which is stateless, a TM maintains a <RT-term>head</RT-term>.
- </p>
-
- <h1>Architecture</h1>
-
- <h2>The Hybrid Model</h2>
- <p>
- For maximum performance in high-frequency loops, the First Order TM is implemented using a <RT-neologism>Direct Execution</RT-neologism> architecture.
- </p>
-
- <ul>
- <li><strong>Inner Loop (C-Extension):</strong> The core operations—reading, stepping, and writing—are implemented in C. This code directly manipulates the memory pointers of the underlying Python List, avoiding interpreter overhead.</li>
- <li><strong>Outer Loop (Python Wrapper):</strong> The Python layer handles initialization and interface compliance.</li>
- </ul>
-
- <p>
- This hybrid approach allows the TM to execute simple steps like <RT-code>s()</RT-code> (step right) in nanoseconds, comparable to native pointer arithmetic in compiled languages.
- </p>
-
- <h2>Entanglement Safety</h2>
- <p>
- A critical feature of the Epimetheus TM is <RT-term>Entanglement</RT-term>. Multiple TMs can operate on the same underlying tape memory simultaneously. This is efficient, but dangerous: if one machine deletes a cell that another machine is looking at, the system could crash or corrupt state.
- </p>
-
- <p>
- To prevent this, the TM implements an <RT-neologism>Entanglement Catalog</RT-neologism> in the C layer.
- </p>
-
- <RT-math>
- \text{Safe}(op) \iff \forall \text{peer} \in \text{Catalog}, \text{Head}(\text{peer}) \notin \text{VictimRange}(op)
- </RT-math>
-
- <p>
- Before any destructive operation (like delete), the machine checks the catalog. If any peer's head is currently positioned on a cell scheduled for deletion, the operation is blocked with a <RT-code>RuntimeError</RT-code>.
- </p>
-
- <h1>Interface</h1>
-
- <h2>Movement</h2>
- <p>
- The TM maintains a <RT-term>Head</RT-term> index. Movement is relative.
- </p>
-
- <ul>
- <li><RT-code>s()</RT-code>: Step Right (increment head).</li>
- <li><RT-code>sn(n)</RT-code>: Step Right by <RT-math>n</RT-math>.</li>
- <li><RT-code>ls()</RT-code>: Step Left (decrement head).</li>
- <li><RT-code>lsn(n)</RT-code>: Step Left by <RT-math>n</RT-math>.</li>
- </ul>
-
- <h2>Read / Write</h2>
- <p>
- Data access occurs at the current head position.
- </p>
-
- <RT-code>
-# Read current cell
-val = tm.r()
-
-# Bulk read next 3 cells
-chunk = tm.rn(3)
-
-# Write to current cell
-tm.w(42)
-
-# Bulk write (overwrite sequence)
-tm.wn([10, 20, 30])
- </RT-code>
-
- <h2>Allocation</h2>
- <p>
- New cells can be created at the boundaries.
- </p>
- <ul>
- <li><RT-code>aR(val)</RT-code>: Append Right (standard append).</li>
- <li><RT-code>aL(val)</RT-code>: Append Left (prepend). Note that this operation shifts the indices of all existing cells. The TM automatically adjusts its own head to maintain logical stability, but peers may experience <RT-neologism>Index Drift</RT-neologism>.</li>
- </ul>
-
- <h2>Deletion</h2>
- <p>
- Deletion is the only operation restricted by Entanglement Safety.
- </p>
-
- <h3>Delete Current (d)</h3>
- <p>
- <RT-code>d()</RT-code> removes the cell currently under the head. After deletion, the head index remains unchanged, but it now points to the <em>next</em> cell in the sequence (the one that shifted into the slot).
- </p>
-
- <h3>Delete Neighbor (esd)</h3>
- <p>
- <RT-code>esd()</RT-code> (Entangle, Step, Delete) removes the cell immediately to the <em>right</em> of the head. This is the primitive operation for Singly Linked Tapes, but is offered on the First Order TM for symmetry.
- </p>
-
- <h1>Implementation Detail</h1>
-
- <h2>The C Module</h2>
- <p>
- The C module <RT-code>TM_module.c</RT-code> defines the <RT-code>FastTM</RT-code> struct.
- </p>
-
- <RT-code>
-typedef struct {
- PyObject_HEAD
- PyObject* tape_obj; /* Shared Python List */
- PyObject* peer_list; /* Shared WeakRef List */
- Py_ssize_t head; /* C-Level Integer */
- PyObject* weakreflist; /* Garbage Collection Support */
-} FastTM;
- </RT-code>
-
- <p>
- By keeping the <RT-code>head</RT-code> as a native C integer <RT-code>Py_ssize_t</RT-code>, arithmetic operations avoid the boxing/unboxing cost of Python Integers.
- </p>
-
- <script src="style/style_orchestrator.js"></script>
- <script>
- window.StyleRT.style_orchestrator();
- </script>
- </RT-article>
- </body>
-</html>