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 r670690 = x;
        double r670691 = y;
        double r670692 = z;
        double r670693 = r670691 - r670692;
        double r670694 = 1.0;
        double r670695 = r670693 + r670694;
        double r670696 = r670690 * r670695;
        double r670697 = r670696 / r670692;
        return r670697;
}

double f(double x, double y, double z) {
        double r670698 = x;
        double r670699 = -6.646625143676237e-189;
        bool r670700 = r670698 <= r670699;
        double r670701 = 2.125153105609533e-223;
        bool r670702 = r670698 <= r670701;
        double r670703 = !r670702;
        bool r670704 = r670700 || r670703;
        double r670705 = z;
        double r670706 = r670698 / r670705;
        double r670707 = y;
        double r670708 = 1.0;
        double r670709 = r670708 * r670706;
        double r670710 = r670709 - r670698;
        double r670711 = fma(r670706, r670707, r670710);
        double r670712 = 1.0;
        double r670713 = cbrt(r670712);
        double r670714 = r670713 * r670713;
        double r670715 = r670714 / r670705;
        double r670716 = r670707 - r670705;
        double r670717 = r670716 + r670708;
        double r670718 = r670713 * r670698;
        double r670719 = r670717 * r670718;
        double r670720 = r670715 * r670719;
        double r670721 = r670704 ? r670711 : r670720;
        return r670721;
}

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))