Data.Colour.RGB:hslsv from colour-2.3.3, C

Percentage Accurate: 100.0% → 100.0%
Time: 6.9s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{x - y}{2 - \left(x + y\right)} \end{array} \]
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
def code(x, y):
	return (x - y) / (2.0 - (x + y))
function code(x, y)
	return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y)))
end
function tmp = code(x, y)
	tmp = (x - y) / (2.0 - (x + y));
end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x - y}{2 - \left(x + y\right)} \end{array} \]
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
def code(x, y):
	return (x - y) / (2.0 - (x + y))
function code(x, y)
	return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y)))
end
function tmp = code(x, y)
	tmp = (x - y) / (2.0 - (x + y));
end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}

Alternative 1: 100.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 - \left(x + y\right)\\ \frac{x}{t_0} - \frac{y}{t_0} \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 2.0 (+ x y)))) (- (/ x t_0) (/ y t_0))))
double code(double x, double y) {
	double t_0 = 2.0 - (x + y);
	return (x / t_0) - (y / t_0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    t_0 = 2.0d0 - (x + y)
    code = (x / t_0) - (y / t_0)
end function
public static double code(double x, double y) {
	double t_0 = 2.0 - (x + y);
	return (x / t_0) - (y / t_0);
}
def code(x, y):
	t_0 = 2.0 - (x + y)
	return (x / t_0) - (y / t_0)
function code(x, y)
	t_0 = Float64(2.0 - Float64(x + y))
	return Float64(Float64(x / t_0) - Float64(y / t_0))
end
function tmp = code(x, y)
	t_0 = 2.0 - (x + y);
	tmp = (x / t_0) - (y / t_0);
end
code[x_, y_] := Block[{t$95$0 = N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]}, N[(N[(x / t$95$0), $MachinePrecision] - N[(y / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 - \left(x + y\right)\\
\frac{x}{t_0} - \frac{y}{t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{x - y}{2 - \left(x + y\right)} \]
  2. Step-by-step derivation
    1. associate--r+99.9%

      \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
  4. Step-by-step derivation
    1. div-sub100.0%

      \[\leadsto \color{blue}{\frac{x}{\left(2 - x\right) - y} - \frac{y}{\left(2 - x\right) - y}} \]
    2. associate--l-100.0%

      \[\leadsto \frac{x}{\color{blue}{2 - \left(x + y\right)}} - \frac{y}{\left(2 - x\right) - y} \]
    3. associate--l-100.0%

      \[\leadsto \frac{x}{2 - \left(x + y\right)} - \frac{y}{\color{blue}{2 - \left(x + y\right)}} \]
  5. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{x}{2 - \left(x + y\right)} - \frac{y}{2 - \left(x + y\right)}} \]
  6. Final simplification100.0%

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

Alternative 2: 61.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \frac{x}{y}\\ \mathbf{if}\;y \leq -7.3 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-20}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-42}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+21}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 1.0 (/ x y))))
   (if (<= y -7.3e+56)
     t_0
     (if (<= y -5e-20)
       -1.0
       (if (<= y -3.8e-42)
         (* y -0.5)
         (if (<= y 3.4e-116)
           -1.0
           (if (<= y 2e-85) (* x 0.5) (if (<= y 2.5e+21) -1.0 t_0))))))))
