Answered: Can you describe a square with 1 equation?

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

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.

L1 norm square

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:

Square comparison

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.

The engineer’s answer

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.

And my (worthless excuse of an) answer?

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…

Comments

  1. To answer your last question, just make a change of the coordinate system using a rotation matrix.

  2. It is possible, but you’ll get quite a monstrosity.

    First, make the move to polar coordinates. Since I’m too lazy to get my pad and pen, I used Wolfram Alpha to get

    maximum {|r cos(theta)|,|r sin(theta)|} = c

    Now, subtract some angle from theta:

    maximum {|r cos(theta-theta_0)|,|r sin(theta-theta_0)|} = c

    Then, if need be, substitute sqrt(x^2+y^2) for r and atan(y/x) for theta.

    Run the following in GNU Octave (or Matlab) for a nice set of concentric tilted squares:
    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

  3. Steve, the rotation matrix looks promising. My gut feeling is that, I need a vector to multiply it with. The 2 solutions don’t lend themselves well to quantifying a vector. Or more precisely, I can’t describe a square with the formula in
    (x-eqn-part, y-eqn-part).

    The question called for 1 equation to describe the square. It looks like I need to multiply at least the 4 corners of the square to rotate it, and even then, I’m missing all the points along the square itself.

    And Roie, your answer *does* look like a monstrosity… It also has merit. I don’t have Octave or Matlab, so I can’t check the veracity of the formulation.

    Ok, I stand corrected.

  4. It runs fine in the free MATLAB clone FreeMat V4.0.
    It indeed produces correct squares, and you can freely rotate them.

  5. Ok, thanks Cees! Confirmed that freely rotatable squares can be described.