MoebInv: C++ libraries for manipulations in non-Euclidean geometry

The introduced package MoebInv contains two CPP libraries for symbolic, numeric and graphical manipulations in non-Euclidean geometry. The first library cycle implements basic geometric operations on cycles, which are the zero sets of certain polynomials of degree two. The second library figure operates on ensembles of cycles interconnected by Moebius-invariant relations: orthogonality, tangency, etc. Both libraries work in spaces with any dimension and arbitrary signatures of their metrics. Their essential functionality is accessible in interactive modes from Python/Jupyter shells and a dedicated Graphical User Interface. The latter does not require any coding skills and can be used in education. The package is tested on (and supplied for) various Linux distributions, Windows 10, Mac OS X and several cloud services.


Introduction
We present the Open Source package MoebInv [1, 2]-a research and educational tool for various geometric setups. Its domain, design and functionality have some unique features which are not available elsewhere. The code is symbiotically growing together with the research in the extended Möbius-Lie geometry [3], both-the code and the theory-benefited from this interaction. Functionality of the package is accessible from a C ++ code and can be interactively used through Python/Jupyter shells and a dedicated Graphical User Interface (GUI).
There is already a collection of well-established and reputable Open Source geometry software (GeoGebra [4], CaRMetal [5], Kig [6], Dr. Geo [7]) as well as commercial educational packages (The Geometer's Sketchpad, Cabri, Cinderella, NetPad). All of those are designed to work primary with the Euclidean geometry-the oldest archetypal mathematical theory. Nowadays it is the first from a large family of various geometries: affine, projective, conformal, Riemannian, etc. According to F. Klein's Erlangen programme (which was influenced by S. Lie), a geometry studies invariant properties under a certain transitive group action.
The package MoebInv works with invariants of fractional linear transformations (FLT) which contain Möbius maps as an important subset. The implementation admits spaces of any (including symbolic) dimensionality and arbitrary signatures of metric (covering the degenerate cases). The associated geometries span a wide domain, which includes conformal [8,Ch. 9], hypercomplex [9] and Lie sphere geometries [10,11,12]. For these fields the package facilitates: • Experiments and research.
• Automated theorem proving and symbolic calculation.
• Visualisation and interactive manipulations.
• Exact arithmetic and high precision numeric evaluation.
• Programming extensions of functionality.
• Educational usage (starting from school and college levels) which does not require any coding skills. For sake of simplicity we illustrate this paper by the fundamental and most visual case of fractional linear transformations (FLT) of the complex plane defined by 2 × 2 complex matrices [8,Ch. 9]: where z ∈ C and det a b c d = 0.
A FLT-invariant family of objects unifies circles, lines and points-all together are called cycles in this framework. A FLT-invariant relations between cycles include incidence, orthogonality, tangency, etc. The efficiency of the package MoebInv is based on the mathematical formalism [2,13] which encodes the variety of different FLT-invariant relations between cycles in a unified way. Besides aesthetical value the conformal and Möbius-Lie geometries have countless applications ranging from quantum spin dynamics [14], cosmology [15] and integrable systems [16] to computer-aided design [17] and physiological models [18].

Problems and Background
From the point of view of synthetic Euclidean geometry a cycle (2D sphere) is the locus of points on a distance R from a given point (x 0 , y 0 ). Its analytic description is encoded in a quadratic equation: where l = kx 0 , n = ky 0 , and m = l 2 + n 2 − R 2 for an arbitrary k = 0. Although it is theoretically sufficient for analytic solutions of various geometrical problems, practically its non-linearity produces rapidly increasing complexity of expression in symbolic computations and growing rounding errors in numeric evaluations. It was only relatively recently realised [19,20] that the space of all spheres possesses a FLT-invariant inner product, which naturally encodes many fundamental geometric relations-the orthogonality to be the most important among them. In addition there is significant set of FLT-invariant geometric relations, e.g. tangency, Steiner power, which are genially quadratic. Analytic solutions of several simultaneous quadratic relations may be very involved. Fortunately, it was observed [21,2] that there is a possibility to reduce such problem to a set of only one quadratic relation and several linear ones. Such a set admits an effective algorithmic solution even in symbolic setup, which is the backbone of the package MoebInv.
More specifically, the first library cycle [1,13,22] manipulates individual cycles within the GiNaC [23] computer algebra system. The mathematical formalism employed in the library cycle is based on Clifford algebras and the Fillmore-Springer-Cnops construction (FSCc), which has a long history, see [24, § 1.1], [20, § 4.1], [19], [25, § 4.2], [26], [13, § 4.2]. Compared to a plain analytical treatment [27,11], FSCc is much more efficient and conceptually coherent in dealing with FLT-invariant properties of cycles. Correspondingly, the computer code based on FSCc is easy to write and maintain. The second library figure manipulates ensembles of cycles (quadrics) interrelated by certain FLT-invariant geometric conditions. There are methods to add, modify and delete elements of the figure as described in the next section.

Software Framework
The library figure implements the functional programming framework-in contrast to procedural approach used in popular software packages like GeoGebra [4], CaRMetal [5], Kig [6], Dr. Geo [7]. The later provides a fixed set of geometric construction procedures, e.g. "find the midpoint of an interval", "drop the perpendicular from a point to a line". In contrast, all new cycles in class figure are added through a list of defining relations, which links the new cycle to already existing ones 1 .
3.1. Software Architecture. Thinking a cycle ensemble as a graph, one can say that the library cycle deals with individual vertices (cycles), while figure considers edges (relations between pairs of cycles) and the whole graph. Intuitively, an interaction with the library figure reminds compass-and-straightedge constructions, where new lines, points or circles are added to a drawing one-by-one through relations to already presented objects (e.g. the line through two points, the intersection point or the circle with given centre and a point). To avoid "chicken or the egg" dilemma all cycles are stored in a hierarchical structure of generations, numbered by integers. The basic principles are: (1) Any explicitly defined cycle (i.e., a cycle which is not related to any previously known cycle) is placed into generation-0; (2) Any new cycle defined by relations to previous cycles from generations k 1 , k 2 , . . . , k n is placed to the generation k calculated as: This rule has an exception that a cycle may have a relation to itself, e.g. isotropy (self-orthogonality) condition C , C = 0, which specifies point-like cycles. If the number or nature of conditions is not sufficient to define the cycle uniquely (up to natural quadratic multiplicity), then the cycle will depend on a number of free (symbolic) variables.
3.2. Software Functionalities. Both libraries are capable to work in spaces of any dimensionality and metrics with an arbitrary signatures: Euclidean, Minkowski and even degenerate. Parameters of objects can be symbolic or numeric, the latter admit calculations with exact or approximate arithmetic. Drawing routines work with any (elliptic, parabolic or hyperbolic) metric in two dimensions trough Asymptote [28] software.
There is a macro-like tool, which is called subfigure. Such a subfigure is a figure itself, such that its inner hierarchy of generations and relations is not visible from the current figure. Instead, some cycles (of any generations) of the current figure are used as predefined cycles of generation-0 of subfigure. Then only one dependent cycle of subfigure, which is known as result, is returned back to the current figure. The generation of the result is calculated from generations of input cycles by the same formula (3).
There is a possibility to test certain conditions (e.g., "are two cycles orthogonal?") or measure certain quantities (e.g., "what is their intersection angle?") for already defined cycles. In particular, such methods can be used to prove geometrical statements according to the Cartesian programme, that is replacing the synthetic geometry by purely algebraic manipulations. Besides C ++ libraries there is a Python wrapper, which can be used in interactive mode. It is accessible through cloud computing on several hosts [29,30] with sample Jupyter notebooks. There is a Graphical User Interface (GUI), which allows to create figures by mouse clicks. Python/Jupyterand GUI are bidirectionally integrated by data exchange routines. There are two-binary and human-readable/editable-formats provided for this purpose.
Metrics of the point space and the cycle spaces do not need to coincide. Similar bi-metric models was used recently to tackle the quantum Hall effect [31]. 1 In fact, it is possible and useful to include relations of a new cycle to itself as well. For example, points are defined by the condition to be self-orthogonal. Figure 1. The illustration of the conformal nine-points theorem discovered with MoebInv package. The left column is the statement for a triangle with straight sides, the right column is its conformal version. The first row show the elliptic point space, the second row-the hyperbolic point space.

Illustrative Examples
As an elementary demonstration, we an analytic proof of a geometrical statement from Jupyter notebooks [29,30]. Let P be a point of contact of a cycle a and its tangent l. We will show that a radius r of the cycle a to the point P is orthogonal to the line l. To simplify setup we assume that a is the unit circle.
First, we need to load libraries (assuming software installation is already done).
[1]: from figure import * Then, we initialise a figure F with a default Euclidean metric. Then, we add the centre C of a as a specific point: [4]: C=F.add_point(cycle2D(F.get_cycle(a)[0]).center(), "C") Now, we want to add a line l tangent to a. A straight line is characterised among cycles by its orthogonality to infinity ("passes the infinity"). The line l is not uniquely defined by these two conditions (the tangency and orthogonality) because the point of its contact to a can be arbitrary. Therefore its coefficients contain a free variable like t_l as can be seen from the figure printout. Note, that the parametrisation of the line l uses trigonometric functions in order to avoid square roots appearing in the solutions of the quadratic tangency relation. With such substitution automatic simplifications of algebraic expressions are much more efficient.
At the next step we add the point P of contact of the circle a and the line l. A point belongs to a cycle if the point is orthogonal the cycle. Also a point is characterised among all cycle by orthogonality to itself. To define the latter reflexive condition we need to "pre-cook" its symbol in advance.
[7]: r=F.add_cycle_rel([is_orthogonal(P), is_orthogonal(C),\ is_orthogonal(F.get_infinity())], "r") Recall, that r depends on the same free parameters as l. Now, we check the orthogonality relation between r and l. Because two of the above conditions were quadratic (i.e., tangency and self-orthogonality), each of them doubled the number of solutions. Therefore, there are four instances of the cycle r, and each of them is checked separately.
Many more examples of computer-assisted proofs were presented in [13] and are freely available for evaluation at [29,30].

Software Impact
The first library cycle was initially reported in [1] and since then was employed as the main research tool in several papers [26,22] and monograph [13]. New results, e.g. elliptic and hyperbolic conformal version of the nine-point theorem, discovered with the second library figure were published in [2,3], cf. Fig. 1. The package has several different uses: • It is easy to produce high-quality illustrations, which are fully-accurate with automatic evaluation of cycles' parameters, cf. Fig. 2 • The package can be used for computer experiments in Möbius-Lie geometry.
• Since the library is based on the GiNaC system, which provides a symbolic computation engine, there is a possibility to make fully automatic proofs of various statements in Möbius-Lie geometry, see the previous Section. • Last but not least, the combination of classical beauty of Lie sphere geometry and modern computer technologies is a useful pedagogical tool to widen interest in mathematics through visual and hands-on experience. A dedicated GUI makes it accessible for all schoolchildren. Several videos created with the package are uploaded to the popular video hosting [32] to disseminate aesthetical attraction of mathematics to wider public.
As a non-trivial example of automated proof accomplished by the figure library for the first time, we present a FLT-invariant version of the classical nine-point theorem [2,3], which is illustrated in the attached video.

Conclusions
The package accumulates more than 15 years of work and is still under active development. The design of the library figure shaped the general theoretical approach to the extension of Möbius-Lie geometry [2,3], which leaded to specific realisations in [33,34,35]. Furthermore, it shall be helpful for computer experiments in Lie sphere geometry of indefinite or nilpotent metrics since our intuition is not elaborated there in contrast to the Euclidean space [22,26,36]. Some advances in the two-dimensional space were achieved recently [13,37], however further developments in higher dimensions are still awaiting their researchers.
The current version (v3.5.7) of the package was tested on major desktop platforms: Linux (Debian, Ubuntu and CentOS distributions), Windows 10, Mac OS X. Pre-compiled binaries for these OSes are provided on the project Web page [2]. The interactive Python/Jupyter shells can be used from cloud services CoLab [30] and CodeOcean [29].