# How to replace a list elements that specify some constraint? [closed]

Let's say I have the list :

-5 u[x, y, z] + 6 v[x, y, z]


and want to get as a result -u[x,y,z] + v[x,y,z]. I have tried :

{-5 u[x, y, z] + 6 v[x, y, z]} /. j_Integer?NonNegative*expr : _ :> expr
(* -5u[x,y,z] + v[x,y,z]*)


Is there any way to have just 1 or -1 as coefficient in a final polynomial ?

## closed as off-topic by Artes, Bob Hanlon, m_goldberg, happy fish, MarcoBMay 5 '17 at 3:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Artes, Bob Hanlon, m_goldberg, happy fish, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

• /. i_Integer :> Sign[i]? – Kuba May 4 '17 at 12:52
• -5 u[x, y, z] + 6 v[x, y, z] /. x_?NumberQ :> Sign[x] – Artes May 4 '17 at 12:52
• Works. Thank you. – Davit Shahnazaryan May 4 '17 at 12:55
• -5 u[x, y, z] + 6 v[x, y, z] /. x_?NumericQ -> Sign[x] – UnchartedWorks May 4 '17 at 13:02

Another approach can be something like this:

coeffList =
CoefficientList[-5 u[x, y, z] + 6 v[x, y, z], {u[x, y, z],
v[x, y, z]}];

Plus @@ ((Sign /@ coeffList).{u[x, y, z], v[x, y, z]})

ClearAll[f1, f2, f3]
f1 = MapAt[Sign, #, {All, 1}]&;

f2 = # /. (# -> Sign@# & /@ Coefficient[#, Variables@#]) &;

f3 = Dot[Variables@#, Sign@Coefficient[#, Variables@#]] &;

f1[-5 u[x, y, z] + 6 v[x, y, z]]


-u[x, y, z] + v[x, y, z]

Equal @@ (#[-5 u[x, y, z] + 6 v[x, y, z]] & /@ {f1, f2, f3})


True