This gem provides a HyperComplex class highly compatible with other numeric classes.
The hypercomplex numbers form finite-dimensional algebra over the real numbers. These algebras are produced by the Cayley–Dickson construction. Examples of such algebras are complex numbers, quaternions, octonions, sedenions, etc.
The hypercomplex number can be represented as
The identity unit (
Ruby >= 3.1
Add this line to your application's Gemfile:
gem 'mcalendar'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install hyper_complex
require 'hyper_complex'
# Creation from complex numbers
q1 = HyperComplex.rect((1+2i), (3+4i)) #=> HyperComplex[1, 2, 3, 4]
q2 = HyperComplex.rect((5+6i), (7+8i)) #=> HyperComplex[5, 6, 7, 8]
# Creation from HyperComplex numbers
o1 = HyperComplex.rect(q1, q2) #=> HyperComplex[1, 2, 3, 4, 5, 6, 7, 8]
# Creation from real numbers
o2 = HyperCoplex[9, 10, 11, 12, 13] #=> HyperComplex[9, 10, 11, 12, 13, 0, 0, 0]
# Creation from polar form
q3 = HyperComplex.polar(1, Math::PI/3, Vector[1, 1, 1].normalize) #=> HyperComplex[0.5, 0.5, 0.5, 0.5]
# standard calculations between numeric instances
(q1+q2)*o1 / Complex::I - 24 #=> HyperComplex[(0/1), (88/1), (-40/1), (20/1), (-80/1), (-184/1), (112/1), (-84/1)]Bug reports and pull requests are welcome on GitHub at https://github.com/bfifelin/hyper_complex.
This project is licensed under the terms of the MIT license.
This gem is based on the gem quaternion_c2 by Masahiro Nomoto.