Implementation of hyperbolic complex numbers in Julia language

Cover Page

Cite item

Abstract

Hyperbolic complex numbers are used in the description of hyperbolic spaces. One of the well-known examples of such spaces is the Minkowski space, which plays a leading role in the problems of the special theory of relativity and electrodynamics. However, such numbers are not very common in different programming languages. Of interest is the implementation of hyperbolic complex in scientific programming languages, in particular, in the Julia language. The Julia language is based on the concept of multiple dispatch. This concept is an extension of the concept of polymorphism for object-oriented programming languages. To implement hyperbolic complex numbers, the multiple dispatching approach of the Julia language was used. The result is a library that implements hyperbolic numbers. Based on the results of the study, we can conclude that the concept of multiple dispatching in scientific programming languages is convenient and natural.

Full Text

1. Introduction The Julia programming language [1, 2] is a promising language for scientific computing. At the moment, the Julia language has reached a stable state. By design, Julia solves the problem of two languages. This problem lies in the fact that for rapid prototyping, data processing and visualization, an interpreted dynamic language or a mathematical package (Python, Matlab, etc.) is used, and for intensive numerical calculations, the program has to be rewritten in a compiled language with static typing (C/ C++, Fortran). An illustration of this problem can be seen in Python, which has gained wide popularity as an interface language-glue. Numerous wrapper libraries were written on it, which used Python code to call C/C++ and Fortran functions from precompiled libraries. For example, the well-known library NumPy [3] consists of 51% C code and only 47% Python code (the remaining percentages are divided between C++, Fortran, JavaScript and Unix shell). The Julia language combines the flexibility of dynamically typed interpreted languages with the performance of statically typed compiled languages. The basic part of the Julia language is very similar to other scientific programming languages, so it does not cause difficulties in mastering. However, Julia’s core is built around the concept of multiple dispatch [4], which is rare in other languages. It is in this mechanism that the essential difference of Julia from other languages lies, and its understanding is essential for the full use of all the advantages of Julia. In the article, the authors paid great attention to illustrating the mechanism of multiple dispatch and other mechanisms that are closely related to it. In the first part of the article, we give the necessary definitions and illustrate the concept of multiple dispatch with simple examples that allow you to understand the syntax associated with this part of the language and capture the essence of this approach. In the second part, we give an example of the implementation of hyperbolic complex numbers in the Julia language. This example allows you to touch not only multiple dispatch, but also the type casting mechanism, the abstract type hierarchy, overloading arithmetic operators, and specifying user-defined data types. 2. Multiple dispatch 2.1. Common definitions Dynamic dispatch is a mechanism that allows you to choose which of the many implementations of a polymorphic function (or operator) should be called in a given case [5]. In this case, the choice of one or another implementation is carried out at the stage of program execution. Multiple dispatch is based on dynamic dispatch. In this case, the choice of implementation of a polymorphic function is made based on the type, number, and order of the function’s arguments. This is how runtime polymorphic dispatch is implemented [6, 7]. Note also that in addition to the term multiple dispatch, the term multimethod is also used. The mechanism of multiple dispatch is similar to the mechanism of overloading functions and operators, implemented, for example, in the C++ language. Function overloading, however, is done exclusively at compile time, while multiple dispatch should work at runtime as well (runtime polymorphism). 2.2. Multiple dispatch in Julia To illustrate the mechanism of multiple dispatch, we will give the following code example in the Julia language: function f(x, y) println("Generic implementation") return x + y end function f(x) println("For single argument") return x end function f(x::Integer, y::Integer) println("Implementation for integers") return x + y end function f(x::String, y::String) println("Implementation for strings") return x * " " * y end function f(x::Tuple{Int, Int}, y::Tuple{Int, Int}) println("Implementation for tuples of two integer elements") return (x[1], x[2], y[1], y[2]) end In this example, we have created five implementations of the
×

About the authors

Anna V. Korolkova

Peoples’ Friendship University of Russia (RUDN University)

Email: korolkova-av@rudn.ru
ORCID iD: 0000-0001-7141-7610

Docent, Candidate of Sciences in Physics and Mathematics, Associate Professor of Department of Applied Probability and Informatics

6, Miklukho-Maklaya St., Moscow, 117198, Russian Federation

Migran N. Gevorkyan

Peoples’ Friendship University of Russia (RUDN University)

Email: gevorkyan-mn@rudn.ru
ORCID iD: 0000-0002-4834-4895

Candidate of Sciences in Physics and Mathematics, Assistant Professor of Department of Applied Probability and Informatics

6, Miklukho-Maklaya St., Moscow, 117198, Russian Federation

Dmitry S. Kulyabov

Peoples’ Friendship University of Russia (RUDN University); Joint Institute for Nuclear Research

Author for correspondence.
Email: kulyabov-ds@rudn.ru
ORCID iD: 0000-0002-0877-7063

