And here I thought bit shifts were already very simple to understand.
I was actually hoping that the video would shed some light on the Udja Eye thing, but it didn’t… oh well.
And here I thought bit shifts were already very simple to understand.
I was actually hoping that the video would shed some light on the Udja Eye thing, but it didn’t… oh well.
Pierce Brown created a beautiful infographic on the Fibonacci sequence. It has rabbits, sea shells and sunflowers. Go take a look.
I was reading this post by Dan Meyer on pseudocontext in maths problems.
If we invite pseudocontext in our classrooms without condition, it becomes harder and harder to tell the difference between the real and the unreal.
Back when I was young, a lot of maths problems made little sense to me. In those days, the maths syllabus up to primary 6 (at 12 years old, or grade 6 if you’re in America) wasn’t particularly hard. At least to me. I’m not bragging, I’m just saying that the education system made things more difficult by introducing word problems. The epitome of conquering a maths exam paper was solving all the word problems at the end.
Word problems were created to introduce another element into elementary math (to make them difficult?). They added language. Suddenly it was something like:
John, Fred and Ken had $5 total. John bought 10 red marbles and Fred bought 12 blue marbles. If 1 red marble costs $0.10, and 1 blue marble costs $0.15, how many blue marbles can Ken buy if they still want to have $1 left?
Your command of the English language became a factor. But it was still ok, because the wording usually formed a pattern. It was marbles, people’s ages, number of apples or oranges in the basket, or some such. In a normal situation, if I really wanted to know your dad’s age, I’d just go ask him. I don’t really need to infer that your dad is 2.5 times your age, and then I figure the answer out (assuming I know your age).
Now if you don’t already know, it’s bloody competitive here in Singapore. Students are afraid of not doing well in school, of heads shaken by their friends, teachers, parents and relatives. Parents send their children to tuition classes (in addition to the normal school classes), regardless of their children’s grades. If the grades are bad, then improve them. If they’re great, great! Now perfect them. Go do your ten year series!
I went to tuition classes till I was 10 years old (primary 4 or 4th grade). I stopped because my dad couldn’t afford to pay for the classes. Being able to eat and pay the bills were more important. It’s a good thing I was disciplined enough to get good enough grades (and imbue enough motivation for all subjects, not just maths).
When I was in university, to supplement the cost of education, I looked into giving tuition. I was surprised that everyone from primary one to university level (?!) were asking for help. Let me just say, I make a lousy tuition teacher. I don’t really know the current syllabus well enough to help the students. Once, I brought up the subject of video games, using the position of battleships to illustrate … something. I can’t remember. I think it was x- and y-coordinate stuff. I was trying to interest the young boy I was teaching. It fell flat. I suck…
Which brings us to curriculum. It turns out that under the Singapore maths curriculum, Singapore students rank high for maths internationally. It’s so good that America has adopted the method. There’s even a name for it: Singapore Math Method. Let me tell you, I’m simultaneously amused and confused.
I’m even more surprised that Israel adopted the method in 2002, translating the textbooks to Hebrew. I was browsing in the bookstore reading Start-up Nation (Amazon link). It told a story of how Israel, being surrounded by hostile countries, had to innovate hard. Their brightest people are in the universities doing research and are also in the top military ranks. The book told a story of how the “flat” nature of their military translated to their way of doing businesses, in particular start-ups. My friend Christopher told me that per capita, Israelis were the richest in the world. It’s their culture that made them more inclined to creating wealth. I was also told about the Jewish mother syndrome… So I’m a little surprised that this group of people want to know about our (Singaporean) method of teaching maths.
I still believe in solving real world problems. I believe we’re not injecting enough curiosity into our students. That Singapore Math Method seems to have less force-feeding of concepts, and more of coaxing the student to question. The Singapore culture doesn’t seem to require curiosity for the students to do well (have I mentioned the parents are bloody competitive?). Hopefully, that’s changing.
This is going to be a cynical view, but I think most Singaporeans are striving for wealth, and wealth alone. Wealth translates to a better life. There’s nothing wrong with that. Singaporeans strive hard to attain wealth so they can forget about (seemingly) miserable lives. Ok, let me take that back. Apparently, Singapore is one of the happiest places in the world. There’s a “but” though…
Singapore ranks high on evaluated happiness, but not on experienced happiness
Alright, this is starting to depress even lil’ cheerful me…
So. Problems are formulated, and then given to our students to solve. But they have to learn how to formulate problems too, and that comes from asking questions, from being curious, from being disciplined and persistent. And that comes from cultural and societal influences, not from educational systems.
The 67th Carnival of Mathematics is up. Awesome stuff there, so go check it out.
Something caught my attention. James Grime created a video of a math puzzle involving two trains and a fly. Hmm… sounds familiar…
Then there’s the video with the solution:
That sounds really familiar…

