Average Error: 12.6 → 1.6
Time: 3.8s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ t_1 := x + \frac{x \cdot y}{z}\\ \mathbf{if}\;x \leq -2.041895623003483 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.363410517185796 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.162995441140994 \cdot 10^{-151}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;x \leq 1.1147993284127676 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma x (/ y z) x)) (t_1 (+ x (/ (* x y) z))))
   (if (<= x -2.041895623003483e-62)
     t_0
     (if (<= x -6.363410517185796e-300)
       t_1
       (if (<= x 3.162995441140994e-151)
         (fma y (/ x z) x)
         (if (<= x 1.1147993284127676e-87) t_1 t_0))))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double t_0 = fma(x, (y / z), x);
	double t_1 = x + ((x * y) / z);
	double tmp;
	if (x <= -2.041895623003483e-62) {
		tmp = t_0;
	} else if (x <= -6.363410517185796e-300) {
		tmp = t_1;
	} else if (x <= 3.162995441140994e-151) {
		tmp = fma(y, (x / z), x);
	} else if (x <= 1.1147993284127676e-87) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function code(x, y, z)
	t_0 = fma(x, Float64(y / z), x)
	t_1 = Float64(x + Float64(Float64(x * y) / z))
	tmp = 0.0
	if (x <= -2.041895623003483e-62)
		tmp = t_0;
	elseif (x <= -6.363410517185796e-300)
		tmp = t_1;
	elseif (x <= 3.162995441140994e-151)
		tmp = fma(y, Float64(x / z), x);
	elseif (x <= 1.1147993284127676e-87)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.041895623003483e-62], t$95$0, If[LessEqual[x, -6.363410517185796e-300], t$95$1, If[LessEqual[x, 3.162995441140994e-151], N[(y * N[(x / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 1.1147993284127676e-87], t$95$1, t$95$0]]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
t_1 := x + \frac{x \cdot y}{z}\\
\mathbf{if}\;x \leq -2.041895623003483 \cdot 10^{-62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -6.363410517185796 \cdot 10^{-300}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 3.162995441140994 \cdot 10^{-151}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

\mathbf{elif}\;x \leq 1.1147993284127676 \cdot 10^{-87}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target3.1
Herbie1.6
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if x < -2.04189562300348299e-62 or 1.11479932841276762e-87 < x

    1. Initial program 17.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]

    if -2.04189562300348299e-62 < x < -6.3634105171857962e-300 or 3.16299544114099425e-151 < x < 1.11479932841276762e-87

    1. Initial program 4.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    3. Taylor expanded in y around 0 2.5

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

    if -6.3634105171857962e-300 < x < 3.16299544114099425e-151

    1. Initial program 9.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    3. Taylor expanded in x around 0 7.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.041895623003483 \cdot 10^{-62}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;x \leq -6.363410517185796 \cdot 10^{-300}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{elif}\;x \leq 3.162995441140994 \cdot 10^{-151}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;x \leq 1.1147993284127676 \cdot 10^{-87}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \end{array} \]

Reproduce

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