1 / 23

Logic (Prolog) as the First Programming Language

Logic (Prolog) as the First Programming Language. Arthur Fleck Professor Emeritus University of Iowa. OVERVIEW. Logical basis Logic/Prolog programming ideas Advantages for the first course Technical course details Experience and Conclusions. Basic Boolean ops Logical implication.

Télécharger la présentation

Logic (Prolog) as the First Programming Language

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. Logic (Prolog) as the First Programming Language Arthur Fleck Professor Emeritus University of Iowa Frontiers in Education 2007

  2. OVERVIEW • Logical basis • Logic/Prolog programming ideas • Advantages for the first course • Technical course details • Experience and Conclusions

  3. Basic Boolean ops Logical implication And, or, and not, but written in the notation of logic ,, A critical Boolean operation in logic  Approached as formal logic (truth tables) Logical basis

  4. Predicates/relations Existential and universal quantification broOf(john_kennedy, robert_kennedy) In logic  and  - X.broOf(X, robert_kennedy) Logical basis

  5. Logical basis • Syntax of well-formed formulas (and to a large extent, programs too), ideasof satisfiability and tautology • Axioms and (sound) proof rulesmodus ponens -- given formulas a and a  b, conclude b

  6. Logical basis • Truth vs. prooftruth -- dependence on unlimited values of logic variables makes direct determination impossibleproof -- concludes truth from analysis of formula syntax, is independent of variable values, and requires no truth evaluation

  7. OVERVIEW OVERVIEW • Logical basis • Logic/Prolog programming ideas  • Advantages for the first course • Technical course details • Experience and Conclusions

  8. Prolog programming ideas • A program consists of a collection of universally quantified logical assertions -- axioms that characterize the essential properties of the problem domain • Solutions are computed by proving logical consequences of the chosen axioms

  9. Prolog programming ideas • Prolog programs are invoked through queries -- existentially quantified logical assertions • A Prolog programming system determines if a query is a logical consequence of the program -- and if so, values of constituent unknowns must also be reported

  10. Prolog programming example cousin(X,Y) :- grandFather(X,GF), grandFather(Y,GF), grandMother(X,GM), grandMother(Y,GM). ?- cousin(carolineKennedy, C). C= carolineKennedy

  11. Corrected Prolog example • cousin(X,Y) :- grandFather(X,GF), grandFather(Y,GF), grandMother(X,GM), grandMother(Y,GM), father(X,F1), father(Y,F2), F1\==F2. • ?- cousin(carolineKennedy,C). % yields C=mariaSriver -- and many more • ?- cousin(C,mariaSriver). % yields C= carolineKennedy -- and many more

  12. OVERVIEW • Logical basis • Logic/Prolog programming ideas • Advantages for the first course  • Technical course details • Experience and Conclusions

  13. Prolog programming advantages • Higher-level abstraction -- focus is on essential properties • Example -- list concatenation relationappend([ ], Suf, Suf).append([X|Pre], Suf, [X|Join]) :- append(Pre, Suf, Join).

  14. Prolog programming advantages • The 'append' assertions comprise several traditional programs --?- append([a,b], [c,d], Ans). % yields Ans=[a,b,c,d]?- append(Ans, [c,d], [a,b,c,d]). % yields Ans=[a,b]?- append(Ans1, Ans2, [a,b,c,d]). % yields Ans1=[ ], Ans2=[a,b,c,d] and Ans1=[a], Ans2=[b,c,d] and …

  15. Prolog programming advantages • Logic programming emphasizes modeling and abstraction • Precision in thinking and accuracy in programming are simultaneously achieved • Programming and problem solving become tightly integrated • The relational programs are innately much more general and reusable

  16. OVERVIEW • Logical basis • Logic/Prolog programming ideas • Advantages for the first course • Technical course details  • Experience and Conclusions

  17. Course details • First phase - introduce logic 1. Discuss formula syntax and use of truth tables 2. Emphasize differences (e.g., domains, quantifiers) found in predicate logic 3. Explain the relationship between proof and truth evaluation

  18. Course details • Second phase - use Prolog to animate logic 1. use logic formulas as syntax guide, start with familiar examples (e.g., genealogical relations) 2. emphasize relational character 3. recursion is natural and raises no conceptual complications

  19. Course details • Third phase - introduce Prolog's backtracking search strategy for proofs1. Require substantial student use of the Prolog trace facility2. Discuss e.g. success/failure loops and negation as failure with this procedural model

  20. Course details • Fourth phase - gain experience with integration of multiple features1. Compare the several means of expressing repetitive computation2. Study the complication of deducing implications of negative assertions3. Projects solving logic puzzles are sources requiring varied facilities

  21. OVERVIEW • Logical basis • Logic/Prolog programming ideas • Advantages for the first course • Technical course details • Experience and Conclusions 

  22. Experience • An elective course, open only to college freshmen, was taught for six years • Students readily handled the formal logic • The interactive and incremental style of Prolog programming promoted student success

  23. Conclusions • Students enjoyed logic/Prolog programming, and their performance met or exceeded that in the traditional first course • Analytical emphasis supports programming in whatever language follows next • The goal to reveal an intrinsic link between analytical thinking and computer solutions to problems is well served • Logic programming is a superior choice for students first programming course

More Related