
(FPCore (x) :precision binary32 (atanh x))
float code(float x) {
return atanhf(x);
}
function code(x) return atanh(x) end
function tmp = code(x) tmp = atanh(x); end
\begin{array}{l}
\\
\tanh^{-1} x
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
\end{array}
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* (+ x x) (+ x 1.0)) (- 1.0 (* x 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(x + x) * Float32(x + Float32(1.0))) / Float32(Float32(1.0) - Float32(x * x))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{\left(x + x\right) \cdot \left(x + 1\right)}{1 - x \cdot x}\right)
\end{array}
Initial program 99.8%
associate-/l*99.3%
Simplified99.3%
associate-/l*99.8%
flip--99.8%
associate-/r/99.8%
add-log-exp19.9%
*-commutative19.9%
exp-lft-sqr19.4%
log-prod19.4%
add-log-exp33.9%
add-log-exp99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*l/99.8%
+-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ 2.0 (/ (- 1.0 x) x)))))
float code(float x) {
return 0.5f * log1pf((2.0f / ((1.0f - x) / x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(2.0) / Float32(Float32(Float32(1.0) - x) / x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2}{\frac{1 - x}{x}}\right)
\end{array}
Initial program 99.8%
associate-/l*99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* x 2.0) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((x * 2.0f) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(x * Float32(2.0)) / Float32(Float32(1.0) - x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x \cdot 2}{1 - x}\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* 0.5 (+ x x)))
float code(float x) {
return 0.5f * (x + x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * (x + x)
end function
function code(x) return Float32(Float32(0.5) * Float32(x + x)) end
function tmp = code(x) tmp = single(0.5) * (x + x); end
\begin{array}{l}
\\
0.5 \cdot \left(x + x\right)
\end{array}
Initial program 99.8%
associate-/l*99.3%
Simplified99.3%
Taylor expanded in x around 0 95.0%
count-295.0%
Simplified95.0%
log1p-udef17.2%
Applied egg-rr17.2%
Taylor expanded in x around 0 98.2%
count-298.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x) :precision binary32 0.0)
float code(float x) {
return 0.0f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.0e0
end function
function code(x) return Float32(0.0) end
function tmp = code(x) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 99.8%
associate-/l*99.3%
Simplified99.3%
Taylor expanded in x around 0 95.0%
count-295.0%
Simplified95.0%
log1p-udef17.2%
Applied egg-rr17.2%
flip-+17.2%
div-inv17.1%
metadata-eval17.1%
flip-+-0.0%
+-inverses-0.0%
metadata-eval-0.0%
+-inverses-0.0%
metadata-eval-0.0%
associate-*r/-0.0%
metadata-eval-0.0%
+-inverses-0.0%
difference-of-squares-0.0%
metadata-eval-0.0%
+-inverses-0.0%
flip-+11.0%
log-prod11.7%
Applied egg-rr9.2%
log-div9.1%
metadata-eval9.1%
log1p-def11.0%
associate-+r-11.0%
+-rgt-identity11.0%
+-inverses11.0%
Simplified11.0%
Final simplification11.0%
herbie shell --seed 2023193
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))