SlideShare a Scribd company logo
13
Most read
17
Most read
Facts, Rules and Queries in Prolog
overviewIntroductionSimple examplesProlog SyntaxAtomsNumbersVariablesComplex terms
Facts Roles and QueriesThere are only three basic constructs in Prolog: facts, rules, and queries. Prolog programming is all about writing knowledge bases.A collection of facts and rules is called a knowledge base (or a database)
Knowledge Base 1Knowledge Base 1 (KB1) is simply a collection of facts. Facts are used to state things that are unconditionally true of the domain of interest.Ex: woman(mia).        woman(jody).        woman(yolanda).        playsAirGuitar(jody). state that Mia, Jody, and Yolanda are women, and Jody plays air guitar.
Knowledge Base 1 KB1 can be used by posing queries.Ex: We can ask Prolog whether Mia is a woman by posing the query:?- woman(mia).Yeswe can ask whether Jody plays air guitar by posing the following query:?- playsAirGuitar(jody).Yes
Knowledge Base 2 Ex:listensToMusic(mia).      happy(yolanda).      playsAirGuitar(mia) :- listensToMusic(mia).     playsAirGuitar(yolanda) :- listensToMusic(yolanda).     listensToMusic(yolanda):- happy(yolanda).KB2 contains two facts: listensToMusic(mia) and happy(yolanda).
The last three    items are rules.Rules state information that is conditionally true of the domain of interest.
Knowledge Base 2 :- should be read as ``if'', or``is implied by''.The part on the left hand side of the :- is called the head of the rule.The part on the right hand side is called the body.Ex: We can ask Prolog whether Mia plays air guitar:?- playsAirGuitar(mia) Yes
Knowledge Base 3 KB3 consists of five clauses:happy(vincent).listensToMusic(butch).playsAirGuitar(vincent):-        listensToMusic(vincent),        happy(vincent).playsAirGuitar(butch):-        happy(butch).playsAirGuitar(butch):-       listensToMusic(butch).There are two facts, namely happy(vincent) and listensToMusic(butch), and threerules.
Knowledge Base 4KB4 contains no rules, only a collection of facts.woman(mia).woman(jody).woman(yolanda).loves(vincent,mia).loves(marcellus,mia).loves(pumpkin,honey_bunny).loves(honey_bunny,pumpkin).
Knowledge Base 4Ex: if we query ?- woman(X).Prolog reports back to us as follows:X = mia The first item in the knowledge base is woman(mia). So, Prolog matches X to mia, thus making thequery agree perfectly with this first item.
Knowledge Base 5Ex:loves(vincent,mia).loves(marcellus,mia).loves(pumpkin,honey_bunny).loves(honey_bunny,pumpkin).jealous(X,Y) :- loves(X,Z),loves(Y,Z).KB5 contains four facts about the loves relation and one rule.Knowledge Base 5In the previous example, It says that an individual X will be jealous of an individual Y if there is some individual Z that X loves, and Y loves that same individual Z too.Ex: ?- jealous(marcellus,W).This query asks: can you find an individual W such that Marcellus is jealous of W?Prolog will return the value W = vincent
Prolog syntaxThere are four kinds of terms in Prolog: atoms, numbers, variables, and complex terms (or structures). Atoms and numbers are lumped together under the heading constants, and constants and variables together make up the simple terms of Prolog.The upper-case letters are A, B, ..., Z; The lower-case letters are a, b, ..., z; The digits are 1, 2, ..., 9;The special characters are +, -, *, /, <, >,=, :, ., &, ~, and _.The _ character is called underscore. A string is an unbroken sequence of characters.
ATOMSAn atom is either:A string of characters made up of upper-case letters, lower-case letters, digits, and the underscore character, that begins with a lower-case letter.
An arbitrary sequence of character enclosed in single quotes. Ex: 'Vincent','The Gimp', ' A string of special characters. Five_Dollar_Shake', '&^%&#@$ &*', and ' '. For example: @= and ====> and ; and :- are all atoms. NUMBERSProlog implementations support Floating point numbers or floats (that is, representations of real numbers such as 1657.3087 or )
Integers (that is: ... -2, -1, 0, 1, 2, 3, ...) are useful for such tasks as counting the elements of a list.VARIABLESA variable is a string of :upper-case letterslower-case lettersdigits underscore characters that starts either with an upper-case letter or with underscore.
COMPLEX TERMSComplex terms are build out of a functor followed by a sequence of arguments. The arguments are put in ordinary brackets, separated by commas, and placed after the functor.The functor must be an atom. That is, variables cannot be used as functors. Arguments can be any kind of term.Ex: in the previous examplesplaysAirGuitar(jody) is a complex term: its functor is playsAirGuitarand its argument is jody.
Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net

