COMPSCI 230 — Homework 7 Due on March 24, 2015

You may talk about this assignment with others, but do not write down anything while you talk. After that, do the assignment alone. What you hand in must be your work only. See Mechanics→Homework on the class web page for details on the homework policy.

WHAT TO DO. Follow these instructions accurately. There will be penalties for improperly formatted answers. This assignment comes with auxiliary files template.tex and mystery.rkt. Rename the file template.tex as usual before starting to work with it. For each of the problems below, write a clear description of your solution under the proper heading in your .tex file. The file mystery.rkt is for reading only, so you will not need to modify it or hand it in. An extra-credit question in this assignment asks you to write a Racket program. If you choose to do that, place your solution into an appropriately-named .rkt file. Starting with this assignment, you will learn to write well-formed proofs. A sloppy proof is useless (and gets little credit, by the way), so pay close attention to the formatting instructions. Good style matters also in proofs, not only in programming.

1. A formula of propositional logic is said to be a if it is true regardless of the truth values of its elementary propositions. For instance, the truth of P → Q depends on the truth values of P and Q, but the formula P ∧ Q → P is true regardless of the truth values of P and Q. A mechanical way to show that a formula of propositional logic is a tautology is to first build its truth table, which for the last formula above is as follows: PQ ((P ∧ Q) → P ) TT T T TF F T FT F T FF F T 1 2

(more about truth-table format below). The formula is a tautology iff1 the column corresponding to the full formula (that is, column 2, which is under the highest-level operator in the formula) contains only the ’T’ , as is the case in the example. A conditional formula that is also a tautology is rewritten with the symbol ‘⇒’ instead of the symbol ‘→’. So the formula above can be rewritten as

P ∧ Q ⇒ P to emphasize that it is a tautology, and reads “P ∧ Q implies P .” So an implication is a conditional that is always true because of its structure. Similarly, a biconditional (↔) that is always true because of its structure is called an equivalence and is denoted by the symbol ‘⇔’. Determine which of the following conditionals or biconditionals are tautologies by building full truth tables in the format specified below. Show your truth tables and state your conclusion for each formula explicitly. (a) (((P →Q)→Q)→((Q→P )→P ))

(b) (((P ∧Q)→R)→((P →R)∨(Q→R)))

TRUTH-TABLE FORMAT. The format described here is slightly different from that used in FDM, and and example follows. In a full truth table, every simple proposition (P , Q, ...) and every operator (∼, ∧, ∨, →, ↔) in the formula gets its own column, as done in the example above. Simple propositions go into the leftmost columns of the table, listed in alphabetical order, just as shown in FDM. Rows are in the standard order: If T represents zero and F represents 1, then the truth-value entries for the simple propositions read like binary numbers in increasing order if you read the table top-down. Parenthesize formulas fully, with exactly one pair of parentheses for each operator. This includes the top-level operator, so the entire formula is enclosed in parentheses, as done above. Parentheses do not get their own columns in the table. Open parentheses are inserted just before the first simple proposition they precede. Closed parentheses are inserted just after the last simple proposition they follow. Truth values for simple propositions are only given once in the first column in which they appear. Do not repeat truth values for subsequent columns associated with simple propositions.

1The abbreviation iff stands for “.”

COMPSCI 230 — Duke — March 16, 2015 An additional row at the bottom of the table contains one integer in each operator column. This integer is analogous to the one used in FDM, and shows the order in which you computed each column of the truth table. This ordering is not unique, and different people may legitimately come up with different orderings. Of course, not all orderings are valid. The smallest order integer is 1. There is no need to include a vertical (as is done in FDM). Instead, separate this last row from the others with a horizontal line. There is one horizontal line separating the column headers from the other rows, one horizontal line separating the truth table from the bottom row of order numbers, and no other horizontal line. There is one vertical line separating the simple propositions from the other formulas, and no other vertical line. As an example, the truth table for the formula

