mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-12-06, 12:08   #2025
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

1011010111002 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
wonder how fast each is.
tested both with the equivalent of 36^577-1 and they came up equal.
I've tested both variants with (on older system):

yours: for(x=1,100000,convert(12345678901234567890,10,16)) done in 19.6 secs

mine: for(x=1,100000,convert1("12345678901234567890",10,16)) done in 10.5 secs

The main difference is:

You're using the power function and I only the multiplication:

power: a= x1*b^e1 + x2*b^e2 + x3*b^e3 + ....
multiplication: a= ((x1*b + x2)*b + x3 ...
kar_bon is offline   Reply With Quote
Old 2010-12-06, 14:52   #2026
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by kar_bon View Post
I've tested both variants with (on older system):

yours: for(x=1,100000,convert(12345678901234567890,10,16)) done in 19.6 secs

mine: for(x=1,100000,convert1("12345678901234567890",10,16)) done in 10.5 secs

The main difference is:

You're using the power function and I only the multiplication:

power: a= x1*b^e1 + x2*b^e2 + x3*b^e3 + ....
multiplication: a= ((x1*b + x2)*b + x3 ...
I knew you'd be better than me in like 2 seconds lol.
science_man_88 is offline   Reply With Quote
Old 2010-12-06, 15:26   #2027
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

No big deal, he knew Horner form and you didn't.
CRGreathouse is offline   Reply With Quote
Old 2010-12-06, 16:11   #2028
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
No big deal, he knew Horner form and you didn't.
he should put his up, yeah I had no power this morning but it's back up now I'm kinda worried my mom supposedly had hypercapnia last night and they think codeine ( methyl-morphine) may have helped it unsurprising with morphine allergies in the family history. I know more terms than my sisters so I can describe it but I haven't gone in to see her yet. I was told to a few times I'm not sure if I have something, They think the flu shot may have triggered her so hopefully I don't do the same. they haven't given water, I think it's from the fact that unless they give a lot they acidify the blood by production of carbonic acid.
science_man_88 is offline   Reply With Quote
Old 2010-12-06, 19:41   #2029
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

I think I found something interesting to talk about with the lucaslehmer() axn came up with. Mind if I see what you think ?

Last fiddled with by science_man_88 on 2010-12-06 at 19:43
science_man_88 is offline   Reply With Quote
Old 2010-12-06, 21:19   #2030
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Go for it.
CRGreathouse is offline   Reply With Quote
Old 2010-12-06, 21:24   #2031
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Go for it.
if you replace 0 with s and do:

Code:
for(x=1,100,print(lucaslehmer2(x)%x","x))
you get many answers printed but:

Code:
for(x=1,100,print(lucaslehmer2(x)%11","x))
gets you only 2 results as far as I see.
science_man_88 is offline   Reply With Quote
Old 2010-12-06, 23:14   #2032
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

never mind I see a pattern forming but I bet it's well known.
science_man_88 is offline   Reply With Quote
Old 2010-12-07, 00:47   #2033
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

22·727 Posts
Default

Here are some string maipulation functions, because I missed them much:

- String to upper case
- String to lower case
- Left string
- Right string
- Mid string

Functions like Find or Replace are therefore possible, too.

More suggestions:
- StrFlip: lower to upper and upper to lower in one string
- StrCap: only first character of string/word capitalize
- StrTrim: delete spaces from beginning/end of string

I think StrReverse or CheckPalindrome were done, right?

Code:
addhelp(StrToUp, "StrToUp(str): Convert a string str in upper case.");
StrToUp(str)={
  my(sup=Vecsmall(str),s="");
  for(n=1,#sup,
    if(sup[n]>=97 && sup[n]<=122,
	s=concat(s,Strchr(sup[n]=sup[n]-32)),
	s=concat(s,Strchr(sup[n])))
  );
s
};

addhelp(StrToLow, "StrToLow(str): Convert a string str in lower case.");
StrToLow(str)={
  my(sup=Vecsmall(str),s="");
  for(n=1,#sup,
    if(sup[n]>=65 && sup[n]<=90,
	s=concat(s,Strchr(sup[n]=sup[n]+32)),
	s=concat(s,Strchr(sup[n])))
  );
s
};

addhelp(StrLeft, "StrLeft(str,n): Gives back n characters from left of string str.");
StrLeft(str,n)={
  my(strh=Vecsmall(str),s="");
  if(n<1, return(s));		\\ n too small: return empty string
  if(n>=#strh, return(str));	\\ n to big: return str
  for(x=1,n,
      s=concat(s,Strchr(strh[x]))
  );
s
};

addhelp(StrRight, "StrRight(str,n): Gives back n characters from right of string str.");
StrRight(str,n)={
  my(strh=Vecsmall(str),s="");
  if(n<1, return(s));		\\ n too small: return empty
  if(n>#strh, return(str));	\\ n too big: return str
  for(x=#strh-n+1,#strh,
      s=concat(s,Strchr(strh[x]))
  );
s
};

addhelp(StrMid, "StrMid(str,n,m): Gives back m characters from position n of string str.");
StrMid(str,n,m)={
  my(strh=Vecsmall(str),s="");
  if(n<1, n=1);			\\ n too small: set n=start of string
  if(n>#strh, return(s));	\\ n too big: return empty string
  if(n+m>#strh, m=#strh-n+1);	\\ m too big: set m maximum length available
  for(x=n,n+m-1,
      s=concat(s,Strchr(strh[x]))
  );
s
};
Notes:

- The expression "sup[n]=sup[n]+32" won't work with "sup[n]+=32" !

- Typing in characters like German Umlaute are not allowed/not doable in PARI!

Last fiddled with by kar_bon on 2010-12-07 at 01:05
kar_bon is offline   Reply With Quote
Old 2010-12-07, 01:06   #2034
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by kar_bon View Post
I think StrReverse or CheckPalindrome were done, right?
So is FaR lol

Last fiddled with by science_man_88 on 2010-12-07 at 01:06
science_man_88 is offline   Reply With Quote
Old 2010-12-07, 01:19   #2035
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by kar_bon View Post
- The expression "sup[n]=sup[n]+32" won't work with "sup[n]+=32" !
It should...

Code:
> v=vector(3,n,n);v[2]+=10;v
%1 = [1, 12, 3]
> v=vectorsmall(3,n,n);v[2]+=10;v
%2 = Vecsmall([1, 12, 3])
Quote:
Originally Posted by kar_bon View Post
- Typing in characters like German Umlaute are not allowed/not doable in PARI!
Right, it uses C strings rather than Unicode. A person who cared should be able to hack together a solution with enough care, but since I avoid Pari for string processing I haven't though about it much. (I have run into it, though, like when I mention French or German authors in addhelp() lines and can't use accents in their names.)
CRGreathouse is offline   Reply With Quote
Reply

Thread Tools


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 22:43.


Fri Aug 6 22:43:29 UTC 2021 up 14 days, 17:12, 1 user, load averages: 4.78, 4.24, 3.78

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.