Average Error: 12.6 → 1.8
Time: 7.3s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{if}\;x \leq -8.412480443797539 \cdot 10^{-68}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.1422609114949007 \cdot 10^{-95}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot \frac{1}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\mathbf{if}\;x \leq -8.412480443797539 \cdot 10^{-68}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 2.1422609114949007 \cdot 10^{-95}:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot \frac{1}{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 (fma x (/ y z) x)))
   (if (<= x -8.412480443797539e-68)
     t_0
     (if (<= x 2.1422609114949007e-95) (fma y (* x (/ 1.0 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 = fma(x, (y / z), x);
	double tmp;
	if (x <= -8.412480443797539e-68) {
		tmp = t_0;
	} else if (x <= 2.1422609114949007e-95) {
		tmp = fma(y, (x * (1.0 / z)), x);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -8.41248044379753882e-68 or 2.14226091149490066e-95 < x

    1. Initial program 17.1

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

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

    if -8.41248044379753882e-68 < x < 2.14226091149490066e-95

    1. Initial program 6.4

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Applied egg-rr7.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.412480443797539 \cdot 10^{-68}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;x \leq 2.1422609114949007 \cdot 10^{-95}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot \frac{1}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \end{array} \]

Reproduce

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