(((P ∧(∼ Q))∨((∼ P )∧R))→(Q∨R)) is as follows PQR (((P ∧ (∼ Q)) ∨ ((∼ P ) ∧ R)) → (Q ∨ R)) TTT FF FF F T T TTF FF FF F T T TFT TT TF F T T TFF TT TF F F F FTT FF TT T T T FTF FF FT F T T FFT FT TT T T T FFF FT FT F T F 2 1 5 3 4 7 6

Note that the full formula is not a tautology because column 7 contains an ‘F’. The LATEX code used to generate this table (and center it on the page) is as follows:

\begin{center} \begin{tabular}{*{3}{c}|*{13}{c}} $P$ & $Q$ & $R$ & $(((P$ & $\logand$ & $(\lognot$ & $Q))$ & $\logor$ & $((\lognot$ & $P)$ & $\logand$ & $R))$ & $\logthen$ & $(Q$ & $\logor$ & $R))$ \\\hline \logT & \logT & \logT & & \logF & \logF & & \logF & \logF & & \logF & & \logT & & \logT & \\ \logT & \logT & \logF & & \logF & \logF & & \logF & \logF & & \logF & & \logT & & \logT & \\ \logT & \logF & \logT & & \logT & \logT & & \logT & \logF & & \logF & & \logT & & \logT & \\ \logT & \logF & \logF & & \logT & \logT & & \logT & \logF & & \logF & & \logF & & \logF & \\ \logF & \logT & \logT & & \logF & \logF & & \logT & \logT & & \logT & & \logT & & \logT & \\ \logF & \logT & \logF & & \logF & \logF & & \logF & \logT & & \logF & & \logT & & \logT & \\ \logF & \logF & \logT & & \logF & \logT & & \logT & \logT & & \logT & & \logT & & \logT & \\ \logF & \logF & \logF & & \logF & \logT & & \logF & \logT & & \logF & & \logT & & \logF & \\\hline & & & & $2$ & $1$ & & $5$ & $3$ & & $4$ & & $7$ & & $6$ & \\ \end{tabular} \end{center}

The argument *{3}{c}|*{13}{c} to the tabular environment in the example above means that the table has three centered columns (*{3}{c}), followed by a vertical bar, followed by 13 centered columns. This format repetition style with is not part of standard LATEX but is provided in the array package, which the .tex file already includes. To avoid confusion with LATEX symbols, the .tex file defines commands \logand, \logor, and so forth for the logical operators, and also rewrites the formulas above for you, so you can see how to write similar formulas in LATEX. The file also defines \logT for ‘T’ and \logF for ‘F’. These and other LATEX commands useful for this assignment are summarized in a table in the Appendix to this assignment. WHAT TO DO. It is easy to get lost in the sea of needed to write a table like this in LATEX. I can think of four ways of getting the table right:

• First draw the table by hand cleanly and in every detail on a sheet of paper, then translate that to LATEX. This procedure works if you are patient, have a good hand at drawing, and are detail oriented.

• Use cut-and-paste very judiciously and directly in LATEX. For instance, if you understand the standard row ordering, then you can write the first three columns of the table in the example above by only writing its first line, then cutting, pasting, and making simple edits three times (as opposed to writing eight rows) for the table above. After that, you could put placeholders (perhaps a question mark) in the operator columns of the first row, and run LATEX to make sure the placeholders are where they belong. You can then copy that row eight times to get placeholders in the full table (including the bottom row with numbers). The next logical step is to replace the placeholders in the bottom row with the appropriate numbers. Once this is done, you can fill each column that has placeholders in the given order. At the end, insert \hline commands where needed (there are exactly two in every table). This procedure works if you are good at cut-and-paste, you work systematically, and you keep compiling the LATEX source and check all your intermediate steps are correct. • 10 extra-credit points for this solution approach. Write Racket code to generate the tables automatically. This is by far the most satisfactory way in terms of the reward you get from doing it, but is also difficult to get right, and may not be worth the investment

