I'm trying to add custom downvalues for GeneratingFunction
, and to do so I thought I just had to Unprotect
it. However, that doesn't work:
Unprotect[GeneratingFunction]
{"GeneratingFunction"}
GeneratingFunction[2] = 3
During evaluation of In[3]:= Set::write: Tag GeneratingFunction in
GeneratingFunction[2] is Protected. >>
3
GeneratingFunction[2]
During evaluation of In[4]:= GeneratingFunction::argmu: GeneratingFunction
called with 1 argument; 3 or more arguments are expected. >>
GeneratingFunction[2]
I'm running Mathematica 9 64 bit on Linux. What do I need to do to really remove protection from this symbol?
Answer
GeneratingFunction
by default is not a function: it is a stub which loads corresponding .mx package. You can see this with the following:
ClearAttributes[GeneratingFunction,{Protected,ReadProtected}]
OwnValues@GeneratingFunction
{HoldPattern[GeneratingFunction] :>
System`Dump`AutoLoad[Hold[GeneratingFunction], Hold[GeneratingFunction, GenerateConditions`TopLevelCode], "Discrete`GeneratingFunction`"] /; System`Dump`TestLoad}
The functions ClearAttributes
and OwnValues
have Hold*
attributes and so the above code does not evaluate GeneratingFunction
. After first evaluation it's Attributes
and Options
are redefined by the loaded package:
GeneratingFunction;
Attributes[GeneratingFunction]
Options[GeneratingFunction]
{Protected, ReadProtected}
{Assumptions :> $Assumptions, GenerateConditions -> False, Method -> Automatic, VerifyConvergence -> True}
I do not know why we can't see any top-level code for GeneratingFunction
with Information
, but Tracing
its evaluation reveals a bunch of top-level functions it uses:
Trace[GeneratingFunction[1, n, x], TraceInternal -> True]
For the original discussion of this issue see this answer by Sasha (Wolfram Research) with comments under it.
Comments
Post a Comment