Average Error: 6.6 → 2.5
Time: 2.7s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;t \le -1.229651158615936528983347561392124591292 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;t \le 1.625406329571911990929648461559105916592 \cdot 10^{-217}:\\ \;\;\;\;x + \frac{1}{t} \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{z}{\sqrt[3]{t}}\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;t \le -1.229651158615936528983347561392124591292 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\

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

\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{z}{\sqrt[3]{t}}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r430361 = x;
        double r430362 = y;
        double r430363 = r430362 - r430361;
        double r430364 = z;
        double r430365 = r430363 * r430364;
        double r430366 = t;
        double r430367 = r430365 / r430366;
        double r430368 = r430361 + r430367;
        return r430368;
}

double f(double x, double y, double z, double t) {
        double r430369 = t;
        double r430370 = -1.2296511586159365e-21;
        bool r430371 = r430369 <= r430370;
        double r430372 = y;
        double r430373 = x;
        double r430374 = r430372 - r430373;
        double r430375 = r430374 / r430369;
        double r430376 = z;
        double r430377 = fma(r430375, r430376, r430373);
        double r430378 = 1.625406329571912e-217;
        bool r430379 = r430369 <= r430378;
        double r430380 = 1.0;
        double r430381 = r430380 / r430369;
        double r430382 = r430374 * r430376;
        double r430383 = r430381 * r430382;
        double r430384 = r430373 + r430383;
        double r430385 = cbrt(r430369);
        double r430386 = r430385 * r430385;
        double r430387 = r430374 / r430386;
        double r430388 = r430376 / r430385;
        double r430389 = r430387 * r430388;
        double r430390 = r430373 + r430389;
        double r430391 = r430379 ? r430384 : r430390;
        double r430392 = r430371 ? r430377 : r430391;
        return r430392;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.6
Target2.0
Herbie2.5
\[\begin{array}{l} \mathbf{if}\;x \lt -9.025511195533004570453352523209034680317 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x \lt 4.275032163700714748507147332551979944314 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if t < -1.2296511586159365e-21

    1. Initial program 9.1

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

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

    if -1.2296511586159365e-21 < t < 1.625406329571912e-217

    1. Initial program 2.0

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Using strategy rm
    3. Applied associate-/l*3.8

      \[\leadsto x + \color{blue}{\frac{y - x}{\frac{t}{z}}}\]
    4. Using strategy rm
    5. Applied div-inv3.9

      \[\leadsto x + \frac{y - x}{\color{blue}{t \cdot \frac{1}{z}}}\]
    6. Applied *-un-lft-identity3.9

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

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

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

    if 1.625406329571912e-217 < t

    1. Initial program 6.8

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt7.2

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

      \[\leadsto x + \color{blue}{\frac{y - x}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{z}{\sqrt[3]{t}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \le -1.229651158615936528983347561392124591292 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;t \le 1.625406329571911990929648461559105916592 \cdot 10^{-217}:\\ \;\;\;\;x + \frac{1}{t} \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{z}{\sqrt[3]{t}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020001 +o rules:numerics
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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