TCP1211-Logic Programming Formal Syntax and Semantics of Logic Programs Faculty of Information Technology Multimedia University.

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
Artificial Intelligence Chapter 13 The Propositional Calculus Biointelligence Lab School of Computer Sci. & Eng. Seoul National University.
1. An Overview of Prolog.
Models and Propositional Logic In propositional logic, a model in general simply fixes the truth value – true or false – for every proposition symbol.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
Logic.
L41 Lecture 2: Predicates and Quantifiers.. L42 Agenda Predicates and Quantifiers –Existential Quantifier  –Universal Quantifier 
Knowledge Representation Methods
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CPSC 322, Lecture 20Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Computer Science cpsc322, Lecture 20 (Textbook.
Exam #3 is Friday. It will consist of proofs, plus symbolizations in predicate logic.
Let remember from the previous lesson what is Knowledge representation
Logical and Rule-Based Reasoning Part I. Logical Models and Reasoning Big Question: Do people think logically?
The Language of Propositional Logic The Syntax and Semantics of PL.
FIRST ORDER LOGIC Levent Tolga EREN.
Adapted from Discrete Math
Intro to Discrete Structures
Discrete Mathematics and Its Applications
Formal Models of Computation Part II The Logic Model
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Chapter 1: The Foundations: Logic and Proofs
First Order Logic Chapter 7. PL is a Weak Representational Language §Propositional Logic (PL) is not a very expressive language because: §Hard to identify.
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 5: Classical Logic.
Pattern-directed inference systems
ARTIFICIAL INTELLIGENCE Lecture 3 Predicate Calculus.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Copyright © Cengage Learning. All rights reserved. CHAPTER 3 THE LOGIC OF QUANTIFIED STATEMENTS THE LOGIC OF QUANTIFIED STATEMENTS.
Barnett/Ziegler/Byleen Finite Mathematics 11e1 Chapter 7 Review Important Terms, Symbols, Concepts 7.1. Logic A proposition is a statement (not a question.
LDK R Logics for Data and Knowledge Representation PL of Classes.
Formal Methods in Software Engineering 1
Key Concepts Representation Inference Semantics Discourse Pragmatics Computation.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
CS6133 Software Specification and Verification
Chapter 2 Logic 2.1 Statements 2.2 The Negation of a Statement 2.3 The Disjunction and Conjunction of Statements 2.4 The Implication 2.5 More on Implications.
1 Introduction to Abstract Mathematics Predicate Logic Instructor: Hayk Melikya Purpose of Section: To introduce predicate logic (or.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
For Wednesday Read chapter 9, sections 1-3 Homework: –Chapter 7, exercises 8 and 9.
1 CSC384: Intro to Artificial Intelligence Lecture 5.  Knowledge Representation.
Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
Logic: Proof procedures, soundness and correctness CPSC 322 – Logic 2 Textbook §5.2 March 7, 2011.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
PREDICATE CALCULS In Propositional Calculus, each atomic symbol denotes a proposition. But there is no way to access the components of an individual assertion.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
Propositional Logic Rather than jumping right into FOL, we begin with propositional logic A logic involves: §Language (with a syntax) §Semantics §Proof.
ARTIFICIAL INTELLIGENCE Lecture 2 Propositional Calculus.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Intro to Artificial Intelligence  Jan 12 th  Announcements: Tutorial splits.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
Section 1.5 and 1.6 Predicates and Quantifiers. Vocabulary Predicate Domain Universal Quantifier Existential Quantifier Counterexample Free variable Bound.
Lecture 041 Predicate Calculus Learning outcomes Students are able to: 1. Evaluate predicate 2. Translate predicate into human language and vice versa.
Metalogic Soundness and Completeness. Two Notions of Logical Consequence Validity: If the premises are true, then the conclusion must be true. Provability:
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
Propositional Logic. Assignment Write any five rules each from two games which you like by using propositional logic notations.
Propositional and predicate logic
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
March 3, 2016Introduction to Artificial Intelligence Lecture 12: Knowledge Representation & Reasoning I 1 Back to “Serious” Topics… Knowledge Representation.
tautology checking continued
Computer Science cpsc322, Lecture 20
Knowledge Representation and Reasoning
The Propositional Calculus
Logics for Data and Knowledge Representation
Horn Clauses and Unification
Back to “Serious” Topics…
CSNB234 ARTIFICIAL INTELLIGENCE
Computer Science cpsc322, Lecture 20
Logical and Rule-Based Reasoning Part I
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

TCP1211-Logic Programming Formal Syntax and Semantics of Logic Programs Faculty of Information Technology Multimedia University

TCP1211-Logic Programming Lecture Outline Syntax of Logic programs. Syntax of Logic programs. Propositional Logic. Propositional Logic. Predicate Logic. (and why predicate logic?) Predicate Logic. (and why predicate logic?) Semantics of a Logic Program. Semantics of a Logic Program.

TCP1211-Logic Programming Three kinds of symbols likes(mother(X),X) :- good(X). woman(mother(Y)). woman(ann). good(husband(ann)). Relation Symbols (Predicate Symbols) : likes, good, woman. Name a relation between data objects. Begin with a lower-case letter. The number of arguments called arity: likes/2, good/1, woman/1.

TCP1211-Logic Programming likes(mother(X),X) :- good(X). woman(mother(Y)). woman(ann). good(husband(ann)). Function Symbols: mother, husband. Construct data objects. Only used in writing the arguments of a formula. Function symbols

TCP1211-Logic Programming Variables likes(mother(X),X) :- good(X). woman(mother(Y)). woman(ann). good(husband(ann)). Variables: X, Y. Represent unspecified objects. Start with an upper-case letter.

TCP1211-Logic Programming List of new terms so far… Predicate/relation symbol Predicate/relation symbol Function symbol Function symbol What next  What next  Formal syntax of Logic Programs Formal syntax of Logic Programs Formal definition of a clause Formal definition of a clause What is a literal ? What is a literal ? Formal definition of a term. Formal definition of a term. The alphabet of a program. The alphabet of a program.

TCP1211-Logic Programming Formal Syntax of Logic Programs likes(mother(X),X) :- good(X). woman(mother(X)). woman(ann). good(husband(ann)). A program is a set of clauses. From a logical point of view, the order in which these clauses are written has no importance. Clauses Syntax of a Program

TCP1211-Logic Programming Syntax of a clause likes(ann, X) :- toy(X), plays(ann, X). A clause is a formula: P :- Q 1,…, Q n. P is a literal called the head of the clause, and Q 1,…,Q n are literals that together form the body of the clause. In the case n = 0, there are no literals in the body; such a clause is written P :-. Literals HeadBody likes(ann, snoopy) :-. Or Simply likes(ann, snoopy). No Literals

TCP1211-Logic Programming Syntax of a Literal likes(mother(X), X) A literal is a formula: p(t 1,…,t k ) where p is a relation symbol of arity k and (t 1,…,t k ) are k terms. In the case k = 0, the literal is written simply as p. 2 Terms (Arity 2) Relation Symbol likes() Or Simply likes 0 Term (Arity 0)

TCP1211-Logic Programming Syntax of a Term likes(mother(husband(X)), X) ---- A Literal A term is either a variable like X, or it is a compound term f(t 1,…, t k ) where f is a function symbol of arity k, and (t 1,…, t k ) are k smaller terms. A function symbol with no arguments is a constant, written simply as f. 2 Terms Variable (Simple Term) Compound Term Function Symbol (Arity 1) Term of Term (Also Compound Term) Term of Term of Term (Variable, A Simple Term)

TCP1211-Logic Programming An Alphabet of a Program likes(mother(X),X) :- good(X). woman(mother(X)). woman(ann). good(husband(ann)). An alphabet of a logic program is a set of relation and function symbols used in the program, together with their arities. We say a program T is well-formed with respect to an alphabet L if all the relation and function symbols used in T are drawn from L and used with the correct arity. Alphabet = {likes/2, woman/1, good/1; mother/1, husband/1, ann/0} Relation Symbols Function Symbols Semicolon

TCP1211-Logic Programming Propositional Logic "It's raining"True or False "I'll get wet"True or False ”He is crying"True or False "I won't give him an ice-cream"True or False Propositional logic may be viewed as a representation language which allows us to express and reason with statements that are either true or false. Examples of such statements are: Logical operators such as , , , , etc. are often used to combined statements into compound statements. The truth value of a compound statement is dependent on the truth value of its constituents.

TCP1211-Logic Programming Implication (  ) A particularly important operator in mathematical logic is implication (  ), which expresses the idea that one condition always is accompanied by another. We write P  Q (P implies Q) to say “whenever P holds, Q also holds”. P = It's rainingQ = I'll get wet P  Q IF It's raining THEN I'll get wet

TCP1211-Logic Programming The Meaning of Implication (  ) using Truth Table QUESTION: Is the statement P  Q true (valid)? P = You are cryingQ = I won’t give you an icecream P  Q IF You are crying THEN I won’t give you an icecream ANSWER: The statement can be either true or false depending on the cases whether P and Q are true or false. P Q P  Q T T T T F F F T T F F T 4 Possible Cases Suppose a parent says to a child “If you are crying, I won’t give you an icecream”, the child stops crying, and doesn’t get any icecream. In logic, the parent did not tell a lie.

TCP1211-Logic Programming P = You are cryingQ = I won’t give you an icecream P  Q IF You are crying THEN I won’t give you an icecream P Q P  Q T T T T F F F T T F F T Only 3 Possible Cases A logical implication, P  Q (P logically implies Q), is an assertion that an implication P  Q (P implies Q) is always true, and thus eliminating the possibility of P to be true and Q to be false. P  Q This Case Is Not Possible Now

TCP1211-Logic Programming Predicate Logic "There is a person whom Sue likes"True or False "Ann likes all the animals"True or False A limitation of propositional logic is the impossibility of expressing general statements concerning similar cases. Predicate logic is more expressive than propositional logic, and such general statements can be specified in its language through the use of quantifiers. Examples of such statements are:  (X)[person(X)  likes(sue, X)]Existentially Quantified  (X)[animal(X)  likes(ann, X)]Universally Quantified Mathematically,

TCP1211-Logic Programming "There is a person whom Sue likes" "Ann likes all the animals"  (X) [person(X)  likes(sue, X)] "There exists X such that X is a person and Sue likes X"  (X) [animal(X)  likes(sue, X)] "For all X such that X is an animal and Ann likes X" Existential Quantifier Universal Quantifier

TCP1211-Logic Programming Variable Quantification in Prolog In Prolog, a variable is either existentially or universally quantified depending on the context in which it is used. In a literal which is used as a goal or sub goal: "There exists X such that X is a person and Sue likes X" ?- person(X), likes(sue, X). % Query/Initial Goal happy(sue) :- person(X), good(X). % Rule Body/Subsequent Goal "Sue is happy if there exists X such that X is a person and X is good" “In Both Cases Variable X Is Existentially Quantified.”

TCP1211-Logic Programming In a literal which is used as a rule head: "For all X such that Sue likes X if X is an animal" likes(sue, X) :- animal(X). % Rule Head likes(mother(X), X). % Fact/Rule Without Body "For all X such that mother of X likes X" “In Both Cases Variable X Is Universally Quantified.”

TCP1211-Logic Programming "For all X such that Sue likes X if X is a toy, and There exists Y such that Y plays with X" likes(sue, X) :- toy(X), person(Y), plays(Y, X). X is Universally Quantified Y is Existentially Quantified "Sue likes every toy some person plays with"

TCP1211-Logic Programming The Semantics of a Prolog Clause Semantically, a clause in a Prolog program, written as Q :- P. is exactly a logical implication P  Q. A unit clause Q :-. can be considered as True  Q. likes(sue, snoopy) :- toy(snoopy), plays(sue, snoopy). %Rule toy(snoopy)  plays(sue, snoopy)  likes(sue, snoopy) Means likes(sue, snoopy). %Fact Means True  likes(sue, snoopy)

TCP1211-Logic Programming The Semantics of a Prolog Goal A goal in a Prolog program, written as :- P. can be considered as P  True. ?- toy(snoopy), plays(sue, snoopy). %Query/Goal toy(snoopy)  plays(sue, snoopy)  True Means

TCP1211-Logic Programming The Semantics of a Prolog Program A Prolog program is regarded as the conjunction of its clauses, and its logical semantics consist of the truth of its clauses. Means likes(sue,snoopy) :- toy(snoopy), plays(sue,snoopy). toy(snoopy). plays(sue,snoopy). toy(snoopy)  plays(sue, snoopy)  likes(sue, snoopy)  True  toy(snoopy)  True  plays(sue, snoopy)

TCP1211-Logic Programming What is an interpretation? i(k, c(m)). A clause in a logic program can be either true or false depending on the interpretation given to the program. This interpretation is to assign meaning to the symbols used in the program, as well as to define the domain of the variables. is Kuala Lumpur capital Malaysia "Kuala Lumpur is the capital of Malaysia" This unit clause will be a true fact under the given interpretation.

TCP1211-Logic Programming i(k, c(m)). If the logic program is given a new interpretation now: is located Kuala Lumpur centre of Melaka "Kuala Lumpur is located at the centre of Melaka" This unit clause will not be a true fact under the new interpretation. Same unit clause, true previously but false now !

TCP1211-Logic Programming f(N,F) :- N = 0, F = 1. f(N,F) :- N > 0, N1 is N-1, f(N1,F1), F is N*F1. A Prolog program which contains two non-unit clauses (rules): If we interpret the relation symbol f as the factorial function then the program clauses are all true when interpreted over the domain of integers. If we interpret the relation symbol f as the fibonacci function or interpret it over the domain of characters then the program clauses are all false. An interpretation that makes all of the program clauses true is called a model of the program. Relation Symbol : fVariables : N, N1, F, F1

TCP1211-Logic Programming Formal Semantics (cont.) Interpretation I of a logic program P requires that there be a domain set D, and the following assignments: (a) Each constant symbol of P is assigned to an element of D; (b) Each function symbol of P is assigned to some particular function over domain D having the same arity; (c) Each relation symbol of P is assigned to some particular relation on D having the same arity. l(m(a), a). % A one-clause program a Ann constant, m mother of function, l likes relation I = I(a) = Ann I(m) = mother of I(l) = likes No variables involved !

TCP1211-Logic Programming l(m(X), X) :- g(X, Y). % A one-clause program m mother of function, l likes relation, g good in relation I = X a person, Y a subject A = I(m) = mother of I(l) = likes I(g) = good in A(X)  { persons } A(Y)  { subjects } Additional requirements must hold when there are variables used in a logic program. An assignment of variables A is a function from the variables of P to the domain D.

TCP1211-Logic Programming Now we can formally define the truth of logic clauses with respect to an interpretation I and a variable assignment A as follow: (1) for a unit clause, I(p(t 1,...,t k )) = true if and only if I(p)(I(A)(t 1 ),...,I(A)(t k )) = true, for every assignment of variables A. (2) for a non-unit clause, I(h :- b 1,...,b k ) = true unless there is some assignment of variables A such that I(A)(h) = false and I(A)(b 1 )=...=I(A)(b k ) = true. An interpretation I is a model for P provided I(c)=true for every clause c of P. We say that I satisfies a goal, ?- g 1,g 2,...,g k provided that I satisfies each of the g i.

TCP1211-Logic Programming For revision… What are the three symbols that you know? What are the three symbols that you know? How do you define a clause, literal, term and alphabet? How do you define a clause, literal, term and alphabet? Propositional Logic vs. Predicate Logic Propositional Logic vs. Predicate Logic Semantics of a Prolog clause, goal and program. Semantics of a Prolog clause, goal and program. The interpretation given to a Prolog program. The interpretation given to a Prolog program.