double code(double x, double y) {
	double t_0 = 1.0 - (x / y);
	double tmp;
	if (y <= -7.3e+56) {
		tmp = t_0;
	} else if (y <= -5e-20) {
		tmp = -1.0;
	} else if (y <= -3.8e-42) {
		tmp = y * -0.5;
	} else if (y <= 3.4e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 2.5e+21) {
		tmp = -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
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 = 1.0d0 - (x / y)
    if (y <= (-7.3d+56)) then
        tmp = t_0
    else if (y <= (-5d-20)) then
        tmp = -1.0d0
    else if (y <= (-3.8d-42)) then
        tmp = y * (-0.5d0)
    else if (y <= 3.4d-116) then
        tmp = -1.0d0
    else if (y <= 2d-85) then
        tmp = x * 0.5d0
    else if (y <= 2.5d+21) then
        tmp = -1.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 - (x / y);
	double tmp;
	if (y <= -7.3e+56) {
		tmp = t_0;
	} else if (y <= -5e-20) {
		tmp = -1.0;
	} else if (y <= -3.8e-42) {
		tmp = y * -0.5;
	} else if (y <= 3.4e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 2.5e+21) {
		tmp = -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 - (x / y)
	tmp = 0
	if y <= -7.3e+56:
		tmp = t_0
	elif y <= -5e-20:
		tmp = -1.0
	elif y <= -3.8e-42:
		tmp = y * -0.5
	elif y <= 3.4e-116:
		tmp = -1.0
	elif y <= 2e-85:
		tmp = x * 0.5
	elif y <= 2.5e+21:
		tmp = -1.0
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 - Float64(x / y))
	tmp = 0.0
	if (y <= -7.3e+56)
		tmp = t_0;
	elseif (y <= -5e-20)
		tmp = -1.0;
	elseif (y <= -3.8e-42)
		tmp = Float64(y * -0.5);
	elseif (y <= 3.4e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = Float64(x * 0.5);
	elseif (y <= 2.5e+21)
		tmp = -1.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 - (x / y);
	tmp = 0.0;
	if (y <= -7.3e+56)
		tmp = t_0;
	elseif (y <= -5e-20)
		tmp = -1.0;
	elseif (y <= -3.8e-42)
		tmp = y * -0.5;
	elseif (y <= 3.4e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = x * 0.5;
	elseif (y <= 2.5e+21)
		tmp = -1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.3e+56], t$95$0, If[LessEqual[y, -5e-20], -1.0, If[LessEqual[y, -3.8e-42], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 3.4e-116], -1.0, If[LessEqual[y, 2e-85], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.5e+21], -1.0, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -7.3 \cdot 10^{+56}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -5 \cdot 10^{-20}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -3.8 \cdot 10^{-42}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 2.5 \cdot 10^{+21}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -7.3e56 or 2.5e21 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(2 - x\right) - y}{x - y}}} \]
      2. associate-/r/99.6%

        \[\leadsto \color{blue}{\frac{1}{\left(2 - x\right) - y} \cdot \left(x - y\right)} \]
      3. associate--l-99.6%

        \[\leadsto \frac{1}{\color{blue}{2 - \left(x + y\right)}} \cdot \left(x - y\right) \]
    5. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{1}{2 - \left(x + y\right)} \cdot \left(x - y\right)} \]
    6. Taylor expanded in y around inf 75.3%

      \[\leadsto \color{blue}{\frac{-1}{y}} \cdot \left(x - y\right) \]
    7. Taylor expanded in y around 0 75.5%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg75.5%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x}{y}\right)} \]
      2. unsub-neg75.5%

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    9. Simplified75.5%

      \[\leadsto \color{blue}{1 - \frac{x}{y}} \]

    if -7.3e56 < y < -4.9999999999999999e-20 or -3.80000000000000017e-42 < y < 3.39999999999999992e-116 or 2e-85 < y < 2.5e21

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around inf 65.9%

      \[\leadsto \color{blue}{-1} \]

    if -4.9999999999999999e-20 < y < -3.80000000000000017e-42

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{2 - y}} \]
    5. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-\frac{y}{2 - y}} \]
      2. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    7. Taylor expanded in y around 0 100.0%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot -0.5} \]
    9. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot -0.5} \]

    if 3.39999999999999992e-116 < y < 2e-85

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around 0 57.7%

      \[\leadsto \color{blue}{\frac{x}{2 - x}} \]
    5. Taylor expanded in x around 0 55.6%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
    6. Step-by-step derivation
      1. *-commutative55.6%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    7. Simplified55.6%

      \[\leadsto \color{blue}{x \cdot 0.5} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification70.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.3 \cdot 10^{+56}:\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-20}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-42}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+21}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]

