# How to represent the answer of linear programming in Rational mode

Hi everyone:

I use COIN in sage to solve a linear programming. And I need the answer to be in fraction, but the default is not factional. That's to say I need the answer

\frac{1}{3}


not

0.3333.... ,


so, how can I get the answer I need ?

edit retag close merge delete

Sort by ยป oldest newest most voted

The arbitrary precision linear programming backend is not yet merged, but you can get it from http://trac.sagemath.org/12533

more

This will give the OP more 3s, but won't return an answer in QQ, unless I'm missing something (always possible, of course.)

( 2012-10-02 17:12:06 +0200 )edit

According to http://www.sagemath.org/doc/reference/sage/libs/ppl.html (to which the above link points), PPL computes in QQ.

( 2012-10-04 12:55:11 +0200 )edit

You can't in general, without making some further assumptions -- how do you know that the answer really isn't 33333/100000?

If you want a sort of best-guess fraction, you can use the Farey sequence and the Sage function farey:

sage: farey(0.3333, 1)
(0, 1)
sage: farey(0.3333, 2)
(0, 1)
sage: farey(0.3333, 3)
(1, 3)
sage: farey(0.3333, 100)
(1, 3)

more