
# 💾 FORCEPASM 0.1 — Specification

## 🧠 Core Philosophy

> **Every dynamic system can be expressed as a combination of:**
> - **Stationary elements** (constants, structures, time)
> - **Probabilistic behavior** (distribution, randomness, collapse)
> - **Force evolution over time** (bias, change, interruption)

---

## 🔣 Instruction Set

FORCEPASM extends PASM with time and determinism primitives. It includes:

### ⏱ Time and Control

| Instruction | Description |
|-------------|-------------|
| `MOV rX, value` | Assigns a **stationary constant** to register `rX` |
| `MOVP rX, {v1: p1, v2: p2, ...}` | Assigns a **probability distribution** to register `rX` |
| `ADDP rX, rY, rZ` | Adds `rY + rZ` into `rX` (can be probabilistic) |
| `MULP rX, rY, rZ` | Multiplies `rY * rZ` into `rX` |
| `DIVP rX, rY, rZ` | Divides `rY / rZ` into `rX` |
| `MEAS rX` | Collapses probabilistic register to sampled value |
| `JMPP p% label_true, (100-p)% label_false` | Jumps probabilistically to one of two labels |
| `JMP label` | Unconditional jump |

---

## ⚙️ Force-Specific Macros

### `HOLD rX, value, duration`

> Holds a value in register `rX` for `duration` time steps.

```pasm
; Pseudo-macro expands into:
IF r_time < t_start + duration:
    MOV rX, value
ELSE:
    MOVP rX, {…} ; resume random or zero
```

---

### `APPLY_FORCE r_position, r_velocity, r_force, r_mass`

> Applies Newtonian force update for one time step.

```pasm
DIVP r_accel, r_force, r_mass
ADDP r_velocity, r_velocity, r_accel
ADDP r_position, r_position, r_velocity
```

---

### `INTERRUPT_CHANCE r_flag, chance%`

> Stochastically flips a register flag to 1, once.

```pasm
JMPP chance% interrupt, (100-chance)% skip
interrupt:
MOV r_flag, 1
skip:
```

---

## 📦 Registers

You may define the following types of registers:

| Type | Purpose |
|------|---------|
| `r_position` | Position in 1D or nD space |
| `r_velocity` | Motion vector (deterministic or stochastic) |
| `r_force` | Force vector or scalar |
| `r_mass` | Scalar mass value |
| `r_time` | Global time counter |
| `r_state` | Any logical or discrete state |
| `r_interrupted` | Binary flag for interruptions |
| `r_accel` | Temporary register for acceleration |

---

## 🔄 Standard Loop Pattern

```pasm
MOV r_time, 0
loop:
ADDP r_time, r_time, 1

; [Physics logic goes here]

JMP loop
```

---

## 📚 Example: Newtonian Particle with Random Interruption

```pasm
; Initialization
MOV r_position, 0
MOV r_velocity, 0
MOV r_mass, 2.0
MOV r_time, 0
MOV r_hold_force, 1.0
MOV r_interrupted, 0

loop:
ADDP r_time, r_time, 1

; 5% chance to interrupt force
JMPP 5% interrupt, 95% skip_interrupt IF r_interrupted = 0
interrupt:
MOV r_interrupted, 1
skip_interrupt:

; Apply force if not interrupted and time < 10
JMPP 100% hold_force, 0% random_force IF r_time < 10 AND r_interrupted = 0
JMP random_force

hold_force:
MOV r_force, r_hold_force
JMP apply_force

random_force:
MOVP r_force, {1.0: 0.5, -1.0: 0.5}

apply_force:
DIVP r_accel, r_force, r_mass
ADDP r_velocity, r_velocity, r_accel
ADDP r_position, r_position, r_velocity

JMP loop
```

---

## 🧩 Simulation Concepts

| Concept | Description | PASM Mapping |
|--------|-------------|--------------|
| Particle | A bundle of position, velocity, mass | `r_position`, `r_velocity`, `r_mass` |
| Field | A rule that produces forces based on space/time | Conditional `MOVP`, `HOLD`, etc. |
| Interaction | When one register affects another | Conditional jumps or feedback |
| Entanglement | Correlated probabilistic dependencies | `MOVP rB IF rA = X` |
| Measurement | Collapse of distribution to sampled outcome | `MEAS` |
| Noise | Uncontrolled randomness | `MOVP` with unbiased values |
| Inertia | Momentum preservation | `r_velocity` propagation |
| Time-dependent behavior | Force logic with time gating | `r_time`, conditional branching |

---

## 🧱 Design Principles

- ✅ **Explicit time**
- ✅ **Separation of stationary vs probabilistic**
- ✅ **Composable state transitions**
- ✅ **Physics-agnostic logic**
- ✅ **Memory and conditional control**
- ✅ **Interruptibility**
- ✅ **Measurement and collapse**
- ✅ **Extensible into multi-agent and multi-particle systems**

---

## 🚀 Future Extensions

| Feature | Description |
|--------|-------------|
| `FORCEPASM-2D` | Extend to 2D/3D vector motion and fields |
| `FORCEPASM-MULTI` | Multi-particle interaction rules |
| `FORCEPASM-GRAPH` | Particles on topological graphs |
| `FORCEPASM-VIZ` | Real-time visualization |
| `FORCEPASM-COMPILE` | Compiler for macro expansion |

---

## 🔚 Closing Thought

> **FORCEPASM is not just a toy language.**  
> It is a **computational substrate** for modeling particles, forces, and quantum behavior — not through differential equations, but through **discrete probabilistic logic** with time, memory, and feedback.
