Thursday, September 10, 2015

Lesson 2-3: If-then Statements in Computer Programs (Day 11)

The lesson scheduled for today is one that I want to change, for two reasons. First, Lesson 2-3 of the U of Chicago text focuses on the programming language BASIC -- and as I wrote last year, BASIC programming isn't common in the 21st century. I changed the lesson so that it focuses on TI-BASIC instead -- but that presumes that the students in the class have graphing calculators.

The other is that I've been meaning to move the first two lessons of Chapter 13 -- namely 13-1 on the Logic of Making Conclusions and 13-2 on Negations -- up to Chapter 2. Dropping Lessons 2-3 leaves a hole right in the middle of Chapter 2, and conveniently, 13-1 and 13-2 fit here. Indeed, 13-1 on Making Conclusions makes perfect sense right after Lesson 2-2 on If-then Statements.

I'm not sure whether I necessarily like all of this chapter-jumping. I already knew going in that I would be presenting the chapters in a different order from the U of Chicago -- and one purpose of posting lessons to the blog is so that I'm not bound by the U of Chicago order. Still, jumping from Chapter 2, one of the earliest chapters, to 13, one of the latest, seems a bit extreme.

But here's the thing -- the U of Chicago text is an outlier in waiting until Chapter 13 to introduce the students to logic. The only other text I know of that waits as late as Chapter 13 to introduce logic is Michael Serra's Discovering Geometry -- but of course the Serra text doesn't teach two-column proofs until late in the text. My first edition copy of Serra teaches converses, inverses, and contrapositives (the content of U of Chicago 13-2) in Lesson 14.6 -- the modern editions of Serra may teach it either in Chapter 13 or not at all.

On the other hand, most texts present this material in Chapter 2. Indeed, Dr. Franklin Mason's text teaches the content of U of Chicago 13-2 in his Lesson 2.3. So an argument could be made that I'm not actually jumping from Chapter 2 to 13 -- instead, I'm actually teaching the correctly numbered Lesson 2-3 (after yesterday's 2-2) after all, albeit in Dr. M's text instead of the U of Chicago!

So here's the plan -- I will post both my 2-3 and my 13-1/13-2 from last year. Recall that I'm not leaving Chapter 13 intact this year (just as Chapter 3 is already broken up). Chapter 13 is best divided up, with Lessons 13-1 and 13-2 included here with the logic of Chapter 2, Lesson 13-5 included with the circles of Chapter 15, and Lesson 13-7 included with the inequalities that are spread throughout the U of Chicago text (including Lessons 1-9 and 7-8).

The only change I had to make is that the Lesson 13-1/13-2 worksheet, because it was originally intended for Chapter 13, mentions information from Chapters 3 to 7. Even the reference to "acute angles" goes back to Chapter 3 -- so students following the blog lessons still haven't actually defined angle or any type of angle. But they should be able to find the negations and converses without knowing the definition of "acute angle." Still, there were two questions on parallelograms that I had to throw out. So that worksheet now has two fewer questions.

This is what I wrote last year for Lesson 2-3:

Lesson 2-3 of the U of Chicago text discusses computer programs written in BASIC. We must remind ourselves that this book was written over 20 years ago, back when BASIC was a popular language. But now, BASIC has been derided as "spaghetti code" and isn't as widely used anymore.

Of course, I asked myself whether I should even include this lesson on this blog. After all, I could have skipped it just as I omitted parts of Chapter 1 -- I can't expect the students in the classroom to have access to a computer at all, much less one that can be programmed in BASIC. But many students do carry around something that can be programmed -- a graphing calculator.

Now I'm aware that many students, especially below Algebra II, don't have graphing calculators. And even those who do have such a calculator usually don't know how to program it. I have an old TI-83 that I've owned ever since I was an AP Calculus student. Nowadays the standard is a TI-84. But still, I want to discuss how to program the TI graphing calculator. If the students have graphing calculators, then they might find this to be an interesting lesson -- especially since one of the reasons given for studying higher math is its use in computer science and video games. But if the students don't have access to calculators, or if the teacher doesn't wish to teach programming, then there can be a second day of Lesson 2-2 (or my lesson on 13-1/13-2 below).

