Arxiv:2108.09893V1 [Cs.CY] 23 Aug 2021 the Algorithm Reads in the Facts and Rules, and II

Arxiv:2108.09893V1 [Cs.CY] 23 Aug 2021 the Algorithm Reads in the Facts and Rules, and II

1 Teaching and learning rules. Prolog is then given a goal to try and mathematics with Prolog satisfy, which sets it off finding combinations of Tom Bensky, Cal Poly San Luis Obispo, the facts that follow the rules. Such combina- [email protected] tions will comprise the \solution" to the stated 24 August 2021 goal. As an example, suppose one is designing a travel-planning application in Prolog. The facts would be cities on a map that are ABSTRACT connected by roads, and what daily traffic pat- terns typically look like on the roads. Facts are Procedural computer languages have long usually fairly straightforward to come by. In been used in many aspects of mathematics ped- this case, the road and traffic data could easily agogy. In this work, we examine the use of Pro- be found on the Internet or even based on one's log, a declarative language for the same pur- personal experience. Facts are usually quanti- pose. We find the facts+rules aspect of Pro- ties one knows or can easily find or identify and log to be a novel platform for developing cod- are simply thought of as true. ing lessons to supplement the learning of math- The rules about the problem are more diffi- ematics. Specific examples are presented. cult to formulate, and are more specific to the problem itself. Rules express in general terms, some relationship one would like to find from I. INTRODUCTION the facts. In the travel application, the rules would involve distance and traffic considera- We have all likely used a computer to enhance tions when traveling from city A to city B, and our understanding of mathematics in some form some formulation that would minimize travel or another. For mathematics pedagogy, there is time. The rules would be very general, free no shortage of books on doing so.1{7 Websites of any specifics about either A or B, and read- are also sources of mathematical lessons on cod- ily applicable to the facts provided. A travel ing.8 rule may very well include concerns for time of Procedural coding languages are the familiar travel, speeds, distances, etc. This rule is to ones, like Python, C, Lua, Pascal, BASIC, or be applied to the facts to find for example, an Javascript. Using these languages involve solv- optimal list of cities to visit. ing a problem with code, using a sequence of Prolog is thus known as a declarative lan- variables, loops, functions, that collectively im- guage since one does not supply step-by-step plement some step-by-step logic (i.e. the \pro- instructions on how to solve a problem. Facts cedure") to solve the problem. and rules are declared, and this is all Prolog This article suggests that coding in Prolog, a needs to search for a solution. The eventual declarative language offers some novel opportu- outcome (or solution) will be all combinations nities to study mathematics, not made available of the facts that are consistent with the rules. with procedural languages or computer algebra How does this work? systems. Internal to Prolog is a run-time engine based around a well-implemented search algorithm. arXiv:2108.09893v1 [cs.CY] 23 Aug 2021 The algorithm reads in the facts and rules, and II. PROLOG: A BRIEF INTRODUCTION works to find combinations of facts that are consistent with the rules, automatically adjust- Coding in Prolog9{12 involves an entirely dif- ing to the search landscape as it runs. It will ferent thought process than needed by a proce- for example, abandon search paths that have dural language. Instead of providing a step-by- no possibility of succeeding, while also keeping step procedure, one provides two sets of infor- track of areas where a search looks more promis- mation about the problem at hand: facts and ing. We emphasize that one does not code the 2 search functionality; this is built into the Prolog relatively easy to come by, with the rules being run-time engine. (Rules are sometimes called more difficult. We assert here that the formula- \clauses" in Prolog, and will be used somewhat tion of the rules into mathematics into Prolog is interchangeably here.) very natural, and is the supplemental exercises The goal in Prolog launches a search of of the study of mathematics that we propose. the facts+rules in an attempt to satisfy the goal. A goal is usually a statement or se- quence of statements that guides Prolog in A. Example: Adding two fractions examaining the rules, to drive some problem specific logic. Again in the travel application, As an example, think of coding a tutorial that after the city and road facts are set, followed shows how to add two fractions.14 The facts are by some travel rules, a goal may have the plainly seen: the numerators and denominators form of go(paris,rome)., where go is some of two fractions. Now what rules apply to add top-level clause that starts the Prolog search. them properly? This is a bit more difficult, In very general terms, this may resemble some- because we know for instance that 1/4+1/2 is thing like go(A,B) :- road exists(A,B), not 2/6. It would be incorrect to supply a rule low traffic(A,B), ... and on, as required. that said \The sum of two fractions is found by In the travel application, it hopefully seems adding the numerators, then adding the denom- plausible that that a shortest route between inators." A correct rule would say \First look at cities could in principle be found by looking at the denominators. If they are the same then the facts about roads and traffic. How the search denominator is also used in the answer, and add should proceed however is not so intuitive. But the numerators to find the answer's numerator." Prolog handles the search aspects, so one only Another rule is needed if the denominators are need to focus on writing rules and presenting different. facts. This is a huge burden lifted off of the Facts can be put in almost immediately and programmer, and allows for sole focus on de- is a rather fun and inventive process, owing scribing the problem at hand via the facts and to Prolog's flexibility as a coding language. rules. In this regard, code is Prolog tends to be Code representing fractions for example could much shorter than an equivalent solution imple- be something like fract(1,4) or fract(1,2), mented in a procedural language. Also, since to express the facts about the two fractions, one the facts and rules are so plainly seen, coding 1=2 and the other 1=4. We note that fract is features of the problem being solved stay in the not a functor built into the Prolog language. It forefront. Simple changes to the code are also is of our own convenient making, that Prolog usually straightforward to implement.13 happily accepts. Here fract takes two param- eters, a numerator and a denominator. The rules however require more care. Inde- III. STUDYING MATHEMATICS WITH pendent of any coding, one must first be com- PROLOG fortable with all of the mathematical rules for adding fractions, then must adapt them into We suggest that the facts, rules, and search Prolog code. Here's a rule to add two fractions characteristics of Prolog are ideal for study- that have the same denominator: ing mathematics. Why? Because, it's hard to add(fract(N1,D1),fract(N2,D2),fract(N,D)) :- think of anything more fact and rule-based than D1 == D2, D = D1, N is N1 + N2. mathematics. Facts here would be the state- ment of the problem. The rules would be the The clause (or rule) called add takes in two rules of mathematics itself, which are mostly parameters, fract(N1,D1) and fract(N2,D2). what is taught in math classes. As in the travel You can see the use of the facts of the fract application, facts for a math problem are again functor. On entry, we expect N1, D1, N2 and 3 D2 to be instantiated (that is, equal to some tions that have a common denominator: as the numbers coming in). Prolog's job in the search denominator of the two incoming fractions, and as it uses this rule, is to find what N and D (the as the denominator of the resulting fraction. numerator and denominator of the fraction) will The body now only needs to evaluate N into the result from the sum of the two initial fractions, sum of N1 + N2. This will also work: that is consistent with the add rule. When writing code, clauses are usually qui- add(fract(N1,D),fract(N2,D),fract(N1+N2,D)). etly translated into one's native tongue (here English). Prolog can be difficult to translate To complete the rule, we still need to han- and perspectives on reading it are available.15 dle fractions with different denominators. Our mathematical logic is to convert the original (Quick Prolog review: :- means \if," , means fractions N =D and N =D into two fractions \and," ; means \or," variables are in upper- 1 1 2 2 case, everything else must be in lowercase, and each with the common denominator of Dsum = D D . The new numerator of N will be N 0 = the period (.) terminates facts and rules.) 1 2 1 1 N D and that of N will be N 0 = N D : The so called \procedural reading" of the 1 2 2 2 2 1 We thus change the problem to that of adding clause add would be \add can successfully add the fractions N D =(D D ) + N D =(D D ).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us