0
$\begingroup$

I have a behavior that I don't understand.

I didn't found a way to have a smaller code to reproduce it, so here is the entire code (you really don't need to understand the functions in details to see and understand the problem)

In[19]:= SetOptions[$FrontEnd, "ClearEvaluationQueueOnKernelQuit" -> False]

In[20]:= Quit[]

In[1]:= Off[SixJSymbol::tri] (* On enlève les messages d'erreurs pour le 6j *)

In[2]:= SetOptions[$FrontEndSession, EvaluationCompletionAction -> "ShowTiming"]

In[3]:= alphaMoins[j1_,j2_,j3_,j4_,j5_,j6_]:=Module[{},

If[j4 >= 1/2,
(j4(j4+1))/(4*(2j4+1))*1/(j4^2)*Sqrt[(j4+j5-j3)(j4-j5+j3)(1-j4+j5+j3)(1+j4+j5+j3)]*Sqrt[(j4+j2-j6)(j4-j2+j6)(1-j4+j2+j6)(1+j4+j2+j6)],0]
];

alphaPlus[j1_,j2_,j3_,j4_,j5_,j6_]:=Module[{},
If[j4+1>=0,(j4*(j4+1))/(4*(2j4+1))*1/((j4+1)^2)*Sqrt[(1+j4+j5-j3)(1+j4-j5+j3)(-j4+j5+j3)(2+j4+j5+j3)]*Sqrt[(1+j4+j2-j6)(1+j4-j2+j6)(-j4+j2+j6)(2+j4+j2+j6)],0]

];

alpha0[j1_,j2_,j3_,j4_,j5_,j6_]:=If[j5==0 && j6==0, j4(j4+1),(j4(j4+1)+j5(j5+1)-j3(j3+1))(j4(j4+1)+j6(j6+1)-j2(j2+1))/4/j4/(j4+1)]
triple456[j1_,j2_,j3_,j4_,j5_,j6_]:=Module[{},

If[j4 > 0,
Return[alphaMoins[j1,j2,j3,j4,j5,j6]*SixJSymbol[{j1,j2,j3},{j4-1,j5,j6}]-alpha0[j1,j2,j3,j4,j5,j6]*SixJSymbol[{j1,j2,j3},{j4,j5,j6}]-alphaPlus[j1,j2,j3,j4,j5,j6]*SixJSymbol[{j1,j2,j3},{j4+1,j5,j6}]]
,Return[0]]

];

In[7]:= opVolume[j1_,j2_,j3_,j4_,j5_,j6_]:=Module[{},
1/4 (triple456[j1,j2,j3,j4,j5,j6]+triple456[j1,j5,j6,j4,j2,j3]+triple456[j4,j2,j6,j1,j5,j3]+triple456[j4,j5,j3,j1,j2,j6])
]

In[8]:= sommeTriple[j1_,j2_,j3_,j4_,j5_,j6_]:=(4*opVolume[j1,j2,j3,j4,j5,j6])

In[9]:= Clear[j1, j2, j3, j4, j5, j6]

In[10]:= zz = Inactivate[opVolume[j1, j2, j3, j4, j5, j6]]

Out[10]= Inactive[opVolume][j1, j2, j3, j4, j5, j6]

In[11]:= zz2 = Activate[zz]

Out[11]= 1/4 (If[j1 > 0, 
    Return[alphaMoins[j4, j2, j6, j1, j5, 
        j3] SixJSymbol[{j4, j2, j6}, {j1 - 1, j5, j3}] - 
      alpha0[j4, j2, j6, j1, j5, j3] SixJSymbol[{j4, j2, j6}, {j1, j5, j3}] - 
      alphaPlus[j4, j2, j6, j1, j5, 
        j3] SixJSymbol[{j4, j2, j6}, {j1 + 1, j5, j3}]], Return[0]] + 
   If[j1 > 0, 
    Return[alphaMoins[j4, j5, j3, j1, j2, 
        j6] SixJSymbol[{j4, j5, j3}, {j1 - 1, j2, j6}] - 
      alpha0[j4, j5, j3, j1, j2, j6] SixJSymbol[{j4, j5, j3}, {j1, j2, j6}] - 
      alphaPlus[j4, j5, j3, j1, j2, 
        j6] SixJSymbol[{j4, j5, j3}, {j1 + 1, j2, j6}]], Return[0]] + 
   If[j4 > 0, 
    Return[alphaMoins[j1, j2, j3, j4, j5, 
        j6] SixJSymbol[{j1, j2, j3}, {j4 - 1, j5, j6}] - 
      alpha0[j1, j2, j3, j4, j5, j6] SixJSymbol[{j1, j2, j3}, {j4, j5, j6}] - 
      alphaPlus[j1, j2, j3, j4, j5, 
        j6] SixJSymbol[{j1, j2, j3}, {j4 + 1, j5, j6}]], Return[0]] + 
   If[j4 > 0, 
    Return[alphaMoins[j1, j5, j6, j4, j2, 
        j3] SixJSymbol[{j1, j5, j6}, {j4 - 1, j2, j3}] - 
      alpha0[j1, j5, j6, j4, j2, j3] SixJSymbol[{j1, j5, j6}, {j4, j2, j3}] - 
      alphaPlus[j1, j5, j6, j4, j2, 
        j3] SixJSymbol[{j1, j5, j6}, {j4 + 1, j2, j3}]], Return[0]])

In[12]:= {j1, j2, j3, j4, j5, j6} = {1, 1, 1, 1, 1, 1}

Out[12]= {1, 1, 1, 1, 1, 1}

In[13]:= zz2

Out[13]= -(2/3)

In[14]:= Clear[j1, j2, j3, j4, j5, j6]

In[15]:= ww = Inactivate[sommeTriple[j1, j2, j3, j4, j5, j6]]

Out[15]= Inactive[sommeTriple][j1, j2, j3, j4, j5, j6]

In[16]:= ww2 = Activate[ww]

Out[16]= If[j1 > 0, 
  Return[alphaMoins[j4, j2, j6, j1, j5, 
      j3] SixJSymbol[{j4, j2, j6}, {j1 - 1, j5, j3}] - 
    alpha0[j4, j2, j6, j1, j5, j3] SixJSymbol[{j4, j2, j6}, {j1, j5, j3}] - 
    alphaPlus[j4, j2, j6, j1, j5, 
      j3] SixJSymbol[{j4, j2, j6}, {j1 + 1, j5, j3}]], Return[0]] + 
 If[j1 > 0, 
  Return[alphaMoins[j4, j5, j3, j1, j2, 
      j6] SixJSymbol[{j4, j5, j3}, {j1 - 1, j2, j6}] - 
    alpha0[j4, j5, j3, j1, j2, j6] SixJSymbol[{j4, j5, j3}, {j1, j2, j6}] - 
    alphaPlus[j4, j5, j3, j1, j2, 
      j6] SixJSymbol[{j4, j5, j3}, {j1 + 1, j2, j6}]], Return[0]] + 
 If[j4 > 0, 
  Return[alphaMoins[j1, j2, j3, j4, j5, 
      j6] SixJSymbol[{j1, j2, j3}, {j4 - 1, j5, j6}] - 
    alpha0[j1, j2, j3, j4, j5, j6] SixJSymbol[{j1, j2, j3}, {j4, j5, j6}] - 
    alphaPlus[j1, j2, j3, j4, j5, 
      j6] SixJSymbol[{j1, j2, j3}, {j4 + 1, j5, j6}]], Return[0]] + 
 If[j4 > 0, 
  Return[alphaMoins[j1, j5, j6, j4, j2, 
      j3] SixJSymbol[{j1, j5, j6}, {j4 - 1, j2, j3}] - 
    alpha0[j1, j5, j6, j4, j2, j3] SixJSymbol[{j1, j5, j6}, {j4, j2, j3}] - 
    alphaPlus[j1, j5, j6, j4, j2, 
      j3] SixJSymbol[{j1, j5, j6}, {j4 + 1, j2, j3}]], Return[0]]

In[17]:= {j1, j2, j3, j4, j5, j6} = {1, 1, 1, 1, 1, 1}

Out[17]= {1, 1, 1, 1, 1, 1}

In[18]:= ww2

Out[18]= 4 Return[-(2/3)]

The strange thing is that opVolume and sommeTriple are the same functions (only a *4 of difference).

And the behavior when I inactivate/activate one is different than for the others.

In the first case (variable zz2) I have (-2/3) as a result and in the other case (variable ww2) I have 4*Return[-(2/3)].

The question is : why do I have an unvealuated return in the second case ?

$\endgroup$
2
$\begingroup$

This is just an extended comment, but your problem has nothing to do with Inactivate and can be shown much more simply:

In[57]:= Clear[s]
r1 = If[s > 0, Return[1], Return[2]];
r2 = 2 If[s > 0, Return[1], Return[2]];

In[60]:= s = 1;
r1
r2

Out[61]= 1

Out[62]= 2 Return[1]

It's weird, yes, but Return is a weird symbol with ambiguous usage outside of its core case of returning from a Module.

$\endgroup$
  • $\begingroup$ Ok ! So I shouldn't use Return outside of a Module to avoid thoose strange behaviors if I understand well ? $\endgroup$ – StarBucK Jul 10 '17 at 13:42
  • 1
    $\begingroup$ @StarBucK I mean you can, but it's never entirely clear from what Return will be returning if you have a more complex functional chain than just a plain Module or something simple like a Scan. In any case when you see a raw Return now you know what's up. $\endgroup$ – b3m2a1 Jul 10 '17 at 13:45
  • 3
    $\begingroup$ @StarBucK mathematica.stackexchange.com/q/29353/5478, I have never had a case that I needed to use Return. You can make use of it but it is rather exotic expression and I recommend avoiding it. $\endgroup$ – Kuba Jul 10 '17 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.