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

Percentage Accurate: 99.9% → 99.9%
Time: 3.8s
Alternatives: 10
Speedup: 1.0×

Specification

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

\\
\left(\left(x \cdot \log y - y\right) - z\right) + \log t
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 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.9% accurate, 1.0× speedup?

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

\\
\left(\left(x \cdot \log y - y\right) - z\right) + \log t
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\mathsf{fma}\left(\log y, x, -z\right) - y\right) + \log t \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (- (fma (log y) x (- z)) y) (log t)))
double code(double x, double y, double z, double t) {
	return (fma(log(y), x, -z) - y) + log(t);
}
function code(x, y, z, t)
	return Float64(Float64(fma(log(y), x, Float64(-z)) - y) + log(t))
end
code[x_, y_, z_, t_] := N[(N[(N[(N[Log[y], $MachinePrecision] * x + (-z)), $MachinePrecision] - y), $MachinePrecision] + N[Log[t], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\mathsf{fma}\left(\log y, x, -z\right) - y\right) + \log t
\end{array}
Derivation
  1. Initial program 99.9%

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

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

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

      \[\leadsto \left(\left(x \cdot \log y + -1 \cdot z\right) - y\right) + \log t \]
    3. *-commutativeN/A

      \[\leadsto \left(\left(\log y \cdot x + -1 \cdot z\right) - y\right) + \log t \]
    4. lower-fma.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(\log y, x, -1 \cdot z\right) - y\right) + \log t \]
    5. lift-log.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(\log y, x, -1 \cdot z\right) - y\right) + \log t \]
    6. mul-1-negN/A

      \[\leadsto \left(\mathsf{fma}\left(\log y, x, \mathsf{neg}\left(z\right)\right) - y\right) + \log t \]
    7. lower-neg.f6499.9

      \[\leadsto \left(\mathsf{fma}\left(\log y, x, -z\right) - y\right) + \log t \]
  5. Applied rewrites99.9%

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(\log y, x, -z\right) - y\right)} + \log t \]
  6. Add Preprocessing

Alternative 2: 70.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(\left(x \cdot \log y - y\right) - z\right) + \log t\\ \mathbf{if}\;t\_1 \leq -200000000000 \lor \neg \left(t\_1 \leq 1000\right):\\ \;\;\;\;\left(-y\right) - z\\ \mathbf{else}:\\ \;\;\;\;\log t - y\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ (- (- (* x (log y)) y) z) (log t))))
   (if (or (<= t_1 -200000000000.0) (not (<= t_1 1000.0)))
     (- (- y) z)
     (- (log t) y))))
double code(double x, double y, double z, double t) {
	double t_1 = (((x * log(y)) - y) - z) + log(t);
	double tmp;
	if ((t_1 <= -200000000000.0) || !(t_1 <= 1000.0)) {
		tmp = -y - z;
	} else {
		tmp = log(t) - 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, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (((x * log(y)) - y) - z) + log(t)
    if ((t_1 <= (-200000000000.0d0)) .or. (.not. (t_1 <= 1000.0d0))) then
        tmp = -y - z
    else
        tmp = log(t) - y
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (((x * Math.log(y)) - y) - z) + Math.log(t);
	double tmp;
	if ((t_1 <= -200000000000.0) || !(t_1 <= 1000.0)) {
		tmp = -y - z;
	} else {
		tmp = Math.log(t) - y;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (((x * math.log(y)) - y) - z) + math.log(t)
	tmp = 0
	if (t_1 <= -200000000000.0) or not (t_1 <= 1000.0):
		tmp = -y - z
	else:
		tmp = math.log(t) - y
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(Float64(x * log(y)) - y) - z) + log(t))
	tmp = 0.0
	if ((t_1 <= -200000000000.0) || !(t_1 <= 1000.0))
		tmp = Float64(Float64(-y) - z);
	else
		tmp = Float64(log(t) - y);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (((x * log(y)) - y) - z) + log(t);
	tmp = 0.0;
	if ((t_1 <= -200000000000.0) || ~((t_1 <= 1000.0)))
		tmp = -y - z;
	else
		tmp = log(t) - y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision] + N[Log[t], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -200000000000.0], N[Not[LessEqual[t$95$1, 1000.0]], $MachinePrecision]], N[((-y) - z), $MachinePrecision], N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(\left(x \cdot \log y - y\right) - z\right) + \log t\\
