Sagetex: Derivatives page and problem

Diff1I've started a page for derivatives using SageTex and posted the first problem. The link to the page is located on the sidebar or you can click here. The first problem is taking the derivative of a polynomial to an integral power, using the Chain Rule. You can see a screen shot above.

Here are some things which caught my eye recently:

  • ABC news reports that students in Florida were caught running a high school prostitution ring. You can read the lurid details here.
  • The NYPost reports that East Side Community HS ran a 2 day course on how students should deal with police officers. The article states, "Principal Mark Federman said he brought in the NYCLU because students told teachers they had bad experiences with being stopped by police. He said the training also was relevant to history classes studying the Ferguson, Mo., shooting.".
  • Learning LaTeX?  Dickimaw Books has a  free book "LaTeX for Complete Novices" which can be downloaded here.

Problem: Combinatorics

TrianglesI've added another problem to the Problems page: How many triangles have vertices using the points above?

Here are some things which caught my eye:

Sagetex: Random pictures

CombGraphIn an earlier post I experimented with random bipartite graphs. With a little more practice under my belt, I've incorporated the same basic idea to create a random picture that is used in the latest addition to the Sagetex:Combinatorics/Probability page; problem 14. There are actually 3 problem variations here, depending on how deep you want to go into the classic problem of finding the number of shortest paths in a grid. There are several random aspects of the problem: the number of vertical lines in the grid, the number of horizontal lines in the grid, and the placement of the point M in the grid that all "special" paths must go through.

The basic idea for these problems is that your LaTeX file is a string and a part of the string will be created in sagesilent and then inserted into your latex document with a statement like \sagestr{output}. By creating the string in the sagesilent environment you're getting the power of Python and Sage commands. LaTeX was made for typesetting, so it's computational skills are limited. By tapping into Sage's calculating power combined with Python commands (for loops, strings) the sagetex package vastly increases the power of what can be accomplished in LaTeX.

The latest problem has you determine:

  • the number of shortest paths from A to Z (bottom left to top right)
  • the number of shortest paths from A to Z that go through M
  • the probability that a randomly chosen shortest path goes through M

Here is the sagesilent code from the latest problem. Note that the blog has destroyed the indentation which is necessary in Python. You should download the template (problem 14 on Sagetex: Combinatorics/Probability) for correct formatting.

k = Integer(randint(6,9))
n = Integer(randint(5,6))
m2 = Integer(randint(n-4,n-2))
m1 = Integer(randint(k-5,k-2))
output = r""
output += r"\begin{tikzpicture}[scale=.7]"
for i in range(0,n+1):
output += r"\draw (0,%s)--(%s,%s);"%(i,k,i)
for i in range(0,k+1):
output += r"\draw (%s,0)--(%s,%s);"%(i,i,n)
output += r"\draw [fill] (0,0) circle [radius=2pt];"
output += r"\node [left] at (0,0) {$A$};"
output += r"\draw [fill] (%s,%s) circle [radius=2pt];"%(k,n)
output += r"\node [right] at (%s,%s) {$Z$};"%(k,n)
output += r"\draw [fill] (%s,%s) circle [radius=2pt];"%(m1,m2)
output += r"\node [above left] at (%s,%s) {$M$};"%(m1,m2)
output += r"\end{tikzpicture}"

For the code above k and n are the length and width of the rectangle, so there are k+1 vertical lines and n+1 horizontal lines. Point M will have the coordinates (m1, m2). After choosing n, k, m1, and m2 randomly the picture that you would normally create in the body of your latex document is "typed" in sagesilent as a string, called output. The command: output += r"\begin{tikzpicture}[scale=.7]" starts building the string. The r occurs before the " symbol to indicate that a raw string is used. This is needed because LaTeX has various symbols, such as \, that aren't treated properly if output was a normal string. The default scale is 1, I've dropped it to .7 to make the picture smaller. This allows me you put have a bigger grid for your picture without it running out of the margins.

Python for loops create the horizontal lines

for i in range(0,k+1):
output += r"\draw (%s,0)--(%s,%s);"%(i,i,n)

and vertical lines

