Average Error: 10.0 → 0.1
Time: 10.9s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.73174539613943765126915824376269586469 \cdot 10^{-102}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \mathbf{elif}\;x \le 3.153542269680621261807512474967274027564 \cdot 10^{-72}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{y \cdot x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -1.73174539613943765126915824376269586469 \cdot 10^{-102}:\\
\;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r33972174 = x;
        double r33972175 = y;
        double r33972176 = z;
        double r33972177 = r33972175 - r33972176;
        double r33972178 = 1.0;
        double r33972179 = r33972177 + r33972178;
        double r33972180 = r33972174 * r33972179;
        double r33972181 = r33972180 / r33972176;
        return r33972181;
}

double f(double x, double y, double z) {
        double r33972182 = x;
        double r33972183 = -1.7317453961394377e-102;
        bool r33972184 = r33972182 <= r33972183;
        double r33972185 = 1.0;
        double r33972186 = z;
        double r33972187 = r33972182 / r33972186;
        double r33972188 = r33972185 * r33972187;
        double r33972189 = y;
        double r33972190 = r33972187 * r33972189;
        double r33972191 = r33972188 + r33972190;
        double r33972192 = r33972191 - r33972182;
        double r33972193 = 3.1535422696806213e-72;
        bool r33972194 = r33972182 <= r33972193;
        double r33972195 = r33972189 * r33972182;
        double r33972196 = r33972195 / r33972186;
        double r33972197 = r33972188 + r33972196;
        double r33972198 = r33972197 - r33972182;
        double r33972199 = r33972194 ? r33972198 : r33972192;
        double r33972200 = r33972184 ? r33972192 : r33972199;
        return r33972200;
}

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.0
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 < -1.7317453961394377e-102 or 3.1535422696806213e-72 < x

    1. Initial program 18.0

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Taylor expanded around 0 6.2

      \[\leadsto \color{blue}{\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x}\]
    5. Taylor expanded around 0 6.2

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

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

    if -1.7317453961394377e-102 < x < 3.1535422696806213e-72

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Taylor expanded around 0 0.1

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

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

      \[\leadsto \left(\color{blue}{\frac{x}{z} \cdot y} + 1 \cdot \frac{x}{z}\right) - x\]
    7. Using strategy rm
    8. Applied associate-*l/0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.73174539613943765126915824376269586469 \cdot 10^{-102}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \mathbf{elif}\;x \le 3.153542269680621261807512474967274027564 \cdot 10^{-72}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{y \cdot x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(1 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

  (/ (* x (+ (- y z) 1.0)) z))