cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A241773 A sequence constructed by greedily sampling the Gauss-Kuzmin distribution log_2[(i+1)^2/(i^2+2*i)] to minimize discrepancy.

This page as a plain text file.
%I A241773 #55 Aug 04 2025 18:39:36
%S A241773 1,2,3,1,4,1,5,2,1,6,1,7,1,2,3,1,8,1,9,2,1,4,1,10,1,3,2,1,11,1,2,5,1,
%T A241773 12,1,3,1,2,4,1,13,1,2,6,1,14,1,3,1,2,15,1,16,1,2,4,1,3,1,5,7,1,2,1,
%U A241773 17,1,2,3,1,18,1,8,2,1,4,1,6,1,2,3,1,5,1,19
%N A241773 A sequence constructed by greedily sampling the Gauss-Kuzmin distribution log_2[(i+1)^2/(i^2+2*i)] to minimize discrepancy.
%C A241773 Let the sequence be A = {a(i)}, i = 1, 2, 3,... and define p(i) =
%C A241773 log_2[(i+1)^2/(i^2+2*i)]. Additionally, define u(j, k) = k*p(j) - N(j, k), where N(j, k) is the number of occurrences of j in {a(i)}, i = 1,..., k-1. Refer to the first argument of u as the "index" of u. Then A is defined by a(1) = 1 and, for i > 1, a(i) = m, where m is the index of the maximal element of the set {u(j, i)}, j = 1, 2, 3,... That there is a single maximal element for all i is guaranteed by the fact that p(i) - p(j) is irrational for all i not equal to j.
%C A241773 Interpreting sequence A as the partial coefficients of the continued fraction expansion of a real number C, say, then C = 1.44224780173510148... which is, by construction, normal (in the continued fraction sense).
%C A241773 The geometric mean of the sequence equals Khintchine's constant K=2.685452001 = A002210 since the frequency of the integers agrees with the Gauss-Kuzmin distribution. - _Jwalin Bhatt_, Feb 11 2025
%H A241773 Jonathan Deane, <a href="/A241773/b241773.txt">Table of n, a(n) for n = 1..10000</a>
%H A241773 Jonathan Deane, <a href="/A241773/a241773.pdf">An integer sequence whose members obey a given p.d.f.</a>
%e A241773 Example from _Jwalin Bhatt_, Jun 10 2025: (Start)
%e A241773 Let p(k) denote the probability of k and c(k) denote the number of occurrences of k among the first n-1 terms; then the expected number of occurrences of k among n random terms is given by n*p(k).
%e A241773 We subtract the actual occurrences c(n) from the expected occurrences and pick the one with the highest value.
%e A241773 | n | n*p(1) - c(1) | n*p(2) - c(2) | n*p(3) - c(3) | choice |
%e A241773 |---|---------------|---------------|---------------|--------|
%e A241773 | 1 |     0.415     |     0.169     |     0.093     |   1    |
%e A241773 | 2 |    -0.169     |     0.339     |     0.186     |   2    |
%e A241773 | 3 |     0.245     |    -0.490     |     0.279     |   3    |
%e A241773 | 4 |     0.660     |    -0.320     |    -0.627     |   1    |
%e A241773 (End)
%p A241773 pdf := i -> -log[2](1 - 1/(i+1)^2);
%p A241773 gen_seq := proc(n)
%p A241773 local i, j, N, A, u, mm, ndig;
%p A241773 ndig := 40; N := 'N';
%p A241773 for i from 1 to n do    N[i] := 0;      end do;
%p A241773 A := 'A'; A[1] := 1; N[1] := 1;
%p A241773 for i from 2 to n do
%p A241773         u := 'u';
%p A241773         for j from 1 to n do
%p A241773                 u[j] := i*pdf(j) - N[j];
%p A241773         end do;
%p A241773         mm := max_maxind(evalf(convert(u, list), ndig));
%p A241773         if mm[3] then
%p A241773                 A[i] := mm[1];
%p A241773                 N[mm[1]] := N[mm[1]] + 1;
%p A241773         else
%p A241773                 return();
%p A241773         end if;
%p A241773 end do;
%p A241773 return(convert(A, list));
%p A241773 end:
%p A241773 max_maxind := proc(inl)
%p A241773 local uniq, mxind, mx, i;
%p A241773 uniq := `true`;
%p A241773 if nops(inl) = 1 then return([1, inl[1], uniq]); end if;
%p A241773 mxind := 1; mx := inl[1];
%p A241773 for i from 2 to nops(inl) do
%p A241773         if inl[i] > mx then
%p A241773                 mxind := i;
%p A241773                 mx := inl[i];
%p A241773                 uniq := `true`;
%p A241773         elif inl[i] = mx then
%p A241773                 uniq := `false`;
%p A241773         end if;
%p A241773 end do;
%p A241773 return([mxind, mx, uniq]);
%p A241773 end:
%p A241773 gen_seq(100);
%t A241773 probCountDiff[j_, k_, count_] := k*-Log[2, 1 - (1/((j + 1)^2))] - Lookup[count, j, 0]
%t A241773 samplePDF[n_] := Module[{coeffs, unreachedVal, counts, k, probCountDiffs, mostProbable},
%t A241773   coeffs = ConstantArray[0, n]; unreachedVal = 1; counts = <||>;
%t A241773   Do[probCountDiffs = Table[probCountDiff[i, k, counts], {i, 1, unreachedVal}];
%t A241773     mostProbable = First@FirstPosition[probCountDiffs, Max[probCountDiffs]];
%t A241773     If[mostProbable == unreachedVal, unreachedVal++]; coeffs[[k]] = mostProbable;
%t A241773     counts[mostProbable] = Lookup[counts, mostProbable, 0] + 1; , {k, 1, n}]; coeffs]
%t A241773 A241773 = samplePDF[120]  (* _Jwalin Bhatt_, Jun 04 2025 *)
%o A241773 (Python)
%o A241773 from fractions import Fraction
%o A241773 def prob_count_diff(j, k, count):
%o A241773     return  - ((1 - Fraction(1,(j+1)*(j+1)))**k) * (2**count)
%o A241773 def sample_pdf(n):
%o A241773     coeffs, unreached_val, counts = [], 1, {}
%o A241773     for k in range(1, n+1):
%o A241773         prob_count_diffs = [prob_count_diff(i, k, counts.get(i, 0)) for i in range(1, unreached_val+1)]
%o A241773         most_probable = prob_count_diffs.index(max(prob_count_diffs)) + 1
%o A241773         unreached_val += most_probable == unreached_val
%o A241773         coeffs.append(most_probable)
%o A241773         counts[most_probable] = counts.get(most_probable, 0) + 1
%o A241773     return coeffs
%o A241773 A241773 = sample_pdf(120)  # _Jwalin Bhatt_, Feb 09 2025
%Y A241773 Cf. A002210, A084580, A089618, A381617, A382961, A383238, A383899.
%K A241773 cofr,easy,nonn
%O A241773 1,2
%A A241773 _Jonathan Deane_, Apr 28 2014