Re: smallest fraction
- To: mathgroup at smc.vnet.net
- Subject: [mg86804] Re: [mg86771] smallest fraction
- From: danl at wolfram.com
- Date: Fri, 21 Mar 2008 01:55:29 -0500 (EST)
- References: <200803200757.CAA29500@smc.vnet.net>
> 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
- Follow-Ups:
- Re: Re: smallest fraction
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: smallest fraction
- References:
- smallest fraction
- From: masmoudi <mas_atef@yahoo.fr>
- smallest fraction