Message #12 Posted by Valentin Albillo on 10 Dec 2003, 4:47 a.m.,
in response to message #11 by RMillán
"ABS instead of ->P? "
Correct! That's the exact intended solution of the puzzle.
Conversion to polar form (->P) changes the complex stack like this:
X: (x, y) ->P X: (mod, arg)
where mod = sqrt(x^2+y^2) and arg = arctan(y/x). We're only interested in the "mod" part, which is mathematically equal to the distance between both given data points, but we're not interested in the "arg" part at all, so it would be nice if we would find some way to avoid computing it at all.
This can be done using the ABS function, which returns the "mod" part alone, changing the complex stack like this:
X: (x, y) ABS X: (mod, 0)
and so we get the distance we need but avoid computing the unneeded angle altogether, thus saving a little time. Thus, my original fast 8-step solution was this:
01 LBL A
Congratulations for solving it, extensive to all of you who took interest in this mini-challenge. The idea was to show how the comprehensive HP-15C built-in function set can be used in non-obvious ways to achieve apparently unrelated computations. In this case, the use of complex functions allows a single "-" operation to perform (x2-x1) and (y2-y1) *simultaneously*, and then ABS computes the square root of the sum of their squares without computing the angle. This way you get done a lot of computation using just *two* steps, "-" and "ABS". Neat :-)
Best regards from V.