\mathbf{if}\;t\_1 \leq -200000000000 \lor \neg \left(t\_1 \leq 1000\right):\\
\;\;\;\;\left(-y\right) - z\\

\mathbf{else}:\\
\;\;\;\;\log t - y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (-.f64 (*.f64 x (log.f64 y)) y) z) (log.f64 t)) < -2e11 or 1e3 < (+.f64 (-.f64 (-.f64 (*.f64 x (log.f64 y)) y) z) (log.f64 t))

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6469.0

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites69.0%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
    6. Taylor expanded in y around inf

      \[\leadsto -1 \cdot y - z \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(y\right)\right) - z \]
      2. lower-neg.f6468.5

        \[\leadsto \left(-y\right) - z \]
    8. Applied rewrites68.5%

      \[\leadsto \left(-y\right) - z \]

    if -2e11 < (+.f64 (-.f64 (-.f64 (*.f64 x (log.f64 y)) y) z) (log.f64 t)) < 1e3

    1. Initial program 100.0%

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

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

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

        \[\leadsto \left(x \cdot \log y + \log t\right) - y \]
      3. *-commutativeN/A

        \[\leadsto \left(\log y \cdot x + \log t\right) - y \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      5. lift-log.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      6. lift-log.f6499.4

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
    5. Applied rewrites99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log y, x, \log t\right) - y} \]
    6. Taylor expanded in x around 0

      \[\leadsto \log t - y \]
    7. Step-by-step derivation
      1. lift-log.f6495.4

        \[\leadsto \log t - y \]
    8. Applied rewrites95.4%

      \[\leadsto \log t - y \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(x \cdot \log y - y\right) - z\right) + \log t \leq -200000000000 \lor \neg \left(\left(\left(x \cdot \log y - y\right) - z\right) + \log t \leq 1000\right):\\ \;\;\;\;\left(-y\right) - z\\ \mathbf{else}:\\ \;\;\;\;\log t - y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot \log y - y\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+16}:\\ \;\;\;\;\left(-y\right) - z\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+127}:\\ \;\;\;\;\log t - z\\ \mathbf{else}:\\ \;\;\;\;\log y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* x (log y)) y)))
   (if (<= t_1 -2e+16)
     (- (- y) z)
     (if (<= t_1 2e+127) (- (log t) z) (* (log y) x)))))
