
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
return (x * log((x / 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 * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
return (x * Math.log((x / y))) - z;
}
def code(x, y, z): return (x * math.log((x / y))) - z
function code(x, y, z) return Float64(Float64(x * log(Float64(x / y))) - z) end
function tmp = code(x, y, z) tmp = (x * log((x / y))) - z; end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
return (x * log((x / 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 * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
return (x * Math.log((x / y))) - z;
}
def code(x, y, z): return (x * math.log((x / y))) - z
function code(x, y, z) return Float64(Float64(x * log(Float64(x / y))) - z) end
function tmp = code(x, y, z) tmp = (x * log((x / y))) - z; end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= x -2.8e-177)
(- (* x (log (* (pow y -1.0) x))) z)
(if (<= x -2e-308)
(* -1.0 z)
(- (fma (* (log y) -1.0) x (* (log x) x)) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e-177) {
tmp = (x * log((pow(y, -1.0) * x))) - z;
} else if (x <= -2e-308) {
tmp = -1.0 * z;
} else {
tmp = fma((log(y) * -1.0), x, (log(x) * x)) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.8e-177) tmp = Float64(Float64(x * log(Float64((y ^ -1.0) * x))) - z); elseif (x <= -2e-308) tmp = Float64(-1.0 * z); else tmp = Float64(fma(Float64(log(y) * -1.0), x, Float64(log(x) * x)) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.8e-177], N[(N[(x * N[Log[N[(N[Power[y, -1.0], $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, -2e-308], N[(-1.0 * z), $MachinePrecision], N[(N[(N[(N[Log[y], $MachinePrecision] * -1.0), $MachinePrecision] * x + N[(N[Log[x], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-177}:\\
\;\;\;\;x \cdot \log \left({y}^{-1} \cdot x\right) - z\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-308}:\\
\;\;\;\;-1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y \cdot -1, x, \log x \cdot x\right) - z\\
\end{array}
\end{array}
if x < -2.79999999999999987e-177Initial program 81.5%
lift-/.f64N/A
frac-2negN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
frac-2negN/A
*-commutativeN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6481.5
Applied rewrites81.5%
if -2.79999999999999987e-177 < x < -1.9999999999999998e-308Initial program 64.6%
Taylor expanded in x around 0
lower-*.f6488.4
Applied rewrites88.4%
if -1.9999999999999998e-308 < x Initial program 77.4%
Applied rewrites99.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (log x) x))
(t_1 (- (* x (log (/ x y))) z))
(t_2 (* x (log y))))
(if (<= t_1 (- INFINITY))
(- (/ (- (pow t_0 2.0) (* t_2 t_2)) (- t_0 (* t_2 -1.0))) z)
(if (<= t_1 1e+302) (- (* x (log (* (pow y -1.0) x))) z) (* -1.0 z)))))
double code(double x, double y, double z) {
double t_0 = log(x) * x;
double t_1 = (x * log((x / y))) - z;
double t_2 = x * log(y);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = ((pow(t_0, 2.0) - (t_2 * t_2)) / (t_0 - (t_2 * -1.0))) - z;
} else if (t_1 <= 1e+302) {
tmp = (x * log((pow(y, -1.0) * x))) - z;
} else {
tmp = -1.0 * z;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = Math.log(x) * x;
double t_1 = (x * Math.log((x / y))) - z;
double t_2 = x * Math.log(y);
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = ((Math.pow(t_0, 2.0) - (t_2 * t_2)) / (t_0 - (t_2 * -1.0))) - z;
} else if (t_1 <= 1e+302) {
tmp = (x * Math.log((Math.pow(y, -1.0) * x))) - z;
} else {
tmp = -1.0 * z;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(x) * x t_1 = (x * math.log((x / y))) - z t_2 = x * math.log(y) tmp = 0 if t_1 <= -math.inf: tmp = ((math.pow(t_0, 2.0) - (t_2 * t_2)) / (t_0 - (t_2 * -1.0))) - z elif t_1 <= 1e+302: tmp = (x * math.log((math.pow(y, -1.0) * x))) - z else: tmp = -1.0 * z return tmp
function code(x, y, z) t_0 = Float64(log(x) * x) t_1 = Float64(Float64(x * log(Float64(x / y))) - z) t_2 = Float64(x * log(y)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64((t_0 ^ 2.0) - Float64(t_2 * t_2)) / Float64(t_0 - Float64(t_2 * -1.0))) - z); elseif (t_1 <= 1e+302) tmp = Float64(Float64(x * log(Float64((y ^ -1.0) * x))) - z); else tmp = Float64(-1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(x) * x; t_1 = (x * log((x / y))) - z; t_2 = x * log(y); tmp = 0.0; if (t_1 <= -Inf) tmp = (((t_0 ^ 2.0) - (t_2 * t_2)) / (t_0 - (t_2 * -1.0))) - z; elseif (t_1 <= 1e+302) tmp = (x * log(((y ^ -1.0) * x))) - z; else tmp = -1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[x], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$2 = N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(t$95$2 * -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[t$95$1, 1e+302], N[(N[(x * N[Log[N[(N[Power[y, -1.0], $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(-1.0 * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log x \cdot x\\
t_1 := x \cdot \log \left(\frac{x}{y}\right) - z\\
t_2 := x \cdot \log y\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\frac{{t\_0}^{2} - t\_2 \cdot t\_2}{t\_0 - t\_2 \cdot -1} - z\\
\mathbf{elif}\;t\_1 \leq 10^{+302}:\\
\;\;\;\;x \cdot \log \left({y}^{-1} \cdot x\right) - z\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot z\\
\end{array}
\end{array}
if (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < -inf.0Initial program 6.3%
Applied rewrites42.4%
if -inf.0 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < 1.0000000000000001e302Initial program 99.7%
lift-/.f64N/A
frac-2negN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
frac-2negN/A
*-commutativeN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
if 1.0000000000000001e302 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) Initial program 10.4%
Taylor expanded in x around 0
lower-*.f6447.6
Applied rewrites47.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* x (log (/ x y))) z)))
(if (<= t_0 (- INFINITY))
(* -1.0 z)
(if (<= t_0 1e+302) (- (* x (log (* (pow y -1.0) x))) z) (* -1.0 z)))))
double code(double x, double y, double z) {
double t_0 = (x * log((x / y))) - z;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = -1.0 * z;
} else if (t_0 <= 1e+302) {
tmp = (x * log((pow(y, -1.0) * x))) - z;
} else {
tmp = -1.0 * z;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x * Math.log((x / y))) - z;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = -1.0 * z;
} else if (t_0 <= 1e+302) {
tmp = (x * Math.log((Math.pow(y, -1.0) * x))) - z;
} else {
tmp = -1.0 * z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * math.log((x / y))) - z tmp = 0 if t_0 <= -math.inf: tmp = -1.0 * z elif t_0 <= 1e+302: tmp = (x * math.log((math.pow(y, -1.0) * x))) - z else: tmp = -1.0 * z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * log(Float64(x / y))) - z) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(-1.0 * z); elseif (t_0 <= 1e+302) tmp = Float64(Float64(x * log(Float64((y ^ -1.0) * x))) - z); else tmp = Float64(-1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * log((x / y))) - z; tmp = 0.0; if (t_0 <= -Inf) tmp = -1.0 * z; elseif (t_0 <= 1e+302) tmp = (x * log(((y ^ -1.0) * x))) - z; else tmp = -1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(-1.0 * z), $MachinePrecision], If[LessEqual[t$95$0, 1e+302], N[(N[(x * N[Log[N[(N[Power[y, -1.0], $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(-1.0 * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right) - z\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;-1 \cdot z\\
\mathbf{elif}\;t\_0 \leq 10^{+302}:\\
\;\;\;\;x \cdot \log \left({y}^{-1} \cdot x\right) - z\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot z\\
\end{array}
\end{array}
if (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < -inf.0 or 1.0000000000000001e302 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) Initial program 8.4%
Taylor expanded in x around 0
lower-*.f6447.3
Applied rewrites47.3%
if -inf.0 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < 1.0000000000000001e302Initial program 99.7%
lift-/.f64N/A
frac-2negN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
frac-2negN/A
*-commutativeN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
(FPCore (x y z) :precision binary64 (* -1.0 z))
double code(double x, double y, double z) {
return -1.0 * 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 = (-1.0d0) * z
end function
public static double code(double x, double y, double z) {
return -1.0 * z;
}
def code(x, y, z): return -1.0 * z
function code(x, y, z) return Float64(-1.0 * z) end
function tmp = code(x, y, z) tmp = -1.0 * z; end
code[x_, y_, z_] := N[(-1.0 * z), $MachinePrecision]
\begin{array}{l}
\\
-1 \cdot z
\end{array}
Initial program 77.7%
Taylor expanded in x around 0
lower-*.f6450.5
Applied rewrites50.5%
herbie shell --seed 2025093
(FPCore (x y z)
:name "Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2"
:precision binary64
(- (* x (log (/ x y))) z))