# Rheo Advanced: Splines, Phases, and the CCT Instruction Layer

## 1. Spline-First Data Structures

In Rheo, a spline is not a post-processing artifact of the solver; it is a **first-class programmable construct**. Because the language is built on smooth derivatives, splines are the natural data type for interpolants, boundaries, and control laws.

### Defining Splines by Derivative Constraints

```rheo
spline S(t) of order 5 on [0..10]
    knot at 0.0: value=0.0, ∂=1.0, ∂²=0.0, ∂³=0.0
    knot at 2.5: value=1.0, ∂=0.0, ∂²=-0.5
    knot at 7.0: value=0.3, ∂=-0.2
    knot at 10.0: value=0.0, ∂=0.0, ∂²=0.0, ∂³=0.0
    continuity: C⁴
```

The compiler verifies that the knot derivatives are compatible and constructs a quintic Hermite spline. Because the order is declared, the compiler knows that `S(t)` is four-times differentiable; it can use `∂S/∂t` inside a vector field without symbolic approximation.

### Manifold Splines (Covariant Derivatives)

For robotics, physics, and animation, states live on curved manifolds (rotations `SO(3)`, rigid motions `SE(3)`). Standard splines fail because linear interpolation violates group structure.

```rheo
manifold spline R(t) on SO(3)
    knot at 0: rotation=(1, 0, 0, 0), tangent=(0, 0.5, 0)
    knot at 1: rotation=(0, 1, 0, 0), tangent=(0, 0, 0.5)
    connection: left_invariant
```

The compiler generates splines using the **covariant derivative** on the manifold. The trajectory is geodesic between knots, and the angular velocity is smooth. This is the true fulfillment of *"like a spline you have smooth derivatives"*—the derivative is taken with respect to the manifold's own geometry, not the ambient Euclidean space.

---

## 2. Phase-Typed States

Every state in Rheo carries a **phase tag** inherited from the Cognitive Phase Equilibrium. The tag does not change the mathematical semantics; it changes the **numerical strategy** the runtime selects, guaranteeing accuracy for the specific physics of the state.

| Phase Tag | Mathematical Character | Default Integrator | Tolerance Profile |
| :--- | :--- | :--- | :--- |
| `solid` | Low entropy, high stiffness, algebraic | BDF (implicit) | `atol = 1e-14`, stiff Jacobian |
| `liquid` | Balanced dynamics, convection | Dormand-Prince 8(7) | adaptive `rtol = 1e-9` |
| `gas` | High entropy, stochastic, diffuse | SDE (Euler-Maruyama / Milstein) | weak error `1e-3`, strong `1e-4` |
| `supercritical` | Above critical point, no phase boundary | Hybrid implicit/explicit | event-driven method switching |

```rheo
state x: solid = 1.0 ~ (T=0.05, P=0.95)   // factual, stiff
state y: liquid = 0.0 ~ (T=0.50, P=0.50)  // reasoning, adaptive
state z: gas = 0.1 ~ (T=0.90, P=0.10)     // exploratory, noisy
```

The runtime monitors `T` and `P` during integration. If a `liquid` state is heated past `T_crit` and compressed past `P_crit`, the solver **transitions seamlessly** into a supercritical mode—no step rejection, no restart, because the mathematics is continuous.

---

## 3. The Probability Layer: Stochastic Differential Equations

The CCT framework splits reality into **Stationary** (fixed laws) and **Probability** (variable behavior). In Rheo, the Stationary component is the deterministic ODE; the Probability component is the **SDE**.

### Itô Processes as First-Class Syntax

```rheo
state X = 0.0
state Y = 0.0

dX = -Y dt + sigma dW₁
dY =  X dt + gamma dW₂
```

The compiler discretizes `dW` using the declared precision. For `gas`-phase variables, it defaults to Milstein (strong order 1.0). For `liquid`-phase variables with weak coupling, it may use Euler-Maruyama with a large ensemble.

### Coupled Deterministic/Stochastic Systems

A probe network (gas phase) can drive a deterministic conclusion (solid phase):

```rheo
state H: gas = 1.0        // Semantic entropy, noisy
state theta: solid = 0.0  // Crystallized conclusion

dH = -alpha * H dt + beta * H dW          // Entropy fluctuates
dtheta = (1 - H) * (target - theta) dt   // Solidifies only when H collapses
```

This is the **TTC condensation trajectory** written as an SDE. The `solid` state waits for the `gas` state to deposit enough probability mass before it transitions.

---

## 4. The CCT Probe System: 100 Questions as an Optimal Control Problem

