
(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]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
Herbie found 10 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]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
(FPCore (a k m)
:precision binary64
(let* ((t_0 (* (pow k m) a)))
(if (<= k 1e-104)
t_0
(/ 1.0 (fma (/ (- k -10.0) t_0) k (/ (pow k (- m)) a))))))double code(double a, double k, double m) {
double t_0 = pow(k, m) * a;
double tmp;
if (k <= 1e-104) {
tmp = t_0;
} else {
tmp = 1.0 / fma(((k - -10.0) / t_0), k, (pow(k, -m) / a));
}
return tmp;
}
function code(a, k, m) t_0 = Float64((k ^ m) * a) tmp = 0.0 if (k <= 1e-104) tmp = t_0; else tmp = Float64(1.0 / fma(Float64(Float64(k - -10.0) / t_0), k, Float64((k ^ Float64(-m)) / a))); end return tmp end
code[a_, k_, m_] := Block[{t$95$0 = N[(N[Power[k, m], $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[k, 1e-104], t$95$0, N[(1.0 / N[(N[(N[(k - -10.0), $MachinePrecision] / t$95$0), $MachinePrecision] * k + N[(N[Power[k, (-m)], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := {k}^{m} \cdot a\\
\mathbf{if}\;k \leq 10^{-104}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{k - -10}{t\_0}, k, \frac{{k}^{\left(-m\right)}}{a}\right)}\\
\end{array}
if k < 9.99999999999999927e-105Initial program 89.7%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.6%
Taylor expanded in k around 0
lower-pow.f6482.7%
Applied rewrites82.7%
if 9.99999999999999927e-105 < k Initial program 89.7%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6489.5%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
metadata-evalN/A
associate-+r+N/A
+-commutativeN/A
+-lft-identityN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
metadata-eval89.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6489.5%
Applied rewrites89.5%
lift-/.f64N/A
lift-fma.f64N/A
div-addN/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lift-pow.f64N/A
pow-flipN/A
lower-pow.f64N/A
lower-neg.f6488.8%
Applied rewrites88.8%
(FPCore (a k m)
:precision binary64
(let* ((t_0 (* (pow k m) a)))
(if (<= m -1.3e+15)
t_0
(if (<= m 1.55e-18) (/ 1.0 (fma (- k -10.0) (/ k a) (/ 1.0 a))) t_0))))double code(double a, double k, double m) {
double t_0 = pow(k, m) * a;
double tmp;
if (m <= -1.3e+15) {
tmp = t_0;
} else if (m <= 1.55e-18) {
tmp = 1.0 / fma((k - -10.0), (k / a), (1.0 / a));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, k, m) t_0 = Float64((k ^ m) * a) tmp = 0.0 if (m <= -1.3e+15) tmp = t_0; elseif (m <= 1.55e-18) tmp = Float64(1.0 / fma(Float64(k - -10.0), Float64(k / a), Float64(1.0 / a))); else tmp = 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, -1.3e+15], t$95$0, If[LessEqual[m, 1.55e-18], N[(1.0 / N[(N[(k - -10.0), $MachinePrecision] * N[(k / a), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := {k}^{m} \cdot a\\
\mathbf{if}\;m \leq -1.3 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;m \leq 1.55 \cdot 10^{-18}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(k - -10, \frac{k}{a}, \frac{1}{a}\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if m < -1.3e15 or 1.55000000000000003e-18 < m Initial program 89.7%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.6%
Taylor expanded in k around 0
lower-pow.f6482.7%
Applied rewrites82.7%
if -1.3e15 < m < 1.55000000000000003e-18Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-/.f64N/A
div-flipN/A
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f64N/A
lower-unsound-/.f32N/A
lower-/.f32N/A
lower-unsound-/.f64N/A
lower-/.f6444.8%
Applied rewrites44.8%
lift-/.f64N/A
lift-fma.f64N/A
div-addN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6444.7%
Applied rewrites44.7%
(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 (* (+ 1.0 (* k (- (* 99.0 k) 10.0))) 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 = (1.0 + (k * ((99.0 * k) - 10.0))) * a;
}
return tmp;
}
public static double code(double a, double k, double m) {
double t_0 = (a * Math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = (1.0 + (k * ((99.0 * k) - 10.0))) * a;
}
return tmp;
}
def code(a, k, m): t_0 = (a * math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k)) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = (1.0 + (k * ((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(10.0 * k)) + Float64(k * k))) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(Float64(1.0 + Float64(k * Float64(Float64(99.0 * k) - 10.0))) * a); end return tmp end
function tmp_2 = code(a, k, m) t_0 = (a * (k ^ m)) / ((1.0 + (10.0 * k)) + (k * k)); tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = (1.0 + (k * ((99.0 * k) - 10.0))) * a; end tmp_2 = 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[(1.0 + N[(k * N[(N[(99.0 * k), $MachinePrecision] - 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]]]
\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}:\\
\;\;\;\;\left(1 + k \cdot \left(99 \cdot k - 10\right)\right) \cdot a\\
\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 89.7%
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 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-/.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f64N/A
mult-flip-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6429.2%
Applied rewrites29.2%
(FPCore (a k m) :precision binary64 (if (<= (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))) INFINITY) (* (/ (pow k m) (fma (- k -10.0) k 1.0)) a) (* (+ 1.0 (* k (- (* 99.0 k) 10.0))) a)))
double code(double a, double k, double m) {
double tmp;
if (((a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))) <= ((double) INFINITY)) {
tmp = (pow(k, m) / fma((k - -10.0), k, 1.0)) * a;
} else {
tmp = (1.0 + (k * ((99.0 * k) - 10.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))) <= Inf) tmp = Float64(Float64((k ^ m) / fma(Float64(k - -10.0), k, 1.0)) * a); else tmp = Float64(Float64(1.0 + Float64(k * Float64(Float64(99.0 * k) - 10.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], Infinity], N[(N[(N[Power[k, m], $MachinePrecision] / N[(N[(k - -10.0), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(N[(1.0 + N[(k * N[(N[(99.0 * k), $MachinePrecision] - 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \leq \infty:\\
\;\;\;\;\frac{{k}^{m}}{\mathsf{fma}\left(k - -10, k, 1\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(1 + k \cdot \left(99 \cdot k - 10\right)\right) \cdot a\\
\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 89.7%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.6%
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 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-/.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f64N/A
mult-flip-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6429.2%
Applied rewrites29.2%
(FPCore (a k m)
:precision binary64
(*
(copysign 1.0 a)
(if (<= (/ (* (fabs a) (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))) 5e+256)
(/ (fabs a) (fma (- k -10.0) k 1.0))
(* (+ 1.0 (* k (- (* 99.0 k) 10.0))) (fabs a)))))double code(double a, double k, double m) {
double tmp;
if (((fabs(a) * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))) <= 5e+256) {
tmp = fabs(a) / fma((k - -10.0), k, 1.0);
} else {
tmp = (1.0 + (k * ((99.0 * k) - 10.0))) * fabs(a);
}
return copysign(1.0, a) * tmp;
}
function code(a, k, m) tmp = 0.0 if (Float64(Float64(abs(a) * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) <= 5e+256) tmp = Float64(abs(a) / fma(Float64(k - -10.0), k, 1.0)); else tmp = Float64(Float64(1.0 + Float64(k * Float64(Float64(99.0 * k) - 10.0))) * abs(a)); end return Float64(copysign(1.0, a) * tmp) end
code[a_, k_, m_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Abs[a], $MachinePrecision] * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+256], N[(N[Abs[a], $MachinePrecision] / N[(N[(k - -10.0), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(k * N[(N[(99.0 * k), $MachinePrecision] - 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Abs[a], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, a\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left|a\right| \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \leq 5 \cdot 10^{+256}:\\
\;\;\;\;\frac{\left|a\right|}{\mathsf{fma}\left(k - -10, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + k \cdot \left(99 \cdot k - 10\right)\right) \cdot \left|a\right|\\
\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))) < 5.00000000000000015e256Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f6444.8%
Applied rewrites44.8%
if 5.00000000000000015e256 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-/.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f64N/A
mult-flip-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6429.2%
Applied rewrites29.2%
(FPCore (a k m)
:precision binary64
(*
(copysign 1.0 a)
(if (<= (/ (* (fabs a) (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))) 4e+294)
(/ (fabs a) (fma (- k -10.0) k 1.0))
(* k (fma -10.0 (fabs a) (/ (fabs a) k))))))double code(double a, double k, double m) {
double tmp;
if (((fabs(a) * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))) <= 4e+294) {
tmp = fabs(a) / fma((k - -10.0), k, 1.0);
} else {
tmp = k * fma(-10.0, fabs(a), (fabs(a) / k));
}
return copysign(1.0, a) * tmp;
}
function code(a, k, m) tmp = 0.0 if (Float64(Float64(abs(a) * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) <= 4e+294) tmp = Float64(abs(a) / fma(Float64(k - -10.0), k, 1.0)); else tmp = Float64(k * fma(-10.0, abs(a), Float64(abs(a) / k))); end return Float64(copysign(1.0, a) * tmp) end
code[a_, k_, m_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Abs[a], $MachinePrecision] * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e+294], N[(N[Abs[a], $MachinePrecision] / N[(N[(k - -10.0), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(k * N[(-10.0 * N[Abs[a], $MachinePrecision] + N[(N[Abs[a], $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, a\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left|a\right| \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \leq 4 \cdot 10^{+294}:\\
\;\;\;\;\frac{\left|a\right|}{\mathsf{fma}\left(k - -10, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;k \cdot \mathsf{fma}\left(-10, \left|a\right|, \frac{\left|a\right|}{k}\right)\\
\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))) < 4.00000000000000027e294Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f6444.8%
Applied rewrites44.8%
if 4.00000000000000027e294 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 #s(literal 1 binary64) (*.f64 #s(literal 10 binary64) k)) (*.f64 k k))) Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f6421.0%
Applied rewrites21.0%
Taylor expanded in k around inf
lower-*.f64N/A
lower-fma.f64N/A
lower-/.f6420.4%
Applied rewrites20.4%
(FPCore (a k m) :precision binary64 (if (<= m 24000.0) (/ a (fma (- k -10.0) k 1.0)) (fma (* -10.0 k) a a)))
double code(double a, double k, double m) {
double tmp;
if (m <= 24000.0) {
tmp = a / fma((k - -10.0), k, 1.0);
} else {
tmp = fma((-10.0 * k), a, a);
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= 24000.0) tmp = Float64(a / fma(Float64(k - -10.0), k, 1.0)); else tmp = fma(Float64(-10.0 * k), a, a); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, 24000.0], N[(a / N[(N[(k - -10.0), $MachinePrecision] * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(-10.0 * k), $MachinePrecision] * a + a), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;m \leq 24000:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(k - -10, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-10 \cdot k, a, a\right)\\
\end{array}
if m < 24000Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f6444.8%
Applied rewrites44.8%
if 24000 < m Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f6421.0%
Applied rewrites21.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-*.f6421.0%
Applied rewrites21.0%
(FPCore (a k m) :precision binary64 (if (<= m 12500.0) (/ a (fma 10.0 k 1.0)) (fma (* -10.0 k) a a)))
double code(double a, double k, double m) {
double tmp;
if (m <= 12500.0) {
tmp = a / fma(10.0, k, 1.0);
} else {
tmp = fma((-10.0 * k), a, a);
}
return tmp;
}
function code(a, k, m) tmp = 0.0 if (m <= 12500.0) tmp = Float64(a / fma(10.0, k, 1.0)); else tmp = fma(Float64(-10.0 * k), a, a); end return tmp end
code[a_, k_, m_] := If[LessEqual[m, 12500.0], N[(a / N[(10.0 * k + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(-10.0 * k), $MachinePrecision] * a + a), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;m \leq 12500:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(10, k, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-10 \cdot k, a, a\right)\\
\end{array}
if m < 12500Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
Applied rewrites27.8%
if 12500 < m Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f6421.0%
Applied rewrites21.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-*.f6421.0%
Applied rewrites21.0%
(FPCore (a k m) :precision binary64 (fma (* -10.0 k) a a))
double code(double a, double k, double m) {
return fma((-10.0 * k), a, a);
}
function code(a, k, m) return fma(Float64(-10.0 * k), a, a) end
code[a_, k_, m_] := N[(N[(-10.0 * k), $MachinePrecision] * a + a), $MachinePrecision]
\mathsf{fma}\left(-10 \cdot k, a, a\right)
Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f6421.0%
Applied rewrites21.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-*.f6421.0%
Applied rewrites21.0%
(FPCore (a k m) :precision binary64 (/ a 1.0))
double code(double a, double k, double m) {
return a / 1.0;
}
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 / 1.0d0
end function
public static double code(double a, double k, double m) {
return a / 1.0;
}
def code(a, k, m): return a / 1.0
function code(a, k, m) return Float64(a / 1.0) end
function tmp = code(a, k, m) tmp = a / 1.0; end
code[a_, k_, m_] := N[(a / 1.0), $MachinePrecision]
\frac{a}{1}
Initial program 89.7%
Taylor expanded in m around 0
lower-/.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
lower-pow.f6444.8%
Applied rewrites44.8%
lift-fma.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
*-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-fma.f6444.8%
Applied rewrites44.8%
Taylor expanded in k around 0
Applied rewrites20.0%
herbie shell --seed 2025183
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))