SlideShare a Scribd company logo
1 of 12
Download to read offline
Formal Logic




        Mathematical Structures
         for Computer Science
                Chapter 1	





Copyright © 2006 W.H. Freeman & Co.       MSCS Slides   Formal Logic
Declarative Programming Languages

     ●        A declarative language is based on predicate logic.	

     ●        A program written in a declarative language consists
              only of statements (actually predicate wffs) that are
              declared as hypotheses.	

     ●        Execution of a declarative program allows the user to
              pose queries, asking for information about possible
              conclusions that can be derived from the hypotheses.	

     ●        After obtaining the user’s query, the language turns on
              its “inference engine” and applies its rules of inference
              to the hypotheses to see which conclusions fit the
              user’s query.	




Section 1.5                            Logic Programming                  1
Prolog
     ●        Prolog (PROgramming in LOGic) is a declarative
              programming language.	

     ●        The set of declarations that constitutes a Prolog program is
              also known as a Prolog database.	

     ●        Items in a Prolog database are either facts or rules.	

     ●        Example of Prolog facts (a binary predicate called “eat”):	

              ■  eat (bear, fish)	

              ■  eat (bear, fox)	

              ■  eat (deer, grass)	

     ●        “bear,” “fish,” “fox,” “deer,” and “grass” are constants
              because they represent specific elements in the domain.	




Section 1.5                              Logic Programming                    2
Prolog

     ●        Other facts that we could add to the Prolog database:	

              ■    animal (bear)	

              ■    animal (fish)	

              ■    animal (fox)	

              ■    animal (deer)	

              ■    plant (grass)	

     ●        We can now pose some simple queries. 	

              ■    is (eat (deer, grass))	

                     •  yes	

              ■    is (eat (bear, rabbit))	

                     •  no	


     ●        “is” asks if the fact exists in the database.	




Section 1.5                                       Logic Programming      3
Prolog

     ●        Queries may include variables, for example:	

               ■    which(x: eat(bear, x))	

     ●        produces:	

               ■    fish	

               ■    fox	

     ●        The second type of item in a Prolog database is a
              Prolog rule. 	

     ●        A rule is a description of a predicate by means of an
              implication. 	





Section 1.5                                     Logic Programming     4
Prolog Rules

     ●        For example, we might use a rule to define a predicate
              of prey:	

              ■    prey(x) if eat(y, x) and animal(x)	

     ●        This says that x is a prey if it is an animal that is eaten.
              If we add this rule to our database, then in response to
              the query:	

              ■    which(x: prey(x))	

     ●        we would get:	

              ■    fish	

              ■    fox	





Section 1.5                                 Logic Programming                5
Horn Clauses and Resolution

     ●        We can describe the facts in our database by the wffs	

              ■    E(b, fi)	

              ■    E(b, fo)	

              ■    E(d, g)	

              ■    A(b)	

              ■    A( fi)	

              ■    A( fo)	

              ■    A(d)	

              ■    P(g)	

              ■    with the rule: E(y, x) Λ A(x) → Pr (x)	

     ●        Prolog treats the rule as being universally quantified
              and uses universal instantiation to strip off the
              universal quantifiers:	

              ■    (∀y)(∀x)[E(y, x) Λ A(x) → Pr(x)]	


Section 1.5                                    Logic Programming         6
Horn Clauses and Resolution

     ●        A Horn clause is a wff composed of predicates or the
              negations of predicates (with either variables or
              constants as arguments) joined by disjunctions, where,
              at most, one predicate is unnegated.	

     ●        Example of Horn clause:	

              ■    [E(y, x)]ʹ′ V [A(x)]ʹ′ V Pr(x)	

     ●        This can be rewritten using DeMorgan’s law as	

              ■    [E(y,x) Λ A(x)] V Pr(x)	

     ●        This is equivalent to:	

              ■    E(y, x) Λ A(x) → Pr(x)	

     ●        The above is a rule in the Prolog program.	



