Operator-Native RDSS Type-and-Effect Calculus
Formation, Preservation, Effect Accounting, and Explicit Residuals
版本: v0.6 Working Draft
日期: 2026-08-10
作者:Neo.K
機構:EveMissLab/一言諾科技有限公司
定位: ON-RDSS 第一代型別—效果演算/Subject Reduction 候選定理/有限 checker 驗證
摘要
本文在 ON-RDSS v0.5 的統一算子形式:
Op[σ⇒τ!ϵ@d]
上建立第一代 Type-and-Effect Calculus。
本輪最重要的修正有三項。
第一,effect 不再只是一個無序集合。ON-RDSS 已明確承認 non-commutativity、History 與 reduction-path relevance,因此 effect annotation 若僅使用:
ϵ1∪ϵ2
會錯誤地把:
A;B
與:
B;A
視為同一效果。本文改用:
χ=[e1,…,en]
作為保序 effect trace,另可從 χ 提取 effect summary。
第二,Subject Reduction 被拆為:
Structural Preservation
與:
Execution Effect Accounting.
結構 reduction 只做合法封裝/巨集化,不應改變外部型別與 effect trace;真正 execution 則可以消耗 effect,但必須把已執行 effect 寫入 trace / history,使「已執行 + 剩餘」仍可重構原 effect obligation。
第三,傳統 progress 被改為:
Progress or Explicit Residual.
若一個 operator word 無法繼續,不把它變成 0 、False 或假輸出,而必須產生帶型、帶義務的 residual。
1. 外部數學接口
Type-and-effect systems 的成熟思想是:type 描述計算可產生何種值,而 effect 額外描述計算可能發生的行為。ON-RDSS 採用此分離,但把 effect 擴張為:
- state mutation;
- relation formation;
- projection / loss;
- authority;
- certificate generation;
- history update;
- meta rewrite。
本文不主張發明 type-and-effect system;研究重點是將 effect discipline 與 partial composition、certificates、history、meta-depth 和 residual semantics 接合。
2. Sorts
第一代 sorts:
σ,τ::=State∣Relation∣Family[σ]∣View[σ]∣Candidate∣Cert∣Evidence∣History∣Algebra[d]∣Residual[ω].
其中:
Residual[ω]
保存尚未解除的 obligation ω。
3. Effects
定義 effect alphabet:
E={realize,mutate,relate,select,project,loss,judge,witness,authority,history,io,meta,rewrite,…}.
4. Effect Trace
不用純集合,而使用:
χ∈E∗.
例如:
χ=[realize,mutate,project].
順序一般具有語義:
[ea,eb]≡[eb,ea].
5. Effect Summary
為了快速靜態檢查,可另外定義:
Summary(χ)=ϵ.
例如:
Summary([mutate,project,mutate])={mutate,project}.
因此:
EffectSummary=EffectTrace.
前者可用於 conservative capability checking;後者保存 history / order。
6. Certified Effect Commutation
不是所有 effect 都不可交換。
定義 context-relative independence:
IΓ⊆E×E.
若:
(ea,eb)∈IΓ
並有:
CommCertΓ(ea,eb),
才允許:
[χ1,ea,eb,χ2]≡Γ[χ1,eb,ea,χ2].
這建立一種 trace-like partial commutation。
若沒有 certificate:
mutate;project
不得因 effect set 相同而交換。
7. Operator Typing
統一 judgment:
Γ⊢O:σ⇒τ!χ@d.
其中:
- σ:輸入 sorts;
- τ:輸出 sort;
- χ:ordered effect trace;
- d:meta-depth。
8. Formation Rule — Realize
Γ⊢R:()⇒State![realize]@0\textscT−Realize
9. Formation Rule — Transform
Γ⊢T:σ⇒τ![mutate]@0Γ⊢σ sortΓ⊢τ sort\textscT−Transform
特化 State transition:
State⇒State.
10. Formation Rule — Relate
Γ⊢L:(σ1,σ2)⇒Relation![relate]@0Γ⊢σ1 sortΓ⊢σ2 sort\textscT−Relate
11. Formation Rule — Select
Γ⊢S:Family[σ]⇒Family[σ]![select]@0Γ⊢σ sort\textscT−Select
附 side condition:
Supp(S(X))⊆Supp(X).
12. Formation Rule — Certify
Γ⊢C:Candidate⇒Cert![judge,witness]@0Γ⊢Candidate sort\textscT−Certify
Certificate 必須 proof-relevant。
13. Formation Rule — Meta
Γ⊢M:(Algebra[d],Evidence)⇒Algebra[d+1]![meta,rewrite]@(d+1)d≥0\textscT−Meta
第一版採單調 meta-depth。
後續可考慮同層 rewrite 與降階 realization。
14. Partial Executability Judgment
Typing 不表示可執行:
Γ⊢O:σ⇒τ!\chi@d
仍需:
Γ;C⊢O↓.
C 可包括:
- authority;
- resource;
- bridge;
- runtime availability;
- certificate;
- freshness。
15. Sequential Composition Typing
若:
Γ⊢O1:σ⇒τ!χ1@d1
以及 unary continuation:
Γ⊢O2:τ⇒υ!χ2@d2,
且 composition certificate 成立,則:
Γ⊢O2⋄O1:σ⇒υ!(χ1⋅χ2)@max(d1,d2).
其中:
⋅
是 effect-trace concatenation。
16. 為什麼不是 χ1∪χ2?
因:
[mutate,project]
與:
[project,mutate]
可能具有:
Summary(χ1)=Summary(χ2),
但語義不同。
因此 sequential composition 預設使用:
χ1⋅χ2.
只有得到 commutation certificate 才能 quotient。
17. Multi-input Wiring Typing
若:
O:(σ1,…,σn)⇒τ!χO@dO
而每一輸入 wiring:
Wi:ρi⇒σi!χi@di,
則在 port / authority / bridge certificates 完整時:
O∘(W1,…,Wn):(ρ1,…,ρn)⇒τ!χwire@max(dO,d1,…,dn).
χwire 不預設只是任意線性化;並行 wiring 的 effect order 需由 causal / commutation semantics 決定。
18. Structural Reduction
定義:
W⇒sW′
表示純 structural / macro reduction。
它:
- 不真正執行 effect;
- 不修改 authority;
- 不消耗 runtime resource;
- 只把 typed subword 封裝為等價 macro operator。
19. Structural Preservation 候選定理
命題 SR-S
若:
Γ⊢W:σ⇒τ!χ@d
且:
W⇒sW′,
則存在:
χ′
使:
Γ⊢W′:σ⇒τ!χ′@d
且:
χ′≡Γχ.
即:
- external input sorts 保持;
- output sort 保持;
- meta-depth 保持;
- effect trace 至少在 certified commutation congruence 下保持。
20. 強 Structural Preservation
若 structural reduction 不包含 effect reordering,則:
χ′=χ.
這是本輪 toy checker 實際驗證的版本。
21. Runtime Execution Step
另定義:
⟨O,ρ,H⟩e,c⟨O′,ρ′,H′⟩.
其中:
- ρ:runtime environment/state;
- e:此次真正執行的 effect;
- c:execution certificate / trace record。
這與 structural reduction 分離。
22. Effect Accounting
若原 operator effect trace:
χ=[e1,…,en],
執行 prefix:
χdone=[e1,…,ek],
剩餘:
χrem=[ek+1,…,en],
要求:
χ=χdone⋅χrem.
若允許 certified commutation:
χ≡Γχdone⋅χrem.
23. Execution Preservation / Accounting 候選定理
命題 SR-E
若:
Γ⊢O:σ⇒τ!χ@d
且:
⟨O,ρ,H⟩χdone,c⟨O′,ρ′,H′⟩,
則:
Γ⊢O′:σ′⇒τ!χrem@d′
並要求:
χ≡Γχdone⋅χrem,
同時:
H′=H⊕Trace(χdone,c).
這不是傳統「effect 完全不變」,而是 effect obligation 的保守會計。
24. Meta Execution 的額外條件
若:
meta∈χdone,
則允許:
d′=d
或:
A′=A.
但必須產生:
AlgebraVersionTransitionCertificate.
非 Meta execution 不得任意改變:
A.
25. Typed Residual
若某一步 composition 期待:
σ
卻收到:
τ,τ∼Γσ,
不輸出普通 value。
而輸出:
Residual[TypeMismatch(actual=τ,expected=σ,location=i)].
26. Bridge Residual
若 type 可透過 bridge 修正但 bridge 尚缺:
Residual[BridgeRequired(τ⇝σ)].
這不是 terminal failure。
未來加入:
B:τ⇀σ
後可 resume reduction。
27. Certificate Residual
若形式作用可能成立,但缺證書:
Residual[CertificateRequired(rule,scope,authority)].
28. Explicit Residual Progress
傳統 progress 常寫:
well-typed closed term 不是 value,就是能繼續一步。
ON-RDSS 需要更寬版本。
候選命題 PR-R
對一個 well-formed operator word W,在固定 Algebra Snapshot 與有限檢查條件下,以下至少一項成立:
- W 已是 executable normal form;
- 存在 certified structural reduction:W⇒sW′;
- 存在 runtime execution step;
- 產生明確 typed residual:Residual[ω].
因此:
Progress∨ExplicitResidual.
29. Residual 不是 Type Error 的遮羞布
只有在:
ω
包含完整:
- expected sort;
- actual sort;
- failed rule;
- bridge possibility;
- required cert;
- AlgebraSnapshotID;
時才算 typed residual。
否則:
UnknownFailure
不能被包裝成合法 Limbo。
30. Subject Reduction 的證明策略
正式證明可按 reduction rule 歸納。
對每個 structural rule:
r:Wl⇒sWr,
都需證:
Interface preservation
In(Wl)=In(Wr).
Output preservation
Out(Wl)=Out(Wr).
Meta-depth preservation
Depth(Wl)=Depth(Wr).
Effect preservation
Effect(Wl)≡ΓEffect(Wr).
Obligation preservation
Obl(Wr)⊆Closure(Obl(Wl)∪Cert(r)).
31. Critical Pair 與 Type Preservation
即使每個 reduction rule individually preserves typing,不同 path:
W⇒∗N1,
W⇒∗N2
仍可能:
Effect(N1)≡Effect(N2).
因此 type preservation 不推出 confluence。
需要另外證:
CriticalPairJoinability.
32. Subject Reduction 與 History
若兩條路徑都保持:
σ⇒τ,
卻:
χ1≡χ2,
則:
same type=same computation.
這正是 ON-RDSS 不把 subject reduction 誤當成 process equality 的原因。
33. Effect Trace 與部分交換
若:
IΓ
是一個 certified independence relation,
可以將 effect words 依:
ab∼bawhen (a,b)∈IΓ
商化。
這與 partially commutative trace / trace-monoid 的數學語言相鄰。
ON-RDSS 不預設所有 effects 的 independence;Independence 本身需要 Cert。
34. 本輪 Toy Checker
本輪有限 checker 使用:
Sig(
inputs,
output,
ordered effects,
meta_depth
)
建立:
R:()⇒State![realize]@0,
T:State⇒State![mutate]@0.
35. Structural Preservation 實測
原 word:
R;T;T
得到:
()⇒State![realize,mutate,mutate]@0.
先 reduction:
T;T⇒T2,
得到:
R;T2.
再封裝:
R;T2⇒RT2.
兩輪結果都保持:
- inputs = () ;
- output = State;
- effect trace =
$[realize,mutate,mutate]$ ;
- meta-depth = 0。
因此 toy model:
StructuralPreservation=true.
36. Explicit Residual 實測
建立:
R;P;T
其中:
P:State⇒View![project].
執行到:
P;T
時:
actual=View,
expected=State.
checker 不輸出假 State,而得到:
Residual[TypeMismatch(View,State)].
37. Effect Accounting 實測
對:
χ=[realize,mutate,mutate],
消耗第一個 effect:
χdone=[realize],
χrem=[mutate,mutate],
實測:
χ=χdone⋅χrem.
再消耗兩個亦成立。
38. Certified Commutation 實測
toy independence relation 只允許:
reada∥readb.
因此:
[reada,readb]⇒[readb,reada]
成立。
但:
[mutate,project]
沒有 commutation certificate,
所以不能交換。
這驗證:
effect order preserved by default.
39. 目前第一個真正的 theorem candidate
因此 ON-RDSS 現在最值得正式證的是:
Typed Structural Preservation Theorem
對固定:
Γ,A
若:
Γ⊢W:σ⇒τ!χ@d
且:
W⇒sW′,
則:
Γ⊢W′:σ⇒τ!χ′@d
且:
χ′≡Γχ.
40. 第二個 theorem candidate
Effect Accounting Theorem
對 certified execution:
WχdoneW′,
若初始 effect:
χ,
則存在剩餘:
χrem
使:
χ≡Γχdone⋅χrem.
且:
H′=H⊕Trace(χdone).
41. 第三個 theorem candidate
Explicit Residual Progress
對 fixed algebra snapshot 中的 well-formed finite operator word:
Executable∨Reducible∨ExecutableStep∨TypedResidual.
這將「停住」本身變成可分析結果。
42. 三個 theorem 之間的關係
Preservation
保證 reduction 不亂掉 type/effect interface。
EffectAccounting
保證真正執行不偷丟 side effects / history。
ExplicitResidualProgress
保證無法前進時不是 silent failure。
三者共同才比較接近 ON-RDSS 的 type safety。
43. ON-RDSS Type Safety 暫定式
可暫寫:
TypeSafetyON=Preservation+EffectAccounting+ExplicitResidualProgress.
再加 governance:
+CertificateSoundness+MetaVersionSafety.
44. 下一輪需要補的東西
- 正式 sort formation;
- subtyping / subeffect relation;
- effect trace equivalence;
- residual typing rules;
- bridge insertion typing;
- wiring typing;
- structural subject-reduction proof skeleton;
- execution accounting induction;
- explicit residual progress proof;
- Meta step 的 version-preservation rule。
45. 暫定結論
ON-RDSS 現在已經從:
萬物皆算子
往前推到:
萬物皆可用同一算子 schema 形式化,
但每個算子必須帶:
Sort+Arity+Ordered Effect Trace+MetaDepth+Certificate Obligations.
而每次計算不是只問:
有沒有 output?
而同時問:
型別是否保持?
effect 有沒有被完整會計?
歷史是否被保存?
不能繼續時留下的是什麼 residual?
這次作用憑什麼合法?
因此 Type-and-Effect Calculus 開始成為 ON-RDSS 真正可驗證的形式核心。