> hi
>
> suppose that we have an interval I belong to [0,1]
>
> I want to know how to calculate a fraction p/q
> belong to I and p+q is the smallest possible
One method is to use Minimize over integers, setting up appropriate
bounding constraints.
minFraction[lo_Rational, hi_Rational] /; 0 < lo < hi :=
Minimize[{p + q, {Denominator[lo]*p - Numerator[lo]*q >= 0,
Denominator[hi]*p - Numerator[hi]*q <= 0, p >= 1, q >= 1}}, {p,
q}, Integers]
For example, we'll work with the interval from 2/7 to 4/9 inclusive.
In[11]:= minFraction[2/7, 4/9]
Out[11]= {4, {p -> 1, q -> 3}}
If you want to enforce that the interval be strictly inside (0,1) you can
have constraint q>=2. More generally you might try to strengthen
constraints based on the input, should speed become an issue.
Daniel Lichtblau
Wolfram Research