Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2

Percentage Accurate: 99.8% → 99.8%
Time: 3.9s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
(FPCore (x y z)
  :precision binary64
  (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z):
	return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function tmp = code(x, y, z)
	tmp = ((x - ((y + 0.5) * log(y))) + y) - z;
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z

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: 99.8% accurate, 1.0× speedup?

\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
(FPCore (x y z)
  :precision binary64
  (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z):
	return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function tmp = code(x, y, z)
	tmp = ((x - ((y + 0.5) * log(y))) + y) - z;
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\left(y - \log y \cdot \left(y - -0.5\right)\right) - \left(z - x\right) \]
(FPCore (x y z)
  :precision binary64
  (- (- y (* (log y) (- y -0.5))) (- z x)))
double code(double x, double y, double z) {
	return (y - (log(y) * (y - -0.5))) - (z - x);
}
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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (y - (log(y) * (y - (-0.5d0)))) - (z - x)
end function
public static double code(double x, double y, double z) {
	return (y - (Math.log(y) * (y - -0.5))) - (z - x);
}
def code(x, y, z):
	return (y - (math.log(y) * (y - -0.5))) - (z - x)
function code(x, y, z)
	return Float64(Float64(y - Float64(log(y) * Float64(y - -0.5))) - Float64(z - x))
end
function tmp = code(x, y, z)
	tmp = (y - (log(y) * (y - -0.5))) - (z - x);
end
code[x_, y_, z_] := N[(N[(y - N[(N[Log[y], $MachinePrecision] * N[(y - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z - x), $MachinePrecision]), $MachinePrecision]
\left(y - \log y \cdot \left(y - -0.5\right)\right) - \left(z - x\right)
Derivation
  1. Initial program 99.8%

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Step-by-step derivation
    1. lift--.f64N/A

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

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

      \[\leadsto \mathsf{neg}\left(\left(z - \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)}\right)\right) \]
    4. add-flipN/A

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

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

      \[\leadsto \mathsf{neg}\left(\left(z - \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) - \left(\mathsf{neg}\left(y\right)\right)\right)\right)\right) \]
    7. fp-cancel-sub-sign-invN/A

      \[\leadsto \mathsf{neg}\left(\left(z - \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} - \left(\mathsf{neg}\left(y\right)\right)\right)\right)\right) \]
    8. associate--l+N/A

      \[\leadsto \mathsf{neg}\left(\left(z - \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right)\right) \]
    9. associate--r+N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(z - x\right) - \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right) \]
    10. sub-negateN/A

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

      \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right) - \left(z - x\right)} \]
  3. Applied rewrites99.8%

    \[\leadsto \color{blue}{\left(y - \log y \cdot \left(y - -0.5\right)\right) - \left(z - x\right)} \]
  4. Add Preprocessing

