
(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 13 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 (- a (log (+ (exp a) (exp b))))))
double code(double a, double b) {
return exp((a - log((exp(a) + exp(b)))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp((a - log((exp(a) + exp(b)))))
end function
public static double code(double a, double b) {
return Math.exp((a - Math.log((Math.exp(a) + Math.exp(b)))));
}
def code(a, b): return math.exp((a - math.log((math.exp(a) + math.exp(b)))))
function code(a, b) return exp(Float64(a - log(Float64(exp(a) + exp(b))))) end
function tmp = code(a, b) tmp = exp((a - log((exp(a) + exp(b))))); end
code[a_, b_] := N[Exp[N[(a - N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{a - \log \left(e^{a} + e^{b}\right)}
\end{array}
Initial program 99.2%
add-exp-log99.2%
div-exp99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.999995) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999995) {
tmp = exp(a) / (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 (exp(a) <= 0.999995d0) then
tmp = exp(a) / (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 (Math.exp(a) <= 0.999995) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.999995: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.999995) tmp = Float64(exp(a) / Float64(exp(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 (exp(a) <= 0.999995) tmp = exp(a) / (exp(a) + 1.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.999995], N[(N[Exp[a], $MachinePrecision] / 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}\;e^{a} \leq 0.999995:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.99999499999999997Initial program 100.0%
Taylor expanded in b around 0 97.3%
if 0.99999499999999997 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0 98.7%
Final simplification98.3%
(FPCore (a b) :precision binary64 (cbrt (pow (+ 1.0 (exp (- b a))) -3.0)))
double code(double a, double b) {
return cbrt(pow((1.0 + exp((b - a))), -3.0));
}
public static double code(double a, double b) {
return Math.cbrt(Math.pow((1.0 + Math.exp((b - a))), -3.0));
}
function code(a, b) return cbrt((Float64(1.0 + exp(Float64(b - a))) ^ -3.0)) end
code[a_, b_] := N[Power[N[Power[N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -3.0], $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{{\left(1 + e^{b - a}\right)}^{-3}}
\end{array}
Initial program 99.2%
add-cbrt-cube98.6%
pow1/399.2%
pow399.2%
clear-num99.1%
inv-pow99.1%
pow-pow99.1%
metadata-eval99.1%
Applied egg-rr99.1%
unpow1/398.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in b around inf 98.6%
rem-exp-log98.6%
exp-diff99.0%
sub-neg99.0%
+-commutative99.0%
prod-exp98.6%
rem-exp-log98.6%
distribute-lft-in73.2%
rec-exp73.2%
lft-mult-inverse99.0%
prod-exp99.4%
Simplified99.4%
Final simplification99.4%
(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}
Initial program 99.2%
Final simplification99.2%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.999995) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999995) {
tmp = 1.0 / (1.0 + exp(-a));
} 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 (exp(a) <= 0.999995d0) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
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 (Math.exp(a) <= 0.999995) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.999995: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.999995) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.999995) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.999995], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.999995:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.99999499999999997Initial program 100.0%
add-cbrt-cube100.0%
pow1/399.9%
pow399.9%
clear-num99.8%
inv-pow99.8%
pow-pow99.8%
metadata-eval99.8%
Applied egg-rr99.8%
unpow1/399.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in b around inf 99.9%
rem-exp-log99.9%
exp-diff99.9%
sub-neg99.9%
+-commutative99.9%
prod-exp99.9%
rem-exp-log99.9%
distribute-lft-in8.4%
rec-exp8.4%
lft-mult-inverse99.9%
prod-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 97.3%
if 0.99999499999999997 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0 98.7%
Final simplification98.3%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a);
} 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 (exp(a) <= 0.0d0) then
tmp = exp(a)
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 (Math.exp(a) <= 0.0) {
tmp = Math.exp(a);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = exp(a); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0 97.2%
Final simplification97.9%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.999999996) (exp a) (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999999996) {
tmp = exp(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 (exp(a) <= 0.999999996d0) then
tmp = exp(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 (Math.exp(a) <= 0.999999996) {
tmp = Math.exp(a);
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.999999996: tmp = math.exp(a) else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.999999996) tmp = exp(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 (exp(a) <= 0.999999996) tmp = exp(a); else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.999999996], N[Exp[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}\;e^{a} \leq 0.999999996:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999999996000000002Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 93.5%
if 0.999999996000000002 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0 98.7%
Taylor expanded in b around 0 66.8%
unpow266.8%
Simplified66.8%
Final simplification74.3%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* 0.5 (* b b))))
(if (<= b 3.5e+96)
(/ 1.0 (- 2.0 a))
(if (<= b 1.35e+154) (/ (- t_0 b) (* b t_0)) (/ -2.0 (* b b))))))
double code(double a, double b) {
double t_0 = 0.5 * (b * b);
double tmp;
if (b <= 3.5e+96) {
tmp = 1.0 / (2.0 - a);
} else if (b <= 1.35e+154) {
tmp = (t_0 - b) / (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 = 0.5d0 * (b * b)
if (b <= 3.5d+96) then
tmp = 1.0d0 / (2.0d0 - a)
else if (b <= 1.35d+154) then
tmp = (t_0 - b) / (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 = 0.5 * (b * b);
double tmp;
if (b <= 3.5e+96) {
tmp = 1.0 / (2.0 - a);
} else if (b <= 1.35e+154) {
tmp = (t_0 - b) / (b * t_0);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): t_0 = 0.5 * (b * b) tmp = 0 if b <= 3.5e+96: tmp = 1.0 / (2.0 - a) elif b <= 1.35e+154: tmp = (t_0 - b) / (b * t_0) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) t_0 = Float64(0.5 * Float64(b * b)) tmp = 0.0 if (b <= 3.5e+96) tmp = Float64(1.0 / Float64(2.0 - a)); elseif (b <= 1.35e+154) tmp = Float64(Float64(t_0 - b) / Float64(b * t_0)); else tmp = Float64(-2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) t_0 = 0.5 * (b * b); tmp = 0.0; if (b <= 3.5e+96) tmp = 1.0 / (2.0 - a); elseif (b <= 1.35e+154) tmp = (t_0 - b) / (b * t_0); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 3.5e+96], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(N[(t$95$0 - b), $MachinePrecision] / N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;b \leq 3.5 \cdot 10^{+96}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{t_0 - b}{b \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 3.4999999999999999e96Initial program 99.5%
add-cbrt-cube98.8%
pow1/399.4%
pow399.4%
clear-num99.4%
inv-pow99.4%
pow-pow99.4%
metadata-eval99.4%
Applied egg-rr99.4%
unpow1/398.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in b around inf 98.8%
rem-exp-log98.8%
exp-diff98.8%
sub-neg98.8%
+-commutative98.8%
prod-exp98.8%
rem-exp-log98.8%
distribute-lft-in75.3%
rec-exp75.3%
lft-mult-inverse99.3%
prod-exp99.3%
Simplified99.3%
Taylor expanded in b around 0 75.5%
Taylor expanded in a around 0 50.7%
mul-1-neg50.7%
unsub-neg50.7%
Simplified50.7%
if 3.4999999999999999e96 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 4.3%
+-commutative4.3%
Simplified4.3%
Taylor expanded in b around inf 4.3%
associate-*r/4.3%
metadata-eval4.3%
unpow24.3%
Simplified4.3%
clear-num4.3%
frac-sub90.4%
*-un-lft-identity90.4%
div-inv90.4%
metadata-eval90.4%
metadata-eval90.4%
div-inv90.4%
/-rgt-identity90.4%
div-inv90.4%
metadata-eval90.4%
Applied egg-rr90.4%
if 1.35000000000000003e154 < b Initial program 97.3%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 7.2%
+-commutative7.2%
Simplified7.2%
Taylor expanded in b around inf 7.2%
associate-*r/7.2%
metadata-eval7.2%
unpow27.2%
Simplified7.2%
Taylor expanded in b around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification59.4%
(FPCore (a b) :precision binary64 (if (<= b -2.0) 0.5 (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5;
} 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 <= (-2.0d0)) then
tmp = 0.5d0
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 <= -2.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 0.5 else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = 0.5; 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 <= -2.0) tmp = 0.5; else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], 0.5, 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 -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if b < -2Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 18.8%
if -2 < b Initial program 99.0%
Taylor expanded in a around 0 79.0%
Taylor expanded in b around 0 63.8%
unpow263.8%
Simplified63.8%
Final simplification56.6%
(FPCore (a b) :precision binary64 (if (<= b 0.0108) (+ 0.5 (* a 0.25)) (/ -2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 0.0108) {
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 <= 0.0108d0) 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 <= 0.0108) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.0108: tmp = 0.5 + (a * 0.25) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.0108) 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 <= 0.0108) tmp = 0.5 + (a * 0.25); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.0108], 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 0.0108:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 0.010800000000000001Initial program 99.4%
Taylor expanded in b around 0 79.7%
Taylor expanded in a around 0 56.4%
*-commutative56.4%
Simplified56.4%
if 0.010800000000000001 < b Initial program 98.6%
Taylor expanded in a around 0 98.6%
Taylor expanded in b around 0 5.6%
+-commutative5.6%
Simplified5.6%
Taylor expanded in b around inf 5.6%
associate-*r/5.6%
metadata-eval5.6%
unpow25.6%
Simplified5.6%
Taylor expanded in b around 0 54.6%
unpow254.6%
Simplified54.6%
Final simplification55.9%
(FPCore (a b) :precision binary64 (if (<= b 3.35e+72) (/ 1.0 (- 2.0 a)) (/ -2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 3.35e+72) {
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 <= 3.35d+72) 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 <= 3.35e+72) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.35e+72: tmp = 1.0 / (2.0 - a) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.35e+72) 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 <= 3.35e+72) tmp = 1.0 / (2.0 - a); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.35e+72], 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 3.35 \cdot 10^{+72}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 3.3499999999999999e72Initial program 99.5%
add-cbrt-cube98.8%
pow1/399.4%
pow399.4%
clear-num99.4%
inv-pow99.4%
pow-pow99.4%
metadata-eval99.4%
Applied egg-rr99.4%
unpow1/398.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in b around inf 98.8%
rem-exp-log98.8%
exp-diff98.8%
sub-neg98.8%
+-commutative98.8%
prod-exp98.8%
rem-exp-log98.8%
distribute-lft-in75.5%
rec-exp75.5%
lft-mult-inverse99.2%
prod-exp99.2%
Simplified99.2%
Taylor expanded in b around 0 77.1%
Taylor expanded in a around 0 52.3%
mul-1-neg52.3%
unsub-neg52.3%
Simplified52.3%
if 3.3499999999999999e72 < b Initial program 98.1%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 6.2%
+-commutative6.2%
Simplified6.2%
Taylor expanded in b around inf 6.2%
associate-*r/6.2%
metadata-eval6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in b around 0 70.6%
unpow270.6%
Simplified70.6%
Final simplification56.2%
(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.2%
Taylor expanded in b around 0 67.9%
Taylor expanded in a around 0 41.5%
*-commutative41.5%
Simplified41.5%
Final simplification41.5%
(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.2%
Taylor expanded in a around 0 82.4%
Taylor expanded in b around 0 41.4%
Final simplification41.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 2023238
(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))))