
(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 11 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-sub72.3%
*-lft-identity72.3%
associate-*l/72.3%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -0.0065) (/ 1.0 (- (exp (- a)) -1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -0.0065) {
tmp = 1.0 / (exp(-a) - -1.0);
} else {
tmp = 1.0 / (exp(b) - -1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-0.0065d0)) then
tmp = 1.0d0 / (exp(-a) - (-1.0d0))
else
tmp = 1.0d0 / (exp(b) - (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -0.0065) {
tmp = 1.0 / (Math.exp(-a) - -1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.0065: tmp = 1.0 / (math.exp(-a) - -1.0) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.0065) tmp = Float64(1.0 / Float64(exp(Float64(-a)) - -1.0)); else tmp = Float64(1.0 / Float64(exp(b) - -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -0.0065) tmp = 1.0 / (exp(-a) - -1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.0065], N[(1.0 / N[(N[Exp[(-a)], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0065:\\
\;\;\;\;\frac{1}{e^{-a} - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -0.0064999999999999997Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub2.8%
neg-mul-12.8%
*-commutative2.8%
associate-*r/2.8%
metadata-eval2.8%
distribute-neg-frac2.8%
exp-neg2.8%
distribute-rgt-neg-out2.8%
exp-neg2.8%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
if -0.0064999999999999997 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
+-commutative99.4%
remove-double-neg99.4%
sub-neg99.4%
div-sub99.4%
neg-mul-199.4%
*-commutative99.4%
associate-*r/99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
exp-neg99.4%
distribute-rgt-neg-out99.4%
exp-neg99.4%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 98.9%
Final simplification99.2%
(FPCore (a b) :precision binary64 (if (<= a -3.5e+102) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -3.5e+102) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (exp(b) - -1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-3.5d+102)) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else
tmp = 1.0d0 / (exp(b) - (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -3.5e+102) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -3.5e+102: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -3.5e+102) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); else tmp = Float64(1.0 / Float64(exp(b) - -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -3.5e+102) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3.5e+102], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -3.50000000000000011e102Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub0.0%
neg-mul-10.0%
*-commutative0.0%
associate-*r/0.0%
metadata-eval0.0%
distribute-neg-frac0.0%
exp-neg0.0%
distribute-rgt-neg-out0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 98.1%
if -3.50000000000000011e102 < a Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub87.7%
neg-mul-187.7%
*-commutative87.7%
associate-*r/87.7%
metadata-eval87.7%
distribute-neg-frac87.7%
exp-neg87.7%
distribute-rgt-neg-out87.7%
exp-neg87.7%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 91.3%
Final simplification92.5%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b 0.16666666666666666))))
(if (<= b 2.8e+77)
(/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666)))))))
(if (<= b 5e+99)
(/
1.0
(+
2.0
(*
b
(+
1.0
(/ (- (* (* b 0.5) (* b 0.5)) (* t_0 t_0)) (- (* b 0.5) t_0))))))
(/
1.0
(+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))))
double code(double a, double b) {
double t_0 = b * (b * 0.16666666666666666);
double tmp;
if (b <= 2.8e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else if (b <= 5e+99) {
tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_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) :: t_0
real(8) :: tmp
t_0 = b * (b * 0.16666666666666666d0)
if (b <= 2.8d+77) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else if (b <= 5d+99) then
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + ((((b * 0.5d0) * (b * 0.5d0)) - (t_0 * t_0)) / ((b * 0.5d0) - t_0)))))
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 t_0 = b * (b * 0.16666666666666666);
double tmp;
if (b <= 2.8e+77) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else if (b <= 5e+99) {
tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): t_0 = b * (b * 0.16666666666666666) tmp = 0 if b <= 2.8e+77: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) elif b <= 5e+99: tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * 0.16666666666666666)) tmp = 0.0 if (b <= 2.8e+77) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); elseif (b <= 5e+99) tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(Float64(Float64(Float64(b * 0.5) * Float64(b * 0.5)) - Float64(t_0 * t_0)) / Float64(Float64(b * 0.5) - t_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) t_0 = b * (b * 0.16666666666666666); tmp = 0.0; if (b <= 2.8e+77) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); elseif (b <= 5e+99) tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.8e+77], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+99], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(N[(N[(N[(b * 0.5), $MachinePrecision] * N[(b * 0.5), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[(b * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $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}
t_0 := b \cdot \left(b \cdot 0.16666666666666666\right)\\
\mathbf{if}\;b \leq 2.8 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+99}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + \frac{\left(b \cdot 0.5\right) \cdot \left(b \cdot 0.5\right) - t\_0 \cdot t\_0}{b \cdot 0.5 - t\_0}\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 < 2.8e77Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub73.4%
neg-mul-173.4%
*-commutative73.4%
associate-*r/73.4%
metadata-eval73.4%
distribute-neg-frac73.4%
exp-neg73.4%
distribute-rgt-neg-out73.4%
exp-neg73.4%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 76.7%
rec-exp76.7%
Simplified76.7%
Taylor expanded in a around 0 65.8%
if 2.8e77 < b < 5.00000000000000008e99Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub37.5%
neg-mul-137.5%
*-commutative37.5%
associate-*r/37.5%
metadata-eval37.5%
distribute-neg-frac37.5%
exp-neg37.5%
distribute-rgt-neg-out37.5%
exp-neg37.5%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 8.6%
*-commutative8.6%
Simplified8.6%
distribute-lft-in8.6%
flip-+100.0%
Applied egg-rr100.0%
if 5.00000000000000008e99 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub73.2%
neg-mul-173.2%
*-commutative73.2%
associate-*r/73.2%
metadata-eval73.2%
distribute-neg-frac73.2%
exp-neg73.2%
distribute-rgt-neg-out73.2%
exp-neg73.2%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.3%
(FPCore (a b) :precision binary64 (if (<= b 6.5e+124) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 6.5e+124) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (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 <= 6.5d+124) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.5e+124) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.5e+124: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.5e+124) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.5e+124) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.5e+124], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{+124}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 6.50000000000000008e124Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub70.6%
neg-mul-170.6%
*-commutative70.6%
associate-*r/70.6%
metadata-eval70.6%
distribute-neg-frac70.6%
exp-neg70.6%
distribute-rgt-neg-out70.6%
exp-neg70.6%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 76.7%
rec-exp76.7%
Simplified76.7%
Taylor expanded in a around 0 64.5%
if 6.50000000000000008e124 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub78.8%
neg-mul-178.8%
*-commutative78.8%
associate-*r/78.8%
metadata-eval78.8%
distribute-neg-frac78.8%
exp-neg78.8%
distribute-rgt-neg-out78.8%
exp-neg78.8%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 84.3%
*-commutative84.3%
Simplified84.3%
Final simplification68.5%
(FPCore (a b) :precision binary64 (if (<= b 6.2e+101) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 6.2e+101) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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 <= 6.2d+101) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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 <= 6.2e+101) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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 <= 6.2e+101: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) 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 <= 6.2e+101) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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 <= 6.2e+101) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); 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, 6.2e+101], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 6.2 \cdot 10^{+101}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\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 < 6.19999999999999998e101Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub72.0%
neg-mul-172.0%
*-commutative72.0%
associate-*r/72.0%
metadata-eval72.0%
distribute-neg-frac72.0%
exp-neg72.0%
distribute-rgt-neg-out72.0%
exp-neg72.0%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 76.2%
rec-exp76.2%
Simplified76.2%
Taylor expanded in a around 0 64.7%
if 6.19999999999999998e101 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub73.2%
neg-mul-173.2%
*-commutative73.2%
associate-*r/73.2%
metadata-eval73.2%
distribute-neg-frac73.2%
exp-neg73.2%
distribute-rgt-neg-out73.2%
exp-neg73.2%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification72.5%
(FPCore (a b) :precision binary64 (if (<= b 1.15e+116) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.15e+116) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (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.15d+116) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.15e+116) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.15e+116: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.15e+116) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.15e+116) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.15e+116], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.15 \cdot 10^{+116}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.14999999999999997e116Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
+-commutative99.5%
remove-double-neg99.5%
sub-neg99.5%
div-sub70.9%
neg-mul-170.9%
*-commutative70.9%
associate-*r/70.9%
metadata-eval70.9%
distribute-neg-frac70.9%
exp-neg70.9%
distribute-rgt-neg-out70.9%
exp-neg70.9%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 76.6%
rec-exp76.6%
Simplified76.6%
Taylor expanded in a around 0 59.2%
if 1.14999999999999997e116 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
div-sub77.4%
neg-mul-177.4%
*-commutative77.4%
associate-*r/77.4%
metadata-eval77.4%
distribute-neg-frac77.4%
exp-neg77.4%
distribute-rgt-neg-out77.4%
exp-neg77.4%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 82.8%
*-commutative82.8%
Simplified82.8%
Final simplification64.1%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
def code(a, b): return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.3%
neg-mul-172.3%
*-commutative72.3%
associate-*r/72.3%
metadata-eval72.3%
distribute-neg-frac72.3%
exp-neg72.3%
distribute-rgt-neg-out72.3%
exp-neg72.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 65.9%
rec-exp65.9%
Simplified65.9%
Taylor expanded in a around 0 50.3%
Final simplification50.3%
(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 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.3%
neg-mul-172.3%
*-commutative72.3%
associate-*r/72.3%
metadata-eval72.3%
distribute-neg-frac72.3%
exp-neg72.3%
distribute-rgt-neg-out72.3%
exp-neg72.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 65.9%
rec-exp65.9%
Simplified65.9%
Taylor expanded in a around 0 38.0%
*-commutative38.0%
Simplified38.0%
Final simplification38.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%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.3%
neg-mul-172.3%
*-commutative72.3%
associate-*r/72.3%
metadata-eval72.3%
distribute-neg-frac72.3%
exp-neg72.3%
distribute-rgt-neg-out72.3%
exp-neg72.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around 0 65.9%
rec-exp65.9%
Simplified65.9%
Taylor expanded in a around 0 38.7%
neg-mul-138.7%
unsub-neg38.7%
Simplified38.7%
Final simplification38.7%
(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%
+-commutative99.6%
remove-double-neg99.6%
sub-neg99.6%
div-sub72.3%
neg-mul-172.3%
*-commutative72.3%
associate-*r/72.3%
metadata-eval72.3%
distribute-neg-frac72.3%
exp-neg72.3%
distribute-rgt-neg-out72.3%
exp-neg72.3%
rgt-mult-inverse100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around 0 81.8%
Taylor expanded in b around 0 37.9%
Final simplification37.9%
(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 2024071
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))