MathGroup Archive 2003

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

Search the Archive

Re: Detecting unsuccessful computations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39426] Re: Detecting unsuccessful computations
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Fri, 14 Feb 2003 03:24:31 -0500 (EST)
  • References: <b2fqoj$k9d$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

At 05:04 AM 2/13/2003, Uri Zwick wrote:
>Hi,
>
>In a previous post I claimed:
>
>>If we write
>>sol = LinearSolve[...] ;
>>If[ SameQ[Head[sol],LinearSolve] , ... , ... ]
>>then in case of failure, the failed calculation will be
>>attempted again!)
>
>This is indeed not true, as pointed out by "Omega Consulting".
>I stand corrected.
>
>BUT, my claim is true if FindMinimum is used instead of LinearSolve.
>In fact, the situation is even worse than I thought. The failed
>computation will be performed THREE times!
>
>Try the following:
>
>In[1]:= FindMinimum[x^2, {x, 1, 1/2, 3/2}]
>
>You will get one error message:
>FindMinimum::regex: Reached the point {...} which is outside ...
>
>Now try
>
>In[2]:= sol = FindMinimum[x^2, {x, 1, 1/2, 3/2}]
>
>You will get TWO error messages:
>FindMinimum::regex: Reached the point {...} which is outside ...
>FindMinimum::regex: Reached the point {...} which is outside ...
>
>The failed computation was performed twice!
>
>Finally,
>
>In[3]:= Head[sol]
>
>Another error message is printed:
>FindMinimum::regex: Reached the point {...} which is outside ...
>
>before giving the answer
>
>FindMinimum
>
>The failed computation was performed again!
>
>I suspect the same would happen with other functions,
>not just with FindMinimum.
>
>Would you consider that reasonable?
>
>It is possible to detect failed calculations using
>techniques posted as replies to my original posting.
>(Thank you all for the solutions.) But, I still feel
>that Mathematica should provide a cleaner and more
>convenient solution to the problem.
>
>Uri
>
>---------------------------------------------------------------------
>|  Prof. Uri Zwick             |  http://www.cs.tau.ac.il/~zwick    |
>|  Dept. of Computer Science   |  zwick at post.tau.ac.il              |
>|  Tel Aviv University         |                                    |
>|  Tel Aviv 69978              |  PHONE: +972 3 6409610             |
>|  ISRAEL                      |  FAX:   +972 3 6409357             |
>---------------------------------------------------------------------

In this case, you can hold evaluation to avoid the repeats.

In[2]:=
sol = Hold @@ {FindMinimum[x^2, {x, 1, 1/2, 3/2}]};

(1 message)

In[3]:=
MatchQ[sol, Hold[_FindMinimum]]

Out[3]=
True

Is that clean or convenient? I guess that's a matter of opinion. 
Personally, I don't see why these things return unevaluated at all. It's 
much easier to handle functions that indicate error by returning $Failed.

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com



  • Prev by Date: Re: Problems evaluating Grad
  • Next by Date: Re: Simple List question. HELP.
  • Previous by thread: Re: Detecting unsuccessful computations
  • Next by thread: Re: Detecting unsuccessful computations