| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 19712 |
\[\log \left(\frac{1 + \sqrt{\mathsf{fma}\left(x, -x, 1\right)}}{x}\right)
\]

(FPCore (x) :precision binary64 (log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))
(FPCore (x) :precision binary64 (log (/ (+ 1.0 (sqrt (fma x (- x) 1.0))) x)))
double code(double x) {
return log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
}
double code(double x) {
return log(((1.0 + sqrt(fma(x, -x, 1.0))) / x));
}
function code(x) return log(Float64(Float64(1.0 / x) + Float64(sqrt(Float64(1.0 - Float64(x * x))) / x))) end
function code(x) return log(Float64(Float64(1.0 + sqrt(fma(x, Float64(-x), 1.0))) / x)) end
code[x_] := N[Log[N[(N[(1.0 / x), $MachinePrecision] + N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Log[N[(N[(1.0 + N[Sqrt[N[(x * (-x) + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)
\begin{array}{l}
\\
\log \left(\frac{1 + \sqrt{\mathsf{fma}\left(x, -x, 1\right)}}{x}\right)
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 100.0%
Applied egg-rr100.0%
[Start]100.0% | \[ \log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)
\] |
|---|---|
expm1-log1p-u [=>]100.0% | \[ \log \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)\right)\right)}
\] |
expm1-udef [=>]100.0% | \[ \log \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} - 1\right)}
\] |
+-commutative [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{\sqrt{1 - x \cdot x}}{x} + \frac{1}{x}}\right)} - 1\right)
\] |
div-inv [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{1 - x \cdot x} \cdot \frac{1}{x}} + \frac{1}{x}\right)} - 1\right)
\] |
*-un-lft-identity [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\sqrt{1 - x \cdot x} \cdot \frac{1}{x} + \color{blue}{1 \cdot \frac{1}{x}}\right)} - 1\right)
\] |
distribute-rgt-out [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{1}{x} \cdot \left(\sqrt{1 - x \cdot x} + 1\right)}\right)} - 1\right)
\] |
cancel-sign-sub-inv [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\color{blue}{1 + \left(-x\right) \cdot x}} + 1\right)\right)} - 1\right)
\] |
+-commutative [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\color{blue}{\left(-x\right) \cdot x + 1}} + 1\right)\right)} - 1\right)
\] |
*-commutative [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\color{blue}{x \cdot \left(-x\right)} + 1} + 1\right)\right)} - 1\right)
\] |
fma-def [=>]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(x, -x, 1\right)}} + 1\right)\right)} - 1\right)
\] |
Simplified100.0%
[Start]100.0% | \[ \log \left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\mathsf{fma}\left(x, -x, 1\right)} + 1\right)\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]100.0% | \[ \log \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{\mathsf{fma}\left(x, -x, 1\right)} + 1\right)\right)\right)\right)}
\] |
expm1-log1p [=>]100.0% | \[ \log \color{blue}{\left(\frac{1}{x} \cdot \left(\sqrt{\mathsf{fma}\left(x, -x, 1\right)} + 1\right)\right)}
\] |
associate-*l/ [=>]100.0% | \[ \log \color{blue}{\left(\frac{1 \cdot \left(\sqrt{\mathsf{fma}\left(x, -x, 1\right)} + 1\right)}{x}\right)}
\] |
*-lft-identity [=>]100.0% | \[ \log \left(\frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, -x, 1\right)} + 1}}{x}\right)
\] |
+-commutative [<=]100.0% | \[ \log \left(\frac{\color{blue}{1 + \sqrt{\mathsf{fma}\left(x, -x, 1\right)}}}{x}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 19712 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 13504 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 6592 |
herbie shell --seed 2023167
(FPCore (x)
:name "Hyperbolic arc-(co)secant"
:precision binary64
(log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))