Average Error: 12.4 → 3.9
Time: 2.4s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -9.04077640072219121 \cdot 10^{-80}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;z \le 1.18667300925519477 \cdot 10^{-299}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \le -9.04077640072219121 \cdot 10^{-80}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\

\mathbf{elif}\;z \le 1.18667300925519477 \cdot 10^{-299}:\\
\;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\

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

\end{array}
double code(double x, double y, double z) {
	return ((x * (y + z)) / z);
}
double code(double x, double y, double z) {
	double temp;
	if ((z <= -9.040776400722191e-80)) {
		temp = (x / (z / (y + z)));
	} else {
		double temp_1;
		if ((z <= 1.1866730092551948e-299)) {
			temp_1 = ((x * (y + z)) * (1.0 / z));
		} else {
			temp_1 = fma((x / z), y, x);
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.4
Target3.1
Herbie3.9
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -9.040776400722191e-80

    1. Initial program 14.1

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.3

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

    if -9.040776400722191e-80 < z < 1.1866730092551948e-299

    1. Initial program 9.1

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied div-inv9.2

      \[\leadsto \color{blue}{\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}}\]

    if 1.1866730092551948e-299 < z

    1. Initial program 12.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -9.04077640072219121 \cdot 10^{-80}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;z \le 1.18667300925519477 \cdot 10^{-299}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(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))