
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Programming in Logic, PROLOG Programming, PROLOG Paradigm, System Interaction, Problem solving in PROLOG, Facts, Queries, Basic Proof technique, PROLOG syntax, Propositional Calculus are key points of this lecture. Programming languages is basic subject of computer science. Its not about any specific language but almost cover all of them.
Typology: Slides
1 / 56
This page cannot be seen from the preview
Don't miss anything!
Prolog Database
Facts + Rules
Query
Used to represent unchanging information about objects and their relationships. Only facts in the PROLOG database can be used for problem solving. Insert facts into the database by, typing the facts into a file and loading (consulting) the file into a running PROLOG system
Each axiom is a Horn clause of the form: H :- B1, B2, ..., Bn. where H is the head term and Bi are the body terms Meaning H is true if all Bi are true
The logic programming system attempts to find axioms using inference steps that imply the goal (theorem) is true
Basic Proof technique - modus ponens
A -> B
A
B
Prolog Uses backward chaining
More efficient than forward chaining for larger collections of axioms
Interactive (hybrid compiled/interpreted)
Applications: expert systems, artificial
intelligence, natural language
understanding, logical puzzles and games
“A dog is a mammal” isa(dog, mammal).
“A sparrow is a bird” isa(sparrow, bird).
“is a sparrow an animal?” ?- animal(sparrow).
answer: “yes” yes
“is a table an animal?” ?- animal(table).
answer: “no” no
“what is a dog?” ?- isa(dog, X).
answer: “a mammal” X = mammal
Alphanumeric atoms - alphabetic character sequence starting with a lower case letter Examples: apple a1 apple_cart Quoted atoms - sequence of characters surrounded by single quotes Examples: ‘Apple’ ‘hello world’ Symbolic atoms - sequence of symbolic characters Examples: & < > * - + >> Special atoms Examples:! ; [ ] {}
Integers and Floating Point numbers Examples: 0 1 9821 -10 1.3 -1.3E
Program with three facts and one rule:
rainy(columbo). rainy(ayubia). cold(ayubia). snowy(X) :- rainy(X), cold(X).
Query and response: ?- snowy(ayubia). yes
Query and response: ?- snowy(columbo). no
Query and response: ?- snowy(lahore). No
because rainy(ayubia) and cold(ayubia) are sub-goals that are both true facts in the database
snowy(X) with X=columbo is a goal that fails, because cold(X) fails, triggering backtracking
Logic Representation :
Propositional Calculus
Boolean statements Logic connectives ¬^ ∧ ∨ ⇔ ⇒
p : Ahmed is father of Belal q : Ahmed is brother of Aslam r : Aslam is uncle of Belal
Statement Logic ¬p Ahmed is not father of Belal
p ∨ q Ahmed is father of Belal or Ahmed is brother of Aslam
p ∧ q ⇒ r If Ahmed is father of Belal and brother of Aslam then Aslam is uncle of Belal
Predicate Calculus Predicates man(Ahmed) father(Ahmed, Belal) brother(Belal, Chand) brother(Chand, Delawar) owns(Belal, car) tall(Belal) hates(Ahmed, Chand) family() Formulae ∀ X,Y,Z(man(X) ∧ man(Y) ∧ father(Z,Y) ∧ father(Z,X) ⇒ brother(X,Y)) Variables X, Y and Z
Constants Ahmed, Belal, Chand, Delawar and car
Prolog code Predicates man(symbol) father(symbol, symbol) brother(symbol, symbol) owns(symbol, symbol) tall(symbol) hates(symbol, symbol) family() Clauses man(ahmed). father(ahmed, belal). brother(ahmed, chand). owns(belal, car). tall(belal). hates(ahmed, chand). family(). brother(X,Y):- man(X), man(Y), father(Z,Y), father(Z,X). Goal brother(ahmed,belal).