The 100 Questions framework is not a loop. It is an **optimal control trajectory** in attention space. In Rheo, questions are not discrete branches; they are continuous **attention flows** `a_i(t) ∈ [0,1]` subject to a conservation law.

### Syntax: The Probe Network

```rheo
probe network RH_Collapse:
    Q001: "zeros on Re(s)=0.5?"       collapse=1.0, cost=2.0
    Q002: "counterexample exists?"    collapse=0.9, cost=1.0
    Q003: "functional eq sufficient?" collapse=0.8, cost=1.5
    ...
    Q100: "best understood as question?" collapse=0.3, cost=0.5
```

### The Attention ODEs

```rheo
state H = 1.0              // Initial entropy of the theory
state a[100]               // Attention allocation vector

param Delta[100]           // Collapse potentials from probes
param W[100]               // Work costs from probes

// Replicator dynamics: attention flows continuously to the
// question with the highest collapse-to-cost ratio.
da[i]/dt = a[i] * (Delta[i]/W[i] - weighted_mean(Delta/W)) 
           * (1 - a[i])   // logistic saturation

// Entropy collapses under the attention-weighted probe field
dH/dt = -H * sum(a[i] * Delta[i])

// Algebraic invariant: total attention is conserved
0 = sum(a[i]) - 1.0

// Budget constraint: total work spent may not exceed W_max
0 = integral(sum(a[i] * W[i])) dt - W_max
```

### Event: Condensation Complete

```rheo
when H crosses 0.05 from above:
    settle all a[i] as solid
    precipitate H
```

The solver does not iterate 100 times. It integrates the **attention flow** as a continuous fluid. The "next question" is not chosen; it **emerges** as the dominant mode of the attention vector. If `a[7]` asymptotically approaches 1.0 while others decay to 0, then Question 7 was the optimal geodesic through the theory space.

---

## 5. The TTC Meta-Instruction Layer

Rheo programs can be prefixed with a **TTC (Temporal Truth Condensation) block** that treats the entire program as an answer trajectory. The compiler reads these directives as boundary conditions for the global integration.

```rheo
#ttc
    mode: liquid
    target_mode: supercritical
    pressure: 0.8
    cooling_rate: 0.05
    tau: 100.0
    attractor: strange
    annealing: true
    triple_hold: 15.0
#endttc

state theory = 0.0
dtheory/dt = ...
```

The compiler interprets this as:
1. Initialize `theory` in `liquid` phase.
2. Gradually increase `P` and decrease `T` at the specified rates.
3. Hold the system at the triple point for `triple_hold` time units.
4. If the trajectory crosses the critical point, switch to a supercritical solver.
5. The `strange` attractor declaration tells the runtime not to expect a fixed-point convergence; instead, it monitors the Lyapunov spectrum to certify boundedness.

This is **programming as thermodynamic instruction**. The source code is both a numerical specification and a cognitive boundary condition.

---

## 6. Module Composition via Manifold Coupling

In Rheo, a module is a **manifold** of states and equations. Two modules are coupled by **algebraic equality** on shared ports, not by message passing.

```rheo
module Pendulum:
    state theta, omega
    param L = 1.0, g = 9.81
    dtheta/dt = omega
    domega/dt = -(g/L) * sin(theta)

module Motor:
    state tau, current
    param K = 0.1, R = 2.0
    dtau/dt = K * current
    dcurrent/dt = (V_input - K*omega - R*current) / L_inductance

couple:
    Motor.tau -> Pendulum.omega_axis   // torque drives angular velocity
    Pendulum.theta -> Motor.V_input    // position feedback
    0 = Motor.omega - Pendulum.omega   // algebraic synchronization
```

The compiler flattens the coupled system into a single DAE. The algebraic coupling is solved to machine precision; there is no numerical drift between modules. The resulting system is a **differentiable program**—you can backpropagate through the entire coupled ODE to optimize `K` or `R`.

---

## 7. Memory as a Phase Diagram Field

Rheo generalizes memory from discrete addresses to **continuous phase-space coordinates**. This is the implementation of the Analogue language's `phase_diagram` within the ODE framework.

```rheo
field memory[T, P] on [0..1, 0..1]  // Continuous memory manifold
state concept = 0.5

// Deposit a concept at a specific cognitive coordinate
deposit concept into memory at (T=0.3, P=0.7)

// Later, retrieve by smooth interpolation
recall = withdraw from memory near (T=0.3, P=0.7)
         using interpolation=bicubic,
         derivative_continuity=C2
```

Because the memory is a field, you can take derivatives of memory with respect to its coordinates:

