Average Error: 12.9 → 1.8
Time: 4.2s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -4.26876604973354 \cdot 10^{-141} \lor \neg \left(x \leq -3.646313345375112 \cdot 10^{-283} \lor \neg \left(x \leq 5.2611451254301515 \cdot 10^{-261}\right) \land x \leq 2604.6530752999397\right):\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \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 -4.26876604973354 \cdot 10^{-141} \lor \neg \left(x \leq -3.646313345375112 \cdot 10^{-283} \lor \neg \left(x \leq 5.2611451254301515 \cdot 10^{-261}\right) \land x \leq 2604.6530752999397\right):\\
\;\;\;\;\frac{x}{\frac{z}{z + y}}\\

\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 -4.26876604973354e-141)
         (not
          (or (<= x -3.646313345375112e-283)
              (and (not (<= x 5.2611451254301515e-261))
                   (<= x 2604.6530752999397)))))
   (/ x (/ z (+ z y)))
   (+ 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 <= -4.26876604973354e-141) || !((x <= -3.646313345375112e-283) || (!(x <= 5.2611451254301515e-261) && (x <= 2604.6530752999397)))) {
		tmp = x / (z / (z + y));
	} else {
		tmp = x + ((x * y) / z);
	}
	return tmp;
}

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.9
Target3.2
Herbie1.8
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.2687660497335401e-141 or -3.64631334537511e-283 < x < 5.26114512543015153e-261 or 2604.6530752999397 < x

    1. Initial program 18.0

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

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

    if -4.2687660497335401e-141 < x < -3.64631334537511e-283 or 5.26114512543015153e-261 < x < 2604.6530752999397

    1. Initial program 4.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.26876604973354 \cdot 10^{-141} \lor \neg \left(x \leq -3.646313345375112 \cdot 10^{-283} \lor \neg \left(x \leq 5.2611451254301515 \cdot 10^{-261}\right) \land x \leq 2604.6530752999397\right):\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \end{array}\]

Reproduce

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