Constants and SymbolicArithmetic objects

6 views
Skip to first unread message

Jason Grout

unread,
Dec 6, 2008, 4:15:00 PM12/6/08
to sage-...@googlegroups.com
I'd like to add an exponential function to RDF/CDF matrices (and enhance
the existing exp function for SR matrices) so that:

sage: A = matrix(SR, [[1,2],[3,4]])
sage: e^A

gives the same as

sage: A.exp()

(I'd also like this to work for other matrices, like over RDF or CDF,
where the returned matrix would be another RDF/CDF matrix---scipy has
functions that do this).

However, currently for constants (in sage/functions/constants.py), the
__pow__ function automatically converts the exponent to an SR object,
which fails for a matrix.

I have not worked with the constants code before. Would there be a
problem with, for the E constant, overriding __pow__ so that if the
object had an "_exp" method, that was called instead of the default
conversion to SR objects?

Would that be the proper way to get the above functionality? The goal
is also to get exp(A) to work as well; would I get that for free?

Thanks,

Jason

Robert Bradshaw

unread,
Dec 6, 2008, 11:08:05 PM12/6/08
to sage-...@googlegroups.com
On Dec 6, 2008, at 1:15 PM, Jason Grout wrote:

>
> I'd like to add an exponential function to RDF/CDF matrices (and
> enhance
> the existing exp function for SR matrices) so that:
>
> sage: A = matrix(SR, [[1,2],[3,4]])
> sage: e^A
>
> gives the same as
>
> sage: A.exp()
>
> (I'd also like this to work for other matrices, like over RDF or CDF,
> where the returned matrix would be another RDF/CDF matrix---scipy has
> functions that do this).
>
> However, currently for constants (in sage/functions/constants.py), the
> __pow__ function automatically converts the exponent to an SR object,
> which fails for a matrix.
>
> I have not worked with the constants code before. Would there be a
> problem with, for the E constant, overriding __pow__ so that if the
> object had an "_exp" method, that was called instead of the default
> conversion to SR objects?

+1, this was my first though when I started reading your email. I
don't think it makes sense for other constants, but for E it
certainly does. Also, I'd just call exp (not _exp), making sure that
it doesn't introduce a recursive call...

> Would that be the proper way to get the above functionality? The goal
> is also to get exp(A) to work as well; would I get that for free?

Yes. When you do exp(A) it attempts to return A.exp() before doing
anything symbolic.

- Robert

Reply all
Reply to author
Forward
0 new messages