Friday, May 22, 2020

Lemay Lesson 4: Working with Objects

Table of Contents

1. Introduction
2. Mbira: Another Musical Google Doodle
3. Memorial Day on the Calendar
4. Lesson 4 -- Working with Objects
5. Another Rapoport Math Problem
6. Reblogging: SBAC Prep
7. More on Java and Geometry
8. More on the AP and SAT Exams
9. More on the Future of Education
10. Conclusion

Introduction

Today is the Friday before Memorial Day. In my old district, there would have been a four-day weekend for Memorial Day, with no school today.

Why is there an extra holiday today? It's a "floating day" that's there only when needed to make the last week of school have three days for finals (Days 178, 179, 180). It all depends on the exact lengths of winter and spring breaks, which in turn depend on which day of the week Christmas falls and how close Easter is to the designated spring break week (the fourth week of March).

Last year, it was a four-day weekend for Memorial Day. But the year before that, it was a three-day holiday weekend. And so if schools had been open, today would have been a non-posting day. I've done it often since the start of the closure -- post on days that I normally wouldn't.

Meanwhile, on the Islamic Calendar, today is the new moon at the end of Ramadan. The new moon occurred late this morning (Pacific time zone) and thus after sunset in the Middle East. As expected, the waxing crescent was not visible in those time zones, and so there is still at least one day left of fasting for Muslims.

Mbira: Another Musical Google Doodle

Yesterday, yet another musical Google Doodle appeared -- the mbira, a Zimbabwean thumb piano. As with previous interactive Doodles, this one is featured for two days, yesterday and today. I'm posting a little information about this doodle -- and I'm submitting this post a few hours earlier than usual, so that you'll have the opportunity to try this on the Doodle before it disappears.

The mbira contains 14 notes, which can be played using 14 keys on our computer keyboard. Here's a correspondence between the computer keys and musical notes:

Home Row = Treble Notes
Key   Note
S        g'
D       eb'
F        f'
G       bb
H       d'
J        bb'
K      c"
L       d"
;        eb"

Lower Row = Bass Notes
Key   Note
Z       g
X       f
C       eb
V       d
B       Bb

Here they are again, arranged from low to high:

Key   Note
B       Bb
V       d
C       eb
X       f
Z       g
G       bb
H       d'
D       eb'
F        f'
S        g'
J        bb'
K      c"
L       d"
;        eb"

As with strings, longer mbira keys sound as lower notes and shorter keys sound as higher notes. But there's a slight inconsistency on Google -- the F key sounds higher than the D key despite being shown as a longer key. I find this annoying when I press the keys S-D-F -- the F key is musically between the other two keys, despite sitting to the right of them.

The F key is the only key whose letter matches its musical note as it sounds as an f'. That is, unless you count the B key, which sounds as a German B (or Bb).

It's also possible to play the mbira using the mouse, but I prefer the keyboard since this allows us to play two notes at the same time (that is, harmony). This is better than the theremin, where only one note can be played at a time (melody).

