mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-11-29, 18:33   #1794
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Ah. You should only use one, but pre-set it to the appropriate size, filled with 0s, then *add* rather than concatenate. That way you can go from

[0, 0, 0, 0, 0]
to
[0, 0, 0, 0, 6]
to
[0, 0, 0, 4, 6]
to
[0, 0, 0, 13, 6]
to
[0, 0, 6, 13, 6]
which can be simplified to
[0, 0, 7, 3, 6]
and then
[7, 3, 6]
if desired.
I was thinking of using while loops and another vector, but your way works I think. The problem is if I get 9*9 then it makes it can make it even longer still.
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 18:39   #1795
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I was thinking of using while loops and another vector, but your way works I think. The problem is if I get 9*9 then it makes it can make it even longer still.
If you multiply an n digit number by an m digit number, n + m digits will suffice (though the most significant digit may be 0).
CRGreathouse is offline   Reply With Quote
Old 2010-11-29, 18:54   #1796
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
If you multiply an n digit number by an m digit number, n + m digits will suffice (though the most significant digit may be 0).
Okay I think I get the preset stuff, if I just add I get 4+9+6+6 if I have it as is.

Last fiddled with by science_man_88 on 2010-11-29 at 18:54
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 19:27   #1797
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Code:
answer[#answer-(x*y-1)]=(answer[#answer-(x*y-1)]+n);carry=floor((c[y]*d[x])/10)
getting closer I got to:

Code:
[6, 0, 13, 6]
I know why it's happened, going to have to work out how to fix it. and it all has to do with: (x*y-1) because:
-(1*1-1) gives -0,
-(2*1-1) and -(1*2-1) give -1,But
-(2*2-1) gives -(3) so it skips -2 the place it should go in.

Last fiddled with by science_man_88 on 2010-11-29 at 19:40
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 19:38   #1798
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

I wouldn't worry about carries; just fix them in the end.
CRGreathouse is offline   Reply With Quote
Old 2010-11-29, 19:44   #1799
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
I wouldn't worry about carries; just fix them in the end.
It's not a carry problem it's a placement formula error problem because I should of had a formula to place the 6 in the 2nd from right not the very right.

Last fiddled with by science_man_88 on 2010-11-29 at 19:44
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 20:00   #1800
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
It's not a carry problem it's a placement formula error problem because I should of had a formula to place the 6 in the 2nd from right not the very right.
Every time you move one digit to the left on the multiplier you need to move the result one digit to the left.
CRGreathouse is offline   Reply With Quote
Old 2010-11-29, 20:04   #1801
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Every time you move one digit to the left on the multiplier you need to move the result one digit to the left.
Instead of multiplying I should be adding lol and subtracting 1 I think. I'll try it.
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 20:16   #1802
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Got it working for 2 digits I'll check for 3. If it works I'll just need to chop off a 0 on the end.
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 20:18   #1803
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Got it working for 2 digits I'll check for 3. If it works I'll just need to chop off a 0 on the end.
oh and then the carry has to be done in the additions.
science_man_88 is offline   Reply With Quote
Old 2010-11-29, 20:52   #1804
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
longmultiply(a,b)= c=eval(Vec(Str(a)));d=eval(Vec(Str(b)));carry=0;answer=vector(length(d)+length(c));forstep(x=#d,1,[-1],forstep(y=#c,1,[-1],n=((c[y]*d[x])+carry)%10;answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);carry=floor((c[y]*d[x])/10)));forstep(w=#answer,2,-1,answer[w-1]=answer[w-1]+floor(answer[w]/10);answer[w]=answer[w]%10)
One thing I can't seem to do is shift it maybe I'll have to add it in as another loop, this code is making me loopy.
science_man_88 is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

All times are UTC. The time now is 23:01.


Fri Aug 6 23:01:50 UTC 2021 up 14 days, 17:30, 1 user, load averages: 3.99, 4.10, 4.01

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.