Ask Your Question

Revision history [back]

I am not sure i understand you question, Sage automatically reduces a rational between 0 and 1 (or not) in lowest terms:

sage: 6/34
3/17

If this is not what you asks for (which is likely), could you give more details of what do you expect ?

I am not sure i understand you question, Sage automatically reduces a rational between 0 and 1 (or not) in lowest terms:modify my answer according to your precision. You can do:

sage: 6/34
3/17
npoints = 10000
sage: f = lambda x: 1/(RR(x).nearby_rational(max_error=1/npoints).denominator())
sage: plot(f, (x,0,1), plot_points=npoints)

If this is not what you asks for (which is likely), could you give more details of what do you expect ?The picture with npoints = 100 look urbanized.

To understand what the .nearby_rational() method does on elements of RR, you can do:

sage: a = 0.1
sage: a.nearby_rational?

From a matematical point of view, you might be interested by the "Stern–Brocot tree" and "Farey sequences".

I modify my answer according to your precision. You can do:

sage: npoints = 10000
sage: f = lambda x: 1/(RR(x).nearby_rational(max_error=1/npoints).denominator())
sage: plot(f, (x,0,1), plot_points=npoints)

The (the picture with npoints = 100 look urbanized.quite urbanized)

To understand what the .nearby_rational() method does on elements of RR, you can do:

sage: a = 0.1
sage: a.nearby_rational?

From a matematical point of view, you might be interested by the "Stern–Brocot tree" and "Farey sequences".