Datalog. P.J. McBrien. Imperial College London. P.J. McBrien (Imperial College London) Datalog 1 / 19

Similar documents
SQL: A Language for Database Applications

SQL: An Implementation of the Relational Algebra

Big Data: Pig Latin. P.J. McBrien. Imperial College London. P.J. McBrien (Imperial College London) Big Data: Pig Latin 1 / 44

INTERMEDIATE LOGIC Glossary of key terms

MATH1061/MATH7861 Discrete Mathematics Semester 2, Lecture 5 Valid and Invalid Arguments. Learning Goals

PHILOSOPHY OF LOGIC AND LANGUAGE OVERVIEW LOGICAL CONSTANTS WEEK 5: MODEL-THEORETIC CONSEQUENCE JONNY MCINTOSH

Module 5. Knowledge Representation and Logic (Propositional Logic) Version 2 CSE IIT, Kharagpur

Artificial Intelligence Prof. P. Dasgupta Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Philosophy 220. Truth Functional Properties Expressed in terms of Consistency

Russell: On Denoting

Rosen, Discrete Mathematics and Its Applications, 6th edition Extra Examples

MISSOURI S FRAMEWORK FOR CURRICULAR DEVELOPMENT IN MATH TOPIC I: PROBLEM SOLVING

Courses providing assessment data PHL 202. Semester/Year

(Refer Slide Time 03:00)

1 Clarion Logic Notes Chapter 4

PHI Introduction Lecture 4. An Overview of the Two Branches of Logic

PHILOSOPHICAL PROBLEMS & THE ANALYSIS OF LANGUAGE

An Introduction to. Formal Logic. Second edition. Peter Smith, February 27, 2019

Semantic Entailment and Natural Deduction

Facts and Free Logic. R. M. Sainsbury

Facts and Free Logic R. M. Sainsbury

LOGIC ANTHONY KAPOLKA FYF 101-9/3/2010

Artificial Intelligence. Clause Form and The Resolution Rule. Prof. Deepak Khemani. Department of Computer Science and Engineering

Transition to Quantified Predicate Logic

9.1 Intro to Predicate Logic Practice with symbolizations. Today s Lecture 3/30/10

UC Berkeley, Philosophy 142, Spring 2016

Also, in Argument #1 (Lecture 11, Slide 11), the inference from steps 2 and 3 to 4 is stated as:

C. Exam #1 comments on difficult spots; if you have questions about this, please let me know. D. Discussion of extra credit opportunities

Williams on Supervaluationism and Logical Revisionism

Grade 6 Math Connects Suggested Course Outline for Schooling at Home

Pastor-teacher Don Hargrove Faith Bible Church September 8, 2011

On Truth At Jeffrey C. King Rutgers University

A. Problem set #3 it has been posted and is due Tuesday, 15 November

God of the gaps: a neglected reply to God s stone problem

Module 02 Lecture - 10 Inferential Statistics Single Sample Tests

10.3 Universal and Existential Quantifiers

Chapters 21, 22: The Language of QL ("Quantifier Logic")

Logic is the study of the quality of arguments. An argument consists of a set of

Please complete the report by March 31

Curriculum Guide for Pre-Algebra

Intersubstitutivity Principles and the Generalization Function of Truth. Anil Gupta University of Pittsburgh. Shawn Standefer University of Melbourne

A BRIEF INTRODUCTION TO LOGIC FOR METAPHYSICIANS

Grade 7 Math Connects Suggested Course Outline for Schooling at Home 132 lessons

Basic Concepts and Skills!

An alternative understanding of interpretations: Incompatibility Semantics

Class 33 - November 13 Philosophy Friday #6: Quine and Ontological Commitment Fisher 59-69; Quine, On What There Is

Study Guides. Chapter 1 - Basic Training

HORWICH S MINIMALIST CONCEPTION OF TRUTH: Some Logical Difficulties

Artificial Intelligence: Valid Arguments and Proof Systems. Prof. Deepak Khemani. Department of Computer Science and Engineering

2.3. Failed proofs and counterexamples

Logic & Proofs. Chapter 3 Content. Sentential Logic Semantics. Contents: Studying this chapter will enable you to:

Exercise Sets. KS Philosophical Logic: Modality, Conditionals Vagueness. Dirk Kindermann University of Graz July 2014

Can Gödel s Incompleteness Theorem be a Ground for Dialetheism? *

SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.

What is the Nature of Logic? Judy Pelham Philosophy, York University, Canada July 16, 2013 Pan-Hellenic Logic Symposium Athens, Greece

