Skip to main content
added 16 characters in body
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

Here is code that generates the endpoints of the intervals

Clear[a, b]
a[1] = {{0, 2/3}}; b[1] = {{2/3, 1}};
a[n_] := a[n] = Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2), #2}} & @@@ a[n@@@a[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 21), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 21)} & @@@ b[n - 1]] // Sort
b[n_] := b[n] =Join[Flatten[= Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1), #2}} & @@@ b[n@@@b[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 12), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 12)} & @@@ a[n - 1]] // Sort

a[2]
b[2]
(* {{0, 7/24}, {73/248, 32/83}, {319/824, 27/38}} *)
(* {{27/324, 193/248}, {192/243, 719/824}, {7/8, 1}} *)

These functions are memoized so that we eliminate any recursion depth problem. (That means that every time you changed the definitions, you'll need to Clear[a, b], as I've shown.)

To convert this to the interval form desired by the OP, we do

Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@a[2]
Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@b[2]
(* {0 <= x <= 7/24, 73/248 <= x < 32/83, 319/824 <= x < 27/38} *)
(* {27/324 <= x <= 193/248, 192/243 <= x < 719/824, 7/8 <= x < 1} *)

Here is code that generates the endpoints of the intervals

a[1] = {{0, 2/3}}; b[1] = {{2/3, 1}};
a[n_] := a[n] = Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2), #2}} & @@@ a[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2)} & @@@ b[n - 1]] // Sort
b[n_] := b[n] =Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1), #2}} & @@@ b[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1)} & @@@ a[n - 1]] // Sort

a[2]
b[2]
(* {{0, 7/24}, {7/24, 3/8}, {3/8, 2/3}} *)
(* {{2/3, 19/24}, {19/24, 7/8}, {7/8, 1}} *)

These functions are memoized so that we eliminate any recursion depth problem.

To convert this to the interval form desired by the OP, we do

Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@a[2]
Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@b[2]
(* {0 <= x <= 7/24, 7/24 <= x < 3/8, 3/8 <= x < 2/3} *)
(* {2/3 <= x <= 19/24, 19/24 <= x < 7/8, 7/8 <= x < 1} *)

Here is code that generates the endpoints of the intervals

Clear[a, b]
a[1] = {{0, 2/3}}; b[1] = {{2/3, 1}};
a[n_] := a[n] = Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2), #2}} & @@@a[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1)} & @@@ b[n - 1]] // Sort
b[n_] := b[n] = Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1), #2}} & @@@b[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2)} & @@@ a[n - 1]] // Sort

a[2]
b[2]
(* {{0, 7/24}, {3/8, 2/3}, {19/24, 7/8}} *)
(* {{7/24, 3/8}, {2/3, 19/24}, {7/8, 1}} *)

These functions are memoized so that we eliminate any recursion depth problem. (That means that every time you changed the definitions, you'll need to Clear[a, b], as I've shown.)

To convert this to the interval form desired by the OP, we do

Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@a[2]
Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@b[2]
(* {0 <= x <= 7/24, 3/8 <= x < 2/3, 19/24 <= x < 7/8} *)
(* {7/24 <= x <= 3/8, 2/3 <= x < 19/24, 7/8 <= x < 1} *)
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

Here is code that generates the endpoints of the intervals

a[1] = {{0, 2/3}}; b[1] = {{2/3, 1}};
a[n_] := a[n] = Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2), #2}} & @@@ a[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 2), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 2)} & @@@ b[n - 1]] // Sort
b[n_] := b[n] =Join[Flatten[{{#1, #1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1)}, {#1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1), #2}} & @@@ b[n - 1], 1], {#1 + (#2 - #1)/2 - (#2 - #1)/2^(n + 1), #1 + (#2 - #1)/2 + (#2 - #1)/2^(n + 1)} & @@@ a[n - 1]] // Sort

a[2]
b[2]
(* {{0, 7/24}, {7/24, 3/8}, {3/8, 2/3}} *)
(* {{2/3, 19/24}, {19/24, 7/8}, {7/8, 1}} *)

These functions are memoized so that we eliminate any recursion depth problem.

To convert this to the interval form desired by the OP, we do

Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@a[2]
Prepend[#1 <= x < #2 & @@@ Rest@#, #1 <= x <= #2 & @@ First@#] &@b[2]
(* {0 <= x <= 7/24, 7/24 <= x < 3/8, 3/8 <= x < 2/3} *)
(* {2/3 <= x <= 19/24, 19/24 <= x < 7/8, 7/8 <= x < 1} *)