Average Error: 12.4 → 1.9
Time: 2.8s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5649729669.802156:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;x \leq 2.074166328143206 \cdot 10^{-140}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \leq -5649729669.802156:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

\mathbf{elif}\;x \leq 2.074166328143206 \cdot 10^{-140}:\\
\;\;\;\;x + \frac{x \cdot y}{z}\\

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


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= x -5649729669.802156)
   (fma x (/ y z) x)
   (if (<= x 2.074166328143206e-140) (+ x (/ (* x y) z)) (+ 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 <= -5649729669.802156) {
		tmp = fma(x, (y / z), x);
	} else if (x <= 2.074166328143206e-140) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = x + (x * (y / z));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.4
Target2.8
Herbie1.9
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if x < -5649729669.8021564

    1. Initial program 22.3

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

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

    if -5649729669.8021564 < x < 2.07416632814320603e-140

    1. Initial program 6.1

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Taylor expanded in y around 0 3.2

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    3. Simplified3.7

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

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

    if 2.07416632814320603e-140 < x

    1. Initial program 15.1

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Taylor expanded in y around 0 5.1

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    3. Simplified5.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)} \]
    4. Applied fma-udef_binary645.2

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y + x} \]
    5. Simplified1.2

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

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

Reproduce

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