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.

Showing 1-4 of 4 results.

A078719 Number of odd terms among n, f(n), f(f(n)), ...., 1 for the Collatz function (that is, until reaching "1" for the first time), or -1 if 1 is never reached.

Original entry on oeis.org

1, 1, 3, 1, 2, 3, 6, 1, 7, 2, 5, 3, 3, 6, 6, 1, 4, 7, 7, 2, 2, 5, 5, 3, 8, 3, 42, 6, 6, 6, 40, 1, 9, 4, 4, 7, 7, 7, 12, 2, 41, 2, 10, 5, 5, 5, 39, 3, 8, 8, 8, 3, 3, 42, 42, 6, 11, 6, 11, 6, 6, 40, 40, 1, 9, 9, 9, 4, 4, 4, 38, 7, 43, 7, 4, 7, 7, 12, 12, 2, 7, 41, 41, 2, 2, 10, 10, 5, 10, 5, 34, 5, 5, 39
Offset: 1

Views

Author

Joseph L. Pe, Dec 20 2002

Keywords

Comments

The Collatz function (related to the "3x+1 problem") is defined by: f(n) = n/2 if n is even; f(n) = 3n + 1 if n is odd. A famous conjecture states that n, f(n), f(f(n)), .... eventually reaches 1.
a(n) = A006667(n) + 1; a(A000079(n))=1; a(A062052(n))=2; a(A062053(n))=3; a(A062054(n))=4; a(A062055(n))=5; a(A062056(n))=6; a(A062057(n))=7; a(A062058(n))=8; a(A062059(n))=9; a(A062060(n))=10. - Reinhard Zumkeller, Oct 08 2011
The count includes also the starting value n if it is odd. See A286380 for the version which never includes n itself. - Antti Karttunen, Aug 10 2017

Examples

			The terms n, f(n), f(f(n)), ...., 1 for n = 12 are: 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, of which 3 are odd. Hence a(12) = 3.
		

Crossrefs

