I am trying to understand your function ReplacePlusMinus
. First question: what is the purpose of the complicated pattern test l_?(Function[{x}, ListQ[x], {}])
? Why not this simpler form:
myReplacePlusMinus[l_List] :=
SequenceReplace[l, {x_, -x_} :> PlusMinus[x]]
Have you tried ReplacePlusMinus
in these examples?
ReplacePlusMinus[{1, -1}]
ReplacePlusMinus[{-a, a}]
Are you ok with the output?