Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this document? Why not share!

- Generics in .NET, C++ and Java by Sasha Goldshtein 5355 views
- Oops by Gayathri Ganesh 933 views
- 9 subprograms by jigeno 2997 views
- Auteursrecht in academische omgevin... by Leon Osinski 377 views
- Collections in-csharp by Lakshmi Mareddy 947 views
- Raspuns MS Subprogram FIV 2016 by Asociatia SOS Inf... 11634 views

No Downloads

Total views

359

On SlideShare

0

From Embeds

0

Number of Embeds

2

Shares

0

Downloads

0

Comments

0

Likes

1

No embeds

No notes for slide

- 1. ICS 313 - Fundamentals of Programming Languages 116. Logical ProgrammingLogic ProgrammingNeither imperative nor functionalDeals with relations, not functionsArguments and results are treated uniformlydaughter(sue,john)lessthan(3,10)Separate logic from controlProgrammer declares what facts and relations are trueSystem determines how to use facts to solve problems
- 2. ICS 313 - Fundamentals of Programming Languages 2Relations (Predicates)A table with n ≥ 0 columns and a possibly infinite setof rowsA tuple (a1,a2,…,an) is in a relation if ai appears incolumn i, 1 ≤ i ≤ nExample: Relation append is a set of tuples of theform (X,Y,Z), where Z consists of the elements of Xfollowed by the elements of YRelations can be specified using Horn clauses(rules)Horn Clauses (Rules)A Horn clause:P if Q1 and Q2 and … and Qk, k ≥ 0can be interpreted as:The consequent, P, is true if the antecedents Q1,Q2,…, Qk , k ≥ 0 are all trueAntecedents: conjunction of zero or more conditions that are atomicformulae in predicate logicConsequent: an atomic formula in predicate logic
- 3. ICS 313 - Fundamentals of Programming Languages 3Horn Clause TerminologyHorn Clause ClauseConsequent Goal HeadAntecedents Subgoals TailHorn clause with no tail FactHorn clause with tail RuleP if Q1 and Q2 and … and Qk p :- q1 , …, qnExample: Links Between LanguagesFortranAlgol 60CPLBCPLCC++Simula 67Smalltalk-80
- 4. ICS 313 - Fundamentals of Programming Languages 4Example Prolog Facts and RulesA prolog program starts with a collection of factslink(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 PrologA simple term is a number, variable or an atom thatstands for itselfAll variables start with capital lettersAll constants are in lower caseA compound term consists of an atom followed by aparenthesized sequence of subterms.The atom is called a functorSubterms are called argumentsAll predicates are in lower case
- 5. ICS 313 - Fundamentals of Programming Languages 5Horn Clauses with VariablesVariables may appear in the antecedents and theconsequent of a Horn clause:p(X1,X2,…,Xn) :- h(X1,X2,…,Xm)p(X1,X2,…,Xn) :- h(X1,X2,…,Xm,Y1,Y2,…,Yk)QueriesSimplest form: Does a particular tuple belong to arelationpath(algol60,smalltalk80).Can’t ask: Does a particular tuple not belong to a relationYes/Fail rather then Yes/No answers, where Fail indicates afailure to deduce an answer.More interesting: Is there an X such that a specificclause containing X evaluates to yespath(X,cplusplus)
- 6. ICS 313 - Fundamentals of Programming Languages 6Examples1 ?- consult(myrules).myrules compiled, 0.00 sec, 1,640 bytes.Yes2 ?- path(X,cplusplus).X = cplusplus ;X = fortran ;X = fortran ;X = algol60 ;X = cpl ;X = bcpl ;X = c ;X = algol60 ;X = simula67 ;No3 ?- path(c,Y).Y = c ;Y = cplusplus ;No4 ?- path(algol60,smalltalk80).YesMore Examples?- link(N,M), link(L,M).N = fortranM = algol60L = fortranYes?- link(N,M), link(L,M), not(L=N).N = cM = cplusplusL = simula67Yes

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment