[Question]
  [
Consider the following number sequence:
> 
> \$ 0, \frac{1}{2}, \frac{1}{4}, \frac{3}{4}, \frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}, \frac{1}{16}, \frac{3}{16}, \frac{5}{16}, \frac{7}{16}, \frac{9}{16}, \frac{11}{16}, \frac{13}{16}, \frac{15}{16}, \frac{1}{32}, \frac{3}{32}, \frac{5}{32}, \dots \$
> 
> 
> 
It enumerates all binary fractions in the unit interval \$ [0, 1) \$.
(To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)
### Task
Write a program (complete program or a function) which...
Choose one of these behaviors:
* Input n, output nth element of the sequence (0-indexed or 1-indexed);
* Input n, output first n elements of the sequence;
* Input nothing, output the infinite number sequence which you can take from one by one;
### Rule
* Your program should at least support first 1000 items;
* You may choose to output decimals, or fractions (built-in, integer pair, strings) as you like;
	+ Input / Output as binary digits is not allowed in this question;
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest codes win;
* Standard loopholes disallowed.
### Testcases
```
input output
1     1/2     0.5
2     1/4     0.25
3     3/4     0.75
4     1/8     0.125
10    5/16    0.3125
100   73/128  0.5703125
511   511/512 0.998046875
512   1/1024  0.0009765625
```
These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.
### Read More
* **[OEIS A006257](https://oeis.org/A006257)**
	+ Josephus problem: \$ a\_{2n} = 2a\_n-1, a\_{2n+1} = 2a\_n+1 \$. (Formerly M2216)
	+ 0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...
* **[OEIS A062383](https://oeis.org/A062383)**
	+ \$ a\_0 = 1 \$: for \$ n>0 \$, \$ a\_n = 2^{\lfloor log\_2n+1 \rfloor} \$ or \$ a\_n = 2a\_{\lfloor \frac{n}{2} \rfloor} \$.
	+ 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...
* > 
> [A006257](https://oeis.org/A006257)(n)/[A062383](https://oeis.org/A062383)(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006
> 
> 
>
  
[Answer]
# [Haskell](https://www.haskell.org/), 25 bytes
```
pred.until(<2)(/2).(+0.5)
```
[Try it online!](https://tio.run/##BcExDoAgDADAr3RwgBgrkrjJS9SBICgRSCP4fevdZevtU@JgNqbHH/iWFpNYtBSjlih6hbPkbGMBA/TE0qCDbAkCrBOiVjt/LiR7Vh4c0Q8 "Haskell – Try It Online")
Outputs decimals, one-indexed without the initial zero term. 
Adds 0.5 to the input, then halves until the results is below 2, then subtracts 1. Using a pointfree expression saves 1 bytes over
```
f n=until(<2)(/2)(n+0.5)-1
```
[Answer]
# Java 10, ~~68~~ 64 bytes
First try at code golf!
Option 1: find the *n*-th element (1-indexed)
-4 bytes thanks to [@Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
```
n->{int x=0;for(;n>>++x!=1;);return((~(1<<x)&n)*2.+1)/(1<<x+1);}
```
This is an anonymous method that finds the *n*-th term by removing the most significant bit from *n*, doubling it and adding one, then dividing by the next highest power of 2.
[Try it online!](https://tio.run/##XZCxTsMwEIb3PsWRAdlYDYSBASd5A7p0RAwmcSuX9BLZlyqoCq8ezqkXWHw@@/f3/76TuZjtqf1ams6EAG/G4XUD4JCsP5jGwi62AG0/fnYWGsE3gFLz4bzhJZAh18AOECpYcFtfo2CqnvSh90JjXSs13VWFltpbGj0K8SOKspzkPcqH51wV8nHteaPnRUfmwFbMTOhL71o4cy6xJ@/w@P4BRt5CRYto59i70FxKKF64KpUEAGQDCbfmjYn/pl7RN0Wk4DBSerj/DmTPeT9SPrApiSz@L1OrRmWvkCXkf2GHAvM4pchKY5qXXw)
Code walkthrough:
```
n->{                      // builds anonymous function with input n
int x=0;                  // stores floor of log(n) (base 2) for most significant digit
for(;n>>++x!=1;);         // calculates floor of log(n) by counting right shifts until 1
return((~(1<<x)&n)        // removes most significant digit of n
*2.+1)                     // multiplies 2 and adds 1 to get the odd numerator
/(1<<x+1);}               // divides by the next highest power of 2 and returns`
```
Will edit if it's necessary to print the final value instead of returning it.
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), ~~5~~ 4 bytes
```
╫\╨]
```
[Try it online!](https://tio.run/##y00syUjPz0n7///R1NUxj6auiP3/39TQEAA "MathGolf – Try It Online")
## How it would look like with the operator working correctly
```
╫\)╨]   (")" adds 1 to TOS, making rounding behave as expected)
```
[Try it online!](https://tio.run/##y00syUjPz0n7/z/70dTVQLwi9v9/U0NDAA "MathGolf – Try It Online")
## Explanation
```
╫     Left-rotate all bits in input
 \    Swap top two elements on stack, pushing the input to the top
  ╨   Round up to nearest power of 2
   ]  Wrap in array (just for pretty printing)
```
I took my inspiration from [this question](https://codegolf.stackexchange.com/questions/83817/ninja-assassins-which-ninja-stays-alive) to solve the problem, my "own" solution was around 10-12 bytes I think.
I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.
[Answer]
# Java 10, ~~89~~ ~~85~~ ~~70~~ ~~69~~ 68 bytes
```
v->{for(float j,t=2;;t*=2)for(j=1;j<t;j+=2)System.out.println(j/t);}
```
Port of [*@Emigma*'s 05AB1E answer](https://codegolf.stackexchange.com/a/172172/52210), so outputs decimals indefinitely as well.  
-15 bytes thanks to *@Arnauld*.
[Try it online.](https://tio.run/##LY5BDoIwEEX3nGKWrQpGthVvIBsSN8ZFLWBaS0vo0MQQzl5bZTOTeZn8/xT3PFftOwjNnYMrl2bJAKTBbuq56KBOJ4C3sgVBbml5yiJbszgccpQCajBQQfD5ZentRHptOYI6YFUyhruqpImq6sTUGZnaR9B8HHZDYWcsxim2aUPUESlbA0u54/zUMXeL/5UPUY00GJ9f9wdw@vcyhSBm1npTWsMX)
**Explanation:**
```
v->{                      // Method with empty unused parameter and no return-type
  for(float j,t=2;;       //  Loop `t` from 2 upwards indefinitely,
                   t*=2)  //  doubling `t` after every iteration
    for(j=1;j<t;          //   Inner loop `j` in the range [1, `t`),
                j+=2)     //   in steps of 2 (so only the odd numbers)
      System.out.println( //    Print with trailing new-line:
        j/t);}            //     `j` divided by `t`
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 19 bytes
```
{($_+.5)/2**.msb-1}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WkMlXlvPVFPfSEtLL7c4Sdew9n9xYqVCGlBcUy8tt0RDXVXP0CBNXVMhLb9IwVBHwUhHwVhHwURHwdAAhIGEqaEhiDCy/g8A "Perl 6 – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 30 bytes
```
n->(n+.5)/n.highestOneBit(n)-1
```
[Try it online!](https://tio.run/##NU7BSsNAEL3nK4ZCYNc0KxX0YNpCiwgexEO9SQ9rsptOTGaX3UmhSL89bq0ehjePefPe6/RRl13zNeHgXWDoElcjY6/sSDWjI3VTZXWvY4RXjfSdAfjxs8caImtOcHTYwJBOYscBqf3Ygw5tlHCRAry7J5f05vnPbvlCbFoT1mBhBROVa0GFupe3pA7YHkzkNzJbZEGyXEzVr4d1QSAxYPpYVAmWCR/SUhT/MQC7U2QzKDey8qkHWzGjVX7XPEIec5rNAedglfa@P23itZNAKa8J5@wy5@kH "Java (JDK 10) – Try It Online")
Returns the nth item in the sequence.
This answer is originally a succession of golfs of [TCFP's Java answer](https://codegolf.stackexchange.com/a/172204/16236). In the end, the golfs didn't look like the original answer anymore (though the math used is the same) so I decided to post the golfs as a separate answer instead of simply commenting on the TCFP's answer. So if you like this answer, go upvote [TCFP's answer](https://codegolf.stackexchange.com/a/172204/16236) as well! ;-)
Intermediate golfs were:
```
n->{int x=0;for(;n>>++x!=1;);return((~(1<<x)&n)*2.+1)/(1<<x+1);} // 64 bytes (TCFP's answer when I started golfing)
n->{int x=0;for(;n>>++x!=1;);x=1<<x;return((~x&n)*2.+1)/x/2;}    // 61 bytes
n->{int x=n.highestOneBit(n);return((~x&n)*2.+1)/x/2;}           // 54 bytes
n->{int x=n.highestOneBit(n);return((~x&n)+.5)/x;}               // 50 bytes
n->((n&~(n=n.highestOneBit(n)))+.5)/n                            // 37 bytes
n->(n-(n=n.highestOneBit(n))+.5)/n                               // 34 bytes
n->(n+.5)/n.highestOneBit(n)-1                                   // 30 bytes, current score
```
[Answer]
# [Python 3](https://docs.python.org/3/), 33 bytes
```
lambda n:(8*n+4)/2**len(bin(n))-1
```
[Try it online!](https://tio.run/##DcdBDkAwEAXQq8xypoi0LETiJFi0oTThk8bG6Ye3e/f77BcajcOkhz/D4gk9dwZFK7Uz5ljBIYEhUlm9c8JDPMb/FK9MoATKHtvKtnRWZtEP "Python 3 – Try It Online")
Outputs decimals, one-indexed without the initial zero term.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~11~~ 8 bytes
Saved 3 bytes thanks to *Kevin Cruijssen*.
```
∞oDÅÉs/˜
```
[Try it online!](https://tio.run/##yy9OTMpM/f//Uce8fJfDrYc7i/VPz/n/HwA "05AB1E – Try It Online")
**Explanation**
```
∞         # start an infinite list [1...
 o        # calculate 2**N
  D       # duplicate
   ÅÉ     # get a list of odd numbers up to 2**N
     s/   # divide each by 2**N
       ˜  # flatten
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
Bṙ1Ḅ,æċ2$
```
[Try it online!](https://tio.run/##ASkA1v9qZWxsef//QuG5mTHhuIQsw6bEizIk/8OH4oKsR///cmFuZ2UoMTAwKQ "Jelly – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 40 bytes
```
for($i=2;;$i*=2){1..$i|?{$_%2}|%{$_/$i}}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py2/SEMl09bI2lolU8vWSLPaUE9PJbPGvlolXtWotkYVSOurZNbW/v8PAA "PowerShell – Try It Online")
Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.
Starts by setting `$i=2`, then enters a `for` loop. Each iteration, we construct a range from `1..$i` and pull out the odd values with `|?{$_%2}`. Those are fed into their own inner loop, where we divide each to get the decimal `|%{$_/$i}`. Those are left on the pipeline and output when the pipeline is flushed after every `for` iteration. Each iteration we're simply incrementing `$i` by `$i*=2` to get the next go-round.
[Answer]
## Haskell, ~~35~~ 32 bytes
Edit: -3 bytes thanks to @Delfad0r.
```
[(y,2^x)|x<-[1..],y<-[1,3..2^x]]
```
This is an infinite list of integer pairs.
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzP1qjUscorkKzpsJGN9pQTy9WpxLE0DHW0wMKx8b@z03MzFOwVSgoyswrUVBRKEnMTlUwMlBI@/8vOS0nMb34v25yQQEA "Haskell – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 40 bytes
```
s=(1,2):[(i*2+u,j*2)|(i,j)<-s,u<-[-1,1]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v9hWw1DHSNMqWiNTy0i7VCdLy0izRiNTJ0vTRrdYp9RGN1rXUMcwNvZ/bmJmnoKtQm5igW@8QkFRZl6JgopCSWJ2qoKhgYFC8X8A "Haskell – Try It Online")
Infinite sequence as pairs of integers (starting from `(1,2)`).
Quite a bit longer than [@nimi's answer](https://codegolf.stackexchange.com/a/172176/82619), but the approach is completely different, so I decided to post it anyway.
This solution is based on the following observation.
Consider the infinite sequence
$$
\left\{\frac{1}{2},\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$
and apply the following steps.
* Replace every number \$\frac{i}{j}\$ in the sequence with the list \$\left\{\frac{2i-1}{2j},\frac{2i+1}{2j}\right\}\$:
$$
\left\{\left\{\frac{1}{4},\frac{3}{4}\right\},\left\{\frac{1}{8},\frac{3}{8}\right\},\left\{\frac{5}{8},\frac{7}{8}\right\},\left\{\frac{1}{16},\frac{3}{16}\right\},\ldots\right\}
$$
* Join all the lists into a single sequence:
$$
\left\{\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$
* Add \$\frac{1}{2}\$ at the beginning of the sequence:
$$
\left\{\frac{1}{2},\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$
Notice how you get back to the sequence you started with!
The solution exploits this fact (together with Haskell's laziness) to compute the sequence `s`.
[Answer]
# [R](https://www.r-project.org/), ~~42~~ 41 bytes
```
function(n)2*c(y<-2^(log2(n)%/%1),n-y+.5)
```
[Try it online!](https://tio.run/##DYnRCsIwDAB/JWwMEu3UFnwZ/slQGLObhZmWLg769TVwD8ddroL7lNJW0A72Zury41lCZGRypxnLo3cv3OLqNHTXzpLhvpwvd6pE7WjcYJ/QQvbfeHiQj4cl5F00SYTVCwSF1Rs27wbSpLf@AQ "R – Try It Online")
*-1 byte thanks to Robin Ryder*
Returns a pair `Denominator,Numerator`. Uses the formula
\$\begin{equation}N = 2\times\left(n-2^{\lfloor \log\_2(n)\rfloor}\right)+1\end{equation}\$ from the Josephus sequence and \$\begin{equation}D = 2^{\lfloor \log\_2(n)\rfloor+1}\end{equation}\$ from the other sequence. Happily we are able to re-use the denominator as the two formulas have quite a lot in common!
[Answer]
# Python 2 - ~~68~~ 66 bytes
*-2 bytes thanks to Kevin*
```
from math import*
def g(n):a=2**floor(log(n,2));print(n-a)*2+1,2*a
```
[Try it Online!](https://tio.run/##DcgxDoMwDADAnVd4tF0Y8AjiMZFKgiViR1aWvj7Njdd@/XGTMXJ4hZr6A1qbR@fle2coaHSkS5jz6x74@pxViM4Wah1tS8Ty2VfhNLIHKKhBJCs3ztzpWGAqqDT@)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~53~~ 51 bytes
* Saved two bytes thanks to [mypetlion](https://codegolf.stackexchange.com/users/65255/mypetlion); reusing default parameters to reset `n`.
```
def f(m=2,n=1):n<m and print(n/m)&f(m,2+n)or f(m+m)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI9fWSCfP1lDTKs8mVyExL0WhoCgzr0QjTz9XUw0oq2OknaeZXwRSqJ2r@T9NQ/M/AA "Python 3 – Try It Online")
[Answer]
# [Racket](https://racket-lang.org/), ~~92~~ 91 bytes
```
(define(f k(m 2)(n 1))(if(> k 0)(if(=(+ n 1)m)(f(- k 1)(+ m m))(f(- k 1)m(+ n 2)))(/ n m)))
```
[Try it online!](https://tio.run/##RcxLDsIwDATQq4zEAlsItU5bPgu4S4AERamjqmXD6YubDbvxG9uzf@bwWXejL2/MdWgefgkrvUJMJVBEJoVjKhBmSpHuyGhrutEBGytTpKOxsIlC@Q9adxwbNRasYvudlmn0X5D6CRF7aiFw6NBjwAlnXHCFGArEQTpIDxm20x8 "Racket – Try It Online")
* Saved a byte thanks to [Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) -- removing superfluous whitespace.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 8 bytes
```
BnWGEy-Q
```
[Try it online!](https://tio.run/##y00syfn/3ykv3N21Ujfw/39TQ0MA "MATL – Try It Online")
Returns Numerator, then Denominator. Uses the same method as [my R answer](https://codegolf.stackexchange.com/a/172213/67312), although it's a bit more efficient.
Explanation, with input `5`:
```
           # implicit input 5
B          # convert to array of bits
           # STACK: [[1 0 1]]
n          # length (place of Most Significant Bit)
           # STACK: [3]
W          # elementwise raise 2^x
           # STACK: [8]
G          # paste input
           # STACK: [8, 5]
E          # double
           # STACK: [8, 10]
y          # copy from below
           # STACK: [8, 10, 8]
-          # subtract
           # STACK: [8, 2]
Q          # increment
           # STACK: [8, 3]
           # implicit end of program, display stack contents
```
[Answer]
# [Factor](https://factorcode.org/), 52 bytes
```
{ 1/2 } [ dup stack. dup 1 v+n append 2 v/n t ] loop
```
[Try it online!](https://tio.run/##HckxCsJAEAXQq/w@kJCUegCxSSNWYjFsRpRsZsfZyUIInn1FuwfvQcGT1evlPJ4OmNmEIxbyZ1v4Nxlq7L6pvcSR@b2yBM441h19N@CDG6ZVkZ3C3P7ZozQCUmWZMKB0AscdMSWtITJZ/QI "Factor – Try It Online")
Prints each fraction on its own line forever. Keeps track of the array of all terms with equal denominator.
```
{ 1/2 }         ! Push the initial array
[ ... t ] loop  ! Loop forever:
  dup stack.    !   Print all fractions separated by a newline
  dup 1 v+n     !   Copy and add 1 to all fractions
  append 2 v/n  !   Join and halve all fractions
```
[Answer]
# [Shakespeare Programming Language](https://github.com/TryItOnline/spl), 426 bytes
```
,.Ajax,.Ford,.Act I:.Scene I:.[Exeunt][Enter Ajax and Ford]Ajax:You be the sum ofyou a cat.Ford:You cat.Scene V:.Ford:Is twice you nicer I?If solet usScene X.You be twice you.Let usScene V.Scene X:.Ford:Remember twice you.You be the sum oftwice the remainder of the quotient betweenI you a cat.Open heart.You big big big big big cat.Speak thy.Recall.Open heart.You be twice the sum ofa cat a big big cat.Speak thy.Let usAct I.
```
[Try it online!](https://tio.run/##bZFNasMwEIWvMgcIOoA3IYsUBIVCAiElZKHIz4lbW3KlEUlO7@onxgV3IZifN9/MQ37oxnElNl/qsRJv1tUx1kyyEnsNgxSctg8Ew@fT1jAcJSkpU1NSn1NWfdpAFxDfQD70ZJtnLCjSijMy91NSkIeqVKUnvrcalNQmBo7kWjbkbQem4Iv6KCb6pBXvf9qHF/T4gu7Qo79E1CxfXFdaKXfoVWvqKLdNLvwEyy0MxwG@A0bSbOVjgKEblOOCbK@Ll00OUN8R9hQ7aNV1i7nJynxQ5sct/2OK3fwrYhx/AQ "Shakespeare Programming Language – Try It Online")
Outputs the sequence infinitely as both numbers separated by a space, with each item being separated by a newline.
[Answer]
# [Python 2](https://docs.python.org/2/), 44 bytes
```
def f(n):m=2**len(bin(n))/4;return 2*n-m+1,m
```
[Try it online!](https://tio.run/##DcdBCoAgEAXQq8xSzQglCIoOU6Q1kL8YbNHpp97u3W89LkTVLWXKBnYsc3TuTDAr47/t@klSfQQUHdrSBF80X0JMDJIFezLBh8GOtzAqsc@GreoH "Python 2 – Try It Online")
Function returns a tuple of (numerator, denominator). An input of 0 is not handled (it was optional).
[Answer]
# Excel ~~48~~ 28 Bytes
Saved 20 bytes (!) thanks to tsh
```
=(A1+0.5)/2^INT(LOG(A1,2))-1
```
~~=MOD(A1+0.5,2^(INT(LOG(A1,2))))/2^INT(LOG(A1,2))~~
Assumes value in A1, output is in decimal.
If you want the output to be in fraction, you can create a custom format for the output cell as "0/###0" and it will show it as fraction.
**Explanation:**
Difficult to explain, since there is a shortcut taken to get to this formula.
Basically the numerator is a bit shift left of the input, and the denominator is the next power of 2 higher than the number input.
I originally started with Excel built in functions for BITLSHIFT and BITRSHIFT, but they will shift the entire 48 bits which is not what you want. The functions DEC2BIN (and BIN2DEC) have a limit of -512 to 511 (10 bits) so this wouldn't work. Instead I had to rebuild the number with a modulus of the original number, then times two, then add 1 (since the left digit would always be 1 before a shift).
```
=MOD(A1                        Use MOD for finding what the right digits are
       +0.5                    this will later add the left "1" to the right digits
           ,2^INT(LOG(A1,2)))) Take Log base 2 number of digits on the right
                               this creates the numerator divided by 2 (explained later)
/ 2^INT(LOG(A1,2))             The denominator should be 2^ (Log2 + 1) but instead of 
                               adding a 1 here, we cause the numerator to be divided by 2 instead
                               This gives us a fraction.  In the numerator, we also added .5
                               instead of 1 so that we wouldn't need to divide it in both the
                               numerator and denominator
Then tsh showed how I could take the int/log out of the mod and remove it from numerator/denominator. 
```
Examples:
[![enter image description here](https://i.stack.imgur.com/509Xa.png)](https://i.stack.imgur.com/509Xa.png)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 22 bytes
```
2^Mod[Log2[2#+1],1]-1&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfKM43PyXaJz/dKNpIWdswVscwVtdQ7b9LfnRAUWZeSXSegq6dQlp0XmysjkJ1no6CIRAZGNTG/gcA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
## C++, ~~97~~ ~~75~~ 71 bytes
-26 bytes thanks to tsh, ceilingcat, Zacharý
```
float f(int i){float d=2,n=1;while(--i)n=d-n==1?d*=2,1:n+2;return n/d;}
```
Testing code :
```
std::cout << "1\t:\t" << f(1) << '\n';
std::cout << "2\t:\t" << f(2) << '\n';
std::cout << "3\t:\t" << f(3) << '\n';
std::cout << "4\t:\t" << f(4) << '\n';
std::cout << "10\t:\t" << f(10) << '\n';
std::cout << "100\t:\t" << f(100) << '\n';
std::cout << "511\t:\t" << f(511) << '\n';
std::cout << "512\t:\t" << f(512) << '\n';
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 13 bytes
```
ṁz*İ1zR:1İ2İ½
```
[Try it online!](https://tio.run/##yygtzv7//@HOxiqtIxsMq4KsDI9sMDqy4dDe//8B "Husk – Try It Online")
Abuses the built in sequences to the fullest.
Outputs an infinite list.
## Explanation
```
ṁz*İ1zR:1İ2İ½
           İ½ powers of ½
       :1İ2   powers of 2, with 1 prepended
     zR       zip replicate the second by the first
 z*           then zip multiply that with:
   İ1         odd numbers
ṁ             map to each of the power arrays, and concatenate into single list
```
[Answer]
# [Factor](https://factorcode.org/), ~~68~~ 66 bytes
Saved 2 bytes thanks to @chunes
```
[ 1 2 [ 2dup / . [ 2 + ] dip 2dup > [ 2 * 1 swap ] when t ] loop ]
```
[Try it online!](https://tio.run/##JYyxCsJAEER/ZWqFiCkVbMXGRqyCxXFZTXDdW@82BL/@XGMzzLwZ5h6ipVyvl9P5uMOTshBDM5l9NI9iKPSeSCIVcIqBC17BhkWaHOThfF87bNGiQ9tPig2an8UaN/Sj/uFhQSvflTmoN/NAAnPDKXmufs31Cw "Factor – Try It Online")
Outputs the sequence infinitely.
```
[
  1 2                    ! First numerator and denominator
  [                      ! Loop body
    2dup /               ! Divide to get next element of sequence
    .                    ! Print the element
    [ 2 + ] dip          ! Add 2 to the numerator
    2dup >               ! If numerator > denominator
    [ 
      2 *                ! Multiply denominator by 2
      1 swap             ! Set numerator to 1
    ]
    when                 ! Functions like an if statement
    t                    ! Push true on the stack so the loop doesn't stop
  ]
  loop                   ! Run while top of stack is true (which is forever)
]
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 63 bytes
No input, prints infinite sequence:
```
f(i,j){for(i=1,j=2;;i+=2,i>j&&(j*=2,i=1))printf("%d/%d ",i,j);}
```
[Try it online!](https://tio.run/##FctLCoAwDADRvacIgpJoRey21Ct4BqlEUvyh7sSrG3U3PJhQjSGoMoqJdPG6o/jGRG@dk9JbI23Mc4zFn74h2nZZTsY0G@psgNT8m7v1Q5h7WZDgSgAYySW3PoGnfjy06uwL "C (gcc) – Try It Online")
[Answer]
# JavaScript (ES6), 44 bytes
Returns the \$n\$-th term, 1-indexed.
```
f=(n,p=q=1)=>n?f(n-1,p<q-2?p+2:!!(q*=2)):p/q
```
[Try it online!](https://tio.run/##DYwxDsIwDAB3XuFKDDZpoMlYavqVRqVBoMpOWsSCeHvIdDec7hU@YZ@3Z3pb0ftSSmSUNnFmR3yTMaJY16YhWz8m4/umwXxiT9SnSy5RNxRgcFcQGCq7rpoxdACYVXZdl/OqD5wCHr/yo5pOYKBOicof "JavaScript (Node.js) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 42 bytes
```
1.step{|i|(1..x=2**i).step(2){|j|p [j,x]}}
```
[Try it online!](https://tio.run/##KypNqvz/31CvuCS1oLoms0bDUE@vwtZISytTEyymYaRZXZNVU6AQnaVTEVtb@/8/AA "Ruby – Try It Online")
Prints integer pairs infinitely, starting from 1/2.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 30 bytes
```
f=(n,d=.5)=>d>n?n/d:f(n-d,d*2)
```
[Try it online!](https://tio.run/##JY5BDoIwFET3nGJ2bbVQW0ANpho3JibegLAglIqGtASM18cii5m8@ZNM/rv@1lMzvoZP7Lxp59lq6rjRSc702ZzdxQlTWOpiw81Gsdn6EbRvPygdR1fBW5RRKTmkUBWPSrVQtlDKka6ULbfjQnLHkQu5XzmEQyqk@le5DCPBRC7Vmv9TcqeyqmIR0Hg3@b5Nev@kxFKCLVwQYdCEI7zIVofW6HABGeppIihAbtf7g7DT/AM "JavaScript (Node.js) – Try It Online") 0-indexed. Started out as a port of my Batch answer but I was able to calculate in multiples of \$\frac{1}{2}\$ which saved several bytes.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 31 bytes
```
->x{(2r*x+1)/2**x.bit_length-1}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf166iWsOoSKtC21BT30hLq0IvKbMkPic1L70kQ9ew9n@0oY6RjrGOiY6hARAZ6JgaGgKxUaxebmJBdU1FDVeBQnSFTlp0RWwsV@1/AA "Ruby – Try It Online")
]