Algorithmadvanced
System Z
Also called Pearl's System Z, Z-ranking.
Ranks defaults by tolerance into layers and ranks worlds by the highest layer they violate, computing rational closure.
- Time
- O(r^2 · P) worst
- Space
- O(s) extra
- Where
- P = the cost of one satisfiability test on a formula of size O(s), exponential in the worst case; r = the number of conditionals; s = the total size of the conditionals
- Model
- Word RAM
- Properties
- deterministic
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Judea Pearl, Moisés Goldszmidt, 1990
System Z reasons with a finite set of propositional conditionals , read "if then normally ". It splits into layers by tolerance: the first layer holds the rules that can be satisfied without breaking any rule, the next layer holds the rules that can be satisfied without breaking the rules that remain, and so on. A world then gets the rank the highest layer of a rule that it breaks, or if it breaks none. A query is accepted when the best worlds of satisfy . This ranking is the least ranking that respects every rule, and the relation that it defines is exactly the rational closure of Lehmann and Magidor. Every step is a satisfiability test, so the whole method is a polynomial number of SAT calls.
In plain words
You have rules of thumb such as "birds fly", "penguins are birds" and "penguins do not fly". Some rules can be followed in a situation that breaks no rule at all: a flying bird that is no penguin follows "birds fly" and breaks nothing. Those rules are the most general, and they go in the bottom layer. Other rules cannot be followed without breaking a general rule: any penguin breaks "birds fly". Those rules are more specific, and they go in a higher layer. A situation is as abnormal as the most specific rule that it breaks. To answer "do penguins fly?", look at the least abnormal penguins and see whether they fly. They do not, so the answer is no, and the specific rule wins over the general one.
The problem
Logic and semantics. The language is propositional logic over a finite set of atoms. A conditional is a pair of formulas. A ranking maps each world to a natural number or , with some world of rank , and gives a formula the rank , with . These are the ordinal conditional functions of Spohn. A ranking admits if : the best worlds satisfy . is consistent if some ranking admits all its rules.
Task. Given and a query , decide whether the query holds in System Z, that is, in the Z-ranking defined below. By the theorem of Goldszmidt and Pearl (1990), this is the same as deciding whether the query is in the rational closure of . The input is propositional. With the query holds exactly when , so the problem is co-NP-hard. The algorithm below makes polynomially many calls of a SAT oracle, so the problem is in , a class at the second level of the polynomial hierarchy. Eiter and Lukasiewicz (2000) studied the exact complexity of this problem and of related semantics, and the cases that are tractable. When the rules and the query are Horn, each test is a Horn-SAT test, and the whole decision takes polynomial time (Lehmann and Magidor 1992, Section 5.8).
The algorithm
A world verifies if it satisfies and falsifies it if it satisfies . For a set of rules, is the conjunction of the material implications over . A rule is tolerated by if some world verifies and falsifies nothing in , that is, if is satisfiable.
PARTITION(R) ▷ returns the layers R0, R1, ... and the rules that have no rank- 1
rest ← R; layers ← [] - 2
while rest is not empty do - 3
layer ← {α → β ∈ rest : α ∧ β ∧ M(rest) is satisfiable} ▷ the rules that rest tolerates - 4
if layer is empty then return (layers, rest) ▷ R is not consistent - 5
append layer to layers - 6
rest ← rest ∖ layer - 7
return (layers, ∅) KAPPA(φ) ▷ k layers; R≥i is the union of layers i to k - 1 and rest- 8
if φ ∧ M(R≥k) is unsatisfiable then return ∞ - 9
lo ← 0; hi ← k - 10
while lo < hi do - 11
mid ← ⌊(lo + hi) / 2⌋ - 12
if φ ∧ M(R≥mid) is satisfiable then hi ← mid else lo ← mid + 1 - 13
return lo ENTAILS(R, α, β)- 14
(layers, rest) ← PARTITION(R) - 15
a ← KAPPA(α ∧ β); b ← KAPPA(α ∧ ¬β) - 16
return a < b or b = ∞
The Z-rank of a rule in layer is . The Z-ranking of a world is if falsifies no rule, if it falsifies a rule without rank, and otherwise . KAPPA never lists the worlds. A world has rank at most exactly when it satisfies , so exactly when is satisfiable. This test is monotone in , so a binary search finds the rank. The implementation decides satisfiability with the Tseitin transformation and a small DPLL solver.
Example
Take the atoms (bird), (flies) and (penguin), and the rules , and .
- Round 0, rest . The world verifies and falsifies nothing, so is tolerated. A world that verifies or is a penguin. If it flies it falsifies , and if it is a bird that does not fly it falsifies . So .
- Round 1, rest . The world verifies both and falsifies neither. So , and the set is consistent.
| world | falsifies | |
|---|---|---|
| any world with and not | nothing | 0 |
| 1 | ||
| 1 | ||
| 2 | ||
| 2 | ||
| 2 |
Then , so penguins normally do not fly, and , so penguins are normally birds. Also : birds are normally not penguins.
Add (birds have wings). Now . The best penguins break , which has rank , whether or not they also break . So , and System Z does not conclude that penguins have wings. This is the drowning problem: one broken rule of a layer hides all the other rules of that layer.
For the Nixon diamond, and are tolerated at once and form one layer. The worlds with break one of the two rules, both with rank , so , and neither nor follows from .
Correctness
The correctness proof has the details. It shows four things. First, a world has rank at most exactly when it satisfies , which justifies lines L8 to L13. Second, admits every rule: a rule of layer is verified by a world of rank at most and falsified only by worlds of rank at least . Third, is the least admissible ranking: for any admissible , an induction on shows that every world verifying a rule of has at least , because such a rule is not tolerated by and so each such world breaks a rule of that set. The same induction shows that no ranking admits a set with rules left over at line L4. Fourth, a rule is tolerated by a set that contains it exactly when its antecedent is not exceptional in the sense of Lehmann and Magidor. So the layers are their sequence of exceptional subsets, and line L16 gives the same answer as their decision procedure for rational closure.
Proof: System Z gives the least admissible ranking and decides rational closurefull
Let be a finite set of conditionals over a finite set of atoms, where and are propositional formulas. A world is a truth assignment to the atoms. A world verifies the rule if it satisfies , and falsifies it if it satisfies . For a set of rules, is the conjunction of the material implications for the rules of , so a world satisfies exactly when it falsifies no rule of . A rule is tolerated by if some world verifies and falsifies no rule of , that is, if is satisfiable.
The partition and the ranking
Lines L1 to L7 compute and, for , the layer of the rules of that tolerates, with . The loop stops at the first where is empty or tolerates none of its rules. Write . Each round removes at least one rule, so . The Z-rank of a rule is . The set is consistent if . Note that for .
The rank of a world is
and the rank of a formula is , with . System Z accepts when or (line L16).
The rank of a formula with a satisfiability oracle
Lemma 1. For and every world : if and only if . Also, if and only if .
Proof. For : exactly when falsifies no rule, that is, . For : exactly when falsifies no rule of and every rule that it falsifies has . These are the conditions that falsifies no rule of , which is . For the last claim, exactly when falsifies no rule of , and then because every Z-rank is at most .
Corollary 2. if and only if is satisfiable, for , and if and only if is unsatisfiable.
So the predicate " is satisfiable" is false and then true as goes from to . Line L8 handles the case , and lines L9 to L13 find the least for which the predicate is true by binary search. That value is .
The ranking is admissible and least
A ranking is a function from worlds to , extended to formulas by the minimum as above. It admits the rule if . It is admissible for if it admits every rule of and gives some world rank .
Lemma 3. admits every rule that has a Z-rank. If is consistent, is admissible for .
Proof. Let . Since tolerates , some world verifies and falsifies no rule of . By Lemma 1, , so . Every world that falsifies has rank at least . So . If is consistent, every rule has a Z-rank. If is empty, every world has rank . Otherwise is not empty, so some world verifies a rule of and falsifies no rule of , and it has rank .
Lemma 4. Let be a ranking that admits every rule of . Then for each and each rule , .
Proof. By induction on . The case is clear. Assume the claim for , and let . Then , so does not tolerate : every world that verifies falsifies some rule . Then , using that admits and the induction hypothesis. So for every such , and .
Theorem 5 (least admissible ranking). If is consistent and is admissible for , then for every world . If is not consistent, no ranking admits every rule of .
Proof. Let be consistent. If falsifies no rule, . Otherwise let be a rule that falsifies with the largest Z-rank . By Lemma 4, . Since admits , .
Now let , and suppose that admits every rule. The set tolerates none of its rules. The argument of Lemma 4, applied inside , shows by induction on that for every and every : each world that verifies falsifies some and so has rank above . So , and cannot admit , because is false.
So, for a consistent set, is the least admissible ranking, and the set has an admissible ranking exactly when it is consistent.
System Z is rational closure
We use the decision procedure of Lehmann and Magidor (1992, Section 5.8). For a finite set of conditionals, a formula is exceptional for if preferentially entails , and by their Lemma 33 and Corollary 6 this holds exactly when . Let be the set of the rules of whose antecedent is exceptional for . Their procedure decides whether is in the rational closure of :
- .
- While is exceptional for and , set .
- Answer yes if is exceptional for , and no otherwise.
Lemma 6. For every finite , a rule is tolerated by if and only if is not exceptional for . So is the set of the rules of that does not tolerate, and the sequence , is for and for .
Proof. Since , contains , so is satisfiable exactly when is. The first is "not exceptional", the second is "tolerated". So . For this is . For no rule is tolerated, so .
Theorem 7. For all formulas and , System Z accepts if and only if the procedure of Lehmann and Magidor answers yes, that is, if and only if is in the rational closure of .
Proof. By Lemma 6, the procedure walks through . It stops at the first where is not exceptional for , or at the fixed point .
Case . By Corollary 2, is not exceptional for exactly when , so the procedure stops at . It answers yes exactly when is unsatisfiable, which by Corollary 2 means . Since , this holds exactly when . That is the test at line L16.
Case . Then is exceptional for every , and the procedure stops at the fixed point with . So and it answers yes. System Z also answers yes, because .
Goldszmidt and Pearl (1990) proved that System Z and rational closure agree. The argument above reaches the same result through the decision procedure of Lehmann and Magidor, and it also covers sets that are not consistent: there, every formula whose rank is entails every formula, as in rational closure.
Cost
The partition makes at most rounds, and round makes one satisfiability test for each rule of , so there are at most tests. Each rank needs one test at line L8 and at most tests in the binary search. One query after the partition needs two ranks, so tests, each on a formula of size , where is the largest size of a rule.
Complexity
Let and let be the total size of the rules. PARTITION runs at most rounds, because each round removes at least one rule, and round tests each remaining rule once. So it makes at most satisfiability tests, each on a formula of size . After the partition, one query needs two calls of KAPPA, each with tests. The total time is , where is the cost of one test. The space outside the solver is for the formula and the layers. In the worst case is exponential, because SAT is NP-complete, but the number of oracle calls is polynomial. For Horn rules each test runs in linear time, so the whole method is polynomial.
Properties
- Least admissible ranking. for every world and every ranking that admits all rules. The rules are believed as weakly as possible, which is Pearl's idea of default reasoning with minimal surprise.
- Rational closure. The relation is rational closure, so it satisfies the rules of System P and Rational Monotonicity.
- Consistency test for free. The set has an admissible ranking exactly when PARTITION uses up all the rules.
- Specificity. A rule whose antecedent is exceptional for the others gets a higher layer and wins over them, as in the penguin example.
- Irrelevance. Atoms that occur in no rule do not change ranks: with only , also .
- Deterministic and syntax independent. The layers depend only on the models of the formulas, not on how the rules are written or ordered.
Variants and improvements
- System Z+. Goldszmidt and Pearl gave each default a strength, and the ranking then uses the strengths in place of the layer numbers.
- Lexicographic closure. Lehmann (1995) compares worlds by the number of broken rules in each layer, from the highest layer down. This solves the drowning problem in the example above: the penguin that keeps its wings breaks fewer rules of layer .
- Maximum entropy. Goldszmidt, Morris and Pearl (1993) rank worlds by the limit of the maximum entropy distributions, which also counts broken rules.
- Inconsistent sets. The implementation keeps the rules left over at line L4 and gives every world that breaks one of them the rank . Then every formula of rank entails every formula, which is what rational closure does for such sets.
- Compiled ranks. The partition does not depend on the query. Compute it once, and answer each query with satisfiability tests.
When to use it
Use System Z when you have propositional rules of thumb with exceptions, you want answers that respect specificity, and you want a semantics with clear properties: it is rational closure, it satisfies System P and Rational Monotonicity, and it has a polynomial number of SAT calls. If you need rules in the same layer to keep working after one of them is broken, use the lexicographic closure or maximum entropy. If you need priorities among defaults that do not come from specificity, use System Z+ or a default logic with priorities.
Pitfalls
- The drowning problem. One broken rule of a layer blocks all rules of that layer for the exceptional worlds. Do not expect penguins to inherit wings from birds.
- Material implication is not the conditional. is not . The material counterpart is used only inside the tolerance test and the rank test.
- Tolerance uses the remaining rules. A rule of round must be tolerated by all rules that are still left, not by the whole set. Testing against the whole set at every round gives wrong layers.
- Strict test at line L16. would accept both and for the Nixon diamond.
- Unsatisfiable antecedents. If has rank , every follows. Without the case at line L16, the test fails for such .
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/system-z/. The authors are listed in prov/8532GG.jsonl.
"""Pearl's System Z for a finite set of propositional conditionals.
A formula is a nested tuple: ("var", name), ("not", f), ("and", f, ...),
("or", f, ...), ("true",) or ("false",). The helpers var, neg, conj, disj and
implies build them. A conditional "if alpha then normally beta" is a pair
(alpha, beta).
partition(rules) returns (layers, rest). layers[i] is the list of the indices
of the rules with Z-rank i. rest holds the indices of the rules that are never
tolerated; it is empty exactly when the set is consistent in Pearl's sense.
kappa(phi, rules) is the Z-rank of a formula, with INF for a formula that no
ranked world satisfies. entails(rules, alpha, beta) decides alpha |~ beta in
System Z, which is the same relation as rational closure.
The only oracle is a satisfiability test: the Tseitin transformation followed
by a small DPLL solver.
"""
from typing import Dict, List, Optional, Tuple
Formula = tuple
Rule = Tuple[Formula, Formula]
Split = Tuple[List[List[int]], List[int]]
INF = float("inf")
TRUE = ("true",)
FALSE = ("false",)
def var(name):
return ("var", name)
def neg(f):
return ("not", f)
def conj(*fs):
return ("and",) + fs if fs else TRUE
def disj(*fs):
return ("or",) + fs if fs else FALSE
def implies(f, g):
return disj(neg(f), g)
def evaluate(f, world):
"""The truth value of f in a world, given as a dict from atom names to booleans."""
op = f[0]
if op == "var":
return world[f[1]]
if op == "not":
return not evaluate(f[1], world)
if op == "and":
return all(evaluate(g, world) for g in f[1:])
if op == "or":
return any(evaluate(g, world) for g in f[1:])
return op == "true"
def atoms(f, out=None):
out = set() if out is None else out
if f[0] == "var":
out.add(f[1])
else:
for g in f[1:]:
atoms(g, out)
return out
# ---- the satisfiability oracle ----
def _tseitin(f):
"""Clauses over positive and negative ints that are satisfiable exactly when f is."""
ids, clauses = {}, []
def lit(g):
op = g[0]
if op == "var":
key = ("var", g[1])
if key not in ids:
ids[key] = len(ids) + 1
return ids[key]
if op == "not":
return -lit(g[1])
x = len(ids) + 1
ids[("gate", x)] = x
if op in ("true", "false"):
clauses.append([x] if op == "true" else [-x])
return x
kids = [lit(h) for h in g[1:]]
if op == "and":
for k in kids:
clauses.append([-x, k])
clauses.append([x] + [-k for k in kids])
else:
for k in kids:
clauses.append([x, -k])
clauses.append([-x] + kids)
return x
clauses.append([lit(f)])
return clauses
def _dpll(clauses, assignment):
while True:
unit = None
simplified = []
for c in clauses:
if any(assignment.get(abs(l)) == (l > 0) for l in c):
continue
rest = [l for l in c if abs(l) not in assignment]
if not rest:
return False
if len(rest) == 1 and unit is None:
unit = rest[0]
simplified.append(rest)
clauses = simplified
if not clauses:
return True
if unit is None:
break
assignment[abs(unit)] = unit > 0
pick = clauses[0][0]
for value in (pick > 0, pick < 0):
trial = dict(assignment)
trial[abs(pick)] = value
if _dpll(clauses, trial):
return True
return False
def satisfiable(f: Formula) -> bool:
"""Whether some world satisfies f. Exponential time in the worst case."""
return _dpll(_tseitin(f), {})
# ---- System Z ----
def material(rule):
"""The material counterpart alpha -> beta of a conditional."""
return implies(rule[0], rule[1])
def partition(rules: List[Rule]) -> Split:
"""Pearl's tolerance partition. Returns (layers, rest) as lists of rule indices.
Cost: at most r (r + 1) / 2 satisfiability tests for r rules.
"""
rest, layers = list(range(len(rules))), [] # @line L1
while rest: # @line L2
m = [material(rules[j]) for j in rest]
layer = [i for i in rest if satisfiable(conj(rules[i][0], rules[i][1], *m))] # @line L3
if not layer: # @line L4
return layers, rest
layers.append(layer) # @line L5
rest = [i for i in rest if i not in layer] # @line L6
return layers, [] # @line L7
def z_ranks(rules: List[Rule]) -> Dict[int, int]:
"""A dict from rule index to its Z-rank, for the rules that have one."""
layers, _ = partition(rules)
return {i: z for z, layer in enumerate(layers) for i in layer}
def _above(rules, layers, rest, i):
"""The material counterparts of the rules in rest and in the layers from i on."""
chosen = list(rest) + [j for layer in layers[i:] for j in layer]
return [material(rules[j]) for j in chosen]
def kappa(phi: Formula, rules: List[Rule], split: Optional[Split] = None) -> float:
"""The Z-rank of the formula phi: the least rank of a world that satisfies it.
Cost after the partition: one test plus a binary search over the layers.
"""
layers, rest = partition(rules) if split is None else split
if not satisfiable(conj(phi, *_above(rules, layers, rest, len(layers)))): # @line L8
return INF
lo, hi = 0, len(layers) # @line L9
while lo < hi: # @line L10
mid = (lo + hi) // 2 # @line L11
if satisfiable(conj(phi, *_above(rules, layers, rest, mid))): # @line L12
hi = mid
else:
lo = mid + 1
return lo # @line L13
def rank_world(world: Dict[str, bool], rules: List[Rule], split: Optional[Split] = None) -> float:
"""The Z-rank of one world: 0 if it falsifies no rule, else 1 + the largest Z-rank it falsifies."""
layers, rest = partition(rules) if split is None else split
falsified = [i for i, (a, b) in enumerate(rules) if evaluate(a, world) and not evaluate(b, world)]
if any(i in rest for i in falsified):
return INF
z = {i: k for k, layer in enumerate(layers) for i in layer}
return 1 + max(z[i] for i in falsified) if falsified else 0
def entails(rules: List[Rule], alpha: Formula, beta: Formula, split: Optional[Split] = None) -> bool:
"""alpha |~ beta in System Z, which is rational closure."""
split = partition(rules) if split is None else split # @line L14
a = kappa(conj(alpha, beta), rules, split) # @line L15
b = kappa(conj(alpha, neg(beta)), rules, split)
return a < b or b == INF # @line L16
test_system_z.py 220 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/system-z/. The authors are listed in prov/8532GG.jsonl.
import random
import unittest
from itertools import product
from system_z import (
FALSE,
INF,
TRUE,
conj,
disj,
entails,
evaluate,
kappa,
neg,
partition,
rank_world,
satisfiable,
var,
z_ranks,
)
a, b, c, d = var("a"), var("b"), var("c"), var("d")
def worlds(names):
return [dict(zip(names, v)) for v in product([False, True], repeat=len(names))]
def holds(rule, w):
return not evaluate(rule[0], w) or evaluate(rule[1], w)
def exceptional_bf(alpha, rules, ws):
"""Lehmann and Magidor: alpha is exceptional for C when no world satisfies alpha and every material counterpart in C."""
return not any(evaluate(alpha, w) and all(holds(r, w) for r in rules) for w in ws)
def partition_bf(rules, ws):
rest, layers = list(range(len(rules))), []
while rest:
layer = [
i for i in rest
if any(evaluate(rules[i][0], w) and evaluate(rules[i][1], w) and all(holds(rules[j], w) for j in rest) for w in ws)
]
if not layer:
return layers, rest
layers.append(layer)
rest = [i for i in rest if i not in layer]
return layers, []
def world_rank_bf(rules, split, w):
layers, rest = split
z = {i: k for k, layer in enumerate(layers) for i in layer}
bad = [i for i, r in enumerate(rules) if not holds(r, w)]
if any(i in rest for i in bad):
return INF
return 1 + max(z[i] for i in bad) if bad else 0
def kappa_bf(rules, split, phi, ws):
return min((world_rank_bf(rules, split, w) for w in ws if evaluate(phi, w)), default=INF)
def rational_closure_bf(rules, alpha, beta, ws):
"""The decision procedure of Lehmann and Magidor (1992, Section 5.8), with exceptionality decided by enumeration."""
cur = list(rules)
while exceptional_bf(alpha, cur, ws):
nxt = [r for r in cur if exceptional_bf(r[0], cur, ws)]
if nxt == cur:
break
cur = nxt
return exceptional_bf(conj(alpha, neg(beta)), cur, ws)
def random_formula(rng, names, depth):
if depth == 0 or rng.random() < 0.3:
x = var(rng.choice(names))
r = rng.random()
if r < 0.05:
return TRUE
if r < 0.08:
return FALSE
return neg(x) if rng.random() < 0.4 else x
op = rng.choice(["and", "or", "not"])
if op == "not":
return neg(random_formula(rng, names, depth - 1))
kids = [random_formula(rng, names, depth - 1) for _ in range(rng.randint(2, 3))]
return conj(*kids) if op == "and" else disj(*kids)
def random_rules(rng, names):
return [
(random_formula(rng, names, rng.randint(0, 2)), random_formula(rng, names, rng.randint(0, 2)))
for _ in range(rng.randint(1, 5))
]
class TestOracle(unittest.TestCase):
def test_satisfiable_matches_truth_tables(self):
rng = random.Random(2)
names = ["a", "b", "c", "d"]
ws = worlds(names)
for _ in range(800):
f = random_formula(rng, names, 3)
self.assertEqual(satisfiable(f), any(evaluate(f, w) for w in ws), f)
self.assertTrue(satisfiable(TRUE))
self.assertFalse(satisfiable(FALSE))
self.assertFalse(satisfiable(conj(a, neg(a))))
class TestAgainstBruteForce(unittest.TestCase):
def test_partition_ranks_and_rational_closure(self):
rng = random.Random(1990)
for _ in range(150):
names = ["a", "b", "c", "d"][: rng.randint(1, 4)]
ws = worlds(names)
rules = random_rules(rng, names)
split = partition(rules)
self.assertEqual(split, partition_bf(rules, ws), rules)
for w in ws:
self.assertEqual(rank_world(w, rules, split), world_rank_bf(rules, split, w))
for _ in range(6):
alpha = random_formula(rng, names, 2)
beta = random_formula(rng, names, 2)
self.assertEqual(kappa(alpha, rules, split), kappa_bf(rules, split, alpha, ws))
self.assertEqual(
entails(rules, alpha, beta, split),
rational_closure_bf(rules, alpha, beta, ws),
(rules, alpha, beta),
)
for rule in rules: # every rule is entailed by its own set
self.assertTrue(entails(rules, rule[0], rule[1], split))
def test_least_admissible_ranking(self):
# Over two atoms, try every ranking with values 0 to 3 that gives some world rank 0.
rng = random.Random(1992)
names = ["a", "b"]
ws = worlds(names)
all_rankings = [r for r in product(range(4), repeat=len(ws)) if 0 in r]
def rank_of(ranking, phi):
return min((ranking[k] for k, w in enumerate(ws) if evaluate(phi, w)), default=INF)
def admissible(ranking, rules):
return all(rank_of(ranking, conj(x, y)) < rank_of(ranking, conj(x, neg(y))) for x, y in rules)
checked = 0
while checked < 25:
rules = random_rules(rng, names)
split = partition(rules)
if split[1]:
self.assertFalse(any(admissible(r, rules) for r in all_rankings))
continue
checked += 1
kz = tuple(rank_world(w, rules, split) for w in ws)
self.assertTrue(admissible(kz, rules))
for r in all_rankings:
if admissible(r, rules):
self.assertTrue(all(x <= y for x, y in zip(kz, r)), (rules, r))
class TestExamples(unittest.TestCase):
def setUp(self):
self.bird, self.fly, self.penguin, self.wings = var("b"), var("f"), var("p"), var("w")
def test_penguin(self):
b_, f_, p_ = self.bird, self.fly, self.penguin
rules = [(b_, f_), (p_, b_), (p_, neg(f_))]
self.assertEqual(partition(rules), ([[0], [1, 2]], []))
self.assertEqual(z_ranks(rules), {0: 0, 1: 1, 2: 1})
self.assertTrue(entails(rules, b_, f_))
self.assertTrue(entails(rules, p_, neg(f_)))
self.assertTrue(entails(rules, p_, b_))
self.assertTrue(entails(rules, conj(b_, neg(p_)), f_))
self.assertFalse(entails(rules, p_, f_))
self.assertEqual(kappa(p_, rules), 1)
self.assertEqual(kappa(b_, rules), 0)
self.assertTrue(entails(rules, b_, neg(p_))) # birds are normally not penguins
def test_drowning(self):
b_, f_, p_, w_ = self.bird, self.fly, self.penguin, self.wings
rules = [(b_, f_), (p_, b_), (p_, neg(f_)), (b_, w_)]
self.assertEqual(partition(rules)[0], [[0, 3], [1, 2]])
self.assertTrue(entails(rules, b_, w_))
self.assertFalse(entails(rules, p_, w_))
self.assertFalse(entails(rules, p_, neg(w_)))
def test_nixon(self):
q, r, p = var("q"), var("r"), var("pacifist")
rules = [(q, p), (r, neg(p))]
self.assertEqual(partition(rules), ([[0, 1]], []))
self.assertFalse(entails(rules, conj(q, r), p))
self.assertFalse(entails(rules, conj(q, r), neg(p)))
self.assertTrue(entails(rules, q, p))
def test_irrelevance(self):
rules = [(a, b)]
self.assertTrue(entails(rules, conj(a, c), b))
def test_inconsistent_sets(self):
for rules in ([(a, b), (a, neg(b))], [(TRUE, a), (TRUE, neg(a))], [(a, FALSE)]):
layers, rest = partition(rules)
self.assertTrue(rest)
self.assertEqual(kappa(a, rules), INF)
self.assertTrue(entails(rules, a, c))
self.assertEqual(partition([(a, b), (a, neg(b)), (c, d)]), ([[2]], [0, 1]))
def test_empty_set(self):
self.assertEqual(partition([]), ([], []))
self.assertTrue(entails([], a, a))
self.assertFalse(entails([], a, b))
self.assertTrue(entails([], FALSE, b))
if __name__ == "__main__":
unittest.main()
History
Adams' probabilistic semantics for conditionals gave the notion of a consistent set of defaults. Pearl (1990) turned the consistency test into an ordering of the defaults, defined the ranking of worlds from it, and called the result System Z. In the same year Goldszmidt and Pearl showed that System Z agrees with the rational closure that Lehmann and Magidor had defined from a different starting point, the KLM rules and ranked models; the journal version of Lehmann and Magidor appeared in 1992. Later work on maximum entropy (1993), the lexicographic closure (1995) and System Z+ addressed the drowning problem and defaults of different strengths. Eiter and Lukasiewicz (2000) mapped the complexity of these semantics.
References
- Judea Pearl, System Z: a natural ordering of defaults with tractable applications to nonmonotonic reasoning, in Rohit Parikh (ed.), Proceedings of the Third Conference on Theoretical Aspects of Reasoning about Knowledge (TARK 1990), Morgan Kaufmann, 121 to 135 (1990), tolerance, the partition of the defaults, the ranking of worlds and the entailment relation
- Moisés Goldszmidt and Judea Pearl, On the relation between rational closure and System Z, Proceedings of the Third International Workshop on Nonmonotonic Reasoning, South Lake Tahoe, 130 to 140 (1990), the proof that System Z entailment and rational closure coincide
- Daniel Lehmann and Menachem Magidor, What does a conditional knowledge base entail?, Artificial Intelligence 55(1), 1 to 60 (1992), Section 2.6 (exceptional formulas), Lemma 33 and Corollary 6 (exceptionality by the material counterpart), Section 5.8 (the decision procedure for rational closure)
- Moisés Goldszmidt and Judea Pearl, Qualitative probabilities for default reasoning, belief revision, and causal modeling, Artificial Intelligence 84(1-2), 57 to 112 (1996), ranking functions for default reasoning, and System Z+ with strengths on the defaults
- Thomas Eiter and Thomas Lukasiewicz, Default reasoning from conditional knowledge bases, complexity and tractable cases, Artificial Intelligence 124(2), 169 to 241 (2000), the complexity of entailment in System Z and related semantics, and the tractable cases
- Daniel Lehmann, Another perspective on default reasoning, Annals of Mathematics and Artificial Intelligence 15(1), 61 to 82 (1995), the lexicographic closure
- Moisés Goldszmidt, Paul Morris and Judea Pearl, A maximum entropy approach to nonmonotonic reasoning, IEEE Transactions on Pattern Analysis and Machine Intelligence 15(3), 220 to 232 (1993), the maximum entropy ranking of defaults
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 8532GG Edit this page History Report an error Markdown