As we look at the available notes, we see that both B and E have flats, suggesting Bb major, except that the seventh (A) is missing. We might also think of it as Eb major without the fourth (Ab). In addition, we see that the note C is available only in the highest octave (as c"). Thus in the lower octaves, Bb lacks the second (in addition to the seventh), and Eb lacks the sixth (and the fourth).

If we look at minor scales rather than major, then this is C minor without the sixth. This is what I've called the Kristen Lawrence Halloween scale, since many of her songs use this scale. But we can't really play any of those minor songs here -- the lack of C in the lower octaves makes it awkward to play any C minor songs. A more playable minor scale is G minor (no second, limited fourth).

Among triads, Bb major, Eb major, and G minor are all playable. C minor is playable only if we consider inversions (where C isn't the root note).

Here is a song that I created using a random number generator. At first I wanted to use the digit 0 to represent a rest and 1-9 to represent the keys S to ; on the home row. But then I chose 0 first (which would start the song with a rest), and there were a few points where the song kept jumping between the middle and high octaves. I changed these so that there's no rest at the start and there is only one octave jump:

Musical Notes: c" bb' c" bb' f' d' g' g' eb' d' g'_ c" bb' c" bb' f' f' eb' d' d" d" bb'_
Keyboard Key: K J    K  J    F H S S  D  H S_  K J    K  J    F F D  H L  L   J_
Running Bass:  B                 B            C             B                 X            B

This song is considered to be in the key of Bb major. (Note: Since I wanted to use 0 for rest and 1-9 for notes, we might try converting the digits of pi or another constant into this scale.)

As for songs that I performed in class that are convertible to this scale, "Benchmark Tests" works. I originally wrote this song in C major with no seventh -- but after I sang it a few times, I ended up dropping the fourth as well. (Once again, I can make up random notes all I want -- a song isn't musical until it sounds right, and in this case, dropping the fourth sounded right.)

Since the new version has no fourth, I can play it in Eb major on the mbira. The scale that my song is in is, in fact, the pentatonic scale. But the five playable notes (excluding C) on the mbira do not form a pentatonic scale since it contains the seventh instead of the sixth. Fortunately, by playing the song in Eb major, the single playable C note (the sixth) is in just the right place for the song:

The Benchmark Tests Song
Musical Notes: eb' f' eb' f' eb' eb' eb'_ eb' f' g' f' eb' f' eb'_ f' c" eb" c" bb' bb' bb'_
Keyboard Key: D  F D   F D  D   D_   D  F S F D   F D_  F K  ;     K J    J     J_
Running Bass:  C               C                C            C             X               B

Each verse contains eight bars -- the six listed bars plus the last two repeated. I always end the song by repeating the first two bars.

Memorial Day on the Calendar

Memorial Day was originally known as Decoration Day. It was created to mark the end of the Civil War and commemorate the soldiers who lost their lives during the war. Its traditional date was May 30th, but now it falls on the last Monday in May. And of course, instead of remembering soldiers, many people treat it as the unofficial start of summer instead.

Notice that "Friday before Memorial Day" and "fourth Friday of May" are equivalent -- both refer to the Friday between May 22nd and 28th. And filmmakers would take full advantage of this -- the summer movie season ought to start on Memorial Day weekend (the fourth Friday in May), but in order to get a jump on the competition, some blockbusters would open earlier. The start of summer movie season gradually became the third Friday in May, and then the first Friday in May.

Last year, Aladdin opened on Memorial Day weekend, John Wick III opened on the third Friday in May, Pokemon opened on the second Friday, and Avengers couldn't even wait for the first Friday in May, instead leaping ahead to the last Friday in April (Arbor Day)! Of course, that was last year -- due to the virus, no blockbusters are opening this May.

One thing I've noticed about Memorial Day and Thanksgiving is that they're the two federal holidays that are closest to being directly opposite each other -- this year, Memorial Day is May 25th, while Thanksgiving will be November 26th. (New Year's Day and Fourth of July are the only other federal holidays that are nearly antipodal.)

And in fact, Thanksgiving has become the unofficial start of the winter (or holiday) season in the way that Memorial Day has become the unofficial start of summer. Both are associated with big meals (Memorial Day on the grill, Thanksgiving in the oven). And of course, the film studios have crept the holiday movie season up from Thanksgiving weekend to the first Friday in November, so that there are usually four weekends of blockbusters in that month as well.

On the school calendar, it's possible to have Memorial Day on the Early Start Calendar serve the same purpose that Labor Day does on the old calendar -- just as school shouldn't start before Labor Day on the old calendar, it shouldn't end past Memorial Day on the new calendar. There are about 90 school days between winter break and Memorial Day, so it's possible to have 90 days of school in first semester, let winter break divide the semesters, and finish before Memorial Day. But in practice, most schools don't have Day 1 early enough in August to have either Day 90 by Christmas or Day 180 by Memorial Day.

I've read that businesses that seek to hire students for summer jobs would prefer it if schools were closed through both Memorial and Labor Day. But it's impossible to squeeze in 180 days of school between Labor and Memorial Day (unless we forego winter and spring breaks, etc.). It might be possible to have a 160-day school year with 70 days in the first semester and 90 in the second. But many people believe that our 180-day school year is already too short relative to other countries, and would be opposed to an even shorter year, even if it benefits students looking for summer jobs.

Theoretically, colleges that work on a 4-1-4 plan (first semester from September-December, winter term in January, second semester from February-May) could start after Labor Day and end by Memorial Day. But in practice, the California State Universities here on the 4-1-4 plan still seem to start a week or two before Labor Day, putting college students looking for summer jobs (whose bosses want employees to work through Labor Day) at a disadvantage.

Once again, what I'm saying here applies to normal years. This year is anything but normal.

Lesson 4 -- Working with Objects

Since I waited so long to post, I wish to speed this up a little. So I will attempt to do all of Lesson 4 today rather than split it up into Part 1 and Part 2 as I did with Lessons 2-3.

Lesson 4 of Laura Lemay's Teach Yourself Java in 21 Days! is called "Working with Objects." Here's how this chapter begins:

Let's start today's lesson with an obvious statement: Because Java is an object-oriented language, you're going to be dealing with a lot of objects. You'll create them, modify them, move them around, change their variables, call their methods, combine them with other objects-and, of course, develop classes and use your own objects in the mix.

As usual, I'll compare Java to the object-oriented language I already know, C++. First, we notice that there are differences between strings and other objects:

The String class is unusual in that respect-although it's a class, there's an easy way to create instances of that class using a literal. The other classes don't have that shortcut; to create instances of those classes you have to do so explicitly by using the new operator.

And that's our first difference between C++ and Java. In C++, new is only used when we wish to create an object on the "free store" (a special area of memory), but in Java, we must use it to call the constructor and create any object (other than a string).

Our first listing involves Date objects, which are built into a Java package that we can import:


Listing 4.1. Laura's Date program.
 1: import java.util.Date;
 2: 
 3: class CreateDates {
 4: 
 5:     public static void main(String args[]) {
 6:         Date d1, d2, d3;
 7: 
 8:         d1 = new Date();
 9:         System.out.println("Date 1: " + d1);
10: 
11:         d2 = new Date(71, 7, 1, 7, 30);
12:         System.out.println("Date 2: " + d2);
13: 
14:         d3 = new Date("April 3 1993 3:24 PM");
15:         System.out.println("Date 3: " + d3);
16:     }
17: }
(Of course, "Laura" here refers to Laura Lemay, our author.)

My output matches Lemay's, except that Line 9 gives today's date:

The second Date object you create in this example has five integer arguments. The arguments represent a date: year, month, day, hours, and minutes. And, as the output shows, this creates a Date object for that particular date: Sunday, August 1, 1971, at 7:30 a.m.

And yes -- the argument 71 means 1971. Thus Java isn't Y2K compliant -- changing this to 20 means 1920 and not 2020. Meanwhile, as the author tells us, the months start from 0, so 7 is August. I know that this is true in C++ as well -- the months start from 0, yet the days start from 1. And so day 1 really means the 1st, not the 2nd.

The next concept is dot notation:

To get to the value of an instance variable, you use an expression in what's called dot notation. With dot notation, the reference to an instance or class variable has two parts: the object on the left side of the dot and the variable on the right side of the dot.

This listing uses dot notation to access a Point class and its variables, the x- and y-coordinates:


Listing 4.2. The TestPoint Class.
 1: import java.awt.Point;
 2: 
 3: class TestPoint {
 4: public static void main(String args[]) {
 5:     Point thePoint = new Point(10,10);
 6:
 7:     System.out.println("X is " + thePoint.x);
 8:     System.out.println("Y is " + thePoint.y);
 9:
10:     System.out.println("Setting X to 5.");
11:     thePoint.x = 5;
12:     System.out.println("Setting Y to 15.");
13:     thePoint.y = 15;
14:
15:     System.out.println("X is " + thePoint.x);
16:     System.out.println("Y is " + thePoint.y);
17:
18:  }
19:}

The dot notation is also used to call class methods as well as variables.

This listing uses dot notation to access the string class and its methods:

Listing 4.3. Several uses of String methods.
 1: class TestString {
 2: 
 3:     public static void main(String args[]) {
 4:         String str = "Now is the winter of our discontent";
 5: 
 6:         System.out.println("The string is: " + str);
 7:         System.out.println("Length of this string: "
 8:                 + str.length());
 9:         System.out.println("The character at position 5: "
10:                 + str.charAt(5));
11:         System.out.println("The substring from 11 to 17: "
12:                 + str.substring(11, 17));
13:         System.out.println("The index of the character d: "
14:                 + str.indexOf('d'));
15:         System.out.print("The index of the beginning of the ");
16:         System.out.println("substring \"winter\": "
17:                 + str.indexOf("winter"));
18:         System.out.println("The string in upper case: "
19:                 + str.toUpperCase());
20:     }

I wish to compare Java's string class to BASIC, another language known for its strings. Of course, both languages have a length method, which BASIC calls LEN. Instead of "substrings," BASIC calls these "midstrings." These substrings are indexed starting with 1 rather than 0, and the length is specified rather than the end position, so str.substring(11, 17) would become written as MID$(S$,12,7) in BASIC. On the other hand, the only way to use charAt in BASIC would be to write MID$(S$,6,1), and indexOf has no equivalent in BASIC.

As a math teacher, I find Java's Math class useful:

Class methods can also be useful for gathering general methods together in one place (the class). For example, the Math class, defined in the java.lang package, contains a large set of mathematical operations as class methods-there are no instances of the class Math, but you can still use its methods with numeric or boolean arguments. For example, the class method Math.max() takes two arguments and returns the larger of the two. You don't need to create a new instance of Math; just call the method anywhere you need it, like this:
int biggerOne = Math.max(x, y);
(The author leaves out the t in int, so I just filled it in here.) In order to use this, we must write:

import java.lang.Math;

This is what the author means when she tells us that Math is in the package java.lang.

We now move on to references:

As you work with objects, one important thing going on behind the scenes is the use of references to those objects. When you assign objects to variables, or pass objects as arguments to methods, you are passing references to those objects, not the objects themselves or copies of those objects.

And references are shown in the next listing:


Listing 4.4. A references example.
 1: import java.awt.Point;
 2:
 3: class ReferencesTest {
 4:     public static void main (String args[]) {
 5:        Point pt1, pt2;
 6:         pt1 = new Point(100, 100);
 7:         pt2 = pt1;
 8: 
 9:         pt1.x = 200;
10:         pt1.y = 200;
11:         System.out.println("Point1: " + pt1.x + ", " + pt1.y);
12:         System.out.println("Point2: " + pt2.x + ", " + pt2.y);
13:     }
14: }
Here we see that when we change pt1, it changes pt2 as well, since these are the same object. In C++, references exist, but it all depends on how the function or constructor is written, and the symbol & must be used. In Java, these are automatically references without any need for an ampersand.

And closely related to references in C++ are pointers. Lemay explains:

There are no explicit pointers or pointer arithmetic in Java as there are in C-like languages-just references. However, with these references, and with Java arrays, you have most of the capabilities that you have with pointers without the confusion and lurking bugs that explicit pointers can create.

OK, I admit that I find the section on converting to objects confusing. For some reason, we must distinguish between int vs. Integer, and boolean vs. Boolean. Apparently, one of them in each pair is a primitive (primordial) type while the other is a class. The class is needed because we can only convert from primitive to primitive and class to class. (And I'm completely confused as to why the Void class is needed.) Hopefully, this will be explained in more detail as I proceed through this text.

In the final listing, we learn the difference between == and String.equals:


Listing 4.5. A test of string equality.
 1: class EqualsTest {
 2: public static void main(String args[]) {
 3:         String str1, str2;
 4:         str1 = "she sells sea shells by the sea shore.";
 5:         str2 = str1;
 6:  
 7:        System.out.println("String1: " + str1);
 8:         System.out.println("String2: " + str2);
 9:         System.out.println("Same object? " + (str1 == str2));
10:  
11:        str2 = new String(str1);
12:  
13:        System.out.println("String1: " + str1);
14:         System.out.println("String2: " + str2);
15:         System.out.println("Same object? " + (str1 == str2));
16:         System.out.println("Same value? " + str1.equals(str2));
17:     }
18:  }
The first time, str1 and str2 are references to the same object, so we get true, but after we used new the second time, they are the different objects (==) but with the same value (equals). In BASIC, = for strings tests only for the same value.

In Lemay's Q & A, one of her questions refers to C++:


Q:
No operator overloading in Java? Why not? I thought Java was based on C++, and C++ has operator overloading.
A:
Java was indeed based on C++, but it was also designed to be simple, so many of C++'s features have been removed. The argument against operator overloading is that because the operator can be defined to mean anything; it makes it very difficult to figure out what any given operator is doing at any one time. This can result in entirely unreadable code. When you use a method, you know it can mean many things to many classes, but when you use an operator you would like to know that it always means the same thing. Given the potential for abuse, the designers of Java felt it was one of the C++ features that was best left out.

Another Rapoport Math Problem

Today on her Daily Epsilon of Math 2020, Rebecca Rapoport writes:

(The number of magic squares of order 4)/40

No, this isn't a Geometry problem -- its reference to "squares" doesn't make it Geometry. A magic square of order n is a configuration of natural numbers from 1 to n^2 such that the sums of every row, column, and diagonal are equal. Here is an example of a magic square of order 3:

276
951
438

The sum of each row, column, and diagonal is 15. But now we are asked to count how many magic squares there are, which is easy in the order-3 case. There are other order-3 magic squares:

438
951
276

492
357
816

But notice that in case, a simple isometry maps the original square to the new one (a reflection in the first case and a rotation in the second). If we consider two magic squares to be identical if there exists an isometry mapping one to the other, then there is only one order-3 magic square.

 Of course, the order-4 case is much more complicated. There exist many magic squares that are distinct in that no isometry maps one to the other. All of them have the same magic number, 34.

As it turns out, it's impossible to calculate it exactly. It seems as if there ought to be an elegant method, such as "there are 16 possibilities for the first number, 15, for the second number, and 14 for the third number -- then there's only one possible number for the fourth number so that the entire row adds up to 34," and so on.

But there isn't such a method. The only reason we know how many magic squares there are is that over the centuries, some mathematicians counted them one-by-one:

http://www.magic-squares.net/order4list.htm

There are 880 basic magic squares of order-4. The complete set was compiled by Bernard Frénicle de Bessy before 1675. [1][2]
This list has been recalculated and verified by many people since that time (myself included).

These 880 magic squares were classified into 12 groups by H. E. Dudeney and first published in The Queen, Jan. 15, 1910. The classification diagrams appeared later in Amusements in Mathematics, 1917, published by Thomas Nelson & Sons, Ltd.

Here are some of the magic squares from this list:

Magic Square #692
  4  9  813
10  714  3
15  211  6
  516  112

Magic Square #576
  4  11316
1415  3  2
1110  6  7
  5  812  9

Magic Square #335
  2  9  716
1514  4  1
  6  31312
11  810  5

The above website contains links that list all 880 of them. And thus this is a pure research question from the Rapoport calendar. Either we know how many magic squares there are or we don't.

And so to answer today's question, the number of magic squares of order 4 is 880, so we obtain:

(The number of magic squares of order 4)/40 = 880/40 = 22

Therefore the desired answer is 22 -- and of course, today's date is the 22nd. There are several Numberphile videos on magic squares, although none of them give 880 as the number of order-4 magic squares there are. One of them is on a the Parker Square, a semimagic square that's almost magic except one of the diagonals doesn't sum to the magic number. (In the YouTube comments, there's a running joke where a "Parker" something is something that almost works, but doesn't.)

Reblogging: SBAC Prep

Last year, May 22nd was a Wednesday, but I didn't sub that day, nor did I post much. All I wrote last year was SBAC Prep, which I will reblog here:

Question 23 of the SBAC Practice Exam is on comparing rates:

Nina has some money saved for a vacation she has planned.

  • The vacation will cost a total of $1600.
  • She will put $150 every week into her account to help pay for the vacation.
  • She will have enough money for the vacation in 8 weeks.

If Nina was able to save $200 a week instead of $150 a week, how many fewer weeks would it take her to save enough money for the vacation? Enter the result in the response box.

First of all, let's ignore the given value $1600 completely, since it has nothing to do with the solution of this problem. What we want to know is, how long will it take Nina to save the same amount of money at $200/wk. as she does at $150/wk. for eight weeks? Thus this is the equation:

200w = 150(8)
200w = 1200
w = 6

So it takes her six weeks to save the money as opposed to eight weeks. Therefore it will take her two fewer weeks (that is, 8 - 6) to save the money -- students should enter the number 2.

Sometimes students might forget that even though w = 6, they must enter the number 2, since the question is not how many weeks will she save, but how many fewer weeks. Sometimes I avoid this problem by letting x = 8 - w, so that as soon as I find x, I have the number I need to enter:

200(8 - x) = 150(8)
1600 - 200x = 1200
-200x = -400
x = 2

I often solve Pappas problems this way -- using the variable x only for the final value that I need to find rather than any intermediate values. Also, if there's a system of equation and Pappas asks us to solve for x, I might eliminate y even if x is easier to eliminate, so that I find the actual asked-for value more directly.

Both the girl and the guy from the Pre-Calc class have trouble with this question. In fact, the guy has only written:

150x = 1600

on his paper, with no final answer. The girl, on the other hand, has written a little more:

1600 = 150w
150(8) = 1600
200

and then she gives 6 weeks as her final answer. Yes, it does take Nina six weeks to save the money -- but that answer isn't justified by anything on the girl's paper. Actually, I'm starting to wonder whether I've attempted to help her during class, perhaps by telling either her only or the entire class that it takes eight weeks to save the money at the slower rate or six weeks at the faster rate. So she tries to include the numbers 8 and 6 somewhere on her paper.

Once again, I wonder whether there's anything to do to make this question easier for the students to understand and answer correctly. Earlier, I wrote that 1600 has nothing to do with the solution -- so let's restate the problem with the 1600 line left out:

Nina has some money saved for a vacation she has planned.

  • She will put $150 every week into her account to help pay for the vacation.
  • She will have enough money for the vacation in 8 weeks.

If Nina was able to save $200 a week instead of $150 a week, how many fewer weeks would it take her to save enough money for the vacation? Enter the result in the response box.

Now look at those first two lines again. The lady will save $150 per week for eight weeks -- that is, she will save a total of $1200. The problem is less confusing because we now know that the target amount is $1200, not $1600. No student would write an equation with 1600 at all, and so more students are likely to get the right answer.

But what is a teacher to do, since we can't make that 1600 line disappear from the computer we're using to administer the SBAC? Well, we can ask the students to look for extraneous information -- for example, we read the following to them out loud:

Nina has some money saved for a vacation she has planned.


  • The vacation will cost a total of $1600.
  • She will put $150 every week into her account to help pay for the vacation.
  • She will have enough money for the vacation in 8 weeks.

Question for the class: how much money will she have saved in eight weeks?

The hope is that that point, the students see that 150 * 8 = 1200, so it's $1200. At this point, the teacher tells the students that so far, 1600 has nothing to do with the problem. The phrase "enough money for the vacation" is another way of saying $1200. This is not the same as the total cost of the vacation, $1600, since presumably Nina already has $400 in the bank before saving begins.

If Nina was able to save $200 a week instead of $150 a week, how many fewer weeks would it take her to save enough money for the vacation?

And since the phrase "enough money for the vacation" is another way of saying $1200, we can rewrite the question as:

If Nina was able to save $200 a week instead of $150 a week, how many fewer weeks would it take her to save $1200?

And now it becomes obvious that at $200 a week, it takes six weeks to save $1200. It now remains for the teacher only to emphasize fewer -- it's not how many weeks, but how many fewer weeks (than eight) it takes for her to earn the money. Therefore we must subtract 8 - 6 = 2.

Some people criticize the Common Core over wording in questions such as these. Indeed, yesterday and today we have two consecutive Questions 22-23 with the phrases "average rate of change" and "enough money for the vacation" -- and both are likely to trip students up.

But I'm not sure how this question can be improved. We might really be in a situation where we want to save money for a trip, but already have money in the account. Thus we must realize to consider that we already have some money, and so it's the remainder that we need to save.

Question 24 of the SBAC Practice Exam is on quadrilaterals:

Consider parallelogram ABCD with point X at the intersection of diagonal segments AC and BD.

Evelyn claims that ABCD is a square. Select all the statements that must be true for Evelyn's claim to be true.

  • AB = BD
  • AD = AB
  • AC = BX
  • Angle ABC isn't 90
  • Angle AXB = 90

Here's some Geometry -- yes, it's been some time since I posted Geometry on this Geometry blog. I'll look at the three length equations first. AD = AB is obviously true, since the sides of a square must indeed be congruent. On the other hand, AB = BD is definitely false -- the diagonal of a square is sqrt(2) times the length of a side, not the same length as a side. And AC = BX is false as well -- the diagonals of a square (or any rectangle) are congruent, and so AC can't be half of BD (which is what BX is, as the diagonals of a parallelogram bisect each other).

Now let's look at the angle statements. The statement that ABC isn't 90 is obviously false -- the angles of a square must be exactly 90. The other statement that AXB = 90 is true, since the diagonals of a square are also perpendicular. So students must select two correct answers, AB = AD and AXB = 90.

Notice that if all Evelyn knew about her parallelogram is AB = AD and AXB = 90, that would not be sufficient for her to conclude that it's a square. A rhombus, after all, also has congruent sides and perpendicular diagonals. (In fact, given that ABCD is a parallelogram, just one of these two is sufficient for her to conclude that ABCD is a rhombus.) On the other hand, adding the falsity of the claim that ABC isn't 90 (that is, the truth that ABC = 90) to either of the two selected statements is enough for Evelyn to conclude that ABCD is a square.

Both the girl and the guy from the Pre-Calc class correctly answer this question.

More on Java and Geometry

Speaking of Geometry, let me now use Java to solve some Geometry problems. Once again, anyone can cut-and-paste Lemay code into the Java compiler -- that doesn't make me a coder. I'm not a coder until I can create my own Java code.

So far, what I've learned in Java is very limited. But in today's lesson, Lemay gives a Point class, so why don't we use that class to do some simple coordinate Geometry?

In Chapter 11 of the U of Chicago text, we learn about three things we can do with points involving their coordinates:

  • Slope Formula
  • Midpoint Formula
  • Distance Formula
Let's try the Slope Formula first. The Slope Formula involves division, but Lemay never explains whether the member variables of Point are of type int or float, and so I don't know whether we'll see integer or decimal division when we write our slope program. In either case, it won't be fractional division, so don't expect to see a slope of 1/3 or anything like that.

Well, there's only one way to find out whether Point uses int or float -- just write out the code and see what happens.


import java.awt.Point;

public class PointyThings {
public static void main(String args[]) {
Point pt1 = new Point(10,10);
Point pt2 = new Point(5,15);
float slope = ((pt2.y - pt1.y)/(pt2.x - pt1.x));
System.out.println("The slope is " + slope);
}
}

Output:
The slope is -1.0

OK, so that works.

Let's try the Midpoint Formula now. Notice that the midpoint of two points is another point, so we should create a new Point object that contains the midpoint.

import java.awt.Point;

public class PointyThings {
public static void main(String args[]) {
Point pt1 = new Point(10,10);
Point pt2 = new Point(5,15);
float slope = ((pt2.y - pt1.y)/(pt2.x - pt1.x));
System.out.println("The slope is " + slope);
Point midpt = new Point((pt1.x + pt2.x)/2,(pt1.y +                      pt2.y)/2);
System.out.println("The midpoint is " + midpt);
}

}

Output:
The slope is -1.0
The midpoint is java.awt.Point[x=7,y=12]

The program compiles and there are no errors, but there are two things wrong here. First of all, we asked the compiler to println the point directly, but we can't do that -- instead, we see the Java notation for the point. (Lemay never prints points directly -- she only prints out both coordinates one at a time.)

I could fix it were it not for the second problem -- the coordinates are indeed both int. The true midpoint should actually be (7.5, 12.5), but we must use int division, which truncates down to the next integer.

Let's just forget about midpoint and see whether we can do the Distance Formula. We know that this requires a square root function. Lemay never explains how to do square roots, but they definitely sound like something that might be in the Math class. So let's import that class and try it out:

import java.awt.Point;
import java.lang.Math;

public class PointyThings {
public static void main(String args[]) {
Point pt1 = new Point(10,10);
Point pt2 = new Point(5,15);
float slope = ((pt2.y - pt1.y)/(pt2.x - pt1.x));
System.out.println("The slope is " + slope);
double dist = Math.sqrt((pt2.x - pt1.x)*(pt2.x -                        pt1.x) + (pt2.y - pt1.y)*(pt2.y - pt1.y));
System.out.println("The distance is " + dist);
}
}

Output:
The slope is -1.0
The distance is 7.0710678118654755

And yes, this works. I did notice that in order to use the Math.sqrt method, I must use double, not float. Also, it's cumbersome to write out what I'm multiplying twice. I wonder whether the class Math contains some sort of squaring or power method.

Well, two out of three isn't bad. I'm not sure what to do about midpoint, though.

Of course, a real programmer wouldn't write the code like this. Most likely, we'd create separate methods to calculate the slope and distance, but I don't know how to do that yet.

More on the AP and SAT Exams

Today is the last day of the AP exams. And they continue to be fraught with problems whenever students try to submit them.

This week, the AP allowed students to submit their work by email. This helped out the students with second week exams, but it's too late for those with first week exams -- and recall that the first week included most subjects that we probably care about on the blog. In particular, Calculus, the hard sciences (Chemistry and Physics), and Computer Science A all tested the first week. Only Statistics has its test today.

And I can only imagine what it's like to be a young student taking the AP exams these two weeks. In my senior year, I took Calculus BC, English Literature, Physics C (both Mechanics and Electricity & Magnetism), and Government (both US and Comparative). Of those six exams, only Comparative Government is today -- the others all tested in the first three days, when it was hard to submit to AP.

Recall that my five-year-old computer had trouble downloading Java earlier this month. Thus I would likely have struggled to submit the tests during the first week.

In fact, some students are now suing the College Board over the AP submission problems:

https://edsource.org/2020/california-students-sue-college-board-after-being-unable-to-submit-ap-exams

(One commenter in that thread also mentioned the problems with time zones -- all students around the world had to take the test simultaneously due for security reasons. I'm not sure what the AP could have done about this -- no matter what time on the clock they chose, it would have been in the middle of the night for someone in the world.)

And even without the computer submission problems, my first day would have been brutal -- both Physics C exams and US Government tested on that first Monday. Yes, I know that the tests are only 45 minutes each this year, but still, three AP exams in one day is tough.

I'm not sure what the AP should have done with the exams this year. Some people believe that the AP's, just like the SAT and SBAC, should have been cancelled. This is especially true for those who believe that standardized tests only benefit the testing companies and not students or teachers.

But then again, I'm grateful that I had taken my AP tests. Due to all of my credit, I was able to begin at UCLA with sophomore status, and I used my fourth year to begin a master's degree in math. If the AP's had been cancelled my senior year, I likely never get my MA degree because I wouldn't have been able to afford it.

And so I'm not quite sure what could have been done better here. The coronavirus crisis has caught everyone by surprise this year, and it's certainly been just as difficult on the test makers as it is on the test takers.

Oh, and speaking of exams, it's official -- the SAT will no longer be required for UC admissions:

https://edsource.org/2020/in-historic-action-uc-moves-to-drop-sat-act-and-develop-a-replacement-exam-for-admissions

This means that none of the cohorts I taught at the old charter school (classes of 2021-2023) will need to take a standardized test for UC's (and I suspect the Cal States will soon follow). Recall that the dean there kept mentioning the importance of getting high SAT scores in order to get the kids to misbehave there, and as it turns out, the test won't even be needed for them.

More on the Future of Education

I'm also starting to hear more and more ideas about how to open schools in the fall. Many are emphasizing the need for social distancing if there are to be students on campus. And it's more important for elementary students to be in school, since these students can't stay home alone if both parents are at work.

One proposal I've heard is to have secondary students continue distance learning, while elementary students take over the middle and high school campuses in order to spread out. If my new district, which normally goes elementary K-6, middle 7-8, and high 9-12, were to adopt this plan, we might see something like elementary K-3, middle 4th, high 5-6, distance only 7-12.

And this worries me as a sub, since the only work subs could get would be in elementary. Notice that technically, I'm hired as a K-12 sub, though I choose to sub in secondary only. If this plan were adopted, then I'd be forced to sub for elementary students. I'd still try to avoid kindergarten, since this is outside my comfort zone -- and I'd go for sixth grade, since I did teach sixth graders at the old charter school. But there might be many other subs like me who are trying to avoid the lower grades, and they might grab the upper grade jobs quickly, leaving me stuck with kinder.

Meanwhile, my old district is a high school only district, rather than a unified K-12 district. The elementary schools in the city don't own the high school campuses, so I'm not quite sure what they'd do if the unified districts choose to house elementary kids on high school campuses.

Even so, there will be a need to hire more elementary schools -- even while falling revenues indicate that the budget for schools will be cut. And the place I fear the cuts may come could be the secondary schools -- if all teaching is online, a teacher could handle a load of 200-300 students, thus freeing funds for elementary teachers.

Conclusion

And all of this again underscores my need to learn Java. I have no idea what the future of education will bring, and what schools will look like next year. This might not be a good year to be a middle or high school teacher, whether as a regular teacher or a sub. I definitely need something like coding to fall back on.

You can expect my Lesson 5 Lemay post about a week from now.

Thursday, May 14, 2020

Lemay Lesson 3 Part 2 -- Java Basics

Table of Contents

1. Introduction
2. Update on Virus & Closures
3. Lesson 3 Part 2 -- Java Basics
4. Some Rapoport Geometry Problems
5. Reblogging for Today
6. Conclusion

Introduction

It's been ages since I've posted on back-to-back days. I decided that I might as well finish Lesson 3 right away. I've already downloaded Zoom and Java, and with all my downloading complete, I need to get through these lessons quickly.

Update on Virus & Closures

I've heard that the stay-at-home order, which was set to expire tomorrow, is supposed to last for three more months. An exact date hasn't been announced -- some sources say July 31st, while other claim it's August 31st. To me, it's logical just to add three months to tomorrow's date to get August 15th -- which is, to me, uncomfortably close to the first day of school.

Notice that this order applies only to the County of Los Angeles, not the State of California. Recall that my two districts are in two different counties. (I mentioned this back when it appeared that an initiative to divide California into three new states would make the ballot -- my two districts would have ended up in two different states under the proposal.) Then again, the state budget proposal that Governor Gavin Newsom released today suggests cuts throughout the budget, including to schools.

Oh, and speaking of LA County, another thing that won't happen is the LA County Fair. This is the fair that the old charter school visited every year and inspired my fair song. I'm sorry, but this year you won't be able to meet me in Pomona, Mona.

I'll wait to see how this affects the first day of school in my districts -- if a stay-at-home order extends past the start of the new school year. Meanwhile, I've heard that the California State University system is set to have all online classes for the fall semester. Some people think it might be awkward for college students to be home but for K-12 students to be in classrooms, thereby suggesting that all K-12 schools remain online only through the end of December as well. This will be very problematic for us subs -- thus making the need for me to learn Java and escape being a sub all the more urgent.

And speaking of online education, I've heard that the online AP exams are causing problems for some students on their computers. The AP Calculus exam was on Tuesday, and those who have older, outdated software were unable to submit. As the owner of a five-year-old computer, I can certainly relate to these students. We'll see whether the AP website is working in time for the AP Computer Science A exam tomorrow.

As for the SAT exam, I've heard that the UC system might not require the SAT test not just for the upcoming Class of 2021, but for 2022 and 2023 as well. This means that none of the students I taught at the old charter school will need to take the exam. Again, the dean at my old school tried to get my students to behave by pressing the need to do well on the SAT -- how could he have known that a coronavirus would wipe out the SAT for all of those students?

Lesson 3 Part 2 -- Java Basics

Here is the link to today's lesson:

http://101.lv/learn/Java/ch3.htm

Lesson 3 of Laura Lemay's Teach Yourself Java in 21 Days! is called "Java Basics." Here's where we left off:

More About Assignment

Variable assignment is a form of expression; in fact, because one assignment expression results in a value, you can string them together like this:
x = y = z = 0;
Once again, my point of emphasis will be on comparisons to C++. And right here in explaining variable assignment, Lemay writes:

The right side of an assignment expression is always evaluated before the assignment takes place. This means that expressions such as x = x + 2 do the right thing; 2 is added to the value of x, and then that new value is reassigned to x. In fact, this sort of operation is so common that Java has several operators to do a shorthand version of this, borrowed from C and C++. Table 3.4 shows these shorthand assignment operators.

Once again, I won't show you Table 3.4, but notice that I did use one of those shorthand assignment operators in the "two-to-the-three-to-the" method from yesterday:

double twotothethreetothe(int n) {
     int cell0 = 1;
     for (int i=1; i<=n; i++)
          cell0 *= 3;
     double cell1 = 1.0;
     for (int i=1; i<=cell0; i++)
          cell1 *= 2.0;
     return cell1;
}

Here cell0 *= 3; is shorthand for cell0 = cell0 * 3. The original BlooP doesn't have this shorthand, and so Hofstadter had to write CELL(0) <= 3 X CELL(0);.

We move on now to incrementing and decrementing:

As in C and C++, the ++ and -- operators are used to increment or decrement a variable's value by 1. For example, x++ increments the value of x by 1 just as if you had used the expression x = x + 1. Similarly x-- decrements the value of x by 1. (Unlike C and C++, Java allows x to be floating point.)

That's interesting, though I can't think of a need to increment or decrement a float as of now. And of course, I've already used i++ in yesterday's program posted above.

Like C++, Java distinguishes between prefix ++i and postfix i++ notation. The next listing demonstrates how it works:


Listing 3.2. Test of prefix and postfix increment operators.
 1: class PrePostFixTest {
 2: 
 3: public static void main (String args[]) {
 4:     int x = 0;
 5:     int y = 0;
 6: 
 7:     System.out.println("x and y are " + x + " and " + y );
 8:     x++;
 9:     System.out.println("x++ results in " + x);
10:     ++x;
11:     System.out.println("++x results in " + x);
12:     System.out.println("Resetting x back to 0.");
13:     x = 0;
14:     System.out.println("------------");
15:     y = x++;
16:     System.out.println("y = x++ (postfix) results in:");
17:     System.out.println("x is " + x);
18:     System.out.println("y is " + y);
19:     System.out.println("------------");
20: 
21:     y = ++x;
22:     System.out.println("y = ++x (prefix) results in:");
23:     System.out.println("x is " + x);
24:     System.out.println("y is " + y);
25:     System.out.println("------------");
26: 
27: }
28: }
In Line 15, postfix x++ assigns 0 to y and then increments x to 1. In Line 21, prefix ++x increments x to 2 and then assigns 2 to y.

At this point other operators are listed, and they work just like C++. The key ones are == for equals (since = is assignment -- again, equality and assignment are distinguished in every language except for Mocha BASIC) and != for does not equal. I already used <= for less than or equal in the program from yesterday.

There are also logical operators, namely && for and, || for or. I already used && in the Goldbach method from yesterday. There are also "bitwise" logical operators:

Finally, here's a short summary of the bitwise operators in Java. Most of these expressions are inherited from C and C++ and are used to perform operations on individual bits in integers. This book does not go into bitwise operations; it's an advanced topic covered better in books on C or C++. Table 3.6 summarizes the bitwise operators.

I won't give Table 3.6 or explain the bitwise operators here.

We learn about "operator precedence," which is essentially Java's version of PEMDAS.

We learn about "string arithmetic," where + is used to concatenate strings. Other languages, including BASIC, use + to concatenate strings. In BASIC, we can't add strings to non-strings, but we learn that in Java, we can.

Lemay wraps up the chapter with a little Q&A. One of the questions here mentions C++:

Q:
Why does Java have all these shorthand operators for arithmetic and assignment? It's really hard to read that way.
A:
The syntax of Java is based on C++, and therefore on C. One of C's implicit goals is the capability of doing very powerful things with a minimum of typing. Because of this, shorthand operators, such as the wide array of assignments, are common.

Some Rapoport Geometry Problems

Yes, there's finally a week full of Geometry problems on the Rapoport calendar. Unfortunately, today isn't one of them.

Today on her Daily Epsilon of Math 2020, Rebecca Rapoport writes:

What is the difference between the prime factors of 8051?

This is a tricky one since it's not easy to find the factors of the number in question. The number 8051 clearly doesn't have 2 or 5 as factors, nor does is it a multiple of 3 as its digit-sum is 14 (omega rule) or a multiple of 11 as its alternating digit-sum is 4 (alpha rule). Trial division by 7 reveals that 8050 is a multiple of 7, but not 8051.

This might take some time, so let's try estimating the size of the factors. The way the question is worded -- "the difference between the prime factors" -- suggests that this number is a semiprime or the product of exactly two primes. One of these two factors must be less than the square root of 8051 while the other must be greater. And the square root is 8051 is almost 90, since 90^2 = 8100.

Hmm -- 8051 is exactly 49 less than the perfect square 8100. In other words, 8051 = 90^2 - 7^2. This gives us an idea:

8051 = 90^2 - 7^2
         = (90 + 7)(90 - 7)
         = (97)(83)

And as both 97 and 83 are prime, we are done. Subtracting them gives 97 - 83 = 14. Therefore the desired difference is 14 -- and of course, today's date is the fourteenth. Using the difference of squares is much more efficient than trial division, where it would have taken us forever to find the prime factors 97 and 83.

(In fact, as soon as we saw that 8051 is 7^2 shy of a perfect square, we know that the difference between the factors is twice 7 or 14 without finding the factors. But of course, we might as well find the factors anyway to make sure that both are prime.)

So this isn't a Geometry problem, but there are several Geometry problems coming up within the upcoming week on the Rapoport calendar. Let's look at these problems in a random order -- yes, I'm doing it this way so you'll have to do the problems rather than cheat by just giving the date.

Problem #1: Find x.

[Here is the given info from the diagram: it's a right triangle with legs x and 21 and hypotenuse 29.]

This is a straightforward Pythagorean Theorem problem:

x^2 + 21^2 = 29^2
x^2 + 441 = 841
x^2 = 400
x = 20

Therefore the desired leg length is 20 -- and of course, this problem will be for the twentieth.

Problem #2: Regular polygon.

[Here is the given info from the diagram: it's a decagon with interior angle measure 8x.]

A decagon has 10 sides, an so we use the Polygon-Sum Theorem from Lesson 5-7:

8x = (10-2)180/10
8x = (8)180/10
x = 180/10 = 18

Therefore the desired value is 18 -- and of course, this problem will be for the eighteenth.

Problem #3: A regular pentagon is enclosed with 90 evenly spaced posts, with a post at each vertex. How many posts are on each side of the pentagon?

This would appear to be a case for the Equilateral Polygon Perimeter Formula of Lesson 8-1:

p = ns

Plugging in the values give:

90 = 5s
s = 18

Thus each side of the pentagon is 18 units. But hold on a minute -- we already did the problem from the eighteenth, so the desired answer can't be 18.

As it turns out, the posts at each vertex are counted as part of two different sides of the pentagon. So there are actually 19 posts on each side -- multiplying by 5, this would give 95 posts with five of them double-counted, for a final total of 90 posts. Therefore the actual correct answer is 19 posts -- and of course, this problem will be for the nineteenth.

This is the classic "fence post error" that often shows up in problems involving fences. (I know, the original problem said "posts," not fence posts -- but that's what they usually mean.) The fence post error often shows up in computer coding. Here's an example from BlooP:

DEFINE PROCEDURE "PRIME?" [N]:
BLOCK 0: BEGIN
     IF N=0 THEN:
     QUIT BLOCK 0;
     CELL(0) <= 2;
     LOOP AT MOST MINUS [N,2] TIMES:

And let's cut it off here. Why do we loop at most n - 2 times? It's because we want the loop to start with 2 at the first trial divisor  -- the value of CELL(0)-- and n - 1 as the last trial divisor. Due to the fence post error, we might think this is (n - 1) - 2 = n - 3 iterations, but in reality it's n - 2 iterations.

Once again, we haven't quite reached loops in Java, but notice that the for loop of Java or C++ avoids the loop-counting fence post error since we specify the start and end values, not the total number of iterations:

boolean isprime(int n) {
     if (n<2)
          return false;
     for (int i=2; i<n; i++)
          if (n%i==0)
               return false;
     return true;

}

Then again, whether the loop condition should be i<n or i<=n (that is, i less than or equal to n) may also be considered a fence post error. We know that it needs to be i<n since if i=n, we'd always get a divisor because n always divides n, so we'd always get false and never find any primes. This is the "itself" part of the definition "a prime number has no factors other than one and itself."

Fence-post errors are usually neither compile- nor run-time errors -- the program still runs, but we'll get invalid answers (such as no numbers are prime). They might cause a run-time error, for example, if we have i>=0 instead of i>0 and attempt to divide by i. (A good compiler might be able to catch a fence-post error if the loop involves the index of an array, but we haven't reached arrays yet.)

Problem #4: The distance between (32, 12, 5) and (20, 3, 13)

We obviously must use the Distance Formula in Three Dimensions, from Lesson 11-6:

d = sqrt((20 - 32)^2 + (3 - 12)^2 + (13 - 5)^2)
   = sqrt(12^2 + 9^2 + 8^2)
   = sqrt(144 + 81 + 64)
   = sqrt(289) = 17

Therefore the desired distance is 17 -- and of course, this problem will be for the seventeenth.

Problem #5: Find x.

[Here is yet another unlabeled diagram, but unlike the other problems, I need to give you labels in order for it to make sense to you. In Triangle ABC, Angle C is right, AC = 36, BC = 45, D is on BC such that Ray AD bisects Angle A, BD = x.]

This problem starts out as another Pythagorean Theorem problem:

BC^2 + 36^2 = 45^2
BC^2 + 1296 = 2025
BC^2 = 27
BC = 27

But no, this problem isn't dated the 27th. That's because we're asked to find BD, not BC.

This problem requires a theorem that has appeared on our mathematical calendars in the past, but not in the U of Chicago text. Because it involves angle bisectors, it's often referred to as the Angle Bisector Theorem:

https://mathbitsnotebook.com/Geometry/Similarity/SMAngle.html

Angle Bisector Theorem:
An angle bisector of a triangle divides the opposite side into two segments that are proportional to the other two sides of the triangle.

The link above gives a proof of this theorem. Of course, the word "proportional" is a huge giveaway that the proof will have something to do with similarity (not to mention "similarity" in the URL).

Notice that this theorem applies to all triangles, not just right triangles -- though the particular triangle we're applying it to happens to be right:

x/45 = (27 - x)/36
36x = (45)(27) - 45x
81x = (45)(27)
x = (45)(27)/81
x = 45/3 = 15

Therefore the desired length is 15 -- and of course, this problem will be for tomorrow, the fifteenth.

Reblogging for Today

Unlike yesterday, there's not much to reblog in last year's May 14th post. I did sub in a special ed math class that day, but I don't need to post that again. So instead, I reblog only the SBAC questions:

Question 11 of the SBAC Practice Exam is on statistics:

Click above the numbers to create a line plot for the given percent chances of rain in different cities.

65, 65, 70, 70, 80, 80, 80, 80, 85, 95, 95, 95, 100

This is a statistics question -- and as I mentioned in my last post, stats, if it's to be taught in Algebra I at all, is covered in the second semester.

As with many Common Core Statistics questions, this is the first time that I've ever seen a "line plot." Apparently, it's similar to a bar graph. There should be two X's above 65, two X's above 70, no X above 75, four X's above 80, one X above 85, no X above 90, three X's above 95, and one X above 100.

The girl from the Pre-Calc class correctly answers for this question. But unfortunately, the guy from that class skips this question altogether. It doesn't help that the question doesn't print on the packet properly -- rather than before Questions 12-13, it appears on the next page after Questions 16-17.

Question 12 of the SBAC Practice Exam is on dimensional analysis:

The formula for the rate at which water flows is R = V/t, where

  *   R is the rate,
  *   V is the volume of water measured in gallons (g), and
  *   t is the amount of time, in seconds (s), for which the water was measured.

Select an appropriate measurement unit for the rate.

A) gs
B) g/s
C) s/g
D) 1/sg

This question on units could appear in the first half of an Algebra I text, since this is a linear equation (provided t is given or a constant). This problem basically solves itself -- the rate is V/t, and V is in g while t is in s. Thus V/t is in g/s, or gallons per second. The correct answer is B).

Both the girl and the guy from the Pre-Calc class correctly answer B) for this question.

Conclusion

We're done with Lesson 3 of the Lemay text. Some of the things I tried to do in the BlooP programs yesterday will be taught in Lesson 4, which will be at some point next week.

And for those of you who are students about to take the AP Comp Sci A exam tomorrow (and are using this website to review a little Java), I wish you good luck in answering the questions, and good luck in being able to submit your answers.