# <symbolic matrix>.simplify_rational() accepts no keywords?

I have a symbolic matrix whose entries I would like to simplify for display. Minimal working example (in the sage REPL):

 a,b=var('a,b'); m=matrix(SR,2,[[(a*b-a)/a,0],[0,1]]).simplify_rational() 

works fine and upon calling m produces

[b - 1 0] [ 0 1] 

as expected. On the other hand, running

 a,b=var('a,b'); m=matrix(SR,2,[[(a*b-a)/a,0],[0,1]]).simplify_rational(algorithm='simple') 

as per the documentation produces

TypeError Traceback (most recent call last) <ipython-input-30-3edf7642200d> in <module>() ----> 1 a,b=var('a,b'); m=matrix(SR,Integer(2),[[(a*b-a)/a,Integer(0)],[Integer(0),Integer(1)]]).simplify_rational(algorithm='simple')

TypeError: simplify_rational() takes no keyword argument

If I apply the method to a single expression it works fine:

 ((a*b-a)/a).simplify_rational(algorithm='simple')  gives back b-1.

edit retag close merge delete

Sort by ยป oldest newest most voted

These are two different methods, with the same name, on different classes (symbolic expressions and symbolic dense matrices respectively). The documentation for the matrix method does not mention keyword arguments, and indeed none are accepted, as you have seen. As an alternative you can apply the symbolic expression method to each entry:

sage: var('a,b')
sage: m=matrix(SR,2,[[(a*b-a)/a,0],[0,1]])
sage: m.apply_map(lambda z: z.simplify_rational(algorithm='simple'))
[b - 1     0]
[    0     1]


It would be nice if the matrix method accepted the same arguments. If you want, someone could open an enhancement ticket on trac.

more

Perfect, thank you!

The nomenclature clash confused me.. Indeed, I can confirm

a,b=var('a,b'); m=matrix(SR,2,[[(a*b-a)/a,0],[0,1]]).apply_map(lambda z: z.simplify_rational(algorithm='simple')); m

returns the same output you displayed (i.e. what was expected).

( 2020-02-16 15:20:48 +0200 )edit