
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
return ((x - ((y + 0.5) * log(y))) + y) - z;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z): return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z) return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) end
function tmp = code(x, y, z) tmp = ((x - ((y + 0.5) * log(y))) + y) - z; end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
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]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
(FPCore (x y z) :precision binary64 (- (- x (log (sqrt y))) (fma (log y) y (- z y))))
double code(double x, double y, double z) {
return (x - log(sqrt(y))) - fma(log(y), y, (z - y));
}
function code(x, y, z) return Float64(Float64(x - log(sqrt(y))) - fma(log(y), y, Float64(z - y))) end
code[x_, y_, z_] := N[(N[(x - N[Log[N[Sqrt[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * y + N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x - \log \left(\sqrt{y}\right)\right) - \mathsf{fma}\left(\log y, y, z - y\right)
Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (fma (- -0.5 y) (log y) (- y (- z x))))
double code(double x, double y, double z) {
return fma((-0.5 - y), log(y), (y - (z - x)));
}
function code(x, y, z) return fma(Float64(-0.5 - y), log(y), Float64(y - Float64(z - x))) end
code[x_, y_, z_] := N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(y - N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(-0.5 - y, \log y, y - \left(z - x\right)\right)
Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
(if (<= z -5.6e+42)
(- (- y (* (log y) (+ 0.5 y))) z)
(if (<= z 1.45e+48)
(fma (- -0.5 y) (log y) (+ x y))
(fma (- -0.5 y) (log y) (- x z)))))double code(double x, double y, double z) {
double tmp;
if (z <= -5.6e+42) {
tmp = (y - (log(y) * (0.5 + y))) - z;
} else if (z <= 1.45e+48) {
tmp = fma((-0.5 - y), log(y), (x + y));
} else {
tmp = fma((-0.5 - y), log(y), (x - z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.6e+42) tmp = Float64(Float64(y - Float64(log(y) * Float64(0.5 + y))) - z); elseif (z <= 1.45e+48) tmp = fma(Float64(-0.5 - y), log(y), Float64(x + y)); else tmp = fma(Float64(-0.5 - y), log(y), Float64(x - z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.6e+42], N[(N[(y - N[(N[Log[y], $MachinePrecision] * N[(0.5 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[z, 1.45e+48], N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(x - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{+42}:\\
\;\;\;\;\left(y - \log y \cdot \left(0.5 + y\right)\right) - z\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, x - z\right)\\
\end{array}
if z < -5.5999999999999999e42Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-+.f6471.3
Applied rewrites71.3%
if -5.5999999999999999e42 < z < 1.4499999999999999e48Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in z around 0
lower-+.f6470.5
Applied rewrites70.5%
if 1.4499999999999999e48 < z Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f6479.6
Applied rewrites79.6%
(FPCore (x y z)
:precision binary64
(if (<= z -5.6e+42)
(- (fma (- -0.5 y) (log y) y) z)
(if (<= z 1.45e+48)
(fma (- -0.5 y) (log y) (+ x y))
(fma (- -0.5 y) (log y) (- x z)))))double code(double x, double y, double z) {
double tmp;
if (z <= -5.6e+42) {
tmp = fma((-0.5 - y), log(y), y) - z;
} else if (z <= 1.45e+48) {
tmp = fma((-0.5 - y), log(y), (x + y));
} else {
tmp = fma((-0.5 - y), log(y), (x - z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.6e+42) tmp = Float64(fma(Float64(-0.5 - y), log(y), y) - z); elseif (z <= 1.45e+48) tmp = fma(Float64(-0.5 - y), log(y), Float64(x + y)); else tmp = fma(Float64(-0.5 - y), log(y), Float64(x - z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.6e+42], N[(N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[z, 1.45e+48], N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(x - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, y\right) - z\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, x - z\right)\\
\end{array}
if z < -5.5999999999999999e42Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-+.f6471.3
Applied rewrites71.3%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-+.f64N/A
distribute-neg-outN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6471.3
Applied rewrites71.3%
if -5.5999999999999999e42 < z < 1.4499999999999999e48Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in z around 0
lower-+.f6470.5
Applied rewrites70.5%
if 1.4499999999999999e48 < z Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f6479.6
Applied rewrites79.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma (- -0.5 y) (log y) (- x z))))
(if (<= x -1.1e+36)
t_0
(if (<= x 500000000.0) (- (fma (- -0.5 y) (log y) y) z) t_0))))double code(double x, double y, double z) {
double t_0 = fma((-0.5 - y), log(y), (x - z));
double tmp;
if (x <= -1.1e+36) {
tmp = t_0;
} else if (x <= 500000000.0) {
tmp = fma((-0.5 - y), log(y), y) - z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(-0.5 - y), log(y), Float64(x - z)) tmp = 0.0 if (x <= -1.1e+36) tmp = t_0; elseif (x <= 500000000.0) tmp = Float64(fma(Float64(-0.5 - y), log(y), y) - z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.1e+36], t$95$0, If[LessEqual[x, 500000000.0], N[(N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \mathsf{fma}\left(-0.5 - y, \log y, x - z\right)\\
\mathbf{if}\;x \leq -1.1 \cdot 10^{+36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 500000000:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, y\right) - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -1.1e36 or 5e8 < x Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-fma.f64N/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
metadata-evalN/A
associate-+l-N/A
lower--.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f6479.6
Applied rewrites79.6%
if -1.1e36 < x < 5e8Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-+.f6471.3
Applied rewrites71.3%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-+.f64N/A
distribute-neg-outN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6471.3
Applied rewrites71.3%
(FPCore (x y z) :precision binary64 (if (<= y 2.8e+45) (- (- x (log (sqrt y))) z) (- (fma (- -0.5 y) (log y) y) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.8e+45) {
tmp = (x - log(sqrt(y))) - z;
} else {
tmp = fma((-0.5 - y), log(y), y) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.8e+45) tmp = Float64(Float64(x - log(sqrt(y))) - z); else tmp = Float64(fma(Float64(-0.5 - y), log(y), y) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.8e+45], N[(N[(x - N[Log[N[Sqrt[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{+45}:\\
\;\;\;\;\left(x - \log \left(\sqrt{y}\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, y\right) - z\\
\end{array}
if y < 2.7999999999999999e45Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-sqrt.f6471.3
Applied rewrites71.3%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--r+N/A
lift-log.f64N/A
lift-sqrt.f64N/A
lower--.f64N/A
lift-sqrt.f64N/A
lift-log.f64N/A
lower--.f6471.3
Applied rewrites71.3%
if 2.7999999999999999e45 < y Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-+.f6471.3
Applied rewrites71.3%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-+.f64N/A
distribute-neg-outN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6471.3
Applied rewrites71.3%
(FPCore (x y z) :precision binary64 (if (<= y 2.8e+45) (- (- x (log (sqrt y))) z) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.8e+45) {
tmp = (x - log(sqrt(y))) - z;
} else {
tmp = (1.0 - log(y)) * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 2.8d+45) then
tmp = (x - log(sqrt(y))) - z
else
tmp = (1.0d0 - log(y)) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.8e+45) {
tmp = (x - Math.log(Math.sqrt(y))) - z;
} else {
tmp = (1.0 - Math.log(y)) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.8e+45: tmp = (x - math.log(math.sqrt(y))) - z else: tmp = (1.0 - math.log(y)) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.8e+45) tmp = Float64(Float64(x - log(sqrt(y))) - z); else tmp = Float64(Float64(1.0 - log(y)) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.8e+45) tmp = (x - log(sqrt(y))) - z; else tmp = (1.0 - log(y)) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.8e+45], N[(N[(x - N[Log[N[Sqrt[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{+45}:\\
\;\;\;\;\left(x - \log \left(\sqrt{y}\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\end{array}
if y < 2.7999999999999999e45Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-sqrt.f6471.3
Applied rewrites71.3%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--r+N/A
lift-log.f64N/A
lift-sqrt.f64N/A
lower--.f64N/A
lift-sqrt.f64N/A
lift-log.f64N/A
lower--.f6471.3
Applied rewrites71.3%
if 2.7999999999999999e45 < y Initial program 99.8%
Taylor expanded in y around -inf
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-/.f6430.2
Applied rewrites30.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6430.2
lift-+.f64N/A
lift-log.f64N/A
lift-/.f64N/A
log-recN/A
lift-log.f64N/A
sub-flip-reverseN/A
lower--.f6430.2
Applied rewrites30.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- x (* (+ y 0.5) (log y))) y)))
(if (<= t_0 -2e+47)
(* (- 1.0 (log y)) y)
(if (<= t_0 500.0) (- (- (log (sqrt y))) z) (fma 1.0 x (- y z))))))double code(double x, double y, double z) {
double t_0 = (x - ((y + 0.5) * log(y))) + y;
double tmp;
if (t_0 <= -2e+47) {
tmp = (1.0 - log(y)) * y;
} else if (t_0 <= 500.0) {
tmp = -log(sqrt(y)) - z;
} else {
tmp = fma(1.0, x, (y - 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 <= -2e+47) tmp = Float64(Float64(1.0 - log(y)) * y); elseif (t_0 <= 500.0) tmp = Float64(Float64(-log(sqrt(y))) - z); else tmp = fma(1.0, x, Float64(y - 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, -2e+47], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 500.0], N[((-N[Log[N[Sqrt[y], $MachinePrecision]], $MachinePrecision]) - z), $MachinePrecision], N[(1.0 * x + N[(y - z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left(x - \left(y + 0.5\right) \cdot \log y\right) + y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+47}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 500:\\
\;\;\;\;\left(-\log \left(\sqrt{y}\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y - z\right)\\
\end{array}
if (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -2.0000000000000001e47Initial program 99.8%
Taylor expanded in y around -inf
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-/.f6430.2
Applied rewrites30.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6430.2
lift-+.f64N/A
lift-log.f64N/A
lift-/.f64N/A
log-recN/A
lift-log.f64N/A
sub-flip-reverseN/A
lower--.f6430.2
Applied rewrites30.2%
if -2.0000000000000001e47 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < 500Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-sqrt.f6471.3
Applied rewrites71.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-sqrt.f6443.4
Applied rewrites43.4%
lift-*.f64N/A
mul-1-negN/A
lift-+.f64N/A
add-flipN/A
sub-negateN/A
lower--.f64N/A
lower-neg.f6443.4
Applied rewrites43.4%
if 500 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Applied rewrites87.9%
Taylor expanded in x around inf
Applied rewrites57.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 x (- y z)))) (if (<= z -5.6e+42) t_0 (if (<= z 1.45e+48) (- x (log (sqrt y))) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, x, (y - z));
double tmp;
if (z <= -5.6e+42) {
tmp = t_0;
} else if (z <= 1.45e+48) {
tmp = x - log(sqrt(y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, x, Float64(y - z)) tmp = 0.0 if (z <= -5.6e+42) tmp = t_0; elseif (z <= 1.45e+48) tmp = Float64(x - log(sqrt(y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.6e+42], t$95$0, If[LessEqual[z, 1.45e+48], N[(x - N[Log[N[Sqrt[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, x, y - z\right)\\
\mathbf{if}\;z \leq -5.6 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+48}:\\
\;\;\;\;x - \log \left(\sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if z < -5.5999999999999999e42 or 1.4499999999999999e48 < z Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Applied rewrites87.9%
Taylor expanded in x around inf
Applied rewrites57.4%
if -5.5999999999999999e42 < z < 1.4499999999999999e48Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
lower--.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-sqrt.f6471.3
Applied rewrites71.3%
Taylor expanded in z around 0
lower--.f64N/A
lower-log.f64N/A
lower-sqrt.f6442.7
Applied rewrites42.7%
(FPCore (x y z) :precision binary64 (fma 1.0 x (- y z)))
double code(double x, double y, double z) {
return fma(1.0, x, (y - z));
}
function code(x, y, z) return fma(1.0, x, Float64(y - z)) end
code[x_, y_, z_] := N[(1.0 * x + N[(y - z), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(1, x, y - z\right)
Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
associate-+l-N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate--l+N/A
associate--r+N/A
lower--.f64N/A
Applied rewrites99.9%
Applied rewrites87.9%
Taylor expanded in x around inf
Applied rewrites57.4%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
-z
Initial program 99.8%
Taylor expanded in z around inf
lower-*.f6430.4
Applied rewrites30.4%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6430.4
Applied rewrites30.4%
herbie shell --seed 2025170
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
(- (+ (- x (* (+ y 0.5) (log y))) y) z))