Average Error: 6.7 → 2.0
Time: 3.2s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.07053695690361482 \cdot 10^{-168} \lor \neg \left(x \le 1.92427481921363205 \cdot 10^{-122}\right):\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{t}{y - x}}{z}} + x\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x \le -1.07053695690361482 \cdot 10^{-168} \lor \neg \left(x \le 1.92427481921363205 \cdot 10^{-122}\right):\\
\;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{t}{y - x}}{z}} + x\\

\end{array}
double f(double x, double y, double z, double t) {
        double r427183 = x;
        double r427184 = y;
        double r427185 = r427184 - r427183;
        double r427186 = z;
        double r427187 = r427185 * r427186;
        double r427188 = t;
        double r427189 = r427187 / r427188;
        double r427190 = r427183 + r427189;
        return r427190;
}

double f(double x, double y, double z, double t) {
        double r427191 = x;
        double r427192 = -1.0705369569036148e-168;
        bool r427193 = r427191 <= r427192;
        double r427194 = 1.924274819213632e-122;
        bool r427195 = r427191 <= r427194;
        double r427196 = !r427195;
        bool r427197 = r427193 || r427196;
        double r427198 = 1.0;
        double r427199 = z;
        double r427200 = t;
        double r427201 = r427199 / r427200;
        double r427202 = y;
        double r427203 = r427202 - r427191;
        double r427204 = fma(r427201, r427203, r427191);
        double r427205 = r427198 * r427204;
        double r427206 = r427200 / r427203;
        double r427207 = r427206 / r427199;
        double r427208 = r427198 / r427207;
        double r427209 = r427208 + r427191;
        double r427210 = r427197 ? r427205 : r427209;
        return r427210;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.7
Target1.9
Herbie2.0
\[\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 2 regimes
  2. if x < -1.0705369569036148e-168 or 1.924274819213632e-122 < x

    1. Initial program 7.4

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

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

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

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

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

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

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

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

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

    if -1.0705369569036148e-168 < x < 1.924274819213632e-122

    1. Initial program 5.2

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

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

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

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

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Using strategy rm
    9. Applied clear-num5.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.07053695690361482 \cdot 10^{-168} \lor \neg \left(x \le 1.92427481921363205 \cdot 10^{-122}\right):\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{t}{y - x}}{z}} + x\\ \end{array}\]

Reproduce

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