
(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 11 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) 2e-27) (/ b (+ 1.0 (exp a))) (log (+ (exp a) (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-27) {
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) <= 2d-27) 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) <= 2e-27) {
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) <= 2e-27: 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) <= 2e-27) 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) <= 2e-27)
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], 2e-27], 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 2 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-27Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 99.7%
if 2.0000000000000001e-27 < (exp.f64 a) Initial program 73.3%
Final simplification79.1%
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 58.9%
Taylor expanded in b around 0 76.8%
Final simplification76.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-27) (/ b (+ 1.0 (exp a))) (log1p (+ a (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-27) {
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) <= 2e-27) {
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) <= 2e-27: 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) <= 2e-27) 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], 2e-27], 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 2 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(a + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-27Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 99.7%
if 2.0000000000000001e-27 < (exp.f64 a) Initial program 73.3%
Taylor expanded in a around 0 72.0%
+-commutative72.0%
Simplified72.0%
Taylor expanded in b around inf 72.0%
log1p-def97.3%
Simplified97.3%
Final simplification97.8%
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 58.9%
Taylor expanded in b around 0 76.7%
log1p-def76.8%
Simplified76.8%
Final simplification76.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-27) (/ b (+ 1.0 (exp a))) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-27) {
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) <= 2e-27) {
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) <= 2e-27: 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) <= 2e-27) 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], 2e-27], 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 2 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-27Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 99.7%
if 2.0000000000000001e-27 < (exp.f64 a) Initial program 73.3%
Taylor expanded in a around 0 70.9%
log1p-def70.9%
Simplified70.9%
Final simplification77.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-27) (/ b (+ 1.0 (exp a))) (+ (log 2.0) (* 0.5 (+ a b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-27) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log(2.0) + (0.5 * (a + 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) <= 2d-27) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log(2.0d0) + (0.5d0 * (a + b))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 2e-27) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log(2.0) + (0.5 * (a + b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 2e-27: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log(2.0) + (0.5 * (a + b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-27) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(2.0) + Float64(0.5 * Float64(a + b))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 2e-27)
tmp = b / (1.0 + exp(a));
else
tmp = log(2.0) + (0.5 * (a + 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], 2e-27], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(0.5 * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + 0.5 \cdot \left(a + b\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-27Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 99.7%
if 2.0000000000000001e-27 < (exp.f64 a) Initial program 73.3%
Taylor expanded in b around 0 70.2%
log1p-def70.2%
Simplified70.2%
Taylor expanded in a around 0 70.3%
Taylor expanded in a around 0 69.8%
distribute-lft-out69.8%
Simplified69.8%
Final simplification76.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-27) (/ b (+ 1.0 (exp a))) (log (+ a (+ b 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-27) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((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) <= 2d-27) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((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) <= 2e-27) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log((a + (b + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 2e-27: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((a + (b + 2.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-27) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log(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) <= 2e-27)
tmp = b / (1.0 + exp(a));
else
tmp = log((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], 2e-27], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[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 2 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + \left(b + 2\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-27Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 99.7%
if 2.0000000000000001e-27 < (exp.f64 a) Initial program 73.3%
Taylor expanded in a around 0 72.0%
+-commutative72.0%
Simplified72.0%
Taylor expanded in b around 0 69.0%
associate-+r+69.0%
+-commutative69.0%
associate-+l+69.0%
Simplified69.0%
Final simplification75.7%
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 (+ a (+ b 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = log((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 (a <= (-1.0d0)) then
tmp = 0.5d0 * b
else
tmp = log((a + (b + 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((a + (b + 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((a + (b + 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(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 (a <= -1.0)
tmp = 0.5 * b;
else
tmp = log((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[a, -1.0], N[(0.5 * b), $MachinePrecision], N[Log[N[(a + N[(b + 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(a + \left(b + 2\right)\right)\\
\end{array}
\end{array}
if a < -1Initial program 9.0%
Taylor expanded in b around 0 98.0%
log1p-def98.4%
Simplified98.4%
Taylor expanded in a around 0 3.9%
*-commutative3.9%
Simplified3.9%
Taylor expanded in b around inf 18.5%
*-commutative18.5%
Simplified18.5%
if -1 < a Initial program 73.2%
Taylor expanded in a around 0 72.3%
+-commutative72.3%
Simplified72.3%
Taylor expanded in b around 0 69.3%
associate-+r+69.3%
+-commutative69.3%
associate-+l+69.3%
Simplified69.3%
Final simplification58.0%
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 (+ 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((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((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((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((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(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((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[(a + 2.0), $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(a + 2\right)\\
\end{array}
\end{array}
if a < -1Initial program 9.0%
Taylor expanded in b around 0 98.0%
log1p-def98.4%
Simplified98.4%
Taylor expanded in a around 0 3.9%
*-commutative3.9%
Simplified3.9%
Taylor expanded in b around inf 18.5%
*-commutative18.5%
Simplified18.5%
if -1 < a Initial program 73.2%
Taylor expanded in b around 0 70.1%
Taylor expanded in a around 0 69.6%
+-commutative69.6%
Simplified69.6%
Final simplification58.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -62.0) (* 0.5 b) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -62.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 <= (-62.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 <= -62.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 <= -62.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 <= -62.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 <= -62.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, -62.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 -62:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -62Initial program 7.4%
Taylor expanded in b around 0 99.7%
log1p-def100.0%
Simplified100.0%
Taylor expanded in a around 0 3.9%
*-commutative3.9%
Simplified3.9%
Taylor expanded in b around inf 18.8%
*-commutative18.8%
Simplified18.8%
if -62 < a Initial program 73.3%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 68.9%
Final simplification58.0%
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 58.9%
Taylor expanded in b around 0 76.7%
log1p-def76.8%
Simplified76.8%
Taylor expanded in a around 0 55.1%
*-commutative55.1%
Simplified55.1%
Taylor expanded in b around inf 6.9%
*-commutative6.9%
Simplified6.9%
Final simplification6.9%
herbie shell --seed 2024023
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))