Section 1.5                                    Logic Programming       7
Horn Clauses and Resolution
     ●        The rule of inference used by Prolog is called resolution.	

     ●        Two Horn clauses in a Prolog database are resolved into a new Horn
              clause if one contains an unnegated predicate that matches a negated
              predicate in the other clause.	

     ●        For example: 	

                      •  A(a)	

                      •  [A(a)]ʹ′ V B(b) 	

               ■    is equivalent to:	

                      •  A(a), A(a) → B(b) 	

               ■    Prolog infers:	

                      •  B(b)	

     ●        which is just an application of modus ponens.	

     ●        Therefore, Prolog’s rule of inference includes modus ponens as
              a special case.	



Section 1.5                                      Logic Programming                   8
Recursion
     ●        Prolog rules are implications. 	

     ●        Their antecedents may depend on facts or other rules.	

     ●        The antecedent of a rule may also depend on that rule
              itself, in which case the rule is defined in terms of itself.	

     ●        For example, we can then define a binary relation in-food-
              chain(x, y), meaning “y is in x’s food chain.” This means
              one of two things:	

              1.     x eats y directly.	

              2.     x eats something that eats something that eats something ...
                       that eats y. 	

                    	

This can also be stated as:	

              2.     x eats z and y is in z’s food chain.	




Section 1.5                                  Logic Programming                      9
Recursion
     ●        Case (1) is simple to test from our existing facts, but without (2), in-
              food-chain means nothing different than eat.	

     ●        On the other hand, (2) without (1) sends us down an infinite path of
              something eating something eating something and so on, with nothing
              telling us when to stop.	

     ●        Recursive definitions always need a stopping point that consists of
              specific information.	

     ●        The Prolog rule for in-food-chain incorporates (1) and (2):	

               ■   in-food-chain(x, y) if eat(x, y)	

               ■   in-food-chain(x, y) if eat(x, z) and in-food-chain(z, y)	

     ●        is a recursive rule because it defines the predicate in-food-chain
              in terms of in-food-chain.	





Section 1.5                                    Logic Programming                         10
Expert Systems
     ●        Many interesting applications programs have been
              developed, in Prolog and similar logic programming
              languages, that gather a database of facts and rules about
              some domain and then use this database to draw
              conclusions.	

     ●        Such programs are known as expert systems, knowledge-
              based systems, or rule-based systems.	

     ●        The database in an expert system attempts to capture the
              knowledge (“elicit the expertise”) of a human expert in a
              particular field.	

     ●        This includes both the facts known to the expert and the
              expert’s reasoning path in reaching conclusions from those
              facts.	



Section 1.5                             Logic Programming                  11

More Related Content

What's hot (8)

Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
20110930 information retrieval raskovalov_lecture1
20110930 information retrieval raskovalov_lecture120110930 information retrieval raskovalov_lecture1
20110930 information retrieval raskovalov_lecture1
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020
 
QwalKeko, a History Querying Tool
QwalKeko, a History Querying ToolQwalKeko, a History Querying Tool
QwalKeko, a History Querying Tool
 
ICLP-DC12
ICLP-DC12ICLP-DC12
ICLP-DC12
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
 
Most Asked Python Interview Questions
Most Asked Python Interview QuestionsMost Asked Python Interview Questions
Most Asked Python Interview Questions
 

Viewers also liked

Expocision elementos y hosting
Expocision elementos y hostingExpocision elementos y hosting
Expocision elementos y hosting
tatianagomezdiaz
 
¿Qué es un doctorado? Explicación visual
¿Qué es un doctorado? Explicación visual¿Qué es un doctorado? Explicación visual
¿Qué es un doctorado? Explicación visual
CBRE España
 
MATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
MATC ACE Syllabus-Grant Writing Essentials_ArthurUphamMATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
MATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
Arthur Upham
 
