MathGroup Archive 2007

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

Search the Archive

Re: question about Protect

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75116] Re: [mg75079] question about Protect
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 18 Apr 2007 04:52:07 -0400 (EDT)
  • References: <200704170011.UAA08565@smc.vnet.net>

I made a similar point in my post:

hhttp://forums.wolfram.com/mathgroup/archive/2007/Apr/msg00254.html

It seems that built-in functions, when they call on another built in  
function will sometimes Protect if it had previously been  
Unprotected. You can see this here:


In[5]:=
Unprotect[Limit];

In[6]:=
Attributes[Limit]

Out[6]=
{Listable, ReadProtected}

In[9]:=
Integrate[Exp[-x], {x, 1, Infinity}]

Out[9]=
1/E

In[10]:=
Attributes[Limit]

Out[10]=
{Listable, Protected, ReadProtected}

By contrast:

In[11]:=
Unprotect[Limit];

In[12]:=
Attributes[Limit]

Out[12]=
{Listable, ReadProtected}

In[13]:=
Integrate[Exp[-x], {x, 1, 2}]

Out[13]=
(-1 + E)/E^2

In[14]:=
Attributes[Limit]

Out[14]=
{Listable, ReadProtected}

I have not investigated this sufficiently to be able to describe the  
exact circumstancs under which this happens but I speculate that a  
Mathematica function that calls on another Mathematica function  
sometimes (or often or always (?)) Unprotects it and when it finished  
its job Protects it again. If this is correct than a function that  
had been earlier Unprotected by a user would end up automatically  
Protected. Probably a better approach would be to simply save and  
resotore the attributes the function had when it was called; so this  
might be a minor bug?

Andrzej Kozlowski




On 17 Apr 2007, at 09:11, dimitris wrote:

> Hello.
>
> The following code add a rule for the Limit command
>
> In[1]:=
> Off[General::spell1]
> Unprotect[Limit];
> Limit[a___] := Null /; (Print[InputForm[limit[a]]]; False)
>
> For example
>
> In[7]:=
> Integrate[1/Sqrt[Abs[x]], {x, -1, 2}]
>
>> From In[7]:=
> InputForm[limit[1 + (1 + x)/2 + (3*(1 + x)^2)/8, x -> -1, Direction ->
> -1, Assumptions -> True]]
>> From In[7]:=
> InputForm[limit[(-I)/Sqrt[x], x -> 0, Direction -> 1, Assumptions ->
> True]]
>> From In[7]:=
> InputForm[limit[I/Sqrt[x], x -> 0, Assumptions -> True]]
>> From In[7]:=
> InputForm[limit[2*Sqrt[x], x -> 1, Direction -> 1, Assumptions ->
> True]]
>> From In[7]:=
> InputForm[limit[2*Sqrt[x], x -> 0, Direction -> -1, Assumptions ->
> True]]
>> From In[7]:=
> InputForm[limit[1/Sqrt[x], x -> 0, Direction -> -1, Assumptions ->
> True]]
>> From In[7]:=
> InputForm[limit[1/Sqrt[x], x -> 0, Assumptions -> True]]
>> From In[7]:=
> InputForm[limit[1/Sqrt[2] - (-2 + x)/(4*Sqrt[2]) + (3*(-2 + x)^2)/
> (32*Sqrt[2]), x -> 2, Direction -> 1, Assumptions -> True]]
>> From In[7]:=
> InputForm[limit[2*Sqrt[x], x -> 2, Direction -> 1, Assumptions ->
> True]]
>> From In[7]:=
> InputForm[limit[2*Sqrt[x], x -> 0, Direction -> -1, Assumptions ->
> True]]
>
> Out[7]=
> 2*(1 + Sqrt[2])
>
> Note that I have NOT protect the Limit command. Nevertheless,
>
> In[8]:=
> Clear[Limit]
> Clear::wrsym: Symbol Limit is Protected.
>
>
> Why do we get this message? How Limit was protected WITHOUT telling
> so?
>
> In[12]:=
> Information["Limit", LongForm -> True]
>
> "Limit[expr, x->x0] finds the limiting value of expr when x approaches
> x0."*Button[More..., ButtonData :> "Limit",
>    Active -> True, ButtonStyle -> "RefGuideLink"]
> Attributes[Limit] = {Listable, Protected}
> Limit[a___] := Null /; (Print[InputForm[limit[a]]]; False)
> Options[Limit] = {Analytic -> False, Assumptions :> $Assumptions,
> Direction -> Automatic}
>
> Of course
>
> In[19]:=
> Unprotect[Limit];
> Clear[Limit];
> Protect[Limit];
>
> In[22]:=
> Information["Limit", LongForm -> True]
>
> "Limit[expr, x->x0] finds the limiting value of expr when x approaches
> x0."*Button[More..., ButtonData :> "Limit",
>    Active -> True, ButtonStyle -> "RefGuideLink"]
> Attributes[Limit] = {Listable, Protected}
> Options[Limit] = {Analytic -> False, Assumptions :> $Assumptions,
> Direction -> Automatic}
>
> but the question still remains!
>
>



  • Prev by Date: Finding unknown parameters
  • Next by Date: Re: LegendreP Evaluation Mystery
  • Previous by thread: question about Protect
  • Next by thread: Re: question about Protect