MathGroup Archive 2008

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

Search the Archive

Re: Re: Set::setraw error

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90379] Re: [mg90352] Re: [mg90326] Set::setraw error
  • From: DrMajorBob <drmajorbob at att.net>
  • Date: Tue, 8 Jul 2008 02:23:47 -0400 (EDT)
  • References: <32330841.1215353835393.JavaMail.root@m08>
  • Reply-to: drmajorbob at longhorns.com

I had a copying error or something that duplicated the line

xgcd[aa_,bb_]:=Module[{a=Abs@aa,b=Abs@bb},

Take one of them out.

Bobby

On Mon, 07 Jul 2008 04:05:31 -0500, DrMajorBob <drmajorbob at att.net> wrote:

> The error message tells you that you can't Set variables used as
> arguments, in this case a=-a, for instance.
>
> There are other problems, including the fact that x, y, and r are
> undefined the first time you use them in
>
> {a, b, r, s, x, y} = {b, c, x - q*r, y - q*s, r, s}
>
> which means (if you get rid of the "setraw" error), that statement will  
> be
> an infinite loop all by itself.
>
> If we knew what you were trying to accomplish, we might go farther, but
> for now I'll show you a partial solution WITH the infinite loop still
> present:
>
> Clear[a,b,xgcd]
> xgcd[0,0]={0,0,1};
> xgcd[0,b_]={Abs@b,0,Sign@b};
> xgcd[a_,0]={Abs@a,Sign@a,0};
> xgcd[aa_,bb_]:=Module[{a=Abs@aa,b=Abs@bb},
> xgcd[aa_, bb_] := Module[{a = Abs@aa, b = Abs@bb},
>    While[b != 0,
>     {c, q} = {Mod[a, b], Quotient[a, b]};
>     Print@{c, q};
>     {a, b, r, s, x, y} = {b, c, x - q*r, y - q*s, r, s}];
>    {a, x*Sign@aa, y*Sign@bb}
>    ]
> xgcd[2,3]
>
> {2,0}
> $IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
> $IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
> $IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
> General::stop: Further output of $IterationLimit::itlim will be  
> suppressed
> during this calculation. >>
> {1,1}
> {0,2}
> {1,-Hold[r]+Hold[x],-Hold[s]+Hold[y]}
>
> Notice I've changed the structure of the function to one that's much
> clearer (IMHO).
>
> To become proficient in Mathematica you need to, among other things,  
> erase
> Return from your memory.
>
> Never use it again. EVER.
>
> Bobby
>
> On Sun, 06 Jul 2008 06:17:46 -0500, Steven Siew <stevensiew2 at gmail.com>
> wrote:
>
>> I have encountered this Set:setraw error for the code below.
>>
>> I'm stumped. Does anyone have any idea what went wrong?
>>
>> xgcd[a_,b_]:=Module[{xsign=1,ysign=1,x=1,y=0,r=0,s=1,c,q},
>>     If[a == 0 && b == 0,Return[{0,0,1}]];
>>     If[a == 0,Return[{Abs[b],0,b/Abs[b]}] ];
>>     If[b == 0,Return[{Abs[a],a/Abs[a],0}]];
>>     If[a<0,a=-a; xsign=-1];
>>     If[b<0,b=-b; ysign=-1];
>>     While[b\[NotEqual]0,
>>       {c,q}={Mod[a,b],Quotient[a,b]};
>>       {a,b,r,s,x,y}={b,c,x-q*r,y-q*s,r,s}
>>       ];
>>     Return[{a,x*xsign,y*ysign}]
>>     ]
>>
>> xgcd[2, 3]
>>
>> \!\(\*
>>   RowBox[{\(Set::"setraw"\), \(\(:\)\(\ \)\), "\<\"Cannot assign to
>> raw \
>> object \\!\\(2\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \
>> ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
>> ButtonData:>\\\"Set::setraw\\\"]\\)\"\>"}]\)
>>
>>
>
>
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: Re: Glitch in online documentation system (a minor bug, actually?)
  • Next by Date: Re: Extracting terms of a polynomial into a list and then
  • Previous by thread: Re: Set::setraw error
  • Next by thread: Re: Re: Set::setraw error