CPSC 121 Quiz 3 Wednesday, 2012 July 18 [6] 1. Given the premises: (∼ q →∼ p) ∧ (q → r), ∼ q ∧ r, d → (s ∧ p), and s ∨ d; prove s. You may only use rules listed on “Dave’s Awesome Sheet” (or lemmas you prove yourself on this quiz). Please make your finished proof clear and easy to read. We suggest using the back of the previous page for your scratchwork! We have begun the proof below. Proof (that the conclusion reached below follows from the premises listed): 1. 2. 3. 4. (∼ q →∼ p) ∧ (q → r) ∼q ∧ r d → (s ∧ p) s∨d [premise] [premise] [premise] [premise] Solution : Here’s a polished, finished version. 5. 6. 7. 8. 9. 10. 11. ∼ q →∼ p ∼q ∼p s∨ ∼ p ∼ (∼ s ∧ p) ∼d s [by SPEC on 1] [by SPEC on 2] [by M.PON on 5, 6] [by GEN on 7] [by DM on 8] [by M.TOL on 3, 9] [by ELIM on 4, 10] (In our first pass, we wound up at several dead-ends, such as deriving q → r and then noticing that if we know ∼ q ∧ r, q → r is totally useless!) Note that it’s also possible to prove this without using the first two premises. See if you can do so! [6] 2. We can model the connections in combinational circuits with predicate logic. Let P be the set of “ports”—inputs of gates, outputs of gates, inputs of the circuit, and outputs of the circuit. Let WireTo(a, b) defined for a ∈ P, b ∈ P mean that a has a wire leading to b. (Notice that WireTo has a direction. For example, we’d never have a “WireTo” relationship from any port to an input of the circuit!) Let Input(a) and Output(a)—each defined for a ∈ P —mean that a is an input to or output from the circuit, respectively. Consider this circuit (with gates labeled g1 , g2 , and g3 ): In this circuit, for example, Input(i1 ) is true because i1 is an input to the circuit. However, g1 (a gate) and o1 (an output of the circuit) are not inputs; so, Input(g1 ) and Input(o1 ) are both false. page 2 Specifically: the Input predicate is true for i1 , i2 , and i3 and false otherwise. The Output predicate is true for o1 and o2 and false otherwise. Here are the only true WireTo relationships: WireTo(i1 , g1 ), WireTo(i1 , g3 ), WireTo(i2 , g1 ), WireTo(i2 , g3 ), WireTo(i3 , g2 ), WireTo(i3 , g3 ), WireTo(g1 , g2 ), WireTo(g2 , o1 ), and WireTo(g3 , o2 ). [1] (a) Input(g2 ) → WireTo(i1 , g2 ) is (circle one): Remember how conditionals work! TRUE FALSE Solution : TRUE. (It can only be false if Input(g1 ) is true but WireTo(i1 , g1 ) is false. Neither of these is the case.) [2] (b) Disprove the statement ∀a ∈ P, WireTo(a, o1 ). Solution : This is false based on any counterexample, such as the fact that there is no wire from input i1 to output o1 . [3] (c) Prove the statement ∀a ∈ P, ∼ Output(a) → ∃b ∈ P, WireTo(a, b). Solution : This is true. It’s trivially true for any output. So, we need only consider gates and inputs. For those, we need an example for each one showing this is true, any examples will do. For instance: all of i1 , i2 , and i3 have wires to g3 . g1 has a wire to g2 . g2 and g3 have wires to o1 and o2 , respectively. [8] 3. A “binary tree” is composed of “subtrees”. Each subtree is either a leaf (with no children), or it has a left child and a right child, each of which is itself a subtree. Let S be the set of all subtrees in a particular binary tree. Let LeftChild (p, c) defined for p ∈ S, c ∈ S be true exactly when c is the left child of p. Let RightChild (p, c) defined for p ∈ S, c ∈ S be true exactly when c is the right child of p Now, let’s further define what it means to be a binary tree. You may always use the predicates LeftChild and RightChild . Furthermore, in each part, you may rely on the definitions and statements from the previous parts being correct, regardless of whether you completed them correctly! [2] (a) Define a predicate Child (p, c) (defined for p ∈ S, c ∈ S) that is true exactly when c is a child of p. Solution : We simply want to state that c is either a right or left child: Child (p, c) = LeftChild (p, c) ∨ RightChild (p, c) It’s tempting to add that p 6= c as in: Child (p, c) = p 6= c ∧ (LeftChild (p, c) ∨ RightChild (p, c)) We won’t take off for this, but there’s a compelling reason—that matters in all problemsolving, including software design—not to do this. If LeftChild (a, a) is true for page 3 some a, why should we suddenly decide here to “overrule” that decision and make Child (a, a) false? In particular: make a single important design decision (that you may wish to change) at a single place in your model. Don’t entangle it throughout your model. If it’s entangled in many places in your model and you later change your mind, you’ll be forced to try changing it in many places. . . or may not even be able to! [2] (b) Define a predicate Root(s) (defined for s ∈ S) that is true when s has no parent. Solution : The root has no parent. That is, there is no subtree such that the root is that subtree’s child: Root(s) =∼ ∃p ∈ S, Child (p, s) [2] (c) No subtree has more than two children. State that fact in predicate logic. Solution : That’s not quite our “no more than one” idiom, but it’s close. We can work from there if we understand the idiom. In this case, we’re saying “it’s not the case that there are three different children of a subtree”. Let’s start with a predicate ThreeChildren(s), meaning s has at least three (different) children: ThreeChildren(s) = ∃c1 ∈ S, ∃c2 ∈ S, ∃c3 ∈ S, c1 6= c2 ∧c1 6= c3 ∧c2 6= c3 ∧Child (s, c1 )∧Child (s, c2 )∧Child (s, c3 ) From there, it’s easy. We just want to say “no subtree has at least three children”: ∀s ∈ S, ∼ ThreeChildren(s) [2] (d) Every non-root subtree in a binary tree has a parent. State that fact in predicate logic. Solution : We want to say something about every subtree that is not the root. That’s restricting the domain of a universal to those subtrees that aren’t the root. Something like: ∀s ∈ S, ∼ Root(s) → . . . Now, we just want to say in the “. . .” that the subtree has a parent: ∀s ∈ S, ∼ Root(s) → ∃p ∈ S, Child (p, s) As we discovered in class discussing this, however, Root(s) also means precisely “subtree s has no parent”. Therefore, with that definition, this can be expressed as: ∀s ∈ S, ∼ Root(s) →∼ Root(s) Which is logically equivalent to T . So, T is a correct answer to this question. Oops! page 4 BONUS: Earn up to 2 bonus points by doing one or more of these problems. • A different way to think of a binary tree—closer to the typical Java version—is that it is composed (mostly) of nodes rather than subtrees. There’s also one special value null that is not a node (or anything else) at all. So, for example, in this version every node has two children, but a node may have null as one or both children (and be a leaf, in the latter case). Consisder the statement “every tree has a root”; discuss whether it is true or false in the two “versions” of binary trees and then rewrite the binary tree problem with this version, explaining the differences. Solution : We don’t include the new version, but we do ask: How must the statements change? Among other things, we must decide whether a null can be a root or not. Essentially we must decide that either a null can be the root, in which case the root can be one of these “nothing-atall” things or the root must be a node, in which case we have to rewrite our definition somewhat (and maybe some of the others) with a new predicate that can test for nullity and there’s one case (the empty tree) where a tree has no root at all! The latter seems by far the more reasonable definition. • Part (c) of the circuit problem is a general statement that we could apply to any combinational circuit. Must it necessarily be true—or necessarily be false—for all combinational circuits? Should it be true or false for all combinational circuits? Justify your answers, ideally including an illustrative example or two. Solution : Part (c) states that every circuit “port” is either an output of the circuit or leads to some other part of the circuit. That’s not true of every combinational circuit. (It’s easy to construct examples, for instance, that ignore some of their inputs.) Should it be true? Well, what would it mean if it weren’t true? Once you’ve thought that through, consider designing a circuit to test if a signed binary number is negative. Is there a similar statement we could make that we really do think should be true?
© Copyright 2026 Paperzz