Bzzz…
Commenter Timo wants to know how to get a nice shape for a reverse engineered Bézier curve.
The question started from calculating the control points of a cubic Bézier curve if you’re given 4 points that lie on the curve, assuming the first and last given points were also the first and last control points. I wrote a similar article for a quadratic Bézier curve too.
To sum up, you have 1 degree of freedom when working on a quadratic Bézier curve. In the case of a cubic Bézier curve, you have 2 degrees of freedom, meaning 2 variables in the calculation that you have to decide on. Now this posed a problem, because there are an infinite number of solutions. How do you decide on a numeric value?
Well, for a quadratic Bézier curve, the simplest and obvious option is to choose the second given point (since the first and last control points are determinable) to be at the halfway mark. For a cubic Bézier curve, the second and third given points are chosen to be at the 1/3 and 2/3 mark along the curve respectively. Now this may or may not be suitable, but it does give you something to start with.
I want to state right now, that I had not been doing formal mathematics for a while. There is a limit to what I know, and I’m not an expert. I just know enough to figure out how to solve problems. Sometimes, it’s not enough. Keep that in mind.
Now Timo’s problem is getting a better shaped cubic Bézier curve from those calculations. Since the 4 given points are fixed, and the first and last control points are also fixed, the only thing you can manipulate are the second and third control points. Which in turn means deciding on values of u and v to get a “nice” cubic Bézier curve in the end.
This, “niceness”, is a subjective criteria. How do you determine if a cubic Bézier curve looks nice? Remember that we don’t have the control points yet. So we don’t know how the curve looks like. So we don’t even know if manipulating the second and third control point to not be at 1/3 and 2/3 will result in a nice curve. It’s a chicken and egg problem.
During the correspondence with Timo, some solutions were discussed. The next simplest set of values to try for u and v are calculated based on the given points.
Let d1 be the distance between the first and second given point.
Let d2 be the distance between the second and third given point.
Let d3 be the distance between the third and last (fourth) given point.
Then let u = d1/(d1 + d2 + d3) and v = (d1 + d2)/(d1 + d2 + d3). This should result in a curve that’s “better shaped” than the (u,v) pair (1/3, 2/3). When I wrote that article for the cubic curve version, this was the next default set of values for u and v, but I didn’t want to add too much more. Well, nobody asked, so I left it as it was.
It turns out that Don Lancaster already wrote about it. He called it “apportioned chords” method.
http://www.tinaja.com/glib/nubz4pts1.pdf
Then Timo had another problem. He wanted the second and third given points to also lie at the “loop tips”. What are loop tips? After some clarification, I believe Timo is referring to the inflection points on the curve. An inflection point
is a point on a curve at which the curvature (second derivative) changes signs. The curve changes from being concave upwards (positive curvature) to concave downwards (negative curvature), or vice versa.
A cubic Bézier curve can have 0, 1 or 2 inflection points. If it’s a straight line, it has 0. If it’s U-shaped, it has 1. And if it zigzags, it has 2. And Adrian Colomitchi proved that there are at most 2 inflection points on a cubic Bézier curve.
UPDATE: The following diagram is wrong. Please refer to this article for the correct version. I was thinking of points where the second derivative was zero, not when it changed signs (as defined above).

