Kahan p9 Example

Percentage Accurate: 67.6% → 100.0%
Time: 10.7s
Alternatives: 12
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 12 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.6% 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 66.0%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. fma-def66.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  5. 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}}} \]
  6. 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 66.0%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. +-commutative66.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\sqrt{\color{blue}{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. Final simplification99.7%

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

Alternative 3: 99.9% accurate, 0.1× speedup?

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

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. fma-def66.0%

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

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

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

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

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

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

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

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

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

Alternative 4: 100.0% accurate, 0.1× speedup?

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

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. fma-def66.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 93.1% 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}{\left(y + \frac{x}{\frac{y}{x}}\right) - x}\\ \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) (- (+ y (/ x (/ y x))) x)))))
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) / ((y + (x / (y / x))) - x);
	}
	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) / ((y + (x / (y / x))) - x)
    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) / ((y + (x / (y / x))) - x);
	}
	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) / ((y + (x / (y / x))) - x)
	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(x - y) / Float64(Float64(y + Float64(x / Float64(y / x))) - x));
	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) / ((y + (x / (y / x))) - x);
	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[(x - y), $MachinePrecision] / N[(N[(y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $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}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\left(y + \frac{x}{\frac{y}{x}}\right) - x}\\


\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.9%

      \[\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-/l*3.1%

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

        \[\leadsto \frac{x - y}{\frac{\color{blue}{y \cdot y + x \cdot x}}{x + y}} \]
      3. remove-double-neg3.1%

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

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

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

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

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

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

      \[\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 3.1%

      \[\leadsto \frac{x - y}{\frac{\color{blue}{{y}^{2}}}{x + y}} \]
    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 \frac{x - y}{\frac{\color{blue}{y \cdot y}}{x + y}} \]
    7. Taylor expanded in y around inf 71.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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}{\left(y + \frac{x}{\frac{y}{x}}\right) - x}\\ \end{array} \]

Alternative 6: 92.0% accurate, 0.8× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.85 \cdot 10^{-162}:\\ \;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\ \mathbf{elif}\;y \leq 10000:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 1.85e-162)
   (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x)))
   (if (<= y 10000.0) (* (- x y) (/ (+ x y) (+ (* x x) (* y y)))) -1.0)))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.85e-162) {
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
	} else if (y <= 10000.0) {
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	} 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 <= 1.85d-162) then
        tmp = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / x))
    else if (y <= 10000.0d0) then
        tmp = (x - y) * ((x + y) / ((x * x) + (y * y)))
    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 <= 1.85e-162) {
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
	} else if (y <= 10000.0) {
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.85e-162:
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x))
	elif y <= 10000.0:
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)))
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.85e-162)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / x)));
	elseif (y <= 10000.0)
		tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / Float64(Float64(x * x) + Float64(y * y))));
	else
		tmp = -1.0;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.85e-162)
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
	elseif (y <= 10000.0)
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.85e-162], N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 10000.0], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-162}:\\
\;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\

\mathbf{elif}\;y \leq 10000:\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\

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


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

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity26.6%

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

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

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

        \[\leadsto 1 + -2 \cdot \color{blue}{\frac{1 \cdot \frac{y \cdot y}{x}}{x}} \]
      2. *-lft-identity37.5%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y \cdot y}{x}}}{x} \]
      3. associate-/l*38.5%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y}{\frac{x}{y}}}}{x} \]
    10. Simplified38.5%

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

    if 1.8500000000000001e-162 < y < 1e4

    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. +-commutative99.8%

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

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

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

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

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

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

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

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

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

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

    if 1e4 < y

    1. Initial program 66.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. +-commutative66.0%

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

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

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

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

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

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

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

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

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

Alternative 7: 81.1% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 2.3 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-132} \lor \neg \left(y \leq 3.8 \cdot 10^{-101}\right):\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{x}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 2.3e-162)
   1.0
   (if (or (<= y 1.1e-132) (not (<= y 3.8e-101)))
     (+ -1.0 (/ (* x x) (* y y)))
     (/ (- x y) x))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 2.3e-162) {
		tmp = 1.0;
	} else if ((y <= 1.1e-132) || !(y <= 3.8e-101)) {
		tmp = -1.0 + ((x * x) / (y * y));
	} else {
		tmp = (x - y) / x;
	}
	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-162) then
        tmp = 1.0d0
    else if ((y <= 1.1d-132) .or. (.not. (y <= 3.8d-101))) then
        tmp = (-1.0d0) + ((x * x) / (y * y))
    else
        tmp = (x - y) / x
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 2.3e-162) {
		tmp = 1.0;
	} else if ((y <= 1.1e-132) || !(y <= 3.8e-101)) {
		tmp = -1.0 + ((x * x) / (y * y));
	} else {
		tmp = (x - y) / x;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 2.3e-162:
		tmp = 1.0
	elif (y <= 1.1e-132) or not (y <= 3.8e-101):
		tmp = -1.0 + ((x * x) / (y * y))
	else:
		tmp = (x - y) / x
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 2.3e-162)
		tmp = 1.0;
	elseif ((y <= 1.1e-132) || !(y <= 3.8e-101))
		tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y)));
	else
		tmp = Float64(Float64(x - y) / x);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 2.3e-162)
		tmp = 1.0;
	elseif ((y <= 1.1e-132) || ~((y <= 3.8e-101)))
		tmp = -1.0 + ((x * x) / (y * y));
	else
		tmp = (x - y) / x;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 2.3e-162], 1.0, If[Or[LessEqual[y, 1.1e-132], N[Not[LessEqual[y, 3.8e-101]], $MachinePrecision]], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{-132} \lor \neg \left(y \leq 3.8 \cdot 10^{-101}\right):\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\

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


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

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

    if 2.2999999999999998e-162 < y < 1.09999999999999995e-132 or 3.8000000000000001e-101 < 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. +-commutative99.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{{x}^{2}}{{y}^{2}} + \color{blue}{-1} \]
      3. unpow285.5%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{{y}^{2}} + -1 \]
      4. unpow285.5%

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

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

    if 1.09999999999999995e-132 < y < 3.8000000000000001e-101

    1. Initial program 99.6%

      \[\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.7%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. +-commutative99.7%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{y \cdot y + x \cdot x}}{x + y}} \]
      3. remove-double-neg99.7%

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

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

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

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - \left(-y\right)}} \]
      7. sub-neg99.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.3 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-132} \lor \neg \left(y \leq 3.8 \cdot 10^{-101}\right):\\ \;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{x}\\ \end{array} \]

