ebook img

Logics for Computer Science PDF

375 Pages·2003·1.464 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Logics for Computer Science

Logics For Computer Science Arindama Singh Department of Mathematics Indian Institute of Technology Madras [email protected] Logics For Computer Science Contents Preface v 1 Propositional Logic 1 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Syntax of PL . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Semantics of PL . . . . . . . . . . . . . . . . . . . . . . . . 12 1.4 Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 1.5 Normal Forms . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.6 Some Applications . . . . . . . . . . . . . . . . . . . . . . . 35 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2 First Order Logic 51 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.2 Syntax of FL . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.3 Preparing for Semantics . . . . . . . . . . . . . . . . . . . . 59 2.4 Semantics of FL . . . . . . . . . . . . . . . . . . . . . . . . 64 2.5 Some Useful Consequences . . . . . . . . . . . . . . . . . . . 77 2.6 Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 2.7 Normal Forms . . . . . . . . . . . . . . . . . . . . . . . . . . 87 2.8 Herbrand Interpretation . . . . . . . . . . . . . . . . . . . . 97 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 3 Resolution 115 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 3.2 Resolution in PL . . . . . . . . . . . . . . . . . . . . . . . . 116 3.3 Unification of Clauses . . . . . . . . . . . . . . . . . . . . . 127 3.4 Extending Resolution . . . . . . . . . . . . . . . . . . . . . 134 3.5 Resolution for FL . . . . . . . . . . . . . . . . . . . . . . . . 139 3.6 Horn Clauses in FL . . . . . . . . . . . . . . . . . . . . . . . 142 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 iii iv Contents 4 Proofs in PL and FL 152 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 4.2 Axiomatic System PC . . . . . . . . . . . . . . . . . . . . . 152 4.3 Axiomatic System FC . . . . . . . . . . . . . . . . . . . . . 165 4.4 Adequacy and Compactness . . . . . . . . . . . . . . . . . . 176 4.5 Natural Deduction . . . . . . . . . . . . . . . . . . . . . . . 184 4.6 Gentzen Systems . . . . . . . . . . . . . . . . . . . . . . . . 194 4.7 Analytic Tableau . . . . . . . . . . . . . . . . . . . . . . . . 204 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 5 Program Verification 233 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 5.2 Issue of Correctness . . . . . . . . . . . . . . . . . . . . . . 235 5.3 The Core Language CL . . . . . . . . . . . . . . . . . . . . 238 5.4 Partial Correctness . . . . . . . . . . . . . . . . . . . . . . . 242 5.5 Hoare Proof and Proof Summary . . . . . . . . . . . . . . . 252 5.6 Total Correctness . . . . . . . . . . . . . . . . . . . . . . . . 259 5.7 The Predicate Transformer wp . . . . . . . . . . . . . . . . 263 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 6 Modal Logics 280 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 6.2 Syntax and Semantics of K . . . . . . . . . . . . . . . . . . 282 6.3 Axiomatic System KC . . . . . . . . . . . . . . . . . . . . . 294 6.4 Other Proof Systems for K . . . . . . . . . . . . . . . . . . 301 6.5 Other Modal Logics . . . . . . . . . . . . . . . . . . . . . . 312 6.6 Various Modalities . . . . . . . . . . . . . . . . . . . . . . . 320 6.7 Computation Tree Logic . . . . . . . . . . . . . . . . . . . . 325 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 7 Some Other Logics 336 7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 7.2 Intuitionistic Logic . . . . . . . . . . . . . . . . . . . . . . . 337 7.3 L ukasiewicz Logics . . . . . . . . . . . . . . . . . . . . . . . 340 7.4 Probabilistic Logic . . . . . . . . . . . . . . . . . . . . . . . 345 7.5 Possibilistic and Fuzzy Logic . . . . . . . . . . . . . . . . . 346 7.6 Default Logic . . . . . . . . . . . . . . . . . . . . . . . . . . 349 7.7 Autoepistemic Logic . . . . . . . . . . . . . . . . . . . . . . 352 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 References 356 Index 362 Preface Each chapter in this book has an introduction, the first section. But there is no introduction to the book itself. So, let me use the mask of the Preface for this purpose. Of course, a plain introduction to the book is just to place the book in your hand; but while you are reading it, you yourself have already done that. Well done! This is the way I will be talking to you throughout. I will ask you to do exercises on the spot, often waiting for you up to some point, and then give you a hint to proceed. It is something like the following commercial for the book: I would like to ask you three questions, would you answer them with a plain ‘Yes’ or ‘No’? Good, you have answered ‘Yes’, whatever be the reason. But see, that was my first question. Would you answer the same to the second as to the third? Very good, you have answered ‘Yes’ again; of course, it does not matter. If you have not bought a copy of this book, are you going to buy it soon? Look, if you have answered ‘Yes’ to the second question, you are also answering ‘Yes’ to the third, and if you have answered ‘No’ to the second, you are not answering ‘No’ to the third, i.e., your answer to the third is undoubtedly, ‘Yes’. Excellent. That is the end of the commercial. You have participated well in the commercial; I hope you will be with me throughout. It is easy to learn logic and easier to teach it; that is the spirit of this book. I would not reveal what is logic; you will discover it eventually. My aim is to equip you with the logical methods so that when you take up computer science as your profession, you will feel like a fish in water. A warning: though the book is ideal for self-learning, it would not replace a teacher. At least on one count: you can ask a question to your teacher and, hopefully, he1 will give you an answer, or you will be inspired 1Themasculinegenderisusedthroughoutthebooknotbecauseofsomechauvinistic reasons, as it is easy to do that. It is easy to write ‘he’ rather than ‘she’ or ‘one’ or ‘a person’ or ‘a human being’ etc. You need not be offended by it. v vi Preface by him for finding your own answer; the book cannot do that always. If you are a teacher, you may not need to learn all the topics, for you had probably learnt them. But you can really teach logic better by helping your students in the exercises. You can supplement the book with more computer science applications which I had to omit, for it is already a somewhat lengthy book. It is ideal for a two-semester course for not so advanced students. But you can cover it in one semester2 by omitting certain proof procedures. In Chapter 1, you will find the logic of statements. The approach is semantic. Thesemanticconsiderationsgiverisetothecalculationalmethod of proof quite naturally. Calculations have been used very informally for proving valid formulas just as you solve problems in school algebra. All the metaresults have been discussed except compactness. That is done via proof theory, again, for ease. In Chapter 2, a similar approach is taken for thelogicofpredicatesorrelations, morecommonlyknownasthefirstorder logic. Thefirstorderlogicdiscussedhereincludestheequalityrelation,and nopreferenceisgiventoonewithoutequality,becauseapplicationsdemand it. This chapter also deals with the Herbrand’s theorems without waiting for the resolution method. The resolution method is the topic of Chapter 3. Chapter 4 is exclusively meant for various proof techniques. In a one- semester course, you may go for only one proof method. Or, you may do one of the proof methods formally in detail and present others in one lecture each. In Chapter 5, you come across a fundamental area of computer science, theprogramverification. Itisalsooneofthemostusefulapplicationsoffirst order logic. You should not stop just after that; you must hunt for some more materials and pursue the topic a bit further. You must have a similar approach to the model checking algorithms that have been introduced in Chapter 6 as an application of modal logics. This chapter gives a very comprehensive account of modal logics used in computer science. It does cover the essential ingredients leaving one: decidability issues, for which you may look through the References. Similarly, Chapter 7 introduces the so-called nonstandard logics which are upcoming, but not entirely new. We discuss only those nonstandard logics that have general frameworks yet; the list is not exhaustive. You are led through the chapters towards logic engineering, an activity that is becoming increasingly important in current research in computer science. The approach of the book is mathematical, in the sense that it involves a continual interplay between the abstract and the concrete. The yearning forunderstandingtheconcretephenomenagivesrisetoabstractionsandto 2It takes around 60 lectures to complete the book. In fact, it is developed from my notes for a logic course offered to Engineering undergraduates at IIT Madras taking theoretical computer science as their minor subject. Some of the postgraduate students in Mathematics also credit the course as an elective. Preface vii understand the abstract, concrete phenomena are a necessity. The typical feeling in any concrete problem is that when you abstract it, an existence of a solution is an opaque mystery. The concrete problems do not come with a label that such and such method would be applicable. It is you who may think of applying an existing method to solve it. Often, patient and continuous involvement with the problems help you to gradually gain insight, leadingtoasolution. So, bepatientandpersistent, relyonyourself as far as possible; start the journey now. I have to pause here for a second. I would like to thank all those who have made this happy journey of yours possible. Though the book has taken shape now, there has been a continual effort throughout. There must be many good reasons for this, the most basic of all these being my interest in higher studies. I thank my parents and my school teacher Mr. Rupakar Sarangi who nourished me physically and mentally by keeping me fit for higher studies. I thank my wife Archana for continuing in a simi- lar vein after our marriage. She, along with my children, Anindya Ambuj and Ananya Asmita, did suffer a lot due to my post-marriage engagement with this book. I thank them for their patience and encouragement. I am indebted to my friend and logic tutor Professor Chinmoy Goswami of the University of Hyderabad. My students helped me considerably to learn logic; in a way, this book is a reward for that. I thank my colleague Dr.M.Thamban Nair of IIT Madras for encouraging me to bring out the book from some scratches on a note book. I also thank the Publishers, Prentice Hall of India, particularly, Mr.K.C.Devasia for his expert guid- ance and the production team for their assistance. Any constructive suggestions for improving the contents would be most welcome. These may be emailed to me at [email protected]. Arindama Singh 1 Propositional Logic 1.1 Introduction Logic is all about how an object follows from other objects. In Proposi- tional logic, our objects are propositions such as Bapuji was indeed a Mahatma. The title of a book on logic could be mis-spelt. Five men cannot have eleven eyes. Buddha’s original name was Arindama. Alexander the great did not set foot in India. The woman who committed the crime did not have three legs. No bachelor is married. Some unmarried men get married. Propositions are declarative sentences which may be asserted to be true or false. It is quite possible that you may not be able to say for certain whetheragivenpropositionistrue(orfalse), withoutgoingtoitsmeanings or external factors. But that does not really matter. All that we need is that it is either true or false. The so-called conjectures or open problems are propositions, the truth of which you do not know yet. For example, Goldbach’s conjecture: “Every even number bigger than 2 is a sum of two prime numbers”, or the P 6= NP: “There is at least one nondeterministic polynomial time solvable problem which is not deterministic polynomial time solvable”. As of now, we do not have any way of showing the truth or falsity of these propositions. However, each of them is either true or false. Note that we are not defining here what a proposition is. In fact, we will not even attempt to do so. We are only getting familiarized with the kind of objects in question. The sentences which are not propositions include questions, orders, ex- clamations, etc., for which we may not like to associate a truth value. We do not know how to say whether “Are you OK?” is true or false. Similarly, we may not assert that “How beautiful is the morning sky!” is true. Our building blocks here are propositions; we will not try to go beyond them. Itisnotourconcerntodeterminewhether‘eachbachelorismarried’, 1 2 Propositional Logic for we do not know the meanings of the words uttered in the proposition. This is so because our units here are propositions and nothing less (or more). However, we seem to know that two propositions such as “I know logic” and “You know logic” can be composed to get another proposition such as “I and you know logic”. We are only interested in propositions and how they are composed to yield other propositions. This is what we mean when we say that propositions are our building blocks. Thus we are interested in the forms rather than the meanings of propositions. Since propositions can be true or false, we must know how to assign truth values to the compound propositions. If indeed I like logic and you like logic, then we must agree that the proposition“Iandyoulikelogic”istrue. Butwhatabouttheproposition“I likelogicandyoulikelogicoryoudonotlikelogic”? Thisisproblematic,for wedonotknowexactlyhowthiscompoundpropositionhasbeencomposed of or formed. We do not know which way to parse it: (I like logic and you like logic) or (you do not like logic) OR (I like logic) and (you like logic or you do not like logic) We must use some such device, say, use of parentheses for disambiguat- ing compound propositions. Further, we must know the connectives like ‘and’, ‘or’, as used above. It is enough to start with some commonly used connectives. If need arises, we will enrich our formalization later by adding new ones. Furthermore, we have the responsibility to say what ‘follows from’ means formally. 1.2 Syntax of PL For any simple proposition, called a propositional variable, we will use any of the symbols p ,p ,... For connectives ‘not’, ‘and’, ‘or’, ‘if ... then 0 1 ...’, ‘if and only if’, we use the symbols ¬,∧,∨,→,↔, respectively; their names are negation, conjunction, disjunction, conditional, biconditional. We use the parentheses ‘)’ and ‘(’ as punctuation marks. We also have the special propositions > and ⊥, called propositional constants, which standforpropositionswhichare‘true’and‘false’,respectively. Bothpropo- sitional variables and propositional constants are commonly called atomic propositions. So, the alphabet of Propositional Logic, PL, is the set {),(,¬,∧,∨,→,↔,>,⊥,p ,p ,p ,...} 0 1 2 consisting of all these symbols. Any expression over this alphabet is a string of symbols such as (¬p → ()∧p ∨, ¬p )(→ ∨, (¬p → p ) 0 1 100 0 1 Only the last one of these is a propositional formula or a proposition. In Syntax of PL 3 fact, we are interested only in such expressions. Now how to define them? Here are some of the ways of defining the set of all propositions, PROP. Definition 1.1 The set of all propositions, PROP is the smallest set of expressions such that {>,⊥,p ,p ,...} ⊆ PROP, and whenever x,y ∈ 0 1 PROP, the expressions ¬x,(x ∧ y),(x ∨ y),(x → y),(x ↔ y) are also in PROP. The ‘smallest’ is in the sense of the relation ⊆, i.e., A is smaller than B iff (if and only if) A ⊆ B. The set PROP can also be defined inductively (or recursively). Definition 1.2 PROP(0) = {p ,p ,...}∪{>,⊥} 0 1 PROP(i+1) = PROP(i)∪{¬x,(x∧y),(x∨y),(x → y), (x ↔ y) : x,y ∈ PROP(i)} PROP = ∪i∈N PROP(i) Can you see that both the definitions above define the same set PROP? What are the sets PROP(i)? PROP(0)containsallatomicpropositionswhichdonotcontainanycon- nective. PROP(1) contains all propositions having a single occurrence of a connective, along with those having no connectives. In general, PROP(i) contains all propositions having i or less number of occurrences of connec- tives. It is of course clear that any proposition has only a finite number of occurrences of connectives,and thus, it must be in some PROP(i). Now, can you prove it? What is there to prove? Well, if PROP(i) has been defined by Definition 1.2, PROP has been defined by Definition 1.1, and if PROP0 = ∪i∈N PROP(i), then you must show that PROP ⊆ PROP0 and PROP0 ⊆ PROP. Do the following exercise before reading further. Exercise 1.1 Show that PROP = PROP0. We see that {>,⊥,p ,p ,...} ⊆ PROP(0) ⊆ PROP0. For x,y ∈ PROP0, 0 1 we also see that x ∈ PROP(i) and y ∈ PROP(j) for some i,j ∈ N. Then, bothx,y ∈PROP(k),wherek = max(i,j). Thisshowsthattheexpressions ¬x,(x∧y),(x∨y),(x → y),(x ↔ y) are in PROP(k+1). Since PROP(k+1) ⊆PROP0,wheneverx,y ∈PROP0,allof¬x,(x∧y),(x∨y),(x → y),(x ↔ y) are also in PROP0. Since PROP is the smallest set of expressions with this property, we have PROP ⊆ PROP0. To see the converse, it is enough to see that PROP(i) ⊆ PROP for each i ∈ N. This is proved by induction on i. To start with, we have al- readyseenthatPROP(0) ⊆PROP.Assumethat(theinductionhypothesis) PROP(i) ⊆ PROP. Now let w ∈ PROP(i+1). By Definition 1.2, w is one of ¬x,(x∧y),(x∨y),(x → y),(x ↔ y), for some x,y ∈ PROP(i). Due to the induction hypothesis, x,y ∈ PROP. By Definition 1.1, the expressions ¬x,(x ∧ y),(x ∨ y),(x → y),(x ↔ y) are in PROP. That is, w ∈PROP, proving that PROP(i+1) ⊆ PROP. This completes the induction proof. We summarize the above discussion in the following statement.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.