GMac, short for “Geometric Macro“, is a .NET based software system that allows implementing geometric models and algorithms based on Geometric Algebra (GA) in arbitrary target programming languages.
The core part of GMac is the GMacCompiler, a transcompiler or source-to-source translator that accepts code written in a simple high-level domain-specific language (GMacDSL), and can be configured using GMacAPI to output very efficient low-level code in any desired target programming language. The ultimate goal behind creating GMac is to allow Geometric Computing (GC) implementations to be as flexible, organized, and efficient as possible. Although GMac is originally created using C#, it can be configured to generate a set of textual code files in any desired structure using an API that is accessible through any .NET language including C++, C#, VB.NET, F#, and IronPython among others.
The main ideas behind GMac date back to my 2010 Ph.D. dissertation that can be found at https://arxiv.org/abs/1607.04767. GMac is intended to be a sophisticated software system for implementing Geometric Algebra algorithms in an efficient manner to narrow the gap between practical software engineering and GA-based geometric modeling in order to enable GA to gain wider acceptance among software designers, as well as researchers. I strongly believe Geometric Algebra rightly deserves to become the main mathematical language for teaching and representing geometric models in computer science and engineering in the very near future.
GMac is a “geometric computing design aid” that can be efficiently and creatively used to implement important aspects of a wide spectrum of geometric computing applications. If we take a look at the GMac system diagram we can see 4 types of users; they are actually 4 roles that an actual user may have two or more of them at once:
Geometric Computing System User: The end-goal of any geometric computing system is to provide computational services to its users. But the kinds of interfaces, computations, and data exchange in a GC system are geometric in essence. Examples of GC systems include computational geometry, computer graphics, CAD\CAM, robotics, computer vision, engineering and many others. Each system is unique in its specific requirements and possible users but they all enjoy a common base of geometric ideas deserving a unified development methodology; just like data-driven and object-oriented software design and tools serve many diverse areas of computing.
Geometric Computing System Designer: To satisfy the geometric computing requirements of the users, the GC system designer must have a set of methods and tools to ease the design and development of his GC system. GMac is one such tool that uses well-established software engineering techniques (a DSL-based optimizing compiler with a configurable text generator) based on the fascinating and universal mathematical language of Geometric Algebra to translate many abstract geometric ideas into optimized code that is both efficient to execute and flexible to shape into the final GC system design.
Geometric Algebra Model Designer: The GA model designer is a person having a geometric idea and wishing to investigate, interact, and eventually implement it. The use of Geometric Algebra as a universal model for geometry goes most of the way into these goals. What remains is translating GA equations and algebraic processes into a working prototype using GMac‘s simple and effective GA-based domain-specific language GMacDSL. The resulting intermediate GMacAST can be then used to provide interactive scripting for the GA model designer\user and structured code generation for the GC system designer.
Geometric Algebra Model User: Often a GA model is general enough that it can be used to interactively investigate many geometric ideas at once. For example, the whole of the very powerful Cinderella interactive geometry system is based on a single GA model; the 2D conformal geometry model on complex scalars. After designing the GA model any number of users can use it as a prototype for studying geometric ideas expressible by that model.
The various GMac system components will never be complete, they are under continuous development to mature into an incrementally useful system. Some features will be added in time, but the basic architecture described here will remain unchanged:
GMacCompiler: This is the core of GMac, a source-to-source compiler that can generate an Abstract Syntax Tree (GMacAST) from a GA-based Domain-Specific Language (GMacDSL) code. The GMacCompiler is an optimizing transcompiler; it can perform high-level domain-specific optimizations backed up by a powerful Computer Algebra System (CAS), like Mathematica or Python’s SymPy for example, to generate the desired code. The GMacCompiler has two sub-components:
- The GMacCompiler Front End: The main role of the front end is to translate GMacDSL code into a GMacAST structure. The front end follows the traditional lexer>parser>semantic analyzer sequence of compiler front ends. It interacts with the GMacIDE, the user interface of GMac, by accepting GMacDSL code and reporting any errors in the code through the GMacIDE interface. It also occasionally requests symbolic computations from the CAS to complete the translation process successfully.
- The GMacCompiler Back End: The back end is responsible for generating text code from the GMacAST structure translated from GMacDSL code. The generation process is highly configurable through an Application Programming Interface (GMacAPI). Using GMacAPI we can reshape with full control the information abstractly encoded in the GMacAST structure into text files having any desired folder, file, and text structure. We can select a target language to convert GMacDSL macros into executable code in a given target language. The GMacAPI infrastructure can be extended easily to add more target languages as desired.
GMacDSL: The use of GA for expressing geometric ideas is very effective. GMacDSL is designed to be a good and simple expressive language for general GA operations on multivectors in any arbitrary GA model of geometry. GMacDSL is not Turing-Complete; it has no looping or conditional branching constructs. These constructs are left for the main GC system application code and the GMac scripting engine. GMacDSL primarily focuses on representing geometric objects in two main ways:
- Direct representation using multivectors of some GA frame.
- Non-recursive combinatorial structures of multivectors and scalars.
GMacDSL also focuses on implementing GA operations on these two types of representations using Geometric Macros: solid parametric blocks containing a sequence of simple commands that assign GA computational expressions to local and output variables of the block. The GMacCompiler front end translates GMacDSL code into GMacAST structures that can be used for interactive scripting through GMacIDE, or for configurable code generation through the GMacCompiler back end and GMacAPI.
GMacAST: When a GA model encoded in GMacDSL has compiled into an Abstract Syntax Tree it is ready for many interesting uses through scripting and code generation. The GMacAST is a set of simple .NET classes that are written in C# but accessible through any .NET language to hold the minimum necessary abstract information for code generation and scripting interaction processes. The GMacAST is accessible through GMacIDE and GMacAPI. Learning the full structure of GMacAST as provided by the GMacAST Guide is necessary for effective use of the GMac system.
GMac Scripting: After we have a GMacAST we can easily interact with it computationally through the GMac scripting engine to test the GA model we encoded with GMacDSL. Scripting can provide many insights into the GA model prototype we created. Scripting also provides more computational power to GA models implemented in the non-Turing-Complete GMacDSL like looping, conditional branching, and others.
GMacAPI: The GMacCompiler back end can be configured using GMacAPI to generate efficient text code in any desired language. GMacAPI is a set of .NET classes created with C# but usable by any .NET language (C++, C#, VB.NET, F#, IronPython, etc.) to specify how to use the information and geometric macros encoded in the GMacAST structure to generate files with desired structure in terms of folders, files, and text. GMacAPI has a set of classes specifically designed for easy controllable template-based or free text generation from arbitrary sources. GMacAPI can also specify binding patterns to associate target language variables or constant values with parts of input parameters to the geometric macros. The net result is a flexible, powerful, and efficient means for implementing configurable low-level code generation from GMacDSL GA-based high-level code.
GMacIDE: This is the main user interface of GMac where we can write GMacDSL code, interact with the GMacCompiler, and use the GMac scripting engine. The main interaction services GMacIDE can provide are:
- Write GMacDSL source code with the help of a project management and code highlighting capable interface.
- Compile GMacDSL code into a GMacAST structure and report any errors in the code.
- Explore the details of the compiled GMacAST in various ways.
- Explore a single high-level geometric macro to see how it translates into low-level code with some statistics on the intermediate optimizations performed.
- Interact with the compiled GMacAST computationally through the GMac scripting engine.
- Provide an extendable interface for generating a set of useful code libraries using a given GMacAST structure.
GMac Guides: GMac can be used to create structured code based on GA models of geometric concepts. In order to fully understand and effectively use the GMac system, we need to study the GMac Guides carefully. Here we will provide several user guides to the GMac components including:
- GMac System Guide: Describes the GMac system, installation, and user interface with examples.
- GMac Math Guide: Describes the custom OOP interface library for communicating with the Mathematica symbolic computing system for performing symbolic operations on GA multivectors. The library is originally designed for GMac, but usable for any other similar system.
- GMacDSL Guide: Describes the syntax of the GMacDSL language providing examples for its use.
- GMacAST Guide: Describes the construction of the GMacAST data structure that is the main intermediate information source for code generation and scripting in GMac.
- TextComposerLib Guide: Describes a custom text composition library made specifically for GMac but very useful by itself for general text composition applications.
- GMacAPI Guide: The most important, and longest, of all GMac Guides. This guide describes the processes, classes, and implementation examples for generating structured code from GMacDSL code for any target language.
- GMac Scripting Guide: Describes the scripting capabilities of GMac that enable GA-based model creators to explore their creations.
In addition to GMac guides, we will provide many practical examples of using GMac for real geometric computing problems as tutorials and illustrations of the GMac system operation. These examples will be provided on the blog of this website in addition to the GMac Samples page that will contain full source code and updated as new samples are created.