
(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}
Sampling outcomes in binary64 precision:
Herbie found 12 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 (if (<= a -2900000000.0) (/ (exp a) (+ (+ 1.0 a) 1.0)) (/ (+ 1.0 a) (+ (- a -1.0) (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -2900000000.0) {
tmp = exp(a) / ((1.0 + a) + 1.0);
} else {
tmp = (1.0 + a) / ((a - -1.0) + 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 <= (-2900000000.0d0)) then
tmp = exp(a) / ((1.0d0 + a) + 1.0d0)
else
tmp = (1.0d0 + a) / ((a - (-1.0d0)) + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2900000000.0) {
tmp = Math.exp(a) / ((1.0 + a) + 1.0);
} else {
tmp = (1.0 + a) / ((a - -1.0) + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2900000000.0: tmp = math.exp(a) / ((1.0 + a) + 1.0) else: tmp = (1.0 + a) / ((a - -1.0) + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -2900000000.0) tmp = Float64(exp(a) / Float64(Float64(1.0 + a) + 1.0)); else tmp = Float64(Float64(1.0 + a) / Float64(Float64(a - -1.0) + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2900000000.0) tmp = exp(a) / ((1.0 + a) + 1.0); else tmp = (1.0 + a) / ((a - -1.0) + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2900000000.0], N[(N[Exp[a], $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(N[(a - -1.0), $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2900000000:\\
\;\;\;\;\frac{e^{a}}{\left(1 + a\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{\left(a - -1\right) + e^{b}}\\
\end{array}
\end{array}
if a < -2.9e9Initial program 100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
if -2.9e9 < a Initial program 97.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--.f6497.4
Applied rewrites97.4%
Taylor expanded in a around 0
lower-+.f6499.7
Applied rewrites99.7%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ (exp a) (+ (exp a) (exp b))))
(t_1
(+
(- a -1.0)
(fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0))))
(if (<= t_0 0.0)
(/ a t_1)
(if (<= t_0 0.6) (/ (+ 1.0 a) t_1) (/ (+ 1.0 a) (+ a 1.0))))))
double code(double a, double b) {
double t_0 = exp(a) / (exp(a) + exp(b));
double t_1 = (a - -1.0) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0);
double tmp;
if (t_0 <= 0.0) {
tmp = a / t_1;
} else if (t_0 <= 0.6) {
tmp = (1.0 + a) / t_1;
} else {
tmp = (1.0 + a) / (a + 1.0);
}
return tmp;
}
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(a) + exp(b))) t_1 = Float64(Float64(a - -1.0) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(a / t_1); elseif (t_0 <= 0.6) tmp = Float64(Float64(1.0 + a) / t_1); else tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a - -1.0), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(a / t$95$1), $MachinePrecision], If[LessEqual[t$95$0, 0.6], N[(N[(1.0 + a), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
t_1 := \left(a - -1\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 1\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{a}{t\_1}\\
\mathbf{elif}\;t\_0 \leq 0.6:\\
\;\;\;\;\frac{1 + a}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\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--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f6470.5
Applied rewrites70.5%
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.f6446.4
Applied rewrites46.4%
Taylor expanded in a around inf
Applied rewrites51.3%
if 0.0 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 99.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--.f6499.9
Applied rewrites99.9%
Taylor expanded in a around 0
lower-+.f6499.9
Applied rewrites99.9%
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.f6499.9
Applied rewrites99.9%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 92.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--.f6490.9
Applied rewrites90.9%
Taylor expanded in a around 0
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in b around 0
Applied rewrites20.8%
Taylor expanded in a around inf
Applied rewrites96.7%
Final simplification77.4%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ (exp a) (+ (exp a) (exp b)))))
(if (<= t_0 0.0)
(/
a
(+ (- a -1.0) (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0)))
(if (<= t_0 0.8397875060102299)
(fma a 0.25 (fma 0.25 (- b) 0.5))
(/ (+ 1.0 a) (+ a 1.0))))))
double code(double a, double b) {
double t_0 = exp(a) / (exp(a) + exp(b));
double tmp;
if (t_0 <= 0.0) {
tmp = a / ((a - -1.0) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0));
} else if (t_0 <= 0.8397875060102299) {
tmp = fma(a, 0.25, fma(0.25, -b, 0.5));
} else {
tmp = (1.0 + a) / (a + 1.0);
}
return tmp;
}
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(a) + exp(b))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(a / Float64(Float64(a - -1.0) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0))); elseif (t_0 <= 0.8397875060102299) tmp = fma(a, 0.25, fma(0.25, Float64(-b), 0.5)); else tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(a / N[(N[(a - -1.0), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.8397875060102299], N[(a * 0.25 + N[(0.25 * (-b) + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{a}{\left(a - -1\right) + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 1\right)}\\
\mathbf{elif}\;t\_0 \leq 0.8397875060102299:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, \mathsf{fma}\left(0.25, -b, 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\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--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f6470.5
Applied rewrites70.5%
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.f6446.4
Applied rewrites46.4%
Taylor expanded in a around inf
Applied rewrites51.3%
if 0.0 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.839787506010229889Initial program 99.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 rewrites98.8%
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.f6498.8
Applied rewrites98.8%
lift-+.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
mul-1-negN/A
metadata-evalN/A
metadata-evalN/A
pow-to-expN/A
*-commutativeN/A
exp-negN/A
associate-*r*N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites98.8%
if 0.839787506010229889 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 92.5%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6490.8
Applied rewrites90.8%
Taylor expanded in a around 0
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in b around 0
Applied rewrites20.8%
Taylor expanded in a around inf
Applied rewrites98.2%
Final simplification77.3%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.6) (/ 1.0 (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 2.0)) (/ (+ 1.0 a) (+ a 1.0))))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.6) {
tmp = 1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0);
} else {
tmp = (1.0 + a) / (a + 1.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.6) tmp = Float64(1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0)); else tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); 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.6], N[(1.0 / N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 100.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.f6482.7
Applied rewrites82.7%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6482.7
Applied rewrites82.7%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-fma.f64N/A
lift-fma.f6469.1
Applied rewrites69.1%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 92.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--.f6490.9
Applied rewrites90.9%
Taylor expanded in a around 0
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in b around 0
Applied rewrites20.8%
Taylor expanded in a around inf
Applied rewrites96.7%
Final simplification74.9%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.6) (/ 1.0 (fma (fma 0.5 b 1.0) b 2.0)) (/ (+ 1.0 a) (+ a 1.0))))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.6) {
tmp = 1.0 / fma(fma(0.5, b, 1.0), b, 2.0);
} else {
tmp = (1.0 + a) / (a + 1.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.6) tmp = Float64(1.0 / fma(fma(0.5, b, 1.0), b, 2.0)); else tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); 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.6], N[(1.0 / N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 100.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.f6482.7
Applied rewrites82.7%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6460.3
Applied rewrites60.3%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6460.3
Applied rewrites60.3%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 92.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--.f6490.9
Applied rewrites90.9%
Taylor expanded in a around 0
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in b around 0
Applied rewrites20.8%
Taylor expanded in a around inf
Applied rewrites96.7%
Final simplification68.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.6) (/ 1.0 (+ 2.0 b)) (/ (+ 1.0 a) (+ a 1.0))))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.6) {
tmp = 1.0 / (2.0 + b);
} else {
tmp = (1.0 + a) / (a + 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 ((exp(a) / (exp(a) + exp(b))) <= 0.6d0) then
tmp = 1.0d0 / (2.0d0 + b)
else
tmp = (1.0d0 + a) / (a + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((Math.exp(a) / (Math.exp(a) + Math.exp(b))) <= 0.6) {
tmp = 1.0 / (2.0 + b);
} else {
tmp = (1.0 + a) / (a + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (math.exp(a) / (math.exp(a) + math.exp(b))) <= 0.6: tmp = 1.0 / (2.0 + b) else: tmp = (1.0 + a) / (a + 1.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.6) tmp = Float64(1.0 / Float64(2.0 + b)); else tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((exp(a) / (exp(a) + exp(b))) <= 0.6) tmp = 1.0 / (2.0 + b); else tmp = (1.0 + a) / (a + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.6], N[(1.0 / N[(2.0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\
\;\;\;\;\frac{1}{2 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 100.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.f6482.7
Applied rewrites82.7%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6482.7
Applied rewrites82.7%
Taylor expanded in b around 0
lower-+.f6444.9
Applied rewrites44.9%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 92.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--.f6490.9
Applied rewrites90.9%
Taylor expanded in a around 0
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in b around 0
Applied rewrites20.8%
Taylor expanded in a around inf
Applied rewrites96.7%
Final simplification55.9%
(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.4%
(FPCore (a b) :precision binary64 (if (<= a -2900000000.0) (/ (exp a) (+ (+ 1.0 a) 1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -2900000000.0) {
tmp = exp(a) / ((1.0 + a) + 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 <= (-2900000000.0d0)) then
tmp = exp(a) / ((1.0d0 + a) + 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 <= -2900000000.0) {
tmp = Math.exp(a) / ((1.0 + a) + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2900000000.0: tmp = math.exp(a) / ((1.0 + a) + 1.0) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -2900000000.0) tmp = Float64(exp(a) / Float64(Float64(1.0 + a) + 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 <= -2900000000.0) tmp = exp(a) / ((1.0 + a) + 1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2900000000.0], N[(N[Exp[a], $MachinePrecision] / N[(N[(1.0 + a), $MachinePrecision] + 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 -2900000000:\\
\;\;\;\;\frac{e^{a}}{\left(1 + a\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -2.9e9Initial program 100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
if -2.9e9 < a Initial program 97.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.f6499.0
Applied rewrites99.0%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6499.0
Applied rewrites99.0%
(FPCore (a b) :precision binary64 (if (<= a -1.32e+154) (/ (+ 1.0 a) (+ (/ (- (* a a) 1.0) (- a 1.0)) 1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -1.32e+154) {
tmp = (1.0 + a) / ((((a * a) - 1.0) / (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 <= (-1.32d+154)) then
tmp = (1.0d0 + a) / ((((a * a) - 1.0d0) / (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 <= -1.32e+154) {
tmp = (1.0 + a) / ((((a * a) - 1.0) / (a - 1.0)) + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.32e+154: tmp = (1.0 + a) / ((((a * a) - 1.0) / (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 <= -1.32e+154) tmp = Float64(Float64(1.0 + a) / Float64(Float64(Float64(Float64(a * a) - 1.0) / Float64(a - 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 <= -1.32e+154) tmp = (1.0 + a) / ((((a * a) - 1.0) / (a - 1.0)) + 1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.32e+154], N[(N[(1.0 + a), $MachinePrecision] / N[(N[(N[(N[(a * a), $MachinePrecision] - 1.0), $MachinePrecision] / N[(a - 1.0), $MachinePrecision]), $MachinePrecision] + 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 -1.32 \cdot 10^{+154}:\\
\;\;\;\;\frac{1 + a}{\frac{a \cdot a - 1}{a - 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -1.31999999999999998e154Initial 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--.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
lower-+.f6436.3
Applied rewrites36.3%
Taylor expanded in b around 0
Applied rewrites3.1%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
if -1.31999999999999998e154 < a Initial program 98.2%
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.f6493.9
Applied rewrites93.9%
lift-pow.f64N/A
lift--.f64N/A
lift-exp.f64N/A
unpow-1N/A
lower-/.f64N/A
lift-exp.f64N/A
lift--.f6493.9
Applied rewrites93.9%
Final simplification94.7%
(FPCore (a b)
:precision binary64
(if (<= b -0.3)
(/ (+ 1.0 a) (+ a 1.0))
(if (<= b 1.2e+63)
(/ (+ 1.0 a) (+ (/ (- (* a a) 1.0) (- a 1.0)) 1.0))
(/
a
(+
(- a -1.0)
(fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -0.3) {
tmp = (1.0 + a) / (a + 1.0);
} else if (b <= 1.2e+63) {
tmp = (1.0 + a) / ((((a * a) - 1.0) / (a - 1.0)) + 1.0);
} else {
tmp = a / ((a - -1.0) + 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 <= -0.3) tmp = Float64(Float64(1.0 + a) / Float64(a + 1.0)); elseif (b <= 1.2e+63) tmp = Float64(Float64(1.0 + a) / Float64(Float64(Float64(Float64(a * a) - 1.0) / Float64(a - 1.0)) + 1.0)); else tmp = Float64(a / Float64(Float64(a - -1.0) + fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 1.0))); end return tmp end
code[a_, b_] := If[LessEqual[b, -0.3], N[(N[(1.0 + a), $MachinePrecision] / N[(a + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.2e+63], N[(N[(1.0 + a), $MachinePrecision] / N[(N[(N[(N[(a * a), $MachinePrecision] - 1.0), $MachinePrecision] / N[(a - 1.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(a / N[(N[(a - -1.0), $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 -0.3:\\
\;\;\;\;\frac{1 + a}{a + 1}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{1 + a}{\frac{a \cdot a - 1}{a - 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\left(a - -1\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 < -0.299999999999999989Initial program 96.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--.f6494.4
Applied rewrites94.4%
Taylor expanded in a around 0
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites20.5%
Taylor expanded in a around inf
Applied rewrites98.5%
if -0.299999999999999989 < b < 1.2e63Initial program 98.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--.f6498.6
Applied rewrites98.6%
Taylor expanded in a around 0
lower-+.f6475.8
Applied rewrites75.8%
Taylor expanded in b around 0
Applied rewrites62.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6480.7
Applied rewrites80.7%
if 1.2e63 < b Initial 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--.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.f6483.3
Applied rewrites83.3%
Taylor expanded in a around inf
Applied rewrites91.4%
Final simplification86.9%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (- a -1.0) 1.0)))
double code(double a, double b) {
return 1.0 / ((a - -1.0) + 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 = 1.0d0 / ((a - (-1.0d0)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / ((a - -1.0) + 1.0);
}
def code(a, b): return 1.0 / ((a - -1.0) + 1.0)
function code(a, b) return Float64(1.0 / Float64(Float64(a - -1.0) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / ((a - -1.0) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[(a - -1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(a - -1\right) + 1}
\end{array}
Initial program 98.4%
Taylor expanded in a around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6498.1
Applied rewrites98.1%
Taylor expanded in a around 0
lower-+.f6486.6
Applied rewrites86.6%
Taylor expanded in b around 0
Applied rewrites39.5%
Taylor expanded in a around 0
Applied rewrites39.2%
(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.4%
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.f6486.0
Applied rewrites86.0%
Taylor expanded in b around 0
Applied rewrites38.7%
(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 2025051
(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))))