mersenneforum.org  

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

Reply
 
Thread Tools
Old 2011-02-05, 02:13   #2135
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

I don't get that, or any, error. (The program doesn't seem to do what you want, but that's another matter,)
CRGreathouse is offline   Reply With Quote
Old 2011-02-05, 12:05   #2136
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
I don't get that, or any, error. (The program doesn't seem to do what you want, but that's another matter,)
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))
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 is offline   Reply With Quote
Old 2011-02-05, 12:09   #2137
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

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

Last fiddled with by science_man_88 on 2011-02-05 at 12:21
science_man_88 is offline   Reply With Quote
Old 2011-02-05, 19:37   #2138
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

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

I always write my functions like
Code:
foo={
  \\ . . .
};
so I know that problem won't happen to me.
CRGreathouse is offline   Reply With Quote
Old 2011-02-05, 19:38   #2139
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Maybe you didn't use braces, so it read each line individually?

I always write my functions like
Code:
foo={
  \\ . . .
};
so I know that problem won't happen to me.
I never knew they were mandatory.
science_man_88 is offline   Reply With Quote
Old 2011-02-05, 22:41   #2140
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I never knew they were mandatory.
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.

Last fiddled with by CRGreathouse on 2011-02-05 at 22:43
CRGreathouse is offline   Reply With Quote
Old 2011-02-05, 23:00   #2141
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
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.
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)); };
Any errors ? if not I may continue and make a union script assuming I remember what a union is.
science_man_88 is offline   Reply With Quote
Old 2011-02-05, 23:34   #2142
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

aredisjoint([1,2,3],[4,5]) returns 0.
CRGreathouse is offline   Reply With Quote
Old 2011-02-05, 23:36   #2143
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
aredisjoint([1,2,3],[4,5]) returns 0.
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)
)};

Last fiddled with by science_man_88 on 2011-02-05 at 23:41
science_man_88 is offline   Reply With Quote
Old 2011-02-06, 00:30   #2144
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
if not I may continue and make a union script assuming I remember what a union is.
I looked over the other thread and I realized it's simple:

Code:
union(A,B)=concat(A,B);vecsort(union,,8)
so simple I messed it up:

Code:
union(A,B)= U=concat(A,B);vecsort(U,,8)

Last fiddled with by science_man_88 on 2011-02-06 at 00:35
science_man_88 is offline   Reply With Quote
Old 2011-02-06, 01:33   #2145
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

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.
science_man_88 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 22:04.


Fri Aug 6 22:04:26 UTC 2021 up 14 days, 16:33, 1 user, load averages: 3.01, 2.83, 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.