
(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 7 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 (+ 1.0 (* k (+ k 10.0)))))
(if (<= m -4.6e-9)
(* a (/ (pow k m) t_0))
(if (<= m 0.8) (/ a t_0) (* a (pow k m))))))
double code(double a, double k, double m) {
double t_0 = 1.0 + (k * (k + 10.0));
double tmp;
if (m <= -4.6e-9) {
tmp = a * (pow(k, m) / t_0);
} else if (m <= 0.8) {
tmp = a / t_0;
} else {
tmp = a * pow(k, m);
}
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 = 1.0d0 + (k * (k + 10.0d0))
if (m <= (-4.6d-9)) then
tmp = a * ((k ** m) / t_0)
else if (m <= 0.8d0) then
tmp = a / t_0
else
tmp = a * (k ** m)
end if
code = tmp
end function
public static double code(double a, double k, double m) {
double t_0 = 1.0 + (k * (k + 10.0));
double tmp;
if (m <= -4.6e-9) {
tmp = a * (Math.pow(k, m) / t_0);
} else if (m <= 0.8) {
tmp = a / t_0;
} else {
tmp = a * Math.pow(k, m);
}
return tmp;
}
def code(a, k, m): t_0 = 1.0 + (k * (k + 10.0)) tmp = 0 if m <= -4.6e-9: tmp = a * (math.pow(k, m) / t_0) elif m <= 0.8: tmp = a / t_0 else: tmp = a * math.pow(k, m) return tmp
function code(a, k, m) t_0 = Float64(1.0 + Float64(k * Float64(k + 10.0))) tmp = 0.0 if (m <= -4.6e-9) tmp = Float64(a * Float64((k ^ m) / t_0)); elseif (m <= 0.8) tmp = Float64(a / t_0); else tmp = Float64(a * (k ^ m)); end return tmp end
function tmp_2 = code(a, k, m) t_0 = 1.0 + (k * (k + 10.0)); tmp = 0.0; if (m <= -4.6e-9) tmp = a * ((k ^ m) / t_0); elseif (m <= 0.8) tmp = a / t_0; else tmp = a * (k ^ m); end tmp_2 = tmp; end
code[a_, k_, m_] := Block[{t$95$0 = N[(1.0 + N[(k * N[(k + 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, -4.6e-9], N[(a * N[(N[Power[k, m], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 0.8], N[(a / t$95$0), $MachinePrecision], N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + k \cdot \left(k + 10\right)\\
\mathbf{if}\;m \leq -4.6 \cdot 10^{-9}:\\
\;\;\;\;a \cdot \frac{{k}^{m}}{t\_0}\\
\mathbf{elif}\;m \leq 0.8:\\
\;\;\;\;\frac{a}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;a \cdot {k}^{m}\\
\end{array}
\end{array}
if m < -4.5999999999999998e-9Initial program 97.3%
associate-/l*97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
distribute-neg-frac297.3%
remove-double-neg97.3%
sqr-neg97.3%
associate-+l+97.3%
sqr-neg97.3%
distribute-rgt-out97.3%
Simplified97.3%
if -4.5999999999999998e-9 < m < 0.80000000000000004Initial program 82.0%
associate-/l*81.9%
remove-double-neg81.9%
distribute-frac-neg281.9%
distribute-neg-frac281.9%
remove-double-neg81.9%
sqr-neg81.9%
associate-+l+81.9%
sqr-neg81.9%
distribute-rgt-out81.9%
Simplified81.9%
Taylor expanded in m around 0 97.2%
if 0.80000000000000004 < m Initial program 75.0%
associate-/l*75.0%
remove-double-neg75.0%
distribute-frac-neg275.0%
distribute-neg-frac275.0%
remove-double-neg75.0%
sqr-neg75.0%
associate-+l+75.0%
sqr-neg75.0%
distribute-rgt-out75.0%
Simplified75.0%
Taylor expanded in k around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification98.1%
(FPCore (a k m) :precision binary64 (if (or (<= m -2.5e+16) (not (<= m 0.135))) (* a (pow k m)) (/ a (+ 1.0 (* k (+ k 10.0))))))
double code(double a, double k, double m) {
double tmp;
if ((m <= -2.5e+16) || !(m <= 0.135)) {
tmp = a * pow(k, m);
} else {
tmp = a / (1.0 + (k * (k + 10.0)));
}
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) :: tmp
if ((m <= (-2.5d+16)) .or. (.not. (m <= 0.135d0))) then
tmp = a * (k ** m)
else
tmp = a / (1.0d0 + (k * (k + 10.0d0)))
end if
code = tmp
end function
public static double code(double a, double k, double m) {
double tmp;
if ((m <= -2.5e+16) || !(m <= 0.135)) {
tmp = a * Math.pow(k, m);
} else {
tmp = a / (1.0 + (k * (k + 10.0)));
}
return tmp;
}
def code(a, k, m): tmp = 0 if (m <= -2.5e+16) or not (m <= 0.135): tmp = a * math.pow(k, m) else: tmp = a / (1.0 + (k * (k + 10.0))) return tmp
function code(a, k, m) tmp = 0.0 if ((m <= -2.5e+16) || !(m <= 0.135)) tmp = Float64(a * (k ^ m)); else tmp = Float64(a / Float64(1.0 + Float64(k * Float64(k + 10.0)))); end return tmp end
function tmp_2 = code(a, k, m) tmp = 0.0; if ((m <= -2.5e+16) || ~((m <= 0.135))) tmp = a * (k ^ m); else tmp = a / (1.0 + (k * (k + 10.0))); end tmp_2 = tmp; end
code[a_, k_, m_] := If[Or[LessEqual[m, -2.5e+16], N[Not[LessEqual[m, 0.135]], $MachinePrecision]], N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision], N[(a / N[(1.0 + N[(k * N[(k + 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -2.5 \cdot 10^{+16} \lor \neg \left(m \leq 0.135\right):\\
\;\;\;\;a \cdot {k}^{m}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{1 + k \cdot \left(k + 10\right)}\\
\end{array}
\end{array}
if m < -2.5e16 or 0.13500000000000001 < m Initial program 87.0%
associate-/l*87.0%
remove-double-neg87.0%
distribute-frac-neg287.0%
distribute-neg-frac287.0%
remove-double-neg87.0%
sqr-neg87.0%
associate-+l+87.0%
sqr-neg87.0%
distribute-rgt-out87.0%
Simplified87.0%
Taylor expanded in k around 0 100.0%
*-commutative100.0%
Simplified100.0%
if -2.5e16 < m < 0.13500000000000001Initial program 80.9%
associate-/l*80.9%
remove-double-neg80.9%
distribute-frac-neg280.9%
distribute-neg-frac280.9%
remove-double-neg80.9%
sqr-neg80.9%
associate-+l+80.9%
sqr-neg80.9%
distribute-rgt-out80.9%
Simplified80.9%
Taylor expanded in m around 0 95.1%
Final simplification97.9%
(FPCore (a k m) :precision binary64 (if (<= m 2.2) (/ a (+ 1.0 (* k k))) (* a (+ 1.0 (* k (* k 99.0))))))
double code(double a, double k, double m) {
double tmp;
if (m <= 2.2) {
tmp = a / (1.0 + (k * k));
} else {
tmp = a * (1.0 + (k * (k * 99.0)));
}
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) :: tmp
if (m <= 2.2d0) then
tmp = a / (1.0d0 + (k * k))
else
tmp = a * (1.0d0 + (k * (k * 99.0d0)))
end if
code = tmp
end function
public static double code(double a, double k, double m) {
double tmp;
if (m <= 2.2) {
tmp = a / (1.0 + (k * k));
} else {
tmp = a * (1.0 + (k * (k * 99.0)));
}
return tmp;
}
def code(a, k, m): tmp = 0 if m <= 2.2: tmp = a / (1.0 + (k * k)) else: tmp = a * (1.0 + (k * (k * 99.0))) return tmp
function code(a, k, m) tmp = 0.0 if (m <= 2.2) tmp = Float64(a / Float64(1.0 + Float64(k * k))); else tmp = Float64(a * Float64(1.0 + Float64(k * Float64(k * 99.0)))); end return tmp end
function tmp_2 = code(a, k, m) tmp = 0.0; if (m <= 2.2) tmp = a / (1.0 + (k * k)); else tmp = a * (1.0 + (k * (k * 99.0))); end tmp_2 = tmp; end
code[a_, k_, m_] := If[LessEqual[m, 2.2], N[(a / N[(1.0 + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(1.0 + N[(k * N[(k * 99.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 2.2:\\
\;\;\;\;\frac{a}{1 + k \cdot k}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(1 + k \cdot \left(k \cdot 99\right)\right)\\
\end{array}
\end{array}
if m < 2.2000000000000002Initial program 88.4%
associate-/l*88.3%
remove-double-neg88.3%
distribute-frac-neg288.3%
distribute-neg-frac288.3%
remove-double-neg88.3%
sqr-neg88.3%
associate-+l+88.3%
sqr-neg88.3%
distribute-rgt-out88.3%
Simplified88.3%
Taylor expanded in m around 0 70.5%
Taylor expanded in k around inf 70.4%
unpow270.4%
Applied egg-rr70.4%
if 2.2000000000000002 < m Initial program 75.0%
associate-/l*75.0%
remove-double-neg75.0%
distribute-frac-neg275.0%
distribute-neg-frac275.0%
remove-double-neg75.0%
sqr-neg75.0%
associate-+l+75.0%
sqr-neg75.0%
distribute-rgt-out75.0%
Simplified75.0%
Taylor expanded in m around 0 3.1%
Taylor expanded in k around 0 14.1%
Taylor expanded in k around 0 38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in k around inf 38.1%
*-commutative38.1%
Simplified38.1%
Final simplification60.8%
(FPCore (a k m) :precision binary64 (if (<= m 1.7) (/ a (+ 1.0 (* k (+ k 10.0)))) (* a (+ 1.0 (* k (* k 99.0))))))
double code(double a, double k, double m) {
double tmp;
if (m <= 1.7) {
tmp = a / (1.0 + (k * (k + 10.0)));
} else {
tmp = a * (1.0 + (k * (k * 99.0)));
}
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) :: tmp
if (m <= 1.7d0) then
tmp = a / (1.0d0 + (k * (k + 10.0d0)))
else
tmp = a * (1.0d0 + (k * (k * 99.0d0)))
end if
code = tmp
end function
public static double code(double a, double k, double m) {
double tmp;
if (m <= 1.7) {
tmp = a / (1.0 + (k * (k + 10.0)));
} else {
tmp = a * (1.0 + (k * (k * 99.0)));
}
return tmp;
}
def code(a, k, m): tmp = 0 if m <= 1.7: tmp = a / (1.0 + (k * (k + 10.0))) else: tmp = a * (1.0 + (k * (k * 99.0))) return tmp
function code(a, k, m) tmp = 0.0 if (m <= 1.7) tmp = Float64(a / Float64(1.0 + Float64(k * Float64(k + 10.0)))); else tmp = Float64(a * Float64(1.0 + Float64(k * Float64(k * 99.0)))); end return tmp end
function tmp_2 = code(a, k, m) tmp = 0.0; if (m <= 1.7) tmp = a / (1.0 + (k * (k + 10.0))); else tmp = a * (1.0 + (k * (k * 99.0))); end tmp_2 = tmp; end
code[a_, k_, m_] := If[LessEqual[m, 1.7], N[(a / N[(1.0 + N[(k * N[(k + 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(1.0 + N[(k * N[(k * 99.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.7:\\
\;\;\;\;\frac{a}{1 + k \cdot \left(k + 10\right)}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(1 + k \cdot \left(k \cdot 99\right)\right)\\
\end{array}
\end{array}
if m < 1.69999999999999996Initial program 88.4%
associate-/l*88.3%
remove-double-neg88.3%
distribute-frac-neg288.3%
distribute-neg-frac288.3%
remove-double-neg88.3%
sqr-neg88.3%
associate-+l+88.3%
sqr-neg88.3%
distribute-rgt-out88.3%
Simplified88.3%
Taylor expanded in m around 0 70.5%
if 1.69999999999999996 < m Initial program 75.0%
associate-/l*75.0%
remove-double-neg75.0%
distribute-frac-neg275.0%
distribute-neg-frac275.0%
remove-double-neg75.0%
sqr-neg75.0%
associate-+l+75.0%
sqr-neg75.0%
distribute-rgt-out75.0%
Simplified75.0%
Taylor expanded in m around 0 3.1%
Taylor expanded in k around 0 14.1%
Taylor expanded in k around 0 38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in k around inf 38.1%
*-commutative38.1%
Simplified38.1%
Final simplification60.9%
(FPCore (a k m) :precision binary64 (/ a (+ 1.0 (* k 10.0))))
double code(double a, double k, double m) {
return a / (1.0 + (k * 10.0));
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = a / (1.0d0 + (k * 10.0d0))
end function
public static double code(double a, double k, double m) {
return a / (1.0 + (k * 10.0));
}
def code(a, k, m): return a / (1.0 + (k * 10.0))
function code(a, k, m) return Float64(a / Float64(1.0 + Float64(k * 10.0))) end
function tmp = code(a, k, m) tmp = a / (1.0 + (k * 10.0)); end
code[a_, k_, m_] := N[(a / N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{1 + k \cdot 10}
\end{array}
Initial program 84.4%
associate-/l*84.4%
remove-double-neg84.4%
distribute-frac-neg284.4%
distribute-neg-frac284.4%
remove-double-neg84.4%
sqr-neg84.4%
associate-+l+84.4%
sqr-neg84.4%
distribute-rgt-out84.4%
Simplified84.4%
Taylor expanded in m around 0 50.5%
Taylor expanded in k around 0 32.4%
*-commutative32.4%
Simplified32.4%
Final simplification32.4%
(FPCore (a k m) :precision binary64 (/ a (+ 1.0 (* k k))))
double code(double a, double k, double m) {
return a / (1.0 + (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 / (1.0d0 + (k * k))
end function
public static double code(double a, double k, double m) {
return a / (1.0 + (k * k));
}
def code(a, k, m): return a / (1.0 + (k * k))
function code(a, k, m) return Float64(a / Float64(1.0 + Float64(k * k))) end
function tmp = code(a, k, m) tmp = a / (1.0 + (k * k)); end
code[a_, k_, m_] := N[(a / N[(1.0 + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{1 + k \cdot k}
\end{array}
Initial program 84.4%
associate-/l*84.4%
remove-double-neg84.4%
distribute-frac-neg284.4%
distribute-neg-frac284.4%
remove-double-neg84.4%
sqr-neg84.4%
associate-+l+84.4%
sqr-neg84.4%
distribute-rgt-out84.4%
Simplified84.4%
Taylor expanded in m around 0 50.5%
Taylor expanded in k around inf 50.4%
unpow250.4%
Applied egg-rr50.4%
Final simplification50.4%
(FPCore (a k m) :precision binary64 a)
double code(double a, double k, double m) {
return a;
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = a
end function
public static double code(double a, double k, double m) {
return a;
}
def code(a, k, m): return a
function code(a, k, m) return a end
function tmp = code(a, k, m) tmp = a; end
code[a_, k_, m_] := a
\begin{array}{l}
\\
a
\end{array}
Initial program 84.4%
associate-/l*84.4%
remove-double-neg84.4%
distribute-frac-neg284.4%
distribute-neg-frac284.4%
remove-double-neg84.4%
sqr-neg84.4%
associate-+l+84.4%
sqr-neg84.4%
distribute-rgt-out84.4%
Simplified84.4%
Taylor expanded in k around 0 76.1%
*-commutative76.1%
Simplified76.1%
add-cube-cbrt75.8%
pow375.8%
Applied egg-rr75.8%
Taylor expanded in m around 0 21.2%
Final simplification21.2%
herbie shell --seed 2024067
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))