shannon_entropy_verdict tool v0.1

STEP: 1499 / 公開日: 2026-08-28 / Test: 35/35 PASS / Lean 4: 13 theorem zero sorry / Type: 26 defer candidate 第 1 号 実装

短答 (3 行)

shannon_entropy_verdict = 分布 (List Nat 頻度) → Shannon エントロピー H(X) → D-FUMT₈ 8 verdict mapping の pure function。 STEP 1493 情報科学 arc 6 candidate の 第 1 号 実装。

姉妹 tool 群 に 連結: d8_verdict_from_measurement (STEP 1350 SNR) / d8_verdict_from_multi_trial (STEP 1371 BH FDR) / d8_verdict_from_sample_pair (STEP 1376 Welch t-test) と 同 pattern の determination-focused tool。

責務分離: TS (`src/mcp/shannon-entropy-verdict.ts`) が 実 entropy 計算 (Math.log2)、 Lean 4 (`data/lean4-transfer/step1499_*.lean`) が 決定表 骨格 (NEITHER/ZERO/TRUE) 静的 identity。 Mathlib 未 import で 実数精度 不可の 分業。

1. 決定表 (first-match priority)

#ConditionVerdictReason
1frequencies is emptyNEITHERempty_distribution
2total count = 0NEITHERall_zero_counts
3any negative frequency (NaN/-1 等)NEITHERnegative_frequency
4single-bin dominant (max ≥ 99% of total)ZERO (〇)deterministic_distribution
5H(X) / H_max ≥ 0.95 (near uniform)INFINITY (∞)near_uniform_max_entropy
60.5 ≤ H(X)/H_max < 0.95TRUE (⊤)moderate_entropy
70 < H(X)/H_max < 0.5BOTHlow_entropy_biased
8H(X) = 0 (nonzero bins のみ 単一)ZEROzero_entropy_pure

2. 使用例 (TS)

import { shannonEntropyVerdict } from './src/mcp/shannon-entropy-verdict';

// ケース A: 一様分布 (max entropy) → INFINITY
const rA = shannonEntropyVerdict({ frequencies: [25, 25, 25, 25] });
// { verdict: 'INFINITY', entropyBits: 2.0, normalizedEntropy: 1.0, ... }

// ケース B: 決定的分布 (single bin) → ZERO
const rB = shannonEntropyVerdict({ frequencies: [100, 0, 0, 0] });
// { verdict: 'ZERO', reason: 'deterministic_distribution', entropyBits: 0, ... }

// ケース C: moderate (70/30 分布) → TRUE
const rC = shannonEntropyVerdict({ frequencies: [70, 30] });
// { verdict: 'TRUE', reason: 'moderate_entropy', entropyBits: ~0.881, ... }

// ケース D: 偏り strong (90/10) → BOTH
const rD = shannonEntropyVerdict({ frequencies: [90, 10] });
// { verdict: 'BOTH', reason: 'low_entropy_biased', entropyBits: ~0.469, ... }

// ケース E: 空 or 全 0 or 負値 → NEITHER
const rE = shannonEntropyVerdict({ frequencies: [] });
// { verdict: 'NEITHER', reason: 'empty_distribution', ... }

3. カスタム threshold

// dominant を strict に (70% で ZERO 判定)
const r1 = shannonEntropyVerdict({
  frequencies: [80, 20],
  dominantThreshold: 0.7,
});
// { verdict: 'ZERO', ... }

// uniform を strict に (99% でないと INFINITY にしない)
const r2 = shannonEntropyVerdict({
  frequencies: [60, 40],
  uniformThreshold: 0.99,
});
// { verdict: 'TRUE', reason: 'moderate_entropy', ... }

4. Lean 4 formalization (13 theorem zero sorry)

ファイル: data/lean4-transfer/step1499_shannon_entropy_verdict.lean

-- 決定表 骨格 の 静的 identity (Nat 上)
total_empty                          : total_count [] = 0
total_all_zero                       : total_count (replicate n 0) = 0
total_single                         : total_count [f] = f
effective_empty                      : effective_bins [] = 0
effective_all_zero                   : effective_bins (replicate n 0) = 0
entropy_total_zero_gives_neither     : total=0 → NEITHER
entropy_effective_zero_gives_neither : effective=0 → NEITHER
entropy_single_bin_gives_zero        : effective=1 → ZERO
entropy_dominant_gives_zero          : 99% dominant → ZERO
entropy_moderate_gives_true          : non-dominant → TRUE
is_dominant_total_zero               : total=0 → dominant true (trivial)
is_dominant_max_zero                 : max=0, total>0 → dominant false
is_dominant_full                     : 100% → dominant true

5. Test coverage (35/35 PASS)

CategoryTestsCases
Guard (NEITHER)10empty / negative / all-zero / NaN / Infinity
ZERO6single bin / near-deterministic 99.5%
INFINITY74-bin uniform / 8-bin uniform / 60/40 (~0.971)
TRUE570/30 moderate
BOTH390/10 low entropy biased
Custom threshold2dominant=0.7 / uniform=0.99
Determinism3same input → same output (verdict + entropy + normalized)

実行: npx tsx test/step1499-shannon-entropy-verdict-test.ts

6. Rei stack 姉妹 tool 群

#tool入力目的STEP
1d8_verdict_from_measurementvalue + noise_floor + threshold_snrSNR ≥ threshold → TRUE / < → NEITHER1350
2d8_verdict_from_multi_trialp-value list + FDR αBH FDR aggregate1371
3d8_verdict_from_sample_pair2 sample listsWelch t-test + Cohen's d BOTH1376 + 1379
4shannonEntropyVerdictfrequency listH(X) → 8 verdict mapping1499 (本 tool)

全 4 tool が pure function、 hardware 依存なし、 determination-focused。 4 tool 揃った ことで 「1 値」 「2 値比較」 「多試行 集約」 「分布 全体」 の 4 側面から D-FUMT₈ verdict 化 の コア完成。

7. Honest scope

❶ 実 entropy 計算 は Math.log2 の IEEE 754 double 精度 (~15-17 桁)。 huge n_bins (>2^50) では accumulation error あり、 実用範囲 (n_bins ≤ 1000) では 問題なし。

❷ Lean 4 side は 決定表 骨格 (NEITHER/ZERO/TRUE 3 verdict) の 静的 identity のみ 検証。 実 entropy 数値 (INFINITY/TRUE/BOTH の 境界) は Mathlib 未 import で 表現困難 のため TS 側 に 責務委譲。

❸ Kolmogorov 複雑度 は 計算不能 (Chaitin) のため 本 tool では 扱わず、 Shannon H(X) の 経験的 分布上 mapping のみ。 実 K(x) proxy は 別 candidate (kolmogorov_lower_bound) 側。

❹ MCP tool wire は 未実装 (rei-aios MCP server への 追加 は 別 STEP)。 現状 は 単体 module + test のみ。

❺ 「世界初」 主張なし。 Shannon (1948) の 既知 entropy formula の D-FUMT₈ verdict mapping。 novelty = 「8 verdict enum への 決定表 明示」 と 「4 姉妹 tool との API 統一」 の operational 側面。