SECTION 2 BASIC CONCEPTS

Today s Lecture 1/28/10

Quine: Quantifiers and Propositional Attitudes

Verification and Validation

Maudlin s Truth and Paradox Hartry Field

Josh Parsons MWF 10:00-10:50a.m., 194 Chemistry CRNs: Introduction to Philosophy, (eds.) Perry and Bratman

Necessity and Truth Makers

Complications for Categorical Syllogisms. PHIL 121: Methods of Reasoning February 27, 2013 Instructor:Karin Howe Binghamton University

Does Deduction really rest on a more secure epistemological footing than Induction?

Van Fraassen: Arguments concerning scientific realism

SYLLOGISTIC LOGIC CATEGORICAL PROPOSITIONS

Quine on the analytic/synthetic distinction

Artificial Intelligence I

Understanding Belief Reports. David Braun. In this paper, I defend a well-known theory of belief reports from an important objection.

Grade 6 correlated to Illinois Learning Standards for Mathematics

Philosophical Logic. LECTURE SEVEN MICHAELMAS 2017 Dr Maarten Steenhagen

Semantic Foundations for Deductive Methods

Informalizing Formal Logic

A flaw in Kripke s modal argument? Kripke states his modal argument against the description theory of names at a number

SUMMARY COMPARISON of 6 th grade Math texts approved for 2007 local Texas adoption

THE IMPLICATIONS OF PARACONSISTENCY

PHILOSOPHY 102 INTRODUCTION TO LOGIC PRACTICE EXAM 1. W# Section (10 or 11) 4. T F The statements that compose a disjunction are called conjuncts.

3. Negations Not: contradicting content Contradictory propositions Overview Connectives

Experimental Design. Introduction

5.6.1 Formal validity in categorical deductive arguments

Part II: How to Evaluate Deductive Arguments

Family Studies Center Methods Workshop

THE MEANING OF OUGHT. Ralph Wedgwood. What does the word ought mean? Strictly speaking, this is an empirical question, about the

In more precise language, we have both conditional statements and bi-conditional statements.

Exhaustification over Questions in Japanese

Ling 98a: The Meaning of Negation (Week 1)

Am I free? Freedom vs. Fate

Chapter 3: Basic Propositional Logic. Based on Harry Gensler s book For CS2209A/B By Dr. Charles Ling;

Glossary (for Constructing the World)

Revisiting the Socrates Example

Topics in Linguistic Theory: Propositional Attitudes

Tautological Necessity and Tautological Validity With Quantifiers

Application For Admission. Application Data. Payment Details

Day 3. Wednesday May 23, Learn the basic building blocks of proofs (specifically, direct proofs)

Assignment Assignment for Lesson 3.1

Overview. Is there a priori knowledge? No: Mill, Quine. Is there synthetic a priori knowledge? Yes: faculty of a priori intuition (Rationalism, Kant)

Haberdashers Aske s Boys School

The Semantic Paradoxes and the Paradoxes of Vagueness

A Liar Paradox. Richard G. Heck, Jr. Brown University

P. Weingartner, God s existence. Can it be proven? A logical commentary on the five ways of Thomas Aquinas, Ontos, Frankfurt Pp. 116.

Transcription:

Datalog P.J. McBrien Imperial College London P.J. McBrien (Imperial College London) Datalog 1 / 19

The Datalog Language Data Data is held as extensional predicates branch sortcode bname cash 56 Wimbledon 94340.45 34 Goodge St 8900.67 67 Strand 34005.00 account no type cname rate sortcode 100 current McBrien, P. NULL 67 101 deposit McBrien, P. 5.25 67 103 current Boyd, M. NULL 34 107 current Poulovassilis, A. NULL 56 119 deposit Poulovassilis, A. 5.50 56 125 current Bailey, J. NULL 56 movement mid no amount tdate 1000 100 2300.00 5/1/1999 1001 101 4000.00 5/1/1999 1002 100-223.45 8/1/1999 1004 107-100.00 11/1/1999 1005 103 145.50 12/1/1999 1006 100 10.23 15/1/1999 1007 107 345.56 15/1/1999 1008 101 1230.00 15/1/1999 1009 119 5600.00 18/1/1999 branch(56, Wimbledon, 94340.45). branch(34, Goodge St, 8900.67). branch(67, Strand, 34005.00). account(100, current, McBrien, P., null, 67). account(101, deposit, McBrien, P., 5.25, 67). account(103, current, Boyd, M., null, 34). account(107, current, Poulovassilis, A., null, 56). account(119, deposit, Poulovassilis, A., 5.50, 56). account(125, current, Bailey, J., null, 56). movement(1000, 100, 2300.00, 5/1/1999). movement(1001, 101, 4000.00, 5/1/1999). movement(1002, 100, 223.45, 8/1/1999). movement(1004, 107, 100.00, 11/1/1999). movement(1005, 103, 145.50, 12/1/1999). movement(1006, 100, 10.23, 15/1/1999). movement(1007, 107, 345.56, 15/1/1999). movement(1008, 101, 1230.00, 15/1/1999). movement(1009, 119, 5600.00, 18/1/1999). P.J. McBrien (Imperial College London) Datalog 2 / 19

