MathOverflow is a question and answer site for professional mathematicians. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Inspired by a Project Euler problem, I recently started playing around with Ulam spirals. My first thought was that an Ulam spiral could be a (rather useless) coordinate system, and how I might be able to convert from "Ulam coordinates" (i.e. just the number on the spiral at a given point) to rectangular coordinates and vice versa.

So the question is: Is there a single function that would return the number on the Ulam spiral given (x,y)? And also (and perhaps more of a challenge), one to convert back?

I'm just a sophomore computer science student, and not terribly competent in math compared to the people on these site, sadly (I'm in Calc III right now). I was able to work out four separate equations to find the number on the spiral given an ordered pair, but that's one for each of four sections in between the 'diagonal axes' (I'm not sure what to call them). Unfortunately, I have yet to make this more simple. Any ideas?

share|cite|improve this question

closed as off-topic by Ricardo Andrade, Todd Trimble, Chris Godsil, Andrés E. Caicedo, Andrey Rekalo Sep 23 '13 at 5:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about research level mathematics within the scope defined in the help center." – Ricardo Andrade, Todd Trimble, Chris Godsil, Andrés E. Caicedo, Andrey Rekalo
If this question can be reworded to fit the rules in the help center, please edit the question.

As you observed, it is easy to find formulae (given by polynomials of degree $2$) for the four "half-lines" given by $\vert x\vert=\vert y\vert$. One gets then formulae for the general case according to the quarter plane determined by $\vert x\vert=\vert y\vert$ containing a given point. I think that this is the simplest solution. By the way, I agree with your first thought. – Roland Bacher Jun 22 '10 at 5:41
Great question. I'm interested in this because it provides a nice spatial hashing algorithm. For example convert (x,y) to ulam, and then insert into hash table using ulam as key. – John Henckel Oct 29 '15 at 3:29

A while ago, Dan Pearcy approached me with a similar problem, asking for the inverse formula to convert $n$ into coordinates $(x,y)$. Using the floor function, it was not too difficult to provide an explicit closed form. He wrote a blog post about this, including my extremely messy closed form:

share|cite|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.