ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 04 Oct 2012 12:55:11 +0200How to represent the answer of linear programming in Rational modehttps://ask.sagemath.org/question/9378/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 ?Tue, 02 Oct 2012 01:00:17 +0200https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/Answer by DSM for <p>Hi everyone:</p>
<p>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 </p>
<pre><code>\frac{1}{3}
</code></pre>
<p>not </p>
<pre><code>`0.3333....` ,
</code></pre>
<p>so, how can I get the answer I need ?</p>
https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?answer=14092#post-id-14092You 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](http://en.wikipedia.org/wiki/Farey_sequence) and the Sage function [farey](http://www.sagemath.org/doc/reference/sage/rings/arith.html#sage.rings.arith.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)
Tue, 02 Oct 2012 11:24:13 +0200https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?answer=14092#post-id-14092Answer by Volker Braun for <p>Hi everyone:</p>
<p>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 </p>
<pre><code>\frac{1}{3}
</code></pre>
<p>not </p>
<pre><code>`0.3333....` ,
</code></pre>
<p>so, how can I get the answer I need ?</p>
https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?answer=14093#post-id-14093The arbitrary precision linear programming backend is not yet merged, but you can get it from http://trac.sagemath.org/12533Tue, 02 Oct 2012 11:47:23 +0200https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?answer=14093#post-id-14093Comment by DSM for <p>The arbitrary precision linear programming backend is not yet merged, but you can get it from <a href="http://trac.sagemath.org/12533">http://trac.sagemath.org/12533</a></p>
https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?comment=18935#post-id-18935This will give the OP more 3s, but won't return an answer in QQ, unless I'm missing something (always possible, of course.)Tue, 02 Oct 2012 17:12:06 +0200https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?comment=18935#post-id-18935Comment by Robert Samal for <p>The arbitrary precision linear programming backend is not yet merged, but you can get it from <a href="http://trac.sagemath.org/12533">http://trac.sagemath.org/12533</a></p>
https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?comment=18920#post-id-18920According to http://www.sagemath.org/doc/reference/sage/libs/ppl.html (to which the above link points), PPL computes in QQ. Thu, 04 Oct 2012 12:55:11 +0200https://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/?comment=18920#post-id-18920