?

Average Error: 12.4 → 0.9
Time: 5.2s
Precision: binary64
Cost: 2512

?

\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z} + x\\ t_1 := \frac{x \cdot \left(y + z\right)}{z}\\ t_2 := x + x \cdot \frac{y}{z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+221}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ (* y x) z) x))
        (t_1 (/ (* x (+ y z)) z))
        (t_2 (+ x (* x (/ y z)))))
   (if (<= t_1 (- INFINITY))
     t_2
     (if (<= t_1 -5e+69)
       t_0
       (if (<= t_1 0.0) t_2 (if (<= t_1 2e+221) t_0 t_2))))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double t_0 = ((y * x) / z) + x;
	double t_1 = (x * (y + z)) / z;
	double t_2 = x + (x * (y / z));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2;
	} else if (t_1 <= -5e+69) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = t_2;
	} else if (t_1 <= 2e+221) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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 = ((y * x) / z) + x;
	double t_1 = (x * (y + z)) / z;
	double t_2 = x + (x * (y / z));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = t_2;
	} else if (t_1 <= -5e+69) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = t_2;
	} else if (t_1 <= 2e+221) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = ((y * x) / z) + x
	t_1 = (x * (y + z)) / z
	t_2 = x + (x * (y / z))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = t_2
	elif t_1 <= -5e+69:
		tmp = t_0
	elif t_1 <= 0.0:
		tmp = t_2
	elif t_1 <= 2e+221:
		tmp = t_0
	else:
		tmp = t_2
	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(Float64(y * x) / z) + x)
	t_1 = Float64(Float64(x * Float64(y + z)) / z)
	t_2 = Float64(x + Float64(x * Float64(y / z)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = t_2;
	elseif (t_1 <= -5e+69)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = t_2;
	elseif (t_1 <= 2e+221)
		tmp = t_0;
	else
		tmp = t_2;
	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 = ((y * x) / z) + x;
	t_1 = (x * (y + z)) / z;
	t_2 = x + (x * (y / z));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = t_2;
	elseif (t_1 <= -5e+69)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = t_2;
	elseif (t_1 <= 2e+221)
		tmp = t_0;
	else
		tmp = t_2;
	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[(N[(y * x), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, -5e+69], t$95$0, If[LessEqual[t$95$1, 0.0], t$95$2, If[LessEqual[t$95$1, 2e+221], t$95$0, t$95$2]]]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{y \cdot x}{z} + x\\
t_1 := \frac{x \cdot \left(y + z\right)}{z}\\
t_2 := x + x \cdot \frac{y}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -5 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+221}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.4
Target3.3
Herbie0.9
\[\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.00000000000000036e69 < (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0 or 2.0000000000000001e221 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 25.1

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    3. Taylor expanded in x around 0 1.7

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

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

      [Start]1.7

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]1.7

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]1.7

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]1.7

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]1.7

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

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -5.00000000000000036e69 or 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 2.0000000000000001e221

    1. Initial program 0.3

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. 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 simplification0.9

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

Alternatives

Alternative 1
Error19.4
Cost848
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{-6}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4500:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error3.7
Cost448
\[x + x \cdot \frac{y}{z} \]
Alternative 3
Error26.0
Cost64
\[x \]

Error

Reproduce?

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