Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

GeneratingFunction[2] = 3
During evaluation of In[3]:= Set::write: Tag GeneratingFunction in 
GeneratingFunction[2] is Protected. >>

During evaluation of In[4]:= GeneratingFunction::argmu: GeneratingFunction
called with 1 argument; 3 or more arguments are expected. >>


I'm running Mathematica 9 64 bit on Linux. What do I need to do to really remove protection from this symbol?

share|improve this question
up vote 7 down vote accepted

GeneratingFunction by default is not a function: it is a stub which loads corresponding .mx package. You can see this with the following:


{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:


{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 isuue see this answer by Sasha (Wolfram Research) with comments under it.

share|improve this answer

I do not know why Unprotectdoes not work (bug, feature?). The following does work though:

ClearAttributes[GeneratingFunction, Protected]
GeneratingFunction[2] = 3


share|improve this answer
hmm, that's not working for me – Andrew MacFie Sep 17 '13 at 22:37
clearing the attribute, attempting to set a value, receiving an error, then clearing the attribute again and setting a value seems to work though – Andrew MacFie Sep 17 '13 at 22:39
@Andrew May be the situation is similar to this? – Alexey Popkov Sep 18 '13 at 2:11
@AndrewMacFie: You need to run it twice so Wolfram can confirm your intentions with absolute certainty. ;-) On a serious note, what kind of "feature" is that?! – Hector Sep 18 '13 at 3:49
@AlexeyPopkov ah yes... this question is very similar to that one – Andrew MacFie Sep 18 '13 at 20:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.