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.

A372727 Triangle read by rows: T(n, k) = n if k = 0, otherwise n - k*floor(n/k). The binary modulo operation.

This page as a plain text file.
%I A372727 #22 Jul 22 2024 00:08:56
%S A372727 0,1,0,2,0,0,3,0,1,0,4,0,0,1,0,5,0,1,2,1,0,6,0,0,0,2,1,0,7,0,1,1,3,2,
%T A372727 1,0,8,0,0,2,0,3,2,1,0,9,0,1,0,1,4,3,2,1,0,10,0,0,1,2,0,4,3,2,1,0,11,
%U A372727 0,1,2,3,1,5,4,3,2,1,0,12,0,0,0,0,2,0,5,4,3,2,1,0
%N A372727 Triangle read by rows: T(n, k) = n if k = 0, otherwise n - k*floor(n/k). The binary modulo operation.
%C A372727 The binary operation 'mod' as defined here is discussed in 'Concrete Mathematics' by Graham et. al. on p. 82 and the connection with the congruence relation '(mod)' on p. 123. See also Bach & Shallit, p. 21, and Apostol, p. 14.
%C A372727 This definition is implemented in Sage, but not in Python. For example, Sage answers 0.mod(0) = 0, whereas in Python 0 % 0 leads to a 'ZeroDivisionError'. What is often misunderstood is that the operation 'mod' gives answers to divisibility, not to division. Apostol shows that n|0 (every integer divides zero), but 0|n implies n = 0 (zero divides only zero), and thus confirms the result given by Sage.
%D A372727 Tom Apostol, Introduction to analytic number theory, 1976, Springer, page 14.
%D A372727 Eric Bach and Jeffrey Shallit, Algorithmic Number Theory, 1997, p. 21.
%D A372727 Ronald L. Graham, Donald E. Knuth and Oren Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994, 34th printing 2022, p. 81f.
%e A372727 Triangle begins:
%e A372727   [ 0]  0;
%e A372727   [ 1]  1, 0;
%e A372727   [ 2]  2, 0, 0;
%e A372727   [ 3]  3, 0, 1, 0;
%e A372727   [ 4]  4, 0, 0, 1, 0;
%e A372727   [ 5]  5, 0, 1, 2, 1, 0;
%e A372727   [ 6]  6, 0, 0, 0, 2, 1, 0;
%e A372727   [ 7]  7, 0, 1, 1, 3, 2, 1, 0;
%e A372727   [ 8]  8, 0, 0, 2, 0, 3, 2, 1, 0;
%e A372727   [ 9]  9, 0, 1, 0, 1, 4, 3, 2, 1, 0;
%e A372727   [10] 10, 0, 0, 1, 2, 0, 4, 3, 2, 1, 0;
%e A372727   [11] 11, 0, 1, 2, 3, 1, 5, 4, 3, 2, 1, 0;
%e A372727 .
%e A372727 The triangle shows the modulo operation in the range 0 <= k <= n. Test your
%e A372727 computer implementation in the range R X R where R = [-6, ..., 0, ..., 6].
%e A372727 According to Graham et al. it should look like this:
%e A372727    0, -1, -2,  0,  0, 0, -6, 0, 0, 0, 2, 4, 0
%e A372727   -5,  0, -1, -2, -1, 0, -5, 0, 1, 1, 3, 0, 1
%e A372727   -4, -4,  0, -1,  0, 0, -4, 0, 0, 2, 0, 1, 2
%e A372727   -3, -3, -3,  0, -1, 0, -3, 0, 1, 0, 1, 2, 3
%e A372727   -2, -2, -2, -2,  0, 0, -2, 0, 0, 1, 2, 3, 4
%e A372727   -1, -1, -1, -1, -1, 0, -1, 0, 1, 2, 3, 4, 5
%e A372727    0,  0,  0,  0,  0, 0,  0, 0, 0, 0, 0, 0, 0
%e A372727   -5, -4, -3, -2, -1, 0,  1, 0, 1, 1, 1, 1, 1
%e A372727   -4, -3, -2, -1,  0, 0,  2, 0, 0, 2, 2, 2, 2
%e A372727   -3, -2, -1,  0, -1, 0,  3, 0, 1, 0, 3, 3, 3
%e A372727   -2, -1,  0, -2,  0, 0,  4, 0, 0, 1, 0, 4, 4
%e A372727   -1,  0, -3, -1, -1, 0,  5, 0, 1, 2, 1, 0, 5
%e A372727    0, -4, -2,  0,  0, 0,  6, 0, 0, 0, 2, 1, 0
%p A372727 MOD := (n, k) -> ifelse(k = 0, n, n - k * iquo(n, k)):
%p A372727 seq( seq(MOD(n, k), k = 0..n), n = 0..12);
%o A372727 (SageMath)
%o A372727 def T(n, k): return n.mod(k)
%o A372727 for n in srange(12): print([T(n, k) for k in range(n + 1)])
%o A372727 (Python)
%o A372727 def T(n, k): return n if k == 0 else n - k * (n // k)
%o A372727 for n in range(12): print([T(n, k) for k in range(n + 1)])
%o A372727 (Python)
%o A372727 def A372727_T(n, k): return n % k if k else n # _Chai Wah Wu_, May 14 2024
%Y A372727 Cf. A111490 (row sums).
%Y A372727 Cf. A048158.
%K A372727 nonn,tabl
%O A372727 0,4
%A A372727 _Peter Luschny_, May 13 2024