for i in range(0,k+1):
output += r"\draw (%s,0)--(%s,%s);"%(i,i,n)

The %s is the string content that will be filled in. In

output += r"\draw (%s,0)--(%s,%s);"%(i,i,n)

there are 3 strings that have data that needs to be determined by Python. The respective values will be i, i, and n, which are varying depending on where you are in the for loop.

The placement of points is determined through commands like

output += r"\draw [fill] (%s,%s) circle [radius=2pt];"%(m1,m2)

There are 2 strings that need to be filled. The first string is that random value m1 and the second string will be the random m2 value.

Creating random test/quiz problems save you time in creating tests, provide you with a solution, and eliminate potential mistakes. Have a student who missed your test? Create a different version quickly.

Here are some current events that caught my eye.

  • As you probably know, Asia is the land of fakes. Whether it's fake Rolex watches, fake DVD's, fake designer bags, or fake Ferraris, appearances can be deceptive. You need to be alert to fake doctors, fake teachers (with fake diplomas) and fake monks. It should be no surprise that cheating is rampant in Asia; it's so "advanced" there you might call it an art form. A great example of this is the cheating scandal a couple of years ago. Lots of students tried cheating, and some teachers caught them. That led to a firestorm, "By late afternoon, the invigilators were trapped in a set of school offices, as groups of students pelted the windows with rocks. Outside, an angry mob of more than 2,000 people had gathered to vent its rage, smashing cars and chanting: "We want fairness. There is no fairness if you do not let us cheat."". So it should be no surprise to hear about the latest cheating in China. First up is the cheating on SATs in Asia. From the article: "Bob Schaeffer, public education director of the nonprofit National Center for Fair & Open Testing, known as FairTest, said that his organization had received several e-mails from sources in Asia alleging that the SAT given on Nov. 8 was circulating among students before it was administered. One message included a screen shot of what appeared to be an entire SAT exam in Chinese.". Technically, this cheating allegation hasn't been confirmed but anyone with experience in Asia knows it has to be true. In fact, the article mentions, "Many local educators believe that the test-makers did not aggressively pursue cheating claims to protect the reputation of their flagship product, the SAT.", so I suspect this will get swept under the rug. You can get more details from an earlier story.
  • The Daily Mail highlights some of China's attempts to crack down on cheating in high school. From the article, "With thousands of Chinese students resorting to 007-style gadgets such as pinhole cameras and radio transmitter bras to cheat in their exams, one college decided to take a stand....

    Security staff in Jinlin, Jiangsu and Guangdong provinces revealed that students started using sophisticated radio vests in order to receive help from someone outside the hall.

    Pupils were also taking pictures of the tests using a button-hole camera hidden in a pen or watch, then using a copper antenna loop stitched into their clothing to beam it out of the hall to someone sitting with a receiver".

  • 2440 students were caught cheating in China on a pharmacy exam. Here's a video of news coverage.
  • ZeroHedge had a piece that illustrates how high school quality has dropped: the article says, "The number of college students taking at least one remedial course rose to 2.7 million in the 2011-2012 academic year from 1.04 million in 1999-2000, federal data show. During the same span, the amount of federal grants spent by undergraduates enrolled in at least one remedial course rose 380%, after inflation, Education Department figures show. There was also a drastic rise in remedial students taking on student debt."
  • RT reports that a racist high school administrator tweet led to a student walk out.
  • LA Times tells us about 6 students getting arrested after fights break out. The school had to go into lockdown. Education is not what it used to be.

SageTex: Tables with a random number of columns/rows