Programs

  • Haskell
    a078719 =
       (+ 1) . length . filter odd . takeWhile (> 2) . (iterate a006370)
    a078719_list = map a078719 [1..]
    -- Reinhard Zumkeller, Oct 08 2011
    
  • Maple
    a:= proc(n) option remember; `if`(n<2, 1,
          `if`(n::even, a(n/2), 1+a(3*n+1)))
        end:
    seq(a(n), n=1..94);  # Alois P. Heinz, Jan 17 2025
  • Mathematica
    f[n_] := Module[{a, i, o}, i = n; o = 1; a = {}; While[i > 1, If[Mod[i, 2] == 1, o = o + 1]; a = Append[a, i]; i = f[i]]; o]; Table[f[i], {i, 1, 100}]
    Table[Count[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &], ?OddQ], {n, 94}] (* _Jayanta Basu, Jun 15 2013 *)
  • PARI
    a(n) = {my(x=n, v=List([])); while(x>1, if(x%2==0, x=x/2, listput(v, x); x=3*x+1)); 1+#v;} \\ Jinyuan Wang, Dec 29 2019

Formula

a(n) = A286380(n) + A000035(n). - Antti Karttunen, Aug 10 2017
a(n) = A258145(A003602(n)-1). - Alan Michael Gómez Calderón, Sep 15 2024

Extensions

"Escape clause" added to definition by N. J. A. Sloane, Jun 06 2017

A256598 Irregular triangle where row n contains the odd terms in the Collatz sequence beginning with 2n+1.

Original entry on oeis.org

1, 3, 5, 1, 5, 1, 7, 11, 17, 13, 5, 1, 9, 7, 11, 17, 13, 5, 1, 11, 17, 13, 5, 1, 13, 5, 1, 15, 23, 35, 53, 5, 1, 17, 13, 5, 1, 19, 29, 11, 17, 13, 5, 1, 21, 1, 23, 35, 53, 5, 1, 25, 19, 29, 11, 17, 13, 5, 1, 27, 41, 31, 47, 71, 107, 161, 121, 91, 137, 103, 155
Offset: 0

Views

Author

Bob Selcoe, Apr 03 2015

Keywords

Comments

The Collatz function is an integer-valued function given by n/2 if n is even and 3n+1 if n is odd. We build a Collatz sequence by beginning with a natural number and iterating the function indefinitely. It is conjectured that all such sequences terminate at 1.
In this triangle, row n is made up of the odd terms of the Collatz sequence beginning with 2n+1. Therefore, it is conjectured that this sequence is well-defined, i.e., that all rows terminate at 1.
The last index k in row n gives the number of iterations required for the Collatz sequence to terminate if even terms are omitted.
T(n,k)/T(n,k+1) is of form: ceiling(T(n,k)*3/2^j) for some j>=1. Therefore, the coefficients in each row may be read as a series of iterated ceilings, where j may vary. For example, row 3 has initial term 7, which is followed by ceiling(7*3/2), ceiling(ceiling(7*3/2)*3/2), ceiling(ceiling(ceiling(7*3/2)*3/2)*3/4), ceiling(ceiling(ceiling(ceiling(7*3/2)*3/2)*3/4)*3/8), ceiling(ceiling(ceiling(ceiling(ceiling(7*3/2)*3/2)*3/4)*3/8)*3/16).
The length of row n is A258145(n) (set to 0 if 1 is not reached after a finite number of steps). - Wolfdieter Lang, Aug 11 2021

Examples

			Triangle starts T(0,0):
n\k   0   1   2   3   4    5   6   7   8   9  10 ...
0:    1
1:    3   5   1
2:    5   1
3:    7   11  17  13  5    1
4:    9   7   11  17  13   5   1
5:    11  17  13  5   1
6:    13  5   1
7:    15  23  35  53  5    1
8:    17  13  5   1
9:    19  29  11  17  13   5   1
10:   21  1
11:   23  35  53  5    1
12:   25  19  29  11  17  13   5   1
...
n=13 starts with 27 and takes 41 steps: (27), 41, 31, 47, 71, 107,... 53, 5, 1, (see A372443).
Row 8 is [17, 13, 5, 1] because it is the subsequence of odd terms for the Collatz sequence starting with 17: [17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1].
		

Crossrefs

Cf. A372443 (row 13 up to its first 1).
Cf. also array A372283 showing the same terms in different orientation.

Programs

  • Mathematica
    f[n_] := NestWhileList[(3*# + 1)/2^IntegerExponent[3*# + 1, 2] &, 2*n + 1, # > 1 &]; Grid[Table[f[n], {n, 0, 12}]] (* L. Edson Jeffery, Apr 25 2015 *)
  • PARI
    row(n) = {my(oddn = 2*n+1, vl = List(oddn), x); while (oddn != 1, x = 3*oddn+1; oddn = x >> valuation(x, 2); listput(vl, oddn)); Vec(vl);}
    tabf(nn) = {for (n=0, nn, my(rown = row(n)); for (k=1, #rown, print1(rown[k], ", ")); print;);} \\ Michel Marcus, Oct 04 2019
  • Sage
    def Collatz(n):
        A = [n]
        b = A[-1]
        while b != 1:
            if is_even(b):
                A.append(b//2)
            else:
                A.append(3*b+1)
        return A
    [y for sublist in [[x for x in Collatz(2*n+1) if is_odd(x)] for n in [0..15]] for y in sublist] # Tom Edgar, Apr 04 2015
    

Formula

T(n,0) = 2n+1 and T(n,k) = A000265(3*T(n,k-1)+1) for k>0. - Tom Edgar, Apr 04 2015

A372283 Array read by upward antidiagonals: A(n, k) = R(A(n-1, k)) for n > 1, k >= 1; A(1, k) = 2*k-1, where Reduced Collatz function R(n) gives the odd part of 3n+1.

Original entry on oeis.org

1, 1, 3, 1, 5, 5, 1, 1, 1, 7, 1, 1, 1, 11, 9, 1, 1, 1, 17, 7, 11, 1, 1, 1, 13, 11, 17, 13, 1, 1, 1, 5, 17, 13, 5, 15, 1, 1, 1, 1, 13, 5, 1, 23, 17, 1, 1, 1, 1, 5, 1, 1, 35, 13, 19, 1, 1, 1, 1, 1, 1, 1, 53, 5, 29, 21, 1, 1, 1, 1, 1, 1, 1, 5, 1, 11, 1, 23, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 1, 35, 25
Offset: 1

Views

Author

Antti Karttunen, Apr 28 2024

Keywords

Comments

Collatz conjecture is equal to the claim that in each column 1 will eventually appear. See also arrays A372287 and A372288.

Examples

			Array begins:
n\k| 1  2  3   4   5   6   7   8   9  10  11  12  13   14  15   16  17  18
---+-----------------------------------------------------------------------
1  | 1, 3, 5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25,  27, 29,  31, 33, 35,
2  | 1, 5, 1, 11,  7, 17,  5, 23, 13, 29,  1, 35, 19,  41, 11,  47, 25, 53,
3  | 1, 1, 1, 17, 11, 13,  1, 35,  5, 11,  1, 53, 29,  31, 17,  71, 19,  5,
4  | 1, 1, 1, 13, 17,  5,  1, 53,  1, 17,  1,  5, 11,  47, 13, 107, 29,  1,
5  | 1, 1, 1,  5, 13,  1,  1,  5,  1, 13,  1,  1, 17,  71,  5, 161, 11,  1,
6  | 1, 1, 1,  1,  5,  1,  1,  1,  1,  5,  1,  1, 13, 107,  1, 121, 17,  1,
7  | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  5, 161,  1,  91, 13,  1,
8  | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 121,  1, 137,  5,  1,
9  | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  91,  1, 103,  1,  1,
10 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 137,  1, 155,  1,  1,
11 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 103,  1, 233,  1,  1,
12 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 155,  1, 175,  1,  1,
13 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 233,  1, 263,  1,  1,
14 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 175,  1, 395,  1,  1,
15 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 263,  1, 593,  1,  1,
16 | 1, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 395,  1, 445,  1,  1,
		

Crossrefs

Cf. A005408 (row 1), A075677 (row 2), A372443 (column 14).
Arrays derived from this one or related to:
A372287 the column index of A(n, k) in array A257852,
A372361 terms xored with binary words of the same length, either of the form 10101...0101 or 110101...0101, depending on whether the binary length is odd or even,
A372360 binary weights of A372361.
Cf. also array A371095 (giving every fourth column, 1, 5, 9, ...) and irregular array A256598 which gives the terms of each column, but only down to the first 1.

Programs

  • Mathematica
    With[{dmax = 15}, Table[#[[k, n-k+1]], {n, dmax}, {k, n}] & [Array[NestList[(3*# + 1)/2^IntegerExponent[3*# + 1, 2] &, 2*# - 1, dmax - #] &, dmax]]] (* Paolo Xausa, Apr 29 2024 *)
  • PARI
    up_to = 91;
    R(n) = { n = 1+3*n; n>>valuation(n, 2); };
    A372283sq(n,k) = if(1==n,2*k-1,R(A372283sq(n-1,k)));
    A372283list(up_to) = { my(v = vector(up_to), i=0); for(a=1,oo, for(col=1,a, i++; if(i > up_to, return(v)); v[i] = A372283sq((a-(col-1)),col))); (v); };
    v372283 = A372283list(up_to);
    A372283(n) = v372283[n];

Formula

For n > 1, A(n, k) = R(A372282(n-1, k)), where R(n) = (3*n+1)/2^A371093(n).
For all k >= 1, A(A258145(k-1), k) = 1 [which is the topmost 1 in each column].

A351123 Irregular triangle read by rows: row n lists the partial sums of the number of divisions by 2 after each tripling step in the Collatz trajectory of 2n+1.

Original entry on oeis.org

1, 5, 4, 1, 2, 4, 7, 11, 2, 3, 4, 6, 9, 13, 1, 3, 6, 10, 3, 7, 1, 2, 3, 8, 12, 2, 5, 9, 1, 4, 5, 7, 10, 14, 6, 1, 2, 7, 11, 2, 3, 6, 7, 9, 12, 16, 1, 3, 4, 5, 6, 7, 9, 11, 12, 14, 15, 16, 18, 19, 20, 21, 23, 26, 27, 28, 30, 31, 33, 34, 35, 36, 37, 38, 41, 42, 43, 44, 48, 50, 52, 56, 59, 60, 61, 66, 70
Offset: 1

Views

Author

Flávio V. Fernandes, Feb 01 2022

Keywords

Comments

The terms in row n are T(n,0), T(n,1), ..., T(n, A258145(n)-2), and are the partial sums of the terms in row n of A351122.
In each row n, the terms also satisfy the equation 3* (3* (3* (3* ... (3* (2n+1) +1) + 2^T(n,0)) + 2^T(n,1)) + 2^T(n,2)) + ... = 2^T(n, A258145(n)-2); e.g., for n=4, and A258145(4)-2=5: 3* (3* (3* (3* (3* (3*9+1) +2^2) +2^3) +2^4) +2^6) +2^9 = 2^13.
For row n, the right-hand side of the equation above is 2^A166549(n+1). E.g., for the above example (n=4), the right-hand side is 2^A166549(4+1) = 2^13.

Examples

			Triangle starts at T(1,0):
n\k   0   1   2   3   4   5   6   7   8   9   10 ...
1:    1   5
2:    4
3:    1   2   4   7  11
4:    2   3   4   6   9  13
5:    1   3   6  10
6:    3   7
7:    1   2   3   8   12
8:    2   5   9
...
E.g., row 3 of A351122 is [1, 1, 2, 3, 4]; its partial sums are [1, 2, 4, 7, 11].
		

Crossrefs

Programs

  • PARI
    orow(n) = my(m=2*n+1, list=List()); while (m != 1, if (m%2, m = 3*m+1, my(nb = valuation(m,2)); m/=2^nb; listput(list, nb));); Vec(list); \\ A351122
    row(n) = my(v = orow(n)); vector(#v, k, sum(i=1, k, v[i])); \\ Michel Marcus, Jul 18 2022

Extensions

Data corrected by Mohsen Maesumi, Jul 18 2022
Last row completed by Michel Marcus, Jul 18 2022
Showing 1-4 of 4 results.