
(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 (let* ((t_0 (/ (exp a) (+ (exp b) (exp a))))) (if (<= t_0 2.0) t_0 (/ 1.0 (+ 1.0 (exp (- a)))))))
double code(double a, double b) {
double t_0 = exp(a) / (exp(b) + exp(a));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = exp(a) / (exp(b) + exp(a))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = 1.0d0 / (1.0d0 + exp(-a))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = Math.exp(a) / (Math.exp(b) + Math.exp(a));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = 1.0 / (1.0 + Math.exp(-a));
}
return tmp;
}
def code(a, b): t_0 = math.exp(a) / (math.exp(b) + math.exp(a)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = 1.0 / (1.0 + math.exp(-a)) return tmp
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(b) + exp(a))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); end return tmp end
function tmp_2 = code(a, b) t_0 = exp(a) / (exp(b) + exp(a)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = 1.0 / (1.0 + exp(-a)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[b], $MachinePrecision] + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{b} + e^{a}}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 2Initial program 100.0%
if 2 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 0.0%
clear-num0.0%
inv-pow0.0%
Applied egg-rr0.0%
expm1-log1p-u0.0%
expm1-udef0.0%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p0.0%
*-lft-identity0.0%
associate-*l/0.0%
rec-exp0.0%
distribute-rgt-in0.0%
rec-exp0.0%
rgt-mult-inverse80.0%
rec-exp80.0%
associate-*r/80.0%
*-rgt-identity80.0%
Simplified80.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (pow (+ 1.0 (/ (exp b) (exp a))) -1.0))
double code(double a, double b) {
return pow((1.0 + (exp(b) / exp(a))), -1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (1.0d0 + (exp(b) / exp(a))) ** (-1.0d0)
end function
public static double code(double a, double b) {
return Math.pow((1.0 + (Math.exp(b) / Math.exp(a))), -1.0);
}
def code(a, b): return math.pow((1.0 + (math.exp(b) / math.exp(a))), -1.0)
function code(a, b) return Float64(1.0 + Float64(exp(b) / exp(a))) ^ -1.0 end
function tmp = code(a, b) tmp = (1.0 + (exp(b) / exp(a))) ^ -1.0; end
code[a_, b_] := N[Power[N[(1.0 + N[(N[Exp[b], $MachinePrecision] / N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(1 + \frac{e^{b}}{e^{a}}\right)}^{-1}
\end{array}
Initial program 98.0%
clear-num98.0%
inv-pow98.0%
Applied egg-rr98.0%
expm1-log1p-u97.5%
expm1-udef97.5%
Applied egg-rr97.5%
expm1-def97.5%
expm1-log1p98.0%
*-lft-identity98.0%
associate-*l/98.0%
rec-exp98.0%
distribute-rgt-in70.7%
rec-exp70.7%
rgt-mult-inverse99.6%
rec-exp99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.999999) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999999) {
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) <= 0.999999d0) 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) <= 0.999999) {
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) <= 0.999999: 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) <= 0.999999) 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) <= 0.999999) 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], 0.999999], 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 0.999999:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999998999999999971Initial program 98.6%
clear-num98.6%
inv-pow98.6%
Applied egg-rr98.6%
expm1-log1p-u98.6%
expm1-udef98.6%
Applied egg-rr98.6%
expm1-def98.6%
expm1-log1p98.6%
*-lft-identity98.6%
associate-*l/98.6%
rec-exp98.6%
distribute-rgt-in4.1%
rec-exp4.1%
rgt-mult-inverse98.6%
rec-exp98.6%
associate-*r/98.6%
*-rgt-identity98.6%
Simplified98.6%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
if 0.999998999999999971 < (exp.f64 a) Initial program 97.8%
Taylor expanded in a around 0 98.4%
Final simplification98.8%
(FPCore (a b) :precision binary64 (if (<= a -395000.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -395000.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 <= (-395000.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 <= -395000.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 <= -395000.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 <= -395000.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 <= -395000.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -395000.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 -395000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -395000Initial program 98.6%
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 -395000 < a Initial program 97.8%
Taylor expanded in a around 0 97.2%
Final simplification98.0%
(FPCore (a b) :precision binary64 (if (<= a -1.55e-6) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -1.55e-6) {
tmp = exp(a) / (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 (a <= (-1.55d-6)) then
tmp = exp(a) / (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 (a <= -1.55e-6) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.55e-6: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.55e-6) tmp = Float64(exp(a) / Float64(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 (a <= -1.55e-6) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.55e-6], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.55 \cdot 10^{-6}:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -1.55e-6Initial program 98.6%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 97.6%
+-commutative97.6%
Simplified97.6%
if -1.55e-6 < a Initial program 97.8%
Taylor expanded in a around 0 98.4%
Final simplification98.1%
(FPCore (a b) :precision binary64 (if (<= a -390000.0) (/ (exp a) a) (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (a <= -390000.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b + (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 <= (-390000.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (2.0d0 + (b + (0.5d0 * (b * b))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -390000.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -390000.0: tmp = math.exp(a) / a else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (a <= -390000.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(0.5 * Float64(b * b))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -390000.0) tmp = exp(a) / a; else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -390000.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -390000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if a < -3.9e5Initial program 98.6%
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.9e5 < a Initial program 97.8%
Taylor expanded in a around 0 97.2%
Taylor expanded in b around 0 61.5%
unpow261.5%
Simplified61.5%
Final simplification72.1%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (- b))))
(if (<= b 5.5e+63)
(/ 1.0 (- 2.0 a))
(if (<= b 1.35e+154) (/ (- t_0 (* b -2.0)) (* b t_0)) (/ -2.0 (* b b))))))
double code(double a, double b) {
double t_0 = b * -b;
double tmp;
if (b <= 5.5e+63) {
tmp = 1.0 / (2.0 - a);
} else if (b <= 1.35e+154) {
tmp = (t_0 - (b * -2.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 = b * -b
if (b <= 5.5d+63) then
tmp = 1.0d0 / (2.0d0 - a)
else if (b <= 1.35d+154) then
tmp = (t_0 - (b * (-2.0d0))) / (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 = b * -b;
double tmp;
if (b <= 5.5e+63) {
tmp = 1.0 / (2.0 - a);
} else if (b <= 1.35e+154) {
tmp = (t_0 - (b * -2.0)) / (b * t_0);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): t_0 = b * -b tmp = 0 if b <= 5.5e+63: tmp = 1.0 / (2.0 - a) elif b <= 1.35e+154: tmp = (t_0 - (b * -2.0)) / (b * t_0) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) t_0 = Float64(b * Float64(-b)) tmp = 0.0 if (b <= 5.5e+63) tmp = Float64(1.0 / Float64(2.0 - a)); elseif (b <= 1.35e+154) tmp = Float64(Float64(t_0 - Float64(b * -2.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 = b * -b; tmp = 0.0; if (b <= 5.5e+63) tmp = 1.0 / (2.0 - a); elseif (b <= 1.35e+154) tmp = (t_0 - (b * -2.0)) / (b * t_0); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * (-b)), $MachinePrecision]}, If[LessEqual[b, 5.5e+63], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(N[(t$95$0 - N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(-b\right)\\
\mathbf{if}\;b \leq 5.5 \cdot 10^{+63}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{t_0 - b \cdot -2}{b \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 5.50000000000000004e63Initial program 97.3%
clear-num97.3%
inv-pow97.3%
Applied egg-rr97.3%
expm1-log1p-u96.6%
expm1-udef96.7%
Applied egg-rr96.7%
expm1-def96.6%
expm1-log1p97.3%
*-lft-identity97.3%
associate-*l/97.3%
rec-exp97.3%
distribute-rgt-in72.1%
rec-exp72.1%
rgt-mult-inverse99.5%
rec-exp99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in b around 0 77.5%
rec-exp77.5%
Simplified77.5%
Taylor expanded in a around 0 49.7%
mul-1-neg49.7%
unsub-neg49.7%
Simplified49.7%
if 5.50000000000000004e63 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 4.1%
+-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 4.1%
associate-*r/4.1%
metadata-eval4.1%
unpow24.1%
Simplified4.1%
frac-2neg4.1%
frac-sub48.5%
*-un-lft-identity48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
distribute-rgt-neg-in48.5%
Applied egg-rr48.5%
if 1.35000000000000003e154 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 6.8%
+-commutative6.8%
Simplified6.8%
Taylor expanded in b around inf 6.8%
associate-*r/6.8%
metadata-eval6.8%
unpow26.8%
Simplified6.8%
Taylor expanded in b around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification57.0%
(FPCore (a b) :precision binary64 (if (<= b 1e-14) (/ 1.0 (- 2.0 a)) (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (b <= 1e-14) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (2.0 + (b + (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 <= 1d-14) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 1.0d0 / (2.0d0 + (b + (0.5d0 * (b * b))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1e-14) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1e-14: tmp = 1.0 / (2.0 - a) else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1e-14) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(0.5 * Float64(b * b))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1e-14) tmp = 1.0 / (2.0 - a); else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1e-14], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-14}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if b < 9.99999999999999999e-15Initial program 97.0%
clear-num97.1%
inv-pow97.1%
Applied egg-rr97.1%
expm1-log1p-u96.3%
expm1-udef96.3%
Applied egg-rr96.3%
expm1-def96.3%
expm1-log1p97.1%
*-lft-identity97.1%
associate-*l/97.1%
rec-exp97.1%
distribute-rgt-in71.9%
rec-exp71.9%
rgt-mult-inverse99.4%
rec-exp99.4%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
Taylor expanded in b around 0 81.9%
rec-exp81.9%
Simplified81.9%
Taylor expanded in a around 0 53.7%
mul-1-neg53.7%
unsub-neg53.7%
Simplified53.7%
if 9.99999999999999999e-15 < b Initial program 100.0%
Taylor expanded in a around 0 97.7%
Taylor expanded in b around 0 51.2%
unpow251.2%
Simplified51.2%
Final simplification52.9%
(FPCore (a b) :precision binary64 (if (<= b 620.0) (+ 0.5 (* a 0.25)) (/ -2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 620.0) {
tmp = 0.5 + (a * 0.25);
} 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 <= 620.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = (-2.0d0) / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 620.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 620.0: tmp = 0.5 + (a * 0.25) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 620.0) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(-2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 620.0) tmp = 0.5 + (a * 0.25); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 620.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 620:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 620Initial program 97.1%
Taylor expanded in b around 0 79.0%
Taylor expanded in a around 0 52.7%
*-commutative52.7%
Simplified52.7%
if 620 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 5.3%
+-commutative5.3%
Simplified5.3%
Taylor expanded in b around inf 5.3%
associate-*r/5.3%
metadata-eval5.3%
unpow25.3%
Simplified5.3%
Taylor expanded in b around 0 50.9%
unpow250.9%
Simplified50.9%
Final simplification52.1%
(FPCore (a b) :precision binary64 (if (<= b 4.8e+62) (/ 1.0 (- 2.0 a)) (/ -2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 4.8e+62) {
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 <= 4.8d+62) 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 <= 4.8e+62) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.8e+62: tmp = 1.0 / (2.0 - a) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 4.8e+62) 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 <= 4.8e+62) tmp = 1.0 / (2.0 - a); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.8e+62], 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 4.8 \cdot 10^{+62}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 4.8e62Initial program 97.3%
clear-num97.3%
inv-pow97.3%
Applied egg-rr97.3%
expm1-log1p-u96.6%
expm1-udef96.7%
Applied egg-rr96.7%
expm1-def96.6%
expm1-log1p97.3%
*-lft-identity97.3%
associate-*l/97.3%
rec-exp97.3%
distribute-rgt-in72.1%
rec-exp72.1%
rgt-mult-inverse99.5%
rec-exp99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in b around 0 77.5%
rec-exp77.5%
Simplified77.5%
Taylor expanded in a around 0 49.7%
mul-1-neg49.7%
unsub-neg49.7%
Simplified49.7%
if 4.8e62 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 5.7%
+-commutative5.7%
Simplified5.7%
Taylor expanded in b around inf 5.7%
associate-*r/5.7%
metadata-eval5.7%
unpow25.7%
Simplified5.7%
Taylor expanded in b around 0 60.2%
unpow260.2%
Simplified60.2%
Final simplification52.4%
(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.0%
Taylor expanded in b around 0 65.1%
Taylor expanded in a around 0 37.3%
*-commutative37.3%
Simplified37.3%
Final simplification37.3%
(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.0%
Taylor expanded in a around 0 80.6%
Taylor expanded in b around 0 37.1%
Final simplification37.1%
(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 2023187
(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))))