Average Error: 6.1 → 0.5
Time: 2.7s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -6.59417047227896231 \cdot 10^{254}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 5.35794824374080815 \cdot 10^{166}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \end{array}\]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(z - t\right) \le -6.59417047227896231 \cdot 10^{254}:\\
\;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\

\mathbf{elif}\;y \cdot \left(z - t\right) \le 5.35794824374080815 \cdot 10^{166}:\\
\;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r395368 = x;
        double r395369 = y;
        double r395370 = z;
        double r395371 = t;
        double r395372 = r395370 - r395371;
        double r395373 = r395369 * r395372;
        double r395374 = a;
        double r395375 = r395373 / r395374;
        double r395376 = r395368 + r395375;
        return r395376;
}

double f(double x, double y, double z, double t, double a) {
        double r395377 = y;
        double r395378 = z;
        double r395379 = t;
        double r395380 = r395378 - r395379;
        double r395381 = r395377 * r395380;
        double r395382 = -6.594170472278962e+254;
        bool r395383 = r395381 <= r395382;
        double r395384 = x;
        double r395385 = a;
        double r395386 = r395385 / r395380;
        double r395387 = r395377 / r395386;
        double r395388 = r395384 + r395387;
        double r395389 = 5.357948243740808e+166;
        bool r395390 = r395381 <= r395389;
        double r395391 = r395381 / r395385;
        double r395392 = r395384 + r395391;
        double r395393 = r395377 / r395385;
        double r395394 = fma(r395393, r395380, r395384);
        double r395395 = r395390 ? r395392 : r395394;
        double r395396 = r395383 ? r395388 : r395395;
        return r395396;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.1
Target0.7
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y \lt -1.07612662163899753 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y \lt 2.8944268627920891 \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 (- z t)) < -6.594170472278962e+254

    1. Initial program 41.8

      \[x + \frac{y \cdot \left(z - t\right)}{a}\]
    2. Using strategy rm
    3. Applied associate-/l*0.4

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

    if -6.594170472278962e+254 < (* y (- z t)) < 5.357948243740808e+166

    1. Initial program 0.3

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

    if 5.357948243740808e+166 < (* y (- z t))

    1. Initial program 24.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -6.59417047227896231 \cdot 10^{254}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 5.35794824374080815 \cdot 10^{166}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020024 +o rules:numerics
(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 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))

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