Algorithm Search⌘K

Algorithmadvanced

Possible models approach

Also called Winslett PMA.

Updates each model of the old beliefs to the models of the new formula that differ from it in a minimal set of atoms.

Time
Θ(k·n·2^n) worstΘ(2^n) best
Space
Θ(2^n) extra
Where
k = the number of models of the base; n = the number of atoms
Properties
deterministic
Origin
Marianne Winslett, 1988

The possible models approach (PMA) of Marianne Winslett is the classic operator for belief update, the change of beliefs when the world itself has changed. It treats each model of the old beliefs as a possible state of the world and moves each one separately to the models of the new formula that change as little as possible. "As little as possible" is measured by the set of atoms that change, compared by set inclusion. The result is the union of what each old model becomes. Winslett (1988) defined it to reason about the effects of actions, and Katsuno and Mendelzon (1991) showed that it satisfies their update postulates U1 to U8. On model sets it takes O(k⋅n⋅2n)O(k \cdot n \cdot 2^n) time for kk old models over nn atoms. On formulas, deciding whether the result entails a given formula is Π2P\Pi_2^P-complete (Eiter and Gottlob 1992, Theorem 6.4).

In plain words

You do not know exactly how the world is, so you keep a list of the states it could be in. Then an action happens, and afterwards some fact is true. For each state on your list, ask: what is the smallest change to this state that makes the fact true? Keep every answer that changes no more than it must, where "no more" means that no other answer changes only a part of the same things. Do this for each state on its own, and your new list is all the answers together.

Two answers that change different things, such as "the lamp moved" and "the chair and the table moved", are both kept. The method does not count the changes. It only throws out an answer when another answer changes a part of what it changes.

The problem

Fix nn atoms. A world is a vector w∈{0,1}nw \in \{0,1\}^n, which we also read as the set of its true atoms. For two worlds, Diff(w,v)=w⊕v\mathrm{Diff}(w, v) = w \oplus v is the set of the atoms on which they differ. The input is nn, the set K=Mod(ψ)K = \mathrm{Mod}(\psi) of the models of the old beliefs and the set P=Mod(μ)P = \mathrm{Mod}(\mu) of the models of the new formula. The output is

Mod(ψ⋄PMAμ)=⋃w∈KMin(w),Min(w)={v∈P:no u∈P has Diff(w,u)⊊Diff(w,v)}.\mathrm{Mod}(\psi \diamond_{\mathrm{PMA}} \mu) = \bigcup_{w \in K} \mathrm{Min}(w), \qquad \mathrm{Min}(w) = \{v \in P : \text{no } u \in P \text{ has } \mathrm{Diff}(w, u) \subsetneq \mathrm{Diff}(w, v)\}.

In Winslett's words, Min(w)\mathrm{Min}(w) is Incorporate(S,w)\mathrm{Incorporate}(S, w): the models of the postconditions SS such that no other such model differs from ww on fewer atoms, "where 'fewer' is defined by set inclusion" (Winslett 1988, p. 90). Winslett also keeps a set of protected formulas that must hold after every action. Here they are part of μ\mu.

If KK is empty the result is empty, and if PP is empty the result is empty.

The algorithm

Worlds and change sets are integers, with bit ii for atom ii. For one world ww, an array CC of 2n2^n bits records which change sets lead into PP. Lines L6 and L7 close it upwards, one atom at a time, so that afterwards C[x]C[x] is true when some model of PP differs from ww only on atoms inside xx. This is the zeta transform of sum over subsets with "or" in place of "+".

  1. PMA(K, P, n)
  2. 1R ← ∅
  3. 2for each w in K do
  4. 3if w ∈ P then
  5. 4add w to R; continue ▷ the empty change set is the least
  6. 5C[x] ← ((w xor x) ∈ P) for each x in 0 .. 2^n - 1
  7. 6for i ← 0 to n-1 do
  8. 7for each x that has bit i do C[x] ← C[x] or C[x xor 2^i]
  9. 8for each v in P do
  10. 9x ← w xor v; if C[x xor 2^i] is false for every bit i of x then
  11. 10add v to R ▷ no change set inside x leads to P
  12. 11return R

