1 / 7

Programming Language Paradigms

Programming Language Paradigms. LOGIC PROGRAMMING. A Logic program is expressed as a set of atomic sentences (FACTS) and HORN clauses(RULES) We can ask questions in the form of conjectures (like FACTS but with variables) to find out what values will make the conjecture true. Eg.

zinnia
Download Presentation

Programming Language Paradigms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Language Paradigms

  2. LOGIC PROGRAMMING A Logic program is expressed as a set of atomic sentences (FACTS) and HORN clauses(RULES) We can ask questions in the form of conjectures (like FACTS but with variables) to find out what values will make the conjecture true. Eg. Ramu is a boy → FACT Ramu's father is Kicha → Relationship Ramu eats choclates if chocolates have nuts and chocolates are available → HORN CLAUSE

  3. LOGIC PROGRAMMING Computation is done by a separate inference engine. (Hidden from programmer). LIPS : Logical Inferences Per Second.

  4. PROLOG OVERVIEW PROLOG – Programming in Logic A Prolog program consists of a database of predicates composed of FACTS and RULES involving CONSTANTS and VARIABLES Constants (ATOMS) begin with lowercase letters Eg: tom, bill, a1, x, y, 217, -32, 2.76 Variables begin with uppercase letter or underscore. Eg: X, U, _x1, Tom, A1 A Fact is true about some constant. A Predicate is a function result is either TRUE or FALSE.

  5. PROLOG OVERVIEW Consider the following relationship in Prolog. Mother (peggy, george). Peggy is the mother of george Rules in Prolog grandmother(x,z) :- mother(x,y), parent(y,z) :- refer to “provided that” = “if” part in rule , refers to “and” in the rule. ; referes to “or” in the rule. If x is the mother of y and y is the parent of z then x is the grandmother of z Goals in Prolog are entered by the user following the ?- prompt

  6. SWI PROLOG TUTORIAL $vi ancestor.pro ancestor(bob, susan). ancestor(A, X) :- parent(A, X). ancestor(A, X) :- parent(A, C), ancestor(C, X). parent(fred, sally). parent(tina, sally). parent(sally, john). parent(sally, diana). parent(sam, bill).

  7. SWI PROLOG TUTORIAL $pl ?- help. ?- [’ancestor.pro’]. ?- listing. ?- halt. $pl –o ancestor –c ancestor.pro $ancestor ?- ancestor(bv, bv). No ?- ancestor(fred, diana). Yes ?- parent(tina, sally). Yes ?- parent(bill, sally). No

More Related