[Date Index]
[Thread Index]
[Author Index]
Re: Attributes and behaviors?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg46606] Re: Attributes and behaviors?
*From*: Paul Abbott <paul at physics.uwa.edu.au>
*Date*: Wed, 25 Feb 2004 13:07:00 -0500 (EST)
*Organization*: The University of Western Australia
*References*: <c1c9kk$atc$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
In article <c1c9kk$atc$1 at smc.vnet.net>,
"Fred Klingener" <flush at BitBucket.com> wrote:
> 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.
Because Sin is Listable:
kSin[{a,b,c}] --> Sin[{a,b,c}] --> {Sin[a],Sin[b],Sin[c]}
> - 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.
This is, I think, more subtle. The documentation on Series says that
Series[f, {x, 0, n}] constructs Taylor series for any function f
according to the formula f[0] + f'[0] + ...
Now if f happens to be {g[x], h[x]} then you see that f[0] =
{g[0],h[0]}, f'[0] = {g'[0],h'[0]}, and so on.
You can also write
{g[x], h[x]} + O[x]^4
and, since Plus is Listable, the behaviour is more obvious.
Note that D does not have the Listable attribute either but it works in
the same fashion as Series (for the same reason).
> - What's the nature of the relationship between attributes and behavior?
Generally, an Attribute is required before the behaviour occurs.
However, there is the possibility of inheritance (your kSin) or from a
fundamental mathematical property.
> - Is the attribute used in some inscrutable inner workings of the kernal?
No.
> - What are the costs and benefits of simply setting the Listability
> attribute in my function?
Very little cost -- but if it's not necessary there is no need to set it.
> - How certain do I have to be that my function really IS Listable before I
> set the attribute?
A simple test should suffice.
> - Does the absence of the Listability attribute of Series[] mean that its
> current listable behavior is an undocumented feature subject to future
> abandonment?
No.
Cheers,
Paul
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
Prev by Date:
**RE: RE: Re: corrected RE: Re: Computing sets of equivalences**
Next by Date:
**Re: Reordering Downvalues?**
Previous by thread:
**Re: Attributes and behaviors?**
Next by thread:
**RE: RE: animation**
| |