A proper subset of xx lies inside xx minus one of its atoms. So line L9 needs only ∣x∣≤n|x| \le n lookups to find out whether a smaller change set exists.

Example

The atoms are aa, bb and cc, and a world is written as the bit string abcabc. The old beliefs are ψ=¬a∧(b↔c)\psi = \neg a \wedge (b \leftrightarrow c), so K={000,011}K = \{000, 011\}. The new formula is μ=(a∧¬b∧¬c)∨(¬a∧b∧c)\mu = (a \wedge \neg b \wedge \neg c) \vee (\neg a \wedge b \wedge c), so P={100,011}P = \{100, 011\}.

model ww of KK change sets to PP minimal ones Min(w)\mathrm{Min}(w)
000 {a}\{a\} to 100, {b,c}\{b, c\} to 011 both {100,011}\{100, 011\}
011 ∅\emptyset to 011 ∅\emptyset {011}\{011\} (lines L3 and L4)

For w=000w = 000, line L5 marks C[{a}]C[\{a\}] and C[{b,c}]C[\{b, c\}]. After lines L6 and L7, C[x]C[x] is true for {a}\{a\}, {a,b}\{a, b\}, {a,c}\{a, c\}, {b,c}\{b, c\} and {a,b,c}\{a, b, c\}. For v=100v = 100, line L9 looks at C[∅]C[\emptyset], which is false, so vv is kept. For v=011v = 011, it looks at C[{c}]C[\{c\}] and C[{b}]C[\{b\}], which are both false, so vv is kept too. The result is {100,011}\{100, 011\}, which is μ\mu itself: the update has lost the fact ¬a\neg a.

Two other operators on the same input show what the choices do:

  • Forbus's update counts the changed atoms instead of comparing them by inclusion. From 000000 it keeps only 100100, one atom away, and drops 011011, two atoms away.
  • Dalal's revision compares the distance to the whole set KK. Since 011011 is in both KK and PP, the revision is K∩P={011}K \cap P = \{011\}, that is ¬a∧b∧c\neg a \wedge b \wedge c.

Update against revision. In the book and magazine example of Katsuno and Mendelzon (1991, KR), bb says that the book is on the table and mm that the magazine is. The agent knows that exactly one of them is there, ψ=(b∧¬m)∨(¬b∧m)\psi = (b \wedge \neg m) \vee (\neg b \wedge m), and then learns μ=b\mu = b. The PMA moves the world ¬b∧m\neg b \wedge m to b∧mb \wedge m and keeps the world b∧¬mb \wedge \neg m, so the update is bb, with nothing known about the magazine. Dalal's revision gives b∧¬mb \wedge \neg m, because μ\mu is consistent with ψ\psi. The update is right if a robot was told to put the book on the table, and the revision is right if the agent only learned more about a room that did not change.

Correctness

For w∈Pw \in P, the empty change set is a subset of every other change set, so Min(w)={w}\mathrm{Min}(w) = \{w\}, which lines L3 and L4 return. For w∉Pw \notin P, after round ii of lines L6 and L7 the entry C[x]C[x] is true exactly when some change set yy to PP has y⊆xy \subseteq x and agrees with xx on the atoms above ii. After the last round this is "some y⊆xy \subseteq x". A change set y⊊xy \subsetneq x misses some atom ii of xx, so y⊆x⊕2iy \subseteq x \oplus 2^i, and the test of line L9 finds it. The full proof is in the correctness proof.

Proof: The method returns, for each model of K, the models of p with an inclusion-minimal change setfull

We use the pseudocode of the page. The input is a number n≥0n \ge 0 of atoms, the set KK of the models of the belief base and the set PP of the models of the new formula pp. A world is a vector in {0,1}n\{0,1\}^n, and we identify it with the set of its true atoms, so that w⊕vw \oplus v is the set Diff(w,v)\mathrm{Diff}(w, v) of the atoms on which ww and vv differ. For a world ww, let

Dw={w⊕v:v∈P}D_w = \{w \oplus v : v \in P\}

