
(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 (exp (- (log1p (exp (- b a))))))
double code(double a, double b) {
return exp(-log1p(exp((b - a))));
}
public static double code(double a, double b) {
return Math.exp(-Math.log1p(Math.exp((b - a))));
}
def code(a, b): return math.exp(-math.log1p(math.exp((b - a))))
function code(a, b) return exp(Float64(-log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[(-N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{b - a}\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
inv-pow100.0%
pow-to-exp100.0%
*-commutative100.0%
log1p-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -9e-6) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -9e-6) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-9d-6)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -9e-6) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9e-6: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -9e-6) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -9e-6) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9e-6], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -9.00000000000000023e-6Initial program 98.7%
*-lft-identity98.7%
associate-/l*98.7%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.7%
/-rgt-identity98.7%
*-commutative98.7%
distribute-rgt-in6.4%
exp-neg6.4%
rgt-mult-inverse98.7%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 98.1%
if -9.00000000000000023e-6 < a Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.2%
Final simplification98.9%
(FPCore (a b) :precision binary64 (if (<= a -2400000.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -2400000.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2400000.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2400000.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2400000.0: tmp = math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -2400000.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2400000.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2400000.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2400000:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -2.4e6Initial program 98.6%
Taylor expanded in b around 0 98.7%
Taylor expanded in a around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in a around inf 98.7%
if -2.4e6 < a Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.3%
exp-neg98.3%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.4%
Final simplification97.8%
(FPCore (a b) :precision binary64 (if (<= a -0.000125) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -0.000125) {
tmp = exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-0.000125d0)) then
tmp = exp(a) / (a + 2.0d0)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -0.000125) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.000125: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.000125) tmp = Float64(exp(a) / Float64(a + 2.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -0.000125) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.000125], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.000125:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -1.25e-4Initial program 98.7%
Taylor expanded in b around 0 98.1%
Taylor expanded in a around 0 95.1%
+-commutative95.1%
Simplified95.1%
if -1.25e-4 < a Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.2%
Final simplification98.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.0 / (exp((b - a)) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 1}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -700.0) (/ (exp a) a) (* (/ 1.0 (- 4.0 (* b b))) (- 2.0 b))))
double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = exp(a) / a;
} else {
tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-700.0d0)) then
tmp = exp(a) / a
else
tmp = (1.0d0 / (4.0d0 - (b * b))) * (2.0d0 - b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = Math.exp(a) / a;
} else {
tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -700.0: tmp = math.exp(a) / a else: tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b) return tmp
function code(a, b) tmp = 0.0 if (a <= -700.0) tmp = Float64(exp(a) / a); else tmp = Float64(Float64(1.0 / Float64(4.0 - Float64(b * b))) * Float64(2.0 - b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -700.0) tmp = exp(a) / a; else tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -700.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(N[(1.0 / N[(4.0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(2.0 - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -700:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{4 - b \cdot b} \cdot \left(2 - b\right)\\
\end{array}
\end{array}
if a < -700Initial program 98.6%
Taylor expanded in b around 0 98.7%
Taylor expanded in a around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in a around inf 98.7%
if -700 < a Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.4%
Taylor expanded in b around 0 49.9%
+-commutative49.9%
Simplified49.9%
+-commutative49.9%
flip-+58.0%
associate-/r/58.0%
metadata-eval58.0%
Applied egg-rr58.0%
Final simplification69.6%
(FPCore (a b)
:precision binary64
(let* ((t_0 (- 4.0 (* b b))))
(if (<= b 1.7e+91)
(/ 1.0 (+ (- 2.0 a) (* 0.5 (* a a))))
(if (<= b 1.35e+154)
(/ t_0 (* t_0 (+ b 2.0)))
(* (- 2.0 b) (/ -1.0 (* b b)))))))
double code(double a, double b) {
double t_0 = 4.0 - (b * b);
double tmp;
if (b <= 1.7e+91) {
tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a)));
} else if (b <= 1.35e+154) {
tmp = t_0 / (t_0 * (b + 2.0));
} else {
tmp = (2.0 - b) * (-1.0 / (b * b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = 4.0d0 - (b * b)
if (b <= 1.7d+91) then
tmp = 1.0d0 / ((2.0d0 - a) + (0.5d0 * (a * a)))
else if (b <= 1.35d+154) then
tmp = t_0 / (t_0 * (b + 2.0d0))
else
tmp = (2.0d0 - b) * ((-1.0d0) / (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 4.0 - (b * b);
double tmp;
if (b <= 1.7e+91) {
tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a)));
} else if (b <= 1.35e+154) {
tmp = t_0 / (t_0 * (b + 2.0));
} else {
tmp = (2.0 - b) * (-1.0 / (b * b));
}
return tmp;
}
def code(a, b): t_0 = 4.0 - (b * b) tmp = 0 if b <= 1.7e+91: tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a))) elif b <= 1.35e+154: tmp = t_0 / (t_0 * (b + 2.0)) else: tmp = (2.0 - b) * (-1.0 / (b * b)) return tmp
function code(a, b) t_0 = Float64(4.0 - Float64(b * b)) tmp = 0.0 if (b <= 1.7e+91) tmp = Float64(1.0 / Float64(Float64(2.0 - a) + Float64(0.5 * Float64(a * a)))); elseif (b <= 1.35e+154) tmp = Float64(t_0 / Float64(t_0 * Float64(b + 2.0))); else tmp = Float64(Float64(2.0 - b) * Float64(-1.0 / Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) t_0 = 4.0 - (b * b); tmp = 0.0; if (b <= 1.7e+91) tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a))); elseif (b <= 1.35e+154) tmp = t_0 / (t_0 * (b + 2.0)); else tmp = (2.0 - b) * (-1.0 / (b * b)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(4.0 - N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.7e+91], N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(0.5 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(t$95$0 / N[(t$95$0 * N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 - b), $MachinePrecision] * N[(-1.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 - b \cdot b\\
\mathbf{if}\;b \leq 1.7 \cdot 10^{+91}:\\
\;\;\;\;\frac{1}{\left(2 - a\right) + 0.5 \cdot \left(a \cdot a\right)}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{t_0}{t_0 \cdot \left(b + 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 - b\right) \cdot \frac{-1}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.7e91Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 73.9%
Taylor expanded in a around 0 58.6%
associate-+r+58.6%
mul-1-neg58.6%
unsub-neg58.6%
unpow258.6%
Simplified58.6%
if 1.7e91 < b < 1.35000000000000003e154Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in92.9%
exp-neg92.9%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 4.2%
+-commutative4.2%
Simplified4.2%
+-commutative4.2%
flip-+4.2%
associate-/r/4.2%
metadata-eval4.2%
Applied egg-rr4.2%
flip--4.2%
metadata-eval4.2%
frac-times79.4%
*-lft-identity79.4%
Applied egg-rr79.4%
if 1.35000000000000003e154 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in59.3%
exp-neg59.3%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 7.2%
+-commutative7.2%
Simplified7.2%
+-commutative7.2%
flip-+100.0%
associate-/r/100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in b around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification64.1%
(FPCore (a b) :precision binary64 (if (<= a -1.5e+139) (/ 2.0 (* a a)) (if (<= a -3e+16) (* (- 2.0 b) (/ -1.0 (* b b))) (+ 0.5 (* a 0.25)))))
double code(double a, double b) {
double tmp;
if (a <= -1.5e+139) {
tmp = 2.0 / (a * a);
} else if (a <= -3e+16) {
tmp = (2.0 - b) * (-1.0 / (b * b));
} 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 (a <= (-1.5d+139)) then
tmp = 2.0d0 / (a * a)
else if (a <= (-3d+16)) then
tmp = (2.0d0 - b) * ((-1.0d0) / (b * b))
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.5e+139) {
tmp = 2.0 / (a * a);
} else if (a <= -3e+16) {
tmp = (2.0 - b) * (-1.0 / (b * b));
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.5e+139: tmp = 2.0 / (a * a) elif a <= -3e+16: tmp = (2.0 - b) * (-1.0 / (b * b)) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.5e+139) tmp = Float64(2.0 / Float64(a * a)); elseif (a <= -3e+16) tmp = Float64(Float64(2.0 - b) * Float64(-1.0 / Float64(b * b))); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.5e+139) tmp = 2.0 / (a * a); elseif (a <= -3e+16) tmp = (2.0 - b) * (-1.0 / (b * b)); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.5e+139], N[(2.0 / N[(a * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, -3e+16], N[(N[(2.0 - b), $MachinePrecision] * N[(-1.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.5 \cdot 10^{+139}:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{elif}\;a \leq -3 \cdot 10^{+16}:\\
\;\;\;\;\left(2 - b\right) \cdot \frac{-1}{b \cdot b}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -1.5e139Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 94.8%
associate-+r+94.8%
mul-1-neg94.8%
unsub-neg94.8%
unpow294.8%
Simplified94.8%
Taylor expanded in a around inf 94.8%
unpow294.8%
Simplified94.8%
if -1.5e139 < a < -3e16Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 45.1%
Taylor expanded in b around 0 4.1%
+-commutative4.1%
Simplified4.1%
+-commutative4.1%
flip-+25.8%
associate-/r/25.8%
metadata-eval25.8%
Applied egg-rr25.8%
Taylor expanded in b around inf 25.2%
unpow225.2%
Simplified25.2%
if -3e16 < a Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in94.7%
exp-neg94.7%
rgt-mult-inverse98.9%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 55.9%
Taylor expanded in a around 0 51.0%
*-commutative51.0%
Simplified51.0%
Final simplification54.0%
(FPCore (a b) :precision binary64 (if (<= a -1.45e+139) (/ 2.0 (* a a)) (* (/ 1.0 (- 4.0 (* b b))) (- 2.0 b))))
double code(double a, double b) {
double tmp;
if (a <= -1.45e+139) {
tmp = 2.0 / (a * a);
} else {
tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.45d+139)) then
tmp = 2.0d0 / (a * a)
else
tmp = (1.0d0 / (4.0d0 - (b * b))) * (2.0d0 - b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.45e+139) {
tmp = 2.0 / (a * a);
} else {
tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.45e+139: tmp = 2.0 / (a * a) else: tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.45e+139) tmp = Float64(2.0 / Float64(a * a)); else tmp = Float64(Float64(1.0 / Float64(4.0 - Float64(b * b))) * Float64(2.0 - b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.45e+139) tmp = 2.0 / (a * a); else tmp = (1.0 / (4.0 - (b * b))) * (2.0 - b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.45e+139], N[(2.0 / N[(a * a), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(4.0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(2.0 - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45 \cdot 10^{+139}:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{4 - b \cdot b} \cdot \left(2 - b\right)\\
\end{array}
\end{array}
if a < -1.4499999999999999e139Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 94.8%
associate-+r+94.8%
mul-1-neg94.8%
unsub-neg94.8%
unpow294.8%
Simplified94.8%
Taylor expanded in a around inf 94.8%
unpow294.8%
Simplified94.8%
if -1.4499999999999999e139 < a Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in81.9%
exp-neg81.9%
rgt-mult-inverse99.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 87.8%
Taylor expanded in b around 0 42.0%
+-commutative42.0%
Simplified42.0%
+-commutative42.0%
flip-+51.7%
associate-/r/51.7%
metadata-eval51.7%
Applied egg-rr51.7%
Final simplification57.6%
(FPCore (a b) :precision binary64 (if (<= b 1.85e+144) (/ 1.0 (+ (- 2.0 a) (* 0.5 (* a a)))) (* (- 2.0 b) (/ -1.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 1.85e+144) {
tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a)));
} else {
tmp = (2.0 - b) * (-1.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.85d+144) then
tmp = 1.0d0 / ((2.0d0 - a) + (0.5d0 * (a * a)))
else
tmp = (2.0d0 - b) * ((-1.0d0) / (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.85e+144) {
tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a)));
} else {
tmp = (2.0 - b) * (-1.0 / (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.85e+144: tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a))) else: tmp = (2.0 - b) * (-1.0 / (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.85e+144) tmp = Float64(1.0 / Float64(Float64(2.0 - a) + Float64(0.5 * Float64(a * a)))); else tmp = Float64(Float64(2.0 - b) * Float64(-1.0 / Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.85e+144) tmp = 1.0 / ((2.0 - a) + (0.5 * (a * a))); else tmp = (2.0 - b) * (-1.0 / (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.85e+144], N[(1.0 / N[(N[(2.0 - a), $MachinePrecision] + N[(0.5 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 - b), $MachinePrecision] * N[(-1.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.85 \cdot 10^{+144}:\\
\;\;\;\;\frac{1}{\left(2 - a\right) + 0.5 \cdot \left(a \cdot a\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 - b\right) \cdot \frac{-1}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.8499999999999998e144Initial program 98.7%
*-lft-identity98.7%
associate-/l*98.7%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.7%
/-rgt-identity98.7%
*-commutative98.7%
distribute-rgt-in71.8%
exp-neg71.8%
rgt-mult-inverse99.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 70.6%
Taylor expanded in a around 0 56.1%
associate-+r+56.1%
mul-1-neg56.1%
unsub-neg56.1%
unpow256.1%
Simplified56.1%
if 1.8499999999999998e144 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in62.1%
exp-neg62.1%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 7.1%
+-commutative7.1%
Simplified7.1%
+-commutative7.1%
flip-+93.4%
associate-/r/93.4%
metadata-eval93.4%
Applied egg-rr93.4%
Taylor expanded in b around inf 93.4%
unpow293.4%
Simplified93.4%
Final simplification60.3%
(FPCore (a b) :precision binary64 (if (<= a -1.7) (/ 2.0 (* a a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -1.7) {
tmp = 2.0 / (a * a);
} 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 (a <= (-1.7d0)) then
tmp = 2.0d0 / (a * a)
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.7) {
tmp = 2.0 / (a * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.7: tmp = 2.0 / (a * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.7) tmp = Float64(2.0 / Float64(a * a)); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.7) tmp = 2.0 / (a * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.7], N[(2.0 / N[(a * a), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.7:\\
\;\;\;\;\frac{2}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -1.69999999999999996Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in1.3%
exp-neg1.3%
rgt-mult-inverse98.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 98.7%
Taylor expanded in a around 0 47.7%
associate-+r+47.7%
mul-1-neg47.7%
unsub-neg47.7%
unpow247.7%
Simplified47.7%
Taylor expanded in a around inf 47.6%
unpow247.6%
Simplified47.6%
if -1.69999999999999996 < a Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 54.3%
Taylor expanded in a around 0 53.4%
*-commutative53.4%
Simplified53.4%
Final simplification51.7%
(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%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 67.1%
Taylor expanded in a around 0 38.6%
*-commutative38.6%
Simplified38.6%
Final simplification38.6%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 67.1%
Taylor expanded in a around 0 39.3%
mul-1-neg39.3%
unsub-neg39.3%
Simplified39.3%
Final simplification39.3%
(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%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in70.7%
exp-neg70.7%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 80.0%
Taylor expanded in b around 0 38.3%
Final simplification38.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 2023297
(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))))