4
$\begingroup$

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 graphics

Mathematica 11.1.1 on windows.

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ – MarcoB Aug 21 '17 at 23:51
  • 2
    $\begingroup$ 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. *) $\endgroup$ – J. M.'s torpor Aug 22 '17 at 0:58
3
$\begingroup$

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];
ParabolicCylinderD; (* autoload *)
Attributes[ParabolicCylinderD]

{Listable, NumericFunction, Protected, ReadProtected}

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

Unprotect[HypergeometricU];
HypergeometricU; (* autoload *)
Attributes[HypergeometricU]

{Listable, NumericFunction, ReadProtected}

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 @ Language`ExtendedDefinition[sym]
    ],
    protect = Unprotect[sym]
    },

    sym;
    Quiet @ MakeBoxes[sym[], TraditionalForm];
    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[BoxForm`a$,Blank[]],Pattern[BoxForm`b$,Blank[]]],TraditionalForm],BoxForm`sufficientVersionQ[6.1`]]],TemplateBox[List[MakeBoxes[BoxForm`a$,TraditionalForm],MakeBoxes[BoxForm`b$,TraditionalForm]],"ParabolicCylinderD"]] RuleDelayed[HoldPattern[MakeBoxes[ParabolicCylinderD[Pattern[BoxForm`v,Blank[]],Pattern[BoxForm`z,Blank[]]],TraditionalForm]],RowBox[List[SubscriptBox[TagBox["D",ParabolicCylinderD],BoxForm`ToTrad[BoxForm`v]],"(",BoxForm`ToTrad[BoxForm`z],")"]]]

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ – J. M.'s torpor Aug 22 '17 at 9:00
3
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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