MathGroup Archive 1998

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

Search the Archive

Re: Sqrt and Listability

  • To: mathgroup at
  • Subject: [mg14875] Re: [mg14836] Sqrt and Listability
  • From: BobHanlon at
  • Date: Mon, 23 Nov 1998 10:11:54 -0500
  • Sender: owner-wri-mathgroup at

In a message dated 11/20/98 6:09:36 AM, andrzej at writes:

>I have come across a mystery. Solving it is a matter of absolutely no
>importance, yet I would be grateful for any help in putting it to rest.
>A few days ago I was giving my introductory course in Mathematica
>programming and was about to explain the 'Listable' attribute of
>functions, when on the spur of the moment I did something one should
>never do and departed from my prepared plan. I just got the idea that a
>good way to introduce listability would be to start with some very well
>known function, remove the Listable attribute, and then demonstrate
>that it would be really desirable to have it back. Of course I could
>have defined my own function but at this point we had not yet got as
>far as defining functions so I wanted to choose something very well
>known. Without any tests my choice fall on Sqrt. Sqrt is of course
>{2, 3}
>One can check it's attributes explicitly: In[2]:=
>Now we remove Listable:
>Sqrt is no longer Listable:
>Or is it?
>This was a little embarrassing. I mumbled something to the effect that
>one should never trust a computer program and replaced Sqrt with Sin.
>Now everything worked as expected.
>My question is: why on earth is Listablity "hard wired" into Sqrt but
>not in other functions, like Sin. Log etc. Is this just a accidental
>quirk (I wouldn't even call it a bug) which just proves my point about
>"never trusting a computer program" or is there something "deep"
>involved in this?

Sqrt[{x, y}]

{Sqrt[x], Sqrt[y]}



Sqrt uses Power. To make Sqrt non-Listable you need to clear the
Listable  attribute from both Sqrt and Power

ClearAttributes[{Sqrt, Power}, Listable]

Sqrt[{x, y}]

Sqrt[{x, y}]

SetAttributes[{Sqrt, Power}, Listable]

Bob Hanlon

  • Prev by Date: Re: Evaluation Control
  • Next by Date: Re: Evaluation Control
  • Previous by thread: Re: Sqrt and Listability
  • Next by thread: Artlandia: student version