__rpow__ issues

17 views
Skip to first unread message

Chris Smith

unread,
May 25, 2021, 5:31:02 AM5/25/21
to sympy
I have a routine for converting an expression into an AccumBounds which is something like

def as_bounds(e):
    if e.is_Symbol:
        return appropriate AccumBounds
    elif e.is_number or not e.args:
        return e
    return e.func(*[bounds(i) for i in e.args

When I call it like this, I don't get an unevaluated power

>>> as_bounds(.5**hint('ip'))
0.5**AccumBounds(1, oo)

But I have an __rpow__ defined for AccumBounds and it works

>>> 0.5**AccumBounds(1, oo)
AccumBounds(0, 0.5)

So what do I need to understand to explain why the result of as_bounds is not evaluated to an AccumBounds instance?

/c

Aaron Meurer

unread,
May 25, 2021, 9:35:34 PM5/25/21
to sympy
I think the problem is that Pow doesn't look at __rpow__ (none of the
sympy classes call the operator methods like this).

We could make Accumbounds use the postprocessors to dispatch on Pow. I
tried doing this at https://github.com/sympy/sympy/pull/13161 for Mul
and Add, but the processors were not well designed at the time. Now
they are designed better. Although Pow is a two-argument function, so
we could also look at making it use multipledispatch. That would be a
more complicated change, however. Right now, the base can dispatch in
Pow by defining _eval_power, but I think the only way the exponent can
dispatch is by using the postprocessors.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/312698eb-550c-40bb-b7da-d98b9fe63d71n%40googlegroups.com.

Chris Smith

unread,
May 26, 2021, 1:49:34 PM5/26/21
to sympy
Thanks, Aaron.
Reply all
Reply to author
Forward
0 new messages