Definitioncore
Default extension
Also called default logic extension.
An extension of a default theory is a set of beliefs that is a fixed point of Reiter's operator, so it contains the facts and every default conclusion it does not block.
An extension is what a default theory lets you believe. A default says "if is believed and can be consistently assumed, believe ". The trouble is that "can be consistently assumed" refers to the final set of beliefs, which the defaults are still building. Reiter (1980) solved this with a fixed point: guess the final set , use only for the consistency tests, derive everything that the facts and the applicable defaults give, and accept when the result is again. A theory can have one extension, several, or none.
Definition
A default theory is a pair . Here is a set of formulas (the facts) and is a set of defaults with a prerequisite , justifications and a conclusion . This page uses the propositional case: finitely many atoms, and finite. is the set of the classical consequences of , and is the set of the conclusions of the defaults in .
For a set of formulas , let be the smallest set of formulas with these three properties.
- .
- .
- For each default in : if and for each , then .
A set is an extension of if (Reiter 1980, Section 2). The argument is used only in the consistency test . The rest of the construction is a least set, so every formula of an extension has a derivation from by classical steps and default steps whose justifications are consistent with the extension.
Iterative form. Reiter's Theorem 2.1 gives an equivalent test. Put and
Then is an extension exactly when . The candidate appears on the right side, so this is a test of a guess, not a way to build from nothing.
Generating defaults. If is an extension, then , where is the set of the defaults whose prerequisite is in and whose justifications are all consistent with . So a finite theory has at most extensions, and each is found by trying the subsets of :
EXTENSIONS(W, D)- 1
found ← ∅ - 2
for each subset S of D do - 3
E ← Th(W ∪ cons(S)) ▷ the candidate - 4
G ← ∅ - 5
repeat ▷ the least G that E allows - 6
G' ← {d ∈ D : pre(d) ∈ Th(W ∪ cons(G)) and ¬β ∉ E for each justification β of d} - 7
if G' = G then leave the loop - 8
G ← G' - 9
if Th(W ∪ cons(G)) = E then add E to found ▷ Γ(E) = E - 10
return found
Lines L4 to L8 compute as . The sets grow, so the loop stops after at most rounds. The implementation keeps each theory as its set of models over the atoms, so a membership test is a check that every model of satisfies . This takes time exponential in both and the number of atoms. That is expected: deciding whether an extension exists is -complete for finite propositional theories (Gottlob 1992), as the page on the complexity of default logic shows.
Normal defaults. A default is normal if it has the form . Reiter (1980, Section 3) proved three facts about theories whose defaults are all normal. Every such theory has an extension. Adding a normal default keeps each old extension inside some new one (semi-monotonicity). Two different extensions contradict each other (orthogonality).
Examples and non-examples
- Tweety. and . The only extension is . If also contains , the justification fails, and the only extension is .
- Nixon diamond, two extensions. (a Quaker and a Republican) and . Each default blocks the other. and are extensions. A credulous reasoner may believe either or . A skeptical reasoner believes only what is in both, and so neither.
- Non-example: the facts alone. For the Nixon diamond, is not an extension. Both and are consistent with , so contains both and is inconsistent, which is not .
- No extension. and . If , the justification fails and , which does not contain . If , the default applies and . In both cases . The default is not normal, so this does not contradict Reiter's existence theorem.
- Non-example: an ungrounded belief. and . The set is not an extension, because the prerequisite is not derivable from without already having , so . The only extension is . In autoepistemic logic the similar premise has the expansion that contains .
- Inconsistent facts. If is inconsistent, always contains all formulas, so the set of all formulas is the unique extension.
- Cumulativity fails. Makinson's example, reported by Kraus, Lehmann and Magidor (1990, Section 3.1), uses two normal defaults and . With the only extension is , so and are both skeptical consequences. Add the consequence to . Now is a second extension, because the second default applies before the first, so is no longer a skeptical consequence. Adding a conclusion that you already believed changed your beliefs, so skeptical default logic fails Cautious Monotonicity, one of the rules of System P.
Related definitions
- Default logic is the logic in which extensions are the semantics, with credulous and skeptical consequence defined from them.
- The complexity of default logic gives the exact complexity of existence, credulous and skeptical reasoning for finite propositional theories.
- A stable expansion in autoepistemic logic is the corresponding fixed point for a modal belief operator.
- A stable model of a normal logic program is an extension in disguise: the rule reads as the default , and the Gelfond-Lifschitz reduct plays the role of .
- is antimonotone: a larger blocks more defaults and gives a smaller . So the Knaster-Tarski theorem does not apply, which is why a fixed point may fail to exist. is monotone, and its least and greatest fixed points give the well-founded semantics of default logic, in the same way as the alternating fixpoint does for programs.
- Nonmonotonic reasoning places extensions among the other ways of drawing defeasible conclusions.
Code
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/default-extension/. The authors are listed in prov/DNSBMF.jsonl.
"""Brute-force search for the extensions of a finite propositional default theory.
A formula is a nested tuple: ("var", name), ("not", f), ("and", f, ...),
("or", f, ...), ("true",) or ("false",). A default alpha : beta_1, ..., beta_n / gamma
is a triple (alpha, [beta_1, ..., beta_n], gamma). A theory is (W, D).
A deductively closed theory over the given atoms is kept as its set of models:
a frozenset of the indices of the worlds that satisfy it. Th(S) contains phi
exactly when every model of S satisfies phi.
extensions(atom_names, W, D) tries each subset S of D, takes E = Th(W and the
conclusions of S) as a candidate, and keeps it when E is a fixed point of
Reiter's operator Gamma. Every extension is generated by a subset of D, so
none is missed. The cost is O(2^|D| |D|^2 2^n) formula evaluations for n atoms.
"""
from itertools import combinations, product
from typing import Dict, FrozenSet, List, Sequence, Tuple
Formula = tuple
Default = Tuple[Formula, Sequence[Formula], Formula]
Models = FrozenSet[int]
def evaluate(f: Formula, world: Dict[str, bool]) -> bool:
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 worlds(atom_names: Sequence[str]) -> List[Dict[str, bool]]:
return [dict(zip(atom_names, v)) for v in product([False, True], repeat=len(atom_names))]
def models(formulas: Sequence[Formula], ws: List[Dict[str, bool]]) -> Models:
"""The models of a set of formulas, that is, the theory Th(formulas)."""
return frozenset(i for i, w in enumerate(ws) if all(evaluate(f, w) for f in formulas))
def generating_defaults(theory: Tuple[Sequence[Formula], Sequence[Default]], e: Models, ws) -> FrozenSet[int]:
"""The least set G of defaults such that each prerequisite follows from W and cons(G) and each justification is consistent with e."""
w_part, d_part = theory
g: FrozenSet[int] = frozenset() # @line L4
while True: # @line L5
th = models(list(w_part) + [d_part[i][2] for i in g], ws)
g2 = frozenset(
i for i, (alpha, betas, _) in enumerate(d_part)
if th <= models([alpha], ws) and all(e & models([b], ws) for b in betas)
) # @line L6
if g2 == g: # @line L7
return g
g = g2 # @line L8
def gamma(theory, e: Models, ws) -> Models:
"""Reiter's operator: Gamma(e) = Th(W and the conclusions of the defaults that e allows)."""
w_part, d_part = theory
g = generating_defaults(theory, e, ws)
return models(list(w_part) + [d_part[i][2] for i in g], ws)
def extensions(atom_names: Sequence[str], w_part: Sequence[Formula], d_part: Sequence[Default]) -> List[Tuple[Models, FrozenSet[int]]]:
"""All extensions of (W, D), each as (models of E, generating defaults), in a fixed order."""
ws = worlds(atom_names)
theory = (list(w_part), list(d_part))
found: Dict[Models, FrozenSet[int]] = {} # @line L1
for k in range(len(d_part) + 1): # @line L2
for s in combinations(range(len(d_part)), k):
e = models(list(w_part) + [d_part[i][2] for i in s], ws) # @line L3
if e in found:
continue
g = generating_defaults(theory, e, ws)
if models(list(w_part) + [d_part[i][2] for i in g], ws) == e: # @line L9
found[e] = g
return sorted(found.items(), key=lambda item: sorted(item[1])) # @line L10
def in_extension(e: Models, phi: Formula, atom_names: Sequence[str]) -> bool:
"""Whether the extension with the models e contains phi."""
ws = worlds(atom_names)
return all(evaluate(phi, ws[i]) for i in e)
test_default_extension.py 169 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/default-extension/. The authors are listed in prov/DNSBMF.jsonl.
import random
import unittest
from itertools import combinations
from default_extension import evaluate, extensions, in_extension, worlds
TRUE = ("true",)
FALSE = ("false",)
def v(x):
return ("var", x)
def neg(f):
return ("not", f)
def disj(*fs):
return ("or",) + fs
def conj(*fs):
return ("and",) + fs
def normal(alpha, gamma):
return (alpha, [gamma], gamma)
def reiter_fixed_points(names, w_part, d_part):
"""Every theory E over the atoms (a set of worlds) with E = union of Reiter's E_i (Theorem 2.1), by trying all of them."""
ws = worlds(names)
idx = range(len(ws))
def mods(fs):
return frozenset(i for i in idx if all(evaluate(f, ws[i]) for f in fs))
out = set()
for k in range(len(ws) + 1):
for e in combinations(idx, k):
e = frozenset(e)
cur = mods(w_part) # E_0 = Th(W)
while True:
add = [g for (a, bs, g) in d_part
if all(evaluate(a, ws[i]) for i in cur)
and all(any(evaluate(b, ws[i]) for i in e) for b in bs)]
nxt = cur & mods(add)
if nxt == cur:
break
cur = nxt
if cur == e:
out.add(e)
return out
def random_formula(rng, names, depth):
if depth == 0 or rng.random() < 0.35:
x = v(rng.choice(names))
return neg(x) if rng.random() < 0.4 else x
if rng.random() < 0.25:
return neg(random_formula(rng, names, depth - 1))
kids = [random_formula(rng, names, depth - 1) for _ in range(2)]
return conj(*kids) if rng.random() < 0.5 else disj(*kids)
def random_theory(rng, names, normal_only=False):
w_part = [random_formula(rng, names, 1) for _ in range(rng.randint(0, 2))]
d_part = []
for _ in range(rng.randint(0, 4)):
alpha = TRUE if rng.random() < 0.4 else random_formula(rng, names, 1)
gamma = random_formula(rng, names, 1)
if normal_only:
d_part.append(normal(alpha, gamma))
else:
betas = [random_formula(rng, names, 1) for _ in range(rng.randint(0, 2))]
d_part.append((alpha, betas, gamma))
return w_part, d_part
class TestExamples(unittest.TestCase):
def test_nixon_diamond(self):
names = ["q", "r", "p"]
q, r, p = v("q"), v("r"), v("p")
exts = extensions(names, [q, r], [normal(q, p), normal(r, neg(p))])
self.assertEqual(len(exts), 2)
(e1, g1), (e2, g2) = exts
self.assertEqual((g1, g2), (frozenset({0}), frozenset({1})))
self.assertTrue(in_extension(e1, p, names))
self.assertTrue(in_extension(e2, neg(p), names))
for e, _ in exts:
self.assertTrue(in_extension(e, conj(q, r), names))
def test_no_extension(self):
a = v("a")
self.assertEqual(extensions(["a"], [], [(TRUE, [neg(a)], a)]), [])
# The same default next to a normal one still blocks every candidate.
b = v("b")
self.assertEqual(extensions(["a", "b"], [], [(TRUE, [neg(a)], a), normal(TRUE, b)]), [])
def test_tweety(self):
names = ["b", "f"]
b, f = v("b"), v("f")
exts = extensions(names, [b], [normal(b, f)])
self.assertEqual(len(exts), 1)
self.assertTrue(in_extension(exts[0][0], f, names))
exts = extensions(names, [b, neg(f)], [normal(b, f)])
self.assertEqual(exts[0][1], frozenset())
self.assertFalse(in_extension(exts[0][0], f, names))
def test_makinson_cumulativity(self):
names = ["a", "b"]
a, b = v("a"), v("b")
d_part = [normal(TRUE, a), normal(disj(a, b), neg(a))]
exts = extensions(names, [], d_part)
self.assertEqual(len(exts), 1)
self.assertTrue(in_extension(exts[0][0], a, names))
self.assertTrue(in_extension(exts[0][0], disj(a, b), names))
exts = extensions(names, [disj(a, b)], d_part)
self.assertEqual(len(exts), 2)
self.assertEqual([in_extension(e, a, names) for e, _ in exts], [True, False])
self.assertTrue(in_extension(exts[1][0], conj(neg(a), b), names))
def test_inconsistent_facts(self):
a = v("a")
exts = extensions(["a"], [a, neg(a)], [normal(TRUE, a)])
self.assertEqual(exts, [(frozenset(), frozenset())])
def test_no_defaults(self):
a = v("a")
exts = extensions(["a"], [a], [])
self.assertEqual(len(exts), 1)
self.assertTrue(in_extension(exts[0][0], a, ["a"]))
class TestAgainstFixedPoints(unittest.TestCase):
def test_random_theories(self):
rng = random.Random(1980)
for t in range(500):
names = ["a", "b"] if t % 10 else ["a", "b", "c"]
w_part, d_part = random_theory(rng, names)
got = {e for e, _ in extensions(names, w_part, d_part)}
self.assertEqual(got, reiter_fixed_points(names, w_part, d_part), (w_part, d_part))
class TestNormalTheories(unittest.TestCase):
def test_existence_orthogonality_and_semi_monotonicity(self):
rng = random.Random(1987)
names = ["a", "b", "c"]
ws = worlds(names)
for _ in range(300):
w_part, d_part = random_theory(rng, names, normal_only=True)
if not any(all(evaluate(f, w) for f in w_part) for w in ws):
continue
exts = [e for e, _ in extensions(names, w_part, d_part)]
self.assertGreaterEqual(len(exts), 1)
for e1, e2 in combinations(exts, 2):
self.assertFalse(e1 & e2) # distinct extensions contradict each other
extra = normal(TRUE if rng.random() < 0.5 else random_formula(rng, names, 1), random_formula(rng, names, 1))
bigger = [e for e, _ in extensions(names, w_part, d_part + [extra])]
for e in exts:
self.assertTrue(any(f <= e for f in bigger)) # some new extension contains e
if __name__ == "__main__":
unittest.main()
References
- Raymond Reiter, A logic for default reasoning, Artificial Intelligence 13(1-2), 81 to 132 (1980), Section 2 (the operator Gamma, the definition of an extension and Theorem 2.1) and Section 3 (normal default theories always have extensions, semi-monotonicity, orthogonality)
- Sarit Kraus, Daniel Lehmann and Menachem Magidor, Nonmonotonic reasoning, preferential models and cumulative logics, Artificial Intelligence 44(1-2), 167 to 207 (1990), Section 3.1 (Makinson's observation that default logic, even with normal defaults, fails Cautious Monotonicity)
- Georg Gottlob, Complexity results for nonmonotonic logics, Journal of Logic and Computation 2(3), 397 to 425 (1992), the Sigma2P-completeness of deciding whether a finite propositional default theory has an extension
Where this leads
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag DNSBMF Edit this page History Report an error Markdown