![]() |
|
|
#210 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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 |
|
|
|
|
|
#211 |
|
Aug 2006
135338 Posts |
Right. Actually I'd just code the first and let the AI (#1) figure out that they're all the same.
|
|
|
|
|
|
#212 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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 Last fiddled with by science_man_88 on 2010-08-11 at 12:34 |
|
|
|
|
|
|
#213 |
|
Aug 2006
597910 Posts |
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 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. |
|
|
|
|
|
#214 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
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. |
|
|
|
|
|
#215 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
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). |
|
|
|
|
|
#216 |
|
Aug 2006
3·1,993 Posts |
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)
|
|
|
|
|
|
#217 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
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 |
|
|
|
|
|
|
#218 | |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Quote:
Last fiddled with by 3.14159 on 2010-08-11 at 13:35 |
|
|
|
|
|
|
#219 | |
|
Aug 2006
135338 Posts |
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:
>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 |
|
|
|
|
|
|
#220 |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
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 |
|
|
|
![]() |
| 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 |