Re: Attributes and behaviors?
- To: mathgroup at smc.vnet.net
- Subject: [mg46565] Re: Attributes and behaviors?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Mon, 23 Feb 2004 22:33:49 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <c1c9kk$atc$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, if you introduce a new data type like DualNumber[] you have to add the rules for the build in functions to handle this. DualNumber /: Sin[d_DualNumber]:= kSin[d] Mathematica is a functional language and you have to setup the new behaviour of the *function* for the data. Regards Jens Fred Klingener wrote: > > Please help me understand better the relationship between attributes and > behaviors. > > Background: I'm a Mathematica (5.0.0) newbie who's trying to build a > package for dual numbers. In the package, ultimately I want to overwrite > the System numeric functions to handle dual numbers without affecting the > handling of the native (atomic) types. > > Progress so far: I have some sample functions working pretty well. > Functions I've named things like kDualNumberSin[] seem to work numerically > and symbolically on dual numbers and to drop through (via an explicit call) > to System`Sin[] on Real arguments. Now I'm ready to think about overwriting > System`Sin[], for example, and I'm having trouble getting my head around > atttributes. > > I've built a toy function: kSin[x_] :=Sin[x], and here are a few > observations about it: > > - In:-> Attributes[Sin] Out:-> {Listable, NumericFunction,...} > - In:-> Attributes[kSin] Out:-> {} > - a few tests show that kSin[] has full listable behavior, that is, it > produces the same > output as Sin[] when fed a List as an input argument. > > - My 'serious' function kDualNumberSin[] relies on Series[] for its > operation. > - Series[] has no Listable attribute. > - a few primitive tests show that Series[] in fact has Listable capability. > - kDualNumberSin[] also seems to have listable capability. > > All of this is confusing. > > - What's the nature of the relationship between attributes and behavior? > - Is the attribute used in some inscrutable inner workings of the kernal? > - What are the costs and benefits of simply setting the Listability > attribute in my function? > - How certain do I have to be that my function really IS Listable before I > set the attribute? > - Does the absence of the Listability attribute of Series[] mean that its > current listable behavior is an undocumented feature subject to future > abandonment? > > TIA for any help, > > Fred Klingener > Brock Engineering