Re: NMinimize problem: fct minimized uses FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg123810] Re: NMinimize problem: fct minimized uses FindRoot
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
- Date: Tue, 20 Dec 2011 03:05:03 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112161047.FAA06783@smc.vnet.net> <jchhbr$ieu$1@smc.vnet.net>
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?
- References:
- Re: NMinimize problem: fct minimized uses FindRoot
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
- Re: NMinimize problem: fct minimized uses FindRoot