
(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 (/ (* 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}
Initial program 99.7%
(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(x * Float32(Float32(2.0) / Float32(Float32(1.0) - x))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(x \cdot \frac{2}{1 - x}\right)
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
(FPCore (x) :precision binary32 (* x (+ 1.0 (* (* x x) (+ 0.3333333333333333 (* (* x x) 0.2))))))
float code(float x) {
return x * (1.0f + ((x * x) * (0.3333333333333333f + ((x * x) * 0.2f))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * (0.3333333333333333e0 + ((x * x) * 0.2e0))))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(0.2)))))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * (single(0.3333333333333333) + ((x * x) * single(0.2))))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.2\right)\right)
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 98.6%
*-commutative98.6%
Simplified98.6%
unpow298.6%
Applied egg-rr98.6%
unpow298.6%
Applied egg-rr98.6%
(FPCore (x) :precision binary32 (* x (+ 1.0 (* (* x x) 0.3333333333333333))))
float code(float x) {
return x * (1.0f + ((x * x) * 0.3333333333333333f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * 0.3333333333333333e0))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(0.3333333333333333)))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * single(0.3333333333333333))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot 0.3333333333333333\right)
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 98.2%
*-commutative98.2%
Simplified98.2%
unpow298.6%
Applied egg-rr98.2%
(FPCore (x) :precision binary32 x)
float code(float x) {
return x;
}
real(4) function code(x)
real(4), intent (in) :: x
code = x
end function
function code(x) return x end
function tmp = code(x) tmp = x; end
\begin{array}{l}
\\
x
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 95.6%
herbie shell --seed 2024110
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))