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