Average Error: 6.7 → 1.1
Time: 18.8s
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} \le -2.72790853210520445783593734651044130646 \cdot 10^{251}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{elif}\;x + \frac{\left(z - x\right) \cdot y}{t} \le 6.41978194333992067450854588504563580042 \cdot 10^{300}:\\ \;\;\;\;x + \frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, 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} \le -2.72790853210520445783593734651044130646 \cdot 10^{251}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r16518210 = x;
        double r16518211 = y;
        double r16518212 = z;
        double r16518213 = r16518212 - r16518210;
        double r16518214 = r16518211 * r16518213;
        double r16518215 = t;
        double r16518216 = r16518214 / r16518215;
        double r16518217 = r16518210 + r16518216;
        return r16518217;
}

double f(double x, double y, double z, double t) {
        double r16518218 = x;
        double r16518219 = z;
        double r16518220 = r16518219 - r16518218;
        double r16518221 = y;
        double r16518222 = r16518220 * r16518221;
        double r16518223 = t;
        double r16518224 = r16518222 / r16518223;
        double r16518225 = r16518218 + r16518224;
        double r16518226 = -2.7279085321052045e+251;
        bool r16518227 = r16518225 <= r16518226;
        double r16518228 = r16518221 / r16518223;
        double r16518229 = fma(r16518228, r16518220, r16518218);
        double r16518230 = 6.419781943339921e+300;
        bool r16518231 = r16518225 <= r16518230;
        double r16518232 = r16518220 / r16518223;
        double r16518233 = fma(r16518232, r16518221, r16518218);
        double r16518234 = r16518231 ? r16518225 : r16518233;
        double r16518235 = r16518227 ? r16518229 : r16518234;
        return r16518235;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.7
Target1.9
Herbie1.1
\[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)) < -2.7279085321052045e+251

    1. Initial program 31.1

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

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

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

    if -2.7279085321052045e+251 < (+ x (/ (* y (- z x)) t)) < 6.419781943339921e+300

    1. Initial program 0.8

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

    if 6.419781943339921e+300 < (+ x (/ (* y (- z x)) t))

    1. Initial program 56.1

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

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

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

Reproduce

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