Average Error: 10.4 → 0.6
Time: 4.4s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.0944681079723717 \cdot 10^{32}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\left(y - z\right) + 1\right)\\ \mathbf{elif}\;x \le 1.26614441465894927 \cdot 10^{126}:\\ \;\;\;\;\left(\left(x \cdot y\right) \cdot \frac{1}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{y}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -6.0944681079723717 \cdot 10^{32}:\\
\;\;\;\;\frac{x}{z} \cdot \left(\left(y - z\right) + 1\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r3648 = x;
        double r3649 = y;
        double r3650 = z;
        double r3651 = r3649 - r3650;
        double r3652 = 1.0;
        double r3653 = r3651 + r3652;
        double r3654 = r3648 * r3653;
        double r3655 = r3654 / r3650;
        return r3655;
}

double f(double x, double y, double z) {
        double r3656 = x;
        double r3657 = -6.094468107972372e+32;
        bool r3658 = r3656 <= r3657;
        double r3659 = z;
        double r3660 = r3656 / r3659;
        double r3661 = y;
        double r3662 = r3661 - r3659;
        double r3663 = 1.0;
        double r3664 = r3662 + r3663;
        double r3665 = r3660 * r3664;
        double r3666 = 1.2661444146589493e+126;
        bool r3667 = r3656 <= r3666;
        double r3668 = r3656 * r3661;
        double r3669 = 1.0;
        double r3670 = r3669 / r3659;
        double r3671 = r3668 * r3670;
        double r3672 = r3663 * r3660;
        double r3673 = r3671 + r3672;
        double r3674 = r3673 - r3656;
        double r3675 = r3661 / r3659;
        double r3676 = r3656 * r3675;
        double r3677 = r3676 + r3672;
        double r3678 = r3677 - r3656;
        double r3679 = r3667 ? r3674 : r3678;
        double r3680 = r3658 ? r3665 : r3679;
        return r3680;
}

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.4
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 3 regimes
  2. if x < -6.094468107972372e+32

    1. Initial program 30.2

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

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

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

    if -6.094468107972372e+32 < x < 1.2661444146589493e+126

    1. Initial program 1.6

      \[\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. Using strategy rm
    4. Applied div-inv0.8

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

    if 1.2661444146589493e+126 < x

    1. Initial program 40.3

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

      \[\leadsto \color{blue}{\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity13.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.0944681079723717 \cdot 10^{32}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\left(y - z\right) + 1\right)\\ \mathbf{elif}\;x \le 1.26614441465894927 \cdot 10^{126}:\\ \;\;\;\;\left(\left(x \cdot y\right) \cdot \frac{1}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{y}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \end{array}\]

Reproduce

herbie shell --seed 2020025 
(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))