double code(double x, double y, double z, double t) {
	double t_1 = (x * log(y)) - y;
	double tmp;
	if (t_1 <= -2e+16) {
		tmp = -y - z;
	} else if (t_1 <= 2e+127) {
		tmp = log(t) - z;
	} else {
		tmp = log(y) * x;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (x * log(y)) - y
    if (t_1 <= (-2d+16)) then
        tmp = -y - z
    else if (t_1 <= 2d+127) then
        tmp = log(t) - z
    else
        tmp = log(y) * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (x * Math.log(y)) - y;
	double tmp;
	if (t_1 <= -2e+16) {
		tmp = -y - z;
	} else if (t_1 <= 2e+127) {
		tmp = Math.log(t) - z;
	} else {
		tmp = Math.log(y) * x;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (x * math.log(y)) - y
	tmp = 0
	if t_1 <= -2e+16:
		tmp = -y - z
	elif t_1 <= 2e+127:
		tmp = math.log(t) - z
	else:
		tmp = math.log(y) * x
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(x * log(y)) - y)
	tmp = 0.0
	if (t_1 <= -2e+16)
		tmp = Float64(Float64(-y) - z);
	elseif (t_1 <= 2e+127)
		tmp = Float64(log(t) - z);
	else
		tmp = Float64(log(y) * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (x * log(y)) - y;
	tmp = 0.0;
	if (t_1 <= -2e+16)
		tmp = -y - z;
	elseif (t_1 <= 2e+127)
		tmp = log(t) - z;
	else
		tmp = log(y) * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+16], N[((-y) - z), $MachinePrecision], If[LessEqual[t$95$1, 2e+127], N[(N[Log[t], $MachinePrecision] - z), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot \log y - y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+16}:\\
\;\;\;\;\left(-y\right) - z\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+127}:\\
\;\;\;\;\log t - z\\

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


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6473.6

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites73.6%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
    6. Taylor expanded in y around inf

      \[\leadsto -1 \cdot y - z \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(y\right)\right) - z \]
      2. lower-neg.f6473.6

        \[\leadsto \left(-y\right) - z \]
    8. Applied rewrites73.6%

      \[\leadsto \left(-y\right) - z \]

    if -2e16 < (-.f64 (*.f64 x (log.f64 y)) y) < 1.99999999999999991e127

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6491.3

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites91.3%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
    6. Taylor expanded in y around 0

      \[\leadsto \log t - z \]
    7. Step-by-step derivation
      1. lift-log.f6491.3

        \[\leadsto \log t - z \]
    8. Applied rewrites91.3%

      \[\leadsto \log t - z \]

    if 1.99999999999999991e127 < (-.f64 (*.f64 x (log.f64 y)) y)

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{x \cdot \log y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \log y \cdot \color{blue}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \log y \cdot \color{blue}{x} \]
      3. lift-log.f6486.1

        \[\leadsto \log y \cdot x \]
    5. Applied rewrites86.1%

      \[\leadsto \color{blue}{\log y \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -500 \lor \neg \left(z \leq 0.00013\right):\\ \;\;\;\;\left(-1 + \frac{\log y \cdot x - y}{z}\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log y, x, \log t\right) - y\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -500.0) (not (<= z 0.00013)))
   (* (+ -1.0 (/ (- (* (log y) x) y) z)) z)
   (- (fma (log y) x (log t)) y)))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -500.0) || !(z <= 0.00013)) {
		tmp = (-1.0 + (((log(y) * x) - y) / z)) * z;
	} else {
		tmp = fma(log(y), x, log(t)) - y;
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -500.0) || !(z <= 0.00013))
		tmp = Float64(Float64(-1.0 + Float64(Float64(Float64(log(y) * x) - y) / z)) * z);
	else
		tmp = Float64(fma(log(y), x, log(t)) - y);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -500.0], N[Not[LessEqual[z, 0.00013]], $MachinePrecision]], N[(N[(-1.0 + N[(N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x + N[Log[t], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -500 \lor \neg \left(z \leq 0.00013\right):\\
\;\;\;\;\left(-1 + \frac{\log y \cdot x - y}{z}\right) \cdot z\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, \log t\right) - y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -500 or 1.29999999999999989e-4 < z

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \left(1 + -1 \cdot \frac{\left(\log t + x \cdot \log y\right) - y}{z}\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

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

        \[\leadsto \mathsf{neg}\left(\left(1 + -1 \cdot \frac{\left(\log t + x \cdot \log y\right) - y}{z}\right) \cdot z\right) \]
      3. distribute-rgt-neg-inN/A

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

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

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

      \[\leadsto \color{blue}{\left(1 - \frac{\mathsf{fma}\left(\log y, x, \log t\right) - y}{z}\right) \cdot \left(-z\right)} \]
    6. Taylor expanded in x around inf

      \[\leadsto \left(1 - \frac{x \cdot \log y - y}{z}\right) \cdot \left(-z\right) \]
    7. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \left(1 - \frac{\log y \cdot x - y}{z}\right) \cdot \left(-z\right) \]
      3. lift-*.f6498.9

        \[\leadsto \left(1 - \frac{\log y \cdot x - y}{z}\right) \cdot \left(-z\right) \]
    8. Applied rewrites98.9%

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

    if -500 < z < 1.29999999999999989e-4

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(x \cdot \log y + \log t\right) - y \]
      3. *-commutativeN/A

        \[\leadsto \left(\log y \cdot x + \log t\right) - y \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      5. lift-log.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      6. lift-log.f6499.7

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
    5. Applied rewrites99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log y, x, \log t\right) - y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -500 \lor \neg \left(z \leq 0.00013\right):\\ \;\;\;\;\left(-1 + \frac{\log y \cdot x - y}{z}\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log y, x, \log t\right) - y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 70.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot \log y - y \leq -2 \cdot 10^{+16}:\\
\;\;\;\;\left(-y\right) - z\\

\mathbf{else}:\\
\;\;\;\;\log t - z\\


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6473.6

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites73.6%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
    6. Taylor expanded in y around inf

      \[\leadsto -1 \cdot y - z \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(y\right)\right) - z \]
      2. lower-neg.f6473.6

        \[\leadsto \left(-y\right) - z \]
    8. Applied rewrites73.6%

      \[\leadsto \left(-y\right) - z \]

    if -2e16 < (-.f64 (*.f64 x (log.f64 y)) y)

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6470.2

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites70.2%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
    6. Taylor expanded in y around 0

      \[\leadsto \log t - z \]
    7. Step-by-step derivation
      1. lift-log.f6470.3

        \[\leadsto \log t - z \]
    8. Applied rewrites70.3%

      \[\leadsto \log t - z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 88.2% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+128} \lor \neg \left(x \leq 0.004\right):\\
\;\;\;\;\log y \cdot x - y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.39999999999999991e128 or 0.0040000000000000001 < x

    1. Initial program 99.8%

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

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

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

        \[\leadsto \left(x \cdot \log y + \log t\right) - y \]
      3. *-commutativeN/A

        \[\leadsto \left(\log y \cdot x + \log t\right) - y \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      5. lift-log.f64N/A

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
      6. lift-log.f6485.4

        \[\leadsto \mathsf{fma}\left(\log y, x, \log t\right) - y \]
    5. Applied rewrites85.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log y, x, \log t\right) - y} \]
    6. Taylor expanded in x around inf

      \[\leadsto x \cdot \log y - y \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \log y \cdot x - y \]
      2. lift-log.f64N/A

        \[\leadsto \log y \cdot x - y \]
      3. lift-*.f6484.9

        \[\leadsto \log y \cdot x - y \]
    8. Applied rewrites84.9%

      \[\leadsto \log y \cdot x - y \]

    if -1.39999999999999991e128 < x < 0.0040000000000000001

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6495.1

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites95.1%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{+128} \lor \neg \left(x \leq 0.004\right):\\ \;\;\;\;\log y \cdot x - y\\ \mathbf{else}:\\ \;\;\;\;\left(\log t - y\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 83.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.45 \cdot 10^{+128} \lor \neg \left(x \leq 7 \cdot 10^{+176}\right):\\ \;\;\;\;\log y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\log t - y\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= x -2.45e+128) (not (<= x 7e+176)))
   (* (log y) x)
   (- (- (log t) y) z)))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((x <= -2.45e+128) || !(x <= 7e+176)) {
		tmp = log(y) * x;
	} else {
		tmp = (log(t) - 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, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((x <= (-2.45d+128)) .or. (.not. (x <= 7d+176))) then
        tmp = log(y) * x
    else
        tmp = (log(t) - y) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((x <= -2.45e+128) || !(x <= 7e+176)) {
		tmp = Math.log(y) * x;
	} else {
		tmp = (Math.log(t) - y) - z;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (x <= -2.45e+128) or not (x <= 7e+176):
		tmp = math.log(y) * x
	else:
		tmp = (math.log(t) - y) - z
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((x <= -2.45e+128) || !(x <= 7e+176))
		tmp = Float64(log(y) * x);
	else
		tmp = Float64(Float64(log(t) - y) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((x <= -2.45e+128) || ~((x <= 7e+176)))
		tmp = log(y) * x;
	else
		tmp = (log(t) - y) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -2.45e+128], N[Not[LessEqual[x, 7e+176]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+128} \lor \neg \left(x \leq 7 \cdot 10^{+176}\right):\\
\;\;\;\;\log y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.45000000000000009e128 or 7.00000000000000005e176 < x

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{x \cdot \log y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \log y \cdot \color{blue}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \log y \cdot \color{blue}{x} \]
      3. lift-log.f6475.3

        \[\leadsto \log y \cdot x \]
    5. Applied rewrites75.3%

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

    if -2.45000000000000009e128 < x < 7.00000000000000005e176

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

        \[\leadsto \left(\log t - y\right) - z \]
      4. lift-log.f6489.3

        \[\leadsto \left(\log t - y\right) - z \]
    5. Applied rewrites89.3%

      \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.45 \cdot 10^{+128} \lor \neg \left(x \leq 7 \cdot 10^{+176}\right):\\ \;\;\;\;\log y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\log t - y\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 48.6% accurate, 23.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 2.35 \cdot 10^{+24}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array} \]
(FPCore (x y z t) :precision binary64 (if (<= y 2.35e+24) (- z) (- y)))
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= 2.35e+24) {
		tmp = -z;
	} else {
		tmp = -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, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (y <= 2.35d+24) then
        tmp = -z
    else
        tmp = -y
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= 2.35e+24) {
		tmp = -z;
	} else {
		tmp = -y;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if y <= 2.35e+24:
		tmp = -z
	else:
		tmp = -y
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (y <= 2.35e+24)
		tmp = Float64(-z);
	else
		tmp = Float64(-y);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (y <= 2.35e+24)
		tmp = -z;
	else
		tmp = -y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.35e+24], (-z), (-y)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.35 \cdot 10^{+24}:\\
\;\;\;\;-z\\

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


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. lower-neg.f6437.2

        \[\leadsto -z \]
    5. Applied rewrites37.2%

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

    if 2.35e24 < y

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot y} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(y\right) \]
      2. lower-neg.f6470.7

        \[\leadsto -y \]
    5. Applied rewrites70.7%

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

