Average Error: 10.5 → 0.7
Time: 2.6s
Precision: binary64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.34303192057842814 \cdot 10^{-194}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \mathbf{elif}\;x \le 2.4438339566529289 \cdot 10^{-143}:\\ \;\;\;\;\left(x \cdot \left(y + 1\right)\right) \cdot \frac{1}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + 1}} - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -2.34303192057842814 \cdot 10^{-194}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + 1}} - x\\

\end{array}
double code(double x, double y, double z) {
	return ((double) (((double) (x * ((double) (((double) (y - z)) + 1.0)))) / z));
}
double code(double x, double y, double z) {
	double VAR;
	if ((x <= -2.343031920578428e-194)) {
		VAR = ((double) (((double) (((double) (x / z)) * ((double) (y + 1.0)))) - x));
	} else {
		double VAR_1;
		if ((x <= 2.443833956652929e-143)) {
			VAR_1 = ((double) (((double) (((double) (x * ((double) (y + 1.0)))) * ((double) (1.0 / z)))) - x));
		} else {
			VAR_1 = ((double) (((double) (x / ((double) (z / ((double) (y + 1.0)))))) - x));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.5
Target0.5
Herbie0.7
\[\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 < -2.34303192057842814e-194

    1. Initial program 13.5

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Simplified2.2

      \[\leadsto \color{blue}{x \cdot \frac{y + 1}{z} - x}\]
    3. Using strategy rm
    4. Applied clear-num2.2

      \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{z}{y + 1}}} - x\]
    5. Using strategy rm
    6. Applied associate-/r/2.2

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

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

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

    if -2.34303192057842814e-194 < x < 2.4438339566529289e-143

    1. Initial program 0.2

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Simplified7.8

      \[\leadsto \color{blue}{x \cdot \frac{y + 1}{z} - x}\]
    3. Using strategy rm
    4. Applied div-inv7.8

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

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

    if 2.4438339566529289e-143 < x

    1. Initial program 15.6

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Simplified1.4

      \[\leadsto \color{blue}{x \cdot \frac{y + 1}{z} - x}\]
    3. Using strategy rm
    4. Applied clear-num1.4

      \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{z}{y + 1}}} - x\]
    5. Using strategy rm
    6. Applied un-div-inv1.2

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + 1}}} - x\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.34303192057842814 \cdot 10^{-194}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \mathbf{elif}\;x \le 2.4438339566529289 \cdot 10^{-143}:\\ \;\;\;\;\left(x \cdot \left(y + 1\right)\right) \cdot \frac{1}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + 1}} - x\\ \end{array}\]

Reproduce

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