
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Initial program 98.9%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.0) (/ a (+ (+ 1.0 a) (fma (fma 0.5 b 1.0) b 1.0))) (fma (fma (* a a) -0.020833333333333332 0.25) a 0.5)))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.0) {
tmp = a / ((1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0));
} else {
tmp = fma(fma((a * a), -0.020833333333333332, 0.25), a, 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.0) tmp = Float64(a / Float64(Float64(1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0))); else tmp = fma(fma(Float64(a * a), -0.020833333333333332, 0.25), a, 0.5); end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(a / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * -0.020833333333333332 + 0.25), $MachinePrecision] * a + 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0:\\
\;\;\;\;\frac{a}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, -0.020833333333333332, 0.25\right), a, 0.5\right)\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.0Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6461.0
Applied rewrites61.0%
Taylor expanded in a around 0
lower-+.f6461.4
Applied rewrites61.4%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6433.3
Applied rewrites33.3%
Taylor expanded in a around inf
Applied rewrites42.9%
if 0.0 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 98.1%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites66.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites65.6%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6469.0
Applied rewrites69.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.500000002) (/ 1.0 (+ (+ 1.0 a) (fma (fma 0.5 b 1.0) b 1.0))) (fma (fma (* a a) -0.020833333333333332 0.25) a 0.5)))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.500000002) {
tmp = 1.0 / ((1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0));
} else {
tmp = fma(fma((a * a), -0.020833333333333332, 0.25), a, 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.500000002) tmp = Float64(1.0 / Float64(Float64(1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0))); else tmp = fma(fma(Float64(a * a), -0.020833333333333332, 0.25), a, 0.5); end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.500000002], N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * -0.020833333333333332 + 0.25), $MachinePrecision] * a + 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.500000002:\\
\;\;\;\;\frac{1}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, -0.020833333333333332, 0.25\right), a, 0.5\right)\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.500000002000000054Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in a around 0
lower-+.f6478.1
Applied rewrites78.1%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6462.2
Applied rewrites62.2%
Taylor expanded in a around 0
Applied rewrites62.5%
if 0.500000002000000054 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.9%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites10.7%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites8.8%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6420.0
Applied rewrites20.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ 1.0 (- (exp b) -1.0))))
(if (<= b -3.05e-37)
t_0
(if (<= b 0.0035)
(/
(- a -1.0)
(+ (/ (- 1.0 (* a a)) (- 1.0 a)) (fma (fma 0.5 b 1.0) b 1.0)))
t_0))))
double code(double a, double b) {
double t_0 = 1.0 / (exp(b) - -1.0);
double tmp;
if (b <= -3.05e-37) {
tmp = t_0;
} else if (b <= 0.0035) {
tmp = (a - -1.0) / (((1.0 - (a * a)) / (1.0 - a)) + fma(fma(0.5, b, 1.0), b, 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b) t_0 = Float64(1.0 / Float64(exp(b) - -1.0)) tmp = 0.0 if (b <= -3.05e-37) tmp = t_0; elseif (b <= 0.0035) tmp = Float64(Float64(a - -1.0) / Float64(Float64(Float64(1.0 - Float64(a * a)) / Float64(1.0 - a)) + fma(fma(0.5, b, 1.0), b, 1.0))); else tmp = t_0; end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3.05e-37], t$95$0, If[LessEqual[b, 0.0035], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(N[(1.0 - N[(a * a), $MachinePrecision]), $MachinePrecision] / N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{e^{b} - -1}\\
\mathbf{if}\;b \leq -3.05 \cdot 10^{-37}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 0.0035:\\
\;\;\;\;\frac{a - -1}{\frac{1 - a \cdot a}{1 - a} + \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -3.0500000000000002e-37 or 0.00350000000000000007 < b Initial program 98.7%
Taylor expanded in a around 0
inv-powN/A
lower-pow.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f6496.6
Applied rewrites96.6%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6496.6
Applied rewrites96.6%
if -3.0500000000000002e-37 < b < 0.00350000000000000007Initial program 99.2%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6466.7
Applied rewrites66.7%
Taylor expanded in a around 0
lower-+.f6467.4
Applied rewrites67.4%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6467.3
Applied rewrites67.3%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
pow2N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6483.7
Applied rewrites83.7%
(FPCore (a b) :precision binary64 (if (<= a -700.0) (/ (exp a) (+ 1.0 1.0)) (/ (- a -1.0) (+ (+ 1.0 a) (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = exp(a) / (1.0 + 1.0);
} else {
tmp = (a - -1.0) / ((1.0 + a) + exp(b));
}
return tmp;
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-700.0d0)) then
tmp = exp(a) / (1.0d0 + 1.0d0)
else
tmp = (a - (-1.0d0)) / ((1.0d0 + a) + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = Math.exp(a) / (1.0 + 1.0);
} else {
tmp = (a - -1.0) / ((1.0 + a) + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -700.0: tmp = math.exp(a) / (1.0 + 1.0) else: tmp = (a - -1.0) / ((1.0 + a) + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -700.0) tmp = Float64(exp(a) / Float64(1.0 + 1.0)); else tmp = Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -700.0) tmp = exp(a) / (1.0 + 1.0); else tmp = (a - -1.0) / ((1.0 + a) + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -700.0], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -700:\\
\;\;\;\;\frac{e^{a}}{1 + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a - -1}{\left(1 + a\right) + e^{b}}\\
\end{array}
\end{array}
if a < -700Initial program 98.8%
Taylor expanded in b around 0
Applied rewrites99.5%
Taylor expanded in a around 0
Applied rewrites99.5%
if -700 < a Initial program 99.0%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6497.8
Applied rewrites97.8%
Taylor expanded in a around 0
lower-+.f6498.8
Applied rewrites98.8%
(FPCore (a b)
:precision binary64
(if (<= b -105.0)
(fma (* (* a a) -0.020833333333333332) a 0.5)
(if (<= b 1.7e+34)
(/
(- a -1.0)
(+ (/ (- 1.0 (* a a)) (- 1.0 a)) (fma (fma 0.5 b 1.0) b 1.0)))
(if (<= b 1.05e+103)
(* (pow a 3.0) -0.020833333333333332)
(/
(- a -1.0)
(+
(+ 1.0 a)
(fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0)))))))
double code(double a, double b) {
double tmp;
if (b <= -105.0) {
tmp = fma(((a * a) * -0.020833333333333332), a, 0.5);
} else if (b <= 1.7e+34) {
tmp = (a - -1.0) / (((1.0 - (a * a)) / (1.0 - a)) + fma(fma(0.5, b, 1.0), b, 1.0));
} else if (b <= 1.05e+103) {
tmp = pow(a, 3.0) * -0.020833333333333332;
} else {
tmp = (a - -1.0) / ((1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= -105.0) tmp = fma(Float64(Float64(a * a) * -0.020833333333333332), a, 0.5); elseif (b <= 1.7e+34) tmp = Float64(Float64(a - -1.0) / Float64(Float64(Float64(1.0 - Float64(a * a)) / Float64(1.0 - a)) + fma(fma(0.5, b, 1.0), b, 1.0))); elseif (b <= 1.05e+103) tmp = Float64((a ^ 3.0) * -0.020833333333333332); else tmp = Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0))); end return tmp end
code[a_, b_] := If[LessEqual[b, -105.0], N[(N[(N[(a * a), $MachinePrecision] * -0.020833333333333332), $MachinePrecision] * a + 0.5), $MachinePrecision], If[LessEqual[b, 1.7e+34], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(N[(1.0 - N[(a * a), $MachinePrecision]), $MachinePrecision] / N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e+103], N[(N[Power[a, 3.0], $MachinePrecision] * -0.020833333333333332), $MachinePrecision], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -105:\\
\;\;\;\;\mathsf{fma}\left(\left(a \cdot a\right) \cdot -0.020833333333333332, a, 0.5\right)\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{+34}:\\
\;\;\;\;\frac{a - -1}{\frac{1 - a \cdot a}{1 - a} + \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;{a}^{3} \cdot -0.020833333333333332\\
\mathbf{else}:\\
\;\;\;\;\frac{a - -1}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 1\right)}\\
\end{array}
\end{array}
if b < -105Initial program 97.4%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites6.4%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites5.2%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6418.3
Applied rewrites18.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6418.3
Applied rewrites18.3%
if -105 < b < 1.7e34Initial program 99.2%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6468.0
Applied rewrites68.0%
Taylor expanded in a around 0
lower-+.f6468.7
Applied rewrites68.7%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6463.6
Applied rewrites63.6%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
pow2N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6480.0
Applied rewrites80.0%
if 1.7e34 < b < 1.0500000000000001e103Initial program 98.9%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites34.1%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites2.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6444.2
Applied rewrites44.2%
if 1.0500000000000001e103 < b Initial program 99.6%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= a -700.0) (/ (exp a) (+ 1.0 1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = exp(a) / (1.0 + 1.0);
} else {
tmp = 1.0 / (exp(b) - -1.0);
}
return tmp;
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-700.0d0)) then
tmp = exp(a) / (1.0d0 + 1.0d0)
else
tmp = 1.0d0 / (exp(b) - (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = Math.exp(a) / (1.0 + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -700.0: tmp = math.exp(a) / (1.0 + 1.0) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -700.0) tmp = Float64(exp(a) / Float64(1.0 + 1.0)); else tmp = Float64(1.0 / Float64(exp(b) - -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -700.0) tmp = exp(a) / (1.0 + 1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -700.0], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -700:\\
\;\;\;\;\frac{e^{a}}{1 + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -700Initial program 98.8%
Taylor expanded in b around 0
Applied rewrites99.5%
Taylor expanded in a around 0
Applied rewrites99.5%
if -700 < a Initial program 99.0%
Taylor expanded in a around 0
inv-powN/A
lower-pow.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f6498.0
Applied rewrites98.0%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6498.0
Applied rewrites98.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (fma (fma 0.5 b 1.0) b 1.0)))
(if (<= b -105.0)
(fma (* (* a a) -0.020833333333333332) a 0.5)
(if (<= b 1.35e+35)
(/ (- a -1.0) (+ (/ (- 1.0 (* a a)) (- 1.0 a)) t_0))
(if (<= b 1.05e+103)
(/ a (+ (+ 1.0 a) t_0))
(/
(- a -1.0)
(+
(+ 1.0 a)
(fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0))))))))
double code(double a, double b) {
double t_0 = fma(fma(0.5, b, 1.0), b, 1.0);
double tmp;
if (b <= -105.0) {
tmp = fma(((a * a) * -0.020833333333333332), a, 0.5);
} else if (b <= 1.35e+35) {
tmp = (a - -1.0) / (((1.0 - (a * a)) / (1.0 - a)) + t_0);
} else if (b <= 1.05e+103) {
tmp = a / ((1.0 + a) + t_0);
} else {
tmp = (a - -1.0) / ((1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0));
}
return tmp;
}
function code(a, b) t_0 = fma(fma(0.5, b, 1.0), b, 1.0) tmp = 0.0 if (b <= -105.0) tmp = fma(Float64(Float64(a * a) * -0.020833333333333332), a, 0.5); elseif (b <= 1.35e+35) tmp = Float64(Float64(a - -1.0) / Float64(Float64(Float64(1.0 - Float64(a * a)) / Float64(1.0 - a)) + t_0)); elseif (b <= 1.05e+103) tmp = Float64(a / Float64(Float64(1.0 + a) + t_0)); else tmp = Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0))); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]}, If[LessEqual[b, -105.0], N[(N[(N[(a * a), $MachinePrecision] * -0.020833333333333332), $MachinePrecision] * a + 0.5), $MachinePrecision], If[LessEqual[b, 1.35e+35], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(N[(1.0 - N[(a * a), $MachinePrecision]), $MachinePrecision] / N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e+103], N[(a / N[(N[(1.0 + a), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)\\
\mathbf{if}\;b \leq -105:\\
\;\;\;\;\mathsf{fma}\left(\left(a \cdot a\right) \cdot -0.020833333333333332, a, 0.5\right)\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+35}:\\
\;\;\;\;\frac{a - -1}{\frac{1 - a \cdot a}{1 - a} + t\_0}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;\frac{a}{\left(1 + a\right) + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{a - -1}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 1\right)}\\
\end{array}
\end{array}
if b < -105Initial program 97.4%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites6.4%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites5.2%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6418.3
Applied rewrites18.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6418.3
Applied rewrites18.3%
if -105 < b < 1.35000000000000001e35Initial program 99.2%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6468.1
Applied rewrites68.1%
Taylor expanded in a around 0
lower-+.f6468.8
Applied rewrites68.8%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6463.5
Applied rewrites63.5%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
pow2N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6479.9
Applied rewrites79.9%
if 1.35000000000000001e35 < b < 1.0500000000000001e103Initial program 98.9%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f644.2
Applied rewrites4.2%
Taylor expanded in a around inf
Applied rewrites32.7%
if 1.0500000000000001e103 < b Initial program 99.6%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (a b)
:precision binary64
(if (<= b 350.0)
(/ (- a -1.0) (+ (+ 1.0 a) 1.0))
(if (<= b 1.05e+103)
(/ a (+ (+ 1.0 a) (fma (fma 0.5 b 1.0) b 1.0)))
(/
(- a -1.0)
(+ (+ 1.0 a) (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0))))))
double code(double a, double b) {
double tmp;
if (b <= 350.0) {
tmp = (a - -1.0) / ((1.0 + a) + 1.0);
} else if (b <= 1.05e+103) {
tmp = a / ((1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0));
} else {
tmp = (a - -1.0) / ((1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 350.0) tmp = Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + 1.0)); elseif (b <= 1.05e+103) tmp = Float64(a / Float64(Float64(1.0 + a) + fma(fma(0.5, b, 1.0), b, 1.0))); else tmp = Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0))); end return tmp end
code[a_, b_] := If[LessEqual[b, 350.0], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e+103], N[(a / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 350:\\
\;\;\;\;\frac{a - -1}{\left(1 + a\right) + 1}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;\frac{a}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a - -1}{\left(1 + a\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 1\right)}\\
\end{array}
\end{array}
if b < 350Initial program 98.7%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6474.0
Applied rewrites74.0%
Taylor expanded in a around 0
lower-+.f6475.4
Applied rewrites75.4%
Taylor expanded in b around 0
Applied rewrites53.6%
if 350 < b < 1.0500000000000001e103Initial program 99.1%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f643.9
Applied rewrites3.9%
Taylor expanded in a around inf
Applied rewrites25.4%
if 1.0500000000000001e103 < b Initial program 99.6%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (/ (- a -1.0) (+ (+ 1.0 a) 1.0)))
double code(double a, double b) {
return (a - -1.0) / ((1.0 + 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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a - (-1.0d0)) / ((1.0d0 + a) + 1.0d0)
end function
public static double code(double a, double b) {
return (a - -1.0) / ((1.0 + a) + 1.0);
}
def code(a, b): return (a - -1.0) / ((1.0 + a) + 1.0)
function code(a, b) return Float64(Float64(a - -1.0) / Float64(Float64(1.0 + a) + 1.0)) end
function tmp = code(a, b) tmp = (a - -1.0) / ((1.0 + a) + 1.0); end
code[a_, b_] := N[(N[(a - -1.0), $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a - -1}{\left(1 + a\right) + 1}
\end{array}
Initial program 98.9%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6480.9
Applied rewrites80.9%
Taylor expanded in a around 0
lower-+.f6481.9
Applied rewrites81.9%
Taylor expanded in b around 0
Applied rewrites40.2%
(FPCore (a b) :precision binary64 (fma (fma (* a a) -0.020833333333333332 0.25) a 0.5))
double code(double a, double b) {
return fma(fma((a * a), -0.020833333333333332, 0.25), a, 0.5);
}
function code(a, b) return fma(fma(Float64(a * a), -0.020833333333333332, 0.25), a, 0.5) end
code[a_, b_] := N[(N[(N[(a * a), $MachinePrecision] * -0.020833333333333332 + 0.25), $MachinePrecision] * a + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, -0.020833333333333332, 0.25\right), a, 0.5\right)
\end{array}
Initial program 98.9%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites63.9%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
Applied rewrites37.6%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6439.7
Applied rewrites39.7%
(FPCore (a b) :precision binary64 (fma 0.25 a 0.5))
double code(double a, double b) {
return fma(0.25, a, 0.5);
}
function code(a, b) return fma(0.25, a, 0.5) end
code[a_, b_] := N[(0.25 * a + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.25, a, 0.5\right)
\end{array}
Initial program 98.9%
Taylor expanded in b around 0
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
pow-to-expN/A
div-expN/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log1p.f64N/A
lift-exp.f64N/A
Applied rewrites63.9%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-commutativeN/A
pow-to-expN/A
metadata-evalN/A
lower-*.f64N/A
lift-neg.f6437.7
Applied rewrites37.7%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f6439.8
Applied rewrites39.8%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 98.9%
Taylor expanded in a around 0
inv-powN/A
lower-pow.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f6481.4
Applied rewrites81.4%
Taylor expanded in b around 0
Applied rewrites39.5%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
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, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2025088
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))