2 LOGIC 2. Propositional Calculus 2.. Definitions This concerns formulae or propositions, B, C,... which are statements which are True or False. If and B are formulae then the following are also formulae: Negation (NOT) Conjunction (ND) B Disjunction (OR) Β Unilateral Implication B Equality = B (same as B and B sometimes called Bilateral Implication) If a formula includes one or more of these operations it is called a composite formula; otherwise it is an atomic formula These can be defined explicitly in terms of truth tables. B B B =B B t t f t t t t t f f f t f f f t t f t f t f f t f f t t one row for each possible combination B is true only if and B are both true B is true if or B is true = B is true if and B have the same value B is true if is true and B is true or if is false and B is true or false. Complex formulae can be obtained by combining formulae and operators. Propositional calculus is concerned only with these formulae and operators, but does not look inside an atomic formula to see if it is true or false. Some formulae are unsatisfiable (never true), e.g. ( ) Some formulae are valid (always true), e.g. ( ) 2.2 Redundancy There is some redundancy in the set of connectives,,, expressed in De Morgan's laws, which are () ( B) equivalent to B (2) ( B) equivalent to B B Venn diagram These can be shown to be true using Venn diagrams or they can be proved using truth tables, e.g. for the st law: B B ( B) B B t t t f f f f t f t f f t f f t t f t f f f f f t t t t So columns 4 and 7 are the same for all possible values of & B. This proves the equivalence ( B) = B. Similarly for the 2nd law. Other examples (mostly obvious) are as follows: = T = F = T = = Commutation B = B B = B ssociation (B C) = ( B) C and similar for Distribution (B C) = ( B) ( C) and similar for & reversed lso ( B) = ( B) = Tautology T = T (the tautology is true for any formula ). T =
2..3 Example Simplify X = (( (B )) (C (D C))) Syntactic approach (B ) = ( B ) de Morgan = ( B) ( ) Distribution = ( B) T = T Tautology C (D C) = C (C D) Commutation = (C C) D ssociation = C D So X = T (C D) = C D In the semantic approach we could build a truth table for all 6 combinations of, B, C and D and show the two columns to be the same (much longer!). 2.4 Implication Some laws concerning implication. ( B) B Modus ponens ( ( B)) B Modus tollens (( B) B) (Syllogism) (( B) (B C)) ( C) Reductio ad absurbum( T) Each infers that if the LHS is t then the RHS is t. Example : it is snowing B : it is cold Modus Tollens states (( B) B) which states that if it is snowing implies it is cold, but it is not cold; then this infers that it is not snowing. Proof of Modus Tollens Use a Truth Table (5) (6) (5) (6) B B B ( B) ( B) t f t f f f t f f t t t t t t t f t f f t f t f t f t t So ((( B) B) ) = t for all and B values. Thus: Modus Tollens is proved. 2.5 NF or Normal Form ll formulas can be reduced to NF (Normal Form) in which the only operators acting on the tomic Formulas are, or. For example ( B C) D (X Y Z W) is in NF. To put in NF we need expressions for B and = B in NF. We can replace B by B (prove from our definition in 2..4 using truth tables) and = B by (( B) (B )) = (( Β) ( B )) Example () ( R (S P)) = (R (S P) = ((R S) (R P) Example (2) ( P Q) (S P) = (P Q) (S P) de Morgan = (P Q) (S P) = (P Q) (P S) Commutation = P (Q S) ssociation 2.2 Predicate Calculus 2.2. Definitions Predicate Calculus looks at the internal structure of formulae, and views these as predicates and a number of arguments. e.g. (i) Water is Wet Wet (Water) (ii) Peter cut the grass with a hook cut (Peter, the grass, a hook) (Note similarity with a semantic set in Chapter 5) In the above "cut" and "wet" are the predicates, the other identifiers are the arguments (or terms), the number being the "arity" of the predicate. rguments may be constants, variables, functions, true, false or other predicates. Constants: 3.459 Variables: Height, Colour Functions: Father(George),Plus(5,6), verage (2.4, 3.6, 5.7, 8.9,... ) The number of arguments of a function is called the arity of the function (similar to a Predicate). Predicates: wet, cut, likes Example: Cut(father(Peter), the grass, a hook, from (2. pm), to (4. pm))
Loves(Son(Peter),Daughter(Maureen)) 2.2.2 Operators Predicates may include the operators of Propositional calculus,,,, = and two others (variable quantifiers) x and x which constrain the variable x in the following formula or predicate. x(p(x)) means "there exists a variable x for which P(x) is true" x(p(x)) means "for all x P(x) is true". (Note: or cannot be constraints on predicates in st order predicate calculus, only on variables). So x must be a variable. [This course is only concerned with st order calculus.] Some relationships (showing that one of and is redundant) (a) x (P(x)) = x( P(x)) (b) x(p(x)) = x ( P(x)) (c) x(p(x) Q(x))= xp(x) xq(x) (d) x(p(x) Q(x))= x P(x) xq(x) Note: x P(x) = y P(y) Examples of domains is called the Existential Operator is called the the Universal Operator 2.2.3 English Sentences More examples (a) Podge is a black cat is a (Podge, cat, colour (black)) (b) If there is snow tomorrow we will go skiing snows (tomorrow) go (we, skiing) (c) Nobody likes exams person (likes (person, exams)) (d) x(admires(jane,x) (good(x) clever (x)) human (x)) ll those Jane admires are good and clever. (e) Some students like studying. student (likes (student, studying)) x (... student (x)) (f) lternatively replace student by the fuzzy quantifier SOME student SOME student (like (student, studying)) This more accurately represents the meaning (see Section 2.3). 2.2.4 Inference Take the famous example: () ll men are mortal x(man(x) mortal(x)) (2) Socrates is a man man (Socrates) So (3) Socrates is mortal mortal(socrates) We obtain (3) from () by noting that the universal operator x allows us to substitute any value in the domain of x and still have a true statement. Thus by substituting Socrates for x we get Man(Socrates) mortal (Socrates); and we infer the truth of (3) using Modus Ponens. This can be seen by writing: Man (Socrates) = Mortal (Socrates) = B If is true and B, then B is true In the above we had to match two statements () and (2). This is often not easy because of the variables in the predicates. (i) In the case of the universal operator,, matching can usually be obtained by a simple substitution, e.g. [Socrates/x] meaning [Socrates replaces x] (This is the notation used for a variable substitution). The algorithm used to determine such a substitution is called "Unification". (ii) In the case of the existential operator,, where possible, it is replaced by the constants which make the predicate true, e.g. x Parent (x, Tom) [meaning x is a parent of Tom] can be replaced by Parent (John, Tom) Parent (Jane, Tom) [meaning Tom has parents John & Jane] However, this is often not possible; for example y( x (Parent (x,y) person (x) person (y))) (Meaning all persons y have a parent x) cannot be replaced by predicates defining the parents of all persons. ristotle s Pile of Stones Stoa of ttalus cropolis, thens 2.3 Fuzzy Logic ristotle was the first to realise that logic based on T or F alone was not sufficient - because a future event E was neither T nor F but had only the potential of being T or F. Pot (E) =.7 (say) on scale [,]. Many events or facts have such fuzzy truth values.
2.3. Fuzzy and Crisp Sets (a) Fuzzy Set Consider the statement: : It is a sunny day. This means that there is a light cloud cover on the day. For what % (x%) cloud cover is True? The answer might be given as x < 3%. But what about 3% cloud cover? Is it still sunny? Obviously there is not a precise percentage separating sunny and not sunny. We overcome this problem by defining a membership function µ (x) for degrees of membership of which might be µ max µ (x) 3% 5% % Cloud Cover The set X defined for µ (x) > is called a fuzzy set. If µ max = and µ min = then the set is normalised. The value µ (x) can be considered as a "possibility", i.e. similar to the probability that belongs to the set X if it has the value x. This equals when x is close to % and drops to zero when x is above 5% in our example. Note µ (x) is not a probability: for example (x)dx µ as it would be for probability. Other examples: : Peter is old f : Peter is fairly old v : Peter is very old - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - µ (age) f v 5 7 Note "fairly" and "very" are examples of fuzzy quantifiers (see S 2.3.4) (b) Crisp Set : Peter is old enough to vote has a membership function: - - - - - - - - - - µ (age) 8 age Such a set with µ (x) = for all = for all not is called a crisp set. This is the kind of set used in convential logic. 2.3.2 Engineering Example.
material (m) has a resistivity (r) =.34 units. This is a fuzzy value with a membership function:.33.34.35 σ µ m (r) = exp{-(r -.34) 2 /2 σ 2 }and σ.5 2.3.3 Type 2 Fuzzy Set But is σ correct? This too is a fuzzy value. When, as in this case, the values µ m (r) are themselves fuzzy we have a Type 2 Fuzzy set, the usual type of fuzzy set. (We can have Type 3, 4 etc. Fuzzy sets also). Uncertainty in µ can be defined in terms of an interval if y (x) µ (x) y 2 (x). So µ (x) appears like y 2 (x) µ (x) range of values y (x) x 2.3.4 Fuzzy Predicates Consider the example Old paintings are usually rare. Rare items are expensive. So Old paintings are usually expensive. This fuzzy logic deduction depends on the fuzzy predicates: expensive, old, rare and fuzzy quantifiers: usually, In Fuzzy predicate logic the above example can be expressed as Old (Painting) Usually Rare (Painting) item (Rare (item) Expensive (item)) So by unification Rare (painting) Expensive (painting) pply the fuzzy quantifier to both sides: B C Usually Rare (Painting) Usually Expensive (Painting) B But Old (Painting) Usually Rare (Painting) C So Old (Painting) Usually Expensive (Painting) [Syllogism] Numerical Values These fuzzy quantifiers can be given numerical values as illustrated in the figure.
F Q (S).9 Fairly S.5.5 S.4 Very S.5.7. S where S = µ (x) for some predicate (like Old). This is sometimes called strength of truth of Similar curves can be drawn for other fuzzy quantifiers. The application of a fuzzy quantifier Q such as "very" or "fairly" has a numerical effect F Q (S) which varies with the strength of S as illustrated in the figure. Thus "very" changes a strength of.7 to about.4 and "fairly" changes it to about.9. Thus the effect of a quantifier is equivalent to an operator or function µ very old (X) = F very (µ old (X)) This supports our application of a fuzzy quantifier to both sides of an implication, as in the example: Rare Expensive Usually Rare Usually Expensive Various analytic forms have appeared in the literature for some of these quantifiers. [Note: term fuzzy modifer used sometimes, but we only use fuzzy quantifer] 2.3.5 Operators Each fuzzy predicate is represented in fuzzy logic by a fuzzy set, but the logical operators,,,, = need redefinition for fuzzy values. (i) Define as having a membership µ (x) = - µ (x) This has the important property of crisp logic ( ) = We expect µ ( ) (x) = µ (x) for all x in fuzzy logic, which it is for the above definition since µ ( ) = - µ = - ( - µ ) = µ Possible definitions of the operators,, =, are as follows (ii) B µ B (x) = Min (µ (x), µ B (x)) For example, Reliable Inexpensive Both 2 3 4 Years Car: Reliable and Inexpensive (iii) B µ B (x) = Max (µ (x), µ B (x)) (iv) =B We expect that this must be symmetric in & B. lso µ = = for all x This indicates the following µ =B (x) = - µ (x) - µ B (x) (v) B If is false, B is true
So if µ =, µ B = If is true, B is true if B is true B is false if B is false So if µ =, µ B = µ B is consistant with this. (+µ Β ) P line 2 µ Α Β line Q µ B µ This suggests the straight line (line ) in the figure, which is µ B = - µ (- µ B ) But we know µ = always. So this cannot be correct, as -µ (- µ ) always. So we try µ B = ( µ - µ B ) (line 2) But this > if µ < µ B, so this cannot be correct. This resulted in the final result. µ B = Min (, - ( µ - µ B ) ) (thick line) This has property µ =B = µ ( B) (B ) = min( µ B, µ B ) =... = - µ - µ B which is consistent with our earlier definition. But note µ as we would expect 2.3.6 Fuzzy Values Many values in our knowledge do not have precise values. For example. (a) the weight of a hook (b) the weight a baby can lift (c) the distance a person can throw an object Yet a "fuzzy" knowledge of these values is critical to our understanding of language and to intelligence. For example - the weight of a fish hook can be described in terms of possibilities as in the figure below Possibility Weight of fish hook, Weight in grams The distance a person can throw a stone: Possibility. Distance in metres These fuzzy values are all part of the knowledge of a human.
If probabilities are used, the integrals under the curves equal. Probabilities are commonly used to express fuzziness (or uncertainty) in Expert Systems (see Chapter 3). More complex examples of fuzzy values are speech or fuzzy images of classes of items eg "a car" In the UK we have an image of something like a Ford Fiesta a "good car" is perhaps a Vauxhall Vectra an expensive car: Mercedes In US it is much bigger: Chevy In Germany "a car" is a BMW So the fuzzy image "car" depends on person and place. 2.3.7 pproximate Representation of Fuzziness To facilitate computation, for many problems it is sufficient to use straight lines as in the diagrams: Example Old 3 5 7 ge ge F Q (S) Q: Very Q s = µ (x) The commutative, associative, distributative and De Morgan s laws are the subject of a homework. The laws hold for the operators but not for the operators = Modus ponens, Modus tollens, Syllogism, Reductio ad absurbum only hold approximately, i.e. the laws are fuzzy like the predicates. 2.5 PPLICTIONS of FUZZY LOGIC lthough Fuzzy Logic was first concerned with language and statements, it is still little used in Linguistics. It underlies uncertain reasoning in Expert Systems and has other applications from finance to earthquake prediction. But its main application today is in process control. n example is an automatic train approaching a station. To stop it may use crisp logic: if train < 5 m from station then apply brake at 5 m there is then a sudden jerk. In fuzzy logic if train is near station then slow train where near is a fuzzy predicate and slow is a fuzzy command which applies a brake with a pressure dependent on the truth value of near and other quantities like speed and de-acceleration. This fuzzy Logic allows the train to stop and leave the station smoothly (first used in JPN).
µ (D) 3 5 7 D: Distance (m) The principal is now used to smooth the operation of many machines (including video recorders) and for the control of whole chemical processes in factories. The basic structure is as follows: Begin End Process Parameters (e.g. Brake Pressure) Sensor Data (e.g. Distance) Defuzzification Fuzzification Fuzzy Parameter µ (e.g. Pressure) Computer (Inference Engine) Fuzzy data (µ (e.g. Distance)) Knowledge Base Data, Formulae There can be several fuzzy quantities, a large number of formulae, data items and laws in a complex process: eg. If (flow in pipe k is low) then (open valve T slightly). General Fuzzy Logic systems can now be purchased, e.g. MathWorks Fuzzy Logic Toolbox costs 785. 2.4 Logical Programming Writing software to represent fuzzy or crisp predicates and laws, and to make logical deduction, as in an Expert System, is not straightforward or natural in procedural languages such as Modula, FORTRN or C. Special languages have been developed for this purpose: LISP, PROLOG, POP and others. We here describe PROLOG, the most successful until now. 2.4. Statements Prolog statement is written like a predicate e.g. likes (tom, ice-cream). age (jack, 24). [note lower case] (rather than a command in a conventional language: such as X:= 3*T + 2;) If statements such as the above are typed into a PROLOG program they are immediately stored as knowledge in a PROLOG knowledge base. ny predicate can be stored in this way. 2.4.2 Questions To pose a question: Is predicate a true? we write? - a. PROLOG then explores its knowledge base to find if it can deduce the truth of a, e.g.? - likes (tom, ice-cream). This matches with our first example, so the answer is: yes It answers no if a is false or unknown. 2.4.3 Conjunction To ask a question? - a, b, c, d. asks if a b c d are true. It does this by examining the truth of each in turn. Example;? - drives (jack, fast-car), handsome (jack), rich (jack).
To find if anyone drives a fast car we write? - drives (_, fast-car). Here _ is like a wild card or predicate; it is called an anonymous variable and the response is yes if any statement like drives (jack, fast-car). is found. e.g.? - likes( _, ann ). Does anyone like nn? 2.4.4 Variables To find who likes nn, we can use a variable, for example? - likes(person, ann). variable variable starts with a capital. If it finds a statement likes(jack, ann). Then it replies Person = jack. which is more useful to nn than just yes! If nn types ; and hits the return key she may find another statement: likes(bob, ann). Example? - age(jack,). Response = 24 Example 2? - studies (Student,Course). note two variables Response might be Student = john; Course = maths; Student = jane; Course = physics;... Course = maths; no Example 3? - studies (john,course), studies (jane,course). will find any common course attended by john and jane; Course = maths 2.4.5 Lists list is written [a, b, c, d, e, f, g] shorthand for this list is [a V] or [a, b, c V] when V is a variable equal to the tail of the list; i.e. 2.4.6 Rules The rule V = [d, e, f, g] in second case. [ ] is the empty list [jack] is a list of one element jack B is written B: -. The statement G: -, B. is the rule and B G Example If child_of (mary, jack). means Mary is the child of Jack. parent_of (p, c). means p is the parent of c then we can write the obvious rule: parent_of (x,y): - child_of (y,x). So? -parent_of (Parent,mary) will first look in the knowledge base for predicates of the form parent_of(..., mary). If none is found it looks for rules which imply such a statement and finds the above rule. By replacing y by mary and x by Parent it deduces: parent_of(parent,mary): - child_of(mary,parent). and now looks for predicates of the form: child_of(mary,...). It finds child_of(mary, jack). and returns Parent = jack This demonstrates that backward-chaining is carried out automatically by PROLOG. So are several other processes in I. However, Object-Oriented languages like C ++ and JV, can also include objects for all of these processes and they are generally more flexible.