Average Error: 10.3 → 0.5
Time: 19.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 r453348 = x;
        double r453349 = y;
        double r453350 = z;
        double r453351 = r453349 - r453350;
        double r453352 = 1.0;
        double r453353 = r453351 + r453352;
        double r453354 = r453348 * r453353;
        double r453355 = r453354 / r453350;
        return r453355;
}

double f(double x, double y, double z) {
        double r453356 = x;
        double r453357 = -8.953946801625355e+27;
        bool r453358 = r453356 <= r453357;
        double r453359 = 2.5905380091358057e+145;
        bool r453360 = r453356 <= r453359;
        double r453361 = !r453360;
        bool r453362 = r453358 || r453361;
        double r453363 = z;
        double r453364 = r453356 / r453363;
        double r453365 = y;
        double r453366 = 1.0;
        double r453367 = r453365 + r453366;
        double r453368 = r453364 * r453367;
        double r453369 = r453368 - r453356;
        double r453370 = r453356 * r453367;
        double r453371 = r453370 / r453363;
        double r453372 = r453371 - r453356;
        double r453373 = r453362 ? r453369 : r453372;
        return r453373;
}

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. Taylor expanded around 0 0.7

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

      \[\leadsto \color{blue}{\frac{x \cdot \left(y + 1\right)}{z}} - 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))