Blades Library Composer

Blades Library Composer

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.


In this post, I will explain the details of the Blades Library Composer GMac project. The purpose of this project is to generate a C# library to compute with GA blades of any frame. Here we use GMacAPI and TextComposerLib to compose the blades library code according to a selected design. In order to thoroughly follow this post, it’s better to have a good understanding of C#. Nevertheless, all the library composition code can be re-written using any .NET language and the generated code design can also be adapted to other target languages.

The objectives of composing this library are:

  • To represent arbitrary blades in any desired GA frame using simple arrays in C#.
  • To perform GA operations and products on blades as efficiently as we can.
  • To illustrate how to use Geometric Algebra, GMac, and TextComposerLib for simplifying this complex task with minimal errors and maintenance effort.

First Steps

To follow the illustrations in this post you first need to download and install the GMacSamples .NET solution as explained in the GMac Samples page. You will find the source code for this post under the BladesLibraryComposer project. Make sure all references to GMac and Mathematica are set correctly and set the BladesLibraryComposer as the startup project. Now if you run the solution you see a screen like the following:

BladesComposerLib Main Screen

As we can see, the interface is really simple. It contains the following elements:

  • Using the Output Folder text box and the Browse button you can select an output folder where the generated code will be put.
  • Using the GMacDSL Code list box you can select the GMacDSL code containing definitions for GA frames used for composing the library.
  • Using the Generate Macro Code checkbox you can select whether or not to generate full computational code in the library. It’s better to leave this unchecked if you just want to inspect the general structure of the generated library. If you choose to generate the full code this would take longer because many symbolic computations are involved.
  • Using the Target Language list box you select the target language of the generated library. Currently, only C# can be used.
  • Finally, you press the Compose Code button to begin the library generation process.

By inspecting the code of this screen in the project you can easily understand its function. You can find the code in the FormMain.cs file under the BladesLibraryComposer project.

Library Design

If you use GMacAPI to compose your own GA-based code library you first need to decide on the high-level code design of your generated library. Since our first objective is to represent blades, I will start by explaining this point.

In Geometric Algebra, a k-blade is a special type of multivectors having the same grade k and resulting from the outer product of k linearly independent vectors. Using the additive representation of multivectors we can store the real coefficients of multivectors as an array of double-precision floating point numbers. For our design, each blade

Then we can

WordPress Appliance - Powered by TurnKey Linux