
(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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, k, m)
use fmin_fmax_functions
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 11 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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, k, m)
use fmin_fmax_functions
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)) (+ (+ 1.0 (* 10.0 k)) (* k k))))) (if (<= t_0 INFINITY) t_0 (fma (* (- (* 99.0 k) 10.0) k) a a))))
double code(double a, double k, double m) {
double t_0 = (a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = fma((((99.0 * k) - 10.0) * k), a, a);
}
return tmp;
}
function code(a, k, m) t_0 = Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = fma(Float64(Float64(Float64(99.0 * k) - 10.0) * k), a, 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[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[(N[(N[(99.0 * k), $MachinePrecision] - 10.0), $MachinePrecision] * k), $MachinePrecision] * a + a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(99 \cdot k - 10\right) \cdot k, a, 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))) < +inf.0Initial program 97.3%
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 k around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in m around 0
Applied rewrites100.0%
(FPCore (a k m) :precision binary64 (if (<= (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))) 0.0) (* (* -10.0 a) k) (* (fma 10.0 k 1.0) a)))
double code(double a, double k, double m) {
double tmp;
if (((a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))) <= 0.0) {
tmp = (-10.0 * a) * k;
} else {
tmp = fma(10.0, k, 1.0) * a;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) <= 0.0) tmp = Float64(Float64(-10.0 * a) * k); else tmp = Float64(fma(10.0, k, 1.0) * a); end return tmp end
code[a_, k_, m_] := If[LessEqual[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], 0.0], N[(N[(-10.0 * a), $MachinePrecision] * k), $MachinePrecision], N[(N[(10.0 * k + 1.0), $MachinePrecision] * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \leq 0:\\
\;\;\;\;\left(-10 \cdot a\right) \cdot k\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(10, k, 1\right) \cdot a\\
\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.5%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6445.7
Applied rewrites45.7%
Taylor expanded in k around 0
Applied rewrites13.7%
Taylor expanded in k around inf
Applied rewrites8.7%
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))) Initial program 71.0%
Taylor expanded in k around 0
remove-double-negN/A
fp-cancel-sub-sign-invN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6473.4
Applied rewrites73.4%
Applied rewrites71.1%
Taylor expanded in m around 0
Applied rewrites35.9%
(FPCore (a k m) :precision binary64 (if (or (<= m -3.7e-6) (not (<= m 0.0011))) (* 1.0 (* (pow k m) a)) (/ a (fma (+ 10.0 k) k 1.0))))
double code(double a, double k, double m) {
double tmp;
if ((m <= -3.7e-6) || !(m <= 0.0011)) {
tmp = 1.0 * (pow(k, m) * a);
} else {
tmp = a / fma((10.0 + k), k, 1.0);
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if ((m <= -3.7e-6) || !(m <= 0.0011)) tmp = Float64(1.0 * Float64((k ^ m) * a)); else tmp = Float64(a / fma(Float64(10.0 + k), k, 1.0)); end return tmp end
code[a_, k_, m_] := If[Or[LessEqual[m, -3.7e-6], N[Not[LessEqual[m, 0.0011]], $MachinePrecision]], N[(1.0 * N[(N[Power[k, m], $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], N[(a / N[(N[(10.0 + k), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -3.7 \cdot 10^{-6} \lor \neg \left(m \leq 0.0011\right):\\
\;\;\;\;1 \cdot \left({k}^{m} \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10 + k, k, 1\right)}\\
\end{array}
\end{array}
if m < -3.7000000000000002e-6 or 0.00110000000000000007 < m Initial program 86.9%
Taylor expanded in k around 0
remove-double-negN/A
fp-cancel-sub-sign-invN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6482.7
Applied rewrites82.7%
Applied rewrites84.5%
Taylor expanded in k around 0
Applied rewrites98.8%
if -3.7000000000000002e-6 < m < 0.00110000000000000007Initial program 92.8%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6492.8
Applied rewrites92.8%
Final simplification96.7%
(FPCore (a k m)
:precision binary64
(let* ((t_0 (* (pow k m) a)))
(if (<= m -7.8e-5)
(* (fma k 10.0 1.0) t_0)
(if (<= m 0.0011) (/ a (fma (+ 10.0 k) k 1.0)) (* 1.0 t_0)))))
double code(double a, double k, double m) {
double t_0 = pow(k, m) * a;
double tmp;
if (m <= -7.8e-5) {
tmp = fma(k, 10.0, 1.0) * t_0;
} else if (m <= 0.0011) {
tmp = a / fma((10.0 + k), k, 1.0);
} else {
tmp = 1.0 * t_0;
}
return tmp;
}
function code(a, k, m) t_0 = Float64((k ^ m) * a) tmp = 0.0 if (m <= -7.8e-5) tmp = Float64(fma(k, 10.0, 1.0) * t_0); elseif (m <= 0.0011) tmp = Float64(a / fma(Float64(10.0 + k), k, 1.0)); else tmp = Float64(1.0 * t_0); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(N[Power[k, m], $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[m, -7.8e-5], N[(N[(k * 10.0 + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[m, 0.0011], N[(a / N[(N[(10.0 + k), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {k}^{m} \cdot a\\
\mathbf{if}\;m \leq -7.8 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(k, 10, 1\right) \cdot t\_0\\
\mathbf{elif}\;m \leq 0.0011:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10 + k, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot t\_0\\
\end{array}
\end{array}
if m < -7.7999999999999999e-5Initial program 100.0%
Taylor expanded in k around 0
remove-double-negN/A
fp-cancel-sub-sign-invN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6498.6
Applied rewrites98.6%
Applied rewrites100.0%
if -7.7999999999999999e-5 < m < 0.00110000000000000007Initial program 92.8%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6492.8
Applied rewrites92.8%
if 0.00110000000000000007 < m Initial program 77.6%
Taylor expanded in k around 0
remove-double-negN/A
fp-cancel-sub-sign-invN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6471.4
Applied rewrites71.4%
Applied rewrites73.5%
Taylor expanded in k around 0
Applied rewrites99.0%
(FPCore (a k m) :precision binary64 (if (<= m -8000000000000.0) (/ (- a (/ (fma -99.0 (/ a k) (* 10.0 a)) k)) (* k k)) (if (<= m 0.9) (/ a (fma (+ 10.0 k) k 1.0)) (* (* (* k a) k) 99.0))))
double code(double a, double k, double m) {
double tmp;
if (m <= -8000000000000.0) {
tmp = (a - (fma(-99.0, (a / k), (10.0 * a)) / k)) / (k * k);
} else if (m <= 0.9) {
tmp = a / fma((10.0 + k), k, 1.0);
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= -8000000000000.0) tmp = Float64(Float64(a - Float64(fma(-99.0, Float64(a / k), Float64(10.0 * a)) / k)) / Float64(k * k)); elseif (m <= 0.9) tmp = Float64(a / fma(Float64(10.0 + k), k, 1.0)); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, -8000000000000.0], N[(N[(a - N[(N[(-99.0 * N[(a / k), $MachinePrecision] + N[(10.0 * a), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision] / N[(k * k), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 0.9], N[(a / N[(N[(10.0 + k), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -8000000000000:\\
\;\;\;\;\frac{a - \frac{\mathsf{fma}\left(-99, \frac{a}{k}, 10 \cdot a\right)}{k}}{k \cdot k}\\
\mathbf{elif}\;m \leq 0.9:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10 + k, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < -8e12Initial program 100.0%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6433.2
Applied rewrites33.2%
Taylor expanded in k around 0
Applied rewrites3.0%
Taylor expanded in k around inf
Applied rewrites2.2%
Taylor expanded in k around inf
Applied rewrites59.7%
if -8e12 < m < 0.900000000000000022Initial program 92.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6491.8
Applied rewrites91.8%
if 0.900000000000000022 < m Initial program 77.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f643.0
Applied rewrites3.0%
Taylor expanded in k around 0
Applied rewrites26.7%
Taylor expanded in k around inf
Applied rewrites45.7%
(FPCore (a k m) :precision binary64 (if (<= m -8000000000000.0) (/ a (* k k)) (if (<= m 0.9) (/ a (fma (+ 10.0 k) k 1.0)) (* (* (* k a) k) 99.0))))
double code(double a, double k, double m) {
double tmp;
if (m <= -8000000000000.0) {
tmp = a / (k * k);
} else if (m <= 0.9) {
tmp = a / fma((10.0 + k), k, 1.0);
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= -8000000000000.0) tmp = Float64(a / Float64(k * k)); elseif (m <= 0.9) tmp = Float64(a / fma(Float64(10.0 + k), k, 1.0)); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, -8000000000000.0], N[(a / N[(k * k), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 0.9], N[(a / N[(N[(10.0 + k), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -8000000000000:\\
\;\;\;\;\frac{a}{k \cdot k}\\
\mathbf{elif}\;m \leq 0.9:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10 + k, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < -8e12Initial program 100.0%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6433.2
Applied rewrites33.2%
Taylor expanded in k around inf
Applied rewrites54.2%
if -8e12 < m < 0.900000000000000022Initial program 92.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6491.8
Applied rewrites91.8%
if 0.900000000000000022 < m Initial program 77.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f643.0
Applied rewrites3.0%
Taylor expanded in k around 0
Applied rewrites26.7%
Taylor expanded in k around inf
Applied rewrites45.7%
(FPCore (a k m) :precision binary64 (if (<= m -4.3e-78) (/ a (* k k)) (if (<= m 0.9) (/ a (fma 10.0 k 1.0)) (* (* (* k a) k) 99.0))))
double code(double a, double k, double m) {
double tmp;
if (m <= -4.3e-78) {
tmp = a / (k * k);
} else if (m <= 0.9) {
tmp = a / fma(10.0, k, 1.0);
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= -4.3e-78) tmp = Float64(a / Float64(k * k)); elseif (m <= 0.9) tmp = Float64(a / fma(10.0, k, 1.0)); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, -4.3e-78], N[(a / N[(k * k), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 0.9], N[(a / N[(10.0 * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -4.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{a}{k \cdot k}\\
\mathbf{elif}\;m \leq 0.9:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < -4.29999999999999994e-78Initial program 98.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6440.7
Applied rewrites40.7%
Taylor expanded in k around inf
Applied rewrites54.9%
if -4.29999999999999994e-78 < m < 0.900000000000000022Initial program 92.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6492.9
Applied rewrites92.9%
Taylor expanded in k around 0
Applied rewrites74.0%
if 0.900000000000000022 < m Initial program 77.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f643.0
Applied rewrites3.0%
Taylor expanded in k around 0
Applied rewrites26.7%
Taylor expanded in k around inf
Applied rewrites45.7%
(FPCore (a k m)
:precision binary64
(if (<= m -1.28e-138)
(/ a (* k k))
(if (<= m 7.2e-16)
(fma (* a (fma 99.0 k -10.0)) k a)
(* (* (* k a) k) 99.0))))
double code(double a, double k, double m) {
double tmp;
if (m <= -1.28e-138) {
tmp = a / (k * k);
} else if (m <= 7.2e-16) {
tmp = fma((a * fma(99.0, k, -10.0)), k, a);
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= -1.28e-138) tmp = Float64(a / Float64(k * k)); elseif (m <= 7.2e-16) tmp = fma(Float64(a * fma(99.0, k, -10.0)), k, a); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, -1.28e-138], N[(a / N[(k * k), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 7.2e-16], N[(N[(a * N[(99.0 * k + -10.0), $MachinePrecision]), $MachinePrecision] * k + a), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.28 \cdot 10^{-138}:\\
\;\;\;\;\frac{a}{k \cdot k}\\
\mathbf{elif}\;m \leq 7.2 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot \mathsf{fma}\left(99, k, -10\right), k, a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < -1.28e-138Initial program 99.0%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6447.8
Applied rewrites47.8%
Taylor expanded in k around inf
Applied rewrites55.1%
if -1.28e-138 < m < 7.19999999999999965e-16Initial program 91.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6491.6
Applied rewrites91.6%
Taylor expanded in k around 0
Applied rewrites53.5%
Applied rewrites53.5%
if 7.19999999999999965e-16 < m Initial program 77.8%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f644.0
Applied rewrites4.0%
Taylor expanded in k around 0
Applied rewrites26.5%
Taylor expanded in k around inf
Applied rewrites45.3%
(FPCore (a k m) :precision binary64 (if (<= m 8.6e-122) (/ a (* k k)) (if (<= m 0.41) (* (fma -10.0 k 1.0) a) (* (* (* k a) k) 99.0))))
double code(double a, double k, double m) {
double tmp;
if (m <= 8.6e-122) {
tmp = a / (k * k);
} else if (m <= 0.41) {
tmp = fma(-10.0, k, 1.0) * a;
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= 8.6e-122) tmp = Float64(a / Float64(k * k)); elseif (m <= 0.41) tmp = Float64(fma(-10.0, k, 1.0) * a); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, 8.6e-122], N[(a / N[(k * k), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 0.41], N[(N[(-10.0 * k + 1.0), $MachinePrecision] * a), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 8.6 \cdot 10^{-122}:\\
\;\;\;\;\frac{a}{k \cdot k}\\
\mathbf{elif}\;m \leq 0.41:\\
\;\;\;\;\mathsf{fma}\left(-10, k, 1\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < 8.60000000000000037e-122Initial program 95.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6463.1
Applied rewrites63.1%
Taylor expanded in k around inf
Applied rewrites51.9%
if 8.60000000000000037e-122 < m < 0.409999999999999976Initial program 99.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in k around 0
Applied rewrites77.9%
if 0.409999999999999976 < m Initial program 77.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f643.0
Applied rewrites3.0%
Taylor expanded in k around 0
Applied rewrites26.7%
Taylor expanded in k around inf
Applied rewrites45.7%
(FPCore (a k m) :precision binary64 (if (<= m 0.41) (* (fma -10.0 k 1.0) a) (* (* (* k a) k) 99.0)))
double code(double a, double k, double m) {
double tmp;
if (m <= 0.41) {
tmp = fma(-10.0, k, 1.0) * a;
} else {
tmp = ((k * a) * k) * 99.0;
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= 0.41) tmp = Float64(fma(-10.0, k, 1.0) * a); else tmp = Float64(Float64(Float64(k * a) * k) * 99.0); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, 0.41], N[(N[(-10.0 * k + 1.0), $MachinePrecision] * a), $MachinePrecision], N[(N[(N[(k * a), $MachinePrecision] * k), $MachinePrecision] * 99.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 0.41:\\
\;\;\;\;\mathsf{fma}\left(-10, k, 1\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(k \cdot a\right) \cdot k\right) \cdot 99\\
\end{array}
\end{array}
if m < 0.409999999999999976Initial program 96.0%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6466.2
Applied rewrites66.2%
Taylor expanded in k around 0
Applied rewrites28.5%
if 0.409999999999999976 < m Initial program 77.6%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f643.0
Applied rewrites3.0%
Taylor expanded in k around 0
Applied rewrites26.7%
Taylor expanded in k around inf
Applied rewrites45.7%
(FPCore (a k m) :precision binary64 (* (* -10.0 a) k))
double code(double a, double k, double m) {
return (-10.0 * a) * k;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, k, m)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = ((-10.0d0) * a) * k
end function
public static double code(double a, double k, double m) {
return (-10.0 * a) * k;
}
def code(a, k, m): return (-10.0 * a) * k
function code(a, k, m) return Float64(Float64(-10.0 * a) * k) end
function tmp = code(a, k, m) tmp = (-10.0 * a) * k; end
code[a_, k_, m_] := N[(N[(-10.0 * a), $MachinePrecision] * k), $MachinePrecision]
\begin{array}{l}
\\
\left(-10 \cdot a\right) \cdot k
\end{array}
Initial program 88.9%
Taylor expanded in m around 0
lower-/.f64N/A
unpow2N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6442.0
Applied rewrites42.0%
Taylor expanded in k around 0
Applied rewrites19.8%
Taylor expanded in k around inf
Applied rewrites7.8%
herbie shell --seed 2024364
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))