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)

CRGreathouse 2011-02-05 02:13

I don't get that, or any, error. (The program doesn't seem to do what you want, but that's another matter,)

science_man_88 2011-02-05 12:05

[QUOTE=CRGreathouse;251356]I don't get that, or any, error. (The program doesn't seem to do what you want, but that's another matter,)[/QUOTE]

[CODE]if(#A!=0&&#B!=0,a=0;for(i=1,#A,for(j=1,#B,if(A[i]==B[j],return(0),a=a+1;if(a==#A*#B,return(1))))),return(0))[/CODE] works perfect when put into PARI as far as I can tell but gives and error when in your form in file.

science_man_88 2011-02-05 12:09

I find something weird if I had it in fancy form I was always "missing something" if not it worked fine.

CRGreathouse 2011-02-05 19:37

Maybe you didn't use braces, so it read each line individually?

I always write my functions like
[code]foo=[COLOR="red"]{[/COLOR]
\\ . . .
[COLOR="Red"]}[/COLOR];[/code]
so I know that problem won't happen to me.

science_man_88 2011-02-05 19:38

[QUOTE=CRGreathouse;251439]Maybe you didn't use braces, so it read each line individually?

I always write my functions like
[code]foo=[COLOR="red"]{[/COLOR]
\\ . . .
[COLOR="Red"]}[/COLOR];[/code]
so I know that problem won't happen to me.[/QUOTE]

I never knew they were mandatory.

CRGreathouse 2011-02-05 22:41

[QUOTE=science_man_88;251440]I never knew they were mandatory.[/QUOTE]

If you don't use them then each line will be interpreted individually. When you type a command and press enter, it does it right away instead of waiting for another line. So you 'knew', really, that it worked that way -- you just never quite associated the two.

But really, do write your functions out in full form. You often seem to get frustrated with others when they don't respond to your posts, but that's one big reason they don't -- it's too hard to figure out what's going on in your scripts. When you make it easy for other people to read they're more likely to read them and hence respond.

science_man_88 2011-02-05 23:00

[QUOTE=CRGreathouse;251454]If you don't use them then each line will be interpreted individually. When you type a command and press enter, it does it right away instead of waiting for another line. So you 'knew', really, that it worked that way -- you just never quite associated the two.

But really, do write your functions out in full form. You often seem to get frustrated with others when they don't respond to your posts, but that's one big reason they don't -- it's too hard to figure out what's going on in your scripts. When you make it easy for other people to read they're more likely to read them and hence respond.[/QUOTE]
okay here's the ones I've got coded for the homework stuff I learned:

[CODE]aredisjoint(A=[],B=[]) ={
a=0;
for(i=1,#A,
for(j=1,#B,
if(A[i]==B[j],
return(0),
a=a+1;
if(a==#A*#B,
return(1),
return(0)
)
)
)
)};
addhelp(aredisjoint,"a function to tell when 2 sets (vectors(which are actually sequences)) are considered disjoint.")
ispd(C) ={
b=0;
for(i=1,#C,
for(j=1,#C,
if(i!=j && aredisjoint(C[i],C[j]),
b=b+1
)
)
);
if(b==#C*#C-#C,
return(1),
return(0)
)
};
addhelp(ispd,"a function to tell when a collection of sets (vectors(which are actually sequences)) is considered pairwise disjoint.")
CPC(C)={
Cp(C[1],C[2]);
A=d;
for(i=3,#C,
Cp(A,C[i]);
A=d
);
printVectorAsSet(A) };
addhelp(CPC,"a function to create the cartesian product of a collection of sets.")
Cp(p,c)={
d=[];
for(i=1,#p,
for(j=1,#c,
x=[p[i],c[j]];
d=concat(d,[x])
)
);
d;};
addhelp(Cp,"a function to create the cartesian product of 2 sets.")
printVectorAsSet(v)={
if(type(v) != "t_VEC",
print1(v)
,
print1("{");
if (#v, printVectorAsSet(v[1]));
for(i=2,#v,
print1(", ");
printVectorAsSet(v[i])
);
print1("}")
)
}
intersection(x,y) ={
C=[];
for(i=1,#x,
for(j=1,#y,
if(x[i]==y[j],
C=concat(C,x[i])
)
)
);
printVectorAsSet(vecsort(C,,8)); };[/CODE]

Any errors ? if not I may continue and make a union script assuming I remember what a union is.

CRGreathouse 2011-02-05 23:34

aredisjoint([1,2,3],[4,5]) returns 0.

science_man_88 2011-02-05 23:36

[QUOTE=CRGreathouse;251457]aredisjoint([1,2,3],[4,5]) returns 0.[/QUOTE]

okay I added a new thing to that and on my end it works it's and if loop checking if #a and #b are = 0 but that shouldn't make a difference in that:

[CODE]aredisjoint(A=[],B=[]) ={
if(#A!=0 && #B!=0,
a=0;
for(i=1,#A,
for(j=1,#B,
if(A[i]==B[j],
return(0),
a=a+1;
if(a==#A*#B,
return(1),
)
)
)
)
,return(0)
)};[/CODE]

science_man_88 2011-02-06 00:30

[QUOTE=science_man_88;251456]if not I may continue and make a union script assuming I remember what a union is.[/QUOTE]

I looked over the other thread and I realized it's simple:

[CODE]union(A,B)=concat(A,B);vecsort(union,,8)[/CODE]

so simple I messed it up:

[CODE]union(A,B)= U=concat(A,B);vecsort(U,,8)[/CODE]

science_man_88 2011-02-06 01:33

Just to update I've changed one thing in Cp and fixed the output for CPC.

hopefully I can program more of this it may become very useful.


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

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