2
$\begingroup$

I'm working now with xAct in Mathematica obtaining huge list (around 50 000 terms) of contractions of a metric tensor with vector fields. I know that some elements of these list are multiplied for certain factor, let us call this for simplicity $f[x]$, and those elements should be deleted for consistency. So for example I will have

 List1={f[x]y,f[x]z,z^2,y,y^2,f[x]^2}; 

So a tried the simplest solution: divide the list by $f[x]$ and check the Denominator

 Redc=List1/(f[x]);
 Numc=Denominator[Redc];

Thus, if the Denominator is different from 1, I will keep that entry and delete the rest (from the original list). Unfortunately I could't find the solution. Perhaps It will be quite easy, but I'm not really expert on Mathematica. I appreciate any help. Thanks

$\endgroup$
  • $\begingroup$ what about DeleteCases? As in {f[x] y, f[x] z, z^2, y} // DeleteCases[f[x] _]. This won't delete the f[x]^2 instance, but it is easily adapted for those cases if that's what you needed $\endgroup$ – glS Nov 2 '16 at 20:14
2
$\begingroup$

I actually think that Position[] works best here, because it is more versatile than Cases[], and will also delete powers. If this still misses some instances of the function, such as Log[f[x]] you may need to look at FreeQ, this assumes that this is not the case.

list={y fx[x], z fx[x], z^2, y, y^2, fx[x]^2};
Delete[list, Partition[Position[list, fx[x]][[All, 1]], 1]]

{z^2, y, y^2}

$\endgroup$
  • $\begingroup$ Jesus!!..thank you so much @Feyre the solution works perfectly! :) $\endgroup$ – Alejandro Guarnizo Nov 2 '16 at 23:42
3
$\begingroup$
Cases[ List1, _?(FreeQ[f])]

or

DeleteCases[ List1,_?(!FreeQ[f][#]&)]

{z^2, y, y^2}

$\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.