How to remove the sign before the element

I want to get rid of the sign in front of the element, but the symbol variables are involved, so I can't use the Abs function to get rid of the sign.

I want this list {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3]} to be processed to {1, 2, 3, 4, x, x, Fx[3], Fx[3]}.

In addition, What should I do when the list contains a ± sign? For example, when the list is {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3], -Fx[-3], ±Fy[-2] ,±Fy[±x]}.

• Related: (9637), (26971), (46004) Apr 2, 2020 at 10:53
• @Mr.Wizard What should I do when the list contains a ± sign? I've updated the question.
– user69323
Apr 2, 2020 at 22:40
• user216, please see my updated answer. @user1066 That's nice! Why not post a formal Answer? Apr 3, 2020 at 11:25

I am sure there are many ways to do this. One possible way could be

ClearAll[x,Fx];
expr = {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3]};
Times[InternalSyntacticNegativeQ /@ expr /. {True -> (-1), False -> 1}, expr]


gives

 {1, 2, 3, 4, x, x, Fx[3], Fx[3]}


expr   /. y_ /; y < 0 -> -y
(*{1, 2, 3, 4, x, x, Fx[3], Fx[3]}*)

• Clever, but beware something like -Fx[-1] Apr 2, 2020 at 10:30
• @Mr.Wizard obviously to simple! Other problems arise if you consider expressions like -g[x]+f[-x] Apr 2, 2020 at 10:39
• It fits the given example however, and I like terse, so you already have my up-vote. :-) Apr 2, 2020 at 10:39
• Me too, thanks. Apr 2, 2020 at 10:40

Not as terse as Ulrich's replacement, but perhaps more robust:

list = {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3], -Fx[-1], +Fx[-1]};

Replace[a : -_ | _?Negative :> -a] /@ list

{1, 2, 3, 4, x, x, Fx[3], Fx[3], Fx[-1], Fx[-1]}


Updated for your latest example:

list2 = {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3], -Fx[-1], +Fx[-1], ±Fy[-2], ±Fy[±x]};

Replace[{a : -_ | _?Negative :> -a, ±a_ :> a}] /@ list2

{1, 2, 3, 4, x, x, Fx[3], Fx[3], Fx[-1], Fx[-1], Fy[-2], Fy[±x]}

ClearAll[removeSigns]

removeSigns = # Sign[#] /. Sign -> (1 &) &;

removeSigns @ {-1, -2, +3, 4, -x, +x, -Fx[3], +Fx[3]}

{1, 2, 3, 4, x, x, Fx[3], Fx[3]}


Also

ClearAll[removeSigns2, removeSigns3, removeSigns4, removeSigns5]

removeSigns2 = Abs[#] /. Abs -> (# &) &

removeSigns3 = ReplaceAll[Abs -> Identity] @* Abs

removeSigns4 = Map[Replace[Abs[x_] :> x]]@*Abs (*thanks: Mr.Wizard *)

removeSigns5 = Function[{x}, If[InternalSyntacticNegativeQ[x], -x, x], Listable];

• Consider also: Replace[Abs[x_] :> x] /@ Abs[list] -- this would not strip inner appearances of Abs. Apr 2, 2020 at 10:58
Sqrt[lst lst]//PowerExpand


{1, 2, 3, 4, x, x, Fx[3], Fx[3]}

(Originally posted as a comment)