| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 26820 |

(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 (<= x 2e+20)
(+
(fma (+ x -0.5) (log x) (- 0.91893853320467 x))
(/
(fma
z
(fma (+ y 0.0007936500793651) z -0.0027777777777778)
0.083333333333333)
x))
(+
(+ 0.91893853320467 (- (* (log x) (- x 0.5)) x))
(/ (+ y 0.0007936500793651) (/ (/ x z) z)))))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 (x <= 2e+20) {
tmp = fma((x + -0.5), log(x), (0.91893853320467 - x)) + (fma(z, fma((y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x);
} else {
tmp = (0.91893853320467 + ((log(x) * (x - 0.5)) - x)) + ((y + 0.0007936500793651) / ((x / z) / z));
}
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 (x <= 2e+20) tmp = Float64(fma(Float64(x + -0.5), log(x), Float64(0.91893853320467 - x)) + Float64(fma(z, fma(Float64(y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x)); else tmp = Float64(Float64(0.91893853320467 + Float64(Float64(log(x) * Float64(x - 0.5)) - x)) + Float64(Float64(y + 0.0007936500793651) / Float64(Float64(x / z) / z))); 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[LessEqual[x, 2e+20], N[(N[(N[(x + -0.5), $MachinePrecision] * N[Log[x], $MachinePrecision] + N[(0.91893853320467 - x), $MachinePrecision]), $MachinePrecision] + N[(N[(z * N[(N[(y + 0.0007936500793651), $MachinePrecision] * z + -0.0027777777777778), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(0.91893853320467 + N[(N[(N[Log[x], $MachinePrecision] * N[(x - 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision] + N[(N[(y + 0.0007936500793651), $MachinePrecision] / N[(N[(x / z), $MachinePrecision] / z), $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}\;x \leq 2 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(0.91893853320467 + \left(\log x \cdot \left(x - 0.5\right) - x\right)\right) + \frac{y + 0.0007936500793651}{\frac{\frac{x}{z}}{z}}\\
\end{array}
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 93.7% |
|---|---|
| Target | 98.6% |
| Herbie | 99.6% |
if x < 2e20Initial program 99.7%
Simplified99.7%
[Start]99.7% | \[ \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}
\] |
|---|---|
remove-double-neg [<=]99.7% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)}
\] |
sub-neg [=>]99.7% | \[ \left(\color{blue}{\left(\left(x - 0.5\right) \cdot \log x + \left(-x\right)\right)} + 0.91893853320467\right) + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
associate-+l+ [=>]99.7% | \[ \color{blue}{\left(\left(x - 0.5\right) \cdot \log x + \left(\left(-x\right) + 0.91893853320467\right)\right)} + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
fma-def [=>]99.7% | \[ \color{blue}{\mathsf{fma}\left(x - 0.5, \log x, \left(-x\right) + 0.91893853320467\right)} + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
sub-neg [=>]99.7% | \[ \mathsf{fma}\left(\color{blue}{x + \left(-0.5\right)}, \log x, \left(-x\right) + 0.91893853320467\right) + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
metadata-eval [=>]99.7% | \[ \mathsf{fma}\left(x + \color{blue}{-0.5}, \log x, \left(-x\right) + 0.91893853320467\right) + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
+-commutative [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, \color{blue}{0.91893853320467 + \left(-x\right)}\right) + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
unsub-neg [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, \color{blue}{0.91893853320467 - x}\right) + \left(-\left(-\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\right)\right)
\] |
remove-double-neg [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \color{blue}{\frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}}
\] |
*-commutative [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{\color{blue}{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)} + 0.083333333333333}{x}
\] |
fma-def [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{\color{blue}{\mathsf{fma}\left(z, \left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778, 0.083333333333333\right)}}{x}
\] |
fma-neg [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{\mathsf{fma}\left(z, \color{blue}{\mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right)}, 0.083333333333333\right)}{x}
\] |
metadata-eval [=>]99.7% | \[ \mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, \color{blue}{-0.0027777777777778}\right), 0.083333333333333\right)}{x}
\] |
if 2e20 < x Initial program 89.4%
Taylor expanded in z around inf 87.8%
Simplified91.8%
[Start]87.8% | \[ \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* [=>]91.0% | \[ \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}}}
\] |
+-commutative [<=]91.0% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{{z}^{2}}{\frac{x}{\color{blue}{y + 0.0007936500793651}}}
\] |
associate-/r/ [=>]91.8% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{{z}^{2}}{x} \cdot \left(y + 0.0007936500793651\right)}
\] |
unpow2 [=>]91.8% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{z \cdot z}}{x} \cdot \left(y + 0.0007936500793651\right)
\] |
+-commutative [=>]91.8% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{x} \cdot \color{blue}{\left(0.0007936500793651 + y\right)}
\] |
Taylor expanded in z around 0 91.8%
Simplified98.9%
[Start]91.8% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{{z}^{2}}{x} \cdot \left(0.0007936500793651 + y\right)
\] |
|---|---|
unpow2 [=>]91.8% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{z \cdot z}}{x} \cdot \left(0.0007936500793651 + y\right)
\] |
associate-/l* [=>]98.9% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{z}{\frac{x}{z}}} \cdot \left(0.0007936500793651 + y\right)
\] |
Applied egg-rr99.5%
[Start]98.9% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{z}{\frac{x}{z}} \cdot \left(0.0007936500793651 + y\right)
\] |
|---|---|
*-commutative [=>]98.9% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\left(0.0007936500793651 + y\right) \cdot \frac{z}{\frac{x}{z}}}
\] |
clear-num [=>]98.9% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(0.0007936500793651 + y\right) \cdot \color{blue}{\frac{1}{\frac{\frac{x}{z}}{z}}}
\] |
un-div-inv [=>]99.5% | \[ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\frac{0.0007936500793651 + y}{\frac{\frac{x}{z}}{z}}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 26820 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 8004 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 7753 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7748 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7748 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7748 |
| Alternative 7 | |
|---|---|
| Accuracy | 95.8% |
| Cost | 7625 |
| Alternative 8 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 7625 |
| Alternative 9 | |
|---|---|
| Accuracy | 81.4% |
| Cost | 7496 |
| Alternative 10 | |
|---|---|
| Accuracy | 82.4% |
| Cost | 7496 |
| Alternative 11 | |
|---|---|
| Accuracy | 81.4% |
| Cost | 7368 |
| Alternative 12 | |
|---|---|
| Accuracy | 81.4% |
| Cost | 7240 |
| Alternative 13 | |
|---|---|
| Accuracy | 60.1% |
| Cost | 841 |
| Alternative 14 | |
|---|---|
| Accuracy | 48.4% |
| Cost | 713 |
| Alternative 15 | |
|---|---|
| Accuracy | 48.3% |
| Cost | 713 |
| Alternative 16 | |
|---|---|
| Accuracy | 23.6% |
| Cost | 192 |
herbie shell --seed 2023263
(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)))