The first BASIC program in the U of Chicago text gives the number of diagonals in a polygon:

10 PRINT "COMPUTE NUMBER OF DIAGONALS IN POLYGON"
20 PRINT "ENTER THE NUMBER OF SIDES"
30 INPUT N
40 IF N>=3 THEN PRINT "THE NUMBER OF DIAGONALS IS "; N*(N-3)/2
50 END

Now let's convert this program to the language of the TI. This language is often called TI-BASIC, even though it's not quite the same as usual BASIC. The first thing that we notice is that unlike BASIC programs, TI-BASIC programs have names. Also, BASIC lines have numbers, while TI-BASIC lines simply begin with a colon. Let's give this program the name DIAGONAL:

PROGRAM:DIAGONAL
:Disp "COMPUTE N
UMBER"
:Disp "OF DIAGON
ALS IN"
:Disp "POLYGON"
:Disp "ENTER THE
 NUMBER"
:Disp "OF SIDES"

:Input N
:If N>3
:Then
:Disp "THE NUMBE
R OF"
:Disp "DIAGONALS
 IS",N(N-3)/2
:End

We notice that the command PRINT in BASIC corresponds to Disp in TI-BASIC. The problem is that unlike a computer screen, the TI screen is only 16 characters across. So I had to divide up the lines of text into several Disp lines on the TI. The command Input is the same for both languages.

But, considering the title of this lesson, the emphasis is on the If line. We observe several differences between BASIC and TI-BASIC. First, in BASIC we write "greater than or equal to" as >=, but on the TI it has its own symbol, found on the TEST menu (2nd-MATH). Next, we see that Then has its own line on the TI, where in BASIC it is in the middle of the line. When displaying the number of diagonals, we notice that TI-BASIC uses a comma where BASIC uses a semicolon. Finally, on the TI we may use juxtaposition for multiplication, where in BASIC we must use an explicit multiplication system. Notice how the TI displays multiplication and division with an asterisk and a slash, respectively. These symbols actually date back to computer BASIC and other languages.

When I wrote this program in the exercises, I decided to include less text to display, since all the text printed by BASIC in the U of Chicago book was intended for widescreen computer monitors. Notice that my new if-then statement looks like this:

:If N>3
:Then
:Disp "DIAGONALS
",N(N-3)/2
:End

A TI-BASIC programmer wouldn't usually write this. As it turns out, if the body of theThen section contains only a single statement, then the line Then can be left out. But I decided to include it anyway in order for this program to look more like the BASIC program -- and to emphasis the word Then because of its importance in mathematical logic and geometry. Actually, if the word Then is omitted, then so should the word End. In TI-BASIC, End denotes the end of the if-then statement, whereas in BASIC, the wordEND denotes the end of the entire program. Actually, when I used to program in BASIC, I didn't need to include Line 50 in my program, but some computers require that line.

Here are some of the other programs from the questions, converted into TI-BASIC. First, here's the program from Question 12:

PROGRAM:ROBOTS
:Disp "HOW MANY 
ROBOTS"
:Input N
:Disp "PROFIT",5
N-1500
:If N<300
:Then
:Disp "ORDER MOR
E ROBOT"
:End

Sorry about the bad grammar there. The sentence "Order more robots" contains 17 characters when the maximum is 16.

Notice that the program in Question 13 uses 3.14159 for pi and multiplies by r twice. But the TI has both a pi key and a squared key. The proper way to enter the line corresponding to 20 is: start by entering pi (which is 2nd-^), then the letter R, then the squared key (left side of the calculator), then the STO-> key (just above ON -- this corresponds to the BASIC LET), and finally the letter A.

Question 25, in the Exploration section, contains a FOR loop in Line 20. As it turns out, TI-BASIC also has For loops. Here is the entire program:

PROGRAM:DIAGLOOP
:For(N,3,20)
:Disp "SIDES",N
:Disp "DIAGONALS
",N(N-3)/2
:Pause
:End

I decided to add a Pause at the end of the loop. Once again, this is because not all the lines of output can be displayed at the same time on the tiny calculator screen. In order to get the calculator to resume after pausing, simply press the ENTER key. Notice that the End line at the end of this program actually ends the For loop, so it corresponds to the line 50 NEXT N in BASIC, not the line 60 END. So this End line cannot be omitted.

