3
$\begingroup$

So if the following function is evaluated with the floating-point arithmetic, we get poor results for certain range of values of $x$. Therefore, I need to provide an alternate function that can be used for those values of $x$. The function is:

$ f(x)= \sqrt{1+x}-\sqrt{1-x} $

I have found the range for this and it is: $-\sqrt{2} \le y \le \sqrt{2}$

So how would I make an alternate expression or function for this.

Do I just multiply by its conjugate.

  • 0
    Multiplying by its conjugate is a good idea.2012-02-12
  • 0
    On a random sample of $10^7$ numbers in $[0,1)$, I got a maximum error of $3.33\times 10^{-16}$ between $f(x)$ as given and after multiplying by its conjugate. So I guess the two expressions have the same performance in floating-point arithmetic. I used double precision.2012-02-12
  • 0
    @lhf: Did you use uniformly distributed samples? The stability problems with the naive expression ought to show up for very small $x$, so it's not likely for $10^7$ uniform samples to contain any small enough points. In fact a typical pseudorandom generator that produces uniformly distributed numbers in $[0,1)$ will return _only_ numbers that can be subtracted from $1$ without loss of precision.2012-02-12
  • 2
    Just wondering what do you mean by saying "we get poor results"?2012-02-13
  • 2
    @Emmad: if $x$ is tiny, the expression given is exceedingly prone to subtractive cancellation.2012-02-13
  • 0
    @J.M., I see now, thanks for your explanation.2012-02-13

2 Answers 2