mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-08-11, 11:57   #210
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

eg. primorial = prime factorial || primorial (well dah) || multiplication of primes upto n || multiplication of the first n primes

is there a way to equate 2 names to a function one to mean the other. if so should be easy

oh wait I could do this:

Code:
primorial(n)= a=1;for(p=1,n,if(isprime(p),a=a*p));return(a)

prime_factorial(n)=primorial(n)

multiplication_of_primes_upto(n) = primorial(n)

then all these are equal and the code should be able to put the words into a function name and figure it out regardless.

they all work as planned I tested them.

Last fiddled with by science_man_88 on 2010-08-11 at 12:24
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 12:26   #211
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Right. Actually I'd just code the first and let the AI (#1) figure out that they're all the same.
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 12:28   #212
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
Right. Actually I'd just code the first and let the AI (#1) figure out that they're all the same.

I'm not sure how to do this in AI yet (I do have a uncle in robotics teaching last I checked wonder if someone like that would help) maybe I should have learned KPL lol

AI is artificial intellegence but it seems like AI is also automatically inferred

Last fiddled with by science_man_88 on 2010-08-11 at 12:34
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 12:34   #213
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

I meant to also say: your method of defining function synonyms is good. (It avoids duplication, which is bad.)

Another possibility would be literally
Code:
prime_factorial=primorial
that is, setting the variable prime_factorial equal to the value of primorial, which is itself a 'function-object'. (Pari calls this a "closure".)

Quote:
Originally Posted by science_man_88 View Post
I'm not sure how to do this in AI yet maybe I should have learned KPL lol

AI is artificial intellegence but it seems like AI is also automatically inferred
I meant it in the sense of artificial intelligence. The essential problem is deciding what the human wants and that's a classic strong-AI task.
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 12:39   #214
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

yeah the equals is good see what i was thinking is:

if someone said:

"multiplication of primes upto"

it would replace " " with "_" and get a function name it can look for.
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 12:45   #215
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

think the hard part then is:

1)size of the database
2)printing the code the function uses not the function itself(unless it makes it part of their database first).
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 12:47   #216
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Fortunately you can print functions (as closures) in the development version, which I'm sure you downloaded rather than the old 'stable' version.

Code:
foo(n)={
  if(n%7 == 4,
    print(n" is a foo");
    1
  ,
    print(n" is not a foo");
    0
  )
};
print(foo)
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 12:50   #217
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Reading GPRC: /cygdrive/c/Program Files/PARI/.gprc ...Done.

GP/PARI CALCULATOR Version 2.4.2 (development CHANGES-1.1971)
i686 running cygwin (ix86/GMP-4.2.1 kernel) 32-bit version
compiled: Dec 23 2007, gcc-3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
(readline v5.2 enabled, extended help enabled)

Copyright (C) 2000-2006 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY
WARRANTY WHATSOEVER.
looks like it to me.

how is this like prime_factorial=primorial ? this seems to print the code of foo but doesn't equate it to another function but I think I know what you mean. This is getting less complicated by the minute, (though the database might get quite big and that's a mountain to climb).

Last fiddled with by science_man_88 on 2010-08-11 at 13:09
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 13:15   #218
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by CRGreathouse
But I thought you were looking at strong pseudoprimes, not Fermat pseudoprimes. In that case "Average case error estimates for the strong probable prime test" is probably more appropriate, though I don't remember if they define an analogue for P(x).
Well, I did manage to get the complete false witness sequence for 2701. It is pseudoprime to 486 bases. That means, it will be registered as composite 82% of the time.

Last fiddled with by 3.14159 on 2010-08-11 at 13:35
3.14159 is offline   Reply With Quote
Old 2010-08-11, 13:42   #219
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Well, I did manage to get the complete false witness sequence for 2701. It is pseudoprime to 486 bases. That means, it will be registered as composite 82% of the time.
Code:
isSPRP(n,b=2)={
	my(s=valuation(n-1,2),d=n>>s);
	n=Mod(b,n)^d;
	if(n==1,return(1));
	while(s--,
		if(n==-1,return(1));
		n=n^2
	);
	n==-1
};
ratioSlow(n)={
	1.-sum(b=1,n-1,isSPRP(n,b))/(n-1)
};
star(n)={
	n--;n>>valuation(n,2)
};
ratio(n)={
	my(f=factor(n)[,1],nu=valuation(f[1]-1,2),nn=star(n));
	for(i=2,#f,nu=min(nu,valuation(f[i]-1,2)););
	1.-(1+(2^(#f*nu)-1)/(2^#f-1))*prod(i=1,#f,gcd(nn,star(f[i])))/(n-1)
};
Code:
>ratio(2701)
time = 31 ms.
%1 = 0.8200000000000000000000000000

>ratioSlow(10^6+1)
time = 34,071 ms.
%2 = 0.9962500000000000000000000000
>ratio(10^6+1)
time = 0 ms.
%3 = 0.9962500000000000000000000000

Last fiddled with by CRGreathouse on 2010-08-11 at 13:46
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 13:45   #220
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Ah, thanks. Although, I do have it perform trial division for isSPRP, up to 106. isPRP does not perform trial division.


Also: Define star(n) (I haven't defined it already.)

Last fiddled with by 3.14159 on 2010-08-11 at 13:50
3.14159 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 06:55.


Fri Aug 6 06:55:33 UTC 2021 up 14 days, 1:24, 1 user, load averages: 2.53, 2.64, 2.71

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.