
(FPCore (a k m) :precision binary64 (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))
double code(double a, double k, double m) {
return (a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = (a * (k ** m)) / ((1.0d0 + (10.0d0 * k)) + (k * k))
end function
public static double code(double a, double k, double m) {
return (a * Math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
def code(a, k, m): return (a * math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))
function code(a, k, m) return Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) end
function tmp = code(a, k, m) tmp = (a * (k ^ m)) / ((1.0 + (10.0 * k)) + (k * k)); end
code[a_, k_, m_] := N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a k m) :precision binary64 (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))
double code(double a, double k, double m) {
return (a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = (a * (k ** m)) / ((1.0d0 + (10.0d0 * k)) + (k * k))
end function
public static double code(double a, double k, double m) {
return (a * Math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
def code(a, k, m): return (a * math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))
function code(a, k, m) return Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) end
function tmp = code(a, k, m) tmp = (a * (k ^ m)) / ((1.0 + (10.0 * k)) + (k * k)); end
code[a_, k_, m_] := N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\end{array}
(FPCore (a k m)
:precision binary64
(let* ((t_0 (* a (pow k m))))
(if (<= k 1e-160)
t_0
(if (<= k 3e+23)
(/ 1.0 (/ (fma k (+ k 10.0) 1.0) t_0))
(/ 1.0 (* k (* k (/ (pow (/ 1.0 k) m) a))))))))
double code(double a, double k, double m) {
double t_0 = a * pow(k, m);
double tmp;
if (k <= 1e-160) {
tmp = t_0;
} else if (k <= 3e+23) {
tmp = 1.0 / (fma(k, (k + 10.0), 1.0) / t_0);
} else {
tmp = 1.0 / (k * (k * (pow((1.0 / k), m) / a)));
}
return tmp;
}
function code(a, k, m) t_0 = Float64(a * (k ^ m)) tmp = 0.0 if (k <= 1e-160) tmp = t_0; elseif (k <= 3e+23) tmp = Float64(1.0 / Float64(fma(k, Float64(k + 10.0), 1.0) / t_0)); else tmp = Float64(1.0 / Float64(k * Float64(k * Float64((Float64(1.0 / k) ^ m) / a)))); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 1e-160], t$95$0, If[LessEqual[k, 3e+23], N[(1.0 / N[(N[(k * N[(k + 10.0), $MachinePrecision] + 1.0), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(k * N[(k * N[(N[Power[N[(1.0 / k), $MachinePrecision], m], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot {k}^{m}\\
\mathbf{if}\;k \leq 10^{-160}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;k \leq 3 \cdot 10^{+23}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(k, k + 10, 1\right)}{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{k \cdot \left(k \cdot \frac{{\left(\frac{1}{k}\right)}^{m}}{a}\right)}\\
\end{array}
\end{array}
if k < 9.9999999999999999e-161Initial program 93.8%
Taylor expanded in k around 0
lower-*.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
if 9.9999999999999999e-161 < k < 3.0000000000000001e23Initial program 99.8%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6499.9
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
if 3.0000000000000001e23 < k Initial program 80.7%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6480.7
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f6480.7
Applied rewrites80.7%
Taylor expanded in k around 0
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in k around inf
Applied rewrites99.9%
Final simplification99.9%
(FPCore (a k m) :precision binary64 (let* ((t_0 (/ (pow k (- m)) a))) (if (<= k 1e-160) (* a (pow k m)) (/ 1.0 (fma (* t_0 (+ k 10.0)) k t_0)))))
double code(double a, double k, double m) {
double t_0 = pow(k, -m) / a;
double tmp;
if (k <= 1e-160) {
tmp = a * pow(k, m);
} else {
tmp = 1.0 / fma((t_0 * (k + 10.0)), k, t_0);
}
return tmp;
}
function code(a, k, m) t_0 = Float64((k ^ Float64(-m)) / a) tmp = 0.0 if (k <= 1e-160) tmp = Float64(a * (k ^ m)); else tmp = Float64(1.0 / fma(Float64(t_0 * Float64(k + 10.0)), k, t_0)); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(N[Power[k, (-m)], $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[k, 1e-160], N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(t$95$0 * N[(k + 10.0), $MachinePrecision]), $MachinePrecision] * k + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{k}^{\left(-m\right)}}{a}\\
\mathbf{if}\;k \leq 10^{-160}:\\
\;\;\;\;a \cdot {k}^{m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(t\_0 \cdot \left(k + 10\right), k, t\_0\right)}\\
\end{array}
\end{array}
if k < 9.9999999999999999e-161Initial program 93.2%
Taylor expanded in k around 0
lower-*.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
if 9.9999999999999999e-161 < k Initial program 88.2%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6488.0
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f6488.0
Applied rewrites88.0%
Taylor expanded in k around 0
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f6499.6
Applied rewrites99.6%
Applied rewrites99.5%
herbie shell --seed 2024228
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))