MathGroup Archive 2005

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

Search the Archive

Re: Re: Asking questions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58271] Re: Re: Asking questions
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 25 Jun 2005 01:56:31 -0400 (EDT)
  • References: <200506230642.CAA14625@smc.vnet.net> <200506240728.DAA00319@smc.vnet.net> <1B204CF5-B280-4564-9DF8-88C92B7112E5@akikoz.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 24 Jun 2005, at 18:31, Andrzej Kozlowski wrote:

>
> On 24 Jun 2005, at 16:28, Bharat Bhole wrote:
>
>
>> Suppose I am running a code
>> MapThread[func,{Table[d,{d,1,10}]] which takes very long to  
>> evaluate for the
>> entire list. Mathematica gives me the output ONLY after 'func[d]'  
>> has been
>> evaluated for all d from 1 to 10. Is it possible to make  
>> Mathematica give
>> the output as it is evaluating after each d. For example, is it  
>> possible to
>> make it give output after it has evaluated func[1], then func[2]  
>> and so on.
>> Thank you for your help.
>> Regards,
>> Bharat.
>>
>>
>
> I think you will need to use assignments to do this, in other  
> words, I can't see how this cold be done in a purely functional  
> way. But in a procedural way, here is an example. Suppose we run:
>
> Do[u[i] = Prime[i], {i, 1, 10^8}]
>
> which should take long enough for the demonstration. First evaluate  
> the above and then choose Enter Subsession form Kernel/Evaluation  
> menu. The evaluation  ought to be interrupted and you can check the  
> values computed so far:
>
>
> (Dialog) In[3]:=
> u[22]
>
> (Dialog) Out[3]=
> 79
>
> etc.
>
> (Dialog) In[5]:=
> Length[DownValues[u]]
>
> (Dialog) Out[5]=
> 206267
>
> will tell you the number of values mathematica has computed. When  
> you want to continue with the evaluation just choose Exit  
> Subsession form the same menu.
>
> Andrzej Kozlowski
>
> Chiba, Japan
>

In the above I assumed that what you want is to see some values  
generated by a long computation. Using Interrupt will work as long as  
you program uses assignments. On the other hand, if you really wan  
tot see all the values while the computation is running you can do it  
by using Print, eg.

Do[u[i] = Prime[i]; Print[u[i]], {i, 1, 3}]

Or even in the functional case:


f=PrimeQ;

Map[(Print[f[#]];f[#])&,Range[10]]

The latter may be the closest what you asked for but note that it  
will take twice as long as the same thing without the Print  
statements and of course is quite impractical if you are expecting  
lots of outputs. One can use various tricks to make this more  
efficient but using Interrupt or inserting Print statements is the  
only way I know of seeing computed values before the result of the  
evaluation is returned.

Note that Print does not return anything, it works purely by "side- 
effects".

Andrzej Kozlowski

Chiba, Japan



  • Prev by Date: Solve yields unreal solutions, NSolve yields real solutions
  • Next by Date: Mathematica 5.1.1 benchmark
  • Previous by thread: Re: Re: Asking questions
  • Next by thread: Re: Asking questions