Let's make some functions for symbolic calculations with wedge products! There are many ways to accomplish this, let us start with a suboptimal way and see how we can improve it. We need some kind of organized storage for our expression and Julia has a well developed type system so let's define a custom type:
type PForm <: Form #PForm is part of the Form family
forms #an array of the differentials
p #length of forms
PForm(f)=(pf=new(f); pf.p=()->length(pf.forms); pf) #p is automatically defined at type initialization
end
Now what is suboptimal about this? One thing is that the p has to be called as a function to obtain the number of forms, adding a pair of parentheses is not the most work intense task however something has to have motivated the creation of a function instead of just assigning the length of forms at initiation to p, and that motivation is to allow the length of forms to change. With such an allowance the wedge products can be constructed without initiating new types:
function ∧(f1::Differential,f2::Differential)
PForm([f1,f2])
end
function ∧(pf::PForm,f::Differential)
push!(pf.forms,f)
pf #We need be careful here, since the last value is returned if we don't make it the whole PForm only the forms field will be returned.
end
function ∧(f::Differential,pf::PForm)
insert!(pf.forms,1,f)
pf
end
Now ∧ is a specific operator symbol which can be called as other primal operations such as * and /, a list of operator symbols in Julia can be found here.