Source identity
| Field | Recorded value |
|---|---|
| Source type | archive member |
| Original record | feedback_experiment.py |
| Date | Not specified in source |
| Path or archive member | archives/libsrc-00eb3fd1c22a/unreal_feedback_experiment/feedback_experiment.py |
| Original SHA-256 | b1f9e81f611751402ce72592c541b410d31957f74f92d9f320a5d13169664a8b |
| Reading-copy SHA-256 | b1f9e81f611751402ce72592c541b410d31957f74f92d9f320a5d13169664a8b |
| Archive source | {"sourceId": "libsrc-00eb3fd1c22a", "member": "unreal_feedback_experiment/feedback_experiment.py"} |
Recovered source transcript
Download complete source text ↓91 lines · 3.5 KB
#!/usr/bin/env python3
"""Reproduce a scalar feedback experiment derived from Anady's seven-operator example.
This is a synthetic numerical experiment, not an Unreal Engine execution or a
consciousness test. The reference-centred feedback rule is a new proposed coupling;
the seven scalar operators and equal-average map come from the project manuscript.
Usage:
python feedback_experiment.py
Writes trajectory.csv next to this script. Requires only Python's standard library.
"""
from __future__ import annotations
import csv
import math
from pathlib import Path
def operator_mean(z: float) -> float:
"""Apply the manuscript's seven scalar operators in parallel and average.
This experiment restricts the domain to finite positive numbers. It does not
silently regularize, clip, or replace the reciprocal operator.
"""
if not math.isfinite(z) or z <= 0.0:
raise ValueError("This experiment requires finite z > 0.")
values = (z + 1.0, z - 1.0, z, z**1.0, 1.0**z, z / 1.0, 1.0 / z)
return math.fsum(values) / 7.0
def feedback_step(z: float, gain: float, reference: float = 1.0) -> float:
"""New coupling: z_next = reference + gain * (F(z) - F(reference)).
No clipping is used. Runs that leave the positive domain or grow beyond the
numerical guard are rejected, rather than counted as successful persistence.
The proven basin for gain=2 in this example is 2/3 < z0 < 1.
"""
if not math.isfinite(gain) or gain < 0.0:
raise ValueError("gain must be finite and nonnegative.")
result = reference + gain * (operator_mean(z) - operator_mean(reference))
if not math.isfinite(result) or result <= 0.0 or result > 1e6:
raise ArithmeticError("Trajectory left this experiment's valid numerical domain.")
return result
def simulate(gain: float, start: float, steps: int = 200) -> list[float]:
if steps < 0:
raise ValueError("steps must be nonnegative.")
operator_mean(start) # Validate even when steps is zero.
states = [start]
for _ in range(steps):
states.append(feedback_step(states[-1], gain))
return states
def main() -> None:
returning = simulate(1.0, 0.99)
persistent = simulate(2.0, 0.99)
unperturbed = simulate(2.0, 1.0)
disconnected = simulate(0.0, 0.99)
assert abs(returning[-1] - 1.0) < 1e-12
assert abs(persistent[-1] - 2.0 / 3.0) < 1e-12
assert all(value == 1.0 for value in unperturbed)
assert all(value == 1.0 for value in disconnected[1:])
assert all(b <= a + 1e-15 for a, b in zip(persistent, persistent[1:]))
assert all(value >= 2.0 / 3.0 - 1e-12 for value in persistent)
assert abs(feedback_step(2.0 / 3.0, 2.0) - 2.0 / 3.0) < 1e-14
output = Path(__file__).resolve().parent / "trajectory.csv"
with output.open("w", newline="", encoding="utf-8") as handle:
writer = csv.writer(handle)
writer.writerow([
"iteration", "reference", "gain_1_start_0.99", "gain_2_start_0.99",
"gain_2_start_1_exact", "gain_0_start_0.99"
])
for i in range(len(returning)):
writer.writerow([
i, 1.0, returning[i], persistent[i], unperturbed[i], disconnected[i]
])
print("7 numerical checks passed.")
print("Gain 1, start 0.99:", returning[-1])
print("Gain 2, start 0.99:", persistent[-1])
print("Synthetic mathematical result only; no Unreal integration was executed.")
print("Full trajectory:", output)
if __name__ == "__main__":
main()