mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

science_man_88 2010-08-11 11:57

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)[/CODE]


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.

CRGreathouse 2010-08-11 12:26

Right. Actually I'd just code the first and let the AI (#1) figure out that they're all the same.

science_man_88 2010-08-11 12:28

[QUOTE=CRGreathouse;224891]Right. Actually I'd just code the first and let the AI (#1) figure out that they're all the same.[/QUOTE]


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

CRGreathouse 2010-08-11 12:34

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[/code]
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=science_man_88;224892]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[/QUOTE]

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.

science_man_88 2010-08-11 12:39

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 2010-08-11 12:45

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).

CRGreathouse 2010-08-11 12:47

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)[/code]

science_man_88 2010-08-11 12:50

[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.[/QUOTE]

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).

3.14159 2010-08-11 13:15

[QUOTE=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).
[/QUOTE]

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.

CRGreathouse 2010-08-11 13:42

[QUOTE=3.14159;224899]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.[/QUOTE]

[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]

[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[/code]

3.14159 2010-08-11 13:45

Ah, thanks. Although, I do have it perform trial division for isSPRP, up to 10[sup]6[/sup]. isPRP does not perform trial division.


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


All times are UTC. The time now is 21:14.

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