1 / 23

CSE3302 Programming Languages (notes?)

CSE3302 Programming Languages (notes?). Dr. Carter Tiernan. Logic Programming. Nonprocedural programming Higher-level language allows one to express the same program with less detail Language does more automatically Programmer focuses more on what to do not on how to do it.

cachet
Download Presentation

CSE3302 Programming Languages (notes?)

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. CSE3302Programming Languages(notes?) Dr. Carter Tiernan Programming Languages

  2. Logic Programming • Nonprocedural programming • Higher-level language allows one to express the same program with less detail • Language does more automatically • Programmer focuses more on what to do not on how to do it Programming Languages

  3. Automatic deduction • Automatic theorem proving • The development of programs that can construct formal proofs of propositions stated in symbolic language • Side effect of proof is construction of a result which demonstrates the proof • Programs expressed in the form of propositions that assert the existence of a desired result Programming Languages

  4. Prolog • Programs are structured like theorems • Clauses that define the problem domain • Facts (database of relationships among atomic individuals) • Goals • Is a fact provable? • Is there an individual satisfying the goal? • Is there a solution satisfying the goal? Programming Languages

  5. Prolog Clauses • Clauses define relationships or “predicates” • Facts or hypotheses parent (charles, harry). • Goals :- grandparent (elizabeth, X). • Conditions or rules grandparent(Y, Z) :- parent (Y,W), parent(W,Z). Programming Languages

  6. Predicates • <head> :- <body> • Predicates • Relationship applied to terms • Relationships • Properties of • Relations among • Terms • Atoms • Variables • Compound terms • Horn clause form Programming Languages

  7. Goals • Executing a goal • Match clauses in predicate by finding an assignment of values to the variables that makes the goal identical to the head of one of the clauses (unification) • Variables are bound (instantiated) to create subgoal • Recursive application and pattern matching Programming Languages

  8. Compound terms • Compound term allows us to describe individuals without naming them • Functor with atoms or variables d(X, plus(U,V), plus(DU,DV)) or d(X, U + V, DU + DV) • Similar to LISP list structure • Acts somewhat like a function but is not a function call Programming Languages

  9. Data structures • No constructors • Data structures are implicitly defined by their properties • Few primitives • Compound terms can provide logical description of structure • Some Prologs allow infix notation for functors Programming Languages

  10. Complex structures • Compound terms represent themselves • Symbolic notations can be defined directly • Good for mathematical relationships • Predicates can define structures • Predicates can replace compound terms • Expressions matched to clauses must exist within the Prolog “closed world” • Good for object-oriented relationships Programming Languages

  11. More data structures • Abstract data types - so abstract they’re only described • Infinite terms - “occurs check” • Representation of ‘infinite’ list is finite • Circular structure Programming Languages

  12. Control Structures • Separation of logic and control • Independent analysis • Order of clauses has no effect on meaning or logic • Control affects generation and unification of subgoals • Efficiency is an issue but not meaning Programming Languages

  13. Subgoal Generation • Top-down • Start from goal; try to reach hypotheses • Recursive approach • Bottom-up • Start with hypotheses; try to reach goal • Iterative approach Programming Languages

  14. Backtracking • Multiple matching clauses may be available • If a failure occurs after a choice point, execution backtracks to the last choice point • Another match is made and execution continues. • Implementation of efficient backtracking is crucial in logic programming Programming Languages

  15. Input / Output Parameters • Goals attempt to satisfy subgoals with whatever value is unified • Parameters are neither inherently input nor output. Which ever is supplied is used as input. • When no parameter values are given, the systems attempts to search for any solution that satisfies the pattern Programming Languages

  16. Searching in Prolog • Depth-first search isspecified • Not pure logic programming • Attempts to satisfy goals in the order written • Will try matching clauses in the order in which they were entered into the DB Programming Languages

  17. Prolog vs. Logic Programming • Interpretation of arithmetic jumps beyond the bounds of strict logic programming unless handled as succ() • Efficiency requires the use underlying hardware support • ‘is’ gives an assignment • Binding forces ordering Programming Languages

  18. Search rationale • Breadth-first • searches paths in parallel • needs exponentially more space than depth-first • Depth-first • Can get caught in infinitely deep search • Programmer is required to order clauses to prevent endless search Programming Languages

  19. Nonmonotonic reasoning • Updateable database • Assert • Retract • Does not match logic • Does match world state changes over time Programming Languages

  20. Cuts • “You have found all the solutions there are; do not bother trying to find any others” • Predicate that always succeeds, but past which you can never backtrack • Used with repeat to provide looping Programming Languages

  21. Higher-order rules • Parameters must be terms not predicates • Logic programming is generally restricted to first-order logic • Resolution algorithm is complete only for first-order logic Programming Languages

  22. Negation • Unsatisfiability - cannot be proved true • Absence of data • Closed world assumption • Conclusions can be drawn about relationships that DO hold • NO conclusions can be made about relationships that do NOT hold • not( -- ) predicate succeeds if -- fails Programming Languages

  23. Equivalence • Term equality • Other types of equivalence cannot be defined • In terms of logical properties • Term inequality requires complete binding for correct interpretation Programming Languages

More Related