On Wed, Dec 7, 2011 at 10:40 PM, Mateusz Paprocki <[email protected]> wrote:
> Hi,
>
> On 6 December 2011 08:28, smichr <[email protected]> wrote:
>>
>> Is there any place in sympy for mixed representation? in pprint, a
>> Rational method?
>>
>> >> Rational(7, 3).mixed
>> '2 1/3'
>> or
>> (2, 1/3)
>>
>> I was working with a younger math class and wishing for this today.
>
>
> You can implement a printer for this, e.g.:
>
> class XStrPrinter(StrPrinter):
>     def _print_Rational(self, r):
>         p = abs(r.p)
>         q = r.q
>         a = p//q
>         b = p % q
>         c = q
>         if not a:
>             s = "%s/%s" % (b, c)
>         else:
>             s = "%s %s/%s" % (a, b, c)
>         if r.p < 0:
>             s = "-" + s
>         return s
>
> Otherwise you can implement MixedRational class (or similar).
>

That would be cool to have.  I don't think you'd be able to use it
without modifying the core, though, due to the way we have things hard
coded into Mul.flatten, and other places.  But extending the printer
is a cool idea.  That requires no modification of the core, and
probably does everything you want.  We should include this in SymPy
and allow it as an optional printer somehow.

Aaron Meurer

>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sympy?hl=en.
>>
>
> Mateusz
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to