Average Error: 14.4 → 0.0
Time: 1.9s
Precision: binary64
\[\left(0 \leq b \land b \leq a\right) \land a \leq 1\]
\[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
\[\begin{array}{l} t_0 := \frac{\sqrt{b}}{a}\\ \sqrt{\left|\mathsf{fma}\left(b, t_0 \cdot t_0, -1\right)\right|} \end{array} \]
\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|}
\begin{array}{l}
t_0 := \frac{\sqrt{b}}{a}\\
\sqrt{\left|\mathsf{fma}\left(b, t_0 \cdot t_0, -1\right)\right|}
\end{array}
(FPCore (a b)
 :precision binary64
 (sqrt (fabs (/ (- (* a a) (* b b)) (* a a)))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (/ (sqrt b) a))) (sqrt (fabs (fma b (* t_0 t_0) -1.0)))))
double code(double a, double b) {
	return sqrt(fabs(((a * a) - (b * b)) / (a * a)));
}
double code(double a, double b) {
	double t_0 = sqrt(b) / a;
	return sqrt(fabs(fma(b, (t_0 * t_0), -1.0)));
}

Error

Bits error versus a

Bits error versus b

Derivation

  1. Initial program 14.4

    \[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
  2. Simplified14.4

    \[\leadsto \color{blue}{\sqrt{\left|\mathsf{fma}\left(b, \frac{b}{a \cdot a}, -1\right)\right|}} \]
  3. Applied add-sqr-sqrt_binary6414.4

    \[\leadsto \sqrt{\left|\mathsf{fma}\left(b, \frac{\color{blue}{\sqrt{b} \cdot \sqrt{b}}}{a \cdot a}, -1\right)\right|} \]
  4. Applied times-frac_binary640.0

    \[\leadsto \sqrt{\left|\mathsf{fma}\left(b, \color{blue}{\frac{\sqrt{b}}{a} \cdot \frac{\sqrt{b}}{a}}, -1\right)\right|} \]
  5. Final simplification0.0

    \[\leadsto \sqrt{\left|\mathsf{fma}\left(b, \frac{\sqrt{b}}{a} \cdot \frac{\sqrt{b}}{a}, -1\right)\right|} \]

Reproduce

herbie shell --seed 2022081 
(FPCore (a b)
  :name "Eccentricity of an ellipse"
  :precision binary64
  :pre (and (and (<= 0.0 b) (<= b a)) (<= a 1.0))
  (sqrt (fabs (/ (- (* a a) (* b b)) (* a a)))))