Sage: plotting nth roots


I've added two more animated GIF (click on it to see the animation) to illustrate how the secant approximation to the tangent line gets better as the two points get closer. This example involves the cube root of x, which is an important example of how a function which is continuous everywhere is not differentiable at x=0.

But $latex f(x)=x^{1/3}$ is one of those quirky Sage things you need to get used to. It doesn't graph it the way a calculator would:


Sage is complaining about raising a negative number to a rational power and even refuses to show the part from -3 to 0.  So how do we get the entire graph? Take a look at the code for the animated GIF:

c = var('c')
p1 = plot(sign(x)*abs(x)^(1/3),-2,2)
a = animate([p1+point((0,0),rgbcolor='black',size=20)+ point((c,c^(1/3)),rgbcolor='black',size=20)+plot(c^(-2/3)*x,(x,-2,2),rgbcolor=(1,1/4,1/2)) for c in srange(1,0,-.05)],xmin=-2, xmax=2, ymin=-2,ymax=2)

The plot of $latex f(x)=x^{1/3}$ is created by: sign(x)*abs(x)^(1/3) and you've got an  example why Sage is a tool for the teacher but not appropriate for the student. First, to get around x being negative (and then raised to rational power) we take the absolute value of it--but now that the answer is positive. The sign(x) is 1 if x is positive, 0 if x is 0, and -1 if x is negative. An annoying contortion to plot a common function. I've added this information to the Sage Essentials page.

A slow time of the year, but there have been a couple of events to report on:

  1. The TCEC Superfinal between reigning champion Stockfish and challenger Komodo is over and Komodo is the winner: 33.5-30.5. There is some information and links posted here.
  2. AlJazeera has an article on how a school was uninvited from a basketball tournament, "...because of concerns its players would wear T-shirts printed with the words "I Can't Breathe" during warm-ups.".
  3. The NY Times has an article on the "Rage Against the Common Core".
  4. A piece from the Las Vegas Review Journal tells us, "The cut scores established by the testing consortia and approved by the state superintendents have established a threshold that will leave only 33 percent of students declared proficient.I’m not sure how local superintendents, school principals or teachers explain to the communities they serve that their children, who attend 5-star schools and earn grades of A or B, are identified as nonproficient on a national test based on the Common Core standards.". Only 33 percent proficient? That will make for some interesting parent-teacher conferences--though I suspect as long as the A's and B's don't change most of the parents won't care.

LaTeX: Math Article Template


Forget the math! The book Concrete Mathematics by Graham, Knuth, Patashnik is known by many just because of the unique choice of fonts. As the concmath package documentation explains, "The book was to be set using the AMS Euler fonts
designed by Hermann Zapf, replacing the usual Computer Modern fonts in math
mode. As for the text font, the original intention was to use Computer Modern
Roman as usual. However, the combination of Computer Modern in text mode
and Euler in math mode soon turned out to be unsatisfactory, and Don Knuth
eventually set out to develop a heavier variant of Computer Modern Roman that
was better suited to match the somewhat darker color of the Euler fonts.". The concmath package developed the original fonts further.

I've posted a template for a math journal article on the Latex page which is typeset in the Concrete Mathematics style. But there are 3 other font choices as well, shown in the red box in the picture. Simply comment out the fonts you don't want with a percent sign at the beginning and remove the percent signs from the lines with the font you want. You might be interested in still other choices of fonts in which case it's worth looking at this survey article on math fonts for LaTeX.

Here are some current events that caught my eye recently.

  1. The UK's paper The Guardian has an article on how anti-intellectualism is taking over the US. The article focuses on the banning of books from schools and the firing of teachers; I mentioned banning of books in Indiana back in October 2014. Numerous authors and editors are being removed from schools all across the nation and "There has been an unfortunate uptick in academic book bannings and firings, made worse by a nationwide disparagement of teachers, teachers' unions and scholarship itself. Brooke Harris, a teacher at Michigan's Pontiac Academy for Excellence, was summarily fired after asking permission to let her students conduct a fundraiser for Trayvon Martin's family. Working at a charter school, Harris was an at-will employee, and so the superintendent needed little justification for sacking her." Three books that cause problems are Harper Lee's To Kill a Mockingbird and Ray Bradbury's Fahrenheit 451. The courts have sided against teachers: "Expression is a teacher's stock in trade, the commodity she sells to her employer in exchange for a salary.'" Thus, the court concluded, it is the "educational institution that has a right to academic freedom, not the individual teacher."". In some cases, decisions of whether something is appropriate is made by someone who hasn't read the material.
  2. It appears that there will be a new winner for the TCEC Superfinal match. With 50 of the 64 games played, Komodo has a 2 point lead over Stockfish. You can follow the matches here.
  3. We've seen the militarization of some high schools. Now the Daily Caller tells us that 30,000 FBI agents are being trained for public places, businesses, and schools.
  4. RT tells us students at Lincoln College Preparatory Academy protested a speech by the governor: "During his speech, however, 12-14 students stood and put their hands in the air – referencing the “Hands up, don’t shoot” phrase that has become a rallying cry for police reform advocates in the aftermath of Michael Brown’s death......Soon after standing with their hands up, the students walked out of Nixon’s speech. According to the ACLU, they were “ushered out of the auditorium” by the school, sent home, and threatened with a 10-day suspension. Ultimately, the school settled on disciplining the students with Saturday detention." The ACLU is taking legal action.

