MathGroup Archive 2011

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

Search the Archive

Re: NMinimize problem: fct minimized uses FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123842] Re: NMinimize problem: fct minimized uses FindRoot
  • From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
  • Date: Thu, 22 Dec 2011 04:28:13 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112211153.GAA02232@smc.vnet.net>


On Wed, 21 Dec 2011, DrMajorBob wrote:

>> So have you now changed your mind about Throw/Catch to consider it (or at
>> least its two-argument form) troublesome and/or leading to spaghetti
>> code?
>
> I didn't change my mind at all. I rarely do, as some may have noticed.
>
> Throw/Catch didn't Compile, did it? So the combination of Throw/Catch and
> Compile is troublesome. GoTo and Label encourage spaghetti code. My
> alternative avoids both.
>
> (Compile's success or failure seems unpredictable in general, so I don't
> use THAT very much, either. I rarely need anything to run in nanoseconds,
> when microseconds will do.)
>

That is not true in V8 since you can either inspect the output with 
CompilePrint or use the options that report on various issues that may 
come up during compile.

Oliver

> Bobby
>
> On Tue, 20 Dec 2011 02:05:03 -0600, Oleksandr Rasputinov
> <oleksandr_rasputinov at hmamail.com> wrote:
>
>> On Mon, 19 Dec 2011 12:17:22 -0000, DrMajorBob <btreat1 at austin.rr.com>
>> wrote:
>>
>>> I see no reason not to write it THIS way:
>>>
>>> cf3 = Compile[{{n, _Integer}},
>>>    Module[{sum = 0, i = 0}, While[i < n && sum <= 10, i++; sum += i];
>>>     If[sum > 10, 0, sum]]]
>>
>> The point of the example is to demonstrate that the compiler can handle
>> arbitrary exprs when they appear as labels and thus that there is no
>> reason in principle the two-argument form of Throw/Catch could not be
>> compiled as long as the tag was not to be treated as a pattern. I thought
>> it would be helpful to demonstrate this with a program that actually does
>> something, albeit something trivial (i.e. squaring a number) accomplished
>> in a way that I sincerely hope nobody would use in practice. Perhaps this
>> makes the original intent clearer:
>>
>> With[{loop = Plot[Sin[x], {x, -Pi, Pi}]},
>>   cf = Compile[{{x, _Integer, 0}},
>>     Block[{i = x, n = 0}, Label[loop];
>>      n += x;
>>      If[--i > 0, Goto[loop]];
>>      n
>>     ]
>>    ]
>> ]
>>
>>> It's not that I don't know how to write spaghetti code! I probably wrote
>>> more Fortran 5 in 1977-1982 than I've written in all other languages
>>> combined. (Demon, IBM Assembler, PL/1, Simscript, QGERT, SAS, MathCAD,
>>> Mathematica, and others I probably forget.)
>>>
>>> But, if there's no reason for a troublesome construct, I plan to avoid
>>> it.
>>
>> So have you now changed your mind about Throw/Catch to consider it (or at
>> least its two-argument form) troublesome and/or leading to spaghetti
>> code?
>> When the only viable alternative (as things stand) is Label/Goto, isn't
>> it
>> the lesser of two evils?
>>
>
>
> -- 
> DrMajorBob at yahoo.com
>
>



  • Prev by Date: Re: import issue
  • Next by Date: Re: question on security warning message "this file contains potentially unsafe dynamic content" with Manipulate notebook
  • Previous by thread: Re: NMinimize problem: fct minimized uses FindRoot
  • Next by thread: Re: NMinimize problem: fct minimized uses FindRoot