|   | 1 |  initial version  | 
One way to do that is to factor the numerator and then the denominator:
sage: print('{}/({})'.format(f.numerator().factor(), f.denominator().factor()))
(x - 1)^2/(x + 1)
One could turn this into a function with a special case for no denominator:
def pretty_print_factor(f):
    d = f.denominator()
    if d == 1:
        print(f.factor())
    else:
        n = f.numerator().factor()
        print('{}/({})'.format(n, d.factor()))
Using this function, we get:
sage: pretty_print_factor(f)
(x - 1)^2/(x + 1)
|   | 2 |  No.2 Revision  | 
One way to do that is to factor the numerator and then the denominator:
sage: print('{}/({})'.format(f.numerator().factor(), print('({})/({})'.format(f.numerator().factor(), f.denominator().factor()))
(x ((x - 1)^2/(x 1)^2)/(x + 1)
One could turn this into a function with a special case for no denominator:
def pretty_print_factor(f):
    d = f.denominator()
    if d == 1:
        print(f.factor())
    else:
        n = f.numerator().factor()
        print('{}/({})'.format(n, print('({})/({})'.format(n, d.factor()))
Using this function, we get:
sage: pretty_print_factor(f)
(x ((x - 1)^2/(x 1)^2)/(x + 1)
The function could be improved to leave out parenthesis when not needed.
 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
 
                
                Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.