Average Error: 6.0 → 1.1
Time: 9.5s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.21580676764020581 \cdot 10^{38}:\\ \;\;\;\;\frac{z - t}{\frac{a}{y}} + x\\ \mathbf{elif}\;y \le 2.3757587408965584 \cdot 10^{-14}:\\ \;\;\;\;\left(\frac{z \cdot y}{a} - \frac{t \cdot y}{a}\right) + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\ \end{array}\]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;y \le -1.21580676764020581 \cdot 10^{38}:\\
\;\;\;\;\frac{z - t}{\frac{a}{y}} + x\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r365233 = x;
        double r365234 = y;
        double r365235 = z;
        double r365236 = t;
        double r365237 = r365235 - r365236;
        double r365238 = r365234 * r365237;
        double r365239 = a;
        double r365240 = r365238 / r365239;
        double r365241 = r365233 + r365240;
        return r365241;
}

double f(double x, double y, double z, double t, double a) {
        double r365242 = y;
        double r365243 = -1.2158067676402058e+38;
        bool r365244 = r365242 <= r365243;
        double r365245 = z;
        double r365246 = t;
        double r365247 = r365245 - r365246;
        double r365248 = a;
        double r365249 = r365248 / r365242;
        double r365250 = r365247 / r365249;
        double r365251 = x;
        double r365252 = r365250 + r365251;
        double r365253 = 2.3757587408965584e-14;
        bool r365254 = r365242 <= r365253;
        double r365255 = r365245 * r365242;
        double r365256 = r365255 / r365248;
        double r365257 = r365246 * r365242;
        double r365258 = r365257 / r365248;
        double r365259 = r365256 - r365258;
        double r365260 = r365259 + r365251;
        double r365261 = r365247 / r365248;
        double r365262 = fma(r365242, r365261, r365251);
        double r365263 = r365254 ? r365260 : r365262;
        double r365264 = r365244 ? r365252 : r365263;
        return r365264;
}

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.6
Herbie1.1
\[\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 < -1.2158067676402058e+38

    1. Initial program 17.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef4.4

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - t\right)}{a}} + x\]
    6. Taylor expanded around 0 17.3

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

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

    if -1.2158067676402058e+38 < y < 2.3757587408965584e-14

    1. Initial program 0.5

      \[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. Using strategy rm
    4. Applied fma-udef1.7

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

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

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

      \[\leadsto \color{blue}{\frac{z - t}{\frac{a}{y}}} + x\]
    8. Using strategy rm
    9. Applied div-sub2.0

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

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

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

    if 2.3757587408965584e-14 < y

    1. Initial program 14.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef3.9

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

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

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

      \[\leadsto \color{blue}{\frac{y}{1} \cdot \frac{z - t}{a}} + x\]
    9. Applied fma-def0.6

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

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

Reproduce

herbie shell --seed 2020042 +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)))