Ask Your Question

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

asked 2020-02-15 18:03:18 +0200

grobber gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-16 12:42:15 +0200

rburing gravatar image

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.

edit flag offensive delete link 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).

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-15 18:03:18 +0200

Seen: 47 times

Last updated: Feb 16 '20