As you can see, inflection points don’t necessarily have to coincide with the given points.
By the way, I used Paint.NET for the illustration. I took a screenshot of me drawing the curve, still with the given points visible (noted by the small squares). Paint.NET appears to have succeeded in doing the very thing Timo wants, to render a cubic Bézier curve using 4 given points. Of course, I’m assuming the image editor is using cubic Bézier curves…
I found another reference with a more explicit mathematical formulation to help Timo.
http://www.cis.usouthal.edu/~hain/general/Publications/Bezier/bezier%20cccg04%20paper.pdf
As of this writing, page 3 of that paper explicitly shows the calculation needed to find the inflection points of a cubic Bézier curve, if they exist. Let me emphasise that again. The curve might have 2 inflection points, only 1 inflection point, or none at all (a straight line, the trivial version of a Bezier curve, has no inflection points).
Then Timo found another forum posting for the fast calculation of maximum curvature. An inflection point would have the “maximum curvature”. The problem with that solution is that it assumes we have the control points.
So my suggestion was to do iteration. Use my method to get a set of control points. Perhaps use the apportioned chords to start off with a good set of control points. Then apply the maximum curvature solution to find the inflection points and the associated values of t. With those values of t, pump them back into my method to find a new set of control points. Pump those control points into the maximum curvature solution to find inflection points and their t values. Iterate till the t values between iterations are within acceptable margins of error.
Caveat: I don’t know if this combination of 2 algorithms in an iterative manner will converge. I have not tested this. Use at your own risk.
Anyway, Timo found another solution himself (he didn’t say what though). He still needed to handle that cusp point. What cusp point, you ask? It’s in page 3 of that paper I mentioned above. That paper is for 2 dimensional cubic Bézier curves. The degree of the curve is independent of the degree of the dimensions. Timo wants to know how the 3 dimensional case will look like.
Now, the method of finding inflection points is to do a cross product of the first derivative and second derivative of the cubic Bézier curve equation. The Bézier curve is parametrised into
x(t) = ax * t^3 + bx * t^2 + cx * t + dx
y(t) = ay * t^3 + by * t^2 + cy * t + dy
and using the Bézier basis matrix, the coefficients are
ax = -x0 + 3*x1 – 3*x2 + x3
bx = 3*x0 – 6*x1 + 3*x2
cx = -3*x0 + 3*x1
dx = x0
ay = -y0 + 3*y1 – 3*y2 + y3
by = 3*y0 – 6*y1 + 3*y2
cy = -3*y0 + 3*y1
dy = y0
Set the cross product to 0. The inflection points are found at values of t when you solve that equation:
x’ * y” – x” * y’ = 0
where x’ and x” are the first and second derivatives of x(t). Similarly for y’ and y”. The solution is in that paper I mentioned before.
This is if the curve is in 2D. The cross product of 2D vectors is a scalar. And we set the scalar to 0 to solve for t. The cross product of 3D vectors is a vector, and so we’re solving with a zero vector.
So with
z(t) = az * t^3 + bz * t^2 + cz * t + dz
for the third dimension, we have
x’ = 3 * ax * t^2 + 2 * bx * t + cx
y’ = 3 * ay * t^2 + 2 * by * t + cy
z’ = 3 * az * t^2 + 2 * bz * t + cz
x” = 6 * ax * t + 2 * bx
y” = 6 * ay * t + 2 * by
z” = 6 * az * t + 2 * bz
The cross product is the determinant of the following

where i, j, k are the unit vectors. I’ll leave it to you to find out the formula for the determinant of a 3 by 3 matrix.
So we’re going to solve this:
0 = (y’ * z’’ – z’ * y’’) * i – (x’ * z’’ – z’ * x’’) * j + (x’ * y’’ – y’ * x’’) * k
where 0 is the zero vector.
This implies that
y’ * z’’ – z’ * y’’ = 0
x’ * z’’ – z’ * x’’ = 0
x’ * y’’ – y’ * x’’ = 0
This time the zeroes are scalars. We now have 3 times the number of equations to solve when compared to the 2D case. This means there are potentially 6 values of t for the inflection points to check. Hopefully, there will be repeated values of t. Hopefully, the number of unique values of t is 2 or less (remember Adrian’s proof?).
If a t value is repeated, it’s probably an inflection point. What if we get 6 unique values? Is a 6-unique-value case even possible? I don’t know. You’ll have to interpret the values in the best way you can, based on some assumptions and arguments.
So after reading through that entire article, what do you think? Comments on the methods I described? Do you have a new method? Your thoughts on whether this problem is even solvable? That I’m a complete idiot?
Let me know in a comment. Or better, write a blog post and tell me about it. Because if it took me that long to explain the solutions, your solution is probably just as long. It’s a Bézier curve. A picture might be appropriate.

