Average Error: 5.9 → 1.3
Time: 7.4s
Precision: binary64
\[x + \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.681862728285677 \cdot 10^{+28}:\\ \;\;\;\;x + \frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{z - t}{\sqrt[3]{a}}\\ \mathbf{elif}\;y \leq 6.996154411165649 \cdot 10^{-88}:\\ \;\;\;\;x + \left(\frac{1}{\frac{a}{y \cdot z}} - \frac{y \cdot t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{z}{a}, -y \cdot \frac{t}{a}\right)\\ \end{array} \]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;y \leq -1.681862728285677 \cdot 10^{+28}:\\
\;\;\;\;x + \frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{z - t}{\sqrt[3]{a}}\\

\mathbf{elif}\;y \leq 6.996154411165649 \cdot 10^{-88}:\\
\;\;\;\;x + \left(\frac{1}{\frac{a}{y \cdot z}} - \frac{y \cdot t}{a}\right)\\

\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(y, \frac{z}{a}, -y \cdot \frac{t}{a}\right)\\


\end{array}
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
(FPCore (x y z t a)
 :precision binary64
 (if (<= y -1.681862728285677e+28)
   (+ x (* (/ y (* (cbrt a) (cbrt a))) (/ (- z t) (cbrt a))))
   (if (<= y 6.996154411165649e-88)
     (+ x (- (/ 1.0 (/ a (* y z))) (/ (* y t) a)))
     (+ x (fma y (/ z a) (- (* y (/ t a))))))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / a);
}
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if (y <= -1.681862728285677e+28) {
		tmp = x + ((y / (cbrt(a) * cbrt(a))) * ((z - t) / cbrt(a)));
	} else if (y <= 6.996154411165649e-88) {
		tmp = x + ((1.0 / (a / (y * z))) - ((y * t) / a));
	} else {
		tmp = x + fma(y, (z / a), -(y * (t / a)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original5.9
Target0.7
Herbie1.3
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.681862728285677e28

    1. Initial program 17.4

      \[x + \frac{y \cdot \left(z - t\right)}{a} \]
    2. Applied add-cube-cbrt_binary6417.9

      \[\leadsto x + \frac{y \cdot \left(z - t\right)}{\color{blue}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}} \]
    3. Applied times-frac_binary642.7

      \[\leadsto x + \color{blue}{\frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{z - t}{\sqrt[3]{a}}} \]

    if -1.681862728285677e28 < y < 6.9961544111656494e-88

    1. Initial program 0.6

      \[x + \frac{y \cdot \left(z - t\right)}{a} \]
    2. Taylor expanded in z around 0 0.6

      \[\leadsto x + \color{blue}{\left(\frac{y \cdot z}{a} - \frac{y \cdot t}{a}\right)} \]
    3. Applied clear-num_binary640.6

      \[\leadsto x + \left(\color{blue}{\frac{1}{\frac{a}{y \cdot z}}} - \frac{y \cdot t}{a}\right) \]
    4. Simplified0.6

      \[\leadsto x + \left(\frac{1}{\color{blue}{\frac{a}{z \cdot y}}} - \frac{y \cdot t}{a}\right) \]

    if 6.9961544111656494e-88 < y

    1. Initial program 9.9

      \[x + \frac{y \cdot \left(z - t\right)}{a} \]
    2. Taylor expanded in z around 0 9.9

      \[\leadsto x + \color{blue}{\left(\frac{y \cdot z}{a} - \frac{y \cdot t}{a}\right)} \]
    3. Applied *-un-lft-identity_binary649.9

      \[\leadsto x + \left(\frac{y \cdot z}{\color{blue}{1 \cdot a}} - \frac{y \cdot t}{a}\right) \]
    4. Applied times-frac_binary646.7

      \[\leadsto x + \left(\color{blue}{\frac{y}{1} \cdot \frac{z}{a}} - \frac{y \cdot t}{a}\right) \]
    5. Applied fma-neg_binary646.7

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(\frac{y}{1}, \frac{z}{a}, -\frac{y \cdot t}{a}\right)} \]
    6. Simplified1.8

      \[\leadsto x + \mathsf{fma}\left(\frac{y}{1}, \frac{z}{a}, \color{blue}{-\frac{t}{a} \cdot y}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.681862728285677 \cdot 10^{+28}:\\ \;\;\;\;x + \frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{z - t}{\sqrt[3]{a}}\\ \mathbf{elif}\;y \leq 6.996154411165649 \cdot 10^{-88}:\\ \;\;\;\;x + \left(\frac{1}{\frac{a}{y \cdot z}} - \frac{y \cdot t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{z}{a}, -y \cdot \frac{t}{a}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
  :precision binary64

  :herbie-target
  (if (< y -1.0761266216389975e-10) (+ x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))

  (+ x (/ (* y (- z t)) a)))