-1
$\begingroup$

The following is a part of my codes.

codes: If[IsABeforeB[y1[[2]], y2[[2]], l] == 0, ( r = r + CommutatorOne[y1, y2, q1, q2, c, y, s, s1]; L1 = InterchangeAandB[i, i + 1, L1]; i = 1; ), i = i + 1; ]]; If IsABeforeB[y1[[2]], y2[[2]], l] == 0, then we do
( r = r + CommutatorOne[y1, y2, q1, q2, c, y, s, s1]; L1 = InterchangeAandB[i, i + 1, L1]; i = 1; ), I wrote the three lines inside a bracket (). If IsABeforeB[y1[[2]], y2[[2]], l] != 0, then let i = i + 1; Is the syntax of the codes correct? Can we use () here? Thank you very much.

The complete codes is in the following.

IndexOfAnElement[a_, l_] := ( r = 0; For[i = 1, i <= Length[l], i++, (If[a == l[[i]], (r = i; Break[])] )]; Return[r]);

IsABeforeB[a_, b_, l_] := ( i = IndexOfAnElement[a, l]; j = IndexOfAnElement[b, l]; r = 0; If[i <= j, r = 1; r = 0 ]; Return[r]); exponentNew[a_[b__]^c_] := c; exponentNew[a_[b__]] := 1; exponentNew[a_^c] := c; exponentNew[a_] := 1; headNew[a_[b__]^c_] := a; headNew[a_[b__]] := a; headNew[a_^c] := a; headNew[a_] := a; Indices[a_[b__]^c_] := {b}; Indices[a_[b__]] := {b}; Indices[a_] := {};

InterchangeAandB[i_, j_, l_] := ( r = l; temp = r[[i]]; r[[i]] = r[[j]]; r[[j]] = temp; Return[r]);

pthPowerNew[expr_, p_] := Replace[expr, s_Symbol :> s^p, Infinity, Heads -> False]; A test example is pthPowerNew[(2+x)/(2*c+3), p] CommutatorOne[l1_, l2_, q1_, q2_, c_, y_, s_, s1_] := ( y1 = headNew[l1[[2]]]; y2 = headNew[l2[[2]]]; {i, p} = Indices[l1[[2]]]; {j, p2} = Indices[l2[[2]]]; r = 0; If[{y1, y2} == {y, s} && p != 0 && p2 != 0, r = l1[[1]]*l2[[1]]*(-1/p)*(1 - q1^p)*KroneckerDelta[p, -p2]* KroneckerDelta[i, j]]; If[{y1, y2} == {s, y} && p != 0 && p2 != 0, r = l1[[1]]*l2[[1]]*(1/p2)*(1 - q1^p2)*KroneckerDelta[p, -p2]* KroneckerDelta[i, j]]; If[{y1, y2} == {s1, y} && p == 0 && p2 == 0, r = l1[[1]]*l2[[1]]*(-1)*Log[q1]*KroneckerDelta[i, j]]; If[{y1, y2} == {y, s1} && p == 0 && p2 == 0, r = l1[[1]]*l2[[1]]*Log[q1]*KroneckerDelta[i, j]]; If[{y1, y2} == {y, y} && p > 0, r = l1[[1]]*l2[[1]]*(-1/p)*(1 - q1^p)*(1 - q2^p)* pthPowerNew[Inverse[c][[j]][[i]], -p]*KroneckerDelta[p, -p2]]; If[{y1, y2} == {y, y} && p < 0, r = l1[[1]]*l2[[1]]*(-1/p)*(1 - q1^(-p))*(1 - q2^(-p))* pthPowerNew[Inverse[c][[i]][[j]], p]*KroneckerDelta[p, -p2]]; If[{y1, y2} == {s, s} && p > 0, r = l1[[1]]*l2[[1]]*(-1/p)*(1 - q1^p)/(1 - q2^(-p))* pthPowerNew[c[[i]][[j]], p]*KroneckerDelta[p, -p2]]; If[{y1, y2} == {s, s} && p < 0, r = l1[[1]]*l2[[1]]*(1/p2)*(1 - q1^p2)/(1 - q2^(-p2))* pthPowerNew[c[[j]][[i]], p2]*KroneckerDelta[p, -p2]]; If[{y1, y2} == {s1, s}, r = l1[[1]]*l2[[1]]*(Log[q1]/Log[q2])*pthPowerNew[c[[i]][[j]], 0]* KroneckerDelta[0, p2]]; If[{y1, y2} == {s, s1}, r = -l1[[1]]*l2[[1]]*(Log[q1]/Log[q2])*pthPowerNew[c[[j]][[i]], 0]* KroneckerDelta[p, 0]]; Return[r]); A test example is CommutatorOne[{w1^(p)*x^(p), y[1, -p]}, {x1^p, s[1, p]}, q1, q2, C1, y, s, s1] Normalization[l1_, l2_, q1_, q2_, c_, y_, s_, s1_, l_] := ( r = 0; L1 = Join[l1, l2]; i = 1; While[i <= Length[L1] - 1,
y1 = L1[[i]]; y2 = L1[[i + 1]]; If[IsABeforeB[y1[[2]], y2[[2]], l] == 0, ( r = r + CommutatorOne[y1, y2, q1, q2, c, y, s, s1]; L1 = InterchangeAandB[i, i + 1, L1]; i = 1; ), i = i + 1 ]]; r = Simplify[r]; Return[r]);

