U.P.B. Sc. Bull., Seres A, Vol. 68, No. 3, 6 COMPUTERISED ALGEBRA USED TO CALCULATE X COST AND SOME COSTS FROM CONVERSIONS OF P-BASE SYSTEM WITH REFERENCES OF P-ADIC NUMBERS FROM Z AND Q C.A. MURESAN Autorul acestu artcol îcearca sa subleze mortata utlzar uor cât ma efcet algortm de calcul etru ca sa fe cât ma ut utlzate resursele calculatorulu, astfel îcât umarul de oerat sa fe ma mc.dua rezetarea uor algortm dfert, se calculeaza matematc costul algortmlor clusv lacoversa d baza î baza a uor umere -adce d Z resectv Q. The author of ths artcle tres to outle the mortace of usg as much as ossble the calculato algorthms order to reduce the use of the comuter. After resetg some dfferet algorthms, the cost of the algorthm s mathematcally calculated, cludg the coverso from a -adc umber to a base- system of a umber from Z ad Q also. Keywords : costs, algorthms, -adc umber Itroducto The artcle wll focus o two algorthms used for fdg out. I oe stuato ca be drectly calculated from the followg relato =... of tmes, whereas the secod oe, we wll use the bary wrtg of. Defg the cost of the algorthm as beg the umber of multlcatos used durg the calculato of, we wll observe that the secod algorthm has a cost C() = α [lg ]; α [,] ; C() s the cost ;w hereas the frst oe has a - cost. The secod algorthm wll be faster tha the frst oe. I order to demostrate these statemets we must observe that f = ; {,} s a bary wrtg of the = PhD Studet, Det. of Mathematcs, Uversty Poltehca of Bucharest, ROMANIA
34 C. A. Muresa C() = -+) + e () +...+ e () where C() s the cost of the secod algorthm. Passg the to some equaltes we wll obta the recedg statemets. Fally, usg the revous formula, we have calculated the coversos costs of atural umbers base- or of some -adc ratoal umbers from Q.. Estmates of the costs of the algorthms used to calculate Defto : The cost of a algorthm that calculates s gve by the umber of the multlcatos effectuated utl we get the result; f we use umber ( to rereset the algorthm, the ts cost wll be C(. Method o : calculato usg algorthms (): Data:, {y s the result} y: = for = to - results y = y Proosto : The cost of the algorthm () s - meag that C()= -. have Proof: It s obvous that for fdg out usg multlcatos of we K for tmes whch mea that we wll have - multlcatos. Method o : We ca fd out a reresetato the -base system. usg the algorthm () where have Be t = ; {, } the = = = ad =, e here we ha ve the algorthm () : Data :, z:= ;y = {the result s y} y: = whle > do beg := [/]; f >* the y: = y*z; z: = z*z := ed; y:=y*z;
Comutersed algebra used to calculate X cost ad some costs from coversos 3 4 8 I ths algorthm z we wll obta the values,,... for every ste, ad y=y*z for every ste whe s a eve umber ad y s the same umber whe s a odd umber. Fally y s. Eamle : Fd (see the et table ) usg the algorthm z y 4 8 The multlcatos ths algorthm are: 4 8 4 4 =, =, =, = 6 6 4 = Numbers of multlcatos for ths eamle s 6 so C() =6. Observato:, 6 8 8 = If ( ) )... ) )) ( ) s the umber -base system the because: = 4 + 3 + + + we have )=,)=,)=,3)=, 4)= ad ( ) )... ) )) () = () =4 where += s the legth of -base system. The -+) + e () +...+ e () =4-+++++=6 Ths s the formula for the algorthm s cost. Defto..Let ( a ),( b ) be two sequeces of ostve umbers.we say that ( a) s O( b) f there est two ostve costats c,c such that c b a C b for every Ν. So, O ( b ) = a. (O s called Ladau s symbol). Proosto. C() = ([ lg ] ) ad [ lg ] C() [ ] O lg Proof: C() s the umber of multlcatos used the algorthm. From = = we obta : = ) ), { } e (,.......... ),
36 C. A. Muresa 4,... form: where - wll be the umber of multlcatos for :, where j j ( ) ad = ( )., for = j, N. = j or fact,the umbers of multlcatos for: 4 =, = from the algorthm. Ad ; = 8 4 4, =,, l l l =... = ( wll be the total umber of multlcatos betwee all the terms wth the * j)* ad ( order to determe ).,, j The C() = -+) + e () +...+ e () We ca suose ) = wthout restrctg the geeralty. But +++..++=e () + ) +...+ ) = ++...+= + ad the for the two relatos results: = C( ) ( ) + ( + ) =., where = ; {, } s the otato for -base system = (meag that legth s + ). The frst relato wll be: = C() = () where + s the legth of whch s wrte -base system. We also have = + ) + K + ) + ) where t has bee assumed that ) = wthout restrctg the geeralty. The = lg = = [ ] lg () whch wll be the secod relato wth [,] whole art. )
Comutersed algebra used to calculate X cost ad some costs from coversos 37 From () ad () results C() = = [ ] C() = [ ] lg so the3 rd relato: lg (3) From the revous relato we wll also have = + ) + K + ) + ) ad t results that + + + + + + + K + + = = < ; ad we have. So [ lg ] < + [ ] equvalet wth the 4th relato: lg. (4) From () ad (4) results [ lg ] C() therefore the th relato: [lg ] = C() () From (6) ad (7): [lg ] = C() = [lg ] ad from here t s obvous that ( ) R ( ) α R such that C() = α [lg ]; α [, ] ad therefore: C() = ([ ] ) O lg. Proosto 3: The d algorthm s oe of the fastest way of fdg lg where cost C(g ) s of the geeral algorthm (g). what t meas: C(g) [ ] Demostrato: Every algorthm (t wll be amed geeral algorthm (g) of cost- C(g)) must follow the stes. The algorthm (g): Ste : y : = ab where a,b {,} Ste : y : = a b where a, b have bee revously foud meag a, b {,,y, y,, y } Ste m : (the fal ste) y m : = a mbm ; a m, bm {,,y, y,, y m } where = y m : whch meas that we have reached the result, the cost of the algorthm s C(g)= m. Our d algorthm also belogs to ths class. I the revous algorthm for y : = ) we have: ) = {,, }.
38 C. A. Muresa I cotra st wth algorthm () where ) {, }. The for geeral algorthm : ) = + j) where <, j < for = ad m) =. Therefore ) = ; ) = ) + ) = ad through ducto results ) = ; ( ) =. I the ed, m) = so, m) = = m meag lg = m=c(g) [ lg ] = m [ ] If we cosder the cost classes accordg to α beg O[ α ] we wll have usg the d algorthm a algorthm of the fastest class because [ lg ] = C() = [ lg ] ad [ lg ] = C(g). base.estmates of the costs of the algorthms used for coversos - Defto.3. N = α / α = a, a, N; a = are the -adc umbers from N Z = = α / α a, a N; a = are the -adc umbers from Z ad we ca defe these umbers as the verses of aturals umbers wrtte -base system. Q = = α / α a, Z, a N; a = are the -adc umbers from Q. Proosto 4.: The cost of wrtg a atural umber from the -base O lg (!) system to -base system s C()= [ ] The atural umbers wrtte the -base system ca also be wrtte N ad they are called -adc umbers from N. Proof:
Comutersed algebra used to calculate X cost ad some costs from coversos 39 Be t N = ( a, a Ka, a, a) s the wrtg a -base system for, where a a {,,.-}, for {,,, -} meag: = a + a + K + a + a + a We cosder the wrtg cost of a -adc umber rereseted by the umber of multlcatos ad the: [ lg ] + O[ lg ( ) ] + + O[ lg ] [ lg ] C ( ) = O K + O C( ) = C lg + C lg ( ) + K + C lg where C R coveetly chose. Be t m c = c; ma c = C the {,,..., ] {,,..., ] c lg C( ) C lg c lg (!) C( ) C lg (!) = = C() = O [ (!)] lg. Obs..: The umber from Z ; Z; < see as reverses to those from N -adc have a smlar otato wth the revous oe; so: Z,C() = lg (!). O [ ] Obs..: The umber from Q that have a -adc fte reresetato : = ( aa Kaa, a Ka m ) for + = a ; m N, = a < = m are called -adc umber from Q to a fte reresetato. Proosto.: The cost C(), Q to a fte reresetato: + = a ; whe coversg a abstract mode the base- system = m C ( ) = O lg ( m + )!. wth the revous relato, of a ratoal umber,s [ ] Proof: From Q;
4 C. A. Muresa a = = + + + + + a + a m a a a K a a + K + m = m m+ m + m+ m m m a + a a a a a.. + + + + + + = K m... + a m+ + a m m So Q ad C( ) = O[ [ ] ] = C( a ), {,..., m } [ lg ( m) ] lg ad + O s the cost for the deomator m, C( m ) = m O[ lg [ m] = C ( a ) has bee calculated. So Q; C ) = O[ lg ( m + ) ] + K + [ lg ] ( O [( m )!] C ( ) = lg +. Obs.3.: The costs for a multlcato ad for a dvsato of two reals umbers wth btes, we ca see [3]. Coclusos It s obvous that we must loo for a less eesve method for mathematcal calculatos. As a result, less resources ad comuter oeratos wll be used. R E F E R E N C E S. Gouvea, F.Q. - P- adc Numbers.A troducto Secod Edto..New Yor- Ed.:Srger- Verlag 997. Kuth, D. The Art of Programg vl. secod edto - Ed:Addso Wesley 98 3. Mgotte, M. - Itroducere algebra comutatoala s rogramare lara - Edtura Uverstat d Bucurest