Re: NMinimize problem: fct minimized uses FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg123819] Re: NMinimize problem: fct minimized uses FindRoot
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 21 Dec 2011 06:53:15 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112161047.FAA06783@smc.vnet.net> <jchhbr$ieu$1@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
> 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.)
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
- Follow-Ups:
- Re: NMinimize problem: fct minimized uses FindRoot
- From: Oliver Ruebenkoenig <ruebenko@wolfram.com>
- Re: NMinimize problem: fct minimized uses FindRoot
- References:
- Re: NMinimize problem: fct minimized uses FindRoot
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
- Re: NMinimize problem: fct minimized uses FindRoot