
(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 10 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%
clear-num98.4%
inv-pow98.4%
Applied egg-rr98.4%
Taylor expanded in a around inf 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
*-lft-identity98.4%
associate-*l/98.4%
rec-exp98.4%
distribute-rgt-in71.5%
rec-exp71.5%
rgt-mult-inverse99.2%
rec-exp99.2%
associate-*r/99.2%
*-rgt-identity99.2%
Simplified99.2%
add-exp-log99.2%
log-rec99.2%
log1p-udef99.2%
div-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
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 (exp(a) <= 1.0d0) 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 (Math.exp(a) <= 1.0) {
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 math.exp(a) <= 1.0: 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 (exp(a) <= 1.0) 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 (exp(a) <= 1.0) 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[N[Exp[a], $MachinePrecision], 1.0], 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}\;e^{a} \leq 1:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 99.6%
clear-num99.6%
inv-pow99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
*-lft-identity99.6%
associate-*l/99.6%
rec-exp99.6%
distribute-rgt-in71.6%
rec-exp71.6%
rgt-mult-inverse99.6%
rec-exp99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Taylor expanded in b around 0 65.7%
rec-exp65.7%
Simplified65.7%
if 1 < (exp.f64 a) Initial program 66.7%
Taylor expanded in a around 0 80.8%
Final simplification66.2%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.0;
} 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 (exp(a) <= 0.0d0) then
tmp = exp(a) / 2.0d0
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 (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / 2.0); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) / 2.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.6%
Taylor expanded in a around 0 98.6%
Taylor expanded in b around 0 98.6%
if 0.0 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0 97.8%
Final simplification98.0%
(FPCore (a b) :precision binary64 (if (<= b -3.1) 1.0 (/ (exp a) 2.0)))
double code(double a, double b) {
double tmp;
if (b <= -3.1) {
tmp = 1.0;
} else {
tmp = exp(a) / 2.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-3.1d0)) then
tmp = 1.0d0
else
tmp = exp(a) / 2.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -3.1) {
tmp = 1.0;
} else {
tmp = Math.exp(a) / 2.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -3.1: tmp = 1.0 else: tmp = math.exp(a) / 2.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -3.1) tmp = 1.0; else tmp = Float64(exp(a) / 2.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -3.1) tmp = 1.0; else tmp = exp(a) / 2.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -3.1], 1.0, N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\end{array}
\end{array}
if b < -3.10000000000000009Initial program 96.5%
clear-num96.5%
inv-pow96.5%
Applied egg-rr96.5%
Taylor expanded in a around inf 96.5%
*-lft-identity96.5%
associate-*l/96.5%
associate-/r/96.5%
*-lft-identity96.5%
associate-*l/96.5%
rec-exp96.5%
distribute-rgt-in96.5%
rec-exp96.5%
rgt-mult-inverse98.2%
rec-exp98.2%
associate-*r/98.2%
*-rgt-identity98.2%
Simplified98.2%
add-exp-log98.2%
log-rec98.2%
log1p-udef98.2%
div-exp100.0%
Applied egg-rr100.0%
exp-neg100.0%
log1p-udef100.0%
add-exp-log100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr98.7%
*-inverses98.7%
Simplified98.7%
if -3.10000000000000009 < b Initial program 99.0%
Taylor expanded in a around 0 97.4%
Taylor expanded in b around 0 76.2%
Final simplification81.2%
(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%
clear-num98.4%
inv-pow98.4%
Applied egg-rr98.4%
Taylor expanded in a around inf 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
*-lft-identity98.4%
associate-*l/98.4%
rec-exp98.4%
distribute-rgt-in71.5%
rec-exp71.5%
rgt-mult-inverse99.2%
rec-exp99.2%
associate-*r/99.2%
*-rgt-identity99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
log1p-udef99.2%
add-exp-log99.2%
+-commutative99.2%
div-exp100.0%
Applied egg-rr100.0%
associate--l+100.0%
metadata-eval100.0%
+-rgt-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b -4.8e-9) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -4.8e-9) {
tmp = 1.0;
} 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 (b <= (-4.8d-9)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -4.8e-9) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -4.8e-9: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -4.8e-9) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -4.8e-9) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -4.8e-9], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-9}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -4.8e-9Initial program 96.6%
clear-num96.6%
inv-pow96.6%
Applied egg-rr96.6%
Taylor expanded in a around inf 96.6%
*-lft-identity96.6%
associate-*l/96.6%
associate-/r/96.6%
*-lft-identity96.6%
associate-*l/96.6%
rec-exp96.6%
distribute-rgt-in94.8%
rec-exp94.8%
rgt-mult-inverse98.3%
rec-exp98.3%
associate-*r/98.3%
*-rgt-identity98.3%
Simplified98.3%
add-exp-log98.3%
log-rec98.3%
log1p-udef98.3%
div-exp100.0%
Applied egg-rr100.0%
exp-neg100.0%
log1p-udef100.0%
add-exp-log100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr97.0%
*-inverses97.0%
Simplified97.0%
if -4.8e-9 < b Initial program 99.0%
Taylor expanded in b around 0 77.4%
Taylor expanded in a around 0 43.2%
*-commutative43.2%
Simplified43.2%
Final simplification55.4%
(FPCore (a b) :precision binary64 (if (<= b -0.98) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -0.98) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-0.98d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.98) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.98: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.98) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.98) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.98], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.98:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -0.97999999999999998Initial program 96.5%
clear-num96.5%
inv-pow96.5%
Applied egg-rr96.5%
Taylor expanded in a around inf 96.5%
*-lft-identity96.5%
associate-*l/96.5%
associate-/r/96.5%
*-lft-identity96.5%
associate-*l/96.5%
rec-exp96.5%
distribute-rgt-in96.5%
rec-exp96.5%
rgt-mult-inverse98.2%
rec-exp98.2%
associate-*r/98.2%
*-rgt-identity98.2%
Simplified98.2%
add-exp-log98.2%
log-rec98.2%
log1p-udef98.2%
div-exp100.0%
Applied egg-rr100.0%
exp-neg100.0%
log1p-udef100.0%
add-exp-log100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr98.7%
*-inverses98.7%
Simplified98.7%
if -0.97999999999999998 < b Initial program 99.0%
Taylor expanded in a around 0 74.6%
Taylor expanded in b around 0 43.7%
+-commutative43.7%
Simplified43.7%
Final simplification55.9%
(FPCore (a b) :precision binary64 (if (<= b -0.24) 1.0 (/ 1.0 (- 2.0 a))))
double code(double a, double b) {
double tmp;
if (b <= -0.24) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-0.24d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 - a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.24) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.24: tmp = 1.0 else: tmp = 1.0 / (2.0 - a) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.24) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.24) tmp = 1.0; else tmp = 1.0 / (2.0 - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.24], 1.0, N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.24:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - a}\\
\end{array}
\end{array}
if b < -0.23999999999999999Initial program 96.5%
clear-num96.5%
inv-pow96.5%
Applied egg-rr96.5%
Taylor expanded in a around inf 96.5%
*-lft-identity96.5%
associate-*l/96.5%
associate-/r/96.5%
*-lft-identity96.5%
associate-*l/96.5%
rec-exp96.5%
distribute-rgt-in96.5%
rec-exp96.5%
rgt-mult-inverse98.2%
rec-exp98.2%
associate-*r/98.2%
*-rgt-identity98.2%
Simplified98.2%
add-exp-log98.2%
log-rec98.2%
log1p-udef98.2%
div-exp100.0%
Applied egg-rr100.0%
exp-neg100.0%
log1p-udef100.0%
add-exp-log100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr98.7%
*-inverses98.7%
Simplified98.7%
if -0.23999999999999999 < b Initial program 99.0%
clear-num99.0%
inv-pow99.0%
Applied egg-rr99.0%
Taylor expanded in a around inf 99.0%
*-lft-identity99.0%
associate-*l/99.0%
associate-/r/99.0%
*-lft-identity99.0%
associate-*l/99.0%
rec-exp99.0%
distribute-rgt-in64.3%
rec-exp64.3%
rgt-mult-inverse99.5%
rec-exp99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in b around 0 78.1%
rec-exp78.1%
Simplified78.1%
Taylor expanded in a around 0 43.7%
neg-mul-143.7%
unsub-neg43.7%
Simplified43.7%
Final simplification56.0%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 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.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.0) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -1Initial program 96.5%
clear-num96.5%
inv-pow96.5%
Applied egg-rr96.5%
Taylor expanded in a around inf 96.5%
*-lft-identity96.5%
associate-*l/96.5%
associate-/r/96.5%
*-lft-identity96.5%
associate-*l/96.5%
rec-exp96.5%
distribute-rgt-in96.5%
rec-exp96.5%
rgt-mult-inverse98.2%
rec-exp98.2%
associate-*r/98.2%
*-rgt-identity98.2%
Simplified98.2%
add-exp-log98.2%
log-rec98.2%
log1p-udef98.2%
div-exp100.0%
Applied egg-rr100.0%
exp-neg100.0%
log1p-udef100.0%
add-exp-log100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr98.7%
*-inverses98.7%
Simplified98.7%
if -1 < b Initial program 99.0%
Taylor expanded in a around 0 74.6%
Taylor expanded in b around 0 42.8%
Final simplification55.2%
(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%
Taylor expanded in a around 0 80.3%
Taylor expanded in b around 0 37.4%
Final simplification37.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 2024021
(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))))