Average Error: 12.6 → 1.0
Time: 5.4s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{if}\;t_0 \leq -1.5048746095998824 \cdot 10^{+307} \lor \neg \left(t_0 \leq -1.2021988713097483 \cdot 10^{+90}\right) \land \left(t_0 \leq 6.821362143384797 \cdot 10^{+199} \lor \neg \left(t_0 \leq 8.164899042416683 \cdot 10^{+304}\right)\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq -1.5048746095998824 \cdot 10^{+307} \lor \neg \left(t_0 \leq -1.2021988713097483 \cdot 10^{+90}\right) \land \left(t_0 \leq 6.821362143384797 \cdot 10^{+199} \lor \neg \left(t_0 \leq 8.164899042416683 \cdot 10^{+304}\right)\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

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


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (+ y z)) z)))
   (if (or (<= t_0 -1.5048746095998824e+307)
           (and (not (<= t_0 -1.2021988713097483e+90))
                (or (<= t_0 6.821362143384797e+199)
                    (not (<= t_0 8.164899042416683e+304)))))
     (fma x (/ y z) x)
     t_0)))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double tmp;
	if ((t_0 <= -1.5048746095998824e+307) || (!(t_0 <= -1.2021988713097483e+90) && ((t_0 <= 6.821362143384797e+199) || !(t_0 <= 8.164899042416683e+304)))) {
		tmp = fma(x, (y / z), x);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target2.8
Herbie1.0
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -1.50487460959988241e307 or -1.2021988713097483e90 < (/.f64 (*.f64 x (+.f64 y z)) z) < 6.82136214338479694e199 or 8.16489904241668317e304 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 15.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]

    if -1.50487460959988241e307 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.2021988713097483e90 or 6.82136214338479694e199 < (/.f64 (*.f64 x (+.f64 y z)) z) < 8.16489904241668317e304

    1. Initial program 0.2

      \[\frac{x \cdot \left(y + z\right)}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -1.5048746095998824 \cdot 10^{+307} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq -1.2021988713097483 \cdot 10^{+90}\right) \land \left(\frac{x \cdot \left(y + z\right)}{z} \leq 6.821362143384797 \cdot 10^{+199} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq 8.164899042416683 \cdot 10^{+304}\right)\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \end{array} \]

Reproduce

herbie shell --seed 2021357 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (/ x (/ z (+ y z)))

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