Re: [sympy] Some queries regarding the Quaternions feature I wish to contribute

31 views
Skip to first unread message

Aaron Meurer

unread,
Sep 8, 2017, 4:02:43 PM9/8/17
to sy...@googlegroups.com


On Fri, Sep 8, 2017 at 6:24 AM, Nikhil Pappu <nkhl...@gmail.com> wrote:
I wrote a Quaternion class which provides basic quaternion operations (please see the attachment).
I have never made an open source contribution before so I am sorry if any of these questions are stupid.

Here are my queries :

1) What module of sympy should I put this file in?

I'm not sure what the best place is. I would look at all the submodules and put it where it fits best for the intended use case. Maybe it needs a new submodule. If you can't find a good place for it, just put it in sympy/functions for now.
 

2) Is my code good enough to be added to sympy? If not, what changes should I make?

Please open a pull request. It is much easier to suggest changes on GitHub.
 

3) printing issue :
In my code I used 2 classes for printing (CustomStrPrinter and CustomLatexPrinter) and set the default to CustomStrPrinter.
The issue is that if I set the default to CustomLatexPrinter it works fine for IPython shell commands but when I call the print function on expressions
it prints the latex form of the expression.
I want shell commands to use the CustomLatexPrinter (if latex is available) and print statements to use the CustomStrPrinter.

I guess I am confused about this whole printing thing.
In short, I want the printing to work in the way it works for sympy matrices (gives a fancy latex matrix in IPython shell commands but gives a normal string when print is used).

If you want to modify the default printers you need to define the appropriate method on the object, like _latex and _sympystr. See http://docs.sympy.org/latest/modules/printing.html.


4) I made some functions in the code called diff, integrate, exp and ln and they can be called on a Quaternion object q as
q.integrate()
q.exp()
q.ln()

but I also want them to work when sympy.integrate(q), sympy.exp(q), sympy.ln(q) are used. How should I accomplish this? 

For integrate() you should define _eval_integral. For exp() I believe _eval_power will work. For other functions such as ln, there's not currently a way to define the behavior. How do you define the exponential and logarithm of a quaternion by the way?

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+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/5f67df3d-3979-435f-bda9-b96570a295a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikhil Pappu

unread,
Sep 8, 2017, 5:56:19 PM9/8/17
to sympy
Thanks for the reply Aaron.
I found info on exp, ln and power of quaternions on the Wikipedia page.
https://en.m.wikipedia.org/wiki/Quaternion
Reply all
Reply to author
Forward
0 new messages