2
$\begingroup$

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!

asked Jul 15 at 22:58
$\endgroup$
5
  • 2
    $\begingroup$ Reading the package, I see the function MakeLinearMap has been used on several functions in the package, and these functions own further pattern restrictions and transformation rules, so my guess is, things like 5 x will never be an argument of fcn. 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$ Commented Jul 16 at 1:32
  • $\begingroup$ @xzczd I couldn't agree more, the package is hard to follow. It kind of feels like the documentation is incomplete. Do you understand why f[5 x] results an iteration error? That means mathematica is interpreting the definition recursively? Additionally, Do you think this error is thrown because the code is incompatible with 14? In that, either pattern restriction, or recursion have changed since '97? $\endgroup$ Commented Jul 16 at 2:34
  • 2
    $\begingroup$ The code f[P_Times] := f[Expand[P]] will run into an iteration error, because f[5 x] just becomes f[5 x], and so it will match again, evaluate to f[5 x], match again, etc. $\endgroup$ Commented Jul 16 at 3:06
  • $\begingroup$ @march thank you for confirming. It seems really obvious when you put it that way hahaha. I just learn pattern methods like P_Times today and haven't used recursion in mathematica before, so I felt like I needed to make sure I understood. Thank you! $\endgroup$ Commented Jul 16 at 3:18
  • 1
    $\begingroup$ In addition to march's comment: As far as I can tell, the package only uses core language feature that doesn't change these years. I believe the only incompatible part is the function name TensorProduct, which is now a built-in. Changing it to something like tensorProduct should make the package fully compatible with v14. $\endgroup$ Commented Jul 16 at 4:31

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.