Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A

Percentage Accurate: 100.0% → 100.0%
Time: 2.6s
Alternatives: 9
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  2. Add Preprocessing

Alternative 2: 100.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(y \cdot \left(x - 0.5\right) - x\right) + 0.918938533204673 \end{array} \]
(FPCore (x y) :precision binary64 (+ (- (* y (- x 0.5)) x) 0.918938533204673))
double code(double x, double y) {
	return ((y * (x - 0.5)) - x) + 0.918938533204673;
}
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 = ((y * (x - 0.5d0)) - x) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((y * (x - 0.5)) - x) + 0.918938533204673;
}
def code(x, y):
	return ((y * (x - 0.5)) - x) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(y * Float64(x - 0.5)) - x) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((y * (x - 0.5)) - x) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(y \cdot \left(x - 0.5\right) - x\right) + 0.918938533204673
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(y \cdot \left(x - 0.5\right) - x\right) + 0.918938533204673} \]
  5. Add Preprocessing

Alternative 3: 97.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y - 1\right)\\ \mathbf{if}\;x \leq -0.72:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.55:\\ \;\;\;\;0.918938533204673 - 0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* x (- y 1.0))))
   (if (<= x -0.72) t_0 (if (<= x 0.55) (- 0.918938533204673 (* 0.5 y)) t_0))))
double code(double x, double y) {
	double t_0 = x * (y - 1.0);
	double tmp;
	if (x <= -0.72) {
		tmp = t_0;
	} else if (x <= 0.55) {
		tmp = 0.918938533204673 - (0.5 * y);
	} else {
		tmp = 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) :: tmp
    t_0 = x * (y - 1.0d0)
    if (x <= (-0.72d0)) then
        tmp = t_0
    else if (x <= 0.55d0) then
        tmp = 0.918938533204673d0 - (0.5d0 * y)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x * (y - 1.0);
	double tmp;
	if (x <= -0.72) {
		tmp = t_0;
	} else if (x <= 0.55) {
		tmp = 0.918938533204673 - (0.5 * y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x * (y - 1.0)
	tmp = 0
	if x <= -0.72:
		tmp = t_0
	elif x <= 0.55:
		tmp = 0.918938533204673 - (0.5 * y)
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(x * Float64(y - 1.0))
	tmp = 0.0
	if (x <= -0.72)
		tmp = t_0;
	elseif (x <= 0.55)
		tmp = Float64(0.918938533204673 - Float64(0.5 * y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x * (y - 1.0);
	tmp = 0.0;
	if (x <= -0.72)
		tmp = t_0;
	elseif (x <= 0.55)
		tmp = 0.918938533204673 - (0.5 * y);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.72], t$95$0, If[LessEqual[x, 0.55], N[(0.918938533204673 - N[(0.5 * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(y - 1\right)\\
\mathbf{if}\;x \leq -0.72:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 0.55:\\
\;\;\;\;0.918938533204673 - 0.5 \cdot y\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.71999999999999997 or 0.55000000000000004 < x

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
    4. Applied rewrites100.0%

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

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

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

    if -0.71999999999999997 < x < 0.55000000000000004

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{918938533204673}{1000000000000000} - \frac{1}{2} \cdot y} \]
    3. Applied rewrites51.1%

      \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 97.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x - 0.5\right)\\ \mathbf{if}\;y \leq -1.4:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.1:\\ \;\;\;\;\left(-x\right) + 0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (- x 0.5))))
   (if (<= y -1.4) t_0 (if (<= y 1.1) (+ (- x) 0.918938533204673) t_0))))
double code(double x, double y) {
	double t_0 = y * (x - 0.5);
	double tmp;
	if (y <= -1.4) {
		tmp = t_0;
	} else if (y <= 1.1) {
		tmp = -x + 0.918938533204673;
	} else {
		tmp = 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) :: tmp
    t_0 = y * (x - 0.5d0)
    if (y <= (-1.4d0)) then
        tmp = t_0
    else if (y <= 1.1d0) then
        tmp = -x + 0.918938533204673d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = y * (x - 0.5);
	double tmp;
	if (y <= -1.4) {
		tmp = t_0;
	} else if (y <= 1.1) {
		tmp = -x + 0.918938533204673;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = y * (x - 0.5)
	tmp = 0
	if y <= -1.4:
		tmp = t_0
	elif y <= 1.1:
		tmp = -x + 0.918938533204673
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(y * Float64(x - 0.5))
	tmp = 0.0
	if (y <= -1.4)
		tmp = t_0;
	elseif (y <= 1.1)
		tmp = Float64(Float64(-x) + 0.918938533204673);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = y * (x - 0.5);
	tmp = 0.0;
	if (y <= -1.4)
		tmp = t_0;
	elseif (y <= 1.1)
		tmp = -x + 0.918938533204673;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.4], t$95$0, If[LessEqual[y, 1.1], N[((-x) + 0.918938533204673), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(x - 0.5\right)\\
\mathbf{if}\;y \leq -1.4:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.1:\\
\;\;\;\;\left(-x\right) + 0.918938533204673\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.3999999999999999 or 1.1000000000000001 < y

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around inf

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

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

    if -1.3999999999999999 < y < 1.1000000000000001

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{-1 \cdot x} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites50.0%

      \[\leadsto \color{blue}{-1 \cdot x} + 0.918938533204673 \]
    4. Applied rewrites50.0%

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

Alternative 5: 73.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+147}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq -6100000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1.82:\\ \;\;\;\;\left(-x\right) + 0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -3.2e+147)
   (* y -0.5)
   (if (<= y -6100000.0)
     (* x y)
     (if (<= y 1.82) (+ (- x) 0.918938533204673) (* y -0.5)))))
