[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Cristóvão Sousa
I made a modification so it can take 1, 3, 4, ... number of operands nicely. def symround(x, ndigits=0): if hasattr(x,'operator') and x.operator(): o = map( lambda y : symround(y,ndigits=ndigits) , x.operands() ) r = o[0] for i in xrange(1,x.nops()): r = x.operator(

[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Simon King
Hi Burcin, On 25 Okt., 15:26, Burcin Erocal wrote: > This initializes a list with a single element for objects which return > None for operator() now. IMHO, this approach is inefficient. In this > case, you should act on the object directly. I didnt claim that it was efficient - my code was inte

Re: [sage-support] Re: Round symbolic expressions

2010-10-25 Thread Burcin Erocal
Hi Simon, On Mon, 25 Oct 2010 06:09:16 -0700 (PDT) Simon King wrote: > On 25 Okt., 14:39, Burcin Erocal wrote: > > If we return an identity operator for these cases, how do you plan > > to test for it in your code: > > Something like this: > > L = x.operands() > if len(L)>1: > return x.op

[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Simon King
PS: I know that testing "is None" is faster than "len(L)>1" and wouldn't insist that there *has* to be an identity operator. One has to consider two different cases anyway. However, if there *is* an operator, s==s.operator()(*s.operands()) should hold. Cheers, Simon -- To post to this group, s

[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Simon King
Hi Burcin! On 25 Okt., 14:39, Burcin Erocal wrote: > If we return an identity operator for these cases, how do you plan to > test for it in your code: Something like this: L = x.operands() if len(L)>1: return x.operator()(*map(lambda ..., L)) else: try: return x.operator()(round

Re: [sage-support] Re: Round symbolic expressions

2010-10-25 Thread Burcin Erocal
Hi Simon, On Mon, 25 Oct 2010 05:09:06 -0700 (PDT) Simon King wrote: > I only opened one ticket, namely #10169, aiming at making > s==s.operator()(*s.operands()) work uniformely. I don't think this makes sense for variables, numeric objects, or constants, in other words, objects for which .ope

[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Simon King
Hi Burcin, On 25 Okt., 11:04, Burcin Erocal wrote: > I suggest we raise a ValueError when there is no operator or operands. > This is already done for iterators of symbolic expressions in #7537: > > http://trac.sagemath.org/sage_trac/ticket/7537 > > Can you open a ticket to do the same for operan

Re: [sage-support] Re: Round symbolic expressions

2010-10-25 Thread Burcin Erocal
Hi Simon, On Mon, 25 Oct 2010 00:41:07 -0700 (PDT) Simon King wrote: > @symbolic experts (Burcin et al): > Is it really necessary that x.operator() returns None and x.operands() > returns []? What about an identity operator? The operator and operands don't have a meaning if you have a single va

[sage-support] Re: Round symbolic expressions

2010-10-25 Thread Simon King
Hi Cristóvão! On 25 Okt., 03:30, Cristóvão Sousa wrote: > ... > It just has a minor bug when the operator has more than two operands, > like x+y+z, but I'll try to fix it as I got the picture now. Yes, to my surprise, the "add" operator only accepts two arguments, but the list of operands of a s

[sage-support] Re: Round symbolic expressions

2010-10-24 Thread Cristóvão Sousa
On Oct 24, 12:34 pm, Simon King wrote: > I guess it would be needed to define a recursive function for that > purpose, using operator and operands of a symbolic expression. Such > as: > > sage: def symround(x, ndigits=0): > :     if hasattr(x,'operator') and x.operator(): > :         retur

[sage-support] Re: Round symbolic expressions

2010-10-24 Thread Simon King
Hi Cristóvão! On 24 Okt., 00:50, Cristóvão Sousa wrote: > But, is there any way of round reals even if they are inside a symbolic > expression? I guess it would be needed to define a recursive function for that purpose, using operator and operands of a symbolic expression. Such as: sage: def sy