NewGlyph := module () description "Basic Geometric Algebra Functions"; local setup, cleanup; global e; export GAversion,GAinit, GAadd_metric,GAmetric,GAmv; option package, load = setup, unload = cleanup; setup := proc () TypeTools:-AddType(`blade`, proc (a) type(a, indexed) and op(0, a) = 'e' end proc); GAversion(); GAinit(); end proc; setup(); cleanup:=proc() TypeTools:-RemoveType(`blade`); end proc; GAinit := proc() global `&@`, `&.`, `&^`, `&x`, `&s` , `&/`, `&l`, `&v`; protect('`&@`','`&.`', '`&^`', '`&x`', '`&s`', '`&/`', '`&l`', '`&v`'); GAadd_metric('default', signum, -infinity, infinity); GAadd_metric('SA', proc () 1 end proc, 1, 3); GAadd_metric('STA', proc (i) `if`(i = 0, 1, -1) end proc, 0, 3); GAadd_metric('MSTA', proc (i) `if`(modp(i, 4) = 0, 1, -1) end proc, 0, infinity); GAadd_metric('Homogeneous', proc () 1 end proc, 0, infinity); GAadd_metric('Conformal', proc (i) `if`(i = -1, -1, 1) end proc, -1, infinity); GAmetric('default'); end proc: GAversion := proc () print(`GA Package`); print(`Version 2.0`); print(`Written by: Mark Ashdown, maja1@mrao.cam.ac.uk`); print(`Extended by: Alan Macdonald, macdonal@luther.edu`); print(`Re-Packaged for Maple 2018 by: Ian McCreath`); end proc; GAadd_metric := proc (fred::name, signature::procedure, minind::{integer, infinity}, maxind::{integer, infinity}) global MetricTable; unprotect('MetricTable'); MetricTable['fred'][sig] := eval(signature); if maxind < minind then ERROR(`The minimum index is greater than the maximum index`) end if; MetricTable['fred'][min] := minind; MetricTable['fred'][max] := maxind; protect('MetricTable'); print(`The GA package knows about metric ` . fred . `.`) end proc: GAmetric := proc (a::name) global Metric, Sig, MetricTable, MinIndex, MaxIndex; if member([a], [indices(MetricTable)]) then unprotect('Metric', 'Sig', 'MinIndex', 'MaxIndex'); Metric := a; Sig := MetricTable[Metric][sig]; MinIndex := MetricTable[Metric][min]; MaxIndex := MetricTable[Metric][max]; protect('Metric', 'Sig', 'MinIndex', 'MaxIndex'); print(`Metric is now set to: ` . Metric) else ERROR(`The metric ` . a . ` is unknown to the GA package`) end if end proc: # Creates multivector with name x of with grade or set of grades g with # indices ind GAmv := proc(x::name,g::{nonnegint,set(nonnegint)},ind::set(integer)) local i; if g::set then add(procname(x,i,ind), i=g) elif g > nops(ind) then ERROR(`grade too large for number of indices.`) elif g=0 then x[NULL] else add(x[op(i)]*e[op(i)], i=combinat:-choose(sort([op(ind)]),g)) end if end: end module;