
(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;
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 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;
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
(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;
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* (+ y 0.5) (log y)))) (t_1 (- t_0 z))) (if (<= z -9.5e+88) t_1 (if (<= z 6e+64) (+ t_0 y) t_1))))
double code(double x, double y, double z) {
double t_0 = x - ((y + 0.5) * log(y));
double t_1 = t_0 - z;
double tmp;
if (z <= -9.5e+88) {
tmp = t_1;
} else if (z <= 6e+64) {
tmp = t_0 + y;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x - ((y + 0.5d0) * log(y))
t_1 = t_0 - z
if (z <= (-9.5d+88)) then
tmp = t_1
else if (z <= 6d+64) then
tmp = t_0 + y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - ((y + 0.5) * Math.log(y));
double t_1 = t_0 - z;
double tmp;
if (z <= -9.5e+88) {
tmp = t_1;
} else if (z <= 6e+64) {
tmp = t_0 + y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x - ((y + 0.5) * math.log(y)) t_1 = t_0 - z tmp = 0 if z <= -9.5e+88: tmp = t_1 elif z <= 6e+64: tmp = t_0 + y else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(Float64(y + 0.5) * log(y))) t_1 = Float64(t_0 - z) tmp = 0.0 if (z <= -9.5e+88) tmp = t_1; elseif (z <= 6e+64) tmp = Float64(t_0 + y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - ((y + 0.5) * log(y)); t_1 = t_0 - z; tmp = 0.0; if (z <= -9.5e+88) tmp = t_1; elseif (z <= 6e+64) tmp = t_0 + y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - z), $MachinePrecision]}, If[LessEqual[z, -9.5e+88], t$95$1, If[LessEqual[z, 6e+64], N[(t$95$0 + y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \left(y + 0.5\right) \cdot \log y\\
t_1 := t\_0 - z\\
\mathbf{if}\;z \leq -9.5 \cdot 10^{+88}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+64}:\\
\;\;\;\;t\_0 + y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -9.50000000000000059e88 or 6.0000000000000004e64 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites90.4%
if -9.50000000000000059e88 < z < 6.0000000000000004e64Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (log y) z)))
(if (<= z -1.22e+118)
t_0
(if (<= z 1.65e+125) (+ (- x (* (+ y 0.5) (log y))) y) t_0))))
double code(double x, double y, double z) {
double t_0 = log(y) - z;
double tmp;
if (z <= -1.22e+118) {
tmp = t_0;
} else if (z <= 1.65e+125) {
tmp = (x - ((y + 0.5) * log(y))) + y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = log(y) - z
if (z <= (-1.22d+118)) then
tmp = t_0
else if (z <= 1.65d+125) then
tmp = (x - ((y + 0.5d0) * log(y))) + y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.log(y) - z;
double tmp;
if (z <= -1.22e+118) {
tmp = t_0;
} else if (z <= 1.65e+125) {
tmp = (x - ((y + 0.5) * Math.log(y))) + y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(y) - z tmp = 0 if z <= -1.22e+118: tmp = t_0 elif z <= 1.65e+125: tmp = (x - ((y + 0.5) * math.log(y))) + y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(log(y) - z) tmp = 0.0 if (z <= -1.22e+118) tmp = t_0; elseif (z <= 1.65e+125) tmp = Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(y) - z; tmp = 0.0; if (z <= -1.22e+118) tmp = t_0; elseif (z <= 1.65e+125) tmp = (x - ((y + 0.5) * log(y))) + y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[y], $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[z, -1.22e+118], t$95$0, If[LessEqual[z, 1.65e+125], N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log y - z\\
\mathbf{if}\;z \leq -1.22 \cdot 10^{+118}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+125}:\\
\;\;\;\;\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.2200000000000001e118 or 1.65000000000000003e125 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites92.5%
Taylor expanded in x around -inf
Applied rewrites77.6%
if -1.2200000000000001e118 < z < 1.65000000000000003e125Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites94.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (log y) z)))
(if (<= z -5.2e+109)
t_0
(if (<= z 1.1e+125) (- x (* (+ y 0.5) (log y))) t_0))))
double code(double x, double y, double z) {
double t_0 = log(y) - z;
double tmp;
if (z <= -5.2e+109) {
tmp = t_0;
} else if (z <= 1.1e+125) {
tmp = x - ((y + 0.5) * log(y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = log(y) - z
if (z <= (-5.2d+109)) then
tmp = t_0
else if (z <= 1.1d+125) then
tmp = x - ((y + 0.5d0) * log(y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.log(y) - z;
double tmp;
if (z <= -5.2e+109) {
tmp = t_0;
} else if (z <= 1.1e+125) {
tmp = x - ((y + 0.5) * Math.log(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(y) - z tmp = 0 if z <= -5.2e+109: tmp = t_0 elif z <= 1.1e+125: tmp = x - ((y + 0.5) * math.log(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(log(y) - z) tmp = 0.0 if (z <= -5.2e+109) tmp = t_0; elseif (z <= 1.1e+125) tmp = Float64(x - Float64(Float64(y + 0.5) * log(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(y) - z; tmp = 0.0; if (z <= -5.2e+109) tmp = t_0; elseif (z <= 1.1e+125) tmp = x - ((y + 0.5) * log(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[y], $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[z, -5.2e+109], t$95$0, If[LessEqual[z, 1.1e+125], N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log y - z\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{+109}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+125}:\\
\;\;\;\;x - \left(y + 0.5\right) \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.1999999999999997e109 or 1.09999999999999995e125 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites91.9%
Taylor expanded in x around -inf
Applied rewrites76.9%
if -5.1999999999999997e109 < z < 1.09999999999999995e125Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites95.0%
Taylor expanded in x around 0
Applied rewrites70.9%
(FPCore (x y z) :precision binary64 (- (log y) z))
double code(double x, double y, double z) {
return log(y) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = log(y) - z
end function
public static double code(double x, double y, double z) {
return Math.log(y) - z;
}
def code(x, y, z): return math.log(y) - z
function code(x, y, z) return Float64(log(y) - z) end
function tmp = code(x, y, z) tmp = log(y) - z; end
code[x_, y_, z_] := N[(N[Log[y], $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\log y - z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites80.9%
Taylor expanded in x around -inf
Applied rewrites29.4%
(FPCore (x y z) :precision binary64 (+ y 0.5))
double code(double x, double y, double z) {
return y + 0.5;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + 0.5d0
end function
public static double code(double x, double y, double z) {
return y + 0.5;
}
def code(x, y, z): return y + 0.5
function code(x, y, z) return Float64(y + 0.5) end
function tmp = code(x, y, z) tmp = y + 0.5; end
code[x_, y_, z_] := N[(y + 0.5), $MachinePrecision]
\begin{array}{l}
\\
y + 0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites71.4%
Taylor expanded in x around inf
Applied rewrites3.8%
(FPCore (x y z) :precision binary64 (- (- (+ y x) z) (* (+ y 0.5) (log y))))
double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 0.5) * log(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y + x) - z) - ((y + 0.5d0) * log(y))
end function
public static double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 0.5) * Math.log(y));
}
def code(x, y, z): return ((y + x) - z) - ((y + 0.5) * math.log(y))
function code(x, y, z) return Float64(Float64(Float64(y + x) - z) - Float64(Float64(y + 0.5) * log(y))) end
function tmp = code(x, y, z) tmp = ((y + x) - z) - ((y + 0.5) * log(y)); end
code[x_, y_, z_] := N[(N[(N[(y + x), $MachinePrecision] - z), $MachinePrecision] - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y
\end{array}
herbie shell --seed 2024321
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- (- (+ y x) z) (* (+ y 1/2) (log y))))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))