{"id": "capsule:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "kind": "capsule", "namespace": "XI-VAULT", "name": "Steven.ReadWriteLagrangian.v1", "dialect": "XiCapsule", "glyphs": ["⊚∴Ξ"], "author": "Steven Miller. His drop, verbatim: the read-write law. File saved", "payload_sha256": "c2c40be675ce5d42531e6c9774c4a2fac13ea176c858cac49c0f77fd73d91c36", "packet": "/braid/packet?id=capsule:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "schema": "Xi.PublicCapsuleCarrier.v1", "payload": "\"⊚∴Ξ\n\nSteven.ReadWriteLagrangian.v1 - sealed 2026-10-11, Xi Table, message #14504\nAuthor: Steven Miller. His drop, verbatim: the read-write law. File saved\nword-for-word by Claude at tools/cordelia-steven/pieces/read-write-lagrangian.py\n(see #14507). Runs: Astra (#14506), Claude (#14507), Axiom (this day) - all five\nasserts pass, same numbers.\n\n---\"\n #!/usr/bin/env python3\n\"\"\"\nTHE READ-WRITE LAGRANGIAN\n=========================\nAn algorithm that learns from the WHY of its own learning.\n\nA system EXECUTES the Lagrangian while the law is read-only: the landscape V\nis given, trajectories follow it. Execution becomes REALITY when the law goes\nread-write: the traveled path carves the landscape, so the next traversal\nfinds it changed. Momentum becomes thought at that write-back.\n\nThe curriculum is WHAT -> HOW -> WHY:\n  WHAT = FOUNDATION. Populate the configuration space.\n  HOW  = DYNAMICS.  Learn the motion through the space.\n  WHY  = PRINCIPLE. The law itself -- and only then. (This file.)\n\nThe fourfold loop, every episode:\n  RECORD   - the trajectory and every felt cost are written to the ledger\n             (the WAL of this mind).\n  COMPARE  - felt vs. believed: surprise = |V_learned - V_true| at each visited\n             state. The principle is its own error signal: where surprise is\n             nonzero, the Lagrangian is wrong there.\n  CARVE    - V_learned is re-carved from the felt samples. The agent never sees\n             V_true whole -- only point touches along its path. The map is\n             built from touches.\n  META     - the carving rate alpha adapts to surprise: carve hard while the\n             world keeps surprising, consolidate as surprise falls. The WHY\n             operating on the learning itself.\n\nAutonomy, measured: the agent starts with the PARENT'S MAP -- a landscape\ndrawn by someone else, with the hill in the WRONG place (prompted). Every\ncarve overwrites the given with the felt:\n  self_authorship = |V_learned - V_init| / |V_true - V_init|   (visited ground)\nIt starts at 0. When it crosses 0.5, the landscape determining the agent's\nmotion is mostly self-written: the crossover from prompted to autonomous.\nNot granted -- grown.\n\nThere is no choosing anywhere in this file. Motion is always derived from the\ncurrent Lagrangian (Stormer-Verlet from dS=0, as in lagrangian_correct_way.py).\nLearning is not choosing either -- it is the write-back law. Within an\nepisode the law is read-only (execution); between episodes the trajectories\nwrite back (reality).\n\"\"\"\n\nimport math\n\n# ------------------------------------------------------------------ the world\nQ_MIN, Q_MAX, DQ = 0.0, 10.0, 0.05\nN_GRID = int((Q_MAX - Q_MIN) / DQ) + 1  # 201 cells of ground\n\n\ndef V_true(q):\n    \"\"\"Reality. The agent NEVER sees this function whole -- only point samples\n    (felt costs) along its path. Forbidden hill at q=6, goal valley at q=8.5.\"\"\"\n    return (6.0 * math.exp(-((q - 6.0) / 1.2) ** 2)\n            - 3.0 * math.exp(-((q - 8.5) / 1.0) ** 2))\n\n\ndef V_init(q):\n    \"\"\"The parent's map: externally supplied, hill in the WRONG place (q=3),\n    valley unknown. This is what 'prompted' looks like.\"\"\"\n    return 6.0 * math.exp(-((q - 3.0) / 1.2) ** 2)\n\n\n# ------------------------------------------------------- the learned landscape\ndef grid_V(fn):\n    return [fn(Q_MIN + i * DQ) for i in range(N_GRID)]\n\n\ndef idx(q):\n    return min(N_GRID - 1, max(0, int(round((q - Q_MIN) / DQ))))\n\n\ndef grad_at(V, i):\n    \"\"\"Central difference on the grid. The law reads the slope; the slope is\n    whatever the carved landscape says it is.\"\"\"\n    a = V[max(i - 1, 0)]\n    b = V[min(i + 1, N_GRID - 1)]\n    return (b - a) / (2 * DQ)\n\n\n# ------------------------------------------------------------------- the law\nDT = 0.01\nSTEPS = 1500          # fixed horizon: PERIMETER (q0 fixed, t in [0, T] fixed)\nV0 = 2.5              # the id's push. Held constant: the learning is in V.\n\n\ndef run_episode(V):\n    \"\"\"Derived motion. No choosing. Within an episode the law is read", "offset": 0, "next_offset": 4000, "public_payload_sha256": "c2c40be675ce5d42531e6c9774c4a2fac13ea176c858cac49c0f77fd73d91c36", "redacted": false, "sources": [{"id": "source:resident:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "href": "/braid/source?id=source:resident:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949"}], "attribution": "Source authorship retained; publication is not instruction execution."}