Of Minimalism and Mathematics
Hi, I am the mathematician here at MindValley.
Whenever we start on a new algorithm, I listen to all the non-mathematicians toss ideas on how to solve a problem (which I otherwise am paid to solve with some high-brow maths).
When they (and myself, in a non-mathematical capacity) are done with coming up with simple (but not simplistic) workarounds there are two areas where I get to apply my high-brow maths *wink*:
- How to quantify and automate the ideas.
- How to implement anything mathematically which otherwise is not possible heuristically (let’s not start on heuristic mathematics).
And while making the algorithm I take two things into considerations:
- How to eliminate as much if-then statements and for-loops as possible.
- How to use mathematics to save the computer the grunt work (although it is meant to do precisely that)- so that the application is lean (and mean).
I will give you a simple example from real life.
I was 10, or maybe 11 years old when I learnt programming (BASIC language) in my school. This is how I used mathematics (and minimalism) to solve my problem.
It was a simple program to print out the sum of first 100 numbers (the teacher wanted to test the for loop expertise of students in the exam,apparently). The standard method was to make a counter and add up each time inside the for loop which ran from 1 to 100. I was not very sure about the for loop syntax, so all I did was to use the formula (which I learned in self study because of my extra mathematical interests):
1+2+3+…+(n-1)+n=n*(n+1)/2.
And boom, to the chagrin of my examiner, I came up with a solution without having to use for loop (and hence saving computer the grunt work). Well, of course I got full marks because nowhere in the question it was stated that one has to use for loops. That was a very elementary concept which made me realize the power of mathematics, and I totally enjoy the experience.
ps: If you want to get fascinated even more, here is the derivation of the above formula. It is very elementary, but it still holds the charm of mathematics to me- as they say, first love never dies.
Let S=1+2+…+(n-1)+n …(*)
This can also be written as :
S=n+(n-1)+…+2+1 …(**)
Now we add equations (*) and (**), and we get:
2S=(1+n)+ (2+(n-1))+… ((n-1)+2)+(n+1)
hence, 2S=(n+1)+(n+1)…..n times.
hence, 2S=n*(n+1)
hence S=n*(n+1)/2
and voila… 1+2+…(n-1)+n=n*(n+1)/2
As a boy, it was a magic. And for me, it still is.
August 9th, 2007 at 4:19 am
So Zen!
August 9th, 2007 at 4:39 am
You got me lost at syntax… O_o
August 9th, 2007 at 5:55 am
I can tutor you on that ( I used to ,uninvited, teach my sister mathematical concepts)
August 9th, 2007 at 8:59 am
+1
I also ever blogged about eliminating nested-if http://ariekusumaatmaja.wordpress.com/2006/10/04/body-and-face-care-protect-yourself-by-laughing-at-your-code-proactively/ (sorry in Indonesian Language and it’s specific to ruby programming).
anyway, in ruby we can do this (ruby-one-liner):
id-ruby:~ arie$ ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]
id-ruby:~ arie$ ruby -e ‘puts (1..100).inject { |i,j| i+j }’
5050
id-ruby:~ arie$
instead of this bad smell below ;-)
id-ruby:~ arie$ irb
irb(main):004:0> s = 0
=> 0
irb(main):005:0> (1..100).each { |e| s += e }
=> 1..100
irb(main):006:0> s
=> 5050
irb(main):007:0> exit
id-ruby:~ arie$
August 10th, 2007 at 11:00 am
[…] Last night, Talat gave birth to his first blog post on our team blog. […]
August 19th, 2007 at 4:22 am
hi i enjoyed the read
August 19th, 2007 at 4:52 am
Thanks.
September 16th, 2007 at 11:45 am
why 2^o=1 ?
why -*- = + ?
please answer the question
September 16th, 2007 at 2:57 pm
What are your assumptions? If
n^x * n^y = n^(x+y) … (1)
and
n^(-z)=1/(n^z) …(2)
Put y=-x in (1),
whence, n^x * n^(-x) = n^(x-x)
=> n^x * n^(-x) = n^0
And by (2)
=> n^x * 1/(n^x) = n^0
=> n^0 = 1
Put n=2
Hence, 2^0=1.
I hope that was fun.If you are looking for deeper analysis I recommend you George Cantor.
As to your second question, I do not know what you mean by that.I haven’t encountered such a thing in rigorous mathematical analysis.
January 19th, 2008 at 4:21 pm
[…] we have Talat on some crazy weird math stuff, Khailee on him working with Rails, and Aslak on Erlang, the next […]
January 25th, 2008 at 5:58 am
i like it
August 3rd, 2008 at 5:06 pm
I agreed with you