MathGroup Archive 2002

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

Search the Archive

Re: A possible bug in Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34429] Re: [mg34392] A possible bug in Lists
  • From: BobHanlon at aol.com
  • Date: Sun, 19 May 2002 04:14:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 5/18/02 4:09:47 AM, Klepachd at yahoo.com writes:

>I am having a problem in Mathematica 4.1 :
>
>Evaluating : 1-{1,1} or {1,1}-1 returns {0,0}
>
>Is that ok ?
>
>how is it that I can subtract a vector from a scalar ?
>

Attributes[Plus]

{Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}


Note that operators such as Plus, Times, Power (as well as many 
functions) are Listable. This enables you to act on each element 
of a List with a scalar.  For example,

mat= {{a11,a12}, {a21,a22}};

mat-b

{{a11 - b, a12 - b}, {a21 - b, a22 - b}}


Plus is also orderless

%==-(b-mat)

True


Times is Listable

mat*b
{{a11*b, a12*b}, {a21*b, a22*b}}


and Orderless

%==b*mat

True


Power is Listable

mat^2

{{a11^2, a12^2}, {a21^2, a22^2}}


But not Orderless

2^mat
{{2^a11, 2^a12}, {2^a21, 2^a22}}

Select[Names["*"], MemberQ[Attributes[#], Listable] &]


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Plot Random Walk!
  • Next by Date: Re: Re[2]: cannot solve *trivial* equation
  • Previous by thread: A possible bug in Lists
  • Next by thread: Re: A possible bug in Lists