I have recently "inherited" some Mathematica scripts which I need to interpret to write in some other languages (Maple and C++). I have never used Mathematica before so I have been learning on the job. There is a small block of code which I think I understand but would like some experienced answers/resources to explore it further. The code is the following:

A truncated example of the list environment is given at the top:

list = {0, 0, 0, a^2 b m (-1 + n) n (a^2 + b^2 - 2e), 0, 0, a b^2 l (-1 + n) n (a^2 + b^2 - 2e)}
k = 0;
i = 0;
  k = k + 1; 
  KK = list[[k]]; 
  If[KK =!= 0, 
    i = i + 1; 
    ff = Print[KK]; 
    CE[α, β, γ, l_, m_, n_] = ff], 
  {α, 0, 1}, {β, 0, 1}, {γ, 0, 1}];

list is another block which contains a large list of algebraic expressions which contain l, m and n (however no alpha, beta or gammas). My interpretation of this block is that it prints all the non zero elements and saves it into the CE function. My question boils down to the pattern matching in the function. I have done some reading via the Mathematica website and other resources and is the alpha, beta and gamma effectively being switched for their respective l, m and n labels which is then run over the range -1 -> 1? If the condition from the if statement is met, it then prints those terms?

From playing around with the code that appears to agree with the behaviour I am seeing, but is there a name or method associated with this?

I thought to seek help at this block as the next part seems to contain more complex pattern matching behaviour:

R[l_, m_, n_, l1_, m1_, n1_] := 
    If[(Abs[α] + Abs[β] + Abs[γ]) <= 3 ∧ n == n1 - γ, 
      CE[α, β, γ, l1 - α, m1 - β, n1 - γ] 
        (Sign[TS] T2[l1 - α, m1 - β, l, m] + 
          If[m == m1 - β ∧ l == l1 - α, (b + a)^2/(4 a b), 0]), 
    {γ, -1, 1}, {β, -1, 1}, {α,-1, 1}];

One final question, is there an equivalent pattern matching behaviour in Maple so as to write these blocks in Maple?

  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Jan 31, 2016 at 12:29
  • $\begingroup$ Related: (31804), (94110), though perhaps not helpful here. $\endgroup$
    – Michael E2
    Jan 31, 2016 at 12:42
  • $\begingroup$ There don't seem to be complex patterns in the definition of R. It would seem straightforward to translate it into any language (omit the underscores, change the brackets if necessary, etc.), but I don't know Maple. $\endgroup$
    – Michael E2
    Jan 31, 2016 at 12:49
  • $\begingroup$ Apologies for untidy code syntax in my original post. I have modified the post by adding an example of the list environment and changing the limits of alpha, beta and gamma. Hopefully that should be a minimal working example now. Thank you for the replies, it is very much appreciated. $\endgroup$
    – Yeti
    Jan 31, 2016 at 14:15
  • $\begingroup$ You should be aware that Print always returns Null, so ff = Print[KK]; CE[α, β, γ, l_, m_, n_] = ff defines certain forms of CE to be identically Null. This doesn't make a lot sense unless this has side effects on in the code surrounding the Do expression that you don't show us. $\endgroup$
    – m_goldberg
    Jan 31, 2016 at 14:45


Browse other questions tagged or ask your own question.