Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2001

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

Search the Archive

Re: Problem overriding simple built-in functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28800] Re: [mg28796] Problem overriding simple built-in functions
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Mon, 14 May 2001 01:32:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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.
> 
> 



  • Prev by Date: Re: MATHEMATICA 4.0 - IWANT TO COPY DATA FROM OTHER APPLICATION
  • Next by Date: Re: Mandrake 8.0 and Mathematica 4.01
  • Previous by thread: Re: Problem overriding simple built-in functions
  • Next by thread: Re: Problem overriding simple built-in functions