Skip to content

市场模型关系分析报告

2026-11-26:ADR-0029 已接受并实施,paid / refunded / charged_back 已改为 virtual derived relation。本报告保留为迁移前的审计时点,第 2 / 3.6 / 3.7 节里把三者列为 base relation 与派生候选的描述不再反映当前模型。

状态:报告原型,不是规范。本文是 Q-013 的关系分析报告原型,样本是迁移前的 Aurora 订阅市场 模型。只做报告,不改模型、规范、ADR 或 Q;不自动改模型(对应 语言决策清单 的 D1)。

1. 范围与口径

  • 样本:docs/examples/market.md 当前模型。共 26 个 base relation,0 个 derived relation。
  • 只报告,不修改:本节列出的派生、冗余、精化等候选都不落成模型改动(D1)。
  • 本文未运行 explore,探索性结论一律标 holds-in-scope 或 unknown;只在有确定场景 witness 时标 refuted。可复现命令见 第 4 节。
  • proved 只保留给两类不需要探索的结论:
    • 编译器/检查器能从声明直接推出的结构事实(key total、类型不可比较、derived 声明合法性);
    • 已声明 axiom 直接给出或一步传递的后果。
  • 状态词沿用 关系语义与历史分析 第 9 节的证据分级:proved / holds-in-scope / refuted / unknown / inconsistent。

2. 关系清单与时间角色

时间角色五类:

  • 静态链接:记录实体间的归属/对应,不随生命周期变化。
  • 当前状态:key total / key partial 的当前快照(状态、属性、当前值)。
  • 事件时间:记录“某事在何时发生”(带 Timestamp 参数)。
  • 历史标志:只记录“曾经发生过”(一元关系,无时间参数)。
  • 派生:由公式定义、不存储的只读关系。当前模型没有;候选见 3.6。
relation 签名与 key @gloss 时间角色
placed_by (Order, Customer),key 全参数 {order} 由 {customer} 下单 静态链接
sold_by (Order, Seller),key 全参数 {order} 由 {seller} 销售 静态链接
line_in (Line, Order),key 全参数 {line} 属于 {order} 静态链接
subscription_for (Subscription, Customer),key 全参数 {sub} 的订阅客户是 {customer} 静态链接
subscription_order (Subscription, Order),key 全参数 {sub} 对应 {order} 静态链接
invoice_for (Invoice, Order),key 全参数 {invoice} 对应 {order} 静态链接
dispute_for (Dispute, Order),key 全参数 {dispute} 对应 {order} 静态链接
status (Order, OrderStatus),key total (order) {order} 的当前状态是 {value} 当前状态
line_money (Line, Money),key total (line) {line} 的金额是 {value} 当前状态
order_currency (Order, Currency),key total (order) {order} 的结算币种是 {value} 当前状态
service_radius (Seller, Length),key total (seller) {seller} 的服务半径是 {value} 当前状态
subscription_status (Subscription, SubscriptionStatus),key total (sub) {sub} 的当前订阅状态是 {value} 当前状态
invoice_status (Invoice, InvoiceStatus),key total (invoice) {invoice} 的当前发票状态是 {value} 当前状态
dispute_status (Dispute, DisputeStatus),key total (dispute) {dispute} 的当前争议状态是 {value} 当前状态
exchange_rate (Currency, Decimal),key total (currency) {currency} 的当前基准汇率是 {rate} 当前状态
settled_amount (Order, Decimal),key partial (order) {order} 的入账金额是 {value} 当前状态(存储的派生快照)
placed_at (Order, Timestamp),key partial (order) {order} 在 {value} 下单 事件时间
paid_at (Order, Timestamp),key partial (order) {order} 在 {value} 支付 事件时间
refunded_at (Order, Timestamp),key partial (order) {order} 在 {value} 退款 事件时间
charged_back_at (Order, Timestamp),key partial (order) {order} 在 {value} 拒付 事件时间
subscription_status_at (Subscription, Timestamp),key partial (sub) {sub} 在 {value} 变更订阅状态 事件时间
exchange_rate_at (Currency, Timestamp, Decimal),key partial (currency, at) {currency} 在 {at} 的基准汇率是 {rate} 事件时间(历史值)
applied_rate (Order, Currency, Currency, Decimal, Timestamp),key partial (order) {order} 在 {at} 从 {from} 折算到 {to},使用汇率 {rate} 事件时间(固化快照)
paid (Order),key 全参数 {order} 曾经支付过 历史标志
refunded (Order),key 全参数 {order} 曾经退款 历史标志
charged_back (Order),key 全参数 {order} 曾经拒付 历史标志

