# TITLE: Gaussian Integer Decomposition to Irreducible Factors # AUTHOR: Roy F.A. Maclean # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 8Apr1997, 21May1999 # MAKE: CASIO # MODEL: 9850 # SIZE: 342+58 # # NOTES: Enter a gaussian integer # (i.e. a number of the form A+Bi with A,B integers) # The irreducible factors will be displayed. # Irreducible means can't be written as product of two non-unit factors # where the units for gaussian integers are 1,-1,i,-i # But it displays results using only positive parts for the factors # so in cases where this isn't possible it also displays # a final factor i or -i to finish. # # e.g. if you enter then number 5 # it will display: # 2+i # 1+2i # -i # which means the number 5 can't be written with only # positive factors as it needs that last -i # You can tidy this up yourself by combining the -i with # the penultimate factor so -i(1+2i)=2-i # # so 5 = (2+i)(1+2i)(-i) # or slightly tidier: # 5 = (2+i)(2-i) # # \i represents the complex i @@ Program "GID 1" Lbl 0 ?->Z Lbl 3:0->T sqrt(Abs Z->R Frac R<>0=>Int (1+R->R 1+\i Prog "GID 2" T=1=>Goto 3 2->A:Lbl 1 1->C Frac .5A=0=>2->C A Prog "GID 2" T=1=>Goto 3 1->B:Lbl 2 A+B\i Prog "GID 2" T=1=>Goto 3 B+A\i Prog "GID 2" T=1=>Goto 3 B+C->B B<=(A-1=>goto 2 Isz A A<=(R-1=>Goto 1 R=1=>Goto 4 R Prog "GID 2" T=1=>Goto 3 Lbl 4 Abs Z=1=>Goto 5 Abs Z Prog "GID 2" T=1=>Goto 3 Lbl 5 Z=1=>Goto 0 Abs Z=1=>Z_ Abs Z=1=>Goto 0 ReP Z->A ImP Z->B A>0=>B>0=>1->C A<0=>B<0=>-1->C A<0=>B>0=>\i->C A>0=>B<0=>-\i->C Z/C_ C<>1=>C_ Goto 0 @@ Program "GID 2" Ans->V Z/V->W If Frac ReP W=0 And Frac ImP W=0 Then V_ W->Z 1->T IfEnd