Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsoned.co.uk Pearson Education Limited 2014 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a licence permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6 10 Kirby Street, London EC1N 8TS. All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners. ISBN 10: 1-292-02420-8 ISBN 13: 978-1-292-02420-2 British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library Printed in the United States of America
First-Order Logic 20 Arithmetic assertions can be written in first-order logic with the predicate symbol <, the function symbols + and, and the constant symbols 0 and 1. Additional predicates can also be defined with biconditionals. a. Represent the property x is an even number. b. Represent the property x is prime. c. Goldbach s conjecture is the conjecture (unproven as yet) that every even number is equal to the sum of two primes. Represent this conjecture as a logical sentence. 21 Equality can be used to indicate the relation between a variable and its value. For instance, WA = red means that Western Australia is colored red. Representing this in firstorder logic, we must write more verbosely ColorOf(WA) = red. What incorrect inference could be drawn if we wrote sentences such as WA = red directly as logical assertions? 22 Write in first-order logic the assertion that every key and at least one of every pair of socks will eventually be lost forever, using only the following vocabulary: Key(x), x is a key; Sock(x), x is a sock; Pair(x,y), x and y are a pair; Now, the current time; Before(t 1,t 2 ), time t 1 comes before time t 2 ; Lost(x,t), object x is lost at time t. 23 For each of the following sentences in English, decide if the accompanying first-order logic sentence is a good translation. If not, explain why not and correct it. (Some sentences may have more than one error!) a. No two people have the same social security number. x,y,n Person(x) Person(y) [HasSS#(x,n) HasSS#(y,n)]. b. John s social security number is the same as Mary s. n HasSS#(John,n) HasSS#(Mary,n). c. Everyone s social security number has nine digits. x,n Person(x) [HasSS#(x,n) Digits(n,9)]. d. Rewrite each of the above (uncorrected) sentences using a function symbol SS# instead of the predicate HasSS#. 24 Represent the following sentences in first-order logic, using a consistent vocabulary (which you must define): a. Some students took French in spring 2001. b. Every student who takes French passes it. c. Only one student took Greek in spring 2001. d. The best score in Greek is always higher than the best score in French. e. Every person who buys a policy is smart. f. No person buys an expensive policy. g. There is an agent who sells policies only to people who are not insured. 324
First-Order Logic X 0 Y 0 Ad 0 Z 0 X 1 Y 1 Ad 1 Z 1 + X 3 Y 3 X 2 Y 2 X 1 Y 1 X 0 Y 0 X 2 Y 2 Ad 2 Z 2 Z 4 Z 3 Z 2 Z 1 Z 0 X 3 Y 3 Ad 3 Z 3 Z 4 Figure 8 A four-bit adder. Each Ad i is a one-bit adder, as in Figure 6. h. There is a barber who shaves all men in town who do not shave themselves. i. A person born in the UK, each of whose parents is a UK citizen or a UK resident, is a UK citizen by birth. j. A person born outside the UK, one of whose parents is a UK citizen by birth, is a UK citizen by descent. k. Politicians can fool some of the people all of the time, and they can fool all of the people some of the time, but they can t fool all of the people all of the time. l. All Greeks speak the same language. (Use Speaks(x,l) to mean that person x speaks language l.) 25 Write a general set of facts and axioms to represent the assertion Wellington heard about Napoleon s death and to correctly answer the question Did Napoleon hear about Wellington s death? 26 Extend the vocabulary from Section 4 to define addition for n-bit binary numbers. Then encode the description of the four-bit adder in Figure 8, and pose the queries needed to verify that it is in fact correct. 27 Obtain a passport application for your country, identify the rules determining eligibility for a passport, and translate them into first-order logic, following the steps outlined in Section 4. 28 Consider a first-order logical knowledge base that describes worlds containing people, songs, albums (e.g., Meet the Beatles ) and disks (i.e., particular physical instances of CDs). The vocabulary contains the following symbols: CopyOf (d, a): Predicate. Disk d is a copy of album a. Owns(p, d): Predicate. Person p owns disk d. Sings(p, s, a): Album a includes a recording of song s sung by person p. Wrote(p, s): Person p wrote song s. McCartney, Gershwin, BHoliday, Joe, EleanorRigby, TheManILove, Revolver: Constants with the obvious meanings. 325
First-Order Logic Express the following statements in first-order logic: a. Gershwin wrote The Man I Love. b. Gershwin did not write Eleanor Rigby. c. Either Gershwin or McCartney wrote The Man I Love. d. Joe has written at least one song. e. Joe owns a copy of Revolver. f. Every song that McCartney sings on Revolver was written by McCartney. g. Gershwin did not write any of the songs on Revolver. h. Every song that Gershwin wrote has been recorded on some album. (Possibly different songs are recorded on different albums.) i. There is a single album that contains every song that Joe has written. j. Joe owns a copy of an album that has Billie Holiday singing The Man I Love. k. Joe owns a copy of every album that has a song sung by McCartney. (Of course, each different album is instantiated in a different physical CD.) l. Joe owns a copy of every album on which all the songs are sung by Billie Holiday. 326
INFERENCE IN FIRST-ORDER LOGIC From Chapter 9 of Artificial Intelligence: A Modern Approach, Third Edition. Stuart Russell and Peter Norvig. Copyright 2010 by Pearson Education, Inc. Published by Prentice Hall. All rights reserved. 327
INFERENCE IN FIRST-ORDER LOGIC In which we define effective procedures for answering questions posed in firstorder logic. Sound and complete inference can be achieved for propositional logic. In this chapter, we build on that to obtain algorithms that can answer any answerable question stated in first-order logic. Section 1 introduces inference rules for quantifiers and shows how to reduce first-order inference to propositional inference, albeit at potentially great expense. Section 2 describes the idea of unification, showing how it can be used to construct inference rules that work directly with first-order sentences. We then discuss three major families of first-order inference algorithms. Forward chaining and its applications to deductive databases and production systems are covered in Section 3; backward chaining and logic programming systems are developed in Section 4. Forward and backward chaining can be very efficient, fibut are applicable only to knowledge bases that can be expressed as sets of Horn clauses. General first-order sentences require resolution-based theorem proving, which is described in Section 5. 1 PROPOSITIONAL VS. FIRST-ORDER INFERENCE This section and the next introduce the ideas underlying modern logical inference systems. We begin with some simple inference rules that can be applied to sentences with quantifiers to obtain sentences without quantifiers. These rules lead naturally to the idea that first-order inference can be done by converting the knowledge base to propositional logic and using propositional inference, which we already know how to do. The next section points out an obvious shortcut, leading to inference methods that manipulate first-order sentences directly. 1.1 Inference rules for quantifiers Let us begin with universal quantifiers. Suppose our knowledge base contains the standard folkloric axiom stating that all greedy kings are evil: x King(x) Greedy(x) Evil(x). 328