Alternative 3: 74.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{x \cdot -2}{y}\\ t_1 := \frac{x}{2 - x}\\ \mathbf{if}\;y \leq -1.05 \cdot 10^{+57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ (* x -2.0) y))) (t_1 (/ x (- 2.0 x))))
   (if (<= y -1.05e+57)
     t_0
     (if (<= y -2.5e-18)
       t_1
       (if (<= y -1.8e-41) (* y -0.5) (if (<= y 4.1e+22) t_1 t_0))))))
double code(double x, double y) {
	double t_0 = 1.0 + ((x * -2.0) / y);
	double t_1 = x / (2.0 - x);
	double tmp;
	if (y <= -1.05e+57) {
		tmp = t_0;
	} else if (y <= -2.5e-18) {
		tmp = t_1;
	} else if (y <= -1.8e-41) {
		tmp = y * -0.5;
	} else if (y <= 4.1e+22) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 + ((x * (-2.0d0)) / y)
    t_1 = x / (2.0d0 - x)
    if (y <= (-1.05d+57)) then
        tmp = t_0
    else if (y <= (-2.5d-18)) then
        tmp = t_1
    else if (y <= (-1.8d-41)) then
        tmp = y * (-0.5d0)
    else if (y <= 4.1d+22) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 + ((x * -2.0) / y);
	double t_1 = x / (2.0 - x);
	double tmp;
	if (y <= -1.05e+57) {
		tmp = t_0;
	} else if (y <= -2.5e-18) {
		tmp = t_1;
	} else if (y <= -1.8e-41) {
		tmp = y * -0.5;
	} else if (y <= 4.1e+22) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 + ((x * -2.0) / y)
	t_1 = x / (2.0 - x)
	tmp = 0
	if y <= -1.05e+57:
		tmp = t_0
	elif y <= -2.5e-18:
		tmp = t_1
	elif y <= -1.8e-41:
		tmp = y * -0.5
	elif y <= 4.1e+22:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 + Float64(Float64(x * -2.0) / y))
	t_1 = Float64(x / Float64(2.0 - x))
	tmp = 0.0
	if (y <= -1.05e+57)
		tmp = t_0;
	elseif (y <= -2.5e-18)
		tmp = t_1;
	elseif (y <= -1.8e-41)
		tmp = Float64(y * -0.5);
	elseif (y <= 4.1e+22)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 + ((x * -2.0) / y);
	t_1 = x / (2.0 - x);
	tmp = 0.0;
	if (y <= -1.05e+57)
		tmp = t_0;
	elseif (y <= -2.5e-18)
		tmp = t_1;
	elseif (y <= -1.8e-41)
		tmp = y * -0.5;
	elseif (y <= 4.1e+22)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x * -2.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.05e+57], t$95$0, If[LessEqual[y, -2.5e-18], t$95$1, If[LessEqual[y, -1.8e-41], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 4.1e+22], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \frac{x \cdot -2}{y}\\
t_1 := \frac{x}{2 - x}\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{+57}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -2.5 \cdot 10^{-18}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.8 \cdot 10^{-41}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 4.1 \cdot 10^{+22}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.04999999999999995e57 or 4.09999999999999979e22 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around inf 76.1%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{x}{y}\right) - -1 \cdot \frac{2 - x}{y}} \]
    5. Step-by-step derivation
      1. associate--l+76.2%

        \[\leadsto \color{blue}{1 + \left(-1 \cdot \frac{x}{y} - -1 \cdot \frac{2 - x}{y}\right)} \]
      2. associate-*r/76.2%

        \[\leadsto 1 + \left(\color{blue}{\frac{-1 \cdot x}{y}} - -1 \cdot \frac{2 - x}{y}\right) \]
      3. associate-*r/76.2%

        \[\leadsto 1 + \left(\frac{-1 \cdot x}{y} - \color{blue}{\frac{-1 \cdot \left(2 - x\right)}{y}}\right) \]
      4. div-sub76.2%

        \[\leadsto 1 + \color{blue}{\frac{-1 \cdot x - -1 \cdot \left(2 - x\right)}{y}} \]
      5. cancel-sign-sub-inv76.2%

        \[\leadsto 1 + \frac{\color{blue}{-1 \cdot x + \left(--1\right) \cdot \left(2 - x\right)}}{y} \]
      6. metadata-eval76.2%

        \[\leadsto 1 + \frac{-1 \cdot x + \color{blue}{1} \cdot \left(2 - x\right)}{y} \]
      7. *-lft-identity76.2%

        \[\leadsto 1 + \frac{-1 \cdot x + \color{blue}{\left(2 - x\right)}}{y} \]
      8. +-commutative76.2%

        \[\leadsto 1 + \frac{\color{blue}{\left(2 - x\right) + -1 \cdot x}}{y} \]
      9. mul-1-neg76.2%

        \[\leadsto 1 + \frac{\left(2 - x\right) + \color{blue}{\left(-x\right)}}{y} \]
      10. unsub-neg76.2%

        \[\leadsto 1 + \frac{\color{blue}{\left(2 - x\right) - x}}{y} \]
    6. Simplified76.2%

      \[\leadsto \color{blue}{1 + \frac{\left(2 - x\right) - x}{y}} \]
    7. Taylor expanded in x around inf 76.2%

      \[\leadsto 1 + \frac{\color{blue}{-2 \cdot x}}{y} \]
    8. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot -2}}{y} \]
    9. Simplified76.2%

      \[\leadsto 1 + \frac{\color{blue}{x \cdot -2}}{y} \]

    if -1.04999999999999995e57 < y < -2.50000000000000018e-18 or -1.8e-41 < y < 4.09999999999999979e22

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around 0 82.8%

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

    if -2.50000000000000018e-18 < y < -1.8e-41

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{2 - y}} \]
    5. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-\frac{y}{2 - y}} \]
      2. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    7. Taylor expanded in y around 0 100.0%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot -0.5} \]
    9. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot -0.5} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{+57}:\\ \;\;\;\;1 + \frac{x \cdot -2}{y}\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-18}:\\ \;\;\;\;\frac{x}{2 - x}\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{+22}:\\ \;\;\;\;\frac{x}{2 - x}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x \cdot -2}{y}\\ \end{array} \]

