Re: Re: Problem overriding simple built-in functions
- To: mathgroup at smc.vnet.net
- Subject: [mg28848] Re: [mg28800] Re: [mg28796] Problem overriding simple built-in functions
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 15 May 2001 00:59:22 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
E.g.:
In[5]:=
GCD[{3,6,8,9},{6,4,6,12}]
Out[5]=
{3,2,2,3}
It seems to me think this can be pretty useful.
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/~andrzej/
on 01.5.15 2:44 AM, David Park at djmp at earthlink.net wrote:
> But what possible benefit was there in the first place in making GCD
> listable?
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
>
>> From: Andrzej Kozlowski [mailto:andrzej at tuins.ac.jp]
To: mathgroup at smc.vnet.net
>>
>> The reason for all this is thet GCD has the Attribute Listable:
>> In[1]:=
>> Attributes[GCD]
>>
>> Out[1]=
>> {Flat,Listable,Orderless,Protected}
>>
>> This means that GCD[{2,3}] is just {GCD[2],GCD[3]} which is just {2,3}. In
>> order for your over-ride to work you will have to clear the Listable
>> attribute of GCD with ClearAttributes[GCD,Listable] . You will, of course,
>> loose all the benefits of listability.
>>
>>
>> --
>> Andrzej Kozlowski
>> Toyama International University
>> JAPAN
>>
>> http://platon.c.u-tokyo.ac.jp/andrzej/
>> http://sigma.tuins.ac.jp/~andrzej/
>>
>>
>>
>>
>> on 01.5.13 4:28 PM, Jean-Christophe Deschamps at jchd at worldnet.fr wrote:
>>
>>> Hi,
>>>
>>> I'm told the following occurs under Mathematica v4.0:
>>>
>>> In[1]:= GCD[{3, 6}]
>>> Out[1]= {3, 6}
>>> In[2]:= GCD[x_List] := Apply[GCD, x]
>>> In[3]:= GCD[{3, 6}]
>>> Out[3]= GCD[{3, 6}]
>>> In[4]:= Apply[GCD, {3, 6}]
>>> Out[4]= 3
>>>
>>> Why is it so? It looks like the override is ignored, but why?
>>>
>>> The same exerpt seems to work fine under version 2.x.
>>>
>>>
>>
>>
>
>