be the change sets that lead from ww into PP, and let Min(w)={v∈P:no y∈Dw has y⊊w⊕v}\mathrm{Min}(w) = \{v \in P : \text{no } y \in D_w \text{ has } y \subsetneq w \oplus v\}. The possible models approach is

K⋄P=⋃w∈KMin(w)K \diamond P = \bigcup_{w \in K} \mathrm{Min}(w)

(Winslett 1988, Section 3, with the protected formulas left out).

Lemma 1 (a model of p). If w∈Pw \in P, then Min(w)={w}\mathrm{Min}(w) = \{w\}.

Proof. w⊕w=∅w \oplus w = \emptyset is in DwD_w, and ∅⊊y\emptyset \subsetneq y for every nonempty yy. So every v∈Pv \in P with v≠wv \ne w has ∅⊊w⊕v\emptyset \subsetneq w \oplus v in DwD_w and is not in Min(w)\mathrm{Min}(w). The set ∅\emptyset has no proper subset, so w∈Min(w)w \in \mathrm{Min}(w). □\square

Lemma 2 (the upward closure). Fix w∉Pw \notin P. After line L5, C[x]C[x] is true exactly when x∈Dwx \in D_w. After the round ii of lines L6 and L7, for i=0,…,n−1i = 0, \ldots, n-1,

(I) C[x]C[x] is true exactly when some y∈Dwy \in D_w has y⊆xy \subseteq x and yy agrees with xx on the atoms i+1,…,n−1i+1, \ldots, n-1.

Proof. Before round 0 the claim holds with "agrees on all atoms" in place of (I), since C[x]C[x] is true exactly for x∈Dwx \in D_w. Suppose it holds after round i−1i - 1, that is, C[x]C[x] is true exactly when some y∈Dwy \in D_w has y⊆xy \subseteq x and yy agrees with xx on the atoms i,…,n−1i, \ldots, n-1. In round ii, line L7 changes only the entries C[x]C[x] with atom ii in xx, and it reads C[x⊕2i]C[x \oplus 2^i], where x⊕2ix \oplus 2^i does not contain atom ii, so that entry is not changed in this round and the order of the updates does not matter. If atom ii is not in xx, then any y⊆xy \subseteq x misses atom ii too and so agrees with xx on atom ii, and the old value is already right. If atom ii is in xx, the sets y⊆xy \subseteq x that agree with xx on the atoms i+1,…,n−1i + 1, \ldots, n-1 are the ones that contain atom ii, which the old C[x]C[x] covers, and the ones that miss it, which the old C[x⊕2i]C[x \oplus 2^i] covers. So the new value C[x]∨C[x⊕2i]C[x] \vee C[x \oplus 2^i] is right. □\square

After the last round, (I) with i=n−1i = n - 1 says: C[x]C[x] is true exactly when some y∈Dwy \in D_w has y⊆xy \subseteq x.

Lemma 3 (the test). Fix w∉Pw \notin P and v∈Pv \in P, and let x=w⊕vx = w \oplus v. After the loop of lines L6 and L7, some y∈Dwy \in D_w has y⊊xy \subsetneq x if and only if C[x⊕2i]C[x \oplus 2^i] is true for some atom ii in xx.

Proof. If y∈Dwy \in D_w and y⊊xy \subsetneq x, take an atom ii in xx but not in yy. Then y⊆x⊕2iy \subseteq x \oplus 2^i, so C[x⊕2i]C[x \oplus 2^i] is true by Lemma 2. Conversely, if C[x⊕2i]C[x \oplus 2^i] is true for an atom ii in xx, Lemma 2 gives y∈Dwy \in D_w with y⊆x⊕2i⊊xy \subseteq x \oplus 2^i \subsetneq x. □\square

Theorem. PMA(K,P,n)(K, P, n) stops and returns K⋄PK \diamond P.