COMPSCI 230 — Duke — March 16, 2015 given the small number of problems over which you would amortize your effort. If you follow this path, please submit your code (see instructions at the bottom of the assignment) and make a note before your first truth table, so we know to look for your code. Warning. The extra-credit solution approach is not for the faint of heart. Only do it if you enjoy programming in Racket. You will get full extra credit only for a clean, functional implementation. You can use a different language if you like, but you will get no extra credit in that case.

• Use someone else’s code or program, from the web or from elsewhere, directly or for inspiration. This would be a violation of academic integrity. Remember that the point of this problem is for you to familiarize yourself with the mechanics of truth tables, so you would be cheating yourself first. Also, if you know how to Google for solutions, so do we. It is not difficult to spot structural similarities for complex code, even if superficial or local changes are made. HINT. Your code will be simpler if the input is an expression, not a string, and is fully parenthesized:

'(((P and (not Q)) or ((not P) and R)) -> (Q or R))

2. The previous problem used parentheses generously, in case you chose to write a computer program to solve it. In this problem we keep things simpler by assuming that ∼ binds more tightly than ∧ and ∨, which in turn bind more tightly than →. “Binds more tightly” here means “is applied before”, as in “multiplication binds more tightly than summation” for standard algebra. Section 5.3 of Carlo’s notes on logic shows an example of using truth tables to prove implications in propositional logic. In principle, this method always works. However, since 6 distinct propositional symbols (c, n, t, h, s, p) are involved in that example, the truth table has 26 = 64 rows, and it had to be split over two pages in the notes. This hints at a problem with truth tables: their size increases exponentially with the number of propositional symbols, so proving things by truth table is extremely inefficient already in propositional logic, which is much simpler than predicate logic. A more compact way to prove formulas given a set of axioms is to use inference rules like the ones shown in section 3.4 of FDM. This set of rules is insufficient for many reasoning tasks, so we add a few rather obvious ones:

Add Or Add Then Add Double Not Remove Double Not ϕ ψ ϕ ∼∼ϕ ϕ ∨ ψ ϕ → ψ ∼∼ϕ ϕ

The text in each box is the name of the inference rule. The “Add Or” rule says that if ϕ is true, then so is also ϕ ∨ ψ for any ψ, and the “Add Then” rule is similar (but note the ψ rather than ϕ in the premise). The “Double Not” rule eliminates double . At some point, the set of inference rules becomes rich enough for a given target level of expressiveness.2 Even then, however, one can add even more rules as a matter of convenience: The new rules can be derived from the old ones, and their introduction can shorten proofs. Whether essential or redundant, a new rule must be shown to be valid. To prove that an inference rule

ϕ1 . . ϕn ψ is valid, you simply prove the implication ϕ1 ∧ ... ∧ ϕn ⇒ ψ . Since inference rules are typically short, it is OK to use a truth table for this proof.

(a) Use a truth table to prove that the inference rule “Add Or” is valid. Of course, in the header of your truth table you use the conditional symbol, not the implication symbol, because as you build the table you do not yet know if the conditional is a tautology.

WHAT TO DO. Make sure you format your table as described earlier. Here and elsewhere, a proof needs to end with a statement that what was to be proven is indeed true. So after showing your truth table, you need a sentence or paragraph that ends with something like the following:

... and therefore the “Add Or” inference rule is valid.

Just showing a truth table is not enough, and the text that follows it must state with precision why the truth table supports your validity argument.

2The topic of deciding when a set of inference rules is rich enough is very interesting, but is beyond the scope of this course.

COMPSCI 230 — Duke — March 16, 2015 (b) Use a truth table to prove that the inference rule “Add Then” is valid. (c) We can save time by proving the validity of both the “Add Double Not” and “Remove Double Not” rules by proving one bicon- ditional rather than two separate conditionals. Use a single truth table to prove that the inference rules “Add Double Not” and “Remove Double Not” are valid. (d) Use the inference rules given in FDM and the inference rules introduced above to prove that the following axioms

