MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Unprotect

  • To: mathgroup at
  • Subject: [mg120897] Re: Unprotect
  • From: Leonid Shifrin <lshifr at>
  • Date: Sun, 14 Aug 2011 20:18:39 -0400 (EDT)
  • Delivered-to:
  • References: <>

Hi Themis,

In code,  one possible answer to both questions is this:

Entropy[x_] := 1/x;
DownValues[Entropy] = RotateRight[DownValues[Entropy]];

To understand why you need to call Entropy first, and why this solves the
first problem, please read this post:

Note that I don't justify this behavior - IMO it is a borderline bug, or at
least this contradicts the semantics of Protect/Unprotect, as exposed to the

The reason why manipulations with DownValues solve the second problem (error
message) can be seen upon removing the ReadProtected attribute of Entropy
and inspecting the code. It uses the construct like

f[args___]:=Block[{someValue = ...}, someCode/;someValue =!=$Failed]

This looks like a general definition (since triple underscore is used), but
it is not, since the condition inside Block is a part of the pattern. When
you add your definition, it is therefore not considered more specific by
Mathematica, and is therefore added after the built-in one. It is the
built-in definition that is responsible for the error message. By
rearranging DownValues, we put your definition on top, so the built-in never
fires. I would consider  it a possible implementation defect - one could
instead add another built-in definition  like

f[args___]:="never happens"/;Message[...]

and issue a message here - and this problem would then be absent.


On Sun, Aug 14, 2011 at 5:15 AM, Themis Matsoukas <tmatsoukas at> wrote:

> I want to redefine a build in command. I use the following example:
> Unprotect[Entropy];
> Entropy[x_] := 1/x
> Entropy[10.]
> When I execute these commands on a fresh kernel I get:
> SetDelayed::write: Tag Entropy in Entropy[x_] is Protected. >>
> $Failed
> Entropy::targ: Argument 10.` at position 1 should be a List, a SparseArray,
> or a String. >>
> Entropy[10.]
> If I execute a second time I get my definition to work but I still get a
> warning about the arguments:
> Entropy::targ: Argument 10.` at position 1 should be a List, a SparseArray,
> or a String. >>
> 0.1
> So, two questions:
> 1. Do I have to execute twice to cause a custom definition to stick?
> 2. How do I get rid of the warning once the custom definition works?
> Running 8.01 on Lion.
> {"8.0 for Mac OS X x86 (64-bit) (February 24, 2011)", 1}
> Themis

  • References:
    • Unprotect
      • From: Themis Matsoukas <>
  • Prev by Date: Cataloging apps for Finder files? (Mathematica notebooks especially)
  • Next by Date: Re: Getting the Date and Time From a Time Server
  • Previous by thread: Unprotect
  • Next by thread: Re: Unprotect