SlideShare uma empresa Scribd logo
1 de 6
ICS 313 - Fundamentals of Programming Languages 1
16. Logical Programming
Logic Programming
Neither imperative nor functional
Deals with relations, not functions
Arguments and results are treated uniformly
daughter(sue,john)
lessthan(3,10)
Separate logic from control
Programmer declares what facts and relations are true
System determines how to use facts to solve problems
ICS 313 - Fundamentals of Programming Languages 2
Relations (Predicates)
A table with n ≥ 0 columns and a possibly infinite set
of rows
A tuple (a1,a2,…,an) is in a relation if ai appears in
column i, 1 ≤ i ≤ n
Example: Relation append is a set of tuples of the
form (X,Y,Z), where Z consists of the elements of X
followed by the elements of Y
Relations can be specified using Horn clauses
(rules)
Horn Clauses (Rules)
A Horn clause:
P if Q1 and Q2 and … and Qk, k ≥ 0
can be interpreted as:
The consequent, P, is true if the antecedents Q1,
Q2,…, Qk , k ≥ 0 are all true
Antecedents: conjunction of zero or more conditions that are atomic
formulae in predicate logic
Consequent: an atomic formula in predicate logic
ICS 313 - Fundamentals of Programming Languages 3
Horn Clause Terminology
Horn Clause Clause
Consequent Goal Head
Antecedents Subgoals Tail
Horn clause with no tail Fact
Horn clause with tail Rule
P if Q1 and Q2 and … and Qk p :- q1 , …, qn
Example: Links Between Languages
Fortran
Algol 60
CPL
BCPL
C
C++
Simula 67
Smalltalk-80
ICS 313 - Fundamentals of Programming Languages 4
Example Prolog Facts and Rules
A prolog program starts with a collection of facts
link(fortran, algol60)
link(algol60, cpl)
link(cpl, bcpl)
link(bcpl, c)
link(c, cplusplus)
link(algol60, simula67)
link(simula67, cplusplus)
link(simula67, smalltalk80)
path(L, L)
path(L,M) :- link(L,X), path(X,M)
In Prolog
A simple term is a number, variable or an atom that
stands for itself
All variables start with capital letters
All constants are in lower case
A compound term consists of an atom followed by a
parenthesized sequence of subterms.
The atom is called a functor
Subterms are called arguments
All predicates are in lower case
ICS 313 - Fundamentals of Programming Languages 5
Horn Clauses with Variables
Variables may appear in the antecedents and the
consequent of a Horn clause:
p(X1,X2,…,Xn) :- h(X1,X2,…,Xm)
p(X1,X2,…,Xn) :- h(X1,X2,…,Xm,Y1,Y2,…,Yk)
Queries
Simplest form: Does a particular tuple belong to a
relation
path(algol60,smalltalk80).
Can’t ask: Does a particular tuple not belong to a relation
Yes/Fail rather then Yes/No answers, where Fail indicates a
failure to deduce an answer.
More interesting: Is there an X such that a specific
clause containing X evaluates to yes
path(X,cplusplus)
ICS 313 - Fundamentals of Programming Languages 6
Examples
1 ?- consult(myrules).
myrules compiled, 0.00 sec, 1,640 bytes.
Yes
2 ?- path(X,cplusplus).
X = cplusplus ;
X = fortran ;
X = fortran ;
X = algol60 ;
X = cpl ;
X = bcpl ;
X = c ;
X = algol60 ;
X = simula67 ;
No
3 ?- path(c,Y).
Y = c ;
Y = cplusplus ;
No
4 ?- path(algol60,smalltalk80).
Yes
More Examples
?- link(N,M), link(L,M).
N = fortran
M = algol60
L = fortran
Yes
?- link(N,M), link(L,M), not(L=N).
N = c
M = cplusplus
L = simula67
Yes

Mais conteúdo relacionado

Mais procurados

Roots of polynomials
Roots of polynomialsRoots of polynomials
Roots of polynomialsDUBAN CASTRO
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methodsDivya Bhatia
 