Alternative 4: 61.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-20}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{+22}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -3.9e+55)
   1.0
   (if (<= y -7e-20)
     -1.0
     (if (<= y -1.85e-41)
       (* y -0.5)
       (if (<= y 3.4e-116)
         -1.0
         (if (<= y 2e-85) (* x 0.5) (if (<= y 9.6e+22) -1.0 1.0)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -3.9e+55) {
		tmp = 1.0;
	} else if (y <= -7e-20) {
		tmp = -1.0;
	} else if (y <= -1.85e-41) {
		tmp = y * -0.5;
	} else if (y <= 3.4e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 9.6e+22) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-3.9d+55)) then
        tmp = 1.0d0
    else if (y <= (-7d-20)) then
        tmp = -1.0d0
    else if (y <= (-1.85d-41)) then
        tmp = y * (-0.5d0)
    else if (y <= 3.4d-116) then
        tmp = -1.0d0
    else if (y <= 2d-85) then
        tmp = x * 0.5d0
    else if (y <= 9.6d+22) then
        tmp = -1.0d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -3.9e+55) {
		tmp = 1.0;
	} else if (y <= -7e-20) {
		tmp = -1.0;
	} else if (y <= -1.85e-41) {
		tmp = y * -0.5;
	} else if (y <= 3.4e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 9.6e+22) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -3.9e+55:
		tmp = 1.0
	elif y <= -7e-20:
		tmp = -1.0
	elif y <= -1.85e-41:
		tmp = y * -0.5
	elif y <= 3.4e-116:
		tmp = -1.0
	elif y <= 2e-85:
		tmp = x * 0.5
	elif y <= 9.6e+22:
		tmp = -1.0
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -3.9e+55)
		tmp = 1.0;
	elseif (y <= -7e-20)
		tmp = -1.0;
	elseif (y <= -1.85e-41)
		tmp = Float64(y * -0.5);
	elseif (y <= 3.4e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = Float64(x * 0.5);
	elseif (y <= 9.6e+22)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -3.9e+55)
		tmp = 1.0;
	elseif (y <= -7e-20)
		tmp = -1.0;
	elseif (y <= -1.85e-41)
		tmp = y * -0.5;
	elseif (y <= 3.4e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = x * 0.5;
	elseif (y <= 9.6e+22)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -3.9e+55], 1.0, If[LessEqual[y, -7e-20], -1.0, If[LessEqual[y, -1.85e-41], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 3.4e-116], -1.0, If[LessEqual[y, 2e-85], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 9.6e+22], -1.0, 1.0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+55}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq -7 \cdot 10^{-20}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 9.6 \cdot 10^{+22}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -3.90000000000000027e55 or 9.6e22 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around inf 74.9%

      \[\leadsto \color{blue}{1} \]

    if -3.90000000000000027e55 < y < -7.00000000000000007e-20 or -1.8500000000000001e-41 < y < 3.39999999999999992e-116 or 2e-85 < y < 9.6e22

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around inf 65.9%

      \[\leadsto \color{blue}{-1} \]

    if -7.00000000000000007e-20 < y < -1.8500000000000001e-41

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{2 - y}} \]
    5. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-\frac{y}{2 - y}} \]
      2. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    7. Taylor expanded in y around 0 100.0%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot -0.5} \]
    9. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot -0.5} \]

    if 3.39999999999999992e-116 < y < 2e-85

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around 0 57.7%

      \[\leadsto \color{blue}{\frac{x}{2 - x}} \]
    5. Taylor expanded in x around 0 55.6%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
    6. Step-by-step derivation
      1. *-commutative55.6%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    7. Simplified55.6%

      \[\leadsto \color{blue}{x \cdot 0.5} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification70.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-20}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{+22}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 5: 73.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \frac{x}{y}\\ t_1 := \frac{x}{2 - x}\\ \mathbf{if}\;y \leq -8.2 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 1.0 (/ x y))) (t_1 (/ x (- 2.0 x))))
   (if (<= y -8.2e+56)
     t_0
     (if (<= y -1.65e-19)
       t_1
       (if (<= y -1.85e-41) (* y -0.5) (if (<= y 6.2e+24) t_1 t_0))))))
