Average Error: 5.9 → 0.8
Time: 17.3s
Precision: 64
\[x + \frac{y \cdot \left(z - x\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;x + \frac{\left(z - x\right) \cdot y}{t} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\ \mathbf{elif}\;x + \frac{\left(z - x\right) \cdot y}{t} \le 1.3995432143967562 \cdot 10^{+297}:\\ \;\;\;\;x + \frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \end{array}\]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;x + \frac{\left(z - x\right) \cdot y}{t} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r17819474 = x;
        double r17819475 = y;
        double r17819476 = z;
        double r17819477 = r17819476 - r17819474;
        double r17819478 = r17819475 * r17819477;
        double r17819479 = t;
        double r17819480 = r17819478 / r17819479;
        double r17819481 = r17819474 + r17819480;
        return r17819481;
}

double f(double x, double y, double z, double t) {
        double r17819482 = x;
        double r17819483 = z;
        double r17819484 = r17819483 - r17819482;
        double r17819485 = y;
        double r17819486 = r17819484 * r17819485;
        double r17819487 = t;
        double r17819488 = r17819486 / r17819487;
        double r17819489 = r17819482 + r17819488;
        double r17819490 = -inf.0;
        bool r17819491 = r17819489 <= r17819490;
        double r17819492 = r17819484 / r17819487;
        double r17819493 = fma(r17819492, r17819485, r17819482);
        double r17819494 = 1.3995432143967562e+297;
        bool r17819495 = r17819489 <= r17819494;
        double r17819496 = r17819485 / r17819487;
        double r17819497 = fma(r17819496, r17819484, r17819482);
        double r17819498 = r17819495 ? r17819489 : r17819497;
        double r17819499 = r17819491 ? r17819493 : r17819498;
        return r17819499;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.9
Target2.0
Herbie0.8
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)\]

Derivation

  1. Split input into 3 regimes
  2. if (+ x (/ (* y (- z x)) t)) < -inf.0

    1. Initial program 60.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)}\]

    if -inf.0 < (+ x (/ (* y (- z x)) t)) < 1.3995432143967562e+297

    1. Initial program 0.8

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

    if 1.3995432143967562e+297 < (+ x (/ (* y (- z x)) t))

    1. Initial program 49.0

      \[x + \frac{y \cdot \left(z - x\right)}{t}\]
    2. Taylor expanded around 0 49.0

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

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

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

Reproduce

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

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

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