More Related Content

PPT
prolog ppt
PPT
Prolog basics
PPTX
Overview prolog
PPTX
PROLOG: Cuts And Negation In Prolog
PPT
Prolog 01
PPT
Predlogic
PPTX
PROLOG: Introduction To Prolog
PPT
Chaps 1-3-ai-prolog
prolog ppt
Prolog basics
Overview prolog
PROLOG: Cuts And Negation In Prolog
Prolog 01
Predlogic
PROLOG: Introduction To Prolog
Chaps 1-3-ai-prolog

What's hot (20)

PDF
10 logic+programming+with+prolog
PPTX
Prolog Programming : Basics
PPT
Introduction to logic and prolog - Part 1
PPTX
Prolog 7-Languages
PPT
Introduction to prolog
PDF
Logic programming (1)
PPTX
Logic
 
PPTX
Lesson 03 Arbitrarily Recursive Data Definitions
PPT
Erlang Concurrency
PPT
Mathematical Logic Part 2
PDF
Ai lab manual
PPT
Bab 1 proposisi
DOCX
Artificial Intelligence Lab File
PPT
Predicate logic_2(Artificial Intelligence)
PDF
Regular expression
PPT
Predicate calculus
PPTX
Knowledge representation and Predicate logic
PPT
L03 ai - knowledge representation using logic
10 logic+programming+with+prolog
Prolog Programming : Basics
Introduction to logic and prolog - Part 1
Prolog 7-Languages
Introduction to prolog
Logic programming (1)
Logic
 
Lesson 03 Arbitrarily Recursive Data Definitions
Erlang Concurrency
Mathematical Logic Part 2
Ai lab manual
Bab 1 proposisi
Artificial Intelligence Lab File
Predicate logic_2(Artificial Intelligence)
Regular expression
Predicate calculus
Knowledge representation and Predicate logic
L03 ai - knowledge representation using logic
Ad

Similar to PROLOG: Fact Roles And Queries In Prolog (20)

PPTX
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
PPT
________ ________1.ppt
PPTX
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
PDF
Prolog,Prolog Programming IN AI.pdf
PDF
PROLOG in artificial intelligence(Basic of pprolog)).pdf
DOCX
AI Lab Manual.docx
PDF
Prolog PPT_merged.pdf
PPT
Introduction to prolog
PPT
Introduction toprolog
PPT
Introduction to prolog
PPT
Introduction toprolog
PPT
Introduction toprolog
PPT
Introduction toprolog
PPT
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
PPT
Chaps 1-3-ai-prolog
PPTX
Plc part 4
PPTX
ProLog (Artificial Intelligence) Introduction
PPTX
Prolog language programming in the facts.pptx
PPTX
Introduction to Prolog
PPTX
Artificial Intelligence and Expert System
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
________ ________1.ppt
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
Prolog,Prolog Programming IN AI.pdf
PROLOG in artificial intelligence(Basic of pprolog)).pdf
AI Lab Manual.docx
Prolog PPT_merged.pdf
Introduction to prolog
Introduction toprolog
Introduction to prolog
Introduction toprolog
Introduction toprolog
Introduction toprolog
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
Chaps 1-3-ai-prolog
Plc part 4
ProLog (Artificial Intelligence) Introduction
Prolog language programming in the facts.pptx
Introduction to Prolog
Artificial Intelligence and Expert System
Ad

More from PROLOG CONTENT (6)

PPTX
PROLOG: Database Manipulation In Prolog
PPTX
Prolog: Cuts And Negation In Prolog
PPTX
PROLOG: Clauses Grammer In Prolog
PPTX
Prolog: Arithmetic Operations In Prolog
PPTX
PROLOG: Matching And Proof Search In Prolog
PPTX
PROLOG: Recursion And Lists In Prolog
PROLOG: Database Manipulation In Prolog
Prolog: Cuts And Negation In Prolog
PROLOG: Clauses Grammer In Prolog
Prolog: Arithmetic Operations In Prolog
PROLOG: Matching And Proof Search In Prolog
PROLOG: Recursion And Lists In Prolog

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx

