The setting
Let's consider a single elimination tournament with $n=2^r$ teams.
Usually the playoff tree is seeded in a way that the two top teams can meet no earlier than in the finals. Top 4 can't eliminate each other before semifinals etc.
The playoff bracket that guarantees these properties is the one where the top team gets paired with the last team, second with second-to-last etc. To pair the second round matchups, rank the first round pairs according to the higher seed and use the same rule.
In the end the playoff tree of 16 teams should look like this:
1
(p1) wp1
16
(p1.2) wp1.2
9
(p8) wp8
8
(p1.3) wp1.3
5
(p5) wp5
12
(p4.2) wp4.2
13
(p4) wp4
4
(p1.4) wp1.4
3
(p3) wp3
14
(p3.2) wp3.2
11
(p6) wp6
6
(p2.3) wp2.3
7
(p7) wp7
10
(p2.2) wp2.2
15
(p2) wp2
2
With p[p] I mark a pair, a wp[p] is the winner of the pair p[p].
A good playoff tree is the one where any subtree has the same properties as described necessary for the whole tree. For example, consider this subtree in the upper tree:
3
(p3) wp3
14
(p3.2) wp3.2
11
(p6) wp6
6
The two higher seeded teams (3 and 6) as on the very opposite sides of the bracket and can only meet at the latest stage. The strongest team here (3) is paired against the weakest of these (14).
The question
Let's number the slots in a round from top to the bottom.
Given s(A) - the seeding of team A and n - the number of teams, what will be the function that would return i - the number of slot for this team in the bracket.
What would be the inverse function (given slot number, return the teams seed - useful to find the opponent).
Examples
In a round of 16 (n=16) we must place team with seed s=13 in the bracket. The slot number must be i=7 - that team must be the first in the 4th pair.
For the inverse function, given that we placed s=13 in the 4th pair, we must find the opponent which will be the second team in that pair. So, given n=16 and the slot number i=8 we must get s=4 - seed of the 13s opponent.
I am looking for a function that would be applicable for arbitrary n instead of hardcoding the seed-slot relations for limited number of n values.
A note
This is a problem that is usually solved programmatically either by hardcoding an ordering or by an iterative process. I am interested if it's replacable with a single mathematical function that you could plug in a number and get another one out for any n. The relation between seeds and slots is a uniquely (if you always start with 1st seed) defined bijection so obviously you could just say that the function exists and let's call it pOff(s).
As you could probably guess, I am interested if this function is expressable with another, previously defined functions (special functions, complex numbers etc. is ok if necessary).