
(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 12 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.9999999934314354) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.9999999934314354) {
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.9999999934314354d0) 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.9999999934314354) {
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.9999999934314354: 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.9999999934314354) 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.9999999934314354) 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.9999999934314354], 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.9999999934314354:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.99999999343143542Initial program 98.8%
Taylor expanded in b around 0
Simplified100.0%
if 0.99999999343143542 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.1%
Simplified99.1%
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 98.8%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.99999998) (/ (exp a) 2.0) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.99999998) {
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.99999998d0) 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.99999998) {
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.99999998: 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.99999998) 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.99999998) 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.99999998], 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.99999998:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999999980000000011Initial program 98.7%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified96.4%
if 0.999999980000000011 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6498.9%
Simplified98.9%
Final simplification98.1%
(FPCore (a b) :precision binary64 (if (<= b 2.2e+92) (/ (exp a) 2.0) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 2.2e+92) {
tmp = exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.2d+92) then
tmp = exp(a) / 2.0d0
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.2e+92) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.2e+92: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.2e+92) tmp = Float64(exp(a) / 2.0); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.2e+92) tmp = exp(a) / 2.0; else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.2e+92], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 2.19999999999999992e92Initial program 98.6%
Taylor expanded in b around 0
Simplified76.4%
Taylor expanded in a around 0
Simplified74.3%
if 2.19999999999999992e92 < 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-*.f6496.1%
Simplified96.1%
(FPCore (a b)
:precision binary64
(if (<= b 1.65e-122)
(+
0.5
(*
a
(+
0.25
(*
(* a a)
(+ -0.020833333333333332 (* (* a a) 0.0020833333333333333))))))
(if (<= b 1.35e+154)
(/
1.0
(+
2.0
(/ (- (* (* b b) (* 0.25 (* b b))) (* b b)) (- (* b (* b 0.5)) b))))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 1.65e-122) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1.35e+154) {
tmp = 1.0 / (2.0 + ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((b * (b * 0.5)) - b)));
} 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.65d-122) then
tmp = 0.5d0 + (a * (0.25d0 + ((a * a) * ((-0.020833333333333332d0) + ((a * a) * 0.0020833333333333333d0)))))
else if (b <= 1.35d+154) then
tmp = 1.0d0 / (2.0d0 + ((((b * b) * (0.25d0 * (b * b))) - (b * b)) / ((b * (b * 0.5d0)) - b)))
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.65e-122) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1.35e+154) {
tmp = 1.0 / (2.0 + ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((b * (b * 0.5)) - b)));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.65e-122: tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))) elif b <= 1.35e+154: tmp = 1.0 / (2.0 + ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((b * (b * 0.5)) - b))) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.65e-122) tmp = Float64(0.5 + Float64(a * Float64(0.25 + Float64(Float64(a * a) * Float64(-0.020833333333333332 + Float64(Float64(a * a) * 0.0020833333333333333)))))); elseif (b <= 1.35e+154) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(Float64(Float64(b * b) * Float64(0.25 * Float64(b * b))) - Float64(b * b)) / Float64(Float64(b * Float64(b * 0.5)) - b)))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.65e-122) tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))); elseif (b <= 1.35e+154) tmp = 1.0 / (2.0 + ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((b * (b * 0.5)) - b))); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.65e-122], N[(0.5 + N[(a * N[(0.25 + N[(N[(a * a), $MachinePrecision] * N[(-0.020833333333333332 + N[(N[(a * a), $MachinePrecision] * 0.0020833333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(1.0 / N[(2.0 + N[(N[(N[(N[(b * b), $MachinePrecision] * N[(0.25 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-122}:\\
\;\;\;\;0.5 + a \cdot \left(0.25 + \left(a \cdot a\right) \cdot \left(-0.020833333333333332 + \left(a \cdot a\right) \cdot 0.0020833333333333333\right)\right)\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{2 + \frac{\left(b \cdot b\right) \cdot \left(0.25 \cdot \left(b \cdot b\right)\right) - b \cdot b}{b \cdot \left(b \cdot 0.5\right) - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.65e-122Initial program 98.2%
Taylor expanded in b around 0
Simplified75.5%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6452.5%
Simplified52.5%
if 1.65e-122 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6485.1%
Simplified85.1%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6432.6%
Simplified32.6%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-commutativeN/A
*-commutativeN/A
swap-sqrN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-commutativeN/A
swap-sqrN/A
metadata-evalN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
Applied egg-rr64.7%
if 1.35000000000000003e154 < 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-*.f64100.0%
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0%
Simplified100.0%
Final simplification61.1%
(FPCore (a b)
:precision binary64
(if (<= b 2.4e-10)
(+
0.5
(*
a
(+
0.25
(*
(* a a)
(+ -0.020833333333333332 (* (* a a) 0.0020833333333333333))))))
(if (<= b 1.35e+154)
(/ 1.0 (/ (- (* (* b b) (* 0.25 (* b b))) (* b b)) (- (* 0.5 (* b b)) b)))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 2.4e-10) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1.35e+154) {
tmp = 1.0 / ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((0.5 * (b * b)) - b));
} 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.4d-10) then
tmp = 0.5d0 + (a * (0.25d0 + ((a * a) * ((-0.020833333333333332d0) + ((a * a) * 0.0020833333333333333d0)))))
else if (b <= 1.35d+154) then
tmp = 1.0d0 / ((((b * b) * (0.25d0 * (b * b))) - (b * b)) / ((0.5d0 * (b * b)) - b))
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.4e-10) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1.35e+154) {
tmp = 1.0 / ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((0.5 * (b * b)) - b));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.4e-10: tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))) elif b <= 1.35e+154: tmp = 1.0 / ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((0.5 * (b * b)) - b)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.4e-10) tmp = Float64(0.5 + Float64(a * Float64(0.25 + Float64(Float64(a * a) * Float64(-0.020833333333333332 + Float64(Float64(a * a) * 0.0020833333333333333)))))); elseif (b <= 1.35e+154) tmp = Float64(1.0 / Float64(Float64(Float64(Float64(b * b) * Float64(0.25 * Float64(b * b))) - Float64(b * b)) / Float64(Float64(0.5 * Float64(b * b)) - b))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.4e-10) tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))); elseif (b <= 1.35e+154) tmp = 1.0 / ((((b * b) * (0.25 * (b * b))) - (b * b)) / ((0.5 * (b * b)) - b)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.4e-10], N[(0.5 + N[(a * N[(0.25 + N[(N[(a * a), $MachinePrecision] * N[(-0.020833333333333332 + N[(N[(a * a), $MachinePrecision] * 0.0020833333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(1.0 / N[(N[(N[(N[(b * b), $MachinePrecision] * N[(0.25 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{-10}:\\
\;\;\;\;0.5 + a \cdot \left(0.25 + \left(a \cdot a\right) \cdot \left(-0.020833333333333332 + \left(a \cdot a\right) \cdot 0.0020833333333333333\right)\right)\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\frac{\left(b \cdot b\right) \cdot \left(0.25 \cdot \left(b \cdot b\right)\right) - b \cdot b}{0.5 \cdot \left(b \cdot b\right) - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.4e-10Initial program 98.4%
Taylor expanded in b around 0
Simplified78.2%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6454.7%
Simplified54.7%
if 2.4e-10 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6493.8%
Simplified93.8%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f645.7%
Simplified5.7%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
+-commutativeN/A
distribute-rgt-inN/A
lft-mult-inverseN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f645.7%
Simplified5.7%
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-commutativeN/A
*-commutativeN/A
swap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-commutativeN/A
swap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
Applied egg-rr59.5%
if 1.35000000000000003e154 < 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-*.f64100.0%
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0%
Simplified100.0%
Final simplification61.1%
(FPCore (a b)
:precision binary64
(if (<= b 2.4e-10)
(+
0.5
(*
a
(+
0.25
(*
(* a a)
(+ -0.020833333333333332 (* (* a a) 0.0020833333333333333))))))
(if (<= b 1e+103)
(* -0.020833333333333332 (* a (* a a)))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= 2.4e-10) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1e+103) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.4d-10) then
tmp = 0.5d0 + (a * (0.25d0 + ((a * a) * ((-0.020833333333333332d0) + ((a * a) * 0.0020833333333333333d0)))))
else if (b <= 1d+103) then
tmp = (-0.020833333333333332d0) * (a * (a * a))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.4e-10) {
tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333)))));
} else if (b <= 1e+103) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.4e-10: tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))) elif b <= 1e+103: tmp = -0.020833333333333332 * (a * (a * a)) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.4e-10) tmp = Float64(0.5 + Float64(a * Float64(0.25 + Float64(Float64(a * a) * Float64(-0.020833333333333332 + Float64(Float64(a * a) * 0.0020833333333333333)))))); elseif (b <= 1e+103) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.4e-10) tmp = 0.5 + (a * (0.25 + ((a * a) * (-0.020833333333333332 + ((a * a) * 0.0020833333333333333))))); elseif (b <= 1e+103) tmp = -0.020833333333333332 * (a * (a * a)); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.4e-10], N[(0.5 + N[(a * N[(0.25 + N[(N[(a * a), $MachinePrecision] * N[(-0.020833333333333332 + N[(N[(a * a), $MachinePrecision] * 0.0020833333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+103], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{-10}:\\
\;\;\;\;0.5 + a \cdot \left(0.25 + \left(a \cdot a\right) \cdot \left(-0.020833333333333332 + \left(a \cdot a\right) \cdot 0.0020833333333333333\right)\right)\\
\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 2.4e-10Initial program 98.4%
Taylor expanded in b around 0
Simplified78.2%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6454.7%
Simplified54.7%
if 2.4e-10 < b < 1e103Initial program 100.0%
Taylor expanded in b around 0
Simplified51.6%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.5%
Simplified2.5%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6427.5%
Simplified27.5%
if 1e103 < 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-*.f64100.0%
Simplified100.0%
(FPCore (a b)
:precision binary64
(if (<= b 400.0)
(+ 0.5 (* a 0.25))
(if (<= b 1e+103)
(* -0.020833333333333332 (* a (* a a)))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= 400.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1e+103) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 400.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 1d+103) then
tmp = (-0.020833333333333332d0) * (a * (a * a))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 400.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1e+103) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 400.0: tmp = 0.5 + (a * 0.25) elif b <= 1e+103: tmp = -0.020833333333333332 * (a * (a * a)) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 400.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 1e+103) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 400.0) tmp = 0.5 + (a * 0.25); elseif (b <= 1e+103) tmp = -0.020833333333333332 * (a * (a * a)); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 400.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+103], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 400:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 400Initial program 98.4%
Taylor expanded in b around 0
Simplified78.4%
Taylor expanded in a around 0
Simplified53.8%
if 400 < b < 1e103Initial program 100.0%
Taylor expanded in b around 0
Simplified46.2%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.5%
Simplified2.5%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6430.4%
Simplified30.4%
if 1e103 < 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-*.f64100.0%
Simplified100.0%
(FPCore (a b)
:precision binary64
(if (<= b 350.0)
(+ 0.5 (* a 0.25))
(if (<= b 1.35e+154)
(* -0.020833333333333332 (* a (* a a)))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 350.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1.35e+154) {
tmp = -0.020833333333333332 * (a * (a * 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 <= 350.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 1.35d+154) then
tmp = (-0.020833333333333332d0) * (a * (a * 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 <= 350.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1.35e+154) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 350.0: tmp = 0.5 + (a * 0.25) elif b <= 1.35e+154: tmp = -0.020833333333333332 * (a * (a * a)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 350.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 1.35e+154) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 350.0) tmp = 0.5 + (a * 0.25); elseif (b <= 1.35e+154) tmp = -0.020833333333333332 * (a * (a * a)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 350.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 350:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 350Initial program 98.4%
Taylor expanded in b around 0
Simplified78.4%
Taylor expanded in a around 0
Simplified53.8%
if 350 < b < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in b around 0
Simplified39.9%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.6%
Simplified2.6%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6440.0%
Simplified40.0%
if 1.35000000000000003e154 < 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-*.f64100.0%
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= b 2.4e-10) (+ 0.5 (* a 0.25)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 2.4e-10) {
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 <= 2.4d-10) 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 <= 2.4e-10) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.4e-10: tmp = 0.5 + (a * 0.25) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.4e-10) 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 <= 2.4e-10) tmp = 0.5 + (a * 0.25); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.4e-10], 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 2.4 \cdot 10^{-10}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.4e-10Initial program 98.4%
Taylor expanded in b around 0
Simplified78.2%
Taylor expanded in a around 0
Simplified54.3%
if 2.4e-10 < b Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6497.0%
Simplified97.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6454.3%
Simplified54.3%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6454.3%
Simplified54.3%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.8%
Taylor expanded in b around 0
Simplified70.4%
Taylor expanded in a around 0
Simplified41.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 98.8%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6480.3%
Simplified80.3%
Taylor expanded in b around 0
Simplified40.9%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2024191
(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))))