| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 3680 |
\[0.5 \cdot \mathsf{log1p}\left(\frac{\left(x + x\right) \cdot \left(x + 1\right)}{1 - x \cdot x}\right)
\]

(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* (+ x x) (+ x 1.0)) (- 1.0 (* x x))))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
float code(float x) {
return 0.5f * log1pf((((x + x) * (x + 1.0f)) / (1.0f - (x * x))));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(x + x) * Float32(x + Float32(1.0))) / Float32(Float32(1.0) - Float32(x * x))))) end
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
0.5 \cdot \mathsf{log1p}\left(\frac{\left(x + x\right) \cdot \left(x + 1\right)}{1 - x \cdot x}\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.7%
Simplified99.2%
[Start]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
\] |
|---|---|
associate-/l* [=>]99.2% | \[ 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2}{\frac{1 - x}{x}}}\right)
\] |
Applied egg-rr99.7%
[Start]99.2% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2}{\frac{1 - x}{x}}\right)
\] |
|---|---|
associate-/l* [<=]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot x}{1 - x}}\right)
\] |
flip-- [=>]99.6% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{\frac{1 \cdot 1 - x \cdot x}{1 + x}}}\right)
\] |
associate-/r/ [=>]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot x}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)}\right)
\] |
add-log-exp [=>]24.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\color{blue}{\log \left(e^{2 \cdot x}\right)}}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
*-commutative [=>]24.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\log \left(e^{\color{blue}{x \cdot 2}}\right)}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
exp-lft-sqr [=>]24.0% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\log \color{blue}{\left(e^{x} \cdot e^{x}\right)}}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
log-prod [=>]24.0% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\color{blue}{\log \left(e^{x}\right) + \log \left(e^{x}\right)}}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
add-log-exp [<=]37.3% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\color{blue}{x} + \log \left(e^{x}\right)}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
add-log-exp [<=]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{x + \color{blue}{x}}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
metadata-eval [=>]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{x + x}{\color{blue}{1} - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
Simplified99.7%
[Start]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{x + x}{1 - x \cdot x} \cdot \left(1 + x\right)\right)
\] |
|---|---|
associate-*l/ [=>]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{\left(x + x\right) \cdot \left(1 + x\right)}{1 - x \cdot x}}\right)
\] |
+-commutative [=>]99.7% | \[ 0.5 \cdot \mathsf{log1p}\left(\frac{\left(x + x\right) \cdot \color{blue}{\left(x + 1\right)}}{1 - x \cdot x}\right)
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 3680 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 3488 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 3488 |
| Alternative 4 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 160 |
| Alternative 5 | |
|---|---|
| Accuracy | 10.8% |
| Cost | 32 |
herbie shell --seed 2023263
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))