
(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 14 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 (<= a -38.0) (/ b (+ (exp a) 1.0)) (log (+ (exp a) (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -38.0) {
tmp = b / (exp(a) + 1.0);
} 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 (a <= (-38.0d0)) then
tmp = b / (exp(a) + 1.0d0)
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 (a <= -38.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((Math.exp(a) + Math.exp(b)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -38.0: tmp = b / (math.exp(a) + 1.0) 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 (a <= -38.0) tmp = Float64(b / Float64(exp(a) + 1.0)); 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 (a <= -38.0)
tmp = b / (exp(a) + 1.0);
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[a, -38.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $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}\;a \leq -38:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\end{array}
if a < -38Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if -38 < a Initial program 69.7%
Final simplification76.6%
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 (+ (exp a) 1.0)) (log1p (+ (exp a) b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} 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 / (Math.exp(a) + 1.0);
} 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 / (math.exp(a) + 1.0) 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(exp(a) + 1.0)); 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[(N[Exp[a], $MachinePrecision] + 1.0), $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}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + b\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 9.6%
add-sqr-sqrt9.6%
log-prod9.7%
Applied egg-rr9.7%
log-prod9.6%
rem-square-sqrt9.6%
log1p-expm19.5%
expm1-def9.5%
rem-exp-log9.5%
associate--l+9.5%
expm1-def96.7%
Simplified96.7%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 69.2%
add-sqr-sqrt67.7%
log-prod68.2%
Applied egg-rr68.2%
log-prod67.7%
rem-square-sqrt69.2%
log1p-expm169.2%
expm1-def69.2%
rem-exp-log69.2%
associate--l+69.7%
expm1-def70.1%
Simplified70.1%
Taylor expanded in b around 0 65.9%
Final simplification74.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-21) (/ b (+ (exp a) 1.0)) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-21) {
tmp = b / (exp(a) + 1.0);
} 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-21) {
tmp = b / (Math.exp(a) + 1.0);
} 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-21: tmp = b / (math.exp(a) + 1.0) 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-21) tmp = Float64(b / Float64(exp(a) + 1.0)); 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-21], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $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^{-21}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 1.99999999999999982e-21Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if 1.99999999999999982e-21 < (exp.f64 a) Initial program 69.7%
Taylor expanded in a around 0 66.9%
log1p-def67.0%
Simplified67.0%
Final simplification74.6%
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 55.0%
add-sqr-sqrt53.9%
log-prod54.3%
Applied egg-rr54.3%
log-prod53.9%
rem-square-sqrt55.0%
log1p-expm155.0%
expm1-def55.0%
rem-exp-log55.0%
associate--l+55.4%
expm1-def76.4%
Simplified76.4%
Final simplification76.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (let* ((t_0 (+ 2.0 (+ b (* 0.5 (* b b)))))) (if (<= (exp a) 2e-21) (/ b (+ (exp a) 1.0)) (+ (log t_0) (/ a t_0)))))
assert(a < b);
double code(double a, double b) {
double t_0 = 2.0 + (b + (0.5 * (b * b)));
double tmp;
if (exp(a) <= 2e-21) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log(t_0) + (a / t_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) :: t_0
real(8) :: tmp
t_0 = 2.0d0 + (b + (0.5d0 * (b * b)))
if (exp(a) <= 2d-21) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log(t_0) + (a / t_0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = 2.0 + (b + (0.5 * (b * b)));
double tmp;
if (Math.exp(a) <= 2e-21) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log(t_0) + (a / t_0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): t_0 = 2.0 + (b + (0.5 * (b * b))) tmp = 0 if math.exp(a) <= 2e-21: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log(t_0) + (a / t_0) return tmp
a, b = sort([a, b]) function code(a, b) t_0 = Float64(2.0 + Float64(b + Float64(0.5 * Float64(b * b)))) tmp = 0.0 if (exp(a) <= 2e-21) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = Float64(log(t_0) + Float64(a / t_0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
t_0 = 2.0 + (b + (0.5 * (b * b)));
tmp = 0.0;
if (exp(a) <= 2e-21)
tmp = b / (exp(a) + 1.0);
else
tmp = log(t_0) + (a / t_0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(2.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[a], $MachinePrecision], 2e-21], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Log[t$95$0], $MachinePrecision] + N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\\
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log t_0 + \frac{a}{t_0}\\
\end{array}
\end{array}
if (exp.f64 a) < 1.99999999999999982e-21Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if 1.99999999999999982e-21 < (exp.f64 a) Initial program 69.7%
Taylor expanded in b around 0 66.8%
unpow266.8%
Simplified66.8%
Taylor expanded in a around 0 65.7%
unpow265.7%
unpow265.7%
Simplified65.7%
Final simplification73.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -45.0) (/ b (+ (exp a) 1.0)) (log (+ 2.0 (+ a (* 0.5 (* a a)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -45.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((2.0 + (a + (0.5 * (a * a)))));
}
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 <= (-45.0d0)) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((2.0d0 + (a + (0.5d0 * (a * a)))))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -45.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((2.0 + (a + (0.5 * (a * a)))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -45.0: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((2.0 + (a + (0.5 * (a * a))))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -45.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(2.0 + Float64(a + Float64(0.5 * Float64(a * a))))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -45.0)
tmp = b / (exp(a) + 1.0);
else
tmp = log((2.0 + (a + (0.5 * (a * a)))));
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, -45.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(2.0 + N[(a + N[(0.5 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -45:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(2 + \left(a + 0.5 \cdot \left(a \cdot a\right)\right)\right)\\
\end{array}
\end{array}
if a < -45Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if -45 < a Initial program 69.7%
Taylor expanded in b around 0 65.9%
Taylor expanded in a around 0 65.0%
unpow265.0%
Simplified65.0%
Final simplification73.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -22.0) (/ b (+ (exp a) 1.0)) (log (+ 2.0 (+ b (* 0.5 (* b b)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -22.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((2.0 + (b + (0.5 * (b * 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 (a <= (-22.0d0)) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((2.0d0 + (b + (0.5d0 * (b * b)))))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -22.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((2.0 + (b + (0.5 * (b * b)))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -22.0: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((2.0 + (b + (0.5 * (b * b))))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -22.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(2.0 + Float64(b + Float64(0.5 * Float64(b * b))))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -22.0)
tmp = b / (exp(a) + 1.0);
else
tmp = log((2.0 + (b + (0.5 * (b * 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[a, -22.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(2.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -22:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\\
\end{array}
\end{array}
if a < -22Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if -22 < a Initial program 69.7%
Taylor expanded in b around 0 66.8%
unpow266.8%
Simplified66.8%
Taylor expanded in a around 0 65.2%
unpow265.2%
Simplified65.2%
Final simplification73.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -28.0) (/ b (+ (exp a) 1.0)) (+ (log 2.0) (* b (+ 0.5 (* b 0.125))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -28.0) {
tmp = b / (exp(a) + 1.0);
} 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 (a <= (-28.0d0)) then
tmp = b / (exp(a) + 1.0d0)
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 (a <= -28.0) {
tmp = b / (Math.exp(a) + 1.0);
} 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 a <= -28.0: tmp = b / (math.exp(a) + 1.0) 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 (a <= -28.0) tmp = Float64(b / Float64(exp(a) + 1.0)); 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 (a <= -28.0)
tmp = b / (exp(a) + 1.0);
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[a, -28.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $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}\;a \leq -28:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + b \cdot \left(0.5 + b \cdot 0.125\right)\\
\end{array}
\end{array}
if a < -28Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if -28 < a Initial program 69.7%
Taylor expanded in b around 0 66.8%
unpow266.8%
Simplified66.8%
Taylor expanded in a around 0 65.2%
unpow265.2%
Simplified65.2%
Taylor expanded in b around 0 65.1%
+-commutative65.1%
unpow265.1%
associate-*r*65.1%
distribute-rgt-out65.1%
*-commutative65.1%
Simplified65.1%
Final simplification73.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -48.0) (* b 0.5) (+ (log 2.0) (* b 0.5))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -48.0) {
tmp = b * 0.5;
} else {
tmp = log(2.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 (a <= (-48.0d0)) then
tmp = b * 0.5d0
else
tmp = log(2.0d0) + (b * 0.5d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -48.0) {
tmp = b * 0.5;
} else {
tmp = Math.log(2.0) + (b * 0.5);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -48.0: tmp = b * 0.5 else: tmp = math.log(2.0) + (b * 0.5) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -48.0) tmp = Float64(b * 0.5); else tmp = Float64(log(2.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 (a <= -48.0)
tmp = b * 0.5;
else
tmp = log(2.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[a, -48.0], N[(b * 0.5), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -48:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2 + b \cdot 0.5\\
\end{array}
\end{array}
if a < -48Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 4.7%
*-commutative4.7%
Simplified4.7%
Taylor expanded in b around inf 18.5%
if -48 < a Initial program 69.7%
add-sqr-sqrt68.2%
log-prod68.7%
Applied egg-rr68.7%
log-prod68.2%
rem-square-sqrt69.7%
log1p-expm169.7%
expm1-def69.7%
rem-exp-log69.7%
associate--l+69.7%
expm1-def69.7%
Simplified69.7%
Taylor expanded in b around 0 66.5%
log1p-def66.5%
+-commutative66.5%
Simplified66.5%
Taylor expanded in a around 0 64.8%
*-commutative64.8%
Simplified64.8%
Final simplification53.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -20.0) (/ b (+ (exp a) 1.0)) (+ (log 2.0) (* b 0.5))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -20.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log(2.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 (a <= (-20.0d0)) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log(2.0d0) + (b * 0.5d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -20.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log(2.0) + (b * 0.5);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -20.0: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log(2.0) + (b * 0.5) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -20.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = Float64(log(2.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 (a <= -20.0)
tmp = b / (exp(a) + 1.0);
else
tmp = log(2.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[a, -20.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -20:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + b \cdot 0.5\\
\end{array}
\end{array}
if a < -20Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 97.8%
if -20 < a Initial program 69.7%
add-sqr-sqrt68.2%
log-prod68.7%
Applied egg-rr68.7%
log-prod68.2%
rem-square-sqrt69.7%
log1p-expm169.7%
expm1-def69.7%
rem-exp-log69.7%
associate--l+69.7%
expm1-def69.7%
Simplified69.7%
Taylor expanded in b around 0 66.5%
log1p-def66.5%
+-commutative66.5%
Simplified66.5%
Taylor expanded in a around 0 64.8%
*-commutative64.8%
Simplified64.8%
Final simplification72.9%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.0) (* b 0.5) (log (+ a 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = b * 0.5;
} 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 = b * 0.5d0
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 = b * 0.5;
} 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 = b * 0.5 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(b * 0.5); 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 = b * 0.5;
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[(b * 0.5), $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:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + 2\right)\\
\end{array}
\end{array}
if a < -1Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 4.7%
*-commutative4.7%
Simplified4.7%
Taylor expanded in b around inf 18.5%
if -1 < a Initial program 69.7%
Taylor expanded in b around 0 65.9%
Taylor expanded in a around 0 64.7%
+-commutative64.7%
Simplified64.7%
Final simplification53.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -48.0) (* b 0.5) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -48.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 <= (-48.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 <= -48.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 <= -48.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 <= -48.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 <= -48.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, -48.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 -48:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -48Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 4.7%
*-commutative4.7%
Simplified4.7%
Taylor expanded in b around inf 18.5%
if -48 < a Initial program 69.7%
Taylor expanded in b around 0 66.8%
unpow266.8%
Simplified66.8%
Taylor expanded in a around 0 65.2%
unpow265.2%
Simplified65.2%
Taylor expanded in b around 0 63.9%
+-commutative63.9%
Simplified63.9%
Final simplification52.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -48.0) (* b 0.5) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -48.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 <= (-48.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 <= -48.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 <= -48.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 <= -48.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 <= -48.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, -48.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 -48:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -48Initial program 10.0%
add-sqr-sqrt9.9%
log-prod10.0%
Applied egg-rr10.0%
log-prod9.9%
rem-square-sqrt10.0%
log1p-expm19.8%
expm1-def9.8%
rem-exp-log9.8%
associate--l+11.4%
expm1-def96.8%
Simplified96.8%
Taylor expanded in b around 0 97.8%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 4.7%
*-commutative4.7%
Simplified4.7%
Taylor expanded in b around inf 18.5%
if -48 < a Initial program 69.7%
Taylor expanded in b around 0 65.9%
log1p-def65.9%
Simplified65.9%
Taylor expanded in a around 0 64.2%
Final simplification53.0%
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 55.0%
add-sqr-sqrt53.9%
log-prod54.3%
Applied egg-rr54.3%
log-prod53.9%
rem-square-sqrt55.0%
log1p-expm155.0%
expm1-def55.0%
rem-exp-log55.0%
associate--l+55.4%
expm1-def76.4%
Simplified76.4%
Taylor expanded in b around 0 74.2%
log1p-def74.7%
+-commutative74.7%
Simplified74.7%
Taylor expanded in a around 0 50.0%
*-commutative50.0%
Simplified50.0%
Taylor expanded in b around inf 7.5%
Final simplification7.5%
herbie shell --seed 2023292
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))