边界说明:

  • settled_amount 是“当前值”,但它是 pay 时点 order_total × rate 的存储快照,属于派生候选(3.8)。
  • applied_rate 记录“何时折算”,带时间参数,归事件时间;同时它是 exchange_rate_at 的订单级固化副本(3.8)。
  • exchange_rate(当前快照)与 exchange_rate_at(历史行)同概念不同时间角色,见 3.9。

3. 候选关系报告

覆盖十类:等价、蕴含、不相交、重叠、独立、派生、冗余、精化、时间投影、上下文重复。每行给主张、范围、证据(附证据类型)、状态、witness/反例。

“范围”里的“s0 可达”指从 init s0 出发、由 transition 生成的可达世界。现有测试确认该集合有 12 个世界、16 条边(impl/rust/crates/koine/tests/explore.rs 的 gold_market_explore_stable_and_contains_refund_flow),因此有界探索在本样本内是可行的。本文未亲自运行 explore,探索性结论标 holds-in-scope / unknown。

证据类型三档:编译器(声明直接可查)、有界 explore(需探索可达世界)、历史/as-of(需路径回放或时间点查询)。

3.1 等价

候选 主张 范围 证据(类型) 状态 witness / 反例
paid ≡ paid_at paid(o) ⇔ ∃t. paid_at(o,t) s0 可达 纸面:只有 pay 同时写两者,无 transition 删除,初始皆空(有界 explore) holds-in-scope 无(当前 transition 集内)
refunded ≡ refunded_at refunded(o) ⇔ ∃t. refunded_at(o,t) s0 可达 同上(有界 explore) holds-in-scope 无
charged_back ≡ charged_back_at charged_back(o) ⇔ ∃t. charged_back_at(o,t) s0 可达 同上(有界 explore) holds-in-scope 无
status Refunded ≡ refunded status(o,Refunded) ⇔ refunded(o) s0 可达 纸面:refund 同时写两者,无 transition 离开 Refunded(有界 explore) holds-in-scope 无(脆弱:新增 Refunded → Closed 即破)
status ChargedBack ≡ charged_back status(o,ChargedBack) ⇔ charged_back(o) s0 可达 同上(有界 explore) holds-in-scope 无(脆弱)
status Paid ≡ paid status(o,Paid) ⇔ paid(o) s0 可达 refund_flow 最终世界:paid(o1) 真、status(o1,Refunded)(run) refuted refund_flow s3

3.2 蕴含

候选 主张 范围 证据(类型) 状态 witness / 反例
status Paid ⇒ paid status(o,Paid) ⇒ paid(o) 全局 axiom PaidStatusRequiresPayment(编译器) proved(axiom) —
refunded ⇒ paid refunded(o) ⇒ paid(o) 全局 axiom RefundRequiresPayment proved(axiom) —
charged_back ⇒ paid charged_back(o) ⇒ paid(o) 全局 axiom ChargebackRequiresPayment proved(axiom) —
status Refunded ⇒ paid 传递:status Refunded ⇒ refunded ⇒ paid 全局 RefundedStatusRequiresRefund + RefundRequiresPayment proved(axiom) —
status ChargedBack ⇒ paid 传递 全局 ChargedBackStatusRequiresChargeback + ChargebackRequiresPayment proved(axiom) —
paid ⇒ status Paid paid(o) ⇒ status(o,Paid) s0 可达 refund_flow s3(run) refuted refund_flow s3:paid(o1) 真、status ≠ Paid

3.3 不相交

候选 主张 范围 证据(类型) 状态 witness / 反例
status 各值 同一 order 不同状态值互斥 全局 key total (order)(编译器) proved(编译器) —
其余 key total 关系 line_money、order_currency、service_radius、subscription_status、invoice_status、dispute_status、exchange_rate 同理 全局 key total(编译器) proved(编译器) —
refunded / charged_back refunded(o) ∧ charged_back(o) 不可能 全局 axiom NoDoubleRefund proved(axiom) —
refunded / status ChargedBack 传递:status ChargedBack ⇒ charged_back + NoDoubleRefund 全局 axiom 传递 proved(axiom) —
charged_back / status Refunded 同理 全局 axiom 传递 proved(axiom) —
paid / status Draft paid(o) ∧ status(o,Draft) 不可能 s0 可达 纸面:pay 要求 Placed,无 transition 写回 Draft(有界 explore) holds-in-scope 无(全局无 axiom)

3.4 重叠

