March 14, 2010Python pi.py SpigotHere is pi.py (not to be confused with pypy), a short python implementation of Jeremy Gibbons's 2005 spigot generator for decimal digits of pi:
def pi_decimal_digits():
q, r, t, j = 1, 180, 60, 2
while True:
u, y = 3*(3*j+1)*(3*j+2), (q*(27*j-12)+5*r)//(5*t)
yield y
q, r, t, j = 10*q*j*(2*j-1), 10*u*(q*(5*j-2)+r-y*t), t*u, j+1
The code to drive the algorithm is longer than the algorithm:
count, digits = 0, pi_decimal_digits()
while 1:
print '%6d: %s' % (
count, ''.join([str(digits.next()) for j in xrange(50)]))
count += 50
This little script can be quite handy if, for example, you want to look up where in the digits of pi you can find the phone number for the Mass Audubon Society that is down the road from my house: > ./pi.py | grep --color 2599661 3050: 56638937787083039069792077346722182562599661501421 Conveniently, their phone number starts at the very visible 3087th digit of pi after the decimal point. My home phone number is a little bit further into the private section the pi phone book, at the 6,301,261th digit. And, if you must, you can reach me at my cell at the 22,000,091th digit, although I should warn you that my reception is not very good out here in the boonies. Happy pi day. Posted by David at 08:35 AM
| Comments (1)
The Mystery of 355/113Today's date is a good excuse to memorize a few more digits of 3.1415926 And yet decimal approximations to pi are an artifact of our ten-fingered anatomy. Fractional approximations to pi are more satisfying, and they promise to teach us something more universal about pi.
We all know that 22/7 is a very good approximation to pi. But this well-known fraction is is actually 1/791 larger than a slightly less-well-known but much more mysterious rational approximation for pi:
Remembering 355/113
The fraction 355/113 is incredibly close to pi, within a third of a millionth of the exact value. This level of accuracy is far beyond its rights as a fraction with such a small denominator, and it causes various oddities elsewhere in math. For example, use any scientific calculator to compute cos(355) in radians. The oddball result is due to the freakish closeness of 355/113 to pi.
A cute mnemonic makes it easy for our base-10 species to remember this useful fraction. Write down the first three odd numbers twice: 1 1 3 3 5 5. Then divide the decimal number represented by the last 3 digits by the decimal number given by the first three digits.
The mystery is: why is this fraction so close to pi? The deeper you look, the more unique and unexplained 355/113 appears to be. March 11, 2010It's Not About The AnswerYesterday my son came across this beautiful problem set from a packet about combinatorics by Lexington teacher Vaag Mosca. Try it. When working the set, you will realize very quickly that all the answers are the same. You could easily "finish" the problems by copying the same answer in each slot. But that would be totally unsatisfying. When Anthony worked the problems and got some different answers, he was puzzled. "I know I got it wrong. What am I missing?" I have never seen Anthony work so hard to double-check his work. Even better, after he got the right answer several times, he felt compelled to understand why it was the same. "I got it, and I see how it is related to seven, but where is the three?" He was really taking a new approach to math. What you learn from this little problem set goes way beyond combinatorics: The lesson is that math is not about the answer. Posted by David at 07:23 AM
| Comments (0)
March 08, 2010Solid GeometryThree dimensional solid geometry has nearly been written out of the American mathematical curriculum. Yet my middle-school math team is approaching the last and most difficult math meet of the year where, among other things, they are expected to know basic solid geometry. So for the 3d-unaware student I have put together a super-compressed introduction to the basics of middle-school solid geometry, with a high level of challenge for intended for math team middle schoolers who are trying to learn everything they need to know in a week. The packet here has only 4 pages and 27 problems, with an extra 6 pages for solutions to check after you are done. The easy bits are skipped, and in exchange you get to see some common types of tricks as well as a hint of insight beyond basic prisms, pyramids, cones and spheres. Here it is: Solid Geometry Facts and 33 Problems and solutions. Posted by David at 01:10 AM
| Comments (0)
March 04, 2010Teaching is HardI coach a middle-school math team of 5th-8th graders, and I have learned that teaching is hard. My kids are all good kids, but after a long day at school, the girls want to chit chat and the boys want to wrestle. When it comes to learning hard math, the whizzes like to dominate the discussion, and the kids who are getting lost would prefer to literally hide under their desk. Sometimes math team practices are disastrous, and I just want to let all my wild gazelles outside to play in the sun. And yet other times the classroom is exciting and magical and packed with learning, with the kids buzzing about primes or permutations by the end of the hour. It's not just the people in the room: we are the same every week. But every week is different. What is happening? Continue reading "Teaching is Hard"Posted by David at 09:53 AM
| Comments (0)
February 12, 2010A Mathematical Notation QuestionQuickly simplify the following
expression: Solution:
Real solution: The real question is, how the heck do you write all that notation in HTML? This problem is the bane of math teachers everywhere. But I did it here in about 5 minutes using a wonderful new tool that was released yesterday. Here is how. The solution is to use mimeTeX notation via the brand-new version of the Google Chart Server. You can use the mathematical notation editor I have posted here - it will interpolate formulas within $dollar signs$ into HTML, generate the right <img> tags, and help insert css styles based on the image heights to get your vertical-alignment approximately right. It helps if you know TeX syntax ahead of time, but even if you don't, it's not hard to learn what you need. When you go to davidbau.com/formula, it starts you off with a simple example. Copy and paste your HTML. QED.
Posted by David at 02:36 PM
| Comments (2)
February 09, 2010Second Coming of Wyden-Bennett?Republicans, preparing for Obama's Healthcare Summit, clearly want to avoid looking as foolish as they did when hosting Obama at their House issues summit. "Start over," seems to be the new mantra. GOP proposals for preconditions before talks just make them look like ridiculous Iranian nuclear negotiators; if Republicans continue on this path, they are playing into Democratic strategies and providing political cover for Democrats to pass healthcare by reconciliation next month. Democrats look serious, and Republicans look like Ahmadinejad. Any good hawk knows that in that situation, stiff and swift sanctions are justified. Continue reading "Second Coming of Wyden-Bennett?"Posted by David at 06:56 AM
| Comments (1)
February 01, 2010Reading JQuery SourcesJQuery has become the stdlib of Javascript. After reading the jQuery docs, the next level of understanding comes from reading the code. Here is an excellent new tool for reading the jQuery source, thanks to James Padolsey. Food for Thought: International jQuery Use On going back and looking at the top regions in which 'jquery' is a topic of Google searches, I find it interesting - and maybe worrying for U.S. internet innovators - that none of the top 6 jQuery cities of the world are in the U.S... Continue reading "Reading JQuery Sources"Posted by David at 07:23 AM
| Comments (0)
January 30, 2010Random Seeds, Coded Hints, and QuintillionsHere is a seedable random number generator in Javascript that you can set up to produce a determinstic sequence of pseudorandom numbers. Browsers do not provide a built-in way to seed Math.random(), so this solution is handy both when you need a repeatable pseudorandom sequence that is completely predictable, and when you need a robust seed that is much more unpredictable than your browser's built-in random number generator. Many games that use weak random number generators have been cracked by exploiting their lack of randomness, and recently it has even been shown that it is possible to guess your 'random' Social Security Number given information about the time and location of your birth. To resist this type of attack, you want do better than a linear congruential PRNG seeded with the current time. Explanations below. A Math.seedrandom Function
Math.seedrandom('any string you like');
Next time you call Math.random(), you will get a deterministic sequence of results that can be reproduced at any time on any browser by calling seedrandom with the same string (with the example seed above, you will always get 0.4514661562021821, 0.06749172707294095, 0.8393296727715214, etc). The code uses RC4 as the pseudorandom number generator, so the randomness is a bit better than what you get from most browsers' built-in Math.random. But since it does all the computation in javascript, it is also is 3-10x slower. A minified version of seedrandom.js (using the Google Closure Compiler) is about 1K. The code also supports automatic seeding... Continue reading "Random Seeds, Coded Hints, and Quintillions"Posted by David at 08:06 PM
| Comments (2)
January 24, 2010Xinhua: We Report, You DecideDoes reading the Chinese press remind you of watching Fox News? There is a whole world outside China and outside Fox News that is starkly different and a bit closer to reality. But when you realize that Fox is actually the most trusted news brand in the U.S. today, you can get an appreciation for the success that a censored Chinese media can have inside the world's largest society. The effects of squashing dissent in the name of nationalism are not "very limited"... Posted by David at 09:49 AM
| Comments (1)
January 19, 2010My God, What Have We Done?Fellow Massachusetts voters! What was the point in electing Brown? Continue reading "My God, What Have We Done?"Posted by David at 09:57 PM
| Comments (3)
January 18, 2010Campaign CallsWe've gotten three calls from the Scott Brown campaign in the last 24 hours, two of them late at night. The GOP smells blood in the water. But everybody around here is a Democrat! Posted by David at 12:10 PM
| Comments (1)
|
||||||||||||||||||||||||||||||||||||||||||
|
Calendar
Hacks
Search
Archives
All Articles
March 2010 February 2010 January 2010 November 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 January 2004 December 2003 November 2003
Recent Entries
Python pi.py Spigot
The Mystery of 355/113 It's Not About The Answer Solid Geometry Teaching is Hard A Mathematical Notation Question Second Coming of Wyden-Bennett? Reading JQuery Sources Random Seeds, Coded Hints, and Quintillions Xinhua: We Report, You Decide My God, What Have We Done? Campaign Calls Vote Ballmer Favors Torture for Lawyers Anagram Flawed Security Google and China Pointless Arbitrage Mandelbrot Bravo for Courier What's in the Box Coin Flips Are Biased Javascript Reversi Time To Build A Treehouse Free Market Healthcare Niagara Restaurants Law vs Power Weiner Goes to Washington Where I Learned Programming Disorderly Conduct Dear Losers McCain/Lieberman Easy Math Typesetting The Small Government Paradox The 3.6% Accident What is a Floppy Disk? Two Steps Behind Politics is Important Your Compiler Vanishes in A Puff of Logic Elastic Shortfalls Poetry and Prose Death and Taxes Geithner's China Triumph COP and the IMF Playbook How To Nationalize A Cultural Problem Obama to the World: Join Us What is a Stress Test? How Big Is It? Helicopters Arrive Under Cover Of AIG Testimony Clever Outrage Processing Congressional Team Building The Bossy R Bulls Enter China Shop American Majesty No Deceit Here Winning at Chess Transition in Cyberspace Elizabeth Warren Continued Fractions Rationals are Nonobvious Yellowstone Swarm RMB in the NYT In Spending We Trust Foreign Affairs on China Junichiro Obama Helicopters Take Off Amazing Transparency A Reflective Phobia Trade Deficit Arithmetic Perfect Numbers Taxman Game Mapping Out a Trade War Currency Disaster The Chinese Depression Sudoku Help Second Grade Spelling Waiting For Doc Twenty Eight Hours What Do You Call It? Rahm Emanuel A Fourth Republic Helicopters and Imports An Historic Day Chomp The 144 Game Klein on Obama I Blame Markowitz Time for Japan to Buy Republican Rebels Pictoral Subtraction McCain and Obama at Al Smith What After November 4? Where Is The Excess Capital? Quick, Get a Mortgage World's Toughest Job What's Scaring People The U.S. Needs a King Dear Nancy Pelosi
Links
Bau family website
Joe
Gary
Eric
Gayle
Reza
Rod
Ulysses
Blossom
Howie
Nelson
Glenn
463
Pop
Wag
Physics
Nature
MG
LegoEd
Anita
Bernie
PCal
Cedric
Adam
Mark
Scott
Ted
StPeter
Joel
XMLBeans
Quick Search Bar
Battelle
Bricklin
Digg
Jake
Gilmour
Googlers
HotLinks
Mini
Raymond
RB
RMack
Sam
TM
Volkh
Wonkette
Waxy
Witt
Xooglers
Zawodny
EconView
UChicagoLaw
Older Writing
About
|
||||||||||||||||||||||||||||||||||||||||||
| Copyright 2010 © David Bau. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||