Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Listing fractions

Hi, I would like to request help in listing rational numbers. For motivation, the command

[x for x in IntegerRange(1,10)]

outputs the integers from 1 through 9. Is there a similar command for listing out rational numbers a/b with a and b in the range (x1,y1) and (x2,y2), respectively.

For instance, if a is in range (1,3) and b is in (4,6), I want to return

[1/4, 1/5, 1/2, 2/5]

On a related note, how can one impose a gcd(x,y)==1 in the following list?

[(x,y) for x in IntegerRange(1,10) for y in IntegerRange(1,10)]