lean-ja / lean-ja/lean-by-example

noConfusion は帰納法の原理から従う

Open
#2,548 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
188
Forks
15
Avg merge
9h 8m
Merged PRs (30d)
6

Description

Lean において、Nat の noConfusion (コンストラクタは単射)は、rec (帰納法)から示すことができますか?

はい。しかも Nat.succ の単射性だけなら、帰納法の仮定は必要なく、Nat.rec で前者関数を作るだけで示せます。

Lean の Nat.rec は、論理的には帰納法の原理、計算的には原始再帰の原理です。コンストラクタに適用された rec はι簡約によって対応する場合へ計算されます。

private def predRec : Nat → Nat :=
Nat.rec
(motive := fun _ => Nat)
0
(fun n _ih => n)
theorem succ_injective_from_rec {m n : Nat}
(h : Nat.succ m = Nat.succ n) : m = n := by
exact congrArg predRec h

ここでは定義的に

predRec 0 = 0
predRec (Nat.succ n) = n

となります。したがって

h : Nat.succ m = Nat.succ n

の両辺に predRec を適用すると、

congrArg predRec h :
predRec (Nat.succ m) = predRec (Nat.succ n)

すなわち定義的に

m = n

が得られます。

コンストラクタの非交差性も rec から示せる

厳密には noConfusion は単射性だけでなく、

0 ≠ Nat.succ n
Nat.succ n ≠ 0

という異なるコンストラクタ同士の非交差性も含みます。公式リファレンスでも、noConfusion はコンストラクタの単射性と非交差性を導く一般的な命題だと説明されています。

これも Nat.rec から作れます。

private def IsZeroRec : Nat → Prop :=
Nat.rec
(motive := fun _ => Prop)
True
(fun _ _ih => False)
theorem zero_ne_succ_from_rec (n : Nat) :
0 ≠ Nat.succ n := by
intro h
have hz : IsZeroRec 0 :=
True.intro
exact h ▸ hz

IsZeroRec 0 は定義的に True、IsZeroRec (Nat.succ n) は定義的に False です。したがって 0 = Nat.succ n なら、等式による輸送によって True の証明から False の証明が得られてしまいます。

結論

Nat.noConfusion の内容は、次のものから導出できます。

  1. Nat.rec の除去・計算規則
  2. 等式の除去規則 Eq.rec
    Lean上では congrArg や ▸ として使用

したがって「Nat.rec だけから」というより、正確には

Nat.rec と等式の通常の除去規則から Nat.noConfusion を構成できる

となります。Lean自身も、帰納型の recursor に基づく補助構成として noConfusion と noConfusionType を生成しています。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue explains Nat.rec, congrArg, Eq.rec, and Nat.noConfusion, but names no target file, page, or test. First identify where this explanation belongs in the Lean-by-example documentation, then verify the examples in Lean and define completion as a placed, reviewed explanation with working snippets.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.