Some time ago, I received an unusual request for help from a stranger via email. It was something of a financial nature, and I felt incapable of answering it fully. So I turned to Christopher, my engineer friend who’s also versed in finance, for help. I felt that the stranger’s request was quite personal, and I wasn’t sure if the stranger wanted the request to be publicised here on the blog. So to protect the innocent, I will wrangle the original problem to be most indecipherable. However, the solution given by Christopher was worth mentioning.
On to the problem then. We shall stick only to money as the sole source of contribution. Emotional and effort labour are just as important, but it’s difficult to quantify them mathematically. We’ll even ignore time labour. It’s not fair, but the world sometimes operate that way, so we’ll just accept it as best as we can.
Suppose there are 2 partners in a new business. Each of them contributes a different amount of money each month to the business, and may even contribute variably across each month. The money is used to maintain the business (for example, settle any bank loans, pay salaries, web site hosting costs, marketing expenses, product creation costs, utility bills and so on). After say 3 years, they want to sell off the business and liquidate their assets in it.
How much should each business partner take from that lump sum of money (from selling the business), based solely on their monetary contribution over the years?
The main problem of using a simple summation of their monetary contributions and calculating a percentage based on that, is inflation. $100 contributed in the 1st month is worth more than $100 contributed in the 37th month (4th year, 1st month).
Christopher suggested abiding by a yearly rate for the purpose of inflation, in particular, using government bonds as the rate. To add stability to the rate, he suggested using the 10-year bond rate. The currency also matters. For our example, we’ll use the United Kingdom pound. Where you get that rate is up to you, as long as you feel it’s legitimate and correct, and that everyone agrees to using that rate. I got mine from Bloomberg (suggested by Christopher):
http://www.bloomberg.com/markets/rates/uk.html

