Re: PARI/GP vecsort/versearch and Mod()
Bill Allombert <[email protected]> Sat, 15 Nov 2025 17:49:20 +0100
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <aRivECvEtZJSAt4A@seventeen> |
On Sat, Nov 15, 2025 at 05:23:55PM +0100, [email protected] wrote: > How to make this work and get rid of 1st } and 2nd { ? > So all in one outer pair of braces? I suppose you can do that { (assert(b,s="")=if(!(b),error(Str(s)))); F4 = [[Mod(0,2),Mod(0,2); \\ 0 Mod(0,2),Mod(0,2)], [Mod(1,2),Mod(0,2); \\ 1 Mod(0,2),Mod(1,2)], [Mod(0,2),Mod(1,2); \\ a Mod(1,2),Mod(1,2)], [Mod(1,2),Mod(1,2); \\ b Mod(1,2),Mod(0,2)]]; slF4 = vecsort(lift(F4)); (inF4(M)=vecsearch(slF4,lift(M))); foreach(F4,a, foreach(F4,b, assert(inF4(a+b),"add not closed"))); print("{0,1,a,b} is closed under matrix +"); } instead of (inF4(M)=vecsearch(slF4,lift(M))) you can do global(inF4(M)=vecsearch(slF4,lift(M))); local(inF4(M)=vecsearch(slF4,lift(M))); my(inF4(M)=vecsearch(slF4,lift(M))); with different scoping rules. But I would rather do the opposite: assert(b,s="")=if(!(b),error(Str(s))); F4 = { [[Mod(0,2),Mod(0,2); \\ 0 Mod(0,2),Mod(0,2)], [Mod(1,2),Mod(0,2); \\ 1 Mod(0,2),Mod(1,2)], [Mod(0,2),Mod(1,2); \\ a Mod(1,2),Mod(1,2)], [Mod(1,2),Mod(1,2); \\ b Mod(1,2),Mod(0,2)]]; } slF4 = vecsort(lift(F4)); inF4(M)=vecsearch(slF4,lift(M)); { foreach(F4,a, foreach(F4,b, assert(inF4(a+b),"add not closed"))); print("{0,1,a,b} is closed under matrix +"); } Cheers, Bill