
(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 8 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.8%
(FPCore (x)
:precision binary32
(+
x
(*
(* x x)
(*
x
(+
0.3333333333333333
(* x (* x (+ 0.2 (* (* x x) 0.14285714285714285)))))))))
float code(float x) {
return x + ((x * x) * (x * (0.3333333333333333f + (x * (x * (0.2f + ((x * x) * 0.14285714285714285f)))))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + ((x * x) * (x * (0.3333333333333333e0 + (x * (x * (0.2e0 + ((x * x) * 0.14285714285714285e0)))))))
end function
function code(x) return Float32(x + Float32(Float32(x * x) * Float32(x * Float32(Float32(0.3333333333333333) + Float32(x * Float32(x * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285))))))))) end
function tmp = code(x) tmp = x + ((x * x) * (x * (single(0.3333333333333333) + (x * (x * (single(0.2) + ((x * x) * single(0.14285714285714285)))))))); end
\begin{array}{l}
\\
x + \left(x \cdot x\right) \cdot \left(x \cdot \left(0.3333333333333333 + x \cdot \left(x \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
+-lowering-+.f32N/A
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x)
:precision binary32
(*
x
(+
1.0
(*
(* x x)
(+
0.3333333333333333
(* x (* x (+ 0.2 (* (* x x) 0.14285714285714285)))))))))
float code(float x) {
return x * (1.0f + ((x * x) * (0.3333333333333333f + (x * (x * (0.2f + ((x * x) * 0.14285714285714285f)))))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * (0.3333333333333333e0 + (x * (x * (0.2e0 + ((x * x) * 0.14285714285714285e0)))))))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(x * Float32(x * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285))))))))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * (single(0.3333333333333333) + (x * (x * (single(0.2) + ((x * x) * single(0.14285714285714285)))))))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(0.3333333333333333 + x \cdot \left(x \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
(FPCore (x) :precision binary32 (+ x (* (* x x) (* x (+ 0.3333333333333333 (* (* x x) 0.2))))))
float code(float x) {
return x + ((x * x) * (x * (0.3333333333333333f + ((x * x) * 0.2f))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + ((x * x) * (x * (0.3333333333333333e0 + ((x * x) * 0.2e0))))
end function
function code(x) return Float32(x + Float32(Float32(x * x) * Float32(x * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(0.2)))))) end
function tmp = code(x) tmp = x + ((x * x) * (x * (single(0.3333333333333333) + ((x * x) * single(0.2))))); end
\begin{array}{l}
\\
x + \left(x \cdot x\right) \cdot \left(x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.2\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.1%
Simplified99.1%
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
+-lowering-+.f32N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f3299.1%
Applied egg-rr99.1%
Final simplification99.1%
(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.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.1%
Simplified99.1%
(FPCore (x) :precision binary32 (+ x (* x (* x (* x 0.3333333333333333)))))
float code(float x) {
return x + (x * (x * (x * 0.3333333333333333f)));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + (x * (x * (x * 0.3333333333333333e0)))
end function
function code(x) return Float32(x + Float32(x * Float32(x * Float32(x * Float32(0.3333333333333333))))) end
function tmp = code(x) tmp = x + (x * (x * (x * single(0.3333333333333333)))); end
\begin{array}{l}
\\
x + x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3298.7%
Simplified98.7%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f3298.7%
Applied egg-rr98.7%
Final simplification98.7%
(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.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3298.7%
Simplified98.7%
Final simplification98.7%
(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.8%
Taylor expanded in x around 0
Simplified97.5%
herbie shell --seed 2024161
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))