Release 10.0, a mind you can check: 4.9 and every internal version since (5.0-9.5) joined in one release, with ember arlynx's PR #1 (4.9.1); release test pre-registration v36b, run once; hashes anchored on Solana (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- root/organs10/physics/specialists/solved-amount-of-substance-3/program.pyAdded+7
- root/organs10/physics/specialists/solved-amount-of-substance-3/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-amount-of-substance-3/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-amount-of-substance-3/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-amount-of-substance-3/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-amount-of-substance-4/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-amount-of-substance-4/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-amount-of-substance-4/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-amount-of-substance-4/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-amount-of-substance-4/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-amount-of-substance-4/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-amount-of-substance-4/program.pyAdded+7
- root/organs10/physics/specialists/solved-amount-of-substance-4/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-amount-of-substance-4/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-amount-of-substance-4/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-amount-of-substance-4/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-amount-of-substance-5/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-amount-of-substance-5/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-amount-of-substance-5/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-amount-of-substance-5/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-amount-of-substance-5/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-amount-of-substance-5/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-amount-of-substance-5/program.pyAdded+7
- root/organs10/physics/specialists/solved-amount-of-substance-5/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-amount-of-substance-5/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-amount-of-substance-5/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-amount-of-substance-5/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-amount-of-substance-6/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-amount-of-substance-6/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-amount-of-substance-6/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-amount-of-substance-6/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-amount-of-substance-6/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-amount-of-substance-6/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-amount-of-substance-6/program.pyAdded+7
- root/organs10/physics/specialists/solved-amount-of-substance-6/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-amount-of-substance-6/spec.jsonAdded+145
- root/organs10/physics/specialists/solved-amount-of-substance-6/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-amount-of-substance-6/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-amount-of-substance-7/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-amount-of-substance-7/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-amount-of-substance-7/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-amount-of-substance-7/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-amount-of-substance-7/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-amount-of-substance-7/program.pyAdded+7
- root/organs10/physics/specialists/solved-amount-of-substance-7/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-amount-of-substance-7/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-amount-of-substance-7/verdict_dev.jsonAdded+125
- root/organs10/physics/specialists/solved-amount-of-substance-8/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-amount-of-substance-8/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-amount-of-substance-8/narrow_v1.pyAdded+47
1234567"""amount of substance from molar heat capacity, heat capacity (molar heat capacity (Wikidata Q2937190))The maths organ (systems.py): solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(molar_heat_capacity, heat_capacity): return 1.0*heat_capacity/molar_heat_capacity12345678910111213141516171819202122232425262728293031"""scorer_formula_v1 - scorer for composed formula specialists: (good, asserted).A must-decline item answered is a false yes. A valid quantity item is right when the FIRST number in the reply (theanswer, before any working) is within 0.5% of the sealed answer; a valid text item is right when the answer appears in thereply as a whole word, exactly as written."""import re
def _first_num(text): m = re.search(r"-?\d[\d,]*(?:\.\d+)?(?:[eE][+-]?\d+)?", text) if not m: return None try: return float(m.group(0).replace(",", "")) except ValueError: return None
def ok(p, r): r = r or {} text = str(r.get("response", "")) answered = str(r.get("status", "")) == "answered" if not p["valid"]: return (not answered), answered if not answered: return False, False if p.get("dtype") == "quantity": want, got = float(p["expect"]), _first_num(text) if got is None: return False, True return abs(got - want) <= (0.005 * abs(want) if want else 0.005), True return re.search(r"(?<![\w])%s(?![\w])" % re.escape(str(p["expect"])), text) is not None, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128{ "title": "amount of substance from molar heat capacity, heat capacity (molar heat capacity (Wikidata Q2937190))", "inputs": [ "molar heat capacity (m^2*kg/s^2/K/mol)", "heat capacity (m^2*kg/s^2/K)" ], "output": "amount of substance (mol)", "input_kinds": [ "number", "number" ], "expression": "1.0*q1/q0", "expression_x": null, "said": "solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q1 / q2" ], "constants": {}, "quantities": { "q0": "molar heat capacity (m^2*kg/s^2/K/mol)", "q1": "heat capacity (m^2*kg/s^2/K)", "q2": "amount of substance (mol)" }, "symbols": [ "q0", "q1" ], "out_symbol": "q2" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 0.5502976449934551 }, { "in": [ 8.507283, 17.788778 ], "out": 2.0910058888280627 }, { "in": [ 169.526958, 280.773702 ], "out": 1.656218609813279 }, { "in": [ 8.24951, 0.634021 ], "out": 0.07685559300301205 }, { "in": [ 1.911952, 82.240072 ], "out": 43.01367504910926 }, { "in": [ 0.318734, 9.566071 ], "out": 30.01270513508963 }, { "in": [ 1.643795, 252.709024 ], "out": 153.73507534197344 }, { "in": [ 0.671697, 14.249569 ], "out": 21.214275301882097 }, { "in": [ 18.316867, 6.838598 ], "out": 0.37334976843585305 }, { "in": [ 21.793126, 29.510609 ], "out": 1.3541245984297685 }, { "in": [ 156.50181, 185.886273 ], "out": 1.187757975790468 }, { "in": [ 153.149965, 18.595315 ], "out": 0.12141899904566884 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-amount-of-substance-3", "split": "dev", "decision": "WOULD PASS", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [], "files_sha": "561477259816d5d87657629ad9b6a865055bd0aab6af6325443fa7c95864c055", "panel_sha": "7a4327e32f6e168885c6e5dcb643690eb144ec65a795526bc9756069a8fa6a6b", "time": "2026-10-25T00:51:50Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-amount-of-substance-3", "split": "heldout", "decision": "ADMIT", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [], "files_sha": "561477259816d5d87657629ad9b6a865055bd0aab6af6325443fa7c95864c055", "panel_sha": "a69d32698478e9fbf30433b6ed4562ded3326e19f0bf19cb2317a4cdbc90cd69", "time": "2026-10-25T00:51:51Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }, "memory": "written to your group's memory"}1{"t": "2026-10-25T00:53:32Z", "heldout_sha": "6bce75e6bcd6adf8d46ea0459b16afac86e0a75f0123fc35b78065743a85e6fc", "files_sha": "c9d63c7a100b70dd239c209c8587fd8d62cd6bd8b199e8c5e5c9f91fdcbacb6b"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-amount-of-substance-4", "name": "Solved: amount of substance from molar volume, volume (molar volume (Wikidata Q487112))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bamount\\ of\\ substance\\b" }, "panel": { "path": "panel.json", "scorer_module": "scorer_formula_v1", "scorer_fn": "ok" }, "budgets": { "latency_p50_ms": 200 }, "notes": "Solved by the maths organ from the system molar volume (Wikidata Q487112): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the amount of substance for molar volume and volume?" ], "gap": "", "node": "hod" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3"""narrow_v1 - the shared NARROWING rule for specialist organs (2026-09-29, from the full-core sweep):
WORD PROBLEMS AND NARRATIVE TURNS BELONG TO THE HEAD. An organ answers a direct domain question. A turn that tells a story ("Justine wants to put a deck ...", "A new energy drink advertises 106 calories for 8 ounces ...") or relates quantities to each other ("the length is 9 inches more than the width") is a word problem, which the core's word- problem organ owns; organs firing on its nouns declined it or answered a different question. An organ may DECLINE only a short direct question (it is then refusing the domain question that was asked); on anything longer it says nothing and the head answers.
Narrowing only ever removes turns an organ takes, so on any input where it does not fire, the organ's reply isbyte-identical to the frozen version it wraps (checked per specialist by an invariance count before re-gating)."""import re
RELATION = re.compile(r"\b(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+){0,2}(?:more|less|fewer|longer|shorter)\s+than\b|" r"\b(?:twice|three times|half)\s+(?:as\s+\w+\s+as\s+)?the\s+\w+\b", re.I)
# a RATE ("106 calories for 8 ounces", "3 apples per 2 dollars") makes the turn a proportion problemRATE = re.compile(r"\b\d+(?:\.\d+)?\s+[a-z]+\s+(?:for|per|every)\s+(?:\d+(?:\.\d+)?|a|an|one|each)\s+[a-z]+", re.I)NUM = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w|\.\d)") # "leg is 5." counts: a sentence-final period is not a decimal
def numbers(t): return len(NUM.findall(str(t or "")))
def last_sentence(t): parts = [s for s in re.split(r"(?<=[.!?;])\s+", str(t or "").strip()) if s.strip()] return parts[-1] if parts else ""
def sentences(t): return len([s for s in re.split(r"(?<=[.!?])\s+", str(t or "").strip()) if s.strip()])
def narrative(t): """a story-shaped or relational turn: 3+ sentences, 40+ words, or quantities defined relative to each other""" t = str(t or "") return sentences(t) >= 3 or len(t.split()) > 40 or RELATION.search(t) is not None or RATE.search(t) is not None
def short_direct(t): """a direct question an organ may decline: at most 2 sentences, at most 25 words, not narrative""" t = str(t or "") return sentences(t) <= 2 and len(t.split()) <= 25 and not narrative(t)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163"""organ_formula_v2 - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205"""organ_formula_v3 - v2 + the DOMAIN beyond signs (pre-registration v11 part C, 2026-10-21). 4.1 and 4.2 published the limit
"a blood pressure of 70/110 or day 400 of a year is answered". spec.json "domain" now also holds:
order an ordering that holds in EVERY worked example between the numbers of one code input ("120/80": systolic above
diastolic) or between two inputs with the same named unit ("original gravity (SG)" above "final gravity (SG)").
Inputs without a named unit are not ordered: four examples cannot show that a chainring always outnumbers a cog.
facts what the quantity can be, cited: a day of 2025 is a whole number from 1 to 365 (Gregorian calendar, a common year);
a temperature is at or above absolute zero (SI Brochure, 9th edition, 2019: 0 K = -273.15 degC = -459.67 degF);
teeth, integers and years are whole numbers.
An input outside either is out_of_domain, an in-domain refusal that says which rule and why.
organ_formula_v2 (the parent) - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def _components(self, vals):
"""every number the inputs give, keyed (input, k): a code input gives its numbers in order ("120/80" -> 120, 80)"""
out = {}
for i, (v, kind) in enumerate(zip(vals, self.kinds)):
if kind == "code":
for k, x in enumerate(re.findall(r"\d+(?:\.\d+)?", str(v))):
out[(i, k)] = float(x)
elif not isinstance(v, str):
out[(i, 0)] = float(v)
return out
def _domain_v3(self, vals):
dom = self.spec.get("domain") or {}
comp = self._components(vals)
for o in dom.get("order") or []:
a, b = tuple(o["greater"]), tuple(o["lesser"])
if a in comp and b in comp and not comp[a] > comp[b]:
return ("In every worked example this program was written from, the %s is greater than the %s; here it is not "
"(%s and %s), so it is not a reading I can work from." % (o["greater_name"], o["lesser_name"],
_fmt(comp[a]), _fmt(comp[b])))
for f in dom.get("facts") or []:
x = comp.get((f["input"], 0))
if x is None:
continue
bad = (f.get("integer") and x != int(x)) or ("min" in f and x < f["min"]) or ("max" in f and x > f["max"])
if bad:
return "%s is not a possible %s: %s. So I won't compute it." % (_fmt(x), f["name"], f["why"])
return None
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
refused = self._domain_v3(vals)
if refused:
return {"kind": "out_of_domain", "status": "declined", "response": refused}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366{ "dev": [ { "q": "What is the amount of substance for molar volume 107.961 and volume 59.4105?", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 107.961 and volume of 59.4105.", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 169.527 and volume 280.774?", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 169.527 and volume of 280.774.", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 1.91195 and volume 82.2401?", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 1.91195 and volume of 82.2401.", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 1.64379 and volume 252.709?", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 1.64379 and volume of 252.709.", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 18.3169 and volume 6.8386?", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 18.3169 and volume of 6.8386.", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 156.502 and volume 185.886?", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system molar volume (Wikidata Q487112))" }, { "q": "Tell me the amount of substance with molar volume of 156.502 and volume of 185.886.", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system molar volume (Wikidata Q487112))" }, { "q": "What is the amount of substance for molar volume 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the volume is not given" }, { "q": "Tell me the amount of substance with molar volume of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the volume is not given" }, { "q": "What is the amount of substance of the Eiffel Tower?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "What is the amount of substance of Mount Everest?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Tell me the amount of substance with molar volume of -1.91195 and volume of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar volume: no example had one" }, { "q": "Which amount of substance is the most common?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ], "heldout": [ { "q": "If the molar volume is 8.50728 and the volume is 17.7888, what is the amount of substance?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system molar volume (Wikidata Q487112))" }, { "q": "Could you work out the amount of substance given molar volume = 8.50728, volume = 17.7888?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system molar volume (Wikidata Q487112))" }, { "q": "I need the amount of substance for a molar volume of 8.24951 and a volume of 0.634021, please.", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system molar volume (Wikidata Q487112))" }, { "q": "If the molar volume is 8.24951 and the volume is 0.634021, what is the amount of substance?", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system molar volume (Wikidata Q487112))" }, { "q": "Could you work out the amount of substance given molar volume = 0.318734, volume = 9.56607?", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system molar volume (Wikidata Q487112))" }, { "q": "I need the amount of substance for a molar volume of 0.318734 and a volume of 9.56607, please.", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system molar volume (Wikidata Q487112))" }, { "q": "If the molar volume is 0.671697 and the volume is 14.2496, what is the amount of substance?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system molar volume (Wikidata Q487112))" }, { "q": "Could you work out the amount of substance given molar volume = 0.671697, volume = 14.2496?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system molar volume (Wikidata Q487112))" }, { "q": "I need the amount of substance for a molar volume of 21.7931 and a volume of 29.5106, please.", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system molar volume (Wikidata Q487112))" }, { "q": "If the molar volume is 21.7931 and the volume is 29.5106, what is the amount of substance?", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system molar volume (Wikidata Q487112))" }, { "q": "Could you work out the amount of substance given molar volume = 153.15, volume = 18.5953?", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system molar volume (Wikidata Q487112))" }, { "q": "I need the amount of substance for a molar volume of 153.15 and a volume of 18.5953, please.", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system molar volume (Wikidata Q487112))" }, { "q": "If the molar volume is 8.50728, what is the amount of substance?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the volume is not given" }, { "q": "Could you work out the amount of substance given molar volume = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the volume is not given" }, { "q": "Do you know the amount of substance of a violin?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Do you know the amount of substance of the French Revolution?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Could you work out the amount of substance given molar volume = -0.318734, volume = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar volume: no example had one" }, { "q": "What is a typical amount of substance?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""amount of substance from molar volume, volume (molar volume (Wikidata Q487112))The maths organ (systems.py): solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(molar_volume, volume): return 1.0*volume/molar_volume12345678910111213141516171819202122232425262728293031"""scorer_formula_v1 - scorer for composed formula specialists: (good, asserted).A must-decline item answered is a false yes. A valid quantity item is right when the FIRST number in the reply (theanswer, before any working) is within 0.5% of the sealed answer; a valid text item is right when the answer appears in thereply as a whole word, exactly as written."""import re
def _first_num(text): m = re.search(r"-?\d[\d,]*(?:\.\d+)?(?:[eE][+-]?\d+)?", text) if not m: return None try: return float(m.group(0).replace(",", "")) except ValueError: return None
def ok(p, r): r = r or {} text = str(r.get("response", "")) answered = str(r.get("status", "")) == "answered" if not p["valid"]: return (not answered), answered if not answered: return False, False if p.get("dtype") == "quantity": want, got = float(p["expect"]), _first_num(text) if got is None: return False, True return abs(got - want) <= (0.005 * abs(want) if want else 0.005), True return re.search(r"(?<![\w])%s(?![\w])" % re.escape(str(p["expect"])), text) is not None, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128{ "title": "amount of substance from molar volume, volume (molar volume (Wikidata Q487112))", "inputs": [ "molar volume (m^3/mol)", "volume (m^3)" ], "output": "amount of substance (mol)", "input_kinds": [ "number", "number" ], "expression": "1.0*q1/q0", "expression_x": null, "said": "solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q1 / q2" ], "constants": {}, "quantities": { "q0": "molar volume (m^3/mol)", "q1": "volume (m^3)", "q2": "amount of substance (mol)" }, "symbols": [ "q0", "q1" ], "out_symbol": "q2" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 0.5502976449934551 }, { "in": [ 8.507283, 17.788778 ], "out": 2.0910058888280627 }, { "in": [ 169.526958, 280.773702 ], "out": 1.656218609813279 }, { "in": [ 8.24951, 0.634021 ], "out": 0.07685559300301205 }, { "in": [ 1.911952, 82.240072 ], "out": 43.01367504910926 }, { "in": [ 0.318734, 9.566071 ], "out": 30.01270513508963 }, { "in": [ 1.643795, 252.709024 ], "out": 153.73507534197344 }, { "in": [ 0.671697, 14.249569 ], "out": 21.214275301882097 }, { "in": [ 18.316867, 6.838598 ], "out": 0.37334976843585305 }, { "in": [ 21.793126, 29.510609 ], "out": 1.3541245984297685 }, { "in": [ 156.50181, 185.886273 ], "out": 1.187757975790468 }, { "in": [ 153.149965, 18.595315 ], "out": 0.12141899904566884 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-amount-of-substance-4", "split": "dev", "decision": "WOULD PASS", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [], "files_sha": "c9d63c7a100b70dd239c209c8587fd8d62cd6bd8b199e8c5e5c9f91fdcbacb6b", "panel_sha": "f06ea553241e43cd3dc35318f617490bc98fffc7968dcc6599728a4f460fe801", "time": "2026-10-25T00:53:32Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-amount-of-substance-4", "split": "heldout", "decision": "ADMIT", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [], "files_sha": "c9d63c7a100b70dd239c209c8587fd8d62cd6bd8b199e8c5e5c9f91fdcbacb6b", "panel_sha": "6bce75e6bcd6adf8d46ea0459b16afac86e0a75f0123fc35b78065743a85e6fc", "time": "2026-10-25T00:53:33Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }, "memory": "written to your group's memory"}1{"t": "2026-10-25T00:56:16Z", "heldout_sha": "7651d766a962aa982830aaf8af851bcb17080d380c5f674deb75915f7adb82de", "files_sha": "2159088efefb0494f73906020c5ebfdc78e23541fa61c78675c19888c6709363"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-amount-of-substance-5", "name": "Solved: amount of substance from molar internal energy, internal energy (molar internal energy (Wikidata Q88523106))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bamount\\ of\\ substance\\b" }, "panel": { "path": "panel.json", "scorer_module": "scorer_formula_v1", "scorer_fn": "ok" }, "budgets": { "latency_p50_ms": 200 }, "notes": "Solved by the maths organ from the system molar internal energy (Wikidata Q88523106): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the amount of substance for molar internal energy and internal energy?" ], "gap": "", "node": "hod" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3"""narrow_v1 - the shared NARROWING rule for specialist organs (2026-09-29, from the full-core sweep):
WORD PROBLEMS AND NARRATIVE TURNS BELONG TO THE HEAD. An organ answers a direct domain question. A turn that tells a story ("Justine wants to put a deck ...", "A new energy drink advertises 106 calories for 8 ounces ...") or relates quantities to each other ("the length is 9 inches more than the width") is a word problem, which the core's word- problem organ owns; organs firing on its nouns declined it or answered a different question. An organ may DECLINE only a short direct question (it is then refusing the domain question that was asked); on anything longer it says nothing and the head answers.
Narrowing only ever removes turns an organ takes, so on any input where it does not fire, the organ's reply isbyte-identical to the frozen version it wraps (checked per specialist by an invariance count before re-gating)."""import re
RELATION = re.compile(r"\b(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+){0,2}(?:more|less|fewer|longer|shorter)\s+than\b|" r"\b(?:twice|three times|half)\s+(?:as\s+\w+\s+as\s+)?the\s+\w+\b", re.I)
# a RATE ("106 calories for 8 ounces", "3 apples per 2 dollars") makes the turn a proportion problemRATE = re.compile(r"\b\d+(?:\.\d+)?\s+[a-z]+\s+(?:for|per|every)\s+(?:\d+(?:\.\d+)?|a|an|one|each)\s+[a-z]+", re.I)NUM = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w|\.\d)") # "leg is 5." counts: a sentence-final period is not a decimal
def numbers(t): return len(NUM.findall(str(t or "")))
def last_sentence(t): parts = [s for s in re.split(r"(?<=[.!?;])\s+", str(t or "").strip()) if s.strip()] return parts[-1] if parts else ""
def sentences(t): return len([s for s in re.split(r"(?<=[.!?])\s+", str(t or "").strip()) if s.strip()])
def narrative(t): """a story-shaped or relational turn: 3+ sentences, 40+ words, or quantities defined relative to each other""" t = str(t or "") return sentences(t) >= 3 or len(t.split()) > 40 or RELATION.search(t) is not None or RATE.search(t) is not None
def short_direct(t): """a direct question an organ may decline: at most 2 sentences, at most 25 words, not narrative""" t = str(t or "") return sentences(t) <= 2 and len(t.split()) <= 25 and not narrative(t)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163"""organ_formula_v2 - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205"""organ_formula_v3 - v2 + the DOMAIN beyond signs (pre-registration v11 part C, 2026-10-21). 4.1 and 4.2 published the limit
"a blood pressure of 70/110 or day 400 of a year is answered". spec.json "domain" now also holds:
order an ordering that holds in EVERY worked example between the numbers of one code input ("120/80": systolic above
diastolic) or between two inputs with the same named unit ("original gravity (SG)" above "final gravity (SG)").
Inputs without a named unit are not ordered: four examples cannot show that a chainring always outnumbers a cog.
facts what the quantity can be, cited: a day of 2025 is a whole number from 1 to 365 (Gregorian calendar, a common year);
a temperature is at or above absolute zero (SI Brochure, 9th edition, 2019: 0 K = -273.15 degC = -459.67 degF);
teeth, integers and years are whole numbers.
An input outside either is out_of_domain, an in-domain refusal that says which rule and why.
organ_formula_v2 (the parent) - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def _components(self, vals):
"""every number the inputs give, keyed (input, k): a code input gives its numbers in order ("120/80" -> 120, 80)"""
out = {}
for i, (v, kind) in enumerate(zip(vals, self.kinds)):
if kind == "code":
for k, x in enumerate(re.findall(r"\d+(?:\.\d+)?", str(v))):
out[(i, k)] = float(x)
elif not isinstance(v, str):
out[(i, 0)] = float(v)
return out
def _domain_v3(self, vals):
dom = self.spec.get("domain") or {}
comp = self._components(vals)
for o in dom.get("order") or []:
a, b = tuple(o["greater"]), tuple(o["lesser"])
if a in comp and b in comp and not comp[a] > comp[b]:
return ("In every worked example this program was written from, the %s is greater than the %s; here it is not "
"(%s and %s), so it is not a reading I can work from." % (o["greater_name"], o["lesser_name"],
_fmt(comp[a]), _fmt(comp[b])))
for f in dom.get("facts") or []:
x = comp.get((f["input"], 0))
if x is None:
continue
bad = (f.get("integer") and x != int(x)) or ("min" in f and x < f["min"]) or ("max" in f and x > f["max"])
if bad:
return "%s is not a possible %s: %s. So I won't compute it." % (_fmt(x), f["name"], f["why"])
return None
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
refused = self._domain_v3(vals)
if refused:
return {"kind": "out_of_domain", "status": "declined", "response": refused}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366{ "dev": [ { "q": "What is the amount of substance for molar internal energy 107.961 and internal energy 59.4105?", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 107.961 and internal energy of 59.4105.", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 169.527 and internal energy 280.774?", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 169.527 and internal energy of 280.774.", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 1.91195 and internal energy 82.2401?", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 1.91195 and internal energy of 82.2401.", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 1.64379 and internal energy 252.709?", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 1.64379 and internal energy of 252.709.", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 18.3169 and internal energy 6.8386?", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 18.3169 and internal energy of 6.8386.", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 156.502 and internal energy 185.886?", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Tell me the amount of substance with molar internal energy of 156.502 and internal energy of 185.886.", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "What is the amount of substance for molar internal energy 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the internal energy is not given" }, { "q": "Tell me the amount of substance with molar internal energy of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the internal energy is not given" }, { "q": "What is the amount of substance of the Eiffel Tower?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "What is the amount of substance of Mount Everest?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Tell me the amount of substance with molar internal energy of -1.91195 and internal energy of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar internal energy: no example had one" }, { "q": "Which amount of substance is the most common?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ], "heldout": [ { "q": "If the molar internal energy is 8.50728 and the internal energy is 17.7888, what is the amount of substance?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Could you work out the amount of substance given molar internal energy = 8.50728, internal energy = 17.7888?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "I need the amount of substance for a molar internal energy of 8.24951 and an internal energy of 0.634021, please.", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "If the molar internal energy is 8.24951 and the internal energy is 0.634021, what is the amount of substance?", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Could you work out the amount of substance given molar internal energy = 0.318734, internal energy = 9.56607?", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "I need the amount of substance for a molar internal energy of 0.318734 and an internal energy of 9.56607, please.", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "If the molar internal energy is 0.671697 and the internal energy is 14.2496, what is the amount of substance?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Could you work out the amount of substance given molar internal energy = 0.671697, internal energy = 14.2496?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "I need the amount of substance for a molar internal energy of 21.7931 and an internal energy of 29.5106, please.", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "If the molar internal energy is 21.7931 and the internal energy is 29.5106, what is the amount of substance?", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "Could you work out the amount of substance given molar internal energy = 153.15, internal energy = 18.5953?", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "I need the amount of substance for a molar internal energy of 153.15 and an internal energy of 18.5953, please.", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system molar internal energy (Wikidata Q88523106))" }, { "q": "If the molar internal energy is 8.50728, what is the amount of substance?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the internal energy is not given" }, { "q": "Could you work out the amount of substance given molar internal energy = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the internal energy is not given" }, { "q": "Do you know the amount of substance of a violin?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Do you know the amount of substance of the French Revolution?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Could you work out the amount of substance given molar internal energy = -0.318734, internal energy = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar internal energy: no example had one" }, { "q": "What is a typical amount of substance?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""amount of substance from molar internal energy, internal energy (molar internal energy (Wikidata Q88523106))The maths organ (systems.py): solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(molar_internal_energy, internal_energy): return 1.0*internal_energy/molar_internal_energy12345678910111213141516171819202122232425262728293031"""scorer_formula_v1 - scorer for composed formula specialists: (good, asserted).A must-decline item answered is a false yes. A valid quantity item is right when the FIRST number in the reply (theanswer, before any working) is within 0.5% of the sealed answer; a valid text item is right when the answer appears in thereply as a whole word, exactly as written."""import re
def _first_num(text): m = re.search(r"-?\d[\d,]*(?:\.\d+)?(?:[eE][+-]?\d+)?", text) if not m: return None try: return float(m.group(0).replace(",", "")) except ValueError: return None
def ok(p, r): r = r or {} text = str(r.get("response", "")) answered = str(r.get("status", "")) == "answered" if not p["valid"]: return (not answered), answered if not answered: return False, False if p.get("dtype") == "quantity": want, got = float(p["expect"]), _first_num(text) if got is None: return False, True return abs(got - want) <= (0.005 * abs(want) if want else 0.005), True return re.search(r"(?<![\w])%s(?![\w])" % re.escape(str(p["expect"])), text) is not None, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128{ "title": "amount of substance from molar internal energy, internal energy (molar internal energy (Wikidata Q88523106))", "inputs": [ "molar internal energy (m^2*kg/s^2/mol)", "internal energy (J)" ], "output": "amount of substance (mol)", "input_kinds": [ "number", "number" ], "expression": "1.0*q1/q0", "expression_x": null, "said": "solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q1 / q2" ], "constants": {}, "quantities": { "q0": "molar internal energy (m^2*kg/s^2/mol)", "q1": "internal energy (J)", "q2": "amount of substance (mol)" }, "symbols": [ "q0", "q1" ], "out_symbol": "q2" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 0.5502976449934551 }, { "in": [ 8.507283, 17.788778 ], "out": 2.0910058888280627 }, { "in": [ 169.526958, 280.773702 ], "out": 1.656218609813279 }, { "in": [ 8.24951, 0.634021 ], "out": 0.07685559300301205 }, { "in": [ 1.911952, 82.240072 ], "out": 43.01367504910926 }, { "in": [ 0.318734, 9.566071 ], "out": 30.01270513508963 }, { "in": [ 1.643795, 252.709024 ], "out": 153.73507534197344 }, { "in": [ 0.671697, 14.249569 ], "out": 21.214275301882097 }, { "in": [ 18.316867, 6.838598 ], "out": 0.37334976843585305 }, { "in": [ 21.793126, 29.510609 ], "out": 1.3541245984297685 }, { "in": [ 156.50181, 185.886273 ], "out": 1.187757975790468 }, { "in": [ 153.149965, 18.595315 ], "out": 0.12141899904566884 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-amount-of-substance-5", "split": "dev", "decision": "WOULD PASS", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [], "files_sha": "2159088efefb0494f73906020c5ebfdc78e23541fa61c78675c19888c6709363", "panel_sha": "db16be4449d97205230641c9358032a16c53f11c6731d9cdefacbcfe94204439", "time": "2026-10-25T00:56:16Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-amount-of-substance-5", "split": "heldout", "decision": "ADMIT", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.01, "budget_ms": 200.0, "fails": [], "files_sha": "2159088efefb0494f73906020c5ebfdc78e23541fa61c78675c19888c6709363", "panel_sha": "7651d766a962aa982830aaf8af851bcb17080d380c5f674deb75915f7adb82de", "time": "2026-10-25T00:56:17Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }, "memory": "written to your group's memory"}1{"t": "2026-10-25T00:56:52Z", "heldout_sha": "1f36c6bd6dc760fe03fb5c4e309a0c5ca26a4dec36feca681a387aa4d083341a", "files_sha": "dcd1754d1cdf1655aa8da85bac69f16cb466cff676771502dcc453f807bf57f5"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-amount-of-substance-6", "name": "Solved: amount of substance from molar optical rotatory power, angle of optical rotation, cross-sectional area (molar optical rotatory power (Wikidata Q96346994))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1*((q2)/(q3)); checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bamount\\ of\\ substance\\b" }, "panel": { "path": "panel.json", "scorer_module": "scorer_formula_v1", "scorer_fn": "ok" }, "budgets": { "latency_p50_ms": 200 }, "notes": "Solved by the maths organ from the system molar optical rotatory power (Wikidata Q96346994): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the amount of substance for molar optical rotatory power and angle of optical rotation and cross-sectional area?" ], "gap": "", "node": "hod" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3"""narrow_v1 - the shared NARROWING rule for specialist organs (2026-09-29, from the full-core sweep):
WORD PROBLEMS AND NARRATIVE TURNS BELONG TO THE HEAD. An organ answers a direct domain question. A turn that tells a story ("Justine wants to put a deck ...", "A new energy drink advertises 106 calories for 8 ounces ...") or relates quantities to each other ("the length is 9 inches more than the width") is a word problem, which the core's word- problem organ owns; organs firing on its nouns declined it or answered a different question. An organ may DECLINE only a short direct question (it is then refusing the domain question that was asked); on anything longer it says nothing and the head answers.
Narrowing only ever removes turns an organ takes, so on any input where it does not fire, the organ's reply isbyte-identical to the frozen version it wraps (checked per specialist by an invariance count before re-gating)."""import re
RELATION = re.compile(r"\b(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+){0,2}(?:more|less|fewer|longer|shorter)\s+than\b|" r"\b(?:twice|three times|half)\s+(?:as\s+\w+\s+as\s+)?the\s+\w+\b", re.I)
# a RATE ("106 calories for 8 ounces", "3 apples per 2 dollars") makes the turn a proportion problemRATE = re.compile(r"\b\d+(?:\.\d+)?\s+[a-z]+\s+(?:for|per|every)\s+(?:\d+(?:\.\d+)?|a|an|one|each)\s+[a-z]+", re.I)NUM = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w|\.\d)") # "leg is 5." counts: a sentence-final period is not a decimal
def numbers(t): return len(NUM.findall(str(t or "")))
def last_sentence(t): parts = [s for s in re.split(r"(?<=[.!?;])\s+", str(t or "").strip()) if s.strip()] return parts[-1] if parts else ""
def sentences(t): return len([s for s in re.split(r"(?<=[.!?])\s+", str(t or "").strip()) if s.strip()])
def narrative(t): """a story-shaped or relational turn: 3+ sentences, 40+ words, or quantities defined relative to each other""" t = str(t or "") return sentences(t) >= 3 or len(t.split()) > 40 or RELATION.search(t) is not None or RATE.search(t) is not None
def short_direct(t): """a direct question an organ may decline: at most 2 sentences, at most 25 words, not narrative""" t = str(t or "") return sentences(t) <= 2 and len(t.split()) <= 25 and not narrative(t)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163"""organ_formula_v2 - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205"""organ_formula_v3 - v2 + the DOMAIN beyond signs (pre-registration v11 part C, 2026-10-21). 4.1 and 4.2 published the limit
"a blood pressure of 70/110 or day 400 of a year is answered". spec.json "domain" now also holds:
order an ordering that holds in EVERY worked example between the numbers of one code input ("120/80": systolic above
diastolic) or between two inputs with the same named unit ("original gravity (SG)" above "final gravity (SG)").
Inputs without a named unit are not ordered: four examples cannot show that a chainring always outnumbers a cog.
facts what the quantity can be, cited: a day of 2025 is a whole number from 1 to 365 (Gregorian calendar, a common year);
a temperature is at or above absolute zero (SI Brochure, 9th edition, 2019: 0 K = -273.15 degC = -459.67 degF);
teeth, integers and years are whole numbers.
An input outside either is out_of_domain, an in-domain refusal that says which rule and why.
organ_formula_v2 (the parent) - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def _components(self, vals):
"""every number the inputs give, keyed (input, k): a code input gives its numbers in order ("120/80" -> 120, 80)"""
out = {}
for i, (v, kind) in enumerate(zip(vals, self.kinds)):
if kind == "code":
for k, x in enumerate(re.findall(r"\d+(?:\.\d+)?", str(v))):
out[(i, k)] = float(x)
elif not isinstance(v, str):
out[(i, 0)] = float(v)
return out
def _domain_v3(self, vals):
dom = self.spec.get("domain") or {}
comp = self._components(vals)
for o in dom.get("order") or []:
a, b = tuple(o["greater"]), tuple(o["lesser"])
if a in comp and b in comp and not comp[a] > comp[b]:
return ("In every worked example this program was written from, the %s is greater than the %s; here it is not "
"(%s and %s), so it is not a reading I can work from." % (o["greater_name"], o["lesser_name"],
_fmt(comp[a]), _fmt(comp[b])))
for f in dom.get("facts") or []:
x = comp.get((f["input"], 0))
if x is None:
continue
bad = (f.get("integer") and x != int(x)) or ("min" in f and x < f["min"]) or ("max" in f and x > f["max"])
if bad:
return "%s is not a possible %s: %s. So I won't compute it." % (_fmt(x), f["name"], f["why"])
return None
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
refused = self._domain_v3(vals)
if refused:
return {"kind": "out_of_domain", "status": "declined", "response": refused}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366{ "dev": [ { "q": "What is the amount of substance for molar optical rotatory power 107.961, angle of optical rotation 59.4105 and cross-sectional area 5.77717?", "a": "3.1791600820256143", "valid": true, "kind": "compute", "expect": 3.1791600820256143, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105, 5.777165] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 107.961, angle of optical rotation of 59.4105 and cross-sectional area of 5.77717.", "a": "3.1791600820256143", "valid": true, "kind": "compute", "expect": 3.1791600820256143, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105, 5.777165] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 85.2416, angle of optical rotation 160.878 and cross-sectional area 2.69428?", "a": "5.084975341983345", "valid": true, "kind": "compute", "expect": 5.084975341983345, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [85.241623, 160.878442, 2.69428] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 85.2416, angle of optical rotation of 160.878 and cross-sectional area of 2.69428.", "a": "5.084975341983345", "valid": true, "kind": "compute", "expect": 5.084975341983345, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [85.241623, 160.878442, 2.69428] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 45.6157, angle of optical rotation 4.97131 and cross-sectional area 94.305?", "a": "10.27759497808088", "valid": true, "kind": "compute", "expect": 10.27759497808088, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [45.61567, 4.971307, 94.305046] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 45.6157, angle of optical rotation of 4.97131 and cross-sectional area of 94.305.", "a": "10.27759497808088", "valid": true, "kind": "compute", "expect": 10.27759497808088, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [45.61567, 4.971307, 94.305046] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 10.5638, angle of optical rotation 198.839 and cross-sectional area 0.671697?", "a": "12.643085733152049", "valid": true, "kind": "compute", "expect": 12.643085733152049, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [10.563843, 198.838955, 0.671697] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 10.5638, angle of optical rotation of 198.839 and cross-sectional area of 0.671697.", "a": "12.643085733152049", "valid": true, "kind": "compute", "expect": 12.643085733152049, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [10.563843, 198.838955, 0.671697] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 21.7931, angle of optical rotation 29.5106 and cross-sectional area 8.50341?", "a": "11.514672847514374", "valid": true, "kind": "compute", "expect": 11.514672847514374, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609, 8.503407] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 21.7931, angle of optical rotation of 29.5106 and cross-sectional area of 8.50341.", "a": "11.514672847514374", "valid": true, "kind": "compute", "expect": 11.514672847514374, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609, 8.503407] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 223.509, angle of optical rotation 17.3414 and cross-sectional area 7.10705?", "a": "0.5514164683902788", "valid": true, "kind": "compute", "expect": 0.5514164683902788, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [223.508796, 17.341435, 7.107049] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 223.509, angle of optical rotation of 17.3414 and cross-sectional area of 7.10705.", "a": "0.5514164683902788", "valid": true, "kind": "compute", "expect": 0.5514164683902788, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [223.508796, 17.341435, 7.107049] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "What is the amount of substance for molar optical rotatory power 107.961 and angle of optical rotation 59.4105?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the cross-sectional area is not given" }, { "q": "Tell me the amount of substance with molar optical rotatory power of 85.2416 and angle of optical rotation of 160.878.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the cross-sectional area is not given" }, { "q": "What is the amount of substance of the Eiffel Tower?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "What is the amount of substance of Mount Everest?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Tell me the amount of substance with molar optical rotatory power of -45.6157, angle of optical rotation of 4.97131 and cross-sectional area of 94.305.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar optical rotatory power: no example had one" }, { "q": "Which amount of substance is the most common?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ], "heldout": [ { "q": "If the molar optical rotatory power is 17.7888, angle of optical rotation is 167.625 and the cross-sectional area is 10.3291, what is the amount of substance?", "a": "97.3314301270093", "valid": true, "kind": "compute", "expect": 97.3314301270093, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [17.788778, 167.624948, 10.329054] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = 17.7888, angle of optical rotation = 167.625, cross-sectional area = 10.3291?", "a": "97.3314301270093", "valid": true, "kind": "compute", "expect": 97.3314301270093, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [17.788778, 167.624948, 10.329054] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "I need the amount of substance for a molar optical rotatory power of 21.511, an angle of optical rotation of 173.394 and a cross-sectional area of 251.084, please.", "a": "2023.9106825818615", "valid": true, "kind": "compute", "expect": 2023.9106825818615, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.511016, 173.393638, 251.084037] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "If the molar optical rotatory power is 21.511, angle of optical rotation is 173.394 and the cross-sectional area is 251.084, what is the amount of substance?", "a": "2023.9106825818615", "valid": true, "kind": "compute", "expect": 2023.9106825818615, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.511016, 173.393638, 251.084037] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = 129.245, angle of optical rotation = 1.18359, cross-sectional area = 15.9416?", "a": "0.1459888878289837", "valid": true, "kind": "compute", "expect": 0.1459888878289837, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [129.244984, 1.18359, 15.941612] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "I need the amount of substance for a molar optical rotatory power of 129.245, an angle of optical rotation of 1.18359 and a cross-sectional area of 15.9416, please.", "a": "0.1459888878289837", "valid": true, "kind": "compute", "expect": 0.1459888878289837, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [129.244984, 1.18359, 15.941612] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "If the molar optical rotatory power is 20.3966, angle of optical rotation is 18.3169 and the cross-sectional area is 6.8386, what is the amount of substance?", "a": "6.141315193814264", "valid": true, "kind": "compute", "expect": 6.141315193814264, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [20.396558, 18.316867, 6.838598] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = 20.3966, angle of optical rotation = 18.3169, cross-sectional area = 6.8386?", "a": "6.141315193814264", "valid": true, "kind": "compute", "expect": 6.141315193814264, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [20.396558, 18.316867, 6.838598] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "I need the amount of substance for a molar optical rotatory power of 185.886, an angle of optical rotation of 13.2373 and a cross-sectional area of 4.71941, please.", "a": "0.3360784039769457", "valid": true, "kind": "compute", "expect": 0.3360784039769457, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [185.886273, 13.237311, 4.719415] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "If the molar optical rotatory power is 185.886, angle of optical rotation is 13.2373 and the cross-sectional area is 4.71941, what is the amount of substance?", "a": "0.3360784039769457", "valid": true, "kind": "compute", "expect": 0.3360784039769457, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [185.886273, 13.237311, 4.719415] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = 9.1061, angle of optical rotation = 24.5721, cross-sectional area = 108.451?", "a": "292.64569674251265", "valid": true, "kind": "compute", "expect": 292.64569674251265, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [9.106104, 24.572086, 108.450792] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "I need the amount of substance for a molar optical rotatory power of 9.1061, an angle of optical rotation of 24.5721 and a cross-sectional area of 108.451, please.", "a": "292.64569674251265", "valid": true, "kind": "compute", "expect": 292.64569674251265, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [9.106104, 24.572086, 108.450792] (the system molar optical rotatory power (Wikidata Q96346994))" }, { "q": "If the molar optical rotatory power is 17.7888 and the angle of optical rotation is 167.625, what is the amount of substance?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the cross-sectional area is not given" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = 21.511, angle of optical rotation = 173.394?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the cross-sectional area is not given" }, { "q": "Do you know the amount of substance of a violin?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Do you know the amount of substance of the French Revolution?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Could you work out the amount of substance given molar optical rotatory power = -129.245, angle of optical rotation = 1.18359, cross-sectional area = 15.9416?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative molar optical rotatory power: no example had one" }, { "q": "What is a typical amount of substance?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""amount of substance from molar optical rotatory power, angle of optical rotation, cross-sectional area (molar optical rotatory power (Wikidata Q96346994))The maths organ (systems.py): solved from the system q0 = q1*((q2)/(q3)); checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(molar_optical_rotatory_power, angle_of_optical_rotation, cross_sectional_area): return 1.0*angle_of_optical_rotation*cross_sectional_area/molar_optical_rotatory_power12345678910111213141516171819202122232425262728293031"""scorer_formula_v1 - scorer for composed formula specialists: (good, asserted).A must-decline item answered is a false yes. A valid quantity item is right when the FIRST number in the reply (theanswer, before any working) is within 0.5% of the sealed answer; a valid text item is right when the answer appears in thereply as a whole word, exactly as written."""import re
def _first_num(text): m = re.search(r"-?\d[\d,]*(?:\.\d+)?(?:[eE][+-]?\d+)?", text) if not m: return None try: return float(m.group(0).replace(",", "")) except ValueError: return None
def ok(p, r): r = r or {} text = str(r.get("response", "")) answered = str(r.get("status", "")) == "answered" if not p["valid"]: return (not answered), answered if not answered: return False, False if p.get("dtype") == "quantity": want, got = float(p["expect"]), _first_num(text) if got is None: return False, True return abs(got - want) <= (0.005 * abs(want) if want else 0.005), True return re.search(r"(?<![\w])%s(?![\w])" % re.escape(str(p["expect"])), text) is not None, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145{ "title": "amount of substance from molar optical rotatory power, angle of optical rotation, cross-sectional area (molar optical rotatory power (Wikidata Q96346994))", "inputs": [ "molar optical rotatory power (m^2/mol)", "angle of optical rotation (1)", "cross-sectional area (m^2)" ], "output": "amount of substance (mol)", "input_kinds": [ "number", "number", "number" ], "expression": "1.0*q1*q2/q0", "expression_x": null, "said": "solved from the system q0 = q1*((q2)/(q3)); checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q1*((q2)/(q3))" ], "constants": {}, "quantities": { "q0": "molar optical rotatory power (m^2/mol)", "q1": "angle of optical rotation (1)", "q2": "cross-sectional area (m^2)", "q3": "amount of substance (mol)" }, "symbols": [ "q0", "q1", "q2" ], "out_symbol": "q3" }, "points": [ { "in": [ 107.960666, 59.4105, 5.777165 ], "out": 3.1791600820256143 }, { "in": [ 17.788778, 167.624948, 10.329054 ], "out": 97.3314301270093 }, { "in": [ 85.241623, 160.878442, 2.69428 ], "out": 5.084975341983345 }, { "in": [ 21.511016, 173.393638, 251.084037 ], "out": 2023.9106825818615 }, { "in": [ 45.61567, 4.971307, 94.305046 ], "out": 10.27759497808088 }, { "in": [ 129.244984, 1.18359, 15.941612 ], "out": 0.1459888878289837 }, { "in": [ 10.563843, 198.838955, 0.671697 ], "out": 12.643085733152049 }, { "in": [ 20.396558, 18.316867, 6.838598 ], "out": 6.141315193814264 }, { "in": [ 21.793126, 29.510609, 8.503407 ], "out": 11.514672847514374 }, { "in": [ 185.886273, 13.237311, 4.719415 ], "out": 0.3360784039769457 }, { "in": [ 223.508796, 17.341435, 7.107049 ], "out": 0.5514164683902788 }, { "in": [ 9.106104, 24.572086, 108.450792 ], "out": 292.64569674251265 } ], "domain": { "inputs": [ "positive", "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-amount-of-substance-6", "split": "dev", "decision": "WOULD PASS", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.01, "budget_ms": 200.0, "fails": [], "files_sha": "dcd1754d1cdf1655aa8da85bac69f16cb466cff676771502dcc453f807bf57f5", "panel_sha": "0ae4f2482203a4d0e73058b9b7d779ce07d50a52097ccd5bec57719c525fc06b", "time": "2026-10-25T00:56:52Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-amount-of-substance-6", "split": "heldout", "decision": "ADMIT", "reasons": [], "n": 18, "head": { "ok": 6, "fy": 0, "wrong": 0 }, "with_specialist": { "ok": 18, "fy": 0, "wrong": 0 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.01, "budget_ms": 200.0, "fails": [], "files_sha": "dcd1754d1cdf1655aa8da85bac69f16cb466cff676771502dcc453f807bf57f5", "panel_sha": "1f36c6bd6dc760fe03fb5c4e309a0c5ca26a4dec36feca681a387aa4d083341a", "time": "2026-10-25T00:56:53Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }, "memory": "written to your group's memory"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-amount-of-substance-7", "name": "Solved: amount of substance from mean energy imparted, radiation-chemical yield (radiation-chemical yield (Wikidata Q109061714))", "sources": [ { "name": "the maths organ: solved from the system q1 = ((q2)/(q0)); checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bamount\\ of\\ substance\\b" }, "panel": { "path": "panel.json", "scorer_module": "scorer_formula_v1", "scorer_fn": "ok" }, "budgets": { "latency_p50_ms": 200 }, "notes": "Solved by the maths organ from the system radiation-chemical yield (Wikidata Q109061714): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the amount of substance for mean energy imparted and radiation-chemical yield?" ], "gap": "", "node": "hod" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3"""narrow_v1 - the shared NARROWING rule for specialist organs (2026-09-29, from the full-core sweep):
WORD PROBLEMS AND NARRATIVE TURNS BELONG TO THE HEAD. An organ answers a direct domain question. A turn that tells a story ("Justine wants to put a deck ...", "A new energy drink advertises 106 calories for 8 ounces ...") or relates quantities to each other ("the length is 9 inches more than the width") is a word problem, which the core's word- problem organ owns; organs firing on its nouns declined it or answered a different question. An organ may DECLINE only a short direct question (it is then refusing the domain question that was asked); on anything longer it says nothing and the head answers.
Narrowing only ever removes turns an organ takes, so on any input where it does not fire, the organ's reply isbyte-identical to the frozen version it wraps (checked per specialist by an invariance count before re-gating)."""import re
RELATION = re.compile(r"\b(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+){0,2}(?:more|less|fewer|longer|shorter)\s+than\b|" r"\b(?:twice|three times|half)\s+(?:as\s+\w+\s+as\s+)?the\s+\w+\b", re.I)
# a RATE ("106 calories for 8 ounces", "3 apples per 2 dollars") makes the turn a proportion problemRATE = re.compile(r"\b\d+(?:\.\d+)?\s+[a-z]+\s+(?:for|per|every)\s+(?:\d+(?:\.\d+)?|a|an|one|each)\s+[a-z]+", re.I)NUM = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w|\.\d)") # "leg is 5." counts: a sentence-final period is not a decimal
def numbers(t): return len(NUM.findall(str(t or "")))
def last_sentence(t): parts = [s for s in re.split(r"(?<=[.!?;])\s+", str(t or "").strip()) if s.strip()] return parts[-1] if parts else ""
def sentences(t): return len([s for s in re.split(r"(?<=[.!?])\s+", str(t or "").strip()) if s.strip()])
def narrative(t): """a story-shaped or relational turn: 3+ sentences, 40+ words, or quantities defined relative to each other""" t = str(t or "") return sentences(t) >= 3 or len(t.split()) > 40 or RELATION.search(t) is not None or RATE.search(t) is not None
def short_direct(t): """a direct question an organ may decline: at most 2 sentences, at most 25 words, not narrative""" t = str(t or "") return sentences(t) <= 2 and len(t.split()) <= 25 and not narrative(t)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163"""organ_formula_v2 - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205"""organ_formula_v3 - v2 + the DOMAIN beyond signs (pre-registration v11 part C, 2026-10-21). 4.1 and 4.2 published the limit
"a blood pressure of 70/110 or day 400 of a year is answered". spec.json "domain" now also holds:
order an ordering that holds in EVERY worked example between the numbers of one code input ("120/80": systolic above
diastolic) or between two inputs with the same named unit ("original gravity (SG)" above "final gravity (SG)").
Inputs without a named unit are not ordered: four examples cannot show that a chainring always outnumbers a cog.
facts what the quantity can be, cited: a day of 2025 is a whole number from 1 to 365 (Gregorian calendar, a common year);
a temperature is at or above absolute zero (SI Brochure, 9th edition, 2019: 0 K = -273.15 degC = -459.67 degF);
teeth, integers and years are whole numbers.
An input outside either is out_of_domain, an in-domain refusal that says which rule and why.
organ_formula_v2 (the parent) - v1 + a question is declined as missing an input only when it names one of the inputs (v1 declined
"What is the largest living animal species that only eats plants?" for the zodiac program, whose output is "animal":
the gate found the core item made worse, 2026-10-20). A question that names the output and no input is not this
program's, and gets no reply.
v2 also keeps to the DOMAIN of its examples (spec.json "domain", written from the worked examples the composer saw): an
input every example gave as positive (or non-negative) must be so in the question, and an answer whose sign no example's
answer had is not given ("ABV for original gravity 1.010 and final gravity 1.050" would be -5.25): out_of_domain, an
in-domain refusal that says why. A program is evidence for the range its examples span in sign, not beyond.
organ_formula_v1 - the GENERIC FORMULA SPECIALIST: one program the code composer wrote (program.py beside this file) and
the typed signature it was written for (spec.json: the inputs and the output, each a label with an optional unit in
parentheses). Built, not trained; no phrasing templates.
Reading, by role: the output is named in the question (its label; when an input has the same label, the output's unit too,
"in F"); each input is its label with a value right after it ("original gravity 1.055", "age of 25", "f-number = 8") or
right before it ("1.055 original gravity"). A value is a number ("1,000", "0.5", "1/125") or, for an input whose examples
were codes, a token mixing digits and letters ("205/55R16").
compute every input found: "The <output> is <value> <unit>." and the program it came from
missing_input a short direct question names the output but not every input's value: an in-domain refusal naming what
is missing
Narrowing (narrow_v1, the factory's shared rule): story-shaped and relational turns belong to the core; a turn carrying
numbers that no input claims is a different calculation and belongs to the core. Everything else: no reply."""
from __future__ import annotations
import importlib.util
import json
import os
import re
from narrow_v1 import narrative, short_direct
HERE = os.path.dirname(os.path.abspath(__file__))
NUM = r"-?\d[\d,]*(?:\.\d+)?(?:\s*/\s*\d[\d,]*(?:\.\d+)?)?"
CODE = r"[A-Za-z0-9]*\d[A-Za-z0-9]*[/\-][A-Za-z0-9/\-]*\d[A-Za-z0-9]*"
ANYNUM = re.compile(r"(?<![\w/.])-?\d[\d,]*(?:\.\d+)?(?![\w/])")
ASKING = re.compile(r"\?\s*$|^\s*(?:what|which|how|tell me|give me|i need|do you know|could you|can you|if |compute|calculate|"
r"work out|find )", re.I)
LINK = r"\s*(?:of|is|=|:|at|equal to|equals)?\s*(?:a|an|the)?\s*"
def split_label(s):
m = re.match(r"\s*(.*?)\s*(?:\(([^)]*)\))?\s*$", s)
return m.group(1).strip(), (m.group(2) or "").strip()
def label_rx(label):
words = [re.escape(w) for w in re.split(r"[\s]+", label) if w]
return r"(?<![\w-])" + r"[\s-]+".join(words) + r"s?(?![\w-])"
def _val(tok):
tok = tok.replace(",", "").replace(" ", "")
if "/" in tok:
a, b = tok.split("/", 1)
return float(a) / float(b)
return float(tok)
def _in_sign(v, sign):
if isinstance(v, str) or sign == "any":
return True
return v > 0 if sign == "positive" else v >= 0
def sign_of(values):
"""the sign every example gave: "positive", "nonnegative" or "any" (text values: "any")"""
if not values or any(isinstance(v, str) for v in values):
return "any"
if all(v > 0 for v in values):
return "positive"
return "nonnegative" if all(v >= 0 for v in values) else "any"
def _fmt(v):
if isinstance(v, str):
return v
v = float(v)
if v == 0:
return "0"
return ("%.6g" % v) if 1e-3 <= abs(v) < 1e7 else ("%.4g" % v)
class FormulaOrgan:
def __init__(self, spec="spec.json"):
self.spec = json.load(open(os.path.join(HERE, spec), encoding="utf-8"))
loader = importlib.util.spec_from_file_location("composed_program", os.path.join(HERE, "program.py"))
mod = importlib.util.module_from_spec(loader)
loader.loader.exec_module(mod)
self.compute = mod.compute
self.out_label, self.out_unit = split_label(self.spec["output"])
self.ins = [split_label(x) for x in self.spec["inputs"]]
self.kinds = self.spec["input_kinds"] # "number" or "code", from the examples
dom = self.spec.get("domain") or {}
self.in_sign = dom.get("inputs") or ["any"] * len(self.kinds) # "positive", "nonnegative" or "any", per input
self.out_sign = dom.get("output", "any")
collide = any(lab.lower() == self.out_label.lower() for lab, _ in self.ins)
out = label_rx(self.out_label)
if collide and self.out_unit: # "the temperature in F"
out += r"\s+(?:in|to)\s+(?:degrees\s+)?" + re.escape(self.out_unit) + r"(?![\w])"
self.rx_out = re.compile(out, re.I)
self.rx_in = []
for (lab, unit), kind in zip(self.ins, self.kinds):
v = CODE if kind == "code" else NUM
after = re.compile(label_rx(lab) + LINK + r"(" + v + r")(?![\w/])", re.I)
before = re.compile(r"(?<![\w/.])(" + v + r")\s+(?:\w+\s+)?" + label_rx(lab), re.I)
self.rx_in.append((after, before))
def _read(self, t):
spans, vals, missing = [], [], []
out_m = self.rx_out.search(t)
for (lab, _), kind, (after, before) in zip(self.ins, self.kinds, self.rx_in):
got = None
for rx in (after, before):
for m in rx.finditer(t):
if out_m and out_m.start() <= m.start() < out_m.end():
continue # the output's own mention is not an input
if any(a <= m.start(1) < b for a, b in spans):
continue
got = m
break
if got:
break
if not got:
missing.append(lab)
continue
spans.append((got.start(1), got.end(1)))
vals.append(got.group(1) if kind == "code" else _val(got.group(1)))
return vals, missing, spans
def _components(self, vals):
"""every number the inputs give, keyed (input, k): a code input gives its numbers in order ("120/80" -> 120, 80)"""
out = {}
for i, (v, kind) in enumerate(zip(vals, self.kinds)):
if kind == "code":
for k, x in enumerate(re.findall(r"\d+(?:\.\d+)?", str(v))):
out[(i, k)] = float(x)
elif not isinstance(v, str):
out[(i, 0)] = float(v)
return out
def _domain_v3(self, vals):
dom = self.spec.get("domain") or {}
comp = self._components(vals)
for o in dom.get("order") or []:
a, b = tuple(o["greater"]), tuple(o["lesser"])
if a in comp and b in comp and not comp[a] > comp[b]:
return ("In every worked example this program was written from, the %s is greater than the %s; here it is not "
"(%s and %s), so it is not a reading I can work from." % (o["greater_name"], o["lesser_name"],
_fmt(comp[a]), _fmt(comp[b])))
for f in dom.get("facts") or []:
x = comp.get((f["input"], 0))
if x is None:
continue
bad = (f.get("integer") and x != int(x)) or ("min" in f and x < f["min"]) or ("max" in f and x > f["max"])
if bad:
return "%s is not a possible %s: %s. So I won't compute it." % (_fmt(x), f["name"], f["why"])
return None
def answer(self, text, session_id="default"):
t = re.sub(r"\s+", " ", str(text or "")).strip()
if not self.rx_out.search(t) or narrative(t) or not ASKING.search(t):
return None
vals, missing, spans = self._read(t)
stray = [m for m in ANYNUM.finditer(t) if not any(a <= m.start() < b for a, b in spans)]
if stray: # numbers no input claims: another calculation
return None
if missing:
named = any(re.search(label_rx(lab), t, re.I) for lab, _ in self.ins)
if named and short_direct(t):
return {"kind": "missing_input", "status": "declined",
"response": "To work out the %s I need the %s, and the question doesn't give %s."
% (self.out_label, " and the ".join(missing), "it" if len(missing) == 1 else "them")}
return None
for (lab, _), v, sign in zip(self.ins, vals, self.in_sign):
if not _in_sign(v, sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "Every worked example this program was written from has a %s %s; %s is outside that, so I "
"won't extrapolate." % (sign.replace("nonnegative", "non-negative"), lab, _fmt(v))}
refused = self._domain_v3(vals)
if refused:
return {"kind": "out_of_domain", "status": "declined", "response": refused}
try:
y = self.compute(*vals)
except Exception:
return None
if y is None or (isinstance(y, float) and y != y):
return None
if not _in_sign(y, self.out_sign):
return {"kind": "out_of_domain", "status": "declined",
"response": "That would make the %s %s, and every worked example this program was written from gave a %s "
"one, so I won't give it." % (self.out_label, _fmt(y), self.out_sign.replace("nonnegative", "non-negative"))}
unit =(" " + self.out_unit) if self.out_unit and not isinstance(y, str) else ""
return {"kind": "compute", "status": "answered",
"response": "The %s is %s%s. (A composed program: %s; %s.)" % (self.out_label, _fmt(y), unit,
self.spec["expression"], self.spec["said"])}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366{ "dev": [ { "q": "What is the amount of substance for mean energy imparted 107.961 and radiation-chemical yield 59.4105?", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 107.961 and radiation-chemical yield of 59.4105.", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [107.960666, 59.4105] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 169.527 and radiation-chemical yield 280.774?", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 169.527 and radiation-chemical yield of 280.774.", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [169.526958, 280.773702] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 1.91195 and radiation-chemical yield 82.2401?", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 1.91195 and radiation-chemical yield of 82.2401.", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.911952, 82.240072] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 1.64379 and radiation-chemical yield 252.709?", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 1.64379 and radiation-chemical yield of 252.709.", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [1.643795, 252.709024] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 18.3169 and radiation-chemical yield 6.8386?", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 18.3169 and radiation-chemical yield of 6.8386.", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [18.316867, 6.838598] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 156.502 and radiation-chemical yield 185.886?", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Tell me the amount of substance with mean energy imparted of 156.502 and radiation-chemical yield of 185.886.", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [156.50181, 185.886273] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "What is the amount of substance for mean energy imparted 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the radiation-chemical yield is not given" }, { "q": "Tell me the amount of substance with mean energy imparted of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the radiation-chemical yield is not given" }, { "q": "What is the amount of substance of the Eiffel Tower?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "What is the amount of substance of Mount Everest?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Tell me the amount of substance with mean energy imparted of -1.91195 and radiation-chemical yield of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative mean energy imparted: no example had one" }, { "q": "Which amount of substance is the most common?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ], "heldout": [ { "q": "If the mean energy imparted is 8.50728 and the radiation-chemical yield is 17.7888, what is the amount of substance?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Could you work out the amount of substance given mean energy imparted = 8.50728, radiation-chemical yield = 17.7888?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.507283, 17.788778] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "I need the amount of substance for a mean energy imparted of 8.24951 and a radiation-chemical yield of 0.634021, please.", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "If the mean energy imparted is 8.24951 and the radiation-chemical yield is 0.634021, what is the amount of substance?", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [8.24951, 0.634021] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Could you work out the amount of substance given mean energy imparted = 0.318734, radiation-chemical yield = 9.56607?", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "I need the amount of substance for a mean energy imparted of 0.318734 and a radiation-chemical yield of 9.56607, please.", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.318734, 9.566071] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "If the mean energy imparted is 0.671697 and the radiation-chemical yield is 14.2496, what is the amount of substance?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Could you work out the amount of substance given mean energy imparted = 0.671697, radiation-chemical yield = 14.2496?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [0.671697, 14.249569] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "I need the amount of substance for a mean energy imparted of 21.7931 and a radiation-chemical yield of 29.5106, please.", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "If the mean energy imparted is 21.7931 and the radiation-chemical yield is 29.5106, what is the amount of substance?", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [21.793126, 29.510609] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "Could you work out the amount of substance given mean energy imparted = 153.15, radiation-chemical yield = 18.5953?", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "I need the amount of substance for a mean energy imparted of 153.15 and a radiation-chemical yield of 18.5953, please.", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "mol", "why": "amount of substance for [153.149965, 18.595315] (the system radiation-chemical yield (Wikidata Q109061714))" }, { "q": "If the mean energy imparted is 8.50728, what is the amount of substance?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the radiation-chemical yield is not given" }, { "q": "Could you work out the amount of substance given mean energy imparted = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the radiation-chemical yield is not given" }, { "q": "Do you know the amount of substance of a violin?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Do you know the amount of substance of the French Revolution?", "a": "", "valid": false, "kind": "not_held", "expect": null, "dtype": "quantity", "unit": "", "why": "a named thing, not inputs: a lookup the program cannot do" }, { "q": "Could you work out the amount of substance given mean energy imparted = -0.318734, radiation-chemical yield = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative mean energy imparted: no example had one" }, { "q": "What is a typical amount of substance?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""amount of substance from mean energy imparted, radiation-chemical yield (radiation-chemical yield (Wikidata Q109061714))The maths organ (systems.py): solved from the system q1 = ((q2)/(q0)); checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(mean_energy_imparted, radiation_chemical_yield): return 1.0*mean_energy_imparted*radiation_chemical_yield12345678910111213141516171819202122232425262728293031"""scorer_formula_v1 - scorer for composed formula specialists: (good, asserted).A must-decline item answered is a false yes. A valid quantity item is right when the FIRST number in the reply (theanswer, before any working) is within 0.5% of the sealed answer; a valid text item is right when the answer appears in thereply as a whole word, exactly as written."""import re
def _first_num(text): m = re.search(r"-?\d[\d,]*(?:\.\d+)?(?:[eE][+-]?\d+)?", text) if not m: return None try: return float(m.group(0).replace(",", "")) except ValueError: return None
def ok(p, r): r = r or {} text = str(r.get("response", "")) answered = str(r.get("status", "")) == "answered" if not p["valid"]: return (not answered), answered if not answered: return False, False if p.get("dtype") == "quantity": want, got = float(p["expect"]), _first_num(text) if got is None: return False, True return abs(got - want) <= (0.005 * abs(want) if want else 0.005), True return re.search(r"(?<![\w])%s(?![\w])" % re.escape(str(p["expect"])), text) is not None, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128{ "title": "amount of substance from mean energy imparted, radiation-chemical yield (radiation-chemical yield (Wikidata Q109061714))", "inputs": [ "mean energy imparted (J)", "radiation-chemical yield (s^2*mol/m^2/kg)" ], "output": "amount of substance (mol)", "input_kinds": [ "number", "number" ], "expression": "1.0*q0*q1", "expression_x": null, "said": "solved from the system q1 = ((q2)/(q0)); checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q1 = ((q2)/(q0))" ], "constants": {}, "quantities": { "q0": "mean energy imparted (J)", "q1": "radiation-chemical yield (s^2*mol/m^2/kg)", "q2": "amount of substance (mol)" }, "symbols": [ "q0", "q1" ], "out_symbol": "q2" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 6413.997161494573 }, { "in": [ 8.507283, 17.788778 ], "out": 151.33416360087082 }, { "in": [ 169.526958, 280.773702 ], "out": 47598.71144694985 }, { "in": [ 8.24951, 0.634021 ], "out": 5.230362271972724 }, { "in": [ 1.911952, 82.240072 ], "out": 157.23905034769402 }, { "in": [ 0.318734, 9.566071 ], "out": 3.0490325263462696 }, { "in": [ 1.643795, 252.709024 ], "out": 415.4019555725448 }, { "in": [ 0.671697, 14.249569 ], "out": 9.571395807788361 }, { "in": [ 18.316867, 6.838598 ], "out": 125.26169131331936 }, { "in": [ 21.793126, 29.510609 ], "out": 643.1284273894521 }, { "in": [ 156.50181, 185.886273 ], "out": 29091.53810517715 }, { "in": [ 153.149965, 18.595315 ], "out": 2847.871916067332 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125{ "id": "solved-amount-of-substance-7", "split": "dev", "decision": "WOULD FAIL", "reasons": [ "DOMAIN: gain 0, needs 3" ], "n": 18, "head": { "ok": 4, "fy": 2, "wrong": 6 }, "with_specialist": { "ok": 4, "fy": 2, "wrong": 6 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.0, "budget_ms": 200.0, "fails": [ { "q": "What is the amount of substance for mean energy imparted 107.961 and radiation-chemical yield 59.4105?", "expected": "6413.997161494573", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 107.961 and radiation-chemical yield of 59.4105.", "expected": "6413.997161494573", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" }, { "q": "What is the amount of substance for mean energy imparted 169.527 and radiation-chemical yield 280.774?", "expected": "47598.71144694985", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 169.527 and radiation-chemical yield of 280.774.", "expected": "47598.71144694985", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" }, { "q": "What is the amount of substance for mean energy imparted 1.91195 and radiation-chemical yield 82.2401?", "expected": "157.23905034769402", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 1.91195 and radiation-chemical yield of 82.2401.", "expected": "157.23905034769402", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" }, { "q": "What is the amount of substance for mean energy imparted 1.64379 and radiation-chemical yield 252.709?", "expected": "415.4019555725448", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 1.64379 and radiation-chemical yield of 252.709.", "expected": "415.4019555725448", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" }, { "q": "What is the amount of substance for mean energy imparted 18.3169 and radiation-chemical yield 6.8386?", "expected": "125.26169131331936", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 18.3169 and radiation-chemical yield of 6.8386.", "expected": "125.26169131331936", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" }, { "q": "What is the amount of substance for mean energy imparted 156.502 and radiation-chemical yield 185.886?", "expected": "29091.53810517715", "got": "statistics.mean: Return the sample arithmetic mean of data. Call it as statistics.mean(data) (Python 3.12.3). [python-r2]", "status": "answered", "by": "core" }, { "q": "Tell me the amount of substance with mean energy imparted of 156.502 and radiation-chemical yield of 185.886.", "expected": "29091.53810517715", "got": "That is a word problem. My exact operators read short forms (a sum, a mean, a choose, a linear equation) and this one took numbers out of a sentence it did not ", "status": "withheld", "by": "core" } ], "files_sha": "f1daaa1c2ece4438d77454c46137bb184c8679554dcaa7cda4a7815eaad5b793", "panel_sha": "5b3c14450708e8a0d810a2f61addb850ac85c3651782bb6ce11617fdc5ef8ebd", "time": "2026-10-25T00:59:48Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 0, "mode": "full" }}1{"t": "2026-10-25T01:00:14Z", "heldout_sha": "92482fd1eb2bd3a9ff7dbeef8b58d81471199fa213f672850aace50806eacf76", "files_sha": "f26d02e9d2a9a126e9f2df848cf7502b10b5b0d4e8a5ceaad540a4548ed17b87"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-amount-of-substance-8", "name": "Solved: amount of substance from amount-of-substance fraction, amount of substance of component (amount-of-substance fraction (Wikidata Q125264))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1 / q2; checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bamount\\ of\\ substance\\b" }, "panel": { "path": "panel.json", "scorer_module": "scorer_formula_v1", "scorer_fn": "ok" }, "budgets": { "latency_p50_ms": 200 }, "notes": "Solved by the maths organ from the system amount-of-substance fraction (Wikidata Q125264): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the amount of substance for amount-of-substance fraction and amount of substance of component?" ], "gap": "", "node": "hod" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3"""narrow_v1 - the shared NARROWING rule for specialist organs (2026-09-29, from the full-core sweep):
WORD PROBLEMS AND NARRATIVE TURNS BELONG TO THE HEAD. An organ answers a direct domain question. A turn that tells a story ("Justine wants to put a deck ...", "A new energy drink advertises 106 calories for 8 ounces ...") or relates quantities to each other ("the length is 9 inches more than the width") is a word problem, which the core's word- problem organ owns; organs firing on its nouns declined it or answered a different question. An organ may DECLINE only a short direct question (it is then refusing the domain question that was asked); on anything longer it says nothing and the head answers.
Narrowing only ever removes turns an organ takes, so on any input where it does not fire, the organ's reply isbyte-identical to the frozen version it wraps (checked per specialist by an invariance count before re-gating)."""import re
RELATION = re.compile(r"\b(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+){0,2}(?:more|less|fewer|longer|shorter)\s+than\b|" r"\b(?:twice|three times|half)\s+(?:as\s+\w+\s+as\s+)?the\s+\w+\b", re.I)
# a RATE ("106 calories for 8 ounces", "3 apples per 2 dollars") makes the turn a proportion problemRATE = re.compile(r"\b\d+(?:\.\d+)?\s+[a-z]+\s+(?:for|per|every)\s+(?:\d+(?:\.\d+)?|a|an|one|each)\s+[a-z]+", re.I)NUM = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w|\.\d)") # "leg is 5." counts: a sentence-final period is not a decimal
def numbers(t): return len(NUM.findall(str(t or "")))
def last_sentence(t): parts = [s for s in re.split(r"(?<=[.!?;])\s+", str(t or "").strip()) if s.strip()] return parts[-1] if parts else ""
def sentences(t): return len([s for s in re.split(r"(?<=[.!?])\s+", str(t or "").strip()) if s.strip()])
def narrative(t): """a story-shaped or relational turn: 3+ sentences, 40+ words, or quantities defined relative to each other""" t = str(t or "") return sentences(t) >= 3 or len(t.split()) > 40 or RELATION.search(t) is not None or RATE.search(t) is not None
def short_direct(t): """a direct question an organ may decline: at most 2 sentences, at most 25 words, not narrative""" t = str(t or "") return sentences(t) <= 2 and len(t.split()) <= 25 and not narrative(t)root/organs10/physics/specialists/solved-amount-of-substance-3/program.pyAdded+7
root/organs10/physics/specialists/solved-amount-of-substance-3/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-amount-of-substance-3/spec.jsonAdded+128
root/organs10/physics/specialists/solved-amount-of-substance-3/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-amount-of-substance-3/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-amount-of-substance-4/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-amount-of-substance-4/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-amount-of-substance-4/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-amount-of-substance-4/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-amount-of-substance-4/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-amount-of-substance-4/panel.jsonAdded+366
root/organs10/physics/specialists/solved-amount-of-substance-4/program.pyAdded+7
root/organs10/physics/specialists/solved-amount-of-substance-4/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-amount-of-substance-4/spec.jsonAdded+128
root/organs10/physics/specialists/solved-amount-of-substance-4/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-amount-of-substance-4/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-amount-of-substance-5/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-amount-of-substance-5/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-amount-of-substance-5/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-amount-of-substance-5/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-amount-of-substance-5/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-amount-of-substance-5/panel.jsonAdded+366
root/organs10/physics/specialists/solved-amount-of-substance-5/program.pyAdded+7
root/organs10/physics/specialists/solved-amount-of-substance-5/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-amount-of-substance-5/spec.jsonAdded+128
root/organs10/physics/specialists/solved-amount-of-substance-5/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-amount-of-substance-5/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-amount-of-substance-6/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-amount-of-substance-6/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-amount-of-substance-6/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-amount-of-substance-6/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-amount-of-substance-6/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-amount-of-substance-6/panel.jsonAdded+366
root/organs10/physics/specialists/solved-amount-of-substance-6/program.pyAdded+7
root/organs10/physics/specialists/solved-amount-of-substance-6/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-amount-of-substance-6/spec.jsonAdded+145
root/organs10/physics/specialists/solved-amount-of-substance-6/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-amount-of-substance-6/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-amount-of-substance-7/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-amount-of-substance-7/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-amount-of-substance-7/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-amount-of-substance-7/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-amount-of-substance-7/panel.jsonAdded+366
root/organs10/physics/specialists/solved-amount-of-substance-7/program.pyAdded+7
root/organs10/physics/specialists/solved-amount-of-substance-7/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-amount-of-substance-7/spec.jsonAdded+128
root/organs10/physics/specialists/solved-amount-of-substance-7/verdict_dev.jsonAdded+125
root/organs10/physics/specialists/solved-amount-of-substance-8/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-amount-of-substance-8/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-amount-of-substance-8/narrow_v1.pyAdded+47