SageTeX: Derivative Problems

CompFuncThe latest update consists of 2 problems added to the SageTeX: Derivatives page. One problem is for taking the derivative using the Quotient Rule and the other for the composition of functions (requiring the Chain Rule).

A reader mentioned that there were some issues with how their browser rendered the page awkwardly. When posting, I'm using the Chromium browser. So this site looks best when viewed through that browser. You can download Chromium from their site.

Here are some events that caught my eye.



Secant line approximation to tangent with animated GIFs

Derx2LAnimated GIF can be a useful tool in the classroom and Sage give you the ability to create them quickly and easily. The animated GIF above along with its mirror image of tangent lines from the left have been posted on the Sage in the Classroom page. The GIFs can be used to help bring to life the concept that the tangent line of a continuous function can be approximated by secant lines. The GIF above illustrates that from the right, the tangent looks like it is the horizontal line y=0.  I've actually created a second set of GIFs where xmin=-.2 and xmax=.2 to show the effect of zooming in. I think that will be useful for the class but I'm not posting it as the GIFs take up a lot of space and are essentially the same code.

And that code is remarkably simple: just 4 lines.

c = var('c')
p1 = plot(x^2,(x,-2,2))
a = animate([p1+point((c,c^2),rgbcolor='black',size=20)+plot(c*x,(x,-2,2),rgbcolor=(1,1/4,1/2)) for c in srange(1,0,-.05)],xmin=-2, xmax=2, ymin=-1,ymax=4)

The first line defines the variable c which is used to generate the moving point. The second line draws the function and axes. The 3rd line is where all the magic happens; animate consists of 3 objects being plotted: the function $latex x^2$, the point on the function which will move from frame to frame, and the secant line from (0,0) to that point $latex (c, c^2)$. The options for each (eg point size and color) are set and the part for c in srange(1,0,-.05) tell us that 20 frames will be created since c is taking on the values from 1 to 0 (but not including 0) where c is decreased by .05. More frames will mean smoother movement but this will, not surprisingly, increase the amount of time to create the GIF

The 4th and final line shows the GIF and places a delay of 1 second between each frame (so 50 = .5 seconds).

Here are some things that caught my eye recently:

1. Komodo and Stockfish have made it to the final for TCEC. They had an equal score against one another in the earlier qualifying round. Stockfish has been the first to draw blood on Game 7. But you can see a potential issue:

SKgm7aNote the difference in time used. In this game, as well as a game that Stockfish lost in the qualifying round, time management has been best handled by Komodo. In the qualifying round Stockfish had a roughly equal position and collapsed when it was left to play moves using the 30 second increment. It will be interesting to see if this turns out to be a factor in the finals.

2. The 6th London Chess Classic is over and Anand had a little help en route to a tiebreak win over Kramnik. Chessbase has a report here.

3. Remember the student who made $300,000 trading penny stocks during class? Not to be outdone a student in NY claimed to have made $78 million. That might seem preposterous to you and I but the media took it and ran. ZeroHedge showed the hearty skepticism that was lacking from mainstream news. And sure enough, the story broke down. ZeroHedge with the follow up story here. From the article, "The story is already coming unglued as the commenters on New York’s site hammer the reporter for even thinking this was possible. New York has now altered its headline to back away from the $72 million figure but the story itself remains. Even if this working-class kid had somehow started with $100,000 as a high school freshman on day one at Stuy High, he’d have needed to average a compounded annualized return of something like 796% over the three years since. C’mon, man."

Plotting the floor function: exclude, point, and circle

Here's the output if you try to use Sage to plot the floor function with the command

plot(floor(x), (x, -2.5, 2.5),color='red', thickness=2)

SageFloorThere's no asymptote here but the problem of the connecting one point to the next for a discontinuous graph results in a plot which is no longer a function. To get rid of this there is a plot option called exclude. Since we know the problem points are the integers between -2.5 to 2.5 we make sure that Sage knows there is a gap there.

