Kahan p9 Example

Percentage Accurate: 67.8% → 92.9%
Time: 26.0s
Alternatives: 9
Speedup: 0.5×

Specification

?
\[\left(0 < x \land x < 1\right) \land y < 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
(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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 67.8% accurate, 1.0× speedup?

\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
(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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}

Alternative 1: 92.9% accurate, 0.3× speedup?

\[\begin{array}{l} t_0 := \frac{x}{\left|y\right|}\\ t_1 := x - \left|y\right|\\ t_2 := \frac{t\_1 \cdot \left(x + \left|y\right|\right)}{x \cdot x + \left|y\right| \cdot \left|y\right|}\\ \mathbf{if}\;t\_2 \leq 2:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{t\_0 \cdot t\_0 + \left(1 \cdot 1 - t\_0\right)}}{\left|y\right|} \cdot t\_1\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (let* ((t_0 (/ x (fabs y)))
       (t_1 (- x (fabs y)))
       (t_2
        (/ (* t_1 (+ x (fabs y))) (+ (* x x) (* (fabs y) (fabs y))))))
  (if (<= t_2 2)
    t_2
    (* (/ (/ 1 (+ (* t_0 t_0) (- (* 1 1) t_0))) (fabs y)) t_1))))
double code(double x, double y) {
	double t_0 = x / fabs(y);
	double t_1 = x - fabs(y);
	double t_2 = (t_1 * (x + fabs(y))) / ((x * x) + (fabs(y) * fabs(y)));
	double tmp;
	if (t_2 <= 2.0) {
		tmp = t_2;
	} else {
		tmp = ((1.0 / ((t_0 * t_0) + ((1.0 * 1.0) - t_0))) / fabs(y)) * t_1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = x / abs(y)
    t_1 = x - abs(y)
    t_2 = (t_1 * (x + abs(y))) / ((x * x) + (abs(y) * abs(y)))
    if (t_2 <= 2.0d0) then
        tmp = t_2
    else
        tmp = ((1.0d0 / ((t_0 * t_0) + ((1.0d0 * 1.0d0) - t_0))) / abs(y)) * t_1
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x / Math.abs(y);
	double t_1 = x - Math.abs(y);
	double t_2 = (t_1 * (x + Math.abs(y))) / ((x * x) + (Math.abs(y) * Math.abs(y)));
	double tmp;
	if (t_2 <= 2.0) {
		tmp = t_2;
	} else {
		tmp = ((1.0 / ((t_0 * t_0) + ((1.0 * 1.0) - t_0))) / Math.abs(y)) * t_1;
	}
	return tmp;
}
def code(x, y):
	t_0 = x / math.fabs(y)
	t_1 = x - math.fabs(y)
	t_2 = (t_1 * (x + math.fabs(y))) / ((x * x) + (math.fabs(y) * math.fabs(y)))
	tmp = 0
	if t_2 <= 2.0:
		tmp = t_2
	else:
		tmp = ((1.0 / ((t_0 * t_0) + ((1.0 * 1.0) - t_0))) / math.fabs(y)) * t_1
	return tmp
function code(x, y)
	t_0 = Float64(x / abs(y))
	t_1 = Float64(x - abs(y))
	t_2 = Float64(Float64(t_1 * Float64(x + abs(y))) / Float64(Float64(x * x) + Float64(abs(y) * abs(y))))
	tmp = 0.0
	if (t_2 <= 2.0)
		tmp = t_2;
	else
		tmp = Float64(Float64(Float64(1.0 / Float64(Float64(t_0 * t_0) + Float64(Float64(1.0 * 1.0) - t_0))) / abs(y)) * t_1);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x / abs(y);
	t_1 = x - abs(y);
	t_2 = (t_1 * (x + abs(y))) / ((x * x) + (abs(y) * abs(y)));
	tmp = 0.0;
	if (t_2 <= 2.0)
		tmp = t_2;
	else
		tmp = ((1.0 / ((t_0 * t_0) + ((1.0 * 1.0) - t_0))) / abs(y)) * t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x / N[Abs[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x - N[Abs[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * N[(x + N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 2], t$95$2, N[(N[(N[(1 / N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(1 * 1), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \frac{x}{\left|y\right|}\\
t_1 := x - \left|y\right|\\
t_2 := \frac{t\_1 \cdot \left(x + \left|y\right|\right)}{x \cdot x + \left|y\right| \cdot \left|y\right|}\\
\mathbf{if}\;t\_2 \leq 2:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t\_0 \cdot t\_0 + \left(1 \cdot 1 - t\_0\right)}}{\left|y\right|} \cdot t\_1\\


\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 67.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 67.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
      3. associate-/l*N/A

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y} \cdot \left(x - y\right)} \]
      5. lower-*.f64N/A

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

        \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
      7. lift-+.f64N/A

        \[\leadsto \frac{\color{blue}{x + y}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
      8. +-commutativeN/A

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

        \[\leadsto \frac{\color{blue}{y + x}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
      10. lift-+.f64N/A

        \[\leadsto \frac{y + x}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
      11. +-commutativeN/A

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

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

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

      \[\leadsto \color{blue}{\frac{1 + \frac{x}{y}}{y}} \cdot \left(x - y\right) \]
    5. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{1 + \frac{x}{y}}{\color{blue}{y}} \cdot \left(x - y\right) \]
      2. lower-+.f64N/A

        \[\leadsto \frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right) \]
      3. lower-/.f6467.7%

        \[\leadsto \frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right) \]
    6. Applied rewrites67.7%

      \[\leadsto \color{blue}{\frac{1 + \frac{x}{y}}{y}} \cdot \left(x - y\right) \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right) \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x}{y} + 1}{y} \cdot \left(x - y\right) \]
      3. flip3-+N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      4. lower-unsound-/.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      5. lower-unsound-+.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      6. lower-unsound-pow.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      7. lower-unsound-pow.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      8. lower-unsound-+.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      9. lower-unsound-*.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      10. lower-unsound-*.f32N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      11. lower-*.f32N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      12. lift-/.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot 1\right)}}{y} \cdot \left(x - y\right) \]
      13. metadata-evalN/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y} \cdot \frac{1}{1}\right)}}{y} \cdot \left(x - y\right) \]
      14. times-fracN/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x \cdot 1}{y \cdot 1}\right)}}{y} \cdot \left(x - y\right) \]
      15. *-commutativeN/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x \cdot 1}{1 \cdot y}\right)}}{y} \cdot \left(x - y\right) \]
      16. *-lft-identityN/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x \cdot 1}{y}\right)}}{y} \cdot \left(x - y\right) \]
      17. associate-*r/N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - x \cdot \frac{1}{y}\right)}}{y} \cdot \left(x - y\right) \]
      18. mult-flipN/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
      19. lift-/.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
      20. lower-unsound--.f64N/A

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
      21. lower-unsound-*.f6467.4%

        \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
    8. Applied rewrites67.4%

      \[\leadsto \frac{\frac{{\left(\frac{x}{y}\right)}^{3} + {1}^{3}}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
    9. Taylor expanded in x around 0

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

        \[\leadsto \frac{\frac{1}{\frac{x}{y} \cdot \frac{x}{y} + \left(1 \cdot 1 - \frac{x}{y}\right)}}{y} \cdot \left(x - y\right) \]
    11. Recombined 2 regimes into one program.
    12. Add Preprocessing

    Alternative 2: 92.7% accurate, 0.5× speedup?

    \[\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{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
      (if (<= t_0 2) t_0 (* (/ (/ (- x y) y) y) (+ y x)))))
    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) / y) * (y + x);
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        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) / y) * (y + x)
        end if
        code = tmp
    end function
    
    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) / y) * (y + x);
    	}
    	return tmp;
    }
    
    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) / y) * (y + x)
    	return tmp
    
    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(Float64(x - y) / y) / y) * Float64(y + x));
    	end
    	return tmp
    end
    
    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) / y) * (y + x);
    	end
    	tmp_2 = tmp;
    end
    
    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], t$95$0, N[(N[(N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]]]
    
    \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{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\
    
    
    \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 67.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 67.8%

        \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
      2. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
        2. mult-flipN/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right) \cdot \frac{1}{x \cdot x + y \cdot y}} \]
        3. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
        4. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\left(x + y\right) \cdot \left(x - y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
        5. associate-*l*N/A

          \[\leadsto \color{blue}{\left(x + y\right) \cdot \left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right)} \]
        6. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
        7. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
        8. mult-flip-revN/A

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

          \[\leadsto \color{blue}{\frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
        10. lift-+.f64N/A

          \[\leadsto \frac{x - y}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
        11. +-commutativeN/A

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

          \[\leadsto \frac{x - y}{\color{blue}{y \cdot y + x \cdot x}} \cdot \left(x + y\right) \]
        13. lift-+.f64N/A

          \[\leadsto \frac{x - y}{y \cdot y + x \cdot x} \cdot \color{blue}{\left(x + y\right)} \]
        14. +-commutativeN/A

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{\color{blue}{y}} \cdot \left(y + x\right) \]
        2. lower--.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
        3. lower-/.f6467.7%

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
      6. Applied rewrites67.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
      7. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
        2. sub-negate-revN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        3. metadata-evalN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        4. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        5. lift--.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        6. lift--.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        8. metadata-evalN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        9. lift-/.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        10. sub-to-fractionN/A

          \[\leadsto \frac{\mathsf{neg}\left(\frac{1 \cdot y - x}{y}\right)}{y} \cdot \left(y + x\right) \]
        11. distribute-neg-fracN/A

          \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(1 \cdot y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
        12. *-lft-identityN/A

          \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
        13. sub-negate-revN/A

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
        14. lift--.f64N/A

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
        15. lower-/.f6467.7%

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
      8. Applied rewrites67.7%

        \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 3: 92.1% accurate, 0.4× speedup?

    \[\begin{array}{l} t_0 := \left|y\right| + x\\ t_1 := x - \left|y\right|\\ t_2 := \left|y\right| \cdot \left|y\right|\\ \mathbf{if}\;\frac{t\_1 \cdot \left(x + \left|y\right|\right)}{x \cdot x + t\_2} \leq 2:\\ \;\;\;\;\frac{t\_0}{t\_2 + x \cdot x} \cdot t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t\_1}{\left|y\right|}}{\left|y\right|} \cdot t\_0\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      (let* ((t_0 (+ (fabs y) x))
           (t_1 (- x (fabs y)))
           (t_2 (* (fabs y) (fabs y))))
      (if (<= (/ (* t_1 (+ x (fabs y))) (+ (* x x) t_2)) 2)
        (* (/ t_0 (+ t_2 (* x x))) t_1)
        (* (/ (/ t_1 (fabs y)) (fabs y)) t_0))))
    double code(double x, double y) {
    	double t_0 = fabs(y) + x;
    	double t_1 = x - fabs(y);
    	double t_2 = fabs(y) * fabs(y);
    	double tmp;
    	if (((t_1 * (x + fabs(y))) / ((x * x) + t_2)) <= 2.0) {
    		tmp = (t_0 / (t_2 + (x * x))) * t_1;
    	} else {
    		tmp = ((t_1 / fabs(y)) / fabs(y)) * t_0;
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: tmp
        t_0 = abs(y) + x
        t_1 = x - abs(y)
        t_2 = abs(y) * abs(y)
        if (((t_1 * (x + abs(y))) / ((x * x) + t_2)) <= 2.0d0) then
            tmp = (t_0 / (t_2 + (x * x))) * t_1
        else
            tmp = ((t_1 / abs(y)) / abs(y)) * t_0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double t_0 = Math.abs(y) + x;
    	double t_1 = x - Math.abs(y);
    	double t_2 = Math.abs(y) * Math.abs(y);
    	double tmp;
    	if (((t_1 * (x + Math.abs(y))) / ((x * x) + t_2)) <= 2.0) {
    		tmp = (t_0 / (t_2 + (x * x))) * t_1;
    	} else {
    		tmp = ((t_1 / Math.abs(y)) / Math.abs(y)) * t_0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = math.fabs(y) + x
    	t_1 = x - math.fabs(y)
    	t_2 = math.fabs(y) * math.fabs(y)
    	tmp = 0
    	if ((t_1 * (x + math.fabs(y))) / ((x * x) + t_2)) <= 2.0:
    		tmp = (t_0 / (t_2 + (x * x))) * t_1
    	else:
    		tmp = ((t_1 / math.fabs(y)) / math.fabs(y)) * t_0
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(abs(y) + x)
    	t_1 = Float64(x - abs(y))
    	t_2 = Float64(abs(y) * abs(y))
    	tmp = 0.0
    	if (Float64(Float64(t_1 * Float64(x + abs(y))) / Float64(Float64(x * x) + t_2)) <= 2.0)
    		tmp = Float64(Float64(t_0 / Float64(t_2 + Float64(x * x))) * t_1);
    	else
    		tmp = Float64(Float64(Float64(t_1 / abs(y)) / abs(y)) * t_0);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = abs(y) + x;
    	t_1 = x - abs(y);
    	t_2 = abs(y) * abs(y);
    	tmp = 0.0;
    	if (((t_1 * (x + abs(y))) / ((x * x) + t_2)) <= 2.0)
    		tmp = (t_0 / (t_2 + (x * x))) * t_1;
    	else
    		tmp = ((t_1 / abs(y)) / abs(y)) * t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(N[Abs[y], $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$1 = N[(x - N[Abs[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 * N[(x + N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision], 2], N[(N[(t$95$0 / N[(t$95$2 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], N[(N[(N[(t$95$1 / N[Abs[y], $MachinePrecision]), $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]]]]
    
    \begin{array}{l}
    t_0 := \left|y\right| + x\\
    t_1 := x - \left|y\right|\\
    t_2 := \left|y\right| \cdot \left|y\right|\\
    \mathbf{if}\;\frac{t\_1 \cdot \left(x + \left|y\right|\right)}{x \cdot x + t\_2} \leq 2:\\
    \;\;\;\;\frac{t\_0}{t\_2 + x \cdot x} \cdot t\_1\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\frac{t\_1}{\left|y\right|}}{\left|y\right|} \cdot t\_0\\
    
    
    \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 67.8%

        \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
      2. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
        2. lift-*.f64N/A

          \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
        3. associate-/l*N/A

          \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
        4. *-commutativeN/A

          \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y} \cdot \left(x - y\right)} \]
        5. lower-*.f64N/A

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

          \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
        7. lift-+.f64N/A

          \[\leadsto \frac{\color{blue}{x + y}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
        8. +-commutativeN/A

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

          \[\leadsto \frac{\color{blue}{y + x}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
        10. lift-+.f64N/A

          \[\leadsto \frac{y + x}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
        11. +-commutativeN/A

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

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

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

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

      1. Initial program 67.8%

        \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
      2. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
        2. mult-flipN/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right) \cdot \frac{1}{x \cdot x + y \cdot y}} \]
        3. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
        4. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\left(x + y\right) \cdot \left(x - y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
        5. associate-*l*N/A

          \[\leadsto \color{blue}{\left(x + y\right) \cdot \left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right)} \]
        6. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
        7. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
        8. mult-flip-revN/A

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

          \[\leadsto \color{blue}{\frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
        10. lift-+.f64N/A

          \[\leadsto \frac{x - y}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
        11. +-commutativeN/A

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

          \[\leadsto \frac{x - y}{\color{blue}{y \cdot y + x \cdot x}} \cdot \left(x + y\right) \]
        13. lift-+.f64N/A

          \[\leadsto \frac{x - y}{y \cdot y + x \cdot x} \cdot \color{blue}{\left(x + y\right)} \]
        14. +-commutativeN/A

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{\color{blue}{y}} \cdot \left(y + x\right) \]
        2. lower--.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
        3. lower-/.f6467.7%

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
      6. Applied rewrites67.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
      7. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
        2. sub-negate-revN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        3. metadata-evalN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        4. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        5. lift--.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        6. lift--.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        8. metadata-evalN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        9. lift-/.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
        10. sub-to-fractionN/A

          \[\leadsto \frac{\mathsf{neg}\left(\frac{1 \cdot y - x}{y}\right)}{y} \cdot \left(y + x\right) \]
        11. distribute-neg-fracN/A

          \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(1 \cdot y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
        12. *-lft-identityN/A

          \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
        13. sub-negate-revN/A

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
        14. lift--.f64N/A

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
        15. lower-/.f6467.7%

          \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
      8. Applied rewrites67.7%

        \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 4: 92.0% accurate, 0.3× speedup?

    \[\begin{array}{l} t_0 := x \cdot x + y \cdot y\\ t_1 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{t\_0}\\ \mathbf{if}\;t\_1 \leq \frac{-1}{2}:\\ \;\;\;\;\frac{\left(-1 \cdot y\right) \cdot y}{t\_0}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      (let* ((t_0 (+ (* x x) (* y y))) (t_1 (/ (* (- x y) (+ x y)) t_0)))
      (if (<= t_1 -1/2)
        (/ (* (* -1 y) y) t_0)
        (if (<= t_1 2) 1 (* (/ (/ (- x y) y) y) (+ y x))))))
    double code(double x, double y) {
    	double t_0 = (x * x) + (y * y);
    	double t_1 = ((x - y) * (x + y)) / t_0;
    	double tmp;
    	if (t_1 <= -0.5) {
    		tmp = ((-1.0 * y) * y) / t_0;
    	} else if (t_1 <= 2.0) {
    		tmp = 1.0;
    	} else {
    		tmp = (((x - y) / y) / y) * (y + x);
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = (x * x) + (y * y)
        t_1 = ((x - y) * (x + y)) / t_0
        if (t_1 <= (-0.5d0)) then
            tmp = (((-1.0d0) * y) * y) / t_0
        else if (t_1 <= 2.0d0) then
            tmp = 1.0d0
        else
            tmp = (((x - y) / y) / y) * (y + x)
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double t_0 = (x * x) + (y * y);
    	double t_1 = ((x - y) * (x + y)) / t_0;
    	double tmp;
    	if (t_1 <= -0.5) {
    		tmp = ((-1.0 * y) * y) / t_0;
    	} else if (t_1 <= 2.0) {
    		tmp = 1.0;
    	} else {
    		tmp = (((x - y) / y) / y) * (y + x);
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = (x * x) + (y * y)
    	t_1 = ((x - y) * (x + y)) / t_0
    	tmp = 0
    	if t_1 <= -0.5:
    		tmp = ((-1.0 * y) * y) / t_0
    	elif t_1 <= 2.0:
    		tmp = 1.0
    	else:
    		tmp = (((x - y) / y) / y) * (y + x)
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(Float64(x * x) + Float64(y * y))
    	t_1 = Float64(Float64(Float64(x - y) * Float64(x + y)) / t_0)
    	tmp = 0.0
    	if (t_1 <= -0.5)
    		tmp = Float64(Float64(Float64(-1.0 * y) * y) / t_0);
    	elseif (t_1 <= 2.0)
    		tmp = 1.0;
    	else
    		tmp = Float64(Float64(Float64(Float64(x - y) / y) / y) * Float64(y + x));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = (x * x) + (y * y);
    	t_1 = ((x - y) * (x + y)) / t_0;
    	tmp = 0.0;
    	if (t_1 <= -0.5)
    		tmp = ((-1.0 * y) * y) / t_0;
    	elseif (t_1 <= 2.0)
    		tmp = 1.0;
    	else
    		tmp = (((x - y) / y) / y) * (y + x);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -1/2], N[(N[(N[(-1 * y), $MachinePrecision] * y), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 2], 1, N[(N[(N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]]]]]
    
    \begin{array}{l}
    t_0 := x \cdot x + y \cdot y\\
    t_1 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{t\_0}\\
    \mathbf{if}\;t\_1 \leq \frac{-1}{2}:\\
    \;\;\;\;\frac{\left(-1 \cdot y\right) \cdot y}{t\_0}\\
    
    \mathbf{elif}\;t\_1 \leq 2:\\
    \;\;\;\;1\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < -0.5

      1. Initial program 67.8%

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

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

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

          \[\leadsto \frac{\color{blue}{\left(-1 \cdot y\right)} \cdot y}{x \cdot x + y \cdot y} \]
        3. Step-by-step derivation
          1. lower-*.f6442.5%

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

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

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

        1. Initial program 67.8%

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

          \[\leadsto \color{blue}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites33.4%

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

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

          1. Initial program 67.8%

            \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
          2. Step-by-step derivation
            1. lift-/.f64N/A

              \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
            2. mult-flipN/A

              \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right) \cdot \frac{1}{x \cdot x + y \cdot y}} \]
            3. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
            4. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\left(x + y\right) \cdot \left(x - y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
            5. associate-*l*N/A

              \[\leadsto \color{blue}{\left(x + y\right) \cdot \left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right)} \]
            6. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
            7. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
            8. mult-flip-revN/A

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

              \[\leadsto \color{blue}{\frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
            10. lift-+.f64N/A

              \[\leadsto \frac{x - y}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
            11. +-commutativeN/A

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

              \[\leadsto \frac{x - y}{\color{blue}{y \cdot y + x \cdot x}} \cdot \left(x + y\right) \]
            13. lift-+.f64N/A

              \[\leadsto \frac{x - y}{y \cdot y + x \cdot x} \cdot \color{blue}{\left(x + y\right)} \]
            14. +-commutativeN/A

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

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

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

            \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
          5. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \frac{\frac{x}{y} - 1}{\color{blue}{y}} \cdot \left(y + x\right) \]
            2. lower--.f64N/A

              \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
            3. lower-/.f6467.7%

              \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
          6. Applied rewrites67.7%

            \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
          7. Step-by-step derivation
            1. lift--.f64N/A

              \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
            2. sub-negate-revN/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            3. metadata-evalN/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            4. lift-*.f64N/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            5. lift--.f64N/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            6. lift--.f64N/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            7. lift-*.f64N/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            8. metadata-evalN/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            9. lift-/.f64N/A

              \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
            10. sub-to-fractionN/A

              \[\leadsto \frac{\mathsf{neg}\left(\frac{1 \cdot y - x}{y}\right)}{y} \cdot \left(y + x\right) \]
            11. distribute-neg-fracN/A

              \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(1 \cdot y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
            12. *-lft-identityN/A

              \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
            13. sub-negate-revN/A

              \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
            14. lift--.f64N/A

              \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
            15. lower-/.f6467.7%

              \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
          8. Applied rewrites67.7%

            \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
        4. Recombined 3 regimes into one program.
        5. Add Preprocessing

        Alternative 5: 92.0% accurate, 0.3× speedup?

        \[\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 \frac{-1}{2}:\\ \;\;\;\;-1\\ \mathbf{elif}\;t\_0 \leq 2:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\ \end{array} \]
        (FPCore (x y)
          :precision binary64
          (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
          (if (<= t_0 -1/2)
            -1
            (if (<= t_0 2) 1 (* (/ (/ (- x y) y) y) (+ y x))))))
        double code(double x, double y) {
        	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
        	double tmp;
        	if (t_0 <= -0.5) {
        		tmp = -1.0;
        	} else if (t_0 <= 2.0) {
        		tmp = 1.0;
        	} else {
        		tmp = (((x - y) / y) / y) * (y + x);
        	}
        	return tmp;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(x, y)
        use fmin_fmax_functions
            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 <= (-0.5d0)) then
                tmp = -1.0d0
            else if (t_0 <= 2.0d0) then
                tmp = 1.0d0
            else
                tmp = (((x - y) / y) / y) * (y + x)
            end if
            code = tmp
        end function
        
        public static double code(double x, double y) {
        	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
        	double tmp;
        	if (t_0 <= -0.5) {
        		tmp = -1.0;
        	} else if (t_0 <= 2.0) {
        		tmp = 1.0;
        	} else {
        		tmp = (((x - y) / y) / y) * (y + x);
        	}
        	return tmp;
        }
        
        def code(x, y):
        	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
        	tmp = 0
        	if t_0 <= -0.5:
        		tmp = -1.0
        	elif t_0 <= 2.0:
        		tmp = 1.0
        	else:
        		tmp = (((x - y) / y) / y) * (y + x)
        	return tmp
        
        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 <= -0.5)
        		tmp = -1.0;
        	elseif (t_0 <= 2.0)
        		tmp = 1.0;
        	else
        		tmp = Float64(Float64(Float64(Float64(x - y) / y) / y) * Float64(y + x));
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y)
        	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
        	tmp = 0.0;
        	if (t_0 <= -0.5)
        		tmp = -1.0;
        	elseif (t_0 <= 2.0)
        		tmp = 1.0;
        	else
        		tmp = (((x - y) / y) / y) * (y + x);
        	end
        	tmp_2 = tmp;
        end
        
        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, -1/2], -1, If[LessEqual[t$95$0, 2], 1, N[(N[(N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]]]]
        
        \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 \frac{-1}{2}:\\
        \;\;\;\;-1\\
        
        \mathbf{elif}\;t\_0 \leq 2:\\
        \;\;\;\;1\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right)\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < -0.5

          1. Initial program 67.8%

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

            \[\leadsto \color{blue}{-1} \]
          3. Step-by-step derivation
            1. Applied rewrites66.8%

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

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

            1. Initial program 67.8%

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

              \[\leadsto \color{blue}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites33.4%

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

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

              1. Initial program 67.8%

                \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
              2. Step-by-step derivation
                1. lift-/.f64N/A

                  \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
                2. mult-flipN/A

                  \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right) \cdot \frac{1}{x \cdot x + y \cdot y}} \]
                3. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \left(x + y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
                4. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\left(x + y\right) \cdot \left(x - y\right)\right)} \cdot \frac{1}{x \cdot x + y \cdot y} \]
                5. associate-*l*N/A

                  \[\leadsto \color{blue}{\left(x + y\right) \cdot \left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right)} \]
                6. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
                7. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(x - y\right) \cdot \frac{1}{x \cdot x + y \cdot y}\right) \cdot \left(x + y\right)} \]
                8. mult-flip-revN/A

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

                  \[\leadsto \color{blue}{\frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
                10. lift-+.f64N/A

                  \[\leadsto \frac{x - y}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x + y\right) \]
                11. +-commutativeN/A

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

                  \[\leadsto \frac{x - y}{\color{blue}{y \cdot y + x \cdot x}} \cdot \left(x + y\right) \]
                13. lift-+.f64N/A

                  \[\leadsto \frac{x - y}{y \cdot y + x \cdot x} \cdot \color{blue}{\left(x + y\right)} \]
                14. +-commutativeN/A

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

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

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

                \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
              5. Step-by-step derivation
                1. lower-/.f64N/A

                  \[\leadsto \frac{\frac{x}{y} - 1}{\color{blue}{y}} \cdot \left(y + x\right) \]
                2. lower--.f64N/A

                  \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
                3. lower-/.f6467.7%

                  \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
              6. Applied rewrites67.7%

                \[\leadsto \color{blue}{\frac{\frac{x}{y} - 1}{y}} \cdot \left(y + x\right) \]
              7. Step-by-step derivation
                1. lift--.f64N/A

                  \[\leadsto \frac{\frac{x}{y} - 1}{y} \cdot \left(y + x\right) \]
                2. sub-negate-revN/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                3. metadata-evalN/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                4. lift-*.f64N/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                5. lift--.f64N/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                6. lift--.f64N/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                7. lift-*.f64N/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 \cdot 1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                8. metadata-evalN/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                9. lift-/.f64N/A

                  \[\leadsto \frac{\mathsf{neg}\left(\left(1 - \frac{x}{y}\right)\right)}{y} \cdot \left(y + x\right) \]
                10. sub-to-fractionN/A

                  \[\leadsto \frac{\mathsf{neg}\left(\frac{1 \cdot y - x}{y}\right)}{y} \cdot \left(y + x\right) \]
                11. distribute-neg-fracN/A

                  \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(1 \cdot y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
                12. *-lft-identityN/A

                  \[\leadsto \frac{\frac{\mathsf{neg}\left(\left(y - x\right)\right)}{y}}{y} \cdot \left(y + x\right) \]
                13. sub-negate-revN/A

                  \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
                14. lift--.f64N/A

                  \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
                15. lower-/.f6467.7%

                  \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
              8. Applied rewrites67.7%

                \[\leadsto \frac{\frac{x - y}{y}}{y} \cdot \left(y + x\right) \]
            4. Recombined 3 regimes into one program.
            5. Add Preprocessing

            Alternative 6: 91.9% accurate, 0.3× speedup?

            \[\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 \frac{-1}{2}:\\ \;\;\;\;-1\\ \mathbf{elif}\;t\_0 \leq 2:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right)\\ \end{array} \]
            (FPCore (x y)
              :precision binary64
              (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
              (if (<= t_0 -1/2)
                -1
                (if (<= t_0 2) 1 (* (/ (+ 1 (/ x y)) y) (- x y))))))
            double code(double x, double y) {
            	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
            	double tmp;
            	if (t_0 <= -0.5) {
            		tmp = -1.0;
            	} else if (t_0 <= 2.0) {
            		tmp = 1.0;
            	} else {
            		tmp = ((1.0 + (x / y)) / y) * (x - y);
            	}
            	return tmp;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(x, y)
            use fmin_fmax_functions
                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 <= (-0.5d0)) then
                    tmp = -1.0d0
                else if (t_0 <= 2.0d0) then
                    tmp = 1.0d0
                else
                    tmp = ((1.0d0 + (x / y)) / y) * (x - y)
                end if
                code = tmp
            end function
            
            public static double code(double x, double y) {
            	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
            	double tmp;
            	if (t_0 <= -0.5) {
            		tmp = -1.0;
            	} else if (t_0 <= 2.0) {
            		tmp = 1.0;
            	} else {
            		tmp = ((1.0 + (x / y)) / y) * (x - y);
            	}
            	return tmp;
            }
            
            def code(x, y):
            	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
            	tmp = 0
            	if t_0 <= -0.5:
            		tmp = -1.0
            	elif t_0 <= 2.0:
            		tmp = 1.0
            	else:
            		tmp = ((1.0 + (x / y)) / y) * (x - y)
            	return tmp
            
            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 <= -0.5)
            		tmp = -1.0;
            	elseif (t_0 <= 2.0)
            		tmp = 1.0;
            	else
            		tmp = Float64(Float64(Float64(1.0 + Float64(x / y)) / y) * Float64(x - y));
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y)
            	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
            	tmp = 0.0;
            	if (t_0 <= -0.5)
            		tmp = -1.0;
            	elseif (t_0 <= 2.0)
            		tmp = 1.0;
            	else
            		tmp = ((1.0 + (x / y)) / y) * (x - y);
            	end
            	tmp_2 = tmp;
            end
            
            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, -1/2], -1, If[LessEqual[t$95$0, 2], 1, N[(N[(N[(1 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]]]]
            
            \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 \frac{-1}{2}:\\
            \;\;\;\;-1\\
            
            \mathbf{elif}\;t\_0 \leq 2:\\
            \;\;\;\;1\\
            
            \mathbf{else}:\\
            \;\;\;\;\frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right)\\
            
            
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < -0.5

              1. Initial program 67.8%

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

                \[\leadsto \color{blue}{-1} \]
              3. Step-by-step derivation
                1. Applied rewrites66.8%

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

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

                1. Initial program 67.8%

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

                  \[\leadsto \color{blue}{1} \]
                3. Step-by-step derivation
                  1. Applied rewrites33.4%

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

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

                  1. Initial program 67.8%

                    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
                  2. Step-by-step derivation
                    1. lift-/.f64N/A

                      \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
                    2. lift-*.f64N/A

                      \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
                    3. associate-/l*N/A

                      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
                    4. *-commutativeN/A

                      \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y} \cdot \left(x - y\right)} \]
                    5. lower-*.f64N/A

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

                      \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
                    7. lift-+.f64N/A

                      \[\leadsto \frac{\color{blue}{x + y}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
                    8. +-commutativeN/A

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

                      \[\leadsto \frac{\color{blue}{y + x}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
                    10. lift-+.f64N/A

                      \[\leadsto \frac{y + x}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
                    11. +-commutativeN/A

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

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

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

                    \[\leadsto \color{blue}{\frac{1 + \frac{x}{y}}{y}} \cdot \left(x - y\right) \]
                  5. Step-by-step derivation
                    1. lower-/.f64N/A

                      \[\leadsto \frac{1 + \frac{x}{y}}{\color{blue}{y}} \cdot \left(x - y\right) \]
                    2. lower-+.f64N/A

                      \[\leadsto \frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right) \]
                    3. lower-/.f6467.7%

                      \[\leadsto \frac{1 + \frac{x}{y}}{y} \cdot \left(x - y\right) \]
                  6. Applied rewrites67.7%

                    \[\leadsto \color{blue}{\frac{1 + \frac{x}{y}}{y}} \cdot \left(x - y\right) \]
                4. Recombined 3 regimes into one program.
                5. Add Preprocessing

                Alternative 7: 91.8% accurate, 0.3× speedup?

                \[\begin{array}{l} t_0 := x - \left|y\right|\\ t_1 := \frac{t\_0 \cdot \left(x + \left|y\right|\right)}{x \cdot x + \left|y\right| \cdot \left|y\right|}\\ \mathbf{if}\;t\_1 \leq \frac{-1}{2}:\\ \;\;\;\;-1\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left|y\right|} \cdot t\_0\\ \end{array} \]
                (FPCore (x y)
                  :precision binary64
                  (let* ((t_0 (- x (fabs y)))
                       (t_1
                        (/ (* t_0 (+ x (fabs y))) (+ (* x x) (* (fabs y) (fabs y))))))
                  (if (<= t_1 -1/2) -1 (if (<= t_1 2) 1 (* (/ 1 (fabs y)) t_0)))))
                double code(double x, double y) {
                	double t_0 = x - fabs(y);
                	double t_1 = (t_0 * (x + fabs(y))) / ((x * x) + (fabs(y) * fabs(y)));
                	double tmp;
                	if (t_1 <= -0.5) {
                		tmp = -1.0;
                	} else if (t_1 <= 2.0) {
                		tmp = 1.0;
                	} else {
                		tmp = (1.0 / fabs(y)) * t_0;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(x, y)
                use fmin_fmax_functions
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    real(8) :: t_0
                    real(8) :: t_1
                    real(8) :: tmp
                    t_0 = x - abs(y)
                    t_1 = (t_0 * (x + abs(y))) / ((x * x) + (abs(y) * abs(y)))
                    if (t_1 <= (-0.5d0)) then
                        tmp = -1.0d0
                    else if (t_1 <= 2.0d0) then
                        tmp = 1.0d0
                    else
                        tmp = (1.0d0 / abs(y)) * t_0
                    end if
                    code = tmp
                end function
                
                public static double code(double x, double y) {
                	double t_0 = x - Math.abs(y);
                	double t_1 = (t_0 * (x + Math.abs(y))) / ((x * x) + (Math.abs(y) * Math.abs(y)));
                	double tmp;
                	if (t_1 <= -0.5) {
                		tmp = -1.0;
                	} else if (t_1 <= 2.0) {
                		tmp = 1.0;
                	} else {
                		tmp = (1.0 / Math.abs(y)) * t_0;
                	}
                	return tmp;
                }
                
                def code(x, y):
                	t_0 = x - math.fabs(y)
                	t_1 = (t_0 * (x + math.fabs(y))) / ((x * x) + (math.fabs(y) * math.fabs(y)))
                	tmp = 0
                	if t_1 <= -0.5:
                		tmp = -1.0
                	elif t_1 <= 2.0:
                		tmp = 1.0
                	else:
                		tmp = (1.0 / math.fabs(y)) * t_0
                	return tmp
                
                function code(x, y)
                	t_0 = Float64(x - abs(y))
                	t_1 = Float64(Float64(t_0 * Float64(x + abs(y))) / Float64(Float64(x * x) + Float64(abs(y) * abs(y))))
                	tmp = 0.0
                	if (t_1 <= -0.5)
                		tmp = -1.0;
                	elseif (t_1 <= 2.0)
                		tmp = 1.0;
                	else
                		tmp = Float64(Float64(1.0 / abs(y)) * t_0);
                	end
                	return tmp
                end
                
                function tmp_2 = code(x, y)
                	t_0 = x - abs(y);
                	t_1 = (t_0 * (x + abs(y))) / ((x * x) + (abs(y) * abs(y)));
                	tmp = 0.0;
                	if (t_1 <= -0.5)
                		tmp = -1.0;
                	elseif (t_1 <= 2.0)
                		tmp = 1.0;
                	else
                		tmp = (1.0 / abs(y)) * t_0;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_] := Block[{t$95$0 = N[(x - N[Abs[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * N[(x + N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1/2], -1, If[LessEqual[t$95$1, 2], 1, N[(N[(1 / N[Abs[y], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]]]]
                
                \begin{array}{l}
                t_0 := x - \left|y\right|\\
                t_1 := \frac{t\_0 \cdot \left(x + \left|y\right|\right)}{x \cdot x + \left|y\right| \cdot \left|y\right|}\\
                \mathbf{if}\;t\_1 \leq \frac{-1}{2}:\\
                \;\;\;\;-1\\
                
                \mathbf{elif}\;t\_1 \leq 2:\\
                \;\;\;\;1\\
                
                \mathbf{else}:\\
                \;\;\;\;\frac{1}{\left|y\right|} \cdot t\_0\\
                
                
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < -0.5

                  1. Initial program 67.8%

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

                    \[\leadsto \color{blue}{-1} \]
                  3. Step-by-step derivation
                    1. Applied rewrites66.8%

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

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

                    1. Initial program 67.8%

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

                      \[\leadsto \color{blue}{1} \]
                    3. Step-by-step derivation
                      1. Applied rewrites33.4%

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

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

                      1. Initial program 67.8%

                        \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
                      2. Step-by-step derivation
                        1. lift-/.f64N/A

                          \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \]
                        2. lift-*.f64N/A

                          \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot \left(x + y\right)}}{x \cdot x + y \cdot y} \]
                        3. associate-/l*N/A

                          \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
                        4. *-commutativeN/A

                          \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y} \cdot \left(x - y\right)} \]
                        5. lower-*.f64N/A

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

                          \[\leadsto \color{blue}{\frac{x + y}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
                        7. lift-+.f64N/A

                          \[\leadsto \frac{\color{blue}{x + y}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
                        8. +-commutativeN/A

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

                          \[\leadsto \frac{\color{blue}{y + x}}{x \cdot x + y \cdot y} \cdot \left(x - y\right) \]
                        10. lift-+.f64N/A

                          \[\leadsto \frac{y + x}{\color{blue}{x \cdot x + y \cdot y}} \cdot \left(x - y\right) \]
                        11. +-commutativeN/A

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

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

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

                        \[\leadsto \color{blue}{\frac{1}{y}} \cdot \left(x - y\right) \]
                      5. Step-by-step derivation
                        1. lower-/.f6466.7%

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

                        \[\leadsto \color{blue}{\frac{1}{y}} \cdot \left(x - y\right) \]
                    4. Recombined 3 regimes into one program.
                    5. Add Preprocessing

                    Alternative 8: 91.8% accurate, 0.4× speedup?

                    \[\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 \frac{-1}{2}:\\ \;\;\;\;-1\\ \mathbf{elif}\;t\_0 \leq 2:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
                    (FPCore (x y)
                      :precision binary64
                      (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
                      (if (<= t_0 -1/2) -1 (if (<= t_0 2) 1 -1))))
                    double code(double x, double y) {
                    	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
                    	double tmp;
                    	if (t_0 <= -0.5) {
                    		tmp = -1.0;
                    	} else if (t_0 <= 2.0) {
                    		tmp = 1.0;
                    	} else {
                    		tmp = -1.0;
                    	}
                    	return tmp;
                    }
                    
                    module fmin_fmax_functions
                        implicit none
                        private
                        public fmax
                        public fmin
                    
                        interface fmax
                            module procedure fmax88
                            module procedure fmax44
                            module procedure fmax84
                            module procedure fmax48
                        end interface
                        interface fmin
                            module procedure fmin88
                            module procedure fmin44
                            module procedure fmin84
                            module procedure fmin48
                        end interface
                    contains
                        real(8) function fmax88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmax44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmax84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmax48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                        end function
                        real(8) function fmin88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmin44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmin84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmin48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                        end function
                    end module
                    
                    real(8) function code(x, y)
                    use fmin_fmax_functions
                        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 <= (-0.5d0)) then
                            tmp = -1.0d0
                        else if (t_0 <= 2.0d0) then
                            tmp = 1.0d0
                        else
                            tmp = -1.0d0
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double x, double y) {
                    	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
                    	double tmp;
                    	if (t_0 <= -0.5) {
                    		tmp = -1.0;
                    	} else if (t_0 <= 2.0) {
                    		tmp = 1.0;
                    	} else {
                    		tmp = -1.0;
                    	}
                    	return tmp;
                    }
                    
                    def code(x, y):
                    	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
                    	tmp = 0
                    	if t_0 <= -0.5:
                    		tmp = -1.0
                    	elif t_0 <= 2.0:
                    		tmp = 1.0
                    	else:
                    		tmp = -1.0
                    	return tmp
                    
                    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 <= -0.5)
                    		tmp = -1.0;
                    	elseif (t_0 <= 2.0)
                    		tmp = 1.0;
                    	else
                    		tmp = -1.0;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(x, y)
                    	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
                    	tmp = 0.0;
                    	if (t_0 <= -0.5)
                    		tmp = -1.0;
                    	elseif (t_0 <= 2.0)
                    		tmp = 1.0;
                    	else
                    		tmp = -1.0;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    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, -1/2], -1, If[LessEqual[t$95$0, 2], 1, -1]]]
                    
                    \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 \frac{-1}{2}:\\
                    \;\;\;\;-1\\
                    
                    \mathbf{elif}\;t\_0 \leq 2:\\
                    \;\;\;\;1\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;-1\\
                    
                    
                    \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))) < -0.5 or 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))

                      1. Initial program 67.8%

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

                        \[\leadsto \color{blue}{-1} \]
                      3. Step-by-step derivation
                        1. Applied rewrites66.8%

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

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

                        1. Initial program 67.8%

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

                          \[\leadsto \color{blue}{1} \]
                        3. Step-by-step derivation
                          1. Applied rewrites33.4%

                            \[\leadsto \color{blue}{1} \]
                        4. Recombined 2 regimes into one program.
                        5. Add Preprocessing

                        Alternative 9: 66.8% accurate, 36.0× speedup?

                        \[-1 \]
                        (FPCore (x y)
                          :precision binary64
                          -1)
                        double code(double x, double y) {
                        	return -1.0;
                        }
                        
                        module fmin_fmax_functions
                            implicit none
                            private
                            public fmax
                            public fmin
                        
                            interface fmax
                                module procedure fmax88
                                module procedure fmax44
                                module procedure fmax84
                                module procedure fmax48
                            end interface
                            interface fmin
                                module procedure fmin88
                                module procedure fmin44
                                module procedure fmin84
                                module procedure fmin48
                            end interface
                        contains
                            real(8) function fmax88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmax44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmax84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmax48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                            end function
                            real(8) function fmin88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmin44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmin84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmin48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                            end function
                        end module
                        
                        real(8) function code(x, y)
                        use fmin_fmax_functions
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            code = -1.0d0
                        end function
                        
                        public static double code(double x, double y) {
                        	return -1.0;
                        }
                        
                        def code(x, y):
                        	return -1.0
                        
                        function code(x, y)
                        	return -1.0
                        end
                        
                        function tmp = code(x, y)
                        	tmp = -1.0;
                        end
                        
                        code[x_, y_] := -1
                        
                        -1
                        
                        Derivation
                        1. Initial program 67.8%

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

                          \[\leadsto \color{blue}{-1} \]
                        3. Step-by-step derivation
                          1. Applied rewrites66.8%

                            \[\leadsto \color{blue}{-1} \]
                          2. Add Preprocessing

                          Reproduce

                          ?
                          herbie shell --seed 2025271 -o generate:evaluate
                          (FPCore (x y)
                            :name "Kahan p9 Example"
                            :precision binary64
                            :pre (and (and (< 0 x) (< x 1)) (< y 1))
                            (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))