
(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 7 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.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* (+ y 0.5) (log y)))) (t_1 (- t_0 z))) (if (<= z -1.08e+26) t_1 (if (<= z 2.2e+47) (+ 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 <= -1.08e+26) {
tmp = t_1;
} else if (z <= 2.2e+47) {
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 <= (-1.08d+26)) then
tmp = t_1
else if (z <= 2.2d+47) 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 <= -1.08e+26) {
tmp = t_1;
} else if (z <= 2.2e+47) {
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 <= -1.08e+26: tmp = t_1 elif z <= 2.2e+47: 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 <= -1.08e+26) tmp = t_1; elseif (z <= 2.2e+47) 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 <= -1.08e+26) tmp = t_1; elseif (z <= 2.2e+47) 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, -1.08e+26], t$95$1, If[LessEqual[z, 2.2e+47], 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 -1.08 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+47}:\\
\;\;\;\;t\_0 + y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.08e26 or 2.1999999999999999e47 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites91.2%
if -1.08e26 < z < 2.1999999999999999e47Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ y 0.5) (log y))))
(if (<= z -1.25e+113)
(- t_0 z)
(if (<= z 6.6e+123) (+ (- x t_0) y) (- (log y) z)))))
double code(double x, double y, double z) {
double t_0 = (y + 0.5) * log(y);
double tmp;
if (z <= -1.25e+113) {
tmp = t_0 - z;
} else if (z <= 6.6e+123) {
tmp = (x - t_0) + y;
} else {
tmp = log(y) - z;
}
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 = (y + 0.5d0) * log(y)
if (z <= (-1.25d+113)) then
tmp = t_0 - z
else if (z <= 6.6d+123) then
tmp = (x - t_0) + y
else
tmp = log(y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y + 0.5) * Math.log(y);
double tmp;
if (z <= -1.25e+113) {
tmp = t_0 - z;
} else if (z <= 6.6e+123) {
tmp = (x - t_0) + y;
} else {
tmp = Math.log(y) - z;
}
return tmp;
}
def code(x, y, z): t_0 = (y + 0.5) * math.log(y) tmp = 0 if z <= -1.25e+113: tmp = t_0 - z elif z <= 6.6e+123: tmp = (x - t_0) + y else: tmp = math.log(y) - z return tmp
function code(x, y, z) t_0 = Float64(Float64(y + 0.5) * log(y)) tmp = 0.0 if (z <= -1.25e+113) tmp = Float64(t_0 - z); elseif (z <= 6.6e+123) tmp = Float64(Float64(x - t_0) + y); else tmp = Float64(log(y) - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + 0.5) * log(y); tmp = 0.0; if (z <= -1.25e+113) tmp = t_0 - z; elseif (z <= 6.6e+123) tmp = (x - t_0) + y; else tmp = log(y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.25e+113], N[(t$95$0 - z), $MachinePrecision], If[LessEqual[z, 6.6e+123], N[(N[(x - t$95$0), $MachinePrecision] + y), $MachinePrecision], N[(N[Log[y], $MachinePrecision] - z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + 0.5\right) \cdot \log y\\
\mathbf{if}\;z \leq -1.25 \cdot 10^{+113}:\\
\;\;\;\;t\_0 - z\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+123}:\\
\;\;\;\;\left(x - t\_0\right) + y\\
\mathbf{else}:\\
\;\;\;\;\log y - z\\
\end{array}
\end{array}
if z < -1.25e113Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites67.7%
if -1.25e113 < z < 6.60000000000000006e123Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites92.2%
if 6.60000000000000006e123 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites96.6%
Taylor expanded in x around inf
Applied rewrites83.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ y 0.5) (log y))))
(if (<= z -1.32e+105)
(- t_0 z)
(if (<= z 1.2e+25) (- x t_0) (- (log y) z)))))
double code(double x, double y, double z) {
double t_0 = (y + 0.5) * log(y);
double tmp;
if (z <= -1.32e+105) {
tmp = t_0 - z;
} else if (z <= 1.2e+25) {
tmp = x - t_0;
} else {
tmp = log(y) - z;
}
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 = (y + 0.5d0) * log(y)
if (z <= (-1.32d+105)) then
tmp = t_0 - z
else if (z <= 1.2d+25) then
tmp = x - t_0
else
tmp = log(y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y + 0.5) * Math.log(y);
double tmp;
if (z <= -1.32e+105) {
tmp = t_0 - z;
} else if (z <= 1.2e+25) {
tmp = x - t_0;
} else {
tmp = Math.log(y) - z;
}
return tmp;
}
def code(x, y, z): t_0 = (y + 0.5) * math.log(y) tmp = 0 if z <= -1.32e+105: tmp = t_0 - z elif z <= 1.2e+25: tmp = x - t_0 else: tmp = math.log(y) - z return tmp
function code(x, y, z) t_0 = Float64(Float64(y + 0.5) * log(y)) tmp = 0.0 if (z <= -1.32e+105) tmp = Float64(t_0 - z); elseif (z <= 1.2e+25) tmp = Float64(x - t_0); else tmp = Float64(log(y) - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + 0.5) * log(y); tmp = 0.0; if (z <= -1.32e+105) tmp = t_0 - z; elseif (z <= 1.2e+25) tmp = x - t_0; else tmp = log(y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.32e+105], N[(t$95$0 - z), $MachinePrecision], If[LessEqual[z, 1.2e+25], N[(x - t$95$0), $MachinePrecision], N[(N[Log[y], $MachinePrecision] - z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + 0.5\right) \cdot \log y\\
\mathbf{if}\;z \leq -1.32 \cdot 10^{+105}:\\
\;\;\;\;t\_0 - z\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+25}:\\
\;\;\;\;x - t\_0\\
\mathbf{else}:\\
\;\;\;\;\log y - z\\
\end{array}
\end{array}
if z < -1.31999999999999994e105Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites65.4%
if -1.31999999999999994e105 < z < 1.19999999999999998e25Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites96.7%
Taylor expanded in x around 0
Applied rewrites72.9%
if 1.19999999999999998e25 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites93.8%
Taylor expanded in x around inf
Applied rewrites72.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (log y) z)))
(if (<= z -1.32e+105)
t_0
(if (<= z 1.2e+25) (- 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 <= -1.32e+105) {
tmp = t_0;
} else if (z <= 1.2e+25) {
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 <= (-1.32d+105)) then
tmp = t_0
else if (z <= 1.2d+25) 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 <= -1.32e+105) {
tmp = t_0;
} else if (z <= 1.2e+25) {
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 <= -1.32e+105: tmp = t_0 elif z <= 1.2e+25: 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 <= -1.32e+105) tmp = t_0; elseif (z <= 1.2e+25) 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 <= -1.32e+105) tmp = t_0; elseif (z <= 1.2e+25) 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, -1.32e+105], t$95$0, If[LessEqual[z, 1.2e+25], 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 -1.32 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+25}:\\
\;\;\;\;x - \left(y + 0.5\right) \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.31999999999999994e105 or 1.19999999999999998e25 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites90.4%
Taylor expanded in x around inf
Applied rewrites69.2%
if -1.31999999999999994e105 < z < 1.19999999999999998e25Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites96.7%
Taylor expanded in x around 0
Applied rewrites72.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.8%
Taylor expanded in x around 0
Applied rewrites81.5%
Taylor expanded in x around inf
Applied rewrites28.9%
(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.8%
Taylor expanded in x around 0
Applied rewrites71.8%
Taylor expanded in x around inf
Applied rewrites3.9%
(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 2024313
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (- (- (+ y x) z) (* (+ y 1/2) (log y))))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))