Kahan p9 Example

Percentage Accurate: 67.8% → 100.0%
Time: 11.3s
Alternatives: 13
Speedup: 2.1×

Specification

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

\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\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 13 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: 67.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (/ (/ (- x y) (hypot x y)) (/ (hypot x y) (+ x y))))
y = abs(y);
double code(double x, double y) {
	return ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
}
y = Math.abs(y);
public static double code(double x, double y) {
	return ((x - y) / Math.hypot(x, y)) / (Math.hypot(x, y) / (x + y));
}
y = abs(y)
def code(x, y):
	return ((x - y) / math.hypot(x, y)) / (math.hypot(x, y) / (x + y))
y = abs(y)
function code(x, y)
	return Float64(Float64(Float64(x - y) / hypot(x, y)) / Float64(hypot(x, y) / Float64(x + y)))
end
y = abs(y)
function tmp = code(x, y)
	tmp = ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
end
NOTE: y should be positive before calling this function
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Derivation
  1. Initial program 65.9%

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

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
    3. fma-def65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  3. Simplified65.9%

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  4. Step-by-step derivation
    1. fma-udef65.9%

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
    3. *-un-lft-identity65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{1 \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
    4. add-sqr-sqrt65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
    5. times-frac66.0%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
    6. hypot-def66.1%

      \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
    7. hypot-def99.6%

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

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
  6. Step-by-step derivation
    1. associate-*l/99.6%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    2. *-lft-identity99.6%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
    3. +-commutative99.6%

      \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
  7. Simplified99.6%

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
  8. Step-by-step derivation
    1. associate-/l/65.9%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}} \]
    2. +-commutative65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{x + y}}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)} \]
    3. clear-num66.0%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    4. *-un-lft-identity66.0%

      \[\leadsto \left(x - y\right) \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{\color{blue}{1 \cdot \left(x + y\right)}}} \]
    5. frac-times99.7%

      \[\leadsto \left(x - y\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    6. div-inv99.9%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    7. /-rgt-identity99.9%

      \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
    8. associate-/r*99.9%

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  9. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  10. Final simplification99.9%

    \[\leadsto \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]

Alternative 2: 99.7% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (* (- x y) (/ (/ (+ x y) (hypot x y)) (hypot x y))))
y = abs(y);
double code(double x, double y) {
	return (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y));
}
y = Math.abs(y);
public static double code(double x, double y) {
	return (x - y) * (((x + y) / Math.hypot(x, y)) / Math.hypot(x, y));
}
y = abs(y)
def code(x, y):
	return (x - y) * (((x + y) / math.hypot(x, y)) / math.hypot(x, y))
y = abs(y)
function code(x, y)
	return Float64(Float64(x - y) * Float64(Float64(Float64(x + y) / hypot(x, y)) / hypot(x, y)))
end
y = abs(y)
function tmp = code(x, y)
	tmp = (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y));
end
NOTE: y should be positive before calling this function
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Derivation
  1. Initial program 65.9%

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

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
    3. fma-def65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  3. Simplified65.9%

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  4. Step-by-step derivation
    1. fma-udef65.9%

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
    3. *-un-lft-identity65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{1 \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
    4. add-sqr-sqrt65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
    5. times-frac66.0%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
    6. hypot-def66.1%

      \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
    7. hypot-def99.6%

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

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
  6. Step-by-step derivation
    1. associate-*l/99.6%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    2. *-lft-identity99.6%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
    3. +-commutative99.6%

      \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
  7. Simplified99.6%

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
  8. Final simplification99.6%

    \[\leadsto \left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]

Alternative 3: 92.5% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ t_1 := \frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(t_1 + -1\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
        (t_1 (* (/ x y) (/ x y))))
   (if (<= t_0 2.0) t_0 (+ t_1 (+ t_1 -1.0)))))
y = abs(y);
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double t_1 = (x / y) * (x / y);
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = t_1 + (t_1 + -1.0);
	}
	return tmp;
}
NOTE: y should be positive before calling this function
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 = ((x - y) * (x + y)) / ((x * x) + (y * y))
    t_1 = (x / y) * (x / y)
    if (t_0 <= 2.0d0) then
        tmp = t_0
    else
        tmp = t_1 + (t_1 + (-1.0d0))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double t_1 = (x / y) * (x / y);
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = t_1 + (t_1 + -1.0);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
	t_1 = (x / y) * (x / y)
	tmp = 0
	if t_0 <= 2.0:
		tmp = t_0
	else:
		tmp = t_1 + (t_1 + -1.0)
	return tmp
