# Pattern test of sign in long expression

The following expression is a short excerpt from a much longer expression I have:

exp = a E^(I (k x - t \[Omega])) \[Alpha]1 +
a E^(-k x - I t \[Omega]) R0 \[Alpha]2 +
a E^(-3 k x - 3 I t \[Omega]) R0 \[Alpha]3 +
a E^(I (5 k x - 5 t \[Omega])) \[Alpha]5;


I need a basic command that checks the above expression and issues an alert if any of the following conditions are not met:

1- Sign of k in the exponential must be positive if "a" is not multiplied by R0.

2- Sign of k in the exponential must be negative if "a" is multiplied by R0.

For example, the command should give me a warning that the last term in expEroor violates either conditions mentioned above:

  expError = a E^(I (k x - t \[Omega])) \[Alpha]1 +
a E^(-k x - I t \[Omega]) R0 \[Alpha]2 +
a E^(-3 k x - 3 I t \[Omega]) R0 \[Alpha]3 +
a R0 E^(I (5 k x - 5 t \[Omega])) \[Alpha]5;


Thanks in advance for help.

One could use

(* test a single term *)
test[(c_:1)*Power[E,b_]]:=With[{s=coeff[D[b,k]]},And[
Implies[FreeQ[c,R0],s>0],
Implies[Not[FreeQ[c,R0]],s<0]
]];

(* select terms that do not pass the test  *)
Select[List@@expError, Not[test[#]===True]&]

(* { a E^(I (5 k x-5 t ω)) R0 α5} *)


The function coeff uses this answer.

• Thanks for your answer. However, there are terms that don’t have “I” multiplied by “k” in the exponent. Oct 10, 2022 at 8:31