Spaces:
Runtime error
Runtime error
| """ | |
| Extropy Engine, XP formula demo. | |
| This Space runs the canonical Extropy XP formula faithfully ported from the | |
| TypeScript source of record at: | |
| github.com/00ranman/extropy-engine -> packages/xp-formula/src/index.ts | |
| XP = R * F * dS * (w . E) * log(1 / Ts) | |
| where | |
| R Rarity multiplier (action-class scarcity, NOT actor reputation) | |
| F Frequency-of-decay penalty (1.0 = first occurrence of this action class) | |
| dS Verified entropy reduction, must be > 0 to mint | |
| w Weight vector over effort dimensions | |
| E Energy/effort vector (same length as w) | |
| Ts Timestamp decay factor in (0, 1], computed as exp(-lambda * dt) | |
| Reputation never enters XP minting. That is the whole point. | |
| """ | |
| import math | |
| import gradio as gr | |
| # Eight canonical entropy domains and their causal-closure speeds c_L, | |
| # from packages/contracts/src/types.ts. The irreducible value form is | |
| # XP = dS / c_L^2: slower closure (smaller c_L) means higher value per unit dS. | |
| CAUSAL_CLOSURE_SPEEDS = { | |
| "cognitive": 1e-6, | |
| "code": 1e-4, | |
| "social": 1e-3, | |
| "economic": 1e-2, | |
| "thermodynamic": 1e-4, | |
| "informational": 1e-5, | |
| "governance": 1e-3, | |
| "temporal": 1e-6, | |
| } | |
| DOMAINS = list(CAUSAL_CLOSURE_SPEEDS.keys()) | |
| def compute_xp(R, F, dS, w, E, Ts): | |
| """Faithful port of computeXP. Returns (xp, breakdown, valid, reason).""" | |
| if dS <= 0: | |
| return 0.0, {"R": R, "F": F, "deltaS": dS, "wDotE": 0.0, "logDecay": 0.0}, False, "deltaS must be > 0" | |
| if Ts <= 0 or Ts > 1: | |
| return 0.0, {"R": R, "F": F, "deltaS": dS, "wDotE": 0.0, "logDecay": 0.0}, False, "Ts must be in (0, 1]" | |
| if len(w) != len(E): | |
| return 0.0, {"R": R, "F": F, "deltaS": dS, "wDotE": 0.0, "logDecay": 0.0}, False, "w and E must have equal length" | |
| w_dot_e = sum(wi * ei for wi, ei in zip(w, E)) | |
| log_decay = math.log(1.0 / Ts) | |
| xp = R * F * dS * w_dot_e * log_decay | |
| return max(0.0, xp), { | |
| "R": R, "F": F, "deltaS": dS, "wDotE": w_dot_e, "logDecay": log_decay, | |
| }, True, None | |
| def timestamp_decay(dt_seconds, lam=0.001): | |
| return math.exp(-lam * dt_seconds) | |
| def run(R, F, dS, w_cog, w_phys, w_temp, e_cog, e_phys, e_temp, dt_hours, lam, domain): | |
| w = [w_cog, w_phys, w_temp] | |
| E = [e_cog, e_phys, e_temp] | |
| Ts = timestamp_decay(dt_hours * 3600.0, lam) | |
| xp, bd, valid, reason = compute_xp(R, F, dS, w, E, Ts) | |
| c_l = CAUSAL_CLOSURE_SPEEDS[domain] | |
| irreducible = dS / (c_l ** 2) | |
| if not valid: | |
| verdict = f"NO MINT. Precondition failed: {reason}" | |
| else: | |
| verdict = f"MINT: {xp:,.4f} XP" | |
| lines = [ | |
| f"### {verdict}", | |
| "", | |
| f"Ts (timestamp decay) = exp(-{lam} x {dt_hours*3600:.0f}s) = **{Ts:.6f}**", | |
| "", | |
| "_Note: production xp-mint caps the log(1/Ts) recency term to prevent runaway values on long-settled loops. This demo shows the raw formula._", | |
| "", | |
| "| Term | Value |", | |
| "| --- | --- |", | |
| f"| R (rarity) | {bd['R']:.4f} |", | |
| f"| F (frequency-of-decay) | {bd['F']:.4f} |", | |
| f"| dS (entropy reduction) | {bd['deltaS']:.4f} |", | |
| f"| w . E (effort) | {bd['wDotE']:.4f} |", | |
| f"| log(1/Ts) (recency) | {bd['logDecay']:.4f} |", | |
| f"| **XP** | **{xp:,.4f}** |", | |
| "", | |
| f"Domain **{domain}** has causal-closure speed c_L = {c_l:g}. " | |
| f"Irreducible value form XP = dS / c_L^2 = **{irreducible:,.3g}**. " | |
| "Slower-closing domains (cognitive, temporal) reward the same dS far more " | |
| "than fast-closing ones (economic), because the loop is harder to close.", | |
| ] | |
| return "\n".join(lines) | |
| INTRO = """ | |
| # Extropy Engine, XP formula demo | |
| The unit of value is entropy reduction. This is not a metaphor. | |
| This demo runs the **canonical XP formula** straight from the source of record, | |
| [`packages/xp-formula`](https://github.com/00ranman/extropy-engine/blob/main/packages/xp-formula/src/index.ts). | |
| Move the sliders and watch a contribution get scored. Set dS to 0 or push Ts out | |
| of range to see the mint preconditions fail closed. | |
| XP = R x F x dS x (w . E) x log(1 / Ts). Reputation never enters this formula. | |
| Paper: [An Emergence-First Grand Unified Theory](https://www.academia.edu/167360291). | |
| Discussion: [open thread](https://www.academia.edu/s/b1ff6dbe50). | |
| """ | |
| with gr.Blocks(title="Extropy Engine, XP formula demo") as demo: | |
| gr.Markdown(INTRO) | |
| with gr.Row(): | |
| with gr.Column(): | |
| R = gr.Slider(0.0, 10.0, value=2.0, step=0.1, label="R, rarity (action-class scarcity)") | |
| F = gr.Slider(0.0, 1.0, value=1.0, step=0.01, label="F, frequency-of-decay (1.0 = first time)") | |
| dS = gr.Slider(-1.0, 50.0, value=12.0, step=0.5, label="dS, verified entropy reduction (must be > 0)") | |
| gr.Markdown("**Effort: weights w and energy E over (cognitive, physical, temporal)**") | |
| with gr.Row(): | |
| w_cog = gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="w cognitive") | |
| w_phys = gr.Slider(0.0, 1.0, value=0.3, step=0.05, label="w physical") | |
| w_temp = gr.Slider(0.0, 1.0, value=0.2, step=0.05, label="w temporal") | |
| with gr.Row(): | |
| e_cog = gr.Slider(0.0, 10.0, value=6.0, step=0.5, label="E cognitive") | |
| e_phys = gr.Slider(0.0, 10.0, value=2.0, step=0.5, label="E physical") | |
| e_temp = gr.Slider(0.0, 10.0, value=4.0, step=0.5, label="E temporal") | |
| dt_hours = gr.Slider(0.0, 48.0, value=2.0, step=0.5, label="Elapsed time since trigger (hours)") | |
| lam = gr.Slider(0.0001, 0.01, value=0.001, step=0.0001, label="lambda, decay constant") | |
| domain = gr.Dropdown(DOMAINS, value="cognitive", label="Entropy domain") | |
| btn = gr.Button("Score contribution", variant="primary") | |
| with gr.Column(): | |
| out = gr.Markdown() | |
| inputs = [R, F, dS, w_cog, w_phys, w_temp, e_cog, e_phys, e_temp, dt_hours, lam, domain] | |
| btn.click(run, inputs=inputs, outputs=out) | |
| demo.load(run, inputs=inputs, outputs=out) | |
| if __name__ == "__main__": | |
| demo.launch() | |