asinh perspective

The hyperbolic arc sine function, asinh, can be used to generate nice false perspective where details differing in size by, say, 100:1 can be clearly seen in the same picture without bad apparent distortion. Here's an example, click on the picture to see it full size:

Here's the Postscript source code if you want to read how the perspective calculation was done, display or print it in high resolution, or fiddle with the parameters:

-rw-r--r--  1 sw  staff   79061 19 Feb 23:18
-rw-r--r--  1 sw  staff  342108 19 Feb 23:26

asinh problem

The standard definition of asinh is:
asinh( x ) = ln( x + sqrt( x2 + 1 ) )
But if you implement it just that way in floating point, there is a problem when x < 0: with x a large negative number, sqrt( x2 + 1 ) is nearly the same as -x, so you are subtracting two large numbers with a small difference. As -x gets bigger, the difference is in digits that are farther to the right, until finally they disappear off the end. When (as in the test below) one wants to take the asinh of fairly large numbers, this loses accuracy until the difference is zero and ln( 0 ) blows up.

But since the function behaves pretty well when x >= 0, and since asinh( -x ) = -asinh( x ), a simple fix is this:

asinh( x ) =
ln( sqrt( x2 + 1 ) + x ) if x >= 0
-ln( sqrt( x2 + 1 ) - x ) if x < 0
Here's a graph of y = asinh( sinh( x ) ), which should be a straight line, using the naive implementation of asinh (in red) and the improved one (in green). The log of the error is also plotted for the two implementations. Click the picture to see it full size:

The pdf version is nice because pdf viewers let you zoom way in on details:

-rw-r--r--  1 sw  staff  106329 19 Feb 23:16 asinh_test3.pdf.gz
Here's the Postscript code if you want to print a hires version, understand the calculations, or tweak the all-important "step" parameter. When step is smaller you get more interesting details, but the calculation takes longer. For some reason (bug?), I haven't gotten this to work with step = .00002 or lower.
-rw-r--r--  1 sw  staff    4566 19 Feb 23:16
Up to my blog-oid: Analepses
or home page.

--Steve Witham