
(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 11 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 (- (+ (- (fma (+ 0.5 y) (log y) (- x))) y) z))
double code(double x, double y, double z) {
return (-fma((0.5 + y), log(y), -x) + y) - z;
}
function code(x, y, z) return Float64(Float64(Float64(-fma(Float64(0.5 + y), log(y), Float64(-x))) + y) - z) end
code[x_, y_, z_] := N[(N[((-N[(N[(0.5 + y), $MachinePrecision] * N[Log[y], $MachinePrecision] + (-x)), $MachinePrecision]) + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(-\mathsf{fma}\left(0.5 + y, \log y, -x\right)\right) + y\right) - z
\end{array}
Initial program 99.8%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
associate-/l*N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lift-log.f64N/A
+-commutativeN/A
lower-/.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6487.9
Applied rewrites87.9%
Taylor expanded in x around 0
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
lift-log.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- x (* (+ y 0.5) (log y))) y)))
(if (<= t_0 -4e+106)
(* (- 1.0 (log y)) y)
(if (<= t_0 -1e+48)
(- x z)
(if (<= t_0 500.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 tmp;
if (t_0 <= -4e+106) {
tmp = (1.0 - log(y)) * y;
} else if (t_0 <= -1e+48) {
tmp = x - z;
} else if (t_0 <= 500.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) tmp = 0.0 if (t_0 <= -4e+106) tmp = Float64(Float64(1.0 - log(y)) * y); elseif (t_0 <= -1e+48) tmp = Float64(x - z); elseif (t_0 <= 500.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]}, If[LessEqual[t$95$0, -4e+106], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, -1e+48], N[(x - z), $MachinePrecision], If[LessEqual[t$95$0, 500.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\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+106}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+48}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;t\_0 \leq 500:\\
\;\;\;\;-\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.00000000000000036e106Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
log-pow-revN/A
lower-*.f64N/A
lift-log.f6458.5
Applied rewrites58.5%
lift-*.f64N/A
lift-log.f64N/A
*-lft-identityN/A
lift-log.f6458.5
Applied rewrites58.5%
if -4.00000000000000036e106 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -1.00000000000000004e48 or 500 < (+.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 rewrites86.3%
if -1.00000000000000004e48 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < 500Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6492.6
Applied rewrites92.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6488.3
Applied rewrites88.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (+ (- x (* (+ y 0.5) (log y))) y) z))) (if (<= t_0 -5e+29) (- x z) (if (<= t_0 500.0) (* -0.5 (log y)) (- x z)))))
double code(double x, double y, double z) {
double t_0 = ((x - ((y + 0.5) * log(y))) + y) - z;
double tmp;
if (t_0 <= -5e+29) {
tmp = x - z;
} else if (t_0 <= 500.0) {
tmp = -0.5 * log(y);
} else {
tmp = x - 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) :: t_0
real(8) :: tmp
t_0 = ((x - ((y + 0.5d0) * log(y))) + y) - z
if (t_0 <= (-5d+29)) then
tmp = x - z
else if (t_0 <= 500.0d0) then
tmp = (-0.5d0) * log(y)
else
tmp = x - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = ((x - ((y + 0.5) * Math.log(y))) + y) - z;
double tmp;
if (t_0 <= -5e+29) {
tmp = x - z;
} else if (t_0 <= 500.0) {
tmp = -0.5 * Math.log(y);
} else {
tmp = x - z;
}
return tmp;
}
def code(x, y, z): t_0 = ((x - ((y + 0.5) * math.log(y))) + y) - z tmp = 0 if t_0 <= -5e+29: tmp = x - z elif t_0 <= 500.0: tmp = -0.5 * math.log(y) else: tmp = x - z return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) tmp = 0.0 if (t_0 <= -5e+29) tmp = Float64(x - z); elseif (t_0 <= 500.0) tmp = Float64(-0.5 * log(y)); else tmp = Float64(x - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = ((x - ((y + 0.5) * log(y))) + y) - z; tmp = 0.0; if (t_0 <= -5e+29) tmp = x - z; elseif (t_0 <= 500.0) tmp = -0.5 * log(y); else tmp = x - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+29], N[(x - z), $MachinePrecision], If[LessEqual[t$95$0, 500.0], N[(-0.5 * N[Log[y], $MachinePrecision]), $MachinePrecision], N[(x - z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+29}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;t\_0 \leq 500:\\
\;\;\;\;-0.5 \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) < -5.0000000000000001e29 or 500 < (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites66.1%
if -5.0000000000000001e29 < (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) < 500Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6489.9
Applied rewrites89.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.f6483.8
Applied rewrites83.8%
Taylor expanded in z around 0
lower-*.f64N/A
lift-log.f6478.0
Applied rewrites78.0%
(FPCore (x y z) :precision binary64 (if (<= x -106.0) (- x z) (if (<= x 0.00052) (- (fma (log y) 0.5 z)) (- x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -106.0) {
tmp = x - z;
} else if (x <= 0.00052) {
tmp = -fma(log(y), 0.5, z);
} else {
tmp = x - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -106.0) tmp = Float64(x - z); elseif (x <= 0.00052) tmp = Float64(-fma(log(y), 0.5, z)); else tmp = Float64(x - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -106.0], N[(x - z), $MachinePrecision], If[LessEqual[x, 0.00052], (-N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), N[(x - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -106:\\
\;\;\;\;x - z\\
\mathbf{elif}\;x \leq 0.00052:\\
\;\;\;\;-\mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if x < -106 or 5.19999999999999954e-4 < x Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites77.1%
if -106 < x < 5.19999999999999954e-4Initial program 99.8%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6462.5
Applied rewrites62.5%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6462.2
Applied rewrites62.2%
(FPCore (x y z) :precision binary64 (if (<= y 3.6e-8) (- 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 <= 3.6e-8) {
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 <= 3.6e-8) 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, 3.6e-8], 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 3.6 \cdot 10^{-8}:\\
\;\;\;\;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 < 3.59999999999999981e-8Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6499.9
Applied rewrites99.9%
if 3.59999999999999981e-8 < y Initial program 99.7%
Taylor expanded in y around inf
Applied rewrites98.5%
(FPCore (x y z) :precision binary64 (if (<= y 3.3e+78) (- x (fma (log y) 0.5 z)) (- (* (- 1.0 (log y)) y) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.3e+78) {
tmp = x - fma(log(y), 0.5, z);
} else {
tmp = ((1.0 - log(y)) * y) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 3.3e+78) tmp = Float64(x - fma(log(y), 0.5, z)); else tmp = Float64(Float64(Float64(1.0 - log(y)) * y) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 3.3e+78], N[(x - N[(N[Log[y], $MachinePrecision] * 0.5 + z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{+78}:\\
\;\;\;\;x - \mathsf{fma}\left(\log y, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y - z\\
\end{array}
\end{array}
if y < 3.3e78Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6493.4
Applied rewrites93.4%
if 3.3e78 < y Initial program 99.6%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
associate-/l*N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lift-log.f64N/A
+-commutativeN/A
lower-/.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6470.8
Applied rewrites70.8%
Taylor expanded in y around inf
*-commutativeN/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
log-pow-revN/A
lower-*.f64N/A
lift-log.f64N/A
lift-*.f64N/A
lift--.f6483.2
lift-*.f64N/A
lift-log.f64N/A
*-lft-identityN/A
lift-log.f6483.2
Applied rewrites83.2%
(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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (<= y 3.8e+119) (- x (fma (log y) 0.5 z)) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.8e+119) {
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 <= 3.8e+119) 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, 3.8e+119], 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 3.8 \cdot 10^{+119}:\\
\;\;\;\;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 < 3.7999999999999999e119Initial program 99.9%
Taylor expanded in y around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f6489.5
Applied rewrites89.5%
if 3.7999999999999999e119 < y Initial program 99.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
log-pow-revN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
log-pow-revN/A
lower-*.f64N/A
lift-log.f6472.6
Applied rewrites72.6%
lift-*.f64N/A
lift-log.f64N/A
*-lft-identityN/A
lift-log.f6472.6
Applied rewrites72.6%
(FPCore (x y z) :precision binary64 (if (<= z -3.8e+32) (- z) (if (<= z 1.9e+43) x (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e+32) {
tmp = -z;
} else if (z <= 1.9e+43) {
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 <= (-3.8d+32)) then
tmp = -z
else if (z <= 1.9d+43) 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 <= -3.8e+32) {
tmp = -z;
} else if (z <= 1.9e+43) {
tmp = x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.8e+32: tmp = -z elif z <= 1.9e+43: tmp = x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.8e+32) tmp = Float64(-z); elseif (z <= 1.9e+43) tmp = x; else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.8e+32) tmp = -z; elseif (z <= 1.9e+43) tmp = x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.8e+32], (-z), If[LessEqual[z, 1.9e+43], x, (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+32}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -3.8000000000000003e32 or 1.90000000000000004e43 < z Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6461.3
Applied rewrites61.3%
if -3.8000000000000003e32 < z < 1.90000000000000004e43Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites38.6%
(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 rewrites30.4%
(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 2025093
(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))