y = abs(y)
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	t_1 = Float64(Float64(x / y) * Float64(x / y))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = Float64(t_1 + Float64(t_1 + -1.0));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	t_1 = (x / y) * (x / y);
	tmp = 0.0;
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = t_1 + (t_1 + -1.0);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(t$95$1 + N[(t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
t_1 := \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(t_1 + -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2

    1. Initial program 99.8%

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

    if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))

    1. Initial program 0.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified3.1%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef3.1%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
      3. *-un-lft-identity3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{1 \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
      4. add-sqr-sqrt3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
      5. times-frac3.1%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
      6. hypot-def3.1%

        \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
      7. hypot-def99.6%

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
    6. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
      2. *-lft-identity99.6%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
      3. +-commutative99.6%

        \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Simplified99.6%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    8. Step-by-step derivation
      1. associate-/l/3.1%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}} \]
      2. +-commutative3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{x + y}}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)} \]
      3. clear-num3.1%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      4. *-un-lft-identity3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{\color{blue}{1 \cdot \left(x + y\right)}}} \]
      5. frac-times99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      6. div-inv99.9%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      7. /-rgt-identity99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
      8. associate-/r*99.9%

        \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    9. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    10. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
      2. inv-pow99.9%

        \[\leadsto \frac{\color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{x - y}\right)}^{-1}}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
    11. Applied egg-rr99.9%

      \[\leadsto \frac{\color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{x - y}\right)}^{-1}}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
    12. Step-by-step derivation
      1. unpow-199.9%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
    13. Simplified99.9%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
    14. Taylor expanded in y around inf 58.6%

      \[\leadsto \color{blue}{\left(\frac{{x}^{2}}{{y}^{2}} + \left(\frac{x}{y} + -1 \cdot \frac{x}{y}\right)\right) - \left(-1 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)} \]
    15. Step-by-step derivation
      1. distribute-rgt1-in58.6%

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

        \[\leadsto \left(\frac{{x}^{2}}{{y}^{2}} + \color{blue}{0} \cdot \frac{x}{y}\right) - \left(-1 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right) \]
      3. mul0-lft58.6%

        \[\leadsto \left(\frac{{x}^{2}}{{y}^{2}} + \color{blue}{0}\right) - \left(-1 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right) \]
      4. associate-+r-58.6%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(0 - \left(-1 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)\right) \]
      7. times-frac58.6%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(0 - \left(-1 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)\right) \]
      8. neg-sub058.6%

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

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(-\color{blue}{\left(1 + -1 \cdot \frac{{x}^{2}}{{y}^{2}}\right)}\right) \]
      10. distribute-neg-in58.6%

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

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\color{blue}{-1} + \left(--1 \cdot \frac{{x}^{2}}{{y}^{2}}\right)\right) \]
      12. mul-1-neg58.6%

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(-1 + \left(-\color{blue}{\left(-\frac{{x}^{2}}{{y}^{2}}\right)}\right)\right) \]
      13. remove-double-neg58.6%

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

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

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(-1 + \frac{x \cdot x}{\color{blue}{y \cdot y}}\right) \]
      16. times-frac80.6%

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

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y} + \left(-1 + \frac{x}{y} \cdot \frac{x}{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + \left(\frac{x}{y} \cdot \frac{x}{y} + -1\right)\\ \end{array} \]

Alternative 4: 92.4% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (+ (* (/ x y) (/ x y)) -1.0))))
y = abs(y);
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = ((x / y) * (x / y)) + -1.0;
	}
	return tmp;
}
NOTE: y should be positive before calling this 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 - y) * (x + y)) / ((x * x) + (y * y))
    if (t_0 <= 2.0d0) then
        tmp = t_0
    else
        tmp = ((x / y) * (x / y)) + (-1.0d0)
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = ((x / y) * (x / y)) + -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
	tmp = 0
	if t_0 <= 2.0:
		tmp = t_0
	else:
		tmp = ((x / y) * (x / y)) + -1.0
	return tmp
y = abs(y)
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	tmp = 0.0;
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = ((x / y) * (x / y)) + -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2

    1. Initial program 99.8%

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

    if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))

    1. Initial program 0.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified3.1%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 3.1%

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

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity3.1%

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{y} \cdot \frac{x + y}{y}\right)} \]
    9. Step-by-step derivation
      1. associate-*l/79.8%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    12. Step-by-step derivation
      1. sub-neg58.6%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. times-frac80.3%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(-1\right) \]
      5. metadata-eval80.3%

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{-1} \]
    13. Simplified80.3%

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y} + -1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \end{array} \]

