
(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 16 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 6.4e-27)
t_0
(/ 1.0 (fma k (+ (/ k t_0) (/ 10.0 t_0)) (/ 1.0 t_0))))))
double code(double a, double k, double m) {
double t_0 = a * pow(k, m);
double tmp;
if (k <= 6.4e-27) {
tmp = t_0;
} else {
tmp = 1.0 / fma(k, ((k / t_0) + (10.0 / t_0)), (1.0 / t_0));
}
return tmp;
}
function code(a, k, m) t_0 = Float64(a * (k ^ m)) tmp = 0.0 if (k <= 6.4e-27) tmp = t_0; else tmp = Float64(1.0 / fma(k, Float64(Float64(k / t_0) + Float64(10.0 / t_0)), Float64(1.0 / t_0))); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 6.4e-27], t$95$0, N[(1.0 / N[(k * N[(N[(k / t$95$0), $MachinePrecision] + N[(10.0 / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot {k}^{m}\\
\mathbf{if}\;k \leq 6.4 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(k, \frac{k}{t\_0} + \frac{10}{t\_0}, \frac{1}{t\_0}\right)}\\
\end{array}
\end{array}
if k < 6.39999999999999982e-27Initial program 95.9%
Taylor expanded in k around 0
lower-*.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
if 6.39999999999999982e-27 < k Initial program 82.3%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6482.4
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-+.f6482.4
Applied rewrites82.4%
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.3
Applied rewrites99.3%
(FPCore (a k m)
:precision binary64
(let* ((t_0 (/ (* a (pow k m)) (+ (* k k) (+ 1.0 (* k 10.0))))))
(if (<= t_0 4e-283)
(/ a (* k (+ k 10.0)))
(if (<= t_0 4e+287) (/ a (fma k 10.0 1.0)) (/ a (* k k))))))
double code(double a, double k, double m) {
double t_0 = (a * pow(k, m)) / ((k * k) + (1.0 + (k * 10.0)));
double tmp;
if (t_0 <= 4e-283) {
tmp = a / (k * (k + 10.0));
} else if (t_0 <= 4e+287) {
tmp = a / fma(k, 10.0, 1.0);
} else {
tmp = a / (k * k);
}
return tmp;
}
function code(a, k, m) t_0 = Float64(Float64(a * (k ^ m)) / Float64(Float64(k * k) + Float64(1.0 + Float64(k * 10.0)))) tmp = 0.0 if (t_0 <= 4e-283) tmp = Float64(a / Float64(k * Float64(k + 10.0))); elseif (t_0 <= 4e+287) tmp = Float64(a / fma(k, 10.0, 1.0)); else tmp = Float64(a / Float64(k * k)); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(k * k), $MachinePrecision] + N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e-283], N[(a / N[(k * N[(k + 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+287], N[(a / N[(k * 10.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(a / N[(k * k), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot {k}^{m}}{k \cdot k + \left(1 + k \cdot 10\right)}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{-283}:\\
\;\;\;\;\frac{a}{k \cdot \left(k + 10\right)}\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+287}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(k, 10, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{k \cdot k}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) < 3.99999999999999979e-283Initial program 97.3%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f6447.6
Applied rewrites47.6%
Taylor expanded in k around inf
Applied rewrites36.8%
if 3.99999999999999979e-283 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) < 4.0000000000000003e287Initial program 99.8%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f6497.0
Applied rewrites97.0%
Taylor expanded in k around 0
Applied rewrites71.0%
if 4.0000000000000003e287 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) Initial program 62.8%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f644.1
Applied rewrites4.1%
Taylor expanded in k around inf
Applied rewrites23.2%
Final simplification38.0%
herbie shell --seed 2024222
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))