Average Error: 6.0 → 0.6
Time: 2.9s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -5.6927132490810346 \cdot 10^{197}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 8.20385041309340159 \cdot 10^{120}:\\ \;\;\;\;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 -5.6927132490810346 \cdot 10^{197}:\\
\;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\

\mathbf{elif}\;y \cdot \left(z - t\right) \le 8.20385041309340159 \cdot 10^{120}:\\
\;\;\;\;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 r249539 = x;
        double r249540 = y;
        double r249541 = z;
        double r249542 = t;
        double r249543 = r249541 - r249542;
        double r249544 = r249540 * r249543;
        double r249545 = a;
        double r249546 = r249544 / r249545;
        double r249547 = r249539 + r249546;
        return r249547;
}

double f(double x, double y, double z, double t, double a) {
        double r249548 = y;
        double r249549 = z;
        double r249550 = t;
        double r249551 = r249549 - r249550;
        double r249552 = r249548 * r249551;
        double r249553 = -5.6927132490810346e+197;
        bool r249554 = r249552 <= r249553;
        double r249555 = x;
        double r249556 = a;
        double r249557 = r249556 / r249551;
        double r249558 = r249548 / r249557;
        double r249559 = r249555 + r249558;
        double r249560 = 8.203850413093402e+120;
        bool r249561 = r249552 <= r249560;
        double r249562 = r249552 / r249556;
        double r249563 = r249555 + r249562;
        double r249564 = r249548 / r249556;
        double r249565 = fma(r249564, r249551, r249555);
        double r249566 = r249561 ? r249563 : r249565;
        double r249567 = r249554 ? r249559 : r249566;
        return r249567;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.0
Target0.7
Herbie0.6
\[\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)) < -5.6927132490810346e+197

    1. Initial program 27.5

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

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

    if -5.6927132490810346e+197 < (* y (- z t)) < 8.203850413093402e+120

    1. Initial program 0.3

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

    if 8.203850413093402e+120 < (* y (- z t))

    1. Initial program 17.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -5.6927132490810346 \cdot 10^{197}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 8.20385041309340159 \cdot 10^{120}:\\ \;\;\;\;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 2020027 +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)))