Logic as a Programming Language

Similar documents
First-Order Logic (FOL)

Symbolic Programming Declarative Programming

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions

Resolution (14A) Young W. Lim 6/14/14

For Wednesday. No reading Chapter 9, exercise 9. Must be proper Horn clauses

IN A NUTSHELL : WHAT IS A VENN DIAGRAM?

Lecture 4: January 12, 2015

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm

Logic Languages. Hwansoo Han

Logic Programming Languages

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

Chapter 16. Logic Programming Languages

CSL105: Discrete Mathematical Structures. Ragesh Jaiswal, CSE, IIT Delhi

Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x).

Chapter 16. Logic Programming Languages ISBN

First-Order Logic. Cholwich Nattee. Sirindhorn International Institute of Technology Thammasat University. Lecture 9: First-Order Logic 1/60

Logic (or Declarative) Programming Foundations: Prolog. Overview [1]

THE PREDICATE CALCULUS

Chapter 16. Logic Programming Languages ISBN

Advanced Logic and Functional Programming

What is the study of logic?

LOGIC AND DISCRETE MATHEMATICS

Introduction to predicate calculus

CS 4700: Artificial Intelligence

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

Logic Programming. Let us have airline flight information of the form: 1. Application Domains: 2. Definitions

(More) Propositional Logic and an Intro to Predicate Logic. CSCI 3202, Fall 2010

Lecture 17 of 41. Clausal (Conjunctive Normal) Form and Resolution Techniques

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Software Paradigms (Lesson 6) Logic Programming

Deduction Rule System vs Production Rule System. Prof. Bob Berwick. Rules Rule

INF5390 Kunstig intelligens. First-Order Logic. Roar Fjellheim

Section 2.4: Arguments with Quantified Statements

Predicate Calculus. Problems? Syntax. Atomic Sentences. Complex Sentences. Truth

Logic Programming Paradigm

Fundamentals of Prolog

COMP3411: Artificial Intelligence 8. First Order Logic

INTLOGS17 Test 1. Prof: S Bringsjord TA: Rini Palamittam NY

Quantification. Using the suggested notation, symbolize the statements expressed by the following sentences.

CS 321 Programming Languages and Compilers. Prolog

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

Part I Logic programming paradigm

References. Topic #16: Logic Programming. Motivation. What is a program? Prolog Program Structure

Set 7: Predicate logic Chapter 8 R&N. ICS 271 Fall 2015

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Announcements. The current topic: Prolog. Logic programming. Logic programming. Lab 2 has been marked.

Lecture 7: January 15, 2014

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms

Knowledge Representation. CS 486/686: Introduction to Artificial Intelligence

(QiuXin Hui) 7.2 Given the following, can you prove that the unicorn is mythical? How about magical? Horned? Decide what you think the right answer

6. Inference and resolution

Section 2.2: Introduction to the Logic of Quantified Statements

Week 7 Prolog overview

First-Order Predicate Logic. Introduction to Intelligent Systems

Implementação de Linguagens 2016/2017

Programming Paradigms

Knowledge Representation

COMP4418 Knowledge Representation and Reasoning

Logic Programming. Chapter 13

SECTION 1.5: LOGIC PROGRAMMING

For next Tuesday. Read chapter 8 No written homework Initial posts due Thursday 1pm and responses due by class time Tuesday

CPSC 121: Models of Computation. Module 6: Rewriting predicate logic statements

Prolog Programming. Lecture Module 8

Lisp History. Lisp and Prolog Background. Lisp Use. Lisp Availability

Logical reasoning systems

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg

will take you everywhere.

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

Automated Reasoning. Natural Deduction in First-Order Logic

Constraint Solving. Systems and Internet Infrastructure Security

Prolog. Logic Programming vs Prolog

First-Order Predicate Logic. CSCI 5582, Fall 2007

Axiomatic Specification. Al-Said, Apcar, Jerejian

Resolution in FOPC. Deepak Kumar November Knowledge Engineering in FOPC

ITCS 6150 Intelligent Systems. Lecture 13 First-Order Logic Chapter 8

ARTIFICIAL INTELLIGENCE (CS 370D)

Logic and its Applications

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

Chapter 12. Computability Mechanizing Reasoning

Practice Problems: All Computer Science majors are people. Some computer science majors are logical thinkers. Some people are logical thinkers.

Knowledge Representation Issues, Predicate Logic, Rules

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry.

What is all the Fuzz about?

Declarative Programming. 2: theoretical backgrounds

An introduction to logic programming with Prolog

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Com S 541. Programming Languages I

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig.

Introduction to Prolog

Operational Semantics

PROLOG PROgramming in LOGic

Part I CHR tutorial. Cambridge University Press Constraint Handling Rules Thom Fruhwirth Excerpt More information

Introduction to Artificial Intelligence 2 nd semester 2016/2017. Chapter 8: First-Order Logic (FOL)

Visual Prolog Tutorial

Vibhav Gogate University of Texas, Dallas Artificial Intelligence: CS 4365 First-order Logic

Lisp and Prolog Background

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3.

PHIL 240, Introduction to Logic, Sections Fall 2011 FINAL EXAM 14 December Name (5 points): Section (5 points):

