I have downloaded a differential forms package from 1997. It can be found here. I am trying to understand how the code works. I am am having some difficulty, and am hoping that someone can help me out. In particular, the second function in the second constructor given below, fcn[P_Times, C___] in MakeLinearMap, is giving me difficulty.
MakeLinearObject[obj_] :=
(obj /: obj[a_, x___] + obj[b_, x___] := obj[a + b, x];
obj /: a_ obj[c_, x___] := obj[a c, x] /; FreeQ[a, obj];
obj /: obj[0, x___] := 0)
MakeLinearMap[fcn_] :=
(fcn[S_Plus, C___] := fcn[#, C]& /@ S;
fcn[P_Times, C___] := fcn[Expand[P], C];
fcn[0, C___] := 0)
I am unfamiliar with pattern_Operator notation used. By examining the documentation, this seems to be a definition for fcn given that the first argument has a head of the operator in question. Experimentation with the first function in the constructor matches these expectations, seen below. Therefore, this first property defines the proper of distribution of linear maps over vector addition.
Clear[f]
f[x_Plus] := f[#] & /@ x
f[3 + 3]
f[x + y]
(*f[6]
f[x]+f[y]*)
Naturally, I expect the second function to define the compatibility of scalar multiplication with the linear map. In other words, if f is a linear map then $f(c\ \vec{v})= c \ f(\vec{v})$. However, experimenting with this second condition leads to an Iteration limit error. See code below.
Clear[f, a, x]
f[x_Plus] := f[#] & /@ x
f[P_Times] := f[Expand[P]]
f[0] := 0
f[x]
f[5 x]
Does anyone know why I am getting an error instead of the expect result of compatibility with scalar multiplication? Thanks in advance!
MakeLinearMaphas been used on several functions in the package, and these functions own further pattern restrictions and transformation rules, so my guess is, things like5 xwill never be an argument offcn. Sadly the package doesn't involve any example so it's hard to follow. (The corresponding article seems to never be online: web.archive.org/web/20171226050954/http://… ) $\endgroup$f[P_Times] := f[Expand[P]]will run into an iteration error, becausef[5 x]just becomesf[5 x], and so it will match again, evaluate tof[5 x], match again, etc. $\endgroup$TensorProduct, which is now a built-in. Changing it to something liketensorProductshould make the package fully compatible with v14. $\endgroup$