
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\left(x \cdot \log y - z\right) - y
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\left(x \cdot \log y - z\right) - y
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* x (log y)) y)))
(if (<=
x
-159999999999999991009911839590618093052754470856211151454208)
t_0
(if (<= x 4299999999999999775203801256910599399407616)
(- (- z) y)
t_0))))double code(double x, double y, double z) {
double t_0 = (x * log(y)) - y;
double tmp;
if (x <= -1.6e+59) {
tmp = t_0;
} else if (x <= 4.3e+42) {
tmp = -z - y;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * log(y)) - y
if (x <= (-1.6d+59)) then
tmp = t_0
else if (x <= 4.3d+42) then
tmp = -z - y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * Math.log(y)) - y;
double tmp;
if (x <= -1.6e+59) {
tmp = t_0;
} else if (x <= 4.3e+42) {
tmp = -z - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * math.log(y)) - y tmp = 0 if x <= -1.6e+59: tmp = t_0 elif x <= 4.3e+42: tmp = -z - y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * log(y)) - y) tmp = 0.0 if (x <= -1.6e+59) tmp = t_0; elseif (x <= 4.3e+42) tmp = Float64(Float64(-z) - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * log(y)) - y; tmp = 0.0; if (x <= -1.6e+59) tmp = t_0; elseif (x <= 4.3e+42) tmp = -z - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[x, -159999999999999991009911839590618093052754470856211151454208], t$95$0, If[LessEqual[x, 4299999999999999775203801256910599399407616], N[((-z) - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := x \cdot \log y - y\\
\mathbf{if}\;x \leq -159999999999999991009911839590618093052754470856211151454208:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4299999999999999775203801256910599399407616:\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -1.5999999999999999e59 or 4.2999999999999998e42 < x Initial program 99.9%
Taylor expanded in z around 0
lower--.f64N/A
lower-*.f64N/A
lower-log.f6466.9%
Applied rewrites66.9%
if -1.5999999999999999e59 < x < 4.2999999999999998e42Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6467.6%
Applied rewrites67.6%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f64N/A
lower-neg.f64N/A
Applied rewrites58.0%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
+-commutativeN/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f6467.6%
Applied rewrites67.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log y))))
(if (<=
x
-24999999999999999942259256128592700174153136998100959730139215991524396637032419119477983119671296)
t_0
(if (<=
x
320000000000000026459892114273856757645960862884871530762449097882645484617963415339927413251909564694950164560744502027165762138700792726383218469763409607330524469754068992)
(- (- z) y)
t_0))))double code(double x, double y, double z) {
double t_0 = x * log(y);
double tmp;
if (x <= -2.5e+97) {
tmp = t_0;
} else if (x <= 3.2e+173) {
tmp = -z - y;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * log(y)
if (x <= (-2.5d+97)) then
tmp = t_0
else if (x <= 3.2d+173) then
tmp = -z - y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.log(y);
double tmp;
if (x <= -2.5e+97) {
tmp = t_0;
} else if (x <= 3.2e+173) {
tmp = -z - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log(y) tmp = 0 if x <= -2.5e+97: tmp = t_0 elif x <= 3.2e+173: tmp = -z - y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * log(y)) tmp = 0.0 if (x <= -2.5e+97) tmp = t_0; elseif (x <= 3.2e+173) tmp = Float64(Float64(-z) - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * log(y); tmp = 0.0; if (x <= -2.5e+97) tmp = t_0; elseif (x <= 3.2e+173) tmp = -z - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -24999999999999999942259256128592700174153136998100959730139215991524396637032419119477983119671296], t$95$0, If[LessEqual[x, 320000000000000026459892114273856757645960862884871530762449097882645484617963415339927413251909564694950164560744502027165762138700792726383218469763409607330524469754068992], N[((-z) - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := x \cdot \log y\\
\mathbf{if}\;x \leq -24999999999999999942259256128592700174153136998100959730139215991524396637032419119477983119671296:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 320000000000000026459892114273856757645960862884871530762449097882645484617963415339927413251909564694950164560744502027165762138700792726383218469763409607330524469754068992:\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -2.5e97 or 3.2000000000000003e173 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f6479.2%
Applied rewrites79.2%
Taylor expanded in x around inf
lower-log.f6433.6%
Applied rewrites33.6%
if -2.5e97 < x < 3.2000000000000003e173Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6467.6%
Applied rewrites67.6%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f64N/A
lower-neg.f64N/A
Applied rewrites58.0%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
+-commutativeN/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f6467.6%
Applied rewrites67.6%
(FPCore (x y z) :precision binary64 (- (- z) y))
double code(double x, double y, double z) {
return -z - 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 = -z - y
end function
public static double code(double x, double y, double z) {
return -z - y;
}
def code(x, y, z): return -z - y
function code(x, y, z) return Float64(Float64(-z) - y) end
function tmp = code(x, y, z) tmp = -z - y; end
code[x_, y_, z_] := N[((-z) - y), $MachinePrecision]
\left(-z\right) - y
Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6467.6%
Applied rewrites67.6%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f64N/A
lower-neg.f64N/A
Applied rewrites58.0%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
+-commutativeN/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f6467.6%
Applied rewrites67.6%
(FPCore (x y z) :precision binary64 (- y))
double code(double x, double y, double z) {
return -y;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -y
end function
public static double code(double x, double y, double z) {
return -y;
}
def code(x, y, z): return -y
function code(x, y, z) return Float64(-y) end
function tmp = code(x, y, z) tmp = -y; end
code[x_, y_, z_] := (-y)
-y
Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6435.3%
Applied rewrites35.3%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6435.3%
Applied rewrites35.3%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))