26
•COMP30411: Knowledge Representation •© University of Manchester, 2006 •1 CS1081 First Order Logic: Syntax and Semantics COMP30411 Sean Bechhofer [email protected] 2 COMP30411: Knowledge Representation Logic Recap You should already know the basics of First Order Logic (FOL) It’s a prerequisite of this course! The next two lectures provide a brief refresher But we won’t go over everything in detail You’re strongly advised to do some background reading if this isn’t familiar territory Much of the remainder of the course will rely on an understanding of this material. E.g. The Language of First Order Logic, Jon Barwise & John Etchemendy, CSLI Lecture Notes, 1993

First Order Logic

  • Upload
    razne

  • View
    6

  • Download
    1

Embed Size (px)

DESCRIPTION

First Order Logic:Syntax and Semantics

Citation preview

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 1

    CS1081

    First Order Logic:Syntax and Semantics

    COMP30411Sean Bechhofer

    [email protected]

    2COMP30411: Knowledge Representation

    Logic Recap

    You should already know the basics of First Order Logic (FOL) Its a prerequisite of this course!

    The next two lectures provide a brief refresher But we wont go over everything in detail

    Youre strongly advised to do some background reading if this isntfamiliar territory Much of the remainder of the course will rely on an

    understanding of this material. E.g. The Language of First Order Logic, Jon Barwise & John

    Etchemendy, CSLI Lecture Notes, 1993

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 2

    3COMP30411: Knowledge Representation

    What is a Logic?

    When people talk about logic they often mean propositional or first-order predicate logic.

    However there are many other logics, for example modal andtemporal logics and description logics. Well meet some of these later on.

    A logic usually has a well defined syntax, semantics and proof theory. The syntax of a logic defines the syntactically acceptable objects of

    the logic, or well-formed formulae. The semantics of a logic associates each formula with a meaning. The proof theory is concerned with manipulating formulae

    according to certain rules.

    4COMP30411: Knowledge Representation

    Coming Up

    Over the course of the next few lectures, well look in some detail atthe syntax, semantics and proof theory of propositional logic.

    Well then move on to predicate logic, seeing how this extendspropositional logicand touching on some of the key characteristics ofsuch languages.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 3

    5COMP30411: Knowledge Representation

    An Example: Cloth Weaves[Maier & Warren, Computing with Logic, 1988]

    An example showing how we can represent the qualities andcharacteristics of cloth types using a simple propositional logicknowledge base.

    6COMP30411: Knowledge Representation

    Cloth

    Woven fabrics consist of two sets of threads interlaced at rightangles.

    The warp threads run the length of the fabric The weft (fill, pick or woof) threads are passed back and forth between

    the warp threads. When weaving, the warp threads are raised or lowered in patterns,

    leading to different weaves. Factors include:

    The pattern in which warps and wefts cross Relative sizes of threads Relative spacing of threads Colours of threads

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 4

    7COMP30411: Knowledge Representation

    Plain Weave

    Over and under in aregular fashion

    8COMP30411: Knowledge Representation

    Twill Weave

    Warp end passes overmore than one weft Known as floats

    Successive threadsoffset by 1

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 5

    9COMP30411: Knowledge Representation

    Satin Weave

    Longer floats Offsets larger than 1

    10COMP30411: Knowledge Representation

    Classifying Cloth

    The example provides a number of rules that describe how particularkinds of cloth are described.

    alternatingWarp ! plainWeave If a piece of cloth has alternating warp, then its a plain weave.

    hasFloats, warpOffsetEq1 ! twillWeave If a piece of cloth has floats and a warp offset of 1, then its a twill

    weave. There are many other properties concerning the colour of threads,

    spacings etc.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 6

    11COMP30411: Knowledge Representation

    Using the Rules

    We could use these rules to build a system that would be able torecognise different kinds of cloth through recognising the individualcharacteristics.

    The example given shows that once we have recognised the followingcharacteristics diagonalTexture floatGTSink colouredWarp whiteFill

    Then we can determine that this cloth is denim.

    12COMP30411: Knowledge Representation

    Knowledge Representation

    Although this is relatively simple (in terms of both the expressivity ofthe language used and the number of facts), this really is an exampleof Knowledge Representation. The rules represent some knowledge about cloth A machine can make use of this knowledge to deduce

    consequences.

    This particular example makes use of propositional logic.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 7

    13COMP30411: Knowledge Representation

    Propositional Logic

    The syntax of propositional logic is constructed from propositions andconnectives.

    A proposition is a statement that is either true or false but not both. Examples: the following are propositions

    Walter Smith is Scotland Manager 2 + 3 = 5 Steve MacLaren is Scotland Manager 2 + 3 = 6 the reactor is in a stable state

    whereas the following are not What's the time? Fantastic Goal! 2+3 antelope

    14COMP30411: Knowledge Representation

    Propositions

    In general, we can determine whether any given statement is aproposition by prefixing it with It is true that

    and seeing whether the result makes grammatical sense. Propositions are often abbreviated using propositional variables eg p,

    q, r. Thus we must associate the propositional variable with its meaning

    i.e. Let p be Tony Blair is Prime Minister. Alternatively we might write something like

    reactor_is_in_a_stable_state so that the intended meaning of thepropositional variable is clearer. But we need to be very careful here that we dont encode too

    much information in the names of the propositions.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 8

    15COMP30411: Knowledge Representation

    Connectives

    Connectives allow us to form compound propositions by combiningpropositions.

    $iffif and only if,

    !impliesif then)

    ~negationnot

    |disjunctionor

    &conjunctionand

    16COMP30411: Knowledge Representation

    And (Conjunction)

    The conjunction p and q, written p q of two propositions is truewhen both p and q are true, false otherwise.

    Its Monday and its rainingp q

    Its rainingq

    Its Mondayp

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 9

    17COMP30411: Knowledge Representation

    Truth Tables

    Truth tables provide a summary of a connective. The truth table shows all possible combinations of the inputs to the

    connective, along with the outcome. Rows in the table give all possible settings of the propositions to

    true (T) or false (F). For a connective with n inputs, we need 2n rows in our truth table. A truth table for is:

    FFF

    FTF

    FFT

    TTT

    p qqp

    18COMP30411: Knowledge Representation

    Or (Disjunction)

    The disjunction p or q, written p q, of two propositions is truewhen p or q (or both) are true, false otherwise.

    This is sometimes called inclusive or, as we dont require that only oneof the propositions is true.

    FFF

    TTF

    TFT

    TTT

    p qqp

    Its Monday or its rainingp q

    Its rainingq

    Its Mondayp

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 10

    19COMP30411: Knowledge Representation

    Not (Negation)

    The negation not p of a proposition p is true when p is false and isfalse otherwise. Can also be read as it is false that p

    TF

    FT

    pp

    Its false that logic is easyIts not the case that logic is easyLogic isnt easy

    p

    Logic is easyp

    20COMP30411: Knowledge Representation

    If then (Implication)

    The implication p implies q, written p q, of two propositions istrue when either p is false or q is true, and false otherwise.

    TFF

    TTF

    FFT

    TTT

    p qqp

    If I study hard then, I get richWhen I study hard, I get rich

    p q

    I get richq

    I study hardp

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 11

    21COMP30411: Knowledge Representation

    If then (Implication)

    We need to be careful with as it may not quite capture ourintuitions about implication.

    In particular (taking the previous example), p q is true in thefollowing situations: I study hard and I get rich; or I don't study hard and I get rich; or I don't study hard and I don't get rich.

    Note the last two situations, where the implication is true regardlessof the truth of p.

    The one thing we can say is that if I've studied hard but failed tobecome rich then the proposition is clearly false.

    22COMP30411: Knowledge Representation

    Iff (Bi-implication)

    The bi-implication p iff q (p if and only if q), written as p q, of twopropositions is true when both p and q are true or when both p andq are false, and false otherwise.

    TFF

    FTF

    FFT

    TTT

    p qqp

    Sean is happy iff its the weekendp q

    Its the weekendq

    Sean is happyp

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 12

    23COMP30411: Knowledge Representation

    Propositional Logic: Moreformally

    The language of propositional logic consists of the following symbols. A set PROP, of proposition symbols, p, q, r etc A set of propositional connectives:-

    nullary connectives true and false; unary connective binary connectives , , ,

    The symbols ( and ) these are used to avoid ambiguity.

    24COMP30411: Knowledge Representation

    Well Formed Formulae

    The set of Well-Formed Formulae (WFF) is defined as: Any propositional symbols is in WFF The nullary connectives true and false are in WFF If A and B are in WFF then so are

    A

    (A) A B A B A B

    A B

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 13

    25COMP30411: Knowledge Representation

    Examples

    p (p) (()) true p true p q

    p q (p q) true false p q (p q) r p q r

    26COMP30411: Knowledge Representation

    Truth Tables

    We can extend the basic truth tables to show interpretations ofcompound propositions.

    To draw up a truth table, construct a column for each propositioninvolved.

    We need 2n rows for n propositions in order to record all possibleways of setting the propositions to T and F.

    If we have 3 propositions, , i.e. we need 23 = 8 rows. Construct a column for each connective, the most deeply nested first. Evaluate each column using values for propositions or previous

    columns.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 14

    27COMP30411: Knowledge Representation

    Example

    TTTTFFTFTFFFTFFFFFFF

    FTFTr

    TTTTp q

    FFTTFTFTTTTT(p q) rqp

    (p q) r

    I eat toast for breakfastr

    I eat cereal for breakfastq

    I eat eggs for breakfastp

    Compound proposition is true if I eat eggs, cereal and toast; or I eat eggs and toast; or I eat cereal and toast

    28COMP30411: Knowledge Representation

    Interpretations

    Given a particular formula, can you tell if it is true or not? The truth of a compound formula depends on the truth values of the

    component propositions. A truth valuation is a function:

    Iv: PROP {T,F}

    which assigns a truth value to each atomic proposition Given a truth valuation, we can define a interpretation I that gives a

    truth value for a (well-formed) compound formula using the truthvaluation for the atomic propositions and the truth tables for theconnectives involved.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 15

    29COMP30411: Knowledge Representation

    Example

    Proposition:(p q) r

    Truth valuation:Iv(p) = F, Iv(q) = T, Iv(r) = F

    Applying the truth valuation gives us:I((p q) r)

    = (Iv(p) Iv(q)) Iv(r))= (F T) F= T F

    = F

    FFF

    TTF

    TFT

    TTT

    p qqp

    TFF

    TTF

    FFT

    TTT

    p qqp

    30COMP30411: Knowledge Representation

    Semantics of PropositionalLogic

    Given an truth valuation Iv:PROP ! {T,F}, we can extend this toprovide us with a interpretation I that assigns either T or F to anystatement of the language.

    The symbol is used to represent the relationship betweeninterpretations and formulae:

    I A if and only if I Bif, and only ifI A , BIf I A then I Bif, and only ifI A ) BI A or I Bif, and only ifI A BI A and I Bif, and only ifI A BI 2 Aif, and only ifI A

    if, and only if Iv(p) = TI pI 2 falseI true

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 16

    31COMP30411: Knowledge Representation

    Tautologies and Satisfiability

    A formula is valid or is a tautology iff it is true under everyinterpretation. If A is a tautology, this is written

    A A formula is said to be satisfiable (or consistent) iff it is true under at

    least one interpretation. A formula is said to be unsatisfiable (or inconsistent or contradictory) iff

    there is no interpretation under which it is true If a formula A is a tautology then A is unsatisfiable.

    32COMP30411: Knowledge Representation

    Truth Tables

    Each line of a truth table corresponds to a interpretation. So we can use truth tables to determine whether or not

    formulae are valid. Example: (p ) q) (q ) p)

    TTTF

    p ) q

    TFTT

    q ) p

    TFF TTF TTT TFT

    (p ) q) (q ) p)qp

    Tautology

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 17

    33COMP30411: Knowledge Representation

    Truth Tables

    Example: (p ) q) p

    TTTF

    p ) q

    FFF FTF TTT FFT

    (p ) q) pqp

    Not a tautology, but satisfiable

    34COMP30411: Knowledge Representation

    Translations

    An alternative to providing a direct semantics (e.g. Interpretations asweve seen here) is to provide a translation of the connectives

    For example, we can define p ! q

    as p q

    If we look at the truth tables for each of these formulae, then we cansee that for any valuations of p and q, the result is the same.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 18

    35COMP30411: Knowledge Representation

    Defining New connectives

    Using this approach of translation rather than a direct semantics, wecan define new connectives.

    Recall the truth table for or p q is true when either p or q is true.

    Its also true when both p and q are true For some situations, we might want a new connective that tells us

    when only one of p or q is true: also known as exclusive or andsometimes written p q

    FFF

    TTF

    TFT

    TTT

    p qqp

    36COMP30411: Knowledge Representation

    Defining New connectives

    We could define p q using a truth table:

    Alternatively, we can give a translation to an equivalent expressionusing the other connectives:

    p q (p q) (p q)

    FFF

    TTF

    TFT

    FTT

    p qqp

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 19

    37COMP30411: Knowledge Representation

    Functional Completeness

    The above example illustrates that we dont actually need the exclusiveor connective It can be defined in terms of , and

    So how many connectives do we really need? We say a set of connectives is functionally complete if there is no

    truth table that can not be expressed as a formula involving onlythese connectives.

    For example, the set {, , } is functionally complete In fact {,} is functionally complete

    De Morgans Laws

    38COMP30411: Knowledge Representation

    Logical Consequences

    We have provided definitions of the syntax and semantics ofpropositional logic.

    Given a set of formulae, we want to know which formulae are logicalconsequences of that set

    B is a consequence of A if its the case that whenever B is true, thenA must be true also. We write:

    A B For example, if we know that both p and p ) q hold, then we might

    want to be able to conclude that q also holds.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 20

    39COMP30411: Knowledge Representation

    Logical Consequences

    We can do this by constructing truth tables. If we want to know whether B follows from A1, A2, . An, then we

    could construct a truth table forA1 A2 An ) B

    and check to see is this is a tautology. E.g. is it the case that q follows from (p ) q) and p?

    Construct a truth table for ((p ) q) p) ) q

    TTFT(p ) q)

    FFFT(p ) q) p

    TFFTTFTFTTTT((p ) q) p) ) qqp

    40COMP30411: Knowledge Representation

    Knowledge Bases

    We can now use thise notion of logical consequence. A Knowledge Base K = {p1, , pn} is a collection of propositions that

    describe facts about a situation of affairs that we are trying to model We can then derive consequences from this knowledge base where q

    is a consequence ifp1,,pn q

    For example, the rules encapsulating the different characteristics andqualities of different cloth weaves.

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 21

    41COMP30411: Knowledge Representation

    Logical Consequences

    As we saw before, we could test for logical consequence byconstructing truth tables.

    If we want to know whether B follows from A1, A2, . An, then wecould construct a truth table for

    A1 A2 An ) B

    and check to see is this is a tautology. E.g. is it the case that q follows from (p ) q) and p?

    Construct a truth table for ((p ) q) p) ) q)

    TTFT(p ) q)

    FFFT(p ) q) p

    TFFTTFTFTTTT((p ) q) p) ) q)qp

    Problem: This is potentiallyexpensive: we need 2n rowsfor n propositions, so ourtruth tables may becomelarge.

    42COMP30411: Knowledge Representation

    Proof Rules

    An alternative is to use some proof rules or proof theory. Proof rules provide us with a mechanism for determining logical

    consequences through some syntactic manipulation of the formulae. A rule stating that B follows (or is provable from) A1,,An is written

    as:

    A well known proof rule is modus ponens:

    where A and B are any WFF.

    B

    A1 An

    B

    A ) B A

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 22

    43COMP30411: Knowledge Representation

    More Proof Rules

    A common rule, known as -elimination is:

    or

    We can read the first as If A and B hold, then A must also hold.

    The -introduction rule tells us:

    or

    Again, we can read the first as: If A holds, then A B must also hold.

    A

    A B

    B

    A B

    A B

    B

    A B

    A

    44COMP30411: Knowledge Representation

    Proof

    By combining proof rules together, we can deduce consequencesfrom premises.

    Ex: from p q and q ) r, can we prove r?

    1. p q [given]2. q ) r [given]3. q [1 -elimination]

    4. r [2,3 modus ponens]

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 23

    45COMP30411: Knowledge Representation

    Proof Theory

    This reasoning about statements of the logic is being done withoutconsidering the interpretations Were not drawing up truth tables to work out if the

    consequences hold. Proof rules show us, given true statements, how to generate further

    true statements. Axioms describe universal truths of the logic

    For example, p p is an axiom of propositional logic

    46COMP30411: Knowledge Representation

    Proofs

    If A1,An,B are WFF, then there is a proof of B from A1,,An iffthere exists some sequence of formulae C1,,Cn such that Cn = Band each formula Ck for 1 k < n is either an axiom, one of theformulae A1,An or is the conclusion of a rule whose premisesappeared earlier in the sequence.

    We write A1,,An ` B to show that B is provable from A1,,An(given some set of proof rules and axioms).

    Ex: from p ) q, ( r q) ) (s p), q can we prove s q?1. p ) q [given]2. ( r q) ) (s p) [given]3. q [given]4. s q [3, -introduction]

    Alternative would be truth table for (p ) q ( r q) ) (s p) q ) ) (s q)

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 24

    47COMP30411: Knowledge Representation

    Relating Proofs and Semantics

    So far weve considered notions of validity and provability Validity is related to semantics. A propositional formula is valid if it is

    satisfied under all possible interpretations We draw up a truth table and check that every line evaluates to

    true. Provability is related to the proof theory. A propositional formula is

    provable if it is an axiom or it is provable from other provableformulae We construct a proof applying proof rules at each step.

    Whats the connections between the two? Soundness and Completeness

    48COMP30411: Knowledge Representation

    Soundness

    We write A1,,An ` B to denote that B is provable from A1,,Anusing a set of proof rules

    A Soundness theorem states that:If A1,,An ` Bthen A1 An B (i.e. A1 An ) B is valid)

    Informally, soundness gives us an assurance that our proof theory isproducing correct answers

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 25

    49COMP30411: Knowledge Representation

    Completeness

    A Completeness theorem states that:If A1 An B (i.e. A1 An ) B is valid)then A1,,An ` B

    Informally, completeness gives us an assurance that if a formula isvalid, we can construct a proof of it using our proof theory.

    Note that completeness doesnt say anything at all about how wemight go about constructing such a proof just that the proofexists.

    Note that both soundness andcompleteness are with respectto a particular set of axiomsand proof rules. `

    Completeness

    Soundness

    50COMP30411: Knowledge Representation

    Soundness and Completeness

    An example of an unsound rule is:

    Using this rule, given any p and q, we can deduce an arbitrary r.However p q ) r is not a valid formula. Thus including this rule inour proof rules would not give us soundness.

    If we only have rules for modus ponens and -elimination, we do nothave completeness. With only those rules, we cant prove

    p ` p q

    even thoughp ) (p q)

    is valid

    C

    A B

  • COMP30411: Knowledge Representation

    University of Manchester, 2006 26

    51COMP30411: Knowledge Representation

    Summary

    Weve seen a (brief) overview of propositional logic, its syntax,semantics and proof theory. We havent seen all the details of the proof rules for

    propositional logic though. These can be found in anyintroductory logic text.

    Weve seen the notions of soundness and completeness, relating theinterpretation semantics and the proof theory.

    Next, well look at predicate calculus, which gives us a much moreexpressive language than propositional logic.