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-09-08 21:53

one more thing worked out and I think I have it for one find replace then it's a matter of vectors i think.

science_man_88 2010-09-08 21:55

[CODE]%135 = (string_to_search,string_to_find)->my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c="";d="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,d=concat(c,"loser!");print1(d);c="";i=i+#s2))
(18:51) gp > substring("hello Alex, Good bye Alex","Alex") c="";i=i+#s2))
hello loser! Good bye loser!
<s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,d=concat(c,"loser!");print1(d);c="";i=i+#s2))[/CODE]

Ive got to pass it to a full vector now and then get it resubmitting it until all the searches are done lol.

science_man_88 2010-09-08 22:12

which could be done with a further script part to multi-search with Vec()

CRGreathouse 2010-09-08 22:29

It looks like you have it working the way you want.

science_man_88 2010-09-08 22:52

[QUOTE=CRGreathouse;229100]It looks like you have it working the way you want.[/QUOTE]

well I think one more change may help. then you can apply it to Vec of Vec to do find and replace and maybe even a Vec of Vec to call each Vec of Vec to search multiple functions to make it search for ? or do you want me to set up Vec although you want to Use it on your PC it may need them to do multiple searches autonomously.

science_man_88 2010-09-08 23:01

[CODE]%4 = (string_to_search,string_to_find,string_to_replace_with)->my(s1=Vec(string_to_search),s2=Vec(string_to_find),s3=string_to_replace_with,good);c="";d="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,d=concat(c,s3);print1(d);c="";i=i+#s2))
(19:58) gp > FaR("Hello Alex","Alex","loser!") c="";i=i+#s2))
Hello loser!
(19:58) gp >[/CODE]

FaR = [B]F[/B]ind [B]a[/B]nd [B]R[/B]eplace

science_man_88 2010-09-08 23:11

[CODE](19:58) gp > primorial=["primorial","prime factorial"]
%5 = ["primorial", "prime factorial"]
(20:06) gp > for(x=2,#primorial,FaR("I want the prime factorial",primorial[x],primorial[1])
*** syntax error, unexpected $end, expecting KPARROW or ',' or ')': ...primorial[x],primorial[1])
^-
(20:08) gp > for(x=2,#primorial,FaR("I want the prime factorial",primorial[x],primorial[1]))
I want the primorial[/CODE]

showing a way to extend it I made a primorial Vec, I then can say from 2 to # primorial, call FaR and check for them if they are there replace with the first in the Vec.

science_man_88 2010-09-08 23:22

Give me Vec with technical names and non technical descriptions and maybe I can try for multiple Vec to check through using a matrix etc.

science_man_88 2010-09-08 23:53

10 Aug 10, 08:52 PM is my first post on a scriptwriter (page 7) so under a month and with arguments we've figured it out lol.

mostly*

CRGreathouse 2010-09-09 04:28

[QUOTE=science_man_88;229105]Give me Vec with technical names and non technical descriptions and maybe I can try for multiple Vec to check through using a matrix etc.[/QUOTE]

For what it's worth, here are some recent-ish posts I've made where I've converted a description to Pari code:

[url]http://mymathforum.com/viewtopic.php?f=40&t=14769i[/url]
[code]trinv(n)=(sqrtint(8*n-7)+1)>>1
forprime(p=2,1e9,if(is(p,trinv(p)),print("S_0 = "p", c = "trinv(p))))[/code]

[url]http://mymathforum.com/viewtopic.php?f=40&t=15163&start=15[/url]
[code]Cohn(P,a='x)={
my(d=poldegree(P,a),an=polcoeff(P,d,a),b=0);
for(i=0,d-1,b=max(b,abs(polcoeff(P,i,a))));
b=ceil(b/an)+1;
while(1,
if(isprime(substpol(P,a,b++)),return(b))
)
};
addhelp(Cohn, "Cohn(P): If P is an irreducible polynomial, return a proof certificate p; otherwise, infinite loop. Based on Ram Murty 2002.");[/code]

[url]http://mymathforum.com/viewtopic.php?f=44&t=14683[/url]
[code]for(n=6000,0,if(isprime(n) && 6000%n==0, print(n)))
forstep(n=6000,0,-1,if(isprime(n) && 6000%n==0, print(n)))
for(n=0,6000,if(isprime(n) && 6000%n==0, print(n)))
forprime(p=0,6000,if(6000%p==0, print(p)))
fordiv(6000,n,if(isprime(n), print(n)))
f=factor(6000)[,1]; for(i=1,#f,print(f[i]))[/code]

[url]http://mymathforum.com/viewtopic.php?f=24&t=14446[/url]
[code]step(M)=my(m,MM=matrix(4,4));for(i=1,4,for(j=1,4,m=M[i,j];if(i==4|j==4,MM[i,j]+=m*1087,if(i==3&j==3,MM[i,j]+=425*m,MM[i+1,j+1]+=425*m);MM[i+1,j]+=187*m;MM[i,j+1]+=475*m)));MM
matrix(4,4,x,y,x==1&y==1)
step(%)[/code]

[url]http://mymathforum.com/viewtopic.php?f=40&t=13249[/url]
[code]er(n)=my(s=eval(Vec(Str(8*n))),n=0);for(i=1,#s,if(s[i]&s[i]!=8,n=10*n+s[i]));n
err1(n,verbose=0)=my(nn,orig=n);while(nn!=n,nn=n;if(n=er(n)<orig,return()))
for(n=1,1e8,err1(n))[/code]

[url]http://mymathforum.com/viewtopic.php?f=40&t=12565[/url]
[code]factorPueo(P = 2009)={
my(m=1, k=(sqrtint(1+8*P)-1)>>1, NB=k*(k+1)/2, NA=NB+m+k, i);
\\ m = 1 is a triangle number; solve k*(k1)/2 = P for k
\\ define two numbers, NB = S(m,k) and NA = S(m,k+1), that bracket P

while(NB!=P,
while(NB > P, \\ is NB too large?
NA = NB;
NB -= m + k - 1;
k -= 1
);
while(NA <= P, \\ is NA too small?
NB = NA;
NA += m + k + 1;
k += 1
);
if(NB < P,
NB += k; \\ make NB larger using [6] above to increase m
NA += k + 1; \\ make NA larger using [7] above to increase m
m += 1
)
);

i = k;
if(i%2 == 0, \\ if k is even, divide by 2 to get factor of P
i /= 2
);

j = P/i;
print("S("m","k") = "P);
print(i" * "j" = "i*j);
};[/code]

The difficulties of these underscores the scope of your project...

science_man_88 2010-09-09 11:39

you're over worked and underpaid.

I've got the basics of math English down with this code though I'll make more list.

if you look at it correcting typo is a task it would need to be AI complete.

the more tasks we need it to do and the more Vec we need to do this the more memory intensive it would be.


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

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