double code(double x, double y) {
	double tmp;
	if (y <= -3.2e+147) {
		tmp = y * -0.5;
	} else if (y <= -6100000.0) {
		tmp = x * y;
	} else if (y <= 1.82) {
		tmp = -x + 0.918938533204673;
	} else {
		tmp = y * -0.5;
	}
	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) :: tmp
    if (y <= (-3.2d+147)) then
        tmp = y * (-0.5d0)
    else if (y <= (-6100000.0d0)) then
        tmp = x * y
    else if (y <= 1.82d0) then
        tmp = -x + 0.918938533204673d0
    else
        tmp = y * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -3.2e+147) {
		tmp = y * -0.5;
	} else if (y <= -6100000.0) {
		tmp = x * y;
	} else if (y <= 1.82) {
		tmp = -x + 0.918938533204673;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -3.2e+147:
		tmp = y * -0.5
	elif y <= -6100000.0:
		tmp = x * y
	elif y <= 1.82:
		tmp = -x + 0.918938533204673
	else:
		tmp = y * -0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -3.2e+147)
		tmp = Float64(y * -0.5);
	elseif (y <= -6100000.0)
		tmp = Float64(x * y);
	elseif (y <= 1.82)
		tmp = Float64(Float64(-x) + 0.918938533204673);
	else
		tmp = Float64(y * -0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -3.2e+147)
		tmp = y * -0.5;
	elseif (y <= -6100000.0)
		tmp = x * y;
	elseif (y <= 1.82)
		tmp = -x + 0.918938533204673;
	else
		tmp = y * -0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -3.2e+147], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, -6100000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.82], N[((-x) + 0.918938533204673), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+147}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq -6100000:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 1.82:\\
\;\;\;\;\left(-x\right) + 0.918938533204673\\

\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.19999999999999979e147 or 1.82000000000000006 < y

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around inf

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

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

      \[\leadsto y \cdot \frac{-1}{2} \]
    5. Applied rewrites26.7%

      \[\leadsto y \cdot -0.5 \]

    if -3.19999999999999979e147 < y < -6.1e6

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
    4. Applied rewrites100.0%

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

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

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

      \[\leadsto x \cdot \color{blue}{y} \]
    8. Applied rewrites26.5%

      \[\leadsto x \cdot \color{blue}{y} \]

    if -6.1e6 < y < 1.82000000000000006

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{-1 \cdot x} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites50.0%

      \[\leadsto \color{blue}{-1 \cdot x} + 0.918938533204673 \]
    4. Applied rewrites50.0%

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

