
(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);
}
real(8) function code(x, y, z)
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}
Sampling outcomes in binary64 precision:
Herbie found 20 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);
}
real(8) function code(x, y, z)
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
(if (<= x 3.2e-81)
(fma
(- x 0.5)
(log x)
(/
(fma
(fma
(fma z (+ y 0.0007936500793651) -0.0027777777777778)
z
0.083333333333333)
(+ 0.91893853320467 x)
(* (- 0.8444480278083504 (* x x)) x))
(* (+ 0.91893853320467 x) x)))
(-
(fma
(- x 0.5)
(log x)
(fma
(fma (/ y x) z (/ (fma 0.0007936500793651 z -0.0027777777777778) x))
z
(/ 0.083333333333333 x)))
(- x 0.91893853320467))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.2e-81) {
tmp = fma((x - 0.5), log(x), (fma(fma(fma(z, (y + 0.0007936500793651), -0.0027777777777778), z, 0.083333333333333), (0.91893853320467 + x), ((0.8444480278083504 - (x * x)) * x)) / ((0.91893853320467 + x) * x)));
} else {
tmp = fma((x - 0.5), log(x), fma(fma((y / x), z, (fma(0.0007936500793651, z, -0.0027777777777778) / x)), z, (0.083333333333333 / x))) - (x - 0.91893853320467);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= 3.2e-81) tmp = fma(Float64(x - 0.5), log(x), Float64(fma(fma(fma(z, Float64(y + 0.0007936500793651), -0.0027777777777778), z, 0.083333333333333), Float64(0.91893853320467 + x), Float64(Float64(0.8444480278083504 - Float64(x * x)) * x)) / Float64(Float64(0.91893853320467 + x) * x))); else tmp = Float64(fma(Float64(x - 0.5), log(x), fma(fma(Float64(y / x), z, Float64(fma(0.0007936500793651, z, -0.0027777777777778) / x)), z, Float64(0.083333333333333 / x))) - Float64(x - 0.91893853320467)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, 3.2e-81], N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision] + N[(N[(N[(N[(z * N[(y + 0.0007936500793651), $MachinePrecision] + -0.0027777777777778), $MachinePrecision] * z + 0.083333333333333), $MachinePrecision] * N[(0.91893853320467 + x), $MachinePrecision] + N[(N[(0.8444480278083504 - N[(x * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / N[(N[(0.91893853320467 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision] + N[(N[(N[(y / x), $MachinePrecision] * z + N[(N[(0.0007936500793651 * z + -0.0027777777777778), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * z + N[(0.083333333333333 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x - 0.91893853320467), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.2 \cdot 10^{-81}:\\
\;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(z, y + 0.0007936500793651, -0.0027777777777778\right), z, 0.083333333333333\right), 0.91893853320467 + x, \left(0.8444480278083504 - x \cdot x\right) \cdot x\right)}{\left(0.91893853320467 + x\right) \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(\mathsf{fma}\left(\frac{y}{x}, z, \frac{\mathsf{fma}\left(0.0007936500793651, z, -0.0027777777777778\right)}{x}\right), z, \frac{0.083333333333333}{x}\right)\right) - \left(x - 0.91893853320467\right)\\
\end{array}
\end{array}
if x < 3.2e-81Initial program 99.6%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift--.f64N/A
sub-negN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-/.f64N/A
div-invN/A
lift-neg.f64N/A
sub-negN/A
lower-fma.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6499.6
Applied rewrites99.6%
lift-fma.f64N/A
lift-/.f64N/A
un-div-invN/A
lift--.f64N/A
flip--N/A
frac-addN/A
lower-/.f64N/A
Applied rewrites99.7%
if 3.2e-81 < x Initial program 90.5%
Taylor expanded in y around 0
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0
(+
(/
(+
(* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
0.083333333333333)
x)
(+ (- (* (log x) (- x 0.5)) x) 0.91893853320467)))
(t_1 (* (/ z x) z)))
(if (<= t_0 -2e+40)
(* t_1 y)
(if (<= t_0 5e+300)
(/
(fma
(fma 0.0007936500793651 z -0.0027777777777778)
z
0.083333333333333)
x)
(* t_1 0.0007936500793651)))))
double code(double x, double y, double z) {
double t_0 = ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x) + (((log(x) * (x - 0.5)) - x) + 0.91893853320467);
double t_1 = (z / x) * z;
double tmp;
if (t_0 <= -2e+40) {
tmp = t_1 * y;
} else if (t_0 <= 5e+300) {
tmp = fma(fma(0.0007936500793651, z, -0.0027777777777778), z, 0.083333333333333) / x;
} else {
tmp = t_1 * 0.0007936500793651;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(Float64(Float64(Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x) + Float64(Float64(Float64(log(x) * Float64(x - 0.5)) - x) + 0.91893853320467)) t_1 = Float64(Float64(z / x) * z) tmp = 0.0 if (t_0 <= -2e+40) tmp = Float64(t_1 * y); elseif (t_0 <= 5e+300) tmp = Float64(fma(fma(0.0007936500793651, z, -0.0027777777777778), z, 0.083333333333333) / x); else tmp = Float64(t_1 * 0.0007936500793651); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(N[(N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] * z), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision] + N[(N[(N[(N[Log[x], $MachinePrecision] * N[(x - 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z / x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+40], N[(t$95$1 * y), $MachinePrecision], If[LessEqual[t$95$0, 5e+300], N[(N[(N[(0.0007936500793651 * z + -0.0027777777777778), $MachinePrecision] * z + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision], N[(t$95$1 * 0.0007936500793651), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} + \left(\left(\log x \cdot \left(x - 0.5\right) - x\right) + 0.91893853320467\right)\\
t_1 := \frac{z}{x} \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+40}:\\
\;\;\;\;t\_1 \cdot y\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+300}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.0007936500793651, z, -0.0027777777777778\right), z, 0.083333333333333\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot 0.0007936500793651\\
\end{array}
\end{array}
if (+.f64 (+.f64 (-.f64 (*.f64 (-.f64 x #s(literal 1/2 binary64)) (log.f64 x)) x) #s(literal 91893853320467/100000000000000 binary64)) (/.f64 (+.f64 (*.f64 (-.f64 (*.f64 (+.f64 y #s(literal 7936500793651/10000000000000000 binary64)) z) #s(literal 13888888888889/5000000000000000 binary64)) z) #s(literal 83333333333333/1000000000000000 binary64)) x)) < -2.00000000000000006e40Initial program 90.5%
Taylor expanded in y around inf
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6492.7
Applied rewrites92.7%
Applied rewrites94.0%
if -2.00000000000000006e40 < (+.f64 (+.f64 (-.f64 (*.f64 (-.f64 x #s(literal 1/2 binary64)) (log.f64 x)) x) #s(literal 91893853320467/100000000000000 binary64)) (/.f64 (+.f64 (*.f64 (-.f64 (*.f64 (+.f64 y #s(literal 7936500793651/10000000000000000 binary64)) z) #s(literal 13888888888889/5000000000000000 binary64)) z) #s(literal 83333333333333/1000000000000000 binary64)) x)) < 5.00000000000000026e300Initial program 99.4%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
associate-+l+N/A
associate--l+N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-log.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
Applied rewrites95.6%
Taylor expanded in x around 0
Applied rewrites44.8%
if 5.00000000000000026e300 < (+.f64 (+.f64 (-.f64 (*.f64 (-.f64 x #s(literal 1/2 binary64)) (log.f64 x)) x) #s(literal 91893853320467/100000000000000 binary64)) (/.f64 (+.f64 (*.f64 (-.f64 (*.f64 (+.f64 y #s(literal 7936500793651/10000000000000000 binary64)) z) #s(literal 13888888888889/5000000000000000 binary64)) z) #s(literal 83333333333333/1000000000000000 binary64)) x)) Initial program 84.4%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
associate-+l+N/A
associate--l+N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-log.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
Applied rewrites87.3%
Taylor expanded in z around inf
Applied rewrites73.2%
Final simplification59.7%
(FPCore (x y z) :precision binary64 (+ (+ (+ (* (- x 0.5) (log x)) (- 0.91893853320467 x)) (/ 0.083333333333333 x)) (* (/ z x) (- (* z (+ y 0.0007936500793651)) 0.0027777777777778))))
double code(double x, double y, double z) {
return ((((x - 0.5) * log(x)) + (0.91893853320467 - x)) + (0.083333333333333 / x)) + ((z / x) * ((z * (y + 0.0007936500793651)) - 0.0027777777777778));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((((x - 0.5d0) * log(x)) + (0.91893853320467d0 - x)) + (0.083333333333333d0 / x)) + ((z / x) * ((z * (y + 0.0007936500793651d0)) - 0.0027777777777778d0))
end function
public static double code(double x, double y, double z) {
return ((((x - 0.5) * Math.log(x)) + (0.91893853320467 - x)) + (0.083333333333333 / x)) + ((z / x) * ((z * (y + 0.0007936500793651)) - 0.0027777777777778));
}
def code(x, y, z): return ((((x - 0.5) * math.log(x)) + (0.91893853320467 - x)) + (0.083333333333333 / x)) + ((z / x) * ((z * (y + 0.0007936500793651)) - 0.0027777777777778))
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) + Float64(0.91893853320467 - x)) + Float64(0.083333333333333 / x)) + Float64(Float64(z / x) * Float64(Float64(z * Float64(y + 0.0007936500793651)) - 0.0027777777777778))) end
function tmp = code(x, y, z) tmp = ((((x - 0.5) * log(x)) + (0.91893853320467 - x)) + (0.083333333333333 / x)) + ((z / x) * ((z * (y + 0.0007936500793651)) - 0.0027777777777778)); end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] + N[(0.91893853320467 - x), $MachinePrecision]), $MachinePrecision] + N[(0.083333333333333 / x), $MachinePrecision]), $MachinePrecision] + N[(N[(z / x), $MachinePrecision] * N[(N[(z * N[(y + 0.0007936500793651), $MachinePrecision]), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(x - 0.5\right) \cdot \log x + \left(0.91893853320467 - x\right)\right) + \frac{0.083333333333333}{x}\right) + \frac{z}{x} \cdot \left(z \cdot \left(y + 0.0007936500793651\right) - 0.0027777777777778\right)
\end{array}
herbie shell --seed 2024230
(FPCore (x y z)
:name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, B"
:precision binary64
:alt
(! :herbie-platform default (+ (+ (+ (* (- x 1/2) (log x)) (- 91893853320467/100000000000000 x)) (/ 83333333333333/1000000000000000 x)) (* (/ z x) (- (* z (+ y 7936500793651/10000000000000000)) 13888888888889/5000000000000000))))
(+ (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467) (/ (+ (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z) 0.083333333333333) x)))