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 r450320 = x;
        double r450321 = y;
        double r450322 = z;
        double r450323 = r450321 - r450322;
        double r450324 = 1.0;
        double r450325 = r450323 + r450324;
        double r450326 = r450320 * r450325;
        double r450327 = r450326 / r450322;
        return r450327;
}

double f(double x, double y, double z) {
        double r450328 = x;
        double r450329 = -8.953946801625355e+27;
        bool r450330 = r450328 <= r450329;
        double r450331 = 2.5905380091358057e+145;
        bool r450332 = r450328 <= r450331;
        double r450333 = !r450332;
        bool r450334 = r450330 || r450333;
        double r450335 = z;
        double r450336 = r450328 / r450335;
        double r450337 = y;
        double r450338 = 1.0;
        double r450339 = r450337 + r450338;
        double r450340 = r450336 * r450339;
        double r450341 = r450340 - r450328;
        double r450342 = r450328 * r450339;
        double r450343 = r450342 / r450335;
        double r450344 = r450343 - r450328;
        double r450345 = r450334 ? r450341 : r450344;
        return r450345;
}

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 *-un-lft-identity2.3

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

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

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

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

      \[\leadsto \frac{1}{1} \cdot \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))