Upload
gwyn
View
56
Download
2
Embed Size (px)
DESCRIPTION
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. - PowerPoint PPT Presentation
Citation preview
Frontiers in Education 2007 1
Logic (Prolog) as the First Programming Language
Arthur Fleck
Professor Emeritus
University of Iowa
2
OVERVIEW
• Logical basis
• Logic/Prolog programming ideas
• Advantages for the first course
• Technical course details
• Experience and Conclusions
3
Logical basis
• 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)
4
Logical basis
• Predicates/relations
• Existential and universal quantification
• broOf(john_kennedy,
robert_kennedy)
• In logic and - X.broOf(X, robert_kennedy)
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 and ,conclude
6
Logical basis• Truth vs. proof
truth -- dependence on unlimitedvalues of logic variables makesdirect determination impossible
proof -- concludes truth from analysisof formula syntax, is independent of variable values, and requires notruth evaluation
7
OVERVIEWOVERVIEW
• 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). % yieldsC=mariaSriver -- and many more
• ?- cousin(C,mariaSriver). % yieldsC= 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 useof truth tables
2. Emphasize differences (e.g., domains, quantifiers) found inpredicate logic
3. Explain the relationship betweenproof 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 thisprocedural 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