%I #11 Oct 25 2021 11:27:14
%S 0,0,0,0,1,0,1,-1,1,0,0,0,0,-1,0,0,0,0,0,-1,0,0,1,0,1,0,1,-1,1,-1,0,
%T -1,0,-1,1,-1,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,-1,1,0,0,-1,0,0,0,0,0,-1,
%U 1,-1,1,-1,1,0,0,-1,1,0,1,0,1,0,0,-1,1,-1,1,-1,1,-1,0,-1,1,-1,0,-1,0,0,1,0,1,0,1,0,0,0,1,-1,1,0,1,0,0,-1,1,-1,0,0,0,0,0,0,1,-1,1,-1,1,-1,0,-1,1,0,1,-1,0,-1,1,-1,0,0,0,-1,1,0,1,0,1,0,0,0,0,-1,0,0,1,-1,1,-1,1,-1,0,0,1,-1,1,-1,1,0,1,-1,1,0,0,-1,1,0,1,-1,1,-1,1,0,1,0,0,-1,0,0,1,0,0,-1,1,-1,0,-1,0,0,1,0,0,0,0,-1,1,0
%N Sqrt(3)+1-adic expansion of 4, in balanced ternary alphabet.
%C Starting with the number 4, repeatedly "carry" into higher terms of the sequence by scaling and shifting the sequence (-2, -2, 1). For odd numbers, retain sign by scaling the carry by half its magnitude, rounded toward 0. See examples for iterates.
%C Also appears to work with initial sequences [2, 0, 1, -1, 1, -1, ...] (repeating 1 and -1), [0, 0, 2, -2, 2, -2] (repeating 2 and -2), and [0, 0, 0, 0, 1, -2, 3, -4] (alternating naturals).
%C Sequence name is by analogy with p-adic numbers and due to the carry sequence (-2, -2, 1) corresponding to the polynomial x^2 - 2x - 2, which has root sqrt(3)+1.
%C 1 only occurs at even positions, -1 occurs only at odd positions.
%C First 8192 digits appear to be aperiodic.
%H Ben Conner, <a href="https://zenzicubic.us/math/polynomial-counting-two-2s">Polynomial Counting: Two 2’s</a>
%e First few iterates of carry, starting from expansion "4":
%e 4;
%e 0, -4, 2;
%e 0, 0, 6, -2;
%e 0, 0, 0, -8, 3;
%e 0, 0, 0, 0, 11, 4;
%e 0, 0, 0, 0, 1, -14, 5;
%e 0, 0, 0, 0, 1, 0, 19, -7;
%e 0, 0, 0, 0, 1, 0, 1, -25, 9;
%e 0, 0, 0, 0, 1, 0, 1, -1, 33, -12;
%e In the limit, this produces the sequence above.
%o (Haskell)
%o a347411_iterates = iterate (doubleBorrow []) (4:repeat 0) where
%o doubleBorrow zs (x:y:z:xs)
%o | abs x >= 2 = let (q, r) = quotRem x 2 in foldl (flip (:)) (r : y-x+r : z+q : xs) zs
%o | otherwise = doubleBorrow (x:zs) (y:z:xs)
%o a347411 n = (a347411_iterates !! (n+1)) !! n
%K sign,base
%O 0
%A _Ben Conner_, Aug 30 2021
|