plot(floor(x), (x, -2.5, 2.5), exclude = [-2..2],color='red', thickness=2)

In this case Sage throws out -2, -1, 0, 1, 2 and the graph is more like we'd expect.

SageFloor2The documentation on exclude can be found on this page of the Sagemath site. Now we're missing the detail as to what happens on the ends of each piece.

P=plot(floor(x), (x, -2.5, 2.5), exclude = [-2..2],color='red', thickness=2)
H = point([(t, t) for t in range(-2, 3)], color='red',size=20)
P += H

SageFloor3To get the open circles at the end we need the circles command.

P=plot(floor(x), (x, -2.5, 2.5), exclude = [-2..2],color='red', thickness=2)
H = point([(t, t) for t in range(-2, 3)], color='red',size=20)
P += H
disk((1,0), .2, (0,2*pi), color='red', fill=False, thickness=2)
for i in range(-2,3):

SageFloor4I've added this useful information to the Sage Essentials page.

Here are some events that caught my eye recently:

1. The TCEC Stage 7 matches are still close. Here are the current standings

TCES7s4Stockfish has rallied and is now in clear 2nd place. Note that Stockfish hasn't lost a game to Komodo and has a winning record versus every computer challenger. Since the championship will be decided by a match between the top two computers, it's chances to retain its title are still intact. The games are live here.

2. There was a school shooting in Portland on Friday. Police have captured a suspect. Here's the local TV broadcast.

3. Does math make you happy? If so, you might like Happy Face Math.

4. Meanwhile, some of the worlds best human chess players battle in London. The games are live on

SageTeX: Product Rule 1

ProductRule1The latest addition is a Product Rule problem not requiring the Chain Rule; it's posted on the Sagetex: Derivatives page.

Here are some issues that caught my eye.

  • It's here! Common Core testing begins in some states. From the article,"Across the country, 30,000 middle and high school students will be taking these math and English-language arts tests, and “millions more students in grades 3-11 will take such tests later in the winter and next spring,” according to an article on"
  • U.S. reports on a new study which seems to suggest that students should discover their own math lessons. From the article, "The conclusion of this small and imperfect study was that the more a teacher used student-centered approaches, the more his or her students learned, and the better they did on an exam of complex problem-solving that resembles the PISA international test for 15-year-olds, on which the United States has historically done poorly.".
  • TCEC Season 7, a chess tournament for computers, continues live here. The top two computers will play in a match for the championship. Komodo has taken the lead and refuses to let go. But second place is definitely more interesting. Last year's champion Stockfish is the only computer, at this point, to have a plus score against Komodo. But Stockfish is in danger of not making second because it has lost numerous games to Gull. Some hard fought high level chess is going on.
  • Bobby Jindal claims that Common Core violates the 10th Ammendment. See the video here.


Teaching Point: motivating digraphs

RPSLSIf you have accelerated math students then I'm a firm supporter of supplementing their curriculum with discrete mathematics. Discrete mathematics deserves a prominent place in high school mathematics:

  • it's relevant to computer science
  • some topics (e.g . combinatorics, graph theory) don't require a strong mathematical foundation to appreciate
  • it can be more interesting than other math topics (such as in The Prediction)

Depending on the curriculum you teach, graphs can be incorporated into the topics. In combinatorics you can ask questions about graphs (what's the maximum number of edges a graph can have) and in matrices you can look at the adjacency matrix of a graph and see what happens when you raise it to a power. Or how about  exploring stochastic matrices? Unfortunately, the role of discrete mathematics in the high school curriculum is limited to a small dose of combinatorics and probability and a bigger dose of matrices.

I think "The Prediction" is a great way to motivate graph theory. I think a great way to motivate digraphs is with The Big Bang Theory's explanation of "Rock, Paper, Scissors, Lizard, Spock". I've put together the digraph to represent the game; it's posted on the Graphics page (PDF and tex file). So imagine playing the video for the class and asking them to explain the rules. If they haven't seen it they're going to have trouble remembering all the possible scenarios. Eventually you can put the teaching point, "Digraphs help us see the relationship between things." on the board along with the digraph above. This has been added to the Teaching Points page.

Here are some things that caught my eye recently:

Sage animated gif: unit circle (radians)

SinRadIn an earlier post, I created an animated GIF using Sage to illustrate how the sine function came from movement of a particle around the unit circle. At the time I mention "A radians version would be more useful to me; perhaps when I have more time.". I've finally put together a radians version--you can see the screenshot above. The animated gif can be downloaded on the Sage output page. Like the degree version, it's built on the code given here.

Here are some stories that have caught my eye: