Logic programming: teaching strategies for ... - ACM Digital Library

0 downloads 0 Views 167KB Size Report
veronica@cs.sfu.ca. Gemma Bel-Enguix. GRLMC-Universitat Rovira i Virgili. Av. Catalunya 35. 43002 Tarragona, Spain. + 34 977 558223 [email protected].
Logic Programming: Teaching Strategies for Students with no Programming Background Veronica Dahl

Diana Cukierman

School of CS, Simon Fraser University & GRLMC-Universitat Rovira i Virgili Burnaby, B.C. V5A 1S6, Canada + 34 977 558223 / +1 778 782 3372

School of CS Simon Fraser University Burnaby, B.C. V5A 1S6, Canada + 1 778 782 7110

[email protected]

[email protected]

Gemma Bel-Enguix

M.Dolores Jiménez-Lopez

GRLMC-Universitat Rovira i Virgili Av. Catalunya 35 43002 Tarragona, Spain + 34 977 558223

GRLMC- Universitat Rovira i Virgili Av. Catalunya 35 43002 Tarragona, Spain + 34 977 559542

[email protected]

[email protected]

ABSTRACT Logic Programming, due to its inferential capabilities and high level power of expression, is more human-oriented than typical computer languages, in that it allows users to think in terms of logic statements, rather than in terms of implementation dependent concepts such as arrays or pointers. It therefore has good potential for promoting fairly immediate and impressive results even among beginners with no previous programming experience. However, the very features that make it easier for non-programmers to understand a program also make it easier for them to overestimate its meaning. For instance, the meaning that mnemonically chosen predicates suggest to a human reader, may easily be attributed to the set of clauses defining it, even when the clauses themselves do not imply it. In other words, untrained programmers tend to read into a program more than it actually says. In this article we describe a few teaching strategies developed from our experience teaching Prolog to non-computer specialists with humanistic sciences background.

Categories and Subject Descriptors

1. INTRODUCTION This article grew out of years of teaching logic programming (LP) to computer specialists, to students of related disciplines such as Cognitive Sciences, and to students from unrelated disciplines, such as Philology. We have found that the latter group, with no experience in programming languages, is actually quite amenable to relating well to the principles of programming in logic as long as we present them in an adequate way, and motivate them through presenting applications of their interest, focussing on possible interdisciplinary uses. In this article, we propose a new approach to teaching logic programming which is specifically geared to students with no previous knowledge of programming. Logic programming is considered to be difficult to teach even to students with previous programming experience. The most commonly used approaches for teaching logic programming to beginners have been identified and evaluated in [4] which analysed 14 textbooks spanning 25 years since the early 80’s, and classified them into three types:

K.3.2, Literacy

General Terms:

Computers and Education, Computer and Information Science Education, Literacy

1. 2. 3.

Logic based, Declarative features based Programs based.

Keywords: Logic Programming, humanities. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. WCCCE '10, May 7–8, 2010, Kelowna, Canada. Copyright © 2010 ACM 978-1-4503-0098-8/10/05... $10.00

The logic based approaches start by covering the abstract theories of mathematical logic and/or logic programming. They introduce first-order predicate logic and then map it to the Prolog language. They usually describe Prolog as a type of logic programming, and initially demonstrate the features that might be common to logic programming in general, followed by Prolog-specific features. Approaches which focus on Prolog’s declarative features require both theoretical and practical knowledge. The focus is not on supplying imperative instructions to the computer, but on specifying the problem domain and leaving the computer to

deduce how to solve a specific problem in that domain from the domain’s general description. Prolog is viewed as a combination of declarative features that include knowledge specification and descriptive style programming. Its double semantics (declarative/procedural) is particularly reviewed in several ways: specification based, database based, problem solving based, system based, and known facts and relations based.

ones to non-programming experts, possibly because everyone relates to language, unlike for instance databases, no matter what their previous programming experience might be.

Programs based approaches require practical experience, and aim at developing the Prolog mindset concretely. Prolog is introduced through showing sample programs and the technical vocabulary used. Students can thus quickly get a feel of what Prolog programs look like, as well as see Prolog at work and contrast it with how other systems work.

2. the non-traditional approach of plunging into logic grammars first and logic programming next seems to work better for students with no previous exposure to computer programming.

The analysis evaluating the effectiveness of these approaches for total beginners, albeit students that have experience with other programming languages, concludes that over the past 25 years the teaching emphasis has moved from abstract and theoretical approaches into more concrete and practical ones, that the database approach is the most popular, and that hybrid approaches mixing components of all three are most effective. However we have found that with an audience that is inexperienced in programming none of these approaches really “works” in itself. For instance, among computing science students, the study concluded that the database approach proved to be the most popular, in the sense of best liked, but the authors explicitly do not take a position as to which might be more effective. This conclusion is not as helpful in our context, where students have no programming experience at all. In the mentioned study, the reason for preferring a database approach was that all students had reasonable previous exposure to database systems and their use, so presenting Prolog through databases appealed to students’ familiar concepts and built on them. Another of the study’s conclusions is that a hybrid approach that combines elements from other teaching approaches seems to work best. The conclusions from our own experience point to two main factors in effectiveness for teaching logic programming to nonprogrammers: constant interaction between the teacher and the students around the discovery mode of teaching (described below) and step-by-step hands-on immediate testing of concepts learned. Constant interaction is essential since many of the technical terms used in logic programming and in programming in general have a “commonsense’ meaning, and our main task as teachers is to clearly communicate that the two dialects, English and logic, share many words and expressions in their syntax, but with different meanings. We aim to make sure that these differences in meaning do not result in misinterpretations. A new, technical meaning for already known words needs to be carefully built as we go along, or we will lose the students in no time. Our approach exploits the uniqueness of the tool to be learned, in that its core inference rule and proof procedures makes sense to humans. It also exploits the linguistic features of Prolog as a crucial bridge between the humanistic and the formal sciences. We call it the language-conscious, discovery based approach. It is discovery-based in the sense that we guide students into stepby-step discovery, with minimal guidelines and relying on their innate sense of logical reasoning, one of the main concepts in logic programming. It is language-conscious in two respects. LP carefully elicits common understanding of the main terms used and it stresses language processing applications. We have found language processing applications to be among the most appealing

Our conclusions might seem surprising: 1. a capacity for abstract thinking is often more important than the "right" - or even any - computer programming background.

2. BACKGROUND: LOGIC PROGRAMMING VERSATILITY The appeal of logic programming for the humanities and for interdisciplinary work is twofold. On the one hand, given that its "instructions" take human-like reasoning forms (namely: if several conditions hold, a certain conclusion also must hold), they lend themselves to the expression of the most disparate domains of knowledge. This is attested to by the myriad of applications that it has proved useful. On the other hand, different components of the same system can be expressed in Prolog and interact with each other easily because of this uniformity of expression. For instance, we can implement an interdisciplinary system that contains a linguistic component (written in Prolog's logic grammar facility) as well as an information retrieval component (written in Prolog rules proper). It is widely accepted that high level languages in general and logic programming in particular are very useful for approximating computer reasoning and human reasoning, thus allowing us to explore problem spaces more transparently and efficiently than if we used more conventional programming languages. A bit more controversial is the notion that the ways in which logic programming approximates human reasoning make it easier than other languages for non-computing experts. In our experience with teaching Prolog to such an audience, we have found that the controversy is resolved by distinguishing the level of knowledge we are talking about. The basics of Prolog, which provide nonetheless the means for quickly writing impressive and powerful high level programs, are relatively easy and quick to learn. On the other hand, high proficiency, including for instance optimal formulations in the sense of elegance and efficiency, often requires more expert-like dedication. In this article, therefore, we seek those approaches to teaching Prolog which do not concern us so much with efficiency (although feasibility, e.g. by loop avoidance, is indeed targeted), but with conciseness and high power of expression. We aim at developing the student's proficiency in writing short code that can concisely express a problem domain in a highly declarative way. We also encourage students to develop programs that obtain answers in a reasonable albeit perhaps not optimal amount of time. We consider elegance of formulation to be more important than efficiency in this first learning stage; we have found that a concise, elegant formulation usually shows a better level of understanding than a sloppy one, and often as a side effect the program also turns out to be more efficient.

3. OUR PROPOSED APPROACH: LANGUAGE-CONSCIOUS DISCOVERY Main components 1. A “blank slate”: The fact that students have no computing background can be turned into a blessing: there is no past, no attachment to imperative thinking, no pull to express things differently than the way we shall elicit, and students report that the marvel of writing one’s own programs for the first time, and getting instant output, is paramount in motivating them to make further progress. We must capitalize on all this. 2. Openness to redefine terms that are second nature to us, such as the term “comment”, as we describe below. 3. Focus on the grammatical view: logic programming serves to translate something into something else, e.g. an English expression into a Spanish one, or two lists into a bigger one containing all elements from each. The discovery mode of teaching- an example This section illustrates what we mean by the discovery mode of teaching, through reproducing the first part of an actual introductory class to Prolog which took place at Universitat Rovira i Virgili, Spain, with an audience of Philology students at various stages in their career, with no experience whatsoever in programming, databases, logic, or anything closely related to LP. These students had however heard of the analogy between a computer and a black box, so that was our starting point. The students were told that they were to fill that black box so that we could later retrieve the contents as needed, and draw inferences from it. The first Prolog program was presented in the required syntax, and related to the language expressions it stood for (adam is a man, etc.): man(adam). man(frankenstein).

woman(eve). woman(cruella).

Next, students were asked to propose some way for asking some question about this program, and the reply was: “With a question mark?” Perfect answer, we only needed to point out that Prolog requires the question mark as a prefix, followed by a minus sign; thus identifying a question right away, rather than “waiting” till the end of the statement. We also pointed out that we have to respect the format in which the program has its information, to be able to query it. At this point students were able to come up with yes-no questions by themselves, e.g. who is a woman. The notion that a fact ends with a period and so does a question, being parallel with their linguistic notion of a period, was no problem for them to discover. The notions of facts, relationships, predicates and arguments were easy to introduce at this point. Variables were presented as smaller boxes contained within the big one which did not yet have their content made explicit. At this point students were able to come up by themselves with the way of asking who is a man (namely ?- man(X).), and to think of more complex queries, such as “Is there anyone who is both a man and a woman”. Next they were asked to define a “couple”, and they did so as a pair of individuals one of whom is a man and the other a woman.

They were asked to propose instances of couples in the world described by our first program, and the notion of importance in the order of the arguments derived from that. When asked for retrieving possible couples from the program, the notion of topdown, left-to-right use of the clauses followed quite naturally. The notion of “comment” was introduced as a notebook where one could write notes to oneself (not to the computer) in order to remember what we meant, e.g. % adam is a man, and which were not part of the program as far as the computer saw it. This is different from its normal meaning, in which a comment is a clarification which is at par with the main text, and very much part of it. The idea that comments can be thought of as belonging to another “space” (a separate notebook) was most useful to make this distinction clear. At this point, students were asked to propose an information domain which might be useful for them to describe in Prolog terms, so that they could subsequently consult it. They proposed a database of books read with their ratings (a number from one to ten), and defined the arguments they were interested in: author, name and rating. We wrote a subset of the desired system, with just two sample tuples. When asked in which ways they would like to use this system, they wanted to find out which books by Virginia Wolf they should read, with the criterion that a book was to be read if rated higher than 9. From this, the need for creating new relationships from the one given was motivated and resulted in the new relationship: need_to_read(Author,Title):- wrote(Author,Title,Rating), gt(Rating,9). The notion of backtrack followed from using the two relationships in the resulting program in order to answer the question: ?-need_to_read(virginia_wolf, Title). Students found it perfectly natural, once the search order was fixed, to explore the space themselves in the same way Prolog does. Approaching Prolog through grammars For several generations of students, we have been following the traditional teaching approach of focussing on Prolog proper, and treating Prolog’s grammatical variant [1,2] as perhaps one chapter among others in the process of learning, as a dispensable chapter, crucial only to people wanting to do natural language processing. When faced two years ago with our first course for students who all came from the humanities and had absolutely no previous computing experience, we found that presenting examples dealing with common knowledge expressible in natural language (such as the “couples dating expert system” just described) was more successful (unsurprisingly) than introducing list processing or numerical computations. Unification was most easily understood in language-related contexts. What was surprising, however, is that while unification is immediate for these students to understand in such contexts, they often find it tricky to extrapolate their understanding of it to more computation-specific structures. However if we start by introducing structure unification for the purpose of producing syntax trees or semantic representations of sentences from a language analyser perspective, it is subsequently easier for them to extrapolate their understanding of unification to non-linguistic structures. This simple switch, for some reason, makes all the difference in their learning.

Even starting directly with logic grammars makes sense to beginners, and can serve as a bridge into logic programs proper, by uncovering the link between rewriting into a string of symbols versus into a list of goals to be proved. That is, we present a logic program first as a kind of specialized grammar that explicitly manipulates the input and output strings solving problems in the linguistic domain, analysing or synthesizing strings of words, but cast in programming rather than grammatical terms. We have found that students can easily follow the programmed version of the linguistic problem once the grammatical version has been grasped. Only in a second stage we present logic programming as a kind of specialized grammar that solves problems as a side effect of rewriting, and which deals with goals to prove rather than symbols to analyse or to generate from. Translation Systems Translation is one of the areas in which students of literature, linguistics and philology usually are interested in and are often proficient. In our experience, translation systems are better understood if their grammatical formulation is presented first. A first translation example as simple as the one below, for translating sequences of three nucleotides into aminoacids, or vice versa, can be used for introducing concepts such as unification, backtracking, dual input/output roles of arguments, analysis vs. synthesis, automated deduction, resolution, the correspondence between grammars and programs, and so on. Table 1: Prolog vs. grammatical version of the program Prolog Version

Grammatical Version

translate([u,u,a],leucine).

s([u,u,a]) --> [leucine].

translate([g,c,a],alanine).

s([g,c,a]) -- > [alanine].

We have found that if we first present some simple translation system, whether in Prolog or in grammatical terms, moving into information retrieval becomes simpler. For students with linguistics or formal language backgrounds, the move into language processing applications is likewise facilitated.

4. CONCLUDING REMARKS There is a large pool of students who could benefit from exposure to high level computing such as through logic programming. Some of these students may apply it specifically, but even those who possibly are never destined to program will benefit, since such an exposure gives them the skill and confidence to embark on successful interdisciplinary endeavours in their future careers. As a desirable side-effect, groups that are underrepresented in computing, such as females, might be attracted into computing sciences careers and related interdisciplinary endeavours. Such efforts might prove to be amongst the most beneficial measures one can take towards social and economic health. For instance, in Canada the computer skills shortage is so high that such skills reportedly facilitate work permits for foreigners [5], and in Europe the demand for ICT skilled professionals is expected to reach 250,000 by the end of this year [6].

While we’ve often had mixed audiences in our logic programming courses, it is only in the last two years that we’ve needed to develop methods for students with no computer background whatsoever. Admittedly, this is a very short time and small student sample. Yet our results, as measured by student questionnaires, personal feedback, and success as evaluated by students’ progress were so impressive that we are starting an international cooperation for further follow-up and evaluation of our methods, in collaboration between the two institutions concerned: SFU and URV. The recommendations we would like to share at this point are thus preliminary but in our experience, most useful. We share them in the hope of helping other colleagues in similar situations, since many of these observations are not obvious to people not having had the experience. Most notably: •

the interactive, language and discovery-centered approach we have described here greatly facilitates the learning process



a capacity for abstract thinking is often more important than a computer programming background



the non-traditional approach of plunging into grammars first and Prolog next seems to work better for our type of audience



translation systems should be taught earlier than more general information systems, in particular humanities students relate more concretely to the translation task, which may even be an application they might use



theoretical concepts are best introduced through practice, e.g. the concept of a relation versus a function, which often confuses even computing students, can be introduced the first time that someone attempts to consult through a function information that was defined as a relation. Theoretical concepts sink in more indelibly - if somewhat subliminally - as a by-product of being needed/used, thus making both the theory and the practice easier to assimilate and to concretely own



focussing first on programming elegance and conciseness yields better results than worrying too much about efficiency



hands-on, immediate testing of concepts learned is most desirable, as it capitalizes on the thrill that students experience when enabled for the first time to produce automated output from expressing their thoughts to a computer

5. APPENDIX: STUDENTS FEEDBACK The following comments are from our Prolog course students majoring in Philology, in their 2nd, 3rd and 4th year of studies, none of whom had had any previous exposure to computer programming. “From the beginning I could understand step by step the notions of logic programming; the discovery method of learning helped me get closer to computational linguistics, whereas before I had no interest in it. My outlook has changed”.

“It seemed to me incredible that language and computation could relate, yet the simple method used, brought this about through analogies with things we already knew, and thus allowed us to understand and even retain the concepts.”

“For me the results were, right from the start, great and valuable”. “The use of grammatical examples was right on, because we were moving within a known world, and our familiarity with the subject helped concentrating on the process”.

“After just two hours of lecture, students are able to take their first steps in programming. Other than didactic, it was a very entertaining way to learn.”

“The use of grammatical examples is a good way of relating the theme to our interest, which is linguistics. From this point, a taste for logic, programming and other themes that are apparently far from language can be awakened.” “The use of known languages (Spanish, Catalan) was particularly appreciated”.

“The use of grammatical examples struck me as the best idea for a good understanding and to give a concrete flavour which can do way more than all the theories”. “It’s a good way to get into the unknown through the known. If mathematical examples had been chosen instead, we would not have understood as much”. “The use of metaphor for clarifying the computer-specific meaning of words that have another meaning in everyday speech (such as “comment”) made it easier to learn these concepts. I think that for learning something new, there is nothing better than utilizing something that one already knows and which is similar” (N.B. initially, a “comment” seemed to the students as something capable of “doing” something, until we equated it with a “cheat sheet”, or “crib sheet”: something to refer to, but not officially visible) . “Personally, I think that without such references to more colloquial expressions I would not have understood important parts of the lessons.” “I could get the concepts of backtracking and argument ordering very easily. What presented the most difficulties for me was the distinction between functions and predicates.” (N.B. Both these concepts were elicited from students- e.g., when asked how they would consult the information in the “black box”, they proposed an orderly search themselves, from left to right and top-down, and “going back” upon failure. The difference between functions and predicates seemed to be only well-learnt when students were trying to write a relation in functional notation but were made aware of the notational discrepancy). “The most difficult thing for me was not so much the notions, but associating them to a specific terminology”. “The most complicated thing for me was interaction with the computer, since I have no exposure to it.” “I found it interesting that from all the different data given, the program could discard those that weren’t conducive and choose the correct ones”.

“It’s a very effective method because it develops the students’ intuition.”

6. ACKNOWLEDGEMENTS We are most grateful to generations of students from Simon Fraser University and Universitat Rovira i Virgili who took our courses in AI, allowing us to discover and put to the test the conclusions we have presented here. Support from the European Commission in the form of V. Dahl's Marie Curie Chair of Excellence, and from both universities as well as from the Canadian National Sciences Research Council, is also gratefully acknowledged.

7. REFERENCES [1] Abramson, H. & Dahl, V. (1989). Logic Grammars. Springer, Berlin. [2] Colmerauer, A. (1978). Metamorphosis Grammars. In Bolc (ed.), Natural Language Communication with Computers, 63, 133-189, Springer, Berlin. [3] Kowalski, R. (in preparation). Computational Logic in Human Reasoning: How to be Artificially Intelligent. http://www.doc.ic.ac.uk/~a rak/. [4] Yang, S. and Joy, M. (2007) Approaches for Learning Prolog Programming [5]

http://www.canada-law.com/demand.htm

[6] http://www.e-skillsilb.org/docs/ILB_press_release_draft_29_Jan.pdf

Suggest Documents