Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7376
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: NMinimize problem: fct minimized uses FindRoot |
| Date | 2011-12-21 11:54 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jcshd5$26f$1@smc.vnet.net> (permalink) |
| References | <201112161047.FAA06783@smc.vnet.net> <jchhbr$ieu$1@smc.vnet.net> |
> 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@hmamail.com> wrote:
> On Mon, 19 Dec 2011 12:17:22 -0000, DrMajorBob <btreat1@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@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: NMinimize problem: fct minimized uses FindRoot Oliver Ruebenkoenig <ruebenko@wolfram.com> - 2011-12-17 07:46 +0000 Re: NMinimize problem: fct minimized uses FindRoot "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-18 09:37 +0000 Re: NMinimize problem: fct minimized uses FindRoot DrMajorBob <btreat1@austin.rr.com> - 2011-12-19 12:17 +0000 Re: NMinimize problem: fct minimized uses FindRoot "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-20 08:07 +0000 Re: NMinimize problem: fct minimized uses FindRoot DrMajorBob <btreat1@austin.rr.com> - 2011-12-21 11:54 +0000
csiph-web