1 : (Q → P ) → R 2 : Q ∨ S → P 3 : T 4 : ∼ Q → ∼ T

imply the following formula

5 : R

Note carefully how inference rules work: each of the premises can represent any proposition that is currently known to be valid (because it is one of the axioms, or because it was introduced by some previous inference rule). The conclusion is then rewritten by replacing each premise symbol that appears in it with the proposition that that premise was tied to. For instance, to apply Modus Tollens ϕ → ψ ∼ ψ ∼ ϕ to the two axioms

a : ∼ (P ∨ Q) → ∼ (R ∧ S) b : ∼ (R ∧ S)

you match ϕ to ∼ (P ∨ Q) and ψ to ∼ (R ∧ S) to obtain

Modus Tollens a : ∼ (P ∨ Q) → ∼ (R ∧ S) b : ∼ (R ∧ S) c : ∼∼ (P ∨ Q) If you wanted to remove the double negation, you would have to then use another inference rule. HINT. You will only need some of the rules. While your proof will be much shorter than a truth-table proof, coming up with the exact sequence of axioms and inference rules to use requires creativity, and is in general difficult. This example is small enough that you should be able to come up with a proof with a modicum of trial and error. One way to go about devising a proof is to write the axioms (1-4) at the top of a blank sheet of paper and the formula (5) to be proven at the bottom. Then write the inference rules either in the margin or on a separate sheet. Finally, fill the gap working alternately from the top (trying to use inference rules and axioms to make them look more like the formula at the bottom) and from the bottom (trying to use the inference rules backwards to make the formula look more like the axioms).

WHAT TO DO. While you devise a proof as described above, once you have it you just write it as a properly ordered sequence of applications of the inference rules. Since these rules say it all, no words are needed for this proof, other than labels that indicate which inference rule is applied to which formulas. As an example, assume that the three axioms

1 : p 2 : p → q 3 : p → (q → r)

are true. (The number or symbol that precedes each axiom give a label to that axiom, so it can be referred to later.) A proof for the (rather simple) formula

4 : r

COMPSCI 230 — Duke — March 16, 2015 is as follows: Modus Ponens Modus Ponens Modus Ponens 2 : p → q 3 : p → (q → r) 6 : q → r 1 : p 1 : p 5 : q 5 : q 6 : q → r 3 : r Note that premise labels are always “old”—they refer to formulas that are known to be true—while conclusion labels are “new”, with the exception of the very last (the formula to be proven). Please stick to analogous notation in your proof. To help you to this end, the .tex file defines a LATEX environment infer and two commands \premise and \conclusion, so to write

Modus Ponens a : p→q b : p c : q

in LATEX you say \[ \begin{infer}{Modus Ponens} \premise{a}{p \logthen q} \premise{b}{p} \conclusion{c}{q} \end{infer} \]

To place several such rules next to each other make a table with the tabular environment.

CODA. The whole point of this exercise is that while each application of an inference rule is a completely mechanical step, coming up with the correct sequence of steps for a proof is not trivial: Inference—mechanized or otherwise—is a challenge already in propositional logic, and becomes even harder in predicate logic. This exercise also highlights an important general observation: The process of devising a proof—in any context and with any technique—is far from linear, and is not reflected at all in the resulting proof, which is instead a sequence of simple steps arranged post facto into a linear logical order. Ludwig Wittgenstein’s metaphor comes to mind (Proposition 6.54 of his Tractatus Logico-Philosophicus, Harcourt, Brace and Company, Inc, 1922): He must so to speak throw away the ladder, after he has climbed up on it.3

3. A common first step in developing a proof for a mathematical statement involving variables is to write out examples for a few values of the variables. This is done either in order to understand the statement more concretely, or to conjecture whether the statement is true or . For instance, you may have conjectured that the formula