Chapter 5 Polynomials
Chapter 5 PolynomialsChapter 5 Polynomials
Chapter 5 PolynomialsReema
 
B02110105012
B02110105012B02110105012
B02110105012theijes
 
3.3 Zeros of Polynomial Functions
3.3 Zeros of Polynomial Functions3.3 Zeros of Polynomial Functions
3.3 Zeros of Polynomial Functionssmiller5
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolationEasyStudy3
 
Nams- Roots of equations by numerical methods
Nams- Roots of equations by numerical methodsNams- Roots of equations by numerical methods
Nams- Roots of equations by numerical methodsRuchi Maurya
 
SMIU Discrete Structure Lecture 3 Section 3E.pdf
SMIU Discrete Structure Lecture 3 Section 3E.pdfSMIU Discrete Structure Lecture 3 Section 3E.pdf
SMIU Discrete Structure Lecture 3 Section 3E.pdfMuhammadUmerIhtisham
 
AP Calculus Slides December 7, 2007
AP Calculus Slides December 7, 2007AP Calculus Slides December 7, 2007
AP Calculus Slides December 7, 2007Darren Kuropatwa
 
VonNeumannAlgebraPresentation
VonNeumannAlgebraPresentationVonNeumannAlgebraPresentation
VonNeumannAlgebraPresentationMatthew Geleta
 

Mais procurados (20)

Function
Function Function
Function
 
Zeroes and roots
Zeroes and rootsZeroes and roots
Zeroes and roots
 
Roots of polynomials
Roots of polynomialsRoots of polynomials
Roots of polynomials
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methods
 
Newton
NewtonNewton
Newton
 
Chapter 5 Polynomials
Chapter 5 PolynomialsChapter 5 Polynomials
Chapter 5 Polynomials
 
B02110105012
B02110105012B02110105012
B02110105012
 
3.3 Zeros of Polynomial Functions
3.3 Zeros of Polynomial Functions3.3 Zeros of Polynomial Functions
3.3 Zeros of Polynomial Functions
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Nams- Roots of equations by numerical methods
Nams- Roots of equations by numerical methodsNams- Roots of equations by numerical methods
Nams- Roots of equations by numerical methods
 
SMIU Discrete Structure Lecture 3 Section 3E.pdf
SMIU Discrete Structure Lecture 3 Section 3E.pdfSMIU Discrete Structure Lecture 3 Section 3E.pdf
SMIU Discrete Structure Lecture 3 Section 3E.pdf
 
Math task 3
Math task 3Math task 3
Math task 3
 
Task 4
Task 4Task 4
Task 4
 
Lecture1
Lecture1Lecture1
Lecture1
 
13 Boolean Algebra
13 Boolean Algebra13 Boolean Algebra
13 Boolean Algebra
 
AP Calculus Slides December 7, 2007
AP Calculus Slides December 7, 2007AP Calculus Slides December 7, 2007
AP Calculus Slides December 7, 2007
 
newton raphson method
newton raphson methodnewton raphson method
newton raphson method
 
VonNeumannAlgebraPresentation
VonNeumannAlgebraPresentationVonNeumannAlgebraPresentation
VonNeumannAlgebraPresentation
 
azEssay3
azEssay3azEssay3
azEssay3
 
Blackbox task 2
Blackbox task 2Blackbox task 2
Blackbox task 2
 

Destaque

Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and JavaSasha Goldshtein
 
9 subprograms
9 subprograms9 subprograms
9 subprogramsjigeno
 
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...Leon Osinski
 
The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive ProgrammingEddy Bertoluzzo
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programmingfuturespective
 
A basic course on Research data management: part 1 - part 4
A basic course on Research data management: part 1 - part 4A basic course on Research data management: part 1 - part 4
A basic course on Research data management: part 1 - part 4Leon Osinski
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebPublitory
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with CapabilitiesScott Wlaschin
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidNicolas Trangez
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effectsJoost de Vries
 
