
(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 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));
}
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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-log-exp99.5%
*-un-lft-identity99.5%
log-prod99.5%
metadata-eval99.5%
add-log-exp100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (or (<= b -1700.0) (not (<= b 2.6e-18))) (/ 1.0 (+ 1.0 (exp b))) (/ 1.0 (+ 1.0 (exp (- a))))))
double code(double a, double b) {
double tmp;
if ((b <= -1700.0) || !(b <= 2.6e-18)) {
tmp = 1.0 / (1.0 + exp(b));
} else {
tmp = 1.0 / (1.0 + exp(-a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-1700.0d0)) .or. (.not. (b <= 2.6d-18))) then
tmp = 1.0d0 / (1.0d0 + exp(b))
else
tmp = 1.0d0 / (1.0d0 + exp(-a))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b <= -1700.0) || !(b <= 2.6e-18)) {
tmp = 1.0 / (1.0 + Math.exp(b));
} else {
tmp = 1.0 / (1.0 + Math.exp(-a));
}
return tmp;
}
def code(a, b): tmp = 0 if (b <= -1700.0) or not (b <= 2.6e-18): tmp = 1.0 / (1.0 + math.exp(b)) else: tmp = 1.0 / (1.0 + math.exp(-a)) return tmp
function code(a, b) tmp = 0.0 if ((b <= -1700.0) || !(b <= 2.6e-18)) tmp = Float64(1.0 / Float64(1.0 + exp(b))); else tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b <= -1700.0) || ~((b <= 2.6e-18))) tmp = 1.0 / (1.0 + exp(b)); else tmp = 1.0 / (1.0 + exp(-a)); end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[b, -1700.0], N[Not[LessEqual[b, 2.6e-18]], $MachinePrecision]], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1700 \lor \neg \left(b \leq 2.6 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\end{array}
\end{array}
if b < -1700 or 2.6e-18 < b Initial program 99.1%
*-lft-identity99.1%
associate-/l*99.1%
remove-double-div99.1%
exp-neg99.1%
associate-/r/99.1%
/-rgt-identity99.1%
*-commutative99.1%
distribute-rgt-in77.8%
exp-neg77.8%
rgt-mult-inverse99.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
if -1700 < b < 2.6e-18Initial program 97.8%
*-lft-identity97.8%
associate-/l*97.8%
remove-double-div97.8%
exp-neg97.8%
associate-/r/97.8%
/-rgt-identity97.8%
*-commutative97.8%
distribute-rgt-in61.8%
exp-neg61.8%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -720.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -720.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 <= (-720.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 <= -720.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 <= -720.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 <= -720.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 <= -720.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -720.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 -720:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -720Initial program 98.7%
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 -720 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
remove-double-div98.3%
exp-neg98.3%
associate-/r/98.3%
/-rgt-identity98.3%
*-commutative98.3%
distribute-rgt-in98.3%
exp-neg98.3%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 96.7%
Final simplification97.7%
(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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= a -465.0)
(/ (exp a) a)
(/
1.0
(+
(- 2.0 a)
(/
(* (- 0.25 (* a (* a 0.027777777777777776))) (* a a))
(+ 0.5 (* a 0.16666666666666666)))))))
double code(double a, double b) {
double tmp;
if (a <= -465.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-465.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / ((2.0d0 - a) + (((0.25d0 - (a * (a * 0.027777777777777776d0))) * (a * a)) / (0.5d0 + (a * 0.16666666666666666d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -465.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -465.0: tmp = math.exp(a) / a else: tmp = 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666)))) return tmp
function code(a, b) tmp = 0.0 if (a <= -465.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(Float64(2.0 - a) + Float64(Float64(Float64(0.25 - Float64(a * Float64(a * 0.027777777777777776))) * Float64(a * a)) / Float64(0.5 + Float64(a * 0.16666666666666666))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -465.0) tmp = exp(a) / a; else tmp = 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -465.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(N[(N[(0.25 - N[(a * N[(a * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(a * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -465:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(2 - a\right) + \frac{\left(0.25 - a \cdot \left(a \cdot 0.027777777777777776\right)\right) \cdot \left(a \cdot a\right)}{0.5 + a \cdot 0.16666666666666666}}\\
\end{array}
\end{array}
if a < -465Initial program 98.7%
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 -465 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
remove-double-div98.3%
exp-neg98.3%
associate-/r/98.3%
/-rgt-identity98.3%
*-commutative98.3%
distribute-rgt-in98.3%
exp-neg98.3%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 55.7%
Taylor expanded in a around 0 53.7%
associate-+r+53.7%
neg-mul-153.7%
unsub-neg53.7%
+-commutative53.7%
*-commutative53.7%
*-commutative53.7%
unpow353.7%
unpow253.7%
associate-*l*53.7%
distribute-lft-out53.7%
unpow253.7%
Simplified53.7%
*-commutative53.7%
flip-+53.7%
associate-*l/53.7%
metadata-eval53.7%
swap-sqr53.7%
metadata-eval53.7%
*-commutative53.7%
cancel-sign-sub-inv53.7%
metadata-eval53.7%
Applied egg-rr53.7%
Taylor expanded in a around 0 53.7%
*-commutative53.7%
unpow253.7%
associate-*r*53.7%
Simplified53.7%
Final simplification67.4%
(FPCore (a b)
:precision binary64
(/
1.0
(+
(- 2.0 a)
(/
(* (- 0.25 (* a (* a 0.027777777777777776))) (* a a))
(+ 0.5 (* a 0.16666666666666666))))))
double code(double a, double b) {
return 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / ((2.0d0 - a) + (((0.25d0 - (a * (a * 0.027777777777777776d0))) * (a * a)) / (0.5d0 + (a * 0.16666666666666666d0))))
end function
public static double code(double a, double b) {
return 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666))));
}
def code(a, b): return 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666))))
function code(a, b) return Float64(1.0 / Float64(Float64(2.0 - a) + Float64(Float64(Float64(0.25 - Float64(a * Float64(a * 0.027777777777777776))) * Float64(a * a)) / Float64(0.5 + Float64(a * 0.16666666666666666))))) end
function tmp = code(a, b) tmp = 1.0 / ((2.0 - a) + (((0.25 - (a * (a * 0.027777777777777776))) * (a * a)) / (0.5 + (a * 0.16666666666666666)))); end
code[a_, b_] := N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(N[(N[(0.25 - N[(a * N[(a * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(a * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(2 - a\right) + \frac{\left(0.25 - a \cdot \left(a \cdot 0.027777777777777776\right)\right) \cdot \left(a \cdot a\right)}{0.5 + a \cdot 0.16666666666666666}}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 57.9%
associate-+r+57.9%
neg-mul-157.9%
unsub-neg57.9%
+-commutative57.9%
*-commutative57.9%
*-commutative57.9%
unpow357.9%
unpow257.9%
associate-*l*57.9%
distribute-lft-out57.9%
unpow257.9%
Simplified57.9%
*-commutative57.9%
flip-+57.9%
associate-*l/61.1%
metadata-eval61.1%
swap-sqr61.1%
metadata-eval61.1%
*-commutative61.1%
cancel-sign-sub-inv61.1%
metadata-eval61.1%
Applied egg-rr61.1%
Taylor expanded in a around 0 61.1%
*-commutative61.1%
unpow261.1%
associate-*r*61.1%
Simplified61.1%
Final simplification61.1%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (- 2.0 a) (* (* a a) (+ 0.5 (* a -0.16666666666666666))))))
double code(double a, double b) {
return 1.0 / ((2.0 - a) + ((a * a) * (0.5 + (a * -0.16666666666666666))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / ((2.0d0 - a) + ((a * a) * (0.5d0 + (a * (-0.16666666666666666d0)))))
end function
public static double code(double a, double b) {
return 1.0 / ((2.0 - a) + ((a * a) * (0.5 + (a * -0.16666666666666666))));
}
def code(a, b): return 1.0 / ((2.0 - a) + ((a * a) * (0.5 + (a * -0.16666666666666666))))
function code(a, b) return Float64(1.0 / Float64(Float64(2.0 - a) + Float64(Float64(a * a) * Float64(0.5 + Float64(a * -0.16666666666666666))))) end
function tmp = code(a, b) tmp = 1.0 / ((2.0 - a) + ((a * a) * (0.5 + (a * -0.16666666666666666)))); end
code[a_, b_] := N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(N[(a * a), $MachinePrecision] * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(2 - a\right) + \left(a \cdot a\right) \cdot \left(0.5 + a \cdot -0.16666666666666666\right)}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 57.9%
associate-+r+57.9%
neg-mul-157.9%
unsub-neg57.9%
+-commutative57.9%
*-commutative57.9%
*-commutative57.9%
unpow357.9%
unpow257.9%
associate-*l*57.9%
distribute-lft-out57.9%
unpow257.9%
Simplified57.9%
Final simplification57.9%
(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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 52.9%
+-commutative52.9%
neg-mul-152.9%
unsub-neg52.9%
unpow252.9%
Simplified52.9%
associate-*r*52.9%
*-un-lft-identity52.9%
distribute-rgt-out--52.9%
*-commutative52.9%
Applied egg-rr52.9%
Final simplification52.9%
(FPCore (a b) :precision binary64 (if (<= a -1.75) (/ 2.0 (* a a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -1.75) {
tmp = 2.0 / (a * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.75d0)) then
tmp = 2.0d0 / (a * a)
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.75) {
tmp = 2.0 / (a * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.75: tmp = 2.0 / (a * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.75) tmp = Float64(2.0 / Float64(a * a)); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.75) tmp = 2.0 / (a * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.75], N[(2.0 / N[(a * a), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.75:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -1.75Initial program 98.7%
*-lft-identity98.7%
associate-/l*98.7%
remove-double-div98.7%
exp-neg98.7%
associate-/r/98.7%
/-rgt-identity98.7%
*-commutative98.7%
distribute-rgt-in3.8%
exp-neg3.8%
rgt-mult-inverse98.7%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 97.6%
Taylor expanded in a around 0 49.6%
+-commutative49.6%
neg-mul-149.6%
unsub-neg49.6%
unpow249.6%
Simplified49.6%
Taylor expanded in a around inf 49.6%
unpow249.6%
Simplified49.6%
if -1.75 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
remove-double-div98.3%
exp-neg98.3%
associate-/r/98.3%
/-rgt-identity98.3%
*-commutative98.3%
distribute-rgt-in98.3%
exp-neg98.3%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 56.1%
Taylor expanded in a around 0 54.4%
*-commutative54.4%
Simplified54.4%
Final simplification52.9%
(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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 38.3%
*-commutative38.3%
Simplified38.3%
Final simplification38.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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 38.8%
neg-mul-138.8%
unsub-neg38.8%
Simplified38.8%
Final simplification38.8%
(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 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in69.1%
exp-neg69.1%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.9%
Taylor expanded in a around 0 37.8%
Final simplification37.8%
(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 2023293
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:herbie-target
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))