[seqfan] Re: Can we write this definition in a better way?

C.R. Drost c.r.drost at gmail.com
Mon Sep 23 19:02:45 CEST 2019


What a strange sequence... multiple layers of self-reference in there. Not
sure if I see a better way to simplify it.

Quick and dirty Haskell implementation:

-- terms that contain an index and a value, equated/compared only over
their value
data IV = IV {index :: Int, value :: Int} deriving Show
instance Eq IV where { IV _ v1 == IV _ v2 = v1 == v2}
instance Ord IV where { compare (IV _ v1) (IV _ v2) = compare v1 v2 }

-- update a pair containing a second-largest and largest element with a new
element
update :: Ord x => (x, x) -> x -> x
update old@(penultimate, ultimate) new
  | ultimate < new     = (ultimate, new)
  | ultimate == new    = (penultimate, new)
  | penultimate <= new = (new, ultimate)
  | otherwise          = old

mySequence = 1 : 2 : go (IV 1 1, IV 2 2) 2 3 where
  go old last idx = val : go (update old newIV) val (idx + 1)
    where
      penultimateOrUltimate = if even last then fst old else snd old
      val = idx - index penultimateOrUltimate
      newIV = IV idx val

One interesting thing is that since the definition of `val` above is a
difference of two indexes, this should be translation-invariant; if you
instead defined a(0) = 1, a(1) = 2 you should get the same sequence shifted
by 1 from that recurrence rule.

But yeah if you eliminate that stuff about choosing either the
second-largest or the largest based on some parity, then you would only
have the ultimate one and you would not need to start with two terms;
choosing a(1) = 1 gives the sequence [1, 1, 1, 1, 1, ...] which is not very
interesting. So you can't simplify away the need for choosing between the
two. You can maybe simplify away that the choice depends recursively on the
prior result, instead just choosing `if even idx` above to eliminate one
part of the self-reference to get a simpler sequence, this leads to a
sequence

1,2,2,1,1,3,4,1,3,3,1,5,6,1,3,3,5,5,1,7,8,1,3,3,5,5,7,7,1,9,10,...

which indeed seems much simpler: the evens showing up here are 4, 6, 8, 10,
... and they are spaced by successive even spacings, a^{-1}(i) - a^{-1}(i -
1) = i eventually, suggesting that maybe you can tweak it so that those
appear on square or triangular numbers or so. And the pattern seems to be
pretty robust then of (1, 3, 3, 5,5, ... 2n-3, 2n-3, 1, 2n-1, 2n) repeated
over and over.

With the extra self-reference I am not sure if I see a good way to simplify
any of it any further though.

-- Chris

On Sun, Sep 22, 2019 at 12:30 PM Ali Sada via SeqFan <seqfan at list.seqfan.eu>
wrote:

>
> Hi Everyone,
>
>
>
> Please see the sequence below. I just want to see if thereis there is a
> better way to write its definition. OEIS editors usually strugglewith my
> language, and I would really appreciate it if you could help me maketheir
> job easier.
>
> The sequence:
>
> 1 ,2 ,2 ,3 ,1 ,2 ,1 ,4 ,5 ,1 ,2 ,4 ,1 ,5 ,1 ,2 ,5 ,1 ,2 ,8 ,4,5 ,3 ,4 ,3
> ,6 ,1 ,8 ,3 ,2 ,5 ,4 ,7 ,6 ,2 ,3 ,9 ,1 ,2 ,12 ,4 ,5 ,3 ,4 ,8 ,9 ,7,8 ,3 ,10
> ,1 ,12 ,3 ,2 ,5 ,4 ,7 ,6 ,9 ,8 ,11 ,10 ,2 ,3 ,13 ,1 ,2 ,16 ,4 ,5 ,3 ,4,8 ,9
> ,7 ,8 ,12 ,13 ,11 ,12 ,3 ,14 ,1 ,16 ,3 ,2 ,5 ,4 ,7 ,6 ,9 ,8 ,11 ,10 ,13
> ,12,15 ,14 ,2 ,3,……
>
>
>
> The definition:
>
> “a(1)=1;
>
> a(2)=2;
>
> a(n)=n-m1, if a(n-1) is odd;
>
> a(n)=n-m2, if a(n-1) is even;
>
> m1 is the most recent position of the largest term up toa(n-1);
>
> m2 is the most recent position of the second largest term upto a(n-1)”
>
>
>
> Example 1: When n=10, a(9) is odd, the largest term up to thatpoint is 5.
> The most recent position of 5 is 9. a(10)=10-9=1
>
> Example 2: When n=17, a(16) is even. The second largest termup to that
> point is 4. The most recent position of 4 is 12. a(17)=17-12=5
>
> Thank you very much in advance.
>
>
>
> Best,
>
>
>
> Ali
>
>
> --
> Seqfan Mailing list - http://list.seqfan.eu/
>



More information about the SeqFan mailing list