Extended Operations on Symbols

31 views
Skip to first unread message

Jin Guu

unread,
Apr 26, 2020, 12:01:35 PM4/26/20
to sage-support
I am writing a calculator for various 'q' quantities, and often find that I need to manipulate symbols more flexibly. For example, I have to deal with the expression

( q + q^(-1) ) ^ (1/2) ------------------ (*)

But currently I could not find any way to achieve this. A naive attempt gives a failure:

sage: q = Frac(ZZ['q']).gen()
sage: q ^ (1/2)
---> ValueError: not a 2nd power
sage: power(q, 1/2)
NotImplementedError: non-integral exponents not supported

Leave alone the expression I need! Indeed, one might have to define a larger parent for the expression (*) to live in. So this might require implementing a new algebraic structure. If that's the case, I'm willing to write it. The problem is that implementing a new structure seems a bit complicated to me.. I might take some time, and need some guides. Thank you so much!

PS. Weirdly enough, exp(sin(q)) is already implemented as in the class <class 'sage.symbolic.expression.Expression'>. Perhaps what I need might not be too hard to implement?

John H Palmieri

unread,
Apr 26, 2020, 12:14:59 PM4/26/20
to sage-support
sage: var('q')
q
sage: (q+q^(-1))^(1/2)
sqrt(q + 1/q)

(By the way, I'm not sure I would call using a fraction field "naive".)

Jin Guu

unread,
Apr 26, 2020, 3:04:44 PM4/26/20
to sage-support
Woah! Thank you so much!

p.s. I said it's naive because I have no better idea.. perhaps there's a better wording. Sorry for that.
Reply all
Reply to author
Forward
0 new messages