The function Normalization has some problems. A test example is Clear[y, s, s1, q1, q2]; l = {y[1, -p], s[1, -p], y[1, 0], s[1, 0], s1[1, 0], y[1, p], s[1, p]}; p = 7; q = q1*q2; C1 = {{1 + 1/(q1 q2), -(mu/(q1 q2))}, {-(1/mu), 1 + 1/(q1 q2)}}; T1 = {{w1^(p)*x^(p), y[1, -p]}, {w2^p*x^p, y[1, -p]}, {2, y[1, 0]}, {x^(-p)*w1^(-p), y[1, p]}, {x^(-p)*w2^(-p), y[1, p]}}; T2 = {{x1^p, s[1, -p]}, {Log[x1], s[1, 0]}, {1, s1[1, 0]}, {x1^(-p), s[1, p]}}; r1 = Normalization[T1, T2, q1, q2, C1, y, s, s1, l]

$\endgroup$
7
  • $\begingroup$ Please include the rest of your code so I can replicate the semantics on my machine? For example the code for the function IsABeforeB[a, b, c] @Jianrong $\endgroup$ Aug 20 '16 at 16:49
  • $\begingroup$ @Conor Cosnett, thank you very much for your help. I include the rest of my codes. It is long. All functions are correct except the function Normalization. $\endgroup$ Aug 20 '16 at 16:58
  • $\begingroup$ @Conor Cosnett, Clear[y, s, s1, q1, q2]; l = {y[1, -p], s[1, -p], y[1, 0], s[1, 0], s1[1, 0], y[1, p], s[1, p]} p = 7 q = q1*q2 C1 = {{1 + 1/(q1 q2), -(mu/(q1 q2))}, {-(1/mu), 1 + 1/(q1 q2)}} T1 = {{w1^(p)*x^(p), y[1, -p]} } T2 = {{x1^p, s[1, -p]} } r1 = Normalization[T1, T2, q1, q2, C1, y, s, s1, l] is a test example. The result should be 0. $\endgroup$ Aug 20 '16 at 16:59
  • $\begingroup$ Please format and explain your code more. @Jianrong. I have a headache now but I will try to understand it tomorrow. $\endgroup$ Aug 20 '16 at 19:26
  • 1
    $\begingroup$ @Conor Cosnett, thank you very much for your suggestions. $\endgroup$ Aug 21 '16 at 11:57
3
$\begingroup$

enter image description here

here is the syntax for a successful If.

Make sure you put in 2 commas!

If[
     a == b,

    (stuff;
     if;
     true),


   (stuff;
    if;
    false)


   ]
$\endgroup$

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.