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.

A080116 Characteristic function of A014486. a(n) = 1 if n's binary expansion is totally balanced, otherwise zero.

This page as a plain text file.
%I A080116 #26 Sep 20 2022 09:24:07
%S A080116 1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
%T A080116 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
%U A080116 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
%N A080116 Characteristic function of A014486. a(n) = 1 if n's binary expansion is totally balanced, otherwise zero.
%C A080116 a(n) = 1 if the binary representation of n forms a valid Dyck path, or equally, a well-formed parenthesization when 1's are converted to left and 0's to right parentheses (that is, when A007088(n) is in A063171), and 0 otherwise. - _Antti Karttunen_, Aug 23 2019
%H A080116 Antti Karttunen, <a href="/A080116/b080116.txt">Table of n, a(n) for n = 0..65537</a>
%H A080116 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%H A080116 <a href="/index/Ch#char_fns">Index entries for characteristic functions</a>
%H A080116 <a href="/index/Par#parens">Index entries for sequences related to parenthesizing</a>
%e A080116 0 stands for an empty parenthesization, thus a(0) = 1.
%e A080116 2 has binary expansion "10", which corresponds with "()", thus a(2) = 1.
%e A080116 3 has binary expansion "11", but "((" is not a well-formed parenthesization, thus a(3) = 0.
%e A080116 10 has binary expansion "1010", corresponding with a well-formed parenthesization "()()", thus a(10) = 1.
%e A080116 38 has binary expansion "100110", but "())(()" is not a well-formed parenthesization, thus a(38) = 0.
%p A080116 A080116 := proc(n) local c,lev; lev := 0; c := n; while(c > 0) do lev := lev + (-1)^c; c := floor(c/2); if(lev < 0) then RETURN(0); fi; od; if(lev > 0) then RETURN(0); else RETURN(1); fi; end;
%t A080116 A080116[n_] := (lev = 0; c = n; While[c > 0, lev = lev + (-1)^c; c = Floor[c/2]; If[lev < 0, Return[0]]]; If[lev > 0, Return[0], Return[1]]); Table[A080116[n], {n, 0, 104}] (* _Jean-François Alcover_, Jul 24 2013, translated from Maple *)
%o A080116 (Sage)
%o A080116 def A080116(n) :
%o A080116     lev = 0
%o A080116     while n > 0 :
%o A080116         lev += (-1)^n
%o A080116         if lev < 0: return 0
%o A080116         n = n//2
%o A080116     return 0 if lev > 0 else 1
%o A080116 [A080116(n) for n in (0..104)] # _Peter Luschny_, Aug 09 2012
%o A080116 (PARI) A080116(n) = { my(k=0); while(n, k += (-1)^n; n >>= 1; if(k<0, return(0))); (0==k); }; \\ _Antti Karttunen_, Aug 23 2019
%Y A080116 Cf. A014486, A063171, A080110, A080111, A080300, A080301.
%K A080116 nonn,base
%O A080116 0,1
%A A080116 _Antti Karttunen_, Feb 11 2003
%E A080116 Examples added by _Antti Karttunen_, Aug 23 2019