| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6976 |
\[\log \left(x \cdot -0.5 + 2 \cdot \frac{1}{x}\right)
\]

(FPCore (x) :precision binary64 (log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))
(FPCore (x) :precision binary64 (log1p (+ -1.0 (/ (+ 1.0 (sqrt (- 1.0 (* x x)))) x))))
double code(double x) {
return log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
}
double code(double x) {
return log1p((-1.0 + ((1.0 + sqrt((1.0 - (x * x)))) / x)));
}
public static double code(double x) {
return Math.log(((1.0 / x) + (Math.sqrt((1.0 - (x * x))) / x)));
}
public static double code(double x) {
return Math.log1p((-1.0 + ((1.0 + Math.sqrt((1.0 - (x * x)))) / x)));
}
def code(x): return math.log(((1.0 / x) + (math.sqrt((1.0 - (x * x))) / x)))
def code(x): return math.log1p((-1.0 + ((1.0 + math.sqrt((1.0 - (x * x)))) / 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 log1p(Float64(-1.0 + Float64(Float64(1.0 + sqrt(Float64(1.0 - Float64(x * x)))) / 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[1 + N[(-1.0 + N[(N[(1.0 + N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)
\mathsf{log1p}\left(-1 + \frac{1 + \sqrt{1 - x \cdot x}}{x}\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 100.0%
Applied egg-rr100.0%
[Start]100.0 | \[ \log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)
\] |
|---|---|
log1p-expm1-u [=>]100.0 | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)\right)\right)}
\] |
expm1-udef [=>]100.0 | \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} - 1}\right)
\] |
add-exp-log [<=]100.0 | \[ \mathsf{log1p}\left(\color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} - 1\right)
\] |
*-un-lft-identity [=>]100.0 | \[ \mathsf{log1p}\left(\left(\color{blue}{1 \cdot \frac{1}{x}} + \frac{\sqrt{1 - x \cdot x}}{x}\right) - 1\right)
\] |
div-inv [=>]100.0 | \[ \mathsf{log1p}\left(\left(1 \cdot \frac{1}{x} + \color{blue}{\sqrt{1 - x \cdot x} \cdot \frac{1}{x}}\right) - 1\right)
\] |
distribute-rgt-out [=>]100.0 | \[ \mathsf{log1p}\left(\color{blue}{\frac{1}{x} \cdot \left(1 + \sqrt{1 - x \cdot x}\right)} - 1\right)
\] |
fma-neg [=>]100.0 | \[ \mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{x}, 1 + \sqrt{1 - x \cdot x}, -1\right)}\right)
\] |
inv-pow [=>]100.0 | \[ \mathsf{log1p}\left(\mathsf{fma}\left(\color{blue}{{x}^{-1}}, 1 + \sqrt{1 - x \cdot x}, -1\right)\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{-1}, 1 + \sqrt{1 - x \cdot x}, \color{blue}{-1}\right)\right)
\] |
Simplified100.0%
[Start]100.0 | \[ \mathsf{log1p}\left(\mathsf{fma}\left({x}^{-1}, 1 + \sqrt{1 - x \cdot x}, -1\right)\right)
\] |
|---|---|
fma-udef [=>]100.0 | \[ \mathsf{log1p}\left(\color{blue}{{x}^{-1} \cdot \left(1 + \sqrt{1 - x \cdot x}\right) + -1}\right)
\] |
+-commutative [=>]100.0 | \[ \mathsf{log1p}\left(\color{blue}{-1 + {x}^{-1} \cdot \left(1 + \sqrt{1 - x \cdot x}\right)}\right)
\] |
+-commutative [<=]100.0 | \[ \mathsf{log1p}\left(-1 + {x}^{-1} \cdot \color{blue}{\left(\sqrt{1 - x \cdot x} + 1\right)}\right)
\] |
*-commutative [<=]100.0 | \[ \mathsf{log1p}\left(-1 + \color{blue}{\left(\sqrt{1 - x \cdot x} + 1\right) \cdot {x}^{-1}}\right)
\] |
unpow-1 [=>]100.0 | \[ \mathsf{log1p}\left(-1 + \left(\sqrt{1 - x \cdot x} + 1\right) \cdot \color{blue}{\frac{1}{x}}\right)
\] |
associate-*r/ [=>]100.0 | \[ \mathsf{log1p}\left(-1 + \color{blue}{\frac{\left(\sqrt{1 - x \cdot x} + 1\right) \cdot 1}{x}}\right)
\] |
distribute-rgt1-in [<=]100.0 | \[ \mathsf{log1p}\left(-1 + \frac{\color{blue}{1 + \sqrt{1 - x \cdot x} \cdot 1}}{x}\right)
\] |
*-rgt-identity [=>]100.0 | \[ \mathsf{log1p}\left(-1 + \frac{1 + \color{blue}{\sqrt{1 - x \cdot x}}}{x}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6976 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 6656 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 6592 |
herbie shell --seed 2023160
(FPCore (x)
:name "Hyperbolic arc-(co)secant"
:precision binary64
(log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))