Ask Your Question

Revision history [back]

This is because 2 and 3 are preparsed by Sage to give Sage integers, not Python ints, and Fraction doe not know how to deal with them.

Here is the action of Sage preparser on your command:

sage: preparse("Fraction(2,3)")
'Fraction(Integer(2),Integer(3))'

If you want to disable it, you can do:

sage: Fraction(2r,3r)
Fraction(2, 3)

Indeed:

sage: preparse("Fraction(2r,3r)")
'Fraction(2,3)'

This is because 2 and 3 are preparsed by Sage to give Sage integers, not Python ints, and Fraction doe not know how to deal with them.

Here is the action of Sage preparser on your command:

sage: preparse("Fraction(2,3)")
'Fraction(Integer(2),Integer(3))'

If you want to disable it, you can do:

sage: Fraction(2r,3r)
Fraction(2, 3)

Indeed:

sage: preparse("Fraction(2r,3r)")
'Fraction(2,3)'

You can also transform the Sage integers back into Python ints:

sage: Fraction(int(2),int(3))
Fraction(2, 3)
sage: preparse("Fraction(int(2),int(3))")
'Fraction(int(Integer(2)),int(Integer(3)))'

This is because 2 and 3 are preparsed by Sage to give Sage integers, not Python ints, and Fraction doe not know how to deal with them.

Here is the action of Sage preparser on your command:

sage: preparse("Fraction(2,3)")
'Fraction(Integer(2),Integer(3))'

If you want to disable it, you can do:

sage: Fraction(2r,3r)
Fraction(2, 3)

Indeed:

sage: preparse("Fraction(2r,3r)")
'Fraction(2,3)'

You can also transform the Sage integers back into Python ints:

sage: Fraction(int(2),int(3))
Fraction(2, 3)
sage: preparse("Fraction(int(2),int(3))")
'Fraction(int(Integer(2)),int(Integer(3)))'

EDIT

If you want to use Sage, you should use Sage rationals, which have much more features than Python Fractions, for this just write:

sage: 2/3
2/3

If you want to do a lot of manipulations with Python Fraction, you can turn Sage preparser off:

sage: preparser(False)
sage: Fraction(2,3)
Fraction(2, 3)