?

Average Error: 15.4 → 8.3
Time: 5.4s
Precision: binary64
Cost: 1104

?

\[\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}\;y \leq -4.9 \cdot 10^{+151}:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-137}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-201}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{+143}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x\\ \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 (<= y -4.9e+151)
     (* -2.0 x)
     (if (<= y -2.9e-137)
       t_0
       (if (<= y 1e-201) (* 2.0 y) (if (<= y 1.42e+143) t_0 (* -2.0 x)))))))
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 (y <= -4.9e+151) {
		tmp = -2.0 * x;
	} else if (y <= -2.9e-137) {
		tmp = t_0;
	} else if (y <= 1e-201) {
		tmp = 2.0 * y;
	} else if (y <= 1.42e+143) {
		tmp = t_0;
	} else {
		tmp = -2.0 * x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * 2.0d0) * y) / (x - y)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((x * 2.0d0) * y) / (x - y)
    if (y <= (-4.9d+151)) then
        tmp = (-2.0d0) * x
    else if (y <= (-2.9d-137)) then
        tmp = t_0
    else if (y <= 1d-201) then
        tmp = 2.0d0 * y
    else if (y <= 1.42d+143) then
        tmp = t_0
    else
        tmp = (-2.0d0) * x
    end if
    code = tmp
end function
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 (y <= -4.9e+151) {
		tmp = -2.0 * x;
	} else if (y <= -2.9e-137) {
		tmp = t_0;
	} else if (y <= 1e-201) {
		tmp = 2.0 * y;
	} else if (y <= 1.42e+143) {
		tmp = t_0;
	} else {
		tmp = -2.0 * x;
	}
	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 y <= -4.9e+151:
		tmp = -2.0 * x
	elif y <= -2.9e-137:
		tmp = t_0
	elif y <= 1e-201:
		tmp = 2.0 * y
	elif y <= 1.42e+143:
		tmp = t_0
	else:
		tmp = -2.0 * x
	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 (y <= -4.9e+151)
		tmp = Float64(-2.0 * x);
	elseif (y <= -2.9e-137)
		tmp = t_0;
	elseif (y <= 1e-201)
		tmp = Float64(2.0 * y);
	elseif (y <= 1.42e+143)
		tmp = t_0;
	else
		tmp = Float64(-2.0 * x);
	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 (y <= -4.9e+151)
		tmp = -2.0 * x;
	elseif (y <= -2.9e-137)
		tmp = t_0;
	elseif (y <= 1e-201)
		tmp = 2.0 * y;
	elseif (y <= 1.42e+143)
		tmp = t_0;
	else
		tmp = -2.0 * x;
	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[y, -4.9e+151], N[(-2.0 * x), $MachinePrecision], If[LessEqual[y, -2.9e-137], t$95$0, If[LessEqual[y, 1e-201], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, 1.42e+143], t$95$0, N[(-2.0 * x), $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}\;y \leq -4.9 \cdot 10^{+151}:\\
\;\;\;\;-2 \cdot x\\

\mathbf{elif}\;y \leq -2.9 \cdot 10^{-137}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 10^{-201}:\\
\;\;\;\;2 \cdot y\\

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

\mathbf{else}:\\
\;\;\;\;-2 \cdot x\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.4
Target0.3
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 y < -4.8999999999999999e151 or 1.42e143 < y

    1. Initial program 23.9

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

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

    if -4.8999999999999999e151 < y < -2.89999999999999985e-137 or 9.99999999999999946e-202 < y < 1.42e143

    1. Initial program 7.9

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

    if -2.89999999999999985e-137 < y < 9.99999999999999946e-202

    1. Initial program 22.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+151}:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-137}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;y \leq 10^{-201}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{+143}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error16.2
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -50000000000000:\\ \;\;\;\;-2 \cdot x\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-50}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x\\ \end{array} \]
Alternative 2
Error32.2
Cost192
\[-2 \cdot x \]

Error

Reproduce?

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