
(FPCore (x y z)
:precision binary64
(+
(+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
(/
(+
(* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
0.083333333333333)
x)))
double code(double x, double y, double z) {
return ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / 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 - 0.5d0) * log(x)) - x) + 0.91893853320467d0) + ((((((y + 0.0007936500793651d0) * z) - 0.0027777777777778d0) * z) + 0.083333333333333d0) / x)
end function
public static double code(double x, double y, double z) {
return ((((x - 0.5) * Math.log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x);
}
def code(x, y, z): return ((((x - 0.5) * math.log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x)
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) - x) + 0.91893853320467) + Float64(Float64(Float64(Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x)) end
function tmp = code(x, y, z) tmp = ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x); end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision] + N[(N[(N[(N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] * z), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z)
:precision binary64
(+
(+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
(/
(+
(* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
0.083333333333333)
x)))
double code(double x, double y, double z) {
return ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / 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 - 0.5d0) * log(x)) - x) + 0.91893853320467d0) + ((((((y + 0.0007936500793651d0) * z) - 0.0027777777777778d0) * z) + 0.083333333333333d0) / x)
end function
public static double code(double x, double y, double z) {
return ((((x - 0.5) * Math.log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x);
}
def code(x, y, z): return ((((x - 0.5) * math.log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x)
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) - x) + 0.91893853320467) + Float64(Float64(Float64(Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x)) end
function tmp = code(x, y, z) tmp = ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x); end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision] + N[(N[(N[(N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] * z), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 0.0 (log x))))
(if (<= x 2e-30)
(+
(+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
(/
(+
(* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
0.083333333333333)
x))
(+
(*
x
(-
(fma -1.0 t_0 (fma 0.5 (/ t_0 x) (* 0.91893853320467 (pow x -1.0))))
1.0))
(fma
(fma
(fma (pow x -1.0) 0.0007936500793651 (/ y x))
z
(* -0.0027777777777778 (pow x -1.0)))
z
(* (pow x -1.0) 0.083333333333333))))))
double code(double x, double y, double z) {
double t_0 = 0.0 - log(x);
double tmp;
if (x <= 2e-30) {
tmp = ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x);
} else {
tmp = (x * (fma(-1.0, t_0, fma(0.5, (t_0 / x), (0.91893853320467 * pow(x, -1.0)))) - 1.0)) + fma(fma(fma(pow(x, -1.0), 0.0007936500793651, (y / x)), z, (-0.0027777777777778 * pow(x, -1.0))), z, (pow(x, -1.0) * 0.083333333333333));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(0.0 - log(x)) tmp = 0.0 if (x <= 2e-30) tmp = Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) - x) + 0.91893853320467) + Float64(Float64(Float64(Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x)); else tmp = Float64(Float64(x * Float64(fma(-1.0, t_0, fma(0.5, Float64(t_0 / x), Float64(0.91893853320467 * (x ^ -1.0)))) - 1.0)) + fma(fma(fma((x ^ -1.0), 0.0007936500793651, Float64(y / x)), z, Float64(-0.0027777777777778 * (x ^ -1.0))), z, Float64((x ^ -1.0) * 0.083333333333333))); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.0 - N[Log[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e-30], N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision] + N[(N[(N[(N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] * z), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(N[(-1.0 * t$95$0 + N[(0.5 * N[(t$95$0 / x), $MachinePrecision] + N[(0.91893853320467 * N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] * 0.0007936500793651 + N[(y / x), $MachinePrecision]), $MachinePrecision] * z + N[(-0.0027777777777778 * N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + N[(N[Power[x, -1.0], $MachinePrecision] * 0.083333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0 - \log x\\
\mathbf{if}\;x \leq 2 \cdot 10^{-30}:\\
\;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(-1, t\_0, \mathsf{fma}\left(0.5, \frac{t\_0}{x}, 0.91893853320467 \cdot {x}^{-1}\right)\right) - 1\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left({x}^{-1}, 0.0007936500793651, \frac{y}{x}\right), z, -0.0027777777777778 \cdot {x}^{-1}\right), z, {x}^{-1} \cdot 0.083333333333333\right)\\
\end{array}
\end{array}
if x < 2e-30Initial program 99.7%
if 2e-30 < x Initial program 90.2%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
Applied rewrites99.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 0.0 (log x))))
(+
(*
x
(-
(fma -1.0 t_0 (fma 0.5 (/ t_0 x) (* 0.91893853320467 (pow x -1.0))))
1.0))
(fma
(fma
(fma (pow x -1.0) 0.0007936500793651 (/ y x))
z
(* -0.0027777777777778 (pow x -1.0)))
z
(* (pow x -1.0) 0.083333333333333)))))
double code(double x, double y, double z) {
double t_0 = 0.0 - log(x);
return (x * (fma(-1.0, t_0, fma(0.5, (t_0 / x), (0.91893853320467 * pow(x, -1.0)))) - 1.0)) + fma(fma(fma(pow(x, -1.0), 0.0007936500793651, (y / x)), z, (-0.0027777777777778 * pow(x, -1.0))), z, (pow(x, -1.0) * 0.083333333333333));
}
function code(x, y, z) t_0 = Float64(0.0 - log(x)) return Float64(Float64(x * Float64(fma(-1.0, t_0, fma(0.5, Float64(t_0 / x), Float64(0.91893853320467 * (x ^ -1.0)))) - 1.0)) + fma(fma(fma((x ^ -1.0), 0.0007936500793651, Float64(y / x)), z, Float64(-0.0027777777777778 * (x ^ -1.0))), z, Float64((x ^ -1.0) * 0.083333333333333))) end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.0 - N[Log[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(x * N[(N[(-1.0 * t$95$0 + N[(0.5 * N[(t$95$0 / x), $MachinePrecision] + N[(0.91893853320467 * N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] * 0.0007936500793651 + N[(y / x), $MachinePrecision]), $MachinePrecision] * z + N[(-0.0027777777777778 * N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + N[(N[Power[x, -1.0], $MachinePrecision] * 0.083333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0 - \log x\\
x \cdot \left(\mathsf{fma}\left(-1, t\_0, \mathsf{fma}\left(0.5, \frac{t\_0}{x}, 0.91893853320467 \cdot {x}^{-1}\right)\right) - 1\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left({x}^{-1}, 0.0007936500793651, \frac{y}{x}\right), z, -0.0027777777777778 \cdot {x}^{-1}\right), z, {x}^{-1} \cdot 0.083333333333333\right)
\end{array}
\end{array}
Initial program 94.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites94.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
Applied rewrites94.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* -1.0 (log x))))
(if (<= x 1.52e+78)
(*
(/
(fma
0.083333333333333
(pow y -1.0)
(fma
x
(fma
-0.5
(/ (log x) y)
(fma 0.91893853320467 (pow y -1.0) (* x (/ (- (log x) 1.0) y))))
(+
(/ (* z (- (* 0.0007936500793651 z) 0.0027777777777778)) y)
(* z z))))
x)
y)
(*
(-
(fma t_0 -1.0 (fma (/ t_0 x) 0.5 (* (pow x -1.0) 0.91893853320467)))
1.0)
x))))
double code(double x, double y, double z) {
double t_0 = -1.0 * log(x);
double tmp;
if (x <= 1.52e+78) {
tmp = (fma(0.083333333333333, pow(y, -1.0), fma(x, fma(-0.5, (log(x) / y), fma(0.91893853320467, pow(y, -1.0), (x * ((log(x) - 1.0) / y)))), (((z * ((0.0007936500793651 * z) - 0.0027777777777778)) / y) + (z * z)))) / x) * y;
} else {
tmp = (fma(t_0, -1.0, fma((t_0 / x), 0.5, (pow(x, -1.0) * 0.91893853320467))) - 1.0) * x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-1.0 * log(x)) tmp = 0.0 if (x <= 1.52e+78) tmp = Float64(Float64(fma(0.083333333333333, (y ^ -1.0), fma(x, fma(-0.5, Float64(log(x) / y), fma(0.91893853320467, (y ^ -1.0), Float64(x * Float64(Float64(log(x) - 1.0) / y)))), Float64(Float64(Float64(z * Float64(Float64(0.0007936500793651 * z) - 0.0027777777777778)) / y) + Float64(z * z)))) / x) * y); else tmp = Float64(Float64(fma(t_0, -1.0, fma(Float64(t_0 / x), 0.5, Float64((x ^ -1.0) * 0.91893853320467))) - 1.0) * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(-1.0 * N[Log[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.52e+78], N[(N[(N[(0.083333333333333 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(-0.5 * N[(N[Log[x], $MachinePrecision] / y), $MachinePrecision] + N[(0.91893853320467 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(N[(N[Log[x], $MachinePrecision] - 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(z * N[(N[(0.0007936500793651 * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * y), $MachinePrecision], N[(N[(N[(t$95$0 * -1.0 + N[(N[(t$95$0 / x), $MachinePrecision] * 0.5 + N[(N[Power[x, -1.0], $MachinePrecision] * 0.91893853320467), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 \cdot \log x\\
\mathbf{if}\;x \leq 1.52 \cdot 10^{+78}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.083333333333333, {y}^{-1}, \mathsf{fma}\left(x, \mathsf{fma}\left(-0.5, \frac{\log x}{y}, \mathsf{fma}\left(0.91893853320467, {y}^{-1}, x \cdot \frac{\log x - 1}{y}\right)\right), \frac{z \cdot \left(0.0007936500793651 \cdot z - 0.0027777777777778\right)}{y} + z \cdot z\right)\right)}{x} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(t\_0, -1, \mathsf{fma}\left(\frac{t\_0}{x}, 0.5, {x}^{-1} \cdot 0.91893853320467\right)\right) - 1\right) \cdot x\\
\end{array}
\end{array}
if x < 1.52e78Initial program 99.1%
Taylor expanded in y around inf
Applied rewrites73.0%
Taylor expanded in x around 0
lower-/.f64N/A
Applied rewrites73.8%
if 1.52e78 < x Initial program 86.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites76.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* (pow x -1.0) 0.083333333333333) y))
(t_1 (pow (* x y) -1.0))
(t_2
(*
(-
(+
(*
(* z z)
(fma
-1.0
(/
(fma
-1.0
(/
(fma
0.91893853320467
(pow y -1.0)
(/ (* (log x) (- x 0.5)) y))
z)
(* 0.0027777777777778 t_1))
z)
(fma 0.0007936500793651 t_1 (pow x -1.0))))
t_0)
(/ x y))
y)))
(if (<= z -4.2e-52)
t_2
(if (<= z 7.4e+151)
(*
(-
(+
(fma
(pow y -1.0)
0.91893853320467
(fma
(/ z x)
(/ (- (* z 0.0007936500793651) 0.0027777777777778) y)
(fma (log x) (/ (- x 0.5) y) (/ (* z z) x))))
t_0)
(/ x y))
y)
t_2))))
double code(double x, double y, double z) {
double t_0 = (pow(x, -1.0) * 0.083333333333333) / y;
double t_1 = pow((x * y), -1.0);
double t_2 = ((((z * z) * fma(-1.0, (fma(-1.0, (fma(0.91893853320467, pow(y, -1.0), ((log(x) * (x - 0.5)) / y)) / z), (0.0027777777777778 * t_1)) / z), fma(0.0007936500793651, t_1, pow(x, -1.0)))) + t_0) - (x / y)) * y;
double tmp;
if (z <= -4.2e-52) {
tmp = t_2;
} else if (z <= 7.4e+151) {
tmp = ((fma(pow(y, -1.0), 0.91893853320467, fma((z / x), (((z * 0.0007936500793651) - 0.0027777777777778) / y), fma(log(x), ((x - 0.5) / y), ((z * z) / x)))) + t_0) - (x / y)) * y;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64((x ^ -1.0) * 0.083333333333333) / y) t_1 = Float64(x * y) ^ -1.0 t_2 = Float64(Float64(Float64(Float64(Float64(z * z) * fma(-1.0, Float64(fma(-1.0, Float64(fma(0.91893853320467, (y ^ -1.0), Float64(Float64(log(x) * Float64(x - 0.5)) / y)) / z), Float64(0.0027777777777778 * t_1)) / z), fma(0.0007936500793651, t_1, (x ^ -1.0)))) + t_0) - Float64(x / y)) * y) tmp = 0.0 if (z <= -4.2e-52) tmp = t_2; elseif (z <= 7.4e+151) tmp = Float64(Float64(Float64(fma((y ^ -1.0), 0.91893853320467, fma(Float64(z / x), Float64(Float64(Float64(z * 0.0007936500793651) - 0.0027777777777778) / y), fma(log(x), Float64(Float64(x - 0.5) / y), Float64(Float64(z * z) / x)))) + t_0) - Float64(x / y)) * y); else tmp = t_2; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[Power[x, -1.0], $MachinePrecision] * 0.083333333333333), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(x * y), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[(z * z), $MachinePrecision] * N[(-1.0 * N[(N[(-1.0 * N[(N[(0.91893853320467 * N[Power[y, -1.0], $MachinePrecision] + N[(N[(N[Log[x], $MachinePrecision] * N[(x - 0.5), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + N[(0.0027777777777778 * t$95$1), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + N[(0.0007936500793651 * t$95$1 + N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[z, -4.2e-52], t$95$2, If[LessEqual[z, 7.4e+151], N[(N[(N[(N[(N[Power[y, -1.0], $MachinePrecision] * 0.91893853320467 + N[(N[(z / x), $MachinePrecision] * N[(N[(N[(z * 0.0007936500793651), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] / y), $MachinePrecision] + N[(N[Log[x], $MachinePrecision] * N[(N[(x - 0.5), $MachinePrecision] / y), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{x}^{-1} \cdot 0.083333333333333}{y}\\
t_1 := {\left(x \cdot y\right)}^{-1}\\
t_2 := \left(\left(\left(z \cdot z\right) \cdot \mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(0.91893853320467, {y}^{-1}, \frac{\log x \cdot \left(x - 0.5\right)}{y}\right)}{z}, 0.0027777777777778 \cdot t\_1\right)}{z}, \mathsf{fma}\left(0.0007936500793651, t\_1, {x}^{-1}\right)\right) + t\_0\right) - \frac{x}{y}\right) \cdot y\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{-52}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;z \leq 7.4 \cdot 10^{+151}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left({y}^{-1}, 0.91893853320467, \mathsf{fma}\left(\frac{z}{x}, \frac{z \cdot 0.0007936500793651 - 0.0027777777777778}{y}, \mathsf{fma}\left(\log x, \frac{x - 0.5}{y}, \frac{z \cdot z}{x}\right)\right)\right) + t\_0\right) - \frac{x}{y}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if z < -4.1999999999999997e-52 or 7.3999999999999995e151 < z Initial program 89.8%
Taylor expanded in y around inf
Applied rewrites61.0%
Taylor expanded in z around -inf
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
Applied rewrites74.8%
if -4.1999999999999997e-52 < z < 7.3999999999999995e151Initial program 97.6%
Taylor expanded in y around inf
Applied rewrites74.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (pow (* x y) -1.0))
(t_1
(*
(-
(+
(*
(* z z)
(fma
-1.0
(/
(fma
-1.0
(/
(fma
0.91893853320467
(pow y -1.0)
(/ (* (log x) (- x 0.5)) y))
z)
(* 0.0027777777777778 t_0))
z)
(fma 0.0007936500793651 t_0 (pow x -1.0))))
(/ (* (pow x -1.0) 0.083333333333333) y))
(/ x y))
y)))
(if (<= z -3.6e-93)
t_1
(if (<= z 7.1e+162)
(*
(/
(fma
0.083333333333333
(pow y -1.0)
(fma
x
(fma
-0.5
(/ (log x) y)
(fma 0.91893853320467 (pow y -1.0) (* x (/ (- (log x) 1.0) y))))
(+
(/ (* z (- (* 0.0007936500793651 z) 0.0027777777777778)) y)
(* z z))))
x)
y)
t_1))))
double code(double x, double y, double z) {
double t_0 = pow((x * y), -1.0);
double t_1 = ((((z * z) * fma(-1.0, (fma(-1.0, (fma(0.91893853320467, pow(y, -1.0), ((log(x) * (x - 0.5)) / y)) / z), (0.0027777777777778 * t_0)) / z), fma(0.0007936500793651, t_0, pow(x, -1.0)))) + ((pow(x, -1.0) * 0.083333333333333) / y)) - (x / y)) * y;
double tmp;
if (z <= -3.6e-93) {
tmp = t_1;
} else if (z <= 7.1e+162) {
tmp = (fma(0.083333333333333, pow(y, -1.0), fma(x, fma(-0.5, (log(x) / y), fma(0.91893853320467, pow(y, -1.0), (x * ((log(x) - 1.0) / y)))), (((z * ((0.0007936500793651 * z) - 0.0027777777777778)) / y) + (z * z)))) / x) * y;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * y) ^ -1.0 t_1 = Float64(Float64(Float64(Float64(Float64(z * z) * fma(-1.0, Float64(fma(-1.0, Float64(fma(0.91893853320467, (y ^ -1.0), Float64(Float64(log(x) * Float64(x - 0.5)) / y)) / z), Float64(0.0027777777777778 * t_0)) / z), fma(0.0007936500793651, t_0, (x ^ -1.0)))) + Float64(Float64((x ^ -1.0) * 0.083333333333333) / y)) - Float64(x / y)) * y) tmp = 0.0 if (z <= -3.6e-93) tmp = t_1; elseif (z <= 7.1e+162) tmp = Float64(Float64(fma(0.083333333333333, (y ^ -1.0), fma(x, fma(-0.5, Float64(log(x) / y), fma(0.91893853320467, (y ^ -1.0), Float64(x * Float64(Float64(log(x) - 1.0) / y)))), Float64(Float64(Float64(z * Float64(Float64(0.0007936500793651 * z) - 0.0027777777777778)) / y) + Float64(z * z)))) / x) * y); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Power[N[(x * y), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(N[(z * z), $MachinePrecision] * N[(-1.0 * N[(N[(-1.0 * N[(N[(0.91893853320467 * N[Power[y, -1.0], $MachinePrecision] + N[(N[(N[Log[x], $MachinePrecision] * N[(x - 0.5), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + N[(0.0027777777777778 * t$95$0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + N[(0.0007936500793651 * t$95$0 + N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, -1.0], $MachinePrecision] * 0.083333333333333), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[z, -3.6e-93], t$95$1, If[LessEqual[z, 7.1e+162], N[(N[(N[(0.083333333333333 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(-0.5 * N[(N[Log[x], $MachinePrecision] / y), $MachinePrecision] + N[(0.91893853320467 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(N[(N[Log[x], $MachinePrecision] - 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(z * N[(N[(0.0007936500793651 * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x \cdot y\right)}^{-1}\\
t_1 := \left(\left(\left(z \cdot z\right) \cdot \mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(0.91893853320467, {y}^{-1}, \frac{\log x \cdot \left(x - 0.5\right)}{y}\right)}{z}, 0.0027777777777778 \cdot t\_0\right)}{z}, \mathsf{fma}\left(0.0007936500793651, t\_0, {x}^{-1}\right)\right) + \frac{{x}^{-1} \cdot 0.083333333333333}{y}\right) - \frac{x}{y}\right) \cdot y\\
\mathbf{if}\;z \leq -3.6 \cdot 10^{-93}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 7.1 \cdot 10^{+162}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.083333333333333, {y}^{-1}, \mathsf{fma}\left(x, \mathsf{fma}\left(-0.5, \frac{\log x}{y}, \mathsf{fma}\left(0.91893853320467, {y}^{-1}, x \cdot \frac{\log x - 1}{y}\right)\right), \frac{z \cdot \left(0.0007936500793651 \cdot z - 0.0027777777777778\right)}{y} + z \cdot z\right)\right)}{x} \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.6000000000000002e-93 or 7.0999999999999997e162 < z Initial program 90.9%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in z around -inf
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
Applied rewrites73.8%
if -3.6000000000000002e-93 < z < 7.0999999999999997e162Initial program 97.2%
Taylor expanded in y around inf
Applied rewrites73.8%
Taylor expanded in x around 0
lower-/.f64N/A
Applied rewrites65.1%
(FPCore (x y z)
:precision binary64
(*
(/
(fma
0.083333333333333
(pow y -1.0)
(fma
x
(fma
-0.5
(/ (log x) y)
(fma 0.91893853320467 (pow y -1.0) (* x (/ (- (log x) 1.0) y))))
(+ (/ (* z (- (* 0.0007936500793651 z) 0.0027777777777778)) y) (* z z))))
x)
y))
double code(double x, double y, double z) {
return (fma(0.083333333333333, pow(y, -1.0), fma(x, fma(-0.5, (log(x) / y), fma(0.91893853320467, pow(y, -1.0), (x * ((log(x) - 1.0) / y)))), (((z * ((0.0007936500793651 * z) - 0.0027777777777778)) / y) + (z * z)))) / x) * y;
}
function code(x, y, z) return Float64(Float64(fma(0.083333333333333, (y ^ -1.0), fma(x, fma(-0.5, Float64(log(x) / y), fma(0.91893853320467, (y ^ -1.0), Float64(x * Float64(Float64(log(x) - 1.0) / y)))), Float64(Float64(Float64(z * Float64(Float64(0.0007936500793651 * z) - 0.0027777777777778)) / y) + Float64(z * z)))) / x) * y) end
code[x_, y_, z_] := N[(N[(N[(0.083333333333333 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(-0.5 * N[(N[Log[x], $MachinePrecision] / y), $MachinePrecision] + N[(0.91893853320467 * N[Power[y, -1.0], $MachinePrecision] + N[(x * N[(N[(N[Log[x], $MachinePrecision] - 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(z * N[(N[(0.0007936500793651 * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(0.083333333333333, {y}^{-1}, \mathsf{fma}\left(x, \mathsf{fma}\left(-0.5, \frac{\log x}{y}, \mathsf{fma}\left(0.91893853320467, {y}^{-1}, x \cdot \frac{\log x - 1}{y}\right)\right), \frac{z \cdot \left(0.0007936500793651 \cdot z - 0.0027777777777778\right)}{y} + z \cdot z\right)\right)}{x} \cdot y
\end{array}
Initial program 94.4%
Taylor expanded in y around inf
Applied rewrites68.8%
Taylor expanded in x around 0
lower-/.f64N/A
Applied rewrites60.7%
herbie shell --seed 2025093
(FPCore (x y z)
:name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, B"
:precision binary64
(+ (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467) (/ (+ (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z) 0.083333333333333) x)))