ProbDiceThe sagetex package documentation has, on page 9, a passage on one of the most useful applicaations of sagetex: making it write your code for you. The documentation gives an example of creating a table. At this site, I've already used it to create a trig table and a log table. Today I've added another problem to the SageTeX: Combinatorics/Probability page that creates a table that has a random number of columns/rows; you can download the tex file and play with it yourself in Sagemath Cloud. The problem type has the form: Imagine you have two 7-sided dice in which the sides of each die are equally likely to occur. Create a chart to show all possible outcomes and use it to find the probability that the sum is prime. You can see a screenshot above showing the code and output. The value of 7 is random (I allow it to be between 4 and 7 so that creating the chart isn't too easy or too difficult) and the goal, in this cas "the sum is prime", is random as well. The solution then will involve creating a table of random size.

Tinkering with the rows is trivial: just print more lines. Adjusting the columns is a bit more complicated: it uses the idea that, in Python, 'my string'*5 will print out 'my string' 5 times. The table is created in the sagesilent environment and the random number of columns is set by

output += r"\begin{tabular}{c|"
output += 'c'*n
output += r"}"

where string 'c' is repeated n times (n has already been defined as a random integer between 4 and 7). That simple construction is all you need. But sagetex also helps us construct the table entries and compute the answer we seek thereby eliminating mistakes. The row construction is here:

for i in range(1,n+1):
output += r"%s &"%(i)
for j in range(1,n+1):
output += r"%s "%(i+j)
if j < n:
output += r"& "
output += r"\\"

and the part worthy of comment is that the IF statement is there because, as long as we aren't at the last column we need to add an ampersand (&) otherwise, we're at the end of the line, so start a new line. Finally, there are 3 different events to calculate. The code is set up so you can easily add your own cases. Getting used to producing LaTeX code as a Python string takes a little time but it's well worth it. How long would it take you to create the trig table or log table that I've posted without using sagetex?

Here are some issues that caught my eye:

  • Have you ever had the annoying "When will I ever use this?" question come up in your class? Douglas Corey of Brigham Young University has some answers.
  • An annoying article, "Why Homework Is Bad for Kids". This sorting of thinking infects the public school system and is one reason for poor student performance in mathematics. You simply can't get the repetition needed to build mathematical skills during the school day and homework is the test of whether a student has mastered what was covered in class (when nobody is around to help them). The author writes, "We like to think all of this makes sense: It is well tested and, besides, it is what everyone is doing worldwide. No wonder we lose our markets to Japanese, Chinese, and Korean kids. Their schools are more strict and they study harder.Yet every element of this familiar equation is questionable.". It DOES make sense and of course, the author avoids coming up with another reason for why these other nations do better. The author points out that "...even in countries as workaholic as Japan, the number of hours kids are forced to study is becoming an issue of concern.". Note how lame this argument is, without more facts. IF a US student spends 20 minutes on homework and IF a Japanese student spends 4 hours on homework then arguing that Japan's push for less homework justifies our having 20 minutes (instead of 1 hour) doesn't make sense. But of course, the author doesn't give you the important information to put the issue into context.
  • It's not math related but "I F@$#ing love science" has a nice video on "10 Lies You Were Probably Taught in School". This is a good site for any science teachers out there. WARNING: DO NOT open their Facebook page or Twitter feed at school. Some users have inappropriate avatars.


Inquiry Based Learning

Inquiry Based Learning (IBL) is a teaching method "that engages students in sense-making activities.  Students are given tasks requiring them to solve problems, conjecture, experiment, explore, create, and communicate... all those wonderful skills and habits of mind that Mathematicians engage in regularly.". The website I linked to has lots of information on running a class using IBL. While I don't think it's practical to run a standard classroom that way because the curriculum couldn't be covered, I do think it's an important part of teaching. With 1100+ pages of material that needs to be covered for my accelerated precalculus class, finding time for IBL is not always so easy. Most of the time I have to resort to bonus problems in order give an IBL type problem. But finding these more nuanced problems isn't always easy. In an earlier post, I gave a link to the problems that Phillips Exeter Academy posts on their website. The IBL site I linked to above has lots of links to helpful resources. The goldmine, for me is Art of Mathematics website which has 11 free PDF books that you are free to download. The books have titles: Art & Sculpture, Calculus, Dance, Games & Puzzles, Geometry, Knot Theory, Music, Number Theory, Patterns, The Infinite, Truth, Reasoning, Certainty, & Proof. There's something for everybody. And the materials are well thought out. If you look around the site, there's plenty of useful information to get you started on the road to IBL. One of the links is to a site for IBL Calculus.

I've added Exeter's problems and the Art of Mathematics books to the mathematical links on the sidebar.

Here are some things that caught my eye:

Odds and Ends: Nov 2, 2014

Limits11I've added a new problem to the Sagetex: Limits page. The screen shot above shows the general form of the question: Evaluate the limit: \displaystyle \lim_{x \to 1}\frac{x^{7}-1}{x^{3}-1}.

The Problems page has also had a trig problem added to it: Prove \frac{\pi}{4}=4\arctan\left(\frac{1}{5}\right)-\arctan\left(\frac{1}{239}\right). This problem is intended for the best of an accelerated class. I would expect to use it in a weekly (optional) problem competition.

Here are some current events that caught my eye:

  • The Daily Signal has "10 Reasons Why Common Core  Should Spook You This Season"
  • It doesn't matter what metric you use to judge a teacher; the new metric will result in some teachers doing worse, some staying the same, and some improving. And in the US that means lawsuit. The Washington Post has an article on a 4th grade teacher in NY who has been penalized by recent changes. It seems like spooky reason number 10 from the Daily Signal: The one size fits all, top down approach has some experts designing a model that will quantify teacher effectiveness. The top down approach means that there is an industry of "experts" that live off of providing a plan or model to "solve" a problem which is then "implemented" on everybody, resulting in all the deficiencies being brought to light which leads to a backlash and the push for a "better" solution. Poltifact has an article which, thankfully, shows US test results versus the world; In math we've gone from 18th (out of 28) against industrialized countries (2000 data) to 27th (out of 34) for 2012 data. A decade of time shows the top down government model has done poorly but don't expect accountability for being terrible at what you do in government. How much money was wasted to get that level of performance?

Sage Interact: Chain Rule

ChainRuleI've added Sage Interact code for generating problems with derivatives, and the user can decide whether the problems require the Chain Rule or not--the screenshot above shows it running on this website. The code, which was designed last year, was created because I needed more problems (with a higher degree of difficulty). At the time, I had students who wanted more practice problems (because they wanted to be able to practice working with more difficult problems) so I ended up giving out the very rough code. I've since cleaned up the code to make the difficulty level more uniform.

The code can be found on the Python/Sage page but since it was designed for the classroom and found some use with my students, it is also on the Sage in the Classroom page.

The basic structure of the code is that the first 6 problems don't involve the Chain Rule, but problems 7-12 require the Chain Rule. Therefore, if the user requests Chain Rule problems then, because the Chain Rule problems are lumped together, a random number from 7 to 12 is repeatedly generated. So if you want to add your own types of problems to the code, make sure that you are grouping Chain Rule problems together.

A more subtle issue to be aware of is when you see code like this:

while i == j and j== 0:
j = Integer(randint(0,len(TheFunctions)-1))

The code is throwing out the possibility of nesting the same exact functions (eg \sin(\sin(x)) but the j==0 code is more subtle. It throws out the possibility of having e^x in the denominator because, for example, if the user has chosen to create problems that don't require the Chain Rule the code might create a quotient problem where e^x is in the denominator but then Sage converts it to a product involving e^{-x} which requires the Chain Rule.

I've two lines of comment to my code because I've had some inquiries about using some of the resources from this site. With respect to the SageTex problems on my website, the problems are generic in nature so I don't think that I or anyone has the rights to it. For example, the Limits8 problem is the sort of problem you would expect to see in any Calculus textbook. I've just randomized it using Python so I can create randomized tests with answer keys. That saves time and eliminates mistakes.

With respect to Python code that I've created, it should be viewed as Copyleft:

Essentially any non commercial use for educational purposes only is okay.

This website contains material I develop for use in my classes, and I hope it can help other teachers out. It would be better still if others can contribute copyleft code, such as SageTex problems, so that the database of problems gets bigger even faster. But using code developed here to sell as your own would not be advisable.

Here are some other issues that have caught my attention since last time:

  • has an interesting piece on textbooks that are never obsolete. It asks the question, "What if a school districts...owned all the copyrights of all the textbooks they used and had their teachers, who were so inclined, write chapters for these textbooks." . And a little further down, "Furthermore, the whole nature of textbooks and supporting materials could easily be changed with access to the Internet where these textbooks could constantly be edited and updated in material with new writing and online links as time goes by and the reality of the subject changes. Wouldn't this obviate the necessity of ever having to scrap textbooks in what remains an unnecessary and expensive process every 7 years that clearly only benefits the interests and profits of textbook publishers?". I like the basic idea but I don't like quite a few of the specifics of implementation.
  • has an article on a teacher who had their license suspended for making comments about a student's name on Facebook. The article says, ""The student's name contained a curse word and Nichols allegedly posted 'I want to ask the parents if I can change it' and 'I still can't get over the student's name!'" it said. "In response to others' comments about the name, Nichols allegedly wrote "How do you think I feel when I have to address him???? I literally can't stop laughing! I have to go all year with this’---!!!'"". Some people have WAY too much free time on their hands. With the potential for some serious penalties, cue the violins, as the teacher in question, "...told the board she was under significant stress at the time due to a recent divorce and struggling with diabetes.The board agreed not to revoke Nichols' teaching certificates permanently, instead ordering a one-year suspension of them because she had "fully accepted responsibility for her actions.""She has also undertaken counseling to deal with her level of stress and many responsibilities,"".
  • has a disturbing article: Imagine a student who, "had reportedly been bullied for years at school, hounded with homophobic slurs and constant harassment.". He snapped one day, threw the first punch, and got beaten up badly enough to be in the hospital for 7 weeks. The others involved had no injuries. But what makes this story enter the bizarre is that, " officials and local police delivered another blow to Martin by charging him with two counts of assault and refusing to allow him back into the school until he signs a written statement saying he threatened the school (which he denies).". Check out the local TV video coverage.


Sage Interact: the Birthday Problem

BirthdayProbThe Birthday Problem asks the question:  In a group of n people, what's the probability that at least 2 will have the same birthday?

Answering the Birthday Problem involves creating a mathematical model. The model rests on two assumptions that aren't true and should be discussed with the class:

  • there are 365 days in a year (Feb 29th is ignored to simplify the model)
  • birthdays are equally likely to be on any given day (Also false. This varies from country to country; in the US birthdays are more towards the middle of the year. Count back 9 months and you've got cold weather. Nothing random there.)

Under those assumptions the sample space is 365^n, since there are 365 choices for each birthday. Counting the number of ways that nobody has the same birthday is just (365)(364)....(365-n+1), giving us the probability of at least 2 people with the same birthday as the complementary probability: 1-[(365)(364)....(365-n+1)]/(365)^n$.

This simple model yields surprising answers: with a group of only 50 people the probability of at least 2 people with the same birthday is 0.97; this illustrates how counter-intuitive probability can be. So is the model any good? It turns out that although the model is built on incorrect assumptions, experimental evidence validates gives results that are close to the model. That's a basic fact about models; they're based on assumptions that in many cases aren't true. Ultimately, experimental evidence is needed to determine whether the model is accurate. Try the Birthday Problem with each of your classes and find out how well it works with 1 class, with any 2 classes, any 3 classes, and so on.

I've created code for computing the Birthday Problem given n people and plots the probabilities on a graph. You can see the output above; the code is on the Python/Sage page.

Some stories that caught my eye recently:

  1. Education Next has articles on "Rethinking the High School Diploma". Three articles consider the idea of having 2 diplomas: 1 for graduating and the second higher diploma for excellence/mastery. It seems symptomatic of today's culture. You can't enforce standards so everybody needs to graduate and the diploma lacks value. So create a second diploma which will show the employer the student has mastered the basics. An interesting idea.
  2. Businessweek has an article suggesting that the US should station soldiers in schools, similar to air marshalls on a plane. The Call of Duty author has, "...anticipated objections. “The public won’t like it, they’ll think it’s a police state,” he said. But, he went on, “All of these are solvable problems.” Anthony’s address, which was punctuated by videos depicting such future threats as a U.S. drone hacked by Iran and a hotel massacre in Las Vegas, included repeated exhortations to policymakers to learn from the examples of corporations and creative artists in selling potentially unpopular ideas. “When we have a new product that has elements that we’re not sure how people will respond to, what do we do as a corporation?” he asked. “We market it, and we market it as much as we can—so that whether people like it or not, we do all the things we can to essentially brainwash people into liking it before it actually comes out.”". Incredible.....
  3. Huffington Post reports on teachers behaving badly: "Louisiana Teachers Planned Illicit Group Sex With Student: Police". The article states, "Police now say that one of the Louisiana high school teachers accused of having group sex with another teacher and a 16-year-old student had previous sexual encounters with the minor.". There's a video from Huffington Post.

Sagetex: derivative as a limit

LimDQI've added another problem to the Sagetex: Limits page. Find the derivative of quadratic function using the limit of a difference quotient. The screenshot is above.

Several stories caught my eye recently:

  1. William Stein, the driving force behind Sage, reports on a, "major 3d update. Print worksheets with embedded 3d graphics. Pan with alt/command. Plots persist between refreshes.". More details can be found here.
  2. The Washington Post has a piece about an "award winning" principal who used to support Common Core and is now opposed to it. She writes about the "Four Common Core 'Flim-Flams'".
  3. Common Dreams reports: "Hundreds of students from high schools across Colorado's Jefferson County school district walked out of classes on Monday, Tuesday, and Wednesday this week, protesting attempts by rightwing members of the school board to amp up what they consider the "positive aspects of the United States and its heritage" within the district's history curriculum while minimizing focus on more progressive aspects of history such as people's movements, the history of struggle, and "social strife."". The article says, "that plan would look at Advanced Placement history courses to make sure materials "promote citizenship, patriotism, essentials and benefits of the free-market system, respect for authority and respect for individual rights" and don't "encourage or condone civil disorder, social strife or disregard of the law."" A passage from a piece on the Breitbart website gives a student opining, "...the nation's foundation was built on civil protest, "and everything that we've done is what allowed us to be at this point today. And if you take that from us, you take away everything that America was built off of."".
  4. This hasn't gotten much publicity: reports, "A secret program to monitor students' online activities began quietly in Huntsville schools, following a phone call from the NSA, school officials say.". According to the school officials they were alerted to a student making threats on Facebook. "The NSA, a U.S. agency responsible for foreign intelligence, this week said it has no record of a call to Huntsville and does not make calls to school systems.". So now Huntsville City Schools are looking at social media sites for gangs, guns, and threats of violence. One school official says, ""There was a foreign connection," said Wardynski, explaining why the NSA would contact Huntsville schools. He said the student in Huntsville had made the online threats while chatting online with a group that included an individual in Yemen.". But it's not just Huntsville. The article continues, "A company called Geo Listening watches social media for school districts including Glendale, Calif. Their web site reads: "Geo Listening's unique monitoring service will process, analyze and report the adverse social media from publicly available student posts... We align our reporting criteria with existing school district procedures and board policy as they relate to student conduct & safety."".

Sagetex: Dartboards and tree diagrams

CombDartsI've added another problem to the Sagetex: Combinatorics/Probability page: "Three darts are thrown at the dartboard. A score is given for each region where the dart lands and the total score is just the sum of the $3$ dart scores. Assume all three darts hit the dartboard. How many different total scores are there? Enumerate them with by drawing a tree diagram."

It's a problem that's illustrates how a tree diagram can be used to organize the solution in a way that anyone can easily check the answer. Typesetting the tree diagram made this a a time consuming problem to create. But the work is done now and the code can be downloaded for you convenience.

Here are some stories that caught my eye recently:

  • Ben Swann alerts us to a "zero tolerance" policy to the extreme.  In Teen Suspended After School Claims Notebook is "Drug Possession" we learn "...a teenager was punished with a lengthy suspension after teachers discovered her folder which contained stories with references to marijuana use." . Her suspension of 10 days was for "...“possession of a controlled substance” despite no drug testing and no drugs in Krystal’s possession". Her written account is considered  possession, apparently, "...although the district’s drug policy posted online provides no specific definition of paraphernalia".
  • CBS San Francisco reports on how outrageous high school behaviour is having an impact: "A Taco Bell restaurant in Antioch has started closing its dining room in the afternoons after managers say it has become a magnet for high school students after class, and fights have been breaking out.“At school you get suspended or something for that, and if you’re not at school you go to the plaza and fight and get away with it,” one student said.". That even includes death threats. Check out the video.