
(FPCore (x) :precision binary32 (acosh x))
float code(float x) {
return acoshf(x);
}
function code(x) return acosh(x) end
function tmp = code(x) tmp = acosh(x); end
\begin{array}{l}
\\
\cosh^{-1} x
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (log (+ x (sqrt (- (* x x) 1.0)))))
float code(float x) {
return logf((x + sqrtf(((x * x) - 1.0f))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + sqrt(((x * x) - 1.0e0))))
end function
function code(x) return log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0))))) end
function tmp = code(x) tmp = log((x + sqrt(((x * x) - single(1.0))))); end
\begin{array}{l}
\\
\log \left(x + \sqrt{x \cdot x - 1}\right)
\end{array}
(FPCore (x) :precision binary32 (log (+ x (* (sqrt (+ x 1.0)) (sqrt (+ x -1.0))))))
float code(float x) {
return logf((x + (sqrtf((x + 1.0f)) * sqrtf((x + -1.0f)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + (sqrt((x + 1.0e0)) * sqrt((x + (-1.0e0))))))
end function
function code(x) return log(Float32(x + Float32(sqrt(Float32(x + Float32(1.0))) * sqrt(Float32(x + Float32(-1.0)))))) end
function tmp = code(x) tmp = log((x + (sqrt((x + single(1.0))) * sqrt((x + single(-1.0)))))); end
\begin{array}{l}
\\
\log \left(x + \sqrt{x + 1} \cdot \sqrt{x + -1}\right)
\end{array}
Initial program 51.4%
pow1/251.4%
difference-of-sqr-151.4%
unpow-prod-down99.2%
sub-neg99.2%
metadata-eval99.2%
Applied egg-rr99.2%
unpow1/299.2%
unpow1/299.2%
Simplified99.2%
(FPCore (x) :precision binary32 (log (* x (- 2.0 (/ 0.5 (* x x))))))
float code(float x) {
return logf((x * (2.0f - (0.5f / (x * x)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x * (2.0e0 - (0.5e0 / (x * x)))))
end function
function code(x) return log(Float32(x * Float32(Float32(2.0) - Float32(Float32(0.5) / Float32(x * x))))) end
function tmp = code(x) tmp = log((x * (single(2.0) - (single(0.5) / (x * x))))); end
\begin{array}{l}
\\
\log \left(x \cdot \left(2 - \frac{0.5}{x \cdot x}\right)\right)
\end{array}
Initial program 51.4%
Taylor expanded in x around inf 98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
unpow298.4%
Applied egg-rr98.4%
(FPCore (x) :precision binary32 (log (+ (/ x 0.5) (/ -0.5 x))))
float code(float x) {
return logf(((x / 0.5f) + (-0.5f / x)));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log(((x / 0.5e0) + ((-0.5e0) / x)))
end function
function code(x) return log(Float32(Float32(x / Float32(0.5)) + Float32(Float32(-0.5) / x))) end
function tmp = code(x) tmp = log(((x / single(0.5)) + (single(-0.5) / x))); end
\begin{array}{l}
\\
\log \left(\frac{x}{0.5} + \frac{-0.5}{x}\right)
\end{array}
Initial program 51.4%
Taylor expanded in x around inf 98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
unpow298.4%
Applied egg-rr98.4%
sub-neg98.4%
distribute-lft-in98.4%
metadata-eval98.4%
div-inv98.4%
add-cbrt-cube35.9%
cbrt-prod50.5%
associate-/l*50.5%
fma-define50.5%
cbrt-prod98.4%
pow298.4%
div-inv98.4%
distribute-lft-neg-in98.4%
metadata-eval98.4%
pow298.4%
pow-flip98.4%
metadata-eval98.4%
Applied egg-rr98.4%
fma-undefine98.4%
associate-*r/98.4%
unpow298.4%
rem-3cbrt-lft98.4%
*-commutative98.4%
associate-*l*98.4%
metadata-eval98.4%
pow-plus98.4%
metadata-eval98.4%
unpow-198.4%
distribute-lft-neg-in98.4%
associate-*r/98.4%
metadata-eval98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
(FPCore (x) :precision binary32 (- (log (/ 0.5 x))))
float code(float x) {
return -logf((0.5f / x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = -log((0.5e0 / x))
end function
function code(x) return Float32(-log(Float32(Float32(0.5) / x))) end
function tmp = code(x) tmp = -log((single(0.5) / x)); end
\begin{array}{l}
\\
-\log \left(\frac{0.5}{x}\right)
\end{array}
Initial program 51.4%
flip-+7.0%
div-inv7.0%
log-prod7.0%
pow27.0%
add-sqr-sqrt7.0%
fmm-def7.0%
metadata-eval7.0%
fmm-def7.0%
metadata-eval7.0%
Applied egg-rr7.0%
log-rec7.0%
sub-neg7.0%
fma-undefine7.0%
unpow27.0%
associate--r+9.4%
+-inverses9.4%
metadata-eval9.4%
metadata-eval9.4%
neg-sub09.4%
Simplified9.4%
Taylor expanded in x around inf 97.8%
(FPCore (x) :precision binary32 (log (+ x x)))
float code(float x) {
return logf((x + x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + x))
end function
function code(x) return log(Float32(x + x)) end
function tmp = code(x) tmp = log((x + x)); end
\begin{array}{l}
\\
\log \left(x + x\right)
\end{array}
Initial program 51.4%
Taylor expanded in x around inf 97.1%
(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 51.4%
Taylor expanded in x around inf 97.1%
flip-+-0.0%
log-div-0.0%
unpow20.0%
unpow2-0.0%
+-inverses-0.0%
+-inverses-0.0%
Applied egg-rr-0.0%
+-inverses6.1%
Simplified6.1%
(FPCore (x) :precision binary32 (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0))))))
float code(float x) {
return logf((x + (sqrtf((x - 1.0f)) * sqrtf((x + 1.0f)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + (sqrt((x - 1.0e0)) * sqrt((x + 1.0e0)))))
end function
function code(x) return log(Float32(x + Float32(sqrt(Float32(x - Float32(1.0))) * sqrt(Float32(x + Float32(1.0)))))) end
function tmp = code(x) tmp = log((x + (sqrt((x - single(1.0))) * sqrt((x + single(1.0)))))); end
\begin{array}{l}
\\
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right)
\end{array}
herbie shell --seed 2024180
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:alt
(! :herbie-platform default (log (+ x (* (sqrt (- x 1)) (sqrt (+ x 1))))))
(log (+ x (sqrt (- (* x x) 1.0)))))