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 9)
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-distance-9/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-distance-9/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-distance-9/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-distance-9/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-distance-9/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-distance-9/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-distance-9/program.pyAdded+7
- root/organs10/physics/specialists/solved-distance-9/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-distance-9/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-distance-9/verdict_dev.jsonAdded+40
- root/organs10/physics/specialists/solved-distance-9/verdict_heldout.jsonAdded+33
- root/organs10/physics/specialists/solved-dose-equivalent/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-dose-equivalent/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-dose-equivalent/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-dose-equivalent/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-dose-equivalent/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-dose-equivalent/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-dose-equivalent/program.pyAdded+7
- root/organs10/physics/specialists/solved-dose-equivalent/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-dose-equivalent/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-dose-equivalent/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-dose-equivalent/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-drift-velocity/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-drift-velocity/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-drift-velocity/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-drift-velocity/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-drift-velocity/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-drift-velocity/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-drift-velocity/program.pyAdded+7
- root/organs10/physics/specialists/solved-drift-velocity/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-drift-velocity/spec.jsonAdded+128
- root/organs10/physics/specialists/solved-drift-velocity/verdict_dev.jsonAdded+38
- root/organs10/physics/specialists/solved-drift-velocity/verdict_heldout.jsonAdded+39
- root/organs10/physics/specialists/solved-drop-height-2/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-drop-height-2/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-drop-height-2/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-drop-height-2/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-drop-height-2/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-drop-height-2/panel.jsonAdded+366
- root/organs10/physics/specialists/solved-drop-height-2/program.pyAdded+7
- root/organs10/physics/specialists/solved-drop-height-2/scorer_formula_v1.pyAdded+31
- root/organs10/physics/specialists/solved-drop-height-2/spec.jsonAdded+119
- root/organs10/physics/specialists/solved-drop-height-2/verdict_dev.jsonAdded+32
- root/organs10/physics/specialists/solved-drop-height-2/verdict_heldout.jsonAdded+33
- root/organs10/physics/specialists/solved-drop-height/exam_log.jsonlAdded+1
- root/organs10/physics/specialists/solved-drop-height/manifest.jsonAdded+41
- root/organs10/physics/specialists/solved-drop-height/narrow_v1.pyAdded+47
- root/organs10/physics/specialists/solved-drop-height/organ_formula_v2.pyAdded+163
- root/organs10/physics/specialists/solved-drop-height/organ_formula_v3.pyAdded+205
- root/organs10/physics/specialists/solved-drop-height/panel.jsonAdded+366
1{"t": "2026-10-24T00:36:30Z", "heldout_sha": "087a766fddac25f714904b405c10b2de0a93dfa17d5e4659a937bf49bfc09fe3", "files_sha": "cf7a443f588fbb4eedc24267740baf07942e8ee4b402c76ad9fb4a48907eb4a0"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-distance-9", "name": "Solved: distance from speed, time (Average speed)", "sources": [ { "name": "the maths organ: solved from the system v = d/t; 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": "\\bdistance\\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 Average speed: 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the distance for speed and time?" ], "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 distance for speed 107.961 and time 59.4105?", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "km", "why": "distance for [107.960666, 59.4105] (the system Average speed)" }, { "q": "Tell me the distance with speed of 107.961 and time of 59.4105.", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "km", "why": "distance for [107.960666, 59.4105] (the system Average speed)" }, { "q": "What is the distance for speed 169.527 and time 280.774?", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "km", "why": "distance for [169.526958, 280.773702] (the system Average speed)" }, { "q": "Tell me the distance with speed of 169.527 and time of 280.774.", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "km", "why": "distance for [169.526958, 280.773702] (the system Average speed)" }, { "q": "What is the distance for speed 1.91195 and time 82.2401?", "a": "157.23905034769405", "valid": true, "kind": "compute", "expect": 157.23905034769405, "dtype": "quantity", "unit": "km", "why": "distance for [1.911952, 82.240072] (the system Average speed)" }, { "q": "Tell me the distance with speed of 1.91195 and time of 82.2401.", "a": "157.23905034769405", "valid": true, "kind": "compute", "expect": 157.23905034769405, "dtype": "quantity", "unit": "km", "why": "distance for [1.911952, 82.240072] (the system Average speed)" }, { "q": "What is the distance for speed 1.64379 and time 252.709?", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "km", "why": "distance for [1.643795, 252.709024] (the system Average speed)" }, { "q": "Tell me the distance with speed of 1.64379 and time of 252.709.", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "km", "why": "distance for [1.643795, 252.709024] (the system Average speed)" }, { "q": "What is the distance for speed 18.3169 and time 6.8386?", "a": "125.26169131331939", "valid": true, "kind": "compute", "expect": 125.26169131331939, "dtype": "quantity", "unit": "km", "why": "distance for [18.316867, 6.838598] (the system Average speed)" }, { "q": "Tell me the distance with speed of 18.3169 and time of 6.8386.", "a": "125.26169131331939", "valid": true, "kind": "compute", "expect": 125.26169131331939, "dtype": "quantity", "unit": "km", "why": "distance for [18.316867, 6.838598] (the system Average speed)" }, { "q": "What is the distance for speed 156.502 and time 185.886?", "a": "29091.538105177147", "valid": true, "kind": "compute", "expect": 29091.538105177147, "dtype": "quantity", "unit": "km", "why": "distance for [156.50181, 185.886273] (the system Average speed)" }, { "q": "Tell me the distance with speed of 156.502 and time of 185.886.", "a": "29091.538105177147", "valid": true, "kind": "compute", "expect": 29091.538105177147, "dtype": "quantity", "unit": "km", "why": "distance for [156.50181, 185.886273] (the system Average speed)" }, { "q": "What is the distance for speed 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the time is not given" }, { "q": "Tell me the distance with speed of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the time is not given" }, { "q": "What is the distance 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 distance 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 distance with speed of -1.91195 and time of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative speed: no example had one" }, { "q": "Which distance 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 speed is 8.50728 and the time is 17.7888, what is the distance?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "km", "why": "distance for [8.507283, 17.788778] (the system Average speed)" }, { "q": "Could you work out the distance given speed = 8.50728, time = 17.7888?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "km", "why": "distance for [8.507283, 17.788778] (the system Average speed)" }, { "q": "I need the distance for a speed of 8.24951 and a time of 0.634021, please.", "a": "5.230362271972725", "valid": true, "kind": "compute", "expect": 5.230362271972725, "dtype": "quantity", "unit": "km", "why": "distance for [8.24951, 0.634021] (the system Average speed)" }, { "q": "If the speed is 8.24951 and the time is 0.634021, what is the distance?", "a": "5.230362271972725", "valid": true, "kind": "compute", "expect": 5.230362271972725, "dtype": "quantity", "unit": "km", "why": "distance for [8.24951, 0.634021] (the system Average speed)" }, { "q": "Could you work out the distance given speed = 0.318734, time = 9.56607?", "a": "3.049032526346269", "valid": true, "kind": "compute", "expect": 3.049032526346269, "dtype": "quantity", "unit": "km", "why": "distance for [0.318734, 9.566071] (the system Average speed)" }, { "q": "I need the distance for a speed of 0.318734 and a time of 9.56607, please.", "a": "3.049032526346269", "valid": true, "kind": "compute", "expect": 3.049032526346269, "dtype": "quantity", "unit": "km", "why": "distance for [0.318734, 9.566071] (the system Average speed)" }, { "q": "If the speed is 0.671697 and the time is 14.2496, what is the distance?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "km", "why": "distance for [0.671697, 14.249569] (the system Average speed)" }, { "q": "Could you work out the distance given speed = 0.671697, time = 14.2496?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "km", "why": "distance for [0.671697, 14.249569] (the system Average speed)" }, { "q": "I need the distance for a speed of 21.7931 and a time of 29.5106, please.", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "km", "why": "distance for [21.793126, 29.510609] (the system Average speed)" }, { "q": "If the speed is 21.7931 and the time is 29.5106, what is the distance?", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "km", "why": "distance for [21.793126, 29.510609] (the system Average speed)" }, { "q": "Could you work out the distance given speed = 153.15, time = 18.5953?", "a": "2847.8719160673327", "valid": true, "kind": "compute", "expect": 2847.8719160673327, "dtype": "quantity", "unit": "km", "why": "distance for [153.149965, 18.595315] (the system Average speed)" }, { "q": "I need the distance for a speed of 153.15 and a time of 18.5953, please.", "a": "2847.8719160673327", "valid": true, "kind": "compute", "expect": 2847.8719160673327, "dtype": "quantity", "unit": "km", "why": "distance for [153.149965, 18.595315] (the system Average speed)" }, { "q": "If the speed is 8.50728, what is the distance?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the time is not given" }, { "q": "Could you work out the distance given speed = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the time is not given" }, { "q": "Do you know the distance 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 distance 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 distance given speed = -0.318734, time = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative speed: no example had one" }, { "q": "What is a typical distance?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""distance from speed, time (Average speed)The maths organ (systems.py): solved from the system v = d/t; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(speed, time): return 1.0*speed*time12345678910111213141516171819202122232425262728293031"""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": "distance from speed, time (Average speed)", "inputs": [ "speed (km/h)", "time (h)" ], "output": "distance (km)", "input_kinds": [ "number", "number" ], "expression": "1.0*t*v", "expression_x": null, "said": "solved from the system v = d/t; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "v = d/t" ], "constants": {}, "quantities": { "v": "speed (km/h)", "d": "distance (km)", "t": "time (h)" }, "symbols": [ "v", "t" ], "out_symbol": "d" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 6413.997161494573 }, { "in": [ 8.507283, 17.788778 ], "out": 151.33416360087082 }, { "in": [ 169.526958, 280.773702 ], "out": 47598.71144694985 }, { "in": [ 8.24951, 0.634021 ], "out": 5.230362271972725 }, { "in": [ 1.911952, 82.240072 ], "out": 157.23905034769405 }, { "in": [ 0.318734, 9.566071 ], "out": 3.049032526346269 }, { "in": [ 1.643795, 252.709024 ], "out": 415.4019555725448 }, { "in": [ 0.671697, 14.249569 ], "out": 9.571395807788361 }, { "in": [ 18.316867, 6.838598 ], "out": 125.26169131331939 }, { "in": [ 21.793126, 29.510609 ], "out": 643.1284273894521 }, { "in": [ 156.50181, 185.886273 ], "out": 29091.538105177147 }, { "in": [ 153.149965, 18.595315 ], "out": 2847.8719160673327 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}12345678910111213141516171819202122232425262728293031323334353637383940{ "id": "solved-distance-9", "split": "dev", "decision": "WOULD PASS", "reasons": [], "n": 18, "head": { "ok": 5, "fy": 1, "wrong": 0 }, "with_specialist": { "ok": 17, "fy": 1, "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": [ { "q": "What is the distance of the Eiffel Tower?", "expected": "", "got": "100. It was supposed to be a temporary installation for the 1889 World Fair, held at Paris to show respect to 100 years of the French Revolution. [simplewiki_f1", "status": "answered", "by": "core" } ], "files_sha": "cf7a443f588fbb4eedc24267740baf07942e8ee4b402c76ad9fb4a48907eb4a0", "panel_sha": "c0b4363001cb4d82a3bc22e9f1b9c99d03395cd999c15cae1ee96044f74c10aa", "time": "2026-10-24T00:36:30Z", "core_head": "oracle_release_runtime_w571"}123456789101112131415161718192021222324252627282930313233{ "id": "solved-distance-9", "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": "cf7a443f588fbb4eedc24267740baf07942e8ee4b402c76ad9fb4a48907eb4a0", "panel_sha": "087a766fddac25f714904b405c10b2de0a93dfa17d5e4659a937bf49bfc09fe3", "time": "2026-10-24T00:36:33Z", "core_head": "oracle_release_runtime_w571", "memory": "written to your group's memory"}1{"t": "2026-10-25T01:20:21Z", "heldout_sha": "17fc953bb009fa95f0ca134d7e258afb8dd368bd65e9db216564aa32ccc9746d", "files_sha": "006b39fa2d8d485fa0f7d5679fea3a5254d0ead1097b90fa188c2e205099bb30"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-dose-equivalent", "name": "Solved: dose equivalent from quality factor, absorbed dose (dose equivalent (Wikidata Q256106))", "sources": [ { "name": "the maths organ: solved from the system q0 = q1*q2; checked by substitution into every equation and by a numeric solution at 12 points", "licence": "yours" } ], "organ": { "module": "organ_formula_v3", "class": "FormulaOrgan", "init": {} }, "accept": { "kinds": [ "compute" ], "declines_in_domain": [ "missing_input", "out_of_domain" ], "context_regex": "\\bdose\\ equivalent\\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 dose equivalent (Wikidata Q256106): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the dose equivalent for quality factor and absorbed dose?" ], "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 dose equivalent for quality factor 107.961 and absorbed dose 59.4105?", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [107.960666, 59.4105] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 107.961 and absorbed dose of 59.4105.", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [107.960666, 59.4105] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 169.527 and absorbed dose 280.774?", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [169.526958, 280.773702] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 169.527 and absorbed dose of 280.774.", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [169.526958, 280.773702] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 1.91195 and absorbed dose 82.2401?", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [1.911952, 82.240072] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 1.91195 and absorbed dose of 82.2401.", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [1.911952, 82.240072] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 1.64379 and absorbed dose 252.709?", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [1.643795, 252.709024] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 1.64379 and absorbed dose of 252.709.", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [1.643795, 252.709024] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 18.3169 and absorbed dose 6.8386?", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [18.316867, 6.838598] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 18.3169 and absorbed dose of 6.8386.", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [18.316867, 6.838598] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 156.502 and absorbed dose 185.886?", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [156.50181, 185.886273] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Tell me the dose equivalent with quality factor of 156.502 and absorbed dose of 185.886.", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [156.50181, 185.886273] (the system dose equivalent (Wikidata Q256106))" }, { "q": "What is the dose equivalent for quality factor 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the absorbed dose is not given" }, { "q": "Tell me the dose equivalent with quality factor of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the absorbed dose is not given" }, { "q": "What is the dose equivalent 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 dose equivalent 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 dose equivalent with quality factor of -1.91195 and absorbed dose of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative quality factor: no example had one" }, { "q": "Which dose equivalent 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 quality factor is 8.50728 and the absorbed dose is 17.7888, what is the dose equivalent?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [8.507283, 17.788778] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Could you work out the dose equivalent given quality factor = 8.50728, absorbed dose = 17.7888?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [8.507283, 17.788778] (the system dose equivalent (Wikidata Q256106))" }, { "q": "I need the dose equivalent for a quality factor of 8.24951 and an absorbed dose of 0.634021, please.", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [8.24951, 0.634021] (the system dose equivalent (Wikidata Q256106))" }, { "q": "If the quality factor is 8.24951 and the absorbed dose is 0.634021, what is the dose equivalent?", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [8.24951, 0.634021] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Could you work out the dose equivalent given quality factor = 0.318734, absorbed dose = 9.56607?", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [0.318734, 9.566071] (the system dose equivalent (Wikidata Q256106))" }, { "q": "I need the dose equivalent for a quality factor of 0.318734 and an absorbed dose of 9.56607, please.", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [0.318734, 9.566071] (the system dose equivalent (Wikidata Q256106))" }, { "q": "If the quality factor is 0.671697 and the absorbed dose is 14.2496, what is the dose equivalent?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [0.671697, 14.249569] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Could you work out the dose equivalent given quality factor = 0.671697, absorbed dose = 14.2496?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [0.671697, 14.249569] (the system dose equivalent (Wikidata Q256106))" }, { "q": "I need the dose equivalent for a quality factor of 21.7931 and an absorbed dose of 29.5106, please.", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [21.793126, 29.510609] (the system dose equivalent (Wikidata Q256106))" }, { "q": "If the quality factor is 21.7931 and the absorbed dose is 29.5106, what is the dose equivalent?", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [21.793126, 29.510609] (the system dose equivalent (Wikidata Q256106))" }, { "q": "Could you work out the dose equivalent given quality factor = 153.15, absorbed dose = 18.5953?", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [153.149965, 18.595315] (the system dose equivalent (Wikidata Q256106))" }, { "q": "I need the dose equivalent for a quality factor of 153.15 and an absorbed dose of 18.5953, please.", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "m^2/s^2", "why": "dose equivalent for [153.149965, 18.595315] (the system dose equivalent (Wikidata Q256106))" }, { "q": "If the quality factor is 8.50728, what is the dose equivalent?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the absorbed dose is not given" }, { "q": "Could you work out the dose equivalent given quality factor = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the absorbed dose is not given" }, { "q": "Do you know the dose equivalent 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 dose equivalent 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 dose equivalent given quality factor = -0.318734, absorbed dose = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative quality factor: no example had one" }, { "q": "What is a typical dose equivalent?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""dose equivalent from quality factor, absorbed dose (dose equivalent (Wikidata Q256106))The maths organ (systems.py): solved from the system q0 = q1*q2; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(quality_factor, absorbed_dose): return 1.0*absorbed_dose*quality_factor12345678910111213141516171819202122232425262728293031"""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": "dose equivalent from quality factor, absorbed dose (dose equivalent (Wikidata Q256106))", "inputs": [ "quality factor (1)", "absorbed dose (m^2/s^2)" ], "output": "dose equivalent (m^2/s^2)", "input_kinds": [ "number", "number" ], "expression": "1.0*q1*q2", "expression_x": null, "said": "solved from the system q0 = q1*q2; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q1*q2" ], "constants": {}, "quantities": { "q0": "dose equivalent (m^2/s^2)", "q1": "quality factor (1)", "q2": "absorbed dose (m^2/s^2)" }, "symbols": [ "q1", "q2" ], "out_symbol": "q0" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 6413.997161494573 }, { "in": [ 8.507283, 17.788778 ], "out": 151.33416360087082 }, { "in": [ 169.526958, 280.773702 ], "out": 47598.71144694985 }, { "in": [ 8.24951, 0.634021 ], "out": 5.230362271972724 }, { "in": [ 1.911952, 82.240072 ], "out": 157.23905034769402 }, { "in": [ 0.318734, 9.566071 ], "out": 3.0490325263462696 }, { "in": [ 1.643795, 252.709024 ], "out": 415.4019555725448 }, { "in": [ 0.671697, 14.249569 ], "out": 9.571395807788361 }, { "in": [ 18.316867, 6.838598 ], "out": 125.26169131331936 }, { "in": [ 21.793126, 29.510609 ], "out": 643.1284273894521 }, { "in": [ 156.50181, 185.886273 ], "out": 29091.53810517715 }, { "in": [ 153.149965, 18.595315 ], "out": 2847.871916067332 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-dose-equivalent", "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": "006b39fa2d8d485fa0f7d5679fea3a5254d0ead1097b90fa188c2e205099bb30", "panel_sha": "ba803ca074f586ecfadfa41c67fe37b387d541a98727cb6af68ad2ec9f4b224e", "time": "2026-10-25T01:20:21Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-dose-equivalent", "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": "006b39fa2d8d485fa0f7d5679fea3a5254d0ead1097b90fa188c2e205099bb30", "panel_sha": "17fc953bb009fa95f0ca134d7e258afb8dd368bd65e9db216564aa32ccc9746d", "time": "2026-10-25T01:20:21Z", "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:22:08Z", "heldout_sha": "d0b36c70b8f7c63fce40f317c40272c904df555cabbdebc56aba5d69b2ce60c4", "files_sha": "6405470696815cb85d117476c4777135f2a3b670e934ac3377d517c14b69e582"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-drift-velocity", "name": "Solved: drift velocity from electric field strength, mobility (mobility (Wikidata Q900648))", "sources": [ { "name": "the maths organ: solved from the system q0 = q2*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": "\\bdrift\\ velocity\\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 mobility (Wikidata Q900648): 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the drift velocity for electric field strength and mobility?" ], "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 drift velocity for electric field strength 107.961 and mobility 59.4105?", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [107.960666, 59.4105] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 107.961 and mobility of 59.4105.", "a": "6413.997161494573", "valid": true, "kind": "compute", "expect": 6413.997161494573, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [107.960666, 59.4105] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 169.527 and mobility 280.774?", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [169.526958, 280.773702] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 169.527 and mobility of 280.774.", "a": "47598.71144694985", "valid": true, "kind": "compute", "expect": 47598.71144694985, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [169.526958, 280.773702] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 1.91195 and mobility 82.2401?", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [1.911952, 82.240072] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 1.91195 and mobility of 82.2401.", "a": "157.23905034769402", "valid": true, "kind": "compute", "expect": 157.23905034769402, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [1.911952, 82.240072] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 1.64379 and mobility 252.709?", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [1.643795, 252.709024] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 1.64379 and mobility of 252.709.", "a": "415.4019555725448", "valid": true, "kind": "compute", "expect": 415.4019555725448, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [1.643795, 252.709024] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 18.3169 and mobility 6.8386?", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [18.316867, 6.838598] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 18.3169 and mobility of 6.8386.", "a": "125.26169131331936", "valid": true, "kind": "compute", "expect": 125.26169131331936, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [18.316867, 6.838598] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 156.502 and mobility 185.886?", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [156.50181, 185.886273] (the system mobility (Wikidata Q900648))" }, { "q": "Tell me the drift velocity with electric field strength of 156.502 and mobility of 185.886.", "a": "29091.53810517715", "valid": true, "kind": "compute", "expect": 29091.53810517715, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [156.50181, 185.886273] (the system mobility (Wikidata Q900648))" }, { "q": "What is the drift velocity for electric field strength 107.961?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mobility is not given" }, { "q": "Tell me the drift velocity with electric field strength of 169.527.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mobility is not given" }, { "q": "What is the drift velocity 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 drift velocity 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 drift velocity with electric field strength of -1.91195 and mobility of 82.2401.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative electric field strength: no example had one" }, { "q": "Which drift velocity 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 field strength is 8.50728 and the mobility is 17.7888, what is the drift velocity?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [8.507283, 17.788778] (the system mobility (Wikidata Q900648))" }, { "q": "Could you work out the drift velocity given electric field strength = 8.50728, mobility = 17.7888?", "a": "151.33416360087082", "valid": true, "kind": "compute", "expect": 151.33416360087082, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [8.507283, 17.788778] (the system mobility (Wikidata Q900648))" }, { "q": "I need the drift velocity for an electric field strength of 8.24951 and a mobility of 0.634021, please.", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [8.24951, 0.634021] (the system mobility (Wikidata Q900648))" }, { "q": "If the electric field strength is 8.24951 and the mobility is 0.634021, what is the drift velocity?", "a": "5.230362271972724", "valid": true, "kind": "compute", "expect": 5.230362271972724, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [8.24951, 0.634021] (the system mobility (Wikidata Q900648))" }, { "q": "Could you work out the drift velocity given electric field strength = 0.318734, mobility = 9.56607?", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [0.318734, 9.566071] (the system mobility (Wikidata Q900648))" }, { "q": "I need the drift velocity for an electric field strength of 0.318734 and a mobility of 9.56607, please.", "a": "3.0490325263462696", "valid": true, "kind": "compute", "expect": 3.0490325263462696, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [0.318734, 9.566071] (the system mobility (Wikidata Q900648))" }, { "q": "If the electric field strength is 0.671697 and the mobility is 14.2496, what is the drift velocity?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [0.671697, 14.249569] (the system mobility (Wikidata Q900648))" }, { "q": "Could you work out the drift velocity given electric field strength = 0.671697, mobility = 14.2496?", "a": "9.571395807788361", "valid": true, "kind": "compute", "expect": 9.571395807788361, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [0.671697, 14.249569] (the system mobility (Wikidata Q900648))" }, { "q": "I need the drift velocity for an electric field strength of 21.7931 and a mobility of 29.5106, please.", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [21.793126, 29.510609] (the system mobility (Wikidata Q900648))" }, { "q": "If the electric field strength is 21.7931 and the mobility is 29.5106, what is the drift velocity?", "a": "643.1284273894521", "valid": true, "kind": "compute", "expect": 643.1284273894521, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [21.793126, 29.510609] (the system mobility (Wikidata Q900648))" }, { "q": "Could you work out the drift velocity given electric field strength = 153.15, mobility = 18.5953?", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [153.149965, 18.595315] (the system mobility (Wikidata Q900648))" }, { "q": "I need the drift velocity for an electric field strength of 153.15 and a mobility of 18.5953, please.", "a": "2847.871916067332", "valid": true, "kind": "compute", "expect": 2847.871916067332, "dtype": "quantity", "unit": "m/s", "why": "drift velocity for [153.149965, 18.595315] (the system mobility (Wikidata Q900648))" }, { "q": "If the electric field strength is 8.50728, what is the drift velocity?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mobility is not given" }, { "q": "Could you work out the drift velocity given electric field strength = 8.24951?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the mobility is not given" }, { "q": "Do you know the drift velocity 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 drift velocity 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 drift velocity given electric field strength = -0.318734, mobility = 9.56607?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative electric field strength: no example had one" }, { "q": "What is a typical drift velocity?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""drift velocity from electric field strength, mobility (mobility (Wikidata Q900648))The maths organ (systems.py): solved from the system q0 = q2*q1; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(electric_field_strength, mobility): return 1.0*electric_field_strength*mobility12345678910111213141516171819202122232425262728293031"""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": "drift velocity from electric field strength, mobility (mobility (Wikidata Q900648))", "inputs": [ "electric field strength (m*kg/s^3/A)", "mobility (s^2*A/kg)" ], "output": "drift velocity (m/s)", "input_kinds": [ "number", "number" ], "expression": "1.0*q1*q2", "expression_x": null, "said": "solved from the system q0 = q2*q1; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "q0 = q2*q1" ], "constants": {}, "quantities": { "q0": "drift velocity (m/s)", "q1": "electric field strength (m*kg/s^3/A)", "q2": "mobility (s^2*A/kg)" }, "symbols": [ "q1", "q2" ], "out_symbol": "q0" }, "points": [ { "in": [ 107.960666, 59.4105 ], "out": 6413.997161494573 }, { "in": [ 8.507283, 17.788778 ], "out": 151.33416360087082 }, { "in": [ 169.526958, 280.773702 ], "out": 47598.71144694985 }, { "in": [ 8.24951, 0.634021 ], "out": 5.230362271972724 }, { "in": [ 1.911952, 82.240072 ], "out": 157.23905034769402 }, { "in": [ 0.318734, 9.566071 ], "out": 3.0490325263462696 }, { "in": [ 1.643795, 252.709024 ], "out": 415.4019555725448 }, { "in": [ 0.671697, 14.249569 ], "out": 9.571395807788361 }, { "in": [ 18.316867, 6.838598 ], "out": 125.26169131331936 }, { "in": [ 21.793126, 29.510609 ], "out": 643.1284273894521 }, { "in": [ 156.50181, 185.886273 ], "out": 29091.53810517715 }, { "in": [ 153.149965, 18.595315 ], "out": 2847.871916067332 } ], "domain": { "inputs": [ "positive", "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132333435363738{ "id": "solved-drift-velocity", "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": "6405470696815cb85d117476c4777135f2a3b670e934ac3377d517c14b69e582", "panel_sha": "7b152d58b23836e88a5be828e0e5edb1e87b9fb3bba14f02e599b8794fd48ed8", "time": "2026-10-25T01:22:08Z", "core_head": "oracle_release_runtime_w571", "head_probe": { "asked": 2, "core_right": 0, "fillable_declines": 2, "mode": "declines" }}123456789101112131415161718192021222324252627282930313233343536373839{ "id": "solved-drift-velocity", "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": "6405470696815cb85d117476c4777135f2a3b670e934ac3377d517c14b69e582", "panel_sha": "d0b36c70b8f7c63fce40f317c40272c904df555cabbdebc56aba5d69b2ce60c4", "time": "2026-10-25T01:22:09Z", "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-24T00:21:42Z", "heldout_sha": "7456fbc870a0e5827309aad8a2d944fad015ee76134fa640cd9597ac07435c13", "files_sha": "74d22cac83dcebf61aba604e99316df9b30a6b558f0b678856f352022d0388d9"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-drop-height-2", "name": "Solved: drop height from impact speed (Free fall)", "sources": [ { "name": "the maths organ: solved from the system h = g*t**2/2; v = g*t; 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": "\\bdrop\\ height\\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 Free fall: 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the drop height for impact speed?" ], "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 drop height for impact speed 107.961?", "a": "594.2653902914861", "valid": true, "kind": "compute", "expect": 594.2653902914861, "dtype": "quantity", "unit": "m", "why": "drop height for [107.960666] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 107.961.", "a": "594.2653902914861", "valid": true, "kind": "compute", "expect": 594.2653902914861, "dtype": "quantity", "unit": "m", "why": "drop height for [107.960666] (the system Free fall)" }, { "q": "What is the drop height for impact speed 6.34623?", "a": "2.0534320749050288", "valid": true, "kind": "compute", "expect": 2.0534320749050288, "dtype": "quantity", "unit": "m", "why": "drop height for [6.346226] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 6.34623.", "a": "2.0534320749050288", "valid": true, "kind": "compute", "expect": 2.0534320749050288, "dtype": "quantity", "unit": "m", "why": "drop height for [6.346226] (the system Free fall)" }, { "q": "What is the drop height for impact speed 0.551236?", "a": "0.01549259757441237", "valid": true, "kind": "compute", "expect": 0.01549259757441237, "dtype": "quantity", "unit": "m", "why": "drop height for [0.551236] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 0.551236.", "a": "0.01549259757441237", "valid": true, "kind": "compute", "expect": 0.01549259757441237, "dtype": "quantity", "unit": "m", "why": "drop height for [0.551236] (the system Free fall)" }, { "q": "What is the drop height for impact speed 186.27?", "a": "1769.0309226312675", "valid": true, "kind": "compute", "expect": 1769.0309226312675, "dtype": "quantity", "unit": "m", "why": "drop height for [186.270057] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 186.27.", "a": "1769.0309226312675", "valid": true, "kind": "compute", "expect": 1769.0309226312675, "dtype": "quantity", "unit": "m", "why": "drop height for [186.270057] (the system Free fall)" }, { "q": "What is the drop height for impact speed 0.710236?", "a": "0.025719059786605446", "valid": true, "kind": "compute", "expect": 0.025719059786605446, "dtype": "quantity", "unit": "m", "why": "drop height for [0.710236] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 0.710236.", "a": "0.025719059786605446", "valid": true, "kind": "compute", "expect": 0.025719059786605446, "dtype": "quantity", "unit": "m", "why": "drop height for [0.710236] (the system Free fall)" }, { "q": "What is the drop height for impact speed 79.8435?", "a": "325.03405867382344", "valid": true, "kind": "compute", "expect": 325.03405867382344, "dtype": "quantity", "unit": "m", "why": "drop height for [79.843538] (the system Free fall)" }, { "q": "Tell me the drop height with impact speed of 79.8435.", "a": "325.03405867382344", "valid": true, "kind": "compute", "expect": 325.03405867382344, "dtype": "quantity", "unit": "m", "why": "drop height for [79.843538] (the system Free fall)" }, { "q": "What is the drop height?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the impact speed is not given" }, { "q": "Could you work out the drop height, please?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the impact speed is not given" }, { "q": "What is the drop height 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 drop height 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 drop height with impact speed of -0.551236.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative impact speed: no example had one" }, { "q": "Which drop height 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 impact speed is 58.5346, what is the drop height?", "a": "174.69261814008215", "valid": true, "kind": "compute", "expect": 174.69261814008215, "dtype": "quantity", "unit": "m", "why": "drop height for [58.534594] (the system Free fall)" }, { "q": "Could you work out the drop height given impact speed = 58.5346?", "a": "174.69261814008215", "valid": true, "kind": "compute", "expect": 174.69261814008215, "dtype": "quantity", "unit": "m", "why": "drop height for [58.534594] (the system Free fall)" }, { "q": "I need the drop height for an impact speed of 31.9492, please.", "a": "52.043744505256306", "valid": true, "kind": "compute", "expect": 52.043744505256306, "dtype": "quantity", "unit": "m", "why": "drop height for [31.949172] (the system Free fall)" }, { "q": "If the impact speed is 31.9492, what is the drop height?", "a": "52.043744505256306", "valid": true, "kind": "compute", "expect": 52.043744505256306, "dtype": "quantity", "unit": "m", "why": "drop height for [31.949172] (the system Free fall)" }, { "q": "Could you work out the drop height given impact speed = 6.8386?", "a": "2.3844240105291346", "valid": true, "kind": "compute", "expect": 2.3844240105291346, "dtype": "quantity", "unit": "m", "why": "drop height for [6.838598] (the system Free fall)" }, { "q": "I need the drop height for an impact speed of 6.8386, please.", "a": "2.3844240105291346", "valid": true, "kind": "compute", "expect": 2.3844240105291346, "dtype": "quantity", "unit": "m", "why": "drop height for [6.838598] (the system Free fall)" }, { "q": "If the impact speed is 17.3414, what is the drop height?", "a": "15.332726651344165", "valid": true, "kind": "compute", "expect": 15.332726651344165, "dtype": "quantity", "unit": "m", "why": "drop height for [17.341435] (the system Free fall)" }, { "q": "Could you work out the drop height given impact speed = 17.3414?", "a": "15.332726651344165", "valid": true, "kind": "compute", "expect": 15.332726651344165, "dtype": "quantity", "unit": "m", "why": "drop height for [17.341435] (the system Free fall)" }, { "q": "I need the drop height for an impact speed of 0.380269, please.", "a": "0.007372759997719279", "valid": true, "kind": "compute", "expect": 0.007372759997719279, "dtype": "quantity", "unit": "m", "why": "drop height for [0.380269] (the system Free fall)" }, { "q": "If the impact speed is 0.380269, what is the drop height?", "a": "0.007372759997719279", "valid": true, "kind": "compute", "expect": 0.007372759997719279, "dtype": "quantity", "unit": "m", "why": "drop height for [0.380269] (the system Free fall)" }, { "q": "Could you work out the drop height given impact speed = 291.545?", "a": "4333.713741374141", "valid": true, "kind": "compute", "expect": 4333.713741374141, "dtype": "quantity", "unit": "m", "why": "drop height for [291.544898] (the system Free fall)" }, { "q": "I need the drop height for an impact speed of 291.545, please.", "a": "4333.713741374141", "valid": true, "kind": "compute", "expect": 4333.713741374141, "dtype": "quantity", "unit": "m", "why": "drop height for [291.544898] (the system Free fall)" }, { "q": "I need the drop height, please.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the impact speed is not given" }, { "q": "Can you tell me the drop height?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the impact speed is not given" }, { "q": "Do you know the drop height 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 drop height 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 drop height given impact speed = -6.8386?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative impact speed: no example had one" }, { "q": "What is a typical drop height?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}1234567"""drop height from impact speed (Free fall)The maths organ (systems.py): solved from the system h = g*t**2/2; v = g*t; checked by substitution into every equation and by a numeric solution at 12 points"""import math
def compute(impact_speed): return 0.0509858106488964*impact_speed**212345678910111213141516171819202122232425262728293031"""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, True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119{ "title": "drop height from impact speed (Free fall)", "inputs": [ "impact speed (m/s)" ], "output": "drop height (m)", "input_kinds": [ "number" ], "expression": "0.0509858106488964*v**2", "expression_x": null, "said": "solved from the system h = g*t**2/2; v = g*t; checked by substitution into every equation and by a numeric solution at 12 points", "composer": "systems (the maths organ)", "library": [], "system": { "equations": [ "h = g*t**2/2", "v = g*t" ], "constants": { "g": [ "standard gravity", 9.80665, "m/s^2" ] }, "quantities": { "h": "drop height (m)", "t": "fall time (s)", "v": "impact speed (m/s)" }, "symbols": [ "v" ], "out_symbol": "h" }, "points": [ { "in": [ 107.960666 ], "out": 594.2653902914861 }, { "in": [ 58.534594 ], "out": 174.69261814008215 }, { "in": [ 6.346226 ], "out": 2.0534320749050288 }, { "in": [ 31.949172 ], "out": 52.043744505256306 }, { "in": [ 0.551236 ], "out": 0.01549259757441237 }, { "in": [ 6.838598 ], "out": 2.3844240105291346 }, { "in": [ 186.270057 ], "out": 1769.0309226312675 }, { "in": [ 17.341435 ], "out": 15.332726651344165 }, { "in": [ 0.710236 ], "out": 0.025719059786605446 }, { "in": [ 0.380269 ], "out": 0.007372759997719279 }, { "in": [ 79.843538 ], "out": 325.03405867382344 }, { "in": [ 291.544898 ], "out": 4333.713741374141 } ], "domain": { "inputs": [ "positive" ], "output": "positive", "order": [], "facts": [] }}1234567891011121314151617181920212223242526272829303132{ "id": "solved-drop-height-2", "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": "74d22cac83dcebf61aba604e99316df9b30a6b558f0b678856f352022d0388d9", "panel_sha": "892b546d9bb88d6baa96e040ac2096a31458867b64013cb997a7b39d40d34e8c", "time": "2026-10-24T00:21:42Z", "core_head": "oracle_release_runtime_w571"}123456789101112131415161718192021222324252627282930313233{ "id": "solved-drop-height-2", "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": "74d22cac83dcebf61aba604e99316df9b30a6b558f0b678856f352022d0388d9", "panel_sha": "7456fbc870a0e5827309aad8a2d944fad015ee76134fa640cd9597ac07435c13", "time": "2026-10-24T00:21:45Z", "core_head": "oracle_release_runtime_w571", "memory": "written to your group's memory"}1{"t": "2026-10-24T00:21:37Z", "heldout_sha": "4c7ea85d8cad0df845052ad5eec2d3b47473499cc2c6293ff516958053abc7da", "files_sha": "590dc728950351892284306af4cb632460d33b01989a4bbe3b08c7b79994d148"}1234567891011121314151617181920212223242526272829303132333435363738394041{ "id": "solved-drop-height", "name": "Solved: drop height from fall time (Free fall)", "sources": [ { "name": "the maths organ: solved from the system h = g*t**2/2; v = g*t; 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": "\\bdrop\\ height\\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 Free fall: 6 checked points used to write the panel's dev half, 6 its held-out half.", "built_from": { "questions": [ "What is the drop height for fall time?" ], "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 drop height for fall time 107.961?", "a": "57150.730914466156", "valid": true, "kind": "compute", "expect": 57150.730914466156, "dtype": "quantity", "unit": "m", "why": "drop height for [107.960666] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 107.961.", "a": "57150.730914466156", "valid": true, "kind": "compute", "expect": 57150.730914466156, "dtype": "quantity", "unit": "m", "why": "drop height for [107.960666] (the system Free fall)" }, { "q": "What is the drop height for fall time 6.34623?", "a": "197.47935161842204", "valid": true, "kind": "compute", "expect": 197.47935161842204, "dtype": "quantity", "unit": "m", "why": "drop height for [6.346226] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 6.34623.", "a": "197.47935161842204", "valid": true, "kind": "compute", "expect": 197.47935161842204, "dtype": "quantity", "unit": "m", "why": "drop height for [6.346226] (the system Free fall)" }, { "q": "What is the drop height for fall time 0.551236?", "a": "1.4899290613358094", "valid": true, "kind": "compute", "expect": 1.4899290613358094, "dtype": "quantity", "unit": "m", "why": "drop height for [0.551236] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 0.551236.", "a": "1.4899290613358094", "valid": true, "kind": "compute", "expect": 1.4899290613358094, "dtype": "quantity", "unit": "m", "why": "drop height for [0.551236] (the system Free fall)" }, { "q": "What is the drop height for fall time 186.27?", "a": "170128.38353093268", "valid": true, "kind": "compute", "expect": 170128.38353093268, "dtype": "quantity", "unit": "m", "why": "drop height for [186.270057] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 186.27.", "a": "170128.38353093268", "valid": true, "kind": "compute", "expect": 170128.38353093268, "dtype": "quantity", "unit": "m", "why": "drop height for [186.270057] (the system Free fall)" }, { "q": "What is the drop height for fall time 0.710236?", "a": "2.473411861519295", "valid": true, "kind": "compute", "expect": 2.473411861519295, "dtype": "quantity", "unit": "m", "why": "drop height for [0.710236] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 0.710236.", "a": "2.473411861519295", "valid": true, "kind": "compute", "expect": 2.473411861519295, "dtype": "quantity", "unit": "m", "why": "drop height for [0.710236] (the system Free fall)" }, { "q": "What is the drop height for fall time 79.8435?", "a": "31258.650308060212", "valid": true, "kind": "compute", "expect": 31258.650308060212, "dtype": "quantity", "unit": "m", "why": "drop height for [79.843538] (the system Free fall)" }, { "q": "Tell me the drop height with fall time of 79.8435.", "a": "31258.650308060212", "valid": true, "kind": "compute", "expect": 31258.650308060212, "dtype": "quantity", "unit": "m", "why": "drop height for [79.843538] (the system Free fall)" }, { "q": "What is the drop height?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the fall time is not given" }, { "q": "Could you work out the drop height, please?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the fall time is not given" }, { "q": "What is the drop height 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 drop height 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 drop height with fall time of -0.551236.", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative fall time: no example had one" }, { "q": "Which drop height 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 fall time is 58.5346, what is the drop height?", "a": "16800.256207366176", "valid": true, "kind": "compute", "expect": 16800.256207366176, "dtype": "quantity", "unit": "m", "why": "drop height for [58.534594] (the system Free fall)" }, { "q": "Could you work out the drop height given fall time = 58.5346?", "a": "16800.256207366176", "valid": true, "kind": "compute", "expect": 16800.256207366176, "dtype": "quantity", "unit": "m", "why": "drop height for [58.534594] (the system Free fall)" }, { "q": "I need the drop height for a fall time of 31.9492, please.", "a": "5005.066905448123", "valid": true, "kind": "compute", "expect": 5005.066905448123, "dtype": "quantity", "unit": "m", "why": "drop height for [31.949172] (the system Free fall)" }, { "q": "If the fall time is 31.9492, what is the drop height?", "a": "5005.066905448123", "valid": true, "kind": "compute", "expect": 5005.066905448123, "dtype": "quantity", "unit": "m", "why": "drop height for [31.949172] (the system Free fall)" }, { "q": "Could you work out the drop height given fall time = 6.8386?", "a": "229.3109732419413", "valid": true, "kind": "compute", "expect": 229.3109732419413, "dtype": "quantity", "unit": "m", "why": "drop height for [6.838598] (the system Free fall)" }, { "q": "I need the drop height for a fall time of 6.8386, please.", "a": "229.3109732419413", "valid": true, "kind": "compute", "expect": 229.3109732419413, "dtype": "quantity", "unit": "m", "why": "drop height for [6.838598] (the system Free fall)" }, { "q": "If the fall time is 17.3414, what is the drop height?", "a": "1474.5542132383343", "valid": true, "kind": "compute", "expect": 1474.5542132383343, "dtype": "quantity", "unit": "m", "why": "drop height for [17.341435] (the system Free fall)" }, { "q": "Could you work out the drop height given fall time = 17.3414?", "a": "1474.5542132383343", "valid": true, "kind": "compute", "expect": 1474.5542132383343, "dtype": "quantity", "unit": "m", "why": "drop height for [17.341435] (the system Free fall)" }, { "q": "I need the drop height for a fall time of 0.380269, please.", "a": "0.7090411617609413", "valid": true, "kind": "compute", "expect": 0.7090411617609413, "dtype": "quantity", "unit": "m", "why": "drop height for [0.380269] (the system Free fall)" }, { "q": "If the fall time is 0.380269, what is the drop height?", "a": "0.7090411617609413", "valid": true, "kind": "compute", "expect": 0.7090411617609413, "dtype": "quantity", "unit": "m", "why": "drop height for [0.380269] (the system Free fall)" }, { "q": "Could you work out the drop height given fall time = 291.545?", "a": "416774.9156182792", "valid": true, "kind": "compute", "expect": 416774.9156182792, "dtype": "quantity", "unit": "m", "why": "drop height for [291.544898] (the system Free fall)" }, { "q": "I need the drop height for a fall time of 291.545, please.", "a": "416774.9156182792", "valid": true, "kind": "compute", "expect": 416774.9156182792, "dtype": "quantity", "unit": "m", "why": "drop height for [291.544898] (the system Free fall)" }, { "q": "I need the drop height, please.", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the fall time is not given" }, { "q": "Can you tell me the drop height?", "a": "", "valid": false, "kind": "missing_input", "expect": null, "dtype": "quantity", "unit": "", "why": "the fall time is not given" }, { "q": "Do you know the drop height 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 drop height 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 drop height given fall time = -6.8386?", "a": "", "valid": false, "kind": "out_of_domain", "expect": null, "dtype": "quantity", "unit": "", "why": "a negative fall time: no example had one" }, { "q": "What is a typical drop height?", "a": "", "valid": false, "kind": "output_only", "expect": null, "dtype": "quantity", "unit": "", "why": "names the output and no input: not this program's" } ]}root/organs10/physics/specialists/solved-distance-9/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-distance-9/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-distance-9/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-distance-9/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-distance-9/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-distance-9/panel.jsonAdded+366
root/organs10/physics/specialists/solved-distance-9/program.pyAdded+7
root/organs10/physics/specialists/solved-distance-9/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-distance-9/spec.jsonAdded+128
root/organs10/physics/specialists/solved-distance-9/verdict_dev.jsonAdded+40
root/organs10/physics/specialists/solved-distance-9/verdict_heldout.jsonAdded+33
root/organs10/physics/specialists/solved-dose-equivalent/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-dose-equivalent/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-dose-equivalent/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-dose-equivalent/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-dose-equivalent/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-dose-equivalent/panel.jsonAdded+366
root/organs10/physics/specialists/solved-dose-equivalent/program.pyAdded+7
root/organs10/physics/specialists/solved-dose-equivalent/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-dose-equivalent/spec.jsonAdded+128
root/organs10/physics/specialists/solved-dose-equivalent/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-dose-equivalent/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-drift-velocity/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-drift-velocity/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-drift-velocity/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-drift-velocity/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-drift-velocity/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-drift-velocity/panel.jsonAdded+366
root/organs10/physics/specialists/solved-drift-velocity/program.pyAdded+7
root/organs10/physics/specialists/solved-drift-velocity/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-drift-velocity/spec.jsonAdded+128
root/organs10/physics/specialists/solved-drift-velocity/verdict_dev.jsonAdded+38
root/organs10/physics/specialists/solved-drift-velocity/verdict_heldout.jsonAdded+39
root/organs10/physics/specialists/solved-drop-height-2/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-drop-height-2/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-drop-height-2/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-drop-height-2/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-drop-height-2/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-drop-height-2/panel.jsonAdded+366
root/organs10/physics/specialists/solved-drop-height-2/program.pyAdded+7
root/organs10/physics/specialists/solved-drop-height-2/scorer_formula_v1.pyAdded+31
root/organs10/physics/specialists/solved-drop-height-2/spec.jsonAdded+119
root/organs10/physics/specialists/solved-drop-height-2/verdict_dev.jsonAdded+32
root/organs10/physics/specialists/solved-drop-height-2/verdict_heldout.jsonAdded+33
root/organs10/physics/specialists/solved-drop-height/exam_log.jsonlAdded+1
root/organs10/physics/specialists/solved-drop-height/manifest.jsonAdded+41
root/organs10/physics/specialists/solved-drop-height/narrow_v1.pyAdded+47
root/organs10/physics/specialists/solved-drop-height/organ_formula_v2.pyAdded+163
root/organs10/physics/specialists/solved-drop-height/organ_formula_v3.pyAdded+205
root/organs10/physics/specialists/solved-drop-height/panel.jsonAdded+366