
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ 1.0 (exp a))) (log1p (+ (exp a) (* b (+ 1.0 (* b 0.5)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p((exp(a) + (b * (1.0 + (b * 0.5)))));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p((Math.exp(a) + (b * (1.0 + (b * 0.5)))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p((math.exp(a) + (b * (1.0 + (b * 0.5))))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(Float64(exp(a) + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + b \cdot \left(1 + b \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 7.1%
Taylor expanded in b around 0 6.5%
associate-+r+6.5%
*-commutative6.5%
Simplified6.5%
Taylor expanded in b around 0 100.0%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 65.1%
log1p-expm1-u65.1%
expm1-undefine65.1%
add-exp-log65.1%
Applied egg-rr65.1%
Taylor expanded in b around 0 63.4%
Final simplification73.4%
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ 1.0 (exp a))) (t_1 (/ -1.0 (pow t_0 2.0))) (t_2 (/ 1.0 t_0)))
(+
(log t_0)
(*
b
(+
t_2
(*
b
(+
(*
0.16666666666666666
(* b (+ (+ (* 2.0 (/ 1.0 (pow t_0 3.0))) t_2) (* 3.0 t_1))))
(* 0.5 (+ t_2 t_1)))))))))assert(a < b);
double code(double a, double b) {
double t_0 = 1.0 + exp(a);
double t_1 = -1.0 / pow(t_0, 2.0);
double t_2 = 1.0 / t_0;
return log(t_0) + (b * (t_2 + (b * ((0.16666666666666666 * (b * (((2.0 * (1.0 / pow(t_0, 3.0))) + t_2) + (3.0 * t_1)))) + (0.5 * (t_2 + t_1))))));
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = 1.0d0 + exp(a)
t_1 = (-1.0d0) / (t_0 ** 2.0d0)
t_2 = 1.0d0 / t_0
code = log(t_0) + (b * (t_2 + (b * ((0.16666666666666666d0 * (b * (((2.0d0 * (1.0d0 / (t_0 ** 3.0d0))) + t_2) + (3.0d0 * t_1)))) + (0.5d0 * (t_2 + t_1))))))
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = 1.0 + Math.exp(a);
double t_1 = -1.0 / Math.pow(t_0, 2.0);
double t_2 = 1.0 / t_0;
return Math.log(t_0) + (b * (t_2 + (b * ((0.16666666666666666 * (b * (((2.0 * (1.0 / Math.pow(t_0, 3.0))) + t_2) + (3.0 * t_1)))) + (0.5 * (t_2 + t_1))))));
}
[a, b] = sort([a, b]) def code(a, b): t_0 = 1.0 + math.exp(a) t_1 = -1.0 / math.pow(t_0, 2.0) t_2 = 1.0 / t_0 return math.log(t_0) + (b * (t_2 + (b * ((0.16666666666666666 * (b * (((2.0 * (1.0 / math.pow(t_0, 3.0))) + t_2) + (3.0 * t_1)))) + (0.5 * (t_2 + t_1))))))
a, b = sort([a, b]) function code(a, b) t_0 = Float64(1.0 + exp(a)) t_1 = Float64(-1.0 / (t_0 ^ 2.0)) t_2 = Float64(1.0 / t_0) return Float64(log(t_0) + Float64(b * Float64(t_2 + Float64(b * Float64(Float64(0.16666666666666666 * Float64(b * Float64(Float64(Float64(2.0 * Float64(1.0 / (t_0 ^ 3.0))) + t_2) + Float64(3.0 * t_1)))) + Float64(0.5 * Float64(t_2 + t_1))))))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
t_0 = 1.0 + exp(a);
t_1 = -1.0 / (t_0 ^ 2.0);
t_2 = 1.0 / t_0;
tmp = log(t_0) + (b * (t_2 + (b * ((0.16666666666666666 * (b * (((2.0 * (1.0 / (t_0 ^ 3.0))) + t_2) + (3.0 * t_1)))) + (0.5 * (t_2 + t_1))))));
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-1.0 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / t$95$0), $MachinePrecision]}, N[(N[Log[t$95$0], $MachinePrecision] + N[(b * N[(t$95$2 + N[(b * N[(N[(0.16666666666666666 * N[(b * N[(N[(N[(2.0 * N[(1.0 / N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + N[(3.0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(t$95$2 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 1 + e^{a}\\
t_1 := \frac{-1}{{t\_0}^{2}}\\
t_2 := \frac{1}{t\_0}\\
\log t\_0 + b \cdot \left(t\_2 + b \cdot \left(0.16666666666666666 \cdot \left(b \cdot \left(\left(2 \cdot \frac{1}{{t\_0}^{3}} + t\_2\right) + 3 \cdot t\_1\right)\right) + 0.5 \cdot \left(t\_2 + t\_1\right)\right)\right)
\end{array}
\end{array}
Initial program 49.2%
Taylor expanded in b around 0 73.2%
Final simplification73.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ 1.0 (exp a))) (log1p (+ (exp a) b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p((exp(a) + b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p((Math.exp(a) + b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p((math.exp(a) + b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(Float64(exp(a) + b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(N[Exp[a], $MachinePrecision] + b), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + b\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 7.1%
Taylor expanded in b around 0 6.5%
associate-+r+6.5%
*-commutative6.5%
Simplified6.5%
Taylor expanded in b around 0 100.0%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 65.1%
log1p-expm1-u65.1%
expm1-undefine65.1%
add-exp-log65.1%
Applied egg-rr65.1%
Taylor expanded in b around 0 62.3%
Final simplification72.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (log1p (exp a)) (/ b (+ 1.0 (exp a)))))
assert(a < b);
double code(double a, double b) {
return log1p(exp(a)) + (b / (1.0 + exp(a)));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p(Math.exp(a)) + (b / (1.0 + Math.exp(a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p(math.exp(a)) + (b / (1.0 + math.exp(a)))
a, b = sort([a, b]) function code(a, b) return Float64(log1p(exp(a)) + Float64(b / Float64(1.0 + exp(a)))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a}\right) + \frac{b}{1 + e^{a}}
\end{array}
Initial program 49.2%
Taylor expanded in b around 0 73.2%
log1p-define73.2%
Simplified73.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (+ (exp a) (expm1 b))))
assert(a < b);
double code(double a, double b) {
return log1p((exp(a) + expm1(b)));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p((Math.exp(a) + Math.expm1(b)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p((math.exp(a) + math.expm1(b)))
a, b = sort([a, b]) function code(a, b) return log1p(Float64(exp(a) + expm1(b))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
\end{array}
Initial program 49.2%
log1p-expm1-u49.2%
expm1-undefine49.2%
add-exp-log49.2%
Applied egg-rr49.2%
associate--l+49.3%
expm1-define74.4%
Applied egg-rr74.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.004) (/ b (+ 1.0 (exp a))) (log (+ (* b (+ 1.0 (* b 0.5))) (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.004) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log(((b * (1.0 + (b * 0.5))) + (a + 2.0)));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.004d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log(((b * (1.0d0 + (b * 0.5d0))) + (a + 2.0d0)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.004) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log(((b * (1.0 + (b * 0.5))) + (a + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.004: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log(((b * (1.0 + (b * 0.5))) + (a + 2.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.004) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log(Float64(Float64(b * Float64(1.0 + Float64(b * 0.5))) + Float64(a + 2.0))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 0.004)
tmp = b / (1.0 + exp(a));
else
tmp = log(((b * (1.0 + (b * 0.5))) + (a + 2.0)));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.004], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.004:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b \cdot \left(1 + b \cdot 0.5\right) + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0040000000000000001Initial program 8.2%
Taylor expanded in b around 0 7.6%
associate-+r+7.6%
*-commutative7.6%
Simplified7.6%
Taylor expanded in b around 0 99.9%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 98.6%
if 0.0040000000000000001 < (exp.f64 a) Initial program 65.0%
Taylor expanded in b around 0 63.2%
associate-+r+63.2%
*-commutative63.2%
Simplified63.2%
Taylor expanded in a around 0 63.1%
+-commutative63.1%
Simplified63.1%
Final simplification73.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 3.9e-32) (/ b (+ 1.0 (exp a))) (+ (log 2.0) (* b (+ 0.5 (* b 0.125))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 3.9e-32) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log(2.0) + (b * (0.5 + (b * 0.125)));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 3.9d-32) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log(2.0d0) + (b * (0.5d0 + (b * 0.125d0)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 3.9e-32) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log(2.0) + (b * (0.5 + (b * 0.125)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 3.9e-32: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log(2.0) + (b * (0.5 + (b * 0.125))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 3.9e-32) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(2.0) + Float64(b * Float64(0.5 + Float64(b * 0.125)))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 3.9e-32)
tmp = b / (1.0 + exp(a));
else
tmp = log(2.0) + (b * (0.5 + (b * 0.125)));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 3.9e-32], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(b * N[(0.5 + N[(b * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 3.9 \cdot 10^{-32}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + b \cdot \left(0.5 + b \cdot 0.125\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 3.9000000000000001e-32Initial program 7.1%
Taylor expanded in b around 0 6.5%
associate-+r+6.5%
*-commutative6.5%
Simplified6.5%
Taylor expanded in b around 0 100.0%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 3.9000000000000001e-32 < (exp.f64 a) Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 61.7%
Final simplification72.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2.1e-30) (/ b (+ 1.0 (exp a))) (log (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2.1e-30) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((2.0 + (b * (1.0 + (b * 0.5)))));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 2.1d-30) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((2.0d0 + (b * (1.0d0 + (b * 0.5d0)))))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 2.1e-30) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log((2.0 + (b * (1.0 + (b * 0.5)))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 2.1e-30: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((2.0 + (b * (1.0 + (b * 0.5))))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2.1e-30) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log(Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 2.1e-30)
tmp = b / (1.0 + exp(a));
else
tmp = log((2.0 + (b * (1.0 + (b * 0.5)))));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 2.1e-30], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2.1 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(2 + b \cdot \left(1 + b \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.1000000000000002e-30Initial program 7.1%
Taylor expanded in b around 0 6.5%
associate-+r+6.5%
*-commutative6.5%
Simplified6.5%
Taylor expanded in b around 0 100.0%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 2.1000000000000002e-30 < (exp.f64 a) Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 62.0%
Final simplification72.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (+ (exp a) (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))
assert(a < b);
double code(double a, double b) {
return log1p((exp(a) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p((Math.exp(a) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p((math.exp(a) + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))))
a, b = sort([a, b]) function code(a, b) return log1p(Float64(exp(a) + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a} + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)\right)
\end{array}
Initial program 49.2%
log1p-expm1-u49.2%
expm1-undefine49.2%
add-exp-log49.2%
Applied egg-rr49.2%
Taylor expanded in b around 0 72.2%
*-commutative72.2%
Simplified72.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 3.3e-43) (/ b (+ 1.0 (exp a))) (+ (* b 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 3.3e-43) {
tmp = b / (1.0 + exp(a));
} else {
tmp = (b * 0.5) + log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 3.3d-43) then
tmp = b / (1.0d0 + exp(a))
else
tmp = (b * 0.5d0) + log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 3.3e-43) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = (b * 0.5) + Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 3.3e-43: tmp = b / (1.0 + math.exp(a)) else: tmp = (b * 0.5) + math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 3.3e-43) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(Float64(b * 0.5) + log(2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 3.3e-43)
tmp = b / (1.0 + exp(a));
else
tmp = (b * 0.5) + log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 3.3e-43], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 3.3 \cdot 10^{-43}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\end{array}
if (exp.f64 a) < 3.30000000000000016e-43Initial program 7.1%
Taylor expanded in b around 0 6.5%
associate-+r+6.5%
*-commutative6.5%
Simplified6.5%
Taylor expanded in b around 0 100.0%
log1p-define100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 3.30000000000000016e-43 < (exp.f64 a) Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 61.6%
*-commutative61.6%
Simplified61.6%
Final simplification72.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -135.0) (* b 0.5) (+ (* b 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -135.0) {
tmp = b * 0.5;
} else {
tmp = (b * 0.5) + log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-135.0d0)) then
tmp = b * 0.5d0
else
tmp = (b * 0.5d0) + log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -135.0) {
tmp = b * 0.5;
} else {
tmp = (b * 0.5) + Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -135.0: tmp = b * 0.5 else: tmp = (b * 0.5) + math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -135.0) tmp = Float64(b * 0.5); else tmp = Float64(Float64(b * 0.5) + log(2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -135.0)
tmp = b * 0.5;
else
tmp = (b * 0.5) + log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -135.0], N[(b * 0.5), $MachinePrecision], N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -135:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\end{array}
if a < -135Initial program 7.1%
Taylor expanded in a around 0 3.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 18.8%
if -135 < a Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 61.6%
*-commutative61.6%
Simplified61.6%
Final simplification49.9%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -130.0) (* b 0.5) (log1p (+ 1.0 b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -130.0) {
tmp = b * 0.5;
} else {
tmp = log1p((1.0 + b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -130.0) {
tmp = b * 0.5;
} else {
tmp = Math.log1p((1.0 + b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -130.0: tmp = b * 0.5 else: tmp = math.log1p((1.0 + b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -130.0) tmp = Float64(b * 0.5); else tmp = log1p(Float64(1.0 + b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -130.0], N[(b * 0.5), $MachinePrecision], N[Log[1 + N[(1.0 + b), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -130:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(1 + b\right)\\
\end{array}
\end{array}
if a < -130Initial program 7.1%
Taylor expanded in a around 0 3.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 18.8%
if -130 < a Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 60.7%
log1p-expm1-u60.7%
expm1-undefine60.7%
add-exp-log60.7%
Applied egg-rr60.7%
+-commutative60.7%
associate--l+60.7%
metadata-eval60.7%
Simplified60.7%
Final simplification49.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -170.0) (* b 0.5) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -170.0) {
tmp = b * 0.5;
} else {
tmp = log((b + 2.0));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-170.0d0)) then
tmp = b * 0.5d0
else
tmp = log((b + 2.0d0))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -170.0) {
tmp = b * 0.5;
} else {
tmp = Math.log((b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -170.0: tmp = b * 0.5 else: tmp = math.log((b + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -170.0) tmp = Float64(b * 0.5); else tmp = log(Float64(b + 2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -170.0)
tmp = b * 0.5;
else
tmp = log((b + 2.0));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -170.0], N[(b * 0.5), $MachinePrecision], N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -170:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -170Initial program 7.1%
Taylor expanded in a around 0 3.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 18.8%
if -170 < a Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 60.7%
Final simplification49.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -125.0) (* b 0.5) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -125.0) {
tmp = b * 0.5;
} else {
tmp = log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-125.0d0)) then
tmp = b * 0.5d0
else
tmp = log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -125.0) {
tmp = b * 0.5;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -125.0: tmp = b * 0.5 else: tmp = math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -125.0) tmp = Float64(b * 0.5); else tmp = log(2.0); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -125.0)
tmp = b * 0.5;
else
tmp = log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -125.0], N[(b * 0.5), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -125:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -125Initial program 7.1%
Taylor expanded in a around 0 3.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 18.8%
if -125 < a Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 61.3%
Final simplification49.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* b 0.5))
assert(a < b);
double code(double a, double b) {
return b * 0.5;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = b * 0.5d0
end function
assert a < b;
public static double code(double a, double b) {
return b * 0.5;
}
[a, b] = sort([a, b]) def code(a, b): return b * 0.5
a, b = sort([a, b]) function code(a, b) return Float64(b * 0.5) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = b * 0.5;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(b * 0.5), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
b \cdot 0.5
\end{array}
Initial program 49.2%
Taylor expanded in a around 0 46.7%
Taylor expanded in b around 0 45.9%
*-commutative45.9%
Simplified45.9%
Taylor expanded in b around inf 7.5%
Final simplification7.5%
herbie shell --seed 2024088
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))