About GMac
On this page you can:
- Learn about the purpose of GMac and its possible uses.
- Read the main features of GMac for coding with Geometric Algebra, scripting, and prototyping.
- Understand the requirements of using GMac and where to download it from.
- Find a short description of GMac’s various components and links to the GMac User Guides.
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.
Coding with Geometric Algebra:
- A simple yet powerful computational Domain Specific Language, GMacDSL, that exposes the power of Geometric Algebra to geometric computing software applications.
- Using GMac, the user can define any number of fixed interrelated frames up to 15 dimensions of any signature.
- Through GMacDSL, the user can define combinatorial nested structures containing multivectors and scalar values to hold basic geometric computing blocks of data.
- GMacDSL provides a rich set of multivector operators to construct sophisticated computational symbolic expressions.
- GMacDSL gives the user the ability to define Geometric Macros, a simple form of parameterized geometric computing procedures based on Geometric Algebra multivector expressions. Geometric macros can call each other to provide simple encapsulation and code reuse capabilities.
- The GMacDSL user code is automatically parsed to an Abstract Syntax Tree; stored in the GMacAST component classes. The GMacAST structure is specifically designed to be effective when used for later scripting and code generation tasks by including comprehensive information about the semantics and relations of the code elements defined in the GMacDSL code.
Scripting and Prototyping:
- The GMac Scripting language is a syntactically simplified version of the powerful C# 4.0 language that can integrate C#, GMacDSL, and the Mathematica Language into a single scripting framework with limitless potential for geometric computing applications.
- The GMac Scripting engine can communicate with Mathematica to perform symbolic, as well as numeric, manipulations and read the results as symbolic expressions, text, or images through the powerful capabilities of the Mathematica computer algebra system.
- The GMac Scripting engine can access GMacAST structures to perform multivector manipulations and explore the underlying GMacDSL code effectively. This provides a valuable toolset for geometric computing application prototyping using Geometric Algebra at the core.
- The GMac Scripting engine glues everything together through C#, a powerful object-oriented general-purpose strongly-typed programming language. C# capabilities, like Linq, Regular Expressions, .NET Framework Access, etc. can be used at various levels of complexity to perform simple-to-sophisticated prototyping tasks including the integration and coordination of GMacDSL code and Mathematica symbolic and numeric manipulations.
Included Software Components:
- GMac includes the powerful text composition library TextComposerLib with all its capabilities intended for structured text generation including, but not limited to, code generation for any desired application.
- GMac also includes a simple wrapper, called SymbolicInterface, around Wolfram Mathematica .NET/Link interface. The SymbolicInterface component classes can be used to interface any desired .NET application with Wolfram Mathematica (as a backend symbolic processor) with ease through a fully managed object-oriented interface.
- The GMacAPI component classes are designed for software engineers to be effective at creating full software libraries for geometric computing applications based on Geometric Algebra models.
Documentation:
- Comprehensive online user guides providing many examples and explanations.
- Freely downloadable GMac samples providing more GMac use cases that will be updated regularly (coming soon).
- The GA Explorer Blog contains ideas and investigations that use GMac to explore Geometric Algebra constructions and applications.
To use GMac you need to have a Windows 7 or later operating system and the .NET Framework version 4.0. GMac depends on Wolfram Mathematica for its symbolic computations so you also need to install Mathematica version 7 or later. To take advantage of GMacAPI and its code generation capabilities you need to use GMac as a .NET components library so you need a .NET development environment like Visual Studio 2010 or later to use GMac in your .NET projects. For more information about installing GMac, you can read the GMac System Guide. For detailed information about all aspects of GMac, you can read the online GMac Guides.
You can download the latest version of GMac source code from GitHub at https://github.com/ga-explorer/GMac.
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 backend 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 easily 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 is a sophisticated compiler and code composition system based on Geometric Algebra. In order to fully understand and effectively use the GMac system, you need to study the GMac Guides carefully.
In addition to GMac guides, we will provide practical examples of using GMac for real geometric computing problems as tutorials and illustrations of the GMac system operation. You can find these examples in the GMac Samples page that will contain full source code and updated as new samples are created.