Average Error: 10.4 → 1.9
Time: 4.0s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.03093838410670302 \cdot 10^{-10}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{x}{z}, \frac{x \cdot y}{z}\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \le -1.03093838410670302 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r649184 = x;
        double r649185 = y;
        double r649186 = z;
        double r649187 = r649185 - r649186;
        double r649188 = 1.0;
        double r649189 = r649187 + r649188;
        double r649190 = r649184 * r649189;
        double r649191 = r649190 / r649186;
        return r649191;
}

double f(double x, double y, double z) {
        double r649192 = z;
        double r649193 = -1.030938384106703e-10;
        bool r649194 = r649192 <= r649193;
        double r649195 = x;
        double r649196 = y;
        double r649197 = r649196 - r649192;
        double r649198 = 1.0;
        double r649199 = r649197 + r649198;
        double r649200 = r649192 / r649199;
        double r649201 = r649195 / r649200;
        double r649202 = r649195 / r649192;
        double r649203 = r649195 * r649196;
        double r649204 = r649203 / r649192;
        double r649205 = fma(r649198, r649202, r649204);
        double r649206 = r649205 - r649195;
        double r649207 = r649194 ? r649201 : r649206;
        return r649207;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.4
Target0.4
Herbie1.9
\[\begin{array}{l} \mathbf{if}\;x \lt -2.7148310671343599 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.87410881643954616 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -1.030938384106703e-10

    1. Initial program 16.6

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

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

    if -1.030938384106703e-10 < z

    1. Initial program 7.5

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity7.5

      \[\leadsto \frac{x \cdot \left(\left(y - z\right) + 1\right)}{\color{blue}{1 \cdot z}}\]
    4. Applied times-frac5.0

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

      \[\leadsto \color{blue}{x} \cdot \frac{\left(y - z\right) + 1}{z}\]
    6. Taylor expanded around 0 2.7

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

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

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

Reproduce

herbie shell --seed 2020036 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1)) (/ 1 z)) (- (* (+ 1 y) (/ x z)) x)))

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