Quiz: Can you describe a square with 1 equation?

I was hanging out with my friends, and somehow the topics wandered into something that prompted a mischievous grin from one of the guys.

“Eh, I have a maths problem for you.” He could probably blind someone with that playful twinkle in his eye.

Can you describe a square with just 1 equation?

“What?” My mind was already racing to solve the problem.

“Just take it as a square in the 2D Cartesian plane. The centre of the square will be at the origin (0,0) to simplify the equation.” He seemed delighted to have stumped me.

I asked if there were any boundary conditions. No. Was the equation elegant? As in fairly simple when looked at, no mangling of terms. He gave it a second, and… yes, it was elegant.

Then he said the most important piece of information so far. “The answer might anger mathematicians. It is probably one of the fundamental differences between an engineer and a mathematician.”

Our conversations left this topic. But my brain was subconsciously still working on it. Then I blurted, “I think I solved it.” I described my way of thinking, and he said that’s along the correct line of thought. Then he just gave me the answer.

Yes, I agree. The answer will probably ruffle the feathers of the math purists.

As of this writing, I have yet to come up with the analytical formula of an equation to describe a square. I will post my findings, and my friend’s answer in a week’s time. You are encouraged to come up with your own solution. Post in the comments. Better yet, write about it in your blog. Tell your friends about it. Show them how awesomely clever you are.

Can you describe a square with 1 equation?

Bonus fun: My friend tried to explain a bit more. “There’s only one equal sign.” I think he was trying to insult me or something…

Update: Find out the answer.

Multiply by -1 to change sign considered harmful

Recently, I had the honour to delve into the depths of some legacy code. The program handled some financial data, and there was a section where the value had to change sign. The exact details aren’t important to the story, so let me come up with a suitable example. Uh… payment!

The monetary value stored in the database was considered positive (or profit). When people pay you $10, you have a record with $10 in the database. What happens when you pay other people? You use a negative value. This keeps the column data storage logic consistent.

So the variables used in the program stored positive values of the amount you need to pay other people, performing calculations as normal. When it came time to store in the database, there was a last line of code before the database update:

decPayment = decPayment * (-1);

Was -1 a magic number (as in, it was hardcoded, and could be some other number)? Was the multiplication in error (maybe it was supposed to be addition)? Was this line of code even supposed to exist?

It turned out that the programmer wanted to change the sign of the variable value. This method of changing sign has some downsides:

  • Multiplication is expensive. Maybe processor chips are fast now, but still…
  • The intent is not clear (what is it trying to achieve?)
  • It has more characters than the more optimal way

So what’s the “more optimal way”?

decPayment = -decPayment;

You don’t have to multiply by -1 to change the sign of a variable. Just directly negate it.

Help: Systolic arrays and matrix multiplication

Commenter apit had given me a problem which I am unable to help with: Matrix multiplication using systolic arrays.

I searched and I came up with very little. About the only thing I understood was that the “array” was not the variable array in code. It’s an array of processors. Systolic arrays are used for parallel processing.

So how is it used for matrix multiplication?

Hmm… I’ve never heard of systolic arrays before this. So I asked my friend and he found a PowerPoint presentation that gave the best explanation that I could understand.

Systolic arrays & their applications, by Jonathan Break.

I believe apit didn’t understand that each “array cell” don’t have past memory of operations, only an intermediate result.

If you happen to understand it, and can explain it better than I do, please chime in with your comment. Thanks.

Launching the Math Wizard

After about 2 months of hard work, it’s here! The Math Wizard is finally here!

I’m selling it for USD 10, and you can find out more here.

Today is auspicious, as the Chinese would say, because there are only 0’s, 1’s and 2’s in the date.

  • 20100210 in YYYYMMDD format
  • 10022010 in DDMMYYYY format

“You know, if you launched on 1 Feb 2010, it would be even nicer. 01022010 in DDMMYYYY format. That’s a palindrome!”

Uh… yes you’re right. Well, I needed 9 more days to prepare…

Answers to philosophical questions must be reasoned

My friend wrote a short guide on what makes a question philosophical. The 3 conditions for a question to pass the philosophical test are interesting.

Has not been answered by science

The obvious reason is that, if it’s answered by science, there’s no point in answering it (philosophically).

For example, “Can penguins fly?” is answered by science. It’s “no”. Their bodies aren’t made for flying. Although…

More than one possible answer

If there’s only one answer, there’s no point in answering it.

For example, “Is 1+1 = 2?” has the answer “yes”. There’s no other answer.

Unless you’re talking about base 2…

Cannot be answered by conducting an experiment

“Can common salt be produced by mixing two liquids together?” can be answered with experiments. After laborious testing, you find that if you mix sodium hydroxide and hydrochloric acid, you get sodium chloride (and water), or more commonly known as salt.

If a question can be answered with experiments, then there’s no point arguing about it. Just do the experiment to test the answer.

So I conclude…

that my friend doesn’t like science. *smile*

No, it’s that when a question can only be answered by reasoning it through, then it’s considered a philosophical question.

Hungarian notation gone terribly wrong – lust

I was working on some legacy code in PowerBuilder, when I saw the name of a user interface control (heavily anonymised and fun-ised):


Let’s break that down:

  • local (as opposed to global)
  • user (I think? User-created as opposed to system/standard)
  • static text (the Label equivalent in ASP.NET)

I wonder what was going through that programmer’s mind when he wrote that…

Making things happen

This is a short announcement, and a slight deviation from the usual topics (not that the topics are consistent, but … never mind).

Making things happen

I’m excited to say that my Math Wizard ebook is going to be launched in about 9 days. Launch date is 10 February, and the time is

  • UTC 1400 (2pm London-ish)
  • EST 0900 (9am New York-ish)
  • Singapore 2200 (10pm. Because I’m like Cinderella. I have to go before midnight.)

Thank you for reading Polymath Programmer, with the wide (and sometimes weird) variety of topics covered. This ebook product I created is an amalgamation of my interests in math and Dungeons & Dragons (a tabletop roleplaying game). The price will be set at USD 10 (for now).

More product details will be announced on the launch date. For now, you can download a free preview of the Math Wizard, or you can read more on why I created the Math Wizard.

I’m making things happen. Tell me about yours.