
(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 (if (<= (exp a) 0.999999999996) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999999999996) {
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.999999999996d0) 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.999999999996) {
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.999999999996: 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.999999999996) 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.999999999996) 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.999999999996], 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.999999999996:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999999999995999977Initial program 100.0%
Taylor expanded in b around 0 100.0%
if 0.999999999995999977 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0 99.5%
Final simplification99.7%
(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.6%
add-exp-log99.6%
div-exp99.6%
Applied egg-rr99.6%
Final simplification99.6%
(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.6%
Final simplification99.6%
(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 99.4%
Taylor expanded in a around 0 99.4%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= a -4e-37) (exp a) (/ 1.0 (+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))
double code(double a, double b) {
double tmp;
if (a <= -4e-37) {
tmp = exp(a);
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (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 (a <= (-4d-37)) then
tmp = exp(a)
else
tmp = 1.0d0 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -4e-37) {
tmp = Math.exp(a);
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -4e-37: tmp = math.exp(a) else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) return tmp
function code(a, b) tmp = 0.0 if (a <= -4e-37) tmp = exp(a); else tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -4e-37) tmp = exp(a); else tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -4e-37], N[Exp[a], $MachinePrecision], N[(1.0 / N[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4 \cdot 10^{-37}:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if a < -4.00000000000000027e-37Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 96.4%
if -4.00000000000000027e-37 < a Initial program 99.4%
Taylor expanded in a around 0 99.5%
Taylor expanded in b around 0 67.1%
unpow267.1%
Simplified67.1%
*-un-lft-identity67.1%
associate-*r*67.1%
distribute-rgt-out67.1%
*-commutative67.1%
Applied egg-rr67.1%
*-commutative67.1%
flip-+67.1%
associate-*l/69.7%
metadata-eval69.7%
swap-sqr69.7%
metadata-eval69.7%
*-commutative69.7%
cancel-sign-sub-inv69.7%
metadata-eval69.7%
Applied egg-rr69.7%
Final simplification77.8%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b 0.5))))
(if (<= b -2.2)
(+ 0.5 (* a 0.25))
(if (<= b 1e+103)
(/ 1.0 (+ 2.0 (/ (- (* b b) (* t_0 t_0)) (- b t_0))))
(/
1.0
(+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))))
double code(double a, double b) {
double t_0 = b * (b * 0.5);
double tmp;
if (b <= -2.2) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0)));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (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) :: t_0
real(8) :: tmp
t_0 = b * (b * 0.5d0)
if (b <= (-2.2d0)) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 1d+103) then
tmp = 1.0d0 / (2.0d0 + (((b * b) - (t_0 * t_0)) / (b - t_0)))
else
tmp = 1.0d0 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b * (b * 0.5);
double tmp;
if (b <= -2.2) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0)));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): t_0 = b * (b * 0.5) tmp = 0 if b <= -2.2: tmp = 0.5 + (a * 0.25) elif b <= 1e+103: tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0))) else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * 0.5)) tmp = 0.0 if (b <= -2.2) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 1e+103) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(Float64(b * b) - Float64(t_0 * t_0)) / Float64(b - t_0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); end return tmp end
function tmp_2 = code(a, b) t_0 = b * (b * 0.5); tmp = 0.0; if (b <= -2.2) tmp = 0.5 + (a * 0.25); elseif (b <= 1e+103) tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0))); else tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.2], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+103], N[(1.0 / N[(2.0 + N[(N[(N[(b * b), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot 0.5\right)\\
\mathbf{if}\;b \leq -2.2:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot b - t_0 \cdot t_0}{b - t_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if b < -2.2000000000000002Initial program 100.0%
Taylor expanded in b around 0 18.8%
Taylor expanded in a around 0 18.8%
*-commutative18.8%
Simplified18.8%
if -2.2000000000000002 < b < 1e103Initial program 99.4%
Taylor expanded in a around 0 72.9%
Taylor expanded in b around 0 58.2%
unpow258.2%
Simplified58.2%
*-un-lft-identity58.2%
associate-*r*58.2%
distribute-rgt-out58.2%
*-commutative58.2%
Applied egg-rr58.2%
distribute-lft-in58.2%
*-rgt-identity58.2%
flip-+62.8%
Applied egg-rr62.8%
if 1e103 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 83.8%
unpow283.8%
Simplified83.8%
*-un-lft-identity83.8%
associate-*r*83.8%
distribute-rgt-out83.8%
*-commutative83.8%
Applied egg-rr83.8%
*-commutative83.8%
flip-+83.8%
associate-*l/100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification61.7%
(FPCore (a b) :precision binary64 (if (<= b -2.0) (+ 0.5 (* a 0.25)) (/ 1.0 (+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (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 <= (-2.0d0)) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 1.0d0 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 0.5 + (a * 0.25) else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 0.5 + (a * 0.25); else tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if b < -2Initial program 100.0%
Taylor expanded in b around 0 18.8%
Taylor expanded in a around 0 18.8%
*-commutative18.8%
Simplified18.8%
if -2 < b Initial program 99.5%
Taylor expanded in a around 0 78.8%
Taylor expanded in b around 0 63.8%
unpow263.8%
Simplified63.8%
*-un-lft-identity63.8%
associate-*r*63.8%
distribute-rgt-out63.8%
*-commutative63.8%
Applied egg-rr63.8%
*-commutative63.8%
flip-+63.8%
associate-*l/67.3%
metadata-eval67.3%
swap-sqr67.3%
metadata-eval67.3%
*-commutative67.3%
cancel-sign-sub-inv67.3%
metadata-eval67.3%
Applied egg-rr67.3%
Final simplification58.8%
(FPCore (a b) :precision binary64 (if (<= b -2.1) (+ 0.5 (* a 0.25)) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= -2.1) {
tmp = 0.5 + (a * 0.25);
} 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 <= (-2.1d0)) then
tmp = 0.5d0 + (a * 0.25d0)
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 <= -2.1) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.1: tmp = 0.5 + (a * 0.25) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.1) tmp = Float64(0.5 + Float64(a * 0.25)); 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 <= -2.1) tmp = 0.5 + (a * 0.25); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.1], N[(0.5 + N[(a * 0.25), $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 -2.1:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -2.10000000000000009Initial program 100.0%
Taylor expanded in b around 0 18.8%
Taylor expanded in a around 0 18.8%
*-commutative18.8%
Simplified18.8%
if -2.10000000000000009 < b Initial program 99.5%
Taylor expanded in a around 0 78.8%
Taylor expanded in b around 0 63.8%
unpow263.8%
Simplified63.8%
*-un-lft-identity63.8%
associate-*r*63.8%
distribute-rgt-out63.8%
*-commutative63.8%
Applied egg-rr63.8%
Final simplification55.9%
(FPCore (a b) :precision binary64 (if (<= b 2.0) 0.5 (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} 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 <= 2.0d0) then
tmp = 0.5d0
else
tmp = 2.0d0 / (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 = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 0.5 else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = 0.5; else tmp = Float64(2.0 / 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 = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], 0.5, N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2Initial program 99.4%
Taylor expanded in a around 0 76.0%
Taylor expanded in b around 0 54.5%
if 2 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 56.6%
unpow256.6%
Simplified56.6%
Taylor expanded in b around inf 56.6%
unpow256.6%
Simplified56.6%
Final simplification55.1%
(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%
Taylor expanded in a around 0 82.6%
Taylor expanded in b around 0 40.5%
Final simplification40.5%
(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 2023215
(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))))