MathGroup Archive 2001

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

Search the Archive

RE: Can Anyone Help With This?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29810] RE: [mg29795] Can Anyone Help With This?
  • From: "Annetts, David (DEM, North Ryde)" <David.Annetts at syd.dem.csiro.au>
  • Date: Wed, 11 Jul 2001 01:26:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Wilson,

> I was wondering if it is possible to turn on/off a verbose 
> mode of printing when
> running modules in Mathematica.
> 
> I have the following segment that I'd like to code, but with 
> the ability to turn
> on/off printing of intermediate results.
> 
> Here is the algorithm (for example).
> 
> Step 0: N = random odd number.
> Step 1: K = N+1, P = 1, Q = (1-D)/4, D = 1-4Q
> Step 2: Let Kr Kr-1 ... K0 be the binary expansion of K.
> Step 3: Set U = 1 and V = P.
> Step 4: For i = r-1 to 0,
> Set (U, V) = (UV mod N, (V^2 + DU^2)/2 mod N)
> If Ki = 1, then also set
> (U, V) = ( (PU +V)/2 mod N, (PV + DU)/2 mod N)
> Step 5: Uk = U and Vk = V
> 
> Is it possible to turn on/off the intermediate results of (U, V)?

The obvious way is to modularise your algorithm and ensure that the Module
takes a parameter which controls what is printed.  For example, something
like

alg[..., __opts] := Module[
	{},
	PrintLevel =  Verbose /. {opts} /. Options[alg];

	(* do something with U/V *)
	If[PrintLevel == "Partial", Print[some stuff]];
	If[PrintLevel == "All", Print[some more stuff stuff]];

	Return[];
	];

To make this work, you need to define
	Options[alg, PrintLevel->None];

and load "Utilities`FilterOptions`".


Regards,

Dave.
--------------------------------------------------------------
  David Annetts, EM Modelling Analyst, CSIRO DEM, North Ryde
  Tel: (+612) 9490 5416		
  Fax: (+612) 9490 5467		  David.Annetts at dem.csiro.au
                 Include "usual_disclaimers"
--------------------------------------------------------------


  • Prev by Date: Re: Rotating tick marks
  • Next by Date: Can this be made cleaner and more efficient?
  • Previous by thread: RE: Can Anyone Help With This?
  • Next by thread: Can This Be Made Cleaner