(Edit 1: Below, I made changes to the code.)
(Edit 3: I made $1/2^{2+1}$ and $1/2^{2}$, $1/2^{1+1}$ and $1/2^{1}$. I apologize for my stupidity.)
A[2] = Reduce[a[1, 1] <= x <= (a[1, 1] + a[1, 2])/2 - 1/2 (1/2^(21 + 1)) (a[1, 2] - a[1, 1]) ||
(a[1, 1] + a[1, 2])/2 + 1/2 (1/2^(21 + 1)) (a[1, 2] - a[1, 1]) <= x < a[1, 2] ||
(b[1, 1] + b[1, 2])/2 - 1/2 (1/2^(21)) (b[1, 2] - b[1, 1]) <= x < (b[1, 1] + b[1, 2])/2+
1/2 (1/2^(21)) (b[1, 2] - b[1, 1]), {x}] (*A2*)
B[2] = Reduce[b[1, 1] <= x <= (b[1, 1] + b[1, 2])/2 - 1/2 (1/2^(21)) (b[1, 2] - b[1, 1]) ||
(b[1, 1] + b[1, 2])/2 + 1/2 (1/2^(21)) (b[1, 2] - b[1, 1]) <= x < b[1, 2] ||
(a[1, 1] + a[1, 2])/2 - 1/2 (1/2^(21 + 1)) (a[1, 2] - a[1, 1]) <= x < (a[1, 1] + a[1, 2])/2 +
1/2 (1/2^(21 + 1)) (a[1, 2] - a[1, 1]), {x}] (*B2*)
a[x_, 1, i_] := A[x][[3^(i - 1)]][[1]]
(*If i is a number in [1,3^(x-1)], then a[x,1,i] is the Lowerbound of the 3^(i-1)th interval of A_n*)
a[x_, 2, i_] := A[x][[3^(i - 1)]][[5]]
(*If i is a number in [1,3^(x-1)], then a[x,1,i] is the Upperbound of the 3^(i-1)th interval of A_n*)
b[x_, 1, i_] := B[x][[3^(i - 1)]][[1]]
(*If i is a number in [1,3^(x-1)], then b[x,1,i] is the Lowerbound of the 3^(i-1)th interval of B_n*)
b[x_, 2, i_] := B[x][[3^(i - 1)]][[5]]
(*If i is a number in [1,3^(x-1)], then b[x,1,i] is the Upperbound of the 3^(i-1)th interval of B_n*)
A[s_, i_] := Reduce[a[s, 1, i] <= x <= (a[s, 1, i] + a[s, 2, i])/2 - 1/2 (1/2^(2 + 1s))
(a[s, 2, i] - a[s, 1, i]) || (a[s, 1, i] + a[s, 2, i])/2 + 1/2 (1/2^(2 + 1s))
(a[s, 2, i] - a[s, 1, i]) <=x < a[s, 2, i] || (b[s, 1, i] + b[s, 2, i])/2 -
1/2 (1/2^(2s-1)) (b[s, 2, i] - b[s, 1, i]) <= x < (b[s, 1, i] + b[s, 2, i])/2
+ 1/2 (1/2^(2s-1)) (b[s, 2, i] - b[s, 1, i]), {x}]
(*Changes the 3^(i-1)th interval of A_n using the description in above the attempt.*)
B[s_, i_] := Reduce[b[s, 1, i] <= x <= (b[s, 1, i] + b[s, 2, i])/2 - 1/2 (1/2^(2s-1))
(b[s, 2, i] - b[s, 1, i]) || (b[s, 1, i] + b[s, 2, i])/2 + 1/2 (1/2^(2s-1))
(b[s, 2, i] - b[s, 1, i]) <= x <b[s, 2, i] || (a[s, 1, i] + a[s, 2, i])/2 -
1/2 (1/2^(2 + 1s)) (a[s, 2, i] - a[s, 1, i]) <= x < (a[s, 1, i] + a[s, 2, i])/2
+ 1/2 (1/2^(2 + 1s)) (a[s, 2, i] - a[s, 1, i]), {x}]
(*Changes 3^(i-1)th interval of A_n into three intervals using the description above the attempt.*)