login
a(0) = 0, a(n) = a(n-1) OR n.
28

%I #107 Jul 18 2024 04:44:06

%S 0,1,3,3,7,7,7,7,15,15,15,15,15,15,15,15,31,31,31,31,31,31,31,31,31,

%T 31,31,31,31,31,31,31,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,

%U 63,63,63,63,63,63,63,63,63,63,63,63,63,63

%N a(0) = 0, a(n) = a(n-1) OR n.

%C Also, 0+1+2+...+n in lunar arithmetic in base 2 written in base 10. - _N. J. A. Sloane_, Oct 02 2010

%C For n>0: replace all 0's with 1's in binary representation of n. - _Reinhard Zumkeller_, Jul 14 2003

%H Reinhard Zumkeller, <a href="/A003817/b003817.txt">Table of n, a(n) for n = 0..10000</a> [From _Reinhard Zumkeller_, Nov 14 2009]

%H D. Applegate, M. LeBrun and N. J. A. Sloane, <a href="http://arxiv.org/abs/1107.1130">Dismal Arithmetic</a>, arXiv:1107.1130 [math.NT], 2011. [Note: we have now changed the name from "dismal arithmetic" to "lunar arithmetic" - the old name was too depressing]

%H Ralf Stephan, <a href="/somedcgf.html">Some divide-and-conquer sequences ...</a>

%H Ralf Stephan, <a href="/A079944/a079944.ps">Table of generating functions</a>

%H Ralf Stephan, <a href="http://arXiv.org/abs/math.CO/0307027">Divide-and-conquer generating functions. I. Elementary sequences</a>, arXiv:math/0307027 [math.CO], 2003.

%H Reinhard Zumkeller, <a href="/A142149/a142149.txt">Logical Convolutions</a>

%H <a href="/index/Di#dismal">Index entries for sequences related to dismal (or lunar) arithmetic</a>

%F a(n) = a(n-1) + n*(1-floor(a(n-1)/n)). If 2^(k-1) <= n < 2^k, a(n) = 2^k - 1. - _Benoit Cloitre_, Aug 25 2002

%F a(n) = 1 + 2*a(floor(n/2)) for n > 0. - _Benoit Cloitre_, Apr 04 2003

%F G.f.: (1/(1-x)) * Sum_{k>=0} 2^k*x^2^k. - _Ralf Stephan_, Apr 18 2003

%F a(n) = 2*A053644(n)-1 = A092323(n) + A053644(n). - _Reinhard Zumkeller_, Feb 15 2004; corrected by _Anthony Browne_, Jun 26 2016

%F a(n) = OR{k OR (n-k): 0<=k<=n}. - _Reinhard Zumkeller_, Jul 15 2008

%F For n>0: a(n+1) = A035327(n) + n = A035327(n) XOR n. - _Reinhard Zumkeller_, Nov 14 2009

%F A092323(n+1) = floor(a(n)/2). - _Reinhard Zumkeller_, Jul 18 2010

%F a(n) = A265705(n,0) = A265705(n,n). - _Reinhard Zumkeller_, Dec 15 2015

%F a(n) = A062383(n) - 1.

%F G.f. A(x) satisfies: A(x) = 2*A(x^2)*(1 + x) + x/(1 - x). - _Ilya Gutkovskiy_, Aug 31 2019

%F a(n) >= A175039(n) - _Austin Shapiro_, Dec 29 2022

%p A003817 := n -> n + Bits:-Nand(n, n):

%p seq(A003817(n), n=0..61); # _Peter Luschny_, Sep 23 2019

%t a[0] = 0; a[n_] := a[n] = BitOr[ a[n-1], n]; Table[a[n], {n, 0, 61}] (* _Jean-François Alcover_, Dec 19 2011 *)

%t nxt[{n_,a_}]:={n+1,BitOr[a,n+1]}; Transpose[NestList[nxt,{0,0},70]] [[2]] (* _Harvey P. Dale_, May 06 2016 *)

%t 2^BitLength[Range[0,100]]-1 (* _Paolo Xausa_, Feb 08 2024 *)

%o (PARI) a(n)=1<<(log(2*n+1)\log(2))-1 \\ _Charles R Greathouse IV_, Dec 08 2011

%o (Haskell)

%o import Data.Bits ((.|.))

%o a003817 n = if n == 0 then 0 else 2 * a053644 n - 1

%o a003817_list = scanl (.|.) 0 [1..] :: [Integer]

%o -- _Reinhard Zumkeller_, Dec 08 2012, Jan 15 2012

%o (Python)

%o def a(n): return 0 if n==0 else 1 + 2*a(int(n/2)) # _Indranil Ghosh_, Apr 28 2017

%o (Python)

%o def A003817(n): return (1<<n.bit_length())-1 # _Chai Wah Wu_, Jul 17 2024

%Y This is Guy Steele's sequence GS(6, 6) (see A135416).

%Y Cf. A000004, A142149, A086099, A142150, A142151, A001477, A062383.

%Y Cf. A167832, A167878. - _Reinhard Zumkeller_, Nov 14 2009

%Y Cf. A179526; subsequence of A007448. - _Reinhard Zumkeller_, Jul 18 2010

%Y Cf. A265705.

%K nonn,base,nice

%O 0,3

%A _Marc LeBrun_