Alternative 6: 61.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+269}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq -1000:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;t\_0 \leq 1:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+169}:\\ \;\;\;\;x \cdot -1\\ \mathbf{elif}\;t\_0 \leq 10^{+242}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673)))
   (if (<= t_0 -5e+269)
     (* x y)
     (if (<= t_0 -1000.0)
       (* y -0.5)
       (if (<= t_0 1.0)
         0.918938533204673
         (if (<= t_0 5e+169)
           (* x -1.0)
           (if (<= t_0 1e+242) (* y -0.5) (* x y))))))))
double code(double x, double y) {
	double t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	double tmp;
	if (t_0 <= -5e+269) {
		tmp = x * y;
	} else if (t_0 <= -1000.0) {
		tmp = y * -0.5;
	} else if (t_0 <= 1.0) {
		tmp = 0.918938533204673;
	} else if (t_0 <= 5e+169) {
		tmp = x * -1.0;
	} else if (t_0 <= 1e+242) {
		tmp = y * -0.5;
	} else {
		tmp = 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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
    if (t_0 <= (-5d+269)) then
        tmp = x * y
    else if (t_0 <= (-1000.0d0)) then
        tmp = y * (-0.5d0)
    else if (t_0 <= 1.0d0) then
        tmp = 0.918938533204673d0
    else if (t_0 <= 5d+169) then
        tmp = x * (-1.0d0)
    else if (t_0 <= 1d+242) then
        tmp = y * (-0.5d0)
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	double tmp;
	if (t_0 <= -5e+269) {
		tmp = x * y;
	} else if (t_0 <= -1000.0) {
		tmp = y * -0.5;
	} else if (t_0 <= 1.0) {
		tmp = 0.918938533204673;
	} else if (t_0 <= 5e+169) {
		tmp = x * -1.0;
	} else if (t_0 <= 1e+242) {
		tmp = y * -0.5;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
	tmp = 0
	if t_0 <= -5e+269:
		tmp = x * y
	elif t_0 <= -1000.0:
		tmp = y * -0.5
	elif t_0 <= 1.0:
		tmp = 0.918938533204673
	elif t_0 <= 5e+169:
		tmp = x * -1.0
	elif t_0 <= 1e+242:
		tmp = y * -0.5
	else:
		tmp = x * y
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
	tmp = 0.0
	if (t_0 <= -5e+269)
		tmp = Float64(x * y);
	elseif (t_0 <= -1000.0)
		tmp = Float64(y * -0.5);
	elseif (t_0 <= 1.0)
		tmp = 0.918938533204673;
	elseif (t_0 <= 5e+169)
		tmp = Float64(x * -1.0);
	elseif (t_0 <= 1e+242)
		tmp = Float64(y * -0.5);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	tmp = 0.0;
	if (t_0 <= -5e+269)
		tmp = x * y;
	elseif (t_0 <= -1000.0)
		tmp = y * -0.5;
	elseif (t_0 <= 1.0)
		tmp = 0.918938533204673;
	elseif (t_0 <= 5e+169)
		tmp = x * -1.0;
	elseif (t_0 <= 1e+242)
		tmp = y * -0.5;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+269], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -1000.0], N[(y * -0.5), $MachinePrecision], If[LessEqual[t$95$0, 1.0], 0.918938533204673, If[LessEqual[t$95$0, 5e+169], N[(x * -1.0), $MachinePrecision], If[LessEqual[t$95$0, 1e+242], N[(y * -0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+269}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;t\_0 \leq -1000:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;0.918938533204673\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+169}:\\
\;\;\;\;x \cdot -1\\

\mathbf{elif}\;t\_0 \leq 10^{+242}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{else}:\\
\;\;\;\;x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < -5.0000000000000002e269 or 1.00000000000000005e242 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64))

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
    4. Applied rewrites100.0%

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

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

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

      \[\leadsto x \cdot \color{blue}{y} \]
    8. Applied rewrites26.5%

      \[\leadsto x \cdot \color{blue}{y} \]

    if -5.0000000000000002e269 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < -1e3 or 5.00000000000000017e169 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < 1.00000000000000005e242

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around inf

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

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

      \[\leadsto y \cdot \frac{-1}{2} \]
    5. Applied rewrites26.7%

      \[\leadsto y \cdot -0.5 \]

    if -1e3 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < 1

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{918938533204673}{1000000000000000} - \frac{1}{2} \cdot y} \]
    3. Applied rewrites51.1%

      \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
    4. Taylor expanded in y around 0

      \[\leadsto \frac{918938533204673}{1000000000000000} \]
    5. Applied rewrites26.2%

      \[\leadsto 0.918938533204673 \]

    if 1 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < 5.00000000000000017e169

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
    4. Applied rewrites100.0%

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

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

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

      \[\leadsto x \cdot -1 \]
    8. Applied rewrites25.6%

      \[\leadsto x \cdot -1 \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 7: 61.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+269}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq -1000:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;t\_0 \leq 20000:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;t\_0 \leq 10^{+242}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673)))
   (if (<= t_0 -5e+269)
     (* x y)
     (if (<= t_0 -1000.0)
       (* y -0.5)
       (if (<= t_0 20000.0)
         0.918938533204673
         (if (<= t_0 1e+242) (* y -0.5) (* x y)))))))
