| Alternative 1 | |
|---|---|
| Accuracy | 53.2% |
| Cost | 320 |
\[\frac{x}{\frac{6}{x}}
\]

(FPCore (x) :precision binary64 (log (/ (sinh x) x)))
(FPCore (x) :precision binary64 (/ x (/ 6.0 x)))
double code(double x) {
return log((sinh(x) / x));
}
double code(double x) {
return x / (6.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((sinh(x) / x))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = x / (6.0d0 / x)
end function
public static double code(double x) {
return Math.log((Math.sinh(x) / x));
}
public static double code(double x) {
return x / (6.0 / x);
}
def code(x): return math.log((math.sinh(x) / x))
def code(x): return x / (6.0 / x)
function code(x) return log(Float64(sinh(x) / x)) end
function code(x) return Float64(x / Float64(6.0 / x)) end
function tmp = code(x) tmp = log((sinh(x) / x)); end
function tmp = code(x) tmp = x / (6.0 / x); end
code[x_] := N[Log[N[(N[Sinh[x], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
code[x_] := N[(x / N[(6.0 / x), $MachinePrecision]), $MachinePrecision]
\log \left(\frac{\sinh x}{x}\right)
\frac{x}{\frac{6}{x}}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 29.8% |
|---|---|
| Target | 53.1% |
| Herbie | 53.2% |
Initial program 32.6%
Taylor expanded in x around 0 55.8%
Simplified55.8%
[Start]55.8% | \[ 0.16666666666666666 \cdot {x}^{2}
\] |
|---|---|
unpow2 [=>]55.8% | \[ 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)}
\] |
Applied egg-rr55.8%
[Start]55.8% | \[ 0.16666666666666666 \cdot \left(x \cdot x\right)
\] |
|---|---|
add-sqr-sqrt [=>]55.7% | \[ \color{blue}{\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)} \cdot \sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}}
\] |
pow2 [=>]55.7% | \[ \color{blue}{{\left(\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)}^{2}}
\] |
*-commutative [=>]55.7% | \[ {\left(\sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}}\right)}^{2}
\] |
sqrt-prod [=>]55.8% | \[ {\color{blue}{\left(\sqrt{x \cdot x} \cdot \sqrt{0.16666666666666666}\right)}}^{2}
\] |
sqrt-prod [=>]26.9% | \[ {\left(\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
add-sqr-sqrt [<=]55.8% | \[ {\left(\color{blue}{x} \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
Applied egg-rr55.8%
[Start]55.8% | \[ {\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
|---|---|
add-sqr-sqrt [=>]55.8% | \[ \color{blue}{\sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} \cdot \sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}}}
\] |
unpow2 [=>]55.8% | \[ \sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} \cdot \sqrt{\color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)}}
\] |
sqrt-prod [=>]26.9% | \[ \sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} \cdot \color{blue}{\left(\sqrt{x \cdot \sqrt{0.16666666666666666}} \cdot \sqrt{x \cdot \sqrt{0.16666666666666666}}\right)}
\] |
add-sqr-sqrt [<=]40.2% | \[ \sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} \cdot \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right)}
\] |
associate-*r* [=>]40.2% | \[ \color{blue}{\left(\sqrt{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} \cdot x\right) \cdot \sqrt{0.16666666666666666}}
\] |
unpow2 [=>]40.2% | \[ \left(\sqrt{\color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)}} \cdot x\right) \cdot \sqrt{0.16666666666666666}
\] |
sqrt-prod [=>]26.9% | \[ \left(\color{blue}{\left(\sqrt{x \cdot \sqrt{0.16666666666666666}} \cdot \sqrt{x \cdot \sqrt{0.16666666666666666}}\right)} \cdot x\right) \cdot \sqrt{0.16666666666666666}
\] |
add-sqr-sqrt [<=]55.8% | \[ \left(\color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right)} \cdot x\right) \cdot \sqrt{0.16666666666666666}
\] |
Applied egg-rr55.9%
[Start]55.8% | \[ \left(\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot x\right) \cdot \sqrt{0.16666666666666666}
\] |
|---|---|
associate-*l* [=>]55.8% | \[ \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)}
\] |
swap-sqr [=>]55.8% | \[ \color{blue}{\left(x \cdot x\right) \cdot \left(\sqrt{0.16666666666666666} \cdot \sqrt{0.16666666666666666}\right)}
\] |
add-sqr-sqrt [<=]55.8% | \[ \left(x \cdot x\right) \cdot \color{blue}{0.16666666666666666}
\] |
metadata-eval [<=]55.8% | \[ \left(x \cdot x\right) \cdot \color{blue}{\frac{1}{6}}
\] |
div-inv [<=]55.8% | \[ \color{blue}{\frac{x \cdot x}{6}}
\] |
associate-/l* [=>]55.9% | \[ \color{blue}{\frac{x}{\frac{6}{x}}}
\] |
Final simplification55.9%
| Alternative 1 | |
|---|---|
| Accuracy | 53.2% |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Accuracy | 53.1% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 53.1% |
| Cost | 320 |
herbie shell --seed 2023272
(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)))