MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re : removing of - sign from a list

  • To: mathgroup at
  • Subject: [mg20283] Re [mg20256]: removing of - sign from a list
  • From: Ranko Bojanic <bojanic at>
  • Date: Mon, 11 Oct 1999 02:19:55 -0400
  • Organization: Ohio State University
  • Sender: owner-wri-mathgroup at

In [mg20256] dummy index list Arturas Acus wrote:
> I want the fastest way to select dummy symbols
> from some expression. Suppose we have a list of
> dummy indices {a,-b,c, -d}. What is the fastest way to
> get rid of the minus sign?


testList={a,-b,c, -d}

One solution that comes immediately to mind is

testList /. -x_-> x
{a,-b,c, -d}

The following solution is just as simple, but more difficult to
explain. It seems that in Mathematica we can define f by writing

f[ -x_ ] := x
f[ x_ ]  := x



However, neither method works with numeric lists:
If testList ={1,-2,3,-4},we get

testList / . -x_-> x


We have clearly to use the Abs function in that case:


  • Prev by Date: Graphics inconsistencies
  • Next by Date: Generalization of Greater to matrices
  • Previous by thread: Graphics inconsistencies
  • Next by thread: Generalization of Greater to matrices