
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
double code(double N) {
return log((N + 1.0)) - log(N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = log((n + 1.0d0)) - log(n)
end function
public static double code(double N) {
return Math.log((N + 1.0)) - Math.log(N);
}
def code(N): return math.log((N + 1.0)) - math.log(N)
function code(N) return Float64(log(Float64(N + 1.0)) - log(N)) end
function tmp = code(N) tmp = log((N + 1.0)) - log(N); end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(N + 1\right) - \log N
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
double code(double N) {
return log((N + 1.0)) - log(N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = log((n + 1.0d0)) - log(n)
end function
public static double code(double N) {
return Math.log((N + 1.0)) - Math.log(N);
}
def code(N): return math.log((N + 1.0)) - math.log(N)
function code(N) return Float64(log(Float64(N + 1.0)) - log(N)) end
function tmp = code(N) tmp = log((N + 1.0)) - log(N); end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(N + 1\right) - \log N
\end{array}
(FPCore (N)
:precision binary64
(if (<= (- (log (+ N 1.0)) (log N)) 0.001)
(+
(/ 1.0 N)
(+
(/ 0.3333333333333333 (pow N 3.0))
(+ (/ -0.5 (pow N 2.0)) (/ -0.25 (pow N 4.0)))))
(- (log (/ N (+ N 1.0))))))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 0.001) {
tmp = (1.0 / N) + ((0.3333333333333333 / pow(N, 3.0)) + ((-0.5 / pow(N, 2.0)) + (-0.25 / pow(N, 4.0))));
} else {
tmp = -log((N / (N + 1.0)));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 0.001d0) then
tmp = (1.0d0 / n) + ((0.3333333333333333d0 / (n ** 3.0d0)) + (((-0.5d0) / (n ** 2.0d0)) + ((-0.25d0) / (n ** 4.0d0))))
else
tmp = -log((n / (n + 1.0d0)))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.001) {
tmp = (1.0 / N) + ((0.3333333333333333 / Math.pow(N, 3.0)) + ((-0.5 / Math.pow(N, 2.0)) + (-0.25 / Math.pow(N, 4.0))));
} else {
tmp = -Math.log((N / (N + 1.0)));
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 0.001: tmp = (1.0 / N) + ((0.3333333333333333 / math.pow(N, 3.0)) + ((-0.5 / math.pow(N, 2.0)) + (-0.25 / math.pow(N, 4.0)))) else: tmp = -math.log((N / (N + 1.0))) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.001) tmp = Float64(Float64(1.0 / N) + Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(-0.5 / (N ^ 2.0)) + Float64(-0.25 / (N ^ 4.0))))); else tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 0.001) tmp = (1.0 / N) + ((0.3333333333333333 / (N ^ 3.0)) + ((-0.5 / (N ^ 2.0)) + (-0.25 / (N ^ 4.0)))); else tmp = -log((N / (N + 1.0))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(1.0 / N), $MachinePrecision] + N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.001:\\
\;\;\;\;\frac{1}{N} + \left(\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{-0.5}{{N}^{2}} + \frac{-0.25}{{N}^{4}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1e-3Initial program 17.9%
+-commutative17.9%
log1p-define17.9%
Simplified17.9%
Taylor expanded in N around inf 99.8%
sub-neg99.8%
+-commutative99.8%
associate-+l+99.8%
associate-*r/99.8%
metadata-eval99.8%
+-commutative99.8%
distribute-neg-in99.8%
associate-*r/99.8%
metadata-eval99.8%
distribute-neg-frac99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
distribute-neg-frac99.8%
Simplified99.8%
if 1e-3 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 93.4%
+-commutative93.4%
log1p-define93.6%
Simplified93.6%
add-exp-log93.7%
Applied egg-rr93.7%
rem-exp-log93.6%
log1p-undefine93.4%
+-commutative93.4%
diff-log94.9%
clear-num94.6%
log-rec95.4%
Applied egg-rr95.4%
Final simplification99.5%
(FPCore (N)
:precision binary64
(if (<= (- (log (+ N 1.0)) (log N)) 0.001)
(+
(/ 0.3333333333333333 (pow N 3.0))
(- (- (/ 1.0 N) (/ 0.25 (pow N 4.0))) (/ 0.5 (pow N 2.0))))
(- (log (/ N (+ N 1.0))))))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 0.001) {
tmp = (0.3333333333333333 / pow(N, 3.0)) + (((1.0 / N) - (0.25 / pow(N, 4.0))) - (0.5 / pow(N, 2.0)));
} else {
tmp = -log((N / (N + 1.0)));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 0.001d0) then
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((1.0d0 / n) - (0.25d0 / (n ** 4.0d0))) - (0.5d0 / (n ** 2.0d0)))
else
tmp = -log((n / (n + 1.0d0)))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.001) {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (((1.0 / N) - (0.25 / Math.pow(N, 4.0))) - (0.5 / Math.pow(N, 2.0)));
} else {
tmp = -Math.log((N / (N + 1.0)));
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 0.001: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (((1.0 / N) - (0.25 / math.pow(N, 4.0))) - (0.5 / math.pow(N, 2.0))) else: tmp = -math.log((N / (N + 1.0))) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.001) tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(Float64(1.0 / N) - Float64(0.25 / (N ^ 4.0))) - Float64(0.5 / (N ^ 2.0)))); else tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 0.001) tmp = (0.3333333333333333 / (N ^ 3.0)) + (((1.0 / N) - (0.25 / (N ^ 4.0))) - (0.5 / (N ^ 2.0))); else tmp = -log((N / (N + 1.0))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 / N), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.001:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.25}{{N}^{4}}\right) - \frac{0.5}{{N}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1e-3Initial program 17.9%
+-commutative17.9%
log1p-define17.9%
Simplified17.9%
add-exp-log17.9%
Applied egg-rr17.9%
Taylor expanded in N around inf 99.8%
associate--l+99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
associate--r+99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
if 1e-3 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 93.4%
+-commutative93.4%
log1p-define93.6%
Simplified93.6%
add-exp-log93.7%
Applied egg-rr93.7%
rem-exp-log93.6%
log1p-undefine93.4%
+-commutative93.4%
diff-log94.9%
clear-num94.6%
log-rec95.4%
Applied egg-rr95.4%
Final simplification99.4%
(FPCore (N) :precision binary64 (if (<= (- (log (+ N 1.0)) (log N)) 8e-5) (+ (/ 0.3333333333333333 (pow N 3.0)) (- (/ 1.0 N) (/ 0.5 (pow N 2.0)))) (- (log (/ N (+ N 1.0))))))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 8e-5) {
tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / N) - (0.5 / pow(N, 2.0)));
} else {
tmp = -log((N / (N + 1.0)));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 8d-5) then
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / n) - (0.5d0 / (n ** 2.0d0)))
else
tmp = -log((n / (n + 1.0d0)))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 8e-5) {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / N) - (0.5 / Math.pow(N, 2.0)));
} else {
tmp = -Math.log((N / (N + 1.0)));
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 8e-5: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / N) - (0.5 / math.pow(N, 2.0))) else: tmp = -math.log((N / (N + 1.0))) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 8e-5) tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0)))); else tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 8e-5) tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / N) - (0.5 / (N ^ 2.0))); else tmp = -log((N / (N + 1.0))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 8e-5], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 8 \cdot 10^{-5}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 8.00000000000000065e-5Initial program 16.8%
+-commutative16.8%
log1p-define16.9%
Simplified16.9%
Taylor expanded in N around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
if 8.00000000000000065e-5 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 91.0%
+-commutative91.0%
log1p-define91.2%
Simplified91.2%
add-exp-log91.3%
Applied egg-rr91.3%
rem-exp-log91.2%
log1p-undefine91.0%
+-commutative91.0%
diff-log93.3%
clear-num93.0%
log-rec93.9%
Applied egg-rr93.9%
Final simplification99.1%
(FPCore (N) :precision binary64 (if (<= N 7200.0) (- (log (/ N (+ N 1.0)))) (/ (exp (fma 0.20833333333333334 (pow N -2.0) (/ -0.5 N))) N)))
double code(double N) {
double tmp;
if (N <= 7200.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = exp(fma(0.20833333333333334, pow(N, -2.0), (-0.5 / N))) / N;
}
return tmp;
}
function code(N) tmp = 0.0 if (N <= 7200.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64(exp(fma(0.20833333333333334, (N ^ -2.0), Float64(-0.5 / N))) / N); end return tmp end
code[N_] := If[LessEqual[N, 7200.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[Exp[N[(0.20833333333333334 * N[Power[N, -2.0], $MachinePrecision] + N[(-0.5 / N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 7200:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\mathsf{fma}\left(0.20833333333333334, {N}^{-2}, \frac{-0.5}{N}\right)}}{N}\\
\end{array}
\end{array}
if N < 7200Initial program 91.7%
+-commutative91.7%
log1p-define91.9%
Simplified91.9%
add-exp-log92.0%
Applied egg-rr92.0%
rem-exp-log91.9%
log1p-undefine91.7%
+-commutative91.7%
diff-log93.4%
clear-num93.1%
log-rec94.3%
Applied egg-rr94.3%
if 7200 < N Initial program 17.1%
+-commutative17.1%
log1p-define17.1%
Simplified17.1%
add-exp-log17.1%
Applied egg-rr17.1%
Taylor expanded in N around inf 94.5%
sub-neg94.5%
log-rec94.5%
+-commutative94.5%
unsub-neg94.5%
associate-*r/94.5%
metadata-eval94.5%
associate-*r/94.5%
metadata-eval94.5%
distribute-neg-frac94.5%
metadata-eval94.5%
Simplified94.5%
expm1-log1p-u94.5%
expm1-undefine19.8%
exp-sum19.8%
exp-diff19.8%
add-exp-log19.8%
div-inv19.8%
pow-flip19.8%
metadata-eval19.8%
exp-prod19.8%
Applied egg-rr19.8%
log1p-undefine19.8%
rem-exp-log19.8%
exp-prod19.8%
*-commutative19.8%
rem-exp-log19.8%
exp-diff19.8%
exp-sum19.8%
associate-+r-21.0%
expm1-undefine21.0%
rem-exp-log21.0%
log1p-define21.0%
log1p-expm194.5%
Simplified99.7%
Final simplification99.2%
(FPCore (N) :precision binary64 (if (<= N 10500.0) (- (log (/ N (+ N 1.0)))) (+ (/ 1.0 N) (+ (/ 0.3333333333333333 (pow N 3.0)) (/ -0.5 (pow N 2.0))))))
double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = (1.0 / N) + ((0.3333333333333333 / pow(N, 3.0)) + (-0.5 / pow(N, 2.0)));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 10500.0d0) then
tmp = -log((n / (n + 1.0d0)))
else
tmp = (1.0d0 / n) + ((0.3333333333333333d0 / (n ** 3.0d0)) + ((-0.5d0) / (n ** 2.0d0)))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -Math.log((N / (N + 1.0)));
} else {
tmp = (1.0 / N) + ((0.3333333333333333 / Math.pow(N, 3.0)) + (-0.5 / Math.pow(N, 2.0)));
}
return tmp;
}
def code(N): tmp = 0 if N <= 10500.0: tmp = -math.log((N / (N + 1.0))) else: tmp = (1.0 / N) + ((0.3333333333333333 / math.pow(N, 3.0)) + (-0.5 / math.pow(N, 2.0))) return tmp
function code(N) tmp = 0.0 if (N <= 10500.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64(Float64(1.0 / N) + Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(-0.5 / (N ^ 2.0)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 10500.0) tmp = -log((N / (N + 1.0))); else tmp = (1.0 / N) + ((0.3333333333333333 / (N ^ 3.0)) + (-0.5 / (N ^ 2.0))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 10500.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[(1.0 / N), $MachinePrecision] + N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 10500:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N} + \left(\frac{0.3333333333333333}{{N}^{3}} + \frac{-0.5}{{N}^{2}}\right)\\
\end{array}
\end{array}
if N < 10500Initial program 91.0%
+-commutative91.0%
log1p-define91.2%
Simplified91.2%
add-exp-log91.3%
Applied egg-rr91.3%
rem-exp-log91.2%
log1p-undefine91.0%
+-commutative91.0%
diff-log93.3%
clear-num93.0%
log-rec93.9%
Applied egg-rr93.9%
if 10500 < N Initial program 16.8%
+-commutative16.8%
log1p-define16.9%
Simplified16.9%
Taylor expanded in N around inf 99.7%
sub-neg99.7%
+-commutative99.7%
associate-+l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.1%
(FPCore (N) :precision binary64 (if (<= N 10500.0) (- (log (/ N (+ N 1.0)))) (+ (/ 0.3333333333333333 (pow N 3.0)) (* (pow N -2.0) (+ N -0.5)))))
double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = (0.3333333333333333 / pow(N, 3.0)) + (pow(N, -2.0) * (N + -0.5));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 10500.0d0) then
tmp = -log((n / (n + 1.0d0)))
else
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((n ** (-2.0d0)) * (n + (-0.5d0)))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -Math.log((N / (N + 1.0)));
} else {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (Math.pow(N, -2.0) * (N + -0.5));
}
return tmp;
}
def code(N): tmp = 0 if N <= 10500.0: tmp = -math.log((N / (N + 1.0))) else: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (math.pow(N, -2.0) * (N + -0.5)) return tmp
function code(N) tmp = 0.0 if (N <= 10500.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64((N ^ -2.0) * Float64(N + -0.5))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 10500.0) tmp = -log((N / (N + 1.0))); else tmp = (0.3333333333333333 / (N ^ 3.0)) + ((N ^ -2.0) * (N + -0.5)); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 10500.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N, -2.0], $MachinePrecision] * N[(N + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 10500:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + {N}^{-2} \cdot \left(N + -0.5\right)\\
\end{array}
\end{array}
if N < 10500Initial program 91.0%
+-commutative91.0%
log1p-define91.2%
Simplified91.2%
add-exp-log91.3%
Applied egg-rr91.3%
rem-exp-log91.2%
log1p-undefine91.0%
+-commutative91.0%
diff-log93.3%
clear-num93.0%
log-rec93.9%
Applied egg-rr93.9%
if 10500 < N Initial program 16.8%
+-commutative16.8%
log1p-define16.9%
Simplified16.9%
Taylor expanded in N around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
frac-sub99.4%
*-un-lft-identity99.4%
unpow299.4%
cube-mult99.3%
Applied egg-rr99.3%
unpow299.3%
distribute-lft-out--99.3%
Simplified99.3%
*-un-lft-identity99.3%
associate-/l*99.2%
div-inv99.3%
sub-neg99.3%
metadata-eval99.3%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
*-lft-identity99.4%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.4%
pow-plus99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification98.9%
(FPCore (N) :precision binary64 (if (<= N 10500.0) (- (log (/ N (+ N 1.0)))) (* (pow N -3.0) (fma N (+ N -0.5) 0.3333333333333333))))
double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = pow(N, -3.0) * fma(N, (N + -0.5), 0.3333333333333333);
}
return tmp;
}
function code(N) tmp = 0.0 if (N <= 10500.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64((N ^ -3.0) * fma(N, Float64(N + -0.5), 0.3333333333333333)); end return tmp end
code[N_] := If[LessEqual[N, 10500.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[Power[N, -3.0], $MachinePrecision] * N[(N * N[(N + -0.5), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 10500:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;{N}^{-3} \cdot \mathsf{fma}\left(N, N + -0.5, 0.3333333333333333\right)\\
\end{array}
\end{array}
if N < 10500Initial program 91.0%
+-commutative91.0%
log1p-define91.2%
Simplified91.2%
add-exp-log91.3%
Applied egg-rr91.3%
rem-exp-log91.2%
log1p-undefine91.0%
+-commutative91.0%
diff-log93.3%
clear-num93.0%
log-rec93.9%
Applied egg-rr93.9%
if 10500 < N Initial program 16.8%
+-commutative16.8%
log1p-define16.9%
Simplified16.9%
Taylor expanded in N around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
frac-sub99.4%
*-un-lft-identity99.4%
unpow299.4%
cube-mult99.3%
Applied egg-rr99.3%
unpow299.3%
distribute-lft-out--99.3%
Simplified99.3%
*-un-lft-identity99.3%
+-commutative99.3%
div-inv99.2%
div-inv99.2%
distribute-rgt-out99.2%
pow-flip99.3%
metadata-eval99.3%
sub-neg99.3%
metadata-eval99.3%
Applied egg-rr99.3%
*-lft-identity99.3%
fma-define99.4%
Simplified99.4%
Final simplification98.8%
(FPCore (N) :precision binary64 (if (<= N 10500.0) (- (log (/ N (+ N 1.0)))) (* (pow N -3.0) (+ 0.3333333333333333 (* N (+ N -0.5))))))
double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = pow(N, -3.0) * (0.3333333333333333 + (N * (N + -0.5)));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 10500.0d0) then
tmp = -log((n / (n + 1.0d0)))
else
tmp = (n ** (-3.0d0)) * (0.3333333333333333d0 + (n * (n + (-0.5d0))))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 10500.0) {
tmp = -Math.log((N / (N + 1.0)));
} else {
tmp = Math.pow(N, -3.0) * (0.3333333333333333 + (N * (N + -0.5)));
}
return tmp;
}
def code(N): tmp = 0 if N <= 10500.0: tmp = -math.log((N / (N + 1.0))) else: tmp = math.pow(N, -3.0) * (0.3333333333333333 + (N * (N + -0.5))) return tmp
function code(N) tmp = 0.0 if (N <= 10500.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64((N ^ -3.0) * Float64(0.3333333333333333 + Float64(N * Float64(N + -0.5)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 10500.0) tmp = -log((N / (N + 1.0))); else tmp = (N ^ -3.0) * (0.3333333333333333 + (N * (N + -0.5))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 10500.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[Power[N, -3.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N * N[(N + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 10500:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;{N}^{-3} \cdot \left(0.3333333333333333 + N \cdot \left(N + -0.5\right)\right)\\
\end{array}
\end{array}
if N < 10500Initial program 91.0%
+-commutative91.0%
log1p-define91.2%
Simplified91.2%
add-exp-log91.3%
Applied egg-rr91.3%
rem-exp-log91.2%
log1p-undefine91.0%
+-commutative91.0%
diff-log93.3%
clear-num93.0%
log-rec93.9%
Applied egg-rr93.9%
if 10500 < N Initial program 16.8%
+-commutative16.8%
log1p-define16.9%
Simplified16.9%
Taylor expanded in N around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
frac-sub99.4%
*-un-lft-identity99.4%
unpow299.4%
cube-mult99.3%
Applied egg-rr99.3%
unpow299.3%
distribute-lft-out--99.3%
Simplified99.3%
+-commutative99.3%
div-inv99.2%
div-inv99.2%
distribute-rgt-out99.2%
pow-flip99.3%
metadata-eval99.3%
sub-neg99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Final simplification98.8%
(FPCore (N) :precision binary64 (if (<= N 250000.0) (- (log (/ N (+ N 1.0)))) (+ (/ 1.0 N) (/ (/ -0.5 N) N))))
double code(double N) {
double tmp;
if (N <= 250000.0) {
tmp = -log((N / (N + 1.0)));
} else {
tmp = (1.0 / N) + ((-0.5 / N) / N);
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 250000.0d0) then
tmp = -log((n / (n + 1.0d0)))
else
tmp = (1.0d0 / n) + (((-0.5d0) / n) / n)
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 250000.0) {
tmp = -Math.log((N / (N + 1.0)));
} else {
tmp = (1.0 / N) + ((-0.5 / N) / N);
}
return tmp;
}
def code(N): tmp = 0 if N <= 250000.0: tmp = -math.log((N / (N + 1.0))) else: tmp = (1.0 / N) + ((-0.5 / N) / N) return tmp
function code(N) tmp = 0.0 if (N <= 250000.0) tmp = Float64(-log(Float64(N / Float64(N + 1.0)))); else tmp = Float64(Float64(1.0 / N) + Float64(Float64(-0.5 / N) / N)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 250000.0) tmp = -log((N / (N + 1.0))); else tmp = (1.0 / N) + ((-0.5 / N) / N); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 250000.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[(1.0 / N), $MachinePrecision] + N[(N[(-0.5 / N), $MachinePrecision] / N), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 250000:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N} + \frac{\frac{-0.5}{N}}{N}\\
\end{array}
\end{array}
if N < 2.5e5Initial program 87.2%
+-commutative87.2%
log1p-define87.3%
Simplified87.3%
add-exp-log87.4%
Applied egg-rr87.4%
rem-exp-log87.3%
log1p-undefine87.2%
+-commutative87.2%
diff-log90.1%
clear-num89.9%
log-rec90.9%
Applied egg-rr90.9%
if 2.5e5 < N Initial program 15.0%
+-commutative15.0%
log1p-define15.1%
Simplified15.1%
add-exp-log15.1%
Applied egg-rr15.1%
Taylor expanded in N around inf 94.5%
sub-neg94.5%
log-rec94.5%
+-commutative94.5%
unsub-neg94.5%
associate-*r/94.5%
metadata-eval94.5%
associate-*r/94.5%
metadata-eval94.5%
distribute-neg-frac94.5%
metadata-eval94.5%
Simplified94.5%
Taylor expanded in N around inf 94.0%
log-rec94.0%
distribute-rgt-neg-in94.0%
exp-prod93.8%
remove-double-neg93.8%
exp-prod94.0%
neg-mul-194.0%
log-rec94.0%
rem-exp-log98.9%
associate-*r/98.9%
Simplified98.9%
Final simplification97.9%
(FPCore (N) :precision binary64 (if (<= N 240000.0) (log (+ 1.0 (/ 1.0 N))) (+ (/ 1.0 N) (/ (/ -0.5 N) N))))
double code(double N) {
double tmp;
if (N <= 240000.0) {
tmp = log((1.0 + (1.0 / N)));
} else {
tmp = (1.0 / N) + ((-0.5 / N) / N);
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 240000.0d0) then
tmp = log((1.0d0 + (1.0d0 / n)))
else
tmp = (1.0d0 / n) + (((-0.5d0) / n) / n)
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 240000.0) {
tmp = Math.log((1.0 + (1.0 / N)));
} else {
tmp = (1.0 / N) + ((-0.5 / N) / N);
}
return tmp;
}
def code(N): tmp = 0 if N <= 240000.0: tmp = math.log((1.0 + (1.0 / N))) else: tmp = (1.0 / N) + ((-0.5 / N) / N) return tmp
function code(N) tmp = 0.0 if (N <= 240000.0) tmp = log(Float64(1.0 + Float64(1.0 / N))); else tmp = Float64(Float64(1.0 / N) + Float64(Float64(-0.5 / N) / N)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 240000.0) tmp = log((1.0 + (1.0 / N))); else tmp = (1.0 / N) + ((-0.5 / N) / N); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 240000.0], N[Log[N[(1.0 + N[(1.0 / N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(1.0 / N), $MachinePrecision] + N[(N[(-0.5 / N), $MachinePrecision] / N), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 240000:\\
\;\;\;\;\log \left(1 + \frac{1}{N}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N} + \frac{\frac{-0.5}{N}}{N}\\
\end{array}
\end{array}
if N < 2.4e5Initial program 87.8%
+-commutative87.8%
log1p-define88.0%
Simplified88.0%
add-log-exp87.9%
log1p-expm1-u87.9%
log1p-undefine87.9%
diff-log87.9%
log1p-undefine87.9%
rem-exp-log87.6%
+-commutative87.6%
add-exp-log87.6%
log1p-undefine87.6%
log1p-expm1-u87.6%
add-exp-log90.6%
Applied egg-rr90.6%
Taylor expanded in N around 0 90.7%
if 2.4e5 < N Initial program 15.3%
+-commutative15.3%
log1p-define15.3%
Simplified15.3%
add-exp-log15.3%
Applied egg-rr15.3%
Taylor expanded in N around inf 94.5%
sub-neg94.5%
log-rec94.5%
+-commutative94.5%
unsub-neg94.5%
associate-*r/94.5%
metadata-eval94.5%
associate-*r/94.5%
metadata-eval94.5%
distribute-neg-frac94.5%
metadata-eval94.5%
Simplified94.5%
Taylor expanded in N around inf 93.9%
log-rec93.9%
distribute-rgt-neg-in93.9%
exp-prod93.7%
remove-double-neg93.7%
exp-prod93.9%
neg-mul-193.9%
log-rec93.9%
rem-exp-log98.8%
associate-*r/98.8%
Simplified98.8%
Final simplification97.8%
(FPCore (N) :precision binary64 (+ (/ 1.0 N) (/ (/ -0.5 N) N)))
double code(double N) {
return (1.0 / N) + ((-0.5 / N) / N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = (1.0d0 / n) + (((-0.5d0) / n) / n)
end function
public static double code(double N) {
return (1.0 / N) + ((-0.5 / N) / N);
}
def code(N): return (1.0 / N) + ((-0.5 / N) / N)
function code(N) return Float64(Float64(1.0 / N) + Float64(Float64(-0.5 / N) / N)) end
function tmp = code(N) tmp = (1.0 / N) + ((-0.5 / N) / N); end
code[N_] := N[(N[(1.0 / N), $MachinePrecision] + N[(N[(-0.5 / N), $MachinePrecision] / N), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{N} + \frac{\frac{-0.5}{N}}{N}
\end{array}
Initial program 24.1%
+-commutative24.1%
log1p-define24.1%
Simplified24.1%
add-exp-log24.1%
Applied egg-rr24.1%
Taylor expanded in N around inf 90.1%
sub-neg90.1%
log-rec90.1%
+-commutative90.1%
unsub-neg90.1%
associate-*r/90.1%
metadata-eval90.1%
associate-*r/90.1%
metadata-eval90.1%
distribute-neg-frac90.1%
metadata-eval90.1%
Simplified90.1%
Taylor expanded in N around inf 87.9%
log-rec87.9%
distribute-rgt-neg-in87.9%
exp-prod87.8%
remove-double-neg87.8%
exp-prod87.9%
neg-mul-187.9%
log-rec87.9%
rem-exp-log92.2%
associate-*r/92.2%
Simplified92.2%
Final simplification92.2%
(FPCore (N) :precision binary64 (/ 1.0 N))
double code(double N) {
return 1.0 / N;
}
real(8) function code(n)
real(8), intent (in) :: n
code = 1.0d0 / n
end function
public static double code(double N) {
return 1.0 / N;
}
def code(N): return 1.0 / N
function code(N) return Float64(1.0 / N) end
function tmp = code(N) tmp = 1.0 / N; end
code[N_] := N[(1.0 / N), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{N}
\end{array}
Initial program 24.1%
+-commutative24.1%
log1p-define24.1%
Simplified24.1%
Taylor expanded in N around inf 84.2%
Final simplification84.2%
(FPCore (N) :precision binary64 0.0)
double code(double N) {
return 0.0;
}
real(8) function code(n)
real(8), intent (in) :: n
code = 0.0d0
end function
public static double code(double N) {
return 0.0;
}
def code(N): return 0.0
function code(N) return 0.0 end
function tmp = code(N) tmp = 0.0; end
code[N_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 24.1%
+-commutative24.1%
log1p-define24.1%
Simplified24.1%
sub-neg24.1%
+-commutative24.1%
add-sqr-sqrt24.2%
distribute-rgt-neg-in24.2%
fma-define25.6%
Applied egg-rr25.6%
Taylor expanded in N around inf 3.3%
log-rec3.3%
log-rec3.3%
distribute-rgt1-in3.3%
metadata-eval3.3%
mul0-lft3.3%
Simplified3.3%
Final simplification3.3%
(FPCore (N) :precision binary64 (log1p (/ 1.0 N)))
double code(double N) {
return log1p((1.0 / N));
}
public static double code(double N) {
return Math.log1p((1.0 / N));
}
def code(N): return math.log1p((1.0 / N))
function code(N) return log1p(Float64(1.0 / N)) end
code[N_] := N[Log[1 + N[(1.0 / N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(\frac{1}{N}\right)
\end{array}
herbie shell --seed 2024044
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
:pre (and (> N 1.0) (< N 1e+40))
:herbie-target
(log1p (/ 1.0 N))
(- (log (+ N 1.0)) (log N)))