MathGroup Archive 1999

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

Search the Archive

Re : removing of - sign from a list

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

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?

Let

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

Then

Map[f,testList]
{a,b,c,d}

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

testList / . -x_-> x
{1,-2,3,-4}

Map[f,testList]
{1,-2,3,-4}

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

Map[Abs,testList]
{1,2,3,4}



  • 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