Professor, Doctor of Sciences in Physics and Mathematics, Professor at the Department of Applied Probability and Informatics

6, Miklukho-Maklaya St., Moscow, 117198, Russian Federation; 6, Joliot-Curie St., Dubna, Moscow Region, 141980, Russian Federation

References

  1. J. Bezanson, A. Edelman, S. Karpinski, and V. B. Shah, “Julia: A fresh approach to numerical computing,” SIAM Review, vol. 59, no. 1, pp. 65- 98, Jan. 2017. doi: 10.1137/141000671.
  2. M. N. Gevorkyan, D. S. Kulyabov, and L. A. Sevastyanov, “Review of Julia programming language for scientific computing,” in The 6th International Conference “Distributed Computing and Grid-technologies in Science and Education”, 2014, p. 27.
  3. T. E. Oliphant, Guide to NumPy, 2nd. CreateSpace Independent Publishing Platform, 2015.
  4. F. Zappa Nardelli, J. Belyakova, A. Pelenitsyn, B. Chung, J. Bezanson, and J. Vitek, “Julia subtyping: a rational reconstruction,” Proceedings of the ACM on Programming Languages, vol. 2, no. OOPSLA, pp. 1-27, Oct. 2018. doi: 10.1145/3276483.
  5. K. Driesen, U. Hölzle, and J. Vitek, “Message dispatch on pipelined processors,” in ECOOP’95 - Object-Oriented Programming, 9th European Conference, Åarhus, Denmark, August 7-11, 1995 (Lecture Notes in Computer Science), M. Tokoro and R. Pareschi, Eds., Lecture Notes in Computer Science. Springer Berlin Heidelberg, 1995, vol. 952. doi: 10.1007/3-540-49538-x_13.
  6. R. Muschevici, A. Potanin, E. Tempero, and J. Noble, “Multiple dispatch in practice,” in OOPSLA’08: Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applications, ACM Press, Oct. 2008, pp. 563-582. doi: 10.1145/1449764.1449808.
  7. S. Gowda, Y. Ma, A. Cheli, M. Gwóźzdź, V. B. Shah, A. Edelman, and C. Rackauckas, “High-performance symbolic-numerics via multiple dispatch,” ACM Communications in Computer Algebra, vol. 55, no. 3, pp. 92-96, Jan. 2022. doi: 10.1145/3511528.3511535.
  8. I. M. Yaglom, Complex numbers in Geometry. Academic Press, 1968, 243 pp.
  9. I. M. Yaglom, B. A. Rozenfel’d, and E. U. Yasinskaya, “Projective metrics,” Russian Mathematical Surveys, vol. 19, no. 5, pp. 49-107, Oct. 1964. doi: 10.1070/RM1964v019n05ABEH001159.
  10. D. S. Kulyabov, A. V. Korolkova, and L. A. Sevastianov, Complex numbers for relativistic operations, Dec. 2021. DOI: 10.20944/ preprints202112.0094.v1.
  11. D. S. Kulyabov, A. V. Korolkova, and M. N. Gevorkyan, “Hyperbolic numbers as Einstein numbers,” Journal of Physics: Conference Series, vol. 1557, 012027, pp. 012027.1-5, May 2020. doi: 10.1088/17426596/1557/1/012027.
  12. P. Fjelstad, “Extending special relativity via the perplex numbers,” American Journal of Physics, vol. 54, no. 5, pp. 416-422, May 1986. doi: 10.1119/1.14605.
  13. W. Band, “Comments on extending relativity via the perplex numbers,” American Journal of Physics, vol. 56, no. 5, pp. 469-469, May 1988. doi: 10.1119/1.15582.
  14. J. Rooney, “On the three types of complex number and planar transformations,” Environment and Planning B: Planning and Design, vol. 5, no. 1, pp. 89-99, 1978. doi: 10.1068/b050089.
  15. J. Rooney, “Generalised complex numbers in Mechanics,” in Advances on Theory and Practice of Robots and Manipulators, ser. Mechanisms and Machine Science, M. Ceccarelli and V. A. Glazunov, Eds., vol. 22, Cham: Springer International Publishing, 2014, pp. 55-62. doi: 10.1007/9783-319-07058-2_7.
  16. M. N. Gevorkyan, A. V. Korolkova, and D. S. Kulyabov, “Approaches to the implementation of generalized complex numbers in the Julia language,” in Workshop on information technology and scientific computing in the framework of the X International Conference Information and Telecommunication Technologies and Mathematical Modeling of High-Tech Systems (ITTMM-2020), ser. CEUR Workshop Proceedings, vol. 2639, Aachen, Apr. 2020, pp. 141-157.

Copyright (c) 2022 Korolkova A.V., Gevorkyan M.N., Kulyabov D.S.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

This website uses cookies

You consent to our cookies if you continue to use our website.

About Cookies