# Error changing Attribute of ParabolicCylinderD after unprotecting

This is related to why-changing-the-order-of-format-causes-error but it seems to be a new issue so posting a new question.

Of all the symbols that I changed its Format by unprotecting it first, then protecting it afterwords, only ParabolicCylinderD gives an error. Why is that? Is there a work around?

MWE, on fresh kernel

Unprotect[ParabolicCylinderD]
Format[ParabolicCylinderD, TeXForm] ="\\text{ParabolicCylinderD}"
Protect[ParabolicCylinderD]

gives

Set::write: Tag ParabolicCylinderD in \text{ParabolicCylinderD} is Protected.

The same commands work on all other symbols I've tried so far. No problems. Only ParabolicCylinderD gives this error.

Screen shot

Mathematica 11.1.1 on windows.

• I notice that this only happens on the first evaluation on my machine (Win7-64, MMA 11.1.1.0). A second evaluation of the same code completes with no errors. I wonder if this has something to do with some code being loaded only once when that function is first invoked in a fresh kernel. – MarcoB Aug 21 '17 at 23:51
• In general, due to the autoloading now being done these days, you should "touch" a symbol first before calling Unprotect[], etc. ParabolicCylinderD; Unprotect[(* stuff *)]; (* etc. *) – J. M.'s torpor Aug 22 '17 at 0:58

The package that ParabolicCylinderD autoloads has the ParabolicCylinderD symbol protected, while the package that HypergeometricU autoloads does not have the HypergeometricU symbol protected:

Unprotect[ParabolicCylinderD];
Attributes[ParabolicCylinderD]

We see that the ParabolicCylinderD symbol is protected after autoloading. The similar code for HypergeometricU does not reprotect the symbol:

Unprotect[HypergeometricU];
Attributes[HypergeometricU]

You might consider using the Initial wrapper from my answer to How can one manually change the rule ordering (note that your question caused me to modify the wrapper so that it is not tripped up by autoloading packages that reprotect symbols, and so that FormatValues get autoloaded as well). The relevant code is:

Initial /: Verbatim[TagSetDelayed][Initial[sym_], lhs_, rhs_] := With[
{
new = Block[{sym},
TagSetDelayed[sym, lhs, rhs];
First @ LanguageExtendedDefinition[sym]
],
protect = Unprotect[sym]
},

sym;
Unprotect[sym];

Replace[new,
Rule[values_, n:Except[{}]] :> (
values[sym] = DeleteDuplicates@Join[n, values[sym]]
),
{2}
];
Protect@protect;
]

You would use it as follows (note that I changed Set to SetDelayed in your definition):

Initial[ParabolicCylinderD] /: Format[ParabolicCylinderD, TeXForm] := "\\text{ParabolicCylinderD}"

Check:

TableForm[FullForm /@ FormatValues[ParabolicCylinderD]]

RuleDelayed[HoldPattern[Format[ParabolicCylinderD,TeXForm]],"\\text{ParabolicCylinderD}"] RuleDelayed[HoldPattern[Condition[MakeBoxes[ParabolicCylinderD[Pattern[BoxForma$,Blank[]],Pattern[BoxFormb$,Blank[]]],TraditionalForm],BoxFormsufficientVersionQ[6.1]]],TemplateBox[List[MakeBoxes[BoxForma$,TraditionalForm],MakeBoxes[BoxFormb$,TraditionalForm]],"ParabolicCylinderD"]] RuleDelayed[HoldPattern[MakeBoxes[ParabolicCylinderD[Pattern[BoxFormv,Blank[]],Pattern[BoxFormz,Blank[]]],TraditionalForm]],RowBox[List[SubscriptBox[TagBox["D",ParabolicCylinderD],BoxFormToTrad[BoxFormv]],"(",BoxFormToTrad[BoxForm`z],")"]]]

• I believe that part of the difference is due to the fact that HypergeometricU[] was an older function, and ParabolicCylinderD[] only came about when this autoloading stuff suddenly became the norm for new Mathematica symbols. – J. M.'s torpor Aug 22 '17 at 9:00

An extended comment. I notice that this behavior only happens on the first evaluation on my machine (Win7-64, MMA 11.1.1.0). A second evaluation of the same code completes with no errors.

I wonder if this has something to do with some code being loaded only once when that function is first invoked in a fresh kernel.

In fact, if you first invoke the function independently of the attribute change, e.g. by using one of the examples from the docs, and then change the attributes, no errors are generated, even in a fresh kernel. See e.g.

Plot[ParabolicCylinderD[5, x], {x, -10, 10}]

Unprotect[ParabolicCylinderD]
Format[ParabolicCylinderD, TeXForm] = "\\text{ParabolicCylinderD}"
Protect[ParabolicCylinderD]