Proof. Every loop runs over a finite set, so the method stops. We show that for each w∈Kw \in K the worlds that lines L3 to L10 add to RR are exactly Min(w)\mathrm{Min}(w). If w∈Pw \in P, lines L3 and L4 add ww alone, which is Min(w)\mathrm{Min}(w) by Lemma 1. If w∉Pw \notin P, line L9 adds v∈Pv \in P exactly when no C[x⊕2i]C[x \oplus 2^i] with ii in xx is true, which by Lemma 3 means that no change set in DwD_w is a proper subset of w⊕vw \oplus v, that is v∈Min(w)v \in \mathrm{Min}(w). The array CC is set up again for each ww, so one model does not change the work for the next. RR starts empty at line L1 and only grows, so line L11 returns the union of the sets Min(w)\mathrm{Min}(w) for w∈Kw \in K. □\square

The empty cases. If KK is empty, the loop of line L2 does not run and the result is empty: an inconsistent base stays inconsistent. If PP is empty, no ww is in PP, no entry of CC is set, and line L8 has nothing to run over, so the result is empty.

Cost. For one w∉Pw \notin P, line L5 takes O(2n)O(2^n) time to clear and fill CC, lines L6 and L7 take O(n⋅2n)O(n \cdot 2^n), and lines L8 to L10 take O(n⋅∣P∣)⊆O(n⋅2n)O(n \cdot |P|) \subseteq O(n \cdot 2^n). For w∈Pw \in P the work is O(1)O(1) with PP stored as a bit array. With k=∣K∣k = |K|, the time is O(k⋅n⋅2n)O(k \cdot n \cdot 2^n) on the word RAM, and the extra space is the 2n2^n bits of CC and of RR.

Complexity

For each model ww of KK outside PP, line L5 costs O(2n)O(2^n), lines L6 and L7 cost Θ(n⋅2n)\Theta(n \cdot 2^n), and lines L8 to L10 cost O(n⋅∣P∣)O(n \cdot |P|). With k=∣K∣k = |K| and PP, RR and CC stored as bit arrays on the word RAM, the time is Θ(k⋅n⋅2n)\Theta(k \cdot n \cdot 2^n) in the worst case. The best case is K⊆PK \subseteq P, where only the arrays are set up, in Θ(2n)\Theta(2^n) time. The extra space is 2n2^n bits for CC, which is reused for each ww.

The direct method compares all pairs of models of PP for each ww, in O(k⋅∣P∣2)O(k \cdot |P|^2) subset tests. It is faster when PP is small. The transform wins when PP holds more than about n⋅2n\sqrt{n \cdot 2^n} worlds.

On formulas the model sets can have 2n2^n members, and the question is whether ψ⋄PMAμ\psi \diamond_{\mathrm{PMA}} \mu entails a formula qq. Eiter and Gottlob (1992) show that this is Π2P\Pi_2^P-complete (Theorem 6.4), the same as for Forbus's, Satoh's and Borgida's operators. A counterexample is a model ww of ψ\psi and a model vv of μ∧¬q\mu \wedge \neg q such that no model of μ\mu has a smaller change set from ww, which is one NP guess followed by one coNP check. When ψ\psi, μ\mu and qq are Horn, the problem drops to coNP-complete (Theorem 7.2). Both classes are in the polynomial hierarchy.

Properties

  • It satisfies U1 to U8. For each world ww, define v≤wuv \le_w u when Diff(w,v)⊆Diff(w,u)\mathrm{Diff}(w, v) \subseteq \mathrm{Diff}(w, u). This is a partial order in which ww is below every other world, so the assignment w↦≤ww \mapsto {\le_w} is faithful in the sense of Katsuno and Mendelzon, and Min(w)\mathrm{Min}(w) is the set of the ≤w\le_w-least models of μ\mu. By their representation theorem the operator satisfies the update postulates U1 to U8 (Katsuno and Mendelzon 1991, KR). The tests check all eight on random inputs.
  • It is not a revision. In the book and magazine example, ψ∧μ\psi \wedge \mu is consistent but the update is not ψ∧μ\psi \wedge \mu, so the revision postulate R2 fails. Dalal's revision fails U8 on the same input: updating the two models of ψ\psi one by one gives bb, but revising the whole of ψ\psi gives b∧¬mb \wedge \neg m.
  • It depends only on the models. Winslett notes that the PMA depends on the models of the theory and not on how its formulas are written, unlike the possible worlds approach of Ginsberg and Smith (Winslett 1988, p. 90).
  • It depends on the choice of atoms. In the book and magazine example, use the atoms x=bx = b and y=b⊕my = b \oplus m. Then ψ\psi is yy, and μ\mu is xx. The world ¬b∧m\neg b \wedge m is ¬x∧y\neg x \wedge y. Its change sets are {x}\{x\} to b∧¬mb \wedge \neg m and {x,y}\{x, y\} to b∧mb \wedge m, so only b∧¬mb \wedge \neg m is kept, and the update becomes b∧¬mb \wedge \neg m, the same as the revision.
  • An inconsistent base stays inconsistent. If ψ\psi has no model, the union is empty. This is what U2 asks, since an unsatisfiable ψ\psi entails every μ\mu.

