
(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))) (log (+ (exp a) (exp 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 = log((exp(a) + exp(b)));
}
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.0d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((exp(a) + exp(b)))
end if
code = tmp
end function
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.log((Math.exp(a) + Math.exp(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.log((math.exp(a) + math.exp(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 = log(Float64(exp(a) + exp(b))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 0.0)
tmp = b / (1.0 + exp(a));
else
tmp = log((exp(a) + exp(b)));
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.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $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}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 9.6%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 69.3%
Final simplification76.3%
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))))
(+
(log t_0)
(+
(* 0.5 (* (pow b 2.0) (- (/ 1.0 t_0) (/ 1.0 (pow t_0 2.0)))))
(/ b t_0)))))assert(a < b);
double code(double a, double b) {
double t_0 = 1.0 + exp(a);
return log(t_0) + ((0.5 * (pow(b, 2.0) * ((1.0 / t_0) - (1.0 / pow(t_0, 2.0))))) + (b / t_0));
}
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
t_0 = 1.0d0 + exp(a)
code = log(t_0) + ((0.5d0 * ((b ** 2.0d0) * ((1.0d0 / t_0) - (1.0d0 / (t_0 ** 2.0d0))))) + (b / t_0))
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = 1.0 + Math.exp(a);
return Math.log(t_0) + ((0.5 * (Math.pow(b, 2.0) * ((1.0 / t_0) - (1.0 / Math.pow(t_0, 2.0))))) + (b / t_0));
}
[a, b] = sort([a, b]) def code(a, b): t_0 = 1.0 + math.exp(a) return math.log(t_0) + ((0.5 * (math.pow(b, 2.0) * ((1.0 / t_0) - (1.0 / math.pow(t_0, 2.0))))) + (b / t_0))
a, b = sort([a, b]) function code(a, b) t_0 = Float64(1.0 + exp(a)) return Float64(log(t_0) + Float64(Float64(0.5 * Float64((b ^ 2.0) * Float64(Float64(1.0 / t_0) - Float64(1.0 / (t_0 ^ 2.0))))) + Float64(b / t_0))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
t_0 = 1.0 + exp(a);
tmp = log(t_0) + ((0.5 * ((b ^ 2.0) * ((1.0 / t_0) - (1.0 / (t_0 ^ 2.0))))) + (b / t_0));
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]}, N[(N[Log[t$95$0], $MachinePrecision] + N[(N[(0.5 * N[(N[Power[b, 2.0], $MachinePrecision] * N[(N[(1.0 / t$95$0), $MachinePrecision] - N[(1.0 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 1 + e^{a}\\
\log t_0 + \left(0.5 \cdot \left({b}^{2} \cdot \left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right)\right) + \frac{b}{t_0}\right)
\end{array}
\end{array}
Initial program 55.1%
Taylor expanded in b around 0 74.3%
Final simplification74.3%
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))) (log (+ 2.0 (+ b (expm1 a))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((2.0 + (b + expm1(a))));
}
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.log((2.0 + (b + Math.expm1(a))));
}
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.log((2.0 + (b + math.expm1(a)))) 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 = log(Float64(2.0 + Float64(b + expm1(a)))); 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[N[(2.0 + N[(b + N[(Exp[a] - 1), $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}:\\
\;\;\;\;\log \left(2 + \left(b + \mathsf{expm1}\left(a\right)\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 9.6%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 69.3%
Taylor expanded in b around 0 65.8%
associate-+r+65.8%
+-commutative65.8%
Simplified65.8%
add-cbrt-cube65.2%
pow365.2%
associate-+r+65.2%
+-commutative65.2%
associate-+l+65.2%
Applied egg-rr65.2%
Taylor expanded in a around inf 65.8%
+-commutative65.8%
associate-+r+65.8%
metadata-eval65.8%
associate-+r+65.8%
+-commutative65.8%
metadata-eval65.8%
sub-neg65.8%
associate--r-65.7%
associate--l+65.8%
associate--r-65.8%
expm1-def65.7%
expm1-def65.8%
sub-neg65.8%
metadata-eval65.8%
+-commutative65.8%
metadata-eval65.8%
associate--r-65.8%
associate--r-65.8%
associate--r+65.8%
associate--r-65.8%
metadata-eval65.8%
+-commutative65.8%
+-commutative65.8%
associate-+l+65.8%
metadata-eval65.8%
sub-neg65.8%
Simplified65.7%
Final simplification73.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (/ b (+ 1.0 (exp a))) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
return (b / (1.0 + exp(a))) + log1p(exp(a));
}
assert a < b;
public static double code(double a, double b) {
return (b / (1.0 + Math.exp(a))) + Math.log1p(Math.exp(a));
}
[a, b] = sort([a, b]) def code(a, b): return (b / (1.0 + math.exp(a))) + math.log1p(math.exp(a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(b / Float64(1.0 + exp(a))) + log1p(exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{b}{1 + e^{a}} + \mathsf{log1p}\left(e^{a}\right)
\end{array}
Initial program 55.1%
Taylor expanded in b around 0 74.2%
log1p-def74.2%
Simplified74.2%
Final simplification74.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.1) (/ b (+ 1.0 (exp a))) (log1p (+ a (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.1) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p((a + exp(b)));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.1) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p((a + Math.exp(b)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.1: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p((a + math.exp(b))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.1) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(Float64(a + exp(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.1], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(a + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(a + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.10000000000000001Initial program 12.4%
Taylor expanded in b around 0 96.9%
log1p-def97.0%
Simplified97.0%
Taylor expanded in b around inf 95.4%
if 0.10000000000000001 < (exp.f64 a) Initial program 69.0%
Taylor expanded in a around 0 68.1%
+-commutative68.1%
Simplified68.1%
Taylor expanded in b around inf 68.1%
log1p-def97.5%
Simplified97.5%
Final simplification97.0%
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 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(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(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(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(exp(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[Exp[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^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 9.6%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 69.3%
Taylor expanded in a around 0 66.9%
log1p-def66.9%
Simplified66.9%
Final simplification74.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.1) (/ b (+ 1.0 (exp a))) (+ (log (+ b 2.0)) (/ a (+ b 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.1) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((b + 2.0)) + (a / (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 (exp(a) <= 0.1d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((b + 2.0d0)) + (a / (b + 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.1) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log((b + 2.0)) + (a / (b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.1: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((b + 2.0)) + (a / (b + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.1) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(Float64(b + 2.0)) + Float64(a / Float64(b + 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.1)
tmp = b / (1.0 + exp(a));
else
tmp = log((b + 2.0)) + (a / (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[N[Exp[a], $MachinePrecision], 0.1], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision] + N[(a / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right) + \frac{a}{b + 2}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.10000000000000001Initial program 12.4%
Taylor expanded in b around 0 96.9%
log1p-def97.0%
Simplified97.0%
Taylor expanded in b around inf 95.4%
if 0.10000000000000001 < (exp.f64 a) Initial program 69.0%
Taylor expanded in b around 0 66.0%
associate-+r+66.0%
+-commutative66.0%
Simplified66.0%
Taylor expanded in a around 0 65.1%
Final simplification72.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.1) (/ b (+ 1.0 (exp a))) (+ (log (+ a 2.0)) (/ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.1) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((a + 2.0)) + (b / (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.1d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((a + 2.0d0)) + (b / (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.1) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log((a + 2.0)) + (b / (a + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.1: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((a + 2.0)) + (b / (a + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.1) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(Float64(a + 2.0)) + Float64(b / 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.1)
tmp = b / (1.0 + exp(a));
else
tmp = log((a + 2.0)) + (b / (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.1], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(a + 2.0), $MachinePrecision]], $MachinePrecision] + N[(b / 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.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + 2\right) + \frac{b}{a + 2}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.10000000000000001Initial program 12.4%
Taylor expanded in b around 0 96.9%
log1p-def97.0%
Simplified97.0%
Taylor expanded in b around inf 95.4%
if 0.10000000000000001 < (exp.f64 a) Initial program 69.0%
Taylor expanded in a around 0 68.1%
+-commutative68.1%
Simplified68.1%
Taylor expanded in b around 0 65.7%
+-commutative65.7%
+-commutative65.7%
Simplified65.7%
Final simplification73.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.1) (/ b (+ 1.0 (exp a))) (log (+ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.1) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((b + (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.1d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((b + (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.1) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log((b + (a + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.1: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((b + (a + 2.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.1) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log(Float64(b + 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.1)
tmp = b / (1.0 + exp(a));
else
tmp = log((b + (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.1], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(b + 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.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.10000000000000001Initial program 12.4%
Taylor expanded in b around 0 96.9%
log1p-def97.0%
Simplified97.0%
Taylor expanded in b around inf 95.4%
if 0.10000000000000001 < (exp.f64 a) Initial program 69.0%
Taylor expanded in b around 0 66.0%
associate-+r+66.0%
+-commutative66.0%
Simplified66.0%
Taylor expanded in a around 0 65.0%
+-commutative65.0%
+-commutative65.0%
associate-+l+65.0%
Simplified65.0%
Final simplification72.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -420.0) (/ b (+ 1.0 (exp a))) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -420.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p(exp(a));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -420.0) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p(Math.exp(a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -420.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p(math.exp(a)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -420.0) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(exp(a)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -420.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -420:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\end{array}
if a < -420Initial program 9.6%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if -420 < a Initial program 69.3%
Taylor expanded in b around 0 66.1%
log1p-def66.1%
Simplified66.1%
Final simplification73.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.35) (/ b (+ 1.0 (exp a))) (+ (log 2.0) (+ (* 0.5 b) (* a (- 0.5 (* b 0.25)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.35) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log(2.0) + ((0.5 * b) + (a * (0.5 - (b * 0.25))));
}
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 <= (-1.35d0)) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log(2.0d0) + ((0.5d0 * b) + (a * (0.5d0 - (b * 0.25d0))))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.35) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log(2.0) + ((0.5 * b) + (a * (0.5 - (b * 0.25))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.35: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log(2.0) + ((0.5 * b) + (a * (0.5 - (b * 0.25)))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.35) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(2.0) + Float64(Float64(0.5 * b) + Float64(a * Float64(0.5 - Float64(b * 0.25))))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.35)
tmp = b / (1.0 + exp(a));
else
tmp = log(2.0) + ((0.5 * b) + (a * (0.5 - (b * 0.25))));
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, -1.35], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(N[(0.5 * b), $MachinePrecision] + N[(a * N[(0.5 - N[(b * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.35:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + \left(0.5 \cdot b + a \cdot \left(0.5 - b \cdot 0.25\right)\right)\\
\end{array}
\end{array}
if a < -1.3500000000000001Initial program 12.4%
Taylor expanded in b around 0 96.9%
log1p-def97.0%
Simplified97.0%
Taylor expanded in b around inf 95.4%
if -1.3500000000000001 < a Initial program 69.0%
Taylor expanded in b around 0 66.7%
log1p-def66.7%
Simplified66.7%
Taylor expanded in a around 0 65.9%
Final simplification73.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.0) (* 0.5 b) (log (+ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = log((b + (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 (a <= (-1.0d0)) then
tmp = 0.5d0 * b
else
tmp = log((b + (a + 2.0d0)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log((b + (a + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.0: tmp = 0.5 * b else: tmp = math.log((b + (a + 2.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.0) tmp = Float64(0.5 * b); else tmp = log(Float64(b + Float64(a + 2.0))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.0)
tmp = 0.5 * b;
else
tmp = log((b + (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[a, -1.0], N[(0.5 * b), $MachinePrecision], N[Log[N[(b + N[(a + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if a < -1Initial program 12.4%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 4.4%
Taylor expanded in b around inf 18.1%
if -1 < a Initial program 69.0%
Taylor expanded in b around 0 66.0%
associate-+r+66.0%
+-commutative66.0%
Simplified66.0%
Taylor expanded in a around 0 65.0%
+-commutative65.0%
+-commutative65.0%
associate-+l+65.0%
Simplified65.0%
Final simplification53.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -128.0) (* 0.5 b) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -128.0) {
tmp = 0.5 * b;
} 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 <= (-128.0d0)) then
tmp = 0.5d0 * b
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 <= -128.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log((b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -128.0: tmp = 0.5 * b else: tmp = math.log((b + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -128.0) tmp = Float64(0.5 * b); 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 <= -128.0)
tmp = 0.5 * b;
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, -128.0], N[(0.5 * b), $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 -128:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -128Initial program 9.6%
Taylor expanded in a around 0 4.0%
Taylor expanded in b around 0 4.2%
Taylor expanded in b around inf 18.5%
if -128 < a Initial program 69.3%
Taylor expanded in a around 0 66.9%
Taylor expanded in b around 0 63.8%
Final simplification53.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -155.0) (* 0.5 b) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -155.0) {
tmp = 0.5 * b;
} 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 <= (-155.0d0)) then
tmp = 0.5d0 * b
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 <= -155.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -155.0: tmp = 0.5 * b else: tmp = math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -155.0) tmp = Float64(0.5 * b); 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 <= -155.0)
tmp = 0.5 * b;
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, -155.0], N[(0.5 * b), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -155:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -155Initial program 9.6%
Taylor expanded in a around 0 4.0%
Taylor expanded in b around 0 4.2%
Taylor expanded in b around inf 18.5%
if -155 < a Initial program 69.3%
Taylor expanded in a around 0 66.9%
Taylor expanded in b around 0 64.4%
Final simplification53.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* 0.5 b))
assert(a < b);
double code(double a, double b) {
return 0.5 * b;
}
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 = 0.5d0 * b
end function
assert a < b;
public static double code(double a, double b) {
return 0.5 * b;
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 * b
a, b = sort([a, b]) function code(a, b) return Float64(0.5 * b) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 * b;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 * b), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot b
\end{array}
Initial program 55.1%
Taylor expanded in a around 0 51.9%
Taylor expanded in b around 0 50.2%
Taylor expanded in b around inf 7.0%
Final simplification7.0%
herbie shell --seed 2023321
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))