login
Generalized nim sum n + n in base 4.
5

%I #35 Jan 30 2023 11:12:50

%S 0,2,0,2,8,10,8,10,0,2,0,2,8,10,8,10,32,34,32,34,40,42,40,42,32,34,32,

%T 34,40,42,40,42,0,2,0,2,8,10,8,10,0,2,0,2,8,10,8,10,32,34,32,34,40,42,

%U 40,42,32,34,32,34,40,42,40,42,128,130,128,130,136,138,136,138,128

%N Generalized nim sum n + n in base 4.

%H Reinhard Zumkeller, <a href="/A004514/b004514.txt">Table of n, a(n) for n = 0..10000</a>

%H <a href="/index/Ni#Nimsums">Index entries for sequences related to Nim-sums</a>

%F Generalized nim sum m + n in base q: write m and n in base q and add mod q with no carries, e.g., 5 + 8 in base 3 = "21" + "22" = "10" = 1.

%F From _Vladeta Jovovic_, Feb 23 2003: (Start)

%F a(n) = 2*(n - a(floor(n/2))).

%F a(n) = 2*A063694(n). (End)

%F a(n) = A088442(n) - 1. - Chris Groer (cgroer(AT)math.uga.edu), Nov 10, 2003

%F a(n) = n + A053985(n). - _Reinhard Zumkeller_, Dec 27 2003

%F a(n) = A063695(2*n+1). - _Reinhard Zumkeller_, Sep 26 2015

%F a(n) = Sum_{k>=0} A030308(n,k)*A103424(k+1). - _Philippe Deléham_, Jan 12 2023

%t A004514[n_]:= A004514[n]= If[n==0, 0, 2*n -2*A004514[Floor[n/2]]];

%t Table[A004514[n], {n,0,90}] (* _G. C. Greubel_, Dec 05 2022 *)

%o (Haskell)

%o a004514 = a063695 . (+ 1) . (* 2) -- _Reinhard Zumkeller_, Sep 26 2015

%o (Magma)

%o function A063694(n)

%o if n le 1 then return n;

%o else return 4*A063694(Floor(n/4)) + ((n mod 4) mod 2);

%o end if; return A063694;

%o end function;

%o A004514:= func< n | 2*A063694(n) >;

%o [A004514(n): n in [0..90]]; // _G. C. Greubel_, Dec 05 2022

%o (SageMath)

%o def A063694(n):

%o if (n<2): return n

%o else: return 4*A063694(floor(n/4)) + ((n%4)%2)

%o def A004514(n): return 2*A063694(n)

%o [A004514(n) for n in range(91)] # _G. C. Greubel_, Dec 05 2022

%o (PARI) a(n) = if(n, bitand(n, 2<<bitor(1,logint(n,2)) \ 3)) << 1; \\ _Kevin Ryde_, Dec 10 2022

%o (Python)

%o def A004514(n): return (n&((1<<(m:=n.bit_length())+(m&1))-1)//3)<<1 # _Chai Wah Wu_, Jan 30 2023

%Y Cf. A053985, A063694, A063695, A088442.

%K base,easy,nonn

%O 0,2

%A _N. J. A. Sloane_

%E More terms from _Reinhard Zumkeller_, Dec 27 2003