p(n) = n2 + n + 41 generates only prime numbers. Before you embark into a proof attempt, you want to gain some confidence in your conjecture. The first ten values seem promising: n p(n) 0 41 1 43 2 47 3 53 4 61 5 71 6 83 7 97 8 113 9 131 10 151

The LATEX source for this table was generated with the function make-latex-table provided with the file mystery.rkt that comes with this assignment.

3The German original reads: Er muss sozusagen die Leiter wegwerfen, nachdem er auf ihr hinaufgestiegen ist.

COMPSCI 230 — Duke — March 16, 2015 (a) A Racket function mystery is provided in that file as well. Explain briefly and clearly what the function mystery does, in general terms—that is, specify what the function is designed to do by analyzing its code, not by actually running it. (b) Run the function mystery without arguments. Report what it returns verbatim, then interpret all parts of the result in a brief and precise paragraph. (c) Comment in one brief paragraph on the perils of using examples when thinking of proofs.

4. Translate each of the following statements to a simple, correct, and well-formed English sentence, and state whether the statement is true or false. The domain of each variable is the set of all real numbers. [Simpler and clearer sentences get more credit.] (a) ∃x ∀y (xy = y) (b) ∀x ∀y (((x ≥ 0) ∧ (y < 0)) → (x − y > 0)) (c) ∀x ∀y ∃z (z = x − y) (d) ∃z ∀x ∀y (z = x − y)

5. Translate each of the following sentences to a formula in predicate calculus. No negation symbol should appear to the left of any quantifier in your solution. Solutions are not necessarily unique, but simple, correct answers are better than more complicated ones. LATEX commands that may be useful in this and there problems are listed in the Appendix to this assignment. HINT. Section 3.3 of FDM and Section 6.1 of Carlo’s notes on logic show how to switch the negation symbol with one quantifier. (a) The product of two negative integers is positive (b) The difference of two negative integers is not always negative.

6. Consider the statement Someone knows everyone’s cell-phone number. We take this statement to hold for some group of people that we do not care to specify, so you can leave the domains of all variables unspecified. Let the predicate K(x, y) mean “x knows y’s cell-phone number. (a) Express the statement above in predicate logic (b) Write a predicate-logic formula that expresses the negation of the initial statement. Your formula should have no negation symbol to the left of any quantifier. (c) Write an English sentence that reflects the formula in your last answer verbatim (that is, just translate the symbols literally into English, in the order in which they appear). (d) Now rewrite the same statement as a clean and simple English sentence.

7. You may not remember or you may not have used the standard symbols, but you definitely encountered existential and universal quantification when you studied limits and continuity in your calculus courses. For instance, let C(f, x) denote the predicate The function f : R → R is continuous at x. This predicate can be defined as follows: ∀ϵ > 0 ∃δ > 0 ∀y ∈ R (|y − x| < δ → |f(y) − f(x)| < ϵ) . (1) The definition above can be read verbatim as follows: For every positive ϵ there is a positive δ such that for every real y if |y − x| < δ then |f(y) − f(x)| < ϵ (2) and can be expressed more succinctly as follows: The value f(y) can be made arbitrarily close to f(x) (without one necessarily coinciding with the other) by choosing y to be close enough (but not equal) to x. (3) The last sentence illustrates that the quantifiers can be implicit, and that making them explicit may require some careful thinking.

COMPSCI 230 — Duke — March 16, 2015 (a) This question is preparation for the following ones. In section 3.2.4 of FDM you saw that

P → Q is equivalent to (∼ P )∨Q

so that ∼ (P →Q) is equivalent to ∼ ((∼ P )∨Q) . Use De Morgan’s laws to rewrite the expression ∼ ((∼ P )∨Q) as a conjunction that uses the symbol ‘∼’ only once. The commands \lognot, \logand, and \logand yield symbols ‘∼’, ‘∧’, and ‘∧’ respectively.

