# How to reset a built-in symbol to its default definition?

I'm trying to add functionality to some of Mathematica's built-in functions in a package I'm building. I'm not trying to overwrite any functionality—just add it where it isn't already defined.

I start my package body with:

Unprotect["packagename*"];
ClearAll["packagename*"]


Clearly, though, I don't want to clear the system definition! However, I do want to reset the symbol to its default system definition before adding my definition, and I don't know how to do that.

I'd also appreciate any advice on best practices for adding this functionality! I'm willing to just use a typical :=, but if there are better ways, I'd certainly be interested.

• An example of a built-in function, and how and why you want to modify it would be helpful. Mar 23, 2019 at 2:16
• Sure! Concretely, I need to extend interval arithmetic to complex numbers. For example, something I might want to include in a package could be Interval[n_Complex] := (#1 + #2*I) & @@ (Interval /@ ReIm[n]). Without this, Interval[n] where n has head Complex doesn't evaluate to anything. Unprotecting Interval and evaluating this works—I just want to do it safely and repeatedly in a package, which I think would involve resetting Interval to the system default somehow. Mar 23, 2019 at 2:20
• "I need to extend interval arithmetic to complex numbers" - this isn't your question anymore, but: look up disk arithmetic. Disks are more natural to operate on than rectangles for complex numbers. Mar 23, 2019 at 4:00
• @J.M. Disk arithmetic may be more useful in delivering tighter error bounds, but there is a price in implementation difficulty. Mar 27, 2019 at 22:22
• @Daniel, yes, I've seen from the literature that there are a lot of subtleties to fret about. I presume this is why Mathematica doesn't have it? Mar 27, 2019 at 23:07

If the System symbol you want to modify is a kernel function, then you can just use Clear to reset it to its default state. For your Interval example:

LanguageExtendedDefinition[Interval]


LanguageDefinitionList[Interval->{OwnValues->{},SubValues->{},UpValues->{},DownValues->{},NValues->{},FormatValues->{},DefaultValues->{},Messages->{},Attributes->{Protected}}]

shows that Interval has no *Values. Using Clear on Interval will only clear new definitions that you add. Example:

Unprotect[Interval];
Interval[n_Complex] := (#1 + #2*I) & @@ (Interval /@ ReIm[n])
Protect[Interval];


Now, let's check:

LanguageExtendedDefinition[Interval]


LanguageDefinitionList[Interval->{OwnValues->{},SubValues->{},UpValues->{},DownValues->{HoldPattern[Interval[n_Complex]]:>(#1+#2 I&)@@Interval/@ReIm[n]},NValues->{},FormatValues->{},DefaultValues->{},Messages->{},Attributes->{Protected}}]

Notice that your definition shows up in the DownValues rule. Let's clear definitions:

Unprotect[Interval];
Clear[Interval]
Protect[Interval];


And the definition is gone:

LanguageExtendedDefinition[Interval]


LanguageDefinitionList[Interval->{OwnValues->{},SubValues->{},UpValues->{},DownValues->{},NValues->{},FormatValues->{},DefaultValues->{},Messages->{},Attributes->{Protected}}]

Note the Interval still works:

Sin[Interval[{0, Pi}]]
`

Interval[{0, 1}]