Average Error: 10.4 → 0.6
Time: 2.2s
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 r772014 = x;
        double r772015 = y;
        double r772016 = z;
        double r772017 = r772015 - r772016;
        double r772018 = 1.0;
        double r772019 = r772017 + r772018;
        double r772020 = r772014 * r772019;
        double r772021 = r772020 / r772016;
        return r772021;
}

double f(double x, double y, double z) {
        double r772022 = x;
        double r772023 = -6.094468107972372e+32;
        bool r772024 = r772022 <= r772023;
        double r772025 = z;
        double r772026 = r772022 / r772025;
        double r772027 = y;
        double r772028 = r772027 - r772025;
        double r772029 = 1.0;
        double r772030 = r772028 + r772029;
        double r772031 = r772026 * r772030;
        double r772032 = 1.2661444146589493e+126;
        bool r772033 = r772022 <= r772032;
        double r772034 = r772022 * r772027;
        double r772035 = 1.0;
        double r772036 = r772035 / r772025;
        double r772037 = r772034 * r772036;
        double r772038 = r772029 * r772026;
        double r772039 = r772037 + r772038;
        double r772040 = r772039 - r772022;
        double r772041 = r772027 / r772025;
        double r772042 = r772022 * r772041;
        double r772043 = r772042 + r772038;
        double r772044 = r772043 - r772022;
        double r772045 = r772033 ? r772040 : r772044;
        double r772046 = r772024 ? r772031 : r772045;
        return r772046;
}

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))