Finally, question 26 asks the student to print an appropriate message if the input is less than 3. I assume that the book intends the student to add a second if-then statement:

:If N>3
:Then
:Disp "DIAGONALS
",N(N-3)/2
:End
:If N<3
:Then
:Disp "NOT ENOUG
H SIDES"
:End

But no professional programmer would do this. Instead, a programmer in both BASIC and TI-BASIC would use the Else command:

:If N>3
:Then
:Disp "DIAGONALS
",N(N-3)/2
:Else
:Disp "NOT ENOUG
H SIDES"
:End

But Else, unfortunately, is not mentioned in the U of Chicago text. In the end, since there isn't enough room (nor likely enough time, unless this becomes a two-day lesson) I decided to include the example program and the program in Question 12, but not the one in Question 13 (in order to avoid explaining the pi key or the STO-> key). Question 25 is included (since it's only a bonus question anyway), but not 26 (since it would be better written with Else).

If the condition in an If statement is false, then the Then statement is not executed. The book uses this fact to segue into what happens in mathematical logic if the hypothesis is false. Then as it turns out, the entire conditional is automatically true. This is called vacuous truth. The concept of vacuous truth can be confusing to many students. For example, the statement:

All unicorns are white.

is actually true -- after all, we have never seen a unicorn that isn't white (precisely because there exists no unicorns at all, much less ones that aren't white). Another way of thinking about this is that there are zero unicorns in this world, and all zero of them are white! In if-then form this statement becomes:

If an animal is a unicorn, then it is white.

The hypothesis is false (since there are no unicorns), so the entire conditional is true. This statement has no counterexamples (unicorns that aren't white), and conditionals without counterexamples are normally called true.

The book then derives, from the statement 1=2, the statement 131=177. There is a famous example of a derivation of a false conclusion from a false hypothesis, often attributed to the British mathematician Bertrand Russell, about a hundred years ago. From the statement 1=2, Russell proved that he was the Pope:

The Pope and I are two, therefore the Pope and I are one.

that is, he used the the Substitution Property of Equality from the hypothesis 1=2.

And here's what I wrote for Lessons 13-1 and 13-2, at the start of February:

In today's lesson, the U of Chicago text introduces the symbol not-p for the negation of p. In other texts, the notation ~p is used, but I have no reason to deviate from the U of Chicago here.

This chapter focuses on mathematical logic, which ultimately helps the students write proofs. I mentioned earlier that the Law of Detachment is often known by its Latin name, modus ponens. In fact, I pointed out that on the Metamath website -- a website full of mathematical proofs -- modus ponens is one of the most used justifications:

http://us.metamath.org/mpegif/ax-mp.html

Notice that I only mention the Metamath website for general information. This website is definitely not suitable for use in a high school math classroom. At Metamath, even a simple proof like that of 2+2=4 is very complex:

http://us.metamath.org/mpegif/2p2e4.html

 In fact, believe it or not the proof was once even more complicated because it tried to use pure set theory to prove that 2+2=4, and then later on more axioms (postulates) were added to make the proofs easier -- similar to the postulates for real numbers mentioned in Lesson 1-7. To repeat, the basic idea is that one makes a proof simpler by adding more axioms/postulates.

Before leaving this site, let me point out that this site gives yet a third way of writing the "not" symbol used in negations:

http://us.metamath.org/mpegif/wn.html

This is when students often ask, "Why do we have to learn proofs?" Of course, they ask because proofs are perhaps the most difficult part of a geometry course. The answer is that even though mathematical proofs may not be important per se -- but proofs are. Many fields, from law to medicine, depend on proving things. We don't want to guess that a certain person is guilty or that taking a certain medicine is effective -- we want to prove it. For centuries, the dominant way to learn how logical arguments work was to read Euclid. Let's learn about how Honest Abe learned about logical arguments from Euclid:

http://the-american-catholic.com/2012/08/16/lincoln-and-euclid/

Unfortunately, the above link is a political and religious website. Well, I suppose it's impossible to avoid politics when discussing Lincoln, but the webpage is also a Catholic site.






No comments:

Post a Comment