Average Error: 12.3 → 1.8
Time: 2.1s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.12348942251738224 \cdot 10^{95}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 2.28734637678198 \cdot 10^{305}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{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}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.12348942251738224 \cdot 10^{95}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\

\mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 2.28734637678198 \cdot 10^{305}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{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 ((((x * (y + z)) / z) <= 1.1234894225173822e+95)) {
		temp = (x / (z / (y + z)));
	} else {
		double temp_1;
		if ((((x * (y + z)) / z) <= 2.2873463767819766e+305)) {
			temp_1 = ((x * (y + z)) / 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.3
Target2.8
Herbie1.8
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < 1.1234894225173822e+95

    1. Initial program 9.4

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

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

    if 1.1234894225173822e+95 < (/ (* x (+ y z)) z) < 2.2873463767819766e+305

    1. Initial program 0.2

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

    if 2.2873463767819766e+305 < (/ (* x (+ y z)) z)

    1. Initial program 62.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.12348942251738224 \cdot 10^{95}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 2.28734637678198 \cdot 10^{305}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +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))