Average Error: 12.4 → 2.1
Time: 2.8s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -3.2437167390649342 \cdot 10^{138} \lor \neg \left(y \le 8.20635231190658476 \cdot 10^{-79} \lor \neg \left(y \le 1.21235126716905928 \cdot 10^{267}\right)\right):\\ \;\;\;\;y \cdot \frac{x}{z} + x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot x + x\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \le -3.2437167390649342 \cdot 10^{138} \lor \neg \left(y \le 8.20635231190658476 \cdot 10^{-79} \lor \neg \left(y \le 1.21235126716905928 \cdot 10^{267}\right)\right):\\
\;\;\;\;y \cdot \frac{x}{z} + x\\

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

\end{array}
double code(double x, double y, double z) {
	return ((x * (y + z)) / z);
}
double code(double x, double y, double z) {
	double VAR;
	if (((y <= -3.243716739064934e+138) || !((y <= 8.206352311906585e-79) || !(y <= 1.2123512671690593e+267)))) {
		VAR = ((y * (x / z)) + x);
	} else {
		VAR = (((y / z) * x) + x);
	}
	return VAR;
}

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.0
Herbie2.1
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -3.243716739064934e+138 or 8.206352311906585e-79 < y < 1.2123512671690593e+267

    1. Initial program 11.6

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

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x + x}\]
    5. Using strategy rm
    6. Applied div-inv7.2

      \[\leadsto \color{blue}{\left(y \cdot \frac{1}{z}\right)} \cdot x + x\]
    7. Applied associate-*l*3.8

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

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

    if -3.243716739064934e+138 < y < 8.206352311906585e-79 or 1.2123512671690593e+267 < y

    1. Initial program 12.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.2437167390649342 \cdot 10^{138} \lor \neg \left(y \le 8.20635231190658476 \cdot 10^{-79} \lor \neg \left(y \le 1.21235126716905928 \cdot 10^{267}\right)\right):\\ \;\;\;\;y \cdot \frac{x}{z} + x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot x + x\\ \end{array}\]

Reproduce

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