Alternative 8: 82.5% accurate, 1.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\frac{x \cdot x}{y} + \left(y - x\right)}\\


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

    1. Initial program 60.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. +-commutative60.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity27.7%

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

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

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

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

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y \cdot y}{x}}}{x} \]
      3. associate-/l*38.8%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y}{\frac{x}{y}}}}{x} \]
    10. Simplified38.8%

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

    if 1.45000000000000001e-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-/l*99.8%

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

        \[\leadsto \frac{x - y}{\frac{\color{blue}{y \cdot y + x \cdot x}}{x + y}} \]
      3. remove-double-neg99.8%

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

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

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

        \[\leadsto \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - \left(-y\right)}} \]
      7. sub-neg99.8%

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

        \[\leadsto \frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + \color{blue}{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 83.8%

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

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

      \[\leadsto \frac{x - y}{\frac{\color{blue}{y \cdot y}}{x + y}} \]
    7. Taylor expanded in y around inf 84.2%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 82.4% accurate, 1.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.45 \cdot 10^{-111}:\\ \;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{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 1.45e-111)
   (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x)))
   (+ -1.0 (/ (* x x) (* y y)))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.45e-111) {
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / 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 <= 1.45d-111) then
        tmp = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / 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 <= 1.45e-111) {
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
	} else {
		tmp = -1.0 + ((x * x) / (y * y));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.45e-111:
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / x))
	else:
		tmp = -1.0 + ((x * x) / (y * y))
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.45e-111)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / 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 <= 1.45e-111)
		tmp = 1.0 + (-2.0 * ((y / (x / y)) / 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, 1.45e-111], N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $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 1.45 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\

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


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

    1. Initial program 60.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. +-commutative60.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity27.7%

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

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

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

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

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y \cdot y}{x}}}{x} \]
      3. associate-/l*38.8%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{\frac{y}{\frac{x}{y}}}}{x} \]
    10. Simplified38.8%

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

    if 1.45000000000000001e-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. +-commutative99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 81.4% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.95 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \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 1.95e-162) 1.0 (if (<= y 1e-132) -1.0 (if (<= y 2e-111) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.95e-162) {
		tmp = 1.0;
	} else if (y <= 1e-132) {
		tmp = -1.0;
	} else if (y <= 2e-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 <= 1.95d-162) then
        tmp = 1.0d0
    else if (y <= 1d-132) then
        tmp = -1.0d0
    else if (y <= 2d-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 <= 1.95e-162) {
		tmp = 1.0;
	} else if (y <= 1e-132) {
		tmp = -1.0;
	} else if (y <= 2e-111) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.95e-162:
		tmp = 1.0
	elif y <= 1e-132:
		tmp = -1.0
	elif y <= 2e-111:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.95e-162)
		tmp = 1.0;
	elseif (y <= 1e-132)
		tmp = -1.0;
	elseif (y <= 2e-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 <= 1.95e-162)
		tmp = 1.0;
	elseif (y <= 1e-132)
		tmp = -1.0;
	elseif (y <= 2e-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, 1.95e-162], 1.0, If[LessEqual[y, 1e-132], -1.0, If[LessEqual[y, 2e-111], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.95 \cdot 10^{-162}:\\
\;\;\;\;1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.95e-162 or 9.9999999999999999e-133 < y < 2.00000000000000018e-111

    1. Initial program 58.3%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. +-commutative58.3%

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

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

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

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

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

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

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

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

    if 1.95e-162 < y < 9.9999999999999999e-133 or 2.00000000000000018e-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. +-commutative99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.95 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-111}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 11: 81.0% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 3.7 \cdot 10^{-101}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 (if (<= y 3.7e-101) (/ (- x y) x) -1.0))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 3.7e-101) {
		tmp = (x - y) / x;
	} 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 <= 3.7d-101) then
        tmp = (x - y) / x
    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 <= 3.7e-101) {
		tmp = (x - y) / x;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 3.7e-101:
		tmp = (x - y) / x
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 3.7e-101)
		tmp = Float64(Float64(x - y) / x);
	else
		tmp = -1.0;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 3.7e-101)
		tmp = (x - y) / x;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 3.7e-101], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.7 \cdot 10^{-101}:\\
\;\;\;\;\frac{x - y}{x}\\

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


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

    1. Initial program 60.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*61.5%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. +-commutative61.5%

        \[\leadsto \frac{x - y}{\frac{\color{blue}{y \cdot y + x \cdot x}}{x + y}} \]
      3. remove-double-neg61.5%

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

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

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

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

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

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

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

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

    if 3.70000000000000005e-101 < 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. +-commutative99.9%

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

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

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

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

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

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

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

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

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

Alternative 12: 67.2% 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 66.0%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. +-commutative66.0%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1} \]
  5. Final simplification65.0%

    \[\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 2023270 
(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))))