core/generate/derivation/__init__.py
Shay 6611a7017d
feat(adr-0178-gb3b1): single-referent accumulation chaining (practice 0 -> 55) (#465)
The first cross-clause comprehension reading: one actor's quantity changes over
successive clauses ("Sam has 14 apples. He buys 9 more." -> 14 + 9). It is the
safe specialisation of the cross-clause sum that GB-3a refuses wholesale (the
Alice/Tom hazard) — we chain only when (same referent) AND (a licensed change
cue of unambiguous polarity), else refuse.

generate/derivation/accumulate.py — compose_accumulation:
- anchor on clause 1's single quantity; apply +M (gain) / -M (loss) per later
  change clause, operand taken in the anchor's unit (accumulation is same-dimension);
  routed through the unchanged self-verification gate.
- polarity (ordered, so ambiguous "gives" is resolved not guessed): "more" -> gain;
  else unambiguous loss verb -> loss; else gives/gave + to/away -> loss; else
  unambiguous gain verb -> gain; else REFUSE.
- referent guard (the ADR-0174 multi-actor hazard's defensive fix, built minimally
  in the clean lane — NOT the retired gender-blind resolver): a later clause's
  subject token must be a pronoun or the anchor's name; a NEW named subject (Tom)
  -> refuse. Pronoun gender/number is not matched; a new name is the only signal.

evals/.../accumulation_runner.py — practice scorer: on a base refusal, attempt
compose_accumulation and gold-check (mirrors search_runner). Sealed: fires only
on already-refused cases, never alters serving.

Measured (sealed practice additive lane): 0 -> 55 correct, wrong unchanged at 1
(the base scorer's pre-existing one; accumulation added 55 correct, 0 wrong). The
36 still-refused are multi-change (GB-3b.2) or unrecognised verbs (vocab growth) —
conservative, never wrong.

Proof obligations (tests fail under the violation): new-named-actor refuses (H1),
no/ambiguous change cue refuses, list anchor refuses, multi-change refuses,
determinism. 136 targeted tests + architectural invariants green; serving 3/47/0
byte-identical (lane-SHA 8/8, claims --check OK).
2026-05-29 10:41:51 -07:00

57 lines
1.6 KiB
Python

"""ADR-0175 Phase 3 — grounded derivation search + self-verification gate.
Phase 3a (this surface): the self-verification gate — grounded operands ∧
grounded operation cues ∧ unit consistency ∧ uniqueness. The wrong=0-critical
guard that keeps the (Phase 3b) bounded search honest.
"""
from __future__ import annotations
from generate.derivation.clauses import (
ClauseResult,
clause_local_results,
segment_clauses,
)
from generate.derivation.accumulate import compose_accumulation
from generate.derivation.compose import compose_sequential
from generate.derivation.comparatives import (
ComparativeScalar,
comparative_step,
extract_comparative_scalars,
)
from generate.derivation.extract import extract_quantities
from generate.derivation.model import GroundedDerivation, Quantity, Step, VALID_OPS
from generate.derivation.multistep import search_chain
from generate.derivation.search import MULTIPLICATIVE_CUES, search_multiplicative
from generate.derivation.target import Target, extract_target
from generate.derivation.verify import (
Resolution,
SelfVerification,
select_self_verified,
self_verifies,
)
__all__ = [
"ClauseResult",
"ComparativeScalar",
"GroundedDerivation",
"MULTIPLICATIVE_CUES",
"Quantity",
"Resolution",
"SelfVerification",
"Step",
"Target",
"VALID_OPS",
"clause_local_results",
"compose_accumulation",
"compose_sequential",
"comparative_step",
"extract_comparative_scalars",
"extract_quantities",
"extract_target",
"search_chain",
"search_multiplicative",
"segment_clauses",
"select_self_verified",
"self_verifies",
]