Average Error: 12.2 → 3.1
Time: 2.8s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5229890799554336 \cdot 10^{-122}:\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \mathbf{elif}\;z \leq 2.0081309839325857 \cdot 10^{-208}:\\ \;\;\;\;\frac{x \cdot \left(z + y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -2.5229890799554336 \cdot 10^{-122}:\\
\;\;\;\;\frac{x}{\frac{z}{z + y}}\\

\mathbf{elif}\;z \leq 2.0081309839325857 \cdot 10^{-208}:\\
\;\;\;\;\frac{x \cdot \left(z + y\right)}{z}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.5229890799554336e-122)
   (/ x (/ z (+ z y)))
   (if (<= z 2.0081309839325857e-208) (/ (* x (+ z y)) z) (fma x (/ y z) x))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.5229890799554336e-122) {
		tmp = x / (z / (z + y));
	} else if (z <= 2.0081309839325857e-208) {
		tmp = (x * (z + y)) / z;
	} else {
		tmp = fma(x, (y / z), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.2
Target3.0
Herbie3.1
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if z < -2.52298907995543361e-122

    1. Initial program 13.1

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Applied associate-/l*_binary640.6

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}} \]

    if -2.52298907995543361e-122 < z < 2.00813098393258565e-208

    1. Initial program 11.2

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

    if 2.00813098393258565e-208 < z

    1. Initial program 11.8

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

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

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

Reproduce

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