
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
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 11 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));
}
real(8) function code(a, b)
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 (<= (exp a) 0.0) (* (exp a) 0.5) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) * 0.5;
} else {
tmp = 1.0 / (exp(b) + 1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.0d0) then
tmp = exp(a) * 0.5d0
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 (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) * 0.5;
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) * 0.5 else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) * 0.5); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) * 0.5; else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] * 0.5), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified100.0%
lift-exp.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64100.0
Applied egg-rr100.0%
if 0.0 < (exp.f64 a) Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6499.5
Simplified99.5%
Final simplification99.6%
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
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 99.6%
(FPCore (a b) :precision binary64 (if (<= (exp b) 2.0) 0.5 (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (exp(b) <= 2.0) {
tmp = 0.5;
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(b) <= 2.0d0) then
tmp = 0.5d0
else
tmp = 6.0d0 / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(b) <= 2.0) {
tmp = 0.5;
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(b) <= 2.0: tmp = 0.5 else: tmp = 6.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (exp(b) <= 2.0) tmp = 0.5; else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(b) <= 2.0) tmp = 0.5; else tmp = 6.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], 0.5, N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if (exp.f64 b) < 2Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6475.0
Simplified75.0%
Taylor expanded in b around 0
Simplified51.6%
if 2 < (exp.f64 b) Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Simplified100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.8
Simplified66.8%
Taylor expanded in b around inf
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.8
Simplified66.8%
(FPCore (a b)
:precision binary64
(if (<= b 5.4e+52)
(* (exp a) 0.5)
(/
1.0
(fma
b
(/
(fma
(fma b 0.16666666666666666 0.5)
(* b (* b (fma b 0.16666666666666666 0.5)))
-1.0)
-1.0)
2.0))))
double code(double a, double b) {
double tmp;
if (b <= 5.4e+52) {
tmp = exp(a) * 0.5;
} else {
tmp = 1.0 / fma(b, (fma(fma(b, 0.16666666666666666, 0.5), (b * (b * fma(b, 0.16666666666666666, 0.5))), -1.0) / -1.0), 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 5.4e+52) tmp = Float64(exp(a) * 0.5); else tmp = Float64(1.0 / fma(b, Float64(fma(fma(b, 0.16666666666666666, 0.5), Float64(b * Float64(b * fma(b, 0.16666666666666666, 0.5))), -1.0) / -1.0), 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, 5.4e+52], N[(N[Exp[a], $MachinePrecision] * 0.5), $MachinePrecision], N[(1.0 / N[(b * N[(N[(N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] * N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.4 \cdot 10^{+52}:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \frac{\mathsf{fma}\left(\mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), b \cdot \left(b \cdot \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right)\right), -1\right)}{-1}, 2\right)}\\
\end{array}
\end{array}
if b < 5.4e52Initial program 99.5%
Taylor expanded in b around 0
Simplified74.2%
Taylor expanded in a around 0
Simplified73.6%
lift-exp.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6473.6
Applied egg-rr73.6%
if 5.4e52 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Simplified100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.6
Simplified76.6%
lift-fma.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6427.4
Applied egg-rr27.4%
Taylor expanded in b around 0
Simplified97.2%
(FPCore (a b)
:precision binary64
(if (<= a -1.15e+34)
(* 0.020833333333333332 (* b (* b b)))
(/
1.0
(fma
b
(/
(fma
(fma b 0.16666666666666666 0.5)
(* b (* b (fma b 0.16666666666666666 0.5)))
-1.0)
-1.0)
2.0))))
double code(double a, double b) {
double tmp;
if (a <= -1.15e+34) {
tmp = 0.020833333333333332 * (b * (b * b));
} else {
tmp = 1.0 / fma(b, (fma(fma(b, 0.16666666666666666, 0.5), (b * (b * fma(b, 0.16666666666666666, 0.5))), -1.0) / -1.0), 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -1.15e+34) tmp = Float64(0.020833333333333332 * Float64(b * Float64(b * b))); else tmp = Float64(1.0 / fma(b, Float64(fma(fma(b, 0.16666666666666666, 0.5), Float64(b * Float64(b * fma(b, 0.16666666666666666, 0.5))), -1.0) / -1.0), 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -1.15e+34], N[(0.020833333333333332 * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(N[(N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] * N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.15 \cdot 10^{+34}:\\
\;\;\;\;0.020833333333333332 \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \frac{\mathsf{fma}\left(\mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), b \cdot \left(b \cdot \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right)\right), -1\right)}{-1}, 2\right)}\\
\end{array}
\end{array}
if a < -1.1499999999999999e34Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6430.6
Simplified30.6%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f642.7
Simplified2.7%
Taylor expanded in b around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6448.4
Simplified48.4%
if -1.1499999999999999e34 < a Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Simplified98.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6461.7
Simplified61.7%
lift-fma.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6450.3
Applied egg-rr50.3%
Taylor expanded in b around 0
Simplified68.2%
(FPCore (a b) :precision binary64 (if (<= a -2.4e+30) (* 0.020833333333333332 (* b (* b b))) (/ 1.0 (fma b (fma b (fma b 0.16666666666666666 0.5) 1.0) 2.0))))
double code(double a, double b) {
double tmp;
if (a <= -2.4e+30) {
tmp = 0.020833333333333332 * (b * (b * b));
} else {
tmp = 1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -2.4e+30) tmp = Float64(0.020833333333333332 * Float64(b * Float64(b * b))); else tmp = Float64(1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -2.4e+30], N[(0.020833333333333332 * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{+30}:\\
\;\;\;\;0.020833333333333332 \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\
\end{array}
\end{array}
if a < -2.3999999999999999e30Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6430.6
Simplified30.6%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f642.7
Simplified2.7%
Taylor expanded in b around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6448.4
Simplified48.4%
if -2.3999999999999999e30 < a Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Simplified98.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6461.7
Simplified61.7%
(FPCore (a b) :precision binary64 (if (<= a -2.4e+30) (* 0.020833333333333332 (* b (* b b))) (/ 1.0 (fma b (* 0.16666666666666666 (* b b)) 2.0))))
double code(double a, double b) {
double tmp;
if (a <= -2.4e+30) {
tmp = 0.020833333333333332 * (b * (b * b));
} else {
tmp = 1.0 / fma(b, (0.16666666666666666 * (b * b)), 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -2.4e+30) tmp = Float64(0.020833333333333332 * Float64(b * Float64(b * b))); else tmp = Float64(1.0 / fma(b, Float64(0.16666666666666666 * Float64(b * b)), 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -2.4e+30], N[(0.020833333333333332 * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(0.16666666666666666 * N[(b * b), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{+30}:\\
\;\;\;\;0.020833333333333332 \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, 0.16666666666666666 \cdot \left(b \cdot b\right), 2\right)}\\
\end{array}
\end{array}
if a < -2.3999999999999999e30Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6430.6
Simplified30.6%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f642.7
Simplified2.7%
Taylor expanded in b around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6448.4
Simplified48.4%
if -2.3999999999999999e30 < a Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Simplified98.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6461.7
Simplified61.7%
Taylor expanded in b around inf
lower-*.f64N/A
unpow2N/A
lower-*.f6461.1
Simplified61.1%
(FPCore (a b) :precision binary64 (if (<= a -2.4e+30) (* 0.020833333333333332 (* b (* b b))) (/ 1.0 (fma b (fma 0.5 b 1.0) 2.0))))
double code(double a, double b) {
double tmp;
if (a <= -2.4e+30) {
tmp = 0.020833333333333332 * (b * (b * b));
} else {
tmp = 1.0 / fma(b, fma(0.5, b, 1.0), 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -2.4e+30) tmp = Float64(0.020833333333333332 * Float64(b * Float64(b * b))); else tmp = Float64(1.0 / fma(b, fma(0.5, b, 1.0), 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -2.4e+30], N[(0.020833333333333332 * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(0.5 * b + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{+30}:\\
\;\;\;\;0.020833333333333332 \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(0.5, b, 1\right), 2\right)}\\
\end{array}
\end{array}
if a < -2.3999999999999999e30Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6430.6
Simplified30.6%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f642.7
Simplified2.7%
Taylor expanded in b around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6448.4
Simplified48.4%
if -2.3999999999999999e30 < a Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Simplified98.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6458.4
Simplified58.4%
(FPCore (a b) :precision binary64 (if (<= b 2.0) 0.5 (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.0d0) then
tmp = 0.5d0
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 0.5 else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = 0.5; else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.0) tmp = 0.5; else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], 0.5, N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6475.0
Simplified75.0%
Taylor expanded in b around 0
Simplified51.6%
if 2 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Simplified100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.8
Simplified66.8%
Taylor expanded in b around inf
cube-multN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6466.8
Simplified66.8%
Taylor expanded in b around 0
lower-/.f64N/A
unpow2N/A
lower-*.f6452.6
Simplified52.6%
(FPCore (a b) :precision binary64 (if (<= a -61000000000.0) (* 0.020833333333333332 (* b (* b b))) (fma 0.25 a 0.5)))
double code(double a, double b) {
double tmp;
if (a <= -61000000000.0) {
tmp = 0.020833333333333332 * (b * (b * b));
} else {
tmp = fma(0.25, a, 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -61000000000.0) tmp = Float64(0.020833333333333332 * Float64(b * Float64(b * b))); else tmp = fma(0.25, a, 0.5); end return tmp end
code[a_, b_] := If[LessEqual[a, -61000000000.0], N[(0.020833333333333332 * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.25 * a + 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -61000000000:\\
\;\;\;\;0.020833333333333332 \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\
\end{array}
\end{array}
if a < -6.1e10Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6431.4
Simplified31.4%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f642.7
Simplified2.7%
Taylor expanded in b around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6446.4
Simplified46.4%
if -6.1e10 < a Initial program 99.5%
Taylor expanded in b around 0
Simplified50.2%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f6449.3
Simplified49.3%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
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 99.6%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6482.2
Simplified82.2%
Taylor expanded in b around 0
Simplified37.6%
(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)));
}
real(8) function code(a, b)
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 2024207
(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))))