Group Abstract Group Abstract

Message Boards Message Boards

1
|
3.9K Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Beginner question about attributes.

Posted 5 years ago

Can anyone help me with why Area maps over a list when its attributes don't include Listable

Attachments:
POSTED BY: Chess Denman
7 Replies
Posted 5 years ago

Hi Thanks for all your interest. I have continued to scrabble about to find an answer to the problem (with no success). However just in case it helps. This must be a relatively recent change in Mathematica because the example is drawn from P. Wellin's book Essentials of Programming in Mathematica pub 2016 (which I am following in order to learn stuff). I've attached the clip which is in section 2.5 on Attributes. I tried it out and Plot worked just fine

c

Attachment

Attachments:
POSTED BY: Chess Denman
Posted 5 years ago

Hi Chess,

I tried it on "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" and got the same error as in Wellin's book. No error on "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)". So this is a change introduced in v12. The documentation page for Area does say it was updated in 12.0 but I could not find any details about the specific changes.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Rohit:

Good point. I missed that. But, in the case of Area[], I'm not yet convinced that that is what is going on here. But, I could be wrong.

The reason I don't think that is what is happening here is that some definitions of Area take lists as arguments. I think (but could definitely be wrong) that it would be difficult for the interpreter/compiler to disambiguate between "listable" arguments and arguments that are lists.

It would be great to hear from the Wolfram team on this one.

POSTED BY: Mike Besso
Posted 5 years ago

Hi Chess,

From the Properties & Relations section of the Listable documentation.

A function implemented in terms of a listable operation may not need the Listable attribute:

So, presumably Area uses listable functions and that is why it is listable even though it does not have the Listable attribute.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Chess:

It seems to me that the Wolfram language (including standard packages) continues to grow at fast pace that makes it challenging for the tech writers to keep up with the documentation.

I have found a several functions like that have features like Area that are not explicitly documented.

In the case of "Listable" functions, there is more than one way to make a function "Listable". If you have a function that takes a single argument, then to make it Listable is to add the Listable attribute. But, for functions that take more than one argument, I think you need to do a bit more work and provide an explicit definition for what to do when you get a list.

In the case of Area, I first assumed that there must be two single argument definitions. For example, I can create a function that takes either either a scalar or a list (without using the Listable attribute) using something like:

Clear[f];
f[x_?NumericQ, multiplier_?NumericQ] := x * 2;
f[l_List, multiplier_?NumericQ] := Map[f[#, multiplier] & , l];

But, if this were the case with Area, then:

Area[{Disk[{0, 0}, r], Sphere[{0, 0, 0}, r]}]

would give the same answer as:

{Area[Disk[{0, 0}, r]], Area[Sphere[{0, 0, 0}, r]]}

But that's not the case here. Passing the list into Area gives a pair of constrained equations:

{ConditionalExpression[\[Pi] r^2, r > 0], 
 ConditionalExpression[4 \[Pi] r^2, r > 0]}

But since calling Area with just a single geometry yields simple expressions (even if Mapping a list on to Area):

{\[Pi] r^2, 4 \[Pi] r^2}

So, now I am not so sure what is going on with Area. But I think that it is likely that we will all continue to run into surprises like this for some time.

Thank you for the great question. Trying to answer questions like this helps me to better use the language, even when it leaves me a bit confused.

POSTED BY: Mike Besso
Posted 5 years ago

Thanks that was a silly transcribing error, but I still don't understand why the Area function is mapping happily over the list when, if you call its attributes they don't include Listable.

POSTED BY: Chess Denman
POSTED BY: Ahmed Elbanna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard