SlideShare a Scribd company logo
1 of 12
CSE240 – Introduction to
Programming Languages
Lecture 23:
Programming with Prolog II
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Install a Prolog Interpreter
SWI - Prolog
http://www.swi-prolog.org/download/stable
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Install a Prolog Interpreter
To enter rules from the command line, type this :
[user].
This puts you in a mode where you can enter facts and rules. Otherwise you get this kind of
message:
ERROR: Undefined procedure: (DWIM could not correct goal)
You can then enter facts (or rules) e.g. :
father(me,sarah).
After having entered the knowledge, type CONTROL-D to come back to the mode where you
can enter questions. Then you can ask:
?- father(me,X).
X = sarah
To quit:
halt.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Online Prolog Interpreter
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Natural Language Predicate Logic Type of Predicate
A car is fast. fast(car). fact
A rose is red. red(rose). fact
Bill likes the car if the car is fast. likes(bill, car) :- fast(car). rule
Humidity is high if it rains high(humidity):- rains(). rule
Jane is mother of Elaine mother_of(jane, elaine). fact
Jane is mother of Mike mother_of(jane, mike). fact
David is father of Jesse father_of(david, jesse). fact
Jesse is father of Obed father_of(jesse, obed). fact
Grandmother X of Z if (X is mother of Y
and (Y is mother of Z or Y is father of Z)
grandmother_of(X, Z) :- mother_of(X, Y),
( mother_of(Y, Z); father_of(Y, Z) ).
rule
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
Predicate Logic
• Facts: What is known, e.g.,
Bill likes car and bike, and he travels with one of them
likes(bill, car), likes(bill, bike)
travels(bill, car); travels(bill, bike)
• Rules: What you can infer from the given facts. Rules enable you to
infer facts from other facts, e.g.,
Bill is the father of Joe, if Joe is the son of bill.
father(bill, joe) :- son(joe, bill).
, means AND
; means OR
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7
Prolog
• PROLOG (PROgramming LOGic)
• Interpreter.
• Deductive database: set of statements and a deduction system.
• Facts and Rules
• Queries
• Upper-Case variables
• Lower-Case constants and names
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
Simple Facts
• Facts and rules creates a database, so, step 1, provide data
% facts:
exam_easy.
arizona_hot.
july_4_is_independence_day.
• step 2, run queries
?- exam_easy.
true
?- arizona_hot.
true
?- july_4_is_independence_day
true
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9
Facts with Arguments
likes(john,mary).
eats(fred,oranges).
age(john,32).
age(ian,2).
?- eats(fred,oranges).
true
?- eats(mike,apples).
false
?- age(ian,two).
false
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10
Facts with Arguments
likes(john,mary).
eats(fred,oranges).
age(john,32).
age(ian,2).
?- eats(fred,X).
X = oranges
?- eats(mike,X).
false
?- age(ian,Y).
Y = 2
?- likes (WhoX, WhoY).
WhoX = john,
WhoY = mary
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11
Facts and Rules
% rules and facts:
mortal(X) :- human(X).
human(socrates).
?- mortal(socrates).
true
?- mortal(P).
P = socrates
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

More Related Content

Similar to 201801 CSE240 Lecture 23

Dutch Specflow Users Meetup - Shared understanding
Dutch Specflow Users Meetup - Shared understandingDutch Specflow Users Meetup - Shared understanding
Dutch Specflow Users Meetup - Shared understandingMark Taling
 
Behind the Curtain: Real-world HR Tech Implementations and What You Need to ...
Behind the Curtain: Real-world HR Tech Implementations and What You Need to  ...Behind the Curtain: Real-world HR Tech Implementations and What You Need to  ...
Behind the Curtain: Real-world HR Tech Implementations and What You Need to ...bhropen
 
Improve your productivity with Microsoft Fow - Power to the people
Improve your productivity with Microsoft Fow - Power to the peopleImprove your productivity with Microsoft Fow - Power to the people
Improve your productivity with Microsoft Fow - Power to the peopleserge luca
 
Torq Systems - Salesforce: Sales Cloud Packages
Torq Systems - Salesforce: Sales Cloud PackagesTorq Systems - Salesforce: Sales Cloud Packages
Torq Systems - Salesforce: Sales Cloud PackagesKyler Miles
 
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...Texavi Innovative Solutions
 
Implementing SunGard Banner Voice Response
Implementing SunGard Banner Voice ResponseImplementing SunGard Banner Voice Response
Implementing SunGard Banner Voice Responseegrong
 
SAP BusinessObjects Bi4 migration pack
SAP BusinessObjects Bi4 migration packSAP BusinessObjects Bi4 migration pack
SAP BusinessObjects Bi4 migration packSebastien Goiffon
 
Apex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedApex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedCarolEnLaNube
 
Improving the development process with metrics driven insights presentation
Improving the development process with metrics driven insights presentationImproving the development process with metrics driven insights presentation
Improving the development process with metrics driven insights presentationindeedeng
 
Use dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application codeUse dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application codeDataWorks Summit
 
How to get Automated Testing "Done"
How to get Automated Testing "Done"How to get Automated Testing "Done"
How to get Automated Testing "Done"TEST Huddle
 
OBIEE Online Training in USA
OBIEE Online Training in USAOBIEE Online Training in USA
OBIEE Online Training in USAUgs8008
 
Mozilla Foundation Metrics - presentation to engineers
Mozilla Foundation Metrics - presentation to engineersMozilla Foundation Metrics - presentation to engineers
Mozilla Foundation Metrics - presentation to engineersJohn Schneider
 
Luminate Online Best Practices for Beginners
Luminate Online Best Practices for BeginnersLuminate Online Best Practices for Beginners
Luminate Online Best Practices for BeginnersBlackbaud
 
Certification exams 712 50 braindumps
Certification exams 712 50 braindumpsCertification exams 712 50 braindumps
Certification exams 712 50 braindumpsadam_jhon
 
Lead Time: What We Know About It...
Lead Time: What We Know About It...Lead Time: What We Know About It...
Lead Time: What We Know About It...azheglov
 

Similar to 201801 CSE240 Lecture 23 (20)

Intro to Workflow Formulas
Intro to Workflow FormulasIntro to Workflow Formulas
Intro to Workflow Formulas
 
Dutch Specflow Users Meetup - Shared understanding
Dutch Specflow Users Meetup - Shared understandingDutch Specflow Users Meetup - Shared understanding
Dutch Specflow Users Meetup - Shared understanding
 
Behind the Curtain: Real-world HR Tech Implementations and What You Need to ...
Behind the Curtain: Real-world HR Tech Implementations and What You Need to  ...Behind the Curtain: Real-world HR Tech Implementations and What You Need to  ...
Behind the Curtain: Real-world HR Tech Implementations and What You Need to ...
 
Improve your productivity with Microsoft Fow - Power to the people
Improve your productivity with Microsoft Fow - Power to the peopleImprove your productivity with Microsoft Fow - Power to the people
Improve your productivity with Microsoft Fow - Power to the people
 
Torq Systems - Salesforce: Sales Cloud Packages
Torq Systems - Salesforce: Sales Cloud PackagesTorq Systems - Salesforce: Sales Cloud Packages
Torq Systems - Salesforce: Sales Cloud Packages
 
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...
Deep Dive into Software Estimation - Texavi Tech Bootcamp on How to be a good...
 
Implementing SunGard Banner Voice Response
Implementing SunGard Banner Voice ResponseImplementing SunGard Banner Voice Response
Implementing SunGard Banner Voice Response
 
201801 CSE240 Lecture 03
201801 CSE240 Lecture 03201801 CSE240 Lecture 03
201801 CSE240 Lecture 03
 
SAP BusinessObjects Bi4 migration pack
SAP BusinessObjects Bi4 migration packSAP BusinessObjects Bi4 migration pack
SAP BusinessObjects Bi4 migration pack
 
Apex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedApex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex Liberated
 
Improving the development process with metrics driven insights presentation
Improving the development process with metrics driven insights presentationImproving the development process with metrics driven insights presentation
Improving the development process with metrics driven insights presentation
 
Use dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application codeUse dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application code
 
201505 CSE340 Lecture 05
201505 CSE340 Lecture 05201505 CSE340 Lecture 05
201505 CSE340 Lecture 05
 
How to get Automated Testing "Done"
How to get Automated Testing "Done"How to get Automated Testing "Done"
How to get Automated Testing "Done"
 
OBIEE Online Training in USA
OBIEE Online Training in USAOBIEE Online Training in USA
OBIEE Online Training in USA
 
Mozilla Foundation Metrics - presentation to engineers
Mozilla Foundation Metrics - presentation to engineersMozilla Foundation Metrics - presentation to engineers
Mozilla Foundation Metrics - presentation to engineers
 
Luminate Online Best Practices for Beginners
Luminate Online Best Practices for BeginnersLuminate Online Best Practices for Beginners
Luminate Online Best Practices for Beginners
 
Tf itpptbo
Tf itpptboTf itpptbo
Tf itpptbo
 
Certification exams 712 50 braindumps
Certification exams 712 50 braindumpsCertification exams 712 50 braindumps
Certification exams 712 50 braindumps
 
Lead Time: What We Know About It...
Lead Time: What We Know About It...Lead Time: What We Know About It...
Lead Time: What We Know About It...
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 
201801 CSE240 Lecture 08
201801 CSE240 Lecture 08201801 CSE240 Lecture 08
201801 CSE240 Lecture 08
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 

201801 CSE240 Lecture 23

  • 1. CSE240 – Introduction to Programming Languages Lecture 23: Programming with Prolog II Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Install a Prolog Interpreter SWI - Prolog http://www.swi-prolog.org/download/stable
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Install a Prolog Interpreter To enter rules from the command line, type this : [user]. This puts you in a mode where you can enter facts and rules. Otherwise you get this kind of message: ERROR: Undefined procedure: (DWIM could not correct goal) You can then enter facts (or rules) e.g. : father(me,sarah). After having entered the knowledge, type CONTROL-D to come back to the mode where you can enter questions. Then you can ask: ?- father(me,X). X = sarah To quit: halt.
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Online Prolog Interpreter
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Natural Language Predicate Logic Type of Predicate A car is fast. fast(car). fact A rose is red. red(rose). fact Bill likes the car if the car is fast. likes(bill, car) :- fast(car). rule Humidity is high if it rains high(humidity):- rains(). rule Jane is mother of Elaine mother_of(jane, elaine). fact Jane is mother of Mike mother_of(jane, mike). fact David is father of Jesse father_of(david, jesse). fact Jesse is father of Obed father_of(jesse, obed). fact Grandmother X of Z if (X is mother of Y and (Y is mother of Z or Y is father of Z) grandmother_of(X, Z) :- mother_of(X, Y), ( mother_of(Y, Z); father_of(Y, Z) ). rule
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 Predicate Logic • Facts: What is known, e.g., Bill likes car and bike, and he travels with one of them likes(bill, car), likes(bill, bike) travels(bill, car); travels(bill, bike) • Rules: What you can infer from the given facts. Rules enable you to infer facts from other facts, e.g., Bill is the father of Joe, if Joe is the son of bill. father(bill, joe) :- son(joe, bill). , means AND ; means OR
  • 7. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7 Prolog • PROLOG (PROgramming LOGic) • Interpreter. • Deductive database: set of statements and a deduction system. • Facts and Rules • Queries • Upper-Case variables • Lower-Case constants and names
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 Simple Facts • Facts and rules creates a database, so, step 1, provide data % facts: exam_easy. arizona_hot. july_4_is_independence_day. • step 2, run queries ?- exam_easy. true ?- arizona_hot. true ?- july_4_is_independence_day true
  • 9. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9 Facts with Arguments likes(john,mary). eats(fred,oranges). age(john,32). age(ian,2). ?- eats(fred,oranges). true ?- eats(mike,apples). false ?- age(ian,two). false
  • 10. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10 Facts with Arguments likes(john,mary). eats(fred,oranges). age(john,32). age(ian,2). ?- eats(fred,X). X = oranges ?- eats(mike,X). false ?- age(ian,Y). Y = 2 ?- likes (WhoX, WhoY). WhoX = john, WhoY = mary
  • 11. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11 Facts and Rules % rules and facts: mortal(X) :- human(X). human(socrates). ?- mortal(socrates). true ?- mortal(P). P = socrates
  • 12. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.