double code(double x, double y) {
	double t_0 = 1.0 - (x / y);
	double t_1 = x / (2.0 - x);
	double tmp;
	if (y <= -8.2e+56) {
		tmp = t_0;
	} else if (y <= -1.65e-19) {
		tmp = t_1;
	} else if (y <= -1.85e-41) {
		tmp = y * -0.5;
	} else if (y <= 6.2e+24) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 - (x / y)
    t_1 = x / (2.0d0 - x)
    if (y <= (-8.2d+56)) then
        tmp = t_0
    else if (y <= (-1.65d-19)) then
        tmp = t_1
    else if (y <= (-1.85d-41)) then
        tmp = y * (-0.5d0)
    else if (y <= 6.2d+24) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 - (x / y);
	double t_1 = x / (2.0 - x);
	double tmp;
	if (y <= -8.2e+56) {
		tmp = t_0;
	} else if (y <= -1.65e-19) {
		tmp = t_1;
	} else if (y <= -1.85e-41) {
		tmp = y * -0.5;
	} else if (y <= 6.2e+24) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 - (x / y)
	t_1 = x / (2.0 - x)
	tmp = 0
	if y <= -8.2e+56:
		tmp = t_0
	elif y <= -1.65e-19:
		tmp = t_1
	elif y <= -1.85e-41:
		tmp = y * -0.5
	elif y <= 6.2e+24:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 - Float64(x / y))
	t_1 = Float64(x / Float64(2.0 - x))
	tmp = 0.0
	if (y <= -8.2e+56)
		tmp = t_0;
	elseif (y <= -1.65e-19)
		tmp = t_1;
	elseif (y <= -1.85e-41)
		tmp = Float64(y * -0.5);
	elseif (y <= 6.2e+24)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 - (x / y);
	t_1 = x / (2.0 - x);
	tmp = 0.0;
	if (y <= -8.2e+56)
		tmp = t_0;
	elseif (y <= -1.65e-19)
		tmp = t_1;
	elseif (y <= -1.85e-41)
		tmp = y * -0.5;
	elseif (y <= 6.2e+24)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.2e+56], t$95$0, If[LessEqual[y, -1.65e-19], t$95$1, If[LessEqual[y, -1.85e-41], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 6.2e+24], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
t_1 := \frac{x}{2 - x}\\
\mathbf{if}\;y \leq -8.2 \cdot 10^{+56}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.65 \cdot 10^{-19}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 6.2 \cdot 10^{+24}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.2000000000000007e56 or 6.20000000000000022e24 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(2 - x\right) - y}{x - y}}} \]
      2. associate-/r/99.6%

        \[\leadsto \color{blue}{\frac{1}{\left(2 - x\right) - y} \cdot \left(x - y\right)} \]
      3. associate--l-99.6%

        \[\leadsto \frac{1}{\color{blue}{2 - \left(x + y\right)}} \cdot \left(x - y\right) \]
    5. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{1}{2 - \left(x + y\right)} \cdot \left(x - y\right)} \]
    6. Taylor expanded in y around inf 75.3%

      \[\leadsto \color{blue}{\frac{-1}{y}} \cdot \left(x - y\right) \]
    7. Taylor expanded in y around 0 75.5%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg75.5%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x}{y}\right)} \]
      2. unsub-neg75.5%

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    9. Simplified75.5%

      \[\leadsto \color{blue}{1 - \frac{x}{y}} \]

    if -8.2000000000000007e56 < y < -1.6499999999999999e-19 or -1.8500000000000001e-41 < y < 6.20000000000000022e24

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around 0 82.8%

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

    if -1.6499999999999999e-19 < y < -1.8500000000000001e-41

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{2 - y}} \]
    5. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-\frac{y}{2 - y}} \]
      2. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-y}{2 - y}} \]
    7. Taylor expanded in y around 0 100.0%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot -0.5} \]
    9. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot -0.5} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+56}:\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-19}:\\ \;\;\;\;\frac{x}{2 - x}\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+24}:\\ \;\;\;\;\frac{x}{2 - x}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]

