?

Average Error: 15.2 → 8.3
Time: 2.7s
Precision: binary64
Cost: 3152

?

\[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
\[\begin{array}{l} t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;t_0 \leq -4 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;t_0 \leq 10^{+143}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (* x 2.0) y) (- x y))))
   (if (<= t_0 (- INFINITY))
     (* -2.0 x)
     (if (<= t_0 -4e-307)
       t_0
       (if (<= t_0 0.0) (* 2.0 y) (if (<= t_0 1e+143) t_0 (* 2.0 y)))))))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double t_0 = ((x * 2.0) * y) / (x - y);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = -2.0 * x;
	} else if (t_0 <= -4e-307) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = 2.0 * y;
	} else if (t_0 <= 1e+143) {
		tmp = t_0;
	} else {
		tmp = 2.0 * y;
	}
	return tmp;
}
public static double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
public static double code(double x, double y) {
	double t_0 = ((x * 2.0) * y) / (x - y);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = -2.0 * x;
	} else if (t_0 <= -4e-307) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = 2.0 * y;
	} else if (t_0 <= 1e+143) {
		tmp = t_0;
	} else {
		tmp = 2.0 * y;
	}
	return tmp;
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
def code(x, y):
	t_0 = ((x * 2.0) * y) / (x - y)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = -2.0 * x
	elif t_0 <= -4e-307:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = 2.0 * y
	elif t_0 <= 1e+143:
		tmp = t_0
	else:
		tmp = 2.0 * y
	return tmp
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
end
function code(x, y)
	t_0 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(-2.0 * x);
	elseif (t_0 <= -4e-307)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(2.0 * y);
	elseif (t_0 <= 1e+143)
		tmp = t_0;
	else
		tmp = Float64(2.0 * y);
	end
	return tmp
end
function tmp = code(x, y)
	tmp = ((x * 2.0) * y) / (x - y);
end
function tmp_2 = code(x, y)
	t_0 = ((x * 2.0) * y) / (x - y);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = -2.0 * x;
	elseif (t_0 <= -4e-307)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = 2.0 * y;
	elseif (t_0 <= 1e+143)
		tmp = t_0;
	else
		tmp = 2.0 * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(-2.0 * x), $MachinePrecision], If[LessEqual[t$95$0, -4e-307], t$95$0, If[LessEqual[t$95$0, 0.0], N[(2.0 * y), $MachinePrecision], If[LessEqual[t$95$0, 1e+143], t$95$0, N[(2.0 * y), $MachinePrecision]]]]]]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;-2 \cdot x\\

\mathbf{elif}\;t_0 \leq -4 \cdot 10^{-307}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;2 \cdot y\\

\mathbf{elif}\;t_0 \leq 10^{+143}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;2 \cdot y\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.2
Target0.4
Herbie8.3
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array} \]

Derivation?

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

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{-2 \cdot x} \]

    if -inf.0 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -3.99999999999999964e-307 or -0.0 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 1e143

    1. Initial program 0.5

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]

    if -3.99999999999999964e-307 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -0.0 or 1e143 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y))

    1. Initial program 60.2

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Taylor expanded in x around inf 32.5

      \[\leadsto \color{blue}{2 \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.3

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

Alternatives

Alternative 1
Error17.0
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{-13}:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-28}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+79}:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+133}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x\\ \end{array} \]
Alternative 2
Error32.0
Cost192
\[-2 \cdot x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))