Average Error: 12.0 → 1.7
Time: 4.4s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.652063733016855 \cdot 10^{+60} \lor \neg \left(x \leq 8.997270110073122 \cdot 10^{-116}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \leq -2.652063733016855 \cdot 10^{+60} \lor \neg \left(x \leq 8.997270110073122 \cdot 10^{-116}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \frac{x \cdot y}{z}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -2.652063733016855e+60) (not (<= x 8.997270110073122e-116)))
   (fma x (/ y z) x)
   (+ x (/ (* x y) z))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -2.652063733016855e+60) || !(x <= 8.997270110073122e-116)) {
		tmp = fma(x, (y / z), x);
	} else {
		tmp = x + ((x * y) / z);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.0
Target3.1
Herbie1.7
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 2 regimes
  2. if x < -2.65206373301685495e60 or 8.9972701100731221e-116 < x

    1. Initial program 19.0

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

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

    if -2.65206373301685495e60 < x < 8.9972701100731221e-116

    1. Initial program 5.6

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.652063733016855 \cdot 10^{+60} \lor \neg \left(x \leq 8.997270110073122 \cdot 10^{-116}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \end{array} \]

Reproduce

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