| Alternative 1 | |
|---|---|
| Accuracy | 52.4% |
| Cost | 20160 |
\[\mathsf{log1p}\left(\left({x}^{4} \cdot 0.008333333333333333 + {x}^{6} \cdot 0.0001984126984126984\right) + 0.16666666666666666 \cdot \left(x \cdot x\right)\right)
\]

(FPCore (x) :precision binary64 (log (/ (sinh x) x)))
(FPCore (x)
:precision binary64
(log1p
(+
(+
(* (pow x 4.0) 0.008333333333333333)
(* (pow x 6.0) 0.0001984126984126984))
(* 0.16666666666666666 (* x x)))))double code(double x) {
return log((sinh(x) / x));
}
double code(double x) {
return log1p((((pow(x, 4.0) * 0.008333333333333333) + (pow(x, 6.0) * 0.0001984126984126984)) + (0.16666666666666666 * (x * x))));
}
public static double code(double x) {
return Math.log((Math.sinh(x) / x));
}
public static double code(double x) {
return Math.log1p((((Math.pow(x, 4.0) * 0.008333333333333333) + (Math.pow(x, 6.0) * 0.0001984126984126984)) + (0.16666666666666666 * (x * x))));
}
def code(x): return math.log((math.sinh(x) / x))
def code(x): return math.log1p((((math.pow(x, 4.0) * 0.008333333333333333) + (math.pow(x, 6.0) * 0.0001984126984126984)) + (0.16666666666666666 * (x * x))))
function code(x) return log(Float64(sinh(x) / x)) end
function code(x) return log1p(Float64(Float64(Float64((x ^ 4.0) * 0.008333333333333333) + Float64((x ^ 6.0) * 0.0001984126984126984)) + Float64(0.16666666666666666 * Float64(x * x)))) end
code[x_] := N[Log[N[(N[Sinh[x], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Log[1 + N[(N[(N[(N[Power[x, 4.0], $MachinePrecision] * 0.008333333333333333), $MachinePrecision] + N[(N[Power[x, 6.0], $MachinePrecision] * 0.0001984126984126984), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(\frac{\sinh x}{x}\right)
\mathsf{log1p}\left(\left({x}^{4} \cdot 0.008333333333333333 + {x}^{6} \cdot 0.0001984126984126984\right) + 0.16666666666666666 \cdot \left(x \cdot x\right)\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 29.7% |
|---|---|
| Target | 52.4% |
| Herbie | 52.4% |
Initial program 28.2%
Taylor expanded in x around 0 28.4%
Applied egg-rr28.4%
[Start]28.4% | \[ \log \left(0.16666666666666666 \cdot {x}^{2} + \left(1 + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right)\right)
\] |
|---|---|
log1p-expm1-u [=>]28.4% | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(0.16666666666666666 \cdot {x}^{2} + \left(1 + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right)\right)\right)\right)}
\] |
expm1-udef [=>]28.4% | \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(0.16666666666666666 \cdot {x}^{2} + \left(1 + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right)\right)} - 1}\right)
\] |
add-exp-log [<=]28.4% | \[ \mathsf{log1p}\left(\color{blue}{\left(0.16666666666666666 \cdot {x}^{2} + \left(1 + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right)\right)} - 1\right)
\] |
associate-+r+ [=>]28.4% | \[ \mathsf{log1p}\left(\color{blue}{\left(\left(0.16666666666666666 \cdot {x}^{2} + 1\right) + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right)} - 1\right)
\] |
pow2 [<=]28.4% | \[ \mathsf{log1p}\left(\left(\left(0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + 1\right) + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right) - 1\right)
\] |
fma-udef [<=]28.4% | \[ \mathsf{log1p}\left(\left(\color{blue}{\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right)} + \left(0.0001984126984126984 \cdot {x}^{6} + 0.008333333333333333 \cdot {x}^{4}\right)\right) - 1\right)
\] |
+-commutative [=>]28.4% | \[ \mathsf{log1p}\left(\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) + \color{blue}{\left(0.008333333333333333 \cdot {x}^{4} + 0.0001984126984126984 \cdot {x}^{6}\right)}\right) - 1\right)
\] |
*-commutative [=>]28.4% | \[ \mathsf{log1p}\left(\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) + \left(\color{blue}{{x}^{4} \cdot 0.008333333333333333} + 0.0001984126984126984 \cdot {x}^{6}\right)\right) - 1\right)
\] |
fma-def [=>]28.4% | \[ \mathsf{log1p}\left(\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) + \color{blue}{\mathsf{fma}\left({x}^{4}, 0.008333333333333333, 0.0001984126984126984 \cdot {x}^{6}\right)}\right) - 1\right)
\] |
Simplified54.5%
[Start]28.4% | \[ \mathsf{log1p}\left(\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) + \mathsf{fma}\left({x}^{4}, 0.008333333333333333, 0.0001984126984126984 \cdot {x}^{6}\right)\right) - 1\right)
\] |
|---|---|
+-commutative [=>]28.4% | \[ \mathsf{log1p}\left(\color{blue}{\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, 0.0001984126984126984 \cdot {x}^{6}\right) + \mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right)\right)} - 1\right)
\] |
associate--l+ [=>]28.7% | \[ \mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left({x}^{4}, 0.008333333333333333, 0.0001984126984126984 \cdot {x}^{6}\right) + \left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) - 1\right)}\right)
\] |
*-commutative [=>]28.7% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, \color{blue}{{x}^{6} \cdot 0.0001984126984126984}\right) + \left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right) - 1\right)\right)
\] |
rem-exp-log [<=]28.7% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \left(\color{blue}{e^{\log \left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right)\right)}} - 1\right)\right)
\] |
expm1-def [=>]28.7% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 1\right)\right)\right)}\right)
\] |
fma-def [<=]28.7% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \mathsf{expm1}\left(\log \color{blue}{\left(0.16666666666666666 \cdot \left(x \cdot x\right) + 1\right)}\right)\right)
\] |
+-commutative [=>]28.7% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \mathsf{expm1}\left(\log \color{blue}{\left(1 + 0.16666666666666666 \cdot \left(x \cdot x\right)\right)}\right)\right)
\] |
log1p-def [=>]54.5% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(0.16666666666666666 \cdot \left(x \cdot x\right)\right)}\right)\right)
\] |
expm1-log1p [=>]54.5% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)
\] |
Applied egg-rr54.5%
[Start]54.5% | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{4}, 0.008333333333333333, {x}^{6} \cdot 0.0001984126984126984\right) + 0.16666666666666666 \cdot \left(x \cdot x\right)\right)
\] |
|---|---|
fma-udef [=>]54.5% | \[ \mathsf{log1p}\left(\color{blue}{\left({x}^{4} \cdot 0.008333333333333333 + {x}^{6} \cdot 0.0001984126984126984\right)} + 0.16666666666666666 \cdot \left(x \cdot x\right)\right)
\] |
Final simplification54.5%
| Alternative 1 | |
|---|---|
| Accuracy | 52.4% |
| Cost | 20160 |
| Alternative 2 | |
|---|---|
| Accuracy | 52.2% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 52.2% |
| Cost | 320 |
herbie shell --seed 2023263
(FPCore (x)
:name "bug500, discussion (missed optimization)"
:precision binary64
:herbie-target
(if (< (fabs x) 0.085) (* (* x x) (fma (fma (fma -2.6455026455026456e-5 (* x x) 0.0003527336860670194) (* x x) -0.005555555555555556) (* x x) 0.16666666666666666)) (log (/ (sinh x) x)))
(log (/ (sinh x) x)))