On Sep 8, 7:42 pm, Jason Merrill <[EMAIL PROTECTED]> wrote:

<snip>

> One additional consideration is that it is useful in this case to know
> whether an expression is constant, as a performance consideration.
> The regular algorithm works (slowly) on constant input, but it's
> faster if we can just short circuit in the case of a constant.
> Clearly, asking an expression for its variables is not the right way
> to find out whether it's constant.  How about something like this
> instead:

<snip>

mhansen pointed out number_of_arguments to me on IRC.  It only works
on things in the symbolic ring, so if you want to find out if
something is constant, you could do something like this

def is_constant(f):
    return SR(f).number_of_arguments() == 0

Since this is so short, in practice there is probably no need to
define the function is_constant.  If f can't be coerced to the
symbolic ring, this will throw a TypeError, but that seems like
perfectly acceptable behavior.  Just catch it.

JM
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to