Average Error: 10.3 → 0.5
Time: 20.4s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8953946801625355128083054592 \lor \neg \left(x \le 2.590538009135805678082833971438481635892 \cdot 10^{145}\right):\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z} - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -8953946801625355128083054592 \lor \neg \left(x \le 2.590538009135805678082833971438481635892 \cdot 10^{145}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\

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

\end{array}
double f(double x, double y, double z) {
        double r518535 = x;
        double r518536 = y;
        double r518537 = z;
        double r518538 = r518536 - r518537;
        double r518539 = 1.0;
        double r518540 = r518538 + r518539;
        double r518541 = r518535 * r518540;
        double r518542 = r518541 / r518537;
        return r518542;
}

double f(double x, double y, double z) {
        double r518543 = x;
        double r518544 = -8.953946801625355e+27;
        bool r518545 = r518543 <= r518544;
        double r518546 = 2.5905380091358057e+145;
        bool r518547 = r518543 <= r518546;
        double r518548 = !r518547;
        bool r518549 = r518545 || r518548;
        double r518550 = z;
        double r518551 = r518543 / r518550;
        double r518552 = y;
        double r518553 = 1.0;
        double r518554 = r518552 + r518553;
        double r518555 = r518551 * r518554;
        double r518556 = r518555 - r518543;
        double r518557 = r518543 * r518554;
        double r518558 = r518557 / r518550;
        double r518559 = r518558 - r518543;
        double r518560 = r518549 ? r518556 : r518559;
        return r518560;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.3
Target0.4
Herbie0.5
\[\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 < -8.953946801625355e+27 or 2.5905380091358057e+145 < x

    1. Initial program 33.9

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Taylor expanded around 0 10.9

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

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

    if -8.953946801625355e+27 < x < 2.5905380091358057e+145

    1. Initial program 2.2

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Taylor expanded around 0 0.7

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

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

      \[\leadsto \frac{x}{z} \cdot \color{blue}{{\left(y + 1\right)}^{1}} - x\]
    6. Applied pow12.3

      \[\leadsto \color{blue}{{\left(\frac{x}{z}\right)}^{1}} \cdot {\left(y + 1\right)}^{1} - x\]
    7. Applied pow-prod-down2.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8953946801625355128083054592 \lor \neg \left(x \le 2.590538009135805678082833971438481635892 \cdot 10^{145}\right):\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z} - x\\ \end{array}\]

Reproduce

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