STEP 1418 — sympy Sum.is_convergent() 3 bug fix upstream contribution 準備

2026-08-27 · rei-aios · arc: 2026-08-26 → 2026-08-27

要旨

藤本さん問「ガブリエルのラッパは 数学上の 未確認問題を 解くのに 役立ちますか?」 を 起点 に、 積分/級数 収束判定 tool rei-critical-mcp 提案 → prior art audit で sympy Sum.is_convergent() が 既存 と 判明 → spot-check で sympy 3 bug 発見 → 藤本さん C 判断 (upstream contribution first) → 2 PR draft + git apply 可能 diff + submission guide 完成。

Rei prototype 20/20 test PASS + sympy 公式 test file 39 assert で wrong verdict 3→0 (誤答除去)、 12 baseline + 4 additional case 全 non-regression 100%。

藤本さん directive quote

「ガブリエルのラッパは、 数学上の 未確認問題を 解くのに 役立ちますか?」
(2026-08-26、 arc 起点)
「上記に 基づいて コネクタ用の ツール、 マシンには 出来ますか?」
(2026-08-26、 rei-critical-mcp 提案 契機)
「D → C で 問題ありません。」
(2026-08-26、 prior art audit 実施承認)
「C で お願い致します。」
(2026-08-26、 sympy upstream PR 3 件 準備 承認、 「一の再現 > 十の未検証」 discipline 直接適用)

3 bug root-cause + 実測 evidence

Bug 1 — 1 - cos(1/n) ~ 1/(2n²) 誤発散 (issue #12544)

Root cause: O(1-cos(1/n), (n,∞)).expr = 1 (loose upper bound、 true asymptotic 1/(2n²) を 捉えない) → p-series match で p=0、 0 ≥ -1S.false return。 Raabe test (fall-through で lim=2>1 → True 返せる) に 到達しない。

Verdict: stock wrong False → patched correct True

Bug 2 — depth-3 Bertrand 1/(n·log·loglog·logloglog) NotImplementedError

Root cause: 既存 Bertrand pattern が 1/(n^p·log^q·loglog^r) の 3 slot のみ、 4-nested log 対応不能 → terminal raise NotImplementedError に 到達。

Verdict: stock NotImplementedError → patched correct verdict 両方向 (`False` for depth-3 divergent、 `True` for `^2` suffix)

Bug 3 — sin(n)/n 誤発散

Root cause: O(sin(n)/n, (n,∞)).expr = 1/n (oscillatory 包絡上限)、 p=-1 で -1 ≥ -1S.false。 実際は Dirichlet で 条件収束。 sin(n)/n / (1/n) = sin(n) = AccumulationBounds(-1, 1) — tight 両側 asymptotic ではない。

Verdict: stock wrong False → patched honest NotImplementedError (sympy Dirichlet test が order.expr.is_Mul 制約で 1/n = Pow を 捉えない、 別 PR 候補)

Unified fix 設計

PR 1: Tightness guard (Bugs 1 + 3 統合)

O(f).expr を tight asymptotic として 扱う assumption が 誤り。 divergence 主張 は tight bound の 場合のみ 有効 (convergence 主張 は upper bound だけで OK)。 tightness を limit_seq(f / order.expr, sym) で 1 度 計算 → finite nonzero (not AccumulationBounds) の 場合のみ S.false return を 許可、 p-series test + 3-Bertrand test 両方の "return S.false" 分岐に guard 適用。 loose bound は Raabe / integral / Dirichlet の 後続 test に fall through。

try:
    _tight_ratio = limit_seq(sequence_term / order.expr, sym)
except NotImplementedError:
    _tight_ratio = None
o_bound_is_tight = (
    _tight_ratio is not None
    and _tight_ratio.is_finite is True
    and _tight_ratio.is_zero is False
    and not _tight_ratio.has(Limit)
    and not isinstance(_tight_ratio, AccumulationBounds)
)

PR 2: 4-level Bertrand pattern (Bug 2、 PR 1 依存)

3-slot Bertrand pattern に 4-slot pattern 1/(n^p·log^q·loglog^r·logloglog^s) を 追加。 tie-breaking chain (p>1 / p=1∧q>1 / p=q=1∧r>1 / p=q=r=1∧s>1) は 標準 Cauchy 凝集 反復適用。 o_bound_is_tight guard は PR 1 から 継承。

Verification 実測

Rei prototype 20/20 PASS (test_patched.py)

Sympy 公式 test file 39 assert 抽出 (test_sums_products.py line 1052-1437)

StatusStock 1.13.3+ PR 1+ PR 1 & 2
PASS373636
FAIL (wrong verdict)200
NIE (honest)033
Net effect: 誤答 3 件 排除 (Bug 1 stock False→patched True 正解、 Bug 3 stock False→patched NIE 誠実)。 line 1197 sin(n)/log(log(n))stock coincidental PASS 発覚 — sympy assert S.false 自体が 数学的に 誤り (Dirichlet で 収束するはず)、 stock は 誤答同士で 偶然一致 で PASS していた、 patched で NIE = 誠実。 sympy test 側 line 1136/1137/1197 3 件 更新必要 (PR に 含めることを 推奨)。

Deliverables (repo 版)

data/sympy-upstream-prep/step1418/:

藤本さん judgment 待ち (未実施)

  1. GitHub account 選択fc0web から submit or sympy に事前相談
  2. PR strategy — 2 PR 順次 vs 1 combined (sympy maintainer は 通常 small focused 好むので 2 順次 推奨)
  3. sympy test 更新 を 同 PR に 含めるか — 含めない と CI red、 含める と 誠実 (推奨)

Honest scope

controllable 表現の 徹底: PR 描述で 「correctness fix to known upstream bug」 framing、 algorithmic novelty 主張ゼロ。 Rei 側で は 「sympy 再発明」 の spike (私 (Claude) の miss — 起草前 fact-check 怠り) を prior art audit 由来 spot-check で 補正的に 発見、 藤本さん C 判断 (upstream first) で 世界資産 貢献に pivot。 sympy 貢献は アルゴリズム的 新規性 でなく 「誤答を honest NIE / correct verdict に 変える 3 dimension の 正当性 改善」 と 位置付ける。
実 submit 未実施: GitHub credential 使用は 「actions visible to others / affects shared state」 に 該当、 藤本さん明示的 承認必要。 私 (Claude) 側 は artifact 保管 + submission guide 提供 まで。
patch 依存性: sympy 1.13.3 install 上 で 開発、 master は 移動している 可能性、 diff 行番号は 近似。 rebase 必要な 場合あり。 実 PR は full CI で regression 検知。