
(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 (exp (- (log1p (exp (- b a))))))
double code(double a, double b) {
return exp(-log1p(exp((b - a))));
}
public static double code(double a, double b) {
return Math.exp(-Math.log1p(Math.exp((b - a))));
}
def code(a, b): return math.exp(-math.log1p(math.exp((b - a))))
function code(a, b) return exp(Float64(-log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[(-N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{b - a}\right)}
\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-sub72.2%
*-lft-identity72.2%
associate-*l/72.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
div-exp99.6%
+-commutative99.6%
metadata-eval99.6%
sub-neg99.6%
add-exp-log99.6%
rec-exp99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
log1p-define99.6%
div-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.998) (/ 1.0 (- (exp (- a)) -1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.998) {
tmp = 1.0 / (exp(-a) - -1.0);
} 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.998d0) then
tmp = 1.0d0 / (exp(-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 (Math.exp(a) <= 0.998) {
tmp = 1.0 / (Math.exp(-a) - -1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.998: tmp = 1.0 / (math.exp(-a) - -1.0) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.998) tmp = Float64(1.0 / Float64(exp(Float64(-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 (exp(a) <= 0.998) tmp = 1.0 / (exp(-a) - -1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.998], N[(1.0 / N[(N[Exp[(-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}\;e^{a} \leq 0.998:\\
\;\;\;\;\frac{1}{e^{-a} - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.998Initial program 98.6%
*-lft-identity98.6%
associate-*l/98.6%
associate-/r/98.6%
+-commutative98.6%
remove-double-neg98.6%
sub-neg98.6%
div-sub4.0%
neg-mul-14.0%
*-commutative4.0%
associate-*r/4.0%
metadata-eval4.0%
distribute-neg-frac4.0%
exp-neg4.0%
distribute-rgt-neg-out4.0%
exp-neg4.0%
rgt-mult-inverse98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
if 0.998 < (exp.f64 a) Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-*r/100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
exp-neg99.9%
distribute-rgt-neg-out99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 99.1%
Final simplification99.3%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.998) (/ (exp a) 2.0) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.998) {
tmp = exp(a) / 2.0;
} 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.998d0) then
tmp = exp(a) / 2.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 (Math.exp(a) <= 0.998) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.998: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.998) tmp = Float64(exp(a) / 2.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 (exp(a) <= 0.998) tmp = exp(a) / 2.0; else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.998], N[(N[Exp[a], $MachinePrecision] / 2.0), $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.998:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.998Initial program 98.6%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 96.9%
if 0.998 < (exp.f64 a) Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-*r/100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
exp-neg99.9%
distribute-rgt-neg-out99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 99.1%
Final simplification98.4%
(FPCore (a b)
:precision binary64
(if (<= b -920.0)
(+ 1.0 (exp b))
(if (<= b 1.05e+103)
(/ (exp a) 2.0)
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -920.0) {
tmp = 1.0 + exp(b);
} else if (b <= 1.05e+103) {
tmp = exp(a) / 2.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 <= (-920.0d0)) then
tmp = 1.0d0 + exp(b)
else if (b <= 1.05d+103) then
tmp = exp(a) / 2.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 <= -920.0) {
tmp = 1.0 + Math.exp(b);
} else if (b <= 1.05e+103) {
tmp = Math.exp(a) / 2.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 <= -920.0: tmp = 1.0 + math.exp(b) elif b <= 1.05e+103: tmp = math.exp(a) / 2.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 <= -920.0) tmp = Float64(1.0 + exp(b)); elseif (b <= 1.05e+103) tmp = Float64(exp(a) / 2.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 <= -920.0) tmp = 1.0 + exp(b); elseif (b <= 1.05e+103) tmp = exp(a) / 2.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, -920.0], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e+103], N[(N[Exp[a], $MachinePrecision] / 2.0), $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 -920:\\
\;\;\;\;1 + e^{b}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\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 < -920Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-lft-identity100.0%
associate-*l/100.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
div-exp100.0%
+-commutative100.0%
metadata-eval100.0%
sub-neg100.0%
add-exp-log100.0%
rec-exp100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.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-sqrt100.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
log1p-undefine100.0%
rem-exp-log100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -920 < b < 1.0500000000000001e103Initial program 99.4%
Taylor expanded in b around 0 91.2%
Taylor expanded in a around 0 88.8%
if 1.0500000000000001e103 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub56.8%
neg-mul-156.8%
*-commutative56.8%
associate-*r/56.8%
metadata-eval56.8%
distribute-neg-frac56.8%
exp-neg56.8%
distribute-rgt-neg-out56.8%
exp-neg56.8%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification92.8%
(FPCore (a b)
:precision binary64
(if (<= b -1.7)
(+ 1.0 (exp b))
(if (<= b 2.7e+77)
(/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666)))))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -1.7) {
tmp = 1.0 + exp(b);
} else if (b <= 2.7e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.7d0)) then
tmp = 1.0d0 + exp(b)
else if (b <= 2.7d+77) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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.7) {
tmp = 1.0 + Math.exp(b);
} else if (b <= 2.7e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.7: tmp = 1.0 + math.exp(b) elif b <= 2.7e+77: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) 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.7) tmp = Float64(1.0 + exp(b)); elseif (b <= 2.7e+77) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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.7) tmp = 1.0 + exp(b); elseif (b <= 2.7e+77) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); 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.7], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.7e+77], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.7:\\
\;\;\;\;1 + e^{b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\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.69999999999999996Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub98.0%
*-lft-identity98.0%
associate-*l/98.0%
lft-mult-inverse98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
div-exp100.0%
Simplified100.0%
div-exp98.0%
+-commutative98.0%
metadata-eval98.0%
sub-neg98.0%
add-exp-log98.0%
rec-exp98.0%
sub-neg98.0%
metadata-eval98.0%
+-commutative98.0%
log1p-define98.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around 0 98.1%
log1p-define98.1%
Simplified98.1%
add-sqr-sqrt96.1%
sqrt-unprod97.5%
sqr-neg97.5%
sqrt-unprod97.5%
add-sqr-sqrt97.5%
log1p-undefine97.5%
rem-exp-log97.5%
+-commutative97.5%
Applied egg-rr97.5%
if -1.69999999999999996 < b < 2.6999999999999998e77Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/99.9%
+-commutative99.9%
remove-double-neg99.9%
sub-neg99.9%
div-sub68.3%
neg-mul-168.3%
*-commutative68.3%
associate-*r/68.3%
metadata-eval68.3%
distribute-neg-frac68.3%
exp-neg68.3%
distribute-rgt-neg-out68.3%
exp-neg68.3%
rgt-mult-inverse99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in b around 0 93.2%
rec-exp93.2%
Simplified93.2%
Taylor expanded in a around 0 80.5%
if 2.6999999999999998e77 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub58.3%
neg-mul-158.3%
*-commutative58.3%
associate-*r/58.3%
metadata-eval58.3%
distribute-neg-frac58.3%
exp-neg58.3%
distribute-rgt-neg-out58.3%
exp-neg58.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 92.2%
*-commutative92.2%
Simplified92.2%
Final simplification86.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.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 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 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-sub72.2%
*-lft-identity72.2%
associate-*l/72.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b 1.25e+153) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e+153) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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+153) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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+153) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.25e+153: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) 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+153) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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+153) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); 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+153], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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^{+153}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.25000000000000005e153Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub72.7%
neg-mul-172.7%
*-commutative72.7%
associate-*r/72.7%
metadata-eval72.7%
distribute-neg-frac72.7%
exp-neg72.7%
distribute-rgt-neg-out72.7%
exp-neg72.7%
rgt-mult-inverse99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in b around 0 74.8%
rec-exp74.8%
Simplified74.8%
Taylor expanded in a around 0 63.8%
if 1.25000000000000005e153 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub68.8%
neg-mul-168.8%
*-commutative68.8%
associate-*r/68.8%
metadata-eval68.8%
distribute-neg-frac68.8%
exp-neg68.8%
distribute-rgt-neg-out68.8%
exp-neg68.8%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification68.3%
(FPCore (a b) :precision binary64 (if (<= b 2.7e+77) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 2.7e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.7d+77) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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.7e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.7e+77: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) 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.7e+77) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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.7e+77) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); 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.7e+77], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.7 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\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 < 2.6999999999999998e77Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub75.4%
neg-mul-175.4%
*-commutative75.4%
associate-*r/75.4%
metadata-eval75.4%
distribute-neg-frac75.4%
exp-neg75.4%
distribute-rgt-neg-out75.4%
exp-neg75.4%
rgt-mult-inverse99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in b around 0 75.7%
rec-exp75.7%
Simplified75.7%
Taylor expanded in a around 0 65.6%
if 2.6999999999999998e77 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub58.3%
neg-mul-158.3%
*-commutative58.3%
associate-*r/58.3%
metadata-eval58.3%
distribute-neg-frac58.3%
exp-neg58.3%
distribute-rgt-neg-out58.3%
exp-neg58.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 92.2%
*-commutative92.2%
Simplified92.2%
Final simplification70.6%
(FPCore (a b) :precision binary64 (if (<= b 1.95e+153) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.95e+153) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} 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.95d+153) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
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.95e+153) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.95e+153: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.95e+153) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))); 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.95e+153) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.95e+153], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $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.95 \cdot 10^{+153}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.94999999999999992e153Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub72.7%
neg-mul-172.7%
*-commutative72.7%
associate-*r/72.7%
metadata-eval72.7%
distribute-neg-frac72.7%
exp-neg72.7%
distribute-rgt-neg-out72.7%
exp-neg72.7%
rgt-mult-inverse99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in b around 0 74.8%
rec-exp74.8%
Simplified74.8%
Taylor expanded in a around 0 60.4%
if 1.94999999999999992e153 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub68.8%
neg-mul-168.8%
*-commutative68.8%
associate-*r/68.8%
metadata-eval68.8%
distribute-neg-frac68.8%
exp-neg68.8%
distribute-rgt-neg-out68.8%
exp-neg68.8%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification65.4%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
def code(a, b): return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.2%
neg-mul-172.2%
*-commutative72.2%
associate-*r/72.2%
metadata-eval72.2%
distribute-neg-frac72.2%
exp-neg72.2%
distribute-rgt-neg-out72.2%
exp-neg72.2%
rgt-mult-inverse99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in b around 0 69.6%
rec-exp69.6%
Simplified69.6%
Taylor expanded in a around 0 55.6%
Final simplification55.6%
(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%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.2%
neg-mul-172.2%
*-commutative72.2%
associate-*r/72.2%
metadata-eval72.2%
distribute-neg-frac72.2%
exp-neg72.2%
distribute-rgt-neg-out72.2%
exp-neg72.2%
rgt-mult-inverse99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in b around 0 69.6%
rec-exp69.6%
Simplified69.6%
Taylor expanded in a around 0 41.3%
*-commutative41.3%
Simplified41.3%
Final simplification41.3%
(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%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.2%
neg-mul-172.2%
*-commutative72.2%
associate-*r/72.2%
metadata-eval72.2%
distribute-neg-frac72.2%
exp-neg72.2%
distribute-rgt-neg-out72.2%
exp-neg72.2%
rgt-mult-inverse99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in b around 0 69.6%
rec-exp69.6%
Simplified69.6%
Taylor expanded in a around 0 42.0%
neg-mul-142.0%
unsub-neg42.0%
Simplified42.0%
Final simplification42.0%
(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%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.2%
neg-mul-172.2%
*-commutative72.2%
associate-*r/72.2%
metadata-eval72.2%
distribute-neg-frac72.2%
exp-neg72.2%
distribute-rgt-neg-out72.2%
exp-neg72.2%
rgt-mult-inverse99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 81.3%
Taylor expanded in b around 0 41.2%
Final simplification41.2%
(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 2024096
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))