Release 10.3 (full): coverage by the store assembled (the search over learned program structures), one judge over every answer, the opening table on the first interrogative, names written another way learned; full: no organ answers over a terminal refusal; release test pre-registration v39, run once; hashes anchored on Solana (part 16)
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-resistivity-tensor/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-resistivity-tensor/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-resistivity-tensor/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-resistivity-tensor/program.pyAdded+7
- root/organs10/physics/specialists/solved-resistivity-tensor/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-resistivity-tensor/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-resistivity-tensor/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-resistivity-tensor/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-rest-energy/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-rest-energy/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-rest-energy/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-rest-energy/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-rest-energy/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-rest-energy/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-rest-energy/program.pyAdded+7
- root/organs10/physics/specialists/solved-rest-energy/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-rest-energy/spec.jsonAdded+117
- root/organs10/physics/specialists/solved-rest-energy/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-rest-energy/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/program.pyAdded+7
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/spec.jsonAdded+168
- root/organs10/physics/specialists/solved-rest-mass-of-atom-2/verdict_dev.jsonAdded+125
- root/organs10/physics/specialists/solved-rest-mass-of-atom/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-rest-mass-of-atom/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-rest-mass-of-atom/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-rest-mass-of-atom/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-rest-mass-of-atom/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-rest-mass-of-atom/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-rest-mass-of-atom/program.pyAdded+7
- root/organs10/physics/specialists/solved-rest-mass-of-atom/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-rest-mass-of-atom/spec.jsonAdded+134
- root/organs10/physics/specialists/solved-rest-mass-of-atom/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-rest-mass-of-atom/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-rest-mass/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-rest-mass/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-rest-mass/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-rest-mass/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-rest-mass/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-rest-mass/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-rest-mass/program.pyAdded+7
- root/organs10/physics/specialists/solved-rest-mass/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-rest-mass/spec.jsonAdded+117
- root/organs10/physics/specialists/solved-rest-mass/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-rest-mass/verdict_heldout.jsonAdded+39
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 resistivity tensor for electric current density 107.961 and electric field strength 59.4105?", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [107.960666, 59.4105] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 107.961 and electric field strength of 59.4105.", "a": "0.5502976449934551", "valid": true, "kind": "compute", "expect": 0.5502976449934551, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [107.960666, 59.4105] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 169.527 and electric field strength 280.774?", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [169.526958, 280.773702] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 169.527 and electric field strength of 280.774.", "a": "1.656218609813279", "valid": true, "kind": "compute", "expect": 1.656218609813279, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [169.526958, 280.773702] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 1.91195 and electric field strength 82.2401?", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [1.911952, 82.240072] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 1.91195 and electric field strength of 82.2401.", "a": "43.01367504910926", "valid": true, "kind": "compute", "expect": 43.01367504910926, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [1.911952, 82.240072] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 1.64379 and electric field strength 252.709?", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [1.643795, 252.709024] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 1.64379 and electric field strength of 252.709.", "a": "153.73507534197344", "valid": true, "kind": "compute", "expect": 153.73507534197344, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [1.643795, 252.709024] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 18.3169 and electric field strength 6.8386?", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [18.316867, 6.838598] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 18.3169 and electric field strength of 6.8386.", "a": "0.37334976843585305", "valid": true, "kind": "compute", "expect": 0.37334976843585305, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [18.316867, 6.838598] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 156.502 and electric field strength 185.886?", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [156.50181, 185.886273] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Tell me the resistivity tensor with electric current density of 156.502 and electric field strength of 185.886.", "a": "1.187757975790468", "valid": true, "kind": "compute", "expect": 1.187757975790468, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [156.50181, 185.886273] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "What is the resistivity tensor for electric current density 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the electric field strength is not given" }, { "q": "Tell me the resistivity tensor with electric current density of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the electric field strength is not given" }, { "q": "What is the resistivity tensor 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 resistivity tensor 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 resistivity tensor with electric current density of -1.91195 and electric field strength of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative electric current density: no example had one" }, { "q": "Which resistivity tensor 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 electric current density is 8.50728 and the electric field strength is 17.7888, what is the resistivity tensor?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [8.507283, 17.788778] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Could you work out the resistivity tensor given electric current density = 8.50728, electric field strength = 17.7888?", "a": "2.0910058888280627", "valid": true, "kind": "compute", "expect": 2.0910058888280627, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [8.507283, 17.788778] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "I need the resistivity tensor for an electric current density of 8.24951 and an electric field strength of 0.634021, please.", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [8.24951, 0.634021] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "If the electric current density is 8.24951 and the electric field strength is 0.634021, what is the resistivity tensor?", "a": "0.07685559300301205", "valid": true, "kind": "compute", "expect": 0.07685559300301205, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [8.24951, 0.634021] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Could you work out the resistivity tensor given electric current density = 0.318734, electric field strength = 9.56607?", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [0.318734, 9.566071] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "I need the resistivity tensor for an electric current density of 0.318734 and an electric field strength of 9.56607, please.", "a": "30.01270513508963", "valid": true, "kind": "compute", "expect": 30.01270513508963, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [0.318734, 9.566071] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "If the electric current density is 0.671697 and the electric field strength is 14.2496, what is the resistivity tensor?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [0.671697, 14.249569] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Could you work out the resistivity tensor given electric current density = 0.671697, electric field strength = 14.2496?", "a": "21.214275301882097", "valid": true, "kind": "compute", "expect": 21.214275301882097, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [0.671697, 14.249569] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "I need the resistivity tensor for an electric current density of 21.7931 and an electric field strength of 29.5106, please.", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [21.793126, 29.510609] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "If the electric current density is 21.7931 and the electric field strength is 29.5106, what is the resistivity tensor?", "a": "1.3541245984297685", "valid": true, "kind": "compute", "expect": 1.3541245984297685, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [21.793126, 29.510609] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "Could you work out the resistivity tensor given electric current density = 153.15, electric field strength = 18.5953?", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [153.149965, 18.595315] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "I need the resistivity tensor for an electric current density of 153.15 and an electric field strength of 18.5953, please.", "a": "0.12141899904566884", "valid": true, "kind": "compute", "expect": 0.12141899904566884, "dtype": "quantity", "unit": "m^3*kg/s^3/A^2", "why": "resistivity tensor for [153.149965, 18.595315] (the system resistivity tensor (Wikidata Q112762959))" }, { "q": "If the electric current density is 8.50728, what is the resistivity tensor?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the electric field strength is not given" }, { "q": "Could you work out the resistivity tensor given electric current density = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the electric field strength is not given" }, { "q": "Do you know the resistivity tensor 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 resistivity tensor 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 resistivity tensor given electric current density = -0.318734, electric field strength = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative electric current density: no example had one" }, { "q": "What is a typical resistivity tensor?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""resistivity tensor from electric current density, electric field strength (resistivity tensor (Wikidata Q112762959))The maths organ (systems.py): solved from the system q3 = q1 * q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(electric_current_density, electric_field_strength): return 1.0*electric_field_strength/electric_current_density12345678910111213141516171819202122232425262728293031"""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": "resistivity tensor from electric current density, electric field strength (resistivity tensor (Wikidata Q112762959))", "inputs": [ "electric current density (A/m^2)", "electric field strength (m*kg/s^3/A)" ], "output": "resistivity tensor (m^3*kg/s^3/A^2)", "input_kinds": [ "number", "number" ], "expression": "1.0*q3/q2", "expression_x": null, "said": "solved from the system q3 = q1 * q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q3 = q1 * q2" ], "constants": {}, "quantities": { "q1": "resistivity tensor (m^3*kg/s^3/A^2)", "q2": "electric current density (A/m^2)", "q3": "electric field strength (m*kg/s^3/A)" }, "symbols": [ "q2", "q3" ], "out_symbol": "q1" }, "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-resistivity-tensor", "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": "b0b041da3280971e7a7e925af0d1802f40d033877dcc86ee36f6d30856d38e28", "panel_sha": "c7c7b095534af3f2e08688bf42aab7a0f50fd04c73b140c2ea1816b9603cbde8", "time": "2026-10-25T01:07:29Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-resistivity-tensor", "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": "b0b041da3280971e7a7e925af0d1802f40d033877dcc86ee36f6d30856d38e28", "panel_sha": "498a63fff82a7dc2cec9d1a04f1a4cf044c6e488571fc8945f0ecad1dd8a7268", "time": "2026-10-25T01:07:30Z", "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-25T01:18:33Z", "heldout_sha": "a381c8ff1b303567dda293082629dcfa9c6db9e3ac0c9e4cd7f8a036a0ecf5fa", "files_sha": "17af75daa1ac4b2c44d4df5a80796e196dda8a3e6e5ba3f603177d18c5d839df"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-rest-energy", "name": "Solved: rest energy from rest mass (rest energy (Wikidata Q11663629))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1*q2 **(2); 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": "\\brest\\ energy\\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 rest energy (Wikidata Q11663629): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the rest energy for rest mass?" ], "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 rest energy for rest mass 107.961?", "a": "5.225296229074162e+18", "valid": true, "kind": "compute", "expect": 5.225296229074162e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [107.960666] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 107.961.", "a": "5.225296229074162e+18", "valid": true, "kind": "compute", "expect": 5.225296229074162e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [107.960666] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy for rest mass 22.652?", "a": "1.0963579033678204e+18", "valid": true, "kind": "compute", "expect": 1.0963579033678204e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [22.652023] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 22.652.", "a": "1.0963579033678204e+18", "valid": true, "kind": "compute", "expect": 1.0963579033678204e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [22.652023] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy for rest mass 173.394?", "a": "8.392252098816641e+18", "valid": true, "kind": "compute", "expect": 8.392252098816641e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [173.393638] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 173.394.", "a": "8.392252098816641e+18", "valid": true, "kind": "compute", "expect": 8.392252098816641e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [173.393638] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy for rest mass 126.709?", "a": "6.132727787128827e+18", "valid": true, "kind": "compute", "expect": 6.132727787128827e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [126.709252] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 126.709.", "a": "6.132727787128827e+18", "valid": true, "kind": "compute", "expect": 6.132727787128827e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [126.709252] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy for rest mass 0.671697?", "a": "3.2510144470038964e+16", "valid": true, "kind": "compute", "expect": 3.2510144470038964e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [0.671697] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 0.671697.", "a": "3.2510144470038964e+16", "valid": true, "kind": "compute", "expect": 3.2510144470038964e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [0.671697] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy for rest mass 1.16997?", "a": "5.66264514893321e+16", "valid": true, "kind": "compute", "expect": 5.66264514893321e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [1.169968] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest energy with rest mass of 1.16997.", "a": "5.66264514893321e+16", "valid": true, "kind": "compute", "expect": 5.66264514893321e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [1.169968] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest energy?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest mass is not given" }, { "q": "Could you work out the rest energy, please?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest mass is not given" }, { "q": "What is the rest energy 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 rest energy 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 rest energy with rest mass of -173.394.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative rest mass: no example had one" }, { "q": "Which rest energy 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 rest mass is 2.57003, what is the rest energy?", "a": "1.2438944780389635e+17", "valid": true, "kind": "compute", "expect": 1.2438944780389635e+17, "dtype": "quantity", "unit": "J", "why": "rest energy for [2.57003] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest energy given rest mass = 2.57003?", "a": "1.2438944780389635e+17", "valid": true, "kind": "compute", "expect": 1.2438944780389635e+17, "dtype": "quantity", "unit": "J", "why": "rest energy for [2.57003] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest energy for a rest mass of 48.921, please.", "a": "2.367775957624573e+18", "valid": true, "kind": "compute", "expect": 2.367775957624573e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [48.920991] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest mass is 48.921, what is the rest energy?", "a": "2.367775957624573e+18", "valid": true, "kind": "compute", "expect": 2.367775957624573e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [48.920991] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest energy given rest mass = 0.348438?", "a": "1.6864383210093476e+16", "valid": true, "kind": "compute", "expect": 1.6864383210093476e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [0.348438] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest energy for a rest mass of 0.348438, please.", "a": "1.6864383210093476e+16", "valid": true, "kind": "compute", "expect": 1.6864383210093476e+16, "dtype": "quantity", "unit": "J", "why": "rest energy for [0.348438] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest mass is 252.709, what is the rest energy?", "a": "1.2231116773677132e+19", "valid": true, "kind": "compute", "expect": 1.2231116773677132e+19, "dtype": "quantity", "unit": "J", "why": "rest energy for [252.709024] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest energy given rest mass = 252.709?", "a": "1.2231116773677132e+19", "valid": true, "kind": "compute", "expect": 1.2231116773677132e+19, "dtype": "quantity", "unit": "J", "why": "rest energy for [252.709024] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest energy for a rest mass of 20.3966, please.", "a": "9.871934053590304e+17", "valid": true, "kind": "compute", "expect": 9.871934053590304e+17, "dtype": "quantity", "unit": "J", "why": "rest energy for [20.396558] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest mass is 20.3966, what is the rest energy?", "a": "9.871934053590304e+17", "valid": true, "kind": "compute", "expect": 9.871934053590304e+17, "dtype": "quantity", "unit": "J", "why": "rest energy for [20.396558] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest energy given rest mass = 134.993?", "a": "6.533659146907719e+18", "valid": true, "kind": "compute", "expect": 6.533659146907719e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [134.992958] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest energy for a rest mass of 134.993, please.", "a": "6.533659146907719e+18", "valid": true, "kind": "compute", "expect": 6.533659146907719e+18, "dtype": "quantity", "unit": "J", "why": "rest energy for [134.992958] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest energy, please.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest mass is not given" }, { "q": "Can you tell me the rest energy?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest mass is not given" }, { "q": "Do you know the rest energy 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 rest energy 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 rest energy given rest mass = -0.348438?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative rest mass: no example had one" }, { "q": "What is a typical rest energy?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""rest energy from rest mass (rest energy (Wikidata Q11663629))The maths organ (systems.py): solved from the system q0 = q1*q2 **(2); checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(rest_mass): return 4.84e+16*rest_mass12345678910111213141516171819202122232425262728293031"""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, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117{ "title": "rest energy from rest mass (rest energy (Wikidata Q11663629))", "inputs": [ "rest mass (kg)" ], "output": "rest energy (J)", "input_kinds": [ "number" ], "expression": "4.84e+16*q1", "expression_x": null, "said": "solved from the system q0 = q1*q2 **(2); 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 **(2)" ], "constants": { "q2": [ "speed of light in vacuum", 220000000.0, "m/s" ] }, "quantities": { "q0": "rest energy (J)", "q1": "rest mass (kg)" }, "symbols": [ "q1" ], "out_symbol": "q0" }, "points": [ { "in": [ 107.960666 ], "out": 5.225296229074162e+18 }, { "in": [ 2.57003 ], "out": 1.2438944780389635e+17 }, { "in": [ 22.652023 ], "out": 1.0963579033678204e+18 }, { "in": [ 48.920991 ], "out": 2.367775957624573e+18 }, { "in": [ 173.393638 ], "out": 8.392252098816641e+18 }, { "in": [ 0.348438 ], "out": 1.6864383210093476e+16 }, { "in": [ 126.709252 ], "out": 6.132727787128827e+18 }, { "in": [ 252.709024 ], "out": 1.2231116773677132e+19 }, { "in": [ 0.671697 ], "out": 3.2510144470038964e+16 }, { "in": [ 20.396558 ], "out": 9.871934053590304e+17 }, { "in": [ 1.169968 ], "out": 5.66264514893321e+16 }, { "in": [ 134.992958 ], "out": 6.533659146907719e+18 } ], "domain": { "inputs": [ "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-rest-energy", "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": "17af75daa1ac4b2c44d4df5a80796e196dda8a3e6e5ba3f603177d18c5d839df", "panel_sha": "b0e7b7eff503d85f31cf7674a0386737806a66cf590652c2b92c8914d662bcd8", "time": "2026-10-25T01:18:33Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-rest-energy", "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": "17af75daa1ac4b2c44d4df5a80796e196dda8a3e6e5ba3f603177d18c5d839df", "panel_sha": "a381c8ff1b303567dda293082629dcfa9c6db9e3ac0c9e4cd7f8a036a0ecf5fa", "time": "2026-10-25T01:18: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"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-rest-mass-of-atom-2", "name": "Solved: rest mass of atom from hydrogen-1 mass, mass defect, atomic number, neutron number (mass defect (Wikidata Q26897126))", "sources": [ { "name": "the maths organ: solved from the system q3 = q4*q0 + q5*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": "\\brest\\ mass\\ of\\ atom\\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 mass defect (Wikidata Q26897126): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the rest mass of atom for hydrogen-1 mass and mass defect and atomic number and neutron number?" ], "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 rest mass of atom for hydrogen-1 mass 107.961, mass defect 59.4105, atomic number 5.77717 and neutron number 1.89126?", "a": "564.2960385318023", "valid": true, "kind": "compute", "expect": 564.2960385318023, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [107.960666, 59.4105, 5.777165, 1.891256] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 107.961, mass defect of 59.4105, atomic number of 5.77717 and neutron number of 1.89126.", "a": "564.2960385318023", "valid": true, "kind": "compute", "expect": 564.2960385318023, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [107.960666, 59.4105, 5.777165, 1.891256] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 2.69428, mass defect 48.921, atomic number 157.223 and neutron number 35.6412?", "a": "374.68058966653797", "valid": true, "kind": "compute", "expect": 374.68058966653797, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [2.69428, 48.920991, 157.22256, 35.641157] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 2.69428, mass defect of 48.921, atomic number of 157.223 and neutron number of 35.6412.", "a": "374.68058966653797", "valid": true, "kind": "compute", "expect": 374.68058966653797, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [2.69428, 48.920991, 157.22256, 35.641157] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 0.551236, mass defect 2.88512, atomic number 10.5638 and neutron number 198.839?", "a": "2.9380492976499477", "valid": true, "kind": "compute", "expect": 2.9380492976499477, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.551236, 2.88512, 10.563843, 198.838955] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 0.551236, mass defect of 2.88512, atomic number of 10.5638 and neutron number of 198.839.", "a": "2.9380492976499477", "valid": true, "kind": "compute", "expect": 2.9380492976499477, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.551236, 2.88512, 10.563843, 198.838955] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 21.7931, mass defect 29.5106, atomic number 8.50341 and neutron number 0.58813?", "a": "155.80521986442068", "valid": true, "kind": "compute", "expect": 155.80521986442068, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [21.793126, 29.510609, 8.503407, 0.58813] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 21.7931, mass defect of 29.5106, atomic number of 8.50341 and neutron number of 0.58813.", "a": "155.80521986442068", "valid": true, "kind": "compute", "expect": 155.80521986442068, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [21.793126, 29.510609, 8.503407, 0.58813] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 7.10705, mass defect 30.2507, atomic number 308.158 and neutron number 178.166?", "a": "2159.8436670986293", "valid": true, "kind": "compute", "expect": 2159.8436670986293, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [7.107049, 30.250749, 308.158051, 178.165518] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 7.10705, mass defect of 30.2507, atomic number of 308.158 and neutron number of 178.166.", "a": "2159.8436670986293", "valid": true, "kind": "compute", "expect": 2159.8436670986293, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [7.107049, 30.250749, 308.158051, 178.165518] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 34.8151, mass defect 0.380269, atomic number 25.4097 and neutron number 20.8456?", "a": "884.260861631089", "valid": true, "kind": "compute", "expect": 884.260861631089, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [34.81508, 0.380269, 25.409711, 20.845641] (the system mass defect (Wikidata Q26897126))" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 34.8151, mass defect of 0.380269, atomic number of 25.4097 and neutron number of 20.8456.", "a": "884.260861631089", "valid": true, "kind": "compute", "expect": 884.260861631089, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [34.81508, 0.380269, 25.409711, 20.845641] (the system mass defect (Wikidata Q26897126))" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 107.961, mass defect 59.4105 and atomic number 5.77717?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the neutron number is not given" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 2.69428, mass defect of 48.921 and atomic number of 157.223.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the neutron number is not given" }, { "q": "What is the rest mass of atom 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 rest mass of atom 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 rest mass of atom with hydrogen-1 mass of -0.551236, mass defect of 2.88512, atomic number of 10.5638 and neutron number of 198.839.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative hydrogen-1 mass: no example had one" }, { "q": "Which rest mass of atom 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 hydrogen-1 mass is 167.625, mass defect is 10.3291, atomic number is 2.21571 and the neutron number is 58.5346, what is the rest mass of atom?", "a": "361.07974491365565", "valid": true, "kind": "compute", "expect": 361.07974491365565, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [167.624948, 10.329054, 2.215713, 58.534594] (the system mass defect (Wikidata Q26897126))" }, { "q": "Could you work out the rest mass of atom given hydrogen-1 mass = 167.625, mass defect = 10.3291, atomic number = 2.21571, neutron number = 58.5346?", "a": "361.07974491365565", "valid": true, "kind": "compute", "expect": 361.07974491365565, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [167.624948, 10.329054, 2.215713, 58.534594] (the system mass defect (Wikidata Q26897126))" }, { "q": "I need the rest mass of atom for a hydrogen-1 mass of 13.999, a mass defect of 0.348438, an atomic number of 45.6157 and a neutron number of 4.97131, please.", "a": "638.2266485937756", "valid": true, "kind": "compute", "expect": 638.2266485937756, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [13.999029, 0.348438, 45.61567, 4.971307] (the system mass defect (Wikidata Q26897126))" }, { "q": "If the hydrogen-1 mass is 13.999, mass defect is 0.348438, atomic number is 45.6157 and the neutron number is 4.97131, what is the rest mass of atom?", "a": "638.2266485937756", "valid": true, "kind": "compute", "expect": 638.2266485937756, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [13.999029, 0.348438, 45.61567, 4.971307] (the system mass defect (Wikidata Q26897126))" }, { "q": "Could you work out the rest mass of atom given hydrogen-1 mass = 246.329, mass defect = 20.3966, atomic number = 18.3169, neutron number = 6.8386?", "a": "4491.579956881549", "valid": true, "kind": "compute", "expect": 4491.579956881549, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [246.329053, 20.396558, 18.316867, 6.838598] (the system mass defect (Wikidata Q26897126))" }, { "q": "I need the rest mass of atom for a hydrogen-1 mass of 246.329, a mass defect of 20.3966, an atomic number of 18.3169 and a neutron number of 6.8386, please.", "a": "4491.579956881549", "valid": true, "kind": "compute", "expect": 4491.579956881549, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [246.329053, 20.396558, 18.316867, 6.838598] (the system mass defect (Wikidata Q26897126))" }, { "q": "If the hydrogen-1 mass is 13.2373, mass defect is 4.71941, atomic number is 41.2905 and the neutron number is 2.12277, what is the rest mass of atom?", "a": "541.8558506889378", "valid": true, "kind": "compute", "expect": 541.8558506889378, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [13.237311, 4.719415, 41.290505, 2.122767] (the system mass defect (Wikidata Q26897126))" }, { "q": "Could you work out the rest mass of atom given hydrogen-1 mass = 13.2373, mass defect = 4.71941, atomic number = 41.2905, neutron number = 2.12277?", "a": "541.8558506889378", "valid": true, "kind": "compute", "expect": 541.8558506889378, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [13.237311, 4.719415, 41.290505, 2.122767] (the system mass defect (Wikidata Q26897126))" }, { "q": "I need the rest mass of atom for a hydrogen-1 mass of 76.5154, a mass defect of 3.14491, an atomic number of 88.6624 and a neutron number of 0.633611, please.", "a": "6780.892039067489", "valid": true, "kind": "compute", "expect": 6780.892039067489, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [76.515411, 3.144912, 88.662361, 0.633611] (the system mass defect (Wikidata Q26897126))" }, { "q": "If the hydrogen-1 mass is 76.5154, mass defect is 3.14491, atomic number is 88.6624 and the neutron number is 0.633611, what is the rest mass of atom?", "a": "6780.892039067489", "valid": true, "kind": "compute", "expect": 6780.892039067489, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [76.515411, 3.144912, 88.662361, 0.633611] (the system mass defect (Wikidata Q26897126))" }, { "q": "Could you work out the rest mass of atom given hydrogen-1 mass = 241.598, mass defect = 1.13479, atomic number = 0.744193, neutron number = 1.35435?", "a": "178.66092284472543", "valid": true, "kind": "compute", "expect": 178.66092284472543, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [241.598281, 1.134791, 0.744193, 1.354346] (the system mass defect (Wikidata Q26897126))" }, { "q": "I need the rest mass of atom for a hydrogen-1 mass of 241.598, a mass defect of 1.13479, an atomic number of 0.744193 and a neutron number of 1.35435, please.", "a": "178.66092284472543", "valid": true, "kind": "compute", "expect": 178.66092284472543, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [241.598281, 1.134791, 0.744193, 1.354346] (the system mass defect (Wikidata Q26897126))" }, { "q": "If the hydrogen-1 mass is 167.625, mass defect is 10.3291 and the atomic number is 2.21571, what is the rest mass of atom?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the neutron number is not given" }, { "q": "Could you work out the rest mass of atom given hydrogen-1 mass = 13.999, mass defect = 0.348438, atomic number = 45.6157?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the neutron number is not given" }, { "q": "Do you know the rest mass of atom 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 rest mass of atom 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 rest mass of atom given hydrogen-1 mass = -246.329, mass defect = 20.3966, atomic number = 18.3169, neutron number = 6.8386?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative hydrogen-1 mass: no example had one" }, { "q": "What is a typical rest mass of atom?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""rest mass of atom from hydrogen-1 mass, mass defect, atomic number, neutron number (mass defect (Wikidata Q26897126))The maths organ (systems.py): solved from the system q3 = q4*q0 + q5*q1 - q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(hydrogen_1_mass, mass_defect, atomic_number, neutron_number): return 1.0*atomic_number*hydrogen_1_mass - 1.0*mass_defect + 1.67492749804e-27*neutron_number12345678910111213141516171819202122232425262728293031"""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, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168{ "title": "rest mass of atom from hydrogen-1 mass, mass defect, atomic number, neutron number (mass defect (Wikidata Q26897126))", "inputs": [ "hydrogen-1 mass (kg)", "mass defect (kg)", "atomic number (1)", "neutron number (1)" ], "output": "rest mass of atom (kg)", "input_kinds": [ "number", "number", "number", "number" ], "expression": "1.0*q0*q4 - 1.0*q3 + 1.67492749804e-27*q5", "expression_x": null, "said": "solved from the system q3 = q4*q0 + q5*q1 - q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q3 = q4*q0 + q5*q1 - q2" ], "constants": { "q1": [ "neutron mass", 1.67492749804e-27, "kg" ] }, "quantities": { "q0": "hydrogen-1 mass (kg)", "q2": "rest mass of atom (kg)", "q3": "mass defect (kg)", "q4": "atomic number (1)", "q5": "neutron number (1)" }, "symbols": [ "q0", "q3", "q4", "q5" ], "out_symbol": "q2" }, "points": [ { "in": [ 107.960666, 59.4105, 5.777165, 1.891256 ], "out": 564.2960385318023 }, { "in": [ 167.624948, 10.329054, 2.215713, 58.534594 ], "out": 361.07974491365565 }, { "in": [ 2.69428, 48.920991, 157.22256, 35.641157 ], "out": 374.68058966653797 }, { "in": [ 13.999029, 0.348438, 45.61567, 4.971307 ], "out": 638.2266485937756 }, { "in": [ 0.551236, 2.88512, 10.563843, 198.838955 ], "out": 2.9380492976499477 }, { "in": [ 246.329053, 20.396558, 18.316867, 6.838598 ], "out": 4491.579956881549 }, { "in": [ 21.793126, 29.510609, 8.503407, 0.58813 ], "out": 155.80521986442068 }, { "in": [ 13.237311, 4.719415, 41.290505, 2.122767 ], "out": 541.8558506889378 }, { "in": [ 7.107049, 30.250749, 308.158051, 178.165518 ], "out": 2159.8436670986293 }, { "in": [ 76.515411, 3.144912, 88.662361, 0.633611 ], "out": 6780.892039067489 }, { "in": [ 34.81508, 0.380269, 25.409711, 20.845641 ], "out": 884.260861631089 }, { "in": [ 241.598281, 1.134791, 0.744193, 1.354346 ], "out": 178.66092284472543 } ], "domain": { "inputs": [ "positive", "positive", "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125{ "id": "solved-rest-mass-of-atom-2", "split": "dev", "decision": "WOULD FAIL", "reasons": [ "DOMAIN: gain 0, needs 3" ], "n": 18, "head": { "ok": 4, "fy": 2, "wrong": 12 }, "with_specialist": { "ok": 4, "fy": 2, "wrong": 12 }, "gain_needed": 3, "core": { "n": 924, "taken": 0, "cap": 9, "examples": [] }, "self_ok": true, "p50_ms": 0.01, "budget_ms": 200.0, "fails": [ { "q": "What is the rest mass of atom for hydrogen-1 mass 107.961, mass defect 59.4105, atomic number 5.77717 and neutron number 1.89126?", "expected": "564.2960385318023", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 107.961, mass defect of 59.4105, atomic number of 5.77717 and neutron number of 1.89126.", "expected": "564.2960385318023", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 2.69428, mass defect 48.921, atomic number 157.223 and neutron number 35.6412?", "expected": "374.68058966653797", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 2.69428, mass defect of 48.921, atomic number of 157.223 and neutron number of 35.6412.", "expected": "374.68058966653797", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 0.551236, mass defect 2.88512, atomic number 10.5638 and neutron number 198.839?", "expected": "2.9380492976499477", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 0.551236, mass defect of 2.88512, atomic number of 10.5638 and neutron number of 198.839.", "expected": "2.9380492976499477", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 21.7931, mass defect 29.5106, atomic number 8.50341 and neutron number 0.58813?", "expected": "155.80521986442068", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 21.7931, mass defect of 29.5106, atomic number of 8.50341 and neutron number of 0.58813.", "expected": "155.80521986442068", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 7.10705, mass defect 30.2507, atomic number 308.158 and neutron number 178.166?", "expected": "2159.8436670986293", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 7.10705, mass defect of 30.2507, atomic number of 308.158 and neutron number of 178.166.", "expected": "2159.8436670986293", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "What is the rest mass of atom for hydrogen-1 mass 34.8151, mass defect 0.380269, atomic number 25.4097 and neutron number 20.8456?", "expected": "884.260861631089", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" }, { "q": "Tell me the rest mass of atom with hydrogen-1 mass of 34.8151, mass defect of 0.380269, atomic number of 25.4097 and neutron number of 20.8456.", "expected": "884.260861631089", "got": "The atomic number of Hydrogen (H) is 1, per PubChem. [chemistry-v3]", "status": "answered", "by": "core" } ], "files_sha": "4f2bb0f162cf3ac0baf2dc2499186a4bc1292c859d0920f54d27572cdca84132", "panel_sha": "9c5bf17a329e3314bff9417dbcc51386eada3dd1a724e6cf0748dd12a42a3ea3", "time": "2026-10-25T01:20:39Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 0, "mode": "full" }}1{"t": "2026-10-25T01:07:48Z", "heldout_sha": "72ce1b458b247ffa80cc767604842e5552fd64d5f26c05c073520b6d5cd61615", "files_sha": "a085d29370fcf1ee6e715b4df238d758dfbe4dd0c193b08c5d943285c253b7a6"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-rest-mass-of-atom", "name": "Solved: rest mass of atom from mass excess, mass number (mass excess (Wikidata Q1571163))", "sources": [ { "name": "the maths organ: solved from the system q2 = q0 - q3*q1; 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": "\\brest\\ mass\\ of\\ atom\\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 mass excess (Wikidata Q1571163): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the rest mass of atom for mass excess and mass number?" ], "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 rest mass of atom for mass excess 107.961 and mass number 59.4105?", "a": "107.96066588996202", "valid": true, "kind": "compute", "expect": 107.96066588996202, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [107.960666, 59.4105] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 107.961 and mass number of 59.4105.", "a": "107.96066588996202", "valid": true, "kind": "compute", "expect": 107.96066588996202, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [107.960666, 59.4105] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 169.527 and mass number 280.774?", "a": "169.5269575388401", "valid": true, "kind": "compute", "expect": 169.5269575388401, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [169.526958, 280.773702] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 169.527 and mass number of 280.774.", "a": "169.5269575388401", "valid": true, "kind": "compute", "expect": 169.5269575388401, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [169.526958, 280.773702] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 1.91195 and mass number 82.2401?", "a": "1.911951762986252", "valid": true, "kind": "compute", "expect": 1.911951762986252, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [1.911952, 82.240072] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 1.91195 and mass number of 82.2401.", "a": "1.911951762986252", "valid": true, "kind": "compute", "expect": 1.911951762986252, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [1.911952, 82.240072] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 1.64379 and mass number 252.709?", "a": "1.6437954948627898", "valid": true, "kind": "compute", "expect": 1.6437954948627898, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [1.643795, 252.709024] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 1.64379 and mass number of 252.709.", "a": "1.6437954948627898", "valid": true, "kind": "compute", "expect": 1.6437954948627898, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [1.643795, 252.709024] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 18.3169 and mass number 6.8386?", "a": "18.31686702277652", "valid": true, "kind": "compute", "expect": 18.31686702277652, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [18.316867, 6.838598] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 18.3169 and mass number of 6.8386.", "a": "18.31686702277652", "valid": true, "kind": "compute", "expect": 18.31686702277652, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [18.316867, 6.838598] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 156.502 and mass number 185.886?", "a": "156.50180977998866", "valid": true, "kind": "compute", "expect": 156.50180977998866, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [156.50181, 185.886273] (the system mass excess (Wikidata Q1571163))" }, { "q": "Tell me the rest mass of atom with mass excess of 156.502 and mass number of 185.886.", "a": "156.50180977998866", "valid": true, "kind": "compute", "expect": 156.50180977998866, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [156.50181, 185.886273] (the system mass excess (Wikidata Q1571163))" }, { "q": "What is the rest mass of atom for mass excess 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mass number is not given" }, { "q": "Tell me the rest mass of atom with mass excess of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mass number is not given" }, { "q": "What is the rest mass of atom 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 rest mass of atom 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 rest mass of atom with mass excess of -1.91195 and mass number of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative mass excess: no example had one" }, { "q": "Which rest mass of atom 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 mass excess is 8.50728 and the mass number is 17.7888, what is the rest mass of atom?", "a": "8.507282654040921", "valid": true, "kind": "compute", "expect": 8.507282654040921, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [8.507283, 17.788778] (the system mass excess (Wikidata Q1571163))" }, { "q": "Could you work out the rest mass of atom given mass excess = 8.50728, mass number = 17.7888?", "a": "8.507282654040921", "valid": true, "kind": "compute", "expect": 8.507282654040921, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [8.507283, 17.788778] (the system mass excess (Wikidata Q1571163))" }, { "q": "I need the rest mass of atom for a mass excess of 8.24951 and a mass number of 0.634021, please.", "a": "8.249509867687042", "valid": true, "kind": "compute", "expect": 8.249509867687042, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [8.24951, 0.634021] (the system mass excess (Wikidata Q1571163))" }, { "q": "If the mass excess is 8.24951 and the mass number is 0.634021, what is the rest mass of atom?", "a": "8.249509867687042", "valid": true, "kind": "compute", "expect": 8.249509867687042, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [8.24951, 0.634021] (the system mass excess (Wikidata Q1571163))" }, { "q": "Could you work out the rest mass of atom given mass excess = 0.318734, mass number = 9.56607?", "a": "0.3187340476516735", "valid": true, "kind": "compute", "expect": 0.3187340476516735, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.318734, 9.566071] (the system mass excess (Wikidata Q1571163))" }, { "q": "I need the rest mass of atom for a mass excess of 0.318734 and a mass number of 9.56607, please.", "a": "0.3187340476516735", "valid": true, "kind": "compute", "expect": 0.3187340476516735, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.318734, 9.566071] (the system mass excess (Wikidata Q1571163))" }, { "q": "If the mass excess is 0.671697 and the mass number is 14.2496, what is the rest mass of atom?", "a": "0.6716971997941935", "valid": true, "kind": "compute", "expect": 0.6716971997941935, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.671697, 14.249569] (the system mass excess (Wikidata Q1571163))" }, { "q": "Could you work out the rest mass of atom given mass excess = 0.671697, mass number = 14.2496?", "a": "0.6716971997941935", "valid": true, "kind": "compute", "expect": 0.6716971997941935, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [0.671697, 14.249569] (the system mass excess (Wikidata Q1571163))" }, { "q": "I need the rest mass of atom for a mass excess of 21.7931 and a mass number of 29.5106, please.", "a": "21.793126492285822", "valid": true, "kind": "compute", "expect": 21.793126492285822, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [21.793126, 29.510609] (the system mass excess (Wikidata Q1571163))" }, { "q": "If the mass excess is 21.7931 and the mass number is 29.5106, what is the rest mass of atom?", "a": "21.793126492285822", "valid": true, "kind": "compute", "expect": 21.793126492285822, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [21.793126, 29.510609] (the system mass excess (Wikidata Q1571163))" }, { "q": "Could you work out the rest mass of atom given mass excess = 153.15, mass number = 18.5953?", "a": "153.14996513701908", "valid": true, "kind": "compute", "expect": 153.14996513701908, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [153.149965, 18.595315] (the system mass excess (Wikidata Q1571163))" }, { "q": "I need the rest mass of atom for a mass excess of 153.15 and a mass number of 18.5953, please.", "a": "153.14996513701908", "valid": true, "kind": "compute", "expect": 153.14996513701908, "dtype": "quantity", "unit": "kg", "why": "rest mass of atom for [153.149965, 18.595315] (the system mass excess (Wikidata Q1571163))" }, { "q": "If the mass excess is 8.50728, what is the rest mass of atom?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mass number is not given" }, { "q": "Could you work out the rest mass of atom given mass excess = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mass number is not given" }, { "q": "Do you know the rest mass of atom 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 rest mass of atom 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 rest mass of atom given mass excess = -0.318734, mass number = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative mass excess: no example had one" }, { "q": "What is a typical rest mass of atom?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""rest mass of atom from mass excess, mass number (mass excess (Wikidata Q1571163))The maths organ (systems.py): solved from the system q2 = q0 - q3*q1; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(mass_excess, mass_number): return 1.0*mass_excess + 1.6605390666e-27*mass_number12345678910111213141516171819202122232425262728293031"""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, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134{ "title": "rest mass of atom from mass excess, mass number (mass excess (Wikidata Q1571163))", "inputs": [ "mass excess (kg)", "mass number (1)" ], "output": "rest mass of atom (kg)", "input_kinds": [ "number", "number" ], "expression": "1.0*q2 + 1.6605390666e-27*q3", "expression_x": null, "said": "solved from the system q2 = q0 - q3*q1; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q2 = q0 - q3*q1" ], "constants": { "q1": [ "unified atomic mass constant", 1.6605390666e-27, "kg" ] }, "quantities": { "q0": "rest mass of atom (kg)", "q2": "mass excess (kg)", "q3": "mass number (1)" }, "symbols": [ "q2", "q3" ], "out_symbol": "q0" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 107.96066588996202 }, { "in": [ 8.507283, 17.788778 ], "out": 8.507282654040921 }, { "in": [ 169.526958, 280.773702 ], "out": 169.5269575388401 }, { "in": [ 8.24951, 0.634021 ], "out": 8.249509867687042 }, { "in": [ 1.911952, 82.240072 ], "out": 1.911951762986252 }, { "in": [ 0.318734, 9.566071 ], "out": 0.3187340476516735 }, { "in": [ 1.643795, 252.709024 ], "out": 1.6437954948627898 }, { "in": [ 0.671697, 14.249569 ], "out": 0.6716971997941935 }, { "in": [ 18.316867, 6.838598 ], "out": 18.31686702277652 }, { "in": [ 21.793126, 29.510609 ], "out": 21.793126492285822 }, { "in": [ 156.50181, 185.886273 ], "out": 156.50180977998866 }, { "in": [ 153.149965, 18.595315 ], "out": 153.14996513701908 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-rest-mass-of-atom", "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": "a085d29370fcf1ee6e715b4df238d758dfbe4dd0c193b08c5d943285c253b7a6", "panel_sha": "8020840d47f926f5d318ff2beb0919cd70624331d63d22ac6855ab67f5984c49", "time": "2026-10-25T01:07:48Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-rest-mass-of-atom", "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": "a085d29370fcf1ee6e715b4df238d758dfbe4dd0c193b08c5d943285c253b7a6", "panel_sha": "72ce1b458b247ffa80cc767604842e5552fd64d5f26c05c073520b6d5cd61615", "time": "2026-10-25T01:07:49Z", "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-25T01:18:34Z", "heldout_sha": "7b4e03147fbd8b935d4814a0a00a060de84c62299cc80730ef1421117ab32711", "files_sha": "498ee76e6cdbacad2c3ca29cb0ac3ddfade42c211f13ffe545399079709ec6c5"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-rest-mass", "name": "Solved: rest mass from rest energy (rest energy (Wikidata Q11663629))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1*q2 **(2); 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": "\\brest\\ mass\\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 rest energy (Wikidata Q11663629): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the rest mass for rest 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 rest mass for rest energy 107.961?", "a": "2.2305922704537617e-15", "valid": true, "kind": "compute", "expect": 2.2305922704537617e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [107.960666] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 107.961.", "a": "2.2305922704537617e-15", "valid": true, "kind": "compute", "expect": 2.2305922704537617e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [107.960666] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass for rest energy 22.652?", "a": "4.680169999350373e-16", "valid": true, "kind": "compute", "expect": 4.680169999350373e-16, "dtype": "quantity", "unit": "kg", "why": "rest mass for [22.652023] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 22.652.", "a": "4.680169999350373e-16", "valid": true, "kind": "compute", "expect": 4.680169999350373e-16, "dtype": "quantity", "unit": "kg", "why": "rest mass for [22.652023] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass for rest energy 173.394?", "a": "3.582513190192202e-15", "valid": true, "kind": "compute", "expect": 3.582513190192202e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [173.393638] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 173.394.", "a": "3.582513190192202e-15", "valid": true, "kind": "compute", "expect": 3.582513190192202e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [173.393638] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass for rest energy 126.709?", "a": "2.617959747937654e-15", "valid": true, "kind": "compute", "expect": 2.617959747937654e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [126.709252] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 126.709.", "a": "2.617959747937654e-15", "valid": true, "kind": "compute", "expect": 2.617959747937654e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [126.709252] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass for rest energy 0.671697?", "a": "1.3878041318061857e-17", "valid": true, "kind": "compute", "expect": 1.3878041318061857e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [0.671697] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 0.671697.", "a": "1.3878041318061857e-17", "valid": true, "kind": "compute", "expect": 1.3878041318061857e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [0.671697] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass for rest energy 1.16997?", "a": "2.4172892685494553e-17", "valid": true, "kind": "compute", "expect": 2.4172892685494553e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [1.169968] (the system rest energy (Wikidata Q11663629))" }, { "q": "Tell me the rest mass with rest energy of 1.16997.", "a": "2.4172892685494553e-17", "valid": true, "kind": "compute", "expect": 2.4172892685494553e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [1.169968] (the system rest energy (Wikidata Q11663629))" }, { "q": "What is the rest mass?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest energy is not given" }, { "q": "Could you work out the rest mass, please?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest energy is not given" }, { "q": "What is the rest mass 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 rest mass 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 rest mass with rest energy of -173.394.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative rest energy: no example had one" }, { "q": "Which rest mass 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 rest energy is 2.57003, what is the rest mass?", "a": "5.309979159718275e-17", "valid": true, "kind": "compute", "expect": 5.309979159718275e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [2.57003] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest mass given rest energy = 2.57003?", "a": "5.309979159718275e-17", "valid": true, "kind": "compute", "expect": 5.309979159718275e-17, "dtype": "quantity", "unit": "kg", "why": "rest mass for [2.57003] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest mass for a rest energy of 48.921, please.", "a": "1.0107642739671871e-15", "valid": true, "kind": "compute", "expect": 1.0107642739671871e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [48.920991] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest energy is 48.921, what is the rest mass?", "a": "1.0107642739671871e-15", "valid": true, "kind": "compute", "expect": 1.0107642739671871e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [48.920991] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest mass given rest energy = 0.348438?", "a": "7.199125405579145e-18", "valid": true, "kind": "compute", "expect": 7.199125405579145e-18, "dtype": "quantity", "unit": "kg", "why": "rest mass for [0.348438] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest mass for a rest energy of 0.348438, please.", "a": "7.199125405579145e-18", "valid": true, "kind": "compute", "expect": 7.199125405579145e-18, "dtype": "quantity", "unit": "kg", "why": "rest mass for [0.348438] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest energy is 252.709, what is the rest mass?", "a": "5.221260831601811e-15", "valid": true, "kind": "compute", "expect": 5.221260831601811e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [252.709024] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest mass given rest energy = 252.709?", "a": "5.221260831601811e-15", "valid": true, "kind": "compute", "expect": 5.221260831601811e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [252.709024] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest mass for a rest energy of 20.3966, please.", "a": "4.214164868174266e-16", "valid": true, "kind": "compute", "expect": 4.214164868174266e-16, "dtype": "quantity", "unit": "kg", "why": "rest mass for [20.396558] (the system rest energy (Wikidata Q11663629))" }, { "q": "If the rest energy is 20.3966, what is the rest mass?", "a": "4.214164868174266e-16", "valid": true, "kind": "compute", "expect": 4.214164868174266e-16, "dtype": "quantity", "unit": "kg", "why": "rest mass for [20.396558] (the system rest energy (Wikidata Q11663629))" }, { "q": "Could you work out the rest mass given rest energy = 134.993?", "a": "2.7891106938169023e-15", "valid": true, "kind": "compute", "expect": 2.7891106938169023e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [134.992958] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest mass for a rest energy of 134.993, please.", "a": "2.7891106938169023e-15", "valid": true, "kind": "compute", "expect": 2.7891106938169023e-15, "dtype": "quantity", "unit": "kg", "why": "rest mass for [134.992958] (the system rest energy (Wikidata Q11663629))" }, { "q": "I need the rest mass, please.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest energy is not given" }, { "q": "Can you tell me the rest mass?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the rest energy is not given" }, { "q": "Do you know the rest mass 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 rest mass 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 rest mass given rest energy = -0.348438?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative rest energy: no example had one" }, { "q": "What is a typical rest mass?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""rest mass from rest energy (rest energy (Wikidata Q11663629))The maths organ (systems.py): solved from the system q0 = q1*q2 **(2); checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(rest_energy): return 2.06611570247934e-17*rest_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, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117{ "title": "rest mass from rest energy (rest energy (Wikidata Q11663629))", "inputs": [ "rest energy (J)" ], "output": "rest mass (kg)", "input_kinds": [ "number" ], "expression": "2.06611570247934e-17*q0", "expression_x": null, "said": "solved from the system q0 = q1*q2 **(2); 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 **(2)" ], "constants": { "q2": [ "speed of light in vacuum", 220000000.0, "m/s" ] }, "quantities": { "q0": "rest energy (J)", "q1": "rest mass (kg)" }, "symbols": [ "q0" ], "out_symbol": "q1" }, "points": [ { "in": [ 107.960666 ], "out": 2.2305922704537617e-15 }, { "in": [ 2.57003 ], "out": 5.309979159718275e-17 }, { "in": [ 22.652023 ], "out": 4.680169999350373e-16 }, { "in": [ 48.920991 ], "out": 1.0107642739671871e-15 }, { "in": [ 173.393638 ], "out": 3.582513190192202e-15 }, { "in": [ 0.348438 ], "out": 7.199125405579145e-18 }, { "in": [ 126.709252 ], "out": 2.617959747937654e-15 }, { "in": [ 252.709024 ], "out": 5.221260831601811e-15 }, { "in": [ 0.671697 ], "out": 1.3878041318061857e-17 }, { "in": [ 20.396558 ], "out": 4.214164868174266e-16 }, { "in": [ 1.169968 ], "out": 2.4172892685494553e-17 }, { "in": [ 134.992958 ], "out": 2.7891106938169023e-15 } ], "domain": { "inputs": [ "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-rest-mass", "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": "498ee76e6cdbacad2c3ca29cb0ac3ddfade42c211f13ffe545399079709ec6c5", "panel_sha": "a4b3eacf459609179c4108b9605360cbc03aa816d33dd18b436cddf8dec0509b", "time": "2026-10-25T01:18:34Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-rest-mass", "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": "498ee76e6cdbacad2c3ca29cb0ac3ddfade42c211f13ffe545399079709ec6c5", "panel_sha": "7b4e03147fbd8b935d4814a0a00a060de84c62299cc80730ef1421117ab32711", "time": "2026-10-25T01:18:34Z", "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"}root/organs10/physics/specialists/solved-resistivity-tensor/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-resistivity-tensor/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-resistivity-tensor/panel.jsonAdded+366
root/organs10/physics/specialists/solved-resistivity-tensor/program.pyAdded+7
root/organs10/physics/specialists/solved-resistivity-tensor/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-resistivity-tensor/spec.jsonAdded+128
root/organs10/physics/specialists/solved-resistivity-tensor/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-resistivity-tensor/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-rest-energy/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-rest-energy/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-rest-energy/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-rest-energy/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-rest-energy/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-rest-energy/panel.jsonAdded+366
root/organs10/physics/specialists/solved-rest-energy/program.pyAdded+7
root/organs10/physics/specialists/solved-rest-energy/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-rest-energy/spec.jsonAdded+117
root/organs10/physics/specialists/solved-rest-energy/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-rest-energy/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/panel.jsonAdded+366
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/program.pyAdded+7
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/spec.jsonAdded+168
root/organs10/physics/specialists/solved-rest-mass-of-atom-2/verdict_dev.jsonAdded+125
root/organs10/physics/specialists/solved-rest-mass-of-atom/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-rest-mass-of-atom/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-rest-mass-of-atom/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-rest-mass-of-atom/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-rest-mass-of-atom/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-rest-mass-of-atom/panel.jsonAdded+366
root/organs10/physics/specialists/solved-rest-mass-of-atom/program.pyAdded+7
root/organs10/physics/specialists/solved-rest-mass-of-atom/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-rest-mass-of-atom/spec.jsonAdded+134
root/organs10/physics/specialists/solved-rest-mass-of-atom/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-rest-mass-of-atom/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-rest-mass/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-rest-mass/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-rest-mass/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-rest-mass/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-rest-mass/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-rest-mass/panel.jsonAdded+366
root/organs10/physics/specialists/solved-rest-mass/program.pyAdded+7
root/organs10/physics/specialists/solved-rest-mass/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-rest-mass/spec.jsonAdded+117
root/organs10/physics/specialists/solved-rest-mass/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-rest-mass/verdict_heldout.jsonAdded+39