double code(double x, double y) {
	double t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	double tmp;
	if (t_0 <= -5e+269) {
		tmp = x * y;
	} else if (t_0 <= -1000.0) {
		tmp = y * -0.5;
	} else if (t_0 <= 20000.0) {
		tmp = 0.918938533204673;
	} else if (t_0 <= 1e+242) {
		tmp = y * -0.5;
	} else {
		tmp = 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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
    if (t_0 <= (-5d+269)) then
        tmp = x * y
    else if (t_0 <= (-1000.0d0)) then
        tmp = y * (-0.5d0)
    else if (t_0 <= 20000.0d0) then
        tmp = 0.918938533204673d0
    else if (t_0 <= 1d+242) then
        tmp = y * (-0.5d0)
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	double tmp;
	if (t_0 <= -5e+269) {
		tmp = x * y;
	} else if (t_0 <= -1000.0) {
		tmp = y * -0.5;
	} else if (t_0 <= 20000.0) {
		tmp = 0.918938533204673;
	} else if (t_0 <= 1e+242) {
		tmp = y * -0.5;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
	tmp = 0
	if t_0 <= -5e+269:
		tmp = x * y
	elif t_0 <= -1000.0:
		tmp = y * -0.5
	elif t_0 <= 20000.0:
		tmp = 0.918938533204673
	elif t_0 <= 1e+242:
		tmp = y * -0.5
	else:
		tmp = x * y
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
	tmp = 0.0
	if (t_0 <= -5e+269)
		tmp = Float64(x * y);
	elseif (t_0 <= -1000.0)
		tmp = Float64(y * -0.5);
	elseif (t_0 <= 20000.0)
		tmp = 0.918938533204673;
	elseif (t_0 <= 1e+242)
		tmp = Float64(y * -0.5);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
	tmp = 0.0;
	if (t_0 <= -5e+269)
		tmp = x * y;
	elseif (t_0 <= -1000.0)
		tmp = y * -0.5;
	elseif (t_0 <= 20000.0)
		tmp = 0.918938533204673;
	elseif (t_0 <= 1e+242)
		tmp = y * -0.5;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+269], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -1000.0], N[(y * -0.5), $MachinePrecision], If[LessEqual[t$95$0, 20000.0], 0.918938533204673, If[LessEqual[t$95$0, 1e+242], N[(y * -0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+269}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;t\_0 \leq -1000:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;t\_0 \leq 20000:\\
\;\;\;\;0.918938533204673\\

\mathbf{elif}\;t\_0 \leq 10^{+242}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{else}:\\
\;\;\;\;x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < -5.0000000000000002e269 or 1.00000000000000005e242 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64))

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\left(-1 \cdot x + y \cdot \left(x - \frac{1}{2}\right)\right)} + \frac{918938533204673}{1000000000000000} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, x, y \cdot \left(x - 0.5\right)\right)} + 0.918938533204673 \]
    4. Applied rewrites100.0%

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

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

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

      \[\leadsto x \cdot \color{blue}{y} \]
    8. Applied rewrites26.5%

      \[\leadsto x \cdot \color{blue}{y} \]

    if -5.0000000000000002e269 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < -1e3 or 2e4 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < 1.00000000000000005e242

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around inf

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

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

      \[\leadsto y \cdot \frac{-1}{2} \]
    5. Applied rewrites26.7%

      \[\leadsto y \cdot -0.5 \]

    if -1e3 < (+.f64 (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) #s(literal 918938533204673/1000000000000000 binary64)) < 2e4

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{918938533204673}{1000000000000000} - \frac{1}{2} \cdot y} \]
    3. Applied rewrites51.1%

      \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
    4. Taylor expanded in y around 0

      \[\leadsto \frac{918938533204673}{1000000000000000} \]
    5. Applied rewrites26.2%

      \[\leadsto 0.918938533204673 \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 50.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.82:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 1.82:\\ \;\;\;\;0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.82) (* y -0.5) (if (<= y 1.82) 0.918938533204673 (* y -0.5))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.82) {
		tmp = y * -0.5;
	} else if (y <= 1.82) {
		tmp = 0.918938533204673;
	} else {
		tmp = y * -0.5;
	}
	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) :: tmp
    if (y <= (-1.82d0)) then
        tmp = y * (-0.5d0)
    else if (y <= 1.82d0) then
        tmp = 0.918938533204673d0
    else
        tmp = y * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.82) {
		tmp = y * -0.5;
	} else if (y <= 1.82) {
		tmp = 0.918938533204673;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.82:
		tmp = y * -0.5
	elif y <= 1.82:
		tmp = 0.918938533204673
	else:
		tmp = y * -0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.82)
		tmp = Float64(y * -0.5);
	elseif (y <= 1.82)
		tmp = 0.918938533204673;
	else
		tmp = Float64(y * -0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.82)
		tmp = y * -0.5;
	elseif (y <= 1.82)
		tmp = 0.918938533204673;
	else
		tmp = y * -0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.82], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 1.82], 0.918938533204673, N[(y * -0.5), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.82:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 1.82:\\
\;\;\;\;0.918938533204673\\

\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.82000000000000006 or 1.82000000000000006 < y

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in y around inf

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

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

      \[\leadsto y \cdot \frac{-1}{2} \]
    5. Applied rewrites26.7%

      \[\leadsto y \cdot -0.5 \]

    if -1.82000000000000006 < y < 1.82000000000000006

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{918938533204673}{1000000000000000} - \frac{1}{2} \cdot y} \]
    3. Applied rewrites51.1%

      \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
    4. Taylor expanded in y around 0

      \[\leadsto \frac{918938533204673}{1000000000000000} \]
    5. Applied rewrites26.2%

      \[\leadsto 0.918938533204673 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 26.2% accurate, 14.9× speedup?

\[\begin{array}{l} \\ 0.918938533204673 \end{array} \]
(FPCore (x y) :precision binary64 0.918938533204673)
double code(double x, double y) {
	return 0.918938533204673;
}
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 = 0.918938533204673d0
end function
public static double code(double x, double y) {
	return 0.918938533204673;
}
def code(x, y):
	return 0.918938533204673
function code(x, y)
	return 0.918938533204673
end
function tmp = code(x, y)
	tmp = 0.918938533204673;
end
code[x_, y_] := 0.918938533204673
\begin{array}{l}

\\
0.918938533204673
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{918938533204673}{1000000000000000} - \frac{1}{2} \cdot y} \]
  3. Applied rewrites51.1%

    \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
  4. Taylor expanded in y around 0

    \[\leadsto \frac{918938533204673}{1000000000000000} \]
  5. Applied rewrites26.2%

    \[\leadsto 0.918938533204673 \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025159 
(FPCore (x y)
  :name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
  :precision binary64
  (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))