3
$\begingroup$

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 ?

$\endgroup$

closed as off-topic by Artes, Bob Hanlon, m_goldberg, happy fish, MarcoB May 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.

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

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]})
$\endgroup$
0
$\begingroup$
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

$\endgroup$

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