PROLOG: Fact Roles And Queries In Prolog

  • 1. Facts, Rules and Queries in Prolog
  • 3. Facts Roles and QueriesThere are only three basic constructs in Prolog: facts, rules, and queries. Prolog programming is all about writing knowledge bases.A collection of facts and rules is called a knowledge base (or a database)
  • 4. Knowledge Base 1Knowledge Base 1 (KB1) is simply a collection of facts. Facts are used to state things that are unconditionally true of the domain of interest.Ex: woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). state that Mia, Jody, and Yolanda are women, and Jody plays air guitar.
  • 5. Knowledge Base 1 KB1 can be used by posing queries.Ex: We can ask Prolog whether Mia is a woman by posing the query:?- woman(mia).Yeswe can ask whether Jody plays air guitar by posing the following query:?- playsAirGuitar(jody).Yes
  • 6. Knowledge Base 2 Ex:listensToMusic(mia). happy(yolanda). playsAirGuitar(mia) :- listensToMusic(mia). playsAirGuitar(yolanda) :- listensToMusic(yolanda). listensToMusic(yolanda):- happy(yolanda).KB2 contains two facts: listensToMusic(mia) and happy(yolanda).
  • 7. The last three items are rules.Rules state information that is conditionally true of the domain of interest.
  • 8. Knowledge Base 2 :- should be read as ``if'', or``is implied by''.The part on the left hand side of the :- is called the head of the rule.The part on the right hand side is called the body.Ex: We can ask Prolog whether Mia plays air guitar:?- playsAirGuitar(mia) Yes
  • 9. Knowledge Base 3 KB3 consists of five clauses:happy(vincent).listensToMusic(butch).playsAirGuitar(vincent):- listensToMusic(vincent), happy(vincent).playsAirGuitar(butch):- happy(butch).playsAirGuitar(butch):- listensToMusic(butch).There are two facts, namely happy(vincent) and listensToMusic(butch), and threerules.
  • 10. Knowledge Base 4KB4 contains no rules, only a collection of facts.woman(mia).woman(jody).woman(yolanda).loves(vincent,mia).loves(marcellus,mia).loves(pumpkin,honey_bunny).loves(honey_bunny,pumpkin).
  • 11. Knowledge Base 4Ex: if we query ?- woman(X).Prolog reports back to us as follows:X = mia The first item in the knowledge base is woman(mia). So, Prolog matches X to mia, thus making thequery agree perfectly with this first item.
  • 12. Knowledge Base 5Ex:loves(vincent,mia).loves(marcellus,mia).loves(pumpkin,honey_bunny).loves(honey_bunny,pumpkin).jealous(X,Y) :- loves(X,Z),loves(Y,Z).KB5 contains four facts about the loves relation and one rule.Knowledge Base 5In the previous example, It says that an individual X will be jealous of an individual Y if there is some individual Z that X loves, and Y loves that same individual Z too.Ex: ?- jealous(marcellus,W).This query asks: can you find an individual W such that Marcellus is jealous of W?Prolog will return the value W = vincent
  • 13. Prolog syntaxThere are four kinds of terms in Prolog: atoms, numbers, variables, and complex terms (or structures). Atoms and numbers are lumped together under the heading constants, and constants and variables together make up the simple terms of Prolog.The upper-case letters are A, B, ..., Z; The lower-case letters are a, b, ..., z; The digits are 1, 2, ..., 9;The special characters are +, -, *, /, <, >,=, :, ., &, ~, and _.The _ character is called underscore. A string is an unbroken sequence of characters.
  • 14. ATOMSAn atom is either:A string of characters made up of upper-case letters, lower-case letters, digits, and the underscore character, that begins with a lower-case letter.
  • 15. An arbitrary sequence of character enclosed in single quotes. Ex: 'Vincent','The Gimp', ' A string of special characters. Five_Dollar_Shake', '&^%&#@$ &*', and ' '. For example: @= and ====> and ; and :- are all atoms. NUMBERSProlog implementations support Floating point numbers or floats (that is, representations of real numbers such as 1657.3087 or )
  • 16. Integers (that is: ... -2, -1, 0, 1, 2, 3, ...) are useful for such tasks as counting the elements of a list.VARIABLESA variable is a string of :upper-case letterslower-case lettersdigits underscore characters that starts either with an upper-case letter or with underscore.
  • 17. COMPLEX TERMSComplex terms are build out of a functor followed by a sequence of arguments. The arguments are put in ordinary brackets, separated by commas, and placed after the functor.The functor must be an atom. That is, variables cannot be used as functors. Arguments can be any kind of term.Ex: in the previous examplesplaysAirGuitar(jody) is a complex term: its functor is playsAirGuitarand its argument is jody.
  • 18. Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net