逐步主鏈
S01 · definition
操作前
\text{proof term: fixed version, imports, environment }E,\ \Gamma,\ \text{kernel}操作後
\text{ST: atoms }P\neq Q,\ \Gamma_0=\varnothing,\ S=P\land Q\to Q\land P,\ \text{six rules}條件:無
規則:mko_proof_term · 依賴:G1, G2, G3, G4
葉節點依據:mko_proof_term + def_intro
MKO 指出「證明項」只有在固定版本、imports、環境與 local context 之後才有意義。本稿固定一個教學用的對應物:環境 E_ST 只含原子 P、Q,起始 context Γ0 為空,目標命題 S=P∧Q→Q∧P,而「檢查器」的角色由 G2 的六條規則擔任:一個判斷只有在能用這六條規則逐條推出時才算成立。之後所有型別結論都是 ST 中的結論;關於 Lean 的陳述只在 S10 另外處理。
S02 · definition
操作前
t
操作後
t=\lambda h{:}P\land Q.\,\langle \mathrm{snd}\,h,\ \mathrm{fst}\,h\rangle條件:無
規則:def_intro · 依賴:S01, G3
葉節點依據:def_intro + def_unfold
為項取名並逐部分預讀它要建立的東西:λh:P∧Q 引入一個名為 h、型別為 P∧Q 的假設,讀作「假設有 P∧Q 的證明 h」;fst h 與 snd h 從 h 取出 P 與 Q 的證明;⟨·,·⟩ 把兩個證明裝成一個合取的證明,分量的先後決定合取項的先後。依命題即型別,蘊涵的證明是一個把前提的證明變成結論的證明的函數。Lean 4 中對應的表面寫法是 `fun h : P ∧ Q => And.intro h.right h.left`(或 `fun h => ⟨h.2, h.1⟩`),這裡只作閱讀對照。
S03 · implies
操作前
\Gamma_1=\Gamma_0,\ h{:}P\land Q操作後
\Gamma_1\vdash h:P\land Q
條件:h{:}P\land Q\in\Gamma_1
規則:st_var · 依賴:S02, G2
葉節點依據:st_var
λ 的綁定說明本體要在哪個 context 中檢查:Γ1 是 Γ0 加上 h:P∧Q。依 Var 規則,h:P∧Q 列在 Γ1 中,所以 Γ1⊢h:P∧Q。這一部分建立的是:在本體內部,h 可以當作 P∧Q 的證明使用。
S04 · implies
操作前
\Gamma_1\vdash h:P\land Q
操作後
\Gamma_1\vdash \mathrm{snd}\,h:Q條件:A=P,\ B=Q
規則:st_and_elim · 依賴:S03, G2
葉節點依據:st_and_elim
對 S03 使用 ∧E2,取 A=P、B=Q:snd h 取出第二分量,型別為 Q。這一部分建立了「由假設得到 Q 的證明」。snd h 的型別是從 h 的型別讀出來的,不是自行指定的。
S05 · implies
操作前
\Gamma_1\vdash h:P\land Q
操作後
\Gamma_1\vdash \mathrm{fst}\,h:P條件:A=P,\ B=Q
規則:st_and_elim · 依賴:S03, G2
葉節點依據:st_and_elim
對 S03 使用 ∧E1:fst h 取出第一分量,型別為 P。現在 Γ1 中同時有 P 的證明與 Q 的證明,而且兩者都只依賴假設 h。
S06 · implies
操作前
\Gamma_1\vdash \mathrm{snd}\,h:Q,\ \ \Gamma_1\vdash \mathrm{fst}\,h:P操作後
\Gamma_1\vdash \langle \mathrm{snd}\,h,\ \mathrm{fst}\,h\rangle:Q\land P條件:a=\mathrm{snd}\,h,\ A=Q,\ b=\mathrm{fst}\,h,\ B=P
規則:st_and_intro · 依賴:S04, S05
葉節點依據:st_and_intro
使用 ∧I,第一分量 a=snd h(型別 A=Q),第二分量 b=fst h(型別 B=P),得到 A∧B=Q∧P。合取項的先後由分量的先後決定:第一分量的型別成為左合取項。這一部分建立了「由 P∧Q 的假設得到 Q∧P 的證明」。
S07 · implies
操作前
\Gamma_0,\ h{:}P\land Q\vdash \langle \mathrm{snd}\,h,\ \mathrm{fst}\,h\rangle:Q\land P操作後
\Gamma_0\vdash \lambda h{:}P\land Q.\,\langle \mathrm{snd}\,h,\ \mathrm{fst}\,h\rangle:P\land Q\to Q\land P條件:x=h,\ A=P\land Q,\ B=Q\land P
規則:st_imp_intro · 依賴:S06, S03
葉節點依據:st_imp_intro + imp_intro
使用 →I,x=h、A=P∧Q、B=Q∧P:釋放假設 h,結論位於 Γ0,其中已沒有 h。綁定上的註記 P∧Q 成為蘊涵的前件,本體的型別 Q∧P 成為後件。這正是 →引入(imp_intro)在命題即型別下的讀法:在假設 P∧Q 的作用域中得到 Q∧P,就得到 P∧Q→Q∧P。
S08 · implies
操作前
T(t)=P\land Q\to Q\land P,\ \ S=P\land Q\to Q\land P
操作後
T(t)\equiv S
條件:無
規則:st_type_eq · 依賴:S07, G3
葉節點依據:st_type_eq + eq_refl_symm_trans
MKO 的公式 T(t)=P 要求推得的型別與命題相同(本稿把命題記為 S,以免與原子 P 混淆)。逐符號比較:前件 P∧Q 對 P∧Q,後件 Q∧P 對 Q∧P,完全相同,所以在 ST 中 T(t)≡S。Lean 的型別比對是到定義相等為止,範圍較寬;ST 只用語法相同,所以這裡沒有使用任何 conversion。
S09 · implies
操作前
\Gamma_0\vdash t:T(t),\ \ T(t)\equiv S
操作後
t\ \text{is a proof term for }S\ \text{in ST}條件:無
規則:mko_proof_term · 依賴:S07, S08, mko_proof_term
葉節點依據:mko_proof_term + modus_ponens + eq_replace
MKO 的定義要求兩件事:項的型別就是該命題,而且固定環境的檢查器接受這個判斷。在 ST 中檢查器就是規則表:S03 到 S07 每一步都是 G2 的一條規則,構成 Γ0⊢t:T(t) 的完整推導;S08 把 T(t) 與 S 等同,所以 Γ0⊢t:S 可推導,這是「kernel 接受 Γ⊢t:P」在 ST 中的對應。因此 t 是 S 在 ST 中的證明項;此步宣稱的就只有這些。
S10 · implies
操作前
t\ \text{proof term in ST};\ \text{Lean not run}操作後
\text{Lean counterpart: candidate term, no kernel verdict, no receipt}條件:無
規則:mko_receipt · 依賴:S09, G4, mko_receipt
葉節點依據:mko_receipt + modus_ponens
依 MKO,只有保存 term 並在指定 kernel/環境中檢查,才形成 receipt。G4 說明本稿沒有執行 Lean,沒有保存也沒有檢查任何 term。所以 Lean 4 對應寫法 `fun h : P ∧ Q => And.intro h.right h.left` 的狀態只是候選 proof term:不宣稱 kernel 接受,也沒有 receipt。ST 的推導不能代替 kernel 判斷,因為兩者是不同的系統(Lean 另有 universe、定義相等與 elaborator)。即使日後 kernel 接受,也只證形式 judgment;命題是否忠實表達原意、imports 是否含不當公理仍需另外審查。
S11 · implies
操作前
\text{rule table of ST}操作後
\text{each outer term form is concluded by exactly one rule}條件:無
規則:case_analysis · 依賴:G2
葉節點依據:case_analysis + def_unfold
逐條檢查六條規則結論中主詞的外層形式:Var 是變數;∧I 是配對 ⟨a,b⟩;∧E1 是 fst p;∧E2 是 snd p;→I 是 λx:A.b;→E 是應用 f a。六條規則對應六種互不相同的形式,而每個項恰有一種外層形式。Γ⊢u:A 的推導必以某條結論為 Γ⊢u:A 的規則結束,所以最後一條規則就是 u 的外層形式所對應的唯一規則,其前提必在其上方已被推出,A 也必具該規則規定的形狀。這證明了引理 L_inversion。
S12 · implies
操作前
t'=\lambda h{:}P\land Q.\,\langle \mathrm{fst}\,h,\ \mathrm{snd}\,h\rangle操作後
\Gamma_0\nvdash t':P\land Q\to Q\land P
條件:無
規則:L_tprime_untyped · 依賴:G3, L_tprime_untyped
葉節點依據:L_inversion + st_type_eq + contradiction
依引理 L_tprime_untyped(在 S12.1 到 S12.4 證明),t′ 在 ST 中不能具有型別 S。所以 t′ 不是 S 的證明項,即使它用到同一個假設與同樣兩個投影。
S13 · implies
操作前
\Gamma_1\vdash \mathrm{fst}\,h:P,\ \ \Gamma_1\vdash \mathrm{snd}\,h:Q操作後
\Gamma_1\vdash \langle \mathrm{fst}\,h,\ \mathrm{snd}\,h\rangle:P\land Q條件:a=\mathrm{fst}\,h,\ A=P,\ b=\mathrm{snd}\,h,\ B=Q
規則:st_and_intro · 依賴:S04, S05
葉節點依據:st_and_intro
看看 t′ 實際證明了什麼:分量次序為 fst h、snd h,∧I 給出 P∧Q,而不是 Q∧P。差別只在分量次序,但型別因此不同。
S14 · implies
操作前
\Gamma_0,\ h{:}P\land Q\vdash \langle \mathrm{fst}\,h,\ \mathrm{snd}\,h\rangle:P\land Q操作後
\Gamma_0\vdash t':P\land Q\to P\land Q
條件:x=h,\ A=P\land Q,\ B=P\land Q
規則:st_imp_intro · 依賴:S13
葉節點依據:st_imp_intro + imp_intro
對 S13 使用 →I 並釋放 h:t′ 是 P∧Q→P∧Q 的證明項,這是另一個命題。所以「是否為 S 的證明項」取決於確切的型別,而不是取決於用到哪些假設或投影。
S15 · implies
操作前
\Gamma_0\vdash t:S,\ \Gamma_0\nvdash t':S,\ \text{Lean not run}操作後
t\ \text{proves }S\ \text{in ST};\ t'\ \text{does not};\ \text{no Lean receipt}條件:無
規則:and_intro_elim · 依賴:S09, S10, S12, S14
葉節點依據:and_intro_elim
合併三個結論:t 是 S 在 ST 中的證明項(S09);t′ 不是(S12),它證明的是 P∧Q→P∧Q(S14);Lean 方面只有候選項,沒有 kernel 判斷與 receipt(S10)。
局部子步與引理
S12.1 · implies
操作前
\Gamma_0\vdash t':P\land Q\to Q\land P\ \ (\text{assumed})操作後
\Gamma_1\vdash \langle \mathrm{fst}\,h,\ \mathrm{snd}\,h\rangle:Q\land P條件:無
規則:L_inversion · 依賴:G3, L_inversion
葉節點依據:L_inversion + st_type_eq
為了反證,假設 Γ0⊢t′:S 有推導。t′ 的外層形式是 λ,依 L_inversion 最後一條規則必為 →I,其結論型別 A→B 中 A 是綁定註記 P∧Q;由 A→B≡P∧Q→Q∧P 得 B≡Q∧P。所以前提 Γ0,h:P∧Q⊢⟨fst h, snd h⟩:Q∧P 可推導,也就是 Γ1⊢⟨fst h, snd h⟩:Q∧P。
S12.2 · implies
操作前
\Gamma_1\vdash \langle \mathrm{fst}\,h,\ \mathrm{snd}\,h\rangle:Q\land P操作後
\Gamma_1\vdash \mathrm{fst}\,h:Q條件:無
規則:L_inversion · 依賴:S12.1, L_inversion
葉節點依據:L_inversion + st_type_eq
配對只能由 ∧I 推出,其結論型別 A∧B 中 A 是第一分量的型別。由 A∧B≡Q∧P 得 A≡Q,所以前提 Γ1⊢fst h:Q 必須可推導。
S12.3 · implies
操作前
\Gamma_1\vdash \mathrm{fst}\,h:Q操作後
\Gamma_1\vdash h:Q\land B\ \text{for some type }B條件:無
規則:L_inversion · 依賴:S12.2, L_inversion
葉節點依據:L_inversion
fst 的形式只能由 ∧E1 推出,其前提是 Γ1⊢h:A∧B 且結論型別為 A。這裡 A≡Q,所以存在某個型別 B 使 Γ1⊢h:Q∧B 可推導。
S12.4 · implies
操作前
\Gamma_1\vdash h:Q\land B
操作後
Q\land B\equiv P\land Q\Rightarrow Q\equiv P\ \ (\text{contradiction})條件:P\not\equiv Q
規則:contradiction · 依賴:S12.3, G1, G2, L_inversion
葉節點依據:st_var + st_type_eq + contradiction
變數只能由 Var 推出,所以 h:Q∧B 必須就是 Γ1 中 h 的條目;Γ1 只列 h 一次,型別為 P∧Q,故 Q∧B≡P∧Q。依 st_type_eq 逐分量比較得 Q≡P,與 G1 中 P、Q 為相異原子矛盾。所以 S12.1 的假設不成立,Γ0⊢t′:S 不可推導。S12.1 到 S12.4 合起來證得引理 L_tprime_untyped。