Average Error: 10.7 → 0.6
Time: 14.1s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.665185119660453336993150082260987152155 \cdot 10^{-188}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, 1, \frac{y}{\frac{z}{x}}\right) - x\\ \mathbf{elif}\;x \le 1.213611178447867364643526562912545374463 \cdot 10^{-194}:\\ \;\;\;\;\frac{1}{z} \cdot \left(x \cdot \left(\left(y - z\right) + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, 1, \frac{y}{\frac{z}{x}}\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -4.665185119660453336993150082260987152155 \cdot 10^{-188}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, 1, \frac{y}{\frac{z}{x}}\right) - x\\

\mathbf{elif}\;x \le 1.213611178447867364643526562912545374463 \cdot 10^{-194}:\\
\;\;\;\;\frac{1}{z} \cdot \left(x \cdot \left(\left(y - z\right) + 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r24897518 = x;
        double r24897519 = y;
        double r24897520 = z;
        double r24897521 = r24897519 - r24897520;
        double r24897522 = 1.0;
        double r24897523 = r24897521 + r24897522;
        double r24897524 = r24897518 * r24897523;
        double r24897525 = r24897524 / r24897520;
        return r24897525;
}

double f(double x, double y, double z) {
        double r24897526 = x;
        double r24897527 = -4.6651851196604533e-188;
        bool r24897528 = r24897526 <= r24897527;
        double r24897529 = z;
        double r24897530 = r24897526 / r24897529;
        double r24897531 = 1.0;
        double r24897532 = y;
        double r24897533 = r24897529 / r24897526;
        double r24897534 = r24897532 / r24897533;
        double r24897535 = fma(r24897530, r24897531, r24897534);
        double r24897536 = r24897535 - r24897526;
        double r24897537 = 1.2136111784478674e-194;
        bool r24897538 = r24897526 <= r24897537;
        double r24897539 = 1.0;
        double r24897540 = r24897539 / r24897529;
        double r24897541 = r24897532 - r24897529;
        double r24897542 = r24897541 + r24897531;
        double r24897543 = r24897526 * r24897542;
        double r24897544 = r24897540 * r24897543;
        double r24897545 = r24897538 ? r24897544 : r24897536;
        double r24897546 = r24897528 ? r24897536 : r24897545;
        return r24897546;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.7
Target0.4
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;x \lt -2.714831067134359919650240696134672137284 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.874108816439546156869494499878029491333 \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 < -4.6651851196604533e-188 or 1.2136111784478674e-194 < x

    1. Initial program 14.0

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

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

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

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

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

    if -4.6651851196604533e-188 < x < 1.2136111784478674e-194

    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.0

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

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

      \[\leadsto \frac{1}{\frac{\frac{z}{\left(y - z\right) + 1}}{\color{blue}{1 \cdot x}}}\]
    8. Applied div-inv7.2

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

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

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

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

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

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

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

Reproduce

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

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

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