3927 IIJ - Programme Guide 2015-v8
3927 IIJ - Programme Guide 2015-v83927 IIJ - Programme Guide 2015-v8
3927 IIJ - Programme Guide 2015-v8
Colin J. O'Sullivan
 
1 la sdr pedre¥a va a por la trainera-carta a los socios
1 la sdr pedre¥a va a por la trainera-carta a los socios1 la sdr pedre¥a va a por la trainera-carta a los socios
1 la sdr pedre¥a va a por la trainera-carta a los socios
Nombre Apellidos
 
Turning Pages Presentation Rtfacts
Turning Pages Presentation RtfactsTurning Pages Presentation Rtfacts
Turning Pages Presentation Rtfacts
rogerpayton
 
Neuroformación mailpermission 5
Neuroformación mailpermission 5Neuroformación mailpermission 5
Neuroformación mailpermission 5
Miguel Ángel Gago
 
Simulation and Surveillance: The Transformation of Government and Control in ...
Simulation and Surveillance: The Transformation of Government and Control in ...Simulation and Surveillance: The Transformation of Government and Control in ...
Simulation and Surveillance: The Transformation of Government and Control in ...
Nikolaos Vaslamatzis
 
Savoy Studios Custom Hospitality Lighting
Savoy Studios Custom Hospitality LightingSavoy Studios Custom Hospitality Lighting
Savoy Studios Custom Hospitality Lighting
marcus mccoy
 

Viewers also liked (20)

Chapter 19 Wound Management, Stoma And Incontinence Products
Chapter 19    Wound  Management,  Stoma And  Incontinence  ProductsChapter 19    Wound  Management,  Stoma And  Incontinence  Products
Chapter 19 Wound Management, Stoma And Incontinence Products
 
Apollo Insulation Aluminum Composite Foils - Catalog 2012
Apollo Insulation Aluminum Composite Foils - Catalog 2012Apollo Insulation Aluminum Composite Foils - Catalog 2012
Apollo Insulation Aluminum Composite Foils - Catalog 2012
 
Expocision elementos y hosting
Expocision elementos y hostingExpocision elementos y hosting
Expocision elementos y hosting
 
¿Qué es un doctorado? Explicación visual
¿Qué es un doctorado? Explicación visual¿Qué es un doctorado? Explicación visual
¿Qué es un doctorado? Explicación visual
 
Programa de alianzas estratégicas
Programa de alianzas estratégicasPrograma de alianzas estratégicas
Programa de alianzas estratégicas
 
MATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
MATC ACE Syllabus-Grant Writing Essentials_ArthurUphamMATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
MATC ACE Syllabus-Grant Writing Essentials_ArthurUpham
 
3927 IIJ - Programme Guide 2015-v8
3927 IIJ - Programme Guide 2015-v83927 IIJ - Programme Guide 2015-v8
3927 IIJ - Programme Guide 2015-v8
 
1 la sdr pedre¥a va a por la trainera-carta a los socios
1 la sdr pedre¥a va a por la trainera-carta a los socios1 la sdr pedre¥a va a por la trainera-carta a los socios
1 la sdr pedre¥a va a por la trainera-carta a los socios
 
Cyf1
Cyf1Cyf1
Cyf1
 
Poesia de la vaca
Poesia de la vacaPoesia de la vaca
Poesia de la vaca
 
Turning Pages Presentation Rtfacts
Turning Pages Presentation RtfactsTurning Pages Presentation Rtfacts
Turning Pages Presentation Rtfacts
 
Impactia, evaluar la actividad científica del SSPA
Impactia, evaluar la actividad científica del SSPAImpactia, evaluar la actividad científica del SSPA
Impactia, evaluar la actividad científica del SSPA
 
Como iniciar-la-lectoescritura-en-los-niños-jugando
Como iniciar-la-lectoescritura-en-los-niños-jugandoComo iniciar-la-lectoescritura-en-los-niños-jugando
Como iniciar-la-lectoescritura-en-los-niños-jugando
 