Variants and improvements

  • Forbus's update. Measure the change from ww by the number of differing atoms, the Hamming distance, and keep the nearest models of μ\mu for each ww. The preorder ≤w\le_w is then total.
  • Borgida's operator. Return ψ∧μ\psi \wedge \mu when it is satisfiable and the PMA result otherwise. This is a revision operator built from the PMA (Eiter and Gottlob 1992, Section 3).
  • Satoh's revision. Compare the change sets by inclusion, as the PMA does, but minimize over all pairs of a model of ψ\psi and a model of μ\mu together, not for each model of ψ\psi on its own.
  • Protected formulas. Winslett's integrity constraints must hold in every result. Add them to μ\mu, or keep them apart so that they need not be stated again for each action.
  • With a solver. For formulas, the inner test "no model of μ\mu has a smaller change set from ww" is a SAT question, so a two-level search, with an NP oracle inside an NP search, decides entailment.

When to use it

Use the PMA when the new formula describes the result of a change in the world, such as an action, an event or a database update, and the old beliefs are a disjunction of possible states. Each possible state must then evolve on its own, and a state that was possible before must lead to some state after. If the new formula is only more information about an unchanged world, use a revision operator such as Dalal's. If the atoms are not equally important or changes should be counted, use Forbus's operator or a weighted variant. If actions have indirect effects, write them as protected formulas or use a richer action theory such as the situation calculus, since the PMA alone may let unrelated atoms change.

Pitfalls

  • Minimal for each model, not over the set. The minimum is taken for each model of ψ\psi on its own. Taking the closest models of μ\mu to the whole set KK gives Satoh's revision, which fails U8.
  • Inclusion, not count. A change of two atoms is kept when no other model of μ\mu changes a subset of those atoms. Counting the atoms gives Forbus's operator, which can give a different result.
  • Lost facts. The update keeps no fact of ψ\psi that μ\mu could change. In the example, ¬a\neg a is lost, because one old state moved to a world where aa is true.
  • Indirect effects. Without constraints, the PMA lets only the atoms in μ\mu change, and it may also make a disjunction where common sense expects one definite change. Winslett's frame problem example uses protected formulas so that moving one object updates the facts that depend on it.
  • Inconsistent base. The result is empty, not μ\mu. This differs from Dalal's revision, which returns μ\mu.

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.

possible_models_approach.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/possible-models-approach/. The authors are listed in prov/J9PKJ2.jsonl.

"""Winslett's possible models approach (PMA) to belief update.

A world over n atoms is an integer w with 0 <= w < 2**n: bit i of w is 1 when
atom i is true. A belief base is given by its set of models. The set of atoms
on which two worlds w and v differ is the integer w ^ v.

The update K <> p is the union, over the models w of K, of the models v of p
whose change set w ^ v is minimal under set inclusion among the change sets
from w to the models of p (Winslett 1988, Section 3).

For one model w, the method marks in an array C of 2**n bits every change set
x that leads from w into p, and then closes C upwards, one atom at a time, so
that C[x] says "some model of p differs from w only on atoms inside x". This
is the zeta transform over subsets. A model v of p is kept when no proper
subset of x = w ^ v is marked, and it is enough to test the n sets that miss
one atom of x.
"""