Alternative 2: 89.9% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := x - \left(z + 0.5 \cdot \log y\right)\\ \mathbf{if}\;x \leq -1420000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\ \;\;\;\;\left(y - \log y \cdot \left(0.5 + y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (let* ((t_0 (- x (+ z (* 0.5 (log y))))))
  (if (<= x -1420000.0)
    t_0
    (if (<= x 4.4e+59) (- (- y (* (log y) (+ 0.5 y))) z) t_0))))
double code(double x, double y, double z) {
	double t_0 = x - (z + (0.5 * log(y)));
	double tmp;
	if (x <= -1420000.0) {
		tmp = t_0;
	} else if (x <= 4.4e+59) {
		tmp = (y - (log(y) * (0.5 + y))) - z;
	} 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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x - (z + (0.5d0 * log(y)))
    if (x <= (-1420000.0d0)) then
        tmp = t_0
    else if (x <= 4.4d+59) then
        tmp = (y - (log(y) * (0.5d0 + y))) - z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x - (z + (0.5 * Math.log(y)));
	double tmp;
	if (x <= -1420000.0) {
		tmp = t_0;
	} else if (x <= 4.4e+59) {
		tmp = (y - (Math.log(y) * (0.5 + y))) - z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x - (z + (0.5 * math.log(y)))
	tmp = 0
	if x <= -1420000.0:
		tmp = t_0
	elif x <= 4.4e+59:
		tmp = (y - (math.log(y) * (0.5 + y))) - z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x - Float64(z + Float64(0.5 * log(y))))
	tmp = 0.0
	if (x <= -1420000.0)
		tmp = t_0;
	elseif (x <= 4.4e+59)
		tmp = Float64(Float64(y - Float64(log(y) * Float64(0.5 + y))) - z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x - (z + (0.5 * log(y)));
	tmp = 0.0;
	if (x <= -1420000.0)
		tmp = t_0;
	elseif (x <= 4.4e+59)
		tmp = (y - (log(y) * (0.5 + y))) - z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(z + N[(0.5 * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1420000.0], t$95$0, If[LessEqual[x, 4.4e+59], N[(N[(y - N[(N[Log[y], $MachinePrecision] * N[(0.5 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := x - \left(z + 0.5 \cdot \log y\right)\\
\mathbf{if}\;x \leq -1420000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\
\;\;\;\;\left(y - \log y \cdot \left(0.5 + y\right)\right) - z\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.42e6 or 4.3999999999999999e59 < x

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto x - \left(z + \frac{1}{2} \cdot \color{blue}{\log y}\right) \]
      4. lower-log.f6471.2%

        \[\leadsto x - \left(z + 0.5 \cdot \log y\right) \]
    4. Applied rewrites71.2%

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

    if -1.42e6 < x < 4.3999999999999999e59

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto \left(y - \log y \cdot \left(\color{blue}{\frac{1}{2}} + y\right)\right) - z \]
      4. lower-+.f6470.1%

        \[\leadsto \left(y - \log y \cdot \left(0.5 + \color{blue}{y}\right)\right) - z \]
    4. Applied rewrites70.1%

      \[\leadsto \color{blue}{\left(y - \log y \cdot \left(0.5 + y\right)\right)} - z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 89.6% accurate, 1.0× speedup?

\[\begin{array}{l} \mathbf{if}\;y \leq 3.2 \cdot 10^{+87}:\\ \;\;\;\;x - \left(z + 0.5 \cdot \log y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \log y\right) \cdot y - z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<= y 3.2e+87)
  (- x (+ z (* 0.5 (log y))))
  (- (* (- 1.0 (log y)) y) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 3.2e+87) {
		tmp = x - (z + (0.5 * log(y)));
	} else {
		tmp = ((1.0 - log(y)) * y) - z;
	}
	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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 3.2d+87) then
        tmp = x - (z + (0.5d0 * log(y)))
    else
        tmp = ((1.0d0 - log(y)) * y) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 3.2e+87) {
		tmp = x - (z + (0.5 * Math.log(y)));
	} else {
		tmp = ((1.0 - Math.log(y)) * y) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 3.2e+87:
		tmp = x - (z + (0.5 * math.log(y)))
	else:
		tmp = ((1.0 - math.log(y)) * y) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 3.2e+87)
		tmp = Float64(x - Float64(z + Float64(0.5 * log(y))));
	else
		tmp = Float64(Float64(Float64(1.0 - log(y)) * y) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 3.2e+87)
		tmp = x - (z + (0.5 * log(y)));
	else
		tmp = ((1.0 - log(y)) * y) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 3.2e+87], N[(x - N[(z + N[(0.5 * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{+87}:\\
\;\;\;\;x - \left(z + 0.5 \cdot \log y\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y - z\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 3.2e87

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto x - \left(z + \frac{1}{2} \cdot \color{blue}{\log y}\right) \]
      4. lower-log.f6471.2%

        \[\leadsto x - \left(z + 0.5 \cdot \log y\right) \]
    4. Applied rewrites71.2%

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

    if 3.2e87 < y

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto y \cdot \left(1 + \log \left(\frac{1}{y}\right)\right) - z \]
      4. lower-/.f6457.4%

        \[\leadsto y \cdot \left(1 + \log \left(\frac{1}{y}\right)\right) - z \]
    4. Applied rewrites57.4%

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

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

        \[\leadsto \left(1 + \log \left(\frac{1}{y}\right)\right) \cdot \color{blue}{y} - z \]
      3. lower-*.f6457.4%

        \[\leadsto \left(1 + \log \left(\frac{1}{y}\right)\right) \cdot \color{blue}{y} - z \]
      4. lift-+.f64N/A

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

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

        \[\leadsto \left(1 + \log \left(\frac{1}{y}\right)\right) \cdot y - z \]
      7. log-recN/A

        \[\leadsto \left(1 + \left(\mathsf{neg}\left(\log y\right)\right)\right) \cdot y - z \]
      8. lift-log.f64N/A

        \[\leadsto \left(1 + \left(\mathsf{neg}\left(\log y\right)\right)\right) \cdot y - z \]
      9. sub-flip-reverseN/A

        \[\leadsto \left(1 - \log y\right) \cdot y - z \]
      10. lower--.f6457.4%

        \[\leadsto \left(1 - \log y\right) \cdot y - z \]
    6. Applied rewrites57.4%

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

Alternative 4: 71.2% accurate, 1.1× speedup?

\[x - \left(z + 0.5 \cdot \log y\right) \]
(FPCore (x y z)
  :precision binary64
  (- x (+ z (* 0.5 (log y)))))
double code(double x, double y, double z) {
	return x - (z + (0.5 * log(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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x - (z + (0.5d0 * log(y)))
end function
public static double code(double x, double y, double z) {
	return x - (z + (0.5 * Math.log(y)));
}
def code(x, y, z):
	return x - (z + (0.5 * math.log(y)))
function code(x, y, z)
	return Float64(x - Float64(z + Float64(0.5 * log(y))))
end
function tmp = code(x, y, z)
	tmp = x - (z + (0.5 * log(y)));
end
code[x_, y_, z_] := N[(x - N[(z + N[(0.5 * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x - \left(z + 0.5 \cdot \log y\right)
Derivation
  1. Initial program 99.8%

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

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

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

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

      \[\leadsto x - \left(z + \frac{1}{2} \cdot \color{blue}{\log y}\right) \]
    4. lower-log.f6471.2%

      \[\leadsto x - \left(z + 0.5 \cdot \log y\right) \]
  4. Applied rewrites71.2%

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

Alternative 5: 69.7% accurate, 1.0× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -1420000:\\ \;\;\;\;\left(1 - \frac{z}{x}\right) \cdot x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\ \;\;\;\;-0.5 \cdot \log y - z\\ \mathbf{else}:\\ \;\;\;\;\left(1 \cdot x + y\right) - z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<= x -1420000.0)
  (* (- 1.0 (/ z x)) x)
  (if (<= x 4.4e+59) (- (* -0.5 (log y)) z) (- (+ (* 1.0 x) y) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1420000.0) {
		tmp = (1.0 - (z / x)) * x;
	} else if (x <= 4.4e+59) {
		tmp = (-0.5 * log(y)) - z;
	} else {
		tmp = ((1.0 * x) + y) - z;
	}
	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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-1420000.0d0)) then
        tmp = (1.0d0 - (z / x)) * x
    else if (x <= 4.4d+59) then
        tmp = ((-0.5d0) * log(y)) - z
    else
        tmp = ((1.0d0 * x) + y) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1420000.0) {
		tmp = (1.0 - (z / x)) * x;
	} else if (x <= 4.4e+59) {
		tmp = (-0.5 * Math.log(y)) - z;
	} else {
		tmp = ((1.0 * x) + y) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1420000.0:
		tmp = (1.0 - (z / x)) * x
	elif x <= 4.4e+59:
		tmp = (-0.5 * math.log(y)) - z
	else:
		tmp = ((1.0 * x) + y) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1420000.0)
		tmp = Float64(Float64(1.0 - Float64(z / x)) * x);
	elseif (x <= 4.4e+59)
		tmp = Float64(Float64(-0.5 * log(y)) - z);
	else
		tmp = Float64(Float64(Float64(1.0 * x) + y) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1420000.0)
		tmp = (1.0 - (z / x)) * x;
	elseif (x <= 4.4e+59)
		tmp = (-0.5 * log(y)) - z;
	else
		tmp = ((1.0 * x) + y) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1420000.0], N[(N[(1.0 - N[(z / x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 4.4e+59], N[(N[(-0.5 * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(1.0 * x), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x \leq -1420000:\\
\;\;\;\;\left(1 - \frac{z}{x}\right) \cdot x\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\
\;\;\;\;-0.5 \cdot \log y - z\\

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


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.42e6

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(x - \left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right)\right)} + \left(\mathsf{neg}\left(z\right)\right) \]
      6. associate-+l-N/A

        \[\leadsto \color{blue}{x - \left(\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)\right)} \]
      7. sub-to-multN/A

        \[\leadsto \color{blue}{\left(1 - \frac{\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)}{x}\right) \cdot x} \]
      8. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left(1 - \frac{\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)}{x}\right) \cdot x} \]
    3. Applied rewrites80.7%

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

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

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

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

    if -1.42e6 < x < 4.3999999999999999e59

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \mathsf{neg}\left(\left(z - \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)}\right)\right) \]
      4. add-flipN/A

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

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

        \[\leadsto \mathsf{neg}\left(\left(z - \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) - \left(\mathsf{neg}\left(y\right)\right)\right)\right)\right) \]
      7. fp-cancel-sub-sign-invN/A

        \[\leadsto \mathsf{neg}\left(\left(z - \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} - \left(\mathsf{neg}\left(y\right)\right)\right)\right)\right) \]
      8. associate--l+N/A

        \[\leadsto \mathsf{neg}\left(\left(z - \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right)\right) \]
      9. associate--r+N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(z - x\right) - \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right) \]
      10. sub-negateN/A

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

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y - \left(\mathsf{neg}\left(y\right)\right)\right) - \left(z - x\right)} \]
    3. Applied rewrites99.8%

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

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

        \[\leadsto \frac{-1}{2} \cdot \color{blue}{\log y} - \left(z - x\right) \]
      2. lower-log.f6471.2%

        \[\leadsto -0.5 \cdot \log y - \left(z - x\right) \]
    6. Applied rewrites71.2%

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

      \[\leadsto -0.5 \cdot \log y - \color{blue}{z} \]
    8. Step-by-step derivation
      1. Applied rewrites42.2%

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

      if 4.3999999999999999e59 < x

      1. Initial program 99.8%

        \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
        2. sub-to-multN/A

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

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

          \[\leadsto \left(\color{blue}{\left(1 - \frac{\left(y + \frac{1}{2}\right) \cdot \log y}{x}\right)} \cdot x + y\right) - z \]
        5. lower-unsound-/.f6488.2%

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

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

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

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

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \color{blue}{\left(y + \frac{1}{2}\right)}}{x}\right) \cdot x + y\right) - z \]
        10. add-flipN/A

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

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \color{blue}{\left(y - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)}}{x}\right) \cdot x + y\right) - z \]
        12. metadata-eval88.2%

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \left(y - \color{blue}{-0.5}\right)}{x}\right) \cdot x + y\right) - z \]
      3. Applied rewrites88.2%

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

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

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

      Alternative 6: 57.4% accurate, 9.8× speedup?

      \[\left(1 \cdot x + y\right) - z \]
      (FPCore (x y z)
        :precision binary64
        (- (+ (* 1.0 x) y) z))
      double code(double x, double y, double z) {
      	return ((1.0 * x) + y) - z;
      }
      
      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, z)
      use fmin_fmax_functions
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          code = ((1.0d0 * x) + y) - z
      end function
      
      public static double code(double x, double y, double z) {
      	return ((1.0 * x) + y) - z;
      }
      
      def code(x, y, z):
      	return ((1.0 * x) + y) - z
      
      function code(x, y, z)
      	return Float64(Float64(Float64(1.0 * x) + y) - z)
      end
      
      function tmp = code(x, y, z)
      	tmp = ((1.0 * x) + y) - z;
      end
      
      code[x_, y_, z_] := N[(N[(N[(1.0 * x), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
      
      \left(1 \cdot x + y\right) - z
      
      Derivation
      1. Initial program 99.8%

        \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
        2. sub-to-multN/A

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

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

          \[\leadsto \left(\color{blue}{\left(1 - \frac{\left(y + \frac{1}{2}\right) \cdot \log y}{x}\right)} \cdot x + y\right) - z \]
        5. lower-unsound-/.f6488.2%

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

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

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

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

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \color{blue}{\left(y + \frac{1}{2}\right)}}{x}\right) \cdot x + y\right) - z \]
        10. add-flipN/A

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

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \color{blue}{\left(y - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)}}{x}\right) \cdot x + y\right) - z \]
        12. metadata-eval88.2%

          \[\leadsto \left(\left(1 - \frac{\log y \cdot \left(y - \color{blue}{-0.5}\right)}{x}\right) \cdot x + y\right) - z \]
      3. Applied rewrites88.2%

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

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

          \[\leadsto \left(\color{blue}{1} \cdot x + y\right) - z \]
        2. Add Preprocessing

        Alternative 7: 48.4% accurate, 6.5× speedup?

        \[\begin{array}{l} \mathbf{if}\;x \leq -1420000:\\ \;\;\;\;1 \cdot x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \]
        (FPCore (x y z)
          :precision binary64
          (if (<= x -1420000.0) (* 1.0 x) (if (<= x 4.4e+59) (- z) (* 1.0 x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -1420000.0) {
        		tmp = 1.0 * x;
        	} else if (x <= 4.4e+59) {
        		tmp = -z;
        	} else {
        		tmp = 1.0 * 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, z)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8) :: tmp
            if (x <= (-1420000.0d0)) then
                tmp = 1.0d0 * x
            else if (x <= 4.4d+59) then
                tmp = -z
            else
                tmp = 1.0d0 * x
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -1420000.0) {
        		tmp = 1.0 * x;
        	} else if (x <= 4.4e+59) {
        		tmp = -z;
        	} else {
        		tmp = 1.0 * x;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if x <= -1420000.0:
        		tmp = 1.0 * x
        	elif x <= 4.4e+59:
        		tmp = -z
        	else:
        		tmp = 1.0 * x
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (x <= -1420000.0)
        		tmp = Float64(1.0 * x);
        	elseif (x <= 4.4e+59)
        		tmp = Float64(-z);
        	else
        		tmp = Float64(1.0 * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (x <= -1420000.0)
        		tmp = 1.0 * x;
        	elseif (x <= 4.4e+59)
        		tmp = -z;
        	else
        		tmp = 1.0 * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[x, -1420000.0], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 4.4e+59], (-z), N[(1.0 * x), $MachinePrecision]]]
        
        \begin{array}{l}
        \mathbf{if}\;x \leq -1420000:\\
        \;\;\;\;1 \cdot x\\
        
        \mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\
        \;\;\;\;-z\\
        
        \mathbf{else}:\\
        \;\;\;\;1 \cdot x\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -1.42e6 or 4.3999999999999999e59 < x

          1. Initial program 99.8%

            \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
          2. Step-by-step derivation
            1. lift--.f64N/A

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

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

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

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

              \[\leadsto \color{blue}{\left(x - \left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right)\right)} + \left(\mathsf{neg}\left(z\right)\right) \]
            6. associate-+l-N/A

              \[\leadsto \color{blue}{x - \left(\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)\right)} \]
            7. sub-to-multN/A

              \[\leadsto \color{blue}{\left(1 - \frac{\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)}{x}\right) \cdot x} \]
            8. lower-unsound-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - \frac{\left(\left(y + \frac{1}{2}\right) \cdot \log y - y\right) - \left(\mathsf{neg}\left(z\right)\right)}{x}\right) \cdot x} \]
          3. Applied rewrites80.7%

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

            \[\leadsto \color{blue}{1} \cdot x \]
          5. Step-by-step derivation
            1. Applied rewrites30.7%

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

            if -1.42e6 < x < 4.3999999999999999e59

            1. Initial program 99.8%

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

              \[\leadsto \color{blue}{-1 \cdot z} \]
            3. Step-by-step derivation
              1. lower-*.f6429.3%

                \[\leadsto -1 \cdot \color{blue}{z} \]
            4. Applied rewrites29.3%

              \[\leadsto \color{blue}{-1 \cdot z} \]
            5. Step-by-step derivation
              1. lift-*.f64N/A

                \[\leadsto -1 \cdot \color{blue}{z} \]
              2. mul-1-negN/A

                \[\leadsto \mathsf{neg}\left(z\right) \]
              3. lift-neg.f6429.3%

                \[\leadsto -z \]
            6. Applied rewrites29.3%

              \[\leadsto -z \]
          6. Recombined 2 regimes into one program.
          7. Add Preprocessing

          Alternative 8: 29.3% accurate, 39.3× speedup?

          \[-z \]
          (FPCore (x y z)
            :precision binary64
            (- z))
          double code(double x, double y, double z) {
          	return -z;
          }
          
          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, z)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              code = -z
          end function
          
          public static double code(double x, double y, double z) {
          	return -z;
          }
          
          def code(x, y, z):
          	return -z
          
          function code(x, y, z)
          	return Float64(-z)
          end
          
          function tmp = code(x, y, z)
          	tmp = -z;
          end
          
          code[x_, y_, z_] := (-z)
          
          -z
          
          Derivation
          1. Initial program 99.8%

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

            \[\leadsto \color{blue}{-1 \cdot z} \]
          3. Step-by-step derivation
            1. lower-*.f6429.3%

              \[\leadsto -1 \cdot \color{blue}{z} \]
          4. Applied rewrites29.3%

            \[\leadsto \color{blue}{-1 \cdot z} \]
          5. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto -1 \cdot \color{blue}{z} \]
            2. mul-1-negN/A

              \[\leadsto \mathsf{neg}\left(z\right) \]
            3. lift-neg.f6429.3%

              \[\leadsto -z \]
          6. Applied rewrites29.3%

            \[\leadsto -z \]
          7. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025258 
          (FPCore (x y z)
            :name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
            :precision binary64
            (- (+ (- x (* (+ y 0.5) (log y))) y) z))