Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Simplify a module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39460] Re: [mg39450] Simplify a module
  • From: Dr Bob <drbob at bigfoot.com>
  • Date: Mon, 17 Feb 2003 04:34:00 -0500 (EST)
  • References: <200302161113.GAA07015@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Try this:

Clear@dcalc2
dcalc2[ein_] := Module[
       {a1 = Mod[ein, 3], a2 = Mod[ein, 8]Mod[ein, 2], a3 = {0, 1, 25, 33, 
37, 10, 41, 0, 43, 11, 5, 9, 45, 34, 0, 36, 46, 26, 30, 31, 27, 0, 29, 32, 
47, 2, 17, 20, 0, 22, 18, 19, 23, 3, 13, 0, 15, 4, 40, 44, 38, 6, 0, 8, 39, 
12, 16, 24, 48, 0}[[1 + Mod[ein, 49]]]},
    Mod[784a1 + 441a2 + 1128a3, 1176]]

Return is rarely used --- only when the return value is not the last 
expression in the function.

Bobby

On Sun, 16 Feb 2003 06:13:46 -0500 (EST), flip <flip_alpha at safebunch.com> 
wrote:

> Hi All,
>
> Can someone recommend a simplification to this module (just a bunch of if
> checks).
>
> It was specified to be done that way (and I know how to sove the problem
> using PowerMod in one step, so please bear with me here).
>
> Thanks, Flip
>
> (* to email me remove "_alpha" *)
>
> Anyway, here goes.
>
> dcalc[ein_] := Module[{e = ein, a1 = 0, a2 = 0, a3 = 0},
> {T1, M1, T2, M2, T3, M3} = {2, 392, 3, 147, 47, 24};
> If[Mod[e, 3] == 1, a1 = 1]; If[Mod[e, 3] == 2, a1 = 2];
> If[Mod[e, 8] == 1, a2 = 1];
> If[Mod[e, 8] == 3, a2 = 3]; If[Mod[e, 8] == 5, a2 = 5];
> If[Mod[e, 8] == 7, a2 = 7];
> If[Mod[e, 49] == 1, a3 = 1]; If[Mod[e, 49] == 2, a3 = 25];
> If[Mod[e, 49] == 3, a3 = 33]; If[Mod[e, 49] == 4, a3 = 37];
> If[Mod[e, 49] == 5, a3 = 10]; If[Mod[e, 49] == 6, a3 = 41];
> If[Mod[e, 49] == 8, a3 = 43]; If[Mod[e, 49] == 9, a3 = 11];
> If[Mod[e, 49] == 10, a3 = 5]; If[Mod[e, 49] == 11, a3 = 9];
> If[Mod[e, 49] == 12, a3 = 45]; If[Mod[e, 49] == 13, a3 = 34];
> If[Mod[e, 49] == 15, a3 = 36]; If[Mod[e, 49] == 16, a3 = 46];
> If[Mod[e, 49] == 17, a3 = 26]; If[Mod[e, 49] == 18, a3 = 30];
> If[Mod[e, 49] == 19, a3 = 31]; If[Mod[e, 49] == 20, a3 = 27];
> If[Mod[e, 49] == 22, a3 = 29]; If[Mod[e, 49] == 23, a3 = 32];
> If[Mod[e, 49] == 24, a3 = 47]; If[Mod[e, 49] == 25, a3 = 2];
> If[Mod[e, 49] == 26, a3 = 17]; If[Mod[e, 49] == 27, a3 = 20];
> If[Mod[e, 49] == 29, a3 = 22]; If[Mod[e, 49] == 30, a3 = 18];
> If[Mod[e, 49] == 31, a3 = 19]; If[Mod[e, 49] == 32, a3 = 23];
> If[Mod[e, 49] == 33, a3 = 3]; If[Mod[e, 49] == 34, a3 = 13];
> If[Mod[e, 49] == 36, a3 = 15]; If[Mod[e, 49] == 37, a3 = 4];
> If[Mod[e, 49] == 38, a3 = 40]; If[Mod[e, 49] == 39, a3 = 44];
> If[Mod[e, 49] == 40, a3 = 38]; If[Mod[e, 49] == 41, a3 = 6];
> If[Mod[e, 49] == 43, a3 = 8]; If[Mod[e, 49] == 44, a3 = 39];
> If[Mod[e, 49] == 45, a3 = 12]; If[Mod[e, 49] == 46, a3 = 16];
> If[Mod[e, 49] == 47, a3 = 24]; If[Mod[e, 49] == 48, a3 = 48];
> Return[Mod[a1*T1*M1 + a2*T2*M2 + a3*T3*M3, 1176]]]
>
>
>
>
>
>
>
>
>



-- 
majort at cox-internet.com
Bobby R. Treat



  • Prev by Date: Re: ParametricPlot - a feature or a bug?
  • Next by Date: Re: ParametricPlot - a feature or a bug?
  • Previous by thread: Simplify a module
  • Next by thread: RE: Simplify a module