Average Error: 10.1 → 0.1
Time: 21.7s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le -6.579027488067199411550511935864463917316 \cdot 10^{210} \lor \neg \left(\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le 3.530201563568855701403158383753448655305 \cdot 10^{90}\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}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le -6.579027488067199411550511935864463917316 \cdot 10^{210} \lor \neg \left(\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le 3.530201563568855701403158383753448655305 \cdot 10^{90}\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 r438092 = x;
        double r438093 = y;
        double r438094 = z;
        double r438095 = r438093 - r438094;
        double r438096 = 1.0;
        double r438097 = r438095 + r438096;
        double r438098 = r438092 * r438097;
        double r438099 = r438098 / r438094;
        return r438099;
}

double f(double x, double y, double z) {
        double r438100 = x;
        double r438101 = y;
        double r438102 = z;
        double r438103 = r438101 - r438102;
        double r438104 = 1.0;
        double r438105 = r438103 + r438104;
        double r438106 = r438100 * r438105;
        double r438107 = r438106 / r438102;
        double r438108 = -6.579027488067199e+210;
        bool r438109 = r438107 <= r438108;
        double r438110 = 3.5302015635688557e+90;
        bool r438111 = r438107 <= r438110;
        double r438112 = !r438111;
        bool r438113 = r438109 || r438112;
        double r438114 = r438100 / r438102;
        double r438115 = r438101 + r438104;
        double r438116 = r438114 * r438115;
        double r438117 = r438116 - r438100;
        double r438118 = r438100 * r438115;
        double r438119 = r438118 / r438102;
        double r438120 = r438119 - r438100;
        double r438121 = r438113 ? r438117 : r438120;
        return r438121;
}

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.1
Target0.5
Herbie0.1
\[\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 (+ (- y z) 1.0)) z) < -6.579027488067199e+210 or 3.5302015635688557e+90 < (/ (* x (+ (- y z) 1.0)) z)

    1. Initial program 27.9

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

      \[\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 -6.579027488067199e+210 < (/ (* x (+ (- y z) 1.0)) z) < 3.5302015635688557e+90

    1. Initial program 0.1

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

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

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

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

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

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

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

      \[\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.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le -6.579027488067199411550511935864463917316 \cdot 10^{210} \lor \neg \left(\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \le 3.530201563568855701403158383753448655305 \cdot 10^{90}\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 2019326 +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))