(b) Rewrite the negation ∼ C(f, x) of the predicate C(f, x) defined earlier in predicate logic notation by • “bringing the negation inside” all three quantifiers in C(f, x), • writing the part in the final parentheses as a conjunction, and • eliminating all occurrences of the negation symbol ∼.

Your answer should have three parts in the style of expressions (1), (2), (3) above. In the “succinct” phrasing, use all and only the quantifiers that are needed to avoid ambiguities. The predicate C(x, f) is written for you in the .tex template file, so you see how symbols are used. The LATEX commands \leq and \geq produce symbols ‘≤’ and ‘≥’ respectively. Please also note the LATEX command \; to create an m-space (a space as wide as the letter ‘m’). The command \, creates an n-space instead. Please use spacing and parentheses for readability and to remove any ambiguities, as done in the definition of C(f, x). (c) Proving ∼ C(f, x), that is, proving that a function f is not continuous at x is conceptually simple, because the first quantifier is existential, as you (hopefully) just found out: Since ∼ C(f, x) claims that some ϵ exists that has some property, all we need to do to prove ∼ C(f, x) for some given f and x is to produce an example of that ϵ, and show that it satisfies the rest of the predicate. Let   1 if x > 0 f(x) = sign(x) =  0 if x = 0 −1 if x < 0 be the sign function. Prove the predicate ∼ C(sign, 0).

WHAT TO DO. “Proving” here means writing a . This amounts to giving a clear and detailed argument for why ∼ C(sign, 0) is true. This argument should give a suitable value of ϵ and show in full detail why that value satisfies the predicate to be proven. As stated earlier, every proof should end with a sentence that connects to what you are proving. So this proof should end with the sentence

Therefore, sign(x) is not continuous at x = 0.

To write sign(x) in LATEX, you write \mbox{sign}(x) assuming that you are in math mode. If you need the symbol ‘≠ ’, you can obtain it with the LATEX command \neq (in math mode). See the Appendix at the end of this assignment for more LATEX symbols. Once you are done writing your proof, re-read it and check that every statement you make in it is grammatically correct, unam- biguous, true, relevant to the argument, and well-supported. Edit until this is the case.

WHAT TO HAND IN. At the start of class on the due date, hand in a paper printout of your .pdf file, stapled (not clipped) in the upper-left corner. Make sure that your name shows up on the first page. One student, one staple! We do not provide staplers in class. Before start of class on the due date, also submit your (properly named) .pdf file on Sakai (not in the Sakai dropbox). If you solved Problem 1 in the extra-credit way, staple a printout of your Racket code to the back of your .pdf file and also submit your (properly named) .rkt file on Sakai. Make sure that both items also contain the expressions in the assignment, and code to compute their truth-tables. We need to be able to just run your code and see the resulting LATEX source for all the truth tables in the assignment.

COMPSCI 230 — Duke — March 16, 2015 A Useful LATEX Commands

Some of the commands below are standard LATEX commands, or are included in the AMS-Math distribution, which is in turn included in the .tex file. Other commands are new, and are defined in the .tex file itself.

LATEX result \lognot ∼ \logand ∧ \logor ∨ \logthen → \logiff ↔ \logimplies ⇒ \logequiv ⇔ \logT T \logF F

Table 1 . Logical operators and truth values. These are new definitions in the .tex file and work both inside and outside math mode.

LATEX result \exists ∃ \forall ∀ = = \neq ≠ < < \leq ≤ > > \geq ≥

Table 2 . Quantifiers and inequalities. These are predefined and work only inside math mode.

To obtain Modus Ponens a : p→q b : p c : q in LATEX you say \[ \begin{infer}{Modus Ponens} \premise{a}{p \logthen q} \premise{b}{p} \conclusion{c}{q} \end{infer} \]

Table 3 . Example use of the environment and commands for inference rules provided in the .tex file.

COMPSCI 230 — Duke — March 16, 2015