Average Error: 12.2 → 2.1
Time: 2.1s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -4.79817812939288 \cdot 10^{-228}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;x \leq 4.013452996809398 \cdot 10^{-24}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \leq -4.79817812939288 \cdot 10^{-228}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

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

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= x -4.79817812939288e-228)
   (* x (/ (+ y z) z))
   (if (<= x 4.013452996809398e-24) (+ x (/ (* x y) z)) (* x (/ (+ y z) 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.79817812939288e-228) {
		tmp = x * ((y + z) / z);
	} else if (x <= 4.013452996809398e-24) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = x * ((y + z) / 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.2
Target3.2
Herbie2.1
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.79817812939287982e-228 or 4.01345299680939833e-24 < x

    1. Initial program 15.5

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary6415.5

      \[\leadsto \frac{x \cdot \left(y + z\right)}{\color{blue}{1 \cdot z}}\]
    4. Applied times-frac_binary641.5

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

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

    if -4.79817812939287982e-228 < x < 4.01345299680939833e-24

    1. Initial program 6.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.79817812939288 \cdot 10^{-228}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;x \leq 4.013452996809398 \cdot 10^{-24}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array}\]

Reproduce

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