Alternative 6: 61.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+61}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+19}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -2e+61)
   1.0
   (if (<= y 3.3e-116)
     -1.0
     (if (<= y 2e-85) (* x 0.5) (if (<= y 4e+19) -1.0 1.0)))))
double code(double x, double y) {
	double tmp;
	if (y <= -2e+61) {
		tmp = 1.0;
	} else if (y <= 3.3e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 4e+19) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-2d+61)) then
        tmp = 1.0d0
    else if (y <= 3.3d-116) then
        tmp = -1.0d0
    else if (y <= 2d-85) then
        tmp = x * 0.5d0
    else if (y <= 4d+19) then
        tmp = -1.0d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -2e+61) {
		tmp = 1.0;
	} else if (y <= 3.3e-116) {
		tmp = -1.0;
	} else if (y <= 2e-85) {
		tmp = x * 0.5;
	} else if (y <= 4e+19) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -2e+61:
		tmp = 1.0
	elif y <= 3.3e-116:
		tmp = -1.0
	elif y <= 2e-85:
		tmp = x * 0.5
	elif y <= 4e+19:
		tmp = -1.0
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -2e+61)
		tmp = 1.0;
	elseif (y <= 3.3e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = Float64(x * 0.5);
	elseif (y <= 4e+19)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -2e+61)
		tmp = 1.0;
	elseif (y <= 3.3e-116)
		tmp = -1.0;
	elseif (y <= 2e-85)
		tmp = x * 0.5;
	elseif (y <= 4e+19)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -2e+61], 1.0, If[LessEqual[y, 3.3e-116], -1.0, If[LessEqual[y, 2e-85], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 4e+19], -1.0, 1.0]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+61}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 3.3 \cdot 10^{-116}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 4 \cdot 10^{+19}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.9999999999999999e61 or 4e19 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around inf 74.9%

      \[\leadsto \color{blue}{1} \]

    if -1.9999999999999999e61 < y < 3.30000000000000001e-116 or 2e-85 < y < 4e19

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around inf 61.9%

      \[\leadsto \color{blue}{-1} \]

    if 3.30000000000000001e-116 < y < 2e-85

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around 0 57.7%

      \[\leadsto \color{blue}{\frac{x}{2 - x}} \]
    5. Taylor expanded in x around 0 55.6%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
    6. Step-by-step derivation
      1. *-commutative55.6%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    7. Simplified55.6%

      \[\leadsto \color{blue}{x \cdot 0.5} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+61}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-85}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+19}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 7: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x - y}{2 - \left(x + y\right)} \end{array} \]
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
def code(x, y):
	return (x - y) / (2.0 - (x + y))
