GALua
Geometric Algebra Library for the Lua Programming Language

Printing multivectors

Printing a multivector is super easy. One way to do it is as follows.

local multivec = 2 - 7*e1^e3 + 2*e2^e1 + e2 - e1^e2^e3
print( "multivec = " .. tostring( multivec ) )

Printing the multivectors of GALua is simply a matter of converting them to a string, and then printing the string. In general, there are two routines supported by the GALua module that provide conversion between string values and multivector values.

local multivec = galua_api.from_string( "2 - 7*e1^e3 + 2*e2^e1 + e2 - e1^e2^e3" )
local multivec_str = galua_api.to_string( multivec )
print( "multivec = " .. multivec_str )

These functions are designed to be inverses of one another. That is, strings created by galua_api.to_string(...) should be consumable by galua_api.from_string(...). As of this writing, there are some known bugs, but it works for the most part. (I know that's not very reassuring. The bugs will get fixed.)

You must be aware that the galua_api.from_string(...) function does not take a string interpreted as Lua code! Just what language is being interpreted by the galua_api.from_string(...) function is covered in an up-coming tutorial. For now, it is safest to only convert strings that are the basis vectors you have defined for your geometric algebra.

You should also be aware that the functionality provided by galua_api.to_string(...) and galua_api.from_string(...) is the same functionality being tapped by GALua's overload of the built-in tostring(...) function, as well as our function call syntax overload of the GALua API table, as well as coercion of strings encountered in mathematical expressions. The coercion process can be tapped directly by a use of calling the GALua API table. That is, if a variable blah holds the value of any Lua data-type, you may attempt to convert it to a multivector as follows.

local multivec = galua_api( blah )

An exception will be thrown, and the program will halt at this location, if a failure to perform the coercion occurs.

Though currently experimental, you may want to be aware of a latex option for printing. By calling galua_api.to_latex_string(...), you can generate a string for the given multivector value that may be compiled by latex for type-setting purposes. This feature is mainly useful in conjunction with the limited support for symbolic manipulation in the underlying GA computation engine of GALua. The coverage of such support is beyond the scope of these tutorials. However, if you would like to type-set any numerical multivector value, (as apposed to an abstract variable multivector value), you may use galua_api.to_latex_string(...) to do so.

Manipulating multivectors

Copyright (C) 2013, by Spencer T. Parkin