OFFSET
1,1
COMMENTS
This appears in the problem of finding a bijection f on Z such that f(x)-x is also a bijection on Z. a(n) is the value on the natural numbers of an f satisfying the above condition as well as f(f(n)) = n. It is interesting to note that all a(n) such that a(n) > n are precisely A184119 (empirical) and ones satisfying a(n) <= n are precisely A136119 (empirical).
FORMULA
a(1) = 2 and for all i > 1 we define a(i) as follows:
Rule 1 : a(i) = j if there is some j such that j < i and a(j) = i.
Rule 2 : If Rule 1 cannot be performed then a(i) = i+2n+3 , if this rule applied n times previously.
EXAMPLE
We begin with a(1) = 2.
To calculate a(2): we first check if 2 has appeared in this sequence before. Indeed since a(1) = 2 we set a(2) = 1.
For a(3): observe that 3 has not appeared before so we can't apply Rule 1. Since we have performed rule 2 zero times before, therefore, a(3) = 3+2(0)+3 = 6.
For a(4): we cannot apply Rule 1 as 4 has not appeared before. We have applied Rule 2 one time before and hence a(4) = 4+2(1)+3 = 9.
Similarly a(5) = 5+2(2)+3 = 12.
However for a(6) we see a(3) = 6 and hence due to Rule 1, we must set a(6) = 3.
MAPLE
a:= proc() local h, t; t:=0; proc(n) option remember;
if n<3 then 3-n else h:= 3+n+2*t;
a(h):= n; t:= t+1; h fi end
end():
seq(a(n), n=1..100); # Alois P. Heinz, Jun 17 2020
MATHEMATICA
Nest[Append[#1, If[! FreeQ[#1[[All, 1]], #2], {FirstPosition[#1[[All, 1]], #2][[1]], #1[[-1, -1]]}, {#2 + 2 #1[[-1, -1]] + 3, 1 + #1[[-1, -1]]}]] & @@ {#, Length[#] + 1} &, {{2, 0}}, 62][[All, 1]] (* Michael De Vlieger, Jun 17 2020 *)
PROG
(Python)
Used = [(1, 2)]
def bfun(num):
print("a(1)=2")
for i in range(2, num + 1):
if any(i in coordinate for coordinate in Used):
for j in range(0, len(Used) + 1):
if i in Used[j]:
print("a(" + str(i) + ")=" + str(Used[j][0]))
break
else:
Used.append((i, i + 2 * len(Used) + 1))
print("a(" + str(i) + ")=" + str(i + 2 * len(Used) - 1))
bfun(70)
CROSSREFS
KEYWORD
nonn
AUTHOR
Bhavya Tiwari, Jun 17 2020
STATUS
approved