The Datalog Language Rules Rules defined as intentional predicates current account(no, Name, Sortcode):- account(no, current, Name,, Sortcode). deposit account(no, Name, Rate, Sortcode):- account(no, deposit, Name, Rate, Sortcode). active customers(cname, BName):- branch(sortcode, BName, ), account(no,,cname,,sortcode), movement(,no,, ). Datalog Rules Datalog rules take the form Head:- Body. Logical semantics: if Body the Head Head must be a single predicate Body may be any conjunction of predicates. Naming of predicates and variables You cannot use the same name for intentional and extensional predicates Convention is the start predicate name with small letter Variables start with a capital letter A variable that only appears once can be replaced by P.J. McBrien (Imperial College London) Datalog 3 / 19

The Datalog Language Rules Quiz 1: Valid Datalog Knowledgebase Which Datalog Knowledgebase is invalid? A single male( Peter ). married to( Paul, Jane ). male(m):-married to(m, ). male(m):- single male(m). female(f):-married to(,f). female(f):- single female(f). C male( Peter ). male( Paul ). female( Jane ). married to( Paul, Jane ). B male( Peter ). married to( Paul, Jane ). male(m):-married to(m, ). female(f):-married to(,f). D married to( Peter, null). married to( Paul, Jane ). male(m):- married to(m, ), isnotnull(m). female(f):- married to(, F), isnotnull(f). P.J. McBrien (Imperial College London) Datalog 4 / 19

The Datalog Language Rules Model-Theoretic Interpretation deposit account(no, Name, Rate, Sortcode):- account(no, deposit, Name, Rate, Sortcode). account(100, current, McBrien, P., null, 67). account(101, deposit, McBrien, P., 5.25, 67). account(103, current, Boyd, M., null, 34). account(107, current, Poulovassilis, A., null, 56). account(119, deposit, Poulovassilis, A., 5.50, 56). account(125, current, Bailey, J., null, 56). If we can assign any combination of values to the variables, what is the minimum set of predicates that must be true. deposit account(101, McBrien, P., 5.25, 67). Is not a model, since it implies deposit account(119, Poulovassilis, A., 5.50, 56) is false, but deposit account(119, Poulovassilis, A., 5.50, 56) is true due to the rule for deposit account. P.J. McBrien (Imperial College London) Datalog 5 / 19

The Datalog Language Rules Model-Theoretic Interpretation deposit account(no, Name, Rate, Sortcode):- account(no, deposit, Name, Rate, Sortcode). account(100, current, McBrien, P., null, 67). account(101, deposit, McBrien, P., 5.25, 67). account(103, current, Boyd, M., null, 34). account(107, current, Poulovassilis, A., null, 56). account(119, deposit, Poulovassilis, A., 5.50, 56). account(125, current, Bailey, J., null, 56). If we can assign any combination of values to the variables, what is the minimum set of predicates that must be true. deposit account(101, McBrien, P., 5.25, 67). deposit account(119, Poulovassilis, A., 5.50, 56). deposit account(127, Poulovassilis, A., 4.50, 56). Is not a minimal model, since deposit account(127, Poulovassilis, A., 4.50, 56) could be made false, and the model still be consistent. P.J. McBrien (Imperial College London) Datalog 5 / 19

The Datalog Language Rules Model-Theoretic Interpretation deposit account(no, Name, Rate, Sortcode):- account(no, deposit, Name, Rate, Sortcode). account(100, current, McBrien, P., null, 67). account(101, deposit, McBrien, P., 5.25, 67). account(103, current, Boyd, M., null, 34). account(107, current, Poulovassilis, A., null, 56). account(119, deposit, Poulovassilis, A., 5.50, 56). account(125, current, Bailey, J., null, 56). If we can assign any combination of values to the variables, what is the minimum set of predicates that must be true. deposit account(101, McBrien, P., 5.25, 67). deposit account(119, Poulovassilis, A., 5.50, 56). Is a minimal model P.J. McBrien (Imperial College London) Datalog 5 / 19

