Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Re: question about Protect

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75182] Re: [mg75149] Re: question about Protect
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 19 Apr 2007 04:38:42 -0400 (EDT)
  • References: <f013jm$8f5$1@smc.vnet.net> <200704180909.FAA08595@smc.vnet.net>

On 18 Apr 2007, at 18:09, dimitris wrote:

> Hello.
>
> What version do you use?

In[1]:=
$Version

Out[1]=
5.2 for Mac OS X (February 24, 2006)

> On mine I get
>
> In[1]:=
> Unprotect[Limit];
>
> In[2]:=
> Attributes[Limit]
>
> Out[2]=
> {Listable}
>
> In[3]:=
> Integrate[Exp[-x], {x, 1, Infinity}]
>
> Out[3]=
> 1/E
>
> In[4]:=
> Attributes[Limit]
>
> Out[4]=
> {Listable, Protected}
>
> Note that Limit MISSES the attribute ReadProtected from the attributes
> list appeared
> on your post.
> (As long as I remember you use 5.2 for Mac; If so, does it seems
> logical
> this difference between the two versions?)

Yes, you are right. The difference is strange.


As for the rest: I agree with you. I misinterpeted the behaviour I  
observed. I think I can partly explain what you (and also Daniel  
Hubner) observed, but there is a new puzzle which will emerge from  
all this.

Fist of all, I was right to assert that when Mathematica's built-in  
functions call on other built-in functions they ofen perform a  
Unprotect-Protect sequence of operations on them. We can see this  
clearly as follows:

Unprotect[Protect];
Protect[a___] := Null /; (Print[protect[a]]; False)

Integrate[1/Sqrt[Abs[x]], {x, -1, 2}]

You will now see Mathematica explicitly protecting various functions.  
Now comes the really puzzling thing: Limit is not among them! This is  
the new puzzle, so let's leave it for the time being and  and  
investigate Series, which visibly is one of them. Now, with Series  
things are clear. Let's start with a fresh Kernel:

Quit[]

Unprotect[Protect];
Protect[a___] := Null /; (Print[protect[a]]; False)
In[1]:=
Unprotect[Protect];
Protect[a___] := Null /; (Print[protect[a]]; False)


In[3]:=
Unprotect[Series];

In[4]:=
Attributes[Series]

Out[4]=
{}

Now let's run:

Integrate[1/Sqrt[Abs[x]], {x, -1, 2}]

I have removed the output as it is quite long but you will see  
several protect[Series] in it. This makes it not surprising that we  
now have:

In[6]:=
Attributes[Series]

Out[6]=
{Protected}

Now David's phenomenon. Let's Unprotect Series again:

Unprotect[Series];

In[8]:=
Attributes[Series]

Out[8]=
{}

Let's also clear the Cache:

Developer`ClearCache[];

Let's again evaluate the same integral:

Integrate[1/Sqrt[Abs[x]], {x, -1, 2}]

You will see only protect(Developer`ZeroQ) a number of times. Somehow  
Integrate no longer performs the Unprotect and Protect operations it  
performed the first time, so of course now we have:

In[12]:=
Attributes[Series]

Out[12]=
{}

It looks like that clearing the cache is not enough to make  
Mathematica forget the previous Integrate. Maybe there is another  
function (other than Quit[] and Exit[] that will do that, I don't  
know). But essentially this, I think, explains what happens in the  
case of Series and it also explains Daniel Hubner's observation that  
the Protection happens only once in a session.

Now, it does not quite explain the case of Limit because Limit never  
seems to be explicitly Protected and Unprotected by Integrate! The  
only explanation that comes to my head is that actually this is also  
done with Limit, but somehow in a "hidden" way so that even the trick  
of with Unprotect[Protect] etc. does not reveal it. That's all that I  
can tell, for more we need someone form wri to reply to this post.

Andrzej Kozlowski







>
> In[5]:=
> Unprotect[Limit];
>
> In[6]:=
> Attributes[Limit]
>
> Out[6]=
> {Listable}
>
> In[7]:=
> Integrate[Exp[-x], {x, 1, 2}]
>
> Out[7]=
> (-1 + E)/E^2
>
> In[8]:=
> Attributes[Limit]
>
> Out[8]=
> {Listable}
>
>> It seems that built-in functions, when they call on another built in
>> function will sometimes Protect if it had previously been  
>> Unprotected.
>
> Your statement seems to have a basement, but your examples are quite
> contradictory. I mean, in the first example it seems that after
> Integrate obtained the
> antiderivative and search for convergence (where Limit is first
> called) it
> then (re)calls Limit in order to apply the Nweton-Leibniz formula.
>
> That is, I think something like the following take place
>
> In[24]:=
> (Limit[Exp[-x], x -> #1] & ) /@ {1, Infinity}
> ant = Integrate[Exp[-x], x]
> (Limit[ant, x -> #1] & ) /@ {1, Infinity}
> (Plus[#2 - #1] & ) @@ %
>
> Out[24]=
> {1/E, 0}
> Out[25]=
> -E^(-x)
> Out[26]=
> {-(1/E), 0}
> Out[27]=
> 1/E
>
> And in the end Limit was Protect(ed).
>
> In the second example (since Limit was not protected and based on your
> argument)
> it seems that Limit was not called at all. But then how Integrate
> checked for convergence
> and moreover how the Newton-Leibniz formula was applied?
>
> I mean by hand we can write down
>
> In[32]:=
> Simplify[(ant /. x -> 2) - (ant /. x -> 1)]
>
> Out[32]=
> (-1 + E)/E^2
>
> but as far as know even for simple cases like these (that is no
> indeterminate forms that
> required limits or improper integrals and the staf) Mathematica
> evaluates the antiderivative
> at the end-points with something like
>
> In[34]:=
> Simplify[Limit[ant, x -> 2] - Limit[ant, x -> 1]]
>
> Out[34]=
> (-1 + E)/E^2
>
> I was puzzled. But now I got more confused!
>
>> I have not investigated this sufficiently to be able to describe the
>> exact circumstancs under which this happens...
>
> I hope you will find the time to do so. With your mathematical and
> Mathematica
> knowledge I am quite sure you will succeed in finding what is going on
> and then...
> share your conclusion with us if you don't mind!
>
>> 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
>> restore the attributes the function had when it was called; so this
>> might be a minor bug?
>
> Bug or not a bug it deserves a thorough explanation by someone from
> WRI.
> Until then above explanation (or should I say guessing?) of you is
> what we
> just have on our hands!
>
>
> Kind Regards
> Dimitris
>
>
>
>
>
>
>
>
> =CF/=C7 dimitris =DD=E3=F1=E1=F8=E5:
>> 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: Re: how make function of solution by NDSolve depending on parameter?
  • Next by Date: Bounding Parameters used in FindFit[]
  • Previous by thread: Re: question about Protect
  • Next by thread: functional programming