Algorithmadvanced
Assumption-based truth maintenance
Also called ATMS, de Kleer ATMS.
Labels each node with the minimal consistent sets of assumptions from which it follows, so a reasoner can work in all contexts at once; the labels can be exponential.
- Time
- 2^O(a k) s worst
- Space
- O(a n 2^a) extra
- Where
- a = the number of assumptions; k = the largest number of antecedents of a justification; n = the number of nodes; s = the number of justifications
- Model
- Word RAM
- Properties
- deterministicincrementalmonotone
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Johan de Kleer, 1986
An assumption-based truth maintenance system (ATMS) records, for each node, every minimal set of assumptions under which the node holds. A justification-based TMS keeps one set of beliefs and relabels it when an assumption changes. The ATMS keeps all contexts at once: the label of a node is the list of its minimal consistent environments, sets of assumptions from which the node follows by the Horn justifications. A nogood is a minimal set of assumptions that derives a contradiction, and no label holds a superset of one. The reasoner can then ask whether a node holds in any context by one subset test, and switch contexts for free. The price is that labels can be exponential in the number of assumptions.
In plain words
Suppose a reasoner works with guesses and wants to compare many combinations of guesses. In place of keeping one combination at a time, the ATMS writes next to each conclusion the smallest combinations of guesses that are enough to reach it. It also keeps a list of the combinations that lead to a contradiction, and drops every entry that contains one of them. To know whether a conclusion holds for some set of guesses, check whether one of its entries is part of that set. Nothing is ever retracted: a new rule only adds entries, and a new contradiction only removes the entries that contain it. The lists can be very long, because each choice between two guesses can double them.
The problem
There is a set of assumptions, a set of nodes that contains and a contradiction node , and a set of justifications, Horn clauses
over nodes. For an environment , the closure is the least set that contains and is closed under , which forward chaining computes. is inconsistent when ; the nogoods are the minimal inconsistent environments. The label of a node must be
- sound: each environment in it derives ;
- consistent: each environment in it is consistent;
- minimal: no environment in it is a superset of another;
- complete: each consistent environment that derives is a superset of one of them.
So is the set of minimal consistent environments with . In logical terms, when and . Reiter and de Kleer (1987) characterized the labels by the prime implicates of the justifications, the clauses of the form that follow from and are minimal. The task is incremental: keep all labels and the nogood list correct while assumptions and justifications are added.
The algorithm
A queue holds pairs (node, environments) that wait to enter a label. Adding an assumption queues . Adding a justification queues with the minimal consistent unions of one environment from each antecedent label, and runs PROPAGATE.
PROPAGATE(Q)- 1
while Q is not empty do - 2
(x, E) ← remove the first pair of Q; drop the environments of E that contain a nogood - 3
N ← the minimal environments of E that have no subset in L(x) - 4
if N is empty then continue with the next pair at L1 - 5
if x = ⊥ then NOGOOD(e) for each e in N; continue at L1 - 6
remove from L(x) every environment that has a subset in N; add N to L(x) - 7
for each justification y ← b_1, …, b_k that has x among its antecedents do - 8
append (y, COMBINE(the justification, x, N)) to Q COMBINE(y ← b_1, …, b_k, x, N)- 9
for each position i with b_i = x, choose an environment of N at i and one of L(b_l) at each other position l - 10
take the union of each choice, and keep the unions that contain no nogood - 11
return the minimal ones among them NOGOOD(e)- 12
if no nogood is a subset of e then add e to the nogoods and remove the nogoods that contain e - 13
remove from every label the environments that contain e
Only the new environments of a node travel on to its consumers (lines L7 to L9). Labels never lose an environment except to a smaller one or to a nogood, so the ATMS is monotone: there is no retraction and no relabelling.
Example
The assumptions are , and the justifications are added in this order.
| step | justification | effect |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | the unions are and ; the minimal one gives | |
| 5 | and enter, and leaves because is a subset: | |
| 6 | becomes a nogood; it leaves , so is empty; does not change |
Now holds in the context , because is a subset of it, and in no context that contains both and , because such a context is inconsistent.
Correctness
The correctness proof shows that every environment that enters a label derives its node (soundness), that lines L2, L3, L6, L12 and L13 keep labels minimal and free of nogoods, and a quiescence lemma: when the queue is empty, for every justification and every choice of label environments of its antecedents, the union contains a nogood or has a subset in the label of the consequent. The reason is that the antecedent environment that entered its label last sent this union, or a subset of it, down the queue. Completeness then follows by induction on a forward chaining derivation, and the same argument shows that the nogoods are exactly the minimal inconsistent environments. Labels with these four properties are unique, so the result does not depend on the order of the additions.
Proof: ATMS label propagation gives sound, consistent, minimal and complete labelsfull
Let be the set of assumptions and the set of justifications , Horn clauses over nodes, where the node stands for a contradiction. For an environment , let be the set of nodes that follow from and by forward chaining; an assumption is in when . is inconsistent when . Since is monotone, every superset of an inconsistent environment is inconsistent. A label is
- sound when for each ;
- consistent when each is consistent;
- minimal when no element of is a proper subset of another;
- complete when each consistent with has a subset in .
The four properties fix the label: it is the set of minimal consistent environments that derive . The goal is that, when the queue is empty, every label has the four properties and the nogood list is the set of minimal inconsistent environments.
We use the procedures of the page. Adding the assumption queues ; adding a justification queues its consequent with COMBINE over the full labels. Line L8 queues a consequent with the products that use the new environments of one antecedent.
Lemma 1 (soundness and consistency of the nogoods)
Every nogood is inconsistent, and every environment in a label derives its node.
Proof. By induction on the steps. An environment enters a queue as for an assumption , or as a union of label environments of the antecedents of a justification . In the first case . In the second case for all by the induction hypothesis and monotonicity, so is in the closure of the union. An environment that line L5 turns into a nogood derives in the same way. Lines L6 and L13 only remove environments or add queued ones.
Lemma 2 (consistency and minimality)
At every moment, each label is minimal and contains no superset of a nogood, and the nogood list holds no two environments one of which contains the other.
Proof. Line L2 drops the queued environments that contain a nogood, and line L13 removes from every label the environments that contain a new nogood. Line L3 keeps only the minimal new environments that no old one is a subset of, and line L6 removes the old ones that a new one is a subset of. Line L12 adds a nogood only when no old nogood is a subset of it (the procedure checks this first) and removes the old ones that contain it.
So, by Lemma 1, a nogood is inconsistent, and with Lemma 2, an environment in a label contains no nogood. After Lemma 4 below, this means it is consistent.
Lemma 3 (quiescence)
When the queue is empty, for every justification and every choice of , the union contains a nogood, or and has a subset in . For this says that is in , or is a nogood. Also, for each assumption , the set contains a nogood or has a subset in .
Proof. An environment that has once been in a label and is in it now has been in it all the time in between, since removed environments contain a nogood (line L13) or a smaller label environment (line L6), and line L3 never adds an environment with a subset in the label. Fix the choice and let be the one that entered its label last; if , or no was added after the justification, take the moment when the justification was added. At that moment line L8 (or the queueing at JUSTIFY) put on the queue a set of environments that contains or a subset of it, since COMBINE keeps the minimal unions of all products that use at its position and the current labels at the others, which already hold the other . When this item is popped, is either dropped at line L2, because it contains a nogood, or dropped at line L3, because it has a subset in , or added to , or turned into a nogood when . In each case, from then on contains a nogood or has a subset in , because nogoods are only replaced by subsets and label environments only by subsets or by removal through a nogood that they contain. Since , the same holds for . The argument for is the same, with the item queued when became an assumption.
Lemma 4 (completeness)
When the queue is empty, for every environment and every node , either contains a nogood, or and has a subset in .
Proof. By induction on the step at which forward chaining from derives . If is an assumption in , Lemma 3 for gives the claim. Otherwise is derived by a justification with each derived earlier. By the induction hypothesis, contains a nogood, and we are done, or each has some with . Then , and Lemma 3 gives a nogood inside , or a subset of in , both inside .
Theorem
When the queue is empty, every label is sound, consistent, minimal and complete, and the nogoods are exactly the minimal inconsistent environments.
Proof. Soundness is Lemma 1 and minimality is Lemma 2. A consistent contains no nogood, since nogoods are inconsistent (Lemma 1); so by Lemma 4 every consistent with has a subset in , which is completeness. An inconsistent has , so by Lemma 4 it contains a nogood. So a label environment, which contains no nogood (Lemma 2), is consistent. Finally, every inconsistent environment contains a nogood, every nogood is inconsistent, and no nogood contains another; so a nogood has no inconsistent proper subset, and every minimal inconsistent environment, which contains a nogood, equals it.
Labels can be exponential
Take assumptions and the justifications , for each , and . Then , and an environment derives exactly when it holds or for every . There are no nogoods, so the minimal such environments are the sets that pick one of for each , and none of them contains another. So for an input of size , and any procedure that writes the labels needs exponential time on this family.
Complexity
Labels can be exponential. With assumptions and justifications , and , the label of holds all choices of one assumption from each pair, and no choice contains another. So any procedure that writes out the labels takes exponential time on an input of size ; the proof page gives the details. In general each label has at most environments, a combination step over antecedents forms at most unions, and each node gets new environments at most times, which gives a bound of the form on the time and on the space. The cost is not only in the size of the output: deciding whether a node has any consistent environment is NP-complete when nogoods are present (Selman and Levesque 1990). To see the hardness, take assumptions and for each variable of a CNF formula, the justification , a justification for each positive literal of a clause and for each negative one, and ; then has a consistent environment exactly when the formula is satisfiable. In practice the labels stay small when the assumptions are few or the nogoods cut the products early, and ATMS implementations use bit vectors for environments and a table of all environments, so that a subset test is a few machine operations.
Properties
- Multiple contexts. All consistent sets of assumptions are represented at once; a query in a context is a subset test against the label.
- Monotone. Justifications and assumptions are only added. Inconsistency removes environments, but no node is ever relabelled because a premise was withdrawn.
- Unique result. The labels and nogoods depend only on the justifications, not on the order in which they were added.
- Horn only. The basic ATMS handles Horn justifications. Disjunctions of assumptions need the extensions of de Kleer's second paper.
- Exponential labels. The size of a label can be even with no nogoods.
Variants and improvements
- Focusing. Restrict the labels to environments inside a set of contexts of interest, to avoid the exponential growth outside them.
- Disjunctions and the CMS. De Kleer's extensions add choose-sets of assumptions; Reiter and de Kleer's clause management system accepts arbitrary clauses and answers with prime implicates.
- Diagnosis. In consistency-based diagnosis, the assumptions say that components work, the nogoods are the conflict sets, and the diagnoses are the minimal hitting sets of the nogoods, as in Reiter's HS-tree and de Kleer and Williams's GDE.
- Abduction. The label of an observation lists its minimal consistent explanations by assumptions, the Horn case of abductive reasoning.
- Lazy labels. Compute the label of a node only when it is asked for, with backward search from the node.
When to use it
Use an ATMS when a problem solver must compare many alternative sets of assumptions, as in model-based diagnosis, qualitative physics and design spaces, and when switching between contexts must be cheap. Use a JTMS when one context is active at a time, when the justifications need nonmonotonic out-lists, or when the number of assumptions is large and unfocused.
Pitfalls
- Label explosion. A few independent binary choices multiply the label size. Focus the labels or keep the number of assumptions per problem small.
- Forgetting minimality. If supersets are not removed from labels and from the nogood list, they grow fast and the subset tests slow down.
- Late nogoods. A nogood that arrives late must remove environments from every label, not only from the nodes near the contradiction.
- Treating the label as a probability. A label says under which assumptions a node holds, not how likely the node is.
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
# An assumption-based truth maintenance system for the page
# https://algorithm.tamnd.com/assumption-based-truth-maintenance/. The authors are listed in prov/.
"""An assumption-based truth maintenance system (ATMS), after de Kleer (1986).
Nodes are hashable values. Some nodes are assumptions. A justification is a
Horn clause x <- a_1, ..., a_k over nodes; with k = 0 the node x is a premise.
The node FALSE stands for a contradiction: a justification FALSE <- a_1, ...,
a_k says that the antecedents cannot hold together.
An environment is a frozenset of assumptions. It is inconsistent when FALSE
follows from it, and the minimal inconsistent environments are the nogoods.
The label of a node is the set of environments in which the node holds, kept
sound (each one derives the node), consistent (none contains a nogood),
minimal (none is a superset of another) and complete (every consistent
environment that derives the node contains one of them).
Labels only grow under new justifications, except that a new nogood removes
the environments that contain it. Propagation sends only the new environments
of a node to the justifications that use the node.
"""
from collections import deque
from itertools import product
FALSE = "FALSE"
def minimal(envs):
"""The environments of envs that have no proper subset in envs, without duplicates."""
envs = sorted(set(envs), key=len)
out = []
for e in envs:
if not any(o <= e for o in out):
out.append(e)
return out
class ATMS:
def __init__(self):
self.label = {FALSE: []}
self.assumptions = set()
self.justs = [] # (consequent, antecedents)
self.consumers = {FALSE: []} # node -> indices of the justifications that use it
self.nogoods = []
def add_node(self, x):
if x not in self.label:
self.label[x] = []
self.consumers[x] = []
def add_assumption(self, a):
self.add_node(a)
self.assumptions.add(a)
self._run(deque([(a, [frozenset([a])])]))
def consistent(self, env):
return not any(n <= env for n in self.nogoods)
def holds(self, x, env):
"""True when x holds in the environment env: some label environment is a subset of env."""
return self.consistent(env) and any(e <= env for e in self.label.get(x, []))
def justify(self, x, antecedents):
self.add_node(x)
for a in antecedents:
self.add_node(a)
k = len(self.justs)
self.justs.append((x, tuple(antecedents)))
for a in set(antecedents):
self.consumers[a].append(k)
self._run(deque([(x, self._combine(k, None, None))]))
def _combine(self, k, changed, delta):
"""The minimal consistent unions of one environment from the label of each antecedent of justification k.
When changed is a node, only the products that take an environment of delta for one occurrence of it."""
_, ants = self.justs[k]
lists = [self.label[a] for a in ants]
products = []
if changed is None:
products.append(lists)
else:
for i, a in enumerate(ants): # @line L9
if a == changed:
products.append(lists[:i] + [delta] + lists[i + 1 :])
envs = []
for ls in products:
for choice in product(*ls):
e = frozenset().union(*choice) # @line L10
if self.consistent(e):
envs.append(e)
return minimal(envs) # @line L11
def _run(self, queue):
while queue: # @line L1
x, envs = queue.popleft() # @line L2
envs = [e for e in envs if self.consistent(e)]
new = minimal(e for e in envs if not any(o <= e for o in self.label[x])) # @line L3
if not new: # @line L4
continue
if x == FALSE: # @line L5
for e in new:
self._nogood(e)
continue
self.label[x] = [o for o in self.label[x] if not any(e <= o for e in new)] + new # @line L6
for k in self.consumers[x]: # @line L7
queue.append((self.justs[k][0], self._combine(k, x, new))) # @line L8
def _nogood(self, env):
if not self.consistent(env):
return
self.nogoods = [n for n in self.nogoods if not env <= n] + [env] # @line L12
for x in self.label: # @line L13
self.label[x] = [e for e in self.label[x] if not env <= e]
test_assumption_based_truth_maintenance.py 110 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/assumption-based-truth-maintenance/. The authors are listed in prov/.
import random
import unittest
from itertools import combinations
from assumption_based_truth_maintenance import ATMS, FALSE
def closure(env, justs):
"""Every node that follows from the assumptions of env by the Horn justifications."""
known = set(env)
changed = True
while changed:
changed = False
for x, ants in justs:
if x not in known and all(a in known for a in ants):
known.add(x)
changed = True
return known
def brute_force(assumptions, nodes, justs):
"""Labels and nogoods from every environment: the minimal consistent environments that derive each node."""
envs = [frozenset(c) for k in range(len(assumptions) + 1) for c in combinations(sorted(assumptions), k)]
closed = {e: closure(e, justs) for e in envs}
bad = [e for e in envs if FALSE in closed[e]]
nogoods = {e for e in bad if not any(o < e for o in bad)}
labels = {}
for x in nodes:
good = [e for e in envs if FALSE not in closed[e] and x in closed[e]]
labels[x] = {e for e in good if not any(o < e for o in good)}
return labels, nogoods, envs, closed
class TestATMS(unittest.TestCase):
def check_properties(self, atms, assumptions, nodes, justs):
labels, nogoods, envs, closed = brute_force(assumptions, nodes, justs)
self.assertEqual(set(atms.nogoods), nogoods)
for x in nodes:
label = atms.label[x]
self.assertEqual(len(label), len(set(label)))
for e in label:
self.assertIn(x, closed[e]) # sound
self.assertNotIn(FALSE, closed[e]) # consistent
self.assertFalse(any(o < e for o in label)) # minimal
for e in envs: # complete
if FALSE not in closed[e] and x in closed[e]:
self.assertTrue(any(o <= e for o in label))
self.assertEqual(set(label), labels[x])
def test_page_example(self):
t = ATMS()
for a in "ABC":
t.add_assumption(a)
t.justify("x", ["A", "B"])
t.justify("y", ["B"])
t.justify("y", ["C"])
self.assertEqual(set(t.label["y"]), {frozenset("B"), frozenset("C")})
t.justify("z", ["x", "y"])
self.assertEqual(set(t.label["z"]), {frozenset("AB")})
t.justify("z", ["y"])
self.assertEqual(set(t.label["z"]), {frozenset("B"), frozenset("C")})
t.justify(FALSE, ["A", "B"])
self.assertEqual(t.nogoods, [frozenset("AB")])
self.assertEqual(t.label["x"], [])
self.assertEqual(set(t.label["z"]), {frozenset("B"), frozenset("C")})
self.assertTrue(t.holds("z", frozenset("BC")))
self.assertFalse(t.holds("z", frozenset("AB")))
def test_random_against_brute_force(self):
rng = random.Random(20261115)
with_nogoods = 0
for _ in range(150):
assumptions = ["A" + str(i) for i in range(rng.randint(1, 6))]
derived = ["n" + str(i) for i in range(rng.randint(1, 4))]
nodes = assumptions + derived
t = ATMS()
for a in assumptions:
t.add_assumption(a)
for x in derived:
t.add_node(x)
justs = []
for _ in range(rng.randint(1, 10)):
x = FALSE if rng.random() < 0.15 else rng.choice(derived + assumptions[:1])
ants = tuple(rng.sample(nodes, rng.randint(0 if x != FALSE else 1, min(3, len(nodes)))))
justs.append((x, ants))
t.justify(x, ants)
self.check_properties(t, assumptions, nodes, justs)
with_nogoods += bool(t.nogoods)
self.assertGreater(with_nogoods, 30) # the random cases do reach contradictions
def test_exponential_label(self):
for n in range(1, 8):
t = ATMS()
xs = []
for i in range(n):
t.add_assumption("A" + str(i))
t.add_assumption("B" + str(i))
t.justify("x" + str(i), ["A" + str(i)])
t.justify("x" + str(i), ["B" + str(i)])
xs.append("x" + str(i))
t.justify("g", xs)
self.assertEqual(len(t.label["g"]), 2**n)
self.assertTrue(all(len(e) == n for e in t.label["g"]))
if __name__ == "__main__":
unittest.main()
History
De Kleer (1986) introduced the ATMS in three papers in one issue of Artificial Intelligence: the basic system, its extensions, and its use in problem solving. It grew from his work with Brown on qualitative physics and with Williams on diagnosis, where the GDE of de Kleer and Williams (1987) used it to find conflict sets. Reiter and de Kleer (1987) gave the logical foundations through prime implicates. Forbus and de Kleer (1993) gave the standard implementation in their textbook.
References
- Johan de Kleer, An assumption-based TMS, Artificial Intelligence 28(2), 127 to 162 (1986), the definitions of assumptions, environments, nogoods and labels, the four label properties, and the label update algorithm
- Johan de Kleer, Extending the ATMS, Artificial Intelligence 28(2), 163 to 196 (1986), disjunctions of assumptions and other extensions of the basic ATMS
- Raymond Reiter and Johan de Kleer, Foundations of assumption-based truth maintenance systems: preliminary report, Proceedings of the Sixth National Conference on Artificial Intelligence (AAAI-87), 183 to 188 (1987), the characterization of ATMS labels and of the clause management system by prime implicates
- Kenneth D. Forbus and Johan de Kleer, Building Problem Solvers, MIT Press (1993), the chapters on the ATMS, its implementation and its use in problem solvers
- Bart Selman and Hector J. Levesque, Abductive and default reasoning: a computational core, Proceedings of the Eighth National Conference on Artificial Intelligence (AAAI-90), 343 to 348 (1990), the hardness of finding an assumption-based explanation over Horn clauses
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 D3V9DW Edit this page History Report an error Markdown