Alternative 9: 58.2% accurate, 35.8× speedup?

\[\begin{array}{l} \\ \left(-y\right) - z \end{array} \]
(FPCore (x y z t) :precision binary64 (- (- y) z))
double code(double x, double y, double z, double t) {
	return -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, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = -y - z
end function
public static double code(double x, double y, double z, double t) {
	return -y - z;
}
def code(x, y, z, t):
	return -y - z
function code(x, y, z, t)
	return Float64(Float64(-y) - z)
end
function tmp = code(x, y, z, t)
	tmp = -y - z;
end
code[x_, y_, z_, t_] := N[((-y) - z), $MachinePrecision]
\begin{array}{l}

\\
\left(-y\right) - z
\end{array}
Derivation
  1. Initial program 99.9%

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

    \[\leadsto \color{blue}{\log t - \left(y + z\right)} \]
  4. Step-by-step derivation
    1. associate--r+N/A

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

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

      \[\leadsto \left(\log t - y\right) - z \]
    4. lift-log.f6472.3

      \[\leadsto \left(\log t - y\right) - z \]
  5. Applied rewrites72.3%

    \[\leadsto \color{blue}{\left(\log t - y\right) - z} \]
  6. Taylor expanded in y around inf

    \[\leadsto -1 \cdot y - z \]
  7. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \left(\mathsf{neg}\left(y\right)\right) - z \]
    2. lower-neg.f6460.8

      \[\leadsto \left(-y\right) - z \]
  8. Applied rewrites60.8%

    \[\leadsto \left(-y\right) - z \]
  9. Add Preprocessing

Alternative 10: 30.1% accurate, 71.7× speedup?

\[\begin{array}{l} \\ -y \end{array} \]
(FPCore (x y z t) :precision binary64 (- y))
double code(double x, double y, double z, double t) {
	return -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, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = -y
end function
public static double code(double x, double y, double z, double t) {
	return -y;
}
def code(x, y, z, t):
	return -y
function code(x, y, z, t)
	return Float64(-y)
end
function tmp = code(x, y, z, t)
	tmp = -y;
end
code[x_, y_, z_, t_] := (-y)
\begin{array}{l}

\\
-y
\end{array}
Derivation
  1. Initial program 99.9%

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

    \[\leadsto \color{blue}{-1 \cdot y} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(y\right) \]
    2. lower-neg.f6436.8

      \[\leadsto -y \]
  5. Applied rewrites36.8%

    \[\leadsto \color{blue}{-y} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025051 
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:incompleteGamma from math-functions-0.1.5.2, A"
  :precision binary64
  (+ (- (- (* x (log y)) y) z) (log t)))