Pure products pamphlets new
Pure products pamphlets newPure products pamphlets new
Pure products pamphlets new
 
Neuroformación mailpermission 5
Neuroformación mailpermission 5Neuroformación mailpermission 5
Neuroformación mailpermission 5
 
Creacions fotogràfiques a partir de frases fetes
Creacions fotogràfiques a partir de frases fetesCreacions fotogràfiques a partir de frases fetes
Creacions fotogràfiques a partir de frases fetes
 
Simulation and Surveillance: The Transformation of Government and Control in ...
Simulation and Surveillance: The Transformation of Government and Control in ...Simulation and Surveillance: The Transformation of Government and Control in ...
Simulation and Surveillance: The Transformation of Government and Control in ...
 
C.roseus paper
C.roseus paperC.roseus paper
C.roseus paper
 
Enhancing input on and above the interactive surface
Enhancing input on and above the interactive surfaceEnhancing input on and above the interactive surface
Enhancing input on and above the interactive surface
 
Savoy Studios Custom Hospitality Lighting
Savoy Studios Custom Hospitality LightingSavoy Studios Custom Hospitality Lighting
Savoy Studios Custom Hospitality Lighting
 

Similar to CPSC 125 Ch 1 Sec 5

Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
Nitesh Singh
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
Pierre de Lacaze
 

Similar to CPSC 125 Ch 1 Sec 5 (19)

#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
 
Family Tree on PROLOG
Family Tree on PROLOGFamily Tree on PROLOG
Family Tree on PROLOG
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
Prolog
Prolog Prolog
Prolog
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Prolog final
Prolog finalProlog final
Prolog final
 
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
 
Tutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsTutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and Systems
 
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptxARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
 
A scalable ontology reasoner via incremental materialization
A scalable ontology reasoner via incremental materializationA scalable ontology reasoner via incremental materialization
A scalable ontology reasoner via incremental materialization
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : Basics
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System
 
Python Training
Python TrainingPython Training
Python Training
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in Logic
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & Prolog
 

More from David Wood

Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
David Wood
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
David Wood
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
David Wood
 

More from David Wood (20)

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchain
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 Keynote
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart City
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software Development
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable Claims
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data model
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors Kill
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in Australia
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social media
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's Journey
 
Open by Default
Open by DefaultOpen by Default
Open by Default
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

