
(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 4 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 (- x (/ 0.5 x)))))
float code(float x) {
return logf((x + (x - (0.5f / x))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + (x - (0.5e0 / x))))
end function
function code(x) return log(Float32(x + Float32(x - Float32(Float32(0.5) / x)))) end
function tmp = code(x) tmp = log((x + (x - (single(0.5) / x)))); end
\begin{array}{l}
\\
\log \left(x + \left(x - \frac{0.5}{x}\right)\right)
\end{array}
Initial program 54.0%
Taylor expanded in x around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.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 54.0%
Taylor expanded in x around inf 97.6%
Final simplification97.6%
(FPCore (x) :precision binary32 (- (log1p -1.0)))
float code(float x) {
return -log1pf(-1.0f);
}
function code(x) return Float32(-log1p(Float32(-1.0))) end
\begin{array}{l}
\\
-\mathsf{log1p}\left(-1\right)
\end{array}
Initial program 54.0%
flip-+7.1%
div-inv7.0%
log-prod7.0%
add-sqr-sqrt7.0%
fma-neg7.0%
metadata-eval7.0%
fma-neg7.0%
metadata-eval7.0%
Applied egg-rr7.0%
fma-def7.0%
associate--r+9.6%
+-inverses10.2%
metadata-eval10.2%
metadata-eval10.2%
+-lft-identity10.2%
log-rec9.6%
Simplified9.6%
Taylor expanded in x around inf 97.5%
log1p-expm1-u16.4%
expm1-udef16.4%
add-exp-log16.4%
Applied egg-rr15.4%
Taylor expanded in x around inf 6.4%
Final simplification6.4%
(FPCore (x) :precision binary32 (/ (- 0.25) (* x x)))
float code(float x) {
return -0.25f / (x * x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = -0.25e0 / (x * x)
end function
function code(x) return Float32(Float32(-Float32(0.25)) / Float32(x * x)) end
function tmp = code(x) tmp = -single(0.25) / (x * x); end
\begin{array}{l}
\\
\frac{-0.25}{x \cdot x}
\end{array}
Initial program 54.0%
flip-+7.1%
div-inv7.0%
log-prod7.0%
add-sqr-sqrt7.0%
fma-neg7.0%
metadata-eval7.0%
fma-neg7.0%
metadata-eval7.0%
Applied egg-rr7.0%
fma-def7.0%
associate--r+9.6%
+-inverses10.2%
metadata-eval10.2%
metadata-eval10.2%
+-lft-identity10.2%
log-rec9.6%
Simplified9.6%
Taylor expanded in x around inf 97.7%
+-commutative97.7%
+-commutative97.7%
associate-+l+97.8%
unpow297.8%
associate-*r/97.8%
metadata-eval97.8%
log-prod98.7%
associate-*r/98.7%
metadata-eval98.7%
Simplified98.7%
log1p-expm1-u16.4%
expm1-udef16.4%
add-exp-log16.4%
Applied egg-rr16.4%
Taylor expanded in x around 0 5.4%
unpow25.4%
Simplified5.4%
Final simplification5.4%
(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 2023238
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:herbie-target
(log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0)))))
(log (+ x (sqrt (- (* x x) 1.0)))))