On Friday, 4 August 2017 19:16:04 UTC-4, Aaron Meurer wrote: > > > > On Fri, Aug 4, 2017 at 6:19 PM, Francesco Bonazzi <franz....@gmail.com > <javascript:>> wrote: > >> >> >> On Friday, 4 August 2017 17:34:25 UTC-4, Aaron Meurer wrote: >>> >>> You can try this, but I foresee problems reusing I=sqrt(-1) the complex >>> number as i the quaternion. Mathematically they aren't the same thing, but >>> even in terms of SymPy, ImaginaryUnit is burdened with things like >>> assumptions, which might cause issues with quaternions. >>> >> >> Implementing quaternions should be simple. Deciding how they interact >> with the rest of SymPy may be more complicated. >> > > If you implement them like Ondrej suggested, as a 4-tuple, they will > interact badly. Even just adding a scalar to a quaternion will be difficult > to make work, as the scalar x would have to be converted to (x, 0, 0, 0) > first. > > On the other hand, if the quaternions i, j, and k are just special > noncommutative expressions, then they will interact just fine, because > SymPy already knows how to deal with noncommutative expressions. The only > hard thing will be making things like i**2 and i*j auto-simplify (if > desired). The former can be done with _eval_power, and the latter with Mul > postprocessors. > > That's one way to go, even if I'm not so sure on whether *i* should be different from the complex numbers. I don't think we need the postprocessors, setting a right value for *_op_priority* should be enough in this case. Postprocessors are meant to handle more complicated cases.
> >> >>> And maybe even you could do something with the Mul processors to make >>> them auto-simplify, if that's what is desired. >>> >> >> I would suggest an immediate evaluation in this case. >> >> Maybe a Quaternion class is the simplest way to implement quaternions. >> > > What do you mean by a Quaternion class? Are you thinking something more > like my or Ondrej's suggestion? > Well, sort of. We could have a class that stores four arguments and overrides __mul__ and __add__ to behave as a Quaternion. Its constructor could have some special properties, such as: - return the first argument only if the other ones are zero (a real number). - return a complex number if the last two arguments are zero (a complex number). - in the printer, expressions such as Quaternion(0, 0, a, 0) should be printed as *a*j* where *j = Quaternion(0, 0, 1, 0)*. Some possible extensions remain: - how should functions of quaternions behave? Like *exp(q)*, *sin(q)*, *log(q)*? - how should quaternions interact with matrices? - how should quaternions behave in equation solvers? - limits and derivatives of quaternions? -- 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+unsubscr...@googlegroups.com. To post to this group, send email to sympy@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/306a9ea8-8d59-4535-8f9e-35f7b245d696%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.