| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 14020 |

(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 2.1e-5)
(+
0.91893853320467
(+
(* -0.5 (log x))
(+
(/ (* z (- (* z (+ 0.0007936500793651 y)) 0.0027777777777778)) x)
(* 0.083333333333333 (/ 1.0 x)))))
(+
(fma (log x) (+ x -0.5) (- 0.91893853320467 x))
(* (+ 0.0007936500793651 y) (/ z (/ x 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 <= 2.1e-5) {
tmp = 0.91893853320467 + ((-0.5 * log(x)) + (((z * ((z * (0.0007936500793651 + y)) - 0.0027777777777778)) / x) + (0.083333333333333 * (1.0 / x))));
} else {
tmp = fma(log(x), (x + -0.5), (0.91893853320467 - x)) + ((0.0007936500793651 + y) * (z / (x / 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 <= 2.1e-5) tmp = Float64(0.91893853320467 + Float64(Float64(-0.5 * log(x)) + Float64(Float64(Float64(z * Float64(Float64(z * Float64(0.0007936500793651 + y)) - 0.0027777777777778)) / x) + Float64(0.083333333333333 * Float64(1.0 / x))))); else tmp = Float64(fma(log(x), Float64(x + -0.5), Float64(0.91893853320467 - x)) + Float64(Float64(0.0007936500793651 + y) * Float64(z / Float64(x / 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, 2.1e-5], N[(0.91893853320467 + N[(N[(-0.5 * N[Log[x], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(z * N[(N[(z * N[(0.0007936500793651 + y), $MachinePrecision]), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(0.083333333333333 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[x], $MachinePrecision] * N[(x + -0.5), $MachinePrecision] + N[(0.91893853320467 - x), $MachinePrecision]), $MachinePrecision] + N[(N[(0.0007936500793651 + y), $MachinePrecision] * N[(z / N[(x / z), $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}\;x \leq 2.1 \cdot 10^{-5}:\\
\;\;\;\;0.91893853320467 + \left(-0.5 \cdot \log x + \left(\frac{z \cdot \left(z \cdot \left(0.0007936500793651 + y\right) - 0.0027777777777778\right)}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \left(0.0007936500793651 + y\right) \cdot \frac{z}{\frac{x}{z}}\\
\end{array}
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 93.8% |
|---|---|
| Target | 98.7% |
| Herbie | 99.0% |
if x < 2.09999999999999988e-5Initial 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(\color{blue}{\left(-\left(-\left(x - 0.5\right)\right)\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(\color{blue}{\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}
\] |
sub-neg [=>]99.7% | \[ \left(\left(\color{blue}{\left(x + \left(-0.5\right)\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}
\] |
metadata-eval [=>]99.7% | \[ \left(\left(\left(x + \color{blue}{-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.7% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)} + 0.083333333333333}{x}
\] |
fma-def [=>]99.7% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\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% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\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% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, \color{blue}{-0.0027777777777778}\right), 0.083333333333333\right)}{x}
\] |
Taylor expanded in x around 0 99.7%
if 2.09999999999999988e-5 < x Initial program 87.2%
Simplified87.2%
[Start]87.2% | \[ \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 [<=]87.2% | \[ \left(\left(\color{blue}{\left(-\left(-\left(x - 0.5\right)\right)\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 [=>]87.2% | \[ \left(\left(\color{blue}{\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}
\] |
sub-neg [=>]87.2% | \[ \left(\left(\color{blue}{\left(x + \left(-0.5\right)\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}
\] |
metadata-eval [=>]87.2% | \[ \left(\left(\left(x + \color{blue}{-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 [=>]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)} + 0.083333333333333}{x}
\] |
fma-def [=>]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{\mathsf{fma}\left(z, \left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778, 0.083333333333333\right)}}{x}
\] |
fma-neg [=>]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\mathsf{fma}\left(z, \color{blue}{\mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right)}, 0.083333333333333\right)}{x}
\] |
metadata-eval [=>]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, \color{blue}{-0.0027777777777778}\right), 0.083333333333333\right)}{x}
\] |
Taylor expanded in z around inf 87.2%
Simplified87.2%
[Start]87.2% | \[ \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}
\] |
|---|---|
unpow2 [=>]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\color{blue}{\left(z \cdot z\right)} \cdot \left(0.0007936500793651 + y\right)}{x}
\] |
+-commutative [<=]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(z \cdot z\right) \cdot \color{blue}{\left(y + 0.0007936500793651\right)}}{x}
\] |
Applied egg-rr87.2%
[Start]87.2% | \[ \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(z \cdot z\right) \cdot \left(y + 0.0007936500793651\right)}{x}
\] |
|---|---|
*-un-lft-identity [=>]87.2% | \[ \color{blue}{1 \cdot \left(\left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(z \cdot z\right) \cdot \left(y + 0.0007936500793651\right)}{x}\right)}
\] |
+-commutative [=>]87.2% | \[ 1 \cdot \color{blue}{\left(\frac{\left(z \cdot z\right) \cdot \left(y + 0.0007936500793651\right)}{x} + \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right)\right)}
\] |
*-commutative [=>]87.2% | \[ 1 \cdot \left(\frac{\color{blue}{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}}{x} + \left(\left(\left(x + -0.5\right) \cdot \log x - x\right) + 0.91893853320467\right)\right)
\] |
+-commutative [=>]87.2% | \[ 1 \cdot \left(\frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x} + \color{blue}{\left(0.91893853320467 + \left(\left(x + -0.5\right) \cdot \log x - x\right)\right)}\right)
\] |
Simplified98.2%
[Start]87.2% | \[ 1 \cdot \left(\frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x} + \left(0.91893853320467 + \left(\left(x + -0.5\right) \cdot \log x - x\right)\right)\right)
\] |
|---|---|
*-lft-identity [=>]87.2% | \[ \color{blue}{\frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x} + \left(0.91893853320467 + \left(\left(x + -0.5\right) \cdot \log x - x\right)\right)}
\] |
+-commutative [=>]87.2% | \[ \color{blue}{\left(0.91893853320467 + \left(\left(x + -0.5\right) \cdot \log x - x\right)\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}}
\] |
associate-+r- [=>]87.2% | \[ \color{blue}{\left(\left(0.91893853320467 + \left(x + -0.5\right) \cdot \log x\right) - x\right)} + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
+-commutative [=>]87.2% | \[ \left(\color{blue}{\left(\left(x + -0.5\right) \cdot \log x + 0.91893853320467\right)} - x\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
associate-+r- [<=]87.2% | \[ \color{blue}{\left(\left(x + -0.5\right) \cdot \log x + \left(0.91893853320467 - x\right)\right)} + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
metadata-eval [<=]87.2% | \[ \left(\left(x + \color{blue}{\left(-0.5\right)}\right) \cdot \log x + \left(0.91893853320467 - x\right)\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
sub-neg [<=]87.2% | \[ \left(\color{blue}{\left(x - 0.5\right)} \cdot \log x + \left(0.91893853320467 - x\right)\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
*-commutative [=>]87.2% | \[ \left(\color{blue}{\log x \cdot \left(x - 0.5\right)} + \left(0.91893853320467 - x\right)\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
fma-def [=>]87.3% | \[ \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right)} + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
sub-neg [=>]87.3% | \[ \mathsf{fma}\left(\log x, \color{blue}{x + \left(-0.5\right)}, 0.91893853320467 - x\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
metadata-eval [=>]87.3% | \[ \mathsf{fma}\left(\log x, x + \color{blue}{-0.5}, 0.91893853320467 - x\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
+-commutative [=>]87.3% | \[ \mathsf{fma}\left(\log x, \color{blue}{-0.5 + x}, 0.91893853320467 - x\right) + \frac{\left(y + 0.0007936500793651\right) \cdot \left(z \cdot z\right)}{x}
\] |
*-commutative [=>]87.3% | \[ \mathsf{fma}\left(\log x, -0.5 + x, 0.91893853320467 - x\right) + \frac{\color{blue}{\left(z \cdot z\right) \cdot \left(y + 0.0007936500793651\right)}}{x}
\] |
associate-/l* [=>]90.9% | \[ \mathsf{fma}\left(\log x, -0.5 + x, 0.91893853320467 - x\right) + \color{blue}{\frac{z \cdot z}{\frac{x}{y + 0.0007936500793651}}}
\] |
associate-/r/ [=>]90.9% | \[ \mathsf{fma}\left(\log x, -0.5 + x, 0.91893853320467 - x\right) + \color{blue}{\frac{z \cdot z}{x} \cdot \left(y + 0.0007936500793651\right)}
\] |
associate-/l* [=>]98.2% | \[ \mathsf{fma}\left(\log x, -0.5 + x, 0.91893853320467 - x\right) + \color{blue}{\frac{z}{\frac{x}{z}}} \cdot \left(y + 0.0007936500793651\right)
\] |
+-commutative [=>]98.2% | \[ \mathsf{fma}\left(\log x, -0.5 + x, 0.91893853320467 - x\right) + \frac{z}{\frac{x}{z}} \cdot \color{blue}{\left(0.0007936500793651 + y\right)}
\] |
Final simplification99.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 14020 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 8004 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 7752 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7748 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.4% |
| Cost | 7496 |
| Alternative 6 | |
|---|---|
| Accuracy | 83.4% |
| Cost | 7240 |
| Alternative 7 | |
|---|---|
| Accuracy | 83.4% |
| Cost | 7117 |
| Alternative 8 | |
|---|---|
| Accuracy | 65.0% |
| Cost | 964 |
| Alternative 9 | |
|---|---|
| Accuracy | 42.7% |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Accuracy | 42.9% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Accuracy | 44.2% |
| Cost | 576 |
| Alternative 13 | |
|---|---|
| Accuracy | 44.4% |
| Cost | 576 |
| Alternative 14 | |
|---|---|
| Accuracy | 44.5% |
| Cost | 576 |
| Alternative 15 | |
|---|---|
| Accuracy | 25.7% |
| Cost | 448 |
| Alternative 16 | |
|---|---|
| Accuracy | 25.9% |
| Cost | 448 |
herbie shell --seed 2023272
(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)))