Alternative 5: 83.6% accurate, 0.9× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 2.3 \cdot 10^{-163}:\\ \;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 2.3e-163)
   (- (+ (/ y x) 1.0) (/ y x))
   (if (<= y 1.35e-120)
     (/ (- x y) y)
     (if (<= y 1.25e-111)
       (+ 1.0 (* -2.0 (/ (* y y) (* x x))))
       (+ -1.0 (/ (* x x) (* y y)))))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 2.3e-163) {
		tmp = ((y / x) + 1.0) - (y / x);
	} else if (y <= 1.35e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.25e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 2.3d-163) then
        tmp = ((y / x) + 1.0d0) - (y / x)
    else if (y <= 1.35d-120) then
        tmp = (x - y) / y
    else if (y <= 1.25d-111) then
        tmp = 1.0d0 + ((-2.0d0) * ((y * y) / (x * x)))
    else
        tmp = (-1.0d0) + ((x * x) / (y * y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 2.3e-163) {
		tmp = ((y / x) + 1.0) - (y / x);
	} else if (y <= 1.35e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.25e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 2.3e-163:
		tmp = ((y / x) + 1.0) - (y / x)
	elif y <= 1.35e-120:
		tmp = (x - y) / y
	elif y <= 1.25e-111:
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)))
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 2.3e-163)
		tmp = Float64(Float64(Float64(y / x) + 1.0) - Float64(y / x));
	elseif (y <= 1.35e-120)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.25e-111)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y * y) / Float64(x * x))));
	else
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 2.3e-163)
		tmp = ((y / x) + 1.0) - (y / x);
	elseif (y <= 1.35e-120)
		tmp = (x - y) / y;
	elseif (y <= 1.25e-111)
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	else
		tmp = -1.0 + ((x * x) / (y * y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 2.3e-163], N[(N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e-120], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.25e-111], N[(1.0 + N[(-2.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{-163}:\\
\;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\

\mathbf{elif}\;y \leq 1.35 \cdot 10^{-120}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 2.2999999999999999e-163

    1. Initial program 59.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.2%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
      3. *-un-lft-identity59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
      5. times-frac59.3%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
      6. hypot-def59.3%

        \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
      7. hypot-def99.7%

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
    6. Step-by-step derivation
      1. associate-*l/99.7%

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

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
      3. +-commutative99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Simplified99.7%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    8. Step-by-step derivation
      1. associate-/l/59.2%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}} \]
      2. +-commutative59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{x + y}}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)} \]
      3. clear-num59.2%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      4. *-un-lft-identity59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{\color{blue}{1 \cdot \left(x + y\right)}}} \]
      5. frac-times99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      6. div-inv99.9%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      7. /-rgt-identity99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
      8. associate-/r*99.9%

        \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    9. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    10. Taylor expanded in x around inf 30.3%

      \[\leadsto \color{blue}{\frac{y}{x} + \left(1 + -1 \cdot \frac{y}{x}\right)} \]
    11. Step-by-step derivation
      1. associate-+r+30.3%

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

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

        \[\leadsto \left(1 + \frac{y}{x}\right) + \color{blue}{\frac{-1 \cdot y}{x}} \]
      4. neg-mul-130.3%

        \[\leadsto \left(1 + \frac{y}{x}\right) + \frac{\color{blue}{-y}}{x} \]
    12. Simplified30.3%

      \[\leadsto \color{blue}{\left(1 + \frac{y}{x}\right) + \frac{-y}{x}} \]
    13. Step-by-step derivation
      1. add-sqr-sqrt29.1%

        \[\leadsto \color{blue}{\sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}}} + \frac{-y}{x} \]
      2. distribute-frac-neg29.1%

        \[\leadsto \sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}} + \color{blue}{\left(-\frac{y}{x}\right)} \]
      3. fma-def29.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\frac{y}{x}\right)} \]
      4. add-sqr-sqrt13.0%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{\frac{y}{x}} \cdot \sqrt{\frac{y}{x}}}\right) \]
      5. sqrt-unprod28.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{\frac{y}{x} \cdot \frac{y}{x}}}\right) \]
      6. sqr-neg28.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\sqrt{\color{blue}{\left(-\frac{y}{x}\right) \cdot \left(-\frac{y}{x}\right)}}\right) \]
      7. sqrt-unprod15.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{-\frac{y}{x}} \cdot \sqrt{-\frac{y}{x}}}\right) \]
      8. add-sqr-sqrt28.1%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\left(-\frac{y}{x}\right)}\right) \]
      9. fma-neg28.1%

        \[\leadsto \color{blue}{\sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}} - \left(-\frac{y}{x}\right)} \]
      10. add-sqr-sqrt31.1%

        \[\leadsto \color{blue}{\left(1 + \frac{y}{x}\right)} - \left(-\frac{y}{x}\right) \]
      11. add-sqr-sqrt18.5%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{-\frac{y}{x}} \cdot \sqrt{-\frac{y}{x}}} \]
      12. sqrt-unprod31.4%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{\left(-\frac{y}{x}\right) \cdot \left(-\frac{y}{x}\right)}} \]
      13. sqr-neg31.4%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \sqrt{\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}} \]
      14. sqrt-unprod13.0%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{\frac{y}{x}} \cdot \sqrt{\frac{y}{x}}} \]
      15. add-sqr-sqrt30.3%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\frac{y}{x}} \]
    14. Applied egg-rr30.3%

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

    if 2.2999999999999999e-163 < y < 1.3499999999999999e-120

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.3499999999999999e-120 < y < 1.2500000000000001e-111

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def98.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified98.4%

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow2100.0%

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

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

    if 1.2500000000000001e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    8. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification38.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.3 \cdot 10^{-163}:\\ \;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \]