Functional programming
Functional programmingFunctional programming
Functional programmingHideshi Ogoshi
 

Destaque (20)

Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and Java
 
Oops
OopsOops
Oops
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...
Auteursrecht in academische omgeving: DPO Professionaliseringsbijeenkomst, 23...
 
Collections in-csharp
Collections in-csharpCollections in-csharp
Collections in-csharp
 
Raspuns MS Subprogram FIV 2016
Raspuns MS Subprogram FIV 2016Raspuns MS Subprogram FIV 2016
Raspuns MS Subprogram FIV 2016
 
The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive Programming
 
Frp
FrpFrp
Frp
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programming
 
A basic course on Research data management: part 1 - part 4
A basic course on Research data management: part 1 - part 4A basic course on Research data management: part 1 - part 4
A basic course on Research data management: part 1 - part 4
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ Incubaid
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
16 exception handling - i
16 exception handling - i16 exception handling - i
16 exception handling - i
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effects
 
Functional programming
Functional programmingFunctional programming
Functional programming
 

Semelhante a 16 logical programming

Semelhante a 16 logical programming (20)

Hak ontoforum
Hak ontoforumHak ontoforum
Hak ontoforum
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Herbrand-satisfiability of a Quantified Set-theoretical Fragment (Cantone, Lo...
Herbrand-satisfiability of a Quantified Set-theoretical Fragment (Cantone, Lo...Herbrand-satisfiability of a Quantified Set-theoretical Fragment (Cantone, Lo...
Herbrand-satisfiability of a Quantified Set-theoretical Fragment (Cantone, Lo...
 
FUZZY LOGIC
FUZZY LOGICFUZZY LOGIC
FUZZY LOGIC
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
Du Calcul des prédicats vers Prolog
Du Calcul des prédicats vers PrologDu Calcul des prédicats vers Prolog
Du Calcul des prédicats vers Prolog
 
Predicate Calculus
Predicate CalculusPredicate Calculus
Predicate Calculus
 
multipleSeqAlignment.ppta4432455344534534
multipleSeqAlignment.ppta4432455344534534multipleSeqAlignment.ppta4432455344534534
multipleSeqAlignment.ppta4432455344534534
 
Programmable PN Sequence Generators
Programmable PN Sequence GeneratorsProgrammable PN Sequence Generators
Programmable PN Sequence Generators
 
Assignment 2 solution acs
Assignment 2 solution acsAssignment 2 solution acs
Assignment 2 solution acs
 
Per6 basis2_NUMBER SYSTEMS
Per6 basis2_NUMBER SYSTEMSPer6 basis2_NUMBER SYSTEMS
Per6 basis2_NUMBER SYSTEMS
 
D024025032
D024025032D024025032
D024025032
 
On observer design methods for a
On observer design methods for aOn observer design methods for a
On observer design methods for a
 
The Chase in Database Theory
The Chase in Database TheoryThe Chase in Database Theory
The Chase in Database Theory
 
Programming modulo representations
Programming modulo representationsProgramming modulo representations
Programming modulo representations
 
Iswc 2016 completeness correctude
Iswc 2016 completeness correctudeIswc 2016 completeness correctude
Iswc 2016 completeness correctude
 
Automata
AutomataAutomata
Automata
 
Automata
AutomataAutomata
Automata
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx
 

Mais de jigeno

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1jigeno
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms accessjigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
14 exception handling
14 exception handling14 exception handling
14 exception handlingjigeno
 
13 concurrency
13 concurrency13 concurrency
13 concurrencyjigeno
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programmingjigeno
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data typesjigeno
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structurejigeno
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statementsjigeno
 
6 data types
6 data types6 data types
6 data typesjigeno
 
5 names
5 names5 names
5 namesjigeno
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysisjigeno
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semanticsjigeno
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languagesjigeno
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminariesjigeno
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2jigeno
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1jigeno
 

Mais de jigeno (19)

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
 
Bsit1
Bsit1Bsit1
Bsit1
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
13 concurrency
13 concurrency13 concurrency
13 concurrency
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
 
6 data types
6 data types6 data types
6 data types
 
5 names
5 names5 names
5 names
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
 

Último

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 2024Victor Rentea
 
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 FresherRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
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...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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 Processorsdebabhi2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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 WorkerThousandEyes
 

Último (20)

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
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 

16 logical programming

  • 1. ICS 313 - Fundamentals of Programming Languages 1 16. Logical Programming Logic Programming Neither imperative nor functional Deals with relations, not functions Arguments and results are treated uniformly daughter(sue,john) lessthan(3,10) Separate logic from control Programmer declares what facts and relations are true System determines how to use facts to solve problems
  • 2. ICS 313 - Fundamentals of Programming Languages 2 Relations (Predicates) A table with n ≥ 0 columns and a possibly infinite set of rows A tuple (a1,a2,…,an) is in a relation if ai appears in column i, 1 ≤ i ≤ n Example: Relation append is a set of tuples of the form (X,Y,Z), where Z consists of the elements of X followed by the elements of Y Relations can be specified using Horn clauses (rules) Horn Clauses (Rules) A Horn clause: P if Q1 and Q2 and … and Qk, k ≥ 0 can be interpreted as: The consequent, P, is true if the antecedents Q1, Q2,…, Qk , k ≥ 0 are all true Antecedents: conjunction of zero or more conditions that are atomic formulae in predicate logic Consequent: an atomic formula in predicate logic
  • 3. ICS 313 - Fundamentals of Programming Languages 3 Horn Clause Terminology Horn Clause Clause Consequent Goal Head Antecedents Subgoals Tail Horn clause with no tail Fact Horn clause with tail Rule P if Q1 and Q2 and … and Qk p :- q1 , …, qn Example: Links Between Languages Fortran Algol 60 CPL BCPL C C++ Simula 67 Smalltalk-80
  • 4. ICS 313 - Fundamentals of Programming Languages 4 Example Prolog Facts and Rules A prolog program starts with a collection of facts link(fortran, algol60) link(algol60, cpl) link(cpl, bcpl) link(bcpl, c) link(c, cplusplus) link(algol60, simula67) link(simula67, cplusplus) link(simula67, smalltalk80) path(L, L) path(L,M) :- link(L,X), path(X,M) In Prolog A simple term is a number, variable or an atom that stands for itself All variables start with capital letters All constants are in lower case A compound term consists of an atom followed by a parenthesized sequence of subterms. The atom is called a functor Subterms are called arguments All predicates are in lower case
  • 5. ICS 313 - Fundamentals of Programming Languages 5 Horn Clauses with Variables Variables may appear in the antecedents and the consequent of a Horn clause: p(X1,X2,…,Xn) :- h(X1,X2,…,Xm) p(X1,X2,…,Xn) :- h(X1,X2,…,Xm,Y1,Y2,…,Yk) Queries Simplest form: Does a particular tuple belong to a relation path(algol60,smalltalk80). Can’t ask: Does a particular tuple not belong to a relation Yes/Fail rather then Yes/No answers, where Fail indicates a failure to deduce an answer. More interesting: Is there an X such that a specific clause containing X evaluates to yes path(X,cplusplus)
  • 6. ICS 313 - Fundamentals of Programming Languages 6 Examples 1 ?- consult(myrules). myrules compiled, 0.00 sec, 1,640 bytes. Yes 2 ?- path(X,cplusplus). X = cplusplus ; X = fortran ; X = fortran ; X = algol60 ; X = cpl ; X = bcpl ; X = c ; X = algol60 ; X = simula67 ; No 3 ?- path(c,Y). Y = c ; Y = cplusplus ; No 4 ?- path(algol60,smalltalk80). Yes More Examples ?- link(N,M), link(L,M). N = fortran M = algol60 L = fortran Yes ?- link(N,M), link(L,M), not(L=N). N = c M = cplusplus L = simula67 Yes