Average Error: 12.4 → 1.7
Time: 2.7s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{if}\;x \leq -4.639344664532624 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1771730614040736 \cdot 10^{-99}:\\ \;\;\;\;x + y \cdot \left(x \cdot \frac{1}{z}\right)\\ \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)))
   (if (<= x -4.639344664532624e+27)
     t_0
     (if (<= x 1.1771730614040736e-99) (+ x (* y (* x (/ 1.0 z)))) 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 tmp;
	if (x <= -4.639344664532624e+27) {
		tmp = t_0;
	} else if (x <= 1.1771730614040736e-99) {
		tmp = x + (y * (x * (1.0 / z)));
	} 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)
	tmp = 0.0
	if (x <= -4.639344664532624e+27)
		tmp = t_0;
	elseif (x <= 1.1771730614040736e-99)
		tmp = Float64(x + Float64(y * Float64(x * Float64(1.0 / z))));
	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]}, If[LessEqual[x, -4.639344664532624e+27], t$95$0, If[LessEqual[x, 1.1771730614040736e-99], N[(x + N[(y * N[(x * N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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)\\
\mathbf{if}\;x \leq -4.639344664532624 \cdot 10^{+27}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.1771730614040736 \cdot 10^{-99}:\\
\;\;\;\;x + y \cdot \left(x \cdot \frac{1}{z}\right)\\

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


\end{array}

Error

Target

Original12.4
Target3.0
Herbie1.7
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.63934466453262382e27 or 1.1771730614040736e-99 < x

    1. Initial program 19.8

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

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

    if -4.63934466453262382e27 < x < 1.1771730614040736e-99

    1. Initial program 5.4

      \[\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 2.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.639344664532624 \cdot 10^{+27}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;x \leq 1.1771730614040736 \cdot 10^{-99}:\\ \;\;\;\;x + y \cdot \left(x \cdot \frac{1}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \end{array} \]

Reproduce

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