Average Error: 10.2 → 0.2
Time: 5.4s
Precision: binary64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} t_0 := \left(\frac{x}{z} + x \cdot \frac{y}{z}\right) - x\\ \mathbf{if}\;z \leq -1.3894035698836182 \cdot 10^{-28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.1269081990223642 \cdot 10^{+44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, x\right)}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(\frac{x}{z} + x \cdot \frac{y}{z}\right) - x\\
\mathbf{if}\;z \leq -1.3894035698836182 \cdot 10^{-28}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.1269081990223642 \cdot 10^{+44}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, x\right)}{z} - x\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (+ (/ x z) (* x (/ y z))) x)))
   (if (<= z -1.3894035698836182e-28)
     t_0
     (if (<= z 1.1269081990223642e+44) (- (/ (fma y x x) z) x) t_0))))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	double t_0 = ((x / z) + (x * (y / z))) - x;
	double tmp;
	if (z <= -1.3894035698836182e-28) {
		tmp = t_0;
	} else if (z <= 1.1269081990223642e+44) {
		tmp = (fma(y, x, x) / z) - x;
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.2
Target0.4
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \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 z < -1.38940356988361817e-28 or 1.12690819902236419e44 < z

    1. Initial program 17.1

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}} \]
    3. Taylor expanded in x around 0 17.1

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, x, x\right)}{z} - x} \]
    5. Taylor expanded in x around 0 0.1

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

      \[\leadsto \color{blue}{\left(\sqrt[3]{\left(\left(\frac{y}{z} + \frac{1}{z}\right) - 1\right) \cdot x} \cdot \sqrt[3]{\left(\left(\frac{y}{z} + \frac{1}{z}\right) - 1\right) \cdot x}\right) \cdot \sqrt[3]{\left(\left(\frac{y}{z} + \frac{1}{z}\right) - 1\right) \cdot x}} \]
    7. Taylor expanded in y around 0 5.5

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

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

    if -1.38940356988361817e-28 < z < 1.12690819902236419e44

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}} \]
    3. Taylor expanded in x around 0 0.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.3894035698836182 \cdot 10^{-28}:\\ \;\;\;\;\left(\frac{x}{z} + x \cdot \frac{y}{z}\right) - x\\ \mathbf{elif}\;z \leq 1.1269081990223642 \cdot 10^{+44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, x\right)}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x}{z} + x \cdot \frac{y}{z}\right) - x\\ \end{array} \]

Reproduce

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