Alternative 6: 83.7% accurate, 0.9× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 5.5 \cdot 10^{-163}:\\ \;\;\;\;\left(x - y\right) \cdot \left(\frac{1}{x} + \frac{\frac{y}{x}}{x}\right)\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 5.5e-163)
   (* (- x y) (+ (/ 1.0 x) (/ (/ y x) x)))
   (if (<= y 1.4e-120)
     (/ (- x y) y)
     (if (<= y 1.15e-111)
       (+ 1.0 (* -2.0 (/ (* y y) (* x x))))
       (+ -1.0 (/ (* x x) (* y y)))))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 5.5e-163) {
		tmp = (x - y) * ((1.0 / x) + ((y / x) / x));
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.15e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 5.5d-163) then
        tmp = (x - y) * ((1.0d0 / x) + ((y / x) / x))
    else if (y <= 1.4d-120) then
        tmp = (x - y) / y
    else if (y <= 1.15d-111) then
        tmp = 1.0d0 + ((-2.0d0) * ((y * y) / (x * x)))
    else
        tmp = (-1.0d0) + ((x * x) / (y * y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 5.5e-163) {
		tmp = (x - y) * ((1.0 / x) + ((y / x) / x));
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.15e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 5.5e-163:
		tmp = (x - y) * ((1.0 / x) + ((y / x) / x))
	elif y <= 1.4e-120:
		tmp = (x - y) / y
	elif y <= 1.15e-111:
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)))
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 5.5e-163)
		tmp = Float64(Float64(x - y) * Float64(Float64(1.0 / x) + Float64(Float64(y / x) / x)));
	elseif (y <= 1.4e-120)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.15e-111)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y * y) / Float64(x * x))));
	else
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 5.5e-163)
		tmp = (x - y) * ((1.0 / x) + ((y / x) / x));
	elseif (y <= 1.4e-120)
		tmp = (x - y) / y;
	elseif (y <= 1.15e-111)
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	else
		tmp = -1.0 + ((x * x) / (y * y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 5.5e-163], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] + N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-120], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.15e-111], N[(1.0 + N[(-2.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{-163}:\\
\;\;\;\;\left(x - y\right) \cdot \left(\frac{1}{x} + \frac{\frac{y}{x}}{x}\right)\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 5.4999999999999998e-163

    1. Initial program 59.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.2%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
      3. *-un-lft-identity59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
      5. times-frac59.3%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
      6. hypot-def59.3%

        \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
      7. hypot-def99.7%

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
    6. Step-by-step derivation
      1. associate-*l/99.7%

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

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
      3. +-commutative99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Simplified99.7%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    8. Taylor expanded in y around 0 32.3%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{y}{x} + 1}}{\mathsf{hypot}\left(x, y\right)} \]
    9. Taylor expanded in y around 0 23.9%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{y}{{x}^{2}} + \frac{1}{x}\right)} \]
    10. Step-by-step derivation
      1. +-commutative23.9%

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

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

        \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{x} + \color{blue}{\frac{\frac{y}{x}}{x}}\right) \]
    11. Simplified31.7%

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

    if 5.4999999999999998e-163 < y < 1.39999999999999997e-120

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.39999999999999997e-120 < y < 1.15e-111

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def98.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified98.4%

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow2100.0%

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

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

    if 1.15e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    8. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification39.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 5.5 \cdot 10^{-163}:\\ \;\;\;\;\left(x - y\right) \cdot \left(\frac{1}{x} + \frac{\frac{y}{x}}{x}\right)\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \]

