Average Error: 9.9 → 0.6
Time: 4.2s
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 -\infty \lor \neg \left(t_0 \leq -3.8945838097341374 \cdot 10^{+124}\right) \land \left(t_0 \leq 2.1638508067000652 \cdot 10^{+60} \lor \neg \left(t_0 \leq 9.428468055278694 \cdot 10^{+302}\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 -\infty \lor \neg \left(t_0 \leq -3.8945838097341374 \cdot 10^{+124}\right) \land \left(t_0 \leq 2.1638508067000652 \cdot 10^{+60} \lor \neg \left(t_0 \leq 9.428468055278694 \cdot 10^{+302}\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 (- INFINITY))
           (and (not (<= t_0 -3.8945838097341374e+124))
                (or (<= t_0 2.1638508067000652e+60)
                    (not (<= t_0 9.428468055278694e+302)))))
     (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 <= -((double) INFINITY)) || (!(t_0 <= -3.8945838097341374e+124) && ((t_0 <= 2.1638508067000652e+60) || !(t_0 <= 9.428468055278694e+302)))) {
		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

Original9.9
Target2.2
Herbie0.6
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -inf.0 or -3.89458380973413745e124 < (/.f64 (*.f64 x (+.f64 y z)) z) < 2.1638508067000652e60 or 9.42846805527869363e302 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 12.8

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

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

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -3.89458380973413745e124 or 2.1638508067000652e60 < (/.f64 (*.f64 x (+.f64 y z)) z) < 9.42846805527869363e302

    1. Initial program 0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq -3.8945838097341374 \cdot 10^{+124}\right) \land \left(\frac{x \cdot \left(y + z\right)}{z} \leq 2.1638508067000652 \cdot 10^{+60} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq 9.428468055278694 \cdot 10^{+302}\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 2022067 
(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))