Average Error: 4.1 → 1.1
Time: 4.5s
Precision: binary64
\[x + \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq -2.573071024185118 \cdot 10^{+147} \lor \neg \left(t_1 \leq -2.3756858379986747 \cdot 10^{-71}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t_1}{a}\\ \end{array} \]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
\mathbf{if}\;t_1 \leq -2.573071024185118 \cdot 10^{+147} \lor \neg \left(t_1 \leq -2.3756858379986747 \cdot 10^{-71}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \frac{t_1}{a}\\


\end{array}
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (* y (- z t))))
   (if (or (<= t_1 -2.573071024185118e+147)
           (not (<= t_1 -2.3756858379986747e-71)))
     (fma (/ y a) (- z t) x)
     (+ x (/ t_1 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 t_1 = y * (z - t);
	double tmp;
	if ((t_1 <= -2.573071024185118e+147) || !(t_1 <= -2.3756858379986747e-71)) {
		tmp = fma((y / a), (z - t), x);
	} else {
		tmp = x + (t_1 / 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

Original4.1
Target0.6
Herbie1.1
\[\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 2 regimes
  2. if (*.f64 y (-.f64 z t)) < -2.573071024185118e147 or -2.37568583799867472e-71 < (*.f64 y (-.f64 z t))

    1. Initial program 4.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)} \]
    3. Taylor expanded in y around 0 8.6

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

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

    if -2.573071024185118e147 < (*.f64 y (-.f64 z t)) < -2.37568583799867472e-71

    1. Initial program 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \leq -2.573071024185118 \cdot 10^{+147} \lor \neg \left(y \cdot \left(z - t\right) \leq -2.3756858379986747 \cdot 10^{-71}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \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)))