feat(quaternion): Add convenience quaternion creator function #48

Merged
glen merged 1 commits from quaternion into main 2022-08-07 03:27:46 +00:00
Owner

Even in the setup just prior to this commit, a quaternion with entries
of type number is simply a Complex<Complex<number>>
So if we provide a convenience wrapper to create sucha thing, we
instantly have a quaternion data type. All of the operations come for
"free" if they were properly defined for the Complex template.
Multiplication already was, abs needed a little tweak, but there is
absolutely no "extra" code to support quaternions. (This commit
does not go through and check all arithmetic functions for proper operation
and tweak those that still need some generalization.)

Note that with the recursive template instantiation, a limit had to be placed
on template instantiation depth. The limit moves deeper as actual arguments
that are deeper nested instantiations are seen, so as long as one doesn't
immediately invoke a triply-nested template, for example, the limit will
never prevent an actual computation. It just prevents a runaway in the types
that Pocomath thinks it needs to know about. (Basically before, using the
quaternion creator would produce Complex<Complex<number>>. Then when you
called it again, Pocomath would think "Maybe I will need
Complex<Complex<Complex<number>>>?!" and create that, even though it had
never seen that, and then another level next time, and so on. The limit
just stops this progression one level beyond any nesting depth that's
actually been observed.

Even in the setup just prior to this commit, a quaternion with entries of type `number` is simply a `Complex<Complex<number>>` So if we provide a convenience wrapper to create sucha thing, we instantly have a quaternion data type. All of the operations come for "free" if they were properly defined for the `Complex` template. Multiplication already was, `abs` needed a little tweak, but there is absolutely no "extra" code to support quaternions. (This commit does not go through and check all arithmetic functions for proper operation and tweak those that still need some generalization.) Note that with the recursive template instantiation, a limit had to be placed on template instantiation depth. The limit moves deeper as actual arguments that are deeper nested instantiations are seen, so as long as one doesn't immediately invoke a triply-nested template, for example, the limit will never prevent an actual computation. It just prevents a runaway in the types that Pocomath thinks it needs to know about. (Basically before, using the quaternion creator would produce `Complex<Complex<number>>`. Then when you called it again, Pocomath would think "Maybe I will need `Complex<Complex<Complex<number>>>`?!" and create that, even though it had never seen that, and then another level next time, and so on. The limit just stops this progression one level beyond any nesting depth that's actually been observed.
glen added 1 commit 2022-08-07 03:27:36 +00:00
Even in the setup just prior to this commit, a quaternion with entries
  of type `number` is simply a `Complex<Complex<number>>`
  So if we provide a convenience wrapper to create sucha thing, we
  instantly have a quaternion data type. All of the operations come for
  "free" if they were properly defined for the `Complex` template.
  Multiplication already was, `abs` needed a little tweak, but there is
  absolutely no "extra" code to support quaternions. (This commit
  does not go through and check all arithmetic functions for proper operation
  and tweak those that still need some generalization.)

  Note that with the recursive template instantiation, a limit had to be placed
  on template instantiation depth. The limit moves deeper as actual arguments
  that are deeper nested instantiations are seen, so as long as one doesn't
  immediately invoke a triply-nested template, for example, the limit will
  never prevent an actual computation. It just prevents a runaway in the types
  that Pocomath thinks it needs to know about. (Basically before, using the
  quaternion creator would produce `Complex<Complex<number>>`. Then when you
  called it again, Pocomath would think "Maybe I will need
  `Complex<Complex<Complex<number>>>`?!" and create that, even though it had
  never seen that, and then another level next time, and so on. The limit
  just stops this progression one level beyond any nesting depth that's
  actually been observed.
glen merged commit 28ccbf8d48 into main 2022-08-07 03:27:46 +00:00
glen deleted branch quaternion 2022-08-07 03:27:47 +00:00
Sign in to join this conversation.
No description provided.