The Datalog Language Rules Quiz 2: Datalog Queries active current account(no):- account(no, current,,, ), movement(,no,, ). What is the minimum model? A active current account(100). active current account(101). active current account(103). active current account(107). active current account(119). active current account(125). C active current account(100). active current account(103). active current account(107). active current account(125). B active current account(100). active current account(101). active current account(103). active current account(107). active current account(119). D active current account(100). active current account(103). active current account(107). P.J. McBrien (Imperial College London) Datalog 6 / 19

Datalog with Negation Datalog : Datalog with Negation Safe Negation Use infront of a predicate to mean that it must not hold. Any variable that appears in a negated predicate must have previously appeared in a non-negated predicate. Find accounts without any movements dormant account(no):- account(no,,,, ), movement(,no,, ). Unsafe dormant account(no):- movement(,no,, ). dormant account(125). P.J. McBrien (Imperial College London) Datalog 7 / 19

Datalog with Negation Quiz 3: Safe Datalog Predicates Which predicate uses safe negation? A non current accounts(no, Type):- account(no,type,,, ), Type = current. C non current accounts(no):- Type = current, account(no,type,,, ). B non current accounts(no, Type):- Type = current, account(no,type,,, ). D non current accounts(no, Type):- account(no,,,, ), Type = current. P.J. McBrien (Imperial College London) Datalog 8 / 19

Datalog with Negation Quiz 4: Datalog Queries (1) branch without recent debit(bname):- branch(sortcode, BName, ), account(no,,,,sortcode), account with recent debit(no). account with recent debit(no):- movement(, No, Value, TDate), Value < 0, TDate > 10/1/1999. What is the minimum model? A C branch without recent debit( Goodge St ). branch without recent debit( Strand ). B branch without recent debit( Wimbledon ). D branch without recent debit( Wimbledon ). branch without recent debit( Goodge St ). branch without recent debit( Strand ). P.J. McBrien (Imperial College London) Datalog 9 / 19

Datalog with Negation Quiz 5: Datalog Queries (2) branch without recent debit(bname):- branch(sortcode, BName, ), branch with recent debit(sortcode). branch with recent debit(sortcode):- account(no,,,,sortcode), movement(, No, Value, TDate), Value < 0, TDate > 10/1/1999. What is the minimum model? A C branch without recent debit( Goodge St ). branch without recent debit( Strand ). B branch without recent debit( Wimbledon ). D branch without recent debit( Wimbledon ). branch without recent debit( Goodge St ). branch without recent debit( Strand ). P.J. McBrien (Imperial College London) Datalog 10 / 19

Relational Algebra and Datalog Projection π RA projection is performed by only using a subset of rule body variables in the head of a rule. π sortcode account account sortcode(sortcode):- account(,,,,sortcode). account sortcode(34). account sortcode(56). account sortcode(67). P.J. McBrien (Imperial College London) Datalog 11 / 19

Relational Algebra and Datalog Selection σ RA selection is performed by naming a variable more than once, or by putting a data value in the rule body. σ amount>1000 movement big credit(mid, No, Amount, Date):- movement(mid, No, Amount, Date), Amount > 1000. big credit(1000, 100, 2300.00, 5/1/1999). big credit(1001, 101, 4000.00, 5/1/1999). big credit(1008, 101, 1230.00, 15/1/1999). big credit(1009, 119, 5600.00, 18/1/1999). P.J. McBrien (Imperial College London) Datalog 12 / 19

Relational Algebra and Datalog Product RA product is performed by naming two predicates in the rule body. branch σ rate>0 account product example(bsortcode, BName, Cash, No, Type, CName, Rate, ASortcode):- branch(bsortcode, BName, Cash), account(no, Type, CName, Rate, ASortcode), Rate > 0. (56, Wimbledon, 94340.45, 101, deposit, McBrien, P., 5.25, 67) (56, Wimbledon, 94340.45, 119, deposit, Poulovassilis, A., 5.50, 56) (34, Goodge St, 8900.67, 101, deposit, McBrien, P., 5.25, 67) (34, Goodge St, 8900.67, 119, deposit, Poulovassilis, A., 5.50, 56) (67, Strand, 34005.00, 101, deposit, McBrien, P., 5.25, 67) (67, Strand, 34005.00, 119, deposit, Poulovassilis, A., 5.50, 56) P.J. McBrien (Imperial College London) Datalog 13 / 19

