Average Error: 6.5 → 1.6
Time: 6.6s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;z \le -9.0264403633635939 \cdot 10^{-299}:\\ \;\;\;\;\left(\frac{z \cdot y}{t} - \frac{x \cdot z}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r2590 = x;
        double r2591 = y;
        double r2592 = r2591 - r2590;
        double r2593 = z;
        double r2594 = r2592 * r2593;
        double r2595 = t;
        double r2596 = r2594 / r2595;
        double r2597 = r2590 + r2596;
        return r2597;
}

double f(double x, double y, double z, double t) {
        double r2598 = z;
        double r2599 = -5.409344260818823e-20;
        bool r2600 = r2598 <= r2599;
        double r2601 = y;
        double r2602 = x;
        double r2603 = r2601 - r2602;
        double r2604 = t;
        double r2605 = r2603 / r2604;
        double r2606 = fma(r2605, r2598, r2602);
        double r2607 = -9.026440363363594e-299;
        bool r2608 = r2598 <= r2607;
        double r2609 = r2598 * r2601;
        double r2610 = r2609 / r2604;
        double r2611 = r2602 * r2598;
        double r2612 = r2611 / r2604;
        double r2613 = r2610 - r2612;
        double r2614 = r2613 + r2602;
        double r2615 = 1.0;
        double r2616 = r2598 / r2604;
        double r2617 = fma(r2616, r2603, r2602);
        double r2618 = r2615 * r2617;
        double r2619 = r2608 ? r2614 : r2618;
        double r2620 = r2600 ? r2606 : r2619;
        return r2620;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.5
Target1.9
Herbie1.6
\[\begin{array}{l} \mathbf{if}\;x \lt -9.0255111955330046 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x \lt 4.2750321637007147 \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 z < -5.409344260818823e-20

    1. Initial program 13.9

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

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

    if -5.409344260818823e-20 < z < -9.026440363363594e-299

    1. Initial program 1.2

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{t}{y - x}}}, z, x\right)\]
    5. Using strategy rm
    6. Applied fma-udef9.7

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

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Taylor expanded around 0 1.2

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

    if -9.026440363363594e-299 < z

    1. Initial program 6.2

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{t}{y - x}}}, z, x\right)\]
    5. Using strategy rm
    6. Applied fma-udef7.4

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

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Using strategy rm
    9. Applied *-un-lft-identity6.7

      \[\leadsto \frac{z}{\frac{t}{y - x}} + \color{blue}{1 \cdot x}\]
    10. Applied *-un-lft-identity6.7

      \[\leadsto \color{blue}{1 \cdot \frac{z}{\frac{t}{y - x}}} + 1 \cdot x\]
    11. Applied distribute-lft-out6.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;z \le -9.0264403633635939 \cdot 10^{-299}:\\ \;\;\;\;\left(\frac{z \cdot y}{t} - \frac{x \cdot z}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \end{array}\]

Reproduce

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