Average Error: 12.2 → 1.7
Time: 3.7s
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 -1.6809885121048745 \cdot 10^{+104}:\\ \;\;\;\;x + \frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;t_0 \leq 1.208491790712971 \cdot 10^{-65}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq 3.712242571148193 \cdot 10^{+294}:\\ \;\;\;\;x + \frac{1}{\frac{z}{x \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{x}{z}\\ \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 -1.6809885121048745e+104)
     (+ x (/ y (/ z x)))
     (if (<= t_0 1.208491790712971e-65)
       (fma x (/ y z) x)
       (if (<= t_0 3.712242571148193e+294)
         (+ x (/ 1.0 (/ z (* x y))))
         (+ x (* y (/ x z))))))))
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 <= -1.6809885121048745e+104) {
		tmp = x + (y / (z / x));
	} else if (t_0 <= 1.208491790712971e-65) {
		tmp = fma(x, (y / z), x);
	} else if (t_0 <= 3.712242571148193e+294) {
		tmp = x + (1.0 / (z / (x * y)));
	} else {
		tmp = x + (y * (x / z));
	}
	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 <= -1.6809885121048745e+104)
		tmp = Float64(x + Float64(y / Float64(z / x)));
	elseif (t_0 <= 1.208491790712971e-65)
		tmp = fma(x, Float64(y / z), x);
	elseif (t_0 <= 3.712242571148193e+294)
		tmp = Float64(x + Float64(1.0 / Float64(z / Float64(x * y))));
	else
		tmp = Float64(x + Float64(y * Float64(x / z)));
	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, -1.6809885121048745e+104], N[(x + N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1.208491790712971e-65], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 3.712242571148193e+294], N[(x + N[(1.0 / N[(z / N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $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 -1.6809885121048745 \cdot 10^{+104}:\\
\;\;\;\;x + \frac{y}{\frac{z}{x}}\\

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

\mathbf{elif}\;t_0 \leq 3.712242571148193 \cdot 10^{+294}:\\
\;\;\;\;x + \frac{1}{\frac{z}{x \cdot y}}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

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

    1. Initial program 22.6

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Applied associate-/l*_binary646.1

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

    if -1.6809885121048745e104 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.208491790712971e-65

    1. Initial program 6.1

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Applied *-un-lft-identity_binary643.3

      \[\leadsto \frac{y \cdot x}{z} + \color{blue}{1 \cdot x} \]
    5. Applied *-un-lft-identity_binary643.3

      \[\leadsto \color{blue}{1 \cdot \frac{y \cdot x}{z}} + 1 \cdot x \]
    6. Applied distribute-lft-out_binary643.3

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

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

    if 1.208491790712971e-65 < (/.f64 (*.f64 x (+.f64 y z)) z) < 3.7122425711481931e294

    1. Initial program 0.3

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Applied clear-num_binary640.3

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

    if 3.7122425711481931e294 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 59.7

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Applied *-un-lft-identity_binary6421.2

      \[\leadsto \frac{y \cdot x}{\color{blue}{1 \cdot z}} + x \]
    5. Applied times-frac_binary642.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -1.6809885121048745 \cdot 10^{+104}:\\ \;\;\;\;x + \frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 1.208491790712971 \cdot 10^{-65}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 3.712242571148193 \cdot 10^{+294}:\\ \;\;\;\;x + \frac{1}{\frac{z}{x \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{x}{z}\\ \end{array} \]

Reproduce

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