2
$\begingroup$

I have an expression as below:

$-\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] A[c,h] A[d,v] \text{Cos}[\theta ]^2-\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v]^2 A[b,h] A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[a,h] A[a,v] A[b,v] A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[b,v] A[c,h] A[c,v] A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[b,h] A[c,v]^2 A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[a,h] A[a,v] A[b,h] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[a,h]^2 A[b,v] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[b,v] A[c,h]^2 A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[b,h] A[c,h] A[c,v] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[a,v] A[b,v] A[c,h] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] \text{Sin}[\theta ]^2-\frac{1}{2} A[a,h] A[b,h] A[c,v] A[d,v] \text{Sin}[\theta ]^2$

There are 16 terms here and every term has for function $A$.

In some terms the first parameter of four function $A$ are different from each other( a,b,c,d), in the other terms the four first paramenter are partial overlap(a,a,b,d;...).

how can I get the first kind. (the result is as below:)

$-\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] A[c,h] A[d,v] \text{Cos}[\theta ]^2-\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] \text{Cos}[\theta ]^2-\frac{1}{2} A[a,v] A[b,v] A[c,h] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] \text{Sin}[\theta ]^2-\frac{1}{2} A[a,h] A[b,h] A[c,v] A[d,v] \text{Sin}[\theta ]^2$

this is the input form for our mma:

 -(1/2) A[a, v] A[b, h] A[c, v] A[d, h] Cos[\[Theta]]^2 + 
 1/2 A[a, h] A[b, v] A[c, v] A[d, h] Cos[\[Theta]]^2 + 
 1/2 A[a, v] A[b, h] A[c, h] A[d, v] Cos[\[Theta]]^2 - 
 1/2 A[a, h] A[b, v] A[c, h] A[d, v] Cos[\[Theta]]^2 + 
 1/2 A[a, v]^2 A[b, h] A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
 1/2 A[a, h] A[a, v] A[b, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] + 
 1/2 A[b, v] A[c, h] A[c, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
 1/2 A[b, h] A[c, v]^2 A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
 1/2 A[a, h] A[a, v] A[b, h] A[d, v] Cos[\[Theta]] Sin[\[Theta]] + 
 1/2 A[a, h]^2 A[b, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] - 
 1/2 A[b, v] A[c, h]^2 A[d, v] Cos[\[Theta]] Sin[\[Theta]] + 
 1/2 A[b, h] A[c, h] A[c, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] - 
 1/2 A[a, v] A[b, v] A[c, h] A[d, h] Sin[\[Theta]]^2 + 
 1/2 A[a, v] A[b, h] A[c, v] A[d, h] Sin[\[Theta]]^2 + 
 1/2 A[a, h] A[b, v] A[c, h] A[d, v] Sin[\[Theta]]^2 - 
 1/2 A[a, h] A[b, h] A[c, v] A[d, v] Sin[\[Theta]]^2
$\endgroup$
1
  • $\begingroup$ Could you please paste this expression in a copyable form (i.e. plain Mathematica InputForm)? While $\LaTeX$ looks pretty and more readable for people, in this case we want to use the expression in Mathematica more than read it. $\endgroup$
    – Szabolcs
    Dec 11, 2012 at 15:44

3 Answers 3

5
$\begingroup$

In principle, you are saying that A[var1_, var2_] behaves kind of like a gamma matrix w.r.t. the first variable. So, you may want to create a replacement rule:

Clear[exp];

exp = -(1/2) A[a, v] A[b, h] A[c, v] A[d, h] Cos[\[Theta]]^2 + 
1/2 A[a, h] A[b, v] A[c, v] A[d, h] Cos[\[Theta]]^2 + 
1/2 A[a, v] A[b, h] A[c, h] A[d, v] Cos[\[Theta]]^2 - 
1/2 A[a, h] A[b, v] A[c, h] A[d, v] Cos[\[Theta]]^2 + 
1/2 A[a, v]^2 A[b, h] A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
1/2 A[a, h] A[a, v] A[b, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] + 
1/2 A[b, v] A[c, h] A[c, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
1/2 A[b, h] A[c, v]^2 A[d, h] Cos[\[Theta]] Sin[\[Theta]] - 
1/2 A[a, h] A[a, v] A[b, h] A[d, v] Cos[\[Theta]] Sin[\[Theta]] + 
1/2 A[a, h]^2 A[b, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] - 
1/2 A[b, v] A[c, h]^2 A[d, v] Cos[\[Theta]] Sin[\[Theta]] + 
1/2 A[b, h] A[c, h] A[c, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] - 
1/2 A[a, v] A[b, v] A[c, h] A[d, h] Sin[\[Theta]]^2 + 
1/2 A[a, v] A[b, h] A[c, v] A[d, h] Sin[\[Theta]]^2 + 
1/2 A[a, h] A[b, v] A[c, h] A[d, v] Sin[\[Theta]]^2 - 
1/2 A[a, h] A[b, h] A[c, v] A[d, v] Sin[\[Theta]]^2;

exp /. A[var_, var2_] A[var_, var3_] -> 0 /. A[_, _]^2 -> 0

which gives the output you want.

$\endgroup$
3
  • $\begingroup$ great! It is helpfull. $\endgroup$
    – cmc
    Dec 11, 2012 at 16:48
  • $\begingroup$ I like this one better than my answer. Slick! $\endgroup$
    – Mr.Wizard
    Dec 11, 2012 at 17:07
  • $\begingroup$ @Mr.Wizard :) thanks! $\endgroup$
    – gpap
    Dec 12, 2012 at 8:27
4
$\begingroup$

Filter your expression as follows:

expression // Cases[#, _ A[a, _] A[b, _] A[c, _] A[d, _]] & // Apply[Plus, #] &

Cases extracts all the terms in the sum that have the required structure and puts them in a list, then Apply converts the list back to a sum.

$\endgroup$
1
  • $\begingroup$ it does work very well. I love it very much. Thanks a lot. $\endgroup$
    – cmc
    Dec 11, 2012 at 16:44
2
$\begingroup$

Another pattern based approach, with your expression assigned to expr:

Plus @@
 Cases[
   expr,
   (Except[_A | _A^_] ..) x : _A .. /; UnsameQ @@ First /@ {x}
 ]
$\endgroup$

Your Answer

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

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