[sage-support] Re: Best Practices for extending functionality of a sage class
On Thursday, June 5, 2014 2:50:22 PM UTC-7, Dinakar Muthiah wrote: Partition.i_part = i_part Then if later I wrote: p = Partition([3,2,1]) I can call p.i_part(2) That works. Of course, without the monkey-patching (changing code on a class after its original definition), you could also just write i_part(p,2) which is the same number of characters and works without modifying global objects that may be used elsewhere. The great thing about python is that you don't have to be hung up on implementing everything as a method. Often, plain old functions are a much cleaner and more concise way of expressing your computations. Of course, as pointed out, if you think the functionality warrants wider adoption, you should create a ticket and provide a code change proposal. For incorporation into sage proper, the function would almost certainly needs to be placed as a method somewhere, to get it out of the way of naming conflicts. For your own code projects you probably don't have to bother. -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Best Practices for extending functionality of a sage class
Ideally, I would like to define a subclass of Partition called MyPartition and include all my custom methods. I think this is a standard way to extend libraries, but for some reason this doesn't work at all. Is there a solution that is more in the spirit of subclassing? -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Having trouble with syntax and nesting integral into limit
On Thursday, June 5, 2014 11:24:39 PM UTC-4, Robert Dodier wrote: On 2014-06-06, kcrisman kcri...@gmail.com javascript: wrote: lim(1/n^2*integrate(sin((2*n+1)*x)/sinh(x),x,0,pi/2),n=infinity) I couldn't make any progress with the integral (in Maxima). Computing the integral numerically with quad_qawo (same function should be in Sage somewhere) suggests that it's pi/2 as n increases without bound. So I'm guessing the limit is zero. If you need a proof, maybe you can show the integral is bounded, therefore the limit is zero. See also http://sourceforge.net/p/maxima/mailman/message/32423506/ for a few more comments on this. -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Segmentation fault in singular multi-polynomial factor() function
Volker Braun wrote: Reported at http://www.singular.uni-kl.de:8002/trac/ticket/621 Fix committed upstream: https://github.com/Singular/Sources/commit/28f4fe9464722511718050dfab7cd61d29898968 If somebody^TM opens a ticket (or has already done so), please cc me or post the ticket # here. I'll otherwise probably do so, and check whether the patch applies clean to our version (and is sufficient for it). -leif -- () The ASCII Ribbon Campaign /\ Help Cure HTML E-Mail -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: numerical approximation with units of measurement?
On Thursday, June 5, 2014 6:32:42 PM UTC-7, Hal Snyder wrote: IIs there a simple way to take n() of things without getting into the following? You could automate the application, but you'll quickly see you need to be a bit careful: #unfortunately, the operators returned for sums and products of multiple #arguments are callable, but don't accept multiple arguments, so we need to #do a little surgery ourselves (borrow the functionality from elsewhere): opdict = { operator.mul : sage.interfaces.maxima_lib.mul_vararg, operator.add : sage.interfaces.maxima_lib.add_vararg, } def recn(e): try: return n(e) except TypeError: pass op=e.operator() if op: if op in opdict: op = opdict[op] return op(*[recn(c) for c in e.operands()]) else: return e -- This now works, a little bit: sage: recn(area) 21.5161409036487*meter^2.00 As you can see, the exponent in meter^2 was also numerified. Perhaps you didn't want that? Nonetheless, a recursive n(..) method seems eminently reasonable and desirable to implement. -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: numerical approximation with units of measurement?
Thank you! I have a lot to learn about Sage, I can see. Will study experiment with recn. In most cases, an integer exponent should look like 2 and not 2.000, don't you think? So I guess I would not n() the exponents. I have just started using Sage and SMC with some online classes. It's great to: - check work with units of measure - take notes that look like math rather than COBOL (+1 typeset_mode) - do symbolic and numerical calculations in those same typeset notes I'm hooked. :-) On Friday, June 6, 2014 6:53:18 PM UTC-5, Nils Bruin wrote: On Thursday, June 5, 2014 6:32:42 PM UTC-7, Hal Snyder wrote: IIs there a simple way to take n() of things without getting into the following? You could automate the application, but you'll quickly see you need to be a bit careful: #unfortunately, the operators returned for sums and products of multiple #arguments are callable, but don't accept multiple arguments, so we need to #do a little surgery ourselves (borrow the functionality from elsewhere): opdict = { operator.mul : sage.interfaces.maxima_lib.mul_vararg, operator.add : sage.interfaces.maxima_lib.add_vararg, } def recn(e): try: return n(e) except TypeError: pass op=e.operator() if op: if op in opdict: op = opdict[op] return op(*[recn(c) for c in e.operands()]) else: return e -- This now works, a little bit: sage: recn(area) 21.5161409036487*meter^2.00 As you can see, the exponent in meter^2 was also numerified. Perhaps you didn't want that? Nonetheless, a recursive n(..) method seems eminently reasonable and desirable to implement. -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Best Practices for extending functionality of a sage class
On Friday, June 6, 2014 7:13:50 AM UTC-7, Dinakar Muthiah wrote: Ideally, I would like to define a subclass of Partition called MyPartition and include all my custom methods. I think this is a standard way to extend libraries, but for some reason this doesn't work at all. Is there a solution that is more in the spirit of subclassing? That tends to be a rather heavy-weight solution, which you should probably only undertake if you really want to store additional data on the objects themselves. One reason is that any routine you inherit from the superclass that produces partitions itself will not take efforts to return an instance of your subclass but will construct an instance of the original class (it can't, even if it has access to the subclass via type(self): instantiating new instances of the subclass may need additional data that the superclass isn't aware of!). You'd end up wrapping all those routines if you want your new instances to persist through operations. That's probably only a good design if you have good arguments why your MyPartition is a different kind of object than Partition. Using normal functions or monkey-patching them in as methods (which is only acceptable in your own private code) is going to be the easiest solution. Or edit partition.py and include your code there. Unless you get your modification accepted upstream that's going to be a rather painful solution wrt. upgrading and portability, though. -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Best Practices for extending functionality of a sage class
On Saturday, 7 June 2014 00:13:50 UTC+10, Dinakar Muthiah wrote: Ideally, I would like to define a subclass of Partition called MyPartition and include all my custom methods. I think this is a standard way to extend libraries, but for some reason this doesn't work at all. Is there a solution that is more in the spirit of subclassing? On Saturday, 7 June 2014 00:13:50 UTC+10, Dinakar Muthiah wrote: Ideally, I would like to define a subclass of Partition called MyPartition and include all my custom methods. I think this is a standard way to extend libraries, but for some reason this doesn't work at all. Is there a solution that is more in the spirit of subclassing? The problem is that a partition in sage is not an isolated object, rather, it is the element class of Partitions. If you want to subclass Partition then you also need to create a parent. Also, as Nils says below you are likely to run into problems because any (most?) method(s) of MyPartition that returns a partition will return a Partition rather than a MyPartition. This said, if you really want to do this then you need something like the following: from sage.structure.element import Element from sage.structure.global_options import GlobalOptions from sage.combinat.partition import PartitionOptions class MyPartition(Partition): @staticmethod def __classcall_private__(cls, mu=None, **keyword): return MyPartitions()(super(MyPartition,cls).__classcall_private__( cls,mu,**keyword)) def fred(self): return fred class MyPartitions(Partitions): Element=MyPartition global_options=PartitionOptions Quite likely there will be more tweaks to get this to work fully, but it certainly gets things going: %attach mypartiiton.py sage: MyPartition([3,2]) [3, 2] sage: mu=MyPartition([3,2]).cells() sage: mu=MyPartition([3,2]).fred() -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Best Practices for extending functionality of a sage class
Oops, cut and past the wrong bits at the end - and google's syntax highlighting was going haywire: sage: MyPartition([3,2]) [3, 2] sage: MyPartition([3,2]).cells() [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)] sage: MyPartition([3,2]).fred() 'fred' -- You received this message because you are subscribed to the Google Groups sage-support group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.