Alternative 7: 84.0% accurate, 0.9× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 4.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{x - y}{\left(x - y\right) + y \cdot \frac{y}{x}}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 4.9e-167)
   (/ (- x y) (+ (- x y) (* y (/ y x))))
   (if (<= y 1.4e-120)
     (/ (- x y) y)
     (if (<= y 1.15e-111)
       (+ 1.0 (* -2.0 (/ (* y y) (* x x))))
       (+ -1.0 (/ (* x x) (* y y)))))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 4.9e-167) {
		tmp = (x - y) / ((x - y) + (y * (y / x)));
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.15e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 4.9d-167) then
        tmp = (x - y) / ((x - y) + (y * (y / x)))
    else if (y <= 1.4d-120) then
        tmp = (x - y) / y
    else if (y <= 1.15d-111) then
        tmp = 1.0d0 + ((-2.0d0) * ((y * y) / (x * x)))
    else
        tmp = (-1.0d0) + ((x * x) / (y * y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 4.9e-167) {
		tmp = (x - y) / ((x - y) + (y * (y / x)));
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.15e-111) {
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 4.9e-167:
		tmp = (x - y) / ((x - y) + (y * (y / x)))
	elif y <= 1.4e-120:
		tmp = (x - y) / y
	elif y <= 1.15e-111:
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)))
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 4.9e-167)
		tmp = Float64(Float64(x - y) / Float64(Float64(x - y) + Float64(y * Float64(y / x))));
	elseif (y <= 1.4e-120)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.15e-111)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y * y) / Float64(x * x))));
	else
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 4.9e-167)
		tmp = (x - y) / ((x - y) + (y * (y / x)));
	elseif (y <= 1.4e-120)
		tmp = (x - y) / y;
	elseif (y <= 1.15e-111)
		tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
	else
		tmp = -1.0 + ((x * x) / (y * y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 4.9e-167], N[(N[(x - y), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] + N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-120], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.15e-111], N[(1.0 + N[(-2.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.9 \cdot 10^{-167}:\\
\;\;\;\;\frac{x - y}{\left(x - y\right) + y \cdot \frac{y}{x}}\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 4.90000000000000003e-167

    1. Initial program 59.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*59.4%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def59.4%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified59.4%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Step-by-step derivation
      1. fma-def59.4%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{x \cdot x + y \cdot y}}{x + y}} \]
      2. add-sqr-sqrt59.4%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{x + y}} \]
      3. *-un-lft-identity59.4%

        \[\leadsto \frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}{\color{blue}{1 \cdot \left(x + y\right)}}} \]
      4. times-frac59.4%

        \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{1} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{x + y}}} \]
      5. hypot-def59.5%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{hypot}\left(x, y\right)}}{1} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{x + y}} \]
      6. hypot-def99.9%

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

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

      \[\leadsto \frac{x - y}{\color{blue}{\left(\frac{{y}^{2}}{x} + \left(-1 \cdot y + x\right)\right) - -1 \cdot \frac{{y}^{2}}{x}}} \]
    7. Step-by-step derivation
      1. cancel-sign-sub-inv30.8%

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

        \[\leadsto \frac{x - y}{\color{blue}{\left(\left(-1 \cdot y + x\right) + \frac{{y}^{2}}{x}\right)} + \left(--1\right) \cdot \frac{{y}^{2}}{x}} \]
      3. neg-mul-130.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{x - y}{\left(\left(x - y\right) + y \cdot \frac{y}{x}\right) + 1 \cdot \color{blue}{\left(y \cdot \frac{y}{x}\right)}} \]
      11. *-lft-identity31.4%

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

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

      \[\leadsto \frac{x - y}{\color{blue}{\left(-1 \cdot y + x\right)} + y \cdot \frac{y}{x}} \]
    10. Step-by-step derivation
      1. +-commutative31.1%

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

        \[\leadsto \frac{x - y}{\left(x + \color{blue}{\left(-y\right)}\right) + y \cdot \frac{y}{x}} \]
      3. sub-neg31.1%

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

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

    if 4.90000000000000003e-167 < y < 1.39999999999999997e-120

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.39999999999999997e-120 < y < 1.15e-111

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def98.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified98.4%

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow2100.0%

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

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

    if 1.15e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    8. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification38.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 4.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{x - y}{\left(x - y\right) + y \cdot \frac{y}{x}}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \]

Alternative 8: 83.5% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 7.5 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-121}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 7.5e-168)
   1.0
   (if (<= y 5.8e-121)
     (/ (- x y) y)
     (if (<= y 1.1e-111) 1.0 (+ (* (/ x y) (/ x y)) -1.0)))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 7.5e-168) {
		tmp = 1.0;
	} else if (y <= 5.8e-121) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = ((x / y) * (x / y)) + -1.0;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 7.5d-168) then
        tmp = 1.0d0
    else if (y <= 5.8d-121) then
        tmp = (x - y) / y
    else if (y <= 1.1d-111) then
        tmp = 1.0d0
    else
        tmp = ((x / y) * (x / y)) + (-1.0d0)
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 7.5e-168) {
		tmp = 1.0;
	} else if (y <= 5.8e-121) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = ((x / y) * (x / y)) + -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 7.5e-168:
		tmp = 1.0
	elif y <= 5.8e-121:
		tmp = (x - y) / y
	elif y <= 1.1e-111:
		tmp = 1.0
	else:
		tmp = ((x / y) * (x / y)) + -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 7.5e-168)
		tmp = 1.0;
	elseif (y <= 5.8e-121)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 7.5e-168)
		tmp = 1.0;
	elseif (y <= 5.8e-121)
		tmp = (x - y) / y;
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = ((x / y) * (x / y)) + -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 7.5e-168], 1.0, If[LessEqual[y, 5.8e-121], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.1e-111], 1.0, N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.5 \cdot 10^{-168}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 5.8 \cdot 10^{-121}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 7.4999999999999995e-168 or 5.8e-121 < y < 1.1e-111

    1. Initial program 59.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around inf 30.4%

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

    if 7.4999999999999995e-168 < y < 5.8e-121

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.1e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity85.4%

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{y} \cdot \frac{x + y}{y}\right)} \]
    9. Step-by-step derivation
      1. associate-*l/85.5%

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

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{y}}}{y} \]
    10. Simplified85.5%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    12. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. times-frac85.9%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(-1\right) \]
      5. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y} + -1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification38.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 7.5 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-121}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \end{array} \]

