
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
return exp(-w) * pow(l, exp(w));
}
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(w, l)
use fmin_fmax_functions
real(8), intent (in) :: w
real(8), intent (in) :: l
code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l): return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l) return Float64(exp(Float64(-w)) * (l ^ exp(w))) end
function tmp = code(w, l) tmp = exp(-w) * (l ^ exp(w)); end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
return exp(-w) * pow(l, exp(w));
}
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(w, l)
use fmin_fmax_functions
real(8), intent (in) :: w
real(8), intent (in) :: l
code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l): return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l) return Float64(exp(Float64(-w)) * (l ^ exp(w))) end
function tmp = code(w, l) tmp = exp(-w) * (l ^ exp(w)); end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}
(FPCore (w l) :precision binary64 (/ (pow l (exp w)) (exp w)))
double code(double w, double l) {
return pow(l, exp(w)) / exp(w);
}
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(w, l)
use fmin_fmax_functions
real(8), intent (in) :: w
real(8), intent (in) :: l
code = (l ** exp(w)) / exp(w)
end function
public static double code(double w, double l) {
return Math.pow(l, Math.exp(w)) / Math.exp(w);
}
def code(w, l): return math.pow(l, math.exp(w)) / math.exp(w)
function code(w, l) return Float64((l ^ exp(w)) / exp(w)) end
function tmp = code(w, l) tmp = (l ^ exp(w)) / exp(w); end
code[w_, l_] := N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}
\end{array}
Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f6499.6
Applied rewrites99.6%
(FPCore (w l)
:precision binary64
(if (<= l 1.0)
(*
(exp (- w))
(pow
(pow (pow l -1.0) -1.0)
(fma (fma (fma 0.16666666666666666 w 0.5) w 1.0) w 1.0)))
(* (fma (- (* 0.5 w) 1.0) w 1.0) (pow l (fma (fma 0.5 w 1.0) w 1.0)))))
double code(double w, double l) {
double tmp;
if (l <= 1.0) {
tmp = exp(-w) * pow(pow(pow(l, -1.0), -1.0), fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0));
} else {
tmp = fma(((0.5 * w) - 1.0), w, 1.0) * pow(l, fma(fma(0.5, w, 1.0), w, 1.0));
}
return tmp;
}
function code(w, l) tmp = 0.0 if (l <= 1.0) tmp = Float64(exp(Float64(-w)) * (((l ^ -1.0) ^ -1.0) ^ fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0))); else tmp = Float64(fma(Float64(Float64(0.5 * w) - 1.0), w, 1.0) * (l ^ fma(fma(0.5, w, 1.0), w, 1.0))); end return tmp end
code[w_, l_] := If[LessEqual[l, 1.0], N[(N[Exp[(-w)], $MachinePrecision] * N[Power[N[Power[N[Power[l, -1.0], $MachinePrecision], -1.0], $MachinePrecision], N[(N[(N[(0.16666666666666666 * w + 0.5), $MachinePrecision] * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * w), $MachinePrecision] - 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision] * N[Power[l, N[(N[(0.5 * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1:\\
\;\;\;\;e^{-w} \cdot {\left({\left({\ell}^{-1}\right)}^{-1}\right)}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, w, 0.5\right), w, 1\right), w, 1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot w - 1, w, 1\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, w, 1\right), w, 1\right)\right)}\\
\end{array}
\end{array}
if l < 1Initial program 99.6%
Taylor expanded in l around inf
*-commutativeN/A
associate-*r*N/A
exp-prodN/A
lower-pow.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-exp.f64N/A
lower-log.f64N/A
lower-exp.f6495.0
Applied rewrites95.0%
Applied rewrites99.4%
Taylor expanded in w around 0
Applied rewrites98.9%
if 1 < l Initial program 99.5%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6498.4
Applied rewrites98.4%
Final simplification98.7%
(FPCore (w l)
:precision binary64
(if (<= w -9.5e-6)
(exp (fma (log l) (exp w) (- w)))
(/
(pow l (exp w))
(fma (fma (fma 0.16666666666666666 w 0.5) w 1.0) w 1.0))))
double code(double w, double l) {
double tmp;
if (w <= -9.5e-6) {
tmp = exp(fma(log(l), exp(w), -w));
} else {
tmp = pow(l, exp(w)) / fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0);
}
return tmp;
}
function code(w, l) tmp = 0.0 if (w <= -9.5e-6) tmp = exp(fma(log(l), exp(w), Float64(-w))); else tmp = Float64((l ^ exp(w)) / fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0)); end return tmp end
code[w_, l_] := If[LessEqual[w, -9.5e-6], N[Exp[N[(N[Log[l], $MachinePrecision] * N[Exp[w], $MachinePrecision] + (-w)), $MachinePrecision]], $MachinePrecision], N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] / N[(N[(N[(0.16666666666666666 * w + 0.5), $MachinePrecision] * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -9.5 \cdot 10^{-6}:\\
\;\;\;\;e^{\mathsf{fma}\left(\log \ell, e^{w}, -w\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\ell}^{\left(e^{w}\right)}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, w, 0.5\right), w, 1\right), w, 1\right)}\\
\end{array}
\end{array}
if w < -9.5000000000000005e-6Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6499.5
Applied rewrites99.5%
if -9.5000000000000005e-6 < w Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f6499.6
Applied rewrites99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
return exp(-w) * pow(l, exp(w));
}
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(w, l)
use fmin_fmax_functions
real(8), intent (in) :: w
real(8), intent (in) :: l
code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l): return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l) return Float64(exp(Float64(-w)) * (l ^ exp(w))) end
function tmp = code(w, l) tmp = exp(-w) * (l ^ exp(w)); end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}
Initial program 99.6%
(FPCore (w l)
:precision binary64
(if (<= l 1.0)
(*
(fma -1.0 w 1.0)
(pow l (fma (fma (fma 0.16666666666666666 w 0.5) w 1.0) w 1.0)))
(* (fma (- (* 0.5 w) 1.0) w 1.0) (pow l (fma (fma 0.5 w 1.0) w 1.0)))))
double code(double w, double l) {
double tmp;
if (l <= 1.0) {
tmp = fma(-1.0, w, 1.0) * pow(l, fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0));
} else {
tmp = fma(((0.5 * w) - 1.0), w, 1.0) * pow(l, fma(fma(0.5, w, 1.0), w, 1.0));
}
return tmp;
}
function code(w, l) tmp = 0.0 if (l <= 1.0) tmp = Float64(fma(-1.0, w, 1.0) * (l ^ fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0))); else tmp = Float64(fma(Float64(Float64(0.5 * w) - 1.0), w, 1.0) * (l ^ fma(fma(0.5, w, 1.0), w, 1.0))); end return tmp end
code[w_, l_] := If[LessEqual[l, 1.0], N[(N[(-1.0 * w + 1.0), $MachinePrecision] * N[Power[l, N[(N[(N[(0.16666666666666666 * w + 0.5), $MachinePrecision] * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * w), $MachinePrecision] - 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision] * N[Power[l, N[(N[(0.5 * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1:\\
\;\;\;\;\mathsf{fma}\left(-1, w, 1\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, w, 0.5\right), w, 1\right), w, 1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot w - 1, w, 1\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, w, 1\right), w, 1\right)\right)}\\
\end{array}
\end{array}
if l < 1Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6474.6
Applied rewrites74.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6486.8
Applied rewrites86.8%
Taylor expanded in w around 0
Applied rewrites98.6%
if 1 < l Initial program 99.5%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6498.4
Applied rewrites98.4%
(FPCore (w l)
:precision binary64
(if (<= l 0.7)
(*
(fma -1.0 w 1.0)
(pow l (fma (fma (fma 0.16666666666666666 w 0.5) w 1.0) w 1.0)))
(* (- 1.0 w) (pow l (fma (fma 0.5 w 1.0) w 1.0)))))
double code(double w, double l) {
double tmp;
if (l <= 0.7) {
tmp = fma(-1.0, w, 1.0) * pow(l, fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0));
} else {
tmp = (1.0 - w) * pow(l, fma(fma(0.5, w, 1.0), w, 1.0));
}
return tmp;
}
function code(w, l) tmp = 0.0 if (l <= 0.7) tmp = Float64(fma(-1.0, w, 1.0) * (l ^ fma(fma(fma(0.16666666666666666, w, 0.5), w, 1.0), w, 1.0))); else tmp = Float64(Float64(1.0 - w) * (l ^ fma(fma(0.5, w, 1.0), w, 1.0))); end return tmp end
code[w_, l_] := If[LessEqual[l, 0.7], N[(N[(-1.0 * w + 1.0), $MachinePrecision] * N[Power[l, N[(N[(N[(0.16666666666666666 * w + 0.5), $MachinePrecision] * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - w), $MachinePrecision] * N[Power[l, N[(N[(0.5 * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 0.7:\\
\;\;\;\;\mathsf{fma}\left(-1, w, 1\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, w, 0.5\right), w, 1\right), w, 1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - w\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, w, 1\right), w, 1\right)\right)}\\
\end{array}
\end{array}
if l < 0.69999999999999996Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6475.1
Applied rewrites75.1%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6487.4
Applied rewrites87.4%
Taylor expanded in w around 0
Applied rewrites98.6%
if 0.69999999999999996 < l Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6460.2
Applied rewrites60.2%
Taylor expanded in w around 0
Applied rewrites97.4%
Taylor expanded in w around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6498.3
Applied rewrites98.3%
(FPCore (w l)
:precision binary64
(let* ((t_0 (fma (* 0.5 w) w 1.0)))
(if (<= w -5.6e+145)
(* t_0 (pow l 1.0))
(if (<= w -3.7e+62)
(* t_0 (pow l (+ 1.0 w)))
(* (- 1.0 w) (pow l (fma (fma 0.5 w 1.0) w 1.0)))))))
double code(double w, double l) {
double t_0 = fma((0.5 * w), w, 1.0);
double tmp;
if (w <= -5.6e+145) {
tmp = t_0 * pow(l, 1.0);
} else if (w <= -3.7e+62) {
tmp = t_0 * pow(l, (1.0 + w));
} else {
tmp = (1.0 - w) * pow(l, fma(fma(0.5, w, 1.0), w, 1.0));
}
return tmp;
}
function code(w, l) t_0 = fma(Float64(0.5 * w), w, 1.0) tmp = 0.0 if (w <= -5.6e+145) tmp = Float64(t_0 * (l ^ 1.0)); elseif (w <= -3.7e+62) tmp = Float64(t_0 * (l ^ Float64(1.0 + w))); else tmp = Float64(Float64(1.0 - w) * (l ^ fma(fma(0.5, w, 1.0), w, 1.0))); end return tmp end
code[w_, l_] := Block[{t$95$0 = N[(N[(0.5 * w), $MachinePrecision] * w + 1.0), $MachinePrecision]}, If[LessEqual[w, -5.6e+145], N[(t$95$0 * N[Power[l, 1.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[w, -3.7e+62], N[(t$95$0 * N[Power[l, N[(1.0 + w), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - w), $MachinePrecision] * N[Power[l, N[(N[(0.5 * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5 \cdot w, w, 1\right)\\
\mathbf{if}\;w \leq -5.6 \cdot 10^{+145}:\\
\;\;\;\;t\_0 \cdot {\ell}^{1}\\
\mathbf{elif}\;w \leq -3.7 \cdot 10^{+62}:\\
\;\;\;\;t\_0 \cdot {\ell}^{\left(1 + w\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - w\right) \cdot {\ell}^{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, w, 1\right), w, 1\right)\right)}\\
\end{array}
\end{array}
if w < -5.5999999999999997e145Initial program 100.0%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6497.6
Applied rewrites97.6%
Taylor expanded in w around inf
Applied rewrites97.6%
Taylor expanded in w around 0
Applied rewrites100.0%
if -5.5999999999999997e145 < w < -3.70000000000000014e62Initial program 100.0%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f645.7
Applied rewrites5.7%
Taylor expanded in w around inf
Applied rewrites5.7%
Taylor expanded in w around 0
lower-+.f6465.5
Applied rewrites65.5%
if -3.70000000000000014e62 < w Initial program 99.4%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6483.7
Applied rewrites83.7%
Taylor expanded in w around 0
Applied rewrites85.4%
Taylor expanded in w around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6494.6
Applied rewrites94.6%
(FPCore (w l) :precision binary64 (let* ((t_0 (fma (fma 0.5 w 1.0) w 1.0))) (if (<= l 0.52) (/ (pow l (+ 1.0 w)) t_0) (* (- 1.0 w) (pow l t_0)))))
double code(double w, double l) {
double t_0 = fma(fma(0.5, w, 1.0), w, 1.0);
double tmp;
if (l <= 0.52) {
tmp = pow(l, (1.0 + w)) / t_0;
} else {
tmp = (1.0 - w) * pow(l, t_0);
}
return tmp;
}
function code(w, l) t_0 = fma(fma(0.5, w, 1.0), w, 1.0) tmp = 0.0 if (l <= 0.52) tmp = Float64((l ^ Float64(1.0 + w)) / t_0); else tmp = Float64(Float64(1.0 - w) * (l ^ t_0)); end return tmp end
code[w_, l_] := Block[{t$95$0 = N[(N[(0.5 * w + 1.0), $MachinePrecision] * w + 1.0), $MachinePrecision]}, If[LessEqual[l, 0.52], N[(N[Power[l, N[(1.0 + w), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(1.0 - w), $MachinePrecision] * N[Power[l, t$95$0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(0.5, w, 1\right), w, 1\right)\\
\mathbf{if}\;\ell \leq 0.52:\\
\;\;\;\;\frac{{\ell}^{\left(1 + w\right)}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - w\right) \cdot {\ell}^{t\_0}\\
\end{array}
\end{array}
if l < 0.52000000000000002Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f6499.6
Applied rewrites99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6477.5
Applied rewrites77.5%
Taylor expanded in w around 0
lower-+.f6489.2
Applied rewrites89.2%
if 0.52000000000000002 < l Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6460.2
Applied rewrites60.2%
Taylor expanded in w around 0
Applied rewrites97.4%
Taylor expanded in w around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6498.3
Applied rewrites98.3%
(FPCore (w l) :precision binary64 (let* ((t_0 (fma (* 0.5 w) w 1.0))) (if (<= l 0.7) (* t_0 (pow l (+ 1.0 w))) (* t_0 (pow l 1.0)))))
double code(double w, double l) {
double t_0 = fma((0.5 * w), w, 1.0);
double tmp;
if (l <= 0.7) {
tmp = t_0 * pow(l, (1.0 + w));
} else {
tmp = t_0 * pow(l, 1.0);
}
return tmp;
}
function code(w, l) t_0 = fma(Float64(0.5 * w), w, 1.0) tmp = 0.0 if (l <= 0.7) tmp = Float64(t_0 * (l ^ Float64(1.0 + w))); else tmp = Float64(t_0 * (l ^ 1.0)); end return tmp end
code[w_, l_] := Block[{t$95$0 = N[(N[(0.5 * w), $MachinePrecision] * w + 1.0), $MachinePrecision]}, If[LessEqual[l, 0.7], N[(t$95$0 * N[Power[l, N[(1.0 + w), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[l, 1.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5 \cdot w, w, 1\right)\\
\mathbf{if}\;\ell \leq 0.7:\\
\;\;\;\;t\_0 \cdot {\ell}^{\left(1 + w\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {\ell}^{1}\\
\end{array}
\end{array}
if l < 0.69999999999999996Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6475.1
Applied rewrites75.1%
Taylor expanded in w around inf
Applied rewrites74.0%
Taylor expanded in w around 0
lower-+.f6486.3
Applied rewrites86.3%
if 0.69999999999999996 < l Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
Taylor expanded in w around inf
Applied rewrites78.5%
Taylor expanded in w around 0
Applied rewrites86.5%
(FPCore (w l) :precision binary64 (* (fma (* 0.5 w) w 1.0) (pow l 1.0)))
double code(double w, double l) {
return fma((0.5 * w), w, 1.0) * pow(l, 1.0);
}
function code(w, l) return Float64(fma(Float64(0.5 * w), w, 1.0) * (l ^ 1.0)) end
code[w_, l_] := N[(N[(N[(0.5 * w), $MachinePrecision] * w + 1.0), $MachinePrecision] * N[Power[l, 1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 \cdot w, w, 1\right) \cdot {\ell}^{1}
\end{array}
Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
Taylor expanded in w around inf
Applied rewrites75.7%
Taylor expanded in w around 0
Applied rewrites71.7%
(FPCore (w l) :precision binary64 (fma (- (* (log l) l) l) w l))
double code(double w, double l) {
return fma(((log(l) * l) - l), w, l);
}
function code(w, l) return fma(Float64(Float64(log(l) * l) - l), w, l) end
code[w_, l_] := N[(N[(N[(N[Log[l], $MachinePrecision] * l), $MachinePrecision] - l), $MachinePrecision] * w + l), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log \ell \cdot \ell - \ell, w, \ell\right)
\end{array}
Initial program 99.6%
Taylor expanded in l around inf
*-commutativeN/A
associate-*r*N/A
exp-prodN/A
lower-pow.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-exp.f64N/A
lower-log.f64N/A
lower-exp.f6494.9
Applied rewrites94.9%
Applied rewrites99.4%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-log.f6456.2
Applied rewrites56.2%
(FPCore (w l) :precision binary64 (* (* l (- (log l) 1.0)) w))
double code(double w, double l) {
return (l * (log(l) - 1.0)) * w;
}
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(w, l)
use fmin_fmax_functions
real(8), intent (in) :: w
real(8), intent (in) :: l
code = (l * (log(l) - 1.0d0)) * w
end function
public static double code(double w, double l) {
return (l * (Math.log(l) - 1.0)) * w;
}
def code(w, l): return (l * (math.log(l) - 1.0)) * w
function code(w, l) return Float64(Float64(l * Float64(log(l) - 1.0)) * w) end
function tmp = code(w, l) tmp = (l * (log(l) - 1.0)) * w; end
code[w_, l_] := N[(N[(l * N[(N[Log[l], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision]
\begin{array}{l}
\\
\left(\ell \cdot \left(\log \ell - 1\right)\right) \cdot w
\end{array}
Initial program 99.6%
Taylor expanded in w around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6456.2
Applied rewrites56.2%
Taylor expanded in w around inf
Applied rewrites3.8%
Applied rewrites3.8%
herbie shell --seed 2024350
(FPCore (w l)
:name "exp-w (used to crash)"
:precision binary64
(* (exp (- w)) (pow l (exp w))))