“重叠”按“不相交假设被推翻”来报:一个 witness 即把不相交判为 refuted,同时说明两者重叠成立。

候选 被检验的不相交假设 范围 证据(类型) 状态 witness / 反例
paid / refunded 两者不相交 s0 可达 refund_flow 最终世界(run) refuted s3:paid(o1) ∧ refunded(o1)
paid / charged_back 两者不相交 s0 可达 chargeback_flow 最终世界(run) refuted 最终:paid(o1) ∧ charged_back(o1)
paid_at / refunded_at 两者不相交 s0 可达 refund_flow 最终世界(run) refuted s3:paid_at(o1,T0) ∧ refunded_at(o1,T0)

3.5 独立

“独立”是全称主张(所有组合都可实现)。纸面只能得到“未发现交叉约束”,不能证明独立;要升级需要 explore/穷举。

候选 主张 范围 证据(类型) 状态 witness / 反例
status / subscription_status 无交叉约束,可独立变化 s0 可达 纸面:不同实体类型,无共同 axiom/transition(有界 explore) unknown(未发现约束 ≠ 证明独立) —
line_money / order_currency 无交叉约束 s0 可达 纸面(有界 explore) unknown —
service_radius / 订单关系 无交叉约束 s0 可达 纸面(有界 explore) unknown —

3.6 派生

候选 derived relation(K-026):

derived relation paid(order: Order) {
  exists (t: Timestamp). paid_at(order, t)
}

derived relation refunded(order: Order) {
  exists (t: Timestamp). refunded_at(order, t)
}

derived relation charged_back(order: Order) {
  exists (t: Timestamp). charged_back_at(order, t)
}
候选 主张 范围 证据(类型) 状态 witness / 反例
paid 派生自 paid_at 声明合法,且扩展等价于迁移前 base paid s0 可达 声明合法性编译器可查;扩展等价纸面(有界 explore) 声明合法性 proved(编译器);扩展等价 holds-in-scope 无
refunded / refunded_at 同理 s0 可达 同上 holds-in-scope 无
charged_back / charged_back_at 同理 s0 可达 同上 holds-in-scope 无
status Paid 派生自 paid status(o,Paid) = paid(o) s0 可达 反例:退款后 paid 真、status ≠ Paid(run) refuted refund_flow s3

3.7 冗余

候选 主张 范围 证据(类型) 状态 witness / 反例
迁移前 paid(base)冗余 可由 paid_at 派生却仍作 base 存储 s0 可达 依赖 3.6 等价(纸面) holds-in-scope —
refunded / charged_back 同理 同上 s0 可达 同上 holds-in-scope —
status Refunded / refunded 过渡性冗余 当前可达世界内等价,双份 s0 可达 依赖 3.1 等价(纸面) holds-in-scope(脆弱) —

消除方向已由 ADR-0016 给出(virtual derived relation)。迁移前模型以 base relation 存储;ADR-0029 已于 2026-11-26 接受并实施,本报告不改(D1)。

3.8 精化

候选 主张 范围 证据(类型) 状态 witness / 反例
applied_rate 精化 exchange_rate_at applied_rate(order,from,to,rate,at) 行蕴含 exchange_rate_at(from,at,rate) 行 s0 可达 纸面:pay 的 require exchange_rate_at(order_currency(order), now(), rate)(有界 explore) holds-in-scope 无
settled_amount 固化 order_total × rate settled_amount 是 pay 时点 order_total × rate 的快照 s0 可达 纸面:pay 写 settled_amount(order, amount_of(order_total(order)) * rate);无后续写 line_money(有界 explore) holds-in-scope(脆弱:改 line_money 即漂移) 无

3.9 时间投影

候选 主张 范围 证据(类型) 状态 witness / 反例
status / paid / paid_at status 是当前投影,paid 是“曾经”投影,paid_at 是事件时间;paid ≡ status Paid 不成立 s0 可达 正向 axiom PaidStatusRequiresPayment;反向反例(历史/as-of) 正向 proved(axiom);反向 refuted refund_flow s3
同一 time 多事件排序 refund_flow 四步都在 T0,as_of(o1, T0) 有歧义 — 纸面(历史/as-of) unknown(缺 as-of 表示,Q-007) refund_flow:Draft→Placed→Paid→Refunded 全在 T0

完整回答“某时刻 t 的 status / paid”需要 as-of:当前 CLI 有 history / diff(路径回放),但没有模型级 as-of;历史真值来源定为 snapshot-sequence + path(ADR-0015);as-of 用 define / derived relation 派生、不引入 interval 类型(Q-007 已 answered)。

