eyelang 1.7.12 → 1.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/guide.md CHANGED
@@ -414,6 +414,7 @@ Use `holds/2` when you want to match the member term directly, for example `name
414
414
  | [`list-collection.eye`](../examples/list-collection.eye) | Demonstrates list and collection built-ins. | [`output/list-collection.eye`](../examples/output/list-collection.eye) |
415
415
  | [`lldm.eye`](../examples/lldm.eye) | Calculates leg-length discrepancy measurements. | [`output/lldm.eye`](../examples/output/lldm.eye) |
416
416
  | [`manufacturing-quality-control.eye`](../examples/manufacturing-quality-control.eye) | Evaluates process capability and quality. | [`output/manufacturing-quality-control.eye`](../examples/output/manufacturing-quality-control.eye) |
417
+ | [`markov-logic-network.eye`](../examples/markov-logic-network.eye) | Scores finite possible worlds with weighted soft formulas in a Markov Logic Network style. | [`output/markov-logic-network.eye`](../examples/output/markov-logic-network.eye) |
417
418
  | [`map-four-color-search.eye`](../examples/map-four-color-search.eye) | Searches for a valid four-colouring of the EU neighbour graph. | [`output/map-four-color-search.eye`](../examples/output/map-four-color-search.eye) |
418
419
  | [`matrix-chain-order.eye`](../examples/matrix-chain-order.eye) | Finds an optimal matrix-chain multiplication order. | [`output/matrix-chain-order.eye`](../examples/output/matrix-chain-order.eye) |
419
420
  | [`matrix-noncommutativity.eye`](../examples/matrix-noncommutativity.eye) | Multiplies 2x2 matrices and shows non-commutativity. | [`output/matrix-noncommutativity.eye`](../examples/output/matrix-noncommutativity.eye) |
@@ -0,0 +1,87 @@
1
+ % Markov Logic Network style scoring over a tiny finite domain.
2
+ %
3
+ % Eyelang is deterministic, so this is not a probabilistic MLN engine. The
4
+ % example encodes the usual MLN MAP idea explicitly: enumerate possible worlds,
5
+ % mark which weighted soft formulas each world satisfies, sum the weights, and
6
+ % choose the highest-scoring world. Weights are stored as integer tenths of a
7
+ % log weight so the example stays reproducible without floating-point noise.
8
+
9
+ materialize(mlnWeight, 2).
10
+ materialize(mlnWorld, 2).
11
+ materialize(mlnSatisfied, 2).
12
+ materialize(mlnViolated, 2).
13
+ materialize(mlnContribution, 3).
14
+ materialize(mlnWorldScore, 2).
15
+ materialize(mlnMapWorld, 2).
16
+ materialize(mlnConclusion, 2).
17
+
18
+ % Evidence and candidate hidden assignments.
19
+ person(alice).
20
+ person(bob).
21
+ friend(alice, bob).
22
+ observed_smokes(alice).
23
+
24
+ candidate_world(w_bob_not_smokes_not_cancer, no, no).
25
+ candidate_world(w_bob_not_smokes_cancer, no, yes).
26
+ candidate_world(w_bob_smokes_not_cancer, yes, no).
27
+ candidate_world(w_bob_smokes_cancer, yes, yes).
28
+
29
+ % Soft formulas are weighted log features.
30
+ formula_weight_tenths(friend_smoking, 20).
31
+ formula_weight_tenths(smoking_causes_cancer, 13).
32
+ formula_weight_tenths(cancer_is_rare, 6).
33
+
34
+ % World interpretation for Bob. Alice's smoking status is observed evidence.
35
+ smokes_in_world(?world, alice) :-
36
+ candidate_world(?world, ?, ?),
37
+ observed_smokes(alice).
38
+ smokes_in_world(?world, bob) :- candidate_world(?world, yes, ?).
39
+ cancer_in_world(?world, bob) :- candidate_world(?world, ?, yes).
40
+
41
+ % Grounded soft formulas for this tiny domain:
42
+ % friend_smoking: friend(alice,bob) and smokes(alice) => smokes(bob)
43
+ % smoking_causes_cancer: smokes(bob) => cancer(bob)
44
+ % cancer_is_rare: not cancer(bob)
45
+ formula_satisfied(?world, friend_smoking) :-
46
+ friend(alice, bob),
47
+ smokes_in_world(?world, alice),
48
+ smokes_in_world(?world, bob).
49
+
50
+ formula_satisfied(?world, smoking_causes_cancer) :-
51
+ candidate_world(?world, no, ?).
52
+ formula_satisfied(?world, smoking_causes_cancer) :-
53
+ smokes_in_world(?world, bob),
54
+ cancer_in_world(?world, bob).
55
+
56
+ formula_satisfied(?world, cancer_is_rare) :-
57
+ candidate_world(?world, ?, no).
58
+
59
+ formula_violated(?world, ?formula) :-
60
+ candidate_world(?world, ?, ?),
61
+ formula_weight_tenths(?formula, ?),
62
+ not(formula_satisfied(?world, ?formula)).
63
+
64
+ contribution_tenths(?world, ?formula, ?weight) :-
65
+ formula_satisfied(?world, ?formula),
66
+ formula_weight_tenths(?formula, ?weight).
67
+
68
+ world_score_tenths(?world, ?score) :-
69
+ candidate_world(?world, ?, ?),
70
+ sumall(?weight, contribution_tenths(?world, ?formula, ?weight), ?score).
71
+
72
+ map_world(?world, ?score) :-
73
+ aggregate_max(?candidate_score, ?candidate_world,
74
+ world_score_tenths(?candidate_world, ?candidate_score),
75
+ ?score, ?world).
76
+
77
+ mlnWeight(?formula, log_weight_tenths(?weight)) :- formula_weight_tenths(?formula, ?weight).
78
+ mlnWorld(?world, world(smokes(bob, ?smokes), cancer(bob, ?cancer))) :-
79
+ candidate_world(?world, ?smokes, ?cancer).
80
+ mlnSatisfied(?world, ?formula) :- formula_satisfied(?world, ?formula).
81
+ mlnViolated(?world, ?formula) :- formula_violated(?world, ?formula).
82
+ mlnContribution(?world, ?formula, log_weight_tenths(?weight)) :-
83
+ contribution_tenths(?world, ?formula, ?weight).
84
+ mlnWorldScore(?world, log_weight_tenths(?score)) :- world_score_tenths(?world, ?score).
85
+ mlnMapWorld(?world, log_weight_tenths(?score)) :- map_world(?world, ?score).
86
+ mlnConclusion(case, "MAP world predicts that Bob smokes and has cancer") :-
87
+ map_world(w_bob_smokes_cancer, ?).
@@ -0,0 +1,32 @@
1
+ mlnWeight(friend_smoking, log_weight_tenths(20)).
2
+ mlnWeight(smoking_causes_cancer, log_weight_tenths(13)).
3
+ mlnWeight(cancer_is_rare, log_weight_tenths(6)).
4
+ mlnWorld(w_bob_not_smokes_not_cancer, world(smokes(bob, no), cancer(bob, no))).
5
+ mlnWorld(w_bob_not_smokes_cancer, world(smokes(bob, no), cancer(bob, yes))).
6
+ mlnWorld(w_bob_smokes_not_cancer, world(smokes(bob, yes), cancer(bob, no))).
7
+ mlnWorld(w_bob_smokes_cancer, world(smokes(bob, yes), cancer(bob, yes))).
8
+ mlnSatisfied(w_bob_smokes_not_cancer, friend_smoking).
9
+ mlnSatisfied(w_bob_smokes_cancer, friend_smoking).
10
+ mlnSatisfied(w_bob_not_smokes_not_cancer, smoking_causes_cancer).
11
+ mlnSatisfied(w_bob_not_smokes_cancer, smoking_causes_cancer).
12
+ mlnSatisfied(w_bob_smokes_cancer, smoking_causes_cancer).
13
+ mlnSatisfied(w_bob_not_smokes_not_cancer, cancer_is_rare).
14
+ mlnSatisfied(w_bob_smokes_not_cancer, cancer_is_rare).
15
+ mlnViolated(w_bob_not_smokes_not_cancer, friend_smoking).
16
+ mlnViolated(w_bob_not_smokes_cancer, friend_smoking).
17
+ mlnViolated(w_bob_not_smokes_cancer, cancer_is_rare).
18
+ mlnViolated(w_bob_smokes_not_cancer, smoking_causes_cancer).
19
+ mlnViolated(w_bob_smokes_cancer, cancer_is_rare).
20
+ mlnContribution(w_bob_smokes_not_cancer, friend_smoking, log_weight_tenths(20)).
21
+ mlnContribution(w_bob_smokes_cancer, friend_smoking, log_weight_tenths(20)).
22
+ mlnContribution(w_bob_not_smokes_not_cancer, smoking_causes_cancer, log_weight_tenths(13)).
23
+ mlnContribution(w_bob_not_smokes_cancer, smoking_causes_cancer, log_weight_tenths(13)).
24
+ mlnContribution(w_bob_smokes_cancer, smoking_causes_cancer, log_weight_tenths(13)).
25
+ mlnContribution(w_bob_not_smokes_not_cancer, cancer_is_rare, log_weight_tenths(6)).
26
+ mlnContribution(w_bob_smokes_not_cancer, cancer_is_rare, log_weight_tenths(6)).
27
+ mlnWorldScore(w_bob_not_smokes_not_cancer, log_weight_tenths(19)).
28
+ mlnWorldScore(w_bob_not_smokes_cancer, log_weight_tenths(13)).
29
+ mlnWorldScore(w_bob_smokes_not_cancer, log_weight_tenths(26)).
30
+ mlnWorldScore(w_bob_smokes_cancer, log_weight_tenths(33)).
31
+ mlnMapWorld(w_bob_smokes_cancer, log_weight_tenths(33)).
32
+ mlnConclusion(case, "MAP world predicts that Bob smokes and has cancer").
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyelang",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "description": "A small Prolog-like logic programming language for facts, rules, goals, answers, and proofs.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/playground.html CHANGED
@@ -538,6 +538,7 @@
538
538
  "list-collection",
539
539
  "lldm",
540
540
  "manufacturing-quality-control",
541
+ "markov-logic-network",
541
542
  "map-four-color-search",
542
543
  "matrix-chain-order",
543
544
  "matrix-noncommutativity",