Average Error: 10.3 → 0.6
Time: 3.5s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.6466251436762367 \cdot 10^{-189} \lor \neg \left(x \le 2.1251531056095331 \cdot 10^{-223}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1 \cdot \frac{x}{z} - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z} \cdot \left(\left(\left(y - z\right) + 1\right) \cdot \left(\sqrt[3]{1} \cdot x\right)\right)\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -6.6466251436762367 \cdot 10^{-189} \lor \neg \left(x \le 2.1251531056095331 \cdot 10^{-223}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1 \cdot \frac{x}{z} - x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z} \cdot \left(\left(\left(y - z\right) + 1\right) \cdot \left(\sqrt[3]{1} \cdot x\right)\right)\\

\end{array}
double f(double x, double y, double z) {
        double r571309 = x;
        double r571310 = y;
        double r571311 = z;
        double r571312 = r571310 - r571311;
        double r571313 = 1.0;
        double r571314 = r571312 + r571313;
        double r571315 = r571309 * r571314;
        double r571316 = r571315 / r571311;
        return r571316;
}

double f(double x, double y, double z) {
        double r571317 = x;
        double r571318 = -6.646625143676237e-189;
        bool r571319 = r571317 <= r571318;
        double r571320 = 2.125153105609533e-223;
        bool r571321 = r571317 <= r571320;
        double r571322 = !r571321;
        bool r571323 = r571319 || r571322;
        double r571324 = z;
        double r571325 = r571317 / r571324;
        double r571326 = y;
        double r571327 = 1.0;
        double r571328 = r571327 * r571325;
        double r571329 = r571328 - r571317;
        double r571330 = fma(r571325, r571326, r571329);
        double r571331 = 1.0;
        double r571332 = cbrt(r571331);
        double r571333 = r571332 * r571332;
        double r571334 = r571333 / r571324;
        double r571335 = r571326 - r571324;
        double r571336 = r571335 + r571327;
        double r571337 = r571332 * r571317;
        double r571338 = r571336 * r571337;
        double r571339 = r571334 * r571338;
        double r571340 = r571323 ? r571330 : r571339;
        return r571340;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.3
Target0.4
Herbie0.6
\[\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 x < -6.646625143676237e-189 or 2.125153105609533e-223 < x

    1. Initial program 12.9

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Using strategy rm
    5. Applied clear-num2.4

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{\left(y - z\right) + 1}}{x}}}\]
    6. Using strategy rm
    7. Applied div-inv2.5

      \[\leadsto \frac{1}{\color{blue}{\frac{z}{\left(y - z\right) + 1} \cdot \frac{1}{x}}}\]
    8. Applied add-cube-cbrt2.5

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

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

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

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

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

    if -6.646625143676237e-189 < x < 2.125153105609533e-223

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Using strategy rm
    5. Applied clear-num7.5

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{\left(y - z\right) + 1}}{x}}}\]
    6. Using strategy rm
    7. Applied div-inv7.6

      \[\leadsto \frac{1}{\color{blue}{\frac{z}{\left(y - z\right) + 1} \cdot \frac{1}{x}}}\]
    8. Applied add-cube-cbrt7.6

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{z}{\left(y - z\right) + 1}} \cdot \frac{\sqrt[3]{1}}{\frac{1}{x}}}\]
    10. Simplified7.9

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{z}{\left(y - z\right) + 1}} \cdot \color{blue}{\left(\sqrt[3]{1} \cdot x\right)}\]
    11. Using strategy rm
    12. Applied associate-/r/7.9

      \[\leadsto \color{blue}{\left(\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z} \cdot \left(\left(y - z\right) + 1\right)\right)} \cdot \left(\sqrt[3]{1} \cdot x\right)\]
    13. Applied associate-*l*0.3

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z} \cdot \left(\left(\left(y - z\right) + 1\right) \cdot \left(\sqrt[3]{1} \cdot x\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.6466251436762367 \cdot 10^{-189} \lor \neg \left(x \le 2.1251531056095331 \cdot 10^{-223}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1 \cdot \frac{x}{z} - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z} \cdot \left(\left(\left(y - z\right) + 1\right) \cdot \left(\sqrt[3]{1} \cdot x\right)\right)\\ \end{array}\]

Reproduce

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