CSC 173 Thurs. Dec 5, 2002 ======================================= Sequential Circuits for Memory Elements A memory element is a collection of gates capable of producing its last input as output. Memory elements are sequential circuits; that is, circuits whose behavior depends not only on the current inputs, but also on the past history. A flip-flop is a 1-bit memory element. A typical flip-flop circuit takes two inputs and produces a single output. * Input data-in is the binary data value to be stored in the memory element. * Input load determines whether the circuit is being asked to load a new binary value. Whenever load=0, the circuit produces as output the stored value (which is the last value loaded into the memory element). Whenever load=1, the circuit stores the value of data-in and produces it as output. ------------------------------------------------------------------------ Flip-Flop Circuit Here is a sequential circuit for a binary flip-flop: *----------------------* | | *-->|AND| | load----->|NOT|---->| 1 |------>|OR|---*--- data-out | *-->| 1| | | | | *------------>|AND|---* data-in ----------->| 2 | When load is 0: * the gate labeled AND2 produces a zero, and therefore doesn't affect data-out. * the gate labeled AND1 produces the previous value of the flip-flop as its output, which becomes data-out. * so, the circuit simply outputs the previous stored value. When load is 1: * the gate labeled AND1 produces a zero, and therefore doesn't affect data-out. * the gate labeled AND2 produces the value of data-in, which becomes data-out. * so, the circuit simply outputs data-in. ------------------------------------------------------------------------ Another useful combinatorial circuit: Multiplexor (MUX) A MUX takes a bunch of inputs and a selector (itself encoded as several binary bits) and chooses the input indicated by the selector. We used a simple MUX in the divide-and-conquer adder to choose between the s and t sums (with or without incoming carry). 1-MUX (1 control bit; 2^1 = 2 inputs): output = x y1 + ~x y2 y1 y2 | | x --+-----------(---+ | | | | | +---NOT-+ | | | | | | | ----- ----- AND AND | | \ / --- OR | 2-MUX (2 control bits; 2^2 = 4 inputs): picture p. 725 AU one wide AND gate for every input, fed by the input and the appropriate plain or negated control bits; one very wide OR gate to pull together the outputs of the ANDs. Generalization has unacceptable fan-in. Divide-and-conquer 2d-MUX - Feed high-order d control bits into 2^d d-MUXes, each of which also takes a contiguous group of 2^d inputs. - Feed low-order d control bits into a final d-MUX, which also takes the outputs of the high-order d-MUXes as inputs. - Delay is 2d, plus 1 for initial inversion of control inputs. Suppose the straightforward MUX is limited to gates with fixed fan-in. Then its AND and OR gates have to be simulated with binary trees, giving the same big-O number of gate delays as the divide-and-conquer MUX. What about total number of gates (chip area)? Turns out the divide-and-conquer MUX is smaller by a factor of approximately d. BIG WIN. NB: The divide-and-conquer adder built an N-input circuit from 2 N/2-input circuits and some patch-up circuitry. The divide-and-conquer MUX built a 2^d-input circuit from 2^d-1 2^d-1 circuits (and some patch-up). Put another way, the MUX built an N-input circuit from sqrt(N) sqrt(N) circuits, which is kind of cool. ============================================================= Read Chapter 14 ============================================================= Propositional Logic has several limitations. One key limitation is that it applies only to atomic propositions. There is no way to talk about properties that apply to categories of objects, or about relationships between those properties. That's what predicate logic is for. Predicate logic is a mathematical model for reasoning with predicates: functions that map variables to truth values. As in propositional logic, we can create logical expressions containing predicates, manipulate those expressions according to the algebraic laws of predicate logic, and construct proofs using rules of inference to deduce new facts from axioms. In fact, proofs in predicate logic (based on unification) are a form of computation used in the programming language Prolog. Although predicate logic is more powerful than propositional logic, it too has its limits. ------------------------------------------------------------------------ Predicates A predicate is a boolean function whose value may be true or false, depending on the arguments to the predicate. * Predicates are a generalization of propositional variables. * A propositional variable is a predicate with no arguments. Example - Consider the following boolean propositions: A (Adam is tall) B (Beth is tall) C (Carl is tall) : Z (Zeke is tall) We need a different proposition for each person; each of these propositions is either true or false. We can capture the same set of truth values using a single predicate (or boolean function), Tall(x). Tall(x) is true whenever person x is tall, and is false otherwise. * Tall(Adam) is true if proposition A above is true. * Tall(Beth) is true if proposition B above is true. * Tall(Carl) is true if proposition C above is true. Predicates are atomic operands in the logical expressions of predicate logic. An argument can be either a constant or a variable. It is conventional to write variables with an initial upper-case letter. Constants can be numbers, names that begin with a lower-case letter, or quoted strings. A relation (remember the first unit this semester?) is one way to represent a predicate. Use the relation name P as the predicate name; If P has three columns, then P(a,b,c) is true if there is a tuple with fields a, b, and c. ------------------------------------------------------------------------ Quantifiers All we want to know about a given proposition A (Adam is tall) is whether A is true or false. Given a predicate such as Tall(x), we want to know whether Tall(x) is true for different values of x. In addition, we might like to know whether Tall(x) is true for every possible value of x, or whether Tall(x) is true for some value of x. Predicate logic has two additional operators not found in propositional logic (called quantifiers) to express truth values about predicates with variable arguments. * Existential quantifier E (there exists): (E x) Tall(x) is true if there exists some value for x such that Tall(x) is true. * Universal quantifier A (for all): (A x) Tall(x) is true if Tall(x) is true for all values of x. [NB: the existential quantifier is written with a backward E. The universal quantifier is written with an upside-down A. I can't type those in ascii. Please DO NOT feed me ordinary E's and A's on the final: write them the way they're supposed to be written.] ======================================================================== Logical Expressions in Predicate Logic A logical expression in predicate logic has much the same form as a logical expression in propositional logic, with the addition of atomic formulae (ie., predicates), and the universal and existential quantifiers. 1. An atomic formula is a logical expression. o A predicate with all constant arguments is a ground atomic formula. o A proposition is a predicate with no arguments, and therefore is a ground atomic formula. o A predicate with at least one variable argument is a nonground atomic formula. o A literal is either an atomic formula or its negation. 2. If L1 and L2 are logical expressions, then L1 AND L2, L1 OR L2, NOT L1, L1 -> L2, and L1 == L2 are logical expressions. 3. If L1 is a logical expressions, then (A X) L1 is a logical expression. 4. If L1 is a logical expressions, then (E X) L1 is a logical expression. Quantifiers have the highest precedence in logical expressions. ------------------------------------------------------------------------ Bound and Free Variables The quantifiers E (there exists) and A (forall) introduce variables into logical expressions. An occurrence of variable x in a logical expression is bound to the closest enclosing quantifier containing x, either (E x) or (A x). If an occurrence of x in a logical expression is not bound to any quantifier (because there is no enclosing quantifier containing x) that occurrence of x is free. Example: (A x) L1(x) OR (E x) L2(x,y) The variable x in L1 is bound to the universal quantifier. The variable x in L2 is bound to the existential quantifier. The variable y is free in this expression. In order for an expression to be *closed*, all of its variables must be bound. Cf. scope in programming languages. A common convention is to say that all variables that are unbound at the outermost nesting level are implicitly universally quantified. ------------------------------------------------------------------------ Evaluating Predicates There are two ways to evaluate the truth of a predicate P(x,y): * Assign a real-world interpretation to P (such as addition, subtraction, or equivalence) and a domain for P (ie, the possible values for the arguments) and compute the function P(x,y) under that interpretation. o If we assign the interpretation "equivalence" to P, and let the domain for P be the set of integers, then we can evaluate P(1,2) by asking is 1 equivalent to 2 (false). o If we assign the interpretation "less than" to P, and let the domain for P be the set of integers, then we can evaluate P(1,2) by asking is 1 less than 2 (true). o If we assign the interpretation "brother" to P, and let the domain for P be all students on campus, then we can evaluate P(Adam,Barney) by asking whether or not Adam and Barney are brothers. * Consult a relational database containing pairs of values for x and y and the corresponding value of P(x,y). o If the interpretation for P is "grade in CSC173" and the domain of x is all students on campus, and the domain of y is the set of possible grades, then we can evaluate P(Rosemary,"A") by looking up Rosemary's grade in the grade file for 173. o If we assign the interpretation "has a better overall record" to P, and let the domain of P be the set of professional football teams, then we can evaluate P(Buffalo, Miami) by looking up their respective records in a football database. Note that the relation approach is limited to finite domains, or at least finite sets of arguments for which the predicate is true. The real world interpretation approach can have an unbounded number of sets of arguments for which the predicate is true. This tradeoff has implications for systems such as Prolog. Numbers are special-cased in Prolog, but for everything else the system suffers from what is called the "closed world" problem. ------------------------------------------------------------------------ Tautologies A tautology in propositional logic is a statement that is true regardless of the truth assignment of propositions. A tautology in predicate logic is a statement that is true regardless of the interpretation of predicates, and regardless of the bindings chosen for any globally unbound variables. We can combine these statements to say, in general, a logical tautology is a statement that is true regardless of *model*. In propositional logic a model is a truth assignment for propositions. In predicate logic a model is an interpretation for predicates and a binding for any globally unbound variables. ------------------------------------------------------------------------ Evaluating Predicates: Example Consider the following family history to be relations (or facts) in a family tree database: male(Adam) female(Ann) male(Barney) female(Beth) male(Bob) female(Barb) male(Carl) female(Carol) male(Chet) female(Chris) parent(Adam,Barney) parent(Ann,Barney) parent(Adam,Beth) parent(Ann,Beth) parent(Adam,Bob) parent(Ann,Bob) parent(Adam,Barb) parent(Barney,Carl) parent(Carol,Carl) parent(Carol,Chet) To find the name of Barney's father, we can assert the following to be true: parent(x,Barney) AND male(x) -> father(x,Barney) This assertion states that if x is a parent of Barney, and x is male, then x is the father of Barney. Note that we haven't defined a father relation in our database; asserting the above expression to be true is the only definition of "father" we need. We know this expression evaluates to true (since we asserted it) regardless of the value of x. We can assign a constant value to x (someone's name), producing ground atomic formulae, which we can evaluate as true or false. When we substitute Adam for x, we find parent(Adam,Barney) and male(Adam) are true, so father(Adam,Barney) must be true as well (since the whole expression must be true). ------------------------------------------------------------------------ Evaluating Quantifiers To evaluate a quantifier for a predicate we must first define * the domain over which the quantifier varies (that is, the set of values for the predicate's arguments) * the interpretation of the predicate (that is, the meaning of the predicate) When we state "there exists x such that P(x)" we must be explicit about the possible values x can take (the domain of P). We evaluate P(x) for each value of x in the domain of P (according to the interpretation for P), and if P(x) is true for some x, then the expression (E x)P(x) is true. Similarly, when we assert "for all x P(x)" we must be clear about what possible values of x we consider (again, the domain of P). We evaluate P(x) for all values of x in the domain of P (again, according to the meaning of P), and if P(x) is true for all x, then the expression (A x)P(x) is true. Note that if the domain of P is infinite, we don't have an algorithm (which terminates) to compute the value of P. * In many cases, we'll have a finite domain, so we do have an algorithm. * In many cases we're concerned about whether two expressions are equivalent, and not whether a particular expression is true or not. ------------------------------------------------------------------------ Evaluating Predicate Expressions: Example Consider the following logical expression in predicate logic: P(x,y) -> (E z)(P(x,z) AND P(z,y)) We can read this as "if P(x,y) then there exists z such that P(x,z) and P(z,y)". (Assume that x and y are universally quantified.) If we make the domain of P the set of real numbers, assign the values 5.1 and 4.2 to the free variables x and y, and interpret P to mean "greater than", then we can evaluate the expression as follows: P(x,y) = P(5.1,4.2) = 5.1 > 4.2 = true (E z) (P(x,z) AND P(z,y)) = (E z)((5.1 >z) AND (z > 4.2)) = true (for z=4.8) true -> true = true If we make the domain of P the set of integers, assign the values 5 and 4 to the free variables x and y, and interpret P to mean "greater than", then we can evaluate the expression as follows: P(x,y) = P(5,4) = 5 > 4 = true (E z) (P(x,z) AND P(z,y)) = (E z)((5 > z) AND (z > 4)) = false true -> false = false ------------------------------------------------------------------------ Summary of evaluation: (1) The truth of many statements with unbound variables is indeterminate: Some statements (e.g. P(x) OR NOT P(x)) may be true regardless of bindings (and others may be false, regardless), but in general we need bindings. (2) The truth of many statements depends on the interpretation of predicates. Again, some statements may be true or false regardless, but in general we need interpretations. (3) As we will see below, some statements under some interpretations and proof systems are true but can't be proven. ======================================================================== Laws for Manipulating Quantifiers Binding free variables in a tautology If a logical expression L with free variables x1..xn is a tautology, then (A x1)(A x2)..(A xn) L is also a tautology. We can use the above rule to bind all free variables in a tautology to a universal quantifier. P(x,y) OR NOT P(x,y) == 1 == (A x)(A y) (P(x,y) OR NOT P(x,y)) An expression with no free variables is a closed expression. Moving NOT within a quantifier There is rule analogous to DeMorgan's law that allows us to move a NOT operator through an expression containing a quantifier. NOT (A x) L(x) == (E x) (NOT L(x)) NOT (E x) L(x) == (A x) (NOT L(x)) The first rule can be read as "it is not the case that for all x, L(x) is true" is equivalent to "for some x, it is not the case that L(x) is true". The second rule can be read as "it is not the case that for some x L(x) is true" is equivalent to "for all x, it is not the case that L(x) is true". Moving quantifiers through AND and OR L1 AND (A x) L2(x) == (A x) (L1 AND L2(x)) L1 AND (E x) L2(x) == (E x) (L1 AND L2(x)) L1 OR (A x) L2(x) == (A x) (L1 OR L2(x)) L1 OR (E x) L2(x) == (E x) (L1 OR L2(x)) Note that we require x is not a free variable in expression L1 in the above rules. We may have to rename variable x (consistently) in L2 to avoid any overlap with free variables in L1. ------------------------------------------------------------------------ Manipulating Quantifiers: Example Given the following expression: (A x)P(x) OR (E x)(NOT P(x)) we can rename the second occurrence of x to avoid any overlap with the first occurrence and arrive at the equivalent expression (A x)P(x) OR (E y)(NOT P(y)) Moving the universal quantifier through the OR we arrive at (A x) (P(x) OR (E y)(NOT P(y))) Moving the existential quantifier through the OR we arrive at (A x) (E y) (P(x) OR NOT P(y)) Using these rules, we can write any expression involving quantifiers Q1, Q2, .. QN, and the logical operators AND, OR, and NOT in *prenex form*: (Q1 x1)(Q2 x2)..(Qn xn)L where all the quantifiers appear outside expression L. 1. First, rewrite the expression so that all of the quantifiers refer to distinct variables not found in other quantifiers or free in the expression. 2. Use the rules above to move the quantifiers outside NOT, AND, and OR.