function code(x, y)
	return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y)))
end
function tmp = code(x, y)
	tmp = (x - y) / (2.0 - (x + y));
end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{x - y}{2 - \left(x + y\right)} \]
  2. Final simplification99.9%

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

Alternative 8: 62.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+59}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{+24}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.85e+59) 1.0 (if (<= y 1e+24) -1.0 1.0)))
double code(double x, double y) {
	double tmp;
	if (y <= -1.85e+59) {
		tmp = 1.0;
	} else if (y <= 1e+24) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.85d+59)) then
        tmp = 1.0d0
    else if (y <= 1d+24) then
        tmp = -1.0d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.85e+59) {
		tmp = 1.0;
	} else if (y <= 1e+24) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.85e+59:
		tmp = 1.0
	elif y <= 1e+24:
		tmp = -1.0
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.85e+59)
		tmp = 1.0;
	elseif (y <= 1e+24)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.85e+59)
		tmp = 1.0;
	elseif (y <= 1e+24)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.85e+59], 1.0, If[LessEqual[y, 1e+24], -1.0, 1.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{+59}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 10^{+24}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.84999999999999999e59 or 9.9999999999999998e23 < y

    1. Initial program 99.9%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in y around inf 74.9%

      \[\leadsto \color{blue}{1} \]

    if -1.84999999999999999e59 < y < 9.9999999999999998e23

    1. Initial program 100.0%

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Step-by-step derivation
      1. associate--r+100.0%

        \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    4. Taylor expanded in x around inf 57.9%

      \[\leadsto \color{blue}{-1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+59}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{+24}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 38.9% accurate, 9.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
	return -1.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -1.0d0
end function
public static double code(double x, double y) {
	return -1.0;
}
def code(x, y):
	return -1.0
function code(x, y)
	return -1.0
end
function tmp = code(x, y)
	tmp = -1.0;
end
code[x_, y_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{x - y}{2 - \left(x + y\right)} \]
  2. Step-by-step derivation
    1. associate--r+99.9%

      \[\leadsto \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
  4. Taylor expanded in x around inf 41.9%

    \[\leadsto \color{blue}{-1} \]
  5. Final simplification41.9%

    \[\leadsto -1 \]

Developer target: 100.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 - \left(x + y\right)\\ \frac{x}{t_0} - \frac{y}{t_0} \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 2.0 (+ x y)))) (- (/ x t_0) (/ y t_0))))
double code(double x, double y) {
	double t_0 = 2.0 - (x + y);
	return (x / t_0) - (y / t_0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    t_0 = 2.0d0 - (x + y)
    code = (x / t_0) - (y / t_0)
end function
public static double code(double x, double y) {
	double t_0 = 2.0 - (x + y);
	return (x / t_0) - (y / t_0);
}
def code(x, y):
	t_0 = 2.0 - (x + y)
	return (x / t_0) - (y / t_0)
function code(x, y)
	t_0 = Float64(2.0 - Float64(x + y))
	return Float64(Float64(x / t_0) - Float64(y / t_0))
end
function tmp = code(x, y)
	t_0 = 2.0 - (x + y);
	tmp = (x / t_0) - (y / t_0);
end
code[x_, y_] := Block[{t$95$0 = N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]}, N[(N[(x / t$95$0), $MachinePrecision] - N[(y / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 - \left(x + y\right)\\
\frac{x}{t_0} - \frac{y}{t_0}
\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023173 
(FPCore (x y)
  :name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
  :precision binary64

  :herbie-target
  (- (/ x (- 2.0 (+ x y))) (/ y (- 2.0 (+ x y))))

  (/ (- x y) (- 2.0 (+ x y))))