Average Error: 12.1 → 2.7
Time: 2.2s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{if}\;t_0 \leq -6.582729939135484 \cdot 10^{-168}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq 1.9816485472502953 \cdot 10^{+98}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;t_0 \leq 2.325475704519075 \cdot 10^{+238}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \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)))
   (if (<= t_0 -6.582729939135484e-168)
     (fma y (/ x z) x)
     (if (<= t_0 1.9816485472502953e+98)
       (+ x (* x (/ y z)))
       (if (<= t_0 2.325475704519075e+238) t_0 (fma (/ y z) x x))))))
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 tmp;
	if (t_0 <= -6.582729939135484e-168) {
		tmp = fma(y, (x / z), x);
	} else if (t_0 <= 1.9816485472502953e+98) {
		tmp = x + (x * (y / z));
	} else if (t_0 <= 2.325475704519075e+238) {
		tmp = t_0;
	} else {
		tmp = fma((y / z), x, x);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y + z)) / z)
	tmp = 0.0
	if (t_0 <= -6.582729939135484e-168)
		tmp = fma(y, Float64(x / z), x);
	elseif (t_0 <= 1.9816485472502953e+98)
		tmp = Float64(x + Float64(x * Float64(y / z)));
	elseif (t_0 <= 2.325475704519075e+238)
		tmp = t_0;
	else
		tmp = fma(Float64(y / z), x, x);
	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[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, -6.582729939135484e-168], N[(y * N[(x / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 1.9816485472502953e+98], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.325475704519075e+238], t$95$0, N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq -6.582729939135484 \cdot 10^{-168}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

\mathbf{elif}\;t_0 \leq 1.9816485472502953 \cdot 10^{+98}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\

\mathbf{elif}\;t_0 \leq 2.325475704519075 \cdot 10^{+238}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.1
Target3.1
Herbie2.7
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -6.58272993913548415e-168

    1. Initial program 11.8

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

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

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

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

    if -6.58272993913548415e-168 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.98164854725029532e98

    1. Initial program 7.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    3. Applied egg-rr0.5

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

    if 1.98164854725029532e98 < (/.f64 (*.f64 x (+.f64 y z)) z) < 2.3254757045190749e238

    1. Initial program 0.2

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

    if 2.3254757045190749e238 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 41.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    3. Applied egg-rr5.1

      \[\leadsto \color{blue}{x + x \cdot \frac{y}{z}} \]
    4. Applied egg-rr5.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -6.582729939135484 \cdot 10^{-168}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 1.9816485472502953 \cdot 10^{+98}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 2.325475704519075 \cdot 10^{+238}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \end{array} \]

Reproduce

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