| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14537 |
(FPCore (x y z)
:precision binary64
(+
(+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
(/
(+
(* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
0.083333333333333)
x)))(FPCore (x y z)
:precision binary64
(if (or (<= z -1.15e+63) (not (<= z 5.4e+29)))
(+
(- 0.91893853320467 (- x (* x (log x))))
(* z (* z (/ (+ 0.0007936500793651 y) x))))
(+
0.91893853320467
(-
(/
(fma
z
(fma (+ 0.0007936500793651 y) z -0.0027777777777778)
0.083333333333333)
x)
(fma (log x) (- 0.5 x) (expm1 (log1p 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);
}
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e+63) || !(z <= 5.4e+29)) {
tmp = (0.91893853320467 - (x - (x * log(x)))) + (z * (z * ((0.0007936500793651 + y) / x)));
} else {
tmp = 0.91893853320467 + ((fma(z, fma((0.0007936500793651 + y), z, -0.0027777777777778), 0.083333333333333) / x) - fma(log(x), (0.5 - x), expm1(log1p(x))));
}
return tmp;
}
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 code(x, y, z) tmp = 0.0 if ((z <= -1.15e+63) || !(z <= 5.4e+29)) tmp = Float64(Float64(0.91893853320467 - Float64(x - Float64(x * log(x)))) + Float64(z * Float64(z * Float64(Float64(0.0007936500793651 + y) / x)))); else tmp = Float64(0.91893853320467 + Float64(Float64(fma(z, fma(Float64(0.0007936500793651 + y), z, -0.0027777777777778), 0.083333333333333) / x) - fma(log(x), Float64(0.5 - x), expm1(log1p(x))))); end return tmp 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]
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e+63], N[Not[LessEqual[z, 5.4e+29]], $MachinePrecision]], N[(N[(0.91893853320467 - N[(x - N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(N[(0.0007936500793651 + y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.91893853320467 + N[(N[(N[(z * N[(N[(0.0007936500793651 + y), $MachinePrecision] * z + -0.0027777777777778), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision] - N[(N[Log[x], $MachinePrecision] * N[(0.5 - x), $MachinePrecision] + N[(Exp[N[Log[1 + x], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\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}
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+63} \lor \neg \left(z \leq 5.4 \cdot 10^{+29}\right):\\
\;\;\;\;\left(0.91893853320467 - \left(x - x \cdot \log x\right)\right) + z \cdot \left(z \cdot \frac{0.0007936500793651 + y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(0.0007936500793651 + y, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \mathsf{fma}\left(\log x, 0.5 - x, \mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)\right)\right)\\
\end{array}
| Original | 90.1% |
|---|---|
| Target | 98.0% |
| Herbie | 99.3% |
if z < -1.14999999999999997e63 or 5.4e29 < z Initial program 55.9%
Taylor expanded in z around inf 55.4%
Simplified68.1%
[Start]55.4 | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{{z}^{2} \cdot \left(0.0007936500793651 + y\right)}{x}
\] |
|---|---|
associate-/l* [=>]68.1 | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{{z}^{2}}{\frac{x}{0.0007936500793651 + y}}}
\] |
unpow2 [=>]68.1 | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{z \cdot z}}{\frac{x}{0.0007936500793651 + y}}
\] |
Taylor expanded in x around inf 68.1%
Simplified68.1%
[Start]68.1 | \[ \left(\left(-1 \cdot \left(\log \left(\frac{1}{x}\right) \cdot x\right) - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
|---|---|
associate-*r* [=>]68.1 | \[ \left(\left(\color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right)\right) \cdot x} - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
*-commutative [=>]68.1 | \[ \left(\left(\color{blue}{x \cdot \left(-1 \cdot \log \left(\frac{1}{x}\right)\right)} - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
mul-1-neg [=>]68.1 | \[ \left(\left(x \cdot \color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
log-rec [=>]68.1 | \[ \left(\left(x \cdot \left(-\color{blue}{\left(-\log x\right)}\right) - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
remove-double-neg [=>]68.1 | \[ \left(\left(x \cdot \color{blue}{\log x} - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
Applied egg-rr99.4%
[Start]68.1 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{\frac{x}{0.0007936500793651 + y}}
\] |
|---|---|
clear-num [=>]68.0 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{1}{\frac{\frac{x}{0.0007936500793651 + y}}{z \cdot z}}}
\] |
associate-/r* [=>]99.4 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \frac{1}{\color{blue}{\frac{\frac{\frac{x}{0.0007936500793651 + y}}{z}}{z}}}
\] |
associate-/r/ [=>]99.4 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{1}{\frac{\frac{x}{0.0007936500793651 + y}}{z}} \cdot z}
\] |
associate-/r/ [=>]99.4 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\left(\frac{1}{\frac{x}{0.0007936500793651 + y}} \cdot z\right)} \cdot z
\] |
clear-num [<=]99.4 | \[ \left(\left(x \cdot \log x - x\right) + 0.91893853320467\right) + \left(\color{blue}{\frac{0.0007936500793651 + y}{x}} \cdot z\right) \cdot z
\] |
if -1.14999999999999997e63 < z < 5.4e29Initial program 99.0%
Simplified99.1%
[Start]99.0 | \[ \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}
\] |
|---|---|
+-commutative [=>]99.0 | \[ \color{blue}{\left(0.91893853320467 + \left(\left(x - 0.5\right) \cdot \log x - x\right)\right)} + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}
\] |
associate-+l+ [=>]99.0 | \[ \color{blue}{0.91893853320467 + \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)}
\] |
+-commutative [<=]99.0 | \[ 0.91893853320467 + \color{blue}{\left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} + \left(\left(x - 0.5\right) \cdot \log x - x\right)\right)}
\] |
sub-neg [=>]99.0 | \[ 0.91893853320467 + \left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} + \color{blue}{\left(\left(x - 0.5\right) \cdot \log x + \left(-x\right)\right)}\right)
\] |
+-commutative [=>]99.0 | \[ 0.91893853320467 + \left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} + \color{blue}{\left(\left(-x\right) + \left(x - 0.5\right) \cdot \log x\right)}\right)
\] |
associate-+r+ [=>]99.0 | \[ 0.91893853320467 + \color{blue}{\left(\left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} + \left(-x\right)\right) + \left(x - 0.5\right) \cdot \log x\right)}
\] |
unsub-neg [=>]99.0 | \[ 0.91893853320467 + \left(\color{blue}{\left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} - x\right)} + \left(x - 0.5\right) \cdot \log x\right)
\] |
associate-+l- [=>]99.0 | \[ 0.91893853320467 + \color{blue}{\left(\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} - \left(x - \left(x - 0.5\right) \cdot \log x\right)\right)}
\] |
remove-double-neg [<=]99.0 | \[ 0.91893853320467 + \left(\color{blue}{\left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)} - \left(x - \left(x - 0.5\right) \cdot \log x\right)\right)
\] |
neg-mul-1 [=>]99.0 | \[ 0.91893853320467 + \left(\color{blue}{-1 \cdot \left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)} - \left(x - \left(x - 0.5\right) \cdot \log x\right)\right)
\] |
*-commutative [<=]99.0 | \[ 0.91893853320467 + \left(\color{blue}{\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right) \cdot -1} - \left(x - \left(x - 0.5\right) \cdot \log x\right)\right)
\] |
Applied egg-rr99.1%
[Start]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \mathsf{fma}\left(\log x, 0.5 - x, x\right)\right)
\] |
|---|---|
fma-udef [=>]99.0 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\left(\log x \cdot \left(0.5 - x\right) + x\right)}\right)
\] |
+-commutative [=>]99.0 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\left(x + \log x \cdot \left(0.5 - x\right)\right)}\right)
\] |
expm1-log1p-u [=>]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)} + \log x \cdot \left(0.5 - x\right)\right)\right)
\] |
expm1-udef [=>]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \left(\color{blue}{\left(e^{\mathsf{log1p}\left(x\right)} - 1\right)} + \log x \cdot \left(0.5 - x\right)\right)\right)
\] |
associate-+l- [=>]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\left(e^{\mathsf{log1p}\left(x\right)} - \left(1 - \log x \cdot \left(0.5 - x\right)\right)\right)}\right)
\] |
Simplified99.3%
[Start]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \left(e^{\mathsf{log1p}\left(x\right)} - \left(1 - \log x \cdot \left(0.5 - x\right)\right)\right)\right)
\] |
|---|---|
associate--r- [=>]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\left(\left(e^{\mathsf{log1p}\left(x\right)} - 1\right) + \log x \cdot \left(0.5 - x\right)\right)}\right)
\] |
+-commutative [<=]99.1 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\left(\log x \cdot \left(0.5 - x\right) + \left(e^{\mathsf{log1p}\left(x\right)} - 1\right)\right)}\right)
\] |
fma-def [=>]99.3 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \color{blue}{\mathsf{fma}\left(\log x, 0.5 - x, e^{\mathsf{log1p}\left(x\right)} - 1\right)}\right)
\] |
expm1-def [=>]99.3 | \[ 0.91893853320467 + \left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} - \mathsf{fma}\left(\log x, 0.5 - x, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}\right)\right)
\] |
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14537 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 8776 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 8137 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 7748 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 7620 |
| Alternative 6 | |
|---|---|
| Accuracy | 93.0% |
| Cost | 7492 |
| Alternative 7 | |
|---|---|
| Accuracy | 93.6% |
| Cost | 7492 |
| Alternative 8 | |
|---|---|
| Accuracy | 89.8% |
| Cost | 7364 |
| Alternative 9 | |
|---|---|
| Accuracy | 89.4% |
| Cost | 7108 |
| Alternative 10 | |
|---|---|
| Accuracy | 89.1% |
| Cost | 6852 |
| Alternative 11 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 1348 |
| Alternative 12 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 1220 |
| Alternative 13 | |
|---|---|
| Accuracy | 45.8% |
| Cost | 969 |
| Alternative 14 | |
|---|---|
| Accuracy | 33.2% |
| Cost | 448 |
| Alternative 15 | |
|---|---|
| Accuracy | 37.9% |
| Cost | 448 |
| Alternative 16 | |
|---|---|
| Accuracy | 33.2% |
| Cost | 320 |
| Alternative 17 | |
|---|---|
| Accuracy | 32.4% |
| Cost | 192 |
| Alternative 18 | |
|---|---|
| Accuracy | 1.2% |
| Cost | 128 |
herbie shell --seed 2023137
(FPCore (x y z)
:name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, B"
:precision binary64
:herbie-target
(+ (+ (+ (* (- x 0.5) (log x)) (- 0.91893853320467 x)) (/ 0.083333333333333 x)) (* (/ z x) (- (* z (+ y 0.0007936500793651)) 0.0027777777777778)))
(+ (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467) (/ (+ (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z) 0.083333333333333) x)))