2
$\begingroup$

I have a functional polynomial expression of the form:

expr = f[x] + f[x] g[w] + Conjugate[f[y]] g[z] +
       Conjugate[g[z]] + g[w] + f[x] f[y] g[w] + 1 +
       Conjugate[a] f[t] + Conjugate[b] Conjugate[c]

I would like to write a function that selects terms that are up to linear (i.e. zero and first order) in the functions f and g, eg. in my case the correct output would be:

1 + f[x] + Conjugate[g[z]] + g[w] + Conjugate[a] f[t] +
Conjugate[b] Conjugate[c] 

Note that the functions are complex, and the conjugate terms are also considered. I basically just want to neglect second-order terms and higher.

$\endgroup$
  • $\begingroup$ You could build rules as in : expr /. {f[x_] f[y_] -> 0, g[x_] g[y_] -> 0}. $\endgroup$ – b.gates.you.know.what May 7 '13 at 11:43
  • $\begingroup$ the expression i put is just a simplification, in the general case it contains a lot more terms with much higher orders, so i would need very many rules $\endgroup$ – Andrei May 7 '13 at 12:38
  • $\begingroup$ Take the Jacobian, zero everything as for the constant term just zero everything in the initial expression. $\endgroup$ – Spawn1701D May 7 '13 at 13:29
1
$\begingroup$

Maybe this

Replace[Expand@expr, Times[terms__ /; Count[{terms}, _f | _g, Infinity] > 1] -> 0, 1]
$\endgroup$
3
$\begingroup$

How about this:

(Series[Simplify[expr/.{forg_[x_] -> m forg[x]}, m \[Element] Reals], {m, 0, 1}] // Normal) /. m -> 1

Edit:

If there are other functions within the expression that are not f or g then you have to be a bit more explicit:

(Series[Simplify[expr/.{f[x_] -> m f[x],g[x_]->m g[x]}, m \[Element] Reals], {m, 0, 1}] // Normal) /. m -> 1
$\endgroup$
  • $\begingroup$ thanks, this works for the above example, but unfortunately my (real) expression also has terms of the form: Conjugate[a]*f[t] and Conjugate[b]*Conjugate[c], for which it fails $\endgroup$ – Andrei May 7 '13 at 13:05
  • $\begingroup$ @user4794, the edit should solve that problem. $\endgroup$ – Jonathan Shock May 7 '13 at 22:06
1
$\begingroup$

Try this

First harvest the terms:

terms = Cases[expr, (_f | _g) | Conjugate[_g | _f], Infinity]//Union

and then

(D[expr, {terms}] /. {f -> (0 &), g -> (0 &)}).terms + (expr/.Thread[terms -> 0])

Note:

For a faster alternative use CoefficientArrays:

#1 + #2.terms & @@ (Take[CoefficientArrays[expr, terms], 2] // Normal)
$\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.