Alternative 9: 83.5% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.3 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.38 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 1.3e-162)
   1.0
   (if (<= y 1.38e-120)
     (/ (- x y) y)
     (if (<= y 1.1e-111) 1.0 (+ -1.0 (/ (* x x) (* y y)))))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.3e-162) {
		tmp = 1.0;
	} else if (y <= 1.38e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.3d-162) then
        tmp = 1.0d0
    else if (y <= 1.38d-120) then
        tmp = (x - y) / y
    else if (y <= 1.1d-111) then
        tmp = 1.0d0
    else
        tmp = (-1.0d0) + ((x * x) / (y * y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.3e-162) {
		tmp = 1.0;
	} else if (y <= 1.38e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.3e-162:
		tmp = 1.0
	elif y <= 1.38e-120:
		tmp = (x - y) / y
	elif y <= 1.1e-111:
		tmp = 1.0
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.3e-162)
		tmp = 1.0;
	elseif (y <= 1.38e-120)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.3e-162)
		tmp = 1.0;
	elseif (y <= 1.38e-120)
		tmp = (x - y) / y;
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = -1.0 + ((x * x) / (y * y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.3e-162], 1.0, If[LessEqual[y, 1.38e-120], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.1e-111], 1.0, N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.38 \cdot 10^{-120}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 1.3e-162 or 1.38e-120 < y < 1.1e-111

    1. Initial program 59.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around inf 30.4%

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

    if 1.3e-162 < y < 1.38e-120

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.1e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    8. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification38.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.3 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.38 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \]

