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*:

  1. How to quantify and automate the ideas.
  2. 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:

  1. How to eliminate as much if-then statements and for-loops as possible.
  2. 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.

12 Responses to “Of Minimalism and Mathematics”

  1. John Says:

    So Zen!

  2. xinch Says:

    You got me lost at syntax… O_o

  3. talat Says:

    I can tutor you on that ( I used to ,uninvited, teach my sister mathematical concepts)

  4. arie Says:

    1. How to eliminate as much if-then statements and for-loops as possible.
    2. 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).

    +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$

  5. MindValley Blog » Blog Archive » Talat’s Baby Will Be A Girl! Says:

    […] Last night, Talat gave birth to his first blog post on our team blog. […]

  6. Darin Says:

    hi i enjoyed the read

  7. Talat Says:

    Thanks.

  8. vel murugan Says:

    why 2^o=1 ?
    why -*- = + ?
    please answer the question

  9. talat Says:

    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.

  10. Code and Tea - Malaysia Ruby Brigate Meetup Jan 2008 Says:

    […] we have Talat on some crazy weird math stuff, Khailee on him working with Rails, and Aslak on Erlang, the next […]

  11. em Says:

    i like it

  12. Blanoninny Says:

    I agreed with you

Leave a Reply