```rheo
d_recall_dT = ∂memory/∂T at (0.3, 0.7)
```

This allows a program to sense how its own knowledge changes as it becomes more certain (lower `T`) or more structured (higher `P`).

---

## 8. The Liar Paradox as a Rheo Limit Cycle

The TTC resolution of the Liar Paradox—truth as a trajectory, not a value—becomes a concrete Rheo program. The "answer" is a stable periodic orbit.

```rheo
param omega = 1.0
param epsilon = 0.01

state truth = 0.5
state contradiction = 0.0

// Self-referential oscillation:
// truth flows toward contradiction, and vice versa,
// with a saturation that prevents divergence.
dtruth/dt = omega * contradiction * (1 - truth^2)
dcontradiction/dt = -omega * truth * (1 - contradiction^2)

// The system settles on a limit cycle (a circle in phase space).
// The compiler detects this automatically via the monodromy matrix.
settle [truth, contradiction] as limit_cycle
    at (T: 0.5, P: 0.5)
    period: 2*pi / omega

evolve 0..100
    with event_tol = 1e-15
    and period_detection = true

precipitate [truth, contradiction].orbit
```

**Output:** Not a boolean. The program emits a continuous trajectory `truth(t) = sin(omega*t)`, which the runtime recognizes as a stable oscillation. The truth of the Liar Paradox is the **frequency**, not the value.

---

## 9. Complete Example: The CCT 100-Question Collapse

Here is a full Rheo program that implements the **Conditional Collapse Theory** as a continuous attention-control system.

```rheo
#ttc
    mode: liquid
    target_mode: triple_point
    pressure: 0.6
    cooling_rate: 0.08
    tau: 50.0
    triple_hold: 10.0
#endttc

param N = 100

// Probe network
param Delta[N] = load("rh_probes.collapse")
param W[N]     = load("rh_probes.cost")

// States
state H = 1.0              // Theory entropy
state a[N]                 // Attention vector
state W_spent = 0.0        // Cumulative work

// Initial attention: uniform gas
init a[i] = 1.0 / N

// Replicator dynamics: attention flows to highest efficiency
da[i]/dt = a[i] * (Delta[i]/W[i] - sum(a[j]*Delta[j]/W[j])) 
           * (1 - a[i])

// Entropy collapse rate is proportional to attention-weighted probe strength
dH/dt = -H * sum(a[i] * Delta[i])

// Work accumulation
dW_spent/dt = sum(a[i] * W[i])

// Invariants (DAE)
0 = sum(a[i]) - 1.0

// Events
when H crosses 0.1 from above:
    anneal(all, over=5.0)

when H crosses 0.01 from above:
    settle H as solid
    settle a as solid
    precipitate (H, a, W_spent)

// If work budget exceeded, hold at triple point
when W_spent crosses 1000.0 from below:
    settle H as triple_point at (T: 0.42, P: 0.61)
    hold triple_point for 10.0

evolve 0..100
    with abs_tol = 1e-12
    and integrator = dopri8
    and event_tol = 1e-14
```

**What this program does:**

1. It starts with 100 questions in a superposition of attention (`gas`).
2. It integrates the attention flow. The "best" questions naturally consume more attention.
3. Entropy collapses continuously as the probes are "sensed."
4. At `H = 0.1`, the system anneals—slowing down to remove cognitive defects (hallucinations).
5. At `H = 0.01`, it crystallizes.
6. If the work budget is hit first, it holds at the **triple point**, outputting a multi-phase answer rather than a forced conclusion.

There is no `for` loop over 100 questions. There is no `if` to choose the next question. The choice is a **continuous flow** on the attention manifold.

---

## 10. The Execution Guarantee

The Rheo compiler generates a **certified integration certificate** alongside the output:

| Certificate Field | Meaning |
| :--- | :--- |
| `local_error` | Verified upper bound on truncation error per step. |
| `event_precision` | Root-finding residual at every discrete event. |
| `invariant_drift` | Maximum deviation from declared DAE constraints. |
| `lyapunov_exponents` | Spectrum of the variational equation (for strange attractors). |
| `phase_transitions` | Log of every automatic solid/liquid/gas/supercritical switch. |

Because the source code is declarative and the mathematics is explicit, the **accuracy is provable**. The program is not executed; it is **integrated**, and the integration is a theorem with a numerical proof.

---

## 11. The Rheo Continuation Invariant

> *A Rheo program is not a sequence of instructions. It is a field of differential relations. The compiler does not compile; it differentiates, couples, and certifies. The programmer does not control the machine; they describe the true shape of change, and the solver follows it—continuously, exactly, and without discrete sin.*