Average Error: 12.5 → 2.3
Time: 4.2s
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}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+174}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{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 (- INFINITY))
     (* x (/ (+ y z) z))
     (if (<= t_0 -2e+174) t_0 (+ x (* x (/ y 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 <= -((double) INFINITY)) {
		tmp = x * ((y + z) / z);
	} else if (t_0 <= -2e+174) {
		tmp = t_0;
	} else {
		tmp = x + (x * (y / z));
	}
	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 tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = x * ((y + z) / z);
	} else if (t_0 <= -2e+174) {
		tmp = t_0;
	} else {
		tmp = x + (x * (y / z));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	tmp = 0
	if t_0 <= -math.inf:
		tmp = x * ((y + z) / z)
	elif t_0 <= -2e+174:
		tmp = t_0
	else:
		tmp = x + (x * (y / 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 <= Float64(-Inf))
		tmp = Float64(x * Float64(Float64(y + z) / z));
	elseif (t_0 <= -2e+174)
		tmp = t_0;
	else
		tmp = Float64(x + Float64(x * Float64(y / z)));
	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;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = x * ((y + z) / z);
	elseif (t_0 <= -2e+174)
		tmp = t_0;
	else
		tmp = x + (x * (y / z));
	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]}, If[LessEqual[t$95$0, (-Infinity)], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e+174], t$95$0, N[(x + N[(x * N[(y / 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 -\infty:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{+174}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.5
Target2.9
Herbie2.3
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
      Proof
      (*.f64 x (/.f64 (+.f64 y z) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 97 points increase in error, 14 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -2.00000000000000014e174

    1. Initial program 0.2

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

    if -2.00000000000000014e174 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 8.8

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Taylor expanded in y around 0 3.6

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

      \[\leadsto \color{blue}{x + \frac{y}{z} \cdot x} \]
      Proof
      (+.f64 x (*.f64 (/.f64 y z) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 z x)))): 36 points increase in error, 13 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) z))): 37 points increase in error, 32 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 (*.f64 y x) z) x)): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -\infty:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq -2 \cdot 10^{+174}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error20.3
Cost584
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{+201}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+56}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error21.0
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{+201}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+56}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \end{array} \]
Alternative 3
Error3.1
Cost448
\[x \cdot \frac{y + z}{z} \]
Alternative 4
Error3.1
Cost448
\[x + x \cdot \frac{y}{z} \]
Alternative 5
Error25.4
Cost64
\[x \]

Error

Reproduce

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