Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: HoldAll?

97 views
Skip to first unread message

Andrzej Kozlowski

unread,
Oct 8, 2007, 12:15:45 AM10/8/07
to

On 7 Oct 2007, at 18:40, Szabolcs Horv=E1t wrote:

> Recently there was a question about finding the roots of an equation
> that is defined in terms of NIntegrate[].
>
> The following *works*, but it gives lots of error messages:
>
> FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}]
>
> The messages suggest that FindRoot evaluates the equation even before
> the unknown 'a' is substituted with a numerical value. This is not
> consistent with the fact that FindRoot has HoldAll.
>
> Would it be possible to
>
> 1. Either remove the attribute HoldAll to make it clear to the
> users how
> this function works (and allow FindRoot to receive Unevaluated
> arguments
> so that equations containing NIntegrate[] can be used directly),
>
> 2. Or prevent FindRoot from evaluating the equation before the unknown
> has been substituted with a numerical value.
>
> If either of these two possibilities is implementable in Mathematica,
> then IMO the current behaviour can be considered a bug. If they
> are not
> implementable, could someone explain why?
>
> --
> Szabolcs
>

I am not sure from your message if you are aware of this:

FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}, Evaluated ->
False]
{a -> 1.25643}

No error messages. Of course, one would expect that using this option
will in most cases have a negative impact ton the performance.
Why the HoldAll attribute? Well, presumably without the HoldAll
attribute the function would always be evaluated irrespective of any
option settings so one could not use this approach. Not having the
HoldAll or HoldFirst argument means that it will always be evaluated,
before the function is applied. having it does not mean that the
argument will not be evaluated; it only means it will not be "pre-
evaluated". It may still be evaluated by the function itself.

Andrzej Kozlowski

Szabolcs Horvát

unread,
Oct 8, 2007, 12:16:46 AM10/8/07
to
On 10/7/07, Andrzej Kozlowski <ak...@mimuw.edu.pl> wrote:
> I am not sure from your message if you are aware of this:
>
> FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}, Evaluated ->
> False]
> {a -> 1.25643}
>

Thanks for the reply! I did not know about this option. It is a new
option in Mathematica 6, but it seems to be undocumented (or at least
I cannot find it anywhere in the documentation).

These plotting functions accept this option too:
{ContourPlot, ContourPlot3D, DensityPlot, FindRoot, ParametricPlot, \
ParametricPlot3D, Plot, Plot3D, RegionPlot, RegionPlot3D}

Most of them have the default setting Evaluated -> Automatic (which
works with FindRoot too, though I have no idea how it decides whether
to evaluate the argument or not).

> No error messages. Of course, one would expect that using this option
> will in most cases have a negative impact ton the performance.
> Why the HoldAll attribute? Well, presumably without the HoldAll
> attribute the function would always be evaluated irrespective of any
> option settings so one could not use this approach. Not having the
> HoldAll or HoldFirst argument means that it will always be evaluated,
> before the function is applied. having it does not mean that the
> argument will not be evaluated; it only means it will not be "pre-
> evaluated". It may still be evaluated by the function itself.

With the Evaluated option, it all makes sense.

>
> Andrzej Kozlowski

Szabolcs

Andrzej Kozlowski

unread,
Oct 8, 2007, 12:18:48 AM10/8/07
to

On 7 Oct 2007, at 20:40, Szabolcs Horv=E1t wrote:

> On 10/7/07, Andrzej Kozlowski <ak...@mimuw.edu.pl> wrote:
>> I am not sure from your message if you are aware of this:
>>

>> FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}, Evaluated =


->
>> False]
>> {a -> 1.25643}
>>
>
> Thanks for the reply! I did not know about this option. It is a new
> option in Mathematica 6, but it seems to be undocumented (or at least
> I cannot find it anywhere in the documentation).
>
> These plotting functions accept this option too:
> {ContourPlot, ContourPlot3D, DensityPlot, FindRoot, ParametricPlot, \
> ParametricPlot3D, Plot, Plot3D, RegionPlot, RegionPlot3D}
>
> Most of them have the default setting Evaluated -> Automatic (which
> works with FindRoot too, though I have no idea how it decides whether
> to evaluate the argument or not).
>
>> No error messages. Of course, one would expect that using this option
>> will in most cases have a negative impact ton the performance.
>> Why the HoldAll attribute? Well, presumably without the HoldAll
>> attribute the function would always be evaluated irrespective of any
>> option settings so one could not use this approach. Not having the
>> HoldAll or HoldFirst argument means that it will always be evaluated,
>> before the function is applied. having it does not mean that the
>> argument will not be evaluated; it only means it will not be "pre-
>> evaluated". It may still be evaluated by the function itself.
>
> With the Evaluated option, it all makes sense.
>
>>
>> Andrzej Kozlowski
>
> Szabolcs

In version 5.* you could use:

Developer`SetSystemOptions["EvaluateNumericalFunctionArgument" -> False]

In Version 6 this still exists but seems to be overriden by the
setting of the option "Evaluated".

Andrzej

0 new messages