Why is partial_fraction a method but not a function?

asked 2017-05-14 23:34:01 +0100

cybervigilante gravatar image

Why is partial_fraction a method but not a function? non-function names don't show up in a Tab search so they're hard to recall. Is there a pattern to whether something is a method, a function, or both so I'd know how to search?

edit retag flag offensive close merge delete

Comments

The partial_fraction method is bound to something that has in a natural way a "partial fraction". If the choice is to make this method, partial_fraction, global, or to take back the functionality of factor in factor( 77 ) and / or factor( x^3 + y^3 ), then my choice is to take back. Sage comes with an iron python interpreter, hitting the tab "TAB" in it after - say

a = 77
a.TAB

gives a list of all methods. Alternatively, dir(a) gives the list of the methods as a list of strings.

In our case, taking f to be a fraction, guessing that there would be a partial fraction method starting with "par", it is enough to try...

sage: var( 'x' );
sage: f = x^4/(x^3 +1)
sage: f.par
f.parent            f.partial_fraction  
sage: f.par

(There was a TAB after f.par)

dan_fulea gravatar imagedan_fulea ( 2017-05-15 01:37:55 +0100 )edit

I am unable to answer why this is the case. But more generally, SageMath is written in an object-oriented manner, meaning that in some sense, all the functionalities are provided through methods. One (mathematical) reason for this choice is that a method only makes sense for some kinds (or types) of objects: It make sense to to compute the partial fraction expansion of $x^4/(x^3+1)$ and to compute the floor of $\pi$, but not vice-versa. I see the existence of functions in SageMath more as an anomaly, though a very handy one, than as the rule.

To answer more specifically your last question: Every function actually calls a method on the object it is applied to, usually with the same name. In other words, you can completely ignore functions if you want!

B r u n o gravatar imageB r u n o ( 2017-05-15 11:41:47 +0100 )edit