So I know that I have sang the praises of Scheme in several posts now, but let me get to some of the downsides:
First of all, it's insane. No control structures. No local variables. THE MADNESS!!!
But more importantly for me, because it uses exact numbers (ie fractions), the numbers can quickly become to large for the interpreter to handle within reasonable amounts of time. In many cases having exact numbers is ideal for math, but when your using mathematical estimates based on numerical analysis that is iterated many, many times, well, things get ugly.
So I'm putting out this question: Does anyone know of a way to turn off exact numbers in Scheme. I realize that you can just use the function (inexact->exact num), but that only turns it off for one instance, what I'm looking for is a more general purpose off switch.
Because of this difficulty, for some of the more advanced numerical methods I'm handling I'm switching to OpenOffice Spreadsheet. It's not a perfect system, but if properly used the spreadsheet can be a mighty powerful tool of data manipulation.
And I shall also see if I can design functions that get around the inexact/exact difficulty even if it is with the inexact->exact function, because I dream, I dream of the day when once more I can Scheme.
Sunday, February 24, 2008
Sunday, February 17, 2008
MC Esher be mathin' out
It's hard exactly to say how MC Escher relates to math. Now certainly MC Escher studied math, and certainly he was inspired by math. But what do the weirdness of his drawings have to do with math?
Well, by all means, the weirdness of his drawings were a matter of creative impulse, but there is a mathematical essence to them. The regularity of his pattern manipulation, the way he defies and distorts perspective, the angles of light bouncing and readjusting. There be math in those hills.
And with that in mind, I direct you The MC Esher Official Website with all sorts of good MC Escher stuff:
http://www.mcescher.com
Go there now... Mathimoto commands it!
Well, by all means, the weirdness of his drawings were a matter of creative impulse, but there is a mathematical essence to them. The regularity of his pattern manipulation, the way he defies and distorts perspective, the angles of light bouncing and readjusting. There be math in those hills.
And with that in mind, I direct you The MC Esher Official Website with all sorts of good MC Escher stuff:
http://www.mcescher.com
Go there now... Mathimoto commands it!
Thursday, February 14, 2008
Happy St. Valentine's Day
Ah, St.Valentine's Day, a day of love, a day of romance, a day of... MATH!!!
Since I have spent much energy elsewhere, I cannot explain the full dimensions of St.Valentine's Day mathematical importance, but I can share with you a Valentine's Day treat.
Want to make your sweetie's heart swoon, give here the formula for Cardioids, vaguely heart shaped graphs using polar coordinates!
(just to refresh you, polar coordinates use distance from the origin (the center of the graph) as r, combined with an angle Θ (it's hard to represent it on a computer, but its basically an O with a line in the middle, or sometimes just a cursive-ish O) to form a location for a point)
or if you're feeling more sine-y
(formulas courtesy of Paul's Online Calc. II Notes, which is itself courtesy of and property of Professor Paul Dawkins of Lamar University)
But if you've messed up former Valentine's Day gifts, perhaps you need something a little bit more spectacular, well then I direct you to this fantastic site:
All About Heart Curves! (not it's actual name)
From the mind of Professor Jürgen Köller.
Well, I think that's a heart healthy start to Valentine's Day. But you can't slack off, after all, you still need to give Valentines to people. Just don't forget to give a Valentine to one very special girl, Math!!!
Since I have spent much energy elsewhere, I cannot explain the full dimensions of St.Valentine's Day mathematical importance, but I can share with you a Valentine's Day treat.
Want to make your sweetie's heart swoon, give here the formula for Cardioids, vaguely heart shaped graphs using polar coordinates!
(just to refresh you, polar coordinates use distance from the origin (the center of the graph) as r, combined with an angle Θ (it's hard to represent it on a computer, but its basically an O with a line in the middle, or sometimes just a cursive-ish O) to form a location for a point)
or if you're feeling more sine-y
(formulas courtesy of Paul's Online Calc. II Notes, which is itself courtesy of and property of Professor Paul Dawkins of Lamar University)
But if you've messed up former Valentine's Day gifts, perhaps you need something a little bit more spectacular, well then I direct you to this fantastic site:
All About Heart Curves! (not it's actual name)
From the mind of Professor Jürgen Köller.
Well, I think that's a heart healthy start to Valentine's Day. But you can't slack off, after all, you still need to give Valentines to people. Just don't forget to give a Valentine to one very special girl, Math!!!
Labels:
Fun,
Graphs,
Math,
Polar Coordinates,
Valentine's Day
Wednesday, February 13, 2008
Time keeps on Schemin'
So one thing I'm a little bit worried about with this blog is the temptation to turn it into a semi-computer science blog. I want to keep things well rooted in math here, because math is awesome. I mean computer science is cool and all, but math is awesome, and also I think there are more computer science blogs out there than math blogs.
Still, I'm dealing with a lot of numerical analysis stuff now, the line between math and computer science is a little bit blurry. Still, because this blog is mine, I'll walk that line.
And so in the interest of math, I will now reveal to you some really cool Scheme code (just to refresh your memories, I'm using Dr. Scheme, a free Scheme interpreter, and I've been consulting The Scheme Programming Language by R. Kent Dybvig for reference) I wrote to deal with numerical analysis problems. Many people have said that Scheme should not be used for numerical analysis hw, and they are right, but that's why it's ultra-cool when you get it right.
So here's some functions:
General method applier for numerical methods requiring iteration (for generating a list of the value at several different iterations, largely for hw purposes but also so you can look at how it is converging).
(define (applymthd method fun initx tol)
(
map (lambda (iter) (method fun initx tol iter)) '(1 5 10 20 50 100 1000)
)
)
So this obviously is a pretty rough function, but I can tweak it into shape and if I do, I'll pass it along.
Here's a cheeky little function for forward distance:
(define (fordist fun n)
(
(- (fun (+ n 1)) (fun n))
)
)
Here's a less cheeky function for Aiken's terms given a function:
(define (Aitkens fun n)
(- (fun n) (/ (expt (- (fun (+ n 1)) (fun n)) 2) (+ (fun (+ n 2)) (* -2 (fun (+ n 1))) (fun n))))
)
But moving on to more sizable methods, here's an implementation of Steffensen's method:
(define (Steffensens fun initx tol iter)
(if (< iter 1)
initx
(
if
(< (abs (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx))) tol)
(- initx (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx)))
(Steffensens fun
(- initx (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx)))
tol (- iter 1))
)
)
)
More stuff: An implementation of Fixed Point Iteration:
(define (fixedpnt fun initx tol iter)
(if (< iter 1)
initx
(if (< (abs (- (fun initx) initx)) tol)
(fun initx)
(fixedpnt fun (fun initx) tol (- iter 1))
)
)
)
So that's that for now. And I'd say that's a good chunk of stuff, so that's some Scheme, but really, it's all about how to deal with numerical analysis in a quick and painless fashion made slightly more insane by using Scheme instead of any number of more saner tools.
Still, I'm dealing with a lot of numerical analysis stuff now, the line between math and computer science is a little bit blurry. Still, because this blog is mine, I'll walk that line.
And so in the interest of math, I will now reveal to you some really cool Scheme code (just to refresh your memories, I'm using Dr. Scheme, a free Scheme interpreter, and I've been consulting The Scheme Programming Language by R. Kent Dybvig for reference) I wrote to deal with numerical analysis problems. Many people have said that Scheme should not be used for numerical analysis hw, and they are right, but that's why it's ultra-cool when you get it right.
So here's some functions:
General method applier for numerical methods requiring iteration (for generating a list of the value at several different iterations, largely for hw purposes but also so you can look at how it is converging).
(define (applymthd method fun initx tol)
(
map (lambda (iter) (method fun initx tol iter)) '(1 5 10 20 50 100 1000)
)
)
So this obviously is a pretty rough function, but I can tweak it into shape and if I do, I'll pass it along.
Here's a cheeky little function for forward distance:
(define (fordist fun n)
(
(- (fun (+ n 1)) (fun n))
)
)
Here's a less cheeky function for Aiken's terms given a function:
(define (Aitkens fun n)
(- (fun n) (/ (expt (- (fun (+ n 1)) (fun n)) 2) (+ (fun (+ n 2)) (* -2 (fun (+ n 1))) (fun n))))
)
But moving on to more sizable methods, here's an implementation of Steffensen's method:
(define (Steffensens fun initx tol iter)
(if (< iter 1)
initx
(
if
(< (abs (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx))) tol)
(- initx (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx)))
(Steffensens fun
(- initx (/ (expt (- (fun initx) initx) 2) (+ (fun (fun initx)) (* -2 (fun initx)) initx)))
tol (- iter 1))
)
)
)
More stuff: An implementation of Fixed Point Iteration:
(define (fixedpnt fun initx tol iter)
(if (< iter 1)
initx
(if (< (abs (- (fun initx) initx)) tol)
(fun initx)
(fixedpnt fun (fun initx) tol (- iter 1))
)
)
)
So that's that for now. And I'd say that's a good chunk of stuff, so that's some Scheme, but really, it's all about how to deal with numerical analysis in a quick and painless fashion made slightly more insane by using Scheme instead of any number of more saner tools.
Labels:
Computer Science,
Math,
methods,
Numerical Analysis,
Scheme
Friday, February 8, 2008
Why plan when you can scheme?
Let me make a pitch for programming in scheme for math purposes.
Why is Scheme good for programming numerical methods and other math brick and brack?
Because it is so gloriously insane!
Scheme is a language without local variables, without control structures, without global constants, it uses reverse-Polish notation (those crazy Poles!) run usually by an interpreter... basically to the layman, let me say that it makes no sense.
But the advantage to Scheme is it fits very well with the idea of constructing logical algorithms and basing your math around that. Scheme strips algorithms down to their basic components, the procedures, and doesn't allow you to go any further than that. There's a ruthlessness to this restriction and enough power in this limited space that you end up being able to do a lot of math stuff simply and in a manner which illuminates the heart of the algorithm.
But it remains insane.
That said here's a good Scheme implementation:
Dr. Scheme
And here's a good guide to the language (note the implementation and this guide are not related, so some aspects of the guide may not work with this implementation):
The Scheme Programming Language by Kent Dybvig
Now I don't want this math blog to go all computer sciency, but it must be admitted that comp. sci. has some math overlap, especially when it comes to doing programming to make math easier. So look out in the future for some bursts of code for math-based functions, most likely in Scheme.
Keep on Scheming!
Why is Scheme good for programming numerical methods and other math brick and brack?
Because it is so gloriously insane!
Scheme is a language without local variables, without control structures, without global constants, it uses reverse-Polish notation (those crazy Poles!) run usually by an interpreter... basically to the layman, let me say that it makes no sense.
But the advantage to Scheme is it fits very well with the idea of constructing logical algorithms and basing your math around that. Scheme strips algorithms down to their basic components, the procedures, and doesn't allow you to go any further than that. There's a ruthlessness to this restriction and enough power in this limited space that you end up being able to do a lot of math stuff simply and in a manner which illuminates the heart of the algorithm.
But it remains insane.
That said here's a good Scheme implementation:
Dr. Scheme
And here's a good guide to the language (note the implementation and this guide are not related, so some aspects of the guide may not work with this implementation):
The Scheme Programming Language by Kent Dybvig
Now I don't want this math blog to go all computer sciency, but it must be admitted that comp. sci. has some math overlap, especially when it comes to doing programming to make math easier. So look out in the future for some bursts of code for math-based functions, most likely in Scheme.
Keep on Scheming!
Thursday, January 31, 2008
Five Def. of Pi's
Ah Pi, that elusive impossible goal. It has driven many to madness (especially the guy in this movie), but many also to great feats.
And so unsurprisingly it has a special place in the hearts of many mathematicians. The 16th century German mathematician Ludoph van Ceulen even had his tombstone engraved with his 32 decimal place estimations of pi.
Ah, Pi!
Fiercely irrational, blissfully transcendent, and so essential to the universe and how it works...
But it's so tricky. Oh course, I know how to write Pi's true form, but instead of revealing that truth to you and thus blowing your minds, I'll just share with you some other def.s of pi, beyond just the ratio of the perimeter of a circle and its diameter (meter! meter!) (all better than the old stand-by 3.14).
1. Good old Archimedes came up with a rough estimate: π is between 223/71 and 22/7
He figured this by drawing a circle, drawing a polygram inside the circle, touching all the sides, and then drawing a polygram outside the circle where the circle touched all of its sides. Then he compared the two polygrams, and by making more and more sides... and this is how you get the rough estimate 22/7 which I used through much of elementary school.
2. Here's one an Indian did write up in the 15th century AD:
and so on... FOREVER!!!
Pretty damn awesome. INFINITE SERIES RULE!!!
Good work Madhava of Sangamagrama! It would take until the 17th century for the series to be rediscovered through the hearty work of James Gregory and Gottfried Leibniz.
3. And if you like your arctangents (and who doesn't?), how about this def. of pi:

Kudos John Machin!
And if you don't like your arctans, well,
and so on, still FOREVER!!!
At least according to a nice little Taylor expansion of arctangent.
4. Well, to take Pi to the next level, another Indian had to get into the game. And so in the early 19th century another Indian did (actually Indians had been working all along, but this 5 def.s not a total history). I'm talking about the one, the only Srinivāsa Rāmānujan!!!
Check out his method for finding Pi, derived from the highest halls of Number Theory:

While that method didn't hit the big time till 1985, in that year William Gosper used it to calculate Pi to 17 million digits. Dude, sweet.
5. But if you want to go a little ways by the abstract route. Well, remember that Euler with some Taylor formulization of e^(ix), sin x and cos x, came up with

which when x = pi leads to a nice little identity involving pi:

Ah, Euler, you may have lived in the 18th century and pronounced your name like a greaser, but you're still one of the best.
So in conclusion let me give you one more def. of pi:
Pi = Awesome
Exactly
And so unsurprisingly it has a special place in the hearts of many mathematicians. The 16th century German mathematician Ludoph van Ceulen even had his tombstone engraved with his 32 decimal place estimations of pi.
Ah, Pi!
Fiercely irrational, blissfully transcendent, and so essential to the universe and how it works...
But it's so tricky. Oh course, I know how to write Pi's true form, but instead of revealing that truth to you and thus blowing your minds, I'll just share with you some other def.s of pi, beyond just the ratio of the perimeter of a circle and its diameter (meter! meter!) (all better than the old stand-by 3.14).
1. Good old Archimedes came up with a rough estimate: π is between 223/71 and 22/7
He figured this by drawing a circle, drawing a polygram inside the circle, touching all the sides, and then drawing a polygram outside the circle where the circle touched all of its sides. Then he compared the two polygrams, and by making more and more sides... and this is how you get the rough estimate 22/7 which I used through much of elementary school.
2. Here's one an Indian did write up in the 15th century AD:
Pretty damn awesome. INFINITE SERIES RULE!!!
Good work Madhava of Sangamagrama! It would take until the 17th century for the series to be rediscovered through the hearty work of James Gregory and Gottfried Leibniz.
3. And if you like your arctangents (and who doesn't?), how about this def. of pi:
Kudos John Machin!
And if you don't like your arctans, well,
At least according to a nice little Taylor expansion of arctangent.
4. Well, to take Pi to the next level, another Indian had to get into the game. And so in the early 19th century another Indian did (actually Indians had been working all along, but this 5 def.s not a total history). I'm talking about the one, the only Srinivāsa Rāmānujan!!!
Check out his method for finding Pi, derived from the highest halls of Number Theory:
While that method didn't hit the big time till 1985, in that year William Gosper used it to calculate Pi to 17 million digits. Dude, sweet.
5. But if you want to go a little ways by the abstract route. Well, remember that Euler with some Taylor formulization of e^(ix), sin x and cos x, came up with
which when x = pi leads to a nice little identity involving pi:
Ah, Euler, you may have lived in the 18th century and pronounced your name like a greaser, but you're still one of the best.
So in conclusion let me give you one more def. of pi:
Pi = Awesome
Exactly
Tuesday, January 29, 2008
Archimedes Rules!!! Woo!!!
I'm not a Hellenophile, I have a good taste for the Classics mind you, but I'm not one of those who say the Greeks invented everything. With Math, for example, despite the immense Greek influence (often not done by actual Greeks but by Egyptians or Syrians who spoke Greek), but India, Arabia, and China also had a huge impact on the history of Math. And yet, there is one Greek, who's outstanding enough that I can never get tired of hearing about him.
ARCHIMEDES!!!
So we have a man who created ancient war machines that matched even the Romans for years. Yet despite the mountains of gold that earned him, the war machines were a distraction. His love was Math. Pure Math. And it was there he performed miracles. Mechanics of Floating Objects. Combinatric speculation. Areas of curves and spheres. And the number of grains of sands that it would take to fill up the universe.
He was so high up the math ladder he had to invent his own number system. He dabbled with the basics of integral calculus and said that they weren't rigorous enough for him.
And the man doesn't stop giving. The Archimedes Palimpsest, the best collection of Archimedes writings despite being buried under layers of rewritten parchment, has never been in the best condition, having been mold encrusted, painted over, and scraped apart. Yet with a little patience, a little hard work, and some ultra-fancy X-rays, the Palimpsest is still giving up new texts by, about, or unrelated to Archimedes. As late as April 2007, a new commentary about Archimedes was discovered.
Check out more info about the Archimedes Palimpsest.
ARCHIMEDES!!!
So we have a man who created ancient war machines that matched even the Romans for years. Yet despite the mountains of gold that earned him, the war machines were a distraction. His love was Math. Pure Math. And it was there he performed miracles. Mechanics of Floating Objects. Combinatric speculation. Areas of curves and spheres. And the number of grains of sands that it would take to fill up the universe.
He was so high up the math ladder he had to invent his own number system. He dabbled with the basics of integral calculus and said that they weren't rigorous enough for him.
And the man doesn't stop giving. The Archimedes Palimpsest, the best collection of Archimedes writings despite being buried under layers of rewritten parchment, has never been in the best condition, having been mold encrusted, painted over, and scraped apart. Yet with a little patience, a little hard work, and some ultra-fancy X-rays, the Palimpsest is still giving up new texts by, about, or unrelated to Archimedes. As late as April 2007, a new commentary about Archimedes was discovered.
Check out more info about the Archimedes Palimpsest.
Subscribe to:
Posts (Atom)