
(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]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
(FPCore (x y z) :precision binary64 (+ x (- y (fma (log y) (- y -0.5) z))))
double code(double x, double y, double z) {
return x + (y - fma(log(y), (y - -0.5), z));
}
function code(x, y, z) return Float64(x + Float64(y - fma(log(y), Float64(y - -0.5), z))) end
code[x_, y_, z_] := N[(x + N[(y - N[(N[Log[y], $MachinePrecision] * N[(y - -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - \mathsf{fma}\left(\log y, y - -0.5, z\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- x (* (+ y 0.5) (log y))) y)) (t_1 (* (- 1.0 (log y)) y)))
(if (<= t_0 -5e+186)
t_1
(if (<= t_0 -1e+111)
(- x z)
(if (<= t_0 -20000000000.0)
t_1
(if (<= t_0 335.0) (- (fma (log y) 0.5 z)) (- x z)))))))
double code(double x, double y, double z) {
double t_0 = (x - ((y + 0.5) * log(y))) + y;
double t_1 = (1.0 - log(y)) * y;
double tmp;
if (t_0 <= -5e+186) {
tmp = t_1;
} else if (t_0 <= -1e+111) {
tmp = x - z;
} else if (t_0 <= -20000000000.0) {
tmp = t_1;
} else if (t_0 <= 335.0) {
tmp = -fma(log(y), 0.5, z);
} else {
tmp = x - z;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) t_1 = Float64(Float64(1.0 - log(y)) * y) tmp = 0.0 if (t_0 <= -5e+186) tmp = t_1; elseif (t_0 <= -1e+111) tmp = Float64(x - z); elseif (t_0 <= -20000000000.0) tmp = t_1; elseif (t_0 <= 335.0) tmp = Float64(-fma(log(y), 0.5, z)); else tmp = Float64(x - z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+186], t$95$1, If[LessEqual[t$95$0, -1e+111], N[(x - z), $MachinePrecision], If[LessEqual[t$95$0, -20000000000.0], t$95$1, If[LessEqual[t$95$0, 335.0], (-N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), N[(x - z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - \left(y + 0.5\right) \cdot \log y\right) + y\\
t_1 := \left(1 - \log y\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+186}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+111}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;t\_0 \leq -20000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 335:\\
\;\;\;\;-\mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -4.99999999999999954e186 or -9.99999999999999957e110 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -2e10Initial program 99.7%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
lower--.f6456.8
Applied rewrites56.8%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6453.3
Applied rewrites53.3%
if -4.99999999999999954e186 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -9.99999999999999957e110 or 335 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites76.9%
if -2e10 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < 335Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6497.3
Applied rewrites97.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6495.6
Applied rewrites95.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- x (* (+ y 0.5) (log y))) y)))
(if (<= t_0 -5e+176)
(+ x (* (- 1.0 (log y)) y))
(if (<= t_0 18.12)
(- y (fma (log y) (- y -0.5) z))
(- x (fma (log y) 0.5 z))))))
double code(double x, double y, double z) {
double t_0 = (x - ((y + 0.5) * log(y))) + y;
double tmp;
if (t_0 <= -5e+176) {
tmp = x + ((1.0 - log(y)) * y);
} else if (t_0 <= 18.12) {
tmp = y - fma(log(y), (y - -0.5), z);
} else {
tmp = x - fma(log(y), 0.5, z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) tmp = 0.0 if (t_0 <= -5e+176) tmp = Float64(x + Float64(Float64(1.0 - log(y)) * y)); elseif (t_0 <= 18.12) tmp = Float64(y - fma(log(y), Float64(y - -0.5), z)); else tmp = Float64(x - fma(log(y), 0.5, z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+176], N[(x + N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 18.12], N[(y - N[(N[Log[y], $MachinePrecision] * N[(y - -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - \left(y + 0.5\right) \cdot \log y\right) + y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+176}:\\
\;\;\;\;x + \left(1 - \log y\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 18.12:\\
\;\;\;\;y - \mathsf{fma}\left(\log y, y - -0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -5e176Initial program 99.6%
Taylor expanded in x around 0
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.6
Applied rewrites99.6%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6489.2
Applied rewrites89.2%
if -5e176 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < 18.120000000000001Initial program 99.7%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6478.2
Applied rewrites78.2%
if 18.120000000000001 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6499.6
Applied rewrites99.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- x (* (+ y 0.5) (log y))) y)) (t_1 (* (- 1.0 (log y)) y)))
(if (<= t_0 -5e+176)
(+ x t_1)
(if (<= t_0 -2000000000.0) (- t_1 z) (- x (fma (log y) 0.5 z))))))
double code(double x, double y, double z) {
double t_0 = (x - ((y + 0.5) * log(y))) + y;
double t_1 = (1.0 - log(y)) * y;
double tmp;
if (t_0 <= -5e+176) {
tmp = x + t_1;
} else if (t_0 <= -2000000000.0) {
tmp = t_1 - z;
} else {
tmp = x - fma(log(y), 0.5, z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) t_1 = Float64(Float64(1.0 - log(y)) * y) tmp = 0.0 if (t_0 <= -5e+176) tmp = Float64(x + t_1); elseif (t_0 <= -2000000000.0) tmp = Float64(t_1 - z); else tmp = Float64(x - fma(log(y), 0.5, z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+176], N[(x + t$95$1), $MachinePrecision], If[LessEqual[t$95$0, -2000000000.0], N[(t$95$1 - z), $MachinePrecision], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - \left(y + 0.5\right) \cdot \log y\right) + y\\
t_1 := \left(1 - \log y\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+176}:\\
\;\;\;\;x + t\_1\\
\mathbf{elif}\;t\_0 \leq -2000000000:\\
\;\;\;\;t\_1 - z\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -5e176Initial program 99.6%
Taylor expanded in x around 0
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.6
Applied rewrites99.6%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6489.2
Applied rewrites89.2%
if -5e176 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -2e9Initial program 99.7%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
lower--.f6489.8
Applied rewrites89.8%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6477.1
Applied rewrites77.1%
if -2e9 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6498.3
Applied rewrites98.3%
(FPCore (x y z)
:precision binary64
(if (<= z -1.28e+36)
(- x z)
(if (<= z 750000.0)
(- (+ y x) (* (log y) (- y -0.5)))
(- y (fma (log y) (- y -0.5) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.28e+36) {
tmp = x - z;
} else if (z <= 750000.0) {
tmp = (y + x) - (log(y) * (y - -0.5));
} else {
tmp = y - fma(log(y), (y - -0.5), z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.28e+36) tmp = Float64(x - z); elseif (z <= 750000.0) tmp = Float64(Float64(y + x) - Float64(log(y) * Float64(y - -0.5))); else tmp = Float64(y - fma(log(y), Float64(y - -0.5), z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.28e+36], N[(x - z), $MachinePrecision], If[LessEqual[z, 750000.0], N[(N[(y + x), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * N[(y - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y - N[(N[Log[y], $MachinePrecision] * N[(y - -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{+36}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;z \leq 750000:\\
\;\;\;\;\left(y + x\right) - \log y \cdot \left(y - -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;y - \mathsf{fma}\left(\log y, y - -0.5, z\right)\\
\end{array}
\end{array}
if z < -1.27999999999999993e36Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites79.1%
if -1.27999999999999993e36 < z < 7.5e5Initial program 99.8%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-*.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6497.3
Applied rewrites97.3%
if 7.5e5 < z Initial program 99.9%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6480.3
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (if (<= x -255000000000.0) (- x z) (if (<= x 1.7e+49) (- (fma (log y) 0.5 z)) (- x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -255000000000.0) {
tmp = x - z;
} else if (x <= 1.7e+49) {
tmp = -fma(log(y), 0.5, z);
} else {
tmp = x - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -255000000000.0) tmp = Float64(x - z); elseif (x <= 1.7e+49) tmp = Float64(-fma(log(y), 0.5, z)); else tmp = Float64(x - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -255000000000.0], N[(x - z), $MachinePrecision], If[LessEqual[x, 1.7e+49], (-N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), N[(x - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -255000000000:\\
\;\;\;\;x - z\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+49}:\\
\;\;\;\;-\mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if x < -2.55e11 or 1.7e49 < x Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites79.6%
if -2.55e11 < x < 1.7e49Initial program 99.8%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6463.9
Applied rewrites63.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6461.0
Applied rewrites61.0%
(FPCore (x y z) :precision binary64 (if (<= y 2.32e-7) (- x (fma (log y) 0.5 z)) (- (+ (- x (* y (log y))) y) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.32e-7) {
tmp = x - fma(log(y), 0.5, z);
} else {
tmp = ((x - (y * log(y))) + y) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.32e-7) tmp = Float64(x - fma(log(y), 0.5, z)); else tmp = Float64(Float64(Float64(x - Float64(y * log(y))) + y) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.32e-7], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.32 \cdot 10^{-7}:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x - y \cdot \log y\right) + y\right) - z\\
\end{array}
\end{array}
if y < 2.3200000000000001e-7Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6499.8
Applied rewrites99.8%
if 2.3200000000000001e-7 < y Initial program 99.7%
Taylor expanded in y around inf
Applied rewrites98.6%
(FPCore (x y z) :precision binary64 (if (<= y 55000.0) (- x (fma (log y) 0.5 z)) (+ x (* (- 1.0 (log y)) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 55000.0) {
tmp = x - fma(log(y), 0.5, z);
} else {
tmp = x + ((1.0 - log(y)) * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 55000.0) tmp = Float64(x - fma(log(y), 0.5, z)); else tmp = Float64(x + Float64(Float64(1.0 - log(y)) * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 55000.0], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 55000:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - \log y\right) \cdot y\\
\end{array}
\end{array}
if y < 55000Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6498.9
Applied rewrites98.9%
if 55000 < y Initial program 99.7%
Taylor expanded in x around 0
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
+-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.7
Applied rewrites99.7%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6479.0
Applied rewrites79.0%
(FPCore (x y z) :precision binary64 (if (<= y 2.8e+183) (- x (fma (log y) 0.5 z)) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.8e+183) {
tmp = x - fma(log(y), 0.5, z);
} else {
tmp = (1.0 - log(y)) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.8e+183) tmp = Float64(x - fma(log(y), 0.5, z)); else tmp = Float64(Float64(1.0 - log(y)) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.8e+183], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{+183}:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\end{array}
\end{array}
if y < 2.80000000000000018e183Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6484.0
Applied rewrites84.0%
if 2.80000000000000018e183 < y Initial program 99.5%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
lower--.f649.1
Applied rewrites9.1%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
unpow1N/A
lower-*.f64N/A
lower--.f64N/A
lift-log.f6480.3
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e-6) (- z) (if (<= z 5.2e+19) x (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-6) {
tmp = -z;
} else if (z <= 5.2e+19) {
tmp = x;
} else {
tmp = -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 (z <= (-1.2d-6)) then
tmp = -z
else if (z <= 5.2d+19) then
tmp = x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-6) {
tmp = -z;
} else if (z <= 5.2e+19) {
tmp = x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e-6: tmp = -z elif z <= 5.2e+19: tmp = x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e-6) tmp = Float64(-z); elseif (z <= 5.2e+19) tmp = x; else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.2e-6) tmp = -z; elseif (z <= 5.2e+19) tmp = x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e-6], (-z), If[LessEqual[z, 5.2e+19], x, (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-6}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.1999999999999999e-6 or 5.2e19 < z Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6457.9
Applied rewrites57.9%
if -1.1999999999999999e-6 < z < 5.2e19Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites38.0%
(FPCore (x y z) :precision binary64 (- x z))
double code(double x, double y, double z) {
return x - 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 - z
end function
public static double code(double x, double y, double z) {
return x - z;
}
def code(x, y, z): return x - z
function code(x, y, z) return Float64(x - z) end
function tmp = code(x, y, z) tmp = x - z; end
code[x_, y_, z_] := N[(x - z), $MachinePrecision]
\begin{array}{l}
\\
x - z
\end{array}
Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites57.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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 = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites29.8%
(FPCore (x y z) :precision binary64 (- (- (+ y x) z) (* (+ y 0.5) (log y))))
double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 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 = ((y + x) - z) - ((y + 0.5d0) * log(y))
end function
public static double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 0.5) * Math.log(y));
}
def code(x, y, z): return ((y + x) - z) - ((y + 0.5) * math.log(y))
function code(x, y, z) return Float64(Float64(Float64(y + x) - z) - Float64(Float64(y + 0.5) * log(y))) end
function tmp = code(x, y, z) tmp = ((y + x) - z) - ((y + 0.5) * log(y)); end
code[x_, y_, z_] := N[(N[(N[(y + x), $MachinePrecision] - z), $MachinePrecision] - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y
\end{array}
herbie shell --seed 2025099
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (- (- (+ y x) z) (* (+ y 1/2) (log y))))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))