7. Relational Calculus (Part I) 7.1 Introduction

Transcription:

Logic as a Programming Language! Logic can be considered the oldest programming language! Aristotle invented propositional logic over 2000 years ago in order to prove properties of formal arguments! Propositions - simple statements that are either true or false; e.g. Betty wears a white dress. Today is Sunday.! Propositional Logic propositions + rules of inference! Most famous inference rule: modus ponens Let A and B be propositions, then A implies B A is true -------------------- B is true HW: Read Section 1 online tutorial available on the CSC301 Prolog page. (first tutorial) Chap 19 & 20 (1) Inference is the act or process of drawing a conclusion based solely on what one already knows. (2) Rule of inference is a scheme for constructing valid inferences.

Propositional Logic Example: If Betty wears a white dress then today is Sunday. Betty wears a white dress. ------------------------------------------------------------------------ Today is Sunday. A fundamental problem with propositional logic is that it is not powerful enough to encode general knowledge - we would like to say things like: All objects that are considered human are mortal. Due to the fact that this sentence is not simple it can not be considered a proposition. But these kind of sentences are key in describing general knowledge.

Quantification o o o In 1879 Gottlob Frege introduced the predicate calculus ( Begriffsschrifft ) Today predicate calculus is more commonly known as First Order Logic. This logic solves the problems of propositional logic by introducing three new structures: predicates, universal quantification, and existential quantification. Friedrich Ludwig Gottlob Frege Philosopher and Logician

First-Order Logic! Quantified Variables! Universally quantified variables X for All objects X! Existentially quantified variables Y there Exists an object Y

First-Order Logic! Predicates! Predicates are functions that map their arguments into true/false! The signature of a predicate p(x) is p: Objects { true, false }! Example: human(x)! human: Objects { true, false }! human(tree) = false! human(paul) = true! Example: mother(x,y)! mother: Objects Objects { true, false }! mother(betty,paul) = true! Mother(giraffe,peter) = false

First-Order Logic! We can combine predicates and quantified variables to make statements on sets of objects! X[mother(X,paul)]! there exists an object X such that X is the mother of Paul! Y[human(Y)]! for all objects Y such that Y is human

First-Order Logic! Logical Connectives: and, or, not! F C[parent(F,C) and male(f)]! There exists an object F for all object C such that F is a parent of C and F is male.! X[day(X) and (wet(x) or dry(x))]! For all objects X such that X is a day and X is either wet or dry.

First-Order Logic! If-then rules: A B! X Y[parent(X,Y) and female(x) mother(x,y)]! For all objects X and for all objects Y such that if X is a parent of Y and X is female then X is a mother.! Q[human(Q) mortal(q)]! For all objects Q such that if Q is human then Q is mortal.

Horn Clause Logic In horn clause logic the form of the WFF s is restricted: P 1 P 2 P n-1 P n P 0 Single predicate in consequent Conjunctions only! Where P 0, P 1, P 2, P n-1, P n are predicates.

Proving things is computation! Use resolution to reason with horn clause expressions - resolution mimics the modus ponens using horn clause expressions. Advantage: this can be done mechanically (Alan Robinson, 1965) Deduction is Computation J. Alan Robinson: A Machine-Oriented Logic Based on the Resolution Principle. J. ACM 12(1): 23-41 (1965)

Basic Prolog Programs Facts - a fact constitutes a declaration of a truth; in Prolog it has to to be a positive assertion. Prolog Programs - a Prolog program is a collection of facts ( and rules, as we will see later). Example: a simple program male(phil). male(john). female(betty). Facts, Prolog will treat these as true and enters them into its knowledgebase. We execute Prolog programs by posing queries on its knowledgebase: Prompt?- male(phil). true - because Prolog can use its knowledgebase to prove true.?- female(phil). false - this fact is not in the knowledgebase. Prolog Programming in Logic

Prolog - Queries & Goals A query is a way to extract information from a logic program. Given a query, Prolog attempts to show that the query is a logical consequence of the program; of the collection of facts. In other words, a query is a goal that Prolog is attempting to satisfy (prove true). When queries contain variables they are existentially quantified, consider?- parent(x,liz). The interpretation of this query is: prove that there is at least one object X that can be considered a parent of liz, or formally, prove that holds. x[parent(x,liz)] NOTE: Prolog will return all objects for which a query evaluates to true.

A Prolog Program % a simple prolog program female(pam). female(liz). female(ann). female(pat). male(tom). male(bob). male(jim). Parent Relation parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). Example Queries:?- female(pam).?- female(x). X[female(X)]??- parent(tom,z).?- father(y). A Family Tree

Compound Queries A compound query is the conjunction of individual simple queries. Stated in terms of goals: a compound goal is the conjunction of individual subgoals each of which needs to be satisfied in order for the compound goal to be satisfied. Consider: or formally,?- parent(x,y), parent(y,ann). X,Y[parent(X,Y) parent(y,ann)] When Prolog tries to satisfy this compound goal, it will make sure that the two Y variables always have the same values. Prolog uses unification and backtracking in order to find all the solutions which satisfy the compound goal.

Homework! Assignment #10 (see website)