
(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-inverse98.8%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
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 (exp(a) <= 1.0d0) 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 (Math.exp(a) <= 1.0) {
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 math.exp(a) <= 1.0: 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 (exp(a) <= 1.0) 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 (exp(a) <= 1.0) 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[N[Exp[a], $MachinePrecision], 1.0], 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}\;e^{a} \leq 1:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial 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.1%
exp-neg70.1%
rgt-mult-inverse98.8%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.1%
if 1 < (exp.f64 a) Initial program 99.7%
*-lft-identity99.7%
associate-/l*99.7%
remove-double-div99.7%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.7%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 74.8%
Final simplification66.3%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ b (* a (- -1.0 b)))))
(if (<= (exp a) 0.0)
(/ (exp a) b)
(/ 1.0 (/ (- (* t_0 t_0) 4.0) (- t_0 2.0))))))
double code(double a, double b) {
double t_0 = b + (a * (-1.0 - b));
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / b;
} else {
tmp = 1.0 / (((t_0 * t_0) - 4.0) / (t_0 - 2.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = b + (a * ((-1.0d0) - b))
if (exp(a) <= 0.0d0) then
tmp = exp(a) / b
else
tmp = 1.0d0 / (((t_0 * t_0) - 4.0d0) / (t_0 - 2.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b + (a * (-1.0 - b));
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / b;
} else {
tmp = 1.0 / (((t_0 * t_0) - 4.0) / (t_0 - 2.0));
}
return tmp;
}
def code(a, b): t_0 = b + (a * (-1.0 - b)) tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / b else: tmp = 1.0 / (((t_0 * t_0) - 4.0) / (t_0 - 2.0)) return tmp
function code(a, b) t_0 = Float64(b + Float64(a * Float64(-1.0 - b))) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / b); else tmp = Float64(1.0 / Float64(Float64(Float64(t_0 * t_0) - 4.0) / Float64(t_0 - 2.0))); end return tmp end
function tmp_2 = code(a, b) t_0 = b + (a * (-1.0 - b)); tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) / b; else tmp = 1.0 / (((t_0 * t_0) - 4.0) / (t_0 - 2.0)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(1.0 / N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - 4.0), $MachinePrecision] / N[(t$95$0 - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + a \cdot \left(-1 - b\right)\\
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{t_0 \cdot t_0 - 4}{t_0 - 2}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 96.0%
*-lft-identity96.0%
associate-/l*96.0%
remove-double-div96.0%
exp-neg96.0%
associate-/r/96.0%
/-rgt-identity96.0%
*-commutative96.0%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse96.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.0%
distribute-rgt1-in98.7%
rec-exp98.7%
associate-*r/98.7%
+-commutative98.7%
*-rgt-identity98.7%
Simplified98.7%
Taylor expanded in b around inf 98.7%
if 0.0 < (exp.f64 a) Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 48.4%
distribute-rgt1-in48.4%
rec-exp48.4%
associate-*r/48.4%
+-commutative48.4%
*-rgt-identity48.4%
Simplified48.4%
Taylor expanded in a around 0 47.4%
+-commutative47.4%
associate-+l+47.4%
mul-1-neg47.4%
distribute-rgt-neg-in47.4%
neg-sub047.4%
associate--r+47.4%
metadata-eval47.4%
Simplified47.4%
associate-+r+47.4%
flip-+55.7%
metadata-eval55.7%
Applied egg-rr55.7%
Final simplification68.3%
(FPCore (a b) :precision binary64 (if (<= a -6500000.0) (/ (exp a) b) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -6500000.0) {
tmp = exp(a) / b;
} 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 <= (-6500000.0d0)) then
tmp = exp(a) / b
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 <= -6500000.0) {
tmp = Math.exp(a) / b;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -6500000.0: tmp = math.exp(a) / b else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -6500000.0) tmp = Float64(exp(a) / b); 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 <= -6500000.0) tmp = exp(a) / b; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -6500000.0], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -6500000:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -6.5e6Initial program 97.2%
*-lft-identity97.2%
associate-/l*97.2%
remove-double-div97.2%
exp-neg97.2%
associate-/r/97.2%
/-rgt-identity97.2%
*-commutative97.2%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse97.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.0%
distribute-rgt1-in100.0%
rec-exp100.0%
associate-*r/100.0%
+-commutative100.0%
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if -6.5e6 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in97.8%
exp-neg97.8%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.0%
Final simplification98.6%
(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-inverse98.8%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (let* ((t_0 (+ b (* a (- -1.0 b))))) (if (<= b -1550000.0) 0.5 (/ 1.0 (/ (- (* t_0 t_0) 4.0) (- (- 2.0) a))))))
double code(double a, double b) {
double t_0 = b + (a * (-1.0 - b));
double tmp;
if (b <= -1550000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (((t_0 * t_0) - 4.0) / (-2.0 - a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = b + (a * ((-1.0d0) - b))
if (b <= (-1550000.0d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / (((t_0 * t_0) - 4.0d0) / (-2.0d0 - a))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b + (a * (-1.0 - b));
double tmp;
if (b <= -1550000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (((t_0 * t_0) - 4.0) / (-2.0 - a));
}
return tmp;
}
def code(a, b): t_0 = b + (a * (-1.0 - b)) tmp = 0 if b <= -1550000.0: tmp = 0.5 else: tmp = 1.0 / (((t_0 * t_0) - 4.0) / (-2.0 - a)) return tmp
function code(a, b) t_0 = Float64(b + Float64(a * Float64(-1.0 - b))) tmp = 0.0 if (b <= -1550000.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(Float64(Float64(t_0 * t_0) - 4.0) / Float64(Float64(-2.0) - a))); end return tmp end
function tmp_2 = code(a, b) t_0 = b + (a * (-1.0 - b)); tmp = 0.0; if (b <= -1550000.0) tmp = 0.5; else tmp = 1.0 / (((t_0 * t_0) - 4.0) / (-2.0 - a)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1550000.0], 0.5, N[(1.0 / N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - 4.0), $MachinePrecision] / N[((-2.0) - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + a \cdot \left(-1 - b\right)\\
\mathbf{if}\;b \leq -1550000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{t_0 \cdot t_0 - 4}{\left(-2\right) - a}}\\
\end{array}
\end{array}
if b < -1.55e6Initial program 96.6%
*-lft-identity96.6%
associate-/l*96.6%
remove-double-div96.6%
exp-neg96.6%
associate-/r/96.6%
/-rgt-identity96.6%
*-commutative96.6%
distribute-rgt-in96.6%
exp-neg96.6%
rgt-mult-inverse96.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
Taylor expanded in b around 0 18.5%
if -1.55e6 < b Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.5%
remove-double-div99.5%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in62.9%
exp-neg62.9%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
distribute-rgt1-in80.9%
rec-exp80.9%
associate-*r/80.9%
+-commutative80.9%
*-rgt-identity80.9%
Simplified80.9%
Taylor expanded in a around 0 53.2%
+-commutative53.2%
associate-+l+53.2%
mul-1-neg53.2%
distribute-rgt-neg-in53.2%
neg-sub053.2%
associate--r+53.2%
metadata-eval53.2%
Simplified53.2%
associate-+r+53.2%
flip-+68.6%
metadata-eval68.6%
Applied egg-rr68.6%
Taylor expanded in b around 0 77.0%
neg-mul-177.0%
Simplified77.0%
Final simplification63.6%
(FPCore (a b) :precision binary64 (if (<= b -56000.0) 0.5 (/ 1.0 (+ b (+ (* a (- -1.0 b)) 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= -56000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (b + ((a * (-1.0 - b)) + 2.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-56000.0d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / (b + ((a * ((-1.0d0) - b)) + 2.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -56000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (b + ((a * (-1.0 - b)) + 2.0));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -56000.0: tmp = 0.5 else: tmp = 1.0 / (b + ((a * (-1.0 - b)) + 2.0)) return tmp
function code(a, b) tmp = 0.0 if (b <= -56000.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(b + Float64(Float64(a * Float64(-1.0 - b)) + 2.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -56000.0) tmp = 0.5; else tmp = 1.0 / (b + ((a * (-1.0 - b)) + 2.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -56000.0], 0.5, N[(1.0 / N[(b + N[(N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -56000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + \left(a \cdot \left(-1 - b\right) + 2\right)}\\
\end{array}
\end{array}
if b < -56000Initial program 96.6%
*-lft-identity96.6%
associate-/l*96.6%
remove-double-div96.6%
exp-neg96.6%
associate-/r/96.6%
/-rgt-identity96.6%
*-commutative96.6%
distribute-rgt-in96.6%
exp-neg96.6%
rgt-mult-inverse96.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
Taylor expanded in b around 0 18.5%
if -56000 < b Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.5%
remove-double-div99.5%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in62.9%
exp-neg62.9%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
distribute-rgt1-in80.9%
rec-exp80.9%
associate-*r/80.9%
+-commutative80.9%
*-rgt-identity80.9%
Simplified80.9%
Taylor expanded in a around 0 53.2%
+-commutative53.2%
associate-+l+53.2%
mul-1-neg53.2%
distribute-rgt-neg-in53.2%
neg-sub053.2%
associate--r+53.2%
metadata-eval53.2%
Simplified53.2%
Final simplification45.2%
(FPCore (a b) :precision binary64 (if (<= b -56000.0) 0.5 (/ 1.0 (+ 1.0 (* (- 1.0 a) (+ b 1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -56000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (1.0 + ((1.0 - a) * (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 (b <= (-56000.0d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / (1.0d0 + ((1.0d0 - a) * (b + 1.0d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -56000.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -56000.0: tmp = 0.5 else: tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0))) return tmp
function code(a, b) tmp = 0.0 if (b <= -56000.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(1.0 + Float64(Float64(1.0 - a) * Float64(b + 1.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -56000.0) tmp = 0.5; else tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -56000.0], 0.5, N[(1.0 / N[(1.0 + N[(N[(1.0 - a), $MachinePrecision] * N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -56000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 - a\right) \cdot \left(b + 1\right)}\\
\end{array}
\end{array}
if b < -56000Initial program 96.6%
*-lft-identity96.6%
associate-/l*96.6%
remove-double-div96.6%
exp-neg96.6%
associate-/r/96.6%
/-rgt-identity96.6%
*-commutative96.6%
distribute-rgt-in96.6%
exp-neg96.6%
rgt-mult-inverse96.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
Taylor expanded in b around 0 18.5%
if -56000 < b Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.5%
remove-double-div99.5%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in62.9%
exp-neg62.9%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
distribute-rgt1-in80.9%
rec-exp80.9%
associate-*r/80.9%
+-commutative80.9%
*-rgt-identity80.9%
Simplified80.9%
Taylor expanded in a around 0 53.2%
associate-+r+53.2%
associate-*r*53.2%
distribute-rgt1-in53.2%
neg-mul-153.2%
Simplified53.2%
Final simplification45.2%
(FPCore (a b) :precision binary64 (if (<= a -2.0) (/ 1.0 (* a (- -1.0 b))) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -2.0) {
tmp = 1.0 / (a * (-1.0 - 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 <= (-2.0d0)) then
tmp = 1.0d0 / (a * ((-1.0d0) - 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 <= -2.0) {
tmp = 1.0 / (a * (-1.0 - b));
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.0: tmp = 1.0 / (a * (-1.0 - b)) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.0) tmp = Float64(1.0 / Float64(a * Float64(-1.0 - 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 <= -2.0) tmp = 1.0 / (a * (-1.0 - b)); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.0], N[(1.0 / N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2:\\
\;\;\;\;\frac{1}{a \cdot \left(-1 - b\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -2Initial program 96.1%
*-lft-identity96.1%
associate-/l*96.1%
remove-double-div96.1%
exp-neg96.1%
associate-/r/96.1%
/-rgt-identity96.1%
*-commutative96.1%
distribute-rgt-in2.6%
exp-neg2.6%
rgt-mult-inverse96.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 67.6%
distribute-rgt1-in97.5%
rec-exp97.5%
associate-*r/97.5%
+-commutative97.5%
*-rgt-identity97.5%
Simplified97.5%
Taylor expanded in a around 0 26.7%
+-commutative26.7%
associate-+l+26.7%
mul-1-neg26.7%
distribute-rgt-neg-in26.7%
neg-sub026.7%
associate--r+26.7%
metadata-eval26.7%
Simplified26.7%
Taylor expanded in a around inf 26.7%
+-commutative26.7%
distribute-lft-in26.7%
*-rgt-identity26.7%
distribute-lft-out26.7%
mul-1-neg26.7%
distribute-rgt-neg-out26.7%
*-commutative26.7%
+-commutative26.7%
distribute-lft-out26.7%
sub-neg26.7%
Simplified26.7%
if -2 < a 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 52.7%
Taylor expanded in a around 0 52.3%
*-commutative52.3%
Simplified52.3%
Final simplification44.6%
(FPCore (a b) :precision binary64 (if (<= b 2.0) (/ 1.0 (- 2.0 a)) (/ 1.0 (* b (- 1.0 a)))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (b * (1.0 - a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.0d0) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 1.0d0 / (b * (1.0d0 - a))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (b * (1.0 - a));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 1.0 / (2.0 - a) else: tmp = 1.0 / (b * (1.0 - a)) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(1.0 / Float64(b * Float64(1.0 - a))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.0) tmp = 1.0 / (2.0 - a); else tmp = 1.0 / (b * (1.0 - a)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b \cdot \left(1 - a\right)}\\
\end{array}
\end{array}
if b < 2Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.3%
remove-double-div98.3%
exp-neg98.3%
associate-/r/98.3%
/-rgt-identity98.3%
*-commutative98.3%
distribute-rgt-in76.7%
exp-neg76.7%
rgt-mult-inverse98.3%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 73.6%
Taylor expanded in a around 0 51.3%
neg-mul-151.3%
unsub-neg51.3%
Simplified51.3%
if 2 < 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-in54.9%
exp-neg54.9%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 47.9%
distribute-rgt1-in47.9%
rec-exp47.9%
associate-*r/47.9%
+-commutative47.9%
*-rgt-identity47.9%
Simplified47.9%
Taylor expanded in a around 0 28.1%
+-commutative28.1%
associate-+l+28.1%
mul-1-neg28.1%
distribute-rgt-neg-in28.1%
neg-sub028.1%
associate--r+28.1%
metadata-eval28.1%
Simplified28.1%
Taylor expanded in b around inf 28.1%
mul-1-neg28.1%
unsub-neg28.1%
Simplified28.1%
Final simplification44.8%
(FPCore (a b) :precision binary64 (if (<= a -9.2) (/ -1.0 (* b a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -9.2) {
tmp = -1.0 / (b * 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 <= (-9.2d0)) then
tmp = (-1.0d0) / (b * 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 <= -9.2) {
tmp = -1.0 / (b * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9.2: tmp = -1.0 / (b * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -9.2) tmp = Float64(-1.0 / Float64(b * 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 <= -9.2) tmp = -1.0 / (b * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9.2], N[(-1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.2:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -9.1999999999999993Initial program 96.1%
*-lft-identity96.1%
associate-/l*96.1%
remove-double-div96.1%
exp-neg96.1%
associate-/r/96.1%
/-rgt-identity96.1%
*-commutative96.1%
distribute-rgt-in1.3%
exp-neg1.3%
rgt-mult-inverse96.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 67.2%
distribute-rgt1-in97.5%
rec-exp97.5%
associate-*r/97.5%
+-commutative97.5%
*-rgt-identity97.5%
Simplified97.5%
Taylor expanded in a around 0 26.9%
+-commutative26.9%
associate-+l+26.9%
mul-1-neg26.9%
distribute-rgt-neg-in26.9%
neg-sub026.9%
associate--r+26.9%
metadata-eval26.9%
Simplified26.9%
Taylor expanded in b around inf 25.7%
mul-1-neg25.7%
unsub-neg25.7%
Simplified25.7%
Taylor expanded in a around inf 25.7%
if -9.1999999999999993 < a Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 53.0%
Taylor expanded in a around 0 52.0%
*-commutative52.0%
Simplified52.0%
Final simplification44.2%
(FPCore (a b) :precision binary64 (if (<= b 7.5e+30) (/ 1.0 (- 2.0 a)) (/ -1.0 (* b a))))
double code(double a, double b) {
double tmp;
if (b <= 7.5e+30) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -1.0 / (b * a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 7.5d+30) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = (-1.0d0) / (b * a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7.5e+30) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -1.0 / (b * a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7.5e+30: tmp = 1.0 / (2.0 - a) else: tmp = -1.0 / (b * a) return tmp
function code(a, b) tmp = 0.0 if (b <= 7.5e+30) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(-1.0 / Float64(b * a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7.5e+30) tmp = 1.0 / (2.0 - a); else tmp = -1.0 / (b * a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7.5e+30], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\end{array}
\end{array}
if b < 7.49999999999999973e30Initial 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-in76.6%
exp-neg76.7%
rgt-mult-inverse98.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 71.7%
Taylor expanded in a around 0 49.3%
neg-mul-149.3%
unsub-neg49.3%
Simplified49.3%
if 7.49999999999999973e30 < 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-in52.4%
exp-neg52.4%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 50.5%
distribute-rgt1-in50.5%
rec-exp50.5%
associate-*r/50.5%
+-commutative50.5%
*-rgt-identity50.5%
Simplified50.5%
Taylor expanded in a around 0 31.2%
+-commutative31.2%
associate-+l+31.2%
mul-1-neg31.2%
distribute-rgt-neg-in31.2%
neg-sub031.2%
associate--r+31.2%
metadata-eval31.2%
Simplified31.2%
Taylor expanded in b around inf 31.2%
mul-1-neg31.2%
unsub-neg31.2%
Simplified31.2%
Taylor expanded in a around inf 30.0%
Final simplification44.5%
(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-inverse98.8%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.2%
Taylor expanded in a around 0 37.2%
*-commutative37.2%
Simplified37.2%
Final simplification37.2%
(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-inverse98.8%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 82.7%
Taylor expanded in b around 0 37.2%
Final simplification37.2%
(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 2023311
(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))))