
(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 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));
}
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 (/ 1.0 (+ (+ 2.0 (exp (- b a))) -1.0)))
double code(double a, double b) {
return 1.0 / ((2.0 + exp((b - a))) + -1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / ((2.0d0 + exp((b - a))) + (-1.0d0))
end function
public static double code(double a, double b) {
return 1.0 / ((2.0 + Math.exp((b - a))) + -1.0);
}
def code(a, b): return 1.0 / ((2.0 + math.exp((b - a))) + -1.0)
function code(a, b) return Float64(1.0 / Float64(Float64(2.0 + exp(Float64(b - a))) + -1.0)) end
function tmp = code(a, b) tmp = 1.0 / ((2.0 + exp((b - a))) + -1.0); end
code[a_, b_] := N[(1.0 / N[(N[(2.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(2 + e^{b - a}\right) + -1}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub76.9%
*-lft-identity76.9%
associate-*l/76.9%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
expm1-log1p-u99.4%
expm1-undefine99.4%
div-exp99.0%
+-commutative99.0%
div-exp99.4%
Applied egg-rr99.4%
sub-neg99.4%
log1p-undefine99.1%
rem-exp-log100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= a -8.6e-9) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -8.6e-9) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-8.6d-9)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -8.6e-9) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -8.6e-9: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -8.6e-9) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -8.6e-9) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -8.6e-9], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.6 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -8.59999999999999925e-9Initial program 99.9%
*-lft-identity99.9%
associate-*l/99.9%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/99.9%
exp-neg99.9%
metadata-eval99.9%
distribute-neg-frac99.9%
distribute-frac-neg299.9%
distribute-lft-neg-out99.9%
+-commutative99.9%
distribute-neg-in99.9%
sub-neg99.9%
*-commutative99.9%
sub-neg99.9%
distribute-neg-in99.9%
Simplified100.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
if -8.59999999999999925e-9 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
*-rgt-identity99.4%
associate-*r/99.4%
exp-neg99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
distribute-frac-neg299.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
distribute-neg-in99.4%
sub-neg99.4%
*-commutative99.4%
sub-neg99.4%
distribute-neg-in99.4%
Simplified99.4%
Taylor expanded in a around 0 98.8%
(FPCore (a b) :precision binary64 (if (<= a -1.02e-8) (/ (exp a) (+ 2.0 a)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -1.02e-8) {
tmp = exp(a) / (2.0 + a);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.02d-8)) then
tmp = exp(a) / (2.0d0 + a)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.02e-8) {
tmp = Math.exp(a) / (2.0 + a);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.02e-8: tmp = math.exp(a) / (2.0 + a) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.02e-8) tmp = Float64(exp(a) / Float64(2.0 + a)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.02e-8) tmp = exp(a) / (2.0 + a); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.02e-8], N[(N[Exp[a], $MachinePrecision] / N[(2.0 + a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.02 \cdot 10^{-8}:\\
\;\;\;\;\frac{e^{a}}{2 + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -1.02000000000000003e-8Initial program 99.9%
Taylor expanded in b around 0 99.9%
Taylor expanded in a around 0 99.0%
+-commutative99.0%
Simplified99.0%
if -1.02000000000000003e-8 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
*-rgt-identity99.4%
associate-*r/99.4%
exp-neg99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
distribute-frac-neg299.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
distribute-neg-in99.4%
sub-neg99.4%
*-commutative99.4%
sub-neg99.4%
distribute-neg-in99.4%
Simplified99.4%
Taylor expanded in a around 0 98.8%
Final simplification98.8%
(FPCore (a b) :precision binary64 (if (<= a -550000.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -550000.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-550000.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -550000.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -550000.0: tmp = math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -550000.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -550000.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -550000.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -550000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -5.5e5Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -5.5e5 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
*-rgt-identity99.4%
associate-*r/99.4%
exp-neg99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
distribute-frac-neg299.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
distribute-neg-in99.4%
sub-neg99.4%
*-commutative99.4%
sub-neg99.4%
distribute-neg-in99.4%
Simplified99.4%
Taylor expanded in a around 0 97.8%
(FPCore (a b)
:precision binary64
(if (<= b -2.0)
(+ 1.0 (exp b))
(if (<= b 1.25e+90)
(/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0 + exp(b);
} else if (b <= 1.25e+90) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
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 = 1.0d0 + exp(b)
else if (b <= 1.25d+90) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0 + Math.exp(b);
} else if (b <= 1.25e+90) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 1.0 + math.exp(b) elif b <= 1.25e+90: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = Float64(1.0 + exp(b)); elseif (b <= 1.25e+90) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 1.0 + exp(b); elseif (b <= 1.25e+90) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.25e+90], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;1 + e^{b}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+90}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < -2Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg99.9%
metadata-eval99.9%
distribute-neg-frac99.9%
distribute-frac-neg299.9%
distribute-lft-neg-out99.9%
+-commutative99.9%
distribute-neg-in99.9%
sub-neg99.9%
*-commutative99.9%
sub-neg99.9%
distribute-neg-in99.9%
Simplified100.0%
add-exp-log100.0%
log-div0.0%
sub-neg0.0%
metadata-eval0.0%
distribute-neg-in0.0%
div-exp0.0%
log-div100.0%
metadata-eval100.0%
frac-2neg100.0%
div-exp100.0%
log-rec100.0%
log1p-define100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around 0 100.0%
log1p-define100.0%
Simplified100.0%
add-sqr-sqrt98.1%
sqrt-unprod98.5%
sqr-neg98.5%
sqrt-unprod98.5%
add-sqr-sqrt98.5%
log1p-undefine98.5%
rem-exp-log98.5%
+-commutative98.5%
Applied egg-rr98.5%
if -2 < b < 1.2500000000000001e90Initial program 99.3%
*-lft-identity99.3%
associate-*l/99.3%
associate-/r/99.3%
*-rgt-identity99.3%
associate-*r/99.3%
exp-neg99.3%
metadata-eval99.3%
distribute-neg-frac99.3%
distribute-frac-neg299.3%
distribute-lft-neg-out99.3%
+-commutative99.3%
distribute-neg-in99.3%
sub-neg99.3%
*-commutative99.3%
sub-neg99.3%
distribute-neg-in99.3%
Simplified99.3%
Taylor expanded in b around 0 89.6%
Taylor expanded in a around 0 79.5%
if 1.2500000000000001e90 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 92.0%
*-commutative92.0%
Simplified92.0%
Final simplification85.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)));
}
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}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub76.9%
*-lft-identity76.9%
associate-*l/76.9%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= b 1.36e+91) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 1.36e+91) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.36d+91) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.36e+91) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.36e+91: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.36e+91) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.36e+91) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.36e+91], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.36 \cdot 10^{+91}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 1.36000000000000007e91Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
*-rgt-identity99.5%
associate-*r/99.5%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.5%
Taylor expanded in b around 0 72.3%
Taylor expanded in a around 0 64.1%
if 1.36000000000000007e91 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 92.0%
*-commutative92.0%
Simplified92.0%
Final simplification69.0%
(FPCore (a b) :precision binary64 (if (<= b 1.25e+149) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e+149) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.25d+149) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.25e+149) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.25e+149: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.25e+149) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.25e+149) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.25e+149], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{+149}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.24999999999999998e149Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
*-rgt-identity99.5%
associate-*r/99.5%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.5%
Taylor expanded in b around 0 70.2%
Taylor expanded in a around 0 62.0%
if 1.24999999999999998e149 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 97.4%
*-commutative97.4%
Simplified97.4%
Final simplification66.7%
(FPCore (a b) :precision binary64 (if (<= b 9e+148) (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 9e+148) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 9d+148) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 9e+148) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 9e+148: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 9e+148) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 9e+148) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 9e+148], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{+148}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 8.99999999999999987e148Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
*-rgt-identity99.5%
associate-*r/99.5%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.5%
Taylor expanded in b around 0 70.2%
Taylor expanded in a around 0 59.0%
if 8.99999999999999987e148 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 97.4%
*-commutative97.4%
Simplified97.4%
Final simplification64.1%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
def code(a, b): return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
*-rgt-identity99.6%
associate-*r/99.6%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.6%
Taylor expanded in b around 0 65.4%
Taylor expanded in a around 0 53.9%
Final simplification53.9%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
*-rgt-identity99.6%
associate-*r/99.6%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.6%
Taylor expanded in b around 0 65.4%
Taylor expanded in a around 0 42.7%
neg-mul-142.7%
unsub-neg42.7%
Simplified42.7%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
*-rgt-identity99.6%
associate-*r/99.6%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.6%
Taylor expanded in b around 0 65.4%
Taylor expanded in a around 0 42.6%
*-commutative42.6%
Simplified42.6%
(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%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
*-rgt-identity99.6%
associate-*r/99.6%
exp-neg99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
distribute-frac-neg299.5%
distribute-lft-neg-out99.5%
+-commutative99.5%
distribute-neg-in99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
distribute-neg-in99.5%
Simplified99.6%
Taylor expanded in a around 0 83.2%
Taylor expanded in b around 0 41.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)));
}
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 2024151
(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))))