hamming_distance_gate tool v0.1

STEP: 1507 / 公開日: 2026-08-28 / Test: 35/35 PASS / Lean 4: 13 theorem zero sorry / Type: STEP 1493 情報科学 arc candidate #2 実装

短答 (3 行)

hamming_distance_gate = bit string 対 (List Nat 0/1) → Hamming 距離 → 訂正可能性 verdict (TRUE/NEITHER/FALSE)。 STEP 1493 情報科学 arc 6 candidate 第 2 号 実装 (shannon_entropy_verdict = #1)。

threshold-based classification: d ≤ threshold → TRUE (訂正可能) / d = threshold+1 → NEITHER (検出のみ) / d > threshold+1 → FALSE (訂正不能)。 default threshold=1 (single-bit-error correction)。

STEP 1479 par2 recovery evidence の 抽象化: 「1116 blocks 中 1 byte 破損 → par2 -r10 で 完全復元」 の 実測 evidence を pure static verdict identity として 形式化。

1. 決定表 (first-match priority)

#ConditionVerdictReason
1a or b emptyNEITHERempty_input
2length mismatchNEITHERlength_mismatch
3invalid bits (non-0-1)NEITHERinvalid_bit
4d = 0TRUE (⊤)identical
5d ≤ correctionThresholdTRUEcorrectable
6d = correctionThreshold + 1NEITHERdetection_only
7d > correctionThreshold + 1FALSE (⊥)uncorrectable

2. 使用例 (TS)

import { hammingDistanceGate } from './src/mcp/hamming-distance-gate';

// A: identical → TRUE
const rA = hammingDistanceGate({ a: [1,0,1,0], b: [1,0,1,0] });
// { verdict: 'TRUE', reason: 'identical', distance: 0, length: 4, ... }

// B: 1-bit flip, threshold=1 → TRUE (correctable)
const rB = hammingDistanceGate({ a: [1,0,1,0], b: [1,1,1,0] });
// { verdict: 'TRUE', reason: 'correctable', distance: 1, ... }

// C: 2-bit flip, threshold=1 → NEITHER (detection only)
const rC = hammingDistanceGate({ a: [1,0,1,0], b: [1,1,0,0] });
// { verdict: 'NEITHER', reason: 'detection_only', distance: 2, ... }

// D: 3-bit flip, threshold=1 → FALSE (uncorrectable)
const rD = hammingDistanceGate({ a: [1,0,1,0], b: [0,1,0,0] });
// { verdict: 'FALSE', reason: 'uncorrectable', distance: 3, ... }

// E: custom threshold=2 (double-bit correction)
const rE = hammingDistanceGate({
  a: [1,0,1,0], b: [1,1,0,0], correctionThreshold: 2
});
// { verdict: 'TRUE', reason: 'correctable', distance: 2, ... }

3. Lean 4 formalization (13 theorem zero sorry)

-- Hamming 距離 定義 (STEP 1493 継承、 disjoint patterns)
hd_self_zero            : ∀ xs, hamming_dist xs xs = 0
hd_single_diff          : hamming_dist [1] [0] = 1

-- verdict 決定表 (★核 4 theorem)
verdict_identical_gives_true      : d=0 → TRUE
verdict_correctable_gives_true    : d≤threshold, d>0 → TRUE
verdict_detection_gives_neither   : d=threshold+1 → NEITHER
verdict_uncorrectable_gives_false : d>threshold+1 → FALSE

-- threshold=1 specialization (single-bit correction)
verdict_d0_t1_true / d1_t1_true / d2_t1_neither / d3_t1_false

-- threshold=0 specialization (strict identical only)
verdict_d0_t0_true / d1_t0_neither / d2_t0_false

4. Test coverage (35/35 PASS)

CategoryTests
Guard (NEITHER)7 (empty / mismatch / invalid / negative)
TRUE (identical + correctable)7
NEITHER (detection only)4
FALSE (uncorrectable)5
Custom threshold (0/2)6
Edge (single bit)3
Determinism3

実行: npx tsx test/step1507-hamming-distance-gate-test.ts

5. STEP 1479 par2 recovery evidence との 対応

STEP 1479 (2026-08-27) で 「par2cmdline-turbo 1.1.1 で 1116 blocks 中 1 byte 破損 injection → repair で md5 完全一致復元」 を 実測。 本 tool は その 抽象化 identity:

本 tool は 実測 evidence の 静的 identity 層、 実 recovery は par2 layer に 委譲。

6. Rei stack 姉妹 tool 群 (更新)

#tool入力目的STEP
1d8_verdict_from_measurementvalue + noise + thresholdSNR verdict1350
2d8_verdict_from_multi_trialp-value list + FDR αBH FDR1371
3d8_verdict_from_sample_pair2 samplesWelch t-test1376+1379
4shannonEntropyVerdictfrequency listH(X) → 8 verdict1499
5peaceAxiomVerdictbefore/after payoffsPeace Axiom #1961506
6hammingDistanceGate2 bit strings + threshold訂正可能性 verdict1507 (本 tool)

6 tool 揃った ことで 「1 値 / 2 値比較 / 多試行 / 分布 / ゲーム / 誤り訂正」 の 6 側面 D-FUMT₈ verdict 化 core 拡張。

7. Honest scope

❶ bit 表現 は Nat (0/1) 制限、 byte string は 前処理で bit 展開必要。

❷ threshold-based classification は 完全 Hamming (Reed-Solomon 等) と 異なる、 単純な Hamming distance のみ。 error correction 実際は BCH / Reed-Solomon 等 の code-specific bound で 決定。

❸ Lean 4 側は 決定表 骨格 のみ、 Hamming code の 実装 (encoding / decoding) は 未形式化。

❹ 「世界初」 主張なし。 Hamming (1950) 既知構造 の D-FUMT₈ verdict mapping、 novelty = 6 姉妹 tool 統一 API 拡張。

❺ 累計 defer 46 → 45 candidate (本 tool 実装 済、 STEP 1499 + 1506 + 1507 で 3 tool 実装 済)。