Alternative 10: 83.6% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 2.4 \cdot 10^{-169}:\\ \;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 2.4e-169)
   (- (+ (/ y x) 1.0) (/ y x))
   (if (<= y 1.4e-120)
     (/ (- x y) y)
     (if (<= y 1.1e-111) 1.0 (+ -1.0 (/ (* x x) (* y y)))))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 2.4e-169) {
		tmp = ((y / x) + 1.0) - (y / x);
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 2.4d-169) then
        tmp = ((y / x) + 1.0d0) - (y / x)
    else if (y <= 1.4d-120) then
        tmp = (x - y) / y
    else if (y <= 1.1d-111) then
        tmp = 1.0d0
    else
        tmp = (-1.0d0) + ((x * x) / (y * y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 2.4e-169) {
		tmp = ((y / x) + 1.0) - (y / x);
	} else if (y <= 1.4e-120) {
		tmp = (x - y) / y;
	} else if (y <= 1.1e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 2.4e-169:
		tmp = ((y / x) + 1.0) - (y / x)
	elif y <= 1.4e-120:
		tmp = (x - y) / y
	elif y <= 1.1e-111:
		tmp = 1.0
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 2.4e-169)
		tmp = Float64(Float64(Float64(y / x) + 1.0) - Float64(y / x));
	elseif (y <= 1.4e-120)
		tmp = Float64(Float64(x - y) / y);
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 2.4e-169)
		tmp = ((y / x) + 1.0) - (y / x);
	elseif (y <= 1.4e-120)
		tmp = (x - y) / y;
	elseif (y <= 1.1e-111)
		tmp = 1.0;
	else
		tmp = -1.0 + ((x * x) / (y * y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 2.4e-169], N[(N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-120], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.1e-111], 1.0, N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.4 \cdot 10^{-169}:\\
\;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\
\;\;\;\;\frac{x - y}{y}\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 2.40000000000000011e-169

    1. Initial program 59.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.2%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{x \cdot x + y \cdot y}} \]
      3. *-un-lft-identity59.2%

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

        \[\leadsto \left(x - y\right) \cdot \frac{1 \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}} \]
      5. times-frac59.3%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right)} \]
      6. hypot-def59.3%

        \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\right) \]
      7. hypot-def99.7%

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
    6. Step-by-step derivation
      1. associate-*l/99.7%

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

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}{\mathsf{hypot}\left(x, y\right)} \]
      3. +-commutative99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{\frac{\color{blue}{y + x}}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Simplified99.7%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}} \]
    8. Step-by-step derivation
      1. associate-/l/59.2%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}} \]
      2. +-commutative59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{x + y}}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)} \]
      3. clear-num59.2%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      4. *-un-lft-identity59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{\color{blue}{1 \cdot \left(x + y\right)}}} \]
      5. frac-times99.7%

        \[\leadsto \left(x - y\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      6. div-inv99.9%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
      7. /-rgt-identity99.9%

        \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
      8. associate-/r*99.9%

        \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    9. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    10. Taylor expanded in x around inf 30.3%

      \[\leadsto \color{blue}{\frac{y}{x} + \left(1 + -1 \cdot \frac{y}{x}\right)} \]
    11. Step-by-step derivation
      1. associate-+r+30.3%

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

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

        \[\leadsto \left(1 + \frac{y}{x}\right) + \color{blue}{\frac{-1 \cdot y}{x}} \]
      4. neg-mul-130.3%

        \[\leadsto \left(1 + \frac{y}{x}\right) + \frac{\color{blue}{-y}}{x} \]
    12. Simplified30.3%

      \[\leadsto \color{blue}{\left(1 + \frac{y}{x}\right) + \frac{-y}{x}} \]
    13. Step-by-step derivation
      1. add-sqr-sqrt29.1%

        \[\leadsto \color{blue}{\sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}}} + \frac{-y}{x} \]
      2. distribute-frac-neg29.1%

        \[\leadsto \sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}} + \color{blue}{\left(-\frac{y}{x}\right)} \]
      3. fma-def29.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\frac{y}{x}\right)} \]
      4. add-sqr-sqrt13.0%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{\frac{y}{x}} \cdot \sqrt{\frac{y}{x}}}\right) \]
      5. sqrt-unprod28.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{\frac{y}{x} \cdot \frac{y}{x}}}\right) \]
      6. sqr-neg28.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\sqrt{\color{blue}{\left(-\frac{y}{x}\right) \cdot \left(-\frac{y}{x}\right)}}\right) \]
      7. sqrt-unprod15.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\sqrt{-\frac{y}{x}} \cdot \sqrt{-\frac{y}{x}}}\right) \]
      8. add-sqr-sqrt28.1%

        \[\leadsto \mathsf{fma}\left(\sqrt{1 + \frac{y}{x}}, \sqrt{1 + \frac{y}{x}}, -\color{blue}{\left(-\frac{y}{x}\right)}\right) \]
      9. fma-neg28.1%

        \[\leadsto \color{blue}{\sqrt{1 + \frac{y}{x}} \cdot \sqrt{1 + \frac{y}{x}} - \left(-\frac{y}{x}\right)} \]
      10. add-sqr-sqrt31.1%

        \[\leadsto \color{blue}{\left(1 + \frac{y}{x}\right)} - \left(-\frac{y}{x}\right) \]
      11. add-sqr-sqrt18.5%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{-\frac{y}{x}} \cdot \sqrt{-\frac{y}{x}}} \]
      12. sqrt-unprod31.4%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{\left(-\frac{y}{x}\right) \cdot \left(-\frac{y}{x}\right)}} \]
      13. sqr-neg31.4%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \sqrt{\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}} \]
      14. sqrt-unprod13.0%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\sqrt{\frac{y}{x}} \cdot \sqrt{\frac{y}{x}}} \]
      15. add-sqr-sqrt30.3%

        \[\leadsto \left(1 + \frac{y}{x}\right) - \color{blue}{\frac{y}{x}} \]
    14. Applied egg-rr30.3%

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

    if 2.40000000000000011e-169 < y < 1.39999999999999997e-120

    1. Initial program 100.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 56.8%

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

    if 1.39999999999999997e-120 < y < 1.1e-111

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def98.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified98.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around inf 100.0%

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

    if 1.1e-111 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in y around inf 85.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified85.4%

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    8. Step-by-step derivation
      1. sub-neg85.9%

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

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

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval85.9%

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification38.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.4 \cdot 10^{-169}:\\ \;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \end{array} \]

