ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 May 2017 04:41:47 -0500Why is partial_fraction a method but not a function?http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/ 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?Sun, 14 May 2017 16:34:01 -0500http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/Comment by B r u n o for <p>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?</p>
http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/?comment=37594#post-id-37594I 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!Mon, 15 May 2017 04:41:47 -0500http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/?comment=37594#post-id-37594Comment by dan_fulea for <p>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?</p>
http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/?comment=37590#post-id-37590The 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`)Sun, 14 May 2017 18:37:55 -0500http://ask.sagemath.org/question/37589/why-is-partial_fraction-a-method-but-not-a-function/?comment=37590#post-id-37590