3.10 上下文重复

候选 主张 范围 证据(类型) 状态 witness / 反例
跨模块同名关系 存在跨业务上下文的同名关系 — 纸面:模型只有 module market,无跨模块同名 无候选 —
模块内 “Paid” 三义 status(o,Paid)、invoice_status(inv,Paid)、paid(o) 不同义 全局 实体类型不同(Order / Invoice / 一元),不可比较(编译器) 纸面(不可比较,非重复) —

4. 证据分级与可复现方法

三类证据按“能不能由声明直接查”划分。可复现命令需要先把 docs/examples/market.md 里的 koine 块拼成一个 model.koi(现有测试 gold("market") 即此做法)。

4.1 编译器可查

只依赖签名、key、类型、gloss、derived 定义,不探索世界。对应候选:

  • key total 导致的单值/不相交(3.3 前两行)。
  • axiom 直接声明或一步传递的蕴含/不相交(3.2、3.3 的 axiom 行)。
  • 类型不可比较(3.10 的 “Paid” 三义)。
  • derived 声明合法性(3.6 第一列)。

可复现:mise run impl:check(含 world_check.rs 与 derived.rs 测试);或对单个模型跑 koine check model.koi。本文按规范语义纸面判断,未重新运行。

4.2 有界 explore 可查

需要遍历 s0 可达世界:等价、反向蕴含、重叠 witness、独立、部分不相交。对应候选 3.1、3.2 的 paid ⇒ status Paid、3.3 的 paid / status Draft、3.4、3.5、3.6–3.8 的扩展等价部分。

可复现命令:

koine explore model.koi --start s0 --depth 10 --max-worlds 1000
koine find model.koi --start s0 --where 'paid(o1) and refunded(o1)'
koine run model.koi refund_flow
koine run model.koi chargeback_flow
koine compare model.koi refund_flow chargeback_flow

现有测试证据:impl/rust/crates/koine/tests/explore.rs 的 gold_market_explore_stable_and_contains_refund_flow 已确认 s0 可达 12 世界 / 16 边且探索完整,compare_final_worlds_produces_diff 已确认 refund_flow 最终 status(o1, Refunded)、chargeback_flow 最终 status(o1, ChargedBack)。本文未亲自运行 explore,相关结论标 holds-in-scope / unknown。

4.3 需要历史 / as-of 才能查

涉及“曾经 vs 当前”、同一 time 多事件顺序、拒绝步、跨对象联动。对应候选 3.9 全部;跨对象联动(D8)当前模型没有 sub1 ↔ o1 之外的业务链接,仅能由 diff 手工拼,无法用查询直接回答。

可复现(路径回放,非 as-of):

koine history model.koi refund_flow
koine diff model.koi refund_flow --from 0 --to 3

as-of、interval、拒绝步入序列当前不可复现(Q-007 已 answered:不引入 interval 类型,as-of 用 define / derived relation 派生;ADR-0015 只定真值来源,模型级 as-of 查询命令属后续里程碑)。

5. 结论与剩余缺口

主要结论:

  1. paid / refunded / charged_back 与对应 *_at 事件时间关系在当前可达世界内等价,是派生候选;迁移前以 base relation 冗余存储,方向已由 ADR-0016 给出。ADR-0029 已于 2026-11-26 接受并实施,三者已改为 virtual derived。
  2. paid 与 status 不是重复:正向 status Paid ⇒ paid 有 axiom,反向被 refund_flow s3 反例推翻。status Refunded ≡ refunded、status ChargedBack ≡ charged_back 只是过渡性等价,新增离开终态的 transition 即破。
  3. refunded 与 charged_back 互斥、且都蕴含 paid,由 axiom 直接保证。
  4. 时间投影是最大缺口:同一 T0 内多事件无法用 time 排序,as-of 有歧义;历史标志与当前状态的分叉只能靠路径回放观察,as-of 不引入内建 interval/命令,用 define / derived relation 派生(Q-007 已 answered)。

剩余问题(不改模型,留待后续):

  • 派生候选是否需要把 paid/refunded/charged_back 改为 derived relation(涉及 view/diff 可见性,ADR-0016)。
  • settled_amount 与 applied_rate 的固化快照是否需要派生化或加一致性 axiom。
  • as-of / interval / 拒绝步历史表示(Q-007)。
  • “独立”类结论需要 explore/穷举才能从 unknown 升级,需先定 scope/bound 与 CI 证据政策。

相关

输入关键词开始搜索…

↑↓ 选择↵ 打开Esc 关闭