CPSC 125 Ch 1 Sec 5

  • 1. Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Formal Logic
  • 2. Declarative Programming Languages ●  A declarative language is based on predicate logic. ●  A program written in a declarative language consists only of statements (actually predicate wffs) that are declared as hypotheses. ●  Execution of a declarative program allows the user to pose queries, asking for information about possible conclusions that can be derived from the hypotheses. ●  After obtaining the user’s query, the language turns on its “inference engine” and applies its rules of inference to the hypotheses to see which conclusions fit the user’s query. Section 1.5 Logic Programming 1
  • 3. Prolog ●  Prolog (PROgramming in LOGic) is a declarative programming language. ●  The set of declarations that constitutes a Prolog program is also known as a Prolog database. ●  Items in a Prolog database are either facts or rules. ●  Example of Prolog facts (a binary predicate called “eat”): ■  eat (bear, fish) ■  eat (bear, fox) ■  eat (deer, grass) ●  “bear,” “fish,” “fox,” “deer,” and “grass” are constants because they represent specific elements in the domain. Section 1.5 Logic Programming 2
  • 4. Prolog ●  Other facts that we could add to the Prolog database: ■  animal (bear) ■  animal (fish) ■  animal (fox) ■  animal (deer) ■  plant (grass) ●  We can now pose some simple queries. ■  is (eat (deer, grass)) •  yes ■  is (eat (bear, rabbit)) •  no ●  “is” asks if the fact exists in the database. Section 1.5 Logic Programming 3
  • 5. Prolog ●  Queries may include variables, for example: ■  which(x: eat(bear, x)) ●  produces: ■  fish ■  fox ●  The second type of item in a Prolog database is a Prolog rule. ●  A rule is a description of a predicate by means of an implication. Section 1.5 Logic Programming 4
  • 6. Prolog Rules ●  For example, we might use a rule to define a predicate of prey: ■  prey(x) if eat(y, x) and animal(x) ●  This says that x is a prey if it is an animal that is eaten. If we add this rule to our database, then in response to the query: ■  which(x: prey(x)) ●  we would get: ■  fish ■  fox Section 1.5 Logic Programming 5
  • 7. Horn Clauses and Resolution ●  We can describe the facts in our database by the wffs ■  E(b, fi) ■  E(b, fo) ■  E(d, g) ■  A(b) ■  A( fi) ■  A( fo) ■  A(d) ■  P(g) ■  with the rule: E(y, x) Λ A(x) → Pr (x) ●  Prolog treats the rule as being universally quantified and uses universal instantiation to strip off the universal quantifiers: ■  (∀y)(∀x)[E(y, x) Λ A(x) → Pr(x)] Section 1.5 Logic Programming 6
  • 8. Horn Clauses and Resolution ●  A Horn clause is a wff composed of predicates or the negations of predicates (with either variables or constants as arguments) joined by disjunctions, where, at most, one predicate is unnegated. ●  Example of Horn clause: ■  [E(y, x)]ʹ′ V [A(x)]ʹ′ V Pr(x) ●  This can be rewritten using DeMorgan’s law as ■  [E(y,x) Λ A(x)] V Pr(x) ●  This is equivalent to: ■  E(y, x) Λ A(x) → Pr(x) ●  The above is a rule in the Prolog program. Section 1.5 Logic Programming 7
  • 9. Horn Clauses and Resolution ●  The rule of inference used by Prolog is called resolution. ●  Two Horn clauses in a Prolog database are resolved into a new Horn clause if one contains an unnegated predicate that matches a negated predicate in the other clause. ●  For example: •  A(a) •  [A(a)]ʹ′ V B(b) ■  is equivalent to: •  A(a), A(a) → B(b) ■  Prolog infers: •  B(b) ●  which is just an application of modus ponens. ●  Therefore, Prolog’s rule of inference includes modus ponens as a special case. Section 1.5 Logic Programming 8
  • 10. Recursion ●  Prolog rules are implications. ●  Their antecedents may depend on facts or other rules. ●  The antecedent of a rule may also depend on that rule itself, in which case the rule is defined in terms of itself. ●  For example, we can then define a binary relation in-food- chain(x, y), meaning “y is in x’s food chain.” This means one of two things: 1.  x eats y directly. 2.  x eats something that eats something that eats something ... that eats y. This can also be stated as: 2.  x eats z and y is in z’s food chain. Section 1.5 Logic Programming 9
  • 11. Recursion ●  Case (1) is simple to test from our existing facts, but without (2), in- food-chain means nothing different than eat. ●  On the other hand, (2) without (1) sends us down an infinite path of something eating something eating something and so on, with nothing telling us when to stop. ●  Recursive definitions always need a stopping point that consists of specific information. ●  The Prolog rule for in-food-chain incorporates (1) and (2): ■  in-food-chain(x, y) if eat(x, y) ■  in-food-chain(x, y) if eat(x, z) and in-food-chain(z, y) ●  is a recursive rule because it defines the predicate in-food-chain in terms of in-food-chain. Section 1.5 Logic Programming 10
  • 12. Expert Systems ●  Many interesting applications programs have been developed, in Prolog and similar logic programming languages, that gather a database of facts and rules about some domain and then use this database to draw conclusions. ●  Such programs are known as expert systems, knowledge- based systems, or rule-based systems. ●  The database in an expert system attempts to capture the knowledge (“elicit the expertise”) of a human expert in a particular field. ●  This includes both the facts known to the expert and the expert’s reasoning path in reaching conclusions from those facts. Section 1.5 Logic Programming 11