0% found this document useful (0 votes)
49 views510 pages

Discrete Mathematical Structures With AP

Uploaded by

masoodvali.22554
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
49 views510 pages

Discrete Mathematical Structures With AP

Uploaded by

masoodvali.22554
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 510
Discrete Mathematical Structures with Applications to Computer Science J.P. Tremblay R. Manohar e ) .NK(=) For example, if P has been declared LOGICAL, the statement P=5%2.LT17 assigns a value of .TRUE. to P. Similarly, if Q has been appropriately declared, the statement Q=A+5.GE.C+D assigns the value . TRUE. to Qif A + 5 is greater than or equal to C + D when the statement is executed, and the value .FALSE. otherwise. From the truth values arising, for example, from relations, more complex logical expressions can be obtained in FORTRAN by using one or more of the three logical connectives previously discussed. The logical operators .AND., -OR., and ,NOT. correspond to the symbolic logical operators A, V, and ~] respectively. The statement PV CTQN R)) is equivalent to the FORTRAN statement P.OR. (.NOT. (Q.AND. R)) Unnecessary parentheses are avoided in FORTRAN by using the following precedence scheme. The arithmetic operators, with their usual order of prece- dence, are the highest in rank and are consequently evaluated first. All relational operators have the same rank and are evaluated after the arithmetic operators. The logical operators are the last to be evaluated, and .NOT., .AND., and .OR. is their decreasing order of precedence. Of two or more binary operators having the same precedence value in an expression, the leftmost is evaluated first; for unary operators, it is the rightmost which is evaluated first. Thus, NOT. P -AND. Q means (.NOT. P) AND. Q; and A+ B + 5.0 .LT. C + D means ((A + B) + 5.0) .LT. (C + D). FORTRAN has a logical “IF statement” whose form is IF (logical expression) statement If the logical expression in the “IF statement” is true, then the statement follow- ‘ing the expression is executed; otherwise, it is skipped. For example, when the statement IF (.NOT. POR. Q) GO TO 100 is executed, it will not transfer control to statement 100 if P and Q have the values .TRUE. and .FALSE. respectively. Arrays of logical variables can also be used in FORTRAN. The statement LOGICAL CASE(10) declares a one-dimensional array of type LOGICAL consisting of 10 elements. Elements of logical arrays are referenced in the same manner as any other sub- scripted variable. 16 MATHEMATICAL Losic Consider the problem of generating all possible assignments of truth values to the logical variables P, Q, and R, as shown in Table 1-2.7, There are 2? = 8 possible assignments. Notice that the truth value of the variable P remains at the same value of’ 7 or F for each of four consecutive assignments of logical values. The values of variables Q and R remain at T or F for two assignments and one assignment of logical values respectively. The value of variable R changes more frequently than the value of variable Q, and that of Q more frequently than that of P, The number of times the kth logical variable remains at a constant truth value can be easily computed and is denoted by BASE[K]. In the case under discussion, we have three variables, and the values can be computed as BASE[K] = 20» =k = 1,2,3 where we have associated BASE[1], BASE[2], and BASE[3] with variables P,Q, and R respectively. In addition to computing the BASE elements, we also need to know the number of assignments which remain to be generated with a particular logical variable remaining at the same value. For example, if we had already generated the assignments TTT and TTF, then variable P would remain at its present value of T throughout the generation of the next two assignments. This in- formation is stored in an element denoted by LENGTH[K]. For variable P, LENGTH(L1] would have a value of 2 after generation of TTT and TTF. The LENGTH values associated with variables P, Q, and R are initially the same as their corresponding BASE values. Therefore, initially LENGTH[k] = BASE[k] k= 1,2,3 Every time an assignment is generated, each element of LENGTH is decremented by 1. When the LENGTH value associated with a variable becomes zero, then the truth value of that variable is negated, and the LENGTH value is reset to the BASE value. The algorithm for the generation of such assignments can now be precisely formulated. Table 1-27 P @ R T T T\|—BASEI3] Tr Tr P BASE\\}— Tr F T T F F F T Tr BASE{2} ——— F T F F F T F F F 1-2 connectives 17 Algorithm NEXT Given n logical variables having values stored in CASE[1), CASE[2], ..., CASE[n] and two vectors BASE and LENGTH each having n elements, it is required to generate the next assignment of truth values for these variables. 1 [Initialize counter] Set k— 1. 2 [Decrement LENGTH([K]] Set LENGTH[k] — LENGTH[k] — 1. 3 [Negate variable and reset LENGTH ([k]?] If LENGTH(k] = 0 then set CASE[k] — \CASE(k] and LENGTH(k] — BASE[K]. 4 [Increment counter] Set k —k + 1. If k < x then go to step 2; other- wise Exit. Mt A program for algorithn NEXT is given in Fig. 1-2.1. The subroutine has the four parameters CASE, N, BASE, and LENGTH. All parameters except N are arrays. The logical array CASE contains an assignment of truth values for the logical variables from which the subroutine is to generate a new assignment of values. l'or example, for the case of three logical variables, CASE(1), CASE(2), and CASE(3) could be associated with the variable names P, Q, and 2 respec- tively. The new assignment of truth values is returned to the main program via the logical array CASE. Let us now consider the problem of constructing a truth table for a state- ment formula, The following straightforward algorithm uses the various logical arrays such as CASE, BASE, and LENGTH which were discussed in algorithm NEXT. Algorithm TRUTH Givena statement formula in n variables and subalgorithm NEXT which generates a new assignment of truth values, it is required to con- struct a truth table for the given statement formula. 1 [Initialize] Repeat for k = 1,2,...,n: Set BASEL] — 26-6, LENGTH{k] — BASE[k), and CASE[K] < F. Set i — 1 and print headings for the truth table. 2 [Evaluate statement] Substitute the logical values in array CASE into the statement formula. Print the values in array CASE and the value of the statement. & [Obtain next assignment for variables] Invoke subalgorithm NEXT. SUBROUTINE NEXTCASE,N»BASE sLENGTH) © GENERATE THE NEXT ASSIGNMENT OF LOGICAL VALUES. LOGICAL CASEIN) INTEGER BASFIN),LENGTHIND OO 1K = ten LENGTHIK) = LENGTH(K) - 1 TFCLENGTH(K) .NE%O) GO TO L CASEIKD = LENGTHIK) = 8A CONTINUE FIGURE 1-2.1 Program for algorithm NEXT, 18 MATHEMATICAL Logic 4 [Increment counter] Set ii + 1. If i < 2" then go to step 2; other- wise Exit Mil The FORTRAN program for the algorithm is given in Fig. 1-2.2. As an example, the formula TVUPAQ) V (RY P) was used in the program. The program consists of a main program, a subroutine, and a function. The subroutine NEXT, given in Fig. 1-2.1, generates an assign- ment each time it is invoked. The function LOGIC is very simple, and its purpose is to generate a single truth value for the statement formula each time the func- tion is invoked. The number of logical variables in the given statement formula and their associated values are passed to the function LOGIC by using the in- teger variable N and the logical vector CASE respectively. For our example, the variables P, Q, and 2 are denoted in the program by the subscripted variables CASE(1), CASE(2), and CASE(3) respectively. Each time the main program needs a new assignment of truth values for the variables, it calls on procedure NEXT after which the function LOGIC is invoked to evaluate the statement formula for this new assignment of values. The main program computes the BASE and LENGTH vectors for subroutine NEXT. Initially, all logical variables are set to false, which enables subroutine NEXT to obtain the next assignment. Note that all variables could have been set to true instead. This assignment, of course, would have produced a truth table with the same information as shown in the sample output but in a different order. 1-2.6 Conditional and Biconditional If P and Q are any two statements, then the statement P — & which is read as “If P, then Q” is called a conditional statement. The statement P — @ has a truth value F when Q has the truth value F and P the truth value 7; otherwise it has the truth value 7. The conditional is defined by Table 1-2.8. The statement P is called the antecedent and Q the consequent in P > Q. Again, according to the definition, it is not necessary that there be any kind of relation between P and Q in order to form P > Q. Table 1-28 TRUTH TABLE FOR CONDITIONAL P Q PO T T e T PF F F T T F F tT 1-2 connzcrives 19 MAINLINE THIS PROGRAM EVALUATES A STATEMENT FORMULA AND GENERATES I7S TRUTH TABLE, VARTABLES TITLE: TITLE FOR THE STATEMENT FORMULA NAME VARTABLE NAMES VALUE: LOGICAL VALUE OF STATEMENT FORMULA NUMBER: NUMBER OF ROWS IN THE TRUTH TABLE aaananaaaar PECLAPATIANS AND TITLES INTEGER®2 NAME(3)/#P9, 908, 1RO/ REALSS TITLE(G1/*eNOTs (Poy AND. Q)60! LOGICAL CASE(10),LOGIC, VALUE INTEGER BASE(19) sLENGTH(LO) C INITIALIZE BASE, LENGTH, CASE, Ny AND NUMBERS N23 NUMBER = 2 #0 N on i K = IyN BASELK) = 2 #* IN - KD LENGTH(K) = BASE(K) CASE(K) = eFALSES 1_ CONTINUE © OUTPUT HEADINGS WRITEC6,10) TITLE 1D FORMAT (TL? (13%, " VARTABLES', 13%, 448) WRITE(6,20) NAME 20 FORMATC® F,AX,4CASE 1 2 3% y/y# %y13Xy3UA2¢ 2K) y21Ky *VALUE? 9) FIND VALUE OF THE STATEMENT FORMULA, OUTPUT TRUT4 VALUES, AND GENERATS NEW TRUTH VALUES FOR THE LOGICAL VARIABLES. 90 2-1 2 1.NUNRER VALUS = LOGICICASE.ND WRITE(6,39) (CASECK) 9K = 1) NPs VALUE 3D FORMATE® 4 13X53(L1 43K) 23K oL LD CALL NEXTECASE Ny BASE, LENGTH) 2 CONTINUE stop end RetReO%e eh) ao LOGICAL FUNCTION LOGICICASE WN) © THIS FUNCTION DFFINFS THE STATEMENT FORMULA TO BE EVALUATED. LOGICAL CASEEND LOGIC = eNOTs(CASECL) sANDeCASE(2) ORs (CASE 3) oORSCASELIDD RETURN END. VARIABLES eNOT.(P6AND.W) OR (ROR.PY cased 2) 3 Poo k VALUE eo oF oF r FoF T T FoT F T For f T TOF F T Tor T Tt TOT € T ro4rr T FIGURE 1-2.2 Program for generating truth tables—mainline and func- tion LOGIC. 20 MATHEMATICAL LoGIc EXAMPLE 1 Express in English the statement P — Q where P: The sun is shining today. Q24+7>4. soLurion If the sun is shining today, then 2+ 7 > 4. Mf The conditional often appears very confusing to a beginner, particularly when one tries to translate a conditional in English into symbolic form. A variety of expressions are used in English which can be appropriately translated by the symbol —. It is customary to represent any one of the following expressions by PQ: 1 Qis necessary for P. 2 P is sufficient for Q. 3 QifP. 4 Ponlyif@ 5 P implies Q. We shall avoid the translation “implies.” Although, in mathematics, the statements “If P, then Q” and “P implies (”' are used interchangeably, we want to use the word “implies” in a different way. In our everyday language, we use the conditional statements in a more restricted sense. It is customary to assume some kind of relationship or implica- tion or feeling of cause and effect between the antecedent, and the consequent in using the conditional. For example, the statement “If I get the book, then I shall read it tonight” sounds reasonable because the second statement “I shall read it (the book) tonight” refers to the book mentioned in the first part of the state- ment. On the other hand, a statement such as “If I get the book, then this room is red” does not make sense to us in our conventional language. However, ac- cording to our definition of the conditional, the last statement is perfectly ac- ceptable and has a truth value which depends on the truth values of the two statements being connected. The first two entries in Table 1-2.8 are similar to what we would expect in our everyday language. Thus, if P is true and @ is true, then P — Q is true. Similarly, if P is true and Qs false, then “If P, then Q” appears to be false. Con- sider, for example, the statement “If I get the money, then I shall buy the car.” If I actually get the money and buy the car, then the statement appears to be correct or true. On the other hand, if I do not buy the car even though I get the money, then the statement is false. Normally, when a conditional statement is made, we assume that the antecedent is true. Because of this convention in English, the first two entries in the truth table do not appear strange. Referring to the above statement again, if I do not get the money and J still buy the car, it is not so clear whether the statement made earlier is true or false. Also, if I do not buy the car and I do not get the money, then it is not intuitively clear whether the statement made is true or false, It may be possible to justify entries in the last two rows of the truth table by considering special examples or even by emphasizing certain aspects of the statements given in the above examples. How- ever, it is best to consider Table 1-2.8 as the definition of the conditional in which the entries in the last two rows are arbitrarily assigned in order to avoid any am- 1-2 connectives 21 biguity. Any other choice for the last two entries would correspond to some other connective which has either been defined or will be defined. In general, the use of “If ..., then ...”” in English has only partial resemblance to the use of the conditional — as defined here. EXAMPLE 2 Write the following statement in symbolic form. If either Jerry takes Calculus or Ken takes Sociology, then Larry will take English. souution Denoting the statements as J: Jerry takes Calculus. K: Ken takes Sociology. L: Larry takes English the above statement can be symbolized as WV K) SL Md EXAMPLE 3. Write in symbolic form the statement, The crop will be destroyed if there is a flood. soLution Let the statements be denoted as €: The erop will he destroyed. F: There is a flood. Note that the given statement uses “if” in the sense of “If ..., then ....” It is better to rewrite the given statement as “If there is a flood, then the erop will be destroyed.” Now it is easy to symbolize it-as FOC Hd} EXAMPLE 4 Construct the truth table for (P > Q) A (QP). soLuTion See Table 9. Note that the given formula has the truth value T whenever both ? and Q have identical truth values, M1) If P and Q are any two statements, then the statement /’? = Q, which is read as “P if and only if Q” and abbreviated as “7 iff Q,” is called a biconditional statement. The statement /’ = Q has the truth value T whenever both / and Table 1-2.9 PQ PQ Q>P (P>0)A QP) ror v T T F F T F F T T F F F F fT T T 22 MATHEMATICAL LocIc Table 1-210 TRUTH TABLE FOR BICONDITIONAL P @ Pee Tr T T r F F F T F F F r Table 1-2.11 P @ PAQ “PAQ TP 10 TPVT@ WPA) (7PV 70) rrr P F F F rT T F F ¥: F r T T For F T Tr F Tr Tr PF F F Tr £ e Tr T Q have identical truth values. Table 1-2.10 defines the biconditional. The state- ment P = Q is also translated as “P is necessary and sufficient for Q.”” Note that the truth values of (P + Q) A (Q— P) given in Table 1-2.9 are identical to the truth values of P = Q defined here. EXAMPLE 5 Construct the truth table for the formula TP AQ =P Vv 1) soLuTion See Table 1-2.11. Note that the truth values of the given for- mula are T for all possible truth values of P and Q. Wt EXERCISES 1-2.6 1 Show that the truth values of the following formulas are independent of their com- ponents. (a) (PA (P>Q)) > @ (0) (PAQeBCIPV Q) ‘c) ((P->Q) A (Q— R)) > (PR) (a) (P2Q)= (PA Q) V CPA 710)) # Construct the truth tables of the following formulas. (a) (QA (P>Q))>P () “UPV (QA R)) = (PV Q) A (PV R)) 3 A connective denoted by V isdefined by Table 1-2.12. Find a formula using P, Q, and Rseanectivs A, V,, and —] whose truth values are identical to the truth values of PVa@ 4 Given the truth values of P and Q as T and those of # and S as F, find the truth values of the following: (a) CPA 0) VR) V (QP) (BV 18)) (o) (P= R) A(T 8) (ce) (PV (Q-+ (RA TP))) = QV 1S) 1-2 connectivrs 23 Table 1-212 P Q Pve T + F r F T F T T F F F 1-2.7 Well-formed Formulas The notion of a statement formula has already been introduced. A statement formula is not a statement (although, for the sake of brevity, we have often called it a statement) ; however, a statement can be obtained from it by replacing the variables by statements. A statement formula is an expression which is a string consisting of variables (capital letters with or without subscripts), parentheses, and connective symbols. Not every string of these symbols is a formula. We shall now give a recursive definition of a statement formula, often called a well-formed formula (wf). A well-formed formula can be generated by the following rules: 1 Astatement variable standing alone is a well-formed formula. 2 If A is a well-formed formula, then “]A is a well-formed formula. 8 IfA ard Bare well-formed formulas, then (A A B),(A V B), (A > B), and (A = B) are well-formed formulas. 4 A string of symbols containing the statement variables, connectives, and parentheses is a well-formed formula, iff it can be obtained by finitely many applications of the rules 1, 2, and 3. According to this definition, the following are well-formed formulas: “UP AQ) UPVQ (Pa (PV Q)) (P>(Q@>R)) (PQ) A (Q>R)) &(P>R)) The following are not well-formed formulas. 1 “PA Q. Obviously P and Q are well-formed formulas. A wif would be either (TP A Q) or 1(P A Q). 2 (P+Q) > (A Q). This is not a wi because A Q is not. 3 (PQ. Note that (P +@Q) isa wi. 4 (P AQ) + Q). The reason for this not being a wf is that one of the pa- rentheses in the beginning is missing, ((P A Q) > Q) isa wff, while (P A Q)>Q is still not a wif. It is possible to introduce some conventions so that the number of paren- theses used can be reduced. In fact, there are conventions which, when followed, allow one to dispense with all the parentheses. We shall not discuss these conven- tions here. For the sake of convenience we shall omit the outer parentheses. Thus we write P A Qin place of (P A Q), (P A Q) > Qin place of ((P A Q) > Q), and ((P>Q) A (Q—> R)) = (P > R) instead of (((PQ) A (Q—>R)) & (P = R)). Since the only formulas we will encounter are well-formed formulas, we will refer to well-formed formulas as formulas.

You might also like