[note: the above was correct as of time of writing this article. You are advised to go visit the Bloomberg site for the updated numbers. Or some other trusted site you know because you're probably more financially powerful than me.]
The rate is 3.51% for the 10-year yield.
Let’s give our business partners names, Arianna and Ben.
Let s(i) be the “sum” at end of year i
Let x(i) be contribution of Arianna in year i
Let y(i) be contribution of Ben in year i
Let b(i) be bond interest rate in year i (3.51% is changed to 0.0351 without the percent).
Then s(i+1) = [1 + b(i)] * [s(i) + x(i) + y(i)]
Let cx(i) be sum contribution of Arianna, and cy(i) be sum contribution of Ben at end of year i.
Then cx(i+1) = [1 + b(i)] * [cx(i) + x(i)]
and cy(i+1) = [1 + b(i)] * [cy(i) + y(i)]
Then contribution percentage at end of year i of Arianna is
100 * cx(i) / s(i)
Contribution percentage at end of year i of Ben is
100 * cy(i) / s(i)
And a note. The numbers were picked out of thin air. I am not saying a man is better than a woman in the business arena. I need some numeric variation, and I just took it as the man contributing more. And the fact that I don’t want to search the stock photos for generic businessy settings with 2 people in them for hours. For some reason, it’s very hard to find a photo with 2 business people of the same gender. Then you wouldn’t be able to guess which one was which. I originally had Andy and Ben starring in my example.
Anyway…
Let’s say, in the 1st month, Arianna and Ben contribute £100 and £150 respectively. In the 2nd month, £200 and £100 respectively. In the 3rd month, £0 and £250 respectively. For the 1st year, Arianna and Ben contribute £1200 and £1800 respectively, for a grand total of £3000.
So at the start of the 2nd year, we look at the rate and say we find it’s 3.5%. Then we inflate their contributions by 3.5% to £1242 (1.035 * 1200) and £1863 (1.035 * 1800) respectively. We also inflate the sum total from £3000 to £3105.
Arianna and Ben continue to contribute to the business in the 2nd year. And at the end of the 2nd year, Arianna and Ben contributed £2100 and £1900 respectively (total £4000).
At the start of the 3rd year, we find the rate to be 3.52%. Here’s where it’s different. First we add the respective contributions to the previous inflated amounts. So we have £3342 (£1242 + £2100), £3763 (£1863 + £1900) and £7105 (£3105 + £4000) for Arianna, Ben and the sum total respectively. Then we inflate them by 3.52% to get £3459.64, £3895.46 and £7355.10.
For the 3rd year, Arianna and Ben contribute £2400 and £2600 respectively. And at the start of the 4th year, the rate is 3.51%.
Adding the sum contributions first, we get £5859.64, £6495.46 and £12355.10 for Arianna, Ben and sum total respectively. Inflating the numbers by 3.51%, we get £6065.31, £6723.45 and £12788.76. At this point, our business partners want to sell off their business, and they want to know what’s their percentage contribution.
So Arianna contributed 100 * 6065.31 / 12788.76 = 47.43%.
Ben contributed 100 * 6723.45 / 12788.76 = 52.57%
I didn’t take care of rounding issues and decimal places in the example. I’ll leave that to you as an exercise. The most accurate method will be to store the values as they are, and only take them out for calculations at the final stage. Storing intermediate results might skew the accuracy if done over many iterations.
The other point is that you are free to calculate on a monthly basis instead of a yearly basis. The assumption is that the rate stays stable throughout the year, so a yearly rate is usable. If you’re inflating on a monthly basis, the contribution values will shoot up very quickly. They will not have any semblance to their original values. I want you to remember that the values are used to calculate the final percentage contribution, not the absolute contribution.
Contributing $40 out of $100 is 40%. Contributing $673.20 out of $1683 is also 40%. It’s relative.
[note to self: why didn't I think of using a currency with $, the generic dollar sign? I had to go pick the pound, and then had to replace all the monetary values in the example with the correct currency symbol...]
[UPDATE: the stranger found another of my article on percentage calculations. It must have made sense, because the stranger took that to mean I could help with the problem the stranger was facing. Yes, I'm using "the stranger" so you don't even know the gender. How's that for anonymity?]
[leading image by nyul]
I wrote an article on cubic Bézier curves almost 3 years ago. And there had been emails and comments sporadically during that period. The latest one was from a lady, so I decided to write something about it (yes, I’m biased).
The recurring (if you count 2 or 3 as recurring) question is about quadratic Bézier curves. I provided a method for calculating the 4 control points of a cubic Bézier curve, given 4 points that the curve has to pass through. The question is, how do you calculate the 3 control points of a quadratic Bézier curve, given 3 points that the curve has to pass through? The 1st and 3rd points are also the end points of the curve.
As with the cubic version, there are infinitely many solutions. The question I posed above missed out a crucial element which would give a unique solution. How far along the curve is the 2nd point? Let’s look at the quadratic Bézier equation first:
B(t) = (1-t)^2 * p0 + 2(1-t)t * p1 + t^2 * p2
where p0, p1 and p2 are the control points, and t in [0,1]
Suppose you have 3 points that the curve has to pass through. The 1st and 3rd points are also the 1st and 3rd control points (substitute t=0 and t=1 into the equation to see why that is so). That leaves the 2nd control point to be calculated. If you didn’t know, the inner control points of a Bézier curve don’t necessarily fall on the curve itself (and usually don’t).
Since you know the 3 points that pass through the curve, and the 1st and 3rd control points are known, let the points be p0, f and p2, where f is the point on the curve when t=u. Stating the value of u is the crucial element for a unique solution. In the case of a quadratic Bézier curve, the value off the top of my head is 1/2. Meaning the 2nd known point is assumed to fall about halfway along the curve. You may have a different opinion based on the problem you’re trying to solve.
So let’s substitute into the equation, shall we? At the 2nd known point f, we have
f = (1-u)^2 * p0 + 2(1-u)u * p1 + u^2 * p2
Rearranging the terms, we have
p1
= [f - (1-u)^2 * p0 - u^2 * p2] / 2(1-u)u
= 1/(2(1-u)u) * f – (1-u)/2u * p0 – u/2(1-u) * p2
Remember that u is determined by you (1/2 is a good value if you have no other information otherwise). p0, f, and p2 are the 3 known points that pass through the curve (f is the point where t=u). So the only unknown is p1, the 2nd control point.
And I can “cancel” the (1-u) and u terms in the simplification because u is strictly between 0 and 1. In particular, u cannot be equal to 0 or 1.
There you have it. A unique solution to finding the control points of a quadratic Bézier curve.
But hey, I’m feeling generous. I’ll do up a solution with real values.
Suppose you have 3 points [1,1], [2,3], [4,2] that pass through a quadratic Bézier curve. The 1st and 3rd points, [1,1] and [4,2] are the 1st and 3rd control points respectively. That leaves calculating the 2nd control point such that the curve pass through [2,3] when t=0.5 (let’s assume [2,3] is halfway along the curve).
Let’s look at the final stage of our 2nd control point calculation
p1
= 1/(2(1-u)u) * f – (1-u)/2u * p0 – u/2(1-u) * p2
= 1/(2*(1-0.5)*0.5) * [2,3] – (1-0.5)/(2*0.5) * [1,1] – (0.5)/(2*(1-0.5)) * [4,2]
= 2 * [2,3] – 0.5 * [1,1] – 0.5 * [4,2]
= [4,6] – [0.5,0.5] – [2,1]
= [1.5,4.5]
So the final control points are [1,1], [1.5,4.5] and [4,2].

But wait, there’s bonus material! The lady also asked about curve tension. I’m not sure if that’s the correct term. Basically, she wanted to know how to skew the 2nd control point towards the 1st or 3rd control points.
This one’s easy. Just adjust your u value. If you assume u=0.2, then the 2nd control point is skewed towards p0, the 1st control point. If you assume u=0.8, then the 2nd control point is skewed towards p2, the 3rd control point.
So to skew towards p0, let u be closer to 0. To skew towards p2, let u be closer to 1.
Remember, u is decided by you, unless the problem you’re solving states otherwise.
What started out as an innocent question meant to poke me became an interesting math problem to ponder. You might want to read the original question and the answers presented. The final question was, can a square be described in any rotational orientation (based on the 2D Cartesian plane) with just 1 equation?
The answer is a resounding YES.
Meet Roie, who proposed this solution:
maximum {|r cos(theta-theta_0)|,|r sin(theta-theta_0)|} = c
This is basically modified from the max-abs solution by Mike Anderson:
max(abs(x),abs(y)) = c
You move from Cartesian coordinates to polar coordinates. Once you’re in polar plane, you can rotate by changing one variable (the angle). I actually wrote something about converting between Cartesian and polar coordinates for the use of image rotations. I can’t believe I forgot about that…
Roie also gave sample (GNU Octave or MATLAB) code:
theta0 = 0.5; x = ones(201,1) * (-10:0.1:10); y = x’; z = max(abs(sqrt(x.^2+y.^2) .* cos(atan(y./x)-theta0)),abs(sqrt(x.^2+y.^2) .* sin(atan(y./x)-theta0))); contour(z) axis square
Unfortunately, I am unable to verify that. Fortunately, Cees Meijer confirmed it for me. He introduced me to FreeMat, a free open source software that works like MATLAB. Unfortunately, I cannot install the Windows version because I need an x64 executable (I’m on Windows 7 64-bit), and FreeMat currently only has x86 version (32-bit).
Oh well, if it works, then I can finally do matrix multiplications in one line of code. So there, Will.
First, I want to say how humbled I am by the people who read this blog. You are awesome.
You might want to read the original post where the question came from. So, can you describe a square with only 1 equation? 3 readers gave their opinions, and they are all correct (meaning they’re smarter than me). I will present their answers first, then present my engineer friend’s answer, and then mine (which is worthless, and didn’t work out the way I wanted).
The first answer was from Mike Anderson, who gave this:
max(abs(x),abs(y)) = c

That actually took me a while to understand. And is actually the more complicated answer. But it’s exactly the answer my friend was looking for, which is an upright square. We’ll assume the centre of the square to be the origin. The absolute function reduces the working Cartesian plane to just the first quadrant (if it works in the first quadrant, it works in the other quadrants). The maximum function ensures that either the x-value or y-value (or both) is equal to c (half the width of the square).
What if the absolute function is not in action? Then if -c < x < c, then y must be either -c or c (because of the maximum function). Therefore there are 2 horizontal parallel lines. Similarly vice versa, creating 2 vertical parallel lines. And there’s your square. This is brilliant.
The second answer was from Christopher Tay, who gave this:
|x| + |y| = C
which is the L1 norm.

The norm of a matrix is the magnitude of the matrix. In this case, the matrix is actually a 2 dimensional vector. The pipe character | surrounding the x and y values mean we’re taking the absolute value.
This one is interesting. It means that the larger the value of x, the smaller y has to be to compensate, so that the sum of x and y is C. This see-sawing effect created a triangular shape for each quadrant. Which when formed together, becomes a square (tilt your head 45 degrees to see it better).
Then Chris McAloney came in with this:
abs(x) + abs(y) = c
This equation is equivalent to the L1 norm form. Chris also pointed out that the squares formed by the previous 2 equations differ from each other by a rotation of PI/4 (radians) or 45 degrees.
So there are 2 solutions! My engineer friend was shocked when I told him. I had to admit, I was gloating just a little when I told him my readers solved his problem…
One small point to note. The constant c in each equation is specific to each equation. As in if you supplied the same constant to each equation, the width of the squares formed are different. Let me illustrate:

The square formed by the max-abs way has a width of 2c.
The square formed by the L1 norm way has a width of sqrt(2)*c.
So what’s my friend’s answer? He said the answer might anger some mathematicians. He also said the answer might demonstrate a fundamental difference between how engineers and mathematicians think. And his answer is…
x^10000 + y^10000 = 1
Or basically x and y to the power of a sufficiently large number. The result is not exactly a square, but it looks sufficiently like a square.
And that was his point. That engineers take “good enough” and practicality as priority. If a wooden beam is in the correct position, and is supporting the weight of the roof, who cares if it’s 1 nanometre off the intended position?
How did he come up with it? He was playing with Wolfram Alpha and was just dumping equations into it… To see what happens, start with
x^2 + y^2 = 1
That’s a circle with radius 1. Then increase the power to 10
x^10 + y^10 = 1
You’ll see a square with round edges. Actually x^100 + y^100 = 1 gives a nice square plot. To my friend, that’s a good enough square. He posed the question to me for an analytical answer, because even he knows his answer wasn’t exact.
I hit upon the idea of starting with a circle. Then morphing it somehow into a square. The idea came from a super equation that can describe a cube or sphere or some other 3D object. I can’t find it anymore… I saw the equation when I was doing research on the demoscene. You vary a parameter t, and you get different 3D objects. That’s neat.
So I started with this:
(r * sin(θ))^2 + (r * cos(θ))^2 = r^2
Yup, I used polar coordinates. I was thinking of somehow wrangling the sines and cosines with ceiling and floor and rounding functions. I was trying to force something like:
ceiling(cos(θ)) * (sin(θ))^2 [<- NOOO, THIS IS WRONG]
to work… That was for y. I had a correspondingly elaborate term for x.
Then it dawned on me.
How am I going to draw a square in the polar coordinate plane when I basically only had theta to work with? Everything will be circular.
I tore my math working off my writing pad and threw it down the rubbish chute. I might also have sworn vehemently. Can’t remember…
So there you have it, 2 equations to describing a square. And 1 equation that creates a result that looks like a square, which for most purposes and intents may be regarded as a square.
Then my friend came in with the last word:
“For bonus points, can you use some trig functions to tilt it back so that the equation can have any angle?”
We have 1 upright square, and 1 square that’s tilted 45 degrees. My friend wanted to know if there’s an equation that creates a square in any rotational orientation. I don’t believe there’s one, so please don’t bother to try. It’ll just waste your brain cells. But you’re welcome to try it as an intellectual exercise.
Me? I need to get another writing pad…
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.
Simple and intuitive to use, SpreadsheetLight gets you creating Open XML spreadsheets within minutes. Find out more.
"With very little information on the Open XML SDK available anywhere, Vincent’s programming guide was a real life saver for us. We could not have done it without it."
I'm a mathematician, programmer, writer, magazine editor, video creator and entrepreneur. I'm also awesome at reverse engineering Bezier curves and excel at creating spreadsheets with C#/VB.NET/Open XML SDK.
My name is Vincent Tan. I write about maths, programming, writing, publishing, design, entrepreneurship, online business and other esoteric topics that might not seem to match each other.
I also publish a monthly online magazine Singularity (browse the archives). Subscribe to get exclusive updates. It's free.