
(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-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-log-exp99.8%
*-un-lft-identity99.8%
log-prod99.8%
metadata-eval99.8%
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 (<= (exp b) 0.9999) (not (<= (exp b) 2.0))) (/ 1.0 (+ 1.0 (exp b))) (/ 1.0 (+ 1.0 (exp (- a))))))
double code(double a, double b) {
double tmp;
if ((exp(b) <= 0.9999) || !(exp(b) <= 2.0)) {
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 ((exp(b) <= 0.9999d0) .or. (.not. (exp(b) <= 2.0d0))) 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 ((Math.exp(b) <= 0.9999) || !(Math.exp(b) <= 2.0)) {
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 (math.exp(b) <= 0.9999) or not (math.exp(b) <= 2.0): 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 ((exp(b) <= 0.9999) || !(exp(b) <= 2.0)) 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 ((exp(b) <= 0.9999) || ~((exp(b) <= 2.0))) 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[N[Exp[b], $MachinePrecision], 0.9999], N[Not[LessEqual[N[Exp[b], $MachinePrecision], 2.0]], $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}\;e^{b} \leq 0.9999 \lor \neg \left(e^{b} \leq 2\right):\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\end{array}
\end{array}
if (exp.f64 b) < 0.99990000000000001 or 2 < (exp.f64 b) Initial program 98.5%
*-lft-identity98.5%
associate-/l*98.5%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in79.4%
exp-neg79.4%
rgt-mult-inverse98.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
if 0.99990000000000001 < (exp.f64 b) < 2Initial 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-in60.8%
exp-neg60.8%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 99.3%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= a -3200000.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -3200000.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 <= (-3200000.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 <= -3200000.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 <= -3200000.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 <= -3200000.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 <= -3200000.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3200000.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 -3200000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -3.2e6Initial 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 -3.2e6 < a Initial 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-in97.8%
exp-neg97.8%
rgt-mult-inverse98.9%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.3%
Final simplification98.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 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-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -1150000.0) (/ (exp a) a) (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))))
double code(double a, double b) {
double tmp;
if (a <= -1150000.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1150000.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1150000.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1150000.0: tmp = math.exp(a) / a else: tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (a <= -1150000.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1150000.0) tmp = exp(a) / a; else tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1150000.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1150000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if a < -1.15e6Initial 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 -1.15e6 < a Initial 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-in97.8%
exp-neg97.8%
rgt-mult-inverse98.9%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.3%
Taylor expanded in b around 0 59.6%
associate-+r+59.6%
+-commutative59.6%
unpow259.6%
Simplified59.6%
Final simplification71.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ 2.0 (* b (* b 0.5)))))
(if (<= b 9.5e+54)
(/ 1.0 (+ (- 2.0 a) (* a (* a 0.5))))
(if (<= b 1.32e+154)
(/ 1.0 (/ (- (* b b) (* t_0 t_0)) (- b t_0)))
(/ 2.0 (* b b))))))
double code(double a, double b) {
double t_0 = 2.0 + (b * (b * 0.5));
double tmp;
if (b <= 9.5e+54) {
tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5)));
} else if (b <= 1.32e+154) {
tmp = 1.0 / (((b * b) - (t_0 * t_0)) / (b - t_0));
} 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) :: t_0
real(8) :: tmp
t_0 = 2.0d0 + (b * (b * 0.5d0))
if (b <= 9.5d+54) then
tmp = 1.0d0 / ((2.0d0 - a) + (a * (a * 0.5d0)))
else if (b <= 1.32d+154) then
tmp = 1.0d0 / (((b * b) - (t_0 * t_0)) / (b - t_0))
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 2.0 + (b * (b * 0.5));
double tmp;
if (b <= 9.5e+54) {
tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5)));
} else if (b <= 1.32e+154) {
tmp = 1.0 / (((b * b) - (t_0 * t_0)) / (b - t_0));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): t_0 = 2.0 + (b * (b * 0.5)) tmp = 0 if b <= 9.5e+54: tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5))) elif b <= 1.32e+154: tmp = 1.0 / (((b * b) - (t_0 * t_0)) / (b - t_0)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) t_0 = Float64(2.0 + Float64(b * Float64(b * 0.5))) tmp = 0.0 if (b <= 9.5e+54) tmp = Float64(1.0 / Float64(Float64(2.0 - a) + Float64(a * Float64(a * 0.5)))); elseif (b <= 1.32e+154) tmp = Float64(1.0 / Float64(Float64(Float64(b * b) - Float64(t_0 * t_0)) / Float64(b - t_0))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) t_0 = 2.0 + (b * (b * 0.5)); tmp = 0.0; if (b <= 9.5e+54) tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5))); elseif (b <= 1.32e+154) tmp = 1.0 / (((b * b) - (t_0 * t_0)) / (b - t_0)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(2.0 + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 9.5e+54], N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.32e+154], N[(1.0 / N[(N[(N[(b * b), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 + b \cdot \left(b \cdot 0.5\right)\\
\mathbf{if}\;b \leq 9.5 \cdot 10^{+54}:\\
\;\;\;\;\frac{1}{\left(2 - a\right) + a \cdot \left(a \cdot 0.5\right)}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\frac{b \cdot b - t_0 \cdot t_0}{b - t_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 9.4999999999999999e54Initial 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-in69.9%
exp-neg69.9%
rgt-mult-inverse98.9%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 74.7%
Taylor expanded in a around 0 57.4%
associate-+r+57.4%
neg-mul-157.4%
unsub-neg57.4%
*-commutative57.4%
unpow257.4%
associate-*l*57.4%
Simplified57.4%
if 9.4999999999999999e54 < b < 1.31999999999999998e154Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in78.3%
exp-neg78.3%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 7.6%
associate-+r+7.6%
+-commutative7.6%
unpow27.6%
Simplified7.6%
associate-+l+7.6%
flip-+70.9%
*-commutative70.9%
associate-*l*70.9%
*-commutative70.9%
associate-*l*70.9%
*-commutative70.9%
associate-*l*70.9%
Applied egg-rr70.9%
if 1.31999999999999998e154 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in68.1%
exp-neg68.1%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
associate-+r+100.0%
+-commutative100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification66.4%
(FPCore (a b) :precision binary64 (if (<= a -1.62e+97) (/ 2.0 (* a a)) (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))))
double code(double a, double b) {
double tmp;
if (a <= -1.62e+97) {
tmp = 2.0 / (a * a);
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * 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.62d+97)) then
tmp = 2.0d0 / (a * a)
else
tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.62e+97) {
tmp = 2.0 / (a * a);
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.62e+97: tmp = 2.0 / (a * a) else: tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.62e+97) tmp = Float64(2.0 / Float64(a * a)); else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.62e+97) tmp = 2.0 / (a * a); else tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.62e+97], N[(2.0 / N[(a * a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.62 \cdot 10^{+97}:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if a < -1.62e97Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 71.7%
associate-+r+71.7%
neg-mul-171.7%
unsub-neg71.7%
*-commutative71.7%
unpow271.7%
associate-*l*71.7%
Simplified71.7%
Taylor expanded in a around inf 71.7%
unpow271.7%
Simplified71.7%
if -1.62e97 < a Initial program 98.1%
*-lft-identity98.1%
associate-/l*98.1%
remove-double-div98.0%
exp-neg98.0%
associate-/r/98.1%
/-rgt-identity98.1%
*-commutative98.1%
distribute-rgt-in85.7%
exp-neg85.7%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 90.7%
Taylor expanded in b around 0 55.9%
associate-+r+55.9%
+-commutative55.9%
unpow255.9%
Simplified55.9%
Final simplification58.8%
(FPCore (a b) :precision binary64 (if (<= b 9.2e+113) (/ 1.0 (+ (- 2.0 a) (* a (* a 0.5)))) (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))))
double code(double a, double b) {
double tmp;
if (b <= 9.2e+113) {
tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5)));
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (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 <= 9.2d+113) then
tmp = 1.0d0 / ((2.0d0 - a) + (a * (a * 0.5d0)))
else
tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 9.2e+113) {
tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5)));
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 9.2e+113: tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5))) else: tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (b <= 9.2e+113) tmp = Float64(1.0 / Float64(Float64(2.0 - a) + Float64(a * Float64(a * 0.5)))); else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 9.2e+113) tmp = 1.0 / ((2.0 - a) + (a * (a * 0.5))); else tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 9.2e+113], N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.2 \cdot 10^{+113}:\\
\;\;\;\;\frac{1}{\left(2 - a\right) + a \cdot \left(a \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 9.19999999999999987e113Initial program 98.0%
*-lft-identity98.0%
associate-/l*98.0%
remove-double-div97.9%
exp-neg97.9%
associate-/r/98.0%
/-rgt-identity98.0%
*-commutative98.0%
distribute-rgt-in70.3%
exp-neg70.3%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 71.4%
Taylor expanded in a around 0 54.4%
associate-+r+54.4%
neg-mul-154.4%
unsub-neg54.4%
*-commutative54.4%
unpow254.4%
associate-*l*54.4%
Simplified54.4%
if 9.19999999999999987e113 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in70.2%
exp-neg70.2%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 84.4%
associate-+r+84.4%
+-commutative84.4%
unpow284.4%
Simplified84.4%
Final simplification61.0%
(FPCore (a b) :precision binary64 (if (<= a -1.35) (/ 2.0 (* a a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -1.35) {
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.35d0)) 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.35) {
tmp = 2.0 / (a * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.35: tmp = 2.0 / (a * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.35) 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.35) tmp = 2.0 / (a * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.35], 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.35:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -1.3500000000000001Initial 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-in2.7%
exp-neg2.7%
rgt-mult-inverse98.7%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 97.4%
Taylor expanded in a around 0 45.7%
associate-+r+45.7%
neg-mul-145.7%
unsub-neg45.7%
*-commutative45.7%
unpow245.7%
associate-*l*45.7%
Simplified45.7%
Taylor expanded in a around inf 45.7%
unpow245.7%
Simplified45.7%
if -1.3500000000000001 < 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 48.3%
Taylor expanded in a around 0 46.2%
*-commutative46.2%
Simplified46.2%
Final simplification46.1%
(FPCore (a b) :precision binary64 (if (<= b 1.28e+41) (/ 1.0 (- 2.0 a)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.28e+41) {
tmp = 1.0 / (2.0 - a);
} 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 <= 1.28d+41) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.28e+41) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.28e+41: tmp = 1.0 / (2.0 - a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.28e+41) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.28e+41) tmp = 1.0 / (2.0 - a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.28e+41], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.28 \cdot 10^{+41}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.27999999999999992e41Initial program 97.8%
*-lft-identity97.8%
associate-/l*97.8%
remove-double-div97.7%
exp-neg97.7%
associate-/r/97.7%
/-rgt-identity97.7%
*-commutative97.7%
distribute-rgt-in70.1%
exp-neg70.1%
rgt-mult-inverse98.9%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 75.6%
Taylor expanded in a around 0 46.5%
neg-mul-146.5%
unsub-neg46.5%
Simplified46.5%
if 1.27999999999999992e41 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 65.3%
associate-+r+65.3%
+-commutative65.3%
unpow265.3%
Simplified65.3%
Taylor expanded in b around inf 65.3%
unpow265.3%
Simplified65.3%
Final simplification52.0%
(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-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 62.7%
Taylor expanded in a around 0 34.0%
neg-mul-134.0%
unsub-neg34.0%
Simplified34.0%
Final simplification34.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 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-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 80.3%
Taylor expanded in b around 0 33.4%
Final simplification33.4%
(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 2023283
(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))))