
(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 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (exp (- 0.0 (log1p (exp b))))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.0;
} else {
tmp = exp((0.0 - log1p(exp(b))));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = Math.exp((0.0 - Math.log1p(Math.exp(b))));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / 2.0 else: tmp = math.exp((0.0 - math.log1p(math.exp(b)))) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / 2.0); else tmp = exp(Float64(0.0 - log1p(exp(b)))); end return tmp end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[Exp[N[(0.0 - N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;e^{0 - \mathsf{log1p}\left(e^{b}\right)}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.3%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified100.0%
if 0.0 < (exp.f64 a) Initial program 99.5%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.1%
Simplified99.1%
inv-powN/A
pow-to-expN/A
exp-lowering-exp.f64N/A
*-lowering-*.f64N/A
log1p-defineN/A
log1p-lowering-log1p.f64N/A
exp-lowering-exp.f6499.1%
Applied egg-rr99.1%
Final simplification99.3%
(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%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.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.0d0) then
tmp = exp(a) / 2.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.0) {
tmp = Math.exp(a) / 2.0;
} 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) / 2.0 else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / 2.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.0) tmp = exp(a) / 2.0; 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[(N[Exp[a], $MachinePrecision] / 2.0), $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:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.3%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified100.0%
if 0.0 < (exp.f64 a) Initial program 99.5%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.1%
Simplified99.1%
Final simplification99.3%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ 1.0 (* b 0.5))) (t_1 (* b t_0)))
(if (<= b 3.1e+44)
(/ (exp a) 2.0)
(/ 4.0 (+ 8.0 (* t_1 (* b (* t_0 t_1))))))))
double code(double a, double b) {
double t_0 = 1.0 + (b * 0.5);
double t_1 = b * t_0;
double tmp;
if (b <= 3.1e+44) {
tmp = exp(a) / 2.0;
} else {
tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + (b * 0.5d0)
t_1 = b * t_0
if (b <= 3.1d+44) then
tmp = exp(a) / 2.0d0
else
tmp = 4.0d0 / (8.0d0 + (t_1 * (b * (t_0 * t_1))))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 1.0 + (b * 0.5);
double t_1 = b * t_0;
double tmp;
if (b <= 3.1e+44) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1))));
}
return tmp;
}
def code(a, b): t_0 = 1.0 + (b * 0.5) t_1 = b * t_0 tmp = 0 if b <= 3.1e+44: tmp = math.exp(a) / 2.0 else: tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1)))) return tmp
function code(a, b) t_0 = Float64(1.0 + Float64(b * 0.5)) t_1 = Float64(b * t_0) tmp = 0.0 if (b <= 3.1e+44) tmp = Float64(exp(a) / 2.0); else tmp = Float64(4.0 / Float64(8.0 + Float64(t_1 * Float64(b * Float64(t_0 * t_1))))); end return tmp end
function tmp_2 = code(a, b) t_0 = 1.0 + (b * 0.5); t_1 = b * t_0; tmp = 0.0; if (b <= 3.1e+44) tmp = exp(a) / 2.0; else tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1)))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b * t$95$0), $MachinePrecision]}, If[LessEqual[b, 3.1e+44], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(4.0 / N[(8.0 + N[(t$95$1 * N[(b * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + b \cdot 0.5\\
t_1 := b \cdot t\_0\\
\mathbf{if}\;b \leq 3.1 \cdot 10^{+44}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{4}{8 + t\_1 \cdot \left(b \cdot \left(t\_0 \cdot t\_1\right)\right)}\\
\end{array}
\end{array}
if b < 3.09999999999999996e44Initial program 98.9%
Taylor expanded in b around 0
Simplified78.6%
Taylor expanded in a around 0
Simplified78.1%
if 3.09999999999999996e44 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.3%
Simplified55.3%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr6.8%
Taylor expanded in b around 0
Simplified95.5%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ 1.0 (* b 0.5))) (t_1 (* b t_0)))
(if (<= b -35000000.0)
0.5
(if (<= b 2.5e+44)
(/
1.0
(+
(+ 2.0 (* a (+ 1.0 (* a 0.5))))
(* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))
(/ 4.0 (+ 8.0 (* t_1 (* b (* t_0 t_1)))))))))
double code(double a, double b) {
double t_0 = 1.0 + (b * 0.5);
double t_1 = b * t_0;
double tmp;
if (b <= -35000000.0) {
tmp = 0.5;
} else if (b <= 2.5e+44) {
tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
} else {
tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + (b * 0.5d0)
t_1 = b * t_0
if (b <= (-35000000.0d0)) then
tmp = 0.5d0
else if (b <= 2.5d+44) then
tmp = 1.0d0 / ((2.0d0 + (a * (1.0d0 + (a * 0.5d0)))) + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
else
tmp = 4.0d0 / (8.0d0 + (t_1 * (b * (t_0 * t_1))))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 1.0 + (b * 0.5);
double t_1 = b * t_0;
double tmp;
if (b <= -35000000.0) {
tmp = 0.5;
} else if (b <= 2.5e+44) {
tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
} else {
tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1))));
}
return tmp;
}
def code(a, b): t_0 = 1.0 + (b * 0.5) t_1 = b * t_0 tmp = 0 if b <= -35000000.0: tmp = 0.5 elif b <= 2.5e+44: tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) else: tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1)))) return tmp
function code(a, b) t_0 = Float64(1.0 + Float64(b * 0.5)) t_1 = Float64(b * t_0) tmp = 0.0 if (b <= -35000000.0) tmp = 0.5; elseif (b <= 2.5e+44) tmp = Float64(1.0 / Float64(Float64(2.0 + Float64(a * Float64(1.0 + Float64(a * 0.5)))) + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); else tmp = Float64(4.0 / Float64(8.0 + Float64(t_1 * Float64(b * Float64(t_0 * t_1))))); end return tmp end
function tmp_2 = code(a, b) t_0 = 1.0 + (b * 0.5); t_1 = b * t_0; tmp = 0.0; if (b <= -35000000.0) tmp = 0.5; elseif (b <= 2.5e+44) tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); else tmp = 4.0 / (8.0 + (t_1 * (b * (t_0 * t_1)))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b * t$95$0), $MachinePrecision]}, If[LessEqual[b, -35000000.0], 0.5, If[LessEqual[b, 2.5e+44], N[(1.0 / N[(N[(2.0 + N[(a * N[(1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 / N[(8.0 + N[(t$95$1 * N[(b * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + b \cdot 0.5\\
t_1 := b \cdot t\_0\\
\mathbf{if}\;b \leq -35000000:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{+44}:\\
\;\;\;\;\frac{1}{\left(2 + a \cdot \left(1 + a \cdot 0.5\right)\right) + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{4}{8 + t\_1 \cdot \left(b \cdot \left(t\_0 \cdot t\_1\right)\right)}\\
\end{array}
\end{array}
if b < -3.5e7Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
Simplified18.8%
if -3.5e7 < b < 2.4999999999999998e44Initial program 98.6%
Taylor expanded in b around 0
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6498.6%
Simplified98.6%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6498.6%
Simplified98.6%
Taylor expanded in a around 0
Simplified86.4%
if 2.4999999999999998e44 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.3%
Simplified55.3%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr6.8%
Taylor expanded in b around 0
Simplified95.5%
(FPCore (a b)
:precision binary64
(if (<= b -86000000.0)
0.5
(/
1.0
(+
(+ 2.0 (* a (+ 1.0 (* a 0.5))))
(* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= -86000000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (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 <= (-86000000.0d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / ((2.0d0 + (a * (1.0d0 + (a * 0.5d0)))) + (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 <= -86000000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -86000000.0: tmp = 0.5 else: tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= -86000000.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(Float64(2.0 + Float64(a * Float64(1.0 + Float64(a * 0.5)))) + 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 <= -86000000.0) tmp = 0.5; else tmp = 1.0 / ((2.0 + (a * (1.0 + (a * 0.5)))) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -86000000.0], 0.5, N[(1.0 / N[(N[(2.0 + N[(a * N[(1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 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 -86000000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(2 + a \cdot \left(1 + a \cdot 0.5\right)\right) + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < -8.6e7Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
Simplified18.8%
if -8.6e7 < b Initial program 99.0%
Taylor expanded in b around 0
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6494.6%
Simplified94.6%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6494.6%
Simplified94.6%
Taylor expanded in a around 0
Simplified84.6%
(FPCore (a b) :precision binary64 (if (<= a -2.6e-5) (/ 1.0 (* b (* b (+ 0.5 (/ 2.0 (* b b)))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (a <= -2.6e-5) {
tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b)))));
} 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 (a <= (-2.6d-5)) then
tmp = 1.0d0 / (b * (b * (0.5d0 + (2.0d0 / (b * b)))))
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 (a <= -2.6e-5) {
tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.6e-5: tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b))))) 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 (a <= -2.6e-5) tmp = Float64(1.0 / Float64(b * Float64(b * Float64(0.5 + Float64(2.0 / Float64(b * b)))))); 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 (a <= -2.6e-5) tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b))))); 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[a, -2.6e-5], N[(1.0 / N[(b * N[(b * N[(0.5 + N[(2.0 / N[(b * b), $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}\;a \leq -2.6 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{b \cdot \left(b \cdot \left(0.5 + \frac{2}{b \cdot b}\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 a < -2.59999999999999984e-5Initial program 98.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6445.3%
Simplified45.3%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6423.9%
Simplified23.9%
Taylor expanded in b around inf
*-lowering-*.f6423.9%
Simplified23.9%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6453.6%
Simplified53.6%
if -2.59999999999999984e-5 < a Initial program 99.5%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.0%
Simplified99.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6471.6%
Simplified71.6%
(FPCore (a b) :precision binary64 (if (<= a -2.6e-5) (/ 1.0 (* b (* b (+ 0.5 (/ 2.0 (* b b)))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* 0.16666666666666666 (* b b))))))))
double code(double a, double b) {
double tmp;
if (a <= -2.6e-5) {
tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (0.16666666666666666 * (b * b)))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2.6d-5)) then
tmp = 1.0d0 / (b * (b * (0.5d0 + (2.0d0 / (b * b)))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (0.16666666666666666d0 * (b * b)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2.6e-5) {
tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (0.16666666666666666 * (b * b)))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.6e-5: tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (0.16666666666666666 * (b * b))))) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.6e-5) tmp = Float64(1.0 / Float64(b * Float64(b * Float64(0.5 + Float64(2.0 / Float64(b * b)))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(0.16666666666666666 * Float64(b * b)))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.6e-5) tmp = 1.0 / (b * (b * (0.5 + (2.0 / (b * b))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (0.16666666666666666 * (b * b))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.6e-5], N[(1.0 / N[(b * N[(b * N[(0.5 + N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(0.16666666666666666 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.6 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{b \cdot \left(b \cdot \left(0.5 + \frac{2}{b \cdot b}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + 0.16666666666666666 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if a < -2.59999999999999984e-5Initial program 98.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6445.3%
Simplified45.3%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6423.9%
Simplified23.9%
Taylor expanded in b around inf
*-lowering-*.f6423.9%
Simplified23.9%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6453.6%
Simplified53.6%
if -2.59999999999999984e-5 < a Initial program 99.5%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.0%
Simplified99.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6471.6%
Simplified71.6%
Taylor expanded in b around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6471.5%
Simplified71.5%
(FPCore (a b) :precision binary64 (if (<= b 3.1) (+ 0.5 (* a 0.25)) (/ (+ 6.0 (/ -18.0 b)) (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 3.1) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = (6.0 + (-18.0 / b)) / (b * (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.1d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = (6.0d0 + ((-18.0d0) / b)) / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 3.1) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = (6.0 + (-18.0 / b)) / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.1: tmp = 0.5 + (a * 0.25) else: tmp = (6.0 + (-18.0 / b)) / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.1) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(Float64(6.0 + Float64(-18.0 / b)) / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.1) tmp = 0.5 + (a * 0.25); else tmp = (6.0 + (-18.0 / b)) / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.1], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(N[(6.0 + N[(-18.0 / b), $MachinePrecision]), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.1:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{6 + \frac{-18}{b}}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 3.10000000000000009Initial program 98.9%
Taylor expanded in b around 0
Simplified78.4%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6460.7%
Simplified60.7%
if 3.10000000000000009 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6474.7%
Simplified74.7%
Taylor expanded in b around inf
/-lowering-/.f64N/A
sub-negN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6474.7%
Simplified74.7%
(FPCore (a b) :precision binary64 (if (<= b 2.1) (+ 0.5 (* a 0.25)) (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 2.1) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 6.0 / (b * (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.1d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 6.0d0 / (b * (b * b))
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 = 6.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.1: tmp = 0.5 + (a * 0.25) else: tmp = 6.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.1) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); 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 = 6.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.1], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 2.10000000000000009Initial program 98.9%
Taylor expanded in b around 0
Simplified78.4%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6460.7%
Simplified60.7%
if 2.10000000000000009 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6474.7%
Simplified74.7%
Taylor expanded in b around inf
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6474.7%
Simplified74.7%
(FPCore (a b) :precision binary64 (if (<= b 1.7) (+ 0.5 (* a 0.25)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.7) {
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 <= 1.7d0) 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 <= 1.7) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.7: tmp = 0.5 + (a * 0.25) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.7) 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 <= 1.7) tmp = 0.5 + (a * 0.25); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.7], 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 1.7:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.69999999999999996Initial program 98.9%
Taylor expanded in b around 0
Simplified78.4%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6460.7%
Simplified60.7%
if 1.69999999999999996 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6453.6%
Simplified53.6%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6453.6%
Simplified53.6%
(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
Simplified68.9%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6446.5%
Simplified46.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
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6486.0%
Simplified86.0%
Taylor expanded in b around 0
Simplified46.3%
(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 2024170
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))