Average Error: 11.1 → 2.1
Time: 2.8s
Precision: binary64
\[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -4.3802569374033836 \cdot 10^{-153} \lor \neg \left(z \leq 1.1593343701556162 \cdot 10^{-211}\right):\\ \;\;\;\;x - \frac{y}{z - \frac{y \cdot t}{z \cdot 2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{z}{t}, x\right)\\ \end{array} \]
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\begin{array}{l}
\mathbf{if}\;z \leq -4.3802569374033836 \cdot 10^{-153} \lor \neg \left(z \leq 1.1593343701556162 \cdot 10^{-211}\right):\\
\;\;\;\;x - \frac{y}{z - \frac{y \cdot t}{z \cdot 2}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{z}{t}, x\right)\\


\end{array}
(FPCore (x y z t)
 :precision binary64
 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -4.3802569374033836e-153) (not (<= z 1.1593343701556162e-211)))
   (- x (/ y (- z (/ (* y t) (* z 2.0)))))
   (fma 2.0 (/ z t) x)))
double code(double x, double y, double z, double t) {
	return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -4.3802569374033836e-153) || !(z <= 1.1593343701556162e-211)) {
		tmp = x - (y / (z - ((y * t) / (z * 2.0))));
	} else {
		tmp = fma(2.0, (z / t), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original11.1
Target0.1
Herbie2.1
\[x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}} \]

Derivation

  1. Split input into 2 regimes
  2. if z < -4.3802569374033836e-153 or 1.15933437015561615e-211 < z

    1. Initial program 11.8

      \[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
    2. Simplified2.3

      \[\leadsto \color{blue}{x - \frac{y}{z - \frac{y \cdot t}{2 \cdot z}}} \]

    if -4.3802569374033836e-153 < z < 1.15933437015561615e-211

    1. Initial program 8.3

      \[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
    2. Simplified4.7

      \[\leadsto \color{blue}{x - \frac{y}{z - \frac{y \cdot t}{2 \cdot z}}} \]
    3. Taylor expanded in y around inf 1.1

      \[\leadsto \color{blue}{2 \cdot \frac{z}{t} + x} \]
    4. Simplified1.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{z}{t}, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.3802569374033836 \cdot 10^{-153} \lor \neg \left(z \leq 1.1593343701556162 \cdot 10^{-211}\right):\\ \;\;\;\;x - \frac{y}{z - \frac{y \cdot t}{z \cdot 2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{z}{t}, x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021313 
(FPCore (x y z t)
  :name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
  :precision binary64

  :herbie-target
  (- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))

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