Average Error: 28.8 → 0.1
Time: 14.5s
Precision: binary64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
\[-0.5 \cdot \left(\mathsf{fma}\left(z + x, \frac{z - x}{y}, -y\right) + \mathsf{fma}\left(-y, 1, y\right)\right) \]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
-0.5 \cdot \left(\mathsf{fma}\left(z + x, \frac{z - x}{y}, -y\right) + \mathsf{fma}\left(-y, 1, y\right)\right)
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
(FPCore (x y z)
 :precision binary64
 (* -0.5 (+ (fma (+ z x) (/ (- z x) y) (- y)) (fma (- y) 1.0 y))))
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) {
	return -0.5 * (fma((z + x), ((z - x) / y), -y) + fma(-y, 1.0, y));
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Initial program 28.8

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

    \[\leadsto \color{blue}{-0.5 \cdot \left(\frac{z \cdot z - x \cdot x}{y} - y\right)} \]
  3. Applied *-un-lft-identity_binary6413.4

    \[\leadsto -0.5 \cdot \left(\frac{z \cdot z - x \cdot x}{y} - \color{blue}{1 \cdot y}\right) \]
  4. Applied *-un-lft-identity_binary6413.4

    \[\leadsto -0.5 \cdot \left(\frac{z \cdot z - x \cdot x}{\color{blue}{1 \cdot y}} - 1 \cdot y\right) \]
  5. Applied difference-of-squares_binary6413.4

    \[\leadsto -0.5 \cdot \left(\frac{\color{blue}{\left(z + x\right) \cdot \left(z - x\right)}}{1 \cdot y} - 1 \cdot y\right) \]
  6. Applied times-frac_binary640.1

    \[\leadsto -0.5 \cdot \left(\color{blue}{\frac{z + x}{1} \cdot \frac{z - x}{y}} - 1 \cdot y\right) \]
  7. Applied prod-diff_binary640.1

    \[\leadsto -0.5 \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{z + x}{1}, \frac{z - x}{y}, -y \cdot 1\right) + \mathsf{fma}\left(-y, 1, y \cdot 1\right)\right)} \]
  8. Final simplification0.1

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

Reproduce

herbie shell --seed 2021307 
(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)))