Average Error: 6.3 → 1.4
Time: 3.0s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -4.9168923767645714 \cdot 10^{80}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 2.08730857278766648 \cdot 10^{115}:\\ \;\;\;\;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 -4.9168923767645714 \cdot 10^{80}:\\
\;\;\;\;x + y \cdot \frac{z - t}{a}\\

\mathbf{elif}\;y \cdot \left(z - t\right) \le 2.08730857278766648 \cdot 10^{115}:\\
\;\;\;\;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 r293123 = x;
        double r293124 = y;
        double r293125 = z;
        double r293126 = t;
        double r293127 = r293125 - r293126;
        double r293128 = r293124 * r293127;
        double r293129 = a;
        double r293130 = r293128 / r293129;
        double r293131 = r293123 + r293130;
        return r293131;
}

double f(double x, double y, double z, double t, double a) {
        double r293132 = y;
        double r293133 = z;
        double r293134 = t;
        double r293135 = r293133 - r293134;
        double r293136 = r293132 * r293135;
        double r293137 = -4.916892376764571e+80;
        bool r293138 = r293136 <= r293137;
        double r293139 = x;
        double r293140 = a;
        double r293141 = r293135 / r293140;
        double r293142 = r293132 * r293141;
        double r293143 = r293139 + r293142;
        double r293144 = 2.0873085727876665e+115;
        bool r293145 = r293136 <= r293144;
        double r293146 = r293136 / r293140;
        double r293147 = r293139 + r293146;
        double r293148 = r293132 / r293140;
        double r293149 = fma(r293148, r293135, r293139);
        double r293150 = r293145 ? r293147 : r293149;
        double r293151 = r293138 ? r293143 : r293150;
        return r293151;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.3
Target0.7
Herbie1.4
\[\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)) < -4.916892376764571e+80

    1. Initial program 14.6

      \[x + \frac{y \cdot \left(z - t\right)}{a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity14.6

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

      \[\leadsto x + \color{blue}{\frac{y}{1} \cdot \frac{z - t}{a}}\]
    5. Simplified3.8

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

    if -4.916892376764571e+80 < (* y (- z t)) < 2.0873085727876665e+115

    1. Initial program 0.5

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

    if 2.0873085727876665e+115 < (* y (- z t))

    1. Initial program 18.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -4.9168923767645714 \cdot 10^{80}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 2.08730857278766648 \cdot 10^{115}:\\ \;\;\;\;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 2020046 +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)))