Average Error: 12.9 → 1.6
Time: 6.3s
Precision: binary64
Cost: 1480
\[\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 -5 \cdot 10^{+94}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \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 -5e+94) (+ x (/ (* x y) z)) 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 <= -5e+94) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
public static 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.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -5e+94) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	t_1 = x / (z / (y + z))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -5e+94:
		tmp = x + ((x * y) / z)
	else:
		tmp = t_1
	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)
	t_1 = Float64(x / Float64(z / Float64(y + z)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -5e+94)
		tmp = Float64(x + Float64(Float64(x * y) / z));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y + z)) / z;
	t_1 = x / (z / (y + z));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -5e+94)
		tmp = x + ((x * y) / z);
	else
		tmp = t_1;
	end
	tmp_2 = 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]}, Block[{t$95$1 = N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -5e+94], N[(x + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\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 -5 \cdot 10^{+94}:\\
\;\;\;\;x + \frac{x \cdot y}{z}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target2.8
Herbie1.6
\[\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 -5.0000000000000001e94 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 14.9

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Applied egg-rr12.6

      \[\leadsto \color{blue}{{\left(\frac{\frac{z}{x}}{y + z}\right)}^{-1}} \]
    3. Taylor expanded in x around 0 14.9

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{z + y}}} \]
      Proof
      (/.f64 x (/.f64 z (+.f64 z y))): 0 points increase in error, 0 points decrease in error
      (/.f64 x (/.f64 z (Rewrite<= +-commutative_binary64 (+.f64 y z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 78 points increase in error, 20 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 y z) x)) z): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -5.0000000000000001e94

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
      Proof
      (fma.f64 x (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 y z)) x)): 4 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 31 points increase in error, 18 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 32 points increase in error, 29 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (/.f64 x (Rewrite<= *-inverses_binary64 (/.f64 z z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x z) z))): 61 points increase in error, 3 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 3 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 64 points increase in error, 79 points decrease in error
    3. Taylor expanded in y around 0 0.2

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

    \[\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 -5 \cdot 10^{+94}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array} \]

Alternatives

Alternative 1
Error20.6
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-70}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-201}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error19.9
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-70}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-201}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.9
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-70}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-201}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error2.8
Cost448
\[\frac{x}{\frac{z}{y + z}} \]
Alternative 5
Error25.0
Cost64
\[x \]

Error

Reproduce

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