
(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 9 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 (- (fma (log y) (- -0.5 y) y) z)))
double code(double x, double y, double z) {
return x + (fma(log(y), (-0.5 - y), y) - z);
}
function code(x, y, z) return Float64(x + Float64(fma(log(y), Float64(-0.5 - y), y) - z)) end
code[x_, y_, z_] := N[(x + N[(N[(N[Log[y], $MachinePrecision] * N[(-0.5 - y), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\mathsf{fma}\left(\log y, -0.5 - y, y\right) - z\right)
\end{array}
Initial program 99.8%
sub-neg99.8%
sub-neg99.8%
associate-+l+99.8%
associate-+l+99.8%
sub-neg99.8%
neg-sub099.8%
associate-+l-99.8%
neg-sub099.8%
neg-mul-199.8%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= y 1.12e-35)
(- x z)
(if (<= y 1.05e-15)
(- (* (log y) -0.5) z)
(if (<= y 1.55e+83) (- x z) (- (* y (- 1.0 (log y))) z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.12e-35) {
tmp = x - z;
} else if (y <= 1.05e-15) {
tmp = (log(y) * -0.5) - z;
} else if (y <= 1.55e+83) {
tmp = x - z;
} else {
tmp = (y * (1.0 - 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) :: tmp
if (y <= 1.12d-35) then
tmp = x - z
else if (y <= 1.05d-15) then
tmp = (log(y) * (-0.5d0)) - z
else if (y <= 1.55d+83) then
tmp = x - z
else
tmp = (y * (1.0d0 - log(y))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.12e-35) {
tmp = x - z;
} else if (y <= 1.05e-15) {
tmp = (Math.log(y) * -0.5) - z;
} else if (y <= 1.55e+83) {
tmp = x - z;
} else {
tmp = (y * (1.0 - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.12e-35: tmp = x - z elif y <= 1.05e-15: tmp = (math.log(y) * -0.5) - z elif y <= 1.55e+83: tmp = x - z else: tmp = (y * (1.0 - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.12e-35) tmp = Float64(x - z); elseif (y <= 1.05e-15) tmp = Float64(Float64(log(y) * -0.5) - z); elseif (y <= 1.55e+83) tmp = Float64(x - z); else tmp = Float64(Float64(y * Float64(1.0 - log(y))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.12e-35) tmp = x - z; elseif (y <= 1.05e-15) tmp = (log(y) * -0.5) - z; elseif (y <= 1.55e+83) tmp = x - z; else tmp = (y * (1.0 - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.12e-35], N[(x - z), $MachinePrecision], If[LessEqual[y, 1.05e-15], N[(N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[y, 1.55e+83], N[(x - z), $MachinePrecision], N[(N[(y * N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.12 \cdot 10^{-35}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-15}:\\
\;\;\;\;\log y \cdot -0.5 - z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+83}:\\
\;\;\;\;x - z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \log y\right) - z\\
\end{array}
\end{array}
if y < 1.12e-35 or 1.0499999999999999e-15 < y < 1.54999999999999996e83Initial program 100.0%
Taylor expanded in x around inf 79.2%
if 1.12e-35 < y < 1.0499999999999999e-15Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around 0 100.0%
*-commutative100.0%
Simplified100.0%
if 1.54999999999999996e83 < y Initial program 99.5%
add-cube-cbrt98.3%
pow398.4%
*-commutative98.4%
Applied egg-rr98.4%
rem-cube-cbrt99.5%
add-sqr-sqrt99.2%
associate-*r*99.3%
Applied egg-rr99.3%
Taylor expanded in y around inf 88.5%
mul-1-neg88.5%
log-rec88.5%
remove-double-neg88.5%
distribute-lft-out--88.4%
*-rgt-identity88.4%
Simplified88.4%
Taylor expanded in y around 0 88.5%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (<= y 2.85e-14) (- (- x (* (log y) 0.5)) z) (+ x (- (* y (- 1.0 (log y))) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.85e-14) {
tmp = (x - (log(y) * 0.5)) - z;
} else {
tmp = x + ((y * (1.0 - 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) :: tmp
if (y <= 2.85d-14) then
tmp = (x - (log(y) * 0.5d0)) - z
else
tmp = x + ((y * (1.0d0 - log(y))) - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.85e-14) {
tmp = (x - (Math.log(y) * 0.5)) - z;
} else {
tmp = x + ((y * (1.0 - Math.log(y))) - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.85e-14: tmp = (x - (math.log(y) * 0.5)) - z else: tmp = x + ((y * (1.0 - math.log(y))) - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.85e-14) tmp = Float64(Float64(x - Float64(log(y) * 0.5)) - z); else tmp = Float64(x + Float64(Float64(y * Float64(1.0 - log(y))) - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.85e-14) tmp = (x - (log(y) * 0.5)) - z; else tmp = x + ((y * (1.0 - log(y))) - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.85e-14], N[(N[(x - N[(N[Log[y], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(x + N[(N[(y * N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.85 \cdot 10^{-14}:\\
\;\;\;\;\left(x - \log y \cdot 0.5\right) - z\\
\mathbf{else}:\\
\;\;\;\;x + \left(y \cdot \left(1 - \log y\right) - z\right)\\
\end{array}
\end{array}
if y < 2.84999999999999985e-14Initial program 100.0%
Taylor expanded in y around 0 100.0%
*-commutative100.0%
Simplified100.0%
if 2.84999999999999985e-14 < y Initial program 99.6%
sub-neg99.6%
sub-neg99.6%
associate-+l+99.6%
associate-+l+99.6%
sub-neg99.6%
neg-sub099.6%
associate-+l-99.6%
neg-sub099.6%
neg-mul-199.6%
Simplified99.7%
Taylor expanded in y around inf 99.0%
log-rec99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (- (+ y (- x (* (log y) (+ y 0.5)))) z))
double code(double x, double y, double z) {
return (y + (x - (log(y) * (y + 0.5)))) - z;
}
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 - (log(y) * (y + 0.5d0)))) - z
end function
public static double code(double x, double y, double z) {
return (y + (x - (Math.log(y) * (y + 0.5)))) - z;
}
def code(x, y, z): return (y + (x - (math.log(y) * (y + 0.5)))) - z
function code(x, y, z) return Float64(Float64(y + Float64(x - Float64(log(y) * Float64(y + 0.5)))) - z) end
function tmp = code(x, y, z) tmp = (y + (x - (log(y) * (y + 0.5)))) - z; end
code[x_, y_, z_] := N[(N[(y + N[(x - N[(N[Log[y], $MachinePrecision] * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \left(x - \log y \cdot \left(y + 0.5\right)\right)\right) - z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -195.0) (- x z) (if (<= x 4000000000000.0) (- (* (log y) -0.5) z) (- x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -195.0) {
tmp = x - z;
} else if (x <= 4000000000000.0) {
tmp = (log(y) * -0.5) - z;
} else {
tmp = x - 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) :: tmp
if (x <= (-195.0d0)) then
tmp = x - z
else if (x <= 4000000000000.0d0) then
tmp = (log(y) * (-0.5d0)) - z
else
tmp = x - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -195.0) {
tmp = x - z;
} else if (x <= 4000000000000.0) {
tmp = (Math.log(y) * -0.5) - z;
} else {
tmp = x - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -195.0: tmp = x - z elif x <= 4000000000000.0: tmp = (math.log(y) * -0.5) - z else: tmp = x - z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -195.0) tmp = Float64(x - z); elseif (x <= 4000000000000.0) tmp = Float64(Float64(log(y) * -0.5) - z); else tmp = Float64(x - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -195.0) tmp = x - z; elseif (x <= 4000000000000.0) tmp = (log(y) * -0.5) - z; else tmp = x - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -195.0], N[(x - z), $MachinePrecision], If[LessEqual[x, 4000000000000.0], N[(N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision] - z), $MachinePrecision], N[(x - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -195:\\
\;\;\;\;x - z\\
\mathbf{elif}\;x \leq 4000000000000:\\
\;\;\;\;\log y \cdot -0.5 - z\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if x < -195 or 4e12 < x Initial program 99.9%
Taylor expanded in x around inf 79.9%
if -195 < x < 4e12Initial program 99.7%
Taylor expanded in x around 0 98.6%
Taylor expanded in y around 0 62.8%
*-commutative62.8%
Simplified62.8%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (if (<= y 3e+82) (- (- x (* (log y) 0.5)) z) (- (* y (- 1.0 (log y))) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e+82) {
tmp = (x - (log(y) * 0.5)) - z;
} else {
tmp = (y * (1.0 - 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) :: tmp
if (y <= 3d+82) then
tmp = (x - (log(y) * 0.5d0)) - z
else
tmp = (y * (1.0d0 - log(y))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3e+82) {
tmp = (x - (Math.log(y) * 0.5)) - z;
} else {
tmp = (y * (1.0 - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e+82: tmp = (x - (math.log(y) * 0.5)) - z else: tmp = (y * (1.0 - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e+82) tmp = Float64(Float64(x - Float64(log(y) * 0.5)) - z); else tmp = Float64(Float64(y * Float64(1.0 - log(y))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e+82) tmp = (x - (log(y) * 0.5)) - z; else tmp = (y * (1.0 - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e+82], N[(N[(x - N[(N[Log[y], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(y * N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+82}:\\
\;\;\;\;\left(x - \log y \cdot 0.5\right) - z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \log y\right) - z\\
\end{array}
\end{array}
if y < 2.99999999999999989e82Initial program 100.0%
Taylor expanded in y around 0 95.4%
*-commutative95.4%
Simplified95.4%
if 2.99999999999999989e82 < y Initial program 99.5%
add-cube-cbrt98.3%
pow398.4%
*-commutative98.4%
Applied egg-rr98.4%
rem-cube-cbrt99.5%
add-sqr-sqrt99.2%
associate-*r*99.3%
Applied egg-rr99.3%
Taylor expanded in y around inf 88.5%
mul-1-neg88.5%
log-rec88.5%
remove-double-neg88.5%
distribute-lft-out--88.4%
*-rgt-identity88.4%
Simplified88.4%
Taylor expanded in y around 0 88.5%
Final simplification93.1%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e-227) (- x z) (if (<= x 1.15e-243) (* (log y) -0.5) (- x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-227) {
tmp = x - z;
} else if (x <= 1.15e-243) {
tmp = log(y) * -0.5;
} else {
tmp = x - 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) :: tmp
if (x <= (-7.2d-227)) then
tmp = x - z
else if (x <= 1.15d-243) then
tmp = log(y) * (-0.5d0)
else
tmp = x - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-227) {
tmp = x - z;
} else if (x <= 1.15e-243) {
tmp = Math.log(y) * -0.5;
} else {
tmp = x - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e-227: tmp = x - z elif x <= 1.15e-243: tmp = math.log(y) * -0.5 else: tmp = x - z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e-227) tmp = Float64(x - z); elseif (x <= 1.15e-243) tmp = Float64(log(y) * -0.5); else tmp = Float64(x - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e-227) tmp = x - z; elseif (x <= 1.15e-243) tmp = log(y) * -0.5; else tmp = x - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e-227], N[(x - z), $MachinePrecision], If[LessEqual[x, 1.15e-243], N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision], N[(x - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-227}:\\
\;\;\;\;x - z\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-243}:\\
\;\;\;\;\log y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;x - z\\
\end{array}
\end{array}
if x < -7.1999999999999999e-227 or 1.15e-243 < x Initial program 99.8%
Taylor expanded in x around inf 64.8%
if -7.1999999999999999e-227 < x < 1.15e-243Initial program 99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 51.0%
*-commutative51.0%
Simplified51.0%
Taylor expanded in z around 0 36.6%
*-commutative36.6%
Simplified36.6%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (- x z))
double code(double x, double y, double z) {
return x - 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 - z
end function
public static double code(double x, double y, double z) {
return x - z;
}
def code(x, y, z): return x - z
function code(x, y, z) return Float64(x - z) end
function tmp = code(x, y, z) tmp = x - z; end
code[x_, y_, z_] := N[(x - z), $MachinePrecision]
\begin{array}{l}
\\
x - z
\end{array}
Initial program 99.8%
Taylor expanded in x around inf 59.8%
Final simplification59.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 69.5%
Taylor expanded in y around 0 42.4%
*-commutative42.4%
Simplified42.4%
Taylor expanded in z around inf 30.6%
neg-mul-130.6%
Simplified30.6%
Final simplification30.6%
(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 2023195
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(- (- (+ y x) z) (* (+ y 0.5) (log y)))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))