def _check_worlds(worlds, n, name):
    out = frozenset(worlds)
    limit = 1 << n
    for w in out:
        if not isinstance(w, int) or isinstance(w, bool) or w < 0 or w >= limit:
            raise ValueError(f"{name} holds {w!r}, which is not a world over {n} atoms")
    return out


def closest_models(w, p, n):
    """The models v of p for which w ^ v is minimal under set inclusion."""
    if w in p:
        return frozenset([w])  # the empty change set is below every other one
    size = 1 << n
    c = [False] * size
    for v in p:
        c[w ^ v] = True
    for i in range(n):
        bit = 1 << i
        for x in range(size):
            if x & bit and not c[x]:
                c[x] = c[x ^ bit]
    keep = []
    for v in p:
        x = w ^ v
        if not any(x >> i & 1 and c[x ^ (1 << i)] for i in range(n)):
            keep.append(v)
    return frozenset(keep)


def pma_update(k_models, p_models, n):
    """Mod(K <> p) under the possible models approach, as a frozenset."""
    if n < 0:
        raise ValueError("n must be at least 0")
    k = _check_worlds(k_models, n, "k_models")
    p = _check_worlds(p_models, n, "p_models")
    result = set()  # @line L1
    size = 1 << n
    for w in sorted(k):  # @line L2
        if w in p:  # @line L3
            result.add(w)  # @line L4
            continue
        c = [False] * size
        for v in p:
            c[w ^ v] = True  # @line L5
        for i in range(n):  # @line L6
            bit = 1 << i
            for x in range(size):
                if x & bit and not c[x]:
                    c[x] = c[x ^ bit]  # @line L7
        for v in p:  # @line L8
            x = w ^ v
            if not any(x >> i & 1 and c[x ^ (1 << i)] for i in range(n)):  # @line L9
                result.add(v)  # @line L10
    return frozenset(result)  # @line L11


def pma_update_per_model(k_models, p_models, n):
    """The same update, returned as a dict from each model of K to its set of closest models of p."""
    k = _check_worlds(k_models, n, "k_models")
    p = _check_worlds(p_models, n, "p_models")
    return {w: closest_models(w, p, n) for w in sorted(k)}
test_possible_models_approach.py 234 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/possible-models-approach/. The authors are listed in prov/J9PKJ2.jsonl.

import random

import pytest

from possible_models_approach import closest_models, pma_update, pma_update_per_model


def worlds(n):
    return range(1 << n)


def random_set(rng, n, prob):
    return frozenset(w for w in worlds(n) if rng.random() < prob)


def all_subsets(n):
    ws = list(worlds(n))
    for mask in range(1 << len(ws)):
        yield frozenset(w for j, w in enumerate(ws) if mask >> j & 1)


def subset_of(x, y):
    return x & y == x


def brute_force(k, p, n):
    """Union over the models w of k of the models of p whose change set from w is inclusion-minimal."""
    out = set()
    for w in k:
        for v in p:
            x = w ^ v
            if not any(subset_of(w ^ u, x) and w ^ u != x for u in p):
                out.add(v)
    return frozenset(out)


def dalal(k, p, n):
    """Dalal's revision by brute force: the models of p at least Hamming distance from the set k."""
    k, p = frozenset(k), frozenset(p)
    if not p:
        return frozenset()
    if not k:
        return p
    dist = {v: min(bin(v ^ w).count("1") for w in k) for v in p}
    best = min(dist.values())
    return frozenset(v for v in p if dist[v] == best)


def forbus(k, p, n):
    """Forbus's update by brute force: for each model of k, the models of p at least Hamming distance from it."""
    out = set()
    for w in k:
        dist = {v: bin(v ^ w).count("1") for v in p}
        if dist:
            best = min(dist.values())
            out |= {v for v in p if dist[v] == best}
    return frozenset(out)