Alternative 11: 83.1% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 4.8 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 4.8e-164)
   1.0
   (if (<= y 1.4e-120) -1.0 (if (<= y 1.7e-111) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 4.8e-164) {
		tmp = 1.0;
	} else if (y <= 1.4e-120) {
		tmp = -1.0;
	} else if (y <= 1.7e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 4.8d-164) then
        tmp = 1.0d0
    else if (y <= 1.4d-120) then
        tmp = -1.0d0
    else if (y <= 1.7d-111) then
        tmp = 1.0d0
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 4.8e-164) {
		tmp = 1.0;
	} else if (y <= 1.4e-120) {
		tmp = -1.0;
	} else if (y <= 1.7e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 4.8e-164:
		tmp = 1.0
	elif y <= 1.4e-120:
		tmp = -1.0
	elif y <= 1.7e-111:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 4.8e-164)
		tmp = 1.0;
	elseif (y <= 1.4e-120)
		tmp = -1.0;
	elseif (y <= 1.7e-111)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 4.8e-164)
		tmp = 1.0;
	elseif (y <= 1.4e-120)
		tmp = -1.0;
	elseif (y <= 1.7e-111)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 4.8e-164], 1.0, If[LessEqual[y, 1.4e-120], -1.0, If[LessEqual[y, 1.7e-111], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.8 \cdot 10^{-164}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 4.79999999999999966e-164 or 1.39999999999999997e-120 < y < 1.69999999999999998e-111

    1. Initial program 59.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around inf 30.4%

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

    if 4.79999999999999966e-164 < y < 1.39999999999999997e-120 or 1.69999999999999998e-111 < y

    1. Initial program 99.9%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def99.4%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around 0 75.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 4.8 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 12: 83.6% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.45 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 (if (<= y 1.45e-162) 1.0 (/ (- x y) y)))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.45e-162) {
		tmp = 1.0;
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.45d-162) then
        tmp = 1.0d0
    else
        tmp = (x - y) / y
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.45e-162) {
		tmp = 1.0;
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.45e-162:
		tmp = 1.0
	else:
		tmp = (x - y) / y
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.45e-162)
		tmp = 1.0;
	else
		tmp = Float64(Float64(x - y) / y);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.45e-162)
		tmp = 1.0;
	else
		tmp = (x - y) / y;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.45e-162], 1.0, N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{x - y}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.4500000000000001e-162

    1. Initial program 59.0%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
      3. fma-def59.2%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    3. Simplified59.2%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    4. Taylor expanded in x around inf 30.1%

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

    if 1.4500000000000001e-162 < y

    1. Initial program 99.9%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    4. Taylor expanded in x around 0 74.0%

      \[\leadsto \frac{x - y}{\color{blue}{y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification37.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.45 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y}\\ \end{array} \]

Alternative 13: 66.9% accurate, 15.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ -1 \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 -1.0)
y = abs(y);
double code(double x, double y) {
	return -1.0;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -1.0d0
end function
y = Math.abs(y);
public static double code(double x, double y) {
	return -1.0;
}
y = abs(y)
def code(x, y):
	return -1.0
y = abs(y)
function code(x, y)
	return -1.0
end
y = abs(y)
function tmp = code(x, y)
	tmp = -1.0;
end
NOTE: y should be positive before calling this function
code[x_, y_] := -1.0
\begin{array}{l}
y = |y|\\
\\
-1
\end{array}
Derivation
  1. Initial program 65.9%

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

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

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
    3. fma-def65.9%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  3. Simplified65.9%

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  4. Taylor expanded in x around 0 69.9%

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

    \[\leadsto -1 \]

Developer target: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;0.5 < t_0 \land t_0 < 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))))
   (if (and (< 0.5 t_0) (< t_0 2.0))
     (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
     (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))))
double code(double x, double y) {
	double t_0 = fabs((x / y));
	double tmp;
	if ((0.5 < t_0) && (t_0 < 2.0)) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	}
	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 = abs((x / y))
    if ((0.5d0 < t_0) .and. (t_0 < 2.0d0)) then
        tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
    else
        tmp = 1.0d0 - (2.0d0 / (1.0d0 + ((x / y) * (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = Math.abs((x / y));
	double tmp;
	if ((0.5 < t_0) && (t_0 < 2.0)) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	}
	return tmp;
}
def code(x, y):
	t_0 = math.fabs((x / y))
	tmp = 0
	if (0.5 < t_0) and (t_0 < 2.0):
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
	else:
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))))
	return tmp
function code(x, y)
	t_0 = abs(Float64(x / y))
	tmp = 0.0
	if ((0.5 < t_0) && (t_0 < 2.0))
		tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = Float64(1.0 - Float64(2.0 / Float64(1.0 + Float64(Float64(x / y) * Float64(x / y)))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = abs((x / y));
	tmp = 0.0;
	if ((0.5 < t_0) && (t_0 < 2.0))
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	else
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[And[Less[0.5, t$95$0], Less[t$95$0, 2.0]], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(2.0 / N[(1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;0.5 < t_0 \land t_0 < 2:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023240 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))

  :herbie-target
  (if (and (< 0.5 (fabs (/ x y))) (< (fabs (/ x y)) 2.0)) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))