














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















1. Application Domains - Logic programming language application areas include natural language processing, expert systems, specifications checking, theorem proving, and control systems (among others). 2. Definitions - Logic programming languages, also called declarative languages, differ substantially from the other programming languages we have discussed. - Declarative rather that procedural : Only specification of results are stated (not detailed procedures for producing them) - Most importantly, logic programs do not specify the execution sequence as in most in the case of other language paradigms. User specifies the specifications of a solution and the computer derives the execution sequence for that solution:
Let us have airline flight information of the form:
flight(flight_number, from_city, to_city, departure_time, arrival_time)
Then all the flights from Washington DC to Santa Clara can be specified as either direct flights or as flights with an intermediate stop:
3. Basic Definitions - Horn clause: Horn clause - can have only two forms o Headed : single atomic proposition on left side o Headless : empty left side (used to state facts )
A Horn clause is an IF clause and not iff, formally,
A0 if A1 and A2 and A3 and … and An
Each Ai is a simple assertion of the form Ri(…) where Ri is a relation name.
Informally, this clause means that, if A1, …, and An are all true, then we can infer that A0 is also true. But, we cannot conversely infer that A0 is false just because some Ai turns out to be false.
4. Logic Programs - Basic elements: Term: - a constant, variable, or structure Constant: - an atom or an integer Atom: - symbolic value of Prolog Atom consists of either: - A string of letters, digits, and underscores beginning with a lowercase letter - a string of printable ASCII characters delimited by apostrophes
Headless Horn clauses o student(Paul). o junior(Mary).
5. Inferencing Process - User query: Computation in a logic program consists of testing a given assertion (query) A. The testing of a query A can be implemented by a process called matching, satisfying, or resolution. The facts and the rules of the program are used to determine which substitutions for variables in the query (called unification) are consistent with the information in the database. If we can infer from the clauses of the program that A is true, then we say that A succeeds. Otherwise, we say that A fails. Note that this does not mean that A is false. For example, Prolog as an interpreter, ¾ prompts the user for an input query and ¾ outputs: the truth value (“yes”) or falsity (“no”) of that query and an assignment to the variables of the query that make the query true (that unifies the query). - If a goal is a compound proposition, each of the facts is a subgoal.
B :- A C :- B … Q :- P
Unification: o It is the process of finding values for variables in propositions that allows matching process to succeed o To unify two expressions U and V, we need to find substitutions for the variables occurring in U and V that makes the two expressions identical. o Generally, it is denoted by σ and written as Uσ = Vσ
Example 1: o To unify the two expressions:
R1(X,John) with f(g(John), Z)
Bind X to g(John) and Z to John to get f(g(John), John) as the unified instance of both expressions.
If the database contains the fact ParentOf(John, Mary) then the unification of the following query: ParentOf(X,Mary)=ParentOf(John,Y) Would be ParentOf(John,Mary)
where X is substituted by John and Y is substituted by Mary.
Example 2: grandmother(X,Y) :- mother(X,Z), mother(Z,Y). grandfather (X,Y) :- father (X,Z), father(Z,Y). mother(anna,peter). mother(anna,clara). father(joe,peter). father(jim,clara). mother(mary,anna). father(tom,joe).
Answer: ?- grandfather(tom,X). ?- grandmother(X,pet er).
6. Programming Languages vs. IPL & LP
y In a logic programming language, the programmer does not identify the computations or functions necessary to derive an answer.
8. Prolog - University of Aix-Marseille Natural language processing - University of Edinburgh Automated theorem proving - Prolog (PROgramming LOGic) (1972): was the first widespread formal logic language. It is a non-procedural, goal oriented language. - Computation takes place by trying to infer the response to queries through accessing a database of facts and rules. - The user supplies the facts, rules, and queries (expressed in predicate calculus), while the computer carries out resolution to try and infer the replies. - By far the dominant logic programming language is Prolog, so that is the language we will examine in some detail. - Prolog is based predominantly on the Horn clause, A :- B, C, D, ...
This tells us A is true if B is true and C is true and ... etc. It does not tell us the circumstances under which a is false
function call, we give the relationship name first, then in brackets the two entities that are related, e.g. eats(wilma,meat), eats(wilma,vegetables) rules: we can establish rules that describe how one relationship or property is true if some other properties or conditions are true. For example, a rule could state that if someone eats meat and they eat vegetables then they are an omnivore.
The result : this is the relationship or property which results from the rule, and goes on the left hand side of our rule, e.g. omnivore(Individual) Note that the entity here will usually be a variable.
The "if" symbol :
the clauses
The clauses: the set of relationships and properties which determine if the rule is to be applied, this goes on the right hand side of the rule.
eats(fred,vegetables). is now asking whether or not fred eats vegetables, not stating it as a new fact.
carnivore(Individual) :- eats(Individual,meat). omnivore(Individual) :- eats(Individual,meat),eats(Individual,vegetables). food(Thing) :- eats(Individual,Thing).
9 Once that is created, we can load the database of facts and rules from the file, then begin issuing queries and getting answers. 9 In the example below assume > is the prompt:
['flint.pl']. flint.pl compiled
Yes
food(meat). Yes
carnivore(fred). Yes
food(dirt). No
omnivore(Individual).
Individual = wilma Yes
Suppose we are given the query "is fred an omnivore?" omnivore(fred).
In trying to solve this query, Prolog does the following:
and after substituting we want to check
if eats(fred,meat) AND eats(fred,vegetables).