Average Error: 12.6 → 0.2
Time: 3.8s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := \frac{x}{\frac{z}{y + z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -3.814786698001926 \cdot 10^{-200}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 3.5870461030883145 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 6.381534117083224 \cdot 10^{+306}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
t_1 := \frac{x}{\frac{z}{y + z}}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -3.814786698001926 \cdot 10^{-200}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 3.5870461030883145 \cdot 10^{-103}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 6.381534117083224 \cdot 10^{+306}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (+ y z)) z)) (t_1 (/ x (/ z (+ y z)))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -3.814786698001926e-200)
       t_0
       (if (<= t_0 3.5870461030883145e-103)
         t_1
         (if (<= t_0 6.381534117083224e+306) t_0 t_1))))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double t_1 = x / (z / (y + z));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -3.814786698001926e-200) {
		tmp = t_0;
	} else if (t_0 <= 3.5870461030883145e-103) {
		tmp = t_1;
	} else if (t_0 <= 6.381534117083224e+306) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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.6
Target3.0
Herbie0.2
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -inf.0 or -3.81478669800192591e-200 < (/.f64 (*.f64 x (+.f64 y z)) z) < 3.5870461030883145e-103 or 6.38153411708322369e306 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 34.7

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Applied associate-/l*_binary640.1

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

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -3.81478669800192591e-200 or 3.5870461030883145e-103 < (/.f64 (*.f64 x (+.f64 y z)) z) < 6.38153411708322369e306

    1. Initial program 0.3

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Applied *-un-lft-identity_binary640.3

      \[\leadsto \frac{x \cdot \left(y + z\right)}{\color{blue}{1 \cdot z}} \]
    3. Applied associate-/r*_binary640.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -\infty:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq -3.814786698001926 \cdot 10^{-200}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 3.5870461030883145 \cdot 10^{-103}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 6.381534117083224 \cdot 10^{+306}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array} \]

Reproduce

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