Average Error: 5.5 → 0.5
Time: 19.6s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;\left(z - t\right) \cdot y = -\infty:\\ \;\;\;\;x + \frac{z - t}{a} \cdot y\\ \mathbf{elif}\;\left(z - t\right) \cdot y \le 4.602631262379337 \cdot 10^{+178}:\\ \;\;\;\;\frac{\left(z - t\right) \cdot y}{a} + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a}, x\right)\\ \end{array}\]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;\left(z - t\right) \cdot y = -\infty:\\
\;\;\;\;x + \frac{z - t}{a} \cdot y\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r14916027 = x;
        double r14916028 = y;
        double r14916029 = z;
        double r14916030 = t;
        double r14916031 = r14916029 - r14916030;
        double r14916032 = r14916028 * r14916031;
        double r14916033 = a;
        double r14916034 = r14916032 / r14916033;
        double r14916035 = r14916027 + r14916034;
        return r14916035;
}

double f(double x, double y, double z, double t, double a) {
        double r14916036 = z;
        double r14916037 = t;
        double r14916038 = r14916036 - r14916037;
        double r14916039 = y;
        double r14916040 = r14916038 * r14916039;
        double r14916041 = -inf.0;
        bool r14916042 = r14916040 <= r14916041;
        double r14916043 = x;
        double r14916044 = a;
        double r14916045 = r14916038 / r14916044;
        double r14916046 = r14916045 * r14916039;
        double r14916047 = r14916043 + r14916046;
        double r14916048 = 4.602631262379337e+178;
        bool r14916049 = r14916040 <= r14916048;
        double r14916050 = r14916040 / r14916044;
        double r14916051 = r14916050 + r14916043;
        double r14916052 = r14916039 / r14916044;
        double r14916053 = fma(r14916038, r14916052, r14916043);
        double r14916054 = r14916049 ? r14916051 : r14916053;
        double r14916055 = r14916042 ? r14916047 : r14916054;
        return r14916055;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original5.5
Target0.7
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y \lt -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y \lt 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 3 regimes
  2. if (* y (- z t)) < -inf.0

    1. Initial program 60.2

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

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

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

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

    if -inf.0 < (* y (- z t)) < 4.602631262379337e+178

    1. Initial program 0.4

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

    if 4.602631262379337e+178 < (* y (- z t))

    1. Initial program 23.3

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

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

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

Reproduce

herbie shell --seed 2019158 +o rules:numerics
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"

  :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)))