Relational Algebra and Datalog Join RA join is performed by naming two predicates in the rule body, and then comparing their attributes. π bname,cname σ branch.sortcode=account.sortcode (branch account) branch customers(bname, CName):- branch(bsortcode, BName, ), account(,,cname,,asortcode), BSortcode = ASortcode. branch customers(bname, CName):- branch(sortcode, BName, ), account(,,cname,,sortcode). branch customers( Wimbledon, Poulovassilis, A. ). branch customers( Wimbledon, Bailey, J. ). branch customers( Goodge St, Boyd, M. ). branch customers( Strand, McBrien, P. ). P.J. McBrien (Imperial College London) Datalog 14 / 19

Relational Algebra and Datalog Quiz 6: Translating RA to Datalog π bname σ account.sortcode=branch.sortcode type= deposit (account branch) Which datalog rule for query is not equivalent to the above RA query? A query(bname):- account(, deposit,,,sortcode), branch(sortcode, BName, ). C query(bname):- branch(,bname, ). query(bname):- branch(sortcode, BName, ), account(, deposit,,,sortcode). B query(bname):- branch(sortcode1, BName, ), account(, deposit,,,sortcode2), Sortcode1 = Sortcode2. D query(bname):- branch(sortcode, BName, ), deposit branch(sortcode). deposit branch(sortcode):- account(, deposit,,,sortcode). P.J. McBrien (Imperial College London) Datalog 15 / 19

Relational Algebra and Datalog Quiz 7: Self Joins query(cname, CAcc, DAcc):- account(dacc, deposit, CName,, ), account(cacc, current, CName,, ). account no type cname rate sortcode 100 current McBrien, P. NULL 67 101 deposit McBrien, P. 5.25 67 103 current Boyd, M. NULL 34 107 current Poulovassilis, A. NULL 56 119 deposit Poulovassilis, A. 5.50 56 125 current Bailey, J. NULL 56 What is the result of the Datalog query? A CName CAcc DAcc B CName CAcc DAcc McBrien, P. 100 101 Poulovassilis, A. 107 119 C CName CAcc DAcc McBrien, P. 101 100 Poulovassilis, A. 119 107 D CName CAcc DAcc McBrien, P. 100 101 Boyd, M. 103 null Poulovassilis, A. 107 119 Bailey, J. 103 null P.J. McBrien (Imperial College London) Datalog 16 / 19

Relational Algebra and Datalog Union RA union is performed by having more than one rule definition for an intentional predicate. σ amount>1000 movement σ amount< 100 movement big movement(mid, No, Amount, Date):- movement(mid, No, Amount, Date), Amount > 1000. big movement(mid, No, Amount, Date):- movement(mid, No, Amount, Date), Amount < 100. big movement(1000, 100, 2300.00, 5/1/1999). big movement(1001, 101, 4000.00, 5/1/1999). big movement(1002, 100, 223.45, 8/1/1999). big movement(1008, 101, 1230.00, 15/1/1999). big movement(1009, 119, 5600.00, 18/1/1999). P.J. McBrien (Imperial College London) Datalog 17 / 19

Relational Algebra and Datalog Difference RA difference is performed using a negation on the predicate being subtracted : need Datalog. π no account π no movement dormant account(no):- account(no,,,, ), movement(,no,, ). dormant account(125). P.J. McBrien (Imperial College London) Datalog 18 / 19

Relational Algebra and Datalog Worksheet: Datalog branch sortcode bname cash 56 Wimbledon 94340.45 34 Goodge St 8900.67 67 Strand 34005.00 movement mid no amount tdate 1000 100 2300.00 5/1/1999 1001 101 4000.00 5/1/1999 1002 100-223.45 8/1/1999 1004 107-100.00 11/1/1999 1005 103 145.50 12/1/1999 1006 100 10.23 15/1/1999 1007 107 345.56 15/1/1999 1008 101 1230.00 15/1/1999 1009 119 5600.00 18/1/1999 account no type cname rate sortcode 100 current McBrien, P. NULL 67 101 deposit McBrien, P. 5.25 67 103 current Boyd, M. NULL 34 107 current Poulovassilis, A. NULL 56 119 deposit Poulovassilis, A. 5.50 56 125 current Bailey, J. NULL 56 key branch(sortcode) key branch(bname) key movement(mid) key account(no) movement(no) fk account(no) account(sortcode) fk branch(sortcode) P.J. McBrien (Imperial College London) Datalog 19 / 19