




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





This problem set is on multiple fault diagnosis. It is based mainly on the framework presented in de Kleer, Mackworth, and Reiter (1990).
Before describing how we will solve this problem we first need to make a diversion into propositional logic. Proposi- tional logic is a logic. In general, a logic is defined by specifying its syntax and semantics. Later in the course we will define other logics. While the syntax and the semantics of different logics will vary greatly from one logic to another, the general framework used to define the syntax and semantics of different logics is usually quite similar. Much of this framework will seem like overkill for a logic as simple as propositional logic. Nonetheless, it is instructive to start out defining propositional logic using the full-blown machinery since understanding how the machinery works in the propositional case will make it easier to understand how it works in other cases.
The syntax of propositional logic is defined as follows: We are given a set {p, q, p 1 , p(a),.. .} of atomic formulas. Note that, in propositional logic, entities like p(a) and p(b) are taken as distinct unrelated atomic formulas. A formula is either an atomic formula or one of the compound formulas ¬Φ, Φ ∧ Ψ, Φ ∨ Ψ, Φ → Ψ, or Φ ↔ Ψ, where Φ and Ψ are formulas.
The semantics of propositional logic is defined as follows: An interpretation is a total function that maps atomic formulas to truth values. The value of a formula Φ under an interpretation I is given by the valuation function V(Φ, I) defined as follows:
An interpretation is said to be a model of a set Σ of formulas if the value of every formula in that set is true under that interpretation. A set of formulas is said to be valid (sometimes called universally valid) if every interpretation is a model of that set. A set of formulas is said to be satisfiable or consistent if it has a model, i.e. some interpretation is a model of that set. A set of formulas is said to be unsatisfiable or inconsistent if it has no model. Let us denote the set of all models of Σ as M (Σ). We extend all of the above definitions to treat a formula Φ as the singleton set {Φ}. A valid formula is said to be a tautology. An inconsistent formula is said to be an inconsistency. A set Σ of formulas is said to entail a formula Φ, denoted Σ |= Φ, if every model of Σ is also a model of Φ. In other words, Σ |= Φ if M (Σ) ⊆ M (Φ). Finally, two formulas Φ and Ψ are said to be equivalent if they have the same set of models. Note that Φ → Ψ is equivalent to ¬Φ ∨ Ψ for all Φ and Ψ. More generally, Φ 1 ∧ · · · ∧ Φn → Ψ is equivalent to ¬Φ 1 ∨ · · · ∨ ¬Φn ∨ Ψ for all Φ 1 ,... , Φn, and Ψ.
Now we define a restricted class of formulas, namely those in conjunctive normal form, or CNF for short. A literal is either an atomic formula or a negated atomic formula. A clause is a disjunction of literals. A CNF formula is a conjunction of clauses. Note that since disjunction and conjunction are commutative and associative, and since Φ ∨ Φ and Φ ∧ Φ are equivalent to Φ for all formulas Φ, clauses can be represented as sets of literals and CNF formulas can be represented as sets of clauses. Thus CNF formulas can be represented as sets of sets of literals. It is then natural to interpret the empty clause as an inconsistency (a universally false formula) and the empty CNF formula as a tautology (a universally true formula).
For every formula Φ, it is possible to construct a CNF formula that is equivalent to Φ. One way to do this is as follows: First construct a truth table for Φ. Take every row for which Φ evaluates to false and construct a clause as follows: If the row maps the atomic formula Ψ to true, then include the literal ¬Ψ in the clause. If the row maps Ψ to false, then include the literal Ψ in the clause. The set of all such clauses, one for every row in the truth table where Φ evaluates to false, constitutes a CNF formula equivalent to Φ. This method might not produce the simplest CNF formula that is equivalent to Φ. In fact, it might produce a formula whose size is exponential in the number of distinct atomic formulas in Φ. In class, we showed how to construct an equivalent CNF formula whose size is linear in the size of the original formula by introducing new atomic formulas. The merit of this simplified, though less efficient, approach is that it is easier to implement.
Let us represent atomic formulas as arbitrary Scheme S-expressions. Furthermore, let us represent a non-negated literal Φ as the list (#t Φ) and a negated literal Φ as the list (#f Φ). This representations allows the following simple Scheme procedure to negate literals:
(define (negate-literal literal) (list (not (first literal)) (second literal)))
Finally, let us represent clauses as lists of literals and CNF formulas as lists of clauses. Suppose one had an arbitrary n-ary Scheme predicate p over Boolean arguments. And suppose that one had a list of n atomic formulas to be taken as names for the n arguments of p. The following simple Scheme procedure implements the above method for constructing a CNF formula to represent p:
(define (clauses p atomic-formulas) (all-values (let ((clause (map (lambda (atomic-formula) (list (a-boolean) atomic-formula)) atomic-formulas))) (when (apply p (map first clause)) (fail)) (map negate-literal clause))))
We can define another restricted class of formulas, namely those in disjunctive normal form, or DNF for short. A minterm is a conjunction of literals. A DNF formula is a disjunction of minterms. Here again, we can represent minterms and DNF formulas as sets or lists, and again, the empty minterm can naturally be interpreted as a tautology while the empty DNF formula can be naturally interpreted as an inconsistency. Similarly, for every formula there exists an equivalent DNF formula. Furthermore, a procedure analogous to clauses can be written to find such a formula. Unfortunately, however, there is no DNF-analog to the CNF-conversion procedure that we discussed in class. It is not always possible to produce an equivalent DNF formula whose size is polynomial in the size of the original formula.
For any two formulas Φ and Ψ, if M (Φ) ⊆ M (Ψ) we say that Φ subsumes Ψ or that Ψ covers Φ. If Φ and Ψ are clauses and clauses are represented as sets of literals, then Φ subsumes Ψ if and only if Φ ⊆ Ψ. Likewise, if Φ and Ψ are minterms and minterms are represented as sets of literals, then Φ covers Ψ if and only if Φ ⊆ Ψ. It is easy to see that if a CNF formula contains two clauses Φ and Ψ such that Φ subsumes Ψ, one can remove Ψ without affecting the truth conditions of the CNF formula. It is also easy to see that if a DNF formula contains two clauses Φ and Ψ such that Φ covers Ψ, one can remove Ψ without affecting the truth conditions of the DNF formula. Furthermore, any clause that contains both the literal Φ and the literal ¬Φ is a tautology. One can remove tautological clauses from CNF formulas without affecting their truth conditions. Similarly, any minterm that contains both the literal Φ and the literal ¬Φ is an inconsistency. One can remove inconsistent minterms from DNF formulas without affecting their truth conditions. Thus, for efficiency, we will always remove subsumed or tautological clauses and covered or inconsistent minterms when computing CNF or DNF formulas.
If Φ is a clause and Σ |= Φ, then we say that Φ is an implicate of Σ. If Φ is an implicate of Σ and no other implicate of Σ subsumes Φ, then we say that Φ is a prime implicate of Σ. If Φ is a minterm and Σ |= Φ, then we say that Φ is an implicant of Σ. If Φ is an implicant of Σ and no other implicant of Σ covers Φ, then we say that Φ is a prime implicant of Σ. Given a method for computing the set of all implicates or implicants, one can compute the set of all prime implicates or prime implicants, respectively, simply by removing subsumed clauses or covered minterms. Furthermore, if one has the set of all prime implicates or implicants then one can compute the other set by ‘multiplying out,’ i.e. distributing ∧ over ∨ or vice versa (and, of course, removing subsumed, covered,
and internal nodes. Once could specify which atomic formulas belong to which class simply by listing the formulas in each class. A vector is a CNF formula where each clause contains a single literal. Alternatively, a vector is a DNF formula containing only a single minterm. An input literal is a true or negated input. An output literal is a true or negated output. An AB-literal is a true or negated AB-formula. An input vector is a vector that contains only input literals. An output vector is a vector that contains only output literals. A test vector is a vector that contains only input or output literals. A diagnosis is a vector that contains only AB-literals. An input vector is a (partial) specification of the inputs to a circuit. An output vector is a (partial) specification of the output of a circuit. A test vector is a (partial) specification of the inputs and output of a circuit. A diagnosis is a partial specification of which components are operational and which are faulty. Let Σ be a set of formulas describing a circuit. Let i be an input vector, let o be an output vector, let t be a test vector, and let d be a diagnosis. Then we can simulate the behavior of the circuit as follows: One can determine the output vector o of an operational or faulty circuit given an input vector i by finding an o such that Σ ∪ {i, d} |= o. Similarly, one can determine the input vector required to derive a given output vector o from an operational or faulty circuit by finding an i such that Σ ∪ {o, d} |= i. Finally, what concerns us here is that one can find a diagnosis for a circuit that is consistent with an observed input/output vector pair (i, o) by finding a d such that Σ ∪ {i, o} |= d. Alternatively, one can find a diagnosis for a circuit that is consistent with a test vector t by finding a d such that Σ ∪ {t} |= d.
All of these problems, namely finding an o, i, t, or d such that Σ ∪ {i, d} |= o, Σ ∪ {o, d} |= i, Σ ∪ {i, o} |= d, or Σ ∪ {t} |= d respectively, are special cases of the more general problem of finding a vector Φ that contains only atomic formulas of a given class and that is entailed by some Σ, where Σ contains both the circuit description and some vectors. We typically want to find all such Φ entailed by Σ that are not covered by some other Ψ that is also entailed by Σ. One can do this simply as follows:
In the case of diagnosis, special terminology is used. A minimal conflict is a prime implicate that contains only AB-literals. A kernel diagnosis is a prime implicant of the set of all minimal conflicts. So to diagnose a circuit one forms a large formula describing the circuit. One conjoins this with an input vector and an output vector. One then converts this formula to CNF and computes all of its prime implicates. One discards those prime implicates that mention non-AB-literals. The resulting set is the set of all minimal conflicts. This takes the form of a CNF formula. One then computes all of the prime implicants of this set of all minimal conflicts by multiplying out the CNF formula into a DNF formula. The result is a set of minterms, each of which is a kernel diagnosis.
This process is made easier if the circuit description, the input vector, and the output vector are already CNF formulas since the conjunction of CNF formulas is itself a CNF formula. Vectors can be represented easily as CNF formulas. We now will see how to easily construct a circuit representation as a CNF formula.
We can represent the circuit from figure 1 as the following formula:
Inverter(ab(g 0 ), in, g 0 ) ∧ Inverter(ab(g 1 ), g 0 , out)
This can be expressed in Scheme as:
(define (make-double-inverter fault-model test-vector) (append (make-inverter fault-model ’(ab g0) ’in ’g0) (make-inverter fault-model ’(ab g1) ’g0 ’out) test-vector))
Here, test-vector is a test vector, i.e. a CNF formula where each clause contains a single input or output literal. For example, for the above circuit, test-vector might be
(((#t in)) ((#f out)))
Figure 1: A double inverter.
Figure 2: A full adder.
to indicate that in was driven with true and out was observed to be false.
Similarly, we can represent the circuit from figure 2 as the following formula:
Xor(ab(g 0 ), a, b, g 0 )∧ And(ab(g 1 ), a, b, g 1 )∧ Xor(ab(g 2 ), g 0 , cin, s)∧ And(ab(g 3 ), g 0 , cin, g 3 )∧ Or(ab(g 4 ), g 3 , cin, cout)
This can be expressed in Scheme as:
(define (make-full-adder fault-model test-vector) (append (make-xor-gate fault-model ’(ab g0) ’a ’b ’g0) (make-and-gate fault-model ’(ab g1) ’a ’b ’g1) (make-xor-gate fault-model ’(ab g2) ’g0 ’c-in ’s) (make-and-gate fault-model ’(ab g3) ’g0 ’c-in ’g3) (make-or-gate fault-model ’(ab g4) ’g3 ’g1 ’c-out) test-vector))
In the above, Invert(ab, x, out), And(ab, x, y, out), Or(ab, x, y, out), Xor(ab, x, y, out), are formula schemas, or macros, that expand into more complex formulas. In the absence of a fault model, these schemas are expanded as follows:
Invert(ab, x, out) 4 = ¬ab → (out ↔ ¬x) And(ab, x, y, out) 4 = ¬ab → (out ↔ (x ∧ y))
Or(ab, x, y, out)
4 = ¬ab → (out ↔ (x ∨ y)) Xor(ab, x, y, out) 4 = ¬ab → (out ↔ ¬(x ↔ y))
The only missing piece is the procedure kernel-diagnoses which you must write. This procedure accepts a CNF formula as input. This formula collectively represents the system description and the test-vector. It should return a list of the kernel diagnoses.
To implement kernel-diagnoses, you must first write a procedure prime-implicates. This procedure should take a CNF formula as input and return as output a list of all of its prime implicates. You should use the method described earlier. Not only will you need the prime-implicates to implement kernel-diagnoses, you will need it also for the correct operation of clauses.
Summary of what we want you to do for this problem set.
This problem set consists solely of writing code. You are to write the following two procedures:
prime-implicates kernel-diagnoses
as per the specifications in this handout. You can also write whatever procedures necessary to support these two procedures. The course software contains all of the procedures defined in this handout pre-loaded so you do not need to type them in.
You can run the GUI for this problem set by typing (p8). You can select then a circuit by clicking on either Double Inv, to get the double inverter, or Full Adder, to get the full adder. (You can also click on SN7483 to get a four-bit carry-lookahead adder. But this circuit will be too difficult to diagnose. So try it only if you feel adventurous. Furthermore, to run SN7483, you will need to implement the procedures
(make-nand2-gate fault-model ab in1 in2 out) (make-nor2-gate fault-model ab in1 in2 out) (make-nor3-gate fault-model ab in1 in2 in3 out) (make-nor4-gate fault-model ab in1 in2 in3 in4 out) (make-nor5-gate fault-model ab in1 in2 in3 in4 in5 out) (make-buffer fault-model ab in out) (make-and3-gate fault-model ab in1 in2 in3 out) (make-and4-gate fault-model ab in1 in2 in3 in4 out) (make-and5-gate fault-model ab in1 in2 in3 in4 in5 out) (make-andi-gate fault-model ab in1 in2 out) (make-sn7483 fault-model test-vector)
in a fashion analogous to the procedures described here.) You can select a fault model by clicking on either None, to get no fault model, or Stuck0, to get the stuck-at-zero fault model. You can then create a test vector by clicking on 0 , 1 , or x to set your ‘logic probe’ to the specified value and then clicking on one of the pins of the circuit to drive that pin to that value. (Don’t click on Vector 1 through Vector 6. These are predefined test vectors for SN7483 and don’t do anything for the double inverter or full adder examples.)
Having selected a circuit, fault model, and test vector, you can diagnose the circuit by clicking on Diagnose. This will call either make-double-inverter, make-full-adder, or make-sn7483 to construct the circuit (which will call your prime-implicates procedure by way of the clauses procedure) and then call your kernel-diagnoses procedure (by way of the diagnose procedure). The diagnoses will be stored and displayed one by one. You can cycle forward and backward through the diagnoses by clicking on +D and −D. Faulty components will be displayed with a circle-slash symbol. Exonerated components will be displayed with a circle symbol.
You must write the procedures prime-implicates and kernel-diagnoses and test them on the double inverter and full adder circuits with both the no-fault model and the stuck-at-zero fault model. We are not going to give you specific test vectors to try. You must try a sufficient number of appropriate test vectors to convince yourself that your program will produce the correct diagnoses for all possible test vector pairs. We will check your program by running it on test vectors that we haven’t told you about. So be sure that you are confident that your program works.
Good luck and have fun!
de Kleer, J., Mackworth, A. K., & Reiter, R. (1990). Characterizing Diagnoses. In Proceedings of the Eighth National Conference on Artificial Intelligence, pp. 324–30, Boston, MA.
Robinson, J. A. (1965). A Machine-Oriented Logic Based on the Resolution Principle. Journal of the Association for Computing Machinery, 12 (1).