
(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 14 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 (if (<= (exp a) 0.9999986) (/ (exp a) (+ (exp a) 1.0)) (exp (- (log1p (exp b))))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.9999986) {
tmp = exp(a) / (exp(a) + 1.0);
} else {
tmp = exp(-log1p(exp(b)));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.9999986) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = Math.exp(-Math.log1p(Math.exp(b)));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.9999986: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = math.exp(-math.log1p(math.exp(b))) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.9999986) tmp = Float64(exp(a) / Float64(exp(a) + 1.0)); else tmp = exp(Float64(-log1p(exp(b)))); end return tmp end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.9999986], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Exp[(-N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.9999986:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.99999859999999996Initial program 98.3%
Taylor expanded in b around 0 100.0%
if 0.99999859999999996 < (exp.f64 a) Initial program 98.4%
add-exp-log98.4%
div-exp98.5%
Applied egg-rr98.5%
Taylor expanded in a around 0 98.7%
neg-mul-198.7%
log1p-def98.7%
Simplified98.7%
Final simplification99.0%
(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 98.4%
add-exp-log98.4%
div-exp98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.9999986) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.9999986) {
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.9999986d0) 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.9999986) {
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.9999986: 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.9999986) 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.9999986) 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.9999986], 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.9999986:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.99999859999999996Initial program 98.3%
Taylor expanded in b around 0 100.0%
if 0.99999859999999996 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0 98.7%
Final simplification99.0%
(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 98.4%
Final simplification98.4%
(FPCore (a b) :precision binary64 (if (<= (exp a) 2e-76) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-76) {
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) <= 2d-76) 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) <= 2e-76) {
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) <= 2e-76: 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) <= 2e-76) 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) <= 2e-76) 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], 2e-76], 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 2 \cdot 10^{-76}:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1.99999999999999985e-76Initial program 98.2%
add-exp-log98.2%
div-exp98.3%
Applied egg-rr98.3%
Taylor expanded in a around inf 100.0%
if 1.99999999999999985e-76 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0 98.1%
Final simplification98.5%
(FPCore (a b)
:precision binary64
(if (<= b -4.05e-7)
1.0
(if (<= b -5.6e-110)
(+ 0.5 (* a 0.25))
(if (<= b -3.9e-157)
(exp a)
(if (<= b 380000.0)
(+ 0.5 (* b -0.25))
(if (<= b 1.35e+154)
(* -0.020833333333333332 (pow a 3.0))
(/ 2.0 (* b b))))))))
double code(double a, double b) {
double tmp;
if (b <= -4.05e-7) {
tmp = 1.0;
} else if (b <= -5.6e-110) {
tmp = 0.5 + (a * 0.25);
} else if (b <= -3.9e-157) {
tmp = exp(a);
} else if (b <= 380000.0) {
tmp = 0.5 + (b * -0.25);
} else if (b <= 1.35e+154) {
tmp = -0.020833333333333332 * pow(a, 3.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) :: tmp
if (b <= (-4.05d-7)) then
tmp = 1.0d0
else if (b <= (-5.6d-110)) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= (-3.9d-157)) then
tmp = exp(a)
else if (b <= 380000.0d0) then
tmp = 0.5d0 + (b * (-0.25d0))
else if (b <= 1.35d+154) then
tmp = (-0.020833333333333332d0) * (a ** 3.0d0)
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.05e-7) {
tmp = 1.0;
} else if (b <= -5.6e-110) {
tmp = 0.5 + (a * 0.25);
} else if (b <= -3.9e-157) {
tmp = Math.exp(a);
} else if (b <= 380000.0) {
tmp = 0.5 + (b * -0.25);
} else if (b <= 1.35e+154) {
tmp = -0.020833333333333332 * Math.pow(a, 3.0);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -4.05e-7: tmp = 1.0 elif b <= -5.6e-110: tmp = 0.5 + (a * 0.25) elif b <= -3.9e-157: tmp = math.exp(a) elif b <= 380000.0: tmp = 0.5 + (b * -0.25) elif b <= 1.35e+154: tmp = -0.020833333333333332 * math.pow(a, 3.0) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= -4.05e-7) tmp = 1.0; elseif (b <= -5.6e-110) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= -3.9e-157) tmp = exp(a); elseif (b <= 380000.0) tmp = Float64(0.5 + Float64(b * -0.25)); elseif (b <= 1.35e+154) tmp = Float64(-0.020833333333333332 * (a ^ 3.0)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -4.05e-7) tmp = 1.0; elseif (b <= -5.6e-110) tmp = 0.5 + (a * 0.25); elseif (b <= -3.9e-157) tmp = exp(a); elseif (b <= 380000.0) tmp = 0.5 + (b * -0.25); elseif (b <= 1.35e+154) tmp = -0.020833333333333332 * (a ^ 3.0); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -4.05e-7], 1.0, If[LessEqual[b, -5.6e-110], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -3.9e-157], N[Exp[a], $MachinePrecision], If[LessEqual[b, 380000.0], N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(-0.020833333333333332 * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.05 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq -5.6 \cdot 10^{-110}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq -3.9 \cdot 10^{-157}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 380000:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < -4.04999999999999987e-7Initial program 96.5%
add-exp-log96.5%
div-exp96.6%
Applied egg-rr96.6%
Taylor expanded in a around 0 96.6%
neg-mul-196.6%
log1p-def96.7%
Simplified96.7%
exp-neg96.6%
log1p-udef96.6%
add-exp-log96.6%
add-sqr-sqrt96.6%
associate-/r*96.6%
Applied egg-rr95.4%
*-inverses95.4%
Simplified95.4%
if -4.04999999999999987e-7 < b < -5.6000000000000001e-110Initial program 99.9%
Taylor expanded in b around 0 99.9%
Taylor expanded in a around 0 90.5%
if -5.6000000000000001e-110 < b < -3.89999999999999999e-157Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 81.9%
if -3.89999999999999999e-157 < b < 3.8e5Initial program 97.9%
Taylor expanded in a around 0 70.1%
Taylor expanded in b around 0 68.2%
*-commutative68.2%
Simplified68.2%
if 3.8e5 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in b around 0 21.9%
Taylor expanded in a around 0 2.8%
Taylor expanded in a around inf 45.4%
if 1.35000000000000003e154 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification78.3%
(FPCore (a b)
:precision binary64
(if (<= b -4.05e-7)
1.0
(if (<= b -5.6e-110)
(+ 0.5 (* a 0.25))
(if (<= b -3.9e-157)
(exp a)
(if (<= b 0.002)
(+ 0.5 (* b -0.25))
(if (<= b 1.08e+142) (exp a) (/ 2.0 (* b b))))))))
double code(double a, double b) {
double tmp;
if (b <= -4.05e-7) {
tmp = 1.0;
} else if (b <= -5.6e-110) {
tmp = 0.5 + (a * 0.25);
} else if (b <= -3.9e-157) {
tmp = exp(a);
} else if (b <= 0.002) {
tmp = 0.5 + (b * -0.25);
} else if (b <= 1.08e+142) {
tmp = exp(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.05d-7)) then
tmp = 1.0d0
else if (b <= (-5.6d-110)) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= (-3.9d-157)) then
tmp = exp(a)
else if (b <= 0.002d0) then
tmp = 0.5d0 + (b * (-0.25d0))
else if (b <= 1.08d+142) then
tmp = exp(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.05e-7) {
tmp = 1.0;
} else if (b <= -5.6e-110) {
tmp = 0.5 + (a * 0.25);
} else if (b <= -3.9e-157) {
tmp = Math.exp(a);
} else if (b <= 0.002) {
tmp = 0.5 + (b * -0.25);
} else if (b <= 1.08e+142) {
tmp = Math.exp(a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -4.05e-7: tmp = 1.0 elif b <= -5.6e-110: tmp = 0.5 + (a * 0.25) elif b <= -3.9e-157: tmp = math.exp(a) elif b <= 0.002: tmp = 0.5 + (b * -0.25) elif b <= 1.08e+142: tmp = math.exp(a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= -4.05e-7) tmp = 1.0; elseif (b <= -5.6e-110) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= -3.9e-157) tmp = exp(a); elseif (b <= 0.002) tmp = Float64(0.5 + Float64(b * -0.25)); elseif (b <= 1.08e+142) tmp = exp(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.05e-7) tmp = 1.0; elseif (b <= -5.6e-110) tmp = 0.5 + (a * 0.25); elseif (b <= -3.9e-157) tmp = exp(a); elseif (b <= 0.002) tmp = 0.5 + (b * -0.25); elseif (b <= 1.08e+142) tmp = exp(a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -4.05e-7], 1.0, If[LessEqual[b, -5.6e-110], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -3.9e-157], N[Exp[a], $MachinePrecision], If[LessEqual[b, 0.002], N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.08e+142], N[Exp[a], $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.05 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq -5.6 \cdot 10^{-110}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq -3.9 \cdot 10^{-157}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 0.002:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{+142}:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < -4.04999999999999987e-7Initial program 96.5%
add-exp-log96.5%
div-exp96.6%
Applied egg-rr96.6%
Taylor expanded in a around 0 96.6%
neg-mul-196.6%
log1p-def96.7%
Simplified96.7%
exp-neg96.6%
log1p-udef96.6%
add-exp-log96.6%
add-sqr-sqrt96.6%
associate-/r*96.6%
Applied egg-rr95.4%
*-inverses95.4%
Simplified95.4%
if -4.04999999999999987e-7 < b < -5.6000000000000001e-110Initial program 99.9%
Taylor expanded in b around 0 99.9%
Taylor expanded in a around 0 90.5%
if -5.6000000000000001e-110 < b < -3.89999999999999999e-157 or 2e-3 < b < 1.08e142Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 38.6%
if -3.89999999999999999e-157 < b < 2e-3Initial program 97.8%
Taylor expanded in a around 0 70.2%
Taylor expanded in b around 0 70.2%
*-commutative70.2%
Simplified70.2%
if 1.08e142 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 96.9%
unpow296.9%
Simplified96.9%
Taylor expanded in b around inf 96.9%
unpow296.9%
Simplified96.9%
Final simplification76.2%
(FPCore (a b) :precision binary64 (if (<= b -1.4) 1.0 (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (b <= -1.4) {
tmp = 1.0;
} 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 <= (-1.4d0)) then
tmp = 1.0d0
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 <= -1.4) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.4: tmp = 1.0 else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.4) tmp = 1.0; 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 <= -1.4) tmp = 1.0; else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.4], 1.0, 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 -1.4:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if b < -1.3999999999999999Initial program 96.5%
add-exp-log96.5%
div-exp96.5%
Applied egg-rr96.5%
Taylor expanded in a around 0 98.3%
neg-mul-198.3%
log1p-def98.3%
Simplified98.3%
exp-neg98.3%
log1p-udef98.3%
add-exp-log98.3%
add-sqr-sqrt98.3%
associate-/r*98.3%
Applied egg-rr97.0%
*-inverses97.0%
Simplified97.0%
if -1.3999999999999999 < b Initial program 98.9%
Taylor expanded in a around 0 79.6%
Taylor expanded in b around 0 63.9%
unpow263.9%
Simplified63.9%
Final simplification71.2%
(FPCore (a b) :precision binary64 (if (<= b -0.76) 1.0 (/ 1.0 (+ 2.0 (* 0.5 (* b b))))))
double code(double a, double b) {
double tmp;
if (b <= -0.76) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (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 <= (-0.76d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 + (0.5d0 * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.76) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (0.5 * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.76: tmp = 1.0 else: tmp = 1.0 / (2.0 + (0.5 * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.76) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 + Float64(0.5 * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.76) tmp = 1.0; else tmp = 1.0 / (2.0 + (0.5 * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.76], 1.0, N[(1.0 / N[(2.0 + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.76:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + 0.5 \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < -0.76000000000000001Initial program 96.5%
add-exp-log96.5%
div-exp96.5%
Applied egg-rr96.5%
Taylor expanded in a around 0 98.3%
neg-mul-198.3%
log1p-def98.3%
Simplified98.3%
exp-neg98.3%
log1p-udef98.3%
add-exp-log98.3%
add-sqr-sqrt98.3%
associate-/r*98.3%
Applied egg-rr97.0%
*-inverses97.0%
Simplified97.0%
if -0.76000000000000001 < b Initial program 98.9%
Taylor expanded in a around 0 79.6%
Taylor expanded in b around 0 63.9%
unpow263.9%
Simplified63.9%
Taylor expanded in b around inf 63.4%
unpow263.4%
Simplified63.4%
Final simplification70.8%
(FPCore (a b) :precision binary64 (if (<= b -4.05e-7) 1.0 (if (<= b 1.82) (+ 0.5 (* a 0.25)) (/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= -4.05e-7) {
tmp = 1.0;
} else if (b <= 1.82) {
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 <= (-4.05d-7)) then
tmp = 1.0d0
else if (b <= 1.82d0) 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 <= -4.05e-7) {
tmp = 1.0;
} else if (b <= 1.82) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -4.05e-7: tmp = 1.0 elif b <= 1.82: tmp = 0.5 + (a * 0.25) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= -4.05e-7) tmp = 1.0; elseif (b <= 1.82) 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 <= -4.05e-7) tmp = 1.0; elseif (b <= 1.82) tmp = 0.5 + (a * 0.25); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -4.05e-7], 1.0, If[LessEqual[b, 1.82], 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 -4.05 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.82:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < -4.04999999999999987e-7Initial program 96.5%
add-exp-log96.5%
div-exp96.6%
Applied egg-rr96.6%
Taylor expanded in a around 0 96.6%
neg-mul-196.6%
log1p-def96.7%
Simplified96.7%
exp-neg96.6%
log1p-udef96.6%
add-exp-log96.6%
add-sqr-sqrt96.6%
associate-/r*96.6%
Applied egg-rr95.4%
*-inverses95.4%
Simplified95.4%
if -4.04999999999999987e-7 < b < 1.82000000000000006Initial program 98.5%
Taylor expanded in b around 0 97.7%
Taylor expanded in a around 0 71.7%
if 1.82000000000000006 < b Initial program 100.0%
Taylor expanded in a around 0 98.5%
Taylor expanded in b around 0 47.9%
unpow247.9%
Simplified47.9%
Taylor expanded in b around inf 47.9%
unpow247.9%
Simplified47.9%
Final simplification71.3%
(FPCore (a b) :precision binary64 (if (<= b -4.05e-7) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -4.05e-7) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-4.05d-7)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -4.05e-7) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -4.05e-7: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -4.05e-7) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -4.05e-7) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -4.05e-7], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.05 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -4.04999999999999987e-7Initial program 96.5%
add-exp-log96.5%
div-exp96.6%
Applied egg-rr96.6%
Taylor expanded in a around 0 96.6%
neg-mul-196.6%
log1p-def96.7%
Simplified96.7%
exp-neg96.6%
log1p-udef96.6%
add-exp-log96.6%
add-sqr-sqrt96.6%
associate-/r*96.6%
Applied egg-rr95.4%
*-inverses95.4%
Simplified95.4%
if -4.04999999999999987e-7 < b Initial program 98.9%
Taylor expanded in b around 0 77.4%
Taylor expanded in a around 0 50.2%
Final simplification60.4%
(FPCore (a b) :precision binary64 (if (<= b -0.68) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -0.68) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-0.68d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.68) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.68: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.68) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.68) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.68], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.68:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -0.680000000000000049Initial program 96.5%
add-exp-log96.5%
div-exp96.5%
Applied egg-rr96.5%
Taylor expanded in a around 0 98.3%
neg-mul-198.3%
log1p-def98.3%
Simplified98.3%
exp-neg98.3%
log1p-udef98.3%
add-exp-log98.3%
add-sqr-sqrt98.3%
associate-/r*98.3%
Applied egg-rr97.0%
*-inverses97.0%
Simplified97.0%
if -0.680000000000000049 < b Initial program 98.9%
Taylor expanded in a around 0 79.6%
Taylor expanded in b around 0 50.6%
+-commutative50.6%
Simplified50.6%
Final simplification60.9%
(FPCore (a b) :precision binary64 (if (<= b -0.68) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -0.68) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-0.68d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.68) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.68: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -0.68) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.68) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.68], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.68:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -0.680000000000000049Initial program 96.5%
add-exp-log96.5%
div-exp96.5%
Applied egg-rr96.5%
Taylor expanded in a around 0 98.3%
neg-mul-198.3%
log1p-def98.3%
Simplified98.3%
exp-neg98.3%
log1p-udef98.3%
add-exp-log98.3%
add-sqr-sqrt98.3%
associate-/r*98.3%
Applied egg-rr97.0%
*-inverses97.0%
Simplified97.0%
if -0.680000000000000049 < b Initial program 98.9%
Taylor expanded in a around 0 79.6%
Taylor expanded in b around 0 49.4%
Final simplification60.0%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 98.4%
Taylor expanded in a around 0 83.8%
Taylor expanded in b around 0 42.6%
Final simplification42.6%
(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 2023182
(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))))