Skip to content

Commit a0bdc04

Browse files
committed
回到 implies -- 不应该用 moreInformative
- 因为 implies 让人更容易想到 `merge` 所对应的是 lattice 中的 meet, 而 `moreInformative` 中的 "more" 让人误认为 `merge` 所对应的是 lattice 中的 join。
1 parent 631ba5f commit a0bdc04

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/belief-system/beliefSystemMerge.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Belief } from "../belief/index.js"
22
import { isNothing, nothing, type Nothing } from "../cell/index.js"
3-
import { merge, moreInformative, type MergeConflict } from "../merge/index.js"
3+
import { implies, merge, type MergeConflict } from "../merge/index.js"
44
import type { Reasons } from "../reason/index.js"
55
import { setIsSubsetOf } from "../utils/set/index.js"
66
import { BeliefSystem } from "./BeliefSystem.js"
@@ -75,9 +75,7 @@ function assimilateOne<A, B>(
7575
// - A belief has less reasons is stronger.
7676

7777
function stronger<A, B>(x: Belief<A>, y: Belief<B>): boolean {
78-
return (
79-
moreInformative(x.value, y.value) && setIsSubsetOf(x.reasons, y.reasons)
80-
)
78+
return implies(x.value, y.value) && setIsSubsetOf(x.reasons, y.reasons)
8179
}
8280

8381
function strongestConsequence<A>(

src/belief/beliefMerge.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { merge, moreInformative, type MergeConflict } from "../merge/index.js"
1+
import { implies, merge, type MergeConflict } from "../merge/index.js"
22
import { setIsSubsetOf, setUnion } from "../utils/set/index.js"
33
import { Belief } from "./Belief.js"
44

@@ -13,8 +13,8 @@ export function beliefMerge<A, B>(
1313
// 写的不是那么对称了。
1414

1515
if (mergedValue === content.value) {
16-
// 正向和反向的 moreInformative 代表等价。
17-
if (moreInformative(increment.value, mergedValue)) {
16+
// 正向和反向的 implies 代表等价。
17+
if (implies(increment.value, mergedValue)) {
1818
// 倾向于 content,除非 increment 真的有更多信息。
1919
// 更小的 reason 集合,代表拥有更多的信息(更精确的依赖关系)。
2020
if (setIsSubsetOf(content.reasons, increment.reasons)) {

src/merge/merge.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,37 @@ export const merge = defineGeneric({
5454
},
5555
})
5656

57-
// 第二个参数对于 merge 来说是多余的。
58-
// 这个实现就是用 lattice 的 meet (merge)
59-
// 来实现 ordered set 中的序关系(小于等于关系)。
60-
// 也就是说,信息越多就越具体,
61-
// 在 lattice 的中位置就更低,
62-
// 所以 merge 是 meet。
63-
export function moreInformative<A, B>(x: A, y: B): boolean {
57+
// merge 的效果是让 partial information 变得 more informative。
58+
//
59+
// - merge 是 lattice 的 meet。
60+
// - implies 是 ordered set 中的 "less or equal to"。
61+
// 虽然 "more informative" 一词中有一个 "more",
62+
// 但是其实就序集而言它是更小。
63+
//
64+
// 注意术语所在的领域:
65+
//
66+
// - merge 是就 partial information 而言的术语。
67+
// - implies 是就命题之间的蕴含而言的术语。
68+
//
69+
// 最好用例子来理解 "more informative":
70+
//
71+
// - 对集合来说,越小的集合越具体,包含的信息更多。
72+
// 比如考虑 CLP(FD) -- Constraint Logic Programming over Finite Domains,
73+
// 在求解 constraint 问题的过程中,domain 作为一个集合会变小。
74+
//
75+
// - 对于命题来说,蕴含式前项的命题比后项的命题包含更多信息。
76+
// 因此 more informative 就是 implies。
77+
// 集合之间的「包含于」关系,就对应于命题之间「蕴含关系」。
78+
//
79+
// - 对区间来说,越小的区间就更精确,就包含更多信息。
80+
// 毕竟,区间是特殊的集合。
81+
//
82+
// - 对于 Belief 来说,「包含更多信息」可以被理解为
83+
// (某个 cell 拥有)更强的信念。
84+
// 更强的信念,代表在更少的条件下相信更多的信息,
85+
/// 「更少的条件下」被实现为更小的 reasons 集合。
86+
87+
export function implies<A, B>(x: A, y: B): boolean {
6488
return merge(x, y) === x
6589
}
6690

0 commit comments

Comments
 (0)