# The KM update postulates U1 to U8, with formulas given by their sets of models.
def update_violations(op, k, k2, p, p2, q, n):
    bad = []
    r = op(k, p, n)
    if not r <= p:
        bad.append("U1")
    if k <= p and r != k:
        bad.append("U2")
    if k and p and not r:
        bad.append("U3")
    if op(sorted(k, reverse=True), sorted(p, reverse=True), n) != r:
        bad.append("U4")
    if not (r & q) <= op(k, p & q, n):
        bad.append("U5")
    r2 = op(k, p2, n)
    if r <= p2 and r2 <= p and r != r2:
        bad.append("U6")
    if len(k) == 1 and not (r & r2) <= op(k, p | p2, n):
        bad.append("U7")
    if op(k | k2, p, n) != r | op(k2, p, n):
        bad.append("U8")
    return bad


# The KM revision postulates R1 to R6, used to show that the PMA is not a revision.
def revision_violations(op, k, p, q, n):
    bad = []
    r = op(k, p, n)
    if not r <= p:
        bad.append("R1")
    if k & p and r != k & p:
        bad.append("R2")
    if p and not r:
        bad.append("R3")
    if op(sorted(k, reverse=True), sorted(p, reverse=True), n) != r:
        bad.append("R4")
    rpq = op(k, p & q, n)
    if not (r & q) <= rpq:
        bad.append("R5")
    if r & q and not rpq <= r & q:
        bad.append("R6")
    return bad


@pytest.mark.parametrize("n", [0, 1, 2, 3, 4, 5])
def test_matches_brute_force(n):
    rng = random.Random(100 + n)
    for _ in range(300):
        k = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
        p = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
        assert pma_update(k, p, n) == brute_force(k, p, n)


@pytest.mark.parametrize("n", [1, 2, 3, 4, 5])
def test_model_by_model(n):
    # For each single model w, the closest models are the inclusion-minimal change sets.
    rng = random.Random(200 + n)
    for _ in range(200):
        k = random_set(rng, n, 0.3)
        p = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
        per = pma_update_per_model(k, p, n)
        assert set(per) == set(k)
        for w in k:
            assert per[w] == brute_force({w}, p, n)
            assert closest_models(w, p, n) == per[w]
        union = frozenset().union(*per.values()) if per else frozenset()
        assert union == pma_update(k, p, n)


def test_exhaustive_two_atoms():
    for k in all_subsets(2):
        for p in all_subsets(2):
            assert pma_update(k, p, 2) == brute_force(k, p, 2)


@pytest.mark.parametrize("n", [1, 2, 3, 4, 5])
def test_update_postulates_u1_to_u8(n):
    rng = random.Random(300 + n)
    for _ in range(250):
        k = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
        if rng.random() < 0.3:
            k = frozenset([rng.randrange(1 << n)])  # complete bases for U7
        k2 = random_set(rng, n, rng.choice([0.1, 0.3]))
        p = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
        p2 = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
        if rng.random() < 0.2:
            p2 = p | random_set(rng, n, 0.2)
        q = random_set(rng, n, rng.choice([0.2, 0.5, 0.8]))
        assert update_violations(pma_update, k, k2, p, p2, q, n) == []


def test_update_postulates_exhaustive_two_atoms():
    subsets = list(all_subsets(2))
    rng = random.Random(400)
    for k in subsets:
        for p in subsets:
            for p2 in subsets:
                k2 = rng.choice(subsets)
                q = rng.choice(subsets)
                assert update_violations(pma_update, k, k2, p, p2, q, 2) == []


# Atoms: b (the book is on the table) is bit 0, m (the magazine is on the table) is bit 1.
B, M = 1, 2


def test_book_and_magazine_update_differs_from_revision():
    # K: exactly one of the book and the magazine is on the table. p: the book is on the table.
    k = frozenset({B, M})
    p = frozenset({B, B | M})
    assert pma_update(k, p, 2) == {B, B | M}  # update: b, and nothing is known about m
    assert dalal(k, p, 2) == {B}  # revision: b and not m
    assert pma_update_per_model(k, p, 2) == {B: {B}, M: {B | M}}
    # The update breaks R2: K and p are consistent, but the result is not K and p.
    assert "R2" in revision_violations(pma_update, k, p, frozenset(worlds(2)), 2)
    # The revision breaks U8: the models of K are not updated one by one.
    assert "U8" in update_violations(dalal, k, frozenset({M}), p, p, p, 2)
    assert dalal({B}, p, 2) | dalal({M}, p, 2) == {B, B | M}


