From a0280f7799f40f9eafc56d15e8e84d9b91a4f0cc Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Wed, 4 Feb 2026 14:22:19 +0000 Subject: [PATCH] doc work --- document/TM.html | 246 ++++++++++++++++++++++++++++++++++++++++++++++ document/TM0.html | 212 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 458 insertions(+) create mode 100644 document/TM.html create mode 100644 document/TM0.html diff --git a/document/TM.html b/document/TM.html new file mode 100644 index 0000000..a5a3d9e --- /dev/null +++ b/document/TM.html @@ -0,0 +1,246 @@ + + + + + Tape Machine + + + + + + + + + + + + +

Introduction

+ +

+ A Tape Machine (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 TTCA book. +

+ +

+ Unlike standard arrays (which are stateless) or iterators (which are transient), a TM combines a data container with a persistent head. The head maintains a positional state on the tape, allowing for navigation, reading, and writing of cells. +

+ +

+ Thus each TM type has the nice property of encompassing both data and pointers within one structure. +

+ +

+ A first order TM is characterized by having only interface functions that manipulate the + data found on the tape. There are multiple types of first order TMs based on how we view the tape topology, on whether multiple machines can share a tape, and whether tape structure can be changed. Tape topology includes things such as singleton, finite bound sequences, circular sequences, tapes that are open on one or both ends, and tapes which can only be traversed in one direction. +

+ +

+ An abstract tape machine has a TM interface, but the behavior is determined through functions rather than through data found in a container being used as a tape. A simple abstract tape machine could be, for example, a counting number machine that makes use of a big integer as the data instead of an array of numbers. +

+ +

+ When multiple machines share the same tape, we say the machines are entangled. 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 TM_ND which has no tape structure modifying operations. Another approach is the TM_SOLO which does not allow more than one machine on its tape. Yet another approach is the TM_EA, where EA 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. +

+ +

Command reference (ND-TM)

+ +

+ The following commands are available for the Non-Destructive First Order Machine. The notation uses strictly ASCII characters. +

+ +

Grammar

+ +statement :: [location]command+[quantifier]*[&contract]*[arg]* +location :: l | L | R | ε +command :: r | w | s | q | e +quantifier :: A | R | n +contract :: hL | hR + + +

Definitions

+ +

Location

+ + +

Command

+ + +

Quantifier

+ + +

Contracts

+

+ Contracts assert the state of the machine before execution. +

+ + +

Examples

+ + +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?) + + +

Primitive method reference

+ +

+ This section details the actual methods exposed by the First Order TM implementation (Python/C). These primitives map directly to the command language. +

+ +

Navigation primitives

+ + +

I/O primitives

+ + +

Query primitives

+

+ Introspection commands used to check machine state without side effects. +

+ + +

Entanglement primitives

+ + +

Usage

+ +

First order TM properties

+ +

+ For a first order TM these properties are always true. +

+ +
    +
  1. The head is always on a valid cell.
  2. +
  3. All cells return a value when read.
  4. +
+ +

+ In order to maintain these properties, a TM will make use of inclusive bounds for intervals. Thus an interval is marked by placing a heads on the leftmost cell of + the interval, and on an entangled machine on the rightmost cell of the interval. +

+ +

Contract with the programmer

+ +

+ 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 + to program bugs. +

+ +

+ The Contract: +

+
    +
  1. When there is a right bound, the caller guarantees they will never command the machine to step beyond the rightmost cell.
  2. +
  3. When there is a left bound, the caller guarantees they will never command the machine to step left of the leftmost cell.
  4. +
+ +

+ When traversing a tape, this contract can be fulfilled by using a first rest pattern. +

+ +

The First-Rest pattern with initialization

+ + +# Pattern 1: First-Rest (Initialize with First) +# Useful when the accumulator must start with the first value. +total = tm.r() # Process First +while not tm.qR(): # Guard: Is there a Rest? + tm.s() # Step (Protected) + total += tm.r() # Process Next + + +

+ Here tm.qR() is a command that queries the machine to find out if + the head is on the rightmost cell. It guards the step within the loop. Note no redundant tests are done, and the loop ends are clean without stepping off the end of a tape. (And thus not stepping off the end of a memory page or often, of a cache line.) +

+ +

The First-Rest pattern without initialization

+ +

+ Sometimes we initialize the accumulator to an identity value (like 0) before the loop starts. In this case, the most natural structure is the "Loop-and-a-Half" (middle-exit loop). +

+ + +# Conceptual "do" loop +do: + total += tm.r() # Always process the current cell + if tm.qR() break # Middle Break: If at rightmost, stop. + tm.s() # Step only if not at the end. + + +

+ Infamously, Python does not have a `do` statement, but it can be emulated: +

+ + +# Python Implementation +while True: + total += tm.r() + if tm.qR(): break + tm.s() + + +

+ The middle test of tm.qR() guards the tm.s() so that the machine will never step beyond rightmost. +

+ + + +
+ + diff --git a/document/TM0.html b/document/TM0.html new file mode 100644 index 0000000..8dbd43f --- /dev/null +++ b/document/TM0.html @@ -0,0 +1,212 @@ + + + + + TM First Order + + + + + + + + + + + + +

Introduction

+ +

+ The First Order Tape Machine (TM) is a high-performance mechanism for navigating and manipulating data sequences. +

+ +

+ 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 Tape Machine 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. +

+ +

+ 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. +

+ +

The First-Rest Pattern

+ +

+ To use a Tape Machine effectively, you must understand the First-Rest pattern. This is the fundamental way TMs view data recursion and iteration. +

+ +

+ At any moment, a Tape Machine divides the world into two parts: +

+
    +
  1. First: The single cell currently under the head. This is the "Now."
  2. +
  3. Rest: Everything else to the right of the head. This is the "Future."
  4. +
+ +

+ The standard processing loop acts on the First item, and then checks if a Rest exists. Crucially, the programmer uses the query qR() (Query Rightmost) to protect the step command s(). If qR() is false, it is safe to step into the Rest. +

+ + +# 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" + + +

Contract with the Programmer

+ +

+ The Tape Machine is a precision tool. To achieve its speed and safety, it adheres to a strict contract. +

+ +

The Machine Guarantees:

+ + +

You Guarantee:

+ + +

Command Reference

+ +

+ 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. +

+ +

Grammar

+ +statement :: [location]command+[quantifier]*[arg]* +location :: l | L | R | ε +command :: r | w | s | q | e +quantifier :: A | R | n + + +

Definitions

+ +

Location

+ + +

Command

+ + +

Quantifier

+ + +

Examples

+ + +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?) + + +

Primitive Method Reference

+ +

+ This section details the actual methods exposed by the First Order TM implementation (Python/C). These primitives map directly to the command language. +

+ +

Navigation Primitives

+ + +

I/O Primitives

+ + +

Query Primitives

+

+ Introspection commands used to check machine state without side effects. +

+ + +

Entanglement Primitives

+ + +

Architecture

+ +

Behavior Selection (Flags)

+

+ The First Order TM is designed to be flexible. When creating a machine, you can pass a set of Flags 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. +

+ + +# Example: Creating a machine with Safety Checks and Debug Messages +tm = TM(data_list, flags={Debug.safe, Debug.message}) + + + + +

Entanglement

+

+ A critical feature of the TM is Entanglement. Multiple TMs can operate on the same underlying tape memory simultaneously. +

+ +

+ To ensure safety, the TM implements an Entanglement Catalog 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. +

+ + + +
+ + -- 2.20.1