
(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 (/ 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}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= a -3.8e-6) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -3.8e-6) {
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 (a <= (-3.8d-6)) 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 (a <= -3.8e-6) {
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 a <= -3.8e-6: 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 (a <= -3.8e-6) 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 (a <= -3.8e-6) 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[a, -3.8e-6], 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}\;a \leq -3.8 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -3.8e-6Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if -3.8e-6 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub99.4%
*-lft-identity99.4%
associate-*l/99.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 99.5%
(FPCore (a b) :precision binary64 (if (<= a -3.8e+101) (/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -3.8e+101) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.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 <= (-3.8d+101)) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.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 <= -3.8e+101) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -3.8e+101: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -3.8e+101) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(a * -0.16666666666666666)) + -1.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 <= -3.8e+101) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3.8e+101], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.8 \cdot 10^{+101}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -3.7999999999999998e101Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 98.4%
Taylor expanded in a around inf 98.4%
*-commutative98.4%
Simplified98.4%
if -3.7999999999999998e101 < a Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub87.5%
*-lft-identity87.5%
associate-*l/87.5%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 91.4%
Final simplification92.9%
(FPCore (a b) :precision binary64 (if (<= b 1.4e+92) (/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 1.4e+92) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.4d+92) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.4e+92) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.4e+92: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.4e+92) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(a * -0.16666666666666666)) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.4e+92) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.4e+92], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.4 \cdot 10^{+92}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 1.4e92Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub67.4%
*-lft-identity67.4%
associate-*l/67.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 78.2%
Taylor expanded in a around 0 68.1%
Taylor expanded in a around inf 68.1%
*-commutative68.1%
Simplified68.1%
if 1.4e92 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub73.2%
*-lft-identity73.2%
associate-*l/73.2%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 93.4%
*-commutative93.4%
Simplified93.4%
Final simplification72.1%
(FPCore (a b) :precision binary64 (if (<= b 4.8e+117) (/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0)))) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 4.8e+117) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 4.8d+117) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (b * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 4.8e+117) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.8e+117: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 4.8e+117) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(a * -0.16666666666666666)) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4.8e+117) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.8e+117], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8 \cdot 10^{+117}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 4.7999999999999998e117Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub67.0%
*-lft-identity67.0%
associate-*l/67.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 77.4%
Taylor expanded in a around 0 67.2%
Taylor expanded in a around inf 67.2%
*-commutative67.2%
Simplified67.2%
if 4.7999999999999998e117 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub77.1%
*-lft-identity77.1%
associate-*l/77.1%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 84.1%
Taylor expanded in b around inf 84.1%
Final simplification69.5%
(FPCore (a b) :precision binary64 (if (<= b 4.8e+117) (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 4.8e+117) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 4.8d+117) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (b * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 4.8e+117) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.8e+117: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 4.8e+117) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4.8e+117) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.8e+117], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8 \cdot 10^{+117}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 4.7999999999999998e117Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub67.0%
*-lft-identity67.0%
associate-*l/67.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 77.4%
Taylor expanded in a around 0 62.1%
if 4.7999999999999998e117 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub77.1%
*-lft-identity77.1%
associate-*l/77.1%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 84.1%
Taylor expanded in b around inf 84.1%
Final simplification65.1%
(FPCore (a b) :precision binary64 (if (<= b 1.62e+35) (/ 1.0 (- 2.0 a)) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 1.62e+35) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.62d+35) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 1.0d0 / (2.0d0 + (b * (b * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.62e+35) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.62e+35: tmp = 1.0 / (2.0 - a) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.62e+35) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.62e+35) tmp = 1.0 / (2.0 - a); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.62e+35], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.62 \cdot 10^{+35}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.62e35Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub69.4%
*-lft-identity69.4%
associate-*l/69.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 80.5%
Taylor expanded in a around 0 51.5%
mul-1-neg51.5%
unsub-neg51.5%
Simplified51.5%
if 1.62e35 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub65.0%
*-lft-identity65.0%
associate-*l/65.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 51.1%
Taylor expanded in b around inf 51.1%
Final simplification51.4%
(FPCore (a b) :precision binary64 (if (<= b 8.2e+34) (/ 1.0 (- 2.0 a)) (/ (/ -2.0 b) b)))
double code(double a, double b) {
double tmp;
if (b <= 8.2e+34) {
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 <= 8.2d+34) 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 <= 8.2e+34) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = (-2.0 / b) / b;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.2e+34: tmp = 1.0 / (2.0 - a) else: tmp = (-2.0 / b) / b return tmp
function code(a, b) tmp = 0.0 if (b <= 8.2e+34) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(Float64(-2.0 / b) / b); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.2e+34) tmp = 1.0 / (2.0 - a); else tmp = (-2.0 / b) / b; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.2e+34], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 / b), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.2 \cdot 10^{+34}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{b}}{b}\\
\end{array}
\end{array}
if b < 8.1999999999999997e34Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub69.4%
*-lft-identity69.4%
associate-*l/69.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 80.5%
Taylor expanded in a around 0 51.5%
mul-1-neg51.5%
unsub-neg51.5%
Simplified51.5%
if 8.1999999999999997e34 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub65.0%
*-lft-identity65.0%
associate-*l/65.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 5.2%
+-commutative5.2%
Simplified5.2%
Taylor expanded in b around inf 5.2%
associate-*r/5.2%
metadata-eval5.2%
Simplified5.2%
Taylor expanded in b around 0 51.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 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 70.3%
Taylor expanded in a around 0 40.3%
mul-1-neg40.3%
unsub-neg40.3%
Simplified40.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 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 78.5%
Taylor expanded in b around 0 39.7%
(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 2024137
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))