1 Logic Programming School of Informatics, University of Edinburgh Logic Programming in 50 Minutes The purpose of this lecture is to explain why logic.

Slides:



Advertisements
Similar presentations
1 C2 in English – can this level be tested? Welcome! Suzanne Vetter-MCaw, ELTAF Members Day,
Advertisements

1 Knowledge Representation Introduction KR and Logic.
Artificial Intelligence: Natural Language and Prolog
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Limitations of the relational model 1. 2 Overview application areas for which the relational model is inadequate - reasons drawbacks of relational DBMSs.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 8 – Search and conclusions.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
1 First order theories (Chapter 1, Sections 1.4 – 1.5)
Some Prolog Prolog is a logic programming language
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Extensible Networking Platform CSE 240 – Logic and Discrete Mathematics Review: Mathematical Induction Use induction to prove that the sum of the.
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
Objectives The student will be able to:
Interesting Integers!.
Getting started with Prolog
Logic Programming Lecture 1: Course orientation; Getting started with Prolog.
1 Logic Programming School of Informatics, University of Edinburgh append/3 A Drosophila of L.P. append([], L, L) append([ H | T ], L, [ H | R ])  append(T,
Logic Programming Lecture 9: Constraint logic programming.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
First-Order Logic: Better choice for Wumpus World Propositional logic represents facts First-order logic gives us Objects Relations: how objects relate.
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Logic Programming Automated Reasoning in practice.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
Code-Carrying Proofs Aytekin Vargun Rensselaer Polytechnic Institute.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
2 We need programming languages to communicate with a computer. The two broad classifications of programming languages are: Low-level and High- level.
PROOF TRANSLATION AND SMT LIB CERTIFICATION Yeting Ge Clark Barrett SMT 2008 July 7 Princeton.
Proof-system search ( ` ) Interpretation search ( ² ) Main search strategy DPLL Backtracking Incremental SAT Natural deduction Sequents Resolution Main.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
First Order Logic (chapter 2 of the book) Lecture 3: Sep 14.
Describing Syntax and Semantics
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
Logic Programming Programming Lecture 1: Getting started with Prolog.
CSC 338: Compiler design and implementation
Proof Carrying Code Zhiwei Lin. Outline Proof-Carrying Code The Design and Implementation of a Certifying Compiler A Proof – Carrying Code Architecture.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
For Wednesday No new reading Prolog handout 2 Chapter 9, exercise 4.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Theorems and conjectures
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Entry Task Write down your age Multiply it by 10 Add 8 to the product Double that answer and subtract 16 Divide the result by 20 Explain what you notice.
Knowledge Based Information System
Component 1.6.
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Presentation transcript:

1 Logic Programming School of Informatics, University of Edinburgh Logic Programming in 50 Minutes The purpose of this lecture is to explain why logic programming was invented; how it might be useful to you; and what you need to do to start programming.

2 Logic Programming School of Informatics, University of Edinburgh The Ideal Every program specification can be written in logic. Specifications are independent of computers. Rules of logic can prove the correctness of a specification even if computers didn’t exist. But proof can also be done by a computer smart enough to find the right proof. So specifications and programs are the same.  nearly

3 Logic Programming School of Informatics, University of Edinburgh Where Has This Worked? Symbolic reasoning systems (machine learning, planning, constraint solving, etc) Language systems (parsers, generators, etc) Verification systems (theorem provers, model checkers, etc). Multi-agent systems (reactive systems, performative handling, brokering, etc) Web systems (page parsing/generation, semantic webs)

4 Logic Programming School of Informatics, University of Edinburgh Axioms, Assumptions, Goals Your parent is your ancestor. Your parent’s ancestors are your ancestors. ancestor(X, Y)  parent(X, Y). ancestor(X, Y)  parent(X, Z) & ancestor(Z, Y). Given: parent(dave, thomas). parent(dave,helen). parent(helen, margaret), etc. We can prove:  A. ancestor(dave, A)  B. ancestor(B, margaret)  A,B. ancestor(B, A)

5 Logic Programming School of Informatics, University of Edinburgh Proof Involves Search ancestor(X, Y)  parent(X, Y). ancestor(X, Y)  parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret).  A. ancestor(dave, A) parent(dave, Y) parent(dave, Z) & ancestor(Z, Y) parent(dave, helen) parent(helen, Y) parent(helen, margaret) A = Y Z = helen Y = margaret parent(dave, thomas) 2 Y = thomas

6 Logic Programming School of Informatics, University of Edinburgh Practical Problem 1 Not all specifications are executable. X =  X 2 is a specification of square root but doesn’t compute square roots. We need to write specifications with an understanding of their future use.

7 Logic Programming School of Informatics, University of Edinburgh Practical Problem 2 Proof mechanisms that are unsophisticated can easily be fooled. e.g. Prolog has trouble with this: Given: p(X)  p(Y) & q(Y,X). p(1). q(1,2). Prove: p(1). Proof mechanisms that are sophisticated are difficult to operate as programming systems.

8 Logic Programming School of Informatics, University of Edinburgh Practical Problem 3 Some computable specifications consume a lot of resource before giving an answer. e.g. Prolog has trouble with this: Given: p  is_integer(X) & X > is_integer(1). is_integer(N)  is_integer(N1) & N is N + 1. Logic programming system designers worry about efficiency. So must programmers.

9 Logic Programming School of Informatics, University of Edinburgh Practical Problem 4 Programmers like to think about closed worlds so negation often is simplified to “I can’t prove it true in my current circumstances”. e.g. Prolog has trouble with this: Given: p(X)  not(q(X)) & r(X). q(2). r(1). Prove: p(X)

10 Logic Programming School of Informatics, University of Edinburgh A Logic Program’s Interpretation ancestor(X, Y)  parent(X, Y). ancestor(X, Y)  parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret). Interpretation contains all ground conclusions:  A1,B1. ancestor(A1, B1)  A2,B2. parent(A2, B2) ancestor(dave, thomas). ancestor(dave,helen). ancestor(helen, margaret). ancestor(dave,margaret) parent(dave, thomas). parent(dave,helen). parent(helen, margaret).

11 Logic Programming School of Informatics, University of Edinburgh Everything is a Structured Term ancestor(X, Y)  parent(X, Y). ancestor(X, Y)  parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret). parent X Z ancestor Z Y & Z Y  parent dave thomas

12 Logic Programming School of Informatics, University of Edinburgh Logic Programs Manipulate Terms sum(null, 0). sum(seq(First,Rest), N)  sum(Rest, N1) & N is N We can prove:  N. sum(null, N)  N. sum(seq(5,null), N)  N. sum(seq(5,seq(2,null)), N) and so on…. N = 0 N = 5 N = 9

13 Logic Programming School of Informatics, University of Edinburgh Logic Programming Learning Curve Time Learning effort Logic programming Imperative programming A crude caricature: Imperative programmers learn lots of little things Logic programmers learn one big thing

14 Logic Programming School of Informatics, University of Edinburgh Starting to Program in Prolog sicstus | ?- 1 < 2. yes | ?- not(1 < 2). no | ?- [library(lists)]. | ?- append([a,b], [c], X). X = [a,b,c] Unix command to start SICStus Prolog Goal, using a built-in predicate Goal, using a built-in logical operator which succeeds which fails Loading definitions from a (library) file Goal, using a loaded predicate. Result of variable binding

15 Logic Programming School of Informatics, University of Edinburgh Sources l Sterling & Shapiro “The Art of Prolog” l Clocksin & Mellish “Prolog Programming” l John Lloyd “Foundations of Logic Programming” Books: Organisation: Association for Logic Programming Main conference: International Conference on Logic Programming Main journal: Theory and Practice of LP (pre-2001 main journal was Journal of LP )