Average Error: 0.1 → 0.0
Time: 6.2s
Precision: binary32
Cost: 6816
\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot \mathsf{fma}\left(x, x, x\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 (/ (* 2.0 (fma x x x)) (- 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(((2.0f * fmaf(x, x, x)) / (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(2.0) * fma(x, x, x)) / 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{2 \cdot \mathsf{fma}\left(x, x, x\right)}{1 - x \cdot x}\right)

Error

Derivation

  1. Initial program 0.1

    \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
  2. Applied egg-rr0.1

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot x}{1 - x \cdot x} \cdot \left(x + 1\right)}\right) \]
  3. Simplified0.0

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot \mathsf{fma}\left(x, x, x\right)}{1 - x \cdot x}}\right) \]
    Proof
    (/.f32 (*.f32 2 (fma.f32 x x x)) (-.f32 1 (*.f32 x x))): 0 points increase in error, 0 points decrease in error
    (/.f32 (Rewrite=> *-commutative_binary32 (*.f32 (fma.f32 x x x) 2)) (-.f32 1 (*.f32 x x))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-/l*_binary32 (/.f32 (fma.f32 x x x) (/.f32 (-.f32 1 (*.f32 x x)) 2))): 0 points increase in error, 0 points decrease in error
    (/.f32 (Rewrite=> fma-udef_binary32 (+.f32 (*.f32 x x) x)) (/.f32 (-.f32 1 (*.f32 x x)) 2)): 2 points increase in error, 0 points decrease in error
    (/.f32 (Rewrite=> distribute-lft1-in_binary32 (*.f32 (+.f32 x 1) x)) (/.f32 (-.f32 1 (*.f32 x x)) 2)): 8 points increase in error, 10 points decrease in error
    (Rewrite<= associate-*r/_binary32 (*.f32 (+.f32 x 1) (/.f32 x (/.f32 (-.f32 1 (*.f32 x x)) 2)))): 3 points increase in error, 5 points decrease in error
    (*.f32 (+.f32 x 1) (Rewrite<= associate-/l*_binary32 (/.f32 (*.f32 x 2) (-.f32 1 (*.f32 x x))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (+.f32 x 1) (/.f32 (Rewrite<= *-commutative_binary32 (*.f32 2 x)) (-.f32 1 (*.f32 x x)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary32 (*.f32 (/.f32 (*.f32 2 x) (-.f32 1 (*.f32 x x))) (+.f32 x 1))): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot \mathsf{fma}\left(x, x, x\right)}{1 - x \cdot x}\right) \]

Alternatives

Alternative 1
Error0.1
Cost3488
\[0.5 \cdot \mathsf{log1p}\left(x \cdot \frac{-2}{x + -1}\right) \]
Alternative 2
Error0.1
Cost3488
\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
Alternative 3
Error1.1
Cost160
\[0.5 \cdot \left(2 \cdot x\right) \]

Error

Reproduce

herbie shell --seed 2022328 
(FPCore (x)
  :name "Rust f32::atanh"
  :precision binary32
  (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))