OFFSET
0,5
COMMENTS
Used to calculate number of subspaces of Zp^n where Zp is field of integers mod p.
Consider a square matrix A and call it special if (0) A is an upper triangular matrix, (1) a nonzero column of A has a 1 on the main diagonal and (2) if a row has a 1 on the main diagonal then this is the only nonzero element in that row.
If the diagonal of a special matrix is given (it can only contain 0's and 1's), many of the fields of A are determined by (0), (1) and (2). The number of fields that can be freely chosen while still satisfying (0), (1) and (2) is a(n), where n is the diagonal, read as a binary number with least significant bit at upper left.
a(n) is also the minimum number of adjacent bit swap operations required to pack all the ones of n to the right. - Philippe Beaudoin, Aug 19 2014
From Rakesh Khanna A, Aug 06 2021: (Start)
a(n) is also the area under the curve formed from the binary representation of n where each 0-bit corresponds to an increase of one unit along the x-axis and each 1-bit corresponds to an increase of one unit along the y-axis.
E.g., n = 20 = 10100_2 and the area under the curve shown below is a(n) = 5.
1 0 1 0 0
\ \ \ \ \ |
\ \ \+----+----+
\ \ | |
\+----+ +
| |
----+----+----+----+
(End)
REFERENCES
A. Siegel, Linear Aspects of Boolean Functions, 1999 (unpublished).
LINKS
Chai Wah Wu, Table of n, a(n) for n = 0..10000
Philip Lafrance, Narad Rampersad and Randy Yee, Some properties of a Rudin-Shapiro-like sequence, arXiv:1408.2277 [math.CO], 2014 (see page 2).
FORMULA
EXAMPLE
20 = 2^4 + 2^2, thus a(20) = (2-0) + (4-1) = 5.
MATHEMATICA
b[n_] := b[n] = If[n == 0, 0, If[EvenQ[n], b[n/2] + DigitCount[n/2, 2, 1], b[(n - 1)/2] + 1]];
a[n_] := b[n] - DigitCount[n, 2, 1];
Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Sep 23 2018 *)
PROG
(MIT/GNU Scheme) (define (A055941 n) (let loop ((n n) (ze 0) (s 0)) (cond ((zero? n) s) ((even? n) (loop (/ n 2) (1+ ze) s)) (else (loop (/ (-1+ n) 2) ze (+ s ze))))))
;; Antti Karttunen, Oct 12 2009
(PARI) a(n) = {my(b=binary(n)); nb = 0; for (i=1, #b-1, if (b[i], nb += sum(j=i+1, #b, !b[j])); ); nb; } \\ Michel Marcus, Aug 12 2014
(Python)
def A055941(n):
s = bin(n)[2:]
return sum(s[i:].count('0') for i, d in enumerate(s, start=1) if d == '1')
# Chai Wah Wu, Sep 07 2014
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Anno Siegel (siegel(AT)zrz.tu-berlin.de), Jul 18 2000
EXTENSIONS
Edited and extended by Antti Karttunen, Oct 12 2009
STATUS
approved