Average Error: 28.1 → 3.8
Time: 9.2s
Precision: binary64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{x}{y}, x, y\right)\\ \mathbf{if}\;z \cdot z \leq 1.0679394866726301 \cdot 10^{+297}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z \cdot z}{y} - t_0\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot 0.5\\ \end{array} \]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{x}{y}, x, y\right)\\
\mathbf{if}\;z \cdot z \leq 1.0679394866726301 \cdot 10^{+297}:\\
\;\;\;\;-0.5 \cdot \left(\frac{z \cdot z}{y} - t_0\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot 0.5\\


\end{array}
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma (/ x y) x y)))
   (if (<= (* z z) 1.0679394866726301e+297)
     (* -0.5 (- (/ (* z z) y) t_0))
     (* t_0 0.5))))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
double code(double x, double y, double z) {
	double t_0 = fma((x / y), x, y);
	double tmp;
	if ((z * z) <= 1.0679394866726301e+297) {
		tmp = -0.5 * (((z * z) / y) - t_0);
	} else {
		tmp = t_0 * 0.5;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original28.1
Target0.2
Herbie3.8
\[y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right) \]

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.0679394866726301e297

    1. Initial program 23.9

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Simplified6.8

      \[\leadsto \color{blue}{-0.5 \cdot \left(\frac{z \cdot z - x \cdot x}{y} - y\right)} \]
    3. Applied div-sub_binary646.8

      \[\leadsto -0.5 \cdot \left(\color{blue}{\left(\frac{z \cdot z}{y} - \frac{x \cdot x}{y}\right)} - y\right) \]
    4. Applied associate--l-_binary646.8

      \[\leadsto -0.5 \cdot \color{blue}{\left(\frac{z \cdot z}{y} - \left(\frac{x \cdot x}{y} + y\right)\right)} \]
    5. Simplified0.7

      \[\leadsto -0.5 \cdot \left(\frac{z \cdot z}{y} - \color{blue}{\mathsf{fma}\left(\frac{x}{y}, x, y\right)}\right) \]

    if 1.0679394866726301e297 < (*.f64 z z)

    1. Initial program 62.0

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Simplified59.2

      \[\leadsto \color{blue}{-0.5 \cdot \left(\frac{z \cdot z - x \cdot x}{y} - y\right)} \]
    3. Taylor expanded in z around 0 37.5

      \[\leadsto -0.5 \cdot \color{blue}{\left(-1 \cdot \left(y + \frac{{x}^{2}}{y}\right)\right)} \]
    4. Simplified29.5

      \[\leadsto -0.5 \cdot \color{blue}{\left(-\mathsf{fma}\left(\frac{x}{y}, x, y\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 1.0679394866726301 \cdot 10^{+297}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z \cdot z}{y} - \mathsf{fma}\left(\frac{x}{y}, x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, x, y\right) \cdot 0.5\\ \end{array} \]

Reproduce

herbie shell --seed 2021215 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :herbie-target
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))