
(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 3.45e-10) t_0 (/ (/ t_0 k) k))))
double code(double a, double k, double m) {
double t_0 = a * pow(k, m);
double tmp;
if (k <= 3.45e-10) {
tmp = t_0;
} else {
tmp = (t_0 / k) / k;
}
return tmp;
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8) :: t_0
real(8) :: tmp
t_0 = a * (k ** m)
if (k <= 3.45d-10) then
tmp = t_0
else
tmp = (t_0 / k) / k
end if
code = tmp
end function
public static double code(double a, double k, double m) {
double t_0 = a * Math.pow(k, m);
double tmp;
if (k <= 3.45e-10) {
tmp = t_0;
} else {
tmp = (t_0 / k) / k;
}
return tmp;
}
def code(a, k, m): t_0 = a * math.pow(k, m) tmp = 0 if k <= 3.45e-10: tmp = t_0 else: tmp = (t_0 / k) / k return tmp
function code(a, k, m) t_0 = Float64(a * (k ^ m)) tmp = 0.0 if (k <= 3.45e-10) tmp = t_0; else tmp = Float64(Float64(t_0 / k) / k); end return tmp end
function tmp_2 = code(a, k, m) t_0 = a * (k ^ m); tmp = 0.0; if (k <= 3.45e-10) tmp = t_0; else tmp = (t_0 / k) / k; end tmp_2 = tmp; end
code[a_, k_, m_] := Block[{t$95$0 = N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 3.45e-10], t$95$0, N[(N[(t$95$0 / k), $MachinePrecision] / k), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot {k}^{m}\\
\mathbf{if}\;k \leq 3.45 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{k}}{k}\\
\end{array}
\end{array}
if k < 3.44999999999999998e-10Initial program 94.4%
Taylor expanded in k around 0
lower-*.f64N/A
lower-pow.f64100.0
Simplified100.0%
if 3.44999999999999998e-10 < k Initial program 85.4%
Taylor expanded in k around inf
unpow2N/A
lower-*.f6482.5
Simplified82.5%
lift-pow.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.0
Applied egg-rr97.0%
(FPCore (a k m)
:precision binary64
(let* ((t_0 (/ (* a (pow k m)) (+ (+ 1.0 (* k 10.0)) (* k k)))))
(if (<= t_0 0.0)
(/
a
(fma (* k (* k (fma k (/ 100.0 (* k k)) (- k)))) (/ 1.0 (- 10.0 k)) 1.0))
(if (<= t_0 1e+301)
(/ a (fma k 10.0 (fma k k 1.0)))
(if (<= t_0 INFINITY)
(/ (fma a (/ (+ -10.0 (/ 99.0 k)) k) a) (* k k))
(fma k (* a (fma 99.0 k -10.0)) a))))))
double code(double a, double k, double m) {
double t_0 = (a * pow(k, m)) / ((1.0 + (k * 10.0)) + (k * k));
double tmp;
if (t_0 <= 0.0) {
tmp = a / fma((k * (k * fma(k, (100.0 / (k * k)), -k))), (1.0 / (10.0 - k)), 1.0);
} else if (t_0 <= 1e+301) {
tmp = a / fma(k, 10.0, fma(k, k, 1.0));
} else if (t_0 <= ((double) INFINITY)) {
tmp = fma(a, ((-10.0 + (99.0 / k)) / k), a) / (k * k);
} else {
tmp = fma(k, (a * fma(99.0, k, -10.0)), a);
}
return tmp;
}
function code(a, k, m) t_0 = Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(k * 10.0)) + Float64(k * k))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(a / fma(Float64(k * Float64(k * fma(k, Float64(100.0 / Float64(k * k)), Float64(-k)))), Float64(1.0 / Float64(10.0 - k)), 1.0)); elseif (t_0 <= 1e+301) tmp = Float64(a / fma(k, 10.0, fma(k, k, 1.0))); elseif (t_0 <= Inf) tmp = Float64(fma(a, Float64(Float64(-10.0 + Float64(99.0 / k)) / k), a) / Float64(k * k)); else tmp = fma(k, Float64(a * fma(99.0, k, -10.0)), a); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(a / N[(N[(k * N[(k * N[(k * N[(100.0 / N[(k * k), $MachinePrecision]), $MachinePrecision] + (-k)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(10.0 - k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+301], N[(a / N[(k * 10.0 + N[(k * k + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(a * N[(N[(-10.0 + N[(99.0 / k), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision] + a), $MachinePrecision] / N[(k * k), $MachinePrecision]), $MachinePrecision], N[(k * N[(a * N[(99.0 * k + -10.0), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot {k}^{m}}{\left(1 + k \cdot 10\right) + k \cdot k}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(k \cdot \left(k \cdot \mathsf{fma}\left(k, \frac{100}{k \cdot k}, -k\right)\right), \frac{1}{10 - k}, 1\right)}\\
\mathbf{elif}\;t\_0 \leq 10^{+301}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(k, 10, \mathsf{fma}\left(k, k, 1\right)\right)}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{-10 + \frac{99}{k}}{k}, a\right)}{k \cdot k}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(k, a \cdot \mathsf{fma}\left(99, k, -10\right), a\right)\\
\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))) < 0.0Initial program 96.9%
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.4
Simplified47.4%
lift-+.f64N/A
*-commutativeN/A
lift-+.f64N/A
flip-+N/A
associate-*l/N/A
div-invN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lower--.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f6448.7
Applied egg-rr48.7%
Taylor expanded in k around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
neg-mul-1N/A
lower-neg.f6455.1
Simplified55.1%
if 0.0 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) < 1.00000000000000005e301Initial 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.3
Simplified97.3%
distribute-lft-inN/A
lift-*.f64N/A
associate-+r+N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f6497.3
Applied egg-rr97.3%
if 1.00000000000000005e301 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) < +inf.0Initial program 100.0%
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.3
Simplified4.3%
distribute-lft-inN/A
lift-*.f64N/A
associate-+r+N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f644.3
Applied egg-rr4.3%
Taylor expanded in k around inf
Simplified44.2%
if +inf.0 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) Initial program 0.0%
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-+.f642.0
Simplified2.0%
distribute-lft-inN/A
lift-*.f64N/A
associate-+r+N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f642.0
Applied egg-rr2.0%
Taylor expanded in k around 0
+-commutativeN/A
lower-fma.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
metadata-evalN/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fma.f6478.4
Simplified78.4%
Final simplification61.0%
herbie shell --seed 2024218
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))