# Atoms a, b, c are bits 0, 1, 2. The example of the page.
A, Bb, C = 1, 2, 4


def test_page_example():
    k = frozenset({0, Bb | C})  # not a, and b if and only if c
    p = frozenset({A, Bb | C})  # (a and not b and not c) or (not a and b and c)
    assert pma_update_per_model(k, p, 3) == {0: {A, Bb | C}, Bb | C: {Bb | C}}
    assert pma_update(k, p, 3) == {A, Bb | C}
    # Forbus counts the changed atoms and drops the world two atoms away from 000.
    assert forbus(k, p, 3) == {A, Bb | C}
    assert forbus({0}, p, 3) == {A}
    assert pma_update({0}, p, 3) == {A, Bb | C}
    # Dalal's revision keeps only the common model.
    assert dalal(k, p, 3) == {Bb | C}


def test_dalal_breaks_update_postulates_and_pma_breaks_r2():
    rng = random.Random(500)
    dalal_bad = pma_bad = 0
    for _ in range(2000):
        n = 3
        k = random_set(rng, n, 0.3)
        k2 = random_set(rng, n, 0.3)
        p = random_set(rng, n, 0.4)
        p2 = random_set(rng, n, 0.4)
        q = random_set(rng, n, 0.5)
        if update_violations(dalal, k, k2, p, p2, q, n):
            dalal_bad += 1
        bad = revision_violations(pma_update, k, p, q, n)
        assert "R1" not in bad and "R4" not in bad and "R5" not in bad
        # R3 fails only for an inconsistent base, which an update keeps inconsistent.
        assert "R3" not in bad or not k
        if "R2" in bad:
            pma_bad += 1
    assert dalal_bad > 0 and pma_bad > 0


def test_inconsistent_inputs():
    # An inconsistent base stays inconsistent, and an inconsistent formula gives no model.
    assert pma_update(set(), {1, 2}, 2) == set()
    assert pma_update({1}, set(), 2) == set()
    assert pma_update({0}, {0}, 0) == {0}


def test_bad_world_rejected():
    with pytest.raises(ValueError):
        pma_update({4}, {1}, 2)
    with pytest.raises(ValueError):
        pma_update({1}, {-1}, 2)
    with pytest.raises(ValueError):
        pma_update({1}, {1}, -1)

History

Winslett presented the PMA at AAAI-88 as a way to reason about actions. She contrasted it with the possible worlds approach of Ginsberg and Smith, which changes a set of formulas and so depends on how they are written. The PMA works on the models: each model is changed by as few atoms as set inclusion allows, and protected formulas state the laws of the domain. Katsuno and Mendelzon (1991) separated update from revision. They gave the postulates U1 to U8, proved a representation by faithful assignments of preorders, one for each world, and showed that the PMA is an update operator in their sense. Eiter and Gottlob (1992) found that its entailment problem is complete for the second level of the polynomial hierarchy, and coNP-complete for Horn formulas.

References

  1. Marianne Winslett, Reasoning about action using a possible models approach, Proceedings of the Seventh National Conference on Artificial Intelligence (AAAI-88), 89 to 93 (1988), p. 90, Section 3 (the definition of Incorporate(S, M) by set inclusion on the differing atoms, and the union over the models of the theory) and Section 4 (the frame problem example)
  2. Hirofumi Katsuno and Alberto O. Mendelzon, On the difference between updating a knowledge base and revising it, in James Allen, Richard Fikes and Erik Sandewall (eds), Proceedings of the Second International Conference on Principles of Knowledge Representation and Reasoning (KR'91), Morgan Kaufmann, 387 to 394 (1991), the whole paper (the postulates U1 to U8, their representation by faithful assignments of partial preorders, and the possible models approach as an update operator)
  3. Thomas Eiter and Georg Gottlob, On the complexity of propositional knowledge base revision, updates, and counterfactuals, Artificial Intelligence 57(2-3), 227 to 270 (1992), Section 3 (the model-based operators of Winslett, Forbus, Satoh and Borgida), Theorem 6.4 (the general case) and Theorem 7.2 (Horn formulas)

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example