Mercurial > hg > jgplsrc
changeset 0:e0bbaa717f41 draft default tip
lol J
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/a.c @@ -0,0 +1,163 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs */ + +#include "j.h" + + +static DF1(swap1){DECLF; R jt->rank?irs2(w,w,fs,jt->rank[1],jt->rank[1],f2):CALL2(f2,w,w,fs);} +static DF2(swap2){DECLF; R jt->rank?irs2(w,a,fs,jt->rank[1],jt->rank[0],f2):CALL2(f2,w,a,fs);} + +F1(jtswap){A y;C*s;I n; + RZ(w); + if(VERB&AT(w))R ADERIV(CTILDE,swap1,swap2,RMAX,rr(w),lr(w)); + else{ + if(C2T&AT(w))RZ(w=cvt(LIT,w)) else ASSERT(LIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVRANK); + n=AN(w); s=CAV(w); + ASSERT(vnm(n,s),EVILNAME); + RZ(y=nfs(AN(w),CAV(w))); + R nameref(y); +}} + + +static B booltab[64]={ + 0,0,0,0, 0,0,0,1, 0,0,1,0, 0,0,1,1, 0,1,0,0, 0,1,0,1, 0,1,1,0, 0,1,1,1, + 1,0,0,0, 1,0,0,1, 1,0,1,0, 1,0,1,1, 1,1,0,0, 1,1,0,1, 1,1,1,0, 1,1,1,1, +}; + +static DF2(jtbdot2){R from(plus(duble(cvt(B01,a)),cvt(B01,w)),VAV(self)->h);} + +static DF1(jtbdot1){R bdot2(zero,w,self);} + +static DF1(jtbasis1){DECLF;A z;D*x;I j;V*v; + PREF1(jtbasis1); + RZ(w=vi(w)); + switch(*AV(w)){ + case 0: + GA(z,FL,3,1,0); x=DAV(z); v=VAV(fs); + j=v->mr; x[0]=j<=-RMAX?-inf:j>=RMAX?inf:j; + j=v->lr; x[1]=j<=-RMAX?-inf:j>=RMAX?inf:j; + j=v->rr; x[2]=j<=-RMAX?-inf:j>=RMAX?inf:j; + R pcvt(INT,z); + case -1: R lrep(inv (fs)); + case 1: R lrep(iden(fs)); + default: ASSERT(0,EVDOMAIN); +}} + +F1(jtbdot){A b,h=0;I j,n,*v; + RZ(w); + if(VERB&AT(w))R ADERIV(CBDOT, jtbasis1,0L, 0,0,0); + RZ(w=vi(w)); + n=AN(w); v=AV(w); + if(1==n){j=*v; ASSERT(-16<=j&&j<=34,EVINDEX);} + else DO(n, j=*v++; ASSERT(-16<=j&&j<16,EVINDEX);); + if(1!=n||j<16){ + GA(b,B01,64,2,0); *AS(b)=16; *(1+AS(b))=4; MC(AV(b),booltab,64L); + RZ(h=cant2(IX(AR(w)),from(w,b))); + R fdef(CBDOT,VERB, jtbdot1,jtbdot2, w,0L,h, 0L, RMAX,0L,0L); + }else switch(j){ + default: ASSERT(0,EVNONCE); + case 16: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0000, w,0L,0L, VIRS2, 0L,0L,0L); + case 17: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0001, w,0L,0L, VIRS2, 0L,0L,0L); + case 18: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0010, w,0L,0L, VIRS2, 0L,0L,0L); + case 19: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0011, w,0L,0L, VIRS2, 0L,0L,0L); + case 20: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0100, w,0L,0L, VIRS2, 0L,0L,0L); + case 21: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0101, w,0L,0L, VIRS2, 0L,0L,0L); + case 22: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0110, w,0L,0L, VIRS2, 0L,0L,0L); + case 23: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise0111, w,0L,0L, VIRS2, 0L,0L,0L); + case 24: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1000, w,0L,0L, VIRS2, 0L,0L,0L); + case 25: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1001, w,0L,0L, VIRS2, 0L,0L,0L); + case 26: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1010, w,0L,0L, VIRS2, 0L,0L,0L); + case 27: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1011, w,0L,0L, VIRS2, 0L,0L,0L); + case 28: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1100, w,0L,0L, VIRS2, 0L,0L,0L); + case 29: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1101, w,0L,0L, VIRS2, 0L,0L,0L); + case 30: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1110, w,0L,0L, VIRS2, 0L,0L,0L); + case 31: R fdef(CBDOT,VERB, jtbitwise1,jtbitwise1111, w,0L,0L, VIRS2, 0L,0L,0L); + case 32: R ADERIV(CBDOT,jtbitwise1,jtbitwiserotate,0,0,0); + case 33: R ADERIV(CBDOT,jtbitwise1,jtbitwiseshift, 0,0,0); + case 34: R ADERIV(CBDOT,jtbitwise1,jtbitwiseshifta,0,0,0); +}} + + +/* The h parameter in self for u M. */ +/* 3 elememt boxed list */ +/* 0 - integer atom of # of entries in hash table */ +/* 1 - 2-column integer table of arguments */ +/* arguments are machine word integers */ +/* column 1 is right arg; column 1 is left arg */ +/* column 0 is IMIN for monad */ +/* 2 - box list of results corresp. to arguments */ +/* unused entries are set to 0 */ + +#if SY_64 +#define HIC(x,y) ((UI)x+10495464745870458733U*(UI)y) +#else +#define HIC(x,y) ((UI)x+2838338383U*(UI)y) +#endif + +static A jtmemoget(J jt,I x,I y,A self){A h,*hv,q;I*jv,k,m,*v; + h=VAV(self)->h; hv=AAV(h); + q=hv[1]; jv=AV(q); m=*AS(q); + k=HIC(x,y)%m; v=jv+2*k; while(IMIN!=*v&&!(y==*v&&x==v[1])){v+=2; if(v==jv+2*m)v=jv;} + R*(AAV(hv[2])+(v-jv)/2); +} + +static A jtmemoput(J jt,I x,I y,A self,A z){A*cv,h,*hv,q;I c,*jv,k,m,*mv,*v; + RZ(z); + c=AC(self); h=VAV(self)->h; hv=AAV(h); + q=hv[0]; mv= AV(q); + q=hv[1]; jv= AV(q); + q=hv[2]; cv=AAV(q); m=AN(q); + if(m<=2**mv){A cc,*cu=cv,jj;I i,*ju=jv,n=m,*u; + v=ptab; while(m>=*v)++v; m=*v; + RZ(jj=reshape(v2(m,2L),sc(IMIN))); jv= AV(jj); + GA(cc,BOX,m,1,0); cv=AAV(cc); + for(i=0,u=ju;i<n;++i,u+=2)if(IMIN!=*u){ + k=HIC(x,y)%m; v=jv+2*k; while(IMIN!=*v){v+=2; if(v==jv+2*m)v=jv;} + cv[(v-jv)/2]=cu[i]; cu[i]=0; v[0]=u[0]; v[1]=u[1]; + } + q=hv[1]; AC(q)=1; fa(q); AC(jj)+=c; hv[1]=jj; + q=hv[2]; AC(q)=1; fa(q); AC(cc)+=c; hv[2]=cc; + } + ++*mv; + k=HIC(x,y)%m; v=jv+2*k; while(IMIN!=*v){v+=2; if(v==jv+2*m)v=jv;} + cv[(v-jv)/2]=raa(c,z); v[0]=y; v[1]=x; + R z; +} + +static I jtint0(J jt,A w){A x; + if(AR(w))R IMIN; + if(NUMERIC&AT(w))switch(AT(w)){ + case B01: R (I)*BAV(w); + case INT: R *AV(w); + } + x=pcvt(INT,w); + R x&&INT&AT(x)?*AV(x):IMIN; +} + +DF1(jtmemo1){DECLF;A z;I x,y; + RZ(w); + x=IMIN; y=int0(w); + if(y==IMIN)R CALL1(f1,w,fs); + R (z=memoget(x,y,self))?z:memoput(x,y,self,CALL1(f1,w,fs)); +} + +DF2(jtmemo2){DECLF;A z;I x,y; + RZ(a&&w); + x=int0(a); y=int0(w); + if(x==IMIN||y==IMIN)R CALL2(f2,a,w,fs); + R (z=memoget(x,y,self))?z:memoput(x,y,self,CALL2(f2,a,w,fs)); +} + +F1(jtmemo){A h,*hv,q;I m;V*v; + RZ(w); + ASSERT(VERB&AT(w),EVDOMAIN); + v=VAV(w); m=ptab[1]; + GA(h,BOX,3,1,0); hv=AAV(h); + RZ(q=sc(0L)); hv[0]=q; + RZ(q=reshape(v2(m,2L),sc(IMIN))); hv[1]=q; + GA(q,BOX,m,1,0); hv[2]=q; + R fdef(CMCAP,VERB,jtmemo1,jtmemo2,w,0L,h,0L,v->mr,v->lr,v->rr); +}
new file mode 100644 --- /dev/null +++ b/a.h @@ -0,0 +1,48 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Macros and Defined-Constants (for Adverbs and Conjunctions) */ + + +#define GAPPEND (I)0 +#define GINSERT (I)3 +#define GTRAIN (I)6 + +#define COMPOSE(c) ((c)==CAT||(c)==CATCO||(c)==CAMP||(c)==CAMPCO) + +#define CONJCASE(a,w) (2*!(VERB&AT(a))+!(VERB&AT(w))) +#define NN 3 /* NOUN NOUN */ +#define NV 2 /* NOUN VERB */ +#define VN 1 /* VERB NOUN */ +#define VV 0 /* VERB VERB */ + +#define DECLF V*sv=VAV(self);A fs=sv->f; \ + AF f1=fs?VAV(fs)->f1:0,f2=fs?VAV(fs)->f2:0 + +#define DECLG V*sv=VAV(self);A gs=sv->g; \ + AF g1=gs?VAV(gs)->f1:0,g2=gs?VAV(gs)->f2:0 + +#define DECLFG DECLF; A gs=sv->g; \ + AF g1=gs?VAV(gs)->f1:0,g2=gs?VAV(gs)->f2:0 + +#define DECLFGH DECLFG; A hs=sv->h; \ + AF h1=hs?VAV(hs)->f1:0,h2=hs?VAV(hs)->f2:0 + +#define PREF1(f) {I m=mr(self); F1RANK( m,f,self);} +#define PREF2(f) {I l=lr(self),r=rr(self); F2RANK(l,r,f,self);} + +#define AS1(f,exp) DF1(f){PROLOG;DECLF ;A z; PREF1(f); z=(exp); EPILOG(z);} +#define AS2(f,exp) DF2(f){PROLOG;DECLF ;A z; PREF2(f); z=(exp); EPILOG(z);} +#define CS1(f,exp) DF1(f){PROLOG;DECLFG;A z; PREF1(f); z=(exp); EPILOG(z);} +#define CS2(f,exp) DF2(f){PROLOG;DECLFG;A z; PREF2(f); z=(exp); EPILOG(z);} + +#define ADERIV(id,f1,f2,m,l,r) fdef(id,VERB,(AF)(f1),(AF)(f2),w,0L,0L,0L,(I)(m),(I)(l),(I)(r)) +#define CDERIV(id,f1,f2,m,l,r) fdef(id,VERB,(AF)(f1),(AF)(f2),a,w ,0L,0L,(I)(m),(I)(l),(I)(r)) + +#define ASSERTVV(a,w) RZ(a&&w); ASSERT(VERB&AT(a)&&VERB&AT(w),EVDOMAIN) +#define ASSERTVN(a,w) RZ(a&&w); ASSERT(VERB&AT(a)&&NOUN&AT(w),EVDOMAIN) +#define ASSERTNN(a,w) RZ(a&&w); ASSERT(NOUN&AT(a)&&NOUN&AT(w),EVDOMAIN) + +#define SCALARFN(id,w) (id==ID(w)&&!lr(w)&&!rr(w)) + +#define FIT0(c,v) (CFIT==v->id&&c==ID(v->f)&&equ(zero,v->g))
new file mode 100644 --- /dev/null +++ b/ab.c @@ -0,0 +1,182 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: b. bitwise functions */ + +#include "j.h" +#include "ve.h" +#include "ar.h" + + +APFX(bw0000II, UI,UI,UI, BW0000) static APFX(bw0000CC, UC,UC,UC, BW0000) +APFX(bw0001II, UI,UI,UI, BW0001) static APFX(bw0001CC, UC,UC,UC, BW0001) +APFX(bw0010II, UI,UI,UI, BW0010) static APFX(bw0010CC, UC,UC,UC, BW0010) +APFX(bw0011II, UI,UI,UI, BW0011) static APFX(bw0011CC, UC,UC,UC, BW0011) +APFX(bw0100II, UI,UI,UI, BW0100) static APFX(bw0100CC, UC,UC,UC, BW0100) +APFX(bw0101II, UI,UI,UI, BW0101) static APFX(bw0101CC, UC,UC,UC, BW0101) +APFX(bw0110II, UI,UI,UI, BW0110) static APFX(bw0110CC, UC,UC,UC, BW0110) +APFX(bw0111II, UI,UI,UI, BW0111) static APFX(bw0111CC, UC,UC,UC, BW0111) +APFX(bw1000II, UI,UI,UI, BW1000) static APFX(bw1000CC, UC,UC,UC, BW1000) +APFX(bw1001II, UI,UI,UI, BW1001) static APFX(bw1001CC, UC,UC,UC, BW1001) +APFX(bw1010II, UI,UI,UI, BW1010) static APFX(bw1010CC, UC,UC,UC, BW1010) +APFX(bw1011II, UI,UI,UI, BW1011) static APFX(bw1011CC, UC,UC,UC, BW1011) +APFX(bw1100II, UI,UI,UI, BW1100) static APFX(bw1100CC, UC,UC,UC, BW1100) +APFX(bw1101II, UI,UI,UI, BW1101) static APFX(bw1101CC, UC,UC,UC, BW1101) +APFX(bw1110II, UI,UI,UI, BW1110) static APFX(bw1110CC, UC,UC,UC, BW1110) +APFX(bw1111II, UI,UI,UI, BW1111) static APFX(bw1111CC, UC,UC,UC, BW1111) + +/* see below */ /* see below */ +REDUCEPFX(bw0001insI, UI,UI, BW0001) static REDUCEPFX(bw0001insC, UC,UC, BW0001) +REDUCEPFX(bw0010insI, UI,UI, BW0010) static REDUCEPFX(bw0010insC, UC,UC, BW0010) +/* see below */ /* see below */ +REDUCEPFX(bw0100insI, UI,UI, BW0100) static REDUCEPFX(bw0100insC, UC,UC, BW0100) +/* see below */ /* see below */ +REDUCEPFX(bw0110insI, UI,UI, BW0110) static REDUCEPFX(bw0110insC, UC,UC, BW0110) +REDUCEPFX(bw0111insI, UI,UI, BW0111) static REDUCEPFX(bw0111insC, UC,UC, BW0111) +REDUCEPFX(bw1000insI, UI,UI, BW1000) static REDUCEPFX(bw1000insC, UC,UC, BW1000) +REDUCEPFX(bw1001insI, UI,UI, BW1001) static REDUCEPFX(bw1001insC, UC,UC, BW1001) +/* see below */ /* see below */ +REDUCEPFX(bw1011insI, UI,UI, BW1011) static REDUCEPFX(bw1011insC, UC,UC, BW1011) +/* see below */ /* see below */ +REDUCEPFX(bw1101insI, UI,UI, BW1101) static REDUCEPFX(bw1101insC, UC,UC, BW1101) +REDUCEPFX(bw1110insI, UI,UI, BW1110) static REDUCEPFX(bw1110insC, UC,UC, BW1110) +/* see below */ /* see below */ + + AHDRR(bw0000insI,UI,UI){I k=SZI*m*c/n; if(1<n)memset(z,C0 ,k); else MC(z,x,k);} +static AHDRR(bw0000insC,UC,UC){I k= m*c/n; if(1<n)memset(z,C0 ,k); else MC(z,x,k);} + + AHDRR(bw1111insI,UI,UI){I k=SZI*m*c/n; if(1<n)memset(z,CFF,k); else MC(z,x,k);} +static AHDRR(bw1111insC,UC,UC){I k= m*c/n; if(1<n)memset(z,CFF,k); else MC(z,x,k);} + + AHDRR(bw0011insI,UI,UI){I d=c/n,k=c-d; DO(m, DO(d, *z++= *x++;); x+=k;);} +static AHDRR(bw0011insC,UC,UC){I d=c/n,k=c-d; DO(m, DO(d, *z++= *x++;); x+=k;);} + + AHDRR(bw1100insI,UI,UI){I d=c/n,k=c-d; if(1<n)DO(m, DO(d, *z++= ~*x++;); x+=k;) else MC(z,x,SZI*m*c/n);} +static AHDRR(bw1100insC,UC,UC){I d=c/n,k=c-d; if(1<n)DO(m, DO(d, *z++= ~*x++;); x+=k;) else MC(z,x, m*c/n);} + + AHDRR(bw0101insI,UI,UI){I d=c/n,k=c-d; x+=k; DO(m, DO(d, *z++= *x++;); x+=k;);} +static AHDRR(bw0101insC,UC,UC){I d=c/n,k=c-d; x+=k; DO(m, DO(d, *z++= *x++;); x+=k;);} + + AHDRR(bw1010insI,UI,UI){I d=c/n,k=c-d;UI t= n%2-1 ; x+=k; DO(m, DO(d, *z++=t^*x++;); x+=k;);} +static AHDRR(bw1010insC,UC,UC){I d=c/n,k=c-d;UC t=(UC)(n%2-1); x+=k; DO(m, DO(d, *z++=t^*x++;); x+=k;);} + + + +#define BITWISE(f,T,op) \ + F2(f){A z;B b;I an,ar,*as,*av,k=0,wn,wr,*ws,x;T*wv,y,*zv; \ + RZ(a&&w); \ + if(!(INT&AT(a)))RZ(a=cvt(INT,a)); \ + if(!(INT&AT(w)))RZ(w=cvt(INT,w)); \ + an=AN(a); ar=AR(a); as=AS(a); av=(I*)AV(a); \ + wn=AN(w); wr=AR(w); ws=AS(w); wv=(T*)AV(w); b=ar>wr; \ + DO(MIN(ar,wr), ASSERT(as[i]==ws[i],EVLENGTH);); \ + GA(z,INT,b?an:wn,MAX(ar,wr),b?as:ws); zv=(T*)AV(z); \ + if(!AN(z))R z; \ + if (ar==wr)DO(an, x=*av++; y=*wv++; *zv++=op(x,y); ) \ + else if(ar< wr)DO(an, x=*av++; DO(wn/an, y=*wv++; *zv++=op(x,y););) \ + else DO(wn, y=*wv++; DO(an/wn, x=*av++; *zv++=op(x,y););); \ + RE(0); R z; \ + } + +#if SY_64 +#define WLEN 64 +#else +#define WLEN 32 +#endif + +#define BWROT(x,y) (0>x ? (y>>(-x%WLEN))|(y<<(WLEN+(x%WLEN))) : (y<<(x%WLEN))|(y>>(WLEN-(x%WLEN))) ) +#define BWSHIFT(x,y) (0>x ? (x<=-WLEN?0:y>>-x) : (x>=WLEN?0:y<<x) ) +#define BWSHIFTA(x,y) (0>x ? (x<=-WLEN?(y<0?-1:0):y>>-x) : (x>=WLEN?0:y<<x) ) + +BITWISE(jtbitwiserotate,UI,BWROT ) +BITWISE(jtbitwiseshift, UI,BWSHIFT ) +BITWISE(jtbitwiseshifta,I, BWSHIFTA) + +DF1(jtbitwise1){R CALL2(VAV(self)->f2,zero,w,self);} + + +static VF bwC[16]={bw0000CC,bw0001CC,bw0010CC,bw0011CC, bw0100CC,bw0101CC,bw0110CC,bw0111CC, + bw1000CC,bw1001CC,bw1010CC,bw1011CC, bw1100CC,bw1101CC,bw1110CC,bw1111CC}; + +static VF bwI[16]={bw0000II,bw0001II,bw0010II,bw0011II, bw0100II,bw0101II,bw0110II,bw0111II, + bw1000II,bw1001II,bw1010II,bw1011II, bw1100II,bw1101II,bw1110II,bw1111II}; + +/* a m b.&.(a.&i.) w */ +/* a m b.&.(a.i.]) w */ +/* m e. 16+i.16 */ + +DF2(jtbitwisechar){DECLFG;A*p,x,y,z;B b;I an,ar,*as,at,d,j,m,n,wn,wr,*ws,wt,zn;VF f; + RZ(a&&w); + d=SZI; + x=a; an=AN(a); ar=AR(a); as=AS(a); at=AT(a); + y=w; wn=AN(w); wr=AR(w); ws=AS(w); wt=AT(a); + if(!(an&&wn&&at&LIT&&wt&LIT))R from(df2(indexof(alp,a),indexof(alp,w),fs),alp); + b=ar<=wr; zn=b?wn:an; m=b?an:wn; n=zn/m; + ASSERT(!ICMP(as,ws,MIN(ar,wr)),EVLENGTH); + j=i0(VAV(fs)->f)-16; + GA(z,d==SZI?LIT:C2T,zn,MAX(ar,wr),b?ws:as); + if(1==n) {f=bwI[j]; m=(m+d-1)/d;} + else if(!ar||!wr||0==n%d){f=bwI[j]; n=(n+d-1)/d; p=b?&x:&y; RZ(*p=irs2(sc(d),*p,0L,0L,0L,jtrepeat));} + else f=bwC[j]; + f(jt,b,m,n,AV(z),AV(x),AV(y)); + *(zn+CAV(z))=0; + R z; +} + +/* compute z=: t{~ a.i.w if t=: c&(m b.) a. */ +/* http://www.jsoftware.com/jwiki/Essays/Bitwise_Functions_on_Charcters */ + +B jtbitwisecharamp(J jt,UC*t,I n,UC*wv,UC*zv){I p;UC c,i,j,*pv,s[256];VF f; + i=t[0]; j=t[255]; + if (i==0 ){c=j; f=bw0001II;} + else if(j==i ){c=i; f=bw0011II;} + else if(j==255 ){c=i; f=bw0111II;} + else if(j==255-i){c=i; f=bw0110II;} + else if(j==0 ){c=i; f=bw0010II;} + else if(i==255 ){c=j; f=bw1011II;} + else R 0; + pv=(UC*)&p; DO(SZI, pv[i]=c;); + f(jt,1,1L,256L/SZI,s,pv,AV(alp)); if(memcmp(s,t,256L))R 0; + f(jt,1,1L,(n+SZI-1)/SZI,zv,pv,wv); zv[n]=0; + R 1; +} + + +static VF bwinsC[16]={bw0000insC,bw0001insC,bw0010insC,bw0011insC, bw0100insC,bw0101insC,bw0110insC,bw0111insC, + bw1000insC,bw1001insC,bw1010insC,bw1011insC, bw1100insC,bw1101insC,bw1110insC,bw1111insC}; + +static VF bwinsI[16]={bw0000insI,bw0001insI,bw0010insI,bw0011insI, bw0100insI,bw0101insI,bw0110insI,bw0111insI, + bw1000insI,bw1001insI,bw1010insI,bw1011insI, bw1100insI,bw1101insI,bw1110insI,bw1111insI}; + +/* m b./&.(a.&i.) w */ +/* m b./&.(a.i.]) w */ +/* m e. 16+i.16 */ + +DF1(jtbitwiseinsertchar){A fs,z;I c,d=SZI,j,m,n,r,wn,wr;UC*u,*v,*wv,x,*zv;VF f; + RZ(w&&self); + wr=AR(w); c=wn=AN(w); n=wr?*AS(w):1; z=VAV(self)->f; fs=VAV(z)->f; + if(!(wn&&d<n&&LIT&AT(w)))R from(df1(indexof(alp,w),fs),alp); + m=wn/n; wv=CAV(w); j=i0(VAV(fs)->f)-16; f=bwinsC[j]; + if(1==wr)switch(j){ + case 0: R scc(0); + case 3: R scc(*wv); + case 5: R scc(*(wv+wn-1)); + case 10: x=*(wv+wn-1); R scc((UC)(wn%2?x:~x)); + case 12: R scc((UC)~*wv); + case 15: R scc((UC)255); + case 1: case 6: case 7: case 9: f=bwinsI[j]; c=n=n/d; + }else if(0==m%d){f=bwinsI[j]; c/=d;} + GA(z,LIT,m,wr-1,1+AS(w)); zv=CAV(z); + f(jt,1L,c,n,zv,wv); + if(1==wr){ + r=wn-n*d; u=wv+n*d; x=*zv; v=1+zv; + switch(j){ + case 1: DO(d-1, x=BW0001(x,*v); ++v;); DO(r, x=BW0001(x,*u); ++u;); break; + case 6: DO(d-1, x=BW0110(x,*v); ++v;); DO(r, x=BW0110(x,*u); ++u;); break; + case 7: DO(d-1, x=BW0111(x,*v); ++v;); DO(r, x=BW0111(x,*u); ++u;); break; + case 9: DO(d-1, x=BW1001(x,*v); ++v;); DO(r, x=BW1001(x,*u); ++u;); break; + } + *(I*)zv=0; *zv=x; + } + R z; +}
new file mode 100644 --- /dev/null +++ b/af.c @@ -0,0 +1,99 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Fix */ + +#include "j.h" + + +F1(jtunname){A x;V*v; + RZ(w); + v=VAV(w); + if(CTILDE==v->id&&!jt->glock&&!(VLOCK&v->flag)){x=v->f; if(NAME&AT(x))R symbrd(x);} + R w; +} + +static B jtselfq(J jt,A w){A hs,*u;V*v; + RZ(w); + if(AT(w)&NOUN+NAME)R 0; + v=VAV(w); + switch(v->id){ + case CSELF: + R 1; + case CATDOT: + case CGRCO: + if(hs=v->h){u=AAV(hs); DO(AN(hs), if(selfq(u[i]))R 1;);} + R 0; + default: + if(v->f&&selfq(v->f))R 1; + if(v->g&&selfq(v->g))R 1; + if(v->h&&selfq(v->h))R 1; + } + R 0; +} /* 1 iff w contains $: */ + +static F2(jtfixa){A aa,f,g,h,wf,x,y,z=w;V*v; + RZ(a&&w); + if(NOUN&AT(w)||VFIX&VAV(w)->flag)R w; + v=VAV(w); f=v->f; g=v->g; h=v->h; wf=ds(v->id); aa=a==zero?num[3]:a; + if(!(f||g))R w; + switch(v->id){ + case CSLASH: + R df1(fixa(num[2],f),wf); + case CSLDOT: case CBSLASH: case CBSDOT: + R df1(fixa(one,f),wf); + case CAT: case CATCO: case CCUT: + R df2(fixa(one,f),fixa(aa,g),wf); + case CAMP: case CAMPCO: case CUNDER: case CUNDCO: + R df2(fixa(aa,f),fixa(one,g),wf); + case CCOLON: + R df2(fixa(one,f),fixa(num[2],g),wf); + case CADVF: + R hook(fixa(num[3],f),fixa(num[3],g)); + case CHOOK: + R hook(fixa(num[2],f),fixa(one,g)); + case CFORK: + f=fixa(aa,f); g=fixa(num[ID(f)==CCAP?1:2],g); h=fixa(aa,h); R folk(f,g,h); + case CATDOT: + case CGRCO: + RZ(f=every(every2(aa,h,0L,jtfixa),0L,jtaro)); + RZ(g=fixa(aa,g)); + R df2(f,g,wf); + case CIBEAM: + if(f)RZ(f=fixa(aa,f)); + if(g)RZ(g=fixa(aa,g)); + R f&&g ? (VDDOP&v->flag?df2(f,g,df2(head(h),tail(h),wf)):df2(f,g,wf)) : + (VDDOP&v->flag?df1(f, df2(head(h),tail(h),wf)):df1(f, wf)) ; + case CTILDE: + if(f&&NAME&AT(f)){ + RZ(y=sfn(0,f)); + if(all1(eps(box(y),jt->fxpath)))R w; + ASSERT(jt->fxi,EVLIMIT); + jt->fxpv[--jt->fxi]=y; + if(x=symbrdlock(f)){ + RZ(z=fixa(aa,x)); + if(a!=zero&&selfq(x))RZ(z=fixrecursive(a,z)); + } + jt->fxpv[jt->fxi++]=mtv; + RE(z); + ASSERT(AT(w)==AT(z)||AT(w)&NOUN&&AT(z)&NOUN,EVDOMAIN); + R z; + }else R df1(fixa(num[2],f),wf); + default: + if(f)RZ(f=fixa(aa,f)); + if(g)RZ(g=fixa(aa,g)); + R f&&g?df2(f,g,wf):f?df1(f,wf):w; +}} /* 0=a if fix names; 1=a if fix names only if does not contain $: */ + + +F1(jtfix){PROLOG;A z;I*rv=jt->rank; + RZ(w); + jt->rank=0; + RZ(jt->fxpath=reshape(sc(jt->fxi=(I)255),ace)); jt->fxpv=AAV(jt->fxpath); + if(LIT&AT(w)){ASSERT(1>=AR(w),EVRANK); RZ(w=nfs(AN(w),CAV(w)));} + ASSERT(AT(w)&NAME+VERB,EVDOMAIN); + RZ(z=fixa(zero,AT(w)&VERB?w:symbrdlock(w))); + if(AT(z)&VERB+ADV+CONJ){V*v=VAV(z); if(v->f){v->flag|=VFIX+VNAMED; v->flag^=VNAMED;}} + jt->rank=rv; jt->fxpath=0; + EPILOG(z); +}
new file mode 100644 --- /dev/null +++ b/ai.c @@ -0,0 +1,381 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Inverse & Identity Functions */ + +#include "j.h" + + +static F1(jtinvamp); + +static B ip(A w,C c,C d){A f,g;V*v; + v=VAV(w); f=v->f; g=v->g; + R CSLASH==ID(f)&&c==ID(VAV(f)->f)&&d==ID(g); +} + +static B consf(A w){A f;C c; + c=ID(w); + if(c==CFCONS||c==CQQ&&(f=VAV(w)->f,NOUN&AT(f)))R 1; + R 0; +} /* 1 iff w is a constant function */ + +static F2(jtfong){A f;C c;V*v; + RZ(a&&w); + v=VAV(a); c=v->id; f=v->f; + R c==CRIGHT ? w : c==CFORK&&(NOUN&AT(f)||CCAP==ID(f)) ? folk(f,v->g,fong(v->h,w)) : folk(ds(CCAP),a,w); +} /* [: f g with simplifications */ + +static F1(jtinvfork){A f,fi,g,gi,h,k;B b,c;V*v; + RZ(w); + v=VAV(w); RZ(f=unname(v->f)); g=v->g; RZ(h=unname(v->h)); + if(CCAP==ID(f))R fong(inv(h),inv(g)); + c=1&&NOUN&AT(f); b=c||consf(f); + ASSERT(b!=consf(h),EVDOMAIN); + RZ(k=c?f:df1(zero,b?f:h)); + RZ(gi=inv(b?amp(k,g):amp(g,k))); + RZ(fi=inv(b?h:f)); + if(CAMP==ID(gi)){ + v=VAV(gi); + if (NOUN&AT(v->f))RZ(gi=folk(v->f, v->g, ds(CRIGHT))) + else if(NOUN&AT(v->g))RZ(gi=folk(v->g,swap(v->f),ds(CRIGHT))); + } + R fong(fi,gi); +} + +static DF1(jtexpandf){A f; RZ(w&&self); f=VAV(self)->f; R expand(VAV(f)->f,w);} + +static DF1(jtexpandg){A f,g,z;V*v; + RZ(w&&self); + f=VAV(self)->f; v=VAV(f); g=v->g; + jt->fill=VAV(g)->g; z=expand(v->f,w); jt->fill=0; + R z; +} + +static F2(jtdiag){I d,k,m,p,r,t,*v; + RZ(a&&w); + r=AR(w); t=AT(w); k=bp(t); + v=AS(w); m=0; DO(r, m=MIN(m,v[i]);); + v=AS(w)+r; p=1; d=0; DO(r, d+=p; p*=*--v;); + if(t!=AT(a))RZ(a=cvt(t,a)); + if(AR(a)){ + ASSERT(m==AN(a),EVLENGTH); + ASSERT(0,EVNONCE); + }else{ + ASSERT(0,EVNONCE); +}} + +static F1(jtbminv){A*wv,x,z=w;I i,j,m,r,*s,t=0,*u,**v,*y,wn,wr,*ws,wd; + RZ(w); + ASSERT(0,EVNONCE); + ASSERT(BOX&AT(w),EVDOMAIN); + wn=AN(w); wr=AR(w); ws=AS(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + if(1>=wr)R raze(w); + if(!wn)R iota(reshape(sc(wr),zero)); + GA(x,INT,wr,1,0); u=AV(x); memset(u,C0,wr*SZI); + GA(x,INT,wr,1,0); v=(I**)AV(x); + DO(wr, m=ws[i]; GA(x,INT,m,1,0); memset(v[i]=AV(x),CFF,m*SZI);); + for(i=0;i<wn;++i){ + x=WVR(i); r=AR(x); s=AS(x); + if(AN(x)){if(!t)t=AT(x); ASSERT(HOMO(t,AT(x)),EVDOMAIN);} + ASSERT(2>r||r==wr,EVRANK); + if(2>r)z=0; + else DO(wr, y=v[i]+u[i]; if(0>*y)*y=s[i]; else ASSERT(*y==s[i],EVLENGTH);); + j=wr; while(1){--j; ++u[j]; if(ws[j]>u[j])break; u[j]=0;} + } + if(!z){A f,h,*zv;I*hv; + GA(z,BOX,wn,2,ws); zv=AAV(z); + GA(h,INT,wr,1,0); hv=AV(h); + GA(f,t,1,1,0); RZ(f=filler(f)); memset(u,C0,wr*SZI); + for(i=0;i<wn;++i){ + zv[i]=x=WVR(i); + if(2>AR(x)){DO(wr, hv[i]=*(v[i]+u[i]);); RZ(zv[i]=diag(x,reshape(h,f)));} + j=wr-1; while(1){--j; ++u[j]; if(ws[j]>u[j])break; u[j]=0;} + }} + DO(wr, RZ(z=df1(z,slash(under(qq(ds(CCOMMA),sc(wr-i)),ds(COPE)))));); + R ope(z); +} /* <;.1 or <;.2 inverse on matrix argument */ + + +static F1(jtinvamp){A f,ff,g,h,*q,x,y;B nf,ng;C c,d,*yv;I n;V*u,*v; + RZ(w); + v=VAV(w); + f=v->f; nf=!!(NOUN&AT(f)); + g=v->g; ng=!!(NOUN&AT(g)); + h=nf?g:f; x=nf?f:g; c=ID(h); u=VAV(h); + switch(c){ + case CPLUS: R amp(negate(x),h); + case CSTAR: R amp(recip(x), h); + case CMINUS: R nf?w:amp(x,ds(CPLUS)); + case CDIV: R nf?w:amp(x,ds(CSTAR)); + case CROOT: R amp(ds(nf?CEXP:CLOG),x); + case CEXP: R ng&&equ(x,num[2])?ds(CROOT):amp(x,ds(nf?CLOG:CROOT)); + case CLOG: R nf?amp(x,ds(CEXP)):amp(ds(CROOT),x); + case CJDOT: R nf?atop(inv(ds(CJDOT)),amp(ds(CMINUS),x)):amp(ds(CMINUS),jdot1(x)); + case CRDOT: R nf?atop(inv(ds(CRDOT)),amp(ds(CDIV ),x)):amp(ds(CDIV ),rdot1(x)); + case CLBRACE: R nf?amp(pinv(x),h):amp(x,ds(CIOTA)); + case COBVERSE: ff=VAV(h)->g; R amp(nf?x:ff,nf?ff:x); + case CPDERIV: if(!AR(h))R ds(CPDERIV); + case CXCO: RE(n=i0(x)); ASSERT(n&&-3<n&&n<3,EVDOMAIN); + case CROT: + case CCIRCLE: + case CSPARSE: if(nf)R amp(negate(x),h); break; + case CABASE: if(nf)R amp(x,ds(CBASE)); break; + case CIOTA: if(nf)R amp(ds(CLBRACE),x); break; + case CTHORN: if(nf)R ds(CEXEC); break; + case CTILDE: + if(ff=VAV(h)->f,VERB&AT(ff))R invamp(amp(nf?ff:x,nf?x:ff)); + else{ff=unname(h); R invamp(amp(nf?x:ff,nf?ff:x));} + case CSCO: + ASSERT(nf,EVDOMAIN); + RE(n=i0(x)); ASSERT(n&&-6<=n&&n<=6,EVDOMAIN); + R amp(sc(-n),h); + case CUCO: + ASSERT(nf,EVDOMAIN); + RE(n=i0(x)); ASSERT(1<=n&&n<=4||7<=n&&n<=8,EVDOMAIN); + R amp(sc(1==n?2L:2==n?1L:3==n?4L:4==n?3L:7==n?8L:7L),h); + case CCANT: + ASSERT(nf,EVDOMAIN); + R obverse(eva(x,"] |:~ x C.^:_1 i.@#@$"),w); + case CPCO: + if(nf){ + RE(n=i0(x)); + switch(n){ + case -4: case 4: R amp(negate(x),h); + case -1: R ds(CPCO); + case 2: R obverse(eval("*/@(^/)\"2"),w); + case 3: R eval("*/"); + }} + break; + case CQCO: + if(nf){ + ASSERT(!AR(x),EVRANK); + R obverse(eval(all1(lt(x,zero))?"*/@(^/)\"2":"(p:@i.@# */ .^ ])\"1"),w); + } + break; + case CFIT: + ASSERT(nf&&(CPOUND==ID(VAV(g)->f)),EVDOMAIN); + ASSERT(1==AR(x),EVRANK); + R fdef(CPOWOP,VERB, jtexpandg,0L, w,num[-1],0L, 0L, RMAX,0L,0L); + case CPOUND: + ASSERT(nf,EVDOMAIN); + ASSERT(1==AR(x),EVRANK); + R fdef(CPOWOP,VERB, jtexpandf,0L, w,num[-1],0L, 0L, RMAX,0L,0L); + break; + case CPOWOP: + if(VGERL&u->flag){ff=*(1+AAV(u->h)); R amp(nf?x:ff,nf?ff:x);} + break; + case CCOMMA: + n=IC(x); + R obverse(1==n?ds(nf?CDROP:CCTAIL):amp(sc(nf?n:-n),ds(CDROP)),w); + case CBASE: + if(!nf)break; + R AR(x) ? amp(x,ds(CABASE)) : + obverse(evc(x,mag(x),"$&x@>:@(y&(<.@^.))@(1&>.)@(>./)@:|@, #: ]"),w); + case CBANG: + ASSERT(!AR(x),EVRANK); + ASSERT(all1(lt(zero,x)),EVDOMAIN); + GA(y,BOX,9,1,0); q=AAV(y); + q[0]=cstr("3 :'(-("); q[1]=q[3]=lrep(w); + q[2]=cstr("-y\"_)%1e_3&* "); q[4]=cstr("\"0 D:1 ])^:_["); + h=lrep(x); + if(nf){q[5]=over(over(h,cstr("&<@|@{:}")),over(h,cstr(",:"))); q[6]=over(h,cstr("%:y*!")); q[7]=h;} + else {q[5]=cstr("1>.{.@/:\"1|y-/(i.!])"); q[6]=h; q[7]=mtv;} + RE(q[8]=cstr("'")); RZ(y=raze(y)); + R obverse(eval(CAV(y)),w); + case CATOMIC: + if(ng){ASSERT(equ(x,nub(x)),EVDOMAIN); R obverse(atop(f,amp(x,ds(CIOTA))),w);} + case CCYCLE: + if(nf&&AR(x)<=(c==CCYCLE))R obverse(eva(w,"/:@x@(i.@#) { ]"),w); break; + case CDROP: + if(!(nf&&1>=AR(x)))break; + RZ(x=cvt(INT,x)); + RZ(y=eps(v2(-1L,1L),signum(x))); yv=CAV(y); + f=amp(mag(x),ds(CPLUS)); + g=1==AN(x)?ds(CPOUND):atop(amp(tally(x),ds(CTAKE)),ds(CDOLLAR)); + h=!yv[1]?f:atop(!yv[0]?ds(CMINUS):amp(negate(signum(x)),ds(CSTAR)),f); + R obverse(hook(swap(ds(CTAKE)),atop(h,g)),w); + case CDOMINO: + if(!(2==AR(x)&&*AS(x)==*(1+AS(x))))break; + ff=eval("+/ .*"); + R nf?atop(h,amp(ff,minv(x))):amp(x,ff); + case CDOT: + if(ip(h,CPLUS,CSTAR)){ + ASSERT(2==AR(x),EVRANK); + ASSERT(*AS(x)==*(1+AS(x)),EVLENGTH); + R nf?amp(ds(CDOMINO),x):amp(h,minv(x)); + } + break; + case CQQ: + if(ng&&equ(x,one)&&equ(f,eval("i.\"1")))R hook(ds(CFROM),ds(CEQ)); + break; + case CBSLASH: + if(nf&&(n=i0(x),0>n)&&(d=ID(u->f),d==CLEFT||d==CRIGHT))R slash(ds(CCOMMA)); + break; + case CIBEAM: + x=VAV(h)->f; y=VAV(h)->g; + if(NOUN&AT(x)&&equ(x,num[3])&&NOUN&AT(y)){ + RE(n=i0(f)); + if(all1(eps(y,v2(4L,5L)))){ASSERT(n&&-2<=n&&n<=2,EVDOMAIN); R amp(sc(-n),g);} + if(all1(eps(y,v2(1L,3L)))){ASSERT(0==n||1==n||10==n||11==n,EVDOMAIN); R foreign(x,num[2]);} + } + break; + case CBDOT: + RE(n=i0(x)); + switch(i0(VAV(h)->f)){ + case 22: case 25: R w; + case 19: case 28: if(ng)R w; break; + case 21: case 26: if(nf)R w; break; + case 32: case 33: case 34: ASSERT(nf,EVDOMAIN); R amp(negate(x),h); + } + break; + case CPOLY: + if(nf&&1==AR(x)&&2==AN(x)&&NUMERIC&AT(x)&&!equ(zero,tail(x))){ + RZ(y=recip(tail(x))); + R amp(over(tymes(y,negate(head(x))),y),h); + }} + ASSERT(0,EVDOMAIN); +} + +static C invf[2][29] = { + CDIV, CPLUS, CMINUS, CLEFT, CRIGHT, CREV, CCANT, CPOLY, + CNOT, CGRADE, CCYCLE, CDOMINO, COPE, CBOX, CLOG, CEXP, + CGE, CLE, CHALVE, CPLUSCO, CSQRT, CSTARCO, CHEAD, CLAMIN, + CABASE, CBASE, CTHORN, CEXEC, 0, + CDIV, CPLUS, CMINUS, CLEFT, CRIGHT, CREV, CCANT, CPOLY, + CNOT, CGRADE, CCYCLE, CDOMINO, CBOX, COPE, CEXP, CLOG, + CLE, CGE, CPLUSCO, CHALVE, CSTARCO, CSQRT, CLAMIN, CHEAD, + CBASE, CABASE, CEXEC, CTHORN, 0 +}; + +F1(jtinv){A f,ff,g;B b,nf,ng,vf,vg;C id,*s;I p,q;V*v; + RZ(w); + ASSERT(VERB&AT(w),EVDOMAIN); + id=ID(w); v=VAV(w); + if(s=strchr(invf[0],id))R ds(invf[1][s-invf[0]]); + f=v->f; nf=f&&AT(f)&NOUN+NAME; vf=f&&!nf; + g=v->g; ng=g&&AT(g)&NOUN+NAME; vg=g&&!ng; + switch(id){ + case CCIRCLE: R eval("1p_1&*"); + case CJDOT: R eval("0j_1&*"); + case CRDOT: R eval("%&0j1@^."); + case CPLUSDOT: R eval("j./\"1\"_ :. +."); + case CSTARDOT: R eval("r./\"1\"_ :. *."); + case CDGRADE: R eval("/:@|."); + case CWORDS: R eval("}:@;@(,&' '&.>\"1) :. ;:"); + case CBANG: R eval("3 :'(-(!-y\"_)%1e_3&* !\"0 D:1 ])^:_ <.&170^:(-:+)^.y' :. !"); + case CXCO: R amp(num[-1],w); + case CSPARSE: R fdef(CPOWOP,VERB,jtdenseit,0L, w,num[-1],0L, 0L, RMAX,RMAX,RMAX); + case CPCO: R fdef(CPOWOP,VERB,jtplt, 0L, w,num[-1],0L, 0L, 0L, 0L, 0L ); + case CQCO: R eval("*/"); + case CUCO: R amp(num[3],w); + case CUNDER: R under(inv(f),g); + case CFORK: R invfork(w); + case CAMP: if(nf!=ng)R invamp(w); /* fall thru */ + case CAT: if(vf&&vg)R atop(inv(g),inv(f)); break; + case CAMPCO: + case CATCO: if(vf&&vg)R atco(inv(g),inv(f)); break; + case CSLASH: if(CSTAR==ID(f))R ds(CQCO); break; + case CQQ: if(vf)R qq(inv(f),g); break; + case COBVERSE: if(vf&&vg)R obverse(g,f); break; + case CSCO: R amp(num[5],w); + case CPOWOP: + if(vf&&ng){RE(p=i0(g)); R -1==p?f:1==p?inv(f):powop(0>p?f:inv(f),sc(ABS(p)));} + if(VGERL&v->flag)R*(1+AAV(v->h)); + break; + case CTILDE: + if(nf)R inv(symbrd(f)); + switch(ID(f)){ + case CPLUS: R ds(CHALVE); + case CSTAR: R ds(CSQRT); + case CJDOT: R eval("0.5j_0.5&*"); + case CLAMIN: R eval("{. :. (,:~)"); + case CSEMICO:R eval(">@{. :. (;~)"); + case CCOMMA: R eval("<.@-:@# {. ] :. (,~)"); + case CEXP: R eval("3 : '(- -&b@(*^.) % >:@^.)^:_ ]1>.b=.^.y' \" 0 :. (^~)"); + } + break; + case CBSLASH: + case CBSDOT: + if(CSLASH==ID(f)&&(ff=VAV(f)->f,ff&&VERB&AT(ff))){ + b=id==CBSDOT; + switch(ID(ff)){ + case CPLUS: R obverse(eval(b?"- 1&(|.!.0)":" - |.!.0"),w); + case CSTAR: R obverse(eval(b?"% 1&(|.!.1)":" % |.!.1"),w); + case CEQ: R obverse(eval(b?"= 1&(|.!.1)":" = |.!.1"),w); + case CNE: R obverse(eval(b?"~:1&(|.!.0)":" ~:|.!.0"),w); + case CMINUS:R obverse(eval(b?"+ 1&(|.!.0)":"(- |.!.0) *\"_1 $&1 _1@#"),w); + case CDIV: R obverse(eval(b?"* 1&(|.!.1)":"(% |.!.1) ^\"_1 $&1 _1@#"),w); + }} + break; + case CCUT: + if(CBOX==ID(f)&&ng&&(p=i0(g),1==p||2==p))R fdef(CPOWOP,VERB, jtbminv,0L, w,num[-1], 0L,0L, RMAX,RMAX,RMAX); + break; + case CIBEAM: + p=i0(f); q=i0(g); + if(3==p&&1==q)R foreign(f,num[2]); + if(3==p&&2==q)R foreign(f,one ); + if(3==p&&3==q)R foreign(f,num[2]); + break; + case CHOOK: + if(CFROM==ID(f)&&CEQ==ID(g))R eval("i.\"1&1"); + break; + } + if(!nameless(w))R inv(fix(w)); + ASSERT(0,EVDOMAIN); +} + +static F1(jtneutral){A x,y;B b;V*v; + RZ(w); + v=VAV(w); + ASSERT(!v->lr&&!v->rr,EVDOMAIN); + RZ(y=v2(0L,1L)); + RZ(x=scf(infm)); b=equ(y,CALL2(v->f2,x,y,w)); RESETERR; if(b)R x; + x=ainf; b=equ(y,CALL2(v->f2,x,y,w)); RESETERR; if(b)R x; + x=zero; b=equ(y,CALL2(v->f2,x,y,w)); RESETERR; if(b)R x; + x=one; b=equ(y,CALL2(v->f2,x,y,w)); RESETERR; if(b)R x; + RZ(x=scf(infm)); b=equ(y,CALL2(v->f2,y,x,w)); RESETERR; if(b)R x; + x=ainf; b=equ(y,CALL2(v->f2,y,x,w)); RESETERR; if(b)R x; + x=zero; b=equ(y,CALL2(v->f2,y,x,w)); RESETERR; if(b)R x; + x=one; b=equ(y,CALL2(v->f2,y,x,w)); RESETERR; if(b)R x; + ASSERT(0,EVDOMAIN); +} /* neutral of arbitrary rank-0 function */ + +F1(jtiden){A f,g,x=0;V*u,*v; + RZ(w=fix(w)); ASSERT(VERB&AT(w),EVDOMAIN); + v=VAV(w); f=v->f; g=v->g; + switch(v->id){ + default: RZ(x=neutral(w)); break; + case CCOMMA: R eval("i.@(0&,)@(2&}.)@$"); + case CDOT: if(!(ip(w,CPLUS,CSTAR)||ip(w,CPLUSDOT,CSTARDOT)||ip(w,CNE,CSTARDOT)))break; + case CDOMINO: R atop(atop(ds(CEQ),ds(CGRADE)),ds(CHEAD)); + case CCYCLE: + case CLBRACE: R atop(ds(CGRADE),ds(CHEAD)); + case CSLASH: if(VERB&AT(f))R atop(iden(f),ds(CPOUND)); break; + case CPLUS: case CMINUS: case CSTILE: case CNE: + case CGT: case CLT: case CPLUSDOT: case CJDOT: case CRDOT: + x=zero; break; + case CSTAR: case CDIV: case CEXP: case CROOT: case CBANG: + case CEQ: case CGE: case CLE: case CSTARDOT: + x=one; break; + case CMAX: x=scf(infm); break; + case CMIN: x=ainf; break; + case CUNDER: x=df1(df1(mtv,iden(f)),inv(g)); break; + case CAT: + if(CAMP==ID(f)&&(u=VAV(f),NOUN&AT(u->f)&&!AR(u->f)&&CSTILE==ID(u->g)))switch(ID(g)){ + case CSTAR: case CEXP: x=one; break; + case CPLUS: x=zero; + } + break; + case CBDOT: + switch(i0(f)){ + case 25: x=num[-1]; break; + case 2: case 4: case 5: case 6: case 7: + case 18: case 20: case 21: case 22: case 23: + x=zero; break; + case 1: case 9: case 11: case 13: case 17: + case 27: case 29: + x=one; + }} + ASSERT(x,EVDOMAIN); + R folk(x,swap(ds(CDOLLAR)),atop(ds(CBEHEAD),ds(CDOLLAR))); +}
new file mode 100644 --- /dev/null +++ b/am.c @@ -0,0 +1,217 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Amend */ + +#include "j.h" + + +/* +static A jtmerge1(J jt,A w,A ind){PROLOG;A z;C*v,*x;I c,k,r,*s,t,*u; + RZ(w&&ind); + RZ(ind=pind(IC(w),ind)); + r=MAX(0,AR(w)-1); s=1+AS(w); t=AT(w); c=aii(w); + ASSERT(!(t&SPARSE),EVNONCE); + ASSERT(r==AR(ind),EVRANK); + ASSERT(!ICMP(s,AS(ind),r),EVLENGTH); + GA(z,t,c,r,s); x=CAV(z); v=CAV(w); u=AV(ind); k=bp(t); + DO(c, MC(x+k*i,v+k*(i+c*u[i]),k);); + EPILOG(z); +} +*/ + +#define MCASE(t,k) ((t)+16*(k)) +#define MINDEX {j=*u++; if(0>j)j+=m; ASSERT(0<=j&&j<m,EVINDEX);} + +static A jtmerge1(J jt,A w,A ind){A z;B*b;C*wc,*zc;D*wd,*zd;I c,it,j,k,m,r,*s,t,*u,*wi,*zi; + RZ(w&&ind); + r=MAX(0,AR(w)-1); s=1+AS(w); t=AT(w); k=bp(t); m=IC(w); c=aii(w); + ASSERT(!(t&SPARSE),EVNONCE); + ASSERT(r==AR(ind),EVRANK); + ASSERT(!ICMP(s,AS(ind),r),EVLENGTH); + GA(z,t,c,r,s); + if(!(AT(ind)&B01+INT))RZ(ind=cvt(INT,ind)); + it=AT(ind); u=AV(ind); b=(B*)u; + ASSERT(!c||1<m||!(it&B01),EVINDEX); + ASSERT(!c||1!=m||!memchr(b,C1,c),EVINDEX); + zi=AV(z); zc=(C*)zi; zd=(D*)zc; + wi=AV(w); wc=(C*)wi; wd=(D*)wc; + switch(MCASE(it,k)){ + case MCASE(B01,sizeof(C)): DO(c, *zc++=wc[*b++?i+c:i];); break; + case MCASE(B01,sizeof(I)): DO(c, *zi++=wi[*b++?i+c:i];); break; +#if !SY_64 + case MCASE(B01,sizeof(D)): DO(c, *zd++=wd[*b++?i+c:i];); break; +#endif + case MCASE(INT,sizeof(C)): DO(c, MINDEX; *zc++=wc[i+c*j];); break; + case MCASE(INT,sizeof(I)): DO(c, MINDEX; *zi++=wi[i+c*j];); break; +#if !SY_64 + case MCASE(INT,sizeof(D)): DO(c, MINDEX; *zd++=wd[i+c*j];); break; +#endif + default: if(it&B01)DO(c, MC(zc,wc+k*(*b++?i+c:i),k); zc+=k;) + else DO(c, MINDEX; MC(zc,wc+k*(i+c*j ),k); zc+=k;); break; + } + R RELOCATE(w,z); +} + +#define CASE2Z(T) {T*xv=(T*)AV(x),*yv=(T*)AV(y),*zv=(T*)AV(z); DO(n, zv[i]=bv[i]?yv[i]:xv[i];); R z;} +#define CASE2X(T) {T*xv=(T*)AV(x),*yv=(T*)AV(y); DO(n, if( bv[i])xv[i]=yv[i];); R x;} +#define CASE2Y(T) {T*xv=(T*)AV(x),*yv=(T*)AV(y); DO(n, if(!bv[i])yv[i]=xv[i];); R y;} +#define CASENZ(T) {T*zv=(T*)AV(z); DO(n, j=iv[i]; if(0>j){j+=m; ASSERT(0<=j,EVINDEX);}else ASSERT(j<m,EVINDEX); \ + zv[i]=*(i+(T*)aa[j]);); R z;} + +F1(jtcasev){A b,*u,*v,w1,x,y,z;B*bv,p,q;I*aa,c,*iv,j,m,n,r,*s,t; + RZ(w); + RZ(w1=ca(w)); u=AAV(w1); + p=1; m=AN(w)-3; v=AAV(w); c=i0(v[m+1]); + DO(m+1, x=symbrd(v[i]); if(!x){p=0; RESETERR; break;} u[i]=x; p=p&&NOUN&AT(x);); + if(p){ + b=u[m]; n=AN(b); r=AR(b); s=AS(b); t=AT(*u); + p=t&B01+LIT+INT+FL+CMPX&&AT(b)&NUMERIC; + if(p)DO(m, y=u[i]; if(!(t==AT(y)&&r==AR(y)&&!ICMP(s,AS(y),r))){p=0; break;}); + } + if(!p)R parse(v[m+2]); + if(q=2==m&&B01&AT(b)){bv=BAV(b); x=u[0]; y=u[1];} + else{ + if(!(INT&AT(b)))RZ(b=cvt(INT,b)); + iv=AV(b); + GA(x,INT,m,1,0); aa=AV(x); DO(m, aa[i]=(I)AV(u[i]);); + } + if(p=!q||0>c||1<AC(u[c]))GA(z,t,n,r,s) else z=u[c]; + switch((!q?12:p?0:c==0?4:8)+(t&B01+LIT?0:t&INT?1:t&FL?2:3)){ + case 0: CASE2Z(C); case 1: CASE2Z(I); case 2: CASE2Z(D); case 3: CASE2Z(Z); + case 4: CASE2X(C); case 5: CASE2X(I); case 6: CASE2X(D); case 7: CASE2X(Z); + case 8: CASE2Y(C); case 9: CASE2Y(I); case 10: CASE2Y(D); case 11: CASE2Y(Z); + case 12: CASENZ(C); case 13: CASENZ(I); case 14: CASENZ(D); case 15: CASENZ(Z); + default: ASSERTSYS(0,"casev"); +}} /* z=:b}x0,x1,x2,...,x(m-2),:x(m-1) */ + + +A jtmerge2(J jt,A a,A w,A ind,B ip){A z;I an,ar,*as,at,in,ir,*iv,k,t,wn,wt; + RZ(a&&w&&ind); + an=AN(a); at=AT(a); ar=AR(a); as=AS(a); + wn=AN(w); wt=AT(w); + in=AN(ind); ir=AR(ind); iv=AV(ind); + ASSERT(!an||!wn||HOMO(at,wt),EVDOMAIN); + ASSERT(ar<=ir,EVRANK); + ASSERT(!ICMP(as,AS(ind)+ir-ar,ar),EVLENGTH); + if(!wn)R ca(w); + RE(t=an&&wn?maxtype(at,wt):wt); + if(an&&t!=at)RZ(a=cvt(t,a)); + if(ip&&t==wt&&(!(t&BOX)||AFNJA&AFLAG(w))){ASSERT(!(AFRO&AFLAG(w)),EVRO); z=w;} + else{RZ(z=cvt(t,w)); if(ARELATIVE(w))RZ(z=relocate((I)w-(I)z,z));} + if(ip&&t&BOX&&AFNJA&AFLAG(w)){A*av,t,x,y;A1*zv;I ad,*tv; + ad=(I)a*ARELATIVE(a); av=AAV(a); zv=A1AV(z); + GA(t,INT,in,1,0); tv=AV(t); memset(tv,C0,in*SZI); + DO(in, y=smmcar(z,AVR(i%an)); if(!y)break; tv[i]=(I)y;); + if(!y){DO(in, if(!tv[i])break; smmfrr((A)tv[i]);); R 0;} + DO(in, x=(A)AABS(zv[iv[i]],z); zv[iv[i]]=AREL(tv[i],z); smmfrr(x);); + }else{ + if(ARELATIVE(a))RZ(a=rca(a)); + if(ARELATIVE(z)){A*av=AAV(a),*zv=AAV(z); DO(in, zv[iv[i]]=(A)AREL(av[i%an],z););} + else {C*av=CAV(a),*zv=CAV(z); k=bp(t); DO(in, MC(zv+k*iv[i],av+k*(i%an),k); );} + } + R z; +} + +A jtjstd(J jt,A w,A ind){A j=0,k,*v,x;B b;I d,i,id,n,r,*s,*u,wr,*ws; + wr=AR(w); ws=AS(w); b=AN(ind)&&BOX&AT(ind); + if(!wr)R from(ind,zero); + if(b&&AR(ind)){ + RE(aindex(ind,w,0L,&j)); + if(!j){ + RZ(x=from(ind,increm(iota(shape(w))))); u=AV(x); + DO(AN(x), ASSERT(*u,EVDOMAIN); --*u; ++u;); + R x; + } + k=AAV0(ind); n=AN(k); + GA(x,INT,wr,1,0); u=wr+AV(x); s=wr+ws; d=1; DO(wr, *--u=d; d*=*--s;); + R n==wr?pdt(j,x):irs2(pdt(j,vec(INT,n,AV(x))),iota(vec(INT,wr-n,ws+n)),0L,0L,RMAX,jtplus); + } + if(!b){n=1; RZ(j=pind(*ws,ind));} + else{ + ind=AAV0(ind); n=AN(ind); r=AR(ind); + ASSERT(!n&&1==r||AT(ind)&BOX+NUMERIC,EVINDEX); + if(n&&!(BOX&AT(ind)))RZ(ind=every(ind,0L,jtright1)); + v=AAV(ind); id=(I)ind*ARELATIVE(ind); + ASSERT(1>=r,EVINDEX); + ASSERT(n<=wr,EVINDEX); + d=n; DO(n, --d; if(!equ(ace,AADR(id,v[d])))break;); if(n)++d; n=d; + j=zero; + for(i=0;i<n;++i){ + x=AADR(id,v[i]); d=ws[i]; + if(AN(x)&&BOX&AT(x)){ + ASSERT(!AR(x),EVINDEX); + x=AAV0(x); k=IX(d); + if(AN(x))k=less(k,pind(d,1<AR(x)?ravel(x):x)); + }else k=pind(d,x); + RZ(j=irs2(tymes(j,sc(d)),k,0L,0L,RMAX,jtplus)); + }} + R n==wr?j:irs2(tymes(j,sc(prod(wr-n,ws+n))),iota(vec(INT,wr-n,ws+n)),0L,0L,RMAX,jtplus); +} /* convert ind in a ind}w into integer positions */ + +/* Reference count for w for amend in place */ +/* 1 jdo tpop */ +/* 2 amendn2 EPILOG/gc */ +/* 1 jdo tpop */ + +static A jtamendn2(J jt,A a,A w,A ind,B ip){PROLOG;A e,z;B b,sa,sw;I at,ir,it,t,t1,wt;P*p; + RZ(a&&w&&ind); + at=AT(a); sa=1&&at&SPARSE; if(sa)at=DTYPE(at); + wt=AT(w); sw=1&&wt&SPARSE; if(sw)wt=DTYPE(wt); + it=AT(ind); ir=AR(ind); + ASSERT(it&NUMERIC+BOX||!AN(ind),EVDOMAIN); + ASSERT(it&DENSE,EVNONCE); + if(sw){ + ASSERT(!(wt&BOX),EVNONCE); ASSERT(HOMO(at,wt),EVDOMAIN); + RE(t=maxtype(at,wt)); t1=STYPE(t); RZ(a=t==at?a:cvt(sa?t1:t,a)); + if(ip=ip&&t==wt&&t1!=BOX){ASSERT(!(AFRO&AFLAG(w)),EVRO); z=w;}else RZ(z=cvt(t1,w)); + p=PAV(z); e=SPA(p,e); b=!AR(a)&&equ(a,e); + p=PAV(a); if(sa&&!equ(e,SPA(p,e))){RZ(a=denseit(a)); sa=0;} + if(it&NUMERIC||!ir)z=(b?jtam1e:sa?jtam1sp:jtam1a)(jt,a,z,it&NUMERIC?box(ind):ope(ind),ip); + else{RE(aindex(ind,z,0L,&ind)); ASSERT(ind,EVNONCE); z=(b?jtamne:sa?jtamnsp:jtamna)(jt,a,z,ind,ip);} + }else z=merge2(sa?denseit(a):a,w,jstd(w,ind),ip); + EPILOG(z); +} + +static DF2(amccn2){R amendn2(a,w,VAV(self)->f,0);} +static DF2(amipn2){R amendn2(a,w,VAV(self)->f,(B)(!(AT(w)&RAT+XNUM)&&(1==AC(w)||AFNJA&AFLAG(w))));} + +static DF2(amccv2){DECLF; + RZ(a&&w); + ASSERT(DENSE&AT(w),EVNONCE); + R merge2(a,w,pind(AN(w),CALL2(f2,a,w,fs)),0); +} + +static DF2(amipv2){DECLF; + RZ(a&&w); + ASSERT(DENSE&AT(w),EVNONCE); + R merge2(a,w,pind(AN(w),CALL2(f2,a,w,fs)),(B)(!(AT(w)&RAT+XNUM)&&(1==AC(w)||AFNJA&AFLAG(w)))); +} + +static DF1(mergn1){ R merge1(w,VAV(self)->f);} +static DF1(mergv1){DECLF; R merge1(w,CALL1(f1,w,fs));} + +static B ger(A w){A*wv,x;I wd; + if(!(BOX&AT(w)))R 0; + wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(AN(w), x=WVR(i); if(BOX&AT(x)&&1==AR(x)&&2==AN(x))x=AAV0(x); if(!(LIT&AT(x)&&1>=AR(x)&&AN(x)))R 0;); + R 1; +} /* 0 if w is definitely not a gerund; 1 if possibly a gerund */ + +static A jtamend(J jt,A w,B ip){ + RZ(w); + if(VERB&AT(w)) R ADERIV(CRBRACE,mergv1,ip?amipv2:amccv2,RMAX,RMAX,RMAX); + else if(ger(w))R gadv(w,CRBRACE); + else R ADERIV(CRBRACE,mergn1,ip?amipn2:amccn2,RMAX,RMAX,RMAX); +} + +F1(jtrbrace){R amend(w,0);} +F1(jtamip ){R amend(w,1);} + + +static DF2(jtamen2){ASSERT(0,EVNONCE);} + +F1(jtemend){ + ASSERT(NOUN&AT(w),EVDOMAIN); + R ADERIV(CEMEND,0L,jtamen2,RMAX,RMAX,RMAX); +}
new file mode 100644 --- /dev/null +++ b/am1.c @@ -0,0 +1,205 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: a ind}z for sparse z & ind is box a0;a1;a2;... or integer */ + +/* am1e a is the sparse element */ +/* am1a a is an arbitrary dense array */ +/* am1sp a an arbitrary sparse array */ + +#include "j.h" + + +static A jtistd1(J jt,A z,A ind){A*iv,j,*jv,x;I d,i,id,n,r,*s; + RZ(z&&ind); + ASSERT(1>=AR(ind),EVRANK); + if(AN(ind)&&!(BOX&AT(ind))){ASSERT(NUMERIC&AT(ind),EVINDEX); RZ(ind=every(ind,0L,jtright1));} + s=AS(z); n=AN(ind); iv=AAV(ind); id=(I)ind*ARELATIVE(ind); + ASSERT(n<=AR(z),EVINDEX); + d=n; DO(n, --d; x=IVR(d); if(!equ(x,ace))break;); n=n?1+d:d; + GA(j,BOX,n,1,0); jv=AAV(j); + for(i=0;i<n;++i){ + x=IVR(i); d=s[i]; + if(BOX&AT(x)){ + ASSERT(!AR(x),EVINDEX); + x=AAV0(x); r=AR(x); + RZ(jv[i]=!AN(x)&&1==r?ace:less(IX(d),pind(d,x))); + }else RZ(jv[i]=pind(d,x)); + } + R j; +} /* convert index list ind into standard form */ + +static A jtastd1(J jt,A a,A z,A ind){A*iv,q,r,s,s1,*sv,x;B b;I ar,*as,d,id,j,m,n,*rv,zr,*zs;P*zp; I*s1v; + ar=AR(a); as=AS(a); + zr=AR(z); zs=AS(z); zp=PAV(z); + if(!ar)R a; + n=AN(ind); iv=AAV(ind); id=(I)ind*ARELATIVE(ind); + GA(r,INT,zr,1,0); rv= AV(r); + GA(s,BOX,zr,1,0); sv=AAV(s); + m=0; j=n; + DO(n, x=IVR(i); b=x==ace; m+=rv[i]=b?1:AR(x); RZ(sv[i]=b?sc(zs[i]):shape(x));); + DO(zr-n, rv[j]=1; RZ(sv[j]=sc(zs[j])); ++j;); + d=m+zr-n; ASSERT(ar<=d,EVRANK); + RZ(s1=raze(s)); s1v=AV(s1); + ASSERT(!ICMP(as,AV(s1)+d-ar,ar),EVLENGTH); + if(ar<d)RZ(a=reshape(s1,a)); + RZ(q=dgrade1(eps(repeat(r,IX(zr)),SPA(zp,a)))); + R equ(q,IX(d))?a:cant2(q,a); +} /* convert replacement array a into standard form relative to index list ind */ + +static A jtssel(J jt,A z,A ind){A a,*iv,p,q,x,y;B*b;I*av,c,i,id,j,m,n,*u,*v,*yv;P*zp; + zp=PAV(z); + y=SPA(zp,i); v=AS(y); m=v[0]; c=v[1]; yv=AV(y); + a=SPA(zp,a); n=AN(a); av=AV(a); + GA(p,B01,m,1,0); b=BAV(p); memset(b,C1,m); + GA(q,INT,m,1,0); v=AV(q); iv=AAV(ind); id=(I)ind*ARELATIVE(ind); + for(i=0;i<n;++i){ + j=av[i]; if(j>=AN(ind))break; + x=IVR(j); + if(x!=ace){ + u=yv+i; DO(m, v[i]=b[i]?*u:-1; u+=c;); + RZ(p=eps(q,1<AR(x)?ravel(x):x)); b=BAV(p); + }} + R p; +} /* which rows of the index matrix of z are selected by index list ind? */ + +static B jtipart(J jt,A z,A ind,A*i1,A*i2){A*iv,p,*pv,q,*qv,x;B*b;I c,d,id,n;P*zp; + n=AN(ind); iv=AAV(ind); id=(I)ind*ARELATIVE(ind); zp=PAV(z); + RZ(b=bfi(AR(z),SPA(zp,a),1)); + c=0; DO(n, if(b[i])++c;); d=n-c; + GA(p,BOX,c,1,0); pv=AAV(p); *i1=p; + GA(q,BOX,d,1,0); qv=AAV(q); *i2=q; + DO(n, x=IVR(i); if(b[i])*pv++=x; else *qv++=x;); + R 1; +} /* partition index into sparse and dense parts */ + +static A jtdcube(J jt,A z,A i2){A*iv,x,y;I i,id,m,n,*s;P*zp; + n=AN(i2); iv=AAV(i2); id=(I)i2*ARELATIVE(i2); + zp=PAV(z); x=SPA(zp,x); s=1+AS(x); + m=1; y=IVR(n-1); if(y==ace)RZ(y=IX(s[n-1])); + for(i=n-2;0<=i;--i){ + m*=s[1+i]; x=IVR(i); + RZ(y=irs2(tymes(sc(m),x==ace?IX(s[i]):x),y,0L,0L,RMAX,jtplus)); + } + R y; +} /* index cube relative to dense axes */ + +static A jtscuba(J jt,A z,A i1,B u){A*iv,q=0,x;I c,d,id,j,n,*s,*v;P*zp; + n=AN(i1); + if(!n)R mtm; + iv=AAV(i1); id=(I)i1*ARELATIVE(i1); s=AS(z); zp=PAV(z); x=SPA(zp,a); v=AV(x); + for(j=n-1;0<=j;--j){ + x=IVR(j); + if(x==ace)RZ(x=IX(s[v[j]]))else{if(1<AR(x))RZ(x=ravel(x)); if(u)RZ(x=nub(x));} + c=AN(x); + if(q){d=*AS(q); RZ(q=stitch(repeat(sc(d),x),reitem(sc(c*d),q)));} + else RZ(q=reshape(v2(c,1L),x)); + } + R q; +} /* index cube relative to sparse axes; 1=u iff unique (remove duplicates) */ + +static A jtscubb(J jt,A z,A i1){A a,q,x,y;I c,d,h,j,*s,*v,*xv;P*zp; + RZ(q=scuba(z,i1,1)); + if(!*AS(q))R mtm; + s=AS(z); zp=PAV(z); y=SPA(zp,i); a=SPA(zp,a); v=AV(a); + c=*(1+AS(q)); d=*(1+AS(y)); h=d-c; + if(c==d)R less(q,y); + RZ(q=less(q,taker(c,y))); + GA(x,INT,h,1,0); xv=AV(x); j=c; DO(h, xv[i]=s[v[j++]];); + RZ(x=odom(2L,h,xv)); + c=*AS(q); d=*AS(x); + R stitch(repeat(sc(d),q),reitem(sc(c*d),x)); +} /* new rows for the index matrix of z for brand new cells */ + +static A jtscubc(J jt,A z,A i1,A p){A a,q,s,y,y1;B*qv;I c,d,h,j=-1,m,n,*sv,*u,*v;P*zp; + zp=PAV(z); a=SPA(zp,a); n=AN(i1); h=AN(a)-n; + if(!h)R mtm; + GA(s,INT,h,1,0); sv=AV(s); + d=1; u=AS(z); v=AV(a); DO(h, d*=sv[i]=u[v[n+i]];); + RZ(y=repeat(p,SPA(zp,i))); m=*AS(y); + RZ(y1=take(v2(m,n),y)); v=AV(y1); + GA(q,B01,m,1,0); qv=BAV(q); + if(m){memset(qv,C0,m); DO(m-1, if(ICMP(v,v+n,n)){if(d>i-j)qv[i]=1; j=i;} v+=n;); if(d>(m-1)-j)qv[m-1]=1;} + RZ(y1=repeat(q,y1)); c=*AS(y1); + if(!c)R mtm; + R less(stitch(repeat(sc(d),y1),reitem(sc(c*d),odom(2L,h,sv))),y); +} /* new rows for the index matrix of z for existing cells */ + +static A jtscube(J jt,A z,A i1,A p){A a,y;P*zp; + zp=PAV(z); a=SPA(zp,a); y=SPA(zp,i); + R !AN(a)&&!*AS(y)?take(one,mtm):over(scubb(z,i1),scubc(z,i1,p)); +} /* new rows for the index matrix of z */ + +static A jtiindx(J jt,A z,A i1){A q,j,j1,y;I c,d,e,h,i,*jv,m,n,*qv,*v,*yv;P*zp; + c=AN(i1); zp=PAV(z); y=SPA(zp,i); + if(c==*(1+AS(y)))R indexof(y,scuba(z,i1,0)); + /* when y has excess columns, do progressive indexing */ + RZ(y=taker(c,y)); + RZ(j=indexof(y,scuba(z,i1,0))); /* j: group indices */ + n= AN(j); jv=AV(j); + m=*AS(y); yv=AV(y); + GA(q,INT,n,1,0); qv=AV(q); /* q: # members in each group */ + for(i=h=0;i<n;++i){ + e=1; d=jv[i]; v=yv+c*d; + DO(m-d-1, if(ICMP(v,v+c,c))break; ++e; v+=c;); + qv[i]=e; h+=e; + } + GA(j1,INT,h,1,0); v=AV(j1); + DO(n, e=qv[i]; d=jv[i]; DO(e, *v++=d++;);); + R j1; +} /* index of index list in the index matrix of z */ + +static A jtzpad1(J jt,A z,A t,B ip){A q,s,x,x0,y,y0;I m;P*zp; + RZ(z&&t); + if(m=*AS(t)){ /* new cells being added */ + zp=PAV(z); + y0=SPA(zp,i); RZ(y=over(y0,t)); RZ(q=grade1(y)); RZ(y=from(q,y)); + x0=SPA(zp,x); RZ(s=shape(x0)); *AV(s)=m; RZ(x=from(q,over(x0,reshape(s,SPA(zp,e))))); + if(ip){ra(y); ra(x); fa(y0); fa(x0);} + SPB(zp,i,y); SPB(zp,x,x); + } + R z; +} /* pad z with new rows t for its index matrix */ + +static B mtind(A ind){A*iv,x;I id; + iv=AAV(ind); id=(I)ind*ARELATIVE(ind); + DO(AN(ind), x=IVR(i); if(!AN(x))R 1;); + R 0; +} /* 1 iff standardized index ind is an empty selection */ + +A jtam1e(J jt,A a,A z,A ind,B ip){A e,i1,i2,p,x,y;B*pv;C*u,*v;I*iv,k,m,n,r,*s,vk,xk;P*zp; + RZ(a&&(ind=istd1(z,ind))); + r=AR(z); zp=PAV(z); x=SPA(zp,x); y=SPA(zp,i); e=SPA(zp,e); + RZ(p=ssel(z,ind)); pv=BAV(p); + RZ(ipart(z,ind,&i1,&i2)); + m=AN(p); n=AN(i2); u=CAV(e); v=CAV(x); + r=AR(x); s=AS(x); k=bp(AT(x)); xk=k*prod(r-(n+1),s+(n+1)); vk=k*prod(r-1,s+1); + if(!n)DO(m, if(pv[i])mvc(xk,v,k,u); v+=vk;) + else{ + RZ(i2=dcube(z,i2)); iv=AV(i2); n=AN(i2); + DO(m, if(pv[i])DO(n, mvc(xk,v+iv[i]*xk,k,u);); v+=vk;); + } + R z; +} /* a (<ind)}z; sparse z; ind is index list; sparse element a replacement */ + +A jtam1a(J jt,A a,A z,A ind,B ip){A a0=a,a1,e,i1,i2,t,x,y;C*u,*v,*xv;I ar,c,*iv,*jv,k,m,n,r,*s,uk,vk,xk;P*zp; + RZ(a&&(ind=istd1(z,ind))); + RZ(a=astd1(a,z,ind)); + if(mtind(ind))R z; + RZ(ipart(z,ind,&i1,&i2)); + RZ(z=zpad1(z,scube(z,i1,ssel(z,ind)),ip)); + zp=PAV(z); x=SPA(zp,x); y=SPA(zp,i); e=SPA(zp,e); + ar=AR(a); n=AN(i2); r=AR(x); s=AS(x); + k=bp(AT(x)); xk=k*prod(r-1-n,s+1+n); vk=k*prod(r-1,s+1); uk=!ar?k:n?xk:vk; + u=CAV(a); xv=v=CAV(x); + RZ(t=iindx(z,i1)); iv=AV(t); m=AN(t); + if(!n&&!m){a1=SPA(zp,a); R ar?sparseit(a0,a1,e):sparseit(reshape(shape(z),a),a1,a);} + if(n){RZ(t=dcube(z,i2)); jv=AV(t); c=AN(t); v=xv-vk;} + if(!n) DO(m, mvc(vk,v+vk*iv[i],uk,u); if(ar)u+=uk; ) + else if(m)DO(m, v=xv+vk*iv[i]; DO(c, mvc(xk,v+xk*jv[i],uk,u); if(ar)u+=uk;);) + else DO(*AS(x), v+=vk; DO(c, mvc(xk,v+xk*jv[i],uk,u); if(ar)u+=uk;);); + R z; +} /* a (<ind)}z; sparse z; ind is index list; arbitrary dense array a replacement */ + +A jtam1sp(J jt,A a,A z,A ind,B ip){R amnsp(a,z,ope(catalog(istd1(z,ind))),ip);} + /* a (<ind)}z; sparse z; ind is index list; arbitrary sparse array a replacement */
new file mode 100644 --- /dev/null +++ b/amn.c @@ -0,0 +1,139 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: a ind}z where z is sparse and ind is <"1 integers */ + +/* amne a is the sparse element */ +/* amna a is an arbitrary dense array */ +/* amnsp a an arbitrary sparse array */ + +#include "j.h" + + +static I jtcsize(J jt,A z,A ind){B*b;I h,j,m,r,*s;P*zp; + r=AR(z); s=AS(z); zp=PAV(z); + RZ(b=bfi(r,SPA(zp,a),0)); + m=1; j=h=*(AR(ind)+AS(ind)-1); DO(r-h, if(b[j])m*=s[j]; ++j;); + R m; +} /* data cell size in z for each element of index array ind */ + +static B jtiaddr(J jt,A z,A ind,A*i1,A*i2){A a,ai,as,ii,jj,q,t,x,y;I c,d,e,h,i,*iv,*jv,m,n,p,*qv,*s,*u,*v,*yv;P*zp; + zp=PAV(z); a=SPA(zp,a); x=SPA(zp,x); s=1+AS(x); + h=*(AS(ind)+AR(ind)-1); /* # axes indexed */ + RZ(q=gt(sc(h),a)); + y=SPA(zp,i); if(!all1(q))RZ(y=repeatr(q,y)); /* indexed cols of index mat */ + m=*AS(y); yv=AV(y); + RZ(ai=IX(h)); + RZ(as=less(IX(AR(z)),a)); u=AV(as); n=AN(as); /* dense axes */ + GA(t,INT,n,1,0); v=AV(t); /* shape of indexed dense axes */ + e=0; d=1; DO(n, if(h>u[i])v[e++]=s[i]; else d*=s[i];); + RZ(*i2=jj=tymes(sc(d),base2(vec(INT,e,v),repeatr(eps(ai,as),ind)))); + c=*(1+AS(y)); + if(!c){ + n=AN(jj); + RZ(*i1=repeat(sc(n),IX(m))); + RZ(*i2=reshape(sc(m*n),jj)); + R 1; + } + RZ(*i1=ii=indexof(y,repeatr(eps(ai,a),ind))); /* group indices in index mat */ + if(c==AN(a))R 1; + n=AN(ii); iv=AV(ii); jv=AV(jj); /* do progressive iota */ + GA(q,INT,n,1,0); qv=AV(q); /* group sizes */ + for(i=h=0;i<n;++i){ + e=1; d=iv[i]; v=yv+c*d; + DO(m-d-1, if(ICMP(v,v+c,c))break; ++e; v+=c;); + qv[i]=e; h+=e; /* # elements in group i */ + } + GA(t,INT,h,1,0); u=AV(t); *i1=t; + GA(t,INT,h,1,0); v=AV(t); *i2=t; + DO(n, e=qv[i]; d=iv[i]; p=jv[i]; DO(e, *u++=d++; *v++=p;);); + R 1; +} /* index i1 (in index matrix) and address i2 (in data array) from index array */ + +static A jtzpadn(J jt,A z,A ind,B ip){A a,ai,i1,p,p1,q,t,x,x0,y,y0,y1;B*b;I c,d,h,m,n;P*zp; + zp=PAV(z); a=SPA(zp,a); x=x0=SPA(zp,x); y=y0=SPA(zp,i); + n=1; h=*(AS(ind)+AR(ind)-1); + RZ(ai=IX(h)); + RZ(t=eps(ai,a)); b=BAV(t); d=0; DO(h, if(b[i])++d;); + RZ(i1=d<h?repeatr(t,ind):ind); if(2!=AR(ind))RZ(i1=d?reshape(v2(AN(i1)/d,d),i1):mtm); + RZ(t=gt(sc(h),a)); RZ(y1=all1(t)?y:repeatr(t,y)); + RZ(p=nub(less(i1,y1))); + if(c=AN(a)-d){ + RZ(t=from(less(a,ai),shape(z))); RZ(p1=odom(2L,c,AV(t))); n=*AS(p1); + if(m=*AS(p))RZ(p=stitch(repeat(sc(n),p),reshape(v2(n*m,c),p1))); + RZ(t=nub(repeat(eps(y1,i1),y1))); + RZ(t=stitch(repeat(sc(n),t),reshape(v2(n**AS(t),c),p1))); + RZ(t=less(t,y)); + if(AN(t))RZ(p=over(p,t)); + } + if(m=*AS(p)){ /* new cells being added */ + RZ(y=over(y,p)); RZ(q=grade1(y)); RZ(y=from(q,y)); + RZ(t=shape(x)); *AV(t)=m; RZ(x=from(q,over(x,reshape(t,SPA(zp,e))))); + if(ip){ra(y); ra(x); fa(y0); fa(x0);} + SPB(zp,i,y); SPB(zp,x,x); + } + R z; +} /* create new indexed cells in z as necessary */ + +static A jtastdn(J jt,A a,A z,A ind){A a1,q,r,s;B*b;I ar,*as,*av,d,ir,n,n1,*v,zr,*zs;P*zp; + ar=AR(a); as=AS(a); + zr=AR(z); zs=AS(z); + if(!ar)R a; + ir=AR(ind); n=*(AS(ind)+ir-1); d=(ir-1)+(zr-n); ASSERT(ar<=d,EVRANK); + GA(s,INT,d,1,0); v=AV(s); ICPY(v,AS(ind),ir-1); ICPY(v+ir-1,zs+n,zr-n); + ASSERT(!ICMP(as,AV(s)+d-ar,ar),EVLENGTH); + if(ar<d)RZ(a=reshape(s,a)); + zp=PAV(z); a1=SPA(zp,a); av=AV(a1); n1=n-1; + GA(s,B01,zr,1,0); b=BAV(s); + memset(b,C0,zr); DO(AN(a1), b[av[i]]=1;); memset(b,!memchr(b,C1,n)?C0:C1,n); + GA(r,INT,zr-n1,1,0); v=AV(r); *v++=ar-(zr-n); DO(zr-n, *v++=1;); + RZ(q=dgrade1(repeat(r,vec(B01,zr-n1,b+n1)))); + R equ(q,IX(ar))?a:cant2(q,a); +} /* convert replacement array a into standard form relative to index array ind */ + +A jtamne(J jt,A a,A z,A ind,B ip){A i1,i2,x,y;C*u,*v;I*iv,*jv,k,m,n,vk,xk;P*zp; + RZ(a&&z&&ind); + RZ(iaddr(z,ind,&i1,&i2)); + zp=PAV(z); x=SPA(zp,x); y=SPA(zp,i); + m=*AS(y); n=AN(i1); + k=bp(AT(x)); xk=k*aii(x); vk=k*csize(z,ind); + u=CAV(a); v=CAV(x); iv=AV(i1); jv=AV(i2); + DO(n, if(m>iv[i])mvc(vk,v+xk*iv[i]+k*jv[i],k,u);); + R z; +} /* a (<"1 ind)}z, sparse z, integer array ind, sparse element a replacement */ + +A jtamna(J jt,A a,A z,A ind,B ip){A i1,i2,x;C*u,*v;I*iv,*jv,k,n,vk,xk;P*zp; + RZ(a&&z&&ind); + RZ(z=zpadn(z,ind,ip)); + RZ(a=astdn(a,z,ind)); + RZ(iaddr(z,ind,&i1,&i2)); + zp=PAV(z); x=SPA(zp,x); n=AN(i1); + k=bp(AT(x)); xk=k*aii(x); vk=k*csize(z,ind); + u=CAV(a); v=CAV(x); iv=AV(i1); jv=AV(i2); + if(AR(a))DO(n, mvc(vk,v+xk*iv[i]+k*jv[i],vk,u); u+=vk;) + else DO(n, mvc(vk,v+xk*iv[i]+k*jv[i],k,u);); + R z; +} /* a (<"1 ind)}z, dense a,integer array ind, sparse z */ + +A jtamnsp(J jt,A a,A z,A ind,B ip){A i1,i2,t;C*ev,*u,*v,*vv;I c,*dv,i,*iv,j,*jv,k,m,n,p,q,r,*s,*yv,zk;P*ap,*zp; + RZ(a&&z&&ind); + r=AR(a); ap=PAV(a); t=SPA(ap,a); if(r>AN(t))RZ(a=reaxis(IX(r),a)); + RZ(a=astdn(a,z,ind)); ap=PAV(a); + RZ(z=zpadn(z,ind,ip)); zp=PAV(z); + RZ(iaddr(z,ind,&i1,&i2)); + s=AS(a); n=AN(i1); c=csize(z,ind); iv=AV(i1); jv=AV(i2); + t=SPA(ap,i); yv= AV(t); m=*AS(t); p=0; + t=SPA(ap,e); ev=CAV(t); + t=SPA(ap,x); u =CAV(t); + t=SPA(zp,x); v =CAV(t); k=bp(AT(t)); zk=k*aii(t); + GA(t,INT,r,1,0); dv=AV(t); memset(dv,C0,SZI*r); dv[r-1]=-1; + for(i=0;i<n;++i){ + vv=v+zk*iv[i]+k*jv[i]; + for(j=0;j<c;++j){ + q=r; DO(r, --q; ++dv[q]; if(dv[q]<s[q])break; dv[q]=0;); + q=1; while(p<m){DO(r, if(q=yv[i]-dv[i])break;); if(0<=q)break; ++p; yv+=r;} + MC(vv,q?ev:u+k*p,k); + vv+=k; + }} + R z; +} /* a (<"1 ind)}z, sparse a, integer array ind, sparse z */
new file mode 100644 --- /dev/null +++ b/ao.c @@ -0,0 +1,492 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Oblique and Key */ + +#include "j.h" + + +static DF1(jtoblique){A x,y;I m,n,r,*u,*v; + RZ(w); + r=AR(w); + RZ(y=gah(MAX(r-1,1),w)); + u=AS(w); v=AS(y); + if(1>=r){*v=m=AN(w); n=1;}else{m=*u++; n=*u++; *v++=m*n; ICPY(v,u,r-2);} + RZ(x=irs2(IX(m),IX(n),0L,0L,1L,jtplus)); AR(x)=1; *AS(x)=AN(x); + R df2(x,y,sldot(VAV(self)->f)); +} + + +#define OBQCASE(id,t) ((id)+(256*(t))) + +#define OBQLOOP(Tw,Tz,zt,init,expr) \ + {Tw*u,*v,*ww=(Tw*)wv;Tz x,*zz; \ + b=1; k=n1; \ + GA(z,zt,d*c,r-1,1+s); *AS(z)=d; zz=(Tz*)AV(z); \ + DO(n, v=ww+i; u=v+n1*MIN(i,m1); init; while(v<=(u-=n1))expr; *zz++=x;); \ + DO(m1, v=ww+(k+=n); u=v+n1*MIN(m-i-2,n1); init; while(v<=(u-=n1))expr; *zz++=x;); \ + } + +static DF1(jtobqfslash){A y,z;B b=0,p;C er,id,*wv;I c,d,k,m,m1,mn,n,n1,r,*s,wt; + RZ(w); + r=AR(w); s=AS(w); wt=AT(w); wv=CAV(w); + if(!(AN(w)&&1<r&&DENSE&wt))R oblique(w,self); + y=VAV(self)->f; y=VAV(y)->f; id=vaid(y); + m=s[0]; m1=m-1; + n=s[1]; n1=n-1; mn=m*n; d=m+n-1; c=prod(r-2,2+s); + if(1==m||1==n){GA(z,wt,AN(w),r-1,1+s); *AS(z)=d; MC(AV(z),wv,AN(w)*bp(wt)); R z;} + if(wt&FL+CMPX)NAN0; + if(1==c)switch(OBQCASE(wt,id)){ + case OBQCASE(B01, CNE ): OBQLOOP(B,B,wt,x=*u, x^=*u ); break; + case OBQCASE(B01, CEQ ): OBQLOOP(B,B,wt,x=*u, x=x==*u ); break; + case OBQCASE(B01, CMAX ): + case OBQCASE(B01, CPLUSDOT): OBQLOOP(B,B,wt,x=*u, x|=*u ); break; + case OBQCASE(B01, CMIN ): + case OBQCASE(B01, CSTAR ): + case OBQCASE(B01, CSTARDOT): OBQLOOP(B,B,wt,x=*u, x&=*u ); break; + case OBQCASE(B01, CLT ): OBQLOOP(B,B,wt,x=*u, x=*u< x ); break; + case OBQCASE(B01, CLE ): OBQLOOP(B,B,wt,x=*u, x=*u<=x ); break; + case OBQCASE(B01, CGT ): OBQLOOP(B,B,wt,x=*u, x=*u> x ); break; + case OBQCASE(B01, CGE ): OBQLOOP(B,B,wt,x=*u, x=*u>=x ); break; + case OBQCASE(B01, CPLUS ): OBQLOOP(B,I,INT,x=*u, x+=*u ); break; + case OBQCASE(FL, CMAX ): OBQLOOP(D,D,wt,x=*u, x=MAX(x,*u) ); break; + case OBQCASE(FL, CMIN ): OBQLOOP(D,D,wt,x=*u, x=MIN(x,*u) ); break; + case OBQCASE(FL, CPLUS ): OBQLOOP(D,D,wt,x=*u, x+=*u ); break; + case OBQCASE(CMPX,CPLUS ): OBQLOOP(Z,Z,wt,x=*u, x=zplus(x,*u)); break; + case OBQCASE(XNUM,CMAX ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)? x:*u); break; + case OBQCASE(XNUM,CMIN ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)?*u: x); break; + case OBQCASE(XNUM,CPLUS ): OBQLOOP(X,X,wt,x=*u, x=xplus(x,*u)); break; + case OBQCASE(RAT, CMAX ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)? x:*u); break; + case OBQCASE(RAT, CMIN ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)?*u: x); break; + case OBQCASE(RAT, CPLUS ): OBQLOOP(Q,Q,wt,x=*u, x=qplus(x,*u)); break; + case OBQCASE(INT, CBW0001 ): OBQLOOP(I,I,wt,x=*u, x&=*u ); break; + case OBQCASE(INT, CBW0110 ): OBQLOOP(I,I,wt,x=*u, x^=*u ); break; + case OBQCASE(INT, CBW0111 ): OBQLOOP(I,I,wt,x=*u, x|=*u ); break; + case OBQCASE(INT, CMAX ): OBQLOOP(I,I,wt,x=*u, x=MAX(x,*u) ); break; + case OBQCASE(INT, CMIN ): OBQLOOP(I,I,wt,x=*u, x=MIN(x,*u) ); break; + case OBQCASE(INT, CPLUS ): + er=0; OBQLOOP(I,I,wt,x=*u, {p=0>x; x+=*u; BOV(p==0>*u&&p!=0>x);}); + if(er==EWOV)OBQLOOP(I,D,FL,x=(D)*u, x+=*u); + } + if(wt&FL+CMPX)NAN1; RE(0); + R b?z:oblique(w,self); +} /* f//.y for atomic f */ + + +#if SY_64 +#define TYMESF(x) {LD t=*u--*(LD)*v++; x=(I)t; BOV(t<IMIN||IMAX<t);} +#else +#define TYMESF(x) {D t=*u--*( D)*v++; x=(I)t; BOV(t<IMIN||IMAX<t);} +#endif +#define ACCUMF {B p;I y; TYMESF(y); p=0>x; x+=y; BOV(p==0>y&&p!=0>x);} + +#define PMCASE(t,c,d) (65536*(c)+256*(d)+(t)) + +#define PMLOOP(Tw,Tz,zt,expr0,expr) \ + {Tw*aa=(Tw*)av,*u,*v,*ww=(Tw*)wv;Tz x,*zv; \ + b=1; GA(z,zt,zn,1,0); zv=(Tz*)AV(z); \ + for(i=0;i<zn;++i){ \ + j=MIN(i,m1); u=aa+j; v=ww+i-j; \ + p=MIN(1+i,zn-i); p=MIN(p,k); \ + expr0; DO(p-1, expr;); *zv++=x; \ + }} + +DF2(jtpolymult){A f,g,y,z;B b=0;C*av,c,d,*wv;I at,i,j,k,m,m1,n,p,t,wt,zn;V*v; + RZ(a&&w&&self); + m=AN(a); n=AN(w); m1=m-1; zn=m+n-1; k=MIN(m,n); + at=AT(a); wt=AT(w); t=maxtype(at,wt); + if(t!=at)RZ(a=cvt(t,a)); at=AT(a); av=CAV(a); + if(t!=wt)RZ(w=cvt(t,w)); wt=AT(w); wv=CAV(w); + v=VAV(self); + f=v->f; y=VAV(f)->f; y=VAV(y)->f; c=vaid(y); + g=v->g; y=VAV(g)->f; d=vaid(y); + if(!(m&&1==AR(a)&&n&&1==AR(w)))R obqfslash(df2(a,w,g),f); + if(t&FL+CMPX)NAN0; + switch(PMCASE(t,c,d)){ + case PMCASE(B01, CNE, CMAX ): + case PMCASE(B01, CNE, CPLUSDOT): PMLOOP(B,B,B01, x=*u--|*v++, x^=*u--|*v++); break; + case PMCASE(B01, CNE, CSTAR ): + case PMCASE(B01, CNE, CMIN ): + case PMCASE(B01, CNE, CSTARDOT): PMLOOP(B,B,B01, x=*u--&*v++, x^=*u--&*v++); break; + case PMCASE(B01, CPLUS, CMAX ): + case PMCASE(B01, CPLUS, CPLUSDOT): PMLOOP(B,I,INT, x=*u--|*v++, x+=*u--|*v++); break; + case PMCASE(B01, CPLUS, CSTAR ): + case PMCASE(B01, CPLUS, CMIN ): + case PMCASE(B01, CPLUS, CSTARDOT): PMLOOP(B,I,INT, x=*u--&*v++, x+=*u--&*v++); break; + case PMCASE(FL, CPLUS, CSTAR ): PMLOOP(D,D,FL, x=*u--**v++, x+=*u--**v++); break; + case PMCASE(CMPX,CPLUS, CSTAR ): PMLOOP(Z,Z,CMPX, x=ztymes(*u--,*v++), x=zplus(x,ztymes(*u--,*v++))); break; + case PMCASE(XNUM,CPLUS, CSTAR ): PMLOOP(X,X,XNUM, x=xtymes(*u--,*v++), x=xplus(x,xtymes(*u--,*v++))); break; + case PMCASE(RAT, CPLUS, CSTAR ): PMLOOP(Q,Q,RAT, x=qtymes(*u--,*v++), x=qplus(x,qtymes(*u--,*v++))); break; + case PMCASE(INT, CBW0110,CBW0001 ): PMLOOP(I,I,INT, x=*u--&*v++, x^=*u--&*v++); break; + case PMCASE(INT, CPLUS, CSTAR ): +/* + er=0; PMLOOP(I,I,INT, TYMESF(x), ACCUMF); +*/ + {A a1,y;I*aa,i,*u,*ww=(I*)wv,*v,*yv,*zv;VF adotymes,adosum; + b=1; + RZ(var(CSTAR,a,w,at,wt,&adotymes,&i)); vains(CPLUS,wt,&adosum,&i); + GA(a1,INT,m,1,0); aa=AV(a1); u=m+(I*)av; DO(m, aa[i]=*--u;); + GA(y,INT,MIN(m,n),1,0); yv=AV(y); + GA(z,INT,zn,1,0); zv=AV(z); + for(i=0;i<zn;++i){ + j=MIN(i,m1); u=aa+m1-j; v=ww+i-j; + p=MIN(1+i,zn-i); p=MIN(p,k); + adotymes(jt,1,p,1,yv,u,v); adosum(jt,1,p,p,zv,yv); + ++zv; + } + if(EWOV==jt->jerr){RESETERR; fa(z); PMLOOP(I,D,FL, x=*u--*(D)*v++, x+=*u--*(D)*v++);} + }} + if(t&FL+CMPX)NAN1; RE(0); + if(!b)R obqfslash(df2(a,w,g),f); + R z; +} /* f//.@(g/) for atomic f, g */ + + +static DF2(jtkey); + +static DF2(jtkeysp){PROLOG;A b,by,e,q,x,y,z;I j,k,n,*u,*v;P*p; + RZ(a&&w); + n=IC(a); + RZ(q=indexof(a,a)); p=PAV(q); + x=SPA(p,x); u=AV(x); + y=SPA(p,i); v=AV(y); + e=SPA(p,e); k=i0(e); + j=0; DO(AN(x), if(k<=u[i])break; if(u[i]==v[i])++j;); + RZ(b=ne(e,x)); + RZ(by=repeat(b,y)); + RZ(x=key(repeat(b,x),from(ravel(by),w),self)); + GA(q,SB01,1,1,0); *AS(q)=n; /* q=: 0 by}1$.n;0;1 */ + p=PAV(q); SPB(p,a,iv0); SPB(p,e,one); SPB(p,i,by); SPB(p,x,reshape(tally(by),zero)); + RZ(z=over(df1(repeat(q,w),VAV(self)->f),x)); + EPILOG(j?cdot2(box(IX(1+j)),z):z); +} + +static DF2(jtkeyi){PROLOG;A j,p;B*pv;I*av,c,d=-1,n,*jv; + RZ(a&&w); + n=IC(a); av=AV(a); + RZ(j=grade1(a)); jv=AV(j); + GA(p,B01,n,1,0); pv=BAV(p); + DO(n, c=d; d=av[*jv++]; *pv++=c<d;); + EPILOG(df2(p,from(j,w),cut(VAV(self)->f,one))); +} /* a f/. w where a is i.~x for dense x & w */ + +static DF2(jtkeybox){PROLOG;B b;I*wv; + RZ(a&&w); + ASSERT(IC(a)==IC(w),EVLENGTH); + if(SPARSE&AT(a))R keysp(a,w,self); + if(b=INT&AT(w)&&1==AR(w)){wv=AV(w); DO(AN(w), if(i!=*wv++){b=0; break;});} + if(b)R group(a); + EPILOG(keyi(indexof(a,a),w,self)); +} /* a </. w */ + +static DF2(jtkey){PROLOG; + RZ(a&&w); + ASSERT(IC(a)==IC(w),EVLENGTH); + if(SPARSE&AT(a))R keysp(a,w,self); + EPILOG(keyi(indexof(a,a),w,self)); +} /* a f/. w */ + +static I jtkeyrs(J jt,A a,I*zr,I*zs){I ac,at,r=0,s=0; + at=AT(a); ac=aii(a); + if(2>=ac)switch(at){ + case C2T: if(1==ac)s=65536; break; + case B01: if(1==ac)s=2; else{s=258; at=C2T;} break; + case LIT: if(1==ac)s=256; else{s=65536; at=C2T;} break; + case INT: if(1==ac)irange(AN(a),AV(a),&r,&s); break; + case SBT: if(1==ac){at=INT; s=jt->sbun; if(65536<s)irange(AN(a),AV(a),&r,&s);} + } + *zr=r; *zs=s; + R at; +} + +#define KCASE(d,t) (t+17*d) +#define KACC1(F,Ta) \ + {Ta*u; \ + if(1==c){ \ + u=(Ta*)av0; DO(n, v=qv+ *u++; y=*wv++; *v=F; ); \ + u=(Ta*)av0; DO(n, if(bv[j=*u++]){*zv++=qv[j]; bv[j]=0; if(s==++m)break;}); \ + }else{ \ + u=(Ta*)av0; DO(n, v=qv+c**u++; DO(c, y=*wv++; *v=F; ++v;);); \ + u=(Ta*)av0; DO(n, if(bv[j=*u++]){v=qv+c*j; DO(c, *zv++=*v++;); bv[j]=0; if(s==++m)break;}); \ + }} +#define KACC(F,Tz,Tw,v0) \ + {Tw*wv=(Tw*)wv0,y;Tz*qv=(Tz*)qv0,*v,*zv=(Tz*)zv0; \ + if(bb){ \ + m=0; v=qv; DO(AN(q), *v++=v0;); qv-=r*c; \ + switch(at){ \ + case B01: KACC1(F,B ); break; \ + case LIT: KACC1(F,UC); break; \ + case C2T: KACC1(F,US); break; \ + case INT: KACC1(F,I ); \ + }}else{ \ + v=zv; DO(m*c, *v++=v0;); \ + if(1==c)DO(n, v=zv+ *xv++; y=*wv++; *v=F; ) \ + else DO(n, v=zv+c**xv++; DO(c, y=*wv++; *v=F; ++v;);); \ + }} + +static DF2(jtkeyslash){PROLOG;A b,q,x,z=0;B bb,*bv,pp=0;C d;I at,*av0,c,n,j,m,*qv0,r,s,*u,wr,wt,*wv0,*xv,zt,*zv0; + RZ(a&&w); + at=AT(a); av0=AV(a); n=IC(a); + wt=AT(w); wv0=AV(w); wr=AR(w); + ASSERT(n==IC(w),EVLENGTH); + x=VAV(self)->f; d=vaid(VAV(x)->f); if(B01&wt)d=d==CMAX?CPLUSDOT:d==CMIN||d==CSTAR?CSTARDOT:d; + if(!(AN(a)&&AN(w)&&at&DENSE&& + (wt&B01&&(d==CEQ||d==CPLUSDOT||d==CSTARDOT||d==CNE||d==CPLUS)|| + wt&INT&&(17<=d&&d<=25)|| + wt&INT+FL&&(d==CMIN||d==CMAX||d==CPLUS) )))R key(a,w,self); + at=keyrs(a,&r,&s); c=aii(w); m=s; + zt=d==CPLUS?(wt&B01?INT:wt&INT?FL:wt):wt; bb=s&&s<=MAX(2*n,65536); + if(bb){ + GA(b,B01,s, 1,0); bv=BAV(b); memset(bv,C1,s); bv-=r; + GA(q,zt, s*c,1,0); qv0=AV(q); + }else{RZ(x=indexof(a,a)); xv=AV(x); m=0; u=xv; DO(n, *u=i==*u?m++:xv[*u]; ++u;);} + GA(z,zt,m*c,wr,AS(w)); *AS(z)=m; zv0=AV(z); + if(wt&FL)NAN0; + switch(KCASE(d,wt)){ + case KCASE(CEQ, B01): KACC(*v==y, B, B, 1 ); break; + case KCASE(CPLUSDOT,B01): KACC(*v||y, B, B, 0 ); break; + case KCASE(CSTARDOT,B01): KACC(*v&&y, B, B, 1 ); break; + case KCASE(CNE, B01): KACC(*v!=y, B, B, 0 ); break; + case KCASE(CMIN, INT): KACC(MIN(*v,y),I, I, IMAX); break; + case KCASE(CMIN, FL ): KACC(MIN(*v,y),D, D, inf ); break; + case KCASE(CMAX, INT): KACC(MAX(*v,y),I, I, IMIN); break; + case KCASE(CMAX, FL ): KACC(MAX(*v,y),D, D, infm); break; + case KCASE(CPLUS, B01): KACC(*v+y, I, B, 0 ); break; + case KCASE(CPLUS, INT): KACC(*v+y, D, I, 0.0 ); pp=1; break; + case KCASE(CPLUS, FL ): KACC(*v+y, D, D, 0.0 ); break; + case KCASE(17, INT): KACC(*v&y, UI,UI,-1 ); break; + case KCASE(22, INT): KACC(*v^y, UI,UI,0 ); break; + case KCASE(23, INT): KACC(*v|y, UI,UI,0 ); break; + case KCASE(25, INT): KACC(~(*v^y), UI,UI,-1 ); + } + if(wt&FL)NAN1; + *AS(z)=m; AN(z)=m*c; if(pp)RZ(z=pcvt(INT,z)); + EPILOG(z); +} /* x f//.y */ + + +#define KMCASE(ta,tw) (ta+65536*tw) +#define KMACC(Ta,Tw) \ + {Ta*u=(Ta*)av;Tw*v=(Tw*)wv; \ + if(1==c)DO(n, ++pv[*u]; qv[*u]+=*v++; ++u;) \ + else DO(n, ++pv[*u]; vv=qv+c**u; DO(c, *vv++ +=*v++;); ++u;); \ + } +#define KMSET(Ta) \ + {Ta*u=(Ta*)av; \ + if(1==c)DO(n, if(pv[j=*u++]){ *zv++=qv[j]/pv[j]; pv[j]=0; if(s==++m)break;}) \ + else DO(n, if(pv[j=*u++]){vv=qv+c*j; d=(D)pv[j]; DO(c, *zv++=*vv++/d;); pv[j]=0; if(s==++m)break;}); \ + } +#define KMFUN(Tw) \ + {Tw*v=(Tw*)wv; \ + if(1==c)DO(n, j=*xv++; ++pv[j]; zv[j]+=*v++;) \ + else DO(n, j=*xv++; ++pv[j]; vv=zv+j*c; DO(c, *vv+++=*v++;);); \ + } + +static DF2(jtkeymean){PROLOG;A p,q,x,z;D d,*qv,*vv,*zv;I at,*av,c,j,m=0,n,*pv,r,s,*u,wr,wt,*wv,*xv; + RZ(a&&w); + at=AT(a); av=AV(a); n=IC(a); + wt=AT(w); wv=AV(w); wr=AR(w); + ASSERT(n==IC(w),EVLENGTH); + if(!(AN(a)&&AN(w)&&at&DENSE&&wt&B01+INT+FL))R df2(a,w,folk(sldot(slash(ds(CPLUS))),ds(CDIV),sldot(ds(CPOUND)))); + at=keyrs(a,&r,&s); c=aii(w); + if(wt&FL)NAN0; + if(s&&s<=MAX(2*n,65536)){ + GA(p,INT,s, 1, 0 ); pv= AV(p); memset(pv,C0,s* SZI); pv-=r; + GA(q,FL, s*c,1, 0 ); qv=DAV(q); memset(qv,C0,s*c*SZD); qv-=r*c; + GA(z,FL, s*c,wr,AS(w)); zv=DAV(z); + switch(KMCASE(at,wt)){ + case KMCASE(B01,B01): KMACC(B, B); break; + case KMCASE(B01,INT): KMACC(B, I); break; + case KMCASE(B01,FL ): KMACC(B, D); break; + case KMCASE(LIT,B01): KMACC(UC,B); break; + case KMCASE(LIT,INT): KMACC(UC,I); break; + case KMCASE(LIT,FL ): KMACC(UC,D); break; + case KMCASE(C2T,B01): KMACC(US,B); break; + case KMCASE(C2T,INT): KMACC(US,I); break; + case KMCASE(C2T,FL ): KMACC(US,D); break; + case KMCASE(INT,B01): KMACC(I ,B); break; + case KMCASE(INT,INT): KMACC(I ,I); break; + case KMCASE(INT,FL ): KMACC(I ,D); + } + switch(at){ + case B01: KMSET(B ); break; + case LIT: KMSET(UC); break; + case C2T: KMSET(US); break; + case INT: KMSET(I ); + } + *AS(z)=m; AN(z)=m*c; + }else{ + RZ(x=indexof(a,a)); xv=AV(x); m=0; u=xv; DO(n, *u=i==*u?m++:xv[*u]; ++u;); + GA(p,INT,m, 1, 0 ); pv= AV(p); memset(pv,C0,m* SZI); + GA(z,FL, m*c,wr,AS(w)); *AS(z)=m; zv=DAV(z); memset(zv,C0,m*c*SZD); + switch(wt){ + case B01: KMFUN(B); break; + case INT: KMFUN(I); break; + case FL: KMFUN(D); + } + if(1==c)DO(m, *zv++/=*pv++;) else DO(m, d=(D)*pv++; DO(c, *zv++/=d;);); + } + if(wt&FL)NAN1; + EPILOG(z); +} /* x (+/%#)/.y */ + + +#define GRPCD(T) {T*v=(T*)wv; DO(n, j=*v++; if(0<=dv[j])++cv[j]; else{dv[j]=i; cv[j]=1; ++zn;});} +#define GRPIX(T,asgn,j,k) {T*v=(T*)wv; DO(n, j=asgn; if(m>=j)*cu[k]++=i; \ + else{GA(x,INT,cv[k],1,0); *zv++=x; u=AV(x); *u++=m=j; cu[k]=u;})} + +F1(jtgroup){PROLOG;A c,d,x,z,*zv;B b;I**cu,*cv,*dv,j,k,m,n,p,q,t,*u,*v,*wv,zn=0; + RZ(w); + if(SPARSE&AT(w))RZ(w=denseit(w)); + n=IC(w); t=AT(w); p=q=0; b=0; k=n?aii(w)*bp(t):0; + if(!AN(w)){GA(z,BOX,n?1:0,1,0); if(n)RZ(*AAV(z)=IX(n)); R z;} + if(2>=k)q=t&B01?(1==k?2:258):t&LIT?(1==k?256:65536):t&C2T?65536:0; + if(k==SZI&&t&INT+SBT)irange(n,AV(w),&p,&q); + if(b=q&&(2>=k||q<=2*n)){ + GA(c,INT,q,1,0); cv=AV(c)-p; /* counts */ + GA(d,INT,q,1,0); dv=AV(d)-p; /* indices */ + wv=AV(w); v=dv+p; DO(q, *v++=-1;); + switch(k){ + case 1: GRPCD(UC); break; + case 2: GRPCD(US); break; + case SZI: GRPCD(I); + }}else{ + RZ(w=indexof(w,w)); wv=AV(w); + GA(c,INT,n,1,0); cv=AV(c); + m=-1; v=wv; DO(n, j=*v++; if(m>=j)++cv[j]; else{m=j; cv[j]=1; ++zn;}); + } + GA(z,BOX,zn,1,0); zv=AAV(z); + m=-1; cu=(I**)cv; + switch(b*k){ + case 1: GRPIX(UC,dv[k=*v++],j,k); break; + case 2: GRPIX(US,dv[k=*v++],j,k); break; + case SZI: GRPIX(I ,dv[k=*v++],j,k); break; + default: GRPIX(I , *v++ ,j,j); + } + EPILOG(z); +} /* (</. i.@#) w */ + + +static DF2(jtkeytally); + +static F1(jtkeytallysp){PROLOG;A b,e,q,x,y,z;I c,d,j,k,*u,*v;P*p; + RZ(w); + RZ(q=indexof(w,w)); + p=PAV(q); + x=SPA(p,x); u=AV(x); c=AN(x); + y=SPA(p,i); v=AV(y); + e=SPA(p,e); k=i0(e); + j=0; DO(c, if(k<=u[i])break; if(u[i]==v[i])++j;); + RZ(b=ne(e,x)); + RZ(x=repeat(b,x)); RZ(x=keytally(x,x,mark)); u=AV(x); d=AN(x); + GA(z,INT,1+d,1,0); v=AV(z); + DO(j, *v++=*u++;); *v++=IC(w)-bsum(c,BAV(b)); DO(d-j, *v++=*u++;); + EPILOG(z); +} /* x #/.y , sparse x */ + +#define KEYTALLY(T) {T*u; \ + u=(T*)av; DO(n, ++*(qv+*u++);); \ + u=(T*)av; DO(n, v=qv+*u++; if(*v){*zv++=*v; *v=0; if(s==++j)break;});} + +static DF2(jtkeytally){PROLOG;A q;I at,*av,j=0,k,n,r=0,s=0,*qv,*u,*v; + RZ(a&&w); + n=IC(a); at=AT(a); av=AV(a); + ASSERT(n==IC(w),EVLENGTH); + if(!AN(a))R vec(INT,n?1:0,&n); + if(at&SPARSE)R keytallysp(a); + at=keyrs(a,&r,&s); + if(n&&at&B01&&1>=AR(a)){B*b=(B*)av; k=bsum(n,b); R !k||n==k?vci(k?k:n):v2(*b?k:n-k,*b?n-k:k);} + if(s&&s<=MAX(2*n,65536)){A z;I*zv; + GA(z,INT,s,1,0); zv=AV(z); + GA(q,INT,s,1,0); qv=AV(q)-r; + u=qv+r; DO(s, *u++=0;); + switch(at){ + case LIT: KEYTALLY(UC); break; + case C2T: KEYTALLY(US); break; + case INT: KEYTALLY(I ); + } + AN(z)=*AS(z)=j; + EPILOG(z); + } + RZ(q=indexof(a,a)); + if(!AR(q))R iv1; + v=qv=AV(q); + u=qv; DO(n, ++*(qv+*u++);); + u=qv; DO(n, k=*u++; if(i<k){j+=*v++=k-i; if(n==j)break;}); + *AS(q)=AN(q)=v-qv; + EPILOG(q); +} /* x #/.y main control & dense x */ + + +#define KEYHEADTALLY(Tz,Ta,Tw,exp0,exp1) \ + {Ta*u;Tw*wv=(Tw*)AV(w);Tz*zz=(Tz*)zv; \ + u=(Ta*)av; DO(n, ++*(qv+*u++);); \ + u=(Ta*)av; DO(n, v=qv+*u++; if(*v){*zz++=exp0; *zz++=exp1; k+=*v; if(n==k)break; *v=0;}); \ + AN(z)=zz-(Tz*)zv; \ + } + +static DF2(jtkeyheadtally){PROLOG;A f,q,x,y,z;B b;I at,*av,k,n,r=0,s=0,*qv,*u,*v,wt,*zv; + RZ(a&&w); + n=IC(a); wt=AT(w); + ASSERT(n==IC(w),EVLENGTH); + ASSERT(!n||wt&NUMERIC,EVDOMAIN); + if(SPARSE&AT(a)||1<AR(w)||!n||!AN(a))R key(a,w,self); + at=keyrs(a,&r,&s); av=AV(a); + f=VAV(self)->f; f=VAV(f)->f; b=CHEAD==ID(f); + if(at&B01&&1>=AR(a)){B*c,*d,*p=(B*)av;I i,j,m; + c=d=p; + if(*p){i=0; d=(B*)memchr(p,C0,n); j=d?d-p:0;} + else {j=0; c=(B*)memchr(p,C1,n); i=c?c-p:0;} + k=bsum(n,p); m=c&&d?2:1; + GA(x,INT,m,1,0); v=AV(x); *v++=MIN(i,j); if(c&&d)*v=MAX(i,j); + GA(y,INT,m,1,0); v=AV(y); *v++=i<j||!d?k:n-k; if(c&&d)*v=i<j?n-k:k; + R stitch(b?from(x,w):y,b?y:from(x,w)); + } + if(at&LIT+C2T+INT&&wt&B01+INT+FL&&s&&s<=MAX(2*n,65536)){ + GA(z,wt&FL?FL:INT,2*s,2,0); zv=AV(z); + GA(q,INT,s,1,0); qv=AV(q)-r; + u=qv+r; DO(s, *u++=0;); k=0; + switch(9*b+(at&INT?6:at&C2T?3:0)+(wt&FL?2:wt&INT?1:0)){ + case 0: KEYHEADTALLY(I,UC,B,*v, wv[i]); break; + case 1: KEYHEADTALLY(I,UC,I,*v, wv[i]); break; + case 2: KEYHEADTALLY(D,UC,D,(D)*v,wv[i]); break; + case 3: KEYHEADTALLY(I,US,B,*v, wv[i]); break; + case 4: KEYHEADTALLY(I,US,I,*v, wv[i]); break; + case 5: KEYHEADTALLY(D,US,D,(D)*v,wv[i]); break; + case 6: KEYHEADTALLY(I,I ,B,*v, wv[i]); break; + case 7: KEYHEADTALLY(I,I ,I,*v, wv[i]); break; + case 8: KEYHEADTALLY(D,I ,D,(D)*v,wv[i]); break; + case 9: KEYHEADTALLY(I,UC,B,wv[i],*v ); break; + case 10: KEYHEADTALLY(I,UC,I,wv[i],*v ); break; + case 11: KEYHEADTALLY(D,UC,D,wv[i],(D)*v); break; + case 12: KEYHEADTALLY(I,US,B,wv[i],*v ); break; + case 13: KEYHEADTALLY(I,US,I,wv[i],*v ); break; + case 14: KEYHEADTALLY(D,US,D,wv[i],(D)*v); break; + case 15: KEYHEADTALLY(I,I ,B,wv[i],*v ); break; + case 16: KEYHEADTALLY(I,I ,I,wv[i],*v ); break; + case 17: KEYHEADTALLY(D,I ,D,wv[i],(D)*v); break; + } + *AS(z)=AN(z)/2; *(1+AS(z))=2; + }else{ + RZ(q=indexof(a,a)); + x=repeat(eq(q,IX(n)),w); y=keytally(q,q,0L); z=stitch(b?x:y,b?y:x); + } + EPILOG(z); +} /* x ({.,#)/.y or x (#,{.)/.y */ + + +F1(jtsldot){A h=0;AF f1=jtoblique,f2=jtkey;C c,d,e;I flag=0;V*v; + RZ(w); + if(NOUN&AT(w)){flag=VGERL; RZ(h=fxeachv(1L,w));} + else{ + v=VAV(w); + switch(ID(w)){ + case CPOUND: f2=jtkeytally; break; + case CSLASH: f2=jtkeyslash; if(vaid(v->f))f1=jtobqfslash; break; + case CBOX: f2=jtkeybox; break; + case CFORK: if(v->f1==(AF)jtmean){f2=jtkeymean; break;} + c=ID(v->f); d=ID(v->g); e=ID(v->h); + if(d==CCOMMA&&(c==CHEAD&&e==CPOUND||c==CPOUND&&e==CHEAD))f2=jtkeyheadtally; + }} + R fdef(CSLDOT,VERB, f1,f2, w,0L,h, flag, RMAX,RMAX,RMAX); +}
new file mode 100644 --- /dev/null +++ b/ap.c @@ -0,0 +1,540 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Prefix and Infix */ + +#include "j.h" +#include "vasm.h" +#include "ve.h" + + +#define MINUSPA(b,r,u,v) r=b?u-v:u+v; +#define MINUSPZ(b,r,u,v) if(b)r=zminus(u,v); else r=zplus(u,v); +#define MINUSPX(b,r,u,v) if(b)r=xminus(u,v); else r=xplus(u,v); +#define MINUSPQ(b,r,u,v) if(b)r=qminus(u,v); else r=qplus(u,v); + +#define DIVPA(b,r,u,v) r=b?(!u&&!v?0:u/(D)v):u*v; +#define DIVPZ(b,r,u,v) if(b)r=zdiv(u,v); else r=ztymes(u,v); + +#define PREFIXPFX(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){I d=c/n,i;Tz v,*y; \ + if(1==d)DO(m, *z++=v= *x++; DO(n-1, *z=v=pfx(v,*x); ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++= *x++;); \ + DO(n-1, DO(d, *z=pfx(*y,*x); ++z; ++x; ++y;)); \ + }} /* for associative functions only */ + +#define PREFIXNAN(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){I d=c/n,i;Tz v,*y; \ + NAN0; \ + if(1==d)DO(m, *z++=v= *x++; DO(n-1, *z=v=pfx(v,*x); ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++= *x++;); \ + DO(n-1, DO(d, *z=pfx(*y,*x); ++z; ++x; ++y;)); \ + } \ + NAN1V; \ + } /* for associative functions only */ + +#define PREFICPFX(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){I d=c/n,i;Tz v,*y; \ + if(1==d)DO(m, *z++=v=(Tz)*x++; DO(n-1, *z=v=pfx(v,*x); ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++=(Tz)*x++;); \ + DO(n-1, DO(d, *z=pfx(*y,*x); ++z; ++x; ++y;)); \ + }} /* for associative functions only */ + +#define PREFIXALT(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){B b;I d=c/n,i;Tz v,*y; \ + if(1==d)DO(m, *z++=v= *x++; b=0; DO(n-1, b=!b; pfx(b,*z,v,*x); v=*z; ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++= *x++;); b=0; \ + DO(n-1, b=!b; DO(d, pfx(b,*z,*y,*x); ++z; ++x; ++y;)); \ + }} + +#define PREALTNAN(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){B b;I d=c/n,i;Tz v,*y; \ + NAN0; \ + if(1==d)DO(m, *z++=v= *x++; b=0; DO(n-1, b=!b; pfx(b,*z,v,*x); v=*z; ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++= *x++;); b=0; \ + DO(n-1, b=!b; DO(d, pfx(b,*z,*y,*x); ++z; ++x; ++y;)); \ + } \ + NAN1V; \ + } + +#define PREFICALT(f,Tz,Tx,pfx) \ + AHDRP(f,Tz,Tx){B b;I d=c/n,i;Tz v,*y; \ + if(1==d)DO(m, *z++=v=(Tz)*x++; b=0; DO(n-1, b=!b; pfx(b,*z,v,*x); v=*z; ++z; ++x;)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++=(Tz)*x++;); b=0; \ + DO(n-1, b=!b; DO(d, pfx(b,*z,*y,*x); ++z; ++x; ++y;)); \ + }} + +#define PREFIXOVF(f,Tz,Tx,fp1,fvv) \ + AHDRP(f,I,I){C er=0;I d=c/n,i,*xx=x,*y,*zz=z; \ + if(1==d){ \ + if(1==n)DO(m, *z++=*x++;) \ + else DO(m, fp1(n,z,x); RER; z=zz+=c; x=xx+=c;) \ + }else for(i=0;i<m;++i){ \ + y=z; DO(d, *z++=*x++;); zz=z; xx=x; \ + DO(n-1, fvv(d,z,y,x); RER; x=xx+=d; y=zz; z=zz+=d;); \ + }} + + +#if SY_ALIGN +#define PREFIXBFXLOOP(T,pfx) \ + {T*xx=(T*)x,*yy,*zz=(T*)z; \ + q=d/sizeof(T); \ + DO(m, yy=zz; DO(q, *zz++=*xx++;); DO(n-1, DO(q, *zz++=pfx(*yy,*xx); ++xx; ++yy;))); \ + } + +#define PREFIXBFX(f,pfx,ipfx,spfx,bpfx,vexp) \ + AHDRP(f,B,B){B*y;I d=c/n,j,q; \ + if(1==d)for(j=0;j<m;++j){vexp} \ + else if(0==d%sizeof(UI ))PREFIXBFXLOOP(UI, pfx) \ + else if(0==d%sizeof(UINT))PREFIXBFXLOOP(UINT,ipfx) \ + else if(0==d%sizeof(US ))PREFIXBFXLOOP(US, spfx) \ + else DO(m, y=z; DO(d, *z++=*x++;); DO(n-1, DO(d, *z++=bpfx(*y,*x); ++x; ++y;))); \ + } /* f/\"r z for boolean associative atomic function f */ +#else +#define PREFIXBFX(f,pfx,ipfx,spfx,bpfx,vexp) \ + AHDRP(f,B,B){B*tv;I d,i,q,r,t,*xi,*yi,*zi; \ + d=c/n; q=d/SZI; r=d%SZI; xi=(I*)x; zi=(I*)z; tv=(B*)&t; \ + if(1==d) for(r=0;r<m;++r){vexp} \ + else if(!r)for(i=0;i<m;++i){ \ + yi=zi; DO(q, *zi++=*xi++;); \ + DO(n-1, DO(q, *zi=pfx(*yi,*xi); ++zi; ++xi; ++yi;)); \ + }else for(i=0;i<m;++i){ \ + yi=zi; MC(zi,xi,d); \ + xi=(I*)((B*)xi+d); \ + zi=(I*)((B*)zi+d); \ + DO(n-1, DO(q, *zi=pfx(*yi,*xi); ++zi; ++xi; ++yi;); \ + t=pfx(*yi,*xi); z=(B*)zi; DO(r, z[i]=tv[i];); \ + xi=(I*)(r+(B*)xi); \ + yi=(I*)(r+(B*)yi); \ + zi=(I*)(r+(B*)zi); ); \ + }} /* f/\"r z for boolean associative atomic function f */ +#endif + +#define BFXANDOR(c0,c1) \ + {B*y=memchr(x,c0,n); if(y){q=y-x; memset(z,c1,q); memset(z+q,c0,n-q);}else memset(z,c1,n); x+=c; z+=c;} + +PREFIXBFX( orpfxB, OR, IOR, SOR, BOR, BFXANDOR(C1,C0)) +PREFIXBFX(andpfxB, AND,IAND,SAND,BAND, BFXANDOR(C0,C1)) +PREFIXBFX( nepfxB, NE, INE, SNE, BNE, {B b=0; DO(n, *z++=b^= *x++;);}) +PREFIXBFX( eqpfxB, EQ, IEQ, SEQ, BEQ, {B b=1; DO(n, *z++=b=b==*x++;);}) + + +static B jtpscanlt(J jt,I m,I c,I n,B*z,B*x,B p){A t;B*v;I d,i; + d=c/n; memset(z,!p,m*c); + if(1==d)DO(m, if(v=memchr(x,p,n))*(z+(v-x))=p; z+=c; x+=c;) + else{ + GA(t,B01,d,1,0); v=BAV(t); + for(i=0;i<m;++i){ + memset(v,C1,d); + DO(n, DO(d, if(v[i]&&p==x[i]){v[i]=0; z[i]=p;};); z+=d; x+=d;); + }} + R 1; +} /* f/\"1 w for < and <: */ + +AHDRP(ltpfxB,B,B){pscanlt(m,c,n,z,x,C1);} +AHDRP(lepfxB,B,B){pscanlt(m,c,n,z,x,C0);} + + +static B jtpscangt(J jt,I m,I c,I n,B*z,B*x,B a,B pp,B pa,B ps){ + A t;B b,*cc="\000\001\000",e,*p=cc+pp,*v;C*u;I d,i,j; + if(c==n)for(i=0;i<m;++i){ + if(v=memchr(x,a,n)){ + j=v-x; b=1&&j%2; + mvc(j,z,2L,p); memset(z+j,b!=ps,n-j); *(z+j)=b!=pa; + }else mvc(n,z,2L,p); + z+=c; x+=c; + }else{ + d=c/n; GA(t,B01,d,1,0); u=BAV(t); + for(i=0;i<m;++i){ + e=pp; memset(u,C0,d); + DO(n, j=i; DO(d, if(u[i])z[i]='1'==u[i]; else + if(a==x[i]){b=1&&j%2; z[i]=b!=pa; u[i]=b!=ps?'1':'0';}else z[i]=e;); + e=!e; z+=d; x+=d;); + }} + R 1; +} /* f/\"1 w for > >: +: *: */ + +AHDRP( gtpfxB,B,B){pscangt(m,c,n,z,x,C0,C1,C0,C0);} +AHDRP( gepfxB,B,B){pscangt(m,c,n,z,x,C1,C0,C1,C1);} +AHDRP( norpfxB,B,B){pscangt(m,c,n,z,x,C1,C0,C1,C0);} +AHDRP(nandpfxB,B,B){pscangt(m,c,n,z,x,C0,C1,C0,C1);} + + +PREFIXOVF( pluspfxI, I, I, PLUSP, PLUSVV) +PREFIXOVF(tymespfxI, I, I, TYMESP,TYMESVV) + +AHDRP(minuspfxI,I,I){C er=0;I d=c/n,i,j,n1=n-1,*xx=x,*y,*zz=z; + if(1==d){ + if(1==n)DO(m, *z++=*x++;) + else DO(m, MINUSP(n,z,x); RER; z=zz+=c; x=xx+=c;); + }else for(i=0;i<m;++i){ + y=z; DO(d, *z++=*x++;); zz=z; xx=x; j=0; + DO(n1, MINUSVV(d,z,y,x); RER; x=xx+=d; y=zz; z=zz+=d; if(n1<=++j)break; + PLUSVV(d,z,y,x); RER; x=xx+=d; y=zz; z=zz+=d; if(n1<=++j)break;); +}} + +PREFICPFX( pluspfxO, D, I, PLUS ) +PREFICPFX(tymespfxO, D, I, TYMES ) +PREFICALT(minuspfxO, D, I, MINUSPA) + +PREFIXPFX( pluspfxB, I, B, PLUS ) +PREFIXNAN( pluspfxD, D, D, PLUS ) +PREFIXNAN( pluspfxZ, Z, Z, zplus ) +PREFIXPFX( pluspfxX, X, X, xplus ) +PREFIXPFX( pluspfxQ, Q, Q, qplus ) + +PREFIXPFX(tymespfxD, D, D, TYMES ) +PREFIXPFX(tymespfxZ, Z, Z, ztymes ) +PREFIXPFX(tymespfxX, X, X, xtymes ) +PREFIXPFX(tymespfxQ, Q, Q, qtymes ) + +PREFIXALT(minuspfxB, I, B, MINUSPA) +PREALTNAN(minuspfxD, D, D, MINUSPA) +PREALTNAN(minuspfxZ, Z, Z, MINUSPZ) +PREFIXALT(minuspfxX, X, X, MINUSPX) +PREFIXALT(minuspfxQ, Q, Q, MINUSPQ) + +PREALTNAN( divpfxD, D, D, DIVPA ) +PREALTNAN( divpfxZ, Z, Z, DIVPZ ) + +PREFIXPFX( maxpfxI, I, I, MAX ) +PREFIXPFX( maxpfxD, D, D, MAX ) +PREFIXPFX( maxpfxX, X, X, XMAX ) +PREFIXPFX( maxpfxQ, Q, Q, QMAX ) +PREFIXPFX( maxpfxS, SB,SB, SBMAX ) + +PREFIXPFX( minpfxI, I, I, MIN ) +PREFIXPFX( minpfxD, D, D, MIN ) +PREFIXPFX( minpfxX, X, X, XMIN ) +PREFIXPFX( minpfxQ, Q, Q, QMIN ) +PREFIXPFX( minpfxS, SB,SB, SBMIN ) + +PREFIXPFX(bw0000pfxI, UI,UI, BW0000) +PREFIXPFX(bw0001pfxI, UI,UI, BW0001) +PREFIXPFX(bw0011pfxI, UI,UI, BW0011) +PREFIXPFX(bw0101pfxI, UI,UI, BW0101) +PREFIXPFX(bw0110pfxI, UI,UI, BW0110) +PREFIXPFX(bw0111pfxI, UI,UI, BW0111) +PREFIXPFX(bw1001pfxI, UI,UI, BW1001) +PREFIXPFX(bw1111pfxI, UI,UI, BW1111) + + +static DF1(jtprefix){DECLF;I r; + RZ(w); + if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,r,jtprefix);} + jt->rank=0; + R eachl(apv(IC(w),1L,1L),w,atop(fs,ds(CTAKE))); +} /* f\"r w for general f */ + +static DF1(jtgprefix){A h,*hv,z,*zv;I m,n,r; + RZ(w); + ASSERT(DENSE&AT(w),EVNONCE); + if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,r,jtgprefix);} + jt->rank=0; + n=IC(w); + h=VAV(self)->h; hv=AAV(h); m=AN(h); + GA(z,BOX,n,1,0); zv=AAV(z); + DO(n, RZ(zv[i]=df1(take(sc(1+i),w),hv[i%m]));); + R ope(z); +} /* g\"r w for gerund g */ + +static DF1(jtpscan){A y,z;C id;I c,cv,f,m,n,r,rr[2],t,wn,wr,*ws,wt,zt;VF ado; + RZ(w); + wt=AT(w); + if(SPARSE&wt)R scansp(w,self,jtpscan); + wn=AN(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; ws=AS(w); + m=prod(f,ws); c=m?AN(w)/m:prod(r,f+ws); n=r?ws[f]:1; + y=VAV(self)->f; id=vaid(VAV(y)->f); + if(2>n||!wn){if(id){jt->rank=0; R r?ca(w):reshape(over(shape(w),one),w);}else R prefix(w,self);} + vapfx(id,wt,&ado,&cv); + if(!ado)R prefix(w,self); + if((t=atype(cv))&&t!=wt)RZ(w=cvt(t,w)); + zt=rtype(cv); jt->rank=0; + GA(z,zt,wn,wr,ws); + ado(jt,m,c,n,AV(z),AV(w)); + if(jt->jerr)R jt->jerr==EWOV?(rr[1]=r,jt->rank=rr,pscan(w,self)):0; else R cv&VRI+VRD?cvz(cv,z):z; +} /* f/\"r w atomic f main control */ + + +static F2(jtseg){A z;I c,k,m,n,*u,zn; + RZ(a&&w); + if(INT&AT(a)){u=AV(a); m=*u; n=*(1+u);} else m=n=0; + c=aii(w); k=c*bp(AT(w)); RE(zn=mult(n,c)); + GA(z,AT(w),zn,MAX(1,AR(w)),AS(w)); *AS(z)=n; + if(ARELATIVE(w)){A*u=AAV(z),*v=AAV(w)+m; DO(n, *u++=(A)AABS(w,*v++););} + else MC(AV(z),CAV(w)+m*k,n*k); + R z; +} + +static A jtifxi(J jt,I m,A w){A z;I d,j,k,n,p,*x; + RZ(w); + p=ABS(m); n=IC(w); d=0>m?(I)((n+(D)p-1)/p):MAX(0,1+n-m); + GA(z,INT,2*d,2,0); *AS(z)=d; *(1+AS(z))=2; + x=AV(z); k=0>m?p:1; j=-k; DO(d, *x++=j+=k; *x++=p;); if(d)*--x=MIN(p,n-j); + R z; +} + +static DF2(jtinfix){PROLOG;DECLF;A x,z;I m; + PREF2(jtinfix); + if(a==ainf)R repeat(zero,w); + RE(m=i0(vib(a))); + RZ(x=ifxi(m,w)); + if(*AS(x))z=eachl(x,w,atop(fs,ac2(jtseg))); + else{A s;I r; + r=AR(w); r=MAX(0,r); GA(s,INT,r,1,0); if(r)ICPY(AV(s),AS(w),r); *AV(s)=0>m?0:m; + RZ(x=df1(reshape(s,filler(w)),fs)); + z=reshape(over(zero,shape(x)),x); + } + EPILOG(z); +} + +static DF2(jtinfix2){PROLOG;A f,x,y;B d;I c,m,n,n1,r,*s,t; + PREF2(jtinfix); + RE(m=i0(vib(a))); t=AT(w); n=IC(w); + if(!(2==m&&2<=n&&t&DENSE))R infix(a,w,self); + c=AN(w)/n; d=1&&t&DIRECT; r=AR(w); s=AS(w); n1=n-1; + if(d ){RZ(x=gah(r,w)); ICPY(AS(x),s,r); *AS(x)=n1; AN(x)=c*n1;} + else RZ(x=curtail(w)); + if(d&!(t&IS1BYTE)){RZ(y=gah(r,w)); ICPY(AS(y),s,r); *AS(y)=n1; AN(y)=c*n1; AK(y)=AK(w)+(I)w+c*bp(t)-(I)y;} + else RZ(y= behead(w)); + f=VAV(self)->f; f=VAV(f)->f; + EPILOG(df2(x,y,vaid(f)?f:qq(f,num[-1]))); +} /* 2 f/\w */ + +static DF2(jtginfix){A h,*hv,x,z,*zv;I d,m,n; + RE(m=i0(vib(a))); + RZ(x=ifxi(m,w)); + h=VAV(self)->h; hv=AAV(h); d=AN(h); + if(n=IC(x)){ + GA(z,BOX,n,1,0); zv=AAV(z); + DO(n, RZ(zv[i]=df1(seg(from(sc(i),x),w),hv[i%d]));); + R ope(z); + }else{A s; + RZ(s=AR(w)?shape(w):ca(iv0)); *AV(s)=ABS(m); + RZ(x=df1(reshape(s,filler(w)),*hv)); + R reshape(over(zero,shape(x)),x); +}} + +#define MCREL(uu,vv,n) {A*u=(A*)(uu),*v=(A*)(vv); DO((n), *u++=(A)AABS(wd,*v++););} + +static DF2(jtinfixd){A fs,z;C*x,*y;I c=0,d,k,m,n,p,q,r,*s,wd,wr,*ws,wt,zc; + F2RANK(0,RMAX,jtinfixd,self); + wr=AR(w); ws=AS(w); wt=AT(w); n=IC(w); + RE(m=i0(a)); p=m==IMIN?IMAX:ABS(m); + if(0>m){p=MIN(p,n); d=p?(n+p-1)/p:0;}else{ASSERT(IMAX-1>n-m,EVDOMAIN); d=MAX(0,1+n-m);} + if(fs=VAV(self)->f,CCOMMA==ID(fs)){RE(c=aii(w)); RE(zc=mult(p,c)); r=2;} + else{if(n)RE(c=aii(w)); zc=p; r=wr?1+wr:2;} + GA(z,wt,d*p*c,r,0); x=CAV(z); y=CAV(w); + s=AS(z); *s++=d; *s++=zc; ICPY(s,1+ws,r-2); + k=c*bp(wt); wd=(I)w*ARELATIVE(w); + if(AN(z))switch((0>m?2:0)+(wd?1:0)){ + case 0: q=p*k; DO(d, MC(x,y,q); x+=q; y+=k;); break; + case 1: q=p*k; DO(d, MCREL(x,y,p); x+=q; y+=k;); break; + case 2: MC(x,y,n*k); if(q=d*p-n)fillv(wt,q*c,x+n*k); break; + case 3: MCREL(x,y,n); if(q=d*p-n)fillv(wt,q*c,x+n*k); break; + } + R z; +} /* a[\w and a]\w and a,\w */ + + +#define SETZ {s=yv; DO(c, *zv++=*s++; );} +#define SETZD {s=yv; DO(c, *zv++=*s++/d;);} + +#define MOVSUMAVG(Tw,Ty,ty,Tz,tz,xd,SET) \ + {Tw*u,*v;Ty*s,x=0,*yv;Tz*zv; \ + GA(z,tz,c*(1+p),AR(w),AS(w)); *AS(z)=1+p; \ + zv=(Tz*)AV(z); u=v=(Tw*)AV(w); \ + if(1==c){ \ + DO(m, x+=*v++;); *zv++=xd; \ + DO(p, x+=(Ty)*v++-(Ty)*u++; *zv++=xd;); \ + }else{ \ + GA(y,ty,c,1,0); s=yv=(Ty*)AV(y); DO(c, *s++=0;); \ + DO(m, s=yv; DO(c, *s+++=*v++;);); SET; \ + DO(p, s=yv; DO(c, x=*s+++=(Ty)*v++-(Ty)*u++; *zv++=xd;);); \ + }} + +static A jtmovsumavg1(J jt,I m,A w,A fs,B avg){A y,z;D d=(D)m;I c,p,s,t,wt; + p=IC(w)-m; wt=AT(w); c=aii(w); + switch((wt&B01?0:wt&INT?2:4)+avg){ + case 0: MOVSUMAVG(B,I,INT,I,INT,x, SETZ ); break; + case 1: MOVSUMAVG(B,I,INT,D,FL, x/d,SETZD); break; + case 2: + irange(AN(w),AV(w),&s,&t); t=0<t&&IMAX>=d*((D)s+(D)t); + if(t) MOVSUMAVG(I,I,INT,I,INT,x, SETZ ) + else MOVSUMAVG(I,D,FL, D,FL, x, SETZ ); break; + case 3: MOVSUMAVG(I,D,FL, D,FL, x/d,SETZD); break; + case 4: NAN0; MOVSUMAVG(D,D,FL, D,FL, x, SETZ ); NAN1; break; + case 5: NAN0; MOVSUMAVG(D,D,FL, D,FL, x/d,SETZD); NAN1; break; + } + R z; +} /* m +/\w or (if 0=avg) m (+/%#)\w (if 1=avg); bool or integer or float; 0<m */ + +static A jtmovsumavg(J jt,I m,A w,A fs,B avg){A z; + z=movsumavg1(m,w,fs,avg); + if(jt->jerr==EVNAN)RESETERR else R z; + R infix(sc(m),w,fs); +} + +static DF2(jtmovavg){I m; + PREF2(jtmovavg); + RE(m=i0(vib(a))); + if(0<m&&m<=IC(w)&&AT(w)&B01+FL+INT)R movsumavg(m,w,self,1); + R infix(a,w,self); +} /* a (+/ % #)\w */ + +#define MOVMINMAX(T,type,ie,CMP) \ + {T d,e,*s,*t,*u,*v,x=ie,*yv,*zv; \ + zv=(T*)AV(z); u=v=(T*)AV(w); \ + if(1==c){ \ + DO(m, d=*v++; if(d CMP x)x=d;); *zv++=x; \ + for(i=0;i<p;++i){ \ + d=*v++; e=*u++; \ + if(d CMP x)x=d; else if(e==x){x=d; t=u; DO(m-1, e=*t++; if(e CMP x)x=e;);} \ + *zv++=x; \ + }}else{ \ + GA(y,type,c,1,0); s=yv=(T*)AV(y); DO(c, *s++=ie;); \ + DO(m, s=yv; DO(c, d=*v++; if(d CMP *s)*s=d; ++s;);); SETZ; \ + for(i=0;i<p;++i){ \ + for(j=0,s=yv;j<c;++j,++s){ \ + d=*v++; e=*u++; x=*s; \ + if(d CMP x)x=d; else if(e==x){x=d; t=c+u-1; DO(m-1, e=*t; t+=c; if(e CMP x)x=e;);} \ + *s=x; \ + } \ + SETZ; \ + }}} + +static A jtmovminmax(J jt,I m,A w,A fs,B max){A y,z;I c,i,j,p,wt; + p=IC(w)-m; wt=AT(w); c=aii(w); + GA(z,AT(w),c*(1+p),AR(w),AS(w)); *AS(z)=1+p; + switch(max+(wt&INT?0:2)){ + case 0: MOVMINMAX(I,INT,IMAX,<=); break; + case 1: MOVMINMAX(I,INT,IMIN,>=); break; + case 2: MOVMINMAX(D,FL, inf ,<=); break; + case 3: MOVMINMAX(D,FL, infm,>=); + } + R z; +} /* a <./\w (0=max) or a >./\ (1=max); vector w; integer or float; 0<m */ + +static A jtmovandor(J jt,I m,A w,A fs,B or){A y,z;B b0,b1,d,e,*s,*t,*u,*v,x,*yv,*zv;I c,i,j,p; + p=IC(w)-m; c=aii(w); x=b0=!or; b1=or; + GA(z,B01,c*(1+p),AR(w),AS(w)); *AS(z)=1+p; + zv=BAV(z); u=v=BAV(w); + if(1==c){ + DO(m, if(b1==*v++){x=b1; break;}); *zv++=x; v=u+m; + for(i=0;i<p;++i){ + d=*v++; e=*u++; + if(d==b1)x=d; else if(e==b1){x=d; t=u; DO(m-1, if(b1==*t++){x=b1; break;});} + *zv++=x; + }}else{ + GA(y,B01,c,1,0); s=yv=BAV(y); DO(c, *s++=b0;); + DO(m, s=yv; DO(c, if(b1==*v++)*s=b1; ++s;);); SETZ; + for(i=0;i<p;++i){ + for(j=0,s=yv;j<c;++j,++s){ + d=*v++; e=*u++; x=*s; + if(d==b1)x=d; else if(e==b1){x=d; t=c+u-1; DO(m-1, e=*t; t+=c; if(b1==e){x=b1; break;});} + *s=x; + } + SETZ; + }} + R z; +} /* a *./\w (0=or) or a +./\ (1=or); boolean w; 0<m */ + +static A jtmovbwandor(J jt,I m,A w,A fs,B or){A z;I c,p,*s,*t,*u,x,*zv; + p=IC(w)-m; c=aii(w); + GA(z,INT,c*(1+p),AR(w),AS(w)); *AS(z)=1+p; + zv=AV(z); u=AV(w); + if(c)switch(or+(1==c?0:2)){ + case 0: DO(1+p, x=*u++; t=u; DO(m-1, x&=*t++;); *zv++=x;); break; + case 1: DO(1+p, x=*u++; t=u; DO(m-1, x|=*t++;); *zv++=x;); break; + case 2: DO(1+p, ICPY(zv,u,c); t=u+=c; DO(m-1, s=zv; DO(c, *s++&=*t++;);); zv+=c;); break; + case 3: DO(1+p, ICPY(zv,u,c); t=u+=c; DO(m-1, s=zv; DO(c, *s++|=*t++;);); zv+=c;); break; + } + R z; +} /* a 17 b./\w (0=or) or a 23 b./\ (1=or); integer w; 0<m */ + +static A jtmovneeq(J jt,I m,A w,A fs,B eq){A y,z;B*s,*u,*v,x,*yv,*zv;I c,p; + p=IC(w)-m; c=aii(w); x=eq; + GA(z,B01,c*(1+p),AR(w),AS(w)); *AS(z)=1+p; + zv=BAV(z); u=v=BAV(w); + if(1<c){GA(y,B01,c,1,0); s=yv=BAV(y); DO(c, *s++=eq;);} + switch(eq+(1<c?2:0)){ + case 0: DO(m, x ^= *v++; ); *zv++=x; DO(p, *zv++=x ^= *u++^ *v++; ); break; + case 1: DO(m, x =x==*v++; ); *zv++=x; DO(p, *zv++=x =x==*u++==*v++; ); break; + case 2: DO(m, s=yv; DO(c, *s++^= *v++;);); SETZ; DO(p, s=yv; DO(c, *zv++=*s++^= *u++^ *v++;);); break; + case 3: DO(m, s=yv; DO(c, x=*s; *s++ =x==*v++;);); SETZ; DO(p, s=yv; DO(c, x=*s; *zv++=*s++ =x==*u++==*v++;);); + } + R z; +} /* m ~:/\w (0=eq) or m =/\ (1=eq); boolean w; 0<m */ + +static A jtmovbwneeq(J jt,I m,A w,A fs,B eq){A y,z;I c,p,*s,*u,*v,x,*yv,*zv; + p=IC(w)-m; c=aii(w); x=eq?-1:0; + GA(z,INT,c*(1+p),AR(w),AS(w)); *AS(z)=1+p; + zv=AV(z); u=v=AV(w); + if(1<c){GA(y,INT,c,1,0); s=yv=AV(y); DO(c, *s++=x;);} + switch(eq+(1<c?2:0)){ + case 0: DO(m, x ^= *v++ ; ); *zv++=x; DO(p, *zv++=x ^= *u++^*v++ ; ); break; + case 1: DO(m, x =~(x^*v++); ); *zv++=x; DO(p, *zv++=x =~(x^~(*u++^*v++)); ); break; + case 2: DO(m, s=yv; DO(c, *s++^= *v++ ;);); SETZ; DO(p, s=yv; DO(c, *zv++=*s++^= *u++^*v++ ;);); break; + case 3: DO(m, s=yv; DO(c, x=*s; *s++ =~(x^*v++););); SETZ; DO(p, s=yv; DO(c, x=*s; *zv++=*s++ =~(x^~(*u++^*v++)););); + } + R z; +} /* m 22 b./\w (0=eq) or m 25 b./\ (1=eq); integer w; 0<m */ + +static DF2(jtmovfslash){A x,z;B b;C id,*wv,*zv;I c,cm,cv,d,m,m0,p,t,wk,wt,zk,zt;VF ado; + PREF2(jtmovfslash); + p=IC(w); wt=AT(w); + RE(m0=i0(vib(a))); m=0<=m0?m0:m0==IMIN?p:MIN(p,-m0); + if(2==m0)R infix2(a,w,self); + x=VAV(self)->f; x=VAV(x)->f; id=ID(x); + if(wt&B01)id=id==CMIN?CSTARDOT:id==CMAX?CPLUSDOT:id; + if(id==CBDOT&&(x=VAV(x)->f,INT&AT(x)&&!AR(x)))id=(C)*AV(x); + switch(0<m0&&m0<=IC(w)?id:0){ + case CPLUS: if(wt&B01+INT+FL)R movsumavg(m,w,self,0); break; + case CMIN: if(wt& INT+FL)R movminmax(m,w,self,0); break; + case CMAX: if(wt& INT+FL)R movminmax(m,w,self,1); break; + case CSTARDOT: if(wt&B01 )R movandor(m,w,self,0); break; + case CPLUSDOT: if(wt&B01 )R movandor(m,w,self,1); break; + case CNE: if(wt&B01 )R movneeq(m,w,self,0); break; + case CEQ: if(wt&B01 )R movneeq(m,w,self,1); break; + case CBW1001: if(wt& INT )R movbwneeq(m,w,self,1); break; + case CBW0110: if(wt& INT )R movbwneeq(m,w,self,0); + } + vains(id,wt,&ado,&cv); + if(!ado||!m||m>p)R infix(a,w,self); + d=0<=m0?1+p-m:(p+m-1)/m; c=aii(w); cm=c*m; b=0>m0&&0<p%m; + zt=rtype(cv); jt->rank=0; + GA(z,zt,c*d,AR(w),AS(w)); *AS(z)=d; + if((t=atype(cv))&&t!=wt){RZ(w=cvt(t,w)); wt=AT(w);} + zv=CAV(z); zk=bp(zt)*c; + wv=CAV(w); wk=bp(wt)*(0<=m0?c:c*m); + DO(d-b, ado(jt,1L,cm,m,zv,wv); zv+=zk; wv+=wk;); + if(b)ado(jt,1L,c*(p%m),p%m,zv,wv); + if(jt->jerr==EWOV){RESETERR; R movfslash(a,cvt(FL,w),self);}else R z; +} /* a f/\w */ + +static DF1(jtiota1){R apv(IC(w),1L,1L);} + +F1(jtbslash){A f;AF f1=jtprefix,f2=jtinfix;V*v; + RZ(w); + if(NOUN&AT(w))R fdef(CBSLASH,VERB, jtgprefix,jtginfix, w,0L,fxeachv(1L,w), VGERL, RMAX,0L,RMAX); + v=VAV(w); f=VAV(w)->f; + switch(v->id){ + case CPOUND: + f1=jtiota1; break; + case CLEFT: case CRIGHT: case CCOMMA: + f2=jtinfixd; break; + case CFORK: + if(v->f1==(AF)jtmean)f2=jtmovavg; break; + case CSLASH: + f2=jtmovfslash; if(vaid(f))f1=jtpscan; + } + R ADERIV(CBSLASH,f1,f2,RMAX,0L,RMAX); +} + +A jtascan(J jt,C c,A w){RZ(w); R df1(w,bslash(slash(ds(c))));}
new file mode 100644 --- /dev/null +++ b/ar.c @@ -0,0 +1,613 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Reduce (Insert) and Outer Product */ + +#include "j.h" +#include "vasm.h" +#include "ve.h" +#include "vcomp.h" +#include "ar.h" + +static DF1(jtreduce); + + +#define PARITY2 u=(UC*)&s; b=0; b^=*u++; b^=*u++; +#define PARITY4 u=(UC*)&s; b=0; b^=*u++; b^=*u++; b^=*u++; b^=*u++; +#define PARITY8 u=(UC*)&s; b=0; b^=*u++; b^=*u++; b^=*u++; b^=*u++; b^=*u++; b^=*u++; b^=*u++; b^=*u++; + +#if SY_64 +#define PARITYW PARITY8 +#else +#define PARITYW PARITY4 +#endif + +#if SY_ALIGN +#define VDONE(T,PAR) \ + {I q=n/sizeof(T);T s,*y=(T*)x; DO(m, s=0; DO(q, s^=*y++;); PAR; *z++=b==pc;);} + +static void vdone(I m,I n,B*x,B*z,B pc){B b,*u; + if(1==m){UI s,*xi; + s=0; b=0; + xi=(I*)x; DO(n/SZI, s^=*xi++;); + u=(B*)xi; DO(n%SZI, b^=*u++;); + u=(B*)&s; DO(SZI, b^=*u++;); + *z=b==pc; + }else if(0==n%sizeof(UI ))VDONE(UI, PARITYW) + else if(0==n%sizeof(UINT))VDONE(UINT,PARITY4) + else if(0==n%sizeof(US ))VDONE(US, PARITY2) + else DO(m, b=0; DO(n, b^=*x++;); *z++=b==pc;); +} +#else +static void vdone(I m,I n,B*x,B*z,B pc){B b;I q,r;UC*u;UI s,*y; + q=n/SZI; r=n%SZI; y=(UI*)x; + switch((r?2:0)+pc){ + case 0: DO(m, s=0; DO(q, s^=*y++;); PARITYW; *z++=!b;); break; + case 1: DO(m, s=0; DO(q, s^=*y++;); PARITYW; *z++= b;); break; + case 2: DO(m, s=0; DO(q, s^=*y++;); PARITYW; u=(UC*)y; DO(r, b^=*u++;); *z++=!b; x+=n; y=(UI*)x;); break; + case 3: DO(m, s=0; DO(q, s^=*y++;); PARITYW; u=(UC*)y; DO(r, b^=*u++;); *z++= b; x+=n; y=(UI*)x;); break; +}} +#endif + +#define RBFXLOOP(T,pfx) \ + {T*xx=(T*)x,*yy,*z0,*zz=(T*)z; \ + q=d/sizeof(T); \ + for(j=0;j<m;++j){ \ + yy=xx; xx-=q; z0=zz; DO(q, --xx; --yy; --zz; *zz=pfx(*xx,*yy);); \ + DO(n-2, zz=z0; DO(q, --xx; --zz; *zz=pfx(*xx,*zz););); \ + }} /* non-commutative */ + +#define RCFXLOOP(T,pfx) \ + {T*xx=(T*)x,*yy,*z0,*zz=(T*)z; \ + q=d/sizeof(T); \ + for(j=0;j<m;++j){ \ + yy=xx; xx+=q; z0=zz; DO(q, *zz++=pfx(*yy,*xx); ++xx; ++yy;); \ + DO(n-2, zz=z0; DO(q, *zz++=pfx(*zz,*xx); ++xx; );); \ + }} /* commutative */ + +#if SY_ALIGN +#define RBFXODDSIZE(pfx,bpfx) RBFXLOOP(C,bpfx) +#define REDUCECFX REDUCEBFX +#else +#define RBFXODDSIZE(pfx,bpfx) \ + {B*zz;I r,t,*xi,*yi,*zi; \ + q=d/SZI; r=d%SZI; xi=(I*)x; zz=z; \ + for(j=0;j<m;++j,zz-=d){ \ + yi=xi; xi=(I*)((B*)xi-d); zi=(I*)zz; \ + DO(q, --xi; --yi; *--zi=pfx(*xi,*yi);); \ + xi=(I*)((B*)xi-r); yi=(I*)((B*)yi-r); t=pfx(*xi,*yi); MC((B*)zi-r,&t,r); \ + DO(n-2, zi=(I*)zz; DO(q, --xi; --zi; *zi=pfx(*xi,*zi);); \ + xi=(I*)((B*)xi-r); zi=(I*)((B*)zi-r); t=pfx(*xi,*zi); MC( zi, &t,r);); \ + }} /* non-commutative */ + +#define RCFXODDSIZE(pfx,bpfx) \ + {I r,t,*xi,*yi,*zi; \ + q=d/SZI; r=d%SZI; \ + for(j=0;j<m;++j,x+=d,z+=d){ \ + yi=(I*)x; x+=d; xi=(I*)x; zi=(I*)z; DO(q, *zi++=pfx(*yi,*xi); ++xi; ++yi;); t=pfx(*yi,*xi); MC(zi,&t,r); \ + DO(n-2, x+=d; xi=(I*)x; zi=(I*)z; DO(q, *zi++=pfx(*zi,*xi); ++xi; ); t=pfx(*zi,*xi); MC(zi,&t,r);); \ + }} /* commutative */ + +#define REDUCECFX(f,pfx,ipfx,spfx,bpfx,vdo) \ + AHDRP(f,B,B){B*y=0;I d,j,q; \ + if(c==n){vdo; R;} \ + d=c/n; \ + if(1==n)DO(d, *z++=*x++;) \ + else if(0==d%sizeof(UI ))RCFXLOOP(UI, pfx) \ + else if(0==d%sizeof(UINT))RCFXLOOP(UINT,ipfx) \ + else if(0==d%sizeof(US ))RCFXLOOP(US, spfx) \ + else RCFXODDSIZE(pfx,bpfx) \ + } /* commutative */ + +#endif + +#define REDUCEBFX(f,pfx,ipfx,spfx,bpfx,vdo) \ + AHDRP(f,B,B){B*y=0;I d,j,q; \ + if(c==n){vdo; R;} \ + d=c/n; x+=m*c; z+=m*d; \ + if(1==n)DO(d, *--z=*--x;) \ + else if(0==d%sizeof(UI ))RBFXLOOP(UI, pfx) \ + else if(0==d%sizeof(UINT))RBFXLOOP(UINT,ipfx) \ + else if(0==d%sizeof(US ))RBFXLOOP(US, spfx) \ + else RBFXODDSIZE(pfx,bpfx) \ + } /* non-commutative */ + +REDUCECFX( eqinsB, EQ, IEQ, SEQ, BEQ, vdone(m,n,x,z,(B)(n%2))) +REDUCECFX( neinsB, NE, INE, SNE, BNE, vdone(m,n,x,z,1 )) +REDUCECFX( orinsB, OR, IOR, SOR, BOR, DO(m, *z++=1&&memchr(x,C1,n); x+=c;)) +REDUCECFX( andinsB, AND, IAND, SAND, BAND, DO(m, *z++=! memchr(x,C0,n); x+=c;)) +REDUCEBFX( ltinsB, LT, ILT, SLT, BLT, DO(m, *z++= *(x+n-1)&&!memchr(x,C1,n-1)?1:0; x+=c;)) +REDUCEBFX( leinsB, LE, ILE, SLE, BLE, DO(m, *z++=!*(x+n-1)&&!memchr(x,C0,n-1)?0:1; x+=c;)) +REDUCEBFX( gtinsB, GT, IGT, SGT, BGT, DO(m, y=memchr(x,C0,n); *z++=1&&(y?1&(y-x):1&n); x+=c;)) +REDUCEBFX( geinsB, GE, IGE, SGE, BGE, DO(m, y=memchr(x,C1,n); *z++=! (y?1&(y-x):1&n); x+=c;)) +REDUCEBFX( norinsB, NOR, INOR, SNOR, BNOR, DO(m, y=memchr(x,C1,n); d=y?y-x:n; *z++=(1&d)==d<n-1; x+=c;)) +REDUCEBFX(nandinsB, NAND,INAND,SNAND,BNAND,DO(m, y=memchr(x,C0,n); d=y?y-x:n; *z++=(1&d)!=d<n-1; x+=c;)) + + +#if SY_ALIGN +REDUCEPFX(plusinsB,I,B,PLUS) +#else +AHDRR(plusinsB,I,B){I d,dw,i,p,q,r,r1,s;UC*tu;UI*v; + if(c==n&&n<SZI)DO(m, s=0; DO(n, s+=*x++;); *z++=s;) + else if(c==n){UI t; + p=n/SZI; q=p/255; r=p%255; r1=n%SZI; tu=(UC*)&t; + for(i=0;i<m;++i){ + s=0; v=(UI*)x; + DO(q, t=0; DO(255, t+=*v++;); DO(SZI, s+=tu[i];)); + t=0; DO(r, t+=*v++;); DO(SZI, s+=tu[i];); + x=(B*)v; DO(r1, s+=*x++;); + *z++=s; + }}else{A t;UI*tv; + d=c/n; dw=(d+SZI-1)/SZI; p=dw*SZI; memset(z,C0,m*d*SZI); + q=n/255; r=n%255; + t=ga(INT,dw,1,0); if(!t)R; + tu=(UC*)AV(t); tv=(UI*)tu; v=(UI*)x; + for(i=0;i<m;++i,z+=d){ + DO(q, memset(tv,C0,p); DO(255, DO(dw,tv[i]+=v[i];); x+=d; v=(UI*)x;); DO(d,z[i]+=tu[i];)); + memset(tv,C0,p); DO(r, DO(dw,tv[i]+=v[i];); x+=d; v=(UI*)x;); DO(d,z[i]+=tu[i];) ; +}}} /* +/"r w on boolean w, originally by Roger Moore */ +#endif + + +REDUCEOVF( plusinsI, I, I, PLUSR, PLUSVV, PLUSRV) +REDUCEOVF(minusinsI, I, I, MINUSR,MINUSVV,MINUSRV) +REDUCEOVF(tymesinsI, I, I, TYMESR,TYMESVV,TYMESRV) + +REDUCCPFX( plusinsO, D, I, PLUSO) +REDUCCPFX(minusinsO, D, I, MINUSO) +REDUCCPFX(tymesinsO, D, I, TYMESO) + +REDUCENAN( plusinsD, D, D, PLUS ) +REDUCENAN( plusinsZ, Z, Z, zplus ) +REDUCEPFX( plusinsX, X, X, xplus ) + +REDUCEPFX(minusinsB, I, B, MINUS ) +REDUCENAN(minusinsD, D, D, MINUS ) +REDUCENAN(minusinsZ, Z, Z, zminus) + +REDUCEPFX(tymesinsD, D, D, TYMES ) +REDUCEPFX(tymesinsZ, Z, Z, ztymes) + +REDUCENAN( divinsD, D, D, DIV ) +REDUCENAN( divinsZ, Z, Z, zdiv ) + +REDUCEPFX( maxinsI, I, I, MAX ) +REDUCEPFX( maxinsD, D, D, MAX ) +REDUCEPFX( maxinsX, X, X, XMAX ) +REDUCEPFX( maxinsS, SB,SB,SBMAX ) + +REDUCEPFX( mininsI, I, I, MIN ) +REDUCEPFX( mininsD, D, D, MIN ) +REDUCEPFX( mininsX, X, X, XMIN ) +REDUCEPFX( mininsS, SB,SB,SBMIN ) + + +static DF1(jtred0){DECLF;A x;I f,r,wr,*s; + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; s=AS(w); + jt->rank=0; + GA(x,AT(w),0L,r,f+s); + R reitem(vec(INT,f,s),lamin1(df1(x,iden(fs)))); +} /* f/"r w identity case */ + +static DF1(jtredg){PROLOG;DECLF;A y,z;B p;C*u,*v;I i,k,n,old,r,wr,yn,yr,*ys,yt; + RZ(w); + ASSERT(DENSE&AT(w),EVNONCE); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; jt->rank=0; + if(r<wr)R rank1ex(w,self,r,jtredg); + n=IC(w); p=ARELATIVE(w); + RZ(z=tail(w)); yt=AT(z); yn=AN(z); yr=AR(z); ys=1+AS(w); + k=yn*bp(yt); v=CAV(w)+k*(n-1); + old=jt->tbase+jt->ttop; + for(i=1;i<n;++i){ + v-=k; + GA(y,yt,yn,yr,ys); u=CAV(y); + if(p){A1*wv=(A1*)v,*yv=(A1*)u;I d=(I)w-(I)y; AFLAG(y)=AFREL; DO(yn, yv[i]=d+wv[i];);}else MC(u,v,k); + RZ(z=CALL2(f2,y,z,fs)); + gc(z,old); + } + EPILOG(z); +} /* f/"r w for general f and 1<(-r){$w */ + + +static C fca[]={CSTAR, CPLUS, CEQ, CMIN, CMAX, CPLUSDOT, CSTARDOT, CNE, 0}; /* commutative & associative */ + +static A jtredsp1a(J jt,C id,A z,A e,I n,I r,I*s){A t;B b,p=0;D d=1; + switch(id){ + default: ASSERT(0,EVNONCE); + case CPLUSDOT: R n?gcd(z,e):ca(e); + case CSTARDOT: R n?lcm(z,e):ca(e); + case CMIN: R n?minimum(z,e):ca(e); + case CMAX: R n?maximum(z,e):ca(e); + case CPLUS: if(n&&equ(e,zero))R z; DO(r, d*=s[i];); t=tymes(e,d>IMAX?scf(d-n):sc((I)d-n)); R n?plus (z,t):t; + case CSTAR: if(n&&equ(e,one ))R z; DO(r, d*=s[i];); t=expn2(e,d>IMAX?scf(d-n):sc((I)d-n)); R n?tymes(z,t):t; + case CEQ: p=1; /* fall thru */ + case CNE: + ASSERT(B01&AT(e),EVNONCE); + if(!n)*BAV(z)=p; + b=1; DO(r, if(!(s[i]%2)){b=0; break;}); + R !p==*BAV(e)&&b!=n%2?not(z):z; +}} /* f/w on sparse vector w, post processing */ + +static A jtredsp1(J jt,A w,A self,C id,VF ado,I cv,I f,I r,I zt){A e,x,z;I m,n;P*wp; + RZ(w); + wp=PAV(w); e=SPA(wp,e); x=SPA(wp,x); n=AN(x); m=*AS(w); + GA(z,zt,1,0,0); + if(n){ado(jt,1L,n,n,AV(z),AV(x)); RE(0); if(m==n)R z;} + R redsp1a(id,z,e,n,AR(w),AS(w)); +} /* f/"r w for sparse vector w */ + +DF1(jtredravel){A f,x,z;C id;I cv,n;P*wp;VF ado; + RZ(w); + f=VAV(self)->f; + if(!(SPARSE&AT(w)))R reduce(AN(w)?gah(1L,w):mtv,f); + wp=PAV(w); x=SPA(wp,x); n=AN(x); + id=vaid(VAV(f)->f); + while(1){ + vains(id,AT(x),&ado,&cv); + ASSERT(ado,EVNONCE); + GA(z,rtype(cv),1,0,0); + if(n)ado(jt,1L,n,n,AV(z),AV(x)); + if(jt->jerr!=EWOV)R redsp1a(id,z,SPA(wp,e),n,AR(w),AS(w));; +}} /* f/@, w */ + +static A jtredspd(J jt,A w,A self,C id,VF ado,I cv,I f,I r,I zt){A a,e,x,z,zx;I c,m,n,*s,t,*v,wr,*ws,xf,xr;P*wp,*zp; + RZ(w); + ASSERT(strchr(fca,id),EVNONCE); + wp=PAV(w); a=SPA(wp,a); e=SPA(wp,e); x=SPA(wp,x); s=AS(x); + xr=r; v=AV(a); DO(AN(a), if(f<v[i])--xr;); xf=AR(x)-xr; + m=prod(xf,s); c=m?AN(x)/m:0; n=s[xf]; + GA(zx,zt,AN(x)/n,AR(x)-1,s); ICPY(xf+AS(zx),1+xf+s,xr-1); + ado(jt,m,c,n,AV(zx),AV(x)); RE(0); + switch(id){ + case CPLUS: if(!equ(e,zero))RZ(e=tymes(e,sc(n))); break; + case CSTAR: if(!equ(e,one )&&!equ(e,zero))RZ(e=expn2(e,sc(n))); break; + case CEQ: ASSERT(B01&AT(x),EVNONCE); if(!*BAV(e)&&0==n%2)e=one; break; + case CNE: ASSERT(B01&AT(x),EVNONCE); if( *BAV(e)&&1==n%2)e=zero; + } + if(AT(e)!=AT(zx)){t=maxtype(AT(e),AT(zx)); if(t!=AT(zx))RZ(zx=cvt(t,zx));} + wr=AR(w); ws=AS(w); + GA(z,STYPE(AT(zx)),1,wr-1,ws); if(1<wr)ICPY(f+AS(z),f+1+ws,wr-1); + zp=PAV(z); + RZ(a=ca(a)); v=AV(a); DO(AN(a), if(f<v[i])--v[i];); + SPB(zp,a,a); + SPB(zp,e,cvt(AT(zx),e)); + SPB(zp,i,SPA(wp,i)); + SPB(zp,x,zx); + R z; +} /* f/"r w for sparse w, rank > 1, dense axis */ + +static B jtredspsprep(J jt,C id,I f,I zt,A a,A e,A x,A y,I*zm,I**zdv,B**zpv,I**zqv,C**zxxv,A*zsn){ + A d,p,q,sn=0,xx;B*pv;C*xxv;I*dv,j,k,m,mm,*qv=0,*u,*v,yc,yr,yr1,*yv; + v=AS(y); yr=v[0]; yc=v[1]; yr1=yr-1; + RZ(d=grade1(eq(a,sc(f)))); dv=AV(d); + DO(AN(a), if(i!=dv[i]){RZ(q=grade1p(d,y)); qv=AV(q); break;}); + GA(p,B01,yr,1,0); pv=BAV(p); memset(pv,C0,yr); + u=yv=AV(y); m=mm=0; j=-1; if(qv)v=yv+yc*qv[0]; + for(k=0;k<yr1;++k){ + if(qv){u=v; v=yv+yc*qv[1+k];}else v=u+yc; + DO(yc-1, if(u[dv[i]]!=v[dv[i]]){++m; pv[k]=1; mm=MAX(mm,k-j); j=k; break;}); + if(!qv)u+=yc; + } + if(yr){++m; pv[yr1]=1; mm=MAX(mm,yr1-j);} + if(qv){j=mm*aii(x); GA(xx,AT(x),j,1,0); xxv=CAV(xx);} + switch(id){ + case CPLUS: case CPLUSDOT: j=!equ(e,zero); break; + case CSTAR: case CSTARDOT: j=!equ(e,one); break; + case CMIN: j=!equ(e,zt&B01?one :zt&INT?sc(IMAX):ainf ); break; + case CMAX: j=!equ(e,zt&B01?zero:zt&INT?sc(IMIN):scf(infm)); break; + case CEQ: j=!*BAV(e); break; + case CNE: j= *BAV(e); break; + } + if(j)GA(sn,INT,m,1,0); + *zm=m; *zdv=dv; *zpv=pv; *zqv=qv; *zxxv=xxv; *zsn=sn; + R 1; +} + +static B jtredspse(J jt,C id,I wm,I xt,A e,A zx,A sn,A*ze,A*zzx){A b;B nz;I t,zt; + RZ(b=ne(zero,sn)); nz=!all0(b); zt=AT(zx); + switch(id){ + case CPLUS: if(nz)RZ(zx=plus (zx, tymes(e,sn) )); RZ(e= tymes(e,sc(wm)) ); break; + case CSTAR: if(nz)RZ(zx=tymes(zx,bcvt(1,expn2(e,sn)))); RZ(e=bcvt(1,expn2(e,sc(wm)))); break; + case CPLUSDOT: if(nz)RZ(zx=gcd(zx,from(b,over(zero,e)))); break; + case CSTARDOT: if(nz)RZ(zx=lcm(zx,from(b,over(one ,e)))); break; + case CMIN: if(nz)RZ(zx=minimum(zx,from(b,over(zt&B01?one: zt&INT?sc(IMAX):ainf, e)))); break; + case CMAX: if(nz)RZ(zx=maximum(zx,from(b,over(zt&B01?zero:zt&INT?sc(IMIN):scf(infm),e)))); break; + case CEQ: ASSERT(B01&xt,EVNONCE); if(nz)RZ(zx=eq(zx,eq(zero,residue(num[2],sn)))); if(!(wm%2))e=one; break; + case CNE: ASSERT(B01&xt,EVNONCE); if(nz)RZ(zx=ne(zx,eq(one, residue(num[2],sn)))); if(!(wm%2))e=zero; break; + } + if(AT(e)!=AT(zx)){t=maxtype(AT(e),AT(zx)); if(t!=AT(zx))RZ(zx=cvt(t,zx));} + *ze=e; *zzx=zx; + R 1; +} + +static A jtredsps(J jt,A w,A self,C id,VF ado,I cv,I f,I r,I zt){A a,a1,e,sn,x,x1=0,y,z,zx,zy;B*pv; + C*xv,*xxv,*zv;I*dv,i,m,n,*qv,*sv,*v,wr,xk,xt,wm,*ws,xc,yc,yr,*yu,*yv,zk;P*wp,*zp; + RZ(w); + ASSERT(strchr(fca,id),EVNONCE); + wr=AR(w); ws=AS(w); wm=ws[f]; + wp=PAV(w); a=SPA(wp,a); e=SPA(wp,e); + y=SPA(wp,i); v=AS(y); yr=v[0]; yc=v[1]; yv=AV(y); + x=SPA(wp,x); xt=AT(x); xc=aii(x); + RZ(redspsprep(id,f,zt,a,e,x,y,&m,&dv,&pv,&qv,&xxv,&sn)); + xv=CAV(x); xk=xc*bp(xt); + GA(zx,zt,m*xc,AR(x),AS(x)); *AS(zx)=m; zv=CAV(zx); zk=xc*bp(zt); + GA(zy,INT,m*(yc-1),2,0); v=AS(zy); v[0]=m; v[1]=yc-1; yu=AV(zy); + v=qv; if(sn)sv=AV(sn); + for(i=0;i<m;++i){A y;B*p1;C*u;I*vv; + p1=1+(B*)memchr(pv,C1,yr); n=p1-pv; if(sn)sv[i]=wm-n; pv=p1; + vv=qv?yv+yc**v:yv; DO(yc-1, *yu++=vv[dv[i]];); + if(1<n){if(qv){u=xxv; DO(n, MC(u,xv+xk*v[i],xk); u+=xk;);} ado(jt,1L,n*xc,n,zv,qv?xxv:xv); RE(0);} + else if(zk==xk)MC(zv,qv?xv+xk**v:xv,xk); + else {if(!x1)GA(x1,xt,xc,1,0); MC(AV(x1),qv?xv+xk**v:xv,xk); RZ(y=cvt(zt,x1)); MC(zv,AV(y),zk);} + zv+=zk; if(qv)v+=n; else{xv+=n*xk; yv+=n*yc;} + } + if(sn)RZ(redspse(id,wm,xt,e,zx,sn,&e,&zx)); + RZ(a1=ca(a)); v=AV(a1); n=0; DO(AN(a), if(f!=v[i])v[n++]=v[i]-(f<v[i]);); + GA(z,STYPE(AT(zx)),1,wr-1,ws); if(1<r)ICPY(f+AS(z),f+1+ws,r-1); + zp=PAV(z); + SPB(zp,a,vec(INT,n,v)); + SPB(zp,e,cvt(AT(zx),e)); + SPB(zp,x,zx); + SPB(zp,i,zy); + R z; +} /* f/"r w for sparse w, rank > 1, sparse axis */ + +static DF1(jtreducesp){A a,g,x,y,z;B b;C id;I cv,f,n,r,rr[2],*v,wn,wr,*ws,wt,zt;P*wp;VF ado; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; + wn=AN(w); ws=AS(w); n=r?ws[f]:1; + wt=AT(w); wt=wn?DTYPE(wt):B01; + g=VAV(self)->f; id=vaid(g); + if(!n)R red0(w,self); + vains(id,wt,&ado,&cv); + if(2==n&&!(ado&&strchr(fca,id))){ + rr[0]=0; rr[1]=r; + jt->rank=rr; x=from(zero,w); + jt->rank=rr; y=from(one, w); + R df2(x,y,g); + } + if(!ado)R redg(w,self); + if(1==n)R tail(w); + zt=rtype(cv); + jt->rank=0; + if(1==wr)z=redsp1(w,self,id,ado,cv,f,r,zt); + else{ + wp=PAV(w); a=SPA(wp,a); v=AV(a); + b=0; DO(AN(a), if(f==v[i]){b=1; break;}); + z=b?redsps(w,self,id,ado,cv,f,r,zt):redspd(w,self,id,ado,cv,f,r,zt); + } + R jt->jerr==EWOV?(rr[1]=r,jt->rank=rr,reducesp(w,self)):z; +} /* f/"r for sparse w */ + +#define BR2IFX(T,F) {T*u=(T*)wv,*v=u+d,x,y; \ + GA(z,B01,wn/2,wr-1,ws); zv=BAV(z); \ + if(1<d)DO(m, DO(d, x=*u++; y=*v++; *zv++=x F y; ); u+=d; v+=d;) \ + else DO(m, x=*u++; y=*u++; *zv++=x F y; ); \ + } +#define BR2PFX(T,F) {T*u=(T*)wv,*v=u+d,x,y; \ + GA(z,B01,wn/2,wr-1,ws); zv=BAV(z); \ + if(1<d)DO(m, DO(d, x=*u++; y=*v++; *zv++=F(x,y);); u+=d; v+=d;) \ + else DO(m, x=*u++; y=*u++; *zv++=F(x,y); ); \ + } +#define BTABIFX(F) {btab[0 ]=0 F 0; \ + btab[SYS&SYS_LILENDIAN?256: 1]=0 F 1; \ + btab[SYS&SYS_LILENDIAN? 1:256]=1 F 0; \ + btab[257 ]=1 F 1; \ + } +#define BTABPFX(F) {btab[0 ]=F(0,0); \ + btab[SYS&SYS_LILENDIAN?256: 1]=F(0,1); \ + btab[SYS&SYS_LILENDIAN? 1:256]=F(1,0); \ + btab[257 ]=F(1,1); \ + } +#define BR2CASE(t,id) ((id)+256*(t)) + +static B jtreduce2(J jt,A w,C id,I f,I r,A*zz){A z=0;B b=0,btab[258],*zv;I c,d,m,wn,wr,*ws,*wv; + wn=AN(w); wr=AR(w); ws=AS(w); wv=AV(w); + m=prod(f,ws); c=m?wn/m:prod(r,f+ws); d=c/2; + switch(BR2CASE(AT(w),id)){ + case BR2CASE(B01,CEQ ): if(b=1==r)BTABIFX(== ); break; + case BR2CASE(B01,CNE ): if(b=1==r)BTABIFX(!= ); break; + case BR2CASE(B01,CLT ): if(b=1==r)BTABIFX(< ); break; + case BR2CASE(B01,CLE ): if(b=1==r)BTABIFX(<= ); break; + case BR2CASE(B01,CGT ): if(b=1==r)BTABIFX(> ); break; + case BR2CASE(B01,CGE ): if(b=1==r)BTABIFX(>= ); break; + case BR2CASE(B01,CMAX ): + case BR2CASE(B01,CPLUSDOT): if(b=1==r)BTABIFX(|| ); break; + case BR2CASE(B01,CPLUSCO ): if(b=1==r)BTABPFX(BNOR ); break; + case BR2CASE(B01,CMIN ): + case BR2CASE(B01,CSTAR ): + case BR2CASE(B01,CSTARDOT): if(b=1==r)BTABIFX(&& ); break; + case BR2CASE(B01,CSTARCO ): if(b=1==r)BTABPFX(BNAND); break; + case BR2CASE(LIT,CEQ ): BR2IFX(C,== ); break; + case BR2CASE(LIT,CNE ): BR2IFX(C,!= ); break; + case BR2CASE(INT,CEQ ): BR2IFX(I,== ); break; + case BR2CASE(INT,CLT ): BR2IFX(I,< ); break; + case BR2CASE(INT,CLE ): BR2IFX(I,<= ); break; + case BR2CASE(INT,CGT ): BR2IFX(I,> ); break; + case BR2CASE(INT,CGE ): BR2IFX(I,>= ); break; + case BR2CASE(INT,CNE ): BR2IFX(I,!= ); break; + case BR2CASE(FL, CEQ ): BR2PFX(D,TEQ); break; + case BR2CASE(FL, CLT ): BR2PFX(D,TLT); break; + case BR2CASE(FL, CLE ): BR2PFX(D,TLE); break; + case BR2CASE(FL, CGT ): BR2PFX(D,TGT); break; + case BR2CASE(FL, CGE ): BR2PFX(D,TGE); break; + case BR2CASE(FL, CNE ): BR2PFX(D,TNE); break; + } + if(b){S*u=(S*)wv; GA(z,B01,wn/2,wr-1,ws); zv=BAV(z); DO(m, *zv++=btab[*u++];);} + if(z&&1<r){I*u=f+AS(z),*v=f+1+ws; DO(r-1, *u++=*v++;);} + *zz=z; + R 1; +} /* f/"r for dense w over an axis of length 2 */ + +static DF1(jtreduce){A z;C id;I c,cv,f,m,n,r,rr[2],t,wn,wr,*ws,wt,zt;VF ado; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; + wn=AN(w); ws=AS(w); n=r?ws[f]:1; + if(SPARSE&AT(w))R reducesp(w,self); + wt=AT(w); wt=wn?wt:B01; + id=vaid(VAV(self)->f); + switch(n){ + case 0: R red0(w,self); + case 1: R tail(w); + case 2: RZ(reduce2(w,id,f,r,&z)); if(z)R z; + } + vains(id,wt,&ado,&cv); + if(!ado)R redg(w,self); + zt=rtype(cv); jt->rank=0; + GA(z,zt,wn/n,MAX(0,wr-1),ws); if(1<r)ICPY(f+AS(z),f+1+ws,r-1); + if((t=atype(cv))&&t!=wt)RZ(w=cvt(t,w)); + m=prod(f,ws); c=m?wn/m:prod(r,f+ws); + ado(jt,m,c,n,AV(z),AV(w)); + if(jt->jerr)R jt->jerr==EWOV?(rr[1]=r,jt->rank=rr,reduce(w,self)):0; else R cv&VRI+VRD?cvz(cv,z):z; +} /* f/"r w main control */ + +static A jtredcatsp(J jt,A w,A z,I r){A a,q,x,y;B*b;I c,d,e,f,j,k,m,n,n1,p,*u,*v,wr,*ws,xr;P*wp,*zp; + ws=AS(w); wr=AR(w); f=wr-r; p=ws[1+f]; + wp=PAV(w); x=SPA(wp,x); y=SPA(wp,i); a=SPA(wp,a); v=AV(a); + m=*AS(y); n=AN(a); n1=n-1; xr=AR(x); + RZ(b=bfi(wr,a,1)); + c=b[f]; d=b[1+f]; if(c&&d)b[f]=0; e=f+!c; + j=0; DO(n, if(e==v[i]){j=i; break;}); + k=1; DO(f, if(!b[i])++k;); + zp=PAV(z); SPB(zp,e,ca(SPA(wp,e))); + GA(q,INT,n-(c&&d),1,0); v=AV(q); DO(wr, if(b[i])*v++=i-(i>f);); SPB(zp,a,q); + if(c&&d){ /* sparse sparse */ + SPB(zp,x,ca(x)); + SPB(zp,i,q=repeatr(ne(a,sc(f)),y)); + v=j+AV(q); u=j+AV(y); + DO(m, *v=p*u[0]+u[1]; v+=n1; u+=n;); + }else if(!c&&!d){ /* dense dense */ + u=AS(x); GA(q,AT(x),AN(x),xr-1,u); v=k+AS(q); *v=u[k]*u[1+k]; ICPY(1+v,2+k+u,xr-k-2); + MC(AV(q),AV(x),AN(x)*bp(AT(x))); + SPB(zp,x,q); SPB(zp,i,ca(y)); + }else{ /* other */ + GA(q,INT,xr,1,0); v=AV(q); + if(1!=k){*v++=0; *v++=k; e=0; DO(xr-1, ++e; if(e!=k)*v++=e;); RZ(x=cant2(q,x));} + v=AV(q); u=AS(x); *v=u[0]*u[1]; ICPY(1+v,2+u,xr-1); RZ(x=reshape(vec(INT,xr-1,v),x)); + e=ws[f+c]; RZ(y=repeat(sc(e),y)); v=j+AV(y); + if(c)DO(m, k=p**v; DO(e, *v=k+ i; v+=n;);) + else DO(m, k= *v; DO(e, *v=k+p*i; v+=n;);); + RZ(q=grade1(y)); RZ(y=from(q,y)); RZ(x=from(q,x)); + SPB(zp,x,x); SPB(zp,i,y); + } + R z; +} /* ,/"r w for sparse w, 2<r */ + +static DF1(jtredcat){A z;B b;I f,r,*s,*v,wr; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; s=AS(w); jt->rank=0; + b=1==r&&1==s[f]; + if(2>r&&!b)R ca(w); + GA(z,AT(w),AN(w),wr-1,s); + if(!b){v=f+AS(z); RE(*v=mult(s[f],s[1+f])); ICPY(1+v,2+f+s,r-2);} + if(SPARSE&AT(w))R redcatsp(w,z,r); + MC(AV(z),AV(w),AN(w)*bp(AT(w))); + if(ARELATIVE(w)){AFLAG(z)=AFREL; z=relocate((I)w-(I)z,z);} + R z; +} /* ,/"r w */ + +static DF1(jtredsemi){I f,n,r,*s,wr; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; s=AS(w); n=r?s[f]:1; + if(2>n){ASSERT(n,EVDOMAIN); R tail(w);} + if(BOX&AT(w))R irs2(rank1ex(curtail(w),0L,r-1,jtbox),tail(w),0L,r,r-1,jtover); + else R irs1(w,0L,r-1,jtbox); +} /* ;/"r w */ + +static DF1(jtredstitch){A c,y;I f,n,r,*s,*v,wr; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + s=AS(w); n=r?s[f]:1; + ASSERT(n,EVDOMAIN); + if(1==n)R irs1(w,0L,r,jthead); + if(1==r)R 2==n?ca(w):irs2(irs2(num[-2],w,0L,0L,1L,jtdrop),irs2(num[-2],w,0L,0L,1L,jttake),0L,1L,0L,jtover); + if(2==r)R irs1(w,0L,2L,jtcant1); + RZ(c=IX(wr)); v=AV(c); v[f]=f+1; v[f+1]=f; RZ(y=cant2(c,w)); + if(SPARSE&AT(w)){A x; + GA(x,INT,f+r-1,1,0); v=AV(x); ICPY(v,AS(y),f+1); + RE(v[f+1]=mult(s[f],s[f+2])); ICPY(v+f+2,s+3+f,r-3); + R reshape(x,y); + }else{ + v=AS(y); + RE(v[f+1]=mult(s[f],s[f+2])); ICPY(v+f+2,s+3+f,r-3); + --AR(y); + R y; +}} /* ,./"r w */ + +static DF1(jtredstiteach){A*wv,y;I n,p,r,t,wd; + RZ(w); + n=AN(w); + if(!(2<n&&1==AR(w)&&BOX&AT(w)))R reduce(w,self); + wv=AAV(w); wd=(I)w*ARELATIVE(w); y=WVR(0); p=IC(y); t=AT(y); + DO(n, y=WVR(i); r=AR(y); if(!(r&&r<=2&&p==IC(y)&&t==AT(y)))R reduce(w,self);); + R box(razeh(w)); +} /* ,.&.>/ w */ + +static DF1(jtredcateach){A*u,*v,*wv,x,*xv,z,*zv;I f,m,mn,n,r,wd,wr,*ws,zm,zn; + RZ(w); + wr=AR(w); ws=AS(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + n=r?ws[f]:1; + if(!r||1>=n)R reshape(repeat(ne(sc(f),IX(wr)),shape(w)),n?w:ace); + if(!(BOX&AT(w)))R df1(cant2(sc(f),w),qq(ds(CBOX),one)); + zn=AN(w)/n; zm=prod(f,ws); m=zm?AN(w)/(zm*n):prod(r-1,ws+f+1); mn=m*n; + GA(z,BOX,zn,wr-1,ws); ICPY(AS(z)+f,ws+f+1,r-1); + GA(x,BOX,n,1,0); xv=AAV(x); + zv=AAV(z); wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(zm, u=wv; DO(m, v=u++; DO(n, xv[i]=AADR(wd,*v); v+=m;); RZ(*zv++=raze(x));); wv+=mn;); + R z; +} /* ,&.>/"r w */ + +static DF2(jtoprod){R df2(a,w,VAV(self)->h);} + + +F1(jtslash){A h;AF f1=jtreduce;C c;V*v; + RZ(w); + if(NOUN&AT(w))R evger(w,sc(GINSERT)); + v=VAV(w); + switch(v->id){ + case CCOMMA: f1=jtredcat; break; + case CCOMDOT: f1=jtredstitch; break; + case CSEMICO: f1=jtredsemi; break; + case CUNDER: if(COPE==ID(v->g)){c=ID(v->f); if(c==CCOMMA)f1=jtredcateach; else if(c==CCOMDOT)f1=jtredstiteach;} + } + RZ(h=qq(w,v2(lr(w),RMAX))); + R fdef(CSLASH,VERB, f1,jtoprod, w,0L,h, 0L, RMAX,RMAX,RMAX); +} + +A jtaslash (J jt,C c, A w){RZ( w); R df1( w, slash(ds(c)) );} +A jtaslash1(J jt,C c, A w){RZ( w); R df1( w,qq(slash(ds(c)),one));} +A jtatab (J jt,C c,A a,A w){RZ(a&&w); R df2(a,w, slash(ds(c)) );} + + +static AHDRR(jtmeanD,D,D){I d,i;D*y;D v,*zz; + d=c/n; + NAN0; + if(1==d)DO(m, v= *x++; DO(n-1, v+=*x++;); *z++=v/n;) + else for(i=0;i<m;++i){ + y=x; x+=d; zz=z; DO(d, *z++ =*x+++ *y++;); + DO(n-3, z=zz; DO(d, *z+++=*x++; )); + z=zz; DO(d, *z =(*z+*x++)/n; ++z;); + } + NAN1V; +} /* based on REDUCEPFX; 2<n */ + +static AHDRR(jtmeanI,D,I){I d,i;I*y;D v,*zz; + d=c/n; + if(1==d)DO(m, v=(D)*x++; DO(n-1, v+=*x++;); *z++=v/n;) + else for(i=0;i<m;++i){ + y=x; x+=d; zz=z; DO(d, *z++ =*x+++(D)*y++;); + DO(n-3, z=zz; DO(d, *z+++=*x++; )); + z=zz; DO(d, *z =(*z+*x++)/n; ++z;); +}} /* based on REDUCEPFX; 2<n */ + +DF1(jtmean){A z;I c,f,m,n,r,wn,wr,*ws,wt; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + wt=AT(w); wn=AN(w); ws=AS(w); n=r?ws[f]:1; + if(!(wn&&2<n&&wt&INT+FL))R divide(df1(w,qq(slash(ds(CPLUS)),sc(r))),sc(n)); + GA(z,FL,wn/n,MAX(0,wr-1),ws); if(1<r)ICPY(f+AS(z),f+1+ws,r-1); + m=prod(f,ws); c=m?wn/m:prod(r,f+ws); + if(wt&INT)meanI(m,c,n,DAV(z), AV(w)); + else meanD(m,c,n,DAV(z),DAV(w)); + RE(0); R z; +} /* (+/%#)"r w */
new file mode 100644 --- /dev/null +++ b/ar.h @@ -0,0 +1,49 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: f/ defns */ + + +#define REDUCEPFX(f,Tz,Tx,pfx) \ + AHDRR(f,Tz,Tx){I d,i;Tx*y;Tz v,*zz; \ + d=c/n; x+=m*c; zz=z+=m*d; \ + if(1==d)DO(m, v= *--x; DO(n-1, --x; v=pfx(*x,v);); *--z=v;) \ + else if(1==n)DO(d, *--z= *--x;) \ + else for(i=0;i<m;++i,zz-=d){ \ + y=x; x-=d; z=zz; DO(d, --z; --x; --y; *z=pfx(*x,*y);); \ + DO(n-2, z=zz; DO(d, --z; --x; *z=pfx(*x,*z);)); \ + }} + +#define REDUCENAN(f,Tz,Tx,pfx) \ + AHDRR(f,Tz,Tx){I d,i;Tx*y;Tz v,*zz; \ + NAN0; \ + d=c/n; x+=m*c; zz=z+=m*d; \ + if(1==d)DO(m, v= *--x; DO(n-1, --x; v=pfx(*x,v);); *--z=v;) \ + else if(1==n)DO(d, *--z= *--x;) \ + else for(i=0;i<m;++i,zz-=d){ \ + y=x; x-=d; z=zz; DO(d, --z; --x; --y; *z=pfx(*x,*y);); \ + DO(n-2, z=zz; DO(d, --z; --x; *z=pfx(*x,*z);)); \ + } \ + NAN1V; \ + } + +#define REDUCCPFX(f,Tz,Tx,pfx) \ + AHDRR(f,Tz,Tx){I d,i;Tx*y;Tz v,*zz; \ + d=c/n; x+=m*c; zz=z+=m*d; \ + if(1==d)DO(m, v=(Tz)*--x; DO(n-1, --x; v=pfx(*x,v);); *--z=v;) \ + else if(1==n)DO(d, *--z=(Tz)*--x;) \ + else for(i=0;i<m;++i,zz-=d){ \ + y=x; x-=d; z=zz; DO(d, --z; --x; --y; *z=pfx(*x,*y);); \ + DO(n-2, z=zz; DO(d, --z; --x; *z=pfx(*x,*z);)); \ + }} + +#define REDUCEOVF(f,Tz,Tx,fr1,fvv,frn) \ + AHDRR(f,I,I){C er=0;I d,i,*xx,*y,*zz; \ + d=c/n; xx=x+=m*c; zz=z+=m*d; \ + if(1==d){DO(m, z=--zz; x=xx-=c; fr1(n,z,x); RER;); R;} \ + if(1==n){DO(d, *--z=*--x;); R;} \ + xx-=d; zz-=d; \ + for(i=0;i<m;++i,xx-=d,zz-=d){ \ + y=xx; x=xx-=d; z=zz; fvv(d,z,x,y); RER; \ + DO(n-2, x=xx-=d; z=zz; frn(d,z,x); RER;); \ + }}
new file mode 100644 --- /dev/null +++ b/as.c @@ -0,0 +1,332 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Suffix and Outfix */ + +#include "j.h" +#include "vasm.h" +#include "ve.h" + + +#define SUFFIXPFX(f,Tz,Tx,pfx) \ + AHDRS(f,Tz,Tx){I d,i;Tz v,*y; \ + d=c/n; x+=m*c; z+=m*c; \ + if(1==d)DO(m, *--z=v= *--x; DO(n-1, --x; --z; *z=v=pfx(*x,v);)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *--z= *--x;); \ + DO(n-1, DO(d, --x; --y; --z; *z=pfx(*x,*y);)); \ + }} + +#define SUFFIXNAN(f,Tz,Tx,pfx) \ + AHDRS(f,Tz,Tx){I d,i;Tz v,*y; \ + NAN0; \ + d=c/n; x+=m*c; z+=m*c; \ + if(1==d)DO(m, *--z=v= *--x; DO(n-1, --x; --z; *z=v=pfx(*x,v);)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *--z= *--x;); \ + DO(n-1, DO(d, --x; --y; --z; *z=pfx(*x,*y);)); \ + } \ + NAN1V; \ + } + +#define SUFFICPFX(f,Tz,Tx,pfx) \ + AHDRS(f,Tz,Tx){I d,i;Tz v,*y; \ + d=c/n; x+=m*c; z+=m*c; \ + if(1==d)DO(m, *--z=v=(Tz)*--x; DO(n-1, --x; --z; *z=v=pfx(*x,v);)) \ + else for(i=0;i<m;++i){ \ + y=z; DO(d, *--z=(Tz)*--x;); \ + DO(n-1, DO(d, --x; --y; --z; *z=pfx(*x,*y);)); \ + }} + +#define SUFFIXOVF(f,Tz,Tx,fs1,fvv) \ + AHDRS(f,I,I){C er=0;I d,i,*xx,*y,*zz; \ + d=c/n; xx=x+=m*c; zz=z+=m*c; \ + if(1==d){ \ + if(1==n)DO(m, *--z=*--x;) \ + else DO(m, z=zz-=c; x=xx-=c; fs1(n,z,x); RER;) \ + }else for(i=0;i<m;++i){ \ + DO(d, *--zz=*--xx;); \ + DO(n-1, x=xx-=d; y=zz; z=zz-=d; fvv(d,z,x,y); RER;); \ + }} + +#if SY_ALIGN +#define SUFFIXBFXLOOP(T,pfx) \ + {T*xx=(T*)x,*yy,*zz=(T*)z; \ + q=d/sizeof(T); \ + DO(m, yy=zz; DO(q, *--zz=*--xx;); DO(n-1, DO(q, --xx; --yy; --zz; *zz=pfx(*xx,*yy);))); \ + } + +#define SUFFIXBFX(f,pfx,ipfx,spfx,bpfx,vexp) \ + AHDRP(f,B,B){B v,*y;I d,q; \ + d=c/n; x+=m*c; z+=m*c; \ + if(1==d){DO(m, *--z=v=*--x; DO(n-1, --x; --z; *z=v=vexp;)); R;} \ + if(0==d%sizeof(UI )){SUFFIXBFXLOOP(UI, pfx); R;} \ + if(0==d%sizeof(UINT)){SUFFIXBFXLOOP(UINT,ipfx); R;} \ + if(0==d%sizeof(US )){SUFFIXBFXLOOP(US, spfx); R;} \ + DO(m, y=z; DO(d, *--z=*--x;); DO(n-1, DO(d, --x; --y; --z; *z=bpfx(*x,*y);))); \ + } +#else +#define SUFFIXBFX(f,pfx,ipfx,spfx,bpfx,vexp) \ + AHDRS(f,B,B){B v;I d,i,q,r,t,*xi,*yi,*zi; \ + d=c/n; x+=m*c; z+=m*c; \ + if(1==d){DO(m, *--z=v=*--x; DO(n-1, --x; --z; *z=v=vexp;)); R;} \ + q=d/SZI; r=d%SZI; xi=(I*)x; zi=(I*)z; \ + if(0==r)for(i=0;i<m;++i){ \ + yi=zi; DO(q, *--zi=*--xi;); \ + DO(n-1, DO(q, --xi; --yi; --zi; *zi=pfx(*xi,*yi);)); \ + }else for(i=0;i<m;++i){ \ + yi=zi; DO(q, *--zi=*--xi;); \ + x=(B*)xi; z=(B*)zi; DO(r, *--z=*--x;); xi=(I*)x; zi=(I*)z; \ + DO(n-1, DO(q, --xi; --yi; --zi; *zi=pfx(*xi,*yi);); \ + xi=(I*)((B*)xi-r); \ + yi=(I*)((B*)yi-r); \ + zi=(I*)((B*)zi-r); t=pfx(*xi,*yi); MC(zi,&t,r);); \ + }} +#endif + +SUFFIXBFX( orsfxB, OR, IOR, SOR, BOR, *x||v ) +SUFFIXBFX( andsfxB, AND, IAND, SAND, BAND, *x&&v ) +SUFFIXBFX( eqsfxB, EQ, IEQ, SEQ, BEQ, *x==v ) +SUFFIXBFX( nesfxB, NE, INE, SNE, BNE, *x!=v ) +SUFFIXBFX( ltsfxB, LT, ILT, SLT, BLT, *x< v ) +SUFFIXBFX( lesfxB, LE, ILE, SLE, BLE, *x<=v ) +SUFFIXBFX( gtsfxB, GT, IGT, SGT, BGT, *x> v ) +SUFFIXBFX( gesfxB, GE, IGE, SGE, BGE, *x>=v ) +SUFFIXBFX( norsfxB, NOR, INOR, SNOR, BNOR, !(*x||v)) +SUFFIXBFX( nandsfxB, NAND,INAND,SNAND,BNAND,!(*x&&v)) + +SUFFIXOVF( plussfxI, I, I, PLUSS, PLUSVV) +SUFFIXOVF(minussfxI, I, I, MINUSS,MINUSVV) +SUFFIXOVF(tymessfxI, I, I, TYMESS,TYMESVV) + +SUFFICPFX( plussfxO, D, I, PLUS ) +SUFFICPFX(minussfxO, D, I, MINUS ) +SUFFICPFX(tymessfxO, D, I, TYMES ) + +SUFFIXPFX( plussfxB, I, B, PLUS ) +SUFFIXNAN( plussfxD, D, D, PLUS ) +SUFFIXNAN( plussfxZ, Z, Z, zplus ) +SUFFIXPFX( plussfxX, X, X, xplus ) +SUFFIXPFX( plussfxQ, Q, Q, qplus ) + +SUFFIXPFX(minussfxB, I, B, MINUS ) +SUFFIXNAN(minussfxD, D, D, MINUS ) +SUFFIXNAN(minussfxZ, Z, Z, zminus) + +SUFFIXPFX(tymessfxD, D, D, TYMES ) +SUFFIXPFX(tymessfxZ, Z, Z, ztymes) +SUFFIXPFX(tymessfxX, X, X, xtymes) +SUFFIXPFX(tymessfxQ, Q, Q, qtymes) + +SUFFIXNAN( divsfxD, D, D, DIV ) +SUFFIXNAN( divsfxZ, Z, Z, zdiv ) + +SUFFIXPFX( maxsfxI, I, I, MAX ) +SUFFIXPFX( maxsfxD, D, D, MAX ) +SUFFIXPFX( maxsfxX, X, X, XMAX ) +SUFFIXPFX( maxsfxQ, Q, Q, QMAX ) +SUFFIXPFX( maxsfxS, SB,SB,SBMAX ) + +SUFFIXPFX( minsfxI, I, I, MIN ) +SUFFIXPFX( minsfxD, D, D, MIN ) +SUFFIXPFX( minsfxX, X, X, XMIN ) +SUFFIXPFX( minsfxQ, Q, Q, QMIN ) +SUFFIXPFX( minsfxS, SB,SB,SBMIN ) + +SUFFIXPFX(bw0000sfxI, UI,UI, BW0000) +SUFFIXPFX(bw0001sfxI, UI,UI, BW0001) +SUFFIXPFX(bw0010sfxI, UI,UI, BW0010) +SUFFIXPFX(bw0011sfxI, UI,UI, BW0011) +SUFFIXPFX(bw0100sfxI, UI,UI, BW0100) +SUFFIXPFX(bw0101sfxI, UI,UI, BW0101) +SUFFIXPFX(bw0110sfxI, UI,UI, BW0110) +SUFFIXPFX(bw0111sfxI, UI,UI, BW0111) +SUFFIXPFX(bw1000sfxI, UI,UI, BW1000) +SUFFIXPFX(bw1001sfxI, UI,UI, BW1001) +SUFFIXPFX(bw1010sfxI, UI,UI, BW1010) +SUFFIXPFX(bw1011sfxI, UI,UI, BW1011) +SUFFIXPFX(bw1100sfxI, UI,UI, BW1100) +SUFFIXPFX(bw1101sfxI, UI,UI, BW1101) +SUFFIXPFX(bw1110sfxI, UI,UI, BW1110) +SUFFIXPFX(bw1111sfxI, UI,UI, BW1111) + + +static DF1(jtsuffix){DECLF;I r; + RZ(w); + if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,r,jtsuffix);} + jt->rank=0; + R eachl(IX(IC(w)),w,atop(fs,ds(CDROP))); +} /* f\."r w for general f */ + +static DF1(jtgsuffix){A h,*hv,z,*zv;I m,n,r; + RZ(w); + if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,jt->rank[1],jtgsuffix);} + jt->rank=0; + n=IC(w); + h=VAV(self)->h; hv=AAV(h); m=AN(h); + GA(z,BOX,n,1,0); zv=AAV(z); + DO(n, RZ(zv[i]=df1(drop(sc(i),w),hv[i%m]));); + R ope(z); +} /* g\."r w for gerund g */ + +#define SSGULOOP(T) \ + {T*v=(T*)zv; \ + for(i=0;i<n1;++i){ \ + RZ(q=CALL2(f2,x,y,fs)); RZ(t==AT(q)&&!AR(q)); \ + *v--=*(T*)AV(q); \ + AK(x)-=k; AK(y)-=k; tpop(old); \ + }} + +static DF1(jtssgu){A fs,q,x,y,z;AF f2;C*zv;I i,k,m,n1,old,r,t;V*sv=VAV(self); + fs=VAV(sv->f)->f; f2=VAV(fs)->f2; + r=AR(w)-1; n1=IC(w)-1; m=aii(w); t=AT(w); k=m*bp(t); + RZ(z=ca(w)); zv=CAV(z)+k*n1; + RZ(q=tail(w)); + RZ(y=gah(r,q)); ICPY(AS(y),AS(q),r); AK(y)=(I)zv-(I)y; zv-=k; + RZ(x=gah(r,q)); ICPY(AS(x),AS(q),r); AK(x)=(I)zv-(I)x; + old=jt->tbase+jt->ttop; + switch(r?0:k){ + case sizeof(C): SSGULOOP(C); break; + case sizeof(I): SSGULOOP(I); break; + case sizeof(S): SSGULOOP(S); break; +#if ! SY_64 + case sizeof(D): SSGULOOP(D); break; +#endif + case sizeof(Z): SSGULOOP(Z); break; + default: + for(i=0;i<n1;++i){ + RZ(q=CALL2(f2,x,y,fs)); RZ(t==AT(q)&&r==AR(q)&&!ICMP(AS(y),AS(q),r)); + MC(zv,CAV(q),k); zv-=k; + AK(x)-=k; AK(y)-=k; + tpop(old); + }} + R z; +} /* same as ssg but for uniform function f */ + +static DF1(jtssg){A fs,q,y,z,*zv;AF f2;B p;C*u,*v;I i,k,n,yn,yr,*ys,yt;V*sv=VAV(self); + if(jt->rank&&jt->rank[1]<AR(w))R rank1ex(w,self,jt->rank[1],jtssg); + jt->rank=0; + fs=VAV(sv->f)->f; f2=VAV(fs)->f2; + n=IC(w); p=ARELATIVE(w); + if(DIRECT&AT(w)){RE(z=ssgu(w,self)); if(z)R z;} + GA(z,BOX,n,1,0); zv=n+AAV(z); + RZ(*--zv=q=tail(w)); yt=AT(q); yn=AN(q); yr=AR(q); ys=1+AS(w); + k=yn*bp(yt); v=CAV(w)+k*(n-1); + for(i=1;i<n;++i){ + v-=k; + GA(y,yt,yn,yr,ys); u=CAV(y); + if(p){A1*wv=(A1*)v,*yv=(A1*)u;I d=(I)w-(I)y; AFLAG(y)=AFREL; DO(yn, yv[i]=d+wv[i];);}else MC(u,v,k); + RZ(*--zv=q=CALL2(f2,y,q,fs)); + } + R ope(z); +} /* f/\."r w for general f and 1<(-r){$w and -.0 e.$w */ + +A jtscansp(J jt,A w,A self,AF sf){A e,ee,x,z;B*b;I f,m,j,r,t,rv[2],wr;P*wp,*zp; + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + wp=PAV(w); e=SPA(wp,e); RZ(ee=over(e,e)); + if(!equ(ee,CALL1(sf,ee,self))){ + RZ(x=denseit(w)); + rv[1]=r; jt->rank=rv; RZ(z=CALL1(sf,x,self)); jt->rank=0; + R z; + }else{ + RZ(b=bfi(wr,SPA(wp,a),1)); + if(r&&b[f]){b[f]=0; RZ(w=reaxis(ifb(wr,b),w));} + j=f; m=0; DO(wr-f, m+=!b[j++];); + } + wp=PAV(w); e=SPA(wp,e); x=SPA(wp,x); + rv[1]=m; jt->rank=rv; RZ(x=CALL1(sf,x,self)); jt->rank=0; + t=maxtype(AT(e),AT(x)); RZ(e=cvt(t,e)); if(t!=AT(x))RZ(x=cvt(t,x)); + GA(z,STYPE(t),1,wr+!m,AS(w)); if(!m)*(wr+AS(z))=1; + zp=PAV(z); + SPB(zp,e,e); + SPB(zp,x,x); + SPB(zp,i,ca(SPA(wp,i))); + SPB(zp,a,ca(SPA(wp,a))); + R z; +} /* f/\"r or f/\."r on sparse w */ + +static DF1(jtsscan){A y,z;C id;I c,cv,f,m,n,r,rr[2],t,wn,wr,*ws,wt,zt;VF ado; + RZ(w); + wt=AT(w); + if(SPARSE&wt)R scansp(w,self,jtsscan); + wn=AN(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; ws=AS(w); + m=prod(f,ws); c=m?AN(w)/m:prod(r,f+ws); n=r?ws[f]:1; + y=VAV(self)->f; id=vaid(VAV(y)->f); + if(2>n||!wn){if(id){jt->rank=0; R r?ca(w):reshape(over(shape(w),one),w);}else R suffix(w,self);} + vasfx(id,wt,&ado,&cv); + if(!ado)R ssg(w,self); + if((t=atype(cv))&&t!=wt)RZ(w=cvt(t,w)); + zt=rtype(cv); jt->rank=0; + GA(z,zt,wn,wr,ws); + ado(jt,m,c,n,AV(z),AV(w)); + if(jt->jerr)R jt->jerr==EWOV?(rr[1]=r,jt->rank=rr,sscan(w,self)):0; else R cv&VRI+VRD?cvz(cv,z):z; +} /* f/\."r w main control */ + + +static F2(jtomask){A c,r,x,y;I m,n,p; + RZ(a&&w); + RE(m=i0(a)); p=ABS(m); n=IC(w); + r=sc(0>m?(n+p-1)/p:MAX(0,1+n-m)); c=tally(w); + x=reshape(sc(p), zero); + y=reshape(0>m?c:r,one ); + R reshape(over(r,c),over(x,y)); +} + +static DF2(jtgoutfix){A h,*hv,x,z,*zv;I m,n; + RZ(x=omask(a,w)); + n=IC(x); + h=VAV(self)->h; hv=AAV(h); m=AN(h); + GA(z,BOX,n,1,0); zv=AAV(z); + DO(n, RZ(zv[i]=df1(repeat(from(sc(i),x),w),hv[i%m]));); + R ope(z); +} + +static AS2(jtoutfix, eachl(omask(a,w),w,atop(fs,ds(CPOUND)))) + +static DF2(jtofxinv){A f,fs,z;C c;I t;V*v; + F2RANK(0,RMAX,jtofxinv,self); + fs=VAV(self)->f; f=VAV(fs)->f; v=VAV(f); c=v->id; t=AT(w); + if(!(c==CPLUS||c==CBDOT&&t&INT||(c==CEQ||c==CNE)&&t&B01))R outfix(a,w,self); + z=irs2(df1(w,fs),df2(a,w,bslash(fs)),0L,RMAX,-1L,c==CPLUS?(AF)jtminus:v->f2); + if(jt->jerr==EVNAN){RESETERR; R outfix(a,w,self);}else R z; +} /* a f/\. w where f has an "inverse" */ + +static DF2(jtofxassoc){A f,i,j,p,s,x,z;C id,*zv;I c,cv,d,k,kc,m,r,t;V*v;VF ado; + F2RANK(0,RMAX,jtofxassoc,self); + m=IC(w); RE(k=i0(a)); c=ABS(k); + f=VAV(self)->f; x=VAV(f)->f; v=VAV(x); id=CBDOT==v->id?(C)*AV(v->f):v->id; + if(k==IMIN||m<=c||id==CSTARDOT&&!(B01&AT(w)))R outfix(a,w,self); + if(-1<=k){d=m-c; RZ(i=apv(d,0L, 1L)); RZ(j=apv(d,c,1L));} + else {d=(m-1)/c; RZ(i=apv(d,c-1,c )); RZ(j=apv(d,c,c ));} + RZ(p=from(i,df1(w,bslash(f)))); + RZ(s=from(j,df1(w,bsdot(f)))); + r=AR(p); c=aii(p); t=AT(p); k=bp(t); kc=k*c; + RZ(var(id,p,p,t,t,&ado,&cv)); + ASSERTSYS(ado,"ofxassoc"); + GA(z,t,c*(1+d),r,AS(p)); *AS(z)=1+d; zv=CAV(z); + MC(zv, AV(s), kc); /* {.s */ + if(1<d)ado(jt,1,c*(d-1),1L,zv+kc,AV(p),kc+CAV(s)); /* (}:p) f (}.s) */ + MC(zv+kc*d,CAV(p)+kc*(d-1),kc); /* {:p */ + if(jt->jerr==EWOV){RESETERR; R ofxassoc(a,cvt(FL,w),self);}else R z; +} /* a f/\. w where f is an atomic associative fn */ + +static DF1(jtiota1rev){R apv(IC(w),IC(w),-1L);} + +F1(jtbsdot){A f;AF f1=jtsuffix,f2=jtoutfix;C id;V*v; + RZ(w); + if(NOUN&AT(w))R fdef(CBSLASH,VERB, jtgsuffix,jtgoutfix, w,0L,fxeachv(1L,w), VGERL, RMAX,0L,RMAX); + v=VAV(w); + switch(v->id){ + case CPOUND: f1=jtiota1rev; break; + case CSLASH: + f1=jtsscan; + f=v->f; id=ID(f); if(id==CBDOT){f=VAV(f)->f; if(INT&AT(f)&&!AR(f))id=(C)*AV(f);} + switch(id){ + case CPLUS: case CEQ: case CNE: case CBW0110: case CBW1001: + f2=jtofxinv; break; + case CSTAR: case CMAX: case CMIN: case CPLUSDOT: case CSTARDOT: + case CBW0000: case CBW0001: case CBW0011: case CBW0101: case CBW0111: case CBW1111: + f2=jtofxassoc; + }} + R ADERIV(CBSDOT,f1,f2,RMAX,0,RMAX); +}
new file mode 100644 --- /dev/null +++ b/au.c @@ -0,0 +1,79 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Adverbs: Utilities */ + +#include "j.h" + + +static I jtfdepger(J jt,A w){A*wv;I d=0,k,wd; + wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(AN(w), k=fdep(fx(WVR(i))); d=MAX(d,k);); + R d; +} + +I jtfdep(J jt,A w){A f,g;I d=0,k;V*v; + RZ(w); + v=VAV(w); + if(v->fdep)R v->fdep; + if(f=v->f) d=VERB&AT(f)?fdep(f):NOUN&AT(f)&&VGERL&v->flag?fdepger(f):0; + if(g=v->g){k=VERB&AT(g)?fdep(g):NOUN&AT(g)&&VGERR&v->flag?fdepger(g):0; d=MAX(d,k);} + if(CFORK==v->id){k=fdep(v->h); d=MAX(d,k);} + R v->fdep=1+d; +} /* function depth: 1 + max depth of components */ + +F1(jtfdepadv){RZ(w); ASSERT(VERB&AT(w),EVDOMAIN); R sc(fdep(w));} + + +DF1(jtdf1){RZ(self); R CALL1(VAV(self)->f1, w,self);} +DF2(jtdf2){RZ(self); R CALL2(VAV(self)->f2,a,w,self);} + +DF1(jtdfs1){A s=jt->sf,z; RZ(self); z=CALL1(VAV(self)->f1, w,jt->sf=self); jt->sf=s; R z;} +DF2(jtdfs2){A s=jt->sf,z; RZ(self); z=CALL2(VAV(self)->f2,a,w,jt->sf=self); jt->sf=s; R z;} + /* for monads and dyads that can possibly involve $: */ + +F1(jtself1){A z;I d=fdep(jt->sf); FDEPINC(d); z=df1( w,jt->sf); FDEPDEC(d); R z;} +F2(jtself2){A z;I d=fdep(jt->sf); FDEPINC(d); z=df2(a,w,jt->sf); FDEPDEC(d); R z;} + +A jtac1(J jt,AF f){R fdef(0,VERB, f,0L, 0L,0L,0L, 0L, RMAX,RMAX,RMAX);} +A jtac2(J jt,AF f){R fdef(0,VERB, 0L,f, 0L,0L,0L, 0L, RMAX,RMAX,RMAX);} + +F1(jtdomainerr1){ASSERT(0,EVDOMAIN);} +F2(jtdomainerr2){ASSERT(0,EVDOMAIN);} + +A jtfdef(J jt,C id,I t,AF f1,AF f2,A fs,A gs,A hs,I flag,I m,I l,I r){A z;V*v; + RE(0); + GA(z,t,1,0,0); v=VAV(z); + v->f1 =f1?f1:jtdomainerr1; /* monad C function */ + v->f2 =f2?f2:jtdomainerr2; /* dyad C function */ + v->f =fs; /* monad */ + v->g =gs; /* dyad */ + v->h =hs; /* fork right tine or other auxiliary stuff */ + v->flag =flag; + v->mr =m; /* monadic rank */ + v->lr =l; /* left rank */ + v->rr =r; /* right rank */ + v->fdep =0; /* function depth */ + v->id =id; /* spelling */ + R z; +} + +B nameless(A w){A f,g,h;C id;V*v; + if(!w||NOUN&AT(w))R 1; + v=VAV(w); + id=v->id; f=v->f; g=v->g; h=v->h; + R !(id==CTILDE&&NAME&AT(f)) && nameless(f) && nameless(g) && (id==CFORK?nameless(h):1); +} + +B jtprimitive(J jt,A w){A x=w;V*v; + RZ(w); + v=VAV(w); + if(CTILDE==v->id&&NOUN&AT(v->f))RZ(x=fix(w)); + R!VAV(x)->f; +} /* 1 iff w is a primitive */ + +B jtboxatop(J jt,A w){A x;C c;V*v; + RZ(w); + x=VAV(w)->f; v=VAV(x); c=v->id; + R COMPOSE(c)&&CBOX==ID(v->f); +} /* 1 iff "last" function in w is <@f */
new file mode 100755 --- /dev/null +++ b/bin/build_defs @@ -0,0 +1,29 @@ +#!/bin/bash +# compiles and runs c programs built by sym2ijs +# creates netdefs.ijs from netdefs.c +# creates hostdefs.ijs from hostdefs.c + +source bin/jconfig + +if [ $bits == 32 ] +then +suffix=".ijs" +else +suffix="_64.ijs" +fi + +rm -f defs/netdefs.ijs defs/hostdefs.ijs defs/temp +cc $M32 -D$un defs/netdefs.c -o defs/temp +defs/temp >defs/netdefs.ijs +cc $M32 -D$un defs/hostdefs.c -o defs/temp +defs/temp >defs/hostdefs.ijs +rm -f defs/temp + +if [ -e defs/hostdefs.ijs ] && [ -e defs/netdefs.ijs ] +then +cp defs/hostdefs.ijs j/system/defs/hostdefs_$lcun$suffix +cp defs/netdefs.ijs j/system/defs/netdefs_$lcun$suffix +echo success: new netdefs and hostdefs copied to j/system/defs +else +echo failed: build netdefs and/or hostdefs failed +fi
new file mode 100755 --- /dev/null +++ b/bin/build_jconsole @@ -0,0 +1,12 @@ +#!/bin/bash +source bin/jconfig +make jconsole + +if [ -x jconsole ] +then +cp jconsole j/bin/. +echo success: jconsole created and copied to j/bin +else +echo failed: jconsole NOT created +fi +
new file mode 100755 --- /dev/null +++ b/bin/build_libj @@ -0,0 +1,147 @@ +#!/bin/bash +TARGET=libj +source bin/jconfig + +LIBJ_OBJS="a.o \ +ab.o \ + af.o \ + ai.o \ + am.o \ + am1.o \ + amn.o \ + ao.o \ + ap.o \ + ar.o \ + as.o \ + au.o \ + c.o \ + ca.o \ + cc.o \ + cd.o \ + cf.o \ + cg.o \ + ch.o \ + cip.o \ + cl.o \ + cp.o \ + cpdtsp.o \ + cr.o \ + crs.o \ + ct.o \ + cu.o \ + cv.o \ + cx.o \ + d.o \ + dc.o \ + dss.o \ + dstop.o \ + dsusp.o \ +dtoa.o \ +f.o \ +f2.o \ +i.o \ +io.o \ +j.o \ +jdlllic.o \ +k.o \ +m.o \ +mbx.o \ +p.o \ +pv.o \ +px.o \ +r.o \ +rl.o \ +rt.o \ +s.o \ +sc.o \ +sl.o \ +sn.o \ +t.o \ +u.o \ +v.o \ +v0.o \ +v1.o \ +v2.o \ +va1.o \ +va2.o \ +va2s.o \ +vamultsp.o \ +vb.o \ +vbang.o \ +vbit.o \ +vcant.o \ +vchar.o \ +vcat.o \ +vcatsp.o \ +vcomp.o \ +vcompsc.o \ +vd.o \ +vdx.o \ +ve.o \ +vf.o \ +vfft.o \ +vfrom.o \ +vfromsp.o \ +vg.o \ +vgauss.o \ +vgcomp.o \ +vgranking.o \ +vgsort.o \ +vgsp.o \ +vi.o \ +viix.o \ +visp.o \ +vm.o \ +vo.o \ +vp.o \ +vq.o \ +vrand.o \ +vrep.o \ +vs.o \ +vsb.o \ +vt.o \ +vu.o \ +vx.o \ +vz.o \ +w.o \ +wc.o \ +wn.o \ +ws.o \ +x.o \ +x15.o \ +xa.o \ +xb.o \ +xc.o \ +xcrc.o \ +xd.o \ +xf.o \ +xfmt.o \ +xh.o \ +xi.o \ +xl.o \ +xo.o \ +xs.o \ +xt.o \ +xu.o " + +echo COMP $COMP +echo LINK $SOLINK +export LIBJ_OBJS + +echo takes minutes for a clean build +echo "running: make libj >& make.txt" +make libj >& make.txt + +# ignore incompatible pointer warnings (they are ok) +echo "(strip make.txt to errors and important warnings) > esum.txt" +cat make.txt | grep -Ev "assignment from incompatible pointer type|initialization from incompatible pointer type|-o|In function" > esum.txt + +cat esum.txt + +if [ -x libj.$SOSUFFIX ] +then +cp libj.$SOSUFFIX j/bin/. +echo success: libj.$SOSUFFIX created and copied to j/bin +else +echo failed: libj.$SOSUFFIX NOT created +fi
new file mode 100755 --- /dev/null +++ b/bin/build_tsdll @@ -0,0 +1,11 @@ +#!/bin/bash +TARGET=libtsdll +source bin/jconfig +make tsdll + +if [ -x libj.$SOSUFFIX ] +then +echo success: libtsdll.$SOSUFFIX created +else +echo failed: libtsdll.$SOSUFFIX NOT created +fi
new file mode 100755 --- /dev/null +++ b/bin/jconfig @@ -0,0 +1,73 @@ +# configuration for build shell scripts - edit to configure + +# bits 32 or 64 +bits=32 + +# readline 0 or 1 to enable jconsole line recall +readline=0 +LIBREADLINE="" + +# readline should be enabled if possible + +# remove # from next 2 lines to enable readline +# readline=1 +# LIBREADLINE=" -lreadline " + +# if link fails install readline or try one of next lines +# LIBREADLINE=" -ledit -lncurses " +# LIBREADLINE=" -ledit64 -lnccurses " + +# be careful with changes after this line + +un=`uname` +lcun=$( echo "$un" | tr -s '[:upper:]' '[:lower:]' ) + +if [ $un != Linux ] && [ $un != Darwin ] +then +echo jconfig: not Linux or Darwin - changes to jconfig and other files required +exit 1 +fi + +if [ $bits != 32 ] && [ $bits != 64 ] +then +echo jconfig: bits must be 32 or 64 +exit 1 +fi + +if [ $readline != 0 ] && [ $readline != 1 ] +then +echo jconfig: readline must be 0 or 1 +exit 1 +fi + +COMP=" -fPIC -O3 -fno-strict-aliasing -DNOASM " + +if [ $un == Linux ] +then +SOLINK=" -shared -W1,soname,libj.so -lm -ldl -o " +SOSUFFIX=so +fi + +if [ $un == Darwin ] +then +SOLINK=" -dynamiclib -lm -ldl -o " +SOSUFFIX=dylib +fi + +if [ $bits == 32 ] +then +COMP=" -m32 $COMP " +SOLINK=" -m32 $SOLINK " +M32=" -m32 " +else +COMP=" -D_UNIX64 $COMP " +M32="" +fi + +if [ $readline == 1 ] +then +COMP="-DREADLINE $COMP " +fi + +SOLINK=" $SOLINK $TARGET.$SOSUFFIX " +export COMP SOLINK M32 LIBREADLINE
new file mode 100644 --- /dev/null +++ b/c.c @@ -0,0 +1,38 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions */ + +#include "j.h" + + +static CS1(obv1, CALL1(f1, w,fs)) +static CS2(obv2, CALL2(f2,a,w,fs)) + +F2(jtobverse){ASSERTVV(a,w); R CDERIV(COBVERSE,obv1,obv2,mr(a),lr(a),rr(a));} + + +static DF1(ad1){DECLFG;A z;I od=jt->db; + RZ(w); + jt->db=0; z=CALL1(f1, w,fs); jt->db=od; + if(EWTHROW==jt->jerr)R 0; + RESETERR; + R z?z:CALL1(g1, w,gs); +} + +static DF2(ad2){DECLFG;A z;I od=jt->db; + RZ(a&&w); + jt->db=0; z=CALL2(f2,a,w,fs); jt->db=od; + if(EWTHROW==jt->jerr)R 0; + RESETERR; + R z?z:CALL2(g2,a,w,gs); +} + +F2(jtadverse){ASSERTVV(a,w); R CDERIV(CADVERSE,ad1,ad2,RMAX,RMAX,RMAX);} + + +static CS1(even1, halve(df1(w,folk(fs,ds(CPLUS ),atop(fs,gs))))) +static CS1(odd1, halve(df1(w,folk(fs,ds(CMINUS),atop(fs,gs))))) + +F2(jteven){ASSERTVV(a,w); R CDERIV(CEVEN,even1,0L, RMAX,0L,0L);} +F2(jtodd ){ASSERTVV(a,w); R CDERIV(CODD, odd1, 0L, RMAX,0L,0L);}
new file mode 100644 --- /dev/null +++ b/ca.c @@ -0,0 +1,247 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Atop and Ampersand */ + +#include "j.h" + + +static DF1(jtonf1){PROLOG;DECLFG;A z;I flag=sv->flag,m=jt->xmode; + PREF1(jtonf1); + if(primitive(gs))if(flag&VFLR)jt->xmode=XMFLR; else if(flag&VCEIL)jt->xmode=XMCEIL; + if(RAT&AT(w))RZ(w=pcvt(XNUM,w)); + z=CALL1(f1,CALL1(g1,w,gs),fs); + jt->xmode=m; + EPILOG(z); +} + +static DF2(jtuponf2){PROLOG;DECLFG;A z;I flag=sv->flag,m=jt->xmode; + RZ(a&&w); + if(primitive(gs))if(flag&VFLR)jt->xmode=XMFLR; else if(flag&VCEIL)jt->xmode=XMCEIL; + if(RAT&AT(a))RZ(a=pcvt(XNUM,a)); + if(RAT&AT(w))RZ(w=pcvt(XNUM,w)); + z=INT&AT(a)&&INT&AT(w)&&CDIV==ID(gs)?intdiv(a,w):CALL1(f1,CALL2(g2,a,w,gs),fs); + jt->xmode=m; + EPILOG(z); +} + +static X jtxmodpow(J jt,A a,A w,A h){A ox,z; + if(!(XNUM&AT(a)))RZ(a=cvt(XNUM,a)); + if(!(XNUM&AT(w)))RZ(w=cvt(XNUM,w)); + if(!(XNUM&AT(h)))RZ(h=cvt(XNUM,h)); + ox=jt->xmod; jt->xmod=h; + GA(z,XNUM,1,0,0); *XAV(z)=xpow(*XAV(a),*XAV(w)); + jt->xmod=ox; + RNE(z); +} + +#define DMOD 46340 /* <. %: _1+2^31 */ + +#if SY_64 +#define XMOD 3037000499 /* <. %: _1+2^63 */ +#else +#define XMOD 94906265 /* <. %: _1+2^53 */ +static I dmodpow(D x,I n,D m){D z=1; while(n){if(1&n)z=fmod(z*x,m); x=fmod(x*x,m); n>>=1;} R(I)z;} +#endif + +static I imodpow(I x,I n,I m){I z=1; while(n){if(1&n)z=(z*x)%m; x=(x*x)%m; n>>=1;} R z;} + +static DF2(jtmodpow2){A h;B b,c;I at,m,n,wt,x,z; + PREF2(jtmodpow2); + h=VAV(self)->h; + if(RAT&AT(a))RZ(a=pcvt(XNUM,a)) else if(!(AT(a)&INT+XNUM))RZ(a=pcvt(INT,a)); + if(RAT&AT(w))RZ(w=pcvt(XNUM,w)) else if(!(AT(w)&INT+XNUM))RZ(w=pcvt(INT,w)); + at=AT(a); wt=AT(w); + if((AT(h)&XNUM||at&XNUM||wt&XNUM)&&at&XNUM+INT&&wt&INT+XNUM){A z; + z=xmodpow(a,w,h); if(!jt->jerr)R z; RESETERR; R residue(h,expn2(a,w)); + } + n=*AV(w); + if(!(INT&at&&INT&wt&&0<=n))R residue(h,expn2(a,w)); + m=*AV(h); x=*AV(a); + if(!m)R expn2(a,w); + if(XMOD<m||XMOD<-m||m==IMIN||x==IMIN)R cvt(INT,xmodpow(a,w,h)); + if(b=0>m)m=-m; + if(c=0>x)x=-x; x=x%m; if(c)x=m-x; +#if SY_64 + z=imodpow(x,n,m); +#else + z=m>DMOD?dmodpow((D)x,n,(D)m):imodpow(x,n,m); +#endif + R sc(b?z-m:z); +} /* a m&|@^ w ; m guaranteed to be INT or XNUM */ + +static DF1(jtmodpow1){A g=VAV(self)->g; R rank2ex(VAV(g)->f,w,self,0L,0L,jtmodpow2);} + /* m&|@(n&^) w ; m guaranteed to be INT or XNUM */ + +static CS1(on1, CALL1(f1,CALL1(g1,w,gs),fs)) +static CS2(jtupon2,CALL1(f1,CALL2(g2,a,w,gs),fs)) + +static DF2(on2){PROLOG;DECLFG;A ga,gw,z; + PREF2(on2); + gw=CALL1(g1,w,gs); + ga=CALL1(g1,a,gs); + z=CALL2(f2,ga,gw,fs); + EPILOG(z); +} + +static DF2(atcomp){AF f; + RZ(a&&w); + f=atcompf(a,w,self); + R f?f(jt,a,w,self):upon2(a,w,self); +} + +static DF2(atcomp0){A z;AF f;D oldct=jt->ct; + RZ(a&&w); + f=atcompf(a,w,self); + jt->ct=0; z=f?f(jt,a,w,self):upon2(a,w,self); jt->ct=oldct; + R z; +} + +F2(jtatop){A f,g,h=0,x;AF f1=on1,f2=jtupon2;B b=0,j;C c,d,e;I flag=0,m=-1;V*av,*wv; + ASSERTVV(a,w); + av=VAV(a); c=av->id; + wv=VAV(w); d=wv->id; + switch(c){ + case CNOT: if(d==CMATCH){f2=jtnotmatch; flag+=VIRS2;} break; + case CGRADE: if(d==CGRADE){f1=jtranking; flag+=VIRS1;} break; + case CSLASH: if(d==CCOMMA)f1=jtredravel; break; + case CCEIL: f1=jtonf1; f2=jtuponf2; flag=VCEIL; break; + case CFLOOR: f1=jtonf1; f2=jtuponf2; flag=VFLR; break; + case CICAP: if(d==CNE)f1=jtnubind; else if(FIT0(CNE,wv))f1=jtnubind0; break; + case CQUERY: if(d==CDOLLAR||d==CPOUND)f2=jtrollk; break; + case CQRYDOT: if(d==CDOLLAR||d==CPOUND)f2=jtrollkx; break; + case CRAZE: if(d==CCUT&&boxatop(w)){f1=jtrazecut1; f2=jtrazecut2;} break; + case CSLDOT: if(d==CSLASH&&CSLASH==ID(av->f))f2=jtpolymult; break; + case CQQ: if(d==CTHORN&&CEXEC==ID(av->f)&&equ(zero,av->g))f1=jtdigits10; break; + case CEXP: if(d==CCIRCLE)f1=jtexppi; break; + case CAMP: + x=av->f; if(RAT&AT(x))RZ(x=pcvt(XNUM,x)); + if((d==CEXP||d==CAMP&&CEXP==ID(wv->g))&&AT(x)&INT+XNUM&&!AR(x)&&CSTILE==ID(av->g)){ + h=x; flag=VMOD; + if(d==CEXP)f2=jtmodpow2; else f1=jtmodpow1; + }} + if(d==CEBAR||d==CEPS||(b=FIT0(CEPS,wv))){ + f=av->f; g=av->g; e=ID(f); if(b)d=ID(wv->f); + if(c==CICAP)m=7; + else if(c==CSLASH)m=e==CPLUS?4:e==CPLUSDOT?5:e==CSTARDOT?6:-1; + else if(c==CAMP&&(g==zero||g==one)){j=*BAV(g); m=e==CIOTA?j:e==CICO?2+j:-1;} + switch(0<=m?d:-1){ + case CEBAR: f2=b?atcomp0:atcomp; flag=6+8*m; break; + case CEPS: f2=b?atcomp0:atcomp; flag=7+8*m; break; + }} + R fdef(CAT,VERB, f1,f2, a,w,h, flag, (I)wv->mr,(I)wv->lr,(I)wv->rr); +} + +F2(jtatco){A f,g;AF f1=on1,f2=jtupon2;B b=0;C c,d,e;I flag=0,j,m=-1;V*av,*wv; + ASSERTVV(a,w); + av=VAV(a); c=av->id; f=av->f; g=av->g; e=ID(f); + wv=VAV(w); d=wv->id; + switch(c){ + case CNOT: if(d==CMATCH){f2=jtnotmatch; flag+=VIRS2;} break; + case CGRADE: if(d==CGRADE){f1=jtranking; flag+=VIRS1;} break; + case CCEIL: f1=jtonf1; f2=jtuponf2; flag=VCEIL; break; + case CFLOOR: f1=jtonf1; f2=jtuponf2; flag=VFLR; break; + case CQUERY: if(d==CDOLLAR||d==CPOUND)f2=jtrollk; break; + case CQRYDOT: if(d==CDOLLAR||d==CPOUND)f2=jtrollkx; break; + case CICAP: m=7; if(d==CNE)f1=jtnubind; else if(FIT0(CNE,wv))f1=jtnubind0; break; + case CAMP: if(g==zero||g==one){j=*BAV(g); m=e==CIOTA?j:e==CICO?2+j:-1;} break; + case CSLASH: + if(vaid(f)&&vaid(w))f2=jtfslashatg; + if(d==CCOMMA)f1=jtredravel; else m=e==CPLUS?4:e==CPLUSDOT?5:e==CSTARDOT?6:-1; + break; + case CSEMICO: + if(d==CLBRACE)f2=jtrazefrom; + else if(d==CCUT){ + j=i0(wv->g); + if(CBOX==ID(wv->f)&&!j)f2=jtrazecut0; + else if(boxatop(w)&&j&&-2<=j&&j<=2){f1=jtrazecut1; f2=jtrazecut2;} + }} + if(0<=m){ + b=d==CFIT&&equ(zero,wv->g); + switch(b?ID(wv->f):d){ + case CEQ: f2=b?atcomp0:atcomp; flag=0+8*m; break; + case CNE: f2=b?atcomp0:atcomp; flag=1+8*m; break; + case CLT: f2=b?atcomp0:atcomp; flag=2+8*m; break; + case CLE: f2=b?atcomp0:atcomp; flag=3+8*m; break; + case CGE: f2=b?atcomp0:atcomp; flag=4+8*m; break; + case CGT: f2=b?atcomp0:atcomp; flag=5+8*m; break; + case CEBAR: f2=b?atcomp0:atcomp; flag=6+8*m; break; + case CEPS: f2=b?atcomp0:atcomp; flag=7+8*m; break; + }} + R fdef(CATCO,VERB, f1,f2, a,w,0L, flag, RMAX,RMAX,RMAX); +} + +F2(jtampco){AF f1=on1;C c,d;I flag=0;V*wv; + ASSERTVV(a,w); + c=ID(a); wv=VAV(w); d=wv->id; + if (c==CSLASH&&d==CCOMMA) f1=jtredravel; + else if(c==CRAZE&&d==CCUT&&boxatop(w))f1=jtrazecut1; + else if(c==CGRADE&&d==CGRADE) {f1=jtranking; flag+=VIRS1;} + R fdef(CAMPCO,VERB, f1,on2, a,w,0L, flag, RMAX,RMAX,RMAX); +} + +static DF1(withl){DECLFG; R jt->rank?irs2(fs,w,gs,AR(fs),jt->rank[1],g2):CALL2(g2,fs,w,gs);} +static DF1(withr){DECLFG; R jt->rank?irs2(w,gs,fs,jt->rank[1],AR(gs),f2):CALL2(f2,w,gs,fs);} + +static DF1(ixfixedleft ){V*v=VAV(self); R indexofprehashed(v->f,w,v->h);} +static DF1(ixfixedright ){V*v=VAV(self); R indexofprehashed(v->g,w,v->h);} + +static DF1(ixfixedleft0 ){A z;D old=jt->ct;V*v=VAV(self); + jt->ct=0.0; z=indexofprehashed(v->f,w,v->h); jt->ct=old; + R z; +} + +static DF1(ixfixedright0){A z;D old=jt->ct;V*v=VAV(self); + jt->ct=0.0; z=indexofprehashed(v->g,w,v->h); jt->ct=old; + R z; +} + +static DF2(with2){R df1(w,powop(self,a));} + +F2(jtamp){A h=0;AF f1=on1,f2=on2;B b;C c,d=0;D old=jt->ct;I flag=0,mode=-1,p,r;V*u,*v; + RZ(a&&w); + switch(CONJCASE(a,w)){ + default: ASSERTSYS(0,"amp"); + case NN: ASSERT(0,EVDOMAIN); + case NV: + f1=withl; v=VAV(w); c=v->id; + if(AN(a)&&AR(a)){ + if(b=c==CFIT&&equ(zero,v->g))c=ID(v->f); + mode=c==CIOTA?IIDOT:c==CICO?IICO:-1; + } + if(0<=mode){ + if(b){jt->ct=0.0; h=indexofsub(mode,a,mark); jt->ct=old; f1=ixfixedleft0;} + else { h=indexofsub(mode,a,mark); f1=ixfixedleft ;} + }else switch(c){ + case CWORDS: RZ(a=fsmvfya(a)); f1=jtfsmfx; break; + case CIBEAM: if(v->f&&v->g&&128==i0(v->f)&&3==i0(v->g)){RZ(h=crccompile(a)); f1=jtcrcfixedleft;} + } + R fdef(CAMP,VERB, f1,with2, a,w,h, flag, RMAX,RMAX,RMAX); + case VN: + f1=withr; + if(AN(w)&&AR(w)){ + v=VAV(a); c=v->id; p=v->flag%256; if(b=c==CFIT&&equ(zero,v->g))c=ID(v->f); + if(7==p%8)mode=II0EPS+p/8; /* (e.i.0:) etc. */ + else mode=c==CEPS?IEPS:c==CLESS?ILESS:-1; + } + if(0<=mode){ + if(b){jt->ct=0.0; h=indexofsub(mode,w,mark); jt->ct=old; f1=ixfixedright0;} + else { h=indexofsub(mode,w,mark); f1=ixfixedright ;} + } + R fdef(CAMP,VERB, f1,with2, a,w,h, flag, RMAX,RMAX,RMAX); + case VV: + v=VAV(w); c=v->id; r=v->mr; + if(c==CFORK||c==CAMP){ + if(c==CFORK)d=ID(v->h); + if(CIOTA==ID(v->g)&&(!d||d==CLEFT||d==CRIGHT)&&equ(alp,v->f)){ + u=VAV(a); d=u->id; + if(d==CLT||d==CLE||d==CEQ||d==CNE||d==CGE||d==CGT)f2=jtcharfn2; + }}else switch(ID(a)){ + case CGRADE: if(c==CGRADE){f1=jtranking; flag+=VIRS1;} break; + case CSLASH: if(c==CCOMMA)f1=jtredravel; break; + case CCEIL: f1=jtonf1; flag=VCEIL; break; + case CFLOOR: f1=jtonf1; flag=VFLR; break; + case CRAZE: if(c==CCUT&&boxatop(w))f1=jtrazecut1; + } + R fdef(CAMP,VERB, f1,f2, a,w,0L, flag, r,r,r); +}}
new file mode 100644 --- /dev/null +++ b/cc.c @@ -0,0 +1,638 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Cuts */ + +#include "j.h" + + +static DF1(jtcut01){DECLF;A h,x; + RZ(x=from(box(every(negate(shape(w)),0L,jtiota)),w)); + if(VGERL&sv->flag){h=sv->h; R df1(x,*AAV(h));}else R CALL1(f1,x,fs); +} /* f;.0 w */ + +static F2(jtcut02v){A z;I*av,e,j,k,m,t,wk; + m=AN(w); t=AT(w); wk=bp(t); + av=AV(a); j=av[0]; e=av[1]; k=ABS(e); + ASSERT(!e||-m<=j&&j<m,EVINDEX); + if(0>j){j+=1+m-k; if(0>j){k+=j; j=0;}}else k=MIN(k,m-j); + GA(z,t,k,1,0); + MC(AV(z),CAV(w)+wk*j,wk*k); + R 0>e?reverse(z):z; +} /* a ];.0 vector */ + +static F2(jtcut02m){A z;C*u,*v;I*av,c,d,e0,e1,j0,j1,k0,k1,m0,m1,*s,t,wk; + s=AS(w); m0=s[0]; m1=s[1]; t=AT(w); wk=bp(t); + av=AV(a); + if(4==AN(a)){j0=av[0]; e0=av[2]; k0=ABS(e0); j1=av[1]; e1=av[3]; k1=ABS(e1);} + else {j0=av[0]; e0=av[1]; k0=ABS(e0); j1=0; e1=m1; k1=e1; } + ASSERT(!e0||-m0<=j0&&j0<m0,EVINDEX); + ASSERT(!e1||-m1<=j1&&j1<m1,EVINDEX); + if(0>j0){j0+=1+m0-k0; if(0>j0){k0+=j0; j0=0;}}else k0=MIN(k0,m0-j0); + if(0>j1){j1+=1+m1-k1; if(0>j1){k1+=j1; j1=0;}}else k1=MIN(k1,m1-j1); + GA(z,t,k0*k1,2,0); s=AS(z); s[0]=k0; s[1]=k1; + u=CAV(z); c=wk*k1; + if(0>e0){d=-wk*m1; v=CAV(w)+wk*(j0*m1+j1+m1*(k0-1));} + else {d= wk*m1; v=CAV(w)+wk*(j0*m1+j1 );} + DO(k0, MC(u,v,c); u+=c; v+=d;); + R 0>e1?irs1(z,0L,1L,jtreverse):z; +} /* a ];.0 matrix */ + +static DF2(jtcut02){DECLF;A h=0,*hv,q,qq,*qv,y,z,*zv;C id;I*as,c,d,e,hn,i,ii,j,k,m,n,*u,*ws; + RZ(a&&w); + if(VGERL&sv->flag){h=sv->h; hv=AAV(h); hn=AN(h);} + id=h?0:ID(fs); d=h?0:id==CBOX?1:2; + if(1>=AR(a))RZ(a=lamin2(zero,a)); + RZ(a=vib(a)); + if(2==AR(a)&&(id==CLEFT||id==CRIGHT)&&AT(w)&B01+LIT+INT+FL+CMPX) + if (2==AN(a)&&1==AR(w))R cut02v(a,w); + else if(4>=AN(a)&&2==AR(w))R cut02m(a,w); + as=AS(a); m=AR(a)-2; RE(n=prod(m,as)); c=as[1+m]; u=AV(a); + ASSERT(2==as[m]&&c<=AR(w),EVLENGTH); + if(!n){ /* empty result; figure out result type */ + switch(d){ + case 0: y=df1(w,*hv); RESETERR; break; + case 1: y=ace; break; + case 2: y=CALL1(f1,w,fs); RESETERR; break; + } + GA(z,y?AT(y):B01,n,m,as); R z; + } + ws=AS(w); + GA(z,BOX,n,m,as); zv=AAV(z); + GA(q,BOX,c,1,0); qv=AAV(q); + GA(qq,BOX,1,0,0); *AAV(qq)=q; + for(ii=0;ii<n;++ii){ + for(i=0;i<c;++i){ + m=ws[i]; j=u[i]; e=u[i+c]; k=ABS(e); + ASSERT(!e||-m<=j&&j<m,EVINDEX); + if(0>j){j+=1+m-k; if(0>j){k+=j; j=0;}}else k=MIN(k,m-j); + RZ(qv[i]=0>e?apv(k,j+k-1,-1L):0==j&&k==m?ace:apv(k,j,1L)); + } + RZ(y=from(qq,w)); u+=c+c; + switch(d){ + case 0: RZ(*zv++=df1(y,hv[ii%hn])); break; + case 1: RZ(*zv++=y); break; + case 2: RZ(*zv++=CALL1(f1,y,fs)); break; + }} + R 1==d?z:ope(z); +} /* a f;.0 w */ + +DF2(jtrazecut0){A z;C*v,*wv,*zu,*zv;I ar,*as,*av,c,d,i,j,k,m,n,q,wt,zn; + RZ(a&&w); + n=AN(w); wt=AT(w); wv=CAV(w); + ar=AR(a); as=AS(a); m=2==ar?1:*as; + if(!((2==ar||3==ar)&&wt&IS1BYTE&&1==AR(w)))R raze(df2(a,w,cut(ds(CBOX),zero))); + ASSERT(2==as[ar-2]&&1==as[ar-1],EVLENGTH); + RZ(a=vib(a)); av=AV(a); + RZ(z=exta(wt,1L,1L,n/2)); zn=AN(z); zv=CAV(z); zu=zn+zv; + for(i=0;i<m;++i){ + j=*av++; k=*av++; + ASSERT(-n<=j&&j<n,EVINDEX); + q=0<=k?k:k==IMIN?IMAX:-k; d=0<=j?MIN(q,n-j):MIN(q,n+1+j); + while(zu<d+zv){c=zv-CAV(z); RZ(z=ext(0,z)); zn=AN(z); v=CAV(z); zv=c+v; zu=zn+v;} + switch((0<=j?2:0)+(0<=k)){ + case 0: v=wv+j+n+1; DO(d, *zv++=*--v;); break; + case 1: v=wv+j+n+1-d; DO(d, *zv++=*v++;); break; + case 2: v=wv+j+d; DO(d, *zv++=*--v;); break; + case 3: v=wv+j; DO(d, *zv++=*v++;); + }} + AN(z)=*AS(z)=zv-CAV(z); + R z; +} /* a ;@:(<;.0) vector */ + + +static DF2(jtcut2bx){A*av,b,t,x,*xv,y,*yv;B*bv;I an,ad,bn,i,j,m,p,q,*u,*v,*ws;V*sv; + RZ(a&&w&&self); + sv=VAV(self); q=*AV(sv->g); + an=AN(a); av=AAV(a); ad=(I)a*ARELATIVE(a); ws=AS(w); + ASSERT(an<=AR(w),EVLENGTH); + GA(x,BOX,an,1,0); xv=AAV(x); + GA(y,BOX,an,1,0); yv=AAV(y); + for(i=0;i<an;++i){ + b=AVR(i); bn=AN(b); m=ws[i]; + ASSERT(1>=AR(b),EVRANK); + if(!bn&&m){xv[i]=zero; RZ(yv[i]=sc(m));} + else{ + if(!(B01&AT(b)))RZ(b=cvt(B01,b)); + if(!AR(b)){if(*BAV(b)){RZ(xv[i]=IX(m)); RZ(yv[i]=reshape(sc(m),0<q?one:zero));}else xv[i]=yv[i]=mtv; continue;} + ASSERT(bn==m,EVLENGTH); + bv=BAV(b); p=0; DO(bn, p+=bv[i];); + GA(t,INT,p,1,0); u=AV(t); xv[i]=t; + GA(t,INT,p,1,0); v=AV(t); yv[i]=t; j=-1; + if(p)switch(q){ + case 1: DO(bn, if(bv[i]){*u++=i ; if(0<=j)*v++=i-j ; j=i;}); *v=bn-j; break; + case -1: DO(bn, if(bv[i]){*u++=i+1; if(0<=j)*v++=i-j-1; j=i;}); *v=bn-j-1; break; + case 2: DO(bn, if(bv[i]){*u++=j+1; *v++=i-j ; j=i;}); break; + case -2: DO(bn, if(bv[i]){*u++=j+1; *v++=i-j-1; j=i;}); break; + }}} + RZ(x=ope(catalog(x))); + RZ(y=ope(catalog(y))); + RZ(t=AN(x)?irs2(x,y,0L,1L,1L,jtlamin2):iota(over(shape(x),v2(2L,0L)))); + R cut02(t,w,self); +} /* a f;.n w for boxed a, with special code for matrix w */ + + +#define MCREL(uu,vv,n) {A*u=(A*)(uu);A*v=(A*)(vv); DO((n), u[i]=AADR(wd,v[i]););} + +#define CUTSWITCH(EACHC) \ + switch(wd?0:id){A z,*za;C id1,*v1,*zc;I d,i,j,ke,q,*zi,*zs; \ + case CPOUND: \ + GA(z,INT,m,1,0); zi=AV(z); EACHC(*zi++=d;); R z; \ + case CDOLLAR: \ + GA(z,INT,m,1,0); zi=AV(z); EACHC(*zi++=d;); \ + R irs2(z,vec(INT,MAX(0,r-1),1+s),0L,0L,1L,jtover); \ + case CHEAD: \ + GA(z,t,m*c,r,s); zc=CAV(z); *AS(z)=m; \ + EACHC(ASSERT(d,EVINDEX); MC(zc,v1,k); zc+=k;); \ + R z; \ + case CTAIL: \ + GA(z,t,m*c,r,s); zc=CAV(z); *AS(z)=m; \ + EACHC(ASSERT(d,EVINDEX); MC(zc,v1+k*(d-1),k); zc+=k;); \ + R z; \ + case CCOMMA: \ + case CLEFT: \ + case CRIGHT: \ + e-=e&&neg; RE(d=mult(m*c,e)); \ + GA(z,t,d,id==CCOMMA?2:1+r,s-1); zc=CAV(z); fillv(t,d,zc); \ + zs=AS(z); zs[0]=m; zs[1]=id==CCOMMA?e*c:e; ke=k*e; \ + EACHC(MC(zc,v1,d*k); zc+=ke;); \ + R z; \ + case CBOX: \ + GA(z,m?BOX:B01,m,1,0); za=AAV(z); \ + EACHC(GA(y,t,d*c,r,s); *AS(y)=d; MC(AV(y),v1,d*k); *za++=y;); \ + R z; \ + case CAT: case CATCO: case CAMP: case CAMPCO: \ + if(CBOX==ID(vf->f)&&(id1=ID(vf->g),id1==CBEHEAD||id1==CCTAIL)){ \ + GA(z,m?BOX:B01,m,1,0); za=AAV(z); \ + EACHC(d=d?d-1:0; GA(y,t,d*c,r,s); *AS(y)=d; MC(AV(y),id1==CBEHEAD?v1+k:v1,d*k); *za++=y;); \ + R z; \ + } \ + /* note: fall through */ \ + default: \ + if(!m){y=reitem(zero,w); R iota(over(zero,shape(h?df1(y,*hv):CALL1(f1,y,fs))));} \ + GA(z,BOX,m,1,0); za=AAV(z); j=0; \ + switch((wd?2:0)+(h?1:0)){ \ + case 0: EACHC(GA(y,t,d*c,r,s); *AS(y)=d; MC(AV(y),v1,d*k); RZ(*za++=CALL1(f1,y,fs)); ); break; \ + case 1: EACHC(GA(y,t,d*c,r,s); *AS(y)=d; MC(AV(y),v1,d*k); RZ(*za++=df1(y,hv[j])); j=(1+j)%hn;); break; \ + case 2: EACHC(GA(y,t,d*c,r,s); *AS(y)=d; MCREL(AV(y),v1,d); RZ(*za++=CALL1(f1,y,fs)); ); break; \ + case 3: EACHC(GA(y,t,d*c,r,s); *AS(y)=d; MCREL(AV(y),v1,d); RZ(*za++=df1(y,hv[j])); j=(1+j)%hn;); break; \ + } \ + EPILOG(ope(z)); \ + } + +#define EACHCUTSP(stmt) \ + if(pfx)for(i=m;i>=1;--i){q=yu[i-1]-yu[i ]; d=q-neg; v1=wv+k*(b+p); stmt; p+=q;} \ + else for(i=1;i<=m;++i){q=yu[i ]-yu[i-1]; d=q-neg; v1=wv+k*(b+p); stmt; p+=q;} + +static F1(jtcps){A z;P*wp,*zp; + GA(z,AT(w),1,AR(w),AS(w)); + zp=PAV(z); + wp=PAV(w); + SPB(zp,a,SPA(wp,a)); + SPB(zp,e,SPA(wp,e)); + SPB(zp,i,SPA(wp,i)); + R z; +} + +static A jtselx(J jt,A x,I r,I i){A z;I c,k; + c=aii(x); k=c*bp(AT(x)); + GA(z,AT(x),r*c,AR(x),AS(x)); *AS(z)=r; + MC(CAV(z),CAV(x)+i*k,r*k); + R z; +} /* (i+i.r){x */ + +static A jtsely(J jt,A y,I r,I i,I j){A z;I c,*s,*v; + c=*(1+AS(y)); + GA(z,INT,r*c,2,0); s=AS(z); s[0]=r; s[1]=c; + v=AV(z); + ICPY(v,AV(y)+i*c,r*c); + DO(r, *v-=j; v+=c;); + R z; +} /* ((i+i.r){y)-"1 ({:$y){.j */ + +static DF2(jtcut2); + +static DF2(jtcut2sx){PROLOG;DECLF;A h=0,*hv,y,yy;B b,neg,pfx,*u,*v;C id;I d,e,hn,m,n,p,t,yn,*yu,*yv;P*ap;V*vf; + PREF2(jtcut2sx); + n=IC(w); t=AT(w); m=*AV(sv->g); neg=0>m; pfx=m==1||m==-1; b=neg&&pfx; + RZ(a=a==mark?eps(w,take(num[pfx?1:-1],w)):DENSE&AT(a)?sparse1(a):a); + ASSERT(n==*AS(a),EVLENGTH); + ap=PAV(a); + if(!(equ(zero,SPA(ap,e))&&AN(SPA(ap,a))))R cut2(cvt(B01,a),w,self); + vf=VAV(fs); + if(VGERL&sv->flag){h=sv->h; hv=AAV(h); hn=AN(h); id=0;}else id=vf->id; + y=SPA(ap,i); yn=AN(y); yv=AV(y); u=v=BAV(SPA(ap,x)); e=m=0; + GA(yy,INT,1+yn,1,0); yu=AV(yy); *yu++=p=pfx?n:-1; + switch(pfx+(id==CLEFT||id==CRIGHT||id==CCOMMA?2:0)){ + case 0: DO(yn, if(*v){++m; *yu++= yv[v-u]; } ++v;); break; + case 1: v+=yn-1; DO(yn, if(*v){++m; *yu++= yv[v-u]; } --v;); break; + case 2: DO(yn, if(*v){++m; d=p; *yu++=p=yv[v-u]; e=MAX(e,p-d);} ++v;); break; + case 3: v+=yn-1; DO(yn, if(*v){++m; d=p; *yu++=p=yv[v-u]; e=MAX(e,d-p);} --v;); + } + yu=AV(yy); p=pfx?yu[m]:0; + if(t&DENSE){C*wv;I c,k,r,*s,wd; + r=MAX(1,AR(w)); s=AS(w); wv=CAV(w); c=aii(w); k=c*bp(t); wd=(I)w*ARELATIVE(w); + CUTSWITCH(EACHCUTSP) + }else if(id==CPOUND){A z;I i,*zi; + GA(z,INT,m,1,0); zi=AV(z); + if(pfx)for(i=m;i>=1;--i)*zi++=(yu[i-1]-yu[i ])-neg; + else for(i=1;i<=m;++i)*zi++=(yu[i ]-yu[i-1])-neg; + EPILOG(z); + }else{A a,ww,x,y,z,*za;I c,i,j,q,qn,r;P*wp,*wwp; + wp=PAV(w); a=SPA(wp,a); x=SPA(wp,x); y=SPA(wp,i); yv=AV(y); r=*AS(y); c=*(1+AS(y)); + RZ(ww=cps(w)); wwp=PAV(ww); + GA(z,BOX,m,1,0); za=AAV(z); + switch(AN(a)&&*AV(a)?2+pfx:pfx){ + case 0: + p=yu[0]; DO(r, if(p<=yv[c*i]){p=i; break;}); + for(i=1;i<=m;++i){ + j=yu[i]; DO(q=r-p, if(j<yv[c*(p+i)]){q=i; break;}); qn=q; + if(neg)DO(qn=r-p, if(j-1<yv[c*(p+i)]){qn=i; break;}); + *AS(ww)=(yu[i]-yu[i-1])-neg; + SPB(wwp,i,sely(y,qn,p,1+yu[i-1])); + SPB(wwp,x,selx(x,qn,p)); + RZ(*za++=h?df1(ww,hv[(i-1)%hn]):CALL1(f1,ww,fs)); + p+=q; if(1<AC(ww)){RZ(ww=cps(w)); wwp=PAV(ww);} + } + break; + case 1: + p=yu[m]; DO(r, if(p<=yv[c*i]){p=i; break;}); + for(i=m;i>=1;--i){ + j=yu[i-1]; DO(q=r-p, if(j<=yv[c*(p+i)]){q=i; break;}); qn=q; + if(neg){j=yu[i]; qn=0; DO(r-p, if(j<yv[c*(p+i)]){qn=q-i; break;});} + *AS(ww)=(yu[i-1]-yu[i])-neg; + SPB(wwp,i,sely(y,qn,p+q-qn,yu[i]+neg)); + SPB(wwp,x,selx(x,qn,p+q-qn)); + RZ(*za++=h?df1(ww,hv[(m-i)%hn]):CALL1(f1,ww,fs)); + p+=q; if(1<AC(ww)){RZ(ww=cps(w)); wwp=PAV(ww);} + } + break; + case 2: + for(i=1;i<=m;++i){ + q=yu[i]-yu[i-1]; *AS(ww)=q-neg; + SPB(wwp,x,irs2(apv(q-neg,p,1L),x,0L,1L,-1L,jtfrom)); + RZ(*za++=h?df1(ww,hv[(i-1)%hn]):CALL1(f1,ww,fs)); + p+=q; if(1<AC(ww)){RZ(ww=cps(w)); wwp=PAV(ww);} + } + break; + case 3: + for(i=m;i>=1;--i){ + q=yu[i-1]-yu[i]; *AS(ww)=q-neg; + SPB(wwp,x,irs2(apv(q-neg,p+neg,1L),x,0L,1L,-1L,jtfrom)); + RZ(*za++=h?df1(ww,hv[(i-1)%hn]):CALL1(f1,ww,fs)); + p+=q; if(1<AC(ww)){RZ(ww=cps(w)); wwp=PAV(ww);} + } + break; + } + EPILOG(ope(z)); +}} /* sparse f;.n (dense or sparse) */ + + +static C*jtidenv0(J jt,A a,A w,V*sv,I zt,A*zz){A fs,y; + *zz=0; + fs=sv->f; + RE(y=df1(zero,iden(VAV(fs)->f))); + if(zt<AT(y)){*zz=df1(cut2(a,w,cut(ds(CBOX),sv->g)),amp(fs,ds(COPE))); R 0;} + if(zt>AT(y))RE(y=cvt(zt,y)); + R CAV(y); +} /* pointer to identity element */ + +#define EACHCUT(stmt) \ + for(i=1;i<=m;++i){ \ + if(pfx&&i==m)q=p; \ + else{u=memchr(v+pfx,sep,p-pfx); u+=!pfx; q=u-v;} \ + d=q-neg; v1=wv+k*(b+n-p); \ + stmt; \ + p-=q; v=u; \ + } +#define EACHCUTG(stmt) \ + for(i=1;i<=m;++i){ \ + if(pfx&&i==m)q=p; \ + else{u=memchr(v+pfx,sep,p-pfx); u+=!pfx; q=u-v;} \ + d=q-neg; v1=wv+k*(b+n-p); \ + old=jt->tbase+jt->ttop; \ + GA(y,wt,d*c,r,s); *AS(y)=d; \ + stmt; \ + if(allbx&&!AR(y)&&BOX&AT(y))*za++=y=*AAV(y); \ + else if(!allbx)*za++=y; \ + else{I ii=i-1; \ + allbx=0; \ + za=AAV(z); DO(ii, RZ(*za++=box(*za));); *za++=y; \ + old=jt->tbase+jt->ttop; \ + } \ + gc(y,old); \ + p-=q; v=u; \ + } + +/* locals in cut2: */ +/* b 1 iff _1 cut */ +/* c atoms in an item of w */ +/* d adjusted length of current cut */ +/* e max width of a cut */ +/* h gerund */ +/* hv gerund */ +/* id function code */ +/* k # bytes in an item of w */ +/* m # of cuts */ +/* n #a and #w */ +/* neg 1 iff _1 or _2 cut */ +/* p remaining length in a */ +/* pfx 1 iff 1 or _1 cut */ +/* q length of current cut */ +/* sep the cut character */ +/* u ptr to a for next cut */ +/* v ptr to a for current cut */ +/* v1 ptr to w for current cut */ +/* wd 1 iff w is relative */ + +static DF2(jtcut2){PROLOG;DECLF;A h=0,*hv,y,z=0,*za;B b,neg,pfx;C id,id1,sep,*u,*v,*v1,*wv,*zc; + I c,cv,e=0,d,hn,i,k,ke,m=0,n,old,p,q,r,*s,wd,wt,*zi,*zs;V*vf;VF ado; + PREF2(jtcut2); + if(SB01&AT(a)||SPARSE&AT(w))R cut2sx(a,w,self); + p=n=IC(w); wt=AT(w); k=*AV(sv->g); neg=0>k; pfx=k==1||k==-1; b=neg&&pfx; + if(a!=mark){ + if(!AN(a)&&n){ + if(VGERL&sv->flag){h=sv->h; ASSERT(AN(h),EVLENGTH); h=*AAV(h); R CALL1(VAV(h)->f1,w,h);} + else R CALL1(f1,w,fs); + } + if(AN(a)&&BOX&AT(a))R cut2bx(a,w,self); + if(!(B01&AT(a)))RZ(a=cvt(B01,a)); + if(!AR(a))RZ(a=reshape(sc(n),a)); + v=CAV(a); sep=C1; + }else if(1>=AR(w)&&wt&IS1BYTE){a=w; v=CAV(a); sep=v[pfx?0:n-1];} + else{RZ(a=n?eps(w,take(num[pfx?1:-1],w)):mtv); v=CAV(a); sep=C1;} + ASSERT(n==IC(a),EVLENGTH); + vf=VAV(fs); + if(VGERL&sv->flag){h=sv->h; hv=AAV(h); hn=AN(h); id=0;}else id=vf->id; + r=MAX(1,AR(w)); s=AS(w); wv=CAV(w); c=aii(w); k=c*bp(wt); wd=(I)w*ARELATIVE(w); + switch(pfx+(id==CLEFT||id==CRIGHT||id==CCOMMA?2:0)){ + case 0: if(AT(a)&B01&&C1==sep)m=bsum(n,v); + else{--v; DO(n, if(sep==*++v) ++m; ); v=CAV(a);} break; + case 1: if(AT(a)&B01&&C1==*v )m=bsum(n,v); + else{u=v+=n; DO(n, if(sep==*--v){++m; u=v;}); p-=u-v; v=u;} break; + case 2: u=--v; DO(n, if(sep==*++v){++m; e=MAX(e,v-u); u=v;}); v=CAV(a); break; + case 3: u=v+=n; DO(n, if(sep==*--v){++m; e=MAX(e,u-v); u=v;}); p-=u-v; v=u; + } + switch(wd?0:id){ + case CPOUND: + GA(z,INT,m,1,0); zi=AV(z); EACHCUT(*zi++=d;); + break; + case CDOLLAR: + GA(z,INT,m,1,0); zi=AV(z); EACHCUT(*zi++=d;); + R irs2(z,vec(INT,MAX(0,r-1),1+s),0L,0L,1L,jtover); + case CHEAD: + GA(z,wt,m*c,r,s); zc=CAV(z); *AS(z)=m; + EACHCUT(if(d)MC(zc,v1,k); else fillv(wt,c,zc); zc+=k;); + break; + case CTAIL: + GA(z,wt,m*c,r,s); zc=CAV(z); *AS(z)=m; + EACHCUT(if(d)MC(zc,v1+k*(d-1),k); else fillv(wt,c,zc); zc+=k;); + break; + case CCOMMA: + case CLEFT: + case CRIGHT: + e-=e&&neg; RE(d=mult(m*c,e)); + GA(z,wt,d,id==CCOMMA?2:1+r,s-1); zc=CAV(z); fillv(wt,d,zc); + zs=AS(z); zs[0]=m; zs[1]=id==CCOMMA?e*c:e; ke=k*e; + EACHCUT(MC(zc,v1,d*k); zc+=ke;); + break; + case CBOX: + GA(z,m?BOX:B01,m,1,0); za=AAV(z); + EACHCUT(GA(y,wt,d*c,r,s); *AS(y)=d; MC(AV(y),v1,d*k); *za++=y;); + break; + case CAT: case CATCO: case CAMP: case CAMPCO: + if(CBOX==ID(vf->f)&&(id1=ID(vf->g),id1==CBEHEAD||id1==CCTAIL)){ + GA(z,m?BOX:B01,m,1,0); za=AAV(z); + EACHCUT(d=d?d-1:0; GA(y,wt,d*c,r,s); *AS(y)=d; MC(AV(y),id1==CBEHEAD?v1+k:v1,d*k); *za++=y;); + } + break; + case CSLASH: + vains(vaid(vf->f),wt,&ado,&cv); + if(ado){C*z0=0,*zc;I t,zk,zt; + zt=rtype(cv); + GA(z,zt,m*c,r,s); *AS(z)=m; + if(!AN(z))R z; + zc=CAV(z); zk=c*bp(zt); + if((t=atype(cv))&&t!=wt){RZ(w=cvt(t,w)); wv=CAV(w);} + EACHCUT(if(d)ado(jt,1L,d*c,d,zc,v1); else{if(!z0){z0=idenv0(a,w,sv,zt,&y); + if(!z0){if(y)R y; else break;}} mvc(zk,zc,zk/c,z0);} zc+=zk;); + if(jt->jerr)R jt->jerr==EWOV?cut2(a,w,self):0; else R cv&VRI+VRD?cvz(cv,z):z; + }} + if(!z){B allbx=1; + if(!m){y=reitem(zero,w); y=h?df1(y,*hv):CALL1(f1,y,fs); RESETERR; R iota(over(zero,shape(y?y:mtv)));} + GA(z,BOX,m,1,0); za=AAV(z); + switch((wd?2:0)+(h?1:0)){ + case 0: EACHCUTG(MC(AV(y),v1,d*k); RZ(y=CALL1(f1,y,fs)); ); break; + case 1: EACHCUTG(MC(AV(y),v1,d*k); RZ(y=df1(y,hv[(i-1)%hn]));); break; + case 2: EACHCUTG(MCREL(AV(y),v1,d); RZ(y=CALL1(f1,y,fs)); ); break; + case 3: EACHCUTG(MCREL(AV(y),v1,d); RZ(y=df1(y,hv[(i-1)%hn]));); + } + if(!allbx)RZ(z=ope(z)); + } + EPILOG(z); +} /* f;.1 f;._1 f;.2 f;._2 monad and dyad */ + +static DF1(jtcut1){R cut2(mark,w,self);} + + +#define PSCASE(id,zt,wt) ((id)+256*(zt)+4096*(wt)) +#define PSLOOP(Tz,Tw,F,v0) \ + {C*u;Tw*wv;Tz s=v0,x,*zv; \ + GA(z,zt,n,1,0); \ + u=m+av; wv=m+(Tw*)AV(w); zv=m+(Tz*)AV(z); \ + switch(pfx+2*(id==CBSLASH)){ \ + case 0: DO(n, x=*--wv; if(*--u)s=v0; *--zv=F; ); break; /* <@(f/\.);.2 */ \ + case 1: DO(n, x=*--wv; *--zv=F; if(*--u)s=v0;); break; /* <@(f/\.);.1 */ \ + case 2: DO(n, x=*wv++; *zv++=F; if(*u++)s=v0;); break; /* <@(f/\ );.2 */ \ + case 3: DO(n, x=*wv++; if(*u++)s=v0; *zv++=F; ); break; /* <@(f/\ );.1 */ \ + }} + +static A jtpartfscan(J jt,A a,A w,I cv,B pfx,C id,C ie){A z=0;B*av;I m,n,zt; + n=AN(w); m=id==CBSDOT?n:0; zt=rtype(cv); av=BAV(a); + switch(PSCASE(ie,zt,AT(w))){ + case PSCASE(CPLUS, INT,B01): PSLOOP(I,B,s+=x, 0 ); break; + case PSCASE(CPLUS, FL, FL ): NAN0; PSLOOP(D,D,s+=x, 0.0 ); NAN1; break; + case PSCASE(CMAX, INT,INT): PSLOOP(I,I,s=MAX(s,x),IMIN); break; + case PSCASE(CMAX, FL, FL ): PSLOOP(D,D,s=MAX(s,x),-inf); break; + case PSCASE(CMIN, INT,INT): PSLOOP(I,I,s=MIN(s,x),IMAX); break; + case PSCASE(CMIN, FL, FL ): PSLOOP(D,D,s=MIN(s,x),inf ); break; + case PSCASE(CMAX, B01,B01): + case PSCASE(CPLUSDOT,B01,B01): PSLOOP(B,B,s|=x, 0 ); break; + case PSCASE(CMIN, B01,B01): + case PSCASE(CSTARDOT,B01,B01): PSLOOP(B,B,s&=x, 1 ); break; + case PSCASE(CNE, B01,B01): PSLOOP(B,B,s^=x, 0 ); break; + case PSCASE(CEQ, B01,B01): PSLOOP(B,B,s=s==x, 1 ); break; + } + R z; +} /* [: ; <@(ie/\);.k on vector w */ + +DF2(jtrazecut2){A fs,gs,x,y,z=0;B b,neg,pfx;C id,ie=0,sep,*u,*v,*wv,*zv;I c,cv=0,d,k,m=0,n,p,q,r,*s,wt; + V*fv,*sv,*vv;VF ado=0; + RZ(a&&w); + sv=VAV(self); gs=CFORK==sv->id?sv->h:sv->g; vv=VAV(gs); y=vv->f; fs=VAV(y)->g; + p=n=IC(w); wt=AT(w); k=*AV(vv->g); neg=0>k; pfx=k==1||k==-1; b=neg&&pfx; + fv=VAV(fs); id=fv->id; + if((id==CBSLASH||id==CBSDOT)&&(vv=VAV(fv->f),CSLASH==vv->id)){ + ie=vaid(vv->f); + if(id==CBSLASH)vapfx(ie,wt,&ado,&cv); /* [: ; <@(f/\ );.n */ + else vasfx(ie,wt,&ado,&cv); /* [: ; <@(f/\.);.n */ + } + if(SPARSE&AT(w))R raze(cut2(a,w,gs)); + if(a!=mark){ + if(!(AN(a)&&1==AR(a)&&AT(a)&B01+SB01))R raze(cut2(a,w,gs)); + if(AT(a)&SB01)RZ(a=cvt(B01,a)); + v=CAV(a); sep=C1; + }else if(1>=AR(w)&&wt&IS1BYTE){a=w; v=CAV(a); sep=v[pfx?0:n-1];} + else{RZ(a=n?eps(w,take(num[pfx?1:-1],w)):mtv); v=CAV(a); sep=C1;} + ASSERT(n==IC(a),EVLENGTH); + r=MAX(1,AR(w)); s=AS(w); wv=CAV(w); c=aii(w); k=c*bp(wt); + if(pfx){u=v+n; while(u>v&&sep!=*v)++v; p=u-v;} + if(ado){I t,zk,zt; /* atomic function f/\ or f/\. */ + if((t=atype(cv))&&t!=wt){RZ(w=cvt(t,w)); wv=CAV(w);} + zt=rtype(cv); zk=c*bp(zt); + if(1==r&&!neg&&B01&AT(a)&&p==n&&v[pfx?0:n-1]){RE(z=partfscan(a,w,cv,pfx,id,ie)); if(z)R z;} + GA(z,zt,AN(w),r,s); zv=CAV(z); + while(p){ + if(u=memchr(v+pfx,sep,p-pfx))u+=!pfx; else{if(!pfx)break; u=v+p;} + q=u-v; + if(d=q-neg){ + ado(jt,1L,c*d,d,zv,wv+k*(b+n-p)); + if(jt->jerr)R jt->jerr==EWOV?razecut2(a,w,self):0; + m+=d; zv+=d*zk; + } + p-=q; v=u; + }}else{B b1=0;I old,wc=c,yk,ym,yr,*ys,yt; /* general f */ + RZ(x=gah(r,w)); ICPY(AS(x),s,r); + while(p){ + if(u=memchr(v+pfx,sep,p-pfx))u+=!pfx; else{if(!pfx)break; u=v+p;} + q=u-v; d=q-neg; + *AS(x)=d; AN(x)=wc*d; AK(x)=(wv+k*(b+n-p))-(C*)x; + old=jt->tbase+jt->ttop; + RZ(y=df1(x,fs)); ym=IC(y); + if(!z){yt=AT(y); yr=AR(y); ys=AS(y); c=aii(y); yk=c*bp(yt); GA(z,yt,n*c,MAX(1,yr),ys); *AS(z)=n; zv=CAV(z);} + if(!(yt==AT(y)&&yr==AR(y)&&(1>=yr||!ICMP(1+AS(y),1+ys,yr-1)))){z=0; break;} + while(IC(z)<=m+ym){RZ(z=ext(0,z)); zv=CAV(z); b1=0;} + memcpy(zv+m*yk,CAV(y),ym*yk); + if(b1)gc(yt&DIRECT?0:y,old); + b1=1; m+=ym; p-=q; v=u; + } + if(!b1&&ie)GA(z,wt,AN(w),r,s); + } + if(z){*AS(z)=m; AN(z)=m*c; R cv&VRI+VRD?cvz(cv,z):z;} + else R raze(cut2(B01&AT(a)?a:eq(scc(sep),a),w,gs)); +} /* ;@(<@f);.n or ([: ; <@f;.n) , monad and dyad */ + +DF1(jtrazecut1){R razecut2(mark,w,self);} + + +static A jttesos(J jt,A a,A w,I n){A p;I*av,c,k,m,*pv,s,*ws; + RZ(a&&w); + c=*(1+AS(a)); av=AV(a); ws=AS(w); + GA(p,INT,c,1,0); pv=AV(p); + if(3==n)DO(c, m=av[i]; s=ws[i]; pv[i]=m?(s+m-1)/m:1&&s;) + else DO(c, m=av[i]; k=av[c+i]; s=ws[i]-ABS(k); pv[i]=0>s?0:m?(k||s%m)+s/m:1;); + R p; +} /* tesselation result outer shape */ + +static F2(jttesa){A x;I*av,c,d,k,p=IMAX,r,*s,t,*u,*v; + RZ(a&&w); + t=AT(a); + RZ(a=vib(a)); + r=AR(a); s=AS(a); c=r?s[r-1]:1; av=AV(a); d=AR(w); + ASSERT(d>=c&&(2>r||2==*s),EVLENGTH); + if(2<=r)DO(c, ASSERT(0<=av[i],EVDOMAIN);); + if(2==r&&c==d&&t&INT)R a; + GA(x,INT,2*d,2,0); s=AS(x); s[0]=2; s[1]=d; + u=AV(x); v=u+d; s=AS(w); + if(2==r)DO(c, *u++=av[i]; k=av[i+c]; *v++=k==p?s[i]:k==-p?-s[i]:k;); + if(2> r)DO(c, *u++=1; k=av[i]; *v++=k==p?s[i]:k==-p?-s[i]:k;); + s+=c; DO(d-c, *u++=0; *v++=*s++;); + R x; +} /* tesselation standardized left argument */ + +static A jttesmatu(J jt,A a,A w,A self,A p,B e){DECLF;A x,y,z,z0;C*u,*v,*v0,*wv,*yv,*zv; + I*av,i,k,m,mc,mi,mj,mr,nc,nr,old,*pv,r,s,*s1,sc,sj,sr,t,tc,tr,*ws,yc,yr,zk,zn,zr,*zs,zt; + ws=AS(w); t=AT(w); k=bp(t); r=k*ws[1]; + av=AV(a); pv=AV(p); wv=CAV(w); + nr=pv[0]; sr=av[2]; mr=av[0]; mi=r*mr; tr=ws[0]; + nc=pv[1]; sc=av[3]; mc=av[1]; mj=k*mc; sj=k*sc; + RZ(nr&&nc&&nr>=sr&&nc>=sc); + GA(y,t,sr*sc,2,2+av); yv=CAV(y); + u=yv; v=wv; DO(sr, MC(u,v,sj); u+=sj; v+=r;); + RZ(z0=CALL1(f1,y,fs)); zt=AT(z0); + RZ(zt&B01+LIT+INT+FL+CMPX); + zn=AN(z0); zr=AR(z0); zs=AS(z0); zk=zn*bp(zt); m=zr*SZI; + GA(z,zt,zn*nr*nc,2+zr,0); s1=AS(z); ICPY(s1,pv,2); ICPY(2+s1,zs,zr); zv=CAV(z); + old=jt->tbase+jt->ttop; + if(e) for(i=0;i<nr;++i){ /* f;._3 */ + v=v0=wv+i*mi; + DO(nc, + u=yv; DO(sr, MC(u,v,sj); u+=sj; v+=r;); v=v0+=mj; RZ(x=CALL1(f1,y,fs)); + RZ(zt==AT(x)&&zr==AR(x)&&!(m&&memcmp(zs,AS(x),m))); MC(zv,AV(x),zk); zv+=zk; tpop(old);); + }else for(i=0;i<nr;++i){ /* f;. 3 */ + v=v0=wv+i*mi; yr=MIN(tr,sr); tr-=mr; tc=ws[1]; + DO(nc, yc=MIN(tc,sc); tc-=mc; s=yc*k; + u=yv; DO(yr, MC(u,v,s ); u+=sj; v+=r;); v=v0+=mj; RZ(x=CALL1(f1,yr<sr||yc<sc?take(v2(yr,yc),y):y,fs)); + RZ(zt==AT(x)&&zr==AR(x)&&!(m&&memcmp(zs,AS(x),m))); MC(zv,AV(x),zk); zv+=zk; tpop(old);); + } + R z; +} /* f;._3 (1=e) or f;.3 (0=e), matrix w, positive size, uniform f */ + +static A jttesmat(J jt,A a,A w,A self,A p,B e){DECLF;A y,z,*zv;C*u,*v,*v0,*wv,*yv; + I*av,i,j,k,mc,mi,mj,mr,nc,nr,*pv,r,s,sc,sj,sr,t,tc,tr,*ws,yc,yr; + ws=AS(w); t=AT(w); k=bp(t); r=k*ws[1]; + av=AV(a); pv=AV(p); wv=CAV(w); + nr=pv[0]; sr=av[2]; mr=av[0]; mi=r*mr; tr=ws[0]; + nc=pv[1]; sc=av[3]; mc=av[1]; mj=k*mc; sj=k*sc; + GA(y,t,sr*sc,2,2+av); yv=CAV(y); + GA(z,BOX,nr*nc,2,pv); zv=AAV(z); + for(i=0;i<nr;++i){ + v=v0=wv+i*mi; yr=MIN(tr,sr); tr-=mr; tc=ws[1]; + for(j=0;j<nc;++j){ + yc=MIN(tc,sc); tc-=mc; s=yc*k; + if(1<AC(y)){GA(y,t,sr*sc,2,2+av); yv=CAV(y);} + u=yv; DO(yr, MC(u,v,e?sj:s); u+=sj; v+=r;); v=v0+=mj; + *zv++=CALL1(f1,e||yr==sr&&yc==sc?y:take(v2(yr,yc),y),fs); + }} + RE(0); R ope(z); +} /* f;._3 (1=e) or f;.3 (0=e), matrix w, positive size */ + +static DF2(jttess2){A gs,p,y,z;I*av,n,t; + PREF2(jttess2); + RZ(a=tesa(a,w)); + av=AV(a); gs=VAV(self)->g; n=*AV(gs); + RZ(p=tesos(a,w,n)); + if(DENSE&AT(w)&&2==AR(w)&&0<=av[2]&&0<=av[3]){ + RE(z=tesmatu(a,w,self,p,(B)(0>n))); + if(!z)z=tesmat(a,w,self,p,(B)(0>n)); + if(z&&!AN(z)){ + y=df1(w,VAV(self)->f); RESETERR; + t=y?AT(y):B01; + if(t!=AT(z))GA(z,t,0L,AR(z),AS(z)); + } + R z; + } + R cut02(irs2(cant1(tymes(head(a),cant1(abase2(p,iota(p))))), tail(a),0L,1L,1L,jtlamin2),w,self); +} + +static DF1(jttess1){A s;I m,r,*v; + RZ(w); + r=AR(w); RZ(s=shape(w)); v=AV(s); + m=IMAX; DO(r, if(m>v[i])m=v[i];); DO(r, v[i]=m;); + R tess2(s,w,self); +} + + +F2(jtcut){A h=0;I flag=0,k; + RZ(a&&w); + ASSERT(NOUN&AT(w),EVDOMAIN); + RZ(w=vi(w)); + RE(k=i0(w)); + if(NOUN&AT(a)){flag=VGERL; RZ(h=fxeachv(1L,a)); ASSERT(3!=k&&-3!=k,EVNONCE);} + switch(k){ + case 0: R fdef(CCUT,VERB, jtcut01,jtcut02, a,w,h, flag, RMAX,2L,RMAX); + case 1: case -1: + case 2: case -2: R fdef(CCUT,VERB, jtcut1, jtcut2, a,w,h, flag, RMAX,1L,RMAX); + case 3: case -3: R fdef(CCUT,VERB, jttess1,jttess2, a,w,h, flag, RMAX,2L,RMAX); + default: ASSERT(0,EVDOMAIN); +}}
new file mode 100644 --- /dev/null +++ b/cd.c @@ -0,0 +1,568 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Differentiation and Integration */ + +#include "j.h" + + +static B jtiscons(J jt,A w){A x;V*v; + RZ(w); + v=VAV(w); x=v->f; + R CQQ==v->id&&NOUN&AT(x)&&!AR(x); +} + +static C ispoly1[]={CLEFT,CRIGHT,CLE,CGE,CNOT,CMINUS,CPLUSCO,CHALVE,CCIRCLE,CJDOT,0}; + +static I jtispoly(J jt,A w){A e,f,g,h,x,y;B nf,ng,vf,vg;C c,id;I k,m,n,t;V*v; + RZ(w); + v=VAV(w); id=v->id; + if(id==CFCONS||iscons(w))R 1; + if(strchr(ispoly1,id))R 2; + if(id==CSTARCO)R 3; + f=v->f; nf=f&&NOUN&AT(f); vf=!nf; + g=v->g; ng=g&&NOUN&AT(g); vg=!ng; x=nf?f:g; t=x?AT(x):0; h=nf?g:f; c=h?ID(h):0; + if(id==CFORK){ + RZ(vf&&vg); + m=ispoly(f); n=ispoly(v->h); + switch(m&&n?ID(g):0){ + case CPLUS: R MAX(m,n); + case CSTAR: R m+n-1; + }} + if(vf&&vg&&(id==CAT||id==CATCO||id==CAMP||id==CAMPCO)){m=ispoly(f); n=ispoly(g); if(m&&n)R 1+(m-1)*(n-1);} + RZ(id==CAMP&&(t&NUMERIC||c==CPOLY)); + if(nf&&1>=AR(x)&&c==CPOLY){ + RZ(t&BOX+NUMERIC); + k=IC(x); + if(t&NUMERIC)R k; + y=*(AAV(x)+k-1); RZ(2>=AR(y)); + if(1>=AR(y))R 1+IC(y); + RZ(2==*(1+AS(y))); + RZ(e=irs1(y,0L,1L,jttail)); + RZ(equ(e,floor1(e))&&all1(le(zero,e))); + RZ(y=aslash(CMAX,cvt(INT,e))); + R 1+*AV(y); + } + if(nf==ng||AR(x))R 0; + if(c==CPLUS||c==CMINUS||c==CSTAR||c==CDIV&&ng)R 2; + RZ(x=pcvt(INT,x)); + if(!(INT&AT(x)))R 0; + k=*AV(x); + R 0<=k&&(c==CBANG&&nf||c==CEXP&&ng)?1+k:0; +} /* 1 + degree of polynomial (0 if not poly) */ + +static F1(jtfpolyc){A b;B*bv;I m,n; + RZ(b=ne(w,zero)); bv=BAV(b); + m=n=AN(w); DO(n, if(bv[--m])break;); ++m; + if(m<n)RZ(w=take(sc(m),w)); n=m; + switch(n){ + case 1: R qq(head(w),zero); + case 3: if(equ(w,over(v2(0L,0L),one)))R ds(CSTARCO); break; + case 2: + if(equ(w,v2( 0L,-1L))) R ds(CMINUS); + if(equ(w,v2( 1L,-1L))) R ds(CNOT); + if(equ(w,v2(-1L, 1L))) R ds(CLE); + if(equ(w,v2( 0L, 1L))) R ds(CLEFT); + if(equ(w,v2( 1L, 1L))) R ds(CGE); + if(equ(w,v2( 0L, 2L))) R ds(CPLUSCO); + if(equ(w,over(zero,scf((D)0.5))))R ds(CHALVE); + if(equ(w,over(zero,scf(PI ))))R ds(CCIRCLE); + if(equ(w,over(zero,a0j1 )))R ds(CJDOT); + } + R amp(w,ds(CPOLY)); +} + +static A jtfpoly(J jt,I n,A f){I m=0>n?1:1+n; RZ(f); R fpolyc(df1(IX(m),tdot(f)));} + +static F1(jtfnegate){V*v; RZ(w); v=VAV(w); R CAT==v->id&&CMINUS==ID(v->f)?v->g:atop(ds(CMINUS),w);} + +static F2(jtfplus){ + RZ(a&&w); + if(iscons(a)&&equ(VAV(a)->f,zero))R w; + if(iscons(w)&&equ(VAV(w)->f,zero))R a; + R folk(a,ds(CPLUS),w); +} + +static F2(jtfminus){ + RZ(a&&w); + if(iscons(a)&&equ(VAV(a)->f,zero))R fnegate(w); + if(iscons(w)&&equ(VAV(w)->f,zero))R a; + R folk(a,ds(CMINUS),w); +} + +static F2(jtftymes){A x,y;B b,c;I k; + RZ(a&&w); + b=iscons(a); x=VAV(a)->f; + c=iscons(w); y=VAV(w)->f; + if(CFORK==ID(w)&&NOUN&AT(y))R ftymes(a,folk(qq(y,ainf),VAV(w)->g,VAV(w)->h)); + if(b&&AT(x)&B01+INT){k=i0(x); if(-1<=k&&k<=1)R !k?a:0<k?w:fnegate(w);} + if(c&&AT(y)&B01+INT){k=i0(y); if(-1<=k&&k<=1)R !k?w:0<k?a:fnegate(a);} + if(b&&CFORK==ID(w)&&iscons(y))R ftymes(qq(tymes(x,VAV(y)->f),zero),VAV(w)->h); + R c?folk(w,ds(CSTAR),a):folk(a,ds(CSTAR),w); +} + +static F1(jtdpoly){A c,e,x;I n,t; + RZ(w); + n=AN(w); t=AT(w); + ASSERT(!n||t&NUMERIC+BOX,EVDOMAIN); + if(!n||t&NUMERIC)R 2>=n?qq(2==n?tail(w):cvt(n?t:B01,zero),zero):fpolyc(behead(tymes(w,IX(n)))); + x=AAV0(w); + if(1<n||1>=AR(x))R dpoly(poly1(w)); + ASSERT(2==AR(x)&&2==*(1+AS(x)),EVDOMAIN); + c=irs1(x,0L,1L,jthead); + e=irs1(x,0L,1L,jttail); + R amp(box(stitch(tymes(c,e),minus(e,one))),ds(CPOLY)); +} + +static F1(jtipoly){A b,c,e,p=0,q=0,x;I n,t; + RZ(w); + n=AN(w); t=AT(w); + ASSERT(!n||t&NUMERIC+BOX,EVDOMAIN); + if(!n||t&NUMERIC)R fpolyc(over(zero,divide(w,apv(n,1L,1L)))); + x=AAV0(w); + if(1<n||1>=AR(x))R ipoly(poly1(w)); + ASSERT(2==AR(x)&&2==*(1+AS(x)),EVDOMAIN); + RZ(c=irs1(x,0L,1L,jthead)); + RZ(e=plus(one,irs1(x,0L,1L,jttail))); + RZ(b=ne(e,zero)); + if(!all0(b))RZ(p=amp(box(repeat(b,stitch(divide(c,e),e))),ds(CPOLY))); + if(!all1(b))RZ(q=evc(not(b),c,"(+/x#y)&*@^.")); + R p&&q?folk(p,ds(CPLUS),q):p?p:q; +} + +static F1(jticube){R atco(eval("* =/~@(i.@$)"),w);} + +static F1(jtdiffamp0){A f,g,h,x,y;B nf,ng;C id;V*v; + RZ(w); + v=VAV(w); + f=v->f; nf=1&&NOUN&AT(f); + g=v->g; ng=1&&NOUN&AT(g); + h=nf?g:f; id=ID(h); x=nf?f:g; + RZ(!AR(x)||id==CPOLY); + switch(id){ + case CPLUS: R qq(one,zero); + case CSTAR: R qq(x,zero); + case CMINUS: R qq(num[nf?-1:1],zero); + case CDIV: R nf?eva(x,"(-x)&%@*:"):qq(recip(x),zero); + case CPOLY: if(nf)R dpoly(x); break; + case CBANG: if(nf&&!AR(x))R dpoly(df1(iota(increm(x)),tdot(w))); break; + case CROOT: if(nf&&!AR(x))R atop(amp(recip(x),ds(CSTAR)),amp(ds(CEXP),decrem(recip(x)))); break; + case CLOG: R eva(logar1(x),nf?"(%x)&%":"(-x)&%@(* *:@^.)"); + case CEXP: + if(nf)R evc(x,w,"(^.x)&*@y"); + RZ(y=pcvt(INT,x)); + if(INT&AT(y))switch(*AV(y)){ + case 0: R qq(zero,zero); + case 1: R qq(one,zero); + case 2: R ds(CPLUSCO); + } + R eva(x,"x&*@(^&(x-1))"); + case CCIRCLE: + if(nf){ + RZ(x=vi(x)); + switch(*AV(x)){ + case 0: R folk(ds(CMINUS),ds(CDIV),w); + case 1: R amp(num[2],h); + case 2: R atop(ds(CMINUS),amp(one,h)); + case 3: R atop(atop(ds(CDIV),ds(CSTARCO)),amp(num[2],h)); + case 5: R amp(num[6],h); + case 6: R amp(num[5],h); + case 7: R atop(atop(ds(CDIV),ds(CSTARCO)),amp(num[6],h)); + }}} + R 0; +} + +static F1(jtdiff0){A df,dg,dh,f,g,h,x,y,z;B b,nf,ng,vf,vg;C id;I m,p,q;V*v; + RZ(w); + v=VAV(w); id=v->id; + f=v->f; nf=f&&NOUN&AT(f); vf=f&&!nf; + g=v->g; ng=g&&NOUN&AT(g); vg=g&&!ng; + if(id==CAMP&&nf!=ng)R diffamp0(w); + switch(id){ + case CLE: + case CGE: + case CLEFT: + case CRIGHT: R qq(one,zero); + case CPLUSCO: R qq(num[2],zero); + case CNOT: + case CMINUS: R qq(num[-1],zero); + case CFCONS: R qq(zero,zero); + case CSTARCO: R ds(CPLUSCO); + case CHALVE: R qq(connum(3L,"1r2"),zero); + case CCIRCLE: R qq(pie,zero); + case CDIV: R eval("- @%@*:"); + case CSQRT: R eval("-:@%@%:"); + case CEXP: R w; + case CLOG: R ds(CDIV); + case CJDOT: R qq(a0j1,zero); + case CRDOT: R atop(ds(CJDOT),w); + case CDDOT: if(vf&&ng)R ddot(f,increm(g)); break; + case CPOWOP: + if(vf&&ng&&!AR(g))switch(p=i0(g)){ + case -1: R diff0(inv(f)); + case 0: RE(0); R qq(one,zero); + case 1: R diff0(f); + default: + if(0>p){RZ(f=inv(f)); p=-p;} + if(q=ispoly(f)){RE(m=i0(vib(expn2(sc(q-1),g)))); R dpoly(df1(IX(1+m),tdot(w)));} + R diff0(atop(powop(f,sc(p-1)),f)); + } + break; + case CQQ: + if(!AR(f)&&NUMERIC&AT(f)&&ng&&equ(g,zero))R qq(zero,zero); + if(vf&&ng)R qq(diff0(f),g); + break; + case CAT: + case CATCO: + case CAMP: + case CAMPCO: + if(vf&&vg){ + p=ispoly(f); q=ispoly(g); + if(p&&q)R dpoly(df1(IX(1+(p-1)*(q-1)),tdot(w))); + RZ(dg=diff0(g)); RZ(df=diff0(f)); v=VAV(df); x=v->f; + if(CQQ!=v->id)R ftymes(dg,atop(df,g)); + switch(CQQ==v->id&&AT(x)&B01+INT?i0(x):9){ + case 0: R df; + case 1: R dg; + case 2: R atop(ds(CPLUSCO),dg); + case -1: R fnegate(dg); + default: R ftymes(df,dg); + }} + break; + case CTILDE: + if(vf)switch(ID(f)){ + case CPLUS: R qq(num[2],zero); + case CSTAR: R ds(CPLUSCO); + case CMINUS: + case CLOG: + case CDIV: R qq(zero,zero); + case CEXP: R eva(w,"x * >:@^."); + } + break; + case CFORK: + h=v->h; + if(NOUN&AT(f))R diff0(folk(qq(f,zero),g,h)); + if(CCAP==ID(f))R diff0(atco(g,h)); + p=ispoly(f); df=diff0(f); + q=ispoly(h); dh=diff0(h); b=p&&q; + switch(ID(g)){ + case CPLUS: z=fplus (df,dh); R b?fpoly(MAX(p,q)-1,z):z; + case CMINUS: z=fminus(df,dh); R b?fpoly(MAX(p,q)-1,z):z; + case CSTAR: z=fplus(ftymes(df,h),ftymes(f,dh)); R b?fpoly(p+q,z):z; + case CCOMMA: R folk(df,g,dh); + case CDIV: x=fminus(ftymes(df,h),ftymes(f,dh)); + y=atop(ds(CSTARCO),h); + R folk(b?fpoly(p+q-1-(p==q),x):x,ds(CDIV),q?fpoly(q+q,y):y); + case CEXP: if(1==q){A k; + RZ(k=df1(zero,h)); + if(equ(k,zero))R qq(zero,zero); + if(equ(k,one))R df; + if(equ(k,num[2]))R ftymes(df,ftymes(h,f)); + R ftymes(df,ftymes(h,folk(f,g,qq(decrem(k),zero)))); + } + }} + R 0; +} + +static F1(jtintgamp0){A f,g,h,x,y;B nf,ng;C id;V*v; + RZ(w); + v=VAV(w); + f=v->f; nf=1&&NOUN&AT(f); + g=v->g; ng=1&&NOUN&AT(g); + h=nf?g:f; id=ID(h); x=nf?f:g; + RZ(!AR(x)||id==CPOLY); + switch(id){ + case CPLUS: R ipoly(over(x,one)); + case CSTAR: R ipoly(over(zero,x)); + case CMINUS: R nf?ipoly(over(x,num[-1])):ipoly(over(negate(x),one)); + case CDIV: R nf?eva(x,"x&*@^."):ipoly(over(zero,recip(x))); + case CPOLY: if(nf)R ipoly(x); break; + case CBANG: if(nf&&AT(x))R ipoly(df1(iota(increm(x)),tdot(w))); break; + case CEXP: + if(ng&&!AR(x)){ + if(equ(x,num[-1]))R ds(CLOG); + RZ(y=pcvt(INT,x)); + R INT&AT(y)?ipoly(take(sc(-1-i0(y)),one)):atop(amp(ds(CDIV),increm(y)),amp(ds(CEXP),increm(y))); + } + case CCIRCLE: + if(nf){ + RZ(x=vi(x)); + switch(*AV(x)){ + case 1: R atop(ds(CMINUS),amp(num[2],h)); + case 2: R amp(one,h); + case 3: R eval("-@^.@(2&o.)"); + case 5: R amp(num[6],h); + case 6: R amp(num[5],h); + case 7: R atop(ds(CLOG),amp(num[6],h)); + }}} + R 0; +} + +static F1(jtintg0); + +static F2(jtintgatop){A df,f=a,g=w,q,x,y;I m,n;V*v; + RZ(a&&w); + m=ispoly(f); + n=ispoly(g); + if(m&&n)R ipoly(df1(IX(1+(m-1)*(n-1)),tdot(atop(a,w)))); + if(2==m){ + RZ(q=v2(0L,1L)); + RZ(x=df1(q,tdot(f))); + RZ(y=equ(one, tail(x))?intg0(g):atop(fpolyc(tymes(q,x)),intg0(g))); + R equ(zero,head(x))?y :folk(y,ds(CPLUS),amp(head(x),ds(CSTAR))); + } + if(1==n||2==n){ + df=atop(intg0(f),g); + if(1==n)R df; + RZ(x=df1(one,tdot(g))); + R equ(x,one)?df:atop(amp(ds(CDIV),x),df); + } + v=VAV(g); + if(m&&equ(take(sc(-m),one),df1(IX(m),tdot(f)))){ /* ^&m @ g */ + if(CLOG==v->id)R 1==m?ds(CRIGHT):2==m?intg0(g):eva(sc(m-1),"(] * ^&x@^.) - x&* @(^&(x-1)@^. d. _1)"); + if(CAMP==v->id&&CCIRCLE==ID(v->g)&&(y=v->f,!AR(y)&&equ(y,floor1(y)))){ + if(2>=m)R 1==m?ds(CRIGHT):intgamp0(g); + switch(i0(y)){ + case 1: R eva(sc(m-1),"%&(-x )@(^&(x-1)@(1&o.) * 2&o.) + ((x-1)%x)&*@(^&(x-2)@(1&o.) d. _1)"); + case 2: R eva(sc(m-1),"%&x @(^&(x-1)@(2&o.) * 1&o.) + ((x-1)%x)&*@(^&(x-2)@(2&o.) d. _1)"); + case 3: R eva(sc(m-1),"%&(x-1)@(^&(x-1)@(3&o.) ) - ^&(x-2)@(3&o.) d. _1 "); + case 7: R eva(sc(m-1),"%&(1-x)@(^&(x-1)@(7&o.) ) + ^&(x-2)@(7&o.) d. _1 "); + }}} + R 0; +} /* integral of a @ w */ + +static F2(jtintgtymes){A f=a,g=w; + RZ(a&&w); + R 0; +} /* integral of a * w */ + +static F1(jtintg0){A df,dh,f,g,h;B nf,ng,vf,vg;C id;I m,n,p,q;V*fv,*gv,*v; + RZ(w); + id=ID(w); v=VAV(w); + f=v->f; nf=f&&NOUN&AT(f); if(vf=f&&!nf)fv=VAV(f); + g=v->g; ng=g&&NOUN&AT(g); if(vg=g&&!ng)gv=VAV(g); + if(id==CAMP&&nf!=ng)R intgamp0(w); + switch(id){ + case CLE: R ipoly(v2(-1L, 1L)); + case CGE: R ipoly(v2( 1L, 1L)); + case CLEFT: + case CRIGHT: R ipoly(v2( 0L, 1L)); + case CNOT: R ipoly(v2( 1L,-1L)); + case CMINUS: R ipoly(v2( 0L,-1L)); + case CPLUSCO: R ds(CSTARCO); + case CFCONS: R amp(v->h,ds(CSTAR)); + case CSTARCO: R ipoly(over(v2(0L,0L),one)); + case CHALVE: R ipoly(over(zero,scf((D)0.5))); + case CCIRCLE: R ipoly(over(zero,scf(PI ))); + case CDIV: R ds(CLOG); + case CSQRT: R eval("%: * (0 2%3)&p."); + case CEXP: R w; + case CLOG: R eval("(]*^.) - ]"); + case CJDOT: R ipoly(over(zero,a0j1)); + case CRDOT: R eval("-@j.@r."); + case CDDOT: if(vf&&ng)R ddot(f,decrem(g)); break; + case CPOWOP: + if(vf&&ng&&!AR(g))switch(p=i0(g)){ + case -1: R intg0(inv(f)); + case 0: RE(0); R ipoly(v2(0L,1L)); + case 1: R intg0(f); + default: + if(0>p){RZ(f=inv(f)); p=-p;} + if(q=ispoly(f)){RE(m=i0(vib(expn2(sc(q-1),g)))); R ipoly(df1(IX(1+m),tdot(w)));} + R intg0(atop(powop(f,sc(p-1)),f)); + } + break; + case CQQ: + if(!AR(f)&&NUMERIC&AT(f)&&ng&&equ(g,zero))R amp(f,ds(CSTAR)); + if(vf&&ng)R qq(intg0(f),g); + break; + case CAT: + case CATCO: + case CAMP: + case CAMPCO: + if(vf&&vg)R intgatop(f,g); + break; + case CTILDE: + if(vf)switch(ID(f)){ + case CPLUS: R ipoly(v2(0L,2L)); + case CSTAR: R ipoly(over(v2(0L,0L),one)); + case CMINUS: R FCONS(zero); + case CLOG: + case CDIV: R ds(CRIGHT); + } + break; + case CFORK: + h=v->h; + if(NOUN&AT(f))R intg0(folk(qq(f,zero),g,h)); + dh=intg0(h); n=ispoly(h); + df=intg0(f); m=ispoly(f); + switch(ID(g)){ + case CPLUS: R m&&n ? (p=MAX(m,n),ipoly(df1(IX(p),tdot(w)))) : fplus(df,dh); + case CMINUS: R m&&n ? (p=MAX(m,n),ipoly(df1(IX(p),tdot(w)))) : fminus(df,dh); + case CSTAR: if(m&&n){p=2+(m-1)*(n-1); R ipoly(df1(IX(p),tdot(w)));} + R intgtymes(f,h); + }} + R 0; +} + +static DF1(jtddot1){V*v=VAV(self); R df1(w,ddot(fix(v->f),v->g));} + +F2(jtddot){A x,*xv,y,z;AF f;I j,n,p,q,r,*wv; + RZ(a&&w); + ASSERT(NOUN&AT(w),EVDOMAIN); + RZ(w=vi(w)); r=AR(w); n=AN(w); wv=AV(w); + if(NOUN&AT(a)){ASSERT(0,EVNONCE);} + if(!nameless(a)||1<r)R CDERIV(CDDOT, jtddot1,0L, 0L,0L,0L); + irange(n,wv,&p,&q); + if(!r){ + if(!p){V*v=VAV(a); R v->mr||v->lr||v->rr?qq(a,zero):a;} + f=0<=p?jtdiff0:jtintg0; y=a; DO(ABS(p), ASSERT(y=CALL1(f,y,0L),EVDOMAIN);); R y; + } + q+=p-1; p=0>p?p:0; q=0<q?q:0; + GA(x,BOX,1+q-p,1,0); xv=AAV(x); xv[-p]=a; + if(0>p){y=a; j=-p; DO(-p, ASSERT(y=intg0(y),EVDOMAIN); xv[--j]=y;);} + if(0<q){y=a; j=-p; DO( q, ASSERT(y=diff0(y),EVDOMAIN); xv[++j]=y;);} + j=n; z=xv[wv[--j]-p]; DO(n-1, RZ(z=folk(xv[wv[--j]-p],ds(CCOMMA),z));); + R qq(z,zero); +} + + +static F1(jtdiffamp){A f,g,h,x,y;B nf,ng;V*v; + RZ(w); + v=VAV(w); + f=v->f; nf=1&&NOUN&AT(f); + g=v->g; ng=1&&NOUN&AT(g); + h=nf?g:f; x=nf?f:g; + switch(ID(h)){ + case CROT: + case CCANT: + case CLBRACE: + case CATOMIC: + case CCYCLE: + if(nf)R atop(hook(eval("=/"),w),eval("i.@$")); + break; + case CPOLY: + if(nf&&1>=AR(x))R dpoly(NUMERIC&AT(x)?x:poly1(x)); + break; + case CBANG: + if(!AR(x)&&(x=pcvt(INT,x),INT&AT(x)))R dpoly(df1(IX(1+*AV(x)),tdot(w))); + break; + case CFIT: + if(nf&&1>=AR(x)&&(y=VAV(h)->f,CPOLY==ID(y)))R dpoly(df1(IX(IC(x)),tdot(w))); + } + R 0; +} + +static F1(jtdiff){A df,dh,f,g,h,z;B nf,ng,vf,vg;C id;I r;V*v; + RZ(w); + ASSERT(VERB&AT(w),EVDOMAIN); + v=VAV(w); id=v->id; r=v->mr; + f=v->f; nf=f&&NOUN&AT(f); vf=f&&!nf; + g=v->g; ng=g&&NOUN&AT(g); vg=g&&!ng; + if(nf&&id==CFORK)R diff(folk(qq(f,ainf),g,v->h)); + if(z=diff0(w))R id==CQQ&&ng&&equ(g,zero)?z:icube(z); + if(id==CAMP&&nf!=ng)R diffamp(w); + switch(id){ + case CREV: R eval("(|.=/])@(i.@$)"); + case CCANT: R eval("(|:=/])@(i.@$)"); + case CHGEOM: R hgdiff(w); + case CSLASH: + switch(ID(f)){ + case CPLUS: R eval("({. =/ */@}.@$ | ])@(i.@$)"); + } + break; + /* ----- commented out because it is incorrect + case CBSLASH: + case CBSDOT: + if(CSLASH==ID(f)&&(ff=VAV(f)->f,ff&&VERB&AT(ff))){ + b=id==CBSDOT; + switch(ID(ff)){ + case CPLUS: R eval(b ? "<:/~@(i.@$)" : ">:/~@(i.@$)"); + }} + break; + ----- */ + case CFCONS: + R atop(amp(ds(CDOLLAR),zero),ds(CDOLLAR)); + case CQQ: + if(NUMERIC&AT(f)&&ng){ + z=atop(amp(ds(CDOLLAR),zero),ds(CDOLLAR)); + R RMAX<mr(w)?z:qq(z,g); + } + if(vf&&ng)R qq(diff(f),g); + break; + case CAT: + case CAMP: + if(vf&&ng)R qq(df1(g,f),ainf); + if(vf&&vg)R folk(diff(g),eval("+/ .*"),atop(diff(f),g)); + break; + case CFORK: + df=diff(f); h=v->h; dh=diff(h); + switch(ID(g)){ + case CPLUS: R fplus(df,dh); + case CMINUS: R fminus(df,dh); + case CSTAR: R fplus(ftymes(df,h),ftymes(f,dh)); + case CDIV: R folk(fminus(ftymes(df,h),ftymes(f,dh)), ds(CDIV), atop(ds(CSTARCO),h)); + }} + R 0; +} + +static F1(jtintg){ASSERT(0,EVNONCE);} + +static A jtdtab(J jt,A a,I d){A h;V*v; + RZ(a); + if(CDCAP==ID(a)&&(v=VAV(a),NOUN&AT(v->f)&&d==i0(v->g))){h=VAV(a)->h; R*(1+AAV(h));} + switch(SGN(d)){ + default: ASSERTSYS(0,"dtab"); + case -1: R dtab(intg(a),d+1); + case 0: R a; + case 1: R dtab(diff(a),d-1); +}} + + +static DF2(jtsslope){A fs,f0,p,y,z,*zv;I m,n,r,t;V*sv=VAV(self); + PREF2(jtsslope); + fs=sv->f; m=*AV(sv->g); + RZ(fs=1<m?dcapco(fs,sc(m-1)):atop(fs,ds(CRIGHT))); + r=AR(a); n=AN(w); + ASSERT(!r||r==AR(w)&&!memcmp(AS(a),AS(w),r*SZI),EVNONCE); + RZ(f0=df2(a,w,fs)); + GA(z,BOX,n,AR(w),AS(w)); zv=AAV(z); + t=CMPX&AT(a)||CMPX&AT(w)?CMPX:FL; + RZ(a=cvt(t,a)); RZ(y=cvt(t,w)); GA(p,t,1,0,0); + if(t&CMPX){Z*av=ZAV(a),e,*pv=ZAV(p),*v=ZAV(y),x; + e.re=1e-7; e.im=0.0; *pv=ZNZ(*av)?*av:e; + DO(n, if(r)*pv=ZNZ(av[i])?av[i]:e; x=v[i]; v[i]=zplus(v[i],*pv); RZ(zv[i]=divide(minus(df2(p,y,fs),f0),p)); v[i]=x;); + }else {D*av=DAV(a),e,*pv=DAV(p),*v=DAV(y),x; + e=1e-7; *pv= *av ?*av:e; + DO(n, if(r)*pv= av[i] ?av[i]:e; x=v[i]; v[i]+=*pv; RZ(zv[i]=divide(minus(df2(p,y,fs),f0),p)); v[i]=x;); + } + R ope(z); /* cant2(IX(AR(w)),ope(z)); */ +} + +static DF1(jtderiv1){A e,ff,fs,gs,s,t,z,*zv;I*gv,d,n,*tv;V*v; + PREF1(jtderiv1); + v=VAV(self); RZ(fs=fix(v->f)); gs=v->g; n=AN(gs); gv=AV(gs); + if(!(AT(w)&FL+CMPX))RZ(w=cvt(FL,w)); + RZ(e=scf((D)1e-7)); + RZ(t=sc(0L)); tv=AV(t); + RZ(s=ca(self)); v=VAV(s); v->g=t; v->lr=v->mr; + GA(z,BOX,n,AR(gs),AS(gs)); zv=AAV(z); + DO(n, *tv=d=gv[i]; zv[i]=(ff=dtab(fs,d))?df1(w,ff):sslope(tymes(e,w),w,s);); + RE(0); R ope(z); +} + +F2(jtdcap){A z;I r,*v; + RZ(a&&w); + ASSERT(NOUN&AT(w),EVDOMAIN); + RZ(w=vi(w)); v=AV(w); DO(AN(w), ASSERT(0<=v[i],EVNONCE);); + if(NOUN&AT(a))R vger2(CDCAP,a,w); + r=mr(a); + R !AR(w)&&nameless(a)&&(z=dtab(a,*v))?z:CDERIV(CDCAP,jtderiv1,0L,r,0L,r); +} + +F2(jtdcapco){I r,*v; + ASSERTVN(a,w); + RZ(w=vi(w)); v=AV(w); DO(AN(w), ASSERT(0<=v[i],EVNONCE);); + r=mr(a); + R CDERIV(CDCAPCO,0L,jtsslope,0L,r,r); +}
new file mode 100644 --- /dev/null +++ b/cf.c @@ -0,0 +1,199 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Forks */ + +#include "j.h" + +#define TC1(t) (t&NOUN?0:t&VERB?3:t&CONJ?2:1) +#define BD(ft,gt) (4*TC1(ft)+TC1(gt)) +#define TDECL V*sv=VAV(self);A fs=sv->f,gs=sv->g,hs=sv->h + +#define FOLK1 {A fx,hx; hx=CALL1(h1, w,hs); fx=CALL1(f1, w,fs); z=CALL2(g2,fx,hx,gs);} +#define FOLK2 {A fx,hx; hx=CALL2(h2,a,w,hs); fx=CALL2(f2,a,w,fs); z=CALL2(g2,fx,hx,gs);} +#define CAP1 {z=CALL1(g1,CALL1(h1, w,hs),gs);} +#define CAP2 {z=CALL1(g1,CALL2(h2,a,w,hs),gs);} + +static DF1(jtcork1){DECLFGH;PROLOG;A z; CAP1; EPILOG(z);} +static DF2(jtcork2){DECLFGH;PROLOG;A z; CAP2; EPILOG(z);} +static DF1(jtfolk1){DECLFGH;PROLOG;A z; FOLK1; EPILOG(z);} +static DF2(jtfolk2){DECLFGH;PROLOG;A z; FOLK2; EPILOG(z);} + +static B jtcap(J jt,A x){V*v; + while(v=VAV(x),CTILDE==v->id&&NAME&AT(v->f)&&(x=symbrd(v->f))); + R CCAP==v->id; +} + +static DF1(jtcorx1){DECLFGH;PROLOG;A z; if(cap(fs))RZ(z=df1( w,folk(ds(CCAP),gs,hs))) else FOLK1; EPILOG(z);} +static DF2(jtcorx2){DECLFGH;PROLOG;A z; if(cap(fs))RZ(z=df2(a,w,folk(ds(CCAP),gs,hs))) else FOLK2; EPILOG(z);} + /* f g h where f may be [: */ + +static DF1(jtnvv1){DECLFGH;PROLOG; EPILOG(CALL2(g2,fs,CALL1(h1, w,hs),gs));} +static DF2(jtnvv2){DECLFGH;PROLOG; EPILOG(CALL2(g2,fs,CALL2(h2,a,w,hs),gs));} + +static DF2(jtfolkcomp){DECLFGH;PROLOG;A z;AF f; + RZ(a&&w); + if(f=atcompf(a,w,self))z=f(jt,a,w,self); else if(cap(fs))CAP2 else FOLK2; + EPILOG(z); +} + +static DF2(jtfolkcomp0){DECLFGH;PROLOG;A z;AF f;D oldct=jt->ct; + RZ(a&&w); + jt->ct=0; + if(f=atcompf(a,w,self))z=f(jt,a,w,self); else if(cap(fs))CAP2 else FOLK2; + jt->ct=oldct; + EPILOG(z); +} + +static DF1(jtcharmapa){V*v=VAV(self); R charmap(w,VAV(v->h)->f,v->f);} +static DF1(jtcharmapb){V*v=VAV(self); R charmap(w,VAV(v->f)->f,VAV(v->h)->f);} + +A jtfolk(J jt,A f,A g,A h){A p,q,x,y;AF f1=jtfolk1,f2=jtfolk2;B b;C c,fi,gi,hi;I flag=0,j,m=-1;V*fv,*gv,*hv,*v; + RZ(f&&g&&h); + gv=VAV(g); gi=gv->id; + hv=VAV(h); hi=hv->id; + if(NOUN&AT(f)){ /* y {~ x i. ] */ + f1=jtnvv1; + if(LIT&AT(f)&&1==AR(f)&&gi==CTILDE&&CFROM==ID(gv->f)&&hi==CFORK){ + x=hv->f; + if(LIT&AT(x)&&1==AR(x)&&CIOTA==ID(hv->g)&&CRIGHT==ID(hv->h))f1=jtcharmapa; + } + R fdef(CFORK,VERB, f1,jtnvv2, f,g,h, flag, RMAX,RMAX,RMAX); + } + fv=VAV(f); fi=fv->id; + switch(fi){ + case CCAP: f1=jtcork1; f2=jtcork2; break; /* [: g h */ + case CTILDE: if(NAME&AT(fv->f)){f1=jtcorx1; f2=jtcorx2;} break; /* f g h */ + case CSLASH: if(gi==CDIV&&hi==CPOUND&&CPLUS==ID(fv->f))f1=jtmean; break; /* +/%# */ + case CAMP: /* x&i. { y"_ */ + case CFORK: /* (x i. ]) { y"_ */ + if(hi==CQQ&&(y=hv->f,LIT&AT(y)&&1==AR(y))&&equ(ainf,hv->g)&& + (x=fv->f,LIT&AT(x)&&1==AR(x))&&CIOTA==ID(fv->g)&& + (fi==CAMP||CRIGHT==ID(fv->h)))f1=jtcharmapb; break; + case CAT: /* <"1@[ { ] */ + if(gi==CLBRACE&&hi==CRIGHT){ + p=fv->f; q=fv->g; + if(CLEFT==ID(q)&&CQQ==ID(p)&&(v=VAV(p),x=v->f,CLT==ID(x)&&equ(one,v->g)))f2=jtsfrom; + }} + switch(fi==CCAP?gi:hi){ + case CQUERY: if(hi==CDOLLAR||hi==CPOUND)f2=jtrollk; break; + case CQRYDOT: if(hi==CDOLLAR||hi==CPOUND)f2=jtrollkx; break; + case CICAP: m=7; if(fi==CCAP){if(hi==CNE)f1=jtnubind; else if(FIT0(CNE,hv))f1=jtnubind0;} break; + case CSLASH: c=ID(gv->f); m=c==CPLUS?4:c==CPLUSDOT?5:c==CSTARDOT?6:-1; + if(fi==CCAP&&vaid(gv->f)&&vaid(h))f2=jtfslashatg; + break; + case CFCONS: if(hi==CFCONS){x=hv->h; j=*BAV(x); m=B01&AT(x)?(gi==CIOTA?j:gi==CICO?2+j:-1):-1;} break; + case CRAZE: if(hi==CLBRACE)f2=jtrazefrom; + else if(hi==CCUT){ + j=i0(hv->g); + if(CBOX==ID(hv->f)&&!j)f2=jtrazecut0; + else if(boxatop(h)&&j&&-2<=j&&j<=2){f1=jtrazecut1; f2=jtrazecut2;} + }} + if(0<=m){ + v=4<=m?hv:fv; b=CFIT==v->id&&equ(zero,v->g); + switch(b?ID(v->f):v->id){ + case CEQ: f2=b?jtfolkcomp0:jtfolkcomp; flag=0+8*m; break; + case CNE: f2=b?jtfolkcomp0:jtfolkcomp; flag=1+8*m; break; + case CLT: f2=b?jtfolkcomp0:jtfolkcomp; flag=2+8*m; break; + case CLE: f2=b?jtfolkcomp0:jtfolkcomp; flag=3+8*m; break; + case CGE: f2=b?jtfolkcomp0:jtfolkcomp; flag=4+8*m; break; + case CGT: f2=b?jtfolkcomp0:jtfolkcomp; flag=5+8*m; break; + case CEBAR: f2=b?jtfolkcomp0:jtfolkcomp; flag=6+8*m; break; + case CEPS: f2=b?jtfolkcomp0:jtfolkcomp; flag=7+8*m; break; + }} + R fdef(CFORK,VERB, f1,f2, f,g,h, flag, RMAX,RMAX,RMAX); +} + + +static DF1(taa){TDECL;A t=df1(w,fs); ASSERT(!t||AT(t)&NOUN+VERB,EVSYNTAX); R df1(t,gs);} +static DF1(tvc){TDECL; R df2(fs,w,gs);} /* also nc */ +static DF1(tcv){TDECL; R df2(w,gs,fs);} /* also cn */ + + +static CS1(jthook1, CALL2(f2,w,CALL1(g1,w,gs),fs)) +static CS2(jthook2, CALL2(f2,a,CALL1(g1,w,gs),fs)) + +static DF1(jthkiota){DECLFG;A a,e;I n;P*p; + RZ(w); + n=IC(w); + if(SB01&AT(w)&&1==AR(w)){ + p=PAV(w); a=SPA(p,a); e=SPA(p,e); + R *BAV(e)||equ(mtv,a) ? repeat(w,IX(n)) : repeat(SPA(p,x),ravel(SPA(p,i))); + } + R B01&AT(w)&&1>=AR(w) ? ifb(n,BAV(w)) : repeat(w,IX(n)); +} /* special code for (# i.@#) */ + +static DF1(jthkodom){DECLFG;B b=0;I n,*v; + RZ(w); + if(INT&AT(w)&&1==AR(w)){n=AN(w); v=AV(w); DO(n, if(b=0>v[i])break;); if(!b)R odom(2L,n,v);} + R CALL2(f2,w,CALL1(g1,w,gs),fs); +} /* special code for (#: i.@(* /)) */ + +static DF2(jthkeps){ + RZ(a&&w); + if(AT(a)==AT(w)&&AT(a)&IS1BYTE&&1==AN(a)){A z; + GA(z,B01,1,AR(a),AS(a)); + *BAV(z)=1&&memchr(CAV(w),*CAV(a),AN(w)); + R z; + } + R eps(a,gah(1L,w)); +} /* special code for (e.,) */ + +static DF2(jthkfrom){R from(a,gah(1L,w));} /* special code for ({ ,) */ +static DF2(jthktake){R take(a,gah(1L,w));} /* special code for ({.,) */ +static DF2(jthkdrop){R drop(a,gah(1L,w));} /* special code for (}.,) */ + +static DF1(jthkindexofmaxmin){D*du,*dv;I*iu,*iv,n,t,*wv,z=0;V*sv; + RZ(w&&self); + n=AN(w); t=AT(w); + if(!(1==AR(w)&&t&INT+FL))R hook1(w,self); + sv=VAV(self); wv=AV(w); + if(n)switch((t&FL?4:0)+(CICO==ID(sv->f)?2:0)+(CMAX==ID(VAV(sv->g)->f))){ + case 0: iu=iv= wv; DO(n, if(*iv<*iu)iu=iv; ++iv;); z=iu- wv; break; + case 1: iu=iv= wv; DO(n, if(*iv>*iu)iu=iv; ++iv;); z=iu- wv; break; + case 2: iu=iv= wv+n-1; DO(n, if(*iv<*iu)iu=iv; --iv;); z=iu- wv; break; + case 3: iu=iv= wv+n-1; DO(n, if(*iv>*iu)iu=iv; --iv;); z=iu- wv; break; + case 4: du=dv=(D*)wv; DO(n, if(*dv<*du)du=dv; ++dv;); z=du-(D*)wv; break; + case 5: du=dv=(D*)wv; DO(n, if(*dv>*du)du=dv; ++dv;); z=du-(D*)wv; break; + case 6: du=dv=(D*)wv+n-1; DO(n, if(*dv<*du)du=dv; --dv;); z=du-(D*)wv; break; + case 7: du=dv=(D*)wv+n-1; DO(n, if(*dv>*du)du=dv; --dv;); z=du-(D*)wv; + } + R sc(z); +} /* special code for (i.<./) (i.>./) (i:<./) (i:>./) */ + + +F2(jthook){AF f1=0,f2=0;C c,d,e,id;I flag=0;V*u,*v; + RZ(a&&w); + switch(BD(AT(a),AT(w))){ + default: ASSERT(0,EVSYNTAX); + case BD(VERB,VERB): + u=VAV(a); c=u->id; f1=jthook1; f2=jthook2; + v=VAV(w); d=v->id; e=ID(v->f); + if(d==CCOMMA)switch(c){ + case CDOLLAR: f2=jtreshape; flag+=VIRS2; break; + case CFROM: f2=jthkfrom; break; + case CTAKE: f2=jthktake; break; + case CDROP: f2=jthkdrop; break; + case CEPS: f2=jthkeps; + }else switch(c){ + case CSLDOT: if(COMPOSE(d)&&e==CIOTA&&CPOUND==ID(v->g)&&CBOX==ID(u->f))f1=jtgroup; break; + case CPOUND: if(COMPOSE(d)&&e==CIOTA&&CPOUND==ID(v->g))f1=jthkiota; break; + case CABASE: if(COMPOSE(d)&&e==CIOTA&&CSLASH==ID(v->g)&&CSTAR==ID(VAV(v->g)->f))f1=jthkodom; break; + case CIOTA: + case CICO: if(d==CSLASH&&(e==CMAX||e==CMIN))f1=jthkindexofmaxmin; break; + case CFROM: if(d==CGRADE)f2=jtordstati; else if(d==CTILDE&&e==CGRADE)f2=jtordstat; + } + R fdef(CHOOK, VERB, f1,f2, a,w,0L, flag, RMAX,RMAX,RMAX); + case BD(ADV, ADV ): f1=taa; break; + case BD(NOUN,CONJ): + case BD(VERB,CONJ): + f1=tvc; id=ID(w); + if(BOX&AT(a)&&(id==CATDOT||id==CGRAVE||id==CGRCO))flag=VGERL; + break; + case BD(CONJ,NOUN): + case BD(CONJ,VERB): + f1=tcv; id=ID(a); + if(BOX&AT(w)&&(id==CGRAVE||id==CPOWOP&&1<AN(w)))flag=VGERR; + } + R fdef(CADVF, ADV, f1,0L, a,w,0L, flag, 0L,0L,0L); +}
new file mode 100644 --- /dev/null +++ b/cg.c @@ -0,0 +1,233 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Gerunds ` and `: */ + +#include "j.h" + + +A jtfxeachv(J jt,I r,A w){A*wv,x,z,*zv;I n,wd; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(r>=AR(w),EVRANK); + ASSERT(n,EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + GA(z,BOX,n,AR(w),AS(w)); zv=AAV(z); + DO(n, RZ(zv[i]=x=fx(WVR(i))); ASSERT(VERB&AT(x),EVDOMAIN);); + R z; +} + +F1(jtfxeach){R every(w,0L,jtfx);} + +static DF1(jtcon1){A h,*hv,*x,z;V*sv; + PREF1(jtcon1); + sv=VAV(self); h=sv->h; hv=AAV(h); + GA(z,BOX,AN(h),AR(h),AS(h)); x=AAV(z); + DO(AN(h), RZ(*x++=CALL1(VAV(*hv)->f1, w,*hv)); ++hv;); + R ope(z); +} + +static DF2(jtcon2){A h,*hv,*x,z;V*sv; + PREF2(jtcon2); + sv=VAV(self); h=sv->h; hv=AAV(h); + GA(z,BOX,AN(h),AR(h),AS(h)); x=AAV(z); + DO(AN(h), RZ(*x++=CALL2(VAV(*hv)->f2,a,w,*hv)); ++hv;); + R ope(z); +} + +static DF1(jtinsert){A f,hs,*hv,z;AF*hf;I j,k,m,n,old; + RZ(w); + n=IC(w); j=n-1; hs=VAV(self)->h; m=AN(hs); hv=AAV(hs); + if(!n)R df1(w,iden(*hv)); + GA(f,INT,m,1,0); hf=(AF*)AV(f); DO(m, hf[i]=VAV(hv[i])->f2;); + RZ(z=from(num[-1],w)); + old=jt->tbase+jt->ttop; + DO(n-1, k=--j%m; RZ(z=CALL2(hf[k],from(sc(j),w),z,hv[k])); gc(z,old);) + R z; +} + +F2(jtevger){A hs;I k; + RZ(a&&w); + RE(k=i0(w)); + if(k==GTRAIN)R exg(a); + RZ(hs=fxeachv(RMAX,a)); + switch(k){ + case GAPPEND: + R fdef(CGRCO,VERB, jtcon1,jtcon2, a,w,hs, VGERL, RMAX,RMAX,RMAX); + case GINSERT: + ASSERT(1>=AR(a),EVRANK); + R fdef(CGRCO,VERB, jtinsert,0L, a,w,hs, VGERL, RMAX,0L,0L); + default: + ASSERT(0,EVDOMAIN); +}} + +F2(jttie){RZ(a&&w); R over(VERB&AT(a)?arep(a):a,VERB&AT(w)?arep(w):w);} + + +static B jtatomic(J jt,C m,A w){A f,g;B ax,ay,vf,vg;C c,id;V*v; + static C atomic12[]={CMIN, CLE, CMAX, CGE, CPLUS, CPLUSCO, CSTAR, CSTARCO, CMINUS, CDIV, CROOT, + CEXP, CLOG, CSTILE, CBANG, CLEFT, CRIGHT, CJDOT, CCIRCLE, CRDOT, CHGEOM, CFCONS, 0}; + static C atomic1[]={CNOT, CHALVE, 0}; + static C atomic2[]={CEQ, CLT, CGT, CPLUSDOT, CSTARDOT, CNE, 0}; + RZ(w&&VERB&AT(w)); + v=VAV(w); id=v->id; + if(strchr(atomic12,id)||strchr(1==m?atomic1:atomic2,id))R 1; + f=v->f; vf=f&&VERB&AT(f); ax=f&&NOUN&AT(f)&&!AR(f); + g=v->g; vg=g&&VERB&AT(g); ay=g&&NOUN&AT(g)&&!AR(g); + switch(id){ + case CAT: + case CATCO: R atomic(1,f)&&atomic(m,g); + case CUNDER: + case CUNDCO: R atomic(m,f)&&atomic(1,g); + case CAMPCO: R atomic(m,f)&&atomic(1,g); + case CQQ: R ax||atomic(m,f); + case CFORK: R (CCAP==ID(f)?atomic(1,g):atomic(m,f)&&atomic(2,g))&&atomic(m,v->h); + case CHOOK: R atomic(2,f)&&atomic(1,g); + case CTILDE: R NAME&AT(f)?atomic(m,fix(f)):atomic(2,f); + case CFIT: R atomic(m,f); + case CAMP: + if(vf&&vg)R atomic(m,f)&&atomic(1,g); + if(ax&&atomic(2,g)||ay&&atomic(2,f))R 1; + if(vg&&1==AR(f)){c=ID(g); R c==CPOLY||c==CBASE;} + } + R 0; +} /* 1 iff verb w is atomic; 1=m monad 2=m dyad */ + +static A jtgjoin(J jt,C c,A a,A w){A f; + RZ(a&&w); + ASSERT(1>=AR(a)&&1>=AR(w),EVRANK); + ASSERT((!AN(a)||BOX&AT(a))&&(!AN(w)||BOX&AT(w)),EVDOMAIN); + RZ(f=qq(atop(ds(CBOX),ds(CCOMMA)),zero)); + R df2(box(spellout(c)),df2(a,w,f),f); +} + +static DF1(jtcase1a){A g,h,*hv,k,t,u,w0=w,x,y,*yv,z;B b;I r,*xv;V*sv; + RZ(w); + r=AR(w); + if(1<r)RZ(w=gah(1L,w)); + sv=VAV(self); g=sv->g; + if(atomic(1,g))RZ(k=df1(w,g)) + else{RZ(k=df1(w,qq(g,zero))); ASSERT(AR(k)==AR(w)&&AN(k)==AN(w),EVRANK);} + if(B01&AT(k)){ + h=sv->h; ASSERT(2<=AN(h),EVINDEX); hv=AAV(h); + RZ(x=df1(t=repeat(not(k),w),hv[0])); if(!AR(x))RZ(x=reshape(tally(t),x)); + RZ(y=df1(t=repeat(k, w),hv[1])); if(!AR(y))RZ(y=reshape(tally(t),y)); + RZ(z=!AN(x)?y:!AN(y)?x:from(grade1(grade1(k)),over(x,y))); + }else{ + RZ(u=nub(k)); + RZ(y=df2(k,w,sldot(gjoin(CATCO,box(scc(CBOX)),from(u,sv->f))))); yv=AAV(y); + b=0; DO(AN(y), if(b=!AR(yv[i]))break;); + if(b){ + RZ(x=df2(k,w,sldot(ds(CPOUND)))); xv=AV(x); + DO(AN(y), if(!AR(yv[i]))RZ(yv[i]=reshape(sc(xv[i]),yv[i]));); + } + RZ(z=from(grade1(grade1(k)),raze(grade2(y,u)))); + } + if(1<r){RZ(z=gah(r,z)); ICPY(AS(z),AS(w0),r);} + R z; +} + +static DF1(jtcase1b){A h,u;V*sv; + sv=VAV(self); h=sv->h; + RZ(u=from(df1(w,sv->g),h)); + ASSERT(!AR(u),EVRANK); + R df1(w,*AAV(u)); +} + +static DF1(jtcase1){A h,*hv;B b;I r,wr;V*sv; + RZ(w); + sv=VAV(self); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; r=MIN(r,sv->mr); jt->rank=0; + if(b=!r&&wr&&AN(w)){h=sv->h; hv=AAV(h); DO(AN(h), if(!atomic(1,hv[i])){b=0; break;});} + R b?case1a(w,self):rank1ex(w,self,r,jtcase1b); +} + +static DF2(jtcase2){A u;V*sv; + PREF2(jtcase2); + sv=VAV(self); + RZ(u=from(df2(a,w,sv->g),sv->h)); + ASSERT(!AR(u),EVRANK); + R df2(a,w,*AAV(u)); +} + +static F2(jtgerfrom){A*av,*v,z;I ad,n; + RZ(a&&w); /* 1==AR(w)&&BOX&AT(w) */ + ASSERT(1>=AR(a),EVRANK); + if(NUMERIC&AT(a))R from(a,w); + else{ + ASSERT(BOX&AT(a),EVDOMAIN); + n=AN(a); av=AAV(a); ad=(I)a*ARELATIVE(a); + GA(z,BOX,n,1,0); v=AAV(z); + DO(n, RZ(*v++=gerfrom(AVR(i),w));); + R z; +}} + +F2(jtagenda){ + RZ(a&&w) + if(NOUN&AT(w))R exg(gerfrom(w,a)); + R fdef(CATDOT,VERB, jtcase1,jtcase2, a,w,fxeachv(1L,a), VGERL, mr(w),lr(w),rr(w)); +} + + +static DF1(jtgcl1){DECLFG;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df2(df1(w,hv[1]),gs,ds(sv->id)); FDEPDEC(d); + R df1(df1(w,hv[2]),ff); +} + +static DF1(jtgcr1){DECLFG;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df2(fs,df1(w,hv[1]),ds(sv->id)); FDEPDEC(d); + R df1(df1(w,hv[2]),ff); +} + +static DF2(jtgcl2){DECLFG;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df2(df2(a,w,hv[1]),gs,ds(sv->id)); FDEPDEC(d); + R df2(df2(a,w,hv[0]),df2(a,w,hv[2]),ff); +} + +static DF2(jtgcr2){DECLFG;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df2(fs,df2(a,w,hv[1]),ds(sv->id)); FDEPDEC(d); + R df2(df2(a,w,hv[0]),df2(a,w,hv[2]),ff); +} + +A jtgconj(J jt,A a,A w,C id){A hs,y;B na;I n; + RZ(a&&w); + ASSERT(VERB&AT(a)&&BOX&AT(w)||BOX&AT(a)&&VERB&AT(w),EVDOMAIN); + na=1&&BOX&AT(a); y=na?a:w; n=AN(y); + ASSERT(1>=AR(y),EVRANK); + ASSERT(2==n||3==n,EVLENGTH); + ASSERT(BOX&AT(y),EVDOMAIN); + RZ(hs=fxeach(3==n?y:link(scc(CLEFT),y))); + R fdef(id,VERB, na?jtgcl1:jtgcr1,na?jtgcl2:jtgcr2, a,w,hs, na?VGERL:VGERR, RMAX,RMAX,RMAX); +} + +static DF1(jtgav1){DECLF;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df1(df1(w,hv[1]),ds(sv->id)); FDEPDEC(d); + R df1(df1(w,hv[2]),ff); +} + +static DF2(jtgav2){DECLF;A ff,*hv=AAV(sv->h);I d; + d=fdep(hv[1]); FDEPINC(d); ff=df1(df2(a,w,hv[1]),ds(sv->id)); FDEPDEC(d); + R df2(df2(a,w,hv[0]),df2(a,w,hv[2]),ff); +} + +A jtgadv(J jt,A w,C id){A hs;I n; + RZ(w); + ASSERT(BOX&AT(w),EVDOMAIN); + n=AN(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(n&&n<=3,EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + RZ(hs=fxeach(3==n?w:behead(reshape(num[4],w)))); + R fdef(id,VERB, jtgav1,jtgav2, w,0L,hs, VGERL, RMAX,RMAX,RMAX); +} + + +static DF1(jtgf1){A h=VAV(self)->h; R df1( w,*AAV(h));} +static DF2(jtgf2){A h=VAV(self)->h; R df2(a,w,*AAV(h));} + +A jtvger2(J jt,C id,A a,A w){A h,*hv,x;V*v; + RZ(x=a?a:w); + ASSERT(2==AN(x),EVLENGTH); + RZ(h=fxeachv(1L,x)); hv=AAV(h); v=VAV(*hv); + R fdef(id,VERB, jtgf1,jtgf2, x,a?w:0L, h, VGERL, (I)v->mr,(I)v->lr,(I)v->rr); +} /* verify and define 2-element gerund */
new file mode 100644 --- /dev/null +++ b/ch.c @@ -0,0 +1,119 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Hypergeometric Series */ + +#include "j.h" + + +static A jthparm(J jt,A j,A f,A h){A z; + if(!(VERB&AT(f)))R shift1(aslash(CSTAR,atab(CPLUS,h,j))); + RZ(z=CALL1(VAV(f)->f1,j,f)); + ASSERT(1>=AR(z),EVRANK); + ASSERT(!AR(z)||AN(j)==AN(z),EVLENGTH); + R z; +} + +static A jthgv(J jt,B b,I n,A w,A self){A c,d,e,h,*hv,j,y;V*sv=VAV(self); + RZ(j=IX(n)); h=sv->h; hv=AAV(h); + c=hparm(j,sv->f,hv[0]); + d=hparm(j,sv->g,hv[1]); + e=shift1(divide(w,apv(n,1L,1L))); + switch((VERB&AT(sv->f)?2:0)+(VERB&AT(sv->g)?1:0)){ + case 0: y=ascan(CSTAR,divide(tymes(c,e),d)); break; + case 1: y=divide(ascan(CSTAR,tymes(c,e)),d); break; + case 2: y=divide(tymes(c,ascan(CSTAR,e)),ascan(CSTAR,d)); break; + case 3: y=divide(tymes(c,ascan(CSTAR,e)),d); + } + R b?over(zero,ascan(CPLUS,y)):aslash(CPLUS,y); +} /* verb or complex cases */ + +static A jthgd(J jt,B b,I n,A w,A p,A q){A c,d,e,z;D r,s,t,*u,*v,x,*zv;I j,pn,qn; + RZ(c=cvt(FL,p)); u=DAV(c); pn=AN(c); + RZ(d=cvt(FL,q)); v=DAV(d); qn=AN(d); + RZ(e=cvt(FL,w)); x=*DAV(e); r=s=1; t=0; z=0; + if(b&&2000>n){GA(z,FL,1+n,1,0); zv=DAV(z); *zv++=0; *zv++=1;} + NAN0; + for(j=1;j<n&&t!=s&&!_isnan(s);++j){ + DO(pn, r*=u[i]; ++u[i];); /* r*=u[i]++; compiler error on 3B1 */ + DO(qn, r/=v[i]; ++v[i];); + r*=x/j; t=s; s+=r; if(z)*zv++=s; JBREAK0; + } + NAN1; + R !b?scf(s):z?take(sc(1+j),z):hgd(b,j,w,p,q); +} /* real vector p,q; real scalar w; all terms (1=b) or last term (0=b) */ + +static DF2(jthgeom2){PROLOG;A h,*hv,t,z;B b;I an,*av,j,n;V*sv=VAV(self); + RZ(a&&w); + if(AR(w))R rank2ex(a,w,self,0L,0L,jthgeom2); + RZ(a=AT(a)&FL+CMPX?vib(a):vi(a)); + an=AN(a); av=AV(a); n=0; DO(an, j=av[i]; ASSERT(0<=j,EVDOMAIN); if(n<j)n=j;); + if(!n)R tymes(zero,a); + h=sv->h; hv=AAV(h); + b=VERB&(AT(sv->f)|AT(sv->g))||CMPX&(AT(w)|AT(hv[0])|AT(hv[1])); + if(!b)z=hgd((B)(1<an),n,w,hv[0],hv[1]); + else if(2000>n)z=hgv((B)(1<an),n,w,self); + else{ + j=10; t=mtv; z=one; + while(z&&!equ(z,t)){t=z; z=hgv(0,j,w,self); j+=j;} + RZ(z); if(1<an)z=hgv(1,j,w,self); + } + if(1<an)z=from(minimum(a,sc(IC(z)-1)),z); + EPILOG(z); +} + +static DF1(jthgeom1){R hgeom2(sc(IMAX),w,self);} + +static F2(jtcancel){A c,d,f,x,y; + f=eval("#/.~"); + a=ravel(a); x=nub(a); c=df1(a,f); + w=ravel(w); y=nub(w); d=df1(w,f); + a=repeat(maximum(zero,minus(c,from(indexof(y,x),over(d,zero)))),x); + w=repeat(maximum(zero,minus(d,from(indexof(x,y),over(c,zero)))),y); + R link(a,w); +} + +F2(jthgeom){A c,d,h=0;B p,q;I at,wt; + RZ(a&&w); + at=AT(a); p=1&&at&NOUN; c=d=mtv; + wt=AT(w); q=1&&wt&NOUN; + if(p){c=a; ASSERT(!AN(a)||at&NUMERIC,EVDOMAIN); ASSERT(1>=AR(a),EVRANK);} + if(q){d=w; ASSERT(!AN(w)||wt&NUMERIC,EVDOMAIN); ASSERT(1>=AR(w),EVRANK);} + RZ(h=cancel(c,d)); + R fdef(CHGEOM,VERB, jthgeom1,jthgeom2, a,w,h, 0L, 0L,0L,0L); +} /* a H. w */ + +F1(jthgdiff){A*hv,p,q,x,y;V*v=VAV(w); + ASSERTNN(v->f,v->g); + hv=AAV(v->h); + x=hv[0]; x=1==AN(x)?head(x):x; + y=hv[1]; y=1==AN(y)?head(y):y; + p=divide(aslash(CSTAR,x),aslash(CSTAR,y)); + q=hgeom(increm(x),increm(y)); + R equ(p,one)?q:folk(qq(p,zero),ds(CSTAR),q); +} /* a H. w D. 1 */ + +DF1(jthgcoeff){PROLOG;A c,d,h,*hv,y,z;B b;I j,n,pn,qn,*v;V*sv=VAV(self); + RZ(w=vi(w)); v=AV(w); + n=0; DO(AN(w), j=v[i]; ASSERT(0<=j,EVDOMAIN); if(n<j)n=j;); + if(!n)R eq(w,w); + h=sv->h; hv=AAV(h); + b=VERB&(AT(sv->f)|AT(sv->g))||CMPX&(AT(w)|AT(hv[0])|AT(hv[1])); + if(!b){D r=1.0,*u,*v,*yv; + RZ(c=cvt(FL,hv[0])); u=DAV(c); pn=AN(c); + RZ(d=cvt(FL,hv[1])); v=DAV(d); qn=AN(d); + GA(y,FL,n,1,0); yv=DAV(y); + DO(n, DO(pn, r*=u[i]; ++u[i];); DO(qn, r/=v[i]; ++v[i];); yv[i]=r;); + }else{A j; + RZ(j=IX(n)); + c=hparm(j,sv->f,hv[0]); + d=hparm(j,sv->g,hv[1]); + switch((VERB&AT(sv->f)?2:0)+(VERB&AT(sv->g)?1:0)){ + case 0: y=ascan(CSTAR,divide(c,d)); break; + case 1: y=divide(ascan(CSTAR,c),d); break; + case 2: y=divide(c,ascan(CSTAR,d)); break; + case 3: y=divide(c,d); + }} + RZ(z=from(w,over(one,y))); + EPILOG(z); +} /* coefficients indexed by w excluding !j */
new file mode 100644 --- /dev/null +++ b/cip.c @@ -0,0 +1,270 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Inner Product */ + +#include "j.h" +#include "vasm.h" + + +static A jtipprep(J jt,A a,A w,I zt,I*pm,I*pn,I*pp){A z=mark;I*as,ar,ar1,m,mn,n,p,*ws,wr,wr1; + ar=AR(a); as=AS(a); ar1=ar?ar-1:0; RE(*pm=m=prod(ar1, as)); + wr=AR(w); ws=AS(w); wr1=wr?wr-1:0; RE(*pn=n=prod(wr1,1+ws)); RE(mn=mult(m,n)); + *pp=p=ar?*(as+ar1):wr?*ws:1; + ASSERT(!(ar&&wr)||p==*ws,EVLENGTH); + GA(z,zt,mn,ar1+wr1,0); + ICPY(AS(z), as,ar1); + ICPY(AS(z)+ar1,1+ws,wr1); + R z; +} /* argument validation & result for an inner product */ + +#define IINC(x,y) {b=0>x; x+=y; BOV(b==0>y&&b!=0>x);} +#define DINC(x,y) {x+=y;} +#define ZINC(x,y) {(x).re+=(y).re; (x).im+=(y).im;} + +#define PDTBY(Tz,Tw,INC) \ + {Tw*v,*wv;Tz c,*x,zero,*zv; \ + v=wv=(Tw*)AV(w); zv=(Tz*)AV(z); memset(&zero,C0,sizeof(Tz)); \ + if(1==n)DO(m, v=wv; c=zero; DO(p, if(*u++)INC(c,*v); ++v;); *zv++=c;) \ + else DO(m, v=wv; memset(zv,C0,zk); DO(p, x=zv; if(*u++)DO(n, INC(*x,*v); ++x; ++v;) else v+=n;); zv+=n; ); \ + } + +#define PDTXB(Tz,Ta,INC,INIT) \ + {Ta*u;Tz c,*x,zero,*zv; \ + u= (Ta*)AV(a); zv=(Tz*)AV(z); memset(&zero,C0,sizeof(Tz)); \ + if(1==n)DO(m, v=wv; c=zero; DO(p, if(*v++)INC(c,*u); ++u; ); *zv++=c;) \ + else DO(m, v=wv; memset(zv,C0,zk); DO(p, x=zv; INIT; DO(n, if(*v++)INC(*x,c); ++x;);); zv+=n; ); \ + } + +static F2(jtpdtby){A z;B b,*u,*v,*wv;C er=0;I at,m,n,p,t,wt,zk; + at=AT(a); wt=AT(w); t=at&B01?wt:at; + RZ(z=ipprep(a,w,t,&m,&n,&p)); zk=n*bp(t); u=BAV(a); v=wv=BAV(w); + NAN0; + switch(t){ + default: ASSERT(0,EVDOMAIN); + case CMPX: if(at&B01)PDTBY(Z,Z,ZINC) else PDTXB(Z,Z,ZINC,c=*u++ ); break; + case FL: if(at&B01)PDTBY(D,D,DINC) else PDTXB(D,D,DINC,c=*u++ ); break; + case INT: if(at&B01)PDTBY(I,I,IINC) else PDTXB(I,I,IINC,c=*u++ ); + if(er==EWOV){ + RZ(z=ipprep(a,w,FL,&m,&n,&p)); zk=n*sizeof(D); u=BAV(a); v=wv=BAV(w); + if(at&B01)PDTBY(D,I,IINC) else PDTXB(D,I,IINC,c=(D)*u++); + }} + NAN1; + R z; +} /* x +/ .* y where x or y (but not both) is Boolean */ + +#define BBLOCK(nn) \ + d=ti; DO(nw, *d++=0;); \ + DO(nn, if(*u++){vi=(UI*)v; d=ti; DO(nw, *d+++=*vi++;);} v+=n;); \ + x=zv; c=tc; DO(n, *x+++=*c++;); + +#if defined(NOASM) && SY_64 +/* +*** from asm64noovf.c +C asminnerprodx(I m,I*z,I u,I*y) +{ + I i=-1,t; +l1: + ++i; + if(i==m) return 0; + t= u FTIMES y[i]; + ov(t) + t= t FPLUS z[i]; + ov(t) + z[i]=t; + goto l1; +} +*/ + +C asminnerprodx(I m,I*z,I u,I*y) +{ + I i=-1,t,p;DI tdi; +l1: + ++i; + if(i==m) return 0; + tdi = u * (DI)y[i]; + t=(I)tdi; + if (tdi<IMIN||IMAX<tdi) R EWOV; + p=0>t; + t= t + z[i]; + if (p==0>z[i]&&p!=0>t) R EWOV; + z[i]=t; + goto l1; +} +#endif + +F2(jtpdt){PROLOG;A z;I ar,at,i,m,n,p,p1,t,wr,wt; + RZ(a&&w); + ar=AR(a); at=AN(a)?AT(a):B01; + wr=AR(w); wt=AN(w)?AT(w):B01; + if((at|wt)&SPARSE)R pdtsp(a,w); + if((at|wt)&XNUM+RAT)R df2(a,w,atop(slash(ds(CPLUS)),qq(ds(CSTAR),v2(1L,AR(w))))); + if(ar&&wr&&AN(a)&&AN(w)&&at!=wt&&B01&at+wt)R pdtby(a,w); + t=coerce2(&a,&w,B01); + ASSERT(t&NUMERIC,EVDOMAIN); + RZ(z=ipprep(a,w,t&B01?INT:t&INT&&!SY_64?FL:t,&m,&n,&p)); + if(!p){memset(AV(z),C0,AN(z)*bp(AT(z))); R z;} + if(!ar!=!wr){if(ar)RZ(w=reshape(sc(p),w)) else RZ(a=reshape(sc(p),a));} + p1=p-1; + switch(t){ + case B01: + if(0==n%SZI||!SY_ALIGN){A tt;B*u,*v,*wv;I nw,q,r,*x,*zv;UC*c,*tc;UI*d,*ti,*vi; + q=p/255; r=p%255; nw=(n+SZI-1)/SZI; + GA(tt,INT,nw,1,0); ti=(UI*)AV(tt); tc=(UC*)ti; + u=BAV(a); v=wv=BAV(w); zv=AV(z); + for(i=0;i<m;++i,v=wv,zv+=n){x=zv; DO(n, *x++=0;); DO(q, BBLOCK(255);); BBLOCK(r);} + }else{B*u,*v,*wv;I*x,*zv; + u=BAV(a); v=wv=BAV(w); zv=AV(z); + for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; if(*u++)DO(n, *x++ =*v++;) else{v+=n; DO(n, *x++=0;);} + DO(p1, x=zv; if(*u++)DO(n, *x+++=*v++;) else v+=n;); + }} + break; + case INT: +#if SY_64 + {C er=0;I c,*u,*v,*wv,*x,*zv; + u=AV(a); v=wv=AV(w); zv=AV(z); + /* + for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; c=*u++; er=asmtymes1v(n,x,c,v); if(er)break; v+=n; + DO(p1, x=zv; c=*u++; er=asminnerprodx(n,x,c,v); if(er)break; v+=n;); + + */ + for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; c=*u++; TYMES1V(n,x,c,v); if(er)break; v+=n; + DO(p1, x=zv; c=*u++; er=asminnerprodx(n,x,c,v); if(er)break; v+=n;); + if(er)break; + } + if(er){A z1;D c,*x,*zv;I*u,*v,*wv; + GA(z1,FL,AN(z),AR(z),AS(z)); z=z1; + u=AV(a); v=wv=AV(w); zv=DAV(z); + for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; c=(D)*u++; DO(n, *x++ =c**v++;); + DO(p1, x=zv; c=(D)*u++; DO(n, *x+++=c**v++;);); + }}} +#else + {D c,*x,*zv;I*u,*v,*wv; + u=AV(a); v=wv=AV(w); zv=DAV(z); + if(1==n)DO(m, v=wv; c=0.0; DO(p, c+=*u++*(D)*v++;); *zv++=c;) + else for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; c=(D)*u++; DO(n, *x++ =c**v++;); + DO(p1, x=zv; c=(D)*u++; DO(n, *x+++=c**v++;);); + } + RZ(z=icvt(z)); + } +#endif + break; + case FL: + {D c,s,t,*u,*v,*wv,*x,*zv; + u=DAV(a); v=wv=DAV(w); zv=DAV(z); + NAN0; + if(1==n){DO(m, v=wv; c=0.0; DO(p, s=*u++; t=*v++; c+=s&&t?s*t:0;); *zv++=c;);} + else for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; if(c=*u++){if(INF(c))DO(n, *x++ =*v?c**v:0.0; ++v;)else DO(n, *x++ =c**v++;);}else{v+=n; DO(n, *x++=0.0;);} + DO(p1, x=zv; if(c=*u++){if(INF(c))DO(n, *x+++=*v?c**v:0.0; ++v;)else DO(n, *x+++=c**v++;);}else v+=n;); + } + NAN1; + } + break; + case CMPX: + {Z c,*u,*v,*wv,*x,*zv; + u=ZAV(a); v=wv=ZAV(w); zv=ZAV(z); + if(1==n)DO(m, v=wv; c=zeroZ; DO(p, c.re+=ZRE(*u,*v); c.im+=ZIM(*u,*v); ++u; ++v;); *zv++=c;) + else for(i=0;i<m;++i,v=wv,zv+=n){ + x=zv; c=*u++; DO(n, x->re =ZRE(c,*v); x->im =ZIM(c,*v); ++x; ++v;); + DO(p1, x=zv; c=*u++; DO(n, x->re+=ZRE(c,*v); x->im+=ZIM(c,*v); ++x; ++v;);); + }}} + EPILOG(z); +} + +#define IPBX(F) \ + for(i=0;i<m;++i){ \ + memcpy(zv,*av?v1:v0,n); if(ac)++av; \ + for(j=1;j<p;++j){ \ + uu=(I*)zv; vv=(I*)(*av?v1+j*wc:v0+j*wc); if(ac)++av; \ + DO(q, *uu++F=*vv++;); \ + if(r){u=(B*)uu; v=(B*)vv; DO(r, *u++F=*v++;);} \ + } \ + zv+=n; \ + } + +#define IPBX0 0 +#define IPBX1 1 +#define IPBXW 2 +#define IPBXNW 3 + +static A jtipbx(J jt,A a,A w,C c,C d){A g=0,x0,x1,z;B*av,b,e,*u,*v,*v0,*v1,*zv;C c0,c1; + I ac,i,j,m,n,p,q,r,*uu,*vv,wc; + RZ(a&&w); + RZ(z=ipprep(a,w,B01,&m,&n,&p)); + ac=AR(a)?1:0; wc=AR(w)?n:0; q=n/SZI; r=n%SZI; + switch(B01&AT(w)?d:0){ + case CEQ: c0=IPBXNW; c1=IPBXW; break; + case CNE: c0=IPBXW; c1=IPBXNW; break; + case CPLUSDOT: case CMAX: c0=IPBXW; c1=IPBX1; break; + case CSTARDOT: case CMIN: case CSTAR: c0=IPBX0; c1=IPBXW; break; + case CLT: c0=IPBXW; c1=IPBX0; break; + case CGT: c0=IPBX0; c1=IPBXNW; break; + case CLE: c0=IPBX1; c1=IPBXW; break; + case CGE: c0=IPBXNW; c1=IPBX1; break; + case CPLUSCO: c0=IPBXNW; c1=IPBX0; break; + case CSTARCO: c0=IPBX1; c1=IPBXNW; break; + default: c0=c1=-1; g=ds(d); RZ(x0=df2(zero,w,g)); RZ(x1=df2(zero,w,g)); + } + if(!g)RZ(x0=c0==IPBX0?reshape(sc(n),zero):c0==IPBX1?reshape(sc(c==CNE?AN(w):n),one):c0==IPBXW?w:not(w)); + if(!g)RZ(x1=c1==IPBX0?reshape(sc(n),zero):c1==IPBX1?reshape(sc(c==CNE?AN(w):n),one):c1==IPBXW?w:not(w)); + av=BAV(a); zv=BAV(z); v0=BAV(x0); v1=BAV(x1); + switch(c){ + case CPLUSDOT: +#define F(x,y) *x++|=*y++ +#include "cip_t.h" + break; + case CSTARDOT: +#define F(x,y) *x++&=*y++ +#include "cip_t.h" + break; + case CNE: +#define F(x,y) *x++^=*y++ +#include "cip_t.h" + break; + } + R z; +} /* a f/ . g w where a and w are nonempty and a is boolean */ + +static DF2(jtdotprod){A fs,gs;C c,d;I r;V*sv; + RZ(a&&w&&self); + sv=VAV(self); fs=sv->f; gs=sv->g; + if(B01&AT(a)&&AN(a)&&AN(w)&&CSLASH==ID(fs)&&(d=vaid(gs))&& + (c=vaid(VAV(fs)->f),c==CSTARDOT||c==CPLUSDOT||c==CNE))R ipbx(a,w,c,d); + r=lr(gs); + R df2(a,w,atop(fs,qq(gs,v2(r==RMAX?r:1+r,RMAX)))); +} + + +F1(jtminors){A d; + RZ(d=apv(3L,-1L,1L)); *AV(d)=0; + R drop(d,df2(one,w,bsdot(ds(CLEFT)))); +} + +static DF1(jtdet){DECLFG;A h=sv->h;I c,r,*s; + RZ(w); + r=AR(w); s=AS(w); + if(h&&1<r&&2==s[r-1]&&s[r-2]==s[r-1])R df1(w,h); + F1RANK(2,jtdet,self); + c=2>r?1:s[1]; + R !c ? df1(mtv,slash(gs)) : 1==c ? CALL1(f1,ravel(w),fs) : h && c==*s ? gaussdet(w) : detxm(w,self); +} + +DF1(jtdetxm){R dotprod(irs1(w,0L,1L,jthead),det(minors(w),self),self);} + /* determinant via expansion by minors. w is matrix with >1 columns */ + +F2(jtdot){A f,h=0;AF f2=jtdotprod;C c,d; + ASSERTVV(a,w); + if(CSLASH==ID(a)){ + f=VAV(a)->f; c=ID(f); d=ID(w); + if(d==CSTAR){ + if(c==CPLUS )f2=jtpdt; + if(c==CMINUS)RZ(h=eval("[: -/\"1 {.\"2 * |.\"1@:({:\"2)")); + }} + R fdef(CDOT,VERB, jtdet,f2, a,w,h, 0L, 2L,RMAX,RMAX); +}
new file mode 100644 --- /dev/null +++ b/cip_t.h @@ -0,0 +1,41 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Template for ipbx (boolean inner products) */ + +/* requires F(x,y) *x++g=*y++ where g is one of | & ^ */ + +if(c==CPLUSDOT&&(c0==IPBX1||c1==IPBX1)||c==CSTARDOT&&(c0==IPBX0||c1==IPBX0)){ + e=c==CPLUSDOT?c1==IPBX1:c1==IPBX0; + for(i=0;i<m;++i){ + b=*av; if(ac)++av; memcpy(zv,b?v1:v0,n); if(b==e){zv+=n; continue;} + for(j=1;j<p;++j){ + b=*av; if(ac)++av; if(b==e){memset(zv,c==CPLUSDOT?C1:C0,n); break;} + uu=(I*)zv; vv=(I*)(b?v1+j*wc:v0+j*wc); + DO(q, F(uu,vv);); + if(r){u=(B*)uu; v=(B*)vv; DO(r, F(u,v););} + } + zv+=n; +}}else if(c==CPLUSDOT&&(c0==IPBX0||c1==IPBX0)||c==CSTARDOT&&(c0==IPBX1||c1==IPBX1)|| + c==CNE&&(c0==IPBX0||c1==IPBX0)){ + e=c==CSTARDOT?c1==IPBX1:c1==IPBX0; + for(i=0;i<m;++i){ + b=*av; if(ac)++av; memcpy(zv,b?v1:v0,n); + for(j=1;j<p;++j){ + b=*av; if(ac)++av; if(b==e)continue; + uu=(I*)zv; vv=(I*)(b?v1+j*wc:v0+j*wc); + DO(q, F(uu,vv);); + if(r){u=(B*)uu; v=(B*)vv; DO(r, F(u,v););} + } + zv+=n; +}}else + for(i=0;i<m;++i){ + memcpy(zv,*av?v1:v0,n); if(ac)++av; + for(j=1;j<p;++j){ + uu=(I*)zv; vv=(I*)(*av?v1+j*wc:v0+j*wc); if(ac)++av; + DO(q, F(uu,vv);); + if(r){u=(B*)uu; v=(B*)vv; DO(r, F(u,v););} + } + zv+=n; + } +#undef F
new file mode 100644 --- /dev/null +++ b/cl.c @@ -0,0 +1,106 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: L: and S: */ + +#include "j.h" + + +static A jtlev1(J jt,A w,A self){A fs; + RZ(w&&self); + if(jt->lmon>=level(w)){fs=VAV(self)->f; R CALL1(VAV(fs)->f1,w,fs);} else R every(w,self,jtlev1); +} + +static A jtlev2(J jt,A a,A w,A self){A fs; + RZ(a&&w&&self); + switch((jt->lleft>=level(a)?2:0)+(jt->lright>=level(w))){ + case 0: R every2(a, w, self,jtlev2); + case 1: R every2(a, box(w),self,jtlev2); + case 2: R every2(box(a),w, self,jtlev2); + default: fs=VAV(self)->f; R CALL2(VAV(fs)->f2,a,w,fs); +}} + +static I jtefflev(J jt,I j,A h,A x){I n,t; n=*(j+AV(h)); R n>=0?n:(t=level(x),MAX(0,n+t));} + +static DF1(jtlcapco1){A z;I m;V*v=VAV(self); + RZ(w); + m=jt->lmon; jt->lmon=efflev(0L,v->h,w); + z=lev1(w,self); + jt->lmon=m; + R z; +} + +static DF2(jtlcapco2){A z;I l,r;V*v=VAV(self); + RZ(a&&w); + l=jt->lleft; jt->lleft =efflev(1L,v->h,a); + r=jt->lright; jt->lright=efflev(2L,v->h,w); + z=lev2(a,w,self); + jt->lleft =l; + jt->lright=r; + R z; +} + + +static F1(jtscfn){ + RZ(w); + if(jt->scn==AN(jt->sca)){RZ(jt->sca=ext(1,jt->sca)); jt->scv=AV(jt->sca);} + jt->scv[jt->scn++]=(I)w; + R zero; +} + +static A jtlevs1(J jt,A w,A self){A fs; + RZ(w&&self); + if(jt->lmon>=level(w)){fs=VAV(self)->f; R scfn(CALL1(VAV(fs)->f1,w,fs));}else R every(w,self,jtlevs1); +} + +static A jtlevs2(J jt,A a,A w,A self){A fs; + RZ(a&&w&&self); + switch((jt->lleft>=level(a)?2:0)+(jt->lright>=level(w))){ + case 0: R every2(a, w, self,jtlevs2); + case 1: R every2(a, box(w),self,jtlevs2); + case 2: R every2(box(a),w, self,jtlevs2); + default: fs=VAV(self)->f; R scfn(CALL2(VAV(fs)->f2,a,w,fs)); +}} + +static DF1(jtscapco1){A x,z=0;I m;V*v=VAV(self); + RZ(w); + m=jt->lmon; jt->lmon=efflev(0L,v->h,w); + GA(x,INT,100,1,0); jt->scv=AV(x); jt->sca=x; jt->scn=0; + ra(jt->sca); + x=levs1(w,self); + jt->lmon=m; + if(x)z=ope(vec(BOX,jt->scn,jt->scv)); + fa(jt->sca); + R z; +} + +static DF2(jtscapco2){A x,z=0;I l,r;V*v=VAV(self); + RZ(a&&w); + l=jt->lleft; jt->lleft =efflev(1L,v->h,a); + r=jt->lright; jt->lright=efflev(2L,v->h,w); + GA(x,INT,100,1,0); jt->scv=AV(x); jt->sca=x; jt->scn=0; + ra(jt->sca); + x=levs2(a,w,self); + jt->lleft =l; + jt->lright=r; + if(x)z=ope(vec(BOX,jt->scn,jt->scv)); + fa(jt->sca); + R z; +} + + +static A jtlsub(J jt,C id,A a,A w){A h,t;B b=id==CLCAPCO;I*hv,n,*v; + RZ(a&&w); + ASSERT(VERB&AT(a)&&NOUN&AT(w),EVDOMAIN); + n=AN(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(0<n&&n<4,EVLENGTH); + RZ(t=vib(w)); v=AV(t); + GA(h,INT,3,1,0); hv=AV(h); + hv[0]=v[2==n]; hv[1]=v[3==n]; hv[2]=v[n-1]; + R fdef(id,VERB, b?jtlcapco1:jtscapco1,b?jtlcapco2:jtscapco2, a,w,h, 0L, RMAX,RMAX,RMAX); +} + +F2(jtlcapco){R lsub(CLCAPCO,a,w);} +F2(jtscapco){R lsub(CSCAPCO,a,w);} +
new file mode 100644 --- /dev/null +++ b/cp.c @@ -0,0 +1,179 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Power Operator ^: and Associates */ + +#include "j.h" + + +static DF1(jtpowseqlim){PROLOG;A x,y,z,*zv;I i,n; + RZ(w); + RZ(z=exta(BOX,1L,1L,20L)); zv=AAV(z); *zv++=x=w; + i=1; n=AN(z); + while(1){ + if(n==i){RZ(z=ext(0,z)); zv=i+AAV(z); n=AN(z);} + RZ(*zv++=x=df1(y=x,self)); + if(equ(x,y)){AN(z)=*AS(z)=i; break;} + ++i; + } + EPILOG(ope(z)); +} /* f^:(<_) w */ + +static F2(jttclosure){A z;B b;I an,*av,c,d,i,wn,wr,wt,*wv,*zu,*zv,*zz; + RZ(a&&w); + wt=AT(w); wn=AN(w); wr=AR(w); + if(B01&wt)RZ(w=cvt(INT,w)); wv=AV(w); + av=AV(a); an=AN(a); + RZ(z=exta(INT,1+wr,wn,20L)); + zv=AV(z); zz=zv+AN(z); + if(1==wn){ + *zv++=c=*wv; d=1+c; + while(c!=d){ + if(zv==zz){i=zv-AV(z); RZ(z=ext(0,z)); zv=AV(z)+i; zz=AV(z)+AN(z);} + d=c; if(0>c)c+=an; ASSERT(0<=c&&c<an,EVINDEX); *zv++=c=av[c]; + }}else{ + ICPY(zv,wv,wn); zu=zv; zv+=wn; + while(1){ + if(zv==zz){i=zv-AV(z); RZ(z=ext(0,z)); zv=AV(z)+i; zz=AV(z)+AN(z); zu=zv-wn;} + b=1; DO(wn, d=c=*zu++; if(0>c)c+=an; ASSERT(0<=c&&c<an,EVINDEX); *zv++=c=av[c]; if(c!=d)b=0;); + if(b)break; + }} + i=zv-AV(z); *AS(z)=d=i/wn-1; AN(z)=d*wn; ICPY(1+AS(z),AS(w),wr); + R z; +} /* {&a^:(<_) w */ + +static DF1(jtindexseqlim1){A fs; + RZ(w); + fs=VAV(self)->f; + R AT(w)&B01+INT?tclosure(VAV(fs)->g,w):powseqlim(w,fs); +} /* {&x^:(<_) w */ + +static DF2(jtindexseqlim2){ + RZ(a&&w); + R 1==AR(a)&&AT(a)&INT&&AT(w)&B01+INT?tclosure(a,w):powseqlim(w,amp(ds(CFROM),a)); +} /* a {~^:(<_) w */ + +static DF1(jtpowseq){A fs,gs,x;I n=IMAX;V*sv; + RZ(w); + sv=VAV(self); fs=sv->f; gs=sv->g; + ASSERT(!AR(gs),EVRANK); + ASSERT(BOX&AT(gs),EVDOMAIN); + x=*AAV(gs); if(!AR(x))RE(n=i0(vib(x))); + if(0>n){RZ(fs=inv(fs)); n=-n;} + if(n==IMAX||1==AR(x)&&!AN(x))R powseqlim(w,fs); + R df1(w,powop(fs,IX(n))); +} /* f^:(<n) w */ + +static DF1(jtfpown){A fs,z;AF f1;I n,old;V*sv; + RZ(w); + sv=VAV(self); + switch(n=*AV(sv->h)){ + case 0: R ca(w); + case 1: fs=sv->f; R CALL1(VAV(fs)->f1,w,fs); + default: + fs=sv->f; f1=VAV(fs)->f1; + z=w; + old=jt->tbase+jt->ttop; + DO(n, RZ(z=CALL1(f1,z,fs)); gc(z,old);); + R z; +}} /* single positive finite exponent */ + +static DF1(jtply1){PROLOG;DECLFG;A b,hs,j,x,*xv,y,z;B*bv,q;I i,k,m,n,*nv,old,p=0; + hs=sv->h; m=AN(hs); + RZ(x=ravel(hs)); RZ(y=from(j=grade1(x),x)); nv=AV(y); + GA(x,BOX,m,1,0); xv=AAV(x); + while(p<m&&0>nv[p])p++; + if(p<m){ + RZ(z=ca(w)); + n=nv[m-1]; k=p; + while(k<m&&!nv[k]){xv[k]=z; ++k;} + RZ(b=eq(ainf,from(j,ravel(gs)))); bv=BAV(b); q=k<m?bv[k]:0; + old=jt->tbase+jt->ttop; + for(i=1;i<=n;++i){ + RZ(z=CALL1(f1,y=z,fs)); + if(q&&equ(y,z)){DO(m-k, xv[k]=z; ++k;); break;} + while(k<m&&i==nv[k]){xv[k]=z; ++k; q=k<m?bv[k]:0;} + if(!(i%10))gc3(x,z,0L,old); + }} + if(0<p){ + RZ(fs=inv(fs)); f1=VAV(fs)->f1; + RZ(z=ca(w)); + n=nv[0]; k=p-1; + RZ(b=eq(scf(-inf),from(j,ravel(gs)))); bv=BAV(b); q=bv[k]; + old=jt->tbase+jt->ttop; + for(i=-1;i>=n;--i){ + RZ(z=CALL1(f1,y=z,fs)); + if(q&&equ(y,z)){DO(1+k, xv[k]=z; --k;); break;} + while(0<=k&&i==nv[k]){xv[k]=z; --k; q=0<=k?bv[k]:0;} + if(!(i%10))gc3(x,z,0L,old); + }} + z=ope(reshape(shape(hs),from(grade1(j),x))); EPILOG(z); +} + +#define DIST(i,x) if(i==e){v=CAV(x); \ + while(k<m&&i==(e=nv[jv[k]])){MC(zv+c*jv[k],v,c); ++k;}} + +static DF1(jtply1s){DECLFG;A hs,j,y,y1,z;C*v,*zv;I c,e,i,*jv,k,m,n,*nv,r,*s,t,zn; + RZ(w); + hs=sv->h; m=AN(hs); nv=AV(hs); + RZ(j=grade1(ravel(hs))); jv=AV(j); e=nv[*jv]; + if(!e&&!nv[jv[m-1]])R reshape(over(shape(hs),shape(w)),w); + RZ(y=y1=CALL1(f1,w,fs)); t=AT(y); r=AR(y); + if(0>e||t==BOX)R ply1(w,self); + if(!e){ + if(HOMO(t,AT(w)))RZ(w=pcvt(t,w)); + if(!(t==AT(w)&&AN(y)==AN(w)&&(r==AR(w)||1>=r&&1>=AR(w))))R ply1(w,self); + } + k=AR(hs); RE(zn=mult(m,AN(y))); + GA(z,AT(y),zn,k+AR(y),0); zv=CAV(z); + s=AS(z); ICPY(s,AS(hs),k); ICPY(k+s,AS(y),r); + n=nv[jv[m-1]]; c=AN(y)*bp(t); s=AS(y); + k=0; DIST(0,w); DIST(1,y); + for(i=2;i<=n;++i){ + RZ(y=CALL1(f1,y,fs)); + if(t!=AT(y)||r!=AR(y)||ICMP(AS(y),s,r))R ply1(w,self); + DIST(i,y); + } + R z; +} /* f^:n w, non-negative finite n, well-behaved f */ + +static DF1(jtinv1){DECLFG;A z; RZ(w); FDEPINC(1); z=df1(w,inv(fs)); FDEPDEC(1); R z;} +static DF2(jtinv2){DECLFG;A z; RZ(a&&w); FDEPINC(1); z=df1(w,inv(amp(a,fs))); FDEPDEC(1); R z;} + +static CS2(jtply2, df1(w,powop(amp(a,fs),gs))) + +static DF1(jtpowg1){A h=VAV(self)->h; R df1( w,*AAV(h));} +static DF2(jtpowg2){A h=VAV(self)->h; R df2(a,w,*AAV(h));} + +static CS1(jtpowv1, df1( w,powop(fs, CALL1(g1, w,gs)))) +static CS2(jtpowv2, df2(a,w,powop(fs, CALL2(g2,a,w,gs)))) +static CS2(jtpowv2a, df1( w,powop(VAV(fs)->f,CALL2(g2,a,w,gs)))) + +F2(jtpowop){A hs;B b,r;I m,n;V*v; + RZ(a&&w); + switch(CONJCASE(a,w)){ + default: ASSERTSYS(0,"powop"); + case NV: ASSERT(0,EVDOMAIN); + case NN: ASSERT(-1==i0(w),EVDOMAIN); R vger2(CPOWOP,a,w); + case VV: + v=VAV(a); b=(v->id==CAT||v->id==CATCO)&&ID(v->g)==CRIGHT; + R CDERIV(CPOWOP,jtpowv1,b?jtpowv2a:jtpowv2,RMAX,RMAX,RMAX); + case VN: + if(BOX&AT(w)){A x,y;AF f1,f2; + if(ARELATIVE(w))RZ(w=car(w)); + if(!AR(w)&&(x=*AAV(w),!AR(x)&&NUMERIC&AT(x)||1==AR(x)&&!AN(x))){ + f1=jtpowseq; f2=jtply2; v=VAV(a); + if((!AN(x)||FL&AT(x)&&inf==*DAV(x))&& + CAMP==v->id&&(CFROM==ID(v->f)&&(y=v->g,INT&AT(y)&&1==AR(y))))f1=jtindexseqlim1; + if(CTILDE==v->id&&CFROM==ID(v->f))f2=jtindexseqlim2; + R CDERIV(CPOWOP,f1,f2,RMAX,RMAX,RMAX); + } + R gconj(a,w,CPOWOP); + } + RZ(hs=vib(w)); + b=0; m=AN(hs); n=m?*AV(hs):0; r=0<AR(hs); + if(!r&&-1==n)R CDERIV(CPOWOP,jtinv1,jtinv2,RMAX,RMAX,RMAX); + if(m&&AT(w)&FL+CMPX)RE(b=!all0(eps(w,over(ainf,scf(infm))))); + R fdef(CPOWOP,VERB, b||!m?jtply1:!r&&0<=n?jtfpown:jtply1s,jtply2, a,w,hs, + 0L,RMAX,RMAX,RMAX); +}}
new file mode 100644 --- /dev/null +++ b/cpdtsp.c @@ -0,0 +1,184 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Dyad +/ .* on Sparse Arguments */ + +#include "j.h" + + +F1(jtbtreetest){ASSERT(0,EVDOMAIN);} +F1(jtbtreedft){ASSERT(0,EVDOMAIN);} + + +/* +vm=: 4 : 0 NB. vector +/ .* sparse matrix + if. dense x do. yy=. 5$.y [ 'i j'=. |: 4$.y + else. yy=. b#5$.y [ 'i j'=. |: b#4$.y [ b=. ({."1 ]4$.y) e. ,4$.x end. + 1 $. (}.$y);0;0;(,.~.j);j +//. (i{x) * yy +) + +mv=: 4 : 0 NB. sparse matrix +/ .* vector + if. dense y do. xx=. 5$.x [ 'i j'=. |: 4$.x + else. xx=. b#5$.x [ 'i j'=. |: b#4$.x [ b=. ({:"1 ]4$.x) e. ,4$.y end. + 1 $. (#x);0;0;(,.~.i);i +//. xx*j{y +) +*/ + +static F2(jtpdtspvv){A x;D*av,s,t,*wv,z;I i,*u,*u0,*uu,*v,*v0,*vv;P*ap,*wp; + RZ(a&&w); + ap=PAV(a); x=SPA(ap,i); u=u0=AV(x); uu=u+AN(x); x=SPA(ap,x); av=DAV(x); + wp=PAV(w); x=SPA(wp,i); v=v0=AV(x); vv=v+AN(x); x=SPA(wp,x); wv=DAV(x); + z=0.0; + NAN0; + while(1){ + i=*u; while(i>*v&&v<vv)++v; if(v==vv)break; + if(i==*v){s=av[u-u0]; t=wv[v-v0]; z+=s&&t?s*t:0; ++u; ++v; continue;} + i=*v; while(i>*u&&u<uu)++u; if(u==uu)break; + if(i==*u){s=av[u-u0]; t=wv[v-v0]; z+=s&&t?s*t:0; ++u; ++v; continue;} + } + NAN1; + R scf(z); +} + +static F2(jtpdtspmv){A ax,b,g,x,wx,y,yi,yj,z;B*bv;I m,n,s[2],*u,*v,*yv;P*ap,*wp,*zp; + RZ(a&&w); + ap=PAV(a); y=SPA(ap,i); yv=AV(y); s[0]=n=*AS(y); s[1]=1; + GA(yj,INT,n,2,s); + if(DENSE&AT(w)){ + GA(yi,INT,n,2,s); u=AV(yi); AR(yj)=1; v=AV(yj); + DO(n, *u++=*yv++; *v++=*yv++;); + ax=SPA(ap,x); RZ(wx=from(yj,w)); + }else{ + v=AV(yj); + DO(n, yv++; *v++=*yv++;); + wp=PAV(w); RZ(b=eps(yj,SPA(wp,i))); bv=BAV(b); + AN(yj)=*AS(yj)=*s=m=bsum(n,bv); v=AV(yj); yv=AV(y); + GA(yi,INT,m,2,s); u=AV(yi); + DO(n, if(*bv++){*u++=*yv++; *v++=*yv++;}else yv+=2;); + RZ(ax=repeat(b,SPA(ap,x))); RZ(wx=from(indexof(SPA(wp,i),yj),SPA(wp,x))); + } + RZ(x=df2(yi,tymes(ax,wx),sldot(slash(ds(CPLUS))))); + RZ(y=nub(yi)); + RZ(g=grade1(y)); + GA(z,STYPE(AT(x)),1,1,AS(a)); zp=PAV(z); + SPB(zp,a,iv0); + SPB(zp,e,scf(0.0)); + SPB(zp,i,from(g,y)); + SPB(zp,x,from(g,x)); + R z; +} /* (sparse matrix) +/ .* vector; non-complex */ + +static F2(jtpdtspvm){A ax,b,g,x,wx,y,yi,yj,z;B*bv;D*av,c,d,*wv,*xv;I m,n,s[2],*u,*v,*yv;P*ap,*wp,*zp; + RZ(a&&w); + wp=PAV(w); y=SPA(wp,i); yv=AV(y); s[0]=n=*AS(y); s[1]=1; + if(DENSE&AT(a)){ + GA(yj,INT,n,2,s); v=AV(yj); + av=DAV(a); x=SPA(wp,x); wv=DAV(x); + GA(x,FL,n,1,0); xv=DAV(x); + DO(n, c=av[*yv++]; *v++=*yv++; d=*wv++; *xv++=c&&d?c*d:0;); + }else{ + GA(yi,INT,n,2,s); u=AV(yi); + DO(n, *u++=*yv++; yv++;); + ap=PAV(a); RZ(b=eps(yi,SPA(ap,i))); bv=BAV(b); + AN(yi)=*AS(yi)=*s=m=bsum(n,bv); u=AV(yi); yv=AV(y); + GA(yj,INT,m,2,s); v=AV(yj); + DO(n, if(*bv++){*u++=*yv++; *v++=*yv++;}else yv+=2;); + RZ(ax=from(indexof(SPA(ap,i),yi),SPA(ap,x))); RZ(wx=repeat(b,SPA(wp,x))); + RZ(x=tymes(ax,wx)); + } + RZ(x=df2(yj,x,sldot(slash(ds(CPLUS))))); + RZ(y=nub(yj)); + RZ(g=grade1(y)); + GA(z,STYPE(AT(x)),1,1,1+AS(w)); zp=PAV(z); + SPB(zp,a,iv0); + SPB(zp,e,scf(0.0)); + SPB(zp,i,from(g,y)); + SPB(zp,x,from(g,x)); + R z; +} /* vector +/ .* (sparse matrix); non-complex */ + +/* p - ptr to sparse array value part */ +/* n - # elements in index array */ +/* iv - ptr to index array (row,column) */ +/* m - length of nv */ +/* nv - row boundaries in iv */ +/* xv - ptr to data values */ +static B jtmmprep(J jt,P*p,I*n,I**iv,I*m,I**nv,D**xv){A x;I j,k,q,*u,*v; + x=SPA(p,x); if(!(FL&AT(x)))RZ(x=cvt(FL,x)); *xv=DAV(x); + x=SPA(p,i); *iv=u=AV(x); *n=AN(x); + if(m&&nv){ + q=*AS(x); k=q?2+u[(q-1)<<1]-*u:1; + GA(x,INT,k,1,0); *nv=v=AV(x); + k=-1; DO(q, j=*u++; u++; if(j>k){*v++=i; k=j;}); + *v++=q; AN(x)=*AS(x)=k=v-*nv; *m=k-1; + } + R 1; +} + +/* ii - row index in result */ +/* zjn - # temp result values to be harvested */ +/* zj - temp result column indices */ +/* zyv - ptr to temp result values */ +/* n - # result values so far */ +/* zi - ptr to result index array */ +/* zx - ptr to result value array */ +static B jtmmharvest(J jt,I ii,I zjn,A zj,D*zyv,I*n,A*zi,A*zx){A x;D*zxv,*zxv0;I j,m,p,*v,*ziv; + m=MIN(*AS(*zi),*AS(*zx)); + while(m<*n+zjn){RZ(*zi=ext(0,*zi)); RZ(*zx=ext(0,*zx)); m=MIN(*AS(*zi),*AS(*zx));} + m=AN(zj); AN(zj)=*AS(zj)=zjn; RZ(x=grade2(zj,zj)); AN(zj)=*AS(zj)=m; + p=-1; v=AV(x); ziv=AV(*zi)+(*n<<1); zxv=zxv0=DAV(*zx)+*n; + DO(zjn, if(p<(j=*v++)){p=j; *ziv++=ii; *ziv++=j; *zxv++=zyv[j]; zyv[j]=0;}); + *n+=zxv-zxv0; + R 1; +} /* collect accumulated values for row ii */ + +static F2(jtpdtspmm){A z,zi,zj,zx,zy;D*axv,c,d,*dv,*wxv,*zyv; + I*aiv,*aivm,i,ii,j,k,k0,m,n=0,old,p,q,*v,wm,*wiv,*wnv,*zjv,*zjv0;P*zp; + RZ(a&&w); + RZ(mmprep(PAV(a),&m,&aiv,0L ,0L ,&axv)); aivm=m+aiv; + RZ(mmprep(PAV(w),&m,&wiv,&wm,&wnv,&wxv)); + GA(zy,FL,*(1+AS(w)),1,0); zyv=DAV(zy); memset(zyv,C0,AN(zy)*sizeof(D)); + old=jt->tbase+jt->ttop; + RZ(zj=exta(INT,1L,1L,1000L)); zjv0=AV(zj); + RZ(zi=exta(INT,2L,2L,1000L)); + RZ(zx=exta(FL, 1L,1L,1000L)); + NAN0; + if(wm&&aiv<aivm){ + i=*aiv++; zjv=zjv0; k=-1; + while(aiv<aivm){ /* run through aiv and axv exactly once */ + j=*aiv++; + if(c=*axv++){ + k0=k; p=k+1; q=wm; ii=-1; + while(p<=q){ii=wiv[wnv[k=(p+q)>>1]<<1]; if(j==ii)break; if(j<ii)q=k-1; else p=k+1;} + if(j==ii){ + p=wnv[1+k]-wnv[k]; dv=wxv+wnv[k]; v=1+wiv+(wnv[k]<<1); + q=zjv-zjv0; while(AN(zj)<p+q){RZ(zj=ext(0,zj)); zjv0=AV(zj); zjv=q+zjv0;} + DO(p, if(d=*dv++){if(!zyv[*v])*zjv++=*v; zyv[*v++]+=c*d; v++;}); + }else k=k0; + } + if(aiv>=aivm||i<(p=*aiv++)){ /* done with row i in a, emit row i in z */ + RZ(mmharvest(i,zjv-zjv0,zj,zyv,&n,&zi,&zx)); + gc3(zj,zi,zx,old); + zjv=zjv0; k=-1; i=p; + }}} + NAN1; + *AS(zx)=AN(zx)=*AS(zi)=n; AN(zi)=n<<1; + GA(z,SFL,1,2,AS(a)); *(1+AS(z))=*(1+AS(w)); + zp=PAV(z); SPB(zp,a,IX(2)); SPB(zp,e,scf(0.0)); SPB(zp,i,zi); SPB(zp,x,zx); + R z; +} + + +F2(jtpdtsp){A x;B ab=0,wb=0;P*p; + RZ(a&&w); + ASSERT(!AR(a)||!AR(w)||*(AS(a)+AR(a)-1)==*AS(w),EVLENGTH); + if(AT(a)&FL+SFL&&AT(w)&FL+SFL){ + if(SPARSE&AT(a)){p=PAV(a); x=SPA(p,a); ab=AR(a)==AN(x)&&equ(zero,SPA(p,e));} + if(SPARSE&AT(w)){p=PAV(w); x=SPA(p,a); wb=AR(w)==AN(x)&&equ(zero,SPA(p,e));} + } + if(ab&&1==AR(a)&&wb&&1==AR(w))R pdtspvv(a,w); + if(ab&&2==AR(a)&& 1==AR(w))R pdtspmv(a,w); + if( 1==AR(a)&&wb&&2==AR(w))R pdtspvm(a,w); + if(ab&&2==AR(a)&&wb&&2==AR(w))R pdtspmm(a,w); + R df2(a,w,atop(slash(ds(CPLUS)),qq(ds(CSTAR),v2(1L,AR(w))))); +}
new file mode 100644 --- /dev/null +++ b/cr.c @@ -0,0 +1,171 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Rank Associates */ + +#include "j.h" + +#define DR(r) (0>r?RMAX:r) + + +I mr(A w){R VAV(w)->mr;} +I lr(A w){R VAV(w)->lr;} +I rr(A w){R VAV(w)->rr;} + +I efr(I ar,I r){R 0>r?MAX(0,r+ar):MIN(r,ar);} + +#define NEWYA {GA(ya,at,acn,acr,as+af); uu=CAV(ya);} +#define NEWYW {GA(yw,wt,wcn,wcr,ws+wf); vv=CAV(yw);} +#define MOVEYA {MC(uu,u+=ak,ak); if(ab)RZ(ya=relocate((I)a-(I)ya,ya));} +#define MOVEYW {MC(vv,v+=wk,wk); if(wb)RZ(yw=relocate((I)w-(I)yw,yw));} + +A jtrank1ex(J jt,A w,A fs,I mr,AF f1){PROLOG;A y,y0,yw,z;B wb;C*v,*vv; + I k,mn,n=1,p,*s,wcn,wcr,wf,wk,wr,*ws,wt,yn,yr,*ys,yt; + RZ(w); + wt=AT(w); + if(wt&SPARSE)R sprank1(w,fs,mr,f1); + wr=AR(w); ws=AS(w); wcr=efr(wr,mr); wf=wr-wcr; wb=ARELATIVE(w); + if(!wf)R CALL1(f1,w,fs); + RE(wcn=prod(wcr,wf+ws)); wk=wcn*bp(wt); v=CAV(w)-wk; NEWYW; + p=wf; s=ws; RE(mn=prod(wf,ws)); + if(AN(w))MOVEYW else RZ(yw=reshape(vec(INT,wcr,ws+wf),filler(w))); +#define VALENCE 1 +#define TEMPLATE 0 +#include "cr_t.h" +} + +A jtrank2ex(J jt,A a,A w,A fs,I lr,I rr,AF f2){PROLOG;A y,y0,ya,yw,z;B ab,b,wb; + C*u,*uu,*v,*vv;I acn,acr,af,ak,ar,*as,at,k,mn,n=1,p,q,*s,wcn,wcr,wf,wk,wr,*ws,wt,yn,yr,*ys,yt; + RZ(a&&w); + at=AT(a); wt=AT(w); + if(at&SPARSE||wt&SPARSE)R sprank2(a,w,fs,lr,rr,f2); + ar=AR(a); as=AS(a); acr=efr(ar,lr); af=ar-acr; ab=ARELATIVE(a); + wr=AR(w); ws=AS(w); wcr=efr(wr,rr); wf=wr-wcr; wb=ARELATIVE(w); + if(!af&&!wf)R CALL2(f2,a,w,fs); + RE(acn=prod(acr,as+af)); ak=acn*bp(at); u=CAV(a)-ak; NEWYA; + RE(wcn=prod(wcr,ws+wf)); wk=wcn*bp(wt); v=CAV(w)-wk; NEWYW; + b=af<=wf; p=b?wf:af; q=b?af:wf; s=b?ws:as; RE(mn=prod(p,s)); RE(n=prod(p-q,s+q)); + ASSERT(!ICMP(as,ws,q),EVLENGTH); + if(AN(a))MOVEYA else RZ(ya=reshape(vec(INT,acr,as+af),filler(a))); + if(AN(w))MOVEYW else RZ(yw=reshape(vec(INT,wcr,ws+wf),filler(w))); +#define VALENCE 2 +#define TEMPLATE 0 +#include "cr_t.h" +} + + +/* Integrated Rank Support */ +/* f knows how to compute f"r */ +/* jt->rank points to a 2-element vector of */ +/* (left, right (monadic)) ranks */ +/* 0=jt->rank means f is not being called from rank */ +/* jt->rank is guaranteed positive */ +/* jt->rank is guaranteed <: argument ranks */ +/* frame agreement is verified before invoking f */ +/* frames either match, or one is empty */ +/* (i.e. prefix agreement invokes general case) */ + +A jtirs1(J jt,A w,A fs,I m,AF f1){A z;I*old=jt->rank,rv[2],wr; + RZ(w); + wr=AR(w); rv[1]=m=efr(wr,m); + if(m>=wr)R CALL1(f1,w,fs); + rv[0]=0; + jt->rank=rv; z=CALL1(f1,w,fs); jt->rank=old; + R z; +} + +A jtirs2(J jt,A a,A w,A fs,I l,I r,AF f2){A z;I af,ar,*old=jt->rank,rv[2],wf,wr; + RZ(a&&w); + ar=AR(a); rv[0]=l=efr(ar,l); af=ar-l; + wr=AR(w); rv[1]=r=efr(wr,r); wf=wr-r; + if(!(af||wf))R CALL2(f2,a,w,fs); + ASSERT(!ICMP(AS(a),AS(w),MIN(af,wf)),EVLENGTH); + /* if(af&&wf&&af!=wf)R rank2ex(a,w,fs,l,r,f2); */ + jt->rank=rv; z=CALL2(f2,a,w,fs); jt->rank=old; + R z; +} + + +static DF1(cons1a){R VAV(self)->f;} + +static DF2(cons2a){R VAV(self)->f;} + +static DF1(cons1){V*sv=VAV(self); + RZ(w); + R rank1ex(w,self,efr(AR(w),*AV(sv->h)),cons1a); +} + +static DF2(cons2){V*sv=VAV(self);I*v=AV(sv->h); + RZ(a&&w); + R rank2ex(a,w,self,efr(AR(a),v[1]),efr(AR(w),v[2]),cons2a); +} + +static DF1(rank1i){DECLF;A h=sv->h;I*v=AV(h); R irs1(w,fs,*v,f1);} + +static DF2(rank2i){DECLF;A h=sv->h;I*v=AV(h); R irs2(a,w,fs,v[1],v[2],f2);} + +static DF1(rank1){DECLF;A h=sv->h;I m,*v=AV(h),wr; + RZ(w); + wr=AR(w); m=efr(wr,v[0]); + R m<wr?rank1ex(w,fs,m,f1):CALL1(f1,w,fs); +} + +static DF2(rank2){DECLF;A h=sv->h;I ar,l,r,*v=AV(h),wr; + RZ(a&&w); + ar=AR(a); l=efr(ar,v[1]); + wr=AR(w); r=efr(wr,v[2]); + R l<ar||r<wr?rank2ex(a,w,fs,l,r,f2):CALL2(f2,a,w,fs); +} + +static void qqset(A a,AF*f1,AF*f2,I*flag){A f,g;C c,d,e,p,q;I m=0;V*v; + static C at1[]={CFLOOR,CLE,CCEIL,CGE,CPLUS,CPLUSDOT,CPLUSCO, + CSTAR,CSTARDOT,CSTARCO,CMINUS,CNOT,CHALVE,CDIV,CSQRT,CEXP,CLOG, + CSTILE,CBANG,CLEFT,CRIGHT,CQUERY,CHGEOM,CJDOT,CCIRCLE, + CPCO,CQCO,CRDOT,CTDOT,CXCO,0}; /* f monad <-> f"r monad */ + static C ir1[]={CCOMMA,CLAMIN,CLEFT,CRIGHT,CCANT,CROT,CTAKE,CDROP,CGRADE,CDGRADE, + CBOX,CNE,CTAIL,CCTAIL,CSLASH,CBSLASH,CBSDOT,CCOMDOT,CPCO,CATDOT,0}; + static C ir2[]={CCOMMA,CLAMIN,CLEFT,CRIGHT,CCANT,CROT,CTAKE,CDROP,CGRADE,CDGRADE, + CDOLLAR,CPOUND,CIOTA,CICO,CEPS,CLBRACE,CMATCH, + CEQ,CLT,CMIN,CLE,CGT,CMAX,CGE,CPLUS,CPLUSDOT,CPLUSCO,CSTAR,CSTARDOT,CSTARCO, + CMINUS,CDIV,CEXP,CNE,CSTILE,CBANG,CCIRCLE,0}; + if(NOUN&AT(a)){*f1=cons1; *f2=cons2; *flag=0; R;} + v=VAV(a); c=v->id; + if(strchr(ir1,c))m+=VIRS1; + if(strchr(ir2,c))m+=VIRS2; + if(!(m&VIRS1)&&v->flag&VIRS1&&c!=CQQ)m+=VIRS1; + if(!(m&VIRS2)&&v->flag&VIRS2&&c!=CQQ)m+=VIRS2; + if(!m){ + p=0; if(f=v->f)p=VERB&AT(f)&&strchr(ir2,d=ID(f)); + q=0; if(g=v->g)q=VERB&AT(g)&&strchr(ir2,e=ID(g)); + switch(c){ + case CFIT: if(p&&d!=CEXP)m+=VIRS2; if(d==CNE)m+=VIRS1; break; + case CTILDE: if(p)m+=VIRS1+VIRS2; break; + case CAMP: if(p&&NOUN&AT(g)||q&&NOUN&AT(f))m+=VIRS1; break; + case CFORK: if(v->f1==(AF)jtmean)m+=VIRS1; + }} + *f1=strchr(at1,c) ? v->f1 : m&VIRS1 ? rank1i : rank1; + *f2= m&VIRS2 ? rank2i : rank2; + *flag=m; +} + +F2(jtqq){A h,t;AF f1,f2;D*d;I flag,*hv,n,r[3],*v; + RZ(a&&w); + GA(h,INT,3,1,0); hv=AV(h); + if(VERB&AT(w)){ + GA(t,FL,3,1,0); d=DAV(t); + n=r[0]=hv[0]=mr(w); d[0]=n<=-RMAX?-inf:RMAX<=n?inf:n; + n=r[1]=hv[1]=lr(w); d[1]=n<=-RMAX?-inf:RMAX<=n?inf:n; + n=r[2]=hv[2]=rr(w); d[2]=n<=-RMAX?-inf:RMAX<=n?inf:n; + w=t; + }else{ + n=AN(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(0<n&&n<4,EVLENGTH); + RZ(t=vib(w)); v=AV(t); + hv[0]=v[2==n]; r[0]=DR(hv[0]); + hv[1]=v[3==n]; r[1]=DR(hv[1]); + hv[2]=v[n-1]; r[2]=DR(hv[2]); + } + qqset(a,&f1,&f2,&flag); + R fdef(CQQ,VERB, f1,f2, a,w,h, flag, r[0],r[1],r[2]); +}
new file mode 100644 --- /dev/null +++ b/cr_t.h @@ -0,0 +1,70 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* cr.c templates */ + +/* template 0 used by the rank operator general cases (monad and dyad) */ +/* requires: */ +/* VALENCE 1 or 2 */ + +#if TEMPLATE==0 +#if VALENCE==1 +#define RCALL CALL1(f1,yw,fs) +#define RDIRECT (wt&DIRECT) +#define RAC (1==AC(yw)) +#define RFLAG (!(AFLAG(w)&AFNJA+AFSMM+AFREL)) +#define RARG {if(1<AC(yw))NEWYW; MOVEYW;} +#define RARGX {if(1<AC(yw)){RZ(yw=ca(yw)); vv=CAV(yw);}} +#else +#define RCALL CALL2(f2,ya,yw,fs) +#define RDIRECT (at&DIRECT&&wt&DIRECT) +#define RAC (1==AC(ya)&&1==AC(yw)) +#define RFLAG (!(AFLAG(a)&AFNJA+AFSMM+AFREL)&&!(AFLAG(w)&AFNJA+AFSMM+AFREL)) +#define RARG {++jj; if(!b||jj==n){if(1<AC(ya))NEWYA; MOVEYA;} \ + if( b||jj==n){if(1<AC(yw))NEWYW; MOVEYW;} if(jj==n)jj=0;} +#define RARGX {if(1<AC(ya)){RZ(ya=ca(ya)); uu=CAV(ya);} \ + if(1<AC(yw)){RZ(yw=ca(yw)); vv=CAV(yw);}} +#endif +{B cc=1;C*zv;I j=0,jj=0,old; + if(mn){y0=y=RCALL; RZ(y);} + else{I d; + d=jt->db; jt->db=0; y=RCALL; jt->db=d; + if(jt->jerr){y=zero; RESETERR;} + } + yt=AT(y); yr=AR(y); ys=AS(y); yn=AN(y); k=yn*bp(yt); + if(!mn||yt&DIRECT&&RFLAG){I zn; + RARGX; RE(zn=mult(mn,yn)); + GA(z,yt,zn,p+yr,0L); ICPY(AS(z),s,p); ICPY(p+AS(z),ys,yr); + if(mn){zv=CAV(z); MC(zv,AV(y),k);} + old=jt->tbase+jt->ttop; + for(j=1;j<mn;++j){ + RARG; + RZ(y=RCALL); + if(yt!=AT(y)||yr!=AR(y)||yr&&ICMP(AS(y),ys,yr))break; + MC(zv+=k,AV(y),k); + if(cc&&RAC)tpop(old); else cc=0; + }} + if(j<mn){A q,*x,yz; + jj=j%n; + GA(yz,BOX,mn,p,s); x=AAV(yz); + if(j){ + zv=CAV(z)-k; + DO(j, GA(q,AT(y0),AN(y0),AR(y0),AS(y0)); MC(AV(q),zv+=k,k); *x++=q;); + } + *x++=y; + DO(mn-j-1, RARG; RZ(y=RCALL); *x++=y;); + z=ope(yz); + } + EPILOG(z); +} +#undef VALENCE +#undef RAC +#undef RARG +#undef RARGX +#undef RCALL +#undef RDIRECT +#undef RFLAG +#endif /* TEMPLATE 0 */ + + +#undef TEMPLATE
new file mode 100644 --- /dev/null +++ b/crs.c @@ -0,0 +1,256 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Rank on Sparse Arrays */ + +#include "j.h" + + +static A jtsprarg(J jt,I f,A x){A q;B*b,c;I r;P*xp; + r=AR(x); xp=PAV(x); + if(SPARSE&AT(x)){c=1; RZ(b=bfi(r,SPA(xp,a),1)); DO(f, if(!b[i]){c=0; break;});} + else{c=0; GA(q,B01,r,1,0); b=BAV(q); memset(b,C0,r);} + memset(b,C1,f); + R c||!r?x:reaxis(ifb(r,b),x); +} /* ensure frame axes are sparse */ + +static A jtsprinit(J jt,I f,I r,I*s,I t,P*p){A a,a1,z;I n,*u,*v;P*zp; + GA(z,t,1,r,f+s); zp=PAV(z); + a=SPA(p,a); n=AN(a)-f; u=f+AV(a); GA(a1,INT,n,1,0); v=AV(a1); DO(n, v[i]=u[i]-f;); + SPB(zp,a,a1); + SPB(zp,e,ca(SPA(p,e))); + SPB(zp,i,iota(v2(0L,n))); + SPB(zp,x,repeat(zero,SPA(p,x))); + R z; +} /* initialize an argument cell */ + +static B*jtspredge(J jt,A y,I f,I*zm){A q;B*b;I c,m,n,*v; + v=AS(y); n=v[0]; c=v[1]; m=n?1:0; + GA(q,B01,n,1,0); b=BAV(q); + if(n){ + if(f){v=AV(y); DO(n-1, if(b[i]=1&&ICMP(v,v+c,f))++m; v+=c;);}else memset(b,C0,n); + b[n-1]=1; + } + *zm=m; + R b; +} /* cell boundaries per index matrix y */ + +static A jtsprz(J jt,A z0,A y,A e,I f,I*s){A a,a0,q,y0,z;B d;I c,et,h,m,n,r,t,*u,*v,zt;P*ep,*zp,*zq; + RZ(z0&&y&&e); + ASSERT(AN(e),EVDOMAIN); + if(SPARSE&AT(e)){ep=PAV(e); ASSERT(all1(eq(SPA(ep,e),SPA(ep,x))),EVSPARSE); q=SPA(ep,e);} + else{RZ(q=reshape(mtv,e)); ASSERT(all1(eq(q,e)),EVSPARSE);} + if(!*AS(z0)){ + t=AT(q); zt=STYPE(t); + GA(z,zt,1L,f+AR(e),s); ICPY(f+AS(z),AS(e),AR(e)); + zp=PAV(z); SPB(zp,e,q); SPB(zp,a,mtv); + GA(q,INT,0L,2L,&zeroZ); SPB(zp,i,q); + GA(q,t,0L,1+AR(z),0L); *AS(q)=0; ICPY(1+AS(q),AS(z),AR(z)); SPB(zp,x,q); + R z; + } + e=q; + zt=t=AT(z0); d=t&SPARSE?0:1; if(d)zt=STYPE(t); else t=DTYPE(zt); + et=AT(e); m=MAX(et,t); zt=STYPE(m); + r=AR(z0); + GA(z,zt,1,f+r-1,s); ICPY(AS(z)+f,AS(z0)+1,r-1); + zp=PAV(z); SPB(zp,e,m==et?e:cvt(m,e)); + if(d){SPB(zp,a,IX(f)); SPB(zp,i,y); SPB(zp,x,m==t?z0:cvt(m,z0)); R z;} + zq=PAV(z0); y0=SPA(zq,i); v=AS(y0); n=v[0]; c=v[1]; v=AV(y0); + ASSERT(equ(e,SPA(zq,e)),EVNONCE); + h=*AS(y); GA(q,INT,h,1,0); u=AV(q); memset(u,C0,h*SZI); + if(n){h=-1; DO(n-1, if(*v!=*(v+c)){u[*v]=i-h; h=i;} v+=c;); u[*v]=n-1-h;} + SPB(zp,i,stitch(repeat(q,y),dropr(1L,y0))); + a0=SPA(zq,a); v=AV(a0); + GA(a,INT,f+c-1,1,0); u=AV(a); DO(f, u[i]=i;); DO(c-1, u[f+i]=v[1+i]+f-1;); + SPB(zp,a,a); + SPB(zp,x,m==t?ra(SPA(zq,x)):cvt(m,SPA(zq,x))); + R z; +} /* result processing */ + +A jtsprank1(J jt,A w,A fs,I mr,AF f1){PROLOG;A q,wx,wy,wy1,ww,z,ze,zi,*zv;B*wb; + I c,i,*iv,j,k,m,n,*v,wcr,wf,wr,*ws,wt,*wv;P*wp,*wq; + RZ(w); + wr=AR(w); ws=AS(w); wcr=efr(wr,mr); wf=wr-wcr; + if(!wf)R CALL1(f1,w,fs); + DO(wf, ASSERT(ws[i],EVNONCE);); + RZ(w=sprarg(wf,w)); wp=PAV(w); wx=SPA(wp,x); wy=SPA(wp,i); + if(mr){ + wt=AT(w); + v=AS(wy); n=v[0]; c=v[1]; wv=AV(wy); RZ(wy1=dropr(wf,wy)); + RZ(wb=spredge(wy,wf,&m)); + RZ(ww=sprinit(wf,wcr,ws,wt,wp)); wq=PAV(ww); + RZ(ze=CALL1(f1,ww,fs)); + GA(z,BOX,m,1,0); zv=AAV(z); + GA(zi,INT,m*wf,2,0); iv=AV(zi); v=AS(zi); v[0]=m; v[1]=wf; + for(i=j=0;i<m;++i){ + k=1+(B*)memchr(wb+j,C1,n-j)-(wb+j); + ICPY(iv,wv+j*c,wf); iv+=wf; + RZ(q=apv(k,j,1L)); SPB(wq,i,from(q,wy1)); SPB(wq,x,from(q,wx)); + RZ(zv[i]=CALL1(f1,ww,fs)); + j+=k; + } + RZ(z=ope(z)); + }else{RZ(zi=ca(wy)); RZ(z=rank1ex(wx,fs,mr,f1)); RZ(ze=CALL1(f1,SPA(wp,e),fs));} + EPILOG(sprz(z,zi,ze,wf,ws)); +} /* f"r w on sparse arrays */ + +static I jtspradv(J jt,I n,B*b,I f,I r,I j,P*p,A*z){A s,x;I k;P*q; + k=n?1+(B*)memchr(b+j,C1,n-j)-(b+j):0; + x=SPA(p,x); + if(r){ + q=PAV(*z); + RZ(s=apv(k,j,1L)); + SPB(q,i,from(s,dropr(f,SPA(p,i)))); + SPB(q,x,from(s,x)); + }else RZ(*z=AN(x)?from(sc(j),x):ca(SPA(p,e))); + R k; +} /* advance to the next cell */ + +static A jtsprank2_0w(J jt,A a,A w,A fs,AF f2,I wf,I wcr){PROLOG;A we,ww,y,z,zi,*zv;B*wb; + I f,*iv,j,*v,wc,wj,wk,wm,wn,*ws,wt,*wv;P*wp; + f=wf; ws=AS(w); + RZ(w=sprarg(wf,w)); wt=AT(w); wp=PAV(w); + y=SPA(wp,i); v=AS(y); wn=v[0]; wc=v[1]; wv=AV(y); RZ(wb=spredge(y,wf,&wm)); + RZ(ww=sprinit(wf,wcr,ws,wt,wp)); RZ(we=wcr?ca(ww):SPA(wp,e)); + GA(z,BOX,wm,1,0); zv=AAV(z); + GA(zi,INT,f*wm,2,0); iv=AV(zi); v=AS(zi); v[0]=wm; v[1]=f; + RE(wj=wk=spradv(wn,wb,wf,wcr,0L,wp,&ww)); j=0; + while(1){ + ICPY(iv,wv,f); iv+=f; RZ(zv[j++]=CALL2(f2,a,ww,fs)); + if(wj==wn)break; + wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk; + } + EPILOG(sprz(ope(z),zi,CALL2(f2,a,we,fs),f,ws)); +} + +static A jtsprank2_a0(J jt,A a,A w,A fs,AF f2,I af,I acr){PROLOG;A aa,ae,y,z,zi,*zv;B*ab; + I f,*iv,j,*v,ac,aj,ak,am,an,*as,at,*av;P*ap; + f=af; as=AS(a); + RZ(a=sprarg(af,a)); at=AT(a); ap=PAV(a); + y=SPA(ap,i); v=AS(y); an=v[0]; ac=v[1]; av=AV(y); RZ(ab=spredge(y,af,&am)); + RZ(aa=sprinit(af,acr,as,at,ap)); RZ(ae=acr?ca(aa):SPA(ap,e)); + GA(z,BOX,am,1,0); zv=AAV(z); + GA(zi,INT,f*am,2,0); iv=AV(zi); v=AS(zi); v[0]=am; v[1]=f; + RE(aj=ak=spradv(an,ab,af,acr,0L,ap,&aa)); j=0; + while(1){ + ICPY(iv,av,f); iv+=f; RZ(zv[j++]=CALL2(f2,aa,w,fs)); + if(aj==an)break; + av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak; + } + EPILOG(sprz(ope(z),zi,CALL2(f2,ae,w,fs),f,as)); +} + +A jtsprank2(J jt,A a,A w,A fs,I lr,I rr,AF f2){PROLOG;A aa,ae,we,ww,y,zi,z,*zv;B*ab,b,*wb;I ac,acr,af,aj,ak,am,an, + ar,*as,at,*av,d,f,g,*ii,*iv,j,k,m,s,*u,*v,wc,wcr,wf,wj,wk,wm,wn,wr,*ws,wt,*wv;P*ap,*wp; + RZ(a&&w); + ar=AR(a); as=AS(a); acr=efr(ar,lr); af=ar-acr; + wr=AR(w); ws=AS(w); wcr=efr(wr,rr); wf=wr-wcr; + if(!af&&!wf)R CALL2(f2,a,w,fs); + DO(af, ASSERT(as[i],EVNONCE);); + DO(wf, ASSERT(ws[i],EVNONCE);); + if(!af)R sprank2_0w(a,w,fs,f2,wf,wcr); + if(!wf)R sprank2_a0(a,w,fs,f2,af,acr); + f=MIN(af,wf); g=MAX(af,wf); m=1; + if(f<g){d=g-f; RZ(y=odom(2L,d,f+(af<wf?ws:as))); ii=AV(y); m=*AS(y);} + ASSERT(!ICMP(as,ws,f),EVLENGTH); + RZ(a=sprarg(af,a)); at=AT(a); ap=PAV(a); + RZ(w=sprarg(wf,w)); wt=AT(w); wp=PAV(w); + y=SPA(ap,i); v=AS(y); an=v[0]; ac=v[1]; av=an?AV(y):0; RZ(ab=spredge(y,af,&am)); + y=SPA(wp,i); v=AS(y); wn=v[0]; wc=v[1]; wv=wn?AV(y):0; RZ(wb=spredge(y,wf,&wm)); + RZ(aa=sprinit(af,acr,as,at,ap)); RZ(ae=acr?ca(aa):SPA(ap,e)); + RZ(ww=sprinit(wf,wcr,ws,wt,wp)); RZ(we=wcr?ca(ww):SPA(wp,e)); + b=af<wf; j=am*(af<wf?m:1)+wm*(af>wf?m:1); + GA(z, BOX,j, 1,0); zv=AAV(z); + GA(zi,INT,j*g,2,0); v=AS(zi); v[0]=j; v[1]=g; iv=AV(zi); + RE(aj=ak=spradv(an,ab,af,acr,0L,ap,&aa)); + RE(wj=wk=spradv(wn,wb,wf,wcr,0L,wp,&ww)); j=s=k=0; u=ii; y=0; v=0; + if(af==wf)while(av||wv){ + if(av&&wv)DO(f, if(s=av[i]-wv[i])break;) else s=av?-1:1; + if (0==s){RZ(zv[j++]=CALL2(f2,aa,ww,fs)); ICPY(iv,av,f); iv+=g;} + else if(0> s){RZ(zv[j++]=CALL2(f2,aa,we,fs)); ICPY(iv,av,f); iv+=g;} + else if(0< s){RZ(zv[j++]=CALL2(f2,ae,ww,fs)); ICPY(iv,wv,f); iv+=g;} + if(0>=s){if(aj==an)av=0; else{av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;}} + if(0<=s){if(wj==wn)wv=0; else{wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;}} + }else while(av||wv){ + if(av&&wv&&f)DO(f, if(s=av[i]-wv[i])break;) else s=!f?0:av?-1:1; + if(b&&0<s||!b&&0>s){RZ(zv[j++]=CALL2(f2,b?ae:aa,b?ww:we,fs)); ICPY(iv,b?wv:av,g); iv+=g; k=m;} + else if(s){ + DO(m, RZ(zv[j++]=y=y?ca(y):CALL2(f2,b?aa:ae,b?we:ww,fs)); ICPY(iv,b?av:wv,f); ICPY(iv+f,u,d); iv+=g; u+=d;); + u=ii; y=0; v=0; + }else{ + while(ICMP(f+(b?wv:av),u,d)){ + RZ(zv[j++]=y=y?ca(y):CALL2(f2,b?aa:ae,b?we:ww,fs)); + ICPY(iv,wv,f); ICPY(iv+f,u,d); iv+=g; u+=d; ++k; + } + RZ(zv[j++]=CALL2(f2,aa,ww,fs)); ICPY(iv,b?wv:av,g); iv+=g; u+=d; ++k; + } + if ( b&&0<=s)if(wj==wn)wv=v=0; else{v=wv; wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;} + else if(!b&&0>=s)if(aj==an)av=v=0; else{v=av; av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;} + if(b&&(!s&&!wv||v&&ICMP(v,wv,f))||!b&&(!s&&!av||v&&ICMP(v,av,f))){ + DO(m-k, RZ(zv[j++]=y=y?ca(y):CALL2(f2,b?aa:ae,b?we:ww,fs)); ICPY(iv,b?av:wv,f); ICPY(iv+f,u,d); iv+=g; u+=d;); + u=ii; y=0; k=0; + } + if ( b&&0>=s&&(!v||ICMP(v,wv,f)))if(aj==an)av=0; else{av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;} + else if(!b&&0<=s&&(!v||ICMP(v,av,f)))if(wj==wn)wv=0; else{wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;} + } + AN(z)=*AS(z)=*AS(zi)=j; AN(zi)=j*g; + EPILOG(sprz(ope(z),zi,CALL2(f2,ae,we,fs),g,g==af?as:ws)); +} /* a f"r w on sparse arrays */ + +A jtva2s(J jt,A a,A w,C id,VF ado,I cv,I t,I zt,I lr,I rr){PROLOG;A aa,ae,we,ww,y,zi,z,*zv;B*ab,b,*wb;I ac,acr,af,aj,ak,am,an, + ar,*as,at,*av,d,f,g,*ii,*iv,j,k,m,s,*u,*v,wc,wcr,wf,wj,wk,wm,wn,wr,*ws,wt,*wv;P*ap,*wp; + RZ(a&&w); + ar=AR(a); as=AS(a); acr=efr(ar,lr); af=ar-acr; + wr=AR(w); ws=AS(w); wcr=efr(wr,rr); wf=wr-wcr; + if(!af&&!wf){ado(jt,a,w); R 0;} + DO(af, ASSERT(as[i],EVNONCE);); + DO(wf, ASSERT(ws[i],EVNONCE);); + if(!ar){ado(jt,a,w); R 0;} + if(!wr){ado(jt,a,w); R 0;} + f=MIN(af,wf); g=MAX(af,wf); m=1; + if(f<g){d=g-f; RZ(y=odom(2L,d,f+(af<wf?ws:as))); ii=AV(y); m=*AS(y);} + ASSERT(!ICMP(as,ws,f),EVLENGTH); + RZ(a=sprarg(af,a)); at=AT(a); ap=PAV(a); + RZ(w=sprarg(wf,w)); wt=AT(w); wp=PAV(w); + y=SPA(ap,i); v=AS(y); an=v[0]; ac=v[1]; av=an?AV(y):0; RZ(ab=spredge(y,af,&am)); + y=SPA(wp,i); v=AS(y); wn=v[0]; wc=v[1]; wv=wn?AV(y):0; RZ(wb=spredge(y,wf,&wm)); + RZ(aa=sprinit(af,acr,as,at,ap)); RZ(ae=acr?ca(aa):SPA(ap,e)); + RZ(ww=sprinit(wf,wcr,ws,wt,wp)); RZ(we=wcr?ca(ww):SPA(wp,e)); + b=af<wf; j=am*(af<wf?m:1)+wm*(af>wf?m:1); + GA(z, BOX,j, 1,0); zv=AAV(z); + GA(zi,INT,j*g,2,0); v=AS(zi); v[0]=j; v[1]=g; iv=AV(zi); + RE(aj=ak=spradv(an,ab,af,acr,0L,ap,&aa)); + RE(wj=wk=spradv(wn,wb,wf,wcr,0L,wp,&ww)); j=s=k=0; u=ii; y=0; v=0; + if(af==wf)while(av||wv){ + if(av&&wv)DO(f, if(s=av[i]-wv[i])break;) else s=av?-1:1; + if (0==s){ado(jt,aa,ww); RZ(zv[j++]); ICPY(iv,av,f); iv+=g;} + else if(0> s){ado(jt,aa,we); RZ(zv[j++]); ICPY(iv,av,f); iv+=g;} + else if(0< s){ado(jt,ae,ww); RZ(zv[j++]); ICPY(iv,wv,f); iv+=g;} + if(0>=s){if(aj==an)av=0; else{av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;}} + if(0<=s){if(wj==wn)wv=0; else{wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;}} + }else while(av||wv){ + if(av&&wv&&f)DO(f, if(s=av[i]-wv[i])break;) else s=!f?0:av?-1:1; + if(b&&0<s||!b&&0>s){ado(jt,b?ae:aa,b?ww:we); RZ(zv[j++]); ICPY(iv,b?wv:av,g); iv+=g; k=m;} + else if(s){ + DO(m, ado(jt,b?aa:ae,b?we:ww); RZ(zv[j++]=y=y?ca(y):0); ICPY(iv,b?av:wv,f); ICPY(iv+f,u,d); iv+=g; u+=d;); + u=ii; y=0; v=0; + }else{ + while(ICMP(f+(b?wv:av),u,d)){ + ado(jt,b?aa:ae,b?we:ww); RZ(zv[j++]=y=y?ca(y):0); + ICPY(iv,wv,f); ICPY(iv+f,u,d); iv+=g; u+=d; ++k; + } + ado(jt,aa,ww); RZ(zv[j++]); ICPY(iv,b?wv:av,g); iv+=g; u+=d; ++k; + } + if ( b&&0<=s)if(wj==wn)wv=v=0; else{v=wv; wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;} + else if(!b&&0>=s)if(aj==an)av=v=0; else{v=av; av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;} + if(b&&(!s&&!wv||v&&ICMP(v,wv,f))||!b&&(!s&&!av||v&&ICMP(v,av,f))){ + DO(m-k, ado(jt,b?aa:ae,b?we:ww); RZ(zv[j++]=y=y?ca(y):0); ICPY(iv,b?av:wv,f); ICPY(iv+f,u,d); iv+=g; u+=d;); + u=ii; y=0; k=0; + } + if ( b&&0>=s&&(!v||ICMP(v,wv,f)))if(aj==an)av=0; else{av+=ak*ac; RE(ak=spradv(an,ab,af,acr,aj,ap,&aa)); aj+=ak;} + else if(!b&&0<=s&&(!v||ICMP(v,av,f)))if(wj==wn)wv=0; else{wv+=wk*wc; RE(wk=spradv(wn,wb,wf,wcr,wj,wp,&ww)); wj+=wk;} + } + AN(z)=*AS(z)=*AS(zi)=j; AN(zi)=j*g; + R 0; + /* EPILOG(sprz(ope(z),zi,CALL2(f2,ae,we,fs),g,g==af?as:ws)); */ +} /* a f"r w on sparse arrays for atomic f */
new file mode 100644 --- /dev/null +++ b/ct.c @@ -0,0 +1,267 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Taylor's Series */ + +#include "j.h" + + +static F1(jttayatop); + +static F1(jtcoeff){V*v; + RZ(w); + v=VAV(w); + R VTAYFINITE&v->flag ? curtail(VAV(v->f)->g) : mtv; +} /* coefficents c in {&c@(n&<.), or empty */ + +static F1(jttpoly){A z; + RZ(w); + RZ(z=atop(amp(ds(CLBRACE),over(AT(w)&CMPX?w:xco1(w),zero)),amp(tally(w),ds(CMIN)))); + VAV(z)->flag=VTAYFINITE; + R z; +} + +static F1(jtfacit){A c;V*u,*v; + RZ(c=coeff(w)); + if(AN(c))R tpoly(tymes(c,fact(AT(c)&XNUM+RAT?xco1(IX(IC(c))):IX(IC(c))))); + v=VAV(w); + if(CFORK==v->id)switch(ID(v->g)){ + case CDIV: + if(CBANG==ID(v->h))R v->f; + break; + case CSTAR: + if(CFORK==ID(v->h)&&(u=VAV(v->h),CDIV==ID(u->g)&&CBANG==ID(u->h)))R folk(v->f,v->g,u->f); + RZ(c=atop(ds(CDIV),ds(CBANG))); + if(equ(c,v->f))R v->h; + if(equ(c,v->h))R v->f; + } + R folk(ds(CBANG),ds(CSTAR),w); +} + +static A jttayamp(J jt,A w,B nf,A x,A h){A y;B ng=!nf;I j,n;V*v=VAV(h); + ASSERT(AR(x)<=(nf?v->lr:v->rr),EVRANK); + switch(v->id){ + case CPLUS: R tpoly(over(x,one)); + case CMINUS: R tpoly(nf?over(x,num[-1]):over(negate(x),one)); + case CSTAR: R tpoly(over(zero,x)); + case CDIV: ASSERT(ng,EVDOMAIN); R tpoly(over(zero,recip(x))); + case CJDOT: R tpoly(nf?over(x,a0j1):over(jdot1(x),one)); + case CPOLY: ASSERT(nf,EVDOMAIN); R tpoly(BOX&AT(x)?poly1(x):x); + case CHGEOM: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); + y=IX(j); + R tpoly(divide(hgcoeff(y,h),fact(y))); + case CBANG: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); + R tpoly(divide(poly1(box(iota(x))),fact(x))); + case CEXP: if(nf)R eva(x,"(^.x)&^ % !"); + RE(n=i0(x)); + R 0<=n?tpoly(over(reshape(x,zero),one)):atop(ds(CDIV),amp(h,sc(-n))); + case CFIT: ASSERT(nf&&CPOLY==ID(v->f),EVDOMAIN); + y=over(x,IX(IC(x))); + R tpoly(mdiv(df2(x,y,h),atab(CEXP,y,IX(IC(x))))); + case CCIRCLE: + switch(i0(x)){ + case 1: R eval("{&0 1 0 _1@(4&|) % !"); + case -3: R eval("{&0 1 0 _1@(4&|) % ]"); + case 2: R eval("{&1 0 _1 0@(4&|) % !"); + case 5: R eval("2&| % !"); + case -7: R eval("2&| % ]"); + case 6: R eval("2&|@>: % !"); + case -1: R eval("(2&| % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0"); + case -5: R eval("({&0 1 0 _1@(4&|) % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0"); + }} + ASSERT(0,EVDOMAIN); +} + +static A jttcoamp(J jt,A w,B nf,A x,A h){I j;V*v=VAV(h); + ASSERT(AR(x)<=v->mr,EVRANK); + switch(v->id){ + case CEXP: + if(nf)R amp(logar1(x),ds(CEXP)); break; + case CHGEOM: + ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); + R tpoly(hgcoeff(IX(j),h)); + } + R facit(tayamp(w,nf,x,h)); +} + +static F2(jttayinv){A y;I m,*v; + RZ(a&&w); + RZ(y=vip(w)); v=AV(y); + m=0; DO(AN(w), m=MAX(m,v[i]);); ++m; + RZ(y=IX(m)); if(AT(w)&XNUM+RAT)RZ(y=xco1(y)); + R rinv(ev2(apv(m,0L,-1L),df1(y,tdot(a)),"|.!.0\"0 1")); +} + +static DF1(jttayrecip){A f=VAV(self)->f; R from(w,head(tayinv(VAV(f)->g,w)));} + /* %@f t. w */ + +static DF1(jttaydiv){A c,f,ft,h,ht,y;I j,m,*u;V*v; + y=VAV(self)->f; v=VAV(y); + RZ(y=vip(w)); u=AV(y); + m=0; DO(AN(w), m=MAX(m,u[i]);); ++m; + RZ(y=IX(m)); if(AT(w)&XNUM+RAT)RZ(y=xco1(y)); + RZ(f=df1(y,ft=tdot(v->f))); + RZ(h=df1(y,ht=tdot(v->h))); + RZ(c=indexof(ne(zero,h),one)); + if(j=*AV(c)){ + ASSERT(all1(eq(zero,take(c,f))),EVDOMAIN); + RZ(y=apv(j,m,1L)); if(AT(w)&XNUM+RAT)RZ(y=xco1(y)); + RZ(f=over(drop(c,f),df1(y,ft))); + RZ(h=over(drop(c,h),df1(y,ht))); + } + R from(w,pdt(f,rinv(ev2(apv(m,0L,-1L),h,"|.!.0\"0 1")))); +} /* (f % h) t. w */ + +static DF1(jttaysqrt){A f;I m,*v; + f=VAV(self)->f; + RZ(w=vip(w)); v=AV(w); + m=0; DO(AN(w), m=MAX(m,v[i]);); ++m; + ASSERT(0,EVNONCE); + /* R from(w,df2(sc(m),df1(IX(m),tdot(VAV(f)->g)),taysqrt0)); */ +} /* %:@f t. w */ + +static F1(jttayfolk){A c,d,f,ft,g,h,ht,pp;B b;V*v=VAV(w); + h=v->h; ht=tdot(h); RZ(d=coeff(ht)); + f=v->f; if(NOUN&AT(f))R tayfolk(folk(qq(f,ainf),v->g,h)); ft=tdot(f); RZ(c=coeff(ft)); + b=AN(c)&&AN(d); g=v->g; pp=eval("[: +//. */"); + switch(ID(g)){ + case CPLUS: + case CMINUS: R b ? tpoly(df1(lamin2(c,d),slash(g))) : folk(ft,g,ht); + case CSTAR: R b ? tpoly(df2(c,d,pp)) : eva(folk(ft,pp,ht),"{ x@(i.@>:@(>./)@,)"); + case CDIV: R ADERIV(CTDOT,jttaydiv,0L,RMAX,RMAX,RMAX); + case CTILDE: g=VAV(g)->f; ASSERT(VERB&AT(f),EVDOMAIN); R tayfolk(folk(h,g,f)); + case CEXP: ASSERT(1==AN(d),EVDOMAIN); R tdot(atop(amp(g,head(d)),f)); + default: ASSERT(0,EVDOMAIN); +}} + +static F1(jttaysum){I n;V*v=VAV(w); + switch(ID(w)){ + case CLEFT: case CRIGHT: + R tpoly(eval("0 _1r2 1r2")); + case CAMP: case CAMPCO: + if(CEXP==ID(v->f)){ + RE(n=i0(v->g)); + ASSERT(0<=n,EVDOMAIN); + + }} + ASSERT(0,EVDOMAIN); +} + +static F1(jttayatop){A c,d,e,f,ft,g,gt,h;I k,m,n;V*v=VAV(w); + f=v->f; g=v->g; + switch(ID(f)){ + case CDIV: R ADERIV(CTDOT,jttayrecip,0L,RMAX,RMAX,RMAX); + case CSQRT: R ADERIV(CTDOT,jttaysqrt, 0L,RMAX,RMAX,RMAX); + case CAMP: + c=VAV(f)->f; d=VAV(f)->g; + if(CEXP==ID(c)&&INT&AT(d)&&!AR(d)){ + k=*AV(d); + if(0>k)R tayatop(atop(ds(CDIV),-1==k?g:atop(amp(c,sc(-k)),g))); + }} + if(CIOTA==ID(g)){B b;C c; + c=ID(f); ft=VAV(f)->f; gt=VAV(f)->g; + if(c==CSLASH&&CPLUS==ID(ft))R taysum(ds(CLEFT)); + b=CSLASH==ID(ft)&&(h=VAV(ft)->f,CPLUS==ID(h)); + if(b&&(c==CAMPCO||c==CATCO||(c==CAMP||c==CAT)&&1<VAV(gt)->mr))R taysum(gt); + ASSERT(0,EVDOMAIN); + } + ft=tdot(f); RZ(c=coeff(ft)); m=AN(c); + gt=tdot(g); RZ(d=coeff(gt)); n=AN(d); + if(n&&all1(eq(zero,curtail(d)))){ + e=tail(d); + if(!equ(one,e))ft=folk(amp(e,ds(CEXP)),ds(CSTAR),ft); + if(2<n)ft=evc(sc(n-1),ft,"0&=@(x&|) * y@<.@(%&x)"); + R !m?ft:tpoly(1==n?df1(e,f):df1(IX(1+n*(m-1)),ft)); + } + ASSERT(m,EVDOMAIN); + /* if(2==m&&equ(zero,head(c)))R folk(tail(c),ds(CSTAR),gt)); */ + h=eval("4 : '+/x*y([:+//.*/)^:(i.#x) 1'"); + R AN(d)?tpoly(df2(c,d,h)):eva(atco(amp(c,h),gt),"[ { x@:(i.@>:@(>./)@,)"); +} + +static AS1(jttdot1, df1(w,tdot(fix(fs)))) +static AS1(jttco1, df1(w,tco (fix(fs)))) +static CS1(jttcap1, df1(w,tcap(fix(fs),gs))) + +static DF1(jttcoh1){R hgcoeff(w,VAV(self)->f);} + +F1(jttdot){A f,g,h;B nf,ng;C id;V*v; + RZ(w); + if(NOUN&AT(w))R vger2(CTDOT,0L,w); + if(!nameless(w))R ADERIV(CTDOT,jttdot1,0L,RMAX,RMAX,RMAX); + v=VAV(w); id=v->id; + f=v->f; nf=f&&NOUN&AT(f); + g=v->g; ng=g&&NOUN&AT(g); + h=v->h; + if(id==CAMP&&nf!=ng)R tayamp(w,nf,nf?f:g,nf?g:f); + switch(id){ + case CEXP: R eval("%@!"); + case CLEFT: + case CRIGHT: R tpoly(v2( 0L, 1L)); + case CGE: R tpoly(v2( 1L, 1L)); + case CLE: R tpoly(v2(-1L, 1L)); + case CNOT: R tpoly(v2( 1L,-1L)); + case CMINUS: R tpoly(v2( 0L,-1L)); + case CPLUSCO: R tpoly(v2( 0L, 2L)); + case CSTARCO: R tpoly(eval("0 0 1")); + case CHALVE: R tpoly(eval("0 0.5")); + case CJDOT: R tpoly(eval("0 0j1")); + case CCIRCLE: R tpoly(eval("0 1p1")); + case CFORK: R tayfolk(w); + case CHOOK: R tayfolk(folk(ds(CRIGHT),f,g)); + case CHGEOM: R folk(ds(CBANG),swap(ds(CDIV)),tco(w)); + case CUNDER: R tdot(atop(inv(g),atop(f,g))); + case CQQ: if(nf){ASSERT(!AR(f),EVRANK); R tpoly(f);} else R tdot(f); + case CEVEN: if(CMINUS==ID(g))R eva(f,"0&=@(2&|) * x t."); break; + case CODD: if(CMINUS==ID(g))R eva(f," 2&| * x t."); break; + case CTDOT: if(nf)R*(1+AAV(h)); break; + case CDDOT: R tdot(ddot(f,g)); + case CAMP: case CAMPCO: case CAT: case CATCO: + R tayatop(w); + case CPOWOP: + if(!nf&&ng&&!AR(g)){A c,d,ft,h;I m,n; + RE(n=i0(g)); + switch(SGN(n)){ + case -1: RZ(h=inv(f)); ASSERT(CPOWOP!=ID(h),EVDOMAIN); R tdot(powop(h,sc(-n))); + case 0: R tpoly(v2(0L,1L)); + case 1: + ft=tdot(f); RZ(c=d=coeff(ft)); m=AN(c); + ASSERT(m,EVDOMAIN); + RZ(h=eval("4 : '+/x*y([:+//.*/)^:(i.#x) 1'")); + DO(n-1, RZ(d=df2(c,d,h));); + R tpoly(d); + }}} + ASSERT(id==CFCONS,EVDOMAIN); + R tpoly(h); +} + +F1(jttco){A f,g;B nf,ng;C id;V*v; + RZ(w); + ASSERT(VERB&AT(w),EVDOMAIN); + if(!nameless(w))R ADERIV(CTCO,jttco1,0L,RMAX,RMAX,RMAX); + v=VAV(w); id=v->id; + f=v->f; nf=f&&NOUN&AT(f); + g=v->g; ng=g&&NOUN&AT(g); + if(id==CAMP&&nf!=ng)R tcoamp(w,nf,nf?f:g,nf?g:f); + switch(id){ + case CEXP: R eval("$&1&$"); + case CHGEOM: R ADERIV(CTCO,jttcoh1,0L,RMAX,RMAX,RMAX); + case CQQ: if(!nf)R tco(f); + } + R facit(tdot(w)); +} + +F2(jttcap){A c,p,s,t;I n; + ASSERTVN(a,w); + ASSERT(!AR(w),EVRANK); + RZ(t=vib(w)); n=*AV(t); + ASSERT(0<=n,EVDOMAIN); + if(!nameless(a))R CDERIV(CTCAP,jttcap1,0L,RMAX,RMAX,RMAX); + RZ(p=tdot(a)); + if(n<IMAX)R amp(df1(iota(t),p),ds(CPOLY)); + RZ(c=coeff(p)); + if(AN(c))R amp(c,ds(CPOLY)); + RZ(s=cstr("3 : ('g=:p.&y@:((")); + RZ(s=over(s,over(lrep(a),cstr(") t.)@i.';'g +:^:(g ~: g@+:)^:_ ] 1') \" 0")))); + R eval(CAV(s)); +}
new file mode 100644 --- /dev/null +++ b/cu.c @@ -0,0 +1,98 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Under and Each */ + +#include "j.h" +#include "ve.h" + + +static A jteverysp(J jt,A w,A fs,AF f1){A*wv,x,z,*zv;P*wp,*zp; + RZ(w); + ASSERT(SBOX&AT(w),EVNONCE); + RZ(z=ca(w)); + wp=PAV(w); x=SPA(wp,x); wv=AAV(x); + zp=PAV(z); x=SPA(zp,x); zv=AAV(x); + DO(AN(x), RZ(*zv++=CALL1(f1,*wv++,fs));); + R z; +} + +#define EVERYI(exp) {RZ(*zv++=x=exp); ASSERT(!(SPARSE&AT(x)),EVNONCE);} + /* note: x can be non-noun */ + +A jtevery(J jt,A w,A fs,AF f1){A*wv,x,z,*zv;I wd; + RZ(w); + if(SPARSE&AT(w))R everysp(w,fs,f1); + if(!(BOX&AT(w)))RZ(w=box0(w)); + GA(z,BOX,AN(w),AR(w),AS(w)); + zv=AAV(z); wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(AN(w), EVERYI(CALL1(f1,WVR(i),fs));); + R z; +} + +A jtevery2(J jt,A a,A w,A fs,AF f2){A*av,*wv,x,z,*zv;B ab,b,wb;I ad,an,ar,*as,wd,wn,wr,*ws; + RZ(a&&w); + an=AN(a); ar=AR(a); as=AS(a); ab=BOX==AT(a); ad=(I)a*ARELATIVE(a); + wn=AN(w); wr=AR(w); ws=AS(w); wb=BOX==AT(w); wd=(I)w*ARELATIVE(w); + b=!ar||!wr||ar==wr; if(b&&ar&&wr)DO(ar, b&=as[i]==ws[i];); + if(!b)R df2(a,w,atop(ds(CBOX),amp(fs,ds(COPE)))); + GA(z,BOX,ar?an:wn,ar?ar:wr,ar?as:ws); zv=AAV(z); + if(ar&&!ab)RZ(a=box0(a)); av=AAV(a); + if(wr&&!wb)RZ(w=box0(w)); wv=AAV(w); + if(ar&&wr) DO(an, EVERYI(CALL2(f2,AVR(i), WVR(i), fs))) + else if(wr){if(ab)a=AAV0(a); DO(wn, EVERYI(CALL2(f2,a, WVR(i), fs)));} + else if(ar){if(wb)w=AAV0(w); DO(an, EVERYI(CALL2(f2,AVR(i), w, fs)));} + else EVERYI(CALL2(f2,ab?AAV0(a):a,wb?AAV0(w):w,fs)) ; + R z; +} + +static DF1(jteach1){DECLF; R every ( w,fs,f1);} +static DF2(jteach2){DECLF; R every2(a,w,fs,f2);} + +DF2(jteachl){RZ(a&&w&&self); R rank2ex(a,w,self,-1L, RMAX,VAV(self)->f2);} +DF2(jteachr){RZ(a&&w&&self); R rank2ex(a,w,self,RMAX,-1L, VAV(self)->f2);} + +static DF1(jtunder1){DECLFG; R df1( w,atop(inv(gs),amp(fs,gs)));} +static DF2(jtunder2){DECLFG; R df2(a,w,atop(inv(gs),amp(fs,gs)));} + +static DF1(jtundco1){DECLFG; R df1( w,atop(inv(gs),ampco(fs,gs)));} +static DF2(jtundco2){DECLFG; R df2(a,w,atop(inv(gs),ampco(fs,gs)));} + + +static DF1(jtunderai1){DECLF;A x,y,z;B b;I j,n,*u,*v;UC f[256],*wv,*zv; + RZ(w); + if(b=LIT&AT(w)&&256<AN(w)){ + x=df1(iota(v2(128L, 2L)),fs); b=x&&256==AN(x)&&NUMERIC&AT(x); + if(b){y=df1(iota(v2( 8L,32L)),fs); b=y&&256==AN(y)&&NUMERIC&AT(y);} + if(b){x=vi(x); y=vi(y); b=x&&y;} + if(b){u=AV(x); v=AV(y); DO(256, j=*u++; if(j==*v++&&-256<=j&&j<256)f[i]=(UC)(0<=j?j:j+256); else{b=0; break;});} + if(jt->jerr)RESETERR; + } + if(!b)R from(df1(indexof(alp,w),fs),alp); + n=AN(w); + GA(z,LIT,n,AR(w),AS(w)); zv=UAV(z); wv=UAV(w); + if(!bitwisecharamp(f,n,wv,zv))DO(n, *zv++=f[*wv++];); + R z; +} /* f&.(a.&i.) w */ + +F2(jtunder){A x;AF f1,f2;B b,b1;C c;I m,r;V*u,*v; + ASSERTVV(a,w); + c=0; f1=jtunder1; f2=jtunder2; r=mr(w); v=VAV(w); + switch(v->id){ + case COPE: f1=jteach1; f2=jteach2; break; + case CFORK: c=ID(v->h); /* fall thru */ + case CAMP: + u=VAV(a); + if(b1=CSLASH==u->id){x=u->f; u=VAV(x);} + b=CBDOT==u->id&&(x=u->f,!AR(x)&&INT&AT(x)&&(m=*AV(x),16<=m&&m<32)); + if(CIOTA==ID(v->g)&&(!c||c==CLEFT||c==CRIGHT)&&equ(alp,v->f)){ + f1=b&& b1?jtbitwiseinsertchar:jtunderai1; + f2=b&&!b1?jtbitwisechar:u->id==CMAX||u->id==CMIN?jtcharfn2:jtunder2; + }} + R CDERIV(CUNDER,f1,f2,r,r,r); +} + +F2(jtundco){ + ASSERTVV(a,w); + R CDERIV(CUNDCO,jtundco1,jtundco2,RMAX,RMAX,RMAX); +}
new file mode 100644 --- /dev/null +++ b/cv.c @@ -0,0 +1,84 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Variants (!.) */ + +#include "j.h" + + +static DF1(jtfitct1){DECLFG;A z;D old=jt->ct; jt->ct=*DAV(gs); z=CALL1(f1, w,fs); jt->ct=old; R z;} +static DF2(jtfitct2){DECLFG;A z;D old=jt->ct; jt->ct=*DAV(gs); z=CALL2(f2,a,w,fs); jt->ct=old; R z;} + +static F2(jtfitct){D d;V*sv; + RZ(a&&w); + ASSERT(!AR(w),EVRANK); + sv=VAV(a); + RZ(w=cvt(FL,w)); d=*DAV(w); ASSERT(0<=d&&d<5.82076609134675e-11,EVDOMAIN); + R CDERIV(CFIT,jtfitct1,jtfitct2,sv->mr,sv->lr,sv->rr); +} + +static DF1(jtfitfill1){DECLFG;A z; jt->fill=gs; z=CALL1(f1, w,fs); jt->fill=0; R z;} +static DF2(jtfitfill2){DECLFG;A z; jt->fill=gs; z=CALL2(f2,a,w,fs); jt->fill=0; R z;} + +static DF1(jtfitpp1){DECLFG;A z;C d[8],*s=3+jt->pp; + MC(d,s,8L); + sprintf(s,FMTI"g",*AV(gs)); + z=CALL1(f1,w,fs); MC(s,d,8L); + R z; +} + +static DF2(jtfitexp2){ + F2RANK(0,0,jtfitexp2,self); + ASSERT(0<=i0(w)&&!jt->jerr,EVDOMAIN); + R aslash(CSTAR,plus(a,df2(iota(w),VAV(self)->g,slash(ds(CSTAR))))); +} /* a ^!.s w */ + +static DF2(jtfitpoly2){ + F2RANK(1,0,jtfitpoly2,self); + R aslash(CPLUS,tymes(a,ascan(CSTAR,shift1(plus(w,df2(IX(IC(a)),VAV(self)->g,slash(ds(CSTAR)))))))); +} /* a p.!.s w */ + +static DF1(jtfitf1){V*sv=VAV(self); R df1( w,fit(fix(sv->f),sv->g));} +static DF2(jtfitf2){V*sv=VAV(self); R df2(a,w,fit(fix(sv->f),sv->g));} + +F2(jtfit){A f;C c;I k,l,m,r;V*sv; + ASSERTVN(a,w); + sv=VAV(a); m=sv->mr; l=sv->lr; r=sv->rr; + switch(sv->id){ + case CLE: case CLT: case CGE: case CGT: case CNE: case CEQ: + case CMATCH: case CEPS: case CIOTA: case CICO: case CNUB: case CSTAR: + case CFLOOR: case CCEIL: case CSTILE: case CPLUSDOT: case CSTARDOT: case CABASE: + case CNOT: case CXCO: case CSLDOT: case CSPARSE: case CEBAR: + R fitct(a,w); + case CEXP: + ASSERT(AT(w)&NUMERIC,EVDOMAIN); + R CDERIV(CFIT,0L,jtfitexp2, m,l,r); + case CPOLY: + ASSERT(AT(w)&NUMERIC,EVDOMAIN); + R CDERIV(CFIT,0L,jtfitpoly2,m,l,r); + case CPOWOP: + if(VERB&AT(sv->g)||!equ(num[-1],sv->g))R fitct(a,w); + f=sv->f; c=ID(f); + if(c==CPOUND){ASSERT(!AR(w),EVRANK); R CDERIV(CFIT,0,jtfitfill2,m,l,r);} + ASSERT(c==CAMP,EVDOMAIN); + f=VAV(f)->g; ASSERT(CPOUND==ID(f),EVDOMAIN); + case CPOUND: case CTAKE: case CTAIL: case CCOMMA: case CCOMDOT: case CLAMIN: case CRAZE: + ASSERT(!AR(w),EVRANK); /* fall thru */ + case CROT: case CDOLLAR: + ASSERT(1>=AR(w),EVRANK); + ASSERT(!AR(w)||!AN(w),EVLENGTH); + R CDERIV(CFIT,jtfitfill1,jtfitfill2,m,l,r); + case CTHORN: + RE(w=sc(k=i0(w))); + ASSERT(0<k,EVDOMAIN); + ASSERT(k<=NPP,EVLIMIT); + R CDERIV(CFIT,jtfitpp1,sv->f2,m,l,r); + case CCYCLE: + RE(k=i0(w)); ASSERT(2==k,EVDOMAIN); RZ(w=sc(k)); + R CDERIV(CFIT,jtpparity,0L,m,RMAX,RMAX); + case CTILDE: + ASSERT(NOUN&AT(sv->f),EVDOMAIN); + R CDERIV(CFIT,jtfitf1,jtfitf2,m,l,r); + default: + ASSERT(0,EVDOMAIN); +}}
new file mode 100644 --- /dev/null +++ b/cx.c @@ -0,0 +1,311 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conjunctions: Explicit Definition : and Associates */ + +/* Usage of the f,g,h fields of : defined verbs: */ +/* f character matrix of left argument to : */ +/* g character matrix of right argument to : */ +/* h 4-element vector of boxes */ +/* 0 vector of boxed tokens for f */ +/* 1 vector of triples of control information */ +/* 2 vector of boxed tokens for g */ +/* 3 vector of triples of control information */ + +#include "j.h" +#include "d.h" +#include "p.h" +#include "w.h" + +#define BASSERT(b,e) {if(!(b)){jsignal(e); i=-1; z=0; continue;}} +#define BGA(v,t,n,r,s) BZ(v=ga(t,(I)(n),(I)(r),(I*)(s))) +#define BZ(e) if(!(e)){i=-1; z=0; continue;} + +#define LINE(sv) {A x; \ + h=sv->h; hv=AAV(sv->h); hi=a&&w?HN:0; \ + line=AAV(hv[hi]); x=hv[1+hi]; n=AN(x); cw=(CW*)AV(x);} + +typedef struct{A t,x,line;C*iv,*xv;I j,k,n;} CDATA; +/* for_xyz. t do. control data */ +/* line 'for_xyz.' */ +/* t iteration array */ +/* n #t */ +/* k length of name xyz */ +/* x text xyz_index */ +/* xv ptr to text xyz_index */ +/* iv ptr to text xyz */ +/* j iteration index */ + +#define WCD (sizeof(CDATA)/sizeof(I)) + +typedef struct{I d,t,e;} TD; +#define WTD (sizeof(TD)/sizeof(I)) +#define NTD 17 /* maximum nesting for try/catch */ + + +static B jtforinit(J jt,CDATA*cv,A t){A x;C*s,*v;I k; + ASSERT(t,EVCTRL); + cv->t=ra(t); /* iteration array */ + cv->n=IC(t); /* # of items in t */ + cv->j=-1; /* iteration index */ + cv->x=0; + cv->k=k=AN(cv->line)-5; /* length of item name */ + if(0<k&&cv->n){ /* for_xyz. */ + s=4+CAV(cv->line); RZ(cv->x=x=ra(str(6+k,s))); + cv->xv=v=CAV(x); MC(k+v,"_index",6L); /* index name */ + cv->iv=s; /* item name */ + } + R 1; +} /* for. do. end. initializations */ + +static B jtunstackcv(J jt,CDATA*cv){ + if(cv->x){ex(link(cv->x,str(cv->k,cv->iv))); fa(cv->x);} + fa(cv->t); + memset(cv,C0,WCD*SZI); + R 1; +} + +static void jttryinit(J jt,TD*v,I i,CW*cw){I j=i,t=0; + v->d=v->t=0; + while(t!=CEND){ + j=(j+cw)->go; + switch(t=(j+cw)->type){ + case CCATCHD: v->d=j; break; + case CCATCHT: v->t=j; break; + case CEND: v->e=j; break; +}}} /* processing on hitting try. */ + +static DF2(jtxdefn){PROLOG;A cd,cl,cn,h,*hv,*line,loc=jt->local,t,td,u,v,z;B b,lk,named,ox=jt->xdefn;CDATA*cv; + CW*ci,*cw;DC d=0;I hi,i=0,j,m,n,od=jt->db,old,r=0,st,tdi=0;TD*tdv;V*sv;X y; + RE(0); + z=mtm; cd=t=u=v=0; sv=VAV(self); st=AT(self); + lk=jt->glock||VLOCK&sv->flag; named=VNAMED&sv->flag?1:0; cn=jt->curname; cl=jt->curlocn; + d=named&&jt->db&&DCCALL==jt->sitop->dctype?jt->sitop:0; /* stack entry for dbunquote for this fn */ + if(VXOP&sv->flag){u=sv->f; v=sv->h; sv=VAV(sv->g);} + if(st&ADV+CONJ){u=a; v=w;} + LINE(sv); ASSERT(n,EVDOMAIN); + RZ(jt->local=stcreate(2,1L,0L,0L)); + if(sv->flag&VTRY1+VTRY2){GA(td,INT,NTD*WTD,2,0); *AS(td)=NTD; *(1+AS(td))=WTD; tdv=(TD*)AV(td);} + /* do not use error exit after this point; use BASSERT, BGA, BZ */ + FDEPINC(1); jt->xdefn=1; + IS(xnam,a); if(u){IS(unam,u); if(NOUN&AT(u))IS(mnam,u);} + IS(ynam,w); if(v){IS(vnam,v); if(NOUN&AT(v))IS(nnam,v);} + if(jt->dotnames){ + IS(xdot,a); if(u){IS(udot,u); if(NOUN&AT(u))IS(mdot,u);} + IS(ydot,w); if(v){IS(vdot,v); if(NOUN&AT(v))IS(ndot,v);} + } + if(jt->db&&jt->sitop&&DCCALL==jt->sitop->dctype&&self==jt->sitop->dcf){ + jt->sitop->dcloc=jt->local; jt->sitop->dcc=hv[1+hi]; jt->sitop->dci=(I)&i; + } + old=jt->tbase+jt->ttop; + while(0<=i&&i<n){ + if(0<jt->pmctr&&C1==jt->pmrec&&named)pmrecord(cn,cl,i,a?VAL2:VAL1); + if(jt->redefined&&jt->sitop&&jt->redefined==jt->sitop->dcn&&DCCALL==jt->sitop->dctype&&self!=jt->sitop->dcf){ + self=jt->sitop->dcf; sv=VAV(self); LINE(sv); jt->sitop->dcc=hv[1+hi]; + jt->redefined=0; + if(i>=n)break; + } + ci=i+cw; + switch(ci->type){ + case CTRY: + BASSERT(tdi<NTD,EVLIMIT); + tryinit(tdv+tdi,i,cw); + if(jt->db)jt->db=(tdv+tdi)->d?jt->dbuser:DBTRY; + ++tdi; ++i; + break; + case CCATCH: case CCATCHD: case CCATCHT: + if(tdi){--tdi; i=1+(tdv+tdi)->e; jt->db=od;}else i=ci->go; break; + case CTHROW: + BASSERT(0,EWTHROW); + case CBBLOCK: + tpop(old); z=parsex(vec(BOX,ci->n,line+ci->i),lk,ci,d); + if(z||DB1==jt->db||DBERRCAP==jt->db||!jt->jerr)++i; + else if(EWTHROW==jt->jerr){if(tdi&&(j=(tdv+tdi-1)->t)){i=1+j; RESETERR;}else BASSERT(0,EWTHROW);} + else{i=ci->go; if(i<SMAX){RESETERR; if(tdi){--tdi; jt->db=od;}}} + break; + case CASSERT: + if(!jt->assert){++i; break;} + case CTBLOCK: + gc(z,old); t=parsex(vec(BOX,ci->n,line+ci->i),lk,ci,d); + if(t||DB1==jt->db||DBERRCAP==jt->db||!jt->jerr)++i; + else if(EWTHROW==jt->jerr){if(tdi&&(j=(tdv+tdi-1)->t)){i=1+j; RESETERR;}else BASSERT(0,EWTHROW);} + else{i=ci->go; if(i<SMAX){RESETERR; if(tdi){--tdi; jt->db=od;}}} + break; + case CFOR: + case CSELECT: + if(!r) + if(cd){m=AN(cd)/WCD; BZ(cd=ext(1,cd)); cv=(CDATA*)AV(cd)+m-1; r=AN(cd)/WCD-m;} + else {r=9; BGA(cd,INT,r*WCD,1,0); cv=(CDATA*)AV(cd)-1; ra(cd);} + ++cv; --r; + cv->t=cv->x=0; cv->line=line[ci->i]; ++i; + break; + case CDOF: + if(!cv->t){BZ(forinit(cv,t)); t=0;} + ++cv->j; + if(cv->j<cv->n){ + if(cv->x){A x; + symbis(nfs(6+cv->k,cv->xv),x=sc(cv->j), jt->local); + symbis(nfs( cv->k,cv->iv),from(x,cv->t),jt->local); + } + ++i; continue; + } + case CBREAKF: + case CENDSEL: + rat(z); unstackcv(cv); --cv; ++r; + i=ci->go; + break; + case CRETURN: + if(cd){rat(z); DO(AN(cd)/WCD-r, unstackcv(cv); --cv; ++r;);} + i=ci->go; + break; + case CCASE: + case CFCASE: + if(!cv->t){BASSERT(t&&NOUN&AT(t),EVCTRL); BZ(cv->t=ra(boxopen(t))); t=0;} + i=ci->go; + break; + case CDOSEL: + BASSERT(!t||NOUN&AT(t),EVCTRL); + i=t&&all0(eps(cv->t,boxopen(t)))?ci->go:1+i; + t=0; + break; + case CDO: + ++i; b=1; + if(t){ + if(SPARSE&AT(t))BZ(t=denseit(t)); + BASSERT(NOUN&AT(t),EVCTRL); + switch(AN(t)?AT(t):0){ + case RAT: + case XNUM: y=*XAV(t); b=*AV(y)||1<AN(y); break; + case CMPX: b=0!=*DAV(t)||0!=*(1+DAV(t)); break; + case FL: b=0!=*DAV(t); break; + case INT: b=0!=*AV(t); break; + case B01: b=*BAV(t); + }} + t=0; + if(b)break; + default: + JBREAK0; + i=ci->go; + }} + FDEPDEC(1); + z=jt->jerr?0:z?ra(z):mtm; + fa(cd); + symfreeh(jt->local,0L); jt->local=loc; jt->asgn=0; jt->xdefn=ox; + tpop(_ttop); + if(z)ASSERT(st&ADV+CONJ||AT(z)&NOUN,EVSYNTAX); + tpush(z); + R z; +} + + +static DF1(xv1){R df1( w,VAV(self)->f);} +static DF2(xv2){R df2(a,w,VAV(self)->g);} + +static DF1(xn1 ){R xdefn(0L,w, self);} +static DF1(xadv){R xdefn(w, 0L,self);} + + +static F1(jtxopcall){R jt->db&&DCCALL==jt->sitop->dctype?jt->sitop->dca:mark;} + +static DF1(xop1){A ff,x; + RZ(ff=fdef(CCOLON,VERB, xn1,jtxdefn, w,self,0L, VXOP|VAV(self)->flag, RMAX,RMAX,RMAX)); + RZ(x=xopcall(one)); + R x==mark?ff:namerefop(x,ff); +} + +static DF2(xop2){A ff,x; + RZ(ff=fdef(CCOLON,VERB, xn1,jtxdefn, a,self,w, VXOP|VAV(self)->flag, RMAX,RMAX,RMAX)); + RZ(x=xopcall(one)); + R x==mark?ff:namerefop(x,ff); +} + + +static B jtxop(J jt,A h){A p,x,y;B b,*pv;I*xv; + GA(x,INT,jt->dotnames?12:6,1,0); xv=AV(x); + xv[0]=(I)mnam; xv[1]=(I)nnam; xv[2]=(I)unam; xv[3]=(I)vnam; xv[ 4]=(I)xnam; xv[ 5]=(I)ynam; + if(jt->dotnames){xv[6]=(I)mdot; xv[7]=(I)ndot; xv[8]=(I)udot; xv[9]=(I)vdot; xv[10]=(I)xdot; xv[11]=(I)ydot;} + RZ(y=raze(from(v2(0L,HN),h))); AT(y)=INT; + RZ(p=eps(x,y)); pv=BAV(p); + b=(pv[0]||pv[1]||pv[2]||pv[3])&&(pv[4]||pv[5]); + if(!b&&jt->dotnames)b=(pv[6]||pv[7]||pv[8]||pv[9])&&(pv[10]||pv[11]); + R b; +} /* whether h denotes an explicit derived function */ + +static F1(jtcolon0){A l,z;C*p,*q,*s;I m,n; + n=0; RZ(z=exta(LIT,1L,1L,300L)); s=CAV(z); + while(1){ + RE(l=jgets("\001")); + if(!l)break; + m=AN(l); p=q=CAV(l); + if(m){while(' '==*p)++p; if(')'==*p){while(' '==*++p); if(p>=m+q)break;}} + while(AN(z)<=n+m){RZ(z=ext(0,z)); s=CAV(z);} + MC(s+n,q,m); n+=m; *(s+n)=CLF; ++n; + } + R str(n,s); +} /* enter nl terminated lines; ) on a line by itself to exit */ + +static F1(jtlineit){ + R 1<AR(w)?ravel(stitch(w,scc(CLF))):AN(w)&&CLF==cl(w)?w:over(w,scc(CLF)); +} + +static B jtsent12c(J jt,A w,A*m,A*d){C*p,*q,*r,*s,*x; + ASSERT(!AN(w)||LIT&AT(w),EVDOMAIN); + ASSERT(2>=AR(w),EVRANK); + RZ(w=lineit(w)); + x=p=r=CAV(w); /* p: monad start; r: dyad start */ + q=s=p+AN(w); /* q: monad end; s: dyad end */ + while(x<s){ + q=x; + while(' '==*x)++x; if(':'==*x){while(' '==*++x); if(CLF==*x){r=++x; break;}} + while(CLF!=*x++); + } + if(x==s)q=r=s; + *m=df1(str(q-p,p),cut(ds(CBOX),num[-2])); + *d=df1(str(s-r,r),cut(ds(CBOX),num[-2])); + R 1; +} /* literal fret-terminated or matrix sentences into monad/dyad */ + +static B jtsent12b(J jt,A w,A*m,A*d){A t,*wv,y,*yv;I j,*v,wd; + ASSERT(1>=AR(w),EVRANK); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(y,BOX,AN(w),AR(w),AS(w)); yv=AAV(y); + DO(AN(w), RZ(yv[i]=vs(WVR(i)));); + RZ(t=indexof(y,link(chr[':'],str(1L,":")))); v=AV(t); j=MIN(*v,*(1+v)); + *m=take(sc(j ),y); + *d=drop(sc(j+1),y); + R 1; +} /* boxed sentences into monad/dyad */ + +F2(jtcolon){A d,h,*hv,m;B b;C*s;I flag=0,n,p; + RZ(a&&w); + if(VERB&AT(a)&&VERB&AT(w)){V*v; + v=VAV(a); if(CCOLON==v->id&&VERB&AT(v->f)&&VERB&AT(v->g))a=v->f; + v=VAV(w); if(CCOLON==v->id&&VERB&AT(v->f)&&VERB&AT(v->g))w=v->g; + R fdef(CCOLON,VERB,xv1,xv2,a,w,0L,0L,mr(a),lr(w),rr(w)); + } + RE(n=i0(a)); + if(equ(w,zero)){RZ(w=colon0(mark)); if(!n)R w;} + if(C2T&AT(w))RZ(w=cvt(LIT,w)); + if(10<n){s=CAV(w); p=AN(w); if(p&&CLF==s[p-1])RZ(w=str(p-1,s));} + else{ + RZ(BOX&AT(w)?sent12b(w,&m,&d):sent12c(w,&m,&d)); + if(4==n){if(AN(m)&&!AN(d))d=m; m=mtv;} + GA(h,BOX,2*HN,1,0); hv=AAV(h); + RE(b=preparse(m,hv, hv+1 )); if(b)flag|=VTRY1; hv[2 ]=jt->retcomm?m:mtv; + RE(b=preparse(d,hv+HN,hv+HN+1)); if(b)flag|=VTRY2; hv[2+HN]=jt->retcomm?d:mtv; + } + if(!n)R ca(w); + if(2>=n){ + RE(b=xop(h)); + if(b)flag|=VXOPR; + else if(2==n&&AN(m)&&!AN(d)){A*u=hv,*v=hv+HN,x; DO(HN, x=*u; *u++=*v; *v++=x;);} + } + flag|=VFIX; + switch(n){ + case 1: R fdef(CCOLON, ADV, b?xop1:xadv,0L, num[n],0L,h, flag, RMAX,RMAX,RMAX); + case 2: R fdef(CCOLON, CONJ, 0L,b?xop2:jtxdefn, num[n],0L,h, flag, RMAX,RMAX,RMAX); + case 3: R fdef(CCOLON, VERB, xn1,jtxdefn, num[n],0L,h, flag, RMAX,RMAX,RMAX); + case 4: R fdef(CCOLON, VERB, xn1,jtxdefn, num[n],0L,h, flag, RMAX,RMAX,RMAX); + case 13: R vtrans(w); + default: ASSERT(0,EVDOMAIN); +}}
new file mode 100644 --- /dev/null +++ b/d.c @@ -0,0 +1,232 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug: Error Signalling and Display */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#endif + +#include "j.h" +#include "d.h" + + +static void jtep(J jt,I n,C*s){I m; + m=NETX-jt->etxn; m=MIN(n,m); + if(0<m){MC(jt->etx+jt->etxn,s,m); jt->etxn+=m;} +} + +static void jteputs(J jt,C*s){ep((I)strlen(s),s);} + +static void jteputc(J jt,C c){ep(1L,&c);} + +static void jteputl(J jt,A w){ep(AN(w),CAV(w)); eputc(CLF);} + +static void jteputv(J jt,A w){I m=NETX-jt->etxn; jt->etxn+=thv(w,MIN(m,200),jt->etx+jt->etxn);} + /* numeric vector w */ + +static void jteputq(J jt,A w){C q=CQUOTE,*s; + if(equ(alp,w))eputs(" a."+!jt->nflag); + else{ + eputc(q); + s=CAV(w); DO(AN(w), eputc(s[i]); if(q==s[i])eputc(q);); + eputc(q); +}} /* string w, possibly with quotes */ + +static void jtefmt(J jt,C*s,I i){ + if(15<NETX-jt->etxn){C*v=jt->etx+jt->etxn; sprintf(v,s,i); jt->etxn+=strlen(v);} +} + +void jtshowerr(J jt){C b[1+2*NETX],*p,*q,*r; + if(jt->etxn&&jt->tostdout){ + p=b; q=jt->etx; r=q+jt->etxn; + while(q<r){if(*q==CLF){strcpy(p,jt->outseq); p+=strlen(jt->outseq); ++q;}else *p++=*q++;} + *p=0; + jsto(jt,MTYOER,b); + } + jt->etxn=0; +} + +static void jtdspell(J jt,C id,A w){C c,s[5]; + if(id==CFCONS){if(jt->nflag)eputc(' '); eputv(VAV(w)->h); eputc(':');} + else{ + s[0]=' '; s[4]=0; + spellit(id,1+s); + c=s[1]; + eputs(s+!(c==CESC1||c==CESC2||jt->nflag&&CA==ctype[c])); +}} + +static void jtdisp(J jt,A w){B b=1&&AT(w)&NAME+NUMERIC; + if(b&&jt->nflag)eputc(' '); + switch(AT(w)){ + case B01: + case INT: + case FL: + case CMPX: + case XNUM: + case RAT: eputv(w); break; + case BOX: eputs(" a:"+!jt->nflag); break; + case NAME: ep(AN(w),NAV(w)->s); break; + case LIT: eputq(w); break; + case LPAR: eputc('('); break; + case RPAR: eputc(')'); break; + case ASGN: dspell(*CAV(w),w); break; + case MARK: break; + default: dspell(VAV(w)->id,w); + } + jt->nflag=b; +} + +static void jtseeparse(J jt,DC d){A*v,y;I m; + y=d->dcy; v=AAV(y); /* list of tokens */ + m=d->dci-1; /* index of active token when error found */ + jt->nflag=0; + DO(AN(y), if(i==m)eputs(" "); disp(v[i]);); +} /* display error line */ + +F1(jtunparse){A*v,z; + RZ(w); + jt->etxn=jt->nflag=0; + v=AAV(w); DO(AN(w), disp(v[i]);); z=str(jt->etxn,jt->etx); + jt->etxn=0; + R z; +} + +static void jtseecall(J jt,DC d){A a; + if(a=d->dca)ep(AN(a),NAV(a)->s); + efmt(d->dcx&&d->dcy?"[:"FMTI"]":"["FMTI"]",lnumsi(d)); +} /* display function line */ + +static void jtdhead(J jt,C k,DC d){static C s[]=" "; + *s=d&&d->dcsusp?'*':'|'; + ep(k+1L,s); +} /* preface stack display line */ + +void jtdebdisp(J jt,DC d){A*x,y;I e,t; + e=d->dcj; + t=d->dctype; + if(e&&!jt->etxn&&(t==DCPARSE||t==DCCALL)){x=e+AAV(jt->evm); dhead(0,0L); eputl(*x);} + switch(t){ + case DCPARSE: dhead(3,d); seeparse(d); if(NETX==jt->etxn)--jt->etxn; eputc(CLF); break; + case DCCALL: dhead(0,d); seecall(d); eputc(CLF); break; + case DCSCRIPT: dhead(0,d); efmt("[-"FMTI"] ", d->dcn-1); + if(0<=d->dcm){y=*(d->dcm+AAV(jt->slist)); ep(AN(y),CAV(y));} + eputc(CLF); +}} + +static B jtdebsi1(J jt,DC d){I t; + RZ(d); + t=d->dctype; + debdisp(d); + d=d->dclnk; + RZ(d&&t==DCPARSE); + t=d->dctype; + RZ(t==DCSCRIPT||t==DCCALL&&d->dcloc); + debdisp(d); + R 1; +} + +F1(jtdbstack){DC d=jt->sitop; + ASSERTMTV(w); + if(d){if(DCCALL!=d->dctype)d=d->dclnk; while(d){debdisp(d); d=d->dclnk;}} + R mtm; +} /* 13!:1 display SI stack */ + +F1(jtdbstackz){A y; + RE(dbstack(w)); + RZ(y=str(jt->etxn,jt->etx)); + jt->etxn=0; + R df1(y,cut(ds(CLEFT),num[-2])); +} /* 13!:18 SI stack as result */ + + +static void jtjsigstr(J jt,I e,I n,C*s){ + if(jt->jerr)R; + jt->jerr=(C)e; jt->jerr1=e; jt->etxn=0; + dhead(0,0L); + if(jt->db&&!spc()){eputs("ws full (can not suspend)"); eputc(CLF); jt->db=0;} + ep(n,s); + if(!jt->glock&&jt->curname){eputs(": "); ep(AN(jt->curname),NAV(jt->curname)->s); jt->curname=0;} + eputc(CLF); + if(n&&!jt->glock)debsi1(jt->sitop); + jt->etxn1=jt->etxn; +} /* signal error e with error text s of length n */ + +static void jtjsig(J jt,I e,A x){jsigstr(e,AN(x),CAV(x));} + /* signal error e with error text x */ + +void jtjsigd(J jt,C*s){C buf[100],*d="domain error: ";I m,n,p; + m=strlen(d); MC(buf,d,m); + n=strlen(s); p=MIN(n,100-m); MC(buf+m,s,p); + jsigstr(EVDOMAIN,m+p,buf); +} + +void jtjsignal(J jt,I e){A x; + if(EVATTN==e||EVBREAK==e||e==EVINPRUPT) *jt->adbreak=0; + x=0<e&&e<=NEVM?*(e+AAV(jt->evm)):mtv; jsigstr(e,AN(x),CAV(x)); +} + +void jtjsignal3(J jt,I e,A w,I j){ + if(jt->jerr)R; + jt->jerr=(C)e; jt->jerr1=e; jt->etxn=0; + dhead(0,0L); + if(jt->db&&!spc()){eputs("ws full (can not suspend)"); eputc(CLF); jt->db=0;} + eputl(*(jt->jerr+AAV(jt->evm))); + if(!jt->glock){ + if(e==EVCTRL){dhead(3,0L); efmt("["FMTI"]",j); eputl(w);} + else{ + dhead(3,0L); eputl(w); + dhead(3,0L); DO(j, eputc(' ');); eputc('^'); eputc(CLF); + } + debsi1(jt->sitop); + } + jt->etxn1=jt->etxn; +} /* signal error e on line w with caret at j */ + +static F2(jtdbsig){I e; + RE(0); + if(!AN(w))R mtm; + RZ(w=vi(w)); e=*AV(w); + ASSERT(1<=e,EVDOMAIN); + ASSERT(e<=255,EVLIMIT); + if(a||e>NEVM){if(!a)a=mtv; RZ(a=vs(a)); jsig(e,a);} else jsignal(e); + R 0; +} + +F1(jtdbsig1){R dbsig(0L,w);} /* 13!:8 signal error */ +F2(jtdbsig2){R dbsig(a, w);} + + +F1(jtdberr){ASSERTMTV(w); R sc(jt->jerr1);} /* 13!:11 last error number */ +F1(jtdbetx){ASSERTMTV(w); R str(jt->etxn1,jt->etx);} /* 13!:12 last error text */ + + +A jtjerrno(J jt){ +#if !SY_WINCE + switch(errno){ + case EMFILE: + case ENFILE: jsignal(EVLIMIT ); R 0; + case ENOENT: jsignal(EVFNAME ); R 0; + case EBADF: jsignal(EVFNUM ); R 0; + case EACCES: jsignal(EVFACCESS); R 0; +#else /* WINCE: */ + switch(GetLastError()){ + case ERROR_DISK_FULL: + case ERROR_FILENAME_EXCED_RANGE: + case ERROR_NO_MORE_FILES: + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_NOT_ENOUGH_QUOTA: + case ERROR_TOO_MANY_OPEN_FILES: jsignal(EVLIMIT ); R 0; + case ERROR_BAD_PATHNAME: + case ERROR_INVALID_NAME: jsignal(EVDOMAIN ); R 0; + case ERROR_ALREADY_EXISTS: + case ERROR_FILE_EXISTS: + case ERROR_PATH_NOT_FOUND: + case ERROR_FILE_NOT_FOUND: jsignal(EVFNAME ); R 0; + case ERROR_ACCESS_DENIED: + case ERROR_WRITE_PROTECT: + case ERROR_SHARING_VIOLATION: jsignal(EVFACCESS); R 0; +#endif + default: jsignal(EVFACE); R 0; +}} /* see <errno.h> / <winerror.h> */
new file mode 100644 --- /dev/null +++ b/d.h @@ -0,0 +1,39 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug */ + + +/* jt->db and jt->dbuser values; 0 means no debug */ + +#define DB1 1 /* full debug */ +#define DBERRCAP 2 /* stack error info capture */ +#define DBTRY 3 /* full debug & try/catch in effect (db only) */ + + +/* jt->dbsusact values: */ + +#define SUSCONT 0 /* continue current suspension */ +#define SUSCLEAR 1 /* clear stack */ +#define SUSRUN 2 /* run again */ +#define SUSRET 3 /* return result */ +#define SUSJUMP 4 /* jump to specified line */ +#define SUSNEXT 5 /* run next line */ +#define SUSSS 6 /* single step mode */ + + +/* si->dcss values; 0 means not single step */ + +#define SSCUTBACK 19 /* cut back one step level */ +#define SSSTEPOVER 20 /* run curr line; stop at next line in curr fn */ +#define SSSTEPINTO 21 /* run curr line; stop at next line */ +#define SSSTEPOUT 22 /* run curr fn to end; stop at next line */ +#define SSSTEPOVERs 30 +#define SSSTEPINTOs 31 + + +extern B jtdbstop(J,DC,I); +extern DC jtssnext(J,DC,C); +extern I lnumcw(I,A); +extern I lnumsi(DC); +
new file mode 100644 --- /dev/null +++ b/dc.c @@ -0,0 +1,43 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug: Function Call Information */ + +#include "j.h" +#include "d.h" + + +static F1(jtdfrep){RZ(w); R NOUN&AT(w)?w:lrep(w);} + +static SYMWALK(jtdloc,A,BOX,5,2,1,{RZ(*zv++=sfn(0,d->name)); RZ(*zv++=dfrep(d->val));}) + +static B jtdrow(J jt,DC si,DC s0,A*zv){A fs,q,*qv,y;C c; + fs=si->dcf; + GA(q,BOX,si->dcx&&si->dcy?2:1,1,0); qv=AAV(q); + if(si->dcx)*qv++=dfrep(si->dcx); + if(si->dcy)*qv++=dfrep(si->dcy); + *zv++=sfn(0,si->dca); /* 0 name */ + *zv++=sc(si->dcj); /* 1 error number */ + *zv++=sc(lnumsi(si)); /* 2 line number */ + *zv++=num[ADV&AT(fs)?1:CONJ&AT(fs)?2:3]; /* 3 name class */ + *zv++=lrep(fs); /* 4 linear rep. */ + *zv++=0; /* 5 script name */ + *zv++=q; /* 6 argument list */ + if(si->dcloc){RZ(y=dloc(si->dcloc)); RZ(*zv++=grade2(y,ope(irs1(y,0L,1L,jthead))));} + else RZ(*zv++=iota(v2(0L,2L))); /* 7 locals */ + c=si->dcsusp||s0&&DCPARSE==s0->dctype&&s0->dcsusp?'*':' '; + RZ(*zv++=scc(c)); /* 8 * if begins a suspension */ + R 1; +} /* construct one row of function call matrix */ + +F1(jtdbcall){A y,*yv,z,*zv;DC si,s0=0;I c=9,m=0,*s; + ASSERTMTV(w); + si=jt->sitop; while(si){if(DCCALL==si->dctype)++m; si=si->dclnk;} + GA(z,BOX,m*c,2,0); s=AS(z); s[0]=m; s[1]=c; + si=jt->sitop; zv=AAV(z); + while(si){if(DCCALL==si->dctype){RZ(drow(si,s0,zv)); zv+=c;} s0=si; si=si->dclnk;} + RZ(y=from(scind(irs1(z,0L,1L,jthead)),over(snl(mtv),ace))); + yv=AAV(y); zv=5+AAV(z); + DO(m, *zv=*yv++; zv+=c;); + R z; +} /* 13!:13 function call matrix */
new file mode 100644 --- /dev/null +++ b/defs/hostdefs.c @@ -0,0 +1,159 @@ +#include <stdio.h> +#ifndef _WIN32 +#include <stdlib.h> +#include <unistd.h> +#include <sys/mman.h> +#include <regex.h> +#include <sys/time.h> +#include <sys/types.h> +#else + +#include <winsock.h> +#include "winregex\rxposix.h" +#endif +#include <sys/types.h> +#include <fcntl.h> +#include <errno.h> +#define offset(r,f) (((char*)&((r*)0)->f)-((char*)((r*)0))) +main(){ + printf ("NB. do not edit -- created by sym2ijs\n\n"); + printf ("cocurrent <'jdefs'\n\n"); +#ifndef _WIN32 + printf ("F_OK=: %d\n",(int)F_OK); + printf ("R_OK=: %d\n",(int)R_OK); + printf ("W_OK=: %d\n",(int)W_OK); + printf ("X_OK=: %d\n",(int)X_OK); + printf ("STDIN_FILENO=: %d\n",(int)STDIN_FILENO); + printf ("STDOUT_FILENO=: %d\n",(int)STDOUT_FILENO); + printf ("STDERR_FILENO=: %d\n",(int)STDERR_FILENO); +#else + puts ("F_OK=:0"); + puts ("R_OK=:4"); + puts ("W_OK=:2"); + puts ("X_OK=:1"); +#endif + printf ("SEEK_CUR=: %d\n",(int)SEEK_CUR); + printf ("SEEK_END=: %d\n",(int)SEEK_END); + printf ("SEEK_SET=: %d\n",(int)SEEK_SET); + puts(""); + printf ("O_APPEND=: %d\n",(int)O_APPEND); + printf ("O_CREAT=: %d\n",(int)O_CREAT); + printf ("O_EXCL=: %d\n",(int)O_EXCL); + printf ("O_RDONLY=: %d\n",(int)O_RDONLY); + printf ("O_RDWR=: %d\n",(int)O_RDWR); + printf ("O_TRUNC=: %d\n",(int)O_TRUNC); + printf ("O_WRONLY=: %d\n",(int)O_WRONLY); + puts(""); +#ifndef _WIN32 + printf ("O_ACCMODE=: %d\n",(int)O_ACCMODE); + printf ("O_NOCTTY=: %d\n",(int)O_NOCTTY); + printf ("O_NONBLOCK=: %d\n",(int)O_NONBLOCK); + printf ("FD_CLOEXEC=: %d\n",(int)FD_CLOEXEC); + printf ("F_DUPFD=: %d\n",(int)F_DUPFD); + printf ("F_GETFD=: %d\n",(int)F_GETFD); + printf ("F_SETFD=: %d\n",(int)F_SETFD); + printf ("F_GETFL=: %d\n",(int)F_GETFL); + printf ("F_SETFL=: %d\n",(int)F_SETFL); + printf ("F_SETLK=: %d\n",(int)F_SETLK); + printf ("F_SETLKW=: %d\n",(int)F_SETLKW); + printf ("F_GETLK=: %d\n",(int)F_GETLK); + printf ("F_UNLCK=: %d\n",(int)F_UNLCK); + printf ("F_WRLCK=: %d\n",(int)F_WRLCK); + printf ("flock_sz=: %d\n",(int)sizeof (struct flock)); + printf ("l_len_off=: %d\n",(int)offset(struct flock,l_len)); + printf ("l_len_sz=: %d\n",(int)sizeof(((struct flock*)0)->l_len)); + printf ("l_pid_off=: %d\n",(int)offset(struct flock,l_pid)); + printf ("l_pid_sz=: %d\n",(int)sizeof(((struct flock*)0)->l_pid)); + printf ("l_start_off=: %d\n",(int)offset(struct flock,l_start)); + printf ("l_start_sz=: %d\n",(int)sizeof(((struct flock*)0)->l_start)); + printf ("l_type_off=: %d\n",(int)offset(struct flock,l_type)); + printf ("l_type_sz=: %d\n",(int)sizeof(((struct flock*)0)->l_type)); + printf ("l_whence_off=: %d\n",(int)offset(struct flock,l_whence)); + printf ("l_whence_sz=: %d\n",(int)sizeof(((struct flock*)0)->l_whence)); + puts(""); + printf ("PROT_READ=: %d\n",(int)PROT_READ); + printf ("PROT_WRITE=: %d\n",(int)PROT_WRITE); + printf ("PROT_EXEC=: %d\n",(int)PROT_EXEC); + printf ("PROT_NONE=: %d\n",(int)PROT_NONE); + printf ("MAP_SHARED=: %d\n",(int)MAP_SHARED); + printf ("MAP_PRIVATE=: %d\n",(int)MAP_PRIVATE); + printf ("MAP_FIXED=: %d\n",(int)MAP_FIXED); +#endif + puts(""); + printf ("REG_EXTENDED=: %d\n",(int)REG_EXTENDED); + printf ("REG_ICASE=: %d\n",(int)REG_ICASE); + printf ("REG_NOSUB=: %d\n",(int)REG_NOSUB); + printf ("REG_NEWLINE=: %d\n",(int)REG_NEWLINE); + puts(""); + printf ("regex_t_sz=: %d\n",(int)sizeof (regex_t)); + printf ("re_nsub_off=: %d\n",(int)offset(regex_t,re_nsub)); + printf ("re_nsub_sz=: %d\n",(int)sizeof(((regex_t*)0)->re_nsub)); + printf ("regmatch_t_sz=: %d\n",(int)sizeof (regmatch_t)); + printf ("rm_so_off=: %d\n",(int)offset(regmatch_t,rm_so)); + printf ("rm_so_sz=: %d\n",(int)sizeof(((regmatch_t*)0)->rm_so)); + printf ("rm_eo_off=: %d\n",(int)offset(regmatch_t,rm_eo)); + printf ("rm_eo_sz=: %d\n",(int)sizeof(((regmatch_t*)0)->rm_eo)); + puts(""); +#ifdef linux +#define fds_bits __fds_bits +#endif + puts(""); +#ifndef _WIN32 + printf ("fd_set_sz=: %d\n",(int)sizeof (fd_set)); + printf ("fds_bits_off=: %d\n",(int)offset(fd_set,fds_bits)); + printf ("fds_bits_sz=: %d\n",(int)sizeof(((fd_set*)0)->fds_bits)); +#endif + printf ("FD_SETSIZE=: %d\n",(int)FD_SETSIZE); + printf ("timeval_sz=: %d\n",(int)sizeof (struct timeval)); + printf ("tv_sec_off=: %d\n",(int)offset(struct timeval,tv_sec)); + printf ("tv_sec_sz=: %d\n",(int)sizeof(((struct timeval*)0)->tv_sec)); + printf ("tv_usec_off=: %d\n",(int)offset(struct timeval,tv_usec)); + printf ("tv_usec_sz=: %d\n",(int)sizeof(((struct timeval*)0)->tv_usec)); + puts(""); + printf ("E2BIG=: %d\n",(int)E2BIG); + printf ("EFAULT=: %d\n",(int)EFAULT); + printf ("ENFILE=: %d\n",(int)ENFILE); + printf ("ENOTTY=: %d\n",(int)ENOTTY); + printf ("EACCES=: %d\n",(int)EACCES); + printf ("EFBIG=: %d\n",(int)EFBIG); + printf ("ENODEV=: %d\n",(int)ENODEV); + printf ("ENXIO=: %d\n",(int)ENXIO); + printf ("EAGAIN=: %d\n",(int)EAGAIN); + printf ("ENOENT=: %d\n",(int)ENOENT); + printf ("EPERM=: %d\n",(int)EPERM); + printf ("EBADF=: %d\n",(int)EBADF); + printf ("EINTR=: %d\n",(int)EINTR); + printf ("ENOEXEC=: %d\n",(int)ENOEXEC); + printf ("EPIPE=: %d\n",(int)EPIPE); + printf ("EINVAL=: %d\n",(int)EINVAL); + printf ("ENOLCK=: %d\n",(int)ENOLCK); + printf ("ERANGE=: %d\n",(int)ERANGE); + printf ("EBUSY=: %d\n",(int)EBUSY); + printf ("EIO=: %d\n",(int)EIO); + printf ("ENOMEM=: %d\n",(int)ENOMEM); + printf ("EROFS=: %d\n",(int)EROFS); + printf ("EISDIR=: %d\n",(int)EISDIR); + printf ("ENOSPC=: %d\n",(int)ENOSPC); + printf ("ESPIPE=: %d\n",(int)ESPIPE); + printf ("ECHILD=: %d\n",(int)ECHILD); + printf ("EMFILE=: %d\n",(int)EMFILE); + printf ("ENOSYS=: %d\n",(int)ENOSYS); + printf ("ESRCH=: %d\n",(int)ESRCH); + printf ("EDEADLK=: %d\n",(int)EDEADLK); + printf ("EMLINK=: %d\n",(int)EMLINK); + printf ("ENOTDIR=: %d\n",(int)ENOTDIR); + printf ("EDOM=: %d\n",(int)EDOM); + printf ("ENOTEMPTY=: %d\n",(int)ENOTEMPTY); + printf ("EXDEV=: %d\n",(int)EXDEV); + printf ("EEXIST=: %d\n",(int)EEXIST); + printf ("ENAMETOOLONG=: %d\n",(int)ENAMETOOLONG); + puts(""); +#ifndef _WIN32 + printf ("EINPROGRESS=: %d\n",(int)EINPROGRESS); + printf ("ECANCELED=: %d\n",(int)ECANCELED); + printf ("ETIMEDOUT=: %d\n",(int)ETIMEDOUT); + printf ("EMSGSIZE=: %d\n",(int)EMSGSIZE); + printf ("ENOTSUP=: %d\n",(int)ENOTSUP); +#endif + exit (0); +}
new file mode 100644 --- /dev/null +++ b/defs/hostdefs.sym @@ -0,0 +1,93 @@ +<stdio.h> +#ifndef _WIN32 +<stdlib.h> +<unistd.h> +<sys/mman.h> +<regex.h> +<sys/time.h> +<sys/types.h> +#else + +<winsock.h> +#include "winregex\rxposix.h" +#endif +<sys/types.h> +<fcntl.h> +<errno.h> + + +; unistd.h: +#ifndef _WIN32 +i F_OK R_OK W_OK X_OK +i STDIN_FILENO STDOUT_FILENO STDERR_FILENO +#else +J F_OK=:0 +J R_OK=:4 +J W_OK=:2 +J X_OK=:1 +#endif +i SEEK_CUR SEEK_END SEEK_SET +; Defining NULL is problematic in various ways. +; Most notably, it's unclear whether it should be boxed or not. + +; fcntl: +i O_APPEND O_CREAT O_EXCL O_RDONLY O_RDWR O_TRUNC O_WRONLY + +#ifndef _WIN32 +i O_ACCMODE O_NOCTTY O_NONBLOCK +i FD_CLOEXEC +i F_DUPFD F_GETFD F_SETFD F_GETFL F_SETFL +i F_SETLK F_SETLKW F_GETLK F_UNLCK F_WRLCK +st struct flock +f l_len +f l_pid +f l_start +f l_type +f l_whence + +; mmap: +i PROT_READ PROT_WRITE PROT_EXEC PROT_NONE +i MAP_SHARED MAP_PRIVATE MAP_FIXED +#endif + +; Regex stuff: +i REG_EXTENDED REG_ICASE REG_NOSUB REG_NEWLINE + +st regex_t +f re_nsub +st regmatch_t +f rm_so +f rm_eo + +; select(2) support. +; This is beyond posix.1, but the following definitions are pretty +; universal now. Linux apparently requires some special treatment. +#ifdef linux +#define fds_bits __fds_bits +#endif + +#ifndef _WIN32 +st fd_set +f fds_bits +#endif +i FD_SETSIZE +st struct timeval +f tv_sec +f tv_usec + +; POSIX error constants: +i E2BIG EFAULT ENFILE ENOTTY +i EACCES EFBIG ENODEV ENXIO +i EAGAIN ENOENT EPERM +i EBADF EINTR ENOEXEC EPIPE +i EINVAL ENOLCK ERANGE +i EBUSY EIO ENOMEM EROFS +i EISDIR ENOSPC ESPIPE +i ECHILD EMFILE ENOSYS ESRCH +i EDEADLK EMLINK ENOTDIR +i EDOM ENOTEMPTY EXDEV +i EEXIST ENAMETOOLONG + +#ifndef _WIN32 +i EINPROGRESS ECANCELED ETIMEDOUT EMSGSIZE ENOTSUP +#endif \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/defs/netdefs.c @@ -0,0 +1,236 @@ +#include <stdio.h> +#ifdef _WIN32 +#include <winsock.h> +#else +#include <stdlib.h> +#include <sys/socket.h> +#ifdef sun +#include <inet/tcp.h> +#endif +#include <netdb.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/ioctl.h> +#endif +#include <sys/types.h> +#define offset(r,f) (((char*)&((r*)0)->f)-((char*)((r*)0))) +main(){ + printf ("NB. do not edit -- created by sym2ijs\n\n"); + printf ("cocurrent <'jdefs'\n\n"); + printf ("FIONBIO=: %d\n",(int)FIONBIO); + printf ("FIONREAD=: %d\n",(int)FIONREAD); + printf ("FD_SETSIZE=: %d\n",(int)FD_SETSIZE); + puts(""); +#ifdef _WIN32 + printf ("SD_RECEIVE=: %d\n",(int)SD_RECEIVE); + printf ("SD_SEND=: %d\n",(int)SD_SEND); + printf ("SD_BOTH=: %d\n",(int)SD_BOTH); +#endif + puts(""); + printf ("sockaddr_sz=: %d\n",(int)sizeof (struct sockaddr)); + printf ("sa_family_off=: %d\n",(int)offset(struct sockaddr,sa_family)); + printf ("sa_family_sz=: %d\n",(int)sizeof(((struct sockaddr*)0)->sa_family)); + printf ("sa_data_off=: %d\n",(int)offset(struct sockaddr,sa_data)); + printf ("sa_data_sz=: %d\n",(int)sizeof(((struct sockaddr*)0)->sa_data)); + puts(""); + printf ("sockaddr_in_sz=: %d\n",(int)sizeof (struct sockaddr_in)); + printf ("sin_family_off=: %d\n",(int)offset(struct sockaddr_in,sin_family)); + printf ("sin_family_sz=: %d\n",(int)sizeof(((struct sockaddr_in*)0)->sin_family)); + printf ("sin_port_off=: %d\n",(int)offset(struct sockaddr_in,sin_port)); + printf ("sin_port_sz=: %d\n",(int)sizeof(((struct sockaddr_in*)0)->sin_port)); + printf ("sin_addr_off=: %d\n",(int)offset(struct sockaddr_in,sin_addr)); + printf ("sin_addr_sz=: %d\n",(int)sizeof(((struct sockaddr_in*)0)->sin_addr)); + puts(""); + printf ("in_addr_sz=: %d\n",(int)sizeof (struct in_addr)); + printf ("s_addr_off=: %d\n",(int)offset(struct in_addr,s_addr)); + printf ("s_addr_sz=: %d\n",(int)sizeof(((struct in_addr*)0)->s_addr)); + puts(""); + printf ("hostent_sz=: %d\n",(int)sizeof (struct hostent)); + printf ("h_name_off=: %d\n",(int)offset(struct hostent,h_name)); + printf ("h_name_sz=: %d\n",(int)sizeof(((struct hostent*)0)->h_name)); + printf ("h_aliases_off=: %d\n",(int)offset(struct hostent,h_aliases)); + printf ("h_aliases_sz=: %d\n",(int)sizeof(((struct hostent*)0)->h_aliases)); + printf ("h_addrtype_off=: %d\n",(int)offset(struct hostent,h_addrtype)); + printf ("h_addrtype_sz=: %d\n",(int)sizeof(((struct hostent*)0)->h_addrtype)); + printf ("h_length_off=: %d\n",(int)offset(struct hostent,h_length)); + printf ("h_length_sz=: %d\n",(int)sizeof(((struct hostent*)0)->h_length)); + printf ("h_addr_list_off=: %d\n",(int)offset(struct hostent,h_addr_list)); + printf ("h_addr_list_sz=: %d\n",(int)sizeof(((struct hostent*)0)->h_addr_list)); + puts(""); + puts(""); + printf ("SIOCATMARK=: %d\n",(int)SIOCATMARK); + puts(""); + puts(""); + printf ("IPPROTO_IP=: %d\n",(int)IPPROTO_IP); + printf ("IPPROTO_ICMP=: %d\n",(int)IPPROTO_ICMP); + printf ("IPPROTO_IGMP=: %d\n",(int)IPPROTO_IGMP); + printf ("IPPROTO_TCP=: %d\n",(int)IPPROTO_TCP); + printf ("IPPROTO_PUP=: %d\n",(int)IPPROTO_PUP); + printf ("IPPROTO_UDP=: %d\n",(int)IPPROTO_UDP); + printf ("IPPROTO_IDP=: %d\n",(int)IPPROTO_IDP); + printf ("IPPROTO_RAW=: %d\n",(int)IPPROTO_RAW); + printf ("IPPROTO_MAX=: %d\n",(int)IPPROTO_MAX); + puts(""); + puts(""); + printf ("INADDR_ANY=: %d\n",(int)INADDR_ANY); + printf ("INADDR_LOOPBACK=: %d\n",(int)INADDR_LOOPBACK); + printf ("INADDR_BROADCAST=: %d\n",(int)INADDR_BROADCAST); +#ifdef INADDR_NONE + printf ("INADDR_NONE=: %d\n",(int)INADDR_NONE); +#else + puts ("INADDR_NONE=: _1"); +#endif + puts(""); +#ifndef _WIN32 + printf ("INADDR_UNSPEC_GROUP=: %d\n",(int)INADDR_UNSPEC_GROUP); + printf ("INADDR_ALLHOSTS_GROUP=: %d\n",(int)INADDR_ALLHOSTS_GROUP); + printf ("INADDR_MAX_LOCAL_GROUP=: %d\n",(int)INADDR_MAX_LOCAL_GROUP); + printf ("IN_LOOPBACKNET=: %d\n",(int)IN_LOOPBACKNET); +#endif + puts(""); + printf ("SOCK_STREAM=: %d\n",(int)SOCK_STREAM); + printf ("SOCK_DGRAM=: %d\n",(int)SOCK_DGRAM); + printf ("SOCK_RAW=: %d\n",(int)SOCK_RAW); + printf ("SOCK_RDM=: %d\n",(int)SOCK_RDM); + printf ("SOCK_SEQPACKET=: %d\n",(int)SOCK_SEQPACKET); + puts(""); + printf ("SOL_SOCKET=: %d\n",(int)SOL_SOCKET); + printf ("SO_DEBUG=: %d\n",(int)SO_DEBUG); + printf ("SO_REUSEADDR=: %d\n",(int)SO_REUSEADDR); + printf ("SO_KEEPALIVE=: %d\n",(int)SO_KEEPALIVE); + printf ("SO_DONTROUTE=: %d\n",(int)SO_DONTROUTE); + printf ("SO_BROADCAST=: %d\n",(int)SO_BROADCAST); + printf ("SO_LINGER=: %d\n",(int)SO_LINGER); + printf ("SO_OOBINLINE=: %d\n",(int)SO_OOBINLINE); + puts(""); + printf ("SO_SNDBUF=: %d\n",(int)SO_SNDBUF); + printf ("SO_RCVBUF=: %d\n",(int)SO_RCVBUF); + printf ("SO_SNDLOWAT=: %d\n",(int)SO_SNDLOWAT); + printf ("SO_RCVLOWAT=: %d\n",(int)SO_RCVLOWAT); + printf ("SO_SNDTIMEO=: %d\n",(int)SO_SNDTIMEO); + printf ("SO_RCVTIMEO=: %d\n",(int)SO_RCVTIMEO); + printf ("SO_ERROR=: %d\n",(int)SO_ERROR); + printf ("SO_TYPE=: %d\n",(int)SO_TYPE); + puts(""); + printf ("linger_sz=: %d\n",(int)sizeof (struct linger)); + printf ("l_onoff_off=: %d\n",(int)offset(struct linger,l_onoff)); + printf ("l_onoff_sz=: %d\n",(int)sizeof(((struct linger*)0)->l_onoff)); + printf ("l_linger_off=: %d\n",(int)offset(struct linger,l_linger)); + printf ("l_linger_sz=: %d\n",(int)sizeof(((struct linger*)0)->l_linger)); + puts(""); + printf ("AF_UNSPEC=: %d\n",(int)AF_UNSPEC); + printf ("AF_UNIX=: %d\n",(int)AF_UNIX); + printf ("AF_INET=: %d\n",(int)AF_INET); + printf ("AF_SNA=: %d\n",(int)AF_SNA); + printf ("AF_DECnet=: %d\n",(int)AF_DECnet); + printf ("AF_APPLETALK=: %d\n",(int)AF_APPLETALK); + printf ("AF_IPX=: %d\n",(int)AF_IPX); + printf ("AF_MAX=: %d\n",(int)AF_MAX); + printf ("PF_UNSPEC=: %d\n",(int)PF_UNSPEC); + printf ("PF_UNIX=: %d\n",(int)PF_UNIX); + printf ("PF_INET=: %d\n",(int)PF_INET); + printf ("PF_SNA=: %d\n",(int)PF_SNA); + printf ("PF_DECnet=: %d\n",(int)PF_DECnet); + printf ("PF_APPLETALK=: %d\n",(int)PF_APPLETALK); + printf ("PF_IPX=: %d\n",(int)PF_IPX); + printf ("PF_MAX=: %d\n",(int)PF_MAX); + puts(""); + printf ("SOMAXCONN=: %d\n",(int)SOMAXCONN); + printf ("MSG_OOB=: %d\n",(int)MSG_OOB); + printf ("MSG_PEEK=: %d\n",(int)MSG_PEEK); + printf ("MSG_DONTROUTE=: %d\n",(int)MSG_DONTROUTE); + puts(""); +#ifndef _WIN32 + printf ("msghdr_sz=: %d\n",(int)sizeof (struct msghdr)); + printf ("msg_name_off=: %d\n",(int)offset(struct msghdr,msg_name)); + printf ("msg_name_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_name)); + printf ("msg_namelen_off=: %d\n",(int)offset(struct msghdr,msg_namelen)); + printf ("msg_namelen_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_namelen)); + printf ("msg_iov_off=: %d\n",(int)offset(struct msghdr,msg_iov)); + printf ("msg_iov_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_iov)); + printf ("msg_iovlen_off=: %d\n",(int)offset(struct msghdr,msg_iovlen)); + printf ("msg_iovlen_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_iovlen)); +#if defined(linux) || defined(Darwin) + printf ("msg_control_off=: %d\n",(int)offset(struct msghdr,msg_control)); + printf ("msg_control_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_control)); + printf ("msg_controllen_off=: %d\n",(int)offset(struct msghdr,msg_controllen)); + printf ("msg_controllen_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_controllen)); + printf ("msg_flags_off=: %d\n",(int)offset(struct msghdr,msg_flags)); + printf ("msg_flags_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_flags)); +#else + printf ("msg_accrights_off=: %d\n",(int)offset(struct msghdr,msg_accrights)); + printf ("msg_accrights_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_accrights)); + printf ("msg_accrightslen_off=: %d\n",(int)offset(struct msghdr,msg_accrightslen)); + printf ("msg_accrightslen_sz=: %d\n",(int)sizeof(((struct msghdr*)0)->msg_accrightslen)); +#endif +#endif + puts(""); +#ifdef _WIN32 + printf ("SOCKET_ERROR=: %d\n",(int)SOCKET_ERROR); + printf ("FD_READ=: %d\n",(int)FD_READ); + printf ("FD_WRITE=: %d\n",(int)FD_WRITE); + printf ("FD_OOB=: %d\n",(int)FD_OOB); + printf ("FD_ACCEPT=: %d\n",(int)FD_ACCEPT); + printf ("FD_CONNECT=: %d\n",(int)FD_CONNECT); + printf ("FD_CLOSE=: %d\n",(int)FD_CLOSE); + printf ("WSABASEERR=: %d\n",(int)WSABASEERR); + printf ("WSAEINTR=: %d\n",(int)WSAEINTR); + printf ("WSAEBADF=: %d\n",(int)WSAEBADF); + printf ("WSAEACCES=: %d\n",(int)WSAEACCES); + printf ("WSAEFAULT=: %d\n",(int)WSAEFAULT); + printf ("WSAEINVAL=: %d\n",(int)WSAEINVAL); + printf ("WSAEMFILE=: %d\n",(int)WSAEMFILE); + printf ("WSAEWOULDBLOCK=: %d\n",(int)WSAEWOULDBLOCK); + printf ("WSAEINPROGRESS=: %d\n",(int)WSAEINPROGRESS); + printf ("WSAEALREADY=: %d\n",(int)WSAEALREADY); + printf ("WSAENOTSOCK=: %d\n",(int)WSAENOTSOCK); + printf ("WSAEDESTADDRREQ=: %d\n",(int)WSAEDESTADDRREQ); + printf ("WSAEMSGSIZE=: %d\n",(int)WSAEMSGSIZE); + printf ("WSAEPROTOTYPE=: %d\n",(int)WSAEPROTOTYPE); + printf ("WSAENOPROTOOPT=: %d\n",(int)WSAENOPROTOOPT); + printf ("WSAEPROTONOSUPPORT=: %d\n",(int)WSAEPROTONOSUPPORT); + printf ("WSAESOCKTNOSUPPORT=: %d\n",(int)WSAESOCKTNOSUPPORT); + printf ("WSAEOPNOTSUPP=: %d\n",(int)WSAEOPNOTSUPP); + printf ("WSAEPFNOSUPPORT=: %d\n",(int)WSAEPFNOSUPPORT); + printf ("WSAEAFNOSUPPORT=: %d\n",(int)WSAEAFNOSUPPORT); + printf ("WSAEADDRINUSE=: %d\n",(int)WSAEADDRINUSE); + printf ("WSAEADDRNOTAVAIL=: %d\n",(int)WSAEADDRNOTAVAIL); + printf ("WSAENETDOWN=: %d\n",(int)WSAENETDOWN); + printf ("WSAENETUNREACH=: %d\n",(int)WSAENETUNREACH); + printf ("WSAENETRESET=: %d\n",(int)WSAENETRESET); + printf ("WSAECONNABORTED=: %d\n",(int)WSAECONNABORTED); + printf ("WSAECONNRESET=: %d\n",(int)WSAECONNRESET); + printf ("WSAENOBUFS=: %d\n",(int)WSAENOBUFS); + printf ("WSAEISCONN=: %d\n",(int)WSAEISCONN); + printf ("WSAENOTCONN=: %d\n",(int)WSAENOTCONN); + printf ("WSAESHUTDOWN=: %d\n",(int)WSAESHUTDOWN); + printf ("WSAETOOMANYREFS=: %d\n",(int)WSAETOOMANYREFS); + printf ("WSAETIMEDOUT=: %d\n",(int)WSAETIMEDOUT); + printf ("WSAECONNREFUSED=: %d\n",(int)WSAECONNREFUSED); + printf ("WSAELOOP=: %d\n",(int)WSAELOOP); + printf ("WSAENAMETOOLONG=: %d\n",(int)WSAENAMETOOLONG); + printf ("WSAEHOSTDOWN=: %d\n",(int)WSAEHOSTDOWN); + printf ("WSAEHOSTUNREACH=: %d\n",(int)WSAEHOSTUNREACH); + printf ("WSAENOTEMPTY=: %d\n",(int)WSAENOTEMPTY); + printf ("WSAEPROCLIM=: %d\n",(int)WSAEPROCLIM); + printf ("WSAEUSERS=: %d\n",(int)WSAEUSERS); + printf ("WSAEDQUOT=: %d\n",(int)WSAEDQUOT); + printf ("WSAESTALE=: %d\n",(int)WSAESTALE); + printf ("WSAEREMOTE=: %d\n",(int)WSAEREMOTE); + printf ("WSASYSNOTREADY=: %d\n",(int)WSASYSNOTREADY); + printf ("WSAVERNOTSUPPORTED=: %d\n",(int)WSAVERNOTSUPPORTED); + printf ("WSANOTINITIALISED=: %d\n",(int)WSANOTINITIALISED); + printf ("WSAHOST_NOT_FOUND=: %d\n",(int)WSAHOST_NOT_FOUND); + printf ("HOST_NOT_FOUND=: %d\n",(int)HOST_NOT_FOUND); + printf ("WSATRY_AGAIN=: %d\n",(int)WSATRY_AGAIN); + printf ("TRY_AGAIN=: %d\n",(int)TRY_AGAIN); + printf ("WSANO_RECOVERY=: %d\n",(int)WSANO_RECOVERY); + printf ("NO_RECOVERY=: %d\n",(int)NO_RECOVERY); + printf ("WSANO_DATA=: %d\n",(int)WSANO_DATA); + printf ("NO_DATA=: %d\n",(int)NO_DATA); + printf ("WSANO_ADDRESS=: %d\n",(int)WSANO_ADDRESS); + printf ("NO_ADDRESS=: %d\n",(int)NO_ADDRESS); + printf ("WM_USER=: %d\n",(int)WM_USER); +#endif + exit (0); +}
new file mode 100644 --- /dev/null +++ b/defs/netdefs.sym @@ -0,0 +1,135 @@ +<stdio.h> +#ifdef _WIN32 +<winsock.h> +#else +<stdlib.h> +<sys/socket.h> +#ifdef sun +<inet/tcp.h> +#endif +<netdb.h> +<netinet/in.h> +<arpa/inet.h> +<sys/ioctl.h> +#endif +<sys/types.h> + + +; Networking-related definitions. +; (Keep "strongly-POSIX-related" definitions in unixsyms.sym, though.) +; + +i FIONBIO FIONREAD FD_SETSIZE + +#ifdef _WIN32 +i SD_RECEIVE SD_SEND SD_BOTH +#endif + +st struct sockaddr +f sa_family +f sa_data + +st struct sockaddr_in +f sin_family +f sin_port +f sin_addr + +st struct in_addr +f s_addr + +st struct hostent +f h_name +f h_aliases +f h_addrtype +f h_length +f h_addr_list + +; Provide just a tiny tiny subset of socket ioctls: + +i SIOCATMARK + +; The following are all "classic" Well Known Numbers as delivered +; with BSD4.3. The official reference today would be a look at +; the IANA lists, most notably RFC 1700. +; All the constants should probably better _not_ be used. +; getprotobyname etc. are they way to go. +; +; Having said that: +; We will restrict ourselves only to those constants listed with +; every netinet/in.h on any platform. + +i IPPROTO_IP IPPROTO_ICMP IPPROTO_IGMP IPPROTO_TCP +i IPPROTO_PUP IPPROTO_UDP IPPROTO_IDP +i IPPROTO_RAW IPPROTO_MAX + +; IMP link numbers? whoa, they lost their relevance in the late 70s... +; I doubt there's still _any_ of the (four?) IMP nodes is still running. +; Solaris has them, Linux not. Trash these entries. +; i IMPLINK_IP IMPLINK_LOWEXPER IMPLINK_HIGHEXPER + +i INADDR_ANY INADDR_LOOPBACK INADDR_BROADCAST +; INADDR_NONE is referring to the (deprecated) return value of +; the deprecated function inet_addr. The value is usually -1 +; (even though Solaris' inet_addr() return an unsigned long...) and +; actually clashes with the valid address INADDR_BROADCAST. Sigh... +#ifdef INADDR_NONE +i INADDR_NONE +#else +J INADDR_NONE=: _1 +#endif + +#ifndef _WIN32 +i INADDR_UNSPEC_GROUP INADDR_ALLHOSTS_GROUP INADDR_MAX_LOCAL_GROUP +i IN_LOOPBACKNET +#endif + +i SOCK_STREAM SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET + +i SOL_SOCKET +i SO_DEBUG SO_REUSEADDR SO_KEEPALIVE SO_DONTROUTE +i SO_BROADCAST SO_LINGER SO_OOBINLINE + +i SO_SNDBUF SO_RCVBUF SO_SNDLOWAT SO_RCVLOWAT SO_SNDTIMEO SO_RCVTIMEO +i SO_ERROR SO_TYPE + +st struct linger +f l_onoff +f l_linger + +; Again, only the common subset: +i AF_UNSPEC AF_UNIX AF_INET AF_SNA AF_DECnet AF_APPLETALK AF_IPX AF_MAX +i PF_UNSPEC PF_UNIX PF_INET PF_SNA PF_DECnet PF_APPLETALK PF_IPX PF_MAX + +i SOMAXCONN +i MSG_OOB MSG_PEEK MSG_DONTROUTE + +#ifndef _WIN32 +st struct msghdr +f msg_name +f msg_namelen +f msg_iov +f msg_iovlen +#if defined(linux) || defined(Darwin) +f msg_control +f msg_controllen +f msg_flags +#else +f msg_accrights +f msg_accrightslen +#endif +#endif + +#ifdef _WIN32 +i SOCKET_ERROR +i FD_READ FD_WRITE FD_OOB FD_ACCEPT FD_CONNECT FD_CLOSE +i WSABASEERR WSAEINTR WSAEBADF WSAEACCES WSAEFAULT WSAEINVAL WSAEMFILE WSAEWOULDBLOCK +i WSAEINPROGRESS WSAEALREADY WSAENOTSOCK WSAEDESTADDRREQ WSAEMSGSIZE WSAEPROTOTYPE +i WSAENOPROTOOPT WSAEPROTONOSUPPORT WSAESOCKTNOSUPPORT WSAEOPNOTSUPP WSAEPFNOSUPPORT +i WSAEAFNOSUPPORT WSAEADDRINUSE WSAEADDRNOTAVAIL WSAENETDOWN WSAENETUNREACH +i WSAENETRESET WSAECONNABORTED WSAECONNRESET WSAENOBUFS WSAEISCONN WSAENOTCONN +i WSAESHUTDOWN WSAETOOMANYREFS WSAETIMEDOUT WSAECONNREFUSED WSAELOOP WSAENAMETOOLONG +i WSAEHOSTDOWN WSAEHOSTUNREACH WSAENOTEMPTY WSAEPROCLIM WSAEUSERS WSAEDQUOT WSAESTALE +i WSAEREMOTE WSASYSNOTREADY WSAVERNOTSUPPORTED WSANOTINITIALISED WSAHOST_NOT_FOUND +i HOST_NOT_FOUND WSATRY_AGAIN TRY_AGAIN WSANO_RECOVERY NO_RECOVERY WSANO_DATA +i NO_DATA WSANO_ADDRESS NO_ADDRESS WM_USER +#endif \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/defs/sym2ijs.ijs @@ -0,0 +1,178 @@ +NB. built from project: source\api\sym2ijs\sym2ijs +NB. sym2ijs +NB. +NB. format: +NB. path sym2ijs name +NB. +NB. e.g. +NB. '\dev\defs\' sym2ijs 'hostdefs' +NB. see doc at end for details + +NB. require 'files strings misc' + +NB. ========================================================= +include1=: 3 : 0 +'#include ', y +) + +NB. ========================================================= +NB. integer +integer1=: 3 : 0 +printf each ;: }. y +) + +NB. ========================================================= +NB. jcode +jcode1=: 3 : 0 +TAB,'puts ("',(2 }. y),'");' +) + +NB. ========================================================= +printf=: 3 : 0 +printf~ y +: +TAB,'printf ("',x,'=: %d\n",(int)',y,');' +) + +NB. ========================================================= +structure1=: 3 : 0 +id=. deb 3 }. 0 pick y +sd=. (7 * 'struct ' -: 7 {. id) }. id +bal=. }. y +msk=. *. /\ ({.&> bal) e. 'f#' +r=. <(sd,'_sz') printf 'sizeof (',id,')' +r=. r, id&structure2 each msk # bal +(< S: 0 r), (-.msk) # bal +) + +NB. ========================================================= +structure2=: 4 : 0 +if. 'f' ~: {. y do. y return. end. +id=. deb 2 }. y +r=. (id,'_off') printf 'offset(',x,',',id,')' +s=. (id,'_sz') printf 'sizeof(((',x,'*)0)->',id,')' +r;s +) + + +NB. ========================================================= +j=. cutopen (0 : 0) rplc '~',TAB +#define offset(r,f) (((char*)&((r*)0)->f)-((char*)((r*)0))) +main(){ +~printf ("NB. do not edit -- created by sym2ijs\n\n"); +~printf ("cocurrent <'jdefs'\n\n"); +) + +SYMTXT=: cutopen j rplc '~',TAB + +bx=: 3 : 'y#i.#y' NB.! +tolist=: 3 : ';y,each LF' NB.! + +NB. ========================================================= +NB. [path] sym2ijs name --- '\dev\defs\' sym2ijs 'netdefs' +NB. reads name.sym and creates name.c +sym2ijs=: 3 : 0 +'' sym2ijs y +: +dat=. 'b' fread jpath x,y,'.sym' +dat=. deb each dat +dat=. (';' ~: {.&> dat) # dat + +NB. split off includes from main: +ndx=. (+. /\. '<' = {.&> dat) i. 0 +hdr=. ndx {. dat +bal=. ndx }. dat +bal=. bal }.~ (bal ~: <'') i. 1 + +NB. includes: +ndx=. bx Q=:'<' = {.&> hdr +hdr=. (include1 each ndx { hdr) ndx } hdr + +NB. structures: +msk=. 1,('t' = {.&> bal) +. (<'st') = 2 {.each bal +bal=. }. < S: 0 msk <@structure1;.1 '';bal + +NB. integers: +ndx=. bx 'i' = {.&> bal +bal=. (integer1 each ndx { bal) ndx } bal +bal=. < S: 0 bal + +NB. J code: +ndx=. bx 'J' = {.&> bal +bal=. (jcode1 each ndx { bal) ndx } bal +bal=. < S: 0 bal + +NB. empties: +ndx=. bx 0 = # &> bal +bal=. (<TAB,'puts("");') ndx } bal + +ftr=. <TAB,'exit (0);',LF,'}' +res=. tolist QQ=: hdr,SYMTXT,bal,ftr +res fwrites x,y,'.c' +) + +doc=: 0 : 0 +sym2ijs - translate C type and constant declarations into J definitions +target_file sym2ijs source_file +for example: 'hostdefs.c' sym2ijs 'hostdefs.sym' + +The original idea and implementation as a shell script and man page were +done by Martin Neitzel. This documentation is based on Martin's man page. + +Converts header definitions given in C into equivalent J definitions. It +expects a compact input format listing the symbols of interest and generates +the corresponding J script defining the same (or closely related) symbols. + +There is no need to figure out C header values or offsets manually or +to hardwire those (usually system-dependent) values. + +The purpose of this tool is portable J code sticking to APIs as defined in +c header files. + +sym2ijs creates an intermediate C language program. This program +is compiled on the target machine and the resulting program, when run, +creates an ijs script with the appropriate J definitions for that target. + +The input file most likely starts with the list of the required include files. + +The first empty line in the input marks the transition from the header +section to the section with various directives. + +Every input line is analyzed according to the character or word at the +beginning of the line. No line may be indented. The rest of the line may +employ arbitrary forms of white space. The following input line formats +are recognized: + +<filename> - include the specified system header file + +"filename" - include the specified local header file. + +first emtpy line - switch from global section in the intermediary C program to the +main() function issuing all the print statements for the values. No header files may +be listed after this line. Other empty lines are preserved in the J script output. + +i symbol ... - integer-typed symbol(s) defined as a C header constants or C variables. +Corresponding assignments to J symbols will be generated. + +t typename - define the (J) symbol typename_sz to have the value of sizeof(typename) . + +st typename - a structure type is introduced, leading to a typename_sz + +st struct structtag - a structure type is introduced, leading to a typename_sz. +The struct keyword has to be used where only this type of defintion is used in +the header file. + +An st line may be followed by f lines for fields in the structure. + +f fieldname - define fieldname_sz and the offset fieldname_off for a member +of the structure + +; comments + +C literal C code + +J literal J code + +# C preprocessor directive - passed to the intermediate C program allowing easy +conditional code. +) \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/copyright.txt @@ -0,0 +1,15 @@ + +JSOFTWARE SOURCES refers to all files in this Jsoftware release +package except for file gpl3.txt. + +JSOFTWARE SOURCES are: +Copyright 1990-2011, Jsoftware Inc. All rights reserved. + +JSOFTWARE SOURCES are: +Licensed under GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +See gpl3.txt for GNU General Public License version 3. +Additional info at http://www.gnu.org/licenses. +
new file mode 100644 --- /dev/null +++ b/docs/gpl3.txt @@ -0,0 +1,621 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS
new file mode 100644 --- /dev/null +++ b/docs/ioj/ioj.htm @@ -0,0 +1,149 @@ +<html> + +<head> +<title>An Implementation of J</title> +</head> + +<body> + +<p align=center> +<font size="6"><b>An Implementation of J</b></font><br> +<font size="5"><b>Roger K.W. Hui</b></font> +</p> +Copyright © 1990-2011, Jsoftware Inc. <br>last updated: 2000-06-23</td> +<br> + +<hr> +<p align=center><font size="5"><b>Preface</b></font></p> +J is a dialect of APL freely available on a wide variety of machines. +It is the latest in the line of development known as "dictionary APL". +The spelling scheme uses the ASCII alphabet. +The underlying concepts, such as arrays, verbs, adverbs, and rank, +are extensions and generalizations of ideas in APL\360. +Anomalies have been removed. +The result is at once simpler and more powerful than previous dialects.<br><br> + +This document describes an implementation of J in C. +The reader is assumed to be familiar with J and C. +J is specified by the +<a href="iojbib.htm#JDictionary"><i>J Dictionary</i></a>, and +introductions to the language are available in +<a href="iojbib.htm#ProgrammingInJ"><i>Programming in J</i></a> and +<a href="iojbib.htm#JPrimer"><i>J Primer</i></a>; +C is described in +<a href="iojbib.htm#CProgrammingLanguage"><i>The C Programming Language</i></a>.<br><br> + +Why "J"? It is easy to type. + +<p align=center><a name="KEI"></a><font size="5"><b>Acknowledgment</b></font></p> +<p align=center><em>Ex ungue leonem</em>.</p> + +<hr> +<br> + +<a name="TOC"></a> +<table align=center> +<caption><font size=5><b>Contents</b></font></caption> +<tr><td> </td> + <td> </td> +</tr> +<tr><td>0. <a href="iojIntro.htm">Introduction</a></td> + <td>6. <a href="iojDisp.htm">Display</a></td> +</tr> +<tr><td> </td> + <td> 6.1 <a href="iojDisp.htm#Numeric">Numeric Display</a></td> +</tr> +<tr><td>1. <a href="iojSent.htm" >Interpreting a Sentence</a></td> + <td> 6.2 <a href="iojDisp.htm#Boxed">Boxed Display</a> </td> +</tr> +<tr><td> 1.1 <a href="iojSent.htm#Word Formation">Word Formation</a></td> + <td> 6.3 <a href="iojDisp.htm#Formatted">Formatted Display</a></td> +</tr> +<tr><td> 1.2 <a href="iojSent.htm#Parsing">Parsing</a></td> + <td> </td> +</tr> +<tr><td> 1.3 <a href="iojSent.htm#Trains">Trains</a></td> + <td>7. <a href="iojComp.htm">Comparatives</a></td> +</tr> +<tr><td> 1.4 <a href="iojSent.htm#Name Resolution">Name Resolution</a></td> + <td> </td> +</tr> +<tr><td> </td> + <td><a href="iojATW.htm">Appendices</a></td> +</tr> +<tr><td>2. <a href="iojNoun.htm">Nouns</a></td> + <td> A. <a href="iojATW.htm">Incunabulum</a></td> +</tr> +<tr><td> 2.1 <a href="iojNoun.htm#Arrays">Arrays</a></td> + <td> B. <a href="iojSp.htm">Special Code</a></td> +</tr> +<tr><td> 2.2 <a href="iojNoun.htm#Types">Types</a></td> + <td> C. <a href="iojTest.htm">Test Scripts</a></td> +</tr> +<tr><td> 2.3 <a href="iojNoun.htm#Memory Management">Memory Management</a> </td> + <td> D. <a href="iojFiles.htm">Program Files</a></td> +</tr> +<tr><td> 2.4 <a href="iojNoun.htm#Global Variables">Global Variables</a></td> + <td> E. <a href="iojXenos.htm">Foreign Conjunction</a></td> +</tr> +<tr><td> </td> + <td> F. <a href="iojSumm.htm">System Summary</a></td> +</tr> +<tr><td>3. <a href="iojVerb.htm">Verbs</a></td> + <td> </td> +</tr> +<tr><td> 3.1 <a href="iojVerb.htm#Anatomy">Anatomy of a Verb</a></td> + <td><a href="iojBib.htm">Bibliography</a></td> +</tr> +<tr><td> 3.2 <a href="iojVerb.htm#Rank">Rank</a></td> + <td><a href="iojIndex.htm">Glossary and Index</a></td> +</tr> +<tr><td> 3.3 <a href="iojVerb.htm#Atomic">Atomic (Scalar) Verbs</a></td> + <td> </td> +</tr> +<tr><td> 3.4 <a href="iojVerb.htm#Obverse">Obverses, Identities, and Variants</a> </td> + <td> </td> +</tr> +<tr><td> 3.5 <a href="iojVerb.htm#Error">Error Handling</a></td> + <td> </td> +</tr> +<tr><td> </td> + <td> </td> +</tr> +<tr><td>4. <a href="iojAdv.htm">Adverbs and Conjunctions</a></td> + <td> </td> +</tr> +<tr><td> </td> + <td> </td> +</tr> +<tr><td>5. <a href="iojRep.htm">Representation</a></td> + <td> </td> +</tr> + <td> 5.1 <a href="iojRep.htm#Atomic">Atomic Representation</a></td> + <td> </td> +</tr> +<tr><td> 5.2 <a href="iojRep.htm#Boxed">Boxed Representation</a></td> + <td> </td> +</tr> +<tr><td> 5.3 <a href="iojRep.htm#Tree">Tree Representation</a></td> + <td> </td> +</tr> +<tr><td> 5.4 <a href="iojRep.htm#Linear">Linear Representation</a></td> + <td> </td> +</tr> +</table> + +<br> +<hr> + +<a href="iojIntro.htm">Next</a> + • +<a href="iojIndex.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html>
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojATW.htm @@ -0,0 +1,83 @@ +<html> + +<head> +<title>An Implementation of J -- Incunabulum</title> +</head> + +<body> + +<p align=center><font size="6"><b>Incunabulum</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +One summer weekend in 1989, Arthur Whitney visited Ken Iverson at +Kiln Farm and produced — on one page and in one afternoon — +an interpreter fragment on the AT&T 3B1 computer. +I studied this interpreter for about a week for its organization +and programming style; and on Sunday, August 27, 1989, at about +four o'clock in the afternoon, wrote the first line of +code that became the implementation described in this document.<br><br> + +Arthur's one-page interpreter fragment is as follows:<br><br> + +<pre> +typedef char C;typedef long I; +typedef struct a{I t,r,d[3],p[2];}*A; +#define P printf +#define R return +#define V1(f) A f(w)A w; +#define V2(f) A f(a,w)A a,w; +#define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}} +I *ma(n){R(I*)malloc(n*4);}mv(d,s,n)I *d,*s;{DO(n,d[i]=s[i]);} +tr(r,d)I *d;{I z=1;DO(r,z=z*d[i]);R z;} +A ga(t,r,d)I *d;{A z=(A)ma(5+tr(r,d));z->t=t,z->r=r,mv(z->d,d,r); + R z;} +V1(iota){I n=*w->p;A z=ga(0,1,&n);DO(n,z->p[i]=i);R z;} +V2(plus){I r=w->r,*d=w->d,n=tr(r,d);A z=ga(0,r,d); + DO(n,z->p[i]=a->p[i]+w->p[i]);R z;} +V2(from){I r=w->r-1,*d=w->d+1,n=tr(r,d); + A z=ga(w->t,r,d);mv(z->p,w->p+(n**a->p),n);R z;} +V1(box){A z=ga(1,0,0);*z->p=(I)w;R z;} +V2(cat){I an=tr(a->r,a->d),wn=tr(w->r,w->d),n=an+wn; + A z=ga(w->t,1,&n);mv(z->p,a->p,an);mv(z->p+an,w->p,wn);R z;} +V2(find){} +V2(rsh){I r=a->r?*a->d:1,n=tr(r,a->p),wn=tr(w->r,w->d); + A z=ga(w->t,r,a->p);mv(z->p,w->p,wn=n>wn?wn:n); + if(n-=wn)mv(z->p+wn,z->p,n);R z;} +V1(sha){A z=ga(0,1,&w->r);mv(z->p,w->d,w->r);R z;} +V1(id){R w;}V1(size){A z=ga(0,0,0);*z->p=w->r?*w->d:1;R z;} +pi(i){P("%d ",i);}nl(){P("\n");} +pr(w)A w;{I r=w->r,*d=w->d,n=tr(r,d);DO(r,pi(d[i]));nl(); + if(w->t)DO(n,P("< ");pr(w->p[i]))else DO(n,pi(w->p[i]));nl();} + +C vt[]="+{~<#,"; +A(*vd[])()={0,plus,from,find,0,rsh,cat}, + (*vm[])()={0,id,size,iota,box,sha,0}; +I st[26]; qp(a){R a>='a'&&a<='z';}qv(a){R a<'a';} +A ex(e)I *e;{I a=*e; + if(qp(a)){if(e[1]=='=')R st[a-'a']=ex(e+2);a= st[ a-'a'];} + R qv(a)?(*vm[a])(ex(e+1)):e[1]?(*vd[e[1]])(a,ex(e+2)):(A)a;} +noun(c){A z;if(c<'0'||c>'9')R 0;z=ga(0,0,0);*z->p=c-'0';R z;} +verb(c){I i=0;for(;vt[i];)if(vt[i++]==c)R i;R 0;} +I *wd(s)C *s;{I a,n=strlen(s),*e=ma(n+1);C c; + DO(n,e[i]=(a=noun(c=s[i]))?a:(a=verb(c))?a:c);e[n]=0;R e;} + +main(){C s[99];while(gets(s))pr(ex(wd(s)));} +</pre> + +<br> +<hr> + +<a href="iojSp.htm">Next</a> + • +<a href="iojComp.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojAdv.htm @@ -0,0 +1,263 @@ +<html> + +<head> +<title>An Implementation of J -- Adverbs and Conjunctions</title> +</head> + +<body> + +<p align=center><font size="6"><b>Adverbs and Conjunctions</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +An adverb is monadic, applying to a noun or verb argument on its <i>left</i>; +a conjunction is dyadic, applying to noun or verb arguments on its +<i>left and right</i>. The result is usually a verb, but can also +be a noun, adverb, or conjunction.<br><br> + +The conjunction<tt> & </tt>is used here to illustrate the relationship +between relevant system components. +(The implementation of adverbs is similar.)<tt> </tt> +<tt>& </tt>derives a verb depending on whether the arguments are +nouns<tt> </tt>(<tt>m </tt>and<tt> n</tt>)<tt> </tt>or +verbs<tt> </tt>(<tt>u </tt>and<tt> v</tt>):<br><br> + +<pre> + m&n <font size=3 face="Times New Roman">gerund join</font> + m&v m&v y <font size=3 face="Times New Roman">is</font> m v y + u&n u&n y <font size=3 face="Times New Roman">is</font> y v n + u&v u&v y <font size=3 face="Times New Roman">is</font> u v y<font size=3 face="Times New Roman">;</font> x u&v y <font size=3 face="Times New Roman">is</font> (v x) u (v y) +</pre> + +A verb defined from<tt> & </tt>is (internally) an <a name="array"></a> +array of type<tt> VERB </tt> +whose value is interpreted according to the defined +type<a name="V"></a><tt> V </tt>in file jtype.h:<br><br> + +<pre> + typedef struct {AF f1,f2;A f,g,h;I flag,mr,lr,rr;C id;} V;</pre> + +<table> +<tr><td> </td> + <td><tt>f1 </tt></td> <td>monad</td> </tr> +<tr><td> </td> <td><tt>f2 </tt></td> <td>dyad </td> </tr> +<tr><td> </td> <td><tt>f </tt></td> <td>left conjunction argument or adverb argument</td> </tr> +<tr><td> </td> <td><tt>g </tt></td> <td>right conjunction argument</td> </tr> +<tr><td> </td> <td><tt>h </tt></td> <td>auxiliary argument</td> </tr> +<tr><td> </td> <td><tt>flag</tt></td> <td>bit flags</td> </tr> +<tr><td> </td> <td><tt>mr </tt></td> <td>monadic rank</td> </tr> +<tr><td> </td> <td><tt>lr </tt></td> <td>left rank</td> </tr> +<tr><td> </td> <td><tt>rr </tt></td> <td>right rank</td> </tr> +<tr><td> </td> <td><tt>id </tt></td> <td><a href="iojSent.htm#ID">ID</a> byte</td> </tr> +</table><br> + +If<tt> fn=: %.&|:</tt>,<tt> </tt>the arrays would be:<br><br> + +<pre> + k flag m t c n r<font face="ISIJ"> + ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂ + fn ³ 28³ 0³ 8³ VERB³ 3³ 1³ 0³... + ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁ + ÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄ¿ + ...³ on1³ on2³ %.³ |:³ 0³ 0³ _³ _³ _³& ³ + ÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÙ</font> + f1 f2 f g h flag mr lr rr id + + k flag m t c n r<font face="ISIJ"> + ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂ + %. ³ 28³ 0³ 8³ VERB³ _³ 1³ 0³... + ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁ + ÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄ¿ + ...³ minv³ mdiv³ 0³ 0³ 0³ 0³ 2³ _³ 2³%. ³ + ÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÙ</font> + f1 f2 f g h flag mr lr rr id + + k flag m t c n r<font face="ISIJ"> + ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂ + |: ³ 28³ 0³ 8³ VERB³ _³ 1³ 0³... + ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁ + ÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄ¿ + ...³cant1³cant2³ 0³ 0³ 0³ 0³ _³ 1³ _³|: ³ + ÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÙ</font> + f1 f2 f g h flag mr lr rr id +</pre> + +Access to the parts of<tt> fn </tt>is by name and by macros defined in files jt.h +and a.h, and <i>never</i> by offsets and indices. +Thus<tt> AV(fn) </tt>points to the value part of<tt> fn</tt>.<tt> </tt> +And if<tt> sv=(V*)AV(fn)</tt>,<tt> </tt> +then<tt> sv->f1 </tt>is<tt> on1</tt>;<tt> </tt> +<tt>sv->f2 </tt>is<tt> on2</tt>;<tt> </tt> +<tt>sv->f </tt>is the array for<tt> %.</tt>;<tt> </tt> +<tt>sv->g </tt>is the array for<tt> |: </tt> +(that is,<tt> sv->f </tt>and<tt> sv->g </tt>are +arrays similar to<tt> fn</tt>);<tt> </tt> +<tt>sv->mr </tt>is<tt> _ </tt>(indicating +that<tt> fn </tt>has infinite monadic rank); and so on. +The macro<tt> <a name="VAV">VAV(f)</a></tt>,<tt> </tt>defined +as<tt> ((V*)AV(f))</tt>,<tt> </tt> +is useful for working with adverbs and conjunctions.<br><br> + +<a name="amp"></a>To introduce<tt> & </tt>into the system, functions which +implement<tt> & </tt>are added +to file c.c (or one of the c*.c files), and declarations of +global objects are added to file je.h:<br> + +<pre> +<font size=3 face="Times New Roman">File c.c:</font> + static CS1(on1, CALL2(f1,CALL2(g1,w,gs),fs)) + static CS2(on2, CALL3(f2,CALL2(g1,a,gs),CALL2(g1,w,gs),fs)) + + static DF1(withl){DECLFG; R jt->rank?irs2(fs,w,gs,AR(fs),jt->rank[1],g2):CALL3(g2,fs,w,gs);} + static DF1(withr){DECLFG; R jt->rank?irs2(w,gs,fs,jt->rank[1],AR(gs),f2):CALL3(f2,w,gs,fs);} + + F2(jtamp){I m; + RZ(a&&w); + switch(CONJCASE(a,w)){ + default: ASSERTSYS(0,"amp"); + case NN: R gjoin(CAMP,a,w); + case NV: R CDERIV(CAMP,withl,0L,RMAX,RMAX,RMAX); + case VN: R CDERIV(CAMP,withr,0L,RMAX,RMAX,RMAX); + case VV: m=mr(w); R CDERIV(CAMP,ID(a)==CSLASH&&ID(w)==CCOMMA?jtredravel:on1,on2,m,m,m); + }} + +<font size=3 face="Times New Roman">File je.h:</font> + extern F2(jtamp); +</pre> + +Corresponding to the four possibilities,<tt> amp </tt>defines +four cases. (The impossible<tt> default </tt>case is to +obviate a spurious C compiler warning.) +The functions<tt> withl</tt>,<tt> withr</tt>,<tt> on1</tt>,<tt> </tt> +and<tt> on2 </tt>are applied when a verb derived from<tt> & </tt>is applied. +The<tt> VV </tt>case also recognizes<tt> u/&, </tt>as a special case, +whereby<tt> redravel </tt>is applied instead of<tt> on1</tt>.<br><br> + +For the example in question,<tt> %.&|: m=: ?4 4$100 </tt>first +branches to the<tt> case VV </tt>in<tt> amp</tt>,<tt> </tt>and +subsequently applies<tt> on1 </tt>to<tt> m</tt>.<tt> </tt> +Consider a partial macro expansion of<tt> on1 </tt>and the +values of its local variables:<br><br> + +<pre> +<font size=3 face="Times New Roman">Macro Expansion:</font> + static A on1(J jt,A w,A self){PROLOG;V*sv=VAV(self); + A fs=sv->f;AF f1=fs?VAV(fs)->f1:0,f2=fs?VAV(fs)->f2:0; + A gs=sv->g;AF g1=gs?VAV(gs)->f1:0,g2=gs?VAV(gs)->f2:0; A z; + PREF1(on1); + z=f1(jt,g1(jt,w,gs),fs); + EPILOG(z); + } +</pre> +Local Variables: +<table> +<tr><td> </td> + <td><tt>w </tt></td> + <td>the matrix<tt> m</tt></td> +</tr> +<tr><td> </td> + <td><tt>self</tt></td> + <td>the verb<tt> fn</tt></td> +</tr> +<tr><td> </td> + <td><tt>sv</tt></td> + <td>pointer to the value part of<tt> fn </tt>as an array</td> +</tr> +<tr><td> </td> + <td><tt>fs</tt></td> + <td>left argument to<tt> &</tt>,<tt> </tt>that is<tt> %.</tt></td> +</tr> +<tr><td> </td> + <td><tt>f1</tt></td> + <td>monad of<tt> %.</tt></td> +</tr> +<tr><td> </td> + <td><tt>f2</tt></td> + <td>dyad of<tt> %.</tt></td> +</tr> +<tr><td> </td> + <td><tt>gs</tt></td> + <td>right argument to<tt> &</tt>,<tt> </tt>that is<tt> |:</tt></td> +</tr> +<tr><td> </td> + <td><tt>g1</tt></td> + <td>monad of<tt> |:</tt></td> +</tr> +<tr><td> </td> + <td><tt>g2</tt></td> + <td>dyad of<tt> |:</tt></td> +</tr> +</table><br> + +The initialization of<tt> sv</tt>,<tt> fs</tt>,<tt> f1</tt>,<tt> </tt> +and so on are the same +for all adverbs and conjunctions; the details of such +initialization are normally suppressed by the use of macros. +If an argument to<tt> & </tt>(<i>i.e.</i><tt> fs </tt>or<tt> gs</tt>) </tt> +is itself a result +of adverbs and conjunctions, expressions such as<tt> g1(jt,w,gs) </tt> +or<tt> f1(jt,xxx,gs) </tt>engender further executions +as occurs in<tt> on1</tt>.<tt> </tt> +The macro<tt> <a name="PREF1">PREF1</a> </tt>implements +<a href="iojVerb.htm#rank">rank</a>, +and the macros<tt> <a href="iojNoun.htm#PROLOG">PROLOG</a> </tt> +and<tt> <a href="iojNoun.htm#EPILOG">EPILOG</a> </tt>manage memory.<br><br> + +The association between<tt> & </tt>and<tt> amp </tt>is established in the +table<tt> <a href="iojVerb.htm#pst">pst</a> </tt> +in file t.c, exactly the way such associations are done for verbs. +In particular,<tt> CAMP </tt>is the ID for<tt> & </tt> +and<tt> ds(CAMP) </tt>is<tt> & </tt>as an array +(that is,<tt> ds(CAMP) </tt> is<tt> &</tt>).<br><br> + +The utilities<tt> <a name="df1">df1</a> </tt> +and<tt> <a name="df2">df2</a> </tt>in file au.c +apply the monad or the dyad +of a verb. For example:<br><br> + +<table> +<tr><td> </td> + <td><tt>ds(CPOUND)</tt></td> + <td><tt>#</tt></td> +</tr> +<tr><td> </td> + <td><tt>ds(COPE)</tt></td> + <td><tt>></tt></td> +</tr> +<tr><td> </td> + <td><tt>amp(ds(CPOUND),ds(COPE))</tt></td> + <td><tt>#&></tt></td> +</tr> + +<tr><td> </td> <td> </td> <td> </td> </tr> + +<tr><td> </td> + <td><tt>df1(w,ds(CPOUND))</tt></td> + <td><tt># w</tt></td> +</tr> +<tr><td> </td> + <td><tt>df1( w,amp(ds(CPOUND),ds(COPE)))</tt></td> + <td><tt>#&> w</tt></td> +</tr> +<tr><td> </td> + <td><tt>df2(a,w,amp(ds(CPOUND),ds(COPE))) </tt></td> + <td><tt>a #&> w</tt></td> +</tr> +</table><br> + +<br> +<hr> + +<a href="iojRep.htm">Next</a> + • +<a href="iojVerb.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojBib.htm @@ -0,0 +1,144 @@ +<html> + +<head> +<title>An Implementation of J -- Bibliography</title> +</head> + +<body> + +<p align=center><font size="6"><b>Bibliography</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +Abramowitz, M. and I.A. Stegun, <i>Handbook of Mathematical Functions</i>, +National Bureau of Standards, 1964 6.<br><br> + +<a name="Bernecky"></a><a name="Bernecky1977"></a>Bernecky, R., <i>Comparison Tolerance</i>, SHARP APL Technical Notes 23, +1977 6 10.<br><br> + +Bernecky, R., <i>An Introduction to Function Rank</i>, APL88, +APL Quote-Quad Volume 18, Number 2, 1987 12.<br><br> + +Bernecky, R., and R.K.W. Hui, <i>Gerunds and Representations</i>, APL91, +APL Quote-Quad, Volume 21, Number 4, 1991 8.<br><br> + +Bernecky, R., and K.E. Iverson, <i>Operators and Enclosed Arrays</i>, +1980 APL User's Meeting Conference Proceedings, 1980 10 6.<br><br> + +Bernecky, R., K.E. Iverson, E.E. McDonnell, +R.C. Metzger, and J.H. Schueler, +<i>Language Extensions of May 1983</i>, SHARP APL Technical Note 45, +I.P. Sharp Associates, 1983 5 2.<br><br> + +<a name="PCB"></a>Berry, P.C., <i>SHARP APL Reference Manual</i>, I.P. Sharp Associates, +1979 3; Additions and Corrections, 1981 6.<br><br> + +<a name="Burke"></a>Burke, C., R.K.W. Hui, K.E. Iverson, E.E. McDonnell, and D.B. McIntyre, +<i>J Phrases</i>, Iverson Software Inc., 1996.<br><br> + +<a name="Falkoff"></a>Falkoff, A.D., and K.E. Iverson, <i>APL\360 User's Manual</i>, IBM Corporation, +1968 8.<br><br> + +Falkoff, A.D., and K.E. Iverson, <i>The Design of APL</i>, IBM Journal +of Research and Development, Volume 17, Number 4, 1973 7.<br><br> + +Falkoff, A.D., and K.E. Iverson, <i>The Evolution of APL</i>, +ACM SIGPLAN Notices, Volume 13, Number 8, 1978 8.<br><br> + +Hodgkinson, R., <i>APL Procedures</i>, APL86, +APL Quote-Quad 16.4, 1986 7.<br><br> + +<a name="Hui87"></a>Hui, R.K.W., <i>Some Uses of { and }</i>, APL87, APL Quote-Quad, +Volume 17, Number 4, 1987 5.<br><br> + +Hui, R.K.W., <i>An Implementation of J</i>, Iverson Software Inc., +1992 1 27.<br><br> + +<a name="Hui95"></a>Hui, R.K.W., <i>Rank and Uniformity</i>, APL95, APL Quote-Quad, +Volume 25, Number 4, 1995 6.<br><br> + +<a name="JDictionary"></a>Hui, R.K.W., and Iverson, K.E., +<i>J Introduction and Dictionary</i>, Iverson Software Inc., 1998.<br><br> + +Hui, R.K.W., K.E. Iverson, and E.E. McDonnell, <i>Tacit Definition</i>, +APL91, APL Quote-Quad, Volume 21, Number 4, 1991 8.<br><br> + +<a name="EEM"></a>Hui, R.K.W., K.E. Iverson, E.E. McDonnell, and A.T. Whitney, +<i>APL\?</i>, APL90, APL Quote-Quad, Volume 20, Number 4, 1990 7.<br><br> + +<a name="EBI"></a><a name="JPrimer"></a>Iverson, E.B., <i>J Primer</i>, Iverson Software Inc., 1996.<br><br> + +Iverson, K.E., <i>A Programming Language</i>, Wiley, 1962 5.<br><br> + +Iverson, K.E., <i>Operators and Functions</i>, Research Report #RC7091, +IBM Corporation, 1978 4 26.<br><br> + +Iverson, K.E., <i>Notation as a Tool of Thought</i>, Communications +of the ACM, Volume 23, Number 8, 1980 8.<br><br> + +<a name="Iverson1983"></a>Iverson, K.E., <i>Rationalized APL</i>, I.P. Sharp Associates Limited, +1983 1 6.<br><br> + +Iverson, K.E., <i>APL87</i>, APL87, APL Quote-Quad, +Volume 17, Number 4, 1987 5.<br><br> + +Iverson, K.E., <i>A Dictionary of APL</i>, APL Quote-Quad, +Volume 18, Number 1, 1987 9.<br><br> + +Iverson, K.E., <i>A Personal View of APL</i>, +IBM Systems Journal, Volume 30, Number 4, 1991 12.<br><br> + +Iverson, K.E., <i>Arithmetic</i>, Iverson Software Inc., 1991.<br><br> + +<a name="ProgrammingInJ"></a>Iverson, K.E., <i>Programming in J</i>, +Iverson Software Inc., 1991.<br><br> + +Iverson, K.E., <i>Tangible Math</i>, Iverson Software Inc., 1991.<br><br> + +<a name="Iverson1989"></a>Iverson, K.E., and E.E. McDonnell, <i>Phrasal Forms</i>, APL89, APL Quote-Quad, +Volume 19, Number 4, 1989 8.<br><br> + +Iverson, K.E., and A.T. Whitney, <i>Practical Uses of a Model of APL</i>, +APL82, APL Quote-Quad, Volume 13, Number 1, 1982 9.<br><br> + +Keenan, D.J., <i>Operators and Uniform Forms</i>, APL79, +APL Quote-Quad, Volume 9, Number 4, 1979 6.<br><br> + +<a name="CProgrammingLanguage"></a>Kernighan, B.W., and D.M. Ritchie, +<i>The C Programming Language</i>, Prentice-Hall, 1978.<br><br> + +McDonnell, E.E. and J.O. Shallit, <i>Extending APL to Infinity</i>, +APL80, North-Holland Publishing Company, 1980.<br><br> + +McIntyre, D.B., <i>Mastering J</i>, +APL91, APL Quote-Quad, Volume 21, Number 4, 1991 8.<br><br> + +<a name="McIntyre"></a>McIntyre, D.B., <i>Language as an Intellectual Tool: +From Hieroglyphics to APL</i>, +IBM Systems Journal, Volume 30, Number 4, 1991 12.<br><br> + +Pesch, R.H., <i>Empty Frames in Sharp APL</i>, APL86, +APL Quote-Quad, Volume 16, Number 4, 1986 7.<br><br> + +Steinbrook, D.H., <i>SAX Reference</i>, +I.P. Sharp Associates, 1986.<br><br> + +Whitney, A.T., <i>A</i>, plenary session, APL89, 1989 8.<br><br> + +Whitney, A.T., private communication, Kiln Farm, 1992 5 24.<br><br> +<br> +<hr> + +<a href="iojGloss.htm">Next</a> + • +<a href="iojSumm.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html>
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojComp.htm @@ -0,0 +1,214 @@ +<html> + +<head> +<title>An Implementation of J -- Comparatives</title> +</head> + +<body> + +<p align=center><font size="6"><b>Comparatives</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +Comparisons between finite numbers are <i>tolerant</i>, as defined in +<a href="iojBib.htm#Bernecky1977">Bernecky</a> [1977]:<br><br> + +<tt> x = y </tt>if<tt> (|x-y) <:!.0 ct * (|x)>.(|y)</tt> +<br><br> + +(<tt><:!.0 </tt>means <i>exact</i> less than or equal.) +That is,<tt> x </tt>and<tt> y </tt>are tolerantly equal if the smaller +is on or within the circle centered at the larger, having +radius<tt> ct </tt>times the magnitude of the +larger.<a name="tolerance"></a><tt> ct</tt>,<tt> </tt>comparison tolerance, +is a real number between<tt> 0 </tt>and<tt> 2^_34 </tt>with a default value +of<tt> 2^_44</tt>;<tt> </tt>a non-default tolerance may be specified +using the <i><a href="iojVerb.htm#fit">fit</a></i> conjunction +(<tt>!.</tt>).<tt> </tt>Tolerant relations can be modelled as follows:<br><br> + +<table> + +<tr> +<td> </td> +<td><tt>ct</tt></td> +<td><tt>=: </tt></td> +<td><tt>2^_44</tt></td> +<td>comparison tolerance</td> +</tr> + +<tr> +<td> </td> +<td><tt>teq</tt></td> +<td><tt>=: </tt></td> +<td><tt>|@- <:!.0 ct&*@>.&|</tt></td> +<td>equal</td> +</tr> + +<tr> +<td> </td> +<td><tt>tne</tt></td> +<td><tt>=: </tt></td> +<td><tt>-.@teq</tt></td> +<td>not equal</td> +</tr> + +<tr> +<td> </td> +<td><tt>tlt</tt></td> +<td><tt>=: </tt></td> +<td><tt>< !.0 *. tne</tt></td> +<td>less than</td> +</tr> + +<tr> +<td> </td> +<td><tt>tgt</tt></td> +<td><tt>=: </tt></td> +<td><tt>> !.0 *. tne</tt></td> +<td>greater than</td> +</tr> + +<tr> +<td> </td> +<td><tt>tle</tt></td> +<td><tt>=: </tt></td> +<td><tt><:!.0 +. teq</td> +<td>less than or equal to</td> +</tr> + +<tr> +<td> </td> +<td><tt>tge</tt></td> +<td><tt>=: </tt></td> +<td><tt>>:!.0 +. teq</td> +<td>greater than or equal to</td> +</tr> + +<tr> +<td> </td> +<td><tt>tfloor</tt></td> +<td><tt>=: </tt></td> +<td><tt><.!.0@(0.5&+) ([ - tgt) ] </td> +<td>floor</td> +</tr> + +<tr> +<td> </td> +<td><tt>tceil</tt></td> +<td><tt>=: </tt></td> +<td><tt><.!.0@(0.5&+) ([ + tlt) ]</td> +<td>ceiling</td> +</tr> + +<tr> +<td> </td> +<td><tt>dsignum</tt></td> +<td><tt>=: </tt></td> +<td><tt>ct&<@| * 0&< - 0&></td> +<td>signum (real)</td> +</tr> + +<tr> +<td> </td> +<td><tt>jsignum</tt></td> +<td><tt>=: </tt></td> +<td><tt>ct&<@| * (%|)</td> +<td>signum (complex)</td> +</tr> + +</table> +<br> + +Additionally, some comparisons internal to the system are <i>fuzzy</i>. +Fuzzy comparisons are like tolerant comparisons, but depend on the +parameter<a name="fuzz"></a><tt> fuzz</tt>,<tt> </tt>having fixed +value<tt> 2^_44</tt>.<tt> </tt>Such comparisons are used in +certain domain tests; for example,<tt> (2 3+1e_14)$'abc' </tt>is valid +but<tt> (2 3+1e_12)$'abc' </tt>is not. Fuzzy comparisons can be +modelled as follows:<br><br> + +<table> + +<tr> +<td> </td> +<td><tt>fuzz</tt></td> +<td><tt>=:</tt></td> +<td><tt>2^_44</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>int</tt></td> +<td><tt>=:</tt></td> +<td><tt>(-2^31)&<: *. <&(2^31)</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>real</tt></td> +<td><tt>=:</tt></td> +<td><tt>{.@+.</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>feq</tt></td> +<td><tt>=:</tt></td> +<td><tt>|@- <:!.0 fuzz&*@>.&|</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>freal</tt></td> +<td><tt>=:</tt></td> +<td><tt>>:!.0 / @: ((fuzz,1)&*) @: | @: +.</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>BfromD</tt></td> +<td><tt>=:</tt></td> +<td><tt>]`(1&=) @. (feq 1&=)</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>IfromD</tt></td> +<td><tt>=:</tt></td> +<td><tt>]`<. @. (int *. (feq <.))</tt></td> +</tr> + +<tr> +<td> </td> +<td><tt>DfromZ </tt></td> +<td><tt>=:</tt></td> +<td><tt>]`real @. (feq real)</tt></td> +</tr> + +</table> +<br> + +The utility<tt> int </tt>tests for membership in the +interval<tt> -2^31 </tt>to<tt> _1+2^31 </tt>inclusive.<tt> real </tt>produces +the real part of a complex number.<tt> feq </tt>is 1 if its arguments +are equal within fuzz;<tt> freal </tt>is 1 if its complex argument is within +fuzz of real.<tt> BfromD</tt>,<tt> IfromD</tt>,<tt> </tt>and<tt> DfromZ </tt>convert +between types: boolean from real ("double"), integer from real, and real +from complex.<br><br> + +<br> +<hr> + +<a href="iojATW.htm">Next</a> + • +<a href="iojDisp.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojDisp.htm @@ -0,0 +1,341 @@ +<html> + +<head> +<title>An Implementation of J -- Display</title> +</head> + +<body> + +<p align=center><font size="6"><b>Display</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<a href="#Numeric" >Numeric Display</a><br> +<a href="#Boxed" >Boxed Display</a><br> +<a href="#Formatted">Formatted Display</a><br> +<br> + +<hr> +<br> + +If the last operation in a line of user input is not assignment, +the result of the line is displayed. More specifically, if the global +variable<tt> <a name="asgn">asgn</a> </tt>is zero at the end of +executing an input line, +and the line had no errors,<tt> jpr </tt>is invoked to display the +result.<tt> jpr </tt>first applies<tt> thorn1 </tt>(the monad<tt> ":</tt>)<tt> </tt> +to compute the <i>display</i> of<tt> y</tt>,<tt> </tt>then writes the +lines to the screen.<br><br> + +In all cases, the display of an object is a literal array. +The display of a literal array is itself. The display of a +verb, adverb, or conjunction is that of the currently +selected <a href="iojRep.htm">representation(s)</a>. +The display of a <a href="#Numeric">numeric</a> array, that of a +<a href="#Boxed">boxed</a> array, and +<i><a href="#Formatted">format</a></i> are now discussed.<br><br> + +Display is implemented by functions and variables in the files +f.c and f2.c.<br><br> +<br> + +<a name="Numeric"></a><font size="5"><b>Numeric Display</b></font><br><br> + +The display of a numeric array<tt> y </tt>is a literal array +having the same rank as<tt> y </tt>(but at least one), such that the shape +of<tt> ":y </tt>matches the shape of<tt> y </tt>in all but the last axis. +Columns are right-justified and are separated by one space. +The conversion from numeric to literal can be modelled as follows:<br> + +<pre> +sprintf =: ": +real =: {.@+. +imag =: {:@+. + +minus =: $&'_'@('-'&=@{.) +ubar =: >@({&(<;._1 ' _ _ _. _.'))@('iInN'&i.@{.) +afte =: minus , (i.&0@(e.&'-+0') }. ]) +efmt =: >:@(i.&'e') ({. , afte@}.) ] +finite =: ]`efmt@.('e'&e.) +massage =: finite`ubar@.(e.&'iInN'@{.) +fmtD =: (minus,massage@(e.&'-+'@{.}.])) @ sprintf + +cleanZ =: (* ] >&| (2^_44)"_ * |.)&.+. +fmtZ1 =: fmtD@real , 'j'&,@fmtD@imag`(''"_)@.(0&=@imag) +fmtZ =: fmtZ1 @ cleanZ + +fmtB =: {&'01' +fmtI =: sprintf +fmt =: (fmtB&.>)`(fmtI&.>)`(fmtD&.>)`(fmtZ&.>) @. (1 4 8&i.@(3!:0)) + +sh =: (*/@}:,{:@(1&,))@$ ($,) ] +width =: (<:@{. 0} ])@:>:@(>./)@sh@:(#&>) +th =: (-@width ;@:({.&.>)"1 ]) @ fmt +</pre> + +The model is divided into groups of verbs. The first group +are utilities:<br><br> + +<tt>sprintf </tt>a function in the C library<br> +<tt>type </tt>type<br> +<tt>real </tt>the real part of a complex number<br> +<tt>imag </tt>the imaginary part of a complex number<br><br> + +<tt>fmtD </tt>formats a real number. Its constituents transform the result +of<tt> sprintf </tt>to follow J conventions in the treatment of negative +signs<tt> </tt>(<tt>minus</tt>),<tt> </tt>exponential +notation<tt> </tt>(<tt>efmt </tt>and<tt> afte</tt>),<tt> </tt>and +infinities and indeterminates<tt> </tt>(<tt>ubar</tt>).<br><br> + +<tt>fmt </tt>formats a numeric array into an array of boxed strings. +It invokes formatters specialized for the different types:<tt> fmtB </tt> +(Boolean),<tt> fmtI </tt>(integer),<tt> fmtD </tt>(floating point), +and<tt> fmtZ </tt>(complex).<br><br> + +<tt>sh </tt>shapes an array into a table having the same number +of rows.<tt> width </tt>computes the maximum width in each column +of an array of boxed strings.<tt> th </tt>is a model of<tt> ": </tt> +on numeric arrays.<br><br> + +<br> + +<a name="Boxed"></a><p><font size="5"><b>Boxed Display</b></font><br><br> + +The display of a boxed array<tt> b </tt>is a literal array<tt> d=:":b </tt> +such that:<br> + • The rank of<tt> d </tt>is the greater of 2 or the rank of<tt> b</tt>.<br> + • Excluding the last two axes, the shape of<tt> d </tt>matches +the shape of<tt> b</tt>.<br> + • The frame (formed by<font size=2 face="ISIJ"> Ú Â ¿Ã Å ´À Á Ù ³ Ä</font>) +is the same in all the planes.<br><br> + +Boxed display can be modelled as follows:<br> + +<pre> +boxed =: 32&= @ (3!:0) +mt =: 0&e.@$ +boxc =: {. 9!:6 '' +tcorn =: 2 0{boxc +tint =: 1 10{boxc +bcorn =: 8 6{boxc +bint =: 7 10{boxc + +sh =: (*/@}: , {:)@(1&,)@$ $ , +rows =: */\.@}:@$ +bl =: }.@(,&0)@(+/)@(0&=)@(|/ i.@{.@(,&1)) +mask =: 1&,. #&, ,.&0@>:@i.@# +mat =: mask@bl@rows { ' '&,@sh + +edge =: ,@(1&,.)@[ }.@# +:@#@[ $ ] +left =: edge&(3 9{boxc)@>@(0&{)@[ , "0 1"2 ] +right =: edge&(5 9{boxc)@>@(0&{)@[ ,~"0 1"2 ] +top =: 1&|.@(tcorn&,)@(edge&tint)@>@(1&{)@[ ,"2 ] +bot =: 1&|.@(bcorn&,)@(edge&bint)@>@(1&{)@[ ,"2~ ] +perim =: [ top [ bot [ left [ right ] + +topleft =: (4{boxc)&((<0 0)}) @ ((_2{boxc)&,.) @ ((_1{boxc)&,) +inside =: 1 1&}. @ ; @: (,.&.>/"1) @: (topleft&.>) +take =: [ {. ]`(]&' ')@.mt@] +frame =: [ perim {@[ inside@:(take&.>)"2 ,:^:(1&=@#@$)@] +rc =: (>./@sh&.>) @: (,.@|:"2@:(0&{"1);1&{"1) @: ($&>) + +thorn1 =: ":`thbox @. boxed +thbox =: (rc frame ]) @: (mat@thorn1&.>) +</pre> + +The model is divided into groups of definitions (which are verbs +unless indicated otherwise). The first group are utilities:<br><br> + +<tt>boxed </tt>1 if boxed<br> +<tt>mt </tt>1 if empty<br> +<tt>boxc </tt>(noun) box drawing characters<br> +<tt>tcorn </tt>(noun) the characters<font size=2 face="ISIJ"> ¿ Ú</font><br> +<tt>tint </tt>(noun) the characters<font size=2 face="ISIJ">  Ä</font><br> +<tt>bcorn </tt>(noun) the characters<font size=2 face="ISIJ"> Ù À</font><br> +<tt>bint </tt>(noun) the characters<font size=2 face="ISIJ"> Á Ä</font><br> +<br> + +<tt>mat </tt>is the main verb of the next group of definitions. +The argument is a literal array; the result is a literal matrix image of +the array — a literal table that "looks like" the argument array.<br><br> + +<tt>perim </tt>draws a perimeter around each plane of the right argument: +According to the information in the left argument (a result +of<tt> rc</tt>),<tt> perim </tt>puts +<font size=2 face="ISIJ"> ¿ Ú Â Ä </font>(<tt>top</tt>), +<font size=2 face="ISIJ"> Ù À Á Ä </font>(<tt>bot</tt>), +<font size=2 face="ISIJ"> à ³ </font>(<tt>left</tt>), or +<font size=2 face="ISIJ"> ´ ³ </font>(<tt>right</tt>) at +appropriate positions on the perimeter of each plane.<br><br> + +<tt>topleft </tt>catenates the characters<font size=2 face="ISIJ"> Å ³ Ä </font> +on the top and left edges of a literal table.<tt> inside </tt>produces +the inside (excluding perimeter) of a plane of the display.<tt> take </tt> +is<tt> {. </tt>if the right argument is non-empty, and is an array +of blanks otherwise.<tt> frame </tt>applies to an array of boxed tabular +displays, and computes the overall display.<tt> rc </tt>computes the +number of rows and columns in the display of atoms in a plane.<br><br> + +<tt>thorn1 </tt>models<tt> ":</tt>;<tt> thbox </tt>models<tt> ": </tt>on +a boxed array.<br><br> + +The following examples illustrate the inner workings of the model:<br> +<pre> + y=: 2 3$(i.2 3);'abc';(i.4 1);(<2 2$'ussr');12;<+&.>i.2 2 3 + x=: mat@thorn1&.>y + + $&.> x rc x { rc x<font size=2 face="ISIJ"> +ÚÄÄÄÂÄÄÄÂÄÄÄÄ¿ ÚÄÄÄÄÂÄÄÄÄÄ¿ ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿ +³2 5³1 3³4 1 ³ ³4 11³5 3 9³ ³4 5 ³4 3 ³4 9 ³ +ÃÄÄÄÅÄÄÄÅÄÄÄÄ´ ÀÄÄÄÄÁÄÄÄÄÄÙ ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´ +³4 4³1 2³11 9³ ³11 5³11 3³11 9³ +ÀÄÄÄÁÄÄÄÁÄÄÄÄÙ ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ</font> + + a =: 2 3 4 $ 'abcdefghijklmnopqrstuvwx' + + a mat a $a +abcd abcd 2 3 4 +efgh efgh +ijkl ijkl $ mat a + 7 4 +mnop mnop +qrst qrst +uvwx uvwx + + + topleft 3 4$'a'<font size=2 face="ISIJ"> +ÅÄÄÄÄ +³aaaa +³aaaa +³aaaa</font> + (2 3;4 5) perim 6 10$'a'<font size=2 face="ISIJ"> +ÚÄÄÄÄÂÄÄÄÄÄ¿ +³aaaaaaaaaa³ +³aaaaaaaaaa³ +Ãaaaaaaaaaa´ +³aaaaaaaaaa³ +³aaaaaaaaaa³ +³aaaaaaaaaa³ +ÀÄÄÄÄÁÄÄÄÄÄÙ</font> + + ] t=: ({rc x) inside@:(take&.>)"2 x<font size=2 face="ISIJ"> +0 1 2³abc³0 +3 4 5³ ³1 + ³ ³2 + ³ ³3 +ÄÄÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄ +ÚÄÄ¿ ³12 ³ÚÄÂÄÄÂÄÄ¿ +³us³ ³ ³³0³1 ³2 ³ +³sr³ ³ ³ÃÄÅÄÄÅÄÄ´ +ÀÄÄÙ ³ ³³3³4 ³5 ³ + ³ ³ÀÄÁÄÄÁÄÄÙ + ³ ³ + ³ ³ÚÄÂÄÄÂÄÄ¿ + ³ ³³6³7 ³8 ³ + ³ ³ÃÄÅÄÄÅÄÄ´ + ³ ³³9³10³11³ + ³ ³ÀÄÁÄÄÁÄÄÙ</font> + (rc x) perim t<font size=2 face="ISIJ"> +ÚÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄ¿ +³0 1 2³abc³0 ³ +³3 4 5³ ³1 ³ +³ ³ ³2 ³ +³ ³ ³3 ³ +ÃÄÄÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄ´ +³ÚÄÄ¿ ³12 ³ÚÄÂÄÄÂÄÄ¿³ +³³us³ ³ ³³0³1 ³2 ³³ +³³sr³ ³ ³ÃÄÅÄÄÅÄÄ´³ +³ÀÄÄÙ ³ ³³3³4 ³5 ³³ +³ ³ ³ÀÄÁÄÄÁÄÄÙ³ +³ ³ ³ ³ +³ ³ ³ÚÄÂÄÄÂÄÄ¿³ +³ ³ ³³6³7 ³8 ³³ +³ ³ ³ÃÄÅÄÄÅÄÄ´³ +³ ³ ³³9³10³11³³ +³ ³ ³ÀÄÁÄÄÁÄÄÙ³ +ÀÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÙ</font> +</pre> +<br> + +<a name="Formatted"></a><p><font size="5"><b>Formatted Display</b></font><br><br> + +<tt>x":y </tt> is a literal representation of<tt> y </tt>specified +by<tt> x</tt>.<tt> </tt>Positive elements of<tt> x </tt>specify +fixed-point notation, while negative +elements specify exponential notation. The left and right ranks are one; +that is, lists in the arguments are independently formatted. +The computation can be modelled as follows:<br> + +<pre> +fmtexp =: {&'++-'@* , _3&{.@('00'&,)@":@| +cexp =: >:@(i.&'e') ({. , fmtexp@".@}.) ] +cminus =: '-'&((e.&'_' # i.@#)@]}) +larg =: (+_20&*@(0&=))@-@(1&|)@|@".@(-.&' %e') +nsprintf =: larg@[ cexp@cminus@":"1 ] +psprintf =: ".@(-.&' %f')@[ ($&' '@(0&=)@<.@[ , cminus@":"1) ] +sprintf =: nsprintf`psprintf@.('f'&e.@[) + +wd =: <.@| +npstr =: ' %- '&,@(,&'e')@(0.1&":)@(-1&<)@| +ppstr =: *@wd }. ' %'&,@(,&'f')@(0.1&":) +pstr =: npstr`ppstr@.(0&<:) + +jexp =: >:@(i.&'e') ({. , ":@".@(-.&' +')@}.) ] +jminus =: '_'&((e.&'-' # i.@#)@]}) +stars =: ]`{.@.(*@[)`($&'*'@[)@.(*@[*.(<#)) +c2j =: stars ]`jexp@.('e'&e.)@jminus + +lb =: (0&=@wd *. 0&<:)@{. +thcell =: (wd@[ <@c2j pstr@[ sprintf ])"0 +thorn2 =: (lb@[ }. ;@:thcell) " 1 +</pre> + +The model is divided into groups of verbs.<br><br> + +<tt>sprintf </tt>is a limited model of<tt> sprintf </tt>in the C library, +applying to a string containing a single<tt> %e </tt>or<tt> %f </tt>conversion +specification and to a single number. +Thus, if<tt> embrace=:('{'&,)@(,&'}')</tt>,<tt> </tt>then:<br> +<pre> + embrace ' %0.3f' sprintf ^5 { 148.413} + embrace '%9.3f' sprintf ^_5 { 0.007} + embrace ' %- 0.3e' sprintf ^_5 { 6.738e-003} + embrace ' %- 9.3e' sprintf -^5 { -1.484e+002} + embrace ' %- 6.3e' sprintf -^_5 { -6.738e-003} +</pre> +<tt>pstr </tt>applies to the left argument of<tt> ": </tt>and produces +the necessary left argument to<tt> sprintf</tt>.<tt> </tt>For example: +<pre> + x embrace pstr x + + _12 { %- 11.0e} + _7.3 { %- 6.3e} + _0.3 { %- 0.3e} + 0 { %0.0f} + 0.3 { %0.3f} + 7.3 {%7.3f} + 12 {%12.0f} +</pre> +<tt>c2j </tt>and its constituents transform the result of<tt> sprintf </tt> +to follow J conventions, in the treatment of signs (<tt>jminus</tt>), +exponential notation (<tt>jexp</tt>), and overflow (<tt>stars</tt>).<br><br> + +<tt>thorn2 </tt>is a model of the dyad<tt> ":</tt>.<tt> </tt>It works by +applying<tt> thcell </tt>to corresponding atoms of the arguments, +producing a list of boxes; the leading blank of the razed result is then +dropped or not, according to the value of<tt> lb </tt>on +the left argument.<br><br> + +<br> +<hr> + +<a href="iojComp.htm">Next</a> + • +<a href="iojRep.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojFiles.htm @@ -0,0 +1,179 @@ +<html> + +<head> +<title>An Implementation of J -- Program Files</title> +</head> + +<body> + +<p align=center><font size="6"><b>Program Files</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> +<dl> +<dt> j.h <dd> Global Definitions +<dt> ja.h <dd> Aliases for jt +<dt> jc.h <dd> Character Definitions +<dt> je.h <dd> Extern Declarations +<dt> jerr.h <dd> Error Codes +<dt> js.h <dd> SYS_ and friends +<dt> jt.h <dd> Definitions for jt +<dt> jtype.h <dd> Type Definitions +</dl> +<dl> +<dt> a.h <dd> Adverbs: Macros and Defined-Constants (for Adverbs and Conjunctions) +<dt> a.c <dd> Adverbs +<dt> af.c <dd> Adverbs: Fix +<dt> ai.c <dd> Adverbs: Inverse & Identity Functions +<dt> aicap.c <dd> Adverbs: I. +<dt> am.c <dd> Adverbs: Amend +<dt> am1.c <dd> Adverbs: a ind}z where z is sparse and ind is box a0;a1;a2;... +<dt> amn.c <dd> Adverbs: a ind}z where z is sparse and ind is <"1 integers +<dt> ao.c <dd> Adverbs: Oblique and Key +<dt> ap.c <dd> Adverbs: Prefix and Infix +<dt> ar.c <dd> Adverbs: Reduce (Insert) and Outer Product +<dt> as.c <dd> Adverbs: Suffix and Outfix +<dt> au.c <dd> Adverbs: Utilities +</dl> +<dl> +<dt> c.c <dd> Conjunctions +<dt> ca.c <dd> Conjunctions: Atop and Ampersand +<dt> cc.c <dd> Conjunctions: Cuts +<dt> cd.c <dd> Conjunctions: Differentiation and Integration +<dt> cf.c <dd> Conjunctions: Forks +<dt> cg.c <dd> Conjunctions: Gerunds ` and `: +<dt> ch.c <dd> Conjunctions: Hypergeometric Series +<dt> cl.c <dd> Conjunctions: L: and S: +<dt> cp.c <dd> Conjunctions: Power Operator ^: and Associates +<dt> cr.c <dd> Conjunctions: Rank Associates +<dt> crs.c <dd> Conjunctions: Rank on Sparse Arrays +<dt> ct.c <dd> Conjunctions: Taylor's Series +<dt> cu.c <dd> Conjunctions: Under and Each +<dt> cv.c <dd> Conjunctions: Variants (!.) +<dt> cx.c <dd> Conjunctions: Explicit Definition : and Associates +</dl> +<dl> +<dt> d.c <dd> Debug: Error Display +<dt> dc.c <dd> Debug: Function Call Information +<dt> ds.c <dd> Debug: Stops and Suspensions +</dl> +<dl> +<dt> f.c <dd> Format: ": Monad +<dt> f2.c <dd> Format: ": Dyad +</dl> +<dl> +<dt> io.h <dd> Input/Output +<dt> i.c <dd> Initializations +<dt> io.c <dd> Input/Output +</dl> +<dl> +<dt> j.c <dd> main(), Main Loop, & Global Variables +</dl> +<dl> +<dt> k.c <dd> Conversions Amongst Internal Types +</dl> +<dl> +<dt> m.h <dd> Memory Management +<dt> m.c <dd> Memory Management +<dt> mbx.c <dd> Memory-Mapped Boxed Arrays +</dl> +<dl> +<dt> p.h <dd> Parsing: Macros and Defined Constants +<dt> p.c <dd> Parsing; see APL Dictionary, pp. 12-13 & 38. +<dt> pc.c <dd> Parsing: Tacit Adverb/Conjunction Translator (11 : and 12 : ) +<dt> pt.c <dd> Parsing: Trace +<dt> pv.c <dd> Parsing: Tacit Verb Translator (13 : ) +<dt> px.c <dd> Execute and Associates +</dl> +<dl> +<dt> r.c <dd> Representations: Atomic, Boxed, and 5!:0 +<dt> rl.c <dd> Representations: Linear and Paren +<dt> rt.c <dd> Representations: Tree +</dl> +<dl> +<dt> s.c <dd> Symbol Table +<dt> sc.c <dd> Symbol Table: Function Call (unquote) +<dt> sl.c <dd> Symbol Table: Locales +<dt> sn.c <dd> Symbol Table: Names +</dl> +<dl> +<dt> t.c <dd> Table of Primitive Symbols +</dl> +<dl> +<dt> u.c <dd> Interpreter Utilities +</dl> +<dl> +<dt> va.h <dd> Verbs: Macros and Defined Constants for Atomic (Scalar) Verbs +<dt> vasm.h <dd> Verbs: Assembly Routines for Integer + * - with Overflow +<dt> ve.h <dd> Atomic Verbs +<dt> vq.h <dd> Rational Numbers +<dt> vx.h <dd> Extended Precision +<dt> vz.h <dd> Complex Numbers +<dt> v.c <dd> Verbs +<dt> v0.c <dd> Verbs: Polynomial Roots & Polynomial Evaluation +<dt> v1.c <dd> Verbs: Match Associates +<dt> v2.c <dd> Verbs: Primes and Factoring +<dt> va1.c <dd> Verbs: Monadic Atomic +<dt> va2.c <dd> Verbs: Atomic (Scalar) Dyadic +<dt> va2s.c <dd> Verbs: Atomic (Scalar) Dyadic Verbs on Sparse Arrays +<dt> vb.c <dd> Verbs: Boolean-Valued +<dt> vbang.c <dd> Verbs: ! +<dt> vcant.c <dd> Verbs: Transpose +<dt> vcat.c <dd> Verbs: Catenate and Friends +<dt> vcomp.c <dd> Verbs: Comparatives +<dt> vd.c <dd> Verbs: Domino +<dt> ve.c <dd> Verbs: Elementary Functions (Arithmetic, etc.) +<dt> vf.c <dd> Verbs: Fill-Dependent Verbs +<dt> vfrom.c <dd> Verbs: From & Associates. See Hui, Some Uses of { and }, APL87. +<dt> vg.c <dd> Verbs: Grades +<dt> vgauss.c<dd> Verbs: Gaussian Elimination +<dt> vi.c <dd> Verbs: Index-of +<dt> visp.c <dd> Verbs: Index-of on Sparse Arrays +<dt> vm.c <dd> Verbs: "Mathematical" Functions (Irrational, Transcendental, etc.) +<dt> vo.c <dd> Verbs: Box & Open +<dt> vp.c <dd> Verbs: Permutations +<dt> vq.c <dd> Verbs: Rational Numbers +<dt> vs.c <dd> Verbs: $. Sparse Arrays +<dt> vt.c <dd> Verbs: Take and Drop +<dt> vx.c <dd> Verbs: Extended Precision Integers +<dt> vz.c <dd> Verbs: Complex-Valued Scalar Functions +</dl> +<dl> +<dt> w.h <dd> Words +<dt> w.c <dd> Words: Word Formation +<dt> wc.c <dd> Words: Control Words +<dt> wn.c <dd> Words: Numeric Input Conversion +<dt> ws.c <dd> Words: Spelling +</dl> +<dl> +<dt> x.h <dd> Xenos: Macros and Defined Constants for !: +<dt> x.c <dd> Xenos aka Foreign: External, Experimental, & Extra +<dt> x15.c <dd> Xenos: DLL call driver +<dt> xa.c <dd> Xenos: Miscellaneous +<dt> xb.c <dd> Xenos: Binary Representation +<dt> xd.c <dd> Xenos: file directory, attributes, & permission +<dt> xf.c <dd> Xenos: Files +<dt> xh.c <dd> Xenos: Host Command Facilities +<dt> xi.c <dd> Xenos: Implementation Internals +<dt> xl.c <dd> Xenos: File Lock/Unlock +<dt> xo.c <dd> Xenos: File Open/Close +<dt> xr.c <dd> Xenos: Interface to regexp Regular Expressions Package +<dt> xs.c <dd> Xenos: Scripts +<dt> xt.c <dd> Xenos: time and space +</dl> + +<br> +<hr> + +<a href="iojXenos.htm">Next</a> + • +<a href="iojTest.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html>
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojGloss.htm @@ -0,0 +1,329 @@ +<html> + +<head> +<title>An Implementation of J -- Glossary</title> +</head> + +<body> + +<p align=center><font size="6"><b>Glossary</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +An explanation is provided for significant names in the system. +Names spelled with majuscules denote defined +types<tt> </tt>(<tt>typedef</tt>)<tt> </tt>or<tt> #define </tt> +constants and macros; those spelled with minuscules denote +C functions and variables.<br><br> + +Each entry has a name, its frequency of occurrence, +and a brief description.<br> + +<table> +<tr valign=top> +<td> </td> +<td> </td> +<td> </td> +</tr> + +<tr valign=top> +<td><tt>A</tt></td> +<td>1157</td> +<td>The data type of an array; the data type of<tt> BOX </tt>array elements</td> +</tr> + +<tr valign=top> +<td><tt>a</tt></td> +<td>1883</td> +<td>The left argument of a verb</td> +</tr> + +<tr valign=top> +<td><tt>a0j1</tt></td> +<td>9</td> +<td>The complex atom<tt> 0j1</tt></td> +</tr> + +<tr valign=top> +<td><tt>ainf</tt></td> +<td>14</td> +<td>The floating point atom<tt> _</tt></td> +</tr> + +<tr valign=top> +<td><tt>AN(x)</tt></td> +<td>759</td> +<td>The<tt> n </tt>part of an array (the number of atoms in the value part)</td> +</tr> + +<tr valign=top> +<td><tt>apv(n,b,m)</tt></td> +<td>96</td> +<td>The arithmetic progression vector<tt> b+m*i.n </tt></td> +</tr> + +<tr valign=top> +<td><tt>AN(x)</tt></td> +<td>759</td> +<td>The<tt> n </tt>part of an array; the number of atoms in the value part</td> +</tr> + +<tr valign=top> +<td><tt>AR(x)</tt></td> +<td>581</td> +<td>The<tt> r </tt>part of an array; the rank of an array</td> +</tr> + +<tr valign=top> +<td><tt>AS(x)</tt></td> +<td>477</td> +<td>The<tt> s </tt>part of an array; the shape of an array</td> +</tr> + +<tr valign=top> +<td><tt>ASSERT(p,e)</tt></td> +<td>822</td> +<td>Signal error<tt> e </tt>if proposition<tt> p </tt>is <i>not</i> true</td> +</tr> + +<tr valign=top> +<td><tt>AT(x)</tt></td> +<td>733</td> +<td>The<tt> t </tt>part of an array; the type of an array</td> +</tr> + +<tr valign=top> +<td><tt>B</tt></td> +<td>706</td> +<td>The data type of<tt> B01 </tt>array elements</td> +</tr> + +<tr valign=top> +<td><tt>B01</tt></td> +<td>160</td> +<td>The type of a Boolean array</td> +</tr> + +<tr valign=top> +<td><tt>bp(t)</tt></td> +<td>92</td> +<td>The number of bytes per atom of type<tt> t </tt></td> +</tr> + +<tr valign=top> +<td><tt>C</tt></td> +<td>566</td> +<td>The data type of<tt> LIT </tt>array elements</td> +</tr> + +<tr valign=top> +<td><tt>cstr(s)</tt></td> +<td>93</td> +<td>A string with value the characters in the 0-terminated string<tt> s</tt></td> +</tr> + +<tr valign=top> +<td><tt>DO(n,stmt)</tt></td> +<td>905</td> +<td>Execute<tt> n </tt>times the statement<tt> stmt</tt>,<tt> </tt> +with local variable<tt> i </tt>running from<tt> 0 </tt>to<tt> n-1</tt></td> +</tr> + +<tr valign=top> +<td><tt>EPILOG(x)</tt></td> +<td>82</td> +<td>Free all temporary storage used since the +last<tt> PROLOG</tt>,<tt> </tt>then return<tt> x </tt>as a result</td> +</tr> + +<tr valign=top> +<td><tt>F1(f)</tt></td> +<td>705</td> +<td>Define<tt> f </tt>as a monadic verb or an adverb</td> +</tr> + +<tr valign=top> +<td><tt>F2(f)</tt></td> +<td>326</td> +<td>Define<tt> f </tt>as a dyadic verb or a conjunction</td> +</tr> + +<tr valign=top> +<td><tt>GA(t,n,r,s)</tt></td> +<td>583</td> +<td>Create an array of type<tt> t </tt>of rank<tt> r </tt>and +shape<tt> s</tt>,<tt> </tt>with<tt> n </tt>atoms</td> +</tr> + +<tr valign=top> +<td><tt>I</tt></td> +<td>1537</td> +<td>The data type in C of a full-word integer</td> +</tr> + +<tr valign=top> +<td><tt>iv0</tt></td> +<td>17</td> +<td><tt>,2-2</tt>,<tt> </tt>the integer vector 0</td> +</tr> + +<tr valign=top> +<td><tt>iv1</tt></td> +<td>18</td> +<td><tt>,2-1</tt>,<tt> </tt>the integer vector 1</td> +</tr> + +<tr valign=top> +<td><tt>jt</tt></td> +<td>2557</td> +<td>Points to a structure of all the global variables for a J instance</td> +</tr> + +<tr valign=top> +<td><tt>LIT</tt></td> +<td>566</td> +<td>The type of a literal (character) array +<tt> </tt>(<tt>CHAR </tt>conflicts with C usage)</td> +</tr> + +<tr valign=top> +<td><tt>mtm</tt></td> +<td>44</td> +<td>The empty matrix<tt> i.0 0</tt></td> +</tr> + +<tr valign=top> +<td><tt>mtv</tt></td> +<td>73</td> +<td>The empty vector<tt> i.0</tt></td> +</tr> + +<tr valign=top> +<td><tt>neg1</tt></td> +<td>22</td> +<td>The integer atom<tt> _1</tt></td> +</tr> + +<tr valign=top> +<td><tt>one</tt></td> +<td>98</td> +<td>The Boolean atom<tt> 1</tt></td> +</tr> + +<tr valign=top> +<td><tt>pie</tt></td> +<td>5</td> +<td>The floating point atom <font face=Symbol>p</font><tt> </tt> +(<tt>pi </tt>conflicts with C usage)</td> +</tr> + +<tr valign=top> +<td><tt>PROLOG</tt></td> +<td>85</td> +<td>Establish a checkpoint for temporary storage usage</td> +</tr> + +<tr valign=top> +<td><tt>RE(x)</tt></td> +<td>220</td> +<td>Return 0 if an error is signalled in executing<tt> x</tt> +</td> +</tr> + +<tr valign=top> +<td><tt>RZ(x)</tt></td> +<td>1537</td> +<td>Return 0 if<tt> x </tt>is 0</td> +</tr> + +<tr valign=top> +<td><tt>sc(k)</tt></td> +<td>217 </td> +<td>An integer atom with value<tt> k </tt>(equivalent to<tt> sc4(INT,k)</tt>)</td> +</tr> + +<tr valign=top> +<td><tt>sc4(t,k)</tt></td> +<td>5</td> +<td>An atom of type<tt> t </tt>with 4-byte value<tt> k </tt></td> +</tr> + +<tr valign=top> +<td><tt>scc(c)</tt></td> +<td>17</td> +<td>A literal atom with value <tt> c </tt></td> +</tr> + +<tr valign=top> +<td><tt>scf(x)</tt></td> +<td>26</td> +<td>A floating point atom with value<tt> x </tt></td> +</tr> + +<tr valign=top> +<td><tt>str(n,s)</tt></td> +<td>52</td> +<td>A string (literal list) of length<tt> n </tt>with value the characters +pointed to by<tt> s </tt></td> +</tr> + +<tr valign=top> +<td><tt>two</tt></td> +<td>24</td> +<td>The integer atom<tt> 2</tt></td> +</tr> + +<tr valign=top> +<td><tt>v1(k)</tt></td> +<td>15</td> +<td>The integer vector<tt> ,k</tt></td> +</tr> + +<tr valign=top> +<td><tt>v2(a,b)</tt></td> +<td>72</td> +<td>The integer vector<tt> a,b</tt></td> +</tr> + +<tr valign=top> +<td><tt>vec(t,n,v) </tt></td> +<td>81</td> +<td>A vector of length<tt> n </tt>of type<tt> t</tt>,<tt> </tt> +with values pointed to by<tt> v</tt></td> +</tr> + +<tr valign=top> +<td><tt>vi(x)</tt></td> +<td>45</td> +<td>"Verify integer", convert<tt> x </tt>to integer</td> +</tr> + +<tr valign=top> +<td><tt>w</tt></td> +<td>3207</td> +<td>The right argument of a verb</td> +</tr> + +<td><tt>zero</tt></td> +<td>129</td> +<td>The Boolean atom<tt> 0</tt></td> +</tr> + +</table><br> + +<br> +<hr> + +<a href="iojIndex.htm">Next</a> + • +<a href="iojBib.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojIndex.htm @@ -0,0 +1,916 @@ +<html> + +<head> +<title>An Implementation of J -- Glossary and Index</title> +</head> + +<body> + +<p align=center><font size="6"><b>Glossary and Index</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +An explanation is provided for significant names in the system. +Names spelled with majuscules denote defined +types<tt> </tt>(<tt>typedef</tt>)<tt> </tt>or<tt> #define </tt> +constants and macros; those spelled with minuscules denote +C functions and variables.<br><br> + +Each entry has a name, its frequency of occurrence, +and a brief description.<br> + +<table> +<tr valign=top> +<td> </td> +<td> </td> +<td> </td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#A"><tt>A</tt></a></td> +<td>1157</td> +<td>the data type of an array; +the data type for a<tt> <a href="#BOX">BOX</a> </tt>array</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#F2"><tt>a</tt></a></td> +<td>1855</td> +<td>the left argument of a verb</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>a0j1</tt></a></td> +<td>9</td> +<td>the complex atom<tt> 0j1</tt></td> +</tr> + +<tr valign=top><td><a href="iojAdv.htm">adverb</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#AF"><tt>AF</tt></a></td> +<td>58</td> +<td>the data type of a function that takes array arguments +and returns an array result</td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#agreement">agreement</a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#APart"><tt>AH</tt></a></td> +<td>16</td> +<td>the number of words in the <a href="#header">header</a> of an array, +excluding the shape</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>ainf</tt></a></td> +<td>14</td> +<td>the floating point atom<tt> _</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#APart"><tt>AN(x)</tt></a></td> +<td>759</td> +<td>the<tt> n </tt>part of an array (the number of atoms in the value part)</td> +</tr> + +<tr valign=top> +<td><a href="ioj.htm">APL</a></td> +<td> </td> +<td>A Programming Language</td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm#arrayutil"><tt>apv(n,b,m)</tt></a></td> +<td>96</td> +<td>the arithmetic progression vector<tt> b+m*i.n </tt></td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#APart"><tt>AR(x)</tt></a></td> +<td>581</td> +<td>the<tt> r </tt>part of an array; the rank of an array</td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm#Arrays">array</a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#APart"><tt>AS(x)</tt></a></td> +<td>477</td> +<td>the<tt> s </tt>part of an array; the shape of an array</td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#Word Formation">ASCII</a></td></tr> + +<tr valign=top> +<td><a href="iojDisp.htm#asgn"><tt>asgn</tt></a></td> +<td>10</td> +<td>1 if assignment is last operation on a user input line</td> +</tr> + +<tr valign=top><td><a href="iojSp.htm#assembly code">assembly code</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#ASSERT"><tt>ASSERT(p,e)</tt></a></td> +<td>822</td> +<td>signal error<tt> e </tt>if proposition<tt> p </tt>is <i>not</i> true</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#APart"><tt>AT(x)</tt></a></td> +<td>733</td> +<td>the<tt> t </tt>part of an array; the type of an array</td> +</tr> + +<tr valign=top><td><a href="iojRep.htm#Atomic">atomic representation</a></td></tr> + +<tr valign=top><td><a href="iojVerb.htm#atomic">atomic verb</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#types"><tt>B</tt></a></td> +<td>706</td> +<td>the data type for a<tt> <a href="#B01">B01</a> </tt>array</td> +</tr> + +<tr valign=top> +<a name="B01"></a> +<td><a href="iojNoun.htm#types"><tt>B01</tt></a></td> +<td>160</td> +<td>Boolean array type<tt> </tt> +(<tt>BOOL </tt>conflicts with C usage)</td> +</tr> + +<tr valign=top><td><a href="iojComp.htm">Bernecky, Robert</a></td></tr> + +<tr valign=top><td><a href="iojBib.htm#PCB">Berry, Paul</a></td></tr> + +<tr valign=top> +<a name="BOX"></a> +<td><a href="iojNoun.htm#types"><tt>BOX</tt></a></td> +<td>115</td> +<td>boxed array type</td> +</tr> + +<tr valign=top><td><a href="iojDisp.htm#Boxed">box drawing character</a></td></tr> + +<tr valign=top><td><a href="iojDisp.htm#Boxed">boxed display</a></td></tr> + +<tr valign=top><td><a href="iojRep.htm#Boxed">boxed representation</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#bp"><tt>bp(t)</tt></a></td> +<td>92</td> +<td>the number of bytes per atom of type<tt> t </tt></td> +</tr> + +<tr valign=top><td><a href="iojBib.htm#Burke">Burke, Chris</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#types"><tt>C</tt></a></td> +<td>566</td> +<td>the data type for a<tt> <a href="#LIT">LIT</a> </tt>array</td> +</tr> + +<tr valign=top> +<a name="CMPX"></a> +<td><a href="iojNoun.htm#types"><tt>CMPX</tt></a></td> +<td>83</td> +<td>complex number array type</td> +</tr> + +<tr valign=top><td><a href="iojComp.htm">comparatives</a></td></tr> + +<tr valign=top><td><a href="iojComp.htm#tolerance">comparison tolerance</a></td></tr> + +<tr valign=top><td><a href="iojAdv.htm">conjunctions</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#constants">constants</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#conventional function">conventional function</a></td> +<td> </td> +<td>a function that returns zero on zero arguments and on errors</td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm#arrayutil"><tt>cstr(s)</tt></a></td> +<td>93</td> +<td>a string with value the characters in the 0-terminated string<tt> s</tt></td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojAdv.htm#df1"><tt>df1(w,self)</tt></a></td> +<td>90</td> +<td>apply the monad of the verb<tt> self</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojAdv.htm#df2"><tt>df2(a,w,self)</tt></a></td> +<td>67</td> +<td>apply the dyad of the verb<tt> self</tt></td> +</tr> + +<tr valign=top><td><a href="iojBib.htm#JDictionary">dictionary</a></td></tr> + +<tr valign=top><td><a href="iojDisp.htm">display</a></td></tr> + +<tr valign=top> +<td><tt>DO(n,stmt)</tt></td> +<td>905</td> +<td>execute<tt> n </tt>times the statement<tt> stmt</tt>,<tt> </tt> +with local variable<tt> i </tt>running from<tt> 0 </tt>to<tt> n-1</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#ds"><tt>ds(s)</tt></a></td> +<td>151</td> +<td>the primitive whose ID is<tt> s</tt></td> +</tr> + +<tr valign=top><td> </td></tr> + +<tr valign=top> +<td><a href="iojSent.htm#enqueue"><tt>enqueue(a,w)</tt></a></td> +<td>3</td> +<td>prepare sentence<tt> w </tt>for parsing;<tt> </tt> +<tt> a </tt>is<tt> <a href="#wordil">wordil(w)</a></tt></td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm#EPILOG"><tt>EPILOG(x)</tt></a></td> +<td>82</td> +<td>free temporary storage used since the +last<tt> <a href="#PROLOG">PROLOG</a></tt>,<tt> </tt>then return<tt> x</tt></td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#errors">error handling</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#evinit"><tt>evinit</tt></a></td> +<td>3</td> +<td>initialize the error messages</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#evm"><tt>evm</tt></a></td> +<td>7</td> +<td>a list of the error messages</td> +</tr> + +<tr valign=top><td> </td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#F1"><tt>F1(f)</tt></a></td> +<td>705</td> +<td>define<tt> f </tt>as a monadic verb or an adverb</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#F1RANK"><tt>F1RANK(r,f1,self)</tt></a></td> +<td>52</td> +<td>implements monadic rank<tt> r </tt>on the verb<tt> self </tt>whose +monad is<tt> f1 </tt></td> +</tr> + +<tr valign=top><td> +<a href="iojVerb.htm#F2"><tt>F2(f)</tt></a></td> +<td>326</td> +<td>define<tt> f </tt>as a dyadic verb or a conjunction</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#F2RANK"><tt>F2RANK(l,r,f2,self)</tt></a></td> +<td>30</td> +<td>implements dyadic ranks<tt> l </tt>and<tt> r </tt>on the +verb<tt> self </tt>whose dyad is<tt> f2 </tt></td> +</tr> + +<tr valign=top><td><a href="iojBib.htm#Falkoff">Falkoff, Adin</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#fit">fit</a></td> +<td> </td> +<td>the conjunction<tt> !. </tt>that produces +<a href="#variant">variants</a> of a verb</td> +</tr> + +<tr valign=top> +<a name="FL"></a> +<td><a href="iojNoun.htm#types"><tt>FL</tt></a></td> +<td>115</td> +<td>floating point array type</td> +</tr> + +<tr valign=top> +<td><a href="iojSent.htm#folk"><tt>folk(x,y,z)</tt></a></td> +<td>53</td> +<td>implements a trident<tt> </tt>(<tt>fork </tt>conflicts with UNIX usage)</td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#fork">fork</a></td></tr> + +<tr valign=top><td><a href="iojXenos.htm">foreign conjunction</a></td></tr> + +<tr valign=top><td><a href="iojDisp.htm#Formatted">format</a></td></tr> + +<tr valign=top><td><a href="iojDisp.htm#Formatted">formatted display</a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#free"><tt>free(x)</tt></a></td> +<td> </td> +<td>C library routine; frees memory block<tt> x </tt>previously +allocated by<tt> malloc</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojComp.htm#fuzz"><tt>fuzz</tt></a></td> +<td>13</td> +<td>a system parameter used in domain tests</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#GA"><tt>GA(t,n,r,s)</tt></a></td> +<td>583</td> +<td>create an array of type<tt> t </tt>of rank<tt> r </tt>and +shape<tt> s</tt>,<tt> </tt>with<tt> n </tt>atoms</td> +</tr> + +<tr valign=top><td><a href="iojRep.htm#gerund">gerund</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#Global Variables">global variables</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<a name="header"></a> +<td><a href="iojNoun.htm#header">header</a></td> +<td> </td> +<td>the non-value parts of an array, offset, flag, max bytes, type, etc.</td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#hook">hook</a></td></tr> + +<tr valign=top><td><a href="ioj.htm">Hui, Roger</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#types"><tt>I</tt></td> +<td>1537</td> +<td>the data type of an<tt> <a href="#INT">INT</a> </tt>array</td> +</tr> + +<tr valign=top> +<td><a href="iojSent.htm#ID">ID</a></td> +<td> </td> +<td>a one-byte value that identifies a primitive</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#iden"><tt>iden(w)</tt></a></td> +<td>6</td> +<td>the identity function for verb<tt> w</tt></td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#identity">identity</a></td></tr> + +<tr valign=top><td><a href="iojIntro.htm">immediate execution</a></td></tr> + +<tr valign=top> +<td><a href="iojIntro.htm"><tt>immex(w)</tt></a></td> +<td>7</td> +<td>"immediate execution" on<tt> w</tt>,<tt> </tt> +displaying the result if the last operation is not assignment</td> +</tr> + +<tr valign=top><td><a href="iojATW.htm">incunabulum</a></td></tr> + +<tr valign=top><td><a href="iojSent.htm#inflect">inflect</a></td></tr> + +<tr valign=top><td><a href="iojSp.htm#in-place">in-place</a></td></tr> + +<tr valign=top> +<a name="INT"></a> +<td><a href="iojNoun.htm#types"><tt>INT</tt></a></td> +<td>390</td> +<td>integer array type</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#inv"><tt>inv(w)</tt></a></td> +<td>21</td> +<td>the obverse for verb<tt> w</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#invamp"><tt>invamp</tt></a></td> +<td>3</td> +<td>the obverse for verb<tt> w </tt>which is of +the form<tt> x&v </tt>or<tt> v&y</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#invf"><tt>invf</tt></a></td> +<td>2</td> +<td>a 2-row table of primitives whose obverses are also primitive</td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#inverse">inverse</a></td></tr> + +<tr valign=top><td> +<a href="iojNoun.htm#Constants"><tt>iv0</tt></a></td> +<td>17</td> +<td><tt>,2-2</tt>,<tt> </tt>the integer vector 0</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>iv1</tt></a></td> +<td>18</td> +<td><tt>,2-1</tt>,<tt> </tt>the integer vector 1</td> +</tr> + +<tr valign=top><td><a href="iojBib.htm#EBI">Iverson, Eric</a></td></tr> + +<tr valign=top><td><a href="ioj.htm#KEI">Iverson, Kenneth E.</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#J"><tt>J</tt></a></td> +<td>606</td> +<td>the data type for<tt> <a href="#jt">jt</a></tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#jerr"><tt>jerr</tt></a></td> +<td>104</td> +<td>the current error number, or 0 if no current error</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#jsignal"><tt>jsignal(e)</tt></a></td> +<td>24</td> +<td>signal error number<tt> e</tt></td> +</tr> + +<tr valign=top> +<a name="jt"></a> +<td><a href="iojNoun.htm#jt"><tt>jt</tt></a></td> +<td>2557</td> +<td>points to a structure of all the global variables for a J instance</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojATW.htm">Kiln Farm</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojRep.htm#Linear">linear representation</a></td></tr> + +<tr valign=top> +<a name="LIT"></a> +<td><a href="iojNoun.htm#types"><tt>LIT</tt></a></td> +<td>566</td> +<td>literal (character) array type<tt> </tt> +(<tt>CHAR </tt>conflicts with C usage)</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#malloc"><tt>malloc(n)</tt></a></td> +<td> </td> +<td>C library routine; allocate<tt> n </tt>bytes of memory</td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#marker">marker</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#Memory Management">memory management</a></td></tr> + +<tr valign=top><td><a href="iojBib.htm#EEM">McDonnell, Eugene</a></td></tr> + +<tr valign=top><td><a href="iojBib.htm#McIntyre">McIntyre, Donald</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#Constants"><tt>mtm</tt></a></td> +<td>44</td> +<td>the empty matrix<tt> i.0 0</tt></td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm#Constants"><tt>mtv</tt></a></td> +<td>73</td> +<td>the empty vector<tt> i.0</tt></td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojSent.htm#Name Resolution">name resolution</a></td></tr> + +<tr valign=top> +<td><a href="iojSent.htm#Word Formation">NB.</a></td> +<td> </td> +<td>comment</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>neg1</tt></a></td> +<td>22</td> +<td>the integer atom<tt> _1</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#NEVM"><tt>NEVM</tt></a></td> +<td>9</td> +<td>the number of error messages</td> +</tr> + +<tr valign=top><td><a href="iojNoun.htm">nouns</a></td></tr> + +<tr valign=top><td><a href="iojDisp.htm#Numeric">numeric display</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojVerb.htm#obverse">obverse</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#Constants"><tt>one</tt></a></td> +<td>98</td> +<td>the Boolean atom<tt> 1</tt></td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojSent.htm#Parsing">parsing</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#pdef"><tt>pdef</tt></a></td> +<td>113</td> +<td>initialize the<tt> <a href="#pst">pst</a> </tt>table</td> +</tr> + +<tr valign=top><td> +<a href="iojNoun.htm#Constants"><tt>pie</tt></a></td> +<td>5</td> +<td>the floating point atom <font face=Symbol>p</font><tt> </tt> +(<tt>pi </tt>conflicts with C usage)</td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#pinit"><tt>pinit</tt></a></td> +<td>3</td> +<td>initialize the<tt> <a href="#pst">pst</a> </tt>table</td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#PREF1"><tt>PREF1</tt></a></td></tr> + +<tr valign=top><td><a href="iojVerb.htm#PREF2"><tt>PREF2</tt></a></td></tr> + +<tr valign=top><td><a href="iojFiles.htm#Parsing">program files</a></td></tr> + +<tr valign=top> +<a name="PROLOG"></a> +<td><a href="iojNoun.htm#PROLOG"><tt>PROLOG</tt></a></td> +<td>85</td> +<td>establish a checkpoint for temporary storage usage</td> +</tr> + +<tr valign=top> +<a name="pst"></a> +<td><a href="iojVerb.htm#pst"><tt>pst</tt></a></td> +<td>16</td> +<td>primitive symbols definition table</td> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<a name="queue"></a> +<td><a href="iojSent.htm#Parsing">queue</a></td> +<td> </td> +<td>data structure for parsing</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#R"><tt>R</tt></a></td> +<td>2510</td> +<td>an alias for<tt> return</tt></td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm#rank">rank</a></td></tr> + +<tr valign=top> +<td><a href="iojVerb.htm#rank1ex"><tt>rank1ex(w,fs,r,f1)</tt></a></td> +<td>16</td> +<td>execute<tt> fs"r w</tt>;<tt> f1 </tt>is the monad of<tt> fs</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#rank2ex"><tt>rank2ex(a,w,fs,l,r,f2)</tt></a></td> +<td>29</td> +<td>execute<tt> a fs"(l,r) w</tt>;<tt> f2 </tt>is the dyad of<tt> fs</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#ravel">ravel</a></td> +<td> </td> +<td>the atoms of an array, in ravelled (row major) order</td> +</tr> + +<tr valign=top><td> +<a href="iojVerb.htm#RE"><tt>RE(x)</tt></a></td> +<td>220</td> +<td>return 0 if an error is signalled in executing<tt> x</tt> +</td> +</tr> + +<tr valign=top><td><a href="iojSp.htm#recognized phrase">recognized phrase</a></td></tr> + +<tr valign=top><td><a href="iojRep.htm">representation</a></td></tr> + +<tr valign=top><td><a href="iojSent.htm#Word Formation">rhematic rules</a></td></tr> + +<tr valign=top><td> +<a href="iojVerb.htm#RZ"><tt>RZ(x)</tt></a></td> +<td>1537</td> +<td>return 0 if<tt> x </tt>is 0</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td> +<a href="iojNoun.htm#arrayutil"><tt>sc(k)</tt></a></td> +<td>217</td> +<td>an integer atom with value<tt> k</tt>;<tt> </tt>equivalent to<tt> <a href="#sc4">sc4</a>(INT,k)</tt></td> +</tr> + +<tr valign=top> +<a name="sc4"></a> +<td><a href="iojNoun.htm#arrayutil"><tt>sc4(t,k)</tt></a></td> +<td>5</td> +<td>an atom of type<tt> t </tt>with 4-byte value<tt> k </tt></td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#arrayutil"><tt>scc(c)</tt></a></td> +<td>17</td> +<td>a literal atom with value <tt> c </tt></td> +</tr> + +<tr valign=top><td> +<a href="iojNoun.htm#arrayutil"><tt>scf(x)</tt></a></td> +<td>26</td> +<td>a floating point atom with value<tt> x </tt></td> +</tr> + +<tr valign=top> +<td><a href="iojVerb.htm#self"><tt>self</tt></a></td> +<td>148</td> +<td>an array representing the current verb</td> +</tr> + +<tr valign=top><td><a href="iojSp.htm">special code</a></td></tr> + +<tr valign=top> +<td><a href="iojSent.htm#spell"><tt>spell</tt></a></td> +<td>5</td> +<td>a 3-row table defining the primitive words</td> +</tr> + +<tr valign=top> +<td><a href="iojSent.htm#spellin"><tt>spellin(n,s)</tt></a></td> +<td>5</td> +<td>the ID of the word in the length-<tt>n </tt>string<tt> s</tt></td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#Word Formation">spelling</a></td></tr> + +<tr valign=top> +<td><a href="iojSent.htm#spellout"><tt>spellout(c)</tt></a></td> +<td>19</td> +<td>spell out the word whose ID is<tt> c</tt></td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#Parsing">stack</a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#arrayutil"><tt>str(n,s)</tt></a></td> +<td>52</td> +<td>a string (literal list) of length<tt> n </tt>with value the characters +pointed to by<tt> s </tt></td> +</tr> + +<tr valign=top> +<a name="SYMB"></a> +<td><a href="iojSent.htm#name resolution"><tt>SYMB</tt></a></td> +<td>11</td> +<td>symbol table array type</td> +</tr> + +<tr valign=top> +<td><a href="iojSent.htm#Name Resolution"><tt>symbis(a,w,g)</tt></a></td> +<td>10</td> +<td>assign the name<tt> a </tt>to array<tt> w </tt>in symbol table<tt> g</tt></td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#Name Resolution">symbol table</a></td></tr> + +<tr valign=top> +<td><a href="iojSent.htm#Name Resolution"><tt>symbrd(w)</tt></a></td> +<td>10</td> +<td>retrieve the value for name<tt> w </tt>from the current symbol table</td> +</tr> + +<tr valign=top><td><a href="iojSumm.htm#Word Formation">system summary</a></td></tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top><td><a href="iojTest.htm">test scripts</a></td></tr> + +<tr valign=top> +<td><a href="iojDisp.htm"><tt>thorn1(w)</tt></a></td> +<td>18</td> +<td>implements the monad<tt> ":</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojSent.htm#tokens"><tt>tokens(w)</tt></a></td> +<td>16</td> +<td>tokenize sentence<tt> w</tt>;<tt> </tt> +convert<tt> w </tt>into a parse <a href="#queue">queue</a></td> +</tr> + +<tr valign=top><td><a href="iojComp.htm#tolerance">tolerance</a></td></tr> + +<tr valign=top> +<td><a href="iojIntro.htm#tpop"><tt>tpop(x)</tt></a></td> +<td>15</td> +<td>free temporary storage used since the checkpoint<tt> x</tt></td> +</tr> + +<tr valign=top><td><a href="iojSent.htm#Trains">trains</a></td></tr> + +<tr valign=top><td><a href="iojRep.htm#Tree">tree representation</a></td></tr> + +<tr valign=top><td><a href="iojNoun.htm#tstack"><tt>tstack</tt></a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>two</tt></a></td> +<td>24</td> +<td>the integer atom<tt> 2</tt></td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojAdv.htm#V"><tt>V</tt></a></td> +<td>88</td> +<td>the data type of a<tt> <a href="#VERB">VERB</a> </tt>array</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#arrayutil"><tt>v1(k)</tt></a></td> +<td>15</td> +<td>the integer vector<tt> ,k</tt></td> +</tr> + +<tr valign=top><td> +<a href="iojNoun.htm#arrayutil"><tt>v2(a,b)</tt></a></td> +<td>72</td> +<td>the integer vector<tt> a,b</tt></td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#value">value</a></td> +<td> </td> +<td>the atoms of an array, in ravelled (row major) order</td> +</tr> + +<tr valign=top> +<a name="variant"></a> +<td><a href="iojVerb.htm#variant">variant</a></td> +<td> </td> +</tr> + +<tr valign=top> +<td><a href="iojAdv.htm#VAV"><tt>VAV(x)</tt></a></td> +<td>191</td> +<td>the value part of a<tt> <a href="#VERB">VERB</a> </tt>array</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#arrayutil"><tt>vec(t,n,v)</tt></a></td> +<td>81</td> +<td>a vector of length<tt> n </tt>of type<tt> t</tt>,<tt> </tt> +with values pointed to by<tt> v</tt></td> +</tr> + + +<tr valign=top> +<a name="VERB"></a> +<td><a href="iojVerb.htm"><tt>VERB</tt></a></td> +<td>185</td> +<td>verb array type; the type of an array representing a verb</td> +</tr> + +<tr valign=top><td><a href="iojVerb.htm">verb</a></td></tr> + +<tr valign=top> +<td><a href="iojNoun.htm#vi"><tt>vi(x)</tt></a></td> +<td>45</td> +<td>"verify integer", convert<tt> x </tt>to integer</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojVerb.htm#F1"><tt>w</tt></a></td> +<td>3207</td> +<td>the right argument of a verb</td> +</tr> + +<tr valign=top><td><a href="iojATW.htm">Whitney, Arthur</a></td></tr> + +<tr valign=top><td><a href="iojSent.htm#Word Formation">word formation</a></td></tr> + +<tr valign=top><td><a href="iojSp.htm#word-parallel">word parallel</a></td></tr> + +<tr valign=top> +<a name="wordil"></a> +<td><a href="iojSent.htm#Word Formation"><tt>wordil(w)</tt></a></td> +<td>5</td> +<td>the words in sentence<tt> w </tt>as a 2-column table of index and length</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#types"><tt>X</tt></a></td> +<td>130</td> +<td>the data type for an<tt> <a href="#XNUM">XNUM</a> </tt>array</td> +</tr> + +<tr valign=top> +<a name="XNUM"></a> +<td><a href="iojNoun.htm#types"><tt>XNUM</tt></a></td> +<td>107</td> +<td>extended-precision integer array type</td> +</tr> + +<tr valign=top><td> </td></tr> + + +<tr valign=top> +<td><a href="iojNoun.htm#types"><tt>Z</tt></a></td> +<td>130</td> +<td>the data type for a<tt> <a href="#CMPX">CMPX</a> </tt>array</td> +</tr> + +<tr valign=top> +<td><a href="iojNoun.htm#Constants"><tt>zero</tt></a></td> +<td>129</td> +<td>the Boolean atom<tt> 0</tt></td> +</tr> + +</table><br> + +<br> +<hr> + +<a href="iojIndex.htm">Next</a> + • +<a href="iojBib.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojIntro.htm @@ -0,0 +1,109 @@ +<html> + +<head> +<title>An Implementation of J -- Introduction</title> +</head> + +<body> + +<p align=center><font size="6"><b>Introduction</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> + +<tt> +<ul> +<li>main + <ul> + <li>jinit2 + <li>immloop + <ul> + <li>prompt + <li>jgets + <li>immex + <ul> + <li>tokens + <ul> + <li>wordil + <li>enqueue + </ul> + <li>parse + <ul> + <li>monad + <li>dyad + <li>adv + <li>conj + <li>trident + <li>bident + <li>is + <li>punc + <li>move + </ul> + <li>jpr + </ul> + <li>tpop + </ul> + </ul> +</ul> +</tt> +The system is organized as diagrammed above. The main +function<tt> main </tt>calls<tt> jinit2 </tt>for initializations, +then<tt> immloop </tt>("immediate execution" loop), which repeats the +following steps:<br><br> + +<tt>prompt </tt>and<tt> jgets </tt>prompt and accept an input sentence.<br><br> + +<tt>immex </tt>is the heart of the execution loop. The argument is a +string of the input sentence. The processing is divided into three parts: + +<ul> +<li><tt>tokens </tt>— word formation — applies the rhematic rules to +partition the sentence into words. +<li><tt>parse </tt>interprets the sentence according to the parsing rules. +Parsing is controlled by a table of (pattern,action) pairs; the eleven possible +actions are embodied as the function listed under<tt> parse </tt> in the diagram. +<li><a name="jpr"></a><tt>jpr </tt>displays the result of the sentence. +</ul> + +Finally,<a name="tpop"></a><tt> tpop </tt>frees the temporary storage used in an iteration.<br><br> + +The fundamental data structure is the APL array (an object of +data type<tt> A</tt>), used to represent all the possible objects in J. +Most functions in the implementation accepts arrays as argument and return +them as result. Functions tend to be short and compact, and functions +which implement J primitives are used freely. Extensive use is made of +C preprocessor definitions and macros. Although the implementation +language is C, the programming style is unmistakably APL.<br><br> + +This document is organized along the lines of the dictionary: +Chapter 1 describes the +<a href="iojSent.htm">interpretation of a sentence</a>. +Chapters 2, 3, and 4 describe +<a href="iojNoun.htm">nouns</a>, +<a href="iojVerb.htm">verbs</a>, and +<a href="iojAdv.htm">adverbs and conjunctions</a>. +Chapter 5 presents alternative <a href="iojRep.htm">representations</a>. +Chapter 6 describes <a href="iojDisp.htm">display</a>. +Chapter 7, the final chapter, describes +<a href="iojComp.htm">comparisons</a>.<br><br> + +The remainder of the document contains various useful bits. +In particular, the Appendix contains a +<a href="iojSumm.htm">system summary</a>, +a means of quickly locating a primitive +in the program files.<br><br> + +<br> +<hr> + +<a href="iojSent.htm">Next</a> + • +<a href="ioj.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html>
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojNoun.htm @@ -0,0 +1,517 @@ +<html> + +<head> +<title>An Implementation of J -- Nouns</title> +</head> + +<body> + +<p align=center><font size="6"><b>Nouns</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<a href="#Arrays" >Arrays</a><br> +<a href="#Types" >Types</a><br> +<a href="#Memory Management">Memory Management</a><br> +<a href="#Global Variables" >Global Variables</a><br><br> + +<hr> +<br> + +<a name="Arrays"></a><font size="5"><b>Arrays</b></font><br><br> + +The fundamental data structure is the array, that is, an object of +the C data type<a name="A"></a><tt> A </tt>defined in file jtype.h:<br> + +<pre> + typedef long I; + typedef struct {I k,flag,m,t,c,n,r,s[1];}* A; +</pre> + +All objects, whether numeric, literal, or boxed, whether +noun, verb, adverb, or conjunction, are represented by arrays. +For example, the string<tt> 'Cogito, ergo sum.'</tt>,<tt> </tt>the +atom<tt> 1.61803</tt>,<tt> </tt>and the table<tt> 11+i.3 4 </tt>are +represented thus:<br><br> +<pre> + k flag m t c n r s[0]<font face="ISIJ"> + ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿ + ³ 32³ 0³ 20³CHAR³ 2³ 17³ 1³ 17³Cogi³to, ³ergo³ sum³. ³ + ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ</font> + + k flag m t c n r<font face="ISIJ"> + ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿ + ³ 28³ 0³ 8³ FL³ 2³ 1³ 0³ 1.61803³ + ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ</font> + + k flag m t c n r s[0] s[1]<font face="ISIJ"> + ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂ + ³ 36³ 0³ 48³ INT³ 2³ 12³ 2³ 3³ 4³ 11³ 12³ 13³ + ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁ + ÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿ + ³ 14³ 15³ 16³ 17³ 18³ 19³ 20³ 21³ 22³ + ÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ</font> +</pre> + +<a name="APart"></a>The parts of an array, and macros for manipulating them, +are as follows:<br><br> +<table> +<tr><td> </td> + <td>Part </td> + <td>Macro </td> + <td> Description</td> +</tr> + +<tr><td> </td> <td><tt>k</tt> </td> <td><tt>AK</tt> </td> <td>offset of ravel with respect to byte 0 of the array</td> </tr> +<tr><td> </td> <td><tt>flag</tt></td> <td><tt>AFLAG</tt></td> <td>flag</td> </tr> +<tr><td> </td> <td><tt>m</tt> </td> <td><tt>AM</tt> </td> <td>maximum # of bytes in ravel</td> </tr> +<tr><td> </td> <td><tt>t</tt> </td> <td><tt>AT</tt> </td> <td>type</td> </tr> +<tr><td> </td> <td><tt>c</tt> </td> <td><tt>AC</tt> </td> <td>reference count</td> </tr> +<tr><td> </td> <td><tt>n</tt> </td> <td><tt>AN</tt> </td> <td># of atoms in ravel</td> </tr> +<tr><td> </td> <td><tt>r</tt> </td> <td><tt>AR</tt> </td> <td>rank</td> </tr> +<tr><td> </td> <td><tt>s</tt> </td> <td><tt>AS</tt> </td> <td>pointer to shape</td> </tr> +<tr><td> </td> <td> </td> <td><tt>AV</tt> </td> <td><a name="ravel"></a>"ravel" or <a name="value"></a>"value", pointer to atoms in ravelled order</td> </tr> +</table><br> + +An array has a <a name="header"></a>"header" and a "value". The header are the +parts<tt> k</tt>,<tt> flag</tt>,<tt> m</tt>,<tt> t</tt>,<tt> </tt>and so forth, +including the shape<tt> s</tt>,<tt> </tt>which consists of<tt> r </tt> +integers whose product equals<tt> n</tt>.<tt> </tt> +The value, the atoms of the array in ravelled (row major) order, +usually follow immediately after<tt> s</tt>,<tt> </tt>but can be +separate from the header, according to the value in the<tt> k </tt>part. +Setting the parts of an array incorrectly, or exceeding the bounds +of the array specified by these parts, almost always lead to +erratic behaviour and catastrophic failure.<br><br> + +The macros<tt> AK</tt>,<tt> AFLAG</tt>,<tt> AM</tt>,<tt> AT</tt>,<tt> </tt> +<tt> AC</tt>,<tt> AN</tt>,<tt> </tt>and<tt> AR </tt>denote "fullword" +integers and may occur on the left or right of an assignment +(<i>i.e.</i> they are "lvalues".)<tt> AS </tt>is an integer +pointer.<tt> AV </tt>is also an integer pointer, and must be <i>cast</i> +to a C data type appropriate to the type of array. +(See <a href="#Types">Types</a>.)<br><br> + +All arrays are created using the macro<tt> <a name="GA">GA</a> </tt>in file j.h. +The statement<br> +<pre> + GA(xyz,t,n,r,s); +</pre> +creates an array named<tt> xyz </tt>of type<tt> t </tt>and +rank<tt> r</tt>,<tt> </tt>having<tt> n </tt>atoms and shape<tt> s</tt>.<tt> </tt> +If the rank is 0,<tt> s </tt>is ignored; if the rank is 1, again<tt> s </tt> +is ignored, and the shape is set to<tt> n</tt>.<tt> </tt>Otherwise, +if<tt> s </tt>is nonzero,<tt> GA </tt>initializes the shape from +the<tt> r </tt>integers pointed to by<tt> s</tt>,<tt> </tt>and +if<tt> s </tt>is 0, the shape is not initialized +and must be initialized subsequently.<tt> GA </tt>returns zero +if the array can not be created.<br><br> + +For example, the arrays diagrammed above can be created as follows, +under the names<tt> ces</tt>,<tt> phi</tt>,<tt> </tt>and<tt> m</tt>:<br> + +<pre> + typedef char C; + typedef double D; + + A ces,m,phi; I j,*s,*v; + + GA(ces,CHAR,17,1,0); + memcpy((C*)AV(ces),"Cogito, ergo sum.",(size_t)17); + + GA(phi,FL,1,0,0); + *(D*)AV(phi)=1.61803; + + GA(m,INT,12,2,0); + s=AS(m); *s=3; *(1+s)=4; + v=AV(m); for(j=11;23>j;++j)*v++=j; +</pre> + +The following <a name="arrayutil"></a>utilities (file u.c) and +array <a name="constants">constants</a> (file i.c) are +convenient for working with simple arrays. +The frequency of use gives a sense of their utility.<br><br> + +<table> +<tr valign=top> +<td> </td> +<td> Facility</td> +<td>Freq. </td> +<td> Description</td> +</tr> + +<tr valign=top> <td> </td> </tr> + +<tr valign=top> +<td> </td> +<td><tt>sc(I k)</tt></td> +<td>217 </td> +<td>An integer atom with value<tt> k </tt>(equivalent to<tt> sc4(INT,k)</tt>)</td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>sc4(I t,I k)</tt></td> +<td>5</td> +<td>An atom of <a href="#types">type</a><tt> t </tt>with 4-byte value<tt> k </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>scf(D x)</tt></td> +<td>26</td> +<td>A floating point atom with value <tt> x </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>scc(C x)</tt></td> +<td>17</td> +<td>A literal atom with value <tt> c </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>apv(I n,I b,I m)</tt></td> +<td>96</td> +<td>The arithmetic progression vector<tt> b+m*i.n </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>str(I n,C*s)</tt></td> +<td>52</td> +<td>A string (literal list) of length<tt> n </tt>with value the characters +pointed to by<tt> s </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>cstr(C*s)</tt></td> +<td>93</td> +<td>A string with value the characters in the 0-terminated string<tt> s </tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>v2(I a,I b)</tt></td> +<td>72</td> +<td>The integer vector<tt> a,b</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>v1(I k)</tt></td> +<td>15</td> +<td>The integer vector<tt> ,k</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>vec(I t,I n,void*v) </tt></td> +<td>81</td> +<td>A vector of length<tt> n </tt>of <a href="#types">type</a><tt> t</tt>,<tt> </tt> +with values pointed to by<tt> v</tt></td> +</tr> + +<tr valign=top> <td> </td> </tr> + +<tr valign=top> +<td> </td> +<td><tt>zero</tt></td> +<td>129</td> +<td><tt>0</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>one</tt></td> +<td>98</td> +<td><tt>1</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>two</tt></td> +<td>24</td> +<td><tt>2</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>neg1</tt></td> +<td>22</td> +<td><tt>_1</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>pie</tt></td> +<td>5</td> +<td><tt>1p1 </tt>(<tt>pi </tt>conflicts with C usage)</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>a0j1</tt></td> +<td>9</td> +<td><tt>0j1</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>ainf</tt></td> +<td>14</td> +<td><tt>_</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>iv0</tt></td> +<td>17</td> +<td><tt>,2-2</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>iv1</tt></td> +<td>18</td> +<td><tt>,2-1</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>mtv</tt></td> +<td>73</td> +<td><tt>i.0</tt></td> +</tr> + +<tr valign=top> +<td> </td> +<td><tt>mtm</tt></td> +<td>44</td> +<td><tt>i.0 0</tt></td> +</tr> + +</table><br> + +For example, the arrays diagrammed above +can be created by<tt> str(17L,"Cogito, ergo sum.") </tt> +or<tt> cstr("Cogito, ergo sum.")</tt>,<tt> </tt> +<tt>scf(1.61803)</tt>,<tt> </tt>and<tt> </tt> +<tt>reshape(v2(3L,4L),apv(12L,11L,1L))</tt>.<br><br> + +<br> + +<a name="Types"></a><p><font size="5"><b>Types</b></font><br><br> + +If<tt> x </tt>is an array, its <i>type</i><tt> AT(x) </tt>specifies +how the atoms starting at<tt> AV(x) </tt>are to be interpreted. +In C programming terms,<tt> AV(x) </tt>must be <i>cast</i> to a +pointer of the appropriate C type:<br> +<pre> + <font size=3 face="Times New Roman">C Data</font> + AT(x) <font size=3 face="Times New Roman">Type Description</font> + + B01 B <font size=3 face="Times New Roman">Boolean</font> <font size=3 face="Times New Roman">(</font>BOOL <font size=3 face="Times New Roman">has a name conflict)</font> + LIT C <font size=3 face="Times New Roman">literal (character;</font> CHAR <font size=3 face="Times New Roman">has a name conflict)</font> + INT I <font size=3 face="Times New Roman">integer</font> + FL D <font size=3 face="Times New Roman">double (IEEE floating point)</font> + CMPX Z <font size=3 face="Times New Roman">complex</font> + BOX A <font size=3 face="Times New Roman">boxed</font> + XNUM X <font size=3 face="Times New Roman">extended precision integer</font> + RAT Q <font size=3 face="Times New Roman">rational number</font> + + SB01 P <font size=3 face="Times New Roman">sparse boolean</font> + SLIT P <font size=3 face="Times New Roman">sparse literal (character)</font> + SINT P <font size=3 face="Times New Roman">sparse integer</font> + SFL P <font size=3 face="Times New Roman">sparse floating point</font> + SCMPX P <font size=3 face="Times New Roman">sparse complex</font> + SBOX P <font size=3 face="Times New Roman">sparse boxed</font> + + VERB V <font size=3 face="Times New Roman">verb</font> + ADV V <font size=3 face="Times New Roman">adverb</font> + CONJ V <font size=3 face="Times New Roman">conjunction</font> + + ASGN I <font size=3 face="Times New Roman">assignment</font> + MARK I <font size=3 face="Times New Roman">marker</font> + SYMB L <font size=3 face="Times New Roman">locale (symbol table)</font> + CONW CW <font size=3 face="Times New Roman">control word</font> + NAME NM <font size=3 face="Times New Roman">name</font> + LPAR I <font size=3 face="Times New Roman">left parenthesis</font> + RPAR I <font size=3 face="Times New Roman">right parenthesis</font> +</pre> +For example, if<tt> x </tt>is literal and<tt> s=(C*)AV(x)</tt>,<tt> </tt> +then<tt> s[i] </tt>is character<tt> i </tt>of<tt> x</tt>. The C data types +in the table are all<tt> typedef</tt>'s<tt> </tt>found in file jtype.h; +the data type<tt> V </tt>is explained in the +<a href="iojVerb.htm">Verbs</a> section.<br><br> + +Types are fullword integers, and are powers of 2 to permit convenient +tests for "composite" types. For example, if:<br> + +<pre> + #define NUMERIC (B01+INT+FL+CMPX+XNUM+RAT+SB01+SINT+SFL+SCMPX) + #define NOUN (NUMERIC+LIT+SLIT+BOX+SBOX) +</pre> +Then the phrase<tt> NUMERIC&AT(x) </tt>tests for numeric arrays, +and the phrase<tt> NOUN&AT(x) </tt>tests for nouns. Such comparisons +play a key role in the <a href="iojSent.htm#Parsing">parser</a>.<br><br> + +A numeric array is accepted as argument by a primitive, +regardless of its type, if it is mathematically within the domain +of the primitive. For example, a primitive with integral domain +would accept integers in an array of type<tt> FL</tt>,<tt> CMPX</tt>,<tt> </tt> +and<tt> B01</tt>,<tt> </tt>and of course<tt> INT</tt>.<tt> </tt> +(This analytic property does not extend to functions internal to +the implementation.) Functions in the file k.c convert between numeric types. +A converted result is an array of the target type equal to the +argument within <a href="iojComp.htm#fuzz">fuzz</a>. +The following functions are available:<br><br> + +<table> +<tr><td><tt> </tt></td> + <td><tt>cvt(t,x) </tt></td> + <td>Convert<tt> x </tt>to type<tt> t</tt>;<tt> </tt>signal error if not possible</td> +</tr> +<tr><td> </td> + <td><tt>pcvt(t,x)</tt></td> + <td>Convert<tt> x </tt>to type<tt> t</tt>;<tt> </tt>return<tt> x </tt>if not possible</td> +</tr> +<tr><td> </td> + <td><tt>icvt(t,x)</tt></td> + <td>Convert floating<tt> x </tt>to<tt> INT </tt>if the values are in range; + otherwise just return<tt> x</tt></td> +</tr> +<tr><td> </td> + <td><tt>bcvt(t,x)</tt></td> + <td>Convert<tt> x </tt>to the "lowest" type</td> +</tr> +</table><br> + +The utility<a name="bp"></a><tt> bp </tt>in file u.c applies to a type, +and returns the number of bytes per atom of that type. Thus<tt> bp(INT) </tt> +is 4;<tt> bp(AT(x)) </tt>is the number of bytes per atom of<tt> x</tt>;<tt> </tt> +and<tt> 28+(4*AR(x))+AN(x)*bp(AT(x)) </tt>is the number of bytes +required by<tt> x </tt>— 4 bytes each +for<tt> k</tt>,<tt>flag</tt>,<tt>m</tt>,<tt>t</tt>,<tt>c</tt>,<tt>n</tt>,<tt>r</tt>;<tt> </tt> +4 bytes each for the<tt> AR(x) </tt>elements of the shape; +and<tt> bp(AT(x)) </tt>bytes each for<tt> AN(x) </tt>atoms.<br><br> + +The atoms of a boxed array are pointers to other arrays, and are +accessible through<tt> (A*)AV(x)</tt>,<tt> </tt>as the following +example illustrates.<tt> aib </tt>applies to a boxed array<tt> x</tt>,<tt> </tt> +and returns the number of atoms in each box of<tt> x</tt>:<br> + +<pre> + #define R return<a name="R"></a> + + A aib(A x){A*u,z;I j,*v; + GA(z,INT,AN(x),AR(x),AS(x)); /* 1 */ + u=(A*)AV(x); v=AV(z); /* 2 */ + for(j=0;AN(x)>j;++j)*v++=AN(*u++); /* 3 */ + R z; + } +</pre> + +Line 1 creates an integer array<tt> z </tt>having the same rank +and shape as<tt> x</tt>.<tt> </tt> +Line 2 initializes pointer values<tt> u </tt>and<tt> v </tt> +for traversing<tt> x </tt>and<tt> z </tt>.<tt> </tt> +Line 3 runs through the atoms of<tt> x</tt>,<tt> </tt>through<tt> u</tt>,<tt> </tt> +and records the number of atoms in each. Since the data type of<tt> u </tt> +is<tt> A*</tt>,<tt> </tt>the data type of<tt> *u </tt>is<tt> A </tt>and +are subject to<tt> AN</tt>,<tt> AT</tt>,<tt> AV</tt>,<tt> </tt>etc.<br><br> + +<br> + +<a name="Memory Management"></a><p><font size="5"><b>Memory Management</b></font><br><br> + +When an array is created,<a name="malloc"></a><tt> malloc </tt>is +called to obtain the requisite storage; +when this storage is no longer needed,<a name="free"></a><tt> free </tt>is +called to return it to the +underlying system. No "garbage collection" is done. The performance +of this strategy is adequate on modern virtual memory systems. +To facilitate the implementation of alternative strategies, +the use of<tt> malloc </tt>and<tt> free </tt>is limited to a single +instance of each, in the file m.c.<br><br> + +The reference count of an array is incremented when it is assigned +a name, directly or indirectly, and is decremented when the name is +reassigned or erased; when the reference count of an array reaches 0, +its storage is freed.<br><br> + +When an array is created, a pointer to it is entered in a "temp stack"<tt> </tt> +(<a name="tstack"></a><tt>tstack </tt>in file m.c.) +A <i>temp</i> is an array on this stack with a reference count of one. +The temp stack plays an important role in the +<a href="iojIntro.htm">main execution loop</a>. +In an iteration of the loop,<br><br> + +<tt> </tt>• The top of the temp stack is recorded;<br> +<tt> </tt>• A line of user-input is executed; and<br> +<tt> </tt>• Temps from the current top-of-stack to the old top-of-stack +recorded above, are freed.<br><br> + +This device permits functions to be written without explicit +memory management code. For example, the monad<tt> ~. </tt>is written:<br> + +<pre> + F1(jtnub){R repeat(nubsieve(w),w);} +</pre> + +And<tt> nub </tt>need not be concerned with temps used +in<tt> repeat </tt>or<tt> nubsieve</tt>,<tt> </tt> +because they are accounted for in the main loop.<br><br> + +On the other hand, a function <i>may</i> account for temps: +On entry into the function, the current top-of-stack is recorded; +on exit, temps are freed down to the recorded point. +(These actions are mediated by the +macros<a name="PROLOG"></a><tt> PROLOG </tt>and<a name="EPILOG"></a><tt> EPILOG</tt>.)<tt> </tt> +Whether a function accounts for temps does not affect the logic of +functions that it calls, nor functions that call it.<br><br> + +<br> + +<a name="Global Variables"></a><p><font size="5"><b>Global Variables</b></font><br><br> + +The only global variables used in the system are +constants which are assigned exactly once. +(For example, the array constant<tt> zero </tt>and the internal complex +number<tt> zeroZ</tt>.)<tt> </tt>All other variables non-local to functions +are accessed through the parameter<a name="jt"></a><tt> jt</tt>.<br><br> + +<tt>jt </tt>has defined type<tt> <a name="J">J</a></tt>,<tt> </tt>a pointer to +a<tt> struct </tt>defined in file jt.h. +Nearly all functions in the system has<tt> jt </tt> +as its first function argument, +and all such functions have the letters<tt> jt </tt>as a prefix in their names. +The file ja.h defines aliases for these names, so that a call to a +function<tt> jtxyz(jt,a,w,h) </tt>is +actually written as<tt> xyz(a,w,h)</tt>.<tt> </tt> +For example, the conjunction<tt> &</tt>,<tt> </tt> +described in <a href="iojAdv.htm#amp">Adverbs and Conjunctions</a>, +is implemented by a function +defined and declared as<tt> jtamp</tt>,<tt> </tt> +having prototype<tt> A jtamp(J jt,A a,A w)</tt>,<tt> </tt>but calls to this +function are written as<tt> amp(a,w)</tt>,<tt> </tt> +and discussions on this function refer to it as<tt> amp</tt>.<br><br> + +<tt>jt </tt>makes it possible to execute multiple instances +of J in the same process.<br><br> + +<br> +<hr> + +<a href="iojVerb.htm">Next</a> + • +<a href="iojSent.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojRep.htm @@ -0,0 +1,526 @@ +<html> + +<head> +<title>An Implementation of J -- Representation</title> +</head> + +<body> + +<p align=center><font size="6"><b>Representation</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<a href="#Atomic">Atomic Representation</a><br> +<a href="#Boxed" >Boxed Representation</a><br> +<a href="#Tree" >Tree Representation</a><br> +<a href="#Linear">Linear Representation</a><br><br> + +<hr> +<br> + +<a name="Atomic"></a><font size="5"><b>Atomic Representation</b></font><br><br> + +<tt>5!:1 </tt>is a verb that applies to a boxed name, and produces +the <i>atomic representation</i> of the named object. +<a name="gerund">Gerunds (results of the<tt> ` </tt>conjunction) +are arrays of atomic representations. +The adverb<tt> 5!:0 </tt>defines an object from its representation.<br><br> + +The atomic representation is a boxed list of two boxes:<br> + +<table> +<tr><td><tt> </tt></td><td>noun </td><td>symbol value </td></tr> +<tr><td> </td><td>verb </td><td>symbol arguments</td></tr> +<tr><td> </td><td>adverb </td><td>symbol arguments</td></tr> +<tr><td> </td><td>conjunction </td><td>symbol arguments</td></tr> +</table><br> + +The symbol is a string computed by +function<tt> <a href="iojSent.htm#spellout">spellout</a> </tt>in file ws.c. +For a primitive with an assigned symbol +(for example<tt> + </tt>or<tt> /.</tt>),<tt> </tt> +the symbol is simply that word; for those without, the symbol is +one of the following:<br><br> + +<pre> + '0' <font size=3 face="Times New Roman">noun</font> + '2' <font size=3 face="Times New Roman">hook</font> + '3' <font size=3 face="Times New Roman">fork</font> + '4' <font size=3 face="Times New Roman">bonded conjunction</font> + '5' <font size=3 face="Times New Roman">2-element a-train or c-train</font> + '6' <font size=3 face="Times New Roman">3-element a-train or c-train</font> +</pre> + +The "value" in the representation of a noun is just the noun itself; +arguments in the representation of a verb, adverb, or conjunction are +themselves atomic representations. If an object is uniquely identified +by the symbol alone, then the second box is elided, and the representation +is the boxed symbol alone.<br><br> + +The following examples illustrate atomic representation:<br><br> +<pre> + ar=: 5!:1 + + plus=: + sum=: +/ mean=: +/ % # + ar <'plus' ar <'sum' ar <'mean'<font face="ISIJ"> +ÚÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +³+³ ³ÚÄÂÄÄÄ¿³ ³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ +ÀÄÙ ³³/³ÚÄ¿³³ ³³3³ÚÄÄÄÄÄÄÄÂÄÂÄ¿³³ + ³³ ³³+³³³ ³³ ³³ÚÄÂÄÄÄ¿³%³#³³³ + ³³ ³ÀÄÙ³³ ³³ ³³³/³ÚÄ¿³³ ³ ³³³ + ³ÀÄÁÄÄÄÙ³ ³³ ³³³ ³³+³³³ ³ ³³³ + ÀÄÄÄÄÄÄÄÙ ³³ ³³³ ³ÀÄÙ³³ ³ ³³³ + ³³ ³³ÀÄÁÄÄÄÙ³ ³ ³³³ + ³³ ³ÀÄÄÄÄÄÄÄÁÄÁÄÙ³³ + ³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³ + ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ</font> + +`(+/)`(+/ % #)<font face="ISIJ"> +ÚÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +³+³ÚÄÂÄÄÄ¿³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ +³ ³³/³ÚÄ¿³³³3³ÚÄÄÄÄÄÄÄÂÄÂÄ¿³³ +³ ³³ ³³+³³³³ ³³ÚÄÂÄÄÄ¿³%³#³³³ +³ ³³ ³ÀÄÙ³³³ ³³³/³ÚÄ¿³³ ³ ³³³ +³ ³ÀÄÁÄÄÄÙ³³ ³³³ ³³+³³³ ³ ³³³ +³ ³ ³³ ³³³ ³ÀÄÙ³³ ³ ³³³ +³ ³ ³³ ³³ÀÄÁÄÄÄÙ³ ³ ³³³ +³ ³ ³³ ³ÀÄÄÄÄÄÄÄÁÄÁÄÙ³³ +³ ³ ³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³ +ÀÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ</font> + a=: 5 xenos=: !: + ar <'a' ar <'xenos' ar <'ar'<font face="ISIJ"> +ÚÄÄÄÄÄ¿ ÚÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +³ÚÄÂÄ¿³ ³!:³ ³ÚÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ +³³0³5³³ ÀÄÄÙ ³³!:³ÚÄÄÄÄÄÂÄÄÄÄÄ¿³³ +³ÀÄÁÄÙ³ ³³ ³³ÚÄÂÄ¿³ÚÄÂÄ¿³³³ +ÀÄÄÄÄÄÙ ³³ ³³³0³5³³³0³1³³³³ + ³³ ³³ÀÄÁÄÙ³ÀÄÁÄÙ³³³ + ³³ ³ÀÄÄÄÄÄÁÄÄÄÄÄÙ³³ + ³ÀÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³ + ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ</font> + lgamma=: ^.@!@<: + ar <'lgamma'<font face="ISIJ"> +ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ +³³@³ÚÄÄÄÄÄÄÄÄÄÄÂÄÄ¿³³ +³³ ³³ÚÄÂÄÄÄÄÄÄ¿³<:³³³ +³³ ³³³@³ÚÄÄÂÄ¿³³ ³³³ +³³ ³³³ ³³^.³!³³³ ³³³ +³³ ³³³ ³ÀÄÄÁÄÙ³³ ³³³ +³³ ³³ÀÄÁÄÄÄÄÄÄÙ³ ³³³ +³³ ³ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÙ³³ +³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³ +ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ</font> +</pre> +<br> + +<a name="Boxed"></a><font size="5"><b>Boxed Representation</b></font><br><br> + +<tt>5!:2 </tt>is a verb that applies to a boxed name, and produces +the <i>boxed representation</i> of the named object. The representation +can be modelled as follows:<br><br> + +<pre> +ar =: 5!:1 +boxed =: 32&=@(3!:0) +oarg =: >@(1&{) + +bxroot =: (<1 0)&C.@,`] @. (e.&(,&.>'0123456789')@[) + +bxx =: {. bxroot bx&.>@oarg +bxgl =: {. bxroot (bxx&.>@{. , bx &.>@}.)@oarg +bxgr =: {. bxroot (bx &.>@{. , bxx&.>@}.)@oarg +bxg =: bxgr`bxgl`bxx @. (i.&(<,'`')@oarg) +bxtil =: bxx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +bxcase =: oarg`bxgl`bxgl`bxg`bxtil`bxx @. ((;:'0@.`:4~')&i.@{.) +bx =: ]`bxcase @. boxed + +brep =: ,@<`[ @. boxed @ bx @ > @ ar + + brep <'brep'<font face="ISIJ"> +ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄÄ¿ +³ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄ¿³@³ar³ +³³ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄÄ¿³@³>³³ ³ ³ +³³³ÚÄÄÄÄÄÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄ¿³@³bx³³ ³ ³³ ³ ³ +³³³³ÚÄÄÄÄÄÄÄÂÄ¿³@.³boxed³³ ³ ³³ ³ ³³ ³ ³ +³³³³³ÚÄÂÄÂÄ¿³[³³ ³ ³³ ³ ³³ ³ ³³ ³ ³ +³³³³³³,³@³<³³ ³³ ³ ³³ ³ ³³ ³ ³³ ³ ³ +³³³³³ÀÄÁÄÁÄÙ³ ³³ ³ ³³ ³ ³³ ³ ³³ ³ ³ +³³³³ÀÄÄÄÄÄÄÄÁÄÙ³ ³ ³³ ³ ³³ ³ ³³ ³ ³ +³³³ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÁÄÄÄÄÄÙ³ ³ ³³ ³ ³³ ³ ³ +³³ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÄÙ³ ³ ³³ ³ ³ +³ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÙ³ ³ ³ +ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÄÙ</font> +</pre> + +The model is divided into groups of verbs. +The first group are utilities: <br> + +<table> +<tr><td> </td> + <td><tt>ar </tt></td> + <td>atomic representation</td> +</tr> +<tr><td> </td> + <td><tt>boxed</tt></td> + <td>1 if boxed</td></tr> +<tr><td> </td> + <td><tt>oarg</tt></td> + <td>open the second element of the list argument</td> +</tr> +</table> +<br> + +<tt>bxroot </tt>produces an infix representation from a +root<tt> r </tt>and its list of arguments<tt> a</tt>.<tt> </tt> +If<tt> r </tt>is a digit, it denotes a primitive without an assigned word +(e.g.<tt> '3' </tt>denotes a fork; +see <a href="#Atomic">Atomic Representation</a>), +and the result of<tt> bxroot </tt>is<tt> a</tt>;<tt> </tt> +otherwise,<tt> r bxroot a </tt>produces:<br> + +<table> +<tr><td> </td> + <td><tt>a,r</tt></td> + <td>if one argument</td> +</tr> +<tr><td> </td> + <td><tt>({.a),r,(}.a) </tt></td> + <td>if two arguments</td> +</tr> +<tr><td> </td> + <td><tt>r</tt></td> + <td>if no arguments (primitive)</td> +</tr> +</table> +<br> + +The other verbs named with the<tt> bx </tt>prefix apply to the +opened atomic representation, and embody logic to effect "nice" +displays for various special cases. The agenda items +in<tt> bxcase </tt>are:<br><br> + +<table> +<tr><td> </td><td>ID</td><td colspan=2> Agenda</td></tr> +<tr><td> </td> + <td><tt>0 </tt></td> + <td><tt>oarg </tt></td> + <td>noun (leaf)</td> +</tr> +<tr><td> </td> + <td><tt>@.</tt></td> + <td><tt>bxgl</tt></td> + <td>gerundial left subtree</td> +</tr> +<tr><td> </td> + <td><tt>`:</tt></td> + <td><tt>bxgl</tt></td> + <td>gerundial left subtree</td> +</tr> +<tr><td> </td> + <td><tt>4</tt></td> + <td><tt>bxg</tt></td> + <td>bonded conjunction; gerundial left or right subtree</td> +</tr> +<tr><td> </td> + <td><tt>~</tt></td> + <td><tt>bxtil</tt></td> + <td>possible instance of<i> evoke</i></td> +</tr> +<tr><td> </td> + <td>other</td> + <td><tt>bxx</tt></td> + <td>none of the above</td> +</tr> +</table> +<br> + +<tt>brep </tt>is a model of<tt> 5!:2</tt>.<br><br> + +<br> + +<a name="Tree"></a><p><font size="5"><b>Tree Representation</b></font><br><br> + +<tt>5!:4 </tt>is a verb that applies to a boxed name, and produces a literal +table of the <i>tree representation</i> of the named object. Thus:<br><br> + +<pre> + tree=: connect @ > @ (,.&.>/) @ ('0'&root ; ]) @ (tr@>@ar) + 5!:4 <'tree'<font face="ISIJ"> + ÚÄ connect + ÚÄ @ ÄÁÄ > + ÚÄ @ Ä´ ÚÄ ,. + ³ ÀÄ / ÄÄÄ &. ÄÄÄÄÁÄ > + ³ + ÚÄ @ Ä´ ÚÄ '0' + ³ ³ ÚÄ & ÄÁÄ root + ³ ÀÄÄÄÄÄÅÄ ; + ³ ÀÄ ] +ÄÄ @ Ä´ + ³ ÚÄ tr + ³ ÚÄ @ ÄÁÄ > + ÀÄ @ ÄÁÄ ar </font> +</pre> + +The tree representation can be modelled as follows:<br><br> + +<pre> +ar =: 5!:1 +lr =: 3 : '5!:5 <''y.''' +boxed =: 32&= @ (3!:0) +mt =: 0&e.@$ +oarg =: >@(1&{) +shr =: |.!.'' +shl =: 1&(|.!.'') +mat =: (1 1&}.)@(_1 _1&}.)@":@< +boxc =: {. 9!:6 '' +dash =: 10{boxc + +extent =: (+./\ *. +./\.) @ (' '&~:) @: ({."1) +limb1 =: 1&|.@$ 1&~: }. (10 6 0{boxc)&,@($&(9{boxc)) +limb =: -@(i.&1)@[ |. #@[ {. limb1@] +pfx =: (limb +/)@extent ,. ] +pad =: [ {. ] ,. dash&=@({:"1)@] { ' '&,:@($&dash)@(-&{: $) +take =: pad`($&' '@[) @. (mt@]) +rc =: #@>@{."1 ; >./@:({:@$@>) +kernt =: (0{boxc)&=@shl@[ *. ' '&~:@] +kernb =: (6{boxc)&=@] *. ' '&~:@shl@[ +kern =: (<0 0)&{&>"2 (kernt +./"1@:+. kernb) (<_1 0)&{&>"2 +gap =: ,&.>"_1 {&((0 1$' ');1 1$' ')@kern +graft =: (pfx&.>@{. 0} ]) @ (,&.>/) @ gap @ ({@rc take&.> ]) + +lab =: ,: @ (2&|.) @ ((' ',dash,dash,' ')&,) +label =: lab`((,.dash)&[) @. (e.&'0123456789'@{.) +center =: ((i.&1) -@+ <.@-:@(+/))@] |. #@] {. [ +root =: label@[ center extent@>@{.@] + +leaf =: ,@<@(((,:dash,' ')&[ center $&1@#) ,. ])@mat@": + +trx =: >@{. (root ; ]) graft@:(tr@>)@oarg +trgl =: >@{. (root ; ]) graft@:(trx@>@{. , tr @>@}.)@oarg +trgr =: >@{. (root ; ]) graft@:(tr @>@{. , trx@>@}.)@oarg +trg =: trgr`trgl`trx @. (i.&(<,'`')@oarg) +trtil =: trx`(leaf@oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +trnoun =: leaf @ lr @ oarg +trcase =: trnoun`trgl`trgl`trg`trtil`trx @. ((;:'0@.`:4~')&i.@{.) +tr =: leaf`trcase @. boxed + +rep =: [. & (((# i.@#)@,@) (@])}) +right =: (5{boxc) rep (e.&(9{boxc) *. shr"1@(e.&dash)) +cross =: (4{boxc) rep (e.&(5{boxc) *. shl"1@(e.&dash)) +left =: (3{boxc) rep (e.&(9{boxc) *. shl"1@(e.&dash)) +bot =: (7{boxc) rep (e.&(6{boxc) *. shr"1@(e.&dash)) +connect =: bot @ left @ cross @ right + +tree =: connect @ > @ (,.&.>/) @ ('0'&root ; ]) @ (tr@>@ar) +</pre> + +The model is divided into groups of definitions +(which are verbs unless indicated otherwise). +The first group are utilities:<br> + +<table> +<tr><td> </td> + <td><tt>ar </tt></td> + <td>atomic representation</td> +</tr> +<tr><td> </td> + <td><tt>boxed</tt></td> + <td>1 if boxed</td> +</tr> +<tr><td> </td> + <td><tt>mt</tt></td> + <td>1 if empty</td> +</tr> +<tr><td> </td> + <td><tt>oarg</tt></td> + <td>open the second element of the list argument</td> +</tr> +<tr><td> </td> + <td><tt>shr</tt></td> + <td>shift right</td> +</tr> +<tr><td> </td> + <td><tt>shl</tt></td> + <td>shift left</td> +</tr> +<tr><td> </td> + <td><tt>mat</tt></td> + <td>a literal matrix image of the argument</td> +</tr> +<tr><td> </td> + <td><tt>boxc</tt></td> + <td>(noun) box drawing characters</td> +</tr> +<tr><td> </td> + <td><tt>dash</tt></td> + <td>(noun) the "dash" in the set of box drawing characters</td> +</tr> +</table><br> + +A "generational tree" (GT) is a list of boxed literal +tables having the same number of rows, such that nodes at the same depth +are in the same box. For example, the GT for tree +is:<pre><font face="ISIJ"> ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄ¿ + ³ ³ ³ ³ ³ÚÄ connect³ ³ + ³ ³ ³ ³ÚÄ @ ijÀÄ > ³ ³ + ³ ³ ³ÚÄ @ ij³ ³ ³ÚÄ ,.³ + ³ ³ ³³ ³ÀÄ / ijÄÄ &. ÄÄÄijÀÄ > ³ + ³ ³ ³³ ³ ³ ³ ³ + ³ ³ÚÄ @ ij³ ³ ³ÚÄ '0' ³ ³ + ³ ³³ ³³ ³ÚÄ & ijÀÄ root ³ ³ + ³ ³³ ³ÀÄÄÄÄij³Ä ; ³ ³ ³ + ³ ³³ ³ ³ÀÄ ] ³ ³ ³ + ³ÄÄ @ ij³ ³ ³ ³ ³ ³ + ³ ³³ ³ ³ÚÄ tr ³ ³ ³ + ³ ³³ ³ÚÄ @ ijÀÄ > ³ ³ ³ + ³ ³ÀÄ @ ijÀÄ ar ³ ³ ³ ³ + ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÙ</font> +</pre> + +<tt>graft </tt>is the main verb in the next group. +The argument is a table whose rows are GTs +for the nodes at the same depth. +The result is a GT.<br><br> + +<tt>root </tt>accepts a string left argument and a GT right argument. +The result is a literal matrix +with the string centered relative to the GT.<br><br> + +<tt>leaf </tt>computes a unitary (single-element) GT from its argument.<br><br> + +<tt>tr </tt>applies to the opened atomic representation of an object +and produces a GT. The verbs named with the<tt> tr </tt>prefix embody +logic to effect "nice" displays for various special cases. +The agenda items in<tt> trcase </tt>are:<br> + +<table> +<tr><td> </td> + <td> </td> +</tr> +<tr><td> </td> + <td>ID</td> + <td colspan=2> Agenda</td> +</tr> +<tr><td> </td> + <td><tt>0 </tt></td> + <td><tt>leaf@oarg </tt></td> + <td>noun (leaf)</td> +</tr> +<tr><td> </td> + <td><tt>@.</tt></td> + <td><tt>trgl</tt></td> + <td>gerundial left subtree</td> +</tr> +<tr><td> </td> + <td><tt>`:</tt></td> + <td><tt>trgl</tt></td> + <td>gerundial left subtree</td> +</tr> +<tr><td> </td> + <td><tt>4</tt></td> + <td><tt>trg</tt></td> + <td>bonded conjunction; gerund left or right</td> +</tr> +<tr><td> </td> + <td><tt>~</tt></td> + <td><tt>trtil</tt></td> + <td>possible instance of <i>evoke</i></td> +</tr> +<tr><td> </td> + <td>other</td> + <td><tt>trx</tt></td> + <td>none of the above</td> +</tr> +</table><br> + +<tt>rep </tt>is a conjunction whose left argument is +a single literal<tt> c </tt>and whose right argument is +a proposition<tt> p</tt>,<tt> </tt> +deriving a verb such that the phrase<tt> c rep p y </tt> +replaces with<tt> c </tt>the positions +in<tt> y </tt>marked by<tt> p y</tt>.<tt> </tt> +<tt>connect </tt>substitutes<tt> </tt> +<font face="ISIJ">Á</font> (bot),<tt> </tt> +<font face="ISIJ">Ã</font> (left),<tt> </tt> +<font face="ISIJ">Å</font> (cross), and<tt> </tt> +<font face="ISIJ">´</font> (right) +at nexuses of the tree.<br><br> + +<tt>tree </tt>is a model of<tt> 5!:4</tt>.<br><br> +<br> + +<a name="Linear"></a><p><font size="5"><b>Linear Representation</b></font><br><br> + +<tt>5!:5 </tt>is a verb that applies to a boxed name, and produces a literal list +of the <i>linear representation</i> of the named object. Thus:<br><br> + +<pre> + lrep=: lr @ > @ ar + + 5!:5 <'lrep' +lr@>@ar + $ 5!:5 <'lrep' +7 +</pre> + +The linear representation can be modelled as follows:<br><br> + +<pre> +ar =: 5!:1 +boxed =: 32&= @ (3!:0) +oarg =: >@(1&{) +mtv =: i.@0: +paren =: ('('&,)@(,&')') +symb =: $&' '@(e.&'.:')@{. , ] +quote =: '''' +alp =: (,65 97+/i.26){a. +dig =: '0123456789' + +slist =: $&','@(1&=) +shape =: mtv`slist`(,&'$'@":)@.(2&<.@#)`('i.'&,@":) @. (0&e.) @ $ +vchar =: >:@(quote&=)@, quote&,@(,"e)@# , +vbox =: }. @ ; @: (','&,@paren@('<'&,)@lnoun&.>) +value =: vchar`vbox`(":!.18@,) @. (2 32&i.@(type * *@(*/)@$)) +lnoun =: shape , value + +dotco =: 2&=@# *. e.&'.:'@{: +name =: e.&alp@{. *. *./@(e.&(alp,dig,'_'))@}: *. e.&(alp,dig,'_.:')@{: +num =: e.&(dig,'_')@{. *. *./@(e.&(dig,'_ .ejdr')) +qstr =: mtv -: -.@(~:/\)@(e."e) -."e@# ] +pstr =: -.@(0&e.)@}:@(+/\)@({&1 _1 0)@('()'&i.) +nopar =: 1&=@# +. dotco +. name +. num +. qstr +. pstr +cp =: paren`] @. nopar + +bp =: ]`cp@.(' '&e.) +hfork =: }.@;@:(' '&,@bp&.>)@] +left =: bp@>@{. +right =: mtv`(cp@>@{:)@.(1&<@#) +ins =: left@] , symb@>@[ , right@] +act =: ;@:(cp&.>)@] +insert =: hfork`hfork`act`act`act`ins @. ('23456'&i.@{.@>@[) + +lx =: {. insert lr&.>@oarg +ltie =: lr`(}.@;@:('`'&,@cp@lr&.>)@oarg) @. ((<,'0')&=@{.) +lgl =: {. insert (ltie&.>@{. , lr &.>@}.)@oarg +lgr =: {. insert (lr &.>@{. , ltie&.>@}.)@oarg +lg =: lgr`lgl`lx @. (i.&(<,'`')@oarg) +ltil =: lx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +lcase =: (cp@lnoun@oarg)`lgl`lgl`lg`ltil`lx @. ((;:'0@.`:4~')&i.@{.) +lr =: symb`lcase@.boxed + +lrep =: lr @ > @ ar +</pre> + +<br> +<hr> + +<a href="iojDisp.htm">Next</a> + • +<a href="iojAdv.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojSent.htm @@ -0,0 +1,331 @@ +<html> + +<head> +<title>An Implementation of J -- Interpreting a Sentence</title> +</head> + +<body> + +<p align=center><font size="6"><b>Interpreting a Sentence</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<a href="#Word Formation" >Word Formation</a><br> +<a href="#Parsing" >Parsing</a><br> +<a href="#Trains" >Trains</a><br> +<a href="#Name Resolution">Name Resolution</a><br><br> + +<hr> +<br> + +<a name="Word Formation"></a><font size="5"><b>Word Formation</b></font><br><br> + +Words are expressed in the standard ASCII alphabet. +Primitive words are spelled with one or two letters; +two letter words end with a period or a colon. +The entire spelling scheme is shown in the <a href="iojSumm.htm">system summary</a>. +The verb<tt> ;: </tt>facilitates exploration of the rhematic rules. Thus:<br><br> + +<pre> + ;: 'sum =:+/_6.95*i.3 4'<font size=2 face="ISIJ"> +ÚÄÄÄÂÄÄÂÄÂÄÂÄÄÄÄÄÂÄÂÄÄÂÄÄÄ¿ +³sum³=:³+³/³_6.95³*³i.³3 4³ +ÀÄÄÄÁÄÄÁÄÁÄÁÄÄÄÄÄÁÄÁÄÄÁÄÄÄÙ</font></pre> +The source code for word formation is in the files w*.c. +The process is controlled by the function<tt> wordil </tt>(word index and length) +and the table<tt> state</tt>.<tt> </tt>Rows of<tt> state </tt>correspond +to 10 states; columns to 9 character classes. +Each table entry is a (new state, function) pair. +Starting at state<tt> S</tt>,<tt> </tt>a sentence is scanned from left to right +one character at a time; the table entry corresponding to the +current state and character class is applied.<br><br> + + New State/Function + States + Character Classes +<pre> +XN S AN NN AN 9N XN XN QN S Space X Other +XI SI AI NI AI 9I X X QI X Other S Space +XI SI A A A A X X QI A Alphanumeric A Letters excl. NB +XI SI A A NB A X X QI N N N The letter N +XI SI A A A A NZ X QI NB NB B The letter B +Z Z Z Z Z Z X X Z NZ NB. 9 Digits and _ +XI SI 9 9 9 9 9 X QI 9 Numeric D . Period +Q Q Q Q Q Q Q Q QQ Q Quote C : Colon +XI SI AI NI AI 9I XI XI Q QQ Even Quotes Q ' Quote +Z Z Z Z Z Z Z Z Z Z Trailing Comment + +X S A N B 9 D C Q <font size=3 face="Times New Roman">Function</font> + I j=:i [ Emit(j,i-1) + N j=:i +</pre> + +<tt>Emit(j,i-1) </tt>produces a pair of indices delimiting a word +in the string.<tt> i </tt>is the current index, and<tt> j </tt>is an internal +register; if the current word is a number immediately following a numeric +list (one or more numbers),<tt> Emit </tt>combines their indices to form +a single word. At the end of the string,<tt> Emit(j,i-1) </tt>is executed.<br><br> + +As an example, this process is applied +to<tt> sum =:+/_6.95*i.3 4</tt>,<tt> </tt>the sentence used above. +In the following table, the columns are: +index, character in the string, +the (current state, character class) pair, +the (new state, function) pair, +and the action. For example, the first step is step 0, +the letter is<tt> s</tt>,<tt> </tt>the current (and initial) state +is<tt> S</tt>,<tt> </tt>and the character class is<tt> A</tt>.<tt> </tt>From +the table, the entry in row<tt> S </tt>and +column<tt> A </tt>is<tt> AN</tt>,<tt> </tt>meaing the new state +is<tt> A </tt>and the function code is<tt> N</tt>.<tt> </tt>The action +assigns 0 to<tt> j</tt>.<br><br> + +<table> +<tr> +<td> </td> +<td> </td> +<td align=center>State /</td> +<td align=center>New State /</td> +<td> </td> +</tr> + +<tr> +<td>i </td> +<td align=center>Char</td> +<td align=center>Char Class</td> +<td align=center>Function</td> +<td align=center>Action</td> +</tr> + +<tr> <td>0 </td> <td align=center><tt>s</tt></td> <td align=center><tt>S A</tt></td> <td align=center><tt>AN </tt></td> <td><tt>j=:0</tt> </td> </tr> +<tr> <td>1 </td> <td align=center><tt>u</tt></td> <td align=center><tt>A A</tt></td> <td align=center><tt>A </tt></td> <td> </td> </tr> +<tr> <td>2 </td> <td align=center><tt>m</tt></td> <td align=center><tt>A A</tt></td> <td align=center><tt>A </tt></td> <td> </td> </tr> +<tr> <td>3 </td> <td align=center><tt> </tt></td> <td align=center><tt>A S</tt></td> <td align=center><tt>SI </tt></td> <td><tt>j=:3 [ Emit(0,2) </tt></td> <td><tt> sum</tt></td> </tr> +<tr> <td>4 </td> <td align=center><tt>=</tt></td> <td align=center><tt>S X</tt></td> <td align=center><tt>XN </tt></td> <td><tt>j=:4 </tt></td> </tr> +<tr> <td>5 </td> <td align=center><tt>:</tt></td> <td align=center><tt>X C</tt></td> <td align=center><tt>X </tt></td> <td> </td> </tr> +<tr> <td>6 </td> <td align=center><tt>+</tt></td> <td align=center><tt>X X</tt></td> <td align=center><tt>XI </tt></td> <td><tt>j=:6 [ Emit(4,5) </tt></td> <td><tt> =:</tt></td> </tr> +<tr> <td>7 </td> <td align=center><tt>/</tt></td> <td align=center><tt>X X</tt></td> <td align=center><tt>XI </tt></td> <td><tt>j=:7 [ Emit(6,6) </tt></td> <td><tt> +</tt></td> </tr> +<tr> <td>8 </td> <td align=center><tt>_</tt></td> <td align=center><tt>X 9</tt></td> <td align=center><tt>9I </tt></td> <td><tt>j=:8 [ Emit(7,7) </tt></td> <td><tt> /</tt></td> </tr> +<tr> <td>9 </td> <td align=center><tt>6</tt></td> <td align=center><tt>9 9</tt></td> <td align=center><tt>9 </tt></td> <td> </td> </tr> +<tr> <td>10</td> <td align=center><tt>.</tt></td> <td align=center><tt>9 D</tt></td> <td align=center><tt>9 </tt></td> <td> </td> </tr> +<tr> <td>11</td> <td align=center><tt>9</tt></td> <td align=center><tt>9 9</tt></td> <td align=center><tt>9 </tt></td> <td> </td> </tr> +<tr> <td>12</td> <td align=center><tt>5</tt></td> <td align=center><tt>9 9</tt></td> <td align=center><tt>9 </tt></td> <td> </td> </tr> +<tr> <td>13</td> <td align=center><tt>*</tt></td> <td align=center><tt>9 X</tt></td> <td align=center><tt>XI </tt></td> <td><tt>j=:13 [ Emit(8,12) </tt></td> <td><tt> _6.95</tt></td> </tr> +<tr> <td>14</td> <td align=center><tt>i</tt></td> <td align=center><tt>X A</tt></td> <td align=center><tt>AI </tt></td> <td><tt>j=:14 [ Emit(13,13)</tt></td> <td><tt> *</tt></td> </tr> +<tr> <td>15</td> <td align=center><tt>.</tt></td> <td align=center><tt>A D</tt></td> <td align=center><tt>X </tt></td> <td> </td> </tr> +<tr> <td>16</td> <td align=center><tt>3</tt></td> <td align=center><tt>X 9</tt></td> <td align=center><tt>9I </tt></td> <td><tt>j=:16 [ Emit(14,15)</tt></td> <td><tt> i.</tt></td> </tr> +<tr> <td>17</td> <td align=center><tt> </tt></td> <td align=center><tt>9 S</tt></td> <td align=center><tt>SI </tt></td> <td><tt>j=:17 [ Emit(16,16)</tt></td> <td><tt> 3</tt></td> </tr> +<tr> <td>18</td> <td align=center><tt>4</tt></td> <td align=center><tt>S 9</tt></td> <td align=center><tt>9N </tt></td> <td><tt>j=:18 </tt></td> </tr> +<tr> <td>19</td> <td align=center><tt> </tt></td> <td align=center><tt> </tt></td> <td align=center><tt> </tt></td> <td><tt> Emit(18,18)</tt></td> <td><tt> 4</tt></td> </tr> +</table><br> + +<a name="ID"></a>Every primitive word has an ID (a unique byte value) +defined in file jc.h. +The ID for the first 128 ASCII characters are simply the byte values 0 to 127; +other IDs are arbitrary assignments in "dictionary order". + +<pre> + ... + #define CLPAR '(' /* 40 050 28 */ + #define CRPAR ')' /* 41 051 29 */ + #define CSTAR '*' /* 42 052 2a */ + #define CPLUS '+' /* 43 053 2b */ + ... + #define CASGN '\200' /* 128 200 80 =. */ + #define CGASGN '\201' /* 129 201 81 =: */ + #define CFLOOR '\202' /* 130 202 82 <. */ + #define CMIN '\202' /* 130 202 82 <. */ + #define CLE '\203' /* 131 203 83 <: */ + #define CCEIL '\204' /* 132 204 84 >. */ + #define CMAX '\204' /* 132 204 84 >. */ + #define CGE '\205' /* 133 205 85 >: */ + ... +</pre> + +Using mnemonics such as<tt> CPLUS </tt>and<tt> CASGN </tt>instead +of<tt> '+' </tt>and<tt> '\200' </tt>makes the source code more readable +and more amenable to automatic manipulation.<br><br> + +The 3-row table<tt> <a name="spell">spell</a> </tt>in file ws.c associates letter +sequences with IDs. +The rows correspond to letters in the range ASCII 32 to 127, +those letters <a name="inflect">inflected</a> by a period, +and those letters inflected by a colon; +table entries are IDs. Thus:<br><br> + +<pre> + static C spell[3][68]={ + '=', '<', '>', '_', '+', '*', ..., + CASGN, CFLOOR, CCEIL, 1, CPLUSDOT,CSTARDOT, ..., + CGASGN, CLE, CGE, CFCONS, CPLUSCO, CSTARCO, ..., + }; +</pre> + +For example, the first column specifies that<tt> =. </tt>has the +ID<tt> CASGN </tt>(assignment) and<tt> =: </tt>the ID<tt> CGASGN </tt> +(global assignment).<br><br> + +<tt>spell </tt>is used by functions<tt> <a name="spellin">spellin</a> </tt> +and<tt> <a name="spellout">spellout</a></tt>:<tt> </tt> +given a string (e.g.<tt> =:</tt>),<tt> spellin </tt>computes the +ID (<tt>CASGN</tt>); given the ID,<tt> spellout </tt>computes the +corresponding string.<br><br> + +Using the information computed by<tt> wordil</tt>,<tt> </tt> +functions<a name="tokens"></a><tt> tokens +</tt>and<a name="enqueue"></a><tt> enqueue </tt>transform a string into a list of nouns, verbs, +adverbs, conjunctions, etc. The next step is to parse this "tokenized" +form of the sentence.<br><br> + +<br> + +<a name="Parsing"></a><p><font size="5"><b>Parsing</b></font><br><br> + +Parsing occurs after word formation and is controlled by +function<tt> parse </tt>and table<tt> cases </tt> in file p.c.<tt> cases </tt> +is a direct translation of the parse table in Section II E of the dictionary: + +<pre> + #define AVN ( ADV+VERB+NOUN) + #define CAVN (CONJ+ADV+VERB+NOUN) + #define EDGE (MARK+ASGN+LPAR) + + PT cases[] = { + EDGE, VERB, NOUN, ANY, monad, ..., 1,2, ..., + EDGE+AVN, VERB, VERB, NOUN, monad, ..., 2,3, ..., + EDGE+AVN, NOUN, VERB, NOUN, dyad, ..., 1,3, ..., + EDGE+AVN, VERB+NOUN, ADV, ANY, adv, ..., 1,2, ..., + EDGE+AVN, VERB+NOUN, CONJ, VERB+NOUN, conj, ..., 1,3, ..., + EDGE+AVN, VERB, VERB, VERB, trident, ..., 1,3, ..., + EDGE, CAVN, CAVN, CAVN, trident, ..., 1,3, ..., + EDGE, CAVN, CAVN, ANY, bident, ..., 1,2, ..., + NAME+NOUN, ASGN, CAVN, ANY, is, ..., 0,2, ..., + LPAR, CAVN, RPAR, ANY, punc, ..., 0,2, ..., + }; +</pre> + +The sentence to be parsed is prefaced with a marker and placed on a queue, +and as parsing proceeds words are moved from the right end of +the queue onto a stack. The classes of the first four words on the stack +are compared to the patterns in columns 0 to 3 of<tt> cases</tt>.<tt> </tt> +The first row matching in all four columns is selected; +the action in column 4 is applied to the words on the stack indicated by +the inclusive indices in columns 8 and 9, with the result replacing +those words. If none of the rows match, the word at the end of the queue +is moved onto the stack by the function<tt> move</tt>.<tt> </tt> +Scanning for a matching pattern then begins anew. +The process terminates when the queue is empty and none of the rules +are applicable. +At that time, the stack should have exactly two words: +the marker and a noun, verb, adverb, or conjunction; +anything else signals syntax error.<br><br> + +This parsing method was first described in +<a href="iojBib.htm#Iverson1983">Iverson</a> [1983]. +The parse table is a compact representation of a large amount +of information; it has guided both the evolution of the language +and its implementation. The following example illustrates parsing +on the sentence<tt> ((i.#y)=i.~y)#y </tt>where<tt> y=:'abc'</tt>. +(<a name="Marker"></a><tt>§ </tt>denotes the marker.)<br><br> + Rule/<br> + Queue + Stack + Action + Comment +<pre> +§((i.#y)=i.~y)#y original sentence +§((i.#y)=i.~y)# 'aba' 13 move +§((i.#y)=i.~y) #'aba' 13 move +§((i.#y)=i.~y )#'aba' 13 move +§((i.#y)=i.~ 'aba')#'aba' 13 move + +§((i.#y)=i. ~'aba')#'aba' 13 move +§((i.#y)= i.~'aba')#'aba' 13 move +§((i.#y) =i.~'aba')#'aba' 13 move +§((i.#y) =v0 'aba')#'aba' 3 adv v0=: i.~ +§((i.#y )=v0 'aba')#'aba' 13 move + +§((i.# 'aba')=v0 'aba')#'aba' 13 move +§((i. #'aba')=v0 'aba')#'aba' 13 move +§(( i.#'aba')=v0 'aba')#'aba' 13 move +§( (i.#'aba')=v0 'aba')#'aba' 13 move +§( (i.3)=v0 'aba')#'aba' 1 monad 3 -: #'aba' + +§( (0 1 2)=v0 'aba')#'aba' 0 monad 0 1 2 -: i.3 +§( 0 1 2=v0 'aba')#'aba' 12 punc +§( 0 1 2=0 1 0)#'aba' 1 monad 0 1 0 -: v0 'aba' +§ (0 1 2=0 1 0)#'aba' 13 move +§ (1 1 0)#'aba' 2 dyad 1 1 0 -: 0 1 2=0 1 0 + +§ 1 1 0#'aba' 12 punc + §1 1 0#'aba' 13 move + §'ab' 2 dyad +</pre> +<br> + +<a name="Trains"></a><p><font size="5"><b>Trains</b></font><br><br> + +A <i>train</i> is an isolated phrase not interpreted by the parsing +rules pertaining to verbs, adverbs, and conjunctions, and +(as a matter of language design) may be assigned any meaning whatsoever. +<a href="iojBib.htm#Iverson1989">Iverson and McDonnell</a> [1989] +defined a train of three verbs as a +<a name="fork"></a><i>fork</i> and a train of +two verbs as a <a name="hook"></a><i>hook</i>. That is, +if<tt> f</tt>,<tt> g</tt>,<tt> </tt>and<tt> h </tt>are verbs, then +so are<tt> (f g h) </tt>and<tt> (g h)</tt>,<tt> </tt>and:<br> + +<pre> + <font size=3 face="Times New Roman">Fork</font> <font size=3 face="Times New Roman">Hook</font> + g g g g + / \ / \ / \ / \ + f h f h y h x h + | | /\ /\ | | + y y x y x y y y +</pre> + +Parsing rules 5, 6, and 7 deal with trains. +(See <a href="#Parsing">Parsing</a>.) +A consequence of the rules is that a train of verbs is resolved +by repeated forming a fork from the <i>rightmost</i> three verbs, with a +final hook if the train is of even length. Likewise, a train +of adverbs and conjunctions is assigned a meaning, and is +resolved by repeatedly forming a +group from the <i>leftmost</i> three adverbs or conjunctions, +with a final group of two if the train is of even length. +Trains are implemented by functions and variables of file cf.c. +The main functions are<tt> <a name="folk"></a>folk </tt> +and<tt> hook</tt>.<tt> </tt>(<tt>fork </tt>conflicts with UNIX usage.)<br><br> + +<br> + +<a name="Name Resolution"></a><p><font size="5"><b>Name Resolution</b></font><br><br> + +During parsing, words are moved from the queue to the stack. +Suppose a name<tt> xyz </tt>is being moved. +If<tt> xyz </tt>is immediately to the left of a copula, it (as a name) +is put on the stack. Otherwise, if<tt> xyz </tt>denotes a noun, +that noun is put on the stack; if<tt> xyz </tt>denotes a verb, +adverb, or conjunction,<tt> 'xyz'~ </tt>is put on the stack, +to be evaluated when the verb, adverb, or conjunction is applied.<br><br> + +Names and their assigned values are stored in symbol tables. +A symbol table is an <a href="iojNoun.htm#Arrays">array</a> of type<tt> SYMB </tt>whose atoms +are pairs (name,value). Functions and variables in the files s*.c work with +symbols tables. In particular,<tt> symbis(a,w,symb) </tt>assigns +the name<tt> a </tt>to<tt> w </tt>in the symbol table<tt> symb</tt>,<tt> </tt> +and<tt> symbrd(w) </tt>"reads" the value of the name<tt> w</tt>.<br><br> + +<br> +<hr> + +<a href="iojNoun.htm">Next</a> + • +<a href="iojIntro.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojSp.htm @@ -0,0 +1,321 @@ +<html> + +<head> +<title>An Implementation of J -- Special Code</title> +</head> + +<body> + +<p align=center><font size="6"><b>Special Code</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +Many primitives contain special code for certain arguments +to effect time and/or space savings not available to +general arguments. +Moreover, some phrases are <a name="recognized phrase"></a>"recognized" +and are supported by special code. +For example, the dyad of the hook<tt> ($,) </tt> +is exactly the reshape of APL (denoted by <font face="Symbol">r</font>); +its implementation avoids actually ravelling the right argument, +and in so doing saves both time and space:<br><br> + +<pre> + ts=: 6!:2 , 7!:2@] + x=: 11 13 17 19 23 + y=: 29 7 23 11 19$'sesquipedalian' + + (x ($,) y) -: x $, y +1 + + ts 'x ($,) y' +0.00773981 2.09818e6 + ts 'x $, y' +0.0170125 3.14662e6 +</pre> + +Instances of such special code are listed below:<br> + +<table> + +<tr valign=top> +<td><tt> </td> +<td><tt> </tt></td> +<td> </td> +</tr> + +<tr valign=top> +<td><tt>=</tt></td> +<td>dyad</td> +<td><a name="word-parallel">word-parallel</a> operation +on Boolean arguments for the following verbs:<br> +<tt>= < <. <: > >. >: +. +: * *. *: ^ ~: | !</tt></td> +</tr> + +<tr valign=top> +<td><tt><.@f</tt></td> +<td>both</td> +<td>avoids non-integer intermediate results on extended precision integers</td> +</tr> + +<tr valign=top> +<td><tt>>.@f</tt></td> +<td>both</td> +<td>avoids non-integer intermediate results on extended precision integers</td> +</tr> + +<tr valign=top> +<td><tt>+</tt></td> +<td>dyad</td> +<td>also<tt> * </tt>and<tt> -</tt>;<tt> </tt>on Windows, +<a name="assembly code">assembly code</a> for integer arguments +for the vector-vector, +vector-scalar, and scalar-vector cases</td> +</tr> + +<tr valign=top> +<td><tt>^</tt></td> +<td>dyad</td> +<td><tt>x^y </tt>works by repeated multiplication if<tt> x </tt>is real +and<tt> y </tt>is integral +</tr> + +<tr valign=top> +<td><tt>m&|@^</tt></td> +<td>dyad</td> +<td>avoids exponentiation for extended precision arguments</td> +</tr> + +<tr valign=top> +<td><tt>m&|@(n&^)</tt></td> +<td>monad</td> +<td>avoids exponentiation for extended precision arguments</td> +</tr> + +<tr valign=top> +<td><tt>+/ .*</tt></td> +<td>dyad</td> +<td>special code</td> +</tr> + +<tr valign=top> +<td><tt>-/ .*</tt></td> +<td>monad</td> +<td>special code in general; special code for square matrices; +special code for arrays of 2-by-2 matrices</td> +</tr> + +<tr valign=top> +<td><tt>$,</tt></td> +<td>dyad</td> +<td>also<tt> ($,)"r</tt>;<tt> </tt>avoids ravel</td> +</tr> + +<tr valign=top> +<td><tt>f;.1</td> +<td>both</td> +<td>also<tt> f;._1 f;.2 f;._2</tt>;<tt> </tt> +avoids building argument cells for several verbs:<tt> < $ , # [ ] {. {: +<@}. <@}: </tt>; also<tt> <&}. <@:}. </tt>etc.</td> +</tr> + +<tr valign=top> +<td><tt>f;.3</td> +<td>both</td> +<td>also<tt> f;._3</tt>;<tt> </tt> +special code for matrix right arguments</td> +</tr> + +<tr valign=top> +<td><tt>#</td> +<td>dyad</td> +<td>special code for Boolean left arguments</td> +</tr> + +<tr valign=top> +<td><tt># i.@#</td> +<td>monad</td> +<td>also<tt> (# i.&#)</tt>,<tt> </tt>etc.;<tt> </tt> +avoids<tt> i. </tt>on Boolean arguments</td> +</tr> + +<tr valign=top> +<td><tt>#: i.@(*/)</td> +<td>monad</td> +<td>also<tt> (#: i.&(*/))</tt>,<tt> </tt>etc.;<tt> </tt> +special code for non-negative integer vectors</td> +</tr> + +<tr valign=top> +<td><tt>=/</tt></td> +<td>monad</td> +<td>also<tt> < <: > >: +. +: * *. *: ~:</tt>;<tt> </tt> +word-parallel operations on Boolean arguments</td> +</tr> + +<tr valign=top> +<td><tt>+/</tt></td> +<td>monad</td> +<td>also<tt> * </tt>and<tt> -</tt>;<tt> </tt>on Windows, +assembly code for integer arguments</td> +</tr> + +<tr valign=top> +<td><tt>,/</tt></td> +<td>monad</td> +<td>linear time</td> +</tr> + +<tr valign=top> +<td><tt>,./</tt></td> +<td>monad</td> +<td>linear time</td> +</tr> + +<tr valign=top> +<td><tt>,.&.>/</tt></td> +<td>monad</td> +<td>linear time</td> +</tr> + +<tr valign=top> +<td><tt>;/</tt></td> +<td>monad</td> +<td>linear time</td> +</tr> + +<tr valign=top> +<td><tt>f/@,</tt></td> +<td>monad</td> +<td>also<tt> f/@:, f/&, f/&:,</tt>;<tt> </tt>avoids ravel</td> +</tr> + +<tr valign=top> +<td><tt>#/.</tt></td> +<td>dyad</td> +<td>avoids building argument cells</td> +</tr> + +<tr valign=top> +<td><tt>/:</tt></td> +<td>both</td> +<td>also<tt> \:</tt>;<tt> </tt>special code for several data types; +special code for arguments with 5 items or less</td> +</tr> + +<tr valign=top> +<td><tt>=/\</tt></td> +<td>monad</td> +<td>also<tt> +. *. ~:</tt>;<tt> </tt> +word-parallel operations on Boolean arguments</td> +</tr> + +<tr valign=top> +<td><tt>+/\</tt></td> +<td>monad</td> +<td>also<tt> * </tt>and<tt> -</tt>;<tt> </tt>on Windows, +assembly code for integer arguments</td> +</tr> + +<tr valign=top> +<td><tt>=/\.</tt></td> +<td>monad</td> +<td>also<tt> < <: > >: +. +: *. *: ~:</tt>;<tt> </tt> +word-parallel operations on Boolean arguments</td> +</tr> + +<tr valign=top> +<td><tt>+/\.</tt></td> +<td>monad</td> +<td>also<tt> * </tt>and<tt> -</tt>;<tt> </tt>on Windows, +assembly code for integer arguments</td> +</tr> + +<tr valign=top> +<td><tt>{</tt></td> +<td>dyad</td> +<td>special code for right arguments of several data types; +special code for integer left arguments; +special code for indexing first two axes</td> +</tr> + +<tr valign=top> +<td><tt><"1@[ { ]</tt></td> +<td>dyad</td> +<td>avoids<tt> <"1 </tt>if left argument is integer array</td> +</tr> + +<tr valign=top> +<td><tt>a=: c}x,y,:z</tt></td> +<td>-</td> +<td>avoids catenation and lamination; +<a name="in-place">in-place</a> if<tt> c </tt>is Boolean +and<tt> a </tt>is<tt> x </tt>or<tt> y</tt></td> +</tr> + +<tr valign=top> +<td><tt>y=: x i}y</tt></td> +<td>-</td> +<td>in-place</td> +</tr> + +<tr valign=top> +<td><tt>f"r</tt></td> +<td>both</td> +<td>numerous verbs have integrated rank support:<br> +<tt>= < <. <: > >. >: + +. +: * *. *: - -: % ^ ~: | |. |: $ , ,. ,: # ! +[ ] { {. {: }. }: / /: \ \. \: e. i. i: o. p. p: </tt> +</td> +</tr> + +<tr valign=top> +<td><tt>?</tt></td> +<td>monad</td> +<td>also<tt> ?.</tt>;<tt> </tt>special code if argument is identically 2</td> +</tr> + +<tr valign=top> +<td><tt>?</tt></td> +<td>dyad</td> +<td>also<tt> ?.</tt>;<tt> </tt>special code if left argument is much smaller +than right argument</td> +</tr> + +<tr valign=top> +<td><tt>E.</tt></td> +<td>monad</td> +<td>special code for Boolean and literal vector arguments</td> +</tr> + +<tr valign=top> +<td><tt>i.</tt></td> +<td>monad</td> +<td>also<tt> i:</tt>;<tt> </tt>special case for length-1 arguments</td> +</tr> + +<tr valign=top> +<td><tt>i.</tt></td> +<td>dyad</td> +<td>also<tt> e. </tt>and<tt> i:</tt>;<tt> </tt>special code for several data types; +special code for<tt> i.!.0</tt>;<tt> </tt> +special code for arguments with many identical columns</td> +</tr> + +</table><br> + +<br> +<hr> + +<a href="iojTest.htm">Next</a> + • +<a href="iojATW.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojSumm.htm @@ -0,0 +1,308 @@ +<html> + +<head> +<title>An Implementation of J -- System Summary</title> +</head> + +<body> + +<p align=center><font size="6"><b>System Summary</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> + +<table align=center> +<tr> +<td> </td> +<td> </td> +<td> </td> +<td> </td> +</tr> + +<tr><td><tt>=</tt></td> +<td><tt>sclass </tt> •<tt> eq </tt></td> +<td><tt>is </tt> </td> +<td><tt>is </tt> </td> +</tr> + +<tr><td><tt><</tt></td> +<td><tt>box </tt> •<tt> lt </tt></td> +<td><tt>floor1 </tt> •<tt> minimum </tt></td> +<td><tt>decrem </tt> •<tt> le </tt></td> +</tr> + +<tr><td><tt>></tt></td> +<td><tt>ope </tt> •<tt> gt </tt></td> +<td><tt>ceil1 </tt> •<tt> maximum </tt></td> +<td><tt>increm </tt> •<tt> ge </tt></td> +</tr> + +<tr><td><tt>_</tt></td> +<td><tt>connum </tt> </td> +<td><tt>connum </tt> </td> +<td><tt>num1 </tt> •<tt> num2 </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>+</tt></td> +<td><tt>conjug </tt> •<tt> plus </tt></td> +<td><tt>rect </tt> •<tt> gcd </tt></td> +<td><tt>duble </tt> •<tt> nor </tt></td> +</tr> + +<tr><td><tt>*</tt></td> +<td><tt>signum </tt> •<tt> tymes </tt></td> +<td><tt>polar </tt> •<tt> lcm </tt></td> +<td><tt>square </tt> •<tt> nand </tt></td> +</tr> + +<tr><td><tt>-</tt></td> +<td><tt>negate </tt> •<tt> minus </tt></td> +<td><tt>not </tt> •<tt> less </tt></td> +<td><tt>halve </tt> •<tt> match </tt></td> +</tr> + +<tr><td><tt>%</tt></td> +<td><tt>recip </tt> •<tt> divide </tt></td> +<td><tt>minv </tt> •<tt> mdiv </tt></td> +<td><tt>sqroot </tt> •<tt> root </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>%</tt></td> +<td><tt>expn1 </tt> •<tt> expn2 </tt></td> +<td><tt>logar1 </tt> •<tt> logar2 </tt></td> +<td> •<tt> powop </tt></td> +</tr> + +<tr><td><tt>$</tt></td> +<td><tt>shape </tt> •<tt> reitem </tt></td> +<td><tt>sparse1 </tt> •<tt> sparse2 </tt></td> +<td><tt>self1 </tt> •<tt> self2 </tt></td> +</tr> + +<tr><td><tt>~</tt></td> +<td><tt>swap </tt> • </td> +<td><tt>nub </tt> •<tt> </tt></td> +<td><tt>nubsieve </tt>•<tt> ne </tt></td> +</tr> + +<tr><td><tt>|</tt></td> +<td><tt>mag </tt> •<tt> residue </tt></td> +<td><tt>reverse </tt> •<tt> rotate </tt></td> +<td><tt>cant1 </tt> •<tt> cant2 </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>.</tt></td> +<td> •<tt> dot </tt></td> +<td> •<tt> even </tt></td> +<td> •<tt> odd </tt></td> +</tr> + +<tr><td><tt>:</tt></td> +<td> •<tt> colon </tt></td> +<td> •<tt> obverse </tt></td> +<td> •<tt> adverse </tt></td> +</tr> + +<tr><td><tt>,</tt></td> +<td><tt>ravel </tt> •<tt> over </tt></td> +<td><tt>table </tt> •<tt> stitch </tt></td> +<td><tt>lamin1 </tt> •<tt> lamin2 </tt></td> +</tr> + +<tr><td><tt>;</tt></td> +<td><tt>raze </tt> •<tt> link </tt></td> +<td> •<tt> cut </tt></td> +<td><tt>words </tt> •<tt> </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>#</tt></td> +<td><tt>tally </tt> •<tt> repeat </tt></td> +<td><tt>base1 </tt> •<tt> base2 </tt></td> +<td><tt>abase1 </tt> •<tt> abase2 </tt></td> +</tr> + +<tr><td><tt>!</tt></td> +<td><tt>fact </tt> •<tt> outof </tt></td> +<td> •<tt> fit </tt></td> +<td> •<tt> foreign </tt></td> +</tr> + +<tr><td><tt>/</tt></td> +<td><tt>slash </tt> • </td> +<td><tt>sldot </tt> • </td> +<td><tt>grade1 </tt> •<tt> grade2 </tt></td> +</tr> + +<tr><td><tt>\</tt></td> +<td><tt>bslash </tt> • </td> +<td><tt>bsdot </tt> • </td> +<td><tt>dgrade1 </tt> •<tt> dgrade2 </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>[</tt></td> +<td><tt>right1 </tt> •<tt> left2 </tt></td> +<td> •<tt> lev </tt></td> +<td> </td> +</tr> + +<tr><td><tt>]</tt></td> +<td><tt>right1 </tt> •<tt> right2 </tt></td> +<td> •<tt> dex </tt></td> +<td><tt>ida </tt> • </td> +</tr> + +<tr><td><tt>{</tt></td> +<td><tt>catalog </tt> •<tt> from </tt></td> +<td><tt>head </tt> •<tt> take </tt></td> +<td><tt>tail </tt> •<tt> </tt></td> +</tr> + +<tr><td><tt>}</tt></td> +<td><tt>rbrace </tt> • </td> +<td><tt>behead </tt> •<tt> drop </tt></td> +<td><tt>curtail </tt> •<tt> </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>"</tt></td> +<td> •<tt> qq </tt></td> +<td><tt>exec1 </tt> •<tt> exec2 </tt></td> +<td><tt>thorn1 </tt> •<tt> thorn2 </tt></td> +</tr> + +<tr><td><tt>`</tt></td> +<td> •<tt> tie </tt></td> +<td> </td> +<td> •<tt> evger </tt></td> +</tr> + +<tr><td><tt>@</tt></td> +<td> •<tt> atop </tt></td> +<td> •<tt> agenda </tt></td> +<td> •<tt> atco </tt></td> +</tr> + +<tr><td><tt>&</tt></td> +<td> •<tt> amp </tt></td> +<td> •<tt> under </tt></td> +<td> •<tt> ampco </tt></td> +</tr> + +<tr><td><tt>?</tt></td> +<td><tt>roll </tt> •<tt> deal </tt></td> +<td><tt>rollx </tt> •<tt> dealx </tt></td> +<td> </td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>{::</tt></td> +<td><tt>map </tt> •<tt> fetch </tt></td> +<td><tt>}:: emend </tt> •<tt> </tt></td> +<td><tt>&.: </tt> •<tt> undco </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>a.</tt></td> +<td><tt>alp </tt> </td> +<td><tt>A. adot1 </tt> •<tt> adot2 </tt></td> +<td><tt>b. bdot </tt> •<tt> </tt></td> +</tr> + +<tr><td><tt>c.</tt></td> +<td><tt>eig1 </tt> •<tt> eig2 </tt></td> +<td><tt>C. cdot1 </tt> •<tt> cdot2 </tt></td> +<td><tt>d. </tt> •<tt> ddot </tt></td> +</tr> + +<tr><td><tt>D.</tt></td> +<td> •<tt> dcap </tt></td> +<td><tt>D: </tt> •<tt> dcapco </tt></td> +<td><tt>e. razein </tt>•<tt> eps </tt></td> +</tr> + +<tr><td><tt>E.</tt></td> +<td> •<tt> ebar </tt></td> +<td><tt>f. fix </tt> • </td> +<td><tt>H. </tt> •<tt> hgeom </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>i.</tt></td> +<td><tt>iota </tt> •<tt> indexof </tt></td> +<td><tt>i: jico1 </tt> •<tt> jico2 </tt></td> +<td><tt>I. icap </tt> • </td> +</tr> + +<tr><td><tt>j.</tt></td> +<td><tt>jdot1 </tt> •<tt> jdot2 </tt></td> +<td><tt>L. level1 </tt>• </td> +<td><tt>L: </tt> •<tt> lco </tt></td> +</tr> + +<tr><td><tt>m.</tt></td> +<td><tt>xd </tt> </td> +<td><tt>n. xd </tt> </td> +<td><tt>o. pix </tt> •<tt> circle </tt></td> + +<tr><td><tt>p.</tt></td> +<td><tt>poly1 </tt> •<tt> poly2 </tt></td> +<td><tt>p: prime </tt> •<tt> </tt></td> +<td><tt>q: factor </tt>•<tt> qco2 </tt></td> +</tr> + +<tr><td> </td><td> </td><td> </td><td> </td></tr> + +<tr><td><tt>r.</tt></td> +<td><tt>rdot1 </tt> •<tt> rdot2 </tt></td> +<td><tt>S: </tt> •<tt> sco </tt></td> +<td><tt>t. tdot </tt> • </td> +</tr> + +<tr><td><tt>t:</tt></td> +<td><tt>tco </tt> • </td> +<td><tt>T. </tt> •<tt> tcap </tt></td> +<td><tt>u. xd </tt> </td> +</tr> + +<tr><td><tt>v.</tt></td> +<td><tt>xd </tt> </td> +<td><tt>x. xd </tt> </td> +<td><tt>x: xco1 </tt> •<tt> xco2 </tt></td> +</tr> + +<tr><td><tt>y.</tt></td> +<td><tt>xd </tt> </td> +<td> </td> +<td> </td> +</tr> + +</table> + +<br> +<hr> + +<a href="iojBib.htm">Next</a> + • +<a href="iojXenos.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojTest.htm @@ -0,0 +1,206 @@ +<html> + +<html> + +<head> +<title>An Implementation of J -- Test Scripts</title> +</head> + +<body> + +<p align=center><font size="6"><b>Test Scripts</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +A <em>script</em> is an ASCII text file containing J sentences; +a <em>test script</em> is script which contains purportedly +true J sentences.<br><br> + +The J test scripts are a set of about 280 scripts that +test the J interpreter. Each script tests a particular +aspect, usually a single primitive. The scripts have names of the +form<tt> gxxx.ijs</tt>,<tt> </tt>where<tt> xxx </tt> +is an encoding based on the vocabulary page of +the J dictionary. For example, the +script<tt> g022.ijs </tt> +tests the primitive<tt> >: </tt> +(increment / larger or equal), named on the basis +that<tt> >: </tt>is group 0, row 2, and column 2.<br><br> + +Test scripts require the utilities in the script<tt> tsu.ijs</tt>.<tt> </tt> +Test scripts can be run with either the<tt> 0!:2 </tt>or +the<tt> 0!:3 </tt>primitive.<br><br> + +<tt>0!:2 </tt>runs a test script <i>with</i> output, stopping at the first result +which is not all 1s, or at the first (untrapped) error. +For example:<br><br> + +<pre> + 0!:0 <'\dev\js\tsu.ijs' + 0!:2 <'\dev\js\g022.ijs' + NB. >:y ----------------------------------------------------------------- + + (>: -: 1&+) 1=?2 3 4$2 +1 + (>: -: 1&+) _1e9+?2 3 4$2e9 +1 + (>: -: 1&+) o._1e9+?2 3 4$2e9 +1 + (>: -: 1&+) j./?2 3 4$2e9 +1 + + _1 0 1 2 3 -: >: _2 _1 0 1 2 +1 + 2147483648 -: >: 2147483647 +1 + _2147483647 -: >:_2147483648 +1 + + t -: [&.>: t=._1e9+?2 3 4$2e9 +1 + + 'domain error' -: >: etx 'abc' +1 + 'domain error' -: >: etx <'abc' +1 + + + NB. x>:y ---------------------------------------------------------------- + + 1 0 1 1 -: 0 0 1 1 >: 0 1 0 1 +1 + + 'domain error' -: 'abc' >: etx 3 4 5 +1 + 'domain error' -: 'abc' >:~etx 3 4 5 +1 + 'domain error' -: 3j4 >: etx 3 4 5 +1 + 'domain error' -: 3j4 >:~etx 3 4 5 +1 + 'domain error' -: (<34) >: etx 3 4 5 +1 + 'domain error' -: (<34) >:~etx 3 4 5 +1 + + 'length error' -: 3 4 >: etx 5 6 7 +1 + + 'length error' -: 3 4 >:~etx 5 6 7 +1 + 'length error' -: (i.3 4) >: etx i.5 4 +1 + 'length error' -: (i.3 4) >:~etx i.5 4 +1 + + 4!:55 ;:'t' +1 +</pre> + +<tt>0!:3 </tt>runs a test script <i>without</i> output, returning a result of 0 +if the script had a result which is not all 1s +or if it contained an (untrapped) error, and a result of 1 otherwise. +For example:<br> + +<pre> + 0!:0 <'\dev\js\tsu.ijs' + 0!:3 <'\dev\js\g022.ijs' +1 +</pre> + +The J test scripts are divided into three groups (running times are +seconds on a Pentium III 500 MHz computer):<br> + +<table> +<tr> +<td> Type</td> +<td> </td> +<td align=center>Number</td> +<td> </td> +<td align=center>Name List</td> +<td> </td> +<td> Run</td> +<td> </td> +<td align=center>Time (Seconds)</td> +</tr> + +<tr> +<td>Ordinary</td> +<td> </td> +<td>240</td> +<td> </td> +<td><tt>ddall</tt></td> +<td> </td> +<td>rundd.ijs</td> +<td> </td> +<td>113</td> +</tr> + +<tr> +<td>Sparse Arrays</td> +<td> </td> +<td>27</td> +<td> </td> +<td><tt>ssall</tt></td> +<td> </td> +<td>runss.ijs</td> +<td> </td> +<td>1140</td><br> +</tr> + +<tr> +<td>Mapped Boxed Arrays</td> +<td> </td> +<td>12</td> +<td> </td> +<td><tt>mbxall</tt></td> +<td> </td> +<td>runmbx.ijs</td> +<td> </td> +<td>3</td> +</tr> +</table> + +<br> +For example, the "ordinary" test scripts can be run as follows:<br> +<br> +<pre> + 0!:2 <'\dev\js\rundd.ijs' + NB. run dd test scripts + + 0!:0 <'d:\dev\js\tsu.ijs' NB. define utilities + jsts0=: 6!:0 '' NB. timestamp at start + ddall=: 3!:2 (1!:1) <'d:\dev\js\ddall' NB. define namelist + ] bbb=: 0!:3 ddall NB. run the test scripts +1 1 1 1 1 1 1 1 1 1 1 1 1 ... + jsts1=: 6!:0 '' NB. timestamp at end +</pre> + +The<tt> rundd.ijs </tt>script first runs +the<tt> tsu.ijs </tt>script +(to define the requisite utilities), then +defines<tt> ddall</tt>,<tt> </tt>the list +of test script names, then runs the test scripts. The boolean +vector<tt> bbb </tt>has the same shape +as<tt> ddall</tt>,<tt> </tt>and can be used +to detect which test scripts have failed. +The bad scripts<tt> (-.b)#ddall </tt>can +be run using the<tt> 0!:2 </tt> +primitive to narrow in on the offending expressions.<br><br> + +<br> +<hr> + +<a href="iojFiles.htm">Next</a> + • +<a href="iojSp.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html>
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojVerb.htm @@ -0,0 +1,596 @@ +<html> + +<head> +<title>An Implementation of J -- Verbs</title> +</head> + +<body> + +<p align=center><font size="6"><b>Verbs</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<a href="#Anatomy">Anatomy of a Verb</a><br> +<a href="#Rank">Rank</a><br> +<a href="#Atomic">Atomic (Scalar) Verbs</a><br> +<a href="#Obverse">Obverses, Identities, and Variants</a><br> +<a href="#Errors">Error Handling</a><br><br> + +<hr> +<br> + +<a name="Anatomy"></a><font size="5"><b>Anatomy of a Verb</b></font><br><br> + +Verbs are implemented as functions. A verb applies to a noun +(if used monadically) or to two nouns (if used dyadically), +and produces a noun result. +The defined type<tt> <a name="AF">AF</a> </tt>and the +macros<tt> <a name="F1">F1</a> </tt>and<tt> <a name="F2">F2</a> </tt> +codify these properties:<br><br> + +<pre> + typedef A(*AF)(); + + #define F1(f) A f(J jt, A w); + #define F2(f) A f(J jt,A a,A w); +</pre> +<tt>AF </tt>is the data type of a function having these properties.<tt> </tt> +<tt>F1 </tt>and<tt> F2 </tt>are used to specify the headers of functions +implementing verbs (and adverbs and conjunctions); +the majority of functions in the implementation are so specified.<tt> </tt> +(<tt><a href="iojNoun.htm#jt">jt</a> </tt>is the global variables +parameter;<tt> a </tt>and<tt> w </tt>denote <font face="Symbol">a</font> +and <font face="Symbol">w</font>, traditionally the names given to +the left and right arguments of APL functions.) +Verbs are represented by arrays of type<tt> VERB</tt>;<tt> </tt> +the details of this representation are discussed in +<a href="iojAdv.htm">Adverbs and Conjunctions</a>.<br><br> + +The verb<tt> j. </tt>is used here to illustrate the relationship +among relevant system components.<tt> j. </tt>has monad<tt> 0j1&*"0 </tt> +and dyad<tt> (+j.)"0</tt>.<tt> </tt>There are three main steps in +the implementation:<br><br> + +1. Define and declare functions which implement the monad and the dyad.<br> +2. Associate<tt> j. </tt>with the functions and other information.<br> +3. Specify obverses, identity functions, and variants (if any).<br><br> + +These steps are executed as follows:<br><br> + +1. Functions which implement the monad and the dyad<tt> j. </tt>are added +to file vm.c (or to one of the v*.c files), and declarations are +added to je.h:<br><br> + +<table> +<tr><td><tt> </tt></td> + <td>File vm.c</td> + <td> </td> + <td>File je.h</td> +</tr> +<tr><td> </td> + <td><tt> F1(jtjdot1){R tymes(a0j1,w);}</tt></td> + <td> </td> + <td><tt> extern F1(jtjdot1);</tt> +</tr> +<tr><td> </td> + <td><tt> F2(jtjdot2){R plus(a,tymes(a0j1,w));}</tt></td> + <td> </td> + <td><tt> extern F2(jtjdot2);</td> +</td> +</table><br> + +2. The association between<tt> j. </tt>and<tt> jdot1 </tt>and<tt> jdot2 </tt> +is established +in the table<tt> <a name="pst"></a>pst</tt>,<tt> </tt>initialized by +functions<tt> <a name="pinit"></a>pinit </tt> +and<tt> <a name="pdef"></a>pdef </tt>in file t.c.<tt> </tt> +<tt>pst </tt>is declared as<tt> A pst[256]; </tt>, +a 256-element vector of type<tt> A</tt>,<tt> </tt> +and<tt> pst[x] </tt>contains the information for the primitive whose +<a href="iojSent.htm#ID">ID</a> is unsigned byte<tt> x</tt>.<tt> </tt>The ID +for<tt> j. </tt>is<tt> CJDOT</tt>,<tt> </tt>therefore the information +for<tt> j. </tt>can be found in<tt> pst[(UC)CJDOT]</tt>.<tt> </tt> +The surrounding entries in<tt> pst </tt>are initialized as follows; +the entry for<tt> j. </tt> indicates that it is a verb, with +monad<tt> jdot1</tt>,<tt> </tt>dyad<tt> jdot2</tt>,<tt> </tt> +and zero monadic, left, and right ranks:<br><br> + +<pre> + /* i: */ pdef(CICO, VERB, jtjico1, jtjico2, 0L, RMAX,RMAX); + /* I. */ pdef(CICAP, ADV, jticap, 0L, 0L, 0L, 0L ); + /* j. */ pdef(CJDOT, VERB, jtjdot1, jtjdot2, 0L, 0L, 0L ); + /* L. */ pdef(CLDOT, VERB, jtlevel1, 0L, RMAX,0L, 0L ); + /* L: */ pdef(CLCO, CONJ, 0L, jtlco, 0L, 0L, 0L ); +</pre> + +The macro<tt> <a name="ds"></a>ds(x) </tt>is defined +as<tt> pst[(UC)(x)]</tt>,<tt> </tt> +and is a convenient reference for a primitive; +for example,<tt> ds(CJDOT) </tt>is the verb<tt> j. </tt>as an array +(in short,<tt> ds(CJDOT) </tt><i>is</i><tt> j.</tt>).<br><br> + +3. A verb may have information additional to that in<tt> pst</tt>,<tt> </tt> +embodied in functions<tt> inv </tt>and<tt> invamp </tt>(obverses) in file +ai.c,<tt> iden </tt>(identity functions) in ai.c, and<tt> fit </tt> +(variants) in cf.c. +See <a href="#Obverse">Obverse, Identities, and Variants</a>.<br><br> + +The obverses associated with<tt> j. </tt>are:<br><br> + +<pre> + j. %&0j1 + n&j. %&0j1@(-&n) + j.&n -&(j.n) +</pre> + +The obverse of<tt> j. </tt>is implemented +as<tt> case CJDOT </tt>in<tt> inv</tt>;<tt> </tt>those +for<tt> n&j. </tt>and<tt> j.&n </tt>are implemented +as<tt> case CJDOT </tt>in<tt> invamp</tt>.<tt> </tt> +The identity function for<tt> j. </tt>is<tt> $&0@(}.@$)</tt>,<tt> </tt> +and is implemented +as<tt> case CJDOT </tt>in<tt> iden</tt>.<tt> j. </tt> +has no variants; the implementation of a variant would have +required a<tt> case </tt>in<tt> fit</tt>.<br><br> + +<br> + +<a name="Rank"></a><p><font size="5"><b>Rank</b></font><br><br> + +Verb (function) rank was introduced by Iverson [1978 §6], +further developed in Iverson [1983, 1987, 1995], +and implemented in SHARP APL, SHARP APL/HP, SAX, A, and J +(see Bernecky <i>et al</i>. [1983, 1987], Hodgkinson [1986], +Steinbrook [1986], Whitney [1989], and Hui <i>et al</i>. [1990], +respectively). This description first appeared in Hui [1995].<br><br> + +A verb of rank<tt> r </tt>is defined on arguments +with rank bounded by<tt> r</tt>;<tt> </tt> +the extension to higher-rank arguments is the same for all verbs. +The rank conjunction<tt> " </tt>(operator) augments the default ranks of +a verb by user-specified ranks. It provides for the +generalization of a verb to higher-rank arrays, +and could justifiably be called the generalization +or extension operator; it also provides for consistent application +to lower-rank arrays, subsuming and superseding +the anomalous bracket-axis operator.<br><br> + +Various aspects of rank are here discussed in terms of a model in J, +updated from Hui [1987 §A.2].<br><br> + +<b>Frames and Cells.</b> A rank<tt> r </tt>splits the argument shape into +the frame and the cell shape; a positive<tt> r </tt>specifies the number +of trailing cell axes, while a negative<tt> r </tt>specifies the +negative of the number of leading frame axes.<br><br> + +<pre> +rk =: #@$ +er =: (0:>.(+rk))`(<.rk) @. (0:<:[) +fr =: -@er }. $@] +cs =: -@er {. $@] +boxr =: ]`(<@$ , [ $: */@[}.])@.(*@#@]) +cells =: fr $ cs boxr ,@] +</pre> + +For rank<tt> r </tt>and argument<tt> y</tt>,<tt> </tt> +the phrase<tt> r er y </tt>computes +the effective rank (non-negative and bounded by<tt> #$y</tt>);<tt> </tt> +<tt>r fr y </tt>computes the frame and<tt> r cs y </tt>the cell shape; +and<tt> r cells y </tt>computes the array of +cells with shape<tt> r fr y</tt>,<tt> </tt> +each cell individually boxed and shaped<tt> s=: r cs y </tt> +(<tt>r cells y </tt>is<tt> <"r y</tt>).<tt> </tt> +The recursively-defined verb<tt> s boxr y </tt> +produces the list of such cells.<br><br> + +The model is shown in action on<tt> x*"0 _1 y</tt>,<tt> </tt> +the atoms (scalars) of<tt> x </tt>times the items of<tt> y</tt>:<br><br> + +<pre> + x=:1 2 3 + y=:i.3 2 + y x*"0 _1 y +0 1 0 1 +2 3 4 6 +4 5 12 15 + 0 er x _1 er y +0 1 + 0 fr x _1 fr y +3 3 + 0 cs x _1 cs y + 2 + 0 cells x _1 cells y<font face="ISIJ"> +ÚÄÂÄÂÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄ¿ +³1³2³3³ ³0 1³2 3³4 5³ +ÀÄÁÄÁÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÙ</font> +</pre> + +<b>Agreement.</b> In the dyad<tt> v"r</tt>,<tt> </tt>commonly the left and +right frames match, that is, the two cell arrays have the same shape; +if not, several design choices are possible: + +In <i>scalar</i> agreement, one frame must be empty, +and the single cell is reshaped using the other frame; +in <i>suffix</i> agreement, one frame must be a suffix of the other, +and again the list of cells is reshaped using the other frame; +finally, in <i>prefix</i> agreement, one frame must be a prefix of the other, +and each cell is reshaped with the excess in the other frame. +All three agreements are proper generalizations +of scalar extension in APL\360, with cells acting the role of scalars. +Agreement results in the two cell +arrays having the same shape ("the frame").<br><br> + +Prefix agreement is adopted in J as suggested by Whitney [1992], +because it best fits the emphasis on leading axes.<br><br> + +<pre> +pfx =: <.&rk +agree =: (pfx {. $@[) -: (pfx {. $@]) +frame =: [:`($@([^:(>&rk))) @. agree +rag =: frame $ ([: */ rk@]}.$@[) # ,@] +lag =: rag~ +</pre> + +<tt>rag </tt>and<tt> lag </tt>apply to both cell arrays +(the results of cells in the previous section), +producing cell arrays with the same shape. +If<tt> v"r </tt>itself were used in the model,<tt> rag </tt>could +be defined more +directly from the specification:<tt> (rk@]}.$@[) $"1 0 ] </tt>— +each cell is reshaped with the excess in the other frame. +In the continuing example, rag and lag have no effect because +the left and right frames match.<br><br> + +<pre> + [xc=.0 cells x [yc=._1 cells y<font face="ISIJ"> +ÚÄÂÄÂÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄ¿ +³1³2³3³ ³0 1³2 3³4 5³ +ÀÄÁÄÁÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÙ</font> + [xa=.xc lag yc [ya=.xc rag yc<font face="ISIJ"> +ÚÄÂÄÂÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄ¿ +³1³2³3³ ³0 1³2 3³4 5³ +ÀÄÁÄÁÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÙ</font> +</pre> + +<b>Assembly.</b> After agreement, the phrase<tt> v&.> </tt>applies<tt> v </tt> +under<tt> > </tt>to corresponding boxed left and right argument cells, +to produce an array of boxed result cells. +It remains to assemble the overall result from the individual results.<br><br> + +Cells are brought to a common rank by adding leading unit axes, +then to a common shape by padding. +The overall shape is<tt> fm,sir</tt>,<tt> </tt> +where<tt> fm </tt>is the frame and<tt> sir </tt>is the common shape +of the individual results. +This is a design choice: the individual results could be required +to have a common shape without further intervention, +but this permissive assembly proves useful. For example, +open<tt> > </tt>on a list of boxed words yields a matrix with the words +padded to a common length.<br><br> + +<pre> +mrk =: >./@:(rk&>)@, +crank =: mrk ,:@]^:(-rk)&.> ] +msh =: >./@:( $&>)@, +cshape=: <@msh {.&.> ] +asm =: > @ cshape @ crank +rank =: 2 : 0 + 'm l r'=.3&$&.|.y. + ([: asm [: x.&.> m&cells) : ([: asm l&cells@[ (lag x.&.> rag) r&cells@]) +) +</pre> + +The conjunction rank integrates the model components. +The left argument<tt> x. </tt>is the verb<tt> v</tt>;<tt> </tt> +the right argument<tt> y.</tt> +is reshaped from the right to exactly 3 numbers +and assigned to<tt> m</tt>,<tt> l</tt>,<tt> </tt>and<tt> r</tt>.<br><br> + +<pre> + [ za=. xa *&.> ya<font face=ISIJ> +ÚÄÄÄÂÄÄÄÂÄÄÄÄÄ¿ +³0 1³4 6³12 15³ +ÀÄÄÄÁÄÄÄÁÄÄÄÄÄÙ</font> + asm za + 0 1 + 4 6 +12 15 + x * rank 0 _1 y + 0 1 + 4 6 +12 15 +</pre> + +<b>Zero Frame.</b> If the frame contains 0 (as in<tt> 3*"1 i.0 4</tt>),<tt> </tt> +there are no argument cells to apply<tt> v </tt>to, +and the shape of a result cell (the value of<tt> sir</tt>)<tt> </tt> +is indeterminate. +Pesch [1986] describes a variety of strategies to address this problem. +In J, the shape is calculated if<tt> v </tt>is uniform (see below); +otherwise<tt> v </tt>is applied to a cell of fills.<br><br> + +<b>Implementation.</b> Rank is implemented by +functions<a name="rank1ex"><tt> rank1ex </tt></a> +and<a name="rank2ex"><tt> rank2ex </tt></a>("rank execution") in file cr.c. +A function<tt> f </tt>has access to the entire arguments of the verb +that it implements, regardless of the ranks of the verb. +Within<tt> f</tt>,<tt> </tt>rank effects can be achieved by +invoking<tt> rank1ex </tt>and<tt> rank2ex</tt>,<tt> </tt>mediated +by the +macros<a name="F1RANK"><tt> F1RANK </tt></a> +and<a name="F2RANK"><tt> F2RANK</tt></a>:<br><br> + +<pre> + A rank1ex( A w,A self,I m, AF f1); + A rank2ex(A a,A w,A self,I l,I r,AF f2); + + F1RANK(m, f1,self); + F2RANK(l,r,f2,self); +</pre> + +<tt>a </tt>and<tt> w </tt>are the left and right arguments of the +verb;<tt> f1 </tt>and<tt> f2 </tt>are functions which implement +the monad and dyad;<tt> m</tt>,<tt>l</tt>,<tt>r </tt>are ranks; +and<a name="self"><tt> self </tt></a>is an +<a href="iojAdv.htm#array">array representing the verb</a>. +For example, the dyad<tt> ": </tt>has ranks<tt> 1 _ </tt> +and is implemented by the function<tt> thorn2</tt>,<tt> </tt> +which uses<tt> F2RANK </tt>as follows:<br><br> + +<pre> + F2(jtthorn2){PROLOG;A da,ea,h,ma,s,y,*yv,z;B e,*ev; ... + F2RANK(1,RMAX,jtthorn2,0); + an=AN(a); t=AT(w); + ... + } +</pre> +If the argument ranks are not greater than the verb ranks, +then<tt> F2RANK </tt>(<tt>F1RANK</tt>)<tt> </tt>does nothing, +and execution proceeds to the statement following the macro; +if the argument ranks <i>are</i> greater, +then<tt> F2RANK </tt>(<tt>F1RANK</tt>)<tt> </tt> +invokes<tt> rank2ex </tt>(<tt>rank1ex</tt>),<tt> </tt> +and on return therefrom exits<tt> f </tt>with the result +obtained therefrom. +In this scheme,<tt> rank2ex </tt>(<tt>rank1ex</tt>)<tt> </tt> +invokes<tt> f </tt> repeatedly, but with arguments of +rank bounded by the verb ranks.<br><br> + +A function may implement rank by other means. For example, +the dyad<tt> { </tt>has ranks<tt> 0 _ </tt>and is implemented +by the function<tt> from</tt>,<tt> </tt>which +eschews<tt> rank2ex </tt>on numeric left arguments wherein rank +effects are uniform and rather simple.<tt> </tt>(<tt>from </tt> +does use<tt> rank2ex </tt>on boxed left arguments.) +<a href="#Atomic">Atomic verbs</a> +also implement rank independently to exploit the special properties +of such verbs.<br><br> + +Verbs derived from adverbs and conjunctions are <i>always</i> invoked +with<tt> self</tt>.<tt> </tt>The +macros<tt> <a name="PREF1">PREF1</a> </tt>and<tt> <a name="PREF2">PREF2</a> </tt> +are used in such cases, +wherein<tt> rank1ex </tt>and<tt> rank2ex </tt>are invoked with +ranks extracted from<tt> self</tt>,<tt> </tt>and not with constants +as in the use of<tt> F1RANK </tt>and<tt> F2RANK </tt> +for primitive verbs.<br><br> + +<br> + +<a name="Atomic"></a><p><font size="5"><b>Atomic (Scalar) Verbs</b></font><br><br> + +Not Yet Available<br><br> +<br> + +<p><font size="5"><b>Obverses, Identities, and Variants</b></font><br><br> + +Verbs have additional parts — obverse, identity, and variants — +which can not be specified as static data structures. +Such information is embodied in functions.<br><br> + +<font size="4">• Obverses</font><a name="obverse"></a><a name="obverse"></a><br><br> + +A verb<tt> u </tt>is an obverse (usually the inverse) of a verb<tt> v </tt> +if<tt> x=u v x </tt> +for a significant subdomain of<tt> v</tt>.<tt> </tt> +The obverse is used in the conjunctions <i>under</i><tt> </tt> +(<tt>&.</tt>)<tt> </tt>and <i>power</i><tt> </tt>(<tt>^:</tt>).<tt> </tt> +For example, exponential<tt> ^ </tt>and logarithm<tt> ^. </tt> +are obverses, and:<br><br> + +<pre> + 3 +&.^. 4 <font size=3 face="Times New Roman">is</font> ^ (^.3) + ^.4 ^ ^:_1 <font size=3 face="Times New Roman">is</font> ^. + 3 *&.^ 4 <font size=3 face="Times New Roman">is</font> ^.(^ 3) * ^ 4 ^.^:_1 <font size=3 face="Times New Roman">is</font> ^ +</pre> + +Obverses are produced by the function<a name="inv"></a><tt> inv </tt> +in file ai.c. (<tt>inv </tt>implements<tt> ^:_1.</tt>)<tt> </tt> +The logic is a combination of table look-up and nested +branch tables<tt> </tt>(<tt>switch/case</tt>).<br><br> + +<b>Primitives. </b>If the obverse of a primitive verb is itself primitive, +the information is recorded in the +2-row table<a name="invf"></a><tt> invf </tt>in file ai.c.<br><br> + +<b>Bonded Verbs. </b>Bonding (Currying) is fixing an argument of +a dyad to derive a monad:<tt> n&v </tt>or<tt> v&n</tt>.<tt> </tt> +For example,<tt> 10&^. </tt>is <i>base-10 log</i> +and<tt> ^&0.5 </tt>is <i>square root</i>. +The obverse of a bonded verb is computed by the +subfunction<a name="invamp"></a><tt> invamp </tt>in file ai.c, +invoked by<tt> inv </tt>as appropriate.<br><br> + +<b>Prefix and Suffix. </b> Sum prefix<tt> +/\ </tt>and sum +suffix<tt> +/\. </tt>can be +expressed as pre-multiplication by matrices obtained by +applying<tt> +/\ </tt>and<tt> +/\. </tt>on the identity matrix; +the obverse is therefore pre-multiplication by the +matrix inverse of these matrices. +(The actual obverse is a more efficient equivalent derived therefrom.) +Similar reasoning applies to<tt> -</tt>,<tt> *</tt>,<tt> %</tt>,<tt> </tt> +and to<tt> = </tt>and<tt> ~: </tt> +on Boolean arguments. The logic is embodied as a sub-<tt>switch </tt> +in<tt> inv</tt>,<tt> </tt> +under<tt> case CBSLASH </tt>and<tt> case CBSDOT</tt>.<br><br> + +<b>Reflex (<tt>~</tt>). </b>The monad<tt> v~ </tt>computes +<tt>y v y</tt>;<tt> </tt>for example,<tt> +~ </tt>is <i>double</i>. +The obverses of a few such verbs are implemented by +a sub-<tt>switch </tt>in<tt> inv</tt>,<tt> </tt> +under<tt> case CTILDE</tt>. <br><br> + +<b>Assigned Obverse. </b>A verb may be assigned an obverse with +the <i>obverse conjunction</i><tt> </tt>(<tt>:.</tt>).<tt> </tt> +<tt>f=: u :.v </tt> +is like<tt> u </tt>but the obverse of<tt> f </tt>is<tt> v</tt>.<br><br> + +<b>Other Verbs. </b><tt>inv </tt>applies to a few other verbs, +including<tt> u@v </tt>and<tt> u&v</tt>,<tt> </tt>whose obverses are<tt> </tt> +<tt>(v inv)@(u inv) </tt>and<tt> (v inv)&(u inv)</tt>.<br><br> + + +<font size="4">• Identities</font><a name="identity"></a><br><br> + +<tt>u/y </tt>applies the dyad between the items of<tt> y</tt>.<tt> </tt> +When<tt> y </tt>has <i>zero</i> items, +the result of<tt> u/y </tt>obtains by applying +to<tt> y </tt>the <i>identity function</i><tt> ui </tt> +of<tt> u</tt>,<tt> </tt>so-called because +<tt>(iu y) u y </tt>or<tt> y u (iu y) </tt>is<tt> y </tt> +for a significant subdomain of<tt> u</tt>.<br><br> + +Identity functions are computed by +function<tt> <a name="iden">iden</a> </tt> +in file ai.c.<tt> iden </tt> behaves like an adverb, applying +to verbs and producing verbs. +The logic is implemented as a branch table<tt> </tt> +(<tt>switch/case</tt>).<tt> </tt> +Not all verbs have identity functions; +<tt>iden </tt>signals error in such cases.<br><br> + + +<font size="4">• Variants</font> +<a name="variant"></a><a name="fit"></a><br><br> + +Variants of a verb are produced by the <i>fit</i> +conjunction<tt> !.</tt>,<tt> </tt>and are used to effect +<a href="iojComp.htm">tolerant comparison</a><tt> </tt> +(<tt>= < <. </tt>and so forth), formatting to +a specific precision<tt> </tt>(<tt>":</tt>),<tt> </tt> +shifts<tt> </tt>(<tt>|.</tt>),<tt> </tt> +and factorial polynomials<tt> </tt> (<tt>^</tt>).<br><br> + +<tt>!. </tt>is implemented by function<tt> fit </tt>in file cf.c. +The logic is implemented as a branch +table<tt> </tt>(<tt>switch/case</tt>).<tt> </tt> +Not all verbs have variants;<tt> fit </tt>signals error in such cases.<br><br> + +<br> + +<a name="Errors"></a><p><font size="5"><b>Error Handling</b></font><br><br> + +When an error is encountered in a function, the global +variable<tt> <a name="jerr">jerr</a> </tt>is set to an error number, and zero is returned. +Therefore, when calling a function that can not have zero as a valid result +(but does return a result), the returned value must be checked for zero; +when calling a "void" function or one whose range +includes zero,<tt> jerr </tt>must be inspected.<br><br> + +Error numbers range between 1 and<tt> <a name="NEVM">NEVM</a></tt>,<tt> </tt> +and are referenced by the<tt> EV* </tt>names (file jerr.h). +The function<tt> <a name="jsignal">jsignal</a> </tt>(d.c) +applies to an error number, sets<tt> jerr </tt>to this number, and +displays the appropriate error message;<tt> jsignal </tt>exits +immediately if<tt> jerr </tt>is already nonzero.<tt> </tt> +<tt><a name="evm">evm</a> </tt>is a list of the error messages. +These messages are initialized by +function<tt> <a name="evinit">evinit</a> </tt>(file i.c), +and may be inspected and changed by the user +through<tt> 9!:8 </tt>and<tt> 9!:9</tt>.<br><br> + +The macro<tt> <a name="ASSERT">ASSERT</a> </tt>(file j.h) is used +extensively in argument validation. +It applies to a proposition and an error number. For example, +the following statements check whether<tt> w </tt> is a literal atom:<br><br> + +<pre> + ASSERT(!AR(w),EVRANK); + ASSERT(LIT&AT(w),EVDOMAIN); +</pre> + +If the proposition is nonzero, execution proceeds to the next statement; +otherwise, the indicated error is<tt> jsignal</tt>-ed and a zero is returned. +The macros<tt> <a name="RZ">RZ</a> </tt>and<tt> <a name="RE">RE</a> </tt> +(file j.h) are used in function calls.<tt> RZ </tt>returns zero +if its argument is zero;<tt> RE </tt>evaluates its argument, +and returns zero if<tt> jerr </tt>is nonzero. For example, +the function<tt> iota </tt>(implementing the +monad<tt> i.</tt>)<tt> </tt>exploits<tt> RZ </tt>as follows: +<br><br> + +<pre> + F1(jtiota){A z;I m,n,*v; + F1RANK(1,jtiota,0); + if(AT(w)&XNUM+RAT)R cvt(XNUM,iota(vi(w))); + RZ(w=vi(w)); n=AN(w); v=AV(w); + if(1==n){m=*v; R 0>m?apv(-m,-m-1,-1L):apv(m,0L,1L);} + m=prod(n,v); z=reshape(mag(w),apv(ABS(m),0L,1L)); + DO(n, if(0>v[i])z=irs1(z,0L,n-i,jtreverse);); + R z; + } +</pre> + +The arguments of a function may be the result of another function; +the convention is that a function checks its arguments for zero +and returns zero immediately in such cases. Thus, in<tt> iota </tt>above:<br><br> + +<pre> + z=reshape(mag(w),apv(ABS(m),0L,1L)); +</pre> + +If<tt> reshape </tt>did <i>not</i> check for zero arguments, +the statement would have to be elaborated:<br><br> + +<pre> + RZ(t0=mag(w)); + RZ(t1=apv(ABS(m),0L,1L)); + z=reshape(t0,t1); +</pre> + +A <a name="conventional function"></a><i>conventional function</i> is a +function that follows the conventions +described herein — return zero on zero arguments and on errors. +The defined type<tt> <a href="#AF">AF</a> </tt>(file jtype.h) typifies a +conventional function. Most functions in the system are conventional; +in particular, all functions implementing primitives are conventional. +Expressions and statements that use only conventional functions +need not employ<tt> RZ </tt>or<tt> RE</tt>,<tt> </tt>and the resulting +programs are neater. +For example, consider functions<tt> shape </tt>and<tt> nub </tt>(file v.c), +implementing the monads<tt> $ </tt>and<tt> ~.</tt>,<tt> </tt>respectively:<br><br> + +<pre> + F1(jtshape){RZ(w); R vec(INT,AR(w),AS(w));} + F1(jtnub){R repeat(nubsieve(w),w);} +</pre> + +<tt>shape </tt>must check for zero arguments<tt> RZ(w)</tt>,<tt> </tt> +because it +applies the <i>un</i>conventional macros<tt> AR </tt>and<tt> AS </tt>to +the argument<tt> w</tt>.<tt> </tt>In contrast,<tt> nub </tt>applies only +conventional functions to <i>its</i> argument and to +results of conventional functions on that argument.<br><br> + +<br> +<hr> + +<a href="iojAdv.htm">Next</a> + • +<a href="iojNoun.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/ioj/iojXenos.htm @@ -0,0 +1,186 @@ +<html> + +<head> +<title>An Implementation of J -- Foreign Conjunction</title> +</head> + +<body> + +<p align=center><font size="6"><b>Foreign Conjunction</b></font><br> +<font size="4"><b><a href="ioj.htm">An Implementation of J</a></b></font></p> + +<hr> +<br> + +<pre> +0!:0 scm00 • scd00 +0!:1 scm01 • scd01 +0!:2 sct1 • sct2 +0!:3 scz1 • scz2 +0!:10 scm10 • scd10 +0!:11 scm11 • scd11 +0!:100 scm00 • scd00 +0!:101 scm01 • scd01 +0!:110 scm10 • scd10 +0!:111 scm11 • scd11 + +1!:0 jdir • +1!:1 jfread • +1!:2 • jfwrite +1!:3 • jfappend +1!:4 jfsize • +1!:5 jmkdir • +1!:6 jfatt1 • jfatt2 +1!:7 jfperm1 • jfperm2 +1!:11 jiread • +1!:12 • jiwrite +1!:20 jfiles • +1!:21 jopen • +1!:22 jclose • +1!:30 jlocks • +1!:31 jlock • +1!:32 junlock • +1!:40 pathapp • +1!:41 pathdll • +1!:42 pathlib • +1!:55 jferase • + +2!:0 host • +2!:1 hostne • +2!:2 hostio • +2!:3 jwait • +2!:4 jargv • +2!:5 jgetenv • +2!:55 joff • + +3!:0 stype • +3!:1 ir • +3!:2 ri • +3!:3 irx • +3!:4 • ic2 +3!:5 • fc2 + +4!:0 nc • +4!:1 nl1 • nl2 +4!:3 snl • +4!:4 scind • +4!:5 nch • +4!:55 ex • +4!:56 exall • + +5!:0 fxx • +5!:1 arx • +5!:2 drx • +5!:4 trx • +5!:5 lrx • +5!:6 prx • + +6!:0 ts • +6!:1 tss • +6!:2 tsit1 • tsit2 +6!:3 dl • +6!:8 qpfreq • +6!:9 qpctr • +6!:10 pmarea1 • pmarea2 +6!:11 pmunpack • +6!:12 pmctr • +6!:13 pmstats • + +7!:0 sp • +7!:1 sps • +7!:2 spit • +7!:3 spcount • +7!:4 spfree • + +9!:0 rlq • +9!:1 rls • +9!:2 dispq • +9!:3 disps • +9!:4 promptq • +9!:5 prompts • +9!:6 boxq • +9!:7 boxs • +9!:8 evmq • +9!:9 evms • +9!:10 ppq • +9!:11 pps • +9!:12 sysq • +9!:14 versq • +9!:16 posq • +9!:17 poss • +9!:18 ctq • +9!:19 cts • +9!:20 mmaxq • +9!:21 mmaxs • +9!:22 numdefq • +9!:23 numdefs • +9!:24 seclevq • +9!:25 seclevs • +9!:26 ilxq • +9!:27 ilxs • +9!:28 doilxq • +9!:29 doilxs • + +11!:x wd • + +13!:0 dbc • +13!:1 dbs • +13!:2 dbsq • +13!:3 dbss • +13!:4 dbrun • +13!:5 dbnext • +13!:6 dbret • +13!:7 dbjump • +13!:8 dbsig1 • dbsig2 +13!:9 dbrr1 • dbrr2 +13!:10 dbrrx1 • dbrrx2 +13!:11 dberr • +13!:12 dbetx • +13!:13 dbcall • +13!:14 dbtrapq • +13!:15 dbtraps • +13!:16 J • +13!:17 dbq • +13!:18 dbsz • +13!:31 • colaux + +15!:0 • cd +15!:1 memr • +15!:2 • memw +15!:3 mema • +15!:4 memf • +15!:5 cdf • +15!:6 symget • +15!:7 symset • +15!:8 gh15 • +15!:9 fh15 • +15!:10 cder • +15!:11 cderx • +15!:12 smmblks • + +18!:0 locnc • +18!:1 locnl1 • locnl2 +18!:2 locpath1 • locpath2 +18!:3 loccreate • +18!:4 locswitch • +18!:5 locname • +18!:55 locexmark • + +128!:0 qr • +128!:1 rinv • +</pre> + +<br> +<hr> + +<a href="iojSumm.htm">Next</a> + • +<a href="iojFiles.htm">Previous</a> + • +<a href="iojIndex.htm">Index</a> + • +<a href="ioj.htm#TOC">Table of Contents</a> +<br> + +</body> +</html> \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/docs/license.txt @@ -0,0 +1,15 @@ + +JSOFTWARE SOURCES refers to all files in this Jsoftware release +package except for file gpl3.txt. + +JSOFTWARE SOURCES are: +Copyright 1990-2011, Jsoftware Inc. All rights reserved. + +JSOFTWARE SOURCES are: +Licensed under GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +See gpl3.txt for GNU General Public License version 3. +Additional info at http://www.gnu.org/licenses. +
new file mode 100644 --- /dev/null +++ b/docs/readme.txt @@ -0,0 +1,142 @@ + +Building J from Jsoftware (www.jsoftware.com) source released under GPL +version 3. + +*** copyright and license + +JSOFTWARE SOURCES refers to all files in this Jsoftware release package +except for file gpl3.txt. + +JSOFTWARE SOURCES are: Copyright 1990-2011, Jsoftware Inc. All rights +reserved. + +JSOFTWARE SOURCES are: Licensed under GNU General Public License as +published by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +See gpl3.txt for GNU General Public License version 3. Additional info at +http://www.gnu.org/licenses. + +(above also appears in copyright.txt and license.txt) + +*** overview + +Unpack J source release tar.gz file. Following assumes tar unpack is done +in ~ and creates ~/jgplsrc. + +Familiarity with J provides essential background and context for working +with the source. + +Development has been primarily in Windows and work on other platforms has +been done with limited resources and limited understanding of normal Unix +practices. The shell scripts, make files, and configuration are eccentric +at best and may need work to fit comfortably in the open source world. + +This release is targeted at Unix. Windows VC++ project files are not +included (they could be created by those familiar with Windows +development). Additional source files required for the Windows COM wrapper +for j.dll in jgplsrc/win. + +If you are playing with a supported platform or are doing a port to a +'nearby' platform then the current packaging might meet your needs. An +example of a 'nearby' platform would be Linux/ARM as differences are minor +from already supported platforms. Further afield, for example other than +Linux/Mac/Windows, will require more work. + +*** folders + +jgplsrc - *.c *.h + +jgplsrc/bin - bash scripts + +jgplsrc/defs - files for building netdefs.ijs and hostdefs.ijs + +jgplsrc/docs - text files + +jgplsrc/docs/ioj - 'Implementation of J' by Roger Hui (out of date, but +useful) + +jgplsrc/j - minimal J environment to test new new binaries + +jgplsrc/test - test scripts to validate binaries + +jgplsrc/win - additional source for win com server + + +*** configuration + +bin/jconfig configs for 32/64bit and whether jconsole has line recall. + +Configuration is driven largely by Unix uname and jconfig insists on uname +of Linux or Darwin. If building for a different uname, you will have to +edit jconfig and perhaps make changes to j.h, js.h, and other files. + +Key platform differences are Unix/Windows, 32/64bits, intel byte +order/non-intel byte order, and XNAN and XINF double bit patterns. + +Buildling Linux/Mac on Intel could be fairly smooth. + +jconfig as distributed sets 32bit and no line recall. Edit jconfig as +required. + +*** touch *.c + +The makes are naive and don't handle h file or config changes. You may need +touch to get a clean build. + +*** build_jconsole - build jconsole binary + +$ cd ~/jgplsrc $ bin/build_jconsole + +*** build_libj - build libj.so or libj.dylib binary $ bin/build_libj + +If build_jconsole and build_libj succeed, the binaries have been copied to +j/bin and you can start J with: + +$ j/bin/jconsole + i.5 + +Congratulations if your J runs! + +*** build_tsdll + +J shared library calls (for example, sockets or memory mapped files) can +require J constants defined from C header files. These values are defined +by netdefs and hostdefs ijs files. Build these with: + +$ bin/build_defs + +*** build_tsdll + +Build tsdll (shared library used to test J calls) with: + +$ bin/build_tsdll + +*** test suite + +A test suite validates a J system. Read test/test.ijs and test/tsu.ijs for +more info. + +$ j/bin/jconsole + load 'test/test.ijs' + bad=: TEST ddall NB. run all tests + BAD ddall NB. report tests that failed + +TEST displays the script name before it is run. If you crash, the last name +displayed is the script that caused the crash. You can narrow down the +cause by displaying each line in the script as it is run: + +$ j/bin/jconsole + load 'test/test.ijs' + TESTX SNS 'gintovfl' NB. display and run each line of gintovfl.ijs + +Get more info about a BAD script the same way: + +A script can fail because of particular random numbers. If rerunning is +clean things are probably OK, but this is an area for caution. + +A script can fail because of a timing sensitvity. For example, comparing +timings of two methods to a threshold. Rerunning may show it sometimes runs +clean and sometimes fails on a timing test. You can ignore timing threshold +failures. +
new file mode 100644 --- /dev/null +++ b/dss.c @@ -0,0 +1,56 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug: Single Step */ + +#include "j.h" +#include "d.h" + + +/* d->dcss - single step code in current function */ +/* jt->dbssd - the d whose dcss is non-zero */ +/* jt->dbss - single step code for propagation to appropriate function */ + + +DC jtssnext(J jt,DC d,C c){ + d=d->dclnk; + while(d&&DCCALL!=d->dctype)d=d->dclnk; /* find next call */ + if(d&&!d->dcsusp){d->dcss=c; jt->dbssd=d;} + else {d=0; jt->dbssd=0;} + R d; +} /* set dcss for next stack level */ + +static A jtssdo(J jt,A a,A w,C c){DC d,e;I n,*v; + RZ(w=vs(w)); + ASSERT(jt->db,EVDOMAIN); + d=jt->sitop; /* cut back to topmost suspension */ + while(d&&!d->dcsusp){ /* do until topmost suspension */ + if(d->dctype==DCCALL)*(I*)(d->dci)=-2; /* terminate each call */ + d=d->dclnk; + } + ASSERT(d,EVDOMAIN); /* must have a suspension */ + while(d&&DCCALL!=d->dctype)d=d->dclnk; /* find topmost call */ + ASSERT(d,EVDOMAIN); /* must have a call */ + if(a)RE(n=lnumcw(i0(a),d->dcc)); /* source line # to cw line # */ + v=(I*)d->dci; /* pointer to line # */ + jt->dbsusact=SUSSS; + switch(c){ + case SSSTEPOVER: if(a)*v=n-1; else --*v; jt->dbss=d->dcss=c; jt->dbssd=d; break; + case SSSTEPINTO: if(a)*v=n-1; else --*v; jt->dbss=d->dcss=c; jt->dbssd=d; break; + case SSSTEPOUT: if(a)*v=n-1; else --*v; jt->dbss=d->dcss=0; ssnext(d,c); break; + case SSCUTBACK: *v=-2; jt->dbss=d->dcss=0; e=ssnext(d,c); if(e)--*(I*)e->dci; + } + fa(jt->dbssexec); jt->dbssexec=AN(w)?ra(w):0; + R mtm; /* 0 return to terminate call */ +} + +F1(jtdbcutback ){R ssdo(0L,w,SSCUTBACK );} /* 13!:19 */ + +F1(jtdbstepover1){R ssdo(0L,w,SSSTEPOVER);} /* 13!:20 */ +F2(jtdbstepover2){R ssdo(a, w,SSSTEPOVER);} + +F1(jtdbstepinto1){R ssdo(0L,w,SSSTEPINTO);} /* 13!:21 */ +F2(jtdbstepinto2){R ssdo(a, w,SSSTEPINTO);} + +F1(jtdbstepout1 ){R ssdo(0L,w,SSSTEPOUT );} /* 13!:22 */ +F2(jtdbstepout2 ){R ssdo(a, w,SSSTEPOUT );}
new file mode 100644 --- /dev/null +++ b/dstop.c @@ -0,0 +1,59 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug: Stops */ + +#include "j.h" +#include "d.h" + + +/* check for stop before each function line; return 1 if stop requested */ +/* 0 or more repetitions of the following patterns, separated by */ +/* abc*yz m:d all names beginning with abc and ending with yz; */ +/* monad line numbers and dyad line numbers (* means all). */ +/* ~abc*yz m:d don't stop */ + +static B stopsub(C*p,C*nw,I md){C*q,*s;I n; + s=strchr(p,';'); if(!s)s=p+strlen(p); + q=strchr(p,':'); if(!q||q>s)q=s; + if(2==md){p=q; q=s; if(':'==*p)++p;} + s=strchr(p,'*'); if(s&&q>s)R 1; + n=strlen(nw); + while(q>p){ + while(' '==*p)++p; + if(!strncmp(p,nw,n)&&(q==p+n||' '==*(p+n)))R 1; + while(q>p&&' '!=*p)++p; + } + R 0; +} + +B jtdbstop(J jt,DC d,I i){A a;B b,c=0,e;C nw[11],*s,*t,*u,*v;I md,n,p,q; + if(!jt->dbss&&d->dcss){d->dcss=0; jt->dbssd=0; c=i!=d->dcstop; d->dcstop=i; R c;} + switch(jt->dbss){ + case SSSTEPOVER: jt->dbss=0; break; + case SSSTEPINTO: jt->dbss=SSSTEPINTOs; break; + case SSSTEPINTOs: jt->dbss=0; if(jt->dbssd){jt->dbssd->dcss=0; jt->dbssd=0;} + c=i!=d->dcstop; d->dcstop=i; R c; + } + if(i==d->dcstop){d->dcstop=-2; R 0;} /* not stopping if already stopped at the same place */ + RZ(jt->dbstops); s=CAV(jt->dbstops); sprintf(nw,FMTI,i); + a=d->dca; n=d->dcm; t=NAV(a)->s; md=d->dcx&&d->dcy?2:1; + while(s){ + while(' '==*s)++s; if(b='~'==*s)++s; while(' '==*s)++s; + u=strchr(s,'*'); v=strchr(s,' '); if(!v)break;; + if(!u||u>v)e=!strncmp(s,t,MAX(n,v-s)); + else{p=u-s; q=v-u-1; e=p<=n&&!strncmp(s,t,p)&&q<=n&&!strncmp(1+u,t+n-q,q);} + if(e){s=1+v; if(stopsub(s,nw,md)){if(b){c=0; break;} c=1;}} + s=strchr(s,';'); if(s)++s; + } + if(c){d->dcstop=i; d->dcss=jt->dbss=0; if(jt->dbssd){jt->dbssd->dcss=0; jt->dbssd=0;}} + else d->dcstop=-2; + R c; +} /* stop on line i? */ + + +F1(jtdbstopq){ASSERTMTV(w); R jt->dbstops?jt->dbstops:mtv;} + /* 13!:2 query stops */ + +F1(jtdbstops){RZ(w=vs(w)); fa(jt->dbstops); jt->dbstops=AN(w)?ra(w):0; R mtm;} + /* 13!:3 set stops */
new file mode 100644 --- /dev/null +++ b/dsusp.c @@ -0,0 +1,232 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Debug: Suspension */ + +#include "j.h" +#include "d.h" +#include "w.h" + + +/* deba() and debz() must be coded and executed in pairs */ +/* in particular, do NOT do error exits between them */ +/* e.g. the following is a NO NO: */ +/* d=deba(...); */ +/* ASSERT(blah,EVDOMAIN); */ +/* debz() */ + +DC jtdeba(J jt,C t,A x,A y,A fs){A q;DC d; + GA(q,LIT,sizeof(DST),1,0); d=(DC)AV(q); + memset(d,C0,sizeof(DST)); + d->dctype=t; d->dclnk=jt->sitop; jt->sitop=d; + switch(t){ + case DCPARSE: d->dcy=y; break; + case DCSCRIPT: d->dcy=y; d->dcm=(I)fs; break; + case DCCALL: + d->dcx=x; d->dcy=y; d->dcf=fs; + d->dca=jt->curname; d->dcm=NAV(jt->curname)->m; + d->dcn=(I)jt->cursymb; + d->dcstop=-2; + if(jt->dbss==SSSTEPINTO){d->dcss=SSSTEPINTO; jt->dbssd=d; jt->dbss=0;} + } + R d; +} /* create new top of si stack */ + +void jtdebz(J jt){jt->sitop=jt->sitop->dclnk;} + /* remove top of si stack */ + +F1(jtsiinfo){A z,*zv;DC d;I c=5,n,*s; + ASSERTMTV(w); + n=0; d=jt->sitop; while(d){++n; d=d->dclnk;} + GA(z,BOX,c*n,2,0); s=AS(z); s[0]=n; s[1]=c; zv=AAV(z); + d=jt->sitop; + while(d){ + RZ(zv[0]=sc(d->dctype)); + RZ(zv[1]=d->dcsusp?scc('*'):scc(' ')); + RZ(zv[2]=sc((I)d->dcss)); + RZ(zv[3]=d->dctype==DCCALL?sc(lnumsi(d)):mtv); + switch(d->dctype){ + case DCPARSE: RZ(zv[4]=unparse(d->dcy)); break; + case DCCALL: RZ(zv[4]=sfn(0,d->dca)); break; + case DCSCRIPT: zv[4]=d->dcy; break; + case DCJUNK: zv[4]=mtv; break; + } + zv+=c; d=d->dclnk; + } + R z; +} /* 13!:32 si info */ + +I lnumcw(I j,A w){CW*u; + if(0>j)R -2; + else if(!w)R j; + else{u=(CW*)AV(w); DO(AN(w), if(j<=u[i].source)R i;) R IMAX/2;} +} /* line number in CW corresp. to j */ + +I lnumsi(DC d){A c;I i; + if(c=d->dcc){i=*(I*)d->dci; R(MIN(i,AN(c)-1)+(CW*)AV(c))->source;}else R 0; +} /* source line number from stack entry */ + + + +static DC suspset(DC d){DC e; + while(d&&DCCALL!=d->dctype){e=d; d=d->dclnk;} /* find topmost call */ + if(!(d&&DCCALL==d->dctype))R 0; /* don't suspend if no such call */ + if(d->dcc)e->dcsusp=1; /* if explicit, set susp on line */ + else d->dcsusp=1; /* if not explicit, set susp on call */ + R d; +} /* find topmost call and set suspension flag */ + +static B jterrcap(J jt){A y,*yv; + jt->dbsusact=SUSCLEAR; + GA(y,BOX,4,1,0); yv=AAV(y); + RZ(yv[0]=sc(jt->jerr1)); + RZ(yv[1]=str(jt->etxn1,jt->etx)); + RZ(yv[2]=dbcall(mtv)); + RZ(yv[3]=locname(mtv)); + RZ(symbis(nfs(22L,"STACK_ERROR_INFO_base_"),y,mark)); + R 1; +} /* error capture */ + +static void jtsusp(J jt){B t;DC d;I old=jt->tbase+jt->ttop; + jt->dbsusact=SUSCONT; + d=jt->dcs; t=jt->tostdout; + jt->dcs=0; jt->tostdout=1; + jt->fdepn =MIN(NFDEP ,jt->fdepn +NFDEP /10); + jt->fcalln=MIN(NFCALL,jt->fcalln+NFCALL/10); + if (jt->dbssexec){RESETERR; immex(jt->dbssexec); tpop(old);} + else if(jt->dbtrap ){RESETERR; immex(jt->dbtrap ); tpop(old);} + while(jt->dbsusact==SUSCONT){ + jt->jerr=0; + if(jt->iepdo&&jt->iep){jt->iepdo=0; immex(jt->iep); tpop(old);} + immex(jgets(" ")); + tpop(old); + } + if(jt->dbuser){jt->fdepn-=NFDEP/10; jt->fcalln-=NFCALL/10;} + else {jt->fdepn =NFDEP; jt->fcalln =NFCALL; } + jt->dcs=d; jt->tostdout=t; +} /* user keyboard loop while suspended */ + +static A jtdebug(J jt){A z=0;C e;DC c,d;I*v; + if(jt->dbssd){jt->dbssd->dcss=0; jt->dbssd=0;} + RZ(d=suspset(jt->sitop)); + v=(I*)d->dci; + if(0>*v)R 0; + e=jt->jerr; jt->jerr=0; + if(DBERRCAP==jt->db)errcap(); else susp(); + switch(jt->dbsusact){ + case SUSRUN: + --*v; break; + case SUSRET: + *v=-2; z=jt->dbresult; jt->dbresult=0; break; + case SUSJUMP: + *v=lnumcw(jt->dbjump,d->dcc)-1; break; + case SUSCLEAR: + jt->jerr=e; + c=jt->sitop; + while(c){if(DCCALL==c->dctype)*(I*)(c->dci)=-2; c=c->dclnk;} + } + if(jt->dbsusact!=SUSCLEAR)jt->dbsusact=SUSCONT; + d->dcsusp=0; + R z; +} + + +static A jtparseas(J jt,B as,A w){A*u,*v,y,z;I n; + n=AN(w); v=AAV(w); + GA(y,BOX,5+n,1,0); u=AAV(y); + *u++=mark; DO(n, *u++=*v++;); *u++=mark; *u++=mark; *u++=mark; *u++=mark; + z=parsea(y); /* y is destroyed by parsea */ + if(as&&z)ASSERT(NOUN&AT(z)&&all1(eq(one,z)),EVASSERT); + R z; +} + +/* parsex: parse an explicit defn line */ +/* w - line to be parsed */ +/* lk - 1 iff locked function */ +/* ci - current row of control matrix */ +/* c - stack entry for dbunquote for this function */ + +A jtparsex(J jt,A w,B lk,CW*ci,DC c){A z;B as,s;DC d,t=jt->sitop; + RZ(w); + JATTN; + as=ci->type==CASSERT; + if(lk)R parseas(as,w); + RZ(d=deba(DCPARSE,0L,w,0L)); + if(0==c)z=parseas(as,w); /* anonymous or not debug */ + else{ /* named and debug */ + if(s=dbstop(c,ci->source)){z=0; jsignal(EVSTOP);} + else {z=parseas(as,w); } + if(!z&&(s||DBTRY!=jt->db)){t->dcj=d->dcj=jt->jerr; z=debug(); t->dcj=0;} + } + debz(); + R z; +} + +DF2(jtdbunquote){A t,z;B b=0,s;DC d;I i;V*sv; + sv=VAV(self); t=sv->f; + RZ(d=deba(DCCALL,a,w,self)); + if(CCOLON==sv->id&&t&&NOUN&AT(t)){ /* explicit */ + ra(self); z=a?dfs2(a,w,self):dfs1(w,self); fa(self); + }else{ /* tacit */ + i=0; d->dci=(I)&i; + while(0==i){ + if(s=dbstop(d,0L)){z=0; jsignal(EVSTOP);} + else {ra(self); z=a?dfs2(a,w,self):dfs1(w,self); fa(self);} + if(!z&&(s||DBTRY!=jt->db)){d->dcj=jt->jerr; z=debug(); if(self!=jt->sitop->dcf)self=jt->sitop->dcf;} + if(b){fa(a); fa(w);} + if(b=jt->dbalpha||jt->dbomega){a=jt->dbalpha; w=jt->dbomega; jt->dbalpha=jt->dbomega=0;} + ++i; + } + } + if(d->dcss)ssnext(d,d->dcss); + if(jt->dbss==SSSTEPINTOs)jt->dbss=0; + debz(); + R z; +} /* function call, debug version */ + + +F1(jtdbc){I k; + RZ(w); + if(AN(w)){ + RE(k=i0(w)); + ASSERT(!k||k==DB1||k==DBERRCAP,EVDOMAIN); + ASSERT(!k||!jt->glock,EVDOMAIN); + } + jt->redefined=0; + if(AN(w)){jt->db=jt->dbuser=k; jt->fdepn=NFDEP/(k?2:1); jt->fcalln=NFCALL/(k?2:1);} + jt->dbsusact=SUSCLEAR; + R mtm; +} /* 13!:0 clear stack; enable/disable suspension */ + +F1(jtdbq){ASSERTMTV(w); R sc(jt->dbuser);} + /* 13!:17 debug flag */ + +F1(jtdbrun ){ASSERTMTV(w); jt->dbsusact=SUSRUN; R mtm;} + /* 13!:4 run again */ + +F1(jtdbnext){ASSERTMTV(w); jt->dbsusact=SUSNEXT; R mtm;} + /* 13!:5 run next */ + +F1(jtdbret ){RZ(w); jt->dbsusact=SUSRET; jt->dbresult=ra(w); R mtm;} + /* 13!:6 exit with result */ + +F1(jtdbjump){RE(jt->dbjump=i0(w)); jt->dbsusact=SUSJUMP; R mtm;} + /* 13!:7 resume at line n (return result error if out of range) */ + +static F2(jtdbrr){DC d; + RE(0); + d=jt->sitop; while(d&&DCCALL!=d->dctype)d=d->dclnk; + ASSERT(d&&VERB&AT(d->dcf)&&!d->dcc,EVDOMAIN); /* must be explicit verb */ + jt->dbalpha=ra(a); jt->dbomega=ra(w); + jt->dbsusact=SUSRUN; + R mtm; +} + +F1(jtdbrr1 ){R dbrr(0L,w);} /* 13!:9 re-run with arg(s) */ +F2(jtdbrr2 ){R dbrr(a, w);} + +F1(jtdbtrapq){ASSERTMTV(w); R jt->dbtrap?jt->dbtrap:mtv;} + /* 13!:14 query trap */ + +F1(jtdbtraps){RZ(w=vs(w)); fa(jt->dbtrap); jt->dbtrap=AN(w)?ra(w):0L; R mtm;} + /* 13!:15 set trap */
new file mode 100644 --- /dev/null +++ b/dtoa.c @@ -0,0 +1,3430 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* Jsoftware Copyright applies only to changes made by Jsoftware */ +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* On a machine with IEEE extended-precision registers, it is + * necessary to specify double-precision (53-bit) rounding precision + * before invoking strtod or dtoa. If the machine uses (the equivalent + * of) Intel 80x87 arithmetic, the call + * _control87(PC_53, MCW_PC); + * does this with many compilers. Whether this or another call is + * appropriate depends on the compiler; for this to work, it may be + * necessary to #include "float.h" or another system-dependent header + * file. + */ + +/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. + * + * This strtod returns a nearest machine number to the input decimal + * string (or sets errno to ERANGE). With IEEE arithmetic, ties are + * broken by the IEEE round-even rule. Otherwise ties are broken by + * biased rounding (add half and chop). + * + * Inspired loosely by William D. Clinger's paper "How to Read Floating + * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * + * 1. We only require IEEE, IBM, or VAX double-precision + * arithmetic (not IEEE double-extended). + * 2. We get by with floating-point arithmetic in a case that + * Clinger missed -- when we're computing d * 10^n + * for a small integer d and the integer n is not too + * much larger than 22 (the maximum integer k for which + * we can represent 10^k exactly), we may be able to + * compute (d*10^k) * 10^(e-k) with just one roundoff. + * 3. Rather than a bit-at-a-time adjustment of the binary + * result in the hard case, we use floating-point + * arithmetic to determine the adjustment to within + * one bit; only in really hard cases do we need to + * compute a second residual. + * 4. Because of 3., we don't need a large table of powers of 10 + * for ten-to-e (just some small tables, e.g. of 10^k + * for 0 <= k <= 22). + */ + +/* + * #define IEEE_8087 for IEEE-arithmetic machines where the least + * significant byte has the lowest address. + * #define IEEE_MC68k for IEEE-arithmetic machines where the most + * significant byte has the lowest address. + * #define Long int on machines with 32-bit ints and 64-bit longs. + * #define IBM for IBM mainframe-style floating-point arithmetic. + * #define VAX for VAX-style floating-point arithmetic (D_floating). + * #define No_leftright to omit left-right logic in fast floating-point + * computation of dtoa. + * #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3 + * and strtod and dtoa should round accordingly. + * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3 + * and Honor_FLT_ROUNDS is not #defined. + * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines + * that use extended-precision instructions to compute rounded + * products and quotients) with IBM. + * #define ROUND_BIASED for IEEE-format with biased rounding. + * #define Inaccurate_Divide for IEEE-format with correctly rounded + * products but inaccurate quotients, e.g., for Intel i860. + * #define NO_LONG_LONG on machines that do not have a "long long" + * integer type (of >= 64 bits). On such machines, you can + * #define Just_16 to store 16 bits per 32-bit Long when doing + * high-precision integer arithmetic. Whether this speeds things + * up or slows things down depends on the machine and the number + * being converted. If long long is available and the name is + * something other than "long long", #define Llong to be the name, + * and if "unsigned Llong" does not work as an unsigned version of + * Llong, #define #ULLong to be the corresponding unsigned type. + * #define KR_headers for old-style C function headers. + * #define Bad_float_h if your system lacks a float.h or if it does not + * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, + * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. + * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) + * if memory is available and otherwise does something you deem + * appropriate. If MALLOC is undefined, malloc will be invoked + * directly -- and assumed always to succeed. + * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making + * memory allocations from a private pool of memory when possible. + * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, + * unless #defined to be a different length. This default length + * suffices to get rid of MALLOC calls except for unusual cases, + * such as decimal-to-binary conversion of a very long string of + * digits. The longest string dtoa can return is about 751 bytes + * long. For conversions by strtod of strings of 800 digits and + * all dtoa conversions in single-threaded executions with 8-byte + * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte + * pointers, PRIVATE_MEM >= 7112 appears adequate. + * #define INFNAN_CHECK on IEEE systems to cause strtod to check for + * Infinity and NaN (case insensitively). On some systems (e.g., + * some HP systems), it may be necessary to #define NAN_WORD0 + * appropriately -- to the most significant word of a quiet NaN. + * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) + * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, + * strtod also accepts (case insensitively) strings of the form + * NaN(x), where x is a string of hexadecimal digits and spaces; + * if there is only one string of hexadecimal digits, it is taken + * for the 52 fraction bits of the resulting NaN; if there are two + * or more strings of hex digits, the first is for the high 20 bits, + * the second and subsequent for the low 32 bits, with intervening + * white space ignored; but if this results in none of the 52 + * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0 + * and NAN_WORD1 are used instead. + * #define MULTIPLE_THREADS if the system offers preemptively scheduled + * multiple threads. In this case, you must provide (or suitably + * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed + * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed + * in pow5mult, ensures lazy evaluation of only one copy of high + * powers of 5; omitting this lock would introduce a small + * probability of wasting memory, but would otherwise be harmless.) + * You must also invoke freedtoa(s) to free the value s returned by + * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. + * #define NO_IEEE_Scale to disable new (Feb. 1997) logic in strtod that + * avoids underflows on inputs whose result does not underflow. + * If you #define NO_IEEE_Scale on a machine that uses IEEE-format + * floating-point numbers and flushes underflows to zero rather + * than implementing gradual underflow, then you must also #define + * Sudden_Underflow. + * #define YES_ALIAS to permit aliasing certain double values with + * arrays of ULongs. This leads to slightly better code with + * some compilers and was always used prior to 19990916, but it + * is not strictly legal and can cause trouble with aggressively + * optimizing compilers (e.g., gcc 2.95.1 under -O2). + * #define USE_LOCALE to use the current locale's decimal_point value. + * #define SET_INEXACT if IEEE arithmetic is being used and extra + * computation should be done to set the inexact flag when the + * result is inexact and avoid setting inexact when the result + * is exact. In this case, dtoa.c must be compiled in + * an environment, perhaps provided by #include "dtoa.c" in a + * suitable wrapper, that defines two functions, + * int get_inexact(void); + * void clear_inexact(void); + * such that get_inexact() returns a nonzero value if the + * inexact bit is already set, and clear_inexact() sets the + * inexact bit to 0. When SET_INEXACT is #defined, strtod + * also does extra computations to set the underflow and overflow + * flags when appropriate (i.e., when the result is tiny and + * inexact or when it is a numeric value rounded to +-infinity). + * #define NO_ERRNO if strtod should not assign errno = ERANGE when + * the result overflows to +-Infinity or underflows to 0. + */ + +/* Options for use with J */ +#include "js.h" +#define Long int +#if SYS & SYS_LILENDIAN +#define IEEE_8087 +#else +#define IEEE_MC68k +#endif +#define MULTIPLE_THREADS +#define ACQUIRE_DTOA_LOCK(n) /* handled by using jt */ +#define FREE_DTOA_LOCK(n) /* handled by using jt */ +/* #define Omit_Private_Memory */ +#define PRIVATE_MEM 8000 +#define Use_J_Memory +#if SY_WIN32 +#define Llong __int64 +#endif + +#ifndef Long +#define Long long +#endif +#ifndef ULong +typedef unsigned Long ULong; +#endif + +#ifdef DEBUG +#include "stdio.h" +#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} +#endif + +#include "stdlib.h" +#include "string.h" + +#ifdef USE_LOCALE +#include "locale.h" +#endif + +#if 0 +#ifdef MALLOC +#ifdef KR_headers +extern char *MALLOC(); +#else +extern void *MALLOC(size_t); +#endif +#else +#define MALLOC malloc +#endif +#endif + +#ifndef Omit_Private_Memory +#ifndef PRIVATE_MEM +#define PRIVATE_MEM 2304 +#endif +#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) +#ifndef Use_J_Memory +static double private_mem[PRIVATE_mem], *pmem_next = private_mem; +#endif +#endif + +#undef IEEE_Arith +#undef Avoid_Underflow +#ifdef IEEE_MC68k +#define IEEE_Arith +#endif +#ifdef IEEE_8087 +#define IEEE_Arith +#endif + +#ifdef Bad_float_h + +#ifdef IEEE_Arith +#define DBL_DIG 15 +#define DBL_MAX_10_EXP 308 +#define DBL_MAX_EXP 1024 +#define FLT_RADIX 2 +#endif /*IEEE_Arith*/ + +#ifdef IBM +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 75 +#define DBL_MAX_EXP 63 +#define FLT_RADIX 16 +#define DBL_MAX 7.2370055773322621e+75 +#endif + +#ifdef VAX +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 38 +#define DBL_MAX_EXP 127 +#define FLT_RADIX 2 +#define DBL_MAX 1.7014118346046923e+38 +#endif + +#ifndef LONG_MAX +#define LONG_MAX 2147483647 +#endif + +#else /* ifndef Bad_float_h */ +#include "float.h" +#endif /* Bad_float_h */ + +#ifndef __MATH_H__ +#include "math.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef CONST +#ifdef KR_headers +#define CONST /* blank */ +#else +#define CONST const +#endif +#endif + +#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 +Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. +#endif + +typedef union { double d; ULong L[2]; } U; + +#ifdef YES_ALIAS +#define dval(x) x +#ifdef IEEE_8087 +#define word0(x) ((ULong *)&x)[1] +#define word1(x) ((ULong *)&x)[0] +#else +#define word0(x) ((ULong *)&x)[0] +#define word1(x) ((ULong *)&x)[1] +#endif +#else +#ifdef IEEE_8087 +#define word0(x) ((U*)&x)->L[1] +#define word1(x) ((U*)&x)->L[0] +#else +#define word0(x) ((U*)&x)->L[0] +#define word1(x) ((U*)&x)->L[1] +#endif +#define dval(x) ((U*)&x)->d +#endif + +/* The following definition of Storeinc is appropriate for MIPS processors. + * An alternative that might be better on some machines is + * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) + */ +#if defined(IEEE_8087) + defined(VAX) +#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ +((unsigned short *)a)[0] = (unsigned short)c, a++) +#else +#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ +((unsigned short *)a)[1] = (unsigned short)c, a++) +#endif + +/* #define P DBL_MANT_DIG */ +/* Ten_pmax = floor(P*log(2)/log(5)) */ +/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ +/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ +/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ + +#ifdef IEEE_Arith +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 0x100000 +#define Exp_msk11 0x100000 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Bias 1023 +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask 0xfffff +#define Bndry_mask1 0xfffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 +#ifndef NO_IEEE_Scale +#define Avoid_Underflow +#ifdef Flush_Denorm /* debugging option */ +#undef Sudden_Underflow +#endif +#endif + +#ifndef Flt_Rounds +#ifdef FLT_ROUNDS +#define Flt_Rounds FLT_ROUNDS +#else +#define Flt_Rounds 1 +#endif +#endif /*Flt_Rounds*/ + +#ifdef Honor_FLT_ROUNDS +#define Rounding rounding +#undef Check_FLT_ROUNDS +#define Check_FLT_ROUNDS +#else +#define Rounding Flt_Rounds +#endif + +#else /* ifndef IEEE_Arith */ +#undef Check_FLT_ROUNDS +#undef Honor_FLT_ROUNDS +#undef SET_INEXACT +#undef Sudden_Underflow +#define Sudden_Underflow +#ifdef IBM +#undef Flt_Rounds +#define Flt_Rounds 0 +#define Exp_shift 24 +#define Exp_shift1 24 +#define Exp_msk1 0x1000000 +#define Exp_msk11 0x1000000 +#define Exp_mask 0x7f000000 +#define P 14 +#define Bias 65 +#define Exp_1 0x41000000 +#define Exp_11 0x41000000 +#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ +#define Frac_mask 0xffffff +#define Frac_mask1 0xffffff +#define Bletch 4 +#define Ten_pmax 22 +#define Bndry_mask 0xefffff +#define Bndry_mask1 0xffffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 4 +#define Tiny0 0x100000 +#define Tiny1 0 +#define Quick_max 14 +#define Int_max 15 +#else /* VAX */ +#undef Flt_Rounds +#define Flt_Rounds 1 +#define Exp_shift 23 +#define Exp_shift1 7 +#define Exp_msk1 0x80 +#define Exp_msk11 0x800000 +#define Exp_mask 0x7f80 +#define P 56 +#define Bias 129 +#define Exp_1 0x40800000 +#define Exp_11 0x4080 +#define Ebits 8 +#define Frac_mask 0x7fffff +#define Frac_mask1 0xffff007f +#define Ten_pmax 24 +#define Bletch 2 +#define Bndry_mask 0xffff007f +#define Bndry_mask1 0xffff007f +#define LSB 0x10000 +#define Sign_bit 0x8000 +#define Log2P 1 +#define Tiny0 0x80 +#define Tiny1 0 +#define Quick_max 15 +#define Int_max 15 +#endif /* IBM, VAX */ +#endif /* IEEE_Arith */ + +#ifndef IEEE_Arith +#define ROUND_BIASED +#endif + +#ifdef RND_PRODQUOT +#define rounded_product(a,b) a = rnd_prod(a, b) +#define rounded_quotient(a,b) a = rnd_quot(a, b) +#ifdef KR_headers +extern double rnd_prod(), rnd_quot(); +#else +extern double rnd_prod(double, double), rnd_quot(double, double); +#endif +#else +#define rounded_product(a,b) a *= b +#define rounded_quotient(a,b) a /= b +#endif + +#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big1 0xffffffff + +#ifndef Pack_32 +#define Pack_32 +#endif + +#ifdef KR_headers +#define FFFFFFFF ((((unsigned long)0xffff)<<16)|(unsigned long)0xffff) +#else +#define FFFFFFFF 0xffffffffUL +#endif + +#ifdef NO_LONG_LONG +#undef ULLong +#ifdef Just_16 +#undef Pack_32 +/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. + * This makes some inner loops simpler and sometimes saves work + * during multiplications, but it often seems to make things slightly + * slower. Hence the default is now to store 32 bits per Long. + */ +#endif +#else /* long long available */ +#ifndef Llong +#define Llong long long +#endif +#ifndef ULLong +#define ULLong unsigned Llong +#endif +#endif /* NO_LONG_LONG */ + +#ifndef MULTIPLE_THREADS +#define ACQUIRE_DTOA_LOCK(n) /*nothing*/ +#define FREE_DTOA_LOCK(n) /*nothing*/ +#endif + +#define Kmax 15 + +#ifdef __cplusplus +#if 0 +extern "C" double strtod(const char *s00, char **se); +extern "C" char *dtoa(double d, int mode, int ndigits, + int *decpt, int *sign, char **rve); +#endif +#endif + + struct +Bigint { + struct Bigint *next; + int k, maxwds, sign, wds; + ULong x[1]; + }; + + typedef struct Bigint Bigint; +#define HAVE_BIGINT +#include "dtoa.h" + +#ifndef Use_J_Memory +Error! Code requires Use_J_Memory due to modifications. +#endif + +static void *d2a_Malloc(struct dtoa_info *d2a, int k); +static Bigint *d2a_Balloc(struct dtoa_info *d2a, int k); +static void d2a_Bfree(struct dtoa_info *d2a, Bigint *v); + +#define p5s (d2a->_p5s) +#define private_mem (d2a->_private_mem) +#define pmem_next (d2a->_pmem_next) +#define freelist (d2a->_freelist) + +#define MALLOC(n) d2a_Malloc(d2a, n) +#define Balloc(k) d2a_Balloc(d2a, k) +#define Bfree(v) d2a_Bfree(d2a, v) +#define multadd(b,m,a) d2a_multadd(d2a, b, m, a) +#define i2b(i) d2a_i2b(d2a, i) +#define mult(a,b) d2a_mult(d2a, a, b) +#define nrv_alloc(s,rve,n) d2a_nrv_alloc(d2a,s,rve,n) +#define rv_alloc(n) d2a_rv_alloc(d2a, n) +#define freedtoa(x) d2a_freedtoa(d2a, x) +#define d2b(d,e,b) d2a_d2b(d2a,d,e,b) +#define pow5mult(b,k) d2a_pow5mult(d2a,b,k) +#define diff(x,y) d2a_diff(d2a,x,y) +#define lshift(x,y) d2a_lshift(d2a,x,y) + +/* static Bigint *freelist[Kmax+1]; */ + + static Bigint * +d2a_Balloc +#ifdef KR_headers + (k) int k; +#else + (struct dtoa_info *d2a, int k) +#endif +{ + int x; + Bigint *rv; +#ifndef Omit_Private_Memory + unsigned int len; +#endif + + ACQUIRE_DTOA_LOCK(0); + if (rv = freelist[k]) { + freelist[k] = rv->next; + } + else { + x = 1 << k; +#ifdef Omit_Private_Memory + rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); +#else + len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) + /sizeof(double); + if (pmem_next - private_mem + len <= PRIVATE_mem) { + rv = (Bigint*)pmem_next; + pmem_next += len; + } + else + rv = (Bigint*)MALLOC(len*sizeof(double)); +#endif + rv->k = k; + rv->maxwds = x; + } + FREE_DTOA_LOCK(0); + rv->sign = rv->wds = 0; + return rv; + } + + static void +d2a_Bfree +#ifdef KR_headers + (v) Bigint *v; +#else + (struct dtoa_info *d2a, Bigint *v) +#endif +{ + if (v) { + ACQUIRE_DTOA_LOCK(0); + v->next = freelist[v->k]; + freelist[v->k] = v; + FREE_DTOA_LOCK(0); + } + } + +#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ +y->wds*sizeof(Long) + 2*sizeof(int)) + + static Bigint * +d2a_multadd +#ifdef KR_headers + (b, m, a) Bigint *b; int m, a; +#else + (struct dtoa_info *d2a, Bigint *b, int m, int a) /* multiply by m and add a */ +#endif +{ + int i, wds; +#ifdef ULLong + ULong *x; + ULLong carry, y; +#else + ULong carry, *x, y; +#ifdef Pack_32 + ULong xi, z; +#endif +#endif + Bigint *b1; + + wds = b->wds; + x = b->x; + i = 0; + carry = a; + do { +#ifdef ULLong + y = *x * (ULLong)m + carry; + carry = y >> 32; + *x++ = (ULong)(y & FFFFFFFF); +#else +#ifdef Pack_32 + xi = *x; + y = (xi & 0xffff) * m + carry; + z = (xi >> 16) * m + (y >> 16); + carry = z >> 16; + *x++ = (z << 16) + (y & 0xffff); +#else + y = *x * m + carry; + carry = y >> 16; + *x++ = y & 0xffff; +#endif +#endif + } + while(++i < wds); + if (carry) { + if (wds >= b->maxwds) { + b1 = Balloc(b->k+1); + Bcopy(b1, b); + Bfree(b); + b = b1; + } + b->x[wds++] = (ULong)carry; + b->wds = wds; + } + return b; + } + +#if 0 + static Bigint * +d2a_s2b +#ifdef KR_headers + (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; +#else + (struct dtoa_info *d2a, CONST char *s, int nd0, int nd, ULong y9) +#endif +{ + Bigint *b; + int i, k; + Long x, y; + + x = (nd + 8) / 9; + for(k = 0, y = 1; x > y; y <<= 1, k++) ; +#ifdef Pack_32 + b = Balloc(k); + b->x[0] = y9; + b->wds = 1; +#else + b = Balloc(k+1); + b->x[0] = y9 & 0xffff; + b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; +#endif + + i = 9; + if (9 < nd0) { + s += 9; + do b = multadd(b, 10, *s++ - '0'); + while(++i < nd0); + s++; + } + else + s += 10; + for(; i < nd; i++) + b = multadd(b, 10, *s++ - '0'); + return b; + } +#endif + + static int +hi0bits +#ifdef KR_headers + (x) register ULong x; +#else + (register ULong x) +#endif +{ + register int k = 0; + + if (!(x & 0xffff0000)) { + k = 16; + x <<= 16; + } + if (!(x & 0xff000000)) { + k += 8; + x <<= 8; + } + if (!(x & 0xf0000000)) { + k += 4; + x <<= 4; + } + if (!(x & 0xc0000000)) { + k += 2; + x <<= 2; + } + if (!(x & 0x80000000)) { + k++; + if (!(x & 0x40000000)) + return 32; + } + return k; + } + + static int +lo0bits +#ifdef KR_headers + (y) ULong *y; +#else + (ULong *y) +#endif +{ + register int k; + register ULong x = *y; + + if (x & 7) { + if (x & 1) + return 0; + if (x & 2) { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + k = 0; + if (!(x & 0xffff)) { + k = 16; + x >>= 16; + } + if (!(x & 0xff)) { + k += 8; + x >>= 8; + } + if (!(x & 0xf)) { + k += 4; + x >>= 4; + } + if (!(x & 0x3)) { + k += 2; + x >>= 2; + } + if (!(x & 1)) { + k++; + x >>= 1; + if (!x) + return 32; + } + *y = x; + return k; + } + + static Bigint * +d2a_i2b +#ifdef KR_headers + (i) int i; +#else + (struct dtoa_info *d2a, int i) +#endif +{ + Bigint *b; + + b = Balloc(1); + b->x[0] = i; + b->wds = 1; + return b; + } + + static Bigint * +d2a_mult +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (struct dtoa_info *d2a, Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int k, wa, wb, wc; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong y; +#ifdef ULLong + ULLong carry, z; +#else + ULong carry, z; +#ifdef Pack_32 + ULong z2; +#endif +#endif + + if (a->wds < b->wds) { + c = a; + a = b; + b = c; + } + k = a->k; + wa = a->wds; + wb = b->wds; + wc = wa + wb; + if (wc > a->maxwds) + k++; + c = Balloc(k); + for(x = c->x, xa = x + wc; x < xa; x++) + *x = 0; + xa = a->x; + xae = xa + wa; + xb = b->x; + xbe = xb + wb; + xc0 = c->x; +#ifdef ULLong + for(; xb < xbe; xc0++) { + if (y = *xb++) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * (ULLong)y + *xc + carry; + carry = z >> 32; + *xc++ = (ULong)(z & FFFFFFFF); + } + while(x < xae); + *xc = (ULong)carry; + } + } +#else +#ifdef Pack_32 + for(; xb < xbe; xb++, xc0++) { + if (y = *xb & 0xffff) { + x = xa; + xc = xc0; + carry = 0; + do { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc(xc, z2, z); + } + while(x < xae); + *xc = carry; + } + if (y = *xb >> 16) { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc(xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } + while(x < xae); + *xc = z2; + } + } +#else + for(; xb < xbe; xc0++) { + if (y = *xb++) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } + while(x < xae); + *xc = carry; + } + } +#endif +#endif + for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; + c->wds = wc; + return c; + } + +#ifndef Use_J_Memory + static Bigint *p5s; +#endif + + static Bigint * +d2a_pow5mult +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (struct dtoa_info *d2a, Bigint *b, int k) +#endif +{ + Bigint *b1, *p5, *p51; + int i; + static const int p05[3] = { 5, 25, 125 }; + + if (i = k & 3) + b = multadd(b, p05[i-1], 0); + + if (!(k >>= 2)) + return b; + if (!(p5 = p5s)) { + /* first time */ +#ifdef MULTIPLE_THREADS + ACQUIRE_DTOA_LOCK(1); + if (!(p5 = p5s)) { + p5 = p5s = i2b(625); + p5->next = 0; + } + FREE_DTOA_LOCK(1); +#else + p5 = p5s = i2b(625); + p5->next = 0; +#endif + } + for(;;) { + if (k & 1) { + b1 = mult(b, p5); + Bfree(b); + b = b1; + } + if (!(k >>= 1)) + break; + if (!(p51 = p5->next)) { +#ifdef MULTIPLE_THREADS + ACQUIRE_DTOA_LOCK(1); + if (!(p51 = p5->next)) { + p51 = p5->next = mult(p5,p5); + p51->next = 0; + } + FREE_DTOA_LOCK(1); +#else + p51 = p5->next = mult(p5,p5); + p51->next = 0; +#endif + } + p5 = p51; + } + return b; + } + + static Bigint * +d2a_lshift +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (struct dtoa_info *d2a, Bigint *b, int k) +#endif +{ + int i, k1, n, n1; + Bigint *b1; + ULong *x, *x1, *xe, z; + +#ifdef Pack_32 + n = k >> 5; +#else + n = k >> 4; +#endif + k1 = b->k; + n1 = n + b->wds + 1; + for(i = b->maxwds; n1 > i; i <<= 1) + k1++; + b1 = Balloc(k1); + x1 = b1->x; + for(i = 0; i < n; i++) + *x1++ = 0; + x = b->x; + xe = x + b->wds; +#ifdef Pack_32 + if (k &= 0x1f) { + k1 = 32 - k; + z = 0; + do { + *x1++ = *x << k | z; + z = *x++ >> k1; + } + while(x < xe); + if (*x1 = z) + ++n1; + } +#else + if (k &= 0xf) { + k1 = 16 - k; + z = 0; + do { + *x1++ = *x << k & 0xffff | z; + z = *x++ >> k1; + } + while(x < xe); + if (*x1 = z) + ++n1; + } +#endif + else do + *x1++ = *x++; + while(x < xe); + b1->wds = n1 - 1; + Bfree(b); + return b1; + } + + static int +cmp +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + ULong *xa, *xa0, *xb, *xb0; + int i, j; + + i = a->wds; + j = b->wds; +#ifdef DEBUG + if (i > 1 && !a->x[i-1]) + Bug("cmp called with a->x[a->wds-1] == 0"); + if (j > 1 && !b->x[j-1]) + Bug("cmp called with b->x[b->wds-1] == 0"); +#endif + if (i -= j) + return i; + xa0 = a->x; + xa = xa0 + j; + xb0 = b->x; + xb = xb0 + j; + for(;;) { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; + } + + static Bigint * +d2a_diff +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (struct dtoa_info *d2a, Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int i, wa, wb; + ULong *xa, *xae, *xb, *xbe, *xc; +#ifdef ULLong + ULLong borrow, y; +#else + ULong borrow, y; +#ifdef Pack_32 + ULong z; +#endif +#endif + + i = cmp(a,b); + if (!i) { + c = Balloc(0); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (i < 0) { + c = a; + a = b; + b = c; + i = 1; + } + else + i = 0; + c = Balloc(a->k); + c->sign = i; + wa = a->wds; + xa = a->x; + xae = xa + wa; + wb = b->wds; + xb = b->x; + xbe = xb + wb; + xc = c->x; + borrow = 0; +#ifdef ULLong + do { + y = (ULLong)*xa++ - *xb++ - borrow; + borrow = y >> 32 & (ULong)1; + *xc++ = (ULong)(y & FFFFFFFF); + } + while(xb < xbe); + while(xa < xae) { + y = *xa++ - borrow; + borrow = y >> 32 & (ULong)1; + *xc++ = (ULong)(y & FFFFFFFF); + } +#else +#ifdef Pack_32 + do { + y = (*xa & 0xffff) - (*xb & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - (*xb++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } + while(xb < xbe); + while(xa < xae) { + y = (*xa & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } +#else + do { + y = *xa++ - *xb++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } + while(xb < xbe); + while(xa < xae) { + y = *xa++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } +#endif +#endif + while(!*--xc) + wa--; + c->wds = wa; + return c; + } + +#if 0 + static double +ulp +#ifdef KR_headers + (x) double x; +#else + (double x) +#endif +{ + register Long L; + double a; + + L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; +#ifndef Avoid_Underflow +#ifndef Sudden_Underflow + if (L > 0) { +#endif +#endif +#ifdef IBM + L |= Exp_msk1 >> 4; +#endif + word0(a) = L; + word1(a) = 0; +#ifndef Avoid_Underflow +#ifndef Sudden_Underflow + } + else { + L = -L >> Exp_shift; + if (L < Exp_shift) { + word0(a) = 0x80000 >> L; + word1(a) = 0; + } + else { + word0(a) = 0; + L -= Exp_shift; + word1(a) = L >= 31 ? 1 : 1 << 31 - L; + } + } +#endif +#endif + return dval(a); + } + + static double +b2d +#ifdef KR_headers + (a, e) Bigint *a; int *e; +#else + (Bigint *a, int *e) +#endif +{ + ULong *xa, *xa0, w, y, z; + int k; + double d; +#ifdef VAX + ULong d0, d1; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + + xa0 = a->x; + xa = xa0 + a->wds; + y = *--xa; +#ifdef DEBUG + if (!y) Bug("zero y in b2d"); +#endif + k = hi0bits(y); + *e = 32 - k; +#ifdef Pack_32 + if (k < Ebits) { + d0 = Exp_1 | y >> (Ebits - k); + w = xa > xa0 ? *--xa : 0; + d1 = y << ((32-Ebits) + k) | w >> (Ebits - k); + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + if (k -= Ebits) { + d0 = Exp_1 | y << k | z >> (32 - k); + y = xa > xa0 ? *--xa : 0; + d1 = z << k | y >> (32 - k); + } + else { + d0 = Exp_1 | y; + d1 = z; + } +#else + if (k < Ebits + 16) { + z = xa > xa0 ? *--xa : 0; + d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; + w = xa > xa0 ? *--xa : 0; + y = xa > xa0 ? *--xa : 0; + d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + w = xa > xa0 ? *--xa : 0; + k -= Ebits + 16; + d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; + y = xa > xa0 ? *--xa : 0; + d1 = w << k + 16 | y << k; +#endif + ret_d: +#ifdef VAX + word0(d) = d0 >> 16 | d0 << 16; + word1(d) = d1 >> 16 | d1 << 16; +#else +#undef d0 +#undef d1 +#endif + return dval(d); + } +#endif + + static Bigint * +d2a_d2b +#ifdef KR_headers + (d, e, bits) double d; int *e, *bits; +#else + (struct dtoa_info *d2a, double d, int *e, int *bits) +#endif +{ + Bigint *b; + int de, k; + ULong *x, y, z; +#ifndef Sudden_Underflow + int i; +#endif +#ifdef VAX + ULong d0, d1; + d0 = word0(d) >> 16 | word0(d) << 16; + d1 = word1(d) >> 16 | word1(d) << 16; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + +#ifdef Pack_32 + b = Balloc(1); +#else + b = Balloc(2); +#endif + x = b->x; + + z = d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ +#ifdef Sudden_Underflow + de = (int)(d0 >> Exp_shift); +#ifndef IBM + z |= Exp_msk11; +#endif +#else + if (de = (int)(d0 >> Exp_shift)) + z |= Exp_msk1; +#endif +#ifdef Pack_32 + if (y = d1) { + if (k = lo0bits(&y)) { + x[0] = y | z << (32 - k); + z >>= k; + } + else + x[0] = y; +#ifndef Sudden_Underflow + i = +#endif + b->wds = (x[1] = z) ? 2 : 1; + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + x[0] = z; +#ifndef Sudden_Underflow + i = +#endif + b->wds = 1; + k += 32; + } +#else + if (y = d1) { + if (k = lo0bits(&y)) + if (k >= 16) { + x[0] = y | z << 32 - k & 0xffff; + x[1] = z >> k - 16 & 0xffff; + x[2] = z >> k; + i = 2; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16 | z << 16 - k & 0xffff; + x[2] = z >> k & 0xffff; + x[3] = z >> k+16; + i = 3; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + if (k >= 16) { + x[0] = z; + i = 0; + } + else { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while(!x[i]) + --i; + b->wds = i + 1; +#endif +#ifndef Sudden_Underflow + if (de) { +#endif +#ifdef IBM + *e = (de - Bias - (P-1) << 2) + k; + *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); +#else + *e = de - Bias - (P-1) + k; + *bits = P - k; +#endif +#ifndef Sudden_Underflow + } + else { + *e = de - Bias - (P-1) + 1 + k; +#ifdef Pack_32 + *bits = 32*i - hi0bits(x[i-1]); +#else + *bits = (i+2)*16 - hi0bits(x[i]); +#endif + } +#endif + return b; + } +#undef d0 +#undef d1 + +#if 0 + static double +ratio +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + double da, db; + int k, ka, kb; + + dval(da) = b2d(a, &ka); + dval(db) = b2d(b, &kb); +#ifdef Pack_32 + k = ka - kb + 32*(a->wds - b->wds); +#else + k = ka - kb + 16*(a->wds - b->wds); +#endif +#ifdef IBM + if (k > 0) { + word0(da) += (k >> 2)*Exp_msk1; + if (k &= 3) + dval(da) *= 1 << k; + } + else { + k = -k; + word0(db) += (k >> 2)*Exp_msk1; + if (k &= 3) + dval(db) *= 1 << k; + } +#else + if (k > 0) + word0(da) += k*Exp_msk1; + else { + k = -k; + word0(db) += k*Exp_msk1; + } +#endif + return dval(da) / dval(db); + } +#endif + + static CONST double +tens[] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22 +#ifdef VAX + , 1e23, 1e24 +#endif + }; + + static CONST double +#ifdef IEEE_Arith +bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; +static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, +#ifdef Avoid_Underflow + 9007199254740992.*9007199254740992.e-256 + /* = 2^106 * 1e-53 */ +#else + 1e-256 +#endif + }; +/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */ +/* flag unnecessarily. It leads to a song and dance at the end of strtod. */ +#define Scale_Bit 0x10 +#define n_bigtens 5 +#else +#ifdef IBM +bigtens[] = { 1e16, 1e32, 1e64 }; +static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 }; +#define n_bigtens 3 +#else +bigtens[] = { 1e16, 1e32 }; +static CONST double tinytens[] = { 1e-16, 1e-32 }; +#define n_bigtens 2 +#endif +#endif + +#ifndef IEEE_Arith +#undef INFNAN_CHECK +#endif + +#ifdef INFNAN_CHECK + +#ifndef NAN_WORD0 +#define NAN_WORD0 0x7ff80000 +#endif + +#ifndef NAN_WORD1 +#define NAN_WORD1 0 +#endif + + static int +match +#ifdef KR_headers + (sp, t) char **sp, *t; +#else + (CONST char **sp, char *t) +#endif +{ + int c, d; + CONST char *s = *sp; + + while(d = *t++) { + if ((c = *++s) >= 'A' && c <= 'Z') + c += 'a' - 'A'; + if (c != d) + return 0; + } + *sp = s + 1; + return 1; + } + +#ifndef No_Hex_NaN + static void +hexnan +#ifdef KR_headers + (rvp, sp) double *rvp; CONST char **sp; +#else + (double *rvp, CONST char **sp) +#endif +{ + ULong c, x[2]; + CONST char *s; + int havedig, udx0, xshift; + + x[0] = x[1] = 0; + havedig = xshift = 0; + udx0 = 1; + s = *sp; + while(c = *(CONST unsigned char*)++s) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'a' && c <= 'f') + c += 10 - 'a'; + else if (c >= 'A' && c <= 'F') + c += 10 - 'A'; + else if (c <= ' ') { + if (udx0 && havedig) { + udx0 = 0; + xshift = 1; + } + continue; + } + else if (/*(*/ c == ')' && havedig) { + *sp = s + 1; + break; + } + else + return; /* invalid form: don't change *sp */ + havedig = 1; + if (xshift) { + xshift = 0; + x[0] = x[1]; + x[1] = 0; + } + if (udx0) + x[0] = (x[0] << 4) | (x[1] >> 28); + x[1] = (x[1] << 4) | c; + } + if ((x[0] &= 0xfffff) || x[1]) { + word0(*rvp) = Exp_mask | x[0]; + word1(*rvp) = x[1]; + } + } +#endif /*No_Hex_NaN*/ +#endif /* INFNAN_CHECK */ + +#if 0 + double +strtod +#ifdef KR_headers + (s00, se) CONST char *s00; char **se; +#else + (void *jt, CONST char *s00, char **se) +#endif +{ +#ifdef Avoid_Underflow + int scale; +#endif + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, + e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; + CONST char *s, *s0, *s1; + double aadj, aadj1, adj, rv, rv0; + Long L; + ULong y, z; + Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; +#ifdef SET_INEXACT + int inexact, oldinexact; +#endif +#ifdef Honor_FLT_ROUNDS + int rounding; +#endif +#ifdef USE_LOCALE + CONST char *s2; +#endif + + sign = nz0 = nz = 0; + dval(rv) = 0.; + for(s = s00;;s++) switch(*s) { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) + goto break2; + /* no break */ + case 0: + goto ret0; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } + break2: + if (*s == '0') { + nz0 = 1; + while(*++s == '0') ; + if (!*s) + goto ret; + } + s0 = s; + y = z = 0; + for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10*y + c - '0'; + else if (nd < 16) + z = 10*z + c - '0'; + nd0 = nd; +#ifdef USE_LOCALE + s1 = localeconv()->decimal_point; + if (c == *s1) { + c = '.'; + if (*++s1) { + s2 = s; + for(;;) { + if (*++s2 != *s1) { + c = 0; + break; + } + if (!*++s1) { + s = s2; + break; + } + } + } + } +#endif + if (c == '.') { + c = *++s; + if (!nd) { + for(; c == '0'; c = *++s) + nz++; + if (c > '0' && c <= '9') { + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for(; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10*y + c; + else if (nd <= DBL_DIG + 1) + z = 10*z + c; + nz = 0; + } + } + } + dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + goto ret0; + } + s00 = s; + esign = 0; + switch(c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while(c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) + e = -e; + } + else + e = 0; + } + else + s = s00; + } + if (!nd) { + if (!nz && !nz0) { +#ifdef INFNAN_CHECK + /* Check for Nan and Infinity */ + switch(c) { + case 'i': + case 'I': + if (match(&s,"nf")) { + --s; + if (!match(&s,"inity")) + ++s; + word0(rv) = 0x7ff00000; + word1(rv) = 0; + goto ret; + } + break; + case 'n': + case 'N': + if (match(&s, "an")) { + word0(rv) = NAN_WORD0; + word1(rv) = NAN_WORD1; +#ifndef No_Hex_NaN + if (*s == '(') /*)*/ + hexnan(&rv, &s); +#endif + goto ret; + } + } +#endif /* INFNAN_CHECK */ + ret0: + s = s00; + sign = 0; + } + goto ret; + } + e1 = e -= nf; + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + dval(rv) = y; + if (k > 9) { +#ifdef SET_INEXACT + if (k > DBL_DIG) + oldinexact = get_inexact(); +#endif + dval(rv) = tens[k - 9] * dval(rv) + z; + } + bd0 = 0; + if (nd <= DBL_DIG +#ifndef RND_PRODQUOT +#ifndef Honor_FLT_ROUNDS + && Flt_Rounds == 1 +#endif +#endif + ) { + if (!e) + goto ret; + if (e > 0) { + if (e <= Ten_pmax) { +#ifdef VAX + goto vax_ovfl_check; +#else +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + /* rv = */ rounded_product(dval(rv), tens[e]); + goto ret; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + e -= i; + dval(rv) *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + word0(rv) -= P*Exp_msk1; + /* rv = */ rounded_product(dval(rv), tens[e]); + if ((word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) + goto ovfl; + word0(rv) += P*Exp_msk1; +#else + /* rv = */ rounded_product(dval(rv), tens[e]); +#endif + goto ret; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) { +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + /* rv = */ rounded_quotient(dval(rv), tens[-e]); + goto ret; + } +#endif + } + e1 += nd - k; + +#ifdef IEEE_Arith +#ifdef SET_INEXACT + inexact = 1; + if (k <= DBL_DIG) + oldinexact = get_inexact(); +#endif +#ifdef Avoid_Underflow + scale = 0; +#endif +#ifdef Honor_FLT_ROUNDS + if ((rounding = Flt_Rounds) >= 2) { + if (sign) + rounding = rounding == 2 ? 0 : 2; + else + if (rounding != 2) + rounding = 0; + } +#endif +#endif /*IEEE_Arith*/ + + /* Get starting approximation = rv * 10**e1 */ + + if (e1 > 0) { + if (i = e1 & 15) + dval(rv) *= tens[i]; + if (e1 &= ~15) { + if (e1 > DBL_MAX_10_EXP) { + ovfl: +#ifndef NO_ERRNO + errno = ERANGE; +#endif + /* Can't trust HUGE_VAL */ +#ifdef IEEE_Arith +#ifdef Honor_FLT_ROUNDS + switch(rounding) { + case 0: /* toward 0 */ + case 3: /* toward -infinity */ + word0(rv) = Big0; + word1(rv) = Big1; + break; + default: + word0(rv) = Exp_mask; + word1(rv) = 0; + } +#else /*Honor_FLT_ROUNDS*/ + word0(rv) = Exp_mask; + word1(rv) = 0; +#endif /*Honor_FLT_ROUNDS*/ +#ifdef SET_INEXACT + /* set overflow bit */ + dval(rv0) = 1e300; + dval(rv0) *= dval(rv0); +#endif +#else /*IEEE_Arith*/ + word0(rv) = Big0; + word1(rv) = Big1; +#endif /*IEEE_Arith*/ + if (bd0) + goto retfree; + goto ret; + } + e1 >>= 4; + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= bigtens[j]; + /* The last multiplication could overflow. */ + word0(rv) -= P*Exp_msk1; + dval(rv) *= bigtens[j]; + if ((z = word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-P)) + goto ovfl; + if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { + /* set to largest number */ + /* (Can't trust DBL_MAX) */ + word0(rv) = Big0; + word1(rv) = Big1; + } + else + word0(rv) += P*Exp_msk1; + } + } + else if (e1 < 0) { + e1 = -e1; + if (i = e1 & 15) + dval(rv) /= tens[i]; + if (e1 >>= 4) { + if (e1 >= 1 << n_bigtens) + goto undfl; +#ifdef Avoid_Underflow + if (e1 & Scale_Bit) + scale = 2*P; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask) + >> Exp_shift)) > 0) { + /* scaled rv is denormal; zap j low bits */ + if (j >= 32) { + word1(rv) = 0; + if (j >= 53) + word0(rv) = (P+2)*Exp_msk1; + else + word0(rv) &= 0xffffffff << j-32; + } + else + word1(rv) &= 0xffffffff << j; + } +#else + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + /* The last multiplication could underflow. */ + dval(rv0) = dval(rv); + dval(rv) *= tinytens[j]; + if (!dval(rv)) { + dval(rv) = 2.*dval(rv0); + dval(rv) *= tinytens[j]; +#endif + if (!dval(rv)) { + undfl: + dval(rv) = 0.; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + if (bd0) + goto retfree; + goto ret; + } +#ifndef Avoid_Underflow + word0(rv) = Tiny0; + word1(rv) = Tiny1; + /* The refinement below will clean + * this approximation up. + */ + } +#endif + } + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b(s0, nd0, nd, y); + + for(;;) { + bd = Balloc(bd0->k); + Bcopy(bd, bd0); + bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ + bs = i2b(1); + + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; +#ifdef Honor_FLT_ROUNDS + if (rounding != 1) + bs2++; +#endif +#ifdef Avoid_Underflow + j = bbe - scale; + i = j + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j += P - Emin; + else + j = P + 1 - bbbits; +#else /*Avoid_Underflow*/ +#ifdef Sudden_Underflow +#ifdef IBM + j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3); +#else + j = P + 1 - bbbits; +#endif +#else /*Sudden_Underflow*/ + j = bbe; + i = j + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j += P - Emin; + else + j = P + 1 - bbbits; +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + bb2 += j; + bd2 += j; +#ifdef Avoid_Underflow + bd2 += scale; +#endif + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = pow5mult(bs, bb5); + bb1 = mult(bs, bb); + Bfree(bb); + bb = bb1; + } + if (bb2 > 0) + bb = lshift(bb, bb2); + if (bd5 > 0) + bd = pow5mult(bd, bd5); + if (bd2 > 0) + bd = lshift(bd, bd2); + if (bs2 > 0) + bs = lshift(bs, bs2); + delta = diff(bb, bd); + dsign = delta->sign; + delta->sign = 0; + i = cmp(delta, bs); +#ifdef Honor_FLT_ROUNDS + if (rounding != 1) { + if (i < 0) { + /* Error is less than an ulp */ + if (!delta->x[0] && delta->wds <= 1) { + /* exact */ +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + if (rounding) { + if (dsign) { + adj = 1.; + goto apply_adj; + } + } + else if (!dsign) { + adj = -1.; + if (!word1(rv) + && !(word0(rv) & Frac_mask)) { + y = word0(rv) & Exp_mask; +#ifdef Avoid_Underflow + if (!scale || y > 2*P*Exp_msk1) +#else + if (y) +#endif + { + delta = lshift(delta,Log2P); + if (cmp(delta, bs) <= 0) + adj = -0.5; + } + } + apply_adj: +#ifdef Avoid_Underflow + if (scale && (y = word0(rv) & Exp_mask) + <= 2*P*Exp_msk1) + word0(adj) += (2*P+1)*Exp_msk1 - y; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= + P*Exp_msk1) { + word0(rv) += P*Exp_msk1; + dval(rv) += adj*ulp(dval(rv)); + word0(rv) -= P*Exp_msk1; + } + else +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + dval(rv) += adj*ulp(dval(rv)); + } + break; + } + adj = ratio(delta, bs); + if (adj < 1.) + adj = 1.; + if (adj <= 0x7ffffffe) { + /* adj = rounding ? ceil(adj) : floor(adj); */ + y = adj; + if (y != adj) { + if (!((rounding>>1) ^ dsign)) + y++; + adj = y; + } + } +#ifdef Avoid_Underflow + if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) + word0(adj) += (2*P+1)*Exp_msk1 - y; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { + word0(rv) += P*Exp_msk1; + adj *= ulp(dval(rv)); + if (dsign) + dval(rv) += adj; + else + dval(rv) -= adj; + word0(rv) -= P*Exp_msk1; + goto cont; + } +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + adj *= ulp(dval(rv)); + if (dsign) + dval(rv) += adj; + else + dval(rv) -= adj; + goto cont; + } +#endif /*Honor_FLT_ROUNDS*/ + + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask +#ifdef IEEE_Arith +#ifdef Avoid_Underflow + || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1 +#else + || (word0(rv) & Exp_mask) <= Exp_msk1 +#endif +#endif + ) { +#ifdef SET_INEXACT + if (!delta->x[0] && delta->wds <= 1) + inexact = 0; +#endif + break; + } + if (!delta->x[0] && delta->wds <= 1) { + /* exact result */ +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + delta = lshift(delta,Log2P); + if (cmp(delta, bs) > 0) + goto drop_down; + break; + } + if (i == 0) { + /* exactly half-way between */ + if (dsign) { + if ((word0(rv) & Bndry_mask1) == Bndry_mask1 + && word1(rv) == ( +#ifdef Avoid_Underflow + (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) + ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) : +#endif + 0xffffffff)) { + /*boundary case -- increment exponent*/ + word0(rv) = (word0(rv) & Exp_mask) + + Exp_msk1 +#ifdef IBM + | Exp_msk1 >> 4 +#endif + ; + word1(rv) = 0; +#ifdef Avoid_Underflow + dsign = 0; +#endif + break; + } + } + else if (!(word0(rv) & Bndry_mask) && !word1(rv)) { + drop_down: + /* boundary case -- decrement exponent */ +#ifdef Sudden_Underflow /*{{*/ + L = word0(rv) & Exp_mask; +#ifdef IBM + if (L < Exp_msk1) +#else +#ifdef Avoid_Underflow + if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1)) +#else + if (L <= Exp_msk1) +#endif /*Avoid_Underflow*/ +#endif /*IBM*/ + goto undfl; + L -= Exp_msk1; +#else /*Sudden_Underflow}{*/ +#ifdef Avoid_Underflow + if (scale) { + L = word0(rv) & Exp_mask; + if (L <= (2*P+1)*Exp_msk1) { + if (L > (P+2)*Exp_msk1) + /* round even ==> */ + /* accept rv */ + break; + /* rv = smallest denormal */ + goto undfl; + } + } +#endif /*Avoid_Underflow*/ + L = (word0(rv) & Exp_mask) - Exp_msk1; +#endif /*Sudden_Underflow}}*/ + word0(rv) = L | Bndry_mask1; + word1(rv) = 0xffffffff; +#ifdef IBM + goto cont; +#else + break; +#endif + } +#ifndef ROUND_BIASED + if (!(word1(rv) & LSB)) + break; +#endif + if (dsign) + dval(rv) += ulp(dval(rv)); +#ifndef ROUND_BIASED + else { + dval(rv) -= ulp(dval(rv)); +#ifndef Sudden_Underflow + if (!dval(rv)) + goto undfl; +#endif + } +#ifdef Avoid_Underflow + dsign = 1 - dsign; +#endif +#endif + break; + } + if ((aadj = ratio(delta, bs)) <= 2.) { + if (dsign) + aadj = aadj1 = 1.; + else if (word1(rv) || word0(rv) & Bndry_mask) { +#ifndef Sudden_Underflow + if (word1(rv) == Tiny1 && !word0(rv)) + goto undfl; +#endif + aadj = 1.; + aadj1 = -1.; + } + else { + /* special case -- power of FLT_RADIX to be */ + /* rounded down... */ + + if (aadj < 2./FLT_RADIX) + aadj = 1./FLT_RADIX; + else + aadj *= 0.5; + aadj1 = -aadj; + } + } + else { + aadj *= 0.5; + aadj1 = dsign ? aadj : -aadj; +#ifdef Check_FLT_ROUNDS + switch(Rounding) { + case 2: /* towards +infinity */ + aadj1 -= 0.5; + break; + case 0: /* towards 0 */ + case 3: /* towards -infinity */ + aadj1 += 0.5; + } +#else + if (Flt_Rounds == 0) + aadj1 += 0.5; +#endif /*Check_FLT_ROUNDS*/ + } + y = word0(rv) & Exp_mask; + + /* Check for overflow */ + + if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { + dval(rv0) = dval(rv); + word0(rv) -= P*Exp_msk1; + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; + if ((word0(rv) & Exp_mask) >= + Exp_msk1*(DBL_MAX_EXP+Bias-P)) { + if (word0(rv0) == Big0 && word1(rv0) == Big1) + goto ovfl; + word0(rv) = Big0; + word1(rv) = Big1; + goto cont; + } + else + word0(rv) += P*Exp_msk1; + } + else { +#ifdef Avoid_Underflow + if (scale && y <= 2*P*Exp_msk1) { + if (aadj <= 0x7fffffff) { + if ((z = aadj) <= 0) + z = 1; + aadj = z; + aadj1 = dsign ? aadj : -aadj; + } + word0(aadj1) += (2*P+1)*Exp_msk1 - y; + } + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { + dval(rv0) = dval(rv); + word0(rv) += P*Exp_msk1; + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#ifdef IBM + if ((word0(rv) & Exp_mask) < P*Exp_msk1) +#else + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) +#endif + { + if (word0(rv0) == Tiny0 + && word1(rv0) == Tiny1) + goto undfl; + word0(rv) = Tiny0; + word1(rv) = Tiny1; + goto cont; + } + else + word0(rv) -= P*Exp_msk1; + } + else { + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; + } +#else /*Sudden_Underflow*/ + /* Compute adj so that the IEEE rounding rules will + * correctly round rv + adj in some half-way cases. + * If rv * ulp(rv) is denormalized (i.e., + * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid + * trouble from bits lost to denormalization; + * example: 1.2e-307 . + */ + if (y <= (P-1)*Exp_msk1 && aadj > 1.) { + aadj1 = (double)(int)(aadj + 0.5); + if (!dsign) + aadj1 = -aadj1; + } + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + } + z = word0(rv) & Exp_mask; +#ifndef SET_INEXACT +#ifdef Avoid_Underflow + if (!scale) +#endif + if (y == z) { + /* Can we stop now? */ + L = (Long)aadj; + aadj -= L; + /* The tolerances below are conservative. */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask) { + if (aadj < .4999999 || aadj > .5000001) + break; + } + else if (aadj < .4999999/FLT_RADIX) + break; + } +#endif + cont: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(delta); + } +#ifdef SET_INEXACT + if (inexact) { + if (!oldinexact) { + word0(rv0) = Exp_1 + (70 << Exp_shift); + word1(rv0) = 0; + dval(rv0) += 1.; + } + } + else if (!oldinexact) + clear_inexact(); +#endif +#ifdef Avoid_Underflow + if (scale) { + word0(rv0) = Exp_1 - 2*P*Exp_msk1; + word1(rv0) = 0; + dval(rv) *= dval(rv0); +#ifndef NO_ERRNO + /* try to avoid the bug of testing an 8087 register value */ + if (word0(rv) == 0 && word1(rv) == 0) + errno = ERANGE; +#endif + } +#endif /* Avoid_Underflow */ +#ifdef SET_INEXACT + if (inexact && !(word0(rv) & Exp_mask)) { + /* set underflow bit */ + dval(rv0) = 1e-300; + dval(rv0) *= dval(rv0); + } +#endif + retfree: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + ret: + if (se) + *se = (char *)s; + return sign ? -dval(rv) : dval(rv); + } +#endif + + static int +quorem +#ifdef KR_headers + (b, S) Bigint *b, *S; +#else + (Bigint *b, Bigint *S) +#endif +{ + int n; + ULong *bx, *bxe, q, *sx, *sxe; +#ifdef ULLong + ULLong borrow, carry, y, ys; +#else + ULong borrow, carry, y, ys; +#ifdef Pack_32 + ULong si, z, zs; +#endif +#endif + + n = S->wds; +#ifdef DEBUG + /*debug*/ if (b->wds > n) + /*debug*/ Bug("oversize b in quorem"); +#endif + if (b->wds < n) + return 0; + sx = S->x; + sxe = sx + --n; + bx = b->x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ +#ifdef DEBUG + /*debug*/ if (q > 9) + /*debug*/ Bug("oversized quotient in quorem"); +#endif + if (q) { + borrow = 0; + carry = 0; + do { +#ifdef ULLong + ys = *sx++ * (ULLong)q + carry; + carry = ys >> 32; + y = *bx - (ys & FFFFFFFF) - borrow; + borrow = y >> 32 & (ULong)1; + *bx++ = (ULong)(y & FFFFFFFF); +#else +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); +#else + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; +#endif +#endif + } + while(sx <= sxe); + if (!*bxe) { + bx = b->x; + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + if (cmp(b, S) >= 0) { + q++; + borrow = 0; + carry = 0; + bx = b->x; + sx = S->x; + do { +#ifdef ULLong + ys = *sx++ + carry; + carry = ys >> 32; + y = *bx - (ys & FFFFFFFF) - borrow; + borrow = y >> 32 & (ULong)1; + *bx++ = (ULong)(y & FFFFFFFF); +#else +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); +#else + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; +#endif +#endif + } + while(sx <= sxe); + bx = b->x; + bxe = bx + n; + if (!*bxe) { + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + return q; + } + +#ifndef MULTIPLE_THREADS + static char *dtoa_result; +#endif + + static char * +#ifdef KR_headers +rv_alloc(i) int i; +#else +d2a_rv_alloc(struct dtoa_info *d2a, int i) +#endif +/* i is guarenteed i >= 0 by caller so the cast to unsigned below is safe */ +{ +#ifndef Use_J_Memory + int j, k, *r; + + j = sizeof(ULong); + for(k = 0; + sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= (unsigned)i; + j <<= 1) + k++; + r = (int*)Balloc(k); + *r = k; + return +#ifndef MULTIPLE_THREADS + dtoa_result = +#endif + (char *)(r+1); +#else + if(i>d2a->ndp) longjmp(d2a->_env, 2); /* this shouldn't happen? */ + return d2a->result; +#endif + } + + static char * +#ifdef KR_headers +nrv_alloc(s, rve, n) char *s, **rve; int n; +#else +d2a_nrv_alloc(struct dtoa_info *d2a, char *s, char **rve, int n) +#endif +{ + char *rv, *t; + + t = rv = rv_alloc(n); + /*while(*t = *s++) t++;*/ + while(*s){*t++=*s++;} /* don't copy the NUL */ + if (rve) + *rve = t; + return rv; + } + +/* freedtoa(s) must be used to free values s returned by dtoa + * when MULTIPLE_THREADS is #defined. It should be used in all cases, + * but for consistency with earlier versions of dtoa, it is optional + * when MULTIPLE_THREADS is not defined. + */ +#if 0 + static void +#ifdef KR_headers +freedtoa(s) char *s; +#else +d2a_freedtoa(struct dtoa_info *d2a, char *s) +#endif +{ + Bigint *b = (Bigint *)((int *)s - 1); + b->maxwds = 1 << (b->k = *(int*)b); + Bfree(b); +#ifndef MULTIPLE_THREADS + if (s == dtoa_result) + dtoa_result = 0; +#endif + } +#endif + +/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + * + * Inspired by "How to Print Floating-Point Numbers Accurately" by + * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the Long + * calculation. + */ + + static char * +d2a_dtoa +#ifdef KR_headers + (d, mode, ndigits, decpt, sign, rve) + double d; int mode, ndigits, *decpt, *sign; char **rve; +#else + (struct dtoa_info *d2a, double d, int mode, int ndigits, int *decpt, int *sign, char **rve) +#endif +{ + /* Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4,5 ==> similar to 2 and 3, respectively, but (in + round-nearest mode) with the tests of mode 0 to + possibly return a shorter string that rounds to d. + With IEEE arithmetic and compilation with + -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same + as modes 2 and 3 when FLT_ROUNDS != 1. + 6-9 ==> Debugging modes similar to mode - 4: don't try + fast floating-point estimate (if applicable). + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, + j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, + spec_case, try_quick; + Long L; +#ifndef Sudden_Underflow + int denorm; + ULong x; +#endif + Bigint *b, *b1, *delta, *mlo, *mhi, *S; + double d2, ds, eps; + char *s, *s0; +#ifdef Honor_FLT_ROUNDS + int rounding; +#endif +#ifdef SET_INEXACT + int inexact, oldinexact; +#endif + +#ifndef MULTIPLE_THREADS + if (dtoa_result) { + freedtoa(dtoa_result); + dtoa_result = 0; + } +#endif + + if (word0(d) & Sign_bit) { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0(d) &= ~Sign_bit; /* clear sign bit */ + } + else + *sign = 0; + +#if defined(IEEE_Arith) + defined(VAX) +#ifdef IEEE_Arith + if ((word0(d) & Exp_mask) == Exp_mask) +#else + if (word0(d) == 0x8000) +#endif + { + /* Infinity or NaN */ + *decpt = 9999; +#ifdef IEEE_Arith + if (!word1(d) && !(word0(d) & 0xfffff)) + return nrv_alloc("Infinity", rve, 8); +#endif + return nrv_alloc("NaN", rve, 3); + } +#endif +#ifdef IBM + dval(d) += 0; /* normalize */ +#endif + if (!dval(d)) { + *decpt = 1; + return nrv_alloc("0", rve, 1); + } + +#ifdef SET_INEXACT + try_quick = oldinexact = get_inexact(); + inexact = 1; +#endif +#ifdef Honor_FLT_ROUNDS + if ((rounding = Flt_Rounds) >= 2) { + if (*sign) + rounding = rounding == 2 ? 0 : 2; + else + if (rounding != 2) + rounding = 0; + } +#endif + + b = d2b(dval(d), &be, &bbits); +#ifdef Sudden_Underflow + i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); +#else + if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { +#endif + dval(d2) = dval(d); + word0(d2) &= Frac_mask1; + word0(d2) |= Exp_11; +#ifdef IBM + if (j = 11 - hi0bits(word0(d2) & Frac_mask)) + dval(d2) /= 1 << j; +#endif + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ + + i -= Bias; +#ifdef IBM + i <<= 2; + i += j; +#endif +#ifndef Sudden_Underflow + denorm = 0; + } + else { + /* d is denormalized */ + + i = bbits + be + (Bias + (P-1) - 1); + x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32) + : word1(d) << (32 - i); + dval(d2) = x; + word0(d2) -= 31*Exp_msk1; /* adjust exponent */ + i -= (Bias + (P-1) - 1) + 1; + denorm = 1; + } +#endif + ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + k = (int)ds; + if (ds < 0. && ds != k) + k--; /* want k = floor(ds) */ + k_check = 1; + if (k >= 0 && k <= Ten_pmax) { + if (dval(d) < tens[k]) + k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } + else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } + else { + b2 -= k; + b5 = -k; + s5 = 0; + } + if (mode < 0 || mode > 9) + mode = 0; + +#ifndef SET_INEXACT +#ifdef Check_FLT_ROUNDS + try_quick = Rounding == 1; +#else + try_quick = 1; +#endif +#endif /*SET_INEXACT*/ + + if (mode > 5) { + mode -= 4; + try_quick = 0; + } + leftright = 1; + switch(mode) { + case 0: + case 1: + ilim = ilim1 = -1; + i = 18; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + i = 1; + } + s = s0 = rv_alloc(i); + +#ifdef Honor_FLT_ROUNDS + if (mode > 1 && rounding != 1) + leftright = 0; +#endif + + if (ilim >= 0 && ilim <= Quick_max && try_quick) { + + /* Try to get by with floating-point arithmetic. */ + + i = 0; + dval(d2) = dval(d); + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) { + ds = tens[k&0xf]; + j = k >> 4; + if (j & Bletch) { + /* prevent overflows */ + j &= Bletch - 1; + dval(d) /= bigtens[n_bigtens-1]; + ieps++; + } + for(; j; j >>= 1, i++) + if (j & 1) { + ieps++; + ds *= bigtens[i]; + } + dval(d) /= ds; + } + else if (j1 = -k) { + dval(d) *= tens[j1 & 0xf]; + for(j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) { + ieps++; + dval(d) *= bigtens[i]; + } + } + if (k_check && dval(d) < 1. && ilim > 0) { + if (ilim1 <= 0) + goto fast_failed; + ilim = ilim1; + k--; + dval(d) *= 10.; + ieps++; + } + dval(eps) = ieps*dval(d) + 7.; + word0(eps) -= (P-1)*Exp_msk1; + if (ilim == 0) { + S = mhi = 0; + dval(d) -= 5.; + if (dval(d) > dval(eps)) + goto one_digit; + if (dval(d) < -dval(eps)) + goto no_digits; + goto fast_failed; + } +#ifndef No_leftright + if (leftright) { + /* Use Steele & White method of only + * generating digits needed. + */ + dval(eps) = 0.5/tens[ilim-1] - dval(eps); + for(i = 0;;) { + L = (Long)dval(d); + dval(d) -= L; + *s++ = '0' + (int)L; + if (dval(d) < dval(eps)) + goto ret1; + if (1. - dval(d) < dval(eps)) + goto bump_up; + if (++i >= ilim) + break; + dval(eps) *= 10.; + dval(d) *= 10.; + } + } + else { +#endif + /* Generate ilim digits, then fix them up. */ + dval(eps) *= tens[ilim-1]; + for(i = 1;; i++, dval(d) *= 10.) { + L = (Long)(dval(d)); + if (!(dval(d) -= L)) + ilim = i; + *s++ = '0' + (int)L; + if (i == ilim) { + if (dval(d) > 0.5 + dval(eps)) + goto bump_up; + else if (dval(d) < 0.5 - dval(eps)) { + while(*--s == '0'); + s++; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + dval(d) = dval(d2); + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) { + /* Yes. */ + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) { + S = mhi = 0; + if (ilim < 0 || dval(d) <= 5*ds) + goto no_digits; + goto one_digit; + } + for(i = 1;; i++, dval(d) *= 10.) { + L = (Long)(dval(d) / ds); + dval(d) -= L*ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (dval(d) < 0) { + L--; + dval(d) += ds; + } +#endif + *s++ = '0' + (int)L; + if (!dval(d)) { +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + if (i == ilim) { +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + switch(rounding) { + case 0: goto ret1; + case 2: goto bump_up; + } +#endif + dval(d) += dval(d); + if (dval(d) > ds || dval(d) == ds && L & 1) { + bump_up: + while(*--s == '9') + if (s == s0) { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + } + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) { + i = +#ifndef Sudden_Underflow + denorm ? be + (Bias + (P-1) - 1 + 1) : +#endif +#ifdef IBM + 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); +#else + 1 + P - bbits; +#endif + b2 += i; + s2 += i; + mhi = i2b(1); + } + if (m2 > 0 && s2 > 0) { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) { + if (leftright) { + if (m5 > 0) { + mhi = pow5mult(mhi, m5); + b1 = mult(mhi, b); + Bfree(b); + b = b1; + } + if (j = b5 - m5) + b = pow5mult(b, j); + } + else + b = pow5mult(b, b5); + } + S = i2b(1); + if (s5 > 0) + S = pow5mult(S, s5); + + /* Check for special case that d is a normalized power of 2. */ + + spec_case = 0; + if ((mode < 2 || leftright) +#ifdef Honor_FLT_ROUNDS + && rounding == 1 +#endif + ) { + if (!word1(d) && !(word0(d) & Bndry_mask) +#ifndef Sudden_Underflow + && word0(d) & (Exp_mask & ~Exp_msk1) +#endif + ) { + /* The special case */ + b2 += Log2P; + s2 += Log2P; + spec_case = 1; + } + } + + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to quorem, so it + * can do shifts and ors to compute the numerator for q. + */ +#ifdef Pack_32 + if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) + i = 32 - i; +#else + if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) + i = 16 - i; +#endif + if (i > 4) { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + if (b2 > 0) + b = lshift(b, b2); + if (s2 > 0) + S = lshift(S, s2); + if (k_check) { + if (cmp(b,S) < 0) { + k--; + b = multadd(b, 10, 0); /* we botched the k estimate */ + if (leftright) + mhi = multadd(mhi, 10, 0); + ilim = ilim1; + } + } + if (ilim <= 0 && (mode == 3 || mode == 5)) { + if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + k++; + goto ret; + } + if (leftright) { + if (m2 > 0) + mhi = lshift(mhi, m2); + + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ + + mlo = mhi; + if (spec_case) { + mhi = Balloc(mhi->k); + Bcopy(mhi, mlo); + mhi = lshift(mhi, Log2P); + } + + for(i = 1;;i++) { + dig = quorem(b,S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = cmp(b, mlo); + delta = diff(S, mhi); + j1 = delta->sign ? 1 : cmp(b, delta); + Bfree(delta); +#ifndef ROUND_BIASED + if (j1 == 0 && mode != 1 && !(word1(d) & 1) +#ifdef Honor_FLT_ROUNDS + && rounding >= 1 +#endif + ) { + if (dig == '9') + goto round_9_up; + if (j > 0) + dig++; +#ifdef SET_INEXACT + else if (!b->x[0] && b->wds <= 1) + inexact = 0; +#endif + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || j == 0 && mode != 1 +#ifndef ROUND_BIASED + && !(word1(d) & 1) +#endif + ) { + if (!b->x[0] && b->wds <= 1) { +#ifdef SET_INEXACT + inexact = 0; +#endif + goto accept_dig; + } +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + switch(rounding) { + case 0: goto accept_dig; + case 2: goto keep_dig; + } +#endif /*Honor_FLT_ROUNDS*/ + if (j1 > 0) { + b = lshift(b, 1); + j1 = cmp(b, S); + if ((j1 > 0 || j1 == 0 && dig & 1) + && dig++ == '9') + goto round_9_up; + } + accept_dig: + *s++ = dig; + goto ret; + } + if (j1 > 0) { +#ifdef Honor_FLT_ROUNDS + if (!rounding) + goto accept_dig; +#endif + if (dig == '9') { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + *s++ = dig + 1; + goto ret; + } +#ifdef Honor_FLT_ROUNDS + keep_dig: +#endif + *s++ = dig; + if (i == ilim) + break; + b = multadd(b, 10, 0); + if (mlo == mhi) + mlo = mhi = multadd(mhi, 10, 0); + else { + mlo = multadd(mlo, 10, 0); + mhi = multadd(mhi, 10, 0); + } + } + } + else + for(i = 1;; i++) { + *s++ = dig = quorem(b,S) + '0'; + if (!b->x[0] && b->wds <= 1) { +#ifdef SET_INEXACT + inexact = 0; +#endif + goto ret; + } + if (i >= ilim) + break; + b = multadd(b, 10, 0); + } + + /* Round off last digit */ + +#ifdef Honor_FLT_ROUNDS + switch(rounding) { + case 0: goto trimzeros; + case 2: goto roundoff; + } +#endif + b = lshift(b, 1); + j = cmp(b, S); + if (j > 0 || j == 0 && dig & 1) { + roundoff: + while(*--s == '9') + if (s == s0) { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else { +/* trimzeros: */ /* since it's unreferenced */ + while(*--s == '0'); + s++; + } + ret: + Bfree(S); + if (mhi) { + if (mlo && mlo != mhi) + Bfree(mlo); + Bfree(mhi); + } + ret1: +#ifdef SET_INEXACT + if (inexact) { + if (!oldinexact) { + word0(d) = Exp_1 + (70 << Exp_shift); + word1(d) = 0; + dval(d) += 1.; + } + } + else if (!oldinexact) + clear_inexact(); +#endif + Bfree(b); + /* *s = 0; */ /* don't NUL terminate */ + *decpt = k + 1; + if (rve) + *rve = s; + return s0; + } + +#ifdef Use_J_Memory +#undef diff +#undef mult +#undef P +#undef MALLOC +#include "j.h" + + static void * +d2a_Malloc +#ifdef KR_headers + (k) int k; +#else + (struct dtoa_info *di, int n) +#endif +{ + A z; + J jt=(J)di->jt; + + z=jtga(jt, LIT, n, 1, 0); + if(!z || jt->jerr) longjmp(di->_env, 1); + return AV(z); + } + + +#endif + +B jtecvtinit(J jt) {A x; struct dtoa_info *di; + if(jt->dtoa) R 1; + GA(x, LIT, sizeof(struct dtoa_info), 1, 0); + di=(struct dtoa_info*)AV(x); + di->_p5s=0; + di->_pmem_next=di->_private_mem; + memset(di->_private_mem, 0, sizeof(di->_private_mem)); + memset(di->_freelist, 0, sizeof(di->_freelist)); + di->jt=jt; + ra(x); jt->dtoa=di; + R 1; +} + +/* uses dtoa and behaves like ecvt (well, ecvt_r) */ +/* this writes exactly ndp bytes at dest */ +B jtecvt(J jt, D dw, I ndp, int *decpt, int *sign, C *dest) +{ + struct dtoa_info *di=(struct dtoa_info*)jt->dtoa; + C *y,*z=0; + + ASSERTSYS(ndp<=INT_MAX, "jtecvt: too long"); + di->ndp=(int)ndp; di->result=dest; + y=d2a_dtoa(di, dw, 2, (int)ndp, decpt, sign, &z); + RZ(y&&z); + memset(z, '0', ndp-(z-y)); + R 1; +} + +#ifdef __cplusplus +} +#endif
new file mode 100644 --- /dev/null +++ b/dtoa.h @@ -0,0 +1,27 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* Jsoftware Copyright applies only to changes made by Jsoftware */ +#include <setjmp.h> + +#if SYS & SYS_MACOSX +/* Use the non-signal restoring pair */ +#define setjmp _setjmp +#define longjmp _longjmp +#endif + +#ifndef HAVE_BIGINT +struct dtoa_info { + jmp_buf _env; +}; +#else +struct dtoa_info { + jmp_buf _env; + Bigint *_p5s; + double *_pmem_next; + double _private_mem[PRIVATE_mem]; + Bigint *_freelist[Kmax+1]; + void *jt; + int ndp; + char *result; +}; +#endif
new file mode 100644 --- /dev/null +++ b/f.c @@ -0,0 +1,444 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Format: ": Monad */ + +#include "j.h" + +#if SY_64 +#define WI 21L +#else +#define WI 12L +#endif + +#define WD (9L+NPP) +#define WZ (WD+WD) +#define FMTF(f,T) void f(J jt,C*s,T*v) +#define ENGAP(j,r,s,exp) \ + {B b;I k=1,p=j,*sr=s+r-2; DO(p?r-1:0, k*=*(sr-i); b=!(p%k); exp;); } + +static F1(jtthxqe); + +static FMTF(jtfmtI,I){I x=*v; + sprintf(s,FMTI,x); + if('-'==*s)*s=CSIGN; +} + +static FMTF(jtfmtD,D){B q;C buf[1+WD],c,*t;D x=*v;I k=0; + if(!memcmp(v,&inf, SZD)){strcpy(s,"_" ); R;} + if(!memcmp(v,&infm,SZD)){strcpy(s,"__"); R;} + if(_isnan(*v) ){strcpy(s,"_."); R;} + x=*v; x=x==*(D*)minus0?0.0:x; /* -0 to 0*/ + sprintf(buf,jt->pp,x); + c=*buf; if(q=c=='-')*s++=CSIGN; q=q||(c=='+'); + if('.'==buf[q])*s++='0'; + MC(s,buf+q,WD+1-q); + if(t=strchr(s,'e')){ + if('-'==*++t)*t++=CSIGN; + while(c=*(k+t),c=='0'||c=='+')k++; + if(k)while(*t=*(k+t))t++; +}} + +static FMTF(jtfmtZ,Z){fmtD(s,&v->re); if(v->im){I k=strlen(s); *(k+s)='j'; fmtD(1+k+s,&v->im);}} + +static void thcase(I t,I*wd,VF*fmt){ + switch(t){ + case CMPX: *wd=WZ; *fmt=jtfmtZ; break; + case FL: *wd=WD; *fmt=jtfmtD; break; + default: *wd=WI; *fmt=jtfmtI; +}} + +I jtthv(J jt,A w,I n,C*s){A t;B ov=0;C buf[WZ],*x,*y=s;I k,n4=n-4,p,wd,wn,wt;VF fmt; + RZ(w&&n); + wn=AN(w); wt=AT(w); x=CAV(w); thcase(wt,&wd,&fmt); + switch(wt){ + case XNUM: case RAT: + RZ(t=thxqe(w)); p=AN(t); if(ov=n<p)p=n4; MC(y,AV(t),p); y+=p; break; + case B01: + if(ov=n<2*wn)p=n4/2; else p=wn; DO(p, *y++=*x++?'1':'0'; *y++=' ';); break; + case INT: + {C*t;I i,*v,x; + v=AV(w); + for(i=0;i<wn;++i){ + t=buf; x=*v++; + sprintf(t,FMTI" ",x); + if('-'==*t)*t=CSIGN; + p=strlen(t); if(ov=n4<p+y-s)break; strcpy(y,t); y+=p; + }} + break; + default: + k=bp(wt); + if(n>=wn*wd)DO(wn, fmt(jt,y,x); y+=strlen(y); *y++=' '; x+=k;) + else DO(wn, fmt(jt,buf,x); p=strlen(buf); if(ov=n4<1+p+y-s)break; strcpy(y,buf); y+=p; *y++=' '; x+=k;); + } + if(ov){if(' '!=*(y-1))*y++=' '; memset(y,'.',3L); y+=3;} + else if(' '==*(y-1))--y; + *y=0; R y-s; +} + +static F1(jtthbit){A z;UC*x;C*y;I c,i,m,n,p,q,r,r1,*s; + n=AN(w); r=AR(w); s=AS(w); + c=r?s[r-1]:1; m=n/c; p=2*c-1; + GA(z,LIT,m*p,r+!r,s); *(AS(z)+AR(z)-1)=p; + x=UAV(w); y=CAV(z); + q=c/BB; r=c%BB; r1=c%BW?(BW-c%BW)/BB:0; + for(i=0;i<m;++i){ + DO(q-!r, memcpy(y,bitdisp+2*BB**x,2*BB ); ++x; y+=2*BB ;); + if(r) {memcpy(y,bitdisp+2*BB**x,2*r -1); ++x; y+=2*r -1;} + else {memcpy(y,bitdisp+2*BB**x,2*BB-1); ++x; y+=2*BB-1;} + x+=r1; + } + R z; +} + +static F1(jtthb){A z;B*x;C*y;I c,m,n,p,r,*s; + n=AN(w); r=AR(w); s=AS(w); + c=r?s[r-1]:1; m=n/c; p=2*c-1; + GA(z,LIT,m*p,r+!r,s); *(AS(z)+AR(z)-1)=p; + x=BAV(w); y=CAV(z); + DO(m, DO(c-1, *y++=*x++?'1':'0'; *y++=' ';); *y++=*x++?'1':'0';); + R z; +} + +static F1(jtthn){A d,t,z;C*tv,*x,*y,*zv;I c,*dv,k,m,n,p,r,*s,wd;VF fmt; + n=AN(w); r=AR(w); s=AS(w); + thcase(AT(w),&wd,&fmt); + GA(t,LIT,wd*(1+n),1,0); tv=CAV(t); + if(1>=r){p=thv(w,AN(t),tv); ASSERTSYS(p,"thn"); AN(t)=*AS(t)=p; z=t;} + else{ + c=s[r-1]; m=n/c; k=bp(AT(w)); + y=tv-wd; x=CAV(w)-k; + RZ(d=apv(c,1L,0L)); dv=AV(d); + DO(m, DO(c, fmt(jt,y+=wd,x+=k); p=strlen(y); dv[i]=MAX(dv[i],p););); + --dv[c-1]; p=0; DO(c, p+=++dv[i];); + GA(z,LIT,m*p,r+!r,s); *(AS(z)+AR(z)-1)=p; zv=CAV(z); memset(zv,' ',AN(z)); + y=tv; DO(m, DO(c, zv+=dv[i]; p=strlen(y); MC(zv-p-(c>1+i),y,p); y+=wd;);); + } + R z; +} + +static F1(jtthsb){A d,z;C*zv;I c,*dv,m,n,p,q,r,*s;SB*x,*y;SBU*u; + n=AN(w); r=AR(w); s=AS(w); x=y=SBAV(w); q=jt->sbun; + if(1>=r){ + c=n; + p=2*n-1; DO(c, p+=SBUV(*x++)->n;); + GA(z,LIT, p,1, 0); zv=CAV(z); memset(zv,' ',AN(z)); + DO(c, u=SBUV(*y++); *zv='`'; MC(1+zv,SBSV(u->i),u->n); zv+=2+u->n;); + }else{ + c=s[r-1]; m=n/c; RZ(d=apv(c,0L,0L)); dv=AV(d); + DO(m, DO(c, p =SBUV(*x++)->n; dv[i]=MAX(dv[i],p););); + p=-1; DO(c, p+=dv[i]+=2;); --dv[c-1]; + GA(z,LIT,m*p,r+!r,s); zv=CAV(z); memset(zv,' ',AN(z)); *(AS(z)+AR(z)-1)=p; + DO(m, DO(c, u=SBUV(*y++); *zv='`'; MC(1+zv,SBSV(u->i),u->n); zv+=dv[i];);); + } + R z; +} + +static F1(jtthx1){A z;B b;C*s,s1[2+XBASEN];I n,p,p1,*v; + n=AN(w); v=AV(w)+n-1; b=0>*v; + p=*v; if(p==XPINF)R cstr("_"); else if(p==XNINF)R cstr("__"); + sprintf(s1,FMTI,*v); p1=strlen(s1); + p=p1+XBASEN*(n-1); + GA(z,LIT,p,1,0); s=CAV(z); + MC(s,s1,p1); if(b)*s=CSIGN; s+=p1; + DO(n-1, --v; sprintf(s,FMTI04,b?-*v:*v); s+=XBASEN;); + R z; +} + +static A jtthq1(J jt,Q y){A c,d,z;B b;C*zv;I m,n=-1; + RZ(c=thx1(y.n)); m=AN(c); + d=y.d; + if(b=1<AN(d)||1!=*AV(d)){RZ(d=thx1(y.d)); n=AN(d);} + GA(z,LIT,m+n+1,1,0); zv=CAV(z); + MC(zv,AV(c),m); if(b){*(zv+m)='r'; MC(zv+m+1,AV(d),n);} + R z; +} + +static A jtthdx1(J jt,DX y){A x,z;B b;C*s,s1[2+XBASEN],s2[20];I e,n,p,p1,p2,*v; + e=y.e-1; x=y.x; p=y.p; + n=AN(x); v=AV(x)+n-1; b=0>*v; + if(p==DXINF)R cstr("_"); else if(p==DXMINF)R cstr("__"); + sprintf(s1,FMTI,b?-*v:*v); p1=strlen(s1); + if(e&&*v){s=s2; *s++='e'; if(0>e)*s++=CSIGN; sprintf(s,FMTI,0<e?e:-e); p2=strlen(s2);}else p2=0; + GA(z,LIT,b+p1+(1<p1)+XBASEN*(n-1)+p2,1,0); s=CAV(z); + if(b)*s++=CSIGN; *s++=*s1; if(1<p1){*s++='.'; MC(s,1+s1,p1-1); s+=p1-1;} + DO(n-1, --v; sprintf(s,FMTI04,b?-*v:*v); s+=XBASEN;); + MC(s,s2,p2); + R z; +} + +static F1(jtthxqe){A d,t,*tv,*v,y,z;C*zv;I c,*dv,m,n,p,r,*s,*wv; + n=AN(w); r=AR(w); s=AS(w); wv=AV(w); + c=r?s[r-1]:1; m=n/c; + GA(t,BOX,n,1,0); tv=AAV(t); + RZ(d=apv(c,1L,0L)); dv=AV(d); v=tv; + switch(AT(w)){ + case XNUM: {X*u =(X*) wv; DO(m, DO(c, RZ(*v++=y=thx1(*u++)); dv[i]=MAX(dv[i],AN(y));));} break; + case RAT: {Q*u =(Q*) wv; DO(m, DO(c, RZ(*v++=y=thq1(*u++)); dv[i]=MAX(dv[i],AN(y));));} break; +#ifdef UNDER_CE + default: + if (AT(w)==XD){DX*u=(DX*)wv; DO(m, DO(c, RZ(*v++=y=thdx1(*u++)); dv[i]=MAX(dv[i],AN(y));));} + else {ZX*u=(ZX*)wv; ASSERT(0,EVNONCE);} + break; +#else + case XD: {DX*u=(DX*)wv; DO(m, DO(c, RZ(*v++=y=thdx1(*u++)); dv[i]=MAX(dv[i],AN(y));));} break; + case XZ: {ZX*u=(ZX*)wv; ASSERT(0,EVNONCE);} break; +#endif + } + --dv[c-1]; + p=0; DO(c, p+=++dv[i];); + GA(z,LIT,m*p,r+!r,s); *(AS(z)+AR(z)-1)=p; zv=CAV(z); memset(zv,' ',AN(z)); + v=tv; DO(m, DO(c, zv+=dv[i]; y=*v++; p=AN(y); MC(zv-p-(c>1+i),AV(y),p);)); + R z; +} + + +static B jtrc(J jt,A w,A*px,A*py){A*v,x,y;I j,k,r,*s,xn,*xv,yn,*yv; + RZ(w); + r=AR(w); s=AS(w); v=AAV(w); + xn=1<r?s[r-2]:1; RZ(*px=x=apv(1+xn,0L,0L)); xv=AV(x); + yn= r?s[r-1]:1; RZ(*py=y=apv(1+yn,0L,0L)); yv=AV(y); + DO(AN(w), s=AS(*v++); j=i/yn%xn; k=i%yn; xv[j]=MAX(xv[j],s[0]); yv[k]=MAX(yv[k],s[1]);); + DO(xn, ASSERT(xv[i]<IMAX,EVLIMIT); ++xv[i];); + DO(yn, ASSERT(yv[i]<IMAX,EVLIMIT); ++yv[i];); + R 1; +} + +static void jtfram(J jt,I k,I n,I*x,C*v){C a,b=9==k,d,l,r; + l=jt->bx[k]; a=b?' ':jt->bx[10]; d=b?l:jt->bx[1+k]; r=b?l:jt->bx[2+k]; + *v++=l; DO(n, memset(v,a,x[i]-1); v+=x[i]-1; *v++=d;); *--v=r; +} + +static void jtfminit(J jt,I m,I ht,I wd,A x,A y,C*zv){C*u,*v;I p,xn,*xv,yn,*yv; + p=ht*wd; + xn=AN(x)-1; xv=AV(x); + yn=AN(y)-1; yv=AV(y); + fram(9L,yn,yv,zv); u=zv; DO(ht-2, MC(u+=wd,zv,wd);); + fram(3L,yn,yv,u=v=zv+wd**xv); DO(xn-1, MC(u+=wd*xv[1+i],v,wd);); + fram(0L,yn,yv,zv); + fram(6L,yn,yv,zv+p-wd); + u=zv; DO(m-1, MC(u+=p,zv,p);); +} /* Initialize with box-drawing characters */ + +static void jtfmfill(J jt,I p,I q,I wd,A w,A x,A y,C*zv){A e,*wv;C*u,*v; + I c,d,i,j,k,n,r,*s,xn,xp,*xv,yn,yp,*yv; + n=AN(w); wv=AAV(w); + xp=jt->pos[0]; yp=jt->pos[1]; + xn=AN(x)-1; xv=AV(x); j=1; DO(1+xn, k=xv[i]; xv[i]=j; j+=k;); + yn=AN(y)-1; yv=AV(y); j=1; DO(1+yn, k=yv[i]; yv[i]=j; j+=k;); + for(i=0;i<n;++i){ + j=i/yn%xn; k=i%yn; d=i/q*p+wd*xv[j]+yv[k]; + e=wv[i]; s=AS(e); r=s[0]; c=s[1]; + if(xp)d+=(xv[1+j]-xv[j]-1-r)/(3-xp)*wd; + if(yp)d+=(yv[1+k]-yv[k]-1-c)/(3-yp); + u=zv+d-wd; v=CAV(e)-c; DO(r, MC(u+=wd,v+=c,c);); +}} /* fill each cell */ + +static F1(jtenframe){A x,y,z;C*zv;I ht,m,n,p,q,wd,wr,xn,*xv,yn,*yv,zn; + RE(rc(w,&x,&y)); + n=AN(w); wr=MAX(2,AR(w)); + xn=AN(x)-1; xv=AV(x); ht=1; DO(xn, ht+=xv[i]; ASSERT(0<ht,EVLIMIT);); + yn=AN(y)-1; yv=AV(y); wd=1; DO(yn, wd+=yv[i]; ASSERT(0<wd,EVLIMIT);); + RE(p=mult(ht,wd)); q=MAX(1,xn*yn); m=n/q; RE(zn=mult(m,p)); + GA(z,LIT,zn,wr,AS(w)); *(AS(z)+wr-2)=ht; *(AS(z)+wr-1)=wd; + if(!n)R z; + zv=CAV(z); + fminit(m,ht,wd,x,y,zv); + fmfill(p,q,wd,w,x,y,zv); + R z; +} + +F1(jtmat){A z;B b=0;C*v,*x;I c,k,m=1,p,q,qc,r,*s,zn; + RZ(w); + r=AR(w); s=AS(w); v=CAV(w); + q=1<r?s[r-2]:1; c=r?s[r-1]:1; + DO(r-2, if(!s[i]){b=1; break;}); + if(b)k=m=0; else{k=2<r?2-r:0; DO(r-2, p=m; m*=s[i]; ASSERT(m>=p,EVLIMIT); k+=m;);} + RE(p=mult(m,q)+k*!!q); ASSERT(0<=p,EVLIMIT); RE(zn=mult(p,c)); + GA(z,LIT,zn,2,0); *AS(z)=p; *(1+AS(z))=c; x=CAV(z); + if(2<r)fillv(LIT,zn,x); + if(zn){RE(qc=mult(q,c)); DO(m, ENGAP(i*q,r,s,x+=c*b); MC(x,v,qc); x+=qc; v+=qc;);} + R z; +} + +static F1(jtmatth1){R mat(thorn1(w));} + +static F1(jtthbox){A z;UC*s;static C ctrl[]=" \001\002\003\004\005\006\007 \013\014 "; + RZ(z=enframe(every(w,0L,jtmatth1))); + s=UAV(z); + DO(AN(z), if(14>s[i])s[i]=ctrl[s[i]];); + R z; +} + +static F1(jtths){A e,i,x,z;C c,*u,*v;I d,m,n,*s;P*p; + RZ(scheck(w)); + p=PAV(w); e=SPA(p,e); i=SPA(p,i); x=SPA(p,x); + RZ(i=thorn1(i)); s=AS(i); m=s[0]; n=s[1]; + RZ(x=thorn1(1<AR(x)?x:table(x))); + RZ(e=shape(x)); s=AV(e)+AN(e)-1; *s=-(*s+3+n); + RZ(z=take(e,x)); + u=CAV(i)-n; + d=aii(z); v=CAV(z)-d; DO(m, MC(v+=d,u+=n,n);); + if(2<AR(z))RZ(z=matth1(z)); + s=AS(z); d=*(1+s); v=1+CAV(z); c=jt->bx[9]; DO(*s, *(v+n)=c; v+=d;); + R z; +} + +F1(jtthorn1){PROLOG;A z; + RZ(w); + if(!AN(w))GA(z,LIT,0,AR(w),AS(w)) + else switch(AT(w)){ +#ifdef UNDER_CE + default: if(AT(w)&XD+XZ)z=thxqe(w); else R 0; break; + case XNUM: case RAT: + z=thxqe(w); break; +#else + default: R 0; + case XNUM: case RAT: case XD: case XZ: + z=thxqe(w); break; +#endif + case BIT: z=thbit(w); break; + case B01: z=thb(w); break; + case LIT: z=ca(w); break; + case C2T: z=rank1ex(w,0L,1L,jttoutf8); break; + case BOX: z=thbox(w); break; + case SBT: z=thsb(w); break; + case NAME: z=sfn(0,w); break; + case ASGN: z=spellout(*CAV(w)); break; + case INT: case FL: case CMPX: + z=thn(w); break; + case SB01: case SINT: case SFL: case SCMPX: case SLIT: case SBOX: + z=ths(w); break; + case VERB: case ADV: case CONJ: + switch((jt->disp)[1]){ + case 1: z=thorn1(arep(w)); break; + case 2: z=thorn1(drep(w)); break; + case 4: z=thorn1(trep(w)); break; + case 5: z=thorn1(lrep(w)); break; + case 6: z=thorn1(prep(w)); break; + }} + EPILOG(z); +} + +#define DDD(v) {*v++='.'; *v++='.'; *v++='.';} +#define EOL(zv) {zv[0]=eov[0]; zv[1]=eov[1]; zv+=m; ++lc;} +#define BDC(x) if(16<=x&&x<=26){*(zv-1)='\342'; *zv++='\224'; *zv++=bdc[x];} + +static I scanbdc(C*v,I h,I nq,I c,I lb,I la){C*u,x;I m; + u=v; x=0; m=0; + if(h>=nq) + DO(c*nq, x=*u++; if(16<=x&&x<=26)m+=3;) + else{ + DO(c*lb, x=*u++; if(16<=x&&x<=26)m+=3;); + u=v+c*(nq-la); + DO(c*la, x=*u++; if(16<=x&&x<=26)m+=3;); + } + R m; +} /* scan for box drawing chars requiring additional space */ + +static I scaneol(C*v,I h,I nq,I c,I lb,I la){C e,*u,x;I m; + u=v; x=0; m=0; + if(h>=nq) + DO(c*nq, e=x; x=*u++; if(x==CCR)++m; else if(x==CLF)e==CCR?--m:++m;) + else{ + DO(c*lb, e=x; x=*u++; if(x==CCR)++m; else if(x==CLF)e==CCR?--m:++m;); + u=v+c*(nq-la); + DO(c*la, e=x; x=*u++; if(x==CCR)++m; else if(x==CLF)e==CCR?--m:++m;); + } + R m; +} /* scan for EOL requiring additional space */ + +/* zn: max length of zu,zv */ +/* zu: points to start of data area */ +/* zv: points to 1 + end of data area */ +/* lb: # lines before ... */ +/* la: # lines after ... */ +/* m: # chars in end-of-line */ +/* eo: eol if 1 char */ +/* eol: eol if 2 chars */ + +static C*dropl(I zn,C*zu,C*zv,I lb,I la,I m,C eo,C*eov){C*u,*v;I lc=0,n,p,q; + p=q=0; u=zu; v=zv; + if(1==m){ + DO(zn, if(p>=lb)break; if(eo ==*u++ )p++;); + DO(zn, if(q> la)break; if(eo ==*--v )q++;); + }else{ + DO(zn, if(p>=lb)break; if(*(S*)eov==*(S*)(u++))p++;); + DO(zn, if(q> la)break; if(*(S*)eov==*(S*)(--v))q++;); + } + DDD(u); EOL(u); n=zv-(m+v); memmove(u,m+v,n); + R u+n; +} /* drop excessive lines */ + +static A jtjprx(J jt,I ieol,I maxlen,I lb,I la,A w){A y,z;B ch;C e,eo,*eov,*v,x,*zu,*zv;D lba; + I c,c1,h,i,j,k,lc,m,n,nbx,nq,p,q,r,*s,zn;S eol; + static C bdc[]="123456789_123456\214\254\220\234\274\244\224\264\230\202\200"; + RZ(y=thorn1(w)); + ch=1&&AT(w)&LIT+C2T+SBT; + r=AR(y); s=AS(y); v=CAV(y); eov=(C*)&eol; + q=1<r?s[r-2]:1; c=r?s[r-1]:1; RE(n=prod(r-2,s)); RE(nq=mult(n,q)); + if(ieol){m=2; *eov=CCR; *(1+eov)=CLF;}else{m=1; *eov=eo=CLF;} + c1=MIN(c,maxlen); lba=(D)lb+la; + p=2<r?2-r:0; h=1; DO(r-2, if(s[i]){h*=s[i]; p+=h;}else{p=0; break;}); + h=lba<IMAX?lb+la:IMAX; h=MIN(nq,h); + RE(zn=(3+m)+(q?p*m:0)+mult(h,ch?c+m+(3+m)*(1+c/maxlen):c1+m+3*(c1<c))); + if(ch&&1<m )zn+= scaneol(v,h,nq,c,lb,la); + if(ch||AT(w)&BOX+SPARSE)zn+=nbx=scanbdc(v,h,nq,c,lb,la); + GA(z,LIT,zn,1,0); zu=zv=CAV(z); + h=lba<nq+(q?p:0)?lb:IMAX; + for(i=lc=0;i<nq;++i){ + if(0==i%q)ENGAP(i,r,s,if(b)EOL(zv)); + if(h<=lc&&nq>la){h=IMAX; p=nq-la; v+=c*(p-i); i=p-1; DDD(zv);} + else if(ch)for(j=k=x=0;j<c;++j){ + e=x; x=*v++; + if (x==CCR){ EOL(zv); k=0;} + else if(x==CLF){if(e!=CCR)EOL(zv); k=0;} + else if(x) {if(k<c1){*zv++=x; BDC(x);} else if(k==c1)DDD(zv); ++k;} + }else if(nbx){DO(c1, *zv++=x=*v++; BDC(x);); if(c1<c){v+=c-c1; DDD(zv);}} + else {MC(zv,v,c1); zv+=c1; v+=c1; if(c1<c){v+=c-c1; DDD(zv);}} + EOL(zv); + } + if(lc>1+lba)zv=dropl(zn,zu,zv,lb,la,m,eo,eov); + p=zv-zu; + ASSERTSYS(p<=zn,"jprx zn"); + *zv=0; z->n=*(z->s)=p; + R z; +} /* output string from array w */ + +F2(jtoutstr){I*v; + RZ(a&&w); + RZ(a=vib(a)); + ASSERT(1==AR(a), EVRANK); + ASSERT(4==AN(a), EVLENGTH); + ASSERT(INT&AT(a),EVDOMAIN); + v=AV(a); + ASSERT(0<=v[0]&&v[0]<=2,EVINDEX); + ASSERT(0<=v[1],EVDOMAIN); + ASSERT(0<=v[2],EVDOMAIN); + ASSERT(0<=v[3],EVDOMAIN); + R jprx(v[0],v[1],v[2],v[3],w); +} + +static F1(jtjpr1){PROLOG;A z; + RZ(z=jprx(jt->outeol,jt->outmaxlen,jt->outmaxbefore,jt->outmaxafter,w)); + if(AN(z))jsto(jt,jt->mtyo==0?MTYOFM:jt->mtyo,CAV(z)); + EPILOG(mtm); +} + +F1(jtjpr){A y;I i,n,t,*v; + RZ(w); + t=AT(w); + if(t&NOUN&&jt->tostdout)RZ(jpr1(w)) + else if(t&VERB+ADV+CONJ){ + RZ(y=evoke(w)?symbrdlock(VAV(w)->f):w); + if(jt->tostdout){ + n=*jt->disp; v=1+jt->disp; + for(i=0;i<n;++i)switch(*v++){ + case 1: RZ(jpr1(arep(y))); break; + case 2: RZ(jpr1(drep(y))); break; + case 4: RZ(jpr1(trep(y))); break; + case 5: RZ(jpr1(lrep(y))); break; + case 6: RZ(jpr1(prep(y))); break; + }}} + R mtm; +}
new file mode 100644 --- /dev/null +++ b/f2.c @@ -0,0 +1,189 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Format: ": Dyad */ + +#include "j.h" + + +static F2(jtth2box){A z;I n,p,q,*v,x,y; + p=jt->pos[0]; q=jt->pos[1]; + RZ(a=vi(a)); n=AN(a); v=AV(a); + ASSERT(1>=AR(a),EVRANK); + ASSERT(1==n||2==n,EVLENGTH); + x=v[0]; y=2>n?0:v[1]; + ASSERT(0<=x&&x<=2&&0<=y&&y<=2,EVDOMAIN); + jt->pos[0]=x; jt->pos[1]=y; + z=thorn1(w); + jt->pos[0]=p; jt->pos[1]=q; + R z; +} + +static I jtc2j(J jt,B e,I m,C*zv){C c,*s,*t;I k,p; + if(e&&(t=strchr(jt->th2buf,'e'))){ + ++t; t+='-'==*t; + k=0; while(c=*(k+t),c=='0'||c=='+')++k; + if(k){ + if(!c||' '==c){*t++='0'; --k;} + while(*t=*(k+t))++t; + p=m-(t-jt->th2buf); DO(p,*t++=' ';); if(0<=p)jt->th2buf[m]=0; + }} + t=jt->th2buf; k=strlen(t); + if(!e&&(s=memchr(t,'-',k))){ /* turn -0 to 0 */ + *s=' '; + DO(k-(1+s-t), c=s[1+i]; if(c!='0'&&c!='.'){*s=CSIGN; break;}); + if(!m&&' '==*s){++t; --k;} + } + if(m&&m<k)memset(zv,'*',m); + else{ + if(k<m){memset(zv+e*k,' ',m-k); if(!e)zv+=m-k;} + DO(k, c=t[i]; *zv++='-'==c?CSIGN:c;); + } + R k; +} /* c format to j format */ + +static B jtfmtex(J jt,I m,I d,I n,I*xv,B b,I c,I q,I ex){B bm=b||m;C*u,*v=jt->th2buf;I k; + if(jt->th2bufn<20+d){A s; jt->th2bufn=20+d; GA(s,LIT,jt->th2bufn,1,0); v=jt->th2buf=CAV(s);} + if(b)*v++='_'; else if(m)*v++=' '; *v++=' '; sprintf(v,FMTI,c); v+=q; + k=(XBASEN+d+1-q)/XBASEN; k=MIN(n-1,k); + DO(k, c=*--xv; sprintf(v,FMTI04,b?-c:c); v+=XBASEN;); + k=v-jt->th2buf-(2+bm); + if(k<d){memset(v,'0',d-k); v+=d-k;} + else if(k>d&&(u=v=jt->th2buf+d+2+bm,'5'<=*v)){ + while('9'==*--u); + if(' '!=*u)++*u; else{*++u='1'; ++ex;} + memset(u+1,'0',v-u-1); + } + jt->th2buf[bm]=jt->th2buf[bm+1]; jt->th2buf[bm+1]='.'; sprintf(v-!d,"e"FMTI"",ex); + R 1; +} /* format one extended integer in exponential form */ + +static B jtfmtx(J jt,B e,I m,I d,C*s,I t,X*wv){B b;C*v=jt->th2buf;I c,n,p,q,*xv;X x; + x=*wv; n=AN(x); xv=AV(x)+n-1; + c=*xv; b=0>c; if(b)c=-c; + if(c==XPINF){if(b)*v++='_'; *v++='_'; *v=0; R 1;} + q=c>999?4:c>99?3:c>9?2:1; p=q+XBASEN*(n-1); + if(e)R fmtex(m,d,n,xv,b,c,q,p-1); + else if(m&&m<b+p+d+!!d){memset(v,'*',m); v[m]=0;} + else{ + if(jt->th2bufn<4+p+d){A s; jt->th2bufn=4+p+d; GA(s,LIT,jt->th2bufn,1,0); v=jt->th2buf=CAV(s);} + if(' '==*s)*v++=' '; if(b)*v++='_'; + sprintf(v,FMTI,c); v+=q; + DO(n-1, c=*--xv; sprintf(v,FMTI04,b?-c:c); v+=XBASEN;); + if(d){*v++='.'; memset(v,'0',d); v[d]=0;} + } + R 1; +} /* format one extended integer */ + +static B jtfmtq(J jt,B e,I m,I d,C*s,I t,Q*wv){B b;C*v=jt->th2buf;I c,ex=0,k,n,p,q,*xv;Q y;X a,g,x; + y=*wv; x=y.n; c=XDIG(x); b=0>c; if(b)x=negate(x); + if(c==XPINF||c==XNINF){if(e)*v++=' '; if(e>b)*v++=' '; if(b)*v++='_'; *v++='_'; *v=0; R 1;} + RZ(a=xpow(xc(10L),xc(1+d))); + if(e&&c&&0>xcompare(x,y.d)){ + ex=XBASEN*(AN(y.n)-AN(y.d)); + g=xtymes(x,xpow(xc(10L),xc(1+d-ex))); + RZ(x=xdiv(g,y.d,XMFLR)); + while(1==xcompare(a,x)){--ex; g=xtymes(xc(10L),g); RZ(x=xdiv(g,y.d,XMFLR));} + if(b)x=negate(x); + }else x=xdiv(xtymes(y.n,a),y.d,XMFLR); + RZ(x=xdiv(xplus(x,xc(5L)),xc(10L),XMFLR)); + n=AN(x); xv=AV(x)+n-1; c=*xv; b=0>c; if(b)c=-c; + q=c>999?4:c>99?3:c>9?2:1; p=q+XBASEN*(n-1); if(c||!e)ex+=p-d-1; + if(e)R fmtex(m,d,n,xv,b,c,q,ex); + else if(m&&m<b+d+!!d+(0>ex?1:1+ex)){memset(v,'*',m); v[m]=0;} + else{ + if(jt->th2bufn<4+p+d){A s; jt->th2bufn=4+p+d; GA(s,LIT,jt->th2bufn,1,0); v=jt->th2buf=CAV(s);} + if(' '==*s)*v++=' '; if(b)*v++='_'; + if(0>ex){k=-ex-1; DO(1+MIN(d,k), *v++='0';);} + sprintf(v,FMTI,c); v+=q; + DO(n-1, c=*--xv; sprintf(v,FMTI04,b?-c:c); v+=XBASEN;); + if(d){v[1]=0; DO(d, *v=*(v-1); --v;); *v='.';} + } + R 1; +} /* format one rational number */ + +static void jtfmt1(J jt,B e,I m,I d,C*s,I t,C*wv){D y; + switch(t){ + case B01: sprintf(jt->th2buf,s,(D)*wv); break; + case INT: sprintf(jt->th2buf,s,(D)*(I*)wv); break; + case XNUM: fmtx(e,m,d,s,t,(X*)wv); break; + case RAT: fmtq(e,m,d,s,t,(Q*)wv); break; + default: + y=*(D*)wv; y=y?y:0.0; /* -0 to 0 */ + if (!memcmp(wv,&inf, SZD))strcpy(jt->th2buf,e?" _" :' '==*s?" _" :"_" ); + else if(!memcmp(wv,&infm,SZD))strcpy(jt->th2buf,e?" __" :' '==*s?" __":"__"); + else if(_isnan(*wv) )strcpy(jt->th2buf,e?" _.":' '==*s?" _.":"_."); + else sprintf(jt->th2buf,s,y); +}} /* format one number */ + +static void jtth2c(J jt,B e,I m,I d,C*s,I n,I t,I wk,C*wv,I zk,C*zv){ + DO(n, fmt1(e,m,d,s,t,wv); c2j(e,m,zv); zv+=zk; wv+=wk;); +} /* format a column */ + +static A jtth2a(J jt,B e,I m,I d,C*s,I n,I t,I wk,C*wv,B first){PROLOG;A y,z;B b=0;C*u,*yv,*zv;I i,m0=m,k,p,q; + q=m?m:t&B01?3:t&INT?12:17; p=n*q; + GA(z,LIT,p,2,0); *AS(z)=n; *(1+AS(z))=q; zv=CAV(z); + if(m){th2c(e,m,d,s,n,t,wk,wv,m,zv); R z;} + for(i=q=0;i<n;++i){ + fmt1(e,m0,d,s,t,wv); + while(p<q+(I)strlen(jt->th2buf)+1){RZ(z=over(z,z)); p+=p; zv=CAV(z);} + u=q+zv; q+=k=c2j(e,0L,u); b=b||CSIGN==*u; zv[q++]=0; m=MAX(m,k); wv+=wk; + } + m+=!first; + GA(y,LIT,n*m,2,0); *AS(y)=n; *(1+AS(y))=m; + yv=CAV(y); memset(yv,' ',AN(y)); u=zv; + if(e){yv+=!first; DO(n, q=strlen(u); MC(yv+(b&&CSIGN!=*u),u,q); yv+=m; u+=1+q;);} + else {yv+=m; DO(n, q=strlen(u); MC(yv-q, u,q); yv+=m; u+=1+q;);} + EPILOG(y); +} /* like th2c, but allocates and returns array */ + +static B jtth2ctrl(J jt,A a,A*ep,A*mp,A*dp,A*sp,I*zkp){A da,ea,ma,s;B b=1,*ev,r; + C*sv;D x,y;I an,*av,d,*dv,i,m,*mv,sk=15,zk=0;Z*au; + r=!(CMPX&AT(a)); jt->th2bufn=500; + if(r)RZ(a=cvt(INT,a)); + an=AN(a); au=ZAV(a); av=AV(a); + GA(ea,B01,an, 1,0); *ep=ea; ev=BAV(ea); + GA(ma,INT,an, 1,0); *mp=ma; mv= AV(ma); + GA(da,INT,an, 1,0); *dp=da; dv= AV(da); + GA(s, LIT,an*sk,2,0); *sp=s; sv=CAV(s); *AS(s)=an; *(1+AS(s))=sk; + for(i=0;i<an;++i){ + if(r){m=av[i]; x=(D)m; d=0;} + else{ + x=au[i].re; m=(I)tfloor(x); ASSERT(teq(x,(D)m),EVDOMAIN); + y=au[i].im; d=(I)tfloor(y); ASSERT(teq(y,(D)d),EVDOMAIN); if(0>y)x=-1; + } + if(0>m)m=-m; if(0>d)d=-d; ASSERT(0<=m&&0<=d,EVLIMIT); + if(0<=x)sprintf(sv, "%%"FMTI"."FMTI"f", m,d); + else sprintf(sv, m?"%%- "FMTI"."FMTI"e" :"%%-"FMTI"."FMTI"e", m?m-1:0,d+!!(SYS&SYS_PC)); + sv+=sk; ev[i]=0>x; mv[i]=m; dv[i]=d; zk+=m; b=b&&m; + if(jt->th2bufn<m)jt->th2bufn=m; if(jt->th2bufn<500+d)jt->th2bufn=500+d; + } + GA(s,LIT,jt->th2bufn,1,0); jt->th2buf=CAV(s); + *zkp=b?zk:0; R 1; +} /* parse format control (left argument of ":) */ + +F2(jtthorn2){PROLOG;A da,ea,h,ma,s,y,*yv,z;B e,*ev;C*sv,*wv,*zv;I an,c,d,*dv,k,m,*mv,n,r,sk,t,wk,*ws,zk; + F2RANK(1,RMAX,jtthorn2,0); + an=AN(a); t=AT(w); + if(t&BOX)R th2box(a,w); + ASSERT(t&NUMERIC&&!(t&SPARSE)&&!(AT(a)&SPARSE),EVDOMAIN); + r=AR(w); ws=AS(w); c=r?ws[r-1]:1; n=c?AN(w)/c:prod(r-1,ws); + ASSERT(!AR(a)||c==an,EVLENGTH); + k=bp(t); wk=c*k; wv=CAV(w)-k; + RZ(th2ctrl(a,&ea,&ma,&da,&s,&zk)); + ev=BAV(ea); mv=AV(ma); dv=AV(da); sk=1<an?*(1+AS(s)):0; sv=CAV(s)-sk; + if(zk||!AN(w)){ + if(1==an)zk*=c; + GA(z,LIT,n*zk,r?r:1,ws); *(AS(z)+AR(z)-1)=zk; zv=CAV(z); + DO(c, if(i<an){e=ev[i]; m=mv[i]; d=dv[i];} th2c(e,m,d,sv+=sk,n,t,wk,wv+=k,zk,zv); zv+=m;); + }else{ + GA(y,BOX,c,1,0); yv=AAV(y); + DO(c, if(i<an){e=ev[i]; m=mv[i]; d=dv[i];} RZ(yv[i]=th2a(e,m,d,sv+=sk,n,t,wk,wv+=k,(B)!i));); + RZ(z=razeh(y)); + if(2<r||1==n&&2!=r){ + if(!r)r=1; + RZ(h=vec(INT,r,ws)); *(AV(h)+r-1)=*(1+AS(z)); + RZ(z=reshape(h,z)); + }} + EPILOG(z); +}
new file mode 100644 --- /dev/null +++ b/i.c @@ -0,0 +1,169 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Initializations */ + +#include "j.h" +#include "w.h" + +#if SYS & SYS_FREEBSD +#include <floatingpoint.h> +#endif + +J gjt=0; // JPF debug + +void startup(void); + +static A jtmakename(J jt,C*s){A z;I m;NM*zv; + m=strlen(s); + GA(z,NAME,m,1,0); zv=NAV(z); + memcpy(zv->s,s,m); *(m+zv->s)=0; + zv->m =(UC)m; + zv->sn =0; + zv->e =0; + zv->flag=NMDOT; + zv->hash=NMHASH(m,s); + ACX(z); + R z; +} + +B jtglobinit(J jt){A x,y;C*s;D*d;I j;UC c,k; + liln=1&&SYS&SYS_LILENDIAN; + jt->adbreak=&breakdata; /* required for ma to work */ + meminit(); /* required for ma to work */ + jt->parsercalls=0; + s=bitdisp; + DO(256, c=(UC)i; DO(BB, *s++=c&(UC)128?'1':'0'; *s++=' '; c<<=1;); ); + DO(16, c=(UC)i; k=0; DO(BB, if(c&(UC)1)++k; c>>=1;); bitc[i]=k;); + DO(15, j=1+i; DO(16, bitc[16*j+i]=bitc[j]+bitc[i];);); + MC(&inf, XINF,SZD); + MC(&jnan,XNAN,SZD); + infm=-inf; + memset(testb,C0,256); + testb[CIF]=testb[CELSEIF]=testb[CSELECT]=testb[CWHILE]=testb[CWHILST]=testb[CFOR]=testb[CCASE]=testb[CFCASE]=1; + num=9+numv; + DO(9, GA(x,INT,1,0,0); ACX(x); * AV(x)=i-9; num[i-9] =x;); + DO(8, GA(x,INT,1,0,0); ACX(x); * AV(x)=i+2; num[i+2] =x;); + GA(x,B01, 1,0,0 ); ACX(x); *BAV(x)=0; num[0]=zero=x; + GA(x,B01, 1,0,0 ); ACX(x); *BAV(x)=1; num[1]=one =x; + memset(chr,C0,256*SZI); + GA(x,LIT, 1,0,0 ); ACX(x); *CAV(x)=' '; chr[' ' ]=x; + GA(x,LIT, 1,0,0 ); ACX(x); *CAV(x)=':'; chr[':' ]=x; + GA(x,LIT, 1,0,0 ); ACX(x); *CAV(x)='/'; chr['/' ]=x; + GA(x,LIT, 1,0,0 ); ACX(x); *CAV(x)='\\'; chr['\\' ]=x; + GA(x,LIT, 1,0,0 ); ACX(x); *CAV(x)=CQUOTE; chr[CQUOTE]=x; + GA(x,B01, 0,1,0 ); ACX(x); mtv =x; + GA(x,LIT, 0,1,0 ); ACX(x); aqq =x; + GA(x,INT, 1,1,0 ); ACX(x); * AV(x)=0; iv0=xzero =x; + GA(x,INT, 1,1,0 ); ACX(x); * AV(x)=1; iv1=xone =x; + GA(x,FL, 1,0,0 ); ACX(x); *DAV(x)=inf; ainf =x; + GA(x,FL, 1,0,0 ); ACX(x); *DAV(x)=PI; pie =x; + GA(x,MARK,1,0,0 ); ACX(x); * AV(x)=0; mark =x; + GA(x,B01, 0,2,&zeroZ); ACX(x); mtm =x; + GA(x,CMPX,1,0,0 ); ACX(x); d=DAV(x); *d=0; *(1+d)=1; a0j1 =x; + RZ(y=str(1L,"z")); ACX(y); + GA(x,BOX, 1,1,0 ); ACX(x); *AAV(x)=y; zpath =x; + RZ(mnam=makename("m")); RZ(mdot=makename("m.")); + RZ(nnam=makename("n")); RZ(ndot=makename("n.")); + RZ(unam=makename("u")); RZ(udot=makename("u.")); + RZ(vnam=makename("v")); RZ(vdot=makename("v.")); + RZ(xnam=makename("x")); RZ(xdot=makename("x.")); + RZ(ynam=makename("y")); RZ(ydot=makename("y.")); + zeroQ.n =xzero; zeroQ.d =xone; + zeroDX.e=0; zeroDX.x=xzero; + memset(minus0,C0,8L); minus0[SYS&SYS_LILENDIAN?7:0]='\200'; + pf=qpf(); + pinit(); + R 1; +} /* called once when dll is loaded to create global constants */ + +static B jtevinit(J jt){A q,*v; + GA(q,BOX,1+NEVM,1,0); v=AAV(q); + DO(AN(q), v[i]=mtv;); + v[EVALLOC ]=cstr("allocation error" ); + v[EVASSERT ]=cstr("assertion failure" ); + v[EVATTN ]=cstr("attention interrupt" ); + v[EVBREAK ]=cstr("break" ); + v[EVCTRL ]=cstr("control error" ); + v[EVDOMAIN ]=cstr("domain error" ); + v[EVFACCESS]=cstr("file access error" ); + v[EVFNAME ]=cstr("file name error" ); + v[EVFNUM ]=cstr("file number error" ); + v[EVILNAME ]=cstr("ill-formed name" ); + v[EVILNUM ]=cstr("ill-formed number" ); + v[EVINDEX ]=cstr("index error" ); + v[EVINPRUPT]=cstr("input interrupt" ); + v[EVFACE ]=cstr("interface error" ); + v[EVLENGTH ]=cstr("length error" ); + v[EVLIMIT ]=cstr("limit error" ); + v[EVLOCALE ]=cstr("locale error" ); + v[EVNAN ]=cstr("NaN error" ); + v[EVNONCE ]=cstr("nonce error" ); + v[EVSPARSE ]=cstr("non-unique sparse elements" ); + v[EVOPENQ ]=cstr("open quote" ); + v[EVWSFULL ]=cstr("out of memory" ); + v[EVRANK ]=cstr("rank error" ); + v[EVRO ]=cstr("read-only data" ); + v[EVSECURE ]=cstr("security violation" ); + v[EVSPELL ]=cstr("spelling error" ); + v[EVSTACK ]=cstr("stack error" ); + v[EVSTOP ]=cstr("stop" ); + v[EVSYNTAX ]=cstr("syntax error" ); + v[EVSYSTEM ]=cstr("system error" ); + v[EVTIME ]=cstr("time limit" ); + v[EVVALUE ]=cstr("value error" ); + ra(q); jt->evm=q; + if(jt->jerr){printf("evinit failed; error %hhi\n", jt->jerr); R 0;} else R 1; +} + +/* static void sigflpe(int k){jsignal(EVDOMAIN); signal(SIGFPE,sigflpe);} */ + +static B jtconsinit(J jt){D y; + jt->assert=1; + RZ(jt->bxa=cstr("+++++++++|-")); jt->bx=CAV(jt->bxa); + y=1.0; DO(44, y*=0.5;); jt->ct=jt->fuzz=y; + jt->disp[0]=1; jt->disp[1]=5; + jt->fcalln=NFCALL; + jt->fdepn=NFDEP; + jt->outmaxafter=222; + jt->outmaxlen=256; + strcpy(jt->outseq,"\x0a"); + strcpy(jt->pp,"%0.6g"); + jt->retcomm=1; + jt->tostdout=1; + jt->transposeflag=1; + jt->xmode=XMEXACT; + R 1; +} + +static C jtjinit3(J jt){S t; +/* required for jdll and doesn't hurt others */ + gjt=jt; // global jt for JPF debug +#if (SYS & SYS_DOS) + t=EM_ZERODIVIDE+EM_INVALID; _controlfp(t,t); +#endif +#if (SYS & SYS_OS2) + t=EM_ZERODIVIDE+EM_INVALID+EM_OVERFLOW+EM_UNDERFLOW; _control87(t,t); +#endif +#if (SYS & SYS_FREEBSD) + fpsetmask(0); +#endif + jt->tssbase=tod(); + meminit(); + sesminit(); + evinit(); + consinit(); + symbinit(); + parseinit(); + xoinit(); + xsinit(); + sbtypeinit(); + rnginit(); +#if (SYS & SYS_DOS+SYS_MACINTOSH) + xlinit(); +#endif + jtecvtinit(jt); + R !jt->jerr; +} + +C jtjinit2(J jt,int dummy0,C**dummy1){jt->sesm=1; R jinit3();}
new file mode 100644 --- /dev/null +++ b/io.c @@ -0,0 +1,409 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Input/Output */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#else +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mman.h> +#define _stdcall +#endif + +#include "j.h" +#include "d.h" + +void jtwri(J jt,I type,C*p,I m,C*s){C buf[1024],*t=jt->outseq,*v=buf;I c,d,e,n; + if(jt->tostdout){ + c=strlen(p); /* prompt */ + e=strlen(t); /* end-of-line */ + n=sizeof(buf)-(c+e+1); /* main text */ + d=m>n?n-3:m; + memcpy(v,p,c); v+=c; + memcpy(v,s,d); v+=d; if(m>n){memcpy(v,"...",3L); v+=3;} + memcpy(v,t,e); v+=e; + *v=0; + jsto(jt,type,buf); +}} + +static void jtwrf(J jt,I n,C*v,F f){C*u,*x;I j=0,m; + while(n>j){ + u=j+v; + m=(x=memchr(u,CLF,n-j))?1+x-u:n-j; + fwrite(u,sizeof(C),m,f); + j+=m; +}} + +A jtinpl(J jt,B b,I n,C*s){C c;I k=0; + if(n&&(c=*(s+n-1),CLF==c||CCR==c))--n; + ASSERT(!*jt->adbreak,EVINPRUPT); + if(!b){ /* 1==b means literal input */ + if(n&&COFF==*(s+n-1))joff(zero); + c=jt->bx[9]; if(c<0)DO(n, if(' '!=s[i]&&c!=s[i]){k=i; break;}); + } + R str(n-k,s+k); +} + +static I advl(I j,I n,C*s){B b;C c,*v; + v=j+s; + DO(n-j, c=*v++; b=c==CCR; if(b||c==CLF)R j+1+i+(b&&CLF==*v);); + R n; +} /* advance one line on CR, CRLF, or LF */ + +void breakclose(J jt); + +static C* nfeinput(J jt,C* s){A y; + jt->breakignore=1; + y=exec1(cstr(s)); + jt->breakignore=0; + if(!y){breakclose(jt);exit(2);} /* J input verb failed */ + jtwri(jt,MTYOLOG,"",strlen(CAV(y)),CAV(y)); + return CAV(y); /* don't combine with previous line! CAV runs (x) 2 times! */ +} + +A jtjgets(J jt,C*p){A y;B b;C*v;I j,k,m,n;UC*s; + *jt->adbreak=0; + if(b=1==*p)p=""; /* 1 means literal input */ + if(jt->dcs){ + ++jt->dcs->dcn; j=jt->dcs->dci; + y=jt->dcs->dcy; n=AN(y); s=UAV(y); + RZ(j<n); + jt->dcs->dcj=k=j; + jt->dcs->dci=j=advl(j,n,s); + m=j-k; if(m&&32>s[k+m-1])--m; if(m&&32>s[k+m-1])--m; + jtwri(jt,MTYOLOG,p,m,k+s); + R inpl(b,m,k+s); + } + /* J calls for input in 3 cases: + debug suspension for normal input + n : 0 input lines up to terminating ) + 1!:1[1 read from keyboard */ + showerr(); + if(jt->nfe) + v=nfeinput(jt,*p?"input_jfe_' '":"input_jfe_''"); + else{ + ASSERT(jt->sminput,EVBREAK); + v=((inputtype)(jt->sminput))(jt,p); + } + R inpl(b,(I)strlen(v),v); +} + +extern C breakdata; + +#if SYS&SYS_UNIX +void breakclose(J jt) +{ + if(jt->adbreak==&breakdata) return; + munmap(jt->adbreak,1); + jt->adbreak=&breakdata; + close(jt->breakfh); + jt->breakfh=0; + unlink(jt->breakfn); + *jt->breakfn=0; +} +#else +void breakclose(J jt) +{ + if(jt->adbreak==&breakdata) return; + UnmapViewOfFile(jt->adbreak); + jt->adbreak=&breakdata; + CloseHandle(jt->breakmh); + jt->breakmh=0; + CloseHandle(jt->breakfh); + jt->breakfh=0; +#if SY_WINCE + DeleteFile(tounibuf(jt->breakfn)); +#else + DeleteFile(jt->breakfn); +#endif + *jt->breakfn=0; +} +#endif + +F1(jtjoff){I x; + RZ(w); + x=i0(w); + breakclose(jt); + if(jt->sesm)jsto(jt, MTYOEXIT,(C*)x); + exit((int)x); + R 0; +} + +#if (SYS & SYS_SESM) + +I jdo(J jt, C* lp){I e,old;A x; + jt->jerr=0; jt->etxn=0; /* clear old errors */ + old=jt->tbase+jt->ttop; + *jt->adbreak=0; + x=inpl(0,(I)strlen(lp),lp); + while(jt->iepdo&&jt->iep){jt->iepdo=0; immex(jt->iep); jt->jerr=0; tpop(old);} + if(!jt->jerr)immex(x); + e=jt->jerr; + jt->jerr=0; + if(e&&DBERRCAP==jt->db&&jt->dbtrap){ + jt->db=0; + immex(jt->dbtrap); + jt->jerr=0; + } + while(jt->iepdo&&jt->iep){jt->iepdo=0; immex(jt->iep); jt->jerr=0; tpop(old);} + showerr(); + spfree(); + tpop(old); + R e; +} + +#define SZINT ((I)sizeof(int)) + +DF1(jtwd){A z=0;C*p=0;D*pd;I e,*pi,t;V*sv; + F1RANK(1,jtwd,self); + RZ(w); + ASSERT(2>AR(w),EVRANK); + sv=VAV(self); + t=i0(sv->g); + if(t>=2000 && t<3000 && AN(w) && LIT!=AT(w) && C2T!=AT(w) && INT!=AT(w)) + { + switch(AT(w)) + { + case B01: + RZ(w=vi(w));break; + case FL: + pd=DAV(w); + GA(w,INT,AN(w),AR(w),0); + pi=AV(w); + DO(AN(w),*pi++=(I)(jfloor(0.5+*pd++));); + break; + default: + ASSERT(0,EVDOMAIN); + } + } + // t is 11!:t and w is wd argument + e=jt->smdowd ? ((dowdtype)(jt->smdowd))(jt, (int)t, w, &z) : EVDOMAIN; + if(!e) R mtm; // e==0 is MTM + if(e==-1) R z; // e---1 is zp + ASSERT(e<=0,e); // e>=0 is EVDOMAIN etc + RZ(z=df1(z,cut(ds(CBOX),num[-2]))); // e==-2 is lit pairs + R reshape(v2(AN(z)/2,2L),z); +} + +C* getlocale(J jt){A y=locname(mtv); y=*AAV(y); R CAV(y);} + +static char breaknone=0; + +B jtsesminit(J jt){jt->adbreak=&breakdata; R 1;} +#endif + +int _stdcall JDo(J jt, char* lp){int r; + r=(int)jdo(jt,lp); + while(jt->nfe) + r=(int)jdo(jt,nfeinput(jt,"input_jfe_' '")); + R r; +} + +/* socket protocol CMDGET name */ +A _stdcall JGetA(J jt, I n, C* name){A x; + jt->jerr=0; + RZ(x=symbrdlock(nfs(n,name))); + ASSERT(!(FUNC&AT(x)),EVDOMAIN); + R binrep1(x); +} + +/* socket protocol CMDSET */ +I _stdcall JSetA(J jt,I n,C* name,I dlen,C* d){I old; + jt->jerr=0; + if(!vnm(n,name)) R EVILNAME; + old=jt->tbase+jt->ttop; + symbis(nfs(n,name),jtunbin(jt,str(dlen,d)),jt->global); + tpop(old); + R jt->jerr; +} + +/* set jclient callbacks */ +void _stdcall JSM(J jt, void* callbacks[]) +{ + jt->smoutput = (outputtype)callbacks[0]; + jt->smdowd = (dowdtype)callbacks[1]; + jt->sminput = (inputtype)callbacks[2]; + jt->sm = (I)callbacks[4]; +} + +C* _stdcall JGetLocale(J jt){return getlocale(jt);} + +A _stdcall Jga(J jt, I t, I n, I r, I*s){ + return ga(t, n, r, s); +} + +void oleoutput(J jt, I n, char* s); /* SY_WIN32 only */ + +/* jsto - display output in output window */ +void jsto(J jt,I type,C*s){C e;I ex; + if(jt->nfe) + { + C q[]="0 output_jfe_ (15!:18)0"; + q[0]+=(C)type; + jt->mtyostr=s; + e=jt->jerr; ex=jt->etxn; + jt->jerr=0; jt->etxn=0; + jt->breakignore=1;exec1(cstr(q));jt->breakignore=0; + jt->jerr=e; jt->etxn=ex; + }else{ + if(jt->smoutput) ((outputtype)(jt->smoutput))(jt,(int)type,s); +#if SY_WIN32 && !SY_WINCE + if(type & MTYOFM) oleoutput(jt,strlen(s),s); /* save output for ole */ +#endif +}} + +#if SYS&SYS_UNIX + +J JInit(void){ + J jt; + /* jtglobinit must be done once when dll is first loaded + Windows does it in dll load routine - thread safe + Unix does it here once, but this is not thread safe */ + + static J g_jt=0; + if(!g_jt) + { + g_jt=malloc(sizeof(JST)); + if(!g_jt) R 0; + memset(g_jt,0,sizeof(JST)); + if(!jtglobinit(g_jt)){free(g_jt);g_jt=0; R 0;} + } + RZ(jt=malloc(sizeof(JST))); + memset(jt,0,sizeof(JST)); + if(!jtjinit2(jt,0,0)){free(jt); R 0;}; + R jt; +} + +int JFree(J jt){return 0;} +#endif + +F1(jtbreakfnq){ + ASSERTMTV(w); + R cstr(jt->breakfn); +} + +F1(jtbreakfns){A z;I *fh,*mh; void* ad; + ASSERT(1>=AR(w),EVRANK); + ASSERT(!AN(w)||AT(w)&LIT,EVDOMAIN); + ASSERT(AN(w)<NPATH,EVDOMAIN); + if(!strcmp(jt->breakfn,CAV(w))) R mtm; + breakclose(jt); +#if SYS&SYS_UNIX + fh=(I*)(I)open(CAV(w),O_RDWR); + ASSERT(-1!=(I)fh,EVDOMAIN); + ad=mmap(0,1,PROT_READ|PROT_WRITE,MAP_SHARED,(I)fh,0); + if(0==ad){close(fh); ASSERT(0,EVDOMAIN);} +#else + RZ(z=toutf16x(w)); + fh=CreateFileW(USAV(z),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); + ASSERT(INVALID_HANDLE_VALUE!=fh,EVDOMAIN); + mh=CreateFileMapping(fh,0,PAGE_READWRITE,0,1,0); + if(0==mh){CloseHandle(fh); ASSERT(0,EVDOMAIN);} + ad=MapViewOfFile(mh,FILE_MAP_WRITE,0,0,0); + if(0==ad){CloseHandle(mh); CloseHandle(fh); ASSERT(0,EVDOMAIN);} +#endif + strcpy(jt->breakfn,CAV(w)); + jt->breakfh=fh; + jt->breakmh=mh; + jt->adbreak=ad; + R mtm; +} + +int valid(C* psrc, C* psnk) +{ + while(*psrc == ' ') ++psrc; + if(!isalpha(*psrc)) return EVILNAME; + while(isalnum(*psrc) || *psrc=='_') *psnk++ = *psrc++; + while(*psrc == ' ') ++psrc; + if(*psrc) return EVILNAME; + *psnk = 0; + return 0; +} + +int _stdcall JGetM(J jt, C* name, I* jtype, I* jrank, I* jshape, I* jdata) +{ + A a; char gn[256]; + if(strlen(name) >= sizeof(gn)) return EVILNAME; + if(valid(name, gn)) return EVILNAME; + RZ(a=symbrdlock(nfs(strlen(gn),gn))); + if(FUNC&AT(a))R EVDOMAIN; + *jtype = AT(a); + *jrank = AR(a); + *jshape = (I)AS(a); + *jdata = (I)AV(a); + return 0; +} + +static int setterm(J jt, C* name, I* jtype, I* jrank, I* jshape, I* jdata) +{ + A a; + I k=1,i,n; + char gn[256]; + + switch(*jtype) + { + case LIT: + case B01: + n = sizeof(char); + break; + + case INT: + n = sizeof(I); + break; + + case FL: + n = sizeof(double); + break; + + case CMPX: + n = 2 * sizeof(double); + break; + + default: + return EVDOMAIN; + } + + // validate name + if(strlen(name) >= sizeof(gn)) return EVILNAME; + if(valid(name, gn)) return EVILNAME; + for(i=0; i<*jrank; ++i) k *= ((I*)(*jshape))[i]; + a = ga(*jtype, k, *jrank, (I*)*jshape); + if(!a) return EVWSFULL; + memcpy(AV(a), (void*)*jdata, n*k); + jset(gn, a); + return jt->jerr; +} + +int _stdcall JSetM(J jt, C* name, I* jtype, I* jrank, I* jshape, I* jdata) +{ + int er; + + PROLOG; + er = setterm(jt, name, jtype, jrank, jshape, jdata); + tpop(_ttop); + return er; +} + +#define EDCBUSY -1 +#define EDCEXE -2 + +C* esub(J jt, I ec) +{ + if(!ec) return ""; + if(ec == EDCBUSY) return "busy with previous input"; + if(ec == EDCEXE) return "not supported in EXE server"; + if(ec > NEVM || ec < 0) return "unknown error"; + return (C*)AV(*(ec+AAV(jt->evm))); +} + +int _stdcall JErrorTextM(J jt, I ec, I* p) +{ + *p = (I)esub(jt, ec); + return 0; +}
new file mode 100644 --- /dev/null +++ b/j.c @@ -0,0 +1,61 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Global Variables */ + +#include "j.h" + +A a0j1=0; /* 0j1 */ +A ace=0; /* a: */ +A ainf=0; /* _ */ +A alp=0; /* a. */ +A aqq=0; /* '' */ +UC bit[8]={(UC)0x80, (UC)0x40, (UC)0x20, (UC)0x10, (UC)0x08, (UC)0x04, (UC)0x02, (UC)0x01}; +UC bitc[256]={0}; /* # 1 bits in each possible byte */ +C bitdisp[256*16]={0}; /* display for each possible byte */ +C breakdata=0; +A chr[256]={0}; /* scalar for each character, or 0 */ +D inf=0; /* _ */ +D infm=0; /* __ */ +A iv0=0; /* ,0 */ +A iv1=0; /* ,1 */ +D jnan=0; /* _. */ +I liln=0; /* 1 iff little endian */ +A mark=0; /* parser marker */ +C minus0[8]={0}; /* the abominable minus 0 */ +A mdot=0; /* m. */ +A mnam=0; /* m as a name */ +I msize[MLEN]={0}; /* m.c size of blocks in mfree[i] */ +A mtm=0; /* i. 0 0 */ +A mtv=0; /* i.0 */ +A ndot=0; /* n. */ +A nnam=0; /* n as a name */ +A* num=0; /* i=num[i]; see numinit() */ +A numv[19]={0}; +A one=0; /* 1 */ +D pf=0; /* performance frequency */ +A pie=0; /* o.1 */ +A pst[256]={0}; +B testb[256]={0}; /* 1 iff test block follows */ +A udot=0; /* u. */ +A unam=0; /* u as a name */ +A vdot=0; /* v. */ +A vnam=0; /* v as a name */ +C wtype[256]={0}; +A xdot=0; /* x. */ +A xnam=0; /* x as a name */ +X xone=0; /* extended integer 1 */ +X xzero=0; /* extended integer 0 */ +A ydot=0; /* y. */ +A ynam=0; /* y as a name */ +A zero=0; /* 0 */ +Q zeroQ={0,0}; /* 0r1 */ +DX zeroDX={0,0}; /* 0 */ +Z zeroZ={0,0}; /* 0j0 */ +A zpath=0; /* default locale search path */ + +/* version text up to first / is the J System ID and it */ +/* identifies the J Front Ends, J Engine, and J Library */ +/* and is used in Unix to find profile.ijs */ + +F1(jtversq){ASSERTMTV(w); R cstr("j701/2011-02-23/15:25");}
new file mode 100644 --- /dev/null +++ b/j.h @@ -0,0 +1,345 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Global Definitions */ + +#include "js.h" + +#if SY_WINCE +#include "..\cesrc\cecompat.h" +#endif + +#if (SYS & SYS_PCWIN) +#define HEAPCHECK heapcheck() +#else +#define HEAPCHECK +#endif + +#if (SYS & SYS_ATARIST) +#define __NO_INLINE__ 1 +#endif + +#if (SYS & SYS_UNIX - SYS_SGI) +#include <memory.h> +#include <sys/types.h> +#endif + +#if (SYS & SYS_ANSILIB) +#include <float.h> +#include <limits.h> +#define link unused_syscall_link +#define qdiv unused_netbsd_qdiv +#include <stdlib.h> +#undef link +#undef qdiv +#else +#define const /*nothing*/ /* blame rx.h */ +#endif + +#if ! SY_WINCE +#include <errno.h> +#include <stdio.h> +#endif + +#include <math.h> +#include <string.h> + + +#if SY_64 +#define IMAX 9223372036854775807L +#define FMTI "%lli" +#define FMTI02 "%02lli" +#define FMTI04 "%04lli" +#define FMTI05 "%05lli" + +#else +#define IMAX 2147483647L +#define FMTI "%li" +#define FMTI02 "%02li" +#define FMTI04 "%04li" +#define FMTI05 "%05li" +#endif + +#define IMIN (~IMAX) /* ANSI C LONG_MIN is -LONG_MAX */ + + +#if (SYS & SYS_AMIGA) +#define XINF "\177\377\000\000\000\000\000\000" +#define XNAN "\177\361\000\000\000\000\000\000" +#endif + +#if (SYS & SYS_ARCHIMEDES) +#define XINF "\000\000\360\177\000\000\000\000" +#define XNAN "\000\000\370\377\000\000\000\000" +#endif + +#if (SYS & SYS_DEC5500) || SY_WINCE_SH +#define XINF "\000\000\000\000\000\000\360\177" +#define XNAN "\000\000\000\000\000\000\370\377" +#endif + +#if (SYS & SYS_MACINTOSH) +/* for old versions of ThinkC */ +/* #define XINF "\177\377\000\000\000\000\000\000\000\000\000\000" */ +/* #define XNAN "\377\377\100\000\100\000\000\000\000\000\000\000" */ +/* for ThinkC 7.0 or later */ +#define XINF "\177\377\177\377\000\000\000\000\000\000\000\000" +#define XNAN "\377\377\377\377\100\000\000\000\000\000\000\000" +#endif + +#if (SYS & SYS_SUN4+SYS_SUNSOL2) +#define XINF "\177\360\000\000\000\000\000\000" +#define XNAN "\177\377\377\377\377\377\377\377" +#endif + +#if (SYS & SYS_VAX) +#define XINF "\377\177\377\377\377\377\377\377" +#define XNAN "\377\177\377\377\377\377\377\376" /* not right */ +#endif + +#if (SY_WINCE_MIPS || SY_WINCE_SH) +#if WIN32_PLATFORM_PSPC +#define XINF "\000\000\000\000\000\000\360\177" +#define XNAN "\377\377\377\377\377\377\367\177" +#else +#define XINF "\000\000\000\000\000\000\360\177" +#define XNAN "\001\000\000\000\000\000\360\177" +#endif +#endif + +#if SY_WINCE_ARM +#define XINF "\000\000\000\000\000\000\360\177" +#define XNAN "\000\000\000\000\000\000\370\177" +#endif + +#if (SYS & SYS_LILENDIAN) +#ifndef XINF +#define XINF "\000\000\000\000\000\000\360\177" +#define XNAN "\000\000\000\000\000\000\370\377" +#endif +#endif + +#ifndef XINF +#define XINF "\177\360\000\000\000\000\000\000" +#define XNAN "\177\370\000\000\000\000\000\000" +#endif + + +#ifndef PI +#define PI ((D)3.14159265358979323846) +#endif +#define P2 ((D)6.28318530717958647693) +#ifndef OVERFLOW +#define OVERFLOW ((D)8.988465674311578e307) +#endif +#ifndef UNDERFLOW +#define UNDERFLOW ((D)4.450147717014403e-308) +#endif + + +#define NALP 256 /* size of alphabet */ +#define NETX 2000 /* size of error display buffer */ +#define NPP 20 /* max value for quad pp */ +#define RMAX IMAX /* max rank */ +#define NPATH 1024 /* max length for path names, */ + /* including trailing 0 byte */ + +#if SY_WINCE +#define NFCALL 100L /* wince named fn call depth */ +#define NFDEP 200L /* wince fn call depth */ +#endif +#if SYS & SYS_MACOSX +#define NFCALL 9000L /* darwin named fn call depth */ +#define NFDEP 18000L /* darwin fn call depth */ +#endif +#ifndef NFCALL +#define NFCALL 10000L /* all other named fn call depth */ +#define NFDEP 20000L /* all other fn call depth */ +#endif + +#define NTSTACK 2000L /* size of stack for temps */ + +#define IIDOT 0 /* modes for indexofsub() */ +#define IICO 1 +#define INUBSV 2 +#define INUB 3 +#define ILESS 4 +#define INUBI 5 +#define IEPS 6 +#define II0EPS 7 +#define II1EPS 8 +#define IJ0EPS 9 +#define IJ1EPS 10 +#define ISUMEPS 11 +#define IANYEPS 12 +#define IALLEPS 13 +#define IIFBEPS 14 + +#define IPHOFFSET 30 /* offset for prehashed versions */ +#define IPHIDOT 30 +#define IPHICO 31 +#define IPHLESS 34 +#define IPHEPS 36 +#define IPHI0EPS 37 +#define IPHI1EPS 38 +#define IPHJ0EPS 39 +#define IPHJ1EPS 40 +#define IPHSUMEPS 41 +#define IPHANYEPS 42 +#define IPHALLEPS 43 +#define IPHIFBEPS 44 + + +#if SY_64 && SY_WIN32 +#define jfloor jfloor1 +#else +#define jfloor floor +#endif + +#define BB 8 /* # bits in a byte */ +#if SY_64 +#define BW 64 /* # bits in a word */ +#else +#define BW 32 +#endif + +#define ABS(a) (0<=(a)?(a):-(a)) +#define ACX(a) {AC(a)=IMAX/2;} +#define ASSERT(b,e) {if(!(b)){jsignal(e); R 0;}} +#define ASSERTD(b,s) {if(!(b)){jsigd((s)); R 0;}} +#define ASSERTMTV(w) {RZ(w); ASSERT(1==AR(w),EVRANK); ASSERT(!AN(w),EVLENGTH);} +#define ASSERTN(b,e,nm) {if(!(b)){jt->curname=(nm); jsignal(e); R 0;}} +#define ASSERTSYS(b,s) {if(!(b)){jsignal(EVSYSTEM); jtwri(jt,MTYOSYS,"",(I)strlen(s),s); R 0;}} +#define ASSERTW(b,e) {if(!(b)){if((e)<=NEVM)jsignal(e); else jt->jerr=(e); R;}} +#define CALL1(f,w,fs) ((f)(jt, (w),(A)(fs))) +#define CALL2(f,a,w,fs) ((f)(jt,(a),(w),(A)(fs))) +#define DF1(f) A f(J jt, A w,A self) +#define DF2(f) A f(J jt,A a,A w,A self) +#define DO(n,stm) {I i=0,_n=(n); for(;i<_n;i++){stm}} +#define DQ(n,stm) {I i=(n)-1; for(;i>=0;--i){stm}} +#define ds(c) pst[(UC)(c)] +#define EPILOG(z) R gc(z,_ttop) +#define FDEPDEC(d) {jt->fdepi-=d;} +#define FDEPINC(d) {ASSERT(jt->fdepn>=d+jt->fdepi,EVSTACK); jt->fdepi+=d;} +#define FCONS(x) fdef(CFCONS,VERB,jtnum1,jtnum2,0L,0L,(x),0L,RMAX,RMAX,RMAX) +#define FEQ(u,v) (ABS((u)-(v))<=jt->fuzz*MAX(ABS(u),ABS(v))) +#define F1(f) A f(J jt, A w) +#define F2(f) A f(J jt,A a,A w) +#define F1RANK(m,f,self) {RZ( w); if(m<AR(w) )R rank1ex( w,(A)self,(I)m, f);} +#define F2RANK(l,r,f,self) {RZ(a&&w); if(l<AR(a)||r<AR(w))R rank2ex(a,w,(A)self,(I)l,(I)r,f);} +#define GA(v,t,n,r,s) RZ(v=ga(t,(I)(n),(I)(r),(I*)(s))) +#define HN 3L +#define IC(w) (AR(w) ? *AS(w) : 1L) +#define ICMP(z,w,n) memcmp((z),(w),(n)*SZI) +#define ICPY(z,w,n) memcpy((z),(w),(n)*SZI) +#define INF(x) ((x)==inf||(x)==infm) +#define IX(n) apv((n),0L,1L) +#define JATTN {if(*jt->adbreak&&!jt->breakignore){jsignal(EVATTN); R 0;}} +#define JBREAK0 {if(2<=*jt->adbreak&&!jt->breakignore){jsignal(EVBREAK); R 0;}} +#define MAX(a,b) ((a)>(b)?(a):(b)) +#define MC memcpy +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define MLEN (SY_64?63:31) +#define NAN0 (_clearfp()) +#define NAN1 {if(_SW_INVALID&_clearfp()){jsignal(EVNAN); R 0;}} +#define NAN1V {if(_SW_INVALID&_clearfp()){jsignal(EVNAN); R ;}} +#define PROLOG I _ttop=jt->tbase+jt->ttop +#define R return +#define RE(exp) {if((exp),jt->jerr)R 0;} +#define RER {if(er){jt->jerr=er; R;}} +#define RESETERR {jt->etxn=jt->jerr=0;} +#define RNE(exp) {R jt->jerr?0:(exp);} +#define RZ(exp) {if(!(exp))R 0;} +#define SBSV(x) (jt->sbsv+(I)(x)) +#define SBUV(x) (jt->sbuv+(I)(x)) +#define SGN(a) ((0<(a))-(0>(a))) +#define SMAX 65535 +#define SMIN (-65536) +#define SZA ((I)sizeof(A)) +#define SZD ((I)sizeof(D)) +#define SZI ((I)sizeof(I)) +#define VAL1 '\001' +#define VAL2 '\002' + + +#if SYS & SYS_LILENDIAN +#define B0000 0x00000000 +#define B0001 0x01000000 +#define B0010 0x00010000 +#define B0011 0x01010000 +#define B0100 0x00000100 +#define B0101 0x01000100 +#define B0110 0x00010100 +#define B0111 0x01010100 +#define B1000 0x00000001 +#define B1001 0x01000001 +#define B1010 0x00010001 +#define B1011 0x01010001 +#define B1100 0x00000101 +#define B1101 0x01000101 +#define B1110 0x00010101 +#define B1111 0x01010101 +#define BS00 0x0000 +#define BS01 0x0100 +#define BS10 0x0001 +#define BS11 0x0101 +#else +#define B0000 0x00000000 +#define B0001 0x00000001 +#define B0010 0x00000100 +#define B0011 0x00000101 +#define B0100 0x00010000 +#define B0101 0x00010001 +#define B0110 0x00010100 +#define B0111 0x00010101 +#define B1000 0x01000000 +#define B1001 0x01000001 +#define B1010 0x01000100 +#define B1011 0x01000101 +#define B1100 0x01010000 +#define B1101 0x01010001 +#define B1110 0x01010100 +#define B1111 0x01010101 +#define BS00 0x0000 +#define BS01 0x0001 +#define BS10 0x0100 +#define BS11 0x0101 +#endif + +#include "ja.h" +#include "jc.h" +#include "jtype.h" +#include "jt.h" +#include "jlib.h" +#include "je.h" +#include "jerr.h" +#include "va.h" +#include "vq.h" +#include "vx.h" +#include "vz.h" +#include "vdx.h" +#include "m.h" +#include "a.h" +#include "s.h" + +// JPFX("here we are\n") +// JPF("size is %i\n", v) +// JPF("size and extra: %i %i\n", (v,x)) +#define JPFX(s) {char b[1000]; sprintf(b, s); jsto(gjt,MTYOFM,b);} +#define JPF(s,v) {char b[1000]; sprintf(b, s, v); jsto(gjt,MTYOFM,b);} +extern J gjt; // global for JPF (procs without jt) + +#if SY_WINCE_MIPS +/* strchr fails for CE MIPS - neg chars - spellit fails in ws.c for f=.+. */ +#define strchr(a,b) strchr(a, (UC)b) +#endif + +#if SYS & SYS_UNIX +#include <fenv.h> +#define _isnan isnan +#define _SW_INVALID FE_INVALID + +static inline UINT _clearfp(void){int r=fetestexcept(FE_ALL_EXCEPT); + feclearexcept(FE_ALL_EXCEPT); return r; +} +#endif
new file mode 100644 --- /dev/null +++ b/j/addons/data/jmf/jmf.ijs @@ -0,0 +1,455 @@ +cocurrent 'jmf' + +jsystemdefs 'hostdefs' + +coinsert 'jdefs' + + +doc=: 0 : 0 + + map name;filename [;sharename;readonly] + - map jmf file (self-describing) + + opt map name;filename [;sharename;readonly] + - map data file (opt is description) + + where: opt=type [;trailing_shape] + + types are defined in dll.ijs as: + JB01 boolean + JCHAR character + JINT integer + JFL floating point + JCMPX complex + + trailing_shape= }. shape (default '') + + [force] unmap name + 0 ok + 1 not mapped + 2 refs + + unmapall'' - unmap all + + createjmf filename;msize - creates jmf file as empty vector + (self-describing) + + additem name - add an item to a name + + share name;sharedname - share 'sharedname' as name + + showle name - show locale entry and header for name + + showmap'' - show all maps + +) +SZI=: IF64{4 8 +'HADK HADFLAG HADM HADT HADC HADN HADR HADS'=: SZI*i.8 +HADCN=: <.HADC%SZI + +HSN=: 7+64 +HS=: SZI*HSN +AFRO=: 1 +AFNJA=: 2 +NULLPTR=: <0 +3 : 0'' +if. IFUNIX do. + lib=. >(UNAME-:'Darwin'){'libc.so.6 ';'libc.dylib ' + api=. 1 : ('(''',lib,''',x) & cd') + c_isatty=: ' isatty i i' api + c_open=: 'open i *c i i' api + c_close=: 'close i i' api + c_read=: 'read x i * x' api + c_write=: 'write x i * x' api + c_lseek=: 'lseek x i x i' api + c_mmap=: 'mmap * * x i i i x' api + c_munmap=: 'munmap i * x' api + if. UNAME -: 'Darwin' do. + c_mmap=: }:@:('mmap * * i i i i i i' api)@:(}: , (<0)"_ , {:) + if. ({.a.)={. 1&(3!:4) 1 do. + c_lseek=: (0 1 3 4&{)@:('lseek i i i i i' api)@:(0&{ , (<0)"_ , 1&{ , 2&{) + end. + end. +else. + CREATE_ALWAYS=: 2 + CREATE_NEW=: 1 + FALSE=: 0 + FILE_BEGIN=: 0 + FILE_END=: 2 + FILE_MAP_READ=: 4 + FILE_MAP_WRITE=: 2 + FILE_SHARE_READ=: 1 + FILE_SHARE_WRITE=: 2 + GENERIC_READ=: _2147483648 + GENERIC_WRITE=: 1073741824 + OPEN_ALWAYS=: 4 + OPEN_EXISTING=: 3 + PAGE_READONLY=: 2 + PAGE_READWRITE=: 4 + TRUNCATE_EXISTING=: 5 + + j=. (GENERIC_READ+GENERIC_WRITE),PAGE_READWRITE,FILE_MAP_WRITE + RW=: j,:GENERIC_READ,PAGE_READONLY,FILE_MAP_READ + + CloseHandleR=: 'kernel32 CloseHandle > i x'&(15!:0) + CreateFileMappingR=: 'kernel32 CreateFileMappingA > x x * i i i *c'&(15!:0) + CreateFileR=: 'kernel32 CreateFileA > x *c i i * i i x'&(15!:0) + GetLastError=: 'kernel32 GetLastError > i'&(15!:0) + FlushViewOfFileR=: 'kernel32 FlushViewOfFile > i * x'&(15!:0) + MapViewOfFileR=: >@{.@('kernel32 MapViewOfFile * x i i i x'&(15!:0)) + OpenFileMappingR=: 'kernel32 OpenFileMappingA > x i i *c'&(15!:0) + SetEndOfFile=: 'kernel32 SetEndOfFile > i x'&(15!:0) + UnmapViewOfFileR=: 'kernel32 UnmapViewOfFile > i *'&(15!:0) + WriteFile=: 'kernel32 WriteFile i x * i *i *'&(15!:0) + if. IF64 do. + GetFileSizeR=: 2 >@{ 'kernel32 GetFileSizeEx i x *x' 15!:0 ;&(,2) + SetFilePointerR=: 'kernel32 SetFilePointerEx > i x x *x i'&(15!:0) + else. + GetFileSizeR=: 'kernel32 GetFileSize > i x *i' 15!:0 ;&(<NULLPTR) + SetFilePointerR=: 'kernel32 SetFilePointer > i x i *i i'&(15!:0) + end. +end. + +if. _1 = 4!:0<'mappings' do. + mappings=: i.0 8 +end. +empty'' +) +symget=: 15!:6 +symset=: 15!:7 +allochdr=: 3 : 'r[2 memw (r=.15!:8 y),HADC,1,JINT' + +freehdr=: 15!:9 +msize=: 3 : 'memr y,HADM,1,JINT' +refcount=: 3 : 'memr y,HADC,1,JINT' +MAXINTU=: 2 ^ IF64{32 64x +MAXINTS=: <: 2 ^ IF64{31 63x +ufs=: + MAXINTU * 0 > ] +sfu=: _1 x: ] - MAXINTU * MAXINTS < ] +findkey=: 4 : 'I. (<x) = {."1 y' +free=: 3 : 0 +'fh mh fad'=. y +if. IFUNIX do. + if. fad do. c_munmap (<fad);mh end. + if. fh~:_1 do. c_close fh end. +else. + if. fad do. UnmapViewOfFileR <<fad end. + if. mh do. CloseHandleR mh end. + if. fh~:_1 do. CloseHandleR fh end. +end. +) +fullname=: 3 : 0 +t=. y-.' ' +t,('_'~:{:t)#'_base_' +) +mbxcheck=: 3 : 0 +x=. 15!:12 y +b=. 0={:"1 x +'a s c'=. |: (-.b)#x +'u n z'=. ,b#x +z=. *./ c e. 1 2 +z=. z, (-:<.) 2^.s +z=. z, (}.a)-:}:a+s +z=. z, u = {.a +z=. z, ({:a+s) <: u+n +z=. z, (-: <.) 64 %~ +/s +z=. z, (+/s) = <.&.(%&64) n +z=. z, *./ 0 = 8|a +) +settypeshape=: 3 : 0 +'name type shape'=: y +rank=. #shape +sad=. symget <fullname name +'bad name' assert sad +had=. 1{s=. memr sad,0 4,JINT +'flag msize'=. memr had,HADFLAG,2,JINT +'not mapped and writeable' assert 2=flag +size=. (JTYPES i.type){JSIZES +ts=. size**/shape +'msize too small' assert ts<:msize +type memw had,HADT,1,JINT +((*/shape),rank,shape) memw had,HADN,(2+rank),JINT +i.0 0 +) +validate=: 3 : 0 +'ts had'=. y +if. ts>:HS do. + d=. memr had,0 4,JINT + *./((HS,ts-HS)=0 2{d),1 2 4 8 16 32 e.~ 3{d +else. 0 end. +) +ERROR_NOT_ENOUGH_MEMORY=: 8 +j=. <;._2 (0 : 0) +1 ERROR_INVALID_FUNCTION +2 ERROR_FILE_NOT_FOUND +3 ERROR_PATH_NOT_FOUND +4 ERROR_TOO_MANY_OPEN_FILES +5 ERROR_ACCESS_DENIED +6 ERROR_INVALID_HANDLE +7 ERROR_ARENA_TRASHED +8 ERROR_NOT_ENOUGH_MEMORY +9 ERROR_INVALID_BLOCK +10 ERROR_BAD_ENVIRONMENT +11 ERROR_BAD_FORMAT +12 ERROR_INVALID_ACCESS +13 ERROR_INVALID_DATA +14 ERROR_OUTOFMEMORY +15 ERROR_INVALID_DRIVE +16 ERROR_CURRENT_DIRECTORY +17 ERROR_NOT_SAME_DEVICE +18 ERROR_NO_MORE_FILES +19 ERROR_WRITE_PROTECT +20 ERROR_BAD_UNIT +21 ERROR_NOT_READY +22 ERROR_BAD_COMMAND +23 ERROR_CRC +24 ERROR_BAD_LENGTH +25 ERROR_SEEK +26 ERROR_NOT_DOS_DISK +27 ERROR_SECTOR_NOT_FOUND +28 ERROR_OUT_OF_PAPER +29 ERROR_WRITE_FAULT +30 ERROR_READ_FAULT +31 ERROR_GEN_FAILURE +32 ERROR_SHARING_VIOLATION +33 ERROR_LOCK_VIOLATION +34 ERROR_WRONG_DISK +) + +WINERRNOS=: 0 ". 2 {.&> j +WINERRMSG=: 3 }.each j +additem=: 3 : 0 +sad=. symget <fullname y +'bad name' assert sad +had=. 1{s=. memr sad,0 4,JINT +'flag msize type rank'=. 1 2 3 6{memr had,0 28,JINT +'not mapped and writeable' assert 2=flag +'scalar' assert 0~:rank +'not supported for boxed data' assert 32~:type +shape=. memr had,HADS,rank,JINT +shape=. shape+1,0#~rank-1 +size=. (JTYPES i.type){JSIZES +ts=. size**/shape +'msize too small' assert ts<:msize +((*/shape),rank,shape) memw had,HADN,(2+rank),JINT +i.0 0 +) +createjmf=: 3 : 0 +'fn msize'=. y +msize=. <. msize +ts=. HS+msize +if. IFUNIX do. + fh=. 0 pick c_open fn; (OR O_RDWR, O_CREAT, O_TRUNC); 8b666 + c_lseek fh;(<:ts);SEEK_SET + c_write fh; (,0{a.); 0+1 + c_lseek fh;0 ;SEEK_SET + d=. HS,AFNJA,msize,JINT,0,0,1,0 + c_write fh;d;(SZI*#d) + c_close fh +else. + fh=. CreateFileR fn;(GENERIC_READ+GENERIC_WRITE);0;NULLPTR;CREATE_ALWAYS;0;0 + SetFilePointerR fh;ts;NULLPTR;FILE_BEGIN + SetEndOfFile fh + SetFilePointerR fh;0;NULLPTR;FILE_BEGIN + d=. HS,AFNJA,msize,JINT,0,0,1,0 + WriteFile fh;d;(SZI*#d);(,0);<NULLPTR + CloseHandleR fh +end. +i.0 0 +) +share=: 3 : 0 +'name sn ro'=. 3{.y,<0 +sn=. '/' (('\'=sn)#i.#sn)} sn +if. IFUNIX do. + map name;sn;sn;ro +else. + name=. fullname name + c=. #mappings + assert c=({."1 mappings)i.<name['noun already mapped' + 4!:55 ::] <name + 'bad noun name'assert ('_'={:name)*._1=nc<name + fh=. _1 + fn=. '' + mh=. OpenFileMappingR (ro{FILE_MAP_WRITE,FILE_MAP_READ);0;sn,{.a. + if. mh=0 do. assert 0[CloseHandleR fh['bad mapping' end. + fad=. MapViewOfFileR mh;FILE_MAP_WRITE;0;0;0 + if. fad=0 do. assert 0[CloseHandleR mh[CloseHandleR fh['bad view' end. + had=. fad + hs=: 0 + ts=. memr had,HADM,1,JINT + mappings=: mappings,name;fn;sn;fh;mh;fad;had;ts + (name)=: symset had + i.0 0 +end. +) +getflagsad=: 3 : 0 +SZI+1{memr (symget <fullname y),0 4,JINT +) +readonly=: 3 : 0 +AFRO(17 b.)memr (getflagsad y),0 1,JINT +: +flagsad=. getflagsad y +flags=. memr flagsad,0 1,JINT +flags=. flags(17 b.)(26 b.)AFRO +flags=. flags(23 b.)AFRO*0~:x +flags memw flagsad,0 1,JINT +i. 0 0 +) +showle=: 3 : 0 +le=. memr (symget <fullname y),0 4,JINT +had=. 1{le +h=. memr had,0 7,JINT +s=. memr had,HADS,(6{h),JINT +le;h;s +) +showmap=: 3 : 0 +h=. 'name';'fn';'sn';'fh';'mh';'address';'header';'ts';'msize';'refs' +hads=. 6{"1 mappings +h,mappings,.(msize each hads),.refcount each hads +) +map=: 3 : 0 +0 map y +: +if. 0=L.x do. t=. <&> x else. t=. x end. +'type tshape hsize'=. 3 {. t, a: + +'trailing shape may not be zero' assert -. 0 e. tshape + +'name fn sn ro'=. 4{.y,(#y)}.'';'';'';0 +sn=. '/' (('\'=sn)#i.#sn)} sn +name=. fullname name +c=. #mappings + +'name already mapped'assert c=({."1 mappings)i.<name +'filename already mapped'assert c=(1{"1 mappings)i.<fn +'sharename already mapped'assert (''-:sn)+.c=(2{"1 mappings)i.<sn +4!:55 ::] <name +'bad noun name'assert ('_'={:name)*._1=nc<name + +ro=. 0~:ro +aa=. AFNJA+AFRO*ro + +if. IFUNIX do. + 'Unix sharename must be same as filename' assert (sn-:'')+.sn-:fn + ts=. 1!:4 <fn + fh=. >0 { c_open fn;(ro{O_RDWR,O_RDONLY);0 + 'bad file name/access' assert fh~:_1 + mh=. ts + fad=. >0{ c_mmap (<0);ts;(OR ro}. PROT_WRITE, PROT_READ);MAP_SHARED;fh;0 + if. fad e. 0 _1 do. + 'bad view' assert 0[free fh,mh,0 + end. +else. + 'fa ma va'=. ro{RW + fh=. CreateFileR (fn,{.a.);fa;(FILE_SHARE_READ+FILE_SHARE_WRITE);NULLPTR;OPEN_EXISTING;0;0 + 'bad file name/access'assert fh~:_1 + ts=. GetFileSizeR fh + mh=: CreateFileMappingR fh;NULLPTR;ma;0;0;(0=#sn){(sn,{.a.);<NULLPTR + if. mh=0 do. 'bad mapping'assert 0[free fh,0,0 end. + fad=. MapViewOfFileR mh;va;0;0;0 + if. fad=0 do. + errno=. GetLastError'' + free fh,mh,0 + if. ERROR_NOT_ENOUGH_MEMORY-:errno do. + 'not enough memory' assert 0 + else. + 'bad view' assert 0 + end. + end. +end. + +if. ro*.0=type do. + had=. allochdr 127 + d=. memr fad,0,HSN,JINT + d=. (sfu HS+-/ufs fad,had),aa,2}.d + d=. 1 HADCN} d + d memw had,0,HSN,JINT +elseif. 0=type do. + had=. fad + if. 0=validate ts,had do. 'bad jmf header' assert 0[free fh,mh,fad end. + aa memw had,HADFLAG,1,JINT + if. sn-:'' do. + t=. 0 + else. + t=. 10000+ memr had,HADC,1,JINT + end. + (,t+1) memw had,HADC,1,JINT +elseif. 1 do. + had=. allochdr 127 + bx=. JBOXED=type + hs=. (+/hsize)*asize=. JSIZES {~ JTYPES i. type + lshape=. bx}.<.(ts-hs)%(*/tshape)*asize + d=. sfu hs+-/ufs fad,had + h=. d,aa,ts,type,1,(*/lshape,tshape),((-.bx)+#tshape),lshape,tshape + h memw had,0,(#h),JINT +end. + +mappings=: mappings,name;fn;sn;fh;mh;fad;had +(name)=: symset had +i.0 0 +) +unmap=: 3 : 0 +0 unmap y +: +'y newsize'=. 2{.(boxopen y),<_1 +n=. <fullname y +row=. ({."1 mappings)i.n +if. row=#mappings do. 1 return. end. +m=. row{mappings +4!:55 ::] n +'sn fh mh fad had'=. 5{.2}.m + +if. *./(-.x),(0=#sn),1~:memr had,HADC,1,JINT do. 2 return. end. + +jmf=. fad = had +if. -.jmf do. freehdr had end. +if. _1=newsize do. + free fh,mh,fad +else. + newsize=. <.newsize + totsize=. newsize + jmf*HS + free _1,mh,fad + if. IFUNIX do. + c_lseek fh;(<:totsize);SEEK_SET + c_write fh;(,0{a.);0+1 + if. jmf do. + c_lseek fh;(SZI*2);SEEK_SET + c_write fh;(,newsize);SZI + end. + c_close fh + else. + SetFilePointerR fh;totsize;NULLPTR;FILE_BEGIN + SetEndOfFile fh + if. jmf do. + SetFilePointerR fh;(SZI*2);NULLPTR;FILE_BEGIN + WriteFile fh;(,newsize);SZI;(,0);<NULLPTR + end. + CloseHandleR fh + end. +end. +mappings=: (row~:i.#mappings)#mappings +0 +) +unmapall=: 3 : '>unmap each 0{"1 mappings' +memshare=: 3 : 0 +bNo_Inherit_Handle=. FALSE +lpShareName=. y,{.a. +mh=. OpenFileMappingR (FILE_MAP_READ+FILE_MAP_WRITE); bNo_Inherit_Handle; lpShareName +('Unable to map ',y) assert mh~:0 + +addr=. MapViewOfFileR mh; (FILE_MAP_READ+FILE_MAP_WRITE); 0; 0; 0 +if. addr=0 do. 'MapViewOfFile failed' assert 0[CloseHandleR mh end. +".(_1=4!:0<'mapTable')#'mapTable=:i.0,3' +mapTable=: mapTable, y; mh; addr +addr +) +memshareclose=: 3 : 0 +r=. y findkey mapTable +'Unknown share name' assert 0~:$r +'mh addr'=. {:(<r; 1 2){mapTable +('Unable to close share: ', y) assert $mh > 0 +UnmapViewOfFileR <<addr +if. CloseHandleR mh do. + mapTable=: (<((i.#mapTable)-.r); i.{:$mapTable){mapTable +end. +)
new file mode 100644 --- /dev/null +++ b/j/bin/profile.ijs @@ -0,0 +1,44 @@ +NB. J profile +NB. JFE sets BINPATH_z_ and ARGV_z_ +NB. add your sentences in startup.ijs + +systype=. 9!:12'' +jpathsep_z_=: '/'&(('\' I.@:= ])}) NB. convert to / separator +BINPATH_z_=: jpathsep BINPATH_z_ + +NB. create SystemFolders +bin=. BINPATH +install=. (bin i: '/'){.bin +addons=. install,'/addons' +system=. install,'/system' +tools=. install,'/tools' +home=. >(systype-5){(2!:5'HOME');2!:5'USERPROFILE' + +userx=. '\j',('64-'#~16={:$3!:3[2),'701-user' +user=. home,userx +break=. user,'/break' +snap=. user,'/snap' +temp=. user,'/temp' +config=. user,'/config' +ids=. ;:'addons bin break config home install snap system tools temp user' + +0!:0 :: ] <jpathsep bin,'/profilex.ijs' NB. override + +SystemFolders_j_=: ids,.jpathsep@".&.>ids + +md=. 3 : 0 NB. recursive makedir +a=. jpathsep y,'/' +if. -.#1!:0 }:a do. + for_n. I. a='/' do. 1!:5 :: [ <n{.a end. +end. +) + +NB. try to ensure user folders exist +md user,'/projects' +md temp +md break +md config +md snap + +NB. boot up J and load startup.ijs if it exists +0!:0 <jpathsep system,'/util/boot.ijs'
new file mode 100644 --- /dev/null +++ b/j/bin/profilex_template.ijs @@ -0,0 +1,28 @@ +NB. profilex.ijs template +NB. copy template to profilex and edit as required +NB. profilex.ijs overrides profile definitions +NB. profilex.ijs is not replaced by installs/updates +NB. errors may prevent startup +NB. check SystemFolders_j_ before/after changes +NB. install is J folder +NB. home is HOME +NB. userx is \j701-user or \j64-701-user +NB. see profile.ijs for more info + +NB. example 1: user in J folder +NB. user=. install,userx + +NB. example 2: user in d:/ +NB. user=. 'd:',userx + +NB. example 3: user in home/Documents +NB. user=. home,'/Documents',userx + +NB. example 4: user in same folder as install +NB. user=. ('/'(i:~{.])install),userx + +user=. home,userx NB. profile default - edit to change +break=. user,'/break' +snap=. user,'/snap' +temp=. user,'/temp' +config=. user,'/config'
new file mode 100644 --- /dev/null +++ b/j/system/config/base.cfg @@ -0,0 +1,83 @@ +NB. base config +NB. +NB. interpreter config: +NB. BoxForm 0=linedraw 1=ascii (9!:7) +NB. BoxPos boxed output positioning (9!:17) +NB. +NB. DisplayForm output display form (9!:3) +NB. The representation(s) to used for default displays of non-nouns. +NB. 1 atomic, 2 boxed, 4 tree, 5 linear, 6 paren. +NB. +NB. MemoryLimit memory limit (9!:21) +NB. Output output definition (9!:37) +NB. +NB. recent lists: +NB. RecentMax max entries in lists +NB. +NB. script formatting: +NB. Format is a numeric list: +NB. 0 0=no format, 1=do format +NB. 1 soft tab width (0=hard tab) +NB. 2 if remove multiple spaces in code +NB. 3 if indent explicit definition +NB. 4 if indent select +NB. +NB. Tags boxed list of tags files +NB. +NB. UserDict: boxed list of user dictionary for codecompletion +NB. each dictionary contains one name per line as proposals for codecompletion +NB. when running gtkide, gtkdocdict will be handled automatically and need not be included here +NB. eg. '~/french.txt';'~/russian.txt' +NB. +NB. external programs: +NB. Browser web browser, used in Help +NB. Browser_nox browser (without X), used in Help +NB. EPSReader read encapsulated postscript files +NB. PDFReader read Adobe pdf files +NB. XDiff external differencing program +NB. Editor external editor program, %f=file name %l=line number +NB. Editor_nox external editor program (without X), used in Linux only + +BoxPos=: 0 0 +DirTreeX=: 'release' +DisplayForm=: 5 +Format=: 1 2 1 0 0 +MemoryLimit=: _ +Output=: 0 256 0 222 +RecentMax=: 15 +Tags=: '~Projects/tags';'~install/tags';'~addons/api/gtkinclude/tags' +UserDict=: '' + +NB. ========================================================= +NB. host dependent configs: +3 : 0'' +select. UNAME +case. 'Darwin' do. + BoxForm=: 0 + Browser=: '' + Browser_nox=: '' + EPSReader=: '' + PDFReader=: '' + XDiff=: '' + Editor=: '' + Editor_nox=: '' +case. 'Linux' do. + BoxForm=: 0 + Browser=: '' + Browser_nox=: '/usr/bin/w3m' + EPSReader=: '/usr/bin/evince' + PDFReader=: '/usr/bin/evince' + XDiff=: '/usr/bin/meld' + Editor=: 'geany +%l %f' + Editor_nox=: 'vi -c%l %f' +case. 'Win' do. + BoxForm=: 1 + Browser=: '' + Browser_nox=: '' + EPSReader=: 'c:/program files/ghostgum/gsview/gsview32.exe -e' + PDFReader=: 'c:/program files/ghostgum/gsview/gsview32.exe -e' + XDiff=: 'c:/program files/winmerge/winmergeu.exe' + Editor=: 'notepad %f' + Editor_nox=: '' +end. +)
new file mode 100644 --- /dev/null +++ b/j/system/main/ctag.ijs @@ -0,0 +1,209 @@ +NB. base class for ctag + +coclass 'ctag' + +initdone=: 0 +tagtags=: tagfiles=: taglines=: '' +Tags=: '' NB. default Tags files +absolutepath=: 1 NB. 0 - do not resolve absolute path +NB. ctag definition + +create=: destroy=: [: NB. abstract class + + +NB. cleartags +NB. ========================================================= +cleartags=: 3 : 0 +initdone=: 0 +tagtags=: tagfiles=: taglines=: '' +EMPTY +) + +NB. loadtags +NB. ========================================================= +loadtags=: 3 : 0 +if. #y do. + parsetags"0 jpath&.> boxopen y +else. + if. Tags do. parsetags"0 jpath&.> boxopen Tags end. +end. +initdone=: 1 +EMPTY +) + +NB. ========================================================= +NB. parsetags parse tags as segmented string for memory efficiency +parsetags=: 3 : 0 +y=. '/' (I.'\'=y)}y=. >y +a=. freads y +if. 4>#a do. EMPTY return. end. +tag=. ; ,&({.a.)&.>@{.@(<;._2)@(,&TAB);._2 a +if. 0=#tag do. EMPTY return. end. +if. 0=#tagtags do. tagtags=: tagfiles=: taglines=: ,{.a. end. +tagtags=: tagtags, tag +if. absolutepath *. y-.@-:pf=. ({.~ i:&'/')y do. + pf=. pf,'/' + tagfiles=: tagfiles, b=. jpathsep ; ,&({.a.)@(pf&,)&.>@(1&{)@(<;._2)@(,&TAB);._2 a +else. + tagfiles=: tagfiles, b=. jpathsep ; ,&({.a.)&.>@(1&{)@(<;._2)@(,&TAB);._2 a +end. +taglines=: taglines, ; <@(,&({.a.))@parseline@;@:(2&}.)@(<;.2)@(,&TAB);._2 a +EMPTY +) + +NB. ========================================================= +parseline=: 3 : 0 +if. '/' = {.y do. + if. #r=. I. ('/;"',TAB) E. y do. + z=. }.({.r){.y + else. + z=. ,'1' + end. +elseif. '0123456789' e.~ {.y do. + if. #r=. I. (';"',TAB) E. y do. + z=. ({.r){.y + else. + z=. ,'1' + end. +elseif. do. + z=. ,'1' +end. +z +) + +NB. find tags + +NB. ========================================================= +NB. y string or boxed list of tags +NB. x (default 0) if x=1 then include partial matches +tagtag=: 0&$: : (4 : 0) +if. 0=#y=. boxxopen y do. 0$0 return. end. +if. 0=initdone do. loadtags'' end. +if. 0=#tagtags do. 0$0 return. end. +res=. 0$0 +for_t. y do. + if. 1 -.@e. r=. (({.a.),(>t),(0=x)#{.a.) E. tagtags do. continue. end. + res=. res, (I.tagtags={.a.) i. I.r +end. +~.res +) + +NB. tag name from index +tagtagname=: 3 : 0 +'a b'=. (y+i.2){r=. I.tagtags={.a. +(}.a+i.b-a){tagtags +) + +NB. tag file from index +tagfile=: 3 : 0 +'a b'=. (y+i.2){r=. I.tagfiles={.a. +if. 1 e. msk=. '/./' E. r=. (}.a+i.b-a){tagfiles do. + r=. r #~ -. +./ 0 _1 |."0 1 msk NB. simplify /./ to / +end. +r +) + +NB. tag line from index +tagline=: 3 : 0 +'a b'=. (y+i.2){r=. I.taglines={.a. +(}.a+i.b-a){taglines +) + +NB. tagopen open in external editor +NB. x (default 0) index of occurrence as in tagselect +NB. ========================================================= +tagopen=: 0&$: : (4 : 0) +if. 0=#n=. tagtag y do. EMPTY return. end. +file=. tagfile idx=. x{n +if. -.fexist <file do. + smoutput 'not found: ',file + EMPTY return. +end. +xedit_j_ file ; {.file tagss tagline idx +EMPTY +) + +NB. tagselect list matching tags +NB. x (default 0) if x=1 then include partial matches +NB. ========================================================= +tagselect=: 0&$: : (4 : 0) +if. x do. y=. tagcp y end. +if. 0=#n=. tagtag y do. EMPTY return. end. +file=. <@tagfile"0 n +line=. <@(' '&,)@tagline"0 n +> line (>:2*i.#file)}2#(<"1 ":,.i.#file) ,&.> (<' ') ,&.> file +) + +NB. tagcp tag completion +NB. return boxed list of partial matches +NB. ========================================================= +tagcp=: 3 : 0 +if. 0=#n=. 1 tagtag y do. 0$<'' return. end. +/:~ ~. <@tagtagname"0 n +) + +NB. user friendly helper verbs + +NB. jump to tag directly for only one candidate, +NB. otherwise display all candidates and wait for user input +NB. x (default 0) if x=1 then include partial matches +NB. ========================================================= +ta=: 0&$: : (4 : 0) +if. x do. y=. tagcp y end. +if. #a=. tagselect y do. + if. 3>#a do. + tagopen ::0: y + else. + smoutput a + smoutput 'Type number and <Enter> (empty cancels):' + if. '' -.@-: b=. 0". 1!:1]1 do. + ({.b) tagopen ::0: y + end. + end. +end. +EMPTY +) + +NB. do string search +NB. ========================================================= +NB. return 0-base line number or 0$0 if nothing done +tagss=: 4 : 0 +what=. >y [ f=. boxopen x +ind=. 0$0 +if. 0=#what do. ind return. end. +if. '0123456789' e. ~{.what do. <: 0". what return. end. NB. line number + +NB. flag to enable UTF-8 support +rxflag=. RX_OPTIONS_UTF8_jregex_ +RX_OPTIONS_UTF8_jregex_=: 1 + +if. 0=tagss_init what do. ind [ RX_OPTIONS_UTF8_jregex_=: rxflag return. end. + +termLF=. , ((0 < #) # LF -. {:) +tagmatches=. {.@{."2 @ rxmatches_jregex_ +groupndx=. [: <: I. + e.~ + +txt=. freads f +if. -. txt -: _1 do. + ndx=. TAGCOMP tagmatches txt + if. #ndx do. + ind=. ~. (0,}:I. txt = LF) groupndx ndx + end. +end. +rxfree_jregex_ :: 0: TAGCOMP +ind [ RX_OPTIONS_UTF8_jregex_=: rxflag +) + +NB. ========================================================= +tagss_init=: 3 : 0 +NB. no magic except anchors, but \ is \\ in tags file for vi compatibility +anchor1=. '^'={.y [ anchor2=. '$'={:y +y=. ('\/';'/') stringreplace ('\\';'\') stringreplace (anchor1#'^'), '\Q', ((-anchor2)}.anchor1}.y), '\E', (anchor2#'$') +TAGCOMP=: rxcomp_jregex_ :: _1: y +if. TAGCOMP -: _1 do. + rxfree_jregex_ :: 0: TAGCOMP + 0 +else. + 1 +end. +)
new file mode 100644 --- /dev/null +++ b/j/system/main/regex.ijs @@ -0,0 +1,302 @@ +NB. Regular expression pattern matching +NB. +NB. PCRE: Perl-compatible regular expression library +NB. with POSIX interface +NB. +NB. ========================================================= +NB. main definitions: +NB. rxmatch single match +NB. rxmatches all matches +NB. +NB. rxcomp compile pattern +NB. rxfree free pattern handles +NB. rxhandles list pattern handles +NB. rxinfo info on pattern handles +NB. +NB. regex utilities: +NB. rxeq -: +NB. rxin e. +NB. rxindex i. +NB. rxE E. +NB. rxfirst {.@{ (first match) +NB. rxall { (all matches) +NB. rxrplc search and replace +NB. rxapply apply verb to pattern +NB. +NB. rxerror last regex error message +NB. +NB. other utilities: +NB. rxcut cut string into nomatch/match list +NB. rxfrom matches from string +NB. rxmerge replace matches in string +NB. +NB. ========================================================= +NB. Form: +NB. here: pat = pattern, or pattern handle +NB. phnd = pattern handle +NB. patndx = pattern;index or phnd;index +NB. str = character string +NB. bstr = boxed list of str +NB. mat = result of regex search +NB. nsub = #subexpressions in pattern +NB. +NB. mat=. pat or patndx rxmatch str +NB. mat=. pat or patndx rxmatches str +NB. +NB. phnd=. rxcomp pat +NB. empty=. rxfree phnd +NB. phnds=. rxhandles '' +NB. 'nsub pat'=. rxinfo phnd +NB. +NB. boolean=. pat rxeq str +NB. index=. pat rxindex str +NB. mask=. pat rxE str +NB. bstr=. pat rxfirst str +NB. bstr=. pat rxall str +NB. str=. (patndx;new) rxrplc str +NB. str=. patndx (verb rxapply) str +NB. +NB. errormsg=. rxerror '' +NB. +NB. bstr mat rxcut str +NB. bstr=. mat rxfrom str +NB. str=. new (mat rxmerge) str + +NB. ========================================================= +NB. following defined in z: +NB.*rxmatch v single match +NB.*rxmatches v all matches +NB.*rxcomp v compile pattern +NB.*rxfree v free pattern handles +NB.*rxhandles v list pattern handles +NB.*rxinfo v info on pattern handles +NB.*rxeq v regex equivalent of -: +NB.*rxin v regex equivalent of e. +NB.*rxindex v regex equivalent of i. +NB.*rxE v regex equivalent of E. +NB.*rxfirst v regex equivalent of {.@{ (first match) +NB.*rxall v regex equivalent of { (all matches) +NB.*rxrplc v search and replace +NB.*rxapply v apply verb to pattern +NB.*rxerror v last regex error message +NB.*rxcut v cut string into nomatch/match list +NB.*rxfrom v matches from string +NB.*rxmerge v replace matches in string +NB.*rxutf8 v set UTF-8 support 1=on(default), 0=off + +coclass <'jregex' + +NB. ========================================================= +NB. flag to enable UTF-8 support +RX_OPTIONS_UTF8=: 1 + +Rxnna=: '(^|[^[:alnum:]_])' +Rxnnz=: '($|[^[:alnum:]_.:])' +Rxass=: '[[:space:]]*=[.:]' +NB. defs + +NB. ========================================================= +NB. rxdll is in bin or tools/regex +3 : 0'' +select. UNAME +case. 'Win' do. t=. 'jpcre.dll' +case. 'Darwin' do. t=. 'libjpcre.dylib' +case. do. t=. 'libjpcre.so' +end. +f=. BINPATH,'/',t +if. 0 = 1!:4 :: 0: <f do. + f=. jpath '~tools/regex/',t +end. +rxdll=: '"',f,'" ' +) + +rxcdm=: 1 : '(rxdll,x)&(15!:0)' + +NB. ========================================================= +NB. J DLL calls corresponding to the four extended regular expression +NB. functions defined in The Single Unix Specification, Version 2 +jregcomp=: 'regcomp + i *x *c i' rxcdm +jregexec=: 'regexec + i *x *c x *i i' rxcdm +jregerror=: 'regerror + x i * *c x' rxcdm +jregfree=: 'regfree + n *x' rxcdm + +NB. regex + +NB. ========================================================= +NB. Global definitions used by the regex script functions +rxmp=: 50 NB. Allocation granule size for compiled patterns. +rxms=: 50 NB. Maximum number of sub-expressions per pattern. +rxszi=: IF64{4 8 +rxregxsz=: 3 NB. J ints for pcre regex_t +re_nsub_off=: 1 +rxlastrc=: 0 +rxlastxrp=: rxregxsz$2-2 +NB. rxpatterns defined only if not already defined +rxpatterns_jregex_=: (3 0 $ _1 ; rxlastxrp ; '') [^:(0:=#@]) ". 'rxpatterns_jregex_' + +NB. ========================================================= +NB. rxmatch +rxmatch=: 4 : 0 +if. lb=. 32 = 3!:0 x do. ph=. >0{x else. ph=. x end. +if. cx=. 2 = 3!:0 ph do. hx=. rxcomp ph +else. rxlastxrp=: > 1{((hx=. ph) - 1) ({"1) rxpatterns end. +nsub=. rxnsub rxlastxrp +rxlastrc=: >0{rv=. jregexec rxlastxrp ; (,y) ; rxms ; ((2*rxms)$_1 0) ; 0 +if. cx do. rxfree hx end. +m=. (nsub,2)$>4{rv +t=. (0{"1 m) +m=. t,.-~/"1 m +m=. _1 0 ((t=_1)#i.#t)} m +if. lb do. (>1{x){ m else. m end. +) + +NB. ========================================================= +NB. rxmatches +rxmatches=: 4 : 0 +if. lb=. 32 = 3!:0 x do. + ph=. >0{x else. ph=. x end. +if. cx=. 2 = 3!:0 ph do. + hx=. rxcomp ph else. NB. rxcomp sets rxlastxrp + rxlastxrp=: > 1{((hx=. ph) - 1) ({"1) rxpatterns end. +nsub=. rxnsub rxlastxrp +o=. 0 +rxm=. (0, nsub, 2)$0 +while. 1 do. + m=. hx rxmatch o}.y + if. 0 e. $m do. break. end. + if. _1 = 0{0{m do. break. end. + m=. m+ ($m)$o,0 + rxm=. rxm , m +NB. Advance the offset o beyond this match. +NB. The match length can be zero (with the *? operators), +NB. so take special care to advance at least to the next +NB. position. If that reaches beyond the end, exit the loop. + o=. (>:o) >. +/0{m + if. o >: #y do. break. end. +end. +if. cx do. rxfree hx end. +if. lb do. (>1{x){"2 rxm else. rxm end. +) + +NB. ========================================================= +NB. rxcomp +NB. +NB. options rxcomp pattern +rxcomp=: 3 : 0 +'rxlastrc rxlastxrp'=: 2 {. jregcomp (rxregxsz$2-2); (,y); 2 + RX_OPTIONS_UTF8*16b40 +if. rxlastrc do. (rxerror'') 13!:8 [12 end. +if. ({:$rxpatterns) = hx=. (<_1) i.~ 0 { rxpatterns do. + rxpatterns=: rxpatterns ,. (rxmp$<_1),(rxmp$<rxregxsz$2-2), ,:rxmp$<'' +end. +rxpatterns=: ((hx+1);rxlastxrp;y) (<a:;hx)} rxpatterns +hx + 1 +) + +NB. ========================================================= +rxnsub=: [: >: 1&{ NB. Number of main+sub-expressions from Perl regex_t + +NB. ========================================================= +NB. rxerror +rxerror=: 3 : 0 +r=. >3{jregerror rxlastrc;rxlastxrp;(80#' ');80 +({.~ i.&(0{a.)) r +) + +NB. ========================================================= +rxfree=: 3 : 0 +hx=. ,y - 1 +while. 0<#hx do. + ix=. 0{hx + jregfree 1{ix ({"_1) rxpatterns + rxpatterns=: ((<_1),(<rxregxsz$2-2),<'') (<(<$0);ix)} rxpatterns + hx=. }.hx +end. +i.0 0 +) + +NB. ========================================================= +NB. rxhandles +rxhandles=: 3 : 0 +h=. >0{rxpatterns +(h~:_1)#h +) + +NB. ========================================================= +NB. rxinfo +rxinfo=: 3 : 0 +i=. (y-1){"1 rxpatterns +|:(<"_1 rxnsub >1{i) ,: 2{i +) + +NB. ========================================================= +NB. rxfrom=: <@({~ (+ i.)/)"1~ +rxfrom=: ,."1@[ <;.0 ] +rxeq=: {.@rxmatch -: 0: , #@] +rxin=: _1: ~: {.@{.@rxmatch +rxindex=: #@] [^:(<&0@]) {.@{.@rxmatch +rxE=: i.@#@] e. {.@{."2 @ rxmatches +rxfirst=: {.@rxmatch >@rxfrom ] +rxall=: {."2@rxmatches rxfrom ] + +NB. ========================================================= +rxapply=: 1 : 0 +: +if. L. x do. 'pat ndx'=. x else. pat=. x [ ndx=. ,0 end. +if. 1 ~: #$ ndx do. 13!:8[3 end. +mat=. ({.ndx) {"2 pat rxmatches y +r=. u&.> mat rxfrom y +r mat rxmerge y +) + +NB. ========================================================= +rxcut=: 4 : 0 +if. 0 e. #x do. <y return. end. +'beg len'=. |: ,. x +if. 1<#beg do. + whilst. 0 e. d do. + d=. 1,<:/\ (}:len) <: 2 -~/\ beg + beg=. d#beg + len=. d#len + end. +end. +a=. 0, , beg ,. beg+len +b=. 2 -~/\ a, #y +f=. < @ (({. + i.@{:)@[ { ] ) +(}: , {: -. a:"_) (a,.b) f"1 y +) + +NB. ========================================================= +rxmerge=: 1 : 0 +: +p=. _2 ]\ m rxcut y +;, ({."1 p),.(#p){.(#m)$x +) + +NB. ========================================================= +rxrplc=: 4 : 0 +pat=. >{.x +new=. {:x +if. L. pat do. 'pat ndx'=. pat else. ndx=. ,0 end. +if. 1 ~: #$ ndx do. 13!:8[3 end. +mat=. ({.ndx) {"2 pat rxmatches y +new mat rxmerge y +) + +NB. ========================================================= +NB. set UTF-8 support on/off +NB. result is previous setting +rxutf8=: 3 : 0 +(RX_OPTIONS_UTF8=: y) ] RX_OPTIONS_UTF8 +) +NB. zdefs + +NB. ========================================================= +NB. define z locale names: +nms=. 0 : 0 +rxmatch rxmatches rxcomp rxfree rxhandles rxinfo rxeq +rxin rxindex rxE rxfirst rxall rxrplc rxapply rxerror +rxcut rxfrom rxmerge rxutf8 +) + +nms=. (nms e.' ',LF) <;._2 nms +". > nms ,each (<'_z_=:') ,each nms ,each <'_jregex_'
new file mode 100644 --- /dev/null +++ b/j/system/main/socket.ijs @@ -0,0 +1,383 @@ +coclass <'jsocket' +coinsert 'jsocket jdefs' + +jsystemdefs 'hostdefs' +jsystemdefs 'netdefs' +3 : 0'' +assert. INADDR_ANY=0 +assert. sockaddr_sz=16 +if. IFUNIX do. + assert. fds_bits_off=0 +end. +) +3 : 0'' +select. UNAME +case. 'Win' do. + c=. >IFWINCE{'wsock32';'winsock' + ccdm=: 1 : ('(''"',c,,'" '',x)&(15!:0)') + ncdm=: ccdm + scdm=: ccdm + wcdm=: ccdm + LIB=: '' + closesocketJ=: 'closesocket i i' scdm + ioctlsocketJ=: 'ioctlsocket i i i *i' scdm +case. 'Linux' do. + c=. 'libc.so.6' + ccdm=: 1 : ('(''"',c,'" '',x)&(15!:0)') + ncdm=: ccdm + scdm=: ccdm + wcdm=: 1 : ']' + LIB=: c + closesocketJ=: 'close i i' scdm + ioctlsocketJ=: 'ioctl i i i *i' scdm +case. 'Darwin' do. + c=. 'libc.dylib' + ccdm=: 1 : ('(''"',c,'" '',x)&(15!:0)') + ncdm=: ccdm + scdm=: ccdm + wcdm=: 1 : ']' + LIB=: c + closesocketJ=: 'close i i' scdm + ioctlsocketJ=: 'ioctl i i i *i' scdm +case. 'SunOS' do. + c=. find_dll 'c' + ccdm=: 1 : ('(''"',c,'" '',x)&(15!:0)') + n=. find_dll 'nsl' + ncdm=: 1 : ('(''"',n,'" '',x)&(15!:0)') + s=. find_dll 'socket' + scdm=: 1 : ('(''"',s,'" '',x)&(15!:0)') + wcdm=: 1 : ']' + LIB=: c + closesocketJ=: 'close i i' scdm + ioctlsocketJ=: 'ioctl i i i *i' scdm +end. +empty'' +) +gethostbyaddrJ=: 'gethostbyaddr * * i i' ncdm +gethostbynameJ=: 'gethostbyname * *c' ncdm +gethostnameJ=: 'gethostname i *c i' ncdm +inet_addrJ=: 'inet_addr i *c' ncdm +inet_ntoaJ=: 'inet_ntoa i i' ncdm +acceptJ=: 'accept i i * *i' scdm +acceptNullJ=: 'acceptNull i i *c *c' scdm +bindJ=: 'bind i i * i' scdm +connectJ=: 'connect i i * i' scdm +FD_ISSETJ=: 'FD_ISSET i i ' scdm +getpeernameJ=: 'getpeername i i * *i' scdm +getprotobynameJ=: 'getprotobyname i *c' scdm +getprotobynumberJ=: 'getprotobynumber i i' scdm +getservbynameJ=: 'getservbyname i i i' scdm +getservbyportJ=: 'getservbyport i i i' scdm +getsocknameJ=: 'getsockname i i * *i' scdm +getsockoptJ=: 'getsockopt i i i i * *i' scdm +htonlJ=: 'htonl i i' scdm +htonsJ=: 'htons s s' scdm +listenJ=: 'listen i i i' scdm +ntohlJ=: 'ntohl i i' scdm +ntohsJ=: 'ntohs s s' scdm +recvJ=: 'recv i i * i i' scdm +recvfromJ=: 'recvfrom i i *c i i * *i' scdm +selectJ=: 'select i i * * * *' ccdm +sendJ=: 'send i i *c i i' scdm +sendtoJ=: 'sendto i i *c i i * i' scdm +setsockoptJ=: 'setsockopt i i i i * i' scdm +shutdownJ=: 'shutdown i i i' scdm +socketJ=: 'socket i i i i' scdm + +WSAAsyncGetHostByAddrJ=: 'WSAAsyncGetHostByAddr i i i i i i i i' wcdm +WSAAsyncGetHostByNameJ=: 'WSAAsyncGetHostByName i i i *c i i' wcdm +WSAAsyncGetProtoByNameJ=: 'WSAAsyncGetProtoByName i i i *c i i' wcdm +WSAAsyncGetProtoByNumberJ=: 'WSAAsyncGetProtoByNumber i i i i i i' wcdm +WSAAsyncGetServByNameJ=: 'WSAAsyncGetServByName i i i *c *c i i' wcdm +WSAAsyncGetServByPortJ=: 'WSAAsyncGetServByPort i i i i *c i i' wcdm +WSAAsyncSelectJ=: 'WSAAsyncSelect i i i i i' wcdm +WSACancelAsyncRequestJ=: 'WSACancelAsyncRequest i i' wcdm +WSACancelBlockingCallJ=: 'WSACancelBlockingCall i ' wcdm +WSACleanupJ=: 'WSACleanup i ' wcdm +WSAGetLastErrorJ=: 'WSAGetLastError i ' wcdm +WSAIsBlockingJ=: 'WSAIsBlocking i ' wcdm +WSASetBlockingHookJ=: 'WSASetBlockingHook i i' wcdm +WSASetLastErrorJ=: 'WSASetLastError i i' wcdm +WSAStartupJ=: 'WSAStartup i i *' wcdm +WSAStringToAddressJ=: 'WSAStringToAddress i c i i i i' wcdm +WSAUnhookBlockingHookJ=: 'WSAUnhookBlockingHook i ' wcdm +x_WSAFDIsSetJ=: 'x_WSAFDIsSet i i i' wcdm + +sderror=: 3 : 0 +'num msg'=. SDERRORS +> (num i. >{.y) { msg, <'unknown error' +) +j=. <;._2 (0 : 0) + 0 no error +10004 EINTR +10009 EBADF +10011 EAGAIN +10013 EACCES +10014 EFAULT +10022 EINVAL +10024 EMFILE +10035 EWOULDBLOCK +10036 EINPROGRESS +10037 EALREADY +10038 ENOTSOCK +10039 EDESTADDRREQ +10040 EMSGSIZE +10041 EPROTOTYPE +10042 ENOPROTOOPT +10043 EPROTONOSUPPORT +10044 ESOCKTNOSUPPORT +10045 EOPNOTSUPP +10046 EPFNOSUPPORT +10047 EAFNOSUPPORT +10048 EADDRINUSE +10049 EADDRNOTAVAIL +10050 ENETDOWN +10051 ENETUNREACH +10052 ENETRESET +10053 ECONNABORTED +10054 ECONNRESET +10055 ENOBUFS +10056 EISCONN +10057 ENOTCONN +10058 ESHUTDOWN +10059 ETOOMANYREFS +10060 ETIMEDOUT +10061 ECONNREFUSED +10062 ELOOP +10063 ENAMETOOLONG +10064 EHOSTDOWN +10065 EHOSTUNREACH +10066 ENOTEMPTY +10067 EPROCLIM +10068 EUSERS +10069 EDQUOT +10070 ESTALE +10071 EREMOTE +10091 SYSNOTREADY +10092 VERNOTSUPPORTED +10093 NOTINITIALISED +10098 EADDRINUSE +10101 EDISCON +11001 HOST_NOT_FOUND +11002 TRY_AGAIN +11003 NO_RECOVERY +11004 NO_DATA +) + +SDERRORS=: (0 ". 5 {. &> j) ; < 6 }.each j +SDERRORS=: ((10000*IFUNIX) | >{.SDERRORS);{:SDERRORS + +tostring=: 3 : 0 +}: ;'.',~each ":each a.i.y +) + +data2string=: 3 : 0 +tostring 4{.4}.2{::y +) + +namesub=: 3 : 0 +if. 0~:res y do. (sdsockerror'');0;'';0 return. end. +0;AF_INET;(data2string y);256#.a.i.2 3{2{::y +) + +flip=: 'a'={.2 ic a.i.'a' +bigendian=: |.^:flip +hns=: 3 : 'a.{~256 256#:y' +hs=: 3 : 'bigendian a.{~256 256#:y' +res=: >@:{. + +sockaddr_in=: 3 : 0 +'s fam host port'=. y +assert. fam=AF_INET +if. 0=#host do. host=. '0.0.0.0' end. +(hs AF_INET),(hns port),(afroms host),8#{.a. +) + +sockaddr_split=: 3 : 0 +'fam port host'=. 1 0 1 0 1 0 0 0 <;.1 (8){.y +assert. AF_INET = 256 256 #. a. i. bigendian fam +port=. 256 256 #. a. i. port +host=. }. , sfroma "0 host +host;port +) + +sfroma=: 3 : 0 +'.',": a. i. y +) +afroms=: 3 : 0 +a.{~4{.".each '.' cutopen y +) +rc0=: 3 : 0 +if. 0=>{.y do. 0 else. sdsockerror'' end. +) + +sdsockaddress=: 3 : 0"0 +r=. getsocknameJ y;(sockaddr_in_sz#{.a.);,sockaddr_in_sz +(rc0 r);data2string r +) +sdsend=: 4 : 0"1 +r=. >{.sendJ (>0{y);x;(#x);>1{y +if. _1=r do. 0;~sdsockerror'' else. 0;r end. +) +sdsendto=: 4 : 0"1 +if. 3 = #y do. + 's flags saddr'=. y + r=. >{.sendtoJ s;x;(#x);flags;saddr;sockaddr_in_sz +else. + 's flags family address port'=. y + r=. >{.sendtoJ s;x;(#x);flags;(sockaddr_in 0 2 3 4{y);sockaddr_in_sz +end. +if. _1=r do. 0;~sdsockerror'' else. 0;r end. +) + +sdcleanup=: 3 : '0[sdclose SOCKETS_jsocket_' +sdinit=: 3 : 0 +if. 0=nc<'SOCKETS_jsocket_' do. 0 return. end. +SOCKETS_jsocket_=: '' +if. IFUNIX do. 0 return. end. +if. 0~:res WSAStartupJ 257;1000$' ' do. _1[mbinfo'Socket Error' else. 0 end. +) +sdrecv=: 3 : 0"1 +'s size'=. 2{.y +r=. recvJ s;(size#' ');size;2{3{.y +if. 0>c=. res r do. '';~sdsockerror'' return. end. +0;c{.>2{r +) +sdrecvfrom=: 3 : 0"1 +'s size flags'=. 3 {. y ,<0 +s=. {.s +r=. recvfromJ s;(size#' ');size;flags;(sockaddr_in_sz#{.a.);,sockaddr_in_sz +'unexpected size of peer address' assert sockaddr_in_sz = 6 pick r +if. 0>c=. res r do. (sdsockerror '');'';'' return. end. +0;(c{.>2{r); 5{r +) +sdconnect=: 3 : 0"1 +rc0 connectJ (>{.y);(sockaddr_in y);sockaddr_in_sz +) +sdsocket=: 3 : 0"1 +s=. res socketJ <"0 [3{.y,(0=#y)#PF_INET,SOCK_STREAM,IPPROTO_TCP +if. s=_1 do. 0;~sdsockerror'' return. end. +SOCKETS_jsocket_=: SOCKETS_jsocket_,s +0;s +) +sdbind=: 3 : 0"1 +rc0 bindJ (>{.y);(sockaddr_in y);sockaddr_in_sz +) +sdasync=: 3 : 0"0 +if. IFUNIX do. 'not implemented under Unix - please use sdselect' assert 0 end. +flags=. OR/ FD_READ,FD_WRITE,FD_OOB,FD_ACCEPT,FD_CONNECT,FD_CLOSE +hwnd=. ".wd'qhwndx' +if. >{.WSAAsyncSelectJ ({.y);hwnd;1026;flags do. sdsockerror '' else. 0 end. +) +sdlisten=: 3 : 0"1 +rc0 listenJ ;/2 {. y,<^:(L.y) SOMAXCONN +) +sdaccept=: 3 : 0"0 +if. _1~:s=. res r=. acceptJ y;(sockaddr_in_sz$' ');,sockaddr_in_sz do. + SOCKETS_jsocket_=: SOCKETS_jsocket_,s + 0;s +else. 0;~sdsockerror '' end. +) +sdgethostbyname=: 3 : 0 +if. 0~:hostent=. res gethostbynameJ <y do. + addr_list=. memr hostent, h_addr_list_off, 1, JPTR + first_addr=. memr addr_list, 0, 1, JPTR + 'name did not resolve to address' assert first_addr ~: 0 + addr=. tostring memr first_addr,0,4 +else. + addr=. '255.255.255.255' +end. +0;PF_INET;addr +) +sdgethostbyaddr=: 3 : 0"1 +'fam addr'=. y +phe=. res gethostbyaddrJ (afroms addr);4;fam +if. phe=0 do. _1;'unknown host' return. end. +a=. memr phe,h_name_off,1,JPTR +0;memr a,0,JSTR +) +sdclose=: 3 : 0"0 +if. 0=res closesocketJ <y do. + 0[SOCKETS_jsocket_=: SOCKETS_jsocket_-.y +else. + sdsockerror '' +end. +) +fdset_bytes=: 4 : 0 +bitvector=. 1 y} (x*8)#0 +bytes=. a. {~ _8 #.@|.\ bitvector +if. -.flip do. bytes=. , _4 |.\ bytes end. +bytes +) +fdset_fds=: 3 : 0 +bytes=. y +if. -.flip do. bytes=. , _4 |.\ bytes end. +bitvec=. , _8 |.\ , (8#2)&#: a. i. bytes +I. bitvec +) +sdselect=: 3 : 0 +if. 0=#y do. y=. SOCKETS_jsocket_;SOCKETS_jsocket_;SOCKETS_jsocket_;0 end. +'r w e t'=. y +time=. <<.1000000 1000000#:1000*t +if. IFUNIX do. + max1=. >:>./r,w,e,0 + m=. 4 + n=. 32 + bytes=. m*>:<.n%~max1 + r=. bytes fdset_bytes r + w=. bytes fdset_bytes w + e=. bytes fdset_bytes e + rwe=. r;w;e +else. + max1=. 0 + rwe=. (] ,~ #) each r;w;e +end. +if. _1=res q=. selectJ (<max1),rwe,time do. + (sdsockerror '');($0);($0);($0) +else. + if. IFUNIX do. rwe=. fdset_fds each 2 3 4{q else. rwe=. ({.{.}.)each 2 3 4{q end. + (<0),rwe +end. +) +sdgetsockopt=: 3 : 0 +'s lev name'=. y +r=. getsockoptJ s;lev;name;(,0);,4 +if. 0~:res r do. 0;~sdsockerror'' return. end. +d=. ''$>4{r +if. name-:SO_LINGER do. 0;65536 65536#:d else. 0;d end. +) +sdsetsockopt=: 3 : 0 +'s lev name val'=. y +if. name -: SO_LINGER do. val=. 65536 65536#.val end. +rc0 setsockoptJ s;lev;name;(,val);4 +) +sdsockerror=: 3 : 0 +> {. cderx '' +) +sdioctl=: 3 : 0 +'s option value'=. y +r=. ioctlsocketJ s;option;,value +if. 0~:res r do. 0;~sdsockerror'' else. 0;''$>3{r end. +) +sdionread=: 3 : 0 +''$>{.sdcheck sdioctl y,FIONREAD,0 +) +sdgethostname=: 3 : 0 +if. 0=res r=. gethostnameJ (256#' ');256 do. + 0;>{.1 take (0{a.)cutopen ;1{r +else. + 0;'unknown host' +end. +) +sdgetpeername=: 3 : 0"0 +namesub getpeernameJ y;(sockaddr_in_sz#{.a.);,sockaddr_in_sz +) +sdgetsockname=: 3 : 0"0 +namesub getsocknameJ y;(sockaddr_in_sz#{.a.);,sockaddr_in_sz +) + +sdgetsockets=: 3 : '0;SOCKETS_jsocket_' +sdcheck=: }. ` (sderror 13!:8 3:) @. (0 ~: >@{.) +INVALID_SOCKET=: 1 +SOCKET_ERROR=: _1 +sdinit''
new file mode 100644 --- /dev/null +++ b/j/system/main/stdlib.ijs @@ -0,0 +1,2007 @@ +18!:4 <'z' +3 : 0 '' + +notdef=. 0: ~: 4!:0 @ < +jpathsep=: '/'&(('\' I.@:= ])}) +winpathsep=: '\'&(('/' I.@:= ])}) +PATHJSEP_j_=: '/' +IF64=: 16={:$3!:3[2 +'IFUNIX IFWIN IFWINCE'=: 5 6 7 = 9!:12'' +IFGTK=: IFJHS=: 0 +IFJ6=: 0 +IFWINE=: IFWIN > 0-:2!:5'_' +if. IFUNIX do. + UNAME=: (2!:0 'uname')-.10{a. +else. + UNAME=: 'Win' +end. +) +jcwdpath=: (1!:43@(0&$),])@jpathsep@((*@# # '/'"_),]) +jsystemdefs=: 3 : 0 +0!:0 <jpath '~system/defs/',y,'_',(tolower UNAME),(IF64#'_64'),'.ijs' +) +18!:4 <'z' +'TAB LF FF CR DEL EAV'=: 9 10 12 13 127 255{a. +LF2=: LF,LF +CRLF=: CR,LF +EMPTY=: i.0 0 +Debug=: 0 +'noun adverb conjunction verb monad dyad'=: 0 1 2 3 3 4 +apply=: 128!:2 +def=: : +define=: : 0 +do=: ". +drop=: }. +each=: &.> +echo=: 0 0&$ @ (1!:2&2) +exit=: 2!:55 +every=: &> +getenv=: 2!:5 +inv=: inverse=: ^:_1 +items=: "_1 +fetch=: {:: +leaf=: L:0 +nameclass=: nc=: 4!:0 +namelist=: 4!:1 +on=: @: +pick=: >@{ +rows=: "1 +stdout=: 1!:2&4 +stderr=: 1!:2&5 +stdin=: 1!:1@3: :. stdout +sign=: * +sort=: /:~ : /: +take=: {. +assert=: 0 0 $ 13!:8^:((0 e. ])`(12"_)) +bind=: 2 : 'x@(y"_)' +boxopen=: <^:(L.=0:) +boxxopen=: <^:(L.<*@#) +clear=: 3 : 0 +". 'do_',(' '-.~y),'_ '' (#~ -.@(4!:55)) (4!:1) 0 1 2 3''' +) +cutLF=: 3 : 'if. L. y do. y else. a: -.~ <;._2 y,LF end.' +cutopen=: 3 : 0 +y cutopen~ (' ',LF) {~ LF e. ,y +: +if. L. y do. y return. end. +if. 1 < #$y do. <"_1 y return. end. +(<'') -.~ (y e.x) <;._2 y=. y,1{.x +) +datatype=: 3 : 0 +n=. 1 2 4 8 16 32 64 128 1024 2048 4096 8192 16384 32768 65536 131072 +t=. '/boolean/literal/integer/floating/complex/boxed/extended/rational' +t=. t,'/sparse boolean/sparse literal/sparse integer/sparse floating' +t=. t,'/sparse complex/sparse boxed/symbol/unicode' +(n i. 3!:0 y) pick <;._1 t +) +empty=: EMPTY"_ +erase=: [: 4!:55 ;: ::] +expand=: # inverse +H=. '0123456789ABCDEF' +h=. '0123456789abcdef' +dfh=: 16 #. 16 | (H,h) i. ] +hfd=: h {~ 16 #.^:_1 ] +isutf8=: 1:@(7&u:) :: 0: +list=: 3 : 0 +w=. {.wcsize'' +w list y +: +if. 0=#y do. i.0 0 return. end. +if. 2>#$y=. >y do. + d=. (' ',LF) {~ LF e. y=. toJ ": y + y=. [;._2 y, d #~ d ~: {: y +end. +y=. y-. ' '{.~ c=. {:$ y=. (": y),.' ' +(- 1>. <. x % c) ;\ <"1 y +) +nl=: 3 : 0 +'' nl y +: +if. 0 e. #y do. y=. 0 1 2 3 end. + +if. 1 4 8 e.~ 3!:0 y do. + nms=. (4!:1 y) -. ;: 'x y x. y.' +else. + nms=. cutopen_z_ y +end. + +if. 0 e. #nms do. return. end. + +if. #t=. x -. ' ' do. + 'n s'=. '~*' e. t + t=. t -. '~*' + b=. t&E. &> nms + if. s do. b=. +./"1 b + else. b=. {."1 b end. + nms=. nms #~ n ~: b +end. +) +names=: list_z_ @ nl +Note=: 3 : '0 0 $ 0 : 0' : [ +script=: [: 3 : '0!:0 y [ 4!:55<''y''' jpath_z_ &.: > +scriptd=: [: 3 : '0!:1 y [ 4!:55<''y''' jpath_z_ &.: > +sminfo=: 3 : 0 +if. IFGTK do. mbinfo_jgtk_ y else. smoutput >_1{.boxopen y end. +) +smoutput=: 0 0 $ 1!:2&2 +tmoutput=: 0 0 $ 1!:2&4 +split=: {. ,&< }. +table=: 1 : 0~ +: +(((#~LF-.@e.])5!:5<'u');,.y),.({.;}.)":x,y u/x +) +timex=: 6!:2 +timespacex=: 6!:2 , 7!:2@] +tolower=: 3 : 0 +x=. I. 26 > n=. ((65+i.26){a.) i. t=. ,y +($y) $ ((x{n) { (97+i.26){a.) x}t +) + +toupper=: 3 : 0 +x=. I. 26 > n=. ((97+i.26){a.) i. t=. ,y +($y) $ ((x{n) { (65+i.26){a.) x}t +) +t=. <;._1 '/invalid name/not defined/noun/adverb/conjunction/verb/unknown' +type=: {&t@(2&+)@(4!:0)&boxopen +ucp=: 7&u: +ucpcount=: # @ (7&u:) +utf8=: 8&u: +uucp=: u:@(7&u:) +3 : 0'' +h=. 9!:12'' +subs=. 2 : 'x I. @(e.&y)@]} ]' +toJ=: (LF subs CR) @: (#~ -.@(CRLF&E.@,)) +toCRLF=: 2&}. @: ; @: (((CR&,)&.>)@<;.1@(LF&,)@toJ) +if. h=5 do. + toHOST=: ] +else. + toHOST=: toCRLF +end. +1 +) +18!:4 <'z' + +coclass=: 18!:4 @ boxxopen +cocreate=: 18!:3 +cocurrent=: 18!:4 @ boxxopen +codestroy=: coerase @ coname +coerase=: 18!:55 +cofullname=: 3 : 0 +y=. ,> y +if. #y do. + if. ('_' = {: y) +: 1 e. '__' E. y do. + y,'_',(>18!:5''),'_' + end. +end. +) +coinsert=: 3 : 0 +n=. ;: :: ] y +p=. ; (, 18!:2) @ < each n +p=. ~. (18!:2 coname''), p +(p /: p = <,'z') 18!:2 coname'' +) +coname=: 18!:5 +conames=: list_z_ @ conl +conew=: 3 : 0 +c=. <y +obj=. cocreate'' +coinsert__obj c +COCREATOR__obj=: coname'' +obj +: +w=. conew y +create__w x +w +) +conl=: 18!:1 @ (, 0 1"_ #~ # = 0:) +copath=: 18!:2 & boxxopen +coreset=: 3 : 0 +if. IFGTK do. + a=. <'jgtkide' + exc=. locEdits__a,locTerm__a,locFif__a,locFiw__a +else. + exc=. '' +end. +0 0$coerase (conl 1) -. exc +) +cocurrent 'z' +cofind=: 3 : 0 +r=. (<,>y) (4 : 'try. x e. nl__y $0 catch. 0 end.'"0 # ]) 18!:1]0 1 +if. 0=#r do. i.0 2 end. +) +cofindv=: 3 : 0 +lcs=. cofind y +if. #lcs do. + lcs ,. ". each (<y,'_') ,each lcs ,each '_' +end. +) +coinfo=: 3 : 0 +ref=. boxxopen y +if. 0 e. $ref do. i.0 4 return. end. +if. 0=4!:0 <'COCREATOR__ref' +do. c=. COCREATOR__ref else. c=. a: end. +(conouns ref),ref,c,< ;:inverse copath ref +) +conouns=: 3 : 0 "0 +n=. nl 0 +t=. n#~ (<y)-:&> ".each n +< ;: inverse t +) +conounsx=: 3 : 0 +r=. '' +if. #y do. + s=. #y=. boxxopen y + loc=. conl 0 + for_i. loc do. r=. r,conouns__i y end. + r=. (r~:a:) # (y$~#r),.r,.s#loc +end. +/:~~.r +) +copathnl=: 3 : 0 +'' copathnl y +: +r=. '' +t=. (coname''),copath coname'' +for_i. t -. <,'z' do. + r=. r,x nl__i y +end. +/:~~.r +) +copathnlx=: 3 : 0 +'' copathnlx y +: +r=. '' +t=. (coname''),copath coname'' +for_i. t=. t -. <,'z' do. + r=. r,<x nl__i y +end. +n=. ~.;r +n,.|:( n&e. &> r) #each t +) +coselect_result=: 3 : 0 +'r x s'=. y +if. r do. + runimmx0_jijs_ '18!:4 <''',s,'''' +end. +empty'' +) +costate=: 3 : 0 +r=. ,: ;:'refs id creator path' +if. #n=. conl 1 do. r,coinfo &> n /: 0 ".&> n end. +) +cocurrent 'z' +cd=: 15!:0 +memr=: 15!:1 +memw=: 15!:2 +mema=: 15!:3 +memf=: 15!:4 +cdf=: 15!:5 +cder=: 15!:10 +cderx=: 15!:11 +gh=. 15!:8 +fh=. 15!:9 +symget=: 15!:6 +symset=: 15!:7 +cdcb=: 15!:13 +JB01=: 1 +JCHAR=: 2 +JSTR=: _1,JCHAR +JINT=: 4 +JPTR=: JINT +JFL=: 8 +JCMPX=: 16 +JBOXED=: 32 +JTYPES=: JB01,JCHAR,JINT,JPTR,JFL,JCMPX,JBOXED +JSIZES=: >IF64{1 1 4 4 8 16 4;1 1 8 8 8 16 8 +ic=: 3!:4 +fc=: 3!:5 +endian=: |.^:('a'={.2 ic a.i.'a') +AND=: $:/ : (17 b.) +OR=: $:/ : (23 b.) +XOR=: $:/ : (22 b.) +cocurrent 'z' +3 : 0 '' +if. -. (UNAME-:'Darwin')+.(UNAME-:'SunOS') do. DLL_PATH=: '' return. end. +llp=. 2!:5 'LD_LIBRARY_PATH',~'DY'#~UNAME-:'Darwin' +if. 0 -: llp do. llp=. '' end. +def_path=. ':/usr/local/lib:/usr/lib:/usr/lib/ccs/lib:/etc/lib:/lib' +DLL_PATH=: a: -.~ <;._1 ':',llp,def_path +) +find_dll=: 3 : 0 +DLL_PATH find_dll y +: +if. UNAME-:'Linux' do. ('find_dll decommitted') 13!:8 ] 24 end. +if. -.IFUNIX do. y return. end. +y=. ,y +if. (UNAME-:'Darwin') do. ext=. '.dylib*' else. ext=. '.so*' end. +for_dir. x do. + l=. (>dir), '/lib', y, ext + if. # fns=. \:~ 1!: 0 l do. + (>dir), '/', > (<0 0) { fns + return. + end. +end. +('could not locate dll ',y) 13!:8 ] 24 +) +break=: 3 : 0 +class=. >(0=#y){y;'default' +p=. 9!:46'' +q=. (>:p i: '/'){.p +fs=. (<q),each {."1[1!:0<q,'*.',class +fs=. fs-.<p +for_f. fs do. + v=. 2<.>:a.i.1!:11 f,<0 1 + (v{a.) 1!:12 f,<0 +end. +i.0 0 +) +setbreak=: 3 : 0 +p=. jpath '~break/' +1!:5 ::] <p +f=. p,(":2!:6''),'.',y +({.a.) 1!:12 f;0 +9!:47 f +f +) +cocurrent 'z' +calendar=: 3 : 0 +0 calendar y +: +a=. ((j<100)*(-100&|){.6!:0'')+j=. {.y +b=. (a-x)+-/<.4 100 400%~<:a +r=. 28+3,(~:/0=4 100 400|a),10$5$3 2 +r=. (-7|b+0,+/\}:r)|."0 1 r(]&:>:*"1>/)i.42 +m=. (<:}.y),i.12*1=#y +h=. 'JanFebMarAprMayJunJulAugSepOctNovDec' +h=. ((x*3)|.' Su Mo Tu We Th Fr Sa'),:"1~_3(_12&{.)\h +<"2 m{h,"2[12 6 21 ($,) r{' ',3":1+i.31 1 +) +getdate=: 3 : 0 +0 getdate y +: +r=. '' +opt=. x +chr=. [: -. [: *./ e.&'0123456789 ' +dat=. ' ' (I. y e.',-/:') } y + +if. chr dat do. + opt=. 0 + dat=. a: -.~ <;._1 ' ',dat + if. 1=#dat do. r return. end. + typ=. chr &> dat + dat=. (2{.typ{dat),{:dat + mth=. 3{.>1{dat + uc=. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + lc=. 'abcdefghijklmnopqrstuvwxyz' + mth=. (lc,a.) {~ mth i.~ uc,a. + mos=. _3[\'janfebmaraprmayjunjulaugsepoctnovdec' + mth=. <": >:mos i. mth + dat=. ;' ',each mth 1 } dat +end. + +dat=. ". :: (''"_) dat +if. 0 e. #dat do. return. end. + +if. 3 ~: #dat do. r return. end. + +if. 31 < {.dat do. 'y m d'=. dat +else. ((opt|.'d m '),' y')=. dat +end. + +if. y<100 do. + y=. y + (-100&|) {. 6!:0'' +end. + +(#~ valdate) y,m,d +) +isotimestamp=: 3 : 0 +r=. }: $y +t=. _6 [\ , 6 {."1 y +d=. '--b::' 4 7 10 13 16 }"1 [ 4 3 3 3 3 3 ": <.t +d=. d ,. }."1 [ 0j3 ": ,. 1 | {:"1 t +c=. {: $d +d=. ,d +d=. '0' (I. d=' ')} d +d=. ' ' (I. d='b')} d +(r,c) $ d +) +todate=: 3 : 0 +0 todate y +: +s=. $y +a=. 657377.75 +, y +d=. <. a - 36524.25 * c=. <. a % 36524.25 +d=. <.1.75 + d - 365.25 * y=. <. (d+0.75) % 365.25 +r=. (1+12|m+2) ,: <. 0.41+d-30.6* m=. <. (d-0.59) % 30.6 +r=. s $ |: ((c*100)+y+m >: 10) ,r +if. x do. r=. 100 #. r end. +r +) +todayno=: 3 : 0 +0 todayno y +: +a=. y +if. x do. a=. 0 100 100 #: a end. +a=. ((*/r=. }: $a) , {:$a) $,a +'y m d'=. <"_1 |: a +y=. 0 100 #: y - m <: 2 +n=. +/ |: <. 36524.25 365.25 *"1 y +n=. n + <. 0.41 + 0 30.6 #. (12 | m-3),"0 d +0 >. r $ n - 657378 +) +tsdiff=: 4 : 0 +r=. -/"2 d=. _6 (_3&([\)) \ ,x,"1 y +if. #i=. i#i.#i=. 0 > 2{"1 r do. + j=. (-/0=4 100 400 |/ (<i;1;0){d)* 2=m=. (<i;1;1){d + j=. _1,.j + m{0 31 28 31 30 31 30 31 31 30 31 30 31 + n=. <i;1 2 + r=. (j + n{r) n } r +end. +r +/ . % 1 12 365 +) +tsrep=: 3 : 0 +0 tsrep y +: +if. x do. + r=. $y + 'w n t'=. |: 0 86400 1000 #: ,y + w=. w + 657377.75 + d=. <. w - 36524.25 * c=. <. w % 36524.25 + d=. <.1.75 + d - 365.25 * w=. <. (d+0.75) % 365.25 + s=. (1+12|m+2) ,: <. 0.41+d-30.6* m=. <. (d-0.59) % 30.6 + s=. |: ((c*100)+w+m >: 10) ,s + r $ s,. (_3{. &> t%1000) +"1 [ 0 60 60 #: n +else. + a=. ((*/r=. }: $y) , {:$y) $, y + 'w m d'=. <"_1 |: 3{."1 a + w=. 0 100 #: w - m <: 2 + n=. +/ |: <. 36524.25 365.25 *"1 w + n=. n + <. 0.41 + 0 30.6 #. (12 | m-3),"0 d + s=. 3600000 60000 1000 +/ .*"1 [ 3}."1 a + r $ s+86400000 * n - 657378 +end. +) +timestamp=: 3 : 0 +if. 0 = #y do. w=. 6!:0'' else. w=. y end. +r=. }: $ w +t=. 2 1 0 3 4 5 {"1 [ _6 [\ , 6 {."1 <. w +d=. '+++::' 2 6 11 14 17 }"1 [ 2 4 5 3 3 3 ": t +mth=. _3[\' JanFebMarAprMayJunJulAugSepOctNovDec' +d=. ,((1 {"1 t) { mth) 3 4 5 }"1 d +d=. '0' (I. d=' ') } d +d=. ' ' (I. d='+') } d +(r,20) $ d +) + +tstamp=: timestamp +valdate=: 3 : 0 +s=. }:$y +'w m d'=. t=. |:((*/s),3)$,y +b=. *./(t=<.t),(_1 0 0<t),12>:m +day=. (13|m){0 31 28 31 30 31 30 31 31 30 31 30 31 +day=. day+(m=2)*-/0=4 100 400|/w +s$b*d<:day +) +weekday=: 7 | 3 + todayno +weeknumber=: 3 : 0 +yr=. {.y +sd=. 1 ((i.~weekday){]) ((<:yr),.12,.29+i.3),yr,.1,.1+i.4 +wk=. >.7%~>: y -&todayno sd +if. wk >weeksinyear yr do. + (>:yr),1 +elseif. wk=0 do. + (,weeksinyear)<:yr +elseif. do. + yr,wk +end. +) +weeksinyear=: 3 : '52+ +./"1 [ 4=weekday(1 1,:12 31),"0 1/~ y' +cocurrent 'z' +dbr=: 13!:0 +dbs=: 13!:1 +dbsq=: 13!:2 +dbss=: 13!:3 +dbrun=: 13!:4 +dbnxt=: 13!:5 +dbret=: 13!:6 +dbjmp=: 13!:7 +dbsig=: 13!:8 +dbrr=: 13!:9 +dbrrx=: 13!:10 +dberr=: 13!:11 +dberm=: 13!:12 +dbstk=: 13!:13 +dblxq=: 13!:14 +dblxs=: 13!:15 +dbtrace=: 13!:16 +dbq=: 13!:17 +dbst=: 13!:18 +dbctx=: 3 3&$: : (4 : 0) +if. -.13!:17'' do. 0 0$'' return. end. +try. + 'before after'=. 2{. <. , x, 3 3 +catch. + 'before after'=. 3 3 +end. +if. 0= #d=. 13!:13'' do. 0 0$'' return. end. +if. '*' -.@e. sus=. >{:"1 d do. 0 0$'' return. end. +'name ln nc def src'=. 0 2 3 4 5{(sus i. '*'){d +dyad=. {: ':'&e.;._2 ] 13!:12'' +if. (_2{.def) -: LF,')' do. + def=. }.def [ def0=. {.def=. }:<;._2 def,LF +else. + def=. ,<def [ def0=: '' +end. +if. def e.~ <,':' do. + if. dyad do. + def=. def}.~ >: def i. <,':' + else. + def=. def{.~ def i. <,':' + end. +end. +min=. 0>.ln-before [ max=. (<:#def)<.ln+after +ctx=. '[',"1 (":,.range) ,"1 ('] ') ,"1 >def{~range=. min + i. >:max-min +> (<'@@ ', name, '[', (dyad#':'), (":ln) ,'] *', (nc{' acv'),' @@ ', src), def0, <"1 ctx +) +dbg=: 13!:0 +dblocals=: _1&$: : (4 : 0) +stk=. }. 13!:13'' +if. 0=#y do. y=. a: else. y=. (y e. i.#stk) # y end. +loc=. (<y ; 0 7) { stk +if. -. x-:_1 do. + t=. ;: ::] x + f=. ({."1 e. t"_) # ] + ({."1 loc) ,. f &.> {:"1 loc +end. +) +dbstack=: 3 : 0 +hdr=. ;:'name en ln nc args locals susp' +stk=. }. 13!:13'' +if. #y do. + if. 2=3!:0 y do. + stk=. stk #~ (<y)={."1 stk + else. + stk=. ((#stk)<.,y){.stk + end. +end. +stk=. 1 1 1 1 0 0 1 1 1 #"1 stk +stk=. hdr, ": &.> stk +wds=. ({:@$@":@,.)"1 |: stk +len=. 20 >.<.-:({.wcsize'') - +/8, 4 {. wds +tc=. (len+1)&<.@$ {.!.'.' ({.~ len&<.@$) +tc@": each stk +) +dbstop=: 3 : 0 +if. 0 e. #y -. ' ' do. 13!:3'' return. end. +t=. 13!:2'' +if. #t do. t=. <;._2 t, ';' -. {:t end. +t=. ~. t, (;: ^: (L.=0:) y) ,&.> <' *:*' +13!:3 ; t ,&.> ';' +) +dbstops=: 3 : 0 +13!:3 ; (;: ^: (L.=0:) y) ,&.> <' *:*;' +) +dbstopme=: 3 : 0 +if. y do. + if. 0 e. $c=. }. 13!:13'' do. return. end. + c=. (> {. {. c), ' *:*' + t=. 13!:2'' + if. #t do. t=. <;._2 t, ';' -. {:t end. + t=. ~. t, <c + 13!:3 }: ; t ,&.> ';' +end. +) +dbstopnext=: 3 : 0 +if. y do. + if. 0 e. $c=. }. 13!:13'' do. return. end. + 'd n a'=. 0 2 6 { {. c + c=. d,' ',(':'#~2=#a),":n+1 + t=. 13!:2'' + if. #t do. t=. <;._2 t, ';' -. {:t end. + t=. ~. t, <c + 13!:3 }: ; t ,&.> ';' +end. +) +dbview=: 3 : 0 +if. _1 = 4!:0 <'jdbview_jdbview_' do. + 'require'~'~system/util/dbview.ijs' +end. +jdbview_jdbview_ }. 13!:13'' +) +cocurrent 'z' +dir=: 3 : 0 +'n' dir y +: +ps=. '/' +y=. jpath y,(0=#y)#'*' +y=. y,((':',ps) e.~ {:y)#'*' +if. 0=#dr=. 1!:0 y do. empty'' return. end. +fls=. 'd' ~: 4{"1>4{"1 dr +if. (1=#dr) *. 0={.fls do. + r=. x dir y,ps,'*' + if. #r do. r return. end. +end. +if. fmt=. 2=3!:0 x do. opt=. 2 1 +else. opt=. 2{.x end. +if. 0={:opt do. fls=. 1#~#dr=. fls#dr end. +if. 0=#dr do. empty'' return. end. +nms=. {."1 dr +nms=. nms ,&.> fls{ps;'' +if. IFWIN do. + nms=. tolower &.> nms +end. +ndx=. /: (":,.fls),.>nms +if. 0=opt do. + list >ndx{nms +elseif. 1=opt do. + path=. (+./\.y=ps)#y + path&,&.>ndx{nms +elseif. fmt<2=opt do. + ndx{nms,.}."1 dr +elseif. fmt do. + 'nms ts size'=. |:3{."1 dr + if. IFWIN do. + nms=. tolower L:0 nms + end. + ds=. ' <dir> ' ((-.fls)#i.#fls) } 12 ":,.size + mth=. _3[\' JanFebMarAprMayJunJulAugSepOctNovDec' + f=. > @ ([: _2&{. [: '0'&, ": )&.> + 'y m d h n s'=. f&> ,<"1 |: 100|ts + m=. (1{"1 ts){mth + time=. d,.'-',.m,.'-',.y,.' ',.h,.':',.n,.':',.s + dat=. (>nms),.ds,.' ',.time + dat /: fls,. /:/: >(3|'dns'i.x){ts;nms;size +elseif. 1 do. + 'invalid left argument' +end. +) +dircompare=: 3 : 0 +0 dircompare y +: +if. 0=#y do. + '''long dirtree timestamps'' dircompare dir1;dir2' + return. +end. + +opt=. 3 {. x +res=. opt dircompares y +if. 0 = L. res do. return. end. + +ps=. '/' +'a b c'=. res + +'x y'=. jpath each cutopen y +x=. x, ps #~ (*#x) *. ps~:_1{.x +y=. y, ps #~ (*#y) *. ps~:_1{.y + +r=. 'comparing ',x,' and ',y,LF + +if. #a do. + r=. r,LF,'not in ',y,':',LF,,(list a),.LF +end. + +if. #b do. + r=. r,LF,'not in ',x,':',LF,,(list b),.LF +end. + +if. +/ # &> c do. + 'cf cd'=. c + r=. r,LF,'not same in both:',LF,,(list cf),.LF + if. {.opt do. + r=. r,LF,;(,&(LF2)) &.> cd + end. + +end. + +if. 0=#;res do. r=. r,'no difference',LF end. + +}:r +) +dircompares=: 3 : 0 +0 dircompares y +: +ps=. '/' +opt=. 3{. x +'x y'=. jpath each cutopen y +x=. x, ps #~ (*#x) *. ps~:_1{.x +y=. y, ps #~ (*#y) *. ps~:_1{.y + +if. 1{opt do. + dx=. dirtree x [ dy=. dirtree y +else. + dx=. 2 0 dir x [ dy=. 2 0 dir y +end. + +if. dx -: dy do. 'no difference' return. end. +if. 0 e. #dx do. 'first directory is empty' return. end. +if. 0 e. #dy do. 'second directory is empty' return. end. + +f=. #~ [: +./\. =&ps +sx=. f x +sy=. f y +fx=. {."1 dx +fy=. {."1 dy + +if. 1{opt do. + fx=. (#sx)}.&.>fx + fy=. (#sy)}.&.>fy + dx=. fx 0 }"0 1 dx + dy=. fy 0 }"0 1 dy +end. + +r=. <fx -. fy +r=. r , <fy -. fx + +dx=. (fx e. fy)#dx +dy=. (fy e. fx)#dy + +if. #j=. dx -. dy do. + j=. {."1 j + cmp=. <@fcompare"1 (sx&,&.>j),.sy&,&.>j + + if. 0=2{opt do. + f=. 'no difference'&-: @ (_13&{.) + msk=. -. f &> cmp + j=. msk#j + cmp=. msk#cmp + end. + + r=. r,< j;<cmp +else. + r=. r,a: +end. + +r +) +dirfind=: 4 : 0 +f=. [: 1&e. x&E. +g=. #~ [: -. [: +./\. =&'/' +d=. {."1 dirtree y +m=. f@g &> d +if. 1 e. m do. ; (m # d) ,each LF else. 0 0$'' end. +) +dirpath=: 3 : 0 +0 dirpath y +: +r=. '' +t=. jpath y +ps=. '/' +if. #t do. t=. t, ps -. {:t end. +dirs=. <t +ifdir=. 'd'&= @ (4&{"1) @ > @ (4&{"1) +subdir=. ifdir # ] +while. #dirs do. + fpath=. (>{.dirs) &, + dirs=. }.dirs + dat=. 1!:0 fpath '*' + if. #dat do. + dat=. subdir dat + if. #dat do. + r=. r, fpath each /:~ {."1 dat + dirs=. (fpath @ (,&ps) each {."1 dat),dirs + end. + end. +end. +if. x do. + f=. 1!:0 @ (,&(ps,'*')) + g=. 0:`(0: e. ifdir) + h=. g @. (*@#) @ f + r=. r #~ h &> r +end. +if. #t do. r=. r,<}:t end. +if. IFWIN do. + r=. tolower each r +end. +/:~ r +) +dirss=: 4 : 0 +if. (2=#x) *. 1=L. x do. + x dirssrplc y return. +end. + +sub=. ' '&(I.@(e.&(TAB,CRLF))@]}) +fls=. {."1 dirtree y +if. 0 e. #fls do. + 'no files in directory: ',y return. +end. +fnd=. '' +while. #fls do. + dat=. 1!:1 <fl=. >{.fls + fls=. }.fls + ndx=. I. x E. dat + if. rws=. #ndx do. + dat=. (20$' '),dat,30$' ' + dat=. (rws,50)$sub(,ndx+/i.50){dat + fnd=. fnd,LF2,fl,' (',(":#ndx),')' + fnd=. fnd,,LF,.dat + end. +end. +if. #fnd do. 2}.fnd else. 'not found: ',x end. +) +dirssrplc=: 4 : 0 +fls=. {."1 dirtree y +if. 0 e. #fls do. + 'no files found' return. +end. +r=. (x&fssrplc) each fls +b=. r ~: <'no match found' +j=. >b # fls , each ': '&, each r +}: , j ,. LF +) +dirtree=: 3 : 0 +0 dirtree y +: +if. 0=4!:0 <'DirTreeX_j_' do. + ex=. boxxopen DirTreeX_j_ +else. + ex=. '' +end. +r=. i.0 3 +ps=. '/' +y=. jpath y +y=. y #~ (+./\ *. +./\.) y~:' ' +y=. y,(0=#y)#'*' +if. ps={:y do. y=. y,'*' end. +if. -. '*' e. y do. + if. 1 = #j=. 1!:0 y do. + select. 'hd' = 1 4 { >4{,j + case. 0 1 do. x dirtree y,ps,'*' return. + case. 1 1 do. i.0 3 return. + end. + end. +end. +ts=. 100"_ #. 6: {. 0: >. <. - # {. 1980"_ +'path ext'=. (b#y);(-.b=. +./\.y=ps)#y +if. #dl=. 1!:0 y do. + att=. > 4{"1 dl + fl=. (('h' ~: 1{"1 att) *. 'd' ~: 4{"1 att)#dl + if. #fl do. + r=. r,(path&,&.>{."1 fl),.1 2{"1 fl + end. +end. +if. #dl=. 1!:0 path,'*' do. + att=. > 4{"1 dl + dr=. {."1 (('h' ~: 1{"1 att) *. 'd' = 4{"1 att) # dl + dr=. dr -. ex + if. #dr do. + r=. r,;x&dirtree@(path&,@,&(ps,ext)) &.> dr + end. +end. +r=. r #~ (ts x) <: ts &> 1{"1 r +if. IFWIN *. #r do. + (tolower L:0 {."1 r) 0 }"0 1 r +end. +) +dirused=: [: (# , +/ @ ; @ (2: {"1 ])) 0&dirtree +cocurrent 'z' + +fboxname=: <@jpath_j_@(8 u: >) ::] +fexists=: #~ fexist +f2utf8=: ] +fappend=: 4 : 0 +(,x) (#@[ [ 1!:3) :: _1: fboxname y +) +fappends=: 4 : 0 +(fputs x) (#@[ [ 1!:3) :: _1: fboxname y +) +fapplylines=: 1 : 0 +0 u fapplylines y +: +y=. > fboxname y +s=. 1!:4 <y +if. s = _1 do. return. end. +p=. 0 +dat=. '' +while. p < s do. + b=. 1e6 <. s-p + dat=. dat, 1!:11 y;p,b + p=. p + b + if. p = s do. + len=. #dat=. dat, LF -. {:dat + elseif. (#dat) < len=. 1 + dat i:LF do. + 'file not in LF-delimited lines' 13!:8[3 + end. + if. x do. + u ;.2 len {. dat + else. + u ;._2 CR -.~ len {. dat + end. + dat=. len }. dat +end. +) +fcopynew=: 4 : 0 +dat=. fread each boxopen y +if. (<_1) e. dat do. _1 return. end. +dat=. ; dat +if. dat -: fread :: 0: x do. 0,#dat else. + if. _1=dat fwrite x do. _1 else. 1,#dat end. +end. +) +fdir=: 1!:0@fboxname +ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen +fexist=: (1:@(1!:4) :: 0:) @ (fboxname &>) @ boxopen +fgets=: 3 : 0 +y=. (-(26{a.)={:y) }. y +if. 0=#y do. '' return. end. +y,LF -. {:y=. toJ y +) +fmakex=: (] 1!:7~ 'x' 2 5 8} 1!:7) @ fboxname +fpathcreate=: 3 : 0 +if. 0=#y do. 1 return. end. +p=. (,'/'-.{:) jpathsep y +if. # 1!:0 }: p do. 1 return. end. +for_n. I. p='/' do. 1!:5 :: 0: < n{.p end. +) +fpathname=: +./\.@:=&'/' (# ; -.@[ # ]) ] +fread=: 3 : 0 +if. 1 = #y=. boxopen y do. + 1!:1 :: _1: fboxname y +else. + 1!:11 :: _1: (fboxname {.y),{:y +end. +: +x freads y +) +freadblock=: 3 : 0 +'f p'=. y +f=. > fboxname f +s=. 1!:4 <f +if. s = _1 do. return. end. +if. (s = 0) +. p >: s do. '';p return. end. +if. 1e6 < s-p do. + dat=. 1!:11 f;p,1e6 + len=. 1 + dat i: LF + if. len > #dat do. + 'file not in LF-delimited lines' 13!:8[3 + end. + p=. p + len + dat=. len {. dat +else. + dat=. 1!:11 f;p,s-p + dat=. dat, LF -. {: dat + p=. s +end. +(toJ dat);p +) +freadr=: 3 : 0 +'f s'=. 2{.boxopen y +f=. fboxname f +max=. 1!:4 :: _1: f +if. max -: _1 do. return. end. +pos=. 0 +step=. 10000 +whilst. blk = cls +do. + blk=. step<.max-pos + if. 0=blk do. 'file not organized in records' return. end. + dat=. 1!:11 f,<pos,blk + cls=. <./dat i.CRLF + pos=. pos+step +end. +len=. cls+pos-step +dat=. 1!:11 f,<len,2<.max-len +dlm=. +/CRLF e. dat +wid=. len+dlm +s=. wid*s,0 #~ 0=#s +dat=. 1!:11 f,<s +dat=. (-wid)[\dat +(-dlm)}."1 dat +) +freads=: 3 : 0 +'' freads y +: +dat=. fread y +if. (dat -: _1) +. 0=#dat do. return. end. +dat=. fgets dat +if. 'b'e.x do. dat=. <;._2 dat +elseif. 'm'e.x do. dat=. ];._2 dat +end. +) +frename=: 4 : 0 +x=. > fboxname x +y=. > fboxname y +if. x -: y do. return. end. +if. IFUNIX do. + 2!:0 'mv "',y,'" "',x,'"' +else. + 'kernel32 MoveFileW i *w *w' 15!:0 (uucp y);uucp x +end. +) +freplace=: 4 : 0 +y=. boxopen y +dat=. ,x +f=. #@[ [ 1!:12 +dat f :: _1: (fboxname {.y),{:y +) +fsize=: (1!:4 :: _1:) @ (fboxname &>) @ boxopen +fss=: 4 : 0 +y=. fboxname y +size=. 1!:4 :: _1: y +if. size -: _1 do. return. end. +blk=. (#x) >. 100000 <. size +r=. i.pos=. 0 +while. pos < size do. + dat=. 1!:11 y,<pos,blk <. size-pos + r=. r,pos+I. x E. dat + pos=. pos+blk+1-#x +end. +r +) +fssrplc=: fstringreplace +fstamp=: (1: >@{ , @ (1!:0) @ fboxname) :: _1: +fputs=: 3 : 0 +dat=. ":y +if. 0 e. $dat do. + '' +else. + if. 1>:#$dat do. + toHOST dat,(-.({:dat) e. CRLF) # LF + else. + ,dat,"1 toHOST LF + end. +end. +) +ftype=: 3 : 0 +d=. (}: ^: ('/'={:)) ucp y +d=. 1!:0 fboxname d +if. #d do. + >: 'd' = 4 { > 4 { ,d +else. + 0 +end. +) +fview=: 3 : 0 +if. 3 ~: nc <'textview_z_' do. + sminfo 'textview not available.' return. +end. +txt=. freads y +if. txt -: _1 do. + sminfo 'file not found: ',,>y return. +end. +textview txt +) +fwrite=: 4 : 0 +(,x) (#@[ [ 1!:2) :: _1: fboxname y +) +fwritenew=: 4 : 0 +dat=. ,x +if. dat -: fread y do. 0 return. end. +dat fwrite y +) +fwrites=: 4 : 0 +(fputs x) (#@[ [ 1!:2) :: _1: fboxname y +) +ftostring=: fputs +fstring=: fgets +cocurrent 'z' +install=: 3 : 0 +require 'pacman' +if. -. checkaccess_jpacman_ '' do. return. end. +'update' jpkg '' +select. y +case. 'gtkide' do. + getgtkbin 0 + 'install' jpkg 'base library ide/gtk gui/gtk' +case. 'all' do. + getgtkbin 0 + 'install' jpkg 'all' +end. +) +getgtkbin=: 3 : 0 +if. UNAME -: 'Linux' do. return. end. +if. (0={.y,0) *. 0 < #1!:0 jpath '~install/gtk/lib' do. return. end. +require 'pacman' +smoutput 'Installing gtk binaries...' +z=. (IFWIN pick 'mac';'win'),(IF64 pick '32';'64'),'.zip' +z=. 'http://www.jsoftware.com/download/gtk',z +'rc p'=. httpget_jpacman_ z +if. rc do. + smoutput 'unable to download: ',z return. +end. +d=. jpath '~install' +if. IFWIN do. + unzip_jpacman_ p;d +else. + hostcmd_jpacman_ 'unzip ',(dquote p),' -d ',dquote d + ('INSTALLPATH';jpath '~install/gtk') dirss jpath '~install/gtk/etc' +end. +if. #1!:0 jpath '~install/gtk/lib' do. + m=. 'Finished install of gtk binaries.' +else. + m=. 'Unable to install gtk binaries.',LF + m=. m,'check that you have write permission for: ',LF,jpath '~install/gtk' +end. +smoutput m +) +cocurrent 'z' +cuts=: 2 : 0 +if. n=1 do. [: u (#@[ + E. i. 1:) {. ] +elseif. n=_1 do. [: u (E. i. 1:) {. ] +elseif. n= 2 do. [: u (E. i. 1:) }. ] +elseif. 1 do. [: u (#@[ + E. i. 1:) }. ] +end. +) +cut=: ' '&$: :([: -.&a: <;._2@,~) +deb=: #~ (+. 1: |. (> </\))@(' '&~:) +debc=: #~"1 [: (+. (1: |. (> </\))) ' '&(+./ .~:) +delstring=: 4 : ';(x E.r) <@((#x)&}.) ;.1 r=. x,y' +detab=: ' ' I.@(=&TAB@])} ] +dlb=: }.~ =&' ' i. 0: +dltb=: #~ [: (+./\ *. +./\.) ' '&~: +dtb=: #~ [: +./\. ' '&~: +joinstring=: ''&$: : (#@[ }. <@[ ;@,. ]) +ljust=: (|.~ +/@(*./\)@(' '&=))"1 +rjust=: (|.~ -@(+/)@(*./\.)@(' '&=))"1 +splitstring=: #@[ }.each [ (E. <;.1 ]) , +ss=: I. @ E. +dropto=: ] cuts 2 +dropafter=: ] cuts 1 +taketo=: ] cuts _1 +takeafter=: ] cuts _2 +charsub=: 4 : 0 +'f t'=. |: _2 ]\ x +l=. f i."1 0 y +x=. l { t,'?' +c=. l = #f +c } x ,: y +) +chopstring=: 3 : 0 +(' ';'""') chopstring y +: +dat=. y +'fd sd'=. 2{. boxopen x +assert. 1 = #fd +if. =/sd do. sd=. (-<:#sd)}.sd +else. + s=. {.('|'=fd){ '|`' + dat=. dat rplc ({.sd);s;({:sd);s + sd=. s +end. +dat=. dat,fd +b=. dat e. fd +c=. dat e. sd +d=. ~:/\ c +fmsk=. b > d +smsk=. (> (0 , }:)) c +smsk=. -. smsk +. c *. 1|.fmsk +y=. smsk#y,fd +fmsk=. 0:^:(,@1: -: ]) smsk#fmsk +fmsk <;._2 y +) +dltbs=: LF&$: : (4 : 0) +txt=. ({.x), y +a=. txt ~: ' ' +b=. (a # txt) e. x +c=. b +. }. b, 1 +d=. ~: /\ a #^:_1 c ~: }: 0, c +}. (a >: d) # txt +) +dquote=: ('"'&,@(,&'"'))@ (#~ >:@(=&'"')) +dtbs=: 3 : 0 +CRLF dtbs y +: +txt=. y , {.x +blk=. txt ~: ' ' +ndx=. +/\ blk +b=. blk < }. (txt e. x), 0 +msk=. blk >: ndx e. b # ndx +}: msk # txt +) +rplc=: stringreplace~ +fstringreplace=: 4 : 0 +nf=. 'no match found' +y=. boxopen y +try. size=. 1!:4 y catch. nf return. end. +if. size=0 do. nf return. end. +old=. freads y +new=. x stringreplace old +if. old -: new do. nf return. end. +new fwrites y +cnt=. +/ (0 pick x) E. old +(":cnt),' replacement',((1~:cnt)#'s'),' made' +) +quote=: (''''&,@(,&''''))@ (#~ >:@(=&'''')) +nos=. i.@#@] e. #@[ ({~^:a:&0@(,&_1)@(]I.+) { _1,~]) I.@E. +splitnostring=: #@[ }.each [ (nos f. <;.1 ]) , +stringreplace=: 4 : 0 + +txt=. ,y +t=. _2 [\ ,x +old=. {."1 t +new=. {:"1 t +oldlen=. # &> old +newlen=. # &> new + +if. *./ 1 = oldlen do. + + hit=. (;old) i. txt + ndx=. I. hit < #old + + if. 0 e. $ndx do. txt return. end. + + cnt=. 1 + exp=. hit { newlen,1 + hnx=. ndx { hit + bgn=. ndx + +/\ 0, (}: hnx) { newlen - 1 + +else. + + + hit=. old I. @ E. each <txt + cnt=. # &> hit + + if. 0 = +/ cnt do. txt return. end. + + bgn=. set=. '' + + pick=. > @ { + diff=. }. - }: + + for_i. I. 0 < cnt do. + ln=. i pick oldlen + cx=. (i pick hit) -. set, ,bgn -/ i.ln + while. 0 e. b=. 1, <:/\ ln <: diff cx do. cx=. b#cx end. + hit=. (<cx) i} hit + bgn=. bgn, cx + set=. set, ,cx +/ i.ln + end. + + cnt=. # &> hit + msk=. 0 < cnt + exp=. (#txt) $ 1 + del=. newlen - oldlen + + if. #add=. I. msk *. del > 0 do. + exp=. (>: (add{cnt) # add{del) (;add{hit) } exp + end. + + if. #sub=. I. msk *. del < 0 do. + sbx=. ; (;sub{hit) + each (sub{cnt) # i. each sub{del + exp=. 0 sbx } exp + end. + + hit=. ; hit + ind=. /: (#hit) $ 1 2 3 + hnx=. (/: ind { hit) { ind + bgn=. (hnx { hit) + +/\ 0, }: hnx { cnt # del + +end. + +ind=. ; bgn + each hnx { cnt # i.each newlen +rep=. ; hnx { cnt # new +rep ind} exp # txt +) +cutpara=: 3 : 0 +txt=. topara y +txt=. txt,LF -. {:txt +b=. (}.b,0) < b=. txt=LF +b <;._2 txt +) +foldtext=: 4 : 0 +if. 0 e. $y do. '' return. end. +y=. ; x&foldpara each cutpara y +y }.~ - (LF ~: |.y) i. 1 +) +foldpara=: 4 : 0 +if. 0=#y do. LF return. end. +r=. '' +x1=. >: x +txt=. y +while. + ind=. ' ' i.~ |. x1{.txt + s=. txt {.~ ndx=. x1 - >: x1 | ind + s=. (+./\.s ~: ' ') # s + r=. r, s, LF + #txt=. (ndx + ind<x1) }. txt +do. end. +r +) +topara=: 3 : 0 +if. 0=#y do. '' return. end. +b=. y=LF +c=. b +. y=' ' +b=. b > (1,}:b) +. }.c,0 +' ' (I. b) } y +) + +cocurrent <'j' +Alpha=: a. {~ , (a.i.'Aa') +/ i.26 +Num=: a. {~ (a.i.'0') + i.10 +AlphaNum=: Alpha,Num +Boxes=: ((16+i.11) { a.),:'+++++++++|-' +ScriptExt=: '.ijs' +ProjExt=: '.jproj' + +extnone=: {.~ i:&'.' +extproj=: , (ProjExt #~ '.'&e. < 0 < #) +extsrc=: , ('.ijs' #~ '.'&e. < 0 < #) + +addfname=: , (e.&'/\' i: 1:) }. ] +boxdraw=: 3 : '9!:7 y { Boxes' +hostcmd=: [: 2!:0 '(' , ,&' || true)' +fpath=: [: }: +./\.@:=&'/' # ] +maxrecent=: 3 : '(RecentMax <. #r) {. r=. ~.y' +pack=: [: (,. ".&.>) ;: ::] +pdef=: 3 : '0 0$({."1 y)=: {:"1 y' +seldir=: #~ '-d'&-:"1 @ (1 4&{"1) @ > @ (4&{"1) +spath=: #~ [: *./\. '/'&~: +termLF=: , (0 < #) # LF -. {: +termsep=: , (0 < #) # '/' -. {: +tolist=: }.@;@:(LF&,each) +remsep=: }.~ [: - '/' = {: + +path2proj=: ,'/',ProjExt ,~ spath +3 : 0'' +if. IFUNIX do. + filecase=: ] + isroot=: '/' = {. +else. + filecase=: tolower + isroot=: ':' = {.@}. +end. +0 +) +dirtreex=: 3 : 0 +'' dirtreex y +: +y=. jpath y +p=. (+./\. y = '/') # y +d=. 1!:0 y,('/' = {:y) # '*' +if. 0 = #d do. '' return. end. +a=. > 4 {"1 d +m=. 'd' = 4 {"1 a +f=. (<p) ,each {."1 d +if. 1 e. m do. + f=. f, ; dirtreex each (m#f) ,each <'/','*' +end. +if. #x do. + f #~ (1 e. x E. ])&> f +end. +) +getfolderdefs=: 3 : 0 +p=. (, '/' , ProjExt ,~ spath) each subdirtree y +t=. p #~ #@(1!:0)&> p +t;<fpath each (1+#y) }. each (-#ProjExt) }. each t +) +isconfigfile=: 3 : 0 +'p f'=. fpathname y +x=. f i: '.' +(p -: jpath '~config/') *. '.cfg'-:x}.f +) +isdir=: 3 : 0 +d=. 1!:0 y +if. 1 ~: #d do. 0 return. end. +'d' = 4 { 4 pick ,d +) +istempname=: 3 : 0 +x=. y i: '.' +*./ ('.ijs'-:x}.y),(x{.y) e. Num +) +istempscript=: 3 : 0 +'p f'=. fpathname y +(p -: jpath '~temp/') *. istempname f +) +jshowconsole=: 3 : 0 +if. -.IFWIN do. 'only supported in windows' return. end. +t=. {.>'kernel32.dll GetConsoleWindow x'cd'' +'user32.dll ShowWindow n x i'cd t;(0-:y){5 0 +i.0 0 +) +mkdir=: 3 : 0 +a=. termsep y +if. #1!:0 }:a do. 1 return. end. +for_n. I. a='/' do. + 1!:5 :: 0: < n{.a +end. +) +newtempscript=: 3 : 0 +x=. ScriptExt +p=. jpath '~temp/' +d=. 1!:0 p,'*',x +a=. (-#x) }. each {."1 d +a=. a #~ (*./ .e.&'0123456789') &> a +a=. 0, {.@:(0&".) &> a +p, x ,~ ": {. (i. >: #a) -. a +) +nounrep=: 2 }. [: ; [: nounrep1 each ;: +nounrep1=: LF2 , ] , '=: ' , [: nounrep2 ". +nounrep2=: 3 : 0 +if. 0 = #y do. '''''' return. end. +select. 3!:0 y +fcase. 32 do. + y=. ; y ,each LF +case. 2 do. + if. LF e. y do. + y=. y, LF -. {:y + '0 : 0', LF, ; <;.2 y,')' + else. + quote y + end. +case. do. + ": y +end. +) +octal=: 3 : 0 +t=. ,y +x=. a. i. t +n=. x e. 9 10 13 +m=. n < 32 > x +if. (isutf8 t) > 1 e. m do. t return. end. +r=. t ,"0 1 [ 3 # EAV +if. #m=. I. m +. x>126 do. + s=. '\',.}.1 ": 8 (#.^:_1) 255,m{x + r=. s m} r +end. +EAV -.~ ,r +) +rmdir=: 3 : 0 +r=. 1;'not a directory: ',":y +if. 0=#y do. r return. end. +d=. 1!:0 y +if. 1 ~: #d do. r return. end. +if. 'd' ~: 4 { 4 pick {. d do. r return. end. +if. IFWIN do. + shell_jtask_ 'rmdir ',y,' /S /Q' +else. + hostcmd_j_ 'rm -rf --preserve-root ',y +end. +(#1!:0 y);'' +) +scripts=: 3 : 0 +if. 0=#y do. + list 0{"1 Public +elseif. 'v'e.y do. + dir=. Public + a=. >0{"1 dir + b=. >1{"1 dir + a /:~ a,.' ',.b +elseif. 1 do. + 'invalid argument to scripts: ',,":y +end. +) +setfolder=: 3 : 0 +if. 0=#y do. + Folder=: FolderTree=: FolderIds=: '' return. +end. +assert. (<y) e. {."1 UserFolders +Folder=: y +'FolderTree FolderIds'=: getfolderdefs jpath '~',y +if. 3=nc <'snapshot_tree_jp_' do. + snapshot_tree_jp_ FolderTree +end. +EMPTY +) +subdirtree=: 3 : 0 +if. 0=#1!:0 y do. '' return. end. +r=. '' +dir=. <y,'/' +while. #dir do. + fpath=. (>{.dir) &, + dir=. }.dir + dat=. seldir 1!:0 fpath '*' + if. #dat do. + dat=. fpath each {."1 dat + r=. r,dat + dir=. (dat ,each '/'),dir + end. +end. +sort filecase each r +) +unixshell=: 3 : 0 +f=. jpath '~temp/shell.sh' +t=. jpath '~temp/shell.txt' +e=. jpath '~temp/shell.err' +('#!/bin/sh',LF,y,LF) fwrite f +'rwx------' 1!:7 <f +hostcmd '"',f,'" > "',t,'" 2> "',e,'"' +r=. (fread t);fread e +ferase f;t;e +r +) +unixshellx=: 3 : 0 +'res err'=. unixshell y +if. #err do. + smoutput 'Shell command error: ',LF,LF,err +end. +res +) +htmlhelp=: 3 : 0 +f=. jpath '~addons/docs/help/',y +if. fexist ({.~ i:&'#') f do. + browse 'file://',f +else. + f=. 'http://www.jsoftware.com/docs/help',}.(i.&'/'{.]) 9!:14'' + browse f,'/',y +end. +) +browseref=: 3 : 0 +htmlhelp 'dictionary/',y +) +dquote=: 3 : 0 +if. '"' = {.y do. y else. '"',y,'"' end. +) +browse=: 3 : 0 +cmd=. dlb@dtb y +isURL=. 1 e. '://'&E. +if. IFJHS do. + cmd=. '/' (I. cmd='\') } cmd + if. -. isURL cmd do. + if. -.fexist cmd do. EMPTY return. end. + cmd=. 'file://',cmd + end. + redirecturl_jijxm_=: (' ';'%20') stringreplace cmd + EMPTY return. +end. +browser=. Browser_j_ +if. IFWIN do. + ShellExecute=. 'shell32 ShellExecuteW > i x *w *w *w *w i'&cd + SW_SHOWNORMAL=. 1 + NULL=. <0 + cmd=. '/' (I. cmd='\') } cmd + if. -. isURL cmd do. + if. -.fexist cmd do. EMPTY return. end. + cmd=. 'file://',cmd + end. + if. 0 = #browser do. + r=. ShellExecute 0;(uucp 'open');(uucp cmd);NULL;NULL;SW_SHOWNORMAL + else. + r=. ShellExecute 0;(uucp 'open');(uucp browser);(uucp dquote cmd);NULL;SW_SHOWNORMAL + end. + if. r<33 do. sminfo 'browse error:',browser,' ',cmd,LF2,1{::cderx'' end. + EMPTY return. +end. +if. 0 = #browser do. + browser=. dfltbrowser'' +end. +browser=. dquote (browser;Browser_nox_j_){::~ nox=. IFUNIX *. (0;'') e.~ <2!:5 'DISPLAY' +cmd=. '/' (I. cmd='\') } cmd +if. -. isURL cmd do. + cmd=. 'file://',cmd +end. +cmd=. browser,' ',dquote cmd +try. + 2!:1 cmd, (0=nox)#' >/dev/null 2>&1 &' +catch. + msg=. 'Could not run the browser with the command:',LF2 + msg=. msg, cmd,LF2 + if. IFGTK do. + msg=. msg, 'You can change the browser definition in Edit|Configure|Base',LF2 + end. + sminfo 'Run Browser';msg +end. +EMPTY +) +dfltbrowser=: verb define +select. UNAME +case. 'Win' do. '' +case. 'Darwin' do. 'open' +case. do. + try. + 2!:0'which google-chrome' + 'google-chrome' return. catch. end. + try. + 2!:0'which chromium-browser' + 'chromium-browser' return. catch. end. + try. + 2!:0'which firefox' + 'firefox' return. catch. end. + try. + 2!:0'which konqueror' + 'konqueror' return. catch. end. + try. + 2!:0'which netscape' + 'netscape' return. catch. end. + '' return. +end. +) +Folder=: '' +FolderTree=: FolderIds=: 0 + +Cwh=: 79 24 +jpath=: 3 : 0 +nam=. jpathsep y +if. '~' ~: {. nam do. return. end. +fld=. SystemFolders, UserFolders +ind=. nam i. '/' +tag=. }. ind {. nam +if. 0=#tag do. + tag=. 'home' + nam=. '~home',}.nam + ind=. nam i. '/' +end. +if. tag -: 'addons' do. + bal=. 8 }. nam +end. +par=. '.' = {. tag +if. par do. + len=. ('.' = tag) i. 0 + tag=. len }. tag +end. +ndx=. ({."1 fld) i. <tag +if. ndx < # fld do. + bal=. ind }. nam + pfx=. 1 pick ndx { fld + if. '~' = {.pfx do. + pfx=. jpath pfx + end. + if. par do. + pfx=. ((#pfx) | (+/\. pfx='/') i: len) {. pfx + end. + nam=. pfx,bal +end. +nam +) +tofoldername=: 3 : 0 +if. 0=#y do. '' return. end. +folders=. UserFolders,SystemFolders +pds=. {."1 folders +pps=. termsep each {:"1 folders +ndx=. \: # &> pps +pds=. ndx{pds +pps=. ndx{pps +res=. filecase each boxxopen y +len=. # &> pps +for_i. i.#res do. + nam=. i pick res + if. '~' = {. nam,'~' do. continue. end. + msk=. pps = len {. each <nam,'/' + if. 1 e. msk do. + ndx=. ((i. >./) msk # len) { I. msk + nam=. ('~', > ndx { pds),(<: ndx { len) }. nam + res=. (<nam) i } res + end. +end. +pps=. }: each pps +ndx=. 1 + pps i: &> '/' +msk=. ndx < len +pps=. msk # ndx {.each pps +pds=. msk # pds +len=. # &> pps +for_i. i.#res do. + nam=. i pick res + if. '~' = {. nam,'~' do. continue. end. + if. '/' = {. nam do. continue. end. + msk=. pps = len {. each <nam + if. 1 e. msk do. + ndx=. ((i. >./) msk # len) { I. msk + nam=. ('~.', > ndx { pds),(<: ndx { len) }. nam + res=. (<nam) i } res + end. +end. +if. L. y do. res else. >res end. +) +Loaded=: '' +Public=: i. 0 2 +UserFolders=: i. 0 2 +Ignore=: ;: 'colib convert coutil dates debug dir dll files libpath strings text' +buildpublic=: 3 : 0 +dat=. deb toJ y +dat=. a: -.~ <;._2 dat, LF +ndx=. dat i. &> ' ' +short=. ndx {.each dat +long=. ndx }. each dat +long=. extsrc@jpathsep@deb each long +msk=. (<'system','/') = 7 {. each long +long=. (msk{'';'~') ,each long +Public=: sort ~. Public,~ short,.long +empty'' +) +cutnames=: 3 : 0 +if. LF e. y do. + txt=. y, LF + nms=. (txt = LF) <;._2 txt +else. + txt=. y, ' ' + msk=. txt = '"' + com=. (txt = ' ') > ~: /\ msk + msk=. (msk *. ~:/\msk) < msk <: 1 |. msk + nms=. (msk # com) <;._2 msk # txt +end. +nms -. a: +) +3 : 0'' +if. 0=9!:24'' do. + exist=: fexist +else. + exist=: 0: +end. +1 +) +fullname=: 3 : 0 +p=. '/' +d=. jpath y +if. </ d i. ':',p do. +elseif. (2{.d) -: 2#p do. +elseif. p ~: 1{.d do. + jcwdpath d +elseif. IFWIN do. + (2{.jcwdpath''),d +end. +) +getscripts=: 3 : 0 +if. 0=#y do. '' return. end. +if. 0=L.y do. + if. fexist y do. + y=. <y + else. + y=. cutnames y + end. +end. +y=. y -. Ignore, IFJHS#;:'plot viewmat' +if. 0=#y do. '' return. end. +ndx=. ({."1 Public) i. y +ind=. I. ndx < # Public +y=. ((ind { ndx) { 1 {"1 Public) ind } y +ind=. (i.#y) -. ind +if. #ind do. + sel=. ind { y + msk=. -. '.' e. &> sel + cnt=. +/ &> sel e. each <'/\' + ndx=. ind #~ msk *. cnt=1 + y=. (addfname each ndx { y) ndx } y + ndx=. ind #~ msk *. cnt > 0 + sel=. (<'~addons/') ,each (ndx{y) ,each <'.ijs' + smsk=. (1:@(1!:4) ::0:)@<@jpath &> sel + y=. (smsk#sel) (smsk#ndx) } y +end. +fullname each jpath each y +) +getpath=: ([: +./\. =&'/') # ] +recentmax=: 3 : '({.~ RecentMax <. #) ~.y' +recentfiles_add_j_=: 3 : 0 +RecentFiles_j_=: recentmax (<jpath y),RecentFiles_j_ +recentsave'' +) +recentproj_add=: 3 : 0 +RecentProjects_j_=: recentmax (<jpath y),RecentProjects_j_ +recentsave'' +) +recentsave=: 3 : 0 +n=. 'Folder RecentDirmatch RecentFif RecentFiles RecentProjects' +r=. 'NB. gtkide recent',LF2,nounrep n +r fwritenew jpath '~config/recent.dat' +) +xedit=: 0&$: : (4 : 0) +'file row'=. 2{.(boxopen y),<0 +if. IFJHS do. + xmr ::0: file + EMPTY return. +end. +editor=. (Editor_j_;Editor_nox_j_){::~ nox=. IFUNIX *. (0;'') e.~ <2!:5 'DISPLAY' +if. 0=#editor do. EMPTY return. end. +cmd=. editor stringreplace~ '%f';(dquote >@fboxname file);'%l';(":>:row) +try. + if. IFUNIX do. + if. x do. + 2!:1 cmd + else. + 2!:1 cmd, (0=nox+.(1 -.@e. 'term' E. editor)*.(1 e. '/vi' E. editor)+.'vi'-:2{.editor)#' &' + end. + else. + (x{0 _1) fork_jtask_ cmd + end. +catch. + msg=. '|Could not run the editor:',cmd,LF + msg=. msg,'|You can change the Editor definition in Edit|Configure|Base' + smoutput msg +end. +EMPTY +) +cocurrent 'z' +jpath=: jpath_j_ +load=: 3 : 0 +0 load y +: +fls=. getscripts_j_ y +fn=. ('script',x#'d')~ +for_fl. fls do. + if. Displayload_j_ do. smoutput > fl end. + if. -. fexist fl do. + smoutput 'not found: ',>fl + end. + fn fl + Loaded_j_=: ~. Loaded_j_,fl +end. +empty'' +) + +loadd=: 1&load +require=: 3 : 0 +fls=. Loaded_j_ -.~ getscripts_j_ y +if. # fls do. load fls else. empty'' end. +) +scripts=: scripts_j_ +show=: 3 : 0 +y=. y,(0=#y)#0 1 2 3 +if. (3!:0 y) e. 2 32 do. y=. cutopen y +else. y=. (4!:1 y) -. (,'y');,'y.' end. +wid=. {.wcsize'' +sub=. '.'&(I. @(e.&(9 10 12 13 127 254 255{a.))@]}) +j=. '((1<#$t)#(":$t),''$''),":,t' +j=. 'if. L. t=. ".y do. 5!:5 <y return. end.';j +j=. 'if. 0~:4!:0 <y do. 5!:5 <y return. end.';j +a=. (,&'=: ',sub @ (3 : j)) each y +; ((wid <. #&> a) {.each a) ,each LF +) +xedit=: xedit_j_ +wcsize=: 3 : 0 +if. (-.IFGTK+.IFJHS) *. UNAME-:'Linux' do. + |.@".@(-.&LF)@(2!:0) :: (Cwh_j_"_) '/bin/stty size 2>/dev/null' +else. + Cwh_j_ +end. +) +coclass 'jcompare' + +MAXPFX=: 100 +MAXLCS=: *: MAXPFX +cin=: e. , +fmt0=: 'p<0 [>q<] >' & (8!:0) +fmt1=: 'p<1 [>q<] >' & (8!:0) +lcs=: * * 1 + >./\@:(_1&|.)@:(>./\"1@:(_1&|."1)) +mindx=: }.@{.@/:~@(+/"1 ,. ]) +remltws=: 3 : 0 +y=. y, LF +dat=. <;._2 y +msk=. CR = {: &> dat +dat=. (-msk) }. each dat +fn=. #~ ([: (+./\ *. +./\.) -.@(e.&(' ',TAB))) +dat=. fn each dat +dat=. dat ,each msk{'';CR +}: ; dat ,each LF +) +comp=: 4 : 0 + +sep=. ((LF cin x) +. LF cin y) { CRLF +if. 2=#$x do. x=. <@dtb"1 x +else. x=. <;._2 x,sep -. {:x end. +if. 2=#$y do. y=. <@dtb"1 y +else. y=. <;._2 y,sep -. {:y end. +if. x -: y do. 'no difference' return. end. +XY=: x,y +AX=: X=: XY i. x +AY=: Y=: XY i. y +NX=: i.#x +NY=: i.#y +SX=: SY=: '' +while. compend'' do. complcs'' end. +sx=. /:~ SX +sy=. /:~ SY +x=. (fmt0 sx) ,each (sx { AX) { XY +y=. (fmt1 sy) ,each (sy { AY) { XY +r=. (x,y) /: (sx,.0),sy,.1 +}: ; r ,each LF +) +fcomp=: 4 : 0 +'p j n'=. 3 {. x +'ifws ifsep'=. 2 2 #: j +'x y'=. _2 {. ,&p each cutopen y +if. L. n do. + 'nx ny'=. n +else. + nx=. x [ ny=. y +end. +f=. 1!:1 :: _1: +tx=. f x=. fboxname x +if. tx -: _1 do. 'unable to read ',nx return. end. +ty=. f y=. fboxname y +if. ty -: _1 do. 'unable to read ',ny return. end. +tx=. f2utf8 tx +ty=. f2utf8 ty +if. ifsep do. + tx=. toJ tx + ty=. toJ ty +end. +if. ifws do. + tx=. remltws tx + ty=. remltws ty +end. +f=. _3&{.@('0'&,@(":@])) +mth=. _3[\' JanFebMarAprMayJunJulAugSepOctNovDec' +'a m d h n s'=. 6{.1 pick dx=. ,1!:0 x +fx=. (4":d),' ',(m{mth),' ::' 0 3 6 9};f &.> 100|a,h,n,s +'a m d h n s'=. 6{.1 pick dy=. ,1!:0 y +fy=. (4":d),' ',(m{mth),' ::' 0 3 6 9};f &.> 100|a,h,n,s +'nx ny'=. <"1>nx;ny +r=. 'comparing:',LF +r=. r,nx,fx,' ',(":2 pick dx),LF +r=. r,ny,fy,' ',(":2 pick dy),LF +r,tx compare ty +) + +compend=: 3 : 0 +old=. 0 0 +len=. (#X),#Y + +while. -. len -: old do. + old=. len + t=. <./len + m=. 0 i.~ (t {. X) = t {. Y + X=: m }. X + Y=: m }. Y + t=. m - t + n=. - +/ *./\. (t {. X) = t {. Y + X=: n }. X + Y=: n }. Y + NX=: m }. n }. NX + NY=: m }. n }. NY + m=. X e. Y + if. 0 e. m do. + SX=: SX,(-.m)#NX + X=: m # X + NX=: m # NX + end. + m=. Y e. X + if. 0 e. m do. + SY=: SY,(-.m)#NY + Y=: m # Y + NY=: m # NY + end. + len=. (#X),#Y +end. +if. -. 0 e. len do. 1 return. end. +SX=: SX,NX +SY=: SY,NY +0 +) +complcs=: 3 : 0 +lx=. #X +ly=. #Y +if. MAXLCS < lx * ly do. + select. MAXPFX < lx,ly + case. 0 1 do. + ly=. <. MAXLCS % lx + case. 1 0 do. + lx=. <. MAXLCS % ly + case. do. + lx=. ly=. MAXPFX + end. +end. +a=. lx {. X +b=. ly {. Y +m=. ((b =/ a),.0),0 +cm=. lcs ^:_ m +len=. >./ ,cm +rc=. 1 + mindx ($cm) #: I. len = ,cm +cm=. , rc {. cm +msk=. (1+i.len) =/ cm +ndx=. <@I."1 msk +pos=. ; (<rc) #: each ndx +pos=. (+/"1 pos),.pos +pos=. ((# &> ndx) # i.len),.pos +pos=. /:~ pos +'ib ia'=. |: 2 }."1 (~:{."1 pos)#pos +n=. 1 + {: ia +SX=: SX,(<<<ia) { n {. NX +X=: n }. X +NX=: n }. NX +n=. 1 + {: ib +SY=: SY,(<<<ib) { n {. NY +Y=: n }. Y +NY=: n }. NY +0 +) +compare=: 4 : 0 +if. x -: y do. 'no difference' return. end. +if. 0=#x do. 'empty left argument' return. end. +if. 0=#y do. 'empty right argument' return. end. +a=. conew 'jcompare' +r=. x comp__a y +coerase a +r +) +fcompare=: 3 : 0 +('';0) fcomp y +: +(x;0) fcomp y +) +fcompares=: 3 : 0 +('';1) fcomp y +: +(x;1) fcomp y +) +compare_z_=: compare_jcompare_ +fcompare_z_=: fcompare_jcompare_ +fcompares_z_=: fcompares_jcompare_ + +cocurrent <'base' \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/j/system/main/task.ijs @@ -0,0 +1,280 @@ +NB. task +NB. +NB. executing tasks with optional timeout or I/O +NB. +NB. TASKS WITHOUT I/O +NB. +NB. fork 'notepad.exe' NB. run notepad, no wait, no I/O +NB. 5000 fork 'notepad.exe' NB. run notepad, wait 5 sec, no I/O +NB. _1 fork 'notepad.exe' NB. run notepad, until closed, no I/O +NB. +NB. 5000 fork 'cmd /k dir' NB. show dir in cmd window for 5 sec and close +NB. _1 fork 'cmd /k dir' NB. show dir in cmd window until user closes it +NB. +NB. launch jpath'~system' NB. run default application, no wait +NB. +NB. TASKS WITH I/O +NB. +NB. spawn 'net users' NB. get stdout from process +NB. '+/i.3 4'spawn'jconsole' NB. call process with I/O +NB. 12 15 18 21 +NB. +NB. SHELL COMMANDS (WITH I/O) +NB. +NB. shell'echo.|time' NB. get result of shell command +NB. The current time is: 8:04:13.09 +NB. Enter the new time: +NB. +NB. (shell'dir /b')shell'find ".dll"' NB. get all DDL names by piping +NB. j.dll +NB. jregexp.dll +NB. +NB. NOTE: the implementation uses C-type structures +NB. by the original Method of Named Fields +NB. +NB. Script developed by Oleg Kobchenko. + +coclass <'jtask' +NB. task util + +int=: {.@:(_2&ic) +sint=: 2&ic + +i64=: {.@:(_3&ic) +si64=: 3&ic + +ptr=: int`i64@.IF64 +sptr=: sint`si64@.IF64 + +NB. ========================================================= +NB. METHOD OF NAMED FIELDS +sndx=: i.@#@[ + {.@I.@E. + +NB. struct=. 'valu' 'memb' sset structdef struct +sset=: 2 : '(m sndx n)}' + +NB. value=. 'memb' sget structdef struct +sget=: 2 : '(m sndx n)&{' + +szero=: # # (0{a.)"_ + +st64=: -.&'.'^:(-.IF64) + +t=. 'Cbyt....Resv....Desk....Titl....XposYposXsizYsizXcntYcnt' +STARTUPINFO=: st64 t,'FillFlagSwRs....Resv....Inph....Outh....Errh....' +PROCESSINFO=: st64 'Proh....Thrh....PridThid' +SECURITYATTR=: st64 'Cbyt....Secd....Inhe' + +'Outh Errh Inph Proh Thrh'=: ,"1&'....'^:IF64>;:'Outh Errh Inph Proh Thrh' + +STARTF_USESTDHANDLES=: 16b100 +STARTF_USESHOWWINDOW=: 1 +WAIT_TIMEOUT=: 258 +CREATE_NEW_CONSOLE=: 16b10 +DUPLICATE_SAME_ACCESS=: 2 + +cdk=: 1 : '(''kernel32 '',m)&cd' + +WaitForSingleObject=: 'WaitForSingleObject > i x i' cdk +CloseHandle=: 'CloseHandle > i x' cdk"0 +TerminateProcess=: 'TerminateProcess > i x i' cdk +ReadFile=: 'ReadFile > i x *c i *i x' cdk +WriteFile=: 'WriteFile > i x *c i *i x' cdk +GetCurrentProcess=: 'GetCurrentProcess > x' cdk + +DuplicateHandleF=: 'DuplicateHandle > i x x x *x i i i' cdk +CreatePipeF=: 'CreatePipe > i *x *x *c i' cdk +CreateProcessF=: 'CreateProcessW > i x *w x x i i x x *c *c' cdk + +DuplicateHandle=: 3 : 0 +p=. GetCurrentProcess '' +r=. DuplicateHandleF p;y;p;(h=.,_1);0;0;DUPLICATE_SAME_ACCESS +CloseHandle y +{.h +) + +NB. ========================================================= +NB. 'hRead hWrite'=. CreatePipe Inheritable=0 +NB. ... FileRead/FileWrite ... +NB. CloseHandle hRead,hWrite +NB. +NB. Inheritable: 0 none, 1 for read, 2 for write +CreatePipe=: 3 : 0 +'inh size'=. 2{.y,0 +sa=. szero SECURITYATTR +sa=. (sint #SECURITYATTR) 'Cbyt' sset SECURITYATTR sa +sa=. (sint *inh) 'Inhe' sset SECURITYATTR sa +r=. CreatePipeF (hRead=.,_1);(hWrite=.,_1);sa;size +hRead=. {. hRead +hWrite=. {. hWrite +if. 1=inh do. hRead=. DuplicateHandle hRead end. +if. 2=inh do. hWrite=. DuplicateHandle hWrite end. +hRead,hWrite +) + +NB. ========================================================= +NB. hProcess=. [hWriteOut[,hReadIn]] CreateProcess 'program agr1 agr2 ...' +NB. ... +NB. CloseHandle hProcess +CreateProcess=: 3 : 0 +'' CreateProcess y +: +'ow ir'=. 2{.x,0 +si=. szero STARTUPINFO +si=. (sint #STARTUPINFO) 'Cbyt' sset STARTUPINFO si +f=. inh=. 0 +if. +/ir,ow do. + inh=. 1 + f=. CREATE_NEW_CONSOLE + si=. (sint STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW) 'Flag' sset STARTUPINFO si + if. ow do. + si=. (sptr ow) Outh sset STARTUPINFO si + si=. (sptr ow) Errh sset STARTUPINFO si + end. + if. ir do. si=. (sptr ir) Inph sset STARTUPINFO si end. +end. +pi=. szero PROCESSINFO +r=. CreateProcessF 0;(uucp y);0;0;inh; f;0;0;si;pi +if. 0=r do. 0 return. end. +ph=. ptr Proh sget PROCESSINFO pi +th=. ptr Thrh sget PROCESSINFO pi +CloseHandle th +ph +) + +NB. ========================================================= +NB. ph=. h CreateProcess 'program agr1 agr2 ...' +NB. ... +NB. Wait ph;5000 +NB. CloseHandle ph +Wait=: 3 : 0 +r=. WaitForSingleObject y +if. WAIT_TIMEOUT=r do. TerminateProcess (0 pick y);_1 end. +) + +NB. ========================================================= +NB. ph=. h CreateProcess 'program agr1 agr2 ...' +NB. ... +NB. r=. ReadAll h +NB. CloseHandle h,ph +ReadAll=: 3 : 0 +ret=. '' +str=. 4096#'z' +while. 1 do. + r=. ReadFile y;str;(#str);(len=.,_1);0 + len=. {.len + if. (0=r)+.0=len do. + 'ec es'=: cderx'' + if. -.ec e.0 109 do. ret=. _1 end. + break. + end. + ret=. ret,len{.str +end. +ret +) + +NB. ========================================================= +NB. ph=. hr,hw CreateProcess 'program agr1 agr2 ...' +NB. r=. WriteAll hw +NB. CloseHandle hw +NB. r=. ReadAll hr +NB. CloseHandle hr,ph +WriteAll=: 3 : 0 +: +while. #x do. + r=. WriteFile y;x;(#x);(len=.,_1);0 + len=. {. len + if. (0=r)+.0=len do. + 'ec es'=: cderx'' + if. -.ec e.0 109 do. ret=. _1 end. + break. + end. + x=. len}.x +end. +1 +) +NB. task main + +NB. ========================================================= +NB.*fork v run task and optionally wait for completion +NB. +NB. form: [timeout=0] fork cmdline +NB. +NB. timeout: 0 no wait, _1 infinite, >0 timeout +NB. cmdline: 'shortcmd arg1 arg2 ...' +NB. cmdline: '"command with space" arg1 ...' +NB. +NB. e.g. fork 'notepad.exe' +fork=: (3 : 0)`(2!:1)@.IFUNIX +0 fork y +: +ph=. CreateProcess y +if. x do. Wait ph;x end. +CloseHandle ph +empty'' +) + +NB. ========================================================= +NB.*spawn v [monad] get stdout of executed task +NB. +NB. form: stdout=. spawn cmdline +NB. +NB. stdout: _1 fail, '' or stdout stream value if success +NB. cmdline: 'shortcmd arg1 arg2 ...' +NB. cmdline: '"command with space" arg1 ...' +NB. +NB. e.g. spawn 'net users' + +NB.*spawn v [dyad] send stdin and get stdout of task +NB. +NB. form: stdout=. [stdin=''] spawn cmdline +NB. +NB. stdin: input to stream as stdin, '' no input +NB. +NB. e.g. 'i.3 4'spawn'jconsole' +spawn=: (3 : 0)`(2!:0@])@.IFUNIX +'' spawn y +: +'or ow'=. CreatePipe 1 +'ir iw'=. CreatePipe 2,#x +ph=. (ow,ir) CreateProcess y +CloseHandle ir +if. #x do. x WriteAll iw end. +CloseHandle iw +CloseHandle ow +r=. ReadAll or +CloseHandle or +CloseHandle ph +r +) + +NB. ========================================================= +NB.*shell v [monad] get stdout of shell command +NB. +NB. e.g. shell 'dir /b/s' + +NB.*shell v [dyad] send stdin and get stdout of shell command +NB. +NB. e.g. (shell 'dir /b/s') shell 'find ".dll"' +SHELL=: IFUNIX{::'cmd /c ';'' + +shell=: ''&$: : (spawn SHELL,]) + +NB. ========================================================= +NB.*launch v [monad] launch default application for parameter +NB. +NB. launch jpath'~system' NB. file manager +NB. launch jpath'~bin/installer.txt' NB. text editor +NB. launch 'http://jsoftware.com' NB. web browser + +3 : 0'' +LAUNCH=: ('gnome-open';'open';'start') {::~ ('Linux';'Darwin')i.<UNAME +if. 0=nc<'LAUNCH_j_'do.if. 0<#LAUNCH_j_ do.LAUNCH=: LAUNCH_j_ end.end. +) +launch=: 3 : 'shell LAUNCH,'' '',y' +NB. task zdefs + +fork_z_=: fork_jtask_ +spawn_z_=: spawn_jtask_ +shell_z_=: shell_jtask_ +launch_z_=: launch_jtask_
new file mode 100644 --- /dev/null +++ b/j/system/util/boot.ijs @@ -0,0 +1,83 @@ +18!:4 <'z' NB. start in z + +NB. ========================================================= +startupconsole=: 3 : 0 +f=. jpath '~config/startup_console.ijs' +if. 1!:4 :: 0: <f do. + 18!:4 <'base' + try. + load f + catch. + smoutput 'An error occurred when loading startup script: ',f + end. +end. +) + +NB. ========================================================= +startupide=: 3 : 0 +startup=. jpath '~config/startup.ijs' +if. 1!:4 :: 0: <startup do. + 18!:4 <'base' + try. + load startup + catch. + smoutput 'An error occurred when loading startup script: ',startup + end. +end. +) + +NB. ========================================================= +3 : 0'' +ndx=. ({."1 SystemFolders_j_) i. <'system' +sys=. '/' ,~ > 1 { ndx { SystemFolders_j_ + +NB. --------------------------------------------------------- +NB. following assumes Displayload is set in immex, then +NB. the profile loaded. No need for another ijx window +if. 0=4!:0<'Displayload_j_' do. + Displayload_j_=: 1 + boot=. 3 : ('0!:0 <y[y 1!:2[2') @ jpathsep @ (sys&,) +else. + Displayload_j_=: 0 + boot=. 3 : '0!:0 <y' @ jpathsep @ (sys&,) +end. + +NB. --------------------------------------------------------- +boot 'main/stdlib.ijs' +load '~system/util/scripts.ijs' +load 'regex' +load 'task' +load '~system/util/configure.ijs' +load '~system/main/ctag.ijs' +load '~system/util/jadetag.ijs' +startupide'' + +NB. --------------------------------------------------------- +NB. JVERSION_z_ (used in about box) +r=. 'Engine: ',9!:14'' +r=. r,LF,'Library: ',LF -.~ 1!:1<jpath '~system/config/version.txt' +r=. r,LF,'Platform: ',UNAME,' ',IF64 pick '32';'64' +r=. r,LF,'Installer: ',1!:1 :: ('unknown'"_) <jpath'~bin/installer.txt' +r=. r,LF,'InstallPath: ',jpath '~install' +JVERSION=: toJ r + +NB. --------------------------------------------------------- +NB. set break +setbreak 'default' + +NB. --------------------------------------------------------- +ndx=. <./ ARGV i. '-jp';'-jprofile' +jsx=. ARGV i. <'-js' +if. ndx < #ARGV do. p=. 2 + ndx else. p=. 1 end. +load__ >{. p }. jsx {. ARGV + +if. jsx<#ARGV do. + ARGVVERB_z_=: 3 : ((>:jsx)}.ARGV) NB. define in z + ARGVVERB__'' NB. run in base +end. + +EMPTY +) + +NB. ========================================================= +18!:4 <'base' NB. end in base
new file mode 100644 --- /dev/null +++ b/j/system/util/configure.ijs @@ -0,0 +1,117 @@ +NB. configure + +cocurrent 'jcfg' +coinsert 'j' + +jdefs=: 0 : 0 +Browser +Browser_nox +DirTreeX +Format +EPSReader +PDFReader +RecentMax +XDiff +Tags +UserDict +Editor +Editor_nox +) + +cbname=: {.~ i.&' ' <. i.&'=' + +NB. ========================================================= +cpath=: 3 : 0 +if. -. '~' e. {.&> {:"1 y do. y return. end. +({."1 y),.jpath each {:"1 y +) + +NB. ========================================================= +cbread=: 3 : 0 +dat=. 'b' freads y +if. dat -: _1 do. return. end. +dat=. dat #~ (<'NB.') ~: 3 {. each dat +dat=. dat #~ '#' ~: {.&> dat +dat=. deb each dat +dat #~ 0 < #&> dat +) + +NB. ========================================================= +cbread1=: 3 : 0 +r=. cbread jpath '~config/',y +if. r -: _1 do. cbread jpath '~system/config/',y end. +) + +NB. ========================================================= +cbread2=: 3 : 0 +r0=. cbread jpath '~system/config/',y +if. r0 -: _1 do. r0=. <'' end. NB. avoid domain error +r1=. cbread jpath '~config/',y +if. (0=#r1) +. r1 -: _1 do. r0 return. end. +n0=. cbname each r0 +n1=. cbname each r1 +if. 0 = #n0 -. n1 do. r1 return. end. +new=. (-.n0 e. n1) # r0 +r=. LF2,'NB. ',(50#'='),LF,'NB. new configs',LF,;new,each LF +r fappends jpath '~config/',y +r1,new +) + +NB. ========================================================= +configbase=: 3 : 0 +Snapshots_j_=: 0 +0!:100 ;LF ,each cbread2 'base.cfg' +9!:3 DisplayForm +9!:7 BoxForm { Boxes +9!:17 BoxPos +9!:21 (2&^ ^: (<&_)) MemoryLimit +9!:37 Output +0!:100 ;(}:,'_j_=:',]) each <;.2 jdefs +EMPTY +) + +NB. ========================================================= +configfolders=: 3 : 0 +UserFolders_j_=: i.0 2 +if. IFWIN do. + BINPATH_z_=: filecase BINPATH_z_ + sf=. filecase each {:"1 SystemFolders_j_ + SystemFolders_j_=: ({."1 SystemFolders_j_),.sf +end. +dat=. cbread1 'folders.cfg' +if. (0=#dat) +. dat -: _1 do. return. end. +ndx=. dat i.&> ' ' +ids=. ndx {.each dat +pts=. jpath each filecase each (ndx+1) }. each dat +uf=. ids,.pts +msk=. (=tolower) {.&>ids +SystemFolders_j_=: SystemFolders,msk#uf +UserFolders_j_=: (-.msk)#uf +SystemFolders_j_=: cpath SystemFolders_j_ +UserFolders_j_=: cpath UserFolders_j_ +EMPTY +) + +NB. ========================================================= +configrecent=: 3 : 0 +Folder=: RecentDirmatch=: RecentFif=: RecentFiles=: RecentProjects=: '' +0!:0 ::] < jpath '~config/recent.dat' +Folder_j_=: Folder #~ (<Folder) e. {."1 UserFolders +RecentDirmatch_j_=: ~. fexists cutLF RecentDirmatch +RecentFif_j_=: ~. cutLF RecentFif +RecentFiles_j_=: ~. fexists cutLF RecentFiles +RecentProjects_j_=: ~. fexists cutLF RecentProjects +RecentProjects_j_=: RecentProjects_j_ #~ '~' = {.&> tofoldername each RecentProjects_j_ +EMPTY +) + +NB. ========================================================= +configrun=: 3 : 0 +configbase'' +configfolders'' +configrecent'' +coerase <'jcfg' +18!:4<'z' +) + +configrun$0
new file mode 100644 --- /dev/null +++ b/j/system/util/jadetag.ijs @@ -0,0 +1,10 @@ +NB. initialise system default ctag and define z locale names + +coclass 'jadetag' +coinsert 'ctag' + +Tags=: Tags_j_ +absolutepath=: 1 +cleartags'' +nms=. <;._1 ' cleartags loadtags ta tagcp tagopen tagselect' +". > nms ,each (<'_z_=:') ,each nms ,each (<'_jadetag_')
new file mode 100644 --- /dev/null +++ b/j/system/util/pacman.ijs @@ -0,0 +1,899 @@ +cocurrent 'jpacman' +coinsert 'j' + +BASELIB=: 'base library' +DATAMASK=: 0 +HWNDP=: '' +ISGUI=: 0 +ONLINE=: 0 +PKGDATA=: 0 7$a: +SECTION=: ,<'All' +SYSNAME=: 'Package Manager' +TIMEOUT=: 60 +WWWREV=: REV=: _1 +3 : 0'' +nc=. '--no-cache' +if. IFUNIX do. + if. UNAME-:'Darwin' do. + HTTPCMD=: 'curl -o %O --stderr %L -f -s -S %U' + else. + try. nc=. nc #~ 1 e. nc E. shell 'wget --help' catch. nc=. '' end. + HTTPCMD=: 'wget ',nc,' -O %O -o %L -t %t %U' + end. +else. + exe=. '"',(jpath '~tools/ftp/wget.exe'),'"' + try. nc=. nc #~ 1 e. nc E. shell exe,' --help' catch. nc=. '' end. + HTTPCMD=: exe,' ',nc,' -O %O -o %L -t %t -T %T %U' + UNZIP=: '"',(jpath '~tools/zip/unzip.exe'),'" -o -C ' +end. +) +setfiles=: 3 : 0 +ADDCFG=: jpath '~addons/config/' +makedir ADDCFG +ADDCFGIJS=: ADDCFG,'config.ijs' +JRELEASE=: ({.~i.&'/') 9!:14'' +LIBTREE=: readtree'' +WWW=: 'http://www.jsoftware.com/jal/',JRELEASE,'/' +LIBVER=: jpath '~system/config/version.txt' +) +destroy=: codestroy +CFGFILES=: <;._2 (0 : 0) +addons.txt +library.txt +release.txt +revision.txt +zips.txt +) +LIBDESC=: 0 : 0 +This is the base library of scripts and labs included in the J system. + +Reinstalling or upgrading this library will overwrite files in the system subdirectory. Restart J afterwards. + +Files outside the system subdirectory, such as profile.ijs, are not changed. +) +cutjal=: ([: (* 4 > +/\) ' ' = ]) <;._1 ] +cutjsp=: ([: (* 5 > +/\) ' ' = ]) <;._1 ] +dquote=: '"'&, @ (,&'"') +fname=: #~ ([: *./\. ~:&'/') +hostcmd=: [: 2!:0 '(' , ] , ' || true)'"_ +ischar=: 2 = 3!:0 +rnd=: [ * [: <. 0.5 + %~ +sep2under=: '/' & (I.@('_' = ])}) +termLF=: , (0 < #) # LF -. {: +todel=: ; @: (DEL&, @ (,&(DEL,' ')) each) +tolist=: }. @ ; @: (LF&,@,@":each) +getintro=: ('...' ,~ -&3@[ {. ])^:(<#) +info=: smoutput +getnames=: 3 : 0 + select. L.y + case. 0 do. + if. +/ BASELIB E. y do. + y=. (<BASELIB), cutnames y rplc BASELIB;'' + else. + y=. cutnames y + end. + case. 1 do. + if. 2 = #$y do. + y=. {."1 y + else. + y=. ,y + end. + case. do. + '' return. + end. + y +) +curtailcaption=: 3 : 0 + idx=. <_1;~I. 45<#&>{:"1 y + y=. (45&getintro &.> idx{y) idx}y +) +deltree=: 3 : 0 + try. + res=. 0< ferase {."1 dirtree y + *./ res,0<ferase |.dirpath y + catch. 0 end. +) +fixjal=: 3 : 0 +if. 2 > #y do. i.0 5 return. end. +m=. _2 |. (LF,')',LF) E. y +r=. _2 }. each m <;._2 y +x=. r i.&> LF +d=. (x+1) }.each r +r=. x {.each r +r=. 3 {."1 cutjal &> ' ' ,each r +x=. d i.&> LF +c=. x {.each d +d=. (x+1) }.each d +r,.c,.d +) +fixjal2=: 3 : 0 +if. 2 > #y do. i.0 2 return. end. +cutjal &> ' ' ,each <;._2 y +) +fixjsp=: 3 : 0 +if. 2 > #y do. i.0 5 return. end. +m=. _2 |. (LF,')',LF) E. y +r=. _2 }. each m <;._2 y +x=. r i.&> LF +d=. (x+1) }.each r +r=. x {.each r +r=. ' ' ,each r +(cutjsp &> r),.d +) +fixlib=: 3 : 0 +msk=. (<LIBTREE) = 1 {"1 y +if. -. 1 e. msk do. ($0);'';0 return. end. +'ver fln siz'=. 2 4 5 { (msk i.1) { y +ver=. fixver ver +ver;fln;siz +) +fixlibs=: 3 : 0 +if. 2 > #y do. + i.0 6 return. +end. +fls=. <;._2 y +ndx=. fls i.&> ' ' +siz=. <&> 0 ". (ndx+1) }.&> fls +fls=. ndx {.each fls +zps=. <;._2 &> fls ,each '_' +pfm=. 3 {"1 zps +msk=. IFUNIX ~: (1 e. 'win'&E.) &> pfm +msk # zps,.fls,.siz +) +fixrev=: 3 : 0 +{. _1 ". :: _1: y -. CRLF +) +fixupd=: 3 : 0 +_1 ". :: _1: y -. CRLF +) +fixver=: 3 : 0 +if. ischar y do. + y=. y -. CRLF + y=. 0 ". ' ' (I. y='.') } y +end. +3 {. y +) +fixvers=: 3 : 0 +s=. $y +y=. ,y +3 {."1 [ 0 ". s $ ' ' (I. y e. './') } y +) +fmtjal=: 3 : 0 +if. 0 = #y do. '' return. end. +r=. (4 {."1 y) ,each "1 ' ',LF2 +r=. <@; "1 r +; r ,each ({:"1 y) ,each <')',LF +) +fmtjal2=: 3 : 0 +if. 0 = #y do. '' return. end. +; (2 {."1 y) ,each "1 ' ',LF +) +fmtdep=: 3 : 0 +}. ; ',' ,each a: -.~ <;._2 y +) +fmtjsp=: 3 : 0 +if. 0 = #y do. '' return. end. +r=. (4 {."1 y) ,each "1 ' ',LF +r=. <@; "1 r +; r ,each ({:"1 y) ,each <')',LF +) +fmtlib=: 3 : 0 +, 'q<.>,q<.>r<0>3.0,r<0>3.0' 8!:2 y +) +fmtver=: 3 : 0 +if. 0=#y do. '' return. end. +if. ischar y do. y return. end. +}. ; '.' ,each ": each y +) +fmtverlib=: 3 : 0 +fmtver y +) +fixzips=: 3 : 0 +if. 2 > #y do. i.0 5 return. end. +fls=. <;._2 y +ndx=. fls i.&> ' ' +siz=. 0 ". (ndx+1) }.&> fls +fls=. ndx {.each fls +zps=. <;._2 &> fls ,each '_' +zps=. zps,.fls,.<&>siz +pfm=. 3 {"1 zps +lnx=. (1 e. 'linux'&E.) &> pfm +mac=. (1 e. 'darwin'&E.) &> pfm +win=. mac < (1 e. 'win'&E.) &> pfm + +select. UNAME +case. 'Win' do. + zps=. win # zps +case. 'Linux' do. + zps=. lnx # zps +case. 'Darwin' do. + zps=. (lnx +. mac) # zps + zps=. zps /: 3 {"1 zps + zps=. (~: 3 {."1 zps) # zps +end. + +bit=. IF64 pick '64';'32' +pfm=. 3 {"1 zps +exc=. (1 e. bit&E.) &> pfm +zps=. zps \: exc +zps=. (~: 3 {."1 zps) # zps +fnm=. 0 {"1 zps +lnm=. 1 {"1 zps +ver=. 2 {"1 zps +pfm=. 3 {"1 zps +fls=. 4 {"1 zps +siz=. 5 {"1 zps +nms=. fnm ,each '/' ,each lnm +pfm=. (pfm i.&> '.') {.each pfm +ndx=. \: # &> pfm +sort ndx { nms,.pfm,.ver,.fls,.siz +) +fwritenew=: 4 : 0 +if. x -: fread y do. + 0 +else. + x fwrite y +end. +) +platformparent=: 3 : 0 +((< _2 {. y) e. '32';'64') # _2 }. y +) +makedir=: 1!:5 :: 0: @ < +plural=: 4 : 0 +y,(1=x)#'s' +) +sizefmt=: 3 : 0 +select. +/ y >: 1e3 1e4 1e6 1e7 1e9 +case. 0 do. + (": y), ' byte',(y~:1)#'s' +case. 1 do. + (": 0.1 rnd y%1e3),' KB' +case. 2 do. + (": 1 rnd y%1e3),' KB' +case. 3 do. + (": 0.1 rnd y%1e6),' MB' +case. 4 do. + (": 1 rnd y%1e6),' MB' +case. do. + (": 0.1 rnd y%1e9),' GB' +end. +) +shellcmd=: 3 : 0 +if. IFUNIX do. + hostcmd y +else. + spawn_jtask_ y +end. +) +subdir=: 3 : 0 +if. 0=#y do. '' return. end. +a=. 1!:0 y,'*' +if. 0=#a do. '' return. end. +a=. a #~ '-d' -:"1 [ 1 4 {"1 > 4 {"1 a +(<y) ,each ({."1 a) ,each '/' +) +testaccess=: 3 : 0 +f=. <jpath'~bin\installer.txt' +d=. 1!:1 f +try. + 1!:55 f + d 1!:2 f + 1 +catch. + 0 +end. +) +toupper1=: 3 : 0 +if. 0=#y do. '' return. end. +(toupper {. y),tolower }. y +) +unzip=: 3 : 0 +'file dir'=. dquote each y +e=. 'Unexpected error' +if. IFUNIX do. + e=. shellcmd 'tar -xzf ',file,' -C ',dir +else. + dir=. (_2&}. , '/' -.~ _2&{.) dir + e=. shellcmd UNZIP,' ',file,' -d ',dir +end. +e +) +zipext=: 3 : 0 +y, IFUNIX pick '.zip';'.tar.gz' +) +CHECKADDONSDIR=: 0 : 0 +The addons directory does not exist and cannot be created. + +It is set to: XX. + +You can either create the directory manually, or set a new addons directory in your profile script. +) +CHECKASK=: 0 : 0 +Read catalog from the server using Internet connection now? + +Otherwise the local catalog is used offline. +) +CHECKONLINE=: 0 : 0 +An active Internet connection is needed to install packages. + +Continue only if you have an active Internet connection. + +OK to continue? +) +CHECKREADSVR=: 0 : 0 +An active Internet connection is needed to read the server repository catalog. + +Continue only if you have an active Internet connection. + +OK to continue? +) +CHECKSTARTUP=: 0 : 0 +Setup repository using Internet connection now? + +Select No if not connected, to complete setup later. After Setup is done, repository can be used offline with more options in Tools menu and Preferences dialog. +) +checkaccess=: 3 : 0 +if. testaccess'' do. 1 return. end. +msg=. 'Unable to run Package Manager, as you do not have access to the installation folder.' +if. IFWIN do. + msg=. msg,LF2,'To run as Administrator, right-click the J icon, select Run as... and ' + msg=. msg,'then select Adminstrator.' +end. +info msg +0 +) +checkaddonsdir=: 3 : 0 +d=. jpath '~addons' +if. # 1!:0 d do. 1 return. end. +if. 1!:5 :: 0: <d do. + log 'Created addons directory: ',d + 1 return. +end. +info CHECKADDONSDIR rplc 'XX';d +0 +) +getonline=: 3 : 0 +ONLINE=: mbnoyes y +) +getserver=: 3 : 0 +'rc p'=. httpgetr (WWW,'revision.txt');2 +if. rc do. 0 return. end. +write_lastupdate'' +WWWREV=: fixrev p +if. WWWREV = REV do. 1 return. end. +refreshweb'' +) +checkonline=: 3 : 0 +select. ReadCatalog +case. 0 do. + if. REV >: 0 do. + ONLINE=: 0 + log 'Using local copy of catalog. See Preferences to change the setting.' + 1 return. + end. + if. 0 = getonline 'Read Catalog from Server';CHECKREADSVR do. 0 return. end. +case. 1 do. + ONLINE=: 1 +case. 2 do. + if. REV >: 0 do. + if. 0 = getonline 'Read Catalog from Server';CHECKASK do. + log 'Using local copy of catalog. See Preferences to change the setting.' + 1 return. + end. + else. + if. 0 = getonline 'Setup Repository';CHECKSTARTUP do. 0 return. end. + end. +end. +log 'Updating server catalog...' +if. 0 = getserver'' do. + ONLINE=: 0 + log 'Working offline using local copy of catalog.' +else. + log 'Done.' +end. +1 +) +checkstatus=: 3 : 0 +if. 0 e. #LIBS do. '' return. end. +msk=. masklib PKGDATA +ups=. pkgups'' +libupm=. 1 e. msk *. ups +msk=. -. msk +addnim=. +/msk *. pkgnew'' +addupm=. +/msk *. pkgups'' +tot=. +/addnim,addupm,libupm +if. 0 = tot do. + 'All available packages are installed and up to date.' return. +end. +select. 0 < addnim,addupm +case. 0 0 do. + msg=. 'Addons are up to date.' +case. 0 1 do. + msg=. 'All addons are installed, ',(":addupm), ' can be updated.' +case. 1 0 do. + if. addnim = <:#PKGDATA do. + msg=. 'No addons are installed.' + else. + j=. ' addon',('s'#~1<addnim),' are not yet installed.' + msg=. 'Installed addons are up to date, ',(":addnim),j + end. +case. 1 1 do. + j=. (":addupm),' addon',('s'#~1<addupm),' can be updated, ' + msg=. j,(":addnim), ' addon',('s'#~1<addnim),' are not yet installed.' +end. +if. 0 = libupm do. + msg,LF,'The base library is up to date.' +else. + msg,LF,'There is a newer version of the base library.' +end. +) + +write_lastupdate=: 3 : 0 +txt=. ": 6!:0 '' +txt fwrites ADDCFG,'lastupdate.txt' +) +checklastupdate=: 3 : 0 +if. _1 -: LASTUPD do. + res=. 'has never been updated.' +else. + res=. 'was last updated: ',timestamp LASTUPD +end. +'Local JAL information ',res +) +PACMANCFG=: jpath '~config/pacman.cfg' + +readconfig=: 3 : 0 +ReadCatalog=: 2 +0!:0 :: ] <PACMANCFG +) +httpget=: 3 : 0 +'f t'=. 2 {. (boxxopen y),a: +n=. f #~ -. +./\. f e. '=/' +p=. jpath '~temp/',n +q=. jpath '~temp/httpget.log' +t=. ":{.t,3 +ferase p;q +fail=. 0 +cmd=. HTTPCMD rplc '%O';(dquote p);'%L';(dquote q);'%t';t;'%T';(":TIMEOUT);'%U';f +try. + e=. shellcmd cmd +catch. fail=. 1 end. +if. fail +. 0 >: fsize p do. + if. _1-:msg=. freads q do. + if. 0=#msg=. e do. msg=. 'Unexpected error' end. end. + log 'Connection failed: ',msg + info 'Connection failed:',LF2,msg + r=. 1;msg + ferase p;q +else. + r=. 0;p + ferase q +end. +r +) +httpgetr=: 3 : 0 +res=. httpget y +if. 0 = 0 pick res do. + f=. 1 pick res + txt=. freads f + ferase f + 0;txt +end. +) +install=: 3 : 0 +dat=. y +'num siz'=. pmview_applycounts dat +many=. 1 < num +msg=. 'Installing ',(":num),' package',many#'s' +msg=. msg,' of ',(many#'total '),'size ',sizefmt siz +log msg +installdo 1 {"1 dat +log 'Done.' +readlocal'' +pacman_init 0 +) +install_console=: 3 : 0 + if. -. init_console 'server' do. '' return. end. + pkgs=. getnames y + if. pkgs -: ,<'all' do. pkgs=. 1 {"1 PKGDATA end. + pkgs=. pkgs (e. # [) ((pkgnew +. pkgups) # 1&{"1@]) PKGDATA + if. 0 = num=. #pkgs do. '' return. end. + many=. 1 < num + msg=. 'Installing ',(":num),' package',many#'s' + log msg + installdo pkgs + log 'Done.' + readlocal'' + pacman_init '' + checkstatus'' +) +upgrade_console=: 3 : 0 + if. -. init_console 'read' do. '' return. end. + pkgs=. getnames y + if. (0=#pkgs) +. pkgs -: ,<'all' do. pkgs=. 1{"1 PKGDATA end. + pkgs=. pkgs (e. # [) (pkgups # 1&{"1@])PKGDATA + install_console pkgs +) +installdo=: 3 : 0 +msk=. -. y e. <BASELIB +if. 0 e. msk do. + install_library'' +end. +install_addon each msk # y +) +install_addon=: 3 : 0 +ndx=. ({."1 ZIPS) i. <y +if. ndx = #ZIPS do. EMPTY return. end. +log 'Downloading ',y,'...' +f=. 3 pick ndx { ZIPS +'rc p'=. httpget WWW,'addons/',f +if. rc do. return. end. +log 'Installing ',y,'...' +msg=. unzip p;jpath'~addons' +ferase p +if. 0>:fsize jpath'~addons/',y,'/manifest.ijs' do. + log 'Extraction failed: ',msg + info 'Extraction failed:',LF2,msg + return. +end. +install_addins y +install_config y +) +install_addins=: 3 :0 +fl=. ADDCFG,'addins.txt' +ins=. fixjal2 freads fl +ins=. ins #~ (<y) ~: {."1 ins +ndx=. ({."1 ADDONS) i. <y +ins=. sort ins, 2 {. ndx { ADDONS +(fmtjal2 ins) fwrites fl +) +install_config=: 3 : 0 +ADDLABS=: '' +0!:0 :: ] < ADDCFGIJS +install_labs y +write_config'' +) +install_labs=: 3 : 0 +labs=. dirtree jpath '~addons/',y,'/*.ijt' +if. 0=#labs do. return. end. +pfx=. jpath '~addons/' +labs=. (#pfx) }.each {."1 labs +LABCATEGORY=: '' +0!:0 ::] <jpath '~addons/',y,'/manifest.ijs' +cat=. LABCATEGORY +if. 0 = #cat do. + cat=. toupper1 (y i. '/') {. y +end. +new=. labs ,each <' ',cat +txt=. sort ~. new,<;._2 ADDLABS +ndx=. 4 + (1 i.~ '.ijt'&E.) &> txt +msk=. fexist &> (<pfx) ,each ndx {.each txt +txt=. msk # txt +ADDLABS=: ; txt ,each LF +) +install_library=: 3 : 0 +log 'Downloading base library...' +f=. 1 pick LIB +'rc p'=. httpget WWW,'library/',f +if. rc do. return. end. +log 'Installing base library...' +unzip p;jpath'~system' +ferase p +readlin'' +) +write_config=: 3 : 0 +txt=. 'NB. Addon configuration',LF2 +txt=. txt,'ADDLABS=: 0 : 0',LF,ADDLABS,')',LF +txt fwrites ADDCFGIJS +) +show_console=: 4 : 0 + if. -. init_console 'read' do. '' return. end. + select. x + case. 'search' do. + pkgs=. getnames y + res=. (pkgsearch pkgs) # 1 2 3 4 {"1 PKGDATA + res=. curtailcaption res + case. 'show' do. + pkgs=. getnames y + if. pkgs -: ,<'all' do. pkgs=. 1 {"1 PKGDATA end. + res=. (msk=. pkgshow pkgs) # 5 {"1 PKGDATA + if. #res do. + res=. ,((<'== '), &.> msk # 1 {"1 PKGDATA) ,. res + res=. (2#LF) joinstring (70&foldtext)&.> res + end. + case. 'showinstalled' do. + res=. (-.@pkgnew # 1 2 3 4&{"1@])PKGDATA + res=. curtailcaption res + case. 'shownotinstalled' do. + res=. (pkgnew # 1 3 4&{"1@])PKGDATA + res=. curtailcaption res + case. 'showupgrade' do. + res=. (pkgups # 1 2 3 4&{"1@])PKGDATA + res=. curtailcaption res + case. 'status' do. + res=. checklastupdate'' + res=. res,LF,checkstatus'' + end. + res +) +showfiles_console=: 4 : 0 + if. -. init_console 'read' do. '' return. end. + pkgs=. getnames y + pkgs=. pkgs (e. # [) (-.@pkgnew # 1&{"1@]) PKGDATA + pkgs=. pkgs -. <BASELIB + if. 0=#pkgs do. '' return. end. + fn=. (<'~addons/') ,&.> (pkgs) ,&.> <'/',x,(x-:'history'){::'.ijs';'.txt' + res=. res #~ msk=. (<_1) ~: res=. fread@jpath &.> fn + if. #res do. + res=. ,((<'== '), &.> msk#pkgs) ,. res + res=. (2#LF) joinstring res + end. +) +remove_console=: 3 : 0 + if. -. init_console 'edit' do. '' return. end. + pkgs=. getnames y + if. pkgs -: ,<'all' do. pkgs=. 1 {"1 PKGDATA end. + pkgs=. pkgs (e. # [) (-.@pkgnew # 1&{"1@]) PKGDATA + pkgs=. pkgs -. <BASELIB + if. 0 = num=. #pkgs do. '' return. end. + many=. 1 < num + msg=. 'Removing ',(":num),' package',many#'s' + log msg + remove_addon each pkgs + log 'Done.' + readlocal'' + pacman_init '' + checkstatus'' +) + +remove_addon=: 3 : 0 + log 'Removing ',y,'...' + treepath=. jpath '~addons/',y + if. ((0 < #@dirtree) *. -.@deltree) treepath do. + nf=. #dirtree treepath + nd=. <: # dirpath treepath + nd=. nd + (tolower treepath) e. dirpath jpath '~addons/', '/' taketo y + msg=. (":nd),' directories and ',(":nf),' files not removed.' + log 'Remove failed: ',msg + info 'Remove failed:',LF2,msg + return. + end. + remove_addins y + remove_config y +) +remove_addins=: 3 :0 + fl=. ADDCFG,'addins.txt' + ins=. fixjal2 freads fl + ins=. ins #~ (<y) ~: {."1 ins + (fmtjal2 ins) fwrites fl +) +remove_config=: 3 : 0 + ADDLABS=: '' + 0!:0 :: ] < ADDCFGIJS + remove_labs y + write_config'' +) +remove_labs=: 3 : 0 + txt=. <;._2 ADDLABS + txt=. txt #~ (<jpathsep y) ~: (#y)&{. each txt + ADDLABS=: ; txt ,each LF +) +LOG=: 1 +LOGMAX=: 100 +log=: 3 : 0 +if. LOG do. smoutput y end. +) +logstatus=: 3 : 0 +if. ONLINE do. + log checkstatus'' +end. +) +readlin=: 3 : 0 +LIN=: 6 1 1 >. fixver freads LIBVER +) +readlocal=: 3 : 0 +readlin'' +ADDONS=: fixjal freads ADDCFG,'addons.txt' +ADDINS=: fixjal2 freads ADDCFG,'addins.txt' +REV=: fixrev freads ADDCFG,'revision.txt' +LASTUPD=: fixupd freads ADDCFG,'lastupdate.txt' +LIBS=: fixlibs freads ADDCFG,'library.txt' +LIB=: fixlib LIBS +ZIPS=: fixzips freads ADDCFG,'zips.txt' +EMPTY +) +readtree=: 3 : 0 +f=. ADDCFG,'tree.txt' +tree=. LF -.~ freads f +if. -. (<tree) e. 'current';'stable' do. + tree=. 'current' + writetree tree +end. +tree +) +writetree=: 3 : 0 +y fwritenew ADDCFG,'tree.txt' +) +refreshweb=: 3 : 0 +if. 0 = refreshjal'' do. 0 return. end. +readlocal'' +1 +) +refreshaddins=: 3 : 0 +ADDLABS=: '' +f=. ADDCFG,'addins.txt' +p=. jpath '~addons/' +sd=. ;subdir each subdir p +if. 0=#sd do. + '' fwrite f + write_config'' return. +end. +r=. s=. '' +for_d. sd do. + mft=. freads (>d),'manifest.ijs' + if. mft -: _1 do. continue. end. + VERSION=: '' + 0!:100 mft + ver=. fmtver fixver VERSION + n=. }: (#p) }. >d + n=. '/' (I.n='\') } n + r=. r,n,' ',ver,LF + s=. s,d +end. +r fwritenew f +s=. (#p) }.each }: each s +install_labs each s +write_config'' +) +refreshjal=: 3 : 0 +'rc p'=. httpget WWW,zipext 'jal' +if. rc do. 0 return. end. +unzip p;ADDCFG +ferase p +if. *./ CFGFILES e. {."1 [ 1!:0 ADDCFG,'*' do. 1 return. end. +msg=. 'Could not install the local repository catalog.' +log msg +info msg +0 +) +updatejal=: 3 : 0 + log 'Updating server catalog...' + if. -. init_console 'server' do. '' return. end. + refreshaddins'' + readlocal'' + pacman_init'' + res=. checklastupdate'' + res,LF,checkstatus'' +) +RELIBMSG=: 0 : 0 +You are now using the XX base library, and can switch to the YY base library. + +This will download the YY version of the base library and overwrite existing files. Addons are not affected. + +OK to switch to the YY library? +) +prelib=: 3 : 0 +old=. LIBTREE +new=. (('stable';'current') i. <old) pick 'current';'beta' +msg=. RELIBMSG rplc ('XX';'YY'),.old;new +if. 0 = query SYSNAME;msg do. + info 'Not done.' return. +end. +switchlibrary 1 pick new +) +switchlibrary=: 3 : 0 +ferase LIBVER +writetree LIBTREE=: y +refreshjal'' +readlocal'' +pmview_setpn'' +) +masklib=: 3 : 0 +(1 {"1 y) = <BASELIB +) +pkglater=: 3 : 0 +if. 0=#PKGDATA do. $0 return. end. +loc=. fixvers > 2 {"1 PKGDATA +srv=. fixvers > 3 {"1 PKGDATA +{."1 /:"2 srv ,:"1 loc +) +pkgnew=: 3 : 0 +0 = # &> 2 {"1 PKGDATA +) +pkgups=: 3 : 0 +(pkgnew'') < pkglater'' +) +pkgsearch=: 3 : 0 + +./"1 +./ y E."1&>"(0 _) 1{"1 PKGDATA +) +pkgshow=: 3 : 0 + y e.~ 1{"1 PKGDATA +) +setshowall=: 3 : 0 +PKGDATA=: (<y) (<(I.DATAMASK);0) } PKGDATA +) +setshownew=: 3 : 0 +ndx=. I. DATAMASK *. pkgnew'' +PKGDATA=: (<y) (<ndx;0) } PKGDATA +) +setshowups=: 3 : 0 +ndx=. I. DATAMASK *. pkgups'' +PKGDATA=: (<y) (<ndx;0) } PKGDATA +) +splitlib=: 3 : 0 +if. 0=#y do. + 2 $ <y return. +end. +msk=. masklib y +(msk#y) ; <(-.msk)#y +) +pacman_init=: 3 : 0 +dat=. ADDONS #~ ({."1 ADDONS) e. {."1 ZIPS +if. 0=#dat do. + dat=. i.0 6 +else. + ndx=. ({."1 ADDINS) i. {."1 dat + ins=. ndx { (1 {"1 ADDINS),<'' + dat=. dat,.<'' + dat=. 0 5 1 3 4 2 {"1 dat + dat=. ins 1 }"0 1 dat +end. +lib=. 'base library';(fmtver LIN);(fmtver 0 pick LIB);'base library scripts';LIBDESC;'' +dat=. dat,lib +dat=. (<0),.dat +PKGDATA=: sort dat +nms=. 1 {"1 PKGDATA +nms=. ~. (nms i.&> '/') {.each nms +SECTION=: 'All';nms +DATAMASK=: (#PKGDATA) $ 1 +EMPTY +) +init_console=: 3 : 0 + if. 0=#y do. y=. 'read' end. + select. y + fcase. 'edit';'server' do. + if. -. checkaccess'' do. 0 return. end. + case. 'read' do. + readconfig'' + if. -. checkaddonsdir'' do. 0 return. end. + setfiles'' + readlocal'' + pacman_init '' + res=. 1 + case. do. res=. 0 + end. + if. y -: 'server' do. res=. getserver'' end. + res +) +jpkg=: 4 : 0 + select. x + case. 'history';'manifest' do. + x showfiles_console y + case. 'install' do. + install_console y + case. 'reinstall' do. + remove_console y + install_console y + case. 'remove' do. + remove_console y + case. ;:'show search showinstalled shownotinstalled showupgrade status' do. + x show_console y + case. 'update' do. + updatejal '' + case. 'upgrade' do. + upgrade_console y + case. do. + msg=. 'Valid options are:',LF + msg=. msg,' history, install, manifest, remove, reinstall, show, search,',LF + msg=. msg,' showinstalled, shownotinstalled, showupgrade, status,',LF + msg,' update, upgrade' + end. +) +jpkg_z_=: 3 : 0 + 'help' jpkg y + : + a=. conew 'jpacman' + res=. x jpkg__a y + destroy__a'' + res +)
new file mode 100644 --- /dev/null +++ b/j/system/util/pm.ijs @@ -0,0 +1,860 @@ +coclass 'jpm' + +SIZE=: 1e7 +SCREENGLOBALS=: 0 +unpack=: 6!:11 +counter=: 6!:12 +stats=: 6!:13 +start=: 3 : 0 +'' start y +: +reset'' +x=. 2 {. x, (#x) }. 1 0 +if. (0 < #y) *: 2 = 3!:0 y do. + y=. ({. y, SIZE) $ ' ' +end. +([ [: (6!:12) 1:) x 6!:10 y +) +stop=: 6!:10 bind ($0) +reset=: 3 : 0 +4!:55 <'PMTESTDATA' +PM=: $0 +PMREAD=: 0 +PMENCODE=: PMDECODE=: PMSTATS=: $0 +PMNDX=: PMLINES=: PMSPACE=: PMTIME=: $0 +PMNAMES=: PMLOCALES=: '' +) + +reset'' +boxopencols=: ]`(<"1)@.(L. = 0:) +bracket=: ('['"_ , ": , '] '"_) each +dab=: -. & ' ' +firstones=: > (0: , }:) +groupndx=: 4 : '<: (#x) }. (+/\r<#x) /: r=. /: x,y' +info=: wdinfo @ ('Performance Monitor'&;) +lastones=: > (}. , 0:) +maskdef=: [: * [: +/\ _1&= - 0: , }:@:(_2&=) +nolocale=: (i.&'_') {. ] +sort=: /:~ :/: +takeafter=: [: ] (#@[ + E. i. 1:) }. ] +taketo=: [: ] (E. i. 1:) {. ] +takewid=: ] ` ((WID&{.) , '...'"_) @. (WID"_ < #) +unwords=: ;: inverse +usage=: [: +/\ (- 0: , }:) +join=: ,.&.>/ +colsum=: 4 : 0 +nub=. ~. key=. x{"1 y +nub /:~ nub x}"_1 1 key +//. y +) +getmatchindex=: 4 : 0 +bgn=. x +end=. y +level=. +/\ bgn - 0 , }: end +bpos=. I. bgn +blvl=. bpos { level +epos=. I. end +elvl=. epos { level +max=. 1 + #end +bndx=. max #. blvl ,. bpos +endx=. max #. elvl ,. epos +mtch=. bndx groupndx endx +bpos ; (/: mtch { /: bndx) { epos +) +getpm1=: 3 : 0 +'nam loc'=. splitname y +nms=. _1 pick PM +nmx=. nms i. <nam +lcx=. nms i. <loc +msk=. ((0 pick PM) e. nmx) *. ((1 pick PM) e. lcx) +msk&# each }:PM +) +subpm=: 3 : 0 +nms=. _1 pick PM +dat=. y&{ each }:PM +ind=. 0 pick dat +loc=. 1 pick dat +nub=. /:~ ~. ind,loc +nms=. nub { nms +loc=. nub i. loc +ind=. nub i. ind +dat=. (<ind) 0 } dat +dat=. (<loc) 1 } dat +dat , <nms +) +tominus=: 3 : 0 +dat=. , y +($y) $ '-' (I. dat='_')} dat +) +ifmt=: 3 : 0 +w=. 20 +dat=. , y +neg=. 0 > dat +dat=. ": &.> <. | dat +msk=. (-w){.(|. w$1j1 1 1),3$1 +exp=. #!.','~ ({.&msk)@-@# +dat=. exp &.> dat +dat=. (neg{'';'-'),&.>,dat +p=. - >./ # &> dat +p {. &> dat +) +ffmt=: 4 : 0 +n=. ifmt 0 | y +if. x do. + n ,. }."1 (j. x) ": ,. 1 || y +end. +) +SCALE=: 1 1 + +timeformat=: 6 & ffmt +TIMETEXT=: ' Time (seconds)' + +spaceformat=: ifmt +SPACETEXT=: ' Space (bytes)' +getdetail=: 4 : 0 + +'type val'=. x +'name loc gvn'=. y + +rep=. (val+1) linerep <name,'_',loc,'_' +if. 0 e. #rep do. ;~i.0 0 return. end. +ndx=. val + +/ PMENCODE * (PMNAMES i. <name),(PMLOCALES i. <loc),0 +if. -. ndx e. PMNDX do. ;~i.0 0 return. end. + +typename=. val pick 'monad';'dyad' +type getdetail1 typename;rep;ndx +) +getdetail1=: 4 : 0 + +'vid rep ind'=. y + +if. -. ind e. PMNDX do. + (i.0 4) ; '' return. +end. + +dat=. x getdetail2 ind +lno=. > {."1 rep +if. lno -: _1 do. + dat ; vid, ' ', 2 pick , rep return. +end. +replno=. _1 , > {."1 rep +repsno=. _1 ; 1 {"1 rep +reptxt=. 2 {"1 rep +len=. # &> repsno +stm=. {."1 dat +lns=. sort (len # replno) {~ (; repsno) i. stm +rep=. 3 {"1 dat +rep=. rep * stm e. {.&> repsno + +val=. (1 2 {"1 dat),. rep +key=. ~. lns +val=. key ,. lns +/ /. val + +val=. replno ,. }."1 (replno e. {."1 val) expand val +val=. val , 1e8, (1 2{+/val), (<0 3){ val + +txt=. (bracket }.replno) ,each reptxt +txt=. vid ; txt , <'total ',vid + +val ; <txt +) +getdetail2=: 4 : 0 + +ind=. y +msk=. PMNDX = ind + +mbgn=. msk *. PMLINES = _1 +mend=. msk *. PMLINES = _2 +nbgn=. +/ mbgn +nend=. +/ mend + +select. * nbgn - nend +case. 0 do. + bnx=. mbgn i. 1 + enx=. >: mend i: 1 +case. _1 do. + bnx=. mbgn i. 1 + enx=. >: (+/\mend) i. nbgn +case. 1 do. + bnx=. (+/\mbgn) i. nbgn - nend + enx=. >: mend i: 1 +end. + +ndx=. PMNDX +lns=. PMLINES +val=. (x pick 'PMTIME';'PMSPACE')~ +if. enx ~: #ndx do. + ndx=. enx {. ndx + lns=. enx {. lns + val=. enx {. val + mbgn=. enx {. mbgn + mend=. enx {. mend +end. + +if. bnx do. + ndx=. bnx }. ndx + lns=. bnx }. lns + val=. bnx }. val + mbgn=. bnx }. mbgn + mend=. bnx }. mend +end. + +msk=. 0 < mbgn usage mend + +if. 0 e. msk do. + ndx=. msk # ndx + lns=. msk # lns + val=. msk # val + mbgn=. msk # mbgn + mend=. msk # mend +end. + +lvl=. mbgn usage mend +if. 1 +. 2 e. lvl do. + rep=. getreps ind;ndx;lns;val + her=. gethdetail ind;ndx;lns;val + tot=. gettdetail ind;ndx;lns;val + + lns=. {."1 rep + assert lns -: {."1 her + assert lns -: {."1 tot + res=. lns ,. ({:"1 tot) ,. ({:"1 her) ,. {:"1 rep +else. + res=. getdetail3 ind;ndx;lns;val +end. +if. 1 ~: scale=. x { SCALE do. + res=. res *"1 [ 1,scale,scale,1 +end. + +) +getdetail3=: 3 : 0 +'ind ndx lns val'=. y +tmsk=. ndx = ind + +tlns=. tmsk # lns +tval=. tmsk # val + +msk=. tlns ~: _2 +tall=. msk # (}.tval,0) - tval +tlns=. msk # tlns +f=. 0:`({: - {.) @. (0: < #) +toff=. msk # tmsk f;._1 val +ther=. tall - toff + +0 colsum tlns,. tall,. ther ,. 1 +) +gethdetail=: 3 : 0 + +'ind ndx lns val'=. y + +all=. (}.val,0) - val +bgn=. lns = _1 +end=. lns = _2 +hit=. ind = ndx +msk=. 1 < bgn usage end +her=. 2 >: bgn usage end +bgn=. msk *. bgn +end=. msk *. end + +'bdx edx'=. bgn getmatchindex end +clr=. <: bdx + +hndx=. ind (I. her) } ndx +hlns=. her } lns ,: (#;.1 hit) # hit # lns +sel=. ind = clr { hndx +clr=. sel # clr +edx=. sel # edx +lns=. (clr{hlns) edx} lns + +msk=. 1 edx} ndx = ind +msk=. msk *. lns ~: _2 +0 colsum msk # lns ,. all +) +gettdetail=: 3 : 0 + +'ind ndx lns val'=. y + +bgn=. lns = _1 +end=. lns = _2 +all=. (}.val,0) - val +j=. (ndx=ind) <;.1 lns +lns=. (# &> j) # {. &> j +lvl=. +/\ bgn - 0, }:end +msk=. 1 < lvl +bnb=. msk *. bgn +enb=. msk *. end +'bdx edx'=. bnb getmatchindex enb +clr=. <: bdx +lns=. (clr{lns) edx} lns + +msk=. lns ~: _2 +0 colsum msk # lns ,. all +) +getreps=: 3 : 0 +'ind ndx lns val'=. y +msk=. (ndx=ind) *. lns ~: _2 +0 colsum (msk # lns) ,. 1 +) +maskit=: 4 : 0 + +bgn=. x +end=. y +sb=. +/\bgn +se=. +/\end +re=. +/\ inverse se + 0 <. <./\sb - se +mskbgn=. 0 < +/\ bgn - 0,}:re +sb=. +/\.bgn +se=. +/\.end +rb=. +/\. inverse sb + 0 <. <./\.se - sb +mskend=. 0 < +/\. end - }.rb,0 + +mskbgn *. mskend +) +f=. '_'"_ = {: +g=. ;&a: +h=. (i:&'_') ({.;}.@}.) ] +k=. [: h }: +splitname=: g`k @. f f. +fullname=: 3 : 0 +'name loc'=. 2 {. boxopen y +if. '_' ~: {:name do. name,'_',loc,'_' else. name end. +) +getnames=: 4 : 0 + +'nms lcs j'=. |: PMDECODE #: x +xjp=. lcs ~: PMLOCALES i. <'jpm' + +if. 0=#y do. xjp return. end. + +y=. ;: y +sns=. splitname &> y +ndx=. y i. <,'~' +rin=. 1 getnames1 x;nms;lcs;<ndx {. sns +rot=. 0 getnames1 x;nms;lcs;<(ndx+1) }. sns + +xjp *. rin > rot +) +getnames1=: 4 : 0 + +'ndx nms lcs sel'=. y + +if. 0=#sel do. (#ndx)#x return. end. + +nmx=. PMNAMES i. {."1 sel +lcx=. PMLOCALES i. {:"1 sel + +msk=. (#ndx) # 0 + +len=. #. (0: < #) &> sel +if. 1 e. b=. len=1 do. + msk=. msk +. lcs e. b#lcx +end. +if. 1 e. b=. len=2 do. + msk=. msk +. nms e. b#nmx +end. +if. 1 e. b=. len=3 do. + msk=. msk +. (lcs e. b#lcx) *. nms e. b#nmx +end. +) + +getshortname=: 3 : 0 +'name loc'=. 2 {. boxopen y +if. #loc=. loc -. ' ' do. + ((name i.'_') {. name),'_',loc,'_' +else. + name +end. +) +getnameloc=: 3 : 0 + +y=. dab y + +if. 0 = #y do. + '';'base';'' return. +end. + +if. L. y do. + select. #y + case. 1 do. + name=. dab > y + loc=. 'base' + given=. name + case. 2 do. + 'name loc'=. dab each y + if. #loc do. + given=. name,'_',loc,'_' + else. + given=. name + loc=. 'base' + end. + case. do. + 'invalid name' assert 0 + end. + +else. + + given=. y + 'name loc'=. dab each splitname y + if. 0=#loc do. loc=. 'base' end. + +end. + + +name;loc;given +) +read=: 3 : 0 +if. PMREAD do. 1 return. end. +if. 0 = +/ 6!:13'' do. + smoutput 'There are no PM records' + 0 return. +end. + +PMTIME=: 6!:11 '' +PMSTATS=: 6!:13 '' +6!:10 '' +PM=: PMTIME +locndx=. (1;0) {:: PMTIME +PMNAMES=: 6 pick PMTIME +PMLOCALES=: locndx }. PMNAMES +PMNAMES=: locndx {. PMNAMES +PMNDX=: > 3 {. PMTIME +ndx=. I. (1: e. '__'&E.) &> PMNAMES + +if. #ndx do. + nms=. (('__'&E. i. 1:) {. ]) each ndx { PMNAMES + ndx merge nms +end. +ndx=. I. ('_'"_ = {:) &> PMNAMES + +if. #ndx do. + namx=. 0 { PMNDX + locx=. 1 { PMNDX + nms=. }: each ndx { PMNAMES + ind=. i:&'_' &> nms + loc=. (>: ind) }.each nms + loc=. (<'base') (I. 0=# &> loc) } loc + nms=. ind {.each nms + lcs=. (namx i. ndx) { locx + assert loc -: (lcs-locndx) { PMLOCALES + + ndx merge nms +end. +ind=. (0 { PMNDX) { PMNAMES i. PMNAMES +PMNDX=: ind 0 } PMNDX +PMLINES=: 3 pick PMTIME +PMSPACE=: 0, +/\ }: 4 pick PMTIME +PMTIME=: 5 pick PMTIME +PMDECODE=: 0,(#PMLOCALES),2 +PMENCODE=: (2 * #PMLOCALES),2 1 +PMNDX=: +/ PMENCODE * PMNDX - 0,locndx,1 + +PMREAD=: 1 +) +merge=: 4 : 0 +ndx=. x +nms=. y +namx=. 0 { PMNDX +locx=. 1 { PMNDX +nmx=. PMNAMES i. nms +msk=. nmx < #PMNAMES + +if. 1 e. msk do. + plc=. (namx i. msk#nmx) { locx + rlc=. (namx i. msk#ndx) { locx + b=. plc=rlc + if. 1 e. b do. + inx=. b # I. msk + nwx=. ((inx{ndx), namx) i. namx + new=. nwx { (inx{nmx), namx + PMNDX=: new 0 } PMNDX + end. +end. + +PMNAMES=: nms ndx} PMNAMES +) +EXHDR=: '1234' ;&,&> ':' +linerep=: 4 : 0 +dat=. x (5!:7) y +if. #dat do. + stm=. ;{."1 dat + lns=. {: &> 1 {"1 dat + txt=. {:"1 dat + lno=. <&> ~. lns + sno=. lns </. stm + ltx=. lns <@unwords/. txt + lno ,. sno ,. ltx +else. + lrep=. 5!:5 :: 0: y + if. lrep -: 0 do. '' return. end. + if. (x=1) *. '4 : 0' -: 5 {. lrep do. '' return. end. + _1;_1;lrep +end. +) +showdetail=: 3 : 0 +0 showdetail y +: +if. 0=#y do. return. end. +if. 0=read '' do. i.0 0 return. end. +if. 0={.PMSTATS do. + 'No detail PM records were recorded' return. +end. +y=. getnameloc y +}. ; LF ,&.> showdetail1&y each x +) +showdetail1=: 4 : 0 +tit=. 'all';'here';'rep';{:y +top=. x pick TIMETEXT;SPACETEXT +'name loc given'=. y +res=. x showdetail2 y +if. 0 = L. res do. return. end. + +'mdat mtxt ddat dtxt tdat ttxt'=. res + +if. (#mdat) *. #ddat do. + txt=. mtxt ,each ' ' ,each dtxt ,each ' ' ,each ttxt +else. + txt=. mtxt ,each dtxt +end. + +top, , LF ,. ": tit ,: txt +) +showdetail2=: 4 : 0 +'name loc given'=. y + +'mdat mrep'=. (x,0) getdetail y +'ddat drep'=. (x,1) getdetail y + +if. 0 = (#mdat) + (#ddat) do. + 'not found: ',getshortname given return. +end. + +if. 0 e. (#mdat), (#ddat) do. + tdat=. 0, (1 2 { -: +/ mdat,ddat), {: +/ (1 {. mdat) , 1 {. ddat +else. + tdat=. 0 ; 2 }. x gettotal fullname y +end. + +trep=. <'total definition' +mtxt=. x showdetailfmt mdat;<mrep +dtxt=. x showdetailfmt ddat;<drep +ttxt=. x showdetailfmt tdat;<trep + +mdat;mtxt;ddat;dtxt;tdat;<ttxt +) +showdetailfmt=: 4 : 0 +'dat lns'=. y +if. 0 e. #dat do. 4 # <i.0 0 return. end. +if. x do. f=. spaceformat else. f=. timeformat end. +'all here rep'=. }. |: dat +lns=. > (#rep) {. boxxopen lns +(f all);(f here);(":,.rep); lns +) +detailoption=: 3 : '2 {. y , (#y) }. 0 0' +totaloption=: 3 : '3 {. y , (#y) }. 0 0 90' +showtotal=: 3 : 0 +0 showtotal y +: +if. 0=read '' do. i. 0 0 return. end. +opt=. totaloption x +'x s p'=. opt +if. -. x e. 0 1 do. + r=. 'first number in left argument should be either 0 (time)' + r,' or 1 (space)' return. +end. +if. -. s e. 0 1 do. + r=. 'second number in left argument should be either 0 (distinguish' + r,' names by locale) or 1 (total names over locales)' return. +end. +if. s do. + tit=. 'name (all locales)';'all';'here';'here%';'cum%';'rep' +else. + tit=. 'name';'locale';'all';'here';'here%';'cum%';'rep' +end. +dat=. x showtotalfmt opt showtotal1 y +if. s do. dat=. (<<<1) { dat end. +dat=. > each dat +txt=. tit ,: dat +t=. x pick TIMETEXT;SPACETEXT +t, ,LF ,. ": txt +) +showtotal1=: 4 : 0 +'t s p'=. x + +'nam loc all her rep'=. x gettotal y +if. 0 = #nam do. a: return. end. + +j=. her % +/her +pct=. 0.1 * <. 0.5 + 1000 * j +cpt=. <. 0.5 + 100 * +/\ j +if. t do. f=. spaceformat else. f=. timeformat end. + +nam=. nam, <'[total]' +loc=. loc, <'' +all=. all +her=. her, +/her +pct=. pct,100 +cpt=. cpt,100 +rep=. rep + +nam; loc; all; her; pct; cpt; rep +) +showtotalfmt=: 4 : 0 +'nam loc all her pct cpt rep'=. y + +if. x do. f=. spaceformat else. f=. timeformat end. + +all=. f all +her=. f her +pct=. 1 ffmt pct +cpt=. ":,.cpt +rep=. ":,.rep + +nam; loc; all; her; pct; cpt; rep +) +gettotal=: 4 : 0 + +if. 0=read'' do. a: return. end. + +'t s p'=. x +ndx=. PMNDX +lns=. PMLINES +if. t do. dat=. PMSPACE else. dat=. PMTIME end. +if. 0 e. lns do. + msk=. lns < 0 + dat=. msk # dat + ndx=. msk # ndx + lns=. msk # lns +end. +msk=. (lns = _1) maskit lns = _2 +if. 0 e. msk do. + dat=. msk # dat + ndx=. msk # ndx + lns=. msk # lns +end. + +if. 0 = #ndx do. a: return. end. +ndx=. ndx - 2 | ndx +nub=. ~. ndx + +rms=. nub getnames y +req=. rms#nub +'all her rep'=. t gettotals ndx;lns;dat;nub;rms + +'nx lx j'=. |: PMDECODE #: req +if. s do. + 'all her rep'=. |: nx +//. all,.her,.rep + nx=. ~. nx +end. +ndx=. \: her ,. all +her=. ndx{her +all=. ndx{all +if. p < 100 do. + len=. 1 + 1 i.~ (+/\her) >: (+/her) * p % 100 + curtailed=. len < #her + if. curtailed do. + curall=. +/ len }. all + curher=. +/ len }. her + her=. len {. her + all=. len {. all + ndx=. len {. ndx + end. +else. + curtailed=. 0 +end. + +rep=. ndx{rep +nam=. (ndx{nx) { PMNAMES + +if. s do. + loc=. (#nx) # a: +else. + loc=. (ndx{lx) { PMLOCALES +end. + +if. curtailed do. + her=. her, curher + loc=. loc, a: + nam=. nam, <'[rest]' +end. + +if. 1 ~: scale=. t { SCALE do. + all=. scale * all + her=. scale * her +end. +nam ; loc ; all ; her ; rep +) +gettotals=: 4 : 0 + +'ndx lns dat nub req'=. y + +bgn=. lns = _1 +end=. lns = _2 +f=. 1: = [: +/\ (- (0: , 1: - }:)) +msk=. f each ndx < /. bgn + +ada=. ndx < /. dat * _1 ^ bgn + +all=. msk +/@# &> ada +rep=. <. -: # &> ada +sbg=. }:bgn +snd=. sbg < }.end +dff=. (}. - }:) dat +str=. (bgn # ndx) ,. sbg # dff +edr=. ((0,snd) # ndx) ,. snd #dff +spc=. i.0 2 +level=. +/\ bgn - end +ups=. (1 1 E. bgn) > 1 1 0 0 E. bgn +if. 1 e. ups do. + + ulvl=. ups # level + upos=. I. ups + spd=. (0 1 E. bgn) *. level > 0 + slvl=. spd # level + spos=. I. spd + + if. #spos do. + + lmax=. 1 + ({:upos) >. {:spos + + uelp=. lmax #. ulvl ,. upos + ind=. /: uelp + uelp=. ind { uelp + uvrb=. ind { ups # ndx + + selp=. lmax #. slvl ,. spos + svrb=. (uelp groupndx selp) { uvrb + sdff=. spos { dff + spc=. svrb ,. sdff + end. + +end. +spcr=. i.0 2 +if. +./mrec=. (_2=PMLINES)*.PMNDX=1|.PMNDX do. + rdat=. >(>{.x){PMTIME;PMSPACE + mdif=. mrec # rdat-1|.rdat + spcr=. (mrec # PMNDX) ,.mdif + spcr=. ((0{"1 spcr)e.ndx) # spcr + spcr=. i.0 2 +end. +sum=. str , edr , spc , spcr +her=. (nub i. {."1 sum) +/ /. {:"1 sum + +if. x=0 do. + assert *./ all >: her +end. + +|: req # all ,. her ,. rep +) +JVDET=: 0 : 0 +pc jvdet; +xywh 0 0 200 200;cc dgrid isigraph rightmove bottommove; +pas 0 0;pmove 217 113 215 220; +rem form end; +) +destroy_jvdet=: 3 : 0 +wd'pclose' +destroy__dgrid'' +) +jvdet_cancel=: jvdet_close=: destroy_jvdet + +viewdetail=: 3 : 0 +require 'jzgrid' +0 viewdetail y +: +if. 0=read '' do. i. 0 0 return. end. +'DETSPACE DETEXPAND'=: opt=. detailoption x +y=. getnameloc y +sname=. getshortname 2 pick y +pn=. 'PM',(x pick TIMETEXT;SPACETEXT),' - ',sname + +res=. x showdetail2 y +if. 0 = L. res do. return. end. +'mdat mtxt ddat dtxt tdat ttxt'=. res +if. (#mdat) *. #ddat do. + txt=. mtxt ,each ' ' ,each dtxt ,each ' ' ,each ttxt + txt=. mtxt ,each dtxt ,each ttxt +else. + txt=. mtxt ,each dtxt +end. +data=: > join <"1 each txt + +if. wdisparent 'jvdet' do. + wd 'psel jvdet' +else. + wd JVDET + dgrid=: '' conew 'jzgrid' +end. + +hdr=. 'HDRCOL' ,&< 'All';'Here';'Rep';'Lines' +hdr=. hdr , ('CELLALIGN';2 2 2 0) ,: ('CELLEDIT';0) +show__dgrid hdr , ('GRIDID';'dgrid') , ('GRIDSORT' ; 1) ,: 'CELLDATA' ;< data +wd 'pn *Execution Details for ',sname +wdfit'' +wd 'pshow' +) +JVTOT=: 0 : 0 +pc jvtot; +xywh 0 0 200 200;cc tgrid isigraph rightmove bottommove; +pas 0 0; +rem form end; +) +tgrid_gridhandler=: 3 : 0 +select. y +case. 'dblclick' do. + if. 0 <: Row__tgrid do. + TOTSPACE viewdetail (<Row__tgrid;0 1) { CELLDATA__tgrid + end. + 0 +case. do. + 1 +end. +) +destroy_jvtot=: 3 : 0 +wd'pclose' +destroy__tgrid'' +) +jvtot_cancel=: jvtot_close=: destroy_jvtot + +viewtotal=: 3 : 0 +require 'jzgrid' +0 viewtotal y +: +if. 0=read '' do. i. 0 0 return. end. + +if. wdisparent 'jvtot' do. + wd 'psel jvtot;pshow' return. +end. + +wd JVTOT + +pn=. 'PM',x pick TIMETEXT;SPACETEXT +'TOTSPACE TOTSUB TOTPCT'=: opt=. totaloption x +dat=. opt showtotal1 y +ftr=. +/ ('[rest]';'[total]') e. _2 {. 0 pick dat +dat=. (> each 2 {. dat), 2 }. dat +dataraw=: |: <"1 &> ,.each ((-ftr)&}.) each dat +dat=. x showtotalfmt dat +data=: |: <"1 &> dat + +tgrid=: '' conew 'jzgrid' + +hdr=. 'HDRCOL' ,&< 'Name';'Locale';'All';'Here';'Here%';'Cum%';'Rep' +hdr=. hdr , ('CELLALIGN';0 0 2 2 2 2 2) ,: ('CELLEDIT';0) +show__tgrid hdr , ('GRIDID';'tgrid') , ('GRIDSORT' ; 1) ,: 'CELLDATA' ;< data +wd 'pn *',pn +wdfit'' +wd 'pshow' +) +getused=: 3 : 0 +if. 0=read '' do. i. 0 0 return. end. +'nms lcs j'=. |: PMDECODE #: ~. PMNDX +xjp=. lcs ~: PMLOCALES i. <'jpm' +sort xjp # (nms { PMNAMES) ,. lcs { PMLOCALES +) +getnotused=: 3 : 0 +loc=. 18!:1 [ 0 1 +r=. i.0 2 +for_lc. loc do. + r=. r, (nl__lc 1 2 3) ,. lc +end. +sort r -. getused'' +)
new file mode 100644 --- /dev/null +++ b/j/system/util/pp.ijs @@ -0,0 +1,376 @@ +coclass 'jpp' +coinsert 'j' +j=. 'assert. break. case. catch. catchd. catcht. continue. do. else. elseif. end.' +CONTROLS=: ;: j,' fcase. for. if. return. select. try. while. whilst.' +CONTROLX=: 0 0 0 0 0 0 0 0 0 0 _1, 0 1 1 0 1 1 1 1 +CONTROLN=: ;: 'case. catch. catchd. catcht. do. else. elseif. end. fcase.' +CONTROLB=: ;: 'for. if. select. try. while. whilst.' +CONTROLM=: CONTROLN -. <'end.' + +FORMEND=: 'rem form end;';,')' +CONTS=: ';xywh';';cc';';cn' +adverbs=: '~ / \ /. \. } b. f. M. t. t:' + +arguments=: 'm n u v x y' + +t=. '= < <. <: > >. >: _: + +. +: * *. *: - -. -: % %. %: ^ ^.' +t=. t,' $ $. $: ~. ~: | |. |: , ,. ,: ; ;: # #. #: ! /: \: [ [: ]' +t=. t,' { {. {: {:: }. }: ". ": ? ?.' +t=. t,' A. c. C. e. E. i. i: I. j. L. o. p. p: q: r. s: u: x:' +t=. t,' _9: _8: _7: _6: _5: _4: _3: _2: _1:' +t=. t,' 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:' +verbs=: t + +t=. '^: . .. .: : :. :: ;. !. !: " ` `: @ @. @: & &. &: &.:' +t=. t,' d. D. D: H. L: S: T.' +conjunctions=: t + +t=. 'assert. break. case. catch. catchd. catcht. continue. do.' +t=. t,' else. elseif. end. fcase. for. goto. if. label.' +t=. t,' return. select. throw. trap. try. while. whilst.' +control_words=: t + +nouns=: 'a. a:' + +j=. ;: adverbs,' ',verbs,' ',conjunctions,' ',control_words,' ',nouns +SystemDefs=: j,;:'=. =:' +EXPDEFINE=: <@;: ;._2 (0 : 0) +1 : 0 +2 : 0 +3 : 0 +4 : 0 +1 define +2 define +3 define +4 define +adverb : 0 +conjunction : 0 +verb : 0 +monad : 0 +dyad : 0 +adverb define +conjunction define +verb define +monad define +dyad define +) +NOUNDEFINE=: <@;: ;._2 '\' -.~ (0 : 0) +0 \: 0 +noun \: 0 +0 \define +noun \define +) +findfor=: 'for_'&-: @ (4&{.) *. ('.'&=) @ {: +info=: mbinfo @ ('Lint'&;) +lastones=: > (}. , 0:) +tolist=: }.@;@:(LF&,@,@":&.>) +findcontrols=: (1: e. (CONTS"_ (1: e. E.) &> <)) &> +firstones=: > (0 , }:) +maskselectside=: +./\ *. +./\. +notquotes=: (+: ~:/\)@(''''&=) +notcomments=: ([: +./\. (=&' ') +: [: +./\ 'NB.'&E. > ~:/\@(''''&=)) +notqc=: (notquotes *. notcomments) f. +debq=: #~ (+. 1: |. (> </\))@(notquotes <: ' '&~:) +checkmulti=: 3 : 0 +tok=. words @ (#~ notqc) each y +bgn=. masknoun1 &> tok +end=. tok=<;:')' +end=. 2 }. ; (1 0,bgn) < @ (</\) ;. 1 [ 0 1,end +if. (+/bgn) = +/end do. + nounmask=. (+.~:/\) bgn +. end + bgn=. nounmask < maskexp1 &> tok + end=. nounmask < tok=<;:')' + if. bgn pairup end do. 0 return. end. +end. +lvl=. (+/\bgn) - +/\end +if. 2 e. lvl do. + lin=. (<:(bgn#lvl) i. 2) { I. bgn + msg=. lin pick y +elseif. 1 = {:lvl do. + lin=. 1 i.~ *./\.1 = lvl + msg=. 'Definition not completed' +elseif. 1 do. + lin=. lvl i. _1 + msg=. 'Unmatched closing paren' +end. +msg=. 'Could not match begin and end of multi-line definition:',LF,LF,msg +lin;msg +) +commentline=: 3 : 0 +line=. y +ndx=. (y e. ' ',TAB) i. 0 +if. -. 'NB. ' -: 4 {. ndx }. line do. + line return. +end. +pre=. ndx {. line +len=. 57 - +/ 1 + 3 * pre = TAB +if. (,'=') -: ~. (4+ndx) }. line do. + line=. pre,'NB. ',len#'=' +elseif. (,'-') -: ~. (4+ndx) }. line do. + line=. pre,'NB. ',len#'-' +end. +line +) +dellb=: #~ +./\ @: -. @ e.&(' ',TAB) +deltb=: #~ +./\.@: -. @ e.&(' ',TAB) +indent1=: 3 : 0 +tok=. y +x=. I. findfor &> tok +tok=. (<'for.') x} tok ++/ (CONTROLX,0) {~ CONTROLS i. tok +) +maskexps=: 3 : 0 +tok=. words @ (#~ notqc) each y +bgn=. maskexp1 &> tok +end=. tok=<;:')' +end=. 2 }. ; (1 0,bgn) < @ (</\) ;. 1 [ 0 1,end +~: /\. bgn +. end +) +maskexp1=: 3 : 0 +1 e. EXPDEFINE 1&e.@E. &> <y +) +masknouns=: 3 : 0 +tok=. words @ (#~ notqc) each y +bgn=. masknoun1 &> tok +if. -. 1 e. bgn do. return. end. +end=. tok = <;:')' +end=. 2 }. ; (1 0,bgn) < @ (</\) ;. 1 [ 0 1,end +~: /\. bgn +. end +) +masknoun1=: 3 : 0 +if. 0=#y do. 0 return. end. +if. 1 e. NOUNDEFINE 1&e.@E. &> <,y do. 1 return. end. +if. (<'Note') ~: {.y do. 0 return. end. +if. -. (#y) e. 2 3 do. 0 return. end. +('NB.'-:3{.2 pick y,<'NB.') > (1{y) e. SystemDefs +) +maskselect=: 4 : 0 +msk=. x +in=. y +ndx=. msk i. 1 +if. ndx=#msk do. msk return. end. +in=. msk <;.1 in +(ndx#0) ,; maskselect1 each in +) + +maskselect1=: 0 , [: *./\ }. >: {. +pairup=: 4 : 0 +r=. +/\x - y +*./ (0={:r), r e. 0 1 +) +remspaces=: 3 : 0 +msk=. notcomments y +(debq msk#y), (-.msk)#y +) +spacing=: 3 : 0 +in=. 0 +bgn=. 0 +msk=. notcomments y +txt=. msk#y +com=. (-.msk)#y + +if. #txt do. + tok=. words txt + if. tok -: 0 do. return. end. + if. #tok do. + in=. indent1 tok + bgn=. ({.tok) e. CONTROLN + if. 1=#tok do. + txt=. ;tok + else. + txt=. spacing1 dlb txt + end. + else. + txt=. '' + end. +else. + com=. dlb com +end. + +in;bgn;<<txt,com +) +words=: 7&u:&.>@:;:@(8&u:) :: 0: +f=. #~ (=&' ') *: 1: |. notquotes *. '=:'&E. +. '=.'&E. +noblankbefore=: f f. ^: _ + +f=. #~ 1: + [: j. (1: |. =&' ') < _1: |. notquotes *. '=:'&E. +. '=.'&E. +blankafter=: f f. ^: _ +spacing1=: blankafter @ noblankbefore +pp=: 3 : 0 +files=. boxxopen y +res=. (#files) $ 0 +for_f. files do. + s=. pp1 f + if. s = _1 do. return. end. + res=. s f_index } res +end. +res +) +pp1=: 3 : 0 +old=. freads y +dat=. pplint old +if. 0 = #dat do. 0 return. end. +if. L. dat do. + 'lin msg'=. dat + msg=. msg, ' in file:',LF,LF, > y + (0 >. lin - 10) flopen >y + if. lin do. + pos=. 1 0 + (+/\LF = toJ old) i. lin + 0 1 + smsetselect pos + end. + info msg + _1 return. +end. +if. dat -: old do. + 0 +else. + 1 [ dat fwrites y +end. +) +pplint=: 3 : 0 +dat=. ucp y + +'fmt wid rms exp sel'=. Format_j_ +if. wid=0 do. spc=. TAB else. spc=. wid#' ' end. +dat=. dat -. 26{a. +if. 0 = #dat do. return. end. +dat=. toJ dat +iftermLF=. LF = {:dat +dat=. <;._2 dat, iftermLF }. LF +dat=. deltb each dat +res=. checkmulti dat +if. L.res do. return. end. +nounx=. I. masknouns dat +nouns=. nounx { dat +dat=. a: nounx} dat +dat=. dellb each dat +if. rms do. + dat=. remspaces each dat +end. +indat=. spacing each dat +if. (<0) e. indat do. + lin=. indat i. <0 + txt=. lin pick dat + cnt=. +/'''' = txt {.~ ('NB.' E. txt) i. 1 + if. 2 | cnt do. + msg=. 'Mismatched quotes' + else. + msg=. 'Could not parse line' + end. + lin;msg + return. +end. + +'in begin dat'=. |: > indat +if. 0 ~: +/ in do. + ins=. +/\ in + if. _1 e. ins do. + lin=. ins i. _1 + msg=. 'Unmatched end of control block' + else. + msk=. (dat = <,')') *. ins > 0 + if. 1 e. msk do. + lin=. msk i. 1 + msg=. 'Unmatched start of control block' + else. + lin=. 0 + msg=. 'Mismatched control words' + end. + end. + lin;msg return. +end. +res=. ppval dat +if. -. res -: 0 do. return. end. +if. -. fmt do. '' return. end. +in=. +/\ in +ins=. _1 |. in +ins=. 0 >. ins - begin +cmt=. 'NB.'&-: @ (3&{.) +ins=. ins * -. cmt &> dat +dat=. ins (([ # spc"_),]) each dat +if. sel do. + msk=. (<'select.') = {. @ words &> dat + msk=. msk maskselect in + dat=. msk (([ # spc"_),]) each dat +end. +if. exp do. + msk=. (dat=<,')') < maskexps dat + dat=. msk (([ # spc"_),]) each dat +end. +dat=. commentline each dat +dat=. nouns nounx } dat +dat=. ; dat ,each LF +dat=. (- -.iftermLF) }. dat + +utf8 dat +) +ppval=: 3 : 0 +dat=. words each y +pos=. <: +/\ # &> dat +dat=. ; dat +bgn=. (dat e. CONTROLB) +. findfor &> dat +end=. dat = <'end.' +lvl=. +/\bgn-end +if. _1 e. lvl do. + lin=. pos I. lvl i. _1 + lin;'Unmatched control end' return. +end. +if. -. 0 = {: lvl do. + lin=. pos I. lvl i: 1 + lin;'Unmatched control begin' return. +end. +if. bgn = #dat do. 0 return. end. +while. max=. >./ lvl do. + b=. max = lvl + b1=. _1 |. b + ndx=. (,1+{:) I. b > +./\ b1 > b + res=. ppval1 ndx{dat + if. res -: 0 do. + dat=. (<'') ndx}dat + lvl=. (max-1) ndx} lvl + else. + 'hit msg'=. res + lin=. pos I. hit + {. ndx + lin;msg + return. + end. +end. +0 +) +ppval1=: 3 : 0 +dat=. y +select. > {. dat +case. 'if.' do. + b=. 0 = +/ dat e. CONTROLM -. ;: 'else. elseif. do.' + e0=. +/ dat = <'else.' + e1=. +/ dat = <'elseif.' + b=. b *. (2 > e0) *. 0 = e0 *. e1 + b=. b *. (+/ dat = <'do.') = 1 + e1 + if. e1 do. + ix=. I. dat = <'elseif.' + dx=. }. I. dat = <'do.' + b=. b *. (#ix) = #dx + if. b do. + b=. b *. (i.@#-:/:) ,ix,.dx + end. + end. +case. 'select.' do. + b=. 0 = +/ dat e. CONTROLM -. ;: 'case. fcase. do.' + ix=. I. dat e. ;: 'case. fcase.' + dx=. I. dat = <'do.' + b=. b *. (#ix) = #dx + if. b do. + b=. b *. (i.@#-:/:) ,ix,.dx + end. +case. 'try.' do. + c=. ;: 'catch. catchd. catcht.' + b=. (1 e. dat e. c) *. 0 = +/ dat e. CONTROLM -. c +case. 'while.';'whilst.' do. + b=. (1 = +/ dat = <'do.') *. 0 = +/ dat e. CONTROLM -. <'do.' +case. do. + b=. 1 = +/ dat = <'do.' + b=. b *. 0 = +/ dat e. CONTROLM -. <'do.' +end. +if. b do. 0 return. end. +0;'Unmatched control words' +)
new file mode 100644 --- /dev/null +++ b/j/system/util/project.ijs @@ -0,0 +1,572 @@ +coclass <'jp' +coinsert 'j' +defaultvalue=: 4 : 'if. _1 = 4!:0 <x do. (x)=: y end.' +index=: #@[ (| - =) i. +intersect=: e. # [ +matchhead=: [ -: #@[ {. ] +towords=: ;:^:(_1 * 1 = L.) +decomment=: 3 : 0 +dat=. <;._2 termLF toJ y +if. 2 > #dat do. y return. end. + +com=. ('NB.'&-:)@(3&{.)&> dat +ncm=. com < (1|.0,}.com) +. (0,}._1|.com) +msk=. com +: ncm *. dat=a: +dat=. msk # dat + +f=. 'NB.'&E. <: ~:/\@(e.&'''') +g=. #~ *./\@f +; (g each dat) ,each LF +) +ffoldername=: 3 : 0 +p=. tofoldername_j_ y +if. '~' ~: {.p do. '';p return. end. +x=. ('/' e. p) + p i. '/' +(x{.p);x}.p +) +fixNB=: 3 : 0 +x=. I. 'nb.' E. y +'NB' (0 1 +/~ x) } y +) +getprojfile=: 3 : 0 +if. 0=#y do. '' return. end. +p=. remsep projname2path y +if. -. ProjExt -: (-#ProjExt) {. p do. + p=. remsep p + 'f n'=. fpathname p + p,'/',n,ProjExt +end. +) +getprojname=: 3 : 0 +ProjectName,(0=#ProjectName)#ProjectPath +) +projname2path=: 3 : 0 +if. '~'={. y do. + jpath y +elseif. ('/'={.y) +: </ y i. ':/' do. + jpath '~',y +elseif. do. + y +end. +) +projfname=: 3 : 0 +if. 0=#y do. '' return. end. +s=. jpathsep y +if. -. '/' e. s do. + ProjectPath,'/',s +else. + jpath s +end. +) +projsname=: 3 : 0 +if. 0=#ProjectPath do. y return. end. +if. ProjectPath matchhead y do. + (1+#ProjectPath) }. y +else. + toprojectfolder y +end. +) +projssource=: 3 : 0 +projread'' +Source;<projsname each Source +) +PPScript=: jpath '~system/util/pp.ijs' +Project=: ProjectPath=: ProjectName=: '' +direrase=: 3 : 0 +if. 0=#y do. return. end. +if. 0=#1!:0 y do. return. end. +if. 0=#d=. dirtreex y do. return. end. +d=. d \: # &> d +m=. ferase d +if. _1 e. m do. + 'Unable to delete: ',towords (m=_1)#d +end. +) +dirsubdirs=: 3 : 0 +r=. 1!:0 (termsep jpathsep y),'*' +if. 0=#r do. '' return. end. +{."1 r #~ '-d' -:("1) 1 4{"1 > 4{"1 r +) +dirtreex=: 3 : 0 +y=. jpathsep y +p=. (+./\. y = '/') # y +d=. 1!:0 y,('/' = {:y) # '*' +if. 0 = #d do. '' return. end. +a=. > 4 {"1 d +m=. 'd' = 4 {"1 a +f=. (<p) ,each {."1 d +if. 1 e. m do. + f, ; dirtreex each (m#f) ,each <'/','*' +end. +) +fwritenew=: 4 : 0 +dat=. ,x +if. dat -: fread y do. 0 return. end. +dat fwrite y +) +isdir=: 3 : 0 +d=. 1!:0 y +if. 1 ~: #d do. 0 return. end. +'d' = 4 { 4 pick ,d +) +projread=: 3 : 0 +projclear'' +if. 0=#Project do. return. end. +projread1 Project +) +projread1_jp_=: 3 : 0 +projclear'' +Build=: 'build.ijs' +Run=: 'run.ijs' +Source=: '' +dat=. 'b' freads y +if. dat-:_1 do. + Build=: projfname Build + Run=: projfname Run return. +end. +dat=. dat #~ (<'NB.') ~: 3 {.each dat +if. 1 e. '=:' E. ;dat do. + 0!:100 ; dat ,each LF + Source=: cutLF Source +else. + Source=: dat +end. +Build=: projfname Build +Run=: projfname Run +Source=: projfname each extsrc each deb each Source -. a: +EMPTY +) +ProjHdr=: fixNB_jp_ 0 : 0 +nb. +nb. defines list of source files. +nb. path defaults to project directory. +) +projwritenew=: 3 : 0 +r=. 'NB. project: ',(getprojname''),LF,ProjHdr,LF +r fwrites y +) +toprojectfolder=: 3 : 0 +if. 0=#y do. '' return. end. +r=. toprojectfolder1 y +if. L. y do. r else. >r end. +) +toprojectfolder1=: 3 : 0 +res=. filecase@jpathsep each boxxopen y +rex=. I. '~' ~: {.&> res +if. 0=#rex do. res return. end. +if. #Folder do. + pid=. termsep jpath '~',Folder + for_i. rex do. + nax=. termsep nam=. i pick res + if. pid matchhead nax do. + res=. (<'~',Folder,(<:#pid) }. nam) i} res + rex=. rex -. i + end. + end. +end. +if. 0=#rex do. res return. end. +pus=. UserFolders,SystemFolders +pds=. {."1 pus +pps=. termsep each {:"1 pus +ndx=. \: # &> pps +pds=. ndx{pds +pps=. ndx{pps +len=. # &> pps +for_i. rex do. + nam=. i pick res + msk=. pps = len {. each <nam,'/' + if. 1 e. msk do. + ndx=. ((i. >./) msk # len) { I. msk + nam=. ('~', > ndx { pds),(<: ndx { len) }. nam + res=. (<nam) i } res + end. +end. +res +) +touserfolder=: 3 : 0 +p=. toprojectfolder y +if. '~' ~: {.p do. '' return. end. +f=. }. (p i.'/'){.p +p #~ (<f) e. {."1 UserFolders +) +gitcheck=: 3 : 0 +0 < # 0 pick gitreadstatus'' +) +gitgui=: 3 : 0 +if. 0 = #ProjectPath do. 0 return. end. +0 0$gitshell 'git gui &' +) +gitreadstatus=: 3 : 0 +if. IFUNIX *: 0 < #ProjectName do. '';'' return. end. +gitshell 'git status' +) +gitshell=: 3 : 0 +p=. dquote remsep ProjectPath +if. IFWIN do. + shell_jtask_ 'cd "',p,'"',LF,y +else. + unixshell 'cd "',p,'"',LF,y +end. +) +gitstatus=: 3 : 0 +if. 3=nc <'textview_z_' do. + textview 0 pick gitreadstatus '' +end. +EMPTY +) +projclear=: 3 : 0 +Build=: Run=: Source=: '' +) +projclose=: 3 : 0 +projreset'' +) +projinit=: 3 : 0 +if. 0-:FolderTree do. setfolder_j_ Folder end. +projopen y,(0=#y) # >{.RecentProjects +) +projopen=: 3 : 0 +projreset'' +if. 0=#y do. return. end. +Project=: getprojfile y +ProjectPath=: }: 0 pick fpathname Project +projpathfolder ProjectPath +if. #Folder do. + p=. (#jpath '~',Folder,'/') }. ProjectPath + ProjectName=: Folder,'/',p +else. + ProjectName=: '' +end. +projread'' +recentproj_add_j_ Project +) +projpathfolder=: 3 : 0 +p=. touserfolder y +f=. (p i. '/') {. p +if. ('~'={.f) *: (<}.f) e. {."1 UserFolders do. + setfolder_j_ '' +else. + setfolder_j_ }.f +end. +) +projreset=: 3 : 0 +projclear'' +Project=: ProjectPath=: ProjectName=: '' +) +projrun=: 3 : 0 +if. #y do. + p=. 0 pick fpathname getprojfile y +else. + p=. ProjectPath,'/' +end. +load ::] p,Run +) +pp_today=: 2 }. [: ": [: <. 100 #. 3 {. 6!:0 +pp_stamp=: [: ":@, 'r<0>2.0' (8!:2) _3 {. 6!:0 +pp_unstamp=: ':' (2 5}"1) 1 1 0 1 1 0 1 1 (#^:_1"1) _6 {.&> ] +pic=: 4 : 0 +'f p'=. fpathname y +path=. remsep f +d=. snapgetpath path +if. d -: 0 do. return. end. +d=. d,'/p',pp_today'' +t=. d,'/',p +dat=. x,(pp_stamp''),EAV +if. _1 -: fread t do. + if. -. pic_inidir d do. 0 return. end. + old=. fread y + if. -. _1 -: old do. + dat=. old,(6#'0'),EAV,dat + end. +end. +dat fappend t +) +pic_files=: 3 : 0 +{."1 [1!:0 (snappath remsep y),'/p','/*',~pp_today'' +) +pic_inidir=: 3 : 0 +if. #1!:0 y do. 1 return. end. +h=. (y i: 'p') {. y +n=. {."1 [ 1!:0 h,'p*' +if. #n do. + direrase h,'plast' + n=. \:~ n -. <'plast' + if. #n do. + if. 1<#n do. + direrase &> (<h) ,each }.n + end. + (h,'plast') frename h,0 pick n + end. +end. +ss_mkdir y +) +pic_list=: 3 : 0 +t=. y,(0=#y)#pp_today'' +p=. (snappath each fpath each FolderTree) ,each <'/p*' +d=. 1!:0 each p +m=. I. 0 < # &> d +if. 0 = #m do. EMPTY return. end. +p=. ;t&pic_list1 each m +s=. >}."1 p +p=. ({."1 p),<'total' +(>p),.' ',.":s,+/s +) +pic_list1=: 4 : 0 +fp=. (snappath fpath y pick FolderTree),'/p',x,'/' +d=. 1!:0 fp,'*' +if. 0=#d do. i. 0 3 return. end. +f=. {."1 d +c=. (EAV+/ .=fread) each (<fp) ,each f +s=. 2{"1 d +m=. (<'/',~y pick FolderIds),each f +m,.c,.s +) +pic_read=: 3 : 0 +'f p'=. fpathname y +r=. fread (snappath remsep f),'/p',(pp_today''),'/',p +if. r -: _1 do. '' else. <;._2 r end. +) +pic_readx=: 3 : 0 +'f n'=. y +_6 }. n pick pic_read f +) +ss_today=: 's' , 2 }. [: ": [: <. 100 #. 3 {. 6!:0 +SnapTrees=: '' +snapfcopy=: 3 : 0 +'source dest'=. y +if. IFWIN do. + 0 pick 'kernel32 CopyFileW i *w *w i' cd (uucp source);(uucp dest);0 +else. + if. 0 = fpathcreate fpath dest do. 0 return. end. + if. _1 -: dat=. fread source do. 0 return. end. + -. _1 -: dat fwrite dest +end. +) +snapgetpath=: 3 : 0 +p=. snappath y +if. 0 = #1!:0 p do. + if. -. ss_mkdir p do. 0 return. end. + y fwrite p,'/dir.txt' +end. +p +) +snappath=: 3 : 0 +jpath '~snap/.snp/',getsha1_jgtk_ y +) +snapshot=: 3 : 0 +if. Snapshots=0 do. return. end. +snapshot1 y;(ss_today'');ProjectPath +) +snapshot_tree=: 3 : 0 +if. Snapshots=0 do. return. end. +if. (<Folder_j_) e. SnapTrees do. return. end. +snapshot1 &> (<0;ss_today'') (,<@fpath) each y +empty SnapTrees_jp_=: SnapTrees,<Folder_j_ +) +snapshot1=: 3 : 0 +'force today path'=. y +p=. snapgetpath path +if. p = 0 do. return. end. +p=. p,'/' +d=. 1!:0 p,'s*' +pfx=. p,today +if. 0=#d do. path ss_make pfx,'001' return. end. +d=. \:~ {."1 d #~ 'd' = 4{"1 > 4{"1 d +last=. 0 pick d +iftoday=. today -: 7 {. last +if. force do. + if. (p,last) ss_match ProjectPath do. + ss_info 'Last snapshot matches current project.' + 0 return. + end. + if. iftoday do. + f=. pfx,_3 {. '00',": 1 + 0 ". _3 {. last + else. + f=. pfx,'001' + end. + path ss_make f + ss_info 'New snapshot: ',1 pick fpathname f + +else. + if. iftoday do. 0 return. end. + if. (p,last) ss_match path do. 0 return. end. + path ss_make pfx,'001' +end. +d=. (Snapshots-1) }. d +for_s. d do. + f=. p,(>s),'/' + 1!:55 f&, each {."1 [ 1!:0 f,'*' + 1!:55 <f +end. + +1 +) +ss_cleanup=: 3 : 0 +if. 1~:#y do. + r=. '' + r=. r,'0 = list invalid snapshot directories',LF + r=. r,'1 = list non-existent projects with snapshots',LF + r=. r,'100 = remove invalid snapshot directories',LF + r=. r,'101 = remove snapshots for non-existent projects' + smoutput r return. +end. +'d r n'=. ss_dirs'' +select. y +case. 0 do. + d #~ n=2 +case. 1 do. + r #~ n=1 +case. 100 do. + ; {. &> rmdir_j_ each d #~ n=2 +case. 101 do. + ; {. &> rmdir_j_ each d #~ n=1 +end. +) +ss_dir=: 3 : 0 +p=. jpath '~snap/.snp/' +d=. 1!:0 p,'*' +d=. ('d' = 4 {"1 > 4 {"1 d) # {."1 d +d=. (<p) ,each d +d;<(1!:1 :: (''"_))@< each d ,each <'/dir.txt' +) +ss_dirs=: 3 : 0 +'d r'=. ss_dir'' +s=. /:r +r=. s{r +d=. s{d +m=. 0 < #&> r +n=. 2 * -. m +r=. m#r +p=. (*./\.@:~:&'/' # ]) each r +p=. r ,each '/' ,each p ,each <ProjExt +n=. (-. fexist &> p) (I.m) } n +r=. (tofoldername_j_ each r) (I.m) } (#d) # <'' +d;r;n +) +ss_files=: 3 : 0 +t=. 1!:0 y,'*' +if. 0=#t do. return. end. +att=. > 4{"1 t +msk=. ('h' = 1{"1 att) +: 'd' = 4{"1 att +t=. /:~ msk # t +if. _1 = 4!:0 <'ss_exclude' do. + exs=. '.' ,each SnapshotX_j_ + ss_exclude_jp_=: [: +./ exs & ((1 e. E.) &>/) +end. +t #~ -. ss_exclude {."1 t +) +ss_find=: 3 : 0 +y=. y,(0=#y)#ProjectPath +'d r'=. ss_dir'' +ndx=. r i. <jpath remsep_j_ y +ndx pick d,<'not found: ',y +) +ss_info=: 3 : 0 +sminfo 'Snapshot';y +) +ss_list=: 3 : 0 +if. 0=#y do. '' return. end. +p=. snappath projname2path y +d=. 1!:0 p,'/s*' +if. #d do. + d=. d #~ 'd' = 4 {"1 > 4 {"1 d + \:~ {."1 d +else. + '' +end. +) +ss_make=: 4 : 0 +fm=. x,'/' +to=. y,'/' +if. 0 = ss_mkdir to do. 0 return. end. +f=. {."1 ss_files fm +fm=. (<fm) ,each f +to=. (<to) ,each f +res=. snapfcopy"1 fm ,. to +if. 0 e. res do. + txt=. 'Unable to copy:',LF2,tolist (res=0)#fm + ss_info txt +end. +*./ res +) +ss_mkdir=: 3 : 0 +if. 0 -: fpathcreate y do. + if. 1 = # 1!:0 y do. 1 return. end. + ss_info 'Unable to create snapshot directory: ',y + 0 return. +end. +arw=. 'rw' 0 1 } 1!:7 <y +if. 0 -: arw 1!:7 :: 0: <y do. + ss_info 'Unable to set read/write attributes for snapshot directory.' + 0 return. +end. +if. -.IFUNIX do. + ph=. 'h' 1 } 1!:6 <y + if. 0 -: ph 1!:6 :: 0: <y do. + ss_info 'Unable to set hidden attribute for snapshot directory.' + end. +end. + +1 +) +ss_match=: 4 : 0 +x=. termsep x +y=. termsep y +a=. ss_files x +b=. ss_files y +ra=. #a +rb=. #b +if. 0 e. ra,rb do. + ra = rb return. +end. +fa=. {."1 a +fb=. {."1 b +if. -. fa -: fb do. 0 return. end. +if. -. (2 {"1 a) -: (2 {"1 b) do. 0 return. end. +fx=. x&, each fa +fy=. y&, each fa +(<@(1!:1) fy) -: <@(1!:1) fx +) +ss_removesnaps=: 3 : 0 +direrase each snappath each fpath each FolderTree +) +ss_state=: 3 : 0 +'d r n'=. ss_dirs'' +r=. 'valid existent, valid nonexistent, invalid:',LF +r=. r,":+/ n =/ 0 1 2 +) +readprojectsource=: 3 : 0 +pn=. ('~'={.y) }. y +f=. getprojfile y +cocurrent 'jptemp' +coinsert 'jp' +ProjectPath=: fpath f +ProjectName=: '' +projread1 f +r=. Source +cocurrent 'jp' +coerase <'jptemp' +r +) +readsource1=: 4 : 0 +s=. readprojectsource y +dat=. freads each s +if. (<_1) e. dat do. + fls=. ; ' ' ,each toprojectfolder each s #~ (<_1) = dat + sminfo 'Project Manager';'Unable to read:',fls + _1 return. +end. +dat=. ;dat +if. x do. decomment_jp_ dat end. +) +writesource1=: 4 : 0 +'p t'=. y +dat=. x readsource1 p +if. _1 -: dat do. return. end. +dat fwritenew jpath t +EMPTY +) + +readsource=: 0&readsource1 +readsourcex=: 1&readsource1 +writesource=: 0&writesource1 +writesourcex=: 1&writesource1
new file mode 100644 --- /dev/null +++ b/j/system/util/scripts.ijs @@ -0,0 +1,44 @@ +NB. scripts.ijs +NB. +NB. defines noun Public (in j locale) + +cocurrent 'j' + +NB. ========================================================= +NB. Public definitions +NB. form: shortname fpathname +buildpublic 0 : 0 +afm ~addons/graphics/afm/afm.ijs +bmp ~addons/graphics/bmp/bmp.ijs +color16 ~addons/graphics/color/color16.ijs +colortab ~addons/graphics/color/colortab.ijs +csv ~addons/tables/csv/csv.ijs +dd ~addons/data/odbc/odbc.ijs +gl3 ~addons/api/gl3/gl3.ijs +gtk ~addons/gui/gtk/gtk.ijs +gtkide ~addons/ide/gtk/gtk.ijs +guid ~addons/general/misc/guid.ijs +jfiles ~addons/data/jfiles/jfiles.ijs +jmf ~addons/data/jmf/jmf.ijs +jpm ~system/util/pm.ijs +jtags ~addons/general/jtags/jtags.ijs +jzopengl ~addons/graphics/opengl/jzopengl.ijs +jzopenglutil ~addons/graphics/opengl/jzopenglutil.ijs +jzplot ~addons/graphics/plot/jzplot.ijs +numeric ~addons/general/misc/numeric.ijs +opengl ~addons/graphics/opengl/opengl.ijs +pack ~addons/general/misc/pack.ijs +pacman ~system/util/pacman.ijs +parts ~addons/general/misc/parts.ijs +plot ~addons/graphics/plot/plot.ijs +project ~system/util/project.ijs +regex ~system/main/regex.ijs +rgb ~addons/graphics/color/rgb.ijs +socket ~system/main/socket.ijs +stats ~addons/stats/base/base.ijs +task ~system/main/task.ijs +trig ~addons/math/misc/trig.ijs +unicode ~addons/convert/misc/unicode.ijs +validate ~addons/general/misc/validate.ijs +viewmat ~addons/graphics/viewmat/viewmat.ijs +)
new file mode 100644 --- /dev/null +++ b/ja.h @@ -0,0 +1,1199 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Aliases for jt */ + + +#define BfromD(x,y) jtBfromD(jt,(x),(y)) +#define BfromI(x,y) jtBfromI(jt,(x),(y)) +#define BfromX(x,y) jtBfromX(jt,(x),(y)) +#define C1fromC2(x,y) jtC1fromC2(jt,(x),(y)) +#define C2fromC1(x,y) jtC2fromC1(jt,(x),(y)) +#define DfromQ(x,y) jtDfromQ(jt,(x),(y)) +#define DfromX(x,y) jtDfromX(jt,(x),(y)) +#define DfromZ(x,y) jtDfromZ(jt,(x),(y)) +#define DXfI(x,y,z) jtDXfI(jt,(x),(y),(z)) +#define IfromD(x,y) jtIfromD(jt,(x),(y)) +#define IfromX(x,y) jtIfromX(jt,(x),(y)) +#define QfromD(x,y) jtQfromD(jt,(x),(y)) +#define QfromX(x,y) jtQfromX(jt,(x),(y)) +#define XfromB(x,y) jtXfromB(jt,(x),(y)) +#define XfromD(x,y) jtXfromD(jt,(x),(y)) +#define XfromI(x,y) jtXfromI(jt,(x),(y)) +#define XfromQ(x,y) jtXfromQ(jt,(x),(y)) +#define aaxis(x0,x1,x2,x3,x4,x5,x6,x7) jtaaxis(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define abase2(x,y) jtabase2(jt,(x),(y)) +#define ac2(x) jtac2(jt,(x)) +#define add2(x,y,z) jtadd2(jt,(x),(y),(z)) +#define afi(x,y) jtafi(jt,(x),(y)) +#define afrom(x,y) jtafrom(jt,(x),(y)) +#define afrom2(x0,x1,x2,x3) jtafrom2(jt,(x0),(x1),(x2),(x3)) +#define afzrndID(x,y) jtafzrndID(jt,(x),(y)) +#define aii(x) jtaii(jt,(x)) +#define aindex(x0,x1,x2,x3) jtaindex(jt,(x0),(x1),(x2),(x3)) +#define aindex1(x0,x1,x2,x3) jtaindex1(jt,(x0),(x1),(x2),(x3)) +#define am1a(x0,x1,x2,x3) jtam1a(jt,(x0),(x1),(x2),(x3)) +#define am1e(x0,x1,x2,x3) jtam1e(jt,(x0),(x1),(x2),(x3)) +#define am1sp(x0,x1,x2,x3) jtam1sp(jt,(x0),(x1),(x2),(x3)) +#define amend(x,y) jtamend(jt,(x),(y)) +#define amendn2(x0,x1,x2,x3) jtamendn2(jt,(x0),(x1),(x2),(x3)) +#define amna(x0,x1,x2,x3) jtamna(jt,(x0),(x1),(x2),(x3)) +#define amne(x0,x1,x2,x3) jtamne(jt,(x0),(x1),(x2),(x3)) +#define amnsp(x0,x1,x2,x3) jtamnsp(jt,(x0),(x1),(x2),(x3)) +#define amp(x,y) jtamp(jt,(x),(y)) +#define ampco(x,y) jtampco(jt,(x),(y)) +#define apipx(x,y) jtapipx(jt,(x),(y)) +#define applystr(x,y) jtapplystr(jt,(x),(y)) +#define apv(x,y,z) jtapv(jt,(x),(y),(z)) +#define arep(x) jtarep(jt,(x)) +#define aro(x) jtaro(jt,(x)) +#define ascan(x,y) jtascan(jt,(x),(y)) +#define aslash(x,y) jtaslash(jt,(x),(y)) +#define aslash1(x,y) jtaslash1(jt,(x),(y)) +#define astd1(x,y,z) jtastd1(jt,(x),(y),(z)) +#define astdn(x,y,z) jtastdn(jt,(x),(y),(z)) +#define atab(x,y,z) jtatab(jt,(x),(y),(z)) +#define atco(x,y) jtatco(jt,(x),(y)) +#define atcompf(x,y,z) jtatcompf(jt,(x),(y),(z)) +#define atomic(x,y) jtatomic(jt,(x),(y)) +#define atop(x,y) jtatop(jt,(x),(y)) +#define attu(x) jtattu(jt,(x)) +#define attv(x) jtattv(jt,(x)) +#define axbytes(x,y) jtaxbytes(jt,(x),(y)) +#define axbytes1(x0,x1,x2,x3,x4) jtaxbytes1(jt,(x0),(x1),(x2),(x3),(x4)) +#define axtally(x,y) jtaxtally(jt,(x),(y)) +#define b0(x) jtb0(jt,(x)) +#define baddson(x,y,z) jtbaddson(jt,(x),(y),(z)) +#define badjust(x,y) jtbadjust(jt,(x),(y)) +#define base2(x,y) jtbase2(jt,(x),(y)) +#define bcvt(x,y) jtbcvt(jt,(x),(y)) +#define bdot(x) jtbdot(jt,(x)) +#define bdot2(x,y,z) jtbdot2(jt,(x),(y),(z)) +#define behead(x) jtbehead(jt,(x)) +#define bfi(x,y,z) jtbfi(jt,(x),(y),(z)) +#define bfind(x,y,z) jtbfind(jt,(x),(y),(z)) +#define bfrom(x,y) jtbfrom(jt,(x),(y)) +#define bigdeal(x,y) jtbigdeal(jt,(x),(y)) +#define bindd(x,y) jtbindd(jt,(x),(y)) +#define binrep1(x) jtbinrep1(jt,(x)) +#define binrep2(x,y) jtbinrep2(jt,(x),(y)) +#define binsert(x,y,z) jtbinsert(jt,(x),(y),(z)) +#define binzz(x,y) jtbinzz(jt,(x),(y)) +#define bitmatch(x,y) jtbitmatch(jt,(x),(y)) +#define bitwise0000(x,y) jtbitwise0000(jt,(x),(y)) +#define bitwise0001(x,y) jtbitwise0001(jt,(x),(y)) +#define bitwise0010(x,y) jtbitwise0010(jt,(x),(y)) +#define bitwise0011(x,y) jtbitwise0011(jt,(x),(y)) +#define bitwise0100(x,y) jtbitwise0100(jt,(x),(y)) +#define bitwise0101(x,y) jtbitwise0101(jt,(x),(y)) +#define bitwise0110(x,y) jtbitwise0110(jt,(x),(y)) +#define bitwise0111(x,y) jtbitwise0111(jt,(x),(y)) +#define bitwise1000(x,y) jtbitwise1000(jt,(x),(y)) +#define bitwise1001(x,y) jtbitwise1001(jt,(x),(y)) +#define bitwise1010(x,y) jtbitwise1010(jt,(x),(y)) +#define bitwise1011(x,y) jtbitwise1011(jt,(x),(y)) +#define bitwise1100(x,y) jtbitwise1100(jt,(x),(y)) +#define bitwise1101(x,y) jtbitwise1101(jt,(x),(y)) +#define bitwise1110(x,y) jtbitwise1110(jt,(x),(y)) +#define bitwise1111(x,y) jtbitwise1111(jt,(x),(y)) +#define bitwisecharamp(x0,x1,x2,x3) jtbitwisecharamp(jt,(x0),(x1),(x2),(x3)) +#define box(x) jtbox(jt,(x)) +#define box0(x) jtbox0(jt,(x)) +#define boxatop(x) jtboxatop(jt,(x)) +#define boxopen(x) jtboxopen(jt,(x)) +#define bput(x,y,z) jtbput(jt,(x),(y),(z)) +#define brep(x,y,z) jtbrep(jt,(x),(y),(z)) +#define brephdr(x0,x1,x2,x3) jtbrephdr(jt,(x0),(x1),(x2),(x3)) +#define breps(x,y,z) jtbreps(jt,(x),(y),(z)) +#define bsdot(x) jtbsdot(jt,(x)) +#define bslash(x) jtbslash(jt,(x)) +#define c2fi(x) jtc2fi(jt,(x)) +#define c2j(x,y,z) jtc2j(jt,(x),(y),(z)) +#define ca(x) jtca(jt,(x)) +#define cancel(x,y) jtcancel(jt,(x),(y)) +#define cant1(x) jtcant1(jt,(x)) +#define cant2(x,y) jtcant2(jt,(x),(y)) +#define canta(x,y) jtcanta(jt,(x),(y)) +#define cants(x,y,z) jtcants(jt,(x),(y),(z)) +#define cap(x) jtcap(jt,(x)) +#define car(x) jtcar(jt,(x)) +#define case1a(x,y) jtcase1a(jt,(x),(y)) +#define casev(x) jtcasev(jt,(x)) +#define catalog(x) jtcatalog(jt,(x)) +#define ccvt(x,y,z) jtccvt(jt,(x),(y),(z)) +#define cdexec1(x0,x1,x2,x3,x4,x5) jtcdexec1(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define cdgahash(x) jtcdgahash(jt,(x)) +#define cdinit() jtcdinit(jt) +#define cdinsert(x,y) jtcdinsert(jt,(x),(y)) +#define cdload(x,y,z) jtcdload(jt,(x),(y),(z)) +#define cdlookup(x) jtcdlookup(jt,(x)) +#define cdlookupl(x) jtcdlookupl(jt,(x)) +#define cdot1(x) jtcdot1(jt,(x)) +#define cdot2(x,y) jtcdot2(jt,(x),(y)) +#define cdparse(x) jtcdparse(jt,(x)) +#define ceil1(x) jtceil1(jt,(x)) +#define center(x0,x1,x2,x3) jtcenter(jt,(x0),(x1),(x2),(x3)) +#define cex(x,y) jtcex(jt,(x),(y)) +#define cfd(x) jtcfd(jt,(x)) +#define cfn(x) jtcfn(jt,(x)) +#define cfr(x) jtcfr(jt,(x)) +#define cfrd(x,y) jtcfrd(jt,(x),(y)) +#define cfrq(x,y) jtcfrq(jt,(x),(y)) +#define cfrx(x,y) jtcfrx(jt,(x),(y)) +#define cfrz(x,y) jtcfrz(jt,(x),(y)) +#define charmap(x,y,z) jtcharmap(jt,(x),(y),(z)) +#define checkmf() jtcheckmf(jt) +#define checksi() jtchecksi(jt) +#define cirx(x0,x1,x2,x3) jtcirx(jt,(x0),(x1),(x2),(x3)) +#define coeff(x) jtcoeff(jt,(x)) +#define coerce2(x,y,z) jtcoerce2(jt,(x),(y),(z)) +#define colon(x,y) jtcolon(jt,(x),(y)) +#define colon0(x) jtcolon0(jt,(x)) +#define compare(x,y) jtcompare(jt,(x),(y)) +#define conall(x,y) jtconall(jt,(x),(y)) +#define congoto(x,y,z) jtcongoto(jt,(x),(y),(z)) +#define congotoblk(x,y) jtcongotoblk(jt,(x),(y)) +#define congotochk(x,y,z) jtcongotochk(jt,(x),(y),(z)) +#define conjug(x) jtconjug(jt,(x)) +#define connum(x,y) jtconnum(jt,(x),(y)) +#define consinit() jtconsinit(jt) +#define constr(x,y) jtconstr(jt,(x),(y)) +#define convert0(x0,x1,x2,x3) jtconvert0(jt,(x0),(x1),(x2),(x3)) +#define conword(x,y) jtconword(jt,(x),(y)) +#define cpa(x,y) jtcpa(jt,(x),(y)) +#define cps(x) jtcps(jt,(x)) +#define crc2(x,y) jtcrc2(jt,(x),(y)) +#define crccompile(x) jtcrccompile(jt,(x)) +#define crcvalidate(x) jtcrcvalidate(jt,(x)) +#define csize(x,y) jtcsize(jt,(x),(y)) +#define cstr(x) jtcstr(jt,(x)) +#define curtail(x) jtcurtail(jt,(x)) +#define cut(x,y) jtcut(jt,(x),(y)) +#define cut02(x,y,z) jtcut02(jt,(x),(y),(z)) +#define cut02m(x,y) jtcut02m(jt,(x),(y)) +#define cut02v(x,y) jtcut02v(jt,(x),(y)) +#define cut2(x,y,z) jtcut2(jt,(x),(y),(z)) +#define cut2bx(x,y,z) jtcut2bx(jt,(x),(y),(z)) +#define cut2sx(x,y,z) jtcut2sx(jt,(x),(y),(z)) +#define cvt(x,y) jtcvt(jt,(x),(y)) +#define cvt0(x) jtcvt0(jt,(x)) +#define cvt2bit(x,y) jtcvt2bit(jt,(x),(y)) +#define cvz(x,y) jtcvz(jt,(x),(y)) +#define daxis(x,y) jtdaxis(jt,(x),(y)) +#define db1b2(x,y) jtdb1b2(jt,(x),(y)) +#define dbcall(x) jtdbcall(jt,(x)) +#define dbin(x,y) jtdbin(jt,(x),(y)) +#define dbincancel(x0,x1,x2,x3,x4) jtdbincancel(jt,(x0),(x1),(x2),(x3),(x4)) +#define dbjump(x) jtdbjump(jt,(x)) +#define dbrr(x,y) jtdbrr(jt,(x),(y)) +#define dbstack(x) jtdbstack(jt,(x)) +#define dbstop(x,y) jtdbstop(jt,(x),(y)) +#define dbsig(x,y) jtdbsig(jt,(x),(y)) +#define dbunquote(x,y,z) jtdbunquote(jt,(x),(y),(z)) +#define dcapco(x,y) jtdcapco(jt,(x),(y)) +#define dcase(x,y) jtdcase(jt,(x),(y)) +#define dcube(x,y) jtdcube(jt,(x),(y)) +#define ddot(x,y) jtddot(jt,(x),(y)) +#define deal(x,y) jtdeal(jt,(x),(y)) +#define deba(x0,x1,x2,x3) jtdeba(jt,(x0),(x1),(x2),(x3)) +#define debdisp(x) jtdebdisp(jt,(x)) +#define debsi1(x) jtdebsi1(jt,(x)) +#define debug() jtdebug(jt) +#define debz() jtdebz(jt) +#define decrem(x) jtdecrem(jt,(x)) +#define deflate(x0,x1,x2,x3) jtdeflate(jt,(x0),(x1),(x2),(x3)) +#define deflateq(x0,x1,x2,x3) jtdeflateq(jt,(x0),(x1),(x2),(x3)) +#define denseit(x) jtdenseit(jt,(x)) +#define det(x,y) jtdet(jt,(x),(y)) +#define detd(x) jtdetd(jt,(x)) +#define detmr(x) jtdetmr(jt,(x)) +#define detr(x) jtdetr(jt,(x)) +#define detxm(x,y) jtdetxm(jt,(x),(y)) +#define detz(x) jtdetz(jt,(x)) +#define df1(x,y) jtdf1(jt,(x),(y)) +#define df2(x,y,z) jtdf2(jt,(x),(y),(z)) +#define dfc(x,y) jtdfc(jt,(x),(y)) +#define dfr(x) jtdfr(jt,(x)) +#define dfrep(x) jtdfrep(jt,(x)) +#define dfs1(x,y) jtdfs1(jt,(x),(y)) +#define dfs2(x,y,z) jtdfs2(jt,(x),(y),(z)) +#define dgamma(x) jtdgamma(jt,(x)) +#define dgcd(x,y) jtdgcd(jt,(x),(y)) +#define dgrade1(x) jtdgrade1(jt,(x)) +#define dgrade2(x,y) jtdgrade2(jt,(x),(y)) +#define dhead(x,y) jtdhead(jt,(x),(y)) +#define diag(x,y) jtdiag(jt,(x),(y)) +#define diff(x) jtdiff(jt,(x)) +#define diff0(x) jtdiff0(jt,(x)) +#define diffamp(x) jtdiffamp(jt,(x)) +#define diffamp0(x) jtdiffamp0(jt,(x)) +#define dir1(x) jtdir1(jt,(x)) +#define disp(x) jtdisp(jt,(x)) +#define divide(x,y) jtdivide(jt,(x),(y)) +#define dlcm(x,y) jtdlcm(jt,(x),(y)) +#define dllsymaddr(x,y) jtdllsymaddr(jt,(x),(y)) +#define dloc(x) jtdloc(jt,(x)) +#define dolock(x0,x1,x2,x3) jtdolock(jt,(x0),(x1),(x2),(x3)) +#define dot(x,y) jtdot(jt,(x),(y)) +#define dotprod(x,y,z) jtdotprod(jt,(x),(y),(z)) +#define dpoly(x) jtdpoly(jt,(x)) +#define dpone(x,y) jtdpone(jt,(x),(y)) +#define drep(x) jtdrep(jt,(x)) +#define drop(x,y) jtdrop(jt,(x),(y)) +#define dropr(x,y) jtdropr(jt,(x),(y)) +#define drow(x,y,z) jtdrow(jt,(x),(y),(z)) +#define drr(x) jtdrr(jt,(x)) +#define dspell(x,y) jtdspell(jt,(x),(y)) +#define dtab(x,y) jtdtab(jt,(x),(y)) +#define duble(x) jtduble(jt,(x)) +#define dx_init(x) jtdx_init(jt,(x)) +#define dx_next() jtdx_next(jt) +#define dx_next30() jtdx_next30(jt) +#define dxplus(x,y) jtdxplus(jt,(x),(y)) +#define eachl(x,y,z) jteachl(jt,(x),(y),(z)) +#define ebar(x,y) jtebar(jt,(x),(y)) +#define ebarmat(x,y) jtebarmat(jt,(x),(y)) +#define ebarprep(x0,x1,x2,x3,x4) jtebarprep(jt,(x0),(x1),(x2),(x3),(x4)) +#define ebarvec(x,y) jtebarvec(jt,(x),(y)) +#define eca(x0,x1,x2,x3,x4,x5) jteca(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define ecd(x0,x1,x2,x3,x4) jtecd(jt,(x0),(x1),(x2),(x3),(x4)) +#define ecm(x0,x1,x2,x3,x4,x5) jtecm(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define ecm_s1(x0,x1,x2,x3,x4,x5) jtecm_s1(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define ecm_s2(x0,x1,x2,x3,x4,x5,x6) jtecm_s2(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define ecvt(x0,x1,x2,x3,x4) jtecvt(jt,(x0),(x1),(x2),(x3),(x4)) +#define efflev(x,y,z) jtefflev(jt,(x),(y),(z)) +#define efmt(x,y) jtefmt(jt,(x),(y)) +#define enframe(x) jtenframe(jt,(x)) +#define enqueue(x,y) jtenqueue(jt,(x),(y)) +#define ep(x,y) jtep(jt,(x),(y)) +#define eps(x,y) jteps(jt,(x),(y)) +#define eputc(x) jteputc(jt,(x)) +#define eputl(x) jteputl(jt,(x)) +#define eputq(x) jteputq(jt,(x)) +#define eputs(x) jteputs(jt,(x)) +#define eputv(x) jteputv(jt,(x)) +#define eq(x,y) jteq(jt,(x),(y)) +#define eqa(x0,x1,x2,x3,x4) jteqa(jt,(x0),(x1),(x2),(x3),(x4)) +#define eqd(x,y,z) jteqd(jt,(x),(y),(z)) +#define eqf(x,y) jteqf(jt,(x),(y)) +#define eqq(x,y,z) jteqq(jt,(x),(y),(z)) +#define eqx(x,y,z) jteqx(jt,(x),(y),(z)) +#define equ(x,y) jtequ(jt,(x),(y)) +#define eqz(x,y,z) jteqz(jt,(x),(y),(z)) +#define errcap() jterrcap(jt) +#define etc(x) jtetc(jt,(x)) +#define ev1(x,y) jtev1(jt,(x),(y)) +#define ev2(x,y,z) jtev2(jt,(x),(y),(z)) +#define eva(x,y) jteva(jt,(x),(y)) +#define eval(x) jteval(jt,(x)) +#define evc(x,y,z) jtevc(jt,(x),(y),(z)) +#define even(x,y) jteven(jt,(x),(y)) +#define every(x,y,z) jtevery(jt,(x),(y),(z)) +#define every2(x0,x1,x2,x3) jtevery2(jt,(x0),(x1),(x2),(x3)) +#define everysp(x,y,z) jteverysp(jt,(x),(y),(z)) +#define evger(x,y) jtevger(jt,(x),(y)) +#define evinit() jtevinit(jt) +#define ex(x) jtex(jt,(x)) +#define exec1(x) jtexec1(jt,(x)) +#define exec2(x,y) jtexec2(jt,(x),(y)) +#define exec2q(x0,x1,x2,x3,x4) jtexec2q(jt,(x0),(x1),(x2),(x3),(x4)) +#define exec2r(x0,x1,x2,x3,x4) jtexec2r(jt,(x0),(x1),(x2),(x3),(x4)) +#define exec2x(x0,x1,x2,x3,x4) jtexec2x(jt,(x0),(x1),(x2),(x3),(x4)) +#define exec2z(x0,x1,x2,x3,x4) jtexec2z(jt,(x0),(x1),(x2),(x3),(x4)) +#define exg(x) jtexg(jt,(x)) +#define expand(x,y) jtexpand(jt,(x),(y)) +#define expn1(x) jtexpn1(jt,(x)) +#define expn2(x,y) jtexpn2(jt,(x),(y)) +#define exprndID(x,y) jtexprndID(jt,(x),(y)) +#define ext(x,y) jtext(jt,(x),(y)) +#define exta(x0,x1,x2,x3) jtexta(jt,(x0),(x1),(x2),(x3)) +#define fa(x) jtfa(jt,(x)) +#define fac_ecm(x) jtfac_ecm(jt,(x)) +#define facit(x) jtfacit(jt,(x)) +#define fact(x) jtfact(jt,(x)) +#define factor(x) jtfactor(jt,(x)) +#define fdef(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) jtfdef(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10)) +#define fdep(x) jtfdep(jt,(x)) +#define fdepger(x) jtfdepger(jt,(x)) +#define fh(x) jtfh(jt,(x)) +#define filler(x) jtfiller(jt,(x)) +#define fit(x,y) jtfit(jt,(x),(y)) +#define fitct(x,y) jtfitct(jt,(x),(y)) +#define fix(x) jtfix(jt,(x)) +#define fixa(x,y) jtfixa(jt,(x),(y)) +#define fixrecursive(x,y) jtfixrecursive(jt,(x),(y)) +#define floor1(x) jtfloor1(jt,(x)) +#define fmfill(x0,x1,x2,x3,x4,x5,x6) jtfmfill(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define fminit(x0,x1,x2,x3,x4,x5) jtfminit(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define fminus(x,y) jtfminus(jt,(x),(y)) +#define fmt02(x,y) jtfmt02(jt,(x),(y)) +#define fmt1(x0,x1,x2,x3,x4,x5) jtfmt1(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define fmt12(x,y) jtfmt12(jt,(x),(y)) +#define fmt22(x,y) jtfmt22(jt,(x),(y)) +#define fmtallcol(x,y,z) jtfmtallcol(jt,(x),(y),(z)) +#define fmtbfc(x) jtfmtbfc(jt,(x)) +#define fmtcomma(x0,x1,x2,x3) jtfmtcomma(jt,(x0),(x1),(x2),(x3)) +#define fmtD(x,y) jtfmtD(jt,(x),(y)) +#define fmtex(x0,x1,x2,x3,x4,x5,x6,x7) jtfmtex(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define fmtprecomp(x,y) jtfmtprecomp(jt,(x),(y)) +#define fmtq(x0,x1,x2,x3,x4,x5) jtfmtq(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define fmtx(x0,x1,x2,x3,x4,x5) jtfmtx(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define fmtxi(x0,x1,x2,x3) jtfmtxi(jt,(x0),(x1),(x2),(x3)) +#define fname(x) jtfname(jt,(x)) +#define fnegate(x) jtfnegate(jt,(x)) +#define fnum(x) jtfnum(jt,(x)) +#define folk(x,y,z) jtfolk(jt,(x),(y),(z)) +#define fong(x,y) jtfong(jt,(x),(y)) +#define foreign(x,y) jtforeign(jt,(x),(y)) +#define foreignextra(x,y) jtforeignextra(jt,(x),(y)) +#define forinit(x,y) jtforinit(jt,(x),(y)) +#define fplus(x,y) jtfplus(jt,(x),(y)) +#define fpoly(x,y) jtfpoly(jt,(x),(y)) +#define fpolyc(x) jtfpolyc(jt,(x)) +#define fr(x) jtfr(jt,(x)) +#define fram(x0,x1,x2,x3) jtfram(jt,(x0),(x1),(x2),(x3)) +#define from(x,y) jtfrom(jt,(x),(y)) +#define frombs(x,y) jtfrombs(jt,(x),(y)) +#define frombs1(x,y,z) jtfrombs1(jt,(x),(y),(z)) +#define frombsn(x,y,z) jtfrombsn(jt,(x),(y),(z)) +#define frombu(x,y,z) jtfrombu(jt,(x),(y),(z)) +#define fromis(x,y) jtfromis(jt,(x),(y)) +#define fromis1(x0,x1,x2,x3) jtfromis1(jt,(x0),(x1),(x2),(x3)) +#define fromr(x,y) jtfromr(jt,(x),(y)) +#define fromsd(x,y) jtfromsd(jt,(x),(y)) +#define fromss(x,y) jtfromss(jt,(x),(y)) +#define fslashatg(x,y,z) jtfslashatg(jt,(x),(y),(z)) +#define fsm0(x,y,z) jtfsm0(jt,(x),(y),(z)) +#define fsmdo(x0,x1,x2,x3,x4,x5) jtfsmdo(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define fsmvfya(x) jtfsmvfya(jt,(x)) +#define ftymes(x,y) jtftymes(jt,(x),(y)) +#define fullname(x) jtfullname(jt,(x)) +#define fx(x) jtfx(jt,(x)) +#define fxchar(x) jtfxchar(jt,(x)) +#define fxeach(x) jtfxeach(jt,(x)) +#define fxeachv(x,y) jtfxeachv(jt,(x),(y)) +#define ga(x0,x1,x2,x3) jtga(jt,(x0),(x1),(x2),(x3)) +#define gadv(x,y) jtgadv(jt,(x),(y)) +#define gah(x,y) jtgah(jt,(x),(y)) +#define gaussdet(x) jtgaussdet(jt,(x)) +#define gausselm(x) jtgausselm(jt,(x)) +#define gb_flip_cycle() jtgb_flip_cycle(jt) +#define gb_init(x) jtgb_init(jt,(x)) +#define gb_next() jtgb_next(jt) +#define gb_unif_rand(x) jtgb_unif_rand(jt,(x)) +#define gc(x,y) jtgc(jt,(x),(y)) +#define gc3(x0,x1,x2,x3) jtgc3(jt,(x0),(x1),(x2),(x3)) +#define gcd(x,y) jtgcd(jt,(x),(y)) +#define gconj(x,y,z) jtgconj(jt,(x),(y),(z)) +#define ge(x,y) jtge(jt,(x),(y)) +#define gerfrom(x,y) jtgerfrom(jt,(x),(y)) +#define getsen(x) jtgetsen(jt,(x)) +#define gjoin(x,y,z) jtgjoin(jt,(x),(y),(z)) +#define gr1(x) jtgr1(jt,(x)) +#define gr2(x,y) jtgr2(jt,(x),(y)) +#define grade1(x) jtgrade1(jt,(x)) +#define grade1p(x,y) jtgrade1p(jt,(x),(y)) +#define grade2(x,y) jtgrade2(jt,(x),(y)) +#define graft(x) jtgraft(jt,(x)) +#define grb(x0,x1,x2,x3,x4) jtgrb(jt,(x0),(x1),(x2),(x3),(x4)) +#define grc(x0,x1,x2,x3,x4) jtgrc(jt,(x0),(x1),(x2),(x3),(x4)) +#define grd(x0,x1,x2,x3,x4) jtgrd(jt,(x0),(x1),(x2),(x3),(x4)) +#define grd1sp(x) jtgrd1sp(jt,(x)) +#define grd1spdd(x,y,z) jtgrd1spdd(jt,(x),(y),(z)) +#define grd1spds(x,y,z) jtgrd1spds(jt,(x),(y),(z)) +#define grd1spsd(x,y,z) jtgrd1spsd(jt,(x),(y),(z)) +#define grd1spss(x,y,z) jtgrd1spss(jt,(x),(y),(z)) +#define grd1spz(x,y,z) jtgrd1spz(jt,(x),(y),(z)) +#define grd2sp(x,y) jtgrd2sp(jt,(x),(y)) +#define grd2spsd(x,y,z) jtgrd2spsd(jt,(x),(y),(z)) +#define grd2spss(x,y,z) jtgrd2spss(jt,(x),(y),(z)) +#define gri(x0,x1,x2,x3,x4) jtgri(jt,(x0),(x1),(x2),(x3),(x4)) +#define gri1(x0,x1,x2,x3,x4) jtgri1(jt,(x0),(x1),(x2),(x3),(x4)) +#define group(x) jtgroup(jt,(x)) +#define grs(x0,x1,x2,x3,x4) jtgrs(jt,(x0),(x1),(x2),(x3),(x4)) +#define grx(x0,x1,x2,x3,x4) jtgrx(jt,(x0),(x1),(x2),(x3),(x4)) +#define gt(x,y) jtgt(jt,(x),(y)) +#define halve(x) jthalve(jt,(x)) +#define head(x) jthead(jt,(x)) +#define hgcoeff(x,y) jthgcoeff(jt,(x),(y)) +#define hgd(x0,x1,x2,x3,x4) jthgd(jt,(x0),(x1),(x2),(x3),(x4)) +#define hgdiff(x) jthgdiff(jt,(x)) +#define hgeom(x,y) jthgeom(jt,(x),(y)) +#define hgeom2(x,y,z) jthgeom2(jt,(x),(y),(z)) +#define hgv(x0,x1,x2,x3) jthgv(jt,(x0),(x1),(x2),(x3)) +#define hia(x,y) jthia(jt,(x),(y)) +#define hiau(x) jthiau(jt,(x)) +#define hid(x) jthid(jt,(x)) +#define hook(x,y) jthook(jt,(x),(y)) +#define hook1(x,y) jthook1(jt,(x),(y)) +#define hostio(x) jthostio(jt,(x)) +#define hparm(x,y,z) jthparm(jt,(x),(y),(z)) +#define hrep(x,y,z) jthrep(jt,(x),(y),(z)) +#define i0(x) jti0(jt,(x)) +#define iaddr(x0,x1,x2,x3) jtiaddr(jt,(x0),(x1),(x2),(x3)) +#define icap(x) jticap(jt,(x)) +#define icor(x,y) jticor(jt,(x),(y)) +#define icube(x) jticube(jt,(x)) +#define icvt(x) jticvt(jt,(x)) +#define iden(x) jtiden(jt,(x)) +#define idenv0(x0,x1,x2,x3,x4) jtidenv0(jt,(x0),(x1),(x2),(x3),(x4)) +#define ifb(x,y) jtifb(jt,(x),(y)) +#define ifc2(x) jtifc2(jt,(x)) +#define ifdz(x) jtifdz(jt,(x)) +#define ifrom(x,y) jtifrom(jt,(x),(y)) +#define ifxi(x,y) jtifxi(jt,(x),(y)) +#define igcd(x,y) jtigcd(jt,(x),(y)) +#define iindx(x,y) jtiindx(jt,(x),(y)) +#define iixBX(x0,x1,x2,x3,x4) jtiixBX(jt,(x0),(x1),(x2),(x3),(x4)) +#define iixI(x0,x1,x2,x3,x4) jtiixI(jt,(x0),(x1),(x2),(x3),(x4)) +#define ilcm(x,y) jtilcm(jt,(x),(y)) +#define immea(x) jtimmea(jt,(x)) +#define immex(x) jtimmex(jt,(x)) +#define increm(x) jtincrem(jt,(x)) +#define indexof(x,y) jtindexof(jt,(x),(y)) +#define indexofprehashed(x,y,z) jtindexofprehashed(jt,(x),(y),(z)) +#define indexofss(x,y,z) jtindexofss(jt,(x),(y),(z)) +#define indexofsub(x,y,z) jtindexofsub(jt,(x),(y),(z)) +#define indexofxx(x,y,z) jtindexofxx(jt,(x),(y),(z)) +#define infix(x,y,z) jtinfix(jt,(x),(y),(z)) +#define infix2(x,y,z) jtinfix2(jt,(x),(y),(z)) +#define inpl(x,y,z) jtinpl(jt,(x),(y),(z)) +#define int0(x) jtint0(jt,(x)) +#define intdiv(x,y) jtintdiv(jt,(x),(y)) +#define intg(x) jtintg(jt,(x)) +#define intg0(x) jtintg0(jt,(x)) +#define intgamp0(x) jtintgamp0(jt,(x)) +#define intgatop(x,y) jtintgatop(jt,(x),(y)) +#define intgtymes(x,y) jtintgtymes(jt,(x),(y)) +#define intmod2(x) jtintmod2(jt,(x)) +#define intpow(x,y) jtintpow(jt,(x),(y)) +#define inv(x) jtinv(jt,(x)) +#define invamp(x) jtinvamp(jt,(x)) +#define invfork(x) jtinvfork(jt,(x)) +#define iocol(x,y,z) jtiocol(jt,(x),(y),(z)) +#define ioe(x,y) jtioe(jt,(x),(y)) +#define ioi(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) jtioi(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11),(x12)) +#define iopart(x0,x1,x2,x3,x4,x5,x6) jtiopart(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define ioresparse(x,y,z) jtioresparse(jt,(x),(y),(z)) +#define ioev(x,y) jtioev(jt,(x),(y)) +#define iovsd(x,y,z) jtiovsd(jt,(x),(y),(z)) +#define iovxs(x,y,z) jtiovxs(jt,(x),(y),(z)) +#define iota(x) jtiota(jt,(x)) +#define ipart(x0,x1,x2,x3) jtipart(jt,(x0),(x1),(x2),(x3)) +#define ipbx(x0,x1,x2,x3) jtipbx(jt,(x0),(x1),(x2),(x3)) +#define ipoly(x) jtipoly(jt,(x)) +#define ipprep(x0,x1,x2,x3,x4,x5) jtipprep(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define iprimetest(x) jtiprimetest(jt,(x)) +#define irs1(x0,x1,x2,x3) jtirs1(jt,(x0),(x1),(x2),(x3)) +#define irs2(x0,x1,x2,x3,x4,x5) jtirs2(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define iscons(x) jtiscons(jt,(x)) +#define isnanq(x) jtisnanq(jt,(x)) +#define ispoly(x) jtispoly(jt,(x)) +#define istd1(x,y) jtistd1(jt,(x),(y)) +#define ixf(x) jtixf(jt,(x)) +#define ixin(x0,x1,x2,x3) jtixin(jt,(x0),(x1),(x2),(x3)) +#define jclose(x) jtjclose(jt,(x)) +#define jdot1(x) jtjdot1(jt,(x)) +#define jdot2(x,y) jtjdot2(jt,(x),(y)) +#define jerrno() jtjerrno(jt) +#define jfread(x) jtjfread(jt,(x)) +#define jfwrite(x,y) jtjfwrite(jt,(x),(y)) +#define jgetenv(x) jtjgetenv(jt,(x)) +#define jgets(x) jtjgets(jt,(x)) +#define jico2(x,y) jtjico2(jt,(x),(y)) +#define jinit3() jtjinit3(jt) +#define joff(x) jtjoff(jt,(x)) +#define joi(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) jtjoi(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11),(x12)) +#define jope(x,y) jtjope(jt,(x),(y)) +#define jpr(x) jtjpr(jt,(x)) +#define jpr1(x) jtjpr1(jt,(x)) +#define jprx(x0,x1,x2,x3,x4) jtjprx(jt,(x0),(x1),(x2),(x3),(x4)) +#define jset(x,y) jtjset(jt,(x),(y)) +#define jsig(x,y) jtjsig(jt,(x),(y)) +#define jsigd(x) jtjsigd(jt,(x)) +#define jsignal(x) jtjsignal(jt,(x)) +#define jsignal3(x,y,z) jtjsignal3(jt,(x),(y),(z)) +#define jsigstr(x,y,z) jtjsigstr(jt,(x),(y),(z)) +#define jstd(x,y) jtjstd(jt,(x),(y)) +#define key(x,y,z) jtkey(jt,(x),(y),(z)) +#define keyi(x,y,z) jtkeyi(jt,(x),(y),(z)) +#define keysp(x,y,z) jtkeysp(jt,(x),(y),(z)) +#define keyrs(x,y,z) jtkeyrs(jt,(x),(y),(z)) +#define keytally(x,y,z) jtkeytally(jt,(x),(y),(z)) +#define keytallysp(x) jtkeytallysp(jt,(x)) +#define laguerre(x,y,z) jtlaguerre(jt,(x),(y),(z)) +#define lamin1(x) jtlamin1(jt,(x)) +#define lamin2(x,y) jtlamin2(jt,(x),(y)) +#define lbox(x) jtlbox(jt,(x)) +#define lchar(x) jtlchar(jt,(x)) +#define lcm(x,y) jtlcm(jt,(x),(y)) +#define lcolon(x) jtlcolon(jt,(x)) +#define lcpx(x) jtlcpx(jt,(x)) +#define le(x,y) jtle(jt,(x),(y)) +#define less(x,y) jtless(jt,(x),(y)) +#define lev1(x,y) jtlev1(jt,(x),(y)) +#define lev2(x,y,z) jtlev2(jt,(x),(y),(z)) +#define level1(x) jtlevel1(jt,(x)) +#define levs1(x,y) jtlevs1(jt,(x),(y)) +#define levs2(x,y,z) jtlevs2(jt,(x),(y),(z)) +#define line(x0,x1,x2,x3) jtline(jt,(x0),(x1),(x2),(x3)) +#define lineit(x) jtlineit(jt,(x)) +#define linf(x0,x1,x2,x3) jtlinf(jt,(x0),(x1),(x2),(x3)) +#define link(x,y) jtlink(jt,(x),(y)) +#define linsert(x,y) jtlinsert(jt,(x),(y)) +#define lnoun(x) jtlnoun(jt,(x)) +#define lnoun0(x) jtlnoun0(jt,(x)) +#define lnum(x) jtlnum(jt,(x)) +#define lnum1(x) jtlnum1(jt,(x)) +#define locale(x,y) jtlocale(jt,(x),(y)) +#define loccrenum(x) jtloccrenum(jt,(x)) +#define locdestroy(x) jtlocdestroy(jt,(x)) +#define locindirect(x,y) jtlocindirect(jt,(x),(y)) +#define lock1(x) jtlock1(jt,(x)) +#define lock2(x,y) jtlock2(jt,(x),(y)) +#define locmap1(x) jtlocmap1(jt,(x)) +#define locname(x) jtlocname(jt,(x)) +#define locnlx(x) jtlocnlx(jt,(x)) +#define logar1(x) jtlogar1(jt,(x)) +#define lp(x) jtlp(jt,(x)) +#define lr2(x,y,z) jtlr2(jt,(x),(y),(z)) +#define lrep(x) jtlrep(jt,(x)) +#define lrr(x) jtlrr(jt,(x)) +#define lsh(x) jtlsh(jt,(x)) +#define lshape(x) jtlshape(jt,(x)) +#define lsparse(x) jtlsparse(jt,(x)) +#define lsub(x,y,z) jtlsub(jt,(x),(y),(z)) +#define lsymb(x,y) jtlsymb(jt,(x),(y)) +#define lt(x,y) jtlt(jt,(x),(y)) +#define ltie(x) jtltie(jt,(x)) +#define ma(x) jtma(jt,(x)) +#define mag(x) jtmag(jt,(x)) +#define makename(x) jtmakename(jt,(x)) +#define map(x) jtmap(jt,(x)) +#define mapx(x,y) jtmapx(jt,(x),(y)) +#define mat(x) jtmat(jt,(x)) +#define match(x,y) jtmatch(jt,(x),(y)) +#define matchs(x,y) jtmatchs(jt,(x),(y)) +#define matchsub(x0,x1,x2,x3,x4,x5,x6,x7,x8) jtmatchsub(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8)) +#define matth1(x) jtmatth1(jt,(x)) +#define maxdenom(x,y) jtmaxdenom(jt,(x),(y)) +#define maximum(x,y) jtmaximum(jt,(x),(y)) +#define maxtype(x,y) jtmaxtype(jt,(x),(y)) +#define mdiv(x,y) jtmdiv(jt,(x),(y)) +#define mdivsp(x,y) jtmdivsp(jt,(x),(y)) +#define meanD(x0,x1,x2,x3,x4) jtmeanD(jt,(x0),(x1),(x2),(x3),(x4)) +#define meanI(x0,x1,x2,x3,x4) jtmeanI(jt,(x0),(x1),(x2),(x3),(x4)) +#define meminit() jtmeminit(jt) +#define memoget(x,y,z) jtmemoget(jt,(x),(y),(z)) +#define memoput(x0,x1,x2,x3) jtmemoput(jt,(x0),(x1),(x2),(x3)) +#define merge1(x,y) jtmerge1(jt,(x),(y)) +#define merge2(x0,x1,x2,x3) jtmerge2(jt,(x0),(x1),(x2),(x3)) +#define minimum(x,y) jtminimum(jt,(x),(y)) +#define minors(x) jtminors(jt,(x)) +#define minus(x,y) jtminus(jt,(x),(y)) +#define minv(x) jtminv(jt,(x)) +#define mkdir1(x) jtmkdir1(jt,(x)) +#define mmharvest(x0,x1,x2,x3,x4,x5,x6) jtmmharvest(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define mmprep(x0,x1,x2,x3,x4,x5) jtmmprep(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define mnomx(x,y) jtmnomx(jt,(x),(y)) +#define modpow2(x,y,z) jtmodpow2(jt,(x),(y),(z)) +#define move(x,y,z) jtmove(jt,(x),(y),(z)) +#define movandor(x0,x1,x2,x3) jtmovandor(jt,(x0),(x1),(x2),(x3)) +#define movbwneeq(x0,x1,x2,x3) jtmovbwneeq(jt,(x0),(x1),(x2),(x3)) +#define movfslash(x,y,z) jtmovfslash(jt,(x),(y),(z)) +#define movminmax(x0,x1,x2,x3) jtmovminmax(jt,(x0),(x1),(x2),(x3)) +#define movneeq(x0,x1,x2,x3) jtmovneeq(jt,(x0),(x1),(x2),(x3)) +#define movsumavg(x0,x1,x2,x3) jtmovsumavg(jt,(x0),(x1),(x2),(x3)) +#define movsumavg1(x0,x1,x2,x3) jtmovsumavg1(jt,(x0),(x1),(x2),(x3)) +#define mr_init(x) jtmr_init(jt,(x)) +#define mr_next() jtmr_next(jt) +#define mr_next31() jtmr_next31(jt) +#define msmerge(x,y,z) jtmsmerge(jt,(x),(y),(z)) +#define msort(x,y,z) jtmsort(jt,(x),(y),(z)) +#define mt_init_by_array(x,y) jtmt_init_by_array(jt,(x),(y)) +#define mt_init(x) jtmt_init(jt,(x)) +#define mt_next() jtmt_next(jt) +#define mult(x,y) jtmult(jt,(x),(y)) +#define multiple(x,y) jtmultiple(jt,(x),(y)) +#define mvw(x0,x1,x2,x3,x4,x5,x6) jtmvw(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define nameref(x) jtnameref(jt,(x)) +#define namerefop(x,y) jtnamerefop(jt,(x),(y)) +#define nch1(x0,x1,x2,x3) jtnch1(jt,(x0),(x1),(x2),(x3)) +#define ne(x,y) jtne(jt,(x),(y)) +#define negate(x) jtnegate(jt,(x)) +#define neutral(x) jtneutral(jt,(x)) +#define newt(x0,x1,x2,x3) jtnewt(jt,(x0),(x1),(x2),(x3)) +#define nextprime(x) jtnextprime(jt,(x)) +#define nfb(x) jtnfb(jt,(x)) +#define nfs(x,y) jtnfs(jt,(x),(y)) +#define nlsym(x) jtnlsym(jt,(x)) +#define nlx(x) jtnlx(jt,(x)) +#define nlxxx(x) jtnlxxx(jt,(x)) +#define nodupgrade(x0,x1,x2,x3,x4,x5,x6,x7,x8) jtnodupgrade(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8)) +#define nor(x,y) jtnor(jt,(x),(y)) +#define norm(x) jtnorm(jt,(x)) +#define not(x) jtnot(jt,(x)) +#define nub(x) jtnub(jt,(x)) +#define nubi(x) jtnubi(jt,(x)) +#define nubsieve(x) jtnubsieve(jt,(x)) +#define nubsievesp(x) jtnubsievesp(jt,(x)) +#define numb(x0,x1,x2,x3) jtnumb(jt,(x0),(x1),(x2),(x3)) +#define numbpx(x,y,z) jtnumbpx(jt,(x),(y),(z)) +#define numcase(x0,x1,x2,x3,x4,x5,x6) jtnumcase(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define numd(x,y,z) jtnumd(jt,(x),(y),(z)) +#define nume(x,y,z) jtnume(jt,(x),(y),(z)) +#define numi(x,y,z) jtnumi(jt,(x),(y),(z)) +#define numj(x,y,z) jtnumj(jt,(x),(y),(z)) +#define numq(x,y,z) jtnumq(jt,(x),(y),(z)) +#define numr(x,y,z) jtnumr(jt,(x),(y),(z)) +#define numx(x,y,z) jtnumx(jt,(x),(y),(z)) +#define nvrpop(x) jtnvrpop(jt,(x)) +#define nvrpush(x) jtnvrpush(jt,(x)) +#define nvrredef(x) jtnvrredef(jt,(x)) +#define oblique(x,y) jtoblique(jt,(x),(y)) +#define obqfslash(x,y) jtobqfslash(jt,(x),(y)) +#define obverse(x,y) jtobverse(jt,(x),(y)) +#define odom(x,y,z) jtodom(jt,(x),(y),(z)) +#define ofxassoc(x,y,z) jtofxassoc(jt,(x),(y),(z)) +#define oind(x) jtoind(jt,(x)) +#define omask(x,y) jtomask(jt,(x),(y)) +#define onf1(x,y) jtonf1(jt,(x),(y)) +#define onm(x) jtonm(jt,(x)) +#define ope(x) jtope(jt,(x)) +#define opes(x,y,z) jtopes(jt,(x),(y),(z)) +#define opes1(x0,x1,x2,x3,x4,x5) jtopes1(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define opes2(x0,x1,x2,x3,x4,x5,x6) jtopes2(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define ord(x) jtord(jt,(x)) +#define ordstat(x,y) jtordstat(jt,(x),(y)) +#define osub(x,y) jtosub(jt,(x),(y)) +#define outfix(x,y,z) jtoutfix(jt,(x),(y),(z)) +#define over(x,y) jtover(jt,(x),(y)) +#define ovgmove(x0,x1,x2,x3,x4,x5,x6) jtovgmove(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define ovs(x,y) jtovs(jt,(x),(y)) +#define ovs0(x0,x1,x2,x3) jtovs0(jt,(x0),(x1),(x2),(x3)) +#define ovv(x,y) jtovv(jt,(x),(y)) +#define pad(x,y,z) jtpad(jt,(x),(y),(z)) +#define parse(x) jtparse(jt,(x)) +#define parsea(x) jtparsea(jt,(x)) +#define parseas(x,y) jtparseas(jt,(x),(y)) +#define parseinit() jtparseinit(jt) +#define parsex(x0,x1,x2,x3) jtparsex(jt,(x0),(x1),(x2),(x3)) +#define partfscan(x0,x1,x2,x3,x4,x5) jtpartfscan(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define pathit(x) jtpathit(jt,(x)) +#define paxis(x,y) jtpaxis(jt,(x),(y)) +#define pcvt(x,y) jtpcvt(jt,(x),(y)) +#define pdef(x0,x1,x2,x3,x4,x5,x6) jtpdef(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define pdt(x,y) jtpdt(jt,(x),(y)) +#define pdtby(x,y) jtpdtby(jt,(x),(y)) +#define pdtsp(x,y) jtpdtsp(jt,(x),(y)) +#define pdtspmv(x,y) jtpdtspmv(jt,(x),(y)) +#define pdtspmm(x,y) jtpdtspmm(jt,(x),(y)) +#define pdtspmm0(x,y) jtpdtspmm0(jt,(x),(y)) +#define pdtspmm1(x,y) jtpdtspmm1(jt,(x),(y)) +#define pdtspmm01(x,y) jtpdtspmm01(jt,(x),(y)) +#define pdtspvm(x,y) jtpdtspvm(jt,(x),(y)) +#define pdtspvmmv01(x,y) jtpdtspvmmv01(jt,(x),(y)) +#define pdtspvmmv0or1(x,y) jtpdtspvmmv0or1(jt,(x),(y)) +#define pdtspvv(x,y) jtpdtspvv(jt,(x),(y)) +#define pfill(x,y) jtpfill(jt,(x),(y)) +#define piev(x,y) jtpiev(jt,(x),(y)) +#define pind(x,y) jtpind(jt,(x),(y)) +#define pinit() jtpinit(jt) +#define pinv(x) jtpinv(jt,(x)) +#define pix(x) jtpix(jt,(x)) +#define plt(x) jtplt(jt,(x)) +#define plus(x,y) jtplus(jt,(x),(y)) +#define ply1(x,y) jtply1(jt,(x),(y)) +#define pmarea2(x,y) jtpmarea2(jt,(x),(y)) +#define pmfree(x) jtpmfree(jt,(x)) +#define pmrecord(x0,x1,x2,x3) jtpmrecord(jt,(x0),(x1),(x2),(x3)) +#define pollard_p_1(x) jtpollard_p_1(jt,(x)) +#define pollard_rho(x) jtpollard_rho(jt,(x)) +#define poly1(x) jtpoly1(jt,(x)) +#define poly2(x,y) jtpoly2(jt,(x),(y)) +#define poly2a(x,y) jtpoly2a(jt,(x),(y)) +#define polymult(x,y,z) jtpolymult(jt,(x),(y),(z)) +#define pospow(x,y) jtpospow(jt,(x),(y)) +#define powop(x,y) jtpowop(jt,(x),(y)) +#define powseqlim(x,y) jtpowseqlim(jt,(x),(y)) +#define prefix(x,y) jtprefix(jt,(x),(y)) +#define prep(x) jtprep(jt,(x)) +#define preparse(x,y,z) jtpreparse(jt,(x),(y),(z)) +#define prevprime(x) jtprevprime(jt,(x)) +#define prime(x) jtprime(jt,(x)) +#define prime1(x) jtprime1(jt,(x)) +#define prime1d(x) jtprime1d(jt,(x)) +#define primetest(x) jtprimetest(jt,(x)) +#define primitive(x) jtprimitive(jt,(x)) +#define probe(x,y) jtprobe(jt,(x),(y)) +#define probeis(x,y) jtprobeis(jt,(x),(y)) +#define probenum(x) jtprobenum(jt,(x)) +#define prod(x,y) jtprod(jt,(x),(y)) +#define pscan(x,y) jtpscan(jt,(x),(y)) +#define pscangt(x0,x1,x2,x3,x4,x5,x6,x7,x8) jtpscangt(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8)) +#define pscanlt(x0,x1,x2,x3,x4,x5) jtpscanlt(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define qbin(x,y) jtqbin(jt,(x),(y)) +#define qco2(x,y) jtqco2(jt,(x),(y)) +#define qco2x(x,y) jtqco2x(jt,(x),(y)) +#define qcompare(x,y) jtqcompare(jt,(x),(y)) +#define qdiv(x,y) jtqdiv(jt,(x),(y)) +#define qgcd(x,y) jtqgcd(jt,(x),(y)) +#define qlcm(x,y) jtqlcm(jt,(x),(y)) +#define qlogd1(x) jtqlogd1(jt,(x)) +#define qlogz1(x) jtqlogz1(jt,(x)) +#define qminus(x,y) jtqminus(jt,(x),(y)) +#define qplus(x,y) jtqplus(jt,(x),(y)) +#define qpow(x,y) jtqpow(jt,(x),(y)) +#define qq(x,y) jtqq(jt,(x),(y)) +#define qr(x) jtqr(jt,(x)) +#define qrem(x,y) jtqrem(jt,(x),(y)) +#define qrr(x) jtqrr(jt,(x)) +#define qstd(x) jtqstd(jt,(x)) +#define qtymes(x,y) jtqtymes(jt,(x),(y)) +#define ra(x) jtra(jt,(x)) +#define ra1(x) jtra1(jt,(x)) +#define raa(x,y) jtraa(jt,(x),(y)) +#define ranec(x0,x1,x2,x3,x4,x5) jtranec(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define rank1ex(x0,x1,x2,x3) jtrank1ex(jt,(x0),(x1),(x2),(x3)) +#define rank2ex(x0,x1,x2,x3,x4,x5) jtrank2ex(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define rankingb(x0,x1,x2,x3,x4,x5) jtrankingb(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define rat(x) jtrat(jt,(x)) +#define ravel(x) jtravel(jt,(x)) +#define raze(x) jtraze(jt,(x)) +#define razecut2(x,y,z) jtrazecut2(jt,(x),(y),(z)) +#define razeg(x0,x1,x2,x3,x4,x5) jtrazeg(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define razeh(x) jtrazeh(jt,(x)) +#define rc(x,y,z) jtrc(jt,(x),(y),(z)) +#define rca(x) jtrca(jt,(x)) +#define rd(x,y,z) jtrd(jt,(x),(y),(z)) +#define rdns(x) jtrdns(jt,(x)) +#define rdot1(x) jtrdot1(jt,(x)) +#define reaxis(x,y) jtreaxis(jt,(x),(y)) +#define recip(x) jtrecip(jt,(x)) +#define rect(x) jtrect(jt,(x)) +#define red0(x,y) jtred0(jt,(x),(y)) +#define redcatsp(x,y,z) jtredcatsp(jt,(x),(y),(z)) +#define redef(x,y) jtredef(jt,(x),(y)) +#define redefg(x) jtredefg(jt,(x)) +#define redg(x,y) jtredg(jt,(x),(y)) +#define redsp1(x0,x1,x2,x3,x4,x5,x6,x7) jtredsp1(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define redsp1a(x0,x1,x2,x3,x4,x5) jtredsp1a(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define redspd(x0,x1,x2,x3,x4,x5,x6,x7) jtredspd(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define redsps(x0,x1,x2,x3,x4,x5,x6,x7) jtredsps(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define redspse(x0,x1,x2,x3,x4,x5,x6,x7) jtredspse(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define redspsprep(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) jtredspsprep(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11),(x12)) +#define reduce(x,y) jtreduce(jt,(x),(y)) +#define reduce2(x0,x1,x2,x3,x4) jtreduce2(jt,(x0),(x1),(x2),(x3),(x4)) +#define reducesp(x,y) jtreducesp(jt,(x),(y)) +#define reitem(x,y) jtreitem(jt,(x),(y)) +#define remdd(x,y) jtremdd(jt,(x),(y)) +#define remid(x,y) jtremid(jt,(x),(y)) +#define rep1d(x0,x1,x2,x3) jtrep1d(jt,(x0),(x1),(x2),(x3)) +#define rep1s(x0,x1,x2,x3) jtrep1s(jt,(x0),(x1),(x2),(x3)) +#define rep1sa(x,y,z) jtrep1sa(jt,(x),(y),(z)) +#define repbdx(x0,x1,x2,x3) jtrepbdx(jt,(x0),(x1),(x2),(x3)) +#define repbsx(x0,x1,x2,x3) jtrepbsx(jt,(x0),(x1),(x2),(x3)) +#define repeat(x,y) jtrepeat(jt,(x),(y)) +#define repeatr(x,y) jtrepeatr(jt,(x),(y)) +#define repidx(x0,x1,x2,x3) jtrepidx(jt,(x0),(x1),(x2),(x3)) +#define repisx(x0,x1,x2,x3) jtrepisx(jt,(x0),(x1),(x2),(x3)) +#define repzdx(x0,x1,x2,x3) jtrepzdx(jt,(x0),(x1),(x2),(x3)) +#define repzsx(x0,x1,x2,x3) jtrepzsx(jt,(x0),(x1),(x2),(x3)) +#define reshape(x,y) jtreshape(jt,(x),(y)) +#define reshapesp(x0,x1,x2,x3) jtreshapesp(jt,(x0),(x1),(x2),(x3)) +#define reshapesp0(x0,x1,x2,x3) jtreshapesp0(jt,(x0),(x1),(x2),(x3)) +#define residue(x,y) jtresidue(jt,(x),(y)) +#define reverse(x) jtreverse(jt,(x)) +#define revsp(x) jtrevsp(jt,(x)) +#define rezero(x,y) jtrezero(jt,(x),(y)) +#define rfc(x) jtrfc(jt,(x)) +#define rfcq(x0,x1,x2,x3) jtrfcq(jt,(x0),(x1),(x2),(x3)) +#define rfcz(x,y) jtrfcz(jt,(x),(y)) +#define rfd(x) jtrfd(jt,(x)) +#define rinv(x) jtrinv(jt,(x)) +#define rmdir1(x) jtrmdir1(jt,(x)) +#define rngga(x,y) jtrngga(jt,(x),(y)) +#define rnginit() jtrnginit(jt) +#define rngseeds(x) jtrngseeds(jt,(x)) +#define rngselects(x) jtrngselects(jt,(x)) +#define rngstates1(x0,x1,x2,x3,x4,x5,x6) jtrngstates1(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define roll(x) jtroll(jt,(x)) +#define roll2(x,y) jtroll2(jt,(x),(y)) +#define rollany(x,y) jtrollany(jt,(x),(y)) +#define rollbool(x) jtrollbool(jt,(x)) +#define rollk(x,y,z) jtrollk(jt,(x),(y),(z)) +#define rollksub(x,y) jtrollksub(jt,(x),(y)) +#define rollnot0(x,y) jtrollnot0(jt,(x),(y)) +#define rollxnum(x) jtrollxnum(jt,(x)) +#define root(x,y) jtroot(jt,(x),(y)) +#define rot(x0,x1,x2,x3,x4,x5,x6,x7) jtrot(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define rotate(x,y) jtrotate(jt,(x),(y)) +#define rotsp(x,y) jtrotsp(jt,(x),(y)) +#define roundID(x,y) jtroundID(jt,(x),(y)) +#define rsh0(x) jtrsh0(jt,(x)) +#define rsort(x) jtrsort(jt,(x)) +#define sb2(x,y) jtsb2(jt,(x),(y)) +#define sbbox(x) jtsbbox(jt,(x)) +#define sbcheck(x) jtsbcheck(jt,(x)) +#define sbcheck1(x0,x1,x2,x3,x4,x5,x6,x7) jtsbcheck1(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define sbextend(x0,x1,x2,x3) jtsbextend(jt,(x0),(x1),(x2),(x3)) +#define sbgetdata(x) jtsbgetdata(jt,(x)) +#define sbhashstat(x) jtsbhashstat(jt,(x)) +#define sbinsert(x0,x1,x2,x3,x4) jtsbinsert(jt,(x0),(x1),(x2),(x3),(x4)) +#define sblit(x,y) jtsblit(jt,(x),(y)) +#define sborder(x) jtsborder(jt,(x)) +#define sbprobe(x,y,z) jtsbprobe(jt,(x),(y),(z)) +#define sbsetdata(x) jtsbsetdata(jt,(x)) +#define sbstr(x,y) jtsbstr(jt,(x),(y)) +#define sbtypeinit() jtsbtypeinit(jt) +#define sbunbox(x) jtsbunbox(jt,(x)) +#define sbunind(x) jtsbunind(jt,(x)) +#define sbunlit(x,y) jtsbunlit(jt,(x),(y)) +#define sbunstr(x,y) jtsbunstr(jt,(x),(y)) +#define sc(x) jtsc(jt,(x)) +#define sc4(x,y) jtsc4(jt,(x),(y)) +#define scansp(x,y,z) jtscansp(jt,(x),(y),(z)) +#define scb(x) jtscb(jt,(x)) +#define scc(x) jtscc(jt,(x)) +#define scf(x) jtscf(jt,(x)) +#define scfn(x) jtscfn(jt,(x)) +#define scheck(x) jtscheck(jt,(x)) +#define scind(x) jtscind(jt,(x)) +#define scuba(x,y,z) jtscuba(jt,(x),(y),(z)) +#define scubb(x,y) jtscubb(jt,(x),(y)) +#define scubc(x,y,z) jtscubc(jt,(x),(y),(z)) +#define scube(x,y,z) jtscube(jt,(x),(y),(z)) +#define scx(x) jtscx(jt,(x)) +#define seecall(x) jtseecall(jt,(x)) +#define seeparse(x) jtseeparse(jt,(x)) +#define seg(x,y) jtseg(jt,(x),(y)) +#define selfq(x) jtselfq(jt,(x)) +#define selm(x) jtselm(jt,(x)) +#define selx(x,y,z) jtselx(jt,(x),(y),(z)) +#define sely(x0,x1,x2,x3) jtsely(jt,(x0),(x1),(x2),(x3)) +#define sent12b(x,y,z) jtsent12b(jt,(x),(y),(z)) +#define sent12c(x,y,z) jtsent12c(jt,(x),(y),(z)) +#define sesminit() jtsesminit(jt) +#define setfv(x,y) jtsetfv(jt,(x),(y)) +#define sfn(x,y) jtsfn(jt,(x),(y)) +#define shape(x) jtshape(jt,(x)) +#define shift1(x) jtshift1(jt,(x)) +#define shift10(x,y) jtshift10(jt,(x),(y)) +#define showerr() jtshowerr(jt) +#define signum(x) jtsignum(jt,(x)) +#define slash(x) jtslash(jt,(x)) +#define sldot(x) jtsldot(jt,(x)) +#define sm_init(x) jtsm_init(jt,(x)) +#define smallprimes(x0,x1,x2,x3) jtsmallprimes(jt,(x0),(x1),(x2),(x3)) +#define smma(x,y) jtsmma(jt,(x),(y)) +#define smmblkf(x) jtsmmblkf(jt,(x)) +#define smmblku(x) jtsmmblku(jt,(x)) +#define smmcar(x,y) jtsmmcar(jt,(x),(y)) +#define smmga(x0,x1,x2,x3,x4) jtsmmga(jt,(x0),(x1),(x2),(x3),(x4)) +#define smmin(x,y) jtsmmin(jt,(x),(y)) +#define smminit(x) jtsmminit(jt,(x)) +#define smmis(x,y) jtsmmis(jt,(x),(y)) +#define smmjoin(x,y) jtsmmjoin(jt,(x),(y)) +#define snl(x) jtsnl(jt,(x)) +#define sortb(x0,x1,x2,x3) jtsortb(jt,(x0),(x1),(x2),(x3)) +#define sortb2(x0,x1,x2,x3) jtsortb2(jt,(x0),(x1),(x2),(x3)) +#define sortb4(x0,x1,x2,x3) jtsortb4(jt,(x0),(x1),(x2),(x3)) +#define sortc(x0,x1,x2,x3) jtsortc(jt,(x0),(x1),(x2),(x3)) +#define sortc2(x0,x1,x2,x3) jtsortc2(jt,(x0),(x1),(x2),(x3)) +#define sortd(x0,x1,x2,x3) jtsortd(jt,(x0),(x1),(x2),(x3)) +#define sorti(x0,x1,x2,x3) jtsorti(jt,(x0),(x1),(x2),(x3)) +#define sorti1(x0,x1,x2,x3) jtsorti1(jt,(x0),(x1),(x2),(x3)) +#define sp(x) jtsp(jt,(x)) +#define sparse1(x) jtsparse1(jt,(x)) +#define sparse1a(x0,x1,x2,x3,x4) jtsparse1a(jt,(x0),(x1),(x2),(x3),(x4)) +#define sparseit(x,y,z) jtsparseit(jt,(x),(y),(z)) +#define sparsen1(x) jtsparsen1(jt,(x)) +#define sparsep1(x) jtsparsep1(jt,(x)) +#define spc() jtspc(jt) +#define spdscell(x0,x1,x2,x3,x4) jtspdscell(jt,(x0),(x1),(x2),(x3),(x4)) +#define spella(x) jtspella(jt,(x)) +#define spellcon(x) jtspellcon(jt,(x)) +#define spellout(x) jtspellout(jt,(x)) +#define spfor1(x) jtspfor1(jt,(x)) +#define spfree() jtspfree(jt) +#define splitij(x,y,z) jtsplitij(jt,(x),(y),(z)) +#define spmult(x0,x1,x2,x3,x4,x5,x6,x7) jtspmult(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7)) +#define spmultdo(x0,x1,x2,x3) jtspmultdo(jt,(x0),(x1),(x2),(x3)) +#define spradv(x0,x1,x2,x3,x4,x5,x6) jtspradv(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define sprank1(x0,x1,x2,x3) jtsprank1(jt,(x0),(x1),(x2),(x3)) +#define sprank2(x0,x1,x2,x3,x4,x5) jtsprank2(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define sprank2_0w(x0,x1,x2,x3,x4,x5) jtsprank2_0w(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define sprank2_a0(x0,x1,x2,x3,x4,x5) jtsprank2_a0(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define sprarg(x,y) jtsprarg(jt,(x),(y)) +#define spredge(x,y,z) jtspredge(jt,(x),(y),(z)) +#define sprinit(x0,x1,x2,x3,x4) jtsprinit(jt,(x0),(x1),(x2),(x3),(x4)) +#define sprintfeD(x0,x1,x2,x3,x4) jtsprintfeD(jt,(x0),(x1),(x2),(x3),(x4)) +#define sprintfnD(x0,x1,x2,x3,x4) jtsprintfnD(jt,(x0),(x1),(x2),(x3),(x4)) +#define sprintfI(x0,x1,x2,x3,x4) jtsprintfI(jt,(x0),(x1),(x2),(x3),(x4)) +#define sprz(x0,x1,x2,x3,x4) jtsprz(jt,(x0),(x1),(x2),(x3),(x4)) +#define spspd(x0,x1,x2,x3) jtspspd(jt,(x0),(x1),(x2),(x3)) +#define spspi(x0,x1,x2,x3) jtspspi(jt,(x0),(x1),(x2),(x3)) +#define spspx(x0,x1,x2,x3) jtspspx(jt,(x0),(x1),(x2),(x3)) +#define spsscell(x0,x1,x2,x3,x4) jtspsscell(jt,(x0),(x1),(x2),(x3),(x4)) +#define sqroot(x) jtsqroot(jt,(x)) +#define square(x) jtsquare(jt,(x)) +#define sscan(x,y) jtsscan(jt,(x),(y)) +#define ssdo(x,y,z) jtssdo(jt,(x),(y),(z)) +#define ssel(x,y) jtssel(jt,(x),(y)) +#define ssg(x,y) jtssg(jt,(x),(y)) +#define ssgu(x,y) jtssgu(jt,(x),(y)) +#define sslope(x,y,z) jtsslope(jt,(x),(y),(z)) +#define ssnext(x,y) jtssnext(jt,(x),(y)) +#define stcreate(x0,x1,x2,x3) jtstcreate(jt,(x0),(x1),(x2),(x3)) +#define stdf(x) jtstdf(jt,(x)) +#define stdnm(x) jtstdnm(jt,(x)) +#define stfind(x,y,z) jtstfind(jt,(x),(y),(z)) +#define stfindnum(x,y) jtstfindnum(jt,(x),(y)) +#define stitch(x,y) jtstitch(jt,(x),(y)) +#define stitchsp2(x,y) jtstitchsp2(jt,(x),(y)) +#define str(x,y) jtstr(jt,(x),(y)) +#define str0(x) jtstr0(jt,(x)) +#define suffix(x,y) jtsuffix(jt,(x),(y)) +#define sumatgbool(x,y,z) jtsumatgbool(jt,(x),(y),(z)) +#define sumattymes(x,y,z) jtsumattymes(jt,(x),(y),(z)) +#define summag(x) jtsummag(jt,(x)) +#define sup(x,y) jtsup(jt,(x),(y)) +#define suq(x,y) jtsuq(jt,(x),(y)) +#define susp() jtsusp(jt) +#define swap(x) jtswap(jt,(x)) +#define swapc(x) jtswapc(jt,(x)) +#define symbinit() jtsymbinit(jt) +#define symbis(x,y,z) jtsymbis(jt,(x),(y),(z)) +#define symbrd(x) jtsymbrd(jt,(x)) +#define symbrdlock(x) jtsymbrdlock(jt,(x)) +#define symext(x) jtsymext(jt,(x)) +#define symfree(x) jtsymfree(jt,(x)) +#define symfreeh(x,y) jtsymfreeh(jt,(x),(y)) +#define symfreeha(x) jtsymfreeha(jt,(x)) +#define symnew(x) jtsymnew(jt,(x)) +#define sympoola(x) jtsympoola(jt,(x)) +#define syrd(x,y) jtsyrd(jt,(x),(y)) +#define syrd1(x,y,z) jtsyrd1(jt,(x),(y),(z)) +#define table(x) jttable(jt,(x)) +#define tail(x) jttail(jt,(x)) +#define take(x,y) jttake(jt,(x),(y)) +#define taker(x,y) jttaker(jt,(x),(y)) +#define tally(x) jttally(jt,(x)) +#define tayamp(x0,x1,x2,x3) jttayamp(jt,(x0),(x1),(x2),(x3)) +#define tayatop(x) jttayatop(jt,(x)) +#define tayfolk(x) jttayfolk(jt,(x)) +#define tayinv(x,y) jttayinv(jt,(x),(y)) +#define taysum(x) jttaysum(jt,(x)) +#define tcap(x,y) jttcap(jt,(x),(y)) +#define tceil(x) jttceil(jt,(x)) +#define tclosure(x,y) jttclosure(jt,(x),(y)) +#define tco(x) jttco(jt,(x)) +#define tcoamp(x0,x1,x2,x3) jttcoamp(jt,(x0),(x1),(x2),(x3)) +#define tconnect(x) jttconnect(jt,(x)) +#define tdot(x) jttdot(jt,(x)) +#define teq(x,y) jtteq(jt,(x),(y)) +#define tesa(x,y) jttesa(jt,(x),(y)) +#define tesmat(x0,x1,x2,x3,x4) jttesmat(jt,(x0),(x1),(x2),(x3),(x4)) +#define tesmatu(x0,x1,x2,x3,x4) jttesmatu(jt,(x0),(x1),(x2),(x3),(x4)) +#define tesos(x,y,z) jttesos(jt,(x),(y),(z)) +#define tess2(x,y,z) jttess2(jt,(x),(y),(z)) +#define tf() jttf(jt) +#define tfloor(x) jttfloor(jt,(x)) +#define tg() jttg(jt) +#define th2a(x0,x1,x2,x3,x4,x5,x6,x7,x8) jtth2a(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8)) +#define th2box(x,y) jtth2box(jt,(x),(y)) +#define th2c(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) jtth2c(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9)) +#define th2ctrl(x0,x1,x2,x3,x4,x5) jtth2ctrl(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define thbit(x) jtthbit(jt,(x)) +#define thb(x) jtthb(jt,(x)) +#define thbox(x) jtthbox(jt,(x)) +#define thdx1(x) jtthdx1(jt,(x)) +#define thn(x) jtthn(jt,(x)) +#define thorn1(x) jtthorn1(jt,(x)) +#define thq1(x) jtthq1(jt,(x)) +#define ths(x) jtths(jt,(x)) +#define thsb(x) jtthsb(jt,(x)) +#define thv(x,y,z) jtthv(jt,(x),(y),(z)) +#define thx1(x) jtthx1(jt,(x)) +#define thxqe(x) jtthxqe(jt,(x)) +#define tie(x,y) jttie(jt,(x),(y)) +#define tine(x) jttine(jt,(x)) +#define tk(x,y) jttk(jt,(x),(y)) +#define tk0(x,y,z) jttk0(jt,(x),(y),(z)) +#define tks(x,y) jttks(jt,(x),(y)) +#define tleaf(x) jttleaf(jt,(x)) +#define tlt(x,y) jttlt(jt,(x),(y)) +#define toc1(x,y) jttoc1(jt,(x),(y)) +#define toc2(x) jttoc2(jt,(x)) +#define toc2e(x) jttoc2e(jt,(x)) +#define tokens(x) jttokens(jt,(x)) +#define totient(x) jttotient(jt,(x)) +#define toutf8(x) jttoutf8(jt,(x)) +#define toutf16(x) jttoutf16(jt,(x)) +#define toutf16x(x) jttoutf16x(jt,(x)) +#define tparse(x) jttparse(jt,(x)) +#define tpoly(x) jttpoly(jt,(x)) +#define tpop(x) jttpop(jt,(x)) +#define tpush(x) jttpush(jt,(x)) +#define traverse(x,y) jttraverse(jt,(x),(y)) +#define trc(x) jttrc(jt,(x)) +#define treach(x) jttreach(jt,(x)) +#define trep(x) jttrep(jt,(x)) +#define tridiag(x,y,z) jttridiag(jt,(x),(y),(z)) +#define troot(x,y) jttroot(jt,(x),(y)) +#define trr(x) jttrr(jt,(x)) +#define tryinit(x,y,z) jttryinit(jt,(x),(y),(z)) +#define ts(x) jtts(jt,(x)) +#define tsit2(x,y) jttsit2(jt,(x),(y)) +#define tymes(x,y) jttymes(jt,(x),(y)) +#define uco1(x) jtuco1(jt,(x)) +#define uco2(x,y) jtuco2(jt,(x),(y)) +#define unbinr(x0,x1,x2,x3,x4) jtunbinr(jt,(x0),(x1),(x2),(x3),(x4)) +#define under(x,y) jtunder(jt,(x),(y)) +#define unh(x) jtunh(jt,(x)) +#define unhex(x) jtunhex(jt,(x)) +#define unlj(x) jtunlj(jt,(x)) +#define unlk(x) jtunlk(jt,(x)) +#define unlock1(x) jtunlock1(jt,(x)) +#define unlock2(x,y) jtunlock2(jt,(x),(y)) +#define unname(x) jtunname(jt,(x)) +#define unparse(x) jtunparse(jt,(x)) +#define unparse1(x0,x1,x2,x3) jtunparse1(jt,(x0),(x1),(x2),(x3)) +#define unparse1a(x,y,z) jtunparse1a(jt,(x),(y),(z)) +#define unparsem(x,y) jtunparsem(jt,(x),(y)) +#define unquote(x,y,z) jtunquote(jt,(x),(y),(z)) +#define unstackcv(x) jtunstackcv(jt,(x)) +#define unzero(x) jtunzero(jt,(x)) +#define upon2(x,y,z) jtupon2(jt,(x),(y),(z)) +#define uponf2(x,y,z) jtuponf2(jt,(x),(y),(z)) +#define usebs(x,y,z) jtusebs(jt,(x),(y),(z)) +#define utype(x,y) jtutype(jt,(x),(y)) +#define v2(x,y) jtv2(jt,(x),(y)) +#define va1(x,y) jtva1(jt,(x),(y)) +#define va1s(x0,x1,x2,x3) jtva1s(jt,(x0),(x1),(x2),(x3)) +#define va2(x,y,z) jtva2(jt,(x),(y),(z)) +#define vaid(x) jtvaid(jt,(x)) +#define vains(x0,x1,x2,x3) jtvains(jt,(x0),(x1),(x2),(x3)) +#define vapfx(x0,x1,x2,x3) jtvapfx(jt,(x0),(x1),(x2),(x3)) +#define var(x0,x1,x2,x3,x4,x5,x6) jtvar(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6)) +#define vasfx(x0,x1,x2,x3) jtvasfx(jt,(x0),(x1),(x2),(x3)) +#define vasp(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) jtvasp(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11),(x12)) +#define vasp0(x0,x1,x2,x3,x4,x5) jtvasp0(jt,(x0),(x1),(x2),(x3),(x4),(x5)) +#define vaspc(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) jtvaspc(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11),(x12)) +#define vaspeq(x0,x1,x2,x3,x4,x5,x6,x7,x8) jtvaspeq(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8)) +#define vaspeqprep(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11) jtvaspeqprep(jt,(x0),(x1),(x2),(x3),(x4),(x5),(x6),(x7),(x8),(x9),(x10),(x11)) +#define vaspz(x) jtvaspz(jt,(x)) +#define vaxis(x,y) jtvaxis(jt,(x),(y)) +#define vc1(x,y) jtvc1(jt,(x),(y)) +#define vci(x) jtvci(jt,(x)) +#define vec(x,y,z) jtvec(jt,(x),(y),(z)) +#define vfinal(x) jtvfinal(jt,(x)) +#define vfn(x) jtvfn(jt,(x)) +#define vger2(x,y,z) jtvger2(jt,(x),(y),(z)) +#define vi(x) jtvi(jt,(x)) +#define vib(x) jtvib(jt,(x)) +#define vip(x) jtvip(jt,(x)) +#define vlocnl(x,y) jtvlocnl(jt,(x),(y)) +#define vmove(x,y,z) jtvmove(jt,(x),(y),(z)) +#define vnm(x,y) jtvnm(jt,(x),(y)) +#define vs(x) jtvs(jt,(x)) +#define vtokens(x) jtvtokens(jt,(x)) +#define vtrans(x) jtvtrans(jt,(x)) +#define wa(x,y,z) jtwa(jt,(x),(y),(z)) +#define weight(x,y) jtweight(jt,(x),(y)) +#define widthdp(x,y,z) jtwidthdp(jt,(x),(y),(z)) +#define wordil(x) jtwordil(jt,(x)) +#define words(x) jtwords(jt,(x)) +#define x10(x) jtx10(jt,(x)) +#define xbin(x,y) jtxbin(jt,(x),(y)) +#define xbinp(x,y) jtxbinp(jt,(x),(y)) +#define xc(x) jtxc(jt,(x)) +#define xco1(x) jtxco1(jt,(x)) +#define xco2(x,y) jtxco2(jt,(x),(y)) +#define xcompare(x,y) jtxcompare(jt,(x),(y)) +#define xcvt(x,y) jtxcvt(jt,(x),(y)) +#define xdefn(x,y,z) jtxdefn(jt,(x),(y),(z)) +#define xd1(x) jtxd1(jt,(x)) +#define xdiv(x,y,z) jtxdiv(jt,(x),(y),(z)) +#define xdivrem(x0,x1,x2,x3) jtxdivrem(jt,(x0),(x1),(x2),(x3)) +#define xev1(x,y) jtxev1(jt,(x),(y)) +#define xev2(x,y,z) jtxev2(jt,(x),(y),(z)) +#define xexp(x,y) jtxexp(jt,(x),(y)) +#define xfact(x) jtxfact(jt,(x)) +#define xfactor(x) jtxfactor(jt,(x)) +#define xgcd(x,y) jtxgcd(jt,(x),(y)) +#define xint(x) jtxint(jt,(x)) +#define xlcm(x,y) jtxlcm(jt,(x),(y)) +#define xlinit() jtxlinit(jt) +#define xlog1(x) jtxlog1(jt,(x)) +#define xlog2(x,y) jtxlog2(jt,(x),(y)) +#define xlog2sub(x,y) jtxlog2sub(jt,(x),(y)) +#define xlogabs(x) jtxlogabs(jt,(x)) +#define xlogd1(x) jtxlogd1(jt,(x)) +#define xlogz1(x) jtxlogz1(jt,(x)) +#define xminus(x,y) jtxminus(jt,(x),(y)) +#define xmodpow(x,y,z) jtxmodpow(jt,(x),(y),(z)) +#define xoinit() jtxoinit(jt) +#define xop(x) jtxop(jt,(x)) +#define xopcall(x) jtxopcall(jt,(x)) +#define xpi(x) jtxpi(jt,(x)) +#define xplus(x,y) jtxplus(jt,(x),(y)) +#define xpow(x,y) jtxpow(jt,(x),(y)) +#define xprimeq(x,y) jtxprimeq(jt,(x),(y)) +#define xprimetest(x) jtxprimetest(jt,(x)) +#define xrand(x) jtxrand(jt,(x)) +#define xrem(x,y) jtxrem(jt,(x),(y)) +#define xrep(x,y) jtxrep(jt,(x),(y)) +#define xroot(x,y) jtxroot(jt,(x),(y)) +#define xsgn(x) jtxsgn(jt,(x)) +#define xsinit() jtxsinit(jt) +#define xsq(x) jtxsq(jt,(x)) +#define xsqrt(x) jtxsqrt(jt,(x)) +#define xstd(x) jtxstd(jt,(x)) +#define xtymes(x,y) jtxtymes(jt,(x),(y)) +#define zacos(x) jtzacos(jt,(x)) +#define zacosh(x) jtzacosh(jt,(x)) +#define zarc(x) jtzarc(jt,(x)) +#define zasin(x) jtzasin(jt,(x)) +#define zasinh(x) jtzasinh(jt,(x)) +#define zatan(x) jtzatan(jt,(x)) +#define zatanh(x) jtzatanh(jt,(x)) +#define zbin(x,y) jtzbin(jt,(x),(y)) +#define zceil(x) jtzceil(jt,(x)) +#define zcir(x,y) jtzcir(jt,(x),(y)) +#define zconjug(x) jtzconjug(jt,(x)) +#define zcos(x) jtzcos(jt,(x)) +#define zcosh(x) jtzcosh(jt,(x)) +#define zdiv(x,y) jtzdiv(jt,(x),(y)) +#define zeq(x,y) jtzeq(jt,(x),(y)) +#define zexp(x) jtzexp(jt,(x)) +#define zfloor(x) jtzfloor(jt,(x)) +#define zgamma(x) jtzgamma(jt,(x)) +#define zgauss(x,y) jtzgauss(jt,(x),(y)) +#define zgcd(x,y) jtzgcd(jt,(x),(y)) +#define zgps(x) jtzgps(jt,(x)) +#define zgrecur(x) jtzgrecur(jt,(x)) +#define zhorner(x,y,z) jtzhorner(jt,(x),(y),(z)) +#define zjx(x) jtzjx(jt,(x)) +#define zlcm(x,y) jtzlcm(jt,(x),(y)) +#define zlog(x) jtzlog(jt,(x)) +#define zm4(x) jtzm4(jt,(x)) +#define zminus(x,y) jtzminus(jt,(x),(y)) +#define zmj(x) jtzmj(jt,(x)) +#define znegate(x) jtznegate(jt,(x)) +#define zp4(x) jtzp4(jt,(x)) +#define zp8(x) jtzp8(jt,(x)) +#define zpad1(x,y,z) jtzpad1(jt,(x),(y),(z)) +#define zpadn(x,y,z) jtzpadn(jt,(x),(y),(z)) +#define zplus(x,y) jtzplus(jt,(x),(y)) +#define zpow(x,y) jtzpow(jt,(x),(y)) +#define zrem(x,y) jtzrem(jt,(x),(y)) +#define zsin(x) jtzsin(jt,(x)) +#define zsinh(x) jtzsinh(jt,(x)) +#define zsqrt(x) jtzsqrt(jt,(x)) +#define zstirling(x) jtzstirling(jt,(x)) +#define ztan(x) jtztan(jt,(x)) +#define ztanh(x) jtztanh(jt,(x)) +#define ztrend(x) jtztrend(jt,(x)) +#define ztridiag(x,y,z) jtztridiag(jt,(x),(y),(z)) +#define ztymes(x,y) jtztymes(jt,(x),(y))
new file mode 100644 --- /dev/null +++ b/jc.h @@ -0,0 +1,202 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Character Definitions */ + + +#define CX 0 /* other */ +#define CS 1 /* space or tab */ +#define CA 2 /* letter */ +#define CN 3 /* N (capital N) */ +#define CB 4 /* B (capital B) */ +#define C9 5 /* digit or sign (underscore) */ +#define CD 6 /* dot */ +#define CC 7 /* colon */ +#define CQ 8 /* quote */ + +#define CESC1 '.' /* 46 056 2e 1st escape char */ +#define CESC2 ':' /* 58 072 3a 2nd escape char */ + +#define C0 '\000' /* 0 000 00 */ +#define C1 '\001' /* 1 001 01 */ +#define COFF '\004' /* 4 004 04 ctrl d */ +#define CTAB '\011' /* 9 011 09 tab */ +#define CLF '\012' /* 10 012 0a line feed */ +#define CCR '\015' /* 13 015 0d carriage return */ +#define CBW0000 '\020' /* 16 020 10 bitwise fns */ +#define CBW0001 '\021' /* 17 021 11 */ +#define CBW0010 '\022' /* 18 022 12 */ +#define CBW0011 '\023' /* 19 023 13 */ +#define CBW0100 '\024' /* 20 024 14 */ +#define CBW0101 '\025' /* 21 025 15 */ +#define CBW0110 '\026' /* 22 026 16 */ +#define CBW0111 '\027' /* 23 027 17 */ +#define CBW1000 '\030' /* 24 030 18 */ +#define CBW1001 '\031' /* 25 031 19 */ +#define CBW1010 '\032' /* 26 032 1a */ +#define CBW1011 '\033' /* 27 033 1b */ +#define CBW1100 '\034' /* 28 034 1c */ +#define CBW1101 '\035' /* 29 035 1d */ +#define CBW1110 '\036' /* 30 036 1e */ +#define CBW1111 '\037' /* 31 037 1f */ +#define CBANG '!' /* 33 041 21 */ +#define CQQ '\042' /* 34 042 22 double quote */ +#define CPOUND '#' /* 35 043 23 */ +#define CDOLLAR '$' /* 36 044 24 */ +#define CDIV '%' /* 37 045 25 */ +#define CAMP '&' /* 38 046 26 */ +#define CQUOTE '\047' /* 39 047 27 single quote */ +#define CLPAR '(' /* 40 050 28 */ +#define CRPAR ')' /* 41 051 29 */ +#define CSTAR '*' /* 42 052 2a */ +#define CPLUS '+' /* 43 053 2b */ +#define CCOMMA ',' /* 44 054 2c */ +#define CMINUS '-' /* 45 055 2d */ +#define CDOT '.' /* 46 056 2e */ +#define CSLASH '/' /* 47 057 2f */ +#define CNOUN '0' /* 48 060 30 */ +#define CHOOK '2' /* 50 062 32 */ +#define CFORK '3' /* 51 063 33 */ +#define CADVF '4' /* 52 064 34 bonded conjunction */ +#define CCOLON ':' /* 58 072 3a */ +#define CSEMICO ';' /* 59 073 3b */ +#define CRAZE ';' /* 59 073 3b */ +#define CBOX '<' /* 60 074 3c */ +#define CLT '<' /* 60 074 3c */ +#define CEQ '=' /* 61 075 3d */ +#define COPE '>' /* 62 076 3e */ +#define CGT '>' /* 62 076 3e */ +#define CQUERY '?' /* 63 077 3f */ +#define CAT '@' /* 64 100 40 */ +#define CLEFT '[' /* 91 133 5b */ +#define CBSLASH '\134' /* 92 134 5c \ backslash */ +#define CRIGHT ']' /* 93 135 5d */ +#define CEXP '^' /* 94 136 5e */ +#define CSIGN '_' /* 95 137 5f minus sign */ +#define CINF '_' /* 95 137 5f infinity */ +#define CGRAVE '`' /* 96 140 60 */ +#define CLBRACE '{' /* 123 173 7b */ +#define CFROM '{' /* 123 173 7b */ +#define CSTILE '|' /* 124 174 7c */ +#define CRBRACE '}' /* 125 175 7d */ +#define CAMEND '}' /* 125 175 7d */ +#define CTILDE '~' /* 126 176 7e */ +#define CASGN '\200' /* 128 200 80 =. */ +#define CGASGN '\201' /* 129 201 81 =: */ +#define CFLOOR '\202' /* 130 202 82 <. */ +#define CMIN '\202' /* 130 202 82 <. */ +#define CLE '\203' /* 131 203 83 <: */ +#define CCEIL '\204' /* 132 204 84 >. */ +#define CMAX '\204' /* 132 204 84 >. */ +#define CGE '\205' /* 133 205 85 >: */ +#define CUSDOT '\206' /* 134 206 86 _. */ +#define CPLUSDOT '\210' /* 136 210 88 +. */ +#define CPLUSCO '\211' /* 137 211 89 +: */ +#define CSTARDOT '\212' /* 138 212 8a *. */ +#define CSTARCO '\213' /* 139 213 8b *: */ +#define CNOT '\214' /* 140 214 8c -. */ +#define CLESS '\214' /* 140 214 8c -. */ +#define CHALVE '\215' /* 141 215 8d -: */ +#define CMATCH '\215' /* 141 215 8d -: */ +#define CDOMINO '\216' /* 142 216 8e %. */ +#define CSQRT '\217' /* 143 217 8f %: */ +#define CROOT '\217' /* 143 217 8f %: */ +#define CLOG '\220' /* 144 220 90 ^. */ +#define CPOWOP '\221' /* 145 221 91 ^: */ +#define CSPARSE '\222' /* 146 222 92 $. */ +#define CSELF '\223' /* 147 223 93 $: */ +#define CNUB '\224' /* 148 224 94 ~. */ +#define CNE '\225' /* 149 225 95 ~: */ +#define CREV '\226' /* 150 226 96 |. */ +#define CROT '\226' /* 150 226 96 |. */ +#define CCANT '\227' /* 151 227 97 |: */ +#define CEVEN '\230' /* 152 230 98 .. */ +#define CODD '\231' /* 153 231 99 .: */ +#define COBVERSE '\232' /* 154 232 9a :. */ +#define CADVERSE '\233' /* 155 233 9b :: */ +#define CCOMDOT '\234' /* 156 234 9c ,. */ +#define CLAMIN '\235' /* 157 235 9d ,: */ +#define CCUT '\236' /* 158 236 9e ;. */ +#define CWORDS '\237' /* 159 237 9f ;: */ +#define CBASE '\240' /* 160 240 a0 #. */ +#define CABASE '\241' /* 161 241 a1 #: */ +#define CFIT '\242' /* 162 242 a2 !. */ +#define CIBEAM '\243' /* 163 243 a3 !: */ +#define CSLDOT '\244' /* 164 244 a4 /. */ +#define CGRADE '\245' /* 165 245 a5 /: */ +#define CBSDOT '\246' /* 166 246 a6 \. */ +#define CDGRADE '\247' /* 167 247 a7 \: */ +#define CLEV '\250' /* 168 250 a8 [. */ +#define CCAP '\251' /* 169 251 a9 [: */ +#define CDEX '\252' /* 170 252 aa ]. */ +#define CIDA '\253' /* 171 253 ab ]: */ +#define CHEAD '\254' /* 172 254 ac {. */ +#define CTAKE '\254' /* 172 254 ac {. */ +#define CTAIL '\255' /* 173 255 ad {: */ +#define CBEHEAD '\256' /* 174 256 ae }. */ +#define CDROP '\256' /* 174 256 ae }. */ +#define CCTAIL '\257' /* 175 257 af }: */ +#define CEXEC '\260' /* 176 260 b0 ". */ +#define CTHORN '\261' /* 177 261 b1 ": */ +#define CGRDOT '\262' /* 178 262 b2 `. */ +#define CGRCO '\263' /* 179 263 b3 `: */ +#define CATDOT '\264' /* 180 264 b4 @. */ +#define CATCO '\265' /* 181 265 b5 @: */ +#define CUNDER '\266' /* 182 266 b6 &. */ +#define CAMPCO '\267' /* 183 267 b7 &: */ +#define CQRYDOT '\270' /* 184 270 b8 ?. */ +#define CQRYCO '\271' /* 185 271 b9 ?: */ + +#define CALP '\272' /* 186 272 ba a. */ +#define CATOMIC '\273' /* 187 273 bb A. */ +#define CACE '\274' /* 188 274 bc a: */ +#define CBDOT '\275' /* 189 275 bd b. */ +#define CCDOT '\276' /* 190 276 be c. */ +#define CCYCLE '\300' /* 192 300 c0 C. */ +#define CDDOT '\301' /* 193 301 c1 d. */ +#define CDCAP '\302' /* 194 302 c2 D. */ +#define CDCAPCO '\303' /* 195 303 c3 D: */ +#define CEPS '\304' /* 196 304 c4 e. */ +#define CEBAR '\305' /* 197 305 c5 E. */ +#define CFIX '\306' /* 198 306 c6 f. */ +#define CFCAPCO '\307' /* 199 307 c7 F: */ +#define CHGEOM '\310' /* 200 310 c8 H. */ +#define CIOTA '\311' /* 201 311 c9 i. */ +#define CICO '\312' /* 202 312 ca i: */ +#define CICAP '\313' /* 203 313 cb I. */ +#define CICAPCO '\314' /* 204 314 cc I: */ +#define CJDOT '\315' /* 205 315 cd j. */ +#define CLDOT '\316' /* 206 316 ce L. */ +#define CLCAPCO '\317' /* 207 317 cf L: */ +#define CMDOT '\320' /* 208 320 d0 m. */ +#define CMCAP '\321' /* 209 321 d1 M. */ +#define CNDOT '\322' /* 210 322 d2 n. */ +#define CCIRCLE '\323' /* 211 323 d3 o. */ +#define CPOLY '\324' /* 212 324 d4 p. */ +#define CPCO '\325' /* 213 325 d5 p: */ +#define CQCAPCO '\326' /* 214 326 d6 Q: */ +#define CQCO '\327' /* 215 327 d7 q: */ +#define CRDOT '\330' /* 216 330 d8 r. */ +#define CSCO '\331' /* 217 331 d9 s: */ +#define CSCAPCO '\332' /* 218 332 da S: */ +#define CTDOT '\333' /* 219 333 db t. */ +#define CTCO '\334' /* 220 334 dc t: */ +#define CTCAP '\335' /* 221 335 dd T. */ +#define CUDOT '\336' /* 222 336 de u. */ +#define CUCO '\337' /* 223 337 df u: */ +#define CVDOT '\340' /* 224 340 e0 v. */ +#define CXDOT '\341' /* 225 341 e1 x. */ +#define CXCO '\342' /* 226 342 e2 x: */ +#define CYDOT '\343' /* 227 343 e3 y. */ + +#define CFCONS '\350' /* 232 350 e8 0: 1: 2: etc. */ +#define CAMIP '\351' /* 233 351 e9 } amend in place */ +#define CCASEV '\352' /* 234 352 ea } case in place */ +#define CFETCH '\353' /* 235 353 eb {:: */ +#define CMAP '\354' /* 236 354 ec {:: */ +#define CEMEND '\355' /* 237 355 ed }:: */ +#define CUNDCO '\356' /* 238 356 ee &.: */ +#define CPDERIV '\357' /* 239 357 ef p.. */ +#define CAPIP '\360' /* 240 360 f0 , append in place */ + +#define CFF '\377' /* 255 377 ff */
new file mode 100644 --- /dev/null +++ b/jconsole.c @@ -0,0 +1,151 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* J console */ +/* #define READLINE for Unix readline support */ +#ifdef _WIN32 +#include <windows.h> +#include <io.h> +#else +#define _isatty isatty +#define _fileno fileno +#endif +#include <signal.h> +#include "j.h" +#include "jeload.h" + +static char **adadbreak; +static void sigint(int k){**adadbreak+=1;signal(SIGINT,sigint);} +static char input[30000]; + +/* J calls for keyboard input (debug suspension and 1!:1[1) */ +/* we call to get next input */ +#ifdef READLINE +/* readlin.h */ +int add_history(const char *); +int read_history(const char *); +int write_history(const char *); +char* readline(const char *); + +int hist=1; +char histfile[256]; + +void rlexit(int c){ if(!hist&&histfile[0]) write_history(histfile);} + +char* Jinput_rl(char* prompt) +{ + static char* line=0; +if(hist) + { + char* s; + hist=0; + histfile[0]=0; + s=getenv("HOME"); + if(s) + { + strcpy(histfile,s); + strcat(histfile,"/.jhistory"); + using_history(); + read_history(histfile); + } + } + if(line) free(line); /* free last input */ + line = readline(prompt); + if(!line) return "2!:55''"; /* ^d eof */ + if(*line) add_history(line); + return line; +} +#endif + +char* Jinput_stdio(char* prompt) +{ + fputs(prompt,stdout); + fflush(stdout); /* windows emacs */ + if(!fgets(input, sizeof(input), stdin)) + { +#ifdef _WIN32 + /* ctrl+c gets here for win */ + if(!_isatty(_fileno(stdin))) return "2!:55''"; + fputs("\n",stdout); + fflush(stdout); + **adadbreak+=1; +#else + /* unix eof without readline */ + return "2!:55''"; +#endif + } + return input; +} + +char* _stdcall Jinput(J jt,char* prompt){ +#ifdef READLINE + if(isatty(0)){ + return Jinput_rl(prompt); + } else +#endif + return Jinput_stdio(prompt); +} + +/* J calls for output */ +void _stdcall Joutput(J jt,int type, char* s) +{ + if(MTYOEXIT==type) + { +#ifdef READLINE + rlexit((int)(I)s); +#endif + exit((int)(I)s); + } + fputs(s,stdout); + fflush(stdout); +} + +void addargv(int argc, char* argv[], C* d) +{ + C *p,*q; I i; + + p=d+strlen(d); + for(i=0;i<argc;++i) + { + if(sizeof(input)<(100+strlen(d)+2*strlen(argv[i]))) exit(100); + if(1==argc){*p++=',';*p++='<';} + if(i)*p++=';'; + *p++='\''; + q=argv[i]; + while(*q) + { + *p++=*q++; + if('\''==*(p-1))*p++='\''; + } + *p++='\''; + } + *p=0; +} + +J jt; + +int main(int argc, char* argv[]) +{ + void* callbacks[] = {Joutput,0,Jinput,0,(void*)SMCON}; int type; + + jepath(argv[0]); // get path to JFE folder + jt=jeload(callbacks); + if(!jt){char m[1000]; jefail(m), fputs(m,stdout); exit(1);} + adadbreak=(char**)jt; // first address in jt is address of breakdata + signal(SIGINT,sigint); + +#ifdef READLINE + char* rl_readline_name="jconsole"; /* argv[0] varies too much*/ +#endif + + if(argc==2&&!strcmp(argv[1],"-jprofile")) + type=3; + else if(argc>2&&!strcmp(argv[1],"-jprofile")) + type=1; + else + type=0; + addargv(argc,argv,input+strlen(input)); + jefirst(type,input); + while(1){jedo(Jinput(jt," "));} + jefree(); + return 0; +}
new file mode 100644 --- /dev/null +++ b/jdlllic.c @@ -0,0 +1,14 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* encode/decode routines - license keys and ijl */ +#ifdef _WIN32 +#include "..\jsrc\j.h" +#else +#include "j.h" +#endif + +F1(jtlock1){ASSERT(0,EVDOMAIN);} /* no encode */ + +F2(jtlock2){ASSERT(0,EVDOMAIN);} /* no decode */ + +F2(jtunlock2){R w;} /* leave alone */
new file mode 100644 --- /dev/null +++ b/je.h @@ -0,0 +1,841 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Extern Declarations */ + + +extern F1(jtabase1); +extern F1(jtadot1); +extern F1(jtaflag1); +extern F1(jtamip); +extern F1(jtarep); +extern F1(jtaro); +extern F1(jtarx); +extern F1(jtassertq); +extern F1(jtasserts); +extern F1(jtbase1); +extern F1(jtbdot); +extern F1(jtbehead); +extern F1(jtbinrep1); +extern F1(jtbit1); +extern F1(jtbitadv); +extern F1(jtbox); +extern F1(jtbox0); +extern F1(jtboxopen); +extern F1(jtboxq); +extern F1(jtboxs); +extern F1(jtbreakfnq); +extern F1(jtbreakfns); +extern F1(jtbsdot); +extern F1(jtbslash); +extern F1(jtca); +extern F1(jtcallback); +extern F1(jtcallbackx); +extern F1(jtcant1); +extern F1(jtcar); +extern F1(jtcasev); +extern F1(jtcatalog); +extern F1(jtcder); +extern F1(jtcderx); +extern F1(jtcdf); +extern F1(jtcdot1); +extern F1(jtceil1); +extern F1(jtconjug); +extern F1(jtcrc1); +extern F1(jtcrccompile); +extern F1(jtctq); +extern F1(jtcts); +extern F1(jtcurtail); +extern F1(jtcvt0); +extern F1(jtdbc); +extern F1(jtdbcall); +extern F1(jtdbcutback); +extern F1(jtdberr); +extern F1(jtdbetx); +extern F1(jtdbjump); +extern F1(jtdbnext); +extern F1(jtdbq); +extern F1(jtdbret); +extern F1(jtdbrr1); +extern F1(jtdbrun); +extern F1(jtdbsig1); +extern F1(jtdbstack); +extern F1(jtdbstackz); +extern F1(jtdbstepinto1); +extern F1(jtdbstepout1); +extern F1(jtdbstepover1); +extern F1(jtdbstopq); +extern F1(jtdbstops); +extern F1(jtdbtrapq); +extern F1(jtdbtraps); +extern F1(jtdecrem); +extern F1(jtdenseit); +extern F1(jtdgrade1); +extern F1(jtdigits10); +extern F1(jtdispq); +extern F1(jtdisps); +extern F1(jtdl); +extern F1(jtdllsymdat); +extern F1(jtdllsymget); +extern F1(jtdllsymset); +extern F1(jtdomainerr1); +extern F1(jtdotnamesq); +extern F1(jtdotnamess); +extern F1(jtdrep); +extern F1(jtdrx); +extern F1(jtduble); +extern F1(jtdx_test); +extern F1(jtemend); +extern F1(jtevmq); +extern F1(jtevms); +extern F1(jtex); +extern F1(jtexec1); +extern F1(jtexg); +extern F1(jtexpn1); +extern F1(jtfa); +extern F1(jtfact); +extern F1(jtfactor); +extern F1(jtfdepadv); +extern F1(jtfh15); +extern F1(jtfiller); +extern F1(jtfix); +extern F1(jtfloor1); +extern F1(jtfmt01); +extern F1(jtfmt11); +extern F1(jtfmt21); +extern F1(jtfname); +extern F1(jtfsmvfya); +extern F1(jtfullname); +extern F1(jtfx); +extern F1(jtfxeach); +extern F1(jtfxx); +extern F1(jtgaussdet); +extern F1(jtgausselm); +extern F1(jtgb_test); +extern F1(jtgh15); +extern F1(jtgrade1); +extern F1(jtgroup); +extern F1(jthalve); +extern F1(jthash); +extern F1(jthead); +extern F1(jthexrep1); +extern F1(jthgdiff); +extern F1(jthost); +extern F1(jthostio); +extern F1(jthostne); +extern F1(jticap); +extern F1(jticvt); +extern F1(jtiden); +extern F1(jtiepdoq); +extern F1(jtiepdos); +extern F1(jtiepq); +extern F1(jtieps); +extern F1(jtimmea); +extern F1(jtimmex); +extern F1(jtincrem); +extern F1(jtintmod2); +extern F1(jtinv); +extern F1(jtiota); +extern F1(jtisnan); +extern F1(jtjclose); +extern F1(jtjdir); +extern F1(jtjdot1); +extern F1(jtjfatt1); +extern F1(jtjferase); +extern F1(jtjfiles); +extern F1(jtjfperm1); +extern F1(jtjfread); +extern F1(jtjfsize); +extern F1(jtjgetenv); +extern F1(jtjgetpid); +extern F1(jtjico1); +extern F1(jtjiread); +extern F1(jtjlock); +extern F1(jtjlocks); +extern F1(jtjmkdir); +extern F1(jtjoff); +extern F1(jtjopen); +extern F1(jtjpr); +extern F1(jtjregerror); +extern F1(jtjregcomp); +extern F1(jtjregfree); +extern F1(jtjreghandles); +extern F1(jtjreginfo); +extern F1(jtjunlock); +extern F1(jtjwait); +extern F1(jtlamin1); +extern F1(jtlcg_test); +extern F1(jtlevel1); +extern F1(jtloccre1); +extern F1(jtlocexmark); +extern F1(jtlock1); +extern F1(jtlocmap); +extern F1(jtlocname); +extern F1(jtlocnc); +extern F1(jtlocnl1); +extern F1(jtlocpath1); +extern F1(jtlocsizeq); +extern F1(jtlocsizes); +extern F1(jtlocswitch); +extern F1(jtlogar1); +extern F1(jtlrep); +extern F1(jtlrx); +extern F1(jtmag); +extern F1(jtmap); +extern F1(jtmat); +extern F1(jtmaxmin); +extern F1(jtmema); +extern F1(jtmemf); +extern F1(jtmemo); +extern F1(jtmemr); +extern F1(jtminv); +extern F1(jtmmaxq); +extern F1(jtmmaxs); +extern F1(jtmr_test); +extern F1(jtmt_test); +extern F1(jtnameref); +extern F1(jtnc); +extern F1(jtnch); +extern F1(jtnegate); +extern F1(jtnfb); +extern F1(jtnfes); +extern F1(jtnfeoutstr); +extern F1(jtnl1); +extern F1(jtnlsym); +extern F1(jtnot); +extern F1(jtnub); +extern F1(jtnubind); +extern F1(jtnubind0); +extern F1(jtnubsieve); +extern F1(jtnubsievesp); +extern F1(jtonm); +extern F1(jtope); +extern F1(jtoutparmq); +extern F1(jtoutparms); +extern F1(jtparse); +extern F1(jtparsea); +extern F1(jtparsercalls); +extern F1(jtpathchdir); +extern F1(jtpathcwd); +extern F1(jtpathdll); +extern F1(jtpderiv1); +extern F1(jtpinv); +extern F1(jtpix); +extern F1(jtplt); +extern F1(jtpmarea1); +extern F1(jtpmctr); +extern F1(jtpmstats); +extern F1(jtpmunpack); +extern F1(jtpolar); +extern F1(jtpoly1); +extern F1(jtposq); +extern F1(jtposs); +extern F1(jtpparity); +extern F1(jtppq); +extern F1(jtpps); +extern F1(jtprep); +extern F1(jtprime); +extern F1(jtprx); +extern F1(jtqpctr); +extern F1(jtqpfreq); +extern F1(jtqr); +extern F1(jtra); +extern F1(jtranking); +extern F1(jtrankle); +extern F1(jtrat); +extern F1(jtravel); +extern F1(jtraze); +extern F1(jtrazeh); +extern F1(jtrazein); +extern F1(jtrbrace); +extern F1(jtrca); +extern F1(jtrdot1); +extern F1(jtrecip); +extern F1(jtrect); +extern F1(jtretcommq); +extern F1(jtretcomms); +extern F1(jtreverse); +extern F1(jtright1); +extern F1(jtrinv); +extern F1(jtrngraw); +extern F1(jtrngseedq); +extern F1(jtrngseeds); +extern F1(jtrngselectq); +extern F1(jtrngselects); +extern F1(jtrngstateq); +extern F1(jtrngstates); +extern F1(jtroll); +extern F1(jtrollx); +extern F1(jtsb1); +extern F1(jtsborder); +extern F1(jtscind); +extern F1(jtsclass); +extern F1(jtscm00); +extern F1(jtscm01); +extern F1(jtscm10); +extern F1(jtscm11); +extern F1(jtsct1); +extern F1(jtscz1); +extern F1(jtseclevq); +extern F1(jtseclevs); +extern F1(jtself1); +extern F1(jtshape); +extern F1(jtshapex); +extern F1(jtshift1); +extern F1(jtsignum); +extern F1(jtsiinfo); +extern F1(jtslash); +extern F1(jtsldot); +extern F1(jtsmmblks); +extern F1(jtsnl); +extern F1(jtsp); +extern F1(jtsparse1); +extern F1(jtspcount); +extern F1(jtspfor); +extern F1(jtspforloc); +extern F1(jtspit); +extern F1(jtsqroot); +extern F1(jtsquare); +extern F1(jtstr0); +extern F1(jtstype); +extern F1(jtswap); +extern F1(jtsymbrd); +extern F1(jtsymbrdlock); +extern F1(jtsympool); +extern F1(jtsysparmq); +extern F1(jtsysparms); +extern F1(jtsysq); +extern F1(jttable); +extern F1(jttail); +extern F1(jttally); +extern F1(jttco); +extern F1(jttdot); +extern F1(jtthorn1); +extern F1(jttlimq); +extern F1(jttlims); +extern F1(jttokens); +extern F1(jttparse); +extern F1(jttpush); +extern F1(jttrep); +extern F1(jttrx); +extern F1(jtts); +extern F1(jtts0); +extern F1(jttsit1); +extern F1(jttss); +extern F1(jttoutf8); +extern F1(jttoutf16); +extern F1(jttoutf16x); +extern F1(jtuco1); +extern F1(jtunbin); +extern F1(jtunlock1); +extern F1(jtunname); +extern F1(jtunparse); +extern F1(jtunzero); +extern F1(jtvaspz); +extern F1(jtversq); +extern F1(jtvi); +extern F1(jtvib); +extern F1(jtvip); +extern F1(jtvs); +extern F1(jtvtrans); +extern F1(jtwordil); +extern F1(jtwords); +extern F1(jtxco1); + +extern F2(jtabase2); +extern F2(jtadot2); +extern F2(jtadverse); +extern F2(jtaflag2); +extern F2(jtagenda); +extern F2(jtamp); +extern F2(jtampco); +extern F2(jtanyebar); +extern F2(jtapip); +extern F2(jtapipx); +extern F2(jtapplystr); +extern F2(jtatco); +extern F2(jtatop); +extern F2(jtbase2); +extern F2(jtbinrep2); +extern F2(jtbit); +extern F2(jtbit2); +extern F2(jtbitmatch); +extern F2(jtbitwise0000); +extern F2(jtbitwise0001); +extern F2(jtbitwise0010); +extern F2(jtbitwise0011); +extern F2(jtbitwise0100); +extern F2(jtbitwise0101); +extern F2(jtbitwise0110); +extern F2(jtbitwise0111); +extern F2(jtbitwise1000); +extern F2(jtbitwise1001); +extern F2(jtbitwise1010); +extern F2(jtbitwise1011); +extern F2(jtbitwise1100); +extern F2(jtbitwise1101); +extern F2(jtbitwise1110); +extern F2(jtbitwise1111); +extern F2(jtbitwiserotate); +extern F2(jtbitwiseshift); +extern F2(jtbitwiseshifta); +extern F2(jtcant2); +extern F2(jtcd); +extern F2(jtcdot2); +extern F2(jtcircle); +extern F2(jtcolon); +extern F2(jtcrc2); +extern F2(jtcut); +extern F2(jtdbrr2); +extern F2(jtdbsig2); +extern F2(jtdbstepinto2); +extern F2(jtdbstepout2); +extern F2(jtdbstepover2); +extern F2(jtdcap); +extern F2(jtdcapco); +extern F2(jtddot); +extern F2(jtdeal); +extern F2(jtdealx); +extern F2(jtdgrade2); +extern F2(jtdivide); +extern F2(jtdomainerr2); +extern F2(jtdot); +extern F2(jtdrop); +extern F2(jtebar); +extern F2(jtenqueue); +extern F2(jteps); +extern F2(jteq); +extern F2(jteven); +extern F2(jtevger); +extern F2(jtexec2); +extern F2(jtexpand); +extern F2(jtexpn2); +extern F2(jtfc2); +extern F2(jtfetch); +extern F2(jtfit); +extern F2(jtfixrecursive); +extern F2(jtfmt02); +extern F2(jtfmt12); +extern F2(jtfmt22); +extern F2(jtforeign); +extern F2(jtforeignextra); +extern F2(jtfrom); +extern F2(jtfrombs); +extern F2(jtfromis); +extern F2(jtfromr); +extern F2(jtfromsd); +extern F2(jtfromss); +extern F2(jtfsm); +extern F2(jtgcd); +extern F2(jtge); +extern F2(jtgrade1p); +extern F2(jtgrade2); +extern F2(jtgt); +extern F2(jthexrep2); +extern F2(jthgeom); +extern F2(jthook); +extern F2(jti1ebar); +extern F2(jtic2); +extern F2(jticap2); +extern F2(jtifbebar); +extern F2(jtifrom); +extern F2(jtindexof); +extern F2(jtintdiv); +extern F2(jtjdot2); +extern F2(jtjfappend); +extern F2(jtjfatt2); +extern F2(jtjfperm2); +extern F2(jtjfwrite); +extern F2(jtjico2); +extern F2(jtjiwrite); +extern F2(jtjregmatch); +extern F2(jtjregmatches); +extern F2(jtlamin2); +extern F2(jtlcm); +extern F2(jtlcapco); +extern F2(jtle); +extern F2(jtleft2); +extern F2(jtless); +extern F2(jtlink); +extern F2(jtloccre2); +extern F2(jtlock2); +extern F2(jtlocnl2); +extern F2(jtlocpath2); +extern F2(jtlogar2); +extern F2(jtlt); +extern F2(jtmatch); +extern F2(jtmaximum); +extern F2(jtmdiv); +extern F2(jtmemw); +extern F2(jtminimum); +extern F2(jtminus); +extern F2(jtnamerefop); +extern F2(jtnand); +extern F2(jtne); +extern F2(jtnl2); +extern F2(jtnor); +extern F2(jtnotmatch); +extern F2(jtobverse); +extern F2(jtodd); +extern F2(jtordstat); +extern F2(jtordstati); +extern F2(jtoutof); +extern F2(jtoutstr); +extern F2(jtover); +extern F2(jtpco2); +extern F2(jtpderiv2); +extern F2(jtpdt); +extern F2(jtpdtsp); +extern F2(jtplus); +extern F2(jtpmarea2); +extern F2(jtpoly2); +extern F2(jtpowop); +extern F2(jtqco2); +extern F2(jtqq); +extern F2(jtrazefrom); +extern F2(jtrdot2); +extern F2(jtreaxis); +extern F2(jtreitem); +extern F2(jtrepeat); +extern F2(jtrepeatr); +extern F2(jtreshape); +extern F2(jtresidue); +extern F2(jtrezero); +extern F2(jtright2); +extern F2(jtroot); +extern F2(jtrotate); +extern F2(jtsb2); +extern F2(jtscapco); +extern F2(jtscm002); +extern F2(jtscm012); +extern F2(jtscm102); +extern F2(jtscm112); +extern F2(jtsct2); +extern F2(jtscz2); +extern F2(jtself2); +extern F2(jtsetfv); +extern F2(jtsfrom); +extern F2(jtsmmcar); +extern F2(jtsmmis); +extern F2(jtsparse2); +extern F2(jtstitch); +extern F2(jtstitchsp2); +extern F2(jtsumebar); +extern F2(jttake); +extern F2(jttcap); +extern F2(jtthorn2); +extern F2(jttie); +extern F2(jttsit2); +extern F2(jttymes); +extern F2(jtuco2); +extern F2(jtundco); +extern F2(jtunder); +extern F2(jtunlock2); +extern F2(jtunparsem); +extern F2(jtxco2); +extern F2(jtxlog2a); +extern F2(jtxroota); +extern F2(jtxrx); + +extern DF1(jtbitwise1); +extern DF1(jtbitwiseinsertchar); +extern DF1(jtcrcfixedleft); +extern DF1(jtdetxm); +extern DF1(jtdf1); +extern DF1(jtexppi); +extern DF1(jtdfs1); +extern DF1(jtfsmfx); +extern DF1(jthgcoeff); +extern DF1(jtmean); +extern DF1(jtnum1); +extern DF1(jtrazecut1); +extern DF1(jtredravel); +extern DF1(jtwd); + +extern DF2(jtbitwisechar); +extern DF2(jtcharfn2); +extern DF2(jtdbunquote); +extern DF2(jtdf2); +extern DF2(jtdfs2); +extern DF2(jteachl); +extern DF2(jteachr); +extern DF2(jtfslashatg); +extern DF2(jtnum2); +extern DF2(jtpolymult); +extern DF2(jtrazecut0); +extern DF2(jtrazecut2); +extern DF2(jtrollk); +extern DF2(jtrollkx); + +extern A jtac1(J,AF); +extern A jtac2(J,AF); +extern B jtadd2(J,F,F,C*); +extern I jtaii(J,A); +extern B jtaindex(J,A,A,I,A*); +extern A jtam1a(J,A,A,A,B); +extern A jtam1e(J,A,A,A,B); +extern A jtam1sp(J,A,A,A,B); +extern A jtamna(J,A,A,A,B); +extern A jtamne(J,A,A,A,B); +extern A jtamnsp(J,A,A,A,B); +extern A jtapv(J,I,I,I); +extern A jtascan(J,C,A); +extern A jtaslash(J,C,A); +extern A jtaslash1(J,C,A); +extern A jtatab(J,C,A,A); +extern AF jtatcompf(J,A,A,A); +extern B jtb0(J,A); +extern A jtbcvt(J,C,A); +extern B* jtbfi(J,I,A,B); +extern B jtbitwisecharamp(J,UC*,I,UC*,UC*); +extern B jtboxatop(J,A); +extern A jtbrep(J,B,B,A); +extern A jtcharmap(J,A,A,A); +extern B jtcheckmf(J); +extern B jtchecksi(J); +extern I jtcoerce2(J,A*,A*,I); +extern int jtcompare(J,A,A); +extern A jtconnum(J,I,C*); +extern A jtcpa(J,B,A); +extern A jtcstr(J,C*); +extern A jtcvt(J,I,A); +extern A jtcvz(J,I,A); +extern A jtdaxis(J,I,A); +extern DC jtdeba(J,C,A,A,A); +extern void jtdebdisp(J,DC); +extern void jtdebz(J); +extern D jtdgcd(J,D,D); +extern A jtdropr(J,I,A); +extern B jtecvt(J,D,I,int*,int*,C*); +extern B jtecvtinit(J); +extern B jtequ(J,A,A); +extern A jtev1(J,A,C*); +extern A jtev2(J,A,A,C*); +extern A jteva(J,A,C*); +extern A jteval(J,C*); +extern A jtevc(J,A,A,C*); +extern A jtevery(J,A,A,AF); +extern A jtevery2(J,A,A,A,AF); +extern A jtext(J,B,A); +extern A jtexta(J,I,I,I,I); +extern A jtfdef(J,C,I,AF,AF,A,A,A,I,I,I,I); +extern I jtfdep(J,A); +extern void jtfh(J,A); +extern I jtfnum(J,A); +extern A jtfolk(J,A,A,A); /* "fork" name conflict under UNIX */ +extern void jtfr(J,A); +extern A jtfrombsn(J,A,A,I); +extern A jtfrombu(J,A,A,I); +extern A jtfxeachv(J,I,A); +extern A jtga(J,I,I,I,I*); +extern A jtgadv(J,A,C); +extern A jtgah(J,I,A); +extern A jtgc(J,A,I); +extern void jtgc3(J,A,A,A,I); +extern A jtgconj(J,A,A,C); +extern B jtglobinit(J); +extern I jti0(J,A); +extern A jtifb(J,I,B*); +extern A jtindexofprehashed(J,A,A,A); +extern A jtindexofss(J,I,A,A); +extern A jtindexofsub(J,I,A,A); +extern A jtindexofxx(J,I,A,A); +extern A jtinpl(J,B,I,C*); +extern A jtiocol(J,I,A,A); +extern A jtiovsd(J,I,A,A); +extern A jtiovxs(J,I,A,A); +extern A jtirs1(J,A,A,I,AF); +extern A jtirs2(J,A,A,A,I,I,AF); +extern A jtjerrno(J); +extern A jtjgets(J,C*); +extern C jtjinit2(J,int,C**); +extern F jtjope(J,A,C*); +extern A jtjset(J,C*,A); +extern void jtjsigd(J,C*); +extern void jtjsignal(J,I); +extern void jtjsignal3(J,I,A,I); +extern A jtjstd(J,A,A); +extern B jtlocdestroy(J,I); +extern I jtmaxtype(J,I,I); +extern B jtmeminit(J); +extern A jtmerge2(J,A,A,A,B); +extern I jtmult(J,I,I); +extern A jtnfs(J,I,C*); +extern void jtnvrredef(J,A); +extern A jtodom(J,I,I,I*); +extern B jtparseinit(J); +extern A jtparsex(J,A,B,CW*,DC); +extern A jtpaxis(J,I,A); +extern A jtpcvt(J,I,A); +extern A jtpfill(J,I,A); +extern A jtpind(J,I,A); +extern B jtpinit(J); +extern void jtpmrecord(J,A,A,I,int); +extern B jtpreparse(J,A,A*,A*); +extern B jtprimitive(J,A); +extern L* jtprobe(J,A,A); +extern I jtprod(J,I,I*); +extern int jtqcompare(J,Q,Q); +extern A jtraa(J,I,A); +extern A jtrank1ex(J,A,A,I,AF); +extern A jtrank2ex(J,A,A,A,I,I,AF); +extern A jtrd(J,F,I,I); +extern B jtredef(J,A,L*); +extern B jtrnginit(J); +extern B jtsbtypeinit(J); +extern A jtsc(J,I); +extern A jtsc4(J,I,I); +extern A jtscansp(J,A,A,AF); +extern A jtscb(J,B); +extern A jtscc(J,C); +extern A jtscf(J,D); +extern B jtscheck(J,A); +extern A jtscx(J,X); +extern B jtsesminit(J); +extern A jtsfn(J,B,A); +extern void jtshowerr(J); +extern A jtsparseit(J,A,A,A); +extern B jtspc(J); +extern A jtspella(J,A); +extern A jtspellcon(J,I); +extern A jtspellout(J,C); +extern B jtspfree(J); +extern B jtspmult(J,A*,A,A,C,I,I,I,I); +extern A jtsprank1(J,A,A,I,AF); +extern A jtsprank2(J,A,A,A,I,I,AF); +extern A jtstcreate(J,C,I,I,C*); +extern F jtstdf(J,A); +extern A jtstfind(J,B,I,C*); +extern A jtstr(J,I,C*); +extern B jtsymbinit(J); +extern A jtsymbis(J,A,A,A); +extern B jtsymext(J,B); +extern B jtsymfree(J,L*); +extern B jtsymfreeh(J,A,L*); +extern L* jtsymnew(J,I*); +extern L* jtsyrd(J,A,A*); +extern A jttaker(J,I,A); +extern D jttceil(J,D); +extern B jtteq(J,D,D); +extern D jttfloor(J,D); +extern I jtthv(J,A,I,C*); +extern B jttlt(J,D,D); +extern A jttoc1(J,B,A); +extern void jttoutf8x(J,C*,I,US*); +extern I jttpop(J,I); +extern B jttrd(J jt,A w); +extern B jtunlk(J,I); +extern A jtv2(J,I,I); +extern A jtva2s(J,A,A,C,VF,I,I,I,I,I); +extern C jtvaid(J,A); +extern void jtvains(J,C,I,VF*,I*); +extern void jtvapfx(J,C,I,VF*,I*); +extern B jtvar(J,C,A,A,I,I,VF*,I*); +extern void jtvasfx(J,C,I,VF*,I*); +extern A jtvasp(J,A,A,C,VF,I,I,I,I,I,I,I,I,I); +extern B jtvc1(J,I,US*); +extern A jtvci(J,I); +extern A jtvec(J,I,I,void*); +extern F jtvfn(J,F); +extern A jtvger2(J,C,A,A); +extern B jtvnm(J,I,C*); +extern void jtwri(J,I,C*,I,C*); +extern A jtxcvt(J,I,A); +extern B jtxlinit(J); +extern B jtxoinit(J); +extern B jtxsinit(J); + +extern B all0(A); +extern B all1(A); +extern I atype(I); +extern I bp(I); +extern I bsum(I,B*); +extern C cf(A); +extern C cl(A); +extern I efr(I,I); +extern B evoke(A); +extern void fillv(I,I,C*); /* "fill" name conflict on Mac */ +extern UI hic(I,UC*); +extern UI hic2(I,UC*); +extern I hsize(I); +extern void irange(I,I*,I*,I*); +extern J jinit(void); +extern void jsto(J,I,C*); +extern void jstpoll(J); +extern void jststop(J); +extern I level(A); +extern I lr(A); +extern I mr(A); +extern void mvc(I,void*,I,void*); +extern B nameless(A); +extern D qpf(void); +extern I rr(A); +extern A relocate(I,A); +extern I rtype(I); +extern C spellin(I,C*); +extern void spellit(C,C*); +extern void smmfrr(A); +extern D tod(void); +extern B vlocnm(I,C*); +extern D xdouble(X); + +extern A a0j1; +extern A ace; +extern A ainf; +extern A alp; +extern A aqq; +extern UC bit[]; +extern UC bitc[]; +extern C bitdisp[]; +extern C breakdata; +extern A chr[]; +extern C ctype[]; +extern D inf; +extern D infm; +extern A iv0; +extern A iv1; +extern D jnan; /* "nan" name conflict under Solaris */ +extern I liln; +extern A mark; +extern C minus0[]; +extern A mnam; +extern I msize[]; +extern A mdot; +extern A mtm; +extern A mtv; +extern A ndot; +extern A nnam; +extern I nptab; +extern A* num; +extern A numv[]; +extern A one; +extern D pf; +extern A pie; /* "pi" name conflict */ +extern I prokey; +extern A pst[]; +extern I ptab[]; +extern A udot; +extern A unam; /* "uname" name conflict in Unix */ +extern A vdot; +extern A vnam; +extern B testb[]; +extern C wtype[]; +extern A xdot; +extern A xnam; +extern X xone; +extern X xzero; +extern A ydot; +extern A ynam; +extern A zero; +extern Z zeroZ; +extern A zpath; + +#if SY_64 && SY_WIN32 +extern D jfloor1(D); +#endif + +#if (SYS & SYS_ATARIST+SYS_ATT3B1) +extern int memcmp(); /* C library fn */ +extern D strtod(); /* C library fn */ +extern I strtol(); /* C library fn */ +#endif
new file mode 100644 --- /dev/null +++ b/jeload.c @@ -0,0 +1,190 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +// utilities for JFE to load JE, initiallize, and run profile sentence +// JFEs are jconsole, jwdw, and jwdp +#define PLEN 1000 // path length +#ifdef _WIN32 + #include <windows.h> + +#ifdef UNDER_CE + #define GETPROCADDRESS(h,p) GetProcAddress(h,_T(p)) +#else + #define GETPROCADDRESS(h,p) GetProcAddress(h,p) +#endif + #define JDLLNAME "\\j.dll" + #define filesep '\\' + #define filesepx "\\" +// setfocus e required for pocketpc and doesn't hurt others +#define ijx "11!:0'pc ijx closeok;xywh 0 0 300 200;cc e editijx rightmove bottommove ws_vscroll ws_hscroll;setfont e \"Courier New\" 12;setfocus e;pas 0 0;pgroup jijx;pshow;'[18!:4<'base'" + +#else + #include <dlfcn.h> + #define GETPROCADDRESS(h,p) dlsym(h,p) + #define _stdcall + #define filesep '/' + #define filesepx "/" + #define ijx "11!:0'pc ijx closeok;xywh 0 0 300 200;cc e editijx rightmove bottommove ws_vscroll ws_hscroll;setfont e monospaced 12;pas 0 0;pgroup jijx;pshow;'[18!:4<'base'" + #ifdef __MACH__ + #define JDLLNAME "/libj.dylib" + #else + #define JDLLNAME "/libj.so" + #endif +#endif +#include "j.h" + +static void* hjdll; +static J jt; +static JDoType jdo; +static JFreeType jfree; +static JgaType jga; +static JGetLocaleType jgetlocale; +static char path[PLEN]; +static char pathdll[PLEN]; + +int jedo(char* sentence) +{ + return jdo(jt,sentence); +} + +void jefree(){jfree(jt);} +char* jegetlocale(){return jgetlocale(jt);} +A jega(I t, I n, I r, I*s){return jga(jt,t,n,r,s);} +void* jehjdll(){return hjdll;} + +// load JE, Jinit, getprocaddresses, JSM +J jeload(void* callbacks) +{ +#ifdef _WIN32 + WCHAR wpath[PLEN]; + MultiByteToWideChar(CP_UTF8,0,pathdll,1+(int)strlen(pathdll),wpath,PLEN); + hjdll=LoadLibraryW(wpath); +#else + hjdll=dlopen(pathdll,RTLD_LAZY); +#endif + if(!hjdll)return 0; + jt=((JInitType)GETPROCADDRESS(hjdll,"JInit"))(); + if(!jt) return 0; + ((JSMType)GETPROCADDRESS(hjdll,"JSM"))(jt,callbacks); + jdo=(JDoType)GETPROCADDRESS(hjdll,"JDo"); + jfree=(JFreeType)GETPROCADDRESS(hjdll,"JFree"); + jga=(JgaType)GETPROCADDRESS(hjdll,"Jga"); + jgetlocale=(JGetLocaleType)GETPROCADDRESS(hjdll,"JGetLocale"); + return jt; +} + +// set path and pathdll (wpath also set for win) +// WIN arg is 0, Unix arg is argv[0] +void jepath(char* arg) +{ +#ifdef _WIN32 + WCHAR wpath[PLEN]; + GetModuleFileNameW(0,wpath,_MAX_PATH); + *(wcsrchr(wpath, '\\')) = 0; + WideCharToMultiByte(CP_UTF8,0,wpath,1+(int)wcslen(wpath),path,PLEN,0,0); +#else + +#define sz 4000 + char arg2[sz],arg3[sz]; + char* src,*snk;int n,len=sz; + // fprintf(stderr,"arg0 %s\n",arg); + // try host dependent way to get path to executable + // use arg if they fail (arg command in PATH won't work) +#ifdef __MACH__ + n=_NSGetExecutablePath(arg2,&len); + if(0!=n) strcat(arg2,arg); +#else + n=readlink("/proc/self/exe",arg2,sizeof(arg2)); + if(-1==n) strcpy(arg2,arg); else arg2[n]=0; +#endif + // fprintf(stderr,"arg2 %s\n",arg2); + // arg2 is path (abs or relative) to executable or soft link + n=readlink(arg2,arg3,sz); + if(-1==n) strcpy(arg3,arg2); else arg3[n]=0; + // fprintf(stderr,"arg3 %s\n",arg3); + if('/'==*arg3) + strcpy(path,arg3); + else + { + getcwd(path,sizeof(path)); + strcat(path,"/"); + strcat(path,arg3); + } + *(1+strrchr(path,'/'))=0; + // remove ./ and backoff ../ + snk=src=path; + while(*src) + { + if('/'==*src&&'.'==*(1+src)&&'.'==*(2+src)&&'/'==*(3+src)) + { + *snk=0; + snk=strrchr(path,'/'); + snk=0==snk?path:snk; + src+=3; + } + else if('/'==*src&&'.'==*(1+src)&&'/'==*(2+src)) + src+=2; + else + *snk++=*src++; + } + *snk=0; + snk=path+strlen(path)-1; + if('/'==*snk) *snk=0; +#endif + strcpy(pathdll,path); + strcat(pathdll,JDLLNAME); + // fprintf(stderr,"arg4 %s\n",path); +} + +// called by jwdp (java jnative.c) to set path +void jesetpath(char* arg) +{ + strcpy(pathdll,arg); // jwdp gives path to j.dll + strcpy(path,arg); + *(strrchr(path,filesep)) = 0; +} + +// build and run first sentence to set BINPATH, ARGV, and run profile +// arg is command line ready to set in ARGV_z_ +// type is 0 normal, 1 -jprofile xxx, 2 ijx basic, 3 nothing +// profile[ARGV_z_=:...[BINPATH=:.... +// profile is from BINPATH, ARGV, ijx basic, or nothing +int jefirst(int type,char* arg) +{ + int r; char* p,*q; + char* input=malloc(2000+strlen(arg)); + *input=0; + if(0==type) + { + strcat(input,"(3 : '0!:0 y')<BINPATH,'"); + strcat(input,filesepx); + strcat(input,"profile.ijs'"); + } + else if(1==type) + strcat(input,"(3 : '0!:0 y')2{ARGV"); + else if(2==type) + strcat(input,ijx); + else + strcat(input,"i.0 0"); + strcat(input,"[ARGV_z_=:"); + strcat(input,arg); + strcat(input,"[BINPATH_z_=:'"); + p=path; + q=input+strlen(input); + while(*p) + { + if(*p=='\'') *q++='\''; // 's doubled + *q++=*p++; + } + *q=0; + strcat(input,"'"); + r=jedo(input); + free(input); + return r; +} + +void jefail(char* msg) +{ + strcpy(msg, "Load library "); + strcat(msg, pathdll); + strcat(msg," failed."); +}
new file mode 100644 --- /dev/null +++ b/jeload.h @@ -0,0 +1,12 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +void jepath(char*); +void jesetpath(char*); +void* jeload(void* callbacks); // returns J +int jefirst(int,char*); +int jedo(char*); +void jefree(); +char* jegetlocale(); +void jefail(char*); +void* jega(I t, I n, I r, I*s); // returns A +void* jehjdll();
new file mode 100644 --- /dev/null +++ b/jerr.h @@ -0,0 +1,48 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Error Codes */ + + +#define EVATTN 1 /* See i.c for error texts */ +#define EVBREAK 2 +#define EVDOMAIN 3 +#define EVILNAME 4 +#define EVILNUM 5 +#define EVINDEX 6 +#define EVFACE 7 +#define EVINPRUPT 8 +#define EVLENGTH 9 +#define EVLIMIT 10 +#define EVNONCE 11 +#define EVASSERT 12 +#define EVOPENQ 13 +#define EVRANK 14 +#define EVSPELL 16 +#define EVSTACK 17 +#define EVSTOP 18 +#define EVSYNTAX 19 +#define EVSYSTEM 20 +#define EVVALUE 21 +#define EVWSFULL 22 +#define EVCTRL 23 +#define EVFACCESS 24 +#define EVFNAME 25 +#define EVFNUM 26 +#define EVTIME 27 +#define EVSECURE 28 +#define EVSPARSE 29 +#define EVLOCALE 30 +#define EVRO 31 +#define EVALLOC 32 +#define EVNAN 33 +#define NEVM 33 /* number of event codes */ + +/* The following codes are never displayed to the user */ + +#define EWOV 50 /* integer overflow */ +#define EWIMAG 51 /* imaginery result */ +#define EWIRR 52 /* irrational result */ +#define EWRAT 53 /* rational result */ +#define EWDIV0 54 /* division by zero */ +#define EWTHROW 55 /* throw. executed */
new file mode 100644 --- /dev/null +++ b/jlib.h @@ -0,0 +1,41 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ + +J _stdcall JInit(); /* init instance */ +void _stdcall JSM(J jt, void*callbacks[]); /* set callbacks */ +int _stdcall JDo(J jt,C*); /* run sentence */ +C* _stdcall JGetLocale(J jt); /* get locale */ +int _stdcall JFree(J jt); /* free instance */ +A _stdcall JGetA(J jt,I n,C* name); /* get 3!:1 from name */ +I _stdcall JSetA(J jt,I n,C* name,I x,C* d);/* name=:3!:2 data */ + +typedef void* (_stdcall *JInitType) (); +typedef int (_stdcall *JDoType) (void*, C*); +typedef C* (_stdcall *JGetLocaleType)(void*); +typedef void (_stdcall *JSMType) (void*, void*); +typedef void (_stdcall *JFreeType) (void*); +typedef A (_stdcall *JgaType) (J jt, I t, I n, I r, I*s); + +/* void* callbacks[] = {Joutput, Jwd, Jinput, unused, smoptions}; */ + +typedef void (_stdcall * outputtype)(J,int,C*); +typedef int (_stdcall * dowdtype) (J,int, A, A*); +typedef C* (_stdcall * inputtype) (J,C*); + +void _stdcall Joutput(J jt, int type, C* s); +int _stdcall Jwd(J jt, int x, A parg, A* pres); +C* _stdcall Jinput(J jt, C*); + +// output type +#define MTYOFM 1 /* formatted result array output */ +#define MTYOER 2 /* error output */ +#define MTYOLOG 3 /* output log */ +#define MTYOSYS 4 /* system assertion failure */ +#define MTYOEXIT 5 /* exit */ +#define MTYOFILE 6 /* output 1!:2[2 */ + +// smoptions +#define SMWIN 0 /* j.exe Jwdw (Windows) front end */ +#define SMJAVA 2 /* j.jar Jwdp (Java) front end */ +#define SMCON 3 /* jconsole */ +
new file mode 100644 --- /dev/null +++ b/js.h @@ -0,0 +1,176 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* SYS_ and friends */ + +#ifndef SYS /* only include once (dtoa.c) */ + +/* Inclusion of a system herein does not necessarily mean that the source */ +/* compiles or works under that system. */ + +#define SYS_AMIGA 1L /* DICE */ +#define SYS_ARCHIMEDES 2L +#define SYS_ATARIST 4L /* GCC */ +#define SYS_ATT3B1 8L /* System V C */ +#define SYS_DEC5500 16L /* GCC */ +#define SYS_IBMRS6000 32L /* AIX XL C */ +#define SYS_MACINTOSH 64L /* Think C */ +#define SYS_MIPS 128L /* GCC */ +#define SYS_NEXT 256L /* GCC */ +#define SYS_OS2 512L +#define SYS_PC 1024L /* Turbo C */ +#define SYS_PCWIN 2048L /* Watcom C 386 */ +#define SYS_PC386 4096L /* Watcom C 386 */ +#define SYS_SGI 8192L /* GCC */ +#define SYS_SUN3 16384L /* GCC */ +#define SYS_SUN4 32768L /* GCC */ +#define SYS_VAX 65536L /* GCC */ +#define SYS_HPUX 131072L /* C89 */ +#define SYS_LINUX 262144L /* GCC */ +#define SYS_FREEBSD 524288L /* x86 only */ +#define SYS_NETBSD 1048576L /* GCC */ +#define SYS_SUNSOL2 2097152L /* GCC */ +#define SYS_MACOSX 4194304L /* GCC (CC) */ + +#define SY_64 0 /* 64-bit systems */ + +#define SY_WIN32 0 /* any windows intel version */ +#define SY_WINCE 0 /* any windows ce versions */ +#define SY_LINUX 0 /* any linux intel version */ +#define SY_MAC 0 /* any macosx intel or powerpc version */ +#define SY_MACPPC 0 /* macosx powerpc */ + +#define SY_GETTOD 0 /* gettimeofday on unix */ + +#define SYS_DOS (SYS_PC + SYS_PC386 + SYS_PCWIN) + +#define SYS_UNIX (SYS_ATT3B1 + SYS_DEC5500 + SYS_IBMRS6000 + \ + SYS_MIPS + SYS_NEXT + SYS_SGI + SYS_SUN3 + \ + SYS_SUN4 + SYS_VAX + SYS_LINUX + SYS_MACOSX + \ + SYS_FREEBSD + SYS_NETBSD + SYS_SUNSOL2 + SYS_HPUX) + +#define SYS_ANSILIB (SYS_AMIGA + SYS_ARCHIMEDES + SYS_DOS + \ + SYS_MACINTOSH + SYS_OS2 + SYS_UNIX) + +#define SYS_SESM (SYS_ARCHIMEDES + SYS_DOS + SYS_MACINTOSH + \ + SYS_OS2 + SYS_UNIX) + +#define SYS_LILENDIAN (SYS_ARCHIMEDES + SYS_DEC5500 + SYS_DOS + \ + SYS_OS2 + SYS_LINUX + SYS_FREEBSD + \ + SYS_NETBSD) + +#if defined(__FreeBSD__) +#define SYS SYS_FREEBSD +#endif + +#if defined(__NetBSD__) +#define SYS SYS_NETBSD +#endif + +#if defined(sparc) && ! defined(__svr4__) +#define SYS SYS_SUN4 +#endif + +#if defined(sparc) && defined(__svr4__) +#define SYS SYS_SUNSOL2 +#endif + +#if defined(__sgi__) +#define SYS SYS_SGI +#endif + +#if defined (_AIX) +#define SYS SYS_IBMRS6000 +#endif + +#ifdef __linux__ +#define SYS SYS_LINUX +#undef SY_LINUX +#define SY_LINUX 1 +#endif + +#if defined _PA_RISC1_1 +#define SYS SYS_HPUX +#endif + +#ifdef __MACH__ +#ifdef __ppc__ +#ifdef __GNUC__ +#define SYS SYS_MACOSX // powerpc +#undef SY_MAC +#define SY_MAC 1 +#undef SY_MACPPC +#def SY_MACPPC 1 +#endif +#endif +#endif + +#ifdef __MACH__ +#ifndef __ppc__ +#ifdef __GNUC__ +#define SYS SYS_MACOSX // intel +#undef SY_MAC +#define SY_MAC 1 +#undef SYS_LILENDIAN +#define SYS_LILENDIAN SYS_MACOSX + +#endif +#endif +#endif + + +#ifdef _WIN32 +#define SYS SYS_PCWIN +#undef SY_WIN32 +#define SY_WIN32 1 +#endif + +#if SYS & SYS_UNIX +#undef SY_GETTOD +#define SY_GETTOD 1 +#endif + +#ifdef UNDER_CE +#undef SY_WINCE +#define SY_WINCE 1 +#endif + +#define SY_ALIGN (!(SY_WIN32 || SYS&SYS_LINUX) || SY_WINCE) +/* SY_ALIGN should be 1 for compilers requiring strict alignment */ +/* e.g. if (I*)av is not allowed for arbitrary av of type C* */ + +/* Windows CE target autoconfiguration: */ +#if SY_WINCE +#ifdef SH3 +#define SY_WINCE_SH 1 +#else +#define SY_WINCE_SH 0 +#endif +#ifdef MIPS +#define SY_WINCE_MIPS 1 +#else +#define SY_WINCE_MIPS 0 +#endif +#ifdef ARM +#define SY_WINCE_ARM 1 +#else +#define SY_WINCE_ARM 0 +#endif +#endif + +/* _WIN64 defined by VC++ and _UNIX64 defined in makefile */ +#if defined(_WIN64) || defined(_UNIX64) +#undef SY_64 +#define SY_64 1 +#endif + +#ifndef SYS /* must be defined */ + error: "SYS must be defined" +#endif + +#if 1!=SY_WIN32+SY_LINUX+SY_MAC + error: "one and only one of SY_WIN32, SY_LINUX, SY_MAC must be 1" +#endif + +#endif /* only include once */ +
new file mode 100644 --- /dev/null +++ b/jt.h @@ -0,0 +1,249 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Definitions for jt ("jthis") */ + +#if !SY_WINCE && (SYS & SYS_DOS) +#include <sys/stat.h> +#endif + +#if (SYS & SYS_UNIX) /* IVL */ +#include <sys/stat.h> +#endif + +/* +All allocated and variable data for a J instance is accessed through +its JST structure. + +Only simple constant data can be global and are shared by J instances. + +Constants such as mtm are created in the dll process_attach. They are +the same for all instances and are never freed. The dll is never +allowed to unload as we don't have code to free mtm et. al. + +j.map must be checked to ensure no 'bad' global data exists. In +windows the global data that needs scrutiny is in the 0003: section. +*/ + + +typedef struct { + C* adbreak; /* must be first! ad mapped shared file break flag */ + I arg; /* integer argument */ + B asgn; /* 1 iff last operation on this line is assignment */ + B assert; /* 1 iff evaluate assert. statements */ + I* breakfh; /* win break file handle */ + C breakfn[NPATH]; /* break file name */ + B breakignore; /* 1 to ignore break (input_jfe_ output_jfe_ */ + I* breakmh; /* win break map handle */ + C* bx; /* box drawing characters */ + A bxa; /* array of box drawing characters */ + I bytes; /* bytes currently in use */ + I bytesmax; /* high-water mark of "bytes" */ + A cdarg; /* table of 15!:0 parsed left arguments */ + A cdhash; /* hash table of indices into cdarg */ + A cdhashl; /* hash table of indices into cdarg */ + I cdna; /* # of used entries in cdarg */ + I cdnl; /* # of used entries in cdhashl */ + I cdns; /* length of used portion of cdstr */ + A cdstr; /* strings for cdarg */ + CMP comp; /* comparison function in sort */ + int compgt; /* comparison: denotes greater than */ + I compk; /* comparison: byte size of each item */ + int complt; /* comparison: denotes less than */ + I compn; /* comparison: number of atoms in each item */ + C* compsev; /* comparison: sparse element value ptr */ + I compsi; /* comparison: sparse current cell index */ + I* compstv; /* comparison: sparse element item indices */ + I compswf; /* comparison: sparse wf value */ + I compsxc; /* comparison: sparse aii(x) */ + C* compsxv; /* comparison: sparse AV(x) */ + I compsyc; /* comparison: sparse aii(y) or *(1+AS(y)) */ + I* compsyv; /* comparison: sparse AV(y) */ + C* compv; /* comparison: beginning of data area */ + A compw; /* comparison: orig arg. (for relative addressing) */ + D ct; /* comparison tolerance */ + UI ctmask; /* 1 iff significant wrt ct; for i. and i: */ + A curlocn; /* current locale name corresp. to curname */ + A curname; /* current name */ + L* cursymb; /* current symbol table entry */ + I db; /* debug flag; see 13!:0 */ + A dbalpha; /* left argument for rerun */ + I dbjump; /* line to jump to */ + A dbomega; /* right argument for rerun */ + A dbresult; /* result to pop to the next level */ + C dbss; /* single step mode */ + DC dbssd; /* stack entry d corresp. to d->dcss setting */ + A dbssexec; /* single step: execute string */ + A dbstops; /* stops set by the user */ + C dbsusact; /* suspension action */ + A dbtrap; /* trap, execute on suspension */ + I dbuser; /* user-entered value for db */ + DC dcs; /* ptr to debug stack entry for current script */ + C diratts[7]; /* set by ismatch, read by dir1 */ + C* dirbase; /* for directory search */ + C dirmode[11]; /* set by ismatch, read by dir1 */ + C dirnamebuf[NPATH];/* for directory search */ + C dirrwx[3]; /* set by ismatch, read by dir1 */ +#if !SY_WINCE + struct stat dirstatbuf; //set by ismatch, read by dir1 +#if !SY_64 && (SYS & SYS_LINUX) + struct stat dummy1; // stat above should be stat64 + struct stat dummy2; // reserve extra to avoid stomping disp +#endif +#endif + I disp[7]; /* # different verb displays */ + I dlllasterror; /* DLL stuff */ + B dotnames; /* 1 iff x. y. etc. names are permitted */ + void*dtoa; /* use internally by dtoa.c */ + C etx[1+NETX]; /* display text for last error (+1 for trailing 0) */ + I etxn; /* strlen(etx) */ + I etxn1; /* last non-zero etxn */ + A evm; /* event messages */ + I fcalli; /* named fn calls: current depth */ + I fcalln; /* named fn calls: maximum permissible depth */ + LS fcallg[1+NFCALL]; /* named fn calls: stack */ + I fdepi; /* fn calls: current depth */ + I fdepn; /* fn calls: maximum permissible depth */ + A fill; /* fill */ + C* fillv; /* fill value */ + C fillv0[sizeof(Z)];/* default fill value */ + A flkd; /* file lock data: number, index, length */ + I flkn; /* file lock count */ + A fopa; /* open files boxed names */ + A fopf; /* open files corresp. file numbers */ + I fopn; /* open files count */ + D fuzz; /* fuzz (sometimes set to 0) */ + I fxi; /* f. depth countdown */ + A fxpath; /* f. path of names */ + A* fxpv; /* f. AAV(fxpath) */ + I getlasterror; /* DLL stuff */ + A global; /* global symbol table */ + I glock; /* 0=unlocked, 1=perm lock, 2=temp lock */ + void*heap; /* heap handle */ + I hin; /* used in dyad i. & i: */ + I* hiv; /* used in dyad i. & i: */ + A iep; /* immediate execution phrase */ + B iepdo; /* 1 iff do iep */ + C jerr; /* error number (0 means no error) */ + I jerr1; /* last non-zero jerr */ + AF lcp; /* linear representation paren function */ + I lleft; /* positive finite left level */ + I lmon; /* positive finite monadic level */ + A local; /* local symbol table */ + I locsize[2]; /* size indices for named and numbered locales */ + I lright; /* positive finite right level */ + A ltext; /* linear representation text */ + AF ltie; /* linear representation tie function */ + I* mfree[MLEN]; /* head ptr of each free list */ + I mfreeb[MLEN]; /* # bytes tied up in the corresp. mfree list */ + I mfreet[MLEN]; /* thresholds for garbage collect */ + I min; /* the r result from irange */ + I mmax; /* space allocation limit */ + I mtyo; /* jsto output type - jfwrite arg to jpr */ + C* mtyostr; /* jsto string */ + I nfe; /* 1 for J native front end */ + B nflag; /* 1 if space required before name */ + B nla[256]; /* namelist names mask */ + I nlt; /* namelist type mask */ + A nvra; /* see comments in p.c */ + A* nvrav; /* see comments in p.c */ + A nvrb; /* see comments in p.c */ + B* nvrbv; /* see comments in p.c */ + I nvrtop; /* see comments in p.c */ + I oleop; /* com flag to capture output */ + void*opbstr; /* com ptr to BSTR for captured output */ + I outeol; /* output: EOL sequence code */ + I outmaxafter; /* output: maximum # lines after truncation */ + I outmaxbefore; /* output: maximum # lines before truncation */ + I outmaxlen; /* output: maximum line length before truncation */ + C outseq[3]; /* EOL: "LF" "CR" "CRLF" */ + I parsercalls; /* # times parser was called */ + A pma; /* perf. monitor: data area */ + I pmctr; /* perf. monitor: ctr>0 means do monitoring */ + B pmrec; /* perf. monitor: 0 entry/exit; 1 all */ + PM0* pmu; /* perf. monitor: (PM0)AV(pma) */ + PM* pmv; /* perf. monitor: (PM*)(sizeof(PM0)+CAV(pma)) */ + I pos[2]; /* boxed output x-y positioning */ + C pp[8]; /* print precision */ + AF pre; /* preface function for assignment */ + I* rank; /* for integrated rank support */ + I redefined; /* symbol table entry of redefined explicit defn */ + int reginitflag; /* 1 iff regular expression stuff initialized */ + I rela; /* if a is relative, a itself; else 0 */ + I relw; /* if w is relative, w itself; else 0 */ + B retcomm; /* 1 iff retain comments and redundant spaces */ + I rng; /* RNG: generator selector */ + UF rngF[5]; /* RNG: function to get the next random number */ + UI* rngfxsv; /* RNG: rngv for fixed seed (?.) */ + UF rngf; /* RNG: rngF[rng] */ + I rngI[5]; /* RNG: indices */ + I rngI0[5]; /* RNG: indices for RNG0 */ + I rngi; /* RNG: current index */ + UI rngM[5]; /* RNG: moduli */ + I rngS[5]; /* RNG: seeds */ + A rngseed; /* RNG: array seed */ + UI* rngV[5]; /* RNG: state vectors */ + UI* rngV0[5]; /* RNG: state vectors for RNG0 */ + UI* rngv; /* RNG: rngV[rng] */ + I rngw; /* RNG: # bits in a random # */ + I sbfillfactor; /* SB for binary tree */ + I sbgap; /* SB for binary tree */ + A sbh; /* SB hash table of indices; -1 means unused */ + I* sbhv; /* SB points to ravel of sbh */ + I sbroot; /* SB root of the binary tree */ + A sbs; /* SB string */ + I sbsn; /* SB string length so far */ + C* sbsv; /* SB points to ravel of sbs */ + A sbu; /* SB data for each unique symbol */ + I sbun; /* SB cardinality */ + SBU* sbuv; /* SB points to ravel of sbu */ + A sca; /* S: result vector */ + I scn; /* S: actual length of sca */ + I* scv; /* S: AV(sca) */ + int sdinited; /* sockets */ + I seclev; /* security level */ + B sesm; /* whether there is a session manager */ + A sf; /* for $: */ + DC sitop; /* top of SI stack */ + A slist; /* files used in right arg to 0!: */ + I slisti; /* index into slist of current script */ + I slistn; /* slist # of real entries */ + I sm; /* sm options set by JSM() */ + void*smdowd; + void*sminput; + void*smoutput; /* sm.. sm/wd callbacks set by JSM() */ + void*smpoll; + D spfor; /* semi-global for use by spfor() */ + B stch; /* enable setting of changed bit */ + A stloc; /* locales symbol table */ + I stmax; /* numbered locales maximum number */ + A stnum; /* numbered locale numbers */ + A stptr; /* numbered locale symbol table ptrs */ + B stswitched; /* called fn switched locale */ + I stused; /* entries in stnum/stptr in use */ + A symb; /* symbol table for assignment */ + I symindex; /* symbol table index (monotonically increasing) */ + A symp; /* symbol pool array */ + L* sympv; /* symbol pool array value ptr, (L*)AV(jt->symp) */ + I tbase; /* index of current frame */ + C* th2buf; /* space for formatting one number */ + I th2bufn; /* current max length of buf */ + UI timelimit; /* execution time limit milliseconds */ + B tmonad; /* tacit translator: 1 iff monad */ + B tostdout; /* 1 if output to stdout */ + I transposeflag; /* com flag for transposed arrays */ + D tssbase; /* initial time of date */ + A* tstack; /* data portion of current frame */ + A tstacka; /* current frame */ + TA* ttab; /* tacit translator */ + I ttabi; /* tacit translator */ + I ttabi0; /* tacit translator */ + B tsubst; /* tacit translator */ + I ttop; /* stack top (index into tstack[]) */ + B xco; /* 1 iff doing x: conversion */ + B xdefn; /* 1 iff within explicit definition */ + A xmod; /* extended integer: the m in m&|@f */ + I xmode; /* extended integer operating mode */ +} JST; + +typedef JST* J;
new file mode 100644 --- /dev/null +++ b/jtype.h @@ -0,0 +1,346 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Type Definitions */ + +#define U unsigned + +#if (SYS & SYS_UNIX) +#define _stdcall +#endif + +#if SY_64 +typedef long long A1; +typedef unsigned long long BT; +typedef long long I; +typedef long long SB; +typedef unsigned long long UI; + +#else +typedef long A1; +typedef unsigned long BT; +typedef long I; +typedef long SB; +typedef unsigned long UI; +#endif + +typedef char B; +typedef char C; +typedef char* Ptr; +typedef short S; +typedef short C2; +typedef unsigned char UC; +typedef unsigned short US; +typedef unsigned short U2; +typedef unsigned int UINT; +typedef int I4; +typedef double D; +typedef FILE* F; + +typedef long double LD; +typedef struct {I k,flag,m,t,c,n,r,s[1];}* A; +typedef struct {A a,t;}TA; +typedef A (*AF)(); +typedef UI (*UF)(); +typedef void (*VF)(); +typedef int (*CMP)(); /* comparison function in sort */ +typedef A X; +typedef struct {X n,d;} Q; +typedef struct {D re,im;} Z; +typedef union {D d;UINT i[2];} DI; + +#if (SYS & SYS_PC+SYS_MACINTOSH) /* for use by the session manager */ +typedef S SI; +#else +typedef I SI; +#endif + +/* Fields of type A */ + +#define AK(x) ((x)->k) /* offset of ravel wrt x */ +#define AFLAG(x) ((x)->flag) /* flag */ +#define AM(x) ((x)->m) /* Max # bytes in ravel */ +#define AT(x) ((x)->t) /* Type; one of the #define below */ +#define AC(x) ((x)->c) /* Reference count. */ +#define AN(x) ((x)->n) /* # elements in ravel */ +#define AR(x) ((x)->r) /* Rank */ +#define AH 7L /* # non-shape header words in A */ +#define AS(x) ((x)->s) /* Pointer to shape */ + +#if SY_64 +#define AKX(x) (SZI*(AH+AR(x))) +#define WP(t,n,r) (AH+ r +(1&&t&LAST0)+((t&NAME?sizeof(NM):0)+(n)*bp(t)+SZI-1)/SZI) +#else +#define AKX(x) (SZI*(AH+AR(x)+!(1&AR(x)))) +#define WP(t,n,r) (AH+(r+!(1&r))+(1&&t&LAST0)+((t&NAME?sizeof(NM):0)+(n)*bp(t)+SZI-1)/SZI) +#endif +/* make sure array values are double-word aligned */ + +#define AV(x) ( (I*)((C*)(x)+AK(x))) /* pointer to ravel */ +#define BAV(x) ( (C*)(x)+AK(x) ) /* boolean */ +#define CAV(x) ( (C*)(x)+AK(x) ) /* character */ +#define USAV(x) ((US*)((C*)(x)+AK(x))) /* wchar */ +#define UAV(x) ( (UC*)(x)+AK(x) ) /* unsigned character */ +#define NAV(x) ((NM*)((C*)(x)+AK(x))) /* name */ +#define IAV(x) AV(x) /* integer */ +#define DAV(x) ( (D*)((C*)(x)+AK(x))) /* double */ +#define ZAV(x) ( (Z*)((C*)(x)+AK(x))) /* complex */ +#define XAV(x) ( (X*)((C*)(x)+AK(x))) /* extended */ +#define QAV(x) ( (Q*)((C*)(x)+AK(x))) /* rational */ +#define AAV(x) ( (A*)((C*)(x)+AK(x))) /* boxed */ +#define A1AV(x) ((A1*)((C*)(x)+AK(x))) /* boxed relative address */ +#define VAV(x) ( (V*)((C*)(x)+AK(x))) /* verb, adverb, conj */ +#define PAV(x) ( (P*)((C*)(x)+AK(x))) /* sparse */ +#define SBAV(x) ((SB*)((C*)(x)+AK(x))) /* symbol */ + +/* Types for AT(x) field of type A */ +/* Note: BOOL name conflict with ???; SCHAR name conflict with sqltypes.h */ + +#define B01 (I)1L /* B boolean */ +#define LIT (I)2L /* C literal (character) */ +#define INT (I)4L /* I integer */ +#define FL (I)8L /* D double (IEEE floating point) */ +#define CMPX (I)16L /* Z complex */ +#define BOX (I)32L /* A boxed */ +#define XNUM (I)64L /* X extended precision integer */ +#define RAT (I)128L /* Q rational number */ +#define BIT (I)256L /* BT bit boolean */ +#define SB01 (I)1024L /* P sparse boolean */ +#define SLIT (I)2048L /* P sparse literal (character) */ +#define SINT (I)4096L /* P sparse integer */ +#define SFL (I)8192L /* P sparse floating point */ +#define SCMPX (I)16384L /* P sparse complex */ +#define SBOX (I)32768L /* P sparse boxed */ +#define SBT (I)65536L /* SB symbol */ +#define C2T (I)131072L /* C2 unicode (2-byte characters) */ +#define VERB (I)262144L /* V verb */ +#define ADV (I)524288L /* V adverb */ +#define CONJ (I)1048576L /* V conjunction */ +#define ASGN (I)2097152L /* I assignment */ +#define MARK (I)4194304L /* I end-of-stack marker */ +#define SYMB (I)8388608L /* I locale (symbol table) */ +#define CONW (I)16777216L /* CW control word */ +#define NAME (I)33554432L /* NM name */ +#define LPAR (I)67108864L /* I left parenthesis */ +#define RPAR (I)134217728L /* I right parenthesis */ +#define XD (I)268435456L /* DX extended floating point */ +#define XZ (I)536870912L /* ZX extended complex */ + +#define ANY -1L +#define SPARSE (SB01+SINT+SFL+SCMPX+SLIT+SBOX) +#define DENSE (NOUN&~SPARSE) +#define NUMERIC (B01+BIT+INT+FL+CMPX+XNUM+RAT+XD+XZ+SB01+SINT+SFL+SCMPX) +#define DIRECT (LIT+C2T+B01+BIT+INT+FL+CMPX+SBT) +#define JCHAR (LIT+C2T+SLIT) +#define NOUN (NUMERIC+JCHAR+BOX+SBOX+SBT) +#define FUNC (VERB+ADV+CONJ) +#define RHS (NOUN+FUNC) +#define IS1BYTE (B01+LIT) +#define LAST0 (B01+LIT+C2T+NAME) + +#define HOMO(s,t) ((s)==(t) || (s)&NUMERIC&&(t)&NUMERIC || (s)&JCHAR&&(t)&JCHAR) +#define STYPE(t) ((t)& B01?SB01:(t)& INT?SINT:(t)& FL?SFL:(t)& CMPX?SCMPX:(t)&LIT?SLIT:(t)& BOX?SBOX:0L) +#define DTYPE(t) ((t)&SB01? B01:(t)&SINT? INT:(t)&SFL? FL:(t)&SCMPX? CMPX:(t)&SLIT?LIT:(t)&SBOX? BOX:0L) + +/* Values for AFLAG(x) field of type A */ + +#define AFRO (I)1 /* read only; can't change data */ +#define AFNJA (I)2 /* non-J alloc; i.e. mem mapped */ +#define AFSMM (I)4 /* SMM managed */ +#define AFREL (I)8 /* uses relative addressing */ + +#define AABS(rel,k) ((I)(rel)+(I)(k)) /* absolute address from relative address */ +#define AREL(abs,k) ((I)(abs)-(I)(k)) /* relative address from absolute address */ +#define ARELATIVE(w) (AT(w)&BOX&&AFLAG(w)&AFNJA+AFSMM+AFREL) +#define AADR(w,z) ((w)?(A)((I)(w)+(I)(z)):(z)) +#define AVR(i) AADR(ad,av[i]) +#define IVR(i) AADR(id,iv[i]) +#define WVR(i) AADR(wd,wv[i]) +#define YVR(i) AADR(yd,yv[i]) +#define AAV0(w) (ARELATIVE(w)?(A)(*AV(w)+(I)(w)):*AAV(w)) +#define RELOCATE(w,z) (ARELATIVE(w)?relocate((I)(w)-(I)(z),(z)):(z)) + + +typedef struct {I i;US n,go,source;C type;} CW; + +/* control word (always has corresponding token string) */ +/* type - as specified in w.h */ +/* go - line number to go to */ +/* source - source line number */ +/* i - beginning index of token string */ +/* n - length of token string */ + + +#define DCPARSE 1 /* sentence for parser */ +#define DCSCRIPT 2 /* script -- line() */ +#define DCCALL 3 /* verb/adv/conj call -- dbunquote() */ +#define DCJUNK 4 /* stack entry is obsolete */ + +typedef struct DS{ /* 1 2 3 */ + struct DS*dclnk; /* x x x link to next stack entry */ + A dca; /* x fn/op name */ + A dcf; /* x fn/op */ + A dcx; /* x left argument */ + A dcy; /* x x x tokens; text ; right argument */ + A dcloc; /* x local symb table (0 if not explicit) */ + A dcc; /* x control matrix (0 if not explicit) */ + I dci; /* x x x index ; next index ; ptr to line # */ + I dcj; /* x x ; prev index ; error # */ + I dcn; /* x x ; line # ; ptr to symb entry */ + I dcm; /* x x ; script index; # of non-locale part of name */ + I dcstop; /* x the last stop in this function */ + C dctype; /* x x x type of entry (see #define DC*) */ + B dcsusp; /* x x 1 iff begins a debug suspension */ + C dcss; /* x single step code */ +} DST; + +typedef DST* DC; + + +typedef struct {I e,p;X x;} DX; + /* for the p field in DX */ +#define DXIPREC ((I)-1) /* infinite precision */ +#define DXINF ((I)-2) /* _ infinity */ +#define DXMINF ((I)-3) /* __ negative infinity */ + +/* extended floating point */ +/* e - exponent */ +/* p - precision & other codes */ +/* +ve # of significant digits */ +/* _1 infinite precision (with trailing 0s) */ +/* _2 infinity _ */ +/* _3 negative infinity __ */ +/* x - mantissa */ +/* least significant digit first */ +/* decimal point after last digit */ + + +typedef struct {A name,val;I flag,sn,next,prev;} L; + +/* symbol pool entry LINFO entry */ +/* name - name on LHS of assignment or locale name */ +/* val - value or locale search path */ +/* flag - various flags */ +/* sn - script index */ +/* next - index of successor in hash list or 0 */ +/* prev - index of predecessor in hash list or address of hash entry */ + +#define LCH (I)1 /* changed since last exec of 4!:5 */ +#define LHEAD (I)2 /* head pointer (no predecessor) */ +#define LINFO (I)4 /* locale info */ + + +typedef struct{A og,g;I ptr,flag;B sw0;} LS; + +/* og: old value of global */ +/* g: global at this level */ +/* ptr: index in pv/nv if numbered locale */ +/* pointer to stloc entry if named locale */ +/* flag: 1 if named locale marked for destruction */ +/* 2 if numbered locale marked for destruction */ +/* sw0: old value of stswitched */ + + +typedef struct{UI hash;I sn;L*e;UC m;C flag,s[1];} NM; + +/* hash: hash for non-locale part of name */ +/* m: length of non-locale part of name */ +/* sn: symbol table number on last reference */ +/* e: symbol pool entry on last reference */ +/* s: points to string part of full name (1 to ?? characters) */ + +#define NMLOC 1 /* direct locale abc_lm_ */ +#define NMILOC 2 /* indirect locale abc__de__fgh ... */ +#define NMDOT 4 /* one of the names m. n. u. v. x. y. */ + + +typedef struct {I a,e,i,x;} P; + +/* value fields of sparse array types */ +/* fields are offsets from beginning of the P struct */ +/* a: sparse axes */ +/* e: sparse element */ +/* i: index matrix, columns correspond to a */ +/* x: value cells corresponding to rows of i */ + +#define SPA(p,a) ((A)((p)->a+(C*)(p))) +#define SPB(p,a,x) {(p)->a=(C*)(x)-(C*)(p); RZ(p->a+(C*)(p));} + + +/* performance monitoring stuff */ + +typedef struct{ + A name; /* verb/adverb/conjunction name */ + A loc; /* locale name */ + I lc; /* line number (-1 for entry; -2 for exit) */ + I s; /* space */ + I t[2]; /* time */ + C val; /* valence: 1 or 2 */ + C unused[3]; /* padding */ +} PM; + +#define PMCOL 6 /* # of fields in PM */ + +typedef struct{ + I n; /* maximum number of records */ + I i; /* index of next record to be written */ + I s; /* initial bytesmax value */ + B rec; /* what to record (0 entry & exit; 1 all) */ + B trunc; /* what to do on overflow (0 wrap; 1 truncate) */ + B wrapped; /* 1 iff wrapping has happened */ + C unused[1]; /* padding */ +} PM0; + + +/* each unique symbol has a row in jt->sbu */ +/* a row is interpreted per SBU */ +/* for best results make sizeof(SBU) a multiple of sizeof(I) */ + +typedef struct{ + I i; /* index into sbs */ + I n; /* length */ + UI h; /* hash value */ + I color; /* binary tree: color */ + I parent; /* binary tree: index of parent */ + I left; /* binary tree: index of left child */ + I right; /* binary tree: index of right child */ + I order; /* order number */ + I down; /* predecessor in ordering */ + I up; /* successor in ordering */ + I flag; /* bit flags */ +} SBU; + +#define SBC2 1 /* 1 iff 2-byte character */ + + +typedef struct {AF f1,f2;A f,g,h;I flag,mr,lr,rr,fdep;C id;} V; + +#define ID(f) (f&&FUNC&AT(f)?VAV(f)->id:C0) + + /* type V flag values */ + /* < 256 see vcompsc.c */ +#define VGERL (I)256 /* gerund left argument */ +#define VGERR (I)512 /* gerund right argument */ +#define VTAYFINITE (I)1024 /* t. finite polynomial */ +#define VIRS1 (I)2048 /* monad has integral rank support */ +#define VIRS2 (I)4096 /* dyad has integral rank support */ +#define VFLR (I)8192 /* function is <.@g */ +#define VCEIL (I)16384 /* function is >.@g */ +#define VMOD (I)32768 /* function is m&|@g */ +#define VLOCK (I)65536 /* function is locked */ +#define VNAMED (I)131072 /* named explicit defn */ +#define VFIX (I)262144 /* f. applied */ +#define VXOPR (I)524288 /* : defn with u. and x. */ +#define VXOP (I)1048576 /* : defn derived fn */ +#define VXOPCALL (I)2097152 /* : defn derived fn call */ +#define VTRY1 (I)4194304 /* monad contains try. */ +#define VTRY2 (I)8388608 /* dyad contains try. */ +#define VDDOP (I)16777216 /* derived from a derived operator */ + + +typedef struct {DX re;DX im;} ZX; + +/* extended complex */ +/* re - real part */ +/* im - imaginary part */ +
new file mode 100644 --- /dev/null +++ b/k.c @@ -0,0 +1,381 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Conversions Amongst Internal Types */ + +#include "j.h" + +#define KF1(f) B f(J jt,A w,void*yv) +#define CVCASE(a,b) ((a)+1024*(b)) + + +#define TOBIT(T,AS) {T*v=(T*)wv,x; \ + for(i=0;i<m;++i){ \ + DO(q, k=0; DO(BB, if(x=*v++){if(AS)k|=bit[i]; else R 0;}); *zv++=k;); \ + if(r){k=0; DO(r, if(x=*v++){if(AS)k|=bit[i]; else R 0;}); *zv++=k;} \ + DO(r1, *zv++=0;); \ + }} + +static KF1(jtcvt2bit){I c,i,m,q,r,r1,wr,*ws,*wv;UC k,*zv=(UC*)yv; + wv=AV(w); wr=AR(w); ws=AS(w); + c=wr?ws[wr-1]:1; m=c?AN(w)/c:0; q=c/BB; r=c%BB; r1=c%BW?(BW-c%BW)/BB:0; + switch(AT(w)){ + default: R 0; + case B01: TOBIT(B, 1 ); break; + case INT: TOBIT(I, 1==x ); break; + case FL: TOBIT(D, FEQ(1.0,x)); break; + } + R 1; +} + +static KF1(jtC1fromC2){UC*x;US c,*v; + v=(US*)AV(w); x=(C*)yv; + DO(AN(w), c=*v++; RZ(256>c); *x++=(UC)c;); + R 1; +} + +static KF1(jtC2fromC1){UC*v;US*x; + v=UAV(w); x=(US*)yv; + DO(AN(w), *x++=*v++;); + R 1; +} + +static KF1(jtBfromI){B*x;I n,p,*v; + n=AN(w); v=AV(w); x=(B*)yv; + DO(n, p=*v++; if(0==p||1==p)*x++=(B)p; else R 0;); + R 1; +} + +static KF1(jtBfromD){B*x;D p,*v;I n; + n=AN(w); v=DAV(w); x=(B*)yv; + DO(n, p=*v++; if(p<-2||2<p)R 0; + if(!p)*x++=0; else if(FEQ(1.0,p))*x++=1; else R 0;); + R 1; +} + +static KF1(jtIfromD){D p,q,r,*v;I i,k=0,n,*x; + n=AN(w); v=DAV(w); x=(I*)yv; + q=IMIN*(1+jt->fuzz); r=IMAX*(1+jt->fuzz); + DO(n, p=v[i]; if(p<q||r<p)R 0;); + for(i=0;i<n;++i){ + p=v[i]; q=jfloor(p); +#if SY_64 + if (FEQ(p,q)){k=(I)q; *x++=SGN(k)==SGN(q)?k:0>q?IMIN:IMAX;} + else if(++q,FEQ(p,q)){k=(I)q; *x++=SGN(k)==SGN(q)?k:0>q?IMIN:IMAX;} + else R 0; +#else + if(FEQ(p,q))*x++=(I)q; else if(FEQ(p,1+q))*x++=(I)(1+q); else R 0; +#endif + } + R 1; +} + +static KF1(jtDfromZ){D d,*x;I n;Z*v; + n=AN(w); v=ZAV(w); x=(D*)yv; + if(jt->fuzz)DO(n, d=ABS(v->im); if(d!=inf&&d<=jt->fuzz*ABS(v->re)){*x++=v->re; v++;} else R 0;) + else DO(n, d= v->im ; if(!d ){*x++=v->re; v++;} else R 0;); + R 1; +} + +static KF1(jtXfromB){B*v;I n,u[1];X*x; + n=AN(w); v=BAV(w); x=(X*)yv; + DO(n, *u=v[i]; x[i]=vec(INT,1L,u);); + R !jt->jerr; +} + +static KF1(jtXfromI){B b;I c,d,i,j,n,r,u[XIDIG],*v;X*x; + n=AN(w); v=AV(w); x=(X*)yv; + for(i=0;i<n;++i){ + c=v[i]; b=c==IMIN; d=b?-(1+c):ABS(c); j=0; + DO(XIDIG, u[i]=r=d%XBASE; d=d/XBASE; if(r)j=i;); + ++j; *u+=b; + if(0>c)DO(XIDIG, u[i]=-u[i];); + x[i]=vec(INT,j,u); + } + R !jt->jerr; +} + +static X jtxd1(J jt,D p){PROLOG;A t;D d,e=tfloor(p),q,r;I m,*u; + switch(jt->xmode){ + case XMFLR: p=e; break; + case XMCEIL: p=ceil(p); break; + case XMEXACT: ASSERT(teq(p,e),EVDOMAIN); p=e; break; + case XMEXMT: if(!teq(p,e))R vec(INT,0L,&m); + } + if(p== inf)R vci(XPINF); + if(p==-inf)R vci(XNINF); + GA(t,INT,30,1,0); u=AV(t); m=0; d=ABS(p); + while(0<d){ + q=jfloor(d/XBASE); r=d-q*XBASE; u[m++]=(I)r; d=q; + if(m==AN(t)){RZ(t=ext(0,t)); u=AV(t);} + } + if(!m){u[0]=0; ++m;}else if(0>p)DO(m, u[i]=-u[i];); + EPILOG(xstd(vec(INT,m,u))); +} + +static KF1(jtXfromD){D*v=DAV(w);X*x=(X*)yv; DO(AN(w), x[i]=xd1(v[i]);); R !jt->jerr;} + +static KF1(jtBfromX){A q;B*x;I e;X*v; + v=XAV(w); x=(B*)yv; + DO(AN(w), q=v[i]; e=*AV(q); RZ(1==AN(q)&&(0==e||1==e)); x[i]=(B)e;); + R 1; +} + +static KF1(jtIfromX){I a,i,m,n,*u,*x;X c,p,q,*v; + v=XAV(w); x=(I*)yv; n=AN(w); + RZ(p=xc(IMAX)); RZ(q=xminus(negate(p),xc(1L))); + for(i=0;i<n;++i){ + c=v[i]; RZ(1!=xcompare(q,c)&&1!=xcompare(c,p)); + m=AN(c); u=AV(c)+m-1; a=0; DO(m, a=*u--+a*XBASE;); x[i]=a; + } + R 1; +} + +static KF1(jtDfromX){D d,*x=(D*)yv,dm,dp;I c,i,n,*v,wn;X p,*wv; + dp=1.7976931348623157e308; dm=-dp; + wn=AN(w); wv=XAV(w); + for(i=0;i<wn;++i){ + p=wv[i]; n=AN(p); v=AV(p)+n-1; c=*v; + if (c==XPINF)d=inf; + else if(c==XNINF)d=infm; + else{ + d=0.0; DO(n, d=*v--+d*XBASE;); + ASSERT(jt->xco||dm<=d&&d<=dp,EVDOMAIN); + } + x[i]=d; + } + R 1; +} + +static KF1(jtQfromX){X*v=XAV(w),*x=(X*)yv; DO(AN(w), *x++=*v++; *x++=iv1;); R 1;} + +static KF1(jtQfromD){B neg,recip;D c,d,t,*wv;I e,i,n,*v;Q q,*x;S*tv; + RZ(w); + n=AN(w); wv=DAV(w); x=(Q*)yv; tv=3*liln+(S*)&t; + for(i=0;i<n;++i){ + t=wv[i]; + ASSERT(!_isnan(t),EVNAN); + if(neg=0>t)t=-t; q.d=iv1; + if (t==inf)q.n=vci(XPINF); + else if(t==0.0)q.n=xzero; + else if(1.1102230246251565e-16<t&&t<9.007199254740992e15){ + d=jfloor(0.5+1/dgcd(1.0,t)); c=jfloor(0.5+d*t); + q.n=xd1(c); q.d=xd1(d); q=qstd(q); + }else{ + if(recip=1>t)t=1.0/t; + e=(I)(0xfff0&*tv); e>>=4; e-=1023; + if(recip){q.d=xtymes(xd1(t/pow(2.0,e-53.0)),xpow(xc(2L),xc(e-53))); q.n=ca(iv1);} + else {q.n=xtymes(xd1(t/pow(2.0,e-53.0)),xpow(xc(2L),xc(e-53))); q.d=ca(iv1);} + } + if(neg){v=AV(q.n); DO(AN(q.n), *v=-*v; ++v;);} + *x++=q; + } + R !jt->jerr; +} + +static KF1(jtDfromQ){D d,f,n,*x,xb=(D)XBASE;I cn,i,k,m,nn,pn,qn,r,*v,wn;Q*wv;X c,p,q,x2=0; + wn=AN(w); wv=QAV(w); x=(D*)yv; nn=308/XBASEN; + for(i=0;i<wn;++i){ + p=wv[i].n; pn=AN(p); k=1==pn?*AV(p):0; + q=wv[i].d; qn=AN(q); + if (k==XPINF)x[i]=inf; + else if(k==XNINF)x[i]=infm; + else if(pn<=nn&&qn<=nn){ + n=0.0; f=1.0; v=AV(p); DO(pn, n+=f*v[i]; f*=xb;); + d=0.0; f=1.0; v=AV(q); DO(qn, d+=f*v[i]; f*=xb;); + x[i]=n/d; + }else{ + k=5+qn; if(!x2)RZ(x2=xc(2L)); + RZ(c=xdiv(take(sc(-(k+pn)),p),q,XMFLR)); + cn=AN(c); m=MIN(cn,5); r=cn-(m+k); v=AV(c)+cn-m; + n=0.0; f=1.0; DO(m, n+=f*v[i]; f*=xb;); + d=1.0; DO(ABS(r), d*=xb;); + x[i]=0>r?n/d:n*d; + }} + R 1; +} + +static KF1(jtXfromQ){Q*v;X*x; + v=QAV(w); x=(X*)yv; + DO(AN(w), RZ(equ(iv1,v->d)); *x++=v->n; ++v;); + R !jt->jerr; +} + +static B jtDXfI(J jt,I p,A w,DX*x){B b;I e,c,d,i,j,n,r,u[XIDIG],*v; + n=AN(w); v=AV(w); + for(i=0;i<n;++i){ + c=v[i]; b=c==IMIN; d=b?-(1+c):ABS(c); j=0; + DO(XIDIG, u[i]=r=d%XBASE; d/=XBASE; if(r)j=i;); + ++j; *u+=b; + e=XBASEN*(j-1); d=u[j-1]; while(d){++e; d/=10;} + if(0>c)DO(j, u[i]=-u[i];); + x[i].e=e; x[i].p=p; x[i].x=vec(INT,j,u);; + } + R !jt->jerr; +} + +/* +static B jtDXfI(J jt,I p,A w,DX*x){A y;I b,c,d,dd,e,i,m,n,q,r,*wv,*yv; + n=AN(w); wv=AV(w); m=(p+XBASEN-1)/XBASEN; + for(i=0;i<n;++i){ + c=wv[i]; d=dd=c==IMIN?-(1+c):ABS(c); + if(d){e=0; while(d){++e; r=d%10; d=d/10;}}else e=1; + GA(y,INT,m,1,0); yv=AV(y); + r=p%XBASEN; q=!!r+((e-r)+XBASEN-1)/XBASEN; + if(d=(e-r)%XBASEN){b=1; DO(XBASEN, b*=10; --d; if(!d)break;);}else b=XBASE; + DO(m-q, *yv++=0;); + d=dd/b; r=dd%b; r+=c==IMIN; r*=XBASE/b; + if(0>c){*yv++=-r; DO(q-1, r=d%XBASE; d=d/XBASE; *yv++=-r;);} + else {*yv++= r; DO(q-1, r=d%XBASE; d=d/XBASE; *yv++= r;);} + x[i].e=e-1; x[i].p=p; x[i].x=y; + } + R !jt->jerr; +} /* most significant digit last, decimal point before last digit */ + + +static B jtccvt(J jt,I t,A w,A*y){A d;I n,r,*s,wt,*wv,*yv; + RZ(w); + r=AR(w); s=AS(w); + switch((t&SPARSE?2:0)+(AT(w)&SPARSE?1:0)){I t1;P*wp,*yp; + case 1: RZ(w=denseit(w)); break; + case 2: RZ(*y=sparseit(cvt(DTYPE(t),w),IX(r),cvt(t,zero))); R 1; + case 3: + t1=DTYPE(t); + GA(*y,t,1,r,s); yp=PAV(*y); wp=PAV(w); + SPB(yp,a,ca(SPA(wp,a))); + SPB(yp,i,ca(SPA(wp,i))); + SPB(yp,e,cvt(t1,SPA(wp,e))); + SPB(yp,x,cvt(t1,SPA(wp,x))); + R 1; + } + n=AN(w); wt=AT(w); wv=AV(w); + if(t==wt){RZ(*y=ca(w)); R 1;} + // else if(n&&t&JCHAR){ASSERT(HOMO(t,wt),EVDOMAIN); RZ(*y=uco1(w)); R 1;} + GA(*y,t,n,r,s); yv=AV(*y); + if(t&CMPX)fillv(t,n,(C*)yv); + if(!n)R 1; + switch(CVCASE(t,wt)){ + case CVCASE(LIT, C2T ): R C1fromC2(w,yv); + case CVCASE(C2T, LIT ): R C2fromC1(w,yv); + case CVCASE(BIT ,B01 ): R cvt2bit(w,yv); + case CVCASE(INT ,B01 ): {I*x= yv;B*v=(B*)wv; DO(n,*x++ =*v++;);} R 1; + case CVCASE(XNUM,B01 ): R XfromB(w,yv); + case CVCASE(RAT ,B01 ): GA(d,XNUM,n,r,s); R XfromB(w,AV(d))&&QfromX(d,yv); + case CVCASE(FL ,B01 ): {D*x=(D*)yv;B*v=(B*)wv; DO(n,*x++ =*v++;);} R 1; + case CVCASE(CMPX,B01 ): {Z*x=(Z*)yv;B*v=(B*)wv; DO(n,x++->re=*v++;);} R 1; + case CVCASE(BIT ,INT ): R cvt2bit(w,yv); + case CVCASE(B01 ,INT ): R BfromI(w,yv); + case CVCASE(XNUM,INT ): R XfromI(w,yv); + case CVCASE(RAT ,INT ): GA(d,XNUM,n,r,s); R XfromI(w,AV(d))&&QfromX(d,yv); + case CVCASE(FL ,INT ): {D*x=(D*)yv;I*v= wv; DO(n,*x++ =(D)*v++;);} R 1; + case CVCASE(CMPX,INT ): {Z*x=(Z*)yv;I*v= wv; DO(n,x++->re=(D)*v++;);} R 1; + case CVCASE(BIT ,FL ): R cvt2bit(w,yv); + case CVCASE(B01 ,FL ): R BfromD(w,yv); + case CVCASE(INT ,FL ): R IfromD(w,yv); + case CVCASE(XNUM,FL ): R XfromD(w,yv); + case CVCASE(RAT ,FL ): R QfromD(w,yv); + case CVCASE(CMPX,FL ): {Z*x=(Z*)yv;D t,*v=(D*)wv; DO(n, t=*v++; x++->re=t||_isnan(t)?t:0.0;);} R 1; /* -0 to 0*/ + case CVCASE(BIT ,CMPX): GA(d,FL,n,r,s); RZ(DfromZ(w,AV(d))); R cvt2bit(d,yv); + case CVCASE(B01 ,CMPX): GA(d,FL,n,r,s); RZ(DfromZ(w,AV(d))); R BfromD(d,yv); + case CVCASE(INT ,CMPX): GA(d,FL,n,r,s); RZ(DfromZ(w,AV(d))); R IfromD(d,yv); + case CVCASE(XNUM,CMPX): GA(d,FL,n,r,s); RZ(DfromZ(w,AV(d))); R XfromD(d,yv); + case CVCASE(RAT ,CMPX): GA(d,FL,n,r,s); RZ(DfromZ(w,AV(d))); R QfromD(d,yv); + case CVCASE(FL ,CMPX): R DfromZ(w,yv); + case CVCASE(B01 ,XNUM): R BfromX(w,yv); + case CVCASE(INT ,XNUM): R IfromX(w,yv); + case CVCASE(RAT ,XNUM): R QfromX(w,yv); + case CVCASE(FL ,XNUM): R DfromX(w,yv); + case CVCASE(CMPX,XNUM): GA(d,FL, n,r,s); RZ(DfromX(w,AV(d))); R ccvt(t,d,y); + case CVCASE(B01 ,RAT ): GA(d,XNUM,n,r,s); RZ(XfromQ(w,AV(d))); R BfromX(d,yv); + case CVCASE(INT ,RAT ): GA(d,XNUM,n,r,s); RZ(XfromQ(w,AV(d))); R IfromX(d,yv); + case CVCASE(XNUM,RAT ): R XfromQ(w,yv); + case CVCASE(FL ,RAT ): R DfromQ(w,yv); + case CVCASE(CMPX,RAT ): GA(d,FL, n,r,s); RZ(DfromQ(w,AV(d))); R ccvt(t,d,y); + default: ASSERT(0,EVDOMAIN); +}} + +A jtcvt(J jt,I t,A w){A y;B b;I*oq; + oq=jt->rank; jt->rank=0; b=ccvt(t,w,&y); jt->rank=oq; + ASSERT(b,EVDOMAIN); + R y; +} + + +A jtbcvt(J jt,C mode,A w){A y,z=w;D ofuzz;I*oq; + RZ(w); + ofuzz=jt->fuzz; oq=jt->rank; + jt->fuzz=0; jt->rank=0; + if(RAT&AT(w))z=ccvt(XNUM,w,&y)?y:w; + if(mode||!(AT(w)&XNUM+RAT))z=ccvt(B01,w,&y)?y:ccvt(INT,w,&y)?y:ccvt(FL,w,&y)?y:w; + jt->fuzz=ofuzz; jt->rank=oq; + RNE(z); +} /* convert to lowest type. 0=mode: don't convert XNUM/RAT to other types */ + +F1(jticvt){A z;D*v,x;I i,k=0,n,*u; + RZ(w); + n=AN(w); v=DAV(w); + GA(z,INT,n,AR(w),AS(w)); u=AV(z); + for(i=0;i<n;++i){ + x=*v++; if(x<IMIN||IMAX<x)R w; +#if SY_64 + k=(I)x; *u++=SGN(k)==SGN(x)?k:0>x?IMIN:IMAX; +#else + *u++=(I)x; +#endif + } + R z; +} + +A jtpcvt(J jt,I t,A w){A y;B b;I*oq=jt->rank; + jt->rank=0; b=ccvt(t,w,&y); jt->rank=oq; + R b?y:w; +} /* convert w to type t, if possible, otherwise just return w */ + + +F1(jtcvt0){I n,t,*u,*v,z0,z1; + RZ(w); + t=AT(w); n=AN(w); + if(n&&t&FL+CMPX){ + if(t&CMPX)n+=n; u=AV(w); v=(I*)minus0; z0=z1=*v; +#if SY_64 + DO(n, if(z0==*u )*u=0; ++u; ); +#else + z1=*(1+v); DO(n, if(z0==u[0]&&z1==u[1])u[0]=u[1]=0; u+=2;); +#endif + } + R w; +} /* convert -0 to 0 in place */ + + +A jtxcvt(J jt,I m,A w){A z;I old=jt->xmode; jt->xmode=m; z=cvt(XNUM,w); jt->xmode=old; R z;} + +F1(jtxco1){RZ(w); ASSERT(AT(w)&DENSE,EVNONCE); R cvt(AT(w)&B01+INT+XNUM?XNUM:RAT,w);} + +F2(jtxco2){A z;B b;I j,n,r,*s,t,*wv,*zu,*zv; + RZ(a&&w); + n=AN(w); r=AR(w); t=AT(w); + ASSERT(t&DENSE,EVNONCE); + RE(j=i0(a)); + switch(j){ + case -2: R aslash1(CDIV,w); + case -1: b=jt->xco; jt->xco=1; z=bcvt(1,w); jt->xco=b; R z; + case 1: R xco1(w); + case 2: + if(!(t&RAT))RZ(w=cvt(RAT,w)); + GA(z,XNUM,2*n,1+r,AS(w)); *(r+AS(z))=2; + MC(AV(z),AV(w),2*n*SZI); + R z; + case 3: + ASSERT(t&XD+XZ,EVDOMAIN); + b=1&&t&XD; + GA(z,INT,b?n:2*n,b?r:1+r,0); s=AS(z); if(!b)*s++=2; ICPY(s,AS(w),r); + zv=AV(z); zu=n+zv; wv=AV(w); + if(t&XD){DX*v=(DX*)wv; DO(n, *zv++=v->p;);} + else {ZX*v=(ZX*)wv,y; DO(n, y=*v++; *zv++=y.re.p; *zu++=y.im.p;);} + R z; + default: + ASSERT(20<=j,EVDOMAIN); + GA(z,t&CMPX?XZ:XD,n,r,AS(w)); + if(t&INT){RZ(DXfI(j,w,(DX*)AV(z))); R z;} + ASSERT(0,EVNONCE); +}}
new file mode 100644 --- /dev/null +++ b/m.c @@ -0,0 +1,378 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Memory Management */ + +#ifdef _WIN32 +#include <windows.h> +#else +#define __cdecl +#endif + +#include "j.h" + + +#define PSIZE 65536L /* size of each pool */ +#define PLIM 1024L /* pool allocation for blocks <= PLIM */ +#define PLIML 10L /* base 2 log of PLIM */ + +I mhb=sizeof(MS); /* # bytes in memory header */ +I mhw=sizeof(MS)/SZI; /* # words in memory header */ + +static A jttraverse(J,A,AF); + + +B jtmeminit(J jt){I k,m=MLEN; + k=1; DO(m, msize[i]=k; k+=k;); /* OK to do this line in each thread */ + jt->tbase=-NTSTACK; + jt->ttop = NTSTACK; + jt->mmax =msize[m-1]; + DO(m, jt->mfree[i]=0; jt->mfreeb[i]=0; jt->mfreet[i]=1048576;); + R 1; +} + + +F1(jtspcount){A z;I c=0,j,m=1+PLIML,*v;MS*x; + ASSERTMTV(w); + GA(z,INT,2*m,2,0); v=AV(z); + DO(m, j=0; x=(MS*)(jt->mfree[i]); while(x){x=(MS*)(x->a); ++j;} if(j){++c; *v++=msize[i]; *v++=j;}); + v=AS(z); v[0]=c; v[1]=2; AN(z)=2*c; + R z; +} /* 7!:3 count of unused blocks */ + +static int __cdecl spfreecomp(const void *x,const void *y){R *(I*)x<*(I*)y?-1:1;} + +B jtspfree(J jt){A t;I c,d,i,j,m,n,*u,*v;MS*x; + m=0; u=5+jt->mfreet; v=5+jt->mfreeb; + /* DO(1+PLIML, if(jt->mfreet[i]<=jt->mfreeb[i]){j=jt->mfreeb[i]/msize[i]; m=MAX(m,j);}); */ + if(*++u<=*++v){j=*v/ 64; m=MAX(m,j);} + if(*++u<=*++v){j=*v/ 128; m=MAX(m,j);} + if(*++u<=*++v){j=*v/ 256; m=MAX(m,j);} + if(*++u<=*++v){j=*v/ 512; m=MAX(m,j);} + if(*++u<=*++v){j=*v/1024; m=MAX(m,j);} + if(!m)R 1; + GA(t,INT,1+m,1,0); v=AV(t); + /* must not allocate memory after this point */ + for(i=6;i<=PLIML;++i){ + if(jt->mfreet[i]>jt->mfreeb[i])continue; + n=0; x=(MS*)(jt->mfree[i]); + while(x){v[n++]=(I)x; x=(MS*)(x->a);} + qsort(v,n,SZI,spfreecomp); + j=0; u=0; c=msize[i]; d=PSIZE/c; + while(n>j){ + x=(MS*)v[j]; + if(MFHEAD&x->mflag&&n>=j+d&&PSIZE==c+v[j+d-1]-v[j]){ + j+=d; + FREE(x); + jt->mfreeb[i]-=PSIZE; + }else{x->a=u; u=(I*)v[j]; ++j;} + } + jt->mfree[i]=u; jt->mfreet[i]=1048576+jt->mfreeb[i]; + } + R 1; +} /* free unused blocks */ + +static F1(jtspfor1){ + RZ(w); + if(BOX&AT(w)){A*wv=AAV(w);I wd=(I)w*ARELATIVE(w); DO(AN(w), spfor1(WVR(i)););} + else traverse(w,jtspfor1); + if(1e9>AC(w)||AFSMM&AFLAG(w)) + if(AFNJA&AFLAG(w)){I j,m,n,p; + m=SZI*WP(AT(w),AN(w),AR(w)); + n=p=m+mhb; + j=6; n>>=j; + while(n){n>>=1; ++j;} + if(p==msize[j-1])--j; + jt->spfor+=msize[j]; + }else jt->spfor+=msize[((MS*)w-1)->j]; + R mtm; +} + +F1(jtspfor){A*wv,x,y,z;C*s;D*v,*zv;I i,m,n,wd; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); v=&jt->spfor; + ASSERT(!n||BOX&AT(w),EVDOMAIN); + GA(z,FL,n,AR(w),AS(w)); zv=DAV(z); + for(i=0;i<n;++i){ + x=WVR(i); m=AN(x); s=CAV(x); + ASSERT(LIT&AT(x),EVDOMAIN); + ASSERT(1>=AR(x),EVRANK); + ASSERT(vnm(m,s),EVILNAME); + RZ(y=symbrd(nfs(m,s))); + *v=0.0; spfor1(y); zv[i]=*v; + } + R z; +} /* 7!:5 space for named object; w is <'name' */ + +F1(jtspforloc){A*wv,x,y,z;C*s;D*v,*zv;I c,i,j,m,n,wd,*yv;L*u; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); v=&jt->spfor; + ASSERT(!n||BOX&AT(w),EVDOMAIN); + GA(z,FL,n,AR(w),AS(w)); zv=DAV(z); + for(i=0;i<n;++i){ + x=WVR(i); m=AN(x); s=CAV(x); + if(!m){m=4; s="base";} + ASSERT(LIT&AT(x),EVDOMAIN); + ASSERT(1>=AR(x),EVRANK); + ASSERT(vlocnm(m,s),EVILNAME); + y=stfind(0,m,s); + ASSERT(y,EVLOCALE); + *v=(D)msize[((MS*)y-1)->j]; + spfor1(LOCPATH(y)); spfor1(LOCNAME(y)); + m=AN(y); yv=AV(y); + for(j=1;j<m;++j){ + c=yv[j]; + while(c){*v+=sizeof(L); u=c+jt->sympv; spfor1(u->name); spfor1(u->val); c=u->next;} + } + zv[i]=*v; + } + R z; +} /* 7!:6 space for a locale */ + + +F1(jtmmaxq){ASSERTMTV(w); R sc(jt->mmax);} + /* 9!:20 space limit query */ + +F1(jtmmaxs){I j,m=MLEN,n; + RE(n=i0(vib(w))); + ASSERT(1E5<=n,EVLIMIT); + j=m-1; DO(m, if(n<=msize[i]){j=i; break;}); + jt->mmax=msize[j]; + R mtm; +} /* 9!:21 space limit set */ + + +void jtfr(J jt,A w){I j,n;MS*x; + if(!w||--AC(w))R; + x=(MS*)w-1; + j=x->j; n=msize[j]; + jt->bytes-=n; + if(PLIML<j)FREE(x); /* malloc-ed */ + else{ /* pool allocation */ + x->a=jt->mfree[j]; + jt->mfree[j]=(I*)x; + jt->mfreeb[j]+=n; +}} + +void jtfh(J jt,A w){fr(w);} + +static A jtma(J jt,I m){A z;C*u;I j,n,p,*v;MS*x; + n=p=m+mhb; + ASSERT(n<=jt->mmax,EVLIMIT); + j=6; n>>=j; + while(n){n>>=1; ++j;} + if(p==msize[j-1])--j; + n=msize[j]; + if(jt->mfree[j]){ /* allocate from free list */ + z=(A)(mhw+jt->mfree[j]); + jt->mfree[j]=((MS*)(jt->mfree[j]))->a; + jt->mfreeb[j]-=n; + }else if(n>PLIM){ /* large block: straight malloc */ + v=MALLOC(n); + ASSERT(v,EVWSFULL); + z=(A)(v+mhw); + }else{ /* small block: do pool allocation */ + v=MALLOC(PSIZE); + ASSERT(v,EVWSFULL); + u=(C*)v; DO(PSIZE/n, x=(MS*)u; u+=n; x->a=(I*)u; x->j=(C)j; x->mflag=0;); x->a=0; + ((MS*)v)->mflag=MFHEAD; + z=(A)(mhw+v); + jt->mfree[j]=((MS*)v)->a; + jt->mfreeb[j]+=PSIZE-n; + } + JBREAK0; + jt->bytes+=n; jt->bytesmax=MAX(jt->bytes,jt->bytesmax); + x=(MS*)z-1; x->a=0; x->j=(C)j; + R z; +} + + +static A jttraverse(J jt,A w,AF f){ + RZ(w); + switch(AT(w)){ + case XD: + {DX*v=(DX*)AV(w); DO(AN(w), CALL1(f,v->x,0L); ++v;);} break; + case RAT: + {A*v=AAV(w); DO(2*AN(w), CALL1(f,*v++,0L););} break; + case XNUM: case BOX: + if(!(AFLAG(w)&AFNJA+AFSMM)){A*wv=AAV(w);I wd=(I)w*ARELATIVE(w); DO(AN(w), CALL1(f,WVR(i),0L););} break; + case VERB: case ADV: case CONJ: + {V*v=VAV(w); CALL1(f,v->f,0L); CALL1(f,v->g,0L); CALL1(f,v->h,0L);} break; + case SYMB: + {I k,*v=1+AV(w);L*u; + CALL1(f,LOCPATH(w),0L); + CALL1(f,LOCNAME(w),0L); + DO(AN(w)-1, if(k=*v++){u=k+jt->sympv; CALL1(f,u->name,0L); CALL1(f,u->val,0L);}); + } break; + case SB01: case SINT: case SFL: case SCMPX: case SLIT: case SBOX: + {P*v=PAV(w); CALL1(f,SPA(v,a),0L); CALL1(f,SPA(v,e),0L); CALL1(f,SPA(v,i),0L); CALL1(f,SPA(v,x),0L);} break; + } + R mark; +} + + +static A jttg(J jt){A t=jt->tstacka,z; + RZ(z=ma(SZI*WP(BOX,NTSTACK,1L))); + AT(z)=BOX; AC(z)=AR(z)=1; AN(z)=*AS(z)=NTSTACK; AM(z)=NTSTACK*SZA; AK(z)=AKX(z); + jt->tstacka=z; jt->tstack=AAV(jt->tstacka); jt->tbase+=NTSTACK; jt->ttop=1; + *jt->tstack=t; + R z; +} + +static void jttf(J jt){A t=jt->tstacka; + jt->tstacka=*jt->tstack; jt->tstack=AAV(jt->tstacka); jt->tbase-=NTSTACK; jt->ttop=NTSTACK; + fr(t); +} + +F1(jttpush){ + RZ(w); + traverse(w,jttpush); + if(jt->ttop>=NTSTACK)RZ(tg()); + jt->tstack[jt->ttop]=w; + ++jt->ttop; + R w; +} + +I jttpop(J jt,I old){ + while(old<jt->tbase+jt->ttop)if(1<jt->ttop)fr(jt->tstack[--jt->ttop]); else tf(); + R old; +} + +A jtgc (J jt,A w,I old){ra(w); tpop(old); R tpush(w);} + +void jtgc3(J jt,A x,A y,A z,I old){ + if(x)ra(x); if(y)ra(y); if(z)ra(z); + tpop(old); + if(x)tpush(x); if(y)tpush(y); if(z)tpush(z); +} + + +F1(jtfa ){RZ(w); traverse(w,jtfa ); fr(w); R mark;} +F1(jtra ){RZ(w); traverse(w,jtra ); ++AC(w); R w; } + +static F1(jtra1){RZ(w); traverse(w,jtra1); AC(w)+=jt->arg; R w;} +A jtraa(J jt,I k,A w){A z;I m=jt->arg; jt->arg=k; z=ra1(w); jt->arg=m; R z;} + +F1(jtrat){R ra(tpush(w));} + +A jtga(J jt,I t,I n,I r,I*s){A z;I m,w; + if(t&BIT){const I c=8*SZI; /* bit type: pad last axis to fullword */ + ASSERTSYS(1>=r||s,"ga bit array shape"); + if(1>=r)w=(n+c-1)/c; else RE(w=mult(prod(r-1,s),(s[r-1]+c-1)/c)); + w+=WP(INT,0L,r); m=SZI*w; + ASSERT( n>=0&&m>w&&w>0,EVLIMIT); /* beware integer overflow */ + }else{ + w=WP(t,n,r); m=SZI*w; + ASSERT(m>n&&n>=0&&m>w&&w>0,EVLIMIT); /* beware integer overflow */ + } + RZ(z=ma(m)); + if(!(t&DIRECT))memset(z,C0,m); + if(t&LAST0){I*v=(I*)z+w-2; *v++=0; *v=0;} + AC(z)=1; AN(z)=n; AR(z)=r; AFLAG(z)=0; AK(z)=AKX(z); AM(z)=msize[((MS*)z-1)->j]-(AK(z)+sizeof(MS)); + AT(z)=0; tpush(z); AT(z)=t; + if(1==r&&!(t&SPARSE))*AS(z)=n; else if(r&&s)ICPY(AS(z),s,r); /* 1==n always if t&SPARSE */ + R z; +} + +A jtgah(J jt,I r,A w){A z; + ASSERT(RMAX>=r,EVLIMIT); + RZ(z=ma(SZI*(AH+r))); + AT(z)=0; ++AC(z); tpush(z); + if(w){ + AFLAG(z)=0; AM(z)=AM(w); AT(z)=AT(w); AN(z)=AN(w); AR(z)=r; AK(z)=CAV(w)-(C*)z; + if(1==r)*AS(z)=AN(w); + } + R z; +} /* allocate header */ + +F1(jtca){A z;I t;P*wp,*zp; + RZ(w); + t=AT(w); + GA(z,t,AN(w),AR(w),AS(w)); if(AFLAG(w)&AFNJA+AFSMM+AFREL)AFLAG(z)=AFREL; + if(t&SPARSE){ + wp=PAV(w); zp=PAV(z); + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,e,ca(SPA(wp,e))); + SPB(zp,i,ca(SPA(wp,i))); + SPB(zp,x,ca(SPA(wp,x))); + }else MC(AV(z),AV(w),AN(w)*bp(t)+(t&NAME?sizeof(NM):0)); + R z; +} + +F1(jtcar){A*u,*wv,z;I n,wd;P*p;V*v; + RZ(z=ca(w)); + n=AN(w); + switch(AT(w)){ + case RAT: n+=n; + case XNUM: + case BOX: u=AAV(z); wv=AAV(w); wd=(I)w*ARELATIVE(w); DO(n, RZ(*u++=car(WVR(i)));); break; + case SB01: case SLIT: case SINT: case SFL: case SCMPX: case SBOX: + p=PAV(z); + SPB(p,a,car(SPA(p,a))); + SPB(p,e,car(SPA(p,e))); + SPB(p,i,car(SPA(p,i))); + SPB(p,x,car(SPA(p,x))); + break; + case VERB: case ADV: case CONJ: + v=VAV(z); + if(v->f)RZ(v->f=car(v->f)); + if(v->g)RZ(v->g=car(v->g)); + if(v->h)RZ(v->h=car(v->h)); + } + R z; +} + +B jtspc(J jt){A z; RZ(z=MALLOC(1000)); FREE(z); R 1; } + +A jtext(J jt,B b,A w){A z;I c,k,m,m1,t; + RZ(w); /* assume AR(w)&&AN(w) */ + m=*AS(w); c=AN(w)/m; t=AT(w); k=c*bp(t); + GA(z,t,2*AN(w),AR(w),AS(w)); + MC(AV(z),AV(w),m*k); /* copy old contents */ + if(b){ra(z); fa(w);} /* 1=b iff w is permanent */ + *AS(z)=m1=AM(z)/k; AN(z)=m1*c; /* "optimal" use of space */ + if(!(t&DIRECT))memset(CAV(z)+m*k,C0,k*(m1-m)); + R z; +} + +A jtexta(J jt,I t,I r,I c,I m){A z;I k,m1; + GA(z,t,m*c,r,0); + k=bp(t); *AS(z)=m1=AM(z)/(c*k); AN(z)=m1*c; + if(2==r)*(1+AS(z))=c; + if(!(t&DIRECT))memset(AV(z),C0,k*AN(z)); + R z; +} /* "optimal" allocation for type t rank r, c atoms per item, >=m items */ + + +/* debugging tools */ + +B jtcheckmf(J jt){C c;I i,j;MS*x,*y; + for(j=0;j<=PLIML;++j){ + i=0; y=0; x=(MS*)(jt->mfree[j]); /* head ptr for j-th pool */ + while(x){ + ++i; c=x->mflag; + if(!(j==x->j)){ + ASSERTSYS(0,"checkmf 0"); + } + if(!(!c||c==MFHEAD)){ + ASSERTSYS(0,"checkmf 1"); + } + y=x; x=(MS*)x->a; + }} + R 1; +} /* traverse free list */ + +B jtchecksi(J jt){DC d;I dt; + d=jt->sitop; + while(d&&!(DCCALL==d->dctype&&d->dcj)){ + dt=d->dctype; + if(!(dt==DCPARSE||dt==DCSCRIPT||dt==DCCALL||dt==DCJUNK)){ + ASSERTSYS(0,"checksi 0"); + } + if(!(d!=d->dclnk)){ + ASSERTSYS(0,"checksi 1"); + } + d=d->dclnk; + } + R 1; +} /* traverse stack per jt->sitop */
new file mode 100644 --- /dev/null +++ b/m.h @@ -0,0 +1,31 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Memory Management */ + +/* ANSI C already has malloc by j.h include of stdlib.h */ +#if (SYS & SYS_PCWIN+SYS_PC386+SYS_UNIX) && !(SYS+SYS_ANSI) +#include <malloc.h> +#endif + +#if SY_WIN32 && !SY_WINCE +#define FREE(a) HeapFree(jt->heap,0,a) +#define MALLOC(n) (void*)HeapAlloc(jt->heap,0,n) +#else +#define FREE(a) free(a) +#define MALLOC(n) malloc(n) +#endif + +typedef struct {I*a;S j;C mflag,unused;} MS; + +/* layout of the two words before every A array */ +/* a: ptr to next block (when in free list) */ +/* address of SMM array, or 0 (when allocated) */ +/* j: mfree/msize index */ +/* mflag: bit flags */ + +#define MFHEAD 1 /* head of 64k block (returned by malloc() */ + + +extern I mhb; +extern I mhw;
new file mode 100644 --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +CFLAGS=$(COMP) + +libj : $(LIBJ_OBJS) + cc $(LIBJ_OBJS) $(SOLINK) + +jconsole : jconsole.o jeload.o + cc jconsole.o jeload.o $(JCON_LINK) $(M32) $(LIBREADLINE) -ldl -o jconsole + +tsdll : tsdll.o + cc tsdll.o $(SOLINK) \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/mbx.c @@ -0,0 +1,251 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Memory-Mapped Boxed Arrays */ + +#include "j.h" + + +/* A SMM array w is laid-out as follows: */ +/* */ +/* Initial part of w is like a regular array of type A */ +/* Following this part (after the ravel of w) is the SMM area */ +/* Let u point to the first byte of the SMM area */ +/* */ +/* length usage */ +/* 4*AH J array header; flag has AFNJA bit */ +/* 4*64 shape padded to rank of 64 */ +/* 4*n array elements, offsets from w */ +/* ... */ +/* 4*MLEN mfree pointers */ +/* */ +/* each SMM array entry has the usual MS*x fields, */ +/* j: mfree/msize index */ +/* a: pointer to next block (when in free list) */ +/* w-x (when allocated) */ + +#define SMMCTOTAL 0 +#define SMMCINUSE 1 +#define SMMCFREE 2 + +#define RMBX 64L /* max rank for mbx */ +#define SMMFREE(a) (I**)((I)(a)+8*(AM(a)/8)-SZI*MLEN) /* address of free lists */ + +static F1(jtsmmblkf); + + +static I smmsize(A a){ + R 8*(AM(a)/8)-SZI*(AH+RMBX+MLEN)-SZA*AN(a)-SZI*((AH+RMBX+MLEN+AN(a))%2); +} /* size of allocateable area */ + +static C*smmu(A a){I v; + v=(I)(a)+SZI*(AH+RMBX)+AN(a)*SZA; /* 1st allocateable address */ + R (C*)(((4+v)>>3)<<3); /* ensure double word aligned */ +} /* first allocateable address */ + +static B jtsmminit(J jt,A a){C*u;I j,k,**mfree,n;MS*x; + n=smmsize(a); + ASSERT(0<n,EVALLOC); + k=64; j=6; n=n>>j; + mfree=SMMFREE(a); DO(MLEN, mfree[i]=0;); + u=smmu(a); + while(n){ + if(1&n){x=(MS*)u; x->j=(C)j; x->a=0; mfree[j]=(I*)AREL(x,a); u+=k;} + n>>=1; k+=k; ++j; + } + R 1; +} /* initialize SMM area */ + + +void smmfrr(A w){A a;A1*wv;I j,**mfree;MS*x; + x=(MS*)w-1; + a=(A)AABS(x,x->a); + j=x->j; + if(BOX&AT(w)){wv=A1AV(w); DO(AN(w), smmfrr((A)AABS(w,wv[i])););} + mfree=SMMFREE(a); + x->a=mfree[j]; + mfree[j]=(I*)AREL(x,a); +} /* free */ + + +static B smmsplit(A a,I j){I i,k,**mfree,p;MS*x,*y; + mfree=SMMFREE(a); p=MLEN; + i=j; + while(p>i&&!mfree[i])++i; + RZ(p>i); + k=msize[i-1]; + while(j<i){ + x=(MS*)AABS(a,mfree[i]); + mfree[i]=x->a; + y=(MS*)(k+(C*)x); y->a=0; y->j=(S)(i-1); + x->a=(I*)AREL(y,a); x->j=(S)(i-1); + mfree[i-1]=(I*)AREL(x,a); + --i; k>>=1; + } + R 1; +} /* ensure mfree[j] has a free block by splitting larger blocks */ + +static void smmput1(A a,I**mfree,I n,C*v){I j,k;MS*x; + k=64; j=6; n>>=j; + while(n){ + if(1&n){x=(MS*)v; x->j=(C)j; x->a=mfree[j]; mfree[j]=(I*)AREL(x,a); v+=k;} + n>>=1; k+=k; ++j; +}} /* put block v of size n into free list(s) */ + +static B jtsmmjoin(J jt,A a,I j){A y;I m,**mfree,n,*p,*q; + RZ(y=smmblkf(a)); + n=*AS(y); + RZ(1<n); + RZ(y=grade2(y,y)); + p=q=AV(y); m=0; + DO(n-1, if(p[2]==p[0]+p[1])q[1]+=p[3]; else{q+=2; q[0]=p[2]; q[1]=p[3]; ++m;} p+=2;); + ++m; + mfree=SMMFREE(a); DO(MLEN, mfree[i]=0;); + p=AV(y); + DO(m, smmput1(a,mfree,p[1],(C*)p[0]); p+=2;); + R mfree[j]||smmsplit(a,j); +} /* ensure mfree[j] has a free block by joining smaller blocks */ + +static A jtsmma(J jt,A a,I m){A z;I j,n,**mfree,p;MS*x; + JBREAK0; + n=p=m+mhb; + ASSERT(n<=jt->mmax,EVLIMIT); + j=6; n>>=j; while(n){n>>=1; ++j;} + if(p==msize[j-1])--j; + mfree=SMMFREE(a); + ASSERT(mfree[j]||smmsplit(a,j)||smmjoin(a,j),EVALLOC); + x=(MS*)AABS(a,mfree[j]); + z=(A)(1+x); + mfree[j]=x->a; + x->a=(I*)AREL(a,x); + R z; +} /* allocate */ + + +static A jtsmmga(J jt,A a,I t,I n,I r,I*s){A z;I m,w; + w=WP(t,n,r); m=SZI*w; + ASSERT(RMAX>=r&&m>n&&n>=0&&m>w&&w>0,EVLIMIT); /* beware integer overflow */ + RZ(z=smma(a,m)); + AT(z)=t; ACX(z); AN(z)=n; AR(z)=r; AFLAG(z)=AFSMM; AK(z)=AKX(z); AM(z)=m-AK(z); + if(r&&s)ICPY(AS(z),s,r); else *AS(z)=n; + if(t&LAST0)*((I*)z+w-1)=0; + R z; +} + +static B jtsmmin(J jt,A a,A w){A*wv;I wd;MS*x; + if(AFNJA&AFLAG(w))R a==w; + x=(MS*)w-1; + if((I)a==AABS(x,x->a))R 1; + if(BOX&AT(w)){wv=AAV(w); wd=(I)w*ARELATIVE(w); DO(AN(w), if(smmin(a,WVR(i)))R 1;);} + R 0; +} /* 1 iff any leaf of w is part of SMM array a */ + +F2(jtsmmcar){A*wv,x,z;A1*zv;I n,t,wd; + RZ(w); + n=AN(w); t=AT(w); + ASSERT(t&B01+LIT+INT+FL+CMPX+BOX,EVDOMAIN); + RZ(z=smmga(a,t,n,AR(w),AS(w))); + zv=A1AV(z); wv=AAV(w); + if(t&BOX){wd=(I)w*ARELATIVE(w); DO(n, RZ(x=smmcar(a,WVR(i))); zv[i]=AREL(x,z););} + else MC(zv,wv,n*bp(t)); + R z; +} /* make copy of w in SMM area of a */ + +F2(jtsmmis){A*wv,x;A1*av;I wd,wn,wr; + RZ(a&&w); + if(a==w)R a; + wn=AN(w); wr=AR(w); + if(smmin(a,w))RZ(w=cpa(1,w)); + AK(a)=SZI*(AH+64); AT(a)=AT(w); AN(a)=wn; AR(a)=wr; + if(!smminit(a)){AT(a)=LIT; AN(a)=0; AR(a)=1; *AS(a)=0; R 0;} + av=A1AV(a); wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(wn, x=smmcar(a,WVR(i)); if(!x){AT(a)=LIT; AN(a)=0; AR(a)=1; *AS(a)=0; R 0;} av[i]=AREL(x,a);); + ICPY(AS(a),AS(w),wr); + R a; +} /* a=:w where a is mapped and w is boxed */ + + +A jtcpa(J jt,B b,A w){A*wv,z,*zv;I wd; + if(0==b&&AFNJA&AFLAG(w))R ra(w); + if(!(BOX&AT(w)))R ca(w); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(z,BOX,AN(w),AR(w),AS(w)); zv=AAV(z); + DO(AN(w), RZ(zv[i]=cpa(b,WVR(i)));); + R z; +} /* copy w down to leaves, recursing on boxed AFNJA iff 1=b */ + +static B leafrel(A w){A*v; + if(BOX&AT(w)){ + if(AFLAG(w)&AFNJA)R 0; + if(AFLAG(w)&AFSMM+AFREL)R 1; + v=AAV(w); DO(AN(w), if(leafrel(v[i]))R 1;); + } + R 0; +} /* 1 iff a leaf of w contains a relative address */ + +F1(jtrca){ + RZ(w); + if(!(BOX&AT(w)))R AFSMM&AFLAG(w)?ca(w):w; + R leafrel(w)?cpa(0,w):w; +} + + + +static F1(jtsmmblkf){A z;I**mfree,p,q,*v,*zv;MS*x; + RZ(w); + mfree=SMMFREE(w); + p=MLEN; q=0; + DO(p, v=mfree[i]; while(v){x=(MS*)AABS(v,w); ++q; v=x->a;}); + GA(z,INT,2*q,2,0); *AS(z)=q; *(1+AS(z))=2; zv=AV(z); + DO(p, v=mfree[i]; while(v){x=(MS*)AABS(v,w); *zv++=(I)x; *zv++=msize[x->j]; v=x->a;}); + R z; +} /* blocks free as a 2-column matrix of (address,size) */ + +static I smmblkun(B b,A w){A1*wv;I z=0;MS*x; + x=(MS*)w-1; + if(b&&x->a)z=1; + if(BOX&AT(w)){wv=A1AV(w); DO(AN(w), z+=smmblkun(1, (A)AABS(wv[i],w)););} + R z; +} /* # of lines in the result of smmblku */ + +static I* smmblku1(B b,I*zv,A w){A1*wv;MS*x; + x=(MS*)w-1; + if(b&&x->a){*zv++=(I)x; *zv++=msize[x->j];} + if(BOX&AT(w)){wv=A1AV(w); DO(AN(w), zv=smmblku1(1,zv,(A)AABS(wv[i],w)););} + R zv; +} + +static A jtsmmblku(J jt,A w){A z;I n; + RZ(w); + n=smmblkun(0,w); + GA(z,INT,2*n,2,0); *AS(z)=n; *(1+AS(z))=2; + smmblku1(0,AV(z),w); + R z; +} /* blocks in use */ + +F1(jtsmmblks){A x,y,z;I n,t,*v,*zv; + RZ(w); + t=AT(w); + ASSERT(AFNJA&AFLAG(w)&&t&BOX,EVDOMAIN); + RZ(x=smmblku(w)); + RZ(y=smmblkf(w)); + n=1+*AS(x)+*AS(y); + GA(z,INT,3*n,2,0); *AS(z)=n; *(1+AS(z))=3; zv=AV(z); + *zv++=IMIN; *zv++=IMIN; *zv++=IMIN; + v=AV(x); DO(*AS(x), *zv++=*v++; *zv++=*v++; *zv++=SMMCINUSE;); + v=AV(y); DO(*AS(y), *zv++=*v++; *zv++=*v++; *zv++=SMMCFREE; ); + RZ(z=grade2(z,z)); zv=AV(z); + *zv++=(I)smmu(w); *zv++=smmsize(w); *zv++=SMMCTOTAL; + R z; +} /* 15!:12 all the blocks in an SMM variable as 3-column matrix */ + +/* +// F2(jtafr2){A x,*wv;A1*wu; +// RZ(a&&w); +// wv=AAV(w); wu=A1AV(w); +// DO(AN(w), x=(A)AABS(wu[i],a); if(BOX&AT(x))RZ(x=afr2(a,x)); wv[i]=x;); +// R w; +// } /* w has addresses relative to a; works in place */ + +A relocate(I m,A w){A1*wv; RZ(w); AFLAG(w)|=AFREL; wv=A1AV(w); DO(AN(w), wv[i]+=m;); R w;} + /* add m to the addresses in w; works in place */
new file mode 100644 --- /dev/null +++ b/p.c @@ -0,0 +1,168 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Parsing; see APL Dictionary, pp. 12-13 & 38. */ + +#include "j.h" +#include "p.h" + + +/* NVR - named value reference */ +/* a value referenced in the parser which is the value of a name */ +/* (that is, in some symbol table). */ +/* */ +/* jt->nvra NVR stack a: stack of A values */ +/* jt->nvrav AAV(jt->nvra) */ +/* jt->nvrb NVR stack b: corresponding to stack a -- */ +/* 1 if unchanged; 0 if redefined */ +/* jt->nvrbv BAV(jt->nvrb) */ +/* jt->nvrtop index of top of stack */ +/* */ +/* Each call of the parser records the current NVR stack top (nvrtop), */ +/* (nvrtop), and pop stuff off the stack back to that top on exit */ +/* */ +/* nvrpush(w): w is a named value just moved from the parser queue */ +/* to the parser stack. Push w onto the NVR stack. */ +/* nvrpop(otop): pop stuff off the NVR stack back to the old top otop */ +/* nvrredef(w): w is the value of a name about to be redefined */ +/* (reassigned or erased). checks whether w is in the */ +/* NVR stack */ + + +B jtparseinit(J jt){A x; + GA(x,INT,20,1,0); ra(x); jt->nvra=x; jt->nvrav=AAV(x); + GA(x,B01,20,1,0); ra(x); jt->nvrb=x; jt->nvrbv=BAV(x); + R 1; +} + +static F1(jtnvrpush){ + if(jt->nvrtop==AN(jt->nvra)){ + RZ(jt->nvra=ext(1,jt->nvra)); jt->nvrav=AAV(jt->nvra); + while(AN(jt->nvrb)<AN(jt->nvra))RZ(jt->nvrb=ext(1,jt->nvrb)); jt->nvrbv=BAV(jt->nvrb); + } + jt->nvrav[jt->nvrtop]=w; + jt->nvrbv[jt->nvrtop]=1; + ++jt->nvrtop; + R w; +} + +static void jtnvrpop(J jt,I otop){A*v=otop+jt->nvrav;B*b=otop+jt->nvrbv; + DO(jt->nvrtop-otop, if(!*b++)fa(*v); ++v;); + jt->nvrtop=otop; +} + +void jtnvrredef(J jt,A w){A*v=jt->nvrav;B*b=jt->nvrbv; + DO(jt->nvrtop, if(w==*v++){if(b[i]){ra(w); b[i]=0;} break;}); +} /* stack handling for w which is about to be redefined */ + + +ACTION(jtmonad ){R dfs1(stack[e],stack[b]);} +ACTION(jtdyad ){R dfs2(stack[b],stack[e],stack[1+b]);} +ACTION(jtadv ){R dfs1(stack[b],stack[e]);} +ACTION(jtconj ){R dfs2(stack[b],stack[e],stack[1+b]);} +ACTION(jttrident){R folk(stack[b],stack[1+b],stack[e]);} +ACTION(jtbident ){R hook(stack[b],stack[e]);} +ACTION(jtpunc ){R stack[e-1];} + +static ACTION(jtmove){A z; + z=stack[MAX(0,e)]; + if(!(NAME&AT(z))||ASGN&AT(stack[b]))R z; + RZ(z=jt->xdefn&&NMDOT&NAV(z)->flag?symbrd(z):nameref(z)); + R nvrpush(z); +} + +static F2(jtisf){R symbis(onm(a),CALL1(jt->pre,w,0L),jt->symb);} + +ACTION(jtis){A f,n,v;B ger=0;C c,*s; + n=stack[b]; v=stack[e]; + if(LIT&AT(n)&&1>=AR(n)){ + ASSERT(1>=AR(n),EVRANK); + s=CAV(n); ger=CGRAVE==*s; + RZ(n=words(ger?str(AN(n)-1,1+s):n)); + if(1==AN(n))RZ(n=head(n)); + } + ASSERT(AN(n)||!IC(v),EVILNAME); + f=stack[1+b]; c=*CAV(f); jt->symb=jt->local&&c==CASGN?jt->local:jt->global; + if(NAME&AT(n)) symbis(n,v,jt->symb); + else if(!AR(n))symbis(onm(n),v,jt->symb); + else {ASSERT(1==AR(n),EVRANK); jt->pre=ger?jtfxx:jtope; rank2ex(n,v,0L,-1L,-1L,jtisf);} + jt->symb=0; + RNE(v); +} + + +#define AVN ( ADV+VERB+NOUN) +#define CAVN (CONJ+ADV+VERB+NOUN) +#define EDGE (MARK+ASGN+LPAR) + +PT cases[] = { + EDGE, VERB, NOUN, ANY, jtmonad, jtvmonad, 1,2,1, + EDGE+AVN, VERB, VERB, NOUN, jtmonad, jtvmonad, 2,3,2, + EDGE+AVN, NOUN, VERB, NOUN, jtdyad, jtvdyad, 1,3,2, + EDGE+AVN, VERB+NOUN, ADV, ANY, jtadv, jtvadv, 1,2,1, + EDGE+AVN, VERB+NOUN, CONJ, VERB+NOUN, jtconj, jtvconj, 1,3,1, + EDGE+AVN, VERB+NOUN, VERB, VERB, jttrident, jtvfolk, 1,3,1, + EDGE, CAVN, CAVN, ANY, jtbident, jtvhook, 1,2,1, + NAME+NOUN, ASGN, CAVN, ANY, jtis, jtvis, 0,2,1, + LPAR, CAVN, RPAR, ANY, jtpunc, jtvpunc, 0,2,0, +}; + + +F1(jtparse){A*u,*v,y,z;I n; + RZ(w); + n=AN(w); v=AAV(w); + GA(y,BOX,5+n,1,0); u=AAV(y); + RZ(deba(DCPARSE,0L,w,0L)); + *u++=mark; DO(n, *u++=*v++;); *u++=mark; *u++=mark; *u++=mark; *u++=mark; + z=parsea(y); + debz(); + R z; +} + +F1(jtparsea){A*s,*stack,y,z;AF f;I b,*c,e,i,j,k,m,n,otop=jt->nvrtop,*sp; + RZ(w); + n=m=AN(w)-4; stack=AAV(w); jt->asgn=0; ++jt->parsercalls; + if(1>=n)R mark; + RZ(y=IX(AN(w))); sp=AV(y); /* current location in tokens */ + do{ + for(i=0;i<NCASES;i++){ + c=cases[i].c; s=n+stack; + if(*c++&AT(*s++)&&*c++&AT(*s++)&&*c++&AT(*s++)&&*c++&AT(*s++)) break; + } + if(i<NCASES){ + b=cases[i].b; j=n+b; + e=cases[i].e; k=n+e; + jt->sitop->dci=sp[k]=sp[n+cases[i].k]; + f=cases[i].f; + jt->asgn=f==jtis; + stack[k]=y=f(jt,j,k,stack); + DO(b, stack[--k]=stack[--j]; sp[k]=sp[j];); n=k; + }else{ + jt->sitop->dci=sp[MAX(0,n-1)]=sp[MAX(0,m-1)]; + stack[n-1]=y=move(n,m-1,stack); + n-=0<m--; + }} while(y&&0<=m); + nvrpop(otop); + RZ(y); + z=stack[1+n]; + ASSERT(AT(z)&MARK+CAVN&&AT(stack[2+n])&MARK,EVSYNTAX); + R z; +} + +/* locals in parsea */ +/* b: beginning index in stack that action applies to */ +/* c: temp on cases[] used to match 4-patterns */ +/* e: ending index in stack that action applies to */ +/* f: current action */ +/* i: index in cases[] of matching 4-pattern */ +/* j: absolute index corresponding to b */ +/* k: absolute index corresponding to e */ +/* m: current # of words in the queue */ +/* n: index of top of stack */ +/* otop: old value of jt->nvrtop */ +/* s: temp on stack used to match 4-patterns */ +/* sp: index in original sentence of stack elements */ +/* stack: parser stack as described in dictionary */ +/* w: argument; contains both the queue and the stack */ +/* y: array temp */ +/* z: result */
new file mode 100644 --- /dev/null +++ b/p.h @@ -0,0 +1,40 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Parsing: Macros and Defined Constants */ + + +#define NCASES 9L /* # of rows in cases parses table */ +#define ACTION(f) A f(J jt,I b,I e,A* stack) +#define TACT(f) TA f(J jt,I b,I e,TA*stack) +#define IS(name,val) symbis(name,val,jt->local) + +typedef TA(*TAF)(); +typedef struct{I c[4];AF f;TAF vf;I b,e,k;} PT; + +/* c: 4-patterns for AT(x) of top 4 parser stack elements */ +/* f: action */ +/* vf: action for tacit verb translator */ +/* b: beginning index in stack that action applies to */ +/* e: ending index in stack that action applies to */ +/* k: index in stack of error indicator */ + +extern PT cases[]; + +extern TACT(jtvadv); +extern TACT(jtvconj); +extern TACT(jtvdyad); +extern TACT(jtvfolk); +extern TACT(jtvhook); +extern TACT(jtvis); +extern TACT(jtvmonad); +extern TACT(jtvpunc); + +extern ACTION(jtadv); +extern ACTION(jtbident); +extern ACTION(jtconj); +extern ACTION(jtdyad); +extern ACTION(jtis); +extern ACTION(jtmonad); +extern ACTION(jtpunc); +
new file mode 100644 --- /dev/null +++ b/pv.c @@ -0,0 +1,244 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Parsing: Tacit Verb Translator (13 : ) */ + +#include "j.h" +#include "p.h" + +#define WTA 2 /* sizeof(TA)/sizeof(A) */ +#define NTTAB 20 +#define TC 5485900 + +#define CHK1 (!(stack[b].t) ) +#define CHK2 (!(stack[b].t||stack[e].t) ) +#define CHK3 (!(stack[b].t||stack[1+b].t||stack[e].t)) +#define CP ds(CCAP) +#define DCASE(x,y) (6*(x)+(y)) +#define FGL(v) folk(v->f,v->g,ds(CLEFT )) +#define FGR(v) folk(v->f,v->g,ds(CRIGHT)) +#define LF ds(CLEFT ) +#define RT ds(CRIGHT) +#define RZZ(exp) {if(!(exp))R zz;} + + +static TA zz={0,0}; + +static F1(jtvtokens){A t,*y,z;I n,*s;TA*x; + RZ(t=tokens(vs(w))); n=AN(t); y=AAV(t); + jt->tmonad=1; + GA(z,BOX,WTA*(5+n),2,0); s=AS(z); *s++=5+n; *s=WTA; + x=(TA*)AV(z); + x->a=mark; x->t=0; ++x; + DO(n, x->a=t=*y++; x->t=0; ++x; if(t==xnam||jt->dotnames&&t==xdot)jt->tmonad=0;); + x->a=mark; x->t=0; ++x; + x->a=mark; x->t=0; ++x; + x->a=mark; x->t=0; ++x; + x->a=mark; x->t=0; ++x; + R z; +} /* build string sentence into queue suitable for parsing */ + +static F1(jtcfn){I j; R !AR(w)&&INT&AT(w)&&(j=*AV(w),-9<=j&&j<=9)?FCONS(w):qq(w,ainf);} + /* constant function with value w */ + +static F1(jttine){V*v; R w&&jt->tmonad&&(v=VAV(w),CP==v->f&&RT==v->h)?v->g:w;} + /* if monad and w = [: g ], then g; else just w itself */ + +static I tvi(A w){A x;I i,z=-1;V*v; + if(w&&VERB&AT(w)){ + v=VAV(w); + if(CQQ==v->id&&num[-1]==v->g){ + x=v->f; + if(!AR(x)&&INT&AT(x)){i=*AV(x)-TC; z=0<=i&&i<NTTAB?i:-1;} + }} + R z; +} + +static C ctab[]={CEQ,CMIN,CMAX,CPLUS,CPLUSDOT,CPLUSCO,CSTAR,CSTARDOT,CSTARCO,CMATCH,CNE,0}; + +static F1(jtswapc){C c; + if(!primitive(w))R swap(w); + c=ID(w); + R strchr(ctab,c)?w:c==CLT?ds(CGT):c==CGT?ds(CLT):c==CLE?ds(CGE):c==CGE?ds(CLE):swap(w); +} /* w~ or equivalent */ + +TACT(jtvmonad){A fs;TA y,z={one};V*v; + y=stack[e]; fs=stack[b].a; + if(!y.t)z.a=df1(y.a,fs); + else{ + v=VAV(y.t); + if(!(CFORK==v->id&&0<=tvi(v->h)))z.t=folk(CP,fs,tine(y.t)); + else if(NOUN&AT(v->f)) z.t=folk(CP,folk(CP,fs,folk(v->f,v->g,RT)),tine(v->h)); + else z.t=folk(tine(v->f),folk(CP,fs,v->g),tine(v->h)); + } + R z; +} + +static I jtdcase(J jt,I xi,V*v){ + R !v ? 0 : 0>xi ? 1 : CFORK!=v->id ? 2 : NOUN&AT(v->f) ? 3 : CP==v->f ? 4 : 5; +} +/* 0 x */ +/* 1 f */ +/* 2 t */ +/* 3 x f t */ +/* 4 [: f t */ +/* 5 s f t */ + +TACT(jtvdyad){A fs,sf,xt,yt;B xl,xr,yl,yr;I xi=-1,yi=-1;TA x,y,z={one};V*u=0,*v=0; + fs=stack[e-1].a; x=stack[b]; y=stack[e]; sf=swapc(fs); + if(xt=tine(x.t)){xi=tvi(x.t); u=VAV(xt); if(0>xi&&CFORK==u->id){xi=tvi(u->f); if(0>xi)xi=tvi(u->h);}} + if(yt=tine(y.t)){yi=tvi(y.t); v=VAV(yt); if(0>yi&&CFORK==v->id){yi=tvi(v->f); if(0>yi)yi=tvi(v->h);}} + if(fs==ds(CLEFT)){if(xt)z.t=xt; else z.a=x.a; R z;} + if(0>xi&&0>yi)switch((xt?2:0)+(yt?1:0)){ + case 0: z.a=df2(x.a,y.a,fs); break; + case 1: z.t=folk(x.a,fs,yt); break; + case 2: z.t=folk(y.a,sf,xt); break; + case 3: + xl=xt==LF; xr=xt==RT; + yl=yt==LF; yr=yt==RT; + if (xl&&yr) z.t=fs; + else if(xr&&(yl||yr&&jt->tmonad))z.t=sf; + else z.t=CFORK==u->id&&primitive(yt)?folk(yt,sf,xt):folk(xt,fs,yt); + }else{B b,c;I i,j,xj,yj; + i=dcase(xi,u); if(u&&CFORK==u->id){xi=tvi(u->f); xj=tvi(u->h);}else{xi=-1; xj=tvi(xt);} + j=dcase(yi,v); if(v&&CFORK==v->id){yi=tvi(v->f); yj=tvi(v->h);}else{yi=-1; yj=tvi(yt);} + z.t=0; b=xj==yj; c=xj==yi; + switch(DCASE(i,j)){ + case DCASE(0,2): z.t=folk(x.a,fs,yt); break; + case DCASE(2,0): z.t=folk(y.a,sf,xt); break; + case DCASE(0,3): z.t=folk(CP,folk(x.a,fs,FGR(v)),v->h); break; + case DCASE(0,4): z.t=folk(CP,folk(x.a,fs,v->g ),v->h); break; + case DCASE(1,2): z.t=folk(xt,fs,yt); break; + case DCASE(1,3): + case DCASE(1,4): z.t=folk(xt,folk(LF,fs,FGR(v)),v->h); break; + case DCASE(2,1): z.t=folk(xt,fs,yt); break; + case DCASE(3,1): z.t=folk(xt,fs,yt); break; + case DCASE(4,1): z.t=folk(xt,fs,yt); break; + case DCASE(2,2): z.t=folk(xt,fs,yt); break; + case DCASE(2,3): z.t=b?folk(CP,folk(RT, fs,FGR(v)),v->h):folk(xt, folk(LF, fs,FGR(v)),v->h); break; + case DCASE(2,4): z.t=b?folk(CP,folk(RT, fs,v->g ),v->h):folk(xt, folk(LF, fs,FGR(v)),v->h); break; + case DCASE(3,2): z.t=b?folk(CP,folk(FGR(u),fs,RT ),yt ):folk(u->h,folk(FGL(u),fs,RT ),yt ); break; + case DCASE(3,3): z.t=b?folk(CP,folk(FGR(u),fs,FGR(v)),v->h):folk(u->h,folk(FGL(u),fs,FGR(v)),v->h); break; + case DCASE(3,4): z.t=b?folk(CP,folk(FGR(u),fs,v->g ),v->h):folk(u->h,folk(FGL(u),fs,FGR(v)),v->h); break; + case DCASE(4,2): z.t=b?folk(CP,folk(u->g, fs,RT ),yt ):folk(u->h,folk(FGL(u),fs,RT ),yt ); break; + case DCASE(4,3): z.t=b?folk(CP,folk(u->g, fs,FGR(v)),v->h):folk(u->h,folk(FGL(u),fs,FGR(v)),v->h); break; + case DCASE(4,4): z.t=b?folk(CP,folk(u->g, fs,v->g ),v->h):folk(u->h,folk(FGL(u),fs,FGR(v)),v->h); break; + case DCASE(0,5): z.t=folk(v->f,folk(x.a, fs,v->g),v->h); break; + case DCASE(2,5): if(b||c)z.t=folk(v->f,folk(b?RT:LF, fs,v->g),v->h); break; + case DCASE(3,5): + case DCASE(4,5): if(b||c)z.t=folk(v->f,folk(b?FGR(u):FGL(u),fs,v->g),v->h); break; + case DCASE(5,0): z.t=folk(u->f,folk(y.a, sf,u->g),u->h); break; + case DCASE(5,2): if(b||c)z.t=folk(u->f,folk(u->g, fs,b?RT :LF ),yt ); break; + case DCASE(5,3): + case DCASE(5,4): if(b||c)z.t=folk(u->f,folk(u->g, fs,b?FGR(v):FGL(v) ),v->h); break; + case DCASE(5,5): if(xi==yi&&xj==yj||xi==yj&&xj==yi) + if(b|| v->g==swapc(v->g))z.t=folk(u->f,folk(u->g,fs, v->g ),u->h); + else if(u->g==swapc(u->g))z.t=folk(v->f,folk(u->g,fs, v->g ),v->h); + else z.t=folk(u->f,folk(u->g,fs,swap(v->g)),u->h); + } + RZZ(z.t); + } + R z; +} + +TACT(jtvadv ){TA z={0}; if(CHK1)z.a=df1(stack[b].a,stack[e].a); R z;} + +TACT(jtvconj){TA z={0}; if(CHK2)z.a=df2(stack[b].a,stack[e].a,stack[e-1].a); R z;} + +TACT(jtvfolk){TA z={0}; if(CHK3)z.a=folk(stack[b].a,stack[1+b].a,stack[e].a); R z;} + +TACT(jtvhook){TA z={0}; if(CHK2)z.a=hook(stack[b].a,stack[e].a); R z;} + +TACT(jtvpunc){R stack[e-1];} + +TACT(jtvis){A ea,et,n,t;I j;TA*u,z={0}; + n=stack[b].a; + if(!(NAME&AT(n)&&CASGN==*CAV(stack[1+b].a)))R z; + t=sfn(0,n); j=jt->ttabi; u=jt->ttab; + if(!t||NTTAB==jt->ttabi)R z; + DO(j, if(equ(t,u->a))R z; ++u;); + ea=stack[e].a; et=stack[e].t; + symbis(n,ea,jt->local); + ++jt->ttabi; u->a=t; u->t=et?et:cfn(ea); + z.a=ea; z.t=jt->tsubst?qq(sc(TC+j),num[-1]):et; + R z; +} + +static TACT(jtvmove){A t;TA*u,x,z; + x=stack[MAX(0,e)]; + if(!(NAME&AT(x.a))||ASGN&AT(stack[b].a))R x; + z.a=nameref(x.a); z.t=0; t=sfn(0,x.a); u=jt->ttab; + DO(jt->ttabi, if(equ(t,u->a)){z.t=jt->tsubst&&jt->ttabi0<=i?qq(sc(TC+i),num[-1]):u->t; break;} ++u;); + R z; +} + +/* final translator result */ +/* modifies argument in place */ +/* a. replaces 880i functions by jt->ttab[i].t entries */ +/* b. replaces n0"_ v1 v2 by n0 v1 v2 */ +/* c. replaces [: g ] by g, if monad */ + +static F1(jtvfinal){I i;V*u,*v; + RZ(w); + if(!(VERB&AT(w)))R w; + v=VAV(w); + if(CFORK!=v->id){i=tvi(w); R 0<=i?vfinal(jt->ttab[i].t):w;} + RZ(v->f=tine(vfinal(v->f))); + RZ(v->g=tine(vfinal(v->g))); + RZ(v->h=tine(vfinal(v->h))); + if(VERB&AT(v->f)){ + u=VAV(v->f); + if(CFCONS==u->id)v->f=u->h; + else if(CQQ==u->id&&NOUN&AT(u->f)&&equ(ainf,u->g))v->f=u->f; + if(NOUN&AT(v->f))RZ(w=folk(v->f,v->g,v->h)); + } + R tine(w); +} + +F1(jttparse){A*s,t,x;C d;I b,*c,e,i,j,k,m,n;TA*stack; + RZ(w); + stack=(TA*)AV(w); n=m=*AS(w)-4; + do{ + for(i=0;i<NCASES;i++){ + c=cases[i].c; s=(A*)(n+stack); d=1; + d=d&&*c++&AT(*s); s+=WTA; + d=d&&*c++&AT(*s); s+=WTA; + d=d&&*c++&AT(*s); s+=WTA; + d=d&&*c++&AT(*s); + if(d)break; + } + if(i<NCASES){ + b=cases[i].b; j=n+b; + e=cases[i].e; k=n+e; + stack[k]=(cases[i].vf)(jt,j,k,stack); + RZ(stack[k].a); + DO(b,stack[--k]=stack[--j];); n=k; + } else {stack[n-1]=vmove(n,m-1,stack); RE(0); n-=0<m--;} + } while(0<=m); + x=stack[1+n].a; t=stack[1+n].t; + ASSERT(NOUN&AT(x)&&MARK&AT(stack[2+n].a),EVSYNTAX); + R t?vfinal(t):cfn(x); +} + +F1(jtvtrans){PROLOG;A local,y,z=0;B tmonad,tsubst;I c,i;TA ttab[NTTAB],*ttab0; + local=jt->local; tmonad=jt->tmonad; ttab0=jt->ttab; tsubst=jt->tsubst; + RZ(ttab[0].a=cstr("x")); ttab[0].t=ds(CLEFT); + RZ(ttab[1].a=cstr("y")); ttab[1].t=RT; c=2; + if(jt->dotnames){ + RZ(ttab[2].a=spellout(CXDOT)); ttab[2].t=ds(CLEFT); + RZ(ttab[3].a=spellout(CYDOT)); ttab[3].t=RT; c+=2; + } + for(i=0;!z&&2>i;++i){ + RZ(y=vtokens(w)); + jt->ttab=ttab; jt->ttabi=jt->ttabi0=c; + RZ(jt->local=stcreate(2,1L,0L,0L)); + IS(ynam,one); if(!jt->tmonad)IS(xnam,one); + if(jt->dotnames){IS(ds(CYDOT),one); if(!jt->tmonad)IS(ds(CXDOT),one);} + jt->tsubst=0==i; + z=tparse(y); RESETERR; + if(i&&!z)z=colon(num[4-jt->tmonad],w); + symfreeh(jt->local,0L); + } + jt->local=local; jt->tmonad=tmonad; jt->ttab=ttab0; jt->tsubst=tsubst; + EPILOG(z); +}
new file mode 100644 --- /dev/null +++ b/px.c @@ -0,0 +1,74 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Execute and Associates */ + +/* Variables for controlling execution */ +/* */ +/* B asgn 1 iff last operation on this line is assignment */ +/* DC dcs ptr to debug stack entry for current script */ +/* I etxn strlen(etx) */ +/* C etx[] space for holding error display */ +/* I jbrk 1 iff user has entered "break" */ +/* C jerr error number for this line */ +/* A slist script files used in right argument to 0!: */ +/* I slisti index in slist for current script */ +/* I slistn slist # real entries; AN(slist) is reserved entries */ +/* B tostdout 1 iff output to standard output */ + +#include "j.h" +#include "p.h" + + +A jteval(J jt,C*s){R parse(tokens(cstr(s)));} + +A jtev1(J jt, A w,C*s){R df1( w,eval(s));} +A jtev2(J jt,A a,A w,C*s){R df2(a,w,eval(s));} +A jteva(J jt, A w,C*s){R df1( w,colon(one, cstr(s)));} +A jtevc(J jt,A a,A w,C*s){R df2(a,w,colon(num[2],cstr(s)));} + +F1(jtexec1){A z; + F1RANK(1,jtexec1,0); + FDEPINC(1); z=parse(tokens(vs(w))); jt->asgn=0; FDEPDEC(1); + R z&&AT(z)&VERB+ADV+CONJ+MARK?mtv:z; +} + +F1(jtimmex){A z; + FDEPINC(1); z=parse(tokens(w)); FDEPDEC(1); + if(EWTHROW==jt->jerr){RESETERR; z=mtm;} + if(z&&!jt->asgn)jpr(z); + R z; +} + +F1(jtimmea){A t,z; + z=immex(w); + ASSERT(jt->asgn||!z||!(AT(z)&NOUN)||(t=eq(one,z), + all1(AT(z)&SPARSE?df1(t,atop(slash(ds(CSTARDOT)),ds(CCOMMA))):t)),EVASSERT); + R z; +} + +static A jtcex(J jt,A w,AF f){A z; RE(w); z=f(jt,w); RESETERR; R z;} + /* conditional execute */ + +F1(jtexg){A*v,*wv,x,y,z;I n,wd; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(n,EVLENGTH); + ASSERT(1>=AR(w),EVRANK); + if(VERB&AT(w))R w; + ASSERT(BOX&AT(w),EVDOMAIN); + GA(z,BOX,n,1,0); v=AAV(z); + DO(n, x=WVR(i); RZ(*v++=(y=cex(x,jtfx))?y:exg(x));); + R parse(z); +} + +A jtjset(J jt,C*name,A x){R symbis(nfs((I)strlen(name),name),x,jt->global);} + +F2(jtapplystr){PROLOG;A fs,z;I d; + F2RANK(1,RMAX,jtapplystr,0); + RZ(fs=parse(tokens(vs(a)))); + ASSERT(VERB&AT(fs),EVSYNTAX); + d=fdep(fs); + FDEPINC(d); z=CALL1(VAV(fs)->f1,w,fs); FDEPDEC(d); + EPILOG(z); +} /* execute string a on argument w */
new file mode 100644 --- /dev/null +++ b/r.c @@ -0,0 +1,190 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Representations: Atomic, Boxed, and 5!:0 */ + +#include "j.h" +#include "w.h" + + +static F1(jtdrr){PROLOG;A df,dg,fs,gs,hs,*x,z;B b,ex,xop;C c,id;I fl,*hv,m;V*v; + RZ(w); + if(AT(w)&NOUN)R w; + if(AT(w)&NAME)R sfn(0,w); + v=VAV(w); id=v->id; fl=v->flag; + fs=v->f; gs=v->g; hs=v->h; + if(fl&VXOPCALL)R drr(hs); + xop=1&&VXOP&fl; ex=id==CCOLON&&hs&&!xop; + b=id==CHOOK||id==CADVF; c=id==CFORK; + m=!!fs+(gs||ex); + if(!m)R spella(w); + if(evoke(w))R sfn(0,fs); + if(fs)RZ(df=fl&VGERL?every(fxeach(fs),0L,jtdrr):drr(fs)); + if(gs)RZ(dg=fl&VGERR?every(fxeach(gs),0L,jtdrr):drr(gs)); + if(ex)RZ(dg=unparsem(zero,w)); + m+=!b&&!xop||hs&&xop; + GA(z,BOX,m,1,0); x=AAV(z); + RZ(x[0]=df); + RZ(x[1]=b||c||xop?dg:fl&VDDOP?(hv=AV(hs),link(sc(hv[0]),link(spellout(id),sc(hv[1])))):spellout(id)); + if(2<m)RZ(x[2]=c||xop?drr(hs):dg); + EPILOG(z); +} + +F1(jtdrep){A z=drr(w); R z&&AT(z)&BOX?z:ravel(box(z));} + + +F1(jtaro){A fs,gs,hs,s,*u,*x,y,z;B ex,xop;C id;I*hv,m;V*v; + RZ(w); + if(FUNC&AT(w)){ + v=VAV(w); id=v->id; fs=v->f; gs=v->g; hs=v->h; + if(VXOPCALL&v->flag)R aro(hs); + xop=1&&VXOP&v->flag; + ex=hs&&id==CCOLON&&!xop; + m=id==CFORK?3:!!fs+(ex||xop&&hs||!xop&&gs); + if(!m)R spella(w); + if(evoke(w))R sfn(0,fs); + } + GA(z,BOX,2,1,0); x=AAV(z); + if(NOUN&AT(w)){RZ(x[0]=ravel(scc(CNOUN))); x[1]=w; R z;} + GA(y,BOX,m,1,0); u=AAV(y); + if(0<m)RZ(u[0]=aro(fs)); + if(1<m)RZ(u[1]=aro(ex?unparsem(zero,w):xop?hs:gs)); + if(2<m)RZ(u[2]=aro(hs)); + s=xop?aro(gs):VDDOP&v->flag?(hv=AV(hs),aro(foreign(sc(hv[0]),sc(hv[1])))):spellout(id); + RZ(x[0]=s); x[1]=y; + R z; +} + +F1(jtarep){R box(aro(w));} + + +static F1(jtfxchar){A y;C c,d,id,*s;I m,n; + n=AN(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(n,EVLENGTH); + s=CAV(w); c=*(s+n-1); + DO(n, d=s[i]; ASSERT(32<=d&&d<127,EVSPELL);); + if(CA==ctype[*s]&&c!=CESC1&&c!=CESC2)R swap(w); + ASSERT(id=spellin(n,s),EVSPELL); + if(id!=CFCONS)y=ds(id); else{m=s[n-2]-'0'; y=FCONS(CSIGN!=*s?sc(m):2==n?ainf:sc(-m));} + ASSERT(y&&RHS&AT(y),EVDOMAIN); + R y; +} + +F1(jtfx){A f,fs,g,h,p,q,*wv,y,*yv;C id;I m,n=0,wd,yd; + RZ(w); + if(LIT&AT(w))R fxchar(w); + m=AN(w); wd=(I)w*ARELATIVE(w); + ASSERT(BOX&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVRANK); + ASSERT(1==m||2==m,EVLENGTH); + wv=AAV(w); y=WVR(0); + if(BOX&AT(y)){RZ(fs=fx(y)); id=0;} + else{RZ(y=vs(y)); ASSERT(id=spellin(AN(y),CAV(y)),EVSPELL);} + if(1<m){ + y=WVR(1); n=AN(y); yv=AAV(y); yd=(I)y*ARELATIVE(y); + if(id==CNOUN)R y; + ASSERT(1>=AR(y),EVRANK); + ASSERT(BOX&AT(y),EVDOMAIN); + } + switch(id){ + case CHOOK: case CADVF: + ASSERT(2==n,EVLENGTH); R hook(fx(YVR(0)),fx(YVR(1))); + case CFORK: + ASSERT(3==n,EVLENGTH); + RZ(f=fx(YVR(0))); ASSERT(AT(f)&VERB+NOUN,EVSYNTAX); + RZ(g=fx(YVR(1))); ASSERT(AT(g)&VERB, EVSYNTAX); + RZ(h=fx(YVR(2))); ASSERT(AT(h)&VERB, EVSYNTAX); + R folk(f,g,h); + default: + if(id)fs=ds(id); + ASSERT(fs&&RHS&AT(fs),EVDOMAIN); + if(!n)R fs; + ASSERT(1==n&&ADV&AT(fs)||2==n&&CONJ&AT(fs),EVLENGTH); + if(0<n){RZ(p=fx(YVR(0))); ASSERT(AT(p)&NOUN+VERB,EVDOMAIN);} + if(1<n){RZ(q=fx(YVR(1))); ASSERT(AT(q)&NOUN+VERB,EVDOMAIN);} + R 1==n ? df1(p,fs) : df2(p,q,fs); +}} + +static A jtunparse1(J jt,CW*c,A x,I j,A y){A q,z;C*s;I t; + switch(t=c->type){ + case CBBLOCK: case CTBLOCK: RZ(z=unparse(x)); break; + case CASSERT: RZ(q=unparse(x)); GA(z,LIT,8+AN(q),1,0); s=CAV(z); + MC(s,"assert. ",8L); MC(8+s,CAV(q),AN(q)); break; + case CLABEL: case CGOTO: RZ(z=ca(*AAV(x))); break; + case CFOR: RZ(z=c->n?*AAV(x):spellcon(t)); break; + default: RZ(z=spellcon(t)); + } + if(j==c->source){ + GA(q,LIT,1+AN(y)+AN(z),1,0); s=CAV(q); + MC(s,CAV(y),AN(y)); s+=AN(y); *s++=' '; MC(s,CAV(z),AN(z)); + z=q; + } + R z; +} /* unparse a single line */ + +static A*jtunparse1a(J jt,I m,A*hv,A*zv){A*v,x,y;CW*u;I i,j,k; + y=hv[0]; v=AAV(y); + y=hv[1]; u=(CW*)AV(y); + y=0; j=k=-1; + for(i=0;i<m;++i,++u){ + RZ(x=unparse1(u,vec(BOX,u->n,v+u->i),j,y)); + k=u->source; + if(j<k){if(y)*zv++=y; DO(k-j-1, *zv++=mtv;);} + y=x; j=k; + } + if(y)*zv++=y; + DO(k-j-1, *zv++=mtv;); + R zv; +} + +F2(jtunparsem){A h,*hv,dc,ds,mc,ms,z,*zu,*zv;I dn,m,mn,n,p;V*wv; + RZ(a&&w); + wv=VAV(w); h=wv->h; hv=AAV(h); + mc=hv[1]; ms=hv[2]; m=mn=AN(mc); + dc=hv[1+HN]; ds=hv[2+HN]; n=dn=AN(dc); + p=n&&(m||3==i0(wv->f)||VXOPR&wv->flag); + if(equ(mtv,hv[2])&&equ(mtv,hv[2+HN])){ + if(m)mn=1+((CW*)AV(mc)+m-1)->source; + if(n)dn=1+((CW*)AV(dc)+n-1)->source; + GA(z,BOX,p+mn+dn,1,0); zu=zv=AAV(z); + RZ(zv=unparse1a(m,hv, zv)); if(p)RZ(*zv++=chr[':']); + RZ(zv=unparse1a(n,hv+HN,zv)); + ASSERTSYS(AN(z)==zv-zu,"unparsem zn"); + }else{ + mn=AN(ms); dn=AN(ds); + GA(z,BOX,p+mn+dn,1,0); zv=AAV(z); + ICPY(zv,AAV(ms),mn); zv+=mn; if(p)RZ(*zv++=chr[':']); + ICPY(zv,AAV(ds),dn); + } + if(a==zero){RZ(z=ope(z)); if(1==AR(z))z=table(z);} + R z; +} /* convert h parameter for : definitions; open if a is 0 */ + +static F2(jtxrep){A h,*hv,*v,x,z,*zv;CW*u;I i,j,n,q[3],*s;V*wv; + RZ(a&&w); + RE(j=i0(a)); ASSERT(1==j||2==j,EVDOMAIN); j=1==j?0:HN; + ASSERT(AT(w)&VERB+ADV+CONJ,EVDOMAIN); + wv=VAV(w); h=wv->h; + if(!(h&&CCOLON==wv->id))R reshape(v2(0L,3L),ace); + hv=AAV(h); + x=hv[ j]; v= AAV(x); + x=hv[1+j]; u=(CW*)AV(x); n=AN(x); + GA(z,BOX,3*n,2,0); s=AS(z); s[0]=n; s[1]=3; + zv=AAV(z); + for(i=0;i<n;++i,++u){ + RZ(*zv++=sc(i)); + q[0]=u->type; q[1]=u->go; q[2]=u->source; RZ(*zv++=vec(INT,3L,q)); + RZ(*zv++=unparse1(u,vec(BOX,u->n,v+u->i),-1L,0L)); + } + R z; +} /* explicit representation -- h parameter for : definitions */ + + +F1(jtarx){F1RANK(0, jtarx,0); R arep( symbrdlock(nfb(w)));} +F1(jtdrx){F1RANK(0, jtdrx,0); R drep( symbrdlock(nfb(w)));} +F1(jttrx){F1RANK(0, jttrx,0); R trep( symbrdlock(nfb(w)));} +F1(jtlrx){F1RANK(0, jtlrx,0); R lrep( symbrdlock(nfb(w)));} +F1(jtprx){F1RANK(0, jtprx,0); R prep( symbrdlock(nfb(w)));} + +F2(jtxrx){F2RANK(0,0,jtxrx,0); R xrep(a,symbrdlock(nfb(w)));}
new file mode 100644 --- /dev/null +++ b/rl.c @@ -0,0 +1,320 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Representations: Linear and Paren */ + +#include "j.h" + +#if !SY_WINCE +extern int isdigit(int); +#endif + +static F1(jtlnoun); +static F1(jtlnum); +static F1(jtlrr); + +#define NUMV(c) (c==C9||c==CD||c==CA||c==CS) + + +static B jtlp(J jt,A w){B b=1,p=0;C c,d,q=CQUOTE,*v;I j=0,n; + RZ(w); + n=AN(w); v=CAV(w); c=*v; d=*(v+n-1); + if(1==n||(2==n||3>=n&&' '==c)&&(d==CESC1||d==CESC2)||vnm(n,v))R 0; + if(C9==ctype[c])DO(n-1, d=c; c=ctype[*++v]; if(b=!NUMV(c)||d==CS&&c!=C9)break;) + else if(c==q) DO(n-1, c=*v++; if(c==q)p=!p; if(b=p?0:c!=q)break;) + else if(c=='(') DO(n-1, c=*v++; j+=c=='('?1:c==')'?-1:0; if(b=!j)break;) + R b; +} /* 1 iff put parens around w */ + +static A jtlcpa(J jt,B b,A w){A z=w;C*zv;I n; + RZ(w); + if(b){n=AN(w); GA(z,LIT,2+n,1,0); zv=CAV(z); *zv='('; MC(1+zv,AV(w),n); zv[1+n]=')';} + R z; +} /* if b then (w) otherwise just w */ + +static A jtlcpb(J jt,B b,A w){A z=w;B p;C c,*v,*wv,*zv;I n; + RZ(w); + n=AN(w); wv=CAV(w); + if(!b){ + c=ctype[*wv]; v=wv; p=0; + if (c==CQ)DO(n-1, c=ctype[*++v]; if(c==CQ)p=!p; else if(p){b=1; break;}) + else if(c==C9)DO(n-1, c=ctype[*++v]; if(!(c==C9 ||c==CS )){b=1; break;}) + else DO(n-1, c= *++v ; if(!(c==CESC1||c==CESC2)){b=1; break;}); + if(b&&vnm(n,wv))b=0; + } + if(b){GA(z,LIT,2+n,1,0); zv=CAV(z); *zv='('; MC(1+zv,wv,n); zv[1+n]=')';} + R z; +} + +static A jtlcpx(J jt,A w){RZ(w); R CALL2(jt->lcp,lp(w),w,0);} + +static F1(jtltiea){A t,*v,*wv,x,y;B b;C c;I n,wd; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); RZ(t=spellout(CGRAVE)); + GA(y,BOX,n+n,1,0); v=AAV(y); + DO(n, *v++=i?t:mtv; x=WVR(i); c=ID(x); RZ(x=lrr(x)); + b=c==CHOOK||c==CFORK||i&&lp(x); RZ(*v++=CALL2(jt->lcp,b,x,0));); + R raze(y); +} + +static F1(jtltieb){A pt,t,*v,*wv,x,y;B b;C c,*s;I wd,n; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); RZ(t=spellout(CGRAVE)); RZ(pt=over(scc(')'),t)); + GA(y,BOX,n+n,1,0); v=AAV(y); + if(1>=n)x=mtv; else{GA(x,LIT,n-2,1,0); s=CAV(x); DO(n-2, *s++='(';);} + DO(n, *v++=0==i?x:1==i?t:pt; x=WVR(i); c=ID(x); RZ(x=lrr(x)); + b=c==CHOOK||c==CFORK||i&&lp(x); RZ(*v++=CALL2(jt->lcp,b,x,0));); + R raze(y); +} + +static F1(jtlsh){R over(thorn1(shape(w)),spellout(CDOLLAR));} + +static F1(jtlshape){I r,*s; + RZ(w); + r=AR(w); s=AS(w); + R 2==r&&(1==s[0]||1==s[1]) ? spellout((C)(1==s[1]?CCOMDOT:CLAMIN)) : !r ? mtv : + 1<r ? lsh(w) : 1<AN(w) ? mtv : spellout(CCOMMA); +} + +static F1(jtlchar){A y;B b,p=1,r1;C c,d,*u,*v;I j,k,m,n; + RZ(w); + m=AN(alp); n=AN(w); j=n-m; r1=1==AR(w); u=v=CAV(w); d=*v; + if(0<=j&&r1&&!memcmp(v+j,AV(alp),m)){ + if(!j)R cstr("a."); + RZ(y=lchar(1==j?scc(*v):str(j,v))); + R lp(y)?over(cstr("a.,~"),y):over(y,cstr(",a.")); + } + if(r1&&m==n&&(y=icap(ne(w,alp)))&&m>AN(y)){ + if(1==AN(y))RZ(y=head(y)); + R over(over(cstr("a. "),lcpx(lnum(y))),over(cstr("}~"),lchar(from(y,w)))); + } + j=2; b=7<n||1<n&&1<AR(w); + DO(n, c=*v++; if(c==CQUOTE)++j; b&=c==d; p&=31<c&&c<127;); + if(b){n=1; j=MIN(3,j);} + if(!p){ + k=(UC)d; RZ(y=indexof(alp,w)); + if(r1&&n<m&&(!k||k==m-n)&&equ(y,apv(n,k,1L)))R over(thorn1(sc(d?-n:n)),cstr("{.a.")); + RZ(y=lnum(y)); + R lp(y)?over(cstr("a.{~"),y):over(y,cstr("{a.")); + } + GA(y,LIT,n+j,1,0); v=CAV(y); + *v=*(v+n+j-1)=CQUOTE; ++v; + if(2==j)MC(v,u,n); else DO(n, *v++=c=*u++; if(c==CQUOTE)*v++=c;); + R over(b?lsh(w):lshape(w),y); +} /* non-empty character array */ + +static F1(jtlbox){A p,*v,*vv,*wv,x,y;B b=0;I n,wd; + RZ(w); + if(equ(ace,w)&&B01==AT(AAV0(w)))R cstr("a:"); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(n, x=WVR(i); if(BOX&AT(x)){b=1; break;}); b=b||1==n; + GA(y,BOX,n+n-!b,1,0); v=vv=AAV(y); + if(b){ + RZ(p=cstr("),(<")); + DO(n, x=WVR(i); *v++=p; RZ(*v++=lnoun(x));); + RZ(*vv=cstr(1==n?"<":"(<")); if(1<n)RZ(vv[n+n-2]=cstr("),<")); + R over(lshape(w),raze(y)); + } + DO(n, x=WVR(i); if(b=1!=AR(x)||!(LIT&AT(x)))break;); + if(!b){C c[256],d,*t;UC*s; + DO(256,c[i]=1;); + RZ(x=raze(w)); s=UAV(x); + DO(AN(x), c[*s++]=0;); + if(c[CQUOTE]&&equ(w,words(x)))R over(cstr(";:"),lchar(x)); + if(c[d=' ']||c[d='|']||c[d='/']||c[d=',']||c[d=';']){ + GA(y,LIT,n+AN(x),1,0); t=CAV(y); + DO(n, x=WVR(i); *t++=d; MC(t,AV(x),AN(x)); t+=AN(x);); + RZ(y=lchar(y)); + R over(lshape(w),over(cstr(isdigit(*CAV(y))?"<;.(_1) ":"<;._1 "),y)); + }} + RZ(p=cstr(";")); + DO(n-1, RZ(*v++=lcpx(lnoun(WVR(i)))); *v++=p;); + RZ(*v=lnoun(WVR(n-1))); + R over(lshape(w),raze(y)); +} /* non-empty boxed array */ + +static F1(jtlnum1){A z;I t; + RZ(w); + t=AT(w); + RZ(z=t&FL+CMPX?df1(w,fit(ds(CTHORN),sc((I)18))):thorn1(w)); + R t&XNUM+RAT&&!memchr(CAV(z),t&XNUM?'x':'r',AN(z))?over(z,scc('x')):z; +} /* dense non-empty numeric vector */ + +static F1(jtlnum){A b,d,t,*v,y;B p;I n; + RZ(t=ravel(w)); + n=AN(w); + if(7<n||1<n&&1<AR(w)){ + d=minus(from(one,t),b=from(zero,t)); if(jt->jerr)RESETERR; + p=equ(t,plus(b,tymes(d,IX(n)))); if(jt->jerr)RESETERR; + if(p){ + if(equ(d,zero))R over(lsh(w),lnum1(b)); + GA(y,BOX,6,1,0); v=AAV(y); v[0]=v[1]=v[2]=v[3]=mtv; + if(p=!(equ(b,sc(n-1))&&equ(d,num[-1]))){ + if (!equ(b,zero )){v[0]=lnum1(b); v[1]=spellout(CPLUS);} + if ( equ(d,num[-1])) v[1]=spellout(CMINUS); + else if(!equ(d,one )){v[2]=lnum1(d); v[3]=spellout(CSTAR);} + } + v[4]=spellout(CIOTA); v[5]=thorn1(p?shape(w):negate(shape(w))); + RE(y); R raze(y); + }} + R over(lshape(w),lnum1(t)); +} /* dense numeric non-empty array */ + +static F1(jtlsparse){A a,e,q,t,x,y,z;B ba,be,bn;I j,r,*v;P*p; + RZ(w); + r=AR(w); p=PAV(w); a=SPA(p,a); e=SPA(p,e); y=SPA(p,i); x=SPA(p,x); + bn=0; v=AS(w); DO(r, if(!*v++){bn=1; break;}); + ba=0; if(r==AR(a)){v=AV(a); DO(r, if(i!=*v++){ba=1; break;});} + be=!(AT(w)&SFL&&0==*DAV(e)); + if(be)RZ(z=over(lnoun(e),cstr(SB01&AT(w)?"":SINT&AT(w)?"+-~2":SFL&AT(w)?"+-~2.1":"+-~2j1"))); + if(be||ba){ + RZ(z=be?over(lcpx(lnoun(a)), over(scc(';'),z)):lnoun(a)); + RZ(z= over(lcpx(lnoun(shape(w))),over(scc(';'),z)) ); + }else RZ(z=lnoun(shape(w))); + RZ(z=over(cstr("1$."),z)); + if(bn||!*AS(y))R z; + if(AN(a)){ + RZ(x=lcpx(lnoun(x))); + RZ(y=1==r?lnoun(ravel(y)):over(cstr("(<\"1)"),lnoun(y))); + RZ(t=over(x,over(cstr(" ("),over(y,cstr(")}"))))); + }else RZ(t=over(lcpx(lnoun(head(x))),cstr(" a:}"))); + ba=0; v=AV(a); DO(AN(a), if(i!=*v++){ba=1; break;}); + if(!ba)R over(t,z); + RZ(q=less(IX(r),a)); + RZ(z=over(over(lcpx(lnoun(q)),cstr("|:")),z)); + RZ(z=over(t,z)); + RZ(q=grade1(over(less(IX(r),q),q))); + j=r; v=AV(q); DO(r, if(i!=*v++){j=i; break;}); + R over(lcpx(lnoun(drop(sc(j),q))),over(cstr("|:"),z)); +} /* sparse array */ + +static F1(jtlnoun0){A s,x;B r1; + RZ(w); + r1=1==AR(w); RZ(s=thorn1(shape(w))); + switch(AT(w)){ + default: R over(cstr("i."),s); + case LIT: x=cstr( "''"); R r1?x:over(over(s,scc('$')),x); + case C2T: x=cstr("u: ''"); R r1?x:over(over(s,scc('$')),x); + case BOX: R over(s,cstr("$a:" )); + case B01: R over(s,cstr("$0" )); + case FL: R over(s,cstr("$0.5" )); + case CMPX: R over(s,cstr("$0j5" )); + case XNUM: R over(s,cstr("$0x" )); + case RAT: R over(s,cstr("$1r2" )); + case SBT: R over(s,cstr("$s: ' '")); +}} /* empty dense array */ + +static F1(jtlnoun){I t; + RZ(w); + t=AT(w); + if(t&SPARSE)R lsparse(w); + if(!AN(w))R lnoun0(w); + switch(t){ + case LIT: R lchar(w); + case C2T: R over(cstr("u: "),lnum(uco2(num[3],w))); + case BOX: R lbox(w); + case SBT: R over(cstr("s: "),lbox(sb2(num[5],w))); + default: R lnum(w); +}} + +static A jtlsymb(J jt,C c,A w){A t;C buf[20],d,*s;I*u;V*v=VAV(w); + if(VDDOP&v->flag){ + u=AV(v->h); s=buf; + *s++=' '; *s++='('; s+=sprintf(s,FMTI,*u); spellit(CIBEAM,s); s+=2; s+=sprintf(s,FMTI,u[1]); *s++=')'; + RZ(t=str(s-buf,buf)); + }else RZ(t=spella(w)); + d=cf(t); + R d==CESC1||d==CESC2?over(chr[' '],t):t; +} + +static B laa(A a,A w){C c,d; + RZ(a&&w); + c=ctype[cl(a)]; d=ctype[cf(w)]; + R (c==C9||c==CA)&&(d==C9||d==CA); +} + +static B lnn(A a,A w){C c; RZ(a&&w); c=cl(a); R ('x'==c||C9==ctype[c])&&C9==ctype[cf(w)];} + +static F2(jtlinsert){A*av,f,g,h,t,t0,t1,t2,*u,y;B b,ft,gt,ht,vb;C c,id;I ad,n;V*v; + RZ(a&&w); + n=AN(a); av=AAV(a); ad=(I)w*ARELATIVE(a); + vb=VERB==AT(w); v=VAV(w); id=v->id; + b=id==CCOLON&&VXOP&v->flag; + if(1<=n){f=AVR(0); t=v->f; c=ID(t); ft=c==CHOOK||c==CFORK||c==CADVF||id==CFORK&&NOUN&AT(t)&&lp(f);} + if(2<=n){g=AVR(1); t=v->g; c=ID(t); gt=vb ?c==CHOOK||c==CFORK:lp(g);} + if(3<=n){h=AVR(2); t=v->h; c=ID(t); ht=vb&&!b?c==CHOOK :lp(h);} + switch(!b?id:2==n?CHOOK:CFORK){ + case CADVF: + case CHOOK: + GA(y,BOX,3,1,0); u=AAV(y); + u[0]=f=CALL2(jt->lcp,ft||lnn(f,g),f,0); + u[2]=g=CALL2(jt->lcp,gt||b, g,0); + u[1]=str(' '==cf(g)||id==CADVF&&!laa(f,g)&&!(lp(f)&&lp(g))?0L:1L," "); + RE(0); R raze(y); + case CFORK: + GA(y,BOX,5,1,0); u=AAV(y); + RZ(u[0]=f=CALL2(jt->lcp,ft||lnn(f,g), f,0)); + RZ(u[2]=g=CALL2(jt->lcp,gt||lnn(g,h)||b,g,0)); RZ(u[1]=str(' '==cf(g)?0L:1L," ")); + RZ(u[4]=h=CALL2(jt->lcp,ht, h,0)); RZ(u[3]=str(' '==cf(h)?0L:1L," ")); + R raze(y); + default: + t0=CALL2(jt->lcp,ft||NOUN&AT(v->f)&&!(VGERL&v->flag)&&lp(f),f,0); + t1=lsymb(id,w); + y=over(t0,laa(t0,t1)?over(chr[' '],t1):t1); + if(1==n)R y; + t2=lcpx(g); + R over(y,laa(y,t2)?over(chr[' '],t2):t2); +}} + +static F1(jtlcolon){A*v,x,y;C*s,*s0;I m,n; + RZ(y=unparsem(one,w)); + n=AN(y); v=AAV(y); RZ(x=lrr(VAV(w)->f)); + if(2>n||2==n&&1==AN(v[0])&&':'==*CAV(v[0])){ + if(!n)R over(x,str(5L," : \'\'")); + y=lrr(v[2==n]); + if(2==n)y=over(str(5L,"\':\'; "),y); + R over(over(x,str(3L," : ")),lcpx(y)); + } + m=0; DO(n, m+=AN(v[i]);); + GA(y,LIT,2+n+m,1,0); + s=s0=CAV(y); + DO(n, *s++=CLF; y=v[i]; m=AN(y); MC(s,CAV(y),m); s+=m;); + *s++=CLF; *s++=')'; + RZ(y=str(s-s0,s0)); + jt->ltext=jt->ltext?over(jt->ltext,y):y; + R over(x,str(4L," : 0")); +} + +static F1(jtlrr){A fs,gs,hs,t,*tv;C id;I fl,m;V*v; + RZ(w); + if(AT(w)&NOUN)R lnoun(w); + if(AT(w)&NAME)R sfn(0,w); + v=VAV(w); id=v->id; fs=v->f; gs=v->g; hs=v->h; fl=v->flag; + if(fl&VXOPCALL)R lrr(hs); + m=!!fs+!!gs+(id==CFORK)+(hs&&id==CCOLON&&VXOP&fl); + if(!m)R lsymb(id,w); + if(evoke(w))R sfn(0,fs); + if(!(VXOP&fl)&&hs&&BOX&AT(hs)&&id==CCOLON)R lcolon(w); + GA(t,BOX,m,1,0); tv=AAV(t); + if(2<m)RZ(tv[2]=lrr(hs)); + if(1<m)RZ(tv[1]=fl&VGERR?CALL1(jt->ltie,fxeach(gs),0L):lrr(gs)); + if(0<m)RZ(tv[0]=fl&VGERL?CALL1(jt->ltie,fxeach(fs),0L):lrr(fs)); + R linsert(t,w); +} + +F1(jtlrep){PROLOG;A z; + jt->ltext=0; jt->lcp=(AF)jtlcpa; jt->ltie=jtltiea; + RE(z=lrr(w)); + if(jt->ltext)z=over(z,jt->ltext); + jt->ltext=0; + EPILOG(z); +} + +F1(jtprep){PROLOG;A z; + jt->ltext=0; jt->lcp=(AF)jtlcpb; jt->ltie=jtltieb; + RE(z=lrr(w)); + if(jt->ltext)z=over(z,jt->ltext); + jt->ltext=0; + EPILOG(z); +} +
new file mode 100644 --- /dev/null +++ b/rt.c @@ -0,0 +1,141 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Representations: Tree */ + +#include "j.h" + +static F1(jttrr); + + +static F1(jttrc){A bot,p,*v,x,y;B b;C*bv,c,ul,ll,*pv;I j,k,m,*s,xn,*xv,yn,*yv; + RZ(w); + s=AS(w); v=AAV(w); + xn=s[0]; RZ(x=apv(xn,0L,0L)); xv=AV(x); + yn=s[1]; RZ(y=apv(yn,0L,0L)); yv=AV(y); + j=0; DO(xn, xv[i]=IC(v[j]); j+=yn;); + GA(bot,LIT,yn,1,0); bv=CAV(bot); + ul=jt->bx[0]; ll=jt->bx[6]; + for(j=b=0;j<xn;++j,b=0<j) + for(k=0;k<yn;++k){ + p=*v++; + if(AN(p)){ + m=*(1+AS(p)); yv[k]=MAX(yv[k],m); + pv=CAV(p); c=*pv; + if(b&&(c==ul&&' '!=bv[k]||c!=' '&&ll==bv[k])){xv[j-1]+=1; b=0;} + bv[k]=*(pv+AN(p)-m); + }else bv[k]=' '; + } + R link(x,y); +} + +static I jtpad(J jt,A a,A w,C*zv){C dash,*u,*v,*wv;I c,d,r,*s; + RZ(a&&w); + s=AV(a); r=s[0]; d=s[1]; + if(AN(w)){ + c=*(1+AS(w)); wv=CAV(w); + if(c==d)MC(zv,wv,AN(w)); + else{ + zv-=d; v=zv+c-1; u=wv-c; dash=jt->bx[10]; + DO(IC(w), MC(zv+=d,u+=c,c); v+=d; if(dash==*v)memset(1+v,dash,d-c);); + }} + R r*d; +} + +static F1(jtgraft){A p,q,t,*u,x,y,z,*zv;C*v;I d,j,k,m,n,*pv,*s,xn,*xv,yn,*yv; + RZ(t=trc(w)); u=AAV(t); + x=u[0]; xn=AN(x); xv=AV(x); m=0; DO(xn,m+=xv[i];); + y=u[1]; yn=AN(y); yv=AV(y); + RZ(p=v2(0L,0L)); pv=AV(p); + GA(z,BOX,yn,1,0); zv=AAV(z); + u=AAV(w); + for(j=0;j<yn;++j){ + RE(k=mult(m,yv[j])); GA(q,LIT,k,2,0); s=AS(q); *s=m; *++s=yv[j]; + v=CAV(q); memset(v,' ',AN(q)); + pv[1]=yv[j]; k=j-yn; DO(xn, *pv=xv[i]; RE(v+=pad(p,u[k+=yn],v));); + zv[j]=q; + } + t=zv[0]; n=yv[0]; + if(1==m)RZ(p=scc(jt->bx[10])) + else{ + v=CAV(t); DO(m, if(' '!=*v){j=i; break;} v+=n;); + v=CAV(t)+AN(t)-n; DO(m, if(' '!=*v){k=m-i; break;} v-=n;); + d=k-j; + GA(p,LIT,m,1,0); v=CAV(p); memset(v,' ',m); + if(1==d)*(v+j)=jt->bx[10]; else{memset(v+j,jt->bx[9],d); *(v+j)=*jt->bx; *(v+k-1)=jt->bx[6];} + } + RZ(zv[0]=stitch(p,t)); + R z; +} + +static A jtcenter(J jt,A a,I j,I k,I m){A z;C*x;I n,*s,zn; + RZ(a); + n=AN(a); RE(zn=mult(m,n)); GA(z,LIT,zn,2,0); s=AS(z); *s=m; *++s=n; + x=CAV(z); memset(x,' ',AN(z)); MC(x+n*(j+(m-(j+k))/2),AV(a),n); + R z; +} + +static F2(jttroot){A t,x;B b;C*u,*v;I j=0,k=0,m,n,*s; + RZ(a&&w); + m=AN(a); u=CAV(a); b=!m||1==m&&'0'<=*u&&*u<='9'; + GA(x,LIT,b?1:4+m,1,0); v=CAV(x); + *v=jt->bx[10]; if(!b){v[3+m]=jt->bx[10]; v[1]=v[2+m]=' '; MC(2+v,u,m);} + t=*AAV(w); s=AS(t); m=*s; n=*(1+s); + u=CAV(t); DO(m, if(' '!=*u){j=i; break;} u+=n;); + u=CAV(t)+(m-1)*n; DO(m, if(' '!=*u){k=i; break;} u-=n;); + R link(center(x,j,k,m),w); +} + +static F1(jttleaf){A t,z;C*v;I n,*s; + RZ(w); + n=AN(w); + GA(t,LIT,2+n,2,0); s=AS(t); s[0]=1; s[1]=2+n; + v=CAV(t); v[0]=jt->bx[10]; v[1]=' '; MC(2+v,AV(w),n); + GA(z,BOX,1,1,0); *AAV(z)=t; + R z; +} + +static F1(jttconnect){A*wv,x,y,z;B b,d;C c,*u,*xv,*yv,*zv;I e,i,j,m,n,p,q,zn; + RZ(w); + n=AN(w); wv=AAV(w); y=*wv; m=*AS(y); + e=0; DO(n,e+=*(1+AS(wv[i]));); + RE(zn=mult(m,e)); GA(z,LIT,zn,2,AS(y)); *(1+AS(z))=e; zv=CAV(z); + for(i=0;i<n;++i){ + y=wv[i]; q=*(1+AS(y)); yv=CAV(y); + if(i){ + xv=CAV(x)+p-1; + for(j=0;j<m;++j){ + b=jt->bx[10]==*xv; c=*yv; d=jt->bx[10]==*(1+yv); + if(b&&c==jt->bx[9])c=jt->bx[5]; + if(d&&c==jt->bx[5])c=jt->bx[4]; + if(d&&c==jt->bx[9])c=jt->bx[3]; + if(b&&c==jt->bx[6])c=jt->bx[7]; + *yv=c; yv+=q; xv+=p; + }} + u=zv-e; yv=CAV(y)-q; DO(m, MC(u+=e,yv+=q,q);); zv+=q; + x=y; p=q; + } + R z; +} + +static F1(jttreach){R troot(scc('0'),graft(ope(every(w,0L,jttrr))));} + +static F1(jttrr){PROLOG;A fs,gs,hs,s,t,*x,z;B ex,xop;C id;I fl,*hv,m;V*v; + RZ(w); + if(AT(w)&NOUN+NAME)R tleaf(lrep(w)); + v=VAV(w); id=v->id; fl=v->flag; fs=v->f; gs=v->g; hs=v->h; + if(fl&VXOPCALL)R trr(hs); + xop=1&&VXOP&fl; ex=id==CCOLON&&hs&&!xop; + m=!!fs+(gs||ex)+(id==CFORK||xop&&hs); + if(!m)R tleaf(spella(w)); + if(evoke(w))R tleaf(sfn(0,fs)); + GA(t,BOX,m,1,0); x=AAV(t); + if(0<m)RZ(x[0]=fl&VGERL?treach(fxeach(fs)):trr(fs)); + if(1<m)RZ(x[1]=fl&VGERR?treach(fxeach(gs)):ex?trr(unparsem(zero,w)):trr(gs)); + if(2<m)RZ(x[2]=trr(hs)); + s=xop?spellout('0'):fl&VDDOP?(hv=AV(hs),over(thorn1(sc(hv[0])),over(spellout(id),thorn1(sc(hv[1]))))):spellout(id); + z=troot(s,graft(ope(t))); + EPILOG(z); +} + +F1(jttrep){PROLOG; EPILOG(tconnect(troot(mtv,trr(w))));}
new file mode 100644 --- /dev/null +++ b/s.c @@ -0,0 +1,272 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Symbol Table */ + +#include "j.h" + + +/* a symbol table aka locale is a type INT vector */ +/* the length is prime and is one of ptab[i] */ +/* zero elements mean unused entry */ +/* non-zero elements are indices in the global symbol pool and */ +/* are head pointers to a linked list */ +/* the first element is symbol pool index for locale info */ + +/* the global symbol pool is a type INT matrix */ +/* the number of columns is symcol=ceiling(sizeof(L)/sizeof(I)) */ +/* elements are interpreted per type L (see jtype.h) */ +/* A name - A name on LHS of assignment or locale name */ +/* A val - value or locale search path */ +/* I sn - script index */ +/* I flag - various flags */ +/* I next - pointer to successor in linked list */ +/* I prev - pointer to predecessor in linked list */ +/* if no predecessor then pointer to hash table entry, and */ +/* flag will include LHEAD */ +/* a stack of free entries is kept using the next pointer */ +/* jt->symp: symbol pool array */ +/* jt->sympv: symbol pool array pointer, (L*)AV(jt->symp) */ +/* jt->symindex: symbol table index (monotonically increasing) */ + +/* numbered locales: */ +/* jt->stnum: -1 means free; others are numbers in use */ +/* jt->stptr: 0 means free; others are symbol tables */ +/* jt->stused: # entries in stnum/stptr in use */ +/* jt->stmax: 1 + maximum number extant */ + +/* named locales: */ +/* jt->stloc: locales symbol table */ + +static I symcol=(sizeof(L)+SZI-1)/SZI; + +B jtsymext(J jt,B b){A x,y;I j,m,n,s[2],*v,xn,yn;L*u; + if(b){y=jt->symp; j=((MS*)y-1)->j; n=*AS(y); yn=AN(y);} + else { j=12; n=1; yn=0; } + m=msize[1+j]; /* new size in bytes */ + m-=sizeof(MS)+SZI*(AH+2); /* less array overhead */ + m/=symcol*SZI; /* new # rows */ + s[0]=m; s[1]=symcol; xn=m*symcol; /* new pool array shape */ + GA(x,INT,xn,2,s); v=AV(x); /* new pool array */ + if(b)ICPY(v,AV(y),yn); /* copy old data to new array */ + memset(v+yn,C0,SZI*(xn-yn)); /* 0 unused area for safety */ + u=n+(L*)v; j=1+n; + DO(m-n-1, u++->next=j++;); /* build free list extension */ + if(b)u->next=jt->sympv->next; /* push extension onto stack */ + ((L*)v)->next=n; /* new stack top */ + jt->symp =ra(x); /* preserve new array */ + jt->sympv=(L*)AV(x); /* new array value ptr */ + if(b)fa(y); /* release old array */ + R 1; +} /* 0: initialize (no old array); 1: extend old array */ + +L* jtsymnew(J jt,I*hv){I j;L*u,*v; + while(!(j=jt->sympv->next))RZ(symext(1)); /* extend pool if req'd */ + jt->sympv->next=(j+jt->sympv)->next; /* new top of stack */ + u=j+jt->sympv; + if(u->next=*hv){v=*hv+jt->sympv; v->prev=j; v->flag^=LHEAD;} + u->prev=(I)hv; u->flag=LHEAD; + *hv=j; + R u; +} /* allocate a new pool entry and insert into hash table entry hv */ + +B jtsymfree(J jt,L*u){I q; + q=u->next; + if(q)(q+jt->sympv)->prev=u->prev; + if(LHEAD&u->flag){*(I*)u->prev=q; if(q)(q+jt->sympv)->flag|=LHEAD;} + else (u->prev+jt->sympv)->next=q; + fa(u->name); u->name=0; /* zero out data fields */ + fa(u->val ); u->val =0; u->sn=u->flag=u->prev=0; + u->next=jt->sympv->next; /* point to old top of stack */ + jt->sympv->next=u-jt->sympv; /* new top of stack */ + R 1; +} /* free pool entry pointed to by u */ + +static SYMWALK(jtsymfreeha, B,B01,100,1, 1, RZ(symfree(d))) /* free pool table entries */ + +B jtsymfreeh(J jt,A w,L*v){I*wv;L*u; + wv=AV(w); + ASSERTSYS(*wv,"symfreeh"); + u=*wv+jt->sympv; + RZ(symfree(u)); + RZ(symfreeha(w)); + memset(wv,C0,AN(w)*SZI); + fa(w); + if(v){v->val=0; RZ(symfree(v));} + R 1; +} /* free entire hash table w, (optional) pointed by v */ + + +static SYMWALK(jtsympoola, I,INT,100,1, 1, *zv++=j;) + +F1(jtsympool){A aa,*pu,q,x,y,*yv,z,*zv;I i,j,n,*u,*v,*xv;L*pv; + RZ(w); + ASSERT(1==AR(w),EVRANK); + ASSERT(!AN(w),EVLENGTH); + GA(z,BOX,3,1,0); zv=AAV(z); + n=*AS(jt->symp); pv=jt->sympv; + GA(x,INT,n*6,2,0); *AS(x)=n; *(1+AS(x))=6; xv= AV(x); zv[0]=x; + GA(y,BOX,n, 1,0); yv=AAV(y); zv[1]=y; + for(i=0;i<n;++i,++pv){ /* per pool entry */ + *xv++=i; + *xv++=(q=pv->val)?AT(pv->val):0; + *xv++=pv->flag; + *xv++=pv->sn; + *xv++=pv->next; + *xv++=pv->prev; + RZ(*yv++=(q=pv->name)?sfn(1,q):mtv); + } + GA(y,BOX,n,1,0); yv=AAV(y); zv[2]=y; + DO(n, yv[i]=mtv;); + n=AN(jt->stloc); v=AV(jt->stloc); + for(i=0;i<n;++i)if(j=v[i]){ /* per named locales */ + x=(j+jt->sympv)->val; + RZ(yv[j]=yv[*AV(x)]=aa=sfn(1,LOCNAME(x))); + RZ(q=sympoola(x)); u=AV(q); DO(AN(q), yv[u[i]]=aa;); + } + n=AN(jt->stptr); pu=AAV(jt->stptr); + for(i=0;i<n;++i)if(x=pu[i]){ /* per numbered locales */ + RZ( yv[*AV(x)]=aa=sfn(1,LOCNAME(x))); + RZ(q=sympoola(x)); u=AV(q); DO(AN(q), yv[u[i]]=aa;); + } + if(x=jt->local){ /* per local table */ + RZ( yv[*AV(x)]=aa=cstr("**local**")); + RZ(q=sympoola(x)); u=AV(q); DO(AN(q), yv[u[i]]=aa;); + } + R z; +} /* 18!:31 symbol pool */ + + +L*jtprobe(J jt,A a,A g){C*s;I*hv,k,m;L*v;NM*u; + RZ(a&&g); + u=NAV(a); m=u->m; s=u->s; k=u->hash%AN(g); hv=AV(g)+(k?k:1); + if(!*hv)R jt->cursymb=0; /* (0) empty slot */ + v=*hv+jt->sympv; + while(1){ + u=NAV(v->name); + if(m==u->m&&!memcmp(s,u->s,m))R jt->cursymb=v; /* (1) exact match */ + if(!v->next)R jt->cursymb=0; /* (2) link list end */ + v=v->next+jt->sympv; +}} + +static L*jtprobeis(J jt,A a,A g){C*s;I*hv,k,m;L*v;NM*u; + u=NAV(a); m=u->m; s=u->s; k=u->hash%AN(g); hv=AV(g)+(k?k:1); + if(*hv){ /* !*hv means (0) empty slot */ + v=*hv+jt->sympv; + while(1){ + u=NAV(v->name); + if(m==u->m&&!memcmp(s,u->s,m))R jt->cursymb=v; /* (1) exact match */ + if(!v->next)break; /* (2) link list end */ + v=v->next+jt->sympv; + }} + RZ(v=symnew(hv)); + v->name=ra(a); + R jt->cursymb=v; +} /* probe for assignment */ + +static L*jtsyrd1(J jt,A a,A g,B b){A*v,x,y;L*e;NM*av; + if(b&&jt->local&&(e=probe(a,jt->local))){av=NAV(a); R av->e=e;} + RZ(g&&(y=LOCPATH(g))); + if(e=probe(a,g))R e; + v=AAV(y); + DO(AN(y), x=v[i]; if(e=probe(a,stfind(1,AN(x),CAV(x))))break;); + R e; +} /* find name a where the current locale is g */ + +static A jtlocindirect(J jt,I n,C*u){A a,g=jt->global,x,y;B lcl=1;C*s,*v,*xv;I k,xn;L*e; + s=n+u; + while(u<s){ + v=s; while('_'!=*--v); ++v; + k=s-v; s=v-2; RZ(a=nfs(k,v)); + e=syrd1(a,g,lcl); lcl=0; + ASSERTN(e,EVVALUE,a); + y=e->val; + ASSERTN(!AR(y),EVRANK,a); + ASSERTN(BOX&AT(y),EVDOMAIN,a); + x=AAV0(y); xn=AN(x); xv=CAV(x); + ASSERTN(1>=AR(x),EVRANK,a); + ASSERTN(xn,EVLENGTH,a); + ASSERTN(LIT&AT(x),EVDOMAIN,a); + ASSERTN(vlocnm(xn,xv),EVILNAME,a); + RZ(g=stfind(1,xn,xv)); + } + R g; +} + +L*jtsyrd(J jt,A a,A*symb){A g=jt->global;I m,n;NM*v; + RZ(a); + n=AN(a); v=NAV(a); m=v->m; + if(n>m)RZ(g=NMILOC&v->flag?locindirect(n-m-2,2+m+v->s):stfind(1,n-m-2,1+m+v->s)) + if(symb)*symb=g; + R syrd1(a,g,(B)(n==m)); +} + + +static A jtdllsymaddr(J jt,A w,C flag){A*wv,x,y,z;I i,n,wd,*zv;L*v; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(!n||BOX&AT(w),EVDOMAIN); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + for(i=0;i<n;++i){ + x=WVR(i); v=syrd(nfs(AN(x),CAV(x)),0L); + ASSERT(v,EVVALUE); + y=v->val; + ASSERT(NOUN&AT(y),EVDOMAIN); + zv[i]=flag?(I)AV(y):(I)v; + } + R z; +} /* 15!:6 (0=flag) or 15!:14 (1=flag) */ + +F1(jtdllsymget){R dllsymaddr(w,0);} +F1(jtdllsymdat){R dllsymaddr(w,1);} + + +F1(jtsymbrd){L*v; RZ(w); ASSERTN(v=syrd(w,0L),EVVALUE,w); R v->val;} + +F1(jtsymbrdlock){A y; + RZ(y=symbrd(w)); + R FUNC&AT(y)&&(jt->glock||VLOCK&VAV(y)->flag)?nameref(w):y; +} + +B jtredef(J jt,A w,L*v){A f,oldn;DC c,d; + d=jt->sitop; while(d&&!(DCCALL==d->dctype&&d->dcj))d=d->dclnk; if(!(d&&DCCALL==d->dctype&&d->dcj))R 1; + oldn=jt->curname; + if(v==(L*)d->dcn){ + jt->curname=d->dca; f=d->dcf; + ASSERT(AT(f)==AT(w)&&(CCOLON==VAV(f)->id)==(CCOLON==VAV(w)->id),EVSTACK); + d->dcf=w; + if(CCOLON==VAV(w)->id)jt->redefined=(I)v; + c=jt->sitop; while(c&&DCCALL!=c->dctype){c->dctype=DCJUNK; c=c->dclnk;} + } + c=d; while(c=c->dclnk){jt->curname=c->dca; ASSERT(!(DCCALL==c->dctype&&v==(L*)c->dcn),EVSTACK);} + jt->curname=oldn; + R 1; +} /* check for changes to stack */ + +A jtsymbis(J jt,A a,A w,A g){A x;I m,n,wn,wr,wt;NM*v;L*e;V*wv; + RZ(a&&w&&g); + n=AN(a); v=NAV(a); m=v->m; + if(n==m)ASSERT(!(jt->local&&g==jt->global&&probe(a,jt->local)),EVDOMAIN) + else{C*s=1+m+v->s; RZ(g=NMILOC&v->flag?locindirect(n-m-2,1+s):stfind(1,n-m-2,s));} + RZ(e=probeis(a,g)); + if(jt->db)RZ(redef(w,e)); + wt=AT(w); + if(wt&FUNC&&(wv=VAV(w),wv->f)){if(wv->id==CCOLON)wv->flag|=VNAMED; if(jt->glock)wv->flag|=VLOCK;} + x=e->val; + ASSERT(!(x&&AFRO&AFLAG(x)),EVRO); + if(!(x&&AFNJA&AFLAG(x))){ + RZ(w=ra(AFNJA&AFLAG(w)?w:rca(w))); + nvrredef(x); + fa(x); + e->val=w; + }else if(x!=w){ /* replacing mapped data */ + if(wt&BOX)R smmis(x,w); + wn=AN(w); wr=AR(w); m=wn*bp(wt); + ASSERT(wt&B01+INT+FL+CMPX+LIT,EVDOMAIN); + ASSERT(AM(x)>=m,EVALLOC); + AT(x)=wt; AN(x)=wn; AR(x)=wr; ICPY(AS(x),AS(w),wr); MC(AV(x),AV(w),m); + } + e->sn=jt->slisti; + if(jt->stch&&(m<n||jt->local!=g&&jt->stloc!=g))e->flag|=LCH; + R mark; +} /* a: name; w: value; g: symbol table */
new file mode 100644 --- /dev/null +++ b/s.h @@ -0,0 +1,39 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* For Symbol Tables aka Locales */ + + +#define LOCPATH(g) ((*AV(g)+jt->sympv)->val ) +#define LOCNAME(g) ((*AV(g)+jt->sympv)->name) +#define NMHASH(p,s) (*(s)+(p)+99991L*(UC)(s)[(p)-1]) + + +/* macro to define a function that walks through a symbol table */ +/* f - name of derived function */ +/* T - for z, C datatype */ +/* TYPE - for z, J datatype */ +/* COUNT - for z, # of initial items for z */ +/* COL - for z, # columns */ +/* SELECT - selection function on a name */ +/* PROCESS - processing on a selected name */ + +#define SYMWALK(f,T,TYPE,COUNT,COL,SELECT,PROCESS) \ + F1(f){A z;I*e,i,j,k,m=0,n;L*d;T*zv; \ + RZ(w); \ + n=AN(w); e=1+AV(w); k=*e; \ + GA(z,(TYPE),(COUNT)*(COL),(1<(COL))?2:1,0); \ + if(1<(COL)){*AS(z)=(COUNT); *(1+AS(z))=(COL);} \ + zv=(T*)AV(z); \ + for(i=1;i<n;++i,k=*++e)while(j=k){ \ + d=j+jt->sympv; \ + k=d->next; \ + if((d->name)&&(SELECT)){ \ + if(m==*AS(z)){RZ(z=ext(0,z)); zv=(m*(COL))+(T*)AV(z);} \ + {PROCESS;} \ + ++m; \ + }} \ + AN(z)=m*(COL); *AS(z)=m; \ + R z; \ + } +
new file mode 100644 --- /dev/null +++ b/sc.c @@ -0,0 +1,60 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Symbol Table: Function Call (unquote) */ + +#include "j.h" + + +static DF2(jtunquote){A aa,fs,g,ll,oldn,oln,z;B lk;I d,i;L*e;V*v; + RE(0); + JATTN; + v=VAV(self); + aa=v->f; RE(e=syrd(aa,&g)); + fs=v->h?v->h:e?e->val:0; /* see namerefop() re v->h */ + oldn=jt->curname; jt->curname=aa; + oln =jt->curlocn; jt->curlocn=ll=g?LOCNAME(g):0; + ASSERT(fs,EVVALUE); + ASSERT(AT(self)==AT(fs),EVDOMAIN); + d=fdep(fs); + FDEPINC(d); ASSERT(jt->fcalln>=jt->fcalli,EVSTACK); + if(0<jt->pmctr)pmrecord(aa,ll,-1L,a?VAL2:VAL1); + lk=jt->glock||VLOCK&VAV(fs)->flag; + i=++jt->fcalli; + jt->fcallg[i].sw0=jt->stswitched; jt->fcallg[i].og=jt->global; + jt->fcallg[i].flag=0; jt->stswitched=0; jt->fcallg[i].g=jt->global=g; + if(jt->db&&!lk)z=dbunquote(a,w,fs); + else{ra(fs); z=a?dfs2(a,w,fs):dfs1(w,fs); fa(fs);} /* beware redefs down the stack */ + if(!jt->stswitched)jt->global=jt->fcallg[i].og; + jt->stswitched=jt->fcallg[i].sw0; + if(jt->fcallg[i].flag)locdestroy(i); + jt->fcallg[i].g=jt->fcallg[i].og=0; jt->stswitched=0; + FDEPDEC(d); --jt->fcalli; + if(0<jt->pmctr)pmrecord(aa,ll,-2L,a?VAL2:VAL1); + jt->curlocn=oln; + jt->curname=oldn; + spfree(); + R z; +} + +static DF1(jtunquote1){R unquote(0L,w,self);} + +F1(jtnameref){A y;L*e;V*v; + RZ(w); + e=syrd(w,0L); + y=e?e->val:ds(CCAP); + if(!y||NOUN&AT(y))R y; + v=VAV(y); + R fdef(CTILDE,AT(y), jtunquote1,jtunquote, w,0L,0L, 0L, v->mr,v->lr,v->rr); +} /* argument assumed to be a NAME */ + +F2(jtnamerefop){V*v; + RZ(a&&w); + v=VAV(w); + R fdef(CCOLON,VERB, jtunquote1,jtunquote, a,0L,w, VXOPCALL, v->mr,v->lr,v->rr); +} + +/* namerefop() is used by explicit defined operators when: */ +/* - debug is on */ +/* - operator arguments have been supplied */ +/* - function arguments have not yet been supplied */
new file mode 100644 --- /dev/null +++ b/sl.c @@ -0,0 +1,258 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Symbol Table: Locales */ + +#include "j.h" + + +A jtstcreate(J jt,C k,I p,I n,C*u){A g,*pv,x,y;C s[20];I m,*nv;L*v; + GA(g,SYMB,ptab[p],1,0); + RZ(v=symnew(AV(g))); v->flag|=LINFO; v->sn=jt->symindex++; + switch(k){ + case 0: /* named locale */ + RZ(x=nfs(n,u)); + LOCNAME(g)=x; LOCPATH(g)=ra(1==n&&'z'==*u?vec(BOX,0L,0L):zpath); + symbis(x,g,jt->stloc); + break; + case 1: /* numbered locale */ + ASSERT(0<=jt->stmax,EVLOCALE); + sprintf(s,FMTI,n); RZ(x=nfs(strlen(s),s)); + LOCNAME(g)=x; LOCPATH(g)=ra(zpath); + ++jt->stused; + m=AN(jt->stnum); + if(m<jt->stused){ + x=ext(1,jt->stnum); y=ext(1,jt->stptr); RZ(x&&y); jt->stnum=x; jt->stptr=y; + nv=m+AV(jt->stnum); pv=m+AAV(jt->stptr); DO(AN(x)-m, *nv++=-1; *pv++=0;); + } + pv=AAV(jt->stptr); + DO(AN(jt->stnum), if(!pv[i]){pv[i]=ra(g); *(i+AV(jt->stnum))=n; break;}); + jt->stmax=n<IMAX?MAX(jt->stmax,1+n):-1; + break; + case 2: /* local symbol table */ + ; + } + R g; +} /* create locale, named (0==k) or numbered (1==k) */ + +B jtsymbinit(J jt){A q;I n=40; + jt->locsize[0]=3; /* default hash table size for named locales */ + jt->locsize[1]=2; /* default hash table size for numbered locales */ + RZ(symext(0)); /* initialize symbol pool */ + GA(q,SYMB,ptab[3],1,0); jt->stloc=q; + RZ(q=apv(n,-1L,0L)); jt->stnum=q; + GA(q,INT,n,1,0); jt->stptr=q; memset(AV(q),C0,n*SZI); + RZ(jt->global=stcreate(0,5L,4L,"base")); + RZ( stcreate(0,7L,1L,"z" )); + R 1; +} + + +F1(jtlocsizeq){I*v; ASSERTMTV(w); v=jt->locsize; R v2(v[0],v[1]);} + /* 9!:38 default locale size query */ + +F1(jtlocsizes){I p,q,*v; + RZ(w); + ASSERT(1==AR(w),EVRANK); + ASSERT(2==AN(w),EVLENGTH); + RZ(w=vi(w)); v=AV(w); p=v[0]; q=v[1]; + ASSERT(0<=p&&0<=q,EVDOMAIN); + ASSERT(p<nptab&&q<nptab,EVLIMIT); + jt->locsize[0]=p; + jt->locsize[1]=q; + R mtm; +} /* 9!:39 default locale size set */ + + +static A jtstfindnum(J jt,B b,I k){A y;I j; + RZ(y=indexof(jt->stnum,sc(k))); j=*AV(y); + if(j<AN(jt->stnum))R*(j+AAV(jt->stptr)); + else if(b){ASSERT(k>=jt->stmax,EVLOCALE); R stcreate(1,jt->locsize[1],k,0L);} + else R 0; +} /* stfind for numbered locales */ + +A jtstfind(J jt,B b,I n,C*u){I old;L*v; + if(!n){n=4; u="base";} + if('9'>=*u)R stfindnum(b,strtol(u,NULL,10)); + else{ + old=jt->tbase+jt->ttop; v=probe(nfs(n,u),jt->stloc); tpop(old); + R v?v->val:b?stcreate(0,jt->locsize[0],n,u):0; +}} /* find the symbol table for locale u, create if b and non-existent */ + +static A jtvlocnl(J jt,B b,A w){A*wv,y;C*s;I i,m,n,wd; + RZ(w); + n=AN(w); + ASSERT(!n||BOX&AT(w),EVDOMAIN); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + for(i=0;i<n;++i){ + y=WVR(i); m=AN(y); s=CAV(y); + ASSERT(1>=AR(y),EVRANK); + ASSERT(m,EVLENGTH); + ASSERT(LIT&AT(y),EVDOMAIN); + if(b)ASSERTN(vlocnm(m,s),EVILNAME,nfs(m,s)); + } + R w; +} /* validate namelist of locale names */ + +static I jtprobenum(J jt,C*u){I j; + RE(j=i0(indexof(jt->stnum,sc((I)strtol(u,NULL,(I)10))))); + R j<AN(jt->stnum)?j:-1; +} /* probe for numbered locales */ + + +F1(jtlocnc){A*wv,y,z;C c,*u;I i,m,n,wd,*zv; + RZ(vlocnl(0,w)); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + for(i=0;i<n;++i){ + y=WVR(i); m=AN(y); u=CAV(y); c=*u; + if(!vlocnm(m,u))zv[i]=-2; + else if(c<='9') zv[i]=0<=probenum(u)?1:-1; + else zv[i]=probe(nfs(m,u),jt->stloc)?0:-1; + } + R z; +} /* 18!:0 locale name class */ + +static F1(jtlocnlx){A*pv,y,*yv,z;B*wv;C s[20];I m=0,n=0,*nv; + RZ(w=cvt(B01,w)); wv=BAV(w); DO(AN(w), m|=1+wv[i];); + if(1&m)z=nlsym(jt->stloc); + if(2&m){ + GA(y,BOX,jt->stused,1,0); yv=AAV(y); pv=AAV(jt->stptr); nv=AV(jt->stnum); + DO(AN(jt->stptr), if(pv[i]){sprintf(s,FMTI,nv[i]); + if(jt->nla[*s]){RZ(yv[n++]=cstr(s)); if(n==jt->stused)break;}}); + y=take(sc(n),y); + } + z=0==m?mtv:1==m?z:2==m?y:over(y,z); + R grade2(z,ope(z)); +} + +F1(jtlocnl1){memset(jt->nla,C1,256); R locnlx(w);} + /* 18!:1 locale name list */ + +F2(jtlocnl2){UC*u; + RZ(a&&w); + ASSERT(LIT&AT(a),EVDOMAIN); + memset(jt->nla,C0,256); + u=UAV(a); DO(AN(a),jt->nla[*u++]=1;); + R locnlx(w); +} /* 18!:1 locale name list */ + +static A jtlocale(J jt,B b,A w){A g,*wv,y;I wd; + RZ(vlocnl(1,w)); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(AN(w), y=WVR(i); RZ(g=stfind(b,AN(y),CAV(y)));); + R g; +} /* last locale (symbol table) from boxed locale names */ + +F1(jtlocpath1){A g; F1RANK(0,jtlocpath1,0); RZ(g=locale(1,w)); R LOCPATH(g);} + /* 18!:2 query locale path */ + +F2(jtlocpath2){A g,x; + F2RANK(1,0,jtlocpath2,0); + RZ( locale(1,a)); RZ(x=every(ravel(a),0L,jtravel)); + RZ(g=locale(1,w)); + fa(LOCPATH(g)); LOCPATH(g)=ra(x); + R mtm; +} /* 18!:2 set locale path */ + + +static F2(jtloccre){A g,y;C*s;I n,p,*u;L*v; + RZ(a&&w); + if(MARK&AT(a))p=jt->locsize[0]; else{RE(p=i0(a)); ASSERT(0<=p,EVDOMAIN); ASSERT(p<nptab,EVLIMIT);} + y=AAV0(w); n=AN(y); s=CAV(y); + if(v=probe(nfs(n,s),jt->stloc)){ + g=v->val; + u=1+AV(g); DO(AN(g)-1, ASSERT(!u[i],EVLOCALE);); + RZ(symfreeh(g,v)); + } + RZ(stcreate(0,p,n,s)); + R box(ca(y)); +} /* create a locale named w with hash table size a */ + +static F1(jtloccrenum){C s[20];I k=jt->stmax,p; + RZ(w); + if(MARK&AT(w))p=jt->locsize[1]; else{RE(p=i0(w)); ASSERT(0<=p,EVDOMAIN); ASSERT(p<nptab,EVLIMIT);} + RZ(stcreate(1,p,k,0L)); + sprintf(s,FMTI,k); + R box(cstr(s)); +} /* create a numbered locale with hash table size n */ + +F1(jtloccre1){ + RZ(w); + if(AN(w))R rank2ex(mark,vlocnl(1,w),0L,0L,0L,jtloccre); + ASSERT(1==AR(w),EVRANK); + R loccrenum(mark); +} /* 18!:3 create locale */ + +F2(jtloccre2){ + RZ(a&&w); + if(AN(w))R rank2ex(a,vlocnl(1,w),0L,0L,0L,jtloccre); + ASSERT(1==AR(w),EVRANK); + R rank1ex(a,0L,0L,jtloccrenum); +} /* 18!:3 create locale with specified hash table size */ + + +F1(jtlocswitch){A g; + ASSERT(!AR(w),EVRANK); + RZ(g=locale(1,w)); + jt->global=g; jt->stswitched=1; + R mtm; +} /* 18!:4 switch locale */ + +F1(jtlocname){A g=jt->global; + ASSERTMTV(w); + ASSERT(g,EVLOCALE); + R box(sfn(0,LOCNAME(g))); +} /* 18!:5 current locale name */ + +static SYMWALK(jtlocmap1,I,INT,18,3,1, + {I t=AT(d->val); + *zv++=i; + *zv++=t&NOUN?0:t&VERB?3:t&ADV?1:t&CONJ?2:t&SYMB?6:-2; + *zv++=(I)sfn(1,d->name);}) + +F1(jtlocmap){A g,q,x,y,*yv,z,*zv;I c=-1,d,j=0,m,*qv,*xv; + RZ(w); + ASSERT(!AR(w),EVRANK); + RE(g=equ(w,zero)?jt->stloc:equ(w,one)?jt->local:locale(0,w)); + ASSERT(g,EVLOCALE); + RZ(q=locmap1(g)); qv=AV(q); + m=*AS(q); + GA(x,INT,m*3,2,AS(q)); xv= AV(x); + GA(y,BOX,m, 1,0 ); yv=AAV(y); + DO(m, *xv++=d=*qv++; *xv++=j=c==d?1+j:0; *xv++=*qv++; c=d; *yv++=(A)*qv++;); + GA(z,BOX,2,1,0); zv=AAV(z); zv[0]=x; zv[1]=y; + R z; +} /* 18!:30 locale map */ + +static SYMWALK(jtredefg,B,B01,100,1,1,RZ(redef(mark,d))) + /* check for redefinition (erasure) of entire symbol table */ + +F1(jtlocexmark){A g,*pv,*wv,y,z;B b,c,*zv;C*u;I i,j,m,n,*nv,wd;L*v; + RZ(vlocnl(1,w)); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + nv=AV(jt->stnum); pv=AAV(jt->stptr); + GA(z,B01,n,AR(w),AS(w)); zv=BAV(z); + for(i=0;i<n;++i){ + zv[i]=1; y=WVR(i); g=0; m=AN(y); u=CAV(y); b='9'>=*u; + if(b){j=probenum(u); if(0<=j)g=pv[j]; } + else {v=probe(nfs(m,u),jt->stloc); if(v )g=v->val;} + if(g){ + c=1; + DO(1+jt->fcalli, if(g==jt->fcallg[i].g){jt->fcallg[i].flag=1+b; jt->fcallg[i].ptr=b?j:(I)v; c=0; break;}); + if(c){ + if(b){RZ(redefg(g)); RZ(symfreeh(g,0L)); pv[j]=0; nv[j]=-1; --jt->stused;} + else {RZ(redefg(g)); RZ(symfreeh(g,v ));} + if(g==jt->global)jt->global=0; + }}} + R z; +} /* 18!:55 destroy a locale (but only mark for destruction if on stack) */ + +B jtlocdestroy(J jt,I i){A g,*pv;B b;I j,*nv;L*v; + nv=AV(jt->stnum); pv=AAV(jt->stptr); + g=jt->fcallg[i].g; b=1==jt->fcallg[i].flag?0:1; + if(b){j=(I )jt->fcallg[i].ptr; RZ(redefg(g)); RZ(symfreeh(g,0L)); pv[j]=0; nv[j]=-1; --jt->stused;} + else {v=(L*)jt->fcallg[i].ptr; RZ(redefg(g)); RZ(symfreeh(g,v ));} + if(g==jt->global)jt->global=0; + R 1; +} /* destroy locale jt->callg[i] (marked earlier by 18!:55) */
new file mode 100644 --- /dev/null +++ b/sn.c @@ -0,0 +1,189 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Symbol Table: Names */ + +#include "j.h" + + +B jtvnm(J jt,I n,C*s){B b=0;C c,d,t;I j,k; + RZ(n); + c=*s; d=*(s+n-1); + if(jt->dotnames&&2==n&&'.'==d&&('m'==c||'n'==c||'u'==c||'v'==c||'x'==c||'y'==c))R 1; + RZ(CA==ctype[c]); + c='a'; + DO(n, d=c; c=s[i]; t=ctype[c]; RZ(t==CA||t==C9); if(c=='_'&&d=='_'&&!b&&i!=n-1){j=1+i; b=1;}); + if(c=='_'){DO(j=n-1, if('_'==s[--j])break;); k=n-j-2; R!b&&j&&(!k||vlocnm(k,s+j+1));} + if(!b)R 1; + k=2; DO(n-j, c=s[j+i]; if(2>k)k+='_'==c; else{RZ(CA==ctype[c]); k=0;}); + R !k; +} /* validate name s, return type or 0 if error */ + +B vlocnm(I n,C*s){C c,t; + if(!n)R 0; + DO(n, t=ctype[c=s[i]]; RZ(c!='_'&&(t==CA||t==C9));); + if(C9==ctype[*s]){RZ(1==n||'0'!=*s); DO(n, c=s[i]; RZ('0'<=c&&c<='9'););} + R 1; +} /* validate locale name */ + +A jtnfs(J jt,I n,C*s){A z;C c,f,*t;I m,p;NM*zv; + DO(n, if(' '!=*s)break; ++s; --n;); + t=s+n-1; + DO(n, if(' '!=*t)break; --t; --n;); + if((1==n||2==n&&'.'==s[1])&&strchr("mnuvxy",c=*s)){ + if(1==n)R c=='y'?ynam:c=='x'?xnam:c=='v'?vnam:c=='u'?unam:c=='n'?nnam:mnam; + else R c=='y'?ydot:c=='x'?xdot:c=='v'?vdot:c=='u'?udot:c=='n'?ndot:mdot; + } + ASSERT(n,EVILNAME); + GA(z,NAME,n,1,0); zv=NAV(z); + memcpy(zv->s,s,n); *(n+zv->s)=0; + f=0; m=n; p=0; + if('_'==*t){--t; while(s<t&&'_'!=*t)--t; f=NMLOC; p=n-2-(t-s); m=n-(2+p);} + else DO(n, if('_'==s[i]&&'_'==s[1+i]){ f=NMILOC; p=n-2-i; m=n-(2+p); break;}); + ASSERT(m<=255&&p<=255,EVLIMIT); + zv->flag=f; + zv->sn=0; zv->e=0; + zv->m=(UC)m; zv->hash=NMHASH(m,s); + R z; +} /* name from string */ + +A jtsfn(J jt,B b,A w){NM*v; RZ(w); v=NAV(w); R str(b?v->m:AN(w),v->s);} + /* string from name: 0=b full name; 1=b non-locale part of name */ + +F1(jtnfb){A y;C*s;I n; + RZ(w); + ASSERT(BOX&AT(w),EVDOMAIN); + ASSERT(!AR(w),EVRANK); + RZ(y=vs(ope(w))); + n=AN(y); s=CAV(y); + ASSERTN(vnm(n,s),EVILNAME,nfs(n,s)); + R nfs(n,s); +} /* name from scalar boxed string */ + +static F1(jtstdnm){C*s;I j,n,p,q; + RZ(w=vs(w)); + n=AN(w); s=CAV(w); + RZ(n); + j=0; DO(n, if(' '!=s[j++])break;); p=j-1; + j=n-1; DO(n, if(' '!=s[j--])break;); q=(n-2)-j; + RZ(vnm(n-(p+q),p+s)); + R nfs(n-(p+q),p+s); +} /* 0 result means error or invalid name */ + +F1(jtonm){A x,y; RZ(x=ope(w)); y=stdnm(x); ASSERTN(y,EVILNAME,nfs(AN(x),CAV(x))); R y;} + + +F1(jtnc){A*wv,x,y,z;I i,n,t,wd,*zv;L*v; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(!n||BOX&AT(w),EVDOMAIN); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + for(i=0;i<n;++i){ + x=0; + RE(y=stdnm(WVR(i))); + if(y&&(v=syrd(y,0L))){x=v->val; t=AT(x);} + zv[i]=!y?-2:!x?-1:t&NOUN?0:t&VERB?3:t&ADV?1:2; + } + R z; +} /* 4!:0 name class */ + + +static SYMWALK(jtnlxxx, A,BOX,20,1, jt->nla[*((UC*)NAV(d->name)->s)]&&jt->nlt&AT(d->val), + RZ(*zv++=sfn(1,d->name)) ) + + SYMWALK(jtnlsym, A,BOX,20,1, jt->nla[*((UC*)NAV(d->name)->s)], + RZ(*zv++=sfn(1,d->name)) ) + +static I nlmask[] = {NOUN,ADV,CONJ,VERB, MARK,MARK,SYMB,MARK}; + +static F1(jtnlx){A z=mtv;B b;I m=0,*v,x; + RZ(w=vi(w)); v=AV(w); + DO(AN(w), x=*v++; m|=nlmask[x<0||6<x?7:x];); + jt->nlt=m&RHS; b=1&&jt->nlt&RHS; + ASSERT(!(m&MARK),EVDOMAIN); + if(b )RZ(z=nlxxx(jt->global)); + if(b&&jt->local)RZ(z=over(nlxxx(jt->local),z)); + if(m&SYMB )RZ(z=over(nlsym(jt->stloc),z)); + R nub(grade2(z,ope(z))); +} + +F1(jtnl1){memset(jt->nla,C1,256L); R nlx(w);} + /* 4!:1 name list */ + +F2(jtnl2){UC*u; + RZ(a&&w); + ASSERT(LIT&AT(a),EVDOMAIN); + memset(jt->nla,C0,256L); + u=UAV(a); DO(AN(a),jt->nla[*u++]=1;); + R nlx(w); +} /* 4!:1 name list */ + + +F1(jtscind){A*wv,x,y,z;I n,wd,*zv;L*v; + RZ(w); + n=AN(w); + ASSERT(!n||BOX&AT(w),EVDOMAIN); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + DO(n, x=WVR(i); RE(y=stdnm(x)); ASSERTN(y,EVILNAME,nfs(AN(x),CAV(x))); v=syrd(y,0L); RESETERR; zv[i]=v?v->sn:-1;); + R z; +} /* 4!:4 script index */ + + +static A jtnch1(J jt,B b,A w,I*pm,A ch){A*v,x,y;C*s,*yv;I*e,i,k,m,p,wn;L*d; + RZ(w); + wn=AN(w); e=AV(w); /* locale */ + x=(A)(*e+jt->sympv)->name; p=AN(x); s=NAV(x)->s; /* locale name */ + m=*pm; v=AAV(ch)+m; /* result to appended to */ + for(i=1;i<wn;++i,++e)if(*e){ + d=*e+jt->sympv; + while(1){ + if(LCH&d->flag&&d->name&&d->val){ + d->flag^=LCH; + if(b){ + if(m==AN(ch)){RZ(ch=ext(0,ch)); v=m+AAV(ch);} + x=d->name; k=NAV(x)->m; + GA(y,LIT,k+2+p,1,0); yv=CAV(y); + MC(yv,NAV(x)->s,k); MC(1+k+yv,s,p); yv[k]=yv[1+k+p]='_'; + *v++=y; ++m; + }} + if(!d->next)break; + d=d->next+jt->sympv; + }} + *pm=m; + R ch; +} + +F1(jtnch){A ch,*pv;B b;I*e,i,m,n;L*d; + RZ(w=cvt(B01,w)); ASSERT(!AR(w),EVRANK); b=*BAV(w); + GA(ch,BOX,20,1,0); m=0; + if(jt->stch){ + n=AN(jt->stloc); e=1+AV(jt->stloc); pv=AAV(jt->stptr); + for(i=1;i<n;++i,++e)if(*e){ + d=*e+jt->sympv; + while(1){ + RZ(ch=nch1(b,d->val,&m,ch)); + if(!d->next)break; + d=d->next+jt->sympv; + }} + n=AN(jt->stptr); + DO(n, if(pv[i])RZ(ch=nch1(b,pv[i],&m,ch));); + } + jt->stch=b; + AN(ch)=*AS(ch)=m; + R grade2(ch,ope(ch)); +} /* 4!:5 names changed */ + + +F1(jtex){A*wv,y,z;B*zv;I i,n,wd;L*v; + RZ(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(!n||BOX&AT(w),EVDOMAIN); + GA(z,B01,n,AR(w),AS(w)); zv=BAV(z); + for(i=0;i<n;++i){ + RE(y=stdnm(WVR(i))); + zv[i]=1&&y; + if(y&&(v=syrd(y,0L))){if(jt->db)RZ(redef(mark,v)); nvrredef(v->val); RZ(symfree(v));} + } + R z; +} /* 4!:55 expunge */
new file mode 100644 --- /dev/null +++ b/t.c @@ -0,0 +1,171 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Table of Primitive Symbols */ + +#include "j.h" + + +C ctype[256]={ + 0, 0, 0, 0, 0, 0, 0, 0, 0, CS, 0, 0, 0, 0, 0, 0, /* 0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */ +CS, 0, 0, 0, 0, 0, 0, CQ, 0, 0, 0, 0, 0, 0, CD, 0, /* 2 !"#$%&'()*+,-./ */ +C9, C9, C9, C9, C9, C9, C9, C9, C9, C9, CC, 0, 0, 0, 0, 0, /* 3 0123456789:;<=>? */ + 0, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, /* 4 @ABCDEFGHIJKLMNO */ +CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, 0, 0, 0, 0, C9, /* 5 PQRSTUVWXYZ[\]^_ */ + 0, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, /* 6 `abcdefghijklmno */ +CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, CA, 0, 0, 0, 0, 0, /* 7 pqrstuvwxyz{|}~ */ +}; +/* 1 2 3 4 5 6 7 8 9 a b c d e f */ + +static B jtpdef(J jt,C id,I t,AF f1,AF f2,I m,I l,I r){A z;V*v; + GA(z,t,1,0,0); ACX(z); v=VAV(z); + v->f1=f1?f1:jtdomainerr1; /* monad C function */ + v->f2=f2?f2:jtdomainerr2; /* dyad C function */ + v->mr=m; /* monadic rank */ + v->lr=l; /* left rank */ + v->rr=r; /* right rank */ + v->fdep=1; /* function depth */ + v->id=id; /* spelling */ + pst[(UC)id]=z; /* other fields are zeroed in ga() */ + R 1; +} + +B jtpinit(J jt){A t;C*s; + MC(wtype,ctype,256L); wtype['N']=CN; wtype['B']=CB; + GA(alp,LIT,NALP,1,0); s=CAV(alp); DO(NALP,*s++=(C)i;); + /* a. */ pst[(UC)CALP ]=t=alp; ACX(t); + /* a: */ pst[(UC)CACE ]=t=ace=sc4(BOX,(I)mtv); ACX(t); + /* ( */ pst[(UC)CLPAR]=t=sc4(LPAR,0L); ACX(t); + /* ) */ pst[(UC)CRPAR]=t=sc4(RPAR,0L); ACX(t); + /* =. */ GA(t,ASGN,1,0,0); ACX(t); *CAV(t)=CASGN; pst[(UC)CASGN ]=t; + /* =: */ GA(t,ASGN,1,0,0); ACX(t); *CAV(t)=CGASGN; pst[(UC)CGASGN]=t; + + /* = */ pdef(CEQ, VERB, jtsclass, jteq, RMAX,0, 0 ); + /* =. */ /* see above */ + /* =: */ /* see above */ + /* < */ pdef(CBOX, VERB, jtbox, jtlt, RMAX,0, 0 ); + /* <. */ pdef(CFLOOR, VERB, jtfloor1, jtminimum,0, 0, 0 ); + /* <: */ pdef(CLE, VERB, jtdecrem, jtle, 0, 0, 0 ); + /* > */ pdef(COPE, VERB, jtope, jtgt, 0, 0, 0 ); + /* >. */ pdef(CCEIL, VERB, jtceil1, jtmaximum,0, 0, 0 ); + /* >: */ pdef(CGE, VERB, jtincrem, jtge, 0, 0, 0 ); + /* + */ pdef(CPLUS, VERB, jtconjug, jtplus, 0, 0, 0 ); + /* +. */ pdef(CPLUSDOT,VERB, jtrect, jtgcd, 0, 0, 0 ); + /* +: */ pdef(CPLUSCO, VERB, jtduble, jtnor, 0, 0, 0 ); + /* * */ pdef(CSTAR, VERB, jtsignum, jttymes, 0, 0, 0 ); + /* *. */ pdef(CSTARDOT,VERB, jtpolar, jtlcm, 0, 0, 0 ); + /* *: */ pdef(CSTARCO, VERB, jtsquare, jtnand, 0, 0, 0 ); + /* - */ pdef(CMINUS, VERB, jtnegate, jtminus, 0, 0, 0 ); + /* -. */ pdef(CNOT, VERB, jtnot, jtless, 0, RMAX,RMAX); + /* -: */ pdef(CHALVE, VERB, jthalve, jtmatch, 0, RMAX,RMAX); + /* % */ pdef(CDIV, VERB, jtrecip, jtdivide, 0, 0, 0 ); + /* %. */ pdef(CDOMINO, VERB, jtminv, jtmdiv, 2, RMAX,2 ); + /* %: */ pdef(CSQRT, VERB, jtsqroot, jtroot, 0, 0, 0 ); + /* ^ */ pdef(CEXP, VERB, jtexpn1, jtexpn2, 0, 0, 0 ); + /* ^. */ pdef(CLOG, VERB, jtlogar1, jtlogar2, 0, 0, 0 ); + /* ^: */ pdef(CPOWOP, CONJ, 0L, jtpowop, 0, 0, 0 ); + /* $ */ pdef(CDOLLAR, VERB, jtshapex, jtreitem, RMAX,1, RMAX); + /* $. */ pdef(CSPARSE, VERB, jtsparse1, jtsparse2,RMAX,RMAX,RMAX); + /* $: */ pdef(CSELF, VERB, jtself1, jtself2, RMAX,RMAX,RMAX); + /* ~ */ pdef(CTILDE, ADV, jtswap, 0L, 0, 0, 0 ); + /* ~. */ pdef(CNUB, VERB, jtnub, 0L, RMAX,0, 0 ); + /* ~: */ pdef(CNE, VERB, jtnubsieve,jtne, RMAX,0, 0 ); + /* | */ pdef(CSTILE, VERB, jtmag, jtresidue,0, 0, 0 ); + /* |. */ pdef(CREV, VERB, jtreverse, jtrotate, RMAX,1, RMAX); + /* |: */ pdef(CCANT, VERB, jtcant1, jtcant2, RMAX,1, RMAX); + /* . */ pdef(CDOT, CONJ, 0L, jtdot, 0, 0, 0 ); + /* .. */ pdef(CEVEN, CONJ, 0L, jteven, 0, 0, 0 ); + /* .: */ pdef(CODD, CONJ, 0L, jtodd, 0, 0, 0 ); + /* : */ pdef(CCOLON, CONJ, 0L, jtcolon, 0, 0, 0 ); + /* :. */ pdef(COBVERSE,CONJ, 0L, jtobverse,0, 0, 0 ); + /* :: */ pdef(CADVERSE,CONJ, 0L, jtadverse,0, 0, 0 ); + /* , */ pdef(CCOMMA, VERB, jtravel, jtover, RMAX,RMAX,RMAX); + /* ,* */ pdef(CAPIP, VERB, 0L, jtapip, 0, RMAX,RMAX); + /* ,. */ pdef(CCOMDOT, VERB, jttable, jtstitch, RMAX,RMAX,RMAX); + /* ,: */ pdef(CLAMIN, VERB, jtlamin1, jtlamin2, RMAX,RMAX,RMAX); + /* ; */ pdef(CSEMICO, VERB, jtraze, jtlink, RMAX,RMAX,RMAX); + /* ;. */ pdef(CCUT, CONJ, 0L, jtcut, 0, 0, 0 ); + /* ;: */ pdef(CWORDS, VERB, jtwords, jtfsm, 1, RMAX,RMAX); + /* # */ pdef(CPOUND, VERB, jttally, jtrepeat, RMAX,1, RMAX); + /* #. */ pdef(CBASE, VERB, jtbase1, jtbase2, 1, 1, 1 ); + /* #: */ pdef(CABASE, VERB, jtabase1, jtabase2, RMAX,1, 0 ); + /* ! */ pdef(CBANG, VERB, jtfact, jtoutof, 0, 0, 0 ); + /* !. */ pdef(CFIT, CONJ, 0L, jtfit, 0, 0, 0 ); + /* !: */ pdef(CIBEAM, CONJ, 0L, jtforeign,0, 0, 0 ); + /* / */ pdef(CSLASH, ADV, jtslash, 0L, 0, 0, 0 ); + /* /. */ pdef(CSLDOT, ADV, jtsldot, 0L, 0, 0, 0 ); + /* /: */ pdef(CGRADE, VERB, jtgrade1, jtgrade2, RMAX,RMAX,RMAX); + /* \ */ pdef(CBSLASH, ADV, jtbslash, 0L, 0, 0, 0 ); + /* \. */ pdef(CBSDOT, ADV, jtbsdot, 0L, 0, 0, 0 ); + /* \: */ pdef(CDGRADE, VERB, jtdgrade1, jtdgrade2,RMAX,RMAX,RMAX); + /* [ */ pdef(CLEFT, VERB, jtright1, jtleft2, RMAX,RMAX,RMAX); + /* [: */ pdef(CCAP, VERB, 0L, 0L, RMAX,RMAX,RMAX); + /* ] */ pdef(CRIGHT, VERB, jtright1, jtright2, RMAX,RMAX,RMAX); + /* { */ pdef(CLBRACE, VERB, jtcatalog, jtfrom, 1, 0, RMAX); + /* {. */ pdef(CHEAD, VERB, jthead, jttake, RMAX,1, RMAX); + /* {: */ pdef(CTAIL, VERB, jttail, 0L, RMAX,0, 0 ); + /* } */ pdef(CRBRACE, ADV, jtrbrace, 0L, 0, 0, 0 ); + /* }* */ pdef(CAMIP, ADV, jtamip, 0L, 0, 0, 0 ); + /* }* */ pdef(CCASEV, VERB, jtcasev, 0L, RMAX,RMAX,RMAX); + /* }. */ pdef(CBEHEAD, VERB, jtbehead, jtdrop, RMAX,1, RMAX); + /* }: */ pdef(CCTAIL, VERB, jtcurtail, 0L, RMAX,0, 0 ); + /* " */ pdef(CQQ, CONJ, 0L, jtqq, 0, 0, 0 ); + /* ". */ pdef(CEXEC, VERB, jtexec1, jtexec2, 1, RMAX,RMAX); + /* ": */ pdef(CTHORN, VERB, jtthorn1, jtthorn2, RMAX,1, RMAX); + /* ` */ pdef(CGRAVE, CONJ, 0L, jttie, 0, 0, 0 ); + /* `. */ /* undefined */ + /* `: */ pdef(CGRCO, CONJ, 0L, jtevger, 0, 0, 0 ); + /* @ */ pdef(CAT, CONJ, 0L, jtatop, 0, 0, 0 ); + /* @. */ pdef(CATDOT, CONJ, 0L, jtagenda, 0, 0, 0 ); + /* @: */ pdef(CATCO, CONJ, 0L, jtatco, 0, 0, 0 ); + /* & */ pdef(CAMP, CONJ, 0L, jtamp, 0, 0, 0 ); + /* &. */ pdef(CUNDER, CONJ, 0L, jtunder, 0, 0, 0 ); + /* &: */ pdef(CAMPCO, CONJ, 0L, jtampco, 0, 0, 0 ); + /* ? */ pdef(CQUERY, VERB, jtroll, jtdeal, 0, 0, 0 ); + /* ?. */ pdef(CQRYDOT, VERB, jtrollx, jtdealx, RMAX,0, 0 ); + /* ?: */ /* undefined */ + /* {:: */ pdef(CFETCH, VERB, jtmap, jtfetch, RMAX,1, RMAX); + /* }:: */ pdef(CEMEND, ADV, jtemend, 0L, 0, 0, 0 ); + /* &.: */ pdef(CUNDCO, CONJ, 0L, jtundco, 0, 0, 0 ); + /* a. */ /* see above */ + /* a: */ /* see above */ + /* A. */ pdef(CATOMIC, VERB, jtadot1, jtadot2, 1, 0, RMAX); + /* b. */ pdef(CBDOT, ADV, jtbdot, 0L, 0, 0, 0 ); + /* C. */ pdef(CCYCLE, VERB, jtcdot1, jtcdot2, 1, 1, RMAX); + /* d. */ pdef(CDDOT, CONJ, 0L, jtddot, 0, 0, 0 ); + /* D. */ pdef(CDCAP, CONJ, 0L, jtdcap, 0, 0, 0 ); + /* D: */ pdef(CDCAPCO, CONJ, 0L, jtdcapco, 0, 0, 0 ); + /* e. */ pdef(CEPS, VERB, jtrazein, jteps, RMAX,RMAX,RMAX); + /* E. */ pdef(CEBAR, VERB, 0L, jtebar, 0, RMAX,RMAX); + /* f. */ pdef(CFIX, ADV, jtfix, 0L, 0, 0, 0 ); + /* H. */ pdef(CHGEOM, CONJ, 0L, jthgeom, 0, 0, 0 ); + /* i. */ pdef(CIOTA, VERB, jtiota, jtindexof,1, RMAX,RMAX); + /* i: */ pdef(CICO, VERB, jtjico1, jtjico2, 0, RMAX,RMAX); + /* I. */ pdef(CICAP, VERB, jticap, jticap2, 1, RMAX,RMAX); + /* j. */ pdef(CJDOT, VERB, jtjdot1, jtjdot2, 0, 0, 0 ); + /* L. */ pdef(CLDOT, VERB, jtlevel1, 0L, RMAX,0, 0 ); + /* L: */ pdef(CLCAPCO, CONJ, 0L, jtlcapco, 0, 0, 0 ); + /* m. */ /* see above */ + /* M. */ pdef(CMCAP, ADV, jtmemo, 0L, 0, 0, 0 ); + /* n. */ /* see above */ + /* o. */ pdef(CCIRCLE, VERB, jtpix, jtcircle, 0, 0, 0 ); + /* p. */ pdef(CPOLY, VERB, jtpoly1, jtpoly2, 1, 1, 0 ); + /* p..*/ pdef(CPDERIV, VERB, jtpderiv1, jtpderiv2,1, 0, 1 ); + /* p: */ pdef(CPCO, VERB, jtprime, jtpco2, 0, RMAX,RMAX); + /* q: */ pdef(CQCO, VERB, jtfactor, jtqco2, 0, 0, 0 ); + /* r. */ pdef(CRDOT, VERB, jtrdot1, jtrdot2, 0, 0, 0 ); + /* s: */ pdef(CSCO, VERB, jtsb1, jtsb2, RMAX,RMAX,RMAX); + /* S: */ pdef(CSCAPCO, CONJ, 0L, jtscapco, 0, 0, 0 ); + /* t. */ pdef(CTDOT, ADV, jttdot, 0L, 0, 0, 0 ); + /* t: */ pdef(CTCO, ADV, jttco, 0L, 0, 0, 0 ); + /* T. */ pdef(CTCAP, CONJ, 0L, jttcap, 0, 0, 0 ); + /* u. */ /* see above */ + /* u: */ pdef(CUCO, VERB, jtuco1, jtuco2, RMAX,RMAX,RMAX); + /* v. */ /* see above */ + /* x. */ /* see above */ + /* x: */ pdef(CXCO, VERB, jtxco1, jtxco2, RMAX,RMAX,RMAX); + /* y. */ /* see above */ + + if(jt->jerr){printf("pinit failed; error %hhi\n", jt->jerr); R 0;} else R 1; +}
new file mode 100644 --- /dev/null +++ b/test/g0.ijs @@ -0,0 +1,298 @@ +NB. handling -0 (-0 on some systems) ------------------------------------ + +test=: 3 : 0 + assert. 1 1 1 -: 0=y + assert. 1 1 1 -: y=0 + assert. (3 3$1) -: =/~ y + assert. (3 3$1) -: =!.0/~ y + assert. 0 0 0 -: y + assert. 0 0 0 -:!.0 y + assert. 0 0 0 -: i. ~ y + assert. 0 0 0 -: i.!.0 ~ y + assert. 0 0 0 -: y i. ,y + assert. 0 0 0 -: y i.!.0 ,y + assert. 1 1 1 -: y e. [0 + assert. 1 1 1 -: y e.!.0 [0 + assert. '' -: y -. [ 0 + assert. '' -: y -.!.0[ 0 + assert. '0 0 0' -: ":y + 1 +) + +mac =: 3 = 9!:12 '' + +test 0 % 3 _4 _7 +test }: 0 % 3 _4 _7 3j4 +test ". mac{'_1e_307 0 1e_307 % 1e307',:'0 0 0' +test ". mac{'}:_1e_307 0 1e_307 123j456 % 1e307',:'0 0 0' +test ". mac{'_1e_307 0 1e_307 * 1e_307',:'0 0 0' + +'0' = , 6}.2 (3!:3) 0.07 _0 +'0' = , 7}.2 (3!:3) 3j47 _0 +'0' = , 6}.2 (3!:3) _1 ". '0.07 _0' +'0' = , 7}.2 (3!:3) _1 ". '3j47 _0' + +f=: 3 : 0 + t=. ($y)$-~0.5 + assert. -. (3!:3 t) -: 3!:3 y + assert. 0=y + assert. 0=!.0 y + assert. t -:!.0 y + assert. (3!:3 t) -: 3!:3 y NB. y changed to true 0 in place + 1 +) + +g=: 3 : 0 + t=. ($y)$-~0.5 + assert. -. (3!:3 t) -: 3!:3 y + assert. 0=y + assert. 0=!.0 y + assert. (0,#y) -: y i.!.0 o. 0 2 + assert. (3!:3 t) -: 3!:3 y NB. y changed to true 0 in place + 1 +) + +f x=: 0 % __ _5 0 5 _ +f x=: 5 5 _5 _5 % _ __ _ __ +g x=: 0 % __ _5 0 5 _ +g x=: 5 5 _5 _5 % _ __ _ __ + +__ __ 0 _ _ (-:!.0) 0 %~ __ _5 0 5 _ + + +NB. 0: to 9: ------------------------------------------------------------ + +0 -: 0: 1=?2 3 4$2 +0 -: 0: a.{~? 10##a. +0 -: 0: _20+?3 2$40 +0 -: 0: o. _20+?13$40 +0 -: 0: r.?13$40 + +0 -: (1=?2 3 4$2 ) 0: 1=?2 3 4$2 +0 -: (1=?2 3 4$2 ) 0: a.{~? 10##a. +0 -: (1=?2 3 4$2 ) 0: _20+?3 2$40 +0 -: (1=?2 3 4$2 ) 0: o. _20+?13$40 +0 -: (1=?2 3 4$2 ) 0: r.?13$40 + +0 -: (a.{~? 10##a. ) 0: 1=?2 3 4$2 +0 -: (a.{~? 10##a. ) 0: a.{~? 10##a. +0 -: (a.{~? 10##a. ) 0: _20+?3 2$40 +0 -: (a.{~? 10##a. ) 0: o. _20+?13$40 +0 -: (a.{~? 10##a. ) 0: r.?13$40 + +0 -: (_20+?3 2$40 ) 0: 1=?2 3 4$2 +0 -: (_20+?3 2$40 ) 0: a.{~? 10##a. +0 -: (_20+?3 2$40 ) 0: _20+?3 2$40 +0 -: (_20+?3 2$40 ) 0: o. _20+?13$40 +0 -: (_20+?3 2$40 ) 0: r.?13$40 + +0 -: (o. _20+?13$40) 0: 1=?2 3 4$2 +0 -: (o. _20+?13$40) 0: a.{~? 10##a. +0 -: (o. _20+?13$40) 0: _20+?3 2$40 +0 -: (o. _20+?13$40) 0: o. _20+?13$40 +0 -: (o. _20+?13$40) 0: r.?13$40 + +0 -: (r.?13$40 ) 0: 1=?2 3 4$2 +0 -: (r.?13$40 ) 0: a.{~? 10##a. +0 -: (r.?13$40 ) 0: _20+?3 2$40 +0 -: (r.?13$40 ) 0: o. _20+?13$40 +0 -: (r.?13$40 ) 0: r.?13$40 + +1 -: 1: 1=?2 3 4$2 +1 -: 1: a.{~? 10##a. +1 -: 1: _20+?3 2$40 +1 -: 1: o. _20+?13$40 +1 -: 1: r.?13$40 + +1 -: (1=?2 3 4$2 ) 1: 1=?2 3 4$2 +1 -: (1=?2 3 4$2 ) 1: a.{~? 10##a. +1 -: (1=?2 3 4$2 ) 1: _20+?3 2$40 +1 -: (1=?2 3 4$2 ) 1: o. _20+?13$40 +1 -: (1=?2 3 4$2 ) 1: r.?13$40 + +1 -: (a.{~? 10##a. ) 1: 1=?2 3 4$2 +1 -: (a.{~? 10##a. ) 1: a.{~? 10##a. +1 -: (a.{~? 10##a. ) 1: _20+?3 2$40 +1 -: (a.{~? 10##a. ) 1: o. _20+?13$40 +1 -: (a.{~? 10##a. ) 1: r.?13$40 + +1 -: (_20+?3 2$40 ) 1: 1=?2 3 4$2 +1 -: (_20+?3 2$40 ) 1: a.{~? 10##a. +1 -: (_20+?3 2$40 ) 1: _20+?3 2$40 +1 -: (_20+?3 2$40 ) 1: o. _20+?13$40 +1 -: (_20+?3 2$40 ) 1: r.?13$40 + +1 -: (o. _20+?13$40) 1: 1=?2 3 4$2 +1 -: (o. _20+?13$40) 1: a.{~? 10##a. +1 -: (o. _20+?13$40) 1: _20+?3 2$40 +1 -: (o. _20+?13$40) 1: o. _20+?13$40 +1 -: (o. _20+?13$40) 1: r.?13$40 + +1 -: (r.?13$40 ) 1: 1=?2 3 4$2 +1 -: (r.?13$40 ) 1: a.{~? 10##a. +1 -: (r.?13$40 ) 1: _20+?3 2$40 +1 -: (r.?13$40 ) 1: o. _20+?13$40 +1 -: (r.?13$40 ) 1: r.?13$40 + +2 -: 2: 1=?2 3 4$2 +2 -: 2: a.{~? 10##a. +2 -: 2: _20+?3 2$40 +2 -: 2: o. _20+?13$40 +2 -: 2: r.?13$40 + +2 -: (1=?2 3 4$2 ) 2: 1=?2 3 4$2 +2 -: (1=?2 3 4$2 ) 2: a.{~? 10##a. +2 -: (1=?2 3 4$2 ) 2: _20+?3 2$40 +2 -: (1=?2 3 4$2 ) 2: o. _20+?13$40 +2 -: (1=?2 3 4$2 ) 2: r.?13$40 + +2 -: (a.{~? 10##a. ) 2: 1=?2 3 4$2 +2 -: (a.{~? 10##a. ) 2: a.{~? 10##a. +2 -: (a.{~? 10##a. ) 2: _20+?3 2$40 +2 -: (a.{~? 10##a. ) 2: o. _20+?13$40 +2 -: (a.{~? 10##a. ) 2: r.?13$40 + +2 -: (_20+?3 2$40 ) 2: 1=?2 3 4$2 +2 -: (_20+?3 2$40 ) 2: a.{~? 10##a. +2 -: (_20+?3 2$40 ) 2: _20+?3 2$40 +2 -: (_20+?3 2$40 ) 2: o. _20+?13$40 +2 -: (_20+?3 2$40 ) 2: r.?13$40 + +2 -: (o. _20+?13$40) 2: 1=?2 3 4$2 +2 -: (o. _20+?13$40) 2: a.{~? 10##a. +2 -: (o. _20+?13$40) 2: _20+?3 2$40 +2 -: (o. _20+?13$40) 2: o. _20+?13$40 +2 -: (o. _20+?13$40) 2: r.?13$40 + +2 -: (r.?13$40 ) 2: 1=?2 3 4$2 +2 -: (r.?13$40 ) 2: a.{~? 10##a. +2 -: (r.?13$40 ) 2: _20+?3 2$40 +2 -: (r.?13$40 ) 2: o. _20+?13$40 +2 -: (r.?13$40 ) 2: r.?13$40 + +9 -: 9: 1=?2 3 4$2 +9 -: 9: a.{~? 10##a. +9 -: 9: _20+?3 2$40 +9 -: 9: o. _20+?13$40 +9 -: 9: r.?13$40 + +9 -: (1=?2 3 4$2 ) 9: 1=?2 3 4$2 +9 -: (1=?2 3 4$2 ) 9: a.{~? 10##a. +9 -: (1=?2 3 4$2 ) 9: _20+?3 2$40 +9 -: (1=?2 3 4$2 ) 9: o. _20+?13$40 +9 -: (1=?2 3 4$2 ) 9: r.?13$40 + +9 -: (a.{~? 10##a. ) 9: 1=?2 3 4$2 +9 -: (a.{~? 10##a. ) 9: a.{~? 10##a. +9 -: (a.{~? 10##a. ) 9: _20+?3 2$40 +9 -: (a.{~? 10##a. ) 9: o. _20+?13$40 +9 -: (a.{~? 10##a. ) 9: r.?13$40 + +9 -: (_20+?3 2$40 ) 9: 1=?2 3 4$2 +9 -: (_20+?3 2$40 ) 9: a.{~? 10##a. +9 -: (_20+?3 2$40 ) 9: _20+?3 2$40 +9 -: (_20+?3 2$40 ) 9: o. _20+?13$40 +9 -: (_20+?3 2$40 ) 9: r.?13$40 + +9 -: (o. _20+?13$40) 9: 1=?2 3 4$2 +9 -: (o. _20+?13$40) 9: a.{~? 10##a. +9 -: (o. _20+?13$40) 9: _20+?3 2$40 +9 -: (o. _20+?13$40) 9: o. _20+?13$40 +9 -: (o. _20+?13$40) 9: r.?13$40 + +9 -: (r.?13$40 ) 9: 1=?2 3 4$2 +9 -: (r.?13$40 ) 9: a.{~? 10##a. +9 -: (r.?13$40 ) 9: _20+?3 2$40 +9 -: (r.?13$40 ) 9: o. _20+?13$40 +9 -: (r.?13$40 ) 9: r.?13$40 + +f=: 3: 4: 5: +4 -: 'abc' f ?3 4$1000 + + +NB. 0: to 9: encore ----------------------------------------------------- + +dr =: 5!:2 +rk =: 1 : ('f=.+"x'; '>2{ dr <''f''') + +_ _ _ -: 0: rk +_ _ _ -: 1: rk +_ _ _ -: 2: rk +_ _ _ -: 3: rk +_ _ _ -: 4: rk +_ _ _ -: 5: rk +_ _ _ -: 6: rk +_ _ _ -: 7: rk +_ _ _ -: 8: rk +_ _ _ -: 9: rk + +fx =: 5!:0 +ar =: 5!:1 +dr =: 5!:2 +tr =: 5!:4 +lr =: 5!:5 + +eq =: 2 : '''x'' -:&ar&< ''y''' + +(,&':'@":&.>i.10) -: 0:`1:`2:`3:`4:`5:`6:`7:`8:`9: + +f =: 1 : 'dr <''x''' + +(,<'_9:') -: _9: f +(,<'_1:') -: _1: f +(,<'0:' ) -: 0: f +(,<'1:' ) -: 1: f +(,<'2:' ) -: 2: f +(,<'3:' ) -: 3: f +(,<'4:' ) -: 4: f +(,<'5:' ) -: 5: f +(,<'6:' ) -: 6: f +(,<'7:' ) -: 7: f +(,<'8:' ) -: 8: f +(,<'9:' ) -: 9: f + +f =: 1 : '5!:5 <''x''' + +'_9:' -: _9: f +'_1:' -: _1: f +'0:' -: 0: f +'1:' -: 1: f +'9:' -: 9: f + +(ar <'zero' ) fx eq zero =: 0: +(ar <'one' ) fx eq one =: 1: +(ar <'two' ) fx eq two =: 2: +(ar <'three') fx eq three =: 3: +(ar <'four' ) fx eq four =: 4: +(ar <'five' ) fx eq five =: 5: +(ar <'six' ) fx eq six =: 6: +(ar <'seven') fx eq seven =: 7: +(ar <'eight') fx eq eight =: 8: +(ar <'nine' ) fx eq nine =: 9: + +f =: 1 : 'lr <''x''' + +'0:' -: 0: f +'1:' -: 1: f +'2:' -: 2: f +'3:' -: 3: f +'4:' -: 4: f +'5:' -: 5: f +'6:' -: 6: f +'7:' -: 7: f +'8:' -: 8: f +'9:' -: 9: f + +g =: 3: 4: 5: +('3:';'4:';'5:') -: dr <'g' +'3: 4: 5:' -: lr <'g' + +1 = 3!:0 0: 'a' +1 = 3!:0 1: 'a' +4 = 3!:0 2: 'a' + + +4!:55 ;:'ar dr eight eq f five four fx g lr ' +4!:55 ;:'mac nine one rk seven six test three tr two x z zero ' + +
new file mode 100644 --- /dev/null +++ b/test/g000.ijs @@ -0,0 +1,91 @@ +NB. =y ------------------------------------------------------------------ + +(,.1) -: =1 +(,.1) -: ='a' +(,.1) -: =3 +(,.1) -: =4.5 +(,.1) -: =3j4 +(,.1) -: =<'abc' + +(i.0 0) -: =0 4 5$1 +(i.0 0) -: ='' +(i.0 0) -: =i.0 +(i.0 0) -: =o.i.0 +(i.0 0) -: =0 4 5 6 7 0$<'' + +(1 5$1) -: =5$1 +(1 5$1) -: =5$'a' +(1 5$1) -: =5$12345 +(1 5$1) -: =5$3.14159 +(1 5$1) -: =5$3j4 +(1 5$1) -: =5$<'abc' + +((n,n)$1,n$0)-:=i.n=:?25 + +test =: 3 : '(1=type b) , (($b)-:(#~.y),#y) , (+/,b)=#y [ b=.=y' + +test x=:?2 +test x=:a.{~?2$3 +test x=:?4023 +test x=:o.?4023 +test x=:j./?2$3 +test x=:(;:'foo upon thee'){~?3 + +test x=:?40 3$2 +test x=:a.{~50+?40 2$3 +test x=:?40 2$3 +test x=:o.?40 2$3 +test x=:j./?2 82 2$3 +test x=:(;:'foo upon thee'){~?40 2$3 + + +NB. x=y ----------------------------------------------------------------- + +NB. Boolean +1 0 0 1 -: 0 0 1 1=0 1 0 1 + +NB. literal +(($t)$1) -: t = t=:a.{~?2 3 4$#a. +(($t)$0) -: (?($t)$2) = t=:a.{~?2 3 4$#a. +(($t)$0) -: (_5e8+?($t)$1e9) = t=:a.{~?2 3 4$#a. +(($t)$0) -: (o._5e8+?($t)$1e9) = t=:a.{~?2 3 4$#a. +(($t)$0) -: (r._5e6+?($t)$1e8) = t=:a.{~?2 3 4$#a. +(($t)$0) -: (($t)$;:'8-+.abc') = t=:a.{~?2 3 4$#a. + +NB. integer +(($t)$1) -: t = t=:_1e9+?2 3 4$2e9 +(a=b)-:0=a-b [ a=:_5+?200$10 [ b=:_5+?200$10 +(a=b)-:a=b{0 1 2 [ a=:(?100$2){0 1 2 [ b=:?100$2 +(a=b)-:a=}.3.4,b [ a=:?200$10 [ b=:?200$10 + +NB. real +(($t)$1) -: t = t=:o._1e9+?2 3 4$2e9 +(a=b)-:0=a-b [ a=:o._5+?200$10 [ b=:o._5+?200$10 +(a=b)-:a=}.3.4,b [ a=:}.3.4,?100$2 [ b=:?100$2 +(a=b)-:a=}.3.4,b [ a=:}.3.4,_5+?200$10 [ b=:_5+?200$10 +(a=b)-:a=}.3j4,b [ a=:o._5+?200$10 [ b=:o._5+?200$10 + +NB. complex +(($t)$1) -: t = t=:j./_1e9+?2 3 4$2e9 +(a=b)-:0=a-b [ a=:r._5+?200$10 [ b=:r._5+?200$10 +(a=b)-:a=}.3j4,b [ a=:}.3j4,?100$2 [ b=:?100$2 +(a=b)-:a=}.3j4,b [ a=:}.3j4,_5+?200$10 [ b=:_5+?200$10 +(a=b)-:a=}.3j4,b [ a=:}.3j4,o._5+?200$10 [ b=:o._5+?200$10 + +NB. boxed +(($t)$1) -: t = t=:<"1?2 3 4 5$10 +(($t)$0) -: (?($t)$2) = t=:<"1?2 3 4$10 +(($t)$0) -: (($t)$'8-+.abc') = t=:<"1?2 3 4$10 +(($t)$0) -: (_5e8+?($t)$1e9) = t=:<"1?2 3 4$10 +(($t)$0) -: (o._5e8+?($t)$1e9) = t=:<"1?2 3 4$10 +(($t)$0) -: (r._5e6+?($t)$1e8) = t=:<"1?2 3 4$10 + +'length error' -: 3 4 = etx 5 6 7 +'length error' -: 3 4 =~etx 5 6 7 +'length error' -: (i.3 4) = etx i.5 4 +'length error' -: (i.3 4) =~etx i.5 4 + + +4!:55 ;:'a b n t test x' + +
new file mode 100644 --- /dev/null +++ b/test/g000a.ijs @@ -0,0 +1,141 @@ +NB. B = B --------------------------------------------------------------- + +x=: ?100$2 +y=: ?100$2 +(x=y) -: (#.x,.y){1 0 0 1 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:?2 +(x=z) -: x=($x)$z [ z=:?2 + +(x=y) -: (40$"0 x)=y [ x=: ?10$2 [ y=: ?10 40$2 +(x=y) -: x=40$"0 y [ x=: ?10 40$2 [ y=: ?10$2 + +1 0 0 1 -: 0 0 1 1 = 0 1 0 1 + + +NB. B = I --------------------------------------------------------------- + +x=: ?100$2 +y=: _1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:?2 +(x=z) -: x=($x)$z [ z=:_1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: ?10$2 [ y=: _1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: ?10 40$2 [ y=: _1e2+?10$2e2 + +1 0 0 1 0 0 0 0 -: 0 0 1 1 0 0 1 1 = 0 1 0 1 _4 3 4 _3 + + +NB. B = D --------------------------------------------------------------- + +x=: ?100$2 +y=: o._1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:?2 +(x=z) -: x=($x)$z [ z=:o._1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: ?10$2 [ y=: o._1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: ?10 40$2 [ y=: o._1e2+?10$2e2 + +1 0 0 1 0 0 0 0 -: 0 0 1 1 0 0 1 1 = 0 1 0 1 _2.5 1.2 _2.5 1.2 +1 0 0 1 0 0 0 0 -: 0 0 1 1 0 0 1 1 = 0 1 0 1 __ _ __ _ +(14 6#0 1) -: 1=1+10^-i.20 + + +NB. I = B --------------------------------------------------------------- + +x=: _1e2+?100$2e2 +y=: ?100$2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:_1e2+?2e2 +(x=z) -: x=($x)$z [ z=:?2 + +(x=y) -: (40$"0 x)=y [ x=: _1e2+?10$2e2 [ y=: ?10 40$2 +(x=y) -: x=40$"0 y [ x=: _1e2+?10 40$2e2 [ y=: ?10$2 + +1 0 0 1 0 0 0 0 -: 0 0 1 1 _3 _3 4 4 = 0 1 0 1 0 1 0 1 +0 0 0 0 -: 2147483647 2147483647 _2147483648 _2147483648 = 0 1 0 1 + + +NB. I = I --------------------------------------------------------------- + +x=: _1e2+?100$2e2 +y=: _1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:?2e6 +(x=z) -: x=($x)$z [ z=:_1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: _1e2+?10$2e2 [ y=: _1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: _1e2+?10 40$2e2 [ y=: _1e2+?10$2e2 + +(_10{.1) -: 9=i.10 + + +NB. I = D --------------------------------------------------------------- + +x=: _1e2+?100$2e2 +y=: o._1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:?2e6 +(x=z) -: x=($x)$z [ z=:o._1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: _1e2+?10$2e2 [ y=: o._1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: _1e2+?10 40$2e2 [ y=: o._1e2+?10$2e2 + +(14 6#0 1) -: 17=17*1+10^-i.20 + + +NB. D = B --------------------------------------------------------------- + +x=: o._1e2+?100$2e2 +y=: ?100$2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:o._1e2+?2e2 +(x=z) -: x=($x)$z [ z=:?2 + +(x=y) -: (40$"0 x)=y [ x=: o._1e2+?10$2e2 [ y=: ?10 40$2 +(x=y) -: x=40$"0 y [ x=: o._1e2+?10 40$2e2 [ y=: ?10$2 + +(14 6#0 1) -: (1+10^-i.20)=1 + + +NB. D = I --------------------------------------------------------------- + +x=: o._1e2+?100$2e2 +y=: _1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:o._1e2+?2e2 +(x=z) -: x=($x)$z [ z=:_1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: o._1e2+?10$2e2 [ y=: _1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: o._1e2+?10 40$2e2 [ y=: _1e2+?10$2e2 + +(14 6#0 1) -: (17*1+10^-i.20)=17 + + +NB. D = D --------------------------------------------------------------- + +x=: o._1e2+?100$2e2 +y=: o._1e2+?100$2e2 +(x=y) -: (z+x)=z+y [ z=:{.0 4.5 +(x=y) -: (z*x)=z*y [ z=:{.1 4j5 +(z=y) -: (($y)$z)=y [ z=:o._1e2+?2e2 +(x=z) -: x=($x)$z [ z=:o._1e2+?2e2 + +(x=y) -: (40$"0 x)=y [ x=: o._1e2+?10$2e2 [ y=: o._1e2+?10 40$2e2 +(x=y) -: x=40$"0 y [ x=: o._1e2+?10 40$2e2 [ y=: o._1e2+?10$2e2 + +(14 6#0 1) -: _17.4=_17.4*1+10^-i.20 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g000i.ijs @@ -0,0 +1,46 @@ +NB. =/ B --------------------------------------------------------------- + +1 0 0 1 -: =/ 0 0 1 1 ,: 0 1 0 1 + +eq=: 4 : 'x=y' + +(=/"1 -: eq/"1) x=:?3 5 17$2 +(=/"2 -: eq/"2) x +(=/"3 -: eq/"3) x + +(=/"1 -: eq/"1) x=:?3 5 32$2 +(=/"2 -: eq/"2) x +(=/"3 -: eq/"3) x + +(=/"1 -: eq/"1) x=:?3 8 32$2 +(=/"2 -: eq/"2) x +(=/"3 -: eq/"3) x + +f=: 3 : '(=/ -: eq/) ?y$2' +,f"1 x=:7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +(eq/"1 -: =/"1) #: i.2^6 +(eq/"1 -: =/"1) #: i.2^7 +(eq/"1 -: =/"1) #: i.2^8 +(eq/"1 -: =/"1) #: i.2^9 + +(eq/ -: =/ ) |: #: i.2^6 +(eq/ -: =/ ) |: #: i.2^7 +(eq/ -: =/ ) |: #: i.2^8 +(eq/ -: =/ ) |: #: i.2^9 + +(eq/"1 -: =/"1) 1 ,"1 #: i.2^6 +(eq/"1 -: =/"1) 1 1 ,"1 #: i.2^6 +(eq/"1 -: =/"1) 1 1 1,"1 #: i.2^6 + +(eq/ -: =/ ) |: 1 ,"1 #: i.2^6 +(eq/ -: =/ ) |: 1 1 ,"1 #: i.2^6 +(eq/ -: =/ ) |: 1 1 1,"1 #: i.2^6 + + +4!:55 ;:'f eq x' + +
new file mode 100644 --- /dev/null +++ b/test/g000p.ijs @@ -0,0 +1,91 @@ +NB. =/\ B --------------------------------------------------------------- + +(0 0 1 1,:1 0 0 1) -: =/\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: =/\20$1 +(20$0 1) -: =/\20$0 + +eq=: 4 : 'x=y' +eqscan=: 2&|@(+/\)&.(-."_) + +(=/\ -: eq/\ ) x=:? 13$2 +(=/\ -: eq/\ ) x=:?4 13$2 +(=/\"1 -: eq/\"1) x +(=/\ -: eq/\ ) x=:?3 5 13$2 +(=/\"1 -: eq/\"1) x +(=/\"2 -: eq/\"2) x + +(=/\ -: eqscan ) x=:? 32$2 +(=/\ -: eqscan ) x=:?4 32$2 +(=/\"1 -: eqscan"1) x +(=/\ -: eqscan ) x=:?4 8 32$2 +(=/\"1 -: eqscan"1) x +(=/\"2 -: eqscan"2) x + +(=/\ -: eqscan ) x=:? 23$2 +(=/\ -: eqscan ) x=:?5 23$2 +(=/\"1 -: eqscan"1) x +(=/\ -: eqscan ) x=:?5 7 23$2 +(=/\"1 -: eqscan"1) x +(=/\"2 -: eqscan"2) x + +f=: 3 : '(=/\ -: eqscan) ?y$2' +,f"1 x=:7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. =/\ I --------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\ -: eq/\) x=:1 2 3 1e9 2e9 +(=/\ -: eq/\) |.x + +(=/\ -: eq/\ ) x=:_1e4+? 13$2e4 +(=/\ -: eq/\ ) x=:_1e4+?4 13$2e4 +(=/\"1 -: eq/\"1) x +(=/\ -: eq/\ ) x=:_1e4+?3 5 13$2e4 +(=/\"1 -: eq/\"1) x +(=/\"2 -: eq/\"2) x + +(=/\ -: eq/\ ) x=:_1e9+? 13$2e9 +(=/\ -: eq/\ ) x=:_1e9+?4 13$2e9 +(=/\"1 -: eq/\"1) x +(=/\ -: eq/\ ) x=:_1e9+?3 5 13$2e9 +(=/\"1 -: eq/\"1) x +(=/\"2 -: eq/\"2) x + + +NB. =/\ D --------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\ -: eq/\ ) x=:0.01*_1e4+? 13$2e4 +(=/\ -: eq/\ ) x=:0.01*_1e4+?4 13$2e4 +(=/\"1 -: eq/\"1) x +(=/\ -: eq/\ ) x=:0.01*_1e4+?3 5 13$2e4 +(=/\"1 -: eq/\"1) x +(=/\"2 -: eq/\"2) x + + +NB. =/\ Z --------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\ -: eq/\ ) x=:[&.j. 0.1*_1e2+?2 13$2e2 +(=/\ -: eq/\ ) x=:[&.j. 0.1*_1e2+?2 4 13$2e2 +(=/\"1 -: eq/\"1) x +(=/\ -: eq/\ ) x=:[&.j. 0.1*_1e2+?2 3 5 13$2e2 +(=/\"1 -: eq/\"1) x +(=/\"2 -: eq/\"2) x + +(,'j') -: =/\'j' +(,<'ace') -: =/\<'ace' + +'domain error' -: =/\ etx 'deipnosophist' +'domain error' -: =/\ etx ;:'peace in our time' + +4!:55 ;:'eq eqscan f x' + +
new file mode 100644 --- /dev/null +++ b/test/g000s.ijs @@ -0,0 +1,64 @@ +NB. =/\. B ------------------------------------------------------------- + +(1 0 0 1,:0 1 0 1) -: =/\. 0 0 1 1 ,: 0 1 0 1 + +eq=: 4 : 'x=y' + +f=: 3 : '(=/\. -: eq/\.) ?y$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. =/\. I ------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\. -: eq/\.) x=.1 2 3 1e9 2e9 +(=/\. -: eq/\.) |.x + +(=/\. -: eq/\. ) x=._1e4+? 23$2e4 +(=/\. -: eq/\. ) x=._1e4+?4 23$2e4 +(=/\."1 -: eq/\."1) x +(=/\. -: eq/\. ) x=._1e4+?7 5 23$2e4 +(=/\."1 -: eq/\."1) x +(=/\."2 -: eq/\."2) x + +(=/\. -: eq/\. ) x=._1e9+? 23$2e9 +(=/\. -: eq/\. ) x=._1e9+?4 23$2e9 +(=/\."1 -: eq/\."1) x +(=/\. -: eq/\. ) x=._1e9+?7 5 23$2e9 +(=/\."1 -: eq/\."1) x +(=/\."2 -: eq/\."2) x + + +NB. =/\. D ------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\. -: eq/\. ) x=.0.01*_1e4+? 23$2e4 +(=/\. -: eq/\. ) x=.0.01*_1e4+?4 23$2e4 +(=/\."1 -: eq/\."1) x +(=/\. -: eq/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(=/\."1 -: eq/\."1) x +(=/\."2 -: eq/\."2) x + + +NB. =/\. Z ------------------------------------------------------------- + +eq=: 4 : 'x=y' + +(=/\. -: eq/\. ) x=.r. 0.1*_1e2+?2 23$2e2 +(=/\. -: eq/\. ) x=.r. 0.1*_1e2+?2 4 23$2e2 +(=/\."1 -: eq/\."1) x +(=/\. -: eq/\. ) x=.r. 0.1*_1e2+?2 7 5 23$2e2 +(=/\."1 -: eq/\."1) x +(=/\."2 -: eq/\."2) x + +'domain error' -: =/\. etx 'deipnosophist' +'domain error' -: =/\. etx ;:'professors in New England' + +4!:55 ;:'f eq x' + +
new file mode 100644 --- /dev/null +++ b/test/g001.ijs @@ -0,0 +1,209 @@ +NB. =. and =: ----------------------------------------------------------- + +erase =: 4!:55 +local =: 4 : '(x)=.y' +global =: 4 : '(x)=:y' + +a =: 1 2 3 +aa =: 'foo upon thee' +a -: 1 2 3 +aa -: 'foo upon thee' +erase <'a' +aa -: 'foo upon thee' +aa =: i.4 3 +aa -: i.4 3 + +a =: 3.14 +alta =: b =: 'first and last letter' +erase <'a' +alta -: b + +Ich_liebe_dich =: 'Je t''aime.' +(#Ich_liebe_dich) -: 0{$Ich_liebe_dich + +('first';'second';'third') =: 'Cogito'; 'ergo'; i.12 +first -: 'Cogito' +second -: 'ergo' +third -: i.12 + +('a_man';'j_k') =: 123 456 +a_man -: 123 +j_k -: 456 + +names =: ' abc def ghi' +0 0$ (names) =: i. 3 3 +(".;.1 names) -: i. 3 3 +4!:55 ;: names + +'p q r' =: <"_1 i.3 4 +p -: 0 + i.4 +q -: 4 + i.4 +r -: 8 + i.4 + +'abc' -: 'p q r' local 'abc' +p -: 0 + i.4 +q -: 4 + i.4 +r -: 8 + i.4 + +'abc' -: 'p q r' global 'abc' +p -: 'a' +q -: 'b' +r -: 'c' + +'p' =: i.12 +p -: i.12 +(<'abc') =: x=: ?4 5$100 +abc -: x + +0 0$ ('p';'q';'r') =: o.4 5 6 +p -: o.4 +q -: o.5 +r -: o.6 + +'p q r' =: <'Ich liebe dich' +p -: 'Ich liebe dich' +p -: q +p -: r + +'Cogito ergo sum'=:i.3 4 +Cogito -: i.4 +ergo -: 4+i.4 +sum -: 8+i.4 + +'abc'=: i.7 +abc -: i.7 + +NB. The following lines generate no display + +a=:12 +'a'=:12 + +'domain error' -: ". etx '2 3 =. 9' +'domain error' -: ". etx '3.5 =. 9' +'domain error' -: ". etx '3j4 =. 9' + +'ill-formed number' -: ". etx '_abc =. 9' + +'ill-formed name' -: ". etx '''p+9'' =. 9' +'ill-formed name' -: ". etx '''3ab'' =. 9' + +'domain error' -: ". etx '(''p'';2 3 ) =. 9' +'domain error' -: ". etx '(''p'';3.5 ) =. 9' +'domain error' -: ". etx '(''p'';3j4 ) =. 9' + +'ill-formed name' -: ". etx '(''p'';''p+9'') =. 9' +'ill-formed name' -: ". etx '(''p'';''3ab'') =. 9' +'ill-formed name' -: ". etx '(''p'';''_ab'') =. 9' +'ill-formed name' -: ". etx ''' '' =. 9' +'ill-formed name' -: ". etx '(''p'';'''') =. 9' + +'rank error' -: ". etx '(<3 4$''a'') =. i.3 4' +'rank error' -: ". etx '(''p'';3 4$''a'') =. 9' + +'length error' -: ". etx '''pqr s'' =. 4 5 6' +'length error' -: ". etx '(''p'';''q'';''r'') =. 4 5' +'length error' -: ". etx '(,<''abc'') =. i.5' + +4!:55 ;:'Cogito a abc ergo p q r sum x' +4!:55 ;:'Cogito a abc ergo p q r sum x' + + +NB. naming side effects ------------------------------------------------- + +fa =: 3 : 0 + fa=:+/ + 2*fa y +) + +(2*+/x) -: fa x=:?30$1000 +( +/x) -: fa x + +fb =: 3 : ('abc=:25'; 'y+abc') +abc =: 12 +37 -: fb abc +50 -: fb abc + +abc =: 12 +37 -: (3 : ('abc=:25'; 'y+abc')) abc +50 -: (3 : ('abc=:25'; 'y+abc')) abc + +37 -: (3&* + 4!:55@(( <'abc')"_)) abc=:12 +_1 -: 4!:0 <'abc' +(30$37) -: (3&* + 4!:55@((30$<'abc')"_)) abc=:12 +_1 -: 4!:0 <'abc' +37 -: (4!:55@(( <'abc')"_) + 3&*) abc=:12 +_1 -: 4!:0 <'abc' +(30$37) -: (4!:55@((30$<'abc')"_) + 3&*) abc=:12 +_1 -: 4!:0 <'abc' + +lf =: 10{a. +write =: 1!:2 +sscript =: 0!:0 + +t=:'x=:'&,@":@i.&.>10-i.10 +x=:<'foo.x' +(;t,&.>lf) write x +sscript (20)$x +0 -: x +0!:0 x=:20$<'foo.x' +0 -: x +1!:55 <'foo.x' + +x=:>|.t +(".x) -: i."0>:i.10 +x -: i.10 + + +NB. reassignment on the same line --------------------------------------- + +t=:123456 +x=:17 +t=:7!:0 '' +x=:i.1e5 +(17,i.1e5) -: (x=:17),x +1200 > y=:t -~ 7!:0 '' + +x=:i.1e3 +(17,i.1e3) -: (17 [ 4!:55 <'x'),x + +4!:55 ;:'b t x y' +4!:55 ;:'b t x y' + +fa =: 3 : 0 + if. y do. + x=:i.1e3 + b,(17,i.1e3) -: (x=:17 [ b=.fa y-1),x + else. + i.0 + end. +) + +fa 1 +fa 2 +fa 3 +fa 4 +fa 5 + +4!:55 ;:'b x' + +fb =: 3 : 0 + if. y do. + x=:i.1e3 + b, (17,i.1e3) -: (17 [ b=.fb y-1 [ 4!:55 <'x'),x + else. + i.0 + end. +) + +fb 1 +fb 2 +fb 3 +fb 4 +fb 5 + +4!:55 ;:'Cogito Ich_liebe_dich a a_man aa abc alta b def erase ergo' +4!:55 ;:'fa fb first' +4!:55 ;:'ghi global j_k lf local names p pqr q r second sscript' +4!:55 ;:'sum t third write x y' + +
new file mode 100644 --- /dev/null +++ b/test/g010.ijs @@ -0,0 +1,51 @@ +NB. < y ----------------------------------------------------------------- + +test =: 3 : '(0=#$t), (-.t-:y), y-:>t=.<y' + +test ?10$2 +test 'a' +test ?2 3 4$1000 +test o.?2 3 4$1000 +test j.?2 3 4$1000 +test <123;123 + +test i.0 +test i.0 2 3 + +2000 > 7!:2 '<x' [ x=: i.1e5 + + +NB. x<y ----------------------------------------------------------------- + +(14 11#1 0) -: 1< 1+ 10^-i.25 + +NB. Boolean +0 1 0 0 -: 0 0 1 1 < 0 1 0 1 +*./ 0 < 1 1 1 +*./ 0 0 0 < 1 + +NB. integer +*./, (x-1) < x=: ?20$10000123 + +NB. floating point +*./, (x-1) < x=: o.?3 4$10000 + +'domain error' -: 'abc' < etx 3 4 5 +'domain error' -: 'abc' <~etx 3 4 5 +'domain error' -: 'ab' < etx 'cd' +'domain error' -: 3 < etx <3 4 +'domain error' -: 3 <~etx <3 4 +'domain error' -: 3.4 < etx 1 2 3j4 +'domain error' -: 3.4 <~etx 1 2 3j4 +'domain error' -: 3j4 < etx 1 2 3j4 +'domain error' -: 'abc' < etx 1 2 3j4 +'domain error' -: 'abc' <~etx 1 2 3j4 + +'length error' -: 3 4 < etx 5 6 7 +'length error' -: 3 4 <~etx 5 6 7 +'length error' -: (i.3 4)< etx i.5 4 +'length error' -: (i.3 4)<~etx i.5 4 + +4!:55 ;:'test x' + +
new file mode 100644 --- /dev/null +++ b/test/g010a.ijs @@ -0,0 +1,157 @@ +NB. B < B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x<y) -: (#.x,.y){0 1 0 0 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.?2 +(x<z) -: x<($x)$z [ z=.?2 + +(x<y) -: (40$"0 x)<y [ x=. ?10$2 [ y=. ?10 40$2 +(x<y) -: x<40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 0 0 -: 0 0 1 1 < 0 1 0 1 + + +NB. B < I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.?2 +(x<z) -: x<($x)$z [ z=._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 1 1 0 -: 0 0 1 1 < _4 3 4 _3 +0 0 -: 0 1 < _2147483648 +1 1 -: 0 1 < 2147483647 + + +NB. B < D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.?2 +(x<z) -: x<($x)$z [ z=.o._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 1 0 1 -: 0 0 1 1 < _2.5 1.2 _2.5 1.2 +(14 6#1 0) -: 1<1+10^-i.20 +0 1 0 1 -: 0 0 1 1 < __ _ __ _ + + +NB. I < B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=._1e5+?2e5 +(x<z) -: x<($x)$z [ z=.?2 + +(x<y) -: (40$"0 x)<y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x<y) -: x<40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +1 1 0 0 -: _3 _3 4 4 < 0 1 0 1 +0 0 -: 2147483647 < 0 1 +1 1 -: _2147483648 < 0 1 + + +NB. I < I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.?2e6 +(x<z) -: x<($x)$z [ z=._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 0 0 0 0 1 1 1 -: 4<i.8 +1 1 1 1 0 0 0 0 -: (i.8)<4 +1 1 1 1 0 1 -: _2147483648 < 2 0 1e9 2e9 _2147483648 2147483647 +0 0 0 0 0 0 -: 2147483647 < 2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I < D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.?2e6 +(x<z) -: x<($x)$z [ z=.o._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +0 0 0 0 1 1 1 1 -: 4<0.5+i.8 +1 1 1 1 0 0 0 0 -: (0.5+i.8)<4 +1 1 1 1 0 1 -: _2147483648 <2.5 0 1e9 2e9 _2147483648 2147483647 +0 0 0 0 0 0 -: 2147483647 <2.5 0 1e9 2e9 _2147483648 2147483647 +(14 6#1 0) -: 17 < 17*1+10^-i.20 +0 1 0 1 -: 4 4 _5 _5 < __ _ __ _ +0 1 0 1 -: _2147483648 _2147483648 2147483647 2147483647 < __ _ __ _ + + +NB. D < B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.o._1e5+?2e5 +(x<z) -: x<($x)$z [ z=.?2 + +(x<y) -: (40$"0 x)<y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x<y) -: x<40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(14 6#1 0) -: (1-10^-i.20) < 1 +(20$0) -: ( 10^-i.20) < 0 +(20$1) -: (-10^-i.20) < 0 + + +NB. D < I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.o._1e5+?2e5 +(x<z) -: x<($x)$z [ z=._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(14 6#1 0) -: (17*1-10^-i.20) < 20$17 +1 1 0 0 -: __ __ _ _ < _1e9+?4$2e9 + + +NB. D < D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<y) -: (z+x)<z+y [ z=.{.0 4.5 +(x<y) -: (z*x)<z*y [ z=.{.1 4j5 +(z<y) -: (($y)$z)<y [ z=.o._1e5+?2e5 +(x<z) -: x<($x)$z [ z=.o._1e5+?2e5 + +(x<y) -: (40$"0 x)<y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<y) -: x<40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +0 -: (o.1) < ^1 +1 -: 1x1 < 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g010i.ijs @@ -0,0 +1,27 @@ +NB. </ B --------------------------------------------------------------- + +0 1 0 0 -: </ 0 0 1 1 ,: 0 1 0 1 + +lt=: 4 : 'x<y' + +(</"1 -: lt/"1) x=.?3 5 17$2 +(</"2 -: lt/"2) x +(</"3 -: lt/"3) x + +(</"1 -: lt/"1) x=.?3 5 32$2 +(</"2 -: lt/"2) x +(</"3 -: lt/"3) x + +(</"1 -: lt/"1) x=.?3 8 32$2 +(</"2 -: lt/"2) x +(</"3 -: lt/"3) x + +f=: 3 : '(</ -: lt/) ?y$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 <."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 <."1 x + +4!:55 ;:'f lt x' + +
new file mode 100644 --- /dev/null +++ b/test/g010p.ijs @@ -0,0 +1,34 @@ +NB. </\ B --------------------------------------------------------------- + +(0 0 1 1,: 0 1 0 0) -: </\ 0 0 1 1 ,: 0 1 0 1 +(20{.1) -: </\20$1 +(20$ 0) -: </\20$0 + +lt=. 4 : 'x<y' + +(</\"1 -: lt/\"1) #:i.16 +(</\"1 -: lt/\"1) #:i.32 + +(</\ -: lt/\ ) x=.1=? 13$4 +(</\ -: lt/\ ) x=.1=?7 13$4 +(</\"1 -: lt/\"1) x +(</\ -: lt/\ ) x=.1=?3 5 13$4 +(</\"1 -: lt/\"1) x +(</\"2 -: lt/\"2) x + +(</\ -: lt/\ ) x=.1=? 16$4 +(</\ -: lt/\ ) x=.1=?8 16$4 +(</\"1 -: lt/\"1) x +(</\ -: lt/\ ) x=.1=?2 4 16$4 +(</\"1 -: lt/\"1) x +(</\"2 -: lt/\"2) x + +(,'j') -: </\'j' +(,<'ace') -: </\<'ace' + +'domain error' -: </\ etx 'deipnosophist' +'domain error' -: </\ etx ;:'peace in our time' + +4!:55 ;:'lt x' + +
new file mode 100644 --- /dev/null +++ b/test/g010s.ijs @@ -0,0 +1,65 @@ +NB. </\. B ------------------------------------------------------------- + +(0 1 0 0,:0 1 0 1) -: </\. 0 0 1 1 ,: 0 1 0 1 + +lt=: 4 : 'x<y' + +f=: 3 : '(</\. -: lt/\.) ?y$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. </\. I ------------------------------------------------------------- + +lt=: 4 : 'x<y' + +(</\. -: lt/\.) x=.1 2 3 1e9 2e9 +(</\. -: lt/\.) |.x + +(</\. -: lt/\. ) x=._1e4+? 23$2e4 +(</\. -: lt/\. ) x=._1e4+?4 23$2e4 +(</\."1 -: lt/\."1) x +(</\. -: lt/\. ) x=._1e4+?7 5 23$2e4 +(</\."1 -: lt/\."1) x +(</\."2 -: lt/\."2) x + +(</\. -: lt/\. ) x=._1e9+? 23$2e9 +(</\. -: lt/\. ) x=._1e9+?4 23$2e9 +(</\."1 -: lt/\."1) x +(</\. -: lt/\. ) x=._1e9+?7 5 23$2e9 +(</\."1 -: lt/\."1) x +(</\."2 -: lt/\."2) x + + +NB. </\. D ------------------------------------------------------------- + +lt=: 4 : 'x<y' + +(</\. -: lt/\. ) x=.0.01*_1e4+? 23$2e4 +(</\. -: lt/\. ) x=.0.01*_1e4+?4 23$2e4 +(</\."1 -: lt/\."1) x +(</\. -: lt/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(</\."1 -: lt/\."1) x +(</\."2 -: lt/\."2) x + + +NB. </\. Z ------------------------------------------------------------- + +lt=: 4 : 'x<y' + +(</\. -: lt/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(</\. -: lt/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(</\."1 -: lt/\."1) x +(</\. -: lt/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(</\."1 -: lt/\."1) x +(</\."2 -: lt/\."2) x + +'domain error' -: </\. etx 3j4 5 +'domain error' -: </\. etx 'deipnosophist' +'domain error' -: </\. etx ;:'professors in New England' + +4!:55 ;:'f lt x' + +
new file mode 100644 --- /dev/null +++ b/test/g011.ijs @@ -0,0 +1,78 @@ +NB. <.y ----------------------------------------------------------------- + +ir=: 3!:1 + +p -: <.p=.?3 4$100 +4 = 3!:0 <.p + +p =. o.?3 4$100 +q =. <.p +q -: <.q +($q) -: $p +(p>:q)*.q>:p-1 + +p =. 1e20*o.?3 4$100 +q =. <.p +q -: <.q +($q) -: $p +(p>:q)*.q>:p-1 + +_ __ -: <. _ __ +(ir -: ir@:<.) _ __ _. + +0 < <. 2 ^ 31 63 +0 > <. - 2 ^ 31 63 + + +NB. <.z complex floor --------------------------------------------------- + +zfl =. <.!.0@+. +inc =. (1&<:@(+/) * 1 0&=@(>:!.0/)) @ (+. - zfl) +zfloor =. zfl j./@:+ inc + +a =. 3+0.1*i.10 +b =. 5+0.1*i.10 + +(<. -: zfloor"0) j./ a ,: b +(<. -: zfloor"0) j./ a ,: -b +(<. -: zfloor"0) j./(-a),: b +(<. -: zfloor"0) j./(-a),: -b + +y =. |: x j./ |. x=.0.1*i.10 +a =. </~ i.10 +b =. (</|.)i.10 +p =. (a>b)+0j1*a*.b +p -: <.y +(<. -: zfloor"0) y + + +NB. x<.y ---------------------------------------------------------------- + +3 -: 3 <. 5 +_5 -: _3 <. _5 +((<3 4)$&> i.2 3) -: ( i.2 3) <. i.2 3 3 4 +((<3 4)$&>o.i.2 3) -: ( o.i.2 3) <. o.i.2 3 3 4 +(- i.2 3 3 4) -: (- i.2 3) <.- i.2 3 3 4 +(-o.i.2 3 3 4) -: (-o.i.2 3) <.-o.i.2 3 3 4 + +(3 <. i.10) -: (0{3 5j7) <. i.10 +((i.10) <. 3) -: (i.10) <. 0{3 5j6 + +'domain error' -: <. etx 'abc' +'domain error' -: <. etx <'abc' + +'domain error' -: 'abc' <. etx 3 4 5 +'domain error' -: 'abc' <.~ etx 3 4 5 +'domain error' -: 3j4 <. etx 3 4 5 +'domain error' -: 3j4 <.~ etx 3 4 5 +'domain error' -: (<34) <. etx 3 4 5 +'domain error' -: (<34) <.~ etx 3 4 5 + +'length error' -: 3 4 <. etx 5 6 7 +'length error' -: 3 4 <.~etx 5 6 7 +'length error' -: (i.3 4) <. etx i.5 4 +'length error' -: (i.3 4) <.~etx i.5 4 + +4!:55 ;:'a b inc ir p q x y zfl zfloor ' + +
new file mode 100644 --- /dev/null +++ b/test/g011a.ijs @@ -0,0 +1,157 @@ +NB. B <. B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x<.y) -: (#.x,.y){0 0 0 1 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.?2 +(x<.z) -: x<.($x)$z [ z=.?2 + +(x<.y) -: (40$"0 x)<.y [ x=. ?10$2 [ y=. ?10 40$2 +(x<.y) -: x<.40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 0 0 1 -: 0 0 1 1 <. 0 1 0 1 + + +NB. B <. I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.?2 +(x<.z) -: x<.($x)$z [ z=._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +_4 0 1 _3 -: 0 0 1 1 <. _4 3 4 _3 +_2147483648 _2147483648 -: 0 1 <. _2147483648 +0 1 -: 0 1 <. 2147483647 + + +NB. B <. D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.?2 +(x<.z) -: x<.($x)$z [ z=.o._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +_2.5 0 _2.5 1 -: 0 0 1 1 <. _2.5 1.2 _2.5 1.2 +(20$0) -: (20$1) - 1<.1+10^-i.20 +__ 0 __ 1 -: 0 0 1 1 <. __ _ __ _ + + +NB. I <. B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=._1e5+?2e5 +(x<.z) -: x<.($x)$z [ z=.?2 + +(x<.y) -: (40$"0 x)<.y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x<.y) -: x<.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +_3 _3 0 1 -: _3 _3 4 4 <. 0 1 0 1 +0 1 -: 2147483647 <. 0 1 +_2147483648 _2147483648 -: _2147483648 <. 0 1 + + +NB. I <. I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.?2e6 +(x<.z) -: x<.($x)$z [ z=._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 1 2 3 4 4 4 4 -: 4<.i.8 +0 1 2 3 4 4 4 4 -: (i.8)<.4 +(6$_2147483648) -: _2147483648 <. 2 0 1e9 2e9 _2147483648 2147483647 +z -: 2147483647 <. z=.2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I <. D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.?2e6 +(x<.z) -: x<.($x)$z [ z=.o._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +0.5 1.5 2.5 3.5 4 4 4 4 -: 4<.0.5+i.8 +0.5 1.5 2.5 3.5 4 4 4 4 -: (0.5+i.8)<.4 +(6$_2147483648) -: _2147483648 <.2.5 0 1e9 2e9 _2147483648 2147483647 +z -: 2147483647 <. z=.2.5 0 1e9 2e9 _2147483648 2147483647 +(20$0) -: 17 - 17 <. 17*1+10^-i.20 +__ 4 __ _5 -: 4 4 _5 _5 <. __ _ __ _ +__ _2147483648 __ 2147483647 -: _2147483648 _2147483648 2147483647 2147483647 <. __ _ __ _ + + +NB. D <. B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.o._1e5+?2e5 +(x<.z) -: x<.($x)$z [ z=.?2 + +(x<.y) -: (40$"0 x)<.y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x<.y) -: x<.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(20$0) -: z - (z=.1-10^-i.20) <. 1 +(20$0) -: 0 - (z=. 10^-i.20) <. 0 +(20$0) -: z - (z=. -10^-i.20) <. 0 + + +NB. D <. I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.o._1e5+?2e5 +(x<.z) -: x<.($x)$z [ z=._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(20$0) -: z - (z=.17*1-10^-i.20) <. 20$17 +(__ __,2}.z) -: __ __ _ _ <. z=._1e9+?4$2e9 + + +NB. D <. D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<.y) -: (z+x)<.z+y [ z=.{.0 4.5 +(x<.y) -: (z*x)<.z*y [ z=.{.1 4j5 +(z<.y) -: (($y)$z)<.y [ z=.o._1e5+?2e5 +(x<.z) -: x<.($x)$z [ z=.o._1e5+?2e5 + +(x<.y) -: (40$"0 x)<.y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<.y) -: x<.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +(^1) -: (o.1) <. ^1 +1x1 -: 1x1 <. 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g011i.ijs @@ -0,0 +1,73 @@ +NB. <./ B --------------------------------------------------------------- + +0 0 0 1 -: <./ 0 0 1 1 ,: 0 1 0 1 + +min=: 4 : 'x<.y' + +(<./"1 -: min/"1) x=.?3 5 17$2 +(<./"2 -: min/"2) x +(<./"3 -: min/"3) x + +(<./"1 -: min/"1) x=.?3 5 32$2 +(<./"2 -: min/"2) x +(<./"3 -: min/"3) x + +(<./"1 -: min/"1) x=.?3 8 32$2 +(<./"2 -: min/"2) x +(<./"3 -: min/"3) x + +f=: 3 : '(<./ -: min/) y?@$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. <./ I ---------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./ -: min/) x=.1 2 3 1e9 2e9 +(<./ -: min/) |.x + +(<./ -: min/ ) x=._1e4+? 23$2e4 +(<./ -: min/ ) x=._1e4+?4 23$2e4 +(<./"1 -: min/"1) x +(<./ -: min/ ) x=._1e4+?7 5 23$2e4 +(<./"1 -: min/"1) x +(<./"2 -: min/"2) x + +(<./ -: min/ ) x=._1e9+? 23$2e9 +(<./ -: min/ ) x=._1e9+?4 23$2e9 +(<./"1 -: min/"1) x +(<./ -: min/ ) x=._1e9+?7 5 23$2e9 +(<./"1 -: min/"1) x +(<./"2 -: min/"2) x + + +NB. <./ D ---------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./ -: min/ ) x=.0.01*_1e4+? 23$2e4 +(<./ -: min/ ) x=.0.01*_1e4+?4 23$2e4 +(<./"1 -: min/"1) x +(<./ -: min/ ) x=.0.01*_1e4+?7 5 23$2e4 +(<./"1 -: min/"1) x +(<./"2 -: min/"2) x + + +NB. <./ Z ---------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./ -: min/ ) x=.(0j1-0j1)+0.1*_1e2+? 23$2e2 +(<./ -: min/ ) x=.(0j1-0j1)+0.1*_1e2+?4 23$2e2 +(<./"1 -: min/"1) x +(<./ -: min/ ) x=.(0j1-0j1)+0.1*_1e2+?7 5 23$2e2 +(<./"1 -: min/"1) x +(<./"2 -: min/"2) x + +4!:55 ;:'f min x' + +
new file mode 100644 --- /dev/null +++ b/test/g011p.ijs @@ -0,0 +1,76 @@ +NB. <./\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 0 0 1) -: <./\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: <./\20$1 +(20$0) -: <./\20$0 + +min=. 4 : 'x<.y' + +(<./\ -: min/\ ) x=.? 13$2 +(<./\ -: min/\ ) x=.?7 13$2 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=.?3 5 13$2 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x +(<./\ -: min/\ ) x=.? 12$2 +(<./\ -: min/\ ) x=.?4 12$2 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=.?4 8 12$2 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x + + +NB. <./\ I --------------------------------------------------------------- + +min=. 4 : 'x<.y' + +(<./\ -: min/\) x=.1 2 3 1e9 2e9 +(<./\ -: min/\) |.x + +(<./\ -: min/\ ) x=._1e4+? 13$2e4 +(<./\ -: min/\ ) x=._1e4+?4 13$2e4 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=._1e4+?3 5 13$2e4 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x + +(<./\ -: min/\ ) x=._1e9+? 13$2e9 +(<./\ -: min/\ ) x=._1e9+?4 13$2e9 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=._1e9+?3 5 13$2e9 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x + + +NB. <./\ D --------------------------------------------------------------- + +min=. 4 : 'x<.y' + +(<./\ -: min/\ ) x=.0.01*_1e4+? 13$2e4 +(<./\ -: min/\ ) x=.0.01*_1e4+?4 13$2e4 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=.0.01*_1e4+?3 5 13$2e4 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x + + +NB. <./\. Z --------------------------------------------------------------- + +min=. 4 : 'x<.y' + +(<./\ -: min/\ ) x=.[&.j. 0.1*_1e2+? 13$2e2 +(<./\ -: min/\ ) x=.[&.j. 0.1*_1e2+?4 13$2e2 +(<./\"1 -: min/\"1) x +(<./\ -: min/\ ) x=.[&.j. 0.1*_1e2+?3 5 13$2e2 +(<./\"1 -: min/\"1) x +(<./\"2 -: min/\"2) x + +(,'j') -: <./\'j' +(,<'ace') -: <./\<'ace' + +'domain error' -: <./\ etx 'deipnosophist' +'domain error' -: <./\ etx ;:'peace in our time' + +4!:55 ;:'f min x' + +
new file mode 100644 --- /dev/null +++ b/test/g011s.ijs @@ -0,0 +1,64 @@ +NB. <./\. B ------------------------------------------------------------- + +(0 0 0 1,:0 1 0 1) -: <./\. 0 0 1 1 ,: 0 1 0 1 + +min=: 4 : 'x<.y' + +f=: 3 : '(<./\. -: min/\.) y?@$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. <./\. I ------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./\. -: min/\.) x=.1 2 3 1e9 2e9 +(<./\. -: min/\.) |.x + +(<./\. -: min/\. ) x=._1e4+? 23$2e4 +(<./\. -: min/\. ) x=._1e4+?4 23$2e4 +(<./\."1 -: min/\."1) x +(<./\. -: min/\. ) x=._1e4+?7 5 23$2e4 +(<./\."1 -: min/\."1) x +(<./\."2 -: min/\."2) x + +(<./\. -: min/\. ) x=._1e9+? 23$2e9 +(<./\. -: min/\. ) x=._1e9+?4 23$2e9 +(<./\."1 -: min/\."1) x +(<./\. -: min/\. ) x=._1e9+?7 5 23$2e9 +(<./\."1 -: min/\."1) x +(<./\."2 -: min/\."2) x + + +NB. <./\. D ------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./\. -: min/\. ) x=.0.01*_1e4+? 23$2e4 +(<./\. -: min/\. ) x=.0.01*_1e4+?4 23$2e4 +(<./\."1 -: min/\."1) x +(<./\. -: min/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(<./\."1 -: min/\."1) x +(<./\."2 -: min/\."2) x + + +NB. <./\. Z ------------------------------------------------------------- + +min=: 4 : 'x<.y' + +(<./\. -: min/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(<./\. -: min/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(<./\."1 -: min/\."1) x +(<./\. -: min/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(<./\."1 -: min/\."1) x +(<./\."2 -: min/\."2) x + +'domain error' -: <./\. etx 'deipnosophist' +'domain error' -: <./\. etx ;:'professors in New England' + +4!:55 ;:'f min x' + +
new file mode 100644 --- /dev/null +++ b/test/g012.ijs @@ -0,0 +1,36 @@ +NB. <:y ----------------------------------------------------------------- + +(<: -: _1&+) 1=?2 3 4$2 +(<: -: _1&+) _1e9+?2 3 4$2e9 +(<: -: _1&+) o._1e9+?2 3 4$2e9 +(<: -: _1&+) j./?2 3 4$2e9 + +_3 _2 _1 0 1 -: <: _2 _1 0 1 2 +2147483646 -: <: 2147483647 +_2147483649 -: <:_2147483648 + +t -: [&.<: t=._1e9+?2 3 4$2e9 + +'domain error' -: <: etx 'abc' +'domain error' -: <: etx <'abc' + + +NB. x<:y ---------------------------------------------------------------- + +1 1 0 1 -: 0 0 1 1 <: 0 1 0 1 + +'domain error' -: 'abc' <: etx 3 4 5 +'domain error' -: 'abc' <:~etx 3 4 5 +'domain error' -: 3j4 <: etx 3 4 5 +'domain error' -: 3j4 <:~etx 3 4 5 +'domain error' -: (<34) <: etx 3 4 5 +'domain error' -: (<34) <:~etx 3 4 5 + +'length error' -: 3 4 <: etx 5 6 7 +'length error' -: 3 4 <:~etx 5 6 7 +'length error' -: (i.3 4) <: etx i.5 4 +'length error' -: (i.3 4) <:~etx i.5 4 + +4!:55 ;:'t' + +
new file mode 100644 --- /dev/null +++ b/test/g012a.ijs @@ -0,0 +1,157 @@ +NB. B <: B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x<:y) -: (#.x,.y){1 1 0 1 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.?2 +(x<:z) -: x<:($x)$z [ z=.?2 + +(x<:y) -: (40$"0 x)<:y [ x=. ?10$2 [ y=. ?10 40$2 +(x<:y) -: x<:40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 1 0 1 -: 0 0 1 1 <: 0 1 0 1 + + +NB. B <: I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.?2 +(x<:z) -: x<:($x)$z [ z=._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 1 1 0 -: 0 0 1 1 <: _4 3 4 _3 +0 0 -: 0 1 <: _2147483648 +1 1 -: 0 1 <: 2147483647 + + +NB. B <: D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.?2 +(x<:z) -: x<:($x)$z [ z=.o._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 1 0 1 -: 0 0 1 1 <: _2.5 1.2 _2.5 1.2 +(14 6#0 1) -: 1<:1-10^-i.20 +0 1 0 1 -: 0 0 1 1 <: __ _ __ _ + + +NB. I <: B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=._1e5+?2e5 +(x<:z) -: x<:($x)$z [ z=.?2 + +(x<:y) -: (40$"0 x)<:y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x<:y) -: x<:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +1 1 0 0 -: _3 _3 4 4 <: 0 1 0 1 +0 0 -: 2147483647 <: 0 1 +1 1 -: _2147483648 <: 0 1 + + +NB. I <: I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.?2e6 +(x<:z) -: x<:($x)$z [ z=._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 0 0 0 1 1 1 1 -: 4<:i.8 +1 1 1 1 1 0 0 0 -: (i.8)<:4 +1 1 1 1 1 1 -: _2147483648 <: 2 0 1e9 2e9 _2147483648 2147483647 +0 0 0 0 0 1 -: 2147483647 <: 2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I <: D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.?2e6 +(x<:z) -: x<:($x)$z [ z=.o._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +0 0 0 0 1 1 1 1 -: 4<:0.5+i.8 +1 1 1 1 0 0 0 0 -: (0.5+i.8)<:4 +1 1 1 1 1 1 -: _2147483648 <:2.5 0 1e9 2e9 _2147483648 2147483647 +0 0 0 0 0 1 -: 2147483647 <:2.5 0 1e9 2e9 _2147483648 2147483647 +(14 6#0 1) -: 17 <: 17*1-10^-i.20 +0 1 0 1 -: 4 4 _5 _5 <: __ _ __ _ +0 1 0 1 -: _2147483648 _2147483648 2147483647 2147483647 <: __ _ __ _ + + +NB. D <: B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.o._1e5+?2e5 +(x<:z) -: x<:($x)$z [ z=.?2 + +(x<:y) -: (40$"0 x)<:y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x<:y) -: x<:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(14 6#0 1) -: (1+10^-i.20) <: 1 +(20$0) -: ( 10^-i.20) <: 0 +(20$1) -: (-10^-i.20) <: 0 + + +NB. D <: I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.o._1e5+?2e5 +(x<:z) -: x<:($x)$z [ z=._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(14 6#0 1) -: (17*1+10^-i.20) <: 20$17 +1 1 0 0 -: __ __ _ _ <: _1e9+?4$2e9 + + +NB. D <: D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x<:y) -: (z+x)<:z+y [ z=.{.0 4.5 +(x<:y) -: (z*x)<:z*y [ z=.{.1 4j5 +(z<:y) -: (($y)$z)<:y [ z=.o._1e5+?2e5 +(x<:z) -: x<:($x)$z [ z=.o._1e5+?2e5 + +(x<:y) -: (40$"0 x)<:y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x<:y) -: x<:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +0 -: (o.1) <: ^1 +1 -: 1x1 <: 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g012i.ijs @@ -0,0 +1,27 @@ +NB. <:/ B --------------------------------------------------------------- + +1 1 0 1 -: <:/ 0 0 1 1 ,: 0 1 0 1 + +le=: 4 : 'x<:y' + +(<:/"1 -: le/"1) x=.?3 5 17$2 +(<:/"2 -: le/"2) x +(<:/"3 -: le/"3) x + +(<:/"1 -: le/"1) x=.?3 5 32$2 +(<:/"2 -: le/"2) x +(<:/"3 -: le/"3) x + +(<:/"1 -: le/"1) x=.?3 8 32$2 +(<:/"2 -: le/"2) x +(<:/"3 -: le/"3) x + +f=: 3 : '(<:/ -: le/) y?@$2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f le x' + +
new file mode 100644 --- /dev/null +++ b/test/g012p.ijs @@ -0,0 +1,34 @@ +NB. <:/\ B -------------------------------------------------------------- + +(0 0 1 1,: 1 1 0 1) -: <:/\ 0 0 1 1 ,: 0 1 0 1 +(20$ 1 ) -: <:/\20$1 +(0<i.20) -: <:/\20$0 + +le=. 4 : 'x<:y' + +(<:/\"1 -: le/\"1) #:i.16 +(<:/\"1 -: le/\"1) #:i.32 + +(<:/\ -: le/\ ) x=.0<? 13$4 +(<:/\ -: le/\ ) x=.0<?7 13$4 +(<:/\"1 -: le/\"1) x +(<:/\ -: le/\ ) x=.0<?3 5 13$4 +(<:/\"1 -: le/\"1) x +(<:/\"2 -: le/\"2) x + +(<:/\ -: le/\ ) x=.0<? 16$4 +(<:/\ -: le/\ ) x=.0<?8 16$4 +(<:/\"1 -: le/\"1) x +(<:/\ -: le/\ ) x=.0<?2 4 16$4 +(<:/\"1 -: le/\"1) x +(<:/\"2 -: le/\"2) x + +(,'j') -: <:/\'j' +(,<'ace') -: <:/\<'ace' + +'domain error' -: <:/\ etx 'deipnosophist' +'domain error' -: <:/\ etx ;:'peace in our time' + +4!:55 ;:'le x' + +
new file mode 100644 --- /dev/null +++ b/test/g012s.ijs @@ -0,0 +1,65 @@ +NB. <:/\. B ------------------------------------------------------------- + +(1 1 0 1,:0 1 0 1) -: <:/\. 0 0 1 1 ,: 0 1 0 1 + +le=: 4 : 'x<:y' + +f=: 3 : '(<:/\. -: le/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. <:/\. I ------------------------------------------------------------- + +le=: 4 : 'x<:y' + +(<:/\. -: le/\.) x=.1 2 3 1e9 2e9 +(<:/\. -: le/\.) |.x + +(<:/\. -: le/\. ) x=._1e4+? 23$2e4 +(<:/\. -: le/\. ) x=._1e4+?4 23$2e4 +(<:/\."1 -: le/\."1) x +(<:/\. -: le/\. ) x=._1e4+?7 5 23$2e4 +(<:/\."1 -: le/\."1) x +(<:/\."2 -: le/\."2) x + +(<:/\. -: le/\. ) x=._1e9+? 23$2e9 +(<:/\. -: le/\. ) x=._1e9+?4 23$2e9 +(<:/\."1 -: le/\."1) x +(<:/\. -: le/\. ) x=._1e9+?7 5 23$2e9 +(<:/\."1 -: le/\."1) x +(<:/\."2 -: le/\."2) x + + +NB. <:/\. D ------------------------------------------------------------- + +le=: 4 : 'x<:y' + +(<:/\. -: le/\. ) x=.0.01*_1e4+? 23$2e4 +(<:/\. -: le/\. ) x=.0.01*_1e4+?4 23$2e4 +(<:/\."1 -: le/\."1) x +(<:/\. -: le/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(<:/\."1 -: le/\."1) x +(<:/\."2 -: le/\."2) x + + +NB. <:/\. Z ------------------------------------------------------------- + +le=: 4 : 'x<:y' + +(<:/\. -: le/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(<:/\. -: le/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(<:/\."1 -: le/\."1) x +(<:/\. -: le/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(<:/\."1 -: le/\."1) x +(<:/\."2 -: le/\."2) x + +'domain error' -: <:/\. etx 3j4 5 +'domain error' -: <:/\. etx 'deipnosophist' +'domain error' -: <:/\. etx ;:'professors in New England' + +4!:55 ;:'f le x' + +
new file mode 100644 --- /dev/null +++ b/test/g020.ijs @@ -0,0 +1,84 @@ +NB. >y ------------------------------------------------------------------ + +rank =. #@$ + +mt =. 0&e.@$ +mrk =. >./@:(rank&>) +crk =. mrk (-@[{.$&1@[,$@])&.> ] +crank =. crk ($,)&.> ] +msh =. >./@:($&>) +cshape =. <@msh {.&.> ] +mtype =. >./@:(((3!:0)*-.@mt)&>) +fill =. >@({&(' ';(<$0);0))@(2 32&i.) +ctype =. (msh <@$ fill@mtype) [^:(mt@])&.> ] +ope =. > @ cshape @ ctype @ crank + +f =. > -: ope + +f i.&.>i.7 +f 1 2;i.2 3 4 +f 'ab';2 3$'wxyz' +f (<<'Now'),<]&.>i.2 3 + +f '';3 4 5 +f 'abc';'' +f (<2;3);'' + +f '';'a';'b';'c' +f 'a';'b';$0 +f 3;'';4 + +f '';($0);0$<'' +f (<0 3 4)$&.>' ';(<$0);0 + +f =. {:@:>@($&0@[ ; ]) +b (f -: {.) i.>:?b=.>:?4$6 +b (f -: {.) i.>:?b=.>:?4$6 +b (f -: {.) i.>:?b=.>:?4$6 + +t -: ><"0 t=.?100$20 +(4 6$'Cogito, ergo sum. ') -: >;:'Cogito, ergo sum.' + +2 1 1 1 -: $ >(i.0 0 0);4 +2 1 1 2 -: $ >(i.0 0 2);4 +2 1 1 2 -: $ >(i.0 0 2);i.0 +2 1 1 3 -: $ >(i.0 0 2);i.3 +2 1 0 3 -: $ >(i.0 0 2);i.0 3 +2 0 0 3 -: $ >(i.0 0 2);i.0 0 3 + +x -: > x=: 0 0 $0 +x -: > x=: 0 0 $3 +x -: > x=: 0 0 $3.4 +x -: > x=: 0 0 $3j4 +x -: > x=: 0 0 $3x +x -: > x=: 0 0 $3r4 +x -: > x=: 0 0 $'a' +x -: > x=: 0 0 $<34 + +'domain error' -: > etx (<'abc'),<12 +'domain error' -: > etx (<'abc'),<<12 +'domain error' -: > etx (<12),<<12 + + +NB. x>y ----------------------------------------------------------------- + +0 0 1 0 -: 0 0 1 1 > 0 1 0 1 + +(14 6#1 0) -: 1>1-10^-i.20 +1 >!.0 [1-10^-i.15 + +'domain error' -: 'abc' > etx 3 4 5 +'domain error' -: 'abc' >~etx 3 4 5 +'domain error' -: 'ab' > etx 'cd' +'domain error' -: 3 > etx <3 4 +'domain error' -: 3 >~etx <3 4 +'domain error' -: 3.4 > etx 1 2 3j4 +'domain error' -: 3.4 >~etx 1 2 3j4 +'domain error' -: 3j4 > etx 1 2 3j4 +'domain error' -: 'abc' > etx 1 2 3j4 +'domain error' -: 'abc' >~etx 1 2 3j4 + +4!:55 ;:'b crank crk cshape ctype f fill mrk msh mt ' +4!:55 ;:'mtype ope rank t x ' + +
new file mode 100644 --- /dev/null +++ b/test/g020a.ijs @@ -0,0 +1,157 @@ +NB. B > B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x>y) -: (#.x,.y){0 0 1 0 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.?2 +(x>z) -: x>($x)$z [ z=.?2 + +(x>y) -: (40$"0 x)>y [ x=. ?10$2 [ y=. ?10 40$2 +(x>y) -: x>40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 0 1 0 -: 0 0 1 1 > 0 1 0 1 + + +NB. B > I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.?2 +(x>z) -: x>($x)$z [ z=._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 0 1 0 1 0 0 1 -: 0 0 1 1 0 0 1 1 > 0 1 0 1 _4 3 4 _3 +1 1 -: 0 1 > _2147483648 +0 0 -: 0 1 > 2147483647 + + +NB. B > D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.?2 +(x>z) -: x>($x)$z [ z=.o._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 0 1 0 1 0 1 0 -: 0 0 1 1 0 0 1 1 > 0 1 0 1 _2.5 1.2 _2.5 1.2 +(14 6#1 0) -: 1>1-10^-i.20 +1 0 1 0 -: 0 0 1 1 > __ _ __ _ + + +NB. I > B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=._1e5+?2e5 +(x>z) -: x>($x)$z [ z=.?2 + +(x>y) -: (40$"0 x)>y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x>y) -: x>40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 0 1 1 -: _3 _3 4 4 > 0 1 0 1 +1 1 -: 2147483647 > 0 1 +0 0 -: _2147483648 > 0 1 + + +NB. I > I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.?2e6 +(x>z) -: x>($x)$z [ z=._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +1 1 1 1 0 0 0 0 -: 4>i.8 +0 0 0 0 0 1 1 1 -: (i.8)>4 +0 0 0 0 0 0 -: _2147483648 > 2 0 1e9 2e9 _2147483648 2147483647 +1 1 1 1 1 0 -: 2147483647 > 2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I > D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.?2e6 +(x>z) -: x>($x)$z [ z=.o._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +1 1 1 1 0 0 0 0 -: 4>0.5+i.8 +0 0 0 0 1 1 1 1 -: (0.5+i.8)>4 +0 0 0 0 0 0 -: _2147483648 >2.5 0 1e9 2e9 _2147483648 2147483647 +1 1 1 1 1 0 -: 2147483647 >2.5 0 1e9 2e9 _2147483648 2147483647 +(14 6#1 0) -: 17 > 17*1-10^-i.20 +1 0 1 0 -: 4 4 _5 _5 > __ _ __ _ +1 0 1 0 -: _2147483648 _2147483648 2147483647 2147483647 > __ _ __ _ + + +NB. D > B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.o._1e5+?2e5 +(x>z) -: x>($x)$z [ z=.?2 + +(x>y) -: (40$"0 x)>y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x>y) -: x>40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(14 6#1 0) -: (1+10^-i.20) > 1 +(20$1) -: ( 10^-i.20) > 0 +(20$0) -: (-10^-i.20) > 0 + + +NB. D > I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.o._1e5+?2e5 +(x>z) -: x>($x)$z [ z=._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(14 6#1 0) -: (17*1+10^-i.20) > 20$17 +0 0 1 1 -: __ __ _ _ > _1e9+?4$2e9 + + +NB. D > D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>y) -: (z+x)>z+y [ z=.{.0 4.5 +(x>y) -: (z*x)>z*y [ z=.{.1 4j5 +(z>y) -: (($y)$z)>y [ z=.o._1e5+?2e5 +(x>z) -: x>($x)$z [ z=.o._1e5+?2e5 + +(x>y) -: (40$"0 x)>y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>y) -: x>40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +1 -: (o.1) > ^1 +0 -: 1x1 > 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g020i.ijs @@ -0,0 +1,27 @@ +NB. >/ B --------------------------------------------------------------- + +0 0 1 0 -: >/ 0 0 1 1 ,: 0 1 0 1 + +gt=: 4 : 'x>y' + +(>/"1 -: gt/"1) x=.?3 5 17$2 +(>/"2 -: gt/"2) x +(>/"3 -: gt/"3) x + +(>/"1 -: gt/"1) x=.?3 5 32$2 +(>/"2 -: gt/"2) x +(>/"3 -: gt/"3) x + +(>/"1 -: gt/"1) x=.?3 8 32$2 +(>/"2 -: gt/"2) x +(>/"3 -: gt/"3) x + +f=: 3 : '(>/ -: gt/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f gt x' + +
new file mode 100644 --- /dev/null +++ b/test/g020p.ijs @@ -0,0 +1,34 @@ +NB. >/\ B --------------------------------------------------------------- + +(0 0 1 1,: 0 0 1 0) -: >/\ 0 0 1 1 ,: 0 1 0 1 +(20$1 0) -: >/\20$1 +(20$0) -: >/\20$0 + +gt=. 4 : 'x>y' + +(>/\"1 -: gt/\"1) #:i.16 +(>/\"1 -: gt/\"1) #:i.32 + +(>/\ -: gt/\ ) x=.0<? 13$4 +(>/\ -: gt/\ ) x=.0<?7 13$4 +(>/\"1 -: gt/\"1) x +(>/\ -: gt/\ ) x=.0<?3 5 13$4 +(>/\"1 -: gt/\"1) x +(>/\"2 -: gt/\"2) x + +(>/\ -: gt/\ ) x=.0<? 16$4 +(>/\ -: gt/\ ) x=.0<?8 16$4 +(>/\"1 -: gt/\"1) x +(>/\ -: gt/\ ) x=.0<?2 4 16$4 +(>/\"1 -: gt/\"1) x +(>/\"2 -: gt/\"2) x + +(,'j') -: >/\'j' +(,<'ace') -: >/\<'ace' + +'domain error' -: >/\ etx 'deipnosophist' +'domain error' -: >/\ etx ;:'peace in our time' + +4!:55 ;:'gt x' + +
new file mode 100644 --- /dev/null +++ b/test/g020s.ijs @@ -0,0 +1,65 @@ +NB. >/\. B ------------------------------------------------------------- + +(0 0 1 0,:0 1 0 1) -: >/\. 0 0 1 1 ,: 0 1 0 1 + +gt=: 4 : 'x>y' + +f=: 3 : '(>/\. -: gt/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. >/\. I ------------------------------------------------------------- + +gt=: 4 : 'x>y' + +(>/\. -: gt/\.) x=.1 2 3 1e9 2e9 +(>/\. -: gt/\.) |.x + +(>/\. -: gt/\. ) x=._1e4+? 23$2e4 +(>/\. -: gt/\. ) x=._1e4+?4 23$2e4 +(>/\."1 -: gt/\."1) x +(>/\. -: gt/\. ) x=._1e4+?7 5 23$2e4 +(>/\."1 -: gt/\."1) x +(>/\."2 -: gt/\."2) x + +(>/\. -: gt/\. ) x=._1e9+? 23$2e9 +(>/\. -: gt/\. ) x=._1e9+?4 23$2e9 +(>/\."1 -: gt/\."1) x +(>/\. -: gt/\. ) x=._1e9+?7 5 23$2e9 +(>/\."1 -: gt/\."1) x +(>/\."2 -: gt/\."2) x + + +NB. >/\. D ------------------------------------------------------------- + +gt=: 4 : 'x>y' + +(>/\. -: gt/\. ) x=.0.01*_1e4+? 23$2e4 +(>/\. -: gt/\. ) x=.0.01*_1e4+?4 23$2e4 +(>/\."1 -: gt/\."1) x +(>/\. -: gt/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(>/\."1 -: gt/\."1) x +(>/\."2 -: gt/\."2) x + + +NB. >/\. Z ------------------------------------------------------------- + +gt=: 4 : 'x>y' + +(>/\. -: gt/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(>/\. -: gt/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(>/\."1 -: gt/\."1) x +(>/\. -: gt/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(>/\."1 -: gt/\."1) x +(>/\."2 -: gt/\."2) x + +'domain error' -: >/\. etx 3j4 5 +'domain error' -: >/\. etx 'deipnosophist' +'domain error' -: >/\. etx ;:'professors in New England' + +4!:55 ;:'f gt x' + +
new file mode 100644 --- /dev/null +++ b/test/g021.ijs @@ -0,0 +1,54 @@ +NB. >.y ----------------------------------------------------------------- + +ir =. 3!:1 + +p -: >.p=.?3 4$100 +4 = 3!:0 >.p + +p =. o.?3 4$100 +q =. >.p +q -: >.q +($q) -: $p +(p<:q)*.q<:1+p + +p =. 1e20*o.?3 4$100 +q =. >.p +q -: >.q +($q) -: $p +(p<:q)*.q<:1+p + +_ __ -: >. _ __ +(ir -: ir@:>.) _ __ _. + +'domain error' -: >. etx 'abc' +'domain error' -: >. etx <'abc' + + +NB. x>.y ---------------------------------------------------------------- + +5 -: 3 >. 5 +_3 -: _3 >. _5 + +( i.2 3 3 4) -: ( i.2 3) >. i.2 3 3 4 +(o.i.2 3 3 4) -: ( o.i.2 3) >. o.i.2 3 3 4 +((<3 4)$&>- i.2 3) -: (- i.2 3) >.- i.2 3 3 4 +((<3 4)$&>-o.i.2 3) -: (-o.i.2 3) >.-o.i.2 3 3 4 + +(3 >. i.10) -: (0{3 5j7) >. i.10 +((i.10) >. 3) -: (i.10) >. 0{3 5j6 + +'domain error' -: 'abc' >. etx 3 4 5 +'domain error' -: 'abc' >.~etx 3 4 5 +'domain error' -: 3j4 >. etx 3 4 5 +'domain error' -: 3j4 >.~etx 3 4 5 +'domain error' -: (<34) >. etx 3 4 5 +'domain error' -: (<34) >.~etx 3 4 5 + +'length error' -: 3 4 >. etx 5 6 7 +'length error' -: 3 4 >.~etx 5 6 7 +'length error' -: (i.3 4) >. etx i.5 4 +'length error' -: (i.3 4) >.~etx i.5 4 + +4!:55 ;:'ir p q' + +
new file mode 100644 --- /dev/null +++ b/test/g021a.ijs @@ -0,0 +1,157 @@ +NB. B >. B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x>.y) -: (#.x,.y){0 1 1 1 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.?2 +(x>.z) -: x>.($x)$z [ z=.?2 + +(x>.y) -: (40$"0 x)>.y [ x=. ?10$2 [ y=. ?10 40$2 +(x>.y) -: x>.40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 1 1 -: 0 0 1 1 >. 0 1 0 1 + + +NB. B >. I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.?2 +(x>.z) -: x>.($x)$z [ z=._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 3 4 1 -: 0 0 1 1 >. _4 3 4 _3 +0 1 -: 0 1 >. _2147483648 +2147483647 2147483647 -: 0 1 >. 2147483647 + + +NB. B >. D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.?2 +(x>.z) -: x>.($x)$z [ z=.o._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 1.2 1 1.2 -: 0 0 1 1 >. _2.5 1.2 _2.5 1.2 +(20$0) -: z - 1>.z=.1+10^-i.20 +0 _ 1 _ -: 0 0 1 1 >. __ _ __ _ + + +NB. I >. B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=._1e5+?2e5 +(x>.z) -: x>.($x)$z [ z=.?2 + +(x>.y) -: (40$"0 x)>.y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x>.y) -: x>.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 1 4 4 -: _3 _3 4 4 >. 0 1 0 1 +2147483647 2147483647 -: 2147483647 >. 0 1 +0 1 -: _2147483648 >. 0 1 + + +NB. I >. I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.?2e6 +(x>.z) -: x>.($x)$z [ z=._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +4 4 4 4 4 5 6 7 -: 4>.i.8 +4 4 4 4 4 5 6 7 -: (i.8)>.4 +z -: z=._2147483648 >. 2 0 1e9 2e9 _2147483648 2147483647 +(($z)$2147483647) -: 2147483647 >. z=.2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I >. D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.?2e6 +(x>.z) -: x>.($x)$z [ z=.o._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +4 4 4 4 4.5 5.5 6.5 7.5 -: 4>.0.5+i.8 +4 4 4 4 4.5 5.5 6.5 7.5 -: (0.5+i.8)>.4 +z -: _2147483648 >. z=.2.5 0 1e9 2e9 _2147483648 2147483647 +(($z)$2147483647) -: 2147483647 >. z=.2.5 0 1e9 2e9 _2147483648 2147483647 +(20$0) -: z - 17 >. z=.17*1+10^-i.20 +4 _ _5 _ -: 4 4 _5 _5 >. __ _ __ _ +_2147483648 _ 2147483647 _ -: _2147483648 _2147483648 2147483647 2147483647 >. __ _ __ _ + + +NB. D >. B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.o._1e5+?2e5 +(x>.z) -: x>.($x)$z [ z=.?2 + +(x>.y) -: (40$"0 x)>.y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x>.y) -: x>.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(20$0) -: 1 - (z=.1-10^-i.20) >. 1 +(20$0) -: z - (z=. 10^-i.20) >. 0 +(20$0) -: 0 - (z=. -10^-i.20) >. 0 + + +NB. D >. I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.o._1e5+?2e5 +(x>.z) -: x>.($x)$z [ z=._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(20$0) -: 17 - (z=.17*1-10^-i.20) >. 20$17 +((2{.z),_ _) -: __ __ _ _ >. z=._1e9+?4$2e9 + + +NB. D >. D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>.y) -: (z+x)>.z+y [ z=.{.0 4.5 +(x>.y) -: (z*x)>.z*y [ z=.{.1 4j5 +(z>.y) -: (($y)$z)>.y [ z=.o._1e5+?2e5 +(x>.z) -: x>.($x)$z [ z=.o._1e5+?2e5 + +(x>.y) -: (40$"0 x)>.y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>.y) -: x>.40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +(o.1) -: (o.1) >. ^1 +1p1 -: 1x1 >. 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g021i.ijs @@ -0,0 +1,73 @@ +NB. >./ B --------------------------------------------------------------- + +0 1 1 1 -: >./ 0 0 1 1 ,: 0 1 0 1 + +max=: 4 : 'x>.y' + +(>./"1 -: max/"1) x=.?3 5 17$2 +(>./"2 -: max/"2) x +(>./"3 -: max/"3) x + +(>./"1 -: max/"1) x=.?3 5 32$2 +(>./"2 -: max/"2) x +(>./"3 -: max/"3) x + +(>./"1 -: max/"1) x=.?3 8 32$2 +(>./"2 -: max/"2) x +(>./"3 -: max/"3) x + +f=: 3 : '(>./ -: max/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. >./ I ---------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./ -: max/) x=.1 2 3 1e9 2e9 +(>./ -: max/) |.x + +(>./ -: max/ ) x=._1e4+? 23$2e4 +(>./ -: max/ ) x=._1e4+?4 23$2e4 +(>./"1 -: max/"1) x +(>./ -: max/ ) x=._1e4+?7 5 23$2e4 +(>./"1 -: max/"1) x +(>./"2 -: max/"2) x + +(>./ -: max/ ) x=._1e9+? 23$2e9 +(>./ -: max/ ) x=._1e9+?4 23$2e9 +(>./"1 -: max/"1) x +(>./ -: max/ ) x=._1e9+?7 5 23$2e9 +(>./"1 -: max/"1) x +(>./"2 -: max/"2) x + + +NB. >./ D ---------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./ -: max/ ) x=.0.01*_1e4+? 23$2e4 +(>./ -: max/ ) x=.0.01*_1e4+?4 23$2e4 +(>./"1 -: max/"1) x +(>./ -: max/ ) x=.0.01*_1e4+?7 5 23$2e4 +(>./"1 -: max/"1) x +(>./"2 -: max/"2) x + + +NB. >./ Z ---------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./ -: max/ ) x=.(0j1-0j1)+0.1*_1e2+? 23$2e2 +(>./ -: max/ ) x=.(0j1-0j1)+0.1*_1e2+?4 23$2e2 +(>./"1 -: max/"1) x +(>./ -: max/ ) x=.(0j1-0j1)+0.1*_1e2+?7 5 23$2e2 +(>./"1 -: max/"1) x +(>./"2 -: max/"2) x + +4!:55 ;:'f max x' + +
new file mode 100644 --- /dev/null +++ b/test/g021p.ijs @@ -0,0 +1,76 @@ +NB. >./\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 1 1 1) -: >./\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: >./\20$1 +(20$0) -: >./\20$0 + +max=. 4 : 'x>.y' + +(>./\ -: max/\ ) x=.? 13$2 +(>./\ -: max/\ ) x=.?7 13$2 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=.?3 5 13$2 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x +(>./\ -: max/\ ) x=.? 12$2 +(>./\ -: max/\ ) x=.?4 12$2 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=.?4 8 12$2 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x + + +NB. >./\ I --------------------------------------------------------------- + +max=. 4 : 'x>.y' + +(>./\ -: max/\) x=.1 2 3 1e9 2e9 +(>./\ -: max/\) |.x + +(>./\ -: max/\ ) x=._1e4+? 13$2e4 +(>./\ -: max/\ ) x=._1e4+?4 13$2e4 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=._1e4+?3 5 13$2e4 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x + +(>./\ -: max/\ ) x=._1e9+? 13$2e9 +(>./\ -: max/\ ) x=._1e9+?4 13$2e9 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=._1e9+?3 5 13$2e9 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x + + +NB. >./\ D --------------------------------------------------------------- + +max=. 4 : 'x>.y' + +(>./\ -: max/\ ) x=.0.01*_1e4+? 13$2e4 +(>./\ -: max/\ ) x=.0.01*_1e4+?4 13$2e4 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=.0.01*_1e4+?3 5 13$2e4 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x + + +NB. >./\. Z --------------------------------------------------------------- + +max=. 4 : 'x>.y' + +(>./\ -: max/\ ) x=.[&.j. 0.1*_1e2+? 13$2e2 +(>./\ -: max/\ ) x=.[&.j. 0.1*_1e2+?4 13$2e2 +(>./\"1 -: max/\"1) x +(>./\ -: max/\ ) x=.[&.j. 0.1*_1e2+?3 5 13$2e2 +(>./\"1 -: max/\"1) x +(>./\"2 -: max/\"2) x + +(,'j') -: >./\'j' +(,<'ace') -: >./\<'ace' + +'domain error' -: >./\ etx 'deipnosophist' +'domain error' -: >./\ etx ;:'peace in our time' + +4!:55 ;:'max x' + +
new file mode 100644 --- /dev/null +++ b/test/g021s.ijs @@ -0,0 +1,64 @@ +NB. >./\. B ------------------------------------------------------------- + +(0 1 1 1,:0 1 0 1) -: >./\. 0 0 1 1 ,: 0 1 0 1 + +max=: 4 : 'x>.y' + +f=: 3 : '(>./\. -: max/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. >./\. I ------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./\. -: max/\.) x=.1 2 3 1e9 2e9 +(>./\. -: max/\.) |.x + +(>./\. -: max/\. ) x=._1e4+? 23$2e4 +(>./\. -: max/\. ) x=._1e4+?4 23$2e4 +(>./\."1 -: max/\."1) x +(>./\. -: max/\. ) x=._1e4+?7 5 23$2e4 +(>./\."1 -: max/\."1) x +(>./\."2 -: max/\."2) x + +(>./\. -: max/\. ) x=._1e9+? 23$2e9 +(>./\. -: max/\. ) x=._1e9+?4 23$2e9 +(>./\."1 -: max/\."1) x +(>./\. -: max/\. ) x=._1e9+?7 5 23$2e9 +(>./\."1 -: max/\."1) x +(>./\."2 -: max/\."2) x + + +NB. >./\. D ------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./\. -: max/\. ) x=.0.01*_1e4+? 23$2e4 +(>./\. -: max/\. ) x=.0.01*_1e4+?4 23$2e4 +(>./\."1 -: max/\."1) x +(>./\. -: max/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(>./\."1 -: max/\."1) x +(>./\."2 -: max/\."2) x + + +NB. >./\. Z ------------------------------------------------------------- + +max=: 4 : 'x>.y' + +(>./\. -: max/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(>./\. -: max/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(>./\."1 -: max/\."1) x +(>./\. -: max/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(>./\."1 -: max/\."1) x +(>./\."2 -: max/\."2) x + +'domain error' -: >./\. etx 'triskaidekaphobia' +'domain error' -: >./\. etx ;:'professors in New England' + +4!:55 ;:'f max x' + +
new file mode 100644 --- /dev/null +++ b/test/g022.ijs @@ -0,0 +1,36 @@ +NB. >:y ----------------------------------------------------------------- + +(>: -: 1&+) 1=?2 3 4$2 +(>: -: 1&+) _1e9+?2 3 4$2e9 +(>: -: 1&+) o._1e9+?2 3 4$2e9 +(>: -: 1&+) j./?2 3 4$2e9 + +_1 0 1 2 3 -: >: _2 _1 0 1 2 +2147483648 -: >: 2147483647 +_2147483647 -: >:_2147483648 + +t -: [&.>: t=._1e9+?2 3 4$2e9 + +'domain error' -: >: etx 'abc' +'domain error' -: >: etx <'abc' + + +NB. x>:y ---------------------------------------------------------------- + +1 0 1 1 -: 0 0 1 1 >: 0 1 0 1 + +'domain error' -: 'abc' >: etx 3 4 5 +'domain error' -: 'abc' >:~etx 3 4 5 +'domain error' -: 3j4 >: etx 3 4 5 +'domain error' -: 3j4 >:~etx 3 4 5 +'domain error' -: (<34) >: etx 3 4 5 +'domain error' -: (<34) >:~etx 3 4 5 + +'length error' -: 3 4 >: etx 5 6 7 +'length error' -: 3 4 >:~etx 5 6 7 +'length error' -: (i.3 4) >: etx i.5 4 +'length error' -: (i.3 4) >:~etx i.5 4 + +4!:55 ;:'t' + +
new file mode 100644 --- /dev/null +++ b/test/g022a.ijs @@ -0,0 +1,157 @@ +NB. B >: B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x>:y) -: (#.x,.y){1 0 1 1 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.?2 +(x>:z) -: x>:($x)$z [ z=.?2 + +(x>:y) -: (40$"0 x)>:y [ x=. ?10$2 [ y=. ?10 40$2 +(x>:y) -: x>:40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 0 1 1 -: 0 0 1 1 >: 0 1 0 1 + + +NB. B >: I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.?2 +(x>:z) -: x>:($x)$z [ z=._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +1 0 1 1 1 0 0 1 -: 0 0 1 1 0 0 1 1 >: 0 1 0 1 _4 3 4 _3 +1 1 -: 0 1 >: _2147483648 +0 0 -: 0 1 >: 2147483647 + + +NB. B >: D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.?2 +(x>:z) -: x>:($x)$z [ z=.o._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +1 0 1 1 1 0 1 0 -: 0 0 1 1 0 0 1 1 >: 0 1 0 1 _2.5 1.2 _2.5 1.2 +(14 6#0 1) -: 1>:1+10^-i.20 +1 0 1 0 -: 0 0 1 1 >: __ _ __ _ + + +NB. I >: B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=._1e5+?2e5 +(x>:z) -: x>:($x)$z [ z=.?2 + +(x>:y) -: (40$"0 x)>:y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x>:y) -: x>:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 0 1 1 -: _3 _3 4 4 >: 0 1 0 1 +1 1 -: 2147483647 >: 0 1 +0 0 -: _2147483648 >: 0 1 + + +NB. I >: I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.?2e6 +(x>:z) -: x>:($x)$z [ z=._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +1 1 1 1 1 0 0 0 -: 4>:i.8 +0 0 0 0 1 1 1 1 -: (i.8)>:4 +0 0 0 0 1 0 -: _2147483648 >: 2 0 1e9 2e9 _2147483648 2147483647 +1 1 1 1 1 1 -: 2147483647 >: 2 0 1e9 2e9 _2147483648 2147483647 + + +NB. I >: D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.?2e6 +(x>:z) -: x>:($x)$z [ z=.o._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +1 1 1 1 0 0 0 0 -: 4>:0.5+i.8 +0 0 0 0 1 1 1 1 -: (0.5+i.8)>:4 +0 0 0 0 1 0 -: _2147483648 >:2.5 0 1e9 2e9 _2147483648 2147483647 +1 1 1 1 1 1 -: 2147483647 >:2.5 0 1e9 2e9 _2147483648 2147483647 +(14 6#0 1) -: 17 >: 17*1+10^-i.20 +1 0 1 0 -: 4 4 _5 _5 >: __ _ __ _ +1 0 1 0 -: _2147483648 _2147483648 2147483647 2147483647 >: __ _ __ _ + + +NB. D >: B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.o._1e5+?2e5 +(x>:z) -: x>:($x)$z [ z=.?2 + +(x>:y) -: (40$"0 x)>:y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x>:y) -: x>:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +(14 6#0 1) -: (1-10^-i.20) >: 1 +(20$1) -: ( 10^-i.20) >: 0 +(20$0) -: (-10^-i.20) >: 0 + + +NB. D >: I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.o._1e5+?2e5 +(x>:z) -: x>:($x)$z [ z=._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +(14 6#0 1) -: (17*1-10^-i.20) >: 20$17 +0 0 1 1 -: __ __ _ _ >: _1e9+?4$2e9 + + +NB. D >: D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x>:y) -: (z+x)>:z+y [ z=.{.0 4.5 +(x>:y) -: (z*x)>:z*y [ z=.{.1 4j5 +(z>:y) -: (($y)$z)>:y [ z=.o._1e5+?2e5 +(x>:z) -: x>:($x)$z [ z=.o._1e5+?2e5 + +(x>:y) -: (40$"0 x)>:y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x>:y) -: x>:40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +1 -: (o.1) >: ^1 +0 -: 1x1 >: 1p1 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g022i.ijs @@ -0,0 +1,27 @@ +NB. >:/ B --------------------------------------------------------------- + +1 0 1 1 -: >:/ 0 0 1 1 ,: 0 1 0 1 + +ge=: 4 : 'x>:y' + +(>:/"1 -: ge/"1) x=.?3 5 17$2 +(>:/"2 -: ge/"2) x +(>:/"3 -: ge/"3) x + +(>:/"1 -: ge/"1) x=.?3 5 32$2 +(>:/"2 -: ge/"2) x +(>:/"3 -: ge/"3) x + +(>:/"1 -: ge/"1) x=.?3 8 32$2 +(>:/"2 -: ge/"2) x +(>:/"3 -: ge/"3) x + +f=: 3 : '(>:/ -: ge/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f ge x' + +
new file mode 100644 --- /dev/null +++ b/test/g022p.ijs @@ -0,0 +1,34 @@ +NB. >:/\ B -------------------------------------------------------------- + +(0 0 1 1,: 1 0 1 1) -: >:/\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: >:/\20$1 +(20$0 1) -: >:/\20$0 + +ge=. 4 : 'x>:y' + +(>:/\"1 -: ge/\"1) #:i.16 +(>:/\"1 -: ge/\"1) #:i.32 + +(>:/\ -: ge/\ ) x=.0=? 13$4 +(>:/\ -: ge/\ ) x=.0=?7 13$4 +(>:/\"1 -: ge/\"1) x +(>:/\ -: ge/\ ) x=.0=?3 5 13$4 +(>:/\"1 -: ge/\"1) x +(>:/\"2 -: ge/\"2) x + +(>:/\ -: ge/\ ) x=.0=? 16$4 +(>:/\ -: ge/\ ) x=.0=?8 16$4 +(>:/\"1 -: ge/\"1) x +(>:/\ -: ge/\ ) x=.0=?2 4 16$4 +(>:/\"1 -: ge/\"1) x +(>:/\"2 -: ge/\"2) x + +(,'j') -: >:/\'j' +(,<'ace') -: >:/\<'ace' + +'domain error' -: >:/\ etx 'deipnosophist' +'domain error' -: >:/\ etx ;:'peace in our time' + +4!:55 ;:'ge x' + +
new file mode 100644 --- /dev/null +++ b/test/g022s.ijs @@ -0,0 +1,65 @@ +NB. >:/\. B ------------------------------------------------------------- + +(1 0 1 1,:0 1 0 1) -: >:/\. 0 0 1 1 ,: 0 1 0 1 + +ge=: 4 : 'x>:y' + +f=: 3 : '(>:/\. -: ge/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. >:/\. I ------------------------------------------------------------- + +ge=: 4 : 'x>:y' + +(>:/\. -: ge/\.) x=.1 2 3 1e9 2e9 +(>:/\. -: ge/\.) |.x + +(>:/\. -: ge/\. ) x=._1e4+? 23$2e4 +(>:/\. -: ge/\. ) x=._1e4+?4 23$2e4 +(>:/\."1 -: ge/\."1) x +(>:/\. -: ge/\. ) x=._1e4+?7 5 23$2e4 +(>:/\."1 -: ge/\."1) x +(>:/\."2 -: ge/\."2) x + +(>:/\. -: ge/\. ) x=._1e9+? 23$2e9 +(>:/\. -: ge/\. ) x=._1e9+?4 23$2e9 +(>:/\."1 -: ge/\."1) x +(>:/\. -: ge/\. ) x=._1e9+?7 5 23$2e9 +(>:/\."1 -: ge/\."1) x +(>:/\."2 -: ge/\."2) x + + +NB. >:/\. D ------------------------------------------------------------- + +ge=: 4 : 'x>:y' + +(>:/\. -: ge/\. ) x=.0.01*_1e4+? 23$2e4 +(>:/\. -: ge/\. ) x=.0.01*_1e4+?4 23$2e4 +(>:/\."1 -: ge/\."1) x +(>:/\. -: ge/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(>:/\."1 -: ge/\."1) x +(>:/\."2 -: ge/\."2) x + + +NB. >:/\. Z ------------------------------------------------------------- + +ge=: 4 : 'x>:y' + +(>:/\. -: ge/\. ) x=.[&.j. 0.1*_1e2+?2 23$2e2 +(>:/\. -: ge/\. ) x=.[&.j. 0.1*_1e2+?2 4 23$2e2 +(>:/\."1 -: ge/\."1) x +(>:/\. -: ge/\. ) x=.[&.j. 0.1*_1e2+?2 7 5 23$2e2 +(>:/\."1 -: ge/\."1) x +(>:/\."2 -: ge/\."2) x + +'domain error' -: >:/\. etx 3j4 5 +'domain error' -: >:/\. etx 'deipnosophist' +'domain error' -: >:/\. etx ;:'professors in New England' + +4!:55 ;:'f ge x' + +
new file mode 100644 --- /dev/null +++ b/test/g030.ijs @@ -0,0 +1,240 @@ +NB. _ ------------------------------------------------------------------- + +eq =. -:&((_8+#3!:1]0.5)&}.)&(3!:1)&, + +(1 0 1 0,:0 1 0 1) -: = _ __ _ __ +1 0 0 1 -: _ _ __ __ = _ __ _ __ +*./, 0= _ = ?2 3$2 +*./, 0= _ = _1e9+?2 3 4$2e9 +*./, 0= _ = o._1e9+?2 3 4$2e9 +*./, 0= _ = j./_1e9+?2 3 4$2e9 +*./, 0= __ = ?2 3$2 +*./, 0= __ = _1e9+?2 3 4$2e9 +*./, 0= __ = o._1e9+?2 3 4$2e9 +*./, 0= __ = r./_1e7+?2 3 4$2e7 + +_ -: ><_ +__ -: ><__ +0 0 1 0 -: _ _ __ __ < _ __ _ __ +*./, 0= _ < ?2 3$2 +*./, 0= _ < _1e9+?2 3 4$2e9 +*./, 0= _ < o._1e9+?2 3 4$2e9 +*./, __ < ?2 3$2 +*./, __ < _1e9+?2 3 4$2e9 +*./, __ < o._1e9+?2 3 4$2e9 +*./, _ <~ ?2 3$2 +*./, _ <~ _1e9+?2 3 4$2e9 +*./, _ <~ o._1e9+?2 3 4$2e9 +*./, 0=__ <~ ?2 3$2 +*./, 0=__ <~ _1e9+?2 3 4$2e9 +*./, 0=__ <~ o._1e9+?2 3 4$2e9 + +_ __ -: <._ __ +_ __ __ __ -: _ _ __ __ <. _ __ _ __ +t -: _ <. t=.?2 3$2 +t -: _ <. t=._1e9+?2 3 4$2e9 +t -: _ <. t=.o._1e9+?2 3 4$2e9 +(($t)$__) -: __ <. t=.?2 3$2 +(($t)$__) -: __ <. t=._1e9+?2 3 4$2e9 +(($t)$__) -: __ <. t=.o._1e9+?2 3 4$2e9 +_ -: <./'' + +_ __ -: <: _ __ +1 0 1 1 -: _ _ __ __ <: _ __ _ __ +*./, 0= _ <: ?2 3$2 +*./, 0= _ <: _1e9+?2 3 4$2e9 +*./, 0= _ <: o._1e9+?2 3 4$2e9 +*./, __ <: ?2 3$2 +*./, __ <: _1e9+?2 3 4$2e9 +*./, __ <: o._1e9+?2 3 4$2e9 +*./, _ <:~ ?2 3$2 +*./, _ <:~ _1e9+?2 3 4$2e9 +*./, _ <:~ o._1e9+?2 3 4$2e9 +*./, 0=__ <:~ ?2 3$2 +*./, 0=__ <:~ _1e9+?2 3 4$2e9 +*./, 0=__ <:~ o._1e9+?2 3 4$2e9 + +_ __ -: > _ __ +_ __ -: > _;__ +0 1 0 0 -: _ _ __ __ > _ __ _ __ +*./, _ > ?2 3$2 +*./, _ > _1e9+?2 3 4$2e9 +*./, _ > o._1e9+?2 3 4$2e9 +*./, 0=__ > ?2 3$2 +*./, 0=__ > _1e9+?2 3 4$2e9 +*./, 0=__ > o._1e9+?2 3 4$2e9 +*./, 0= _ >~ ?2 3$2 +*./, 0= _ >~ _1e9+?2 3 4$2e9 +*./, 0= _ >~ o._1e9+?2 3 4$2e9 +*./, __ >~ ?2 3$2 +*./, __ >~ _1e9+?2 3 4$2e9 +*./, __ >~ o._1e9+?2 3 4$2e9 + +_ __ -: >._ __ +_ _ _ __ -: _ _ __ __ >. _ __ _ __ +(($t)$_) -: _ >. t=.?2 3$2 +(($t)$_) -: _ >. t=._1e9+?2 3 4$2e9 +(($t)$_) -: _ >. t=.o._1e9+?2 3 4$2e9 +t -: __ >. t=.?2 3$2 +t -: __ >. t=._1e9+?2 3 4$2e9 +t -: __ >. t=.o._1e9+?2 3 4$2e9 +__ -: >./'' + +_ __ -: >: _ __ +1 1 0 1 -: _ _ __ __ >: _ __ _ __ +*./, _ >: ?2 3$2 +*./, _ >: _1e9+?2 3 4$2e9 +*./, _ >: o._1e9+?2 3 4$2e9 +*./, 0=__ >: ?2 3$2 +*./, 0=__ >: _1e9+?2 3 4$2e9 +*./, 0=__ >: o._1e9+?2 3 4$2e9 +*./, 0= _ >:~ ?2 3$2 +*./, 0= _ >:~ _1e9+?2 3 4$2e9 +*./, 0= _ >:~ o._1e9+?2 3 4$2e9 +*./, __ >:~ ?2 3$2 +*./, __ >:~ _1e9+?2 3 4$2e9 +*./, __ >:~ o._1e9+?2 3 4$2e9 + +_ __ eq + _ __ +_ __ eq _ __ + _ __ + +'NaN error' -: _ + etx __ +'NaN error' -: __ + etx _ + +*./, _ = _ + ?2 3$2 +*./, _ = _ + _1e9+?2 3 4$2e9 +*./, _ = _ + o._1e9+?2 3 4$2e9 +*./, _ = _ + }.0j1,o._1e9+?12$2e9 +*./, __ = __ + ?2 3$2 +*./, __ = __ + _1e9+?2 3 4$2e9 +*./, __ = __ + o._1e9+?2 3 4$2e9 +*./, __ = __ + }.0j1,o._1e9+?12$2e9 + +(_ __,.0 0) -: +. _ __ +NB. _ _ _ _ -: _ _ __ __ +. _ __ _ __ +NB. *./, _ = _ +. ?2 3$2 +NB. *./, _ = _ +. _1e9+?2 3 4$2e9 +NB. *./, _ = _ +. o._1e9+?2 3 4$2e9 +NB. *./, _ = _ +. j./_1e9+?2 3 4$2e9 +NB. *./, _ = __ +. ?2 3$2 +NB. *./, _ = __ +. _1e9+?2 3 4$2e9 +NB. *./, _ = __ +. o._1e9+?2 3 4$2e9 +NB. *./, _ = __ +. j./_1e9+?2 3 4$2e9 + +_ __ -: +: _ __ + +1 _1 -: * _ __ +_ __ __ _ eq _ _ __ __ * _ __ _ __ +(-~0.5 0.5) eq 0 * _ __ +(-~0.5 0.5) eq _ __ * 0 +(-~0.5) eq _ * 0 +(-~0.5) eq _ * -~5 +(-~0.5) eq _ * -~0.5 +0 = _ * -~0j5 +(-~0.5) eq __ * 0 +(-~0.5) eq __ * -~5 +(-~0.5) eq __ * -~0.5 +0 = __ * -~0j5 +((*a){0 _ __) eq _ * a=.?2 3$2 +((*a){0 _ __) eq _ * a=._1e9+?2 3 4$2e9 +((*a){0 _ __) eq _ * a=.o._1e9+?2 3 4$2e9 +((*a){0 __ _) eq __ * a=.?2 3$2 +((*a){0 __ _) eq __ * a=._1e9+?2 3 4$2e9 +((*a){0 __ _) eq __ * a=.o._1e9+?2 3 4$2e9 + +NB. _ -: *. _ +NB. _ad180 -: *. __ +NB. _ar3.14159265358979 -: *. __ +NB. _ __ __ _ -: _ _ __ __ *. _ __ _ __ +NB. _. _. eq 0 *. _ __ +NB. _. _. eq _ __ *. 0 + +'NaN error' -: _ *. etx a=.?2 3$2 +'NaN error' -: _ *. etx a=._1e9+?2 3 4$2e9 +'NaN error' -: _ *. etx a=.o._1e9+?2 3 4$2e9 +'NaN error' -: __ *. etx a=.?2 3$2 +'NaN error' -: __ *. etx a=._1e9+?2 3 4$2e9 +'NaN error' -: __ *. etx a=.o._1e9+?2 3 4$2e9 + +_ _ -: *: _ __ + +__ _ -: - _ __ + +_ __ eq _ __ - __ _ + +'NaN error' -: _ - etx _ +'NaN error' -: __ - etx __ + +*./, _ = _ - ?2 3$2 +*./, _ = _ - _1e9+?2 3 4$2e9 +*./, _ = _ - o._1e9+?2 3 4$2e9 +*./, _ = _ - }.0j1,_1e9+?24$2e9 +*./, __ = __ - ?2 3$2 +*./, __ = __ - _1e9+?2 3 4$2e9 +*./, __ = __ - o._1e9+?2 3 4$2e9 +*./, __ = __ - }.0j1,_1e9+?24$2e9 +*./, __ = _ -~ ?2 3$2 +*./, __ = _ -~ _1e9+?2 3 4$2e9 +*./, __ = _ -~ o._1e9+?2 3 4$2e9 +*./, __ = _ -~ }.0j1,_1e9+?24$2e9 +*./, _ = __ -~ ?2 3$2 +*./, _ = __ -~ _1e9+?2 3 4$2e9 +*./, _ = __ -~ o._1e9+?2 3 4$2e9 +*./, _ = __ -~ }.0j1,_1e9+?24$2e9 + +__ _ -: -. _ __ +'' -: _ -. _ +'' -: __ -. __ +'' -: _ __ -. __ _ +a -: (a,_ __) -. _ __ [ a=.?20$1e9 +__ _ -: (__ _,a) -. a=.?20$1e9 + +_ __ eq -: _ __ +_ -: _ +__ -: __ +0 -: _ -: __ +0 -: _ -: ?2e9 +0 -: __ -: -?2e9 + +0 0 -: % _ __ +_ eq % 0 +NB. _. _. _. _. eq _ _ __ __ % _ __ _ __ +0 0 -: 0 % _ __ +_ __ eq _ __ % 0 +((*a){0 _ __) eq (a=._1e9+?2 3 4$2e9) % 0 +((*a){_ _ __) eq _ % a=.?2 3$2 +((*a){_ _ __) eq _ % a=._1e9+?2 3 4$2e9 +((*a){_ _ __) eq _ % a=.o._1e9+?2 3 4$2e9 +((*a){__ __ _) eq __ % a=.?2 3$2 +((*a){__ __ _) eq __ % a=._1e9+?2 3 4$2e9 +((*a){__ __ _) eq __ % a=.o._1e9+?2 3 4$2e9 +(($a)$0) -: _ %~ a=.?2 3$2 +(($a)$0) -: _ %~ a=._1e9+?2 3 4$2e9 +(($a)$0) -: _ %~ a=.o._1e9+?2 3 4$2e9 +(($a)$0) -: __ %~ a=.?2 3$2 +(($a)$0) -: __ %~ a=._1e9+?2 3 4$2e9 +(($a)$0) -: __ %~ a=.o._1e9+?2 3 4$2e9 + +_ -: %: _ +NB. _ad180 -: %: __ +NB. _ar3.14159265358979 -: %: __ +1 1 1 1 -: _ _ __ __ %: _ __ _ __ +1 1 1 1 1 -: _ %: _2 _1 0 1 2 +1 1 1 1 1 -: __ %: _2 _1 0 1 2 +(($a)$1) -: _ %: a=.?2 34$2 +(($a)$1) -: _ %: a=._1e9+?2 34$2e9 +(($a)$1) -: _ %: a=.o._1e9+?2 34$2e9 +(($a)$1) -: _ %: a=.j./_1e9+?2 34$2e9 +(($a)$1) -: __ %: a=.?2 34$2 +(($a)$1) -: __ %: a=._1e9+?2 34$2e9 +(($a)$1) -: __ %: a=.o._1e9+?2 34$2e9 +(($a)$1) -: __ %: a=.j./_1e9+?2 34$2e9 + +_ 0 -: ^ _ __ +NB. _ 0 _. _. -: _ _ __ __ ^ _ __ _ __ + +(,'_') -: ": _ + +4!:55 ;:'a eq t' + +
new file mode 100644 --- /dev/null +++ b/test/g030a.ijs @@ -0,0 +1,16 @@ +NB. _ locales ----------------------------------------------------------- + +f=. f_a_ / +x=. _500+?50$1000 + +f_a_ =. + +(+ /x) -: f x + +f_a_ =. >. +(>./x) -: f x + +18!:55 ;:'a' + +4!:55 ;:'f x' + +
new file mode 100644 --- /dev/null +++ b/test/g031.ijs @@ -0,0 +1,38 @@ +NB. _. ------------------------------------------------------------------ + +0 $ 0 : 0 +_. = _. +0 = _. = _ +0 = _. = __ + +'_.' -: ": _. +'_.' -: ": _ + __ +'_.' -: ": __ + _ +'_.' -: ": _ - _ +'_.' -: ": __ - __ +'_.' -: ": _ % _ +'_.' -: ": _ % __ +'_.' -: ": __ % _ +'_.' -: ": __ % __ + +_. -: _. +0 -: _. -: _ +0 -: _. -: __ +) + +8 -: (3!:0) _. + +'NaN error' -: ex '_. ". ''circ''' + + +NB. conversion of _0 to 0 in place -------------------------------------- + +x=: 20$_. +1 [ x i.!.0 ]1 2 3 4 +(3!:1 x) -: 3!:1 ($x)$_. + + +4!:55 ;:'x' + + +
new file mode 100644 --- /dev/null +++ b/test/g032.ijs @@ -0,0 +1,39 @@ +NB. _: ------------------------------------------------------------------ + +_ -: _: 1=?2 3 4$2 +_ -: _: a.{~? 10##a. +_ -: _: _20+?3 2$40 +_ -: _: o. _20+?13$40 +_ -: _: r.?13$40 + +_ -: (1=?2 3 4$2 ) _: 1=?2 3 4$2 +_ -: (1=?2 3 4$2 ) _: a.{~? 10##a. +_ -: (1=?2 3 4$2 ) _: _20+?3 2$40 +_ -: (1=?2 3 4$2 ) _: o. _20+?13$40 +_ -: (1=?2 3 4$2 ) _: r.?13$40 + +_ -: (a.{~? 10##a. ) _: 1=?2 3 4$2 +_ -: (a.{~? 10##a. ) _: a.{~? 10##a. +_ -: (a.{~? 10##a. ) _: _20+?3 2$40 +_ -: (a.{~? 10##a. ) _: o. _20+?13$40 +_ -: (a.{~? 10##a. ) _: r.?13$40 + +_ -: (_20+?3 2$40 ) _: 1=?2 3 4$2 +_ -: (_20+?3 2$40 ) _: a.{~? 10##a. +_ -: (_20+?3 2$40 ) _: _20+?3 2$40 +_ -: (_20+?3 2$40 ) _: o. _20+?13$40 +_ -: (_20+?3 2$40 ) _: r.?13$40 + +_ -: (o. _20+?13$40) _: 1=?2 3 4$2 +_ -: (o. _20+?13$40) _: a.{~? 10##a. +_ -: (o. _20+?13$40) _: _20+?3 2$40 +_ -: (o. _20+?13$40) _: o. _20+?13$40 +_ -: (o. _20+?13$40) _: r.?13$40 + +_ -: (r.?13$40 ) _: 1=?2 3 4$2 +_ -: (r.?13$40 ) _: a.{~? 10##a. +_ -: (r.?13$40 ) _: _20+?3 2$40 +_ -: (r.?13$40 ) _: o. _20+?13$40 +_ -: (r.?13$40 ) _: r.?13$40 + +
new file mode 100644 --- /dev/null +++ b/test/g0a.ijs @@ -0,0 +1,37 @@ +NB. handling empty arrays ----------------------------------------------- + +(i.n) -: /: (n,0 5)$0 [ n=.0 +(i.n) -: /: (n,0 )$0 [ n=.?1000 +(i.n) -: /: (n,0 )$'a' [ n=.0 +(i.n) -: /: (n,4 0)$'a' [ n=.?1000 +(i.n) -: /: i.n,0 5 [ n=.0 +(i.n) -: /: i.n,0 [ n=.?1000 +(i.n) -: /: (n,0 5)$3.4 [ n=.0 +(i.n) -: /: (n,0 )$3.4 [ n=.?1000 +(i.n) -: /: (n,0 5)$3j4 [ n=.0 +(i.n) -: /: (n,0 )$3j4 [ n=.?1000 +(i.n) -: /: (n,0 5)$<'a' [ n=.0 +(i.n) -: /: (n,0 )$<'a' [ n=.?1000 + +(i.n) -: \: (n,0 5)$0 [ n=.0 +(i.n) -: \: (n,0 )$0 [ n=.?1000 +(i.n) -: \: (n,0 )$'a' [ n=.0 +(i.n) -: \: (n,4 0)$'a' [ n=.?1000 +(i.n) -: \: i.n,0 5 [ n=.0 +(i.n) -: \: i.n,0 [ n=.?1000 +(i.n) -: \: (n,0 5)$3.4 [ n=.0 +(i.n) -: \: (n,0 )$3.4 [ n=.?1000 +(i.n) -: \: (n,0 5)$3j4 [ n=.0 +(i.n) -: \: (n,0 )$3j4 [ n=.?1000 +(i.n) -: \: (n,0 5)$<'a' [ n=.0 +(i.n) -: \: (n,0 )$<'a' [ n=.?1000 + +(":0 2 3$'a') -: ":0 2 3$1 +(":0 2 3$'a') -: ":0 2 3$4 +(":0 2 3$'a') -: ":0 2 3$3.4 +(":0 2 3$'a') -: ":0 2 3$3j4 +(":0 2 3$'a') -: ":0 2 3$<'a' + +4!:55 ;:'n' + +
new file mode 100644 --- /dev/null +++ b/test/g0x.ijs @@ -0,0 +1,46 @@ +NB. 0!: ----------------------------------------------------------------- + +sc00 =: 0!:0 + +lf =: 10{a. +mtv =: '' +mtm =: i.0 0 + +mtm -: sc00 '3+4',lf,'#''Cogito, ergo sum.''' +mtm -: sc00 'i.2 3 4',lf,'3+4' +mtm -: sc00 'i.2 2 2 2 2 2',lf,';:''Cogito, ergo sum.''' +mtm -: sc00 '' +mtm -: sc00 20$' ' + +l0 =: 'i.20',lf,'mtm -: sc00 l1',lf,'i.20' +l1 =: 'i.21',lf,'mtm -: sc00 l2',lf,'i.21' +l2 =: 'i.22' +mtm -: sc00 l0 + +t=:,('abc',.'=:',"1 ":x=:?3 2000$10000),"1 lf +mtm -: sc00 t +a -: 0{x +b -: 1{x +c -: 2{x + +1 [ 0!:0 'x=: ''',(1050$'x'),'''' + +1 [ 0!:100 'a=: 12345',:'b=: i.3 4' +a -: 12345 +b -: i.3 4 + +'domain error' -: 0!: 0 etx 0 +'domain error' -: 0!: 0 etx 2 +'domain error' -: 0!: 1 etx 0 +'domain error' -: 0!: 1 etx 2 +'domain error' -: 0!:10 etx 0 +'domain error' -: 0!:10 etx 2 +'domain error' -: 0!:11 etx 0 +'domain error' -: 0!:11 etx 2 +'domain error' -: 0!:11 etx 0 +'domain error' -: 0!:11 etx 2 + +4!:55 ;:'a b c l0 ' +4!:55 ;:'l1 l2 lf mtm mtv s sc00 t x ' + +
new file mode 100644 --- /dev/null +++ b/test/g100.ijs @@ -0,0 +1,141 @@ +NB. +y ------------------------------------------------------------------ + +t -: +t=.1=?100$2 +t -: +t=. _1e9+?100$2e9 +t -: +t=.o.1e_9+?100$2e9 + +f =. |@*~ % ] +test =. f -: + +test j./_1e9+?2 100$2e9 +test r./_1e7+?2 100$2e7 +test 0 3j4 + +3j_4 -: +3j4 + +'domain error' -: + etx 'abc' +'domain error' -: + etx <'abc' +'domain error' -: + etx <3 4 5 + + +NB. x+y ----------------------------------------------------------------- + +4 = type 1234+5678 +4 = type _1234+_5678 +4 = type 2e9 +4 = type _2e9 +4 = type 2147483647 + +(IF64{8 4) = type 2e9 +3e8 +(IF64{8 4) = type 2e15+3e15 +(IF64{8 4) = type _2e9 +_3e8 +(IF64{8 4) = type _2e15+_3e15 +(IF64{8 4) = type 2147483647+1 + +x=: - y=: 1+i.100 +(x + <._1+2^IF64{31 63x) -: x + <._1+2^IF64{31 63 +(y + <. -2^IF64{31 63x) -: y + <. -2^IF64{31 63 + +( 2e8*>:i.20) -: +/\20$ 2e8 +(_2e8*>:i.20) -: +/\20$_2e8 + +4 -: 2 + 2 +3 -: 7 + _4 + +2147483648 -: 1+ 2147483647 +_2147483649 -: _1+_2147483648 + +t -: 3+t=.i.?27$2 +t -: (t=.i.?27$2)+4 +t -: (i.3 4)+t=.i.3 4,?27$2 +t -: (t=.i.3 4,?27$2)+i.3 4 + + +NB. complex numbers ----------------------------------------------------- + +16 -: type 3j4 5j6 + +(2 3$1 0) -: =3j4 5j6 3j4 +1 0 1 -: 3j4 = 3j4 3j_4 3j4 +a=.3j4 +3j4 -: a +b=:3j4 +3j4 -: b + +(3j4;5j6;7j8) -: (<3j4),(<5j6),<7j8 +0 0j1 1 1 -: <. 0.2j0.2 0.2j0.8 0.8j0.2 0.8j0.8 +2j4 -: <:3j4 + +3j4 -: ><3j4 +(<.&.-t) -: >.t=.0.2j0.2 0.2j0.8 0.8j0.2 0.8j0.8 +4j4 -: >:3j4 + +3j_4 -: +3j4 +8j10 -: 3j4+5j6 +3 4 -: +.3j4 +1j1 -: 5j11 +. 3j7 + +'domain error' -: 'abc' + etx 4 +'domain error' -: 'abc' +~etx 4 +'domain error' -: 4 + etx <'abc' +'domain error' -: 4 +~etx <'abc' +'domain error' -: 'j' + etx <'abc' +'domain error' -: 'j' +~etx <'abc' + +'length error' -: 3 4 + etx 5 6 7 +'length error' -: 3 4 +~etx 5 6 7 +'length error' -: 3 4 + etx i.5 6 +'length error' -: 3 4 +~etx i.5 6 +'length error' -: 3 4 5 + etx i.4 3 +'length error' -: 3 4 5 +~etx i.4 3 + + +NB. x+y integer overflow handling --------------------------------------- + +test =. + 0&=@:- +&((o.0)&+) +testa =. (+/ 0&=@:- +/ @((o.0)&+))@,"0 +testb =. (+/\ 0&=@:- +/\ @((o.0)&+))@,"0 +testc =. (+/\. 0&=@:- +/\.@((o.0)&+))@,"0 +x =: <._1+2^IF64{31 62 +y =: <. -2^IF64{31 62 + +4 = type&> _1 0 +&.> x +4 = type&> _1 0 +&.>~x +4 = type&> 1 0 +&.> y +4 = type&> 1 0 +&.>~y + +4 = type&> _1 0 +/@,&.> x +4 = type&> _1 0 +/@,&.>~x +4 = type&> 1 0 +/@,&.> y +4 = type&> 1 0 +/@,&.>~y + +4 = type&> _1 0 +/\@,&.> x +4 = type&> _1 0 +/\@,&.>~x +4 = type&> 1 0 +/\@,&.> y +4 = type&> 1 0 +/\@,&.>~y + +4 = type&> _1 0 +/\.@,&.> x +4 = type&> _1 0 +/\.@,&.>~x +4 = type&> 1 0 +/\.@,&.> y +4 = type&> 1 0 +/\.@,&.>~y + +,(2e9 2e9 _2e9 _2e9) test &>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) test &>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testa&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testa&>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testb&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testb&>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testc&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testc&>/~1e9 _1e9 1e9 _1e9 + +,_2 _1 0 1 2 test &>/ x,y +,_2 _1 0 1 2 test &>/~x,y +,_2 _1 0 1 2 testa&>/ x,y +,_2 _1 0 1 2 testa&>/~x,y +,_2 _1 0 1 2 testb&>/ x,y +,_2 _1 0 1 2 testb&>/ x,y +,_2 _1 0 1 2 testc&>/~x,y +,_2 _1 0 1 2 testc&>/~x,y + +4!:55 ;:'a b f t test testa testb testc x y' + +
new file mode 100644 --- /dev/null +++ b/test/g100a.ijs @@ -0,0 +1,151 @@ +NB. B + B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x+y) -: (#.x,.y){0 1 1 2 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.?2 +(x+z) -: x+($x)$z [ z=.?2 + +(x+y) -: (40$"0 x)+y [ x=. ?10$2 [ y=. ?10 40$2 +(x+y) -: x+40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 1 2 -: 0 0 1 1 + 0 1 0 1 + +'domain error' -: 1 0 1 + etx 'abc' +'domain error' -: 1 0 1 + etx <123 + + +NB. B + I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.?2 +(x+z) -: x+($x)$z [ z=._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +_4 _3 _2 _1 1 2 3 4 -: 0 0 0 0 1 1 1 1 + _4 _3 _2 _1 0 1 2 3 +((2^31),_2147483647) -: 1 + 2147483647 _2147483648 + + +NB. B + D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.?2 +(x+z) -: x+($x)$z [ z=.o._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +2.5 1.5 1.5 0.5 _0.5 -: 0 0 1 1 1 + 2.5 1.5 0.5 _0.5 _1.5 + + +NB. I + B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=._1e5+?2e5 +(x+z) -: x+($x)$z [ z=.?2 + +(x+y) -: (40$"0 x)+y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x+y) -: x+40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +6 5 9 -: 6 4 9 + 0 1 0 +((2^31),_2147483647) -: 2147483647 _2147483648 + 1 + +'domain error' -: 1 2 3 + etx 'abc' +'domain error' -: 1 2 3 + etx <123 + + +NB. I + I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.?2e6 +(x+z) -: x+($x)$z [ z=._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +3 4 5 6 -: 3+i.4 +3 2e9 -: 1 5e8+2 15e8 +4e9 -: 2e9+2e9 + + +NB. I + D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.?2e6 +(x+z) -: x+($x)$z [ z=.o._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +3.5 4.5 5.5 6.5 -: (i.4)+3.5 + + +NB. D + B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.o._1e5+?2e5 +(x+z) -: x+($x)$z [ z=.?2 + +(x+y) -: (40$"0 x)+y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x+y) -: x+40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +1.25 -: 0.25 + 1 + +'domain error' -: 1.2 2 3 + etx 'abc' +'domain error' -: 1.2 2 3 + etx <123 + + +NB. D + I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.o._1e5+?2e5 +(x+z) -: x+($x)$z [ z=._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +5.1415926 -: 3.1415926 + 2 + + +NB. D + D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x+y) -: (z+x)+z+y [ z=.{.0 4.5 +(x+y) -: (z*x)+z*y [ z=.{.1 4j5 +(z+y) -: (($y)$z)+y [ z=.o._1e5+?2e5 +(x+z) -: x+($x)$z [ z=.o._1e5+?2e5 + +(x+y) -: (40$"0 x)+y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x+y) -: x+40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +10.5 _10.5 -: 9.1 _10 + 1.4 _0.5 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g100i.ijs @@ -0,0 +1,113 @@ +NB. +/ B ---------------------------------------------------------------- + +f=: 3 : 'y -: +/y$1' +f"0 ?2 10$1e5 +f"0 i.4 10 +f"0 [_1 0 1+ 255 +f"0 [_1 0 1+4*255 +f"0 [_1 0 1+8*255 + +f=: 3 : 'y -: +/(i.5e3) e. y?5e3' +f"0 ?2 10$4e3 +f"0 i.4 10 +f"0 [_1 0 1+ 255 +f"0 [_1 0 1+4*255 +f"0 [_1 0 1+8*255 + +f=: 3 : 'n -: +/(i.y) e. (n=.<.-:y)?y' +f"0 ?2 10$1e4 +f"0 i.4 10 +f"0 [_1 0 1+ 255 +f"0 [_1 0 1+4*255 +f"0 [_1 0 1+8*255 + +f=: 3 : '($/|.y) -: +/y$1' +,f"1 ,."0 1~i.10 +,f"1 x=:7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+8*255 +,f"1 |."1 x + +f=: 3 : '200 -: +/+/(i.y) e. 200?*/y' +,f"1 x=:7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+8*255 +,f"1 |."1 x + +plus=: 4 : 'x+y' + +f=: 3 : '(+/ -: plus/) y ?@$ 2' +,f"1 x=:7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x +,f"1 x=:7 8 9,."0 1 [ _1 0 1+8*255 +,f"1 |."1 x + + +NB. +/ I ---------------------------------------------------------------- + +plus=: 4 : 'x+y' + +(+/ -: plus/) x=:1 2 3 1e9 2e9 +(+/ -: plus/) |.x + +(+/ -: plus/ ) x=:_1e4+? 23$2e4 +(+/ -: plus/ ) x=:_1e4+?4 23$2e4 +(+/"1 -: plus/"1) x +(+/ -: plus/ ) x=:_1e4+?7 5 23$2e4 +(+/"1 -: plus/"1) x +(+/"2 -: plus/"2) x + +(+/ -: plus/ ) x=:_1e9+? 23$2e9 +(+/ -: plus/ ) x=:_1e9+?4 23$2e9 +(+/"1 -: plus/"1) x +(+/ -: plus/ ) x=:_1e9+?7 5 23$2e9 +(+/"1 -: plus/"1) x +(+/"2 -: plus/"2) x + + +NB. +/ D ---------------------------------------------------------------- + +plus=: 4 : 'x+y' + +(+/ -: plus/ ) x=:0.01*_1e9+? 11$2e9 +(+/ -: plus/ ) x=:0.01*_1e9+?4 11$2e9 +(+/"1 -: plus/"1) x +(+/ -: plus/ ) x=:0.01*_1e9+?7 5 11$2e9 +(+/"1 -: plus/"1) x +(+/"2 -: plus/"2) x + + +NB. +/ Z ---------------------------------------------------------------- + +plus=: 4 : 'x+y' + +(+/ -: plus/ ) x=:j./0.01*_1e9+?2 11$2e9 +(+/ -: plus/ ) x=:j./0.01*_1e9+?2 4 11$2e9 +(+/"1 -: plus/"1) x +(+/ -: plus/ ) x=:j./0.01*_1e9+?2 7 5 11$2e9 +(+/"1 -: plus/"1) x +(+/"2 -: plus/"2) x + + +NB. +/ X ---------------------------------------------------------------- + +(+/ -: +/ @:x:) x=:_1e5+?2 7 5 23$2e5 +(+/"1 -: +/"1@:x:) x +(+/"2 -: +/"2@:x:) x +(+/"3 -: +/"3@:x:) x + +'domain error' -: +/ etx 3 4$'abc' +'domain error' -: +/"1 etx 3 4$'abc' +'domain error' -: +/ etx ;:'modus operandi' +'domain error' -: +/"1 etx 3 4$;:'I think not' + + +4!:55 ;:'f plus x' + +
new file mode 100644 --- /dev/null +++ b/test/g100p.ijs @@ -0,0 +1,75 @@ +NB. +/\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 1 1 2) -: +/\ 0 0 1 1 ,: 0 1 0 1 +(>:i.20) -: +/\20$1 + +plus=. 4 : 'x+y' + +(+/\ -: plus/\ ) x=.? 13$2 +(+/\ -: plus/\ ) x=.?7 13$2 +(+/\"1 -: plus/\"1) x +(+/\ -: plus/\ ) x=.?3 5 13$2 +(+/\"1 -: plus/\"1) x +(+/\"2 -: plus/\"2) x +(+/\ -: plus/\ ) x=.? 12$2 +(+/\ -: plus/\ ) x=.?4 12$2 +(+/\"1 -: plus/\"1) x +(+/\ -: plus/\ ) x=.?4 8 12$2 +(+/\"1 -: plus/\"1) x +(+/\"2 -: plus/\"2) x + + +NB. +/\ I --------------------------------------------------------------- + +plus=. 4 : 'x+y' + +(+/\ -: plus/\) x=.1 2 3 1e9 2e9 +(+/\ -: plus/\) |.x + +(+/\ -: plus/\ ) x=._1e4+? 13$2e4 +(+/\ -: plus/\ ) x=._1e4+?4 13$2e4 +(+/\"1 -: plus/\"1) x +(+/\ -: plus/\ ) x=._1e4+?3 5 13$2e4 +(+/\"1 -: plus/\"1) x +(+/\"2 -: plus/\"2) x + +(+/\ -: plus/\ ) x=._1e9+? 13$2e9 +(+/\ -: plus/\ ) x=._1e9+?4 13$2e9 +(+/\"1 -: plus/\"1) x +(+/\ -: plus/\ ) x=._1e9+?3 5 13$2e9 +(+/\"1 -: plus/\"1) x +(+/\"2 -: plus/\"2) x + + +NB. +/\ D --------------------------------------------------------------- + +plus=. 4 : 'x+y' + +1e_12 > >./ | , (+/\ - plus/\ ) x=.0.01*_1e4+? 13$2e4 +1e_12 > >./ | , (+/\ - plus/\ ) x=.0.01*_1e4+?4 13$2e4 +1e_12 > >./ | , (+/\"1 - plus/\"1) x +1e_12 > >./ | , (+/\ - plus/\ ) x=.0.01*_1e4+?3 5 13$2e4 +1e_12 > >./ | , (+/\"1 - plus/\"1) x +1e_12 > >./ | , (+/\"2 - plus/\"2) x + + +NB. +/\. Z --------------------------------------------------------------- + +plus=. 4 : 'x+y' + +1e_12 > >./ | , (+/\ - plus/\ ) x=.j./0.1*_1e2+?2 13$2e2 +1e_12 > >./ | , (+/\ - plus/\ ) x=.j./0.1*_1e2+?2 4 13$2e2 +1e_12 > >./ | , (+/\"1 - plus/\"1) x +1e_12 > >./ | , (+/\ - plus/\ ) x=.j./0.1*_1e2+?2 3 5 13$2e2 +1e_12 > >./ | , (+/\"1 - plus/\"1) x +1e_12 > >./ | , (+/\"2 - plus/\"2) x + +(,'j') -: +/\'j' +(,<'ace') -: +/\<'ace' + +'domain error' -: +/\ etx 'deipnosophist' +'domain error' -: +/\ etx ;:'peace in our time' + +4!:55 ;:'f plus x' + +
new file mode 100644 --- /dev/null +++ b/test/g100s.ijs @@ -0,0 +1,72 @@ +NB. +/\. B -------------------------------------------------------------- + +(20$1) -: +/\._20{.1 +(>:i.-20) -: +/\.20$1 + +plus=: 4 : 'x+y' + +f=: 3 : '(+/\. -: plus/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. +/\. I -------------------------------------------------------------- + +(2!>:i.20) -: +/\.&.|. i.20 + +plus=: 4 : 'x+y' + +(+/\. -: plus/\.) x=.1 2 3 1e9 2e9 +(+/\. -: plus/\.) |.x + +(+/\. -: plus/\. ) x=._1e4+? 23$2e4 +(+/\. -: plus/\. ) x=._1e4+?4 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\. -: plus/\. ) x=._1e4+?7 5 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\."2 -: plus/\."2) x + +(+/\. -: plus/\. ) x=._1e9+? 23$2e9 +(+/\. -: plus/\. ) x=._1e9+?4 23$2e9 +(+/\."1 -: plus/\."1) x +(+/\. -: plus/\. ) x=._1e9+?7 5 23$2e9 +(+/\."1 -: plus/\."1) x +(+/\."2 -: plus/\."2) x + + +NB. +/\. D -------------------------------------------------------------- + +(2!>:i.20) -: +/\.&.|. [&.o. i.20 + +plus=: 4 : 'x+y' + +(+/\. -: plus/\. ) x=.(2^_8)*_1e4+? 23$2e4 +(+/\. -: plus/\. ) x=.(2^_8)*_1e4+?4 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\. -: plus/\. ) x=.(2^_8)*_1e4+?7 5 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\."2 -: plus/\."2) x + + +NB. +/\. Z -------------------------------------------------------------- + +(2!>:i.20) -: +/\.&.|. [&.j. i.20 + +plus=: 4 : 'x+y' + +(+/\. -: plus/\. ) x=.j./(2^_8)*_1e4+?2 23$2e4 +(+/\. -: plus/\. ) x=.j./(2^_8)*_1e4+?2 4 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\. -: plus/\. ) x=.j./(2^_8)*_1e4+?2 7 5 23$2e4 +(+/\."1 -: plus/\."1) x +(+/\."2 -: plus/\."2) x + +'domain error' -: +/\. etx 'deipnosophist' +'domain error' -: +/\. etx ;:'sui generis' + + +4!:55 ;:'f plus x' + +
new file mode 100644 --- /dev/null +++ b/test/g101.ijs @@ -0,0 +1,69 @@ +NB. +.y ---------------------------------------------------------------- + +f =. 9 11&o."0"_ + +(f -: +.) r.?10 20$1000 +(f -: +.) 0.1*_500+?200$1000 + +a -: [&.+. a=.0.1*_50j_50+j.&?~100$100 + +0 0 -: +. 0 +1 0 -: +. 1 +3 0 -: +. 3 +3.4 0 -: +. 3.4 +3 4 -: +. 3j4 + +8 -: 3!:0 +. r.?10$1000 + +'domain error' -: +. etx 'abc' +'domain error' -: +. etx <'abc' + + +NB. x+.y --------------------------------------------------------------- + +0 1 1 1 -: 0 0 1 1 +. 0 1 0 1 +(12$6 1 2 3 2 1) -: 6 +. i.12 +1j1 -: 5j11 +. 3j7 + +x=: j./ _50 + 2 10000 ?@$ 100 +y=: j./ _50 + 2 10000 ?@$ 100 +(x+.y) -: y+.x +x=: j./ _5000 + 2 10000 ?@$ 10000 +y=: j./ _5000 + 2 10000 ?@$ 10000 +(x+.y) -: y+.x + +'domain error' -: 'abc' +. etx 4 +'domain error' -: 'abc' +.~etx 4 +'domain error' -: 4 +. etx <'abc' +'domain error' -: 4 +.~etx <'abc' +'domain error' -: 'j' +. etx <'abc' +'domain error' -: 'j' +.~etx <'abc' + +'length error' -: 0 1 +. etx 0 1 0 +'length error' -: 0 1 +.~etx 5 6 7 +'length error' -: 0 1 +. etx i.5 6 +'length error' -: 0 1 +.~etx i.5 6 +'length error' -: 0 1 1 +. etx ?4 3$2 +'length error' -: 3 4 5 +.~etx ?4 3$2 + + +NB. x+.y, GCD as a linear combination of x and y ------------------------ + +gcd =: 3 : 0 NB. (x+.y)=+/(x,y)*x gcd y + : + m=.x,1 0 + n=.y,0 1 + while. {.m do. n=.t [ m=.n-m*<.n %&{. t=.m end. + }.n +) + +init =. , ,. =@i.@2: +iter =. {: ,: {. - {: * <.@%&{./ +gcd1 =. (}.@{.) @ (iter^:(*@{.@{:)^:_) @ init + +(+./ -: [ +/ .* gcd /)"1 x=.?3 10 2$100 +(+./ -: [ +/ .* gcd1/)"1 x + +4!:55 ;:'a f gcd gcd1 init iter x y' + +
new file mode 100644 --- /dev/null +++ b/test/g101a.ijs @@ -0,0 +1,62 @@ +NB. B +. B -------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x+.y) -: (#.x,.y){0 1 1 1 +(x+.y) -: (z+x)+.z+y [ z=.{.0 4.5 +(z+.y) -: (($y)$z)+.y [ z=.?2 +(x+.z) -: x+.($x)$z [ z=.?2 + +(x+.y) -: (40$"0 x)+.y [ x=. ?10$2 [ y=. ?10 40$2 +(x+.y) -: x+.40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 1 1 -: 0 0 1 1 +. 0 1 0 1 + + +NB. B +. I -------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2e5 +(x+.y) -: (z+x)+.z+y [ z=.{.0 4.5 +(z+.y) -: (($y)$z)+.y [ z=.?2 +(x+.z) -: x+.($x)$z [ z=.?2e5 + +(x+.y) -: (40$"0 x)+.y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x+.y) -: x+.40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 1 1 1 -: 0 0 1 1 +. 0 1 0 1+4-4 + + +NB. I +. B -------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x+.y) -: (z+x)+.z+y [ z=.{.0 4.5 +(z+.y) -: (($y)$z)+.y [ z=._1e5+?2e5 +(x+.z) -: x+.($x)$z [ z=.?2 + +(x+.y) -: (40$"0 x)+.y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x+.y) -: x+.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 1 1 1 -: (0 0 1 1+3-3) +. 0 1 0 1 + + +NB. I +. I -------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x+.y) -: (z+x)+.z+y [ z=.{.0 4.5 +(z+.y) -: (($y)$z)+.y [ z=._1e5+?2e5 +(x+.z) -: x+.($x)$z [ z=._1e5+?2e5 + +(x+.y) -: (40$"0 x)+.y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x+.y) -: x+.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 1 1 1 -: (0 0 1 1+3-3) +. 0 1 0 1+3-3 + +'domain error' -: 1 +. etx 'chthonic' +'domain error' -: 0 0 +. etx ;:'sui generis' + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g101i.ijs @@ -0,0 +1,29 @@ +NB. +./ B --------------------------------------------------------------- + +0 1 1 1 -: +./ 0 0 1 1 ,: 0 1 0 1 +1 1 1 -: +./ #:i.8 +0 1 1 1 1 1 1 1 -: +./"1 #:i.8 + +or=: 4 : 'x+.y' + +(+./"1 -: or/"1) x=.1=?3 5 17$13 +(+./"2 -: or/"2) x +(+./"3 -: or/"3) x + +(+./"1 -: or/"1) x=.1=?3 5 32$13 +(+./"2 -: or/"2) x +(+./"3 -: or/"3) x + +(+./"1 -: or/"1) x=.1=?3 8 32$13 +(+./"2 -: or/"2) x +(+./"3 -: or/"3) x + +f=: 3 : '(+./ -: or/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f or x' + +
new file mode 100644 --- /dev/null +++ b/test/g101p.ijs @@ -0,0 +1,34 @@ +NB. +./\ B -------------------------------------------------------------- + +(0 0 1 1,:0 1 1 1) -: +./\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: +./\20$1 +(20$0) -: +./\20$0 + +or=. 4 : 'x+.y' + +(+./\"1 -: or/\"1) #:i.16 +(+./\"1 -: or/\"1) #:i.32 + +(+./\ -: or/\ ) x=.? 13$2 +(+./\ -: or/\ ) x=.?7 13$2 +(+./\"1 -: or/\"1) x +(+./\ -: or/\ ) x=.?3 5 13$2 +(+./\"1 -: or/\"1) x +(+./\"2 -: or/\"2) x + +(+./\ -: or/\ ) x=.? 16$2 +(+./\ -: or/\ ) x=.?8 16$2 +(+./\"1 -: or/\"1) x +(+./\ -: or/\ ) x=.?2 4 16$2 +(+./\"1 -: or/\"1) x +(+./\"2 -: or/\"2) x + +(,'j') -: +./\'j' +(,<'ace') -: +./\<'ace' + +'domain error' -: +./\ etx 'deipnosophist' +'domain error' -: +./\ etx ;:'peace in our time' + +4!:55 ;:'or x' + +
new file mode 100644 --- /dev/null +++ b/test/g101s.ijs @@ -0,0 +1,43 @@ +NB. +./\. B ------------------------------------------------------------- + +(0 1 1 1,:0 1 0 1) -: +./\. 0 0 1 1 ,: 0 1 0 1 + +or=: 4 : 'x+.y' + +f=: 3 : '(+./\. -: or/\.) y ?@$ 2' +f"0 x=.>:i.2 10 +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4+255 +,f"1 |."1 x + + +NB. +./\. I ------------------------------------------------------------- + +or=: 4 : 'x+.y' + +(+./\. -: or/\.) x=.1 2 3 1e2 2e2 +(+./\. -: or/\.) |.x +(+./\. -: or/\.) x=.1 2 3 1e9 2e9 +(+./\. -: or/\.) |.x + +(+./\. -: or/\. ) x=._1e4+? 23$2e4 +(+./\. -: or/\. ) x=._1e4+?4 23$2e4 +(+./\."1 -: or/\."1) x +(+./\. -: or/\. ) x=._1e4+?7 5 23$2e4 +(+./\."1 -: or/\."1) x +(+./\."2 -: or/\."2) x + +(+./\. -: or/\. ) x=._1e2+? 23$2e2 +(+./\. -: or/\. ) x=._1e2+?4 23$2e2 +(+./\."1 -: or/\."1) x +(+./\. -: or/\. ) x=._1e2+?7 5 23$2e2 +(+./\."1 -: or/\."1) x +(+./\."2 -: or/\."2) x + +'domain error' -: +./\. etx 'deipnosophist' +'domain error' -: +./\. etx ;:'professors in New Englor' + +4!:55 ;:'f or x' + +
new file mode 100644 --- /dev/null +++ b/test/g102.ijs @@ -0,0 +1,67 @@ +NB. +:y ----------------------------------------------------------------- + +test=:+~"_ -: +: +test 1=?2 3 4$2 +test _20+?50$50 +test o. _20+?50$50 +test r. ?3 4 5$100 +test i.0 3 4 +test i.3 0 + +dr =: 5!:2 +mr =: 1 : ('f=.+"x'; '{. >2{ dr <''f''') +lr =: 1 : '5!:5 <''x''' + +0 -: +: mr +0 -: -: mr +0 -: *: mr +0 -: %: mr + +(+: b. _1) -: -: lr +(-: b. _1) -: +: lr +(*: b. _1) -: %: lr +(%: b. _1) -: *: lr + +7 -: +: 3.5 + +'domain error' -: +: etx 'abc' +'domain error' -: +: etx 3;4 5 +'domain error' -: +: etx <!.0?5$2 + + +NB. x+:y ---------------------------------------------------------------- + +(2 2$1 0 0 0) -: +:/~ 0 1 +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1 + +(2 2$1 0 0 0) -: +:/~ 0 1{0 1 4 5 6 +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1{0 1 4 5 6 +1 0 0 0 -: 0 0 1 1 +:~0 1 0 1{0 1 4 5 6 + +(2 2$1 0 0 0) -: +:/~ 0 1{0 1 4.5 6 _7.89 +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1{0 1 4.5 6 _7.89 +1 0 0 0 -: 0 0 1 1 +:~0 1 0 1{0 1 4.5 6 _7.89 + +(2 2$1 0 0 0) -: +:/~ 0 1{0 1 4.5j6 _7.89 +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1{0 1 4.5j6 _7.89 +1 0 0 0 -: 0 0 1 1 +:~0 1 0 1{0 1 4.5j6 _7.89 + +'domain error' -: 0 1 +: etx 'ab' +'domain error' -: 0 1 +:~etx 'ab' +'domain error' -: 0 1 +: etx 2 +'domain error' -: 0 1 +:~etx 2 +'domain error' -: 0 1 +: etx 3.4 0 +'domain error' -: 0 1 +:~etx 3.4 0 +'domain error' -: 0 1 +: etx 0j1 1 +'domain error' -: 0 1 +:~etx 0j1 1 +'domain error' -: 1 +: etx <'asfd' +'domain error' -: 1 +:~etx <'asfd' + +'length error' -: 0 1 +: etx 0 1 0 +'length error' -: 0 1 +:~etx 0 1 0 +'length error' -: 0 1 0 +: etx ?4 3$2 +'length error' -: 0 1 0 +:~etx ?4 3$2 + +4!:55 ;:'dr lr mr test' + +
new file mode 100644 --- /dev/null +++ b/test/g102a.ijs @@ -0,0 +1,138 @@ +NB. B +: B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x+:y) -: (#.x,.y){1 0 0 0 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.?2 +(x+:z) -: x+:($x)$z [ z=.?2 + +(x+:y) -: (40$"0 x)+:y [ x=. ?10$2 [ y=. ?10 40$2 +(x+:y) -: x+:40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1 + + +NB. B +: I --------------------------------------------------------------- + +x=. ?100$2 +y=. 2|?100$2e5 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.?2 +(x+:z) -: x+:($x)$z [ z=.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. ?10$2 [ y=. 2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. ?10 40$2 [ y=. 2|?10$2e5 + +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1+4-4 + + +NB. B +: D --------------------------------------------------------------- + +x=. ?100$2 +y=. [&.o.?100$2 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.?2 +(x+:z) -: x+:($x)$z [ z=.[&.o.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. ?10$2 [ y=. [&.o.2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. ?10 40$2 [ y=. [&.o.2|?10$2e5 + +1 0 0 0 -: 0 0 1 1 +: 0 1 0 1+3.5-3.5 + + +NB. I +: B --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. ?100$2 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.2|?2e5 +(x+:z) -: x+:($x)$z [ z=.?2 + +(x+:y) -: (40$"0 x)+:y [ x=. 2|?10$2e5 [ y=. ?10 40$2 +(x+:y) -: x+:40$"0 y [ x=. 2|?10 40$2e5 [ y=. ?10$2 + +1 0 0 0 -: (0 0 1 1+3-3) +: 0 1 0 1 + + +NB. I +: I --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. 2|?100$2e5 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.2|?2e6 +(x+:z) -: x+:($x)$z [ z=.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. 2|?10$2e5 [ y=. 2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. 2|?10 40$2e5 [ y=. 2|?10$2e5 + +1 0 0 0 -: (0 0 1 1+3-3) +: 0 1 0 1+3-3 + + +NB. I +: D --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. [&.o.2|?100$2e5 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.2|?2e6 +(x+:z) -: x+:($x)$z [ z=.[&.o.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. 2|?10$2e5 [ y=. [&.o.2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. 2|?10 40$2e5 [ y=. [&.o.2|?10$2e5 + +1 0 0 0 -: (0 0 1 1+3-3) +: 0 1 0 1+3.4-3.4 + + +NB. D +: B --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. ?100$2 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.[&.o.2|?2e5 +(x+:z) -: x+:($x)$z [ z=.?2 + +(x+:y) -: (40$"0 x)+:y [ x=. [&.o.2|?10$2e5 [ y=. ?10 40$2 +(x+:y) -: x+:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. ?10$2 + +1 0 0 0 -: (0 0 1 1+3.4-3.4) +: 0 1 0 1 + + +NB. D +: I --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. 2|?100$2e5 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.[&.o.2|?2e5 +(x+:z) -: x+:($x)$z [ z=.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. [&.o.2|?10$2e5 [ y=. 2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. 2|?10$2e5 + +1 0 0 0 -: (0 0 1 1+3.4-3.4) +: 0 1 0 1+34-34 + + +NB. D +: D --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. [&.o.2|?100$2e5 +(x+:y) -: (z+x)+:z+y [ z=.{.0 4.5 +(x+:y) -: (z*x)+:z*y [ z=.{.1 4j5 +(z+:y) -: (($y)$z)+:y [ z=.[&.o.2|?2e5 +(x+:z) -: x+:($x)$z [ z=.[&.o.2|?2e5 + +(x+:y) -: (40$"0 x)+:y [ x=. [&.o.2|?10$2e5 [ y=. [&.o.2|?10 40$2e5 +(x+:y) -: x+:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. [&.o.2|?10$2e5 + +1 0 0 0 -: (0 0 1 1+3.4-3.4) +: 0 1 0 1+3.4-3.4 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g102i.ijs @@ -0,0 +1,27 @@ +NB. +:/ B --------------------------------------------------------------- + +1 0 0 0 -: +:/ 0 0 1 1 ,: 0 1 0 1 + +nor=: 4 : 'x+:y' + +(+:/"1 -: nor/"1) x=.?3 5 17$2 +(+:/"2 -: nor/"2) x +(+:/"3 -: nor/"3) x + +(+:/"1 -: nor/"1) x=.?3 5 32$2 +(+:/"2 -: nor/"2) x +(+:/"3 -: nor/"3) x + +(+:/"1 -: nor/"1) x=.?3 8 32$2 +(+:/"2 -: nor/"2) x +(+:/"3 -: nor/"3) x + +f=: 3 : '(+:/ -: nor/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f nor x' + +
new file mode 100644 --- /dev/null +++ b/test/g102p.ijs @@ -0,0 +1,34 @@ +NB. +:/\ B -------------------------------------------------------------- + +(0 0 1 1,:1 0 0 0) -: +:/\ 0 0 1 1 ,: 0 1 0 1 +(20{.1) -: +:/\20$1 +(20$0 1) -: +:/\20$0 + +nor=. 4 : 'x+:y' + +(+:/\"1 -: nor/\"1) #:i.16 +(+:/\"1 -: nor/\"1) #:i.32 + +(+:/\ -: nor/\ ) x=.0=? 13$4 +(+:/\ -: nor/\ ) x=.0=?7 13$4 +(+:/\"1 -: nor/\"1) x +(+:/\ -: nor/\ ) x=.0=?3 5 13$4 +(+:/\"1 -: nor/\"1) x +(+:/\"2 -: nor/\"2) x + +(+:/\ -: nor/\ ) x=.0=? 16$4 +(+:/\ -: nor/\ ) x=.0=?8 16$4 +(+:/\"1 -: nor/\"1) x +(+:/\ -: nor/\ ) x=.0=?2 4 16$4 +(+:/\"1 -: nor/\"1) x +(+:/\"2 -: nor/\"2) x + +(,'j') -: +:/\'j' +(,<'ace') -: +:/\<'ace' + +'domain error' -: +:/\ etx 'deipnosophist' +'domain error' -: +:/\ etx ;:'peace in our time' + +4!:55 ;:'nor x' + +
new file mode 100644 --- /dev/null +++ b/test/g102s.ijs @@ -0,0 +1,22 @@ +NB. +:/\. B ------------------------------------------------------------- + +(1 0 0 0,:0 1 0 1) -: +:/\. 0 0 1 1 ,: 0 1 0 1 + +nor=: 4 : 'x+:y' + +f=: 3 : '(+:/\. -: nor/\.) y ?@$ 2' +f"0 x=.>:i.2 10 +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4+255 +,f"1 |."1 x + +'domain error' -: +:/\. etx i.12 +'domain error' -: +:/\. etx 3.4 5 +'domain error' -: +:/\. etx 3j4 5 +'domain error' -: +:/\. etx 'deipnosophist' +'domain error' -: +:/\. etx ;:'professors in New England' + +4!:55 ;:'f nor x' + +
new file mode 100644 --- /dev/null +++ b/test/g110.ijs @@ -0,0 +1,188 @@ +NB. *y ------------------------------------------------------------------ + +qct =: 2^_44 +sgn =: (%|) * >:!.0&qct@| +test =: sgn -: * + +test x=:1=?2 5$2 +test x=:_10+?13$20 +test x=:o._10+?5 10$20 +test x=:^0j1*_10+?5 10$20 + +s=:_1 0 1 + +test s* qct +test s*+:qct +test s*-:qct + +test 0j1*s* qct +test 0j1*s*+:qct +test 0j1*s*-:qct + +s -: *!.0 s*qct + +t -: * t=:1=i.0 0 +t -: * t=:0j1*i.0 5 + +dr =: 5!:2 +rk =: 1 : ('f=.+"x'; '>2{ dr <''f''') + +0 0 0 -: * rk + +1 _1 -: * }. 1j1 _ __ + +0 0j1 0j_1 -: * 0 j. 0 _ __ +1 _1 = * _ __ j. 0 +(<'NaN error') = * etx&.> j./~ _ __ + +'domain error' -: * etx 'abc' +'domain error' -: * etx <12 + + +NB. x*y ----------------------------------------------------------------- + +4 = type 1234* 5678 +4 = type 1234*_5678 +8 = type ". > IF64 {'123456* 123456';'1e15* 1e15' +8 = type ". > IF64 {'123456*_123456';'1e15*_1e15' + +(10^>:i.20) -: */\20$10 +((20$_1 1)*10^>:i.20) -: */\20$_10 + +'domain error' -: 'abc' * etx 4 +'domain error' -: 'abc' *~etx 4 +'domain error' -: 4 * etx <'abc' +'domain error' -: 4 *~etx <'abc' + +'length error' -: 3 4 * etx 5 6 7 +'length error' -: 3 4 *~etx 5 6 7 +'length error' -: 3 4 * etx i.5 6 +'length error' -: 3 4 *~etx i.5 6 + + +NB. x*y integer overflow handling --------------------------------------- + +test =: * 0&=@:- *&((o.0)&+) +testa =: (*/ 0&=@:- */ @((o.0)&+))@, +testb =: (*/\ 0&=@:- */\ @((o.0)&+))@, +testc =: (*/\. 0&=@:- */\.@((o.0)&+))@, +x =: <._1+2^31 +y =: <.-2^31 + +4 = type&> _1 0 1 *&.> x +4 = type&> _1 0 1 *&.>~x +4 = type&> 0 1 *&.> -x +4 = type&> 0 1 *&.>~-x +4 = type&> _1 0 1 */@,&.> x +4 = type&> _1 0 1 */@,&.>~x +4 = type&> 0 1 */@,&.> -x +4 = type&> 0 1 */@,&.>~-x +4 = type&> _1 0 1 */\@,&.> x +4 = type&> _1 0 1 */\@,&.>~x +4 = type&> 0 1 */\@,&.> -x +4 = type&> 0 1 */\@,&.>~-x +4 = type&> _1 0 1 */\.@,&.> x +4 = type&> _1 0 1 */\.@,&.>~x +4 = type&> 0 1 */\.@,&.> -x +4 = type&> 0 1 */\.@,&.>~-x + +f =: 4&=@type@* *. test + +2 f 1e9 +2 f~1e9 +61034 f 32768 +61034 f~32768 +65536 f 32767 +65536 f~32767 +65535 f 32768 +65535 f~32768 + +46340 f 46341 +46340 f _46341 +_46340 f 46341 +_46340 f _46341 + +,(2e6 2e6 _2e6 _2e6) test &> 3e7 _3e7 3e7 _3e7 +,(2e6 2e6 _2e6 _2e6) testa&> 3e7 _3e7 3e7 _3e7 +,(2e6 2e6 _2e6 _2e6) testb&> 3e7 _3e7 3e7 _3e7 +,(2e6 2e6 _2e6 _2e6) testc&> 3e7 _3e7 3e7 _3e7 + +,_1 0 1 test &>/ 1234567 _1234567 +,_1 0 1 test &>/~1234567 _1234567 +,_1 0 1 testa&>/ 1234567 _1234567 +,_1 0 1 testa&>/~1234567 _1234567 +,_1 0 1 testb&>/ 1234567 _1234567 +,_1 0 1 testb&>/~1234567 _1234567 +,_1 0 1 testc&>/ 1234567 _1234567 +,_1 0 1 testc&>/~1234567 _1234567 + +,(<.2^30) test &> <. 2^i.10 +,(<.2^30) test &>~<. 2^i.10 +,(<.2^30) test &> <.-2^i.10 +,(<.2^30) test &>~<.-2^i.10 +,(<.2^30) testa&> <. 2^i.10 +,(<.2^30) testa&>~<. 2^i.10 +,(<.2^30) testa&> <.-2^i.10 +,(<.2^30) testa&>~<.-2^i.10 +,(<.2^30) testb&> <. 2^i.10 +,(<.2^30) testb&>~<. 2^i.10 +,(<.2^30) testb&> <.-2^i.10 +,(<.2^30) testb&>~<.-2^i.10 +,(<.2^30) testc&> <. 2^i.10 +,(<.2^30) testc&>~<. 2^i.10 +,(<.2^30) testc&> <.-2^i.10 +,(<.2^30) testc&>~<.-2^i.10 + +,_2 _1 0 1 2 test &>/ x,y +,_2 _1 0 1 2 test &>/ x,y +,_2 _1 0 1 2 testa&>/~x,y +,_2 _1 0 1 2 testa&>/ x,y +,_2 _1 0 1 2 testb&>/~x,y +,_2 _1 0 1 2 testb&>/~x,y +,_2 _1 0 1 2 testc&>/~x,y +,_2 _1 0 1 2 testc&>/~x,y + +12e6 test 8e5 +12e6 test _8e5 +_12e6 test 8e5 +_12e6 test _8e5 + +12e6 testa 8e5 +12e6 testb 8e5 +12e6 testc 8e5 + +exp =: * * | ^ i.@>:@<.@(^.&2147483647)@| +f =: *./@,@(test"0/)&exp " 0 + +x f/ x =: 2 3 5 6 7 10 11 12 13 +x f/-x +(-x) f/ x +(-x) f/-x + +eq =: -:&(3!:1) + +( 1 0*_ ) eq 2 0*_ +( 1 0*_ ) eq 2.5 0*_ +(_1 0*_ ) eq _2 0*_ +(_1 0*_ ) eq _2.5 0*_ +( 1 0*__) eq 2 0*__ +( 1 0*__) eq 2.5 0*__ +(_1 0*__) eq _2 0*__ +(_1 0*__) eq _2.5 0*__ + + +NB. x*y on complex arguments -------------------------------------------- + +times=: (-/@:* j./ +/@:(* |.))&+. + +x=: j./?2 20 100$50 +y=: j./?2 20 100$50 +x (* -: times"0) y +x (* -: times"0) y*?($y)$2 +(x*?($x)$2) (* -: times"0) y +(x*?($x)$2) (* -: times"0) y*?($y)$2 + + +4!:55 ;:'dr eq exp f qct rk s sgn t test testa testb testc times x y' + +
new file mode 100644 --- /dev/null +++ b/test/g110a.ijs @@ -0,0 +1,136 @@ +NB. B * B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x*y) -: (#.x,.y){0 0 0 1 +(x*y) -: (z+x)*z+y [ z=.{.0 4.5 +(x*y) -: (z*x)*z*y [ z=.{.1 4.5 +(z*y) -: (($y)$z)*y [ z=.?2 +(x*z) -: x*($x)$z [ z=.?2 + +(x*y) -: (40$"0 x)*y [ x=. ?10$2 [ y=. ?10 40$2 +(x*y) -: x*40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 0 0 1 -: 0 0 1 1 * 0 1 0 1 + + +NB. B * I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4.5 +(x*y) -: (z*x)*z*y [ z=.{.1 4.5 +(z*y) -: (($y)$z)*y [ z=.?2 +(x*z) -: x*($x)$z [ z=._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 0 3 _3 -: 0 0 1 1 * _4 4 3 _3 +2147483647 _2147483648 -: 1 * 2147483647 _2147483648 +0 0 -: 0 0 * 2147483647 _2147483648 + + +NB. B * D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.?2 +(x*z) -: x*($x)$z [ z=.o._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 0 2.5 _2.5 -: 0 0 1 1 * _4.5 3.14 2.5 _2.5 + + +NB. I * B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=._1e5+?2e5 +(x*z) -: x*($x)$z [ z=.?2 + +(x*y) -: (40$"0 x)*y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x*y) -: x*40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 0 2.5 _2.5 -: _4.5 3.14 2.5 _2.5 * 0 0 1 1 +2147483647 _2147483648 -: 2147483647 _2147483648 * 1 +0 0 -: 2147483647 _2147483648 * 0 0 + + +NB. I * I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.?2e6 +(x*z) -: x*($x)$z [ z=._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +6 _6 _6 6 -: 2 2 _2 _2 * 3 _3 3 _3 +1e8 _1e8 -: 1e4*1e4 _1e4 +1e10 _1e10 -: 1e5*1e5 _1e5 + + +NB. I * D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.?2e6 +(x*z) -: x*($x)$z [ z=.o._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + + +NB. D * B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.o._1e5+?2e5 +(x*z) -: x*($x)$z [ z=.?2 + +(x*y) -: (40$"0 x)*y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x*y) -: x*40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + + +NB. D * I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.o._1e5+?2e5 +(x*z) -: x*($x)$z [ z=._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + + +NB. D * D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x*y) -: (z+x)*z+y [ z=.{.0 4j5 +(x*y) -: (z*x)*z*y [ z=.{.1 4j5 +(z*y) -: (($y)$z)*y [ z=.o._1e5+?2e5 +(x*z) -: x*($x)$z [ z=.o._1e5+?2e5 + +(x*y) -: (40$"0 x)*y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x*y) -: x*40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g110i.ijs @@ -0,0 +1,60 @@ +NB. */ B ---------------------------------------------------------------- + +times=: 4 : 'x*y' + +(*/ -: times/ ) x=.?3 5 23$2 +(*/"1 -: times/"1) x +(*/"2 -: times/"2) x + +(*/ -: times/ ) x=.?3 5 32$2 +(*/"1 -: times/"1) x +(*/"2 -: times/"2) x + +f=: 3 : '(*/ -: times/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. */ I ---------------------------------------------------------------- + +times=: 4 : 'x*y' + +(*/ -: times/) x=.10 20 30 1e6 2e6 +(*/ -: times/) |.x + +(*/ -: times/ ) x=._1e2+? 23$2e2 +(*/ -: times/ ) x=._1e2+?4 23$2e2 +(*/"1 -: times/"1) x +(*/ -: times/ ) x=._1e2+?7 5 23$2e2 +(*/"1 -: times/"1) x +(*/"2 -: times/"2) x + + +NB. */ D ---------------------------------------------------------------- + +times=: 4 : 'x*y' + +(*/ -: times/ ) x=.0.1*_1e2+? 23$2e2 +(*/ -: times/ ) x=.0.1*_1e2+?4 23$2e2 +(*/"1 -: times/"1) x +(*/ -: times/ ) x=.0.1*_1e2+?7 5 23$2e2 +(*/"1 -: times/"1) x +(*/"2 -: times/"2) x + + +NB. */ Z ---------------------------------------------------------------- + +times=: 4 : 'x*y' + +(*/ -: times/ ) x=.j./0.1*_1e2+?2 23$2e2 +(*/ -: times/ ) x=.j./0.1*_1e2+?2 4 23$2e2 +(*/"1 -: times/"1) x +(*/ -: times/ ) x=.j./0.1*_1e2+?2 7 5 23$2e2 +(*/"1 -: times/"1) x +(*/"2 -: times/"2) x + +4!:55 ;:'times x' + +
new file mode 100644 --- /dev/null +++ b/test/g110p.ijs @@ -0,0 +1,76 @@ +NB. */\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 0 0 1) -: */\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: */\20$1 +(20$0) -: */\20$0 + +times=. 4 : 'x*y' + +(*/\ -: times/\ ) x=.? 13$2 +(*/\ -: times/\ ) x=.?7 13$2 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=.?3 5 13$2 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x +(*/\ -: times/\ ) x=.? 12$2 +(*/\ -: times/\ ) x=.?4 12$2 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=.?4 8 12$2 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x + + +NB. */\ I --------------------------------------------------------------- + +times=. 4 : 'x*y' + +(*/\ -: times/\) x=.1 2 3 1e9 2e9 +(*/\ -: times/\) |.x + +(*/\ -: times/\ ) x=._10+? 7$20 +(*/\ -: times/\ ) x=._10+?4 7$20 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=._10+?3 5 7$20 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x + +(*/\ -: times/\ ) x=._1e9+? 13$2e9 +(*/\ -: times/\ ) x=._1e9+?4 13$2e9 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=._1e9+?3 5 13$2e9 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x + + +NB. */\ D --------------------------------------------------------------- + +times=. 4 : 'x*y' + +(*/\ -: times/\ ) x=.0.1*_1e2+? 13$2e2 +(*/\ -: times/\ ) x=.0.1*_1e2+?4 13$2e2 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=.0.1*_1e2+?3 5 13$2e2 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x + + +NB. */\. Z --------------------------------------------------------------- + +times=. 4 : 'x*y' + +(*/\ -: times/\ ) x=.j./0.1*_1e2+?2 13$2e2 +(*/\ -: times/\ ) x=.j./0.1*_1e2+?2 4 13$2e2 +(*/\"1 -: times/\"1) x +(*/\ -: times/\ ) x=.j./0.1*_1e2+?2 3 5 13$2e2 +(*/\"1 -: times/\"1) x +(*/\"2 -: times/\"2) x + +(,'j') -: */\'j' +(,<'ace') -: */\<'ace' + +'domain error' -: */\ etx 'deipnosophist' +'domain error' -: */\ etx ;:'peace in our time' + +4!:55 ;:'times x' + +
new file mode 100644 --- /dev/null +++ b/test/g110s.ijs @@ -0,0 +1,71 @@ +NB. */\. B -------------------------------------------------------------- + +(_20{.1) -: */\._20{.1 +(20$1) -: */\.20$1 + +times=: 4 : 'x*y' + +f=: 3 : '(*/\. -: times/\.) y ?@ $2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. */\. I -------------------------------------------------------------- + +(!>:i.10) -: */\.&.|. >:i.10 + +times=: 4 : 'x*y' + +(*/\. -: times/\.) x=.1 2 3 1e5 2e5 +(*/\. -: times/\.) |.x + +(*/\. -: times/\. ) x=._30*? 7$60 +(*/\. -: times/\. ) x=._30*?4 7$60 +(*/\."1 -: times/\."1) x +(*/\. -: times/\. ) x=._30*?7 5 7$60 +(*/\."1 -: times/\."1) x +(*/\."2 -: times/\."2) x + +(*/\. -: times/\. ) x=._1e9*? 23$2e9 +(*/\. -: times/\. ) x=._1e9*?4 23$2e9 +(*/\."1 -: times/\."1) x +(*/\. -: times/\. ) x=._1e9*?7 5 23$2e9 +(*/\."1 -: times/\."1) x +(*/\."2 -: times/\."2) x + + +NB. */\. D -------------------------------------------------------------- + +(!>:i.10) -: */\.&.|. [&.o. >:i.10 + +times=: 4 : 'x*y' + +(*/\. -: times/\. ) x=.0.01*_1e4*? 23$2e4 +(*/\. -: times/\. ) x=.0.01*_1e4*?4 23$2e4 +(*/\."1 -: times/\."1) x +(*/\. -: times/\. ) x=.0.01*_1e4*?7 5 23$2e4 +(*/\."1 -: times/\."1) x +(*/\."2 -: times/\."2) x + + +NB. */\. Z -------------------------------------------------------------- + +(!>:i.10) -: */\.&.|. [&.j. >:i.10 + +times=: 4 : 'x*y' + +(*/\. -: times/\. ) x=.j./0.1*_1e2*?2 23$2e2 +(*/\. -: times/\. ) x=.j./0.1*_1e2*?2 4 23$2e2 +(*/\."1 -: times/\."1) x +(*/\. -: times/\. ) x=.j./0.1*_1e2*?2 7 5 23$2e2 +(*/\."1 -: times/\."1) x +(*/\."2 -: times/\."2) x + +'domain error' -: */\. etx 'deipnosophist' +'domain error' -: */\. etx ;:'sui generis' + +4!:55 ;:'f times x' + +
new file mode 100644 --- /dev/null +++ b/test/g111.ijs @@ -0,0 +1,38 @@ +NB. *. ------------------------------------------------------------------ + +f =. 10 12&o."0"_ + +(f -: *.) r.?10 20$1000 +(f -: *.) 0.1*_500+?200$1000 + +(f -: *.) 271j1 391j1 513j1 + +a -: [&.*. a=.0.1*_50j_50+j.&?~100$100 + +(3,o.1) -: *. _3 + +10 = # ((10$39)$&.>1) *./&.> (10$25)$&.>1 + +'domain error' -: *. etx <'abc' +'domain error' -: *. etx 'abc' + +x=: j./ _50 + 2 10000 ?@$ 100 +y=: j./ _50 + 2 10000 ?@$ 100 +(x*.y) -: y*.x +x=: j./ _5000 + 2 10000 ?@$ 10000 +y=: j./ _5000 + 2 10000 ?@$ 10000 +(x*.y) -: y*.x + +'domain error' -: 'abc' *. etx 4 +'domain error' -: 'abc' *.~etx 4 +'domain error' -: 4 *. etx <'abc' +'domain error' -: 4 *.~etx <'abc' + +'length error' -: 3 4 *. etx 5 6 7 +'length error' -: 3 4 *.~etx 5 6 7 +'length error' -: 3 4 *. etx i.5 6 +'length error' -: 3 4 *.~etx i.5 6 + +4!:55 ;:'a f x y' + +
new file mode 100644 --- /dev/null +++ b/test/g111a.ijs @@ -0,0 +1,62 @@ +NB. B *. B -------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x*.y) -: (#.x,.y){0 0 0 1 +(x*.y) -: (z+x)*.z+y [ z=.{.0 4.5 +(z*.y) -: (($y)$z)*.y [ z=.?2 +(x*.z) -: x*.($x)$z [ z=.?2 + +(x*.y) -: (40$"0 x)*.y [ x=. ?10$2 [ y=. ?10 40$2 +(x*.y) -: x*.40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 0 0 1 -: 0 0 1 1 *. 0 1 0 1 + + +NB. B *. I -------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2e5 +(x*.y) -: (z+x)*.z+y [ z=.{.0 4.5 +(z*.y) -: (($y)$z)*.y [ z=.?2 +(x*.z) -: x*.($x)$z [ z=.?2e5 + +(x*.y) -: (40$"0 x)*.y [ x=. ?10$2 [ y=. +?10 40$2e5 +(x*.y) -: x*.40$"0 y [ x=. ?10 40$2 [ y=. +?10$2e5 + +0 0 0 1 -: 0 0 1 1 *. 0 1 0 1+4-4 + + +NB. I *. B -------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x*.y) -: (z+x)*.z+y [ z=.{.0 4.5 +(z*.y) -: (($y)$z)*.y [ z=._1e5+?2e5 +(x*.z) -: x*.($x)$z [ z=.?2 + +(x*.y) -: (40$"0 x)*.y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x*.y) -: x*.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 0 0 1 -: (0 0 1 1+3-3) *. 0 1 0 1 + + +NB. I *. I -------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x*.y) -: (z+x)*.z+y [ z=.{.0 4.5 +(z*.y) -: (($y)$z)*.y [ z=._1e5+?2e5 +(x*.z) -: x*.($x)$z [ z=._1e5+?2e5 + +(x*.y) -: (40$"0 x)*.y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x*.y) -: x*.40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 0 0 1 -: (0 0 1 1+3-3) *. 0 1 0 1+3-3 + +'domain error' -: 1 *. etx 'chthonic' +'domain error' -: 0 0 *. etx ;:'sui generis' + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g111i.ijs @@ -0,0 +1,29 @@ +NB. *./ B --------------------------------------------------------------- + +0 0 0 1 -: *./ 0 0 1 1 ,: 0 1 0 1 +0 0 0 -: *./ #:i.8 +0 0 0 0 0 0 0 1 -: *./"1 #:i.8 + +and=: 4 : 'x*.y' + +(*./"1 -: and/"1) x=.0<?3 5 17$17 +(*./"2 -: and/"2) x +(*./"3 -: and/"3) x + +(*./"1 -: and/"1) x=.1<?3 5 32$32 +(*./"2 -: and/"2) x +(*./"3 -: and/"3) x + +(*./"1 -: and/"1) x=.1<?3 8 32$32 +(*./"2 -: and/"2) x +(*./"3 -: and/"3) x + +f=: 3 : '(*./ -: and/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'and f x' + +
new file mode 100644 --- /dev/null +++ b/test/g111p.ijs @@ -0,0 +1,34 @@ +NB. *./\ B -------------------------------------------------------------- + +(0 0 1 1,:0 0 0 1) -: *./\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: *./\20$1 +(20$0) -: *./\20$0 + +and=. 4 : 'x*.y' + +(*./\"1 -: and/\"1) #:i.16 +(*./\"1 -: and/\"1) #:i.32 + +(*./\ -: and/\ ) x=.? 13$2 +(*./\ -: and/\ ) x=.?7 13$2 +(*./\"1 -: and/\"1) x +(*./\ -: and/\ ) x=.?3 5 13$2 +(*./\"1 -: and/\"1) x +(*./\"2 -: and/\"2) x + +(*./\ -: and/\ ) x=.? 16$2 +(*./\ -: and/\ ) x=.?8 16$2 +(*./\"1 -: and/\"1) x +(*./\ -: and/\ ) x=.?2 4 16$2 +(*./\"1 -: and/\"1) x +(*./\"2 -: and/\"2) x + +(,'j') -: *./\'j' +(,<'ace') -: *./\<'ace' + +'domain error' -: *./\ etx 'deipnosophist' +'domain error' -: *./\ etx ;:'peace in our time' + +4!:55 ;:'and x' + +
new file mode 100644 --- /dev/null +++ b/test/g111s.ijs @@ -0,0 +1,43 @@ +NB. *./\. B ------------------------------------------------------------- + +(0 0 0 1,:0 1 0 1) -: *./\. 0 0 1 1 ,: 0 1 0 1 + +and=: 4 : 'x*.y' + +f=: 3 : '(*./\. -: and/\.) y ?@$ 2' +f"0 x=.>:i.2 10 +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. *./\. I ------------------------------------------------------------- + +and=: 4 : 'x*.y' + +(*./\. -: and/\.) x=.1 2 3 1e2 2e2 +(*./\. -: and/\.) |.x +(*./\. -: and/\.) x=.1 2 3 1e9 2e9 +(*./\. -: and/\.) |.x + +(*./\. -: and/\. ) x=._1e4+? 23$2e4 +(*./\. -: and/\. ) x=._1e4+?4 23$2e4 +(*./\."1 -: and/\."1) x +(*./\. -: and/\. ) x=._1e4+?7 5 23$2e4 +(*./\."1 -: and/\."1) x +(*./\."2 -: and/\."2) x + +(*./\. -: and/\. ) x=._1e2+? 23$2e2 +(*./\. -: and/\. ) x=._1e2+?4 23$2e2 +(*./\."1 -: and/\."1) x +(*./\. -: and/\. ) x=._1e2+?7 5 23$2e2 +(*./\."1 -: and/\."1) x +(*./\."2 -: and/\."2) x + +'domain error' -: *./\. etx 'deipnosophist' +'domain error' -: *./\. etx ;:'professors in New England' + +4!:55 ;:'f and x' + +
new file mode 100644 --- /dev/null +++ b/test/g112.ijs @@ -0,0 +1,51 @@ +NB. *:y ----------------------------------------------------------------- + +test=.*~"_ -: *: +test 1=?2 3 4$2 +test _20+?50$50 +test o. _20+?50$50 +test r. ?3 4 5$100 +test i.0 3 4 +test i.3 0 + +'domain error' -: *: etx 'abc' +'domain error' -: *: etx 3;4 5 +'domain error' -: *: etx <!.0?7$2 + + +NB. x*:y ---------------------------------------------------------------- + +(2 2$1 1 1 0) -: *:/~ 0 1 +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1 + +(2 2$1 1 1 0) -: *:/~ 0 1{0 1 4 5 6 +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1{0 1 4 5 6 +1 1 1 0 -: 0 0 1 1 *:~0 1 0 1{0 1 4 5 6 + +(2 2$1 1 1 0) -: *:/~ 0 1{0 1 4.5 6 _7.89 +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1{0 1 4.5 6 _7.89 +1 1 1 0 -: 0 0 1 1 *:~0 1 0 1{0 1 4.5 6 _7.89 + +(2 2$1 1 1 0) -: *:/~ 0 1{0 1 4.5j6 _7.89 +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1{0 1 4.5j6 _7.89 +1 1 1 0 -: 0 0 1 1 *:~0 1 0 1{0 1 4.5j6 _7.89 + +'domain error' -: 0 1 *: etx 'ab' +'domain error' -: 0 1 *:~etx 'ab' +'domain error' -: 0 1 *: etx 2 +'domain error' -: 0 1 *:~etx 2 +'domain error' -: 0 1 *: etx 3.4 0 +'domain error' -: 0 1 *:~etx 3.4 0 +'domain error' -: 0 1 *: etx 0j1 1 +'domain error' -: 0 1 *:~etx 0j1 1 +'domain error' -: 1 *: etx <'asfd' +'domain error' -: 1 *:~etx <'asfd' + +'length error' -: 0 1 *: etx 0 1 0 +'length error' -: 0 1 *:~etx 0 1 0 +'length error' -: 0 1 0 *: etx ?4 3$2 +'length error' -: 0 1 0 *:~etx ?4 3$2 + +4!:55 ;:'test' + +
new file mode 100644 --- /dev/null +++ b/test/g112a.ijs @@ -0,0 +1,138 @@ +NB. B *: B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x*:y) -: (#.x,.y){1 1 1 0 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.?2 +(x*:z) -: x*:($x)$z [ z=.?2 + +(x*:y) -: (40$"0 x)*:y [ x=. ?10$2 [ y=. ?10 40$2 +(x*:y) -: x*:40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1 + + +NB. B *: I --------------------------------------------------------------- + +x=. ?100$2 +y=. 2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.?2 +(x*:z) -: x*:($x)$z [ z=.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. ?10$2 [ y=. 2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. ?10 40$2 [ y=. 2|?10$2e5 + +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1+4-4 + + +NB. B *: D --------------------------------------------------------------- + +x=. ?100$2 +y=. [&.o.2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.?2 +(x*:z) -: x*:($x)$z [ z=.[&.o.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. ?10$2 [ y=. [&.o.2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. ?10 40$2 [ y=. [&.o.2|?10$2e5 + +1 1 1 0 -: 0 0 1 1 *: 0 1 0 1+3.5-3.5 + + +NB. I *: B --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. ?100$2 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.2|?2e5 +(x*:z) -: x*:($x)$z [ z=.?2 + +(x*:y) -: (40$"0 x)*:y [ x=. 2|?10$2e5 [ y=. ?10 40$2 +(x*:y) -: x*:40$"0 y [ x=. 2|?10 40$2e5 [ y=. ?10$2 + +1 1 1 0 -: (0 0 1 1+3-3) *: 0 1 0 1 + + +NB. I *: I --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. 2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.2|?2e6 +(x*:z) -: x*:($x)$z [ z=.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. 2|?10$2e5 [ y=. 2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. 2|?10 40$2e5 [ y=. 2|?10$2e5 + +1 1 1 0 -: (0 0 1 1+3-3) *: 0 1 0 1+3-3 + + +NB. I *: D --------------------------------------------------------------- + +x=. 2|?100$2e5 +y=. [&.o.2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.2|?2e6 +(x*:z) -: x*:($x)$z [ z=.[&.o.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. 2|?10$2e5 [ y=. [&.o.2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. 2|?10 40$2e5 [ y=. [&.o.2|?10$2e5 + +1 1 1 0 -: (0 0 1 1+3-3) *: 0 1 0 1+3.4-3.4 + + +NB. D *: B --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. ?100$2 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.[&.o.2|?2e5 +(x*:z) -: x*:($x)$z [ z=.?2 + +(x*:y) -: (40$"0 x)*:y [ x=. [&.o.2|?10$2e5 [ y=. ?10 40$2 +(x*:y) -: x*:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. ?10$2 + +1 1 1 0 -: (0 0 1 1+3.4-3.4) *: 0 1 0 1 + + +NB. D *: I --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. 2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.[&.o.2|?2e5 +(x*:z) -: x*:($x)$z [ z=.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. [&.o.2|?10$2e5 [ y=. 2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. 2|?10$2e5 + +1 1 1 0 -: (0 0 1 1+3.4-3.4) *: 0 1 0 1+34-34 + + +NB. D *: D --------------------------------------------------------------- + +x=. [&.o.2|?100$2e5 +y=. [&.o.2|?100$2e5 +(x*:y) -: (z+x)*:z+y [ z=.{.0 4.5 +(x*:y) -: (z*x)*:z*y [ z=.{.1 4j5 +(z*:y) -: (($y)$z)*:y [ z=.[&.o.2|?2e5 +(x*:z) -: x*:($x)$z [ z=.[&.o.2|?2e5 + +(x*:y) -: (40$"0 x)*:y [ x=. [&.o.2|?10$2e5 [ y=. [&.o.2|?10 40$2e5 +(x*:y) -: x*:40$"0 y [ x=. [&.o.2|?10 40$2e5 [ y=. [&.o.2|?10$2e5 + +1 1 1 0 -: (0 0 1 1+3.4-3.4) *: 0 1 0 1+3.4-3.4 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g112i.ijs @@ -0,0 +1,27 @@ +NB. *:/ B --------------------------------------------------------------- + +1 1 1 0 -: *:/ 0 0 1 1 ,: 0 1 0 1 + +nand=: 4 : 'x*:y' + +(*:/"1 -: nand/"1) x=.?3 5 17$2 +(*:/"2 -: nand/"2) x +(*:/"3 -: nand/"3) x + +(*:/"1 -: nand/"1) x=.?3 5 32$2 +(*:/"2 -: nand/"2) x +(*:/"3 -: nand/"3) x + +(*:/"1 -: nand/"1) x=.?3 8 32$2 +(*:/"2 -: nand/"2) x +(*:/"3 -: nand/"3) x + +f=: 3 : '(*:/ -: nand/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f nand x' + +
new file mode 100644 --- /dev/null +++ b/test/g112p.ijs @@ -0,0 +1,34 @@ +NB. *:/\ B -------------------------------------------------------------- + +(0 0 1 1,:1 1 1 0) -: *:/\ 0 0 1 1 ,: 0 1 0 1 +(20$1 0) -: *:/\20$1 +(-.20{.1) -: *:/\20$0 + +nand=. 4 : 'x*:y' + +(*:/\"1 -: nand/\"1) #:i.16 +(*:/\"1 -: nand/\"1) #:i.32 + +(*:/\ -: nand/\ ) x=.0<? 13$4 +(*:/\ -: nand/\ ) x=.0<?7 13$4 +(*:/\"1 -: nand/\"1) x +(*:/\ -: nand/\ ) x=.0<?3 5 13$4 +(*:/\"1 -: nand/\"1) x +(*:/\"2 -: nand/\"2) x + +(*:/\ -: nand/\ ) x=.0<? 16$4 +(*:/\ -: nand/\ ) x=.0<?8 16$4 +(*:/\"1 -: nand/\"1) x +(*:/\ -: nand/\ ) x=.0<?2 4 16$4 +(*:/\"1 -: nand/\"1) x +(*:/\"2 -: nand/\"2) x + +(,'j') -: *:/\'j' +(,<'ace') -: *:/\<'ace' + +'domain error' -: *:/\ etx 'deipnosophist' +'domain error' -: *:/\ etx ;:'peace in our time' + +4!:55 ;:'nand x' + +
new file mode 100644 --- /dev/null +++ b/test/g112s.ijs @@ -0,0 +1,23 @@ +NB. *:/\. B ------------------------------------------------------------- + +(1 1 1 0,:0 1 0 1) -: *:/\. 0 0 1 1 ,: 0 1 0 1 + +nand=: 4 : 'x*:y' + +f=: 3 : '(*:/\. -: nand/\.) y ?@$ 2' +f"0 x=.>:i.2 10 +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4+255 +,f"1 |."1 x + +'domain error' -: *:/\. etx i.12 +'domain error' -: *:/\. etx 3.4 5 +'domain error' -: *:/\. etx 3j4 5 +'domain error' -: *:/\. etx 'deipnosophist' +'domain error' -: *:/\. etx ;:'professors in New England' + +4!:55 ;:'f nand x' + + +
new file mode 100644 --- /dev/null +++ b/test/g120.ijs @@ -0,0 +1,87 @@ +NB. -y ------------------------------------------------------------------ + +'domain error' -: - etx 'abc' +'domain error' -: - etx ;:'sui generis' +'domain error' -: - etx <i.2 3 + + +NB. x-y ----------------------------------------------------------------- + +4 = type 1234-5678 +4 = type _1234-_5678 +4 = type _2e9 +8 = type ". x=: > IF64{'_2e9-3e8 ';'_9e18-1e18' +4 = type ". x=: > IF64{'0-_2147483647';'0-_9223372036854775807' +4 = type _2147483647-1 +4 = type _2147483648 +4 = type _1-_2147483648 +8 = type ". x=: > IF64{'_2147483648-1';'_9223372036854775808-1' +8 = type ". x=: > IF64{'0-_2147483648';'0-_9223372036854775808' +8 = type ". x=: > IF64{' -_2147483648';' -_9223372036854775808' + +_1 -: 3 - 4 +2 -: 9.5 - 7.5 + +'domain error' -: 'abc' - etx 4 +'domain error' -: 'abc' -~etx 4 +'domain error' -: 4 - etx <'abc' +'domain error' -: 4 -~etx <'abc' + +'length error' -: 3 4 - etx 5 6 7 +'length error' -: 3 4 -~etx 5 6 7 +'length error' -: 3 4 - etx i.5 6 +'length error' -: 3 4 -~etx i.5 6 +'length error' -: 3 4 - etx ?4 2$183164 +'length error' -: 3 4 -~etx ?4 2$183164 + + +NB. x-y integer overflow handling --------------------------------------- + +test =. - 0&=@:- -&((o.0)&+) +testa =. (-/ 0&=@:- -/ @((o.0)&+))@,"0 +testb =. (-/\ 0&=@:- -/\ @((o.0)&+))@,"0 +testc =. (-/\. 0&=@:- -/\.@((o.0)&+))@,"0 +x =. IF64{:: 2147483647; 9223372036854775807 +y =. IF64{:: _2147483648; _9223372036854775808 + +8 4 4 4 4 = type&> _2 _1 0 1 2-&.> x +8 8 4 4 4 = type&> _2 _1 0 1 2-&.>~x +4 4 8 8 8 = type&> _2 _1 0 1 2-&.> y +4 4 4 8 8 = type&> _2 _1 0 1 2-&.>~y + +8 4 4 4 4 = type&> _2 _1 0 1 2-/@,&.> x +8 8 4 4 4 = type&> _2 _1 0 1 2-/@,&.>~x +4 4 8 8 8 = type&> _2 _1 0 1 2-/@,&.> y +4 4 4 8 8 = type&> _2 _1 0 1 2-/@,&.>~y + +8 4 4 4 4 = type&> _2 _1 0 1 2-/\@,&.> x +8 8 4 4 4 = type&> _2 _1 0 1 2-/\@,&.>~x + 8 8 8 = type&> 0 1 2-/\@,&.> y + 8 8 = type&> 1 2-/\@,&.>~y + +8 4 4 4 4 = type&> _2 _1 0 1 2-/\.@,&.> x +8 8 4 4 4 = type&> _2 _1 0 1 2-/\.@,&.>~x +4 4 8 8 8 = type&> _2 _1 0 1 2-/\.@,&.> y +4 4 4 8 8 = type&> _2 _1 0 1 2-/\.@,&.>~y + +,(2e9 2e9 _2e9 _2e9) test &>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) test &>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testa&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testa&>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testb&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testb&>/~1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testc&>/ 1e9 _1e9 1e9 _1e9 +,(2e9 2e9 _2e9 _2e9) testc&>/~1e9 _1e9 1e9 _1e9 + +,_2 _1 0 1 2 test &>/ x,y +,_2 _1 0 1 2 test &>/~x,y +,_2 _1 0 1 2 testa&>/ x,y +,_2 _1 0 1 2 testa&>/~x,y +,_2 _1 0 1 2 testb&>/ x,y +,_2 _1 0 1 2 testb&>/~x,y +,_2 _1 0 1 2 testc&>/ x,y +,_2 _1 0 1 2 testc&>/~x,y + +4!:55 ;:'test testa testb testc x y' + +
new file mode 100644 --- /dev/null +++ b/test/g120a.ijs @@ -0,0 +1,145 @@ +NB. B - B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x-y) -: (#.x,.y){0 _1 1 0 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.?2 +(x-z) -: x-($x)$z [ z=.?2 + +(x-y) -: (40$"0 x)-y [ x=. ?10$2 [ y=. ?10 40$2 +(x-y) -: x-40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 _1 1 0 -: 0 0 1 1 - 0 1 0 1 + + +NB. B - I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.?2 +(x-z) -: x-($x)$z [ z=._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +1 0 _1 _2 -: 1 - i.4 +2147483647 -: 0 - _2147483647 +2147483648 -: 0 - _2147483648 + + +NB. B - D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.?2 +(x-z) -: x-($x)$z [ z=.o._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +_3.5 18.2 -: 1 - 4.5 _17.2 + + +NB. I - B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=._1e5+?2e5 +(x-z) -: x-($x)$z [ z=.?2 + +(x-y) -: (40$"0 x)-y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x-y) -: x-40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +5 3 8 -: 6 4 9 - 1 +_2147483648 -: _2147483647 - 1 +_2147483649 -: _2147483648 - 1 + + +NB. I - I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.?2e6 +(x-z) -: x-($x)$z [ z=._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +_6 _4 _2 -: 3 4 5 - 9 8 7 +_3e8 -: _1e8 - 2e8 +_3e9 -: _1e9 - 2e9 +2147483650 -: 2 - _2147483648 + + +NB. I - D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.?2e6 +(x-z) -: x-($x)$z [ z=.o._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +65 _38.8 -: 45 _23 - _20 15.8 + + +NB. D - B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.o._1e5+?2e5 +(x-z) -: x-($x)$z [ z=.?2 + +(x-y) -: (40$"0 x)-y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x-y) -: x-40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + +2.14159 3.14159 -: 3.14159 - 1 0 + + +NB. D - I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.o._1e5+?2e5 +(x-z) -: x-($x)$z [ z=._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +2.14159 5.14159 -: 3.14159 - 1 _2 + + +NB. D - D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x-y) -: (z+x)-z+y [ z=.{.0 4.5 +(x-y) -: (z*x)-z*y [ z=.{.1 4j5 +(z-y) -: (($y)$z)-y [ z=.o._1e5+?2e5 +(x-z) -: x-($x)$z [ z=.o._1e5+?2e5 + +(x-y) -: (40$"0 x)-y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x-y) -: x-40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +3 -: 3.14159 - 0.14159 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g120i.ijs @@ -0,0 +1,69 @@ +NB. -/ B ---------------------------------------------------------------- + +0 _1 1 0 -: -/ 0 0 1 1 ,: 0 1 0 1 + +minus=: 4 : 'x-y' + +(-/ -: minus/ ) x=.?3 5 23$2 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + +(-/ -: minus/ ) x=.?3 5 32$2 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + +f=: 3 : '(-/ -: minus/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. -/ I ---------------------------------------------------------------- + +minus=: 4 : 'x-y' + +(-/ -: minus/) x=.1 2 3 _1e9 2e9 +(-/ -: minus/) |.x + +(-/ -: minus/ ) x=._1e4+? 23$2e4 +(-/ -: minus/ ) x=._1e4+?4 23$2e4 +(-/"1 -: minus/"1) x +(-/ -: minus/ ) x=._1e4+?7 5 23$2e4 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + +(-/ -: minus/ ) x=._1e9+? 23$2e9 +(-/ -: minus/ ) x=._1e9+?4 23$2e9 +(-/"1 -: minus/"1) x +(-/ -: minus/ ) x=._1e9+?7 5 23$2e9 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + + +NB. -/ D ---------------------------------------------------------------- + +minus=: 4 : 'x-y' + +(-/ -: minus/ ) x=.0.1*_1e2+? 23$2e2 +(-/ -: minus/ ) x=.0.1*_1e2+?4 23$2e2 +(-/"1 -: minus/"1) x +(-/ -: minus/ ) x=.0.1*_1e2+?7 5 23$2e2 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + + +NB. -/ Z ---------------------------------------------------------------- + +minus=: 4 : 'x-y' + +(-/ -: minus/ ) x=.j./0.1*_1e2+?2 23$2e2 +(-/ -: minus/ ) x=.j./0.1*_1e2+?2 4 23$2e2 +(-/"1 -: minus/"1) x +(-/ -: minus/ ) x=.j./0.1*_1e2+?2 7 5 23$2e2 +(-/"1 -: minus/"1) x +(-/"2 -: minus/"2) x + +4!:55 ;:'f minus x' + +
new file mode 100644 --- /dev/null +++ b/test/g120p.ijs @@ -0,0 +1,86 @@ +NB. -/\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 _1 1 0) -: -/\ 0 0 1 1 ,: 0 1 0 1 +(20$1 0) -: -/\20$1 +(21$1 0) -: -/\21$1 + +minus=. 4 : 'x-y' + +(-/\ -: minus/\ ) x=.? 13$2 +(-/\ -: minus/\ ) x=.?7 13$2 +(-/\"1 -: minus/\"1) x +(-/\ -: minus/\ ) x=.?3 5 13$2 +(-/\"1 -: minus/\"1) x +(-/\"2 -: minus/\"2) x +(-/\ -: minus/\ ) x=.? 12$2 +(-/\ -: minus/\ ) x=.?4 12$2 +(-/\"1 -: minus/\"1) x +(-/\ -: minus/\ ) x=.?4 8 12$2 +(-/\"1 -: minus/\"1) x +(-/\"2 -: minus/\"2) x + + +NB. -/\ I --------------------------------------------------------------- + +minus=. 4 : 'x-y' + +(-/\ -: minus/\) x=.2 3 1e9 _2e9 +(-/\ -: minus/\) |.x +(-/\ -: minus/\) x=.1 2 3 1e9 _2e9 +(-/\ -: minus/\) |.x +(-/\ -: minus/\) x=._1e4+?13$2e4 +(-/\ -: minus/\) x=._1e4+?14$2e4 + +(-/\ -: minus/\ ) x=._1e4+? 13$2e4 +(-/\ -: minus/\ ) x=._1e4+?4 13$2e4 +(-/\"1 -: minus/\"1) x +(-/\ -: minus/\ ) x=._1e4+?3 5 13$2e4 +(-/\"1 -: minus/\"1) x +(-/\"2 -: minus/\"2) x + +(-/\ -: minus/\ ) x=._1e9+? 13$2e9 +(-/\ -: minus/\ ) x=._1e9+?4 13$2e9 +(-/\"1 -: minus/\"1) x +(-/\ -: minus/\ ) x=._1e9+?3 5 13$2e9 +(-/\"1 -: minus/\"1) x +(-/\"2 -: minus/\"2) x + + +NB. -/\ D --------------------------------------------------------------- + +minus=. 4 : 'x-y' + +1e_12 > >./ | , (-/\ - minus/\) x=.0.01*_1e4+?13$2e4 +1e_12 > >./ | , (-/\ - minus/\) x=.0.01*_1e4+?14$2e4 + +1e_12 > >./ | , (-/\ - minus/\ ) x=.0.01*_1e4+? 13$2e4 +1e_12 > >./ | , (-/\ - minus/\ ) x=.0.01*_1e4+?4 13$2e4 +1e_12 > >./ | , (-/\"1 - minus/\"1) x +1e_12 > >./ | , (-/\ - minus/\ ) x=.0.01*_1e4+?3 5 13$2e4 +1e_12 > >./ | , (-/\"1 - minus/\"1) x +1e_12 > >./ | , (-/\"2 - minus/\"2) x + + +NB. -/\. Z --------------------------------------------------------------- + +minus=. 4 : 'x-y' + +1e_12 > >./ | , (-/\ - minus/\) x=.j./0.01*_1e4+?2 13$2e4 +1e_12 > >./ | , (-/\ - minus/\) x=.j./0.01*_1e4+?2 14$2e4 + +1e_12 > >./ | , (-/\ - minus/\ ) x=.j./0.1*_1e2+?2 13$2e2 +1e_12 > >./ | , (-/\ - minus/\ ) x=.j./0.1*_1e2+?2 4 13$2e2 +1e_12 > >./ | , (-/\"1 - minus/\"1) x +1e_12 > >./ | , (-/\ - minus/\ ) x=.j./0.1*_1e2+?2 3 5 13$2e2 +1e_12 > >./ | , (-/\"1 - minus/\"1) x +1e_12 > >./ | , (-/\"2 - minus/\"2) x + +(,'j') -: -/\'j' +(,<'ace') -: -/\<'ace' + +'domain error' -: -/\ etx 'deipnosophist' +'domain error' -: -/\ etx ;:'peace in our time' + +4!:55 ;:'f minus x' + +
new file mode 100644 --- /dev/null +++ b/test/g120s.ijs @@ -0,0 +1,71 @@ +NB. -/\. B -------------------------------------------------------------- + +(20$_1 1) -: -/\._20{.1 +(20$ 0 1) -: -/\. 20$1 + +minus=: 4 : 'x-y' + +f=: 3 : '(-/\. -: minus/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. -/\. I -------------------------------------------------------------- + +(,(->:i._10),.10+i.10) -: -/\.i.20 + +minus=: 4 : 'x-y' + +(-/\. -: minus/\.) x=.1 2 3 1e9 _2e9 +(-/\. -: minus/\.) |.x + +(-/\. -: minus/\. ) x=._1e4+? 23$2e4 +(-/\. -: minus/\. ) x=._1e4+?4 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\. -: minus/\. ) x=._1e4+?7 5 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\."2 -: minus/\."2) x + +(-/\. -: minus/\. ) x=._1e9+? 23$2e9 +(-/\. -: minus/\. ) x=._1e9+?4 23$2e9 +(-/\."1 -: minus/\."1) x +(-/\. -: minus/\. ) x=._1e9+?7 5 23$2e9 +(-/\."1 -: minus/\."1) x +(-/\."2 -: minus/\."2) x + + +NB. -/\. D -------------------------------------------------------------- + +(,(->:i._10),.10+i.10) -: -/\. [&.o.i.20 + +minus=: 4 : 'x-y' + +(-/\. -: minus/\. ) x=.(2^_8)*_1e4+? 23$2e4 +(-/\. -: minus/\. ) x=.(2^_8)*_1e4+?4 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\. -: minus/\. ) x=.(2^_8)*_1e4+?7 5 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\."2 -: minus/\."2) x + + +NB. -/\. Z -------------------------------------------------------------- + +(,(->:i._10),.10+i.10) -: -/\. [&.j.i.20 + +minus=: 4 : 'x-y' + +(-/\. -: minus/\. ) x=.j./(2^_8)*_1e4+?2 23$2e4 +(-/\. -: minus/\. ) x=.j./(2^_8)*_1e4+?2 4 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\. -: minus/\. ) x=.j./(2^_8)*_1e4+?2 7 5 23$2e4 +(-/\."1 -: minus/\."1) x +(-/\."2 -: minus/\."2) x + +'domain error' -: -/\. etx 'deipnosophist' +'domain error' -: -/\. etx ;:'sui generis' + +4!:55 ;:'f minus x' + +
new file mode 100644 --- /dev/null +++ b/test/g121.ijs @@ -0,0 +1,166 @@ +NB. -.y ----------------------------------------------------------------- + +not =: 1&- + +NB. Boolean +(-. -: not) 1=?2 3 4$2 +(-. -: not) 1=?2 +(-. -: not) 1=i.2 3 0 + +NB. integer +(-. -: not) ?2 3 4$2123 +(-. -: not) _1000+?1 2 3 4$2123 +(-. -: not) ?22334 +(-. -: not) i.2 3 0 + +NB. floating point +(-. -: not) o.?2 3 4$2123 +(-. -: not) o._1000+?1 2 3 4$2123 +(-. -: not) o.?22334 +(-. -: not) o.i.2 3 0 + +NB. complex +(-. -: not) ^j.?2 3 4$2123 +(-. -: not) ^j._1000+?1 2 3 4$2123 +(-. -: not) ^j.?22334 +(-. -: not) ^j.i.2 3 0 + +(-. -: not) '' + +'domain error' -: -. etx 'abc' +'domain error' -: -. etx 3;1 2 + + +NB. x-.y ---------------------------------------------------------------- + +rank =: #@$ +dr =: rank@] - 0&>.@<:@rank@[ +res =: (dr (*/@{. , }.) $@]) $ ,@] +less =: [`(([ -.@e. res) # [)@.((<: >:)&rank) + +NB. Boolean +t (-. -: less) (?30 $#t){t=:1=?100 2 3$3 +t (-. -: less) (?2 15 $#t){t=:1=?100 2 $2 +t (-. -: less) (?4 3 2$#t){t=:1=?100 $2 +(3 2$1 0) (-. -: less) 3 2$0 1 +(3 2 5 4$1 0) (-. -: less) 5 4$1 0 +(3 2 5 4$1 0) (-. -: less) 2 5 4$1 0 +(,1) -: 1 -. 2 0 4 0 +'' -: 1 -. i.2 3 + +NB. literal +t (-. -: less) (?30 $#t){t=:(?100 2 3$256){a. +t (-. -: less) (?2 15 $#t){t=:(?100 2 $256){a. +t (-. -: less) (?4 3 2$#t){t=:(?100 $256){a. +(3 2$'abc') (-. -: less) 3 2$'xyz' +(3 2 5 1$'abdef') (-. -: less) 5 1$'abdef' +(3 2 5 1$'abdef') (-. -: less) 2 5 1$'abdef' +(,'&') -: '&' -. 'adsfb=12as' +'' -: '&' -. 2 3$'=1&2];' + +NB. integer +t (-. -: less) (?30 $#t){t=:?100 2 3$1233 +t (-. -: less) (?2 15 $#t){t=:_1000+?100 2 $2123 +t (-. -: less) (?4 3 2$#t){t=:?100 $212312 +(3 2$4 5) (-. -: less) 3 2$5 4 +(i.3 2 5 1) (-. -: less) i.5 1 +(i.3 2 5 1) (-. -: less) i.2 5 1 +(,_17) -: _17 -. 2 0 4 0 3j4 +'' -: _17 -. 2 3$99 _17 0 9.7 _12 + +NB. floating point +t (-. -: less) (?30 $#t){t=:o.?100 2 3$1233 +t (-. -: less) (?2 15 $#t){t=:o._1000+?100 2 $2123 +t (-. -: less) (?4 3 2$#t){t=:o.?100 $212312 +(3 2$4.5) (-. -: less) 3 2$4.51 +(o.i.3 2 4 5) (-. -: less) o.i.4 5 +(o.i.3 2 4 5) (-. -: less) o.i.2 4 5 +(,2.7) -: 2.7 -. 2 0 4 0 3j4 +'' -: 2.7 -. 2 3$99 2.7 _17 0 3j4 7 1 + +NB. complex +t (-. -: less) (?30 $#t){t=:^j.?100 2 3$1233 +t (-. -: less) (?2 15 $#t){t=:^j.?100 2 $2123 +t (-. -: less) (?4 3 2$#t){t=:^j.?100 $212312 +(3 2$4j5) (-. -: less) 3 2$5j4 +(j.i.3 2 4 5) (-. -: less) j.i.4 5 +(j.i.3 2 4 5) (-. -: less) j.i.2 4 5 +(,2j7) -: 2j7 -. 2 0 4 0 6 +'' -: 2j7 -. 2 3 4$99 2j7 _17 0 3j4 7 1 + +NB. boxed +t (-. -: less) (?30 $#t){t=: ":&.>?100 2 3$1233 +t (-. -: less) (?2 15 $#t){t=: ":&.>_1000+?100 2 $2123 +t (-. -: less) (?4 3 2$#t){t=: ":&.>?100 $212312 +(":&.>3 2$4 5 ) (-. -: less) ":&.>3 2$5 4 +(":&.>i.3 2 5 1) (-. -: less) ":&.>i.5 1 +(":&.>i.3 2 5 1) (-. -: less) ":&.>i.2 5 1 +(,<_17) -: (<_17) -. <"0 ] 2 0 4 0 3j4 +'' -: (<_17) -. <"0 ] 2 3$99 _17 0 9.7 _12 + +NB. empties +(3 0$'') (-. -: less) i.5 0 +(4 0$'') (-. -: less) i.0 0 +(4 0$'') (-. -: less) i.1 0 +(9 0$'') (-. -: less) i.2 3 4 0 + +x -: x -. 0#x=: 1000 ?@$2 +x -: x -. 0#x=: 1000 2?@$2 +x -: x -. 0#x=: 1000 4?@$2 +x -: x -. 0#x=: 1000 9?@$2 +x -: x -. 0#x=: a.{~1000 ?@$#a. +x -: x -. 0#x=: a.{~1000 2?@$#a. +x -: x -. 0#x=: a.{~1000 4?@$#a. +x -: x -. 0#x=: a.{~1000 9?@$#a. +x -: x -. 0#x=: u: 1000 ?@$65536 +x -: x -. 0#x=: u: 1000 3?@$65536 +x -: x -. 0#x=: 1000 ?@$50 +x -: x -. 0#x=: 1000 2?@$50 +x -: x -. 0#x=: 1000 ?@$2e9 +x -: x -. 0#x=: 1000 2?@$2e9 +x -: x -. 0#x=: t{~ 1000 ?@$#t=: ":&.>?100$1000 +x -: x -. 0#x=: t{~ 1000 2?@$#t=: ":&.>?100$1000 + +NB. non-homogeneous data + +x -: x -. (5 $'a') [ x=: 1000 ?@$2 +x -: x -. (5 2$'a') [ x=: 1000 2?@$2 +x -: x -. (5 4$'a') [ x=: 1000 4?@$2 +x -: x -. (5 9$'a') [ x=: 1000 9?@$2 +x -: x -. (5 $123) [ x=: a.{~1000 ?@$#a. +x -: x -. (5 2$123) [ x=: a.{~1000 2?@$#a. +x -: x -. (5 4$123) [ x=: a.{~1000 4?@$#a. +x -: x -. (5 9$123) [ x=: a.{~1000 9?@$#a. +x -: x -. (5 9$123) [ x=: u: 1000 ?@$65536 +x -: x -. (5 3$123) [ x=: u: 1000 3?@$65536 +x -: x -. (5 $'a') [ x=: 1000 ?@$50 +x -: x -. (5 2$'a') [ x=: 1000 2?@$50 +x -: x -. (5 $'a') [ x=: 1000 ?@$2e9 +x -: x -. (5 2$'a') [ x=: 1000 2?@$2e9 +x -: x -. (5 $'a') [ x=: t{~ 1000 ?@$#t=: ":&.>?100$1000 +x -: x -. (5 2$'a') [ x=: t{~ 1000 2?@$#t=: ":&.>?100$1000 + +(,0) -: -.&(,2) 0 +(,1) -: -.&(,2) 1 +('') -: -.&(,2) 2 +(,3) -: -.&(,2) 3 + +f=: 4 : 0 + xx=: x + yy=: y + assert. (x-.y) -: -.&y x + 1 +) + +s=: 1 0 1 1 0; 3 1 4 5 0; 3 1 4 5 0 0.2; 3 1 4 5 0j2; 3 4 5 5 0x; '3145' +t=: 0 ; 'abc'; 0 3 4; 0 3.4; 0 3j4; 0 3 4x; <0 3;4 +s f&>/ t + +'length error' -: -.&0 1 2 etx i.5 2 +'length error' -: -.&0 1 2 etx i.5 4 +'length error' -: -.&(i.2 5 3) etx i.5 4 + + +4!:55 ;:'dr f less not rank res s t x xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g122.ijs @@ -0,0 +1,233 @@ +NB. -:y ----------------------------------------------------------------- + +(-: -: 0.5&*) ?2 3 4$2 +(-: -: 0.5&*) _20+?50$50 +(-: -: 0.5&*) o. _20+?50$50 +(-: -: 0.5&*) r. ?3 4 5$100 +(-: -: 0.5&*) i.0 3 4 +(-: -: 0.5&*) i.3 0 + +'domain error' -: -: etx 'abc' +'domain error' -: -: etx 3;4 5 + + +NB. x-:y ---------------------------------------------------------------- + +'' -: $0 +'' -: 0$a: +($0) -: 0$a: + +(0 3 4 5$1) -: 0 3 4 5$4 +(0 3 4 5$1) -: 0 3 4 5$4.6 +(0 3 4 5$1) -: 0 3 4 5$4j6 +(0 3 4 5$1) -: 0 3 4 5$'a' +(0 3 4 5$1) -: 0 3 4 5$<'a' + +(0 3 4 5$456) -: 0 3 4 5$0 +(0 3 4 5$456) -: 0 3 4 5$4.6 +(0 3 4 5$456) -: 0 3 4 5$4j6 +(0 3 4 5$456) -: 0 3 4 5$'a' +(0 3 4 5$456) -: 0 3 4 5$<'a' + +(0 3 4 5$4.6) -: 0 3 4 5$0 +(0 3 4 5$4.6) -: 0 3 4 5$456 +(0 3 4 5$4.6) -: 0 3 4 5$4j6 +(0 3 4 5$4.6) -: 0 3 4 5$'a' +(0 3 4 5$4.6) -: 0 3 4 5$<'a' + +(0 3 4 5$4j6) -: 0 3 4 5$0 +(0 3 4 5$4j6) -: 0 3 4 5$456 +(0 3 4 5$4j6) -: 0 3 4 5$4.6 +(0 3 4 5$4j6) -: 0 3 4 5$'a' +(0 3 4 5$4j6) -: 0 3 4 5$<'a' + +(0 3 4 5$'j') -: 0 3 4 5$0 +(0 3 4 5$'j') -: 0 3 4 5$456 +(0 3 4 5$'j') -: 0 3 4 5$4.6 +(0 3 4 5$'j') -: 0 3 4 5$4j6 +(0 3 4 5$'j') -: 0 3 4 5$<'a' + +(0 3 4 5$<56) -: 0 3 4 5$0 +(0 3 4 5$<56) -: 0 3 4 5$456 +(0 3 4 5$<56) -: 0 3 4 5$4.6 +(0 3 4 5$<56) -: 0 3 4 5$4j6 +(0 3 4 5$<56) -: 0 3 4 5$'a' + +match =: 0:`(*./@:=&,)@.(-:&$) +test =: -: = match + +NB. Boolean +0 test 0 +1 test 1 +a test a=:?1000$2 +(?2 3$2) test ?2 3 4 5$2 +((}:a),-.{:a) test a=:?100$2 +(}.a,5) test a=:?100$2 +(}.a,5) test~a=:?100$2 +(}.a,4.5) test a=:?100$2 +(}.a,4.5) test~a=:?100$2 +(}.a,4j5) test a=:?100$2 +(}.a,4j5) test~a=:?100$2 +(}:a,5) test a=:?100$2 +(}:a,5) test~a=:?100$2 +(}:a,4.5) test a=:?100$2 +(}:a,4.5) test~a=:?100$2 +(}:a,4j5) test a=:?100$2 +(}:a,4j5) test~a=:?100$2 + +NB. literal +'a' test 'b' +a test a=:a.{~?100$256 +((}:a),{:a.) test a=:a.{~?100$255 +(a.{~?2 3$256) test a.{~?2 3 4 5$256 +(($a)$1) test a=:a.{~?2 3 4$255 +(($a)$45) test a=:a.{~?2 3 4$255 +(($a)$4.5) test a=:a.{~?2 3 4$255 +(($a)$4j5) test a=:a.{~?2 3 4$255 +(($a)$<45) test a=:a.{~?2 3 4$255 +f =: $&'abc' test $&'abc' +g =: ,&'d'@}:@($&'abc') test ,&'e'@}:@($&'abc') +h =: {&'ab'@:?@($&2) test {&'ab'@:?@($&2) +f"0 i.25 +g"0 i.25 +h"0 i.25 + +NB. integer +3 test 3 +3 test _3 +a test a=:_1e9+?1000$2e9 +(?2 3$234) test ?2 3 4 5$234 +((}:a),2e9) test a=:?100$2e9 +(}.a,4.5) test a=:_1e9+?100$2e9 +(}.a,4.5) test~a=:_1e9+?100$2e9 +(}.a,4j5) test a=:_1e9+?100$2e9 +(}.a,4j5) test~a=:_1e9+?100$2e9 +(}:a,4.5) test a=:_1e9+?100$2e9 +(}:a,4.5) test~a=:_1e9+?100$2e9 +(}:a,4j5) test a=:_1e9+?100$2e9 +(}:a,4j5) test~a=:_1e9+?100$2e9 + +NB. real +3.5 test 3.5 +3.5 test _3.5 +a test a=:o._1e9+?100$2e9 +(o.?2 3$234) test o.?2 3 4 5$234 +((}:a),2e9) test o.a=:?100$2e8 +(}.a,4j5) test a=:o._1e9+?100$2e9 +(}.a,4j5) test~a=:o._1e9+?100$2e9 +(}:a,4j5) test a=:o._1e9+?100$2e9 +(}:a,4j5) test~a=:o._1e9+?100$2e9 + +NB. complex +3j5 test 3j5 +3j5 test 3j_5 +a test a=:j./_1e9+?2 50$2e9 +(j./?2 3$234) test j./?2 3 4 5$234 +((}:a),2e9) test a=:j./?2 50$2e8 + +NB. boxed +(<'asdf') test <'asdf' +(<'asdf') test <'foob' +a test a=:<"1 ?300 3$1e9 +((}:a),<9) test a=:<"1 ?300 3$1e9 + +a (-:!.0 = *./@:(=!.0)&,) a=:o._1e9+?100$2e9 +(}:a,4j5) (-:!.0 = *./@:(=!.0)&,) a=:o._1e9+?100$2e9 +(}:a,4j5) (-:!.0 = *./@:(=!.0)&,)~a=:o._1e9+?100$2e9 +((}.a),4j5) (-:!.0 = *./@:(=!.0)&,) a=:o._1e9+?100$2e9 +((}.a),4j5) (-:!.0 = *./@:(=!.0)&,)~a=:o._1e9+?100$2e9 +((}:a),4j5) (-:!.0 = *./@:(=!.0)&,) a=:o._1e9+?100$2e9 +((}:a),4j5) (-:!.0 = *./@:(=!.0)&,)~a=:o._1e9+?100$2e9 + +a (-:!.0 = *./@:(=!.0)&,) a=:j./_1e9+?2 50$2e9 +((}.a),4j5) (-:!.0 = *./@:(=!.0)&,) a=:j./_1e9+?2 50$2e9 +((}.a),4j5) (-:!.0 = *./@:(=!.0)&,)~a=:j./_1e9+?2 50$2e9 +((}:a),4j5) (-:!.0 = *./@:(=!.0)&,) a=:j./_1e9+?2 50$2e9 +((}:a),4j5) (-:!.0 = *./@:(=!.0)&,)~a=:j./_1e9+?2 50$2e9 + +1 -:!.(2^_42) 1+2^_43 +1 -:!.(2^_43) 1+2^_44 +1 -:!.(2^_44) 1+2^_45 +1 -:!.(2^_45) 1+2^_46 + + +NB. x-:"r y ------------------------------------------------------------- + +0 0 0 0 -: 1 2 3 -:"1 i.4 2 +0 0 0 0 -: 1 2 3 -:"1 [4 3$'x' + +1 0 0 0 1 -: 0 1 2 -:"1[5$i.4 3 +(10$1) -: x-:"1 x=:?10 7$1e6 + +n=: 300 +match=: 4 : 'x-:y' +test1=: 3 : '(c-:"1 d) -: c match"1 d=:((i.n)-?n$2){c=:((n,y)?@$2){''ab''' +test2=: 3 : '(c-:"1 e) -: c match"1 e=:(?n ){c=:((n,y)?@$2){''ab''' + +test1"0 i.3 10 +test2"0 i.3 10 + +(-:"0/~ -: match"0/~) x=:?20$2 +(-:"0/~ -: match"0/~) x=:a{~?20$#a=:'aleatoric' +(-:"0/~ -: match"0/~) x=:?20$10 +(-:"0/~ -: match"0/~) x=:o.?20$10 +(-:"0/~ -: match"0/~) x=:r.?20$10 +(-:"0/~ -: match"0/~) x=:a{~?20$#a=:;:'deipno sop hist anti dis est a blish' + +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:?10 3$2 +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:[;.1 ' aleatoric quitrent russia' +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:?10 4$1e6 +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:o.?10 4$1000 +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:r.?10 4$1000 +(-:"1/~ -: match"1/~) x=:a{~?20$#a=:5 3$;:'deipno sop hist anti dis est a blish' + +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: ?3$2 +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: 'xyz' +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: ?3$1e6 +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: o.?3$100 +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: r.?3$100 +(x=:a{~?20$3) (-:"0 -: match"0) y=:a{~?20$3 [ a=: ;:'ja oder nein' + +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: ?3 5$2 +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: 3 7$'ipso facto Cogito, ergo sum.' +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: ?3 4$3 +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: o.?3 5$3 +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: r.?3 5$3 +(x=:a{~?20$3) (-:"1 -: match"1) y=:a{~?20$3 [ a=: (<'do'),.3 5$;:'pi no so hi do to an am no' + +test3=: 4 : 0 + a=: x{~?(3,y)$#x + xx=:a{~?#a + yy=:a{~?3 5$#a + assert. xx (-:"1 -: match"1) yy + assert. yy (-:"1 -: match"1) xx + 1 +) + +0 1 test3"1 0 i.3 10 +'abc' test3"1 0 i.3 10 +0 1 2 test3"1 0 i.3 10 +0 1 2.3 test3"1 0 i.3 10 +0 1 2j3 test3"1 0 i.3 10 +(0 1;2;i.7) test3"1 0 i.3 10 + +test4=: 4 : 0 + a=: x{~?(3,y)$#x + xx=:a{~?3 5 2 7$#a + yy=:a{~?3 5$#a + assert. xx (-:"1 -: match"1) yy + assert. yy (-:"1 -: match"1) xx + 1 +) + +0 1 test4"1 0 i.3 10 +'abc' test4"1 0 i.3 10 +0 1 2 test4"1 0 i.3 10 +0 1 2.3 test4"1 0 i.3 10 +0 1 2j3 test4"1 0 i.3 10 +(0 1;2;i.7) test4"1 0 i.3 10 + + +4!:55 ;:'a c d e f g h match n test test1 test2 test3 test4 x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g122a.ijs @@ -0,0 +1,28 @@ +NB. x -.@-:"r y --------------------------------------------------------- + +f=: 4 : 0 + xx=: x{~ y ?@$ #x + yy=: x{~ y ?@$ #x + r=: <:#$xx + assert. ( xx -.@ -:"r yy) -: -. xx -:"r yy + assert. ( xx -.@:-:"r yy) -: -. xx -:"r yy + assert. ( xx -.@ -:"r {.yy) -: -. xx -:"r {.yy + assert. ( xx -.@:-:"r {.yy) -: -. xx -:"r {.yy + assert. (({.xx) -.@ -:"r yy) -: -. ({.xx) -:"r yy + assert. (({.xx) -.@:-:"r yy) -: -. ({.xx) -:"r yy + 1 +) + +(<0 1 ) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(<'abcd',0 _1{a.) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(< 100?@$100) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(< 100?@$0 ) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(<j./2 100?@$0 ) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(< x: 100?@$100) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(< x: 100?@$0 ) f&> (100+i.4) ,&.>/ '';<"0 i.8 +(<":&.>100?@$100) f&> (100+i.4) ,&.>/ '';<"0 i.8 + + +4!:55 ;:'f r xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g128x.ijs @@ -0,0 +1,46 @@ +NB. 128!:0 and 128!:1 --------------------------------------------------- + +a =. ?19 4$100 +qr =. 128!:0 a +q =. >0{qr +r =. >1{qr + +($q) -: $a +($r) -: 2$1{$a + +i =. =i.#r +1e_13>>./|,(a+0=a)%~a-q+/ . *r +1e_14>>./|,i - (|:q) +/ . * q +*./,(|*r)<:<:/~i.#r + +s =. 128!:1 r +($r) -: $s +1e_14>>./|,i-r +/ . * s + +a =. j.&?~ 9 5$100 +qr =. 128!:0 a +q =. >0{qr +r =. >1{qr + +($q) -: $a +($r) -: 2$1{$a + +i =. =i.#r +1e_13>>./|,(a+0=a)%~a-q+/ . * r +1e_14>>./|,i - (+|:q) +/ . * q +*./,(|*r)<:<:/~i.#r + +s =. 128!:1 r +($r) -: $s +1e_14>>./|,i-r +/ . * s + + +NB. 128!:2 -------------------------------------------------------------- + +(+/ x) -: '+/' 128!:2 x=: ?3 4 5$1e9 +(+/"1 x) -: '+/"1' 128!:2 x + + +4!:55 ;:'a i q qr r s x' + +
new file mode 100644 --- /dev/null +++ b/test/g128x3.ijs @@ -0,0 +1,76 @@ +NB. 128!:3 crc-32 ------------------------------------------------------- + +NB. modified from Henry Rich msg to J forum 2005-01-10 + +NB. CRC calculation. +NB. This builds the CRC by passing the bytes into the +NB. MSB of the shiftregister and shifting right, +NB. applying the polynomial (inverted) using the LSB. +NB. Some other implementations seem to process bits in a different order. +NB. CRC-32 of '123456789' is CBF43926 + +NB. crcbyte: One calculation: y is shiftregister, x is new byte +NB. crc: y is string or numeric vector; result is CRC-32 + +bitand =: 17 b. +bitxor =: 22 b. +bitshift=: 33 b. + +shift=: |.!.'' + +mask32 =: <._1+IF64*2^32 +crcpolyb=: |. 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1 +crcpolyi=: mask32 bitand (_2 _2,30$2) #. crcpolyb +crctbli =: (_1&bitshift)`(crcpolyi&bitxor@(_1&bitshift))@.(2&|)^:8"0 +crctblb =: bitshift`(crcpolyb&bitxor@shift)@.{:^:8"0 +prep =: |. @ (mask32&,) @ (a.&i.^:(2:=3!:0)) +crcbyte =: {&(crctbli i.256)@(255&bitand)@bitxor bitxor _8&bitshift@] +crc =: _1&bitxor @ (crcbyte/) @ prep + +f=: 128!:3 + +_873187034 -: f x=: '123456789' +_873187034 -: crcpolyi f x +_873187034 -: crcpolyb f x +_873187034 -: (<crcpolyi) f x +_873187034 -: (<crcpolyb) f x +_873187034 -: (crcpolyi;_1) f x +_873187034 -: (crcpolyb;_1) f x + +(f -: crc) x +(f -: crc) x=: 'assiduously avoid any and all asinine alliterations' + +b=: 32 ?@$ 2 + +'domain error' -: f etx 2 3 4 +'domain error' -: f etx 2 3 4x +'domain error' -: f etx 2 3.4 +'domain error' -: f etx 2 3j4 +'domain error' -: f etx 2 3r4 +'domain error' -: f etx 2 3;4 + +'rank error' -: f etx 3 4$'abc' + +'domain error' -: 123 f etx 3 4 5 +'domain error' -: 123 f etx 3 4 5x +'domain error' -: 123 f etx 3.4 5 +'domain error' -: 123 f etx 3j4 5 +'domain error' -: 123 f etx 3r4 5 + +'domain error' -: '34' f etx 'xyz' +'domain error' -: 3.4 f etx 'xyz' +'domain error' -: 3j4 f etx 'xyz' +'domain error' -: (<'abc') f etx 'xyz' +'domain error' -: (34;'a') f etx 'xyz' +'domain error' -: (b;'a') f etx 'xyz' + +'length error' -: (34;56;3) f etx 'xyz' +'length error' -: (b;_1;3) f etx 'xyz' + + +4!:55 ;:'b bitand bitshift bitxor crc crcbyte crcpoly crcpolyb crcpolyi crctbl' +4!:55 ;:'crctblb crctbli' +4!:55 ;:'f mask32 p prep shift x ' + + +
new file mode 100644 --- /dev/null +++ b/test/g128x5.ijs @@ -0,0 +1,49 @@ +NB. 128!:5 -------------------------------------------------------------- + +isnan=: 128!:5 + +(($x)$0) -: isnan x=: 31 17 3 ?@$ 2 +(($x)$0) -: isnan x=: 31 3 ?@$ 2e9 +(($x)$0) -: isnan x=: 31 ?@$ 0 +(($x)$0) -: isnan x=: j./2 31 ?@$ 0 +(($x)$0) -: isnan x=: 31 17 ?@$ 200x +(($x)$0) -: isnan x=: % /2 31 ?@$ 20x +(($x)$0) -: isnan x=: 'Barack Obama vs. Hillary Clinton' +(($x)$0) -: isnan x=: ;:'John McCain' + +(($x)$0) -: isnan x=: _ __ 567 +(($x)$0) -: isnan x=: _ __ 5j7 + +((i.#x) e. i) -: isnan _. (i=: 100 ?@$ #x)}x=: 1e4 ?@$ 0 +((i.#x) e. i) -: isnan (<_. ) (i=: 100 ?@$ #x)}x=: 1e4 $ a: +((i.#x) e. i) -: isnan (<<<_.) (i=: 100 ?@$ #x)}x=: 1e4 $ a: + +1 = isnan <^:10 ] _. +0 = isnan <20 ?@$ 2 +0 = isnan <20 ?@$ 2e9 +0 = isnan <'abc' + +x=: 1e6 ?@$ 0 +b=: (#x) ?@$ 2 +x=: (-~0j1)+_. (I.b)}x +b -: isnan x + +'domain error' -: 0 (128!:5) etx 3 4 5 +'domain error' -: 1 (128!:5) etx 3 4 5 + + +NB. 128!:5 and mapped boxed arrays -------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + +r=: x=: 1 2 3 ; _. ; 3j4 _. ; 'abc' +(isnan x) -: isnan r + +r=: x=: (5!:1 <'mean') ; _. ; (<<<3j4 _.) ; 'abc' +(isnan x) -: isnan r + +0 = unmap_jmf_ 'q' +0 = unmap_jmf_ 'r' + + +4!:55 ;:'b f f1 g i isnan mean q r x'
new file mode 100644 --- /dev/null +++ b/test/g130.ijs @@ -0,0 +1,29 @@ +NB. %y ------------------------------------------------------------------ + +_ -: % 0 +_ 4 0.1 -: % 0 0.25 10 + +'domain error' -: % etx 'abc' +'domain error' -: % etx ;:'Opposable Thumbs' +'domain error' -: % etx <!.0?2 3 + + +NB. x%y ----------------------------------------------------------------- + +0.75 -: 3 % 4 +_120 -: _12 % 0.1 +_ __ -: 3 _4 % 0 + +'domain error' -: 'abc' % etx 4 +'domain error' -: 'abc' %~etx 4 +'domain error' -: 4 % etx <'abc' +'domain error' -: 4 %~etx <'abc' + +'length error' -: 3 4 % etx 5 6 7 +'length error' -: 3 4 %~etx 5 6 7 +'length error' -: 3 4 % etx i.5 6 +'length error' -: 3 4 %~etx i.5 6 +'length error' -: 3 4 % etx ?4 2$183164 +'length error' -: 3 4 %~etx ?4 2$183164 + +
new file mode 100644 --- /dev/null +++ b/test/g130a.ijs @@ -0,0 +1,141 @@ +NB. B % B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x%y) -: (#.x,.y){0 0 _ 1 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.?2 +(x%z) -: x%($x)$z [ z=.?2 + +(x%y) -: (40$"0 x)%y [ x=. ?10$2 [ y=. ?10 40$2 +(x%y) -: x%40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 0 _ 1 -: 0 0 1 1 % 0 1 0 1 + + +NB. B % I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.?2 +(x%z) -: x%($x)$z [ z=._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +0 0 0 0.25 _0.33333333333333 -: 0 0 0 1 1 % 0 _4 3 4 _3 + + +NB. B % D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.?2 +(x%z) -: x%($x)$z [ z=.o._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +0 0 0 _0.2 0.25 -: 0 0 0 1 1 % 0 _5 1.2 _5 4 + + +NB. I % B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=._1e5+?2e5 +(x%z) -: x%($x)$z [ z=.?2 + +(x%y) -: (40$"0 x)%y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x%y) -: x%40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +__ _5 _ 4 -: _5 _5 4 4 % 0 1 0 1 + + +NB. I % I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.?2e6 +(x%z) -: x%($x)$z [ z=._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +_1.5 _4 _ 6 3.5 -: 3 4 5 6 7 % _2 _1 0 1 2 + + + +NB. I % D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.?2e6 +(x%z) -: x%($x)$z [ z=.o._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. _1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +_2 0 2 -: _1 0 1%0.5 + + +NB. D % B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.o._1e5+?2e5 +(x%z) -: x%($x)$z [ z=.?2 + +(x%y) -: (40$"0 x)%y [ x=. o._1e5+?10$2e5 [ y=. ?10 40$2 +(x%y) -: x%40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10$2 + + 0.25 _ -: 0.25 % 1 0 +_0.25 __ -: _0.25 % 1 0 + + +NB. D % I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.o._1e5+?2e5 +(x%z) -: x%($x)$z [ z=._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. o._1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +_0.25 _0.5 _ 0.5 0.25 -: 0.5 % _2 _1 0 1 2 + 0.25 0.5 __ _0.5 _0.25 -: _0.5 % _2 _1 0 1 2 + + +NB. D % D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. o._1e5+?100$2e5 +(x%y) -: (z+x)%z+y [ z=.{.0 4.5 +(x%y) -: (z*x)%z*y [ z=.{.1 4j5 +(z%y) -: (($y)$z)%y [ z=.o._1e5+?2e5 +(x%z) -: x%($x)$z [ z=.o._1e5+?2e5 + +(x%y) -: (40$"0 x)%y [ x=. o._1e5+?10$2e5 [ y=. o._1e5+?10 40$2e5 +(x%y) -: x%40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. o._1e5+?10$2e5 + +_4 _0.25 -: _2 0.5 % 0.5 _2 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g130i.ijs @@ -0,0 +1,51 @@ +NB. %/ B ---------------------------------------------------------------- + +div=. 4 : 'x%y' + +(%/ -: div/ ) x=.?3 5 23$2 +(%/"1 -: div/"1) x +(%/"2 -: div/"2) x + +(%/ -: div/ ) x=.?3 5 32$2 +(%/"1 -: div/"1) x +(%/"2 -: div/"2) x + + +NB. %/ I ---------------------------------------------------------------- + +div=. 4 : 'x%y' + +(%/ -: div/ ) x=._1e2+? 23$2e2 +(%/ -: div/ ) x=._1e2+?4 23$2e2 +(%/"1 -: div/"1) x +(%/ -: div/ ) x=._1e2+?7 5 23$2e2 +(%/"1 -: div/"1) x +(%/"2 -: div/"2) x + + +NB. %/ D ---------------------------------------------------------------- + +div=. 4 : 'x%y' + +(%/ -: div/ ) x=.0.1*_1e2+? 23$2e2 +(%/ -: div/ ) x=.0.1*_1e2+?4 23$2e2 +(%/"1 -: div/"1) x +(%/ -: div/ ) x=.0.1*_1e2+?7 5 23$2e2 +(%/"1 -: div/"1) x +(%/"2 -: div/"2) x + + +NB. %/ Z ---------------------------------------------------------------- + +div=. 4 : 'x%y' + +(%/ -: div/ ) x=.j./0.1*_1e2+?2 23$2e2 +(%/ -: div/ ) x=.j./0.1*_1e2+?2 4 23$2e2 +(%/"1 -: div/"1) x +(%/ -: div/ ) x=.j./0.1*_1e2+?2 7 5 23$2e2 +(%/"1 -: div/"1) x +(%/"2 -: div/"2) x + +4!:55 ;:'div x' + +
new file mode 100644 --- /dev/null +++ b/test/g130p.ijs @@ -0,0 +1,88 @@ +NB. %/\ B --------------------------------------------------------------- + +(0 0 1 1 ,: 0 0 _ 1) -: %/\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: %/\20$1 +x -: %/\x=.0 0 0 +x -: %/\x=.0 0 0 0 + +div=. 4 : 'x%y' + +(%/\ -: div/\ ) x=. 13$1 +(%/\ -: div/\ ) x=. 0, 12$1 +(%/\ -: div/\ ) x=. 7 13$1 +(%/\ -: div/\ ) x=. 0,6 13$1 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=. 3 5 13$1 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x +(%/\ -: div/\ ) x=. 12$1 +(%/\ -: div/\ ) x=.4 12$1 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=.4 8 12$1 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x + + +NB. %/\ I --------------------------------------------------------------- + +div=. 4 : 'x%y' + +x -: %/\x=. [&.>: 0 0 0 +x -: %/\x=. [&.>: 0 0 0 0 + +(%/\ -: div/\) x=.1 2 3 1e9 2e9 +(%/\ -: div/\) |.x + +(%/\ -: div/\ ) x=. x+0=x=._1e2+? 13$2e2 +(%/\ -: div/\ ) x=. x+0=x=._1e2+?4 13$2e2 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=. x+0=x=._1e2+?3 5 13$2e2 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x + +(%/\ -: div/\ ) x=. x+0=x=._1e9+? 13$2e9 +(%/\ -: div/\ ) x=. x+0=x=._1e9+?4 13$2e9 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=. x+0=x=._1e9+?3 5 13$2e9 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x + + +NB. %/\ D --------------------------------------------------------------- + +div=. 4 : 'x%y' + +x -: %/\x=. [&.o. 0 0 0 +x -: %/\x=. [&.o. 0 0 0 0 + +(%/\ -: div/\ ) x=. x+0=x=.0.01*_1e4+? 13$2e4 +(%/\ -: div/\ ) x=. x+0=x=.0.01*_1e4+?4 13$2e4 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=. x+0=x=.0.01*_1e4+?3 5 13$2e4 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x + + +NB. %/\ Z --------------------------------------------------------------- + +div=. 4 : 'x%y' + +x -: %/\x=. [&.j. 0 0 0 +x -: %/\x=. [&.j. 0 0 0 0 + +(%/\ -: div/\ ) x=. x+0=x=.j./0.1*_1e2+?2 13$2e2 +(%/\ -: div/\ ) x=. x+0=x=.j./0.1*_1e2+?2 4 13$2e2 +(%/\"1 -: div/\"1) x +(%/\ -: div/\ ) x=. x+0=x=.j./0.1*_1e2+?2 3 5 13$2e2 +(%/\"1 -: div/\"1) x +(%/\"2 -: div/\"2) x + +(,'j') -: %/\'j' +(,<'ace') -: %/\<'ace' + +'domain error' -: %/\ etx 'deipnosophist' +'domain error' -: %/\ etx ;:'peace in our time' + +4!:55 ;:'div x' + +
new file mode 100644 --- /dev/null +++ b/test/g131.ijs @@ -0,0 +1,121 @@ +NB. %. ------------------------------------------------------------------ + +X =: +/ . * +en =: 1&{@(,&1 1)@$ +norm =: (%:@X +)@, + +qr =: 3 : 0 + n =. en y + if. 1>:n do. + ((% ;&,. ,~@en@[ $ ]) norm) y + else. + m =. >.-: n + a0 =. m{."1 y + a1 =. m}."1 y + t0 =. qr a0 + q0 =. >@{. t0 + r0 =. >@{: t0 + c =. (+|:q0) X a1 + t1 =. qr a1 - q0 X c + q1 =. >@{. t1 + r1 =. >@{: t1 + (q0,.q1);(r0,.c),(-n){."1 r1 + end. +) + +em =: >.@-:@# NB. m =. >.-:#y. +mm =: ,~@em NB. mm =. m,m +ai =: rinv@(mm {. ]) NB. ai =. rinv mm{.y. +di =: rinv@(mm }. ]) NB. di =. rinv mm}.y. +bee =: (em , em - #) {. ] NB. b =. (m,m-n){.y. +bx =: -@(ai X bee X di) NB. bx =. - ai X b X di +r4 =: (ai,.bx) , (-@# {."1 di) NB. (ai,.bx),(-n){."1 di +rinv =: r4`% @. (1&>:@#) + +minv =: (|.@$ ($,) (rinv@] X +@|:@[)&>/@qr) " 2 +mdiv =: (%.@] +/ . * [) " _ 2 + +id=: =&i.&# + +4 19 -: $%.?19 4$2 +6 10 -: $%.?10 6$100 +7 11 -: $%.?11 7$100 +5 7 -: $%.j./?2 7 5$100 + +1 -: %.1 +(%4) -: %.4 +(%3.5) -: %.3.5 +(%4j_5) -: %.4j_5 + +(%. -: minv) 1 +(%. -: minv) ?12369 +(%. -: minv) o.?1721 +(%. -: minv) j./?100 2001 + +(b-:minv a) *. 1e_10>>./|,(id a)-a X b=.%.a=._50000+?10 10$10000 +(b-:minv a) *. 1e_10>>./|,(id a)-a X b=.%.a=.0.01*_4000+?7 7$10000 +(b-:minv a) *. 1e_10>>./|,(id a)-a X b=.%.a=.j./?2 8 8$1300 + +(b-:minv a) *. (1=+/a*b) *. (+/a*+a)-:%+/b*+b =.%.a=.1=?36$2 +(b-:minv a) *. (1=+/a*b) *. (+/a*+a)-:%+/b*+b =.%.a=._10+?17$20 +(b-:minv a) *. (1=+/a*b) *. (+/a*+a)-:%+/b*+b =.%.a=.0.1*_10+?13$20 +(b-:minv a) *. (1=+/a*b) *. (+/a*+a)-:%+/b*+b =.%.a=.r.?23$20 + +x -: %. x=.=i.1 +x -: %. x=.=i.2 +x -: %. x=.=i.4 +x -: %. x=.=i.9 + +f =. (%@[ * ]) -: %.@:* + +4 f =i.1 +3 f =i.2 +_912 f =i.15 + +_6.9 f =i.1 +5.79 f =i.2 +_13.9 f =i.9 + +0j1 f =i.1 +3j4 f =i.2 +123j_7.9 f =i.16 + +(i.0 0 ) -: %. i.0 0 +(i.0 10) -: %. i.10 0 +(i.0) -: %. i.0 + +(i.0 0 ) -: minv i.0 0 +(i.0 10) -: minv i.10 0 +(i.0) -: minv i.0 + +(i.0 0 ) -: (i.0 0) %. i.0 0 +(i.0 10) -: (i.0 10) %. i.0 0 +(i.0) -: (?10$100) %. i.10 0 +(i.0 3) -: (?10 3$100) %. i.10 0 + +(i.0 0 ) -: (i.0 0) mdiv i.0 0 +(i.0 10) -: (i.0 10) mdiv i.0 0 +(i.0) -: (?10$100) mdiv i.10 0 +(i.0 3) -: (?10 3$100) mdiv i.10 0 + +( ?10$100) (%. -: mdiv) _50000+?10 10$112300 +(0.1*?10$100) (%. -: mdiv) 0.0231*_4000+?10 10$12200 +(j./?2 10$100) (%. -: mdiv) j./0.0231*_4000+?2 10 10$12200 + +(?10 10$100) (%. -: mdiv) ?10 10$100 +(0.1*?7 7$100) (%. -: mdiv) 0.231*_40+?7 7$100 +(j./?2 9 9$100) (%. -: mdiv) r./0.231*_40+?2 9 9$100 + +'domain error' -: %. etx 4 4$'abc' +'domain error' -: %. etx 4 4$<123 + +'domain error' -: 'abcd' %. etx ?4 4$100 + +'length error' -: %. etx ?3 5$123 +'length error' -: 3 4 5 %. etx ?7 4$100 + +4!:55 ;:'X a a0 a1 ai b bee bx c di ' +4!:55 ;:'em en f id m mdiv minv mm n norm ' +4!:55 ;:'q0 q1 q2 qr r0 r1 r4 rinv t0 t1 x ' + +
new file mode 100644 --- /dev/null +++ b/test/g132.ijs @@ -0,0 +1,35 @@ +NB. %:y ----------------------------------------------------------------- + +test =. ^&0.5 -: %: + +test 1=?2 3 4$2 +test _20+?50$50 +test o. _20+?50$50 +test r. ?3 4 5$100 +test i.0 3 4 +test i.3 0 + +1e_15 > | 1.41421356237309504880 - %: 2 +1e_15 > | 1.73205080756887729352 - %: 3 +1e_15 > | 3.16227766016837933199 - %: 10 +1e_15 > | 1.61803398874989482820 - -:>:%:5 + +1e_15 > | 0j1.41421356237309504880 - %: _2 + +'domain error' -: %: etx 'abc' +'domain error' -: %: etx 3;4 5 + + +NB. x%:y ---------------------------------------------------------------- + +'domain error' -: 3 4 %: etx 'ab' +'domain error' -: 3 4 %:~etx 'ab' +'domain error' -: 3 4 %: etx 3;4 5 +'domain error' -: 3 4 %:~etx 3;4 5 + +'length error' -: 3 4 %: etx i.4 3 +'length error' -: 3 4 %:~etx i.4 3 + +4!:55 ;:'test' + +
new file mode 100644 --- /dev/null +++ b/test/g13x.ijs @@ -0,0 +1,170 @@ +NB. 13!: ---------------------------------------------------------------- + +13!:0 [1 + +foo =: foo_loc1_ +foo_loc1_ =: foo_loc2_ / +foo_loc2_ =: foo_loc3_ ~ +foo_loc3_ =: + + +commute =: ~ + +goo =: 4 : 0 + p=.2*x + q=.p goo1 commute y + q*q +) + +goo1 =: goo2 +goo2 =: goo3 +goo3 =: + + +fac =: 3 : 0 + if. 2>y do. 1 + elseif. 2=y do. %'abc' + elseif. 1 do. y*fac y-1 + end. +) + +conj =: 2 : 0 + if. 1=x do. y=.*:@y else. y=.%:@y end. + %glob + y/ +) + +h =: 3 : 'y h1 2' +h1 =: 4 : 'x+y' + +f1 =: 3 : '+/' +f2 =: 3 : '(' + +13!:0 [1 +'domain error' -: (3 : '%y' ) etx 'asdf' +'domain error' -: % (1 : 'u y') etx 'asdf' +13!:0 [0 + +f =: % 1 : 'u y' +'domain error' -: f etx 'asdf' + +f=: 3 : 'try. 13!:8 y catch. 13!:11 $0 end.' + +254 -: f 254 +255 -: f 255 +10 -: f 256 + +13!:8 :: 1: x=: ?256 +x -: 13!:11 '' + +'length error' -: 13!:11 etx 'junkfoo' +'length error' -: 13!:12 etx 'junkfoo' + + +NB. stops --------------------------------------------------------------- + +'' -: 13!:2 '' +1 [ 13!:3 'sum *' +'sum *' -: 13!:2 '' +1 [ 13!:3 '' + + +NB. error text ---------------------------------------------------------- + +sum=: +/ +f=: 3 : '2 3+g y' +g=: 3 : 'if. y do. y else. + end.' +h=: 2 3&+@sum + +'value error: junkfoo' -: fex 'junkfoo' + +'length error: fex' -: fex '2 3+4 5 6' +'domain error: fex' -: fex '+/1;2 3' +'domain error: sum' -: fex 'sum ''asdf''' +'syntax error: g' -: fex 'f 0' +'length error: f' -: fex 'f 2 3 4' +'domain error: sum' -: fex 'h ''asdf''' +'length error: h' -: fex 'h i.3 4' + +'length error: fex' -: fex '2 3+4 5 6' + +f=: 3 : 0 + abc=. 'abc' + ". :: 0: 'abc,',y + 13!:12 '' +) + +' ...' -: _4{. }: f 204 $'123 ' +' ...' -: _4{. }: f 204 $'1.3 ' +' ...' -: _4{. }: f 204 $'1j3 ' +' ...' -: _4{. }: f 221 $(16$'123'),'x ' +' ...' -: _4{. }: f 221 $' 1r',14$'1123' + +18!:55 ;:'loc1 loc2 loc3' + + +NB. 13!:13 ------------------------------------------------------------- + +mean=: sum % # +sum =: [: +/ ".@('t=:13!:13 $0'&[) ] ] + +13!:0 ]1 +1: mean x=: ?4 5$100 + +($t) -: 2 9 +(0{"1 t) -: 'sum';'mean' NB. name +(1{"1 t) -: 0;0 NB. error number +(2{"1 t) -: 0;0 NB. line number +(3{"1 t) -: 3;3 NB. name class +((<1 4){t) -: <'sum % #' NB. definition +(_8{.&.>5{"1 t) -: 2$<'g13x.ijs' NB. defining scripts +(6{"1 t) -: (<,<x),<,<x NB. boxed argument(s) +(7{"1 t) -: 2$<0 2$0 NB. locals +(8{"1 t) e. ' ';'*' NB. * if begins suspension + +1: mean"1 x + +($t) -: 2 9 +(0{"1 t) -: 'sum';'mean' NB. name +(1{"1 t) -: 0;0 NB. error number +(2{"1 t) -: 0;0 NB. line number +(3{"1 t) -: 3;3 NB. name class +((<1 4){t) -: <'sum % #' NB. definition +(_8{.&.>5{"1 t) -: 2$<'g13x.ijs' NB. defining scripts +(6{"1 t) -: (<,<{:x),<,<{:x NB. boxed argument(s) +(7{"1 t) -: 2$<0 2$a: NB. locals +(8{"1 t) e. ' ';'*' NB. * if begins suspension + +sum=: 3 : ('z=.+/y';'t=: 13!:13 $0';'z') + +1: mean"1 x + +($t) -: 2 9 +(0{"1 t) -: 'sum';'mean' NB. name +(1{"1 t) -: 0;0 NB. error number +(2{"1 t) -: 1;0 NB. line number +(3{"1 t) -: 3;3 NB. name class +((<1 4){t) -: <'sum % #' NB. definition +(_8{.&.>5{"1 t) -: 2$<'g13x.ijs' NB. defining scripts +(6{"1 t) -: (<,<{:x),<,<{:x NB. boxed argument(s) +NB. (7{"1 t) -: (('y.';{:x),:(,'z');+/{:x);<0 2$a: NB. locals +(>(<0 7){t) e. ('y.';{:x), ((,'y');{:x),:(,'z');+/{:x NB. locals +(8{"1 t) e. ' ';'*' NB. * if begins suspension + +13!:0 ]0 + + +NB. 13!:18 ------------------------------------------------------------- + +mean=: sum % # +sum=: 3 : ('z=.+/y';'t=: 13!:18 $0';'z') + +13!:0 ]1 +1: mean i.12 +NB. (2{.t) -: (2,{:$t){.];.1 '|sum[1]|mean[0] !' + +13!:0 ]0 + + +4!:55 ;:'commute conj f f1 f2 fac foo ' +4!:55 ;:'g goo goo1 goo2 goo3 h h1 mean sum t x ' + +
new file mode 100644 --- /dev/null +++ b/test/g15x.ijs @@ -0,0 +1,135 @@ +NB. 15!: ---------------------------------------------------------------- + +pc=:(9!:12 '') e. 2 6 NB. works on Windows only + +NB. a small memory leak is expected on the next line +2 = {:15!:1 ((15!:8) 10),0 5 4 NB. reference count + +require'socket' +require 'dll' NB. DLL utils + + +3 : 0'' +if. pc do. + require 'winapi' NB. API utils +else. + winset=:1: +end. +1 +) + +winset 'CREATE_NEW FILE_BEGIN FILE_CURRENT FILE_END GENERIC_READ GENERIC_WRITE' +winset 'OPEN_EXISTING' + +cderx =: 15!:11 + +Fclose =: fclose =: >@{.@('kernel32 CloseHandle i i' &(15!:0)) +Fdelete =: fdelete =: >@{.@('kernel32 DeleteFileA i *c' &(15!:0)) +Fdeletedir=: fdeletedir=: >@{.@('kernel32 RemoveDirectoryA i *c' &(15!:0)) +Fcreate =: >@{.@('kernel32 CreateFileA i *c i i * i i i'&(15!:0)) +Fcreatedir=: >@{.@('kernel32 CreateDirectoryA i *c *' &(15!:0)) +Fsize =: >@{.@('kernel32 GetFileSize i i *i' &(15!:0)) +Fwrite =: >@{.@('kernel32 WriteFile i i * i *i *' &(15!:0)) +Fsetptr =: >@{.@('kernel32 SetFilePointer i i i *i i' &(15!:0)) +Fcopyto =: >@{.@('kernel32 CopyFileA i *c *c i' &(15!:0)) +Fmoveto =: >@{.@('kernel32 MoveFileA i *c *c' &(15!:0)) +Fread =: 'kernel32 ReadFile i i * i *i *' &(15!:0) + +fcopyto =: 4 : 'Fcopyto x,y,<0' +fmoveto =: 4 : 'Fmoveto x,y' +fcreatedir=: 3 : 'Fcreatedir y,<<0' +fsize =: 3 : 'Fsize y;<<0' +fsetptr =: 4 : '>{.Fsetptr x;y;(<0);FILE_BEGIN' + +fcreate=: 3 : 0 NB. fcreate name + >{.Fcreate y,(GENERIC_READ+GENERIC_WRITE);0;(<0);CREATE_NEW ;0;0 +) + +fopen =: 3 : 0 NB. fopen name + >{.Fcreate y,(GENERIC_READ+GENERIC_WRITE);0;(<0);OPEN_EXISTING;0;0 +) + +fwrite =: 4 : 0 NB. string fwrite handle + Fwrite y;x;(#x);(,0);<<0 +) + +fread =: 3 : 0 NB. fread handle + y fsetptr 0 + n=. fsize y + >2{Fread y;(n#' ');n;(,0);<<0 +) + +test=: 3 : 0 NB. windows only +if. pc do. +assert. 1 -: fcreatedir <'testtemp' +assert. 0 -: fdelete <'testtemp\non_existent_file' +assert. 2 -: >{.cderx '' + +assert. _1 ~: h=: fcreate <'testtemp\test.jnk' + +s=: 'boustrophedonic paracletic kerygmatic' +assert. 1 -: s fwrite h + +assert. (#s) -: fsize h +assert. s -: fread h + +i=: ?#s +t=: 'professors in New England guard the glory that was Greece' +assert. i -: h fsetptr i + +assert. 1 -: t fwrite h +assert. (i+#t) -: fsize h +assert. ((i{.s),t) -: fread h +assert. 1 -: fclose h + +assert. 1 -: fcreatedir <'testtemp\tempdir' + +assert. (<'testtemp\test.jnk') fcopyto <'testtemp\test1.jnk' +assert. _1 ~: h=: fopen <'testtemp\test1.jnk' +assert. ((i{.s),t) -: fread h +assert. 1 -: fclose h + +assert. (<'testtemp\test1.jnk') fmoveto <'testtemp\tempdir\test2.jnk' +assert. _1 ~: h=: fopen <'testtemp\tempdir\test2.jnk' +assert. ((i{.s),t) -: fread h +assert. 1 -: fclose h + +assert. 1 -: fdelete <'testtemp\test.jnk' + +assert. 0 -: fdeletedir <'testtemp\tempdir' +assert. (>{.cderx '') e. 5 145 +assert. 1 -: fdelete <'testtemp\tempdir\test2.jnk' +assert. 1 -: fdeletedir <'testtemp\tempdir' +assert. 1 -: fdeletedir <'testtemp' +end. +1 +) + +test '' + +0 -: sdclose_jsocket_ >1{sdsocket_jsocket_'' NB. all systems + +t=: 100 ?@$ 1e6 +t -: 15!:1 (15!:14 <'t'),0,(*/$t),3!:0 t +t=: 100 4 ?@$ 0 +t -: ($t)$15!:1 (15!:14 <'t'),0,(*/$t),3!:0 t + +'domain error' -: 15!:6 etx <'test' +'domain error' -: 15!:6 etx ;:'t test' +'domain error' -: 15!:14 etx <'test' +'domain error' -: 15!:14 etx ;:'t test' + +'value error' -: 15!:6 etx <'undefinedname' +'value error' -: 15!:6 etx ;:'t undefinedname' +'value error' -: 15!:14 etx <'undefinedname' +'value error' -: 15!:14 etx ;:'t undefinedname' + +4!:55 ;:'CREATE_NEW FILE_BEGIN FILE_CURRENT FILE_END GENERIC_READ ' +4!:55 ;:'GENERIC_WRITE OPEN_EXISTING ' +4!:55 ;:'Fclose Fcopyto Fcreate Fcreatedir Fdelete Fdeletedir Fmoveto Fread ' +4!:55 ;:'Fsetptr Fsize Fwrite ' +4!:55 ;:'cderx fclose fcopyto fcreate fcreatedir fdelete fdeletedir fmoveto ' +4!:55 ;:'fopen fread fsetptr fsize fwrite ' +4!:55 ;:'h i pc s t test' + +
new file mode 100644 --- /dev/null +++ b/test/g18x.ijs @@ -0,0 +1,104 @@ +NB. 18!:30 y ------------------------------------------------------------ + +x=: i.12 +sum=: +/ +adv=: / + +t=: 18!:30 <'base' +(,2) -: $t +32 -: type t +'x y' =: t +2 = #$x +3 = {:$x +4 -: type x +32 -: type y +1 = #$y +(;:'adv sum x') e. y +1 3 0 -: (y i. ;:'adv sum x'){{:"1 x + +4!:55 <'sum' +-. (<'sum') e. >1{18!:30 <'base' + +'domain error' -: 18!:30 etx 2 +'domain error' -: 18!:30 etx 2.5 +'domain error' -: 18!:30 etx 2j5 +'domain error' -: 18!:30 etx 2r5 + +'rank error' -: 18!:30 etx '' +'rank error' -: 18!:30 etx ;:'z base' + +'locale error' -: 18!:30 etx <'nonexistentlocale' + + +NB. 18!:31 y ------------------------------------------------------------ + +pcheck=: 3 : 0 + yy=: y + assert. ((,3)-:$y) *. 32=type y + 'p a s'=: y + assert. 2=#$p + assert. (2=#$p) *. 4 =type p NB. symbol pool + assert. (1=#$a) *. 32=type a NB. object name + assert. (1=#$s) *. 32=type s NB. locale name (or '**local**') + assert. (#p) = (#a),#s + + i=: i.#p + b=: 0 0 -:"1 ]2 5{"1 p + assert. {.b + assert. 0=1 2 3 5{"1 b#p + assert. (4{"1 b#p) e. (# i.@#) b + assert. 0 e. 4{"1 b#p + m=: >:>.2^.#b + x=: ~. /:~ ,{~^:(i.m) b*4{"1 p NB. transitive closure + assert. x -: I. b + + f =: 2{"1 p + h =: 2<:4|f NB. head of linked list + li=: 4<:8|f NB. locale info + assert. i -: 0{"1 p NB. index + assert. b +. li +. 0<1{"1 p NB. internal type + assert. li <: (s e.<'**local**')+.32=1{"1 p NB. search path of locales + assert. 0<:f NB. flag + assert. b +. li +. (3{"1 p) e. _1,i.#4!:3 '' NB. script index + assert. i e.~ next=. 4{"1 p NB. next + assert. h +. i e.~ prev=. 5{"1 p NB. prev + assert. b +. h +. (0=next) +. i = (next*-.h){prev,0 + assert. b +. h +. i = (prev*-.h){next,0 + + assert. b +. li +. -. a e. a: + assert. b +. li +. s e. '**local**';18!:1 i.2 + assert. (18!:1 i.2) e. s + 1 +) + +pcheck 18!:31 '' + +k=: 18!:3 '' +sum__k=: +/ +sam__k=: 'United States of America' +junk_asdf_ =: 400$'foo' + +pcheck 18!:31 '' + +18!:55 k,<'asdf' + +f=: 3 : 0 + a=. 12 + b=. o. y + pcheck 18!:31 '' +) + +f 1 2 3 + +(<'asdf') -: 18!:3 <'asdf' +pcheck 18!:31 '' +(<'asdf') -: 6 (18!:3) <'asdf' +pcheck 18!:31 '' +(<'asdf') -: 5 (18!:3) <'asdf' +pcheck 18!:31 '' +18!:55 <'asdf' + + +4!:55 ;:'a adv b f h i k li m p pcheck s sum t x y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g1x.ijs @@ -0,0 +1,150 @@ +NB. 1!: ----------------------------------------------------------------- + +read =. 1!:1 +write =. 1!:2 +append =. 1!:3 +size =. 1!:4 +erase =. 1!:55 + +mtm =. i. 0 0 + +t =. a.,":?~300 +mtm -: t write <'junkfoo' +t =. read <'junkfoo' +1 -: #$t +2 -: type t +(#t) -: size <'junkfoo' + +mtm -: (|.t) write <'oofknuj' +(#t) = size 'junkfoo';'oofknuj' +x =. read <'oofknuj' +x -: |.t + +mtm -: t append <'oofknuj' +(2*#t) = size <'oofknuj' +x =. read <'oofknuj' +x -: (|.t),t + +erase 'junkfoo';'oofknuj' + + +NB. 1!: terminal input/output ------------------------------------------- + +in =. 1!:1 +out =. 1!:2&2 + +NB. 0 0$out 'this line should appear in the output' +t =. in 1 +1 1 1 1 +t -: '1 1 1 1' +t =. in 1 +1 +t -: ,'1' + + +NB. 1!: ----------------------------------------------------------------- + +read =. 1!:1 +write =. 1!:2 +append =. 1!:3 +size =. 1!:4 +erase =. 1!:55 + +'file name error' -: read etx <'J9k8L7m6' +'file name error' -: size etx <'J9k8L7m6' +(<erase etx <'NoSuch.943') e. 'file name error';'interface error' + +'domain error' -: read etx 'ab' +'domain error' -: 'abc' write etx 'ab' +'domain error' -: 'abc' append etx 'ab' +'domain error' -: size etx 'ab' +'domain error' -: erase etx 'ab' + +'file number error' -: read etx 0 +'file number error' -: 'abc' write etx 0 +'file number error' -: 'abc' append etx 0 +'file number error' -: size etx 0 +'file number error' -: erase etx 0 + +'file number error' -: 'abc' write etx 1 +'file number error' -: 'abc' append etx 1 +'file number error' -: size etx 1 +'file number error' -: erase etx 1 + +'file number error' -: read etx 2 +'file number error' -: size etx 2 +'file number error' -: erase etx 2 + +'file number error' -: read etx <2 +'file number error' -: 'abc' write etx <1 +'file number error' -: 'abc' append etx <1 +'file number error' -: size etx <1 +'file number error' -: erase etx <1 + +'file number error' -: read etx 68 +'file number error' -: 'abc' write etx 68 +'file number error' -: 'abc' append etx 68 +'file number error' -: size etx 68 +'file number error' -: erase etx 68 + +'file number error' -: read etx <68 +'file number error' -: 'abc' write etx <68 +'file number error' -: 'abc' append etx <68 +'file number error' -: size etx <68 +'file number error' -: erase etx <68 + +'domain error' -: read etx 3.5 +'domain error' -: 'abc' write etx 3.5 +'domain error' -: 'abc' append etx 3.5 +'domain error' -: size etx 3.5 +'domain error' -: erase etx 3.5 + +'domain error' -: read etx 3j5 +'domain error' -: 'abc' write etx 3j5 +'domain error' -: 'abc' append etx 3j5 +'domain error' -: size etx 3j5 +'domain error' -: erase etx 3j5 + +'domain error' -: read etx <3.5 +'domain error' -: 'abc' write etx <3.5 +'domain error' -: 'abc' append etx <3.5 +'domain error' -: size etx <3.5 +'domain error' -: erase etx <3.5 + +'domain error' -: read etx <3j5 +'domain error' -: 'abc' write etx <3j5 +'domain error' -: 'abc' append etx <3j5 +'domain error' -: size etx <3j5 +'domain error' -: erase etx <3j5 + +'rank error' -: read etx <3 4$'a' +'rank error' -: 'abc' write etx <3 4$'a' +'rank error' -: 'abc' append etx <3 4$'a' +'rank error' -: size etx <3 4$'a' +'rank error' -: erase etx <3 4$'a' + +'length error' -: read etx <'' +'length error' -: 'abc' write etx <'' +'length error' -: 'abc' append etx <'' +'length error' -: size etx <'' +'length error' -: erase etx <'' + +'domain error' -: 1 write etx <'abc' +'domain error' -: 3 write etx <'abc' +'domain error' -: 3.4 write etx <'abc' +'domain error' -: 3j4 write etx <'abc' +'domain error' -: (<'a')write etx <'abc' + +'domain error' -: 1 0 1 append etx <'abc' +'domain error' -: 3 4 append etx <'abc' +'domain error' -: 3.4 5 append etx <'abc' +'domain error' -: 3j4 append etx <'abc' +'domain error' -: (<'a')append etx <'abc' + +'rank error' -: (3 4$'a') write etx <'abc' +'rank error' -: (3 4$'a') append etx <'abc' + + +4!:55 ;:'append erase in mtm out read size t write x' + +
new file mode 100644 --- /dev/null +++ b/test/g1x0.ijs @@ -0,0 +1,44 @@ +NB. 1!:0 ---------------------------------------------------------------- + +dir =. 1!:0 +read =. 1!:1 +size =. 1!:4 + +test =. 3 : 0 + d=.5{."1 y + assert. (0 e.$y)+.32-:type y NB. overall type + assert. (2=#$y)*.5<:{:$y NB. overall shape + assert. (~.type&>d)e. 2 4 4 2 2,:2 4 1 2 2 NB. type + assert. ($&.>}."1 d) e.,&.>(6;'';9;6),:6;'';3;6 NB. shape + assert. p e."_1&>(#&>p)$&.><'rwx',.'-' [ p=.3{"1 d NB. permission + assert. (4{"1 d)e."_1&><'rhsvda',.'-' NB. attributes + 1 +) + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +test dir (-.mac)#'*.*' +test dir (pc#'\*.*'),(unix#'/etc/p*') +test dir (pc#'c:\autoexec.bat'),(unix#'/etc/passwd') + +p =. >{:4!:3 '' +p =. < p ([ }.~ [: - |.@[ i. ]) (pc#'\'),(mac#':'),unix#'/' +d =. dir p,&.><(-.mac)#'*.ijs' +s =. >2{"1 d +s -: #@read p,&.>{."1 d +s -: size p,&.>{."1 d + +'domain error' -: dir etx 1 2 3 +'domain error' -: dir etx 1.2 3 +'domain error' -: dir etx 1j2 3 +'domain error' -: dir etx <1 2 + +'rank error' -: dir etx 2 3$'ab' + +4!:55 ;:'d dir read mac p pc s size t test unix win x' + +
new file mode 100644 --- /dev/null +++ b/test/g1x1.ijs @@ -0,0 +1,71 @@ +NB. 1!:1 ---------------------------------------------------------------- + +dir =. 1!:0 +read =. 1!:1 +write =. 1!:2 +size =. 1!:4 +open =. 1!:21 +close =. 1!:22 +erase =. 1!:55 + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +p =. >{:4!:3 '' +p =. < p ([ }.~ [: - |.@[ i. ]) (pc#'\'),(mac#':'),unix#'/' +f =. p,&.><'g100.ijs' +h =. open f + +(read f) -: read h +(read f) -: read <h +(size h) -: # read h +close h + +f =. <'foogoo5.x' +t =. (?1000$#a.){a. +t write f +h =. open f + +t -: read f +t -: read h + +erase f + +d =. dir p,&.><(-.mac)#'*.ijs' +(>2{"1 d) -: #@read p,&.>{."1 d + +x=.'1'#~1 j. 1 2 4 8 4 2 1 0 +t=.read 1 NB. read from keyboard +1 1 1 1 1 1 1 1 +t -: x +t=.read <1 NB. read from keyboard +1 1 1 1 1 1 1 1 +t -: x + +'domain error' -: read etx 'a' +'domain error' -: read etx 'abc' +'domain error' -: read etx 3.45 +'domain error' -: read etx 3j4 + +'rank error' -: read etx <0 1 0 +'rank error' -: read etx <3 4 +'rank error' -: read etx <1 3$'abc' + +'length error' -: read etx <'' +'length error' -: read etx <i.0 + +'file name error' -: read etx <'1234skidoo' + +'file number error' -: read etx 0 +'file number error' -: read etx 2 +'file number error' -: read etx 12345 12346 +'file number error' -: read etx <0 +'file number error' -: read etx <2 +'file number error' -: read etx <12345 + +4!:55 ;:'close d dir erase f h mac open p pc read size t unix win write x' + +
new file mode 100644 --- /dev/null +++ b/test/g1x11.ijs @@ -0,0 +1,95 @@ +NB. 1!:11 --------------------------------------------------------------- + +write =. 1!:2 +iread =. 1!:11 +open =. 1!:21 +close =. 1!:22 +erase =. 1!:55 + +intv =. [ {~ ([: ({. + i.@{:) ]) + +f =. <'foo1x11.x' +t =. a.{~?1000$#a. +t write f +(t intv i) -: iread f,<i=.?100 900 +h =. open f +(t intv i) -: iread f,<i=.?100 900 +(t intv i) -: iread h, i=.?200 800 +(t intv i) -: iread h; i=.?300 700 +(t intv i) -: iread h, i=.(?1000),0 + +(i}.t) -: iread h, i=.?1000 +(i}.t) -: iread h; i=.?1000 +(i}.t) -: iread f,<i=.?1000 + +(i{.t) -: iread h, i=.->:?1000 +(i{.t) -: iread h; i=.->:?1000 +(i{.t) -: iread f,<i=.->:?1000 + +erase h + + +f =. <'foo1x11.x' +'0123456789' write f +h =. open f + +'domain error' -: iread etx 'abc' +'domain error' -: iread etx 3.4 5 +'domain error' -: iread etx 3j4 2 3 +'domain error' -: iread etx f,<'ab' +'domain error' -: iread etx f,<3.4 5 +'domain error' -: iread etx f,<3j4 5 +'domain error' -: iread etx f,<3;4 +'domain error' -: iread etx h;'ab' +'domain error' -: iread etx h;3.4 5 +'domain error' -: iread etx h;3j4 5 +'domain error' -: iread etx h;<3;4 + +'rank error' -: iread etx 0 1 0;2 3 +'rank error' -: iread etx 3 4;2 3 +'rank error' -: iread etx (1 3$'abc');2 3 +'rank error' -: iread etx f,<i.1 2 + +'length error' -: iread etx 'a' +'length error' -: iread etx '';2 3 +'length error' -: iread etx (i.0);2 3 +'length error' -: iread etx h;i.0 +'length error' -: iread etx ,f +'length error' -: iread etx ,h +'length error' -: iread etx f,<2 3 4 + +'index error' -: iread etx h,10 +'index error' -: iread etx h,9 2 +'index error' -: iread etx h,_11 +'index error' -: iread etx h,_1 2 +'index error' -: iread etx h;10 +'index error' -: iread etx h;9 2 +'index error' -: iread etx h;_11 +'index error' -: iread etx h;_1 2 +'index error' -: iread etx f,<10 +'index error' -: iread etx f,<9 2 +'index error' -: iread etx f,<_11 +'index error' -: iread etx f,<_1 2 + +f =. (3=9!:12 ''){'no/such/dir/or/file';':no:such:dir:or:file' +'file name error' -: iread etx f,<1 2 +'file name error' -: iread etx 'noQsuch';0 + +'file number error' -: iread etx 0 1 0 +'file number error' -: iread etx 1 3 +'file number error' -: iread etx 2 2 +'file number error' -: iread etx _2 2 +'file number error' -: iread etx _1234 2 +'file number error' -: iread etx 12345 12346 +'file number error' -: iread etx 0;1 +'file number error' -: iread etx 1;1 +'file number error' -: iread etx 2;1 +'file number error' -: iread etx _2; 2 +'file number error' -: iread etx _1234;2 +'file number error' -: iread etx 12345;2 3 + +erase h + +4!:55 ;:'close erase f h i intv iread open t write' + +
new file mode 100644 --- /dev/null +++ b/test/g1x12.ijs @@ -0,0 +1,101 @@ +NB. 1!:12 --------------------------------------------------------------- + +read =. 1!:1 +write =. 1!:2 +iread =. 1!:11 +iwrite =. 1!:12 +open =. 1!:21 +erase =. 1!:55 + +f =. <'foo1x12.x' +x =. (?1000$#a.){a. +x write f +h =. open f + +'' iwrite h,?#x +x -: read h + +y =. 'Cogito, ergo sum.' +y iwrite h,100 +y -: iread h,100,#y + +'plangent' iwrite f,<_1 +'plangent' -: iread h,(_1+#x),8 + +erase h + +f =. <'foo1x12.x' +'0123456789' write f +h =. open f + +'domain error' -: 'asdf' iwrite etx 'abc' +'domain error' -: 'asdf' iwrite etx 3.4 5 +'domain error' -: 'asdf' iwrite etx 3j4 2 3 +'domain error' -: 'asdf' iwrite etx f,<'ab' +'domain error' -: 'asdf' iwrite etx f,<3.4 5 +'domain error' -: 'asdf' iwrite etx f,<3j4 5 +'domain error' -: 'asdf' iwrite etx f,<<3 +'domain error' -: 'asdf' iwrite etx h;'ab' +'domain error' -: 'asdf' iwrite etx h;3.4 5 +'domain error' -: 'asdf' iwrite etx h;3j4 5 + +'domain error' -: 0 1 iwrite etx h,1 +'domain error' -: 3 4 5 iwrite etx h,1 +'domain error' -: 3.4 5 iwrite etx h,1 +'domain error' -: 3j4 5 iwrite etx h,1 +'domain error' -: (<'ab')iwrite etx h,1 +'domain error' -: 0 1 iwrite etx h;1 +'domain error' -: 3 4 5 iwrite etx h;1 +'domain error' -: 3.4 5 iwrite etx h;1 +'domain error' -: 3j4 5 iwrite etx h;1 +'domain error' -: (<'ab')iwrite etx h;1 +'domain error' -: 0 1 iwrite etx f,<1 +'domain error' -: 3 4 5 iwrite etx f,<1 +'domain error' -: 3.4 5 iwrite etx f,<1 +'domain error' -: 3j4 5 iwrite etx f,<1 +'domain error' -: (<'ab')iwrite etx f,<1 + +'rank error' -: 'asdf' iwrite etx 0 1 0;2 +'rank error' -: 'asdf' iwrite etx 3 4;2 +'rank error' -: 'asdf' iwrite etx (1 3$'abc');2 3 +'rank error' -: 'asdf' iwrite etx f,<1 1$2 +'rank error' -: (,.a.) iwrite etx h,1 +'rank error' -: (,.a.) iwrite etx h;1 +'rank error' -: (,.a.) iwrite etx f,<1 + +'length error' -: 'asdf' iwrite etx 'a' +'length error' -: 'asdf' iwrite etx '';2 3 +'length error' -: 'asdf' iwrite etx (i.0);2 3 +'length error' -: 'asdf' iwrite etx h;i.0 +'length error' -: 'asdf' iwrite etx ,f +'length error' -: 'asdf' iwrite etx ,h +'length error' -: 'asdf' iwrite etx f,<2 3 4 +'length error' -: 'asdf' iwrite etx h,2 4 +'length error' -: 'asdf' iwrite etx h;2 4 +'length error' -: 'asdf' iwrite etx f,<2 4 + +'index error' -: 'asdf' iwrite etx h,_11 +'index error' -: 'asdf' iwrite etx h;_11 +'index error' -: 'asdf' iwrite etx f,<_11 + +f =. (3=9!:12 ''){'no/such/dir/or/file';':no:such:dir:or:file' +'file name error' -: 'asdf' iwrite etx f,<1 2 + +'file number error' -: 'asdf' iwrite etx 0 1 0 +'file number error' -: 'asdf' iwrite etx 1 3 +'file number error' -: 'asdf' iwrite etx 2 2 +'file number error' -: 'asdf' iwrite etx _2 2 +'file number error' -: 'asdf' iwrite etx _1234 2 +'file number error' -: 'asdf' iwrite etx 12345 12346 +'file number error' -: 'asdf' iwrite etx 0;1 +'file number error' -: 'asdf' iwrite etx 1;1 +'file number error' -: 'asdf' iwrite etx 2;1 +'file number error' -: 'asdf' iwrite etx _2; 2 +'file number error' -: 'asdf' iwrite etx _1234;2 +'file number error' -: 'asdf' iwrite etx 12345;2 3 + +erase h + +4!:55 ;:'erase f h iread iwrite open read write x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x2.ijs @@ -0,0 +1,68 @@ +NB. 1!:2 ---------------------------------------------------------------- + +read =. 1!:1 +write =. 1!:2 +erase =. 1!:55 + +f =. <'foogQ0m1.x' +x =. (?1000$#a.){a. +x write f + +x-:read f +x-:read f [ (x=.a.{~?(>:?1000)$#a.) write f +x-:read f [ x=.,'j' [ 'j' write f +x-:read f [ (x=.'') write f + +erase f + +NB. 0 0$((0j7,1 j.0,~2^i.5)#'1') write 2 +NB. 1 1 1 1 1 1 The 1s should line up + +read =. 1!:1 +write =. 1!:2 + +'domain error' -: 'abcd' write etx 'a' +'domain error' -: 'abcd' write etx 'abc' +'domain error' -: 'abcd' write etx 3.45 +'domain error' -: 'abcd' write etx 3j4 + +'domain error' -: 0 1 0 write etx <'asdf' +'domain error' -: 3 4 write etx <'asdf' +'domain error' -: 3.4 5.6 write etx <'asdf' +'domain error' -: 3j4 0 write etx <'asdf' +'domain error' -: (<'abc')write etx <'asdf' + +'rank error' -: 'abcd' write etx <0 1 0 +'rank error' -: 'abcd' write etx <3 4 +'rank error' -: 'abcd' write etx <1 3$'abc' + +'rank error' -: (,.'ab')write etx <'asdf' + +'length error' -: 'abcd' write etx <'' +'length error' -: 'abcd' write etx <i.0 + +'file number error' -: 'abcd' write etx 0 +'file number error' -: 'abcd' write etx 1 +'file number error' -: 'abcd' write etx 3 +'file number error' -: 'abcd' write etx 345 +'file number error' -: 'abcd' write etx <0 +'file number error' -: 'abcd' write etx <1 +'file number error' -: 'abcd' write etx <3 +'file number error' -: 'abcd' write etx <345 + +'domain error' -: 3j4 0 write etx <'noQsuch' +'file name error' -: read etx <'noQsuch' + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +f =. mac{'no/such/dir/or/file';':no:such:dir:or:file' + +'file name error' -: 'asdf' write etx f + +4!:55 ;:'erase f mac pc read unix win write x' + +
new file mode 100644 --- /dev/null +++ b/test/g1x20.ijs @@ -0,0 +1,98 @@ +NB. 1!:20 --------------------------------------------------------------- + +dir =. 1!:0 +write =. 1!:2 +files =. 1!:20 +open =. 1!:21 +close =. 1!:22 +erase =. 1!:55 + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +f =. <'foo.x' +g =. <'g' + +(128$'a') write f +h =. open f +h -: open f +h -: open h +h -: open <h +h e. >{."1 files '' +erase h +(214$'triskaidekaphobic') write g +q =. files '' +h =. open <'non1such.x' +erase g,<'non1such.x' +q -: files '' + +0~:open g +close g +q -: files '' +erase g + +d =. ({. ~ 5: <. #) {."1 dir mac{'../js/*.*';'::js:' +h =. open (<(unix#''),(pc#'../js/'),mac#':temp:'),&.>d +h e. >{."1 files '' +q e. files '' +close h +q -: files '' + +x -: open x=.'' +x -: open x=.i.0 1 2 +x -: open x=.0 1 2$a: + +x -: close x=.'' +x -: close x=.i.0 1 2 +x -: close x=.0 1 2$a: + +'domain error' -: open etx 'a' +'domain error' -: open etx 'abc' +'domain error' -: open etx 3.45 +'domain error' -: open etx <3.45 +'domain error' -: open etx 3j4 +'domain error' -: open etx <3j4 + +'rank error' -: open etx <3 4$'a' +'rank error' -: open etx <21 31 + +'length error' -: open etx <'' +'length error' -: open etx <i.0 + +'file number error' -: open etx 0 +'file number error' -: open etx 1 +'file number error' -: open etx 2 +'file number error' -: open etx 3 4 5 +'file number error' -: open etx 0;1;0 +'file number error' -: open etx 3;4;5 + +t=.(pc#'does\not\exist\no.x'),(mac#':does:not:exist:no.x'),unix#'does/not/exist/no.x' +'file name error' -: open etx <t + +'domain error' -: close etx 'abc' +'domain error' -: close etx 3.45 +'domain error' -: close etx <3.45 +'domain error' -: close etx 3j4 +'domain error' -: close etx <3j4 + +'rank error' -: close etx <1 4$'a' +'rank error' -: close etx <21 31 + +'length error' -: close etx <'' +'length error' -: close etx <i.0 + +'file number error' -: close etx 0 +'file number error' -: close etx 1 +'file number error' -: close etx 2 +'file number error' -: close etx 0 1 +'file number error' -: close etx i.2 4 +'file number error' -: close etx 12345 12346 +'file number error' -: close etx 0;1;0 +'file number error' -: close etx 4;5;6 + +4!:55 ;:'close d dir erase f files g h mac open pc q t unix win write x' + +
new file mode 100644 --- /dev/null +++ b/test/g1x3.ijs @@ -0,0 +1,57 @@ +NB. 1!:3 ---------------------------------------------------------------- + +read =. 1!:1 +write =. 1!:2 +append =. 1!:3 +erase =. 1!:55 + +f =. <'foogQ0m1.x' +x =. (?1000$#a.){a. +x append f + +x-:read f +x-:read f [ y append f [ x=.x,y=.a.{~?(>:?1000)$#a. +x-:read f [ y append f [ x=.x,y=.'j' +x-:read f [ y append f [ x=.x,y=.'' + +erase f + +'domain error' -: 'abcd' append etx 'a' +'domain error' -: 'abcd' append etx 'abc' +'domain error' -: 'abcd' append etx 3.45 +'domain error' -: 'abcd' append etx 3j4 + +'domain error' -: 0 1 0 append etx <'asdf' +'domain error' -: 3 4 append etx <'asdf' +'domain error' -: 3.4 5.6 append etx <'asdf' +'domain error' -: 3j4 0 append etx <'asdf' +'domain error' -: (<'abc')append etx <'asdf' + +'rank error' -: 'abcd' append etx <0 1 0 +'rank error' -: 'abcd' append etx <3 4 +'rank error' -: 'abcd' append etx <1 3$'abc' + +'rank error' -: (,.'ab')append etx <'asdf' + +'length error' -: 'abcd' append etx <'' +'length error' -: 'abcd' append etx <i.0 + +'file number error' -: 'abcd' append etx 0 +'file number error' -: 'abcd' append etx 1 +'file number error' -: 'abcd' append etx 3 +'file number error' -: 'abcd' append etx 345 +'file number error' -: 'abcd' append etx <0 +'file number error' -: 'abcd' append etx <1 +'file number error' -: 'abcd' append etx <3 +'file number error' -: 'abcd' append etx <345 + +'domain error' -: 3j4 0 append etx <'noQsuch' +'file name error' -: read etx <'noQsuch' + +mac =. 3 = 9!:12 '' +f =. mac{'no/such/dir/or/file';':no:such:dir:or:file' +'file name error' -: 'asdf' append etx f + +4!:55 ;:'append erase f mac read write x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x30.ijs @@ -0,0 +1,68 @@ +NB. 1!:30 --------------------------------------------------------------- + +pc=: (9!:12 '') e. 0 1 2 6 7 NB. works on DOS or Windows only + +3 : 0 '' +if. pc do. + +write =: 1!:2 +open =: 1!:21 +close =: 1!:22 +locks =: 1!:30 +lock =: 1!:31 +unlock =: 1!:32 + +f =: <'foo.x' +(128$'a') write f +h =: open f + +k =: locks '' +assert. lock h,0 8 +assert. lock h,8 16 +assert. 0 -: lock h,0 16 +assert. ((h,0 8),:h,8 16)e.locks '' + +assert. unlock h,0 8 +assert. unlock h,8 16 +assert. k -: locks '' + +assert. lock h,0 8 +assert. lock h,8 16 +assert. lock h,64 1 +close h +assert. k -: locks '' + +assert. 'domain error' -: lock etx 'a' +assert. 'domain error' -: lock etx 'abc' +assert. 'domain error' -: lock etx 3.45 +assert. 'domain error' -: lock etx 3j4 +assert. 'domain error' -: lock etx 0;1;0 +assert. 'domain error' -: lock etx 4;5;6 + +assert. 'file number error' -: lock etx 0 0 1 +assert. 'file number error' -: lock etx 1 4 5 +assert. 'file number error' -: lock etx 2 4 5 +assert. 'file number error' -: lock etx 12345 12346,"0 1 [ 4 5 + +assert. 'domain error' -: unlock etx 'abc' +assert. 'domain error' -: unlock etx 3.45 5 +assert. 'domain error' -: unlock etx 3j4 +assert. 'domain error' -: unlock etx 0;1;0 +assert. 'domain error' -: unlock etx 4;5;6 +assert. 'domain error' -: unlock etx 0 0 1 + +assert. 'index error' -: unlock etx 3 +assert. 'index error' -: unlock etx 4 +assert. 'index error' -: unlock etx 1234 5 +assert. 'index error' -: unlock etx i.2 4 +assert. 'index error' -: unlock etx 1 4 5 +assert. 'index error' -: unlock etx 2 4 5 +assert. 'index error' -: unlock etx 12345 12346,"0 1 [ 4 5 +end. +1 +) + + +4!:55 ;:'close f h k lock locks open pc unlock write ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x4.ijs @@ -0,0 +1,57 @@ +NB. 1!:4 ---------------------------------------------------------------- + +dir =. 1!:0 +size =. 1!:4 +open =. 1!:21 +close =. 1!:22 + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +p =. >{:4!:3 '' +p =. < p ([ }.~ [: - |.@[ i. ]) (pc#'\'),(mac#':'),unix#'/' +d =. dir p,&.><(-.mac)#'*.ijs' +(>2{"1 d) -: size p,&.>{."1 d + +j =. (5<.#d)?#d +f =. p,&.>j{0{"1 d +s =. >j{2{"1 d +h =. open f +s = size f +s = size h +s = size ;/h +(s,s) = size f,<"0 h +close h + +'domain error' -: size etx 'a' +'domain error' -: size etx 3.45 +'domain error' -: size etx 3j4 +'domain error' -: size etx <3.45 +'domain error' -: size etx <3j4 + +'rank error' -: size etx <1 4$'asdf' +'rank error' -: size etx <0 1 0 +'rank error' -: size etx <1 2 3 4 + +'length error' -: size etx <'' +'length error' -: size etx <i.0 + +'file number error' -: size etx 0 +'file number error' -: size etx 1 +'file number error' -: size etx 2 +'file number error' -: size etx 12311 12313 +'file number error' -: size etx <0 +'file number error' -: size etx <1 +'file number error' -: size etx <2 +'file number error' -: size etx <12311 + +f =. mac{'no/such/dir/or/file';':no:such:dir:or:file' +'file name error' -: size etx f +'file name error' -: size etx <'noQsuch' + +4!:55 ;:'close d dir f h j mac open p pc s size unix win x ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x43.ijs @@ -0,0 +1,18 @@ +NB. 1!:43 and 1!:44 ----------------------------------------------------- + +(1=#$s) *. 2=type s=: 1!:43 '' +'' -: 1!:44 s + +'domain error' -: 1!:44 etx 0 1 0 +'domain error' -: 1!:44 etx 1 2 3 +'domain error' -: 1!:44 etx 1 2j3 +'domain error' -: 1!:44 etx <s + +'rank error' -: 1!:44 etx ,:s + +'length error' -: 1!:44 etx '' + + +4!:55 ;:'s' + +
new file mode 100644 --- /dev/null +++ b/test/g1x5.ijs @@ -0,0 +1,51 @@ +NB. 1!:5 ---------------------------------------------------------------- + +dir =. 1!:0 +read =. 1!:1 +write =. 1!:2 +mkdir =. 1!:5 +att =. 1!:6 +erase =. 1!:55 + +x=. 9!:12 '' +win =. x e. 2 6 +mac =. x e. 3 +unix=. x e. 5 7 +pc =. x e. 0 1 2 6 + +p=: (1!:43 ''),mac{'/:' + +mkdir d=.<'brandnew' +". pc#'''----d-'' -: att d' + +f=. p&,&.> mac{'brandnew/foo.x';':brandnew:foo.x' +0 0$(x=.a.{~?500$#a.) write f +x -: read f +(<'foo.x') -: _5{.&.> {.,dir p&,&.>mac{'brandnew/*.*';':brandnew' + +erase f,d + +'domain error' -: mkdir etx 0 +'domain error' -: mkdir etx 2 +'domain error' -: mkdir etx 'a' +'domain error' -: mkdir etx 3.45 +'domain error' -: mkdir etx 3j4 +'domain error' -: mkdir etx <0 1 0 +'domain error' -: mkdir etx <1 2 3 4 + +'rank error' -: mkdir etx <1 3$'abc' + +badf =. e.&('interface error';'file name error') +badf <mkdir etx <'' +badf <mkdir etx mac{'does/not/exist';':does:not:exist' +badf <mkdir etx <':bad:/bad/\bad\' + +'asdf' write <'conflict' +bada =. e.&('interface error';'file access error') +bada <mkdir etx <'conflict' +erase <'conflict' + +4!:55 ;:'att bada badf d dir erase f mac mkdir p pc ' +4!:55 ;:'read unix win write x ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x55.ijs @@ -0,0 +1,68 @@ +NB. 1!:55 --------------------------------------------------------------- + +write =. 1!:2 +files =. 1!:20 +open =. 1!:21 +lock =. 1!:31 +erase =. 1!:55 + +f =. <'foo1x55.x' +g =. <'goo1x55.x' +q =. files '' + +(128$'a') write f +erase f + +(128$'a') write f +h =. open f +erase f +q -: files '' + +(128$'a') write f +h =. open f +erase h +q -: files '' + +(128$'a') write f +h =. open f +erase <h +q -: files '' + +(128$'a') write f +(281$'a') write g +h =. open f +erase g,<h +q -: files '' + +'domain error' -: erase etx 'a' +'domain error' -: erase etx 'abc' +'domain error' -: erase etx 3.45 +'domain error' -: erase etx 3j4 +'domain error' -: erase etx <3.45 +'domain error' -: erase etx <3j4 +'domain error' -: erase etx <0;1;0 + +'file number error' -: erase etx 0 +'file number error' -: erase etx 1 +'file number error' -: erase etx 2 +'file number error' -: erase etx <0 +'file number error' -: erase etx <1 +'file number error' -: erase etx <2 +'file number error' -: erase etx 0;1;0 +'file number error' -: erase etx 3;4;5 +'file number error' -: erase etx 12345 12346 + +'rank error' -: erase etx <3 4 5 +'rank error' -: erase etx <3 4$'a' + +'length error' -: erase etx <'' +'length error' -: erase etx <i.0 + +mac =. 3 = 9!:12 '' +f =. mac{'no/such/dir/or/file';':no:such:dir:or:file' +(<erase etx <'NoSuch.943') e. 'file name error';'interface error' +(<erase etx f ) e. 'file name error';'interface error' + +4!:55 ;:'erase f files g h lock mac open q write ' + +
new file mode 100644 --- /dev/null +++ b/test/g1x7.ijs @@ -0,0 +1,80 @@ +NB. 1!:7 ---------------------------------------------------------------- + +write =: 1!:2 +mkdir =: 1!:5 +perm =: 1!:7 +open =: 1!:21 +close =: 1!:22 +erase =: 1!:55 + +unix =: (9!:12 '') e. 5 7 +nn =: unix{3 9 + +test =: 3 : ('((,nn)-:$y) *. *./y e."_1 nn$''rwx'',.''-''') + +d =. <'brandnew' +mkdir d +test perm d +erase d + +f =. <'foogoo5.x' +'foo upon thee' write f +test perm f + +(nn$'r--') perm f +(nn$'r--') = perm f +(nn$'rw-') perm f +(nn$'rw-') = perm f +h =. open f +(nn$'rw-') = perm h +close h + +h =. open f +(perm h) -: perm f +(perm h) -: perm <h +close h + +erase f + + +NB. 1!:7 ---------------------------------------------------------------- + +perm =. 1!:7 + +'domain error' -: perm etx 'a' +'domain error' -: perm etx 'abc' +'domain error' -: perm etx 3.45 +'domain error' -: perm etx 3j4 +'domain error' -: perm etx <3.45 +'domain error' -: perm etx <3j4 +'domain error' -: perm etx <<'abc' + +'rank error' -: perm etx <0 1 0 +'rank error' -: perm etx <,4 +'rank error' -: perm etx <1 3$'abc' + +'length error' -: perm etx <'' + +'file name error' -: perm etx <'1234skidoo' +'file name error' -: perm etx <'does\not\exist' + +'file number error' -: perm etx 0 +'file number error' -: perm etx 1 +'file number error' -: perm etx 2 +'file number error' -: perm etx 12345 12346 + +'domain error' -: 0 1 0 perm etx <'foo.x' +'domain error' -: 3 1 perm etx <'foo.x' +'domain error' -: 3.5 perm etx <'foo.x' +'domain error' -: 3j4 perm etx <'foo.x' +'domain error' -: (<'r')perm etx <'foo.x' +'domain error' -: (nn$'abc') perm etx <'foo.x' +'domain error' -: (nn$'a--') perm etx <'foo.x' +'domain error' -: (nn$'-a-') perm etx <'foo.x' +'domain error' -: (nn$'--a') perm etx <'foo.x' + +'length error' -: 'wx' perm etx <'foo.x' + +4!:55 ;:'close d erase f h mkdir nn open perm test unix write ' + +
new file mode 100644 --- /dev/null +++ b/test/g200.ijs @@ -0,0 +1,320 @@ +NB. ^y ------------------------------------------------------------------ + +x =: 0.001 * _900+?4 5$2000 +y =: 0.001 * _900+?4 5$2000 +a =: x j. (*y)*(o.1)|y +a =: a,0,*/\4$0j1 + +exp=: (%!i._50) & (+/ .*) @ ((i._50)&(^~/)) + +5e_13 > | (^a)%~(^a)-exp a +a =!.5e_13 ^.^a +a =!.5e_13 ^^.a + +1 -: ^ 0 +2.71828182845904523536 -: ^ 1 +7.38905609893065022723 -: ^ 2 +148.4131591025766 -: ^ 5 + +rou =: [:^ 0j2p1&% * i. NB. roots of unity +([: */ 1: = rou ^ ])"0 i.4 5 + +0 < ^ _744.440 NB. _1074*^.2 +0 = ^ _744.441 +_ > ^ 709.782 NB. 1024*^.2 +_ = ^ 709.783 + +0 = ^ __ +0 = ^ __j5 __j_5 + +'domain error' -: ^ etx 'abc' +'domain error' -: ^ etx <'abc' + +0 = ^_744.441j2e9 +0 = ^_744.441j_2e9 + +'limit error' -: ^ etx _744.440j2e9 +'limit error' -: ^ etx _744.440j_2e9 + +(j./ ^710+^. 2 1 o.0.01) = ^ 710j0.01 +(j./ ^710+^. 2 1 o.1.57) = ^ 710j1.57 +(j./_1 1 * ^710+^.|2 1 o.1.58) = ^ 710j1.58 +(j./_1 _1 * ^710+^.|2 1 o.4.71) = ^ 710j4.71 +(j./ 1 _1 * ^710+^. 2 1 o.1.57) = ^ 710j_1.57 +(j./ 1 _1 * ^710+^. 2 1 o.0.01) = ^ 710j_0.01 + + +NB. x^y ----------------------------------------------------------------- + +pow =: ^.@[ ^@* ] + +(x=:x+0=x=:_50+?4$100) (^-:pow) y=: _50+?4 10$100 +(x=:x+0=x=:_50+?4 10 2$100) (^-:pow) y=: 0.02*_50+?4 10$100 +(x=:x+0=x=:o._50+?4 10$100) (^-:pow) y=:o. 0.01*_50+?4 10$100 +(x=:x+0=x=:r./_50+?2 4$100) (^-:pow) y=:j./0.01*_50+?2 4 10$100 + +(a^ i.30) -: */\1,29$ a=: 2 +(a^-i.30) -: */\1,29$%a=: 2 +(a^ i.30) -: */\1,29$ a=:_2 +(a^-i.30) -: */\1,29$%a=:_2 +(a^ i.30) -: */\1,29$ a=: 2.45 +(a^-i.30) -: */\1,29$%a=: 2.45 +(a^ i.30) -: */\1,29$ a=:_2.45 +(a^-i.30) -: */\1,29$%a=:_2.45 +(a^ i.30) -: */\1,29$ a=: 2j1.6 +(a^-i.30) -: */\1,29$%a=: 2j1.6 +(a^ i.30) -: */\1,29$ a=: 2j_1.6 +(a^-i.30) -: */\1,29$%a=: 2j_1.6 +(a^ i.30) -: */\1,29$ a=:_2j1.6 +(a^-i.30) -: */\1,29$%a=:_2j1.6 +(a^ i.30) -: */\1,29$ a=:_2j_1.6 +(a^-i.30) -: */\1,29$%a=:_2j_1.6 + +a -: a^1 [ a=: ?20$2e9 +a -: a^1 [ a=:-?20$2e9 +a -: a^1 [ a=:o._1e9+?20$2e9 +a -: a^1 [ a=:j./_1e9+?2 20$2e9 + +(20$1) -: a^0 [ a=: ?20$2e9 +(20$1) -: a^0 [ a=:-?20$2e9 +(20$1) -: a^0 [ a=:o._1e9+?20$2e9 +(20$1) -: a^0 [ a=:r./_1e7+?2 20$2e7 + +1 0 1 1 -: 0 0 1 1 ^ 0 1 0 1 + +1 -: 0^0 +(9$1) -: (-:_5+i.9)^0 + +_ _ _ _ 1 0 0 0 0 -: 0 ^ _4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4 )^ _4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4.5)^ _4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4j5)^ _4+i.9 + +_ _ _ _ 1 0 0 0 0 -: 0 ^ -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4 )^ -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4.5)^ -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4j5)^ -:_4+i.9 + +_ _ _ _ 1 0 0 0 0 -: 0 ^ }. 0j1, -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4 )^ }. 0j1, -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4.5)^ }. 0j1, -:_4+i.9 +_ _ _ _ 1 0 0 0 0 -: ({.0 4j5)^ }. 0j1, -:_4+i.9 + +a=:1.41421356237309504880 +a -: 2 ^ 0.5 +(%a) -: 2 ^_0.5 +(%a) -: 0.5 ^ 0.5 +a -: 0.5 ^_0.5 +(0, a) -: +. _2 ^ 0.5 +(0,%-a) -: +. _2 ^_0.5 +(0,% a) -: +. _0.5 ^ 0.5 +(0, -a) -: +. _0.5 ^_0.5 + +1.25992104989487316476 -: 2^%3 + +x=: j./_50+2 30 ?@$ 100 +n=: 30 ?@$ 50 +x (^ -: pow) n +x (^ -: pow) -n + +'domain error' -: 3 ^ etx 'abc' +'domain error' -: 3 ^~etx 'abc' +'domain error' -: 2 ^ etx 2;4 5 +'domain error' -: 2 ^~etx 2;4 5 + +'length error' -: 2 3 ^ etx 4 5 6 +'length error' -: 2 3 ^~etx 4 5 6 +'length error' -: 2 3 ^ etx i.4 5 +'length error' -: 2 3 ^~etx i.4 5 + + +NB. x^0 ----------------------------------------------------------------- + +e.&'1 ' ": x ^ 0 [ x=: ?200$2 +e.&'1 ' ": x ^ 0 [ x=: _5e6+?200$1e7 +e.&'1 ' ": x ^ 0 [ x=: 0.001*_5e6+?200$1e7 +e.&'1 ' ": x ^ 0 [ x=: j./0.001*_5e6+?2 200$1e7 + + +NB. 0^y ----------------------------------------------------------------- + +e.&'0 ' ": 0 ^ 10$1 +e.&'0 ' ": 0 ^ 1+?10$1e6 +e.&'0 ' ": 0 ^ 0.1*1+?10$2e9 +e.&'0 ' ": 0 ^ j./ 1+?2 10$2e3 + +e.&'0 ' ": (2-2) ^ 10$1 +e.&'0 ' ": (2-2) ^ 1+?10$1e6 +e.&'0 ' ": (2-2) ^ 0.1*1+?10$2e9 +e.&'0 ' ": (2-2) ^ j./ 1+?2 10$2e3 + +e.&'0 ' ": (o.0) ^ 10$1 +e.&'0 ' ": (o.0) ^ 1+?10$1e6 +e.&'0 ' ": (o.0) ^ 0.1*1+?10$2e9 +e.&'0 ' ": (o.0) ^ j./ 1+?2 10$2e3 + +e.&'0 ' ": (-~2j1) ^ 10$1 +e.&'0 ' ": (-~2j1) ^ 1+?10$1e6 +e.&'0 ' ": (-~2j1) ^ 0.1*1+?10$2e9 +e.&'0 ' ": (-~2j1) ^ j./ 1+?2 10$2e3 + +(,'_') -: ": 0^_5 +(,'_') -: ": 0^_5.4 + +(,'0') -: ": 0^3j4 +'_ _ 0 0 0 0 0 0' -: ": 0^_3 _1 0j3 0j_3 3j4 3j_4 _3j4 _3j_4 + + +NB. 0^0 ----------------------------------------------------------------- + +(,'1') -: ": ^~0 +(,'1') -: ": ^~-~2 +(,'1') -: ": ^~-~2.5 +(,'1') -: ": ^~-~2j5 + + +NB. x^0.5 --------------------------------------------------------------- + +x -: *~ x^0.5 [ x=:?2000$2 +(%:x) -: x^0.5 +(j.x^0.5) -: (-x)^0.5 + +x -: *~ x^0.5 [ x=:?2000$10000 +(%:x) -: x^0.5 +(j.x^0.5) -: (-x)^0.5 + +x -: *~ x^0.5 [ x=:0.01*?2000$10000 +(%:x) -: x^0.5 +(j.x^0.5) -: (-x)^0.5 + +x -: *~ x^0.5 [ x=:j./0.01*_5000+?2 2000$10000 +(%:x) -: x^0.5 + + +NB. x ^!.s y ------------------------------------------------------------ + +(3 ^!.4 [ 6) -: */3+4*i.6 +(3j4^!._1 [ 6) -: */3j4-i.6 + +f =: 4 : '*/x+(i.y)*/s' + +(12 ^!.s 6) -: 12 f 6 [ s=:1.5 +(12 ^!.s 6) -: 12 f 6 [ s=:1 +(12 ^!.s 6) -: 12 f 6 [ s=:_1 + +'domain error' -: ^!.4 etx 5 +'domain error' -: 3^!.4 etx 5.6 +'domain error' -: ex '^!.''a''' +'domain error' -: ex '^!.(<4) ' + + +NB. x m&|@^ y ----------------------------------------------------------- + +6 = 2 (10&|@^) 1e9 +2 = 2 (10&|@^) 1+1e9 +4 = 2 (10&|@^) 2+1e9 +8 = 2 (10&|@^) 3+1e9 + +6 = 2x (10&|@^) 1e9 +2 = 2x (10&|@^) 1+1e9 +4 = 2x (10&|@^) 2+1e9 +8 = 2x (10&|@^) 3+1e9 + +6 = 2 (10&|@^) 10^40x +2 = 2 (10&|@^) 1+10^40x +4 = 2 (10&|@^) 2+10^40x +8 = 2 (10&|@^) 3+10^40x + +6 = 2x (10&|@^) 10^40x +2 = 2x (10&|@^) 1+10^40x +4 = 2x (10&|@^) 2+10^40x +8 = 2x (10&|@^) 3+10^40x + +6 = 10&|@(2 &^) 1e9 +2 = 10&|@(2 &^) 1+1e9 +4 = 10&|@(2 &^) 2+1e9 +8 = 10&|@(2 &^) 3+1e9 + +6 = 10&|@(2x&^) 1e9 +2 = 10&|@(2x&^) 1+1e9 +4 = 10&|@(2x&^) 2+1e9 +8 = 10&|@(2x&^) 3+1e9 + +6 = 10&|@(2 &^) 10^40x +2 = 10&|@(2 &^) 1+10^40x +4 = 10&|@(2 &^) 2+10^40x +8 = 10&|@(2 &^) 3+10^40x + +6 = 10&|@(2x&^) 10^40x +2 = 10&|@(2x&^) 1+10^40x +4 = 10&|@(2x&^) 2+10^40x +8 = 10&|@(2x&^) 3+10^40x + +f=: 3 : 0 + assert. 2 (y&|@^ -: y&|@^&x:) 10000 + assert. 3 (y&|@^ -: y&|@^&x:) 10000 + assert. 5 (y&|@^ -: y&|@^&x:) 10000 + assert. 64 (y&|@^ -: y&|@^&x:) 10000 + assert. 17393 (y&|@^ -: y&|@^&x:) 10000 + 1 +) + +f 1e9 +f"0 (i:2)+<.%:<:2^IF64{31 63 +f"0 (i:2)+<.%:<:2^53 + +x=: 7700892415753674751x +1 = 2 x&|@^ -:x-1 + +(3 (17 &|)@^ 9.5) -: 17|3 ^9.5 +(3 (17x&|)@^ 9.5) -: 17|3 ^9.5 +(3.7 (17 &|)@^ 9 ) -: 17|3.7^9 +(3.7 (17x&|)@^ 9 ) -: 17|3.7^9 + +h=: 7927 +y=: 1e5 4 2 +((895 h&|@^ y),h|895 ^_1) -: 895 h&|@^ y,_1 +((895x h&|@^ y),h|895x^_1) -: 895x h&|@^ y,_1 + +(10000&|@(2&^) x) -: 2 (10000&|@^) x=: 5 10 ?@$ 1e6 + + +NB. x^y on infinite arguments ------------------------------------------- + +0 -: 0 ^ _ +_ -: 0 ^ __ +_ -: 2.5 ^ _ +1 -: 1 ^ _ +0 -: _0.5 ^ _ +0 -: 0.5 ^ _ + +'domain error' -: _1 ^ etx _ +'domain error' -: _1 ^ etx __ +'domain error' -: _5.15 ^ etx _ +'domain error' -: _0.15 ^ etx __ + +0 0 0 1 _ _ _ _ -: ({._ 1x)^ __ _5 _4 0 1 2 3x _ +0 0 0 1 __ _ __ -: ({.__ 1x)^ __ _5 _4 0 1 2 3x + 0 1 _ _ _ -: 0 1 2 3x _ ^ {. _ 1x +0 0 0 _ 1 0 0 0 -: __ _5 _4 0 1 2 3x _ ^ {. __ 1x + +'domain error' -: _5x ^ etx {._ 1x +'domain error' -: __ 1x ^ etx {._ 1x + +0 0 0 1 _ _ _ _ -: ({._ 1r1)^ __ _5 _4 0 1 2 3r1 _ +0 0 0 1 __ _ __ -: ({.__ 1r1)^ __ _5 _4 0 1 2 3r1 + 0 1 _ _ _ -: 0 1 2 3r1 _ ^ {. _ 1r1 +0 0 0 _ 1 0 0 0 -: __ _5 _4 0 1 2 3r1 _ ^ {. __ 1r1 + +0 -: _1r2 ^ {. _ 1r1 +0 -: 1r2 ^ {. _ 1r1 +_ -: 1r2 ^ {. __ 1r1 + +'domain error' -: _5r1 ^ etx {._ 1r1 +'domain error' -: __ 1r1 ^ etx {._ 1r1 +'domain error' -: _1r2 ^ etx {.__ 1r1 + + +4!:55 ;:'a exp f h pow rou s x y' + +
new file mode 100644 --- /dev/null +++ b/test/g200a.ijs @@ -0,0 +1,146 @@ +NB. B ^ B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x^y) -: (#.x,.y){1 0 1 1 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.?2 +(x^z) -: x^($x)$z [ z=.?2 + +(x^y) -: (40$"0 x)^y [ x=. ?10$2 [ y=. ?10 40$2 +(x^y) -: x^40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 0 1 1 -: 0 0 1 1 ^ 0 1 0 1 + + +NB. B ^ I --------------------------------------------------------------- + +x=. ?100$2 +y=. _1e5+?100$2e5 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.?2 +(x^z) -: x^($x)$z [ z=._1e5+?2e5 + +(x^y) -: (40$"0 x)^y [ x=. ?10$2 [ y=. _1e5+?10 40$2e5 +(x^y) -: x^40$"0 y [ x=. ?10 40$2 [ y=. _1e5+?10$2e5 + +_ 0 1 1 -: 0 0 1 1 ^ _4 3 4 _3 + + +NB. B ^ D --------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e5+?100$2e5 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.?2 +(x^z) -: x^($x)$z [ z=.o._1e5+?2e5 + +(x^y) -: (40$"0 x)^y [ x=. ?10$2 [ y=. o._1e5+?10 40$2e5 +(x^y) -: x^40$"0 y [ x=. ?10 40$2 [ y=. o._1e5+?10$2e5 + +_ 0 1 1 -: 0 0 1 1 ^ _2.5 1.2 _2.5 1.2 + + +NB. I ^ B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=._1e5+?2e5 +(x^z) -: x^($x)$z [ z=.?2 + +(x^y) -: (40$"0 x)^y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x^y) -: x^40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +1 0 1 1 1 _3 1 4 -: 0 0 1 1 _3 _3 4 4 ^ 0 1 0 1 0 1 0 1 +1 2147483647 1 _2147483648 -: 2147483647 2147483647 _2147483648 _2147483648 ^ 0 1 0 1 + + +NB. I ^ I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _10+?100$20 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.?2e6 +(x^z) -: x^($x)$z [ z=._1e5+?2e5 + +(x^y) -: (40$"0 x)^y [ x=. _1e5+?10 $2e5 [ y=. _10+?10 40$20 +(x^y) -: x^40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _10+?10 $20 + +1r9 0.25 1 6 49 -: 3 4 5 6 7 ^ _2 _1 0 1 2 +1 _5 1 6 -: _5 _5 6 6 ^ 0 1 0 1+4-4 +1 10 100 1000 1e4 1e5 1e6 1e7 1e8 1e9 -: 10^i.10 +1 _10 100 _1000 1e4 _1e5 1e6 _1e7 1e8 _1e9 -: _10^i.10 + + +NB. I ^ D --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. 1e_4*_1e5+?100$2e5 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.?2e6 +(x^z) -: x^($x)$z [ z=.1e_4*_1e5+?2e5 + +(x^y) -: (40$"0 x)^y [ x=. _1e5+?10 $2e5 [ y=. 1e_4*_1e5+?10 40$2e5 +(x^y) -: x^40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. 1e_4*_1e5+?10 $2e5 + +0j1 0 1 -: _1 0 1^0.5 +1.41421356237309504880 -: 2^0.5 +1.61803398874989482820 -: -:>:5^0.5 + + +NB. D ^ B --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. ?100$2 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.o._1e5+?2e5 +(x^z) -: x^($x)$z [ z=.?2 + +(x^y) -: (40$"0 x)^y [ x=. o._1e5+?10 $2e5 [ y=. ?10 40$2 +(x^y) -: x^40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. ?10 $2 + + 0.25 1 -: 0.25 ^ 1 0 +_0.25 1 -: _0.25 ^ 1 0 + + +NB. D ^ I --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. _10+?100$20 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.o._1e5+?2e5 +(x^z) -: x^($x)$z [ z=._10+?20 + +(x^y) -: (40$"0 x)^y [ x=. o._1e5+?10 $2e5 [ y=. _10+?10 40$20 +(x^y) -: x^40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. _10+?10 $20 + +4 2 1 0.5 0.25 -: 0.5 ^ _2 _1 0 1 2 +4 _2 1 _0.5 0.25 -: _0.5 ^ _2 _1 0 1 2 + + +NB. D ^ D --------------------------------------------------------------- + +x=. o._1e5+?100$2e5 +y=. 1e_4*_1e5+?100$2e5 +(x^y) -: (z+x)^z+y [ z=.{.0 4.5 +(x^y) -: (z*x)^z*y [ z=.{.1 4j5 +(z^y) -: (($y)$z)^y [ z=.1e_4*_1e5+?2e5 +(x^z) -: x^($x)$z [ z=.1e_4*_1e5+?2e5 + +(x^y) -: (40$"0 x)^y [ x=. o._1e5+?10 $2e5 [ y=. 1e_4*_1e5+?10 40$2e5 +(x^y) -: x^40$"0 y [ x=. o._1e5+?10 40$2e5 [ y=. 1e_4*_1e5+?10 $2e5 + +0j1.41421356237309504880 4 -: _2 0.5 ^ 0.5 _2 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g200i.ijs @@ -0,0 +1,27 @@ +NB. ^/ B --------------------------------------------------------------- + +1 0 1 1 -: ^/ 0 0 1 1 ,: 0 1 0 1 + +pow=: 4 : 'x^y' + +(^/"1 -: pow/"1) x=.?3 5 17$2 +(^/"2 -: pow/"2) x +(^/"3 -: pow/"3) x + +(^/"1 -: pow/"1) x=.?3 5 32$2 +(^/"2 -: pow/"2) x +(^/"3 -: pow/"3) x + +(^/"1 -: pow/"1) x=.?3 8 32$2 +(^/"2 -: pow/"2) x +(^/"3 -: pow/"3) x + +f=: 3 : '(^/ -: pow/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f pow x' + +
new file mode 100644 --- /dev/null +++ b/test/g200m.ijs @@ -0,0 +1,34 @@ +NB. m&|@^ --------------------------------------------------------------- + +f=: |`^/ +g=: 3 : 0 + 'm x y'=.y + x m&|@^ y +) + +(f -: g) 1e3 2 24 +(f -: g) 1e3 _2 24 +(f -: g) _1e3 2 24 +(f -: g) _1e3 _2 24 + +(f -: g) 1e3 2 0 +(f -: g) 1e3 _2 0 +(f -: g) _1e3 2 0 +(f -: g) _1e3 _2 0 + +(f -: g) 1e3 2 _5 +(f -: g) 1e3 _2 _5 +(f -: g) _1e3 2 _5 +(f -: g) _1e3 _2 _5 + +(f -: g) x: 1e6 2 500 +(f -: g) x: 1e6 _2 500 +(f -: g) x: _1e6 2 500 +(f -: g) x: _1e6 _2 500 + +1r4 -: 2 (1e6&|@^) _2x +125 625 1r25 -: 5 (1e6&|@^) 3 4 _2x + +4!:55 ;:'f g' + +
new file mode 100644 --- /dev/null +++ b/test/g200p.ijs @@ -0,0 +1,34 @@ +NB. ^/\ B --------------------------------------------------------------- + +(0 0 1 1,: 1 0 1 1) -: ^/\ 0 0 1 1 ,: 0 1 0 1 +(20$1) -: ^/\20$1 +(20$0 1) -: ^/\20$0 + +pow=. 4 : 'x^y' + +(^/\"1 -: pow/\"1) #:i.16 +(^/\"1 -: pow/\"1) #:i.32 + +(^/\ -: pow/\ ) x=.0=? 13$4 +(^/\ -: pow/\ ) x=.0=?7 13$4 +(^/\"1 -: pow/\"1) x +(^/\ -: pow/\ ) x=.0=?3 5 13$4 +(^/\"1 -: pow/\"1) x +(^/\"2 -: pow/\"2) x + +(^/\ -: pow/\ ) x=.0=? 16$4 +(^/\ -: pow/\ ) x=.0=?8 16$4 +(^/\"1 -: pow/\"1) x +(^/\ -: pow/\ ) x=.0=?2 4 16$4 +(^/\"1 -: pow/\"1) x +(^/\"2 -: pow/\"2) x + +(,'j') -: ^/\'j' +(,<'ace') -: ^/\<'ace' + +'domain error' -: ^/\ etx 'triskaidekaphobia' +'domain error' -: ^/\ etx ;:'ex cathedra' + +4!:55 ;:'pow x' + +
new file mode 100644 --- /dev/null +++ b/test/g201.ijs @@ -0,0 +1,40 @@ +NB. ^.y ----------------------------------------------------------------- + +log =. ^.@| j. 12&o. + +f =. ^. -: log + +f 3j4 3j_4 _3j4 _3j_4 +f %3j4 3j_4 _3j4 _3j_4 +f 0 +f 3 _3 0j4 0j_4 +f %3 _3 0j4 0j_4 + +__ 0 1 10 -: ^.0 1 2.71828182845904523536 22026.465794806717 + +1e_15 > | 0.69314718055994530941 - ^. 2 +1e_15 > | 1.09861228866810969139 - ^. 3 +1e_15 > | 2.30258509299404568401 - ^.10 + +'domain error' -: ^. etx 'abc' +'domain error' -: ^. etx <'abc' + + +NB. x^.y ---------------------------------------------------------------- + +(__ j. 0) -:&(3!:3) {. 10^. 0 _1 +(i.10) = x^."1] 1 , */\ 9#,:x=. 2+?15$20 + +'domain error' -: 3 ^. etx 'abc' +'domain error' -: 3 ^.~etx 'abc' +'domain error' -: 2 ^. etx 2;4 5 +'domain error' -: 2 ^.~etx 2;4 5 + +'length error' -: 2 3 ^. etx 4 5 6 +'length error' -: 2 3 ^.~etx 4 5 6 +'length error' -: 2 3 ^. etx i.4 5 +'length error' -: 2 3 ^.~etx i.4 5 + +4!:55 ;:'f log x' + +
new file mode 100644 --- /dev/null +++ b/test/g202.ijs @@ -0,0 +1,271 @@ +NB. ^: ------------------------------------------------------------------ + +f1 =: 3&+ +f2 =: + +g =: +:@[ + 3&*@] +x =: ?30 +y =: ?30 +n =: 3+?10 + +( f1^:n y) -: ".(;n$<'f1 '),' y' +(x f2^:n y) -: x&f2^:n y +( f1^:g y) -: f1^:(g y) y +(x f2^:g y) -: x&f2 ^: (x g y) y + +a=:t=: 911 +4!:55 ;:'t x y' +b=: 7!:0 '' +a=: 7!:0 '' + +x=: 1000?1e7 +y=: ;~^:5 x +t=: ;~;~;~;~;~x +t -: y +x=: 0 +t -: y + +4!:55 ;:'t x y' +b=: 7!:0 '' +a -: b + +x=: 1000?1e7 +y=: <^:5 x +t=: <<<<<x +t -: y +x=: 0 +t -: y + +4!:55 ;:'t x y' +b=: 7!:0 '' +a -: b + +f=: 3 : 0 + if. y do. + assert. 'limit error' -: (32 ?@$ 2)&~:^:] etx (4$32) ?@$ 2 + end. + 1 +) + +f -.IF64 + +234 0 0 0 -: 0"0^:(0 2 3 7) 234 +3j4 0 0 0 -: 0"0^:(0 2 3 7) 3j4 + +(o.^:(i.3 4)1) -: (o.1)^i.3 4 +(o.^:p 1) -: (o.1)^p=:_7+?4 5$15 + +(+/^:4 i. 2 3 4 5) -: +/,i.2 3 4 5 +(o.^:(6) 2) -: 2*(o.1)^6 + +f =: 2&- +g =: *&3 +(f f^:_1 x) -: x=:?100 +(f^:_1 f x) -: x +(g g^:_1 x) -: x=:?100 +(g^:_1 g x) -: x + +NB. applying f zero times when appropriate + +f=: >: [ ".@(('c=:>:c')&[) +x=: 20 ?@$ 0 +(f x) -: >:x [ c=: 0 +(c=>./,n) *. x -: f^:n x [ c=: 0 [ n=: 0 +(c=>./,n) *. (>:^:n x) -: f^:n x [ c=: 0 [ n=: 10 20 $ 0 +(c=>./,n) *. (>:^:n x) -: f^:n x [ c=: 0 [ n=: 10 20 ?@$ 5 + +x=: 1:`2:`3: +y=: 'asdf' +(x ,&<^:[ y) -: x ,&<^:(x[y) y + + +NB. ^: Newton's Method -------------------------------------------------- + +eps =: 1e_8&*@+ 0&= +Da =: 1 : '[ %~ + -&x ]' NB. secant slope adverb with absolute diff. +D =: 1 : 'eps x Da ]' NB. secant slope adverb with relative diff. +Nt =: 1 : '- x % x D' NB. one iteration of Newton's method + +*./ 1e_6 > | 3 - 3&* D 4 5 6 +*./ 1e_6 > | (2&^ D 4 5 6) - (^.2)*2^4 5 6 + +(%:2) -: 3 : '(y^2)-2' Nt^:_ x=:1 + + +NB. ^:_1 ---------------------------------------------------------------- + +ar =: 5!:1 +lr =: 5!:5 +inv =: 1 : 'x^:_1' +test =: 2 : '((x b._1)-:lr<''y'') *. (y b._1)-:lr<''x''' +f_g =: 2 : ('f=.y :.x f.'; '((x b._1)-:lr<''y'') +. (x b._1)-:lr<''f''') +eq =: 2 : '(ar<''x'') -: (ar<''y'')' +testx=: 2 : '(x b._1)-:lr<''y''' + +< test > +<: test >: ++ test + ++: test -: +- test - +-. test -. +*: test %: +% test % +%. test %. +^ test ^. +|. test |. +|: test |: +,: test {. +#. test #: +/: test /: +[ test [ +] test ] +{. test ,: +". test ": +C. test C. +p. test p. +*/ test q: + +({=) test (i."1&1) + +m&+ testx ((-m)&+) [ m=:o.?10000 +m&- testx (m&-) [ m=:^0j1*?1000 +-&m testx (m&+) [ m=:^0j1*?1000 +m&* testx ((%m)&*) [ m=:o.?10000 +m&% testx (m&%) [ m=:^0j1*?1000 +%&m testx (m&*) [ m=:^0j1*?1000 +m&o. testx ((-m)&o.) [ m=:o.?10000 +m&|. testx ((-m)&|.) [ m=:o.?10000 +m&^. testx (m&^) [ m=:o.?10000 +^.&m testx (%:&m) [ m=:o.?10000 +m&^ testx (m&^.) [ m=:o.?10000 +^&m testx (m&%:) [ m=:o.?10000 +m&%: testx (^&m) [ m=:o.?10000 +%:&m testx (^.&m) [ m=:o.?10000 +p&{ testx ((/:p)&{ ) [ p=:?~13 + +([: *: [: +: [: -: |. ) testx ([: |. [: +: [: -: %:) +([: *: [: +: [: -: [: |. ]) testx ([: |. [: +: [: -: %:) + +g=: 3!:2 +(lr <'g') -: 0&(3!:1) b. _1 +(lr <'g') -: 1&(3!:1) b. _1 +(lr <'g') -: 0&(3!:3) b. _1 +(lr <'g') -: 1&(3!:3) b. _1 + +i -: {&m ^:_1 (i=: ?3 2$#m) { m=:?5 3$1000 +(i{m) -: m&i.^:_1 (i=: ?3 2$#m) [ m=:?5 3$1000 + +([ -: m&#. inv @ (m&#. )) x=:1,?7$m [ m=:2+?7 +([ -: (4$m)&#:inv @ ((4$m)&#:)) x=: ?m^4 [ m=:2+?7 + +(-: f^:_1 @ f=:p:) x=:?5$100 +(-: f^:_1 @ f=:+.) x=:j./_50+?2 10$100 +(-: f^:_1 @ f=:*.) x=:j./_50+?2 10$100 + ++ /\ f_g (- |.!.0 ) ++ /\. f_g (- 1&(|.!.0)) +* /\ f_g (% |.!.1 ) +* /\. f_g (% 1&(|.!.1)) += /\ f_g (= |.!.1 ) += /\. f_g (= 1&(|.!.1)) +~:/\ f_g (~: |.!.0 ) +~:/\. f_g (~:1&(|.!.0)) +- /\ f_g ((-|.!.0) *"_1 $&1 _1@#) +- /\. f_g (+ 1&(|.!.0)) +% /\ f_g ((%|.!.1) ^"_1 $&1 _1@#) +% /\. f_g (* 1&(|.!.1)) + +NB. <;.1 f_g ; +NB. <;.2 f_g ; +10j2&": f_g ". + +x -: + /\ ^:_1 + /\ x=:>:?7 3$100 +x -: + /\.^:_1 + /\.x +x -: - /\ ^:_1 - /\ x +x -: - /\.^:_1 - /\.x +x -: * /\ ^:_1 * /\ x +x -: * /\.^:_1 * /\.x +x -: % /\ ^:_1 % /\ x +x -: % /\.^:_1 % /\.x + +y -: = /\ ^:_1 = /\ y=:?12 5$2 +y -: = /\.^:_1 = /\.y +y -: ~:/\ ^:_1 ~:/\ y +y -: ~:/\.^:_1 ~:/\.y + +f=: 3: * 12"_ + ] +x -: f f^:_1 x=:0.1*1+?2 10$100 +x -: f^:_1 f x + +f=: [: 2&* 10&^. +x -: f f^:_1 x=:0.1*1+?2 10$100 +x -: f^:_1 f x + +cap=: [: +f=: cap 2&* 10&^. +x -: f f^:_1 x=:0.1*1+?2 10$100 +x -: f^:_1 f x + +plus =: + +minus=: - +times=: * + +(12&+^:_1 -: 12&plus ^:_1) x=:?2 10$100 +(+&12^:_1 -: plus&12 ^:_1) x=:?2 10$100 + +(12&-^:_1 -: 12&minus^:_1) x=:?2 10$100 +(-&12^:_1 -: minus&12^:_1) x=:?2 10$100 + +(+~^:_1 -: plus ~^:_1) x=:?2 10$100 +(*~^:_1 -: times~^:_1) x=:?2 10$100 + +f_loc_ =: -: +fi_loc_ =: 3 : 'twice y' +twice_loc_ =: +: +g =: f_loc_ :. fi_loc_ + +f=: + :. * +12 -: 3 (f^:_1) 4 + +x -: g g^:_1 x=:?2 10$100 +x -: g^:_1 g x=:?2 10$100 + +m=: (_500+?1000),2^?20 +m&p. testx ((({:m)%~1,~-{.m)&p.) +'domain error' -: ex '5 0&p. ^:_1 ]17' + +b=: ? 100$2 +n=: +/b +Expand=: (* +/\)@[ { -@>:@#@] {. ] +(b&Expand -: b&#^:_1) x=: ?n$1000 +(b&Expand -: b&#^:_1) x=:a.{~?n$#a. +(b&Expand -: b&#^:_1) x=:y {~?n$#y=:;:'tris kai deka phobia finden tush' +(b&Expand -: b&#^:_1) x=: ?(n,5)$1000 +(b&Expand -: b&#^:_1) x=:a.{~?(n,5)$#a. +(b&Expand -: b&#^:_1) x=:y {~?(n,5)$#y=:;:'tris kai deka phobia finden tush' +(b&Expand -: b&#^:_1) x=: ?(n,2 5)$1000 +(b&Expand -: b&#^:_1) x=:a.{~?(n,2 5)$#a. +(b&Expand -: b&#^:_1) x=:y {~?(n,2 5)$#y=:;:'tris kai deka phobia finden tush' + +(2&+&.(b&#) y) -: b*2+y=:?((#b),5)$1000 + +'a a a' -: 1 0 1 0 0 1&#^:_1 'a' + +'length error' -: 1 0 1 0 0 1&#^:_1 etx 'ab' +'length error' -: 1 0 1 0 0 1&#^:_1 etx 'abcd' +'length error' -: 1 0 1 0 0 1&#^:_1 etx ,'a' + +'length error' -: 1 0 1 0 0 1&#^:_1 etx i.2 4 +'length error' -: 1 0 1 0 0 1&#^:_1 etx i.4 6 +'length error' -: 1 0 1 0 0 1&#^:_1 etx i.1 3 + +x -: ]&.( _2&|:) x=: ?2 3 4 5$1000 +x -: ]&.(_2 _3&|:) x + +18!:55 ;:'loc' + + +4!:55 ;:'a b c D Da Nt Expand ar cap eps eq f f1 f2 f_g ' +4!:55 ;:'g h hi i id inv lr m minus n p plus ' +4!:55 ;:'t test testx times x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g202b.ijs @@ -0,0 +1,102 @@ +NB. ^: with boxed right argument ---------------------------------------- + +(>: ^:(i.1000) 1 ) -: >: ^:(<1000) 1 +(>: ^:(i.1000) 1x ) -: >: ^:(<1000) 1x +(>:&.>^:(i.1000) <1 ) -: >:&.>^:(<1000) <1 + +(>: ^:(i. 0) 1 ) -: >: ^:(< 0) 1 +(>: ^:(i. 0) 1x ) -: >: ^:(< 0) 1x +(>:&.>^:(i. 0) <1 ) -: >:&.>^:(< 0) <1 + +(>: ^:(i.1000) 1 4 9 ) -: >: ^:(<1000) 1 4 9 +(>: ^:(i.1000) 1 4 9x) -: >: ^:(<1000) 1 4 9x +(>:&.>^:(i.1000) <1 4 9 ) -: >:&.>^:(<1000) <1 4 9 + +(>: ^:(i. 0) 1 4 9 ) -: >: ^:(< 0) 1 4 9 +(>: ^:(i. 0) 1 4 9x) -: >: ^:(< 0) 1 4 9x +(>:&.>^:(i. 0) <1 4 9 ) -: >:&.>^:(< 0) <1 4 9 + +f=: ^:a: +'^:a:' -: 5!:5 <'f' + +spleak=: 3 : 0 + x2288=: 7!:0 '' + y2288=: 7!:0 '' + x2288=: 7!:0 '' + ". y + y2288=: 7!:0 '' + assert. x2288 = y2288 + 1 +) + +spleak '>: ^:(<1000) 1x' +spleak '>:&.>^:(<1000) <1 ' + +'domain error' -: >:^:(<2.5) etx 1 +'domain error' -: >:^:(<2j5) etx 1 +'domain error' -: >:^:(<2r5) etx 1 + + +NB. {&x^:n with boxed n ------------------------------------------------- + +x=: (# ,~ # <. ]) (+ i.@#) 1+1000 ?@$ 10 + +indexlim=: 4 : 0 + s=. 1+t=. y + z=. ,:y + while. -.s-:t do. + z=. z, t=. t{x [ s=. t + end. + }: z +) + +({&x^:a: -: x&indexlim) 0 +({&x^:a: -: x&indexlim) 6 4 9 + +x ({~^:a: -: indexlim) 0 +x ({~^:a: -: indexlim) 6 4 9 + +spleak '{&x^:a: 0' +spleak '{&x^:a: 6 4 9' + +spleak 'x {~^:a: 0' +spleak 'x {~^:a: 6 4 9' + +NB. Each record of a file begins with a byte indicating the record length +NB. (excluding the record length byte itself), followed by the record contents. +NB. Given a file, the verb rec below produces the list of boxed records. + +rec=: 3 : 0 + n=. #y + d=. _1 ,~ n<.1+(i.n)+a.i.y + m=. {&d^:a: 0 + ((i.n) e. m) <;._1 y +) + +rec1=: 3 : 0 + n=. #y + d=. _1 ,~ n<.1+(i.n)+a.i.y + m=. d {~^:a: 0 + ((i.n) e. m) <;._1 y +) + +randomfile=: 3 : 0 + c =. 1+y ?@$ 255 NB. record lengths + rec=. {&a.&.> c ?@$&.> 256 NB. record contents + (c{a.),&.> rec NB. records with lengths +) + +test=: 3 : 0 + boxed_rec=: randomfile y + assert. r -: }.&.> boxed_rec [ r=: rec ; boxed_rec + assert. r -: }.&.> boxed_rec [ r=: rec1 ; boxed_rec + 1 +) + +test"0 ] 10^i.4 + + +4!:55 ;:'boxed_rec f indexlim r randomfile rec rec1 spleak' +4!:55 ;:'test x x2288 y2288' + +
new file mode 100644 --- /dev/null +++ b/test/g210.ijs @@ -0,0 +1,237 @@ +NB. $y ------------------------------------------------------------------ + +NB. Boolean +s -: $ s $ 0 1 [ s =. $0 +s -: $ s $ 0 1 [ s =. ,?20 +s -: $ s $ 0 1 [ s =. ?20 30 +s -: $ s $ 0 1 [ s =. ?(?7)$10 + +NB. literal +s -: $ s $ 'abc' [ s =. $0 +s -: $ s $ 'abc' [ s =. ,?20 +s -: $ s $ 'abc' [ s =. ?20 30 +s -: $ s $ 'abc' [ s =. ?(?7)$5 + +NB. integer +s -: $ s $ 4 0 [ s =. $0 +s -: $ s $ 4 0 [ s =. ,?20 +s -: $ s $ 4 0 [ s =. ?20 30 +s -: $ s $ 4 0 [ s =. ?(?7)$10 + +NB. floating point +s -: $ s $ o.4 2 [ s =. $0 +s -: $ s $ o.4 2 [ s =. ,?20 +s -: $ s $ o.4 2 [ s =. ?10 7 +s -: $ s $ o.4 2 [ s =. ?(?7)$5 + +NB. complex +s -: $ s $ ^0j1 4 [ s =. $0 +s -: $ s $ ^0j1 4 [ s =. ,?20 +s -: $ s $ ^0j1 4 [ s =. ?4 7 +s -: $ s $ ^0j1 4 [ s =. ?(?7)$5 + +NB. boxed +s -: $ s $ 0j1;'abc' [ s =. $0 +s -: $ s $ 0j1;'abc' [ s =. ,?20 +s -: $ s $ 0j1;'abc' [ s =. ?4 7 +s -: $ s $ 0j1;'abc' [ s =. ?(?7)$5 + +'' -: $ 0 +'' -: $ 'a' +'' -: $ 4 +'' -: $ _3.456 +'' -: $ 3j4 +'' -: $ <'Cogito' + +(,1) -: $ ,0 +(,1) -: $ ,'x' +(,1) -: $ ,_5 +(,1) -: $ ,3.4 +(,1) -: $ ,5j6.7 +(,1) -: $ ,<'ergo' + +(3!:0 ]10x) -: 3!:0 $ 10 20 30x +(3!:0 ]10x) -: 3!:0 $ 5 % 10 20 30x + + +NB. x$y ----------------------------------------------------------------- + +res =. (, }.@$) $ ,@] + +NB. Boolean +(4 5 res 0) -: 4 5$0 +(4 5 res b) -: 4 5$b=.1=?20$2 +(4 5 res 3 4$b) -: 4 5$3 4$b=.1=?20$2 +(4 5 0 res b) -: 4 5 0$b=.1=?20$2 +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +NB. literal +(4 5 res 'x') -: 4 5$'x' +(4 5 res b) -: 4 5$b=.a.{~?20$$a. +(4 5 res 3 4$b) -: 4 5$3 4$b=.a.{~?20$$a. +(4 5 0 res b) -: 4 5 0$b=.a.{~?20$$a. +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +NB. integer +(4 5 res 8) -: 4 5$8 +(4 5 res b) -: 4 5$b=.?20$12345 +(4 5 res 3 4$b) -: 4 5$3 4$b=.?20$12345 +(4 5 0 res b) -: 4 5 0$b=.?20$12345 +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +NB. floating point +(4 5 res 4.5) -: 4 5$4.5 +(4 5 res b) -: 4 5$b=.o.?20$12345 +(4 5 res 3 4$b) -: 4 5$3 4$b=.o.?20$12345 +(4 5 0 res b) -: 4 5 0$b=.o.?20$12345 +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +NB. complex +(4 5 res 4j5) -: 4 5$4j5 +(4 5 res b) -: 4 5$b=.^0j1*?20$12345 +(4 5 res 3 4$b) -: 4 5$3 4$b=.^0j1*?20$12345 +(4 5 0 res b) -: 4 5 0$b=.^0j1*?20$12345 +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +NB. boxed +(4 5 res <9) -: 4 5$<9 +(4 5 res b) -: 4 5$b=.;:'(4 5 res b) -: 4 5$b=.^0j1*?20$12345' +(4 5 res 3 4$b) -: 4 5$3 4$b +(4 5 0 res b) -: 4 5 0$b +(4 5 0 res 0 6$b) -: 4 5 0$0 6$b +(4 5 0 res 6 0 7$b) -: 4 5 0$6 0 7$b + +1 1 1 -: $1 1 1$123 +1 2 3 -: $((o.1 2 3)%o.1)$i.6 +1 2 3 -: $(-j.j.1 2 3)$'abc' + +0 0 0 0 0 0 -: 6$0 +0 1 1 0 0 1 -: 6$0 1 1 0 +0 1 0 0 1 1 -: 6$0 1 0 0 1 1 +0 1 0 0 1 1 -: 6$0 1 0 0 1 1 0 1 0 1 1 0 + +'eeeeee' -: 6$'e' +'eieiei' -: 6$'ei' +'eioeio' -: 6$'eio' +'romero' -: 6$'rome' +'lieb l' -: 6$'lieb ' +'lieber' -: 6$'lieber' +'Weltan' -: 6$'Weltanschauung' + +0 1 2 3 0 1 -: 6$i.4 +0 1 2 3 4 5 -: 6$i.6 +0 1 2 3 4 5 -: 6$i.12 + +3.4 3.4 3.4 3.4 -: 4$3.4 +3.4 0 1 3.4 -: 4$3.4 0 1 +3.4 0 1 2 -: 4$3.4,i.12 + +3j4 3j4 3j4 3j4 -: 4$3j4 +3j4 0 1 3j4 -: 4$3j4 0 1 +3j4 0 1 2 -: 4$3j4,i.12 + +(1 2;1 2;1 2) -: 3$<1 2 +(1 2;'a';1 2) -: 3$1 2;'a' +(1 2;'a';3.4) -: 3$1 2;'a';3.4;<"0 i.7 + +f=: 4 : '(x$y) -: (x$i.#y){y' " 0 _ + +( i.11) f&>/ (>:i.10)$&.>(0=?10$4){a. +(200+i.11) f&>/ (>:i.10)$&.>(0=?10$4){a. +( i.11) f&>/ (>:i.10)$&.>0{a. +(200+i.11) f&>/ (>:i.10)$&.>0{a. +( i.11) f&>/ (>:i.10)$&.>1{a. +(200+i.11) f&>/ (>:i.10)$&.>1{a. + +(200+i.11) f 16}.(3!:1) _ +(200+i.11) f |. 16}.(3!:1) _ +(200+i.11) f 16}.(3!:1) __ +(200+i.11) f |. 16}.(3!:1) __ +(200+i.11) f 16}.(3!:1) _. +(200+i.11) f |. 16}.(3!:1) _. +(200+i.11) f 16}.(3!:1) o.1 +(200+i.11) f |. 16}.(3!:1) o.1 + +'domain error' -: 'abc'$ etx 'abc' +'domain error' -: 3.5 $ etx 'abc' +'domain error' -: 3j4 $ etx 'abc' +'domain error' -: (<5) $ etx 'abc' +'domain error' -: _3 $ etx 'abc' + +'length error' -: 3 4 $ etx '' +'length error' -: 3 4 $ etx i.0 1 2 + + +NB. x$"r y -------------------------------------------------------------- + +f =. 4 : 'x$y' " 1 _ + +2 3 4 (f"1 -: $"1) ?2 3 4$2 +2 3 4 (f"1 -: $"1) a.{~?2 3 4$256 +2 3 4 (f"1 -: $"1) ?2 3 4$1000 +2 3 4 (f"1 -: $"1) o.?2 3 4$1000 +2 3 4 (f"1 -: $"1) r./?2 2 3 4$1000 +2 3 4 (f"1 -: $"1) 2 3 4$;:'Cogito, ergo sum. sui generis' + +2 3 4 (f"2 -: $"2) ?2 3 4$2 +2 3 4 (f"2 -: $"2) a.{~?2 3 4$256 +2 3 4 (f"2 -: $"2) ?2 3 4$1000 +2 3 4 (f"2 -: $"2) o.?2 3 4$1000 +2 3 4 (f"2 -: $"2) r./?2 2 3 4$1000 +2 3 4 (f"2 -: $"2) 2 3 4$;:'When eras die their thoughts are left to strange police' + +2 (f"2 -: $"2) ?7 3 4$2 +2 (f"2 -: $"2) a.{~?7 3 4$256 +2 (f"2 -: $"2) ?7 3 4$1000 +2 (f"2 -: $"2) o.?7 3 4$1000 +2 (f"2 -: $"2) r./?2 7 3 4$1000 +2 (f"2 -: $"2) 7 3 4$;:'salt of the earth boustrophedonic bull of Bashan' + +1e6 2 3 4 5 0 1e4 -: $ 2 3 4 5 0 $"1 2 i.1e6 0 1e4 +1e6 2 3 4 5 0 0 -: $ 2 3 4 5 0 $"1 2 i.1e6 1e4 0 + + +NB. x$!.f y ------------------------------------------------------------- + +(2 3 4$2 3 4 5, 20$0 ) -: 2 3 4$!.'' 2 3 4 5 +(2 3 4$'chthonic',16$' ') -: 2 3 4$!.'' 'chthonic' +(2 3 4$t, 20$<$0) -: 2 3 4$!.'' t=.;:'Cogito, ergo sum.' + +(2 15$0 1 0,27$1 ) -: 2 15$!.1 [ 0 1 0 +(2 15$1 2 3,27$1 ) -: 2 15$!.1 [ 1 2 3 +(2 15$1.2 3,28$1 ) -: 2 15$!.1 [ 1.2 3 +(2 15$1 2j3,28$1 ) -: 2 15$!.1 [ 1 2j3 + +(2 15$0 1 0,27$_1 ) -: 2 15$!._1 [ 0 1 0 +(2 15$1 2 3,27$_1 ) -: 2 15$!._1 [ 1 2 3 +(2 15$1.2 3,28$_1 ) -: 2 15$!._1 [ 1.2 3 +(2 15$1 2j3,28$_1 ) -: 2 15$!._1 [ 1 2j3 + +(2 15$0 1 0,27$3.5) -: 2 15$!.3.5 [ 0 1 0 +(2 15$1 2 3,27$3.5) -: 2 15$!.3.5 [ 1 2 3 +(2 15$1.2 3,28$3.5) -: 2 15$!.3.5 [ 1.2 3 +(2 15$1 2j3,28$3.5) -: 2 15$!.3.5 [ 1 2j3 + +(2 15$0 1 0,27$3j5) -: 2 15$!.3j5 [ 0 1 0 +(2 15$1 2 3,27$3j5) -: 2 15$!.3j5 [ 1 2 3 +(2 15$1.2 3,28$3j5) -: 2 15$!.3j5 [ 1.2 3 +(2 15$1 2j3,28$3j5) -: 2 15$!.3j5 [ 1 2j3 + +((i.4),"0 1 [4$8) -: 5$!.8"0 i.4 +(4 5$8) -: 5$!.8"1 i.4 0 + +'domain error' -: 9 3 $!.'a' etx 4 +'domain error' -: 9 3 $!.'a' etx 'b';'c';'d' +'domain error' -: 9 3 $!.4 etx 'sui generis' +'domain error' -: 9 3 $!.4 etx ;:'Cogito, ergo sum.' +'domain error' -: 9 3 $!.(<4) etx 'eleemosynary' +'domain error' -: 9 3 $!.(<4) etx i.2 3 + +4!:55 ;:'b f res s t' + +
new file mode 100644 --- /dev/null +++ b/test/g210a.ijs @@ -0,0 +1,201 @@ +NB. $ shape overflow ---------------------------------------------------- + +NB. Some tests fail because memory is obtained in 65536 word increments, +NB. and malloc does not always fail gracefully. +NB. Other tests fail because they try to grab the entire result array +NB. at the outset, and fail with a limit error or an out of memory. + +test =: 1 : '<@(x etx) e. (''out of memory'';''limit error'')"_' + +m =: <. 2^IF64{16 32 +m2 =: <. m%2 +m4 =: <. m%4 + + +NB. 32 bit specific shape overflow tests -------------------------------- + +3 : 0 '' + if. IF64 do. 1 return. end. + + assert. (32768$'a') ="0 _ test 65536$'a' + assert. (65536$'a') ="0 _ test 65536$'a' + + assert. > test (i.65536);65536$<1 + assert. > test (i.65536);65535$<1 + assert. > test (i.65536);32768$<1 + assert. > test (i.65536);32767$<1 + assert. > test (i.65536);16384$<1 + assert. > test (i.65536);16383$<1 + assert. > test (i.65536); 8192$<1 + assert. > test (i.65536); 8191$<1 + assert. > test (i.32768);65536$<1 + assert. > test (i.32768);65535$<1 + assert. > test (i.32768);32768$<1 + assert. > test (i.32768);32767$<1 + assert. > test (i.32768);16384$<1 + assert. > test (i.32768);16383$<1 + + assert. (i.16384) >."0 _ test i.16384 + assert. (i.16384) >."0 _ test i.32768 + assert. (i.16384) >."0 _ test i.32 1024 + assert. (i.32768) >."0 _ test i.32768 + assert. (i.32768) >."0 _ test i.65536 + assert. (i.65536) >."0 _ test i.65536 + assert. (i.32767) >."0 _ test i.65536 + assert. (i.32767) >."0 _ test i.16$2 + + f=: 4 : 'x>.y' + assert. (i.32768) f "0 _ test i.65536 + assert. (i.65536) f "0 _ test i.65536 + + assert. 32768 65536 $ test 'a' + assert. 8192 65536 $ test 4 + assert. 4096 65536 $ test 4.8 + assert. 2048 65536 $ test 4j8 + assert. 65536 32768 $ test 'a' + assert. 16384 32768 $ test 4 + assert. 8192 32768 $ test 4.8 + assert. 4096 32768 $ test 4j8 + + assert. (i.65536 1) +/ .* test i.1 65536 + assert. (i.65536 1) +/ .* test i.1 65535 + assert. (i.65536 1) +/ .* test i.1 32768 + assert. (i.65536 1) +/ .* test i.1 32767 + assert. (i.65536 1) +/ .* test i.1 16384 + assert. (i.65536 1) +/ .* test i.1 16383 + assert. (i.65536 1) +/ .* test i.1 8192 + + assert. (65536$'a') ,"0 1 test 65536$'b' + assert. (65536$'a') ,"0 1 test 32768$'b' + + assert. [;.1 test (32767$'x'),65536{.'x' + assert. [;.1 test (32768$'x'),65536{.'x' + assert. [;.1 test (65535$'x'),65536{.'x' + assert. [;.1 test (65536$'x'),65536{.'x' + + assert. 65536 # test 65536$'a' + assert. 65536 # test 65535$'a' + assert. 65536 # test 32768$'a' + assert. 65536 # test 32767$'a' + assert. 65536 123# test 2 65536$'a' + assert. 65536 123# test 2 65535$'a' + assert. 65536 123# test 2 32768$'a' + assert. 65536 123# test 2 32767$'a' + + assert. (i.65536) ["1 test 65536 1$'a' + assert. (i.65536) ["1 test 32768 1$'a' + assert. (i.65536) ["1 test 16384 1$'a' + assert. (i.65536) ["1 test 8192 1$'a' + + assert. (<(65536 ?@$ 2); 65536 ?@$ 3){ test 2 3$'abcdef' + assert. (<(32768 ?@$ 2); 65536 ?@$ 3){ test 2 3$'abcdef' + assert. (<(16384 ?@$ 2); 65536 ?@$ 3){ test 2 3$'abcdef' + assert. (65650 ?@$ 2){ test 2 32767$'abc' + assert. (65650 ?@$ 2){ test 2 32768$'abc' + assert. (65650 ?@$ 2){ test 2 32769$'abc' + assert. (65650 ?@$ 2){ test 2 65535$'abc' + assert. (65650 ?@$ 2){ test 2 65536$'abc' + assert. (65650 ?@$ 2){ test 2 65537$'abc' + assert. (65536 ?@$ 2){ test 2 65536$'abc' + assert. (32768 ?@$ 2){ test 2 65536$'abc' + + assert. 65536 65536 {. test 65536 4$'a' + assert. 65535 65536 {. test 65535 4$'a' + assert. 32768 65536 {. test 32768 4$'a' + assert. 65536 {."1 test 65536 2$'a' + assert. 65536 {."1 test 65535 2$'a' + assert. 65536 {."1 test 32768 2$'a' + + assert. (16384 2$'a') i."1 _ test 16384 2$'a' + assert. (16384 2$'a') i."1 _ test 32768 2$'a' + assert. (32768 2$'a') i."1 _ test 32768 2$'a' + assert. (32768 2$'a') i."1 _ test 65536 2$'a' + assert. (65536 2$'a') i."1 _ test 65536 2$'a' + assert. (32767 2$'a') i."1 _ test 65536 2$'a' + + assert. 'limit error' -: ; etx ;~i.(2^30),0 + assert. 'limit error' -: ,~ etx i.(2^30),0 + 1 +) + + +NB. general shape overflow tests ---------------------------------------- + +<"2 test i.m, m ,0 2 +<"2 test i.m,(m -1),0 2 +<"2 test i.m, m2 ,0 2 +<"2 test i.m,(m2-1),0 2 +<"2 test i.m, m4 ,0 2 +<"2 test i.m,(m4-1),0 2 +<"2 test i.m,(m%8) ,0 2 + +(0 $~ m,m ,0) +/ .* test 0 1$0 +(0 $~ m,m2,0) +/ .* test 0 1$0 +(1 0$0) +/ .* test 0 $~ 0,m,m +(1 0$0) +/ .* test 0 $~ 0,m,m2 + +('a' $~ m,m ,0) ,"1 test 'b' +('a' $~ m,m2,0) ,"1 test 'b' + +#"2 test ((16 $~ IF64{ 8 16),0 2)$'a' +#"2 test (( 2 $~ IF64{31 63),0 2)$'a' + +/:"2 test i.m,32768 0 +/:"2 test i.m,32767 0 +/:"2 test i.m,16384 0 +/:"2 test i.m,16383 0 +/:"2 test i.m, 8192 0 +/:"2 test i.256 256, m2 ,0 +/:"2 test i.256 256,(m2-1),0 +/:"2 test i.256 256, m4 ,0 +/:"2 test i.256 256,(m%8) ,0 + +(-: ]"2) i.m ,m ,0 2 +(-: ]"2) i.m ,m2,0 2 +(-: ]"2) i.m ,m4,0 2 +(-: ]"2) i.m2,m ,0 2 +(-: ]"2) i.m4,m ,0 2 + +(i.m,0) ]"1 test 65536$'a' +(i.m,0) ]"1 test 32768$'a' + +( -2^IF64{31 63) {. test i. 4 0 +( -2^IF64{31 63) {. test i. 3 4 0 +(2 3,-2^IF64{31 63) {. test i.2 3 4 0 + +i.@2:"1 test i. (2^IF64{30 62),0 + +f=: 3 : '<y' +f"2 test i.m, m ,0 2 +f"2 test i.m,(m -1),0 2 +f"2 test i.m, m2 ,0 2 +f"2 test i.m,(m2-1),0 2 +f"2 test i.m, m4 ,0 2 +f"2 test i.m,(m4-1),0 2 +f"2 test i.m,(m%8) ,0 2 + +f=: 4 : 'x>.y' +17 f"0 1 test i.m,m ,0 +17 f"0 1 test i.m,m2,0 +(i.m,m ,0) f"1 0 test 17 +(i.m,m2,0) f"1 0 test 17 + +": test <i. m ,m ,0 +": test <i. m ,m2,0 +": test <i. m ,m4,0 +": test <i. m2,m ,0 +": test <i.(3$<.2^IF64{12 22),1 0 + +": test (i.0,m-3);i.(m -2),0 +": test (i.0,m-3);i.(m2-2),0 + +": test <(0,imax)$0 +": test ((0,<.imax%2)$0);(0,>.imax%2)$0 +": test (i. 1 0);i. 0,<.imax%3 +": test (i. 2 0);i. 0,<.imax%4 +": test (i. 3 0);i. 0,<.imax%5 + + +4!:55 ;:'f m m2 m4 test' + +
new file mode 100644 --- /dev/null +++ b/test/g211.ijs @@ -0,0 +1,349 @@ +NB. $.y ----------------------------------------------------------------- + +f=: 3 : 0 + (scheck s), y -: $.^:_1 s=: $. y +) + +f x=: ? 13$2 +f x=: ? 11 13$2 +f x=: ?4 11 13$2 +f x=: 4 11 13$0 + +f x=: ? 13$20 +f x=: ? 11 13$20 +f x=: ?4 11 13$20 +f x=: 4 11 13$2-2 + +f x=:o. ? 13$20 +f x=:o. ? 11 13$20 +f x=: 4 11 13$o.0 + +f x=:j./?2 13 $10 +f x=:j./?2 11 13 $10 +f x=:j./?2 11 13 4$10 +f x=: 2 11 13 4$-~1j2 + +f=: 4 : 0 + (scheck s), y -: $.^:_1 s=: (2;x)$. y +) + +d=: 11 3 5 7 2$0 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +c f&> <($d)$0 +c f&> <($d)$2-2 +c f&> <($d)$o.0 +c f&> <($d)$-~0j1 + +1024 -: type $. 10$1 +4096 -: type $. 10$2 +8192 -: type $. 10$2.7 +16384 -: type $. 10$2j7 + +'domain error' -: $. etx 2 37x +'domain error' -: $. etx 2 3r7 + +'nonce error' -: $. etx 3 4$'a' +'nonce error' -: $. etx <"0 i.2 3 + + +NB. x$.y ---------------------------------------------------------------- + +ieq=: 2 : ('yi=. y b. _1'; '(5!:5 <''x'') -: y b. _1') + +$.^:_1 ieq $. +1&$. ieq (_1&$.) +2&$. ieq (_2&$.) +3&$. ieq (_3&$.) +4&$. ieq (_4&$.) +5&$. ieq (_5&$.) +6&$. ieq (_6&$.) +7&$. ieq (_7&$.) +_1&$. ieq ( 1&$.) +_2&$. ieq ( 2&$.) +_3&$. ieq ( 3&$.) +_4&$. ieq ( 4&$.) +_5&$. ieq ( 5&$.) +_6&$. ieq ( 6&$.) +_7&$. ieq ( 7&$.) +_8&$. ieq ( 8&$.) + +'domain error' -: 'a' $. etx 3 4 5 +'domain error' -: 3.5 $. etx 3 4 5 +'domain error' -: 3j5 $. etx 3 4 5 +'domain error' -: 3r5 $. etx 3 4 5 +'domain error' -: 1234 $. etx 1 $. 8 9 +'domain error' -: _999 $. etx 1 $. 8 9 + +'rank error' -: 1 2 $. etx 3 4 5 +'rank error' -: (<3) $. etx 3 4 5 + +'length error' -: (3;1;4) $. etx 3.4 5 + + +NB. 1$.y ---------------------------------------------------------------- + +perm=: i.@! A. i. + +scheck@(1&$.)"(1) 3 5 7 11;"1 ,/(perm 1){"(2 1) 1 comb 4 +scheck@(1&$.)"(1) 3 5 7 11;"1 ,/(perm 2){"(2 1) 2 comb 4 +scheck@(1&$.)"(1) 3 5 7 11;"1 ,/(perm 3){"(2 1) 3 comb 4 +scheck@(1&$.)"(1) 3 5 7 11;"1 ,/(perm 4){"(2 1) 4 comb 4 + +'domain error' -: 1$. etx 'abc' +'domain error' -: 1$. etx 'abc';0 1;0 +'domain error' -: 1$. etx (<2 3 4);0 1;0 +'domain error' -: 1$. etx (>IF64{3e9 4;3e19 4);0 1;0 +'domain error' -: 1$. etx 2 3 4;0 1;2x +'domain error' -: 1$. etx 2 3 4;0 1;2r3 + +'length error' -: 1$. etx 2 3 4;0 1;0;99 + +'rank error' -: 1$. etx 2 3$2 3 4;0 1;0 +'rank error' -: 1$. etx (i.2 3);0 1;0 +'rank error' -: 1$. etx 2 3 4 5 6;(i.2 2);0 +'rank error' -: 1$. etx 2 3 4;0 1;0 1 +'rank error' -: 1$. etx 2 3 4;0 1;'' + +'index error' -: 1$. etx 2 3 4;0 0;0 +'index error' -: 1$. etx 2 3 4;0 3;0 +'index error' -: 1$. etx 2 3 4;2 _1;0 +'index error' -: 1$. etx 2 3 4;_4;0 +'index error' -: 1$. etx 2 3 4;0 0;0 + +'nonce error' -: 1$. etx 2 3 4;0 1;' ' +'nonce error' -: 1$. etx 2 3 4;0 1;<a: + + +NB. 2$.y ---------------------------------------------------------------- + +x=: ?5 6$10 +y=: $. x +(i.#$x) -: 2 $.y + +(/:~a) -: 2 $. 1 $. 2 3 4 5 6;a=:3?5 + +scheck (2;2 0) $. $. x=: ? 3 5 7$1000 +scheck (2;'' ) $. $. x + +f=: 4 : 'd -: $.^:_1 (2;x)$.(2;y)$.d' + +d=: ?5 4 1 3 2$3 +c=: ; (i.1+r) <"1@comb&.> r=:#$d +] b=: f&>/~c + +d=: ?7 4 6 5 1 2 3$3 +r=: #$d +g=: >:@?@(r"_) ? r"_ +f&g~"0 i.5 10 + +d -: (2;_1 )&$.&.$. d +d -: (2;_1 _2)&$.&.$. d + +a=: ?. 8 5 6 4 2$3 +b=: $. a +c=: (2;0 )$.a +d=: (2;0 1 )$.a +e=: (2;0 1 2)$.a + +(7$.b) = (2 2;i.5)$.a +(7$.b) = (2 2;i.5)$.c +(7$.b) = (2 2;i.5)$.d +(7$.b) = (2 2;i.5)$.e +(7$.c) = (2 2;0 )$.a +(7$.c) = (2 2;0 )$.b +(7$.c) = (2 2;0 )$.d +(7$.c) = (2 2;0 )$.e +(7$.d) = (2 2;0 1)$.a +(7$.d) = (2 2;0 1)$.b +(7$.d) = (2 2;0 1)$.c +(7$.d) = (2 2;0 1)$.e +(7$.e) = (2 2;i.3)$.a +(7$.e) = (2 2;i.3)$.b +(7$.e) = (2 2;i.3)$.c +(7$.e) = (2 2;i.3)$.d + +'domain error' -: 2 $.etx 0 1 2x +'domain error' -: 2 $.etx 0 1r2 + +'domain error' -: (2;'ab') $. etx $. i.2 3 +'domain error' -: (2;<<2 ) $. etx $. i.2 3 + +'rank error' -: (2;1 1$0)$. etx $. i.2 3 + +'index error' -: (2;0 ) $. etx 9 +'index error' -: (2;0 3 ) $. etx i.2 3 4 +'index error' -: (2;0 3 ) $. etx $. i.2 3 4 +'index error' -: (2;0 0 ) $. etx i.2 3 4 +'index error' -: (2;0 0 ) $. etx $. i.2 3 4 +'index error' -: (2;_1 2) $. etx i.2 3 4 +'index error' -: (2;_1 2) $. etx $. i.2 3 4 + + +NB. 3$.y ---------------------------------------------------------------- + +x=: ?5 6$10 +y=: $. x +0 -: 3 $.y + +1 -: type 3 $. $. 10$1 +4 -: type 3 $. $. 10$2 +8 -: type 3 $. $. 10$2.7 +16 -: type 3 $. $. 10$2j7 + +(type@(3&$.) -: type@(5&$.)) $. 10$1 +(type@(3&$.) -: type@(5&$.)) $. 10$2 +(type@(3&$.) -: type@(5&$.)) $. 10$2.7 +(type@(3&$.) -: type@(5&$.)) $. 10$2j7 + +(scheck x), 1024 -: type x=:(3;1 ) $. $. 1 1 0 +(scheck x), 4096 -: type x=:(3;4 ) $. $. 1 1 0 +(scheck x), 8192 -: type x=:(3;4.5) $. $. 1 1 0 +(scheck x), 16384 -: type x=:(3;4j5) $. $. 1 1 0 + +(scheck x), 4096 -: type x=:(3;1 ) $. $. 1 2 0 +(scheck x), 4096 -: type x=:(3;4 ) $. $. 1 2 0 +(scheck x), 8192 -: type x=:(3;4.5) $. $. 1 2 0 +(scheck x), 16384 -: type x=:(3;4j5) $. $. 1 2 0 + +(scheck x), 8192 -: type x=:(3;1 ) $. $. 1.2 0 +(scheck x), 8192 -: type x=:(3;4 ) $. $. 1.2 0 +(scheck x), 8192 -: type x=:(3;4.5) $. $. 1.2 0 +(scheck x), 16384 -: type x=:(3;4j5) $. $. 1.2 0 + +(scheck x), 16384 -: type x=:(3;1 ) $. $. 1j2 0 +(scheck x), 16384 -: type x=:(3;4 ) $. $. 1j2 0 +(scheck x), 16384 -: type x=:(3;4.5) $. $. 1j2 0 +(scheck x), 16384 -: type x=:(3;4j5) $. $. 1j2 0 + +'domain error' -: 3 $.etx 0 1 +'domain error' -: 3 $.etx 'abc' +'domain error' -: 3 $.etx 0 1 2 +'domain error' -: 3 $.etx 0 1.2 +'domain error' -: 3 $.etx 0 1j2 +'domain error' -: 3 $.etx 0 1 2x +'domain error' -: 3 $.etx 0 1r2 +'domain error' -: 3 $.etx 0 1;2 + +'domain error' -: (3;'a') $. etx $. i.2 3 +'domain error' -: (3;4x ) $. etx $. i.2 3 +'domain error' -: (3;4r5) $. etx $. i.2 3 +'domain error' -: (3;<<1) $. etx $. i.2 3 + +'rank error' -: (1 3$3;1) $. etx $. i.2 3 +'rank error' -: (3;,2) $. etx $. i.2 3 +'rank error' -: (3;'') $. etx $. i.2 3 + +'length error' -: (3;1;2) $. etx $. i.2 3 + + +NB. 4$.y ---------------------------------------------------------------- + +f=: 3 : 0 + yy=. $. y + i=. 4$.yy + assert. (#i) -: #5$.yy + assert. ({:$i) = #2$.yy + assert. 4 -: type i + assert. 2 -: #$i + assert. *./, (0<:i)*.i<"1 $yy + 1 +) + +f ?3 4 5$2 +f ?3 4 5$20 +f o._10+?3 24$20 +f j./o._10+?2 34$20 + +f=: $ #: I.@, +g=: 4 $. $. +(f -: g) x=: 97 101 ?@$ 2 +(f -: g) x=: 97 101 2 ?@$ 2 +(f -: g) x=: 97 101 3 ?@$ 2 + +'domain error' -: 4 $.etx 0 1 +'domain error' -: 4 $.etx 'abc' +'domain error' -: 4 $.etx 0 1 2 +'domain error' -: 4 $.etx 0 1.2 +'domain error' -: 4 $.etx 0 1j2 +'domain error' -: 4 $.etx 0 1 2x +'domain error' -: 4 $.etx 0 1r2 +'domain error' -: 4 $.etx 0 1;2 + + +NB. 5$.y ---------------------------------------------------------------- + +f=: 3 : 0 + yy=. $. y + x =. 5$.yy + assert. (type x) -: type y + assert. (type x) -: type 3$.yy + assert. (#x) -: # 4$.yy + assert. (}.$x) -: (-.(i.#$yy)e.2$.yy)#$yy + 1 +) + +f ?3 4 5$2 +f ?3 4 5$20 +f o.?3 45$20 +f j./o.?2 45$20 + +'domain error' -: 5 $.etx 0 1 +'domain error' -: 5 $.etx 'abc' +'domain error' -: 5 $.etx 0 1 2 +'domain error' -: 5 $.etx 0 1.2 +'domain error' -: 5 $.etx 0 1j2 +'domain error' -: 5 $.etx 0 1 2x +'domain error' -: 5 $.etx 0 1r2 +'domain error' -: 5 $.etx 0 1;2 + + +NB. 7$.y ---------------------------------------------------------------- + +x=: ?5 6$10 +y=: $. x +n=: 7 $. y +n -: +/ ,0~:x +n -: #@(4&$.) y +n -: #@(5&$.) y + + +NB. 8$.y ---------------------------------------------------------------- + +f=: 3 : '(*./ scheck s) *. (m*d) -: s=: 8 $. m * (2;y)$.d' + +d=: ?5 4 6 3 2$3 +m=: ?5 4 6 $2 +c=: ; (i.1+r) <"1@comb&.> r=:#$d +f&> c + +g=: 3 : '(*./ scheck s) *. (110+m*d) -: s=: 8 $. 110 + m * (2;y)$.d' +g&> c + +h=: 3 : '(*./ scheck s) *. (3.4+m*d) -: s=: 8 $. 3.4 + m * (2;y)$.d' +h&> c + + +NB. $.y large integers in shape ----------------------------------------- + +n=: IF64 { 2e9 9e18 +scheck x=: 1 $. n +n = # x +(,n) -: $x +i=: 1000 ?@$ #x +d=: 1000 ?@$ 0 +scheck x=: d i}x +(+/x) -: +/d +(,. /:~ ~. i) -: 4 $. x +b=: (i.#i)=i:~i +d=: (b#d)/:b#i +i=: /:~b#i +d -: 5 $. x + +scheck |.x +(|.d) -: 5 $. |.x +(,.(n-1)-|.i) -: 4 $. |. x + +4!:55 ;:'a b c d e f g h i ieq m n perm r s x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g212.ijs @@ -0,0 +1,15 @@ +NB. $: ------------------------------------------------------------------ + +(!i.10) -: 1:`(* $:@<:)@.*"0 i.10 +12 -: 2&$: : * 6 +(^5) -: 12 ^ : $:@- 7 + +f=: 0&$: : (4 : 'x+y') + +x -: f x=: _50+?2 3 4$100 +x -: f x=: j./_50+?2 3 4$100 +(x+y) -: x f y=: j./_50+2 3 4$100 + +4!:55 ;:'f x y' + +
new file mode 100644 --- /dev/null +++ b/test/g220.ijs @@ -0,0 +1,33 @@ +NB. ~ ------------------------------------------------------------------- + +3 -: 2 -~ 5 +2.5 -: 2 %~ 5 + +(x=:?2 3 4$1000) (-~ -: ] - [) y=:?2 3$1000 +(x=:?2 3 4$1000) (%~ -: ] % [) y=:?2 3$1000 + +(+:t) -: +~t=:_50+?2 3 4$100 +(*:t) -: *~t=:o._50+?2 3 4$100 + +mean=: +/ % # +(mean x) -: 'mean'~ x=: ?100$1000 + +'value error' -: ex '''asdf''~ x' + +'domain error' -: ex '0 0 1~ x' +'domain error' -: ex '1 2 3~ x' +'domain error' -: ex '1 2.3~ x' +'domain error' -: ex '1 2j3~ x' +'domain error' -: ex '1 23x~ x' +'domain error' -: ex '1 2r3~ x' +'domain error' -: ex '(<''mean'')~ x' + +'ill-formed name' -: ex ' ''a___''~ 12' +'ill-formed name' -: ex ' ''a_gosh!_''~ 12' +'ill-formed name' -: ex '''a_gosh*@!_''~ 12' +'ill-formed name' -: ex ' ''do_gosh!_''~ 12' + + +4!:55 ;:'mean t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g220t.ijs @@ -0,0 +1,29 @@ +NB. ~ timing tests ------------------------------------------------------ + +ratio =: >./ % <./ + +test0=: 3 : 0 + xx=: 1e5?@$1e6 + t=: i. 0 2 + t=:t,10 timer '3+ xx',:'3+~xx' + t=:t,10 timer '3- xx',:'3-~xx' + t=:t,10 timer '3* xx',:'3*~xx' + t=:t,10 timer '3% xx',:'3%~xx' + t=:t,10 timer 'xx+xx',:'+~xx' + t=:t,10 timer 'xx*xx',:'*~xx' + 5 > ratio"1 t +) + +test1=: 3 : 0 + i=: ?10 + yy=: 24000 10?@$1e6 + 5 > ratio t=: 100 timer 'i{"1 yy',:'yy{~"1 i' +) + +test0 '' +test1 '' + + +4!:55 ;:'i ratio t test0 test1 xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g221.ijs @@ -0,0 +1,57 @@ +NB. ~.y ----------------------------------------------------------------- + +(,b)-:~.b=.0 +(,b)-:~.b=.'a' +(,b)-:~.b=.243 +(,b)-:~.b=.2.71828 +(,b)-:~.b=.3j4.54e2 +(,b)-:~.b=.<i.12 + +b-:~.b=.1 0 +b-:~.b=.1 3 4$a. +b-:~.b=.i.1 2 3 4 +b-:~.b=.o.i.1 2 3 +b-:~.b=.^0j1*i.1 0 3 +b-:~.b=.1 3 2$;:'Cogito, ergo sum.' + +b-:~.b=.0$0 +b-:~.b=.0 3 4$a. +b-:~.b=.i.0 2 3 4 +b-:~.b=.o.i.0 2 3 +b-:~.b=.^0j1*i.0 2 0 3 +b-:~.b=.0 3 2$;:'Cogito, ergo sum.' + +(1{.b)-:~.b=.5#1 +(1{.b)-:~.b=.5#1 3 4$a. +(1{.b)-:~.b=.5#i.1 2 3 4 +(1{.b)-:~.b=.5#o.i.1 2 3 +(1{.b)-:~.b=.5#^0j1*i.1 0 3 +(1{.b)-:~.b=.5#1 3 2$;:'Cogito, ergo sum.' + +test=: 3 : 0 + yy=: y + xx=: ~. yy + assert. xx -:&(#@$ ) yy + assert. xx -:&(}.@$) yy + assert. xx <:&# yy + assert. (#xx) > >./xx i. yy + assert. (i.~xx) -: i.#xx + 1 +) + +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 0 1 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 'abcde' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$2e9 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: o.?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: j./?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: ;:' miasma chthonic chronic kakistocracy dado' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: x: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: %/0 1+x:?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: u: ?5$65536 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: s:' miasma chthonic chronic kakistocracy dado' + + +4!:55 ;:'b t test xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g222.ijs @@ -0,0 +1,193 @@ +NB. ~:y ----------------------------------------------------------------- + +(,1) -: ~:0 +(,1) -: ~:'a' +(,1) -: ~:243 +(,1) -: ~:2.71828 +(,1) -: ~:3j4.54e2 +(,1) -: ~:<i.12 + +(,1) -: ~:,1 +(,1) -: ~:1 3 4$a. +(,1) -: ~:i.1 2 3 4 +(,1) -: ~:o.i.1 2 3 +(,1) -: ~:r.i.1 0 3 +(,1) -: ~:1 3 2$;:'Cogito, ergo sum.' + +'' -: ~:0$0 +'' -: ~:0 3 4$a. +'' -: ~:i.0 2 3 4 +'' -: ~:o.i.0 2 3 +'' -: ~:^0j1*i.0 2 0 3 +'' -: ~:0 3 2$;:'Cogito, ergo sum.' + +(5{.1) -: ~:5#1 +(5{.1) -: ~:5#1 3 4$a. +(5{.1) -: ~:5#i.1 2 3 4 +(5{.1) -: ~:5#o.i.1 2 3 +(5{.1) -: ~:5#^0j1*i.1 0 3 +(5{.1) -: ~:5#1 3 2$;:'Cogito, ergo sum.' + +test =: 3 : '(1=type b), (($b)-:,#y), b-:(i.#y)=i.~y [ b=.~:y' + +test ?2 +test a.{~?#a. +test ?2023 +test o.?2023 +test j./?2$3324 +test ('foo';'upon';'thee'){~?3 + +test ?20 2$2 +test a.{~50+?40 2$3 +test ?20 2$3 +test o.?20 2$3 +test j./?2 82 2$3 +test ('foo';'upon';'thee'){~?20 2$3 + +test=: 3 : 0 + yy=: y + b=: ~: yy + assert. 1=type b + assert. 1=#$b + assert. b -:&# yy + assert. b -: (i.@# = i.~) yy + assert. (b#yy) -: ~.yy + 1 +) + +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 0 1 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 'abcde' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: _10+?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$2e9 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: o.?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: j./?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: ;:' miasma chthonic chronic kakistocracy dado' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: x: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: %/0 1+x:?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: u: ?5$65536 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: s:' miasma chthonic chronic kakistocracy dado' + +test=: 3 : 0 + yy=: y + b=: ~:"_1 yy + assert. 1=type b + assert. (<:#$yy)=#$b + assert. (1{$b) = 1{$yy + assert. b -: (i.@# = i.~)"_1 yy + assert. ((<"1 b)#&.><"_1 yy) -: <@~."_1 yy + 1 +) + +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 0 1 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 'abcde' +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: _10+?5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$2e9 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: o.?5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: j./?2 5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: ;:' miasma chthonic chronic kakistocracy dado' +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: x: ?5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: %/0 1+x:?2 5$20 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: u: ?5$65536 +test@:(t"_ {~ 3 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: s:' miasma chthonic chronic kakistocracy dado' + + +NB. ~:"r y -------------------------------------------------------------- + +g =: 3 : '~:y' + +(g"0 -: ~:"0 ) y=:?2 3 4 5$2 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:'ab'{~?2 3 4 5$2 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:?2 3 4 5$3 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:o.?5 4 3 2$2 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:r.?5 4 3 2$2 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:(?5 4 3 2$#x){x=:;:'kakistocracy piscatory sequipedalian' +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y +(g"0 -: ~:"0 ) y=:?0 0 0 0$0 +(g"1 -: ~:"1 ) y +(g"2 -: ~:"2 ) y +(g"3 -: ~:"3 ) y +(g"4 -: ~:"4 ) y +(g"_1 -: ~:"_1) y + +(,:~:y) -: ~:!.0"1 ,: <"1 y=: 13 97 ?@$ 1e6 + + +NB. x~:y ---------------------------------------------------------------- + +NB. Boolean +0 1 1 0 -: 0 0 1 1~:0 1 0 1 + +NB. literal +(($t)$0) -: t ~: t=:a.{~?2 3 4$#a. +(($t)$1) -: (?($t)$2) ~: t=:a.{~?2 3 4$#a. +(($t)$1) -: (_5e8+?($t)$1e9) ~: t=:a.{~?2 3 4$#a. +(($t)$1) -: (o._5e8+?($t)$1e9) ~: t=:a.{~?2 3 4$#a. +(($t)$1) -: (r._5e7+?($t)$1e8) ~: t=:a.{~?2 3 4$#a. +(($t)$1) -: (($t)$;:'8-+.abc') ~: t=:a.{~?2 3 4$#a. + +NB. integer +(($t)$0) -: t ~: t=:_1e9+?2 3 4$2e9 +(a~:b)-:0~:a-b [ a=:_5+?200$10 [ b=:_5+?200$10 +(a~:b)-:a~:b{0 1 2 [ a=:(?100$2){0 1 2 [ b=:?100$2 +(a~:b)-:a~:}.3.4,b [ a=:?200$10 [ b=:?200$10 + +NB. real +(($t)$0) -: t ~: t=:o._1e9+?2 3 4$2e9 +(a~:b)-:0~:a-b [ a=:o._5+?200$10 [ b=:o._5+?200$10 +(a~:b)-:a~:}.3.4,b [ a=:}.3.4,?100$2 [ b=:?100$2 +(a~:b)-:a~:}.3.4,b [ a=:}.3.4,_5+?200$10 [ b=:_5+?200$10 +(a~:b)-:a~:}.3j4,b [ a=:o._5+?200$10 [ b=:o._5+?200$10 + +NB. complex +(($t)$0) -: t ~: t=:j./_1e9+?2 3 4$2e9 +(a~:b)-:0~:a-b [ a=:r._5+?200$10 [ b=:r._5+?200$10 +(a~:b)-:a~:}.3j4,b [ a=:}.3j4,?100$2 [ b=:?100$2 +(a~:b)-:a~:}.3j4,b [ a=:}.3j4,_5+?200$10 [ b=:_5+?200$10 +(a~:b)-:a~:}.3j4,b [ a=:}.3j4,o._5+?200$10 [ b=:o._5+?200$10 + +NB. boxed +(($t)$0) -: t ~: t=:<"1?2 3 4 5$10 +(($t)$1) -: (?($t)$2) ~: t=:<"1?2 3 4$10 +(($t)$1) -: (($t)$'8-+.abc') ~: t=:<"1?2 3 4$10 +(($t)$1) -: (_5e8+?($t)$1e9) ~: t=:<"1?2 3 4$10 +(($t)$1) -: (o._5e8+?($t)$1e9) ~: t=:<"1?2 3 4$10 +(($t)$1) -: (r._5e7+?($t)$1e8) ~: t=:<"1?2 3 4$10 + +'length error' -: 1 2 ~: etx 'abc' +'length error' -: 1 2 ~: etx i. 3 4 5 + + +4!:55 ;:'a b g t test x y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g222a.ijs @@ -0,0 +1,141 @@ +NB. B ~: B -------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x~:y) -: (#.x,.y){0 1 1 0 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.?2 +(x~:z) -: x~:($x)$z [ z=.?2 + +(x~:y) -: (40$"0 x)~:y [ x=. ?10$2 [ y=. ?10 40$2 +(x~:y) -: x~:40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 1 0 -: 0 0 1 1 ~: 0 1 0 1 + + +NB. B ~: I -------------------------------------------------------------- + +x=. ?100$2 +y=. _1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.?2 +(x~:z) -: x~:($x)$z [ z=._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. ?10$2 [ y=. _1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. ?10 40$2 [ y=. _1e2+?10$2e2 + +0 1 1 0 1 1 1 1 -: 0 0 1 1 0 0 1 1 ~: 0 1 0 1 _4 3 4 _3 + + +NB. B ~: D -------------------------------------------------------------- + +x=. ?100$2 +y=. o._1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.?2 +(x~:z) -: x~:($x)$z [ z=.o._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. ?10$2 [ y=. o._1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. ?10 40$2 [ y=. o._1e2+?10$2e2 + +0 1 1 0 1 1 1 1 -: 0 0 1 1 0 0 1 1 ~: 0 1 0 1 _2.5 1.2 _2.5 1.2 +0 1 1 0 1 1 1 1 -: 0 0 1 1 0 0 1 1 ~: 0 1 0 1 __ _ __ _ +(14 6#1 0) -: 1~:1+10^-i.20 + + +NB. I ~: B -------------------------------------------------------------- + +x=. _1e2+?100$2e2 +y=. ?100$2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=._1e2+?2e2 +(x~:z) -: x~:($x)$z [ z=.?2 + +(x~:y) -: (40$"0 x)~:y [ x=. _1e2+?10$2e2 [ y=. ?10 40$2 +(x~:y) -: x~:40$"0 y [ x=. _1e2+?10 40$2e2 [ y=. ?10$2 + +0 1 1 0 1 1 1 1 -: 0 0 1 1 _3 _3 4 4 ~: 0 1 0 1 0 1 0 1 +1 1 1 1 -: 2147483647 2147483647 _2147483648 _2147483648 ~: 0 1 0 1 + + +NB. I ~: I -------------------------------------------------------------- + +x=. _1e2+?100$2e2 +y=. _1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.?2e6 +(x~:z) -: x~:($x)$z [ z=._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. _1e2+?10$2e2 [ y=. _1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. _1e2+?10 40$2e2 [ y=. _1e2+?10$2e2 + +(9 1#1 0) -: 9~:i.10 + + +NB. I ~: D -------------------------------------------------------------- + +x=. _1e2+?100$2e2 +y=. o._1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.?2e6 +(x~:z) -: x~:($x)$z [ z=.o._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. _1e2+?10$2e2 [ y=. o._1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. _1e2+?10 40$2e2 [ y=. o._1e2+?10$2e2 + +(14 6#1 0) -: 17~:17*1+10^-i.20 + + +NB. D ~: B -------------------------------------------------------------- + +x=. o._1e2+?100$2e2 +y=. ?100$2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.o._1e2+?2e2 +(x~:z) -: x~:($x)$z [ z=.?2 + +(x~:y) -: (40$"0 x)~:y [ x=. o._1e2+?10$2e2 [ y=. ?10 40$2 +(x~:y) -: x~:40$"0 y [ x=. o._1e2+?10 40$2e2 [ y=. ?10$2 + +(14 6#1 0) -: (1+10^-i.20)~:1 + + +NB. D ~: I -------------------------------------------------------------- + +x=. o._1e2+?100$2e2 +y=. _1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.o._1e2+?2e2 +(x~:z) -: x~:($x)$z [ z=._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. o._1e2+?10$2e2 [ y=. _1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. o._1e2+?10 40$2e2 [ y=. _1e2+?10$2e2 + +(14 6#1 0) -: (17*1+10^-i.20)~:17 + + +NB. D ~: D -------------------------------------------------------------- + +x=. o._1e2+?100$2e2 +y=. o._1e2+?100$2e2 +(x~:y) -: (z+x)~:z+y [ z=.{.0 4.5 +(x~:y) -: (z*x)~:z*y [ z=.{.1 4j5 +(z~:y) -: (($y)$z)~:y [ z=.o._1e2+?2e2 +(x~:z) -: x~:($x)$z [ z=.o._1e2+?2e2 + +(x~:y) -: (40$"0 x)~:y [ x=. o._1e2+?10$2e2 [ y=. o._1e2+?10 40$2e2 +(x~:y) -: x~:40$"0 y [ x=. o._1e2+?10 40$2e2 [ y=. o._1e2+?10$2e2 + +(14 6#1 0) -: _17.4~:_17.4*1+10^-i.20 + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g222i.ijs @@ -0,0 +1,46 @@ +NB. ~:/ B --------------------------------------------------------------- + +0 1 1 0 -: ~:/ 0 0 1 1 ,: 0 1 0 1 + +ne=: 4 : 'x~:y' + +(~:/"1 -: ne/"1) x=.1=?3 5 17$13 +(~:/"2 -: ne/"2) x +(~:/"3 -: ne/"3) x + +(~:/"1 -: ne/"1) x=.1=?3 5 32$13 +(~:/"2 -: ne/"2) x +(~:/"3 -: ne/"3) x + +(~:/"1 -: ne/"1) x=.1=?3 8 32$13 +(~:/"2 -: ne/"2) x +(~:/"3 -: ne/"3) x + +f=. 3 : '(~:/ -: ne/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +(ne/"1 -: ~:/"1) #: i.2^6 +(ne/"1 -: ~:/"1) #: i.2^7 +(ne/"1 -: ~:/"1) #: i.2^8 +(ne/"1 -: ~:/"1) #: i.2^9 + +(ne/ -: ~:/ ) |: #: i.2^6 +(ne/ -: ~:/ ) |: #: i.2^7 +(ne/ -: ~:/ ) |: #: i.2^8 +(ne/ -: ~:/ ) |: #: i.2^9 + +(ne/"1 -: ~:/"1) 0 ,"1 #: i.2^6 +(ne/"1 -: ~:/"1) 0 0 ,"1 #: i.2^6 +(ne/"1 -: ~:/"1) 0 0 0,"1 #: i.2^6 + +(ne/ -: ~:/ ) |: 0 ,"1 #: i.2^6 +(ne/ -: ~:/ ) |: 0 0 ,"1 #: i.2^6 +(ne/ -: ~:/ ) |: 0 0 0,"1 #: i.2^6 + + +4!:55 ;:'f ne x' + +
new file mode 100644 --- /dev/null +++ b/test/g222p.ijs @@ -0,0 +1,91 @@ +NB. ~:/\ B --------------------------------------------------------------- + +(0 0 1 1,:0 1 1 0) -: ~:/\ 0 0 1 1 ,: 0 1 0 1 +(20$1 0) -: ~:/\20$1 +(20$0 ) -: ~:/\20$0 + +ne=: 4 : 'x~:y' +nescan=: 2&|@(+/\) + +(~:/\ -: ne/\ ) x=.? 13$2 +(~:/\ -: ne/\ ) x=.?4 13$2 +(~:/\"1 -: ne/\"1) x +(~:/\ -: ne/\ ) x=.?3 5 13$2 +(~:/\"1 -: ne/\"1) x +(~:/\"2 -: ne/\"2) x + +(~:/\ -: nescan ) x=.? 32$2 +(~:/\ -: nescan ) x=.?4 32$2 +(~:/\"1 -: nescan"1) x +(~:/\ -: nescan ) x=.?4 8 32$2 +(~:/\"1 -: nescan"1) x +(~:/\"2 -: nescan"2) x + +(~:/\ -: nescan ) x=.? 23$2 +(~:/\ -: nescan ) x=.?5 23$2 +(~:/\"1 -: nescan"1) x +(~:/\ -: nescan ) x=.?5 7 23$2 +(~:/\"1 -: nescan"1) x +(~:/\"2 -: nescan"2) x + +f=. 3 : '(~:/\ -: nescan) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. ~:/\ I --------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\ -: ne/\) x=.1 2 3 1e9 2e9 +(~:/\ -: ne/\) |.x + +(~:/\ -: ne/\ ) x=._1e4+? 13$2e4 +(~:/\ -: ne/\ ) x=._1e4+?4 13$2e4 +(~:/\"1 -: ne/\"1) x +(~:/\ -: ne/\ ) x=._1e4+?3 5 13$2e4 +(~:/\"1 -: ne/\"1) x +(~:/\"2 -: ne/\"2) x + +(~:/\ -: ne/\ ) x=._1e9+? 13$2e9 +(~:/\ -: ne/\ ) x=._1e9+?4 13$2e9 +(~:/\"1 -: ne/\"1) x +(~:/\ -: ne/\ ) x=._1e9+?3 5 13$2e9 +(~:/\"1 -: ne/\"1) x +(~:/\"2 -: ne/\"2) x + + +NB. ~:/\ D --------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\ -: ne/\ ) x=.0.01*_1e4+? 13$2e4 +(~:/\ -: ne/\ ) x=.0.01*_1e4+?4 13$2e4 +(~:/\"1 -: ne/\"1) x +(~:/\ -: ne/\ ) x=.0.01*_1e4+?3 5 13$2e4 +(~:/\"1 -: ne/\"1) x +(~:/\"2 -: ne/\"2) x + + +NB. ~:/\ Z -------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\ -: ne/\ ) x=.[&.j. 0.1*_1e2+?2 13$2e2 +(~:/\ -: ne/\ ) x=.[&.j. 0.1*_1e2+?2 4 13$2e2 +(~:/\"1 -: ne/\"1) x +(~:/\ -: ne/\ ) x=.[&.j. 0.1*_1e2+?2 3 5 13$2e2 +(~:/\"1 -: ne/\"1) x +(~:/\"2 -: ne/\"2) x + +(,'j') -: ~:/\'j' +(,<'ace') -: ~:/\<'ace' + +'domain error' -: ~:/\ etx 'deipnosophist' +'domain error' -: ~:/\ etx ;:'peace in our time' + +4!:55 ;:'f ne nescan x' + +
new file mode 100644 --- /dev/null +++ b/test/g222s.ijs @@ -0,0 +1,64 @@ +NB. ~:/\. B ------------------------------------------------------------- + +(0 1 1 0,:0 1 0 1) -: ~:/\. 0 0 1 1 ,: 0 1 0 1 + +ne=: 4 : 'x~:y' + +f=. 3 : '(~:/\. -: ne/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + + +NB. ~:/\. I ------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\. -: ne/\.) x=.1 2 3 1e9 2e9 +(~:/\. -: ne/\.) |.x + +(~:/\. -: ne/\. ) x=._1e4+? 23$2e4 +(~:/\. -: ne/\. ) x=._1e4+?4 23$2e4 +(~:/\."1 -: ne/\."1) x +(~:/\. -: ne/\. ) x=._1e4+?7 5 23$2e4 +(~:/\."1 -: ne/\."1) x +(~:/\."2 -: ne/\."2) x + +(~:/\. -: ne/\. ) x=._1e9+? 23$2e9 +(~:/\. -: ne/\. ) x=._1e9+?4 23$2e9 +(~:/\."1 -: ne/\."1) x +(~:/\. -: ne/\. ) x=._1e9+?7 5 23$2e9 +(~:/\."1 -: ne/\."1) x +(~:/\."2 -: ne/\."2) x + + +NB. ~:/\. D ------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\. -: ne/\. ) x=.0.01*_1e4+? 23$2e4 +(~:/\. -: ne/\. ) x=.0.01*_1e4+?4 23$2e4 +(~:/\."1 -: ne/\."1) x +(~:/\. -: ne/\. ) x=.0.01*_1e4+?7 5 23$2e4 +(~:/\."1 -: ne/\."1) x +(~:/\."2 -: ne/\."2) x + + +NB. ~:/\. Z ------------------------------------------------------------- + +ne=: 4 : 'x~:y' + +(~:/\. -: ne/\. ) x=.r. 0.1*_1e2+?2 23$2e2 +(~:/\. -: ne/\. ) x=.r. 0.1*_1e2+?2 4 23$2e2 +(~:/\."1 -: ne/\."1) x +(~:/\. -: ne/\. ) x=.r. 0.1*_1e2+?2 7 5 23$2e2 +(~:/\."1 -: ne/\."1) x +(~:/\."2 -: ne/\."2) x + +'domain error' -: ~:/\. etx 'deipnosophist' +'domain error' -: ~:/\. etx ;:'professors in New England' + +4!:55 ;:'f ne x' + +
new file mode 100644 --- /dev/null +++ b/test/g230.ijs @@ -0,0 +1,71 @@ +NB. |y ------------------------------------------------------------------ + +complex =: 16&=@(3!:0) +mag =: (>.-)`(%:@*+)@.complex +f =: | -: mag + +NB. Boolean +0 1 -: | 0 1 +t -: | t=:1=?2 3 4 5$2 +f 1=?2 3 4$2 + +NB. integer +f _1e5+?25 2 2 2$2e5 +3 2 1 0 1 2 3 -: | _3 _2 _1 0 1 2 3 +0 = 2147483648 - | _2147483648 +0 = 2147483647 - | _2147483647 +4 = 3!:0 |_2147483647 + +NB. floating point +f o._1e5+?2 3 4 5$2e5 + +NB. complex +f r._1e5+?2 3 4$2e5 +f j./_1e5+?2 3 4$2e5 +5 5 5 5 -: |3j4 3j_4 _3j4 _3j_4 + +'domain error' -: | etx 'abc' +'domain error' -: | etx 3;4 + + +NB. x|y ----------------------------------------------------------------- + +test =: 3 : (':'; 'r=.x|y'; '*./,((*r)e.0,*x)*.(0=x)+.(|r)<|x') + +NB. Boolean +(2 2$0 1 0 0) -: |/~0 1 + +NB. integer +(_50+?200$100) test _50+?200$100 +(13$0 1 2) -: 3|_6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 +(13$0 _2 _1) -: _3|_6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 +t -: 0|t=:_25+?400$50 + +NB. floating point +( _50+?200$100) test o._50+?200$100 +(o._50+?200$100) test _50+?200$100 +(o._50+?200$100) test o._50+?200$100 + +t = _ | t=: 1+10 ?@$ 1e6 +_ = _ | - t +(-t)= __ | - t +__ = __ | t + +x=: j./ _50 + 2 10000 ?@$ 100 +y=: j./ _500 + 2 10000 ?@$ 1000 +*./ (0=x) +. (|x) > |x|y +x=: j./ _500 + 2 10000 ?@$ 1000 +y=: j./ _5000 + 2 10000 ?@$ 10000 +*./ (0=x) +. (|x) > |x|y + +'domain error' -: 'abc' | etx 1 2 3 +'domain error' -: 'abc' | etx 'feg' +'domain error' -: 'abc' | etx 0;1;2 + +'domain error' -: (2;3) | etx 2 3 +'domain error' -: (2;3) | etx 'eg' +'domain error' -: (2;3) | etx 4;5 + +4!:55 ;:'complex f mag t test x y' + +
new file mode 100644 --- /dev/null +++ b/test/g230a.ijs @@ -0,0 +1,62 @@ +NB. B | B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x|y) -: (#.x,.y){0 1 0 0 +(x|y) -: (z+x)|z+y [ z=.{.0 4.5 +(z|y) -: (($y)$z)|y [ z=.?2 +(x|z) -: x|($x)$z [ z=.?2 + +(x|y) -: (40$"0 x)|y [ x=. ?10$2 [ y=. ?10 40$2 +(x|y) -: x|40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +0 1 0 0 -: 0 0 1 1 | 0 1 0 1 + + +NB. B | I --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2e5 +(x|y) -: (z+x)|z+y [ z=.{.0 4.5 +(z|y) -: (($y)$z)|y [ z=.?2 +(x|z) -: x|($x)$z [ z=.?2e5 + +(x|y) -: (40$"0 x)|y [ x=. ?10$2 [ y=. +?10 40$2e5 +(x|y) -: x|40$"0 y [ x=. ?10 40$2 [ y=. +?10$2e5 + +0 1 0 0 -: 0 0 1 1 | 0 1 0 1+4-4 + + +NB. I | B --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. ?100$2 +(x|y) -: (z+x)|z+y [ z=.{.0 4.5 +(z|y) -: (($y)$z)|y [ z=._1e5+?2e5 +(x|z) -: x|($x)$z [ z=.?2 + +(x|y) -: (40$"0 x)|y [ x=. _1e5+?10$2e5 [ y=. ?10 40$2 +(x|y) -: x|40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. ?10$2 + +0 1 0 0 -: (0 0 1 1+3-3) | 0 1 0 1 + + +NB. I | I --------------------------------------------------------------- + +x=. _1e5+?100$2e5 +y=. _1e5+?100$2e5 +(x|y) -: (z+x)|z+y [ z=.{.0 4.5 +(z|y) -: (($y)$z)|y [ z=._1e5+?2e5 +(x|z) -: x|($x)$z [ z=._1e5+?2e5 + +(x|y) -: (40$"0 x)|y [ x=. _1e5+?10$2e5 [ y=. _1e5+?10 40$2e5 +(x|y) -: x|40$"0 y [ x=. _1e5+?10 40$2e5 [ y=. _1e5+?10$2e5 + +0 1 0 0 -: (0 0 1 1+3-3) | 0 1 0 1+3-3 + +'domain error' -: 1 | etx 'chthonic' +'domain error' -: 0 0 | etx ;:'sui generis' + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g230i.ijs @@ -0,0 +1,27 @@ +NB. |/ B --------------------------------------------------------------- + +0 1 0 0 -: |/ 0 0 1 1 ,: 0 1 0 1 + +res=: 4 : 'x|y' + +(|/"1 -: res/"1) x=.?3 5 17$2 +(|/"2 -: res/"2) x +(|/"3 -: res/"3) x + +(|/"1 -: res/"1) x=.?3 5 32$2 +(|/"2 -: res/"2) x +(|/"3 -: res/"3) x + +(|/"1 -: res/"1) x=.?3 8 32$2 +(|/"2 -: res/"2) x +(|/"3 -: res/"3) x + +f=: 3 : '(|/ -: res/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f res x' + +
new file mode 100644 --- /dev/null +++ b/test/g230p.ijs @@ -0,0 +1,34 @@ +NB. |/\ B --------------------------------------------------------------- + +(0 0 1 1,: 0 1 0 0) -: |/\ 0 0 1 1 ,: 0 1 0 1 +(20{.1) -: |/\20$1 +(20$ 0) -: |/\20$0 + +res=. 4 : 'x|y' + +(|/\"1 -: res/\"1) #:i.16 +(|/\"1 -: res/\"1) #:i.32 + +(|/\ -: res/\ ) x=.1=? 13$4 +(|/\ -: res/\ ) x=.1=?7 13$4 +(|/\"1 -: res/\"1) x +(|/\ -: res/\ ) x=.1=?3 5 13$4 +(|/\"1 -: res/\"1) x +(|/\"2 -: res/\"2) x + +(|/\ -: res/\ ) x=.1=? 16$4 +(|/\ -: res/\ ) x=.1=?8 16$4 +(|/\"1 -: res/\"1) x +(|/\ -: res/\ ) x=.1=?2 4 16$4 +(|/\"1 -: res/\"1) x +(|/\"2 -: res/\"2) x + +(,'j') -: |/\'j' +(,<'ace') -: |/\<'ace' + +'domain error' -: |/\ etx 'deipnosophist' +'domain error' -: |/\ etx ;:'guard the glory that was Greece' + +4!:55 ;:'res x' + +
new file mode 100644 --- /dev/null +++ b/test/g230s.ijs @@ -0,0 +1,18 @@ +NB. |/\. B ------------------------------------------------------------- + +(0 1 0 0,:0 1 0 1) -: |/\. 0 0 1 1 ,: 0 1 0 1 + +rem=: 4 : 'x|y' + +f=: 3 : '(|/\. -: rem/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +'domain error' -: |/\. etx 'deipnosophist' +'domain error' -: |/\. etx ;:'professors in New England' + +4!:55 ;:'f rem x' + +
new file mode 100644 --- /dev/null +++ b/test/g231.ijs @@ -0,0 +1,253 @@ +NB. |.y ----------------------------------------------------------------- + +rev =: ]`((<:-i.)@# { ]) @. (*@#@$) + +NB. Boolean +(|. -: rev) 1=?50 2 3$2 +(|. -: rev) 1=?1 100$2 +(|. -: rev) 1=?100 0$2 +(|. -: rev) 1 + +NB. literal +(|. -: rev) (?45 1 2 2$#a){a=.'foo upon thee 1=?10 20$2' +(|. -: rev) (?400 1 1$#a){a +(|. -: rev) (?0 10 2$#a){a +(|. -: rev) 'a' +(|. -: rev) '' + +NB. integer +(|. -: rev) ?25 2 2 2$212341 +(|. -: rev) ?400 1$123541 +(|. -: rev) ?0 1000$123456 +(|. -: rev) _4 +(|. -: rev) i.0 + +NB. floating point +(|. -: rev) o.?35 3 5$212341 +(|. -: rev) o.?1 40$123541 +(|. -: rev) o.?100 0$123456 +(|. -: rev) 3.4 +(|. -: rev) ,_3.4 + +NB. complex +(|. -: rev) ^0j1*?30 2 5$21234 +(|. -: rev) ^0j1*?1 256$1235 +(|. -: rev) ^0j1*?127 0$1234 +(|. -: rev) 3j4 +(|. -: rev) 0$3j4 + +NB. boxed +(|. -: rev) (?30 2 1 1 1$#x){x=.;:'Cogito, ergo sum. $212 341 CBC News' +(|. -: rev) (?255 1$#x){x +(|. -: rev) (?0 0$#x){x +(|. -: rev) <i.2 3 +(|. -: rev) ,<i.2 3 + +(|. -: rev) x=.a.{~?50 1$#a. +(|. -: rev) x=.a.{~?50 2$#a. +(|. -: rev) x=.a.{~?50 3$#a. +(|. -: rev) x=.a.{~?50 4$#a. +(|. -: rev) x=.a.{~?50 5$#a. +(|. -: rev) x=.a.{~?50 6$#a. +(|. -: rev) x=.a.{~?50 7$#a. +(|. -: rev) x=.a.{~?50 8$#a. +(|. -: rev) x=.a.{~?50 9$#a. +(|. -: rev) x=.a.{~?50 10$#a. +(|. -: rev) x=.a.{~?50 11$#a. +(|. -: rev) x=.a.{~?50 12$#a. + + +NB. |."r y -------------------------------------------------------------- + +f =: 3 : '|.y' + +(|."0 -: f"0) ?2 3 4$1e6 +(|."1 -: f"1) a.{~?2 3 4$#a. +(|."2 -: f"2) o.?2 3 5$1e6 +(|."3 -: f"3) ?2 3 4$2e5 + +(|."2 -: rev"2) x=.a.{~?4 12 1$#a. +(|."2 -: rev"2) x=.a.{~?4 12 2$#a. +(|."2 -: rev"2) x=.a.{~?4 12 3$#a. +(|."2 -: rev"2) x=.a.{~?4 12 4$#a. +(|."2 -: rev"2) x=.a.{~?4 12 5$#a. +(|."2 -: rev"2) x=.a.{~?4 12 6$#a. +(|."2 -: rev"2) x=.a.{~?4 12 7$#a. +(|."2 -: rev"2) x=.a.{~?4 12 8$#a. +(|."2 -: rev"2) x=.a.{~?4 12 9$#a. +(|."2 -: rev"2) x=.a.{~?4 12 10$#a. +(|."2 -: rev"2) x=.a.{~?4 12 11$#a. +(|."2 -: rev"2) x=.a.{~?4 12 12$#a. + + +NB. x|.y ---------------------------------------------------------------- + +rank =: #@$ +rot =: ]`(((i.@]-]-|~)#){])@.(*@rank@])"0 _ + +NB. Boolean +(_50+?100) (|. -: rot) 1=?50 2 3$2 +(_50+?100) (|. -: rot) 1=?1 100$2 +(_50+?100) (|. -: rot) 1=?100 0$2 +(_50+?100) (|. -: rot) 1 + +NB. literal +(_50+?100) (|. -: rot) (?45 1 2 2$#a){a=.'foo upon thee 1=?10 20$2' +(_50+?100) (|. -: rot) (?400 1 1$#a){a +(_50+?100) (|. -: rot) (?0 10 2$#a){a +(_50+?100) (|. -: rot) 'a' +(_50+?100) (|. -: rot) '' + +NB. integer +(_50+?100) (|. -: rot) ?25 2 2 2$212341 +(_50+?100) (|. -: rot) ?400 1$123541 +(_50+?100) (|. -: rot) ?0 1000$123456 +(_50+?100) (|. -: rot) _4 +(_50+?100) (|. -: rot) i.0 + +NB. floating point +(_50+?100) (|. -: rot) o.?35 3 5$212341 +(_50+?100) (|. -: rot) o.?1 40$123541 +(_50+?100) (|. -: rot) o.?100 0$123456 +(_50+?100) (|. -: rot) 3.4 +(_50+?100) (|. -: rot) ,_3.4 + +NB. complex +(_50+?100) (|. -: rot) ^0j1*?30 2 5$21234 +(_50+?100) (|. -: rot) ^0j1*?1 256$1235 +(_50+?100) (|. -: rot) ^0j1*?127 0$1234 +(_50+?100) (|. -: rot) 3j4 +(_50+?100) (|. -: rot) 0$3j4 + +NB. boxed +(_50+?100) (|. -: rot) (?30 2 1 1 1$#x){x=.;:'Cogit, ergo $212 341 CBC News' +(_50+?100) (|. -: rot) (?255 1$#x){x +(_50+?100) (|. -: rot) (?0 0$#x){x +(_50+?100) (|. -: rot) <i.2 3 +(_50+?100) (|. -: rot) ,<i.2 3 + +(1 1 1 $'a') -: 1 2 3 |.'a' +(1 1 1 1$4 ) -: (?4$10)|.4 + +x -: '' |. x=. ? 2 3 4$2 +x -: '' |. x=. 3 4 5 6 $ 'deipnosophist' +x -: '' |. x=. ? 12$1000 + +'domain error' -: 'abc'|. etx i.4 3 2 +'domain error' -: 3.45 |. etx i.2 3 4 +'domain error' -: 3j4 |. etx i.3 4 +'domain error' -: (3;4)|. etx i.4 2 + + +NB. x|.y, left rank 1 --------------------------------------------------- + +f1 =: 3 : 0 + : + i =.0 [ n=.#x [ r=.#$y + while. i<n do. + y=. (i{x) |."(r-i) y + i=. >: i + end. + y +) + +2 3 (|. -: f1) ?4 5 6$10000 +2 _3 (|. -: f1) a.{~?4 5 6$#a. +_2 3 (|. -: f1) o.?4 5$100 +_2 _3 (|. -: f1) j./?2 3 4$1000 + +(?1$10) (|. -: f1) x=.?7 6 5 4 3$10000 +(?2$10) (|. -: f1) x +(?3$10) (|. -: f1) x +(?4$10) (|. -: f1) x +(?5$10) (|. -: f1) x + +(?1$10) (|."1 _1 -: f1"1 _1) x=.?7 6 5 4 3$10000 +(?2$10) (|."1 _1 -: f1"1 _1) x +(?3$10) (|."1 _1 -: f1"1 _1) x +(?4$10) (|."1 _1 -: f1"1 _1) x + +'length error' -: 2 3 |. etx i.5 +'length error' -: 2 3 4 |. etx 2 3$'a' + + +NB. x|.!.f y ------------------------------------------------------------ + +' abcdef' -: |.!.'' 'abcdefg' +0 4 5 6 -: |.!.'' 4 5 6 7 +(i.0 4 5) -: |.!.'' i.0 4 5 + +(9,i.2 4) -: _1 |.!.9 i.3 4 +'ito, ergoXXX' -: 3 |.!.'X' 'Cogito, ergo' +'XXXXXXXXXXXX' -: 99 |.!.'X' 'Cogito, ergo' +'XXXXXXXXXXXX' -: _29|.!.'X' 'Cogito, ergo' +(i.0) -: 9 |.!.99 i.0 + +(1 1 1$9) -: 1 2 3|.!.9 [4 + +'domain error' -: 2 |.!.4 etx 'abcdef' +'domain error' -: 2 1 |.!.4 etx +&.>i.4 3 +'domain error' -: _2 |.!.'a' etx i.7 3 +'domain error' -: 3 |.!.'a' etx ;:'Cogito, ergo carborundum' +'domain error' -: 9 |.!.(<4) etx 'supercalifragilisticexpialidocious' +'domain error' -: 0 |.!.(<4) etx o.i.17 + + +NB. x|."r y ------------------------------------------------------------- + +rot =: 3 : (':'; 'x|.y') + +1 2 3 (|."0 1 -: rot"0 1) ?3 7$2 +1 2 3 (|."0 1 -: rot"0 1) a.{~?3 7$#a. +1 2 3 (|."0 1 -: rot"0 1) ?3 7$1000 +1 2 3 (|."0 1 -: rot"0 1) o.?3 7$1000 +1 2 3 (|."0 1 -: rot"0 1) j./?2 3 7$1000 + +_3 (|."0 1 -: rot"0 1) ?3 7$2 +_3 (|."0 1 -: rot"0 1) a.{~?3 7$#a. +_3 (|."0 1 -: rot"0 1) ?3 7$1000 +_3 (|."0 1 -: rot"0 1) o.?3 7$1000 +_3 (|."0 1 -: rot"0 1) j./?2 3 7$1000 + +_2 3 (|."1 2 -: rot"1 2) ?2 3 7$2 +_2 3 (|."1 2 -: rot"1 2) a.{~?2 3 7$#a. +_2 3 (|."1 2 -: rot"1 2) ?2 3 7$1000 +_2 3 (|."1 2 -: rot"1 2) o.?2 3 7$1000 +_2 3 (|."1 2 -: rot"1 2) j./?2 2 3 7$1000 + +1 2 3 (|."0 _ -: rot"0 _) ?20$10000 +(2 3,:4 5) (|."1 2 -: rot"1 2) ?2 3 4$1000 +(2 3,:4 5) (|. -: rot) ?7 9$1000 +(?2 3 2$10) (|."2 -: rot"2) ?2 3 4$1000 + + +NB. x|.!.f"r y ---------------------------------------------------------- + +4!:55 ;:'f rot' +4!:55 ;:'f rot' + +rot =: 3 : (':'; 'x|.!.f y') + +1 2 3 (|.!.f"0 1 -: rot"0 1) ?3 7$2 [ f=:0 +1 2 3 (|.!.f"0 1 -: rot"0 1) a.{~?3 7$#a. [ f=:'*' +1 2 3 (|.!.f"0 1 -: rot"0 1) ?3 7$1000 [ f=:1 +1 2 3 (|.!.f"0 1 -: rot"0 1) o.?3 7$1000 [ f=:3.56 +1 2 3 (|.!.f"0 1 -: rot"0 1) j./?2 3 7$1000 [ f=:3j4 + +_3 (|.!.f"0 1 -: rot"0 1) ?3 7$2 [ f=:2 +_3 (|.!.f"0 1 -: rot"0 1) a.{~?3 7$#a. [ f=:'@' +_3 (|.!.f"0 1 -: rot"0 1) ?3 7$1000 [ f=:3.4 +_3 (|.!.f"0 1 -: rot"0 1) o.?3 7$1000 [ f=:0 +_3 (|.!.f"0 1 -: rot"0 1) j./?2 3 7$1000 [ f=:2.5 + +_2 3 (|.!.f"1 2 -: rot"1 2) ?2 3 7$2 [ f=:3j4 +_2 3 (|.!.f"1 2 -: rot"1 2) a.{~?2 3 7$#a. [ f=:' ' +_2 3 (|.!.f"1 2 -: rot"1 2) ?2 3 7$1000 [ f=:999 +_2 3 (|.!.f"1 2 -: rot"1 2) o.?2 3 7$1000 [ f=:3j4 +_2 3 (|.!.f"1 2 -: rot"1 2) j./?2 2 3 7$1000 [ f=:0 + +1 2 3 (|.!.f"0 _ -: rot"0 _) ?20$10000 [ f=:9 + +4!:55 ;:'a f f1 rank rev rot x' + +
new file mode 100644 --- /dev/null +++ b/test/g232.ijs @@ -0,0 +1,342 @@ +NB. |: ------------------------------------------------------------------ + +NB. mask =: =/ i.@>:@(>./) +NB. vec =: >@{@:(i.&.>)@((<./ .+) 127&*@-.) +NB. ind =: vec +/ .* (#. |:) +NB. mask =: i.@>:@(>./) =/ ] +NB. canta =: ($@] ind mask@[) { ,@] + +X =: +/ .* +mask =: = /: ~. +rho =: <./@# +ind =: (#:i.)@:rho X #.~ +canta =: (mask@[ ind $@]) { ,@] + +rank =: #@$ +pfill =: (i.@[ -. |) , | +en =: - #@; +ci =: (/:@pfill ;) { i.@en , en + (#&> # i.@#)@] +cant2 =: (rank@] ci [) canta ] + +cant1 =: i.@-@#@$ |: ] + +vfy =: 3 : 0 + : + a =. (#$y) pfill x + ((x|:y) -: a|:y), ((x|:y) -: (+&.>x)|:y), ($x|:y) -: a{$y + ) + +x =: a.{~?(?~5)$256 +(|:x) -: (|.i.$$x)|:x +x -: ''|:x +x -: _1|:x +0 1 vfy x +(p=:?~#$x) vfy x + +NB. Boolean +(p=:(?#$a)?#$a) vfy a =: 1=?(4?6)$2 +(|: -: cant1) a +(|: -: cant1) a=:? 8 32$2 +(|: -: cant1) a=:?32 8$2 +(|: -: cant1) a=:? 8 8$2 +(|: -: cant1) a=:?13 13$2 +(|: -: cant1) a=:?13 7$2 +(|: -: cant1) a=:? 7 13$2 + +NB. literal +(p=:(?#$a)?#$a) vfy a =: a.{~?(4?6)$256 +(|: -: cant1) a +(|: -: cant1) a=:a.{~? 8 32$256 +(|: -: cant1) a=:a.{~?32 8$256 +(|: -: cant1) a=:a.{~? 8 8$256 +(|: -: cant1) a=:a.{~?13 13$256 +(|: -: cant1) a=:a.{~?13 7$256 +(|: -: cant1) a=:a.{~? 7 13$256 + +NB. integer +(p=:(?#$a)?#$a) vfy a =: ?(4?6)$111256 +(|: -: cant1) a +(|: -: cant1) a=:_1e6+? 8 32$2e6 +(|: -: cant1) a=:_1e6+?32 8$2e6 +(|: -: cant1) a=:_1e6+? 8 8$2e6 +(|: -: cant1) a=:_1e6+?13 13$2e6 +(|: -: cant1) a=:_1e6+?13 7$2e6 +(|: -: cant1) a=:_1e6+? 7 13$2e6 + +NB. floating point +(p=:(?#$a)?#$a) vfy a =: o.?(4?6)$111256 +(|: -: cant1) a +(|: -: cant1) a=:o._1e6+? 8 32$2e6 +(|: -: cant1) a=:o._1e6+?32 8$2e6 +(|: -: cant1) a=:o._1e6+? 8 8$2e6 +(|: -: cant1) a=:o._1e6+?13 13$2e6 +(|: -: cant1) a=:o._1e6+?13 7$2e6 +(|: -: cant1) a=:o._1e6+? 7 13$2e6 + +NB. complex +(p=:(?#$a)?#$a) vfy a =: ^0j1*?(4?6)$111 +(|: -: cant1) a +(|: -: cant1) a=:r._1e6+? 8 32$2e6 +(|: -: cant1) a=:r._1e6+?32 8$2e6 +(|: -: cant1) a=:r._1e6+? 8 8$2e6 +(|: -: cant1) a=:r._1e6+?13 13$2e6 +(|: -: cant1) a=:r._1e6+?13 7$2e6 +(|: -: cant1) a=:r._1e6+? 7 13$2e6 + +NB. boxed +x =: (+&.>?20$100), ;:'((?#$a)?#$a) vfy a =: ^0j1*?(4?6)$111' +(p=:(?#$a)?#$a) vfy a =: x{~?(4?6)$#x +(|: -: cant1) a +(|: -: cant1) a=:x{~? 8 32$#x=:;:'deip no so phist epi cur ean ex cell ence' +(|: -: cant1) a=:x{~?32 8$#x +(|: -: cant1) a=:x{~? 8 8$#x +(|: -: cant1) a=:x{~?13 13$#x +(|: -: cant1) a=:x{~?13 7$#x +(|: -: cant1) a=:x{~? 7 13$#x + +id0 =: =&i. +id1 =: 1: (<0 1)&|:@i.@$@]} ($&0)&(,~) +(id0 4) -: id1 4 +(id0 0) -: id1 0 +(id0 7) -: id1 7 + +t -: |: t=:'a' +t -: |: t=:9 +t -: |: t=:3j4 +t -: |: t=:<i.3 4 + +t -: ''|: t=:'a' +t -: ''|: t=:9 +t -: ''|: t=:3j4 +t -: ''|: t=:<i.3 4 + +(x=:2 2?2) (|: -: cant2"1 _) y=:? 5 7$100 +(x=:3 3?3) (|: -: cant2"1 _) y=:?3 5 7$100 + +((i.4 6)A. i.4) (|: -: cant2)"1 _ x=:?5 6 7 8$2e6 + + +NB. |: main diagonals --------------------------------------------------- + +diag =: <@;~"0@:i.@(<./)@$ { ] + +(diag -: (<0 1)&|:) x=:?4 5$100 +(diag -: (<0 1)&|:) x=:?5 2$100 +(diag -: (<0 1)&|:) x=:?5 5$100 + +((<0 1)&|:&.(<"_2) x) -: (0 1;+&.>2}.i.#$x)|:x=:a.{~?2 3 $#256 +((<0 1)&|:&.(<"_2) x) -: (0 1;+&.>2}.i.#$x)|:x=:a.{~?2 3 4 $#256 +((<0 1)&|:&.(<"_2) x) -: (0 1;+&.>2}.i.#$x)|:x=:a.{~?2 3 4 1 $#256 +((<0 1)&|:&.(<"_2) x) -: (0 1;+&.>2}.i.#$x)|:x=:a.{~?2 3 4 1 2$#256 + +(0 1;2;3) (|: -: cant2) x=:?2 3 4 5$100 +(0 1;2;3) (|: -: cant2) x=:?3 2 4 5$100 +(0 1;2;3) (|: -: cant2) x=:?3 3 4 5$100 + +'' -: (<0 1)|: x=:?0 5$100 +'' -: (<0 1)|: x=:?5 0$100 +'' -: (<0 1)|: x=:?0 0$100 + +(i.2 0 5) -: (0 1;2;3) |: x=:?2 3 0 5$100 +(i.0 4 5) -: (0 1;2;3) |: x=:?0 3 4 5$100 +(i.0 2 3) -: (0 1;2;3) |: x=:?0 0 2 3$100 + + +NB. |: on matrices ------------------------------------------------------ + +mi =: i.@{: +/ {: * i.@{. +cant =: mi@$ { , + +NB. Boolean +( |: -: cant) 1=?50 45$2 +(1 0&|: -: cant) 1=?40 60$2 +(|:"2 -: cant"2) ?3 1 100$2 +(|:"2 -: cant"2) ?3 100 0$2 +(|:"2 -: cant"2) a=:? 8 32$2 +(|:"2 -: cant"2) a=:?4 32 8$2 +(|:"2 -: cant"2) a=:?5 8 8$2 +(|:"2 -: cant"2) a=:?1 13 13$2 +(|:"2 -: cant"2) a=:?3 13 7$2 +(|:"2 -: cant"2) a=:?2 7 13$2 + +NB. literal +( |: -: cant) (?45 45$#a){a=:'foo upon thee 1=?10 20$2' +(0&|: -: cant) (?10 200$#a){a +(|:"2 -: cant"2) (?400 1$#a){a +(|:"2 -: cant"2) (?0 1000$#a){a +(|:"2 -: cant"2) a=:a.{~? 8 32$256 +(|:"2 -: cant"2) a=:a.{~?4 32 8$256 +(|:"2 -: cant"2) a=:a.{~?5 8 8$256 +(|:"2 -: cant"2) a=:a.{~?1 13 13$256 +(|:"2 -: cant"2) a=:a.{~?3 13 7$256 +(|:"2 -: cant"2) a=:a.{~?2 7 13$256 + +NB. integer +( |: -: cant) ?50 50$212341 +(1 0&|: -: cant) ?60 45$212341 +(|:"2 -: cant"2) ?400 1$123541 +(|:"2 -: cant"2) ?0 1000$123456 +(|:"2 -: cant"2) a=:_1e6+? 8 32$2e6 +(|:"2 -: cant"2) a=:_1e6+?4 32 8$2e6 +(|:"2 -: cant"2) a=:_1e6+?5 8 8$2e6 +(|:"2 -: cant"2) a=:_1e6+?1 13 13$2e6 +(|:"2 -: cant"2) a=:_1e6+?3 13 7$2e6 +(|:"2 -: cant"2) a=:_1e6+?2 7 13$2e6 + +NB. floating point +( |: -: cant) o.?35 35$212341 +(0&|: -: cant) o.?30 40$212341 +(|:"2 -: cant"2) o.?1 400$123541 +(|:"2 -: cant"2) o.?100 0$123456 +(|:"2 -: cant"2) a=:o._1e6+? 8 32$2e6 +(|:"2 -: cant"2) a=:o._1e6+?4 32 8$2e6 +(|:"2 -: cant"2) a=:o._1e6+?5 8 8$2e6 +(|:"2 -: cant"2) a=:o._1e6+?1 13 13$2e6 +(|:"2 -: cant"2) a=:o._1e6+?3 13 7$2e6 +(|:"2 -: cant"2) a=:o._1e6+?2 7 13$2e6 + +NB. complex +( |: -: cant) ^0j1*?30 25$21234 +(1 0&|: -: cant) ^0j1*?25 25$21234 +(|:"2 -: cant"2) ^0j1*?1 256$1235 +(|:"2 -: cant"2) ^0j1*?127 0$1234 +(|:"2 -: cant"2) a=:r._1e6+? 8 32$2e6 +(|:"2 -: cant"2) a=:r._1e6+?4 32 8$2e6 +(|:"2 -: cant"2) a=:r._1e6+?5 8 8$2e6 +(|:"2 -: cant"2) a=:r._1e6+?1 13 13$2e6 +(|:"2 -: cant"2) a=:r._1e6+?3 13 7$2e6 +(|:"2 -: cant"2) a=:r._1e6+?2 7 13$2e6 + +NB. boxed +( |: -: cant) (?30 25$#x){x=:;:'Cogito, ergo sum. +/2 12 341 CBC News' +(0&|: -: cant) (?30 30$#x){x +(|:"2 -: cant"2) (?255 1$#x){x +(|:"2 -: cant"2) (?0 0$#x){x +(|:"2 -: cant"2) a=:x{~? 8 32$#x +(|:"2 -: cant"2) a=:x{~?4 32 8$#x +(|:"2 -: cant"2) a=:x{~?5 8 8$#x +(|:"2 -: cant"2) a=:x{~?1 13 13$#x +(|:"2 -: cant"2) a=:x{~?3 13 7$#x +(|:"2 -: cant"2) a=:x{~?2 7 13$#x + +(1 0 2 |:x) -: |:&.(<"_2) x=:?3 4 5$1000 +(1 0 2 3 |:x) -: |:&.(<"_2) x=:?2 3 4 2$1000 +(1 0 2 3 4|:x) -: |:&.(<"_2) x=:a.{~?2 3 4 2 3$#a. + +(i.0 13 7) -: |:"2 i.0 7 13 +(i.a,0) -: |: i.0,a=:<._1+2^31 +(i.0,a) -: |: i.a,0 + +'domain error' -: 'abc' |: etx i.3 4 +'domain error' -: (<'abc')|: etx i.3 4 +'domain error' -: 0.5 |: etx i.3 4 +'domain error' -: (<0.5) |: etx i.3 4 +'domain error' -: 3j4 |: etx i.3 4 +'domain error' -: (<3j4) |: etx i.3 4 +'domain error' -: (<<0) |: etx i.3 4 +'domain error' -: (0;<<1) |: etx i.3 4 +'domain error' -: (0;'a') |: etx i.3 4 + +'index error' -: 0 0 |: etx i.3 4 +'index error' -: (<0 0) |: etx i.3 4 +'index error' -: 2 |: etx i.3 4 +'index error' -: (<2 2) |: etx i.3 4 +'index error' -: (i.2 3) |: etx i.3 4 + + +NB. |:"r ---------------------------------------------------------------- + +(2 1 |:x) -: |:"2 x=:?4 3 2 $100 +(_1 _2|:x) -: |:"2 x=:?2 3 4 5$100 + +(|:"2 -: cant1"2) ?2 3 4$2 +(|:"2 -: cant1"2) a.{~?2 3 4$#a. +(|:"2 -: cant1"2) ?2 3 4$1000 +(|:"2 -: cant1"2) o.?2 3 4$1000 +(|:"2 -: cant1"2) r.?2 3 4$1000 +(|:"2 -: cant1"2) x{~?2 3 4$#x=:(+/i.2 3);;:'Cogito, ergo sum.' + +1 0 (|:"2 -: cant2"2) ?3 4 5$1000 +1 0 (|:"3 -: cant2"3) ?2 3 4 5$1000 +1 2 0 (|:"3 -: cant2"3) ?2 3 4 5$1000 + +(1 0,:0 1) (|:"1 2 -: cant2"1 2) a.{~?2 3 4$#a. +(1 0,:0 1) (|:"1 2 -: cant2"1 2) a.{~?2 3 4 5$#a. +(1 0,:0 2) (|:"1 3 -: cant2"1 3) a.{~?2 3 4 5$#a. + +NB. magic cubes due to Professor James G. Mauldon + +magic=: 4 : 0 + assert. (,3)=$x + assert. x=<.x + assert. 0=#$y + assert. y=<.y + s=. y + m=. 3 3{.3 4$x + s #. s | +/ .*&m (#: i.) 3#s +) + +magicprop=: 3 : 0 + s=. +/ (<0 1 2) |: y + z=. *./, s = +/y + z=. z , *./, s = +/"1 y + z=. z , *./, s = +/"2 (0 1;0 2;1 2)|:"0 _ y +) + +vfy=: 4 : 0 + m=. x magic y + (1 1 1 -: magicprop m) >: *./1=y+.x,+/x +) + +3 4 5 vfy 1 +3 4 5 vfy"1 0 >: i.5 10 +3 4 5 vfy"1 0 p: i.4 5 + +2 4 6 vfy 1 +2 4 6 vfy"1 0 >: i.5 10 +2 4 6 vfy"1 0 p: i.4 5 + +(x=: >:3?20) vfy"1 0 y=: >:?4 5$80 + + +NB. |: inverse ---------------------------------------------------------- + +vfy=: 4 : 'y -: x&|:^:_1 x|:y' " 1 _ + +x=: ?2 3 5 7 11 13$1000 +((23$0) ? #$x) vfy x +((23$1) ? #$x) vfy x +((23$2) ? #$x) vfy x +((23$3) ? #$x) vfy x +((23$4) ? #$x) vfy x +((23$5) ? #$x) vfy x +((23$6) ? #$x) vfy x + + +NB. |: symmetric array ------------------------------------------------- + +NB. two transposes suffice to test for symmetry +NB. 0. (p|:q|:X) -: (p{q)|:X +NB. 1. Therefore, the following are equivalent: +NB. P (] -: |:)"1 _ X +NB. (subgroup P) (] -: |:)"1 _ X +NB. 2. The two permutations 0&C. and _2&C. generate the whole group + +perm=: i.@! A. i. + +x=: (4$8)$0 +x=: (?1e6) (<"1 (perm #$x){?$x)}x +x=: (?1e6) (<"1 (perm #$x){?$x)}x +x=: (?1e6) (<"1 (perm #$x){?$x)}x + +sym0=: [: *./ perm@#@$ (] -: |:)"1 _ ] +sym1=: (-: 0&|:) *. (-: _2&|:) + +(sym0 -: sym1) x + + +4!:55 ;:'a cant cant1 cant2 canta ci diag en id0 id1 ' +4!:55 ;:'ind magic magicprop mask mi p perm pfill ' +4!:55 ;:'rank rho sym0 sym1 t vfy X x y' + +
new file mode 100644 --- /dev/null +++ b/test/g300.ijs @@ -0,0 +1,228 @@ +NB. +/ .* --------------------------------------------------------------- + +test =: +/ .* -: +/@(*"1 _) + +f=: 4 : 0 + xx=: x ?@$ 2 + yy=: y ?@$ 2 + assert. xx test yy + 1 +) + +(<'') f&> '';17;13 17;1 2 3 +(<17) f&> '';17;17 1;17 2 3 +(<17 3) f&> '';3 17;3 11;3 1 1 +(<1 7 3) f&> '';3 17;3 11;3 1 1 + +f=: 4 : 0 + xx=: (3,x) ?@$ 2 + yy=: (x,y) ?@$ 2 + assert. xx test yy + 1 +) + +(255+i:5) f"0/ 15+i.20 +(510+i:5) f"0/ 15+i.20 + +(3 15?@$2) test ?15 7$2 +(3 15?@$2) test ?15 2 7$100 +(3 15?@$2) test ?15 7$1e9 +(3 15?@$2) test o.?15 7 2$1100 +(3 15?@$2) test r.?15 7 1 2$1100 + +(3 15?@$100) test ?15 2 3 1 $2 +(3 15?@$100) test ?15 1 2 2$100 +(3 15?@$100) test ?15 7$1e9 +(3 15?@$100) test o.?15 7$1100 +(3 15?@$100) test r.?15 7$1100 + +(2 3 15?@$1e9) test ?15 7$2 +(2 3 15?@$1e9) test ?15 1 2 3$100 +(2 3 15?@$1e9) test ?15 7$1e9 +(2 3 15?@$1e9) test o.?15 2 3 1$1100 +(2 3 15?@$1e9) test r.?15 7$1100 + +(3 15?@$0) test ?15 7$2 +(3 15?@$0) test ?15 7$100 +(3 15?@$0) test ?15 7$1e9 +(3 15?@$0) test o.?15 7$1100 +(3 15?@$0) test r.?15 7$1100 + +(r.3 15?@$100) test ?15 7$2 +(r.3 15?@$100) test ?15 7$100 +(r.3 15?@$100) test ?15 7$1e9 +(r.3 15?@$100) test o.?15 7$1100 +(r.3 15?@$100) test r.?15 7$1100 + +(?1000) test o.?1000 +(?1000) test o.?10$1000 +(r.?1000) test ?10 2 3 1$1000 +(10?@$1000) test ?10$1000 +(r.10?@$1000) test o.?10 7$1000 + +(10?@$0) test o.?1000 +(10 1 7 1?@$1e3) test ?2 +(10 7?@$0) test 7?20 + +(i.0) test i.0 +(i.0) test i.0 4 5 +(i.4 0) test 5 +5 test i.0 5 +(i.4 0) test i.0 5 + +test&>/~ 0;1;(?1e4);(1e9+?1e9);2e9;(o.?1e6);r.?1e6 + +1 test x=: 3 5 ?@$ 1e4 +1 test~x +1 test x=: 3 5 ?@$ 1e9 +1 test~x +1 test x=: 3 5 ?@$ 0 +1 test~x +1 test x=: j./2 3 5 ?@$ 0 +1 test~x + +g=: 4 : 0 + assert. (x{~ 107 ?@$ #x) test y{~ 107 ?@$ #y + assert. (x{~ 107 ?@$ #x) test y{~ 107 5?@$ #y + assert. (x{~ 3 107 ?@$ #x) test y{~ 107 ?@$ #y + assert. (x{~ 3 107 ?@$ #x) test y{~ 107 5?@$ #y + 1 +) + +0 1 g 97 ?@$ 1e4 +0 1 g~ 97 ?@$ 1e4 +0 1 g 97 ?@$ 0 +0 1 g~ 97 ?@$ 0 +0 1 g j./ 2 97 ?@$ 1e4 +0 1 g~j./ 2 97 ?@$ 1e4 + +0 g 97 ?@$ 1e4 +0 g~ 97 ?@$ 1e4 +0 g 97 ?@$ 0 +0 g~ 97 ?@$ 0 +0 g j./ 2 97 ?@$ 1e4 +0 g~j./ 2 97 ?@$ 1e4 + +1 g 97 ?@$ 1e4 +1 g~ 97 ?@$ 1e4 +1 g 97 ?@$ 0 +1 g~ 97 ?@$ 0 +1 g j./ 2 97 ?@$ 1e4 +1 g~j./ 2 97 ?@$ 1e4 + +0 -: 0 +/ .* _ +0 -: 0 +/ .*~_ +0 -: 0 +/ .* __ +0 -: 0 +/ .*~__ +0 -: 0 0 0 +/ .* _ +0 -: 0 0 0 +/ .*~_ +0 -: _ +/ .* 0 +0 -: _ +/ .*~0 +0 -: _ _ _ +/ .* 0 +0 -: _ _ _ +/ .*~0 +0 -: _ _ _ +/ .* 0 0 0 +0 -: _ _ _ +/ .*~0 0 0 +0 -: _ 0 _ +/ .* 0 _ 0 +0 -: _ 0 _ +/ .*~0 _ 0 + +sh =. $@(+/ .*) -: }:@$@[ , }.@$@] + +1 sh 2 +567 sh ,7 +_123 sh r.?12$100 +3.4 sh o.i.1 4 5 +4 sh i.0 +3j4 sh i.0 0 0 +(,9) sh ,_3.45 +(,9) sh i.1 4 5 1 +(,9) sh i.1 0 0 +(i.0) sh 0 +(i.0) sh i.0 +(i.0) sh i.0 3 4 5 +'' sh i.59$0 +(i.3 0) sh i.0 5 +(i.3 4 0) sh 4j5 +(i.3 0 0) sh i.0 +(i.0 5 0) sh i.12$0 +(i.4 5 1) sh o.9 +(i.4 5 1) sh ,9 +(i.4 5 1) sh i.1 2 0 + +'domain error' -: (3 4$0) +/ .* etx 4 5$'c' +'domain error' -: (3 4$'a') +/ .* etx 4 5$'c' +'domain error' -: (3 4$4) +/ .* etx 4 5$'c' +'domain error' -: (3 4$4.5) +/ .* etx 4 5$'c' +'domain error' -: (3 4$4j5) +/ .* etx 4 5$'c' + +'domain error' -: (3 4$'a') +/ .* etx 4 5$0 +'domain error' -: (3 4$'a') +/ .* etx 4 5$'a' +'domain error' -: (3 4$'a') +/ .* etx 4 5$4 +'domain error' -: (3 4$'a') +/ .* etx 4 5$4.5 +'domain error' -: (3 4$'a') +/ .* etx 4 5$4j5 + +'length error' -: (i.3 4) +/ .* etx 5$6 +'length error' -: (3 4$5.6) +/ .* etx i.3 4 +'length error' -: (3 4$5) +/ .* etx ,1 +'length error' -: (3 4$5) +/ .* etx i.1 4 +'length error' -: (3 4$5) +/ .* etx i.1 0 4 +'length error' -: (3 4$5) +/ .* etx i.0 4 +'length error' -: (3 4$5) +/ .* etx i.0 + +'length error' -: (i.0) +/ .* etx i.3 4 +'length error' -: (i.0) +/ .* etx 3 4 5 +'length error' -: (i.0) +/ .* etx i.3 4 0 +'length error' -: (i.0) +/ .* etx ,3j4 +'length error' -: (i.3 4 0) +/ .* etx i.3 4 + +'length error' -: (i.1) +/ .* etx i.3 4 +'length error' -: (i.1) +/ .* etx 3 4 5 +'length error' -: (i.1) +/ .* etx i.3 4 0 +'length error' -: (i.3 4 1) +/ .* etx i.3 4 +'length error' -: (i.3 4 1) +/ .* etx i.3 0 0 + + +NB. -/ .* y ------------------------------------------------------------- + +f=: -/"1 @: */ @ (0 1&(|."0 1))"2 +g=: -/"1 @: (*/"2) @: ((0 1&(|."0 1))"2) +h=: [: -/"1 {."2 * |."1@:({:"2) + +(f -: -/ .*) m=. ?300 2 2$100 +(g -: -/ .*) m +(h -: -/ .*) m + +(-/ .* -: */@((<0 1)&|:)) m=.(<:/~i.6) * 6 6 ?@$ 0 +(-/ .* -: */@((<0 1)&|:)) m=.(<:/~i.7) * 7 7 ?@$ 0 + +eqf=: 4 : 0 + (x -:!.t y) +. (t>|x) *. t>|y [ t=. 2^_34 +) + +(-"0/ .* eqf -/ .*) m=. ?5 5$2 +(-"0/ .* eqf -/ .*) m=. ?6 6$2 +(-"0/ .* eqf -/ .*) m=. ?7 7$2 + +(-"0/ .* eqf -/ .*) m=. _100+?5 5$200 +(-"0/ .* eqf -/ .*) m=. _100+?6 6$200 +(-"0/ .* eqf -/ .*) m=. _100+?7 7$200 + +(-"0/ .* eqf -/ .*) m=. 0.1*_100+?5 5$2000 +(-"0/ .* eqf -/ .*) m=. 0.1*_100+?6 6$2000 +(-"0/ .* eqf -/ .*) m=. 0.1*_100+?7 7$2000 + +(-"0/ .* eqf -/ .*) m=. j./0.1*_100+?2 5 5$2000 +(-"0/ .* eqf -/ .*) m=. j./0.1*_100+?2 6 6$2000 +(-"0/ .* eqf -/ .*) m=. j./0.1*_100+?2 7 7$2000 + +(-"0/ .* eqf -/ .*) m=. _100+?5 5$200x +(-"0/ .* eqf -/ .*) m=. _100+?6 6$200x +(-"0/ .* eqf -/ .*) m=. _100+?7 7$200x + +(-"0/ .* eqf -/ .*) m=. %/1+?2 4 4$200x +(-"0/ .* eqf -/ .*) m=. %/1+?2 5 5$200x +(-"0/ .* eqf -/ .*) m=. %/1+?2 6 6$200x + + +4!:55 ;:'eqf f g h m sh test x xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g300b.ijs @@ -0,0 +1,140 @@ +NB. boolean inner products, +./ .*. and ~:/ .*. , etc. ------------------ + +ip=: 4 : 0 + assert. x (~:/ .= -: ~:/@(= "1 _)) y + assert. x (~:/ .~: -: ~:/@(~:"1 _)) y + assert. x (~:/ .+. -: ~:/@(+."1 _)) y + assert. x (~:/ .+: -: ~:/@(+:"1 _)) y + assert. x (~:/ .*. -: ~:/@(*."1 _)) y + assert. x (~:/ .*: -: ~:/@(*:"1 _)) y + assert. x (~:/ .< -: ~:/@(< "1 _)) y + assert. x (~:/ .<: -: ~:/@(<:"1 _)) y + assert. x (~:/ .> -: ~:/@(> "1 _)) y + assert. x (~:/ .>: -: ~:/@(>:"1 _)) y + assert. x (+./ .= -: +./@(= "1 _)) y + assert. x (+./ .~: -: +./@(~:"1 _)) y + assert. x (+./ .+. -: +./@(+."1 _)) y + assert. x (+./ .+: -: +./@(+:"1 _)) y + assert. x (+./ .*. -: +./@(*."1 _)) y + assert. x (+./ .*: -: +./@(*:"1 _)) y + assert. x (+./ .< -: +./@(< "1 _)) y + assert. x (+./ .<: -: +./@(<:"1 _)) y + assert. x (+./ .> -: +./@(> "1 _)) y + assert. x (+./ .>: -: +./@(>:"1 _)) y + assert. x (*./ .= -: *./@(= "1 _)) y + assert. x (*./ .~: -: *./@(~:"1 _)) y + assert. x (*./ .+. -: *./@(+."1 _)) y + assert. x (*./ .+: -: *./@(+:"1 _)) y + assert. x (*./ .*. -: *./@(*."1 _)) y + assert. x (*./ .*: -: *./@(*:"1 _)) y + assert. x (*./ .< -: *./@(< "1 _)) y + assert. x (*./ .<: -: *./@(<:"1 _)) y + assert. x (*./ .> -: *./@(> "1 _)) y + assert. x (*./ .>: -: *./@(>:"1 _)) y + 1 +) + +test=: 4 : 0 + xx=: x ?@$ 2 + yy=: y ?@$ 2 + assert. xx ip yy + xx=: (|.y) ?@$ 2 + yy=: (|.x) ?@$ 2 + assert. xx ip yy + 1 +) + +'' test '' +'' test 16 +'' test 17 +'' test 13 16 +'' test 13 17 +'' test 1 2 8 +'' test 1 3 7 +13 test 13 +13 test 13 0 +13 test 13 1 +13 test 13 16 +13 test 13 17 +16 test 16 +16 test 16 0 +16 test 16 1 +16 test 16 16 +16 test 16 17 +13 16 test 16 0 +13 16 test 16 1 +13 16 test 16 19 +13 16 test 16 24 +13 17 test 17 0 +13 17 test 17 1 +13 17 test 17 19 +13 17 test 17 24 +16 16 test 16 19 +16 16 test 16 24 +16 17 test 17 19 +16 17 test 17 24 + +0 -: 0 +./ .*. 0 +0 -: 0 +./ .*.~0 +0 -: 0 0 0 +./ .*. 0 +0 -: 0 0 0 +./ .*.~0 +0 -: 0 0 0 +./ .*. 0 0 0 + +0 -: 0 ~:/ .*. 0 +0 -: 0 ~:/ .*.~0 +0 -: 0 0 0 ~:/ .*. 0 +0 -: 0 0 0 ~:/ .*.~0 +0 -: 0 0 0 ~:/ .*. 0 0 0 + +sh =. $@(+./ .*.) -: }:@$@[ , }.@$@] + +1 sh 0 +1 sh ,0 +0 sh 12 ?@$ 2 +1 sh 1 4 5 ?@$ 2 +1 sh i.0 +0 sh i.0 0 0 +(,0) sh ,1 +(,0) sh 1 4 5 1 ?@$ 2 +(,0) sh 1 0 0 ?@$ 2 +(i.0) sh 0 +(i.0) sh i.0 +(i.0) sh i.0 3 4 5 +'' sh i.59$0 +(i.3 0) sh i.0 5 +(i.3 0 0) sh i.0 +(i.0 5 0) sh i.12$0 +(4 5 1 ?@$ 2) sh i.1 2 0 + +'domain error' -: (3 4 ?@$ 2) +./ .*. etx 4 5$'c' +'domain error' -: (3 4 ?@$ 2) +./ .*. etx 4 5$<'c' +'domain error' -: (3 4 ?@$ 2) +./ .*. etx u: 4 5 ?@$ 100 + +'domain error' -: (4 3$'c' ) +./ .*. etx 3 4 ?@$ 2 +'domain error' -: (4 3$<'c' ) +./ .*. etx 3 4 ?@$ 2 +'domain error' -: (4 3$u: 12) +./ .*. etx 3 4 ?@$ 2 + +'length error' -: (3 4 ?@$ 2) +./ .*. etx 5$1 +'length error' -: (3 4 ?@$ 2) +./ .*. etx 3 4 ?@$ 2 +'length error' -: (3 4$5) +./ .*. etx ,1 +'length error' -: (3 4$5) +./ .*. etx i.1 4 +'length error' -: (3 4$5) +./ .*. etx i.1 0 4 +'length error' -: (3 4$5) +./ .*. etx i.0 4 +'length error' -: (3 4$5) +./ .*. etx i.0 + +'length error' -: (i.0) +./ .*. etx i.3 4 +'length error' -: (i.0) +./ .*. etx 3 4 5 +'length error' -: (i.0) +./ .*. etx i.3 4 0 +'length error' -: (i.0) +./ .*. etx ,3j4 +'length error' -: (i.3 4 0) +./ .*. etx i.3 4 + +'length error' -: (i.1) +./ .*. etx i.3 4 +'length error' -: (i.1) +./ .*. etx 3 4 5 +'length error' -: (i.1) +./ .*. etx i.3 4 0 +'length error' -: (i.3 4 1) +./ .*. etx i.3 4 +'length error' -: (i.3 4 1) +./ .*. etx i.3 0 0 + + +4!:55 ;:'ip sh test xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g300t.ijs @@ -0,0 +1,11 @@ +NB. -/ .* y timing tests ------------------------------------------------ + +h=: [: -/"1 {."2 * |."1@:({:"2) + +m=: 1024 %~ _5e5* 5000 2 2 ?@$1e6 +0.4 > | (-/ % <./) t=: (10 timer '-/ .* m') , 10 timer 'h m' + + +4!:55 ;:'h m t' + +
new file mode 100644 --- /dev/null +++ b/test/g301.ijs @@ -0,0 +1,37 @@ +NB. .. and .: ----------------------------------------------------------- + +symm =: 2 : 'x -:@:+ x&y' +skew =: 2 : 'x -:@:- x&y' + +sin =: 1&o. +cos =: 2&o. +sinh =: 5&o. +cosh =: 6&o. + +sin1 =: ^ .: - &. j. +cos1 =: ^@j. .. - +sinh1 =: ^ .: - +cosh1 =: ^ .. - + +sin2 =: ^ skew- &. j. +cos2 =: ^@j.symm- +sinh2 =: ^ skew- +cosh2 =: ^ symm- + +x=:(0.01*_700+?20$1400),0,*/\4$0j1 + +1e_12 > | (sin - sin1 ) x +1e_12 > | (cos - cos1 ) x +1e_12 > | (sinh - sinh1) x +1e_12 > | (cosh - cosh1) x + +1e_12 > | (sin - sin2 ) x +1e_12 > | (cos - cos2 ) x +1e_12 > | (sinh - sinh2) x +1e_12 > | (cosh - cosh2) x + + +4!:55 ;:'cos cos1 cos2 cosh cosh1 cosh2 sin sin1 sin2 sinh ' +4!:55 ;:'sinh1 sinh2 skew symm x ' + +
new file mode 100644 --- /dev/null +++ b/test/g310.ijs @@ -0,0 +1,299 @@ +NB. : ------------------------------------------------------------------- + +p =: ?4 10$500 +q =: ?4 10$50 + +f =: 3 : 'y%3' : * +(q%3) -: f q +(p*q) -: p f q + +f =: ^ : (3 : (':';'x+y')) +(^p) -: f p +(p+q) -: p f q + +f =: %&>: : | +(%1+q) -: f q +(p|q) -: p f q + +f =: 4 : 'x+y' + +3 4 5 (f -: +) x=:?3$1e9 + +f=: 3 : '1 [ big=.y$''abc''' +p=: 7!:0 '' +f 2e5 +q=: 7!:0 '' +2000>q-p + +minors =: }."1@(1&([\.)) +det =: 2 : 'y/@,`({."1 x .y $:@minors)@.(1&<@{:@$)"2' +(-/det* a) -: -/ .* a=:?3 3$1000 + + +NB. : fn call nesting --------------------------------------------------- + +f=: 3 : 'if. 0<y do. f<:y else. 1 end.' + +f 14 +f 15 +f 30 +f 60 + + +NB. 13 : ---------------------------------------------------------------- + +Tv =: 1 : '13 : x' +ar =: 5!:1 +eq =: 2 : '(ar<''x'') -: (ar<''y'')' + +(+/ % #) eq ('(+/y)%#y' Tv) ++ eq ('x+y' Tv) +(+*-) eq ('(x+y)*(x-y)' Tv) + + +NB. : ------------------------------------------------------------------- + +nl =: 10{a. NB. system independent new-line + +monad =: *:@:>: +dyad =: *:@:>:@:+ + +x =: <;._1 '/t=.y+1/t^2/:/t=.x+y/t=.t+1/t^2' + +f0 =: 3 : x NB. boxed sentences +(f0 -: monad) ?30$100 +(?31$100) (f0 -: dyad) ?31$100 + +f1 =: 3 : (>x) NB. character matrix +(f1 -: monad) ?30$100 +(?31$100) (f1 -: dyad) ?31$100 + +f2 =: 3 : (;x,&.><nl) NB. string (with embedded newlines) +(f2 -: monad) ?30$100 +(?31$100) (f2 -: dyad) ?31$100 + +f3 =: 3 : (}:;x,&.><nl) NB. string without final newline +(f3 -: monad) ?30$100 +(?31$100) (f3 -: dyad) ?31$100 + +f4 =: 3 : (2{.x) NB. boxed monad only +(f4 -: monad) ?30$100 + +f4a =: 3 : (>2{.x) NB. matrix monad only +(f4a -: monad) ?30$100 + +f5 =: 3 : (2}.x) NB. boxed dyad only +(?31$100) (f5 -: dyad) ?31$100 + +f5a =: 3 : (>2}.x) NB. matrix dyad only +(?31$100) (f5a -: dyad) ?31$100 + +f6 =: 3 : '(y+1)^2' NB. string monad only +(f6 -: monad) ?30$100 + +f6a =: 3 : ('(y+1)^2',nl) NB. string monad only +(f6a -: monad) ?30$100 + +f6b =: 3 : (':', nl,'(x+y+1)^2') NB. string dyad only +(?31$100) (f6b -: dyad) o.?31$100 + +f6c =: 3 : (': ',nl,'(x+y+1)^2') NB. string dyad only +(?31$100) (f6c -: dyad) o.?31$100 + +f7 =: 3 : '7' NB. scalar string +7 -: f7 ?30$100 + +x=: 'abc',nl,(a.{~190+i.4),nl +('p=: 0 : 0',nl,x,')',nl) 1!:2 <'asdf.txt' +0!:0 <'asdf.txt' +p -: x +1!:55 <'asdf.txt' + + +NB. : treatment of comments and white space ----------------------------- + +9!:41 ]1 NB. retain comments and whitespace + +f1 =: 3 : 0 + + 1 NB. aa + + + 4 NB. bbb + +) + +x=: ];._1 '// 1 NB. aa/// 4 NB. bbb/' +(5!:1 <'f1') -: <(,':');<((,'0');3);<(,'0');,.x +(5!:2 <'f1') -: 3;(,':');,.x +(5!:5 <'f1') -: '3 : 0',nl,nl,' 1 NB. aa',nl,nl,nl,' 4 NB. bbb',nl,nl,')' + +f2 =: 3 : 0 + + : + + 1 NB. aa + + + 4 NB. bbb +) + +x=: ];._1 '//:// 1 NB. aa/// 4 NB. bbb' +(5!:1 <'f2') -: <(,':');<((,'0');3);<(,'0');,.x +(5!:2 <'f2') -: 3;(,':');,.x +(5!:5 <'f2') -: '3 : 0',nl,nl,':',nl,nl,' 1 NB. aa',nl,nl,nl,' 4 NB. bbb',nl,')' + +f3 =: 3 : 0 + + 11 NB. aaaa + 12 NB. b + + + 15 NB. cc + + + : + + 21 NB. ddd + + + 24 NB. e + NB. ff +) + +x=: ];._1 '// 11 NB. aaaa/ 12 NB. b/// 15 NB. cc///:// 21 NB. ddd/// 24 NB. e/ NB. ff' +(5!:1 <'f3') -: <(,':');<((,'0');3);<(,'0');x +(5!:2 <'f3') -: 3;(,':');x +(5!:5 <'f3') -: '3 : 0',nl,nl,' 11 NB. aaaa',nl,' 12 NB. b',nl,nl,nl,' 15 NB. cc',nl,nl,nl,':',nl,nl,' 21 NB. ddd',nl,nl,nl,' 24 NB. e',nl,' NB. ff',nl,')' + +9!:41 ]0 NB. discard comments and white space + +f1 =: 3 : 0 + + 1 NB. aa + + + 4 NB. bbb + +) + +x=: ];._1 '//1///4' +(5!:1 <'f1') -: <(,':');<((,'0');3);<(,'0');,.x +(5!:2 <'f1') -: 3;(,':');,.x +(5!:5 <'f1') -: '3 : 0',nl,nl,'1',nl,nl,nl,'4',nl,')' + +f2 =: 3 : 0 + + : + + 1 NB. aa + + + 4 NB. bbb +) + +x=: ];._1 '/://1///4' +(5!:1 <'f2') -: <(,':');<((,'0');3);<(,'0');,.x +(5!:2 <'f2') -: 3;(,':');,.x +(5!:5 <'f2') -: '3 : 0',nl,':',nl,nl,'1',nl,nl,nl,'4',nl,')' + +f3 =: 3 : 0 + + 11 NB. aaaa + 12 NB. b + + + 15 NB. cc + + + : + + 21 NB. ddd + + + 24 NB. e + NB. ff +) + +x=: ];._1 '//11/12///15/://21///24' +(5!:1 <'f3') -: <(,':');<((,'0');3);<(,'0');x +(5!:2 <'f3') -: 3;(,':');x +(5!:5 <'f3') -: '3 : 0',nl,nl,'11',nl,'12',nl,nl,nl,'15',nl,':',nl,nl,'21',nl,nl,nl,'24',nl,')' + +9!:41 ]1 NB. retain comments and white space + + +NB. : ------------------------------------------------------------------- + +'domain error' -: ex '''y.'': ''x.+y.''' +'domain error' -: ex '3.5 : ''x.'' ' +'domain error' -: ex '3j4 : ''x.'' ' + +'domain error' -: ex '''y.'' : 0 ' +'domain error' -: ex '''x.'' : 1 ' +'domain error' -: ex '''y.'' : 2 ' +'domain error' -: ex '''y.'' : 3 ' +'domain error' -: ex '''y.'' : 3.5' +'domain error' -: ex '''y.'' : 3j4' + +'rank error' -: ex '1 2 : ''x.''' +'rank error' -: ex '(,:1) : ''x.''' +'rank error' -: ex '3 : (2 3 4$''a'')' +'rank error' -: ex '2 : (2 3$<''a'')' + +'syntax error' -: (3 : '+') etx 4 + + +NB. : empty defn -------------------------------------------------------- + +f=: 3 : '' + +'domain error' -: f etx 4 +'domain error' -: 3 f etx 4 + +f=: 3 : (i.0) + +'domain error' -: f etx 4 +'domain error' -: 3 f etx 4 + +f=: 4 : '' + +'domain error' -: f etx 4 +'domain error' -: 3 f etx 4 + +f=: 4 : (i.0) + +'domain error' -: f etx 4 +'domain error' -: 3 f etx 4 + +f =: (3 : '') : + + +'domain error' -: f\ etx 0 1 0 +'domain error' -: f;._1 etx 0 1 0 +'domain error' -: f/. etx i.3 5 +'domain error' -: 0 1 ,&f etx 1 0 +'domain error' -: 0 1 f@* etx 1 0 +'domain error' -: (2: * f) etx 1 0 +'domain error' -: (+ f) etx 5 + +f1 =: 3 : 'y' +f2 =: 3 : (':'; 'x+y') +f3 =: 4 : 'x+y' + +'domain error' -: 3 f1 etx 4 +'domain error' -: f2 etx 4 +'domain error' -: f3 etx 4 + +'domain error' -: ~./ etx 0 1 0 +'domain error' -: 0 1 ~./ etx 1 0 +'domain error' -: 0 1 ~.&* etx 1 0 +'domain error' -: 0 1 *@~. etx 1 0 +'domain error' -: (+ ~. -) etx 1 0 +'domain error' -: (~. -) etx 1 0 + + +4!:55 ;:'a ar det dyad eq f f0 f1 f2 f3 f4' +4!:55 ;:'f4a f5 f5a f6 f6a f6b f6c f7' +4!:55 ;:'minors monad nl p q Tv x' + +
new file mode 100644 --- /dev/null +++ b/test/g310a.ijs @@ -0,0 +1,76 @@ +NB. : ------------------------------------------------------------------- + +jnc =: 4!:0 +verb =: 3&= @ jnc +boxed =: 32&= @ type +open =: 32&~: @ type +inv =: 1 : 'x^: _1' + +pow=: 2 : 0 + assert. verb <'u' + if. verb <'v' do. u powv v + elseif. boxed n do. u powg n + elseif. 1 do. u pown n + end. +) + +powv=: 2 : 0 + u pown (v y) y + : + x u pown (x v y) y +) + +pown =: 2 : 0 + if. #$n do. u powg (>@{.`(>@{:))"1 n;"0<y + elseif. 0>n do. u inv pown (-n) y + elseif. 1 do. + assert. n-:<.n + z=.y [ t=.0-:y [ i=._1 + while. (t-:z)<n>i=.>:i do. z=.u t=.z end. + end. + : + x&u pown n y +) + +powg=: 2 : 0 + assert. ($n) -: ,2 + v0=. (0{n) `:6 + v1=. (1{n) `:6 + u pown (v0 y) v1 y + : + assert. ($n) -:"1 ,. 2 3 + n=. _3}.'[';n + v0=. (0{n) `:6 + v1=. (1{n) `:6 + v2=. (2{n) `:6 + (x v0 y) u pown (x v1 y) (x v2 y) +) + +(>: pow n -: >: ^: n) 1 [ n=.?10 +(>: pow n -: >: ^: n) 1 [ n=.?10$10 +(>: pow n -: >: ^: n) 1 [ n=._5+?10$10 +(>: pow n -: >: ^: n) 1 [ n=.i.9 + +((0&,+,&0) pow (i.9) -: (0&,+,&0)^:(i.9)) ,1 + +f=: (0&,+,&0) pow (i.9) +3 -: 4!:0 <'f' + +(+/\ pow n -: +/\ ^:n) 7{.1 [ n=.i.9 +(+/\ pow n -: +/\ ^:n) 7{.1 [ n=._7+i.15 +g=: i.@>:@+:@# - # +(+/\ pow g -: +/\ ^:g) 7{.1 + +(2&o. pow _ -: 2&o. ^:_) 1 + +f=:(#:1 3)&(+/ .*) +(f pow n -: f ^: n) 0 1 [ n=._5+i.11 + +(,~ pow n -: ,~ ^:n) 'x' [ n=.i.6 +(,&'x' pow n -: ,&'x' ^:n) '' [ n=.i.6 +(,&'xx' pow n -: ,&'xx'^:n) '' [ n=.i.6 + + +4!:55 ;:'boxed f g inv jnc n open pow powg pown powv verb' + +
new file mode 100644 --- /dev/null +++ b/test/g310names.ijs @@ -0,0 +1,22 @@ +NB. names ---------------------------------------------------------------- + +abc_xyz_ -: p: i._5 [ 3 : ' abc_xyz_ =. p: i._5 ' 0 +abc_xyz_ -: 12 [ 3 : '''a abc_xyz_''=. 3 12 ' 0 +abc_xyz_ -: i.3 4 [ 3 : '".''abc_xyz_ =. i.3 4'' ' 0 + +'domain error' -: 3 : ' y =: 12 ' etx 0 +'domain error' -: 3 : '". '' y =: 12''' etx 0 +'domain error' -: 3 : ' ''a y''=: 12 3' etx 0 + +'domain error' -: 3 : ('a=. 3';' a =:3 ') etx 0 +'domain error' -: 3 : ('a=. 3';'".'' a =:3''') etx 0 +'domain error' -: 3 : ('a=. 3';' ''c a''=:3 ') etx 0 + +1 [ 3 : ('a=: 99 ?.@$ 1e6';'a=.12') 0 +a -: 99 ?.@$ 1e6 + + +18!:55 <'xyz' +4!:55 ;:'a c' + +
new file mode 100644 --- /dev/null +++ b/test/g310r.ijs @@ -0,0 +1,88 @@ +NB. : representations of explicit operators ----------------------------- + +nl=: 10{a. +nn=: <@((,'0')&;) + +F=: 2 : 0 +u v y +: +x u v y +) + + +F1=: 2 : 'u v y' + +F2=: 2 : 0 +: +x u v y +) + +f =: + F * +f1=: + F1 * +f2=: + F2 * + +(5!:1 <'F' ) -: <(,':');<(nn 2),nn ];._1 '/u v y/:/x u v y' +(5!:1 <'F1') -: <(,':');<(nn 2),nn ];._1 '/u v y' +(5!:1 <'F2') -: <(,':');<(nn 2),nn ];._1 '/:/x u v y' +(5!:1 <'f' ) -: <(5!:1 <'F' ),<,&.>'+*' +(5!:1 <'f1') -: <(5!:1 <'F1'),<,&.>'+*' +(5!:1 <'f2') -: <(5!:1 <'F2'),<,&.>'+*' + +(5!:2 <'F' ) -: 2;(,':');];._1 '/u v y/:/x u v y' +(5!:2 <'F1') -: 2;(,':');];._1 '/u v y' +(5!:2 <'F2') -: 2;(,':');];._1 '/:/x u v y' +(5!:2 <'f' ) -: ,&.> '+';(5!:2 <'F' );'*' +(5!:2 <'f1') -: ,&.> '+';(5!:2 <'F1');'*' +(5!:2 <'f2') -: ,&.> '+';(5!:2 <'F2');'*' + +(5!:5 <'F' ) -: '2 : 0',nl,'u v y',nl,':',nl,'x u v y',nl,')' +(5!:5 <'F1') -: '2 : ''u v y''' +(5!:5 <'F2') -: '2 : ('':''; ''x u v y'')' +(5!:5 <'f' ) -: '+ (2 : 0) *',(i.&nl }. ]) 5!:5 <'F' +(5!:5 <'f1') -: '+ (',(5!:5 <'F1'),') *' +(5!:5 <'f2') -: '+ (',(5!:5 <'F2'),') *' + +G=: 1 : 0 +u y +: +x u y +) + +G1=: 1 : 'u y' + +G2=: 1 : 0 +: +x u y +) + +g =: +/ G +g1=: +/ G1 +g2=: +/ G2 + +sum=: +/ + +(5!:1 <'G' ) -: <(,':');<(nn 1),nn ];._1 '/u y/:/x u y' +(5!:1 <'G1') -: <(,':');<(nn 1),nn ];._1 '/u y' +(5!:1 <'G2') -: <(,':');<(nn 1),nn ];._1 '/:/x u y' +(5!:1 <'g' ) -: <(5!:1 <'G'),<,5!:1 <'sum' +(5!:1 <'g1') -: <(5!:1 <'G1'),<,5!:1 <'sum' +(5!:1 <'g2') -: <(5!:1 <'G2'),<,5!:1 <'sum' + +(5!:2 <'G' ) -: 1;(,':');];._1 '/u y/:/x u y' +(5!:2 <'G1') -: 1;(,':');];._1 '/u y' +(5!:2 <'G2') -: 1;(,':');];._1 '/:/x u y' +(5!:2 <'g' ) -: (,&.>'+/');<5!:2 <'G' +(5!:2 <'g1') -: (,&.>'+/');<5!:2 <'G1' +(5!:2 <'g2') -: (,&.>'+/');<5!:2 <'G2' + +(5!:5 <'G' ) -: '1 : 0',nl,'u y',nl,':',nl,'x u y',nl,')' +(5!:5 <'G1') -: '1 : ''u y''' +(5!:5 <'G2') -: '1 : ('':''; ''x u y'')' +(5!:5 <'g' ) -: '+/ (1 : 0)',(i.&nl }. ]) 5!:5 <'G' +(5!:5 <'g1') -: '+/ (',(5!:5 <'G1'),')' +(5!:5 <'g2') -: '+/ (',(5!:5 <'G2'),')' + + +4!:55 ;:'F f F1 f1 F2 f2 G g G1 g1 G2 g2 nl nn sum' + +
new file mode 100644 --- /dev/null +++ b/test/g310t.ijs @@ -0,0 +1,208 @@ +NB. 13 : y --------------------------------------------------------------- + +ar=: 5!:1 + +eq=: 4 : 0 + 0!:100 'f9=.',x + g9 =. 13 : y + assert. 'f9' -:&ar&< 'g9' + 1 +) + +eq1=: 4 : 0 + x eq y + assert. (3 : y -: 13 : y) 123 + 1 +) + +eq2=: 4 : 0 + x eq y + assert. 456 (4 : y -: 13 : y) 123 + 1 +) + +eq12=: 4 : 0 + x eq y + assert. (3 : y -: 13 : y) 123 + assert. 456 (4 : y -: 13 : y) 123 + 1 +) + +eqx=: 3 : 0 + f9=. (3+(<,'x')e.;:y) : y + g9=. 13 : y + assert. 'f9' -:&ar&< 'g9' + 1 +) + + +NB. 13 : y constants ----------------------------------------------------- + +'0"_' eq12 '0' +'1"_' eq12 '1' +'1:' eq12 '2-1' +'1x"_' eq12 '1x' +'1r2"_' eq12 '1r2' +'3:' eq12 '2+1' +'_3:' eq12 '1-4' +'11"_' eq12 '10+1' +'(i.2 3)"_' eq12 'i.2 3' +'''a''"_' eq12 '''a''' +'''abc''"_' eq12 '''abc''' + + +NB. 13 : y monads -------------------------------------------------------- + +'*:' eq1 '*:y' +'#' eq1 '#y' +'[: *: >:' eq1 '*: >: y' +'[: +: [: -: [: *: %:' eq1 '+: -: *: %: y' +'[: i. #' eq1 'i. # y' +'<: * >:' eq1 '(<:y)*>:y' +'+/ % #' eq1 '(+/y)%#y' +'* # ]' eq1 '(*y)#y' +'] #~ 0 < ]' eq1 '(0<y)#y' +'2 ^~ ]' eq1 'y^2' +'_1 ^~ ]' eq1 'y^_1' +'12 ^~ ]' eq1 'y^12' +'0.5 ^~ ]' eq1 'y^0.5' +'2 ^. ]' eq1 '2^.y' +'10 ^. ]' eq1 '10^.y' +'3 + 4 * ]' eq1 '3 + 4 * y' +'7 * ]' eq1 '(3+4)*y' +'_10 ]\ ":' eq1 '_10 ]\ ": y' +'+/ % #' eq1 '(13 : ''(+/y)%#y'') y' + +'2= ]' eq1 'y= 2' +'2<.]' eq1 'y<.2' +'2>.]' eq1 'y>.2' +'2+ ]' eq1 'y+ 2' +'2+.]' eq1 'y+.2' +'1+:]' eq 'y+:1' +'2* ]' eq1 'y* 2' +'2*.]' eq1 'y*.2' +'1*:]' eq 'y*:1' +'2-:]' eq1 'y-:2' +'2~:]' eq1 'y~:2' + +'2< ]' eq1 'y> 2' +'2<:]' eq1 'y>:2' +'2> ]' eq1 'y< 2' +'2>:]' eq1 'y<:2' + +'(200$''3'') {~ ]' eq1 'y{a' [ a=: 200$'3' + + +NB. 13 : y dyads --------------------------------------------------------- + +'*' eq2 'x*y' +',' eq2 'x,y' +'+ * -' eq2 '(x+y)*(x-y)' +'3 + 4 * >.' eq2 '3 + 4 * x>.y' + +'/:~' eq1 'y/:y' +'/:~' eq2 'y/:x' +'[ /: [' eq2 'x/:x' + + +NB. 13 : y can not translate --------------------------------------------- + +eqx '+:^:y y' +eqx '+:^:x y' +eqx '(y * *:)y' +eqx '(x * *:)y' +eqx 'd*d=:y' +eqx 'x>.d*d=:y' +eqx '3+y=.y+2' +eqx '3+x=.x+2' + + +NB. 13 : y local defns --------------------------------------------------- + +'0 < 20 -~ ]' eq1 '0<t [ t=. y - 20' +'30 ^~ 20 -~ ]' eq1 't^30 [ t=. y - 20' +'2 ^ 10 -~ ]' eq1 '2^ t [ t=. y - 10' +'2 ^ 10 - ]' eq1 '2^ t [ t=. 10 - y' + +'[: -: 7-~]' eq1 ' -:t [ t=. y-7' +'[: ([: *: -:) 7-~]' eq1 ' *:-:t [ t=. y-7' +'[: ([: ^ [: *: -:) 7-~]' eq1 '^*:-:t [ t=. y-7' + +' 4 + 12-~]' eq1 ' 4+t=.y-12' +'[: ( [: *: 4 + ]) 12-~]' eq1 ' *:4+t=.y-12' +' [: *: 12-~]' eq1 ' *: t=.y-12' +'[: (6 - *: ) 12-~]' eq1 '6-*: t=.y-12' +'[: (6 - [: *: 4 + ]) 12-~]' eq1 '6-*:4+t=.y-12' + +'[: ([: *: -:) -:' eq1 '*:-: t=. -:y' +'[: ((7< ]) # ]) -:' eq1 '(7<t)#t=. -:y' +'[: ((7< ]) # ]) -:' eq1 '(t>7)#t=. -:y' + +'[: (%: - *: ) 12-~]' eq1 '(%:t) - *: t=. y-12' +'[: (%: - 1<]) 12-~]' eq1 '(%:t) - 1< t=. y-12' +'[: ((0<]) - *: ) 12-~]' eq1 '(0<t) - *: t=. y-12' +'[: ((0<]) - 1<]) 12-~]' eq1 '(t>0) - 1< t=. y-12' + +'*: + -:' eq1 's+t [ s=. *:y [ t=. -:y' +'(] + #) + #' eq1 '(s+t) [ s=.y+t[t=.#y' + +'+ = -' eq2 ' s = t [ s=. x+y [ t=. x-y' +'+ ( [ =2 %]) -' eq2 ' s = 2%t [ s=. x+y [ t=. x-y' +'+ ( [ =[:%]) -' eq2 ' s = %t [ s=. x+y [ t=. x-y' +'+ ( [ = % ) -' eq2 ' s = s%t [ s=. x+y [ t=. x-y' +'+ ((3* [)= ]) -' eq2 '(s*3)= t [ s=. x+y [ t=. x-y' +'+ ((3* [)=2 %]) -' eq2 '(s*3)= 2%t [ s=. x+y [ t=. x-y' +'+ ((3* [)=[:%]) -' eq2 '(s*3)= %t [ s=. x+y [ t=. x-y' +'+ ((3* [)= % ) -' eq2 '(s*3)= s%t [ s=. x+y [ t=. x-y' +'+ (([:*:[)= ]) -' eq2 '(*:s)= t [ s=. x+y [ t=. x-y' +'+ (([:*:[)=2 %]) -' eq2 '(*:s)= 2%t [ s=. x+y [ t=. x-y' +'+ (([:*:[)=[:%]) -' eq2 '(*:s)= %t [ s=. x+y [ t=. x-y' +'+ (([:*:[)= % ) -' eq2 '(*:s)= s%t [ s=. x+y [ t=. x-y' + +'+ (([:*:[)= % ) -' eq2 '(*:s)= s%t [ s=. x+y [ t=. x-y' +'+ (([:*:])= % ) -' eq2 '(*:t)= s%t [ s=. x+y [ t=. x-y' +'- (([:*:])= % ) +' eq2 '(*:s)= t%s [ s=. x+y [ t=. x-y' + +'+ (*= ]) -' eq2 '(s*t)= t [ s=. x+y [ t=. x-y' +'+ (*=2 %]) -' eq2 '(s*t)= 2%t [ s=. x+y [ t=. x-y' +'+ (*=[:%]) -' eq2 '(s*t)= %t [ s=. x+y [ t=. x-y' +'+ (*= % ) -' eq2 '(s*t)= s%t [ s=. x+y [ t=. x-y' +'+ (*= % ) -' eq2 '(t*s)= s%t [ s=. x+y [ t=. x-y' +'- (%= * ) +' eq2 '(t%s)= s*t [ s=. x+y [ t=. x-y' + +'(20-~]) * +' eq2 ' s * t [ s=. y-20 [ t=. x+y' +'(20-~]) ([ *12-]) +' eq2 ' s *12-t [ s=. y-20 [ t=. x+y' +'(20-~]) (([:*:[)* ]) +' eq2 '(*:s)* t [ s=. y-20 [ t=. x+y' +'(20-~]) (([:*:[)*12-]) +' eq2 '(*:s)*12-t [ s=. y-20 [ t=. x+y' + +'9:' eq 't=.9' +'99"_' eq 't=. 99' +'_99 ". ]' eq '(t=._99)".y' +'[: {: _99 (0,[~:".) ]' eq '{:0,nn~:(nn=._99)". y' +'3 + 4 * ]' eq '3+4*y' +'13 + 14 * ]' eq '13+14*y' +'''ABC'' {~ ''abc'' i. ]' eq '(''abc'' i. y){''ABC''' +'+' eq 'y+x' +'7 + ]' eq 'y+7' +'+ - *' eq '(x+y)-(y*x)' +'17 < ]' eq 'y>17' +'% * [: -: +' eq '(-:x+y)*x%y' +'3 + *:' eq '3+t [ t=. *:y' +'[: ((0 < ]) # ]) expensive' eq '(t>0)#t=. expensive y' +'* (<. - >.) %' eq '(s<.t)-s>.t [ s=. x*y [ t=. x%y' +'[: ((''d'' = 4 {"1 [: > 4 {"1 ]) # ]) 1!:0' eq '(''d''=4{"1 >4{"1 t)#t=. 1!:0 y' + +isnum=: 13 : '{:0,nn~:(nn=._99)".y' +'[: {: (_99) (0 , [ ~: ".) ]' -: 5!:5 <'isnum' +0 = isnum 'abc' +1 = isnum '1.234e7' + +isnum=: 13 : '{:0,nn~:(nn=._1)".y' +'[: {: (_1) (0 , [ ~: ".) ]' -: 5!:5 <'isnum' +0 = isnum 'abc' +1 = isnum '1.234e7' + + +4!:55 ;:'a ar eq eq1 eq12 eq2 eqx isnum' + +
new file mode 100644 --- /dev/null +++ b/test/g311.ijs @@ -0,0 +1,14 @@ +NB. :. ------------------------------------------------------------------ + +f =. + :. - +g =. - :. + +(f b. _1) -: 5!:5 <'g' + +'domain error' -: ex '3 4 :. ''+''' +'domain error' -: ex '3 4 :. +' +'domain error' -: ex '* :. ''+/''' + + +4!:55 ;:'f g' + +
new file mode 100644 --- /dev/null +++ b/test/g312.ijs @@ -0,0 +1,24 @@ +NB. :: ------------------------------------------------------------------ + +f =. o. :: ('err'"0) + +(o.y) -: f y=._20+?4 5$50 +(4 5 3$'err') -: f y=.(?4 5$256){a. + +(1 o.y) -: 1 f y=.0.1*_10+?4 5$20 +(4 5 3$'err') -: 1 f y=.(?4 5$256){a. + +g =. 3&+ :: ('err'"_) + +(3+y) -: g y=._20+?4 5$50 +'err' -: g y=.(?4 5$256){a. + +'domain error' -: ex '+ :: 0 ' +'domain error' -: ex '+ :: 1 ' +'domain error' -: ex '+ :: 0 0 ' +'domain error' -: ex '+ :: ''a'' ' +'domain error' -: ex '+ :: (<0) ' + +4!:55 ;:'f g y' + +
new file mode 100644 --- /dev/null +++ b/test/g320.ijs @@ -0,0 +1,320 @@ +NB. ,y ------------------------------------------------------------------ + +t -: ,(i. 2 3 4){t=.?24$2 +(|.t) -: ,(i.-2 3 4){t=.?24$2 + +(i.24) -: ,i. 2 3 4 +(|.i.24) -: ,i.-2 3 4 + +t -: ,(i. 2 3 4){t=.o._50+?24$1232 +(|.t) -: ,(i.-2 3 4){t=.o._50+?24$2123 + +t -: ,(i. 2 3 4){t=.j./_50+?2 24$1232 +(|.t) -: ,(i.-2 3 4){t=.j./_50+?2 24$2123 + +t -: ,(i. 2 3 4){t=.24$3 4;;:'j./_50+?2 24$123 2' +(|.t) -: ,(i.-2 3 4){t=.24$5j6;;:'j./_50+?2 24$2 123' + +0 = #,0 3 2 3$0 1 +0 = #,0 3 4 5$a. +0 = #,i.2 3 4 0 +0 = #,o.i.2 3 4 0 +0 = #,0j1*i.2 3 0 4 +0 = #, 2 0 2 $<0 + +1 = #,0 +1 = #,'a' +1 = #,9 +1 = #,3.4 +1 = #,3j4 +1 = #,<123 + + +NB. ,"r y --------------------------------------------------------------- + +([ -: ,"1) ?4 13$1e8 +(, -: ,"2) ?4 13$1e8 +(,"0 x) -: (($x),1)$,x=.o.?4 13$1e8 +(,"_1 -: ,"2) (?4 7 11$#x){x=.'amelioration delicatessen' +(,"2 x) -: 4 77$,x=.?4 7 11$2 + +(i.0 24 ) -: ,"3 i.0 2 3 4 +(i.2 3 0) -: ,"_2 i.2 3 5 7 11 0 + +'limit error' -: ,"2 etx (>IF64{0 2e9 2;0 5e18 2)$9 + + +NB. x,y ----------------------------------------------------------------- + +NB. atom-atom +0 1 -: 0,1 +'ab' -: 'a','b' +3 4 -: 3,4 +1 _4.5 -: 1,_4.5 +3 4j5 -: 3,4j5 + +NB. atom-list +0 1 1 0 0 -: 0, 1 1 0 0 +1 1 0 0 0 -: 0,~1 1 0 0 +'abcde' -: 'abcd', 'e' +'eabcd' -: 'abcd',~'e' +3 4 7 5 6 -: 3, 4 7 5 6 +4 7 5 6 3 -: 3,~4 7 5 6 +3 4 7.5 6 8 -: 3, 4 7.5 6 8 +4 7.5 6 8 3 -: 3,~4 7.5 6 8 +3 4 7j5 6 8 -: 3 4 7j5, 6 8 +6 8 3 4 7j5 -: 3 4 7j5,~6 8 + +NB. atom-array +(5 2$9 9,i.8) -: 9, i.4 2 +(5 2$(i.8),9 9) -: 9,~i.4 2 + +NB. atom-empty +(,' ') -: ' ','' +5 0 -: $ ' ',4 0 $'a' +5 0 3 -: $ ' ',4 0 3$'a' + +NB. list-list +0 1 1 0 0 -: 0 1 1,0 0 +'abcde' -: 'ab','cde' +3 4 7 5 6 -: 3 4,7 5 6 +3 4 7.5 6 8 -: 3 4 7.5,6 8 +3 4 7j5 6 8 -: 3 4,7j5 6 8 + +NB. list-array +(9 10 11, 4 3{.i.4 2) -: 9 10 11, i.4 2 +(9 10 11,~4 3{.i.4 2) -: 9 10 11,~i.4 2 +(5 2$0 0, i.8) -: '' , i.4 2 +(5 2$(i.8),0 0) -: ($0),~i.4 2 + +NB. numeric +x=.i.2 6 +t=.i.4 3 2 +5 3 6 -: $x,t +5 3 6 -: $t,x +(((}.$t)$1), t) -: 1, t +(((}.$t)$1),~t) -: 1,~t +((1 3 2{.,:,:99 13), t) -: 99 13, t +((1 3 2{.,:,:99 13),~t) -: 99 13,~t +(1 0 0+$t) -: $(|.2{t), t +(1 0 0+$t) -: $(|.2{t),~t +(2 1 1*$t) -: $(|.t), t +(2 1 1*$t) -: $(|.t),~t + +(3 6$(6$0), ,x) -: ($0), x +(3 6$(6$0),~,x) -: ($0),~x +(3 6$(6$0), ,x) -: '', x +(3 6$(6$0),~,x) -: '',~x +(3 6$(6$0), ,x) -: (0$<''), x +(3 6$(6$0),~,x) -: (0$<''),~x + +NB. literal +x=.a.{~97+i.2 6 +t=.a.{~97+i.4 3 2 +5 3 6 -: $x,t +5 3 6 -: $t,x +(((}.$t)$'a'), t) -: 'a', t +(((}.$t)$'a'),~t) -: 'a',~t +((1 3 2{.,:,:'*&'), t) -: '*&', t +((1 3 2{.,:,:'*&'),~t) -: '*&',~t +(1 0 0+$t) -: $(|.2{t), t +(1 0 0+$t) -: $(|.2{t),~t +(2 1 1*$t) -: $(|.t), t +(2 1 1*$t) -: $(|.t),~t + +(3 6$(6$' '), ,x) -: ($0), x +(3 6$(6$' '),~,x) -: ($0),~x +(3 6$(6$' '), ,x) -: '', x +(3 6$(6$' '),~,x) -: '',~x +(3 6$(6$' '), ,x) -: (0$<''), x +(3 6$(6$' '),~,x) -: (0$<''),~x + +NB. boxed +x=.2 6$;:'(2 1 1*$t) -: $(|.t),~t' +t=.4 3 2$;:'((a.{~66+i.3 2),~(1,$t)$,t) -: (a.{~66+i.3 2),~t' +5 3 6 -: $x,t +5 3 6 -: $t,x +(((}.$t)$<i.8), t) -: (<i.8), t +(((}.$t)$<i.8),~t) -: (<i.8),~t +((1 3 2{.,:,:9;10 11), t) -: (9;10 11), t +((1 3 2{.,:,:9;10 11),~t) -: (9;10 11),~t +(1 0 0+$t) -: $(|.2{t), t +(1 0 0+$t) -: $(|.2{t),~t +(2 1 1*$t) -: $(|.t), t +(2 1 1*$t) -: $(|.t),~t + +(3 6$(6$<''), ,x) -: ($0), x +(3 6$(6$<''),~,x) -: ($0),~x +(3 6$(6$<''), ,x) -: '', x +(3 6$(6$<''),~,x) -: '',~x +(3 6$(6$<''), ,x) -: (0$<''), x +(3 6$(6$<''),~,x) -: (0$<''),~x + +x=.?31 2$1e5 [ y=.?1 1$1e5 +x -: }:x,y +x -: }.y,x + +x=.a.{~?31 2$#a. [ y=.a.{~?1 1$#a. +x -: }:x,y +x -: }.y,x + +'domain error' -: 3 4 , etx 'abc' +'domain error' -: 3 4 ,~etx 'abc' +'domain error' -: 'ab', etx 'a';3 +'domain error' -: 'ab',~etx 'a';3 +'domain error' -: 3 4 , etx 'a';3 +'domain error' -: 3 4 ,~etx 'a';3 + + +NB. x,y empty and fills ------------------------------------------------- + +(3 5 2 4{.' ') -: (3 2 0$''), 2 5 0 4$'' +(3 5 2 4{.' ') -: (3 2 0$''),~2 5 0 4$'' +(3 5 2 0{.' ') -: (3 2 0$''), 2 5 0 0$'' +(3 5 2 0{.' ') -: (3 2 0$''),~2 5 0 0$'' + +(3 5 2 4{.a:) -: (3 2 0$a:), 2 5 0 4$a: +(3 5 2 4{.a:) -: (3 2 0$a:),~2 5 0 4$a: +(3 5 2 0{.a:) -: (3 2 0$a:), 2 5 0 0$a: +(3 5 2 0{.a:) -: (3 2 0$a:),~2 5 0 0$a: + +(3 5 2 4{.0) -: (3 2 0$0), 2 5 0 4$0 +(3 5 2 4{.0) -: (3 2 0$0),~2 5 0 4$0 +(3 5 2 0{.0) -: (3 2 0$0), 2 5 0 0$0 +(3 5 2 0{.0) -: (3 2 0$0),~2 5 0 0$0 + +(3 5 2 4{.0) -: (3 2 0$0), 2 5 0 4$3.4 +(3 5 2 4{.0) -: (3 2 0$0), 2 5 0 4$3j4 +(3 5 2 4{.0) -: (3 2 0$0), 2 5 0 4$3x +(3 5 2 4{.0) -: (3 2 0$0), 2 5 0 4$3r4 + +(x,~ 4$99 99, 4$ 0) -: 99 99 , x=.i.2 4 +(x,~ 4$99 99, 4$ 1) -: 99 99 ,!.1 x=.i.2 4 +(x,~ 4$99 99, 4$100) -: 99 99 ,!.100 x=.i.2 4 +(x,~ 4$99 99, 4$3.5) -: 99 99 ,!.3.5 x=.i.2 4 +(x,~ 4$99 99, 4$3j5) -: 99 99 ,!.3j5 x=.i.2 4 + +(x,~3 4$99 99,12$ 0) -: 99 99 , x=.i.2 3 4 +(x,~3 4$99 99,12$ 1) -: 99 99 ,!.1 x=.i.2 3 4 +(x,~3 4$99 99,12$100) -: 99 99 ,!.100 x=.i.2 3 4 +(x,~3 4$99 99,12$3.5) -: 99 99 ,!.3.5 x=.i.2 3 4 +(x,~3 4$99 99,12$3j5) -: 99 99 ,!.3j5 x=.i.2 3 4 + +(x, 4$99 99, 4$ 0) -: 99 99 , ~x=.i.2 4 +(x, 4$99 99, 4$ 1) -: 99 99 ,!.1 ~x=.i.2 4 +(x, 4$99 99, 4$100) -: 99 99 ,!.100~x=.i.2 4 +(x, 4$99 99, 4$3.5) -: 99 99 ,!.3.5~x=.i.2 4 +(x, 4$99 99, 4$3j5) -: 99 99 ,!.3j5~x=.i.2 4 + +(x, 3 4$99 99,12$ 0) -: 99 99 , ~x=.i.2 3 4 +(x, 3 4$99 99,12$ 1) -: 99 99 ,!.1 ~x=.i.2 3 4 +(x, 3 4$99 99,12$100) -: 99 99 ,!.100~x=.i.2 3 4 +(x, 3 4$99 99,12$3.5) -: 99 99 ,!.3.5~x=.i.2 3 4 +(x, 3 4$99 99,12$3j5) -: 99 99 ,!.3j5~x=.i.2 3 4 + +(x,~ 4$'ab', 4$' ') -: 'ab' , x=.2 4$'short shrift' +(x,~ 4$'ab', 4$'q') -: 'ab' ,!.'q' x +(x,~3 4$'ab', 12$' ') -: 'ab' , x=.2 3 4$'hey nonny nonny' +(x,~3 4$'ab', 12$'q') -: 'ab' ,!.'q' x + +(x, 4$'ab', 4$' ') -: 'ab' , ~x=.2 4$'Esperanto' +(x, 4$'ab', 4$'q') -: 'ab' ,!.'q'~x +(x, 3 4$'ab', 12$' ') -: 'ab' , ~x=.2 3 4$'Vandermonde matrices' +(x, 3 4$'ab', 12$'q') -: 'ab' ,!.'q'~x + +(x,~ 4$(3;4), 4$a: ) -: (3;4) , x=.2 4$;:'how now Charlie Brown?' +(x,~ 4$(3;4), 4$<9 ) -: (3;4) ,!.(<9)x +(x,~3 4$(3;4),12$a: ) -: (3;4) , x=.2 3 4$;:'sigh no more a-shore x' +(x,~3 4$(3;4),12$<9 ) -: (3;4) ,!.(<9)x + +(x, 4$(3;4), 4$a: ) -: (3;4) , ~x=.2 4$;:'how now Charlie Brown?' +(x, 4$(3;4), 4$<9 ) -: (3;4) ,!.(<9)~x +(x, 3 4$(3;4),12$a: ) -: (3;4) , ~x=.2 3 4$;:'sigh no more a-shore x' +(x, 3 4$(3;4),12$<9 ) -: (3;4) ,!.(<9)~x + +'domain error' -: 99 99 ,!.'a' etx 2 3 4$123 +'domain error' -: 99 99 ,!.(<0)etx 2 3 4$123 +'domain error' -: 'ab' ,!.12 etx 2 3 4$'x' +'domain error' -: 'ab' ,!.(<0)etx 2 3 4$'x' +'domain error' -: (3;4) ,!.'a' etx 2 3 4$<123 +'domain error' -: (3;4) ,!.12 etx 2 3 4$<123 + + +NB. x,"r y -------------------------------------------------------------- + +cat=: 4 : 'x,y' + +'A' (,"1 -: cat"1)&> (3,&.>i.10)$&.><'satrap feudal futile' +'A' (,"1 -: cat"1)&>~(3,&.>i.10)$&.><'supermarine' +((i.10)$&.><'ABCDEFGHI') (,"1 -: cat"1)&>/ (3,&.>i.10)$&.><'oxymoron' +((i.10)$&.><'ABCDEFGHI') (,"1 -: cat"1)&>/~(3,&.>i.10)$&.><'suzerainty' +(<'ABC') (,"_1 -: cat"_1)&> (3,&.>i.10)$&.><'inescapable culpable' +(<'ABC') (,"_1 -: cat"_1)&>~(3,&.>i.10)$&.><'inescapable culpable' + +12345 (,"0 -: cat"0) ?3 5 7$1e6 +12345 (,"0 -: cat"0)~?3 5 7$1e6 +12345 (,"1 -: cat"1) ?3 5 7$1e6 +12345 (,"1 -: cat"1)~?3 5 7$1e6 +12345 (,"2 -: cat"2) ?3 5 7$1e6 +12345 (,"2 -: cat"2)~?3 5 7$1e6 +12345 (,"3 -: cat"3) ?3 5 7$1e6 +12345 (,"3 -: cat"3)~?3 5 7$1e6 + +123.4 5 6 (,"0 -: cat"0) o.?3 3 3$1e6 +123.4 5 6 (,"0 -: cat"0)~o.?3 3 3$1e6 +123.4 5 6 (,"1 -: cat"1) o.?3 3 3$1e6 +123.4 5 6 (,"1 -: cat"1)~o.?3 3 3$1e6 +123.4 5 6 (,"2 -: cat"2) o.?3 3 3$1e6 +123.4 5 6 (,"2 -: cat"2)~o.?3 3 3$1e6 +123.4 5 6 (,"3 -: cat"3) o.?3 3 3$1e6 +123.4 5 6 (,"3 -: cat"3)~o.?3 3 3$1e6 + +r=: <"1 ] 4 4#:i.16 +f=: 3 : 'xx (,"y -: cat"y) yy' + +f&>r [ xx=: ? 2 3 4$2 [ yy=: ? 2 3 4$2 +f&>r [ xx=:a.{~? 2 3 4$256 [ yy=:a.{~? 2 3 4$256 +f&>r [ xx=: ? 2 3 4$100 [ yy=: ? 2 3 4$100 +f&>r [ xx=:o. ? 2 3 4$100 [ yy=:o. ? 2 3 4$100 +f&>r [ xx=:j./ ?2 2 3 4$100 [ yy=:j./ ?2 2 3 4$100 + +f&>r [ xx=: ? 2 3 $2 [ yy=: ? 2 3 4$2 +f&>r [ xx=:a.{~? 2 3 $256 [ yy=:a.{~? 2 3 4$256 +f&>r [ xx=: ? 2 3 $100 [ yy=: ? 2 3 4$100 +f&>r [ xx=:o. ? 2 3 $100 [ yy=:o. ? 2 3 4$100 +f&>r [ xx=:j./ ?2 2 3 $100 [ yy=:j./ ?2 2 3 4$100 + +f&>r [ xx=: ? 2 3 4$2 [ yy=: ? 2 3 $2 +f&>r [ xx=:a.{~? 2 3 4$256 [ yy=:a.{~? 2 3 $256 +f&>r [ xx=: ? 2 3 4$100 [ yy=: ? 2 3 $100 +f&>r [ xx=:o. ? 2 3 4$100 [ yy=:o. ? 2 3 $100 +f&>r [ xx=:j./ ?2 2 3 4$100 [ yy=:j./ ?2 2 3 $100 + +f&>r [ xx=:?2 [ yy=: ? 2 3 4$2 +f&>r [ xx=:'A' [ yy=:a.{~? 2 3 4$256 +f&>r [ xx=:?100 [ yy=: ? 2 3 4$100 +f&>r [ xx=:o.?100 [ yy=:o. ? 2 3 4$100 +f&>r [ xx=:j./?2$100 [ yy=:j./ ?2 2 3 4$100 + +f&>r [ xx=: ? 2 3 4$2 [ yy=:?2 +f&>r [ xx=:a.{~? 2 3 4$256 [ yy=:'B' +f&>r [ xx=: ? 2 3 4$100 [ yy=:?100 +f&>r [ xx=:o. ? 2 3 4$100 [ yy=:o.?100 +f&>r [ xx=:j./ ?2 2 3 4$100 [ yy=:j./?2$100 + +3.5 (,"0 1 -: cat"0 1) i.5 0 +3.5 (,"1 0 -: cat"1 0)~i.5 0 +3.5 (,"0 2 -: cat"0 2) i.3 0 5 +3.5 (,"2 0 -: cat"2 0)~i.3 0 5 + +(i.0 10) -: (i.0 3),"1 i.0 7 +(i.0 8 3) -: (i.0 3),"_1 i.0 7 3 + +n=:11 +test=. 4 : '((n,x)$''x'') (,"1 -: cat"1) (n,y)$''y''' + +test"0/~i.20 + +4!:55 ;:'cat f n r t test x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g320ip.ijs @@ -0,0 +1,133 @@ +NB. x,y Append in place ------------------------------------------------- + +f=: 3 : 0 + z=. i.0 + for_i. i.y do. + z=. z,i + end. +) + +(i. -: f)"0 ?2 10$2e3 + +f1=: 3 : 0 + z=. i.0 0 + for_i. i.y do. + z=. z,i. i + end. +) + +(i."0@i. -: f1)"0 ?2 10$100 + +f2=: 3 : 0 + z=. '' + for_x. y do. + z=. z,x + end. +) + +(] -: f2) 'only Hugh can prevent florist friars' +(] -: f2) ?1000$1e6 + +global=: i.7 +f3=: 3 : 'global=. global,y' +((i.7),999 888) -: f3 999 888 +NB. global -: i.7 + +f4=: 3 : 0 + a =: 4 27$'a' + a1=: 4 27$'a' + b =: 3 17$(10$'b'),'1234567' + a =: a,b + assert. a -: a1,b + 1 +) + +f4 '' + +global=: ;: 'zero one two three four' + +f5=: 3 : 0 + txt=. 1 2 { global + txt=. txt ,each 'x' +) + +('onex';'twox') -: f5 '' +global -: ;: 'zero one two three four' + +f6=: 3 : 0 + g=. ;: 'zero one two three four' + t=. 1 2 { g + t=. t ,each 'x' + assert. t -: ;:'onex twox' + assert. g -: ;: 'zero one two three four' + 1 +) + +f6 '' + +f7=: 3 : 0 + g=. ;: 'zero one two three four' + t=. 1 2 { g + t=. t ,&.> 'x' + assert. t -: ;:'onex twox' + assert. g -: ;: 'zero one two three four' + 1 +) + +f7 '' + +global=: '01234' + +f8=: 3 : 0 + a=. y + a=. a,'x' +) + +'01234x' -: f8 global +global -: '01234' + +'01234x' -: f8 '01234' + +f9=: 3 : 0 + a=. '01234' + a=. a,'x' +) + +'01234x' -: f9 '' + +test=: 4 : 0 + q=. x, y + x=. x, y + assert. q -: x + 1 +) + +5 6 test 2 3 4 +5 6 test 2 3 4 +(i.4 3) test 10 20 30 +5 6 7 8 test 0 1 0 +5 6 7.8 test 0 1 0 +5 6 7.8 test 0 3 4 +5 6 7.8 test 0 3.4 +5 6 7j8 test 0 1 0 +5 6 7j8 test 0 3 4 +5 6 7j8 test 0 3.4 +5 6 7j8 test 0 3j4 + +(<5 6 ) test&>~ (i.10 25)$&.> <2 3 4 +(<'12') test&>~ (i.10 25)$&.> <'abc' + +testa=: 4 : 0 + (a.{~x ?@$ 256) test a.{~y ?@$ 256 + ( x ?@$ 2e9) test y ?@$ 2e9 + ( x ?@$ 0 ) test y ?@$ 0 +) + +67 testa&> '';,&.> 3 5 7 11 13 67 71 +(<4 5 ) testa&> '';3;5;7 +(<6 4 5) testa&> '';3;5;7; 4 5;2 3;4 3;2 5; 2 3 4;2 4 5;2 7 + + +4!:55 ;:'a a1 b f f1 f2 f3 f4 f5 f6 f7 f8 f9 global local test testa' + +
new file mode 100644 --- /dev/null +++ b/test/g320ipt.ijs @@ -0,0 +1,44 @@ +NB. x,y Append in place timing tests ------------------------------------ + +ss =: +/ @: *: +rsq =: [: -. ss@(- +/ % #)@[ %~ ss@:- + +f=: 3 : 0 + z=. i.0 + for_i. i.y do. + z=. z,i + end. +) + +(i. -: f)"0 ] 2 10?@$2e3 + +x =: 800 * 2^i.8 +y =: timer 'f ',"1 ":,.x +y1=: (1,.x) +/ .*y %. 1,.x +threshold < y rsq y1 + +load 'jmf' +createjmf_jmf_ 'mmf';4e6 +map_jmf_ 'q';'mmf' + +g=: 3 : 0 + q=: i.0 + for_i. i.y do. + q=: q,i + end. +) + +(i. -: g)"0 ] 2 10?@$2e3 + +x =: 800 * 2^i.8 +y =: timer 'g ',"1 ":,.x +y1=: (1,.x) +/ .*y %. 1,.x +threshold < y rsq y1 + +0 = unmap_jmf_ 'q' +1!:55 <'mmf' + + +4!:55 ;:'f g q rsq ss x y y1' + +
new file mode 100644 --- /dev/null +++ b/test/g321.ijs @@ -0,0 +1,205 @@ +NB. ,.y ----------------------------------------------------------------- + +(1 1$x) -: ,.x=.0 +(1 1$x) -: ,.x=.'a' +(1 1$x) -: ,.x=.123450 +(1 1$x) -: ,.x=.3.145 +(1 1$x) -: ,.x=.1.23e18j5.67e_89 +(1 1$x) -: ,.x=.<i.10 + +0 1 -: $,.'' +1 0 -: $,.1 4 5 0$9 +2 0 -: $,.2 4 0 5$9 +0 12 -: $,.i.0 3 4 +0 0 -: $,.i.0 2 3 0 +0 0 -: $,.0 0$<'' + +table =: (# , */@}.@$) $ , + +(table x) -: ,.x=.i.?4$10 +(table x) -: ,.x=.a.{~256|i.?4$10 + + +NB. ,."r y -------------------------------------------------------------- + +table =: (# , */@}.@$) $ , + +(,."0 -: table"0) ?2 3 4 5$1e8 +(,."1 -: table"1) ?2 3 4 5$1e8 +(,."2 -: table"2) ?2 3 4 5$1e8 +(,."3 -: table"3) ?2 3 4 5$1e8 + +(,."0 -: table"0) (?2 3 4 5$#x){x=.'metaphoric meteoric' +(,."_1 -: table"_1) (?2 3 4 5$#x){x=.'imitative harmony' +(,."_2 -: table"_2) (?2 3 4 5$#x){x=.'personification' +(,."_3 -: table"_3) (?2 3 4 5$#x){x=.'sui generis' + +(,."0 -: table"0) i.i. 5 +(,."0 -: table"0) i.i._5 +(,."1 -: table"1) i.i. 5 +(,."1 -: table"1) i.i._5 +(,."2 -: table"2) i.i. 5 +(,."2 -: table"2) i.i._5 + + +NB. x,.y ---------------------------------------------------------------- + +overr =: ,"_1 +f =: ,. -: overr + +3 4 -: 3,.4 +(3 2$3 4 3 5 3 6) -: 3,.4 5 6 +(2 4$0 1 2 9 3 4 5 9) -: (i.2 3),.9 +(2 4$9j4 0 1 2 5j6 3 4 5) -: 9j4 5j6,.i.2 3 + +4 f i.0 +4 f~i.0 +4 f i.0 9 +4 f~i.0 9 +4 f i.0 9 2 +4 f~i.0 9 2 +4 f i.9 0 +4 f~i.9 0 +4 f i.9 0 2 +4 f~i.9 0 2 + +NB. Boolean +(?2) f ?2 +(?2) f ?12$2 +(?2) f ?3 10$2 +(?2) f ?7 2 10$2 +(?11$2) f ?2 +(?11$2) f ?11$2 +(?11$2) f ?11 1$2 +(?11$2) f ?11 3 2$2 +(?7 3$2) f ?2 +(?7 3$2) f ?7$2 +(?7 3$2) f ?7 9$2 +(?7 3$2) f ?7 8 9$2 +(?6 1 3$2) f ?2 +(?6 1 3$2) f ?6$2 +(?6 1 3$2) f ?6 9$2 +(?6 1 3$2) f ?6 4 9$2 + +NB. literal +(a.{~?#a.) f a.{~?#a. +(a.{~?#a.) f a.{~?12$#a. +(a.{~?#a.) f a.{~?3 10$#a. +(a.{~?#a.) f a.{~?7 2 10$#a. +(a.{~?11$#a.) f a.{~?#a. +(a.{~?11$#a.) f a.{~?11$#a. +(a.{~?11$#a.) f a.{~?11 1$#a. +(a.{~?11$#a.) f a.{~?11 3 2$#a. +(a.{~?7 3$#a.) f a.{~?#a. +(a.{~?7 3$#a.) f a.{~?7$#a. +(a.{~?7 3$#a.) f a.{~?7 9$#a. +(a.{~?7 3$#a.) f a.{~?7 8 9$#a. +(a.{~?6 1 3$#a.) f a.{~?#a. +(a.{~?6 1 3$#a.) f a.{~?6$#a. +(a.{~?6 1 3$#a.) f a.{~?6 9$#a. +(a.{~?6 1 3$#a.) f a.{~?6 4 9$#a. + +NB. integer +(?2222) f ?2 +(?2222) f ?12$1234 +(?2222) f ?3 10$2e9 +(?2222) f ?7 2 10$2e7 +(?11$2e6) f ?2e7 +(?11$2e6) f ?11$77 +(?11$2e6) f ?11 1$882 +(?11$2e6) f ?11 3 2$2 +(?7 3$1234) f ?243 +(?7 3$1234) f ?7$2 +(?7 3$1234) f ?7 9$2123 +(?7 3$1234) f ?7 8 9$2 +(?6 1 3$2e3) f ?2123 +(?6 1 3$2e3) f ?6$2123 +(?6 1 3$2e3) f ?6 9$2113 12 +(?6 1 3$2e3) f ?6 4 9$2123 + +NB. floating point +(o.?25) f ?2 +(o.?25) f ^?12$10 +(o.?25) f ?3 10$2 123 +(o.?25) f o.?7 2 10$2123 +(^?11$20) f ?2123 +(^?11$20) f o.?11$2123 +(^?11$20) f o.?11 1$2123 +(^?11$20) f ?11 3 2$2 +(o.?7 3$234) f o.?2e3 +(o.?7 3$234) f o.?7$2e3 +(o.?7 3$234) f o.?7 9$2e3 +(o.?7 3$234) f o.?7 8 9$2e3 +(o.?6 1 3$22) f ^.>:?20 +(o.?6 1 3$22) f ^.>:?6$20 +(o.?6 1 3$22) f ^.>:?6 9$20 +(o.?6 1 3$22) f ^.>:?6 4 9$20 + +NB. complex +(j.?25) f ?2 +(j.?25) f ?12$100 +(j.?25) f o.?3 10$2123 +(j.?25) f j.?7 2 10$2123 +(r.?11$20) f ?2 +(r.?11$20) f ?11$2123 +(r.?11$20) f o.?11 1$2123 +(r.?11$20) f r.?11 3 2$2 +(j.?7 3$234) f ?2 +(j.?7 3$234) f ?7$2e3 +(j.?7 3$234) f o.?7 9$2e3 +(j.?7 3$234) f j.?7 8 9$2e3 +(r.?6 1 3$22) f r.?20 +(r.?6 1 3$22) f r.?6$20 +(r.?6 1 3$22) f r.?6 9$20 +(r.?6 1 3$22) f r.?6 4 9$20 + +NB. boxed +(<?2e9) f t{~? #t=.'asdf';3 4 +(<?2e9) f t{~?12 $#t=.2;3;;:'?12$2;:(<?2e9) f t{~?3 10$#t=.2;' +(<?2e9) f t{~?3 10 $#t=.2;;:'(<?2e9) f t{~?3 10$#t=.2;' +(<?2e9) f t{~?7 2 10$#t=.<"0 i.123 +(t{~?12$#t) f t{~? #t=.'asdf';3 4;;:'Cogito, ergo sum.' +(t{~?12$#t) f t{~?12 $#t=.2;3;;:'?12$2;:(<?2e9) f t{~?3 10$#t=.2;' +(t{~?12$#t) f t{~?12 10 $#t=.2;;:'(<?2e9) f t{~?3 10$#t=.2;' +(t{~?12$#t) f t{~?12 2 10$#t=.<"0 i.123 +(<"0?7 2$999) f t{~? #t=.'asdf';3 4;;:'Cogito, ergo sum.' +(<"0?7 2$999) f t{~?7 $#t=.2;3;;:'?12$2;:(<?2e9) f t{~?3 10$#t=.2;' +(<"0?7 2$999) f t{~?7 10 $#t=.2;;:'(<?2e9) f t{~?3 10$#t=.2;' +(<"0?7 2$999) f t{~?7 2 10$#t=.<"0 i.123 +(t{~?13 2 2$#t) f t{~? #t=.'asdf';3 4;;:'Cogito, ergo sum.' +(t{~?13 2 2$#t) f t{~?13 $#t=.2;3;;:'?12$2;:(<?2e9) f t{~?3 10$#t=.2;' +(t{~?13 2 2$#t) f t{~?13 3 $#t=.2;;:'(<?2e9) f t{~?3 10$#t=.2;' +(t{~?13 2 2$#t) f t{~?13 2 3$#t=.<"0 ?123$11231 + +'domain error' -: 1 2 3 ,. etx 'abc' +'domain error' -: 1 2 3 ,. etx 2;3;4 +'domain error' -: (2;3;4) ,. etx 'abc' +'domain error' -: (2;3;4) ,. etx 2 3 4 +'domain error' -: 'abc' ,. etx 1 2 3 +'domain error' -: 'abc' ,. etx 2;3;4 + +'length error' -: 'abc' ,. etx 'sui generis' +'length error' -: (,1) ,. etx 3 4 + + +NB. > ,.&.>/y ----------------------------------------------------------- + +f=: 4 : 0 + d=: x {~ (10,y) ?@$ #x + assert. d -: > ,.&.>/ e=: ('';1,0=(y-1) ?@$ 5) <;.1 d + 1 +) + +0 1 f"_ 0 ] 100+i.12 +a. f"_ 0 ] 100+i.12 +(a.{~1000 2 ?@$ 256) f"_ 0 ] 100+i.12 +(u: i.1e3) f"_ 0 ] 100+i.12 +(1000 ?@$ 1e4) f"_ 0 ] 100+i.12 +(1000 ?@$ 0 ) f"_ 0 ] 100+i.12 +(j./ 2 1000 ?@$ 0) f"_ 0 ] 100+i.12 +(<"0 ] 1000 ?@$ 1e5) f"_ 0 ] 100+i.12 + + +4!:55 ;:'d e f overr t table x' + +
new file mode 100644 --- /dev/null +++ b/test/g321t.ijs @@ -0,0 +1,21 @@ +NB. ,.&.>/y timing tests ------------------------------------------------ + +f =: >@(,.&.>/) +ss =: +/ @: *: +rsq=: [: -. ss@(- +/ % #)@[ %~ ss@:- + +([ -: f@:(<"1)@|:) x=: 10 17?@$2 +([ -: f@:(<"1)@|:) x=: (10 17?@$#a.){a. +([ -: f@:(<"1)@|:) x=: 10 17?@$2e9 +([ -: f@:(<"1)@|:) x=:j./2 10 17?@$2e9 +([ -: f@:(<"1)@|:) x=: (10 17?@$#t){t=:;:'Sui generis ec cle si as tic' + +(|:>34$<x) -: f 17$<x,.x=:(10?@$#a.){a. + +y=: ". 'timer ''f t'' [ t=: (<12?@$1e9) $~ ',"1 ": ,. x=: 11000*1+i.9 +threshold < y rsq y (] +/ .* %.) x^/0 1 + + +4!:55 ;:'f rsq ss t x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g322.ijs @@ -0,0 +1,109 @@ +NB. ,:y ----------------------------------------------------------------- + +(,t)-:,:t=:1 +(,t)-:,:t=:'a' +(,t)-:,:t=:4 +(,t)-:,:t=:3.45 +(,t)-:,:t=:1j3 +(,t)-:,:t=:<'abc' + +((1,$t)$,t) -: ,:t=:(?(?7)$7)$1 0 1 +((1,$t)$,t) -: ,:t=:(?(?7)$7)$'abc' +((1,$t)$,t) -: ,:t=:(?(?7)$7)$3 4 5 +((1,$t)$,t) -: ,:t=:(?(?7)$7)$o.i.12 +((1,$t)$,t) -: ,:t=:(?(?7)$7)$^0j1*?5$5 +((1,$t)$,t) -: ,:t=:(?(?7)$7)$'cogito';3 4 + +7 (($,:) -: (>@# <)) ?3 1 4$2 +7 (($,:) -: (>@# <)) a{~?3 1 4$#a=:'astringent bailiwick' +7 (($,:) -: (>@# <)) ?3 4$100 +7 (($,:) -: (>@# <)) <"0?2 3 4$100 + + +NB. ,:"r y -------------------------------------------------------------- + +f =: 3 : ',:y' + +(,:"0 -: f"0) x=:?2 3 4$1e5 +(,:"1 -: f"1) x=:a.{~?2 3 4$#a. +(,:"2 -: f"2) x=:o.?2 3 4$1e5 +(,:"3 -: f"3) x=:(?2 3 4$#y){y=:;:'Cogito, ergo sum. ipso facto 1 2' + + +NB. x,:y ---------------------------------------------------------------- + +f =: ,. -: ,:/ +f 0 1 +f 'ab' +f 3 4 +f 1 _4.5 +f 3 4j5 + +NB. numeric +t=:i.4 3 2 +(1, (1,$t)$,t) -: 1,: t +(1,~(1,$t)$,t) -: 1,:~t +(99 13, (1,$t)$,t) -: 99 13,: t +(99 13,~(1,$t)$,t) -: 99 13,:~t +((|.2{t), (1,$t)$,t) -: (|.2{t),: t +((|.2{t),~(1,$t)$,t) -: (|.2{t),:~t +((|.t), (1,$t)$,t) -: (|.t),: t +((|.t),~(1,$t)$,t) -: (|.t),:~t + +NB. literal +t=:a.{~96+i.4 3 2 +('&', (1,$t)$,t) -: '&',: t +('&',~(1,$t)$,t) -: '&',:~t +('-+', (1,$t)$,t) -: '-+',: t +('-+',~(1,$t)$,t) -: '-+',:~t +((|.2{t), (1,$t)$,t) -: (|.2{t),: t +((|.2{t),~(1,$t)$,t) -: (|.2{t),:~t +((|.t), (1,$t)$,t) -: (|.t),: t +((|.t),~(1,$t)$,t) -: (|.t),:~t + +NB. box +t=:4 3 2$;:'((a.{~66+i.3 2),~(1,$t)$,t) -: (a.{~66+i.3 2),:~t' +((<'&'), (1,$t)$,t) -: (<'&'),: t +((<'&'),~(1,$t)$,t) -: (<'&'),:~t +((2 3;'+'), (1,$t)$,t) -: (2 3;'+'),: t +((2 3;'+'),~(1,$t)$,t) -: (2 3;'+'),:~t +((|.2{t), (1,$t)$,t) -: (|.2{t),: t +((|.2{t),~(1,$t)$,t) -: (|.2{t),:~t +((|.t), (1,$t)$,t) -: (|.t),: t +((|.t),~(1,$t)$,t) -: (|.t),:~t + +'domain error' -: 3 4 ,: etx 'abc' +'domain error' -: 3 4 ,:~etx 'abc' +'domain error' -: 'ab',: etx 'a';3 +'domain error' -: 'ab',:~etx 'a';3 +'domain error' -: 3 4 ,: etx 'a';3 +'domain error' -: 3 4 ,:~etx 'a';3 + + +NB. x,:"r y ------------------------------------------------------------- + +f =: 4 : 'x,:y' + +x=: ?3 4$1e6 +y=: ?3 4$1e6 + +x (,:"0 -: f"0) y +x (,:"1 -: f"1) y +x (,:"1 -: f"1) 0{y +x (,:"2 -: f"2) y +x (,:"0 2 -: f"0 2) y + +lam=: 4 : 'x,:y' +x (,:"1 -: lam"1) y [ x=: ?3$2 [ y=: ?5 4 3$2 +y (,:"1 -: lam"1) x +x (,:"1 -: lam"1) y [ x=: ?3$100 [ y=: ?5 4 3$1e6 +y (,:"1 -: lam"1) x +x (,:"1 -: lam"1) y [ x=: a.{~?3$#a. [ y=: a.{~?5 4 3$#a. +y (,:"1 -: lam"1) x +x (,:"1 -: lam"1) y [ x=: j./?2 3$100 [ y=: j./?2 5 4 3$1e6 +y (,:"1 -: lam"1) x + + +4!:55 ;:'a f lam t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g330.ijs @@ -0,0 +1,133 @@ +NB. ;y ------------------------------------------------------------------ + +maxr =: [: >./ #@$&> +templ =: $&0^:2 @ (1&>.) @ maxr +raze =: (1&#) @ > @ (,&.>/) @ (,<@templ) @ , + +(; -: raze) 1 2 3 4;5 6 7 8;i.3 4 +(; -: raze) (i.3 4);1 2 3 4;5 6 7 8 + +NB. Boolean +(; -: raze) 0 1 0;1 0;0 +(; -: raze) 0 ;1=?3 4$2 +(; -: raze) 0 1;1=?3 4$2 +(; -: raze) <"0 t=:?2 3 4$2 +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t + +NB. literal +(; -: raze) 'abc';'dc';'a' +(; -: raze) 'a' ;3 4$'abc' +(; -: raze) 'ad';3 4$'abc' +(; -: raze) <"0 t=:(?2 3 4 2$#a.){a. +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t + +NB. integer +(; -: raze) 0 1 2;3 4;2 +(; -: raze) 2 ;?3 4$100000 +(; -: raze) 2 3;?3 4$100000 +(; -: raze) <"0 t=:?2 3 4 2$100000 +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t + +NB. floating point +(; -: raze) 1.2 3.4 5.6;_12.6 17;o.1 +(; -: raze) 2.5 ;o.?3 4$100000 +(; -: raze) 2.5 6;o.?3 4$100000 +(; -: raze) <"0 t=:o.?2 3 4 2$100000 +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t + +NB. complex +(; -: raze) 1j2 3j4 5j6;_12j6 17;0j1 +(; -: raze) 2j5 ;^0j1*?3 4$100000 +(; -: raze) 2j5 6;^0j1*?3 4$100000 +(; -: raze) <"0 t=:^0j1*?2 3 4 2$100000 +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t +(; -: raze) 0 1 0; 123 45; 3.4 _5.67e8; 6j7 + +NB. boxed +(; -: raze) (1;'two';'drei');(3 4;3 4$6);<<i.2 3 4 +(; -: raze) (<123) ;<<"0?3 4$100 +(; -: raze) ((<123),<'a');<<"0?3 4$100 +(; -: raze) t=:(?2 3 4 2$#x){x=:<&.>(<"0?30$100),;:'(; -: raz)^0j1*?2 3$10' +(; -: raze) <"0 t +(; -: raze) <"1 t +(; -: raze) <"2 t +(; -: raze) <"3 t +(; -: raze) <"4 t + +($0) -: ;'' +($0) -: ;i.0 4 5 +(,0) -: ;0 +(,0) -: ;<0 +(,'a') -: ;'a' +(,'a') -: ;<'a' +(,9) -: ;9 +(,9) -: ;<9 +(,3.4) -: ;3.4 +(,3.4) -: ;<3.4 +(,3j4) -: ;3j4 +(,3j4) -: ;<3j4 + +x -: ; 10$<x=:i.0 +x -: ; 10$<x=:i.0 2 +x -: ; 10$<x=:i.0 2 3 +x -: ; 10$<x=:i.0 2 3 4 + +(i. (+/x),y) -: ; (x=:?10$10)$&.><i.1,y=:0 +(i. (+/x),y) -: ; (x=:?10$10)$&.><i.1,y=:0 2 +(i. (+/x),y) -: ; (x=:?10$10)$&.><i.1,y=:0 2 3 +(i. (+/x),y) -: ; (x=:?10$10)$&.><i.1,y=:0 2 3 4 + +(; -: raze) (?#x) A. x=:1 2 3;1.2 3;'';0 1;3j4 +(; -: raze) (?#x) A. x +(; -: raze) (?#x) A. x + +(; -: raze) ; (<0 5$<123),<2 3 4$<'a' + +'domain error' -: ; etx 1 2 ; 'abc' +'domain error' -: ; etx 1 2 ;~'abc' +'domain error' -: ; etx 1 2 ; <<'abc' +'domain error' -: ; etx 1 2 ;~<<'abc' +'domain error' -: ; etx 'ab'; <<'a' +'domain error' -: ; etx 'ab';~<<'a' + + +NB. x;y ----------------------------------------------------------------- + +boxed =: e.&32 64@(3!:0) +mt =: 0&e.@$ +link =: <@[ , <`]@.(boxed *. -.@mt)@] + +1 2 (; -: link) 3 4 5 +'' (; -: link) '' +'abc' (; -: link) +&.>i.3 4 +(+&.>i.3 4) (; -: link) 'abc' +'' (; -: link) 0$<'' +(0$<'') (; -: link) '' + +(IF64{1200 2800) > 7!:2 'x;y' [ x=: i.1e4 [ y=: 2e4$'chthonic' + +'domain error' -: ex '>''abc''; 2 3 4 ' +'domain error' -: ex '>''abc'';~2 3 4 ' +'domain error' -: ex '>''abc''; 2;3;4 ' +'domain error' -: ex '>''abc'';~2;3;4 ' +'domain error' -: ex '>2 3 4; 2;3;''1234''' +'domain error' -: ex '>2 3 4;~2;3;''1234''' + +4!:55 ;:'a boxed link maxr mt raze t templ x y' + +
new file mode 100644 --- /dev/null +++ b/test/g330f.ijs @@ -0,0 +1,49 @@ +NB. x ;@:{ y ------------------------------------------------------------ + +f=: 4 : '; x { y' +m=: 179 + +data=: 4 : 0 + select. y + case. 1 do. ?&.> ((?m$11),&.>x{'';'';5;2 3) $&.> 2 + case. 2 do. {&a.&.> ?&.> ((?m$11),&.>x{'';'';5;2 3) $&.> #a. + case. 4 do. ?&.> ((?m$11),&.>x{'';'';5;2 3) $&.> 500 + case. 8 do. o.&.> ?&.> ((?m$11),&.>x{'';'';5;2 3) $&.> 500 + case. 16 do. r.&.> ?&.> ((?m$11),&.>x{'';'';5;2 3) $&.> 500 + end. +) + +test=: 3 : 0 + i=: ?2003$m + b=: ?2003$2 + assert. i (f -: ;@:{) yy=: 1 data y + assert. (+:-:i) (f -: ;@:{) yy + assert. b (f -: ;@:{) yy + assert. i (f -: ;@:{) yy=: 2 data y + assert. (+:-:i) (f -: ;@:{) yy + assert. b (f -: ;@:{) yy + assert. i (f -: ;@:{) yy=: 3 data y + assert. (+:-:i) (f -: ;@:{) yy + assert. b (f -: ;@:{) yy + 1 +) + +test 1 +test 2 +test 4 +test 8 +test 16 + +'domain error' -: (30$'a') ;@:{ etx 2$<'xy' +'domain error' -: (30$<'a') ;@:{ etx 2$<'xy' +'domain error' -: (30$1.5) ;@:{ etx 2$<'xy' +'domain error' -: (30$3j1) ;@:{ etx 2$<'xy' +'domain error' -: (30$1 2) ;@:{ etx 2 3;'abc';4 5 6 7 + +'index error' -: (30$3) ;@:{ etx 2$<'xy' +'index error' -: (71$3 _6) ;@:{ etx 5$<'xy' + + +4!:55 ;:'b data f i m test yy' + +
new file mode 100644 --- /dev/null +++ b/test/g330t.ijs @@ -0,0 +1,18 @@ +NB. ;y timing tests ----------------------------------------------------- + +ss =: +/ @: *: +rsq =: [: -. ss@(- +/ % #)@[ %~ ss@:- +ratio=: >./ % <./ + +a=: ;:'Cogito, ergo sum. boustrophedonic chthonic' +y=: ". '6!:2 ''; t'' [ t=: a $~ ',"1 ": ,. x=: 1000*1+i.9 +threshold < t=: y rsq y (] +/ .* %.) x^/0 1 + +x=:3000$a +y=:(<$0),x +5>ratio t=:100 timer&>';x';';y' + + +4!:55 ;:'a ratio rsq ss t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g331.ijs @@ -0,0 +1,435 @@ +NB. ;.n ----------------------------------------------------------------- + +'domain error' -: ex ' [;.''2''' +'domain error' -: ex ' [;.4' +'domain error' -: ex ' <;.4x' +'domain error' -: ex '+/;.3.4' +'domain error' -: ex ' <;.3j4' +'domain error' -: ex ' <;.3r4' +'domain error' -: ex ' <;.(<2)' + +'rank error' -: ex '<;.1 2' + + +NB. f;.0 ---------------------------------------------------------------- + +a=:0 1 1,:2 2 3 +b=:0 1 1,:2 2 _3 +w=:i.2 3 5 + +(a[;.0 w) -: (1{a){.(0{a)}.w +(b[;.0 w) -: |."1 a[;.0 w +([;.0 w) -: |.|."1|."2 w + +w=:a.{~i.2 3 4 5 +(a[;.0 w) -: (1{a){.(0{a)}.w +( [;.0 w) -: (i.-$w){,w + +a=: 'abcdefghijklmnopqrstuvwxyz' +(|.a) -: [;.0 a +'fghi' -: (,. 5 4) [;.0 a +'ihgf' -: (,. 5 _4) [;.0 a +'stuv' -: (,._5 4) [;.0 a +'vuts' -: (,._5 _4) [;.0 a + +f=: 4 : 0 + (x [;.0 y) -: > x <;.0 y +) + +(,."1 ] 5 4*"1 ] _1^#:i.4) f"2 1 a +(,."1 ] 5 4*"1 ] _1^#:i.4) f"2 1 x=: ?100$1e6 + +(2 2$"1 ] 2 3 4 5*"1 ] _1^#:i.16) f"2 x=: a.{~?10 11$#a. +(2 2$"1 ] 2 3 4 5*"1 ] _1^#:i.16) f"2 x=: ?11 10$1e6 +(,."1 ] 5 4*"1 ] _1^#:i.4) f"2 x=: ?11 13$1e6 + +'' -: (,. 25 0)[;.0 a +'' -: (,. 26 0)[;.0 a +'' -: (,._26 0)[;.0 a +'' -: (,._27 0)[;.0 a +a -: (i.2 0 )[;.0 a +(,'z' ) -: (,. 25 4) [;.0 a +'yz' -: (,. 24 4) [;.0 a +'xyz' -: (,. 23 4) [;.0 a +'wxyz' -: (,. 22 4) [;.0 a +'vwxy' -: (,. 21 4) [;.0 a +'abc' -: (,. _24 7) [;.0 a +'ab' -: (,. _25 7) [;.0 a +(,'a') -: (,. _26 7) [;.0 a + +(i.2 0 4) -: (1,:2 0 4) [;.0 [ 4 5 6$'a' + +(i.-4 5) -: [;.0 i.4 5 +(<@(+i.)/"1 m) -: (,."1 m=:|(i.26)+/0 _26) <;.0 i.26 +(<@(+i.)/"1 m) -: (,."1 m=: (i.26)+/0 _26) <;.0 i.26 + +'length error' -: (1,:2 3 4) <;.0 etx i.2 3 +'length error' -: (i.3 2) <;.0 etx i.2 3 + +'domain error' -: 'abc' [;.0 etx i.3 4 +'domain error' -: (3;4 5) [;.0 etx i.3 4 +'domain error' -: 3j4 5j6 [;.0 etx i.3 4 + +'index error' -: (,. 26 4) [;.0 etx i.26 +'index error' -: (,._27 4) [;.0 etx i.26 + + +NB. f;.n y ------------------------------------------------------------ + +t=:'a bc def ghij' +x=:'abcd efg hi j' + +(' a';' bc';' def';' ghij') -: <;. 1 ' ',t +((,'a');'bc';'def';'ghij') -: <;._1 ' ',t +('a ';'bc ';'def ';'ghij ') -: <;. 2 t,' ' +((,'a');'bc';'def';'ghij') -: <;._2 t,' ' +(' abcd';' efg';' hi';' j') -: <;. 1 ' ',x +('abcd';'efg';'hi';,'j') -: <;._1 ' ',x +('abcd ';'efg ';'hi ';,'j ') -: <;. 2 x,' ' +('abcd';'efg';'hi';,'j') -: <;._2 x,' ' + +(<;.1 ' ',t) -: <;.1x ' ',t +(<;.1 ' ',t) -: <;.1r1 ' ',t + +(4 5$' a bc def ghij') -: ,;. 1 ' ',t +(4 4$'a bc def ghij') -: ,;._1 ' ',t +(4 5$'a bc def ghij ') -: ,;. 2 t,' ' +(4 4$'a bc def ghij') -: ,;._2 t,' ' +(4 5$' abcd efg hi j ') -: ,;. 1 ' ',x +(4 4$'abcdefg hi j ') -: ,;._1 ' ',x +(4 5$'abcd efg hi j ') -: ,;. 2 x,' ' +(4 4$'abcdefg hi j ') -: ,;._2 x,' ' + +(,.2 3 4 5) -: $;. 1 ' ',t +(,.1 2 3 4) -: $;._1 ' ',t +(,.2 3 4 5) -: $;. 2 t,' ' +(,.1 2 3 4) -: $;._2 t,' ' +(,.5 4 3 2) -: $;. 1 ' ',x +(,.4 3 2 1) -: $;._1 ' ',x +(,.5 4 3 2) -: $;. 2 x,' ' +(,.4 3 2 1) -: $;._2 x,' ' + +2 3 4 5 -: #;. 1 ' ',t +1 2 3 4 -: #;._1 ' ',t +2 3 4 5 -: #;. 2 t,' ' +1 2 3 4 -: #;._2 t,' ' +5 4 3 2 -: #;. 1 ' ',x +4 3 2 1 -: #;._1 ' ',x +5 4 3 2 -: #;. 2 x,' ' +4 3 2 1 -: #;._2 x,' ' + +(4 5$' a bc def ghij') -: [;. 1 ' ',t +(4 4$'a bc def ghij') -: [;._1 ' ',t +(4 5$'a bc def ghij ') -: [;. 2 t,' ' +(4 4$'a bc def ghij') -: [;._2 t,' ' +(4 5$' abcd efg hi j ') -: [;. 1 ' ',x +(4 4$'abcdefg hi j ') -: [;._1 ' ',x +(4 5$'abcd efg hi j ') -: [;. 2 x,' ' +(4 4$'abcdefg hi j ') -: [;._2 x,' ' + +(4 5$' a bc def ghij') -: ];. 1 ' ',t +(4 4$'a bc def ghij') -: ];._1 ' ',t +(4 5$'a bc def ghij ') -: ];. 2 t,' ' +(4 4$'a bc def ghij') -: ];._2 t,' ' +(4 5$' abcd efg hi j ') -: ];. 1 ' ',x +(4 4$'abcdefg hi j ') -: ];._1 ' ',x +(4 5$'abcd efg hi j ') -: ];. 2 x,' ' +(4 4$'abcdefg hi j ') -: ];._2 x,' ' + +' ' -: {.;. 1 ' ',t +'abdg' -: {.;._1 ' ',t +'abdg' -: {.;. 2 t,' ' +'abdg' -: {.;._2 t,' ' +' ' -: {.;. 1 ' ',x +'aehj' -: {.;._1 ' ',x +'aehj' -: {.;. 2 x,' ' +'aehj' -: {.;._2 x,' ' + +'acfj' -: {:;. 1 ' ',t +'acfj' -: {:;._1 ' ',t +' ' -: {:;. 2 t,' ' +'acfj' -: {:;._2 t,' ' +'dgij' -: {:;. 1 ' ',x +'dgij' -: {:;._1 ' ',x +' ' -: {:;. 2 x,' ' +'dgij' -: {:;._2 x,' ' + +1: #;. 1 x=:1 +1: #;._1 x +1: #;. 2 x +1: #;._2 x +1: #;. 1 x=:'a' +1: #;._1 x +1: #;. 2 x +1: #;._2 x +1: <;. 1 x=:1 +1: <;._1 x +1: <;. 2 x +1: <;._2 x +1: <;. 1 x=:'a' +1: <;._1 x +1: <;. 2 x +1: <;._2 x + + +NB. x f;.n y ------------------------------------------------------------ + +('ab';'cd';'efg') -: 1 0 1 0 1 0 0 <;. 1 'abcdefg' +(,&.>'b';'d';'fg') -: 1 0 1 0 1 0 0 <;._1 'abcdefg' + +('ab';'cd';'efg') -: 0 0 1 0 1 0 1 0 0 <;. 1 'xyabcdefg' +(,&.>'b';'d';'fg') -: 0 0 1 0 1 0 1 0 0 <;._1 'xyabcdefg' + +('ab';'cd';'efg') -: 0 1 0 1 0 0 1 <;. 2 'abcdefg' +(,&.>'a';'c';'ef') -: 0 1 0 1 0 0 1 <;._2 'abcdefg' + +('ab';'cd';'efg') -: 0 1 0 1 0 0 1 0 0 <;. 2 'abcdefgxy' +(,&.>'a';'c';'ef') -: 0 1 0 1 0 0 1 0 0 <;._2 'abcdefgxy' + +5 9 21 -: 1 0 1 0 1 0 0 +/;. 1 [ 2 3 4 5 6 7 8 +3 5 15 -: 1 0 1 0 1 0 0 +/;._1 [ 2 3 4 5 6 7 8 + +5 9 21 -: 0 0 1 0 1 0 1 0 0 +/;. 1 [ 99 98 2 3 4 5 6 7 8 +3 5 15 -: 0 0 1 0 1 0 1 0 0 +/;._1 [ 99 98 2 3 4 5 6 7 8 + +5 9 21 -: 0 1 0 1 0 0 1 +/;. 2 [ 2 3 4 5 6 7 8 +2 4 13 -: 0 1 0 1 0 0 1 +/;._2 [ 2 3 4 5 6 7 8 + +5 9 21 -: 0 1 0 1 0 0 1 0 0 +/;. 2 [ 2 3 4 5 6 7 8 99 98 +2 4 13 -: 0 1 0 1 0 0 1 0 0 +/;._2 [ 2 3 4 5 6 7 8 99 98 + + +p=: ?100$2 +q=: ?100 7$100 + +(p {.;.1 q) -: p (3 : '{.y');.1 q +(p {:;.1 q) -: p (3 : '{:y');.1 q + +(+/x) -: '' +/;.1 x=: ?100$100 + + +NB. f;.1 and f;._1 ------------------------------------------------------ + +x=:' Now! is the time, all good men!' +((x e.' ')<;. 1 x) -: <;. 1 x +((x e.' ')<;._1 x) -: <;._1 x +('Now!';'is';'the';'time,';'all';'good';'men!') -: <;._1 x + +b=:1 0 0 1 1 0 +x=:b <;.1 i.6 2 +3=$x +(#;.1 b) -: #&>x + +(,:'cdef') -: 0 0 1 0 0 0 [;.1 'abcdef' + +(,<,3) -: <;.1 (3) +(,<,3) -: 1 <;.1 (3) +(,<'') -: <;._1 (3) +(,<'') -: 1 <;._1 (3) +(,<i.1 9 3) -: 1 <;. 1 i.1 9 3 +(,<i.0 9 3) -: 1 <;._1 i.1 9 3 +(10$<i.1 0) -: <;. 1 i.10 0 +(10$<i.0 0) -: <;._1 i.10 0 + +'' -: '' <;.1 '' +'' -: <;.1 '' +'' -: <;._1 '' +'' -: 0 0 0 <;.1 'abc' + +(<@, "0 x) -: 1 <;. 1 x=: 'abcdefg' +(<@}."0 x) -: 1 <;._1 x=: 'abcdefg' +x -: 1 +/;. 1 x=: 2 3 4 5 6 7 8 +(x-x) -: 1 +/;._1 x=: 2 3 4 5 6 7 8 + +'length error' -: 1 0 0 <;. 1 etx 'abcde' +'length error' -: 1 0 0 <;. 1 etx 'ab' +'length error' -: (,1) <;. 1 etx 'abcd' +'length error' -: 1 0 0 1 <;. 1 etx (4) + +'domain error' -: 'abc' <;. 1 etx i.3 +'domain error' -: 2 0 0 <;. 1 etx 'abc' +'domain error' -: 3j4 1 1 <;._1 etx i.3 + + +NB. f;.2 and f;._2 ------------------------------------------------------ + +t=:'Now! is the time, all good men! ' +((t e.' ')<;. 2 t) -: <;. 2 t +((t e.' ')<;._2 t) -: <;._2 t +('Now!';'is';'the';'time,';'all';'good';'men!') -: <;._2 t + +b=:0 0 1 1 0 1 +x=:b <;.2 i.6 3 4 +3=$x +(#;.2 b) -: #&>x + +'' -: '' <;.2 '' +'' -: <;.2 '' +'' -: <;._2 '' +'' -: 0 0 0 <;.2 'abc' + +(,:'abc') -: 0 0 1 0 0 0[;.2 'abcdef' + +(,<,3) -: <;.2 (3) +(,<,3) -: 1 <;.2 (3) +(,<'') -: <;._2 (3) +(,<'') -: 1 <;._2 (3) +(,<i.1 9 3) -: 1 <;. 2 i.1 9 3 +(,<i.0 9 3) -: 1 <;._2 i.1 9 3 +(10$<i.1 0) -: <;. 2 i.10 0 +(10$<i.0 0) -: <;._2 i.10 0 + +'' -: '' <;.2 '' +'' -: <;.2 '' +'' -: <;._2 '' +'' -: 0 0 0 <;.2 'abc' + +(<@, "0 x) -: 1 <;. 2 x=: 'abcdefg' +(<@}."0 x) -: 1 <;._2 x=: 'abcdefg' +x -: 1 +/;. 2 x=: 2 3 4 5 6 7 8 +(x-x) -: 1 +/;._2 x=: 2 3 4 5 6 7 8 + +'length error' -: 1 0 0 <;. 2 etx 'abcde' +'length error' -: 1 0 0 <;. 2 etx 'ab' +'length error' -: (,1) <;. 2 etx 'abcd' +'length error' -: 1 0 0 1 <;. 2 etx (4) + +'domain error' -: 'abc' <;. 2 etx i.3 +'domain error' -: 2 0 0 <;. 2 etx 'abc' +'domain error' -: 3j4 1 1 <;._2 etx i.3 + + +NB. f;.n on special fns, n e. _2 _1 1 2 --------------------------------- + +test=: 4 : 0 + assert. (# ;. x y) -: (3 : '# y');.x y + assert. ($ ;. x y) -: (3 : '$ y');.x y + assert. ({. ;. x y) -: (3 : '{. y');.x y + assert. ({: ;. x y) -: (3 : '{: y');.x y + assert. (, ;. x y) -: (3 : ', y');.x y + assert. ([ ;. x y) -: (3 : '[ y');.x y + assert. (] ;. x y) -: (3 : '] y');.x y + assert. (< ;. x y) -: (3 : '< y');.x y + assert. (<@}.;. x y) -: (3 : '<@}. y');.x y + assert. (<@}:;. x y) -: (3 : '<@}: y');.x y + b=. (#y){.(i._2+#y) e. +/\2+?(#y)$10 + assert. (b # ;. x y) -: b (3 : '# y');.x y + assert. (b $ ;. x y) -: b (3 : '$ y');.x y + assert. (b {. ;. x y) -: b (3 : '{. y');.x y + assert. (b {: ;. x y) -: b (3 : '{: y');.x y + assert. (b , ;. x y) -: b (3 : ', y');.x y + assert. (b [ ;. x y) -: b (3 : '[ y');.x y + assert. (b ] ;. x y) -: b (3 : '] y');.x y + assert. (b < ;. x y) -: b (3 : '< y');.x y + assert. (b <@}.;. x y) -: b (3 : '<@}. y');.x y + assert. (b <@}:;. x y) -: b (3 : '<@}: y');.x y + 1 +) + +1 test t=: 'a' ( 0,(<&3000 # ]) +/\2+?40$1500)}3000$'xyz' +_1 test t +2 test t=: 'a' (_1,(<&3000 # ]) +/\2+?40$1500)}3000$'xyz' +_2 test t + +1 test t=: (2 3$'abcdef') ( 0,(<&998 # ])+/\2+?40$50)}a.{~?1000 2 3$#a. +_1 test t +2 test t=: (2 3$'abcdef') (_1,(<&998 # ])+/\2+?40$50)}a.{~?1000 2 3$#a. +_2 test t + +1 test t=: 11 ( 0,(<&3000 # ]) +/\2+?40$1500)}?3000$10 +_1 test t +2 test t=: 11 (_1,(<&3000 # ]) +/\2+?40$1500)}?3000$10 +_2 test t + +1 test t=: (-i.2 3) ( 0,(<&998 # ])+/\2+?40$50)}?1000 2 3$100 +_1 test t +2 test t=: (-i.2 3) (_1,(<&998 # ])+/\2+?40$50)}?1000 2 3$100 +_2 test t + +(<@}.;._1 t) -: (3 : '<}.y') ;._1 t=: ' foo upon thee' +(<@}:;._1 t) -: (3 : '<}:y') ;._1 t=: 'foo upon thee ' + +'a d' -: {.;._1 ',abc,,d' + 2 1 0 3 -: {.;._2 ] 2 3 4 1 2 4 4 3 4 + + +NB. f;.3 and f;._3 ------------------------------------------------------ + +'domain error' -: 'ab' $;. 3 etx i.3 4 +'domain error' -: (1,:3.4 5) $;. 3 etx i.3 4 +'domain error' -: (1 2;3 4) $;. 3 etx i.3 4 +'domain error' -: (_1,:2) <;. 3 etx i.12 +'length error' -: (1,:2 3) <;. 3 etx i.12 + +'domain error' -: 'ab' $;._3 etx i.3 4 +'domain error' -: (1,:3.4 5) $;._3 etx i.3 4 +'domain error' -: (1 2;3 4) $;._3 etx i.3 4 +'domain error' -: (_1,:2) <;._3 etx i.12 +'length error' -: (1,:2 3) <;._3 etx i.12 + +size =: #@$ $ <./@$ +i1 =: 3 : '{($y)-&.>~i.&.>$y' + +f1 =: 3 : 0 + t=.(i1 y){.&.><y + if. -.0 e.$t do. t=.(($&.>t)<.&.><size y){.&.>t end. + t +) + +*./ (f1 -: <;.3)@i. 5 5 #:i.25 +*./ (f1 -: <;.3)@i. 3 3 3#:i.27 + +i2 =: 3 : '{ (size y) ((<:|)#])&.>($y)-&.>~i.&.>$y' + +f2 =: 3 : 0 + t=.(i2 y){.&.><y + if. -.0 e.$t do. t=.(($&.>t)<.&.><size y){.&.>t end. + t +) + +*./ (f2 -: <;._3)@i. 5 5 #:i.25 +*./ (f2 -: <;._3)@i. 3 3 3#:i.27 + +f3 =: 4 : '((<{:x)=$&.>t)#t=.x<;.3 y' + +*./ (,."1[7 8#: i.28) (f3-:<;._3)"2 i.30 +*./ (,."1[7 8#:28+i.28) (f3-:<;._3)"2 i.30 + +f4 =: 4 : '(x,.0,:(({:$x)-#$y){.$y) <;.3 y' + +(i.2 0) (f4-:<;.3) i.4 5 +(i.2 0) (f4-:<;.3) i.3 4 5 +*./ b=:(,."1 [7 8#: i.28) (f4-:<;.3)"2 _ i.4 5 +*./ b=:(,."1 [7 8#:28+i.28) (f4-:<;.3)"2 _ i.4 5 +*./ b=:(,."1 [7 8#: i.28) (f4-:<;.3)"2 _ i.3 4 5 +*./ b=:(,."1 [7 8#:28+i.28) (f4-:<;.3)"2 _ i.3 4 5 + +f5 =: 4 : '(x,.0,:(({:$x)-#$y){.$y) <;._3 y' + +(i.2 0) (f5-:<;._3) i.4 5 +(i.2 0) (f5-:<;._3) i.3 4 5 +*./ (,."1 [7 8#: i.28) (f5-:<;._3)"2 _ i.4 5 +*./ (,."1 [7 8#:28+i.28) (f5-:<;._3)"2 _ i.4 5 +*./ (,."1 [7 8#: i.28) (f5-:<;._3)"2 _ i.3 4 5 +*./ (,."1 [7 8#:28+i.28) (f5-:<;._3)"2 _ i.3 4 5 + +'a' -: [;. 3 'a' +'a' -: [;._3 'a' +x -: [;. 3 x=:?1000001 +x -: [;._3 x=:?1000001 + +x=: 4 5$0 +y=: 0=?91 131$10 +(x E. y) -: ($x) x&-:;.3 y + +f1=: 4 : '{.&.> {. (1,.x) <;. 3 ,:y' +f2=: 4 : '{.&.> {. (1,.x) <;._3 ,:y' + +(x=: ?3 4 2 2$9) (f1 -: <;. 3)"2 i. 11 13 +(x=: ?3 4 2 2$9) (f2 -: <;._3)"2 i. 11 13 + + +4!:55 ;:'a b c f f1 f2 f3 f4 f5' +4!:55 ;:'i1 i2 m p q size t test testw w x y' + +
new file mode 100644 --- /dev/null +++ b/test/g331bx.ijs @@ -0,0 +1,86 @@ +NB. x f;.n y for boxed x, n e. _2 _1 1 2 -------------------------------- + +stdx =: #@$@] {. }.@(1&;)@[ +index =: 1 : '({.@(1&{.);.m i.@#)@[ ` 0: @. (''''&-:@[ *. *@#@])' +size =: 1 : ' #;.m~@[ ` ] @. (''''&-:@[ *. *@#@])' +cut =: 2 : '(stdx (n index&.> ,:&>&{ n size&.>) $@]) u;.0 ]' + +f=: 1 : 0 + : + assert. -. 0 e. $y + c=: ; (i.1+r) <"1@comb&.>r=. #$y + for_i. i.#c do. + j=. >i{c + t=. (j{x) j}r$a: + assert. t (u;. 1 -: u cut 1) y + assert. t (u;._1 -: u cut _1) y + assert. t (u;. 2 -: u cut 2) y + assert. t (u;._2 -: u cut _2) y + end. + 1 +) + +y=: i. 5 7 +x=: 1 0 1 0 0; 1 0 0 0 1 0 1 +x < f y +x ] f y +x=: ($y)$&.>0 +x < f y +x ] f y + +y=: ?(1+?3$25)$1000 +x=: ?&.>($y)$&.>2 +x < f y +x ] f y +x=: ($y)$&.>0 +x < f y +x ] f y + +g=: 1 : 0 + : + assert. 0 e. $y + c=: ; (i.1+r) <"1@comb&.>r=. #$y + for_i. i.#c do. + j=. >i{c + t=. (j{x) j}r$a: + s=. i. >+/&.>t#~(t e.a:)*:*$y + assert. s -: t u;. 1 y + assert. s -: t u;._1 y + assert. s -: t u;. 2 y + assert. s -: t u;._2 y + end. + 1 +) + +y=: 0 11 25$10 +x=: ?&.>($y)$&.>2 +x < g y +x ] g y + +y=: 14 0 25$10 +x=: ?&.>($y)$&.>2 +x < g y +x ] g y + +y=: 14 11 0$10 +x=: ?&.>($y)$&.>2 +x < g y +x ] g y + +'domain error' -: (1 0 1;'abcd') <;.1 etx i.3 4 +'domain error' -: (1 0 1;2 3 4 1) <;.1 etx i.3 4 +'domain error' -: (1 0 1;<4$<1) <;.1 etx i.3 4 +'domain error' -: (1 0 1;2 3 4 1.2) <;.1 etx i.3 4 +'domain error' -: (1 0 1;2 3 4 1j2) <;.1 etx i.3 4 +'domain error' -: (1 0 1;1 0 1 1r2) <;.1 etx i.3 4 + +'length error' -: (1 0 ; 1 0 0 0) <;.1 etx i.3 4 +'length error' -: (1 0 1; 1 0 0 ) <;.1 etx i.3 4 +'length error' -: (1 0 1; 1 0 0 0;0)<;.1 etx i.3 4 + +'rank error' -: (1 0 1;,:1 0 0 0) <;.1 etx i.3 4 + + +4!:55 ;:'c cut f g index size stdx x y' + +
new file mode 100644 --- /dev/null +++ b/test/g331col.ijs @@ -0,0 +1,44 @@ +NB. x <;.n y for boxed x and matrix y ----------------------------------- + +cutcol=: 2 : 0 + : + assert. 2=$#y + assert. (,2)-:$x + assert. 32=3!:0 x + assert. 1>:#@$&>x + assert. (0&=#&>x)+.($y)=#&>x + assert. (a:=x)+.1=3!:0&>x + 'b c'=. x + 'p q'=. $y + if. ''-:b do. i=. 0 + else. i=. b {.;.n i.#b [ p=. b # ;.n b end. + if. ''-:c do. j=. 0 + else. j=. c {.;.n i.#c [ q=. c # ;.n c end. + ((i,.p),."1/ j,.q) u;.0 y +) + +test=: 3 : 0 + 'b c yy'=: y + for_k. 1 _1 2 _2 do. + assert. ('';'') (< cutcol k -: <;. k) yy + assert. ('';c ) (< cutcol k -: <;. k) yy + assert. (b ;'') (< cutcol k -: <;. k) yy + assert. (b ;c ) (< cutcol k -: <;. k) yy + end. + 1 +) + +m=: 50 +n=: 300 +b=: (i.m)e.?20$m +c=: (i.n)e.?20$n +y=: a{~?(m,n)$#a=: ' abcd efgh ijkl mnop qrst uvwy xz ' + +test b ;c ;y +test b ;(0*c);y +test (0*b);c ;y +test (0*b);(0*c);y + + +4!:55 ;:'a b c cutcol m n test y yy' +
new file mode 100644 --- /dev/null +++ b/test/g331ins.ijs @@ -0,0 +1,98 @@ +NB. f/;.n --------------------------------------------------------------- + +sp =: 7!:2 +spa=: 3 : '7!:5 <''y''' + +test=: 1 : 0 + f=: u/ + xx=: ,: 'b=: ?(#yy)$2 [ yy=: y{~?233 $#y' + xx=: xx,'b=: ?(#yy)$2 [ yy=: y{~?233 5$#y' + xx=: xx,'b=: (#yy)$1 [ yy=: y{~?233 $#y' + xx=: xx,'b=: (#yy)$1 [ yy=: y{~?233 5$#y' + for_exp. xx do. + ".exp + assert. (b f;. 1 yy) -: b u/;. 1 yy + assert. (b f;._1 etx yy) -: b u/;._1 etx yy + assert. (b f;. 2 yy) -: b u/;. 2 yy + assert. (b f;._2 etx yy) -: b u/;._2 etx yy + end. + if. (1=3!:0 y) >: (<5!:5 <'u') e. ;:'= < <: > >: +. * *. ~:' do. + yy=: y{~?10000$#y + b=: ?(#yy)$2 + p=: sp 'b u/;.1 yy' + q=: spa b u/;.1 yy + assert. p <: q*IF64{1.5 2 + end. + 1 +) + += test 0 1 +< test 0 1 +<. test 0 1 +<: test 0 1 +> test 0 1 +>. test 0 1 +>: test 0 1 += test 0 1 ++ test 0 1 ++. test 0 1 ++: test 0 1 +- test 0 1 +* test 0 1 +*. test 0 1 +*: test 0 1 +~: test 0 1 + += test i.2000 +< test i.2000 +<. test i.2000 +<: test i.2000 +> test i.2000 +>. test i.2000 +>: test i.2000 += test i.2000 ++ test i.2000 ++. test i.2000 +- test i.2000 +* test i.2000 +*. test i.2000 +~: test i.2000 + += test o.i.2000 +< test o.i.2000 +<. test o.i.2000 +<: test o.i.2000 +> test o.i.2000 +>. test o.i.2000 +>: test o.i.2000 += test o.i.2000 ++ test o.i.2000 +- test o.i.2000 +* test o.i.2000 +~: test o.i.2000 + +testb=: 3 : 0 + yy=: y{~?233$#y + b=: ?(#yy)$2 + c=: (#yy)$1 + for_i. 16+i.16 do. + j=: i + assert. (> i b./&.> b <;.1 yy) -: b i b./;.1 yy + assert. (> i b./&.> c <;.1 yy) -: c i b./;.1 yy + t=: y{~?10000$#y + a=: ?(#t)$2 + p=: sp 'a i b./;.1 t' + q=: spa a i b./;.1 t + assert. p <: 1.5*q + end. + 1 +) + +testb i.2000 + +1 0 -: $ 1 0 +/;.1 i.2 0 + + +4!:55 ;:'a b c f j p q sp spa t test testb xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g331ps.ijs @@ -0,0 +1,130 @@ +NB. special code for [: ; <@(f/\);.n and [: ; <@(f/\.);.n --------------- + +test=: 1 : 0 + : + f=: u + if. *./0=#;.1~x do. + assert. (0#y) -: x ([: ; <@(u/\ );. 1) etx y + assert. (0#y) -: x ([: ; <@(u/\.);. 1) etx y + else. + assert. (; x <@(u/\ );. 1 etx y) -: x ([: ; <@(u/\ );. 1) etx y + assert. (; x <@(u/\.);. 1 etx y) -: x ([: ; <@(u/\.);. 1) etx y + end. + if. *./0=#;.2~x do. + assert. (0#y) -: x ([: ; <@(u/\ );. 2) etx y + assert. (0#y) -: x ([: ; <@(u/\.);. 2) etx y + else. + assert. (; x <@(u/\ );. 2 etx y) -: x ([: ; <@(u/\ );. 2) etx y + assert. (; x <@(u/\.);. 2 etx y) -: x ([: ; <@(u/\.);. 2) etx y + end. + if. *./0=#;._1~x do. + assert. (0#y) -: x ([: ; <@(u/\ );._1) etx y + assert. (0#y) -: x ([: ; <@(u/\.);._1) etx y + else. + assert. (; x <@(u/\ );._1 etx y) -: x ([: ; <@(u/\ );._1) etx y + assert. (; x <@(u/\.);._1 etx y) -: x ([: ; <@(u/\.);._1) etx y + end. + if. *./0=#;._2~x do. + assert. (0#y) -: x ([: ; <@(u/\ );._2) etx y + assert. (0#y) -: x ([: ; <@(u/\.);._2) etx y + else. + assert. (; x <@(u/\ );._2 etx y) -: x ([: ; <@(u/\ );._2) etx y + assert. (; x <@(u/\.);._2 etx y) -: x ([: ; <@(u/\.);._2) etx y + end. + 1 +) + +testb=: 4 : 0 + x < test y + x <. test y + x <: test y + x > test y + x >. test y + x >: test y + x = test y + x + test y + x - test y + x +. test y + x +: test y + x * test y + x *. test y + x *: test y + x ~: test y +) + +n=: 547 + +x testb y [ x=: n$0 [ y=: ? n $2 +x testb y [ x=: n$0 [ y=: ?(n,7)$2 +x testb y [ x=: n$1 [ y=: ? n $2 +x testb y [ x=: n$1 [ y=: ?(n,7)$2 +x testb y [ x=: ?n$2 [ y=: ? n $2 +x testb y [ x=: ?n$2 [ y=: ?(n,7)$2 + +testn=: 4 : 0 + x = test y + x < test y + x <. test y + x >. test y + x + test y + x +. test y + x - test y + x * test y +) + +x testn y [ x=: n$0 [ y=: _5e3+? n $1e4 +x testn y [ x=: n$0 [ y=: 0.1*_5e3+? n $1e4 +x testn y [ x=: n$0 [ y=: _5e3+?(n,3)$1e4 +x testn y [ x=: n$0 [ y=: 0.1*_5e3+?(n,3)$1e4 +x testn y [ x=: n$1 [ y=: _5e3+? n $1e4 +x testn y [ x=: n$1 [ y=: 0.1*_5e3+? n $1e4 +x testn y [ x=: n$1 [ y=: _5e3+?(n,3)$1e4 +x testn y [ x=: n$1 [ y=: 0.1*_5e3+?(n,3)$1e4 +x testn y [ x=: ?n$2 [ y=: _5e3+? n $1e4 +x testn y [ x=: ?n$2 [ y=: 0.1*_5e3+? n $1e4 +x testn y [ x=: ?n$2 [ y=: _5e3+?(n,3)$1e4 +x testn y [ x=: ?n$2 [ y=: 0.1*_5e3+?(n,3)$1e4 + +testbw=: 4 : 0 + for_i. 16+i.16 do. + x i b. test y + end. +) + +x testbw y [ x=: n$0 [ y=: _5e8+?n$1e9 +x testbw y [ x=: n$1 [ y=: _5e8+?n$1e9 +x testbw y [ x=: ?n$2 [ y=: _5e8+?n$1e9 + +testov=: 4 : 0 + x + test y + x - test y + x >. test y + x <. test y +) + +x testov y [ x=: n$0 [ y=: (?n$#y){y=: _1 1 , <.(_1+2^31),-2^31 +x testov y [ x=: n$1 +x testov y [ x=: ?n$2 + + +NB. special code for [: ; <@f;.n ---------------------------------------- + +(x ([: ; <@|.;.1) etx y) -: ; x <@|.;.1 etx y=: $. (#x)$100 + +P=: 1 : '[: ; <@:u;.1' +x=: 1 (0)}0=1019 ?@$ 4 + +(x +/;.1 y) -: x +/P y=: (#x) ?@$ 100 +(x >./;.1 y) -: x >./P y +(x +/;.1 y) -: x +/P y=: (#x) ?@$ 0 +(x >./;.1 y) -: x >./P y + +(x ([: , +/;.1) y) -: x +/P y=: ((#x),3) ?@$ 100 +(x ([: , >./;.1) y) -: x >./P y +(x ([: , +/;.1) y) -: x +/P y=: ((#x),3) ?@$ 0 +(x ([: , >./;.1) y) -: x >./P y + + +4!:55 ;:'f n P test testb testbw testi testn testov x y' + +
new file mode 100644 --- /dev/null +++ b/test/g331sp.ijs @@ -0,0 +1,82 @@ +NB. x f;.n y for sparse x, n e. _2 _1 1 2 ------------------------------- + +box=: 3 : '<y' + +C=: 1 : 0 + : + assert. x (u;. 1 -: $.@[ u;. 1 ]) y + assert. x (u;._1 -: $.@[ u;._1 ]) y + assert. x (u;. 2 -: $.@[ u;. 2 ]) y + assert. x (u;._2 -: $.@[ u;._2 ]) y + 1 +) + +f=: 1 : 0 + n=. #y + assert. b u C y [ b=. ?n$2 + assert. b u C y [ b=. 0=?n$10 + assert. b u C y [ b=. 1 ( 0)}b + assert. b u C y [ b=. 1 (_1)}b + assert. b u C y [ b=. n$1 + assert. b u C y [ b=. n$0 + assert. b u C y [ b=. (? = i.) n + 1 +) + +< f x=: ?100$1e6 +$ f x +[ f x +, f x +<@}. f x +box f x + +< f x=: a.{~ ?101 1 7$#a. +$ f x +[ f x +, f x +<@}. f x +box f x + +test=: 4 : 0 + b=: $. (#y){.(i._2+#y) e. +/\2+?(#y)$10 + assert. (b # ;. x y) -: b (3 : '# y');.x y + assert. (b $ ;. x y) -: b (3 : '$ y');.x y + assert. (b {. ;. x y) -: b (3 : '{. y');.x y + assert. (b {: ;. x y) -: b (3 : '{: y');.x y + assert. (b , ;. x y) -: b (3 : ', y');.x y + assert. (b [ ;. x y) -: b (3 : '[ y');.x y + assert. (b ] ;. x y) -: b (3 : '] y');.x y + assert. (b < ;. x y) -: b (3 : '< y');.x y + assert. (b <@}.;. x y) -: b (3 : '<@}. y');.x y + assert. (b <@}:;. x y) -: b (3 : '<@}: y');.x y + 1 +) + +1 test t=: a.{~ ?300$#a. +_1 test t +2 test t +_2 test t + +1 test t=: a.{~?101 2 3$#a. +_1 test t +2 test t +_2 test t + +1 test t=: ?317$1e6 +_1 test t +2 test t +_2 test t + +1 test t=: ? 173 2 3$100 +_1 test t +2 test t +_2 test t + +'length error' -: ($. 1 0 1 0 0) <;.1 etx i.7 + +'index error' -: ($. 1 1 1 0 0) {.;._1 etx i.5 + + +4!:55 ;:'b box C f t test x' + +
new file mode 100644 --- /dev/null +++ b/test/g332.ijs @@ -0,0 +1,315 @@ +NB. ;:y ----------------------------------------------------------------- + +('Cogito';(,',');'ergo';'sum.') -: ;:'Cogito, ergo sum.' +('Opposable';'Thumbs') -: ;:'Opposable Thumbs' +('1 2';'+.';'/:';'..';'*.';'4 5 6') -: ;:'1 2+./: ..*.4 5 6' +'' -: ;:'' +'' -: ;:' ' + +rhet=: 'anaphora anthimeria antithesis cacozelia comprobatio ' +rhet=: rhet, 'epiphonema erotema erotesis hypophora metaphor ' +rhet=: rhet, 'metonymy occultatio oxymoron polyptoton simile ' +rhet=: rhet, 'syllepsis synecdoche tasis' +rhet=: ;:rhet +1 = #$rhet + +(,<,t) -: ;: t=.'+' +(,<,t) -: ;: t=.'+.' +(,<,t) -: ;: t=.'+:' +(,<,t) -: ;: t=.'.' +(,<,t) -: ;: t=.'..' +(,<,t) -: ;: t=.'.:' + +(,<t-.' ') -: ;: t=.' - ' +(,<t-.' ') -: ;: t=.'- ' +(,<t-.' ') -: ;: t=.' -' +(,<t-.' ') -: ;: t=.' :' +(,<t-.' ') -: ;: t=.': ' +(,<t-.' ') -: ;: t=.' : ' + +(,&':'&":&.>i.10) -: ;:'0: 1:2:3: 4: 5: 6: 7: 8:9:' +('2:';'_3 4';'5:') -: ;:'2: _3 4 5:' + +(,<,t) -: ;:t=. '3 1.5 _4 _1.23e_45j_6.7e_8 5 _ __ 9 2 6' +(,<,t) -: ;:t=. '+.' +(,<,t) -: ;:t=. 'abc...' +(,<,t) -: ;:t=. 'abc:::' +(,<,t) -: ;:t=. 'abc.:.' +(,<,t) -: ;:t=. 'supercalifragilisticexpialidocious' +(,<,t) -: ;:t=. 'supercalifragilisticexpialidocious.' +(,<,t) -: ;:t=. 'supercalifragilisticexpialidocious:' +(,<,t) -: ;:t=. 'dichloro_diphenol_trichloroethane' +5 = $;:'dichloro-diphenol-trichloroethane' + +(,<'9 10') -: ;:' 9 10 ' +(,<'9 10') -: ;:' 9 10 ' +('ab';'cd') -: ;:' ab cd ' +(,<'0. 2 3') -: ;:'0. 2 3' +(,<'1. 2 3') -: ;:'1. 2 3' +(,<'_. 2 3') -: ;:'_. 2 3' +('0:';'2 3') -: ;:'0: 2 3' +('1:';'2 3') -: ;:'1: 2 3' +('_:';'2 3') -: ;:'_: 2 3' +(,<'2 3 0.') -: ;:'2 3 0.' +(,<'2 3 1.') -: ;:'2 3 1.' +(,<'2 3 _.') -: ;:'2 3 _.' +('2 3';'0:') -: ;:'2 3 0:' +('2 3';'1:') -: ;:'2 3 1:' +('2 3';'_:') -: ;:'2 3 _:' + +q =. '''' +(,<,t) -: ;: t =. q,q +(,<,t) -: ;: t =. q,'Ich liebe dich',q +(,<,t) -: ;: t =. q,'Je ',q,q,' te aime',q +(,<,t) -: ;: t =. q,'un deux trois ...',q +(,<,t) -: ;: t =. q,'un 2 trois ...',q + +((q,'abc',q);'9 10') -: ;: q,'abc',q,'9 10' +((q,'abc',q);'cd') -: ;: q,'abc',q,'cd' +((q,'abc',q);,'.') -: ;: q,'abc',q,'.' +((q,'abc',q);,':') -: ;: q,'abc',q,':' +('9 10';q,'abc',q) -: ;: '9 10',q,'abc',q +('cd' ;q,'abc',q) -: ;: 'cd' ,q,'abc',q +((,'.');q,'abc',q) -: ;: '.' ,q,'abc',q +((,':');q,'abc',q) -: ;: ':' ,q,'abc',q + +(,<,t) -: ;: t =. '5' +(,<,t) -: ;: t =. '_5' +(,<,t) -: ;: t =. '_' +(,<,t) -: ;: t =. '__' +(,<,t) -: ;: t =. '.' +(,<,t) -: ;: t =. ':' +(,<,t) -: ;: t =. '+' +(,<,t) -: ;: t =. 'a' + +(,<'56.') -: ;:'56.' +((,'.');'56') -: ;:'.56' +(,<'_.56') -: ;:'_.56' +(,<'_0.56') -: ;:'_0.56' + +(,<,t) -: ;: t =. 'Ich_liebe_dich' +(,<,t) -: ;: t =. 'Ich_liebe_dich_' +(,<,t) -: ;: t =. 'Ich_liebe_dich_.' +(,<,t) -: ;: t =. 'Ich_liebe_dich_:' + +(,<,t) -: ;: t =. '+.' +(,<,t) -: ;: t =. '+..' +(,<,t) -: ;: t =. '+...' +(,<,t) -: ;: t =. '+:' +(,<,t) -: ;: t =. '+::' +(,<,t) -: ;: t =. '+:::' +(,<,t) -: ;: t =. '+.:.:' +(,<,t) -: ;: t =. 'a.' +(,<,t) -: ;: t =. 'a..' +(,<,t) -: ;: t =. 'a...' +(,<,t) -: ;: t =. 'a:' +(,<,t) -: ;: t =. 'a::' +(,<,t) -: ;: t =. 'a:::' +(,<,t) -: ;: t =. 'a.:.:' +(,<,t) -: ;: t =. '.' +(,<,t) -: ;: t =. '..' +(,<,t) -: ;: t =. '...' +(,<,t) -: ;: t =. ':.:.' +(,<,t) -: ;: t =. ':' +(,<,t) -: ;: t =. '::' +(,<,t) -: ;: t =. ':::' +(,<,t) -: ;: t =. '.:.:' +(,<,t) -: ;: t =. '.:' +(,<,t) -: ;: t =. ':.' + +7=3+4 NB. Don't thread on me! +((,&.>'7=3+4'),<'NB. Don''t!') -: ;:'7=3+4 NB. Don''t!' +NB. +'' -: ". 'NB.' +(,<'NB.') -: ;:'NB.' +(,<'NB. ') -: ;:'NB. ' + +eq =. 3 : 0 + : + f =. 3 : (('a=.',x);('b=.',y);'=/5!:1 ''a'';''b''') + 1 +) + +(<;._1 -: ;:) ' A. a. a: b. C. c. D. D: E. e. f. H. i. j. m. n. o. p. p.. p: q:' +(<;._1 -: ;:) ' r. t. T. u. v. x. y.' + + +NB. ;: numeric input ---------------------------------------------------- + +1 = type 0001 0000 +1 = type 1 0 1 +1 = type 1.0 0.0 1.0e0 +1 = type 1j0 0j0 +1 = type 1e_9999j1e_9999 + +4 = type 2 3 4 5 +4 = type 1.5e2 _1.5e2 +4 = type 200e_2 +4 = type 1e1 1e2 1e3 1e4 1e5 1e6 1e7 1e8 1e9 +_4 -: -4 +4 -: -_4 +45 -: 5+4*10 + +8 = type 1e20 +8 = type 1e999 +8 = type _1.23e_4 5 +8 = type 8.5j0.0 _7.25e23j0e99 +3.5 -: 3+%2 +_1 -: >._1.2345 +_0.2345 -: r->.r=._1.2345 +42 -: 10^.1e42 +_42 -: 10^.1e_42 + +16 = type 0j1 +16 = type 0j1e999 +NB. 16 = type 1e999j1e999 +16 = type 1j1 2j2 1 0 1 2 +16 = type _1.23e_4j_5.6e_7 0j4 4j0 8 9 0 1 +_1.23e_4 _5.6e_7 -: +. _1.23e_4j_5.6e_7 +0 1 _1 -: {:@+."(0) 0 1j1 0j_1 +4 5 _6 -: {.@+."(0) 4j1 5 _6j7 +3j4 -: 3+0j4 +3j4 -: 3+4*0j1 +3j4 -: 3+4*%:_1 + +_ -: <./'' +_ -: %0 +__ -: >./'' +__ -: _4%0 +4 = $ _ 1 __ 3 + +0.75 _0.75 _0.75 0.75 -: 3r4 3r_4 _3r4 _3r_4 +0.75 7.5 75 750 -: 0.75r1 0.75r0.1 0.75r0.01 0.75r0.001 + +9 3 0j3 _3 0j_3 3 -: 9 3ad0 3ad90 3ad180 3ad270 3ad360 +9 3 0j3 _3 0j_3 3 -: 9 3ar0 3ar1.570796326794896 3ar3.141592653589793 3ar4.712388980384689 3ar6.283185307179586 +9 3 0j_3 _3 0j3 3 -: 9 3ad0 3ad_90 3ad_180 3ad_270 3ad_360 +9 3 0j_3 _3 0j3 3 -: 9 3ar0 3ar_1.570796326794896 3ar_3.141592653589793 3ar_4.712388980384689 3ar_6.283185307179586 + +9 2p6 3p_7 _4p8 _5p_9 -: 9, 2 3 _4 _5*(o.1)^6 _7 8 _9 +9 2x6 3x_7 _4x8 _5x_9 -: 9, 2 3 _4 _5* ^6 _7 8 _9 + +dig=.'0123456789abcdefghijklmnopqrstuvwxyz' +9 2b1011 2b_1011 -: 9 11 _11 +9 _2b1011 _2b_1011 -: 9 _9 9 +9 1p1b10 1p1b.1 -: 9, (o.1),%o.1 +9 1x1b10 1x1b.1 -: 9, ^1 _1 +0j1b3j4 -: 0j1 #. dig i. '3j4' +3j_4boustrophedonic -: 3j_4 #. dig i. 'oustrophedonic' +_3r4b_123.45 -: (_3r4^_2) * -_3r4 #. dig i. '12345' + + +NB. ;: various errors --------------------------------------------------- + +'open quote' -: ;: etx 'don''t' +'open quote' -: ;: etx '''' + +'domain error' -: ;: etx 1 0 +'domain error' -: ;: etx 1 2 3 +'domain error' -: ;: etx 3.4 +'domain error' -: ;: etx 3j4 +'domain error' -: ;: etx <'asdf' + +'spelling error' -: ex '10:' +'spelling error' -: ex '_10:' +'spelling error' -: ex 'l.' +'spelling error' -: ex 'l.' + +'ill-formed number' -: ex '123abc ' +'ill-formed number' -: ex '__abc ' +'ill-formed number' -: ex '123 45a ' +NB. 'ill-formed number' -: ex '123 45e ' +'ill-formed number' -: ex '123 45j ' + +'ill-formed number' -: ex '5_ ' +'ill-formed number' -: ex '5__ ' +'ill-formed number' -: ex '__5 ' +'ill-formed number' -: ex '4e5_ ' +'ill-formed number' -: ex '4e5__ ' +'ill-formed number' -: ex '4e__5 ' +'ill-formed number' -: ex '5_e4 ' +'ill-formed number' -: ex '5__e4 ' +'ill-formed number' -: ex '__5e4 ' +'ill-formed number' -: ex '_e ' +'ill-formed number' -: ex '_e5 ' +'ill-formed number' -: ex '5e_ ' +'ill-formed number' -: ex '5e__4 ' +'ill-formed number' -: ex '5e0.5 ' +'ill-formed number' -: ex '5e4.0 ' +'ill-formed number' -: ex '4ee ' +'ill-formed number' -: ex '4e5e ' +'ill-formed number' -: ex '4e5e6 ' +'ill-formed number' -: ex '4ej ' + +'ill-formed number' -: ex '2 3r ' +'ill-formed number' -: ex '2 3re ' +'ill-formed number' -: ex '3rr ' +'ill-formed number' -: ex '3rj ' +'ill-formed number' -: ex '3rad ' +'ill-formed number' -: ex '3rar ' +'ill-formed number' -: ex '3rp ' +'ill-formed number' -: ex '3rx ' +'ill-formed number' -: ex '2 3r4r ' +'ill-formed number' -: ex '2 3r4j ' +'ill-formed number' -: ex '2 3r4ad ' +'ill-formed number' -: ex '2 3r4ar ' +'ill-formed number' -: ex '2 3r4p ' +'ill-formed number' -: ex '2 3r4x ' +'ill-formed number' -: ex '2 3rb ' + +'ill-formed number' -: ex '4j ' +'ill-formed number' -: ex '4jj ' +'ill-formed number' -: ex '4j5j ' +'ill-formed number' -: ex '4j5j6 ' +'ill-formed number' -: ex '4je ' +'ill-formed number' -: ex '4j_e ' +'ill-formed number' -: ex '4j_e5 ' +'ill-formed number' -: ex '4j5e_ ' +'ill-formed number' -: ex '4j5e0.5 ' +'ill-formed number' -: ex '4je5 ' +'ill-formed number' -: ex '4je_ ' +'ill-formed number' -: ex '5j__4 ' +'ill-formed number' -: ex '5j4_ ' +'ill-formed number' -: ex '5j4__ ' + +'ill-formed number' -: ex '_3ad90 ' +'ill-formed number' -: ex '2 3ad ' +'ill-formed number' -: ex '2 3ade ' +'ill-formed number' -: ex '3adr ' +'ill-formed number' -: ex '3adj ' +'ill-formed number' -: ex '3adp ' +'ill-formed number' -: ex '3adx ' +'ill-formed number' -: ex '2 3ad4r ' +'ill-formed number' -: ex '2 3ad4j ' +'ill-formed number' -: ex '2 3ad4p ' +'ill-formed number' -: ex '2 3ad4x ' +'ill-formed number' -: ex '2 3ad4b ' + +'ill-formed number' -: ex '_3ar90 ' +'ill-formed number' -: ex '2 3ar ' +'ill-formed number' -: ex '2 3are ' +'ill-formed number' -: ex '3arr ' +'ill-formed number' -: ex '3arj ' +'ill-formed number' -: ex '3arp ' +'ill-formed number' -: ex '3arx ' +'ill-formed number' -: ex '2 3ar4r ' +'ill-formed number' -: ex '2 3ar4j ' +'ill-formed number' -: ex '2 3ar4p ' +'ill-formed number' -: ex '2 3ar4x ' +'ill-formed number' -: ex '2 3ar4b ' + +'ill-formed number' -: ex '_3b ' +'ill-formed number' -: ex '2 3b4.56.7' +'ill-formed number' -: ex '2 3b__56.7' +'ill-formed number' -: ex '2 3b4.56_ ' +'ill-formed number' -: ex '2 3eb ' +'ill-formed number' -: ex '2 3rb ' +'ill-formed number' -: ex '2 3jb ' +'ill-formed number' -: ex '2 3adb ' +'ill-formed number' -: ex '2 3arb ' +'ill-formed number' -: ex '2 3pb ' +'ill-formed number' -: ex '2 3xb ' + +4!:55 ;:'dig eq q r rhet t' + +
new file mode 100644 --- /dev/null +++ b/test/g332s.ijs @@ -0,0 +1,180 @@ +NB. x;:y ---------------------------------------------------------------- + +NB. example 0: English words +NB. rows are sp A; cols are sp A + +me=: (i.#a.) e. (a.i.''''),,(a.i.'Aa')+/i.26 +se=: 2 2 2 $ 0 0 1 1 0 3 1 0 + +(;: -: (0;se;me)&;:) y=: 'Now is the time all good men' +(<;._1 -: (0;se;me)&;:) y=: ' fourscore and ten years ago our fathers brought forth on this continent' + + +NB. example 1: separating quoted strings from non-quoted strings +NB. rows are 0 NQ Q Q1; cols are NQ Q + +mq =: ''''=a. +sq =: 4 2 2 $ 1 1 2 1 1 0 2 2 2 0 3 0 1 2 2 0 +sqx=: 4 2 2 $ 1 1 2 0 1 0 2 3 2 0 3 0 1 1 2 0 + +remq =: (+: ~:/\)@(''''&=) # ] +remq1=: 3 : '(,"0 (({:"1 t)e.2 3)#}:"1 t=. (4;sq;mq) ;: y) ;@:(<;.0) y' +remq2=: (1;sqx;mq)&;: + +(remq -: remq1) y=: '''Don''''t tread on me!'', he said with some feeling ' +(remq -: remq2) y +(remq -: remq2) y=: '''The Power of the Powerless'' by Havel; ''1984'' by Orwell' + +( 3&$"0&.>(0;sq ;mq);:y) -: (0;(sq ,"2 ]0);< 3&$"0&.>(a.-.'''');'''');: 3&$"0 y +(2 3&$"0&.>(0;sq ;mq);:y) -: (0;(sq ,"2 ]0);<2 3&$"0&.>(a.-.'''');'''');:2 3&$"0 y + +( 3&$"0 (1;sqx;mq);:y) -: (1;(sqx,"2 ]0);< 3&$"0&.>(a.-.'''');'''');: 3&$"0 y +(2 3&$"0 (1;sqx;mq);:y) -: (1;(sqx,"2 ]0);<2 3&$"0&.>(a.-.'''');'''');:2 3&$"0 y + +t=: (1;sqx;mq) ;: 'a''',1e6$'x' +t -: ,'a' +1000 > 7!:5 <'t' + + +NB. example 2: names and numbers with vector notation + +mv=: (#a.)$0 NB. X other +mv=: 1 (a.i.'_0123456789')}mv NB. 9 digits and _ +mv=: 2 ((a.i.'Aa')+/i.26)}mv NB. A A-Z a-z +sv=: 0 3 2$0 +NB. X 9 A +sv=:sv,_2]\ 0 0 1 1 2 1 NB. 0 other +sv=:sv,_2]\ 0 5 1 0 1 0 NB. 1 number +sv=:sv,_2]\ 0 2 2 0 2 0 NB. 2 name + + +NB. example 3: J sentences + +mj=: 256$0 NB. X other +mj=: 1 (a.i.' ')}mj NB. S space +mj=: 2 ((a.i.'Aa')+/i.26)}mj NB. A A-Z a-z excluding N B +mj=: 3 (a.i.'N')}mj NB. N the letter N +mj=: 4 (a.i.'B')}mj NB. B the letter B +mj=: 5 (a.i.'0123456789_')}mj NB. 9 digits and _ +mj=: 6 (a.i.'.')}mj NB. D . +mj=: 7 (a.i.':')}mj NB. C : +mj=: 8 (a.i.'''')}mj NB. Q quote +t=. 0 9 2$0 +NB. X S A N B 9 D C Q +t=.t,_2]\ 1 1 0 0 2 1 3 1 2 1 6 1 1 1 1 1 7 1 NB. 0 space +t=.t,_2]\ 1 2 0 3 2 2 3 2 2 2 6 2 1 0 1 0 7 2 NB. 1 other +t=.t,_2]\ 1 2 0 3 2 0 2 0 2 0 2 0 1 0 1 0 7 2 NB. 2 alphanumeric +t=.t,_2]\ 1 2 0 3 2 0 2 0 4 0 2 0 1 0 1 0 7 2 NB. 3 N +t=.t,_2]\ 1 2 0 3 2 0 2 0 2 0 2 0 5 0 1 0 7 2 NB. 4 NB +t=.t,_2]\ 9 0 9 0 9 0 9 0 9 0 9 0 1 0 1 0 9 0 NB. 5 NB. +t=.t,_2]\ 1 4 0 5 6 0 6 0 6 0 6 0 6 0 1 0 7 4 NB. 6 numeric +t=.t,_2]\ 7 0 7 0 7 0 7 0 7 0 7 0 7 0 7 0 8 0 NB. 7 quote +t=.t,_2]\ 1 2 0 3 2 2 3 2 2 2 6 2 1 2 1 2 7 0 NB. 8 even quotes +t=.t,_2]\ 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 NB. 9 trailing comment +sj=: t + +A=: 'NB' -.~ a.{~,(a.i.'Aa')+/i.26 +mj1=: (a.-.;t);t=. ' '; A; 'N'; 'B'; '0123456789_'; '.'; ':'; '''' + + +NB. Example 4: Detecting 0xABC hex strings (test end-of-input) +NB. m: 3='0', 2='x', 1=nonzero hexdigit, 0=other + +mh=: a. e. '0x123456789abcdefABCDEF' +mh=: mh + a. e. '0x' +mh=: mh + a. e. '0' +NB. ghi 0aA x 0 +sh=: 1 4 2 $ 0 0 0 0 0 0 1 1 NB. awaiting 0 +sh=: sh , 4 2 $ 0 0 0 0 2 0 0 0 NB. found 0, awaiting x +sh=: sh , 4 2 $ 0 0 3 0 0 0 3 0 NB. found 0x, awaiting hexdigit +sh=: sh , 4 2 $ 0 3 3 0 0 3 3 0 NB. found hexdigit, awaiting end-of-string + +('0x30';'0x40' ) -: (0;sh;mh;0 _1 0 0) ;: 'qqq0x30x30x40x0xxxx' +('0x30';'0x40' ) -: (0;sh;mh;0 _1 0 0) ;: 'qqq0x30x30x40x0' +('0x30';'0x40' ) -: (0;sh;mh;0 _1 0 0) ;: 'qqq0x30x30x40x0x' +('0x30';'0x40';'0x3' ) -: (0;sh;mh;0 _1 0 0) ;: 'qqq0x30x30x40x0x3' +('0x30';'0x40';'0x34a') -: (0;sh;mh;0 _1 0 0) ;: 'qqq0x30x30x40x0x34a' +NB. Using the same machine, test ijr +('0x50' ;'0x0' ) -: (0;sh;mh;4 _1 0 0) ;: 'qqq0x30x50x40x0xxxx' +('0x30' ;'0x40') -: (0;sh;mh;4 3 1 0) ;: 'qqq0x30x50x40x0xxxx' +('q0x30';'0x40') -: (0;sh;mh;4 2 1 0) ;: 'qqq0x30x50x40x0xxxx' + + +f=: ;: + +(<;._1 ' Cogito ergo sum') -: (0;se;me) f y=: 'Cogito, ergo sum.' +(<;._1 ' Cogito ergo sum') -: (0;se;me) f y,5$' ' +(<;._1 ' Cogito ergo sum') -: (2;se;me) (,"0@f <;.0 ]) y +(<;._1 ' Cogito ergo sum') -: (2;se;me) (,"0@f <;.0 ]) y,5$' ' +(<;._1 ' Don''t tread on me') -: (0;se;me) f y=: 'Don''t tread on me!' +(<;._1 ' Don''t tread on me') -: (0;se;me) f y,' ' +(<;._1 ' Don''t tread on me') -: (2;se;me) (,"0@f <;.0 ]) y +(<;._1 ' Don''t tread on me') -: (2;se;me) (,"0@f <;.0 ]) y,5$' ' + +testj=: 4 : 0 + assert. x -: (0;sj;mj) f y + assert. x -: (0;sj;mj) f y,5$' ' + assert. x -: (2;sj;mj) (,"0@f <;.0 ]) y + assert. x -: (2;sj;mj) (,"0@f <;.0 ]) y,5$' ' + t=: (2;sj;mj) f y + assert. 0<:t + assert. t -: /:~ t + assert. 0<1{"1 t + assert. (i e. i.#y) *. i-:~.i=. ; <@(+i.)/@}:"1 t + t=: (3;sj;mj) f y + assert. 1=#$t + assert. t e. i.*/}:$sj + 1 +) + +(,<y) testj y=: '_3.4e_5j_6.7e_8' +(,<y) testj y=: '1 2 _3.4e_5j_6.7e_8 9' +(,<y) testj y=: 'abc' +(,<y) testj y=: 'abc_locale59_' +(,<y) testj y=: 'abc__59' +(,<y) testj y=: '''To quote or not to quote''' +(,<y) testj y=: '''Don''''t tread on me!''' + +(<;._1 ' abc _59') testj y=: 'abc _59' +(<;._1 ';abc;''def'';1 2') testj y=: 'abc ''def'' 1 2' + +y=: 'sum=. (i.3 4)+/ .*0j4+pru 4' +x=: <;._1 ';sum;=.;(;i.;3 4;);+;/;.;*;0j4;+;pru;4' +x testj y + + +'domain error' -: 0 1 0 ;: etx 'abcd montegu' +'domain error' -: 'abc' ;: etx 'abcd montegu' +'domain error' -: 1 2 3 ;: etx 'abcd montegu' +'domain error' -: 1 2 3.5 ;: etx 'abcd montegu' +'domain error' -: 1 2 3j5 ;: etx 'abcd montegu' + +'domain error' -: (0;se;256$0 3.5) ;: etx 'abcd montegu' +'domain error' -: (0;se;256$0 3j5) ;: etx 'abcd montegu' +'domain error' -: (0;se;256$'abc') ;: etx 'abcd montegu' +'domain error' -: (0;se) ;: etx 'abcd montegu' +'domain error' -: (0;sh;mh;<<0 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' +'domain error' -: (0;sh;mh;0.5 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' +'domain error' -: (0;sh;mh;0j1 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' +'domain error' -: (0;sh;mh;'a' ) ;: etx 'qqq0x30x50x40x0xxxx' + +'rank error' -: 0 ;: etx 'abcd montegu' +'rank error' -: (,:0;se;' '~:a.) ;: etx 'abcd montegu' +'rank error' -: (,:0;(,se);me) ;: etx 'abcd montegu' +'rank error' -: (0;(0{se);me) ;: etx 'abcd montegu' +'rank error' -: ( 0;sh;mh;,:0 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' + +'index error' -: (_1;se;me) ;: etx 'abcd montegu' +'index error' -: ( 6;se;me) ;: etx 'abcd montegu' +'index error' -: ( 0;se;256$0 _15) ;: etx 'abcd montegu' +'index error' -: ( 0;se;256$0,#se) ;: etx 'abcd montegu' +'index error' -: ( 0;sh;mh;4 _1 1 0) ;: etx 'qqq0x30x50x40x0xxxx' NB. invalid output string +'index error' -: ( 0;sh;mh;0 _1 0 4) ;: etx 'qqq0x30x50x40x0xxxx' +'index error' -: ( 0;sh;mh;19 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' +'index error' -: ( 0;sh;mh;_1 _1 0 0) ;: etx 'qqq0x30x50x40x0xxxx' + + +4!:55 ;:'A f me mh mj mj1 mq mv remq remq1 remq2 se sh sj sq sqx sv' +4!:55 ;:'t testj x y' + +
new file mode 100644 --- /dev/null +++ b/test/g3x.ijs @@ -0,0 +1,403 @@ +NB. 3!:0 ---------------------------------------------------------------- + +NB. Boolean +1 = type 0 +1 = type 1 +1 = type 1 0 1 0 0 +1 = type 3 = 4 5 +1 = type (<'ergo')e.;:'Cogito, ergo sum.' + +NB. literal +2 = type a. +2 = type 'abc' +2 = type '' +2 = type ":1 2 3 + +NB. integer +4 = type 4 5 6 +4 = type 1e8 1e9 +4 = type i.3 4 +4 = type 12+13 +4 = type *_1.5 2 3.1415 +4 = type a.i.'abcd' + +NB. floating Point +8 = type 1.5 2.3 _6.3234 +8 = type 1e19 +8 = type 3%4 + +NB. complex +16 = type 0j1 3.5j_6 +16 = type %:-i.12 +16 = type ^.->:i.12 + +NB. boxed +32 = type (<'abc'),<'bar' +32 = type ;:'Cogito, ergo sum.' +32 = type 0$<'' + +NB. extended integer +64 = type 10x +64 = type !?3 4$10x +64 = type A. 20?20 + +NB. rational +128 = type 3r5 +128 = type %/?2 3 4$100x + + +NB. 3!:1, 3!:2, and 3!:3 ------------------------------------------------ + +binrep=: 3!:1 +unbin =: 3!:2 +hexrep=: 3!:3 + +f=: 1 : 0 NB. miscellaneous arrays + test=: (-: unbin@(0&u)) , (-: unbin@(1&u)) , (-: unbin@(10&u)) , (-: unbin@(11&u)) , (-: unbin@u) + assert. test x=: ?20$2 + assert. test x=: a. + assert. test x=: a.{~?2 34$#a. + assert. test x=: _4e5+?100$8e5 + assert. test x=: o._4e5+?100$8e5 + assert. test x=: j./_500+?2 50$1000 + assert. test x=: _ __ + 1 [ y +) + +binrep f 1 +hexrep f 1 + +f=: 1 : 0 NB. arrays with varying ranks + test=: (-: unbin@(0&u)) , (-: unbin@(1&u)) , (-: unbin@(10&u)) , (-: unbin@(11&u)) , (-: unbin@u) + assert. test x=: ?1000 + assert. test x=: ?3$1000 + assert. test x=: ?3 5$1000 + assert. test x=: ?3 5 7$1000 + assert. test x=: ?3 5 7 11$1000 + assert. test x=: ?3 5 7 11 13$1000 + 1 [ y +) + +binrep f 1 +hexrep f 1 + +f=: 1 : 0 NB. empty arrays + test=: (-: unbin@(0&u)) , (-: unbin@(1&u)) , (-: unbin@(10&u)) , (-: unbin@(11&u)) , (-: unbin@u) + assert. test x=: ?0$1e6 + assert. test x=: ?3 0$1e6 + assert. test x=: ?3 5 0$1e6 + assert. test x=: ?3 5 7 0$1e6 + assert. test x=: ?3 5 7 11 0$1e6 + assert. test x=: ?3 5 7 11 13 0$1e6 + assert. test x=: (?20$2)$0 + assert. test x=: (?1 2 4#4 3 2)$'a' + assert. test x=: (?10$!.2[3 4 5)$3.4 + assert. test x=: (i.30)$3j4 + 1 [ y +) + +binrep f 1 +hexrep f 1 + +f=: 1 : 0 NB. extended integer and rational + test=: (-: unbin@(0&u)) , (-: unbin@(1&u)) , (-: unbin@(10&u)) , (-: unbin@(11&u)) , (-: unbin@u) + assert. test x=: ?1000x + assert. test x=: ?3$1000x + assert. test x=: ?3 5$1000x + assert. test x=: ?3 5 7$1000x + assert. test x=: ?3 5 7 11$1000x + assert. test x=: ?3 5 7 11 13$1000x + assert. test x=: !?20x + assert. test x=: !?2$20x + assert. test x=: !?2 3$20x + assert. test x=: !?2 3 5$20x + assert. test x=: !?2 3 5 7$20x + assert. test x=: !?2 3 5 7 11$20x + assert. test x=: %/?2$20x + assert. test x=: %/?2 11$20x + assert. test x=: %/?2 11 7$20x + assert. test x=: %/?2 11 7 5$20x + assert. test x=: %/?2 11 7 5 3$20x + assert. test x=: %/?2 11 7 5 3 2$20x + 1 [ y +) + +binrep f 1 +hexrep f 1 + +f=: 1 : 0 NB. boxed arrays + test=: (-: unbin@(0&u)) , (-: unbin@(1&u)) , (-: unbin@(10&u)) , (-: unbin@(11&u)) , (-: unbin@u) + assert. test x=: 5!:1 <'test' + assert. test x=: t{~?3 $#t=. (5!:1 <'test');;:'Cogito, ergo sum. jarl is the root of earl' + assert. test x=: t{~?3 5 $#t + assert. test x=: t{~?3 5 7 $#t + assert. test x=: t{~?3 5 7 11$#t + assert. test x=: t{~?3 $#t=. (?20$2);(?2 3 4$1e6);(o.?2 3$1e6);(j./?2 3 4$1e6);(x:?17$1e6);%/?2 3 4 5$100000x + assert. test x=: t{~?3 5 $#t + assert. test x=: t{~?3 5 7 $#t + assert. test x=: t{~?3 5 7 11$#t + assert. test x=: <0 + assert. test x=: <<<<<<0 + assert. test x=: +&.> ?3 4 5$20 + assert. test x=: +&.>o. ?3 4 5$20 + assert. test x=: <"0 j./?2 3 4$5 + assert. test x=: (1=?100$10) <;.1 ?100$2 + assert. test x=: (1=?100$10) <;.1 (?100$#a.){a. + assert. test x=: (1=?100$10) <;.1 ?100$1000 + assert. test x=: (1=?100$20) <;.1 o.?100$10000 + assert. test x=: (1=?100$20) <;.1 j./?2 100$5 + assert. test x=: 23$<'the same' + assert. test x=: 2 3$<'the same' + assert. test x=: 3 7 5$<'the same' + assert. test x=: 5!:1 <'test' + assert. test x=: 5!:2 <'test' + g=: test f. + assert. test x=: 5!:1 <'g' + assert. test x=: 5!:2 <'g' + g=: +/ % # + assert. test x=: 5!:1 <'g' + assert. test x=: 5!:2 <'g' + g=: ~.@q:@%@(-/ .*)@Hilbert + assert. test x=: 5!:1 <'g' + assert. test x=: 5!:2 <'g' + 1 [ y +) + +binrep f 1 +hexrep f 1 + +test =: 3 : 0 + p=. binrep y + q=. hexrep y + (2=#$q), (*./(,q)e.'0123456789abcdef'), (#,q)=+:#p +) + +test ?20$2 +test a. +test (?2 3 4$#a.){a. +test _4e5+?100$8e5 +test o._4e5+?100$8e5 +test j./_500+?2 100$1000 +test ?4 25$1000x +test %/?2 4 25$100x + +test (?20$2)$0 +test (?1 2 4#4 3 2)$'a' +test (?10$!.2[3 4 5)$3.4 +test (i.30)$3j4 + +'3!:2' -: 3!:1 b. _1 +'3!:1' -: 3!:2 b. _1 +'3!:2' -: 3!:3 b. _1 +'3!:2' -: 0&(3!:1) b. _1 +'3!:2' -: 1&(3!:1) b. _1 +'3!:2' -: 0&(3!:3) b. _1 +'3!:2' -: 1&(3!:3) b. _1 + +(-: ]&.( 0&(3!:1))) x=: ?2000$2 +(-: ]&.( 0&(3!:1))) x=: ?29 7$2 +(-: ]&.( 0&(3!:1))) x=: a.{~?2000$#a. +(-: ]&.( 0&(3!:1))) x=: a.{~?29 7$#a. +(-: ]&.( 0&(3!:1))) x=: ?2000$2e6 +(-: ]&.( 0&(3!:1))) x=: ?29 7$2e6 +(-: ]&.( 0&(3!:1))) x=: o.?2000$2e6 +(-: ]&.( 0&(3!:1))) x=: o.?29 7$2e6 +(-: ]&.( 0&(3!:1))) x=: j./?2 2000$2e6 +(-: ]&.( 0&(3!:1))) x=: j./?2 29 7$2e6 +(-: ]&.( 0&(3!:1))) x=: ;:'bou stro phe don ic' +(-: ]&.( 0&(3!:1))) x=: 3 41$;:'4 score and 7 years ago, +/ . *' + +(-: ]&.( 1&(3!:1))) x=: ?2000$2 +(-: ]&.( 1&(3!:1))) x=: ?29 7$2 +(-: ]&.( 1&(3!:1))) x=: a.{~?2000$#a. +(-: ]&.( 1&(3!:1))) x=: a.{~?29 7$#a. +(-: ]&.( 1&(3!:1))) x=: ?2000$2e6 +(-: ]&.( 1&(3!:1))) x=: ?29 7$2e6 +(-: ]&.( 1&(3!:1))) x=: o.?2000$2e6 +(-: ]&.( 1&(3!:1))) x=: o.?29 7$2e6 +(-: ]&.( 1&(3!:1))) x=: j./?2 2000$2e6 +(-: ]&.( 1&(3!:1))) x=: j./?2 29 7$2e6 +(-: ]&.( 1&(3!:1))) x=: ;:'bou stro phe don ic' +(-: ]&.( 1&(3!:1))) x=: 3 41$;:'4 score and 7 years ago, +/ . *' + +(-: ]&.(10&(3!:1))) x=: ?2000$2 +(-: ]&.(10&(3!:1))) x=: ?29 7$2 +(-: ]&.(10&(3!:1))) x=: a.{~?2000$#a. +(-: ]&.(10&(3!:1))) x=: a.{~?29 7$#a. +(-: ]&.(10&(3!:1))) x=: ?2000$2e6 +(-: ]&.(10&(3!:1))) x=: ?29 7$2e6 +(-: ]&.(10&(3!:1))) x=: o.?2000$2e6 +(-: ]&.(10&(3!:1))) x=: o.?29 7$2e6 +(-: ]&.(10&(3!:1))) x=: j./?2 2000$2e6 +(-: ]&.(10&(3!:1))) x=: j./?2 29 7$2e6 +(-: ]&.(10&(3!:1))) x=: ;:'bou stro phe don ic' +(-: ]&.(10&(3!:1))) x=: 3 41$;:'4 score and 7 years ago, +/ . *' + +(-: ]&.(11&(3!:1))) x=: ?2000$2 +(-: ]&.(11&(3!:1))) x=: ?29 7$2 +(-: ]&.(11&(3!:1))) x=: a.{~?2000$#a. +(-: ]&.(11&(3!:1))) x=: a.{~?29 7$#a. +(-: ]&.(11&(3!:1))) x=: ?2000$2e6 +(-: ]&.(11&(3!:1))) x=: ?29 7$2e6 +(-: ]&.(11&(3!:1))) x=: o.?2000$2e6 +(-: ]&.(11&(3!:1))) x=: o.?29 7$2e6 +(-: ]&.(11&(3!:1))) x=: j./?2 2000$2e6 +(-: ]&.(11&(3!:1))) x=: j./?2 29 7$2e6 +(-: ]&.(11&(3!:1))) x=: ;:'bou stro phe don ic' +(-: ]&.(11&(3!:1))) x=: 3 41$;:'4 score and 7 years ago, +/ . *' + +NB. empty array type +x=: 0 1 0;'abc';3;4.5 6;7j8 9 10;(<1 2 3;4.5);1 2 3x;3r4 5r6 +(type&.>x) -: type&.> 3!:2@(3!:1) 0#&.>x +(type&.>x) -: type&.> 3!:2@(3!:3) 0#&.>x + +'domain error' -: unbin etx ?36$2 +'domain error' -: unbin etx ?20$10 +'domain error' -: unbin etx -:?20$10 +'domain error' -: unbin etx r.?20$10 +'domain error' -: unbin etx 'g' (<8;2)}hexrep ?10$10 +'domain error' -: unbin etx '00000005' 0}0 hexrep ?10$10 +'domain error' -: ex '_1&(3!:1) ^: _1 ] 9' +'domain error' -: ex ' 2&(3!:1) ^: _1 ] 9' +'domain error' -: ex '_1&(3!:3) ^: _1 ] 9' +'domain error' -: ex ' 2&(3!:3) ^: _1 ] 9' +'domain error' -: ex '(3!:1)&0 ^: _1 ] 9' +'domain error' -: ex '(3!:1)&1 ^: _1 ] 9' +'domain error' -: ex '(3!:3)&0 ^: _1 ] 9' +'domain error' -: ex '(3!:3)&1 ^: _1 ] 9' + +'domain error' -: unbin etx '02' (<_2;0 1)}3!:3 x=: ?8$2 +'domain error' -: unbin etx '10' (<_2;6 7)}3!:3 x=: ?8$2 + +'rank error' -: unbin etx 'f' +'rank error' -: unbin etx 5 3$hexrep i.4 +('rank error';'domain error') e.~ <unbin etx 'f' 2}0 hexrep ?4$10 +('rank error';'domain error') e.~ <unbin etx 'f' 2}1 hexrep ?4$10 +'rank error' -: ex '0 1&(3!:1) ^: _1 ] 9' +'rank error' -: ex '0 1&(3!:3) ^: _1 ] 9' + +'index error' -: unbin etx ( 7{a.) (>IF64{(20+i.4);40+i.8)}x=: binrep ;:'Cogito, ergo sum.' +'index error' -: unbin etx (_1{a.) (>IF64{(24+i.4);48+i.8)}x +'index error' -: unbin etx ( 7{a.) (>IF64{(28+i.4);56+i.8)}x +'index error' -: unbin etx (_1{a.) (>IF64{(32+i.4);64+i.8)}x +'index error' -: unbin etx '7' 5}x=: hexrep ;:'Cogito, ergo sum.' +'index error' -: unbin etx 'f' 6}x +'index error' -: unbin etx '7' 7}x +'index error' -: unbin etx 'f' 8}x + +'length error' -: unbin etx '' +'length error' -: unbin etx _5}.binrep ?20$2 +'length error' -: unbin etx _5}.binrep 4 5$'sesquipedalian' +'length error' -: unbin etx _5}.binrep 3 4 5 + +NB. 3!:2 decoding pre-601 data ------------------------------------------ + +Indirect=: 32 64 128,<.2^10+i.6 NB. indirect types + +bhdr_pre601=: 4 : 0 + b=. (1<x){4 8 + t=. 256 #. a.i. |.^:(2|x) (b+i.b){y + y=. ((b+i.b){y),(b#(1<x){0 _1{a.),(b+b)}.y + if. t e. Indirect do. + r=. 256 #. a.i. |.^:(2|x) y{~(3*b)+i.b + if. 1024<:t do. + j=. 5+r [ n=. 4 + else. + j=. 4+r [ n=. +:^:(t=128) 256 #. a.i. |.^:(2|x) ((2*b)+i.b){y + end. + if. n do. + i=. 256 #. a.i. |."1^:(2|x) y{~(b*j+i.n)+/i.b + y=. (({.i){.y) , ; x&bhdr_pre601&.> ((i.#y) e. i) <;.1 y + end. end. + y +) + +binrep_pre601=: [ bhdr_pre601 (3!:1) + +test=: 3 : 0 + assert. (-: unbin@( 0&binrep_pre601)) y + assert. (-: unbin@( 1&binrep_pre601)) y + assert. (-: unbin@(10&binrep_pre601)) y + assert. (-: unbin@(11&binrep_pre601)) y + 1 +) + +test y=: i.2 3 +test y=: o. i.2 3 +test y=: ^j.i.2 3 +test y=: ;:'Cogito, ergo sum.' +test y=: 0$<'abcde' +test y=: <'' +test y=: {:: <'' +test y=: 5!:1 <'binrep_pre601' +test y=: {:: 5!:1 <'binrep_pre601' +test y=: !i.10x +test y=: % >: +/~ i.4x +test y=: $. (3 4 ?@$ 2) * 3 4 5 ?@$ 1e5 + + +NB. 3!:n exact representation ------------------------------------------- + +NB. xr - exact representation +NB. rx - left inverse to xr +NB. rx xr y exactly reproduces array y on the same byte-order 32-bit machine + +br =: 3!:1 +rb =: 3!:2 +WS =: IF64{4 8 NB. word size +H =: (17*WS) -~ # br i.17 NB. # of header bytes in binary representation +hbr =: H&}. @ br @ , NB. headerless binary representation +xrh =: [: hbr #@$ , $ + +xr=: 3 : 0 + t=. 3!:0 y + if. t e. 8 16 do. (t{a.),(xrh y),hbr y + elseif. 32~:t do. (t{a.),5!:5 <'y' + elseif. 1 do. (t{a.),(xrh y),(hbr@:(#&>) , ;) xr&.>,y + end. +) + +rbi =: 3 : 0 + rb y ,~ (-#y) }. br (WS%~#y)$7 +) + +hrx =: 3 : 0 + r=. rbi WS {.1 }.y + s=. rbi (r*WS){.(1+WS)}.y + r;s +) + +rx=: 3 : 0 + t=. a.i.{.y + if. -. t e. 8 16 32 do. ". }.y return. end. NB. other + 'r s'=. hrx y + h=. 1+WS*1+r + if. 8 =t do. rb ((h-#y)}.br s$0.1),h}.y NB. real + elseif. 16=t do. rb ((h-#y)}.br s$0j1),h}.y NB. complex + elseif. 1 do. NB. boxed + n=. */s,WS + c=. rbi n{.h}.y + s $ rx&.> ((i.+/c) e. 0,+/\c) <;.1 (n+h)}.y + end. +) + +(-:!.0 rx@xr) x=: ?2 3 4 5$2 +(-:!.0 rx@xr) x=: a.{~ ?1000$#a. +(-:!.0 rx@xr) x=: ?2 3 $1e9 +(-:!.0 rx@xr) x=: ?2 3 4$1e9 +(-:!.0 rx@xr) 0.07 +(-:!.0 rx@xr) o.1 +(-:!.0 rx@xr) _ __ +(-:!.0 rx@xr) j./o.?2 3 4$1e6 +(-:!.0 rx@xr) ;:'Cogito, ergo sum.' +(-:!.0 rx@xr) 0.07 ; (j./i.2 3 4) ; ,. ;:'Cogito, ergo sum.' +(-:!.0 rx@xr) !100x +(-:!.0 rx@xr) +/ .*~^:(10) 2 2$0 1 1 1x +(-:!.0 rx@xr) (+%)/\44$1x +(-:!.0 rx@xr) 5!:1 <'xrh' + + +4!:55 ;:'bhdr_pre601 binrep binrep_pre601 br f g H hbr hexrep hrx Indirect' +4!:55 ;:'rb rbi rx test unbin WS x xr xrh y' + +
new file mode 100644 --- /dev/null +++ b/test/g3x4.ijs @@ -0,0 +1,98 @@ +NB. 3!:4 ---------------------------------------------------------------- + +ic =. 3!:4 + +g1 =. -:!.0 (_1&ic)@(1&ic) +g2 =. -:!.0 (_2&ic)@(2&ic) +". > IF64 { 'g3=: 1:' ; 'g3=: -:!.0 (_3&ic)@(3&ic)' + +g1 ?2000$32768 +g1 -?2000$32769 +g1 _32768+?2000$65536 +g1 _32768 0 32767 + +g2 ?2000$123456789 +g2-?2000$123456789 +g2 _5e5+?2000$1e6 +g2 <.(_1+2^31),0,-2^31 + +g3 1003 ?@$ imax +g3 -1003 ?@$ imax +g3 (1 _1{~1003 ?@$ 2) * 1003 ?@$ imax +g3 imin,0,imax + +'' -: _2 ic '' +'' -: _1 ic '' +'' -: 2 ic i.0 +'' -: 1 ic i.0 +'' -: _2 ic '' +'' -: _1 ic '' +'' -: 0 ic '' +'' -: (-2+IF64) ic i.0 +'' -: (-2+IF64) ic '' +'' -: ( 2+IF64) ic i.0 +'' -: ( 2+IF64) ic '' + +(2 ic x) -: 2 ic 1= x=.(2-2)+?10$2 +(2 ic x) -: 2 ic (o.0)+x=._50+?10$100 +(2 ic x) -: 2 ic (j.0)+x=._50+?10$100 + +(1 ic x) -: 1 ic 1= x=.(2-2)+?10$2 +(1 ic x) -: 1 ic (o.0)+x=._50+?10$100 +(1 ic x) -: 1 ic (j.0)+x=._50+?10$100 + + '2&(3!:4)' -: _2&(3!:4) b. _1 +'_2&(3!:4)' -: 2&(3!:4) b. _1 + '1&(3!:4)' -: _1&(3!:4) b. _1 +'_1&(3!:4)' -: 1&(3!:4) b. _1 + +'domain error' -: ic etx 3 4 5 +'domain error' -: '1' ic etx 3 4 5 +'domain error' -: 1.2 ic etx 3 4 5 +'domain error' -: 1j2 ic etx 3 4 5 +'domain error' -: (<1)ic etx 3 4 5 +". (-.IF64) # '''domain error'' -: 3 ic etx 3 4 5' +". (-.IF64) # '''domain error'' -: _3 ic etx 8$0{a.' + +'domain error' -: 2 ic etx 'abcd0123' +'domain error' -: 2 ic etx (i.12){a. +'domain error' -: 2 ic etx 1 2 3.4 +'domain error' -: 2 ic etx 1 2 3j4 +'domain error' -: 2 ic etx 1;2 3 4 + +'domain error' -: 1 ic etx 'abcd0123' +'domain error' -: 1 ic etx (i.12){a. +'domain error' -: 1 ic etx 1 2 3.4 +'domain error' -: 1 ic etx 1 2 3j4 +'domain error' -: 1 ic etx 1;2 3 4 + +'domain error' -: 0 ic etx 0 1 0 +'domain error' -: 0 ic etx 1 2 3.4 5 +'domain error' -: 0 ic etx 1 2 3j4 5 +'domain error' -: 0 ic etx 1;2 3 4;5;6 + +'domain error' -: _1 ic etx 0 1 0 0 +'domain error' -: _1 ic etx 1 2 3.4 5 +'domain error' -: _1 ic etx 1 2 3j4 5 +'domain error' -: _1 ic etx 1;2 3 4;5 6 + +'domain error' -: _2 ic etx 0 1 0 0 +'domain error' -: _2 ic etx 1 2 3.4 5 +'domain error' -: _2 ic etx 1 2 3j4 5 +'domain error' -: _2 ic etx 1;2 3 4;5 6 + +'rank error' -: 2 ic etx i.1 4 +'rank error' -: _2 ic etx 1 4$'a' +'rank error' -: 1 ic etx i.3 4 +'rank error' -: _1 ic etx 3 4$'abcd' +'rank error' -: 0 ic etx 3 4$'a' + +'length error' -: _2 ic etx 'ab' +'length error' -: _2 ic etx 'abcdef' +'length error' -: _1 ic etx 'abc' +'length error' -: 0 ic etx 'abc' + + +4!:55 ;:'g1 g2 g3 ic x' + +
new file mode 100644 --- /dev/null +++ b/test/g3x5.ijs @@ -0,0 +1,78 @@ +NB. 3!:5 ---------------------------------------------------------------- + +fc =. 3!:5 + +f =. -:!.0 (_2&fc)@(2&fc) + +f o.?1000$2e9 +f-o.?1000$2e9 +f _1e9+o.?2000$2e9 +f (_1+2^31),0,-2^31 + +g =. -:!.0 (_1&fc)@(1&fc) + +g 0.5+?1000$1e6 +g 0.5-?1000$1e6 + +'' -: 2 fc i.0 +'' -: 1 fc i.0 +'' -: _2 fc '' +'' -: _1 fc '' + +(2 fc x) -: 2 fc 1= x=.(o.0)+?10$2 +(2 fc x) -: 2 fc <. x=.(o.0)+_50+?10$100 +(2 fc x) -: 2 fc (j.0)+x=.(o.0)+_50+?10$100 + +(1 fc x) -: 1 fc 1= x=.(o.0)+?10$2 +(1 fc x) -: 1 fc <. x=.(o.0)+_50+?10$100 +(1 fc x) -: 1 fc (j.0)+x=.(o.0)+_50+?10$100 + +eq =. 2 : ('ar=.5!:1'; '(ar <''x.'') -: (ar <''y.'')') + + '2&(3!:5)' -: _2&(3!:5) b. _1 +'_2&(3!:5)' -: 2&(3!:5) b. _1 + '1&(3!:5)' -: _1&(3!:5) b. _1 +'_1&(3!:5)' -: 1&(3!:5) b. _1 + +'domain error' -: fc etx 3 4.5 +'domain error' -: 0 fc etx 3 4.5 +'domain error' -: 3 fc etx 3 4.5 +'domain error' -: _3 fc etx 8$0{a. +'domain error' -: '1' fc etx 3 4.5 +'domain error' -: 1.2 fc etx 3 4.5 +'domain error' -: 1j2 fc etx 3 4.5 +'domain error' -: (<1)fc etx 3 4.5 + +'domain error' -: 2 fc etx 'abcd0123' +'domain error' -: 2 fc etx (i.12){a. +'domain error' -: 2 fc etx 1 2 3j4 +'domain error' -: 2 fc etx 1;2 3 4 + +'domain error' -: 1 fc etx 'abcd0123' +'domain error' -: 1 fc etx (i.12){a. +'domain error' -: 1 fc etx 1 2 3j4 +'domain error' -: 1 fc etx 1;2 3 4 + +'domain error' -: _1 fc etx 0 1 0 0 +'domain error' -: _1 fc etx 1 2 3.4 5 +'domain error' -: _1 fc etx 1 2 3j4 5 +'domain error' -: _1 fc etx 1;2 3 4;5 6 + +'domain error' -: _2 fc etx 0 1 0 0 +'domain error' -: _2 fc etx 1 2 3.4 5 +'domain error' -: _2 fc etx 1 2 3j4 5 +'domain error' -: _2 fc etx 1;2 3 4;5 6 + +'rank error' -: 2 fc etx i.1 4 +'rank error' -: _2 fc etx 1 4$'a' +'rank error' -: 1 fc etx i.3 4 +'rank error' -: _1 fc etx 3 4$'abcd' + +'length error' -: _2 fc etx 'ab' +'length error' -: _2 fc etx 'abcdef' +'length error' -: _1 fc etx 'a' +'length error' -: _1 fc etx 'abc' + +4!:55 ;:'eq f fc g x' + +
new file mode 100644 --- /dev/null +++ b/test/g400.ijs @@ -0,0 +1,252 @@ +NB. #y ------------------------------------------------------------------ + +tally =: {.@(,&1)@$ +f =: # -: tally + +0 -: #'' +0 -: #$0 + +1 -: #0 +1 -: #'a' +1 -: #4 +1 -: #3.5 +1 -: #123j_45 +1 -: #<'abc' + +NB. Boolean +f (?5$4)$0 +0 -: #0 5$0 + +NB. literal +f (?5$4)$'abc' +0 -: #0 5$'abc' + +NB. integer +f (?5$4)$34 +0 -: #0 5$34 + +NB. floating point +f (?5$4)$3.14 +0 -: #0 5$3.14 + +NB. complex +f (?5$4)$3j4 +0 -: #0 5$3j4 + +NB. boxed +f (?5$4)$<'asdf' +0 -: #0 5$<'asdf' + +(3!:0 ]10x) -: 3!:0 # 10 20 30x +(3!:0 ]10x) -: 3!:0 # 5 % 10 20 30x + + +NB. x#y ----------------------------------------------------------------- + +copy =: ; @ (<@($ ,:)"_1) +f =: # -: copy + +3 (# -: copy) 'a' +3 (# -: copy) 'abcd' +1 2 3 4 (# -: copy) 'a' +1 2 3 4 (# -: copy) 'abcd' + +0 (# -: copy) 12 +0 (# -: copy) 21 13 14 15 +0 (# -: copy) ?3 4 5$1e4 +0 0 0 0 (# -: copy) 12 +0 0 0 0 (# -: copy) 21 13 14 15 + +1 (# -: copy) 12 +1 (# -: copy) 21 13 14 15 +1 (# -: copy) ?3 4 5$1e4 +1 1 1 1 (# -: copy) 12 +1 1 1 1 (# -: copy) 21 13 14 15 + +m=: o.?4 5$100 +3 (# -: copy) m +1 2 0 3 (# -: copy) m +0 2 3 0 (# -: copy) m + +(3#x) -: (3.5-0.5)#x=:'asdf' + +NB. NaN related tests +(2#_1e6 _1e6) -: _1e6 _1e6 _1e6 _1e6 +(3 2$_834524) -: 1 0 1 0 1 # 5 2$_834524 +(3 8$240 255{a.) -: 1 0 1 0 1 # 5 8$240 255{a. + +'domain error' -: 'abc' # etx 3 4 5 +'domain error' -: 1 2 _3 # etx 3 4 5 +'domain error' -: (2;3;4) # etx 'abc' +'domain error' -: 2 3.4 # etx i.2 3 +'domain error' -: 3.4 # etx i.2 3 +'domain error' -: 2 3j4.5 # etx i.2 3 +'domain error' -: 3j4.5 # etx i.2 3 + +'length error' -: (,2) # etx 4 5 6 +'length error' -: 2 3 # etx 4 5 6 +'length error' -: 2 3 4 # etx i.2 5 +'length error' -: 4 5 6 7 # etx i.0 + +(<2 1e9 2e9 # etx 'abc') e. 'limit error';'out of memory' + + +NB. b#"r x ------------------------------------------------------------- + +f1=: 3 : 0 + n=: y + assert. (b=: ?n$2) (# -: copy) xx=: ?n$2 + assert. (b=: ?n$2) (# -: copy) xx=: a.{~?n$#a. + assert. (b=: ?n$2) (# -: copy) xx=: a.{~?(n,7)$#a. + assert. (b=: ?n$2) (# -: copy) xx=: ?n$1e9 + assert. (b=: ?n$2) (# -: copy) xx=: o.?n$1e9 + assert. (b=: ?n$2) (# -: copy) xx=: j./?(2,n)$1e9 + assert. (b=: ?n$2) (# -: copy) xx=: <"0 ?n$1e9 + assert. (b=: ?n$2) (# -: copy) xx=: ? n $100000x + assert. (b=: ?n$2) (# -: copy) xx=: % /?(2,n)$100000x + 1 +) + +f1"0 ]100 101 102 103 + +f2=: 3 : 0 + n=: y + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: ?(3,n)$2 + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: a.{~?(3,n)$#a. + assert. (b=: ?n$2) (#"2 -: copy"2) xx=: a.{~?(3,n,7)$#a. + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: ?(3,n)$1e9 + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: o.?(3,n)$1e9 + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: j./?(2 3,n)$1e9 + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: <"0 ?(3,n)$1e9 + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: ?(3,n) $100000x + assert. (b=: ?n$2) (#"1 -: copy"1) xx=: % /?(2 3,n)$100000x + 1 +) + +f2"0 ]100 101 102 103 + +f3=: 4 : 0 + n=: x + c=: y + assert. (b=: ?n$2) (# -: copy) xx=: a.{~?(n,c)$#a. + 1 +) + +100 101 102 103 104 f3"0/ i.21 + +f4=: 4 : 0 + n=: x + c=: y + assert. (b=: ?n$2) (# -: copy) xx=: a{~?(n,c)$#a=: 0 1 255{a. + 1 +) + +100 101 102 103 104 f4"0/ i.21 + +'' -: (0$0) # '' +(i.3 0 5) -: (0$0) #"2 i.3 0 5 + +'length error' -: 1 0 1 # etx i.4 +'length error' -: 1 0 1 #"2 etx i. 4 5 6 + + +NB. x#y, complex x ------------------------------------------------------ + +'aa b' -: 2j4 1 # 'ab' +3 3 0 0 0 0 4 -: 2j4 1 # 3 4 + +'aa a' -: 2j4 1 # 'a' +(2 4 2 4#'a b ') -: 2j4 #'ab' +'aa ' -: 2j4 # 'a' + +(1 0 2 4# ,/x,:"1[0) -: 1 2j4 # x=: i.2 3 + +f=: 4 : 'x#y' + +x (f"1 -: #"1) y=: ?3 4 9$100 [ x=: j./?2 9$5 +x (f"2 -: #"2) y=: ?3 9 4$100 + + +NB. x#!.f y ------------------------------------------------------------- + +'aa____b' -: 2j4 1 #!.'_' 'ab' +3 3 9 9 9 9 4 -: 2j4 1 #!.9[ 3 4 + +'aa____a' -: 2j4 1 #!.'_' 'a' +(2 4 2 4#'a_b_') -: 2j4 #!.'_' 'ab' +'aa____' -: 2j4 #!.'_' 'a' + +(1 0 2 4# ,/x,:"1[3j4) -: 1 2j4 #!.3j4 x=:i.2 3 + +'domain error' -: 9 3j1 #!.'a' etx 4 +'domain error' -: 1 2j3 #!.'a' etx 'b';'c' +'domain error' -: 3j4 #!.4 etx 'sui generis' +'domain error' -: 5 3j5 4#!.4 etx ;:'Cogito, ergo' +'domain error' -: 1j7 #!.(<4) etx 'eleemosynary' +'domain error' -: 9 3j4 #!.(<4) etx i.2 3 + + +NB. x#"r y -------------------------------------------------------------- + +f=: 4 : 'x#y' + +1 0 2 (#"0 -: f"0) x=:?3 3 3 3$1e5 +1 0 2 (#"1 -: f"1) x +1 0 2 (#"2 -: f"2) x +1 0 2 (#"3 -: f"3) x +1 0 2 (#"4 -: f"4) x + +1 0 1 (#"0 -: f"0) x=:?3 3 3 3$1e5 +1 0 1 (#"1 -: f"1) x +1 0 1 (#"2 -: f"2) x +1 0 1 (#"3 -: f"3) x +1 0 1 (#"4 -: f"4) x + +0 (#"0 -: f"0) x=:?3 3 3 3$1e5 +0 (#"1 -: f"1) x +0 (#"2 -: f"2) x +0 (#"3 -: f"3) x +0 (#"4 -: f"4) x + +1 (#"0 -: f"0) x=:?3 3 3 3$1e5 +1 (#"1 -: f"1) x +1 (#"2 -: f"2) x +1 (#"3 -: f"3) x +1 (#"4 -: f"4) x + +2 (#"0 -: f"0) x=:?3 3 3 3$1e5 +2 (#"1 -: f"1) x +2 (#"2 -: f"2) x +2 (#"3 -: f"3) x +2 (#"4 -: f"4) x + +1 0 2 (#"0 -: f"0) x=:o.?1e6 +1 0 2 (#"1 -: f"1) x + +3 (#"0 -: f"0) x=:4 4 4$'antidisestablishmentarianism' +3 (#"1 -: f"1) x +3 (#"2 -: f"2) x +3 (#"3 -: f"3) x + +(?5 2$10) (# -: f"1 _) x=:2 5$;:'When eras die their legacies are left to strange police' +(?5 2$10) (#"_1 -: f"_1 ) y=:5 2$;:'Professors in New England guard the glory that was Greece' + +1j2 3j4 0j5 (#"0 0 -: f"0 0) x=:(?3 3 3$3){;:'chirality paronomasiac onomatopoeia' +1j2 3j4 0j5 (#"0 1 -: f"0 1) x +1j2 3j4 0j5 (#"0 2 -: f"0 2) x +1j2 3j4 0j5 (#"0 3 -: f"0 3) x +1j2 3j4 0j5 (#"1 0 -: f"1 0) x +1j2 3j4 0j5 (#"1 1 -: f"1 1) x +1j2 3j4 0j5 (#"1 2 -: f"1 2) x +1j2 3j4 0j5 (#"1 3 -: f"1 3) x + +(i.0 8 ) -: 3 1 4 #"1 i.0 3 +(i.0 0 7) -: (i.0 5) # 5 7$'sesquipedalian' + +(i.1e9 0) -: 1e4# i.1e5 0 +(i.1e9 2e4 0) -: 1e4#"2 i.1e9 2 0 + + +4!:55 ;:'a b c copy f f1 f2 f3 f4 g m n tally x xx y ' + +
new file mode 100644 --- /dev/null +++ b/test/g400e.ijs @@ -0,0 +1,61 @@ +NB. x #^:_1 y (expand) -------------------------------------------------- + +expand=: (* +/\ )@[ { -@>:@(+/)@[ {. +/@[ $ ] +exp =: #^:_1 + +f=: 4 : 0 + b=. ?x$2 + x=. (?(+/b)$#y){y + b (exp -: expand) x +) + +(>:(i.10),?10$500) f"0 _ ] 0 1 +(>:(i.10),?10$500) f"0 _ a. +(>:(i.10),?10$500) f"0 _ ? 25$1000 +(>:(i.10),?10$500) f"0 _ o. ? 25$1000 +(>:(i.10),?10$500) f"0 _ j./ ?2 25$1000 +(>:(i.10),?10$500) f"0 _ 'ab';<"0? 25$1000 + +g=: 4 : 0 + b=. ?x$2 + x=. a.{~?((+/b),y)$#a. + b (exp -: expand) x +) + +(>:(i.10),?10$500) g"0/>:i.20 + + +NB. x #^:_1 y (expand), scalar y ---------------------------------------- + +b (exp -: expand) x=: ?2 [ b=: ?(1+?1000)$2 +b (exp -: expand) x=: a.{~?#a. [ b=: ?(1+?1000)$2 +b (exp -: expand) x=: ?1e6 [ b=: ?(1+?1000)$2 +b (exp -: expand) x=: o. ?1e6 [ b=: ?(1+?1000)$2 +b (exp -: expand) x=: j./ ?2$1e6 [ b=: ?(1+?1000)$2 + +b (exp -: expand) x=: ?2 [ b=: (1+?1000)$1 +b (exp -: expand) x=: a.{~?#a. [ b=: (1+?1000)$1 +b (exp -: expand) x=: ?1e6 [ b=: (1+?1000)$1 +b (exp -: expand) x=: o. ?1e6 [ b=: (1+?1000)$1 +b (exp -: expand) x=: j./ ?2$1e6 [ b=: (1+?1000)$1 + +b (exp -: expand) x=: ?2 [ b=: (1+?1000)$0 +b (exp -: expand) x=: a.{~?#a. [ b=: (1+?1000)$0 +b (exp -: expand) x=: ?1e6 [ b=: (1+?1000)$0 +b (exp -: expand) x=: o. ?1e6 [ b=: (1+?1000)$0 +b (exp -: expand) x=: j./ ?2$1e6 [ b=: (1+?1000)$0 + + +'rank error' -: 0 #^:_1 etx 'a' +'rank error' -: 0 #^:_1 etx 'abc' +'rank error' -: 1 #^:_1 etx 'a' +'rank error' -: 1 #^:_1 etx 'abc' + +'length error' -: 1 0 1 #^:_1 etx 2 3 4 +'length error' -: 1 0 1 #^:_1 etx 'abc' +'length error' -: 1 0 1 #^:_1 etx i.5 3 + + +4!:55 ;:'b exp expand f g x' + +
new file mode 100644 --- /dev/null +++ b/test/g401.ijs @@ -0,0 +1,143 @@ +NB. #.y ----------------------------------------------------------------- + +base1 =. 2&#. +f =. *./@,@:(#. -: base1) + +NB. Boolean +f ?2 3 4$2 +f ?2 + +NB. integer +f _6000+?2 3 4$12345 +f _500+?1000 + +NB. floating point +f o._5000+?2 3 4$10000 +f o._500+?1000 + +NB. complex +f r.?2 3 4$1000 +f r.?12345 + +0 -: #. '' +0 -: #. (,0) +1 -: #. (,1) +2 -: #. 1 0 +4 -: #. 1 0 0 +8 -: #. 1 0 0 0 +13 -: #. 1 1 0 1 +(2^69) -: #.70{.1 +(i.4) -: #.4 2$0 0 0 1 1 0 1 1 + +(_3r2+2x^n+1) = #. (n$1),1r2 [ n=: 30 +(_3r2+2x^n+1) = #. (n$1),1r2 [ n=: 34 +(_3r2+2x^n+1) = #. (n$1),1r2 [ n=: 62 +(_3r2+2x^n+1) = #. (n$1),1r2 [ n=: 66 + +x -: #."0 x=: 10 ?@$ 2 +x -: #."0 x=: 10 ?@$ 2e6 +x -: #."0 x=: 10 ?@$ 200x +x -: #."0 x=: 100 * 10 ?@$ 0 + +'domain error' -: #. etx 'abc' +'domain error' -: #. etx ;:'Cogito, ergo sum.' + + +NB. x#.y ---------------------------------------------------------------- + +rank =. #@$ +ext =. (#@] # [)`[ @. (*@rank@[) +base2 =. (] +/ .* */\.@}.@(,&1)@ext)"1 +f =. *./@,@:(#. -: base2) + +NB. Boolean +(?2) f ?2 +(?2) f ?10$2 +(?2) f ?7 2$2 +(?2) f ?4 3 5$2 +(?10$2) f ?2 +(?10$2) f ?10$2 +(?10$2) f ?2 10$2 +(?10$2) f ?1 2 3 10$2 +(?10 4$2) f ?2 +(?10 4$2) f ?4$2 +(?10 4$2) f ?10 2 4$2 +(?10 4$2) f ?10 1 1 4$2 +(?2 3 4$2) f ?2 +(?2 3 4$2) f ?4$2 +(?2 3 4$2) f ?2 4$2 +(?2 3 4$2) f ?2 3 0 4$2 + +NB. integer +(?200) f ?2 +(?200) f ?10$200 +(?200) f _900+?7 2$2000 +(?200) f _900+?2 3 4$2000 +(_100+?7$200) f ?2 +(_100+?7$200) f _900+?7$2000 +(_100+?7$200) f _900+?1 7$2100 +(_100+?7$200) f _900+?3 2 7$2100 +(_100+?2 7$200) f ?2 +(_100+?2 7$200) f _900+?7$100 +(_100+?2 7$200) f _900+?2 1 7$100 +(_100+?2 7$200) f _900+?2 3 7$100 +(_100+?3 2 7$200) f _1000+?2000 +(_100+?2 3 7$200) f ?7$2 +(_100+?3 2 7$200) f _900+?3 7$100 +(_100+?3 2 7$200) f _900+?3 2 7$100 + +NB. floating point +(o.?200) f ?2 +(^.?200) f o.?10$200 +(^.?200) f ?7 2$2 +(o.?200) f _900+?4 3 2$2000 +(o._100+?7$200) f o.?2 +(o._100+?7$200) f o._900+?7$2000 +(o._100+?7$200) f _900+?1 7$2000 +(o._100+?7$200) f _900+?2 3 7$2000 +(o._100+?2 7$200) f ^?2 +(o._100+?2 7$200) f ^_9+?7$20 +(o._100+?2 7$200) f _900+?2 7$100 +(o._100+?2 7$200) f o._900+?2 3 7$100 +(o._100+?3 2 7$200) f o._1000+?2000 +(o._100+?2 3 7$200) f ?7$2000 +(o._100+?3 2 7$200) f o._900+?3 7$100 +(o._100+?3 2 7$200) f _900+?3 2 7$100 + +NB. complex +(r.?200) f r.?2 +(r.?200) f o.?10$200 +(r.?200) f ?7 2$2 +(r.?200) f j._900+?4 3 2$2000 +(r._100+?7$200) f r.?2 +(r._100+?7$200) f r._900+?7$2000 +(r._100+?7$200) f _900+?1 7$2000 +(r._100+?7$200) f _900+?1 1 1 7$2000 +(r._100+?2 7$200) f r.?2 +(r._100+?2 7$200) f r._9+?7$20 +(r._100+?2 7$200) f _900+?2 1 7$100 +(r._100+?2 7$200) f r._900+?2 3 1 7$100 +(r._100+?3 2 7$200) f r._1000+?2000 +(r._100+?2 3 7$200) f r.?7$2000 +(r._100+?3 2 7$200) f o._900+?3 7$100 +(r._100+?3 2 7$200) f _900+?3 2 7$100 + +465 -: 10 #. 4 6 5 +465 -: 10 10 10 #. 4 6 5 +444 -: 10 10 10 #. 4 +12 345 -: 10#.i.2 3 + +(_3r2+2x^n+1) = 2 #. (n$1),1r2 [ n=: 30 +(_3r2+2x^n+1) = 2 #. (n$1),1r2 [ n=: 34 +(_3r2+2x^n+1) = 2 #. (n$1),1r2 [ n=: 62 +(_3r2+2x^n+1) = 2 #. (n$1),1r2 [ n=: 66 + +'domain error' -: 'abc' #. etx 1 2 3 +'domain error' -: (1;2;3) #. etx 1 2 3 +'domain error' -: 1 2 3 #. etx 'a' +'domain error' -: 1 2 3 #. etx <5 + + +4!:55 ;:'base1 base2 ext f n rank x' + +
new file mode 100644 --- /dev/null +++ b/test/g402.ijs @@ -0,0 +1,98 @@ +NB. #:y ----------------------------------------------------------------- + +max =: >./@:|@, +bits =: ] (1 >. ] + [ >: 2x&^@]) <.@(2&^.)@(1&>.) +abase1 =: #:~ $&2@bits@max + +NB. Boolean +(#: -: abase1) x=:?2 3 4$2 +(#: -: abase1) x=: 0 +(#: -: abase1) x=: 1 + +NB. integer +(#: -: abase1) x=:_6000+?2 3 4$12345 +(#: -: abase1) x=:_500+?1000 +(#: -: abase1) x=:_1e8+?100$2e8 +(#: -: abase1) x=:_2147483648 +(#: -: abase1) x=: 2147483647 +(#: -: abase1) x=:_2147483648 25 9 2147483647 +(#: -: abase1) imin +(#: -: abase1) imax +(#: -: abase1) x=: imax,imin,_5e8+10 ?@$ 1e9 + +NB. floating point +(#: -: abase1) x=:o._5000+?2 3 4$10000 +(#: -: abase1) x=:o._500+?1000 + +0~:{.#:(2^12)-1e_9 + +NB. complex +(#: -: abase1) x=:j./?2 3 4$1000 +(#: -: abase1) x=:r.?12345 6789 + +(,0) -: #: 0 +(,1) -: #: 1 +1 0 -: #: 2 +1 0 0 -: #: 4 +1 0 0 0 -: #: 8 +1 0 0 0 -: #: _8 +1 1 0 1 -: #: 13 + +(70{.1) -: #: 2^69 + +f =: ([,-.@(0&e.))@$ $ , +(f t) -: #:t=:?(>:?7$3)$2 +(f t) -: #:t=:(?32$2)$2 +(f t) -: #:t=:(?32$2)$2.4 +(f t) -: #:t=:(?32$2)$2j4 + +'domain error' -: #: etx 'abc' +'domain error' -: #: etx 123;45 6 + + +NB. x#:y ---------------------------------------------------------------- + +abase2 =: ([ | i.@#@$@] |: ([%~]-|)/\.@}.@,)"1 0 +f =: *./@,@:(#: -: abase2) + +NB. Boolean +(?4$2) f ?2 3 4$2 +(?4$2) f ?2 + +NB. integer +(?4$100) f _6000+?2 5$12345 +(_4+?2 4$10) f _6000+?2 1 3$12345 +(?4$10) f _500+?1000 +(_40+?3 2 4$100) f _6000+?3$12345 + +NB. floating point +(_15+?1 2 4$30) f o._5000+?1 2$10000 +(_4+?7$9) f o._500+?10000 + +NB. complex +(_15+3 4$30) f r.?3 1 1 4$1000 +(_4+?3 1 1 7$9) f r.?3 1$12345 + +(?2) (|-:#:) ?2 +(?100) (|-:#:) ?100 +(o.?100) (|-:#:) o.?100 +(r.?100) (|-:#:) r.?100 + +1 2 3 4 -: 10 10 10 10#:1234 +0 0 _1 _1 -: _2 _2 _2 _2#:1 + +f=: #: i.@(*/) +g=: 3 : 'y#:i.*/y' + +(f -: g) ?5$5 +(f -: g) ?5$14 +(f -: g) _7+?5$14 + +'domain error' -: 2 3 4#: etx 'abc' +'domain error' -: 4 3 2#: etx 123;45 6 +'domain error' -: 'abc'#: etx 7 +'domain error' -: (123;4 5 6)#: etx _12 + +4!:55 ;:'abase1 abase2 bits f g max t x ' + +
new file mode 100644 --- /dev/null +++ b/test/g410.ijs @@ -0,0 +1,442 @@ +NB. !y ------------------------------------------------------------------ + +fac=: 1:`(* $:@<:) @. * " 0 + +(! -: fac) i.10 + +1 1 -: ! 0 1 +1 1 2 -: ! 0 1 2 +_ _ -: ! 300 301 +_ _ -: ! 1e90 1e200 +_ _ -: ! }: 1e90 1e200 0j1 +_ __ -: ! _1 _2 +__ 0 _ 0 -: ! _300+0.5*i.4 +1 [ ! _. NB. succeeds if J doesn't hang or crash + +(!3.5) -: 3.5 * !2.5 +(!3.5) -: 4.5 %~ !4.5 +(!12.2) -: 12.2 * !11.2 +(!12.2) -: 13.2 %~ !13.2 + +(!x) -: (!x-k) * */"1 x -/i.k=: ?10 [ x=: 10+10* 20 ?@$ 0 +(!x) -: (!x-k) * */"1 x -/i.k +(!x) -: (!x+k) % */"1 (x+1)+/i.k=: ?10 [ x=: j./10+10*2 20 ?@$ 0 +(!x) -: (!x+k) % */"1 (x+1)+/i.k + +1e_10 > | 0.8862269254 - ! 0.5 +1e_10 > | 1.2254167024 - ! _0.25 +1e_10 > | 3.6256099082 - ! _0.75 + +2.678938534707747 = ! _2r3 NB. Knuth, Volume 1, Appendix B +1.772453850905516 = ! _1r2 +1.354117939426400 = ! _1r3 +1p0.5 = ! _1r2 +0.5p0.5 = ! 1r2 + +(!x) -: !x j. 1e_20 [ x=: 0.01 * 20 ?@$ 2000 +(!x) -: !x j. _1e_20 + +'domain error' -: ! etx 'abc' +'domain error' -: ! etx <'abc' + +'limit error' -: ! etx - 2 +2^53 +'limit error' -: ! etx {.- 2 0j1+2^53 + + +NB. Gamma Function ------------------------------------------------------ + +NB. Formulae from Abramowitz & Stegun + +re =: {.@+. NB. real part +im =: {:@+. NB. imaginary part + +c=: 0 1 0.5772156649015329 _0.6558780715202538 +c=:c, _0.0420026350340952 0.1665386113822915 _0.0421977345555443 +c=:c, _0.009621971527877 0.007218943246663 _0.0011651675918591 +c=:c, _0.0002152416741149 0.0001280502823882 _0.0000201348547807 +c=:c, _0.0000012504934821 0.000001133027232 _0.0000002056338417 +c=:c, 6.116095e_9 5.0020075e_9 _1.1812746e_9 +c=:c, 1.043427e_10 7.7823e_12 _3.6968e_12 +c=:c, 5.1e_13 _2.06e_14 _5.4e_15 +c=:c, 1.4e_15 1e_16 + +NB. 6.1.34 Power Series +gps =: % @ (c&p.) + +NB. 6.1.15 Recurrence Formula +em =: (<.@| + 0.5&<@(1&|)@| - 0&< *. (=<.))@re +grp =: (gps@- * <:@[ ^!._1 ]) em +grm =: (gps@+ % ^!. 1 ) em +grecur =: grm`grp@.(0:<re) + +NB. 6.1.20 Gauss Multiplication Formula +Gauss =: 2p1&^@-:@-.@[ * (^ -&0.5) * */@:(grecur"0)@:([ %~ i.@[ + ]) + +NB. 6.1.37 Stirling's Approximation +sbase =: %:@(2p1&%) * %&1x1 ^ ] +scorr =: 1 1r12 1r288 _139r51840 _571r2488320&p.@% +Stirling =: sbase * scorr + +en =: 1&>.@>.@(%&(%:3r4))@|@im +gamma =: (en Gauss ]) ` Stirling @. (20&<@|@im) " 0 + +g =: !@<: + +(24$'_ __ ') -: ": g -i.10 + +(g@>: = [ * g) x=: _0.1 _0.9 0.1 0.9 _4.1 _4.9 4.1 4.9 +(g@>: = [ * g) z=: _0.1 _0.9 0.1 0.9 j./_0.4 _0.5 0.4 0.5 _4 _5 4 5 +(g@>: = [ * g) z=: _4.1 _4.9 4.1 4.9 j./_0.4 _0.5 0.4 0.5 _4 _5 4 5 + +(g@+ = +@g) z=:j./1e_2*_1e3+?2 20$2e3 NB. 6.1.23 +(g@+ = +@g) z=:j./3e_2*_1e3+?2 20$2e3 + +(g = gamma) >:i.4 5 + +(g = gamma) x=: _0.1 _0.9 0.1 0.9 j./_0.4 _0.5 0.4 0.5 _4 _5 4 5 +(g = gamma) x=: _4.1 _4.9 4.1 4.9 j./_0.4 _0.5 0.4 0.5 _4 _5 4 5 + +(g =!.1e_12 gamma) 1.5 +(g =!.1e_12 gamma) 1r3 1r2 2r3 +(g =!.1e_12 gamma) x=: 1e_2*_7e2+?2 20$2e3 +(g =!.1e_12 gamma) x=: 3e_2*_7e2+?2 20$2e3 +(g =!.1e_12 gamma) z=:j./1e_2*_7e2+?2 20$2e3 + +sinh =: 5&o. +rm =: *:@|@g@j. % 1p1&%@(* sinh@o.) NB. 6.1.29 +1e_12 > | 1 - rm y=:0.001*_30000+?4 5$60000 + +1e_10 > | 0.9513507699 - g 1.1 NB. Table 6.1 +1e_10 > | 0.8862269255 - g 1.5 +1e_10 > | 0.9617658319 - g 1.9 + +1e_12 > | _0.190945499187j_0.244058298905 - ^. g 1j0.5 NB. Table 6.7 +1e_12 > | _0.650923199302j_0.301640320468 - ^. g 1j1 +1e_12 > | _1.876078786431j0.129646316310 - ^. g 1j2 + +x -: g^:_1 g x=:34 +x -: g^:_1 g x=:3.4 + +NB. y -: g g^:_1 y=:1.5 +y -: g g^:_1 y=:3j4 + +NB. EEM, 1999-06-02 +NB. coefficients in ascending order +NB. from Hart et al. Computer Approximations, 6.6 +NB. for gamma (2+x), Index 5243, p. 248 + +p=:_42353.689509744089 +p=:p,_20886.861789269888 +p=:p,_8762.710297852149 +p=:p,_2008.52740130727915 +p=:p,_439.3304440600257 +p=:p,_50.108693752970953 +p=:p,_6.744950724592529 +q=:_42353.689509744090 +q=:q,_2980.385330925665 +q=:q,9940.307415082771 +q=:q,_1528.607273779522 +q=:q,_499.028526621439 +q=:q,189.498234157028016 +q=:q,_23.081551524580124 +q=:q,1.0 + +gm=: p&p. % q&p. + +gamma=: 3 : 0 " 0 +X=.1|y NB.X is fractional part of y +N=._2+<.y NB.X=(y-2)-N; N=_2+y-X=_2+<. y +l=.(N<0)+i.|N NB.l is list of N integers +e=._1^N<0 NB._1 if N<0, 1 otherwise +w=.X+2+l*e NB.w is list of N factors +r=.w^e NB.1%w if N<0, w otherwise +*/r,gm X +) + +(g = gamma) x=: _12.5 +i.5 5 +(g = gamma) x=: _12.25+i.5 5 +(g = gamma) x=: _12.75+i.5 5 +(g = gamma) x=: _12.33+i.5 5 + + +NB. !y Stirling's approximation, Abramowitz & Stegun -------------------- + +sbase =: %:@(2p1&%) * %&1x1 ^ ] +scorr =: 1 1r12 1r288 _139r51840 _571r2488320&p.@% +stirlg =: sbase * scorr NB. 6.1.37 + +stirlf =: ^@(1r12&%) * %:@(2p1&*) * %&1x1 ^ ] NB. 6.1.38 + +g =: stirlg@>: |@-.@% ! +f =: stirlf |@-.@% ! + +1e_8 > g 10 +i.2 5 +1e_8 > g 10.5+i.2 5 +1e_8 > g 10 +10*i.3 5 +1e_8 > g 10.5+10*i.3 5 + +5e_6 > f 10 +i.2 5 +5e_6 > f 10.5+i.2 5 +5e_6 > f 10 +10*i.3 5 +5e_6 > f 10.5+10*i.3 5 + + +NB. !^:_1 --------------------------------------------------------------- + +x = !y=:!^:_1 x=:>:i.4 5 +x = !y=:!^:_1 x=:>:?20$1e8 + +(=!.(2^_34) !@(!^:_1)) 1+i.7 +(=!.(2^_34) !@(!^:_1)) 2 ^ i.7 +(=!.(2^_34) !@(!^:_1)) 10^50*i.7 + + +NB. x!y ----------------------------------------------------------------- + +case =: 2&#. @ (0&>*.(=<.)) @ ([,],-~) +f000 =: !@] % !@[ * !@-~ +f001 =: 0: +f010 =: f000 +f011 =: _1&^@[ * [ ! (->:) +f100 =: 0: +f101 =: 'impossible'"0 +f110 =: _1&^@-~ * !&|&>:~ +f111 =: 0: +f =: f000`f001`f010`f011`f100`f101`f110`f111 @. case " 0 + + 3.4 (! -: f) _5.6 +1e_14 > | _3.6 (! - f) _5.6 +_3.6 (! -: f) _5 + 3 (! -: f) _5 +_3 (! -: f) 5.6 +_5 (! -: f) _2 +_5 (! -: f) _9 + +a =: _10+i.21 +b =: _10+i.11 +c =: i.16 +a (!/ -: f/) b +a (!/ -: f/) c + +(a%3) (!/ -: f/) c +(a%2) (!/ -: f/) c%2 +(a%2) (!/ -: f/) c%3 +(a%2) (!/ -: f/) c%o._1 +a (!/ -: f/) c%_4 + +pascal0=: (0&,+,&0)^:(i.`1:) +(!/~@i. -: |:@pascal0) 32 + +pascal1=: +/\@(|.!.0)^:(i.`($&1)) +(!/~@i. -: pascal1) 32 + +pascal2=: 1 1&([: +//. */)^:(i.`1:) +(!/~@i. -: |:@pascal2) 32 + +C =: <:`($:&<: + ($:<:))@.(< *. *@[)"0 +(!/~@i. -: C/~@i.) 12 + +*./ 1 = 0 ! 0.5*_10+i.21 +*./ 1 = !~ 0.5*_10+i.21 + +_ -: 3.5 ! _5 +_ -: 3.5 ! _6 + +1 = 0 ! (, -) 0.5*i.12 +1 = 0 ! (, -) }. 0j1, 0.5*i.12 +1 = 0 ! (, -) 10^20*i.11 +1 = 0 ! (, -) }. 0j1, 10^20*i.11 + +(-: 1&!) (, -) 0.5*i.12 +(-: 1&!) (, -) }. 0j1, 0.5*i.12 +(-: 1&!) (, -) 10^20*i.11 +(-: 1&!) (, -) }. 0j1, 10^20*i.11 + +test=: 4 : 0 + assert. (x!y) -: (!x) %~ */"1 y-/i.x + 1 +) + +(x=: i.10) test"0 _ y=: 1e9* 20?@$ 10 + +1 [ _. ! _. _ __ , (, -) 0.5*i.12 NB. succeeds if J doesn't hang or crash +1 [ _. !~ _. _ __ , (, -) 0.5*i.12 NB. succeeds if J doesn't hang or crash + +'domain error' -: 'abc' ! etx 3 4 5 +'domain error' -: 'abc' !~etx 3 4 5 +'domain error' -: 3 4 5 ! etx <'abc' +'domain error' -: 3 4 5 !~etx <'abc' + +'length error' -: 3 4 ! etx 4 5 6 +'length error' -: 3 4 !~etx 4 5 6 + + +NB. x!y all size x combinations of i.y --------------------------------- + +start =: i.@-.@- +count =: <:@[ ! <:@[ + |.@start +recur =: [: ; start ,.&.> -@count <@{."0 _ comb0&.<: +test =: *@[ *. < +basis =: i.@(<: , [) +comb0 =: basis`recur @. test + +seed =: *@[ i.@{ 1 0&,:@(,&1)@>:@(-~) +c0 =: #;.1@~:@({."1"_) +grow =: c0 ([: ; i.@#@[ ,.&.> -@(+/\.)@[ <@{."0 _ ]) >: +comb1 =: [ grow@]^:(0&>.@<:@[) seed + +comb2 =: 4 : 0 + if. 0=x do. + i.1 0 + else. + k=.i.>:y-x + c=.x!&<:x+|.k + ;k,.&.>(-c){.&.><x comb2&.<:y + end. +) + +comb3 =: 4 : 0 + i=.1+x + z=.1 0$k=.i.#c=.1,~(y-x)$0 + while. i=.<:i do. z=.;k,.&.>(-c=.+/\.c){.&.><1+z end. +) + +comb4 =: 4 : 0 + z=.1 0$k=.i.#c=.1,~(y-x)$0 + for. i.x do. z=.;k,.&.>(-c=.+/\.c){.&.><1+z end. +) + +seed5=: i.@(,&0)&.> @ ({.&1) @ <: @ - +cb =: i.@# ,.&.> [: ,&.>/\. >:&.> +comb5=: [: ; [ cb@]^:[ seed5 + +comb6 =: 4 : 0 + k=. i.>:d=.y-x + z=. (d$<i.0 0),<i.1 0 + for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end. + ; z +) + +f =: 4 : 0 + 'm n'=.x + t=.y NB. m comb n + assert. ($t) -: (m!n),m + assert. t e.i.n + assert. m=#@~."1 t + assert. t -: ~.t + assert. (i.#t) -: /:t + assert. (i.m)-:"1 /:"1 t + 1 +) + +(f comb0/)"1 (i.6),.5 +(f comb0/) 4 4 +(f comb0/) 0 4 +(f comb0/) 0 0 + +(f comb1/)"1 (i.6),.5 +(f comb1/) 4 4 +(f comb1/) 0 4 +(f comb1/) 0 0 + +(f comb2/)"1 (i.6),.5 +(f comb2/) 4 4 +(f comb2/) 0 4 +(f comb2/) 0 0 + +(f comb3/)"1 (i.6),.5 +(f comb3/) 4 4 +(f comb3/) 0 4 +(f comb3/) 0 0 + +(f comb4/)"1 (i.6),.5 +(f comb4/) 4 4 +(f comb4/) 0 4 +(f comb4/) 0 0 + +(f comb5/)"1 (i.6),.5 +(f comb5/) 4 4 +(f comb5/) 0 4 +(f comb5/) 0 0 + +(f comb6/)"1 (i.6),.5 +(f comb6/) 4 4 +(f comb6/) 0 4 +(f comb6/) 0 0 + +6 (comb0 -: comb1) 11 +6 (comb0 -: comb2) 11 +6 (comb0 -: comb3) 11 +6 (comb0 -: comb4) 11 +6 (comb0 -: comb5) 11 +6 (comb0 -: comb6) 11 + +NB. n ifc c index from combination, the index of combination c +NB. n cfi i combination from index, the i-th combination of i.n +NB. (m,n) ic c (m comb0 n) i. c +NB. (m,n) ci i i{(m comb0 n) + +ifc=: 4 : 0 " 0 1 + (+/(i.#y)!x) + ((#y),x) ic y +) + +ic=: 4 : 0 " 1 + 'm n'=. x + if. 1>:m do. {.y,0 + else. + k=. {.y + i=. m-1 + j=. i+i.i-n + (+/i!k{.j) + (x-1,1+k) ic (}.y-1+k) + end. +) + +cfi=: 4 : 0 " 0 + assert. 0<=y + assert. y=<.y + assert. y<2^x + v=. +/\(i.x)!x + m=. (y<v)i. 1 + (m,x) ci (y-m{0,v) +) + +ci=: 4 : 0 " 1 0 + 'm n'=. x + if. 0=m do. + i.0 + else. + v=. +/\ (m-1)!(1-m)}.i.-n + k=. (v>y) i. 1 + k,(1+k)+(x-1,1+k)ci(y-k{0,v) + end. +) + +(x{5 comb0 9) -: 5 9 ci x=:?20$5!9 +( 4 comb0 6) -: 4 6 ci i.!/4 6 + +(<:20!100x) -: 20 100x ic 80x+i.20 +(79x+(3 2$0 1 0 2 1 2),"1]3+i.18) -: 20 100x ci (20!100x)-3 2 1 + +i0=: [: ; ] ifc&.> i.@>: comb0&.> ] +i1=: i.@(2&^) +i2=: ifc&.> i.@>: comb0&.> ] +i3=: (+/\@}:@(0&,) +&.> i.&.>) @ (i.@>: ! ]) +j0=: ] cfi&.> i3 +j1=: i.@>: comb0&.> ] + +(i0 -: i1)"0 i.5 +(i2 -: i3)"0 i.5 +(j0 -: j1)"0 i.5 + + +4!:55 ;:'C a b basis c cfi ci c0 case cb' +4!:55 ;:'comb0 comb1 comb2 comb3 comb4 comb5 comb6' +4!:55 ;:'count em en ' +4!:55 ;:'f f000 f001 f010 f011 f100 f101 f110 f111 ' +4!:55 ;:'fac g gamma Gauss gm gps grecur grm grow grp ' +4!:55 ;:'i ic ifc im i0 i1 i2 i3 j0 j1 k m n p' +4!:55 ;:'pascal0 pascal1 pascal2 q re' +4!:55 ;:'recur rm sbase scorr seed seed5 sinh start stirlf stirlg Stirling ' +4!:55 ;:'t test x y z ' + +
new file mode 100644 --- /dev/null +++ b/test/g410a.ijs @@ -0,0 +1,62 @@ +NB. B ! B --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2 +(x!y) -: (#.x,.y){1 1 0 1 +(x!y) -: (z+x)!z+y [ z=.{.0 4.5 +(z!y) -: (($y)$z)!y [ z=.?2 +(x!z) -: x!($x)$z [ z=.?2 + +(x!y) -: (40$"0 x)!y [ x=. ?10$2 [ y=. ?10 40$2 +(x!y) -: x!40$"0 y [ x=. ?10 40$2 [ y=. ?10$2 + +1 1 0 1 -: 0 0 1 1 ! 0 1 0 1 + + +NB. B ! I --------------------------------------------------------------- + +x=. ?100$2 +y=. ?100$2e2 +(x!y) -: (z+x)!z+y [ z=.{.0 4.5 +(z!y) -: (($y)$z)!y [ z=.?2 +(x!z) -: x!($x)$z [ z=.?2e2 + +(x!y) -: (40$"0 x)!y [ x=. ?10$2 [ y=. +?10 40$2e2 +(x!y) -: x!40$"0 y [ x=. ?10 40$2 [ y=. +?10$2e2 + +1 1 0 1 -: 0 0 1 1 ! 0 1 0 1+4-4 + + +NB. I ! B --------------------------------------------------------------- + +x=. _1e2+?100$2e2 +y=. ?100$2 +(x!y) -: (z+x)!z+y [ z=.{.0 4.5 +(z!y) -: (($y)$z)!y [ z=._1e2+?2e2 +(x!z) -: x!($x)$z [ z=.?2 + +(x!y) -: (40$"0 x)!y [ x=. _1e2+?10$2e2 [ y=. ?10 40$2 +(x!y) -: x!40$"0 y [ x=. _1e2+?10 40$2e2 [ y=. ?10$2 + +1 1 0 1 -: (0 0 1 1+3-3) ! 0 1 0 1 + + +NB. I ! I --------------------------------------------------------------- + +x=. _1e2+?100$2e2 +y=. _1e2+?100$2e2 +(x!y) -: (z+x)!z+y [ z=.{.0 4.5 +(z!y) -: (($y)$z)!y [ z=._1e2+?2e2 +(x!z) -: x!($x)$z [ z=._1e2+?2e2 + +(x!y) -: (40$"0 x)!y [ x=. _1e2+?10$2e2 [ y=. _1e2+?10 40$2e2 +(x!y) -: x!40$"0 y [ x=. _1e2+?10 40$2e2 [ y=. _1e2+?10$2e2 + +1 1 0 1 -: (0 0 1 1+3-3) ! 0 1 0 1+3-3 + +'domain error' -: 1 ! etx 'chthonic' +'domain error' -: 0 0 ! etx ;:'sui generis' + +4!:55 ;:'x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g410i.ijs @@ -0,0 +1,27 @@ +NB. !/ B --------------------------------------------------------------- + +1 1 0 1 -: !/ 0 0 1 1 ,: 0 1 0 1 + +bang=: 4 : 'x!y' + +(!/"1 -: bang/"1) x=.?3 5 17$2 +(!/"2 -: bang/"2) x +(!/"3 -: bang/"3) x + +(!/"1 -: bang/"1) x=.?3 5 32$2 +(!/"2 -: bang/"2) x +(!/"3 -: bang/"3) x + +(!/"1 -: bang/"1) x=.?3 8 32$2 +(!/"2 -: bang/"2) x +(!/"3 -: bang/"3) x + +f=: 3 : '(!/ -: bang/) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +4!:55 ;:'f bang x' + +
new file mode 100644 --- /dev/null +++ b/test/g410p.ijs @@ -0,0 +1,34 @@ +NB. !/\ B --------------------------------------------------------------- + +(0 0 1 1,: 1 1 0 1) -: !/\ 0 0 1 1 ,: 0 1 0 1 +(20$ 1 ) -: !/\20$1 +(0<i.20) -: !/\20$0 + +bang=. 4 : 'x!y' + +(!/\"1 -: bang/\"1) #:i.16 +(!/\"1 -: bang/\"1) #:i.32 + +(!/\ -: bang/\ ) x=.0<? 13$4 +(!/\ -: bang/\ ) x=.0<?7 13$4 +(!/\"1 -: bang/\"1) x +(!/\ -: bang/\ ) x=.0<?3 5 13$4 +(!/\"1 -: bang/\"1) x +(!/\"2 -: bang/\"2) x + +(!/\ -: bang/\ ) x=.0<? 16$4 +(!/\ -: bang/\ ) x=.0<?8 16$4 +(!/\"1 -: bang/\"1) x +(!/\ -: bang/\ ) x=.0<?2 4 16$4 +(!/\"1 -: bang/\"1) x +(!/\"2 -: bang/\"2) x + +(,'j') -: !/\'j' +(,<'ace') -: !/\<'ace' + +'domain error' -: !/\ etx 'sesquipedalian' +'domain error' -: !/\ etx ;:'super cali fragi listic espi ali do cious' + +4!:55 ;:'bang x' + +
new file mode 100644 --- /dev/null +++ b/test/g410s.ijs @@ -0,0 +1,18 @@ +NB. !/\. B ------------------------------------------------------------- + +(1 1 0 1,:0 1 0 1) -: <:/\. 0 0 1 1 ,: 0 1 0 1 + +outof=: 4 : 'x!y' + +f=: 3 : '(!/\. -: outof/\.) y ?@$ 2' +,f"1 x=.7 8 9,."0 1 [ _1 0 1+ 255 +,f"1 |."1 x +,f"1 x=.7 8 9,."0 1 [ _1 0 1+4*255 +,f"1 |."1 x + +'domain error' -: !/\. etx 'deipnosophist' +'domain error' -: !/\. etx ;:'professors in New England' + +4!:55 ;:'f outof x' + +
new file mode 100644 --- /dev/null +++ b/test/g411.ijs @@ -0,0 +1,225 @@ +NB. ":!.n --------------------------------------------------------------- + +'1.23457' -: ":x=:1.23456789012345 +'1.23457' -: ":!.6 x +'1.23456789012' -: ":!.12 x +'123456789' -: ":y=:123456789 +'123456789' -: ":!.4 y + +'domain error' -: ex '":!.''8''' +'domain error' -: ex '":!.0 ' +'domain error' -: ex '":!.0.7 ' +'domain error' -: ex '":!.(<5) ' +'rank error' -: ex '":!.12 13' +'limit error' -: ex '":!.67 ' + + +NB. ^!.n ---------------------------------------------------------------- + +k=:0.25*_50+?100 +x=:0.25*_50+?100 +f =: 4 : '*/x+(i.y)*k' " 0 + +x (^!.k -: f) 0 +x (^!.k -: f) 1 +x (^!.k -: f) 2 +x (^!.k -: f) 3 + +k=:0.25*_50+? 100 +x=:0.25*_50+?13$100 +x (^!.k/ -: f/) n=:?7$20 + +'domain error' -: ex '^!.''8''' +'domain error' -: ex '^!.(<8) ' + + +NB. p.^!.n -------------------------------------------------------------- + +k =:0.01*_100+?200 +f =: 4 : '+/x*y^!.k i.#x' " 1 0 +p =: _10+?5$20 +p (p.!.k -: f) x=:?3 5$10 + +'domain error' -: ex 'p.!.''8''' +'domain error' -: ex 'p.!.(<8) ' + +(4 5$!.'' x) -: 4 5$x,(20-#x)$0 [ x=:?7$1000 +(4 5$!.9 x) -: 4 5$x,(20-#x)$9 +(4 5$!.9.5 x) -: 4 5$x,(20-#x)$9.5 +(4 5$!.9 x) -: 4 5$x,(20-#x)$9 [ x=:r.?12$111 +(4 5$!.9 x) -: 4 5$x=:?22$1000 +(4 5$!.'' x) -: 4 5$x,(20-#x)$' ' [ x=:'kakistocracy' +(4 5$!.'q' x) -: 4 5$x,(20-#x)$'q' +(4 5$!.(<3) x) -: 4 5$x,(20-#x)$<3 [ x=:;:'anti dis establish ment arian ism' + +'domain error' -: 3 4 $!.'a' etx 4 5 6 +'domain error' -: 3 4 $!.'a' etx 4;5;6 +'domain error' -: 3 4 $!.4 etx 'abc' +'domain error' -: 3 4 $!.4 etx <"0 i.4 +'domain error' -: 3 4 $!.(<4)etx 'abc' +'domain error' -: 3 4 $!.(<4)etx 4 5 6 + +'rank error' -: ex '$!.(i.2 3) ' +'length error' -: ex '$!.1 2 ' +'length error' -: ex '$!.(,''a'')' + + +NB. #!.n ---------------------------------------------------------------- + +f =: 4 : '(+.x) #&, y,.k' + +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:?10$1000 [ k=:123 +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:?10$1000 [ k=:0 +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:?10$1000 [ k=:2.3 +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:?10$1000 [ k=:2j3 +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:o.?10$100 [ k=:0 + +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:a.{~?10$#a. [ k=:'x' +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:a.{~?10$#a. [ k=:' ' + +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:10$;:'on a clear day' [ k=:<'see forever' +(x f y) -: x #!.k y [ x=:j./?2 10$20 [ y=:10$;:'on a clear day' [ k=:<$0 + +'domain error' -: 3j4 5 #!.'a' etx 4 5 +'domain error' -: 3j4 5 #!.'a' etx 4;5 +'domain error' -: 3j4 5 #!.4 etx 'ab' +'domain error' -: 3j4 5 #!.4 etx 4;5 +'domain error' -: 3j4 5 #!.(<4)etx 'ab' +'domain error' -: 3j4 5 #!.(<4)etx 4 5 + +'rank error' -: ex '#!.(i.2 3) ' +'rank error' -: ex '#!.($0) ' +'rank error' -: ex '#!.1 2 ' +'rank error' -: ex '#!.(,''a'')' + + +NB. {.!.n --------------------------------------------------------------- + +(20{.!.0 x) -: x,(20-#x)$0 [ x=:?7$1000 +(20{.!.19 x) -: x,(20-#x)$19 [ x=:?7$1000 +(20{.!.1.9 x) -: x,(20-#x)$1.9 [ x=:?7$1000 +(20{.!.1j9 x) -: x,(20-#x)$1j9 [ x=:?7$1000 +(20{.!.9 x) -: 20$x=:?25$1000 +(20{.!.'x' x) -: x,(20-#x)$'x' [ x=:'chthonic' +(20{.!.' ' x) -: x,(20-#x)$' ' +(20{.!.'x' x) -: 20$x [ x=:27$'rapport' +(20{.!.(<12)x) -: x,(20-#x)$<12 [ x=:;:'Cogito, ergo sum.' +(20{.!.a: x) -: x,(20-#x)$<$0 +(20{.!.(<12)x) -: 20$x [ x=:27$;:'Cogito, ergo sum.' + +'domain error' -: 34 {.!.'a' etx 4 5 6 +'domain error' -: 34 {.!.'a' etx 4;5;6 +'domain error' -: 34 {.!.4 etx 'abc' +'domain error' -: 34 {.!.4 etx <"0 i.4 +'domain error' -: 34 {.!.(<4)etx 'abc' +'domain error' -: 34 {.!.(<4)etx 4 5 6 + +'rank error' -: ex '{.!.(i.2 3) ' +'rank error' -: ex '{.!.1 2 ' +'rank error' -: ex '{.!.(,''a'')' + + +NB. |.!.n --------------------------------------------------------------- + +(2|.!.'' x) -: 2}.x,2$0 [ x=:?7$1000 +(2|.!.19 x) -: 2}.x,2$19 [ x=:?7$1000 +(2|.!.1.9 x) -: 2}.x,2$1.9 [ x=:?7$1000 +(2|.!.1j9 x) -: 2}.x,2$1j9 [ x=:?7$1000 +(0|.!.9 x) -: x=:?25$1000 +(2|.!.'x' x) -: 2}.x,2$'x' [ x=:'chthonic' +(2|.!.'' x) -: 2}.x,2$' ' +(0|.!.'x' x) -: x=:27$'chthonic' +(2|.!.(<12)x) -: 2}.x,2$<12 [ x=:;:'Cogito, ergo sum.' +(2|.!.'' x) -: 2}.x,2$<$0 +(0|.!.(<12)x) -: x=:27$;:'Cogito, ergo sum.' + +'domain error' -: 34 |.!.'a' etx 4 5 6 +'domain error' -: 34 |.!.'a' etx 4;5;6 +'domain error' -: 34 |.!.4 etx 'abc' +'domain error' -: 34 |.!.4 etx <"0 i.4 +'domain error' -: 34 |.!.(<4)etx 'abc' +'domain error' -: 34 |.!.(<4)etx 4 5 6 + +'rank error' -: ex '|.!.(i.2 3) ' + +'length error' -: ex '|.!.1 2 ' +'length error' -: ex '|.!.(,''a'')' + + +NB. ,!.n ---------------------------------------------------------------- + +'domain error' -: 2 4 ,!.'a' etx 2 5$4 5 6 +'domain error' -: 2 4 ,!.'a' etx 2 5$4;5;6 +'domain error' -: 2 4 ,!.4 etx 2 5$'abc' +'domain error' -: 2 4 ,!.4 etx 2 5$<"0 i.4 +'domain error' -: 2 4 ,!.(<4)etx 2 5$'abc' +'domain error' -: 2 4 ,!.(<4)etx 2 5$4 5 6 + +'rank error' -: ex ',!.(i.2 3) ' +'rank error' -: ex ',!.1 2 ' +'rank error' -: ex ',!.(,''a'')' + + +NB. ,.!.n --------------------------------------------------------------- + +'domain error' -: (i.2 4) ,.!.'a' etx 2 1 5$4 5 6 +'domain error' -: (i.2 4) ,.!.'a' etx 2 1 5$4;5;6 +'domain error' -: (i.2 4) ,.!.4 etx 2 1 5$'abc' +'domain error' -: (i.2 4) ,.!.4 etx 2 1 5$<"0 i.4 +'domain error' -: (i.2 4) ,.!.(<4)etx 2 1 5$'abc' +'domain error' -: (i.2 4) ,.!.(<4)etx 2 1 5$4 5 6 + +'rank error' -: ex ',.!.(i.2 3) ' +'rank error' -: ex ',.!.1 2 ' +'rank error' -: ex ',.!.(,''a'')' + + +NB. ,:!.n --------------------------------------------------------------- + +'domain error' -: 3 4 ,:!.'a' etx 4 5 6 +'domain error' -: 3 4 ,:!.'a' etx 4;5;6 +'domain error' -: 3 4 ,:!.4 etx 'abc' +'domain error' -: 3 4 ,:!.4 etx <"0 i.4 +'domain error' -: 3 4 ,:!.(<4)etx 'abc' +'domain error' -: 3 4 ,:!.(<4)etx 4 5 6 + +'rank error' -: ex ',:!.(i.2 3) ' +'rank error' -: ex ',:!.1 2 ' +'rank error' -: ex ',:!.(,''a'')' + + +NB. !. comparison tolerance --------------------------------------------- + +i=:i.22 +v=:1+10^-i +(1=v) -: 1 =!.(2^_44) v +(1=v) -: 14 8#0 1 +(1=!.0 v) *./ .<: 16 6#0 1 + +0 0 0 0 1 -: _ = ] __ 1 2 3 _ +0 0 0 0 1 -: _ =!.0 ] __ 1 2 3 _ +1 0 0 0 0 -: __ = ] __ 1 2 3 _ +1 0 0 0 0 -: __ =!.0 ] __ 1 2 3 _ + +'domain error' -: ex '= !.''a'' ' +'domain error' -: ex '~:!.1 ' +'domain error' -: ex '> !.3j4 ' +'domain error' -: ex '<:!.(<3 4) ' +'domain error' -: ex '= !.1e_7 ' + +'rank error' -: ex '>:!.1e_14 0' + + +NB. x v!.f y where x is extended and v requires fill -------------------- + +(8x {.!.17 y) -: 8 {.!.17 y=: 1 2 +((17r2-1r2) {.!.17 y) -: 8 {.!.17 y +(8x $ !.17 y) -: 8 $ !.17 y=: 1 2 +((17r2-1r2) $ !.17 y) -: 8 $ !.17 y +(8x |.!.17 y) -: 8 |.!.17 y=: i.20 +((17r2-1r2) |.!.17 y) -: 8 |.!.17 y + + +4!:55 ;:'f i k n p v x y' + +
new file mode 100644 --- /dev/null +++ b/test/g412.ijs @@ -0,0 +1,51 @@ +NB. !: treatement of placeholder argument ------------------------------- + +F=: 2 : 0 + assert. 'rank error' -: m!:n etx 0 + assert. 'rank error' -: m!:n etx 'a' + assert. 'length error' -: m!:n etx 0 1 + assert. 'length error' -: m!:n etx 'ab' + 1 +) + +pc=: (9!:12 '') e. 0 1 2 6 7 + +1 F 20 +". pc#'1 F 30' +4 F 3 +6 F 8 +6 F 9 +7 F 0 +7 F 3 +9 F 0 +9 F 2 +9 F 6 +9 F 8 +9 F 10 +9 F 12 +9 F 14 +9 F 16 +9 F 18 +9 F 20 +9 F 24 +9 F 26 +9 F 28 +9 F 32 +9 F 34 +9 F 36 +9 F 38 +9 F 40 +13 F 1 +13 F 2 +13 F 4 +13 F 5 +13 F 13 +13 F 14 +13 F 17 +13 F 18 +18 F 5 + + +4!:55 ;:'F pc' + +
new file mode 100644 --- /dev/null +++ b/test/g420.ijs @@ -0,0 +1,691 @@ +NB. f/y for atomic verbs ------------------------------------------------ + +insert =: 1 : '{. ` ({. x $:@}.) @. (1&<@#)' NB. one or more items + +(= /t) -: = insert t=: 20 ?@$ 2 +(< /t) -: < insert t +(<./t) -: <.insert t +(<:/t) -: <:insert t +(> /t) -: > insert t +(>./t) -: >.insert t +(>:/t) -: >:insert t +(+ /t) -: + insert t +(+./t) -: +.insert t +(+:/t) -: +:insert t +(* /t) -: * insert t +(*./t) -: *.insert t +(*:/t) -: *:insert t +(- /t) -: - insert t +(% /t) -: % insert t +(^ /t) -: ^ insert t +(~:/t) -: ~:insert t +(| /t) -: | insert t +(! /t) -: ! insert t + +(= /"1 t) -: = insert"1 t=: #:i.16 +(< /"1 t) -: < insert"1 t +(<./"1 t) -: <.insert"1 t +(<:/"1 t) -: <:insert"1 t +(> /"1 t) -: > insert"1 t +(>./"1 t) -: >.insert"1 t +(>:/"1 t) -: >:insert"1 t +(+ /"1 t) -: + insert"1 t +(+./"1 t) -: +.insert"1 t +(+:/"1 t) -: +:insert"1 t +(* /"1 t) -: * insert"1 t +(*./"1 t) -: *.insert"1 t +(*:/"1 t) -: *:insert"1 t +(- /"1 t) -: - insert"1 t +(% /"1 t) -: % insert"1 t +(^ /"1 t) -: ^ insert"1 t +(~:/"1 t) -: ~:insert"1 t +(| /"1 t) -: | insert"1 t +(! /"1 t) -: ! insert"1 t + +(= /t) -: = insert t=: 10 17 ?@$2 +(< /t) -: < insert t +(<./t) -: <.insert t +(<:/t) -: <:insert t +(> /t) -: > insert t +(>./t) -: >.insert t +(>:/t) -: >:insert t +(+ /t) -: + insert t +(+./t) -: +.insert t +(+:/t) -: +:insert t +(* /t) -: * insert t +(*./t) -: *.insert t +(*:/t) -: *:insert t +(- /t) -: - insert t +(% /t) -: % insert t +(^ /t) -: ^ insert t +(~:/t) -: ~:insert t +(| /t) -: | insert t +(! /t) -: ! insert t + +(= /t) -: = insert t=: 10 1 1 1 ?@$2 +(< /t) -: < insert t +(<./t) -: <.insert t +(<:/t) -: <:insert t +(> /t) -: > insert t +(>./t) -: >.insert t +(>:/t) -: >:insert t +(+ /t) -: + insert t +(+./t) -: +.insert t +(+:/t) -: +:insert t +(* /t) -: * insert t +(*./t) -: *.insert t +(*:/t) -: *:insert t +(- /t) -: - insert t +(% /t) -: % insert t +(^ /t) -: ^ insert t +(~:/t) -: ~:insert t +(| /t) -: | insert t +(! /t) -: ! insert t + +(<./t) -: <.insert t=: ?20 ?@$1e6 +(>./t) -: >.insert t +(+ /t) -: + insert t +(+./t) -: +.insert t +(* /t) -: * insert t +(*./t) -: *.insert t +(- /t) -: - insert t +(% /t) -: % insert t + +(<./t) -: <.insert t=:?10 17$1e6 +(>./t) -: >.insert t=:?10 17$1e6 +(+ /t) -: + insert t=:?10 17$1e6 +(+./t) -: +.insert t=:?10 17$1e6 +(* /t) -: * insert t=:?10 17$1e6 +(*./t) -: *.insert t=:?10 17$1e6 +(- /t) -: - insert t=:?10 17$1e6 +(% /t) -: % insert t=:?10 17$1e6 + +(<./t) -: <.insert t=:o.?20$1e6 +(>./t) -: >.insert t=:o.?20$1e6 +(+ /t) -: + insert t=:o.?20$1e6 +(+./t) -: +.insert t=:o.?20$1e6 +(* /t) -: * insert t=:o.?20$1e6 +(*./t) -: *.insert t=:o.?20$1e6 +(- /t) -: - insert t=:o.?20$1e6 +(% /t) -: % insert t=:o.?20$1e6 + +(<./t) -: <.insert t=:o.?10 17$1e6 +(>./t) -: >.insert t=:o.?10 17$1e6 +(+ /t) -: + insert t=:o.?10 17$1e6 +(+./t) -: +.insert t=:o.?10 17$1e6 +(* /t) -: * insert t=:o.?10 17$1e6 +(*./t) -: *.insert t=:o.?10 17$1e6 +(- /t) -: - insert t=:o.?10 17$1e6 +(% /t) -: % insert t=:o.?10 17$1e6 + +(i.53) -: +/@($&1)"0 i.53 +*./ (+/ -: {.@(+/)@(,.&0))@:?@($&2)"0 [?29$13193 + + +NB. ,/ ------------------------------------------------------------------ + +insert =: 1 : '{. ` ({. x $:@}.) @. (1&<@#)' NB. one or more items + +(,/t) -: ,insert t=:7 +(,/t) -: ,insert t=:'abc' +(,/t) -: ,insert t=: ,'a' +(,/t) -: ,insert t=:?7 0$1000 +(,/t) -: ,insert t=:?7 1$1000 +(,/t) -: ,insert t=:?7 9$1000 +(,/t) -: ,insert t=:?1 7$1000 +(,/t) -: ,insert t=:7 2$;:'Cogito, ergo sum.' +(,/t) -: ,insert t=:o.?2 7 3$1000 +(,/t) -: ,insert t=:?2 0 7 3$1000 +(,/t) -: ,insert t=:r.?7 2 3 1 1$10000 + +'limit error' -: ,/ etx (>IF64{2e5 1.5e4 0;2e13 1e7 0) $ 0 +'limit error' -: ,/ etx (>IF64{1e9 1e9 0;4e18 4e18 0) $ 0 + + +NB. ;/ ------------------------------------------------------------------ + +(;/a) -: <"_1 a=:?10 20$1000 +a=:4 5$(;:'sui generis'),<"0 ?20$1000 +(;/a) -: (0{a);(1{a);(2{a);3{a + + +NB. f/ identity functions ----------------------------------------------- + +(s$0) -: +/i.0,s [ s=:?(?5)$10 +(s$0) -: -/i.0,s [ s=:?(?5)$10 +(s$1) -: */i.0,s [ s=:?(?5)$10 +(s$1) -: %/i.0,s [ s=:?(?5)$10 +(s$1) -: %:/i.0,s [ s=:?(?5)$10 +(s$1) -: =/i.0,s [ s=:?(?5)$10 +(s$0) -: ~:/i.0,s [ s=:?(?5)$10 +(s$0) -: </i.0,s [ s=:?(?5)$10 +(s$0) -: >/i.0,s [ s=:?(?5)$10 +(s$1) -: >:/i.0,s [ s=:?(?5)$10 +(s$1) -: <:/i.0,s [ s=:?(?5)$10 +(s$1) -: ^/i.0,s [ s=:?(?5)$10 +(s$0) -: |/i.0,s [ s=:?(?5)$10 +(s$1) -: !/i.0,s [ s=:?(?5)$10 +(s$1) -: *./i.0,s [ s=:?(?5)$10 +(s$0) -: +./i.0,s [ s=:?(?5)$10 + +(s$1) -: 1 b./i.0,s [ s=:?(?5)$10 +(s$0) -: 2 b./i.0,s [ s=:?(?5)$10 +(s$0) -: 4 b./i.0,s [ s=:?(?5)$10 +(s$0) -: 6 b./i.0,s [ s=:?(?5)$10 +(s$0) -: 7 b./i.0,s [ s=:?(?5)$10 +(s$1) -: 9 b./i.0,s [ s=:?(?5)$10 +(s$1) -: 11 b./i.0,s [ s=:?(?5)$10 +(s$1) -: 13 b./i.0,s [ s=:?(?5)$10 + +-.0 e.,(s$_1e50) >: >./i.0,s [ s=:?(?5)$10 +-.0 e.,(s$ 1e50) <: <./i.0,s [ s=:?(?5)$10 +(<./'') -: ->./'' + +(i.0,}.s) -: ,/i.0,s [ s=:?(?5)$10 + +f =: =@/:@{. +(f x) -: + / .* /x [ x=: i.0,?(?5)$10 +(f x) -: + / .* /x [ x=: i.0 +(f x) -: +./ .*./x [ x=: i.0,?(?5)$10 +(f x) -: ~:/ .*./x [ x=: i.0,?(?5)$10 +(f x) -: %./x [ x=: i.0,?(?5)$10 + +f =: /:@{. +(f x) -: { /x [ x=:i.0,?(?5)$10 +(f x) -: { /x [ x=:i.0 +(f x) -: C./x [ x=:i.0,?(?5)$10 +(f x) -: C./x [ x=:i.0 + +(s$1) -: +&.^./i.0,s [ s=:?(?5)$10 +(s$<$0) -: ,&.>/i.0,s [ s=:?(?5)$10 +(<$0) -: ,&.>/'' +(s$5) -: *&.(_4&+)/i.0,s [ s=:?(?5)$10 + +(4 5$0) -: + /i.0 4 5 +0 -: +/ /i.0 4 5 +(4 5$0) -: *&.^ /i.0 4 5 +0 -: *&.^/ /i.0 4 5 +(4 5$1) -: * /i.0 4 5 +1 -: */ /i.0 4 5 +(4 5$1) -: +&.^. /i.0 4 5 +1 -: +&.^.//i.0 4 5 + + +NB. +/b ----------------------------------------------------------------- + +rand =: 3 : 'x=: y ?@$ 2' +(+/ -: +/@(0&+))@rand"0 i.30 +(+/ -: +/@(0&+))@rand"0 ?10$10000 + +(+/ -: +/"1@|: )@rand"1 [20 20,20 59,61 23,10 10#:i.100 +(+/ -: +/"1@|: )@rand"1 ?20 2$1000 50 + + +NB. f/"r y -------------------------------------------------------------- + +4!:55 ;:'f g x' + +g =: 3 : 0 + n=.#y + if. 0=n do. f/y return. end. + i=.1 + z=.{:y + while. n>:i=.>:i do. z=.((-i){y) f z end. +) + +f =: + +((+/ -: f/ ), +/ -: g ) x =: _1e7+?2 3 7 13$2e7 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x +((+/ -: f/ ), +/ -: g ) x =: _1e7+?2 3 0 13$2e7 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x +((+/ -: f/ ), +/ -: g ) x =: _1e7+?2 3 1 7$2e7 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x +((+/ -: f/ ), +/ -: g ) x =: ?2 3 4 5$2e9 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x +((+/ -: f/ ), +/ -: g ) x =: o._1e7+?2 3 4 5$2e7 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x +((+/ -: f/ ), +/ -: g ) x =: ?3 4 5 7$2 +((+/"1 -: f/"1), +/"1 -: g"1) x +((+/"2 -: f/"2), +/"2 -: g"2) x +((+/"3 -: f/"3), +/"3 -: g"3) x + +f =: +. +((+./ -: f/ ), +./ -: g ) x =: _1e7+?2 3 1 7$2e7 +((+./"1 -: f/"1), +./"1 -: g"1) x +((+./"2 -: f/"2), +./"2 -: g"2) x +((+./"3 -: f/"3), +./"3 -: g"3) x +((+./ -: f/ ), +./ -: g ) x =: ?2 3 1 7$2 +((+./"1 -: f/"1), +./"1 -: g"1) x +((+./"2 -: f/"2), +./"2 -: g"2) x +((+./"3 -: f/"3), +./"3 -: g"3) x + +f =: +: +((+:/ -: f/ ), +:/ -: g ) x =: ?2 3 1 7$2 +((+:/"1 -: f/"1), +:/"1 -: g"1) x +((+:/"2 -: f/"2), +:/"2 -: g"2) x +((+:/"3 -: f/"3), +:/"3 -: g"3) x + +f =: - +((-/ -: f/ ), -/ -: g ) x =: _1e7+?2 3 8 13$2e7 +((-/"1 -: f/"1), -/"1 -: g"1) x +((-/"2 -: f/"2), -/"2 -: g"2) x +((-/"3 -: f/"3), -/"3 -: g"3) x +((-/ -: f/ ), -/ -: g ) x =: ?2 3 8 13$2 +((-/"1 -: f/"1), -/"1 -: g"1) x +((-/"2 -: f/"2), -/"2 -: g"2) x +((-/"3 -: f/"3), -/"3 -: g"3) x + +f =: * +((*/ -: f/ ), */ -: g ) x =: >:?2 3 1 7$10 +((*/"1 -: f/"1), */"1 -: g"1) x +((*/"2 -: f/"2), */"2 -: g"2) x +((*/"3 -: f/"3), */"3 -: g"3) x +((*/ -: f/ ), */ -: g ) x =: >:?5 3 1 7$1000 +((*/"1 -: f/"1), */"1 -: g"1) x +((*/"2 -: f/"2), */"2 -: g"2) x +((*/"3 -: f/"3), */"3 -: g"3) x +((*/ -: f/ ), */ -: g ) x =: o._500+?5 3 1 7$1000 +((*/"1 -: f/"1), */"1 -: g"1) x +((*/"2 -: f/"2), */"2 -: g"2) x +((*/"3 -: f/"3), */"3 -: g"3) x +((*/ -: f/ ), */ -: g ) x =: ?3 6 1 8$2 +((*/"1 -: f/"1), */"1 -: g"1) x +((*/"2 -: f/"2), */"2 -: g"2) x +((*/"3 -: f/"3), */"3 -: g"3) x + +f =: *. +((*./ -: f/ ), *./ -: g ) x =: >:?2 3 1 7$10 +((*./"1 -: f/"1), *./"1 -: g"1) x +((*./"2 -: f/"2), *./"2 -: g"2) x +((*./"3 -: f/"3), *./"3 -: g"3) x +((*./ -: f/ ), *./ -: g ) x =: >:?5 3 1 7$1000 +((*./"1 -: f/"1), *./"1 -: g"1) x +((*./"2 -: f/"2), *./"2 -: g"2) x +((*./"3 -: f/"3), *./"3 -: g"3) x +((*./ -: f/ ), *./ -: g ) x =: o._500+?5 3 1 7$1000 +((*./"1 -: f/"1), *./"1 -: g"1) x +((*./"2 -: f/"2), *./"2 -: g"2) x +((*./"3 -: f/"3), *./"3 -: g"3) x +((*./ -: f/ ), *./ -: g ) x =: ?3 6 1 8$2 +((*./"1 -: f/"1), *./"1 -: g"1) x +((*./"2 -: f/"2), *./"2 -: g"2) x +((*./"3 -: f/"3), *./"3 -: g"3) x + +f =: *: +((*:/ -: f/ ), *:/ -: g ) x =: ?3 6 1 8$2 +((*:/"1 -: f/"1), *:/"1 -: g"1) x +((*:/"2 -: f/"2), *:/"2 -: g"2) x +((*:/"3 -: f/"3), *:/"3 -: g"3) x + +f =: % +((%/ -: f/ ), %/ -: g ) x =: >:?3 6 1 8$14 +((%/"1 -: f/"1), %/"1 -: g"1) x +((%/"2 -: f/"2), %/"2 -: g"2) x +((%/"3 -: f/"3), %/"3 -: g"3) x +((%/ -: f/ ), %/ -: g ) x =: o.>:7?3 6 1 8$14 +((%/"1 -: f/"1), %/"1 -: g"1) x +((%/"2 -: f/"2), %/"2 -: g"2) x +((%/"3 -: f/"3), %/"3 -: g"3) x +((%/ -: f/ ), %/ -: g ) x =: ?3 6 1 8$2 +((%/"1 -: f/"1), %/"1 -: g"1) x +((%/"2 -: f/"2), %/"2 -: g"2) x +((%/"3 -: f/"3), %/"3 -: g"3) x + +f =: = +((=/ -: f/ ), =/ -: g ) x =: _26+?3 6 1 8$52 +((=/"1 -: f/"1), =/"1 -: g"1) x +((=/"2 -: f/"2), =/"2 -: g"2) x +((=/"3 -: f/"3), =/"3 -: g"3) x +((=/ -: f/ ), =/ -: g ) x =: o._26+?3 6 1 8$52 +((=/"1 -: f/"1), =/"1 -: g"1) x +((=/"2 -: f/"2), =/"2 -: g"2) x +((=/"3 -: f/"3), =/"3 -: g"3) x +((=/ -: f/ ), =/ -: g ) x =: ?3 6 1 8$2 +((=/"1 -: f/"1), =/"1 -: g"1) x +((=/"2 -: f/"2), =/"2 -: g"2) x +((=/"3 -: f/"3), =/"3 -: g"3) x + +f =: ~: +((~:/ -: f/ ), ~:/ -: g ) x =: _26+?3 6 1 8$52 +((~:/"1 -: f/"1), ~:/"1 -: g"1) x +((~:/"2 -: f/"2), ~:/"2 -: g"2) x +((~:/"3 -: f/"3), ~:/"3 -: g"3) x +((~:/ -: f/ ), ~:/ -: g ) x =: o._26+?3 6 1 8$52 +((~:/"1 -: f/"1), ~:/"1 -: g"1) x +((~:/"2 -: f/"2), ~:/"2 -: g"2) x +((~:/"3 -: f/"3), ~:/"3 -: g"3) x +((~:/ -: f/ ), ~:/ -: g ) x =: ?3 6 1 8$2 +((~:/"1 -: f/"1), ~:/"1 -: g"1) x +((~:/"2 -: f/"2), ~:/"2 -: g"2) x +((~:/"3 -: f/"3), ~:/"3 -: g"3) x + +f =: < +((</ -: f/ ), </ -: g ) x =: _17+?2 3 1 13$34 +((</"1 -: f/"1), </"1 -: g"1) x +((</"2 -: f/"2), </"2 -: g"2) x +((</"3 -: f/"3), </"3 -: g"3) x +((</ -: f/ ), </ -: g ) x =: o._17+?2 3 1 13$34 +((</"1 -: f/"1), </"1 -: g"1) x +((</"2 -: f/"2), </"2 -: g"2) x +((</"3 -: f/"3), </"3 -: g"3) x +((</ -: f/ ), </ -: g ) x =: ?2 3 1 13$2 +((</"1 -: f/"1), </"1 -: g"1) x +((</"2 -: f/"2), </"2 -: g"2) x +((</"3 -: f/"3), </"3 -: g"3) x + +f =: <. +((<./ -: f/ ), <./ -: g ) x =: _1e7+?2 3 1 13$2e7 +((<./"1 -: f/"1), <./"1 -: g"1) x +((<./"2 -: f/"2), <./"2 -: g"2) x +((<./"3 -: f/"3), <./"3 -: g"3) x +((<./ -: f/ ), <./ -: g ) x =: o._1e7+?2 3 1 13$2e7 +((<./"1 -: f/"1), <./"1 -: g"1) x +((<./"2 -: f/"2), <./"2 -: g"2) x +((<./"3 -: f/"3), <./"3 -: g"3) x +((<./ -: f/ ), <./ -: g ) x =: ?2 3 1 13$2 +((<./"1 -: f/"1), <./"1 -: g"1) x +((<./"2 -: f/"2), <./"2 -: g"2) x +((<./"3 -: f/"3), <./"3 -: g"3) x + +f =: <: +((<:/ -: f/ ), <:/ -: g ) x =: _1e7+?2 3 1 13$2e7 +((<:/"1 -: f/"1), <:/"1 -: g"1) x +((<:/"2 -: f/"2), <:/"2 -: g"2) x +((<:/"3 -: f/"3), <:/"3 -: g"3) x +((<:/ -: f/ ), <:/ -: g ) x =: o._1e7+?2 3 1 13$2e7 +((<:/"1 -: f/"1), <:/"1 -: g"1) x +((<:/"2 -: f/"2), <:/"2 -: g"2) x +((<:/"3 -: f/"3), <:/"3 -: g"3) x +((<:/ -: f/ ), <:/ -: g ) x =: ?2 3 1 13$2 +((<:/"1 -: f/"1), <:/"1 -: g"1) x +((<:/"2 -: f/"2), <:/"2 -: g"2) x +((<:/"3 -: f/"3), <:/"3 -: g"3) x + +f =: > +((>/ -: f/ ), >/ -: g ) x =: _1e7+?2 3 1 13$2e7 +((>/"1 -: f/"1), >/"1 -: g"1) x +((>/"2 -: f/"2), >/"2 -: g"2) x +((>/"3 -: f/"3), >/"3 -: g"3) x +((>/ -: f/ ), >/ -: g ) x =: o._1e7+?2 3 1 13$2e7 +((>/"1 -: f/"1), >/"1 -: g"1) x +((>/"2 -: f/"2), >/"2 -: g"2) x +((>/"3 -: f/"3), >/"3 -: g"3) x +((>/ -: f/ ), >/ -: g ) x =: ?2 3 1 13$2 +((>/"1 -: f/"1), >/"1 -: g"1) x +((>/"2 -: f/"2), >/"2 -: g"2) x +((>/"3 -: f/"3), >/"3 -: g"3) x + +f =: >. +((>./ -: f/ ), >./ -: g ) x =: _1e7+?2 3 1 13$2e7 +((>./"1 -: f/"1), >./"1 -: g"1) x +((>./"2 -: f/"2), >./"2 -: g"2) x +((>./"3 -: f/"3), >./"3 -: g"3) x +((>./ -: f/ ), >./ -: g ) x =: o._1e7+?2 3 1 13$2e7 +((>./"1 -: f/"1), >./"1 -: g"1) x +((>./"2 -: f/"2), >./"2 -: g"2) x +((>./"3 -: f/"3), >./"3 -: g"3) x +((>./ -: f/ ), >./ -: g ) x =: ?2 3 17 2$2 +((>./"1 -: f/"1), >./"1 -: g"1) x +((>./"2 -: f/"2), >./"2 -: g"2) x +((>./"3 -: f/"3), >./"3 -: g"3) x + +f =: >: +((>:/ -: f/ ), >:/ -: g ) x =: _1e7+?2 3 1 13$2e7 +((>:/"1 -: f/"1), >:/"1 -: g"1) x +((>:/"2 -: f/"2), >:/"2 -: g"2) x +((>:/"3 -: f/"3), >:/"3 -: g"3) x +((>:/ -: f/ ), >:/ -: g ) x =: o._1e7+?2 3 1 13$2e7 +((>:/"1 -: f/"1), >:/"1 -: g"1) x +((>:/"2 -: f/"2), >:/"2 -: g"2) x +((>:/"3 -: f/"3), >:/"3 -: g"3) x +((>:/ -: f/ ), >:/ -: g ) x =: ?2 3 1 13$2 +((>:/"1 -: f/"1), >:/"1 -: g"1) x +((>:/"2 -: f/"2), >:/"2 -: g"2) x +((>:/"3 -: f/"3), >:/"3 -: g"3) x + +f =: ! +((!/ -: f/ ), !/ -: g ) x =: _7+?3 6 1 8$14 +((!/"1 -: f/"1), !/"1 -: g"1) x +((!/"2 -: f/"2), !/"2 -: g"2) x +((!/"3 -: f/"3), !/"3 -: g"3) x +((!/ -: f/ ), !/ -: g ) x =: -:?3 2 1 4$10 +((!/"1 -: f/"1), !/"1 -: g"1) x +((!/"2 -: f/"2), !/"2 -: g"2) x +((!/"3 -: f/"3), !/"3 -: g"3) x +((!/ -: f/ ), !/ -: g ) x =: ?3 6 1 8$2 +((!/"1 -: f/"1), !/"1 -: g"1) x +((!/"2 -: f/"2), !/"2 -: g"2) x +((!/"3 -: f/"3), !/"3 -: g"3) x + +f =: ^ +((^/ -: f/ ), ^/ -: g ) x =: x+0=x=:_2+?3 4 1 2$4 +((^/"1 -: f/"1), ^/"1 -: g"1) x +((^/"2 -: f/"2), ^/"2 -: g"2) x +((^/"3 -: f/"3), ^/"3 -: g"3) x +((^/ -: f/ ), ^/ -: g ) x =: x+0=x=:-:_3+?3 4 1 2$6 +((^/"1 -: f/"1), ^/"1 -: g"1) x +((^/"2 -: f/"2), ^/"2 -: g"2) x +((^/"3 -: f/"3), ^/"3 -: g"3) x +((^/ -: f/ ), ^/ -: g ) x =: ?3 4 1 2$2 +((^/"1 -: f/"1), ^/"1 -: g"1) x +((^/"2 -: f/"2), ^/"2 -: g"2) x +((^/"3 -: f/"3), ^/"3 -: g"3) x + +f =: o. +((o./ -: f/ ), o./ -: g ) x =: ?2 2 2 2$9 +((o./"1 -: f/"1), o./"1 -: g"1) x +((o./"2 -: f/"2), o./"2 -: g"2) x +((o./"3 -: f/"3), o./"3 -: g"3) x +((o./ -: f/ ), o./ -: g ) x =: ?2 2 2 2$2 +((o./"1 -: f/"1), o./"1 -: g"1) x +((o./"2 -: f/"2), o./"2 -: g"2) x +((o./"3 -: f/"3), o./"3 -: g"3) x + +f =: | +((|/ -: f/ ), |/ -: g ) x =: _7+?3 6 1 8$14 +((|/"1 -: f/"1), |/"1 -: g"1) x +((|/"2 -: f/"2), |/"2 -: g"2) x +((|/"3 -: f/"3), |/"3 -: g"3) x +((|/ -: f/ ), |/ -: g ) x =: -:_7+?3 6 1 8$14 +((|/"1 -: f/"1), |/"1 -: g"1) x +((|/"2 -: f/"2), |/"2 -: g"2) x +((|/"3 -: f/"3), |/"3 -: g"3) x +((|/ -: f/ ), |/ -: g ) x =: ?3 6 1 8$2 +((|/"1 -: f/"1), |/"1 -: g"1) x +((|/"2 -: f/"2), |/"2 -: g"2) x +((|/"3 -: f/"3), |/"3 -: g"3) x + +f =: , +((,/ -: f/ ), ,/ -: g ) x =: a.{~?2 3 5 13$#a. +((,/"1 -: f/"1), ,/"1 -: g"1) x +((,/"2 -: f/"2), ,/"2 -: g"2) x +((,/"3 -: f/"3), ,/"3 -: g"3) x +((,/ -: f/ ), ,/ -: g ) x =: ?2 3 1 7$1e7 +((,/"1 -: f/"1), ,/"1 -: g"1) x +((,/"2 -: f/"2), ,/"2 -: g"2) x +((,/"3 -: f/"3), ,/"3 -: g"3) x + +f =: ; +((;/ -: f/ ), ;/ -: g ) x =: a.{~?2 3 5 13$#a. +((;/"1 -: f/"1), ;/"1 -: g"1) x +((;/"2 -: f/"2), ;/"2 -: g"2) x +((;/"3 -: f/"3), ;/"3 -: g"3) x +((;/ -: f/ ), ;/ -: g ) x =: ?2 3 1 7$1e7 +((;/"1 -: f/"1), ;/"1 -: g"1) x +((;/"2 -: f/"2), ;/"2 -: g"2) x +((;/"3 -: f/"3), ;/"3 -: g"3) x + +(2 3 4$+ /$0) -: + /"2 i.2 3 0 4 +(2 3 4$+./$0) -: +./"2 i.2 3 0 4 +(2 3 4$- /$0) -: - /"2 i.2 3 0 4 +(2 3 4$* /$0) -: * /"2 i.2 3 0 4 +(2 3 4$*./$0) -: *./"2 i.2 3 0 4 +(2 3 4$% /$0) -: % /"2 i.2 3 0 4 +(2 3 4$%:/$0) -: %:/"2 i.2 3 0 4 +(2 3 4$= /$0) -: = /"2 i.2 3 0 4 +(2 3 4$~:/$0) -: ~:/"2 i.2 3 0 4 +(2 3 4$> /$0) -: > /"2 i.2 3 0 4 +(2 3 4$>./$0) -: >./"2 i.2 3 0 4 +(2 3 4$>:/$0) -: >:/"2 i.2 3 0 4 +(2 3 4$< /$0) -: < /"2 i.2 3 0 4 +(2 3 4$<./$0) -: <./"2 i.2 3 0 4 +(2 3 4$<:/$0) -: <:/"2 i.2 3 0 4 + +f=: [^:(0&~:@[) +(f/ -: g ) x=: (? 15$2) * ? 15$10 +(f/"1 -: g"1) x=: (?22 15$2) * ?22 15$10 + + +NB. f/@, ---------------------------------------------------------------- + +A =: 1 : 0 + (u/@, y) -: u/,y +) + += A ?10 20 30 $2 +~: A ?10 20 30 $2 + ++ A ?10 20 30 $2 ++ A ?10 20 $100 ++ A o. ?10 20 3 4 $100 ++ A j./?2 10 20 3 $100 + ++. A ?10 20 30 $2 ++. A ?10 20 $100 + +*. A ?10 20 30 $2 +*. A ?10 20 $100 + +- A ?10 20 30 $2 +- A ?10 20 $100 +- A o. ?10 20 3 4 $100 +- A j./?2 10 20 3 $100 + +>. A ?10 20 30 $2 +>. A ?10 20 $100 +>. A o. ?10 20 3 4 $100 + +<. A ?10 20 30 $2 +<. A ?10 20 $100 +<. A o. ?10 20 3 4 $100 + +pl=: + + +pl A ?10 20 30 $2 +pl A ?10 20 $100 +pl A o. ?10 20 3 4 $100 +pl A j./?2 10 20 3 $100 + ++ A ?100 10$1e7 +* A 1+?2 10$10 + += A 0 3 4 5$1 ++. A 0 3 4 5$1 +*. A 0 3 4 5$1 +~: A 0 3 4 5$1 + +<. A 0 3 4 5$1 +<. A 4 6 0 3$200 +<. A 0 3 4 5$1.2 + +>. A 0 3 4 5$1 +>. A 4 6 0 3$200 +>. A 0 3 4 5$1.2 + ++ A 0 3 4 5$1 ++ A 4 6 0 3$200 ++ A 0 3 4 5$1.2 ++ A 4 6 0 3$1j2 + +* A 0 3 4 5$1 +* A 4 6 0 3$200 +* A 0 3 4 5$1.2 +* A 4 6 0 3$1j2 + + +NB. g/ ------------------------------------------------------------------ + +(+`%/x) -: (0{x)+(1{x)%(2{x)+(3{x)%4{x =:_500+?5 12$1000 +((<'+')/x) -: +/x + +(+`%/x) -: (0{x)+(1{x)%(2{x)+3{x =:_500+?4 12$1000 +((<'+')/x) -: +/x + +(+`%/x) -: (0{x)+(1{x)%2{x =:_500+?3 12$1000 +((<'+')/x) -: +/x + +(+`%/x) -: +/x =: _500+?2 12$1000 +((<'+')/x) -: +/x + +(+`%/x) -: {.x =: _500+?1 12$1000 +((<'+')/x) -: {.x + +(+`%/x) -: 12$0 [ x=:_500+?0 12$1000 +((<'+')/x) -: 12$0 + + +NB. x f/y --------------------------------------------------------------- + +p =: ?(>:?20)$100 +q =: ?(>:?20)$100 + +(p+"0 99 q) -: p+/q +(p*"0/q) -: p*/q +({p;q) -: p,&.>/q +({p;q) -: p<@,"0/q + +iota =: > @ (+/&.>/) @ (i.&.> *&.> */\.@}.@(,&1)) +(i. -: iota) 2 3 4 +(i. -: iota) >:?(?5)$6 +(i. -: iota) $0 + +(($x),$y) -: $(x=:i.0 ) < / y=:i.0 3 +(($x),$y) -: $(x=:i.0 ) <!.0/ y=:i.?~5 +(($x),$y) -: $(x=:i.0 ) ^ / y=:i.0 3 +(($x),$y) -: $(x=:i.0 ) ^!.0/ y=:i.?~5 +(($x),$y) -: $(x=:i.0 3) < / y=:i.0 +(($x),$y) -: $(x=:i.0 3) <!.0/ y=:i.0 +(($x),$y) -: $(x=:i.0 3) ^ / y=:i.0 +(($x),$y) -: $(x=:i.0 3) ^!.0/ y=:i.0 +(($x),$y) -: $(x=:i.0 ) < / y=:i.0 +(($x),$y) -: $(x=:i.0 ) <!.0/ y=:i.0 +(($x),$y) -: $(x=:i.0 ) ^ / y=:i.0 +(($x),$y) -: $(x=:i.0 ) ^!.0/ y=:i.0 + + +NB. +/ Magic Cubes ----------------------------------------------------- + +NB. by Professor James G. Mauldon via Ken Iverson + +MC=: #. ] | (#: i.)@(3&#) +/ .* (3 3{.3 5$3 5 4)"_ + +test=: 3 : 0 + c=: MC y + s=: {. , +/ c + assert. s = (+/ , +/"1) c + assert. s = (+/ , +/"1) (<0 1)|:c + assert. s = (+/ , +/"1) (<0 2)|:c + assert. s = (+/ , +/"1) (<1 2)|:c + assert. s = (+/ , +/"1) (<0 1 2)|:c + 1 +) + +test 11 +test 23 +test 29 + + +4!:55 ;:'A a c f g i insert iota k MC n p pl q ' +4!:55 ;:'rand s t test x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g420ce.ijs @@ -0,0 +1,53 @@ +NB. ,&.>/"r y ----------------------------------------------------------- + +c=: , + +a=: ' 0123456789',(,65 97+/i.26){a. + +f=: 3 : 0 + assert. (c&.>/ -: ,&.>/) y + for_r. i.#$y do. + assert. (c&.>/"r -: ,&.>/"r) y + end. + 1 +) + +f y=: <"0 ] _5e5+11 19 13 ?@$ 1e6 +f y=: <"0 ] 11 19 13 ?@$ 0 +f y=: <"0 a{~11 19 13 ?@$ #a + +NB. unit length axis + +f y=: <"0 a{~11 19 1 ?@$ #a +f y=: <"0 a{~11 1 13 ?@$ #a +f y=: <"0 a{~ 1 19 13 ?@$ #a + +f y=: <"0 a{~1 1 1 ?@$ #a + +NB. 0-length axis + +f y=: <"0 a{~11 19 0 ?@$ #a +f y=: <"0 a{~11 0 13 ?@$ #a +f y=: <"0 a{~ 0 19 13 ?@$ #a + +f y=: <"0 a{~0 0 0 ?@$ #a + +NB. non-boxed arguments + +f y=: _5e5+11 19 13 ?@$ 1e6 +f y=: 11 19 13 ?@$ 0 +f y=: a{~11 19 13 ?@$ #a + +NB. scalar arguments + +f y=: <4 +f y=: <4.5 +f y=: <2 3$'abcd' +f y=: 4 +f y=: 4.5 +f y=: 'a' + + +4!:55 ;:'a c f r y' + +
new file mode 100644 --- /dev/null +++ b/test/g420fg.ijs @@ -0,0 +1,105 @@ +NB. f/@:g for atomic verbs ---------------------------------------------- + +f=: ;: '! % * + - < = > ^ | <. <: >. >: +. +: *. *: ~: o.' + +testsub=: 2 : 0 + xx=: y{~101 23 ?@$ #y + yy=: y{~101 23 ?@$ #y + assert. (u/ xx v yy) -: xx u/@:v yy + assert. (u/ xx v&(0&{.) yy) -: xx u/@:v&(0&{.) yy + assert. (u/ xx v&(1&{.) yy) -: xx u/@:v&(1&{.) yy + assert. (u/ xx v&(2&{.) yy) -: xx u/@:v&(2&{.) yy + x0=: (?#y){y + y0=: (?#y){y + assert. (u/ x0 v yy) -: x0 u/@:v yy + assert. (u/ xx v y0) -: xx u/@:v y0 + 1 +) + +test=: 2 : 0 + if. 'b' e. y do. u testsub v 0 1 end. + if. 'c' e. y do. u testsub v a. end. + if. 'i' e. y do. u testsub v _1000+ 1000 ?@$ 2000 end. + if. 'd' e. y do. u testsub v 4096%~*_1000+ 1000 ?@$ 2000 end. + if. 'z' e. y do. u testsub v j./ _1000+2 1000 ?@$ 2000 end. +) + ++ test * 'bidz' ++ test *. 'bidz' ++ test +. 'bidz' ++ test < 'bid' ++ test <: 'bid' ++ test = 'bidz' ++ test ~: 'bidz' ++ test > 'bid' ++ test >: 'bid' + +>. test * 'bid' +>. test + 'bid' + +*. test +. 'b' ++. test *. 'b' += test *. 'b' +~: test *. 'b' + +space=: 7!:2 +x=: 53 7 ?@$ 1e6 +y=: 53 7 ?@$ 1e6 +p=: 13#x +q=: 13#y +300 > | -/ space 'p +/@:* q',:'x +/@:* y' +300 > | -/ space 'p ([: +/ *) q',:'x ([: +/ *) y' + +space=: 7!:2 +x=: 53 7 ?@$ 0 +y=: 53 7 ?@$ 0 +p=: 13#x +q=: 13#y +300 > | -/ space 'p +/@:* q',:'x +/@:* y' +300 > | -/ space 'p ([: +/ *) q',:'x ([: +/ *) y' + +246 -: 2 +/@:* 123 +_111 -: 12 */@:- 123 + + +NB. integer overflow handling ------------------------------------------- + +x=: 23 7 ?@$ 1e4 +y=: 23 7 ?@$ 1e5 +(+/x*y) -: x +/@:* y + +x=: 31 7 ?@$ >.imax%16 +y=: 31 7 ?@$ >.imax%16 +(+/x+y) -: x +/@:+ y + +x=: (31$1 _1) * 31 7 ?@$ >.imax%16 +y=: (31$1 _1) * 31 7 ?@$ >.imax%16 +(-/x+y) -: x -/@:+ y + +x=: 31 7 ?@$ 1e4 +y=: 31 7 ?@$ 1e4 +(+/x+ y) -: x +/@:+ y +(+/x>.y) -: x +/@:>. y + +x=: 30 7 ?@$ 1e4 +y=: 30 7 ?@$ 1e4 +(+/x+ y) -: x +/@:+ y +(+/x>.y) -: x +/@:>. y + +x=: 31 7 ?@$ >.imax%8 +y=: 31 7 ?@$ >.imax%8 +(+/x+ y) -: x +/@:+ y +(+/x>.y) -: x +/@:>. y + +x=: 30 7 ?@$ >.imax%8 +y=: 30 7 ?@$ >.imax%8 +(+/x+ y) -: x +/@:+ y +(+/x>.y) -: x +/@:>. y + +(4=3!:0 x) *. (imax-1) = x=: (2-1 1) +/@:* 1, imax-2 +(4=3!:0 x) *. (imax-2) = x=: _1 2 +/@:* 1, x:^:_1 <.imax%2x + + +4!:55 ;:'f p q space test testsub x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g420r2.ijs @@ -0,0 +1,17 @@ +NB. f/"r y over an axis of length 2 ------------------------------------- + +(= /"1 -: 4 : 'x= y'/"1) b=: 3 5 7 2 ?@$ 2 +(< /"1 -: 4 : 'x< y'/"1) b +(<./"1 -: 4 : 'x<.y'/"1) b +(<:/"1 -: 4 : 'x<:y'/"1) b +(> /"1 -: 4 : 'x> y'/"1) b +(>./"1 -: 4 : 'x>.y'/"1) b +(>:/"1 -: 4 : 'x>:y'/"1) b +(+./"1 -: 4 : 'x+.y'/"1) b +(+:/"1 -: 4 : 'x+:y'/"1) b +(*./"1 -: 4 : 'x*.y'/"1) b +(*:/"1 -: 4 : 'x*:y'/"1) b +(~:/"1 -: 4 : 'x~:y'/"1) b + + +4!:55 ;:'b' \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/g420stch.ijs @@ -0,0 +1,130 @@ +NB. ,./ ------------------------------------------------------------------ + +(,./ -: |:) x=: a.{~?1001 123$#a. + +f=: 3 : 0 + n=. #y + r=. #$y + if. 0=n do. +'domain error' end. + if. 1=n do. {.y return. end. + if. 1>:r do. + if. 2=n do. y else. (_2}.y) ,"1 0 (_2{.y) end. + return. + end. + if. 2=r do. |:y return. end. + s=. $ y + t=. ((- 2&<)#$y) $ (1{s) , (*/0 2{s,1 1), 3}.s + t ($,) (<"0 (<0 1) C. i.#$y) |: y +) + +g=: 4 : 'x,.y' + +((,./ -: g/) , ,./ -: f) x=: ? 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?0$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?1$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?2$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?3$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?4$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1,?5$8) ?@$ 1e6 + +((,./ -: g/) , ,./ -: f) x=: ?1$1e6 +((,./ -: g/) , ,./ -: f) x=: ?2$1e6 +((,./ -: g/) , ,./ -: f) x=: ?3$1e6 +((,./ -: g/) , ,./ -: f) x=: ?4$1e6 +((,./ -: g/) , ,./ -: f) x=: ?(1+?123)$1e6 + +((,./ -: g/) , ,./ -: f) x=: (1+?2$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1+?3$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1+?4$8) ?@$ 1e6 +((,./ -: g/) , ,./ -: f) x=: (1+?5$8) ?@$ 1e6 + + +(,./ etx -: f etx) i.0 + +(,./"1 etx -: f"1 etx) i.1 2 3 0 +(,./"2 etx -: f"2 etx) i.1 2 0 4 +(,./"3 etx -: f"3 etx) i.1 0 3 4 + +(,./"1 etx -: g/"1 etx) i.1 2 3 0 +(,./"2 etx -: g/"2 etx) i.1 2 0 4 +(,./"3 etx -: g/"3 etx) i.1 0 3 4 + +((,./"1 -: g/"1) , ,./"1 -: f"1) x=: (1+?2$8) ?@$ 1e6 +((,./"1 -: g/"1) , ,./"1 -: f"1) x=: (1+?3$8) ?@$ 1e6 +((,./"1 -: g/"1) , ,./"1 -: f"1) x=: (1+?4$8) ?@$ 1e6 +((,./"1 -: g/"1) , ,./"1 -: f"1) x=: (1+?5$8) ?@$ 1e6 + +((,./"2 -: g/"2) , ,./"2 -: f"2) x=: (1+?2$8) ?@$ 1e6 +((,./"2 -: g/"2) , ,./"2 -: f"2) x=: (1+?3$8) ?@$ 1e6 +((,./"2 -: g/"2) , ,./"2 -: f"2) x=: (1+?4$8) ?@$ 1e6 +((,./"2 -: g/"2) , ,./"2 -: f"2) x=: (1+?5$8) ?@$ 1e6 + +((,./"3 -: g/"3) , ,./"3 -: f"3) x=: (1+?2$8) ?@$ 1e6 +((,./"3 -: g/"3) , ,./"3 -: f"3) x=: (1+?3$8) ?@$ 1e6 +((,./"3 -: g/"3) , ,./"3 -: f"3) x=: (1+?4$8) ?@$ 1e6 +((,./"3 -: g/"3) , ,./"3 -: f"3) x=: (1+?5$8) ?@$ 1e6 + +'domain error' -: ,./ etx i.0 +'domain error' -: ,./ etx i.0,?1$10 +'domain error' -: ,./ etx i.0,?2$10 +'domain error' -: ,./ etx i.0,?3$10 + +'limit error' -: ,./ etx i. >IF64{1e7 1 1e5 0; 1e17 1 1e5 0 +'limit error' -: ,./ etx i. >IF64{3 1 1e9 0; 3 1 5e18 0 + + +NB. ,./ on sparse arguments --------------------------------------------- + +sp=: 4 : 0 + yy=: y + t=: ,./"x yy + c=: ; (i.1+r) <"1@comb&.> r=. #$y + for_d. c do. + assert. (t -: z) *. scheck z=: ,./"x s=: (2;d)$.yy + end. + 1 +) + +_ sp x=: (* $ ?@$ 2:) (1+?2$8) ?@$ 1e6 +_ sp x=: (* $ ?@$ 2:) (1+?3$8) ?@$ 1e6 +_ sp x=: (* $ ?@$ 2:) (1+?4$8) ?@$ 1e6 + +1 sp x=: (* $ ?@$ 2:) (1+?2$8) ?@$ 1e6 +1 sp x=: (* $ ?@$ 2:) (1+?3$8) ?@$ 1e6 +1 sp x=: (* $ ?@$ 2:) (1+?4$8) ?@$ 1e6 + +2 sp x=: (* $ ?@$ 2:) (1+?2$8) ?@$ 1e6 +2 sp x=: (* $ ?@$ 2:) (1+?3$8) ?@$ 1e6 +2 sp x=: (* $ ?@$ 2:) (1+?4$8) ?@$ 1e6 + +3 sp x=: (* $ ?@$ 2:) (1+?2$8) ?@$ 1e6 +3 sp x=: (* $ ?@$ 2:) (1+?3$8) ?@$ 1e6 +3 sp x=: (* $ ?@$ 2:) (1+?4$8) ?@$ 1e6 + + +NB. ,.&.>/ -------------------------------------------------------------- + +f =: 4 : 'x,.&.>y' +test =: f/ -: ,.&.>/ + +test 5$&.>'abcde' + +test ?@($&2) &.> (1+?123),&.>1+?k$20 [ k=:10 +test {&a.@?@($&(#a.)) &.> (1+?123),&.>1+?k$20 +test ?@($&1000) &.> (1+?123),&.>1+?k$20 +test o.@?@($&1000) &.> (1+?123),&.>1+?k$20 +test r.@?@($&1000) &.> (1+?123),&.>1+?k$20 +test {&x@?@($&(#x)) &.> (1+?123),&.>1+?k$20 [ x=.;:'bou stro phe don ic 1' + +test ((1+?123),&.>2 3 4) $&.> 2;3;4.5 +test ((1+?123),&.>2 3 4) $&.> 2;3;4j5 +test ((1+?123),&.>2 3 4) $&.> 2;3;0 + +'domain error' -: ,.&.>/ etx i.0 + +'length error' -: ,.&.>/ etx 1 2;3 4 5 + + +4!:55 ;:'c f g k s sp t test x yy z' + +
new file mode 100644 --- /dev/null +++ b/test/g420t.ijs @@ -0,0 +1,28 @@ +NB. f/ timing tests ----------------------------------------------------- + +ss =: +/ @: *: +rsq=: [: -. ss@(- +/ % #)@[ %~ ss@:- + +f=: 3 : ',/(y,2 3)$''x''' +y=: timer 'f ',"1 ": ,. x=: 2^8+i.12 +threshold < y rsq y (] +/ .* %.) x^/0 1 + +f=: 3 : ',./(y,5 3)$''a''' +y=: timer 'f ',"1 ":,. x=: 2^8+i.12 +threshold < y rsq y (] +/ .* %.) x^/0 1 + +t=: (timer ',./x'),timer '|:x' [ x=: a.{~7001 131?@$#a. +(1-threshold) > s=: (|@-/ % >./) t + +f=: 3 : ',.&.>/y$(5 3$''a'');5 2$''b''' +y=: timer 'f ',"1 ":,. x=: 2^8+i.12 +threshold < y rsq y (] +/ .* %.) x^/0 1 + +f=: 3 : ';/(y,4 3)$''a''' +y=: timer 'f ',"1 ":,. x=: 2^8+i.12 +threshold < y rsq y (] +/ .* %.) x^/0 1 + + +4!:55 ;:'f rsq s ss t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g421.ijs @@ -0,0 +1,198 @@ +NB. f/. f\ f\. models -------------------------------------------------- + +en =: #@] +em =: (en >.@% -@[)`(en 0&>.@>:@- [) @. (0&<:@[) +kay =: en`em @. (0&<@[) +omask =: (em,en) $ ($&0@|@[ , $&1@kay) + +base =: 1&>.@-@[ * i.@em +iind =: base ,. |@[ <. en - base +seg =: ((+i.)/@[ { ])"1 _ + +infix =: 1 : '(iind x@seg ])"0 _' +outfix =: 1 : '(omask x@# ])"0 _' +prefix =: 1 : '>:@,.@i.@# x@{. ]' +suffix =: 1 : ',.@i.@# x@}. ]' + +key =: 1 : '=@[ x@# ]' + +osub =: >@]`(>@[ >@:{ ]) @. (*@#@]) +oind =: (+/&i./ </.&, i.)@(2&{.)@(,&1 1)@$ +ob =: 1 : 'oind x@osub"0 1 ,@(<"_2)' + +bs =: 1 : '(x prefix) : (x infix )' +bsd =: 1 : '(x suffix) : (x outfix)' +sd =: 1 : '(x ob ) : (x key )' + + +NB. f/.y --------------------------------------------------------------- + +NB. Boolean +a=:1=?10 5$2 +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(+.//. -: +./ ob) a +(</. -: < ob) 1 +(</. -: < ob) 0$1 + +NB. literal +a=:a.{~32+?10 5 3$95 +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(</. -: < ob) 'a' +(</. -: < ob) '' + +NB. integer +a=:?3 4 5 6$100 +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(+//. -: +/ ob) a +(</. -: < ob) i.0 7 +(</. -: < ob) i.7 0 4 +(</. -: < ob) i.0 0 4 5 +(</. -: < ob) 34 +(</. -: < ob) 0$34 + +NB. floating point +a=:o._40+?10 5$100 +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(+//. -: +/ ob) a +(</. -: < ob) _3.454 +(</. -: < ob) 0$_3.4 + +NB. complex +a=:^0j0.01*_400+?10 5$1000 +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(+//. -: +/ ob) a +(</. -: < ob) _3j454 +(</. -: < ob) 0$_3j4 + +NB. boxed +t=:(1=?70$3)<;.1 ?70$100 +a=:t{~?10 3$#t +(</. -: < ob) a +(</. -: < ob) ,a +(]/. -: ] ob) a +(</. -: < ob) <i.3 4 +(</. -: < ob) 0$<'_3j4' + + +NB. f/.y convolution --------------------------------------------------- + +pru=: [: ^ 0j2p1&% NB. principal n-th root of unity + +conv=: +//.@(*/) NB. convolution + +conv1=: 4 : 0 + n=. #x + A=. (pru 2*n)^*/~i.2*n NB. (%.A) = (2*n)%~r^-*/~i.2*n + }: x *&.(A&(+/ .*))&((2*n)&{.) y +) + +pconv=: (| +/~@i.)@#@[ +//.&, */ NB. positive wrapped convolution + +pconv1=: 4 : 0 + n=. #x + A=. (*:pru 2*n)^*/~i.n NB. (%.A) = n%~r^-*/~i.n + x *&.(A&(+/ .*)) y +) + +s=: ?10$100 +t=: ?10$100 +eq=: 1e_8&> @: (>./) @: | @: - +s ( conv eq conv1) t +s (pconv eq pconv1) t + + +NB. x f/. y ------------------------------------------------------------ + +NB. Boolean +a=:1=?11 5$2 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 +k (+.//. -: +./ key) a [ k=:?11$4 + +NB. literal +a=:a.{~32+?11$95 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 + +NB. integer +a=:?11 5$110 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 +k (+//. -: +/ key) a [ k=:?11$4 + +NB. floating point +a=: (2^_12) * _4e5+?11$1e6 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 +k (+//. -: +/ key) a [ k=:?11$4 + +NB. complex +a=: j./_4e5+?2 11 5$1e6 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 +k (+//. -: +/ key) a [ k=:?11$4 + +NB. boxed +a=:x{~?11 3$#x=:(1=?70$3)<;.1 ?70$110 +k (</. -: < key) a [ k=:?11$4 +k (]/. -: ] key) a [ k=:?11$4 + +'' -: '' </. '' +'' -: '' </. i.0 4 5 +'' -: (i.0 4 5) </. '' +(,<,5) -: 4 </. 5 +(,<i.1 9) -: 4 </. i.1 9 +(,<,4) -: (i.1 9) </. 4 +(,<,4) -: (i.1 0) </. 4 +(,<x ) -: (i.(#x),0) </. x=:'abcdefghij' + +'length error' -: 'abc' </. etx i.4 +'length error' -: 'abcd' </. etx i.3 +'length error' -: '' </. etx i.4 +'length error' -: 4 </. etx i.4 +'length error' -: 'abcd' </. etx 4 + + +NB. x f/.y on empty x --------------------------------------------------- + +test=: 2 : 0 + n=: p: ?200 + xx=: n ?@$ >.-:n + assert. xx (u/. -: v/.) i.n,0 + assert. ((n,0)$0 ) (u/. -: v/.) i.n,0 + assert. ((n,0)$0 ) (u/. -: v/.) i.n + assert. ((n,0)$'' ) (u/. -: v/.) i.n + assert. ((n,0)$u: 0 ) (u/. -: v/.) i.n + assert. ((n,0)$2 ) (u/. -: v/.) i.n + assert. ((n,0)$2.5 ) (u/. -: v/.) i.n + assert. ((n,0)$2j5 ) (u/. -: v/.) i.n + assert. ((n,0)$2x ) (u/. -: v/.) i.n + assert. ((n,0)$2r5 ) (u/. -: v/.) i.n + assert. ((n,0)$a: ) (u/. -: v/.) i.n + assert. ((n,0)$s:<'x') (u/. -: v/.) i.n + 1 +) + +< test (3 : '<y') +# test (3 : '#y') ++ / test (3 : '+ /y') +>./ test (3 : '>./y') +({.,# ) test (3 : '({.,# )y') +(# ,{.) test (3 : '(# ,{.)y') + + +4!:55 ;:'a base bs bsd conv conv1 em en eq iind infix k ' +4!:55 ;:'kay key n ob oind omask osub outfix pconv pconv1 prefix pru ' +4!:55 ;:'s sd seg suffix t test x xx' + +
new file mode 100644 --- /dev/null +++ b/test/g421c.ijs @@ -0,0 +1,57 @@ +NB. x </. i.#x ---------------------------------------------------------- + +test=: 3 : 0 + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~?1000 $#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~ 1000 $0 + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~ 0 $#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~?1000 2$#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~?1000 5$#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~?1000 5$#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~ 1000 5$0 + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: y{~ 0 5$#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: 0#y + assert. (x</.i.#x) -: <:&.>x </.>:i.#x=: '' ($,)y + 1 +) + +test 0 1 +test a. +test i.900 +test _450+i.900 +test 1e6+i.900 +test _1e6+i.900 +test u: i.65536 +test -: i.900 +test -: _450+i.900 +test <"0 ?40$100 + +'length error' -: 1 2 3 </. etx i.4 + +test1=: 3 : 0 + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~?1000 $#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~ 1000 $0 + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~ 0 $#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~?1000 2$#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~?1000 5$#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~?1000 5$#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~ 1000 5$0 + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: y{~ 0 5$#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: 0#y + assert. ((</.i.@#) x) -: <:&.>x </.>:i.#x=: '' ($,)y + 1 +) + +test1 0 1 +test1 a. +test1 i.900 +test1 _450+i.900 +test1 1e6+i.900 +test1 _1e6+i.900 +test1 u: i.65536 +test1 -: i.900 +test1 -: _450+i.900 +test1 <"0 ?40$100 + + +4!:55 ;:'test test1 x' +
new file mode 100644 --- /dev/null +++ b/test/g421d.ijs @@ -0,0 +1,52 @@ +NB. x ({.,#)/. y and x (#,{.)/.y ---------------------------------------- + +f=: ~:@[ # ] +g=: #/. + +test=: 3 : 0 + y testa 0 1 + y testa i.900 + y testa _450+i.900 + y testa o. i.900 + y testa x: i.900 +) + +testa=: 4 : 0 + yy=:y{~?1000$#y + assert. xx (({.,#)/. -: (f,.g)) yy [ xx=:x{~?1000$#x + assert. xx ((#,{.)/. -: (g,.f)) yy + if. 1:@:>: :: 0: x do. + assert. xx (({.,#)/. -: (f,.g)) xx + assert. xx ((#,{.)/. -: (g,.f)) xx + end. + assert. xx (({.,#)/. -: (f,.g)) yy [ xx=:x{~ 1000$0 + assert. xx ((#,{.)/. -: (g,.f)) yy + if. 1:@:>: :: 0: x do. + assert. xx (({.,#)/. -: (f,.g)) xx + assert. xx ((#,{.)/. -: (g,.f)) xx + assert. xx (({.,#)/. -: (f,.g)) xx=: ''($,)x + assert. xx ((#,{.)/. -: (g,.f)) xx + end. + 1 +) + +test 0 1 +test 1 0 +test a. +test i.900 +test _450+i.900 +test 1e6+i.900 +test _1e6+i.900 +test u: 100 ?@$ 65536 +test o.i.900 +test o._450+i.900 +test <"0 ?40$100 + + +'domain error' -: 1 2 3 ({.,#)/. etx 'abc' +'domain error' -: 1 2 3 ({.,#)/. etx ;:'foo upon thee' + + +4!:55 ;:'f g test testa xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g421e.ijs @@ -0,0 +1,56 @@ +NB. f//. y -------------------------------------------------------------- + +data=: 4 : 0 + select. x + case. 'b' do. y ?@$ 2 + case. 'i' do. y ?@$ 1000 + case. 'I' do. y ?@$ 1e9 + case. 'd' do. 1e_4 * _5e6 + y ?@$ 1e7 + case. 'z' do. j./ 1e_4 * _5e6 + (2,y) ?@$ 1e7 + case. 'x' do. x: _5e8 + y ?@$ 1e9 + case. 'q' do. x: 1e_4 * _5e8 + y ?@$ 1e9 + end. +) + +test=: 1 : 0 + yy=: y data 17 19 + assert. (u/"_/. -: u//.) yy + assert. (u/"_/. -: u//.) |:yy + 1 +) + +test2=: 2 : 0 + xx=: y data 17 + yy=: y data 23 + assert. xx (u//.@(v/) -: u/"_/.@(v/"_)) yy + assert. yy (u//.@(v/) -: u/"_/.@(v/"_)) xx + 1 +) + ++ test"0 'biIdxqz' +>. test"0 'biIdxq' +<. test"0 'biIdxq' + ++. test 'b' +*. test 'b' +~: test 'b' += test 'b' +< test 'b' +<: test 'b' +> test 'b' +>: test 'b' + +17 b. test"0 'iI' +22 b. test"0 'iI' +23 b. test"0 'iI' + ++ test2 *"0 'biIdxqz' + +~: test2 *. 'b' + +22 b. test2 (17 b.)"0 'iI' + + +4!:55 ;:'data test test2 xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g421i.ijs @@ -0,0 +1,157 @@ +NB. x f//. y special code for + +. *. >. <. = ~: ----------------------- + +test=: 1 : 0 + n=. 1000 + v=: 3 : ((5!:5 <'u'),'/y') + yy=: y {~ n ?@$ #y + assert. (xx=: ? n $2 ) (u//. -: v/.) yy + assert. (xx=: ?(n,2)$2 ) (u//. -: v/.) yy + assert. (xx=: ?(n,3)$2 ) (u//. -: v/.) yy + assert. (xx=: a.{~? n $#a. ) (u//. -: v/.) yy + assert. (xx=: a.{~?(n,2)$#a. ) (u//. -: v/.) yy + assert. (xx=: a.{~?(n,3)$#a. ) (u//. -: v/.) yy + assert. (xx=: ? n $100 ) (u//. -: v/.) yy + assert. (xx=: _50 +? n $100 ) (u//. -: v/.) yy + assert. (xx=: _5e9+? n $100 ) (u//. -: v/.) yy + assert. (xx=: ? n $1e9 ) (u//. -: v/.) yy + assert. (xx=: ?(n,2)$100 ) (u//. -: v/.) yy + assert. (xx=: u:? n $65536) (u//. -: v/.) yy + 1 +) + ++ test 0 1 ++ test 0=?100$2 ++ test 0<?100$2 ++ test ?100$1000 ++ test _500+?100$1000 ++ test ?100$1e9 ++ test _5e8+?100$1e9 ++ test 1 _1 _2147483648 2147483647 ++ test -:_5e8+?100$1e9 + +<. test 0 1 +<. test 0=?100$2 +<. test 0<?100$2 +<. test ?100$1000 +<. test _500+?100$1000 +<. test ?100$1e9 +<. test _5e8+?100$1e9 +<. test 1 _1 _2147483648 2147483647 +<. test -:_5e8+?100$1e9 + +>. test 0 1 +>. test 0=?100$2 +>. test 0<?100$2 +>. test ?100$1000 +>. test _500+?100$1000 +>. test ?100$1e9 +>. test _5e8+?100$1e9 +>. test 1 _1 _2147483648 2147483647 +>. test -:_5e8+?100$1e9 + +*. test 0 1 +*. test 0=?100$2 +*. test 0<?100$2 +* test 0 1 +* test 0=?100$2 +* test 0<?100$2 + ++. test 0 1 ++. test 0=?100$2 ++. test 0<?100$2 + += test 0 1 += test 0=?100$2 += test 0<?100$2 + +~: test 0 1 +~: test 0=?100$2 +~: test 0<?100$2 + +17 b. test ?100$1000 +17 b. test _500+?100$1000 +17 b. test ?100$1e9 +17 b. test _5e8+?100$1e9 +17 b. test 1 _1 _2147483648 2147483647 +17 b. test -~2 2 +17 b. test _1 _1 + +22 b. test ?100$1000 +22 b. test _500+?100$1000 +22 b. test ?100$1e9 +22 b. test _5e8+?100$1e9 +22 b. test 1 _1 _2147483648 2147483647 +22 b. test -~2 2 +22 b. test _1 _1 + +23 b. test ?100$1000 +23 b. test _500+?100$1000 +23 b. test ?100$1e9 +23 b. test _5e8+?100$1e9 +23 b. test 1 _1 _2147483648 2147483647 +23 b. test -~2 2 +23 b. test _1 _1 + +25 b. test ?100$1000 +25 b. test _500+?100$1000 +25 b. test ?100$1e9 +25 b. test _5e8+?100$1e9 +25 b. test 1 _1 _2147483648 2147483647 +25 b. test -~2 2 +25 b. test _1 _1 + +x=: 7183 2 ?@$ 61 +x (+.//. -: 3 : '+./y'/.) y=: ?($x)$2 +x (+.//. -: 3 : '+./y'/.) y=: 0=?($x)$100 +x (+.//. -: 3 : '+./y'/.) y=: 0<?($x)$100 +x (+.//. -: 3 : '+./y'/.) y=: ?($x)$1e6 +x (+.//. -: 3 : '+./y'/.) y=: o.?($x)$1e6 + +x (*.//. -: 3 : '*./y'/.) y=: ?($x)$2 +x (*.//. -: 3 : '*./y'/.) y=: 0=?($x)$100 +x (*.//. -: 3 : '*./y'/.) y=: 0<?($x)$100 +x (*.//. -: 3 : '*./y'/.) y=: ?($x)$1e6 +x (*.//. -: 3 : '*./y'/.) y=: o.?($x)$1e6 + +x (<.//. -: 3 : '<./y'/.) y=: ?($x)$2 +x (<.//. -: 3 : '<./y'/.) y=: 0=?($x)$100 +x (<.//. -: 3 : '<./y'/.) y=: 0<?($x)$100 +x (<.//. -: 3 : '<./y'/.) y=: ?($x)$1e6 +x (<.//. -: 3 : '<./y'/.) y=: o.?($x)$1e6 + +x (>.//. -: 3 : '>./y'/.) y=: ?($x)$2 +x (>.//. -: 3 : '>./y'/.) y=: 0=?($x)$100 +x (>.//. -: 3 : '>./y'/.) y=: 0<?($x)$100 +x (>.//. -: 3 : '>./y'/.) y=: ?($x)$1e6 +x (>.//. -: 3 : '>./y'/.) y=: o.?($x)$1e6 + +'domain error' -: x + //. etx (#x)$ 'abc' +'domain error' -: x + //. etx (#x)$<'abc' +'domain error' -: x +.//. etx (#x)$ 'abc' +'domain error' -: x +.//. etx (#x)$<'abc' +'domain error' -: x *.//. etx (#x)$ 'abc' +'domain error' -: x *.//. etx (#x)$<'abc' +'domain error' -: x >.//. etx (#x)$ 'abc' +'domain error' -: x >.//. etx (#x)$<'abc' +'domain error' -: x <.//. etx (#x)$ 'abc' +'domain error' -: x <.//. etx (#x)$<'abc' + +'length error' -: 1 2 3 + //. etx 0 1 +'length error' -: 1 2 3 + //. etx 4 5 +'length error' -: 1 2 3 + //. etx 4 5.6 +'length error' -: 1 2 3 +.//. etx 0 1 +'length error' -: 1 2 3 +.//. etx 4 5 +'length error' -: 1 2 3 +.//. etx 4 5.6 +'length error' -: 1 2 3 *.//. etx 0 1 +'length error' -: 1 2 3 *.//. etx 4 5 +'length error' -: 1 2 3 *.//. etx 4 5.6 +'length error' -: 1 2 3 <.//. etx 0 1 +'length error' -: 1 2 3 <.//. etx 4 5 +'length error' -: 1 2 3 <.//. etx 4 5.6 +'length error' -: 1 2 3 >.//. etx 0 1 +'length error' -: 1 2 3 >.//. etx 4 5 +'length error' -: 1 2 3 >.//. etx 4 5.6 + + +4!:55 ;:'test v x xx y yy' +
new file mode 100644 --- /dev/null +++ b/test/g421p.ijs @@ -0,0 +1,16 @@ +NB. x +//.@(*/) y special code ----------------------------------------- + +test=: 4 : 0 + xx=: x{~53 ?@$ #x + yy=: y{~61 ?@$ #y + assert. (xx +//.@(*/) yy) -: +//. xx */ yy + assert. (yy +//.@(*/) xx) -: +//. yy */ xx + 1 +) + +test&>/~ 0 1;(_500+?@$~1000);(100 ?@$ 0); j./2 100 ?@$ 0 + + +4!:55 ;:'test xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/g421t.ijs @@ -0,0 +1,36 @@ +NB. x #/. y ------------------------------------------------------------- + +tally=: 3 : '#y' + +test=: 3 : 0 + assert. (#/.~ -: tally/.~) xx=: y{~?1000 $#y + assert. (#/.~ -: tally/.~) xx=: y{~ 1000 $0 + assert. (#/.~ -: tally/.~) xx=: y{~ 0 $#y + assert. (#/.~ -: tally/.~) xx=: y{~?1000 2$#y + assert. (#/.~ -: tally/.~) xx=: y{~?1000 5$#y + assert. (#/.~ -: tally/.~) xx=: y{~?1000 5$#y + assert. (#/.~ -: tally/.~) xx=: y{~ 1000 5$0 + assert. (#/.~ -: tally/.~) xx=: y{~ 0 5$#y + assert. (#/.~ -: tally/.~) xx=: 0#y + assert. (#/.~ -: tally/.~) xx=: '' ($,)y + 1 +) + +test 0 1 +test 1 0 +test a. +test i.900 +test _450+i.900 +test 1e6+i.900 +test _1e6+i.900 +test u: 100 ?@$ 65536 +test o.i.900 +test o._450+i.900 +test <"0 ?40$100 + + +'length error' -: 1 2 3 #/. etx i.4 + + +4!:55 ;:'tally test x' +
new file mode 100644 --- /dev/null +++ b/test/g422.ijs @@ -0,0 +1,330 @@ +NB. /:y ----------------------------------------------------------------- + +NB. Boolean +a =: 1=?10 5$2 +i =: /:a +k =: ?10$5 +i =&# a +(/:~i) -: i. #a +(/:k#a) -: ;i{(i.&.>k)+&.>+/\}:0,k +(,0) -: /:0 +'' -: /:(0,?(?5)$10)$0 +(i.#a) -: /:a =: ((?10),0)$0 +(/:a) -: /:,.~a=:?400$2 +(/:a) -: /:,.~a=:? 1$2 +((+/a=/0 1)#0 1) -: /:~a=:?1000$2 + +f=: 3 : 0 " 0 + a=: (1000,y) ?@$ 2 + k=: (#a) ?@$ 5 + i=: /:a + assert. i -: /:a{'01' + assert. i -: /: #.a + assert. (/:k#a) -: ; i { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >: i.16 + +NB. literal +a =: a.{~32+?10 5$95 +i =: /:a +k =: ?10$5 +i =&# a +(/:~i) -: i.#a +(/:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: /:'g' +'' -: /:(0,?(?5)$10)$0 +(i.#a) -: /:a =: ((?10),0)$0 +(/:a) -: /:,.~ a=:a.{~?400$256 +(/:a) -: /:,.~ a=:a.{~?1 $256 +((+/x=/ a.)# a.) -: /:~x=:a.{~?1000$#a. + +f=: 3 : 0 " 0 + a=: a.{~(1000,y) ?@$ #a. + k=: (#a) ?@$ 5 + assert. (/:k#a) -: ; (/:a) { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >:i.16 + +NB. integer +a =: ?10 5$100 +i =: /:a +k =: ?10$5 +i=&#a +(/:~i) -: i.#a +(/:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: /:5 +'' -: /:(0,?(?5)$10)$5 +(i.#a) -: /:a =: ((?10),0)$5 +*./a>:}:0, a=:/:~?1000$1e2 +*./a>:}:0, a=:/:~?1000$1e3 +*./a>:}:0, a=:/:~?1000$1e4 +*./a>:}:0, a=:/:~?1000$1e9 +(/: 100#.a) -: /: a=: ?1000 2$100 +(/: 100#.a) -: /: a=: ?1000 2$ 5 + +a=: (--:m) + 1000 ?@$ m=:IF64{2e9 9e18 +y=: (/:a) { a +*./ (}:y) <: }.y + +m=:<._1+2^31 +1 0 -: /: m,0 +0 1 -: /: 0,m +m=:<.-2^31 +0 1 -: /: m,0 +1 0 -: /: 0,m + +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.1 +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.2 +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.3 +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.4 +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.5 +((i.!#a) A. i.#a) (/:@[ -: /:@:{)"1 2 a=: 88#"0 i.6 + +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?1 8$5e6 +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?2 8$5e6 +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?3 8$5e6 +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?4 8$5e6 +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?5 8$5e6 +((i.!#a) A. i.#a) (] -: /:~@:{)"1 2 a=: /:~ (88$8),"1?6 8$5e6 + +f=: 3 : 0 " 0 + a=: (100,y) ?@$ 200 + k=: (#a) ?@$ 5 + assert. (/:k#a) -: ; (/:a) { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >: i.16 + +(/:v) -: /: a.{~ v=: ?10000$#a. +(/:v) -: /: a.{~ v=: ?66000$#a. + +(/:v) -: /: a.{~ 2000 + v=: _2000 + ?10000$#a. +(/:v) -: /: a.{~ 2000 + v=: _2000 + ?66000$#a. + +(/:v) -: /: a.{~ 128 + v=: _128 + ?10000$#a. +(/:v) -: /: a.{~ 128 + v=: _128 + ?66000$#a. + +(/:"1 v) -: /:"1 a.{~ v=: ?2 3 10000$#a. +(/:"1 v) -: /:"1 a.{~ v=: ?2 3 66000$#a. + +(/:"1 v) -: /:"1 a.{~ 2000 + v=: _2000 + ?2 3 10000$#a. +(/:"1 v) -: /:"1 a.{~ 2000 + v=: _2000 + ?2 3 66000$#a. + +(/:"1 v) -: /:"1 a.{~ 128 + v=: _128 + ?2 3 10000$#a. +(/:"1 v) -: /:"1 a.{~ 128 + v=: _128 + ?2 3 66000$#a. + +(/:v) -: /: o. v=: (?~20000){(?10000$65536),32768*?10000$65536 +(/:v) -: /: (-#v){.0 (3!:3) v + +NB. floating point +a =: o._40+?10 5$100 +i =: /:a +k =: ?10$5 +i =&# a +(/:~i) -: i.#a +(/:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: /:2.718 +'' -: /:(0,?(?5)$10)$3.14 +(i.#x) -: /:x=: ((?10),0)$3.14 +*./x>:}:0, x=:/:~o.?1000$1e2 + +v=:?100$25 +(/:v) -: /:v-25 +(/:v) -: /:v+100 +(/:v) -: /:o.v +(/:v) -: /:,.~v + +(/:v) -: /: 0.01*v=: ?10000$50000 +(/:v) -: /: 0.01*v=: ?66000$50000 + +(/:v) -: /: 0.01*v=: - 1+ ?10000$50000 +(/:v) -: /: 0.01*v=: - 1+ ?66000$50000 + +(/:v) -: /: 0.01*v=: _25000+?10000$50000 +(/:v) -: /: 0.01*v=: _25000+?66000$50000 + +(/:"1 v) -: /:"1 o. v=: ?2 3 10000$50000 +(/:"1 v) -: /:"1 o. v=: ?2 3 66000$50000 + +(/:"1 v) -: /:"1 o. v=: - 1+ ?2 3 10000$50000 +(/:"1 v) -: /:"1 o. v=: - 1+ ?2 3 66000$50000 + +(/:"1 v) -: /:"1 o. v=: _25000+?2 3 10000$50000 +(/:"1 v) -: /:"1 o. v=: _25000+?2 3 66000$50000 + +NB. complex +a =: r._40+?10 5$100 +i =: /:a +k =: ?10$5 +i =&# a +i -: /: +.a +(/:~i) -: i. #a +(/:k#a) -: ; i { (i.&.>k) +&.> +/\ }:0,k +(,0) -: /: 3j4 +'' -: /: (0,?(?5)$10)$3j4 +(i.#x) -: /: x=: ((?10),0)$3j4 +(i.12) -: /: r.12 5$100 + +NB. boxed +(/:a) -: /: <"0 a=: ?20 7$1000 +(/:a) -: /: <"1 a +(/:a) -: /: <&.> a +(/:a) -: /: <&.> a +(/:a) -: /: > a=: _50+&.>(?10$20)$&.>100 +(/:a) -: /: > a=:o.&.>_50+&.>(?10$20)$&.>100 +(/:a) -: /: > a=:r.&.>_50+&.>(?10$20)$&.>100 +(/:a) -: /: > a=:(<"0 ?5$2),(<"0 ?5$100),(<"0 o.?5$100),<"0 r.?5$100 +(/:a) -: /: > a=:(?~#a){a +(/:a) -: /: i.&.>a=:?~30 + +f=: 3 : 0 + assert. (/: a) -: /: <"0 a=.?(100,y)$3 + assert. (/:"1 a) -: /:"1 <"0 a + assert. (/:"2 a) -: /:"2 <"0 a + assert. (/: a) -: /: <"1 a + assert. (/:"2 a) -: /:"1 <"1 a + assert. (/:"3 a) -: /:"2 <"1 a + 1 +) + +*./@f"0 >: i.3 10 +*./@f"1 >: 5 6#:i.3 10 +*./@f"1 >:5 3 2#:i.3 10 + +g=: 3 : '0 1 -: /: ,:~ t=. y$t,<t=.1 2 3;''abc'' ' +g"0 i.3 10 + +(/:"1 a) -: /:"1 <"0 a=:? 20 17$1000 +(/:"2 a) -: /:"2 <"0 a=:?4 20 17$1000 + +le=: 0: = {.@/: +x=: o.&.>_50+&.>(?10$20)$&.>100 +y=: ;:'Cogito, ergo sum. Sui generis. Sine qua non.' +z=: <"0 >5!:1 <'le' +2 le\ /:~a=: (?~#x,y,z) { x,y,z + +0 1 2 -: /: x=:3j4; 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:(i.0); 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:''; 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:(o.i.0); 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:(j.i.0); 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:(0$a:); 'Ex ungue leonem'; <<5 6 7 +2 1 0 -: /: |. x +0 1 2 -: /: x=:'' ; (i.0) ; <0$a: +0 1 2 -: /: |. x + +a=: < 2 3 $ 1 2 3 4 5 6 +b=: < 3 2 $ 1 2 5 6 3 4 +c=: < 1 3 $ 1 2 3 +d=: < 1 2 $ 1 2 +e=: < 2 2 $ 1 2 5 6 + +(i.5) -: /: d,e,b,c,a +(/:"1 p) -: /:"1 (d,e,b,c,a){~p=: (i.!5) A. i.5 + +NB. extended integer +(/: -: /: @:x:) a=: _500+?100 $1000 +(/: -: /:@:(<"0)@:x:) a +(/: -: /: @:x:) a=: _500+?100 4$1000 +(/: -: /:@:(<"1)@:x:) a + +NB. rationals +(/: -: /: @:x:) a=: -:_500+?100 $1000 +(/: -: /:@:(<"0)@:x:) a +(/: -: /: @:x:) a=: -:_500+?100 4$1000 +(/: -: /:@:(<"1)@:x:) a + +'index error' -: 3 4 5 /: etx 1 2 3 4 + + +NB. /:y on integer lists ------------------------------------------------ + +v=:?100$25 +(/:v) -: /:v-25 +(/:v) -: /:v+100 +(/:v) -: /:o.v +(/:v) -: /:,.~v + +1 2 3 4 5 0 -: /: v=: 2e9 _2e9 1 2 3 4 +_2e9 1 2 3 4 2e9 -: /:~v + +x=: <._1+2^31 +y=: _1-x +v=:x,y,1 2 3 4 +(/:v) -: 1 2 3 4 5 0 +(/:~v) -: y,1 2 3 4,x + + +NB. /:"r ---------------------------------------------------------------- + +g =: 3 : ('/:y'; ':'; 'x/:y') + +(/:"0 -: g"0) y=:?2 3 4 17$2 +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y + +(/:"0 -: g"0) y=:a.{~?2 3 4 17$#a. +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y +(/:"0 -: g"0) y=:a.{~?2 3 4 18$#a. +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y + +(/:"0 -: g"0) y=:?2 3 4 17$34 +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y +(/:"0 -: g"0) y=:?2 3 4 17$+:*/2 3 4 17 +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y +(/:"0 -: g"0) y=:_50+?2 3 4 17$100 +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y + +(/:"0 -: g"0) y=:o.?2 3 4 17$34 +(/:"1 -: g"1) y +(/:"2 -: g"2) y +(/:"3 -: g"3) y +(/:"4 -: g"4) y + +x=:?20 3$100 +x (/:"2 2 -: g"2 2) y=:?2 20 3$100 +x (/:"2 3 -: g"2 3) y=:?20 2 3$100 +x (/:"1 1 -: g"1 1) y=:o.?3$100 +x (/:"1 0 -: g"1 0) y=:?1000 +x (/:"1 0 -: g"1 0) y=:a.{~?20$256 + +(/:~"1 -: g~"1) y=:?4 17$2 +(/:~"1 -: g~"1) y=:a.{~32+?17 4$95 +(/:~"1 -: g~"1) y=:?2 7 16$100 +(/:~"1 -: g~"1) y=:o.?4 17$1232 + +(2 3 4 1$0) -: /:"0 i.2 3 4 +(0 0 0 1$0) -: /:"0 i.0 0 0 + +'index error' -: (i.4) /: etx i.5 + +4!:55 ;:'a b c d e f g ge i k le m p v x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g422os.ijs @@ -0,0 +1,23 @@ +NB. x{/:~y (order statistics) ------------------------------------------- + +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 ?@$ 60 +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 0.1 * 100 ?@$ 60 +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 ?@$ 10000 +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 0.1 * 100 ?@$ 10000 +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 $ 10000 +(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 $ 34.5 + +y=: 1000 ?@$ 600 +x=: n -~ 20 ?@$ +:n=: #y +(x{/:~y) -: x ({/:~)"0 1 y +y=: 0.1 * y +(x{/:~y) -: x ({/:~)"0 1 y + +'domain error' -: 'a' ({/:~) etx y + +'index error' -: 1e6 ({/:~) etx y +'index error' -: _1e6 ({/:~) etx y + + +4!:55 ;:'n x y' +
new file mode 100644 --- /dev/null +++ b/test/g422rk.ijs @@ -0,0 +1,61 @@ +NB. /:@/: y ------------------------------------------------------------- + +rk=: 3 : '/:/:y' + +f=: 4 : 0 + assert. (/:@/: -: rk ) xx=: x{~ ( 1e4,y) ?@$ #x + assert. (/:@/:"2 -: rk"2) xx=: x{~ (5 1e4,y) ?@$ #x + 1 +) + +0 1 f"1 0 i.10 +a. f"1 0 i.10 + +(/:@/: -: rk ) x=: u: 1e4 ?@$ 65536 +(/:@/:"1 -: rk"1) x=: u: 5 1e4 ?@$ 65536 + +g=: 3 : 0 + assert. (/:@/: -: rk ) xx=: 1e4 ?@$ y + assert. (/:@/:"1 -: rk"1) xx=: 3 1e4 ?@$ y + 1 +) + +g"0 ] 10^i.10 +g"0 ] 10^IF64#11 12 13 18 + +(/:@/: -: rk ) x=: 1e3 5 ?@$ 0 +(/:@/: -: rk ) x=: <"0 ] 1e3 5 ?@$ 1e4 +(/:@/: -: rk ) x=: y{~ 1e3 5 ?@$ #y=: 'abc';1 2 3;7.5;;:'bush kerry nader' + +(/:@/:"2 -: rk"2) x=: 3 1e3 5 ?@$ 0 +(/:@/:"2 -: rk"2) x=: <"0 ]3 1e3 5 ?@$ 1e4 +(/:@/:"2 -: rk"2) x=: y{~ 3 1e3 5 ?@$ #y=: 'abc';1 2 3;7.5;;:'bush kerry nader' + +(/:@/:"0 -: rk"0) x=: 3 12 ?@$ 2 +(/:@/:"0 -: rk"0) x=: a.{~3 12 ?@$ #a. +(/:@/:"0 -: rk"0) x=: 3 12 ?@$ 2e9 +(/:@/:"0 -: rk"0) x=: 3 12 ?@$ 0 +(/:@/:"0 -: rk"0) x=: u: 3 12 ?@$ 65536 +(/:@/:"0 -: rk"0) x=: y{~ 3 12 ?@$ #y=: 'abc';1 2 3;7.5;;:'bush kerry nader' + +x=: 1e4 ?@$ 1e4 +y=: 1e4 ?@$ 5000 +(/:x/:y) -: x /:@/: y + +x=: (5 1e4 ?@$ 2) * 5 1e4 ?@$ 1000 +(/:@/:"1 x) -: /:@/:"1 $.x + +(i.0 ) -: /:@/: 0 1e9 2e9 99 $ 0 +(i.0 2e9) -: /:@/:"1 ] 0 2e9 $ 0 +(i.0 2e9) -: /:@/:"2 ] 0 2e9 17 $ 0 + +(3 4 17$i.17) -: /:@/:"2 ] 3 4 17 0 $ 0 +(3 4 17$i.17) -: rk "2 ] 3 4 17 0 $ 0 + +(/:@/: -: /:@/:@x:)"1 ] 17 31 ?@$ 1000 + +'limit error' -: /:@/:"2 etx 0 $~ (IF64$2e9),1e9 11 17 0 + + +4!:55 ;:'f g rk x xx y' +
new file mode 100644 --- /dev/null +++ b/test/g422sort.ijs @@ -0,0 +1,198 @@ +NB. y/:y and y\:y ------------------------------------------------------- + +test=: 3 : 0 + t=. (/:y){y + assert. t -: y/:y + assert. t -: /:~ y + if. (1=#$y)*.0=1{.0$y do. assert. (}.t)>:}:t end. + t=. (\:y){y + assert. t -: y\:y + assert. t -: \:~ y + if. (1=#$y)*.0=1{.0$y do. assert. (}.t)<:}:t end. + 1 +) + +test1=: 3 : 0 + t=. (/:"1 y){"1 y + assert. t -: y/:"1 y + assert. t -: /:~"1 y + assert. t -: /:"1~ y + t=. (\:"1 y){"1 y + assert. t -: y\:"1 y + assert. t -: \:~"1 y + assert. t -: \:"1~ y + 1 +) + +*./ b=: test @:(] ?@$ 2:)"0 ] 500+i.2000 +*./ b=: test1@:(3&, ?@$ 2:)"0 ] 500+i.2000 + +test a.{~ 1000 ?@$ #a. +test a.{~ 1001 ?@$ #a. +test a.{~ 1002 ?@$ #a. +test a.{~ 1003 ?@$ #a. +test a.{~ 1004 ?@$ #a. +test a.{~ 1005 ?@$ #a. +test a.{~ 1006 ?@$ #a. +test a.{~ 1007 ?@$ #a. + +test a.{~ 1000 2 ?@$ #a. +test a.{~ 1001 2 ?@$ #a. +test a.{~ 1002 2 ?@$ #a. +test a.{~ 1003 2 ?@$ #a. + +test a.{~ 7000 2 ?@$ #a. +test a.{~ 7001 2 ?@$ #a. +test a.{~ 7002 2 ?@$ #a. +test a.{~ 7003 2 ?@$ #a. + +test u: 1000 ?@$ 65536 +test u: 1001 ?@$ 65536 +test u: 1002 ?@$ 65536 +test u: 1003 ?@$ 65536 + +test u: 7000 ?@$ 65536 +test u: 7001 ?@$ 65536 +test u: 7002 ?@$ 65536 +test u: 7003 ?@$ 65536 + +test 1000 ?@$ 1e4 +test 1001 ?@$ 1e4 +test 1002 ?@$ 1e4 +test 1003 ?@$ 1e4 + +test -1+ 1000 ?@$ 1e4 +test -1+ 1001 ?@$ 1e4 +test -1+ 1002 ?@$ 1e4 +test -1+ 1003 ?@$ 1e4 + +test _5e3+ 1000 ?@$ 1e4 +test _5e3+ 1001 ?@$ 1e4 +test _5e3+ 1002 ?@$ 1e4 +test _5e3+ 1003 ?@$ 1e4 + +test 1000 ?@$ 1e9 +test 1001 ?@$ 1e9 +test 1002 ?@$ 1e9 +test 1003 ?@$ 1e9 + +test 1000 ?@$ IF64{1e9 1e18 +test 1001 ?@$ IF64{1e9 1e18 +test 1002 ?@$ IF64{1e9 1e18 +test 1003 ?@$ IF64{1e9 1e18 + +test - 1 + 1000 ?@$ IF64{1e9 1e18 +test - 1 + 1001 ?@$ IF64{1e9 1e18 +test - 1 + 1002 ?@$ IF64{1e9 1e18 +test - 1 + 1003 ?@$ IF64{1e9 1e18 + +test(--:n)+ 1000 ?@$ n=: IF64{1e9 1e18 +test(--:n)+ 1001 ?@$ n=: IF64{1e9 1e18 +test(--:n)+ 1002 ?@$ n=: IF64{1e9 1e18 +test(--:n)+ 1003 ?@$ n=: IF64{1e9 1e18 + +test 0.01* 1000 ?@$ IF64{1e9 1e18 +test 0.01* 1001 ?@$ IF64{1e9 1e18 +test 0.01* 1002 ?@$ IF64{1e9 1e18 +test 0.01* 1003 ?@$ IF64{1e9 1e18 + +test 0.01* -1+1000 ?@$ IF64{1e9 1e18 +test 0.01* -1+1001 ?@$ IF64{1e9 1e18 +test 0.01* -1+1002 ?@$ IF64{1e9 1e18 +test 0.01* -1+1003 ?@$ IF64{1e9 1e18 + +test 0.01*(--:n)+ 1000 ?@$ n=: IF64{1e9 1e18 +test 0.01*(--:n)+ 1001 ?@$ n=: IF64{1e9 1e18 +test 0.01*(--:n)+ 1002 ?@$ n=: IF64{1e9 1e18 +test 0.01*(--:n)+ 1003 ?@$ n=: IF64{1e9 1e18 + + +test1 a.{~ 3 1000 ?@$ #a. +test1 a.{~ 3 1001 ?@$ #a. +test1 a.{~ 3 1002 ?@$ #a. +test1 a.{~ 3 1003 ?@$ #a. + +test1 a.{~ 3 1000 2 ?@$ #a. +test1 a.{~ 3 1001 2 ?@$ #a. +test1 a.{~ 3 1002 2 ?@$ #a. +test1 a.{~ 3 1003 2 ?@$ #a. + +test1 a.{~ 3 1000 2 ?@$ #a. +test1 a.{~ 3 1001 2 ?@$ #a. +test1 a.{~ 3 1002 2 ?@$ #a. +test1 a.{~ 3 1003 2 ?@$ #a. + +test1 u: 3 1000 ?@$ 65536 +test1 u: 3 1001 ?@$ 65536 +test1 u: 3 1002 ?@$ 65536 +test1 u: 3 1003 ?@$ 65536 + +test1 u: 3 1000 ?@$ 65536 +test1 u: 3 1001 ?@$ 65536 +test1 u: 3 1002 ?@$ 65536 +test1 u: 3 1003 ?@$ 65536 + +test1 3 1000 ?@$ 1e4 +test1 3 1001 ?@$ 1e4 +test1 3 1002 ?@$ 1e4 +test1 3 1003 ?@$ 1e4 + +test1 -1+ 3 1000 ?@$ 1e4 +test1 -1+ 3 1001 ?@$ 1e4 +test1 -1+ 3 1002 ?@$ 1e4 +test1 -1+ 3 1003 ?@$ 1e4 + +test1 _5e4+ 3 1000 ?@$ 1e4 +test1 _5e4+ 3 1001 ?@$ 1e4 +test1 _5e4+ 3 1002 ?@$ 1e4 +test1 _5e4+ 3 1003 ?@$ 1e4 + +test1 3 1000 ?@$ 1e9 +test1 3 1001 ?@$ 1e9 +test1 3 1002 ?@$ 1e9 +test1 3 1003 ?@$ 1e9 + +test1 3 1000 ?@$ IF64{1e9 1e18 +test1 3 1001 ?@$ IF64{1e9 1e18 +test1 3 1002 ?@$ IF64{1e9 1e18 +test1 3 1003 ?@$ IF64{1e9 1e18 + +test1 -1+ 3 1000 ?@$ 1e9 +test1 -1+ 3 1001 ?@$ 1e9 +test1 -1+ 3 1002 ?@$ 1e9 +test1 -1+ 3 1003 ?@$ 1e9 + +test1 -1+ 3 1000 ?@$ IF64{1e9 1e18 +test1 -1+ 3 1001 ?@$ IF64{1e9 1e18 +test1 -1+ 3 1002 ?@$ IF64{1e9 1e18 +test1 -1+ 3 1003 ?@$ IF64{1e9 1e18 + +test1 _5e8+ 3 1000 ?@$ 1e9 +test1 _5e8+ 3 1001 ?@$ 1e9 +test1 _5e8+ 3 1002 ?@$ 1e9 +test1 _5e8+ 3 1003 ?@$ 1e9 + +test1 (--:n) + 3 1000 ?@$ n=: IF64{1e9 1e18 +test1 (--:n) + 3 1001 ?@$ n=: IF64{1e9 1e18 +test1 (--:n) + 3 1002 ?@$ n=: IF64{1e9 1e18 +test1 (--:n) + 3 1003 ?@$ n=: IF64{1e9 1e18 + +test1 0.01* 3 1000 ?@$ IF64{1e9 1e18 +test1 0.01* 3 1001 ?@$ IF64{1e9 1e18 +test1 0.01* 3 1002 ?@$ IF64{1e9 1e18 +test1 0.01* 3 1003 ?@$ IF64{1e9 1e18 + +test1 0.01* -1+ 3 1000 ?@$ IF64{1e9 1e18 +test1 0.01* -1+ 3 1001 ?@$ IF64{1e9 1e18 +test1 0.01* -1+ 3 1002 ?@$ IF64{1e9 1e18 +test1 0.01* -1+ 3 1003 ?@$ IF64{1e9 1e18 + +test1 0.01*(--:n) + 3 1000 ?@$ n=: IF64{1e9 1e18 +test1 0.01*(--:n) + 3 1001 ?@$ n=: IF64{1e9 1e18 +test1 0.01*(--:n) + 3 1002 ?@$ n=: IF64{1e9 1e18 +test1 0.01*(--:n) + 3 1003 ?@$ n=: IF64{1e9 1e18 + + +4!:55 ;:'b n test test1' + +
new file mode 100644 --- /dev/null +++ b/test/g430.ijs @@ -0,0 +1,492 @@ +NB. f/. f\ f\. models -------------------------------------------------- + +en =: #@] +em =: (en >.@% -@[)`(en 0&>.@>:@- [) @. (0&<:@[) +kay =: en`em @. (0&<@[) +omask =: (em,en) $ ($&0@|@[ , $&1@kay) + +base =: 1&>.@-@[ * i.@em +iind =: base ,. |@[ <. en - base +seg =: ((+i.)/@[ { ])"1 _ + +infix =: 1 : '(iind x@seg ])"0 _' +outfix =: 1 : '(omask x@# ])"0 _' +prefix =: 1 : '>:@,.@i.@# x@{. ]' +suffix =: 1 : ',.@i.@# x@}. ]' + +key =: 1 : '=@[ x@# ]' + +osub =: >@]`(>@[ >@:{ ]) @. (*@#@]) +oind =: (+/&i./ </.&, i.)@(2&{.)@(,&1 1)@$ +ob =: 1 : 'oind x@osub"0 1 ,@(<"_2)' + +bs =: 1 : '(x prefix) : (x infix )' +bsd =: 1 : '(x suffix) : (x outfix)' +sd =: 1 : '(x ob ) : (x key )' + + +NB. f\y ----------------------------------------------------------------- + +NB. Boolean +a=:1=?10 5$2 +(<\ -: < bs) a +(<\ -: < bs) ,a +(]\ -: ] bs) a +(+./\ -: +./ bs) a + +NB. literal +a=:a.{~32+?10 5$95 +(<\a) -: < bs a +(<\,a) -: < bs ,a +(]\a) -: ] bs a + +NB. integer +a=:?10 5$100 +(<\ -: < bs) a +(<\ -: < bs) ,a +(]\ -: ] bs) a +(+/\ -: +/ bs) a + +NB. floating point +a=:4096%~_4e6+?10 5$1e7 +(<\ -: < bs) a +(<\ -: < bs) ,a +(]\ -: ] bs) a +(+/\ -: +/ bs) a + +NB. complex +a=:j./4096%~_400+?2 10 5$1000 +(<\ -: < bs) a +(<\ -: < bs) ,a +(]\ -: ] bs) a +(+/\ -: +/ bs) a + +NB. boxed +t=:(1=?70$3)<;.1 ?70$100 +a=:t{~?10 3$#t +(<\ -: < bs) a +(<\ -: < bs) ,a +(]\ -: ] bs) a + +'' -: <\ i.0 +'' -: <\ i.0 2 3 4 + + +NB. f/\y ---------------------------------------------------------------- + +(= /\ -: = / bs) ?20$2 +(< /\ -: < / bs) ?20$2 +(<./\ -: <./ bs) ?20$2 +(<:/\ -: <:/ bs) ?20$2 +(> /\ -: > / bs) ?20$2 +(>./\ -: >./ bs) ?20$2 +(>:/\ -: >:/ bs) ?20$2 +(+ /\ -: + / bs) ?20$2 +(+./\ -: +./ bs) ?20$2 +(+:/\ -: +:/ bs) ?20$2 +(* /\ -: * / bs) ?20$2 +(*./\ -: *./ bs) ?20$2 +(*:/\ -: *:/ bs) ?20$2 +(- /\ -: - / bs) ?20$2 +(% /\ -: % / bs) 20$1 +(% /\ -: % / bs) 0,19$1 +(^ /\ -: ^ / bs) ?20$2 +(~:/\ -: ~:/ bs) ?20$2 +(| /\ -: | / bs) ?20$2 +(! /\ -: ! / bs) ?20$2 + +(= /\ -: = / bs)"1 #:i.32 +(< /\ -: < / bs)"1 #:i.32 +(<./\ -: <./ bs)"1 #:i.32 +(<:/\ -: <:/ bs)"1 #:i.32 +(> /\ -: > / bs)"1 #:i.32 +(>./\ -: >./ bs)"1 #:i.32 +(>:/\ -: >:/ bs)"1 #:i.32 +(+ /\ -: + / bs)"1 #:i.32 +(+./\ -: +./ bs)"1 #:i.32 +(+:/\ -: +:/ bs)"1 #:i.32 +(* /\ -: * / bs)"1 #:i.32 +(*./\ -: *./ bs)"1 #:i.32 +(*:/\ -: *:/ bs)"1 #:i.32 +(- /\ -: - / bs)"1 #:i.32 +(% /\ -: % / bs)"1 32 5$1 +(^ /\ -: ^ / bs)"1 #:i.32 +(~:/\ -: ~:/ bs)"1 #:i.32 +(| /\ -: | / bs)"1 #:i.32 +(! /\ -: ! / bs)"1 #:i.32 + +(= /\ -: = / bs) |:#:i.32 +(< /\ -: < / bs) |:#:i.32 +(<./\ -: <./ bs) |:#:i.32 +(<:/\ -: <:/ bs) |:#:i.32 +(> /\ -: > / bs) |:#:i.32 +(>./\ -: >./ bs) |:#:i.32 +(>:/\ -: >:/ bs) |:#:i.32 +(+ /\ -: + / bs) |:#:i.32 +(+./\ -: +./ bs) |:#:i.32 +(+:/\ -: +:/ bs) |:#:i.32 +(* /\ -: * / bs) |:#:i.32 +(*./\ -: *./ bs) |:#:i.32 +(*:/\ -: *:/ bs) |:#:i.32 +(- /\ -: - / bs) |:#:i.32 +(% /\ -: % / bs) 5 32$1 +(^ /\ -: ^ / bs) |:#:i.32 +(~:/\ -: ~:/ bs) |:#:i.32 +(| /\ -: | / bs) |:#:i.32 +(! /\ -: ! / bs) |:#:i.32 + +(i.1+n) -: 0,+/\n$1 [ n=:?1000 +(n$1) -: +/\n{.1 [ n=:?1000 + +(-/\b) -: +/\b*($b)$1 _1 [ b=:?1000$2 +(-/\b) -: ($b)$1 0 [ b=:2000$1 + +f =: # ($&0 1@] , - $ 2&|@>:@]) i.&1 +*./(f -: >:/\)"1 #:i.32 + +f =: # ($&1 0@] , - $ 2&| @]) i.&0 +*./(f -: > /\)"1 #:i.32 + +(<./\ -: <./bs) a=:5e4-~?13$1e5 +(>./\ -: >./bs) a=:5e4-~?13$1e5 +(+ /\ -: + /bs) a=:5e4-~?13$1e5 +(* /\ -: * /bs) a=:50-~?9$100 +(- /\ -: - /bs) a=:5e4-~?13$1e5 +(% /\ -: % /bs) a=:a+0=a=:5e4-~?13$1e5 + +(<./\ -: <./bs) a=:5e4-~?10 7$1e5 +(>./\ -: >./bs) a=:5e4-~?10 7$1e5 +(+ /\ -: + /bs) a=:5e4-~?10 7$1e5 +(* /\ -: * /bs) a=:50-~?9$100 +(- /\ -: - /bs) a=:5e4-~?10 7$1e5 +(% /\ -: % /bs) a=:a+0=a=:5e4-~?10 7$1e5 + +(<./\ -: <./bs) a=: 4096 %~ 5e2-~?9$1e3 +(>./\ -: >./bs) a=: 4096 %~ 5e2-~?9$1e3 +(+ /\ -: + /bs) a=: 4096 %~ 5e2-~?9$1e3 +(* /\ -: * /bs) a=: 4096 %~ 54 -~?9$105 +(- /\ -: - /bs) a=: 4096 %~ 5e2-~?9$1e3 +(% /\ -: % /bs) a=:a+0=a=: 4096 %~ 54 -~?9$105 + +(<./\ -: <./bs) a=: 4096 %~ 5e2-~?5 7$1e3 +(>./\ -: >./bs) a=: 4096 %~ 5e2-~?5 7$1e3 +(+ /\ -: + /bs) a=: 4096 %~ 5e2-~?5 7$1e3 +(* /\ -: * /bs) a=: 4096 %~ 54 -~?4 7$105 +(- /\ -: - /bs) a=: 4096 %~ 5e2-~?4 7$1e3 +(% /\ -: % /bs) a=:a+0=a=: 4096 %~ 54 -~?4 7$105 + +(+ /\ -: + /bs) a=:j./?2 13$1e6 +(* /\ -: * /bs) a=:j./?2 13$100 +(- /\ -: - /bs) a=:j./?2 13$1e6 +(% /\ -: % /bs) a=:a+0=a=:j./?2 13$1e6 + +'domain error' -: < /\ etx 'abc' +'domain error' -: <./\ etx 'abc' +'domain error' -: <:/\ etx 'abc' +'domain error' -: > /\ etx 'abc' +'domain error' -: >./\ etx 'abc' +'domain error' -: >:/\ etx 'abc' + +'domain error' -: + /\ etx 'abc' +'domain error' -: +./\ etx 'abc' +'domain error' -: +:/\ etx 'abc' +'domain error' -: * /\ etx 'abc' +'domain error' -: *./\ etx 'abc' +'domain error' -: *:/\ etx 'abc' +'domain error' -: - /\ etx 'abc' +'domain error' -: % /\ etx 'abc' +'domain error' -: %:/\ etx 'abc' + +'domain error' -: ^ /\ etx 'abc' +'domain error' -: ^./\ etx 'abc' +'domain error' -: | /\ etx 'abc' +'domain error' -: ! /\ etx 'abc' +'domain error' -: ? /\ etx 'abc' + +'domain error' -: < /\ etx 2 3;'abc' +'domain error' -: <./\ etx 2 3;'abc' +'domain error' -: <:/\ etx 2 3;'abc' +'domain error' -: > /\ etx 2 3;'abc' +'domain error' -: >./\ etx 2 3;'abc' +'domain error' -: >:/\ etx 2 3;'abc' + +'domain error' -: + /\ etx 2 3;'abc' +'domain error' -: +./\ etx 2 3;'abc' +'domain error' -: +:/\ etx 2 3;'abc' +'domain error' -: * /\ etx 2 3;'abc' +'domain error' -: *./\ etx 2 3;'abc' +'domain error' -: *:/\ etx 2 3;'abc' +'domain error' -: - /\ etx 2 3;'abc' +'domain error' -: % /\ etx 2 3;'abc' +'domain error' -: %:/\ etx 2 3;'abc' + +'domain error' -: ^ /\ etx 2 3;'abc' +'domain error' -: ^./\ etx 2 3;'abc' +'domain error' -: | /\ etx 2 3;'abc' +'domain error' -: ! /\ etx 2 3;'abc' +'domain error' -: ? /\ etx 2 3;'abc' + + +NB. f\"r y -------------------------------------------------------------- + +(<bs"0 -: <\"0) x=:a.{~?3 5 7$#a. +(<bs"1 -: <\"1) x +(<bs"2 -: <\"2) x +(<bs"3 -: <\"3) x + +([bs"0 -: [\"0) x=:?3 5 7$1e5 +([bs"1 -: [\"1) x +([bs"2 -: [\"2) x +([bs"3 -: [\"3) x + +f=: [^:(0&~:@[) +(f/\ -: f/prefix ) x=: (? 15$2) * ? 15$10 +(f/\"1 -: f/prefix"1) x=: (?22 15$2) * ?22 15$10 + + +NB. f/\"r y ------------------------------------------------------------- + +(+/bs"0 -: +/\"0) x=:?3 7 5$2 +(+/bs"1 -: +/\"1) x +(+/bs"2 -: +/\"2) x +(+/bs"3 -: +/\"3) x + +(+/bs"0 -: +/\"0) x=:?3 12 7$200 +(+/bs"1 -: +/\"1) x +(+/bs"2 -: +/\"2) x +(+/bs"3 -: +/\"3) x + +(+/bs"0 -: +/\"0) x=:?3 12 7$2e9 +(+/bs"1 -: +/\"1) x +(+/bs"2 -: +/\"2) x +(+/bs"3 -: +/\"3) x + +(+/bs"0 -: +/\"0) x=:4096 %~ _1e4+?3 12 7$2e4 +(+/bs"1 -: +/\"1) x +(+/bs"2 -: +/\"2) x +(+/bs"3 -: +/\"3) x + +(-/bs"0 -: -/\"0) x=:?3 5 7$2 +(-/bs"1 -: -/\"1) x +(-/bs"2 -: -/\"2) x +(-/bs"3 -: -/\"3) x + +(-/bs"0 -: -/\"0) x=:?3 5 7$200 +(-/bs"1 -: -/\"1) x +(-/bs"2 -: -/\"2) x +(-/bs"3 -: -/\"3) x + +(-/bs"0 -: -/\"0) x=:4096 %~ _1e4+?3 12 7$2e4 +(-/bs"1 -: -/\"1) x +(-/bs"2 -: -/\"2) x +(-/bs"3 -: -/\"3) x + +(%/bs"0 -: %/\"0) x=:1+?3 5 7$200 +(%/bs"1 -: %/\"1) x +(%/bs"2 -: %/\"2) x +(%/bs"3 -: %/\"3) x + +(%/bs"0 -: %/\"0) x=:1+?3 5 7$200 +(%/bs"1 -: %/\"1) x +(%/bs"2 -: %/\"2) x +(%/bs"3 -: %/\"3) x + +(|/bs"0 -: |/\"0) x=:_100+?3 5 7$200 +(|/bs"1 -: |/\"1) x +(|/bs"2 -: |/\"2) x +(|/bs"3 -: |/\"3) x + +(<:/bs"0 -: <:/\"0) x=:?3 5 12$2 +(<:/bs"1 -: <:/\"1) x +(<:/bs"2 -: <:/\"2) x +(<:/bs"3 -: <:/\"3) x + +(=/bs"0 -: =/\"0) x=:?3 5 12$2 +(=/bs"1 -: =/\"1) x +(=/bs"2 -: =/\"2) x +(=/bs"3 -: =/\"3) x + +(~:/bs"0 -: ~:/\"0) x=:?3 5 12$2 +(~:/bs"1 -: ~:/\"1) x +(~:/bs"2 -: ~:/\"2) x +(~:/bs"3 -: ~:/\"3) x + +(>:/bs"0 -: >:/\"0) x=:?3 5 12$2 +(>:/bs"1 -: >:/\"1) x +(>:/bs"2 -: >:/\"2) x +(>:/bs"3 -: >:/\"3) x + +(>/bs"0 -: >/\"0) x=:?3 5 12$2 +(>/bs"1 -: >/\"1) x +(>/bs"2 -: >/\"2) x +(>/bs"3 -: >/\"3) x + +(+:/bs"0 -: +:/\"0) x=:?3 5 12$2 +(+:/bs"1 -: +:/\"1) x +(+:/bs"2 -: +:/\"2) x +(+:/bs"3 -: +:/\"3) x + +(+./bs"0 -: +./\"0) x=:?3 5 12$2 +(+./bs"1 -: +./\"1) x +(+./bs"2 -: +./\"2) x +(+./bs"3 -: +./\"3) x + +(*:/bs"0 -: *:/\"0) x=:?3 5 12$2 +(*:/bs"1 -: *:/\"1) x +(*:/bs"2 -: *:/\"2) x +(*:/bs"3 -: *:/\"3) x + +(*./bs"0 -: *./\"0) x=:?3 5 12$2 +(*./bs"1 -: *./\"1) x +(*./bs"2 -: *./\"2) x +(*./bs"3 -: *./\"3) x + +(-: +/\"1) i. 0 (0)}?1$10 +(-: +/\"1) i. 0 (0)}?2$10 +(-: +/\"1) i. 0 (0)}?3$10 +(-: +/\"1) i. 0 (0)}?4$10 +(-: +/\"1) i. 0 (0)}?5$10 + +(-: +/\"2) i. 0 (1)}?2$10 +(-: +/\"2) i. 0 (1)}?3$10 +(-: +/\"2) i. 0 (1)}?4$10 +(-: +/\"2) i. 0 (1)}?5$10 + +(-: +/\"2) i. 0 (2)}?3$10 +(-: +/\"2) i. 0 (2)}?4$10 +(-: +/\"2) i. 0 (2)}?5$10 + + +NB. x f\y --------------------------------------------------------------- + +NB. Boolean +a=:1=?11 5$2 +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (+./\ -: +./ bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:1 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +NB. literal +a=:a.{~32+?11 5$95 +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:'d' +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +NB. integer +a=:?11 5$110 +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (+/\ -: +/ bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:12 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +NB. floating point +a=:4096 %~ _100+?11 5$200 +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (+/\ -: +/ bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:2.71828 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +NB. complex +a=:j./4096 %~ _1e3+?2 11 5$2e3 +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (+/\ -: +/ bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:3j4 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +NB. boxed +t=:(1=?70$3)<;.1 ?70$110 +a=:t{~?11 3$#t +k (<\ -: < bs) a [ k=:_4+?11 +k (<\ -: < bs) ,a [ k=:_4+?11 +k (]\ -: ] bs) a [ k=:_4+?11 +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:1+#a +a=:<'Ivanhoe' +k (<\ -: < bs) a [ k=:0 +k (<\ -: < bs) a [ k=:4 + +(, <x) -: __ < \x=: ?20$100 +(, <x) -: (o._1e13)< \x +(,+/x) -: __ +/\x + +12 = # 0 (3 : 'y') \ i. 11 0 + +f=: i.@:>:@:$ +(5,$f (3,}.$x)$0) -: $ 3 f\x=: i.7 3 4 +(4,$f (3,}.$x)$0) -: $ 3 f\x=: i.6 3 4 +(3,$f (3,}.$x)$0) -: $ 3 f\x=: i.5 3 4 +(2,$f (3,}.$x)$0) -: $ 3 f\x=: i.4 3 4 +(1,$f (3,}.$x)$0) -: $ 3 f\x=: i.3 3 4 +(0,$f (3,}.$x)$0) -: $ 3 f\x=: i.2 3 4 +(0,$f (3,}.$x)$0) -: $ 3 f\x=: i.1 3 4 +(0,$f (3,}.$x)$0) -: $ 3 f\x=: i.0 3 4 + +(8,$f (0,}.$x)$0) -: $ 0 f\x=: i.7 3 4 +(7,$f (0,}.$x)$0) -: $ 0 f\x=: i.6 3 4 +(6,$f (0,}.$x)$0) -: $ 0 f\x=: i.5 3 4 +(5,$f (0,}.$x)$0) -: $ 0 f\x=: i.4 3 4 +(4,$f (0,}.$x)$0) -: $ 0 f\x=: i.3 3 4 +(3,$f (0,}.$x)$0) -: $ 0 f\x=: i.2 3 4 +(2,$f (0,}.$x)$0) -: $ 0 f\x=: i.1 3 4 +(1,$f (0,}.$x)$0) -: $ 0 f\x=: i.0 3 4 + +(3,$f (3,}.$x)$0) -: $ _3 f\x=: i.7 3 4 +(2,$f (3,}.$x)$0) -: $ _3 f\x=: i.6 3 4 +(2,$f (3,}.$x)$0) -: $ _3 f\x=: i.5 3 4 +(2,$f (3,}.$x)$0) -: $ _3 f\x=: i.4 3 4 +(1,$f (3,}.$x)$0) -: $ _3 f\x=: i.3 3 4 +(1,$f (2,}.$x)$0) -: $ _3 f\x=: i.2 3 4 +(1,$f (1,}.$x)$0) -: $ _3 f\x=: i.1 3 4 +(0,$f (0,}.$x)$0) -: $ _3 f\x=: i.0 3 4 + +(0 5$0) -: 5 +\ 3 4 +(0 5$0) -: 5 +\ 3 4.5 +(0 5$0) -: 5 +\ 3 4j5 +(0 5$0) -: 5 +\ 3 4x +(0 5$0) -: 5 +\ 3 4r5 + +(0 5$0) -: 5 (3 : 'y')\ 3 4 +(0 5$0) -: 5 (3 : 'y')\ 3 4.5 +(0 5$0) -: 5 (3 : 'y')\ 3 4j5 +(0 5$0) -: 5 (3 : 'y')\ 3 4x +(0 5$0) -: 5 (3 : 'y')\ 3 4r5 + +'domain error' -: 'a' <\ etx i.12 +'domain error' -: 3.5 <\ etx i.12 +'domain error' -: (o._1e12)<\ etx i.12 +'domain error' -: 3j4 <\ etx i.12 +'domain error' -: (<9) <\ etx i.12 + +(5 +`%\1 2 3) -: 5 +`%\1 2 3x + + +4!:55 ;:'A a b base bs bsd em en f iind ' +4!:55 ;:'infix inv k kay key n ob oind omask osub ' +4!:55 ;:'outfix prefix sd seg suffix t test w x y' + +
new file mode 100644 --- /dev/null +++ b/test/g430a2.ijs @@ -0,0 +1,151 @@ +NB. 2 f/\y and 2 f~/\y for vector y ------------------------------------- + +f=: =/ +(2 = /\y) -: 2 f\y=: ? 101$2 +(2 = /\y) -: 2 f\y=: ? 100$1e6 +(2 = /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 = /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: </ +(2 < /\y) -: 2 f\y=: ? 101$2 +(2 < /\y) -: 2 f\y=: ? 100$1e6 +(2 < /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: <./ +(2 <./\y) -: 2 f\y=: ? 101$2 +(2 <./\y) -: 2 f\y=: ? 100$1e6 +(2 <./\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: <:/ +(2 <:/\y) -: 2 f\y=: ? 101$2 +(2 <:/\y) -: 2 f\y=: ? 100$1e6 +(2 <:/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: >/ +(2 > /\y) -: 2 f\y=: ? 101$2 +(2 > /\y) -: 2 f\y=: ? 100$1e6 +(2 > /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: >./ +(2 >./\y) -: 2 f\y=: ? 101$2 +(2 >./\y) -: 2 f\y=: ? 100$1e6 +(2 >./\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: >:/ +(2 >:/\y) -: 2 f\y=: ? 101$2 +(2 >:/\y) -: 2 f\y=: ? 100$1e6 +(2 >:/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: +/ +(2 + /\y) -: 2 f\y=: ? 101$2 +(2 + /\y) -: 2 f\y=: ? 100$1e6 +(2 + /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 + /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: +./ +(2 +./\y) -: 2 f\y=: ? 101$2 +(2 +./\y) -: 2 f\y=: ? 100$1e6 +(2 +./\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 +./\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: +:/ +(2 +:/\y) -: 2 f\y=: ? 101$2 + +f=: */ +(2 * /\y) -: 2 f\y=: ? 101$2 +(2 * /\y) -: 2 f\y=: ? 100$1e6 +(2 * /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 * /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: *./ +(2 *./\y) -: 2 f\y=: ? 101$2 +(2 *./\y) -: 2 f\y=: ? 100$1e6 +(2 *./\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 *./\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: *:/ +(2 *:/\y) -: 2 f\y=: ? 101$2 + +f=: -/ +(2 - /\y) -: 2 f\y=: ? 101$2 +(2 - /\y) -: 2 f\y=: ? 101$1e6 +(2 - /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 - /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: %/ +(2 % /\y) -: 2 f\y=: ? 101$2 +(2 % /\y) -: 2 f\y=: ? 101$1e6 +(2 % /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 % /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: ^/ +(2 ^ /\y) -: 2 f\y=: ? 101$2 +(2 ^ /\y) -: 2 f\y=: ? 101$13 +(2 ^ /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 ^ /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: ^./ +NB. (2 ^./\y) -: 2 f\y=: ? 101$2 +(2 ^./\y) -: 2 f\y=: 1+?101$13 +(2 ^./\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 ^./\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: ~:/ +(2 ~:/\y) -: 2 f\y=: ? 101$2 +(2 ~:/\y) -: 2 f\y=: ? 101$1e3 +(2 ~:/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 ~:/\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: |/ +(2 | /\y) -: 2 f\y=: ? 101$2 +(2 | /\y) -: 2 f\y=: ? 101$1e3 +(2 | /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 | /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: !/ +(2 ! /\y) -: 2 f\y=: ? 101$2 +(2 ! /\y) -: 2 f\y=: ? 101$113 +(2 ! /\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 ! /\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: <~/ +(2 < ~/\y) -: 2 f\y=: ? 101$2 +(2 < ~/\y) -: 2 f\y=: ? 100$1e6 +(2 < ~/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: <:~/ +(2 <:~/\y) -: 2 f\y=: ? 101$2 +(2 <:~/\y) -: 2 f\y=: ? 100$1e6 +(2 <:~/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 + +f=: -~/ +(2 - ~/\y) -: 2 f\y=: ? 101$2 +(2 - ~/\y) -: 2 f\y=: ? 101$1e6 +(2 - ~/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 - ~/\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +f=: !~/ +(2 ! ~/\y) -: 2 f\y=: ? 101$2 +(2 ! ~/\y) -: 2 f\y=: ? 101$113 +(2 ! ~/\y) -: 2 f\y=: (2^_8)*_1e3+? 101$2e3 +(2 ! ~/\y) -: 2 f\y=: j./(2^_8)*_1e3+?2 101$2e3 + +y=: 1e4 ?@$ 2 +((}:> }.) -: 2 > /\]) y +((}:>:}.) -: 2 >:/\]) y +((}:< }.) -: 2 < /\]) y +((}:<:}.) -: 2 <:/\]) y +((}:+.}.) -: 2 +./\]) y +((}:*.}.) -: 2 *./\]) y +((}:= }.) -: 2 = /\]) y +((}:~:}.) -: 2 ~:/\]) y + +NB. commented out because times were too close (within 10%) and prone to fail +NB. y=: 1e6 ?@$ 2 +NB. >/ t=: 6!:2 '(}:+.}.)y',:'2+./\y' +NB. >/ t=: 6!:2 '(}:~:}.)y',:'2~:/\y' + + +4!:55 ;:'f t y' + +
new file mode 100644 --- /dev/null +++ b/test/g430avg.ijs @@ -0,0 +1,46 @@ +NB. x (+/ % #)\ y ------------------------------------------------------- + +avg=: 3 : '(+/y)%#y' + +test=: 3 : 0 + m=: 1+?50 + for_c. (i.0);3;2 3 do. + d=. >c + assert. m (avg\ -: (+/ % #)\) yy=: (?(500 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(254 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(255 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(256 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(257 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(258 ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?(m ,d)$#y){y + assert. m (avg\ -: (+/ % #)\) yy=: (?((m-1),d)$#y){y + assert. 1 (avg\ -: (+/ % #)\) yy=: (?(20 ,d)$#y){y + assert. 1 (avg\ -: (+/ % #)\) yy=: (?(1 ,d)$#y){y + assert. 0 (avg\ -: (+/ % #)\) yy=: (?(20 ,d)$#y){y + assert. 0 (avg\ -: (+/ % #)\) yy=: (i.0 ,d ){y + assert. _5 (avg\ -: (+/ % #)\) yy=: (?(25 ,d)$#y){y + assert. _5 (avg\ -: (+/ % #)\) yy=: (?(23 ,d)$#y){y + assert. _5 (avg\ -: (+/ % #)\) yy=: (?(3 ,d)$#y){y + assert. _5 (avg\ -: (+/ % #)\) yy=: (i.0 ,d ){y + assert. _ (avg\ -: (+/ % #)\) yy=: (?(23 ,d)$#y){y + assert. _ (avg\ -: (+/ % #)\) yy=: (i.0 ,d ){y + assert. __ (avg\ -: (+/ % #)\) yy=: (?(23 ,d)$#y){y + assert. __ (avg\ -: (+/ % #)\) yy=: (i.0 ,d ){y + end. + 1 +) + +test 0 1 NB. boolean +test ?$~1000 NB. integer +test 256%~?$~5000 NB. floating point +test 256%~j./?2 1000$5000 NB. complex + +12 (avg\ -: (+/%#)\) _ (?100)} ?100 $1e5 +12 (avg\ -: (+/%#)\) _ (?100)} ?100 3$1e5 +12 (avg\ -: (+/%#)\) __ (?100)} ?100 $1e5 +12 (avg\ -: (+/%#)\) __ (?100)} ?100 3$1e5 + + +4!:55 ;:'avg m test yy' + +
new file mode 100644 --- /dev/null +++ b/test/g430b.ijs @@ -0,0 +1,111 @@ +NB. f/\ B --------------------------------------------------------------- + +eq =. 4 : 'x= y' +lt =. 4 : 'x< y' +le =. 4 : 'x<:y' +gt =. 4 : 'x> y' +ge =. 4 : 'x>:y' +or =. 4 : 'x+.y' +nor =. 4 : 'x+:y' +and =. 4 : 'x*.y' +nand=. 4 : 'x*:y' +ne =. 4 : 'x~:y' + +(=/\"1 -: eq/\"1) x=.0<?17 13$4 +(=/\"1 -: eq/\"1) x=.0=?17 13$4 +(=/\"1 -: eq/\"1) x=.0<?16 24$4 +(=/\"1 -: eq/\"1) x=.0=?16 24$4 + +(=/\"2 -: eq/\"2) x=.0<?2 17 13$4 +(=/\"2 -: eq/\"2) x=.0=?2 17 13$4 +(=/\"2 -: eq/\"2) x=.0<?2 16 24$4 +(=/\"2 -: eq/\"2) x=.0=?2 16 24$4 + +(</\"1 -: lt/\"1) x=.0<?17 13$4 +(</\"1 -: lt/\"1) x=.0=?17 13$4 +(</\"1 -: lt/\"1) x=.0<?16 24$4 +(</\"1 -: lt/\"1) x=.0=?16 24$4 + +(</\"2 -: lt/\"2) x=.0<?2 17 13$4 +(</\"2 -: lt/\"2) x=.0=?2 17 13$4 +(</\"2 -: lt/\"2) x=.0<?2 16 24$4 +(</\"2 -: lt/\"2) x=.0=?2 16 24$4 + +(<:/\"1 -: le/\"1) x=.0<?17 13$4 +(<:/\"1 -: le/\"1) x=.0=?17 13$4 +(<:/\"1 -: le/\"1) x=.0<?16 24$4 +(<:/\"1 -: le/\"1) x=.0=?16 24$4 + +(<:/\"2 -: le/\"2) x=.0<?2 17 13$4 +(<:/\"2 -: le/\"2) x=.0=?2 17 13$4 +(<:/\"2 -: le/\"2) x=.0<?2 16 24$4 +(<:/\"2 -: le/\"2) x=.0=?2 16 24$4 + +(>/\"1 -: gt/\"1) x=.0<?17 13$4 +(>/\"1 -: gt/\"1) x=.0=?17 13$4 +(>/\"1 -: gt/\"1) x=.0<?16 24$4 +(>/\"1 -: gt/\"1) x=.0=?16 24$4 + +(>/\"2 -: gt/\"2) x=.0<?2 17 13$4 +(>/\"2 -: gt/\"2) x=.0=?2 17 13$4 +(>/\"2 -: gt/\"2) x=.0<?2 16 24$4 +(>/\"2 -: gt/\"2) x=.0=?2 16 24$4 + +(>:/\"1 -: ge/\"1) x=.0<?17 13$4 +(>:/\"1 -: ge/\"1) x=.0=?17 13$4 +(>:/\"1 -: ge/\"1) x=.0<?16 24$4 +(>:/\"1 -: ge/\"1) x=.0=?16 24$4 + +(>:/\"2 -: ge/\"2) x=.0<?2 17 13$4 +(>:/\"2 -: ge/\"2) x=.0=?2 17 13$4 +(>:/\"2 -: ge/\"2) x=.0<?2 16 24$4 +(>:/\"2 -: ge/\"2) x=.0=?2 16 24$4 + +(+./\"1 -: or/\"1) x=.0<?17 13$4 +(+./\"1 -: or/\"1) x=.0=?17 13$4 +(+./\"1 -: or/\"1) x=.0<?16 24$4 +(+./\"1 -: or/\"1) x=.0=?16 24$4 + +(+./\"2 -: or/\"2) x=.0<?2 17 13$4 +(+./\"2 -: or/\"2) x=.0=?2 17 13$4 +(+./\"2 -: or/\"2) x=.0<?2 16 24$4 +(+./\"2 -: or/\"2) x=.0=?2 16 24$4 + +(+:/\"1 -: nor/\"1) x=.0<?17 13$4 +(+:/\"1 -: nor/\"1) x=.0=?17 13$4 +(+:/\"1 -: nor/\"1) x=.0<?16 24$4 +(+:/\"1 -: nor/\"1) x=.0=?16 24$4 + +(+:/\"2 -: nor/\"2) x=.0<?2 17 13$4 +(+:/\"2 -: nor/\"2) x=.0=?2 17 13$4 +(+:/\"2 -: nor/\"2) x=.0<?2 16 24$4 +(+:/\"2 -: nor/\"2) x=.0=?2 16 24$4 + +(*./\"1 -: and/\"1) x=.0<?17 13$4 +(*./\"1 -: and/\"1) x=.0=?17 13$4 +(*./\"1 -: and/\"1) x=.0<?16 24$4 +(*./\"1 -: and/\"1) x=.0=?16 24$4 + +(*:/\"1 -: nand/\"1) x=.0<?17 13$4 +(*:/\"1 -: nand/\"1) x=.0=?17 13$4 +(*:/\"1 -: nand/\"1) x=.0<?16 24$4 +(*:/\"1 -: nand/\"1) x=.0=?16 24$4 + +(*:/\"2 -: nand/\"2) x=.0<?2 17 13$4 +(*:/\"2 -: nand/\"2) x=.0=?2 17 13$4 +(*:/\"2 -: nand/\"2) x=.0<?2 16 24$4 +(*:/\"2 -: nand/\"2) x=.0=?2 16 24$4 + +(~:/\"1 -: ne/\"1) x=.0<?17 13$4 +(~:/\"1 -: ne/\"1) x=.0=?17 13$4 +(~:/\"1 -: ne/\"1) x=.0<?16 24$4 +(~:/\"1 -: ne/\"1) x=.0=?16 24$4 + +(~:/\"2 -: ne/\"2) x=.0<?2 17 13$4 +(~:/\"2 -: ne/\"2) x=.0=?2 17 13$4 +(~:/\"2 -: ne/\"2) x=.0<?2 16 24$4 +(~:/\"2 -: ne/\"2) x=.0=?2 16 24$4 + +4!:55 ;:'and eq ge gt le lt nand nor ne or x' + +
new file mode 100644 --- /dev/null +++ b/test/g430d.ijs @@ -0,0 +1,98 @@ +NB. x ]\y and x [\y and x ,\ y ------------------------------------------ + +test=: 1 : 0 + : + assert. x u y{~?10 $#y + assert. x u y{~?11 $#y + assert. x u y{~?12 $#y + assert. x u y{~?13 2 3$#y + assert. x u y{~?14 2 1 3$#y + 1 +) + +5 ([\ -: >@:(<\)) test 0 1 +5 ([\ -: >@:(<\)) test 'chiaroscuro' +5 ([\ -: >@:(<\)) test 2 3 4 +5 ([\ -: >@:(<\)) test o.i.5 +5 ([\ -: >@:(<\)) test j./?2 3 4$100 +5 ([\ -: >@:(<\)) test ;:'Cogito, ergo sum.' + +5 (]\ -: >@:(<\)) test 0 1 +5 (]\ -: >@:(<\)) test 'chiaroscuro' +5 (]\ -: >@:(<\)) test 2 3 4 +5 (]\ -: >@:(<\)) test o.i.5 +5 (]\ -: >@:(<\)) test j./?2 3 4$100 +5 (]\ -: >@:(<\)) test ;:'Cogito, ergo sum.' + +5 (,\ -:,&>@:(<\)) test 0 1 +5 (,\ -:,&>@:(<\)) test 'chiaroscuro' +5 (,\ -:,&>@:(<\)) test 2 3 4 +5 (,\ -:,&>@:(<\)) test o.i.5 +5 (,\ -:,&>@:(<\)) test j./?2 3 4$100 +5 (,\ -:,&>@:(<\)) test ;:'Cogito, ergo sum.' + +_5 ([\ -: >@:(<\)) test 0 1 +_5 ([\ -: >@:(<\)) test 'chiaroscuro' +_5 ([\ -: >@:(<\)) test 2 3 4 +_5 ([\ -: >@:(<\)) test o.i.5 +_5 ([\ -: >@:(<\)) test j./?2 3 4$100 +_5 ([\ -: >@:(<\)) test ;:'Cogito, ergo sum.' + +_5 (]\ -: >@:(<\)) test 0 1 +_5 (]\ -: >@:(<\)) test 'chiaroscuro' +_5 (]\ -: >@:(<\)) test 2 3 4 +_5 (]\ -: >@:(<\)) test o.i.5 +_5 (]\ -: >@:(<\)) test j./?2 3 4$100 +_5 (]\ -: >@:(<\)) test ;:'Cogito, ergo sum.' + +5 (,\ -:,&>@:(<\)) test 0 1 +5 (,\ -:,&>@:(<\)) test 'chiaroscuro' +5 (,\ -:,&>@:(<\)) test 2 3 4 +5 (,\ -:,&>@:(<\)) test o.i.5 +5 (,\ -:,&>@:(<\)) test j./?2 3 4$100 +5 (,\ -:,&>@:(<\)) test ;:'Cogito, ergo sum.' + +(i.(1+k), 2e9 0) -: 2e9 [\ ((k+2e9),0)$0 [ k=: 147483647 +(i.(1+k), 2e9 0) -: 2e9 ]\ ((k+2e9),0)$0 +(i.(1+k), 0) -: 2e9 ,\ ((k+2e9),0)$0 +(i.(1+k), 2e9 0) -: 2e9 [\ ((k+2e9),0)$0 [ k=: ?147483647 +(i.(1+k), 2e9 0) -: 2e9 ]\ ((k+2e9),0)$0 [ k=: ?147483647 +(i.(1+k), 0) -: 2e9 ,\ ((k+2e9),0)$0 [ k=: ?147483647 + +'domain error' -: 0 [\ etx i.imax,0 +'domain error' -: 0 ]\ etx i.imax,0 +'domain error' -: 0 ,\ etx i.imax,0 + +(i.1 10 0) -: (<:-imax) [\ i.10 0 +(i.1 10 0) -: (<:-imax) ]\ i.10 0 +(i.1 0) -: (<:-imax) ,\ i.10 2 0 + +m=: imax-2e6 +(i.0,m,2 3) -: m [\ i.0 2 3 +(i.0,m,1e9 3) -: m [\ i.0 1e9 3 +(i.0,m,2 3) -: m ]\ i.0 2 3 +(i.0,m,1e9 3) -: m ]\ i.0 1e9 3 +'limit error' -: m ,\ etx i.0 2 3 +'limit error' -: m ,\ etx i.0 2e9 3 + +(,\~ i.2) -: 4=i.2 3 1 +(,\~i.2) -: 4 : 'x,\y'"0 _ ~ i.2 +(,\~i.3) -: 4 : 'x,\y'"0 _ ~ i.3 +(,\~i.6) -: 4 : 'x,\y'"0 _ ~ i.6 + +_5 (]\ -: 3 : ']y'\) 3 4 5 +_5 ([\ -: 3 : '[y'\) 3 4 5 +_5 (,\ -: 3 : ',y'\) 3 4 5 + +_5 (]\ -: 3 : ']y'\) 3 4 5$'a' +_5 ([\ -: 3 : '[y'\) <"0 i. 3 4 5 +_5 (,\ -: 3 : ',y'\) o.i.3 4 5 + +_5 (]\ -: 3 : ']y'\) 0 4 5$'a' +_5 ([\ -: 3 : '[y'\) <"0 i. 0 4 5 +_5 (,\ -: 3 : ',y'\) o.i.0 4 5 + + +4!:55 ;:'k m test' + +
new file mode 100644 --- /dev/null +++ b/test/g430fin.ijs @@ -0,0 +1,75 @@ +NB. x +/\ y ------------------------------------------------------------- + +test=: 1 : 0 + f=: 3 : ((5!:5 <'u'),'/y')\ + g=: u f./\ + mm=: 1+?50 + for_c. (i.0);3;2 3 do. + d=. >c + assert. mm (f -: g) yy=: (?(500 ,d)$#y){y + assert. mm (f -: g) yy=: (?(254 ,d)$#y){y + assert. mm (f -: g) yy=: (?(255 ,d)$#y){y + assert. mm (f -: g) yy=: (?(256 ,d)$#y){y + assert. mm (f -: g) yy=: (?(257 ,d)$#y){y + assert. mm (f -: g) yy=: (?(258 ,d)$#y){y + assert. mm (f -: g) yy=: (?(mm ,d)$#y){y + assert. mm (f -: g) yy=: (?((mm-1),d)$#y){y + assert. 2 (f -: g) yy=: (?(20 ,d)$#y){y + assert. 2 (f -: g) yy=: (?(1 ,d)$#y){y + assert. 1 (f -: g) yy=: (?(20 ,d)$#y){y + assert. 1 (f -: g) yy=: (?(1 ,d)$#y){y + assert. 0 (f -: g) yy=: (?(20 ,d)$#y){y + assert. 0 (f -: g) yy=: (i.0 ,d ){y + assert. _5 (f -: g) yy=: (?(25 ,d)$#y){y + assert. _5 (f -: g) yy=: (?(23 ,d)$#y){y + assert. _5 (f -: g) yy=: (?(3 ,d)$#y){y + assert. _5 (f -: g) yy=: (i.0 ,d ){y + assert. _ (f -: g) yy=: (?(23 ,d)$#y){y + assert. _ (f -: g) yy=: (i.0 ,d ){y + assert. __ (f -: g) yy=: (?(23 ,d)$#y){y + assert. __ (f -: g) yy=: (i.0 ,d ){y + end. + 1 +) + ++ test 0 1 NB. boolean +<. test 0 1 +>. test 0 1 ++. test 0 1 +*. test 0 1 += test 0 1 +~: test 0 1 + ++ test ?1000$1e3 NB. small integer +<. test ?1000$1e3 +>. test ?1000$1e3 + ++ test ?1000$2e8 NB. large integer +<. test ?1000$2e8 +>. test ?1000$2e8 + ++ test 256%~?$~5000 NB. floating point +>. test 256%~?$~5000 +<. test 256%~?$~5000 + ++ test 256%~j./?2 1000$5000 NB. complex + ++ test 1000 ?@$ 1e9 ++ test 1000 ?@$ 2e9 ++ test (1000 ?@$ 2e9)* _1^1000 ?@$ 2 + +sum=: 3 : '+/y' + +12 (sum\ -: +/\) _ (?100)} ?100 $1e5 +12 (sum\ -: +/\) _ (?100)} ?100 3$1e5 +12 (sum\ -: +/\) __ (?100)} ?100 $1e5 +12 (sum\ -: +/\) __ (?100)} ?100 3$1e5 + +3 (sum\ -: +/\) 675365485 435227401 325776289 990265772 435227401 852965599 + +4 = type 12 +/\ ?100$1e5 + + +4!:55 ;:'f g mm sum test yy' + +
new file mode 100644 --- /dev/null +++ b/test/g430inv.ijs @@ -0,0 +1,21 @@ +NB. inverses of scans --------------------------------------------------- + +inv=: 1 : 'x^:_1' + +w -: +/\ inv +/\ w=:_20+?20 3$50 +w -: -/\ inv -/\ w=:_20+?30 3$50 +w -: */\ inv */\ w=:w+0=w=:0.5*_20+?25 4$50 +w -: %/\ inv %/\ w=:w+0=w=:0.5*_20+?25 4$50 +w -: =/\ inv =/\ w=:1=?40 2$3 +w -: ~:/\ inv ~:/\ w=:1=?40 2$3 + +w -: +/\. inv +/\. w=:_20+?20 3$50 +w -: -/\. inv -/\. w=:_20+?30 3$50 +w -: */\. inv */\. w=:w+0=w=:0.5*_20+?25 4$50 +w -: %/\. inv %/\. w=:w+0=w=:0.5*_20+?25 4$50 +w -: =/\. inv =/\. w=:1=?40 2$3 +w -: ~:/\. inv ~:/\. w=:1=?40 2$3 + + +4!:55 ;:'inv w' +
new file mode 100644 --- /dev/null +++ b/test/g431.ijs @@ -0,0 +1,269 @@ +NB. f/. f\ f\. models -------------------------------------------------- +en =: #@] +em =: (en >.@% 1&>.@|@[)`(en 0&>.@>:@- [) @. (0&<:@[) +kay =: en`em @. (0&<@[) +omask =: (em,en) $ ($&0@|@[ , $&1@kay) + +base =: 1&>.@-@[ * i.@em +iind =: base ,. |@[ <. en - base +seg =: ((+i.)/@[ { ])"1 _ + +infix =: 1 : '(iind x@seg ])"0 _' +outfix =: 1 : '(omask x@# ])"0 _' +prefix =: 1 : '>:@,.@i.@# x@{. ]' +suffix =: 1 : ',.@i.@# x@}. ]' + +key =: 1 : '=@[ x@# ]' + +osub =: >@]`(>@[ >@:{ ]) @. (*@#@]) +oind =: (+/&i./ </.&, i.)@(2&{.)@(,&1 1)@$ +ob =: 1 : 'oind x@osub"0 1 ,@(<"_2)' + +bs =: 1 : '(x prefix) : (x infix )' +bsd =: 1 : '(x suffix) : (x outfix)' +sd =: 1 : '(x ob ) : (x key )' + + +NB. f\.y ---------------------------------------------------------------- + +NB. Boolean +a=:1=?10 5$2 +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a +(+./\. -: +./ bsd) a + +NB. literal +a=:a.{~32+?10 5$95 +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a + +NB. integer +a=:?10 5$100 +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a +(+/\. -: +/ bsd) a + +NB. floating point +a=:o._40+?10 5$100 +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a +(+/\. -: +/ bsd) a + +NB. complex +a=:^0j0.01*_400+?10 5$1000 +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a +(+/\. -: +/ bsd) a + +NB. boxed +t=:(1=?70$3)<;.1 ?70$100 +a=:t{~?10 3$#t +(<\. -: < bsd) a +(<\. -: < bsd) ,a +(]\. -: ] bsd) a + +'' -: <\. '' +'' -: <\. i.0 10 20 + + +NB. f/\.y ---------------------------------------------------------------- + +(= /\. -: = / bsd) ?20$2 +(< /\. -: < / bsd) ?20$2 +(<./\. -: <./ bsd) ?20$2 +(<:/\. -: <:/ bsd) ?20$2 +(> /\. -: > / bsd) ?20$2 +(>./\. -: >./ bsd) ?20$2 +(>:/\. -: >:/ bsd) ?20$2 +(+ /\. -: + / bsd) ?20$2 +(+./\. -: +./ bsd) ?20$2 +(+:/\. -: +:/ bsd) ?20$2 +(* /\. -: * / bsd) ?20$2 +(*./\. -: *./ bsd) ?20$2 +(*:/\. -: *:/ bsd) ?20$2 +(- /\. -: - / bsd) ?20$2 +(% /\. -: % / bsd) ?20$2 +(^ /\. -: ^ / bsd) ?20$2 +(~:/\. -: ~:/ bsd) ?20$2 +(| /\. -: | / bsd) ?20$2 +(! /\. -: ! / bsd) ?20$2 + +*./(= /\. -: = / bsd)"1 #:i.32 +*./(< /\. -: < / bsd)"1 #:i.32 +*./(<./\. -: <./ bsd)"1 #:i.32 +*./(<:/\. -: <:/ bsd)"1 #:i.32 +*./(> /\. -: > / bsd)"1 #:i.32 +*./(>./\. -: >./ bsd)"1 #:i.32 +*./(>:/\. -: >:/ bsd)"1 #:i.32 +*./(+ /\. -: + / bsd)"1 #:i.32 +*./(+./\. -: +./ bsd)"1 #:i.32 +*./(+:/\. -: +:/ bsd)"1 #:i.32 +*./(* /\. -: * / bsd)"1 #:i.32 +*./(*./\. -: *./ bsd)"1 #:i.32 +*./(*:/\. -: *:/ bsd)"1 #:i.32 +*./(- /\. -: - / bsd)"1 #:i.32 +*./(% /\. -: % / bsd)"1 #:i.32 +*./(^ /\. -: ^ / bsd)"1 #:i.32 +*./(~:/\. -: ~:/ bsd)"1 #:i.32 +*./(| /\. -: | / bsd)"1 #:i.32 +*./(! /\. -: ! / bsd)"1 #:i.32 + +*./(= /\. -: = / bsd) |:#:i.32 +*./(< /\. -: < / bsd) |:#:i.32 +*./(<./\. -: <./ bsd) |:#:i.32 +*./(<:/\. -: <:/ bsd) |:#:i.32 +*./(> /\. -: > / bsd) |:#:i.32 +*./(>./\. -: >./ bsd) |:#:i.32 +*./(>:/\. -: >:/ bsd) |:#:i.32 +*./(+ /\. -: + / bsd) |:#:i.32 +*./(+./\. -: +./ bsd) |:#:i.32 +*./(+:/\. -: +:/ bsd) |:#:i.32 +*./(* /\. -: * / bsd) |:#:i.32 +*./(*./\. -: *./ bsd) |:#:i.32 +*./(*:/\. -: *:/ bsd) |:#:i.32 +*./(- /\. -: - / bsd) |:#:i.32 +*./(% /\. -: % / bsd) |:#:i.32 +*./(^ /\. -: ^ / bsd) |:#:i.32 +*./(~:/\. -: ~:/ bsd) |:#:i.32 +*./(| /\. -: | / bsd) |:#:i.32 +*./(! /\. -: ! / bsd) |:#:i.32 + +(<./\. -: <./bsd) 5e5-~20$1e6 +(>./\. -: >./bsd) 5e5-~?20$1e6 +(+ /\. -: + /bsd) 5e5-~?20$1e6 +(* /\. -: * /bsd) 50-~?7$100 +(- /\. -: - /bsd) 5e5-~?20$1e6 +(% /\. -: % /bsd) 5e5-~?20$1e6 + +(<./\. -: <./bsd) 5e5-~?10 17$1e6 +(>./\. -: >./bsd) 5e5-~?10 17$1e6 +(+ /\. -: + /bsd) 5e5-~?10 17$1e6 +(* /\. -: * /bsd) 50-~?10 17$100 +(- /\. -: - /bsd) 5e5-~?10 17$1e6 +(% /\. -: % /bsd) 5e5-~?10 17$1e6 + +(<./\. -: <./bsd) o.500-~?20$1e3 +(>./\. -: >./bsd) o.500-~?20$1e3 +(+ /\. -: + /bsd) o.500-~?20$1e3 +(* /\. -: * /bsd) o.50-~?7$100 +(- /\. -: - /bsd) o.500-~?20$1e3 +(% /\. -: % /bsd) o.500-~?20$1e3 + +(<./\. -: <./bsd) o.455-~?10 17$1e3 +(>./\. -: >./bsd) o.455-~?10 17$1e3 +(+ /\. -: + /bsd) o.455-~?10 17$1e3 +(* /\. -: * /bsd) o.50-~?10 17$100 +(- /\. -: - /bsd) o.455-~?10 17$1e3 +(% /\. -: % /bsd) o.455-~?10 17$1e3 + +(+ /\. -: + /bsd) j./?2 20$1e6 +(* /\. -: * /bsd) j./?2 20$100 +(- /\. -: - /bsd) j./?2 20$1e6 +(% /\. -: % /bsd) j./?2 20$1e6 + +(+ /\. -: + /bsd) r.?10 17$1e6 +(* /\. -: * /bsd) r.?10 17$100 +(- /\. -: - /bsd) r.?10 17$1e6 +(% /\. -: % /bsd) r.?10 17$1e6 + +(i.-1+n) -: 0,~+/\.n#1 [ n=:?1000 +(n#1) -: +/\.(-n){.1 [ n=:?1000 + +(-/\.x) -: (#x)$2|0 1+#x=:2000$1 +(-/\.x) -: (#x)$2|0 1+#x=:2001$1 +(-/\.x) -: +/\.&.(*&((#x)$_1^1 0+#x)) x=:_900+?100 7$2000 +(-/\.x) -: +/\.&.(*&((#x)$_1^1 0+#x)) x=:_900+?101 7$2000 + +(%/\.x) -: */\.&.(^&((#x)$_1^1 0+#x)) x=:>:?100 7$200 +(%/\.x) -: */\.&.(^&((#x)$_1^1 0+#x)) x=:>:?101 7$200 + + +NB. f\."r y ------------------------------------------------------------- + +(<bsd"0 -: <\."0) x=:?3 5 7$1000 +(<bsd"1 -: <\."1) x +(<bsd"2 -: <\."2) x +(<bsd"3 -: <\."3) x + +([bsd"0 -: [\."0) x=:a.{~?2 3 5$#a. +([bsd"1 -: [\."1) x +([bsd"2 -: [\."2) x +([bsd"3 -: [\."3) x + +f=: [^:(0&~:@[) +(f/\. -: f/suffix ) x=: (? 15$2) * ? 15$10 +(f/\."1 -: f/suffix"1) x=: (?22 15$2) * ?22 15$10 + + +NB. f/\."r y ------------------------------------------------------------ + +plus =: 4 : 'x+y' +sum =: 3 : '+ /y' +#~. (sum\."0 ; plus/\."0 ; +/\."0) x=:?7 5 11$1e6 +#~. (sum\."1 ; plus/\."1 ; +/\."1) x +#~. (sum\."2 ; plus/\."2 ; +/\."2) x +#~. (sum\."3 ; plus/\."3 ; +/\."3) x +#~. (sum\."0 ; plus/\."0 ; +/\."0) x=:?7 5 11$6e8 +#~. (sum\."1 ; plus/\."1 ; +/\."1) x +#~. (sum\."2 ; plus/\."2 ; +/\."2) x +#~. (sum\."3 ; plus/\."3 ; +/\."3) x + +times =: 4 : 'x*y' +product =: 3 : '* /y' +#~. (product\."0 ; times/\."0 ; */\."0) x=:x+0=x=:50-?7 5 11$100 +#~. (product\."1 ; times/\."1 ; */\."1) x +#~. (product\."2 ; times/\."2 ; */\."2) x +#~. (product\."3 ; times/\."3 ; */\."3) x +#~. (product\."0 ; times/\."0 ; */\."0) x=:x+0=x=:5e3-?7 5 11$1e4 +#~. (product\."1 ; times/\."1 ; */\."1) x +#~. (product\."2 ; times/\."2 ; */\."2) x +1 = #~. (product\."3 ; times/\."3 ; */\."3) x + +max =: 4 : 'x>.y' +maxover =: 3 : '>./y' +#~. (maxover\."0 ; max/\."0 ; >./\."0) x=:5e5-?7 5 11$1e6 +#~. (maxover\."1 ; max/\."1 ; >./\."1) x +#~. (maxover\."2 ; max/\."2 ; >./\."2) x +#~. (maxover\."3 ; max/\."3 ; >./\."3) x +#~. (maxover\."0 ; max/\."0 ; >./\."0) x=:o.5e5-?7 5 11$1e6 +#~. (maxover\."1 ; max/\."1 ; >./\."1) x +#~. (maxover\."2 ; max/\."2 ; >./\."2) x +#~. (maxover\."3 ; max/\."3 ; >./\."3) x +#~. (maxover\."0 ; max/\."0 ; >./\."0) x=:?7 5 11$2 +#~. (maxover\."1 ; max/\."1 ; >./\."1) x +#~. (maxover\."2 ; max/\."2 ; >./\."2) x +#~. (maxover\."3 ; max/\."3 ; >./\."3) x + +xor =: 4 : 'x~:y' +xover =: 3 : '~:/y' +#~. (xover\."0 ; xor/\."0 ; ~:/\."0) x=:?7 5 11$2 +#~. (xover\."1 ; xor/\."1 ; ~:/\."1) x +#~. (xover\."2 ; xor/\."2 ; ~:/\."2) x +#~. (xover\."3 ; xor/\."3 ; ~:/\."3) x + +(-: +/\."1) i. 0 (0)}?1$10 +(-: +/\."1) i. 0 (0)}?2$10 +(-: +/\."1) i. 0 (0)}?3$10 +(-: +/\."1) i. 0 (0)}?4$10 +(-: +/\."1) i. 0 (0)}?5$10 + +(-: +/\."2) i. 0 (1)}?2$10 +(-: +/\."2) i. 0 (1)}?3$10 +(-: +/\."2) i. 0 (1)}?4$10 +(-: +/\."2) i. 0 (1)}?5$10 + +(-: +/\."2) i. 0 (2)}?3$10 +(-: +/\."2) i. 0 (2)}?4$10 +(-: +/\."2) i. 0 (2)}?5$10 + + +4!:55 ;:'a base bs bsd em en f iind infix ' +4!:55 ;:'kay key max maxover n ob oind omask osub outfix ' +4!:55 ;:'plus prefix product sd seg suffix sum t times x xor xover ' + +
new file mode 100644 --- /dev/null +++ b/test/g431a.ijs @@ -0,0 +1,111 @@ +NB. f/. f\ f\. models -------------------------------------------------- +en =: #@] +em =: (en >.@% 1&>.@|@[)`(en 0&>.@>:@- [) @. (0&<:@[) +kay =: en`em @. (0&<@[) +omask =: (em,en) $ ($&0@|@[ , $&1@kay) + +base =: 1&>.@-@[ * i.@em +iind =: base ,. |@[ <. en - base +seg =: ((+i.)/@[ { ])"1 _ + +infix =: 1 : '(iind x@seg ])"0 _' +outfix =: 1 : '(omask x@# ])"0 _' +prefix =: 1 : '>:@,.@i.@# x@{. ]' +suffix =: 1 : ',.@i.@# x@}. ]' + +key =: 1 : '=@[ x@# ]' + +osub =: >@]`(>@[ >@:{ ]) @. (*@#@]) +oind =: (+/&i./ </.&, i.)@(2&{.)@(,&1 1)@$ +ob =: 1 : 'oind x@osub"0 1 ,@(<"_2)' + +bs =: 1 : '(x prefix) : (x infix )' +bsd =: 1 : '(x suffix) : (x outfix)' +sd =: 1 : '(x ob ) : (x key )' + + +NB. x f\. y ------------------------------------------------------------- + +NB. Boolean +a=:1=?11 5$2 +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 +k (+./\. -: +./ bsd) a [ k=:_4+?11 + +NB. literal +a=:a.{~32+?11 5$95 +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 + +NB. integer +a=:?11 5$110 +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 +k (+/\. -: +/ bsd) a [ k=:_4+?11 + +NB. floating point +a=: 256 %~ _4e5+ 11 5 ?@$ 1e6 +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 +k (+/\. -: +/ bsd) a [ k=:_4+?11 + +NB. complex +a=:j./ 256 %~ _4e5+ 2 11 5 ?@$ 1e6 +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 +k (+/\. -: +/ bsd) a [ k=:_4+?11 + +NB. boxed +t=:(1=?70$3)<;.1 ?70$110 +a=:t{~?11 3$#t +k (<\. -: < bsd) a [ k=:_4+?11 +k (<\. -: < bsd) ,a [ k=:_4+?11 +k (]\. -: ] bsd) a [ k=:_4+?11 + + +NB. x f/\. y ------------------------------------------------------------ + +testa=: 1 : 0 + f=: u/ + assert. (i:1+#a) (u/\. -: f\.)"0 _ a=: y {~ 11 ?@$ #y + assert. (i:1+#a) (u/\. -: f\.)"0 _ a=: y {~ 11 3 ?@$ #y + assert. (i:1+#a) (u/\. -: f\.)"0 _ a=: y {~ 12 ?@$ #y + assert. (i:1+#a) (u/\. -: f\.)"0 _ a=: y {~ 12 3 ?@$ #y + if. y -: 0 1 do. + assert. (i:8) (u/\. -: f\.)"0 1"0 _ a=: #: i.2^7 + assert. (i:9) (u/\. -: f\.)"0 1"0 _ a=: #: i.2^8 + end. + 1 +) + +t=: 0 1; (100 ?@$ 1e9) ; (128 %~ 100 ?@$ 1e4); (100 ?@$ 1000x) ; (%/0 1x + 2 100 ?@$ 1000) +<. testa&> t +>. testa&> t ++ testa&> t , < j./ 2 100 ?@$ 1000 +* testa&> t , < j./ 2 100 ?@$ 1000 ++. testa&> 0 1; 100 ?@$ 1000 +*. testa&> 0 1; 100 ?@$ 1000 += testa&> 0 1; 100 ?@$ 1000 +~: testa&> 0 1; 100 ?@$ 1000 + +testb=: 3 : 0 + f=: y b./ + assert. (i:<:#a) (y b./\. -: f\.)"0 _ a=: _1e9+11 ?@$ 2e9 + assert. (i:<:#a) (y b./\. -: f\.)"0 _ a=: _1e9+11 3 ?@$ 2e9 + assert. (i:<:#a) (y b./\. -: f\.)"0 _ a=: _1e9+12 ?@$ 2e9 + assert. (i:<:#a) (y b./\. -: f\.)"0 _ a=: _1e9+12 3 ?@$ 2e9 + 1 +) + +testb"0 ] 22 25 +testb"0 ] 16 17 19 21 23 31 + + +4!:55 ;:'a base bs bsd em en f iind infix k kay key ob oind omask osub outfix' +4!:55 ;:'prefix sd seg suffix t testb' +
new file mode 100644 --- /dev/null +++ b/test/g432.ijs @@ -0,0 +1,330 @@ +NB. \:y ----------------------------------------------------------------- + +NB. Boolean +a =: 1=?10 5$2 +i =: \:a +k =: ?10$5 +i =&# a +(\:~i) -: i.-#a +(\:k#a) -: ;i{(i.&.>k)+&.>+/\}:0,k +(,0) -: \:0 +'' -: \:(0,?(?5)$10)$0 +(i.#a) -: \:a =: ((?10),0)$0 +(\:a) -: \:,.~a=:?400$2 +(\:a) -: \:,.~a=:? 1$2 +((+/a=/1 0)#1 0) -: \:~a=:?1000$2 + +f=: 3 : 0 " 0 + a=: (1000,y) ?@$ 2 + k=: (#a) ?@$ 5 + i=: \:a + assert. i -: \:a{'01' + assert. i -: \: #.a + assert. (\:k#a) -: ; i { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >: i.16 + +NB. literal +a =: a.{~32+?10 5$95 +i =: \:a +k =: ?10$5 +i =&# a +(\:~i) -: i.-#a +(\:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: \:'g' +'' -: \:(0,?(?5)$10)$0 +(i.#a) -: \:a =: ((?10),0)$0 +(\:a) -: \:,.~ a=:a.{~?400$256 +(\:a) -: \:,.~ a=:a.{~? 1$256 +((+/x=/|.a.)#|.a.) -: \:~x=:a.{~?1000$#a. + +f=: 3 : 0 " 0 + a=: a.{~(1000,y) ?@$ #a. + k=: (#a) ?@$ 5 + assert. (\:k#a) -: ; (\:a) { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >:i.16 + +NB. integer +a =: ?10 5$100 +i =: \:a +k =: ?10$5 +i=&#a +(\:~i) -: i.-#a +(\:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: \:5 +'' -: \:(0,?(?5)$10)$5 +(i.#a) -: \:a =: ((?10),0)$5 +*./a>:}:0,~a=:\:~?1000$1e2 +*./a>:}:0,~a=:\:~?1000$1e3 +*./a>:}:0,~a=:\:~?1000$1e4 +*./a>:}:0,~a=:\:~?1000$1e9 +(\: 100#.a) -: \: a=: ?1000 2$100 +(\: 100#.a) -: \: a=: ?1000 2$ 5 + +a=: (--:m) + 1000 ?@$ m=:IF64{2e9 9e18 +y=: (\:a) { a +*./ (}:y) >: }.y + +m=:<._1+2^31 +0 1 -: \: m,0 +1 0 -: \: 0,m +m=:<.-2^31 +1 0 -: \: m,0 +0 1 -: \: 0,m + +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.1 +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.2 +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.3 +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.4 +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.5 +((i.!#a) A. i.#a) (\:@[ -: \:@:{)"1 2 a=: 88#"0 i.6 + +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?1 8$5e6 +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?2 8$5e6 +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?3 8$5e6 +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?4 8$5e6 +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?5 8$5e6 +((i.!#a) A. i.#a) (] -: \:~@:{)"1 2 a=: \:~ (88$8),"1?6 8$5e6 + +f=: 3 : 0 " 0 + a=: (100,y) ?@$ 200 + k=: (#a) ?@$ 5 + assert. (\:k#a) -: ; (\:a) { (i.&.>k)+&.>+/\}:0,k + 1 +) + +f >: i.16 + +(\:v) -: \: a.{~ v=: ?10000$#a. +(\:v) -: \: a.{~ v=: ?66000$#a. + +(\:v) -: \: a.{~ 2000 + v=: _2000 + ?10000$#a. +(\:v) -: \: a.{~ 2000 + v=: _2000 + ?66000$#a. + +(\:v) -: \: a.{~ 128 + v=: _128 + ?10000$#a. +(\:v) -: \: a.{~ 128 + v=: _128 + ?66000$#a. + +(\:"1 v) -: \:"1 a.{~ v=: ?2 3 10000$#a. +(\:"1 v) -: \:"1 a.{~ v=: ?2 3 66000$#a. + +(\:"1 v) -: \:"1 a.{~ 2000 + v=: _2000 + ?2 3 10000$#a. +(\:"1 v) -: \:"1 a.{~ 2000 + v=: _2000 + ?2 3 66000$#a. + +(\:"1 v) -: \:"1 a.{~ 128 + v=: _128 + ?2 3 10000$#a. +(\:"1 v) -: \:"1 a.{~ 128 + v=: _128 + ?2 3 66000$#a. + +(\:v) -: \: o. v=: (?~20000){(?10000$65536),32768*?10000$65536 +(\:v) -: \: (-#v){.0 (3!:3) v + +NB. floating point +a =: o._40+?10 5$100 +i =: \:a +k =: ?10$5 +i =&# a +(\:~i) -: i.-#a +(\:k#a) -: ;i{(i.&.>k)+&.>+/\_1}.0,k +(,0) -: \:2.718 +'' -: \:(0,?(?5)$10)$3.14 +(i.#x) -: \:x=: ((?10),0)$3.14 +*./x>:}:0,~x=:\:~o.?1000$1e2 + +v=:?100$25 +(\:v) -: \:v-25 +(\:v) -: \:v+100 +(\:v) -: \:o.v +(\:v) -: \:,.~v + +(\:v) -: \: 0.01*v=: ?10000$50000 +(\:v) -: \: 0.01*v=: ?66000$50000 + +(\:v) -: \: 0.01*v=: - 1+ ?10000$50000 +(\:v) -: \: 0.01*v=: - 1+ ?66000$50000 + +(\:v) -: \: 0.01*v=: _25000+?10000$50000 +(\:v) -: \: 0.01*v=: _25000+?66000$50000 + +(\:"1 v) -: \:"1 o. v=: ?2 3 10000$50000 +(\:"1 v) -: \:"1 o. v=: ?2 3 66000$50000 + +(\:"1 v) -: \:"1 o. v=: - 1+ ?2 3 10000$50000 +(\:"1 v) -: \:"1 o. v=: - 1+ ?2 3 66000$50000 + +(\:"1 v) -: \:"1 o. v=: _25000+?2 3 10000$50000 +(\:"1 v) -: \:"1 o. v=: _25000+?2 3 66000$50000 + +NB. complex +a =: r._40+?10 5$100 +i =: \:a +k =: ?10$5 +i =&# a +i -: \: +.a +(\:~i) -: i.-#a +(\:k#a) -: ; i { (i.&.>k) +&.> +/\ }:0,k +(,0) -: \: 3j4 +'' -: \: (0,?(?5)$10)$3j4 +(i.#x) -: \: x=: ((?10),0)$3j4 +(i.12) -: \: r.12 5$100 + +NB. boxed +(\:a) -: \: <"0 a=: ?20 7$1000 +(\:a) -: \: <"1 a +(\:a) -: \: <&.> a +(\:a) -: \: <&.> a +(\:a) -: \: > a=: _50+&.>(?10$20)$&.>100 +(\:a) -: \: > a=:o.&.>_50+&.>(?10$20)$&.>100 +(\:a) -: \: > a=:r.&.>_50+&.>(?10$20)$&.>100 +(\:a) -: \: > a=:(<"0 ?5$2),(<"0 ?5$100),(<"0 o.?5$100),<"0 r.?5$100 +(\:a) -: \: > a=:(?~#a){a +(\:a) -: \: i.&.>a=:?~30 + +f=: 3 : 0 + assert. (\: a) -: \: <"0 a=.?(100,y)$3 + assert. (\:"1 a) -: \:"1 <"0 a + assert. (\:"2 a) -: \:"2 <"0 a + assert. (\: a) -: \: <"1 a + assert. (\:"2 a) -: \:"1 <"1 a + assert. (\:"3 a) -: \:"2 <"1 a + 1 +) + +*./@f"0 >: i.3 10 +*./@f"1 >: 5 6#:i.3 10 +*./@f"1 >:5 3 2#:i.3 10 + +g=: 3 : '0 1 -: \: ,:~ t=. y$t,<t=.1 2 3;''abc'' ' +g"0 i.3 10 + +(\:"1 a) -: \:"1 <"0 a=:? 20 17$1000 +(\:"2 a) -: \:"2 <"0 a=:?4 20 17$1000 + +ge=: 0: = {.@\: +x=: o.&.>_50+&.>(?10$20)$&.>100 +y=: ;:'Cogito, ergo sum. Sui generis. Sine qua non.' +z=: <"0 >5!:1 <'ge' +2 ge\ \:~a=: (?~#x,y,z) { x,y,z + +2 1 0 -: \: x=:3j4; 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +2 1 0 -: \: x=:(i.0); 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +2 1 0 -: \: x=:''; 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +2 1 0 -: \: x=:(o.i.0); 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +2 1 0 -: \: x=:(j.i.0); 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +2 1 0 -: \: x=:(0$a:); 'Ex ungue leonem'; <<5 6 7 +0 1 2 -: \: |. x +0 1 2 -: \: x=:'' ; (i.0) ; <0$a: +0 1 2 -: \: |. x + +a=: < 2 3 $ 1 2 3 4 5 6 +b=: < 3 2 $ 1 2 5 6 3 4 +c=: < 1 3 $ 1 2 3 +d=: < 1 2 $ 1 2 +e=: < 2 2 $ 1 2 5 6 + +(i.5) -: /: d,e,b,c,a +(\:"1 p) -: \:"1 (d,e,b,c,a){~p=: (i.!5) A. i.5 + +NB. extended integer +(\: -: \: @:x:) a=: _500+?100 $1000 +(\: -: \:@:(<"0)@:x:) a +(\: -: \: @:x:) a=: _500+?100 4$1000 +(\: -: \:@:(<"1)@:x:) a + +NB. rationals +(\: -: \: @:x:) a=: -:_500+?100 $1000 +(\: -: \:@:(<"0)@:x:) a +(\: -: \: @:x:) a=: -:_500+?100 4$1000 +(\: -: \:@:(<"1)@:x:) a + +'index error' -: 3 4 5 \: etx 1 2 3 4 + + +NB. \:y on integer lists ------------------------------------------------ + +v=:?100$25 +(\:v) -: \:v-25 +(\:v) -: \:v+100 +(\:v) -: \:o.v +(\:v) -: \:,.~v + +0 5 4 3 2 1 -: \: v=: 2e9 _2e9 1 2 3 4 + 2e9 4 3 2 1 _2e9 -: \:~v + +x=: <._1+2^31 +y=: _1-x +v=:x,y,1 2 3 4 +(\:v) -: 0 5 4 3 2 1 +(\:~v) -: x,4 3 2 1,y + + +NB. \:"r ---------------------------------------------------------------- + +g =: 3 : ('\:y'; ':'; 'x\:y') + +(\:"0 -: g"0) y=:?2 3 4 17$2 +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y + +(\:"0 -: g"0) y=:a.{~?2 3 4 17$#a. +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y +(\:"0 -: g"0) y=:a.{~?2 3 4 18$#a. +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y + +(\:"0 -: g"0) y=:?2 3 4 17$34 +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y +(\:"0 -: g"0) y=:?2 3 4 17$+:*/2 3 4 17 +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y +(\:"0 -: g"0) y=:_50+?2 3 4 17$100 +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y + +(\:"0 -: g"0) y=:o.?2 3 4 17$34 +(\:"1 -: g"1) y +(\:"2 -: g"2) y +(\:"3 -: g"3) y +(\:"4 -: g"4) y + +x=:?20 3$100 +x (\:"2 2 -: g"2 2) y=:?2 20 3$100 +x (\:"2 3 -: g"2 3) y=:?20 2 3$100 +x (\:"1 1 -: g"1 1) y=:o.?3$100 +x (\:"1 0 -: g"1 0) y=:?1000 +x (\:"1 0 -: g"1 0) y=:a.{~?20$256 + +(\:~"1 -: g~"1) y=:?4 17$2 +(\:~"1 -: g~"1) y=:a.{~32+?17 4$95 +(\:~"1 -: g~"1) y=:?2 7 16$100 +(\:~"1 -: g~"1) y=:o.?4 17$1232 + +(2 3 4 1$0) -: \:"0 i.2 3 4 +(0 0 0 1$0) -: \:"0 i.0 0 0 + +'index error' -: (i.4) \: etx i.5 + +4!:55 ;:'a b c d e f g ge i k le m p v x y z' + +
new file mode 100644 --- /dev/null +++ b/test/g4x.ijs @@ -0,0 +1,309 @@ +NB. 4!:0 ---------------------------------------------------------------- + +jnc =: 4!:0 +jnl =: 4!:1 +erase =: 4!:55 + +nounx =: ?3 4$1000 +verbx =: +/ % # +advx =: 1 : 'x^:_1' +conjx =: ^: + +1 [ erase ;:'x y' + +0 -: jnc <'nounx' +1 -: jnc <'advx' +2 -: jnc <'conjx' +3 -: jnc <'verbx' +_1 -: jnc <'nonexistent' +_2 -: jnc <'@#$!invalid' +0 1 2 3 _1 _2 -: jnc <;._1 ' nounx advx conjx verbx nonexistent @#$!invalid' + +a =:'abc' +plus =: 3+4 +f =: 3 : ('a=.9'; 'plus=.+'; 'jnc ''a'';''plus''') +0 0 -: jnc 'a';'plus' +0 3 -: f 0 +0 3 0 -: jnc 'a';'f';'a' +3 3 -: jnc 'jnl';'jnc' + +nm =: ;:'x y' +_1 0 -: (3 : 'jnc nm' ) 8 +0 0 -: 7 (3 : (':';'jnc nm')) 8 +3 _1 -: + (1 : 'jnc nm') +0 _1 -: 'a' (1 : 'jnc nm') +3 3 -: + (2 : 'jnc nm') - +3 0 -: + (2 : 'jnc nm') 'b' +0 3 -: 'b' (2 : 'jnc nm') - +0 0 -: 'a' (2 : 'jnc nm') 'b' + +_2 _2 _2 -: jnc <;._1 ' 9 +-1aber *' +_1 -: jnc <'asflkjasasdf' +_2 -: jnc <'+*abc' +_2 -: jnc <'abc\def' + + +nounx =: 2 +verbx =: +/ . * +advx =: / +conjx =: . +0 3 1 2 -: jnc 'nounx';'verbx';'advx';'conjx' +erase 'verbx';'conjx' +0 _1 1 _1 -: jnc 'nounx';'verbx';'advx';'conjx' + +a=./ +b=.0 +c=.& +v=.+/ +erase <'z' + + +NB. 4!:1 ---------------------------------------------------------------- + +jnc =: 4!:0 +jnl =: 4!:1 +erase =: 4!:55 + +nounx =: 2 +verbx =: +/ . * +advx =: / +conjx =: . +(<'nounx') e. jnl 0 +(<'verbx') e. jnl 3 +(<'advx' ) e. jnl 1 +(<'conjx') e. jnl 2 +(jnl 0) -: jnl (>:?20)$0 +(jnl 1) -: jnl (>:?20)$1 +(jnl 2) -: jnl (>:?20)$2 +(jnl 3) -: jnl (>:?20)$3 +(jnl i.4) -: jnl 3 2 1 0,?10$4 +(;:'nounx verbx advx conjx') e. jnl i.4 +(;:'nounx verbx advx conjx') e. a. jnl i.4 +(;:'nounx verbx') e. 'nv' jnl i.4 +(;:'advx conjx' ) -.@e. 'nv' jnl i.4 +erase 'verbx';'conjx' +(;:'verbx conjx') -.@e. jnl i.4 +(;:'nounx advx' ) e. jnl i.4 + +(<,'y' ) e. (3 : 'jnl 0') 9 +(;:'x y') e. 8 (3 : (':';'jnl 0')) 9 + +(<,'x' ) e. + (1 : 'jnl 3') +(<,'x' ) e. 'a' (1 : 'jnl 0') +(;:'x y') e. + (2 : 'jnl 3') - +(<,'x' ) e. 'a' (2 : 'jnl 0') - +(<,'y' ) e. + (2 : 'jnl 0') 'b' + +t =. jnl i.4 +1 = #$t +32 -: type <'t' +*./ 2 = type&>t +*./ 1 = #&$&>t +t -: t/:>t +*./ (jnc t) e. i.4 + + +NB. 4!:55 --------------------------------------------------------------- + +jnc =: 4!:0 +jnl =: 4!:1 +erase =: 4!:55 + +nounx =: 2 +verbx =: +/ . * +advx =: / +conjx =: . +nm =: ;:'nounx verbx advx conjx' +f =: 3 : ('".y'; 'b=.jnc nm'; 'erase nm'; 'a=.jnc nm'; 'b,a') + 0 3 1 2 -: jnc nm + 3 3 3 3 0 3 1 2 -: f '(nounx=.verbx=.advx=.conjx=.*) 12' + 0 3 1 2 -: jnc nm + 0 0 3 2 0 3 1 _1 -: f '(advx=.*) nounx=.verbx=.12' + 0 3 1 _1 -: jnc nm + 0 0 1 _1 0 3 _1 _1 -: f 'nounx=.verbx=.12' + 0 3 _1 _1 -: jnc nm + 2 3 _1 _1 0 _1 _1 _1 -: f '3(nounx=. &)+ 4' + 0 _1 _1 _1 -: jnc nm + 0 _1 _1 _1 _1 _1 _1 _1 -: f '12' +_1 _1 _1 _1 -: jnc nm + +erase ;:'x y' +g =: 3 : (t,':'; t =. 'yy=.y'; 'b=.jnc yy'; 'erase yy'; 'a=.jnc yy'; 'b,a') + 0 _1 -: g <'y' +_1 _1 -: g <'x' + 0 _1 -: 2 g <'y' + 0 _1 -: 2 g <'x' + +nounx =: 2 +verbx =: +/ . * +advx =: / +conjx =: . + 0 3 1 2 _1 -: jnc ;:'nounx verbx advx conjx undef' + 1 1 1 1 1 -: t=.erase ;:'nounx verbx advx conjx undef' +_1 _1 _1 _1 _1 -: jnc ;:'nounx verbx advx conjx undef' + +0 -: erase <'*&^invalid@' + +a =. 9 +1 1 0 0 0 -: t=.erase 'a'; 'undefined'; 'in+valid'; '8.'; 'a.' + +alpha =. i.3 4 +beta =. ;:'Cogito, ergo sum.' +gamma =. ! + +1 1 1 1 0 0 -: t=.erase ;:'alpha beta boo hoo + +:' + + +NB. 4!: ----------------------------------------------------------------- + +jnc =: 4!:0 +jnl =: 4!:1 +scind =: 4!:4 +erase =: 4!:55 + +_2 -: jnc <'' +0 -: erase <'' + +'domain error' -: jnc etx 1 +'domain error' -: jnc etx 1 2 +'domain error' -: jnc etx 3 3.5 +'domain error' -: jnc etx 'abcvz*' +'domain error' -: jnc etx 3j4 +'domain error' -: jnc etx 'a';1 +'domain error' -: jnc etx 'a';1 2 +'domain error' -: jnc etx 'a';3 3.5 +'domain error' -: jnc etx 'a';3j4 +'domain error' -: jnc etx <<'ab' +'domain error' -: jnc etx i.3 4 +'domain error' -: 'abc' jnc etx 3 + +'rank error' -: jnc etx <3 4$'a' + +'domain error' -: jnl etx 'abc' +'domain error' -: jnl etx 2 3j4 +'domain error' -: jnl etx 1 1.5 +'domain error' -: jnl etx <1 2 +'domain error' -: jnl etx 0 1 2 _1 3 +'domain error' -: jnl etx _2 _1 +'domain error' -: jnl etx 6 99999 0 + +'domain error' -: 2 3 jnl etx 3 +'domain error' -: 2.5 jnl etx 3 +'domain error' -: 3j54 jnl etx 3 +'domain error' -: (<'abc') jnl etx 3 + +'domain error' -: erase etx 1 +'domain error' -: erase etx 1 2 +'domain error' -: erase etx 3 3.5 +'domain error' -: erase etx 'abc' +'domain error' -: erase etx 3j4 +'domain error' -: erase etx 'a';1 +'domain error' -: erase etx 'a';1 2 +'domain error' -: erase etx 'a';3 3.5 +'domain error' -: erase etx 'a';3j4 +'domain error' -: erase etx <<'ab' + +'rank error' -: erase etx <3 4$'a' + +'domain error' -: scind etx 1 2 3 +'domain error' -: scind etx 'abc123' +'domain error' -: scind etx 1 2 3;'abc' +'domain error' -: scind etx <<'abc' + +'ill-formed name' -: scind etx <'+*abc' +'ill-formed name' -: scind etx <'abc\def' +'ill-formed name' -: scind etx <'' + +'rank error' -: scind etx <3 4$'xab' +'rank error' -: scind etx <,:'xab' + + +NB. locales ------------------------------------------------------------- + +jnc =: 4!:0 +jnl =: 4!:1 +erase =: 4!:55 + +x =: ?13$100000 +y =: 'supercalifragilisticespialidocious' +abcd =: x +abcd_locale_ =: y +abcd -: x +abcd_locale_ -: y +0 0 -: jnc ;:'abcd abcd_locale_' +(<'locale') e. jnl 6 +(<'locale') e. 'l' jnl 6 +-. (<'locale') e. 'abc' jnl 6 +1=+/(jnl 0) e. <'abcd' +erase <'abcd_locale_' +abcd -: x +0 _1 -: jnc ;:'abcd abcd_locale_' + +x =: 'sui generis' +ab_cd =. x +ab_cd_asdf_ =. +/ % # +ab_cd -: x +9.5 -: ab_cd_asdf_ i.20 +0 3 -: jnc ;:'ab_cd ab_cd_asdf_' +(<'asdf') e. jnl 6 +(<'asdf') e. 'abc' jnl 6 +-. (<'asdf') e. 'xyz' jnl 6 +1=+/(jnl 0) e. <'ab_cd' +erase <'ab_cd_asdf_' +ab_cd -: x +0 _1 -: jnc ;:'ab_cd ab_cd_asdf_' +1=+/(jnl 0 3) e. <'ab_cd' + +exec_foo_ =: ". +1 [ exec_foo_ 'xy =: i.3 4' +xy_foo_ -: i.3 4 +1 [ exec_foo_ 'ces__ =: ;:''Cogito, ergo sum.''' +ces -: ;:'Cogito, ergo sum.' +erase ;:'exec_foo_ xy_foo_ ces__' + +'ill-formed name' -: ex 'a_ =: 12' +'ill-formed name' -: ex 'abcd_ =: 12' + +'domain error' -: ex '_ =: 12' +'domain error' -: ex '__ =: 12' + +NB. 'nonce error' -: 3 : 'abc_d_ =. 17' etx 17 + +18!:55 ;:'asdf foo locale' + + +NB. z locale ------------------------------------------------------------ + +erase ;:'abc abc_z_ sum sum_z_' +x=: o.?3 4$1000 +abc__ =: x +abc__ -: x +abc -: x +y =: j./?2 5 4$1000 +abc_z_ =: y +abc_z_ -: y +abc_nonexist_ -: y +abc__ -: x +abc -: x +sum_z_ =: +/ +(+/y) -: sum y +(+/y) -: sum__ y +(+/y) -: sum_z_ y +(+/y) -: sum_nonexist_ y +ces_exist_ =: ;:'Cogito, ergo sum.' +3 3 3 3 -: jnc ;:'sum sum_exist_ sum_nonexist_ sum_z_' +-. (<'sum') e. jnl 3 +jnc_z_ =: jnc f. +jnl_z_ =: jnl f. +3 -: jnc_z_ <'sum' +(<'sum') e. jnl_z_ 3 +erase ;:'abc abc_z_ ces_exist_ sum_z_' + +18!:55 ;:'exist nonexist' + +4!:55 ;:'a ab_cd abc abc__ abc_z_ abcd ' +4!:55 ;:'advx alpha b beta c ces conjx erase f' +4!:55 ;:'g gamma jnc jnc_z_ jnl jnl_z_ nm nounx plus scind sum ' +4!:55 ;:'sum__ sum_z_ t v verbx x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g4x5.ijs @@ -0,0 +1,63 @@ +NB. 4!:5 ---------------------------------------------------------------- + +nch =: 4!:5 +nch_bar_=: 4!:5 +erase =: 4!:55 + +1 [ nch 1 +abc=: 1 2 3 +foo_bar_=:3 4 5 +foo=:'in base locale' +boo__=:12 +(t=:nch 1) -: ;:'abc_base_ boo_base_ foo_bar_ foo_base_' + +abc=: 1 2 3 +foo_bar_=:3 4 5 +foo=:'in base locale' +boo__=:12 +(t=:nch_bar_ 1) -: ;:'abc_base_ boo_base_ foo_bar_ foo_base_ t_base_' + +abc=: 1 2 3 +abc=: 'xyz' +(t=:nch 1) -: ;:'abc_base_ t_base_' + +1 [ ".('a',.>":&.>i.30),"1 '=:123' +erase 'a',&.>":&.>i.5 +(t=:nch 1) -: /:~ ,&'_base_'&.> (<,'t'),'a',&.>":&.>5+i.25 +erase 'a',&.>":&.>5+i.25 + +nch 0 +abc=: 1 2 3 +nch 1 +foo_bar_=:3 4 5 +boo__=:12 +(t=:nch 1) -: ;:'boo_base_ foo_bar_' + +f=: 3 : 0 + abc=: 6 49 + i=.1+y + foo_bar_=: 'hope to do good' + boo=.19 + 1 +) + +f 12 +f 15 +(t=:nch 1) -: ;:'abc_base_ f_base_ foo_bar_ t_base_' + +'domain error' -: nch etx 34 +'domain error' -: nch etx 3.4 +'domain error' -: nch etx 3j4 +'domain error' -: nch etx 'a' +'domain error' -: nch etx <1 + +'rank error' -: nch etx 1 0 1 +'rank error' -: nch etx '' + +nch 0 + +18!:55 ;:'bar' + +4!:55 ;:'abc boo erase f foo nch t' + +
new file mode 100644 --- /dev/null +++ b/test/g500.ijs @@ -0,0 +1,47 @@ +NB. [ -------------------------------------------------------------------- + +xb =: ?2 3 4$2 +xa =: 'Fourscore and seven years ago' +xi =: ?9 12$100000 +xd =: o.?1 2 3$100000 +xj =: j.&?~2 2 3 3$1000 + +xb -: xb [ xb +xb -: xb [ xa +xb -: xb [ xi +xb -: xb [ xd +xb -: xb [ xj + +xa -: xa [ xb +xa -: xa [ xa +xa -: xa [ xi +xa -: xa [ xd +xa -: xa [ xj + +xi -: xi [ xb +xi -: xi [ xa +xi -: xi [ xi +xi -: xi [ xd +xi -: xi [ xj + +xd -: xd [ xb +xd -: xd [ xa +xd -: xd [ xi +xd -: xd [ xd +xd -: xd [ xj + +xj -: xj [ xb +xj -: xj [ xa +xj -: xj [ xi +xj -: xj [ xd +xj -: xj [ xj + +x=: i.1e4 +y=: 2e4$'boustrophedonic chuffed' + +(IF64{1000 2400) > 7!:2 'x[y' + + +4!:55 ;:'x xa xb xd xi xj y' + +
new file mode 100644 --- /dev/null +++ b/test/g502.ijs @@ -0,0 +1,35 @@ +NB. [: ------------------------------------------------------------------ + +ss =: [: +/ *: +(+/*:x) -: ss x=: _40+?20$1000 +(+/*:x) -: ss x=:o._40+?20$1000 +(+/x*:y) -: x ss y [ x=:?20$2 [ y=:?20$2 + +cc=: [: +f =: cc +/ *: +(+/*:x) -: f x=:_40+?20$1000 +cc=: c1 +c1=: c2 +c2=: [: +(+/*:x) -: f x=:_40+?20$1000 +cc =. %: +((%:x)+/*:x) -: f x + +'domain error' -: [: etx 1 0 1 +'domain error' -: [: etx 3 4$'chthonic' +'domain error' -: [: etx ?2 3 4$100000 +'domain error' -: [: etx o.?2 4$100000 +'domain error' -: [: etx r.o.?2 4$100000 +'domain error' -: [: etx ;:'Cogito, ergo sum.' + +'domain error' -: (<'boo hoo') [: etx 1 0 1 +'domain error' -: (?7$10000) [: etx 'triskaidekaphobia' +'domain error' -: (a.{~?95$256) [: etx ?2 3 4$100000 +'domain error' -: (?17$2) [: etx o.?2 4$100000 +'domain error' -: 'eleemosynary' [: etx r.o.?2 4$100000 +'domain error' -: '' [: etx ;:'Cogito, ergo sum.' + + +4!:55 ;:'c1 c2 cc f ss t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g510.ijs @@ -0,0 +1,66 @@ +NB. ] -------------------------------------------------------------------- + +xb =: ?2 3 4$2 +xa =: 'Fourscore and seven years ago' +xi =: ?9 12$100000 +xd =: o.?1 2 3$100000 +xj =: j.&?~2 2 3 3$1000 + +xb -: xb ] xb +xb -: xa ] xb +xb -: xi ] xb +xb -: xd ] xb +xb -: xj ] xb + +xa -: xb ] xa +xa -: xa ] xa +xa -: xi ] xa +xa -: xd ] xa +xa -: xj ] xa + +xi -: xb ] xi +xi -: xa ] xi +xi -: xi ] xi +xi -: xd ] xi +xi -: xj ] xi + +xd -: xb ] xd +xd -: xa ] xd +xd -: xi ] xd +xd -: xd ] xd +xd -: xj ] xd + +xj -: xb ] xj +xj -: xa ] xj +xj -: xi ] xj +xj -: xd ] xj +xj -: xj ] xj + +x=: i.1e4 +y=: 2e4$'boustrophedonic chuffed' + +(IF64{2000 2400) > t=: 7!:2 'x]y' + + +NB. ]"r ------------------------------------------------------------------ + +dex =: 3 : ('y'; ':'; 'y') + +'abc' (]" 1 -: dex" 1) ?2 3 4$100 +4 5 (]"_1 -: dex"_1) ?2 3 4$100 + +f=: ] ^:(2&|) +g=: 0&+^:(2&|) + +(f/ -: g/ ) x=:?20$10 +(f/\ -: g/\ ) x=:?20$10 +(f/\. -: g/\.) x=:?20$10 +(f"0 -: g"0 ) x=:?20$10 +(f^:3 -: g^:3) x=:? 2$10 + +'length error' -: 'abc' ]"_1 etx i.2 3 + + +4!:55 ;:'dex f g t x xa xb xd xi xj y' + +
new file mode 100644 --- /dev/null +++ b/test/g520.ijs @@ -0,0 +1,591 @@ +NB. {y ------------------------------------------------------------------ + +NB. Boolean +a =: 1=?(1+?10)$2 +b =: 1=?(1+?10)$2 +({a;b) -: a,&.>/b + +NB. literal +a =: a.{~97+?(1+?10)$26 +b =: a.{~97+?(1+?10)$26 +({a;b) -: a,&.>/b + +NB. integer +a =: _40+?(1+?10)$100 +b =: _40+?(1+?10)$100 +({a;b) -: a,&.>/b +(i.v) -: v#."1>{i.&.>v =: >: ?7 7 7 7 +(i.v) -: v#."1>{i.&.>v =: >: ?7 7 7 7 +(i.v) -: v#."1>{i.&.>v =: >: ?7 7 7 7 + +NB. floating-point +a =: 0.1*_40+?(1+?10)$100 +b =: 0.1*_40+?(1+?10)$100 +({a;b) -: a,&.>/b + +NB. complex +a =: ^0j0.1*_40+?(1+?10)$100 +b =: ^0j0.1*_40+?(1+?10)$100 +({a;b) -: a,&.>/b +b =: _40+?(1+?10)$100 +({a;b) -: a,&.>/b + +NB. boxed +a =: (1,}.0=?(#a)$4)<;.(1) a=:_40+?(1+?20)$100 +b =: (1,}.0=?(#b)$4)<;.(1) b=:0.1*_40+?(1+?20)$100 +({(<a),<b) -: a<@,"0/b + +count =: */@$@> +prod =: */\.@}.@(,&1) +copy =: */@[ $&> prod@[ (#,)&.> ] +catalog =: ;@:($&.>) $ count <"1@|:@copy ] + +f =: { -: catalog + +f 0 1;1=?2 3$6 +f (3 4$'foobar');'lieben' +f (?5$105);?2 3$10 +f o.&.>(?5$105);2 3$10 +f 3j4;5j6 7 8 9 +f 0 1;2;3.4;5j6 7 + +'domain error' -: { etx 1 2 3; 'ab' +'domain error' -: { etx 1 2 3;~'ab' +'domain error' -: { etx 1 2 3; <<4 5 +'domain error' -: { etx 1 2 3;~<<4 5 +'domain error' -: { etx 'abc'; <<4 5 +'domain error' -: { etx 'abc';~<<4 5 + + +NB. x{y ----------------------------------------------------------------- + +a -: 0{a=:?2 +a -: 0{a=:(?#a.){a. +a -: 0{a=:?1e9 +a -: 0{a=:o.?1e9 +a -: 0{a=:r.?1e7 +a -: 0{a=:<?1e9 + +NB. Boolean +a=:1=?2 3 4$2 +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +NB. literal +a=:a.{~?2 3 4$256 +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +NB. integer +a=:?2 3 4$10000 +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +NB. floating point +a=:o.?2 3 4$10000 +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +NB. complex +a=:^0j1*?2 3 4$200 +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +NB. boxed +a=:2 3 4$;:'(($p),($q),4)-:$(<p;q){a' +(|.a) -: 1 0{a +(2{."1 a) -: 0 1{"1 a +(_2{."2 a) -: _2 _1{"2 a +(($0)$,_1 _1 _1{.a) -: (<_1 _1 _1){a + +p=:?(?(?4)$5)$2 +q=:?(?(?4)$5)$3 +r=:?(?(?4)$5)$4 +i=:p;q;r +(;$&.>i) -: $(<i){a +(($p),3 4) -: $(<<p){a +(($p),($q),4) -: $(<p;q){a + +(i.0 3 0 59) -: (i.0 3){i.(_1+2^31),0 59 +(i.0 ) -: (<_1+1e9 2e9){i.1e9 2e9 0 +(i.0 59) -: (<_1+1e9 2e9){i.1e9 2e9 0 59 + +(i.2 0 3 4 5 6) -: (i.2 0 3){0 4 5 6$'abc' +(i.2 0 3 4 5 6) -: (i.2 0 3){0 4 5 6$4 +(i.2 0 3 4 5 6) -: (i.2 0 3){0 4 5 6$0.5 + +(i.4 5 2 0 3 6) -: (i.2 0 3){"_ 2 [ 4 5 0 6$'abc' +(i.4 5 2 0 3 6) -: (i.2 0 3){"_ 2 [ 4 5 0 6$4 +(i.4 5 2 0 3 6) -: (i.2 0 3){"_ 2 [ 4 5 0 6$0.5 + +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 1$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 2$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 3$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 4$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 5$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 6$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 7$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 8$256 +j -: x i. j{x [ j=:?~#x=: ~.a.{~?100 9$256 + +NB. scalar right arguments + +x -: i{ x=: 0 [ i=: <i.0 +x -: i{ x=: 'a' +x -: i{ x=: 2 +x -: i{ x=: 2.5 +x -: i{ x=: 2j5 +x -: i{ x=: <2 3 4 +x -: i{ x=: 2x + +x -: i{ x=: 0 [ i=: <'' +x -: i{ x=: 'a' +x -: i{ x=: 2 +x -: i{ x=: 2.5 +x -: i{ x=: 2j5 +x -: i{ x=: <2 3 4 +x -: i{ x=: 2x + +x -: i{ x=: 0 [ i=: <0$<i.12 +x -: i{ x=: 'a' +x -: i{ x=: 2 +x -: i{ x=: 2.5 +x -: i{ x=: 2j5 +x -: i{ x=: <2 3 4 +x -: i{ x=: 2x + +'domain error' -: 3.5 { etx i.12 +'domain error' -: 'abc' { etx i.12 +'domain error' -: (<3.5) { etx i.12 +'domain error' -: (<0;'abc'){ etx i.3 4 +'domain error' -: (<0;3.5) { etx i.3 4 + +'length error' -: (<0 2) { etx i.12 +'length error' -: (<0;2) { etx i.12 + +'index error' -: 0 { etx 0 5$'abc' +'index error' -: 0 { etx i.0 5 +'index error' -: 0 { etx o.i.0 5 +'index error' -: 2 { etx a=:1=?2 3 4$2 +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + +'index error' -: 2 { etx a=:(?2 3 4$#a.){a. +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + +'index error' -: 2 { etx a=:?2 3 4$333 +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + +'index error' -: 2 { etx a=:o.?2 3 4$333 +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + +'index error' -: 2 { etx a=:^0j1*?2 3 4$33 +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + +'index error' -: 2 { etx a=:2 3 4$3;'abc' +'index error' -: _3 { etx a +'index error' -: (<0 _4 0) { etx a +'index error' -: (<2 0) { etx a + + +NB. x{y boxed indices --------------------------------------------------- + +fr =: 4 : '>{&.>/(<"0|.>x),<y' + +(<i=: <:s-?+:s) ({ -: fr) ?s$2 [ s=:2 3 4 7 +(<i=: <:s-?+:s) ({ -: fr) a.{~?s$#a. [ s=:2 3 4 7 11 +(<i=: <:s-?+:s) ({ -: fr) _1e6+?s$2e6 [ s=:2 5 1 7 1 1 +(<i=: <:s-?+:s) ({ -: fr) o._1e6+?s$2e6 [ s=:2 1 5 1 1 7 3 +(<i=: <:s-?+:s) ({ -: fr) r._1e6+?s$2e6 [ s=:1 2 5 1 1 1 1 7 +(<i=: <:s-?+:s) ({ -: fr) <"0?s$1e8 [ s=:2 3 4 7 1 1 + +(<i=: }:<:s-?+:s) ({ -: fr) ?s$2 [ s=:2 3 4 7 +(<i=: }:<:s-?+:s) ({ -: fr) a.{~?s$#a. [ s=:2 3 4 7 11 +(<i=: }:<:s-?+:s) ({ -: fr) _1e6+?s$2e6 [ s=:2 5 1 7 1 1 +(<i=: }:<:s-?+:s) ({ -: fr) o._1e6+?s$2e6 [ s=:2 1 5 1 1 7 3 +(<i=: }:<:s-?+:s) ({ -: fr) r._1e6+?s$2e6 [ s=:1 2 5 1 1 1 1 7 +(<i=: }:<:s-?+:s) ({ -: fr) <"0?s$1e8 [ s=:2 3 4 7 1 1 + +(<i=:<"0 <:s-?+:s) ({ -: fr) ?s$2 [ s=:2 3 4 7 +(<i=:<"0 <:s-?+:s) ({ -: fr) a.{~?s$#a. [ s=:2 3 4 7 11 +(<i=:<"0 <:s-?+:s) ({ -: fr) _1e6+?s$2e6 [ s=:2 5 1 7 1 1 +(<i=:<"0 <:s-?+:s) ({ -: fr) o._1e6+?s$2e6 [ s=:2 1 5 1 1 7 3 +(<i=:<"0 <:s-?+:s) ({ -: fr) r._1e6+?s$2e6 [ s=:1 2 5 1 1 1 1 7 +(<i=:<"0 <:s-?+:s) ({ -: fr) <"0?s$1e8 [ s=:2 3 4 7 1 1 + +(<i=:<"0 }:<:s-?+:s) ({ -: fr) ?s$2 [ s=:2 3 4 7 +(<i=:<"0 }:<:s-?+:s) ({ -: fr) a.{~?s$#a. [ s=:2 3 4 7 11 +(<i=:<"0 }:<:s-?+:s) ({ -: fr) _1e6+?s$2e6 [ s=:2 5 1 7 1 1 +(<i=:<"0 }:<:s-?+:s) ({ -: fr) o._1e6+?s$2e6 [ s=:2 1 5 1 1 7 3 +(<i=:<"0 }:<:s-?+:s) ({ -: fr) r._1e6+?s$2e6 [ s=:1 2 5 1 1 1 1 7 +(<i=:<"0 }:<:s-?+:s) ({ -: fr) <"0?s$1e8 [ s=:2 3 4 7 1 1 + +x -: (<i.&.>4{.$x){x=:?2 3 4 5$1e6 +x -: (<i.&.>3{.$x){x +x -: (<i.&.>2{.$x){x +x -: (<i.&.>1{.$x){x +x -: (<i.&.>0{.$x){x + +(|.|."_1 |."_2 |."_3 x) -: (<i.&.>-4{.$x){x=:?2 3 4 5$2 +(|.|."_1 |."_2 x) -: (<i.&.>-3{.$x){x +(|.|."_1 x) -: (<i.&.>-2{.$x){x +(|. x) -: (<i.&.>-1{.$x){x + +jot=:<$0 +x=:(?3 4 5 7$#a){a=:'supercalifragilisticexpialidocious !@#$' +((<i; j ){x) -: i{ j{"_ _1 x [ i=:?2 3$3 [ j=:?7 1 1$4 +((<i; j; <a: ){x) -: i{ j{"_ _1 x [ i=:?2 3$3 [ j=:?7 1 1$4 +((<i; j; a:;<a: ){x) -: i{ j{"_ _1 x [ i=:?2 3$3 [ j=:?7 1 1$4 +((<i; a:;j ){x) -: i{ j{"_ _2 x [ i=:?23 $3 [ j=:?1 17 $5 +((<i; a:;j; <a: ){x) -: i{ j{"_ _2 x [ i=:?23 $3 [ j=:?1 17 $5 +((<i; a:;a:;j ){x) -: i{ j{"_ _3 x [ i=:?2 3$3 [ j=:?23 $7 +((<a:;i; j ){x) -: i{"_ _1 j{"_ _2 x [ i=:?2 3$4 [ j=:?17 $5 +((<a:;i; j; <a: ){x) -: i{"_ _1 j{"_ _2 x [ i=:?2 3$4 [ j=:?17 2 $5 +((<a:;i; a:;j ){x) -: i{"_ _1 j{"_ _3 x [ i=:?2 3$4 [ j=:?1 7 2$7 +((<a:;a:;i; j ){x) -: i{"_ _2 j{"_ _3 x [ i=:?23 $5 [ j=:?2 11 $7 + +i=:?&.(+&n)2 3 $n=:0{$x +j=:?&.(+&n)57 $n=:1{$x +k=:?&.(+&n)1 11$n=:2{$x +l=:?&.(+&n)13 $n=:3{$x +((<i;j;k;l){x) -: i{j{"_ _1 k{"_ _2 l{"_ _3 x +((<i;j;k ){x) -: i{j{"_ _1 k{"_ _2 x +((<i;j ){x) -: i{j{"_ _1 x +((<<i ){x) -: i{ x + +((<0 1)|:x) -: (,&.>~i.#x){x=:?15 15$10000 + + +NB. i{y integer indices ------------------------------------------------- + +fr =: 4 : '((x**/s)+/i.s=.}.$y){,y' + +i -: (i=:?2 3 4$1000) { y=:i.1000 +i -: (i=:?2 3 4$1000) fr y=:i.1000 + +(?100 $#y) ({ -: fr) y=:?200 $2 +(?100 $#y) ({ -: fr) y=:?200 3$2 +(?100 $#y) ({ -: fr) y=:?200 10$2 +(?100 $#y) ({ -: fr) y=:?200 21$2 +(?100 8$#y) ({ -: fr) y=:?200 $2 +(?100 8$#y) ({ -: fr) y=:?200 3$2 +(?100 8$#y) ({ -: fr) y=:?200 10$2 +(?100 8$#y) ({ -: fr) y=:?200 21$2 + +(?100 $#y) ({ -: fr) y=:(?20 $256){a. +(?100 $#y) ({ -: fr) y=:(?20 3$256){a. +(?100 $#y) ({ -: fr) y=:(?20 10$256){a. +(?100 $#y) ({ -: fr) y=:(?20 21$256){a. +(?100 9$#y) ({ -: fr) y=:(?20 $256){a. +(?100 9$#y) ({ -: fr) y=:(?20 3$256){a. +(?100 9$#y) ({ -: fr) y=:(?20 10$256){a. +(?100 9$#y) ({ -: fr) y=:(?20 21$256){a. + +(?101 $#y) ({ -: fr) y=:?20 $29999 +(?101 $#y) ({ -: fr) y=:?20 3$29999 +(?101 $#y) ({ -: fr) y=:?20 10$29999 +(?101 $#y) ({ -: fr) y=:?20 21$29999 +(?101 7$#y) ({ -: fr) y=:?20 $29999 +(?101 7$#y) ({ -: fr) y=:?20 3$29999 +(?101 7$#y) ({ -: fr) y=:?20 10$29999 +(?101 7$#y) ({ -: fr) y=:?20 21$29999 + +(?101 $#y) ({ -: fr) y=:o.?20 $29999 +(?101 $#y) ({ -: fr) y=:o.?20 2$29999 +(?101 $#y) ({ -: fr) y=:o.?20 5$29999 +(?101 $#y) ({ -: fr) y=:o.?20 11$29999 +(?101 7$#y) ({ -: fr) y=:o.?20 $29999 +(?101 7$#y) ({ -: fr) y=:o.?20 2$29999 +(?101 7$#y) ({ -: fr) y=:o.?20 5$29999 +(?101 7$#y) ({ -: fr) y=:o.?20 11$29999 + +(?101 $#y) ({ -: fr) y=:r.?25 $29999 +(?101 $#y) ({ -: fr) y=:r.?25 2$29999 +(?101 $#y) ({ -: fr) y=:r.?25 5$29999 +(?101 $#y) ({ -: fr) y=:r.?25 7$29999 +(?101 7$#y) ({ -: fr) y=:r.?25 $29999 +(?101 7$#y) ({ -: fr) y=:r.?25 2$29999 +(?101 7$#y) ({ -: fr) y=:r.?25 5$29999 +(?101 7$#y) ({ -: fr) y=:r.?25 7$29999 + +(?100 $#y) ({ -: fr) y=:(?23 $25){25$;:'opposable thumbs!' +(?100 $#y) ({ -: fr) y=:(?23 3$25){25$;:'+/i.1 2$a.' +(?100 $#y) ({ -: fr) y=:(?23 10$25){<"0?25$11234 +(?100 $#y) ({ -: fr) y=:(?23 21$25){;/?25$12355 +(?100 9$#y) ({ -: fr) y=:(?23 $25){;/o.?25$12345 +(?100 9$#y) ({ -: fr) y=:(?23 3$25){;/r.?25$12355 +(?100 9$#y) ({ -: fr) y=:(?23 10$25){;/j.?25$10000 +(?100 9$#y) ({ -: fr) y=:(?23 21$25){;/o.?25$23145 + +'index error' -: (2-2){ etx i.0 +'index error' -: (2-2){ etx '' +'index error' -: (2-2){ etx 0 2 3$a: +'index error' -: (2-2){"1 etx i.4 0 +'index error' -: (2-2){"1 etx a.{~i.4 0 + + +NB. x{"r y -------------------------------------------------------------- + +from =: 4 : 'x{y' + +(?100$5) ({"1 -: from"1) ?67 5$2 +(?100$5) ({"1 -: from"1) (?67 5$#x){x=:'sesquipedalian milquetoast' +(?100$5) ({"1 -: from"1) _1e6+?67 5$2e6 +(?100$5) ({"1 -: from"1) o._1e6+?67 5$2e6 +(?100$5) ({"1 -: from"1) r._1e6+?67 5$2e6 +(?100$5) ({"1 -: from"1) (?67 5$#x){x=:1;2;3;4;;:'quidnunc quinquagenarian 2e6' + +(_5+?100$10) ({"1 -: from"1) ?67 5$2 +(_5+?100$10) ({"1 -: from"1) (?67 5$#x){x=:'boustrophedonic' +(_5+?100$10) ({"1 -: from"1) _1e6+?67 5$2e6 +(_5+?100$10) ({"1 -: from"1) o._1e6+?67 5$2e6 +(_5+?100$10) ({"1 -: from"1) r._1e6+?67 5$2e6 +(_5+?100$10) ({"1 -: from"1) (?67 5$#x){x=:1;2;3;4;;:'miasma eleemosynary gruntlement' + +(_5+?100$10) ({"1 -: from"1) ?3 67 5$2 +(_5+?100$10) ({"1 -: from"1) (?3 67 5$#x){x=:'onomatopoeia' +(_5+?100$10) ({"1 -: from"1) _1e6+?3 67 5$2e6 +(_5+?100$10) ({"1 -: from"1) o._1e6+?3 67 5$2e6 +(_5+?100$10) ({"1 -: from"1) r._1e6+?3 7 5$2e6 +(_5+?100$10) ({"1 -: from"1) (?3 67 5$#x){x=:[&.>'supercalifragilisticexpialidocious' + +(_67+?100$134) ({"2 -: from"2) ?3 67 5$2 +(_67+?100$134) ({"2 -: from"2) (?3 67 5$#x){x=:'quotidian' +(_67+?100$134) ({"2 -: from"2) _1e6+?3 67 5$2e6 +(_67+?100$134) ({"2 -: from"2) o._1e6+?3 67 5$2e6 +(_7 +?100$ 14) ({"2 -: from"2) r._1e6+?3 7 5$2e6 +(_67+?100$134) ({"2 -: from"2) <"0?3 67 5$3e6 + +(_5+?7 11$10) ({"_ 1 -: from"_ 1) ?67 5$2 +(_5+?7 11$10) ({"_ 1 -: from"_ 1) (?67 5$#x){x=:'rhematic hoplite' +(_5+?7 11$10) ({"_ 1 -: from"_ 1) _1e6+?67 5$2e6 +(_5+?7 11$10) ({"_ 1 -: from"_ 1) o._1e6+?67 5$2e6 +(_5+?7 11$10) ({"_ 1 -: from"_ 1) r._1e6+? 7 5$2e6 +(_5+?7 11$10) ({"_ 1 -: from"_ 1) (?67 5$#x){x=:;:'Cogito, ergo sum.' + +(_5+?67$10) ({"_1 -: from"_1) ?67 5$2 +(_5+?67$10) ({"_1 -: from"_1) (?67 5$#x){x=:'tetragrammaton' +(_5+?67$10) ({"_1 -: from"_1) _1e6+?67 5$2e6 +(_5+?67$10) ({"_1 -: from"_1) o._1e6+?67 5$2e6 +(_5+? 7$10) ({"_1 -: from"_1) r._1e6+? 7 5$2e6 +(_5+?67$10) ({"_1 -: from"_1) (?67 5$#x){x=:1;2;3;;:'4 chthonic thalassic amanuensis' + +(<2) ({"1 -: from"1) x=:?4 5$2 +(<2) ({"1 -: from"1) x=:a.{~?4 5$#a. +(<2) ({"1 -: from"1) x=:?4 5$100 +(<2) ({"1 -: from"1) x=:o.?4 5$100 +(<2) ({"1 -: from"1) x=:j./?2 4 5$100 + +(<2) ({"2 -: from"2) x=:?3 4 5$2 +(<2) ({"2 -: from"2) x=:a.{~?3 4 5$#a. +(<2) ({"2 -: from"2) x=:?3 4 5$100 +(<2) ({"2 -: from"2) x=:o.?3 4 5$100 +(<2) ({"2 -: from"2) x=:j./?2 3 4 5$100 + +(<2 1) ({"2 -: from"2) x=:?3 4 5$2 +(<2 1) ({"2 -: from"2) x=:a.{~?3 4 5$#a. +(<2 1) ({"2 -: from"2) x=:?3 4 5$1000 +(<2 1) ({"2 -: from"2) x=:o.?3 4 5$1000 +(<2 1) ({"2 -: from"2) x=:j./?2 3 4 5$1000 + +(<<<2 1) ({"1 -: from"1) x=:?4 5$2 +(<<<2 1) ({"1 -: from"1) x=:a.{~?4 5$#a. +(<<<2 1) ({"1 -: from"1) x=:?4 5$1000 +(<<<2 1) ({"1 -: from"1) x=:o.?4 5$1000 +(<<<2 1) ({"1 -: from"1) x=:j./?2 4 5$1000 + +(6$&><"0 x) -: (6$0){"_ 0 x=:?4 5$2 +(6$&><"0 x) -: (6$0){"_ 0 x=:(?4 5$#x){x=:'archipelago' +(6$&><"0 x) -: (6$0){"_ 0 x=:?4 5$1000 +(6$&><"0 x) -: (6$0){"_ 0 x=:o.?4 5$1000 +(6$&><"0 x) -: (6$0){"_ 0 x=:r.?4 5$1000 +(6$&><"0 x) -: (6$0){"_ 0 x=:<"0?4 5$1000 + +(1 2;2 1) ({"2 -: from"2) x=:?3 4 5$1000 +(<1 2) ({"2 -: from"2) x +(<"1 ?3 6 2$4 5) ({"2 -: from"2) x +(<"1 ?3 6 1$4 ) ({"2 -: from"2) x +(<"1 ?3 7 6 2$4 5) ({"2 -: from"2) x +(<"1 ?3 7 6 1$4 ) ({"2 -: from"2) x + +(0 4$'') -: (i.0 4){"1 'abc' + + +'domain error' -: 'abc' {"1 etx i.3 4 +'domain error' -: 2.3 {"1 etx i.3 4 +'domain error' -: 2j3 {"1 etx i.3 4 +'domain error' -: (<'1'){"1 etx i.3 4 + +'length error' -: (i.7) {"0 1 etx i.8 9 +'length error' -: (i.7) {"_1 etx 5 9$'asdf' +'length error' -: (<0 1){"1 etx i.3 4 + +'index error' -: 5 {"1 etx ?4 5 $1234 +'index error' -: _6 {"2 etx ?4 5 6$1234 +'index error' -: 0 {"1 etx ?4 0 $1234 +'index error' -: 0 {"2 etx ?4 0 5$1234 +'index error' -: (<3) {"1 etx ?5 2 $1234 + + +NB. x{y complementary indexing ------------------------------------------ + +jot=:<$0 + +NB. Boolean +a =: 1=?2 3 4$2 +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<1){a + +NB. literal +a =: a.{~?2 3 4$256 +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<_2){a + +NB. integer +a =: ?2 3 4$256 +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<1){a + +NB. floating point +a =: o.?2 3 4$256 +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<_2){a + +NB. complex +a =: ^0j1*?2 3 4$256 +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<1){a + +NB. boxed +a =: 2 3 4$;:'+/..*(1 0 1#"2 a)-:(<jot;<<0){a' +(1{.a) -: (<<<1){a +(1{.a) -: (<<<1 _1){a +(1 0 1#"2 a) -: (<jot;<<_2){a + +'domain error' -: (<<<'a') { etx i.12 +'domain error' -: (<<<3.5) { etx i.12 + +'length error' -: (<0;<<_2) { etx i.12 + +'index error' -: (<<<2) { etx a=:1=?2 3 4$2 +'index error' -: (<0;<<_4 2){ etx a +'index error' -: (<<<2) { etx a=:(?2 3 4$#a.){a. +'index error' -: (<0;<<_4 2){ etx a +'index error' -: (<<<2) { etx a=:?2 3 4$1234 +'index error' -: (<0;<<_4 2){ etx a +'index error' -: (<<<2) { etx a=:o.?2 3 4$124 +'index error' -: (<0;<<_4 2){ etx a +'index error' -: (<<<2) { etx a=:r.?2 3 4$124 +'index error' -: (<0;<<_4 2){ etx a +'index error' -: (<<<2) { etx a=:2 3 4$'Mary';4 +'index error' -: (<0;<<_4 2){ etx a + + +NB. (<"1 x){y ----------------------------------------------------------- + +y=: ?11 13 17 19$1e6 +x=: ?2 3 5 7 11 4$$y +((<"1 x){y) -: x (<"1@[ { ]) y +((<"1 -x){y) -: (-x) (<"1@[ { ]) y +((<"1 <"0 x){y) -: (<"0 x)(<"1@[ { ]) y + +'domain error' -: 'abc' (<"1@[ { ]) etx y +'domain error' -: 3.5 (<"1@[ { ]) etx y + +'index error' -: 999 (<"1@[ { ]) etx y + + +NB. x{y leading indices are integer singletons -------------------------- + +f=: 4 : 0 + (;$&.>>x)$ ,: > {&.>/ (a:($,)&.>|.>x),<y +) + +s=: 11 7 5 3 2 13 7 +x=: ?s$1e9 + +(i=: <?&.>1{.s) ({ -: f) x +(i=: <?&.>2{.s) ({ -: f) x +(i=: <?&.>3{.s) ({ -: f) x +(i=: <?&.>4{.s) ({ -: f) x +(i=: <?&.>5{.s) ({ -: f) x +(i=: <?&.>6{.s) ({ -: f) x +(i=: <?&.>7{.s) ({ -: f) x + +(i=: <((?1$5){.&.><7$1)$&.>?&.>1{.s) ({ -: f) x +(i=: <((?2$5){.&.><7$1)$&.>?&.>2{.s) ({ -: f) x +(i=: <((?3$5){.&.><7$1)$&.>?&.>3{.s) ({ -: f) x +(i=: <((?4$5){.&.><7$1)$&.>?&.>4{.s) ({ -: f) x +(i=: <((?5$5){.&.><7$1)$&.>?&.>5{.s) ({ -: f) x +(i=: <((?6$5){.&.><7$1)$&.>?&.>6{.s) ({ -: f) x +(i=: <((?7$5){.&.><7$1)$&.>?&.>7{.s) ({ -: f) x + + +4!:55 ;:'a b catalog copy count f fr from i j ' +4!:55 ;:'jot k l n p prod q r s v x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g520b.ijs @@ -0,0 +1,96 @@ +NB. boolean { y --------------------------------------------------------- + +f0=: 3 : 0 + x=: a.{~ (2,y) ?@$ #a. + assert. (b{x) -: i{x + 1 +) + +f0"0 i.15 [ i=: (2-2)+b=: ?1000$2 +f0"0 i.15 [ i=: (2-2)+b=: ?1001$2 +f0"0 i.15 [ i=: (2-2)+b=: ?1002$2 +f0"0 i.15 [ i=: (2-2)+b=: ?1003$2 + +f0"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 +f0"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 5 7 +f0"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 5 7 11 + +f0"0 i.15 [ i=: (2-2)+b=: 1000$0 +f0"0 i.15 [ i=: (2-2)+b=: 1001$0 +f0"0 i.15 [ i=: (2-2)+b=: 1002$0 +f0"0 i.15 [ i=: (2-2)+b=: 1003$0 + +x=: 'a',:'012345',240 255{a. +y=: |."1 x +(b{x) -: (b+2-2){x [ b=: 1000 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1001 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1002 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1003 ?@$ 2 +(b{y) -: (b+2-2){y + +x=: 'a',:'012345',240 127{a. +y=: |."1 x +(b{x) -: (b+2-2){x [ b=: 1000 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1001 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1002 ?@$ 2 +(b{y) -: (b+2-2){y +(b{x) -: (b+2-2){x [ b=: 1003 ?@$ 2 +(b{y) -: (b+2-2){y + +f1=: 3 : 0 + x=: a.{~ (3 2,y) ?@$ #a. + assert. (b{"_ _1 x) -: i{"_ _1 x + 1 +) + +f1"0 i.15 [ i=: (2-2)+b=: ?1000$2 +f1"0 i.15 [ i=: (2-2)+b=: ?1001$2 +f1"0 i.15 [ i=: (2-2)+b=: ?1002$2 +f1"0 i.15 [ i=: (2-2)+b=: ?1003$2 + +f1"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 +f1"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 5 7 +f1"0 i.15 [ i=: (2-2)+b=: ?2$~2 3 5 7 11 + +f1"0 i.15 [ i=: (2-2)+b=: 1000$0 +f1"0 i.15 [ i=: (2-2)+b=: 1001$0 +f1"0 i.15 [ i=: (2-2)+b=: 1002$0 +f1"0 i.15 [ i=: (2-2)+b=: 1003$0 + +f2=: 3 : 0 + i=: (2-2)+b=: y ?@$ 2 + assert. (b{x) -: i{x=: ? 2$2 + assert. (b{x) -: i{x=: a.{~? 2$#a. + assert. (b{x) -: i{x=: ? 2$2e9 + assert. (b{x) -: i{x=: o. ? 2$2e9 + assert. (b{x) -: i{x=: r. ? 2$2e5 + assert. (b{x) -: i{x=: x: ? 2$2e9 + assert. (b{x) -: i{x=: %/x:?2 2$2e9 + assert. (b{x) -: i{x=: x{~ ? 2$#x=: ;:'Cogito, ergo sum. kakistocracy' + 1 +) + +f2"0 ] 1000+i.10 + +(b{"1 x) -: i{"1 x=: ? 5 2$2 [ i=: (2-2)+b=: ?5 120$2 +(b{"1 x) -: i{"1 x=: a.{~? 5 2$#a. +(b{"1 x) -: i{"1 x=: ? 5 2$2e9 +(b{"1 x) -: i{"1 x=: o. ? 5 2$2e9 +(b{"1 x) -: i{"1 x=: r. ? 5 2$2e5 +(b{"1 x) -: i{"1 x=: x: ? 5 2$2e9 +(b{"1 x) -: i{"1 x=: %/x:?2 5 2$2e9 +(b{"1 x) -: i{"1 x=: x{~?5 2$#x=: ;:'Cogito, ergo sum. kakistocracy' + + +'index error' -: (10$1 0) { etx i.1 5 +'index error' -: (10$0 ) { etx i.0 5 + + +4!:55 ;:'b f0 f1 f2 i x ' + +
new file mode 100644 --- /dev/null +++ b/test/g520p.ijs @@ -0,0 +1,56 @@ +NB. { permutations and permutation groups ------------------------------- + +NB. Generating any permutation as a sequence of 0&C. (rotating by 1) +NB. and _2&C. (transposing the last 2 items), based on the idea that +NB. p=: 0 C. i.n +NB. q=: _2 C. i.n +NB. can generate +NB. p0=: {/ (n=>:i.2+n) { p,:q +NB. q0=: q +NB. which are similar to p and q except that the leading item +NB. is invariant under permutation by p0 and q0. e.g. for n=:7 +NB. p: 1 2 3 4 5 6 0 +NB. q: 0 1 2 3 4 6 5 +NB. p0: 0 2 3 4 5 6 1 +NB. q0: 0 1 2 3 4 6 5 + +gen =: gn { generator@# +generator=: (,.0 _2)"_ C. i. + +gn=: 3 : 0 + 0 ,~ (0 C. i.#y) gn y + : + if. 2=n=. #y do. + (x-:y)}.1 + else. + m=. x i. {.y + (m#0) ,~ ; ((m|.x) gn&}. y) { (n=>:i.2+n) ; 1 + end. +) + +test=: 3 : 0 " 1 + assert. (1<#y) *. 0~:C.!.2 y + s=. gen y + assert. y -: {/s + assert. (~.s) e. generator #y + 1 +) + +test@(?~)"0 ] 2+?2 10$8 + +NB. the subgroup generated by a permutation or matrix of permutations + +stdarg =: i.@{:@$ , ,:^:(1: -: #@$) +pvp =: ~.@(,/)@({"1/~) +subgroup=: pvp^:_ @ stdarg + +NB. all permutations of i.n + +perm =: i.@! A. i. + +(perm -: /:~@subgroup@generator)"0 ]2+i.4 + + +4!:55 ;:'gen generator gn perm pvp stdarg subgroup test' + +
new file mode 100644 --- /dev/null +++ b/test/g521.ijs @@ -0,0 +1,362 @@ +NB. {.y ----------------------------------------------------------------- + +([ -: {.) 0 +([ -: {.) 'a' +([ -: {.) 3 +([ -: {.) 3.4 +([ -: {.) 3j4 +([ -: {.) <3 4 + +head =: }.&$ $ , + +NB. Boolean +(head -: {.) 1=?2 +(head -: {.) 1=?4$2 +(head -: {.) 1=?3 4$2 +(head -: {.) 1=?2 3 4$2 + +NB. literal +(head -: {.) 'a' +(head -: {.) a.{~?4$256 +(head -: {.) a.{~?3 4$256 +(head -: {.) a.{~?2 3 4$256 + +NB. integer +(head -: {.) 12345 +(head -: {.) ?4$123456 +(head -: {.) ?3 4$123456 +(head -: {.) ?2 3 4$123456 + +NB. floating point +(head -: {.) 123.45 +(head -: {.) o.?4$1236 +(head -: {.) o.?3 4$1256 +(head -: {.) o.?2 3 4$1456 + +NB. complex +(head -: {.) 123j45 +(head -: {.) ^0j1*?4$1236 +(head -: {.) ^0j1*?3 4$1256 +(head -: {.) ^0j1*?2 3 4$1456 + +NB. boxed +t=:(+&.>i.5),;:'(head -: {.) ^0j1*?3 4$1256' +(head -: {.) <123j45 +(head -: {.) t{~?4$#t +(head -: {.) t{~?3 4$#t +(head -: {.) t{~?2 3 4$#t + +( 3$0 ) -: {. 0 3$1 +(2 3$' ') -: {. 0 2 3$'a' +( 3$0 ) -: {. 0 3$12345 +( 3$0 ) -: {. 0 3$123.45 +( 3$0 ) -: {. 0 3$123j45 +(1 3$a: ) -: {. 0 1 3$<45 + +(2 3$3j4) -: {.!.3j4 i. 0 2 3 + + +NB. {."r y -------------------------------------------------------------- + +head =: }.&$ $ , +f0 =: {." 0 -: head" 0 +f1 =: {." 1 -: head" 1 +f2 =: {." 2 -: head" 2 +g1 =: {."_1 -: head"_1 +g2 =: {."_2 -: head"_2 + +f1 ?3 4 $2 +f1 ?3 4 5$2 +f2 ?3 4 $2 +f2 ?3 4 5$2 +g1 ?4 5 $2 +g1 ?4 5 6$2 +g2 ?4 5 $2 +g2 ?4 5 6$2 + +f1 (?3 4 $#x ){x=:'boustrophedonic' +f1 (?3 4 5$#a.){a. +f2 (?3 4 $#a.){a. +f2 (?3 4 5$#a.){a. +g1 (?3 4 $#x ){x=:'boustrophedonic' +g1 (?3 4 5$#a.){a. +g2 (?3 4 $#a.){a. +g2 (?3 4 5$#a.){a. + +f1 _1e5+?3 4 $2e5 +f1 _1e5+?3 4 5$2e5 +f2 _1e5+?3 4 $2e5 +f2 _1e5+?3 4 5$2e5 +g1 _1e5+?4 5 $2e5 +g1 _1e5+?4 5 6$2e5 +g2 _1e5+?4 5 $2e5 +g2 _1e5+?4 5 6$2e5 + +f1 o._1e5+?3 4 $2e5 +f1 o._1e5+?3 4 5$2e5 +f2 o._1e5+?3 4 $2e5 +f2 o._1e5+?3 4 5$2e5 +g1 o._1e5+?4 5 $2e5 +g1 o._1e5+?4 5 6$2e5 +g2 o._1e5+?4 5 $2e5 +g2 o._1e5+?4 5 6$2e5 + +f1 r._1e5+?3 4 $2e5 +f1 r._1e5+?3 4 5$2e5 +f2 r._1e5+?3 4 $2e5 +f2 r._1e5+?3 4 5$2e5 +g1 r._1e5+?4 5 $2e5 +g1 r._1e5+?4 5 6$2e5 +g2 r._1e5+?4 5 $2e5 +g2 r._1e5+?4 5 6$2e5 + +f1 (?31 4 $#x){x=:;:'super cali fragi listic' +f1 (?31 4 5$#x){x=:+&.>i.100 +f2 (?31 4 $#x){x=:(;:'Cogito, ergo sum.'),+&.>i.12 +f2 (?31 4 5$#x){x=:(<<'opposable thumbs'),+&.>i.12 +g1 (?31 4 $#x){x=:<"0 a. +g1 (?31 4 5$#x){x=:(i.12){.&.>123 +g2 (?31 4 $#x){x=:(<'junkfoo'),(i.12){.&.>3j4 +g2 (?31 4 5$#x){x=:5!:1&.<'g2' + +f =: {."0 -: head"0 +f ?4 5$2 +f 2 3 4$'supercalifragilisticespialidocious' +f ?2 3 4$1000 +f o.?100$1000 +f j./_500+?2 12$1000 +f >5!:1<'f' + + +NB. x{.y ---------------------------------------------------------------- + +(x,20$0 ) -: 23{.x=:?3$2 +(x,20$' ') -: 23{.x=:'fot' +(x,20$0 ) -: 23{.x=:?3$10000 +(x,20$0 ) -: 23{.x=:o.?3$10000 +(x,20$0 ) -: 23{.x=:j./?2 3$10000 +(x,20$<$0) -: 23{.x=:;:'Cogito, ergo' + +mt =: 0&e.@$ +fill =: > @ ({&(' ';a:;0)) @ (2 32&i.) @ (3!:0) +pad =: fill@] $~ (|@[ - #@]) 0} $@] +ti =: i.@-@[ + [ + #@] +case =: 0&<:@[ #.@, |@[ > #@] +itake =: (ti{])`(],~pad)`(i.@[{])`(],pad) @. case +taker =: 4 : '({.x) itake"({:x) y' +raise =: (1"0@[ $ ])`]@.(*@#@$@]) +larg =: <@,"(0) _&(0})@:-@i.@# +targ =: larg@[,<@raise +take =: >@(taker&.>/)@targ " 1 _ + +f =: {. -: take + +3 f 1 +_3 f 1 +0 f 5 +3 4 f 'a' +_3 4 f 'a' +3 _4 f <'foo' +_3 _4 f <'foo' + +2 3 4 f 3j4 +2 3 _4 f 3.4 +2 _3 4 f 324 +2 _3 _4 f '3' +_2 3 4 f 0 +_2 3 _4 f _24 +_2 _3 4 f _1.23e_34j_5.67e_28 +_2 _3 _4 f <7 + +3 f ?12$100 +_3 f ?12$123 +3 f 'abafasfkjsadf' +_3 f 'abasdfasdfasf' +3 f +&.>i.12 +_3 f +&.>i.12 + +3 f ?5 6 4$100 +_3 f ?5 6 4$100 +5 f ?5 6 4$100 +3 4 f ?5 6 4$100 +3 6 f ?5 6 4$100 +3 _6 f ?5 6 4$100 +_3 _6 f ?5 6 4$100 +5 6 f ?5 6 4$100 +5 6 4 f ?5 6 4$100 +1 _4 f +&.>?6 7$100 + +3 f '' +3 f i.0 +3 f 0$3.4 +3 f 0$3j4 +3 f 0$12x +3 f 0$3r4 +3 f 0$<'abc' +3 f 0 0$<'' +3 4 f i.0 0 +3 4 f 4 0 3$' ' +_3 4 f 0 0 5$<'' + +'domain error' -: 'abc' {. etx i.2 3 4 +'domain error' -: 3.4 5 {. etx i.2 3 4 +'domain error' -: 3j4 {. etx i.2 3 4 +'domain error' -: (3;4) {. etx i.2 3 4 + +'length error' -: 3 4 5 {. etx 1 2 +'length error' -: 3 4 5 {. etx i.1 2 + + +NB. x{."r y ------------------------------------------------------------- + +(i.4 0) -: 0{."1 i.4 5 +(i.4 5 0) -: 0{."1 i.4 5 7 +(i.4 0 7) -: 0{."2 i.4 5 7 + +((i.n){"1 x) -: n{."1 x=:? 11 13$1e9 [ n=:?13 +((i.n){"1 x) -: n{."1 x=:?5 11 13$1e9 [ n=:?13 + +x =: o.?3 5 7$1e9 +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:0 0 +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:0 2 +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:3 0 +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:3 2 +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:?}.$x +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:?}.$x +((i.1{n){"1 (i.0{n){"2 x) -: n{."2 x [ n=:?}.$x + +([\x) -: (>:i.#x){."0 1 x=:'abcdefghij' + +f =: 4 : 'x{.y' +3 4 5 ({."1 0 -: f"1 0) i.6 7 +3 4 5 ({."1 0 -: f"1 0) i.0 7 +3 0 5 ({."1 0 -: f"1 0) i.6 7 +3 0 5 ({."1 0 -: f"1 0) i.0 7 + + +NB. x{.!.f y ------------------------------------------------------------ + +(4 5$0) -: 4 5{. 0 +(4 5$9) -: 4 5{.!.9 [ 9 +(4 5$9) -: 4 5{.!.9 [ 0{9 0.1 +(4 5$9) -: 4 5{.!.9 [ 0{9 0j1 + +(7 3$(,i.2 3),15$o.1) -: 7{.!.(o.1) i.2 3 +(7 3$(,o.i.2 3),15$_9) -: 7{.!._9 o.i.2 3 + +'domain error' -: 5 0 {.!.'a' etx i. 4 3 +'domain error' -: 5 0 {.!.(<9) etx i.5 4 3 +'domain error' -: 4 5{.!.'a' etx 0 +'domain error' -: 4 5{.!.'a' etx i.3 4 +'domain error' -: 4 5{.!.'a' etx o.i.2 8 +'domain error' -: 4 5{.!.'a' etx r.i.2 8 +'domain error' -: 4 5{.!.'a' etx +&.>i.3 4 + +'domain error' -: 45 {.!.0 etx 'abc' +'domain error' -: 45 {.!.1 etx +&.>i.3 4 +'domain error' -: 45 {.!.5 etx 'amanuensis' +'domain error' -: 45 {.!._6 etx +&.>i.3 4 +'domain error' -: 45 {.!.3.5 etx 'abc' +'domain error' -: 45 {.!._6.89 etx +&.>i.3 4 +'domain error' -: 45 {.!.3j5 etx 'abc' +'domain error' -: 45 {.!._6j89 etx +&.>i.3 4 + +'domain error' -: 4 5{.!.(<3 4) etx 0 +'domain error' -: 4 5{.!.(<3 4) etx 2 3$'fourscore and seven years ago' +'domain error' -: 4 5{.!.(<'a') etx i.3 4 +'domain error' -: 4 5{.!.(<34) etx o.i.2 8 +'domain error' -: 4 5{.!.(<'a') etx r.i.2 8 + +'rank error' -: ex '{.!.($0)' +'rank error' -: ex '{.!.(,0)' + + +NB. fills --------------------------------------------------------------- + +ec =: '' +en =: $0 +eb =: 0$<0 +jot =: <'' + +' ' -: 3{.ec +0 0 0 -: 3{.en +(3$a:)-: 3{.eb + +((s,_3{.t)$' ') -: s {.(t=:2|8?8)$' ' [ s=:1+?5$2 +((s,_3{.t)$0 ) -: s {.(t=:2|8?8)$0 [ s=:1+?5$2 +((s,_3{.t)$a: ) -: s {.(t=:2|8?8)$a: [ s=:1+?5$2 + +((s,_3{.t)$' ') -: (-s){.(t=:2|8?8)$' ' [ s=:1+?5$2 +((s,_3{.t)$0 ) -: (-s){.(t=:2|8?8)$0 [ s=:1+?5$2 +((s,_3{.t)$a: ) -: (-s){.(t=:2|8?8)$a: [ s=:1+?5$2 + +s -: $ s {.' ' [ s=:?8$2 +s -: $ s {.0 [ s=:?8$2 +s -: $ s {.a: [ s=:?8$2 + +s -: $(-s){.' ' [ s=:?8$2 +s -: $(-s){.0 [ s=:?8$2 +s -: $(-s){.a: [ s=:?8$2 + +a=:1 3$'a' +(a,' ') -: a,ec +(a,' ') -: a,en +(a,' ') -: a,eb +(' ',a) -: ec,a +(' ',a) -: en,a +(' ',a) -: eb,a + +a=:i.1 3 +(a,0) -: a,ec +(a,0) -: a,en +(a,0) -: a,eb +(0,a) -: ec,a +(0,a) -: en,a +(0,a) -: eb,a + +a=:,:1;2;'abc' +(a,jot) -: a,ec +(a,jot) -: a,en +(a,jot) -: a,eb +(jot,a) -: ec,a +(jot,a) -: en,a +(jot,a) -: eb,a + +(0 0 1 0{' ',:a) -: >ec;en;a;eb [ a=:'abc' +(0 0 1 0{0 ,:a) -: >ec;en;a;eb [ a=:3 4 5 +(0 0 1 0{jot,:a) -: >ec;en;a;eb [ a=:4;5;i.3 4 + + +NB. x{.y with infinite left arguments ----------------------------------- + +(_ 3{.x) -: (({.$x),3){.x=: ?(?10 20)$1000 +(3 _{.x) -: (3,{:$x ){.x=: ?(?10 20)$1000 +(_ {.x) -: x +(_ _{.x) -: x +(2 _{.x) -: 2{.x + +(__ 3{.x) -: (({.$x),3){.x=: ?(?10 20)$1000 +(3 __{.x) -: (3,{:$x ){.x=: ?(?10 20)$1000 +(__ {.x) -: x +(__ __{.x) -: x +(2 __{.x) -: 2{.x + +(_ 2{."2 x) -: ((1{$x),2){."2 x=: ?(?10 20 30)$1000 +(2 _{."2 x) -: (2,2{$x ){."2 x=: ?(?10 20 30)$1000 + +(__ 2{."2 x) -: ((1{$x),2){."2 x=: ?(?10 20 30)$1000 +(2 __{."2 x) -: (2,2{$x ){."2 x=: ?(?10 20 30)$1000 + +(_ 2 3 _{. 12) -: 1 2 3 1{.12 +(__ 2 3 __{. 12) -: 1 2 3 1{.12 + +'domain error' -: 2.5 _ {. etx i.3 4 + +'limit error' -: (>IF64{(_,_1+2^31);_,_1+2^63){. etx i.3 4 + + +4!:55 ;:'a case eb ec en f f0 f1 f2 fill ' +4!:55 ;:'g1 g2 head itake jot larg mt n pad raise ' +4!:55 ;:'s t take taker targ ti x ' + +
new file mode 100644 --- /dev/null +++ b/test/g522.ijs @@ -0,0 +1,60 @@ +NB. {:y ----------------------------------------------------------------- + +tail =. _1&{ + +4 -: {: 4 +4 -: {: i.5 +'.' -: {: 'Cogito, ergo sum.' +(<'sum.') -: {: ;:'Cogito, ergo sum.' +8 9 10 11 -: {: i.3 4 + +NB. Boolean +(tail -: {:) 1=?2 +(tail -: {:) 1=?4$2 +(tail -: {:) 1=?3 4$2 +(tail -: {:) 1=?2 3 4$2 + +NB. literal +(tail -: {:) 'a' +(tail -: {:) a.{~?4$256 +(tail -: {:) a.{~?3 4$256 +(tail -: {:) a.{~?2 3 4$256 + +NB. integer +(tail -: {:) 12345 +(tail -: {:) ?4$123456 +(tail -: {:) ?3 4$123456 +(tail -: {:) ?2 3 4$123456 + +NB. floating point +(tail -: {:) 123.45 +(tail -: {:) o.?4$1236 +(tail -: {:) o.?3 4$1256 +(tail -: {:) o.?2 3 4$1456 + +NB. complex +(tail -: {:) 123j45 +(tail -: {:) ^0j1*?4$1236 +(tail -: {:) ^0j1*?3 4$1256 +(tail -: {:) ^0j1*?2 3 4$1456 + +NB. boxed +t=.(+&.>i.5),;:'(tail -: {:) ^0j1*?3 4$1256' +(tail -: {:) <123j45 +(tail -: {:) t{~?4$#t +(tail -: {:) t{~?3 4$#t +(tail -: {:) t{~?2 3 4$#t + +( 3$0 ) -: {: 0 3$1 +(2 3$' ') -: {: 0 2 3$'a' +( 3$0 ) -: {: 0 3$12345 +( 3$0 ) -: {: 0 3$123.45 +( 3$0 ) -: {: 0 3$123j45 +(1 3$a: ) -: {: 0 1 3$<45 + +(2 3$3j4) -: {:!.3j4 i. 0 2 3 + + +4!:55 ;:'t tail' + +
new file mode 100644 --- /dev/null +++ b/test/g530.ijs @@ -0,0 +1,362 @@ +NB. m}y and u}y --------------------------------------------------------- + +g =. e.&' '@{.} @ (,:&'_') +h =. e.&' ' {"0 1 ,"0&'_' + +(g -: h) 'Cogito, ergo sum.' +(g -: h) 2 3 4$'Now is the time, all good mean, to ergo sum.' + +((<0 1)&|: -: i.@}.@$}) i.,~?20 +((<0 1)&|: -: i.@}.@$}) i.,~?20 + +'domain error' -: ex '''a''} 2 3 4' +'domain error' -: ex '(<0)} 2 3 4 ' +'domain error' -: ex '2.1 } 2 3 4 ' +'domain error' -: ex '2j1 } 2 3 4 ' + +'index error' -: 3 } etx 2 3 4 +'index error' -: _4 } etx 2 3 4 +'index error' -: 3 1 2 0 } etx 3 4$'a' +'index error' -: _4 1 2 0 } etx 3 4$'a' + +'rank error' -: 2 } etx 3 4$'a' +'rank error' -: (3 4$0 1)} etx 3 4$'a' + +'length error' -: 2 3} etx i.4 3 +'length error' -: 2 3} etx i.4 1 + + +NB. a=: c}x,y,... ,:z --------------------------------------------------- + +f=: 3 : 0 + b=: ?5 7 11 13 17$2 + c=: ?($b)$3 + select. y + case. 'B' do. + xx=: ?($b)$2 + yy=: ?($b)$2 + zz=: ?($b)$2 + case. 'I' do. + xx=: _500+?($b)$1000 + yy=: _500+?($b)$1000 + zz=: _500+?($b)$1000 + case. 'D' do. + xx=: o._500+?($b)$1000 + yy=: o._500+?($b)$1000 + zz=: o._500+?($b)$1000 + case. 'Z' do. + xx=: j./_500+?(2,$b)$1000 + yy=: j./_500+?(2,$b)$1000 + zz=: j./_500+?(2,$b)$1000 + end. + i.0 0 +) + +g0=: 3 : 0 NB. basic identities, boolean selection + f y + q=: (xx*b)+yy*-.b + dd=: (b)}yy,:xx + aa=: b}yy,:xx + yy=: b}yy,:xx + assert. q -: dd + assert. q -: aa + assert. q -: yy + 1 +) + +g1=: 3 : 0 NB. basic identities, integer selection + f y + q=: (xx*0=c)+(yy*1=c)+zz*2=c + dd=: (c)}xx,yy,:zz + aa=: c}xx,yy,:zz + yy=: c}xx,yy,:zz + assert. q -: dd + assert. q -: aa + assert. q -: yy + 1 +) + +g2=: 3 : 0 NB. force new copy, boolean selection + f y + q=: (xx*b)+yy*-.b + p=: yy + yy=: b}yy,:xx + assert. q -: yy + assert. q -: (xx*b)+p*-.b + assert. -. p -: yy + 1 +) + +g3=: 3 : 0 NB. force new copy, integer selection + f y + q=: (xx*0=c)+(yy*1=c)+zz*2=c + p=: yy + yy=: c}xx,yy,:zz + assert. q -: yy + assert. q -: (xx*0=c)+(p*1=c)+zz*2=c + assert. -. p -: yy + 1 +) + +g4=: 3 : 0 NB. in place, boolean selection + f y + q=: (xx*b)+yy*-.b + t=: 7!:2 'yy=: b}yy,:xx' + assert. q -: yy + assert. t<IF64{2000 4000 + 1 +) + +g5=: 3 : 0 NB. integer selection + f y + q=: (xx*0=c)+(yy*1=c)+zz*2=c + yy=: c}xx,yy,:zz + assert. q -: yy + d =: 1+c + z1=: 0+zz + assert. 'index error' -: ex 'zz=: d}xx,yy,:zz' + assert. zz -: z1 + 1 +) + +g8=: 3 : 0 NB. force idiom misidentification, boolean selection + f y + xx=: {.,xx + q=: (xx*b)+yy*-.b + aa=: b}yy,:xx + yy=: b}yy,:xx + assert. q -: yy + assert. q -: aa + 1 +) + +g9=: 3 : 0 NB. force idiom misidentification, integer selection + f y + xx=: {.,xx + q=: (xx*0=c)+(yy*1=c)+zz*2=c + aa=: c}xx,yy,:zz + yy=: c}xx,yy,:zz + assert. q -: yy + assert. q -: aa + 1 +) + +g10=: 3 : 0 NB. force idiom misidentification, boolean selection + f y + xx=: 5&, + a=: b}xx,:yy + assert. a -: (5*-.b) + b*yy + 1 +) + +g11=: 3 : 0 NB. force idiom misidentification, integer selection + f y + xx=: 5&,@((2,$c)&$) + a=: c}xx,yy,:zz + assert. a -: (5*0=c) + (yy*1=c) + zz*2=c + 1 +) + +g2c=: 3 : 0 NB. character data, boolean selection + f y + q=: b{"0 1 xx,"0 yy + p=: yy + yy=: b}xx,:yy + assert. q -: yy + assert. q -: b{"0 1 xx,"0 p + assert. -. p -: yy + 1 +) + +g3c=: 3 : 0 NB. character data, integer selection + f y + q=: c{"0 1 xx,"0 1 yy ,"0 zz + p=: yy + yy=: c}xx,yy,:zz + assert. q -: yy + assert. q -: c{"0 1 xx,"0 1 p,"0 zz + assert. -. p -: yy + 1 +) + +g0 "0 'BIDZ' +g1 "0 'BIDZ' +g2 "0 'BIDZ' +g2c"0 'C' +g3 "0 'BIDZ' +g3c"0 'C' +g4 "0 'BIDZ' +g5 "0 'BIDZ' +g8 "0 'BIDZ' +g9 "0 'BIDZ' +g10"0 'BIDZ' +g11"0 'BIDZ' + +y=: 1 2 3 +b=: 0 1 2 +4!:55 ;:'x' +'value error' -: ex 'x=:b}x,:y' +x=: 10 20 30 +'index error' -: ex 'x=:b}x,:y' +b=: 0 1 +'length error' -: ex 'x=:b}x,:y' +b=: 'abc' +'domain error' -: ex 'x=:b}x,:y' +y=: 'abc' +b=: 0 1 0 +'domain error' -: ex 'x=:b}x,:y' + + +NB. x m}y and x u}y ----------------------------------------------------- + +ia =. 1 : 'x@(i.@$@])' +f =. '_'&((' '&= # i.@#)@,@]}) +h =. e.&' ' {"0 1 ,"0&'_' + +'Cogito,*ergo*sum.' -: '*' (' '&= # i.@#)@]} 'Cogito, ergo sum.' +(f -: h) 'Cogito, ergo sum.' +(f -: h) 2 3 4$'Now is the time, all good mean, to ergo sum.' + +C =. 2 : 'x & ((#i.@#)@,@y@] })' + +(f -: '_' C (' '&=)) 'Cogito, ergo sum.' +(f -: '_' C (' '&=)) 2 3 4$'Now is the time, all good mean, to ergo sum.' +a -: ' ' C('_'&=) '_' C(' '&=) a =. 2 3 4$'Now is the time, all good mean, ' + +*./ (=@i. -: 1&((<0 1)&|:ia})@($&0)@(,~))"0 ?5$10 + +'abcX' -: 'X' _1}'abcd' + +1 -: type 'a' ''}0$0 +2 -: type 'a' ''}'' +4 -: type 'a' ''}i.0 +8 -: type 'a' ''}0$3.5 +16 -: type 'a' ''}0$3j5 +32 -: type 'a' ''}0$<3 5 +64 -: type 'a' ''}0$3x +128 -: type 'a' ''}0$3r5 + +123 -: 123 (0)}456 +123 -: 123 a: }456 + +(3 4$123) -: 123 a: }?3 4$1000 +(3 4$123) -: 123 (<$0)}?3 4$1000 +(3 4$123) -: 123 (<'')}?3 4$1000 + +y=: ?100 50 7$1e6 +i=: ?50 2$100 50 +x=: ?50 7$1e6 +(x (<"1 i)} y) -: x (<"1 i,"1 0"1 i.7)}y + +i=: ?11$100 +j=: ?13$50 +k=: ?17$7 +x=: ?11 13 17$1e6 +(x (<i;j;k)}y) -: x ({i;j;k)}y + +test=: 4 : 'y -: x (i.0)}y' +y=: 0 1 1;'235';2 3 5;2 3.5 6;2 3j5 6;(2;3;5);(u: 'abc');s: ' a b c' +(0$&.>y) test&>/ y + +y -: (0$a:) ($0)} y=: 5 ?@$ 1e6 +y -: '' ($0)} y +y -: (i.0) ($0)} y +y -: (0$0.5)($0)} y +y -: (0$0j5)($0)} y + +'domain error' -: ex '7 ''a''} 2 3 4' +'domain error' -: ex '7 (<2.3)} 2 3 4' +'domain error' -: ex '7 ( 2.1)} 2 3 4' +'domain error' -: ex '7 ( 2j1)} 2 3 4' + +'domain error' -: 1 i.@#@]} etx 'abc' +'domain error' -: (<'a')i.@#@]} etx 'abc' +'domain error' -: 'a' i.@#@]} etx 2 3 4 +'domain error' -: (<12) i.@#@]} etx 2 3 4 +'domain error' -: 1 i.@#@]} etx 2;3 4 +'domain error' -: 'ab' i.@#@]} etx 2;3 4 + +'domain error' -: 1 (0 1)} etx 'abc' +'domain error' -: (<'a')(0 1)} etx 'abc' +'domain error' -: 'a' (0 1)} etx 2 3 4 +'domain error' -: (<12) (0 1)} etx 2 3 4 +'domain error' -: 1 (0 1)} etx 2;3 4 +'domain error' -: 'ab' (0 1)} etx 2;3 4 + +'index error' -: 7 ( 3)} etx 2 3 4 +'index error' -: 7 (_4)} etx 2 3 4 +'index error' -: 7 3:} etx 2 3 4 +'index error' -: 7 _4:} etx 2 3 4 + +'length error' -: 2 3 i.@#@]} etx i.3 +'length error' -: (i.2 3) i.@$@]} etx i.4 3 2 + +'rank error' -: (i.2 3 4) i.@#@]} etx i.3 4 +'rank error' -: (i.2 3 4) 0 } etx i.3 4 + + +NB. } in place ---------------------------------------------------------- + +sp =: 7!:2 +b32 =: 100>#3!:1 i.8 NB. 1 if 32-bit; 0 if 64-bit + +foo =. 3 : 0 + pqr=.xyz =. i.10000 + z=.'' + z=.z,sp 'xyz=. _123 (4)}xyz' NB. create copy + z=.z,sp 'xyz=. _456 (5)}xyz' NB. in place + z=.z,sp 'xyz=. _789 (6})xyz' NB. in place + z=.z,sp 'qqq=. _123 (7)}xyz' NB. create copy + assert. xyz -: 0 1 2 3 _123 _456 _789,7}.i.10000 + assert. pqr -: i. 10000 + z +) + +goo =. 3 : 0 + pqr=.xyz =. i.10000 + z=.'' + z=.z,sp 'xyz=. xyz 4}~ _123' NB. create copy + z=.z,sp 'xyz=. xyz 5}~ _456' NB. in place + z=.z,sp 'xyz=. xyz 6}~ _789' NB. in place + z=.z,sp 'qqq=. xyz 7}~ _123' NB. create copy + assert. xyz -: 0 1 2 3 _123 _456 _789,7}.i.10000 + assert. pqr -: i. 10000 + z +) + +(68500 2900 2900 68500*2-b32) > t=.foo 1 +(68500 2900 2900 68500*2-b32) > t=.goo 1 + +abc =. save =. i.10000 +(68500*2-b32) > t1=.sp 'abc=. _123 (0) }abc' NB. create copy +( 2900*2-b32) > t2=.sp 'abc=. _123 (1 2)}abc' NB. in place +( 2900*2-b32) > t2=.sp 'abc=. _123 (3 4})abc' NB. in place + +abc =. save =. i.10000 +(68500*2-b32) > t1=.sp 'abc=. abc 0}~ _123' NB. create copy +( 2900*2-b32) > t2=.sp 'abc=. abc 1 2}~ _123' NB. in place +( 2900*2-b32) > t2=.sp 'abc=. abc 3 4}~ _123' NB. in place + +-. abc -: save +abc -: (5#_123),5}.i.10000 +*./ 0 <: save +save -: i.10000 + +4!:55;:'ab abc x' + +abc =: ?20 50 100$1e6 +x =: ?1e6 +10000 > sp 'abc=: x (<10;20;30)}abc' +x -: (<10;20;30){abc + +y=: ?1e6 +ab=: y (<10;20;30)}abc +x -: (<10;20;30){abc +y -: (<10;20;30){ab +*./, 1 (<10;20;30)} ab = abc + + +4!:55 ;:'a aa ab abc b b32 C c d dd f foo ' +4!:55 ;:'g g0 g1 g2 g2c g3 g3c g4 g5 g8 g9 g10 g11 goo ' +4!:55 ;:'h i ia j k p q save sp t t0 t1 t2 test x xx y yy z z1 zz ' +
new file mode 100644 --- /dev/null +++ b/test/g530t.ijs @@ -0,0 +1,53 @@ +NB. a=: c}x,y,... ,:z timing tests -------------------------------------- + +f=: 3 : 0 + b=: ?5 7 11 13 17$2 + c=: ?($b)$3 + select. y + case. 'B' do. + xx=: ?($b)$2 + yy=: ?($b)$2 + zz=: ?($b)$2 + case. 'I' do. + xx=: _500+?($b)$1000 + yy=: _500+?($b)$1000 + zz=: _500+?($b)$1000 + case. 'D' do. + xx=: o._500+?($b)$1000 + yy=: o._500+?($b)$1000 + zz=: o._500+?($b)$1000 + case. 'Z' do. + xx=: j./_500+?(2,$b)$1000 + yy=: j./_500+?(2,$b)$1000 + zz=: j./_500+?(2,$b)$1000 + end. + i.0 0 +) + +g6=: 3 : 0 NB. good timing, boolean selection + f y + t0=: timer 'q=: (xx*b)+yy*-.b' + t1=: timer 'yy=: b}yy,:xx' + assert. q -: yy + assert. (1-threshold) > (t1-t0)%t0 + 1 +) + +g7=: 3 : 0 NB. good timing, integer selection + f y + t0=: timer 'q=: (xx*0=c)+(yy*1=c)+zz*2=c' + t1=: timer 'yy=: c}xx,yy,:zz' + assert. q -: yy + assert. (1-threshold) > (t1-t0)%t0 + 1 +) + +g6 "0 'BIDZ' +g7 "0 'BIDZ' + + +4!:55 ;:'b c f g6 g7 q t0 t1 xx yy zz' + + + +
new file mode 100644 --- /dev/null +++ b/test/g531.ijs @@ -0,0 +1,124 @@ +NB. }.y ----------------------------------------------------------------- + +behead =: 1&}. + +NB. Boolean +(behead -: }.) 1=?2 +(behead -: }.) 1=?4$2 +(behead -: }.) 1=?3 4$2 +(behead -: }.) 1=?2 3 4$2 +(behead -: }.) 1=?0 3$2 + +NB. literal +(behead -: }.) 'a' +(behead -: }.) a.{~?4$256 +(behead -: }.) a.{~?3 4$256 +(behead -: }.) a.{~?2 3 4$256 +(behead -: }.) 1=?0 3$256 + +NB. integer +(behead -: }.) 12345 +(behead -: }.) ?4$123456 +(behead -: }.) ?3 4$123456 +(behead -: }.) ?2 3 4$123456 +(behead -: }.) ?0 3$123456 + +NB. (behead -: }.)loating point +(behead -: }.) 123.45 +(behead -: }.) o.?4$1236 +(behead -: }.) o.?3 4$1256 +(behead -: }.) o.?2 3 4$1456 +(behead -: }.) 0 3$123.456 + +NB. complex +(behead -: }.) 123j45 +(behead -: }.) ^0j1*?4$1236 +(behead -: }.) ^0j1*?3 4$1256 +(behead -: }.) ^0j1*?2 3 4$1456 +(behead -: }.) 0 3$123j56 + +NB. boxed +t=:(+&.>i.5),;:'(raze a) -: }. a=: ^0j1*?3 4$1256' +(behead -: }.) <123j45 +(behead -: }.) t{~?4$#t +(behead -: }.) t{~?3 4$#t +(behead -: }.) t{~?2 3 4$#t +(behead -: }.) 0 3$<123456 + + +NB. x}.y ---------------------------------------------------------------- + +pi =: 0&< @[ * 0&<.@- +ni =: 0&>:@[ * 0&>.@+ +di =: ({.~ #@$) (pi + ni) $@] +drop =: (di {. ])"1 _ + +m=:?4 5 6$100 +0 (}. -: drop) m +1 (}. -: drop) m +_1 (}. -: drop) m +2 0 _1 (}. -: drop) m +0 0 9 (}. -: drop) m +_9 _9 _9 (}. -: drop) m + +test =: }. -: [ }. 0&<:@i.@#@[ $ ] + +1 2 3 test 4 +1 0 3 test 4 +1 2 0 test 4 +0 0 0 test 4 + +1 2 3 test 'a' +1 0 3 test 'a' +1 2 0 test 'a' +0 0 0 test 'a' + +1 2 3 test <4;5;6 +1 0 3 test <'sui generis' +1 2 0 test 4 +0 0 0 test <;:'Cogito, ergo sum.' + +'length error' -: 1 2 3 }. etx i.2 3 +'length error' -: 2 3 }. etx 'abcd' + + +NB. x}."r y ------------------------------------------------------------- + +f =: 4 : 'x}.y' + +5 (}."1 -: f"1) i.4 5 +_7 (}."1 -: f"1) i.4 5 7 +5 (}."2 -: f"2) i.4 5 7 + +( ?17) (}."1 -: f"1) ? 11 13$1e9 +(-?17) (}."1 -: f"1) ? 11 13$1e9 +( ?17) (}."1 -: f"1) ?5 11 13$1e9 +(-?17) (}."1 -: f"1) ?5 11 13$1e9 + +x =: o.?3 5 7$1e9 +n (}."2 -: f"2) x [ n=:0 0 +n (}."2 -: f"2) x [ n=:0 2 +n (}."2 -: f"2) x [ n=:3 0 +n (}."2 -: f"2) x [ n=:3 2 +n (}."2 -: f"2) x [ n=:?}.$x +n (}."2 -: f"2) x [ n=:?}.$x +n (}."2 -: f"2) x [ n=:?}.$x + +([\.x) -: (i.#x)}."0 1 x=:'abcdefghij' + +3 4 5 (}."1 0 -: f"1 0) i.6 7 +3 4 5 (}."1 0 -: f"1 0) i.0 7 +3 0 5 (}."1 0 -: f"1 0) i.6 7 +3 0 5 (}."1 0 -: f"1 0) i.0 7 + +(4x }."1 x) -: 4 }."1 x=: (1+?7 20) ?@$ 1e6 + +( 5e4$1) -: $ (5e4$0) }. 7 +(7,5e4$1) -: $ (5e4$0) }."1 0 i.7 +( 5e2$1) -: $ (5e2$0) }. 7x +(7,5e2$1) -: $ (5e2$0) }."1 0 i.7x + + +4!:55 ;:'behead di drop f m n ni pi t test x ' + +
new file mode 100644 --- /dev/null +++ b/test/g532.ijs @@ -0,0 +1,50 @@ +NB. }:y ----------------------------------------------------------------- + +curtail =. _1&}. + +NB. Boolean +(curtail -: }:) 1=?2 +(curtail -: }:) 1=?4$2 +(curtail -: }:) 1=?3 4$2 +(curtail -: }:) 1=?2 3 4$2 +(curtail -: }:) 1=?0 3$2 + +NB. literal +(curtail -: }:) 'a' +(curtail -: }:) a.{~?4$256 +(curtail -: }:) a.{~?3 4$256 +(curtail -: }:) a.{~?2 3 4$256 +(curtail -: }:) 1=?0 3$256 + +NB. integer +(curtail -: }:) 12345 +(curtail -: }:) ?4$123456 +(curtail -: }:) ?3 4$123456 +(curtail -: }:) ?2 3 4$123456 +(curtail -: }:) ?0 3$123456 + +NB. floating point +(curtail -: }:) 123.45 +(curtail -: }:) o.?4$1236 +(curtail -: }:) o.?3 4$1256 +(curtail -: }:) o.?2 3 4$1456 +(curtail -: }:) 0 3$123.456 + +NB. complex +(curtail -: }:) 123j45 +(curtail -: }:) ^0j1*?4$1236 +(curtail -: }:) ^0j1*?3 4$1256 +(curtail -: }:) ^0j1*?2 3 4$1456 +(curtail -: }:) 0 3$123j56 + +NB. boxed +t=.(+&.>i.5),;:'(raze a) -: }: a=. ^0j1*?3 4$1256' +(curtail -: }:) <123j45 +(curtail -: }:) t{~?4$#t +(curtail -: }:) t{~?3 4$#t +(curtail -: }:) t{~?2 3 4$#t +(curtail -: }:) 0 3$<123456 + +4!:55 ;:'curtail t ' + +
new file mode 100644 --- /dev/null +++ b/test/g5x.ijs @@ -0,0 +1,65 @@ +NB. 5!: ----------------------------------------------------------------- + +ar =. 5!:1 +dr =. 5!:2 +tr =. 5!:4 +lr =. 5!:5 +pr =. 5!:6 + +'domain error' -: ar etx 0 +'domain error' -: dr etx 0 +'domain error' -: tr etx 0 +'domain error' -: lr etx 0 +'domain error' -: pr etx 0 + +'domain error' -: ar etx 't' +'domain error' -: dr etx 't' +'domain error' -: tr etx 't' +'domain error' -: lr etx 't' +'domain error' -: pr etx 't' + +'domain error' -: ar etx 34 +'domain error' -: dr etx 34 +'domain error' -: tr etx 34 +'domain error' -: lr etx 34 +'domain error' -: pr etx 34 + +'domain error' -: ar etx 3.4 +'domain error' -: dr etx 3.4 +'domain error' -: tr etx 3.4 +'domain error' -: lr etx 3.4 +'domain error' -: pr etx 3.4 + +'domain error' -: ar etx 3j4 +'domain error' -: dr etx 3j4 +'domain error' -: tr etx 3j4 +'domain error' -: lr etx 3j4 +'domain error' -: pr etx 3j4 + +'ill-formed name' -: ar etx <'' +'ill-formed name' -: dr etx <'' +'ill-formed name' -: tr etx <'' +'ill-formed name' -: lr etx <'' +'ill-formed name' -: pr etx <'' + +'ill-formed name' -: ar etx <'-' +'ill-formed name' -: dr etx <'-' +'ill-formed name' -: tr etx <'-' +'ill-formed name' -: lr etx <'-' +'ill-formed name' -: pr etx <'-' + +'ill-formed name' -: ar etx <'a b c' +'ill-formed name' -: dr etx <'a b c' +'ill-formed name' -: tr etx <'a b c' +'ill-formed name' -: lr etx <'a b c' +'ill-formed name' -: pr etx <'a b c' + +'value error' -: ar etx <'asdfasdf' +'value error' -: dr etx <'asdfasdf' +'value error' -: tr etx <'asdfasdf' +'value error' -: lr etx <'asdfasdf' +'value error' -: pr etx <'asdfasdf' + +4!:55 ;:'ar dr pr lr tr' + +
new file mode 100644 --- /dev/null +++ b/test/g5x0.ijs @@ -0,0 +1,168 @@ +NB. 5!:0 ---------------------------------------------------------------- + +fx =: 5!:0 +ar =: 5!:1 + +((ar <'a') fx) -: a =: 2=?20$2 +((ar <'a') fx) -: a =: a.{~?2 3 4$#a. +((ar <'a') fx) -: a =: ?2 3$2000 +((ar <'a') fx) -: a =: o.?20$100 +((ar <'a') fx) -: a =: ^0j1*?3 4 5$100 +((ar <'a') fx) -: a =: +&.>?4 3$100 + +((ar <'a') fx) -: a =: 0 4 5 $ 2=?20$2 +((ar <'a') fx) -: a =: 0 0 $ a.{~?2 3 4$#a. +((ar <'a') fx) -: a =: 4 0 0 $ ?2 3$2000 +((ar <'a') fx) -: a =: 0 $ o.?20$100 +((ar <'a') fx) -: a =: 4 0 5 $ ^0j1*?3 4 5$100 +((ar <'a') fx) -: a =: 5 0 $ +&.>?4 3$100 + +tv =: 1 : '=/(ar<''x'') fx `(x f.)' +eq =: ar&<@[ -: ar&<@] +each =: 1 : 'x f.&.>' +pow =: 2 : ('i=.>:y'; 't=.]'; 'while. i=.<:i do. t=.x&t f. end.') + ++ tv ++/ . * tv ++/ pow 4 tv +|. each tv + ++/ : * tv ++/ : [: tv +3 : '2*y' tv +[: : (3&*) tv +[: : [: tv + +(+%) tv +(=<.) tv +(+,-) tv +(0&<: *. <.) tv + +f =: \. +g =: (ar <'f') fx +'f' eq 'g' + +f =: : +g =: (ar <'f') fx +'f' eq 'g' + +f =: eq +g =: (ar <'f') fx +'f' eq 'g' + +f =: each +g =: (ar <'f') fx +'f' eq 'g' + +f =: pow +g =: (ar <'f') fx +'f' eq 'g' + +a. -: (<'a.') fx +=/ (<'+') fx ` + +(+/a) -: + (<'/') fx a=:?20$100 + +f =: +&.^. +g =: + ((<'&.') fx) ^. +'f' eq 'g' + +f =: +/. +g =: (<'/.';<''`+) fx +'f' eq 'g' + +f =: /. +g =: (<'/.') fx +'f' eq 'g' + +f =: & +g =: (<,<,'&') fx +'f' eq 'g' + + +NB. 5!:0 ---------------------------------------------------------------- + +fx =: 5!:0 +ar =: 5!:1 + +'rank error' -: ex '( 3 4$<9 ) fx' +'rank error' -: ex '(<3 4$<9 ) fx' +'rank error' -: ex '(<3 4$''a'') fx' + +'domain error' -: ex '0 fx' +'domain error' -: ex '34 fx' +'domain error' -: ex '3.5 fx' +'domain error' -: ex '3j4 fx' +'domain error' -: ex '+ fx' + +'length error' -: ex '(<''+'';3;4) fx' + +'domain error' -: ex '(<0 1 0 ) fx' +'domain error' -: ex '(<3 4 5 ) fx' +'domain error' -: ex '(<3.5 4 5) fx' +'domain error' -: ex '(<3j5 4 5) fx' + +'spelling error' -: ex '(<''asdf:'') fx' +'spelling error' -: ex '(<128{a.) fx' +'spelling error' -: ex '(<156{a.) fx' +'spelling error' -: ex '(<254{a.) fx' +'spelling error' -: ex '(<255{a.) fx' + +'spelling error' -: ex '(<''*%'';4 ) fx' +'spelling error' -: ex '(<''*%'' ) fx' +'spelling error' -: ex '(<''*.%'' ) fx' +'spelling error' -: ex '(<''ab.'' ) fx' +'domain error' -: ex '(<''=.'' ) fx' +'domain error' -: ex '(<''=:'' ) fx' +'domain error' -: ex '(<''x.'' ) fx' +'domain error' -: ex '(<''0'' ) fx' +'domain error' -: ex '(<''2'' ) fx' +'domain error' -: ex '(<''3'' ) fx' +'domain error' -: ex '(<3 ;4 ) fx' +'domain error' -: ex '(<3j4 ;5 ) fx' +'domain error' -: ex '(<(<''+'');4 ) fx' +'rank error' -: ex '(<(3 4$''+'');4 ) fx' + +'domain error' -: ex '(<''/.'';<4 ) fx' +'domain error' -: ex '(<''/.'';<''a'' ) fx' +'domain error' -: ex '(<''/.'';<3.5 ) fx' +'domain error' -: ex '(<''/.'';<3j4 ) fx' +'rank error' -: ex '(<''/.'';<3 4$<9 ) fx' +'length error' -: ex '(<''+.'';<+`% ) fx' +'length error' -: ex '(<''/.'';<+`% ) fx' +'length error' -: ex '(<''&'';<''''`% ) fx' +'length error' -: ex '(<''&'';<3$+`% ) fx' + +noun=.3 4 +cn =. ar <'noun' +verb=.+ +cv =. ar <'verb' + +f=:+% +(<(,'2');<+ ` %) -: ar <'f' +'domain error' -: ex '(<''2'';<3 4 ) fx' +'syntax error' -: ex '(<''2'';<cv,cn ) fx' +'syntax error' -: ex '(<''2'';<cn,cv ) fx' +'syntax error' -: ex '(<''2'';<cn,cn ) fx' +'domain error' -: ex '(<''2'' ) fx' +'length error' -: ex '(<''2'';<<''%'' ) fx' +'length error' -: ex '(<''2'';<+ ` % `- ) fx' + +f=:+,* +(<(,'3');<+ ` , ` *) -: ar <'f' +'domain error' -: ex '(<''3'' ) fx' +'syntax error' -: ex '(<''3'';<cv,cv,cn ) fx' +'syntax error' -: ex '(<''3'';<cv,cn,cv ) fx' +'syntax error' -: ex '(<''3'';<cv;cv;''/'' ) fx' +'length error' -: ex '(<''3'';0$<i.0 ) fx' +'length error' -: ex '(<''3'';<+ ` , ) fx' +'length error' -: ex '(<''3'';<4$ , ` * ) fx' + +10 -: (<'/';<<'+') fx i.5 +'domain error' -: ex '(<''/''; <<''\'' ) fx' +'domain error' -: ex '(<''&''; <''/'';''@'') fx' +'length error' -: ex '(<''a.'';<<''+'' ) fx' + + +4!:55 ;:'a ar cn cv each eq f fx g noun pow tv verb ' + +
new file mode 100644 --- /dev/null +++ b/test/g5x1.ijs @@ -0,0 +1,172 @@ +NB. 5!:1 ---------------------------------------------------------------- + +ar =: 5!:1 +dr =: 5!:2 +nar =: <&((<,'0')&,)&< +mtv =: $0 + +(ar <'a') -: nar a =: 1=?10$2 +(ar <'a') -: nar a =: 'Cogito, ergo sum.' +(ar <'a') -: nar a =: ?3 4$10 +(ar <'a') -: nar a =: 3.14159265358979 +(ar <'a') -: nar a =: ^0j1*?3 4$10 +(ar <'a') -: nar a =: +&.>?10$25 + +(ar <'a') -: nar a =: 0 3 4 $ 1=?10$2 +(ar <'a') -: nar a =: 4 0 $ 'Cogito, ergo sum.' +(ar <'a') -: nar a =: 0 $ ?3 4$10 +(ar <'a') -: nar a =: 4 0 5 $ 3.14159265358979 +(ar <'a') -: nar a =: 0 0 $ ^0j1*?3 4$10 +(ar <'a') -: nar a =: 0 0 0 $ +&.>?10$25 + +f=: ^ +(ar <'f') -: <,'^' +f=: /. +(ar <'f') -: <'/.' +f=: &. +(ar <'f') -: <'&.' + +plus =: + +or =: +. +over =: , +hook =: (plus or) f. +fork =: (plus,or) f. +(ar <'plus') -: <,'+' +(ar <'or' ) -: <'+.' +(ar <'over') -: <,',' +(ar <'hook') -: <(,'2');<ar ;:'plus or' +(ar <'fork') -: <(,'3');<ar ;:'plus over or' + +f =: * +g =: + +a =: >'*y'; ':'; 'x*y' +n3 =: 3 +gd =: : +fnn =: 3 : a +fvv =: * : + +(ar <'gd' ) -: <(,':') +(ar <'fnn') -: <(,':');<ar ;:'n3 a' +(ar <'fvv') -: <(,':');<ar ;:'f g' + +one =: 1 +two =: 2 +adv =: 1 : a=:,:'x/' +conj =: 2 : c=:,:'x&y' +(ar <'adv' ) -: <(,':');<ar ;:'one a' +(ar <'conj') -: <(,':');<ar ;:'two c' + +tv =: 2 : '(ar <''x'') -: <,y' + += tv '=' +< tv '<' +<. tv '<.' +<: tv '<:' +> tv '>' +>. tv '>.' +>: tv '>:' ++ tv '+' ++. tv '+.' ++: tv '+:' +* tv '*' +*. tv '*.' +*: tv '*:' +- tv '-' +-. tv '-.' +-: tv '-:' +% tv '%' +%. tv '%.' +%: tv '%:' +^ tv '^' +^. tv '^.' +$ tv '$' +~. tv '~.' +~: tv '~:' +| tv '|' +|. tv '|.' +|: tv '|:' +, tv ',' +,. tv ',.' +,: tv ',:' +; tv ';' +;: tv ';:' +# tv '#' +#. tv '#.' +#: tv '#:' +/: tv '/:' +\: tv '\:' +[ tv '[' +] tv ']' +{ tv '{' +{. tv '{.' +}. tv '}.' +". tv '".' +": tv '":' +! tv '!' +? tv '?' +[ tv '[' +] tv ']' +A. tv 'A.' +C. tv 'C.' +E. tv 'E.' +e. tv 'e.' +i. tv 'i.' +j. tv 'j.' +o. tv 'o.' +r. tv 'r.' +0: tv '0:' +1: tv '1:' + +f=: ~ +(<,'~') -: ar <'f' +f=: / +(<,'/') -: ar <'f' +f=: /. +(<'/.') -: ar <'f' +f=: \ +(<,'\') -: ar <'f' +f=: \. +(<'\.') -: ar <'f' +f=: } +(<,'}') -: ar <'f' + +f=: ^: +(<'^:') -: ar <'f' +f=: ` +(<,'`') -: ar <'f' +f=: `: +(<'`:') -: ar <'f' +f=: . +(<,'.') -: ar <'f' +f=: :. +(<':.') -: ar <'f' +f=: : +(<,':') -: ar <'f' +f=: ;. +(<';.') -: ar <'f' +f=: @ +(<,'@') -: ar <'f' +f=: " +(<,'"') -: ar <'f' +f=: & +(<,'&') -: ar <'f' +f=: &. +(<'&.') -: ar <'f' +f=: !. +(<'!.') -: ar <'f' + +x=:y=:f=:+/ +-:&ar / ;:'f x' +-:&ar / ;:'f y' + +x=:y=:f=:/ +-:&ar / ;:'f x' +-:&ar / ;:'f y' + +x=:y=:f=:& +-:&ar / ;:'f x' +-:&ar / ;:'f y' + +4!:55 ;:'a adv ar c conj dr f fnn fork fvv g gd hook mtv n3 nar ' +4!:55 ;:'one or over plus tv two x y' + +
new file mode 100644 --- /dev/null +++ b/test/g5x2.ijs @@ -0,0 +1,270 @@ +NB. 5!:2 ---------------------------------------------------------------- + +ar =: 5!:1 +boxed =: 32&=@(3!:0) +oarg =: >@(1&{) + +bxroot =: (<1 0)&C.@,`] @. (e.&(,&.>'0123456789')@[) + +bxx =: {. bxroot bx&.>@oarg +bxgl =: {. bxroot (bxx&.>@{. , bx &.>@}.)@oarg +bxgr =: {. bxroot (bx &.>@{. , bxx&.>@}.)@oarg +bxg =: bxgr`bxgl`bxx @. (i.&(<,'`')@oarg) +bxtil =: bxx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +bxcase =: oarg`bxgl`bxgl`bxg`bxtil`bxx @. ((;:'0@.`:4~')&i.@{.) +bx =: ]`bxcase @. boxed + +brep =: ,@<`[ @. boxed @ bx @ > @ ar + +br =: 5!:2 +test1 =: (br -: brep) " 0 +*./ test1 ;:'ar bx boxed oarg' +*./ test1 ;:'bxroot bxx bxgl bxgr bxg bxtil bxcase bx' + +test =: 1 : '(br -: brep) <''x''' + ++ test ++. test +i. test +0: test +- test + +1 2 3&+ test +,&'abcd' test +(<"0 i.7)&e. test + +(+/ % #) test +(+%) test + ++/ test ++./ test ++./ .* test ++/ .* test ++`*@.< test ++`-`*`:0 test +brep test +bxcase test + +(br -: brep) <'ger' [ ger =: +/`%`# +(br -: brep) <'a' [ a =:<"0 i.7 +(br -: brep) <'a' [ a =: '' + +(br -: brep) <'test' +a =: / +(br -: brep) <'a' +a =: 1 : 'x/\' +(br -: brep) <'a' +inv =: 1 : 'x^:_' +(br -: brep) <'inv' + +c =: & +(br -: brep) <'c' +ip =: 2 : 'x@ (y"(0 _1"1 _))' +(br -: brep) <'ip' + +a =: i.3 4 +(br <'a') -: ,<a +f =: ^ +(br <'f') -: ,<,'^' +f =: /. +(br <'f') -: ,<'/.' +f =: &. +(br <'f') -: ,<'&.' + +plus =: + +or =: +. +hook =: (plus or) f. +fork =: (plus,or) f. +(br <'plus') -: ,<,'+' +(br <'or' ) -: ,<'+.' +(br <'hook') -: ;:'++.' +(br <'fork') -: ;:'+,+.' + +gd =: : +f1 =: 3 : n1 =: 'y+2' +f2 =: 3 : n2 =: ( ':'; 't=.x+y'; 't^2') +f12 =: 3 : n12=: ('y+2'; ':'; 't=.x+y'; 't^2') +fvv =: * : + +(br <'gd' ) -: ;:':' +(br <'f1' ) -: (3;,':'),<,:n1 +(br <'f2' ) -: (3;,':'),<>n2 +(br <'f12') -: (3;,':'),<>n12 +(br <'fvv') -: ;:'* : +' + +adv =: 1 : 'x/f.' +conj =: 2 : 'x&y f.' +(br <'adv' ) -: (1;,':'),<,:'x/f.' +(br <'conj') -: (2;,':'),<,:'x&y f.' + +t=:'i=.0'; 't=.]'; 'while. y>i do.'; 'i=.1+i'; 't=.x@t f.'; 'end.' +pow =: 2 : t +(br <'pow') -: (2;,':'),<>t + +f=:o. pow 0 +r=:,<,']' +(br <'f') -: r + +f=:o. pow 1 +r=:(<'o.'),(<,'@'),r +(br <'f') -: r + +f=:o. pow 2 +r=:(<'o.'),(<,'@'),<r +(br <'f') -: r + +f=:o. pow 3 +r=:(<'o.'),(<,'@'),<r +(br <'f') -: r + +tv =: 2 : '(br <''x'') -: ,<,y' += tv '=' +< tv '<' +<. tv '<.' +<: tv '<:' +> tv '>' +>. tv '>.' +>: tv '>:' +_: tv '_:' ++ tv '+' ++. tv '+.' ++: tv '+:' +* tv '*' +*. tv '*.' +*: tv '*:' +- tv '-' +-. tv '-.' +-: tv '-:' +% tv '%' +%. tv '%.' +%: tv '%:' +^ tv '^' +^. tv '^.' +$ tv '$' +~. tv '~.' +~: tv '~:' +| tv '|' +|. tv '|.' +|: tv '|:' +, tv ',' +,. tv ',.' +,: tv ',:' +; tv ';' +;: tv ';:' +# tv '#' +#. tv '#.' +#: tv '#:' +! tv '!' +/: tv '/:' +\: tv '\:' +[ tv '[' +] tv ']' +{ tv '{' +{. tv '{.' +{: tv '{:' +}. tv '}.' +}: tv '}:' +". tv '".' +": tv '":' +? tv '?' +A. tv 'A.' +C. tv 'C.' +E. tv 'E.' +e. tv 'e.' +i. tv 'i.' +j. tv 'j.' +o. tv 'o.' +p. tv 'p.' +r. tv 'r.' +0: tv '0:' +1: tv '1:' + +f=: ~ +(,<,'~' ) -: br <'f' +f=: / +(,<,'/' ) -: br <'f' +f=: /. +(,<,'/.') -: br <'f' +f=: \ +(,<,'\' ) -: br <'f' +f=: \. +(,<,'\.') -: br <'f' +f=: } +(,<,'}' ) -: br <'f' +f=: b. +(,<,'b.') -: br <'f' +f=: f. +(,<,'f.') -: br <'f' + +f=: ^: +(,<,'^:') -: br <'f' +f=: . +(,<,'.' ) -: br <'f' +f=: .. +(,<,'..') -: br <'f' +f=: .: +(,<,'.:') -: br <'f' +f=: : +(,<,':' ) -: br <'f' +f=: :. +(,<,':.') -: br <'f' +f=: ;. +(,<,';.') -: br <'f' +f=: !. +(,<,'!.') -: br <'f' +f=: !: +(,<,'!:') -: br <'f' +f=: " +(,<,'"' ) -: br <'f' +f=: ` +(,<,'`' ) -: br <'f' +f=: `: +(,<,'`:') -: br <'f' +f=: @ +(,<,'@' ) -: br <'f' +f=: @. +(,<,'@.') -: br <'f' +f=: @: +(,<,'@:') -: br <'f' +f=: & +(,<,'&' ) -: br <'f' +f=: &. +(,<,'&.') -: br <'f' +f=: &: +(,<,'&:') -: br <'f' +f=: &.: +(,<,'&.:') -: br <'f' + + +NB. 5!:2, handling gerunds ---------------------------------------------- + +fx =: 5!:0 +br =: 5!:2 +th =: 3 : ('f=.y fx'; '{.@(]`<@.(1&<@#)) br<''f''') + +g =: [`((e.&' ' # i.@#)@])`] +f =: g} +(br<'f') -: (th"0 g);,'}' +f =: (1{g) fx} +(br<'f') -: (>th 1{g);,'}' + +g =: */\.`(i.@#)`(+/~) +f =: i.^:g +(br<'f') -: 'i.';'^:';<th"0 g +f =: i.^:* +(br<'f') -: ;:'i.^:*' + +g =: ]`(+%) +f =: g`:0 +(br<'f') -: (th"0 g);'`:';0 + +g =: ((%&4@# , 4:) $ ]) ` %: ` $ +f =: g@.* +(br<'f') -: (th"0 g);'@.';,'*' + + +4!:55 ;:'a adv ar boxed br brep bx bxcase bxg ' +4!:55 ;:'bxgl bxgr bxroot bxtil bxx c conj f f1 f12 f2 ' +4!:55 ;:'fork fvv fx g gd ger hook inv ip n1 ' +4!:55 ;:'n12 n2 oarg or plus pow r t test test1 th tv ' + +
new file mode 100644 --- /dev/null +++ b/test/g5x30.ijs @@ -0,0 +1,51 @@ +NB. 5!:30 --------------------------------------------------------------- + +cr =: 13{a. +lf =: 10{a. +crlf=: 13 10{a. + +f =: 5!:30 + +dtb =: -@(+/"1)@(*./\."1)@(' '&=) <@}."_1 ] +g =: ; @: (,&lf&.>) @: dtb @: (1 1&}.) @: (_1 _1&}.) @: ": @: < + +t=: 0 250 _ _ f x=: i.4 5 +t -: ,(":i.4 5),.lf + +t=: 0 250 5 10 f x=: i.300 +t -: (250{.":x),'...',lf + +t=: 0 _ _ _ f x=: ?2 3 4 5 3$1e6 +t -: g x + +t=: 0 250 5 10 f i.40 1 +16 = +/ t=lf +t -: (,' ',.'01234',.lf),'...',lf,,(2":30+i.10 1),.lf + +t=: 0 _ 5 10 f x=: lf (100?2000)}2000$'x' +16 = +/ t=lf +i =: 1 i.~ '...' E. t +t -: (i{.x),'...',lf,(((5+i)-#t){.x),lf + +'domain error' -: 'abc' 5!:30 etx 4 5 6 +'domain error' -: (1 2 3 4.5) 5!:30 etx 4 5 6 +'domain error' -: (1 2 3 4j5) 5!:30 etx 4 5 6 +'domain error' -: (1 2 3 4r5) 5!:30 etx 4 5 6 +'domain error' -: (1;2;3;455) 5!:30 etx 4 5 6 + +'domain error' -: (0 _1 9 9 ) 5!:30 etx 4 5 6 +'domain error' -: (0 9 _1 9 ) 5!:30 etx 4 5 6 +'domain error' -: (0 9 9 _1 ) 5!:30 etx 4 5 6 + +'rank error' -: (1 ) 5!:30 etx 4 5 6 +'rank error' -: (,:1 2 3 4) 5!:30 etx 4 5 6 + +'length error' -: (i.5 ) 5!:30 etx 4 5 6 +'length error' -: (i.3 ) 5!:30 etx 4 5 6 + +'index error' -: (3 10 10 9) 5!:30 etx 4 5 6 + + +4!:55 ;:'cr crlf dtb f g i lf t x' + +
new file mode 100644 --- /dev/null +++ b/test/g5x4.ijs @@ -0,0 +1,133 @@ +NB. 5!:4 ---------------------------------------------------------------- + +ar =: 5!:1 +lr =: 3 : '5!:5 <''y''' +boxed =: 32&= @ (3!:0) +mt =: 0&e.@$ +oarg =: >@(1&{) +shr =: |.!.'' +shl =: 1&(|.!.'') +mat =: (1 1&}.)@(_1 _1&}.)@":@< +boxc =: 9!:6 '' +dash =: 10{boxc + +extent =: (+./\ *. +./\.) @ (' '&~:) @: ({."1) +limb1 =: 1&|.@$ 1&~: }. (10 6 0{boxc)&,@($&(9{boxc)) +limb =: -@(i.&1)@[ |. #@[ {. limb1@] +pfx =: (limb +/)@extent ,. ] +pad =: [ {. ] ,. dash&=@({:"1)@] { ' '&,:@($&dash)@(-&{: $) +take =: pad`($&' '@[) @. (mt@]) +rc =: #@>@{."1 ; >./@:({:@$@>) +kernt =: (0{boxc)&=@shl@[ *. ' '&~:@] +kernb =: (6{boxc)&=@] *. ' '&~:@shl@[ +kern =: (<0 0)&{&>"2 (kernt +./"1@:+. kernb) (<_1 0)&{&>"2 +gap =: ,&.>"_1 {&((0 1$' ');1 1$' ')@kern +graft =: (pfx&.>@{. 0} ]) @ (,&.>/) @ gap @ ({@rc take&.> ]) + +lab =: ,: @ (2&|.) @ ((' ',dash,dash,' ')&,) +label =: lab`((,.dash)&[) @. (e.&'0123456789'@{.) +center =: ((i.&1) -@+ <.@-:@(+/))@] |. #@] {. [ +root =: label@[ center extent@>@{.@] + +leaf =: ,@<@(((,:dash,' ')&[ center $&1@#) ,. ])@mat@": + +trx =: >@{. (root ; ]) graft@:(tr@>)@oarg +trgl =: >@{. (root ; ]) graft@:(trx@>@{. , tr @>@}.)@oarg +trgr =: >@{. (root ; ]) graft@:(tr @>@{. , trx@>@}.)@oarg +trg =: trgr`trgl`trx @. (i.&(<,'`')@oarg) +trtil =: trx`(leaf@oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +trnoun =: leaf @ lr @ oarg +trcase =: trnoun`trgl`trgl`trg`trtil`trx @. ((;:'0@.`:4~')&i.@{.) +tr =: leaf`trcase @. boxed + +rep =: 2 : 'x & ((# i.@#)@,@y@]})' +right =: (5{boxc) rep (e.&(9{boxc) *. shr"1@(e.&dash)) +cross =: (4{boxc) rep (e.&(5{boxc) *. shl"1@(e.&dash)) +left =: (3{boxc) rep (e.&(9{boxc) *. shl"1@(e.&dash)) +bot =: (7{boxc) rep (e.&(6{boxc) *. shr"1@(e.&dash)) +connect =: bot @ left @ cross @ right + +tree =: connect @ > @ (,.&.>/) @ ('0'&root ; ]) @ (tr@>@ar) + + +jtr =: 5!:4 +test=: 1 : '(jtr -: tree) <''x''' + ++ test ++. test +i. test +0: test +- test + +1 2 3&+ test ++&(i.10 2) test ++&(i.11 1) test +,&'abcd' test +(<"0 i.7)&e. test + ++/ % # test ++ % test + ++/ test ++./ test ++./ .* test ++/ .* test ++`*@.< test +NB. +`-`*`:0 test + +(+/`%`#) test +(<"0 i.7) test +'' test +(i.10 1) test +(i.11 1) test + +(jtr -: tree)"0 ;:'ar lr boxed mt oarg shr shl mat' NB. ,' boxc dash' +(jtr -: tree)"0 ;:'extent limb1 limb pfx pad take rc' +(jtr -: tree)"0 ;:'kernt kernb kern gap graft' +(jtr -: tree)"0 ;:'lab label center root leaf' +(jtr -: tree)"0 ;:'trx trgl trgr trg trtil trnoun trcase tr' +(jtr -: tree)"0 ;:'rep right cross left bot connect tree' + +a =. / +(jtr -: tree) <'a' +a =. 1 : 'x/\' +(jtr -: tree) <'a' +inv =. 1 : 'x^: _' +(jtr -: tree) <'inv' + +c =. & +(jtr -: tree) <'c' +ip =. 2 : 'x @ (y"1 _)' +(jtr -: tree) <'ip' + + +NB. 5!:4, handling gerunds ---------------------------------------------- + +fx =. 5!:0 +jtr =. 5!:4 +th =. 3 : ('f=.y fx'; '{.@(]`<@.(1&<@#)) jtr<''f''') + +g =.[`((e.&' ' # i.@#)@])`] +f =. g} +h =. g`:6} +(jtr<'f') -: jtr <'h' + +g =. */\.`(i.@#)`(+/~) +f =. i.^:g +h =. i.^:(g`:6) +(jtr<'f') -: jtr <'h' + +g =. ((%&4@# , 4:) $ ]) ` %: ` $ +f =. g@.* +h =. g`:6@* +(0 5}.jtr<'f') -: 0 4}.jtr<'h' + + +4!:55 ;:'a ar bot boxc boxed c center connect cross dash ' +4!:55 ;:'extent f fx g gap ger graft h inv ip ' +4!:55 ;:'jtr kern kernb kernt lab label leaf left limb limb1 ' +4!:55 ;:'lr mat mt oarg pad pfx rc rep right root ' +4!:55 ;:'shl shr take test th tr trcase tree trg trgl trgr ' +4!:55 ;:'trnoun trtil trx ' + +
new file mode 100644 --- /dev/null +++ b/test/g5x5.ijs @@ -0,0 +1,520 @@ +NB. 5!:5 ---------------------------------------------------------------- + +ar=: 5!:1 + +test1=: 1 : 0 + 0!:10 'asdf=.',5!:5 <'x' + assert. (ar <'x') -: ar <'asdf' + 1 +) + +test2=: 3 : 0 + 0!:10 'asdf=.',5!:5 y + assert. (ar y) -: ar <'asdf' +) + + +NB. 5!:5 nouns ---------------------------------------------------------- + +test=: [ -: ".@(3 : '5!:5<''y''') + +test '' +test 0 1$'' +test 1 0$'' +test 0 3 4$'abc' +test 4 3 2 4 9 0 3 4$'Cogito, ergo sum.' +test 'j' +test ,'j' +test 5$'j' +test 13$'j' +test '''' +test ,'''' +test 5$'''' +test 6$'''' +test 23$'''' +test 24$'''' +test 'sui generis' +test 'Don''t tread on me!' +test 1 1$'j' +test 1 3$'row' +test 6 1$'column' +test 2 3$'j' +test 1 13$'j' +test 13 1$'j' +test 6 12$'j' +test 2 3$'''' +test 1 13$'''' +test 13 1$'''' +test 6 13$'''' +test 3 7$'Opposable thumbs' +test 6 13$'Don''t tread on me!' +test 2 3 4$'j' +test 2 3 4$'''' +test 2 3 4$'Don''t tread on me!' +test (?2 3 4 5$#a.){a. +test 'abc', a. +test 'abc',~a. +test (0 {a.), a. +test (0 {a.),~a. +test (0 1{a.), a. +test (0 1{a.),~a. +test (0 4{a.), a. +test (0 4{a.),~a. +test (_1 {a.), a. +test (_1 {a.),~a. +test (_2 _1{a.), a. +test (_2 _1{a.),~a. +test (_4 _1{a.), a. +test (_4 _1{a.),~a. +test '_' (a.i.' ')}a. +test (a.{~(i.26)+a.i.'a') ((i.26)+a.i.'A')}a. +test |.a. +test a.{~?#a. + +test 0 +test i.0 +test i.1 0 +test i.0 1 +test i.0 3 4 0 +test 3j4 +test ,_123 +test _123 2 3 4 +test 0 _1.2e_3j_4.5e_6 7 8 9 0 _8 +test 5$183164 +test 13$183164 +test x=:?13$183164 +test x=:?2 3$183164 +test x=:?1 1$183164 +test x=:?1 7$183164 +test x=:?7 1$183164 +test x=:o.i.3 4 +test x=:o.>:i.-4 5 +test x=:r.?2 3 4$10 +test j.i.4 5 +test r.i.8 +test i.3 4 +test 5+i.3 4 +test 5+2*i.3 4 +test 5+_1*i.3 4 +test i.-3 4 +test 10$_ +test 4 5$__ +test 4 5$_ 0 __ + +test 0$<'' +test 0 1$<'abc' +test 1 0$<'abc' +test 0 3 4 5 0$<'abc' +test <'' +test a: +test <'j' +test <,'j' +test ,<'foobar' +test ;:'Cogito, ergo sum.' +test '' ;;:'sui generis' +test 'f';;:'sui generis' +test ,&.>'f';;:'sui generis' +test 'Opposable';'thumbs' +test 'Opposable';'thumbs ' +test 2 3$'foobar';?2 3$183164 +test 'abcd';5$233{a. +test <0;'abcd' +test <(,0);'abcd' +test 5!:1<'test' +test 5!:2<'test' +test 5!:4<'test' +test 5!:5<'test' + +'a:' -: 5!:5 <'t' [ t=:a: + + +NB. 5!:5 empty arrays --------------------------------------------------- + +test=: 3 : '((3!:0 x) -: 3!:0 y) *. x -: y [ x=. ".5!:5 <''y''' + +test 0$0 +test 0$'abc' +test 0$3 4 +test 0$3.4 +test 0$3j4 +NB. test 0$3r4 +test 0$34x +test 0$3r4 +test 0$3;4 +test 0$s: ' a b cd' +test 0$u: ' a b cd' + +test s$0 [ s=: 0 (?#s)}s=: ?10$5 +test s$'abc' [ s=: 0 (?#s)}s=: ?10$5 +test s$3 4 [ s=: 0 (?#s)}s=: ?10$5 +test s$3.4 [ s=: 0 (?#s)}s=: ?10$5 +test s$3j4 [ s=: 0 (?#s)}s=: ?10$5 +NB. test s$3r4 [ s=: 0 (?#s)}s=: ?10$5 +test s$34x [ s=: 0 (?#s)}s=: ?10$5 +test s$3;4 [ s=: 0 (?#s)}s=: ?10$5 +test s$s: ' a b cd' [ s=: 0 (?#s)}s=: ?10$5 +test s$u: ' a b cd' [ s=: 0 (?#s)}s=: ?10$5 + + +NB. 5!:5 ---------------------------------------------------------------- + ++ test1 ++. test1 ++: test1 +j. test1 +0: test1 +f test1 ++/ test1 ++./ test1 ++/ .* test1 +3&$ test1 +,&(3 4$'asdf') test1 +3&$ @ (,&(3 4$'asdf')) test1 +3&$ @ ,&(3 4$'asdf') test1 +3 : 'foo y' test1 +3 : (':'; 'x bar y') test1 +3 : ('foo y'; ':'; 'x bar y') test1 +3 : (97 9 98{a.) test1 ++/ : (- * %) test1 +1 H. 1 test1 +*: (2 : 'u"n y') (1;2;3) test1 +(4;5;6) (2 : 'u"n y') *: test1 +(4;5;6) (2 : 'u"n y') (1;2;3) test1 + +(3x (2&+) ]) test1 +(1 2 3x (2&+) ]) test1 +(-&3x (2&+) ]) test1 + +f =:+ +g =:- +f3=:$ +(+ %) test1 +(+&(3) 4&*) test1 +(f g) test1 +(f3 g) test1 +(+(*#)) test1 +(+(*#-)) test1 +((+-) (*%)) test1 +((+-) (*%#))test1 +(+-)/ test1 +((+-*)%) test1 +((+-*)#) test1 + +f=:+ +g=:- +h=:$ +(+-* ) test1 +((+&3) 4&- * ) test1 +(+ (-&4) 5&* ) test1 +(f g % ) test1 +(% f g ) test1 +(f g h ) test1 +(f g h f ) test1 +(f g h f g ) test1 +(f g h f g h ) test1 +((f g h) f g ) test1 +((f g ) f g ) test1 +((f g h) f g h ) test1 +((f g ) f g h ) test1 +((+-*) % # ) test1 +((+ *) % # ) test1 +(+ (-#*) % ) test1 +(+ (- *) % ) test1 +(+ - (*%#) ) test1 +(+ - (* #) ) test1 +((+=-) (*,%) ($;#)) test1 +((+ -) (* %) ($ #)) test1 + +(+`-`*@.i. ) test1 +(+/`(-&.+)`(%/\.)@.(i.@]) ) test1 +((+%)`(-&.+)`(%/\.)@.(i.@]) ) test1 +((+-*)`(-&.+)`(%/\.)@.(i.@])) test1 + +a=: / +test2 <'a' +a=: /. +test2 <'a' + +c=: . +test2 <'c' +c=: : +test2 <'c' +c=: .. +test2 <'c' +c=: .: +test2 <'c' +c=: &. +test2 <'c' + +a=: `] +test2 <'a' +a=: `(+/ .* ) +test2 <'a' +a=: `(+/%#) +test2 <'a' +a=: `(+/`%`#) +test2 <'a' +a=: *` +test2 <'a' +a=: +/ .*` +test2 <'a' +a=: (+/%#)` +test2 <'a' +a=: +/`%`#` +test2 <'a' +a=: (+% )`$`#` +test2 <'a' +a=: (+-*)`$`#` +test2 <'a' +a=: +/`%`#@. +test2 <'a' +a=: (+% )`*`#@. +test2 <'a' +a=: (+-*)`$`#@. +test2 <'a' +a=: +/`%`#`:0 +test2 <'a' +a=: (+% )`%`#`:0 +test2 <'a' +a=: (+%-)`%`#`:0 +test2 <'a' +a=: : - +test2 <'a' +a=: - : +test2 <'a' +a=: (+-)@ +test2 <'a' +a=: (+-*)@ +test2 <'a' + +f=:& +g=:* +a=: f g +test2 <'a' +a=: g f +test2 <'a' +a=: @.(+/%#) +test2 <'a' +a=: `:0 +test2 <'a' + +f=:g=:h=:/ +a=: f g +test2 <'a' +a=: f g h +test2 <'a' +a=: f g h f +test2 <'a' +a=: f g h f g +test2 <'a' +a=: f g h (f g) +test2 <'a' +a=: f g (f g) +test2 <'a' +a=: f g h (f g h) +test2 <'a' +a=: f g (f g h) +test2 <'a' +a=: /\.(&+)("1) +test2 <'a' +a=: (/\.)(+&)("1 _) + +c=: 2 : '%&y@(+&y -&x ])' +test2 <'c' + +test2 <'test1' +test2 <'test2' + + +NB. 5!:5 on "real" examples --------------------------------------------- + +ar =: 5!:1 +boxed =: 32&= @ type +oarg =: >@(1&{) +mtv =: i.@0: +paren =: ('('&,)@(,&')') +symb =: $&' '@(e.&'.:')@{. , ] +quote =: '''' +alp =: (,65 97+/i.26){a. +dig =: '0123456789' + +slist =: $&','@(1&=) +shape =: mtv`slist`(,&'$'@":)@.(2&<.@#)`('i.'&,@":) @. (0&e.) @ $ +vchar =: >:@(quote&=)@, quote&,@(,"e)@# , +vbox =: }. @ ; @: (','&,@paren@('<'&,)@lnoun&.>) +value =: vchar`vbox`(":!.18@,) @. (2 32&i.@(type * *@(*/)@$)) +lnoun =: shape , value + +dotco =: 2&=@# *. e.&'.:'@{: +name =: e.&alp@{. *. *./@(e.&(alp,dig,'_'))@}: *. e.&(alp,dig,'_.:')@{: +num =: e.&(dig,'_')@{. *. *./@(e.&(dig,'_ .ejdr')) +qstr =: mtv -: -.@(~:/\)@(e."e) -."e@# ] +pstr =: -.@(0&e.)@}:@(+/\)@({&1 _1 0)@('()'&i.) +nopar =: 1&=@# +. dotco +. name +. num +. qstr +. pstr +cp =: paren`] @. nopar + +bp =: ]`cp@.(' '&e.) +hfork =: }.@;@:(' '&,@bp&.>)@] +left =: bp@>@{. +right =: mtv`(cp@>@{:)@.(1&<@#) +ins =: left@] , symb@>@[ , right@] +act =: ;@:(cp&.>)@] +insert =: hfork`hfork`act`act`act`ins @. ('23456'&i.@{.@>@[) + +lx =: {. insert lr&.>@oarg +ltie =: lr`(}.@;@:('`'&,@cp@lr&.>)@oarg) @. ((<,'0')&=@{.) +lgl =: {. insert (ltie&.>@{. , lr &.>@}.)@oarg +lgr =: {. insert (lr &.>@{. , ltie&.>@}.)@oarg +lg =: lgr`lgl`lx @. (i.&(<,'`')@oarg) +ltil =: lx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +lcase =: (cp@lnoun@oarg)`lgl`lgl`lg`ltil`lx @. ((;:'0@.`:4~')&i.@{.) +lr =: symb`lcase@.boxed + +lrep =: lr @ > @ ar + +test2"0 ;:'ar boxed oarg mtv paren symb quote alp dig' +test2"0 ;:'slist shape vchar vbox value lnoun' +test2"0 ;:'dotco name num qstr pstr nopar cp' +test2"0 ;:'bp hfork left right ins act insert' +test2"0 ;:'lx ltie lgl lgr lg ltil lcase lr lrep' + +ar =: 5!:1 +boxed =: 32&= @ type +mt =: 0&e.@$ +oarg =: >@(1&{) +shr =: |.!.'' +shl =: 1&(|.!.'') +mat =: (1 1&}.)@(_1 _1&}.)@":@< +boxc =: 9!:6 '' +dash =: 10{boxc + +extent =: (+./\ *. +./\.) @ (' '&~:) @: ({."1) +limb1 =: 1&|.@$ 1&~: }. (10 6 0{boxc)&,@($&(9{boxc)) +limb =: -@(i.&1)@[ |. #@[ {. limb1@] +pfx =: (limb +/)@extent ,. ] +pad =: [ {. ] ,. dash&=@({:"1)@] { ' '&,:@($&dash)@(-&{: $) +take =: pad`($&' '@[) @. (mt@]) +rc =: #@>@{."1 ; >./@:({:@$@>) +kernt =: (0{boxc)&=@shl@[ *. ' '&~:@] +kernb =: (6{boxc)&=@] *. ' '&~:@shl@[ +kern =: (<0 0)&{&>"2 (kernt +./"1@:+. kernb) (<_1 0)&{&>"2 +gap =: ,&.>"_1 {&((0 1$' ');1 1$' ')@kern +graft =: (pfx&.>@{. 0} ]) @ (,&.>/) @ gap @ ({@rc take&.> ]) + +lab =: ,: @ (2&|.) @ ((' ',dash,dash,' ')&,) +label =: lab`((,.dash)&[) @. (e.&'0123456789'@{.) +center =: ((i.&1) -@+ <.@-:@(+/))@] |. #@] {. [ +root =: label@[ center extent@>@{.@] + +leaf =: ,@<@(((,:dash,' ')&[ center $&1@#) ,. ])@mat@": + +trx =: >@{. (root ; ]) graft@:(tr@>)@oarg +trgl =: >@{. (root ; ]) graft@:(trx@>@{. , tr @>@}.)@oarg +trgr =: >@{. (root ; ]) graft@:(tr @>@{. , trx@>@}.)@oarg +trg =: trgr`trgl`trx @. (i.&(<,'`')@oarg) +trtil =: trx`(leaf@oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg) +trcase =: (leaf@oarg)`trgl`trgl`trg`trtil`trx @. ((;:'0@.`:4~')&i.@{.) +tr =: leaf`trcase @. boxed + +rep =: 2 : 'x & (((# i.@#)@,@y@])})' +right =: (5{boxc) rep (e.&(9{boxc) *. shr"1@(e.&dash)) +cross =: (4{boxc) rep (e.&(5{boxc) *. shl"1@(e.&dash)) +left =: (3{boxc) rep (e.&(9{boxc) *. shl"1@(e.&dash)) +bot =: (7{boxc) rep (e.&(6{boxc) *. shr"1@(e.&dash)) +connect =: bot @ left @ cross @ right + +tree =: connect @ > @ (,.&.>/) @ (> (root ; ]) tr@>@ar) + +test2"0 ;:'ar boxed mt oarg shr shl mat boxc dash' +test2"0 ;:'extent limb1 limb pfx pad take rc kernt kernb kern gap graft' +test2"0 ;:'lab label center root leaf' +test2"0 ;:'trx trgl trgr trg trtil trcase tr' +test2"0 ;:'rep right cross left bot connect tree' + +en =: #@] +em =: (en >.@% -@[)`(en 0&>.@>:@- [) @. (0&<:@[) +kay =: en`em @. (0&<@[) +omask =: (em,en) $ ($&0@|@[ , $&1@kay) + +base =: 1&>.@-@[ * i.@em +iind =: base ,. |@[ <. en - base +seg =: ((+i.)/@[ { ])"1 _ + +infix =: 1 : '(iind x@seg ])"0 _' +outfix =: 1 : '(omask x@# ])"0 _' +prefix =: 1 : '>:@,.@i.@# x@{. ]' +suffix =: 1 : ',.@i.@# x@}. ]' + +key =: 1 : '=@[ x@# ]' + +osub =: >@]`(>@[ >@:{ ]) @. (*@#@]) +oind =: (+/&i./ </.&, i.)@(2&{.)@(,&1 1)@$ +ob =: 1 : 'oind x@osub"0 1 ,@(<"_2)' + +bs =: 1 : '(x prefix) : (x infix )' +bsd =: 1 : '(x suffix) : (x outfix)' +sd =: 1 : '(x ob ) : (x key )' + +test2"0 ;:'en em kay omask' +test2"0 ;:'base iind seg' +test2"0 ;:'infix outfix prefix suffix' +test2"0 ;:'key osub oind ob' +test2"0 ;:'bs bsd sd' + + +NB. 5!:5, handling gerunds ---------------------------------------------- + +fx =: 5!:0 +lr =: 5!:5 + +g =:[`((e.&' ' # i.@#)@])`] +f =: g} +(lr<'f') -: '[`((e.&'' '' # i.@#)@])`]}' +f =: (1{g) fx} +(lr<'f') -: '(e.&'' '' # i.@#)@]}' + +g =: */\.`(i.@#)`(+/~) +f =: i.^:g +(lr<'f') -: 'i.^:(*/\.`(i.@#)`(+/~))' +f =: ^:g +(lr<'f') -: '^:(*/\.`(i.@#)`(+/~))' +f =: +/\^: +(lr<'f') -: '+/\^:' +f =: i.^:* +(lr<'f') -: 'i.^:*' + +g =: */\.`(+/ % #)`] +f =: `g +(lr<'f') -: '`(*/\.`(+/ % #)`])' +f =: g` +(lr<'f') -: '*/\.`(+/ % #)`]`' + +g =: ]`(+%) +f =: g `:0 +(lr<'f') -: ']`(+ %)`:0' +f =: g`: +(lr<'f') -: ']`(+ %)`:' +f =: `:0 +(lr<'f') -: '`:0' + +g =: ((%&4@# , 4:) $ ]) ` %: ` $ +f =: g@.* +(lr<'f') -: '((%&4@# , 4:) $ ])`%:`$@.*' +f =: g@. +(lr<'f') -: '((%&4@# , 4:) $ ])`%:`$@.' +f =: @.('abc'&i.) +(lr<'f') -: '@.(''abc''&i.)' + +4!:55 ;:'a act alp ar base bot boxc boxed bp bs ' +4!:55 ;:'bsd c center connect cp cross dash dig dotco em ' +4!:55 ;:'en extent f f3 fx g gap graft h hfork ' +4!:55 ;:'id iind infix ins insert kay kern kernb kernt key ' +4!:55 ;:'lab label lcase leaf left lg lgl lgr limb limb1 ' +4!:55 ;:'lnoun lr lrep ltie ltil lx mat mt mtv name ' +4!:55 ;:'nopar num oarg ob oind omask osub outfix pad paren ' +4!:55 ;:'pfx prefix pstr qstr quote rc rep right root ' +4!:55 ;:'s sd seg shape shl shr slist suffix symb ' +4!:55 ;:'t take test test1 test2 tr trcase tree trg trgl trgr trtil trx ' +4!:55 ;:'value vbox vchar x ' + +
new file mode 100644 --- /dev/null +++ b/test/g5x6.ijs @@ -0,0 +1,17 @@ +NB. 5!:6 ---------------------------------------------------------------- + +lr=: 5!:5 +pr=: 5!:6 + +sumsq=: +/ @: *: +xtx =: |: ((+/) .*) ] + +'+/@:*:' -: lr <'sumsq' +'(+/)@:*:' -: pr <'sumsq' + +'|: +/ .* ]' -: lr <'xtx' +'|: ((+/) .*) ]' -: pr <'xtx' + +4!:55 ;:'lr pr sumsq xtx' + +
new file mode 100644 --- /dev/null +++ b/test/g5x7.ijs @@ -0,0 +1,171 @@ +NB. 5!:7 ---------------------------------------------------------------- + +xr=: 5!:7 + +ww=: ;:'bblock. tblock. do. if. else.' +ww=: ww, ;:'end. while. whilst. elseif. try.' +ww=: ww, ;:' catch. break. continue. label. goto.' +ww=: ww, ;:' return. for. do. break. select.' +ww=: ww, ;:' case. fcase. do. end. assert. throw. catchd. catcht.' + +chk=: 4 : 0 + assert. 32 = type y + assert. 2 = #$y + assert. x =&* {.$y + assert. 3 = {:$y + assert. ({."1 y) -: <"0 i.#y + c=. 1{"1 y + t=. 2{"1 y + assert. 4 = type&> c + assert. (<,3) = $&.> c + assert. 2 = type&> t + assert. 1 = #@$&> t + i=. {.&>c + assert. i e. 1+i.#ww + p=. ((<'for_')=4{.&.>t) +. ((<'goto_')=5{.&.>t) +. (<'label_')=6{.&.>t + assert. (i e. 1 2) ~: (((1+t i.&> '.'){.&.> t) e. 2}.ww) +. p + assert. (1{&>c) e. 65534 65535,i.1+#c + assert. (2{&>c) e. i.#c + 1 +) + +mean=: +/ % # + +0 chk 1 xr <'mean' +0 chk 2 xr <'mean' + +0 chk 1 xr <'chk' +1 chk 2 xr <'chk' + +perm=: 3 : 0 + z=. i.1 0 + for. i.y do. z=.,/(0,.1+z){"2 1\:"1=i.>:{:$z end. +) + +1 chk 1 xr <'perm' +0 chk 2 xr <'perm' + +f1 =. 3 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. 'true' return. + label_false. 'false' return. +) + +1 chk 1 xr <'f1' +0 chk 2 xr <'f1' + +f2=: 3 : 0 + 3 f2 y + : + select. + if. y do. 1 else. 0 end. + fcase. 0 do. + 'zero' + case. 1 do. + 'one' + end. +) + +1 chk 1 xr <'f2' +1 chk 2 xr <'f2' + +f3=: 4 : 0 + while. + if. y do. 1 + elseif. 2 do. 3 end. + do. + 4 + try. 5 catch. 6 end. + end. +) + +0 chk 1 xr <'f3' +1 chk 2 xr <'f3' + +f4=: 3 : 0 + 0 + if. y + do. + for. 1 do. 2 end. + for_xyzabc. i.12 do. >:xyzabc end. + else. + whilst. 3 do. 4 end. + end. +) + +1 chk 1 xr <'f4' +0 chk 2 xr <'f4' + +f5=: (3 : '*:y') : (4 : 'x*y') + +0 chk 1 xr <'f5' +0 chk 2 xr <'f5' + +c1=: 2 : 0 + if. ?2 do. + x&y + else. + x@y + end. +) + +0 chk 1 xr <'c1' +1 chk 2 xr <'c1' + +a1=: 1 : 0 + if. ?2 do. + x/\ + else. + x/\. + end. +) + +1 chk 1 xr <'a1' +0 chk 2 xr <'a1' + +c2=: 2 : 0 + 'monad' + u^:n y + : + 'dyad' + x u^:n y +) + +1 chk 1 xr <'c2' +1 chk 2 xr <'c2' + +a2=: 2 : 0 + 'monad' + u/ y + : + 'dyad' + x u/ y +) + +1 chk 1 xr <'a2' +1 chk 2 xr <'a2' + +a3=: /\ +0 chk 1 xr <'a3' +0 chk 2 xr <'a3' + +'domain error' -: 2 (5!:7) etx 0 1 0 +'domain error' -: 2 (5!:7) etx 0 1 2 +'domain error' -: 2 (5!:7) etx 0 1.2 +'domain error' -: 2 (5!:7) etx 0 1j2 +'domain error' -: 2 (5!:7) etx 0 1r2 +'domain error' -: 2 (5!:7) etx 'a2' + +'domain error' -: 0 (5!:7) etx <'a2' +'domain error' -: 3 (5!:7) etx <'a2' +'domain error' -: (<2) (5!:7) etx <'a2' + +'domain error' -: 5!:7 etx <'foo' +'domain error' -: 1 (5!:7) etx <'ww' + +'value error' -: 2 (5!:7) etx <'nonexistentverb' + + +4!:55 ;:'a1 a2 a3 c1 c2 chk f1 f2 f3 f4 f5 mean perm ww xr' + +
new file mode 100644 --- /dev/null +++ b/test/g600.ijs @@ -0,0 +1,472 @@ +NB. " ------------------------------------------------------------------- + +a =. ?(1+?(1+?5)#4)$100 +b =. ?(($a),1+?(1+?3)#4)$100 +c =. a.{~?(1+?(1+?3)#4)$#a. + +(b+a) -: a +"(-#$a) b +(a+b) -: a +"(-#$a) b +(a+b) -: a +"0 b +(a+b) -: b + (<(#$a)}.$b)$&><"0 a + +($c,"0 'x') -: ($c),2 +($c,"1 0 'x') -: ($c)+(-$$c){.1 +( c,"1 'x') -: c,"1 0 'x' +($c,"1 'xyz') -: ($c)+(-$$c){.3 +($c,"1 'xyz') -: $c,"(#"1) 'xyz' + +(#a) = $<"_1 a +(#b) = $<"_1 b +(#c) = $<"_1 c + +'xyz' -: 'xyz'"99 b +'xyz' -: 'xyz'"_ b +'xyz' -: 'xyz'"# b +(((#b),3)$'xyz') -: 'xyz'"_1 b +((($b),3)$'xyz') -: 'xyz'"0 b + +'xyz' -: a 'xyz'"99 b +'xyz' -: a 'xyz'"_ b +((($a),3)$'xyz') -: a 'xyz'"0 _ b +(((#a),3)$'xyz') -: a 'xyz'"_1 _ b +(((}:$b),3)$'xyz') -: a 'xyz'"1 b + +dr =: 5!:2 +rk =: 1 : ('f=. +"x'; '>2{dr<''f''') + +0 0 0 -: + rk +2 _ 2 -: %. rk +_ 1 _ -: $ rk +1 2 3 -: +"1 2 3 rk +3 3 3 -: +"3 rk +3 2 3 -: +"2 3 rk +_ _ _ -: +"1e20 1e30 1e40 rk + +1 -: 1:"0 '1' +1 -: + "0 [1 +1 -: "."0 '1' + +f=: f +(0:"0 -: 0: :. f"0) i.0 +(0:"0 -: 0: :. f"0)~ i.0 + +'domain error' -: o."0 etx 'abc' +'domain error' -: 2 3 4 o."0 etx 'abc' +'domain error' -: (3 : ' o. y')"0 etx 'abc' +'domain error' -: 2 3 4 (4 : 'x o. y')"0 etx 'abc' + +'domain error' -: ex '+"''abc'' ' +'domain error' -: ex '+"(<4) ' +'domain error' -: ex '+"3j4 ' +'domain error' -: ex '+"1.2 ' +'rank error' -: ex '+"(i.2 3) ' +'length error' -: ex '+"(i.4) ' +'length error' -: ex '+" '''' ' + + +NB. f"r on non-uniform f, on f with side effects ------------------------ + +f=: 3 : 0 + glob=: y + 1 +) + +f"1 x=: ?10 5$1e6 +glob -: {:x + +f"0 x=: <"1 ?10 5$1e6 +glob -: {:x + +f=: (>/ * ,&# $ ]) i.@(>./) +(i."0 -: f) x=:?10$20 + +f=: 3 : 0 + t=: 1+t + if. mm>t do. +:y else. y*2.5-0.5 end. +) + +y=: ?41 5$2e6 +(t = */$y) , (+:y) -: f"0 y [ t=: 0 [ mm=: ?*/$y +(t = #y) , (+:y) -: f"1 y [ t=: 0 [ mm=: ? #y + +f=: 4 : 0 + t=: 1+t + if. mm>t do. x+y else. x+y+-~1p1 end. +) + +x=: ?41 5$2e6 +y=: ?41 5$2e6 +(t = */$x) , (x + y) -: x f"0 y [ t=: 0 [ mm=: ?*/$x +(t = */$x) , (x +"0 1 y) -: x f"0 1 y [ t=: 0 [ mm=: ?*/$x +(t = */$x) , (x +"1 0 y) -: x f"1 0 y [ t=: 0 [ mm=: ?*/$x +(t = */$x) , (x +"1 0 y) -: x f"1 0 y [ t=: 0 [ mm=: ?*/$x +(t = #x) , (x +"1 y) -: x f"1 y [ t=: 0 [ mm=: ? #x + +f=: 3 : 'if. 2|{.y do. y else. 10+y end.' +(f"0 x) -: x+10*0=2| x=: ?41 5$10 +(f"1 x) -: x+10*0=2|{."1 x +(f"0 x) -: x+10*0=2| x=: ?41 5$10 +(f"1 x) -: x+10*0=2|{."1 x +(f"0 x) -: x+10*0=2| x=: ?41 5$10 +(f"1 x) -: x+10*0=2|{."1 x + +x=: ?41 5$2e6 +f=: 3 : ('t=: t,<y'; 'y') +(t -: <"0 ,x) , x -: f"0 x [ t=: '' +(t -: <"1 x) , x -: f"1 x [ t=: '' + +f=: 3 : 0 + t=: t,<y + if. mm>#t do. y else. y+-~1p1 end. +) + +(t -: <"0 ,x) , x -: f"0 x [ t=: '' [ mm=: ?*/$x +(t -: <"1 x) , x -: f"1 x [ t=: '' [ mm=: ? #x + +x=: ?41 5$2e6 +y=: ?41 5$2e6 +f=: 4 : ('t=: t,<x;y'; 'x') + +(t -: , x <@;"0 y) , x -: x f"0 y [ t=: '' +(t -: , x <@;"0 1 y) , x -: x f"0 1 y [ t=: '' +(t -: , x <@;"1 0 y) , (5 5$"1 x) -: x f"1 0 y [ t=: '' +(t -: , x <@;"1 y) , x -: x f"1 y [ t=: '' + +x=: ?41 5$2e6 +y=: ?41 5$2e6 +f=: 4 : 0 + t=: t,<x;y + if. mm>#t do. x else. x+-~1p1 end. +) + +(t -: , x <@;"0 y) , x -: x f"0 y [ t=: '' [ mm=: ?*/$x +(t -: , x <@;"0 1 y) , x -: x f"0 1 y [ t=: '' [ mm=: ?*/$x +(t -: , x <@;"1 0 y) , (5 5$"1 x) -: x f"1 0 y [ t=: '' [ mm=: ?*/$x +(t -: , x <@;"1 y) , x -: x f"1 y [ t=: '' [ mm=: ? #x + + +NB. f"r zero frames ----------------------------------------------------- + +(0 7 3 4$0) -: 3 4&$ "1 i.0 7 9 +(0 7 3 4$0) -: (3 : '3 4$y')"1 i.0 7 9 + +(0 7 $0) -: 2 3&+"_ "1 i.0 7 9 +(0 7 $0) -: (3 : '2 3+y')"1 i.0 7 9 + +(5 0 3$0) -: (i.5) (+3&$) "0 1 i.5 0 7 +(5 0 3$0) -: (i.5) (4 : 'x+3$y')"0 1 i.5 0 7 + +(5 0$0) -: 'abcde' (+3&$) "0 1 i.5 0 7 +(5 0$0) -: 'abcde' (4 : 'x+3$y')"0 1 i.5 0 7 + + +NB. model of f"r -------------------------------------------------------- + +rk =: #@$ +er =: (0:>.(+rk))`(<.rk) @. (0:<:[) +fr =: -@er }. $@] +cs =: -@er {. $@] +boxr =: ]`(<@$ , [ $: */@[}.])@.(*@#@]) +cells =: fr $ cs boxr ,@] + +pfx =: <.&rk +agree =: (pfx {. $@[) -: (pfx {. $@]) +frame =: [:`($@([^:(>&rk))) @. agree +rag =: frame $ ([: */ rk@]}.$@[) # ,@] +lag =: rag~ + +mrk =: >./@:(rk&>)@, +crank =: mrk ,:@]^:(-rk)&.> ] +msh =: >./@:( $&>)@, +cshape=: <@msh {.&.> ] +asm =: > @ cshape @ crank + +rank =: 2 : 0 + 'mm ll rr'=.3&$&.|.y + ([: asm [: x&.> mm&cells) : ([: asm ll&cells@[ (lag x&.> rag) rr&cells@]) +) + +x=: ?2 3$1e6 +y=: a.{~?2 3 4$#a. + +(<" 1 -: < rank 1) y +(<"_1 -: < rank _1) y + +x (;" 1 -: ; rank 1) y +x (;"_1 -: ; rank _1) y + +x (;"1 2 -: ; rank 1 2) y + + +NB. " on atomic verbs --------------------------------------------------- + +(a="2 0 b) -: a=($a)$b [ a=.o.?2 3 4 5$1e6 [ b=. ? 1e6 +(a="0 2 b) -: (4 5$"1 0 a)=2 3$,:b [ a=. ?2 3 $1e6 [ b=.r.? 4 5$1e6 +(a="2 0 b) -: (2 3$,:a)=4 5$"1 0 b [ a=.o.? 4 5$1e6 [ b=. ?2 3 $2 +(a="0 2 b) -: (($b)$a)=b [ a=. ? 2 [ b=. ?2 3 4 5$16 + +(a="2 1 b) -: a=3&#@,:"2[5#"0 b [ a=. ?2 3 4 5$2 [ b=. ?2 4 $16 +(a="1 2 b) -: (5#"0 a)=3&#@,:"2 b [ a=. ?2 3 4 $16 [ b=. ?2 4 5$16 +(a="2 1 b) -: (3&#@,:"2 a)=5#"0 b [ a=.o.?2 4 5$16 [ b=.o.?2 3 4 $16 +(a="1 2 b) -: (3&#@,:"2[5#"0 a)=b [ a=.r.?2 4 $1e6 [ b=.r.?2 3 4 5$2 + +(a<"2 0 b) -: a<($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a<"0 2 b) -: (4 5$"1 0 a)<2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a<"2 0 b) -: (2 3$,:a)<4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a<"0 2 b) -: (($b)$a)<b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a<"2 1 b) -: a<3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a<"1 2 b) -: (5#"0 a)<3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a<"2 1 b) -: (3&#@,:"2 a)<5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a<"1 2 b) -: (3&#@,:"2[5#"0 a)<b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a<."2 0 b) -: a<.($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a<."0 2 b) -: (4 5$"1 0 a)<.2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a<."2 0 b) -: (2 3$,:a)<.4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a<."0 2 b) -: (($b)$a)<.b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a<."2 1 b) -: a<.3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a<."1 2 b) -: (5#"0 a)<.3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a<."2 1 b) -: (3&#@,:"2 a)<.5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a<."1 2 b) -: (3&#@,:"2[5#"0 a)<.b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a<:"2 0 b) -: a<:($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a<:"0 2 b) -: (4 5$"1 0 a)<:2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a<:"2 0 b) -: (2 3$,:a)<:4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a<:"0 2 b) -: (($b)$a)<:b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a<:"2 1 b) -: a<:3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a<:"1 2 b) -: (5#"0 a)<:3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a<:"2 1 b) -: (3&#@,:"2 a)<:5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a<:"1 2 b) -: (3&#@,:"2[5#"0 a)<:b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a>"2 0 b) -: a>($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a>"0 2 b) -: (4 5$"1 0 a)>2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a>"2 0 b) -: (2 3$,:a)>4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a>"0 2 b) -: (($b)$a)>b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a>"2 1 b) -: a>3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a>"1 2 b) -: (5#"0 a)>3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a>"2 1 b) -: (3&#@,:"2 a)>5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a>"1 2 b) -: (3&#@,:"2[5#"0 a)>b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a>."2 0 b) -: a>.($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a>."0 2 b) -: (4 5$"1 0 a)>.2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a>."2 0 b) -: (2 3$,:a)>.4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a>."0 2 b) -: (($b)$a)>.b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a>."2 1 b) -: a>.3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a>."1 2 b) -: (5#"0 a)>.3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a>."2 1 b) -: (3&#@,:"2 a)>.5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a>."1 2 b) -: (3&#@,:"2[5#"0 a)>.b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a>:"2 0 b) -: a>:($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a>:"0 2 b) -: (4 5$"1 0 a)>:2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a>:"2 0 b) -: (2 3$,:a)>:4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a>:"0 2 b) -: (($b)$a)>:b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a>:"2 1 b) -: a>:3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a>:"1 2 b) -: (5#"0 a)>:3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a>:"2 1 b) -: (3&#@,:"2 a)>:5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a>:"1 2 b) -: (3&#@,:"2[5#"0 a)>:b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a+"2 0 b) -: a+($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a+"0 2 b) -: (4 5$"1 0 a)+2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a+"2 0 b) -: (2 3$,:a)+4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a+"0 2 b) -: (($b)$a)+b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a+"2 1 b) -: a+3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a+"1 2 b) -: (5#"0 a)+3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a+"2 1 b) -: (3&#@,:"2 a)+5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a+"1 2 b) -: (3&#@,:"2[5#"0 a)+b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a*"2 0 b) -: a*($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a*"0 2 b) -: (4 5$"1 0 a)*2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a*"2 0 b) -: (2 3$,:a)*4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a*"0 2 b) -: (($b)$a)*b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a*"2 1 b) -: a*3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a*"1 2 b) -: (5#"0 a)*3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a*"2 1 b) -: (3&#@,:"2 a)*5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a*"1 2 b) -: (3&#@,:"2[5#"0 a)*b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a-"2 0 b) -: a-($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a-"0 2 b) -: (4 5$"1 0 a)-2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a-"2 0 b) -: (2 3$,:a)-4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a-"0 2 b) -: (($b)$a)-b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a-"2 1 b) -: a-3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a-"1 2 b) -: (5#"0 a)-3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a-"2 1 b) -: (3&#@,:"2 a)-5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a-"1 2 b) -: (3&#@,:"2[5#"0 a)-b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a%"2 0 b) -: a%($a)$b [ a=.?2 3 4 5$1e6 [ b=.? 1e6 +(a%"0 2 b) -: (4 5$"1 0 a)%2 3$,:b [ a=.?2 3 $1e6 [ b=.? 4 5$1e6 +(a%"2 0 b) -: (2 3$,:a)%4 5$"1 0 b [ a=.? 4 5$1e6 [ b=.?2 3 $1e6 +(a%"0 2 b) -: (($b)$a)%b [ a=.? 1e6 [ b=.?2 3 4 5$1e6 + +(a%"2 1 b) -: a%3&#@,:"2[5#"0 b [ a=.?2 3 4 5$1e6 [ b=.?2 4 $1e6 +(a%"1 2 b) -: (5#"0 a)%3&#@,:"2 b [ a=.?2 3 4 $1e6 [ b=.?2 4 5$1e6 +(a%"2 1 b) -: (3&#@,:"2 a)%5#"0 b [ a=.?2 4 5$1e6 [ b=.?2 3 4 $1e6 +(a%"1 2 b) -: (3&#@,:"2[5#"0 a)%b [ a=.?2 4 $1e6 [ b=.?2 3 4 5$1e6 + +(a%:"2 0 b) -: a%:($a)$b [ a=.1+?2 3 4 5$20 [ b=.? 1e6 +(a%:"0 2 b) -: (4 5$"1 0 a)%:2 3$,:b [ a=.1+?2 3 $20 [ b=.? 4 5$1e6 +(a%:"2 0 b) -: (2 3$,:a)%:4 5$"1 0 b [ a=.1+? 4 5$20 [ b=.?2 3 $1e6 +(a%:"0 2 b) -: (($b)$a)%:b [ a=.1+? 20 [ b=.?2 3 4 5$1e6 + +(a%:"2 1 b) -: a%:3&#@,:"2[5#"0 b [ a=.1+?2 3 4 5$20 [ b=.?2 4 $1e6 +(a%:"1 2 b) -: (5#"0 a)%:3&#@,:"2 b [ a=.1+?2 3 4 $20 [ b=.?2 4 5$1e6 +(a%:"2 1 b) -: (3&#@,:"2 a)%:5#"0 b [ a=.1+?2 4 5$20 [ b=.?2 3 4 $1e6 +(a%:"1 2 b) -: (3&#@,:"2[5#"0 a)%:b [ a=.1+?2 4 $20 [ b=.?2 3 4 5$1e6 + +(a~:"2 0 b) -: a~:($a)$b [ a=.o.?2 3 4 5$16 [ b=. ? 16 +(a~:"0 2 b) -: (4 5$"1 0 a)~:2 3$,:b [ a=. ?2 3 $16 [ b=.r.? 4 5$16 +(a~:"2 0 b) -: (2 3$,:a)~:4 5$"1 0 b [ a=.o.? 4 5$16 [ b=. ?2 3 $2 +(a~:"0 2 b) -: (($b)$a)~:b [ a=. ? 2 [ b=. ?2 3 4 5$16 + +(a~:"2 1 b) -: a~:3&#@,:"2[5#"0 b [ a=. ?2 3 4 5$2 [ b=. ?2 4 $16 +(a~:"1 2 b) -: (5#"0 a)~:3&#@,:"2 b [ a=. ?2 3 4 $16 [ b=. ?2 4 5$16 +(a~:"2 1 b) -: (3&#@,:"2 a)~:5#"0 b [ a=.o.?2 4 5$16 [ b=.o.?2 3 4 $16 +(a~:"1 2 b) -: (3&#@,:"2[5#"0 a)~:b [ a=.r.?2 4 $16 [ b=.r.?2 3 4 5$2 + +(a-"2 0 b) -: i.2 0 4 5 [ a=.?2 0 4 5$16 [ b=.? 16 +(a-"0 2 b) -: i.2 0 4 5 [ a=.?2 0 $16 [ b=.? 4 5$16 +(a-"2 0 b) -: i.2 0 4 5 [ a=.? 4 5$16 [ b=.?2 0 $16 +(a-"0 2 b) -: i.2 0 4 5 [ a=.? 16 [ b=.?2 0 4 5$16 + +(a-"2 1 b) -: i.2 0 0 5 [ a=.?2 0 0 5$16 [ b=.?2 0 $16 +(a-"1 2 b) -: i.2 0 0 5 [ a=.?2 0 0 $16 [ b=.?2 0 5$16 +(a-"2 1 b) -: i.2 0 0 5 [ a=.?2 0 5$16 [ b=.?2 0 0 $16 +(a-"1 2 b) -: i.2 0 0 5 [ a=.?2 0 $16 [ b=.?2 0 0 5$16 + +(a-b) -: a-"0 b [ a=.?2 3 4$1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"1 b [ a=.?2 3 4$1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"2 b [ a=.?2 3 4$1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"3 b [ a=.?2 3 4$1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"_ b [ a=.?2 3 4$1e6 [ b=.?2 3 4$1e6 + +(a-b) -: a-"0 b [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"1 b [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"2 b [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"3 b [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(a-b) -: a-"_ b [ a=.o.?1e6 [ b=.?2 3 4$1e6 + +(b-a) -: b-"0 a [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(b-a) -: b-"1 a [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(b-a) -: b-"2 a [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(b-a) -: b-"3 a [ a=.o.?1e6 [ b=.?2 3 4$1e6 +(b-a) -: b-"_ a [ a=.o.?1e6 [ b=.?2 3 4$1e6 + +(a-"0 _ b) -: (($b)$"1 0 a)-($a)$,:b [ a=.?3 1 5$1e6 [ b=.?2 7e6 +(a-"_ 0 b) -: (($b)$,: a)-($a)$"1 0 b [ a=.?3 1 5$1e6 [ b=.?2 7e6 + + +NB. ="r on non-numerics ------------------------------------------------- + +(a="2 0 b) -: a=($a)$b [ a=.a.{~?2 3 4 5$256 [ b=.a.{~? 256 +(a="0 2 b) -: (4 5$"1 0 a)=2 3$,:b [ a=.a.{~?2 3 $256 [ b=.a.{~? 4 5$256 +(a="2 0 b) -: (2 3$,:a)=4 5$"1 0 b [ a=.a.{~? 4 5$256 [ b=.a.{~?2 3 $256 +(a="0 2 b) -: (($b)$a)=b [ a=.a.{~? 256 [ b=.a.{~?2 3 4 5$256 + +(a="2 1 b) -: a=3&#@,:"2[5#"0 b [ a=.a.{~?2 3 4 5$256 [ b=.a.{~?2 4 $256 +(a="1 2 b) -: (5#"0 a)=3&#@,:"2 b [ a=.a.{~?2 3 4 $256 [ b=.a.{~?2 4 5$256 +(a="2 1 b) -: (3&#@,:"2 a)=5#"0 b [ a=.a.{~?2 4 5$256 [ b=.a.{~?2 3 4 $256 +(a="1 2 b) -: (3&#@,:"2[5#"0 a)=b [ a=.a.{~?2 4 $256 [ b=.a.{~?2 3 4 5$256 + +xx=.256$(;:'Cogito, ergo sum.'),(?&.>30$1e6),(<?3 4$100),<3j4 + +(a="2 0 b) -: a=($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~? 256 +(a="0 2 b) -: (4 5$"1 0 a)=2 3$,:b [ a=.xx{~?2 3 $256 [ b=.xx{~? 4 5$256 +(a="2 0 b) -: (2 3$,:a)=4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.xx{~?2 3 $256 +(a="0 2 b) -: (($b)$a)=b [ a=.xx{~? 256 [ b=.xx{~?2 3 4 5$256 + +(a="2 1 b) -: a=3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~?2 4 $256 +(a="1 2 b) -: (5#"0 a)=3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.xx{~?2 4 5$256 +(a="2 1 b) -: (3&#@,:"2 a)=5#"0 b [ a=.xx{~?2 4 5$256 [ b=.xx{~?2 3 4 $256 +(a="1 2 b) -: (3&#@,:"2[5#"0 a)=b [ a=.xx{~?2 4 $256 [ b=.xx{~?2 3 4 5$256 + +xx=.256$(;:'Cogito, ergo sum.'),(<"1 ?30 2$1e6),(<?3 4$100),<3j4 + +(a="2 0 b) -: a=($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~? 256 +(a="0 2 b) -: (4 5$"1 0 a)=2 3$,:b [ a=.xx{~?2 3 $256 [ b=.xx{~? 4 5$256 +(a="2 0 b) -: (2 3$,:a)=4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.xx{~?2 3 $256 +(a="0 2 b) -: (($b)$a)=b [ a=.xx{~? 256 [ b=.xx{~?2 3 4 5$256 + +(a="2 1 b) -: a=3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~?2 4 $256 +(a="1 2 b) -: (5#"0 a)=3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.xx{~?2 4 5$256 +(a="2 1 b) -: (3&#@,:"2 a)=5#"0 b [ a=.xx{~?2 4 5$256 [ b=.xx{~?2 3 4 $256 +(a="1 2 b) -: (3&#@,:"2[5#"0 a)=b [ a=.xx{~?2 4 $256 [ b=.xx{~?2 3 4 5$256 + +(a="2 0 b) -: a=($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.? 256 +(a="0 2 b) -: (4 5$"1 0 a)=2 3$,:b [ a=.xx{~?2 3 $256 [ b=.? 4 5$256 +(a="2 0 b) -: (2 3$,:a)=4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.?2 3 $256 +(a="0 2 b) -: (($b)$a)=b [ a=.xx{~? 256 [ b=.?2 3 4 5$256 + +(a="2 1 b) -: a=3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.?2 4 $256 +(a="1 2 b) -: (5#"0 a)=3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.?2 4 5$256 +(a="2 1 b) -: (3&#@,:"2 a)=5#"0 b [ a=.xx{~?2 4 5$256 [ b=.?2 3 4 $256 +(a="1 2 b) -: (3&#@,:"2[5#"0 a)=b [ a=.xx{~?2 4 $256 [ b=.?2 3 4 5$256 + +0 1 0 -: 'abc'='cba' +0 0 0 -: 'abc'=1 2 3 +0 0 0 -: 'abc'=<'asdf' +0 0 0 -: (<'asdf')=4 5 6 + + +NB. ~:"r on non-numerics ------------------------------------------------ + +(a~:"2 0 b) -: a~:($a)$b [ a=.a.{~?2 3 4 5$256 [ b=.a.{~? 256 +(a~:"0 2 b) -: (4 5$"1 0 a)~:2 3$,:b [ a=.a.{~?2 3 $256 [ b=.a.{~? 4 5$256 +(a~:"2 0 b) -: (2 3$,:a)~:4 5$"1 0 b [ a=.a.{~? 4 5$256 [ b=.a.{~?2 3 $256 +(a~:"0 2 b) -: (($b)$a)~:b [ a=.a.{~? 256 [ b=.a.{~?2 3 4 5$256 + +(a~:"2 1 b) -: a~:3&#@,:"2[5#"0 b [ a=.a.{~?2 3 4 5$256 [ b=.a.{~?2 4 $256 +(a~:"1 2 b) -: (5#"0 a)~:3&#@,:"2 b [ a=.a.{~?2 3 4 $256 [ b=.a.{~?2 4 5$256 +(a~:"2 1 b) -: (3&#@,:"2 a)~:5#"0 b [ a=.a.{~?2 4 5$256 [ b=.a.{~?2 3 4 $256 +(a~:"1 2 b) -: (3&#@,:"2[5#"0 a)~:b [ a=.a.{~?2 4 $256 [ b=.a.{~?2 3 4 5$256 + +xx=.256$(;:'Cogito, ergo sum.'),(?&.>30$1e6),(<?3 4$100),<3j4 + +(a~:"2 0 b) -: a~:($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~? 256 +(a~:"0 2 b) -: (4 5$"1 0 a)~:2 3$,:b [ a=.xx{~?2 3 $256 [ b=.xx{~? 4 5$256 +(a~:"2 0 b) -: (2 3$,:a)~:4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.xx{~?2 3 $256 +(a~:"0 2 b) -: (($b)$a)~:b [ a=.xx{~? 256 [ b=.xx{~?2 3 4 5$256 + +(a~:"2 1 b) -: a~:3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~?2 4 $256 +(a~:"1 2 b) -: (5#"0 a)~:3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.xx{~?2 4 5$256 +(a~:"2 1 b) -: (3&#@,:"2 a)~:5#"0 b [ a=.xx{~?2 4 5$256 [ b=.xx{~?2 3 4 $256 +(a~:"1 2 b) -: (3&#@,:"2[5#"0 a)~:b [ a=.xx{~?2 4 $256 [ b=.xx{~?2 3 4 5$256 + +xx=.256$(;:'Cogito, ergo sum.'),(<"1 ?30 2$1e6),(<?3 4$100),<3j4 + +(a~:"2 0 b) -: a~:($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~? 256 +(a~:"0 2 b) -: (4 5$"1 0 a)~:2 3$,:b [ a=.xx{~?2 3 $256 [ b=.xx{~? 4 5$256 +(a~:"2 0 b) -: (2 3$,:a)~:4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.xx{~?2 3 $256 +(a~:"0 2 b) -: (($b)$a)~:b [ a=.xx{~? 256 [ b=.xx{~?2 3 4 5$256 + +(a~:"2 1 b) -: a~:3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.xx{~?2 4 $256 +(a~:"1 2 b) -: (5#"0 a)~:3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.xx{~?2 4 5$256 +(a~:"2 1 b) -: (3&#@,:"2 a)~:5#"0 b [ a=.xx{~?2 4 5$256 [ b=.xx{~?2 3 4 $256 +(a~:"1 2 b) -: (3&#@,:"2[5#"0 a)~:b [ a=.xx{~?2 4 $256 [ b=.xx{~?2 3 4 5$256 + +(a~:"2 0 b) -: a~:($a)$b [ a=.xx{~?2 3 4 5$256 [ b=.? 256 +(a~:"0 2 b) -: (4 5$"1 0 a)~:2 3$,:b [ a=.xx{~?2 3 $256 [ b=.? 4 5$256 +(a~:"2 0 b) -: (2 3$,:a)~:4 5$"1 0 b [ a=.xx{~? 4 5$256 [ b=.?2 3 $256 +(a~:"0 2 b) -: (($b)$a)~:b [ a=.xx{~? 256 [ b=.?2 3 4 5$256 + +(a~:"2 1 b) -: a~:3&#@,:"2[5#"0 b [ a=.xx{~?2 3 4 5$256 [ b=.?2 4 $256 +(a~:"1 2 b) -: (5#"0 a)~:3&#@,:"2 b [ a=.xx{~?2 3 4 $256 [ b=.?2 4 5$256 +(a~:"2 1 b) -: (3&#@,:"2 a)~:5#"0 b [ a=.xx{~?2 4 5$256 [ b=.?2 3 4 $256 +(a~:"1 2 b) -: (3&#@,:"2[5#"0 a)~:b [ a=.xx{~?2 4 $256 [ b=.?2 3 4 5$256 + +1 0 1 -: 'abc'~:'cba' +1 1 1 -: 'abc'~:1 2 3 +1 1 1 -: 'abc'~:<'asdf' +1 1 1 -: (<'asdf')~:4 5 6 + + +4!:55 ;:'a agree asm b boxr c cells crank cs cshape dr er f fr frame ' +4!:55 ;:'glob lag mm mrk msh pfx rag rank rk t x xx y ' + +
new file mode 100644 --- /dev/null +++ b/test/g601.ijs @@ -0,0 +1,216 @@ +NB. ".y ----------------------------------------------------------------- + +p -: (".'p=.20?20') +'' -: ".'' +'' -: ".' ' + +'' -: ".'+' +'' -: ".'/' +'' -: ".'&' + +x -: ". ": x=._5e5+?30$1e6 + +(>x) -: ". ":&>x=. ?&.>7 8 9$&.>1e6 +(>x) -: ". ":&>x=. ?&.>8 8 8$&.>1e6 +x -: ". ":,.x=. ?8$1e6 + +x=._5e7+?20$1e8 +y=._5e7+?20$1e8 +(x+y) -: ".(":,.x),.'+',.":,.y +(x*y) -: ".(":,.x),.'*',.":,.y +(x-y) -: ".(":,.x),.'-',.":,.y +(x%y) -: ".(":,.x),.'%',.":,.y + +x=._5e7+?20$1e8 +n=.?20$100 +(x+&>i.&.>n) -: ".(":,.x),.'+i.',"1 ":,.n + +x -: ". ":x=. j./_5e5+?2 5 9$1e6 +x -: ". , (9{a.),.":,.x=. ?100$10000 + +a=. 123456 +b=. 123456 +4!:55 ;:'a b' +x=. 123456 +y=. 123456 + +x=. 7!:0 '' +a=. |.i.1000 +b=. <".'a' +b -: <|.i.1000 +a=. 'kakistocracy' +b -: <|.i.1000 +a -: 'kakistocracy' +4!:55 ;:'a b' +y=. 7!:0 '' +x -: y + +'domain error' -: ". etx 0 1 0 +'domain error' -: ". etx 2 3 4 +'domain error' -: ". etx 2.3 4 +'domain error' -: ". etx 2 3j4 +'domain error' -: ". etx 'abc';'3' +'domain error' -: ". etx '3+<3' + +'syntax error' -: ". etx '=.' +'syntax error' -: ". etx '3 (4)' +'syntax error' -: ". etx ')' +'syntax error' -: ". etx '(' + +'spelling error' -: ". etx 128{a. +'spelling error' -: ". etx 195{a. +'spelling error' -: ". etx 255{a. +'spelling error' -: ". etx '1 2 3',( 0{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',( 10{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',( 13{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',( 27{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',(127{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',(130{a.),'5 6 7' +'spelling error' -: ". etx '1 2 3',(255{a.),'5 6 7' + +'ill-formed number' -: ". etx '3ee4' +'ill-formed number' -: ". etx '3jj4' + + +NB. "."0@": y ----------------------------------------------------------- + +f=: 3 : '"."0 ": y' +(f -: "."0@":) !30x +(f -: "."0@":) ?10^20x +(f -: "."0@":) 10 ?@$ 1000 + + +NB. x".y ---------------------------------------------------------------- + +1234 -: _999 ". '1234' +1 _2 3 -: _999 ". '1 -2 3' +1 _2 3 -: _999 ". '1 _2 3' +1 2e_8 _3e_8 -: _999 ". '1 2e-8 -3e-8' + +3j4 -: _999 ". '3j4' +1 _2 3j4 -: _999 ". '1 -2 3j4' +1 _2 3j4 -: _999 ". '1 _2 3j4' +1 _2 _999 -: _999 ". '1 _2 j43' +1 2e_8 _3e_8 3j4 -: _999 ". '1 2e-8 -3e-8 3j4' +1 2e_8 _3j_4 -: _999 ". '1 2e-8 -3j-4' + +_999 -: _999 ". '+' +_999 -: _999 ". '++' +2 -: _999 ". '+2' +2000 2000 0.002 -: _999 ". '2e+3 2e3 2e-3' +_999 2 2.3 3 -: _999 ". '+ 2 +2.3 3' + +_ __ -: _999 ". '- --' +8 _999 -: _999 ". '8 1-4' +8 _999 9 _ 1 __ 2 -: _999 ". '8 __4 9 _ 1 __ 2' +8 _999 9 _ 1 __ 2 -: _999 ". '8 _4_ 9 _ 1 __ 2' +8 _999 9 _ 1 __ 2 -: _999 ". '8 _47_ 9 _ 1 __ 2' +8 _999 9 _ 1 __ 2 -: _999 ". '8 _478_ 9 _ 1 __ 2' +8 _999 9 _ 1 __ 2 -: _999 ". '8 _4781_ 9 _ 1 __ 2' +8 _999 9 _ 1 __ 2 -: _999 ". '8 _47812_ 9 _ 1 __ 2' + +0.34 -: _999 ". '0.34' +0.34 -: _999 ". '.34' +3j4 0.34 -: _999 ". '3j4 0.34' +3j4 0.34 -: _999 ". '3j4 .34' + +_999 0 _999 3.4 -: _999 ". 'bad 0 huh? 3.4' + +1234 8.9 -: _999 ". '1,234 8.9' +1234567 8.9 -: _999 ". '1,234,567 8.9' +1234567890 8.9 -: _999 ". '1,234,567,890 8.9' +_999 2 -: _999 ". ', 2' +2.4 _999 -: _999 ". '2.4 ,' +_999 0 _999 3.4 -: _999 ". ', 0 ,,,, 3.4' +_9j9 0 _9j9 3.4 -: _9j9 ". ', 0 ,,,, 3.4' +_999 _999 1234 -: _999 ". ',123 123, 1,,,,234' +_9j9 _9j9 1234 -: _9j9 ". ',123 123, 1,,,,234' + +x -: _999 ". ": x=.?3 4$10000 +x -: _999 ". ": x=._1e4+?3 4$2e4 +x -: _999 ". ": x=.j./?2 3 4$10000 +x -: _999 ". ": x=.j./_1e4+?2 3 4$2e4 + +(1 _999,:2 3) -: _999 ". '1 ',:'2 3' +(111 _999,:2 3) -: _999 ". '111',:'2 3' +(3 2$111 _999 _999 _999 2 3) -: _999 ". '111',' ',:'2 3' + +x -: _999 ". ": ,.x=. _1e9+?20$2e9 +x -: _999 ". ":!.16 ,.x=.o._1e9+?20$2e9 +x -: _999 ". ":!.16 ,.x=.j./ _1e9+?2 20$2e9 + +eq=. -:&(3!:1) +1 2 _ 3.4 eq _999 ". '1 2 _ 3.4' +1 2 _ 3j4 eq _999 ". '1 2 _ 3j4' +1 2 __ 3.4 eq _999 ". '1 2 __ 3.4' +1 2 __ 3j4 eq _999 ". '1 2 __ 3j4' +1 2 _. 3.4 eq _999 ". '1 2 _. 3.4' +1 2 _. 3j4 eq _999 ". '1 2 _. 3j4' + +(i.0) -: _999 ". i.0 +(i.0) -: _9j9 ". i.0 +( 2e9 0$0) -: _999 ". 2e9 0$'' +( 2e9 0$0) -: _9j9 ". 2e9 0$'' +(3 1e9 0$0) -: _999 ". 3 1e9 0$'' +(3 1e9 0$0) -: _9j9 ". 3 1e9 0$'' +(1e9 1e9 0$0) -: _999 ". 1e9 1e9 0$'' +(1e9 1e9 0$0) -: _9j9 ". 1e9 1e9 0$'' + +1 -: type _3.5 ". '1 0 1 0' +1 -: type _3j5 ". '1 0 1 0' +4 -: type _3.5 ". '1 0 1 9' +4 -: type _3j5 ". '1 0 1 9' +8 -: type _3.5 ". '1 0 1.9' +8 -: type _3j5 ". '1 0 1.9' + +1 -: type _3.5 ". '1 0 1j0' +1 -: type _3j5 ". '1 0 1j0' +4 -: type _3.5 ". '1 0 4j0' +4 -: type _3j5 ". '1 0 4j0' +8 -: type _3.5 ". '1 0.1j0' +8 -: type _3j5 ". '1 0.1j0' + +( %3 _4) -: _999 ". ' 1r3 _1r4' +(3j4,%3 _4) -: _999 ". '3j4 1r3 _1r4' + +((^1 2),_999) -: _999 ". '1x1 1x2 abc' +((^1 2),_9j9) -: _9j9 ". '1x1 1x2 abc' + +1p1 1p2 _999 -: _999 ". '1p1 1p2 abc' +1p1 1p2 _9j9 -: _9j9 ". '1p1 1p2 abc' + +2b111 5b312 _999 -: _999 ". '2b111 5b312 abc' +2b111 5b312 _9j9 -: _9j9 ". '2b111 5b312 abc' + +0j4 _5 0 -: 0 ". '4ad90 5ar3.14159265358979 abc' + +(1 2 3 ,: 4 5 99) -: 99 ". '1 2 3',: '4 5' +(1 2 3 ,:~ 4 5 99) -: 99 ". '1 2 3',:~'4 5' +(1 2 3 ,: 99 99 99) -: 99 ". '1 2 3',: ' ' +(1 2 3 ,:~ 99 99 99) -: 99 ". '1 2 3',:~ ' ' + +(1j2 3 4 ,: 4 5 99) -: 99 ". '1j2 3 4',: '4 5' +(1j2 3 4 ,:~ 4 5 99) -: 99 ". '1j2 3 4',:~ '4 5' +(1j2 3 4 ,: 99 99 99) -: 99 ". '1j2 3 4',: ' ' +(1j2 3 4 ,:~ 99 99 99) -: 99 ". '1j2 3 4',:~ ' ' + +0.75 -: 1j2 ". '3r4' +1j2 -: 1j2 ". '34x' +1j2 -: 1j2 ". 'steer' +1j2 -: 1j2 ". 'jinx' + +'domain error' -: '9' ". etx '1 2 3 4' +'domain error' -: (<5) ". etx '1 2 3 4' +'domain error' -: _5 ". etx 1 0 1 0 +'domain error' -: _5 ". etx i.5 +'domain error' -: _5 ". etx 3.4 5.6 +'domain error' -: _5 ". etx 3j4 5.6 +'domain error' -: _5 ". etx 'abc';'ef' + +'rank error' -: (,_5) ". etx '1 2 3' +'rank error' -: 3 4 ". etx '1 2 3' + + +4!:55 ;:'a b eq f n p x y' + +
new file mode 100644 --- /dev/null +++ b/test/g602.ijs @@ -0,0 +1,381 @@ +NB. ":y on non-empty numeric array y ------------------------------------ + +sprintf =: ": +real =: {.@+. +imag =: {:@+. + +minus =: $&'_'@('-'&=@{.) +ubar =: >@({&(<;._1 ' _ _ _. _.'))@('iInN'&i.@{.) +afte =: minus , (i.&0@(e.&'-+0') }. ]) +efmt =: >:@(i.&'e') ({. , afte@}.) ] +finite =: ]`efmt@.('e'&e.) +massage =: finite`ubar@.(e.&'iInN'@{.) +fmtD =: (minus,massage@(e.&'-+'@{.}.])) @ sprintf + +cleanZ =: (* ] >&| (2^_44)"_ * |.)&.+. +fmtZ1 =: fmtD@real , 'j'&,@fmtD@imag`(''"_)@.(0&=@imag) +fmtZ =: fmtZ1 NB. @ cleanZ + +fmtB =: {&'01' +fmtI =: sprintf +fmt =: (fmtB&.>)`(fmtI&.>)`(fmtD&.>)`(fmtZ&.>) @. (1 4 8&i.@(3!:0)) + +sh =: (*/@}:,{:@(1&,))@$ ($,) ] +width =: (<:@{. 0} ])@:>:@(>./)@sh@:(#&>) +th =: (-@width ;@:({.&.>)"1 ]) @ fmt + +f =: ": -: th + +f x=:1=?2 3 4$2 +f x=:_50+?2 3 4$100 +f x=:o._50+?2 3 4$100 +f x=:r.?4 3 2$100 + +f x=:1=?2 +f x=:_50+?100 +f x=:o._50+?100 +f x=:r.?100 +f x=:r.0 + +f x=:_3.1415e_76 _3.1415e76 +f x=:_3.1415e_76j_3.1415e76 + +f _ +f __ +f _. +f 3 7$ _ 3 __ 4 _. 6 + +(":_3.1415e_76) -: fmtD '-3.1415e-76' +(":_3.1415e76 ) -: fmtD '-3.1415e+076' +(": _) -: fmtD 'INF' +(": _) -: fmtD 'inf' +(":__) -: fmtD '-INF' +(":__) -: fmtD '-inf' +(":_.) -: fmtD 'NAN' +(":_.) -: fmtD 'nan' +(":_.) -: fmtD '+NAN01' +(":_.) -: fmtD '+nan01' + +(,'_' ) -: ": _ +'__' -: ": __ +'_.' -: ": _. + +(":x) -: }. ; ' ',&.>":&.>x=: 4 5,imax,1 _2 3 +(":x) -: }. ; ' ',&.>":&.>x=: 4 5,imin,1 _2 3 + +(":imax) -: ": <:2x^IF64{31 63 +(":imin) -: ": - 2x^IF64{31 63 + +sqz=: #"1~ -.@(1 1&E.)@(*./)@(' '&=) +(":x) -: sqz _3 }.@,\' ',.":,., x=: 2 3$imax,1 2 _3 +(":x) -: sqz _3 }.@,\' ',.":,., x=: 2 3$imin,1 2 _3 + + +NB. ":y print precision ------------------------------------------------- + +pi=:o.1 +'3.14159' -: ":pi +'3.14159' -: ":!.6 pi +'3.141592653589793' -: ":!.16 pi + +ppq =: 9!:10 +pp =: 9!:11 + +6 -: ppq '' +x=:7^_4+i.14 + +(": -: ":!. 6) x +(": -: ":!. 4) x [ pp 4 +(": -: ":!. 8) x [ pp 8 +(": -: ":!.12) x [ pp 12 +(": -: ":!. 6) x [ pp 6 + +'domain error' -: pp etx 'a' +'domain error' -: pp etx <7 +'domain error' -: pp etx 7.5 +'domain error' -: pp etx 7j5 +'domain error' -: pp etx _6 + +'rank error' -: pp etx 5 6 + +'limit error' -: pp etx 25 + + +NB. ":y on boxed array y ------------------------------------------------ + +boxed =: 32 = 3!:0 +mt =: 0 e. $ +boxc =: 9!:6 '' +tcorn =: 2 0{boxc +tint =: 1 10{boxc +bcorn =: 8 6{boxc +bint =: 7 10{boxc + +sh =: (*/@}: , {:)@(1&,)@$ $ , +rows =: */\.@}:@$ +bl =: }.@(,&0)@(+/)@(0&=)@(|/ i.@{.@(,&1)) +mask =: 1&,. #&, ,.&0@>:@i.@# +mat =: mask@bl@rows { ' ' , sh + +edge =: ,@(1&,.)@[ }.@# +:@#@[ $ ] +left =: edge&(3 9{boxc)@>@(0&{)@[ , "0 1"2 ] +right =: edge&(5 9{boxc)@>@(0&{)@[ ,~"0 1"2 ] +top =: 1&|.@(tcorn&,)@(edge&tint)@>@(1&{)@[ ,"2 ] +bot =: 1&|.@(bcorn&,)@(edge&bint)@>@(1&{)@[ ,"2~ ] +perim =: [ top [ bot [ left right + +topleft =: (4{boxc)&((<0 0)}) @ ((_2{boxc)&,.) @ ((_1{boxc)&,) +inside =: 1 1&}. @: ; @: (,.&.>/"1) @: (topleft&.>) +take =: {. ' '"_^:mt +frame =: [ perim {@[ inside@:(take&.>)"2 ,:^:(1 = #@$)@] +rc =: (>./@sh&.>) @: (,.@|:"2@:(0&{"1);1&{"1) @: ($&>) + +thorn1 =: ":`thbox @. boxed +thbox =: (rc frame ]) @: (mat@thorn1&.>) + +f =: ": -: thorn1 + +y =: 2 3$(i.2 3);'abc';(i.4 1);(2 2$'ussr');12;<+&.>i.2 2 3 +f y + +f <'abc' +f <'' +f <2 0 3$'abc' +f <2 3 4 2$'abc' + +f ;:'Cogito, ergo sum.' +f (?3$20)?&.>30 + +f <i.2 3 +f 3;<o.i.2 3 +f <<3;<r.?1 1 2 3$100 +f <<'';i.2 0 3 4 2 +f +&.>i.2 3 4 +f (<i.3 4) (<0 0 0)} +.&.>i.2 3 4 + + +NB. x":y ---------------------------------------------------------------- + +sp =: +./@(0&>)@+.@[ >:@*. 0&<:@] +f0 =: (-.&' ') @ (((* * 20&+@|)@{. j. {:)@+.@[ ": ]) +f =: 4 : 0 + ((*./0<:+.x)*x sp {.y)}. ; ((x sp y)$&.>' ') ,&.> x <@f0"0 y +) +f =: 4 : 0 + }.;' ' ,&.> x <@f0"0 y +) + +NB. Boolean +t=:(,. 15 j.i.10) <@": 0 +t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '0.',9$'0' +t=:(,.- 15 j.i.10) <@": 0 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 0.',9$'0' +(0j4 f t) -: 0j4 ": t=:1=?9$2 +(0j_4 f t) -: 0j_4 ": t=:1=?9$2 +(0 ": t) -: 0 ": (2-2)+t=:?10 10$2 +'*****' -: 5j6":0 + +NB. integer +t=:(,.15 j. i.10) <@": 3 +t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.',9$'0' +t=:(,.15 j. i.10) <@": _3 +t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.',9$'0' +t=:(,.-15 j. i.10) <@": 3 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.',9$'0' +t=:(,.-15 j. i.10) <@": _3 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.',9$'0' +(0j4 f t) -: 0j4 ": t=:_50+?9$100 +(0j_4 f t) -: 0j_4 ": t=:_50+?9$100 +'*****' -: 5j3":12 + +NB. floating point +t=:(,. 15 j. i.10) <@": 3.2 +t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.2',8$'0' +t=:(,. 15 j. i.10) <@": _3.2 +t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.2',8$'0' +t=:(,.-15 j. i.10) <@": 3.2 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.2',8$'0' +t=:(,.-15 j. i.10) <@": _3.2 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.2',8$'0' +(0j4 f t) -: 0j4 ": t=:o._50+?9$100 +(0j_4 f t) -: 0j_4 ": t=:o._50+?9$100 +'*****' -: 5j3":_1.2 + +NB. complex +t=:(,. 15 j. i.10) <@": 3.2j4 +t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.2',8$'0' +t=:(,. 15 j. i.10) <@": _3.2j4 +t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.2',8$'0' +t=:(,.-15 j. i.10) <@": 3.2j4 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.2',8$'0' +t=:(,.-15 j. i.10) <@": _3.2j4 +t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.2',8$'0' +'*****' -: 5j3":_1.2j4 + +(;_1 _2 _3<@{."0 t{'01') -: 1 2 3": t=:1=?3$2 +(;_1 _2 _3<@{."0 t{'0123456789') -: 1 2 3": t=:?3$10 + +(9 {."1 ' _',:' __') -: 0 _1 { _9j2 ": ,. _ , (i: 5) , __ +(9 {."1 ' _',:' __') -: 0 _1 { 9j_2 ": ,. _ , (i: 5) , __ + +test =: 4 : '((}:$z)-:}:$y),(#$z)-:1>.#$y [ z=: x ": y' + +9j4 test 50 +9j4 test ,12 +9j4 test 1 2 3 +9j4 test i.1 3 +9j4 test i.3 1 +9j4 test i.3 4 +9j4 test i.2 3 4 +9j4 test i.2 3 4 5 + +0j4 test 50 +0j4 test ,12 +0j4 test 1 2 3 +0j4 test i.1 3 +0j4 test i.3 1 +0j4 test i.3 4 +0j4 test i.2 3 4 +0j4 test i.2 3 4 5 + +9j4 test i.0 +9j4 test i.5 0 +9j4 test i.0 5 +9j4 test i.2 0 4 + +0j4 test i.0 +0j4 test i.5 0 +0j4 test i.0 5 +0j4 test i.2 0 4 + +(_12{.'1234.57') -: 12j2 ": 1234.567 + +-:/ 10 ": ,. 3.33e_16 _3.33e_16 +-:/ 10j4 ": ,. 3.33e_16 _3.33e_16 +' 0' -: 3 ": _3.33e_12j_4.44e_14 + +'domain error' -: 9.2 ": etx 12 +'domain error' -: 9j2 ": etx '3 4' +'domain error' -: 9j2 ": etx <123 +'domain error' -: 'ab' ": etx 4 5 +'domain error' -: (<21) ": etx 4 5 + +'length error' -: 1 2 ": etx 4 +'length error' -: 1 2 ": etx 4 5 6 +'length error' -: 1 2 ": etx i.2 3 +'length error' -: 1 2 ": etx i.2 3 4 + + +NB. x":y on boxed arrays ------------------------------------------------ + +(0 0 ": x) -: ": x=: ,. ;: 'Cogito, ergo sum.' + +(' *'{~0=i.3 3) -: 3 3{.1 1}.0 0":x=:x,:|.x=:(1 1$'*');3 3$'*' +(' *'{~1=i.3 3) -: 3 3{.1 1}.0 1":x +(' *'{~2=i.3 3) -: 3 3{.1 1}.0 2":x +(' *'{~3=i.3 3) -: 3 3{.1 1}.1 0":x +(' *'{~4=i.3 3) -: 3 3{.1 1}.1 1":x +(' *'{~5=i.3 3) -: 3 3{.1 1}.1 2":x +(' *'{~6=i.3 3) -: 3 3{.1 1}.2 0":x +(' *'{~7=i.3 3) -: 3 3{.1 1}.2 1":x +(' *'{~8=i.3 3) -: 3 3{.1 1}.2 2":x + +f =: 4 : 0 + old=.9!:16 '' + 9!:17 x + z=.":y + 9!:17 old + z +) + +0 0 (f -: ":) x=:i.&.>i.2 3 4 +0 1 (f -: ":) x +0 2 (f -: ":) x +1 0 (f -: ":) x +1 1 (f -: ":) x +1 2 (f -: ":) x +2 0 (f -: ":) x +2 1 (f -: ":) x +2 2 (f -: ":) x + +0 0 (f -: ":) x=:i.&.><"1 >:7 7#:?4 3$49 +0 1 (f -: ":) x +0 2 (f -: ":) x +1 0 (f -: ":) x +1 1 (f -: ":) x +1 2 (f -: ":) x +2 0 (f -: ":) x +2 1 (f -: ":) x +2 2 (f -: ":) x + +'domain error' -: 'ab' ": etx 1;2;3 +'domain error' -: 1.2 0 ": etx 1;2;3 +'domain error' -: 1 2j3 ": etx 1;2;3 +'domain error' -: (1;2) ": etx 1;2;3 + +'length error' -: 0 1 2 3 ": etx 1;2;3 +'length error' -: (i.0) ": etx 1;2;3 + + +NB. x":y on extended integers ------------------------------------------- + +20j4 (": -: (": x:)) x=: _5e8+?20$1e9 +20j4 (": -: (": x:)) ,.x +20j4 (": -: (": x:)) 5 4$x +20j0 (": -: (": x:)) x +20j0 (": -: (": x:)) ,.x +20j0 (": -: (": x:)) 5 4$x +0j4 (": -: (": x:)) x +0j4 (": -: (": x:)) ,.x +0j4 (": -: (": x:)) 5 4$x +0 (": -: (": x:)) x +0 (": -: (": x:)) ,.x +0 (": -: (": x:)) 5 4$x + +0j_4 (": -: (": x:)) 123454 +0j_4 (": -: (": x:)) 123455 +0j_4 (": -: (": x:)) 123456 +0j_4 (": -: (": x:)) 123496 +0j_4 (": -: (": x:)) 123996 +0j_4 (": -: (": x:)) 129996 +0j_4 (": -: (": x:)) 199996 +0j_4 (": -: (": x:)) 999996 + +_14 (": -: (": x:)) 123454 +_14 (": -: (": x:)) 123455 +_14 (": -: (": x:)) 123456 +_14 (": -: (": x:)) 123496 +_14 (": -: (": x:)) 123996 +_14 (": -: (": x:)) 129996 +_14 (": -: (": x:)) 199996 +_14 (": -: (": x:)) 999996 + +0j_6 (": -: (": x:)) 1234 +0j_6 (": -: (": x:)) 1235 +0j_6 (": -: (": x:)) 1236 +0j_6 (": -: (": x:)) 1239 +0j_6 (": -: (": x:)) 1299 +0j_6 (": -: (": x:)) 1999 +0j_6 (": -: (": x:)) 9999 + +0j3 (": -: (": x:^:_1)) 12344x 12346 12347 % 10000x +0j3 (": -: (": x:^:_1)) 12349x 12399 12999 19999 99999 % 10000x +0j3 (": -: (": x:^:_1)) x=: %/x: (+ 0&=) _4e8+?2 20 5$1e9 + +12j3 (": -: (": x:^:_1)) 12344x 12346 12347 % 10000x +12j3 (": -: (": x:^:_1)) 12349x 12399 12999 19999 99999 % 10000x +12j3 (": -: (": x:^:_1)) x=: %/x: (+ 0&=) _4e8+?2 20 5$1e9 + +'0.0000e0' -: 0j_4 ": 0r1 +'0.0000' -: 0j4 ": 0r1 + +2 50027 -: $ 0j25 ": ,. 10 ^ 0 50000x + + +4!:55 ;:'afte bcorn bint bl bot boxc boxed cleanZ edge efmt ' +4!:55 ;:'f f0 finite fmt fmtB fmtD fmtI fmtZ fmtZ1 frame ' +4!:55 ;:'imag inside k left mask massage mat minus mt perim ' +4!:55 ;:'pi pp ppq rc real right rows sh sp sprintf ' +4!:55 ;:'sqz t take tcorn test th thbox thorn1 tint top ' +4!:55 ;:'topleft ubar width x y z ' +
new file mode 100644 --- /dev/null +++ b/test/g610.ijs @@ -0,0 +1,18 @@ +NB. ` ------------------------------------------------------------------- + +do =: 0!:100 +ar =: 5!:1 +test =: 2 : 0 + do 'f9=.',x + do 'g9=.',y + =&ar/;:'f9 g9' +) + +'+ -' test '+`- `:6' +'+ - *' test '+`-`* `:6' +'+ - * %' test '+`-`*`% `:6' + + +4!:55 ;:'ar do test' + +
new file mode 100644 --- /dev/null +++ b/test/g612.ijs @@ -0,0 +1,26 @@ +NB. x`:y ---------------------------------------------------------------- + +f =: - ` % ` ^ `: 0 +y =: 2 3 +x =: 5 7 +(( -y),( %y),: ^y) -: f y +((5-y),(5%y),:5^y) -: 5 f y +((x-y),(x%y),:x^y) -: x f y + +(;/ -: ;`;`:3) x=: 10 ?@$ 1e6 +(;/ -: ;`;`:3) x=: 10 3 ?@$ 1e6 + +'domain error' -: ex '-`a`:0 ' [ a=: 5!:1 <'plus' [ plus=: '+' +'domain error' -: ex '-`a/ ' +'domain error' -: ex '-`a/.' +'domain error' -: ex '-`a\ ' +'domain error' -: ex '-`a\.' +'domain error' -: ex '-`a;. 1' +'domain error' -: ex '-`a;._1' +'domain error' -: ex '-`a;. 2' +'domain error' -: ex '-`a;._2' + + +4!:55 ;:'a f x y' + +
new file mode 100644 --- /dev/null +++ b/test/g620.ijs @@ -0,0 +1,13 @@ +NB. @ ------------------------------------------------------------------- + +({.x|.y) -: (x=.?20) {.@|. y=.?20 3$1000 + +1 -: 0 1 (-~/@[) 1 + +'domain error' -: ". etx '3 @ 3' +'domain error' -: ". etx '3 @ +' +'domain error' -: ". etx '+ @ 3' + +4!:55 ;:'a x y' + +
new file mode 100644 --- /dev/null +++ b/test/g620a.ijs @@ -0,0 +1,29 @@ +NB. ^@o. ---------------------------------------------------------------- + +(^o.z) -: ^@o. z=: 0 j. 0.5 * i.5 4 +(^o.z) -: ^@o. z=: 1 j. 0.5 * i.5 4 +(^o.z) -: ^@o. z=: 20 j. 0.5 * i.5 4 + +(^o.z) -: ^@o. z=: 0 j. _0.5 * i.5 4 +(^o.z) -: ^@o. z=: 1 j. _0.5 * i.5 4 +(^o.z) -: ^@o. z=: 20 j. _0.5 * i.5 4 + +(^o.z) -: ^@o. z=: 0 j. 10 + 0.5 * i.5 4 +(^o.z) -: ^@o. z=: 1 j. 10 + 0.5 * i.5 4 +(^o.z) -: ^@o. z=: 20 j. 10 + 0.5 * i.5 4 + +(^o.z) -: ^@o. z=: 0 j. 10 + _0.5 * i.5 4 +(^o.z) -: ^@o. z=: 1 j. 10 + _0.5 * i.5 4 +(^o.z) -: ^@o. z=: 20 j. 10 + _0.5 * i.5 4 + +(^o.z) -: ^@o. z=: 0 j. 0.33333 _0.33333 + +(^o.x) -: ^@o. x=: _0.5 + 23 ?@$ 0 +(^o.x) -: ^@o. x=: x: %/ 0.01 * 1+ 2 37 ?@$ 1000 + +'domain error' -: ^@o. etx 'abc' +'domain error' -: ^@o. etx <3j4 + +4!:55 ;:'x z' + +
new file mode 100644 --- /dev/null +++ b/test/g621.ijs @@ -0,0 +1,122 @@ +NB. @. ------------------------------------------------------------------ + +f=: 1:`(* $:@<:) @. * +(!i.10) -: f"0 i.10 + +do =: 0!:100 +ar =: 5!:1 +test =: 2 : 0 + do 'f9=.',x + do 'g9=.',y + =&ar/;:'f9 g9' +) + +ifopen =: (-:>) @ {. @ [ +from1 =: >@{ ` { @. (1&<@#@[) +from =: ($:&.> <) ` from1 @. ifopen + +g =: ;: '&+&.+&:^.@' +'(++^.)+^.' test '((1 3 5;3;5) from g)`:6' +'(++^.)+^.' test 'g@.(1 3 5;3;5)' + +'index error' -: +`-`* @. ] etx 3 +'index error' -: +`-`* @. ] etx _4 + +'rank error' -: +`-`* @. ] etx i.3 +'rank error' -: +`-`* @. ] etx i.1 1 + +ack=: c1`c1`c2`c3 @. (#.@(,&*)) " 0 +c1 =: >:@] NB. 1+y +c2 =: <:@[ ack 1: NB. (x-1) ack 1 +c3 =: <:@[ ack [ ack <:@] NB. (x-1) ack x ack y-1 + +(0&ack -: >:&.(3&+)) x=: ?10$20 +(1&ack -: 2&+&.(3&+)) x=: ?10$20 +(2&ack -: 2&*&.(3&+)) x=: ?10$20 +(3&ack -: 2&^&.(3&+)) 3 + +(o. x) -: o.`*`(*:@+:)@.0 x=: 1 2 3 +(* x) -: o.`*`(*:@+:)@.1 x=: 1 2 3 +(*:+:x) -: o.`*`(*:@+:)@.2 x=: 1 2 3 + + +NB. g @. v " 0 ---------------------------------------------------------- + +NB. Example: CDF of standard Normal N(0,1) by J.E.H. Shaw +NB. +NB. n01pdf v probability density function for N(0,1) +NB. erf v error function +NB. n01cdfh v cumulative distribution function for N(0,1) using H. +NB. n01cdfr v ratio used for CDF in tails of N(0,1) +NB. n01cdfn v more accurate than n01cdfh in lower tail (say y. < _6) +NB. n01cdfp v more accurate than n01cdfh in upper tail (say y. > 6) +NB. n01cdfa v N(0,1) cdf using @. +NB. n01cdf v N(0,1) cdf using agenda + +agenda=: 2 : 0 + j=. ~.k=. v y + b=. k (('@:' <@(,&<) '<'&;)"0 j{m)/. y + (/:/:k) { ; b /: j +) + +n01pdf =: ([: ^ _0.5"_ * *:) % (%: 2p1)"_ +erf =: (*&(%:4p_1) % ^@:*:) * [: 1 H. 1.5 *: +n01cdfh=: [: -: 1: + [: erf %&(%:2) +n01cdfr=: n01pdf % ] + 1: % ] + 2: % ] + 3: % ] + 4: % ] + 4.5&% +n01cdfn=: [: - n01cdfr +n01cdfp=: 1: - n01cdfr +n01cdfa=: n01cdfn`n01cdfh`n01cdfp @. (>&_6 + >&6) " 0 +n01cdf =: n01cdfn`n01cdfh`n01cdfp agenda (>&_6 + >&6) + +(n01cdf -: n01cdfa) x=: _10 + 0.01 * ? 10000 $ 1000 + +f0 =: -`*: @. (1: = 2&|) " 0 +f1 =: 3 : ' (b**:y)+(-.b=.2|y)*-y' +(f0 -: f1) x=: ?13 17 19$1000 + +square=: 3 : '*: y' + +f0=: 1: ` *: @. (1: = 2&|) " 0 +f1=: 1: ` square @. (1: = 2&|) " 0 +(f0 -: f1) x=: ?13 17 19$1000 + +f0=: 1: ` - ` *: @. (3&|) " 0 +f1=: 1: ` - ` square @. (3&|) " 0 +(f0 -: f1) x=: ?13 17 19$1000 + + +NB. @. -- all size x partitions of y ------------------------------------ + +start =: +/@{. >:@i.@<.@%&>: {:@$ +mask =: start <:/ {."1 <. -.@(-/)@(_2&{.)"1 +pfx =: +/"1 # >:@i.@# +ind =: , # */@$ $ i.@{:@$ +decr =: (>:@(-/)@(_1 0&{) _1} ])"1 +form =: pfx@[ decr@,. ind@[ { ] +recur =: (mask form ])@(part&<:) + +test =: 1&<@[ *. < +basis =: (0&<@] , [) $ (1&=@[ 1&>.@* ]) +part =: basis`recur@.test + +f=: 4 : 0 + t=.x part y + assert. x={:$t + assert. (i.#t)-:/:t + assert. (0=x)+.y=+/"1 t + assert. (/:"1 t) *./ .=i.x + 1 +) + +f/+/\?5 10 +0 f 0 +0 f 5 +5 f 5 + + +4!:55 ;:'ack agenda ar c1 c2 c3 basis decr do erf f f0 f1 form from from1 ' +4!:55 ;:'g ifopen ind mask ' +4!:55 ;:'n01cdf n01cdfa n01cdfh n01cdfn n01cdfp n01cdfr n01pdf ' +4!:55 ;:'part pfx recur square start t test x z ' + +
new file mode 100644 --- /dev/null +++ b/test/g622.ijs @@ -0,0 +1,12 @@ +NB. @: ------------------------------------------------------------------ + +( x*y) -: (x=.?10$200) +/@ * (y=.?10$2000) +(+/x*y) -: (x=.?10$200) +/@:* (y=.?10$2000) + +'domain error' -: ". etx '3 @: +' +'domain error' -: ". etx '+ @: 3' +'domain error' -: ". etx '3 @: 3' + +4!:55 ;:'x y' + +
new file mode 100644 --- /dev/null +++ b/test/g630.ijs @@ -0,0 +1,18 @@ +NB. & ------------------------------------------------------------------- + +((|.x),|.y) -: (x=.'Cogito, ergo sum.') ,&|. y=.'I think not' + +dr =. 5!:2 + +f =. 3 4 5 6&+ +(,&.>3 4 5 6;'&';'+') -: dr <'f' +(f i.4 3) -: 3 4 5 6+"_ i.4 3 + +f =. -&3 4 5 6 +(,&.>'-';'&';3 4 5 6) -: dr <'f' +(f i.4 3) -: (i.4 3)-"_ [3 4 5 6 + + +4!:55 ;:'dr f x y' + +
new file mode 100644 --- /dev/null +++ b/test/g631.ijs @@ -0,0 +1,44 @@ +NB. u&.v ---------------------------------------------------------------- + +12 _12 _12 12 = 3 3 _3 _3 +&.^. 4 _4 4 _4 +7 _1 1 _7 = 3 3 _3 _3 *&.^ 4 _4 4 _4 + +1 -: +&.^./'' +0 -: *&.^ /'' + +totient =. * -.@%@~.&.q: +t1 =. 1: #. 1: = (+.i.) +(t1 -: totient)"0 x=.>:?2 10$1000 + + +NB. f&.> ---------------------------------------------------------------- + +(100$<1) -: #&.>?100$1000 +(,&.>6 1 4 4) = $&.>;:'Cogito, ergo sum.' + +(<"0 (>x)+ >y) -: x +&.>y [ x=. ?1000 [ y=. ?1000 +(<"0 (>x)>.>y) -: x >.&.>y [ x=. ?1000 [ y=.<"0?1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?1000 [ y=. ?1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?1000 [ y=.<"0?1000 + +(<"0 (>x)+ >y) -: x +&.>y [ x=. ?1000 [ y=. ?100$1000 +(<"0 (>x)>.>y) -: x >.&.>y [ x=. ?1000 [ y=.<"0?100$1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?1000 [ y=. ?100$1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?1000 [ y=.<"0?100$1000 + +(<"0 (>x)+ >y) -: x +&.>y [ x=. ?100$1000 [ y=. ?1000 +(<"0 (>x)>.>y) -: x >.&.>y [ x=. ?100$1000 [ y=.<"0?1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?100$1000 [ y=. ?1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?100$1000 [ y=.<"0?1000 + +(<"0 (>x)+ >y) -: x +&.>y [ x=. ?100$1000 [ y=. ?100$1000 +(<"0 (>x)>.>y) -: x >.&.>y [ x=. ?100$1000 [ y=.<"0?100$1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?100$1000 [ y=. ?100$1000 +(<"0 (>x)* >y) -: x * &.>y [ x=.<"0?100$1000 [ y=.<"0?100$1000 + +'length error' -: (i.12) +&.> etx i.3 4 +'length error' -: (i.3 4) +&.> etx i.4 3 + +4!:55 ;:'t1 totient x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g631c.ijs @@ -0,0 +1,11 @@ +NB. u&.:v --------------------------------------------------------------- + +f0=: +/&.:*: +f1=: %: @: (+/) @: *: + +(f0 -: f1)"1 ] _50+?4 10 5$100 + + +4!:55 ;:'f0 f1' + +
new file mode 100644 --- /dev/null +++ b/test/g632.ijs @@ -0,0 +1,10 @@ +NB. &: ------------------------------------------------------------------ + +(+/~"1+:i.2 3) -: (i.2 3) +/& (+:"1) i.2 3 +(+/~ +:i.2 3) -: (i.2 3) +/&:(+:"1) i.2 3 + +'domain error' -: ". etx '3 &: +' +'domain error' -: ". etx '+ &: 3' +'domain error' -: ". etx '3 &: 3' + +
new file mode 100644 --- /dev/null +++ b/test/g640.ijs @@ -0,0 +1,273 @@ +NB. ?y ------------------------------------------------------------------ + +tick =: [ <.@%~ (* 3 : 'qrl=:(<:2^31)|(7^5)*qrl')@] +roll =: (<:2^31)&tick"0 + +NB. qrl =: 9!:0 '' +NB. (? -: roll) 1000000 +NB. (? -: roll) 2 3 4 $987654321 +NB. qrl -: 9!:0 '' + +test=: 3 : 0 + r=: ?y + assert. ($r) -: $y + assert. 0<:r + assert. r<y + 1 +) + +test 1+?2 3 4$100 +test 1+?100 +test 2 0 3$100 + +0 -: ?1 +1 -: 3!:0 ?2 3 4 5$2 + +(2^_53) = +./ ? 5e3 $ 0 +1 = +./@:?@:(5e3&$)"0 ] 10^1 2 6 8 9 +1 = +./@:?@:(5e3&$)"0 ] 2 ^1 3 5 7 8 13 23 30 +1 = +./@:?@:(5e3&$)"0 ] IF64#<.10^10 11 12 13 18 +1 = +./@:?@:(5e3&$)"0 ] IF64#<.2 ^32 33 34 43 47 53 62 + +zz =: 3.90 NB. Z(3.90)=0.99995 +mean=: +/ % # +var =: <:@# %~ +/@:*:@:(- mean) + +testmean=: 4 : 0 + m=: x + t=: y + c=: zz * (var t)%&%:#t + d=: (mean t) - |-:<:m + assert. c > | d + 1 +) + +test1=: 3 : 0 + y testmean 1e4 ?@$ y + y testmean ? 1e4 $ y +) + +test1 0 +test1"0 ] 10^1 2 6 7 8 9 +test1"0 ] 2*10^1 2 6 7 8 9 +test1"0 ] 2^1 2 3 4 5 28 29 30 +test1"0 ] 1+2^1 2 3 4 5 28 29 30 +test1"0 ] IF64#<. 10^10 11 17 18 +test1"0 ] IF64#<.4*10^10 11 17 18 +test1"0 ] IF64#<. 2^3 7 9 32 33 47 53 62 +test1"0 ] IF64#<. 1+2^3 7 9 32 33 47 53 62 +test1"0 ] IF64#<._1+2^3 7 9 32 33 47 53 62 + +test1"0 x: 5 555 55555 + +64 = 3!:0 ?10$20x + +'domain error' -: ? etx 'abc' +'domain error' -: ? etx 2 3 _4 +'domain error' -: ? etx 2 3.4 5 +'domain error' -: ? etx 2 3j4 5 +'domain error' -: ? etx 2 3;4 5 + +'domain error' -: ?@(*/) etx 'abc' + + +NB. x?y ----------------------------------------------------------------- + +bigdeal=: 4 : 0 + t=. 0 $ v=. y $~ <.1.11*x + while. x > #t do. t=. ~. roll v end. + x {. t +) + +roll =: ?. + +rix =: i.@[ ([ ,. [ + roll@:-~) ] +deal1=: [ {. <@~."1@|.@rix C. i.@-@] +deal =: deal1 ` bigdeal @. (< 0.01&*) NB. pre J 5.03 + +deal =: [ {. <@~."1@|.@rix C. i.@] NB. J 5.03 or later + +10 (?. -: deal) 100 +10 (?. -: deal) 1000 +10 (?. -: deal) 10000 + +NB. qrl =: 9!:0 '' +NB. (? -: deal)~ 100 +NB. 300 (? -: deal) 1000 +NB. a =. 10 20 30 +NB. b =. +: a +NB. (a?b) -: (a deal b) +NB. qrl -: 9!:0 '' + +test1=: 4 : 0 + r=. x?y + assert. ($r) -: ,x + assert. 0<:r + assert. r<y + assert. r -: ~.r + 1 +) + +10 test1 15 +10 test1 30 +10 test1 45 +4 test1 4+?100 +4 test1 4+?10000 +1 test1 1+?100 +1 test1 1+?10000 +0 test1 ?100 +0 test1 ?10000 +0 test1 0 + +10 test1 IF64{1e9 1e18 +10 test1 IF64{<:2^31 63 +10 test1 IF64{5+2^10 31 + +100 test1 100 + +'' -: 0?0 +'' -: 0?9 + +64 = 3!:0 ]20x?100 +64 = 3!:0 ]20 ?100x +64 = 3!:0 ]20x?100x + +'domain error' -: 2 ? etx 1 +'domain error' -: 4 ? etx 0 +'domain error' -: 4 ? etx 3 +'domain error' -: 3 ? etx 'abc' +'domain error' -: 3 ?~etx 'abc' +'domain error' -: 1 ? etx 2 3 _4 +'domain error' -: 5 ?~etx 2 3 _4 +'domain error' -: 2 ? etx 2 3.4 5 +'domain error' -: 5 ?~etx 2 3.4 5 +'domain error' -: 2 ? etx 2 3j4 5 +'domain error' -: 5 ?~etx 2 3j4 5 +'domain error' -: 2 ? etx 2 3;4 5 +'domain error' -: 2 ?~etx 2 3;4 5 + +'domain error' -: ?~@(*/) etx 'abc' + +'length error' -: 2 3 ? etx 4 5 6 + + +NB. Model of gb_flip ---------------------------------------------------- + +mod_diff=: (<._1+2^31)&(17 b.)@:- + +gb_next_rand=: 3 : 0 + if. 0 > gb_i do. gb_i=: <: # gb_A=: gb_flip_cycle gb_A end. + (gb_i=: <:gb_i) ] gb_i{gb_A +) + +gb_flip_cycle=: 3 : 0 + +/ (0 1 2=/<.(i.55)%24) * (mod_diff 31&|.)^:1 2 3~y +) + +gb_init_rand1=: 3 : 0 + prev=. s=. y mod_diff 0 NB. strip off the sign + seed=. (31$2) #: s + next=. 1 + z=. '' + for. i.54 do. + z=. z,next + t=. next + seed=. _1 |. seed NB. cyclic shift right 1 + next=. (prev mod_diff next) mod_diff #. seed + prev=. t + end. + s,~z /: 55|+/\54$21 +) + +gb_init_rand=: 3 : 0 + 0 0 $ gb_i=: _2 + # gb_A=: gb_flip_cycle^:5 gb_init_rand1 y +) + +roll=: 3 : 0 + assert. 0~:y + z=. i.0 + for_t. y (] - |) <.2^31 do. + while. t<:r=. gb_next_rand '' do. end. + z=. z,r + end. + ($y)$y|z +) + +roll0=: 3 : 0 + assert. 0=y + (2^53) %~ (2^31) #. |."1 (0 2^22)|"1 gb_next_rand"0 (($y),2)$0 +) + +gb_init_rand _314159 +119318998 -: gb_next_rand '' +1 [ gb_next_rand^:133 '' +748103812 -: roll 16#.8#5 + +gb_init_rand 7^5 +IF64 +. (?. -: roll) 10^i.7 + +NB. gb_init_rand 7^5 +NB. (?. -: roll0) 2 5$0 + + +NB. Model of lcg -------------------------------------------------------- + +lcg=: 3 : '2147483647&|@(16807&*)^:y 1x' NB. linear congruence generator + +test_lcg=: 3 : 0 + t=: x:^:_1 lcg 1+i.1597 + assert. ( 5{.t) -: 16807 282475249 1622650073 984943658 1144108930 + assert. (_5{.t) -: 1476003502 1607251617 2028614953 1481135299 1958017916 + 1 +) + +test_lcg 1 + + +NB. Model of dx-1597-4d ------------------------------------------------- + +B=: 1073741362x +M=: <._1+2^31 + +r1597=: lcg 1+i.1597 + +dx=: 3 : 0 + z=. M|B*+/r1597{~532*i.4 + r1597=: (}.r1597),z + z +) + +dx1=: 3 : 0 + z=. <. M|29746*M|36097*+/r1597{~532*i.4 + r1597=: (}.r1597),z + z +) + +test_dx=: 3 : 0 + r1597=: lcg 1+i.1597 + t=: dx^:(1+i.5000) 0 + assert. (( i.5){t) -: 221240004 2109349384 527768079 238300266 1495348915 + assert. ((5+i.5){t) -: 1589596592 1437773979 813027151 401290350 1732813760 + r1597=: x:^:_1 lcg 1+i.1597 + x=: dx1^:(1+i.5000) 0 + assert. t -: x + if. -.IF64 do. + i=: 9!:42 '' + 9!:43 ]3 + 9!:1 ]1 + x=: 128!:4 ]5000 + assert. t -: x + 9!:43 ]i + end. + 1 +) + +test_dx 1 + + +4!:55 ;:'a B b bigdeal c d deal deal1 dx dx1' +4!:55 ;:'gb_A gb_flip_cycle gb_i gb_init_rand gb_init_rand1 gb_next_rand' +4!:55 ;:'i lcg M m mean mod_diff n qrl r r1597 rix roll roll0 seed' +4!:55 ;:'t test test_dx test_lcg test1 testmean tick var x zz' + +
new file mode 100644 --- /dev/null +++ b/test/g640k.ijs @@ -0,0 +1,369 @@ +NB. x ?@$ y ------------------------------------------------------------- + +NRNG=: 5 NB. number of RNGs + +NB. Ewart Shaw, Hypergeometric Functions and CDFs in J, +NB. Vector 18.4, 2002 4. + +NB. erf, A&S table 7.1 +NB. normal cdf, A&S table 26.1 +NB. chi-square cdf, A&S table 26.8 + +erf =: 1 H. 1.5@*: * 2p_0.5&* % ^@:*: NB. A&S 7.1.21 +n01cdf =: -: @ >: @ erf @ %&(%:2) + +gamma =: ! & <: +ig0 =: 4 : '(1 H. (1+x) % x&((* ^) * (^ -)~)) y' +incgam =: ig0 % gamma@[ NB. incomplete gamma +chisqcdf =: incgam&-: + +NB. Stirling Numbers of the second kind. +NB. see Hui & Iverson, Representations of Recursion, APL95 +NB. {n,r} is r{s2 n + +s2=: 1: ` (i.@>: ((0,]) + [ * 0,~]) $:@<:) @. * + +sp=: 7!:2 + + +g0=: 2 3$(? @$)`(? @:$)`([: ? $)`(? @#)`(? @:#)`([: ? #) +g1=: 2 3$(?.@$)`(?.@:$)`([: ?. $)`(?.@#)`(?.@:#)`([: ?. #) +g =: g0,:g1 + +NB. test that special code is used by looking at space used + +test=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + h=: ,g + t=: 3 : '7!:5 <''y''' ?1e5$y + for_i. i.#h do. + f=: h@.i + s=: sp '1e5 f y' + assert. (IF64{0.01 0.015) > t%~|t-s + end. + 9!:43 j + 1 +) + +j=: 9!:42 '' +0 test :: 1: 2 NB. prime the pump +9!:43 j + +(i.NRNG) test"0/ 2 +(i.NRNG) test"0/ 1e9 + +test1=: 4 : 0 + h=: ,g + for_i. i.#h do. + f=: h@.i + assert. (,x) -: $ x f y + end. + 1 +) + +1e4 test1 2 +1e4 test1 1e9 + +test2=: 4 : 0 + h=: ,g + t=: 3!:0 ?yy=: y + for_i. i.#h do. + f=: h@.i + c=: x f etx y + assert. t = 3!:0 c + assert. (c-:<.c) *. (0<:c) *. c<y + end. + 1 +) + +1483 test2"0 >:i.2 10 +1483 test2"0] 2^i.10 +1483 test2 1e9 + +test3=: 4 : 0 NB. tests on ?. + j=. 9!:42 '' + 9!:43 ]1 + 9!:1 ]7^5 + t=: x h@.0 y + for_i. {: i. 2,-:#h do. + f=: h@.i + assert. t -: x f y + end. + 9!:43 j + 1 +) + +1229 test3"0 >:i.2 10 +1229 test3"0 ] 2^i.10 +1229 test3"0 ]10^i.10 + +test4=: 4 : 0 + h=: ,0{"2 g + for_i. i.#h do. + f=: h@.i + assert. x -: $x f y + end. + 1 +) + +1e8 100 0 2 test4"1 0 >: i.2 10 +1e8 100 0 2 test4"1 0 ]2^i.10 +13 97 7 test4 1000 + +test5=: 4 : 0 + h=: ,1{"2 g + for_i. i.#h do. + f=: h@.i + assert. (,+/x) -: $x f y + end. + 1 +) + +100 0 101 123 test5"1 0 >: i.2 10 +100 0 101 123 test5"1 0 ] 2^i.10 +97 13 test5 1e6 + +test6=: 4 : 0 + h=: ,0{"2 g + for_i. i.#h do. + f=: h@.i + assert. 'limit error' -: x f etx y + end. + 1 +) + +j=: 9!:42 '' +(10 100 1000, <.imax%1234) test6 100 +9!:43 j + +test7=: 4 : 0 + h=: ,1{"2 g + for_i. i.#h do. + f=: h@.i + assert. 'limit error' -: x f etx y + end. + 1 +) + +j=: 9!:42 '' +(1 0 1 * imax - 1e6 0 2e6) test7 100 +9!:43 j + +test8=: 4 : 0 + h=: ,g + for_i. i.#h do. + f=: h@.i + assert. 'domain error' -: x f etx y + end. + 1 +) + +j=: 9!:42 '' +'a' test8 12 +a: test8 12 +_35 test8 12 +3.5 test8 12 +3j5 test8 12 +10 test8 'a' +10 test8 a: +10 test8 _35 +10 test8 3.5 +10 test8 3j5 +9!:43 j + +(2^_53) = +./ 5e3 ?@$ 0 +1 = 5e3 ([: +./ ?@$)"0 ] 10^1 2 6 8 9 +1 = 5e3 ([: +./ ?@$)"0 ] 2 ^1 3 5 7 8 13 23 30 +1 = 5e3 ([: +./ ?@$)"0 ] IF64#<.10^10 11 12 13 18 +1 = 5e3 ([: +./ ?@$)"0 ] IF64#<.2 ^32 33 34 43 47 53 62 + +mean=: +/ % # +var =: <:@# %~ +/@:*:@:(- mean) + +test9=: 4 : 0 NB. mean test + j=. 9!:42 '' + 9!:43 x + yy=: y + t=: 2e4 ?@$ yy + d=: (%:var t) %~ | (mean t) - |-:<:yy + p=: n01cdf d + assert. p<0.99995 + 9!:43 j + 1 +) + +(i.NRNG) test9"0/ 0 +(i.NRNG) test9"0/ 10^1 2 6 8 9 +(i.NRNG) test9"0/ 2 ^1 3 5 7 8 13 23 30 +(i.NRNG) test9"0/ IF64#<.10^10 11 12 13 18 +(i.NRNG) test9"0/ IF64#<.2 ^32 33 34 43 47 53 62 + +test10=: 3 : 0 + j=. 9!:42 '' + 9!:43 y + xx=: 1e5 ?@$ 0 + assert. (0<xx)*.xx<1 + assert. (2^_53)=+./xx + 9!:43 j + 1 +) + +test10"0 i.NRNG + + +NB. tests from Knuth II, section 3.3.2 ---------------------------------- + +NB. equidistribution (frequency) test + +testa=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + n=: 20011 NB. number of trials + yy=: y + m=: 260<.yy+260*0=yy NB. 1+ degrees of freedom + e=: n%m NB. expected count + assert. 5 <: e + if. 0=yy do. d=: <.m* n ?@$ yy + elseif. m<yy do. d=: <.m*y%~n ?@$ yy + elseif. 1 do. d=: n ?@$ yy + end. + a=: <: #/.~ (i.m),d NB. actual counts + c=: e %~ +/ *: a - e NB. chi-square statistic + p=: (m-1) chisqcdf c + assert. (0.00001<p)*.p<0.99999 + 9!:43 j + 1 +) + +0 $ 0 : 0 +(i.NRNG) testa"0/ 0 +(i.NRNG) testa"0/ 6 10 100 +(i.NRNG) testa"0/ 2^1 2 3 4 5 6 7 8 +(i.NRNG) testa"0/ 2^28 30 , IF64#32 33 34 53 62 +(i.NRNG) testa"0/10^7 8 9 , IF64#16 17 18 +(i.NRNG) testa"0/13^6 7 8 , IF64#16 17 +2 testa"0 x: 5 55 +) + +NB. serial test: chi-square test on successive k-tuples + +testb=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + k=: 2 + n=: ]&.(p:^:_1)k*1e4 NB. number of trials + yy=: y + m=: yy^k NB. 1+ degrees of freedom + e=: n%k*m NB. expected count + assert. 5 <: e + d=: yy #. (-k) ]\ n ?@$ yy + a=: <: #/.~ (i.m),d NB. actual counts + c=: e %~ +/ *: a - e NB. chi-square statistic + p=: (m-1) chisqcdf c + assert. (0.0001<p)*.p<0.9999 + 9!:43 j + 1 +) + +0 $ 0 : 0 +(i.NRNG) testb"0/ 2 6 10 +2 testb"0 x: 2 22 +) + +NB. gap test: chi-square test on successive k-tuples + +testc=: 3 : 0 +) + +NB. poker (partition) test: chi-square test on # distinct values in groups of k + +testd=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + 'k d'=: y + n=: ]&.(p:^:_1) 2e4 + r=: i.1+k + x1=: #@~."1 (n,k) ?@$ d + ea=: n*(d^k)%~(s2 k)**/\1,d-i.k + m=: 1 i.~ 5<:+/\ ea + e=: (m>.r) +//. ea + assert. 5 <: e NB. expected counts + a=: <: #/.~ (m}.r),m>.x1 NB. actual counts + c=: +/ e %~ *: a - e NB. chi-square statistic + p=: (#e) chisqcdf c + assert. (0.0001<p)*.p<0.9999 + 9!:43 j + 1 +) + +0 $ 0 : 0 +(i.NRNG) testd"0 1/ _2]\ 5 10 5 13 7 23 7 29 13 52 +) + +NB. coupon collector's test: chi-square test on lengths of segments + +couplen=: 4 : 0 NB. Ewart Shaw, 2005-09-08 + p=. <: 2^x NB. number of states + s0=. p | (i.p) +."1/&.#: 2^i.x NB. transition table + s=. s0 ,"0 p{.2 NB. output when in state 0 + ijr=. 1 0 , 2^{.y NB. process {.y 'by hand' + }: {:"1 (2;s;'';ijr) ;: y +) + +teste=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + d=: y + t=: 4*d + r=: d+i.t-d + xx=: (d*5e4) ?@$ d + x1=: d couplen xx + n=: #x1 + e=: n*(((!d)%d^r)*(d-1)&{@s2"0 r-1),1-((!d)%d^t-1)*d{s2 t-1 + assert. 5 <: e NB. expected counts + a=: <: #/.~ (r,t),t<.x1 NB. actual counts + c=: +/ e %~ *: a - e NB. chi-square statistic + p=: (#e) chisqcdf c + assert. (0.0001<p)*.p<0.9999 + 9!:43 j + 1 +) + +0 $ 0 : 0 +(i.NRNG) teste"0/ 4 5 6 10 +2 teste 10 +) + +NB. permutation test: chi-square test on orderings of successive k-tuples + +testf=: 4 : 0 + j=. 9!:42 '' + 9!:43 x + k=: y + n=: k*1e3 NB. number of trials + m=: !k NB. 1+ degrees of freedom + e=: n%k*m NB. expected count + assert. 5 <: e + d=: A. /:"1 (-k) ]\ n ?@$ 0 + a=: <: #/.~ (i.m),d NB. actual counts + c=: e %~ +/ *: a - e NB. chi-square statistic + p=: (m-1) chisqcdf c + assert. (0.0001<p)*.p<0.9999 + 9!:43 j + 1 +) + +0 $ 0 : 0 +(i.NRNG) testf"0/ 3 4 5 +2 testf 5x +) + +4!:55 ;:'a c chisqcdf couplen d e ea erf f g g0 g1 gamma h ig0 incgam' +4!:55 ;:'j k m mean n n01cdf NRNG p r s s2 sp t' +4!:55 ;:'test test1 test10 test2 test3 test4' +4!:55 ;:'test5 test6 test7 test8 test9' +4!:55 ;:'testa testb testc testd teste testf' +4!:55 ;:'var x xx x1 y yy' + +
new file mode 100644 --- /dev/null +++ b/test/g640r.ijs @@ -0,0 +1,109 @@ +NB. ? different RNGs ---------------------------------------------------- + +NRNG=: 5 NB. number of RNGs + +'length error' -: 9!:42 etx 4 5 +'rank error' -: 9!:42 etx 0 +'rank error' -: 9!:42 etx i.2 3 + +'domain error' -: 9!:43 etx 'a' +'domain error' -: 9!:43 etx <3 +'domain error' -: 9!:43 etx 3.4 +'domain error' -: 9!:43 etx 3j4 +'domain error' -: 9!:43 etx _1 + +'rank error' -: 9!:43 etx ,1 +'rank error' -: 9!:43 etx 3 4 + +'length error' -: 9!:44 etx 4 5 +'rank error' -: 9!:44 etx 0 +'rank error' -: 9!:44 etx i.2 3 + + +NB. seed + +test0=: 3 : 0 + j=: 9!:42 '' + yy=: y + 9!:43 yy + p2=: 9!:44 '' [ p1=: 1000 ?@$ 0 [ p0=: 9!:44 '' [ 9!:1 ]1000003 + q2=: 9!:44 '' [ q1=: 1000 ?@$ 0 [ q0=: 9!:44 '' [ 9!:1 ]1000003 + assert. p0 -: q0 + assert. p1 -: q1 + assert. p2 -: q2 + 9!:43 j + 1 +) + +test0"0 i.NRNG + +NB. state + +test1=: 3 : 0 + j=: 9!:42 '' + yarg=: y + 9!:43 y + 1000 ?@$ 0 + t=: 9!:44 '' [ xx=: 1000 ?@$ 1e6 [ s=: 9!:44 '' + u=: 9!:44 '' [ yy=: 1000 ?@$ 1e6 [ 9!:45 s + assert. xx -: yy + assert. t -: u + 9!:43 j + 1 +) + +test1"0 i.NRNG + + +NB. preserving state under switching of RNGs + +test2=: 4 : 0 + j=: 9!:42 '' + xx=: x + yy=: y + 2003 ?@$ 1e6 [ 9!:1 ]12345 [ 9!:43 x + p0=: 17 ?@$ 1e6 + p0=: p0, 19 ?@$ 1e6 + p1=: 9!:44 '' + 2003 ?@$ 1e6 [ 9!:1 ]12345 [ 9!:43 x + q0=: 17 ?@$ 1e6 + 9!:43 y + 2003 ?@$ 1e6 + 9!:43 x + q0=: q0, 19 ?@$ 1e6 + q1=: 9!:44 '' + assert. p0 -: q0 + assert. p1 -: q1 + 9!:43 j + 1 +) + +test2/"1 (~:/"1 # ]) ,/,"0/~ i.NRNG + +NB. preserving state under switching of RNGs + +test2a=: 3 : 0 + j=: 9!:42 '' + yy=: y + 2003 ?@$ 1e6 [ 9!:1 ]12345 [ 9!:43 y + p0=: 17 ?@$ 1e6 + p0=: p0, 19 ?@$ 1e6 + p1=: 9!:44 '' + 2003 ?@$ 1e6 [ 9!:1 ]12345 [ 9!:43 y + q0=: 17 ?@$ 1e6 + 2003 ?.@$ 1e6 + q0=: q0, 19 ?@$ 1e6 + q1=: 9!:44 '' + assert. p0 -: q0 + assert. p1 -: q1 + 9!:43 j + 1 +) + +test2a"0 i.NRNG + + +4!:55 ;:'j NRNG p0 p1 p2 q0 q1 q2 s t ' +4!:55 ;:'test0 test1 test2 test2a u xx yarg yy' + +
new file mode 100644 --- /dev/null +++ b/test/g641.ijs @@ -0,0 +1,53 @@ +NB. ?.y ----------------------------------------------------------------- + +seed =. 9!:0 '' +x=.30$1e6 +a -: b [ a=.?.x [ b=.?.x +seed -: 9!:0 '' + +seed =. 9!:0 '' +(s$?.1e6) -: ?."0 s$1e6 [ s=.5 6 7 +seed -: 9!:0 '' + +'domain error' -: ?. etx 0 _1 +'domain error' -: ?. etx 'abc' +'domain error' -: ?. etx 2 3 _4 +'domain error' -: ?. etx 2 3.4 5 +'domain error' -: ?. etx 2 3j4 5 +'domain error' -: ?. etx 2 3;4 5 + +'domain error' -: ?.@(*/) etx 'abc' + + +NB. x?.y ---------------------------------------------------------------- + +seed=. 9!:0 '' +a -: b [ a=.?.~100 [ b=.?.~100 +seed -: 9!:0 '' + +seed=. 9!:0 '' +((s,16)$16?.17) -: 16 ?. s$17 [ s=.3 4 +((s,17)$17?.17) -: 17 ?. s$17 [ s=.3 4 +seed -: 9!:0 '' + +'domain error' -: 2 ?. etx 1 +'domain error' -: 4 ?. etx 0 +'domain error' -: 4 ?. etx 3 +'domain error' -: 3 ?. etx 'abc' +'domain error' -: 3 ?.~etx 'abc' +'domain error' -: 1 ?. etx 2 3 _4 +'domain error' -: 5 ?.~etx 2 3 _4 +'domain error' -: 2 ?. etx 2 3.4 5 +'domain error' -: 5 ?.~etx 2 3.4 5 +'domain error' -: 2 ?. etx 2 3j4 5 +'domain error' -: 5 ?.~etx 2 3j4 5 +'domain error' -: 2 ?. etx 2 3;4 5 +'domain error' -: 2 ?.~etx 2 3;4 5 + +'domain error' -: ?.~@(*/) etx 'abc' + +'length error' -: 2 3 ?. etx 4 5 6 + +4!:55 ;:'a b s seed x' + +
new file mode 100644 --- /dev/null +++ b/test/g6x.ijs @@ -0,0 +1,245 @@ +NB. 6!: ----------------------------------------------------------------- + +ts =: 6!:0 +tss =: 6!:1 +time =: 6!:2 +dl =: 6!:3 + +t =: ts '' +6 = $t +(-: <.) 5{.t +*./0<:t +1990<:0{t +*./ (1&<: *. <:&12 31) 1 2{t +24 60 60 *./ . > 3 4 5{t + +NB. 0.5>|(x=:t-~tss '')-[dl 5 [ t=:tss '' + +0<:time 't=:+/i.5000' +t -: +/i.5000 +NB. 0.5>|5-x=:time 'dl 5' + +'domain error' -: time etx 0 1 +'domain error' -: time etx 3 4 _5 +'domain error' -: time etx 3j4 +'domain error' -: time etx 3;4 5 + +'domain error' -: 'j' time etx '3+4' +'domain error' -: 3.4 time etx '3+4' +'domain error' -: 3j4 time etx '3+4' +'domain error' -: (3;4) time etx '3+4' +'domain error' -: 3r4 time etx '3+4' + +'domain error' -: dl etx '5' +'domain error' -: dl etx 3j4 +'domain error' -: dl etx <3 + + +NB. 6!:8 and 6!:9 ------------------------------------------------------ + +qpf=: 6!:8 +qpc=: 6!:9 + +x=: qpf '' +8 = type x +0 = #$x +0 < x + +x=: qpc"1 i.21 0 +8 = type x +1 = #$x +0 <: x +(}.x) >: }:x + + +NB. 6!:10 11 12 13 ------------------------------------------------------ + +bpe =: IF64{28 56 NB. bytes per entry +bhdr =: IF64{16 32 NB. bytes for header + +pmdata =: 6!:10 +pmunpack=: 6!:11 +pmctr =: 6!:12 +pmstats =: 6!:13 + +0 = pmdata '' +0 = 5{pmstats '' +'domain error' -: pmctr etx 0 + +avg=: 3 : 0 + n=. #y + s=. +/ y + s % n +) + +200 -: x=: pmdata (bhdr+bpe*200)$'c' + +1 = x=: pmctr 1 +1 = 5{pmstats '' +n=: 1+?35 +1 [ avg"1 ?(n,11)$1000 +0 = x=: pmctr _1 + +s=: pmstats '' +t=: pmunpack '' + +4 = type s +s -: 0 0 200,(200<.4+2*n),(200<:4+2*n),0 + +f=: 4 : 0 + t=. y + assert. (32=type t) *. ((,7) -: $t) *. (*./ 1 = #@$&>t) *. *./ x = 6{.#&>t + assert. (type&.>t) e.&> 4;4;4;4;1 4 8;1 4 8;32 + assert. *./ (>0{t) e. i.#>6{t + assert. *./ (>1{t) e. i.#>6{t + assert. *./ (>2{t) e. 1 2 + assert. (xx -: <.xx) *. *./ 0 <: xx=: >4{t + assert. (*./ 0<:xx) *. *./ (}.xx) >: }:xx=: >5{t + assert. (*./ (xx e. a:) +. 2=type&>xx) *. *./ 1 = #@$&>xx=: >6{t + 1 +) + +(4+2*n) f t +({&:>/0 6{t) -: (1 2,(2*n),1)#;:'pmctr pmstats avg pmctr' +({&:>/1 6{t) e. <'base' +(>3{t) -: _2 _1 _2,((2*n)$_1 _2),_1 + +200 -: x=: 1 0 pmdata (bhdr+bpe*200)$'c' + +1 = x=: pmctr 1 +1 = 5{pmstats '' +n=: 1+?35 +1 [ avg"1 ?(n,11)$1000 +0 = x=: pmctr _1 + +s=: pmstats '' +t=: pmunpack '' + +4 = type s +s -: 1 0 200,(200<.4+5*n),(200<:4+5*n),0 + +(4+5*n) f t +({&:>/0 6{t) -: (1 2,(5*n),1)#;:'pmctr pmstats avg pmctr' +({&:>/1 6{t) e. <'base' +(>3{t) -: _2 _1 _2,((5*n)$_1 0 1 2 _2),_1 + +sum_foo_=: 3 : 0 + +/y +) + +sum_z_=: sum_foo_ + +mean_l6x_=: 3 : 0 + (sum y) % #y +) + +100 -: 1 pmdata (bhdr+bpe*100)$'x' +1 -: pmctr 1 +1 [ mean_l6x_ i.12 +0 -: pmctr _1 +t=: 6!:11 '' +10 f t +({&:>/0 6{t) -: ;:'pmctr mean_l6x_ mean_l6x_ sum sum_foo_ sum_foo_ sum_foo_ sum mean_l6x_ pmctr' +({&:>/1 6{t) -: ;:'base l6x l6x l6x foo foo foo l6x l6x base' + +mean_aa_=: 3 : 0 + sum=. +/ + (sum y) % #y +) + +100 -: 1 pmdata (bhdr+bpe*100)$'x' +1 -: pmctr 1 +1 [ mean_aa_ i.12 +0 -: pmctr _1 +t=: 6!:11 '' +8 f t +({&:>/0 6{t) -: ;:'pmctr mean_aa_ mean_aa_ mean_aa_ sum sum mean_aa_ pmctr' +({&:>/1 6{t) -: ;:'base aa aa aa aa aa aa base' + +f=: 255$'a' +12 -: ". f,'=: 12' +4!:55 <f + +sp=: 7!:0 +m=: sp '' +m=: sp '' + +". f,'=: 3 : ''(+/y) % #y''' +20000 -: x=: pmdata (bhdr+bpe*20000)$'c' +1 = pmctr 1 +1 [ ". f,' i.1234' +0 = pmctr _1 +1 [ pmunpack '' +0 = pmdata '' +4!:55 <f + +100 > (sp '') - m + +". f,'=: 3 : ''(+/y) % #y''' +100 -: pmdata (bhdr+bpe*100)$'c' +1 = pmctr 1 +1 [ ". f,'"1 i.100 14' +0 = pmctr _1 +0 0 100 100 1 0 -: pmstats '' +1 [ pmunpack '' +0 = pmdata '' +4!:55 <f + +100 > (sp '') - m + +0 -: pmdata '' + +'domain error' -: pmdata etx 1 0 1 +'domain error' -: pmdata etx 1 2 3 +'domain error' -: pmdata etx 1.2 3 +'domain error' -: pmdata etx 1j2 3 +'domain error' -: pmdata etx 1 2 3x +'domain error' -: pmdata etx 1r2 3 + +'rank error' -: pmdata etx 3 20$'a' + +'domain error' -: 1 2 pmdata etx 20$'x' +'domain error' -: 1.2 pmdata etx 20$'x' +'domain error' -: 1j2 pmdata etx 20$'x' +'domain error' -: 1 2x pmdata etx 20$'x' +'domain error' -: 1r2 pmdata etx 20$'x' +'domain error' -: '01' pmdata etx 20$'x' +'domain error' -: (1;0) pmdata etx 20$'x' + +'rank error' -: (1 2$0) pmdata etx 20$'x' + +'length error' -: 0 1 0 pmdata etx 20$'x' + +'domain error' -: pmctr etx 1.5 +'domain error' -: pmctr etx 1j5 +'domain error' -: pmctr etx 10^100x +'domain error' -: pmctr etx 1r5 +'domain error' -: pmctr etx <2 + +'rank error' -: pmctr etx 1 2 + +'domain error' -: pmunpack etx '' + +1 [ pmdata 5000$'c' +1 = pmctr 1 +1 [ avg"1 i.3 12 +0 = pmctr _1 +7 -: # pmunpack '' + +'domain error' -: pmunpack etx 1.2 3 +'domain error' -: pmunpack etx 1j2 3 +'domain error' -: pmunpack etx 1r2 3 +'domain error' -: pmunpack etx 1;2 3 + +'index error' -: pmunpack etx 8 +'index error' -: pmunpack etx _9 + +0 -: pmdata '' + +18!:55 ;:'aa l6x foo' + +4!:55 ;:'avg bhdr bpe dl f m n ' +4!:55 ;:'pmctr pmdata pmstats pmunpack qpc qpf ' +4!:55 ;:'s sp sum_z_ t time ts tss x xx ' + +
new file mode 100644 --- /dev/null +++ b/test/g6x0.ijs @@ -0,0 +1,31 @@ +NB. 6!:0 ---------------------------------------------------------------- + +ts=: 6!:0 + +t=: ts '' +(,6) = $t +(-: <.) 5{.t +*./ 0 <: t +1990 <: 0{t +*./ (1&<: *. <:&12 31) 1 2{t +24 60 60 *./ . > 3 4 5{t + +t=: ts x=: 'YYYY-MM-DD hh:mm:ss.sss' +t -:&$ x +t -:&(3!:0) x +t -:&((-.x e. 'YMDhms')&#) x + +'domain error' -: ts etx 3 4 5 +'domain error' -: ts etx <'YYYY-MM-DD hh:mm:ss.sss' + +'rank error' -: ts etx ,: 'YYYY-MM-DD hh:mm:ss.sss' + +1 [ 6!:3 (55&< * 60&-) 5{ts '' NB. delay til a new minute if close to it +(}.;'-'&,@}.@":&.>10000 100 100+3{.ts '') -: ts 'YYYY-MM-DD' +(ts -: ts@u:) 'YYYY-MM-DD' +(ts -: ts@u:) 'MM/DD/YY hh:mm' +(":{.ts '') -: ts 'YYYY' +(_2{.":{.ts '') -: ts 'YY' + + +4!:55 ;:'t ts x'
new file mode 100644 --- /dev/null +++ b/test/g7x.ijs @@ -0,0 +1,88 @@ +NB. 7!: ----------------------------------------------------------------- + +NB. Testing malloc/free; try f 200 or g 40000, etc. + +sp =: 7!:0 +space=:7!:2 + +pr =: [ NB. for silent iteration +NB. pr =: 1!:2&2 NB. to see each iteration + +f =: 3 : 0 + old=.sp '' + whilst. y=.<:y do. + pr y + end. + old,sp '' +) + +g =: 3 : 0 + old=.sp '' + whilst. y=.<:y do. + t=.(?20000)$a. + pr y + end. + old,sp '' +) + +h =: 3 : 0 + old=.sp '' + whilst. y=.<:y do. + n=.>:?50 + a=. (n,n) ?@$ 5000 + b=.%.a + d=.>./|,(=i.n)-a+/ . *b + pr y,n,d + end. + old,sp '' +) + +x=:20 +y=:20 +s=: 2 3 + +x =: sp '' +s =: f 30+?200 +y =: sp '' +x -: y + +x =: sp '' +s =: g 30+?200 +y =: sp '' +x -: y + +x =: sp '' +s =: h 3+?7 +y =: sp '' +x -: y + +t =: sp '' +0 = $$t +t = <.t +0<:t + +0<space 't=:i.100' +t-:i.100 +(IF64{1064 2500)>|(n*IF64{4 8)-space 'i.n' [ n=:1000 +(IF64{1064 2500)>|(n*IF64{4 8)-space 'i.n' [ n=:2000 + +'domain error' -: 7!:2 etx 0 1 +'domain error' -: 7!:2 etx 3 4 _5 +'domain error' -: 7!:2 etx 3j4 +'domain error' -: 7!:2 etx 3;4 5 + + +NB. 7!:3 ---------------------------------------------------------------- + +t=:7!:3 '' +t -: <.t +0 < t +2 -: #$t +2 -: {:$t +t -: /:~t +*./~:{."1 t + + +4!:55 ;:'f g h n old pr s sp space t x y ' + +
new file mode 100644 --- /dev/null +++ b/test/g7x5.ijs @@ -0,0 +1,141 @@ +NB. 7!:5 ---------------------------------------------------------------- + +bp=: (IF64{1 1 4 8 16 4 4 2,:1 1 8 8 16 8 8 2) {~ 1 2 4 8 16 32 65536 131072 i. 3!:0 +sp=: 7!:5 +f =: 3 : '7!:5 <''y''' + +g =: 3 : 0 + w=. IF64{4 8 + z=. w*2 NB. 2 words for memory management + z=. z + w*7 NB. 7 words for non-shape header words + z=. z + w*r+(-.IF64)*0=2|r=. #$y NB. shape, pad to doubleword boundary if 32 bits + z=. z + ((bp y)**/$y) + w*(3!:0 y)e. 1 2 131072 NB. atoms & trailing 0 byte + >.&.(2&^.) z +) + +(f -: g) 23 +(f -: g) 2.3 +(f -: g) 2j3 +(f -: g) 2j3 +(f -: g) u: 'a' +(f -: g) {.s: ' ab' + +(f -: g)@($& 0 1 )"0 ]200+i.4 10 +(f -: g)@($& 'x' )"0 ]200+i.4 10 +(f -: g)@($&(u: 'x'))"0 ]100+i.4 10 +(f -: g)@($& 0 1 )"0 ]160+i.4 10 +(f -: g)@($& 'x' )"0 ]160+i.4 10 +(f -: g)@($&(u: 'x'))"0 ] 80+i.4 10 + +(f -: g)@($& 0 1 )"1 ]1,"0 ] 200+i.4 10 +(f -: g)@($& 'x' )"1 ]1,"0 ] 200+i.4 10 +(f -: g)@($&(u: 'x'))"1 ]1,"0 ] 100+i.4 10 +(f -: g)@($& 0 1 )"1 ]1,"0 ] 160+i.4 10 +(f -: g)@($& 'x' )"1 ]1,"0 ] 160+i.4 10 +(f -: g)@($&(u: 'x'))"1 ]1,"0 ] 80+i.4 10 + +(f -: g) x=: (?1e4)$1 0 +(f -: g) x=: (?1e4)$2 3 +(f -: g) x=: (?1e4)$2.3 +(f -: g) x=: (?1e4)$2j3 +(f -: g) x=: (?1e4)$2j3 +(f -: g) x=: (?1e4)$u: 'ab' +(f -: g) x=: (?1e4)$s: ' ab c' + +(f -: g) x=: (1+?100 100)$1 0 +(f -: g) x=: (1+?100 100)$2 3 +(f -: g) x=: (1+?100 100)$2.3 +(f -: g) x=: (1+?100 100)$2j3 +(f -: g) x=: (1+?100 100)$2j3 +(f -: g) x=: (1+?100 100)$u: 'ab' +(f -: g) x=: (1+?100 100)$s: ' ab c' + +(f -: g) x=: (1+?100 10 50)$1 0 +(f -: g) x=: (1+?100 10 50)$2 3 +(f -: g) x=: (1+?100 10 50)$2.3 +(f -: g) x=: (1+?100 10 50)$2j3 +(f -: g) x=: (1+?100 10 50)$2j3 +(f -: g) x=: (1+?100 10 50)$u: 'ab' +(f -: g) x=: (1+?100 10 50)$s: ' ab c' + +(sp ;:'f g sp') -: (sp <'f'),(sp <'g'),sp <'sp' + +(sp <'sp') -: sp <'sp_base_' +(sp <'f' ) -: sp <'f__x' [ x=: <'base' + +0 <: f 5!:1 <'bp' + +x=: 3 : 0 + if. y do. c=.1 else. c=.2 end. + c +) + +0 <: sp <'x' + +x=: 4 : 0 + if. x<y do. c=.10 else. c=.20 end. + s=. 0 + for_xyz. i.c do. + s=. xyz+s + end. +) + +0 <: sp <'x' + +x=: 2 : 0 + : + select. x + case. 1 do. u y + case. 2 do. u 2*y + fcase. 3 do. 3*y + case. 4 do. u 4*y + end. +) + +0 <: sp <'x' +0 < 7!:5 <'x' [ x=: 9e4 $ <2e4$0 +0 < 7!:5 <'x' [ x=: 9e4 $ <4e4$0 + +'value error' -: 7!:5 etx <'nonexistent' + +'domain error' -: 7!:5 etx <i.4 +'domain error' -: 7!:5 etx <1 2.3 4 +'domain error' -: 7!:5 etx <1 2j3 4 +'domain error' -: 7!:5 etx <u: 'abc' +'domain error' -: 7!:5 etx <s: ' bc' +'domain error' -: 7!:5 etx <<'abc' +'domain error' -: 7!:5 etx i.4 +'domain error' -: 7!:5 etx 1 2.3 4 +'domain error' -: 7!:5 etx 1 2j3 4 +'domain error' -: 7!:5 etx u: 'abc' +'domain error' -: 7!:5 etx s: ' bc' + +'rank error' -: 7!:5 etx <,:'abc' + +'ill-formed name' -: 7!:5 etx <'bad name' +'ill-formed name' -: 7!:5 etx <'' + + +NB. 7!:5 on mapped arrays ----------------------------------------------- + +load'jmf' +18!:4 <'base' +1 [ unmap_jmf_ 'q' +f=: <jpath '~temp\q.jmf' +1 [ createjmf_jmf_ f,<3e5 NB. 3e5 bytes for data +map_jmf_ (<'q'),f,'';0 NB. map q to jmf file +'' -: q + +(7!:5 <'q') -: 7!:5 <'x' [ q=:x=: (?1e4)?@$2 +(7!:5 <'q') -: 7!:5 <'x' [ q=:x=: a.{~(?1e4)?@$#a. +(7!:5 <'q') -: 7!:5 <'x' [ q=:x=: (?100 100)?@$1e6 +(7!:5 <'q') -: 7!:5 <'x' [ q=:x=: o.(?30 30 30)?@$1e6 +(7!:5 <'q') -: 7!:5 <'x' [ q=:x=: j./(2,?100 100)?@$1e6 + +1 [ unmap_jmf_ 'q' +18!:55 <'jmf' + + +4!:55 ;:'bp f g q sp x' + +
new file mode 100644 --- /dev/null +++ b/test/g7x6.ijs @@ -0,0 +1,55 @@ +NB. 7!:6 ---------------------------------------------------------------- + +(7!:6 <'') -: 7!:6 <'base' + +spn=: 3 : '>.&.(2&^.) k*2+7+1+4+1+>.(#y)%k=.IF64{4 8' NB. space needed for a name +NB. 2 MS struct +NB. 7 header words +NB. 1 shape +NB. 4 NM struct +NB. 1 trailing 0 pad +NB. #y letters in the name + +spl=: 4 : 0 NB. space needed for locale y with hash table size x + z=. spn >y NB. locale name + z=. z+(IF64{4 8)*2^6+x NB. hash table + z=. z+7!:5 <'p' [ p=. 18!:2 y NB. path + z=. z+ (+/spn&> v) + +/ (IF64{24 48) + 7!:5 v=. ,&('_',(>y),'_')&.>(nl__y '')-.;:'x y' +) + +sp_z_=: 7!:5 + +18!:55 <'abc' +(<'abc') -: (h=:3) (18!:3) <'abc' +foot_abc_=: i.3 4 +charboil_abc_=: 123$'x' +jajabinks_abc_ =: !100x +(p=: ;:'z base j') 18!:2 <'abc' +NB. (7!:6 <'abc') -: ((spn 'abc')+(4*2^6+h)+sp <'p') + (+/spn&> nl_abc_ '') + +/ 24+sp_abc_ nl_abc_ '' +(7!:6 <'abc') -: h spl <'abc' +18!:55 <'abc' + +'locale error' -: 7!:6 etx <'nonexistent' +'locale error' -: 7!:6 etx <'123789456' + +'domain error' -: 7!:6 etx <i.4 +'domain error' -: 7!:6 etx <1 2.3 4 +'domain error' -: 7!:6 etx <1 2j3 4 +'domain error' -: 7!:6 etx <u: 'abc' +'domain error' -: 7!:6 etx <s: ' bc' +'domain error' -: 7!:6 etx <<'abc' +'domain error' -: 7!:6 etx i.4 +'domain error' -: 7!:6 etx 1 2.3 4 +'domain error' -: 7!:6 etx 1 2j3 4 +'domain error' -: 7!:6 etx u: 'abc' +'domain error' -: 7!:6 etx s: ' bc' + +'rank error' -: 7!:5 etx <,:'abc' + +'ill-formed name' -: 7!:5 etx <'bad name' +'ill-formed name' -: 7!:5 etx <'' + + +4!:55 ;:'h p sp_z_ spl spn' + +
new file mode 100644 --- /dev/null +++ b/test/g8x.ijs @@ -0,0 +1,775 @@ +NB. 8!:n ---------------------------------------------------------------- + +NB. require 'numeric' NB. for round +round=: [ * [: <. 0.5 + %~ + +afzrnd=: *@] * [ round |@] NB. away from zero rounding + +fmt =: 8!:0 +fmt1=: 8!:1 +fmt2=: 8!:2 +NB. or +NB. load j model + +t=: '' fmt y=: 0.01 * _2000 + 4 5 ?@$ 10000 +32=type t +($t) -: $y +2=type&>t +-. ' 'e.&>t +-. '_'e.&>t +(0>y)='-'={.&>t + +('' fmt i.0) -: '' fmt '' +('' fmt s$0) -: '' fmt s$'' [ s=: 0 (?5)}5 ?@$ 10 + +(":&.>y) -: '0' fmt y=: 10 ?@$ 100 +(":&.>y) -: '0' fmt y=: 2 3 10 ?@$ 100 + +('domain error';'assertion failure') e.~< 3 fmt etx i.2 3 +('domain error';'assertion failure') e.~< 'cc' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 'clc' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 'p<x>r<*>p(y)' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 'p<x({open[})' fmt etx i.2 3 + +('rank error' ;'assertion failure') e.~< '' fmt1 etx i.2 3 4 +('rank error' ;'assertion failure') e.~< '' fmt2 etx i.2 3 4 + +('length error';'assertion failure') e.~< ',,' fmt etx i.2 4 +('length error';'assertion failure') e.~< (3$<'') fmt etx i.2 4 + +('rank error' ;'assertion failure') e.~< '' fmt etx 2 ;2 3$'abc' +('rank error' ;'assertion failure') e.~< '' fmt etx 2 3;'abc' + + +NB. 8!:n : various right arguments -------------------------------------- + +(<@,"1 x) -: '' fmt x=: 'abc' +(<@,"1 x) -: '' fmt x=: a. +(<@,"1 x) -: '' fmt x=: a. {~ 2 3 4 ?@$ #a. +(<@,"1 x) -: '' fmt x=: 2 3 0 4$'' +(<@,"1 x) -: '' fmt x=: 2 3 0 4$0 + +('' fmt 123;'') -: '' fmt 123;i.0 + + +NB. 8!:n : insufficient width ------------------------------------------- + +(<8$'*') -: '8.2' fmt 123456.7 +(<8$'*') -: 'c8.2' fmt 12345.7 +(<8$'*') -: '8.2' fmt _12345 +(<8$'*') -: 'c8.2' fmt _1234 + + +NB. 8!:n : b modifier --------------------------------------------------- + +(2$<'nil') -: 'b<nil>2' fmt 0.004 _0.004 +(2$<'') -: 'b2' fmt 0.004 _0.004 + +('0.01';'-0.01') -: 'b<nil>2' fmt 0.005 _0.005 +('0.01';'-0.01') -: 'b<nil>2' fmt 0.006 _0.006 + + +NB. 8!:n : c modifier --------------------------------------------------- + +(< '1,234.56') -: 'c2' fmt 1234.56 +(<'-1,234.56') -: 'c2' fmt _1234.56 + +(,'1') -: > 'c' fmt 1 + '12' -: > 'c' fmt 12 + '123' -: > 'c' fmt 123 + '1,234' -: > 'c' fmt 1234 + '12,345' -: > 'c' fmt 12345 + '123,456' -: > 'c' fmt 123456 + '1,234,567' -: > 'c' fmt 1234567 + '12,345,678' -: > 'c' fmt 12345678 + '123,456,789' -: > 'c' fmt 123456789 + '1,234,567,890' -: > 'c' fmt 1234567890 + '1.234567890e10'-: > 'c' fmt 12345678901 + +(,'-1') -: > 'c' fmt _1 +'-12' -: > 'c' fmt _12 +'-123' -: > 'c' fmt _123 +'-1,234' -: > 'c' fmt _1234 +'-12,345' -: > 'c' fmt _12345 +'-123,456' -: > 'c' fmt _123456 +'-1,234,567' -: > 'c' fmt _1234567 +'-12,345,678' -: > 'c' fmt _12345678 +'-123,456,789' -: > 'c' fmt _123456789 +'-1,234,567,890' -: > 'c' fmt _1234567890 +'-1.234567890e10'-: > 'c' fmt _12345678901 + +('domain error';'assertion failure') e.~< 'c<xx>' fmt etx 2 3 4 + + +NB. 8!:n : l modifier --------------------------------------------------- + +(<'234.56 ') -: 'l9.2' fmt 234.56 +(<' 234.56') -: '9.2' fmt 234.56 + +(<'-234.56 ') -: 'l9.2' fmt _234.56 +(<' -234.56') -: '9.2' fmt _234.56 + +NB. ('domain error';'assertion failure') e.~< 'l3' fmt etx 2 3 4 +('domain error';'assertion failure') e.~< 'l<xx>' fmt etx 2 3 4 + + +NB. 8!:n : m & n modifiers ---------------------------------------------- + +(<'mmm123.45nn') -: 'm<mmm>n<nn>' fmt _123.45 +(<,'0') -: 'm<mmm>n<nn>' fmt 0 +(<'0.00') -: 'm<mmm>n<nn>2' fmt 0.004 +(<'0.00') -: 'm<mmm>n<nn>2' fmt _0.004 + +(<'123.45') -: 'm<mmm>n<nn>' fmt 123.45 + + +NB. 8!:n : p & q modifiers ---------------------------------------------- + +(<'ppp123.45qq') -: 'p<ppp>q<qq>' fmt 123.45 +(<'ppp0qq') -: 'p<ppp>q<qq>' fmt 0 +(<'ppp0.00qq') -: 'p<ppp>q<qq>2' fmt 0.004 +(<'ppp0.00qq') -: 'p<ppp>q<qq>2' fmt _0.004 + +(<'-123.45') -: 'p<ppp>q<qq>' fmt _123.45 + + +NB. 8!:n : r modifier --------------------------------------------------- + +'abababa12345.67' -: > 'r<ab>15.2' fmt y=: 12345.67 +'ababa++12345.67' -: > 'p<++>r<ab>15.2' fmt y +'ababab-12345.67' -: > 'r<ab>15.2' fmt -y +'ababa12345.67--' -: > 'n<-->r<ab>15.2' fmt -y +'12345.67abababa' -: > 'lr<ab>15.2' fmt y +'ababab12,345.67' -: > 'cr<ab>15.2' fmt y + + +NB. 8!:n : s modifier --------------------------------------------------- + +y=: 0.01 * _3000 + 4 5 ?@$ 10000 + +(0>y)='~'={.&>'s<-~>' fmt y + +s=: '' fmt y +t=: 's<.!>' fmt y +s ([: *./ = +. '.'&i.@[ = '!'&i.@])&> t + +s=: '' fmt y +t=: 's<-~.!>' fmt y +s ([: *./ = +. '-.'&i.@[ = '~!'&i.@])&> t + +(<'1 234,56') -: 'cs<, .,>2' fmt 1234.56 +(<'1.234^19') -: 's<e^>' fmt 1.234e19 +(<'!!!!!!!!') -: 'cs<*!>8.2' fmt 12345 + +('domain error';'assertion failure') e.~< 's< $>' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 's<1 >' fmt etx i.2 3 + +('domain error';'assertion failure') e.~< 's<.>' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 's<. *>' fmt etx i.2 3 +('domain error';'assertion failure') e.~< 's<. .,>' fmt etx i.2 3 + + +NB. 8!:n : # of decimal places ------------------------------------------ + +(<x) -: '' fmt ".x=: '5','' +(<x) -: '' fmt ".x=: '5.1' +(<x) -: '' fmt ".x=: '5.12' +(<x) -: '' fmt ".x=: '5.123' +(<x) -: '' fmt ".x=: '5.1234' +(<x) -: '' fmt ".x=: '5.12345' +(<x) -: '' fmt ".x=: '5.123456' +(<x) -: '' fmt ".x=: '5.1234567' +(<x) -: '' fmt ".x=: '5.12345678' +(<x) -: '' fmt ".x=: '5.123456789' + +(< '12') -: '' fmt 12 +(<'-12') -: '' fmt _12 +(<,'0' ) -: '' fmt 0 + +NB. the next line occassionally fails for having the "wrong" value of x on the +NB. left side 'cause it pastes in the value from above. This happens when you +NB. run 0!:2 from inside an explicit verb. Presumably this is because of x=. +NB. vs x=: I believe this is actually the correct behavior. +x -: ''&fmt@".&> x=: '1.' &,&.> (}.i.10){.&.> <'123456789' +x -: ''&fmt@".&> x=: '12345.' &,&.> (}.i.10){.&.> <'123456789' +x -: ''&fmt@".&> x=: '1234567890.'&,&.> (}.i.5 ){.&.> <'123456789' + +x -: ''&fmt@".&> x=: '-1.' &,&.> (}.i.10){.&.> <'123456789' +x -: ''&fmt@".&> x=: '-12345.' &,&.> (}.i.10){.&.> <'123456789' +x -: ''&fmt@".&> x=: '-1234567890.'&,&.> (}.i.5 ){.&.> <'123456789' + + +NB. 8!:n : various data types ------------------------------------------- + +('' fmt y) -: '' fmt x: y=: 0.01 * 3 4 ?@$ 1000 +('' fmt y) -: '' fmt (-~0.5)+ y=: 3 4 ?@$ 2 +('' fmt y) -: '' fmt (-~0.5)+ y=: 3 4 ?@$ 1000 +('' fmt y) -: '' fmt (-~0j5)+ y=: 0.01 * 3 4 ?@$ 1000 +('' fmt y) -: '' fmt $. y=: 0.01 * 3 4 ?@$ 1000 + +(( u:'5') fmt y) -: '5' fmt y=: 3 4 ?@$ 0 +((<u:'5') fmt y) -: (<'5') fmt y=: 3 4 ?@$ 0 + +('domain error';'assertion failure') e.~< '' fmt etx 1 2 3 4j5 + +('rank error'; 'assertion failure') e.~< '' fmt etx 1 2;3 +('rank error'; 'assertion failure') e.~< '' fmt etx 1;i.2 3 + +('rank error'; 'assertion failure') e.~< (3 3$'4') fmt etx i.2 3 + + +NB. 8!:n : miscellaneous regression checks ------------------------------ + +('' fmt y) -: ($0) fmt y=: 0.01 * _2000 + 4 5 ?@$ 10000 + +(<@,"0 '01234') -: fmt i.5 + +a: -: fmt '' +a: -: '' fmt '' + +('3e9';,'3') -: '' fmt 3e9 3 +('3e9';,'3') -: fmt 3e9 3 + +(<;._1' na1 __ na2 na3e-10 3e-10') -: 'm<na>s<-->' fmt _1 __ _2 _3e_10 3e_10 +(<;._1' na1 __ na2 na3e-10 3e-10') -: 'm<na>' fmt _1 __ _2 _3e_10 3e_10 + +((0$a:)&fmt -: ''&fmt) 1p1 +((0$a:)&fmt -: ''&fmt) i.3 + +(,3) -: $'' fmt1 i.3 +1 3 -: $fmt2 i.3 +1 0 -: $fmt2 i.0 + +((<y) -: x fmt y)*. ((,<,:y) -: x fmt1 y)*. (,:y) -: x fmt2 y=:'abc' [ x=:1p1 +((<y) -: x fmt y)*. ((,<,:y) -: x fmt1 y)*. (,:y) -: x fmt2 y=:'abc' [ x=:0j1 +((<y) -: x fmt y)*. ((,<,:y) -: x fmt1 y)*. (,:y) -: x fmt2 y=:'abc' [ x=:'s<X>' + +(<'_3') -: 's<-_>' fmt _3 + +(<14{.x) -: 'c' fmt 0".x=:'-219.47193390041042' + +('12345.0';'0.0';'0.5') -: '' fmt 12345 0 0.5 +(<;._1 x) -: '' fmt ".x=:' 889.460 219.138 786.039 922.395 991.019' + +NB. 8!:n : d modifier --------------------------------------------------- + +(<,'_') -: '' fmt _ +(<,'__') -: '' fmt __ +(<,'_.') -: '' fmt _. +((,'_');'__';'_.';,'0') -: fmt _ __ _. 0 + +(''&fmt -: '3'&fmt) x=:_ 0.123 __ +(''&fmt -: '0'&fmt) _ 0 4 __ _. 1 2 3 + +(3$<'BOOM') -: 'd<BOOM>' fmt _ __ _. + +s=: 'd<n/a>' fmt y {~ x=: 1000 ?@$ 100 [ y=: _ __ _. , 0.01 * 97 ?@$ 10000 +(<'n/a') -:"0 s #~ x e. i.3 +(s-.<'n/a') -: '' fmt y{~ x -. i.3 + +s=: 'd<n/a>' fmt y {~ x=: 1000 ?@$ 100 [ y=: _ __ _. , 97 ?@$ 0 +(<'n/a') -:"0 s #~ x e. i.3 +(s-.<'n/a') -: '' fmt y{~ x -. i.3 + + +NB. 8!:n : rank 1 right arguments --------------------------------------- + +(<@,"0 '012') -: '' fmt i.3 +(<@,:@,"0 '012') -: '' fmt1 i.3 +(,: '012') -: '' fmt2 i.3 +2 = #@$ '' fmt2 i.3 +2 = #@$ '' fmt2 i.0 + + +NB. 8!:n : # of decimal places ------------------------------------------ + +(<11{.x) -: '' fmt ".x=: '5.123456789' +(<11{.x) -: '' fmt ".x=: '5.1234567891' +(<11{.x) -: '' fmt ".x=: '5.12345678912' +(<11{.x) -: '' fmt ".x=: '5.123456789123' +(<11{.x) -: '' fmt ".x=: '5.1234567891234' + +(<11{.x) -: '9' fmt ".x=: '5.1234123412' +(<10{.x) -: '8' fmt ".x +(< 9{.x) -: '7' fmt ".x +(< 8{.x) -: '6' fmt ".x +(< 7{.x) -: '5' fmt ".x +(< 6{.x) -: '4' fmt ".x +(< 5{.x) -: '3' fmt ".x +(< 4{.x) -: '2' fmt ".x +(< 3{.x) -: '1' fmt ".x +(< 1{.x) -: '0' fmt ".x + +('domain error';'assertion failure') e.~< '10' fmt etx ".x +('domain error';'assertion failure') e.~< '-1' fmt etx ".x +('domain error';'assertion failure') e.~< '_1' fmt etx ".x +('domain error';'assertion failure') e.~< '11' fmt etx ".x +('domain error';'assertion failure') e.~< '20.10' fmt etx ".x +('domain error';'assertion failure') e.~< '20.19' fmt etx ".x + + +NB. 8!:n : rounding ----------------------------------------------------- + +(<'0',~}:x-.'8') -: '' fmt ".x=: '5.1234567899' +(<'0',~}:x-.'8') -: '' fmt ".x=: '5.1234567896' +(<'0',~}:x-.'8') -: '' fmt ".x=: '5.1234567895' +(<11{. x ) -: '' fmt ".x=: '5.1234567894' +(<'5.123456781') -: '' fmt ".x=: '5.1234567805' + +NB. test Chris's rounding examples +(<@":"0@:(0.1&round) -: '1'&fmt) x=:1.05 1.15 1.25 1.35 1.45 1.55 1.65 1.75 +(,:' 2,231,834.54') -: 'c14.2' fmt2 o. 710415 + +NB. check positive & negative 4r10 5r10 6r10 roundings... (away from zero) +(<@":"0(1& round) x) -: y=: 'm<_>0' fmt x=: 0.4 + i:5 +(<@":"0(1&afzrnd) x) -: y +('s<-_>'fmt 0+i: 5 ) -: y + +(<@":"0(1&afzrnd) x) -: y=: 'm<_>0' fmt x=: 0.5 + i:5 +('s<-_>'fmt (->:i._5),>:i.6) -: y + +(<@":"0(1& round) x) -: y=: 'm<_>0' fmt x=: 0.6 + i:5 +(<@":"0(1&afzrnd) x) -: y +('s<-_>'fmt 1+i: 5 ) -: y + +(<@":"0(1& round) x) -: y=: 'm<_>0' fmt x=:_0.4 + i:5 +(<@":"0(1&afzrnd) x) -: y +('s<-_>'fmt 0+i: 5 ) -: y + +(<@":"0(1&afzrnd) x) -: y=: 'm<_>0' fmt x=:_0.5 + i:5 +('s<-_>'fmt (->:i._6),>:i.5) -: y + +(<@":"0(1& round) x) -: y=: 'm<_>0' fmt x=:_0.6 + i:5 +(<@":"0(1&afzrnd) x) -: y +('s<-_>'fmt _1+i: 5 ) -: y + +NB. exponential rounding +'3.123456777e9' -: >'' fmt 3123456777.4 +'3.123456778e9' -: >'' fmt 3123456777.5 +'3.123456778e9' -: >'' fmt 3123456777.6 +'3.123456777e-10' -: >'' fmt 3.1234567774e_10 +'3.123456778e-10' -: >'' fmt 3.1234567775e_10 +'3.123456778e-10' -: >'' fmt 3.1234567776e_10 +'3.123456777e-23' -: >'' fmt 3.1234567774e_23 +'3.123456778e-23' -: >'' fmt 3.1234567775e_23 +'3.123456778e-23' -: >'' fmt 3.1234567776e_23 +'3.123456777e23' -: >'' fmt 3.1234567774e23 +'3.123456778e23' -: >'' fmt 3.1234567775e23 +'3.123456778e23' -: >'' fmt 3.1234567776e23 + +NB. in small neighborhoods: +NB. these numbers are adjacent floating point numbers, +NB. and should have perfect decimal <-> binary conversion +('70940822612508'&,&.> 4 5#'89') -: '0' fmt x=: 709408226125088 + 8 %~ i.9 + +NB. ugly rounding examples :-) +'806392019.591013' -: > '6' fmt 806392019.5910134315490722656250000000000000000 + + 709408226.1250885 =!.(0) 709408226.1250884532928466796875000000000000 +'709408226.125089' -: > '6' fmt 709408226.1250884532928466796875000000000000 + + 695833212.8014305 =!.(0) 695833212.8014304637908935546875000000000000 +'695833212.801431' -: > '6' fmt 695833212.8014304637908935546875000000000000 + +'-7369.780882677' -: > '' fmt _7369.7808826765003686887212097644805908203125000 +'-7369.780882676' -: > '' fmt _7369.7808826764994591940194368362426757812500000 +'-7369.780882676' -: > '' fmt _7369.7808826764985496993176639080047607421875000 + +'-7425.108822418' -: > '' fmt _7425.1088224183995407656766474246978759765625000 + +'5.123456790' -: > '' fmt 5.123456789499999608494817948667332530021667480468750 +'5.123456789' -: > '' fmt 5.123456789499998720316398248542100191116333007812500 +'5.123456789' -: > '' fmt 5.123456789499989838532201247289776802062988281250000 + +'5.123456790' -: >'9' fmt 5.123456789500004049386916449293 +'5.123456790' -: >'9' fmt 5.123456789500003161208496749168 +'5.123456790' -: >'9' fmt 5.123456789500002273030077049043 +'5.123456790' -: >'9' fmt 5.123456789500001384851657348918 +'5.123456790' -: >'9' fmt 5.123456789500000496673237648793 + 5.1234567895 =!.(0) 5.123456789499999608494817948667 +'5.123456790' -: >'9' fmt 5.123456789499999608494817948667 +'5.123456789' -: >'9' fmt 5.123456789499998720316398248542 +'5.123456789' -: >'9' fmt 5.123456789499997832137978548417 +'5.123456789' -: >'9' fmt 5.123456789499996943959558848292 +'5.123456789' -: >'9' fmt 5.123456789499996055781139148166 +'5.123456789' -: >'9' fmt 5.123456789499995167602719448041 + + +NB. 8!:n : multiple modifiers ------------------------------------------- + +('domain error';'assertion failure') e.~< 'cc' fmt etx 10 ?@$ 1e6 +('domain error';'assertion failure') e.~< 'b<not>cb' fmt etx 10 ?@$ 1e6 +('domain error';'assertion failure') e.~< 'dd<x>' fmt etx 10 ?@$ 1e6 +('domain error';'assertion failure') e.~< 'p<p>q<q>p<p>' fmt etx 10 ?@$ 1e6 +('domain error';'assertion failure') e.~< 'lllll10.3' fmt etx 10 ?@$ 1e6 +('domain error';'assertion failure') e.~< 'm<mm>n<n>cm<p>' fmt etx 10 ?@$ 1e6 + + +NB. 8!:n : m, n, p, & q modifiers with empty string --------------------- + +(' 3.14';' 3.14') -: 'mnpq5.2' fmt 1p1;_1p1 +('' fmt |x) -: 'm' fmt x=:(_1 1{~100 ?@$ 2) * 100 ?@$ 0 + + +NB. 8!:n : s modifier with the empty string ----------------------------- + +( 'c'&fmt -:'cs' &fmt) x=: _1 1.123 12345, 1e9*1p1 +( ''&fmt -: 's' &fmt) x +('3.1'&fmt -: 's3.1'&fmt) 12345 + +( 'c'&fmt -:'cs<>' &fmt) x=: _1 1.123 12345, 1e9*1p1 +( ''&fmt -: 's<>' &fmt) x +('3.1'&fmt -: 's<>3.1'&fmt) 12345 + + +NB. 8!:n : _ __ _. & other modifiers ------------------------------------ + +(''&fmt -: 's<-->'&fmt) _ __ _. +(''&fmt -: 's<-X>'&fmt) _ __ _. +(''&fmt -: 'cs<eE*S-?,X.D>'&fmt) _ __ _. +(''&fmt -: 'm<M>n<N>p<P>q<Q>'&fmt) _ __ _. +(''&fmt -: 'cb<ZeRo>'&fmt) _ __ _. + +('_ ';'__ ';'_. ') -: 'l3.3' fmt _ __ _. + +(<@,"0 '_**') -: '1.0' fmt _ __ _. +(<@,"0 '_XX') -: 's<-z*X>1.0' fmt _ __ _. + + +NB. 8!:n : exponential notation ----------------------------------------- + +s=:(,'0');('12' <@,"0 _ '000000000'), '3456789' <@,"0 _ 'e9' +(x{s) -: '' fmt 1e9*x=:10 12 ?@$ 10 + +-. 'e' e. , '' fmt2 1e9 * 100 ?@$ 0 + 'e' e. , '' fmt2 1e11 * 100 ?@$ 0 + 'e' e. , '' fmt2 1e_9 * 100 ?@$ 0 + + '-' e. , '' fmt2 1e_9 * 100 ?@$ 0 +-. '_' e. , '' fmt2 1e_9 * 100 ?@$ 0 + +-. _ e. _&".&> '' fmt x=:1e11 * 100 ?@$ 0 +-. _ e. _&".&> '' fmt x=:1e_9 * 100 ?@$ 0 + +'M3e-11' -: , 'm<M>' fmt2 _3e_11 + '3e-11' -: , 'm<M>' fmt2 3e_11 +'M3e_11' -: , 'm<M>s<-_>' fmt2 _3e_11 + '3e_11' -: , 'm<M>s<-_>' fmt2 3e_11 +'-3e-11' -: , '' fmt2 _3e_11 + +4 -: 3!:0 y=:".x=:'2.01e9' +x -: >'' fmt y + +4 -: 3!:0 y=:".x=:'2.123456789e9' +x -: >'' fmt y + +NB. exponents of large magnitude +t=:(y=:(1+1000 ?@$ 9) + 1000 ?@$ 0) * 10 ^ x=: 10 + 1000 ?@$ 308 - 10 +'e'&e.&> s=: '' fmt t +1e_9 > | y - ([:".i.&'e'{.])&> s +x = ([:".([:>:i.&'e')}.])&> s + +t=:(y=:(1+1000 ?@$ 9) + 1000 ?@$ 0) * 10 ^ x=: - 10 + 1000 ?@$ 308 - 10 +'e'&e.&> s=: '' fmt t +1e_9 > | y - ([:".i.&'e'{.])&> s +x = ([:".([:>:i.&'e')}.])&> s + + +NB. 8!:n : modifier text using <> () [] --------------------------------- + +'<<12>>>' -: > 'p(<<)q[>>>]' fmt 12 +'**<<12.00>>>' -: > 'r<*>p(<<)q[>>>]12.2' fmt 12 +'<<12.00>>>**' -: > 'r<*>p(<<)lq[>>>]12.2' fmt 12 + + +NB. 8!:n : monad -------------------------------------------------------- + +(( 2$a:)&fmt -: fmt) x=: 10 2 ?@$ 0 +(( 4$a:)&fmt -: fmt) x=: 3 4 ?@$ 0 +(( 20$a:)&fmt -: fmt) x=: 10 20 ?@$ 0 +(( 3$a:)&fmt -: fmt) x=: 1 2 3 ?@$ 0 +(( 5$a:)&fmt -: fmt) x=: 3 4 5 ?@$ 0 +(( 5$a:)&fmt -: fmt) x=: 123.4 123.45 123.456 123.4567 123.45678 + +((({:y)$a:)&fmt -: fmt) x=: 0 ?@$~ y=: ? 10 +((({:y)$a:)&fmt -: fmt) x=: 0 ?@$~ y=: 2 ?@$ 10 +((({:y)$a:)&fmt -: fmt) x=: 0 ?@$~ y=: 3 ?@$ 10 +((({:y)$a:)&fmt -: fmt) x=: 0 ?@$~ y=: 4 ?@$ 7 + +((({:y)$a:)&fmt -: fmt) x=: 1e_3 * 1e6 ?@$~ y=: ? 10 +((({:y)$a:)&fmt -: fmt) x=: 1e_3 * 1e6 ?@$~ y=: 2 ?@$ 10 +((({:y)$a:)&fmt -: fmt) x=: 1e_3 * 1e6 ?@$~ y=: 3 ?@$ 10 +((({:y)$a:)&fmt -: fmt) x=: 1e_3 * 1e6 ?@$~ y=: 4 ?@$ 7 + + +NB. 8!:1 ---------------------------------------------------------------- + + (,:&.>@,@fmt -: fmt1) y=: ? 0 + (,:&.>@,@fmt -: fmt1) y=: ? 1e3 + (,:&.>@,@fmt -: fmt1) y=: 1e_3 * ? 1e6 + (fmt1 -: fmt1@,) y=: ? 0 +'' (fmt1 -: fmt1@,) y=: ? 0 + + (,:&.>@fmt -: fmt1) y=: (1+?20) ?@$ 0 + (,:&.>@fmt -: fmt1) y=: (1+?20) ?@$ 1e3 + (,:&.>@fmt -: fmt1) y=: 1e_3 * (1+?20) ?@$ 1e6 +'' (,:&.>@fmt -: fmt1) y=: (1+?20) ?@$ 0 +'' (,:&.>@fmt -: fmt1) y=: (1+?20) ?@$ 1e3 +'' (,:&.>@fmt -: fmt1) y=: 1e_3 * (1+?20) ?@$ 1e6 + + (,:&.>@,@fmt -: fmt1) '' +'' (,:&.>@,@fmt -: fmt1) '' + + (<@:>"1@:|:@fmt -: fmt1) y=: (1+?10 10) ?@$ 0 + (<@:>"1@:|:@fmt -: fmt1) y=: (1+?10 10) ?@$ 1e3 + (<@:>"1@:|:@fmt -: fmt1) y=: 1e_3 * (1+?10 10) ?@$ 1e6 +'' (<@:>"1@:|:@fmt -: fmt1) y=: (1+?10 10) ?@$ 0 +'' (<@:>"1@:|:@fmt -: fmt1) y=: (1+?10 10) ?@$ 1e3 +'' (<@:>"1@:|:@fmt -: fmt1) y=: 1e_3 * (1+?10 10) ?@$ 1e6 + +1 = #@$ fmt1 y=:(1+?10 10) ?@$ 1000 +1 = #@$ '' fmt1 y=:(1+?10 10) ?@$ 1000 +2 = #@$&> fmt1 y=:(1+?10 10) ?@$ 1000 +2 = #@$&> '' fmt1 y=:(1+?10 10) ?@$ 1000 + +NB. fmt1 on empties, chars +f=:,@:(<@,:"1)@] +'' (f -: fmt1) y=: (1 + ?10 10)$'abcdefg' +'' (f -: fmt1) y=: ( 0, 1+?10)$'abcdefg' +'' (f -: fmt1) y=: ((1+?10), 0)$'abcdefg' +'' (f -: fmt1) y=: 0 0 $'abcdefg' +'' (f -: fmt1) y=: ( 0, 1+?10)$0 +'' (f -: fmt1) y=: ((1+?10), 0)$0 + (f -: fmt1) y=: (1 + ?10 10)$'abcdefg' + (f -: fmt1) y=: ( 0, 1+?10)$'abcdefg' + (f -: fmt1) y=: ((1+?10), 0)$'abcdefg' + (f -: fmt1) y=: 0 0 $'abcdefg' + (f -: fmt1) y=: ( 0, 1+?10)$0 + (f -: fmt1) y=: ((1+?10), 0)$0 + (f -: fmt1) y=: (1+?10) $ 'abcdefg' + (f -: fmt1) y=: 0 $ 'abcdefg' + (f -: fmt1) y=: 0 $ 0 + +2 = #fmt1 2 3$'abc' + + +NB. 8!:2 ---------------------------------------------------------------- + +NB. fmt2 on character and empty matrices +f=:,:@,@] + (f-:fmt2) y=: (1 + ?10 10)$'abcdefg' + (f-:fmt2) y=: ( 0, 1+?10)$'abcdefg' + (f-:fmt2) y=: ((1+?10), 0)$'abcdefg' + (f-:fmt2) y=: 0 0 $'abcdefg' + (f-:fmt2) y=: ( 0, 1+?10)$0 + (f-:fmt2) y=: ((1+?10), 0)$0 +'' (f-:fmt2) y=: (1 + ?10 10)$'abcdefg' +'' (f-:fmt2) y=: ( 0, 1+?10)$'abcdefg' +'' (f-:fmt2) y=: ((1+?10), 0)$'abcdefg' +'' (f-:fmt2) y=: 0 0 $'abcdefg' +'' (f-:fmt2) y=: ( 0, 1+?10)$0 +'' (f-:fmt2) y=: ((1+?10), 0)$0 + +'8.5' (fmt2 -: ,./@:>@:(<@:>"1)@:|:@fmt) y=: (2+?10 10) ?@$ 0 +'0.5' (fmt2 -: ,./@:>@:(<@:>"1)@:|:@fmt) y=: (2+?10 10) ?@$ 0 +'0.0' (fmt2 -: ,./@:>@:(<@:>"1)@:|:@fmt) y=: (2+?10 10) ?@$ 1e6 + +NB. fmt2 always has a matrix result +2 = #@$ fmt2 '1' +2 = #@$ fmt2 1 +2 = #@$ fmt2 1p1 +2 = #@$ fmt2 y=: (1+?10) ?@$ 100 +2 = #@$ fmt2 $0 +2 = #@$ fmt2 '' + +NB. data type doesn't matter +'' -:&fmt2 $0 + +NB. fmt2 on scalars + (fmt2 -: ,:@>@fmt) y=: ? 0 +'0.5' (fmt2 -: ,:@>@fmt) y=: ? 0 +'' (fmt2 -: ,:@>@fmt) y=: ? 0 + +NB. fmt2 on vectors + (fmt2 -: ,:@;@fmt) y=:0.01 * (1+?100) ?@$ 1e6 +'0.5' (fmt2 -: ,:@;@fmt) y=:0.01 * (1+?100) ?@$ 1e6 +'' (fmt2 -: ,:@;@fmt) y=:0.01 * (1+?100) ?@$ 1e6 + +NB. character vecs +(,:-:fmt2) y=: (1+?10)$'abcdefg' +(,:-:fmt2) y=: 0$'abcdefg' + +NB. scalar character +(,:@,: -: fmt2) y=: (?#a.){a. + + +NB. 8!:0 : empties ------------------------------------------------------ + +(<@,"1 -: fmt) y=: (1 + ?10 10)$'abcdefg' +(<@,"1 -: fmt) y=: ( 0, 1+?10)$'abcdefg' +(<@,"1 -: fmt) y=: ((1+?10), 0)$'abcdefg' +(<@,"1 -: fmt) y=: 0 0 $'abcdefg' +(<@,"1 -: fmt) y=: ( 0, 1+?10)$0 +(<@,"1 -: fmt) y=: ((1+?10), 0)$0 + + +NB. 8!:0 : atomic arguments --------------------------------------------- + +(''&$@fmt@, -: fmt) 0 +(''&$@fmt@, -: fmt) ?0 +(''&$@fmt@, -: fmt) ?1e6 + + +NB. 8!:n : exponential notation # of decimal places --------------------- + +(< x ) -: '' fmt ".x=: '5e9' +(< x ) -: '' fmt ".x=: '5.1e9' +(< x ) -: '' fmt ".x=: '5.12e9' +(< x ) -: '' fmt ".x=: '5.123e9' +(< x ) -: '' fmt ".x=: '5.1234e9' +(< x ) -: '' fmt ".x=: '5.12345e9' +(< x ) -: '' fmt ".x=: '5.123456e9' +(< x ) -: '' fmt ".x=: '5.1234567e9' +(< x ) -: '' fmt ".x=: '5.12345678e9' +(< x ) -: '' fmt ".x=: '5.123456789e9' +(<(11{.x),'e9') -: '' fmt ".x=: '5.123456789e9' +(<(11{.x),'e9') -: '' fmt ".x=: '5.1234567891e9' +(<(11{.x),'e9') -: '' fmt ".x=: '5.12345678912e9' +(<(11{.x),'e9') -: '' fmt ".x=: '5.123456789123e9' +(<(11{.x),'e9') -: '' fmt ".x=: '5.1234567891234e9' + +(< x ) -: '' fmt 0".x=: '5e-10' +(< x ) -: '' fmt 0".x=: '5.1e-10' +(< x ) -: '' fmt 0".x=: '5.12e-10' +(< x ) -: '' fmt 0".x=: '5.123e-10' +(< x ) -: '' fmt 0".x=: '5.1234e-10' +(< x ) -: '' fmt 0".x=: '5.12345e-10' +(< x ) -: '' fmt 0".x=: '5.123456e-10' +(< x ) -: '' fmt 0".x=: '5.1234567e-10' +(< x ) -: '' fmt 0".x=: '5.12345678e-10' +(< x ) -: '' fmt 0".x=: '5.123456789e-10' +(<(11{.x),'e-10') -: '' fmt 0".x=: '5.123456789e-10' +(<(11{.x),'e-10') -: '' fmt 0".x=: '5.1234567891e-10' +(<(11{.x),'e-10') -: '' fmt 0".x=: '5.12345678912e-10' +(<(11{.x),'e-10') -: '' fmt 0".x=: '5.123456789123e-10' +(<(11{.x),'e-10') -: '' fmt 0".x=: '5.1234567891234e-10' + +(< '1.2e10') -: '' fmt 12e9 +(<'-1.2e10') -: '' fmt _12e9 + + +NB. 8!:n : minimum width ------------------------------------------------ + + (#@":"0 -: #&>@fmt) x=:i.10 20 10 + (#@":"0 -: #&>@fmt) x=:5 4 ?@$ 100 + (#@":"0 -: #&>@fmt) x=: 4 ?@$ 100 +'' (#@":"0@] -: #&>@fmt) x=:i.10 20 10 +'' (#@":"0@] -: #&>@fmt) x=:5 4 ?@$ 100 +'' (#@":"0@] -: #&>@fmt) x=: 4 ?@$ 100 + +x=:10 20 ?@$ 20000 [ y=: 1000 %~ 10 20 ?@$ 1000 +x (#@":"0@[ -: i.&'.'&> @ fmt @:+) y +x ((-:"1{.)@:(([:#i.&'.'}.])&>)@ fmt @:+) y +x (#@":"0@[ -: i.&'.'&> @(''&fmt)@:+) y +x ((-:"1{.)@:(([:#i.&'.'}.])&>)@(''&fmt)@:+) y + +y=: 10000 %~ 10#. 10 20 4 ?@$ 10 10 5 5 +x (#@":"0@[ -: i.&'.'&> @ fmt @:+) y +x ((-:"1{.)@:(([:#i.&'.'}.])&>)@ fmt @:+) y +x (#@":"0@[ -: i.&'.'&> @(''&fmt)@:+) y +x ((-:"1{.)@:(([:#i.&'.'}.])&>)@(''&fmt)@:+) y + + +NB. 8!:n : computed width ----------------------------------------------- + +'0.0' (>./@:(#@":"0)@] -:"2 #&>@fmt) x=:i.10 20 10 +'0.0' (>./@:(#@":"0)@] -:"1 #&>@fmt) x=:5 4 ?@$ 100 +'0.0' (>./@:(#@":"0)@] -:"0 #&>@fmt) x=: 4 ?@$ 100 + +(i.10) (>./@:(#@(j.@[":])"0) -:"1 #&>@('0.'&,@":@[ fmt ]))"0 _ x=: 5 4 ?@$ 100 +(i.10) (>./@:(#@(j.@[":])"0) -:"1 #&>@('0.'&,@":@[ fmt ]))"0 _ x=: 5 4 ?@$ 0 + + +NB. 8!:n : multiple format phrases -------------------------------------- + +y=: (1 _1 {~ 10 ?@$ 2) * (10 ?@$ 10000) + 10 ?@$ 0 +x=: ',,c,m<MINUS>,p<+>,n<\/>q</\>,0,0.0,0.4,6.1,6.5,20.5,0.8' +s=: |: ;(#<;._1 x)#<,:y +(( }. x) fmt s) -: (<;._1 x) fmt s +(( }. x) fmt s) -: ,./ (<;._1 x) fmt&> <|:,:y +(( }. x) fmt1 s) -: (}.x) <@:>"1@|:@fmt s +((<;._1 x) fmt1 s) -: (}.x) <@:>"1@|:@fmt s +(<;._1 x) -:&(fmt&s) }.x +(<;._1 x) -:&(fmt1&s) }.x +(<;._1 x) -:&(fmt2&s) }.x + +y=: (20 ?@$ 1000) + 20 ?@$ 0 +x=: ',0,1,2,3,4,5,6,7,8,9,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9' +s=: |: ;(#<;._1 x)#<,:y +(( }. x) fmt s) -: (<;._1 x) fmt s +(( }. x) fmt s) -: ,./ (<;._1 x) fmt&> <|:,:y +(( }. x) fmt1 s) -: (}.x) <@:>"1@|:@fmt s +((<;._1 x) fmt1 s) -: (}.x) <@:>"1@|:@fmt s +(<;._1 x) -:&(fmt&s) }.x +(<;._1 x) -:&(fmt1&s) }.x +(<;._1 x) -:&(fmt2&s) }.x + +f=:<"_1 @: (0 1&|:) +y=: 1e_3 * 2 3 4 ?@$ 1e6 +('0,1,2,3' fmt y) -: f^:_1 '0123' fmt&.> f y +('0,1,2,3' fmt y) -: (<"0 '0123') fmt y + +f=:<"_1 @: (0 1 2&|:) +y=: 1e_3 * 4 3 2 5?@$ 1e6 +('0,1,2,3,4' fmt y) -: f^:_1 '01234' fmt&.> f y +('0,1,2,3,4' fmt y) -: (<"0 '01234') fmt y + + +NB. 8!:n : boxed right arguments ---------------------------------------- + +x=: (10 ?@$ 10) <@(?@$ { a."_)"0 _] 256 +x=: x,<"0 ] (10 ?@$ 0) , (10 ?@$ 1e3) , 1e_3 * 10 ?@$ 1e6 + +( fmt y) -: fmt&> y=:x {~ 10 ?@$ #x +( '' fmt y) -: (10$ a:) fmt&> y=:x {~ 10 ?@$ #x +( (9$',') fmt y) -: (10$<'') fmt&> y=:x {~ 10 ?@$ #x +('0,1,2,3,4,5,6,7,8,9' fmt y) -: ({.@":"0 i.10) fmt&> y=:x {~ 10 ?@$ #x + +y=:2 3 4$4#1 10 100 1e3 1e4 1e5 +x=:'0.1,0.2,0.3,0.4' + (="1 {.@{.) #&> x fmt y NB. columns have uniform computed width +8 9 10 11 = {.@{. #&> x fmt y NB. and its what we're expecting + 2 -~/\ {.@{. #&> x fmt y NB. decimals grow by one => width grows by one + +NB. but when we box it, it grows in both directions, since the computed width +NB. is now independent of the rest of the column +2 -~/\"1 #&> x fmt <"0 y NB. decimals grow by one => width grows by one +2 -~/\"1 |:,/ #&> x fmt <"0 y NB. magnitude grow by ten => width grows by one + +y=: ,/y +NB. same as above, but now y is rank-2 + (="1 {. ) #&> x fmt y NB. columns have uniform computed width +8 9 10 11 = {. #&> x fmt y NB. and its what we're expecting + 2 -~/\ {. #&> x fmt y NB. decimals grow by one => width grows by one +2 -~/\"1 #&> x fmt <"0 y NB. decimals grow by one => width grows by one +2 -~/\"1 |: #&> x fmt <"0 y NB. magnitude grow by ten => width grows by one + +NB. with fmt1, we'll rank pad on the left instead of computed-width padding +NB. on the right when we box. so boxing in this case should be the same as +NB. left justify. same deal for fmt2. +(('l'&,&.> <;._1 ',',x) fmt1 y) -: x fmt1 <"0 y +(('l'&,&.> <;._1 ',',x) fmt2 y) -: x fmt2 <"0 y + +('domain error';'assertion failure') e.~< '' fmt etx <<1p1 +('domain error';'assertion failure') e.~< '' fmt1 etx <<101 +('domain error';'assertion failure') e.~< '' fmt2 etx <<100 + +('' fmt < 'abcdef') -: '' fmt < u:'abcdef' +('' fmt <, '5' ) -: '' fmt <, u:'5' +('' fmt <0$'5' ) -: '' fmt <0$u:'5' +('' fmt < '5' ) -: '' fmt < u:'5' + + +4!:55 ;:'afzrnd f fmt fmt1 fmt2 s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/g9x.ijs @@ -0,0 +1,316 @@ +NB. 9!:0 and 9!:1 ------------------------------------------------------- + +rlq =: 9!:0 +rls =: 9!:1 + +1 [ rls 7^5 +(7^5) -: rlq '' +a =: ?$~100 +b =: ?$~100 +1 [ rls 7^5 +(7^5) -: rlq '' +c =: ?$~100 +-. a -: b +a -: c + +'domain error' -: rls etx 3.5 +'domain error' -: rls etx 'a' +'domain error' -: rls etx <9 +'domain error' -: rls etx 3j4 + + +NB. 9!:2 and 9!:3 ------------------------------------------------------- + +dispq =: 9!:2 +disps =: 9!:3 + +read =: 1!:1 +erase =: 1!:55 +drop1 =: (>:@(i.&(10{a.)) }. ]) @ read +old =: dispq '' +p =: <'a1b2q0.x' +q =: <'a1b2q1.x' + +nub =: (i.@# = i.~) # ] + +t=: 0 : 0 +disps 1 +p 0!:100 'nub' +q 0!:100 '5!:1 <''nub''' +(drop1 p) -: drop1 q +erase p,q + +disps 2 +p 0!:100 'nub' +q 0!:100 '5!:2 <''nub''' +(drop1 p) -: drop1 q +erase p,q + +disps 4 +p 0!:100 'nub' +q 0!:100 '5!:4 <''nub''' +(drop1 p) -: drop1 q +erase p,q + +disps 5 +p 0!:100 'nub' +q 0!:100 '5!:5 <''nub''' +(drop1 p) -: drop1 q +erase p,q + +disps old +(,old) -: dispq '' +) + +'domain error' -: disps etx 'abc' +'domain error' -: disps etx 1;2 3 +'domain error' -: disps etx 2 3j4 +'domain error' -: disps etx 2 3.4 +'domain error' -: disps etx 2 3 2 + +'rank error' -: disps etx 1 2$2 3 + +'index error' -: disps etx 2 _1 +'index error' -: disps etx 2 7 +'index error' -: disps etx 2 0 + + +NB. 9!:6 and 9!:7 ------------------------------------------------------- + +boxq =: 9 !: 6 +boxs =: 9 !: 7 + +old =: boxq '' +(11={:$old) *. *./ old e. a. +'' -: boxs '0123456789?' +'0?29a96?8' -: ,":<'a' +'' -: boxs old + +'domain error' -: boxs etx 9;'ab' +'domain error' -: boxs etx 3j4 +'domain error' -: boxs etx i.11 +'domain error' -: boxs etx o.i.11 + +'length error' -: boxs etx 10$' ' +'length error' -: boxs etx 12$' ' + +'rank error' -: boxs etx 2 3 11$'x' + + +NB. 9!:8 and 9!:9 ------------------------------------------------------- + +evmq =: 9!:8 +evms =: 9!:9 + +t =: evmq '' +1 -: #$t +32 -: type t +*./ 1 = #&$&>t +*./ (t=a:) +. 2 = type&>t + +t =: evmq '' + +evms (<'bah humbug') (t i.<'domain error')}t +'bah humbug' -: ^ etx 'abc' +evms t +'domain error' -: ^ etx 'abc' + +'rank error' -: evms etx 3 4$<'abc' +'rank error' -: evms etx <'abc' +'rank error' -: evms etx ($t)$<3 4$'a' + +'length error' -: evms etx }.t +'length error' -: evms etx t,<'abc' + +'domain error' -: evms etx ($t)$0 1 +'domain error' -: evms etx ($t)$'abc' +'domain error' -: evms etx ($t)$2 3 +'domain error' -: evms etx ($t)$2.3 +'domain error' -: evms etx ($t)$2j3 +'domain error' -: evms etx ($t)$<0 1 +'domain error' -: evms etx ($t)$<2 3 +'domain error' -: evms etx ($t)$<2.3 +'domain error' -: evms etx ($t)$<2j3 + + +NB. 9!:10 and 9!:11 ----------------------------------------------------- + +ppq =: 9!:10 +pps =: 9!:11 + +a6 =: ": o.1 +a9 =: ":!.9 o.1 +a12=: ":!.12 o.1 + +1 [ pps 9 +a9 -: ": o.1 +a6 -: ":!.6 o.1 +a9 -: ":!.9 o.1 +a12 -: ":!.12 o.1 + +1 [ pps 12 +a12 -: ": o.1 +a6 -: ":!.6 o.1 +a9 -: ":!.9 o.1 +a12 -: ":!.12 o.1 + +1 [ pps 6 +a6 -: ": o.1 +a6 -: ":!.6 o.1 +a9 -: ":!.9 o.1 +a12 -: ":!.12 o.1 + +'domain error' -: pps etx '4' +'domain error' -: pps etx _4 +'domain error' -: pps etx <7 +'domain error' -: pps etx 3.4 +'domain error' -: pps etx 3j4 + +'rank error' -: pps etx 7 8 + +'limit error' -: pps etx 30 + + +NB. 9!:12 and 9!:14 ----------------------------------------------------- + +s=:9!:12 '' NB. system identifier +(0=#$s), s e. _1 0 1 2 3 4 5 6 7 + +v=:9!:14 '' NB. J version +(1=#$v), *./(_16{.v) e. '0123456789 .:/-' + + +NB. 9!:16 and 9!:17 ----------------------------------------------------- + +'domain error' -: 9!:17 etx 'ab' +'domain error' -: 9!:17 etx 0 1.2 +'domain error' -: 9!:17 etx 0j1 2 + +'length error' -: 9!:17 etx 0 1 2 +'length error' -: 9!:17 etx i.0 + +'rank error' -: 9!:17 etx ,:1 2 +'rank error' -: 9!:17 etx i.1 1 + + +NB. 9!:18 and 9!:19 ----------------------------------------------------- + +(2^_44) -: 9!:18 '' +0 = 1 = 1+1e_13 +9!:19 [1e_12 +1 = 1 = 1+1e_13 +0 = 1 =!.(1e_14) 1+1e_13 +9!:19 [2^_44 +0 = 1 = 1+1e_13 + +'domain error' -: 9!:19 etx 'a' +'domain error' -: 9!:19 etx <1e_12 +'domain error' -: 9!:19 etx _1e_13 +'domain error' -: 9!:19 etx 1e_8 +'domain error' -: 9!:19 etx 14 +'domain error' -: 9!:19 etx 14x + +'rank error' -: 9!:19 etx ,1e_14 +'rank error' -: 9!:19 etx 1 1 1$1e_14 + + +NB. 9!:25 --------------------------------------------------------------- + +'domain error' -: 9!:25 etx 'a' +'domain error' -: 9!:25 etx 2.5 +'domain error' -: 9!:25 etx 2 +'domain error' -: 9!:25 etx 2j4 +'domain error' -: 9!:25 etx <2 + +'rank error' -: 9!:25 etx 1 1 0 + + +NB. 9!:26 and 9!:27 ----------------------------------------------------- + +'length error' -: 9!:26 etx i.4 + +'rank error' -: 9!:26 etx 4 +'rank error' -: 9!:26 etx '4' +'rank error' -: 9!:26 etx i.0 0 + +'domain error' -: 9!:27 etx i.12 +'domain error' -: 9!:27 etx 3 4.5 +'domain error' -: 9!:27 etx 3 4j5 +'domain error' -: 9!:27 etx 3 4r5 +'domain error' -: 9!:27 etx ;:'es chat o lo gy' + +'rank error' -: 9!:27 etx 3 4$'abc' + + +NB. 9!:28 and 9!:29 ----------------------------------------------------- + +'length error' -: 9!:28 etx i.4 +'length error' -: 9!:28 etx 'abc' + +'rank error' -: 9!:28 etx 4 +'rank error' -: 9!:28 etx '4' +'rank error' -: 9!:28 etx i.0 0 + +'domain error' -: 9!:29 etx 435 +'domain error' -: 9!:29 etx 4.5 +'domain error' -: 9!:29 etx 4j5 +'domain error' -: 9!:29 etx 4r5 +'domain error' -: 9!:29 etx <0 + +'rank error' -: 9!:29 etx 0 1 + + +NB. 9!:32 and 9!:33 ----------------------------------------------------- + +'domain error' -: 9!:33 etx _5 +'domain error' -: 9!:33 etx 3j4 +'domain error' -: 9!:33 etx 'a' +'domain error' -: 9!:33 etx <4.5 + +'limit error' -: 9!:33 etx >IF64{1e9;1e16 + +'rank error' -: 9!:33 etx 3 4.5 + + +NB. 9!:38 and 9!:39 ----------------------------------------------------- + +t=: 9!:38 '' +(,2) -: $ t +4 = type t + +9!:39 t+1 +(t+1) -: 9!:38 '' +9!:39 t +t -: 9!:38 '' + +'domain error' -: 9!:39 etx 2 3.4 +'domain error' -: 9!:39 etx 2 3j4 +'domain error' -: 9!:39 etx 2 3r4 +'domain error' -: 9!:39 etx 2 3;4 +'domain error' -: 9!:39 etx '23' +'domain error' -: 9!:39 etx _1 3 + +'rank error' -: 9!:39 etx 2 +'rank error' -: 9!:39 etx ,:3 2 + +'limit error' -: 9!:39 etx 2 1000 + + +NB. 9!:48 and 9!:49 ----------------------------------------------------- + +old=: 9!:48 '' +9!:49 ]0 +'spelling error' -: ex 'x.=: 1' +'spelling error' -: ex 'y.=: 1' +'spelling error' -: ex 'm.=: 1' +'spelling error' -: ex 'n.=: 1' +'spelling error' -: ex 'u.=: +' +'spelling error' -: ex 'v.=: +' +9!:49 old + + +4!:55 ;:'a a12 a6 a9 b boxq boxs c dispq disps ' +4!:55 ;:'drop1 erase evmq evms nub old p ppq pps promptq ' +4!:55 ;:'prompts q read rlq rls s t v ' + +
new file mode 100644 --- /dev/null +++ b/test/g9x40.ijs @@ -0,0 +1,160 @@ +NB. 9!:40 and 9!:41 ----------------------------------------------------- + +t=: 9!:40 '' +1 -: type t +0 = $#t + +'rank error' -: 9!:40 etx 0 +'rank error' -: 9!:40 etx 1 + +'length error' -: 9!:40 etx 1 2 +'length error' -: 9!:40 etx 'abc' + +'rank error' -: 9!:41 etx ,0 +'rank error' -: 9!:41 etx ,1 + +lf=: 10{a. +nn=: <@((,'0')&;) + +9!:41 ]1 + +f=: 3 : t=: 0 : 0 + assert. 0<:y NB. non-negative + %: y +) + +(5!:1 <'f') -: < (,':');<(nn 3),nn ];._2 t +(5!:2 <'f') -: 3;(,':');];._2 t +(5!:5 <'f') -: '3 : 0',lf,t,')' + +f=: 3 : t=: 0 : 0 + : + assert. 0<:y NB. non-negative + %: y +) + +x=: ':',(t i. lf)}.t + +(5!:1 <'f') -: < (,':');<(nn 3),nn ];._2 x +(5!:2 <'f') -: 3;(,':');];._2 x +(5!:5 <'f') -: '3 : 0',lf,x,')' + +f=: 3 : t=: 0 : 0 + assert. 0<:y NB. non-negative + %: y NB. monadic definition + : + x %: y NB. dyadic definition +) + +x=: (i{.t),(2+i)}.t [ i=: (' :' E. t)i.1 + +(5!:1 <'f') -: < (,':');<(nn 3),nn ];._2 x +(5!:2 <'f') -: 3;(,':');];._2 x +(5!:5 <'f') -: '3 : 0',lf,x,')' + +f=: 4 : t=: 0 : 0 + assert. 0< x NB. positive + assert. 0<:y NB. non-negative + x %: y NB. dyadic only definition +) + +(5!:1 <'f') -: < (,':');<(nn 4),nn ];._2 t +(5!:2 <'f') -: 4;(,':');];._2 t +(5!:5 <'f') -: '4 : 0',lf,t,')' + +f=: 1 : t=: 0 : 0 + assert. 2|2{6!:0 '' NB. only on odd numbered days + x/ +) + +(5!:1 <'f') -: < (,':');<(nn 1),nn ];._2 t +(5!:2 <'f') -: 1;(,':');];._2 t +(5!:5 <'f') -: '1 : 0',lf,t,')' + +f=: 1 : t=: 0 : 0 + : + assert. 2|2{6!:0 '' NB. only on odd numbered days + x u/ y NB. dyadic only +) + +x=: ':',(t i. lf)}.t + +(5!:1 <'f') -: < (,':');<(nn 1),nn ];._2 x +(5!:2 <'f') -: 1;(,':');];._2 x +(5!:5 <'f') -: '1 : 0',lf,x,')' + +f=: 1 : t=: 0 : 0 + assert. 2|2{6!:0 '' NB. only on odd numbered days + u/ y NB. monadic only + : +) + +(5!:1 <'f') -: < (,':');<(nn 1),nn ];._2 t +(5!:2 <'f') -: 1;(,':');];._2 t +(5!:5 <'f') -: '1 : 0',lf,t,')' + +f=: 1 : t=: 0 : 0 + assert. 1=2|2{6!:0 '' NB. only on odd numbered days + u/ y NB. monadic defn + : + assert. 0=2|2{6!:0 '' NB. only on even numbered days + x u/ y NB. dyadic defn +) + +x=: (i{.t),(3+i)}.t [ i=: (' :' E. t)i.1 + +(5!:1 <'f') -: < (,':');<(nn 1),nn ];._2 x +(5!:2 <'f') -: 1;(,':');];._2 x +(5!:5 <'f') -: '1 : 0',lf,x,')' + +f=: 2 : t=: 0 : 0 + assert. 1=2|2{6!:0 '' NB. only on odd numbered days + u^:n +) + +(5!:1 <'f') -: < (,':');<(nn 2),nn ];._2 t +(5!:2 <'f') -: 2;(,':');];._2 t +(5!:5 <'f') -: '2 : 0',lf,t,')' + +f=: 2 : t=: 0 : 0 + : + assert. 1=2|2{6!:0 '' NB. only on odd numbered days + x u^:n y NB. dyadic only +) + +x=: ':',(t i. lf)}.t + +(5!:1 <'f') -: < (,':');<(nn 2),nn ];._2 x +(5!:2 <'f') -: 2;(,':');];._2 x +(5!:5 <'f') -: '2 : 0',lf,x,')' + +f=: 2 : t=: 0 : 0 + assert. 1=2|2{6!:0 '' NB. only on odd numbered days + u^:n y NB. monadic only + : +) + +(5!:1 <'f') -: < (,':');<(nn 2),nn ];._2 t +(5!:2 <'f') -: 2;(,':');];._2 t +(5!:5 <'f') -: '2 : 0',lf,t,')' + +f=: 2 : t=: 0 : 0 + assert. 1=2|2{6!:0 '' NB. only on odd numbered days + u^:n y NB. monadic defn + : + assert. 0=2|2{6!:0 '' NB. only on even numbered days + x u^:n y NB. dyadic defn +) + +x=: (i{.t),(3+i)}.t [ i=: (' :' E. t)i.1 + +(5!:1 <'f') -: < (,':');<(nn 2),nn ];._2 x +(5!:2 <'f') -: 2;(,':');];._2 x +(5!:5 <'f') -: '2 : 0',lf,x,')' + +9!:41 ]0 + + +4!:55 ;:'f i lf nn t x' + +
new file mode 100644 --- /dev/null +++ b/test/ga.ijs @@ -0,0 +1,130 @@ +NB. a. ------------------------------------------------------------------ + +2 -: type a. +1 -: #$a. +256 -: #a. +(i.256) -: i.~a. +32 48 65 97 -: a.i.' 0Aa' + + +NB. a: ------------------------------------------------------------------ + +0 -: #$a: +32 -: 3!:0 a: +($0) -: >a: +a: -: <$0 +a: -: <'' + +'a:' -: 3 : '5!:5<''y''' a: + + +NB. A. ------------------------------------------------------------------ + +boxed =: 32&=@type +pind =: ]`]`+@.(*@])"0 +pfill =: [ ((i.@[-.]) , ]) pind + +ord =: >:@(>./) +base =: >:@i.@-@# +rfd =: +/@({.>}.)\. +dfr =: /:^:2@,/ + +adot1 =: (base #. rfd)@((ord pfill ])`C.@.boxed) " 1 +adot2 =: dfr@(base@] #: [) { ] + +(A. -: adot1) 7?12 +(A. -: adot1) x=:(1=1,?6$3) <;.1 (7?12) + +(?!5) (A. -: adot2) 'xyzab' +(?!5) (A. -: adot2) r.i.5 2 + +5 -: A.0 3 2 1 +5 -: A.3 2 1 +5 -: A.0;2;3 1 +5 -: A.<3 1 + +(_1 A. y) -: |. y=:1=?300 2$2 +(_1 A. y) -: |. y=:(?400$#a.){a. +(_1 A. y) -: |. y=:?300$2000 +(_1 A. y) -: |. y=:o.?400 2$100 +(_1 A. y) -: |. y=:^0j1*?400 2$100 +(_1 A. y) -: |. y=:^0j1*?400 2$100 +(_1 A. y) -: |. y=:(?400$#y){y=:;:'^0j1*?400 2$100' + +(0 A. y) -: y=:1=?2 +(0 A. y) -: y=:(?#a.){a. +(0 A. y) -: y=:?20000 +(0 A. y) -: y=:o.?20000 +(0 A. y) -: y=:^0j1*?2000 +(0 A. y) -: y=:<^0j1*?2000 + +(_1 A. y) -: y=:1=?2 +(_1 A. y) -: y=:(?#a.){a. +(_1 A. y) -: y=:?20000 +(_1 A. y) -: y=:o.?20000 +(_1 A. y) -: y=:^0j1*?2000 +(_1 A. y) -: y=:<^0j1*?2000 + +(0 A. y) -: y=:i.0 4 5 +(0 A. y) -: y=:0 5$a. +(0 A. y) -: y=:0$<1234 + +([ -: 3&A.^:_1@(3&A.)) x=:?100$10000 +([ -: 3&A.^:_1@(3&A.)) x=:?20 4$100 +([ -: 3&A.^:_1@(3&A.)) x=:(?200$3){;:'Hey nonny nonny' + +([ -: A.&y^:_1@(A.&y)) x=:?100$#y=:~.'Antebellum' +([ -: A.&y^:_1@(A.&y)) x=:?100$#y=:100?100 + +0 -: A. i.0 +(i.1 0) -: (i.1) A. i.0 + +(3 4$0) -: A."0 ]3 4 ?@$ 100 + +'domain error' -: A. etx 'abcd' +'domain error' -: A. etx 3 4;'abc' +'domain error' -: A. etx 3.4 5 +'domain error' -: A. etx 3j4 5 + +'domain error' -: 'ab' A. etx i.4 +'domain error' -: 3.5 A. etx i.4 +'domain error' -: 3j5 A. etx i.4 +'domain error' -: (<5) A. etx i.4 + +'domain error' -: A.&1 2 2^:_1 etx 4 + +'index error' -: 24 A. etx 'abcd' +'index error' -: _25 A. etx 'abcd' + + +NB. A. encore ----------------------------------------------------------- + +p0 =: i.@! A. i. + +j=:?~!5 +p=:j{p0 5 +j -: A.p +j -: A.@C.p +p -: j A.i.5 + +grow =: [: ,/ 0&,.@:>: {"2 1 \:"1@=@(_1&,)@{. + +p1 =: 1 0&$`([: ,/ 0&,.@($:&.(<:"_)) {"2 1 \:"1@=@i.) @. * +p2 =: grow^:(]`(1 0&$)) +p3 =: 3 : 'grow^:y i.1 0' + +p4 =: 3 : 0 + z=. i.1 0 + for. i.y do. z=.,/(0,.1+z){"2 1\:"1=i.>:{:$z end. +) + +(p0 -: p1)"0 i.6 +(p0 -: p2)"0 i.6 +(p0 -: p3)"0 i.6 +(p0 -: p4)"0 i.6 + + +4!:55 ;:'adot1 adot2 base boxed dfr grow j ord p p0 ' +4!:55 ;:'p1 p2 p3 p4 pfill pind rfd x y z ' + +
new file mode 100644 --- /dev/null +++ b/test/gassert.ijs @@ -0,0 +1,66 @@ +NB. assert -------------------------------------------------------------- + +1: 9!:41 ]1 + +lf=: 10{a. + +f=: 3 : 0 + assert. y + 1 +) + +1 -: f 1 +1 -: f 1 1 1 +1 -: f (?3$5)$1 +1 -: f '' +1 -: f }. 314 1 1 1 +1 -: f }. 3.4 1 1 1 +1 -: f }. 3j4 1 1 1 +1 -: f }. 31x 1 1 1 +1 -: f }. 3r4 1 1 1 + +'assertion failure' -: f etx 0 +'assertion failure' -: f etx 0 0 0 +'assertion failure' -: f etx 1 1 1 0 +'assertion failure' -: f etx ' 2 3' +'assertion failure' -: f etx 1;2 3 +'assertion failure' -: f etx 1 2 3 +'assertion failure' -: f etx 1 2.3 +'assertion failure' -: f etx 1 2j3 +'assertion failure' -: f etx 1 2r3 +'assertion failure' -: f etx 1 233x +'assertion failure' -: f etx s: ' 1 2 3' + +s=: 1 (5!:7) <'f' +(2{.>s{~<0;1) -: 25 65535 + +s=: 5!:5 <'f' +s -: '3 : 0',lf,' assert. y',lf,' 1',lf,')' + +word=: 3 : 0 + assert. 1>:#$y + assert. y e. a. + assert. +./ 'aeiouyAEIOUY' e. ,y + 1 +) + +word 'kerygmatic' +word 'lucubrations' + +'assertion failure' -: word etx 1 2 3 +'assertion failure' -: word etx ,: 'kerygmatic' +'assertion failure' -: word etx 'zzz' + +'control error' -: ex '3 : s' [ s=: 'assert.',lf,'if. y do. 1 end.' +'control error' -: ex '3 : s' [ s=: 'assert.',lf,'assert. 0=y',lf,'2' + +s=: 0 : 0 + if. y do. 'true' else. 'false' end. + assert. +) + +'control error' -: ex '3 : s' + + +4!:55 ;:'f lf s word' +
new file mode 100644 --- /dev/null +++ b/test/gb.ijs @@ -0,0 +1,248 @@ +NB. n b. ---------------------------------------------------------------- + +0 0 0 1 -: 0 0 1 1 (1 b.) 0 1 0 1 +0 1 1 1 -: 0 0 1 1 (7 b.) 0 1 0 1 + +0 0 0 1 -: 0 0 1 1 (+&.o.1) b. 0 1 0 1 + +(|:#:i.16) -: 0 0 1 1 (i.16) b. 0 1 0 1 +(|:(4#2)#:_16+i.16) -: 0 0 1 1 (_16+i.16) b. 0 1 0 1 + +f =: (i.16) b. +(f 0 1) -: 0 f 0 1 + +f =: (_16+i.16) b. +(f 0 1) -: 0 f 0 1 + +5 6 3 0 4 -: $ (i.3 0 4) b. 5 6$1 +4 3 0 2 -: $ 0 0 1 1 (i.3 0 2) b. 0 1 0 1 + +'domain error' -: ex '''b'' b.' +'index error' -: ex '36 b.' +'index error' -: ex '_17 b.' +'domain error' -: ex '3.4 b.' +'domain error' -: ex '3j4 b.' +'domain error' -: ex '(<1) b.' + +f =: (?16) b. + +'domain error' -: 'a' f etx 1 +'domain error' -: 2 f etx 1 +'domain error' -: 3.4 f etx 1 +'domain error' -: 3j4 f etx 1 +'domain error' -: (<1)f etx 1 + +'domain error' -: f etx 'a' +'domain error' -: f etx 2 +'domain error' -: f etx 3.4 +'domain error' -: f etx 3j4 +'domain error' -: f etx <1 + + +NB. n b. bitwise operations --------------------------------------------- + +N=: IF64{32 64 +B=: N $ 2 +f=: B&#: + +x=: (_1^?100$2) * ?100$2e9 +y=: (_1^?100$2) * ?100$2e9 + +(x 0"0 &f y) -: f x (16+#.0 0 0 0) b. y +(x *. &f y) -: f x (16+#.0 0 0 1) b. y +(x > &f y) -: f x (16+#.0 0 1 0) b. y +(x ["0 &f y) -: f x (16+#.0 0 1 1) b. y +(x < &f y) -: f x (16+#.0 1 0 0) b. y +(x ]"0 &f y) -: f x (16+#.0 1 0 1) b. y +(x ~: &f y) -: f x (16+#.0 1 1 0) b. y +(x +. &f y) -: f x (16+#.0 1 1 1) b. y +(x +: &f y) -: f x (16+#.1 0 0 0) b. y +(x = &f y) -: f x (16+#.1 0 0 1) b. y +(x -.@]"0&f y) -: f x (16+#.1 0 1 0) b. y +(x >: &f y) -: f x (16+#.1 0 1 1) b. y +(x -.@["0&f y) -: f x (16+#.1 1 0 0) b. y +(x <: &f y) -: f x (16+#.1 1 0 1) b. y +(x *: &f y) -: f x (16+#.1 1 1 0) b. y +(x 1"0 &f y) -: f x (16+#.1 1 1 1) b. y + +g0=: 4 : 0 + r=. x + x=. y + r1=. 1+r + assert. (0"0 /"r1&f x) -: f (16+#.0 0 0 0) b./"r x + assert. (*. /"r1&f x) -: f (16+#.0 0 0 1) b./"r x + assert. (> /"r1&f x) -: f (16+#.0 0 1 0) b./"r x + assert. (["0 /"r1&f x) -: f (16+#.0 0 1 1) b./"r x + assert. (< /"r1&f x) -: f (16+#.0 1 0 0) b./"r x + assert. (]"0 /"r1&f x) -: f (16+#.0 1 0 1) b./"r x + assert. (~: /"r1&f x) -: f (16+#.0 1 1 0) b./"r x + assert. (+. /"r1&f x) -: f (16+#.0 1 1 1) b./"r x + assert. (+: /"r1&f x) -: f (16+#.1 0 0 0) b./"r x + assert. (= /"r1&f x) -: f (16+#.1 0 0 1) b./"r x + assert. (-.@]"0/"r1&f x) -: f (16+#.1 0 1 0) b./"r x + assert. (>: /"r1&f x) -: f (16+#.1 0 1 1) b./"r x + assert. (-.@["0/"r1&f x) -: f (16+#.1 1 0 0) b./"r x + assert. (<: /"r1&f x) -: f (16+#.1 1 0 1) b./"r x + assert. (*: /"r1&f x) -: f (16+#.1 1 1 0) b./"r x + assert. (1"0 /"r1&f x) -: f (16+#.1 1 1 1) b./"r x + 1 +) + +1 g0 x=: (? * _1: ^ ?@($&2)@$) 7 13 11$2e9 +2 g0 x +3 g0 x + +g1=: 4 : 0 + r=. x + x=. y + r1=. 1+r + assert. (0"0 /\."r1&f x) -: f (16+#.0 0 0 0) b./\."r x + assert. (*. /\."r1&f x) -: f (16+#.0 0 0 1) b./\."r x + assert. (> /\."r1&f x) -: f (16+#.0 0 1 0) b./\."r x + assert. (["0 /\."r1&f x) -: f (16+#.0 0 1 1) b./\."r x + assert. (< /\."r1&f x) -: f (16+#.0 1 0 0) b./\."r x + assert. (]"0 /\."r1&f x) -: f (16+#.0 1 0 1) b./\."r x + assert. (~: /\."r1&f x) -: f (16+#.0 1 1 0) b./\."r x + assert. (+. /\."r1&f x) -: f (16+#.0 1 1 1) b./\."r x + assert. (+: /\."r1&f x) -: f (16+#.1 0 0 0) b./\."r x + assert. (= /\."r1&f x) -: f (16+#.1 0 0 1) b./\."r x + assert. (-.@]"0/\."r1&f x) -: f (16+#.1 0 1 0) b./\."r x + assert. (>: /\."r1&f x) -: f (16+#.1 0 1 1) b./\."r x + assert. (-.@["0/\."r1&f x) -: f (16+#.1 1 0 0) b./\."r x + assert. (<: /\."r1&f x) -: f (16+#.1 1 0 1) b./\."r x + assert. (*: /\."r1&f x) -: f (16+#.1 1 1 0) b./\."r x + assert. (1"0 /\."r1&f x) -: f (16+#.1 1 1 1) b./\."r x + 1 +) + +1 g1 x=: (? * _1: ^ ?@($&2)@$) 7 13 11$2e9 +2 g1 x +3 g1 x + +g2=: 4 : 0 + r=. x + x=. y + r1=. 1+r + assert. (0"0 /\"r1&f x) -: f (16+#.0 0 0 0) b./\"r x + assert. (*. /\"r1&f x) -: f (16+#.0 0 0 1) b./\"r x + assert. (> /\"r1&f x) -: f (16+#.0 0 1 0) b./\"r x + assert. (["0 /\"r1&f x) -: f (16+#.0 0 1 1) b./\"r x + assert. (< /\"r1&f x) -: f (16+#.0 1 0 0) b./\"r x + assert. (]"0 /\"r1&f x) -: f (16+#.0 1 0 1) b./\"r x + assert. (~: /\"r1&f x) -: f (16+#.0 1 1 0) b./\"r x + assert. (+. /\"r1&f x) -: f (16+#.0 1 1 1) b./\"r x + assert. (+: /\"r1&f x) -: f (16+#.1 0 0 0) b./\"r x + assert. (= /\"r1&f x) -: f (16+#.1 0 0 1) b./\"r x + assert. (-.@]"0/\"r1&f x) -: f (16+#.1 0 1 0) b./\"r x + assert. (>: /\"r1&f x) -: f (16+#.1 0 1 1) b./\"r x + assert. (-.@["0/\"r1&f x) -: f (16+#.1 1 0 0) b./\"r x + assert. (<: /\"r1&f x) -: f (16+#.1 1 0 1) b./\"r x + assert. (*: /\"r1&f x) -: f (16+#.1 1 1 0) b./\"r x + assert. (1"0 /\"r1&f x) -: f (16+#.1 1 1 1) b./\"r x + 1 +) + +1 g2 x=: (? * _1: ^ ?@($&2)@$) 7 13 11$2e9 +2 g2 x +3 g2 x + +x=: (? * _1: ^ ?@($&2)@$) 2 3 5$2e9 +y=: (? * _1: ^ ?@($&2)@$) 7 3 $2e9 + +(x 0"0 "1/&f y) -: f x (16+#.0 0 0 0) b./y +(x *. "1/&f y) -: f x (16+#.0 0 0 1) b./y +(x > "1/&f y) -: f x (16+#.0 0 1 0) b./y +(x ["0 "1/&f y) -: f x (16+#.0 0 1 1) b./y +(x < "1/&f y) -: f x (16+#.0 1 0 0) b./y +(x ]"0 "1/&f y) -: f x (16+#.0 1 0 1) b./y +(x ~: "1/&f y) -: f x (16+#.0 1 1 0) b./y +(x +. "1/&f y) -: f x (16+#.0 1 1 1) b./y +(x +: "1/&f y) -: f x (16+#.1 0 0 0) b./y +(x = "1/&f y) -: f x (16+#.1 0 0 1) b./y +(x -.@]"0"1/&f y) -: f x (16+#.1 0 1 0) b./y +(x >: "1/&f y) -: f x (16+#.1 0 1 1) b./y +(x -.@["0"1/&f y) -: f x (16+#.1 1 0 0) b./y +(x <: "1/&f y) -: f x (16+#.1 1 0 1) b./y +(x *: "1/&f y) -: f x (16+#.1 1 1 0) b./y +(x 1"0 "1/&f y) -: f x (16+#.1 1 1 1) b./y + + +NB. 32 33 34 b. --------------------------------------------------------- + +test=: 3 : 0 + assert. xx (f -: g) yy [ xx=: ?4 5$2e9 [ yy=: ?4 5$2e9 + assert. xx (f -: g) -yy + assert. (-xx) (f -: g) yy + assert. (-xx) (f -: g) -yy + assert. xx (f -: g) 0*yy + assert. (-xx) (f -: g) 0*yy + assert. 0 (f -: g) yy + assert. 0 (f -: g) -yy + assert. xx (f -: g) yy [ xx=: imin + assert. xx (f -: g) -yy + assert. xx (f -: g) yy [ xx=: imax + assert. xx (f -: g) -yy + assert. xx (f -: g) yy [ xx=: 4 5 ?@$100 [ yy=: imin + assert. (-xx) (f -: g) yy + assert. xx (f -: g) yy [ xx=: 4 5 ?@$2e9 [ yy=: imin + assert. (-xx) (f -: g) yy + assert. xx (f -: g) yy [ xx=: 4 5 ?@$100 [ yy=: imax + assert. (-xx) (f -: g) yy + assert. xx (f -: g) yy [ xx=: 4 5 ?@$2e9 [ yy=: imax + assert. (-xx) (f -: g) yy + 1 +) + +f=: 4 : 'x|. B#:y' " 0 +g=: B&#:@(32 b.) +test '' + +f=: 4 : 'x |.!.0 B#: y' " 0 +g=: B&#:@(33 b.) +test '' + +f=: 4 : '(N {. (N<.|x)$(0>x)*.0>y) +. x |.!.0"0 1 B#: y' " 0 +g=: B&#:@(34 b.) +test '' + + +NB. v b. ---------------------------------------------------------------- + +0 0 0 -: + b. 0 +2 _ 2 -: %. b. 0 + +((":/:p),'&{') -: p&{ b. _1 [ p=:?~13 +'^.' -: ^ b. _1 + +'0 $~ }.@$' -: + b. 1 +'0 $~ }.@$' -: *&.^ b. 1 +'1 $~ }.@$' -: * b. 1 +'1 $~ }.@$' -: +&.^. b. 1 + +_ _ _ -: asdfnotexist b. 0 + +'domain error' -: + b. etx 2 +'domain error' -: ^ b. etx _2 +'domain error' -: - b. etx _ +'domain error' -: ^ b. etx 0.5 + + +NB. n b. inverse -------------------------------------------------------- + +x -: ]&.(12345&(22 b.)) x=: (] , -) 20 ?@$ 2e9 +x -: ]&.(12345&(25 b.)) x +x -: ]&.(12345&(21 b.)) x +x -: ]&.(12345&(26 b.)) x + +x -: ]&.(19 b.&12345) x +x -: ]&.(28 b.&12345) x + +'domain error' -: ex '21 b.&12345 b. _1' +'domain error' -: ex '26 b.&12345 b. _1' +'domain error' -: ex '12345&(19 b.) b. _1' +'domain error' -: ex '12345&(28 b.) b. _1' + + +4!:55 ;:'B d f g g0 g1 g2 N p test x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/gbpar.ijs @@ -0,0 +1,104 @@ +NB. byte parallel ------------------------------------------------------- +NB. m-bytes-at-a-time operations on boolean functions + +A=: 1 : 0 +: + g=: 4 : ('x ',(5!:5 <'u'),' y') + xx=: x ?@$ 2 + yy=: (x,c=. y) ?@$ 2 + assert. (xx u yy) -: (c#"0 xx) u yy + assert. (xx u yy) -: xx g"0 1 yy + assert. (yy u xx) -: yy u c#"0 xx + assert. (yy u xx) -: yy g"1 0 xx + 1 +) + +s=: 17 +s = A"1 0 >:i.25 +s < A"1 0 >:i.25 +s <: A"1 0 >:i.25 +s > A"1 0 >:i.25 +s >: A"1 0 >:i.25 +s +. A"1 0 >:i.25 +s +: A"1 0 >:i.25 +s *. A"1 0 >:i.25 +s *: A"1 0 >:i.25 +s ~: A"1 0 >:i.25 + +I=: 1 : 0 +: + b=: (x,y) ?@$ 2 + assert. (u/ -: u/"1&.|: ) b + assert. (u/"2 -: u/"1&.|:"2 ) b + assert. (u/"1 -: {.@(u/\.)"1) b + assert. (u/"1 -: {:@(u/\ )"1) b + 1 +) + +s=: 5 11 +s = I"1 0 >:i.25 +s < I"1 0 >:i.25 +s <: I"1 0 >:i.25 +s > I"1 0 >:i.25 +s >: I"1 0 >:i.25 +s +. I"1 0 >:i.25 +s +: I"1 0 >:i.25 +s *. I"1 0 >:i.25 +s *: I"1 0 >:i.25 +s ~: I"1 0 >:i.25 + +f=: 4 : 0 + b=: (x,y) ?@$ 2 + assert. (~:/"1 b) -: 2|+/"1 b + assert. (= /"1 b) -: ~:/&.:-."1 b + assert. (+ /"1 b) -: +/"1 b+0 + 1 +) + +17 f"1 0 ]1 +i.25 +2 5 f"1 0 ]1 +i.25 +'' f"1 0 ]256+i.25 + +P=: 1 : 0 +: + b=: (x,y) ?@$ 2 + assert. (u/\ -: u/\"1&.|: ) b + assert. (u/\"2 -: u/\"1&.|:"2) b + 1 +) + +s=: 5 11 +s = P"1 0 >:i.17 +s < P"1 0 >:i.17 +s <: P"1 0 >:i.17 +s > P"1 0 >:i.17 +s >: P"1 0 >:i.17 +s +. P"1 0 >:i.17 +s +: P"1 0 >:i.17 +s *. P"1 0 >:i.17 +s *: P"1 0 >:i.17 +s ~: P"1 0 >:i.17 + +S=: 1 : 0 +: + b=: (x,y) ?@$ 2 + assert. (u/\. -: u/\."1&.|: ) b + assert. (u/\."2 -: u/\."1&.|:"2) b + 1 +) + +s=: 5 11 +s = S"1 0 >:i.17 +s < S"1 0 >:i.17 +s <: S"1 0 >:i.17 +s > S"1 0 >:i.17 +s >: S"1 0 >:i.17 +s +. S"1 0 >:i.17 +s +: S"1 0 >:i.17 +s *. S"1 0 >:i.17 +s *: S"1 0 >:i.17 +s ~: S"1 0 >:i.17 + + +4!:55 ;:'A b c f g I P S s xx yy' + \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/gc.ijs @@ -0,0 +1,169 @@ +NB. C.y ----------------------------------------------------------------- + +boxed =: 32&=@type +ord =: >:@(>./) +pind =: ]`]`+@.(*@])"0 +pfill =: [ ((i.@[-.]) , ]) pind + +ac =: (, i. ]) { 1&|.@[ , ] +dfc =: >@(ac&.>/)@(pind&.> , <@i.@[) +bc =: <@((i.>./) |. ])@~. +cfd =: ~.@(/: {.&>)@:(bc"1)@|:@({/\)@(,~@[ $ pfill) +cdot1 =: (ord cfd ])`(ord@; dfc ])@.boxed " 1 + +isperm =: 3 : '(/:~y)-:i.#y' " 1 +iscyc =: 3 : '(isperm ;y)*.(({.&>y)-:>./&>y)*.(i.#y)-:/:{.&>y' " 1 + +(C.4 5 2 1 0 3) -: (,2);4 0;5 3 1 +(C.2;4 0;5 3 1) -: 4 5 2 1 0 3 +'C.' -: C. b. _1 + +p =: 12?15$12 +^/@:(iscyc@C.) p +p -: C.&C. p +c =: C.p +c -: C.C.c +^/@:(C. -: cdot1) p + +(C.k ) -: (,&.>i._1{k),<k [ k =: 1 0+?100 +(C.k,_2) -: (,&.>i. <:k),<k-0 1 [ k =: 2+?100 + +'domain error' -: C. etx 'abcde' +'domain error' -: C. etx 3j4 5 +'domain error' -: C. etx 3 4;'abc' + + +NB. C.!.2 y ------------------------------------------------------------- + +parity=: 3 : 0 " 1 + n=. #q=. y + p=. 0 + for_i. i. n do. + if. i~:j=. q i. i do. + q=. (i,i{q) (i,j)}q + p=. -. p + end. + end. + _1^p +) + +(parity -: C.!.2) (i.!n) A. i.n=:3 +(parity -: C.!.2) (i.!n) A. i.n=:4 +(parity -: C.!.2) (i.!n) A. i.n=:5 + +0 1 _1 -: C.!.2 ]2 , (i.8) ,: 1 0 2 3 4 5 6 7 + +CT=: 3 : '(C.!.2 p) (<"1 p)}1$.$~y [ p=. (i.!y) A. i.y' NB. complete tensor + +(CT 3) -: C.!.2&> {i.&.> $~ 3 +(CT 4) -: C.!.2&> {i.&.> $~ 4 + +'domain error' -: ex 'C.!.3 ' +'domain error' -: ex 'C.!.''a''' +'domain error' -: ex 'C.!.(<2) ' + +'rank error' -: ex 'C.!.2 2 ' + + +NB. x C.y --------------------------------------------------------------- + +boxed =: 32&=@type +pind =: ]`]`+@.(*@])"0 +pfill =: [ ((i.@[-.]) , ]) pind + +ac =: (, i. ]) { 1&|.@[ , ] +dfc =: >@(ac&.>/)@(pind&.> , <@i.@[) +cdot2 =: ((#@] pfill`dfc@.(boxed@]) [) { ]) " 1 _ + +cyc =: (1&<@#@> # ])@C. + +p (C. -: cdot2) x [ p=:?~#x=:1=?200 2$2 +p (C. -: cdot2) x [ p=:?~#x=:(?200$#a.){a. +p (C. -: cdot2) x [ p=:?~#x=:?200 2$2 +p (C. -: cdot2) x [ p=:?~#x=:o.?200 2$2 +p (C. -: cdot2) x [ p=:?~#x=:r.?200$2002 +p (C. -: cdot2) x [ p=:?~#x=:(?200$#t){t=:;:'#a.){a.now is the 1 2 3' + +(cyc p) (C. -: cdot2) x [ p=:?~#x=:1=?200 2$2 +(cyc p) (C. -: cdot2) x [ p=:?~#x=:(?200$#a.){a. +(cyc p) (C. -: cdot2) x [ p=:?~#x=:?200 2$2 +(cyc p) (C. -: cdot2) x [ p=:?~#x=:o.?200 2$2 +(cyc p) (C. -: cdot2) x [ p=:?~#x=:r.?200$2002 +(cyc p) (C. -: cdot2) x [ p=:?~#x=:(?200$#t){t=:;:'#a.){a.now is the 1 2 3' + +1 2 3 0 4 -: (2 1;3 0 1)C.i.5 + +(p C. x) -: (p=:?~200){x=:1=?200 2$2 +(p C. x) -: (p=:?~200){x=:(?200$#a.){a. +(p C. x) -: (p=:?~200){x=:?200 2$2000 +(p C. x) -: (p=:?~200){x=:o.?200 2$2000 +(p C. x) -: (p=:?~200){x=:^0j1*?200$200 +(p C. x) -: (p=:?~200){x=:(?200$#x){x=:;:'#a.){a.now is the 1 2 3' + +((cyc p) C. x) -: (p=:?~400){x=:1=?400 2$2 +((cyc p) C. x) -: (p=:?~1200){x=:(?1200$#a.){a. +((cyc p) C. x) -: (p=:?~200){x=:?200 2$2000 +((cyc p) C. x) -: (p=:?~200){x=:o.?200 2$2000 +((cyc p) C. x) -: (p=:?~200){x=:^0j1*?200$200 +((cyc p) C. x) -: (p=:?~200){x=:(?200$#x){x=:;:'#a.){a.now is the 1 2 3' + +'index error' -: 0 1 24 C. etx i.4 +'index error' -: 0 1 _24 C. etx i.4 + +'domain error' -: 3 4j5 C. etx i.4 +'domain error' -: 'abc' C. etx i.4 +'domain error' -: (3 4;'a') C. etx i.4 + + +NB. C. ------------------------------------------------------------------ + +pow =: i.@#@[ C.~ (#&>@C.@[|]) # C.@[ NB. y-th power of permutation x +ord =: *./@(#&>"_)@C. NB. the order of permutation y + +assert=: 0!:2@":^:-. NB. assert y signal error if 0=y + +g0 =: , ,. =@i.@2: NB. initial state for GCD +it =: {: ,: {. - {: * <.@%&{./ NB. iterative step for GCD +gcd =: (}.@{.)@(it^:(*@{.@{:)^:_)@g0 NB. GCD as a linear combination + +ab =: |.@(gcd/ * [ % +./)@(,&{.) NB. coeff. for Chinese Remainder +cr =: [: |/\ *.&{. , ,&{: +/ .* ab NB. Chinese Remainder + +wh =: <:@#@[ - { i. {:@[ NB. oc wh q index in opened cycle +chk0 =: [: assert { -: wh |. [ NB. oc chk0 q 1 iff q is legal +where =: wh [ chk0 NB. oc where q wh with validation +mr =: #&>@[ ,. (>@[ where ])"0 1 NB. c mr q moduli and residues +chk1 =: ] [ [: assert {:@[ -: {.@[|] NB. check Chinese Remainder +log =: (|: chk1 {:@(cr/)) @ (C.@[mr]) NB. q -: p pow p log q + +p=:?~300 +(i.#p) -: p pow 0 +p -: p pow 1 +(p{p) -: p pow 2 +(p{p{p) -: p pow 3 +(/:p) -: p pow <:ord p +(i.#p) -: p pow ord p + +p1 =: {^:(]`(i.@#@[)) NB. much slower than pow +p (pow -: p1) k=:?10000 +p (pow -: p1) k=:?10000 + +0 $ 0 : 0 +n=:ord p +(n-1) = p log /:p +0 = p log i.#p +1 = p log p +2 = p log p{p +3 = p log p{p{p +3 = p log p pow 3 +k = p log p pow k=:?n +k = p log"1 p pow"1 0 k=:?2 10$n +) + + +4!:55 ;:'ab ac assert bc boxed c cdot1 cdot2 cfd chk0 ' +4!:55 ;:'chk1 cr CT cyc dfc f g g0 gcd iscyc ' +4!:55 ;:'isperm it k log mr n ord p p1 parity pfill ' +4!:55 ;:'pind pow t wh where x ' + +
new file mode 100644 --- /dev/null +++ b/test/gcompsc.ijs @@ -0,0 +1,472 @@ +NB. fork special code for the following cases: -------------------------- +NB. comp i. 0: i.&0@:comp +NB. comp i. 1: i.&1@:comp +NB. comp i: 0: i:&0@:comp +NB. comp i: 1: i:&1@:comp +NB. [: + / comp + /@:comp +NB. [: +./ comp +./@:comp +NB. [: *./ comp *./@:comp +NB. [: I. comp I. @:comp +NB. where comp is one of the following: +NB. = ~: < <: >: > E. e. + +sp=: 7!:2 + +ftab=: 2 : 0 + select. x 2 2 0 1 0 1 NB. detect what x is by applying it + case. 2 do. y i. 0: + case. 3 do. y i. 1: + case. 4 do. y i: 0: + case. 5 do. y i: 1: + case. 6 do. [: + / y + case. 1 do. [: +./ y + case. 0 do. [: *./ y + case. 0 0 1 1 3 5 do. [: I. y + end. +) + +data=: 3 : 0 + xb=: 1000?@$2 [ yb=: 1000?@$2 + xi=: _5e8 + 1000?@$1e9 [ yi=: _5e8 + 1000?@$1e9 + xd=: 0.01 * _5e8 + 1000?@$1e9 [ yd=: 0.01 * _5e8 + 1000?@$1e9 + xs=: s: ' ',": 1000?@$4000 [ ys=: s: ' ',":1000?@$4000 + ai=: _5e8 + ?1e9 + ad=: 0.01 * _5e8 + ?1e9 + as=: {. s: ":?4000 + zb=: 0$0 + zi=: 0$2 + zd=: 0$2.3 + zs=: 0$as + xb1=: 1001?@$2 [ yb1=: 1001?@$2 + xb2=: 1002?@$2 [ yb2=: 1002?@$2 + xb3=: 1003?@$2 [ yb3=: 1003?@$2 + xb4=: 1004?@$2 [ yb4=: 1004?@$2 + xb5=: 1005?@$2 [ yb5=: 1005?@$2 + xb6=: 1006?@$2 [ yb6=: 1006?@$2 + xb7=: 1007?@$2 [ yb7=: 1007?@$2 + i.0 0 +) + +testvv=: 2 : 0 NB. vector vector + : + assert. (u xb v yb) -: xb u@:v yb + assert. (u xb v yi) -: xb u@:v yi + assert. (u xb v yd) -: xb u@:v yd + assert. (u xi v yb) -: xi u@:v yb + assert. (u xi v yi) -: xi u@:v yi + assert. (u xi v yd) -: xi u@:v yd + assert. (u xd v yb) -: xd u@:v yb + assert. (u xd v yi) -: xd u@:v yi + assert. (u xd v yd) -: xd u@:v yd + assert. (u xs v ys) -: xs u@:v ys + f=: u ftab v + assert. (u xb v yb) -: xb f yb + assert. (u xb v yi) -: xb f yi + assert. (u xb v yd) -: xb f yd + assert. (u xi v yb) -: xi f yb + assert. (u xi v yi) -: xi f yi + assert. (u xi v yd) -: xi f yd + assert. (u xd v yb) -: xd f yb + assert. (u xd v yi) -: xd f yi + assert. (u xd v yd) -: xd f yd + assert. (u xs v ys) -: xs f ys + 1 +) + +testsv=: 2 : 0 NB. scalar vector + : + assert. (u 0 v zb) -: 0 u@:v zb + assert. (u 0 v zi) -: 0 u@:v zi + assert. (u 0 v zd) -: 0 u@:v zd + assert. (u 0 v yb) -: 0 u@:v yb + assert. (u 0 v yi) -: 0 u@:v yi + assert. (u 0 v yd) -: 0 u@:v yd + assert. (u 1 v zb) -: 1 u@:v zb + assert. (u 1 v zi) -: 1 u@:v zi + assert. (u 1 v zd) -: 1 u@:v zd + assert. (u 1 v yb) -: 1 u@:v yb + assert. (u 1 v yi) -: 1 u@:v yi + assert. (u 1 v yd) -: 1 u@:v yd + assert. (u ai v yb) -: ai u@:v yb + assert. (u ai v yi) -: ai u@:v yi + assert. (u ai v yd) -: ai u@:v yd + assert. (u ad v yb) -: ad u@:v yb + assert. (u ad v yi) -: ad u@:v yi + assert. (u ad v yd) -: ad u@:v yd + assert. (u as v ys) -: as u@:v ys + f=: u ftab v + assert. (u 0 v yb) -: 0 f yb + assert. (u 0 v yi) -: 0 f yi + assert. (u 0 v yd) -: 0 f yd + assert. (u 1 v yb) -: 1 f yb + assert. (u 1 v yi) -: 1 f yi + assert. (u 1 v yd) -: 1 f yd + assert. (u ai v yb) -: ai f yb + assert. (u ai v yi) -: ai f yi + assert. (u ai v yd) -: ai f yd + assert. (u ad v yb) -: ad f yb + assert. (u ad v yi) -: ad f yi + assert. (u ad v yd) -: ad f yd + assert. (u as v ys) -: as f ys + 1 +) + +testvs=: 2 : 0 NB. vector scalar + : + assert. (u xb v 0 ) -: xb u@:v 0 + assert. (u xb v 1 ) -: xb u@:v 1 + assert. (u xb v ai) -: xb u@:v ai + assert. (u xb v ad) -: xb u@:v ad + assert. (u xi v 0 ) -: xi u@:v 0 + assert. (u xi v 1 ) -: xi u@:v 1 + assert. (u xi v ai) -: xi u@:v ai + assert. (u xi v ad) -: xi u@:v ad + assert. (u xd v 0 ) -: xd u@:v 0 + assert. (u xd v 1 ) -: xd u@:v 1 + assert. (u xd v ai) -: xd u@:v ai + assert. (u xd v ad) -: xd u@:v ad + assert. (u xs v as) -: xs u@:v as + f=: u ftab v + assert. (u xb v 0 ) -: xb f 0 + assert. (u xb v 1 ) -: xb f 1 + assert. (u xb v ai) -: xb f ai + assert. (u xb v ad) -: xb f ad + assert. (u xi v 0 ) -: xi f 0 + assert. (u xi v 1 ) -: xi f 1 + assert. (u xi v ai) -: xi f ai + assert. (u xi v ad) -: xi f ad + assert. (u xd v 0 ) -: xd f 0 + assert. (u xd v 1 ) -: xd f 1 + assert. (u xd v ai) -: xd f ai + assert. (u xd v ad) -: xd f ad + assert. (u xs v as) -: xs f as + 1 +) + +testss=: 2 : 0 NB. scalar scalar + : + assert. (u 0 v 0 ) -: 0 u@:v 0 + assert. (u 0 v 1 ) -: 0 u@:v 1 + assert. (u 0 v ai) -: 0 u@:v ai + assert. (u 0 v ad) -: 0 u@:v ad + assert. (u 1 v 0 ) -: 1 u@:v 0 + assert. (u 1 v 1 ) -: 1 u@:v 1 + assert. (u 1 v ai) -: 1 u@:v ai + assert. (u 1 v ad) -: 1 u@:v ad + assert. (u ai v 0 ) -: ai u@:v 0 + assert. (u ai v 1 ) -: ai u@:v 1 + assert. (u ai v ai) -: ai u@:v ai + assert. (u ai v ad) -: ai u@:v ad + assert. (u ad v 0 ) -: ad u@:v 0 + assert. (u ad v 1 ) -: ad u@:v 1 + assert. (u ad v ai) -: ad u@:v ai + assert. (u ad v ad) -: ad u@:v ad + assert. (u as v as) -: as u@:v as + f=: u ftab v + assert. (u 0 v 0 ) -: 0 f 0 + assert. (u 0 v 1 ) -: 0 f 1 + assert. (u 0 v ai) -: 0 f ai + assert. (u 0 v ad) -: 0 f ad + assert. (u 1 v 0 ) -: 1 f 0 + assert. (u 1 v 1 ) -: 1 f 1 + assert. (u 1 v ai) -: 1 f ai + assert. (u 1 v ad) -: 1 f ad + assert. (u ai v 0 ) -: ai f 0 + assert. (u ai v 1 ) -: ai f 1 + assert. (u ai v ai) -: ai f ai + assert. (u ai v ad) -: ai f ad + assert. (u ad v 0 ) -: ad f 0 + assert. (u ad v 1 ) -: ad f 1 + assert. (u ad v ai) -: ad f ai + assert. (u ad v ad) -: ad f ad + assert. (u as v as) -: as f as + 1 +) + +testbvv=: 2 : 0 NB. boolean vector vector + : + assert. (u xb v yb ) -: xb u@:v yb + assert. (u xb1 v yb1) -: xb1 u@:v yb1 + assert. (u xb2 v yb2) -: xb2 u@:v yb2 + assert. (u xb3 v yb3) -: xb3 u@:v yb3 + assert. (u xb4 v yb4) -: xb4 u@:v yb4 + assert. (u xb5 v yb5) -: xb5 u@:v yb5 + assert. (u xb6 v yb6) -: xb6 u@:v yb6 + assert. (u xb7 v yb7) -: xb7 u@:v yb7 + f=: u ftab v + assert. (u xb v yb ) -: xb f yb + assert. (u xb1 v yb1) -: xb1 f yb1 + assert. (u xb2 v yb2) -: xb2 f yb2 + assert. (u xb3 v yb3) -: xb3 f yb3 + assert. (u xb4 v yb4) -: xb4 f yb4 + assert. (u xb5 v yb5) -: xb5 f yb5 + assert. (u xb6 v yb6) -: xb6 f yb6 + assert. (u xb7 v yb7) -: xb7 f yb7 + 1 +) + +testbsv=: 2 : 0 NB. boolean scalar vector + : + assert. (u 0 v zb ) -: 0 u@:v zb + assert. (u 0 v yb ) -: 0 u@:v yb + assert. (u 0 v yb1 ) -: 0 u@:v yb1 + assert. (u 0 v yb2 ) -: 0 u@:v yb2 + assert. (u 0 v yb3 ) -: 0 u@:v yb3 + assert. (u 0 v yb4 ) -: 0 u@:v yb4 + assert. (u 0 v yb5 ) -: 0 u@:v yb5 + assert. (u 0 v yb6 ) -: 0 u@:v yb6 + assert. (u 0 v yb7 ) -: 0 u@:v yb7 + assert. (u 1 v 0$yb) -: 1 u@:v 0$yb + assert. (u 1 v yb ) -: 1 u@:v yb + assert. (u 1 v yb1 ) -: 1 u@:v yb1 + assert. (u 1 v yb2 ) -: 1 u@:v yb2 + assert. (u 1 v yb3 ) -: 1 u@:v yb3 + assert. (u 1 v yb4 ) -: 1 u@:v yb4 + assert. (u 1 v yb5 ) -: 1 u@:v yb5 + assert. (u 1 v yb6 ) -: 1 u@:v yb6 + assert. (u 1 v yb7 ) -: 1 u@:v yb7 + f=: u ftab v + assert. (u 0 v zb ) -: 0 f zb + assert. (u 0 v yb ) -: 0 f yb + assert. (u 0 v yb1 ) -: 0 f yb1 + assert. (u 0 v yb2 ) -: 0 f yb2 + assert. (u 0 v yb3 ) -: 0 f yb3 + assert. (u 0 v yb4 ) -: 0 f yb4 + assert. (u 0 v yb5 ) -: 0 f yb5 + assert. (u 0 v yb6 ) -: 0 f yb6 + assert. (u 0 v yb7 ) -: 0 f yb7 + assert. (u 1 v zb ) -: 1 f zb + assert. (u 1 v yb ) -: 1 f yb + assert. (u 1 v yb1 ) -: 1 f yb1 + assert. (u 1 v yb2 ) -: 1 f yb2 + assert. (u 1 v yb3 ) -: 1 f yb3 + assert. (u 1 v yb4 ) -: 1 f yb4 + assert. (u 1 v yb5 ) -: 1 f yb5 + assert. (u 1 v yb6 ) -: 1 f yb6 + assert. (u 1 v yb7 ) -: 1 f yb7 + 1 +) + +testbvs=: 2 : 0 NB. boolean vector scalar + : + assert. (u zb v 0) -: zb u@:v 0 + assert. (u xb v 0) -: xb u@:v 0 + assert. (u xb1 v 0) -: xb1 u@:v 0 + assert. (u xb2 v 0) -: xb2 u@:v 0 + assert. (u xb3 v 0) -: xb3 u@:v 0 + assert. (u xb4 v 0) -: xb4 u@:v 0 + assert. (u xb5 v 0) -: xb5 u@:v 0 + assert. (u xb6 v 0) -: xb6 u@:v 0 + assert. (u xb7 v 0) -: xb7 u@:v 0 + assert. (u xb v 1) -: xb u@:v 1 + assert. (u xb1 v 1) -: xb1 u@:v 1 + assert. (u xb2 v 1) -: xb2 u@:v 1 + assert. (u xb3 v 1) -: xb3 u@:v 1 + assert. (u xb4 v 1) -: xb4 u@:v 1 + assert. (u xb5 v 1) -: xb5 u@:v 1 + assert. (u xb6 v 1) -: xb6 u@:v 1 + assert. (u xb7 v 1) -: xb7 u@:v 1 + f=: u ftab v + assert. (u zb v 0) -: zb f 0 + assert. (u xb1 v 0) -: xb1 f 0 + assert. (u xb2 v 0) -: xb2 f 0 + assert. (u xb3 v 0) -: xb3 f 0 + assert. (u xb4 v 0) -: xb4 f 0 + assert. (u xb5 v 0) -: xb5 f 0 + assert. (u xb6 v 0) -: xb6 f 0 + assert. (u xb7 v 0) -: xb7 f 0 + assert. (u xb v 1) -: xb f 1 + assert. (u xb1 v 1) -: xb1 f 1 + assert. (u xb2 v 1) -: xb2 f 1 + assert. (u xb3 v 1) -: xb3 f 1 + assert. (u xb4 v 1) -: xb4 f 1 + assert. (u xb5 v 1) -: xb5 f 1 + assert. (u xb6 v 1) -: xb6 f 1 + assert. (u xb7 v 1) -: xb7 f 1 + 1 +) + +NB. test that special code is invoked by looking at space used + +testsp=: 2 : 0 + if. 'I.'-: 5!:5 <'u' do. 1 return. end. + expression=: 4#,:'sp ''x u@:v y'' [ x=. ,~x [ y=. ,~y' + assert. 1=#~. ".expression [ x=. xb [ y=. yb + assert. 1=#~. ".expression [ x=. xb [ y=. yi + assert. 1=#~. ".expression [ x=. xb [ y=. yd + assert. 1=#~. ".expression [ x=. xi [ y=. yb + assert. 1=#~. ".expression [ x=. xi [ y=. yi + assert. 1=#~. ".expression [ x=. xi [ y=. yd + assert. 1=#~. ".expression [ x=. xd [ y=. yb + assert. 1=#~. ".expression [ x=. xd [ y=. yi + assert. 1=#~. ".expression [ x=. xd [ y=. yd + assert. 1=#~. ".expression [ x=. xs [ y=. ys + f=: u ftab v + expression=: 4#,:'sp ''x f y'' [ x=. ,~x [ y=. ,~y' + assert. 1=#~. ".expression [ x=. xb [ y=. yb + assert. 1=#~. ".expression [ x=. xb [ y=. yi + assert. 1=#~. ".expression [ x=. xb [ y=. yd + assert. 1=#~. ".expression [ x=. xi [ y=. yb + assert. 1=#~. ".expression [ x=. xi [ y=. yi + assert. 1=#~. ".expression [ x=. xi [ y=. yd + assert. 1=#~. ".expression [ x=. xd [ y=. yb + assert. 1=#~. ".expression [ x=. xd [ y=. yi + assert. 1=#~. ".expression [ x=. xd [ y=. yd + assert. 1=#~. ".expression [ x=. xs [ y=. ys + 1 +) + +test=: 2 : 0 + u testvv v + u testsv v + u testvs v + u testss v + u testbvv v + u testbsv v + u testbvs v + u testsp v + 1 +) + +data '' + +i.&0 test < +i.&0 test <: +i.&0 test = +i.&0 test ~: +i.&0 test >: +i.&0 test > + +i.&1 test < +i.&1 test <: +i.&1 test = +i.&1 test ~: +i.&1 test >: +i.&1 test > + +i:&0 test < +i:&0 test <: +i:&0 test = +i:&0 test ~: +i:&0 test >: +i:&0 test > + +i:&1 test < +i:&1 test <: +i:&1 test = +i:&1 test ~: +i:&1 test >: +i:&1 test > + ++ / test < ++ / test <: ++ / test = ++ / test ~: ++ / test >: ++ / test > + ++./ test < ++./ test <: ++./ test = ++./ test ~: ++./ test >: ++./ test > + +*./ test < +*./ test <: +*./ test = +*./ test ~: +*./ test >: +*./ test > + +I. test < +I. test <: +I. test = +I. test ~: +I. test >: +I. test > + + +testc=: 2 : 0 NB. character + xx=: a.{~ ?400$#a. + yy=: a.{~ ?400$#a. + xa=: a.{~ ? #a. + ya=: a.{~ ? #a. + assert. (u xx v yy) -: xx u@:v yy + assert. (u xx v ya) -: xx u@:v ya + assert. (u xa v yy) -: xa u@:v yy + assert. (u xa v ya) -: xa u@:v ya + f=: u ftab v + assert. (u xx v yy) -: xx f yy + assert. (u xx v ya) -: xx f ya + assert. (u xa v yy) -: xa f yy + assert. (u xa v ya) -: xa f ya + if. -.'I.'-: 5!:5 <'u' do. + assert. 1=#~. t=: ".4#,:'sp ''xx u@:v yy'' [ xx=: ,~xx [ yy=: ,~yy' + assert. 1=#~. t=: ".4#,:'sp ''xx f yy'' [ xx=: ,~xx [ yy=: ,~yy' + end. + 1 +) + +i.&0 testc = +i.&0 testc ~: +i.&1 testc = +i.&1 testc ~: +i:&0 testc = +i:&0 testc ~: +i:&1 testc = +i:&1 testc ~: ++ / testc = ++ / testc ~: ++./ testc = ++./ testc ~: +*./ testc = +*./ testc ~: +I. testc = +I. testc ~: + +testE=: 2 : 0 + xb=: 7 ?@$2 + yb=: 1e5?@$2 + xi=: 4 ?@$5 + yi=: 1e5?@$5 + xj=: 4 ?@$1e6 + yj=: xj ((?3$9e4)+/i.#xj)}1e5?@$1e6 + xc=: 'abcd'{~ 4 ?@$4 + yc=: 'abcd'{~ 1e5?@$4 + assert. (u xb v yb) -: xb u@:v yb + assert. (u xc v yc) -: xc u@:v yc + assert. (u xi v yi) -: xi u@:v yi + assert. (u xj v yj) -: xj u@:v yj + f=: u ftab v + assert. (u xb v yb) -: xb f yb + assert. (u xc v yc) -: xc f yc + assert. (u xi v yi) -: xi f yi + assert. (u xj v yj) -: xj f yj + if. -.'I.'-: 5!:5 <'u' do. + expression=: 4#,:'sp ''xx u@:v yy'' [ xx=: ,~xx [ yy=: ,~yy' + assert. 1=#~. ". expression [ xx=: xb [ yy=: yb + assert. 1=#~. ". expression [ xx=: xc [ yy=: yc + assert. 1=#~. ". expression [ xx=: xi [ yy=: yi + expression=: 4#,:'sp ''xx f yy'' [ xx=: ,~xx [ yy=: ,~yy' + assert. 1=#~. ". expression [ xx=: xb [ yy=: yb + assert. 1=#~. ". expression [ xx=: xc [ yy=: yc + assert. 1=#~. ". expression [ xx=: xi [ yy=: yi + end. + 1 +) + ++ / testE E. ++./ testE E. +i.&1 testE E. +I. testE E. + + +4!:55 ;:'ad ai as data expression f ftab sp' +4!:55 ;:'t test testbsv testbvs testbvv testc testE testsp' +4!:55 ;:'testss testsv testvs testvv' +4!:55 ;:'xa xb xb1 xb2 xb3 xb4 xb5 xb6 xb7 xc xd xi xj xs xx' +4!:55 ;:'ya yb yb1 yb2 yb3 yb4 yb5 yb6 yb7 yc yd yi yj ys yy' +4!:55 ;:'zb zd zi zs' + +
new file mode 100644 --- /dev/null +++ b/test/gct.ijs @@ -0,0 +1,35 @@ +NB. comparison tolerance ------------------------------------------------ + +e=: 0, 2 ^ - 42 43 45 46 52 53 + +f=: 3 : 0 + xx=: y + yy=: y*1-e + assert. 1 0 0 1 1 1 1 -: xx = yy + assert. 0 1 1 0 0 0 0 -: xx ~: yy + assert. 0 0 0 0 0 0 0 -: xx < yy + assert. 1 0 0 1 1 1 1 -: xx <: yy + assert. 0 1 1 0 0 0 0 -: xx > yy + assert. 1 1 1 1 1 1 1 -: xx >: yy + assert. 0 1 2 0 0 0 0 -: i.~ yy + assert. 0 1 2 0 0 0 0 -: yy i. 0+yy + assert. 6 1 2 6 6 6 6 -: i:~ yy + assert. 6 1 2 6 6 6 6 -: yy i: 0+yy + assert. 1 1 1 0 0 0 0 -: ~: yy + assert. 0 1 2 -: I.@~: yy + assert. (3{.yy) -: ~. yy + assert. (1 2{yy) -: yy -. xx + assert. (1 2{yy) -: yy -. 13$xx + assert. (i < /.i.#e) -: yy < /.i.#e [ i=: i.~yy + assert. (i +//.i.#e) -: yy +//.i.#e [ i=: i.~yy + assert. (i # /.i.#e) -: yy # /.i.#e [ i=: i.~yy + 1 +) + +f"0 ]1 +f"0 ]0.001 * 5 10 ?@$ 2e9 + + +4!:55 ;:'e f i xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gctrl.ijs @@ -0,0 +1,69 @@ +NB. control word parsing ------------------------------------------------ + +f0 =. 3 : 'if. if. 1 do. 2 end. do. 3 else. 4 end.' +f1 =. 3 : 'if. while. 1 do. 2 end. do. 3 end.' +f2 =. 3 : 'if. try. 1 catch. 2 end. do. 3 else. 4 end.' +f3 =. 3 : 'if. 1 do. while. 2 do. 3 end. end.' + +g0 =. 3 : 'while. try. 1 catch. 2 end. do. 3 end.' +g1 =. 3 : 'while. 0 try. 1 catch. 2 end. do. 3 end.' +g2 =. 3 : 'while. if. 1 do. 2 else. 3 end. do. 4 end.' +g3 =. 3 : 'while. 1 do. if. 2 do. 3 else. 4 end. end.' +g4 =. 3 : 'while. 0 if. 1 do. break. end. 2 do. 3 end.' +g5 =. 3 : 'while. 0 if. 1 do. continue. end. 2 do. 3 end.' + + +NB. control words ------------------------------------------------------- + +test =. 3 : '''control error'' -: ". etx ''3 : y''' + +test 'if.' +test 'else.' +test 'elseif.' +test 'end.' +test 'do.' +test 'try.' +test 'catch.' +test 'while.' +test 'whilst.' +test 'continue.' +test 'break.' +test 'goto_.' +test 'goto_nonexist.' + +test 'do. 1 2 3 end.' +test 'else. 1 2 3 end.' +test 'elseif. 1 do. 2 end.' +test 'end. 1' +test '1 end.' +test '1 end. 2' +test 'if. 1 end.' +test 'if. 1 do.' +test 'if. 1 do. 2 elseif. 3 end.' +test 'if. 1 do. 2 do. 3 end.' +test 'while. 1 do.' +test 'while. 1 end.' +test 'whilst. 1 do.' +test 'whilst. 1 end.' +test 'try. ''without catch.''' +test 'try. 1 catch.' +test 'try. 1 end.' + +test 'if. y do. continue. end.' +test 'if. y do. break. end.' +test 'if. y do. return.' + +test 'if. 1 do. 2 elseif. 3 do. 4 else. 5 end.' +test 'if. 1 do. 2 else. if. 3 do. 4 else. 5 end.' +test 'while. 1 do. 2 else. 3 end.' +test 'whilst. 1 do. 2 else. 3 end.' + +'spelling error' -: ex '3 : ''goto.''' +'spelling error' -: ex '3 : ''label.''' +'spelling error' -: ex '3 : ''repeat.''' +'spelling error' -: ex '3 : ''until.''' +'spelling error' -: ex '3 : ''begin.''' + +4!:55 ;:'f0 f1 f2 f3 g0 g1 g2 g3 g4 g5 test ' + +
new file mode 100644 --- /dev/null +++ b/test/gd.ijs @@ -0,0 +1,97 @@ +NB. D. scalar functions ------------------------------------------------- + +D =: D. 1 +E =: 1 : '3 : (x,'' y'') D' + +test =. 2 : 0 + f=: x D + g=: y E + h=: $@f -: $@g + b=.$0 + b=.b,1e_4>|(f-g)2+0.01*?50 + b=.b,h t=: 0.0001*2+? 4$50000 + b=.b,h t=: 0.0001*2+? 3 2$50000 + b=.b,h t=: 0.0001*2+?2 3 1$50000 +) + +<: test '<:' +>: test '>:' ++: test '+:' +*: test '*:' +- test '- ' +-. test '-.' +% test '% ' +%: test '%:' +^ test '^ ' +^. test '^.' +[ test '[' +] test ']' +j. test 'j.' +o. test 'o.' +r. test 'r.' + +3&+ test '3&+' ++&3 test '+&3' +3&* test '3&*' +*&3 test '*&3' +3&- test '3&-' +-&3 test '-&3' +3&% test '3&%' +%&3 test '%&3' +1.2&^ test '1.2&^' +^&3 test '^&3' +3&^. test '3&^.' +^.&3 test '^.&3' +1&o. test '1&o.' +2&o. test '2&o.' +3&o. test '3&o.' +5&o. test '5&o.' +6&o. test '6&o.' +7&o. test '7&o.' + +12"_ test '12"_' +_17"_ test '_17"_' +*:"1 test '*:"1' +4&%"1 test '4&%"1' +^&1.7"2 test '^&1.7"2' + +*:@>: test '*:@>:' +<:@+: test '<:@+:' +^.@+: test '^.@+: ' +*:@(1&o.) test '*:@(1&o.)' + +(*: + ] ) test '(*: + ] )' +([ * ^ ) test '([ * ^ )' +(2&o. - %:) test '(2&o. - %:)' +(-: % ^.) test '(-: % ^.)' +(*: + +: + 1"0) test '(*: + +: + 1"0)' +(*: % +: + 1"0) test '(*: % +: + 1"0)' +(*:@>: * 2&*) test '(*:@>: * 2&*)' + +'length error' -: 1 2 3&* D etx i.7 +'length error' -: 1 2 3&* D etx i.7 3 + + +NB. D. non-scalar functions --------------------------------------------- + +eq =: 2 : '''x'' -:&(5!:1)&< ''y''' +dc =: }.@(* i.@#) + +x=.(>:?10),~_5+?5$20 +(x&p. d. 1) eq ((dc x)&p.) +(x&p. d. 2) eq ((dc^:2 x)&p.) +(x&p. d. 3) eq ((dc^:3 x)&p.) +(x&p. d. 4) eq ((dc^:4 x)&p.) +(x&p. d. 0) eq ((dc^:0 x)&p."0) +(x&p. d. 0) eq (x&p."0) +x=.j./_5+?2 5$20 +((<x)&p. d. 1) eq ((dc p.<x)&p.) + +_0.5 1&p. eq (2&! d. 1) + +((10"_ * %:) D. 1) eq ((10 * %:) D. 1) + + +4!:55 ;:'D E b dc eq f g h test x ' + +
new file mode 100644 --- /dev/null +++ b/test/gddot.ijs @@ -0,0 +1,106 @@ +NB. d. scalar functions ------------------------------------------------- + +equ=: 2 : '''x'' -:&(5!:5)&< ''y''' +eqt=: 2 : '(x t. i.20) -: (y t. i.20)' +eqv=: 2 : '(x v) -: y v=. 0.01*_500+?2 3$1000' + +1: d. 1 eqt 0: +2.5"0 d. 1 eqt 0: +_14"0 d. 1 eqt 0: +-~ d. 1 eqt 0: +%~ d. 1 eqt 0: +6&p. d. 1 eqt 0: +_6&p. d. 1 eqt 0: +''&p. d. 1 eqt 0: + +>: d. 1 eqt 1: +<: d. 1 eqt 1: +] d. 1 eqt 1: +[ d. 1 eqt 1: +3&+ d. 1 eqt 1: ++&3 d. 1 eqt 1: +-&3 d. 1 eqt 1: +2.5&+ d. 1 eqt 1: ++&2.5 d. 1 eqt 1: + +- d. 1 eqt _1: +-. d. 1 eqt _1: +2.5&- d. 1 eqt _1: +_1&* d. 1 eqt _1: +*&_1 d. 1 eqt _1: + ++: d. 1 eqt 2: ++~ d. 1 eqt 2: +-: d. 1 eqt (0.5"0) +o. d. 1 eqt (1p1"0) + +*: d. 1 equ +: +^. d. 1 equ % +^ d. 1 equ ^ +%: d. 1 equ (-:@%@%:) +0&o. d. 1 equ (- % 0&o.) +1&o. d. 1 equ (2&o.) +2&o. d. 1 equ (-@(1&o.)) +2&! d. 1 eqt (_0.5 1&p.) +2&! d. 1 eqt (-:@(] * <:) d. 1) + +(+: + *: ) d. 1 eqt (2: + +: ) +(+: + 1: ) d. 1 eqt 2: +(^. + 1&o.) d. 1 equ (% + 2&o.) + +(+: - *: ) d. 1 eqt (2: - +: ) +(+: - 1: ) d. 1 eqt 2: +(1: - +: ) d. 1 eqt _2: +(17"0 - +: ) d. 1 eqt _2: +(^. - 1&o.) d. 1 equ (% - 2&o.) + +(] * <: ) d. 1 eqt (+:@(2&!) d. 1) +(] * >: ) d. 1 eqt (+:@(2&!)@>: d. 1) +(1&o. * ^ ) d. 1 eqv ((2&o.*^) + (1&o.*^)) +(1&o. * ] ) d. 1 eqv ((2&o.*]) + 1&o.) + +(1&o. % ] ) d. 1 eqv (((2&o.*]) - 1&o.) % *:) + +(] ^ 0: ) d. 1 eqt 0: +(] ^ 1: ) d. 1 eqt 1: +(] ^ 2: ) d. 1 eqt +: +(] ^ 3: ) d. 1 eqt (0 0 3&p.) +(] ^ 4: ) d. 1 eqt (0 0 0 4&p.) +(] ^ 5: ) d. 1 eqt (0 0 0 0 5&p.) +(] ^ 2j5"0)d. 1 eqv (2j5&* @ (^&1j5)) +(] ^ _1: ) d. 1 eqv (% d. 1) + +^@(]^2:) d. 1 eqv (^@*: d. 1) +*:@^ d. 1 eqt (+:@^ * ^) +2&!@*: d. 1 eqt ((2&! d. 1)@*: * +:) +(1&o.@+:) d. 1 eqt (+:@(2&o.)@+:) +(+:@(1&o.)) d. 1 eqt (+:@(2&o.)) +(*:@>:) d. 1 eqt (2 2&p.) +(>:@*:) d. 1 eqt (0 2&p.) + +0&o. d. 1 equ (- % 0&o.) +0&o. d. 1 eqv (%:@-.@*: d. 1) + +*:^:3 d. 1 eqt (8: * ^&7 ) +*:^:2 d. 1 eqt (*:@*: d. 1) +*:^:1 d. 1 eqt (*: d. 1) +*:@>:^:3 d. 1 eqt ((p.. *:@>:@*:@>:@*:@>: t. i.12)&p.) +>:@*:^:3 d. 1 eqt (>:@*:@>:@*:@>:@*: d. 1) ++:^:_1 d. 1 eqt (0.5"_ ) ++:^:_2 d. 1 eqt (0.25"_ ) + +^&3 d. _1 eqt ((^&2 * ]) d. _1) +^&3 d. _1 eqt ((*: * ]) d. _1) + +1 2 3&p. d. _1 eqt ((1: + +: + 3&*@*:) d. _1) +(1 2 3&p. + 4 5&p.) d. _1 eqt (5 7 3&p. d. _1) +(1 2 3&p. - 4 5&p.) d. _1 eqt (_3 _3 3&p. d. _1) +(1 2 3&p. * 4 5&p.) d. _1 eqt ((+//.1 2 3*/4 5)&p. d. _1) + +((1 % *:) d. 1) equ ((1: % *:) d. 1) +((1 + *:) d. _1) equ ((1: + *:) d. _1) + + +4!:55 ;:'eqt equ eqv' + +
new file mode 100644 --- /dev/null +++ b/test/gdll.ijs @@ -0,0 +1,296 @@ +NB. DLL call ------------------------------------------------------------ + +load'dll' + +3 : 0 '' +if. 0=4!:0<'libtsdll' do. 1[lib=: libtsdll return. end. +t=. >IF64{'32';'64' +s=. >(UNAME-:'Darwin'){'.so';'.dylib' +if. IFUNIX do. + lib=: jpath '~home/dev/j/tsdll/libtsdll',t,s +else. + if. IF64 do. + lib=: '\dev\j\p_tsdll\release64\tsdll.dll' + else. + lib=: '\dev\j\p_tsdll\release\tsdll.dll' + end. +end. +lib=: lib,' ' +1 +) + +dcd=: 4 : '(lib,x) cd y' + +NB. test integer types +a=: 4 u: +/401 402 403 +b=: 4 u: 402 403 +('&';(,'&');'a';'bc')= 'cbasic c *c c *c' dcd (,'a');'a';'bc' +(a;(,a);(4 u: 401);b)= 'wbasic w *w w *w' dcd (,4 u: 400);(4 u: 401);4 u: 402 403 +(9;(,9);2;3 4)= 'sbasic s *s s *s' dcd (,2);2;3 4 +(9;(,9);2;1 ic 3 4)= 'sbasic s *s s *s' dcd (,2);2;1 ic 3 4 NB. shorts in chars +(9;(,9);2;3 4)= 'ibasic i *i i *i' dcd (,2);2;3 4 +(9;(,.9);2;,.3 4)= 'ibasic i *i i *i' dcd (,.2);2;,.3 4 NB. allow rank>1 +(9;(,9);2;3 4)= 'xbasic x *x x *x' dcd (,2);2;3 4 +(2;(,2);1;0 1)= 'ibasic i *i i *i' dcd (,1);1;0 1 NB. boolean promotion to int + +NB. declaration (left argument) and parameter (right argument) checking +(0 0 -: cder '') *. (9;(,9);2;3 4) -: 'ibasic i *i i *i' dcd (,2);2;3 4 NB. base working example + +'limit error' -: (lib,'ibasic i *i i *i',2300$' ' ) cd etx (,2);2;3 4 +'limit error' -: ((2300$' '),lib,'ibasic i *i i *i') cd etx (,2);2;3 4 + +(1 0 -: cder '') *. 'domain error' -: ((1200$'x'),' proc i i i') cd etx 2;3 +(1 0 -: cder '') *. 'domain error' -: ('xxxx proc i i i' ) cd etx 2;3 +(1 0 -: cder '') *. 'domain error' -: ('xxxx proc i i i' ) cd etx 2;3 + +(2 0 -: cder '') *. 'domain error' -: (lib,(1200$'x'),' i i i' ) cd etx 2;3 +(2 0 -: cder '') *. 'domain error' -: (lib,'xxxx i i i' ) cd etx 2;3 +(2 0 -: cder '') *. 'domain error' -: (lib,'xxxx i i i' ) cd etx 2;3 + +(4 0 -: cder '') *. 'domain error' -: (lib,'ibasic ',400$'i ' ) cd etx 2;3 +(4 0 -: cder '') *. 'domain error' -: 'ibasic i *i i *i' dcd etx (,2);2;3 4;'abcd' +(4 0 -: cder '') *. 'domain error' -: 'ibasic i *i i *i' dcd etx (,2);2 + +(5 0 -: cder '') *. 'domain error' -: 'ibasic I *i i *i' dcd etx (,2);2;3 4 +(5 1 -: cder '') *. 'domain error' -: 'ibasic i *I i *i' dcd etx (,2);2;3 4 +(5 2 -: cder '') *. 'domain error' -: 'ibasic i *i I *i' dcd etx (,2);2;3 4 +(5 3 -: cder '') *. 'domain error' -: 'ibasic i *i i *I' dcd etx (,2);2;3 4 + +(6 0 -: cder '') *. 'domain error' -: 'ibasic i *i i *i' dcd etx ('abc');2 ;3 4 +(6 1 -: cder '') *. 'domain error' -: 'ibasic i *i i *i' dcd etx (,2) ;4.5;3 4 +(6 2 -: cder '') *. 'domain error' -: 'ibasic i *i i *i' dcd etx (,2) ;2 ;3j4 5 + +NB. 'rank error' -: 'ibasic i *i i *i' dcd etx ,:(,2);2;3 4 +NB. 'rank error' -: 'ibasic i *i i *i' dcd etx ,.(,2);2;3 4 + +NB. mema memory +add=: mema 2*IF64{4 8 +3 4 memw add,0,2,JINT +(9;(,9);2;<<add)= 'xbasic x *x x *x' dcd (,2);2;<<add +0=memf add + +NB. l type is same as x on J64 and and error on J32 +3 : 0'' +if. IF64 do. + assert. (9;(,9);2;3 4) = 'xbasic l *l l *l' dcd (,2);2;3 4 +else. + assert. 'domain error'-: 'xbasic l *l l *l' dcd etx (,2);2;3 4 + assert. 5 0 -: cder '' NB. error 5, result/arg declaration 0 +end. +) + +NB. pointer result +address=. 0{::'pc *c' dcd '' +'test'-:memr address,0,_1 +address=. 0{::'pc *' dcd '' +'test'-:memr address,0,_1 + +NB. d and *d results and *d arg +(6.6;3;1.1 2.2 3.3;,6.6)= 'dipdpd d i *d *d' dcd 3;1.1 2.2 3.3;,1.1 +(6.6;3;(,.1.1 2.2 3.3);,.6.6)= 'dipdpd d i *d *d' dcd 3;(,.1.1 2.2 3.3);,.1.1 + +NB. f and *f results and *f arg - convert in place +NB. 1.5 2.4 3.5 doubles convert exactly to floats +(7.5;3;1.5 2.5 3.5;,7.5)= 'fipfpf f i *f *f' dcd 3;1.5 2.5 3.5;,1.1 +(7.5;3;(,.1.5 2.5 3.5);,.7.5)= 'fipfpf f i *f *f' dcd 3;(,.1.5 2.5 3.5);,.1.1 +(7.5;3;(1 fc 1.5 2.5 3.5);,7.5)= 'fipfpf f i *f *f' dcd 3;(1 fc 1.5 2.5 3.5);,1.1 NB. shorts in chars +(7.5;3;(,.1 fc 1.5 2.5 3.5);,.7.5)= 'fipfpf f i *f *f' dcd 3;(,.(1 fc 1.5 2.5 3.5));,.1.1 NB. shorts in chars + +NB. verify that double to float loses bits +6.6~: 0{::'fipfpf f i *f *f' dcd 3;1.1 2.2 3.3;,1.1 + +NB. alternate (__cdecl) calling convention +(24;23) -: 'altinci + i i' dcd 23 + +NB. *j +(1.6;a)= 'complex d i *j' dcd a=.0;,1.6j2.7 +(2.7;a)= 'complex d i *j' dcd a=.1;,1.6j2.7 + +NB. test f and d results and scalars +(<1.5)= 'f f' dcd '' +(<1.5)= 'd d' dcd '' +(3.3;1.1;2.2 )= 'ddd d d d' dcd 1.1;2.2 +(6.6;1.1;2.2;3.3)= 'dddd d d d d' dcd 1.1;2.2;3.3 +(4;1.5;2.5)= 'fff f f f' dcd 1.5;2.5 +z=:'fd d f d f d *f *d' dcd 1.1;1.2;1.3;1.4;(6.6,6.6);7.7,7.7 +(1.1;1.2;1.3;1.4;1.2 1.4)= 1 2 3 4 6{z +0.00001>5.0 1.1 1.3-;0 5{z + +(+/>yy)=>{.'dx0 d x d' dcd yy=:12;12.5 +(+/>yy)=>{.'dx1 d d x' dcd yy=:12.5;12 +(+/>yy)=>{.'dx2 d x d x' dcd yy=:12;12.5;13 +(+/>yy)=>{.'dx3 d d x d' dcd yy=:12.5;12;13.6 +(+/>yy)=>{.'dx4 d x d x d' dcd yy=:12;12.5;13;15.4 +(+/>yy)=>{.'dx5 d d x d x' dcd yy=:12.5;12;13.6;7 +(+/>yy)=>{.'dx6 d x d x d x' dcd yy=:12;12.5;13;15.4;9 +(+/>yy)=>{.'dx7 d d x d x d' dcd yy=:12.5;12;13.6;7;23.7 + +td=: 16$'d ' +( +/>yy)=>{.z=:('d1 d ',td) dcd yy=:<"0 [ 1.3*?8#10 +(<.+/>yy)=>{.z=:('d2 x ',td) dcd yy=:<"0 [ 1.3*?8#10 + +td1a=: 18$'d ' + +3 : 0'' +try. + (+/>yy)=>{.z=:('d1a d ',td1a) dcd yy=:<"0 [ 1.3*?9#10 +catch. + *./IF64,IFUNIX,7 0-:cder'' +end. +) + +td3=: 32$'d x ' +(+/>yy)=>{.z=:('d3 d ',td3) dcd yy=:16$12.3;4 +td4=: 32$'d i ' +(+/>yy)=>{.z=:('d4 d ',td4) dcd yy=:16$12.3;4 + +xx=:'d5 d d i d i d i d *d *f *x *i' +(+/;yy)=>{.z=: xx dcd yy=:1.1;2;3.3;4;5.5;6;7.7;2.2 3.3;3.3 4.4;23 24;46 47 + +tf=: 16$'f ' +(<.+/>yy)=<.>{.z=:('f1 f ',tf ) dcd yy=:<"0 [ 1.375*?8#10 +(<.+/>yy)= >{.z=:('f2 x ',tf ) dcd yy=:<"0 [ 1.375*?8#10 +tf3=: 32$'f x ' +(<.+/>yy)=<.>{.z=:('f3 f ',tf3) dcd yy=:16$12.3;4 + +NB. test scalar boolean and integer promotion to double +(0;0;0)='ddd d d d' dcd 0;0 +(2;1;1)='ddd d d d' dcd 1;1 +(5;2;3)='ddd d d d' dcd 2;3 +8=3!:0 >'ddd d d d' dcd 2;3 + +NB. test scalar boolean and integer promotion to float (double then downconverted) +(0;0;0)='fff f f f' dcd 0;0 +(2;1;1)='fff f f f' dcd 1;1 +(5;2;3)='fff f f f' dcd 2;3 +8=3!:0 >'fff f f f' dcd 2;3 + +NB. test boolean and integer lists promoted to double +'v0 v1 v2 v3 v4 v5'=.(2.2-2.2)+i.6 NB. this works +'v0 v1 v2 v3 v4 v5'=.i.6 +(6;0;1;2;3;0 2 4;1 3 5)-:'fd d f d f d *f *d' dcd v0;v1;v2;v3;(3$v4);3$v5 + +NB. use of > parameter +24 -: 'altinci >+ i i' dcd 23 +(>:x) -: 'altinci >+ i i' dcd ,. x=: 17 ?@$ 1e6 +(>:x) -: 'altinci >+ i i' dcd ,. <"0 x + +(+/"1 x) -: 'ddd > d d d' dcd x=: 17 2 ?@$ 0 +(+/"1 x) -: 'ddd > d d d' dcd <"0 x +(+/"1 x) -: 'ddd > d d d' dcd x=: 17 2 ?@$ 2 +(+/"1 x) -: 'ddd > d d d' dcd <"0 x +(+/"1 x) -: 'ddd > d d d' dcd x=: 17 2 ?@$ 100 +(+/"1 x) -: 'ddd > d d d' dcd <"0 x +(+/"1 x) -: 'ddd > d d d' dcd x=: (-~0j5)+17 2 ?@$ 0 +(+/"1 x) -: 'ddd > d d d' dcd <"0 x + +(+/"1 x) -: 'fff > f f f' dcd x=: 1024 %~ 17 2 ?@$ 1e4 +(+/"1 x) -: 'fff > f f f' dcd x=: 17 2 ?@$ 2 +(+/"1 x) -: 'fff > f f f' dcd x=: 17 2 ?@$ 100 +(+/"1 x) -: 'fff > f f f' dcd x=: (-~0j5)+1024 %~ 17 2 ?@$ 1e4 + +(+/"1 x) -: 'dx0 > d x d' dcd x=: 7 2 ?@$ 9 0 +(+/"1 x) -: 'dx1 > d d x' dcd x=: 7 2 ?@$ 0 9 +(+/"1 x) -: 'dx2 > d x d x' dcd x=: 7 3 ?@$ 9 0 9 +(+/"1 x) -: 'dx3 > d d x d' dcd x=: 7 3 ?@$ 0 9 0 +(+/"1 x) -: 'dx4 > d x d x d' dcd x=: 7 4 ?@$ 9 0 9 0 +(+/"1 x) -: 'dx5 > d d x d x' dcd x=: 7 4 ?@$ 0 9 0 9 +(+/"1 x) -: 'dx6 > d x d x d x' dcd x=: 7 5 ?@$ 9 0 9 0 9 +(+/"1 x) -: 'dx7 > d d x d x d' dcd x=: 7 5 ?@$ 0 9 0 9 0 + + +td=: 16$'d ' +(+/"1 x) -: ('d1 >d ',td) dcd x=: 17 8?@$ 0 + +(6 0 -: cder '') *. 'domain error' -: 'ddd > d d d' dcd etx 'ab' + +NB. space usage + +s0=: 7!:0 '' +s1=: 7!:0 '' +yy=: <"0 ] 8 ?.@$ 0 +4!:55 ;:'yy' +xx=: lib,'f1 f ',16$'f ' +9 = # xx 15!:0 <"0 ]8 ?@$ 0 + +s0=: 7!:0 '' +9 = # xx 15!:0 <"0 ]8 ?@$ 0 +s1=: 7!:0 '' +s0 -: s1 + +s0=: 7!:0 '' +1 [ 100 (6!:2) 'xx 15!:0 <"0 ]8 ?@$ 0' +s1=: 7!:0 '' +s0 -: s1 + +s0=: 7!:0 '' +yy=: <"0 ] 8 ?.@$ 0 +1 [ 100 (6!:2) 'xx 15!:0 yy' +yy -: <"0 ] 8 ?.@$ 0 +4!:55 ;:'yy' +s1=: 7!:0 '' +s0 -: s1 + + +f=: 3 : 0 + if. (9!:12 '') e. 6 do. NB. do only under Windows + 'ole32.dll CoCreateGuid i *c' 15!:0 y + else. + 0;16$' ' + end. +) + +('';,16) = $&.> x=: f <16$' ' +('';,16) = $&.> x=: f ,<16$' ' + + +NB. 0 procaddress +xbasic_add=: ":>{.'xbasic_add x' dcd '' +(9;(,9);2;3 4) = ('0 ',xbasic_add,' x *x x *x') cd (,2);2;3 4 + +(2 0 -: cder '') *. 'domain error' -: '0 1e4 x x' cd etx (,2);2;3 4 +(2 0 -: cder '') *. 'domain error' -: '0 _1e4 x x' cd etx (,2);2;3 4 +(2 0 -: cder '') *. 'domain error' -: '0 abc x x' cd etx (,2);2;3 4 +(2 0 -: cder '') *. 'domain error' -: '0 34aa x x' cd etx (,2);2;3 4 + +(2 0 -: cder '') *. 'domain error' -: ('0 ',(>IF64{'2333444555';19$'93'),' x x') cd etx (,2);2;3 4 +(2 0 -: cder '') *. 'domain error' -: ('0 _',(>IF64{'2333444555';19$'93'),' x x') cd etx (,2);2;3 4 + +NB. 1 procindex - 0 is objxxx and 1 is objddd +obj_add=: <>{.'obj_add x' dcd '' +5 = >{.'objxxx x * x x' dcd obj_add;2;3 +5.75 = >{.'objddd d * d d' dcd obj_add;2.5;3.25 +5 = >{.'1 0 x * x x' cd obj_add;2;3 +5.75 = >{.'1 1 d * d d' cd obj_add;2.5;3.25 + +5 = >{.'1 0 x x x x' cd (>obj_add);2;3 +5 = >{.'1 0 x x x x' cd (>obj_add),2 3 +5 = >{.'1 0 x x x x' cd (>obj_add),2 3+-~0.5 + +5.75 = >{.'1 1 d x d d' cd (>obj_add);2.5;3.25 +5.75 = >{.'1 1 d x d d' cd (>obj_add),2.5 3.25 +55 = >{.'1 1 d x d d' cd (>obj_add),22 33 + +(2 0 -: cder '') *. 'domain error' -: '1 _10000 x * x x' cd etx obj_add;2;3 +(2 0 -: cder '') *. 'domain error' -: '1 1e2 x * x x' cd etx obj_add;2;3 +(2 0 -: cder '') *. 'domain error' -: '1 abc x * x x' cd etx obj_add;2;3 +(2 0 -: cder '') *. 'domain error' -: '1 34aa x * x x' cd etx obj_add;2;3 + +(2 0 -: cder '') *. 'domain error' -: ('1 ',(>IF64{'2333444555';19$'93'),' x * x x') cd etx obj_add;2;3 + +(5 1 -: cder '') *. 'domain error' -: '1 0 x *d x x' cd etx obj_add;2;3 +(5 1 -: cder '') *. 'domain error' -: '1 0 x *x x x' cd etx obj_add;2;3 +(5 1 -: cder '') *. 'domain error' -: '1 0 x d x x' cd etx obj_add;2;3 +(5 1 -: cder '') *. 'domain error' -: '1 0 x' cd etx obj_add;2;3 + +(6 0 -: cder '') *. 'domain error' -: '1 0 x x x x' cd etx obj_add ;2 ;3 +(6 0 -: cder '') *. 'domain error' -: '1 0 x * x x' cd etx (>obj_add);2 ;3 +(6 0 -: cder '') *. 'domain error' -: '1 0 x * x x' cd etx (>obj_add),2 3 +(6 1 -: cder '') *. 'domain error' -: '1 0 x * x x' cd etx obj_add ;'2';3 +(6 2 -: cder '') *. 'domain error' -: '1 0 x * x x' cd etx obj_add ;2 ;'3' + + +4!:55 ;:'a add address b dcd f lib obj_add pc s0 s1 td td1a td3 td4 tf tf3' +4!:55 ;:'v0 v1 v2 v3 v4 v5 x xbasic_add xx yy z' + +
new file mode 100644 --- /dev/null +++ b/test/ge.ijs @@ -0,0 +1,93 @@ +NB. e.y ----------------------------------------------------------------- + +y =. 'abc';'dc';'a' +(e.y) -: 1 1 1 0 1 1,0 0 1 1 1 0,:1 0 0 0 0 1 + +x =. 1 0 0 1 0 1 (<;.1) 3#"1,.'abcdca' +(e.x) -: e.y + +(e.'') -: i.0 0 + +'domain error' -: e. etx 1 2;'abc' +'domain error' -: e. etx 1 2;<<'abc' +'domain error' -: e. etx 'ab';<<'a' + + +NB. x e.y --------------------------------------------------------------- + +1 0 0 -: 'foo' e.'f' +0 0 0 -: 'foo' e.'x' +0 0 0 -: 'foo' e.4 +1 0 0 -: 1 0 0 e.1 +1 0 0 -: 2 1 4 e.2 +1 0 0 -: (o.3 1 2)e.o.3 + +0 0 -: (i.2 3) e. 4 3$'a' +0 0 0 -: (i.3 2 4) e. 1 2 4$<'a' +(3 2$0) -: (3 2 4$'a') e. i.2 4 + +nan=: e.!.0&_. + +0 0 0 0 -: nan 0 1 2 3 +0 0 0 0 -: nan 0 1 2 3 +0 0 1 0 -: nan 0 1 _. 3 +0 0 1 0 -: nan 0 1 _. 3 + +test=: 3 : 0 + yy=: y + i=: ?101$#yy + b=: yy e. i{yy + assert. 1=type b + assert. 1=#$b + assert. b -:&# yy + assert. b >: 1 i}(#yy)$0 + 1 +) + +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 0 1 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 'abcde' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$2e9 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: o.?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: j./?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: ;:' miasma chthonic chronic kakistocracy dado' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: x: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: %/0 1+x:?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: u: ?5$65536 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: s:' miasma chthonic chronic kakistocracy dado' + +0 0 -: (i.2 3) e. i.2 4 +0 0 -: (i.2 3) e. 4 5$'a' + +0 -: 3 e. i.4 3 + + +NB. x e."r y ------------------------------------------------------------ + +g=: 4 : 'x e. y' + +x=.?2 3 4 5$5 +x (g"0 0 -: e."0 0) y=.?2 3 4 5$5 +x (g"1 0 -: e."1 0) y=.?2 3 4 $5 +x (g"2 0 -: e."2 0) y=.?2 3 $5 +x (g"3 0 -: e."3 0) y=.?2 $5 +x (g"4 0 -: e."4 0) y=.? 5 +x (g"0 1 -: e."0 1) y=.?13 $5 +x (g"1 1 -: e."1 1) y=.?2 3 4 7$5 +x (g"2 1 -: e."2 1) y=.?2 3 2$5 +x (g"3 1 -: e."3 1) y=.?2 7$5 +x (g"4 1 -: e."4 1) y=.? 9$5 +x (g"1 2 -: e."1 2) y=.?2 3 4 2 5$5 +x (g"2 2 -: e."2 2) y=.?2 3 1 5$5 +x (g"3 2 -: e."3 2) y=.?2 4 5$5 +x (g"4 2 -: e."4 2) y=.?3 17 5$5 +x (g"2 3 -: e."2 3) y=.?2 3 7 4 5$5 +x (g"3 3 -: e."3 3) y=.?2 7 4 5$5 +x (g"4 3 -: e."4 3) y=.?11 7 4 5$5 + +(i.0 3 4) (g"1 -: e."1) i.0 3 7 + + +4!:55 ;:'b g i nan t test x y yy' + +
new file mode 100644 --- /dev/null +++ b/test/gebar.ijs @@ -0,0 +1,78 @@ +NB. x E.y --------------------------------------------------------------- + +1 0 1 0 0 -: 'co' E. 'cocoa' +1 1 1 1 0 -: 'aa' E. 5$'a' +1 0 0 0 0 -: E.~ 'abcde' +0 0 0 0 0 -: 'xy' E. 'asfdd' + +(($j)$0) -: (a.{~j,j) E. a.{~j=.?(?100)$256 +(($j)$0) -: (a.{~j,j) E. a.{~j=.?(?100)$256 +(($j)$0) -: (a.{~j,j) E. a.{~j=.?(?100)$256 +(($j)$0) -: (a.{~j,j) E. a.{~j=.?(?100)$256 +(($j)$0) -: (a.{~j,j) E. a.{~j=.?(?100)$256 + +((m*n)$n{.1) *./ . <: s E. (m*n)$s=.a.{~?n$256 [ m=.?20 [ n=.?20 +((m*n)$n{.1) *./ . <: s E. (m*n)$s=.a.{~?n$256 [ m=.?20 [ n=.?20 +((m*n)$n{.1) *./ . <: s E. (m*n)$s=.a.{~?n$256 [ m=.?20 [ n=.?20 +((m*n)$n{.1) *./ . <: s E. (m*n)$s=.a.{~?n$256 [ m=.?20 [ n=.?20 +((m*n)$n{.1) *./ . <: s E. (m*n)$s=.a.{~?n$256 [ m=.?20 [ n=.?20 + +ebar =: 4 : 0 + assert. (0 e.$x) +. 2=type x + assert. (0 e.$y) +. 2=type y + assert. (1>:#$x)*.1>:#$y + m=.#x + n=.#y + p=.(*m)+n-m + v=.(a.i.y),99 + td1=.(m-i.m) (a.i.,x)}(#a.)$1+m + z=.($y)$k=.0 + while. k<p do. + i=.0 + while. i<m do. + if. (i{x)=(k+i){y do. i=.>:i else. break. end. + end. + z=.(i=m) k}z + k=.k+((k+m){v){td1 + end. + z +) + +a. (ebar -: E.) a. +a. (ebar -: E.) 'abc' +'abc' (ebar -: E.) a. +'ABC' (ebar -: E.) a. +'' (ebar -: E.) a. +a. (ebar -: E.) '' +'' (ebar -: E.) '' +'a' (ebar -: E.) a. +NB. a. (ebar -: E.) 'a' +'a' (ebar -: E.) 'a' +'a' (ebar -: E.) 'b' +'aaa' (ebar -: E.) 50$'aaa' + +x=: a.{~ ?31$#a. +y=: x ((?40$y-&#x)+/i.#x)}y=: a.{~ ?9111$#a. +(x E. y) -: x E.&(a.&i.) y + +x=: ?31$1000 +i=: ?40$y-&#x +y=: x (i+/i.#x)}y=: ?9111$1000 +((# i.@#)x E. y) e. i + +(30$0) -: (<"0 ?35$10) E. <"0 ?30$10 + +1 1 1 -: 2.3 E. 2.3 2.3 2.3 +1 1 1 -: 2j3 E. 2j3 2j3 2j3 +1 1 0 -: 1 1 E. 1 1 1 + 1e_15 +0 0 0 -: 1 1 E.!.0 ] 1 1 1 + 1e_15 + +(5$1) -: (i.0) E. i.5 +(5$1) -: (i.0) E. 'abcde' +(5$1) -: '' E. i.5 +(5$1) -: '' E. 'abcde' + + +4!:55 ;:'g ebar i j m n s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gesc.ijs @@ -0,0 +1,115 @@ +NB. e. special code ----------------------------------------------------- + +E=: 1 : 0 +: + xx=: x {~ 500 ?@$ #x + yy=: y {~1000 ?@$ #y + '`f g h'=: >1{>5!:1 <'u' + if. '[:' -: 5!:5 <'f' do. + assert. (xx u yy ) -: g xx h yy + assert. (u f.&yy xx) -: g xx h yy + else. + assert. (xx u yy ) -: (xx f yy) g (xx h yy) + assert. (u f.&yy xx) -: (xx f yy) g (xx h yy) + end. + 1 +) + +A0=: 1 : 0 + x E ~ a=. 0 1 + x E ~ a=. #:i.2^1 + x E ~ a=. #:i.2^2 + x E ~ a=. #:i.2^3 + x E ~ a=. #:i.2^4 + x E ~ a=. #:i.2^5 + x E ~ a=. #:i.2^6 + x E ~ a=. #:i.2^7 + x E ~ a=. #:i.2^8 + x E ~ a=. #:i.2^9 + x E ~ a=. a. + x E ~ a=. a.{~ 600 1 ?@$ 256 + x E ~ a=. a.{~ 600 2 ?@$ 256 + x E ~ a=. a.{~ 600 3 ?@$ 256 + x E ~ a=. a.{~ 600 4 ?@$ 256 + x E ~ a=. a.{~ 600 5 ?@$ 256 + x E ~ a=. a.{~ 600 6 ?@$ 256 + x E ~ a=. a.{~ 600 7 ?@$ 256 + x E ~ a=. a.{~ 600 8 ?@$ 256 + x E ~ a=. a.{~ 600 9 ?@$ 256 + x E ~ a=. 600 ?@$ 2e9 + x E ~ a=. 600 2 ?@$ 2e9 + x E ~ a=. 600 ?@$ 600 + x E ~ a=. 600 2 ?@$ 600 + x E ~ a=. _300+600 ?@$ 600 + x E ~ a=. _5e7+600 ?@$ 1e8 + x E ~ a=. 600 ?@$ 0 + x E ~ a=. 600 2 ?@$ 0 + x E ~ a=. j./ 2 600 ?@$ 0 + x E ~ a=. j./ 2 600 2 ?@$ 0 + x E ~ a=. u: 600 ?@$ 65536 + x E ~ a=. u: 600 2 ?@$ 65536 + x E ~ a=. (1;2 3;4 5;;:'foo upon thee'),":&.> 600 ?@$ 1000 + x E ~ a=. a{~600 2 ?@$ #a=.(1;2 3;4 5;;:'foo upon thee'),":&.> 20 ?@$ 1000 + x E ~ a=. s: ' cogito ergo sum kakistocracy foo upon thee ',": 600 ?@$ 1000 + x E ~ a=. a{~600 2 ?@$ #a=. s: ' cogito ergo sum ',": 600 ?@$ 1000 + x E ~ a=. x: 600 ?@$ IF64{2e9 9e18 + x E ~ a=. x: 600 2 ?@$ 1000 + x E ~ a=. %/x: 0 1+2 600 ?@$ IF64{2e9 9e18 + x E ~ a=. %/x: 0 1+2 600 2 ?@$ 1000 + x E ~ a=. 4 0$0 + x E ~ a=. 4 0$'a' + x E ~ a=. 4 0$100 + x E ~ a=. 4 0$0.5 + x E ~ a=. 4 0$3j4 + x E ~ a=. 4 0$a: + x E ~ a=. 4 0$u: 123 + x E ~ a=. 4 0$s: ' cogito' + x E ~ a=. 4 0$3x + x E ~ a=. 4 0$3r4 +) + +(e. i. 0:) A0 +(e. i. 1:) A0 +(e. i: 0:) A0 +(e. i: 1:) A0 +([: + / e.) A0 +([: +./ e.) A0 +([: *./ e.) A0 +([: I. e.) A0 + +A1=: 4 : 0 + x (e.i.0:) E y + x (e.i.1:) E y + x (e.i:0:) E y + x (e.i:1:) E y + x ([:+ /e.) E y + x ([:+./e.) E y + x ([:*./e.) E y + x ([:I. e.) E y +) + +A1~ 3 4 0 5$0 +A1~ 3 4 0 5$a. +A1~ 3 4 0 5$-~2 +A1~ 3 4 0 5$-~3.4 +A1~ 3 4 0 5$-~3j4 + +(600 ?@$ 1000) A1 600 ?@$ 1e4 +(600 ?@$ 1000) A1 ~ 600 ?@$ 1e4 +(600 ?@$ 1000) A1 600 ?@$ 2e9 +(600 ?@$ 1000) A1 ~ 600 ?@$ 2e9 +(600 ?@$ 1000) A1 (o.0)+600 ?@$ 1000 +(600 ?@$ 1000) A1 ~ (o.0)+600 ?@$ 1000 + +(a.{~600 1 ?@$ 256) A1 600 1 ?@$ 2 +(a.{~600 1 ?@$ 256) A1 ~ 600 1 ?@$ 2 +(a.{~600 2 ?@$ 256) A1 600 2 ?@$ 2 +(a.{~600 2 ?@$ 256) A1 ~ 600 2 ?@$ 2 +(a.{~600 4 ?@$ 256) A1 600 4 ?@$ 2 +(a.{~600 4 ?@$ 256) A1 ~ 600 4 ?@$ 2 + + +4!:55 ;:'A0 A1 E f g h xx yy' + + +
new file mode 100644 --- /dev/null +++ b/test/gf.ijs @@ -0,0 +1,124 @@ +NB. f. ------------------------------------------------------------------ + +ar =: 5!:1 + +mat =: ?3 4$1e5 +mat -: 'mat' f. + +slash =: / +plus =: + +v =: plus slash +f =: 'v' f. +g =: +/ +(ar<'f') -: ar<'g' +(+/y) -: 'v' f. y=: _1e7+?12$2e7 + +each =: &.> +f =: 'each' f. +g =: &.> +(ar<'f') -: ar<'g' +(|.&.>y) -: |. 'each' f. y=: ;:'Cogito, ergo sum.' + +f=: undefined_no +'value error' -: ex 'f f.' + +t=: ~ +s=: 't' f. +(5!:1 <'s') -: 5!:1 <'t' + +s=: `:6 +t=: ((&.>) (`<)) s +f=: 't' f. +g=: ((&.>)(`<))(`:6) +(5!:1 <'f') -: 5!:1 <'g' + + +NB. f. and $: ----------------------------------------------------------- + +lr =: 1 : '5!:5 <''x''' +sgn =: * +dec =: <: +inc =: >: +fact =: 1:`(* $:@<:)@.* +fact1=: 1:`(* $:@dec)@.sgn + +'1:`(* $:@<:)@.*' -: fact f. lr +'1:`(* $:@<:)@.*' -: fact1 f. lr +'>:@(3 : ''1:`(* $:@<:)@.* y'' :(4 : ''x 1:`(* $:@<:)@.* y''))' -: inc@fact f. lr +'3 : ''1:`(* $:@<:)@.* y'' :(4 : ''x 1:`(* $:@<:)@.* y'')&.<:' -: fact&.dec f. lr + +s =: $: +cap =: [: + +monad=: 3 : '$: y' +dyad =: 4 : 'x $: y' +ambi =: (3 : '$: y') : (4 : 'x $: y') + +eq=: 2 : 0 + f=: x f. + g=: y f. + assert. (5!:1 <'f') -: 5!:1 <'g' + 1 +) + +>:@ s eq (>:@ ambi ) +>:@:s eq (>:@:ambi ) +>:@ s@ *: eq (>:@ monad@ *: ) +>:@:s@:*: eq (>:@:monad@:*: ) +s@ *: eq (monad@ *: ) +s@:*: eq (monad@:*: ) +s@ *:@ >: eq (monad@ *:@ >: ) +s@:*:@:>: eq (monad@:*:@:>: ) + +s & *: eq (ambi & *: ) +s &:*: eq (ambi &:*: ) +s & *:@>: eq (monad& *:@>: ) +*& s eq (* & monad ) +*&.s eq (* &.monad ) +*&:s eq (* &:monad ) + +s : + eq (monad : + ) +* : s eq (* : dyad ) + +s~ eq (dyad ~ ) + +s ;.1 eq ( monad ;. 1 ) ++&s;._3 eq (+&monad ;. _3 ) + +(+ s - ) eq (+ dyad - ) +([: + s ) eq ([: + ambi) +([: s - ) eq ([: monad - ) +(cap s - ) eq (cap monad - ) +(+ - s ) eq (+ - ambi) +(* : (+ - s) ) eq (* : (+ - dyad) ) +((+ - s) : > ) eq ((+ - monad) : >) + +(+ s ) eq (+ monad ) +(s >: ) eq (dyad >: ) +(s/ ) eq (dyad / ) +(s/. ) eq (monad/. ) +(s\ ) eq (monad\ ) +(s\. ) eq (monad\. ) + +( s`!`+@.] ) eq ( ambi `!`+@.] ) +( ^`!`+@.s ) eq ( ^ `!`+@.ambi ) +(%&(s`!`+@.])) eq (%&(monad`!`+@.] ) ) +(%&(^`!`+@.s)) eq (%&(^ `!`+@.monad) ) +(s`!`+@.]@* ) eq ( monad`!`+@.] @ *) +(^`!`+@.s@* ) eq ( ^ `!`+@.monad@ *) + +s"2@*: eq (monad"2@*: ) +s"2@*:@>: eq (monad"2@*:@>:) +s"2~ eq (dyad"2~ ) +(s"2 >: ) eq (dyad"2 >: ) + +C=: 0:`0:`1:`($:&<: + ($: <:)) @. ([: #. <:,0<[) +f=: (C +:)"0 f. +4!:55 ;:'C' +(f -: (!+:)) y=: 10 ?@$ 6 + + +4!:55 ;:'a ambi ar b C cap dec dyad each f fact fact1 eq g inc lr ' +4!:55 ;:'mat monad plus s sgn slash t v y' + +
new file mode 100644 --- /dev/null +++ b/test/gfor.ijs @@ -0,0 +1,261 @@ +NB. for. ---------------------------------------------------------------- + +f0=: 3 : 0 + s=. 0 + for. + i. y + do. + s=.>:s + end. +) + +(f0 = ])"0 n=:?5 10$100 + +f1=: 3 : 0 + s=.0 + for_j. + i.y + do. + s=.j+s + end. +) + +f1a=: 3 : 0 + s=.0 + for_j. + i.y + do. + s=.j_index+s + end. +) + +(f1 = 2&!)"0 n=:?5 10$100 +(f1a = 2&!)"0 n=:?5 10$100 + +f2=: 3 : 0 + s=.0 + for_j. + i.y + do. + if. 2|j do. continue. end. + s=.j+s + end. +) + +f2a=: 3 : 0 + s=.0 + for_j. + i.y + do. + if. 2|j_index do. continue. end. + s=.j_index+s + end. +) + +(f2 = 2&!@>.&.-:)"0 n=:?4 5$100 +(f2a = 2&!@>.&.-:)"0 n=:?4 5$100 + +f3=: 3 : 0 + s=.0 + for_j. + i.2e3 + do. + if. s>:y do. j break. end. + s=.j+s + end. +) + +1 0 2&-:@/:@(, 2&!@(_1 0&+)@f3)"0 n=:>:?4 5$1e6 + +f3a=: 3 : 0 + s=.0 + for_j. + i.2e3 + do. + if. s>:y do. j return. end. + s=.j+s + end. +) + +1 0 2&-:@/:@(, 2&!@(_1 0&+)@f3a)"0 n=:>:?4 5$1e6 + +f4=: 3 : 0 + t=.4!:0 ;:'xyz xyz_index' + for_xyz. + 1 + do. + t=.t,4!:0 ;:'xyz xyz_index' + end. + t=.t,4!:0 ;:'xyz xyz_index' +) + +_1 _1 0 0 _1 _1 -: f4 0 + +f5=: 3 : 0 + 'm n'=. $y + z=. (n,m)$_1 + for_i. i.m do. + for_j. i.n do. + z=. ((<i,j){y) (<j,i)}z + end. + end. +) + +(|: -: f5) x=:? 7 11$1000 +(|: -: f5) x=:?13 9$1000 +(|: -: f5) x=:? 8 8$1000 + +f6=: 3 : 0 + s=. y + z=. s$_1 + for_i. i.0{s do. + for_j. i.1{s do. + for_k. i.2{s do. + for_e. i.3{s do. + z=. (s#.i,j,k,e) (<i,j,k,e)}z + end. + end. + end. + end. +) + +(i. -: f6) 3 3 3 3 +(i. -: f6) 2 3 4 5 + +f7=: 4 : 0 + s=. 1 + for. i.y,0 do. + s=. x*s + end. +) + +2 (^ -: f7) 13 +3 (^ -: f7) 7 + +f8=: 4 : 0 + s=.0 + for_i. + select. x + case. 1 do. y + case. 2 do. i.y + end. + do. + s=.i+s + end. +) + +(+/x) -: 1 f8 x=:?10$100 +(2!n) -: 2 f8 n=:?1000 +'control error' -: 3 f8 etx 10 + +f9=: 3 : 0 + z=. '' + for_i. y do. + z=. z,>i + end. +) + +(; -: f9) (?1000$#x){x=: ;:'Cogito, ergo sum. 4 5 6 John Smith a b c d' + +f10=: 4 : 0 + best=. _999 + for_var. y do. + if. x=var do. + best=. var + end. + end. + best +) + +x -: f10"0 1~x=: ?100$1e6 +_999 = 1e7 f10 x + +f11=: 4 : 0 + best=. _999 + for_var. y do. + if. x=var do. + best=. var_index + end. + end. + best +) + +(i:~x) -: f11"0 1~x=: ?100$90 +_999 = 1e7 f11 x + +'ill-formed name' -: ex '3 : ''for_123. 4 5 6 do. 7 end.'' ' +'ill-formed name' -: ex '3 : ''for_1ab. 4 5 6 do. 7 end.'' ' +'ill-formed name' -: ex '3 : ''for__ab. 4 5 6 do. 7 end.'' ' +'ill-formed name' -: ex '3 : ''for_. 4 5 6 do. 7 end.'' ' + +g0=: 3 : 'for. do. 7 end.' + +'control error' -: g0 etx 0 + +g1=: 3 : 0 + for. + if. y do. 1 2 3 end. + do. + 9 + end. +) + +9 -: g1 1 + +'control error' -: g1 etx 0 + +'control error' -: ex '3 : ''for. 4 5 6 7 end.'' ' +'control error' -: ex '3 : ''for. 4 5 6 7 do. '' ' +'control error' -: ex '3 : ''for. 4 5 6 7 '' ' +'control error' -: ex '3 : ''for. 4 5 6 7 for. 1 2 3 do. end.'' ' + + +NB. for. ---------------------------------------------------------------- + +comp=: 4 : 0 + k=. (,.&.>-) i.#c=. 1,~y$0 + z=. ((x>:&*y),*x)$y + for. }. i.x do. z=. ; ((1+{:$z){.&.>k) +"1&.> (-c=.+/\.c){.&.><0,.z end. +) + +f=: 4 : 0 NB. assertions on m comp n + 'm n'=. x + c=. y + assert. ($c) -: ((m>:&*n)*+/+/\.^:(m-1) 1,~n$0),m + assert. ((#c)$n) -: +/"1 c + assert. *./ 0 <: ,c + assert. (i.#c) -: /:c + 1 +) + +(i.9) (, f comp)"0 (8) +0 (, f comp)"0 i.8 + +queens=: 3 : 0 + z=.i.n,*n=.y + for. }.z do. + b=. -. (i.n) e."1 ,. z +"1 _ ((-i.){:$z) */ _1 0 1 + z=. ((+/"1 b)#z),.(,b)#(*/$b)$i.n + end. +) + +f=: 4 : 0 NB. assertions on queens n + n=. x + q=. y + assert. n={:$q + assert. 2=#$q + assert. (i.n) e."1 q + assert. (/:q) -: i.#q + x=. (i.n),."1 q + y=. ((,.]) , (,.-)) 0 -.~ i:n + assert. -. x (,/"3@:(+"1"1 2) e."2 [) y + 1 +) + +(f queens)"0 i.9 + + +4!:55 ;:'comp f f0 f1 f1a f2 f2a f3 f3a f4 f5 f6 f7 f8 f9 f10 f11' +4!:55 ;:'g0 g1 n queens x ' + +
new file mode 100644 --- /dev/null +++ b/test/gft.ijs @@ -0,0 +1,32 @@ +NB. f. and performance -------------------------------------------------- + +tally=: # +plus =: + +sum =: plus/ +mean =: sum % tally +rev =: |. + +x=: 5e5?@$100 +y=: 5e5?@$100 + +s=: 10 timer 'x #/. y' +t=: 10 timer 'x tally/.f. y' +(1-*:threshold) > | (s-t)%s + +s=: 10 timer '+/y' +t=: 10 timer 'sum f. y' +(1-*:threshold) > | (s-t)%s + +s=: 10 timer '(+/ % #) y' +t=: 10 timer 'mean f. y' +(1-*:threshold) > | (s-t)%s + +y=: (1e5 7?@$#a.){a. +s=: 10 timer '|."1 y' +t=: 10 timer 'rev"1 f. y' +(1-*:threshold) > | (s-t)%s + + +4!:55 ;:'mean plus rev s sum t tally x y' + +
new file mode 100644 --- /dev/null +++ b/test/ggoto.ijs @@ -0,0 +1,180 @@ +NB. goto ---------------------------------------------------------------- + +fc =: 3 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. 'true' return. + label_false. 'false' return. +) + +'true' -: fc 1 +'false' -: fc 0 + +fc=: 3 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. 'true' return. + label_false. 'false' return. + label_truee. 'ok' +) + +'true' -: fc 1 +'false' -: fc 0 + +fc=: 3 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. 'true' return. + label_false. 'false' return. + label_tru. 'ok' +) + +'true' -: fc 1 +'false' -: fc 0 + +xx=: 0 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. 'true' return. + label_false. 'false' return. + label_true. 'bad' +) + +'control error' -: ex '3 : xx' + +xx=: 0 : 0 + if. y do. goto_true. else. goto_false. end. + label_true. label_true. 'true' return. + label_false. 'false' return. +) + +'control error' -: ex '3 : xx' + +def=: 3 : 0 " 0 + ('control error';'') i. < ex '3 : (yy=: (y{.xx),goto,y}.xx)' +) + +goto=: <'goto_it.' +lab =: <'label_it.' + +build=: 3 : 0 + (y{.bod),lab,y}.bod +) + +bod=: (<;._2) 0 : 0 + select. NB. 0 + if. NB. 1 + y NB. 2 + do. NB. 3 + 1 NB. 4 + else. NB. 5 + 0 NB. 6 + end. NB. 7 + fcase. NB. 8 + 0 NB. 9 + do. NB. 10 + 'zero' NB. 11 + case. NB. 12 + 1 NB. 13 + do. NB. 14 + 'one' NB. 15 + end. NB. 16 +) + +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 0 +0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 1 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 2 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 3 +0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 4 +0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 5 +0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 6 +0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 7 +0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 8 +0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 9 +0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 10 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 -: b=: def i.1+#xx=: build 11 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 -: b=: def i.1+#xx=: build 12 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 -: b=: def i.1+#xx=: build 13 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 -: b=: def i.1+#xx=: build 14 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 -: b=: def i.1+#xx=: build 15 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 -: b=: def i.1+#xx=: build 16 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 17 + +bod=: (<;._2) 0 : 0 + while. NB. 0 + if. NB. 1 + y NB. 2 + do. NB. 3 + 1 NB. 4 + elseif. NB. 5 + 2 NB. 6 + do. NB. 7 + 3 NB. 8 + end. NB. 9 + do. NB. 10 + 4 NB. 11 + try. NB. 12 + 5 NB. 13 + catch. NB. 14 + 6 NB. 15 + end. NB. 16 + end. NB. 17 +) + +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 0 +0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 1 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 2 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 3 +0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 4 +0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 5 +0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 6 +0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 7 +0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 8 +0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 9 +0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 10 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 -: b=: def i.1+#xx=: build 11 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 -: b=: def i.1+#xx=: build 12 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 -: b=: def i.1+#xx=: build 13 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 -: b=: def i.1+#xx=: build 14 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 -: b=: def i.1+#xx=: build 15 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 -: b=: def i.1+#xx=: build 16 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 -: b=: def i.1+#xx=: build 17 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 18 + +bod=: (<;._2) 0 : 0 + 0 NB. 0 + if. NB. 1 + y NB. 2 + do. NB. 3 + for. NB. 4 + 1 NB. 5 + do. NB. 6 + 2 NB. 7 + end. NB. 8 + else. NB. 9 + whilst. NB. 10 + 3 NB. 11 + do. NB. 12 + 4 NB. 13 + end. NB. 14 + end. NB. 15 +) + +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 0 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 1 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 2 +0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 3 +0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 4 +0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 5 +0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 6 +0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 7 +0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 8 +0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 -: b=: def i.1+#xx=: build 9 +0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 -: b=: def i.1+#xx=: build 10 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 -: b=: def i.1+#xx=: build 11 +0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 -: b=: def i.1+#xx=: build 12 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 -: b=: def i.1+#xx=: build 13 +0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 -: b=: def i.1+#xx=: build 14 +0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 -: b=: def i.1+#xx=: build 15 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -: b=: def i.1+#xx=: build 16 + + +4!:55 ;:'b bod build def fc goto i lab xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gh.ijs @@ -0,0 +1,327 @@ +NB. H. ------------------------------------------------------------------ + +(^ -: '' H. '') x=.0.01*_100+?40$200 +(^ -: 1 H. 1 ) x +(^ -: '' H. '') x=.j./0.01*_100+?2 40$200 +(^ -: 1 H. 1 ) x +*./ 1e_14 > | (^ - 40&('' H. '')) x=.0.01*_100+?40$200 +*./ 1e_14 > | (^ - 40&(1 H. 1 )) x +*./ 1e_14 > | (^ - 40&('' H. '')) x=.j./0.01*_100+?2 40$200 +*./ 1e_14 > | (^ - 40&(1 H. 1 )) x + +f =: '' H. '' +(f -: _&f) x=.0.001*_1000+?40$2000 +(f -: _&f) x=.0.001*j./_1000+?2 40$2000 + +rf=: 1 : '(,m)"_ ^!.1/ i.@[' +L1=: 2 : 'm rf %&(*/) n rf' +L2=: (i.@[ ^~ ]) % (!@i.@[) +H =: 2 : '(m L1 n +/ . * L2) " 0' + + +NB. Tchebyshev polynomials + +T =: (,1)"_ ` (i.@2:) ` ((0:,+:@$:@(-&1)) - $:@(-&2),0 0"_) @. (2&<.) +cos =: 2&o. +roots =: cos @ o. @ (>:@+:@i. % +:) +extrema =: cos @ o. @ (i. % ]) + +test=: 3 : 0 + n=: y + x=. 0.001*_1000+?40$2000 + f=. (n,-n) H. 0.5 + assert. 1e_10 > | 10&f@(-:@-.) roots n + assert. 1e_16 > (+/|f t. i.1+n) %~| f@(-:@-.) roots n + assert. 1e_16 > (+/|f t. i.1+n) %~| (_1^i.n) - f@(-:@-.) extrema n + assert. 0 = (f - (1+n)&f) x + g=. ((-n),n) H. 0.5 + assert. 1e_8 > | ((T n)&p. - 10&g@(-:@-.)) x + 1 +) + +test"(0) 1 2 3 4 5 6 7 + + (1 H. '' -: 1 1 H. 1 ) x=.0.01*_50+?40$100 + (1 H. '' -: 1 1 1 H. 1 1) x +10 (1 H. '' -: 1 1 H. 1 ) x +10 (1 H. '' -: 1 1 1 H. 1 1) x + +*./ 0 = 0 (?4$13) H. (?2$13) x=.0.01*_50+?40$1000 +*./ 1 = 1 (?3$13) H. (?4$13) x +*./, 0 1 = 0 1 (?2$13) H. (?1$13)/ x + +10 (2 3 H. 4 -: */@(2 3&(^!.1/)) H. (4&(^!.1))) x=.0.01*?10$30 + (2 3 H. 4 -: */@(2 3&(^!.1/)) H. (4&(^!.1))) x + +sin =: 1&o. +sinh=: 5&o. +cos =: 2&o. +cosh=: 6&o. + +sinb =: * '' H. 3r2@(_1r4&*)@*: +sinhb=: * '' H. 3r2@( 1r4&*)@*: +cosb =: '' H. 1r2@(_1r4&*)@*: +coshb=: '' H. 1r2@( 1r4&*)@*: + +(sin -: sinb ) z=.0.001*_1000+ ? 4 10$2000 +(sin -: sinb ) z=.0.001*_1000+j./?2 4 10$2000 +(sinh -: sinhb) z=.0.001*_1000+ ? 4 10$2000 +(sinh -: sinhb) z=.0.001*_1000+j./?2 4 10$2000 +(cos -: cosb ) z=.0.001*_1000+ ? 4 10$2000 +(cos -: cosb ) z=.0.001*_1000+j./?2 4 10$2000 +(cosh -: coshb) z=.0.001*_1000+ ? 4 10$2000 +(cosh -: coshb) z=.0.001*_1000+j./?2 4 10$2000 + +'domain error' -: ex '1 H. a.' +'domain error' -: ex 'a. H. 1 ' +'domain error' -: ex '1 H. a:' +'domain error' -: ex 'a: H. 1 ' + +'rank error' -: ex '(i.2 3) H. 1' +'rank error' -: ex '1 H. (i.2 3)' + +'domain error' -: 3 _5 (1 H. 1 etx) 0.5 +'domain error' -: 'abc' (1 H. 1 etx) 0.5 +'domain error' -: (2;3 4) (1 H. 1 etx) 0.5 +'domain error' -: 3 4 (1 H. 1 etx) 'ab' +'domain error' -: 3 4 (1 H. 1 etx) 2;3 4 + +'length error' -: 3 4 (1 H. 1 etx) 5 6 7 + + +NB. H. verb arguments --------------------------------------------------- + +X =: +/ . * +eterm =: (i.@[ ^~ ]) % !@i.@[ +rf =: 1 : '(,x)"_ ^!.1/ i.@[' +coeff =: 2 : 'x rf %&(*/) y rf' +prf =: 1 : '[: */ (,x)"_ ^!.1/ ]' NB. product of rising factorials +H =: 2 : '(x % y)@i.@[ X eterm' NB. u H v models u H. v +H1 =: 2 : 'x coeff y X eterm' NB. m H1 n models m H. n +H2 =: 2 : '(x prf) H. (y prf)' NB. m H2 n models m H. n + +1 -: ] H. >: 1 + +p =: */@(2 3&(^!.1/)) +q =: 4&(^!.1) +r =: %/@(2 4 3&(^!.1/)) + +f0 =: 2 3 H1 4 " 0 +f1 =: 2 3 H. 4 +f2 =: p H q " 0 +f3 =: p H. q +f4 =: r H 1: " 0 +f5 =: r H. 1: + +n=.(i.6),10 15 20 +x=.0.34 +n (f0 -: f1) x +n (f2 -: f3) x +n (f4 -: f5) x +n (f1 -: f3) x +n (f3 -: f5) x +n (2 3 H. 4 -: 2 3 H2 4) x + +*./ 0 = 0 f5 x=.0.001*?4$100 +*./ 1 = 1 f5 x +*./ , 0 1 = 0 1 f5/ x + +(f1 -: f5) x=.0.001*_500+?10$1000 +_ (f1 -: f5) x + +70 (f1 -: p H. q) x=.0.001*_500+?10$1000 +70 (f1 -: p H. 4) x +70 (f1 -: 2 3 H. q) x + +'rank error' -: 5 (i.2 3)"_ H. '' etx 2 3 +'length error' -: 5 i.@2: H. '' etx 2 3 +'domain error' -: 5 'abcde'"_ H. '' etx 2 3 + + +NB. H. further identities ----------------------------------------------- + +NB. Abramowitz & Stegun 15.1.3 + +((^.@-. % -) -: 1 1 H. 2) z=. j./1e_5*_5e4+?2 20$1e5 + +(^.@>: -: [ * 1 1 H. 2@-) x=. (0.01&<@| # ]) 0.001*_700+40 ?@$1401 +(^.@>: -: [ * 1 1 H. 2@-) x=. (0.01&<@| # ]) (0.002*?40$400) r. ?40$1000 + +NB. Abramowitz & Stegun 15.1.7 + +f7 =: 1r2 1r2 H. 3r2 @-@*: +g7 =: 1 1 H. 3r2 @-@*: * >:&.*: +h7 =: ^.@(+ >:&.*:) % ] + +(f7 -: g7) x=.(+ {&0.004 _0.004@(0&>) * 0.004&>@|) 0.001*_999+?40$1999 +(f7 -: h7) x + +NB. Abramowitz & Stegun 15.1.8 + +f8 =: 1 : '^&(-x)@-.' +g8 =: 1 : 'x H. ($0)' +h8 =: 1 : '(x,1) H. 1' + +(a f8 -: a g8) x=.0.01*_50+?40$100 [ a=.0.1*?50 +(a f8 -: a h8) x +(a f8 -: a g8) x=.j./0.01*_50+?2 40$100 +(a f8 -: a h8) x + +*./ 1e_10 > | (a f8 - 50&(a g8)) x=.0.01*_30+?40$60 +*./ 1e_10 > | (a f8 - 50&(a h8)) x +*./ 1e_10 > | (a f8 - 50&(a g8)) x=.j./0.01*_30+?2 40$60 +*./ 1e_10 > | (a f8 - 50&(a h8)) x + +*./ 1e_10 > | (a f8 -: 50&(a g8)) x=.0.001*_1000+?40$2000 [ a=.1 +*./ 1e_10 > | (a f8 -: 50&(a g8)) x [ a=.1.5 +*./ 1e_10 > | (a f8 -: 50&(a g8)) x [ a=.2 +*./ 1e_10 > | (a f8 -: 50&(a g8)) x [ a=.2.3 + +NB. Abramowitz & Stegun 15.1.13 + +f13 =: 1 : '(0 1r2+x)H.(1+2*x)' +g13 =: 1 : '(2^2*x)"_ * (1: + %:@-.) ^ (_2*x)"_' +h13 =: 1 : '%:@-. * (1 1r2+x) H. (1+2*x)' + +(0.2 f13 -: 0.2 g13) x=.0.001*_990+?40$1981 +(0.2 f13 -: 0.2 h13) x +(2 f13 -: 2 g13) x +(2 f13 -: 2 h13) x +(5 f13 -: 5 g13) x +(5 f13 -: 5 g13) x + +NB. Abramowitz & Stegun 15.1.14 + +f14 =: 1 : '(x,1r2+x) H. (2*x)' +g14 =: 1 : '(2^_1+2*x)"_ * %@%:@-. * >:@%:@-. ^ (1-2*x)"_' + +(0.2 f14 -: 0.2 g14) x=.0.001*_990+?40$1981 +(2 f14 -: 2 g14) x +(3 f14 -: 3 g14) x +(4 f14 -: 4 g14) x + +NB. Abramowitz & Stegun 15.1.17 + +sin =: 1&o. +cos =: 2&o. +f17 =: 1 : '(x,-x) H. 1r2 @ (*:@sin)' +g17 =: 1 : 'cos @ ((2*x)&*)' + +*./ 1e_14>| (0.4 f17 - 0.4 g17) x=.0.001*_1000+?40$2001 +*./ 1e_14>| (1 f17 - 1 g17) x +*./ 1e_14>| (1.4 f17 - 1.4 g17) x +*./ 1e_14>| (3 f17 - 3 g17) x + +NB. modified Bessel fn of various orders; A&S Table 9.8, 9.9, 9.10 + +Bessel =: 1 : '(($0) H. (x+1) * ^&(-:x) % (!x)"_)@:*:@:-:' + +f0 =: 0 Bessel * ^@- +1e_10 > | 1 - f0 0 +1e_10 > | 0.9071009258 - f0 0.1 +1e_10 > | 0.4657596076 - f0 1 NB. A&S say 96077 +1e_10 > | 0.3085083225 - f0 2 +1e_10 > | 0.1835408126 - f0 5 +1e_10 > | 0.1278333371 - f0 10 +1e_10 > | 0.0897803119 - f0 20 + +f1 =: 1 Bessel * ^@- +1e_10 > | 0 - f1 0 +1e_10 > | 0.1564208032 - f1 0.5 +1e_10 > | 0.2079104154 - f1 1 +1e_10 > | 0.1968267133 - f1 3 +1e_10 > | 0.1639722669 - f1 5 +1e_10 > | 0.1160577582 - f1 11 +1e_10 > | 0.0875062222 - f1 20 + +f2a =: 2 Bessel * %@*: +1e_10 > | 0.1251041992 - f2a 0.1 +1e_10 > | 0.1357476698 - f2a 1 +1e_10 > | 0.2042345837 - f2a 2.5 +1e_10 > | 0.4013868359 - f2a 4 +1e_10 > | 0.7002245987 - f2a 5 NB. A&S say 45988 + +f2 =: 2 Bessel * ^@- +1e_9 > | 0.117951906 - f2 5 +1e_9 > | 0.103580801 - f2 10 +1e_9 > | 0.081029690 - f2 20 + +1e_6 > | 2.8791e_2 - (3 Bessel * ^@-) 2 +1e_7 > | 6.8654e_3 - (4 Bessel * ^@-) 2 +1e_7 > | 1.3298e_3 - (5 Bessel * ^@-) 2 +1e_8 > | 2.1656e_4 - (6 Bessel * ^@-) 2 +1e_9 > | 3.0402e_5 - (7 Bessel * ^@-) 2 +1e_10> | 3.7487e_6 - (8 Bessel * ^@-) 2 +1e_11> | 4.1199e_7 - (9 Bessel * ^@-) 2 + +1e_8 > | 0.29462538 - (1e9 "_ * ^&_10 * 10 Bessel) 2 +1e_8 > | 1.32920036 - (1e11"_ * ^&_11 * 11 Bessel) 2 +1e_6 > | 0.411087 - (1e24"_ * ^&_20 * 20 Bessel) 2 +1e_6 > | 0.976669 - (1e26"_ * ^&_21 * 21 Bessel) 2 + + +NB. a H. b t. ----------------------------------------------------------- + +k =. i. n=.10 + +(1 H. 1 t. k) -: %!k +(1 H. 1 t: k) -: n$1 +(0&(1 H. 1) t. k) -: n{.%!0{.k +(1&(1 H. 1) t. k) -: n{.%!1{.k +(2&(1 H. 1) t. k) -: n{.%!2{.k +(3&(1 H. 1) t. k) -: n{.%!3{.k +(4&(1 H. 1) t. k) -: n{.%!4{.k +(5&(1 H. 1) t. k) -: n{.%!5{.k + +(1 H. '' t. k) -: n$1 +(1 H. '' t. k) -: +/\^:0 n$1 +(2 H. '' t. k) -: +/\^:1 n$1 +(3 H. '' t. k) -: +/\^:2 n$1 +(4 H. '' t. k) -: +/\^:3 n$1 +(5 H. '' t. k) -: +/\^:4 n$1 + +(_1 H. '' t. k) -: (_1^k)*k!1 +(_2 H. '' t. k) -: (_1^k)*k!2 +(_3 H. '' t. k) -: (_1^k)*k!3 +(_4 H. '' t. k) -: (_1^k)*k!4 +(_5 H. '' t. k) -: (_1^k)*k!5 + +(1 1 H. 2 t. k) -: %>:k + + +NB. a H. b D. 1 --------------------------------------------------------- + +f =: 1 H. '' D. 1 +g =: ^&_2@-. +(f -: g) x=.0.001*_900+?20$1800 + +f =: 1.5 H. '' D. 1 +g =: 1.5"_ * ^&_2.5@-. +(f -: g) x=.0.001*_900+?20$1800 + + +NB. H. erf and N(0,1) --------------------------------------------------- + +NB. by Ewart Shaw + +erf =: 1 H. 1.5@*: * 2p_0.5&* % ^@:*: +n01cdf=: -: @: >: @: erf @: ((%:0.5)&*) NB. CDF of N(0,1) + +1e_10 > | (erf 0.5) - 0.5204998778 +1e_10 > | (erf 1 ) - 0.8427007929 +1e_10 > | (erf 1.5) - 0.9661051465 + +1e_15 > | (n01cdf 0 ) - 0.5 +1e_15 > | (n01cdf 0.5) - 0.691462461274013 +1e_15 > | (n01cdf 1.0) - 0.841344746068543 +1e_15 > | (n01cdf 1.5) - 0.933192798731142 +1e_15 > | (n01cdf 2.0) - 0.977249868051821 + + +4!:55 ;:'Bessel H H1 H2 T X a coeff cos cosb ' +4!:55 ;:'cosh coshb erf eterm extrema f f0 f1 f13 f14 f17 ' +4!:55 ;:'f2 f2a f3 f4 f5 f7 f8 g g13 g14 ' +4!:55 ;:'g17 g7 g8 h h13 h7 h8 k L1 L2 n n01cdf p ' +4!:55 ;:'prf q r rf roots sin sinb sinh sinhb test x z ' + +
new file mode 100644 --- /dev/null +++ b/test/gi.ijs @@ -0,0 +1,462 @@ +NB. i.y ----------------------------------------------------------------- + +iota =: 3 : '+/&>{(}.*/\.|y,1)*&.>((0>y)*|>:y)+&.>(*y)*&.>i.&.>|y' + +a =: i.1+?50 +1 = $$a +0 = 0{a +_1 *./ . = 2-/\a +((#a)$(0{a)+_1{a) -: a+|.a + +p =: i.q=:_5+?10 10 10 +($p) -: |q +p -: iota q + +'domain error' -: i. etx 'abc' +'domain error' -: i. etx 3.4 5 +'domain error' -: i. etx 3j4 5 +'domain error' -: i. etx 3 4;5 + + +NB. x i.y --------------------------------------------------------------- + +NB. Boolean +a=:1=?10 5$2 +a-:(i.~a){a +(i.~a)-:i.~<"_1 a +a-:(a i.0+a){a +a-:(a i.[&.o.a){a +a-:(a i.[&.(0j1&*)a){a +0=a i.0{a +(#a)=a i.4 5 6 7 8 +(#a)=a i.'abcde' +(b*#a) -: (a=:(>:?20)$0) i. b=:?30$2 + +NB. literal +a=:a.{~32+?10 5$95 +a-:(i.~a){a +(i.~a)-:i.~<"_1 a +0=a i.0{a +(#a)=a i.4 5 6 7 8 +(b*#a) -: (a=:(>:?40)$'axy') i. (b=:?30$2){'ab' +(1|.a) -: (a i.1|.a){a=:a.{~?117 1$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 2$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 3$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 4$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 5$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 6$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 7$#a. +(1|.a) -: (a i.1|.a){a=:a.{~?117 8$#a. + +(1|.a) -: (a i. 1|.a){a=:a.{~?7000 2$#a. +(1|.a) -: (a i. 1|.a){a=:a.{~?7000 4$#a. +(1|."2 a) -: (a i."(2) 1|."2 a){"_1 a=:a.{~?7 5000 2$#a. +(1|."2 a) -: (a i."(2) 1|."2 a){"_1 a=:a.{~?7 5000 4$#a. + +NB. integer +a=:?10 5$100 +a-:(i.~a){a +(i.~a)-:i.~<"_1 a +a-:(a i.[&.o.a){a +a-:(a i.[&.(0j1&*)a){a +0=a i.0{a +(#a)=a i.4 5 6 7 8 +(#a)=a i.'abcde' +(b*#a) -: (a=:(>:?40)$49 9 123) i. (b=:?40$2){49 _49 +(i.31) -: i.~2^i. 31 +(i.31) -: i.~2^i._31 +(30$0) -: i.~30$123456 +(30$0) -: i.~30$_12345678 +a -: (i.~a){a=:?4000$4000 NB. small integers +(1000{.a) -: (a i.1000{.a){a=:?4000$4000 NB. small integers +a -: (i.~a){a=: _5 2147483647 NB. large integers +a -: (i.~a){a=: 2 2147483647 NB. large integers +a -: (i.~a){a=: ?4000$123456 NB. large integers +(1000{.a) -: (a i.1000{.a){a=:?4000$123456 NB. large integers + +NB. floating point +a=:o._40+?10 5$100 +a-:(i. ~a){a +a-:(i.!.0~a){a +a-:(a i. [&.(0j1&*)a){a +a-:(a i.!.0 [&.(0j1&*)a){a +(i. ~a)-:i. ~<"_1 a +(i.!.0~a)-:i.!.0~<"_1 a +0=a i. 0{a +0=a i.!.0[0{a +(#a)=a i. 4 5 6 7 8 +(#a)=a i.!.0 [4 5 6 7 8 +(#a)=a i. 'abcde' +(#a)=a i.!.0 'abcde' +(b*#a) -: (a=:(>:?40)$4.95 9 _1.62) i. (b=:?70$2){4.95 1234 +(b*#a) -: (a=:(>:?40)$4.95 9 _1.62) i.!.0 (b=:?70$2){4.95 1234 + +NB. complex +a=:r.?10 5$1000 +a-:(i. ~a){a +a-:(i.!.0 ~a){a +(i. ~a)-:i. ~<"_1 a +(i.!.0~a)-:i.!.0~<"_1 a +0=a i. 0{a +0=a i.!.0[0{a +(#a)=a i. 4 5 6 7 8 +(#a)=a i.!.0[4 5 6 7 8 +(#a)=a i. 'abcde' +(#a)=a i.!.0 'abcde' +(b*#a) -: (a=:(>:?40)$4j95 9 _1.62) i. (b=:?30$2){4j95 1234 +(b*#a) -: (a=:(>:?40)$4j95 9 _1.62) i.!.0 (b=:?30$2){4j95 1234 + +NB. boxed +t=:(1=?70$3)<;.1 ?70$100 +a=:t{~?10 5$#t +a-:(i. ~a){a +a-:(i.!.0~a){a +(i. ~a)-:i. ~<"_1 a +(i.!.0~a)-:i.!.0~<"_1 a +0=a i. 0{a +0=a i.!.0[0{a +(#a)=a i. 'Cogit' +(#a)=a i.!.0 'Cogit' +(#a)=a i. 4 5 6 7 8 +(#a)=a i.!.0[4 5 6 7 8 +(b*#a) -: (a=:(>:?40)$(<4;'aj95'),<'lieben') i. (b=:?50$2){(<4;'aj95'),<1234 +((i. ~x){x) -: x=:;:'i.~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4' +((i.!.0~x){x) -: x=:;:'i.~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4' +(20$0) -: i. ~(?20$3){'';($0);(0$<'') +(20$0) -: i.!.0~(?20$3){'';($0);(0$<'') +(20$0) -: i. ~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4 +(20$0) -: i.!.0~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4 + + +NB. x i.y encore -------------------------------------------------------- + +a =: 1=?100 4$2 +j =: i.~a +j -: a i.0+a +j -: (0+a)i.a +a -: j{a +(#a) -: a i.'abcd' +(2$#a) -: a i.2 4$2 + +0 -: (i.6 2 3)i.i.2 3 +6 -: (i.6 2 3)i.2 3$9 + +($0) -: (6 2 3$9)i.0 2 3$5 +(5 0 4$0) -: (6 2 3$9)i.5 0 4 2 3$5 + +0 -: (6 2 0$9)i.2 0$0 +(3$0) -: (6 2 0$9)i.3 2 0$0 +(3$0) -: (6 2 0$0.5)i.3 2 0$'a' +(3$0) -: (6 2 0$0.5)i.3 2 0$<'' + +(($b)$0) -: ''i.b=:'abc' +(($b)$0) -: ($0)i.b=:i.3 4 +(($b)$0) -: (0$<'')i.b=:+&.>i.3 4 +0 0 -: (i.0 3 4)i.b=:i.2 3 4 + +3 3 3 3 3 -: (i.3 4 ) i. 5 4$'a' +3 3 3 3 3 -: (3 4$<'a') i. 5 4$'a' + +test=: 3 : 0 + n=: ?y + xx=: ?n$10>.<.n%3 + yy=: xx+2.5-2.5 + ((~.xx)-:~.yy),((~:xx)-:~:yy),((xx i. xx) -: yy i. yy) +) + +test 1000 +test 1000 +test 1000 + +*./@test"0 [4 5$1000 + +2 2 2 -: (i.2 3) i. etx i.3 4 +2 2 2 -: (i.2 3) i. etx 3 4$'a' +2 2 2 -: (i.2 3) i. etx 3 4$;:'Cogito, erogeneous' +3 3 -: (2 3 4$'x') i."2 etx 'kakistocracy' + +2 -: (i.2 3) i. etx 4 +3 3 -: (2 3 4 6$'x') i."3 etx 'lieben' + + +NB. x i.y for strings x and y ------------------------------------------- + +map =: 3 : '(i.-#y) (a.i.|.y)}256$#y' +ciof =: a.&i.@] { map@[ + +f =: i. -: ciof + +((?3000$256){a.) f (?4 80$256){a. +((?3000$256){a.) f (? 300$256){a. + + +NB. x i.y on boxed numerics --------------------------------------------- + +0 0 -: i. ~<"0 [ 1,1-2^_45 +0 0 -: i. ~<"0 |.1,1-2^_45 +0 1 -: i.!.0~<"0 [ 1,1-2^_45 +0 1 -: i.!.0~<"0 |.1,1-2^_45 + +(i.~t) -: (2*#x)$i.~x [ t=:(<"0 x), <"0 x=:?180$90 +(i.~t) -: (2*#x)$i.~x [ t=:(<"0 x), <"0 (o.1)%~o.x=:?180$90 +(i.~t) -: (2*#x)$i.~x [ t=:(<"0 x),~<"0 (o.1)%~o.x=:?180$90 + +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.0, x=:?40$2 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.345,x=:?40$2 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3.5,x=:?40$2 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3j5,x=:?40$2 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.0, x=:?40$2e9 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.345,x=:?40$2e9 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3.5,x=:?40$2e9 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3j5,x=:?40$2e9 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.0, x=:o.?40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.345,x=:o.?40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3.5,x=:o.?40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3j5,x=:o.?40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.0, x=:j./?2 40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.345,x=:j./?2 40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3.5,x=:j./?2 40$2e7 +(2$<i.~x) -: (y i.<"0 x); (<"0 x)i.y=:<"0 }.3j5,x=:j./?2 40$2e7 + + +NB. x i."r y ------------------------------------------------------------ + +g =: 4 : 'x i. y' + +(i.3 0) (g"1 -: i."1) i.3 2 +(i.3 0) (g"1 -: i."1) i.3 0 +(i.0 0) (g"1 -: i."1) i.0 7 +(i.0 7) (g"1 -: i."1) i.0 3 +(i.3) (g"1 -: i."1) i.0 7 +(i.3) (g"1 -: i."1) i.0 0 +'' (g"1 -: i."1) i.0 7 +'' (g"1 -: i."1) i.0 5 +'' (g"1 -: i."1) i.0 0 +(i.3 5) (g"1 -: i."1) 3 7$'a' +(i.3 5) (g"1 -: i."1) 3 7$<5 +'abc' (g"1 -: i."1) 7 5$3 +'abc' (g"1 -: i."1) 7 5$<3 + +(i.6) -: x i."1 0 (<0 1)|:x=:a.{~6 16$32+96?96 +(15-i.6) -: x i."1 0 (<0 1)|:|."1 x +(6$0) -: x i."1 0 {."1 x +(6$15) -: x i."1 0 {:"1 x +(($x)$i.16) -: x i."1 x +(x=:0=5|?20 19$2) (g"1 -: i."1) 1 + +x=:a.{~?(117 7,c)$#a. [ c=:3 +x (g"2 -: i."2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i."_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:4 +x (g"2 -: i."2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i."_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:11 +x (g"2 -: i."2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i."_1) y=:a.{~?(117, c)$#a. + +x=:p+?117 7$q [ p=:0 [ q=:14 +x (g"1 -: i."1 ) y=:p+?q +x (g"1 -: i."1 ) x +x (g"1 -: i."1 ) y=:p+?117 3$q +x (g"1 -: i."1 ) y=:p+?12$q +x (g"_1 -: i."_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_7 [ q=:14 +x (g"1 -: i."1 ) y=:p+?q +x (g"1 -: i."1 ) x +x (g"1 -: i."1 ) y=:p+?117 3$q +x (g"1 -: i."1 ) y=:p+?12$q +x (g"_1 -: i."_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_2000 [ q=:14 +x (g"1 -: i."1 ) y=:p+?q +x (g"1 -: i."1 ) x +x (g"1 -: i."1 ) y=:p+?117 3$q +x (g"1 -: i."1 ) y=:p+?12$q +x (g"_1 -: i."_1) y=:p+?117$q +x=:p+?117 7$q [ p=:0 [ q=:1e4 +x (g"1 -: i."1 ) y=:p+?q +x (g"1 -: i."1 ) x +x (g"1 -: i."1 ) y=:p+?117 3$q +x (g"1 -: i."1 ) y=:p+?12$q +x (g"_1 -: i."_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_5e5 [ q=:1e6 +x (g"1 -: i."1 ) y=:p+?q +x (g"1 -: i."1 ) x +x (g"1 -: i."1 ) y=:p+?117 3$q +x (g"1 -: i."1 ) y=:p+?12$q +x (g"_1 -: i."_1) y=:p+?117$q + +x=:?7 63 3$q=:4 +x (g"2 -: i."2 ) y=:((?10$63){0{x),?14 3$q +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:(?~1{$y){"2 y=:x,"2?7 5 3$q +x (g"_1 -: i."_1) y=:((?5$63){1{x),?2 3$q + +x=:o.?7 13 3$q=:3 +x (g"2 -: i."2 ) y=:((?10$13){0{x),o.?14 3$q +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:(?~1{$y){"2 y=:x,"2 o.?7 5 3$q +x (g"_1 -: i."_1) y=:((?5$13){1{x),o.?2 3$q + +x=:r.?7 13 3$q=:3 +x (g"2 -: i."2 ) y=:((?10$13){0{x),r.?14 3$q +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:(?~1{$y){"2 y=:x,"2 r.?7 5 3$q +x (g"_1 -: i."_1) y=:((?5$13){1{x),r.?2 3$q + +x=:<"0 ?7 63 3$q=:3 +x (g"2 -: i."2 ) y=:((?10$63){0{x),<"0?14 3$q +x (g"2 -: i."2 ) x +x (g"2 -: i."2 ) y=:(?~1{$y){"2 y=:x,"2<"0?7 5 3$q +x (g"_1 -: i."_1) y=:((?5$63){1{x),<"0?2 3$q + +x (g"1 2 -: i."1 2) x=:1 2,:3 4 + + +NB. x i.!.0 "r y -------------------------------------------------------- + +g =: 4 : 'x i.!.0 y' + +(i.3 0) (g"1 -: i.!.0"1) i.3 2 +(i.3 0) (g"1 -: i.!.0"1) i.3 0 +(i.0 0) (g"1 -: i.!.0"1) i.0 7 +(i.0 7) (g"1 -: i.!.0"1) i.0 3 +(i.3) (g"1 -: i.!.0"1) i.0 7 +(i.3) (g"1 -: i.!.0"1) i.0 0 +'' (g"1 -: i.!.0"1) i.0 7 +'' (g"1 -: i.!.0"1) i.0 5 +'' (g"1 -: i.!.0"1) i.0 0 +(i.3 5) (g"1 -: i.!.0"1) 3 7$'a' +(i.3 5) (g"1 -: i.!.0"1) 3 7$<5 +'abc' (g"1 -: i.!.0"1) 7 5$3 +'abc' (g"1 -: i.!.0"1) 7 5$<3 + +(i.6) -: x i.!.0"1 0 (<0 1)|:x=:a.{~6 16$32+96?96 +(15-i.6) -: x i.!.0"1 0 (<0 1)|:|."1 x +(6$0) -: x i.!.0"1 0 {."1 x +(6$15) -: x i.!.0"1 0 {:"1 x +(($x)$i.16) -: x i.!.0"1 x +(x=:0=5|?20 19$2) (g"1 -: i.!.0"1) 1 + +x=:a.{~?(117 7,c)$#a. [ c=:3 +x (g"2 -: i.!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i.!.0"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:4 +x (g"2 -: i.!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i.!.0"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:11 +x (g"2 -: i.!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i.!.0"_1) y=:a.{~?(117, c)$#a. + +x=:p+?117 7$q [ p=:0 [ q=:14 +x (g"1 -: i.!.0"1 ) y=:p+?q +x (g"1 -: i.!.0"1 ) x +x (g"1 -: i.!.0"1 ) y=:p+?117 3$q +x (g"1 -: i.!.0"1 ) y=:p+?12$q +x (g"_1 -: i.!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_7 [ q=:14 +x (g"1 -: i.!.0"1 ) y=:p+?q +x (g"1 -: i.!.0"1 ) x +x (g"1 -: i.!.0"1 ) y=:p+?117 3$q +x (g"1 -: i.!.0"1 ) y=:p+?12$q +x (g"_1 -: i.!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_2000 [ q=:14 +x (g"1 -: i.!.0"1 ) y=:p+?q +x (g"1 -: i.!.0"1 ) x +x (g"1 -: i.!.0"1 ) y=:p+?117 3$q +x (g"1 -: i.!.0"1 ) y=:p+?12$q +x (g"_1 -: i.!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:0 [ q=:1e4 +x (g"1 -: i.!.0"1 ) y=:p+?q +x (g"1 -: i.!.0"1 ) x +x (g"1 -: i.!.0"1 ) y=:p+?117 3$q +x (g"1 -: i.!.0"1 ) y=:p+?12$q +x (g"_1 -: i.!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_5e5 [ q=:1e6 +x (g"1 -: i.!.0"1 ) y=:p+?q +x (g"1 -: i.!.0"1 ) x +x (g"1 -: i.!.0"1 ) y=:p+?117 3$q +x (g"1 -: i.!.0"1 ) y=:p+?12$q +x (g"_1 -: i.!.0"_1) y=:p+?117$q + +x=:?7 63 3$q=:4 +x (g"2 -: i.!.0"2 ) y=:((?10$63){0{x),?14 3$q +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:(?~1{$y){"2 y=:x,"2?7 5 3$q +x (g"_1 -: i.!.0"_1) y=:((?5$63){1{x),?2 3$q + +x=:o.?7 13 3$q=:3 +x (g"2 -: i.!.0"2 ) y=:((?10$13){0{x),o.?14 3$q +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:(?~1{$y){"2 y=:x,"2 o.?7 5 3$q +x (g"_1 -: i.!.0"_1) y=:((?5$13){1{x),o.?2 3$q + +x=:r.?7 13 3$q=:3 +x (g"2 -: i.!.0"2 ) y=:((?10$13){0{x),r.?14 3$q +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:(?~1{$y){"2 y=:x,"2 r.?7 5 3$q +x (g"_1 -: i.!.0"_1) y=:((?5$13){1{x),r.?2 3$q + +x=:<"0 ?7 63 3$q=:3 +x (g"2 -: i.!.0"2 ) y=:((?10$63){0{x),<"0?14 3$q +x (g"2 -: i.!.0"2 ) x +x (g"2 -: i.!.0"2 ) y=:(?~1{$y){"2 y=:x,"2<"0?7 5 3$q +x (g"_1 -: i.!.0"_1) y=:((?5$63){1{x),<"0?2 3$q + +x (g"1 2 -: i.!.0"1 2) x=:1 2,:3 4 + + +NB. x i. y on floating point -------------------------------------------- + +0 0 0 0 -: i.~ 1+2^-45 46 47 48 + +f=: 4 : 0 + ct=. x + y -: (i.!.ct~ y){y +) + +(2^-34+-:i.3 10) f"0 1 x=: 0.001 * _1e5 + ?777$2e5 + +f1=: 3 : 0 + t -: (i.~ t){t=. y+i.1000 +) + +f1"0] 10^i.2 10 + +f2=: 3 : 0 + t -: (i.~ t){t=. y+?~1000 +) + +f2"0] 10^i.2 10 + +t=: 9!:18 '' +f=: 1: i."1~ =/~ +(i. -: f)~ x=: 1+ t*i.50 +(i. -: f)~ x=: 1+0.4*t*i.50 +(i. -: f)~ x=: 1+0.5*t*i.50 +(i. -: f)~ x=: 1+ t*?~50 +(i. -: f)~ x=: 1+0.4*t*?~50 +(i. -: f)~ x=: 1+0.5*t*?~50 + +x (i. -: f) y [ x=: 1+ t*i.50 [ y=: 1+ t*?~60 +x (i. -: f)~y +x (i. -: f) y [ x=: 1+0.4*t*i.50 [ y=: 1+0.4*t*?~60 +x (i. -: f)~y +x (i. -: f) y [ x=: 1+0.5*t*i.50 [ y=: 1+0.5*t*?~60 +x (i. -: f)~y + + +4!:55 ;:'a b c ciof ct f f1 f2 g iota j map n p q t test x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/gi0.ijs @@ -0,0 +1,21 @@ +NB. x i.y on boolean scalar y ------------------------------------------- + +f0=: 4 : 0 " 0 + if. y<x do. v=: 0 y}x$1 else. v=: x$1 end. + assert. (x<.y)=v i. 0 + 1 +) + +f1=: 4 : 0 " 0 + if. y<x do. v=: 1 y}x$0 else. v=: x$0 end. + assert. (x<.y)=v i. 1 + 1 +) + +*./, f0/~i.40 +*./, f1/~i.40 + + +4!:55 ;:'b f0 f1 i n x' + +
new file mode 100644 --- /dev/null +++ b/test/gibs.ijs @@ -0,0 +1,76 @@ +NB. i.!.0 and associates ------------------------------------------------ + +NB. i.!.0 using grading and binary search +NB. currently invoked only for boxed arrays where +NB. - each target item has more than one element, or +NB. - some opened target item has more than one numeric element + +test=: 4 : 0 + assert. (~.!.0 -: ~. ) y + assert. (~:!.0 -: ~: ) y + assert. (I.@(~:!.0) -: I.@~: ) y + assert. x ( (i.!.0) -: i. ) y + assert. (x&(i.!.0) -: x&i. ) y + assert. x ( (i:!.0) -: i: ) y + assert. (x&(i:!.0) -: x&i: ) y + assert. x ( (-.!.0) -: -. ) y + assert. ( (-.!.0)&x -: -.&x ) y + assert. x ( (e.!.0) -: e. ) y + assert. ( (e.!.0)&x -: e.&x ) y + assert. x ((e.!.0 i. 0:) -: (e.i.0:) ) y + assert. ((e.!.0 i. 0:)&x -: (e.i.0:)&x ) y + assert. x ((e.!.0 i. 1:) -: (e.i.1:) ) y + assert. ((e.!.0 i. 1:)&x -: (e.i.1:)&x ) y + assert. x ((e.!.0 i: 0:) -: (e.i:0:) ) y + assert. ((e.!.0 i: 0:)&x -: (e.i:0:)&x ) y + assert. x ((e.!.0 i: 1:) -: (e.i:1:) ) y + assert. ((e.!.0 i: 1:)&x -: (e.i:1:)&x ) y + assert. x ( + /@(e.!.0) -: + /@e. ) y + assert. ( + /@(e.!.0)&x -: + /@e.&x ) y + assert. x (([: +/ e.!.0) -: + /@e. ) y + assert. (([: +/ e.!.0)&x -: + /@e.&x ) y + assert. x ( +./@(e.!.0) -: +./@e. ) y + assert. ( +./@(e.!.0)&x -: +./@e.&x ) y + assert. x (([:+./ e.!.0) -: +./@e. ) y + assert. (([:+./ e.!.0)&x -: +./@e.&x ) y + assert. x ( *./@(e.!.0) -: *./@e. ) y + assert. ( *./@(e.!.0)&x -: *./@e.&x ) y + assert. x (([:*./ e.!.0) -: *./@e. ) y + assert. (([:*./ e.!.0)&x -: *./@e.&x ) y + assert. x ( I.@(e.!.0) -: I.@e. ) y + assert. ( I.@(e.!.0)&x -: I.@e.&x ) y + assert. x (([: I. e.!.0) -: I.@e. ) y + assert. (([: I. e.!.0)&x -: I.@e.&x ) y + 1 +) + +x test y [ x=: <"(1) 1019 2?@$100 [ y=: <"(1) 877 2?@$100 +y test y + +x test y [ x=: i.&.> 1000 ?@# 750 [ y=: i.&.> 1019 ?@# 880 +y test y + +a=: ;:'chthonic kakistocracy kleptocracy eleemosynary amanuensis paronomasiac' +a=: a,;:'onomatopoeia metonymic metronymic paraclete parousia pauline exegesis' +a=: a,(<"0 ] 20 ?@$ 100) +x test y [ x=: a{~ 811 2?@$ #a [ y=: a{~ 947 2 ?@$#a +y test y + +x test y [ x=: 811 0$a: [ y=: 947 0$a: +y test y + +NB. mapped boxed arrays + +0!:0 <testpath,'gmbx.ijs' +q=: x=: (811 2 ?@$ #u){u=: 17 3;(<"0] 30 ?@$ 100), (<5!:2 <'mean'), ;:'Cogito, ergo sum.' +r=: y=: (547 2 ?@$ #u){u + +(mbxcheck_jmf_ q), q test y +(mbxcheck_jmf_ r), x test r +(mbxcheck_jmf_ q), q test r +(mbxcheck_jmf_ q), q test q + + +4!:55 ;:'a f f1 g mean test u x y' + +
new file mode 100644 --- /dev/null +++ b/test/gibst.ijs @@ -0,0 +1,41 @@ +NB. i.!.0 and associates timing tests ----------------------------------- + +L=: 1 : 0 +: + f=: x&u + assert. (threshold*{.t) <: -/}.t=: 10 timer 'f y','x u y',:'/:x' + 1 +) + +R=: 1 : 0 +: + f=: u&y + assert. (threshold*{.t) <: -/}.t=: 10 timer 'f x','x u y',:'/:y' + 1 +) + +x=: <"1 ] 23 2 ?@$ 100 +y=: <"1 ] 3581 2 ?@$ 100 + +y i.!.0 L x +y i:!.0 L x +NB. x -.!.0 R y NB. does not use prehasing as of 2005-11-16 +x e.!.0 R y + +x (e.!.0 i. 0: ) R y +x (e.!.0 i. 1: ) R y +x (e.!.0 i: 0: ) R y +x (e.!.0 i: 1: ) R y +x ([: + / e.!.0 ) R y +x ( + /@(e.!.0)) R y +x ([: +./ e.!.0 ) R y +x ( +./@(e.!.0)) R y +x ([: *./ e.!.0 ) R y +x ( *./@(e.!.0)) R y +x ([: I. e.!.0 ) R y +x ( I. @(e.!.0)) R y + + +4!:55 ;:'f L R t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gicap.ijs @@ -0,0 +1,42 @@ +NB. I.y ----------------------------------------------------------------- + +ifb=: (# i.@#) +n=: 547 + +(I. -: ifb) n$0 +(I. -: ifb) n$1 +(I. -: ifb) ?n$2 +(I. -: ifb) ?n$100 + +1 = {. I. b. 0 + +'domain error' -: I. etx 'abc' +'domain error' -: I. etx ;:'Cogito, ergo sum.' + + +NB. I.@~: y ------------------------------------------------------------- + +f=: ((= i.@#) # ]) @ (i.~) + +test=: 3 : 0 + yy=: y + assert. (f -: I.@~:) yy + 1 +) + +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 0 1 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: 'abcde' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: ?5$2e9 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: o.?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: j./?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: ;:' miasma chthonic chronic kakistocracy dado' +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: x: ?5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.5 [ t=: %/0 1+x:?2 5$20 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: u: ?5$65536 +test@:(t"_ {~ 877&, ?@$ (#t)"_)"0 >:i.3 5 [ t=: s:' miasma chthonic chronic kakistocracy dado' + + +4!:55 ;:'f ifb n t test yy' + +
new file mode 100644 --- /dev/null +++ b/test/gicap2.ijs @@ -0,0 +1,159 @@ +NB. x I. y -------------------------------------------------------------- + +le=: 0 1 -: /:@,: +lt=: -: < 0 1 -: /:@,: +ge=: 0 1 -: \:@,: +gt=: -: < 0 1 -: \:@,: + +test1=: 4 : 0 + xx=: /:~ y{~(353,x) ?@$ #y + yy=: y{~(419,x) ?@$ #y + t=: |. xx + i=: xx I. yy + j=: t I. yy + assert. (yy le"_1 i{xx,{:xx) +. (i=#xx) *. yy gt"_1 _ {:xx + assert. (yy gt"_1 (i-1){xx ) +. 0=i + assert. (yy ge"_1 j{t,{:t ) +. (j=#t ) *. yy lt"_1 _ {:t + assert. (yy lt"_1 (j-1){t ) +. 0=j + 1 +) + +test2=: 4 : 0 + xx=: /:~ x{~ 353 ?@$ #x + yy=: y{~ 419 ?@$ #y + t=: |. xx + i=: xx I. yy + j=: t I. yy + assert. (yy le"_1 i{xx,{:xx) +. (i=#xx)*. yy gt"_1 _ {:xx + assert. (yy gt"_1 (i-1){xx ) +. 0=i + assert. (yy ge"_1 j{t,{:t ) +. (j=#xx)*. yy lt"_1 _ {:t + assert. (yy lt"_1 (j-1){t ) +. 0=j + 1 +) + +'' test1 0 1 +2 3 test1 0 1 +'' test1 a. +2 test1 a. +4 test1 a. +8 test1 a. +11 test1 a. +'' test1 200 ?@$ 250 +5 test1 200 ?@$ 250 +'' test1 0.1 * 200 ?@$ 250 +3 test1 0.1 * 200 ?@$ 250 +'' test1 j./ 2 200 ?@$ 250 +3 test1 j./ 2 200 ?@$ 250 +'' test1 'paraskavedekatriaphobia';":&.> 200 ?@$ 250 +3 test1 'paraskavedekatriaphobia';":&.> 200 ?@$ 250 + +0 1 test2 200 ?@$ 250 +0 1 test2~ 200 ?@$ 250 +0 1 test2 0.1 * 200 ?@$ 250 +0 1 test2~0.1 * 200 ?@$ 250 +t test2 0.5 * t=: 200 ?@$ 250 +t test2~0.5 * t +t test2 x: t=: 200 ?@$ 250 +t test2~x: t +t test2 1r2 * t=: 200 ?@$ 250 +t test2~1r2 * t +a. test2 u: 1000 ?@$ 65536 +a. test2~u: 1000 ?@$ 65536 + +(20*0<x) -: (20$0) I. x=: 7 13 ?@$ 2 +(20*0<x) -: (20$0) I. x=: _5+7 13 ?@$ 10 +(20*1<x) -: (20$1) I. x=: 7 13 ?@$ 2 +(20*1<x) -: (20$1) I. x=: _5+7 13 ?@$ 10 + +(1+10<x) -: (imin,10,imax) I. x=: _11+ 7 13 ?@$ 22 +(1+10>x) -: (imax,10,imin) I. x=: _11+ 7 13 ?@$ 22 + +'domain error' -: 0 0 1 I. etx 'abcd' +'domain error' -: 0 0 1 I. etx~'abcd' +'domain error' -: 0 0 1 I. etx ;:'foo upon thee' +'domain error' -: 0 0 1 I. etx~;:'foo upon thee' +'domain error' -: 1 2 3 I. etx 'abcd' +'domain error' -: 1 2 3 I. etx~'abcd' +'domain error' -: 1 2 3 I. etx ;:'foo upon thee' +'domain error' -: 1 2 3 I. etx~;:'foo upon thee' + + +NB. x I. y mixed type --------------------------------------------------- + +p=: +/\ 1+10 ?@$ 5 +q=: _10+ 3 4 ?@$ 40 + +test3=: 3 : 0 + i=: p I. q + assert. i -: j=: (p+y) I. q + assert. i -: k=: p I. q+y + 1 +) + +test3 -~0.5 +test3 -~0j5 +test3 x: 0 +test3 -~1r5 + + +NB. x I. y model -------------------------------------------------------- + +bs=: 1 : 0 +: + i=. 0,_1+#x + while. <:/i do. + k=. <.-:+/i + b=. u y ,: k{x + i=. (i*-.b) + b*k+1 _1 + end. + 1+{:i +) + +I=: 4 : 0 + r=. 0>._1+#$x + assert. r<:#$y NB. rank error + assert. (}.$x) -: (-r){.$y NB. length error + assert. 1 [ x,y NB. domain error + ord=. /:`\: @. ({. /: 0 _1{ :: 0: x) + x ord f. bs"(_,r) y +) + +test4=: 1 : 0 + x=. 0 1 1 1 2 3 7 [ y + assert. 0 -: x u _5 + assert. 0 -: x u _4.5 + assert. (#x) -: x u 99 + assert. 4 -: x u 2 + assert. 4 -: x u 1.5 + assert. (0 0,(#x),4 4) -: x u _5 _4.5 99 2 1.5 + assert. (i.~ -: u~) x + assert. (i.~ -: u~) x=. /:~ ~. 100 ?@$ 1e6 + assert. (i.~ -: u~) x=. /:~ ~. 100 2 ?@$ 0 + assert. 0 0 0 -: '' I 'abc' + assert. (i.~ -: u~) i. 6 3 + assert. (i.~ -: u~) i. _6 3 + 1 +) + +I test4 0 +I. test4 0 + +test5=: 3 : 0 + xx=: 233 ?@$ 1500 + yy=: 263 ?@$ 3000 + 'domain error' -: xx I. etx yy +) + +test5"0 i.5 20 + +((i.0) I. 1 2 3) -: (0$a.) I. 1 2 3 +((i.0) I. 1 2 3) -: (0$a:) I. 1 2 3 +(2 3 5 7 I. i.0) -: 2 3 5 7 I. 0$a. +(2 3 5 7 I. i.0) -: 2 3 5 7 I. 0$a: + + +4!:55 ;:'bs ge gt I i j k le lt p q t' +4!:55 ;:'test1 test2 test3 test4 test5' +4!:55 ;:'x xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/gico.ijs @@ -0,0 +1,474 @@ +NB. i:y ----------------------------------------------------------------- + +(i: 5) -: _5+i.11 +(i:_5) -: 5-i.11 +(i: 0) -: ,0 + +(|.@i: -: i:@(_1 1&*&.+.))"0 (_40+?3 4$100) j. ?3 4$100 + +ico=: 3 : '(y*-*y)+i.(_1^0>y)++:y' " 0 + +(i: 5) -: ico 5 +(i: _5) -: ico _5 +(i: 0) -: ico 0 + +(#@i: -: >:@+:@| )"0 x=: _50+20?@$ 100 +(#@i: -: >:@+:@| )"0 x=: _500+20?@$1000 + +(#@i: -: >:@{:@+.)"0 x=: (_50+20 ?@$ 100) j. 1+ 20 ?@$100 +1 = #@~.@(2&(-/\))@i:"0 x + +4 = type i: 10j2 +8 = type i: 10j3 +4 = type i: 10j4 +4 = type i: 10j5 +8 = type i: 10j6 +4 = type i: 10j10 +4 = type i: 10j20 +4 = type i: _10j5 +64 = type i: 10x +64 = type i: 2*5r2 +128 = type i: 5r2 +128 = type i: _5r2 + +(i:5r2) -: i: 2.5 + +f=: 3 : 0 " 0 + n=: (?@# { ])@q: yy=: y + assert. 4=type i: yy j. n + 1 +) + +f 2+10?@$100 +f 2+10?@$1000 + +'domain error' -: i: etx 'a' +'domain error' -: i: etx 2.3 +'domain error' -: i: etx _2.3 +'domain error' -: i: etx <3 + + +NB. x i:y --------------------------------------------------------------- + +NB. Boolean +a=:1=?10 5$2 +a-:(i:~a){a +(i:~a)-:i:~<"_1 a +a-:(a i:0+a){a +a-:(a i:[&.o.a){a +a-:(a i:[&.(0j1&*)a){a +(<:#a) =a i:{:a +(#a)=a i:4 5 6 7 8 +(#a)=a i:'abcde' +(b{_1 0+#a) -: (a=:(>:?200)$0) i: b=:?30$2 + +NB. literal +a=:a.{~32+?10 5$95 +a-:(i:~a){a +(i:~a)-:i:~<"_1 a +0=a i:0{a +(#a)=a i:4 5 6 7 8 +(b{({:(a='a')#i.#a),#a) -: (a=:(>:?40)$'axy') i: (b=:?30$2){'ab' +(1|.a) -: (a i:1|.a){a=:a.{~?117 1$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 2$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 3$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 4$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 5$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 6$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 7$#a. +(1|.a) -: (a i:1|.a){a=:a.{~?117 8$#a. + +(1|.a) -: (a i: 1|.a){a=:a.{~?23000 2$#a. +(1|.a) -: (a i: 1|.a){a=:a.{~?12000 4$#a. +(1|."2 a) -: (a i:"(2) 1|."2 a){"_1 a=:a.{~?7 23000 2$#a. +(1|."2 a) -: (a i:"(2) 1|."2 a){"_1 a=:a.{~?7 12000 4$#a. + +NB. integer +a=:?10 5$100 +a-:(i:~a){a +(i:~a)-:i:~<"_1 a +a-:(a i:[&.o.a){a +a-:(a i:[&.(0j1&*)a){a +0=a i:0{a +(#a)=a i:4 5 6 7 8 +(#a)=a i:'abcde' +(b{({:(a=49)#i.#a),#a) -: (a=:(>:?40)$49 9 123) i: (b=:?40$2){49 _49 +(i.31) -: i:~2x^i. 31 +(i.31) -: i:~2x^i._31 +(30$29) -: i:~30$123456 +(30$29) -: i:~30$_12345678 +a -: (i:~a){a=:?4000$4000 NB. small integers +(1000{.a) -: (a i:1000{.a){a=:?4000$4000 NB. small integers +a -: (i:~a){a=: _5 2147483647 NB. large integers +a -: (i:~a){a=: 2 2147483647 NB. large integers +a -: (i:~a){a=: ?4000$123456 NB. large integers +(1000{.a) -: (a i:1000{.a){a=:?4000$123456 NB. large integers + +NB. floating point +a=:o._40+?10 5$100 +a-:(i: ~a){a +a-:(i:!.0~a){a +a-:(a i: [&.(0j1&*)a){a +a-:(a i:!.0 [&.(0j1&*)a){a +(i: ~a)-:i: ~<"_1 a +(i:!.0~a)-:i:!.0~<"_1 a +0=a i: 0{a +0=a i:!.0[0{a +(#a)=a i: 4 5 6 7 8 +(#a)=a i:!.0 [4 5 6 7 8 +(#a)=a i: 'abcde' +(#a)=a i:!.0 'abcde' +(b{({:(a=4.95)#i.#a),#a) -: (a=:(>:?40)$4.95 9 _1.62) i: (b=:?70$2){4.95 1234 +(b{({:(a=4.95)#i.#a),#a) -: (a=:(>:?40)$4.95 9 _1.62) i:!.0 (b=:?70$2){4.95 1234 + +NB. complex +a=:r.?10 5$1000 +a-:(i: ~a){a +a-:(i:!.0 ~a){a +(i: ~a)-:i: ~<"_1 a +(i:!.0~a)-:i:!.0~<"_1 a +0=a i: 0{a +0=a i:!.0[0{a +(#a)=a i: 4 5 6 7 8 +(#a)=a i:!.0[4 5 6 7 8 +(#a)=a i: 'abcde' +(#a)=a i:!.0 'abcde' +(b{({:(a=4j95)#i.#a),#a) -: (a=:(>:?40)$4j95 9 _1.62) i: (b=:?30$2){4j95 1234 +(b{({:(a=4j95)#i.#a),#a) -: (a=:(>:?40)$4j95 9 _1.62) i:!.0 (b=:?30$2){4j95 1234 + +NB. boxed +t=:(1=?70$3)<;.1 ?70$100 +a=:t{~?10 5$#t +a-:(i: ~a){a +a-:(i:!.0~a){a +(i: ~a)-:i: ~<"_1 a +(i:!.0~a)-:i:!.0~<"_1 a +0=a i: 0{a +0=a i:!.0[0{a +(#a)=a i: 'Cogit' +(#a)=a i:!.0 'Cogit' +(#a)=a i: 4 5 6 7 8 +(#a)=a i:!.0[4 5 6 7 8 +(b{({:(a=x)#i.#a),#a) -: (a=:(>:?40)$x,<'lieben') i: (b=:?50$2){(x=:<4;'aj95'),<1234 +((i: ~x){x) -: x=:;:'i:~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4' +((i:!.0~x){x) -: x=:;:'i:~(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4' +(20$<:#x) -: i: ~x=:(?20$3){'';($0);(0$<'') +(20$<:#x) -: i:!.0~x=:(?20$3){'';($0);(0$<'') +(20$<:#x) -: i: ~x=:(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4 +(20$<:#x) -: i:!.0~x=:(?20$3){3 4;([&.o.3 4);[&.(0j1&*)3 4 + + +NB. x i:y encore -------------------------------------------------------- + +a =: 1=?100 4$2 +j =: i:~a +j -: a i:0+a +j -: (0+a)i:a +a -: j{a +(#a) -: a i:'abcd' +(2$#a) -: a i:2 4$2 + +0 -: (i.6 2 3x)i: i. 2 3x +6 -: (i.6 2 3x)i:2 3$9 + +($0) -: (6 2 3$9)i:0 2 3$5 +(5 0 4$0) -: (6 2 3$9)i:5 0 4 2 3$5 + +5 -: (6 2 0$9)i:2 0$0 +(3$5) -: (6 2 0$9)i:3 2 0$0 +(3$5) -: (6 2 0$0.5)i:3 2 0$'a' +(3$5) -: (6 2 0$0.5)i:3 2 0$<'' + +(($b)$0) -: '' i:b=:'abc' +(($b)$0) -: ($0) i:b=:i. 3 4x +(($b)$0) -: (0$<'') i:b=:+&.>i.3 4x +0 0 -: (i.0 3 4x)i:b=:i.2 3 4x + +3 3 3 3 3 -: (i.3 4x ) i: 5 4$'a' +3 3 3 3 3 -: (3 4$<'a') i: 5 4$'a' + +test=: 3 : 0 + n=. ?y + x=. ?n$10>.<.n%3 + y=. x+2.5-2.5 + ((~.x)-:~.y),((~:x)-:~:y),((x i: x) -: y i: y) +) + +test 1000 +test 1000 +test 1000 + +*./@test"0 [4 5$1000 + +2 2 2 -: (i.2 3) i: etx i.3 4 +2 2 2 -: (i.2 3) i: etx 3 4$'a' +2 2 2 -: (i.2 3) i: etx 3 4$;:'Cogito, erogeneous' +3 3 -: (2 3 4$'x') i:"2 etx 'kakistocracy' + +2 -: (i.2 3) i: etx 4 +3 3 -: (2 3 4 6$'x') i:"3 etx 'lieben' + + +NB. x i:y for strings x and y ------------------------------------------- + +map =: 3 : '(i.#y) (a.i.y)}256$#y' +ciof =: a.&i.@] { map@[ + +f =: i: -: ciof + +((?3000$256){a.) f (?4 80$256){a. +((?3000$256){a.) f (? 300$256){a. + + +NB. x i:y on boxed numerics --------------------------------------------- + +1 1 -: i: ~<"0 [ 1,1-2^_45 +1 1 -: i: ~<"0 |.1,1-2^_45 +0 1 -: i:!.0~<"0 [ 1,1-2^_45 +0 1 -: i:!.0~<"0 |.1,1-2^_45 + +(i:~t) -: (2*#x)$(#x)+i:~x [ t=:(<"0 x), <"0 x=:?180$90 +(i:~t) -: (2*#x)$(#x)+i:~x [ t=:(<"0 x), <"0 (o.1)%~o.x=:?180$90 +(i:~t) -: (2*#x)$(#x)+i:~x [ t=:(<"0 x),~<"0 (o.1)%~o.x=:?180$90 + +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.0, x=:?40$2 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.345,x=:?40$2 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3.5,x=:?40$2 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3j5,x=:?40$2 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.0, x=:?40$2e9 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.345,x=:?40$2e9 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3.5,x=:?40$2e9 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3j5,x=:?40$2e9 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.0, x=:o.?40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.345,x=:o.?40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3.5,x=:o.?40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3j5,x=:o.?40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.0, x=:j./?2 40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.345,x=:j./?2 40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3.5,x=:j./?2 40$2e7 +(2$<i:~x) -: (y i:<"0 x); (<"0 x)i:y=:<"0 }.3j5,x=:j./?2 40$2e7 + + +NB. x i:"r y ------------------------------------------------------------ + +g =: 4 : 'x i: y' + +(i.3 0) (g"1 -: i:"1) i.3 2 +(i.3 0) (g"1 -: i:"1) i.3 0 +(i.0 0) (g"1 -: i:"1) i.0 7 +(i.0 7) (g"1 -: i:"1) i.0 3 +(i.3) (g"1 -: i:"1) i.0 7 +(i.3) (g"1 -: i:"1) i.0 0 +'' (g"1 -: i:"1) i.0 7 +'' (g"1 -: i:"1) i.0 5 +'' (g"1 -: i:"1) i.0 0 +(i.3 5) (g"1 -: i:"1) 3 7$'a' +(i.3 5) (g"1 -: i:"1) 3 7$<5 +'abc' (g"1 -: i:"1) 7 5$3 +'abc' (g"1 -: i:"1) 7 5$<3 + +(i.6) -: x i:"1 0 (<0 1)|:x=:a.{~6 16$32+96?96 +(15-i.6) -: x i:"1 0 (<0 1)|:|."1 x +(6$0) -: x i:"1 0 {."1 x +(6$15) -: x i:"1 0 {:"1 x +(($x)$i.16) -: x i:"1 x +(x=:0=5|?20 19$2) (g"1 -: i:"1) 1 + +x=:a.{~?(117 7,c)$#a. [ c=:3 +x (g"2 -: i:"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:4 +x (g"2 -: i:"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:11 +x (g"2 -: i:"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:"_1) y=:a.{~?(117, c)$#a. + +x=:p+?117 7$q [ p=:0 [ q=:14 +x (g"1 -: i:"1 ) y=:p+?q +x (g"1 -: i:"1 ) x +x (g"1 -: i:"1 ) y=:p+?117 3$q +x (g"1 -: i:"1 ) y=:p+?12$q +x (g"_1 -: i:"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_7 [ q=:14 +x (g"1 -: i:"1 ) y=:p+?q +x (g"1 -: i:"1 ) x +x (g"1 -: i:"1 ) y=:p+?117 3$q +x (g"1 -: i:"1 ) y=:p+?12$q +x (g"_1 -: i:"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_2000 [ q=:14 +x (g"1 -: i:"1 ) y=:p+?q +x (g"1 -: i:"1 ) x +x (g"1 -: i:"1 ) y=:p+?117 3$q +x (g"1 -: i:"1 ) y=:p+?12$q +x (g"_1 -: i:"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:0 [ q=:1e4 +x (g"1 -: i:"1 ) y=:p+?q +x (g"1 -: i:"1 ) x +x (g"1 -: i:"1 ) y=:p+?117 3$q +x (g"1 -: i:"1 ) y=:p+?12$q +x (g"_1 -: i:"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_5e5 [ q=:1e6 +x (g"1 -: i:"1 ) y=:p+?q +x (g"1 -: i:"1 ) x +x (g"1 -: i:"1 ) y=:p+?117 3$q +x (g"1 -: i:"1 ) y=:p+?12$q +x (g"_1 -: i:"_1) y=:p+?117$q + +x=:?7 63 3$q=:4 +x (g"2 -: i:"2 ) y=:((?10$63){0{x),?14 3$q +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:(?~1{$y){"2 y=:x,"2?7 5 3$q +x (g"_1 -: i:"_1) y=:((?5$63){1{x),?2 3$q + +x=:o.?7 13 3$q=:3 +x (g"2 -: i:"2 ) y=:((?10$13){0{x),o.?14 3$q +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:(?~1{$y){"2 y=:x,"2 o.?7 5 3$q +x (g"_1 -: i:"_1) y=:((?5$13){1{x),o.?2 3$q + +x=:r.?7 13 3$q=:3 +x (g"2 -: i:"2 ) y=:((?10$13){0{x),r.?14 3$q +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:(?~1{$y){"2 y=:x,"2 r.?7 5 3$q +x (g"_1 -: i:"_1) y=:((?5$13){1{x),r.?2 3$q + +x=:<"0 ?7 63 3$q=:3 +x (g"2 -: i:"2 ) y=:((?10$63){0{x),<"0?14 3$q +x (g"2 -: i:"2 ) x +x (g"2 -: i:"2 ) y=:(?~1{$y){"2 y=:x,"2<"0?7 5 3$q +x (g"_1 -: i:"_1) y=:((?5$63){1{x),<"0?2 3$q + +x (g"1 2 -: i:"1 2) x=:1 2,:3 4 + + +NB. x i:!.0 "r y -------------------------------------------------------- + +g =: 4 : 'x i:!.0 y' + +(i.3 0) (g"1 -: i:!.0"1) i.3 2 +(i.3 0) (g"1 -: i:!.0"1) i.3 0 +(i.0 0) (g"1 -: i:!.0"1) i.0 7 +(i.0 7) (g"1 -: i:!.0"1) i.0 3 +(i.3) (g"1 -: i:!.0"1) i.0 7 +(i.3) (g"1 -: i:!.0"1) i.0 0 +'' (g"1 -: i:!.0"1) i.0 7 +'' (g"1 -: i:!.0"1) i.0 5 +'' (g"1 -: i:!.0"1) i.0 0 +(i.3 5) (g"1 -: i:!.0"1) 3 7$'a' +(i.3 5) (g"1 -: i:!.0"1) 3 7$<5 +'abc' (g"1 -: i:!.0"1) 7 5$3 +'abc' (g"1 -: i:!.0"1) 7 5$<3 + +(i.6) -: x i:!.0"1 0 (<0 1)|:x=:a.{~6 16$32+96?96 +(15-i.6) -: x i:!.0"1 0 (<0 1)|:|."1 x +(6$0) -: x i:!.0"1 0 {."1 x +(6$15) -: x i:!.0"1 0 {:"1 x +(($x)$i.16) -: x i:!.0"1 x +(x=:0=5|?20 19$2) (g"1 -: i:!.0"1) 1 + +x=:a.{~?(117 7,c)$#a. [ c=:3 +x (g"2 -: i:!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:!.0"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:4 +x (g"2 -: i:!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:!.0"_1) y=:a.{~?(117, c)$#a. +x=:a.{~?(117 7,c)$#a. [ c=:11 +x (g"2 -: i:!.0"2 ) y=:a.{~?(14, c)$#a. +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:a.{~?(117 3,c)$#a. +x (g"_1 -: i:!.0"_1) y=:a.{~?(117, c)$#a. + +x=:p+?117 7$q [ p=:0 [ q=:14 +x (g"1 -: i:!.0"1 ) y=:p+?q +x (g"1 -: i:!.0"1 ) x +x (g"1 -: i:!.0"1 ) y=:p+?117 3$q +x (g"1 -: i:!.0"1 ) y=:p+?12$q +x (g"_1 -: i:!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_7 [ q=:14 +x (g"1 -: i:!.0"1 ) y=:p+?q +x (g"1 -: i:!.0"1 ) x +x (g"1 -: i:!.0"1 ) y=:p+?117 3$q +x (g"1 -: i:!.0"1 ) y=:p+?12$q +x (g"_1 -: i:!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_2000 [ q=:14 +x (g"1 -: i:!.0"1 ) y=:p+?q +x (g"1 -: i:!.0"1 ) x +x (g"1 -: i:!.0"1 ) y=:p+?117 3$q +x (g"1 -: i:!.0"1 ) y=:p+?12$q +x (g"_1 -: i:!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:0 [ q=:1e4 +x (g"1 -: i:!.0"1 ) y=:p+?q +x (g"1 -: i:!.0"1 ) x +x (g"1 -: i:!.0"1 ) y=:p+?117 3$q +x (g"1 -: i:!.0"1 ) y=:p+?12$q +x (g"_1 -: i:!.0"_1) y=:p+?117$q +x=:p+?117 7$q [ p=:_5e5 [ q=:1e6 +x (g"1 -: i:!.0"1 ) y=:p+?q +x (g"1 -: i:!.0"1 ) x +x (g"1 -: i:!.0"1 ) y=:p+?117 3$q +x (g"1 -: i:!.0"1 ) y=:p+?12$q +x (g"_1 -: i:!.0"_1) y=:p+?117$q + +x=:?7 63 3$q=:4 +x (g"2 -: i:!.0"2 ) y=:((?10$63){0{x),?14 3$q +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:(?~1{$y){"2 y=:x,"2?7 5 3$q +x (g"_1 -: i:!.0"_1) y=:((?5$63){1{x),?2 3$q + +x=:o.?7 13 3$q=:3 +x (g"2 -: i:!.0"2 ) y=:((?10$13){0{x),o.?14 3$q +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:(?~1{$y){"2 y=:x,"2 o.?7 5 3$q +x (g"_1 -: i:!.0"_1) y=:((?5$13){1{x),o.?2 3$q + +x=:r.?7 13 3$q=:3 +x (g"2 -: i:!.0"2 ) y=:((?10$13){0{x),r.?14 3$q +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:(?~1{$y){"2 y=:x,"2 r.?7 5 3$q +x (g"_1 -: i:!.0"_1) y=:((?5$13){1{x),r.?2 3$q + +x=:<"0 ?7 63 3$q=:3 +x (g"2 -: i:!.0"2 ) y=:((?10$63){0{x),<"0?14 3$q +x (g"2 -: i:!.0"2 ) x +x (g"2 -: i:!.0"2 ) y=:(?~1{$y){"2 y=:x,"2<"0?7 5 3$q +x (g"_1 -: i:!.0"_1) y=:((?5$63){1{x),<"0?2 3$q + +x (g"1 2 -: i:!.0"1 2) x=:1 2,:3 4 + + +NB. x i: y for floats --------------------------------------------------- + +f=: 4 : 0 + ct=: x + y -: (i:!.ct~ y){y +) + +(2^-34+-:i.3 10) f"0 1 x=: 0.001 * _1e5 + ?777$2e5 + +f1=: 3 : 0 + t -: (i:~ t){t=. y+i.1000 +) + +f1"0] 10^i.2 10 + +f2=: 3 : 0 + t -: (i:~ t){t=. y+?~1000 +) + +f2"0] 10^i.2 10 + + +4!:55 ;:'a b c ciof ct f f1 f2 g ico j map n p q t test x y yy' + +
new file mode 100644 --- /dev/null +++ b/test/giconv.ijs @@ -0,0 +1,53 @@ +NB. almost integers as integer arguments -------------------------------- + +f=: 3 : 0 " 0 + yy=: y + assert. 1: >:^:yy 0 + assert. 1: yy $ 4 + assert. 1: yy # 4 + assert. 1: yy{ i.120 + assert. 1: yy{.1 2 3 + assert. 1: yy}.1 2 3 + assert. 1: +"yy 1 + assert. 1: i. yy + assert. 1: i: yy + 1 +) + +e=: 1e_14 + +f (1+e)*x=: >:20 ?@$100 +f (1-e)*x + +1 [ 1 +: (1+e),1-e +1 [ 1 +:~(1+e),1-e +1 [ 1 *: (1+e),1-e +1 [ 1 *:~(1+e),1-e + +1 [ ( 1+e) $. 1 2 3 +1 [ ( 1-e) $. 1 2 3 +1 [ (2*1+e) $. $. 100 ?@$ 2 +1 [ (2*1-e) $. $. 100 ?@$ 2 +1 [ (3*1+e) $. $. 100 ?@$ 2 +1 [ (3*1-e) $. $. 100 ?@$ 2 + +1 [ (2*1+e)|. i.24 +1 [ (2*1-e)|. i.24 + +1 [ (2*1+e)|.!.0 i.24 +1 [ (2*1-e)|.!.0 i.24 + +1 [ (2 1*1+e)|: i.2 3 4 +1 [ (2 1*1-e)|: i.2 3 4 + +1 [ <;.(1*1+e) ' chthonic' +1 [ <;.(1*1-e) ' chthonic' +1 [ <;.(2*1+e) ' chthonic' +1 [ <;.(2*1-e) ' chthonic' +1 [ <;.(3*1+e) ' chthonic' +1 [ <;.(3*1-e) ' chthonic' + + +4!:55 ;:'e f x yy' + +
new file mode 100644 --- /dev/null +++ b/test/gif.ijs @@ -0,0 +1,133 @@ +NB. if/else ------------------------------------------------------------- + +fa =. 3 : 'if. y do. 1 else. 0 end.' + +1 = fa 1 +1 = fa 1 0 0 0 +1 = fa 1 2 3 + +1 = fa 2 +1 = fa 2 3 4 +1 = fa 3 4$5 0 +1 = fa _1 0 0 + +1 = fa 1 2.5 +1 = fa 0.05 +1 = fa _1 0 2.5 + +1 = fa 1 3j4 +1 = fa 0j1 + +1 = fa '0' +1 = fa (16$0){a. +1 = fa 'abcd' +1 = fa 0 1 2{a. +1 = fa <0 + +1 = fa 0;0;1 +1 = fa i.0 +1 = fa '' +1 = fa o.i.4 0 3 + +0 = fa 0 +0 = fa 0 1 1 1 +0 = fa 0 1 2 +0 = fa i.2 3 4 +0 = fa o.i.2 3 +0 = fa 0 3j4 +0 = fa 0 0 0 +0 = fa 3 4$0 1 +0 = fa 3 4$0 _2 +0 = fa 3 4$0 3.4 5 +0 = fa 2 3$0 4j5 + +fb =. 3 : 0 + if. + t=.y+5 + t>10 + do. + 1 + else. + 0 + end. +) + +1 = fb 5.5 +1 = fb 6+i.2 3 +0 = fb 4.2 +0 = fb 5 6 7 + +fc =. 3 : 0 + 'zero' + if. y do. 'one' end. +) + +'one' -: fc 1 +'one' -: fc 2 +'zero' -: fc 0 +'zero' -: fc 0 1 2 + +fd =. 3 : 0 + if. + 'zero' + y + do. + 'one' + end. +) + +'one' -: fd 1 +'one' -: fd 2 +(i.0 0) -: fd 0 +(i.0 0) -: fd 0 1 2 + +fe =. 3 : '''result'' if. y do. end.' +'result' -: fe 0 +'result' -: fe 1 +'result' -: fe 1 0 2 0 + +ff =. 3 : 'if. do. 1 2 3 end.' +1 2 3 -: ff 0 +1 2 3 -: ff 4 5 +1 2 3 -: ff 'abc' + +fg =. 3 : 0 + if. 0=y do. 'zero' + elseif. 1=y do. 'one' + elseif. 2=y do. 'two' + elseif. 1 do. 'big' end. +) + +'zero' -: fg 0 +'one' -: fg 1 +'two' -: fg 2 +'big' -: fg 3 +'big' -: fg 17.5 +'big' -: fg 'abc' + +fi =. 3 : 'if. y do. ''good'' return. end. ''bad''' + +'good' -: fi 1 2 3 +'good' -: fi 1 +'bad' -: fi 0 + +fj =. 3 : 'if. 23=y do. ''is 23'' else. ''not 23'' end.' +'is 23' -: fj 23 +'not 23' -: fj 17 + +fk =. 3 : 'if. (4-4)+23=y do. ''is 23'' else. ''not 23'' end.' +'is 23' -: fk 23 +'not 23' -: fk 17 + +fl =. 3 : 'if. (4.5-4.5)+23=y do. ''is 23'' else. ''not 23'' end.' +'is 23' -: fl 23 +'not 23' -: fl 17 + +fm =. 3 : 'if. (4j5-4j5)+23=y do. ''is 23'' else. ''not 23'' end.' +'is 23' -: fm 23 +'not 23' -: fm 17 + + +4!:55 ;:'fa fb fc fd fe ff fg fi fj fk fl fm t ' + +
new file mode 100644 --- /dev/null +++ b/test/gimaxmin.ijs @@ -0,0 +1,39 @@ +NB. i.<./ --------------------------------------------------------------- + +test=: 3 : 0 + yy=: y + assert. ((i.<./)yy) -: yy i.<./yy + assert. ((i.>./)yy) -: yy i.>./yy + assert. ((i:<./)yy) -: yy i:<./yy + assert. ((i:>./)yy) -: yy i:>./yy + 1 +) + +test 1e3 ?@$ imax +test - 1e3 ?@$ imax +test (<.imax%_2) + 1e3 ?@$ imax +test 1e3 $ imax +test 1e3 $ imin + +test 1e3 ?@$ 0 +test - 1e3 ?@$ 0 +test _10p1 + 1e3 ?@$ 60 +test 1e3 $ 1.234 +test 1e3 $ _1.234 + +test 1e3 ?@$ 2 +test 1e3 $ 0 +test 1e3 $ 1 + +test i.0 +test 0$0.5 +test 100 3 ?@$ 4 + +'domain error' -: (i.<./) etx 'abc' +'domain error' -: (i.<./) etx 1j2 3 4 +'domain error' -: (i.<./) etx 1;2;3 4 + + +4!:55 ;:'test yy' + +
new file mode 100644 --- /dev/null +++ b/test/gintdiv.ijs @@ -0,0 +1,82 @@ +NB. integer division and remainder -------------------------------------- + +f1=: 4 : 0 + assert. ( x <.@% y) -: <. x % y + assert. ( x <.@% -y) -: <. x % -y + assert. ((-x) <.@% y) -: <.(-x) % y + assert. ((-x) <.@% -y) -: <.(-x) % -y + assert. ( x >.@% y) -: >. x % y + assert. ( x >.@% -y) -: >. x % -y + assert. ((-x) >.@% y) -: >.(-x) % y + assert. ((-x) >.@% -y) -: >.(-x) % -y + 1 +) + +( 300 ?@$ 100) f1 32 +(32*300 ?@$ 100) f1 32 +( 300 ?@$ 100) f1 17 +(17*300 ?@$ 100) f1 17 + +( 2 300 ?@$ 100) f1 32 17 +( 2 300 ?@$ 100) f1~32 17 +(32*2 300 ?@$ 100) f1 32 17 +(32*2 300 ?@$ 100) f1~32 17 +(17*2 300 ?@$ 100) f1 32 17 +(17*2 300 ?@$ 100) f1~32 17 + +3 : 0 '' + if. -. IF64 do. + imax f1 32 + imax f1~32 + imax f1 17 + imax f1~17 + imax f1 32 17 + imax f1~32 17 + imin f1 32 + imin f1~32 + imin f1 17 + imin f1~17 + imin f1 32 17 + imin f1~32 17 + end. + 1 +) + +f2=: 4 : 0 + assert. (x|t) -: t - x * t <.@% x [ t=. y + assert. (x|t) -: t - x * t <.@% x [ t=. -y + 1 +) + +(2^i.12) f2"0 _ y=: 400 ?@$ 200 +(2^i.12) f2"0 _ y=: 400 ?@$ 2e5 + +3 : 0 '' + if. -. IF64 do. + (2^i.12) f2"0 _ imin,_1 0 1,imax + (2^i.12) f2"0 _~imin,_1 0 1,imax + end. + 1 +) + +f3=: 4 : 0 + assert. ((0,x)#: y) -: (<. y %x),"0 x| y + assert. ((0,x)#:-y) -: (<.(-y)%x),"0 x|-y + 1 +) + +(2^i.12) f3"0 _ y=: 4000 ?@$ 200 +(2^i.12) f3"0 _ y=: 4000 ?@$ 2e5 + +3 : 0 '' + if. -. IF64 do. + (2^i.12) f3"0 _ imin,_1 0 1,imax + end. + 1 +) + + +4!:55 ;:'f f1 f2 f3 y' + + +
new file mode 100644 --- /dev/null +++ b/test/gintg.ijs @@ -0,0 +1,134 @@ +NB. scalar function integrals ------------------------------------------- + +I =: 1 : 'x d. _1' +D =: 1 : 'x d. 1' + +t =: 5e_11 +z =: (% |) j./ 16384 %~ _5e5 + 2 4 5 ?@$ 1e6 NB. data for testing +test =: 1 : 'x I D -: x"0' NB. use as f test z + +testlr =: 1 : '(u testl y) , (u testr y)' + +testl=: 1 : 0 + assert. t > | ( u - u I D) y + assert. t > | (<: @u - <: @u I D) y + assert. t > | (>: @u - >: @u I D) y + assert. t > | (+: @u - +: @u I D) y + assert. t > | (- @u - - @u I D) y + assert. t > | (-. @u - -. @u I D) y + assert. t > | (-: @u - -: @u I D) y + assert. t > | (j. @u - j. @u I D) y + assert. t > | (0.3&+@u - 0.3&+@u I D) y + assert. t > | (+&0.3@u - +&0.3@u I D) y + assert. t > | (0.3&-@u - 0.3&-@u I D) y + assert. t > | (-&0.3@u - -&0.3@u I D) y + assert. t > | (0.3&*@u - 0.3&*@u I D) y + assert. t > | (*&0.3@u - *&0.3@u I D) y + assert. t > | (%&0.3@u - %&0.3@u I D) y + assert. t > | (0.4 _0.3&p. @u - (0.4 _0.3&p.) @u I D) y + assert. t > | ((0.5"0 + 0.7"0 * ])@u - (0.5"0 + 0.7"0 * ])@u I D) y + 1 +) + +testr=: 1 : 0 + assert. t > | (u - u I D) y + assert. t > | (u@<: - u@<: I D) y + assert. t > | (u@>: - u@>: I D) y + assert. t > | (u@+: - u@+: I D) y + assert. t > | (u@- - u@- I D) y + assert. t > | (u@-. - u@-. I D) y + assert. t > | (u@-: - u@-: I D) y + assert. t > | (u@j. - u@j. I D) y + assert. t > | (u@(0.3&+) - u@(0.3&+) I D) y + assert. t > | (u@(+&0.3) - u@(+&0.3) I D) y + assert. t > | (u@(0.3&-) - u@(0.3&-) I D) y + assert. t > | (u@(-&0.3) - u@(-&0.3) I D) y + assert. t > | (u@(0.4&*) - u@(0.4&*) I D) y + assert. t > | (u@(*&0.5) - u@(*&0.5) I D) y + assert. t > | (u@(%&3) - u@(%&3) I D) y + assert. t > | (u@(0.4 _0.3&p.) - u@(0.4 _0.3&p.) I D) y + assert. t > | (u@(0.5"0 + 0.7"0 * ]) - u@(0.5"0 + 0.7"0 * ]) I D) y + 1 +) + +<: testlr z +>: testlr z ++: testlr z +*: testlr z +- testlr z +-. testlr z +-: testlr z +%: testlr z +^ testlr z +^. testlr z +] testlr z +[ testlr z +j. testlr z +o. testlr z +r. testlr z +_9: testlr z +_8: testlr z +_7: testlr z +_6: testlr z +_5: testlr z +_4: testlr z +_3: testlr z +_2: testlr z +_1: testlr z +0: testlr z +1: testlr z +2: testlr z +3: testlr z +4: testlr z +5: testlr z +6: testlr z +7: testlr z +8: testlr z +9: testlr z + ++ ~ testlr z +* ~ testlr z +- ~ testlr z +% ~ testlr z +^.~ testlr z + +3&! testlr z +1&o. testlr z +2&o. testlr z +3&o. testlr z +5&o. testlr z +6&o. testlr z +7&o. testlr z + +*: @(1&o.) testlr z +^&2@(1&o.) testlr z +^&3@(1&o.) testlr z +^&4@(1&o.) testlr z +^&5@(1&o.) testlr z + +*: @(2&o.) testlr z +^&2@(2&o.) testlr z +^&3@(2&o.) testlr z +^&4@(2&o.) testlr z +^&5@(2&o.) testlr z + +*: @(3&o.) testlr z +^&2@(3&o.) testlr z +^&3@(3&o.) testlr z +^&4@(3&o.) testlr z +^&5@(3&o.) testlr z + +*: @(7&o.) testlr z +^&2@(7&o.) testlr z +^&3@(7&o.) testlr z +^&4@(7&o.) testlr z +^&5@(7&o.) testlr z + +*: @^. testlr z +^&2@^. testlr z +^&3@^. testlr z +^&4@^. testlr z +^&5@^. testlr z + + +4!:55 ;:'D I t test testl testlr testr z'
new file mode 100644 --- /dev/null +++ b/test/gintovfl.ijs @@ -0,0 +1,238 @@ +NB. integer operations -------------------------------------------------- + +B =: IF64{31 63 + +V =: 1 : 'x ; x& x:' +E =: 1 : 'x -: x&.x:' +EI=: 1 : 'x E *. 4&=@type@:x' +C =: 1 : 'x E *. x E~' +CI=: 1 : 'x C *. 4&=@type@:x' +xi=: x:^:_1 + +permute=: ?~@# { ] + + +NB. integers remain as integers ---------------------------------------- + +<: EI imax +>: EI imin + +f=: 3 : 0 + xx=: y $ xi imax <.@% x: y + assert. +/ EI xx + assert. +/\ EI xx + assert. +/\. EI xx + assert. +/ EI -xx + assert. +/\ EI -xx + assert. +/\. EI -xx + assert. +/ EI yy=: permute , xx ,. - (#xx) ?@$ 100 + assert. +/\ EI yy + assert. +/\. EI yy + assert. +/ EI yy=: permute , (-xx) ,. (#xx) ?@$ 100 + assert. +/\ EI yy + assert. +/\. EI yy + assert. +/ EI yy=: permute , xx (- ,. ]) (#xx) ?@$ 100 + assert. +/\ EI yy + assert. +/\. EI yy + assert. +/ EI yy=: permute , (-xx) (+ ,. ]) (#xx) ?@$ 100 + assert. +/\ EI yy + assert. +/\. EI yy + 1 +) + +f 3 +f 4 +f"0 >: 5 ?@$ 100 + ++: EI x=: xi imax <.@% 2x ++: EI x=: xi imin >.@% 2x + +f=: 3 : 0 + n=: <. (0=(2^.yy)|B) -~ yy ^. imax [ yy=: y + assert. */ EI xx=: n $ yy + assert. */\ EI xx + assert. */\. EI xx + assert. */ EI xx=: permute yy * n$1 _1 + assert. */\ EI xx + assert. */\. EI xx + assert. */ EI xx=: permute n # q: yy + assert. */\ EI xx + assert. */\. EI xx + assert. */ EI xx=: (1,0=(<:#xx) ?@$ 10) */;.1 xx + assert. */\ EI xx + assert. */\. EI xx + 1 +) + +f"0 <. (2+10 ?@$ 20) %: imax +f"0 <. 2^1+i.20 +f"0 ] 2 + 10 ?@$ 100 +f"0 ] 2 + 10 ?@$ 1000 + +*/ EI x=: B$_2 +*/ EI x=: (1,0=(B-1) ?@$ 4) */;.1 B$_2 +*/\ EI x=: B$_2 +*/\ EI x=: (1,0=(B-1) ?@$ 4) */;.1 B$_2 +*/\. EI x=: B$_2 +*/\. EI x=: (1,0=(B-1) ?@$ 4) */;.1 B$_2 + +*: EI x=: <. (%:2) * 2^IF64{15 31 +*: EI x=: >. - (%:2) * 2^IF64{15 31 + +- EI imin+1 2 3 +- EI imax-1 2 3 + +-. EI imin + 2 + +| EI x=: imin + 1+10 ?@$ 100 + ++/ .* EI x=: (n,n) $ <. n %: imax % !n=: 3 ++/ .* EI x=: (n,n) ?@$ <. n %: imax % !n=: 5 + +-/ .* EI x=: 10 2 2 ?@$ <. 2 %: imax + +#. EI x=: ( IF64{31 63) $ 1 +#. EI x=: (2 3 4,IF64{31 63) ?@$ 2 + +0 _1 + CI imax +1 + CI imax-1 +x + CI imax - x=: 10 ?@$ 10 +x + CI imax - x=: 10 ?@$ 1e6 +0 + CI imax,imin +0 1 + CI imin +1 + CI imin+1 +(-x) + CI imin + x=: 10 ?@$ 10 +(-x) + CI imin + x=: 10 ?@$ 1e6 +imin + CI imax + +imax +. CI x=: imin +imax +. CI x=: 0 1,imax +imax +. CI x=: q: imax +imax +. CI x=: q: imax +imin +. CI x=: 1 _1 +imin +. CI x=: 1 2 4 8 16 +imin +. CI x=: <. 2^i.IF64{30 62 + +0 - EI x=: imax +imax - EI x=: 10 ?@$ 100 +imax - EI x=: 10 ?@$ 1e6 +x - EI imax [ x=: 10 ?@$ 5 +x - EI imax [ x=: 10 ?@$ 100 +x - EI imax [ x=: 10 ?@$ 1e6 +imin - EI 0 +imin - EI x=: - 10 ?@$ 5 +imin - EI x=: - 10 ?@$ 100 +imin - EI x=: - 10 ?@$ 1e6 +imin - EI x=: - imax +x - EI imin [ x=: - 1 + 10 ?@$ 5 +x - EI imin [ x=: - 1 + 10 ?@$ 100 +x - EI imin [ x=: - 1 + 10 ?@$ 1e6 + +0 1 _1 * CI imax +0 1 * CI imin +2 * CI xi imax <.@% 2x +x * CI xi imax <.@% x: x=: 1+20 ?@$ 10 +x * CI xi imax <.@% x: x=: 1+100 ?@$ 100 +2 * CI xi imin >.@% 2x +x * CI xi imin >.@% x: x=: 1+20 ?@$ 10 +x * CI xi imin >.@% x: x=: 1+100 ?@$ 100 + +imax *. CI 1,q: imax +imin *. CI <. 2^ 10 ?@$ IF64{30 62 + +imax | EI imin +imin | EI imax + +n #. EI 1 $~ <. n ^. 1 + imax * _1 + n=: 2 +n #. EI 1 $~ <. n ^. 1 + imax * _1 + n=: 3 +n #. EI 1 $~ <. n ^. 1 + imax * _1 + n=: 4 +n #. EI 1 $~ <. n ^. 1 + imax * _1 + n=: 5 +n (#. $&1:)"0 EI x=: <.n^.1+imax*_1+n=: 2+10 ?@$ 100 + +x +/ .* CI y [ x=: 2$1 [ y=: 2$xi imax <.@% 2x +x +/ .* CI y [ x=: 3$1 [ y=: 3$xi imax <.@% 3x +1 1 +/ .* CI y=: 1,imax-1 +1 1 +/ .* CI y=: 1,imax-2 +1 1 +/ .* CI y=: 1,imax-3 + +(2 - 1 1) +/@:* CI 1,imax-1 +(2 - 1 1) +/@:* CI 1,imax-2 +_1 2 +/@:* CI 1,x:^:_1 <.imax%2x + + +NB. integers overflowing into doubles ----------------------------------- + +- E imin + +imax + C x=: 10 ?@$ 100 +imin + C x=: - 10 ?@$ 100 +(-x) + C imin + x=: 10 ?@$ 100 + +imin +. C imin +imin +. C 0 + +imax - E _1 +imax - E x=: - 10 ?@$ 100 +imin - E x=: 10 ?@$ 100 + +_1 * C imin +imax * C x=: _50 + 10 ?@$ 100 +imin * C x=: _50 + 10 ?@$ 100 + +| E imin + +-/ .* E x=: (=i.2) * >. 2 %: imax +-/ .* E x=: 10 2 2 ?@$ <. 2^IF64{17 33 + +x +/ .* C y [ x=: 4 1 1 1 1 [ y=: 0 _1 0 1,imax +x +/ .* C y [ x=: 4 1 1 1 2 [ y=: 0 0 0 0,imax +x +/ .* C y [ x=: 4 1 1 1 1 [ y=: 0 _1 0 _1,imin +x +/ .* C y [ x=: 4 1 1 1 _1 [ y=: 0 0 0 0,imin +x +/ .* E y [ x=: 4 1 1 1 1 (?7)}7 5 ?@$ 100 [ y=: (0 _1 0 1,imax) (<a:;?11)}5 11 ?@$ 100 +x +/ .* E y [ x=: 4 1 1 1 2 (?7)}7 5 ?@$ 100 [ y=: (0 0 0 0,imax) (<a:;?11)}5 11 ?@$ 100 +x +/ .* E y [ x=: 4 1 1 1 1 (?7)}7 5 ?@$ 100 [ y=: (0 _1 0 _1,imin) (<a:;?11)}5 11 ?@$ 100 +x +/ .* E y [ x=: 4 1 1 1 _1 (?7)}7 5 ?@$ 100 [ y=: (0 0 0 0,imin) (<a:;?11)}5 11 ?@$ 100 + + +NB. integers overflowing into doubles, asm routines --------------------- + +f=: 1 : 0 +: + 'A bg'=. x [ nn=.y + assert. u f. E"1 data=: A i} bg {~( nn,nn) ?@$ #bg [ i=. ,&.>~ i.nn + assert. u f. E"2 data=: A i} bg {~((*:nn),nn,nn) ?@$ #bg [ i=. (i.*:nn),&.>,{i.&.>nn,nn + assert. u"1 f. E"2 data + 1 +) + +(imax; 1000 ?@$ 1e4) +/ f"1 0 >: i.7 +(imax; 1000 ?@$ 1e4) +/\ f"1 0 >: i.7 +(imax; 1000 ?@$ 1e4) +/\. f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) +/ f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) +/\ f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) +/\. f"1 0 >: i.7 + +(imax; 1 2) */ f"1 0 >: i.7 +(imax; 1 2) */\ f"1 0 >: i.7 +(imax; 1 2) */\. f"1 0 >: i.7 +(imin; 1 2) */ f"1 0 >: i.7 +(imin; 1 2) */\ f"1 0 >: i.7 +(imin; 1 2) */\. f"1 0 >: i.7 + +(imax; 1000 ?@$ 1e4) -/ f"1 0 >: i.7 +(imax; 1000 ?@$ 1e4) -/\ f"1 0 >: i.7 +(imax; 1000 ?@$ 1e4) -/\. f"1 0 >: i.7 +(imax;-1000 ?@$ 1e4) -/ f"1 0 >: i.7 +(imax;-1000 ?@$ 1e4) -/\ f"1 0 >: i.7 +(imax;-1000 ?@$ 1e4) -/\. f"1 0 >: i.7 +(imin; 1000 ?@$ 1e4) -/ f"1 0 >: i.7 +(imin; 1000 ?@$ 1e4) -/\ f"1 0 >: i.7 +(imin; 1000 ?@$ 1e4) -/\. f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) -/ f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) -/\ f"1 0 >: i.7 +(imin;-1000 ?@$ 1e4) -/\. f"1 0 >: i.7 + + +4!:55 ;:'B C CI data E EI f n nn permute V x xi xx y yy' + +
new file mode 100644 --- /dev/null +++ b/test/giph.ijs @@ -0,0 +1,116 @@ +NB. prehashed i. family of functions ------------------------------------ + +g=: 4 : 0 + xx=: y{~(1e4,x) ?@$ #y + yy=: y{~(1e3,x) ?@$ #y + ss=: y{~( x) ?@$ #y + fidot=: xx&i. + fico =: xx&i: + fedot=: e.&xx + assert. (fidot yy) -: xx i. yy + assert. (fico yy) -: xx i: yy + assert. (fedot yy) -: yy e. xx + assert. (fidot ss) -: xx i. ss + assert. (fico ss) -: xx i: ss + assert. (fedot ss) -: ss e. xx + 1 +) + +h=: 4 : 0 + xx=: y{~(1e4,x) ?@$ #y + yy=: y{~(1e3,x) ?@$ #y + ss=: y{~( x) ?@$ #y + fidot=: xx&(i.!.0) + fico =: xx&(i:!.0) + fedot=: e.!.0&xx + assert. (fidot yy) -: xx i. yy + assert. (fico yy) -: xx i: yy + assert. (fedot yy) -: yy e. xx + assert. (fidot ss) -: xx i. ss + assert. (fico ss) -: xx i: ss + assert. (fedot ss) -: ss e. xx + 1 +) + +'' g 0 1 +2 3 g 0 1 +31 g 0 1 + +'' g a. +2 3 g a. +37 g a. + +'' g u: 1000 ?@# 256 +2 3 g u: 1000 ?@# 256 +13 g u: 1000 ?@# 256 +'' g u: 1000 ?@# 65536 +2 3 g u: 1000 ?@# 65536 +13 g u: 1000 ?@# 65536 + +'' g 1000 ?@$ 0 +2 3 g 1000 ?@$ 0 + +'' h 1000 ?@$ 0 +2 3 h 1000 ?@$ 0 + +'' g j./ _1e4+2 1000 ?@$ 2e4 +2 3 g j./ _1e4+2 1000 ?@$ 2e4 + +'' h j./ _1e4+2 1000 ?@$ 2e4 +2 3 h j./ _1e4+2 1000 ?@$ 2e4 + +'' g x: 1000 ?@$ 3e3 +2 3 g x: 1000 ?@$ 3e3 + +'' g %/ x: 0 1 + 2 1000 ?@$ 3e3 +2 3 g %/ x: 0 1 + 2 1000 ?@$ 3e3 + +'' g ;:'Cogito, ergo sum. 4 20 and 10 years ago' +1 2 g ;:'Cogito, ergo sum. 4 20 and 10 years ago' + +'' g s: ' Cogito ergo sum 4 20 and 10 years ago kakistocracy' +2 3 g s: ":&.> 20 ?@$1000 + +'' g 1000 ?@$ m=: 1e1 +'' g m -~ 1000 ?@$ 2*m +'' g 1000 ?@$ m=: 1e3 +'' g m -~ 1000 ?@$ 2*m +'' g 1000 ?@$ m=: 1e5 +'' g m -~ 1000 ?@$ 2*m +'' g 1000 ?@$ m=: 1e7 +'' g m -~ 1000 ?@$ 2*m +'' g 1000 ?@$ m=: 1e9 +'' g m -~ 1000 ?@$ 2*m + +2 3 g 1000 ?@$ m=: 1e1 +2 3 g m -~ 1000 ?@$ 2*m +2 3 g 1000 ?@$ m=: 1e3 +2 3 g m -~ 1000 ?@$ 2*m +2 3 g 1000 ?@$ m=: 1e5 +2 3 g m -~ 1000 ?@$ 2*m +2 3 g 1000 ?@$ m=: 1e7 +2 3 g m -~ 1000 ?@$ 2*m +2 3 g 1000 ?@$ m=: 1e9 +2 3 g m -~ 1000 ?@$ 2*m + +x=: 10 ?@$2 +f=: x&i. +(i.~x) -: f x+0 +(i.~x) -: f x+-~0.1 +(i.~x) -: f x+-~0j1 +(i.~x) -: f x+-~1x +(i.~x) -: f x+-~1r2 + +((i.7 2) -. 2 3) -: -.& 2 3 i. 7 2 +((i.7 2) -. ,:2 3) -: -.&(,:2 3) i. 7 2 + +'rank error' -: (i.3 4)&i. etx 7 + +'length error' -: (i.3 4)&i. etx i.5 +'length error' -: (i.3 4)&i. etx i.2 5 + + +4!:55 ;:'f fedot fico fidot g h m ss x xx yy' + + + \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/gipht.ijs @@ -0,0 +1,63 @@ +NB. prehashed i. family of functions ------------------------------------ + +f0=: 4 : 0 + f=: x&i. + assert. </ (1,threshold) %~ t=: timer 'f y',:'x i. y' + 1 +) + +x f0 0+x=: 1e4 ?@$ m=: 1e1 +x f0 0+x=: m -~ 1e4 ?@$ 2*m +x f0 0+x=: 1e4 ?@$ m=: 1e3 +x f0 0+x=: m -~ 1e4 ?@$ 2*m +x f0 0+x=: 1e4 ?@$ m=: 1e5 +x f0 0+x=: m -~ 1e4 ?@$ 2*m +x f0 0+x=: 1e4 ?@$ m=: 1e7 +x f0 0+x=: m -~ 1e4 ?@$ 2*m +x f0 0+x=: 1e4 ?@$ m=: 1e9 +x f0 0+x=: m -~ 1e4 ?@$ 2*m + +x f0 1=x=: 1e6 ?@$ 2 +x f0 1=x=: 1e4 4 ?@$ 2 +x f0 0+x=: 1e4 ?@$ 1e9 +x f0 0+x=: 1e4 4 ?@$ 1e9 +x f0 0+x=: 1e4 ?@$ 0 +x f0 0+x=: 1e4 4 ?@$ 0 +x f0 0+x=: j./_1e4+2 1e4 ?@$ 2e4 +x f0 0+x=: j./_1e4+2 1e4 4 ?@$ 2e4 +x f0 0+x=: x: 1e4 ?@$ 3e3 +x f0 0+x=: x: 1e4 4 ?@$ 3e3 +x f0 0+x=: %/x:0 1+2 1e4 ?@$ 3e3 +x f0 0+x=: %/x:0 1+2 1e4 4 ?@$ 3e3 + +NB. possible garbage collect can louse up timing +(x=: a.{~ 1e4 ?@$ #a. ) f0 :: 1: y=: a.{~ 1e4 ?@$ #a. + +(x=: a.{~ 1e4 4 ?@$ #a. ) f0 y=: a.{~ 1e4 4 ?@$ #a. +(x=: u: 1e4 ?@$ 256 ) f0 y=: u: 1e4 ?@$ 256 +(x=: u: 1e4 4 ?@$ 256 ) f0 y=: u: 1e4 4 ?@$ 256 +(x=: u: 1e4 ?@$ 65536) f0 y=: u: 1e4 ?@$ 65536 +(x=: u: 1e4 4 ?@$ 65536) f0 y=: u: 1e4 4 ?@$ 65536 + +mean=: +/ % # + +g=: 4 : 0 + xx=: x ?@$ y + yy=: 10000 ?@$ y + f=: xx&i. + timer '3 : ''for_q. y do. k=. f q end.'' yy' +) + +f1=: 3 : 0 + t=: (2e4*>:i.8) g"0 y + assert. (1-threshold) > >./| t (- % ]) mean t + 1 +) + + +f1"0 ]1e1 1e3 1e5 1e7 1e9 + + +4!:55 ;:'f f0 f1 g m mean t x xx y yy' + + \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/giscode.ijs @@ -0,0 +1,22 @@ +NB. i. special code ----------------------------------------------------- + +test=: 2 : 0 +: + assert. x (u -: v) y + assert. y (u -: v) x + 1 +) + +1 2 3 (e.i.1: ) test (4 : '(x e. y)i.1') '' +1 2 3 (e.i.0: ) test (4 : '(x e. y)i.0') '' +1 2 3 (e.i:1: ) test (4 : '(x e. y)i:1') '' +1 2 3 (e.i:0: ) test (4 : '(x e. y)i:0') '' +1 2 3 (+ /@e. ) test (4 : '+ /x e. y' ) '' +1 2 3 (+./@e. ) test (4 : '+./x e. y' ) '' +1 2 3 (*./@e. ) test (4 : '*./x e. y' ) '' +1 2 3 (I. @e. ) test (4 : 'I. x e. y' ) '' + + +4!:55 ;:'test' + +
new file mode 100644 --- /dev/null +++ b/test/git.ijs @@ -0,0 +1,63 @@ +NB. x i. y timing tests ------------------------------------------------- + +ss =: +/ @: *: +rsq=: [: -. ss@(- +/ % #)@[ %~ ss@:- + +f=: 3 : 0 + 10 timer 's i. t' [ s=. y$2 [ t=. y$3 +) + +x =: 7000+2000 * i.10 +y =: f"0 x +y1=: (1,.x) +/ .* y %. 1,.x +threshold < y rsq y1 + +f=: 4 : 0 + 10 timer 'i.~t' [ t=.a.{~(y,x)?@$#a. +) + +n=: 2000*4+i.8 +y=: (>:i.15) f"0/ n +y1=: y (] +/ .*"2 1 %."1 2) n^/0 1 +threshold < (+/ % #), y rsq"1 y1 + +f=: 3 : 0 + 5 timer 'i.~t' [ t=. y ?@$ y +) + +n=: 8000*4+i.8 +y=: f"0 n +y1=: y (] +/ .*"2 1 %."1 2) n^/0 1 +threshold < y rsq y1 + +f=: 3 : 0 + 5 timer 'i.~t' [ t=. 0.001*_5e5+y?@$1e6 +) + +n=: 8000*4+i.8 +y=: f"0 n +y1=: y (] +/ .*"2 1 %."1 2) n^/0 1 +threshold < y rsq y1 + +f1=: 3 : 0 + ".'timer ''i.~x'' [ x=. y+i.',"1 ":,.n +) + +f2=: 3 : 0 + ".'timer ''i:~x'' [ x=. y+i.',"1 ":,.n +) + +n=: 1000 * 1 2 3 4 5 6 7 14 21 + +y=: f1"0 (0 0.5 1.5 +/10^i.14),1.1 1x1 1p1 */ 10^i.14 +y1=: y (] +/ .*"_ 1 %."1 2) n^/0 1 +threshold < (+/ % #), y rsq"1 y1 + +y=: f2"0 (0 0.5 1.5 +/10^i.14),1.1 1x1 1p1 */ 10^i.14 +y1=: y (] +/ .*"_ 1 %."1 2) n^/0 1 +threshold < (+/ % #), y rsq"1 y1 + + +4!:55 ;:'f f1 f2 n rsq ss x y y1' + +
new file mode 100644 --- /dev/null +++ b/test/gix.ijs @@ -0,0 +1,166 @@ +NB. x i.y with wrong rank/shape ----------------------------------------- + +f0=: 4 : 0 + assert. ( 7$3) -: ( 3 4 $x) i. 7 2$y + assert. (5 7$3) -: (5 3 4 $x) i."2 ]5 7 2$y + assert. (5 7$3) -: ( 3 4 $x) i."2 ]5 7 2$y + assert. (5 7$3) -: (5 3 4 $x) i."2 ] 7 2$y + assert. 3 -: ( 3 4 2$x) i. 7 2$y + assert. (5 $3) -: (5 3 4 2$x) i."3 2 ]5 7 2$y + assert. (5 $3) -: ( 3 4 2$x) i."3 2 ]5 7 2$y + assert. (5 $3) -: (5 3 4 2$x) i."3 2 ] 7 2$y + 1 +) + +f1=: 4 : 0 + assert. ( 7$3) -: ( 3 4 $x) i: 7 2$y + assert. (5 7$3) -: (5 3 4 $x) i:"2 ]5 7 2$y + assert. (5 7$3) -: ( 3 4 $x) i:"2 ]5 7 2$y + assert. (5 7$3) -: (5 3 4 $x) i:"2 ] 7 2$y + assert. 3 -: ( 3 4 2$x) i: 7 2$y + assert. (5 $3) -: (5 3 4 2$x) i:"3 2 ]5 7 2$y + assert. (5 $3) -: ( 3 4 2$x) i:"3 2 ]5 7 2$y + assert. (5 $3) -: (5 3 4 2$x) i:"3 2 ] 7 2$y + 1 +) + +f2=: 4 : 0 + assert. ( 7$0) -: ( 7 2$x) e. 3 4 $y + assert. (5 7$0) -: ( 7 2$x) e."2 ]5 3 4 $y + assert. (5 7$0) -: (5 7 2$x) e."2 ] 3 4 $y + assert. (5 7$0) -: ( 7 2$x) e."2 ]5 3 4 $y + assert. 0 -: ( 7 2$x) e. 3 4 2$y + assert. (5 $0) -: (5 7 2$x) e."2 3 ]5 3 4 2$y + assert. (5 $0) -: ( 7 2$x) e."2 3 ]5 3 4 2$y + assert. (5 $0) -: (5 7 2$x) e."2 3 ] 3 4 2$y + 1 +) + +f3=: 4 : 0 + assert. ( 3 4 $x) -: ( 3 4 $x) -. 7 2$y + assert. (5 3 4 $x) -: (5 3 4 $x) -."2 ]5 7 2$y + assert. (5 3 4 $x) -: ( 3 4 $x) -."2 ]5 7 2$y + assert. (5 3 4 $x) -: (5 3 4 $x) -."2 ] 7 2$y + assert. ( 3 4 2$x) -: ( 3 4 2$x) -. 7 2$y + assert. (5 3 4 2$x) -: (5 3 4 2$x) -."3 2 ]5 7 2$y + assert. (5 3 4 2$x) -: ( 3 4 2$x) -."3 2 ]5 7 2$y + assert. (5 3 4 2$x) -: (5 3 4 2$x) -."3 2 ] 7 2$y + 1 +) + +f4=: 4 : 0 + assert. ( 0$0) -: ( 7 2$x) I.@e. 3 4 $y + assert. (5 0$0) -: ( 7 2$x) I.@e."2 ]5 3 4 $y + assert. (5 0$0) -: (5 7 2$x) I.@e."2 ] 3 4 $y + assert. (5 0$0) -: ( 7 2$x) I.@e."2 ]5 3 4 $y + assert. ( 0$0) -: ( 7 2$x) I.@e. 3 4 2$y + assert. (5 0$0) -: (5 7 2$x) I.@e."2 3 ]5 3 4 2$y + assert. (5 0$0) -: ( 7 2$x) I.@e."2 3 ]5 3 4 2$y + assert. (5 0$0) -: (5 7 2$x) I.@e."2 3 ] 3 4 2$y + 1 +) + +f5=: 4 : 0 + assert. ( 0) -: ( 7 2$x) *./@e. 3 4 $y + assert. (5$0) -: ( 7 2$x) *./@e."2 ]5 3 4 $y + assert. (5$0) -: (5 7 2$x) *./@e."2 ] 3 4 $y + assert. (5$0) -: ( 7 2$x) *./@e."2 ]5 3 4 $y + assert. ( 0) -: ( 7 2$x) *./@e. 3 4 2$y + assert. (5$0) -: (5 7 2$x) *./@e."2 3 ]5 3 4 2$y + assert. (5$0) -: ( 7 2$x) *./@e."2 3 ]5 3 4 2$y + assert. (5$0) -: (5 7 2$x) *./@e."2 3 ] 3 4 2$y + 1 +) + +f6=: 4 : 0 + assert. ( 0) -: ( 7 2$x) +./@e. 3 4 $y + assert. (5$0) -: ( 7 2$x) +./@e."2 ]5 3 4 $y + assert. (5$0) -: (5 7 2$x) +./@e."2 ] 3 4 $y + assert. (5$0) -: ( 7 2$x) +./@e."2 ]5 3 4 $y + assert. ( 0) -: ( 7 2$x) +./@e. 3 4 2$y + assert. (5$0) -: (5 7 2$x) +./@e."2 3 ]5 3 4 2$y + assert. (5$0) -: ( 7 2$x) +./@e."2 3 ]5 3 4 2$y + assert. (5$0) -: (5 7 2$x) +./@e."2 3 ] 3 4 2$y + 1 +) + +f7=: 4 : 0 + assert. ( 0) -: ( 7 2$x) +/@e. 3 4 $y + assert. (5$0) -: ( 7 2$x) +/@e."2 ]5 3 4 $y + assert. (5$0) -: (5 7 2$x) +/@e."2 ] 3 4 $y + assert. (5$0) -: ( 7 2$x) +/@e."2 ]5 3 4 $y + assert. ( 0) -: ( 7 2$x) +/@e. 3 4 2$y + assert. (5$0) -: (5 7 2$x) +/@e."2 3 ]5 3 4 2$y + assert. (5$0) -: ( 7 2$x) +/@e."2 3 ]5 3 4 2$y + assert. (5$0) -: (5 7 2$x) +/@e."2 3 ] 3 4 2$y + 1 +) + +f8=: 4 : 0 + assert. ( 0) -: ( 7 2$x) (e.i.0:) 3 4 $y + assert. (5$0) -: ( 7 2$x) (e.i.0:)"2 ]5 3 4 $y + assert. (5$0) -: (5 7 2$x) (e.i.0:)"2 ] 3 4 $y + assert. (5$0) -: ( 7 2$x) (e.i.0:)"2 ]5 3 4 $y + assert. ( 0) -: ( 7 2$x) (e.i.0:) 3 4 2$y + assert. (5$0) -: (5 7 2$x) (e.i.0:)"2 3 ]5 3 4 2$y + assert. (5$0) -: ( 7 2$x) (e.i.0:)"2 3 ]5 3 4 2$y + assert. (5$0) -: (5 7 2$x) (e.i.0:)"2 3 ] 3 4 2$y + 1 +) + +f9=: 4 : 0 + assert. ( 7) -: ( 7 2$x) (e.i.1:) 3 4 $y + assert. (5$7) -: ( 7 2$x) (e.i.1:)"2 ]5 3 4 $y + assert. (5$7) -: (5 7 2$x) (e.i.1:)"2 ] 3 4 $y + assert. (5$7) -: ( 7 2$x) (e.i.1:)"2 ]5 3 4 $y + assert. ( 1) -: ( 7 2$x) (e.i.1:) 3 4 2$y + assert. (5$1) -: (5 7 2$x) (e.i.1:)"2 3 ]5 3 4 2$y + assert. (5$1) -: ( 7 2$x) (e.i.1:)"2 3 ]5 3 4 2$y + assert. (5$1) -: (5 7 2$x) (e.i.1:)"2 3 ] 3 4 2$y + 1 +) + +fa=: 4 : 0 + assert. 6 -: 0 i:~ (7 2$x) e. 3 4 $y + assert. 6 -: ( 7 2$x) (e.i:0:) 3 4 $y + assert. (5$6) -: ( 7 2$x) (e.i:0:)"2 ]5 3 4 $y + assert. (5$6) -: (5 7 2$x) (e.i:0:)"2 ] 3 4 $y + assert. (5$6) -: ( 7 2$x) (e.i:0:)"2 ]5 3 4 $y + assert. ( 0) -: ( 7 2$x) (e.i:0:) 3 4 2$y + assert. (5$0) -: (5 7 2$x) (e.i:0:)"2 3 ]5 3 4 2$y + assert. (5$0) -: ( 7 2$x) (e.i:0:)"2 3 ]5 3 4 2$y + assert. (5$0) -: (5 7 2$x) (e.i:0:)"2 3 ] 3 4 2$y + 1 +) + +fb=: 4 : 0 + assert. 7 -: 1 i:~ (7 2$x) e. 3 4$y + assert. 7 -: ( 7 2$x) (e.i:1:) 3 4 $y + assert. (5$7) -: ( 7 2$x) (e.i:1:)"2 ]5 3 4 $y + assert. (5$7) -: (5 7 2$x) (e.i:1:)"2 ] 3 4 $y + assert. (5$7) -: ( 7 2$x) (e.i:1:)"2 ]5 3 4 $y + assert. 1 -: 1 i:~ (7 2$x) e. 3 4 2$y + assert. 1 -: ( 7 2$x) (e.i:1:) 3 4 2$y + assert. (5$1) -: (5 7 2$x) (e.i:1:)"2 3 ]5 3 4 2$y + assert. (5$1) -: ( 7 2$x) (e.i:1:)"2 3 ]5 3 4 2$y + assert. (5$1) -: (5 7 2$x) (e.i:1:)"2 3 ] 3 4 2$y + 1 +) + +f0&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f1&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f2&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f3&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f4&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f5&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f6&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f7&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f8&>/~ 0;'a';4;4.5;4j5;4x;4r5 +f9&>/~ 0;'a';4;4.5;4j5;4x;4r5 +fa&>/~ 0;'a';4;4.5;4j5;4x;4r5 +fb&>/~ 0;'a';4;4.5;4j5;4x;4r5 + + +4!:55 ;:'f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb' + +
new file mode 100644 --- /dev/null +++ b/test/gj.ijs @@ -0,0 +1,51 @@ +NB. j. ------------------------------------------------------------------ + +jdot =. 0j1&* + +(j. -: jdot) 0.1*_500+?10 20$1000 +(j. -: jdot) (?40$100)*^0j1*?40$100 + +a =. 0.1 * _500 + ?10 20$1000 +b =. 0.1 * _500 + ?10 20$1000 +(a j. b) -: a+0j1*b +(a j.&(^@j.) b) -: (^0j1*a)+0j1*^0j1*b +(3 j. b ) -: 3+0j1*b +(a j. _4) -: a+0j1*_4 + +a -: [ &. j. a + +'domain error' -: j. etx 'abc' +'domain error' -: j. etx <'abc' + +'domain error' -: 'abc' j. etx 3 +'domain error' -: 'abc' j.~etx 3 +'domain error' -: 4 j. etx <'abc' +'domain error' -: 4 j.~etx <'abc' + +'length error' -: 3 4 j. etx 5 6 7 +'length error' -: 3 4 j.~etx 5 6 7 +'length error' -: 3 4 j. etx i.3 4 +'length error' -: 3 4 j.~etx i.3 4 + + +NB. complex numbers ----------------------------------------------------- + +type =. 3!:0 + +16 = type 3j4 +9j8 -: +/2j3 7j5 +2j_3 -: +2j3 + +_5j_2 -: -/2j3 7j5 +_2j_3 -: -2j3 + +_1j31 -: */2j3 7j5 +(*2j3) -: (%|) 2j3 +t -: *t=.0 0j1 _1 0j_1 1 + +(29j11%74) -: %/2j3 7j5 +(2j_3%13) -: %2j3 + +4!:55 ;:'a b jdot t' + +
new file mode 100644 --- /dev/null +++ b/test/glco.ijs @@ -0,0 +1,56 @@ +NB. f L: n -------------------------------------------------------------- + +Level =: 2 : 0 + m=. 0{ 3&$&.|. n + ly=. L. y if. 0>m do. m=.0>.m+ly end. + if. m>:ly do. u y else. u Level m&.> y end. + : + 'l r'=. 1 2{ 3&$&.|. n + lx=. L. x if. 0>l do. l=.0>.l+lx end. + ly=. L. y if. 0>r do. r=.0>.r+ly end. + b=. (l,r)>:lx,ly + if. b-: 0 0 do. x u Level(l,r)&.> y + elseif. b-: 0 1 do. x u Level(l,r)&.><y + elseif. b-: 1 0 do. (<x) u Level(l,r)&.> y + elseif. 1 do. x u y + end. +) + +totient=: * -.@%@~.&.q: +a =: 5!:2 <'totient' + +test=: 4 : '(0: L: x y) -: (0: Level x y)' + +(i:5) test"0 _ a +_ test a +__ test a + +test=: 4 : '(2 # L: x y) -: (2 # Level x y)' +0 1 2 test"0 _ a + +((5;2) # L: 0 a) -: (5;2) # Level 0 a +((5;2) # L: _1 a) -: (5;2) # Level _1 a + +f=: 4 : '<^:(1+x) ?y$1000' +a=: (?3 5$10) f"0 ?3 5$30 +(+ / L: 0 a) -: + / Level 0 a +(>./ L: 0 a) -: >./ Level 0 a +((+/ % #) L: 0 a) -: (+/ % #) Level 0 a +(a + L: 0 a) -: a + Level 0 a + +'domain error' -: ex '1 2 3 L: 4' +'domain error' -: ex '<: L: ''abc''' +'domain error' -: ex '<: L: (<123) ' +'domain error' -: ex '<: L: 3.4 ' +'domain error' -: ex '<: L: 3j4 ' + +'length error' -: ex '<: L: 1 2 3 4' +'length error' -: ex '<: L: (i.0) ' +'length error' -: ex '<: L: '''' ' + +'rank error' -: ex '<: L: (i.1 2)' + + +4!:55 ;:'a f Level test totient' + +
new file mode 100644 --- /dev/null +++ b/test/gldot.ijs @@ -0,0 +1,34 @@ +NB. L. y ---------------------------------------------------------------- + +open =: 32&~: @ (3!:0) +mt =: 0&e. @ $ +level =: >:@(>./)@($:&>"_)@, ` 0: @. (open +. mt) + +(L. -: level) ?10 3$2 +(L. -: level) 'sui generis' +(L. -: level) ?25$1000 +(L. -: level) o.?2 7 3$10000 +(L. -: level) r./?2 4 5$1000 + +(L. -: level) 0 2 1$1 0 +(L. -: level) 2 0$'sui generis' +(L. -: level) 3 4 5 0$25 +(L. -: level) 0 0$o.1 +(L. -: level) 0$3j4 +(L. -: level) 0$;:'Cogito, ergo sum.' + +f=: 3 : '<^:(>:y) 123' +g=: >:@(>./)@, +(g -: L.@f) ?2 3 4$20 +(g -: L.@f) ?20$20 +(g -: L.@f) ?1 3 3 1$15 + +totient=: * -.@%@~.&.q: +a =: 5!:2 <'totient' +4 -: L. a +(L. -: level) a + + +4!:55 ;:'a f g level mt open totient' + +
new file mode 100644 --- /dev/null +++ b/test/glocale.ijs @@ -0,0 +1,550 @@ +NB. locatives ----------------------------------------------------------- + +ab__=: x=: ?20$1e9 +x -: ab__ +x -: ab_base_ +(<'base') e. 4!:1 [6 +-.a: e. 4!:1 [6 +(,<,'z') -: 18!:2 <'base' + +not_a_locative=: x=: ?4 5$1e9 +x -: not_a_locative + +'ill-formed name' -: ex 'abc_' + +'ill-formed name' -: ex 'abc__d_e_=: 5' +'ill-formed name' -: ex 'abc_34e_ =: 5' +'ill-formed name' -: ex 'abc___d =: 5' +'ill-formed name' -: ex 'abc_012_ =: 5' + + +NB. indirect reference -------------------------------------------------- + +ab_xyz_ =: x =: ?20$1e9 +x -: ab_xyz_ +indirect=: <'xyz' +x -: ab__indirect +a__indirect=: y=: ?20$1e6 +y -: a_xyz_ + +c=: <'charlie' +b_charlie_=: <'baker' +a__b__c =: y=: ?20$1e6 +y -: a__b__c +y -: a_baker_ +d=: <'base' +y -: a__b__c__d +f=: 3 : 'a__b__c__local [ local=.<''base''' +y -: f 0 + +a_z_=: x=: ?20$1e6 +x -: a__k [ k=: <'huh' + +'value error' -: ex 'ab__huh' +'value error' -: ab__k etx [ k=: <'huh' + +'rank error' -: ex 'ab__k' [ k=: 'xyz' +'rank error' -: ex 'ab__k' [ k=: 3$<'abc' +'rank error' -: ex 'ab__k' [ k=: 3 4$<'abc' + +'length error' -: ex 'ab__k' [ k=: <'' +'length error' -: ex 'ab__k' [ k=: <$0 + +'domain error' -: ex 'ab__k' [ k=: 0 +'domain error' -: ex 'ab__k' [ k=: 'x' +'domain error' -: ex 'ab__k' [ k=: 5 +'domain error' -: ex 'ab__k' [ k=: 5.4 +'domain error' -: ex 'ab__k' [ k=: 5j4 +'domain error' -: ex 'ab__k' [ k=: 5x +'domain error' -: ex 'ab__k' [ k=: 5r4 + +'domain error' -: ex 'ab__k' [ k=: <0 1 0 +'domain error' -: ex 'ab__k' [ k=: <i.5 +'domain error' -: ex 'ab__k' [ k=: <3.4 5 +'domain error' -: ex 'ab__k' [ k=: <3j4 5 +'domain error' -: ex 'ab__k' [ k=: <3 4 5x +'domain error' -: ex 'ab__k' [ k=: <3r4 5 +'domain error' -: ex 'ab__k' [ k=: <<'abc' + +'rank error' -: ex 'ab__k' [ k=: <2 3$'x' + +'ill-formed name' -: ex 'ab___' +'ill-formed name' -: ex 'ab__4' +'ill-formed name' -: ex 'ab__4=: 8' +'ill-formed name' -: ex '9+ab__4' +'ill-formed name' -: ex 'ab__4xy' +'ill-formed name' -: ex 'ab__a__5' +'ill-formed name' -: ex 'ab__a___b' +'ill-formed name' -: ex 'ab___cde' + +'ill-formed name' -: ex 'ab__k' [ k=: <'*(&!' +'ill-formed name' -: ex 'ab__k' [ k=: <'ab_xyz' +'ill-formed name' -: ex 'ab__k' [ k=: <'ab_xyz_' +'ill-formed name' -: ex 'ab__k' [ k=: <'ab__xyz' + +18!:55 ;:'baker charlie huh xyz' + + +NB. 18!:0 --------------------------------------------------------------- + +lnc =: 18!:0 +lcreate =: 18!:3 +ldestroy=: 18!:55 + +0 -: lnc <'base' +0 0 -: lnc <;._1 ' base z' +0 0 1 -: lnc x=:(;:'base z'),lcreate '' +_1 _1 -: lnc 'nonsuch123';'99999999' +_2 _2 -: lnc '!!#*@';'01abc' + +ldestroy {:x + +'domain error' -: lnc etx 0 1 0 +'domain error' -: lnc etx 'abc' +'domain error' -: lnc etx '123' +'domain error' -: lnc etx 1 2 3 +'domain error' -: lnc etx 1 2.3 +'domain error' -: lnc etx 1 2j3 +'domain error' -: lnc etx 1 2 3x +'domain error' -: lnc etx 1 2r3 + +'domain error' -: lnc etx 'ab';0 1 0 +'domain error' -: lnc etx 'ab';1 2 3 +'domain error' -: lnc etx 'ab';1 2.3 +'domain error' -: lnc etx 'ab';1 2j3 +'domain error' -: lnc etx 'ab';1 2 3x +'domain error' -: lnc etx 'ab';1 2r3 + +'domain error' -: 2 lnc etx <'base' + +'length error' -: lnc etx 'ab';'' +'length error' -: lnc etx 'ab';$0 + + +NB. 18!:1 --------------------------------------------------------------- + +lnc =: 18!:0 +lnl =: 18!:1 + +x=:lnl 0 1 +1 -: #$x +32 -: type x +x -: /~x +(;:'base z') e. x +2 = type&>x +1 = #@$ &>x + +0 = lnc lnl 0 +1 = lnc lnl 1 + +(lnl 0) -: lnl -~2 +(lnl 0) -: lnl -~2.5 +(lnl 0) -: lnl -~2j5 +(lnl 0) -: lnl -~2x +(lnl 0) -: lnl -~2r5 + +(lnl $0) -: lnl '' +(lnl $0) -: lnl 0$<5 + +x=: lnl 0 1 +(a lnl 0 1) -: (a e.~ {.&>x)#x [ a=: 'j' +(a lnl 0 1) -: (a e.~ {.&>x)#x [ a=: 'j0' +(a lnl 0 1) -: (a e.~ {.&>x)#x [ a=: 'zb' + +'domain error' -: lnl etx 'abc' +'domain error' -: lnl etx 1 2.3 +'domain error' -: lnl etx 1 2j3 +'domain error' -: lnl etx 1 2 3x +'domain error' -: lnl etx 1 2r3 +'domain error' -: lnl etx 0;1 + +'domain error' -: 0 1 0 lnl etx 0 +'domain error' -: 2 3 4 lnl etx 0 +'domain error' -: 2 3.4 lnl etx 0 +'domain error' -: 2 3j4 lnl etx 0 +'domain error' -: 2 3 4x lnl etx 0 +'domain error' -: 2 3r4 lnl etx 0 +'domain error' -: (<'abc')lnl etx 0 + + +NB. 18!:2 --------------------------------------------------------------- + +lpath=: 18!:2 + +y=: (+%)/\20$1r1 +a_new_ =: y +y -: a_new_ +(<;._1 ' first new') lpath <'cool' +y -: a_cool_ +a_first_=: x=:'kakistocracy kerygma' +x -: a_cool_ + +4!:55 ;:'a_new_ a_first_' + +(<'a') lpath <'cool' +('a';'bc';'d') lpath <'new' +(,<,'a') -: lpath <'cool' +(;:'a bc d') -: lpath <'new' + +(,<,'z') -: lpath <'NonExistentLocale' +(<'NonExistent') lpath <'abc' +(,<'NonExistent') -: lpath <'abc' +'' -: lpath <'z' + +(i.0 0) -: '' lpath <'asdf' +(i.0 0) -: (i.0) lpath <'asdf' +(i.0 0) -: (0$a:)lpath <'asdf' + +18!:55 ;:'a abc asdf bc cool d first new NonExistent NonExistentLocale' + +'domain error' -: lpath etx 0 1 0 +'domain error' -: lpath etx 'abc' +'domain error' -: lpath etx 2 3 4 +'domain error' -: lpath etx 2 3.4 +'domain error' -: lpath etx 2 3j4 +'domain error' -: lpath etx 2 3x +'domain error' -: lpath etx 2 3r4 +'domain error' -: lpath etx 2;3 4 + +'domain error' -: lpath etx <0 1 0 +'domain error' -: lpath etx <2 3 4 +'domain error' -: lpath etx <2 3.4 +'domain error' -: lpath etx <2 3j4 +'domain error' -: lpath etx <2 3 4x +'domain error' -: lpath etx <2 3r4 +'domain error' -: lpath etx <<'abc' +'domain error' -: lpath etx <<'234' + +'ill-formed name' -: lpath etx <'!!#+' +'ill-formed name' -: lpath etx <'abc_ju' +'ill-formed name' -: lpath etx <'abc_junk_' +'ill-formed name' -: lpath etx <'abc__j' + +'rank error' -: lpath etx <3 4$'abc' + +'length error' -: lpath etx <'' +'length error' -: lpath etx <$0 + +'domain error' -: 0 1 0 lpath etx <'z' +'domain error' -: 'abc' lpath etx <'z' +'domain error' -: 1 2 3 lpath etx <'z' +'domain error' -: 1 2.3 lpath etx <'z' +'domain error' -: 1 2j3 lpath etx <'z' +'domain error' -: 1 2 3x lpath etx <'z' +'domain error' -: 1 2r3 lpath etx <'z' + +'domain error' -: ('base';0 1 0) lpath etx <'z' +'domain error' -: ('base';1 2 3) lpath etx <'z' +'domain error' -: ('base';1 2.3) lpath etx <'z' +'domain error' -: ('base';1 2j3) lpath etx <'z' +'domain error' -: ('base';1 2x ) lpath etx <'z' +'domain error' -: ('base';1 2r3) lpath etx <'z' + +'length error' -: ('base';'' ) lpath etx <'z' +'length error' -: ('base';$0 ) lpath etx <'z' + +'rank error' -: ('base';2 3$'ab')lpath etx <'z' + +'ill-formed name' -: ('base';'!!@$') lpath etx <'z' +'ill-formed name' -: ('base';'z ') lpath etx <'z' +'ill-formed name' -: ('base';'ab_c') lpath etx <'z' + + +NB. 18!:3 --------------------------------------------------------------- + +lcreate =: 18!:3 +ldestroy=: 18!:55 +spnow =: 7!:0 + +x=: 12345 +y=: spnow '' +y=: spnow '' + +t=: lcreate '' +t e. 18!:1 [1 +0 -: #$t +32 -: type t +2 -: type x=:>t +1 -: #$x +*./ x e. '0123456789' +asdf__t=: i.1e4 +18!:55 t,;:'t x' + +x=: 12345 +x=: spnow '' +(200*1+IF64) > x-y + +(<'asdf') -: 8 lcreate <'asdf' +(<'asdf') -: 4 lcreate <'asdf' +x_asdf_=: i.1e4 +'locale error' -: 5 lcreate etx <'asdf' + +18!:55 <'asdf' + +'domain error' -: lcreate etx 0 1 +'domain error' -: lcreate etx 234 +'domain error' -: lcreate etx 2.4 +'domain error' -: lcreate etx 2j4 +'domain error' -: lcreate etx 2r4 +'domain error' -: lcreate etx 23x + +'domain error' -: lcreate etx <0 1 +'domain error' -: lcreate etx <234 +'domain error' -: lcreate etx <2.4 +'domain error' -: lcreate etx <2j4 +'domain error' -: lcreate etx <2r4 +'domain error' -: lcreate etx <23x + +'domain error' -: _34 lcreate etx <'asdf' +'domain error' -: 3.4 lcreate etx <'asdf' +'domain error' -: 3j4 lcreate etx <'asdf' +'domain error' -: 3r4 lcreate etx <'asdf' +'domain error' -: '4' lcreate etx <'asdf' +'domain error' -: (<4)lcreate etx <'asdf' + +'limit error' -: 256 lcreate etx <'asdf' + + +NB. 18!:4 --------------------------------------------------------------- + +lswitch=: 18!:4 + +f_a_ =: 3 : 0 + p=. 18!:5 '' + q=. f1_b_ 0 + r=. 18!:5 '' + p,q,r +) + +f1_b_ =: 3 : 0 + p=. 18!:5 '' + lswitch_base_ <'asdf' + q=. 18!:5 '' + p,q +) + +(<;._1 ' a b asdf a') -: x=: f_a_ 0 + +f_a_ =: 3 : 0 + p=. 18!:5 '' + q=. f1_b_ 0 + r=. 18!:5 '' + p,q,r +) + +f1_b_ =: 3 : 0 + p=. 18!:5 '' + q=. f2_c_ 0 + r=. 18!:5 '' + p,q,r +) + +f2_c_ =: 3 : 0 + p=. 18!:5 '' + 18!:4 <'asdf' + q=. 18!:5 '' + p,q +) + +(<;._1 ' a b c asdf asdf a') -: x=: f_a_ 0 + +18!:4 <'base' +(<'base') -: 18!:5 '' + +lswitch x=:<'NonExistent2' +x_base_ -: 18!:5 '' +x_base_ e. 18!:1 [0 +lswitch_base_ <'base' +(<'base') -: 18!:5 '' + +lswitch <'base' +plus_a_=: + +4 plus_a_ _3 +(<'base') -: 18!:5 '' + +18!:55 ;:'a b c asdf NonExistent2' + +'domain error' -: lswitch etx 0 +'domain error' -: lswitch etx 'a' +'domain error' -: lswitch etx 2 +'domain error' -: lswitch etx 2.3 +'domain error' -: lswitch etx 2j3 +'domain error' -: lswitch etx 2x +'domain error' -: lswitch etx 2r3 + +'domain error' -: lswitch etx <0 1 0 +'domain error' -: lswitch etx <2 3 4 +'domain error' -: lswitch etx <2 3.4 +'domain error' -: lswitch etx <2 3j4 +'domain error' -: lswitch etx <2 3x +'domain error' -: lswitch etx <2 3r4 +'domain error' -: lswitch etx <<'abc' + +'domain error' -: (<'j') lswitch etx <'abc' + +'rank error' -: lswitch etx <3 4$'a' + +'length error' -: lswitch etx <'' +'length error' -: lswitch etx <$0 + +'ill-formed name' -: lswitch etx <'!!#+' +'ill-formed name' -: lswitch etx <'abc_ju' +'ill-formed name' -: lswitch etx <'abc_junk_' +'ill-formed name' -: lswitch etx <'abc__j' + + +NB. 18!:5 --------------------------------------------------------------- + +lname=: 18!:5 + +(<'base') -: lname '' + +'rank error' -: lname etx 0 +'rank error' -: lname etx i.2 3 + +'length error' -: lname etx 2 3 4 +'length error' -: lname etx 'abc' + + +NB. 18!:55 -------------------------------------------------------------- + +lcreate =: 18!:3 +lname =: 18!:5 +ldestroy=: 18!:55 +spnow =: 7!:0 + +x=: y=: spnow '' +x=: spnow '' +-.(<'ex1') e. 18!:1 [0 +a_ex1_=: i.1e5 +extract_ex1_=: 1e4$'pericope' +(<'ex1') e. 18!:1 [0 +ldestroy <'ex1' +-.(<'ex1') e. 18!:1 [0 +y=: spnow '' +(200*1+IF64) > |x-y + +x=: y=: spnow '' +x=: spnow '' +k=: lcreate '' +k e. 18!:1 [1 +a__k=: i.1e5 +extract__k=: 1e4$'pericope' +ldestroy k +-. k e. 18!:1 [1 +'locale error' -: ex '#a__k' +'locale error' -: ex 'a__k=: i.12' +4!:55 <'k' +y=: spnow '' +(200*1+IF64) > |x-y + +x=: spnow '' +k=: lcreate"1 i.20 0 +ldestroy k +4!:55 <'k' +y=: spnow '' +(200*1+IF64) > |x-y + +1 -: ldestroy <'NoNoSuchLocale' + +k=: lcreate '' +a__k=: i.12 +ldestroy k +'locale error' -: ex 'a__k=: i.9' + +'' -: ldestroy '' +'' -: ldestroy i.0 +'' -: ldestroy 0$<'' + +g_a_=: 3 : 0 + z=. (<,'a') e. 18!:1 [0 + ldestroy_base_ <'a' + z=. z,(<,'a') e. 18!:1 [0 +) + +g_a_ 0 +-. (<,'a') e. 18!:1 [0 + +g_b_=: 3 : 0 + z=. '' + asdf_b_=: x=. ?.1000$1000 + ldestroy_base_ <'b' + z=. (<,'b') -: 18!:5 '' + z=. z,x -: ?.1000$1000 + z=. z,0 -: 4!:0 <'asdf' + z=. z,0 -: 4!:0 <'asdf_b_' +) + +h_b_ =: 3 : 0 + top_b_=: 'cacophemistic' + z=. 3 0 -: 4!:0 ;:'g_b_ top_b_' + z=.z,(<,'b') e. 18!:1 [0 + g_b_ 0 + z=.z,3 0 -: 4!:0 ;:'g_b_ top_b_' + z=.z,(<,'b') e. 18!:1 [0 +) + +h_b_ 0 +-. (<,'b') e. 18!:1 [0 +_1 -: 18!:0 <'b' +_1 _1 _1 -: 4!:0 ;:'g_b_ top_b_ h_b_' + +f0_loca_ =: 18!:5@i.@0: @ (18!:55) +(;:'base loca') -: (18!:5 ''),f0_loca_ <'loca' +_1 -: 18!:0 <'loca' + +f1_locb_ =: 18!:1@i.@2: @ (18!:55) +(<'locb') e. f1_locb_ <'locb' +_1 -: 18!:0 <'locb' + +18!:55 ;:'a b loca locb' + +'domain error' -: ldestroy etx 0 1 0 +'domain error' -: ldestroy etx 'abc' +'domain error' -: ldestroy etx 2 3 4 +'domain error' -: ldestroy etx 2 3.4 +'domain error' -: ldestroy etx 2 3j4 +'domain error' -: ldestroy etx 2 3x +'domain error' -: ldestroy etx 2 3r4 +'domain error' -: ldestroy etx 2;3 4 + +'domain error' -: ldestroy etx <0 1 0 +'domain error' -: ldestroy etx <2 3 4 +'domain error' -: ldestroy etx <2 3.4 +'domain error' -: ldestroy etx <2 3j4 +'domain error' -: ldestroy etx <2 3 4x +'domain error' -: ldestroy etx <2 3r4 +'domain error' -: ldestroy etx <<'abc' +'domain error' -: ldestroy etx <<'234' + +'ill-formed name' -: ldestroy etx <'!!#+' +'ill-formed name' -: ldestroy etx <'abc_ju' +'ill-formed name' -: ldestroy etx <'abc_junk_' +'ill-formed name' -: ldestroy etx <'abc__j' + +'rank error' -: ldestroy etx <3 4$'abc' + +'length error' -: ldestroy etx <'' +'length error' -: ldestroy etx <$0 + +'domain error' -: 3 ldestroy etx <'abc' + + +NB. locatives and 4!:5 -------------------------------------------------- + +1 [ 4!:5 [1 +a_baker_ =: i.12 +xy_z_ =: 99 +k=: 18!:3 '' +sum__k=: +/ +x=: 4!:5 [1 +4!:5 [0 +18!:55 k,<'baker' +x -: /:~ ('sum_',(":>k),'_');;:'a_baker_ k_base_ xy_z_' + + +4!:55 ;:'a a_z_ ab c d f ' +4!:55 ;:'indirect k lcreate ldestroy lname lnc lnl lpath lswitch ' +4!:55 ;:'not_a_locative spnow t test x xy_z_ y ' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx.ijs @@ -0,0 +1,21 @@ +NB. mapped boxed arrays ------------------------------------------------- + +load 'jmf' +18!:4 <'base' + +1 [ unmap_jmf_ 'q' +f=: <'q.jmf' +1 [ createjmf_jmf_ f,<4e6 NB. 4e6 bytes for data +map_jmf_ (<'q'),f,'';0 NB. map q to jmf file +'' -: q + +1 [ unmap_jmf_ 'r' +f1=: <'r.jmf' +1 [ createjmf_jmf_ f1,<7e5 +map_jmf_ (<'r'),f1,'';0 +'' -: r + +g =: 6 7 4 5 2 3 0 1&{"1 @: (5&}.) @: (3!:3) @: ({."1) +mean=: +/ % # + +
new file mode 100644 --- /dev/null +++ b/test/gmbx0.ijs @@ -0,0 +1,89 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. = ------------------------------------------------------------------- + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (=j{x) -: = j{q [ j=: ?$~#x +q=: x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (=j{x) -: = j{q [ j=: ?$~#x +q=: x=: <"0 +&.>?10 2 3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (=j{x) -: = j{q [ j=: ?$~#x + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x=j{x) -: q = j{q [ j=: ?$~#x +(mbxcheck_jmf_ q), (x=j{x) -: q = j{x +(mbxcheck_jmf_ q), (x=j{x) -: (j{q) = x +(mbxcheck_jmf_ q), (x=j{x) -: (j{q) = q +q=: x=: (?10 3$#x){x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), (x="1 j{x) -: q ="1 j{q [ j=: ?#x +(mbxcheck_jmf_ q), (x="1 j{x) -: q ="1 j{x +(mbxcheck_jmf_ q), (x="1 j{x) -: (j{q) ="1 x +(mbxcheck_jmf_ q), (x="1 j{x) -: (j{q) ="1 q + + +NB. =: ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q + +x=: 2 2 2 2 2 2 2$x +q=: 2 2 2 2 2 2 2$q +(mbxcheck_jmf_ q), x -: q + +x=: x;2 +q=: q;2 +(mbxcheck_jmf_ q), x -: q + +x=: >{.x +q=: >{.q +(mbxcheck_jmf_ q), x -: q + +x=: ,x +q=: ,q +(mbxcheck_jmf_ q), x -: q + +'allocation error' -: ex 'q=: i.&.>10^i.7' + + +NB. < ------------------------------------------------------------------- + +q=: x=: (?2 3 4$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (<x) -: <q +(mbxcheck_jmf_ q), (<"0 x) -: <"0 q +(mbxcheck_jmf_ q), (<"1 x) -: <"1 q +(mbxcheck_jmf_ q), (<"2 x) -: <"2 q + + +NB. > ------------------------------------------------------------------- + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (> x) -: > q +(mbxcheck_jmf_ q), (>{.x) -: > {. q +q=: x=: <"0 ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (>x) -: > q +(mbxcheck_jmf_ q), (>{.x) -: > {.q +x=: (<1;2;3;4) 1}x +q=: (<1;2;3;4) 1}q +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q),(>x) -: >q +q=: x=: ((<4$<'x'),<<"0 ]2 3$'abcdef') ((1;0;2);<0;1;0)} <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (>x) -: >q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx1.ijs @@ -0,0 +1,51 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. -. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{q [ j=: ?3$#q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{x +(mbxcheck_jmf_ q), (x -. j{x) -: x -. j{q +q=: x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{q [ j=: ?3$#q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{x +(mbxcheck_jmf_ q), (x -. j{x) -: x -. j{q +q=: x=: <"0 +&.>?10 2 3$5 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{q [ j=: ?3$#q +(mbxcheck_jmf_ q), (x -. j{x) -: q -. j{x +(mbxcheck_jmf_ q), (x -. j{x) -: x -. j{q + + +NB. -: ------------------------------------------------------------------ + +q=: x=: (?5 2 3$#x){x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ((0{x)-:"2 x) -: (0{q) -:"2 q +(mbxcheck_jmf_ q), ((1{x)-:"2 x) -: (1{q) -:"2 q +(mbxcheck_jmf_ q), (x -:"0 a:{x) -: x -:"0 a:{q +(mbxcheck_jmf_ q), (x -:"0 a:{x) -: q -:"0 a:{x +(mbxcheck_jmf_ q), (x -:"0 a:{x) -: q -:"0 a:{q +(mbxcheck_jmf_ q), (x -:"1 a:{x) -: x -:"1 a:{q +(mbxcheck_jmf_ q), (x -:"1 a:{x) -: q -:"1 a:{x +(mbxcheck_jmf_ q), (x -:"1 a:{x) -: q -:"1 a:{q +(mbxcheck_jmf_ q), (x -:"2 a:{x) -: x -:"2 a:{q +(mbxcheck_jmf_ q), (x -:"2 a:{x) -: q -:"2 a:{x +(mbxcheck_jmf_ q), (x -:"2 a:{x) -: q -:"2 a:{q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ((1|.x)-:"1 x)-:"1 (1|.q) -:"1 q +(mbxcheck_jmf_ q), ((1|.x)-:"2 x)-:"1 (1|.q) -:"2 q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx2.ijs @@ -0,0 +1,163 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. ^: ------------------------------------------------------------------ + +q=: x=: <13 +(>:^:x 1) -: >:^:q 1 +mbxcheck_jmf_ q + + +NB. $ ------------------------------------------------------------------- + +q=: x=: (?2 3 4$#x){x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ($x) -: $q +(mbxcheck_jmf_ q), (3$x) -: 3$q +(mbxcheck_jmf_ q), (7$x) -: 7$q +(mbxcheck_jmf_ q), (3$"0 x) -: 3$"0 q +(mbxcheck_jmf_ q), (3$"1 x) -: 3$"1 q +(mbxcheck_jmf_ q), (3$"2 x) -: 3$"2 q + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (2 5$!.y x) -: 2 5$!.y q +(mbxcheck_jmf_ q), (2 5$!.y x) -: 2 5$!.r x +(mbxcheck_jmf_ q), (2 5$!.y x) -: 2 5$!.r q + + +NB. $. ------------------------------------------------------------------ + +q=: x=: 2 3 4;0 +(1$.x) -: 1$.q +mbxcheck_jmf_ q + +y=: $. 2 3 4 5 ?@$ 5 +q=: x=: 2;0 1 +(x$.y) -: q$.y +mbxcheck_jmf_ q + + +NB. ~. ------------------------------------------------------------------ + +q=: x=: (?2 3 4$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (~. x) -: ~. q +(mbxcheck_jmf_ q), (~."0 x) -: ~."0 q +(mbxcheck_jmf_ q), (~."1 x) -: ~."1 q +(mbxcheck_jmf_ q), (~."2 x) -: ~."2 q +q=: x=: <"1 ?20 2 3$5 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (~.x) -: ~.q +(mbxcheck_jmf_ q), (~.!.0 x) -: ~.!.0 q + + +NB. ~: ------------------------------------------------------------------ + +q=: x=: (?7 2 3$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (~:j{x) -: ~: j{q [ j=: ?$~#x +(mbxcheck_jmf_ q), (~:"0 j{x) -: ~:"0 j{q +(mbxcheck_jmf_ q), (~:"1 j{x) -: ~:"1 j{q +(mbxcheck_jmf_ q), (~:"2 j{x) -: ~:"2 j{q +q=: x=: <"0 +&.>?10 2 3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (~: j{x) -: ~: j{q [ j=: ?$~#x +(mbxcheck_jmf_ q), (~:!.0 j{x) -: ~:!.0 j{q [ j=: ?$~#x + +q=: x=: (?7 2 3$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x~:j{x) -: q ~: j{q [ j=: ?$~#x +(mbxcheck_jmf_ q), (x~:"0 j{x) -: q ~:"0 j{q +(mbxcheck_jmf_ q), (x~:"1 j{x) -: q ~:"1 j{q +(mbxcheck_jmf_ q), (x~:"2 j{x) -: q ~:"2 j{q +(mbxcheck_jmf_ q), (x~:j{x) -: q ~: j{x +(mbxcheck_jmf_ q), (x~:j{x) -: (j{q) ~: x +(mbxcheck_jmf_ q), (x~:j{x) -: (j{q) ~: q +q=: x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), (x~:j{x) -: q ~: j{q [ j=: ?$~#x +(mbxcheck_jmf_ q), (x~:j{x) -: q ~: j{x +(mbxcheck_jmf_ q), (x~:j{x) -: (j{q) ~: x +(mbxcheck_jmf_ q), (x~:j{x) -: (j{q) ~: q +(mbxcheck_jmf_ q), (x~:!.0 j{x) -: (j{q) ~:!.0 q + + +NB. |. ------------------------------------------------------------------ + +q=: x=: (?30$#x){x=: <"0 (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (|.x) -: |. q +(mbxcheck_jmf_ q), (|."1 x) -: |."1 q +(mbxcheck_jmf_ q), (|."2 x) -: |."2 q + +q=: x=: (?30$#x){x=: <"0 (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 0|.x) -: 0|. q +(mbxcheck_jmf_ q), ( 1|.x) -: 1|. q +(mbxcheck_jmf_ q), (_2|.x) -: _2|. q +(mbxcheck_jmf_ q), ( 0|.!.'' x) -: 0|.!.'' q +(mbxcheck_jmf_ q), ( 1|.!.'' x) -: 1|.!.'' q +(mbxcheck_jmf_ q), (_2|.!.'' x) -: _2|.!.'' q +(mbxcheck_jmf_ q), ( 0|.!.y x) -: 0|.!.y q [ y=: <?888 +(mbxcheck_jmf_ q), ( 1|.!.y x) -: 1|.!.y q +(mbxcheck_jmf_ q), (_2|.!.y x) -: _2|.!.y q +(mbxcheck_jmf_ q), ( 0|.!.y x) -: 0|.!.y q [ y=: 0{q +(mbxcheck_jmf_ q), ( 1|.!.y x) -: 1|.!.y q +(mbxcheck_jmf_ q), (_2|.!.y x) -: _2|.!.y q +q=: x=: <"0 <"0 ? 20 2 3$4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 0|.x) -: 0|. q +(mbxcheck_jmf_ q), ( 1|.x) -: 1|. q +(mbxcheck_jmf_ q), (_2|.x) -: _2|. q +(mbxcheck_jmf_ q), ( 1|."0 x) -: 1|."0 q +(mbxcheck_jmf_ q), ( 1|."1 x) -: 1|."1 q +(mbxcheck_jmf_ q), ( 1|."2 x) -: 1|."2 q +(mbxcheck_jmf_ q), ( 0 1|.x) -: 0 1|. q +(mbxcheck_jmf_ q), ( 2 3 1|.x) -: 2 3 1|. q +(mbxcheck_jmf_ q), (j|."_1 x) -: j|."_1 q [ j=: ?(#x)$1{$x + +q=: x=: <5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (|.x) -: |.q +(mbxcheck_jmf_ q), (2|.x) -: 2|.q + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (10|.!.y x) -: 10|.!.y q +(mbxcheck_jmf_ q), (10|.!.y x) -: 10|.!.r x +(mbxcheck_jmf_ q), (10|.!.y x) -: 10|.!.r q + + +NB. |: ------------------------------------------------------------------ + +q=: x=: 3 7$(<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (|:x) -: |: q +(mbxcheck_jmf_ q), (0 1|:x) -: 0 1|: q +(mbxcheck_jmf_ q), ((<0 1)|:x) -: (<1 0)|: q +q=: x=: 2 3 7$(<"0 ?35$50),(<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (|:x) -: |: q +(mbxcheck_jmf_ q), (0 1|:x) -: 0 1|: q +(mbxcheck_jmf_ q), (1 0|:x) -: 1 0|: q +(mbxcheck_jmf_ q), (1 0|:"2 x) -: 1 0|:"2 q +(mbxcheck_jmf_ q), (2 0 1|: x) -: 2 0 1|: q +(mbxcheck_jmf_ q), ((2;0 1)|: x) -: (2;0 1)|: q +(mbxcheck_jmf_ q), ((2 0;1)|: x) -: (2 0;1)|: q + +q=: x=: 0 1;2 3 +(x|:y) -: q|:y=: ?20 3 10 7$100 +mbxcheck_jmf_ q + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx3.ijs @@ -0,0 +1,295 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. : ------------------------------------------------------------------- + +q=: x=: <"0 ?100$100 + +f=: 4 : 0 + y=. (<i.>x{y) x}y +) + +(mbxcheck_jmf_ q), x -: q + +j=: ?#x +x=: j f x +q=: j f q +(mbxcheck_jmf_ q), x -: q + +f=: 3 : 0 + y=. (-. (3{.&.>y) e. <'NB.')#y + y=. y -.&.><;:13 10{a. + y=. ;: ; y + y=. (-. ({.&>y) e. '''_0123456789')#y + y=. ~. /:~ y +) + +q=: f q=: <;._2 (1!:1) <testpath,'gmbx3.ijs' +x=: f x=: <;._2 (1!:1) <testpath,'gmbx3.ijs' +(mbxcheck_jmf_ q), x -: q + +q=: x=: 't=.y+y';'*:t' +(3 : q -: 3 : x) 2 3 13 +mbxcheck_jmf_ q + +q=: x=: 't=.y+y';'*:t';':';'x*y' +7 (3 : q -: 3 : x) 2 3 13 +mbxcheck_jmf_ q + + +NB. , ------------------------------------------------------------------- + +q=: x=: (?10 2 3$#x){x=: <"0 (<5!:2 <'g') ,;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,x) -: ,q +(mbxcheck_jmf_ q), (,"0 x) -: ,"0 q +(mbxcheck_jmf_ q), (,"1 x) -: ,"1 q +(mbxcheck_jmf_ q), (,"2 x) -: ,"2 q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,x) -: ,q +(mbxcheck_jmf_ q), (,"0 x) -: ,"0 q +(mbxcheck_jmf_ q), (,"1 x) -: ,"1 q +(mbxcheck_jmf_ q), (,"2 x) -: ,"2 q + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x, 0 3 1{x) -: q, 0 3 1{q +(mbxcheck_jmf_ q), (x,~0 3 1{x) -: q,~0 3 1{q +(mbxcheck_jmf_ q), (x, 0 1{q) -: q, 0 1{x +(mbxcheck_jmf_ q), (x,~0 1{q) -: q,~0 1{x +(mbxcheck_jmf_ q), (x, 1{x) -: q, 1{q +(mbxcheck_jmf_ q), (x,~1{x) -: q,~1{q +(mbxcheck_jmf_ q), (x, 1{q) -: q, 1{x +(mbxcheck_jmf_ q), (x,~1{q) -: q,~1{x + +q=: x=: (?10 2 3$#x){x=: (<5!:2 <'g') ,;:'Cogito, ergo sum.' +r=: y=: (?10 2 3$#y){y=: (<5!:2 <'g') ,;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x,y) -: x,r +(mbxcheck_jmf_ q), (x,y) -: q,y +(mbxcheck_jmf_ q), (x,y) -: q,r +(mbxcheck_jmf_ q), (x,"0 y) -: x,"0 r +(mbxcheck_jmf_ q), (x,"0 y) -: q,"0 y +(mbxcheck_jmf_ q), (x,"0 y) -: q,"0 r +(mbxcheck_jmf_ q), (x,"1 y) -: x,"1 r +(mbxcheck_jmf_ q), (x,"1 y) -: q,"1 y +(mbxcheck_jmf_ q), (x,"1 y) -: q,"1 r +(mbxcheck_jmf_ q), (x,"2 y) -: x,"2 r +(mbxcheck_jmf_ q), (x,"2 y) -: q,"2 y +(mbxcheck_jmf_ q), (x,"2 y) -: q,"2 r + +q=: x=: 2 3$(<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +t=: <"0 i.1 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x,!.y t) -: x,!.r t +(mbxcheck_jmf_ q), (x,!.y t) -: q,!.y t +(mbxcheck_jmf_ q), (x,!.y t) -: q,!.r t + + +NB. ,. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,. x) -: ,. q +q=: x=: (?10 2 3$#x){x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,.x) -: ,.q +(mbxcheck_jmf_ q), (,."0 x) -: ,."0 q +(mbxcheck_jmf_ q), (,."1 x) -: ,."1 q +(mbxcheck_jmf_ q), (,."2 x) -: ,."2 q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,. x) -: ,. q +(mbxcheck_jmf_ q), (,."1 x) -: ,."1 q + +q=: x=: (?10 2 3$#x){x=: (<5!:2 <'g') ,;:'Cogito, ergo sum.' +r=: y=: (?10 2 3$#y){y=: (<5!:2 <'g') ,;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x,.y) -: x,.r +(mbxcheck_jmf_ q), (x,.y) -: q,.y +(mbxcheck_jmf_ q), (x,.y) -: q,.r +(mbxcheck_jmf_ q), (x,."0 y) -: x,."0 r +(mbxcheck_jmf_ q), (x,."0 y) -: q,."0 y +(mbxcheck_jmf_ q), (x,."0 y) -: q,."0 r +(mbxcheck_jmf_ q), (x,."1 y) -: x,."1 r +(mbxcheck_jmf_ q), (x,."1 y) -: q,."1 y +(mbxcheck_jmf_ q), (x,."1 y) -: q,."1 r +(mbxcheck_jmf_ q), (x,."2 y) -: x,."2 r +(mbxcheck_jmf_ q), (x,."2 y) -: q,."2 y +(mbxcheck_jmf_ q), (x,."2 y) -: q,."2 r + +q=: x=: 5 2 3$(<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +t=: <"0 i.5 2 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x,.!.y t) -: x,.!.r t +(mbxcheck_jmf_ q), (x,.!.y t) -: q,.!.y t +(mbxcheck_jmf_ q), (x,.!.y t) -: q,.!.r t + + +NB. ,: ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,:x) -: ,:q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,: x) -: ,: q +(mbxcheck_jmf_ q), (,:"0 x) -: ,:"0 q +(mbxcheck_jmf_ q), (,:"1 x) -: ,:"1 q +(mbxcheck_jmf_ q), (,:"2 x) -: ,:"2 q + +q=: x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +y=: j{x [ j=: ?~#x +r=: j{q +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), y -: r +(mbxcheck_jmf_ q), (x,:y) -: q,:r +(mbxcheck_jmf_ q), (x,:y) -: q,:y +(mbxcheck_jmf_ q), (x,:y) -: x,:r + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +t=: 'abc';2 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x,:!.y t) -: x,:!.r t +(mbxcheck_jmf_ q), (x,:!.y t) -: q,:!.y t +(mbxcheck_jmf_ q), (x,:!.y t) -: q,:!.r t + + +NB. ; ------------------------------------------------------------------- + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (;x) -: ;q +q=: x=: (?4$20)#&.> <"0 ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (;x) -: ;q +q=: x=: <"0@?@(3 4&$)&.>10$100 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (;x) -: ;q +q=: x=: (i.2 3) ; (i.7) ; i.3 2 1 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (;x) -: ;q + +q=: x=: (?7 2 3$#x){x=: (5!:2 <'mean'),;:'Cogito, ergo sum.' +r=: y=: (?7 2 3$#y){y=: (5!:2 <'mean'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ r), (x;y) -: x;r +(mbxcheck_jmf_ r), (x;y) -: q;y +(mbxcheck_jmf_ r), (x;y) -: q;r +(mbxcheck_jmf_ r), (x;<y) -: x;<r +(mbxcheck_jmf_ r), (x;<y) -: q;<y +(mbxcheck_jmf_ r), (x;<y) -: q;<r +(mbxcheck_jmf_ r), (x;"0 y) -: x;"0 r +(mbxcheck_jmf_ r), (x;"0 y) -: q;"0 y +(mbxcheck_jmf_ r), (x;"0 y) -: q;"0 r +(mbxcheck_jmf_ r), (x;"1 y) -: x;"1 r +(mbxcheck_jmf_ r), (x;"1 y) -: q;"1 y +(mbxcheck_jmf_ r), (x;"1 y) -: q;"1 r +(mbxcheck_jmf_ r), (x;"2 y) -: x;"2 r +(mbxcheck_jmf_ r), (x;"2 y) -: q;"2 y +(mbxcheck_jmf_ r), (x;"2 y) -: q;"2 r + +q=: ;:'Cogito, ergo sum.' +mbxcheck_jmf_ q +t=: q;1234567 +q=: (<5!:2 <'g') 1}q +t -: q;1234567 +t=: q;<q +q=: (<,',') 1}q +t -: q;<q +mbxcheck_jmf_ q + + +NB. ;. ------------------------------------------------------------------ + +q=: x=: (?40$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (< ;.1 x) -: < ;.1 q +(mbxcheck_jmf_ q), ($ ;.1 x) -: $ ;.1 q +(mbxcheck_jmf_ q), (# ;.1 x) -: # ;.1 q +(mbxcheck_jmf_ q), (, ;.1 x) -: , ;.1 q +(mbxcheck_jmf_ q), ([ ;.1 x) -: [ ;.1 q +(mbxcheck_jmf_ q), (] ;.1 x) -: ] ;.1 q +(mbxcheck_jmf_ q), ({.;.1 x) -: {.;.1 q +(mbxcheck_jmf_ q), ({:;.1 x) -: {:;.1 q +(mbxcheck_jmf_ q), (}.;.1 x) -: }.;.1 q +(mbxcheck_jmf_ q), (}:;.1 x) -: }:;.1 q +(mbxcheck_jmf_ q), (|.;.1 x) -: |.;.1 q +(mbxcheck_jmf_ q), ({.`{:`[;.1 x)-: {.`{:`[;.1 q +(mbxcheck_jmf_ q), (j < ;.1 x) -: j < ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j $ ;.1 x) -: j $ ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j # ;.1 x) -: j # ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j , ;.1 x) -: j , ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j [ ;.1 x) -: j [ ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j ] ;.1 x) -: j ] ;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {.;.1 x) -: j {.;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {:;.1 x) -: j {:;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j }.;.1 x) -: j }.;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j }:;.1 x) -: j }:;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j |.;.1 x) -: j |.;.1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {.`{:;.1 x)-: j {.`{:;.1 q [ j=: 0=?(#x)$4 +q=: x=: (?40$#x){x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (< ;.1 x) -: < ;.1 q +(mbxcheck_jmf_ q), ($ ;.1 x) -: $ ;.1 q +(mbxcheck_jmf_ q), (# ;.1 x) -: # ;.1 q +(mbxcheck_jmf_ q), (, ;.1 x) -: , ;.1 q +(mbxcheck_jmf_ q), ([ ;.1 x) -: [ ;.1 q +(mbxcheck_jmf_ q), (] ;.1 x) -: ] ;.1 q +(mbxcheck_jmf_ q), ({.;.1 x) -: {.;.1 q +(mbxcheck_jmf_ q), ({:;.1 x) -: {:;.1 q +(mbxcheck_jmf_ q), (}.;.1 x) -: }.;.1 q +(mbxcheck_jmf_ q), (}:;.1 x) -: }:;.1 q +(mbxcheck_jmf_ q), (|.;.1 x) -: |.;.1 q +(mbxcheck_jmf_ q), ({.`{:`[;.1 x)-: {.`{:`[;.1 q +(mbxcheck_jmf_ q), (j < ;.2 x) -: j < ;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j $ ;._1 x) -: j $ ;._1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j # ;._1 x) -: j # ;._1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j , ;.2 x) -: j , ;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j [ ;.2 x) -: j [ ;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j ] ;.2 x) -: j ] ;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {.;.2 x) -: j {.;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {:;.2 x) -: j {:;.2 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j }.;._1 x) -: j }.;._1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j }:;._1 x) -: j }:;._1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j |.;._1 x) -: j |.;._1 q [ j=: 0=?(#x)$4 +(mbxcheck_jmf_ q), (j {.`{:;.2 x)-: j {.`{:;.2 q [ j=: 0=?(#x)$4 + +q=: x=: 1;1 0 1 0 0 +y=: 7 5 ?@$ 100 +(x <;.1 y) -: q <;.1 y +mbxcheck_jmf_ q + + +NB. ;: ------------------------------------------------------------------ + +me=: (i.#a.) e. (a.i.''''),,(a.i.'Aa')+/i.26 +se=: 2 2 2 $ 0 0 1 1 0 3 1 0 +y=: 'Now is the time all good men' +q=: x=: 0;se;me +(x;:y) -: q;:y +mbxcheck_jmf_ q + +q=: x=: (a.&-. ; ]) '''',a.{~,(a.i.'Aa')+/i.26 +((0;se;<x);:y) -: (0;se;<q);:y +mbxcheck_jmf_ q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j me mean q r se t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx4.ijs @@ -0,0 +1,281 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. # ------------------------------------------------------------------- + +q=: x=: (?20$#x){x=: <"0 (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: ?(#x)$5 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: ?(#x)$2 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: ?5 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: 0 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: 1 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: j./?(2,#x)$10 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: j./?2$10 +(mbxcheck_jmf_ q), (j#x) -: j # q [ j=: 0j2 +q=: x=: <"0 <"0 i.5 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: 1 2 0 4 3 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: 1 1 0 1 1 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: 3 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: 1 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: j./?2 5$10 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: j./?2$10 +(mbxcheck_jmf_ q), (j# x) -: j # q [ j=: 0j3 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: 1 2 0 4 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: 1 1 0 1 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: 3 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: 1 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: j./?2 4$10 +(mbxcheck_jmf_ q), (j#"1 x) -: j #"1 q [ j=: j./?2$10 + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (3j2#!.y x) -: 3j2#!.y q +(mbxcheck_jmf_ q), (3j2#!.y x) -: 3j2#!.r x +(mbxcheck_jmf_ q), (3j2#!.y x) -: 3j2#!.r q + + +NB. / ------------------------------------------------------------------- + +q=: x=: (?2 12$2){(<5!:2 <'g'),< i.2 3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (= /x) -: = /q +(mbxcheck_jmf_ q), (~:/x) -: ~:/q +(mbxcheck_jmf_ q), (, /x) -: , /q +(mbxcheck_jmf_ q), (; /x) -: ; /q +(mbxcheck_jmf_ q), (f /x) -: (f=: = )/q +(mbxcheck_jmf_ q), (f /x) -: (f=: ~: )/q +(mbxcheck_jmf_ q), (f /x) -: (f=: , )/q +(mbxcheck_jmf_ q), (f /x) -: (f=: ; )/q +(mbxcheck_jmf_ q), (f /x) -: (f=: 4 : 'x= y')/q +(mbxcheck_jmf_ q), (f /x) -: (f=: 4 : 'x~:y')/q +(mbxcheck_jmf_ q), (f /x) -: (f=: 4 : 'x, y')/q +(mbxcheck_jmf_ q), (f /x) -: (f=: 4 : 'x; y')/q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (= /x) -: = /q +(mbxcheck_jmf_ q), (~:/x) -: ~:/q +(mbxcheck_jmf_ q), (, /x) -: , /q +(mbxcheck_jmf_ q), (; /x) -: ; /q +f=: = +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: ~: +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: , +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: ; +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: 4 : 'x= y' +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: 4 : 'x~:y' +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: 4 : 'x, y' +(mbxcheck_jmf_ q), (f /x) -: f/q +f=: 4 : 'x; y' +(mbxcheck_jmf_ q), (f /x) -: f/q +q=: x=: +`% +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x/y) -: q/y=: 1+?5$10 +(mbxcheck_jmf_ q), (x/y) -: q/y=: 1+?5$10x + +q=: x=: <"1 ]11 7 ?@$ 100 +(,.&.>/x) -: ,.&.>/q +mbxcheck_jmf_ q + +q=: x=: <"1 <"0 ] 11 7 ?@$ 100 +(,.&.>/x) -: ,.&.>/q +mbxcheck_jmf_ q + + +NB. /. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x < /.x) -: q < /. q +(mbxcheck_jmf_ q), (x < /.x) -: q < /. x +(mbxcheck_jmf_ q), (x < /.x) -: x < /. q +(mbxcheck_jmf_ q), (x # /.x) -: q # /. q +(mbxcheck_jmf_ q), (x [ /.x) -: q [ /. q +(mbxcheck_jmf_ q), (x ] /.x) -: q ] /. q +(mbxcheck_jmf_ q), (x {./.x) -: q {./. q +(mbxcheck_jmf_ q), (x {:/.x) -: q {:/. q +(mbxcheck_jmf_ q), (x }./.x) -: q }./. q +(mbxcheck_jmf_ q), (x }:/.x) -: q }:/. q +(mbxcheck_jmf_ q), (x 3&$/.x) -: q 3&$/. q +q=: x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x < /.x) -: q < /. q +(mbxcheck_jmf_ q), (x < /.x) -: q < /. x +(mbxcheck_jmf_ q), (x < /.x) -: x < /. q +(mbxcheck_jmf_ q), (x # /.x) -: q # /. q +(mbxcheck_jmf_ q), (x [ /.x) -: q [ /. q +(mbxcheck_jmf_ q), (x ] /.x) -: q ] /. q +(mbxcheck_jmf_ q), (x {./.x) -: q {./. q +(mbxcheck_jmf_ q), (x {:/.x) -: q {:/. q +(mbxcheck_jmf_ q), (x }./.x) -: q }./. q +(mbxcheck_jmf_ q), (x }:/.x) -: q }:/. q +(mbxcheck_jmf_ q), (x 3&$/.x) -: q 3&$/. q + +q=: x=: (<@('a'&,)@":)`(<@('b'&,)@":)`(<@('c'&,)@":) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x/.y) -: q/.y=: i.4 5 + + +NB. /: ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (/: x) -: /: q +(mbxcheck_jmf_ q), (/:~x) -: /:~q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (/: x) -: /: q +(mbxcheck_jmf_ q), (/:~x) -: /:~q +(mbxcheck_jmf_ q), (/: x) -: /: q +(mbxcheck_jmf_ q), (/:"1 x) -: /:"1 q +(mbxcheck_jmf_ q), (/:"2 x) -: /:"2 q + +q=: x=: (?7 2$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +r=: y=: (?7 2$#y){y=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x/:y) -: x/:r +(mbxcheck_jmf_ q), (x/:y) -: q/:y +(mbxcheck_jmf_ q), (x/:y) -: q/:r + + +NB. \ ------------------------------------------------------------------- + +q=: x=: (?5 4 3$2){(<5!:2 <'g'),< i.2 3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,/\x) -: ,/\q +f=: , +(mbxcheck_jmf_ q), (f/\x) -: f/\q + +q=: x=: (?20$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 <\x) -: 3 <\q +(mbxcheck_jmf_ q), (_3 <\x) -: _3 <\q +(mbxcheck_jmf_ q), ( 30<\x) -: 30<\q +(mbxcheck_jmf_ q), (_30<\x) -: _30<\q +(mbxcheck_jmf_ q), ( 3 [\x) -: 3 [\q +(mbxcheck_jmf_ q), (_3 [\x) -: _3 [\q +(mbxcheck_jmf_ q), ( 30[\x) -: 30[\q +(mbxcheck_jmf_ q), (_30[\x) -: _30[\q +f=: |. +(mbxcheck_jmf_ q), ( 3 f\x) -: 3 f\q +(mbxcheck_jmf_ q), (_3 f\x) -: _3 f\q +(mbxcheck_jmf_ q), ( 30 f\x) -: 30 f\q +(mbxcheck_jmf_ q), (_30 f\x) -: _30 f\q +q=: x=: (?20$#x){x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 <\x) -: 3 <\q +(mbxcheck_jmf_ q), (_3 <\x) -: _3 <\q +(mbxcheck_jmf_ q), ( 30<\x) -: 30<\q +(mbxcheck_jmf_ q), (_30<\x) -: _30<\q +(mbxcheck_jmf_ q), ( 3 [\x) -: 3 [\q +(mbxcheck_jmf_ q), (_3 [\x) -: _3 [\q +(mbxcheck_jmf_ q), ( 30[\x) -: 30[\q +(mbxcheck_jmf_ q), (_30[\x) -: _30[\q +f=: |. +(mbxcheck_jmf_ q), ( 3 f\x) -: 3 f\q +(mbxcheck_jmf_ q), (_3 f\x) -: _3 f\q +(mbxcheck_jmf_ q), ( 30 f\x) -: 30 f\q +(mbxcheck_jmf_ q), (_30 f\x) -: _30 f\q + +q=: x=: (<@('a'&,)@":)`(<@('b'&,)@":)`(<@('c'&,)@":) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x\y) -: q\y=: i.7 +(mbxcheck_jmf_ q), ( 3 x\y) -: 3 q\y=: i.7 +(mbxcheck_jmf_ q), (_3 x\y) -: _3 q\y=: i.7 + + +NB. \. ------------------------------------------------------------------ + +q=: x=: <"0 ?12 3$1e6 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,/\.x) -: ,/\.q +f=: , +(mbxcheck_jmf_ q), (f/\.x) -: f/\.q +f=: 4 : 'x,y' +(mbxcheck_jmf_ q), (f/\.x) -: f/\.q +q=: x=: <"0 <"0 ?12 3$1e6 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (,/\.x) -: ,/\.q +f=: , +(mbxcheck_jmf_ q), (f/\.x) -: f/\.q +f=: 4 : 'x,y' +(mbxcheck_jmf_ q), (f/\.x) -: f/\.q + +q=: x=: (?20$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 <\.x) -: 3 <\.q +(mbxcheck_jmf_ q), (_3 <\.x) -: _3 <\.q +(mbxcheck_jmf_ q), ( 30<\.x) -: 30<\.q +(mbxcheck_jmf_ q), (_30<\.x) -: _30<\.q +(mbxcheck_jmf_ q), ( 3 [\.x) -: 3 [\.q +(mbxcheck_jmf_ q), (_3 [\.x) -: _3 [\.q +(mbxcheck_jmf_ q), ( 30[\.x) -: 30[\.q +(mbxcheck_jmf_ q), (_30[\.x) -: _30[\.q +f=: |. +(mbxcheck_jmf_ q), ( 3 f\.x) -: 3 f\.q +(mbxcheck_jmf_ q), (_3 f\.x) -: _3 f\.q +(mbxcheck_jmf_ q), ( 30 f\.x) -: 30 f\.q +(mbxcheck_jmf_ q), (_30 f\.x) -: _30 f\.q +q=: x=: (?20$#x){x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 <\.x) -: 3 <\.q +(mbxcheck_jmf_ q), (_3 <\.x) -: _3 <\.q +(mbxcheck_jmf_ q), ( 30<\.x) -: 30<\.q +(mbxcheck_jmf_ q), (_30<\.x) -: _30<\.q +(mbxcheck_jmf_ q), ( 3 [\.x) -: 3 [\.q +(mbxcheck_jmf_ q), (_3 [\.x) -: _3 [\.q +(mbxcheck_jmf_ q), ( 30[\.x) -: 30[\.q +(mbxcheck_jmf_ q), (_30[\.x) -: _30[\.q +f=: |. +(mbxcheck_jmf_ q), ( 3 f\.x) -: 3 f\.q +(mbxcheck_jmf_ q), (_3 f\.x) -: _3 f\.q +(mbxcheck_jmf_ q), ( 30 f\.x) -: 30 f\.q +(mbxcheck_jmf_ q), (_30 f\.x) -: _30 f\.q + +q=: x=: (<@('a'&,)@":)`(<@('b'&,)@":)`(<@('c'&,)@":) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x\.y) -: q\.y=: i.7 +(mbxcheck_jmf_ q), ( 3 x\.y) -: 3 q\.y=: i.7 +(mbxcheck_jmf_ q), (_3 x\.y) -: _3 q\.y=: i.7 + + +NB. \: ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (\: x) -: \: q +(mbxcheck_jmf_ q), (\:~x) -: \:~q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (\: x) -: \: q +(mbxcheck_jmf_ q), (\:~x) -: \:~q +(mbxcheck_jmf_ q), (\: x) -: \: q +(mbxcheck_jmf_ q), (\:"1 x) -: \:"1 q +(mbxcheck_jmf_ q), (\:"2 x) -: \:"2 q + +q=: x=: (?7 2$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +r=: y=: (?7 2$#y){y=: (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x\:y) -: x\:r +(mbxcheck_jmf_ q), (x\:y) -: q\:y +(mbxcheck_jmf_ q), (x\:y) -: q\:r + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx5.ijs @@ -0,0 +1,287 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. [ ------------------------------------------------------------------- + +q=: x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +y=: j{x [ j=: ?2 3 4$#x +r=: j{q +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ([x) -: ([q) +(mbxcheck_jmf_ q), (x[y) -: (q[r) +(mbxcheck_jmf_ q), (x[y) -: (x[r) +(mbxcheck_jmf_ q), (x[y) -: (q[y) + + +NB. ] ------------------------------------------------------------------- + +q=: x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +y=: j{x [ j=: ?2 3 4$#x +r=: j{q +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (]x) -: (]q) +(mbxcheck_jmf_ q), (x]y) -: (q]r) +(mbxcheck_jmf_ q), (x]y) -: (x]r) +(mbxcheck_jmf_ q), (x]y) -: (q]y) + + +NB. { ------------------------------------------------------------------- + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ({ x) -: {q +(mbxcheck_jmf_ q), (j{x) -: j{q [ j=: i.#q +(mbxcheck_jmf_ q), (j{x) -: j{q [ j=: ?20##q + +q=: x=: <"0 <"0 i.10 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (1 0{"2 x) -: 1 0{"2 q +(mbxcheck_jmf_ q), (1 0 1{ x) -: 1 0 1{ q +(mbxcheck_jmf_ q), (j{x) -: j{q [ j=: <?$q +(mbxcheck_jmf_ q), (j{x) -: j{q [ j=: <"1 ?12 3$$q + +y=: ?3 5 7 11$1e6 +q=: x=: <"1 ?(2 3,$$y)$$y +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{y) -: q{y +q=: x=: <0 1;2 3 4;5;6 7 8 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{y) -: q{y +q=: x=: (<0 1;2 3 4;5;6 7 8),<1 0;2 4 4;1;8 6 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{y) -: q{y +q=: x=: <(<0 1);2 3 4;5;6 7 8 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{y) -: q{y +q=: x=: 2 3 4;5;6 7 8 +(mbxcheck_jmf_ q), ((<0 1;x){y) -: (<0 1;q){y + +y=: $. (2 3 4 5 ?@$ 10) * 0=2 3 4 5 ?@$ 6 +q=: x=: <0;2 1;3 +(x{y) -: q{y +mbxcheck_jmf_ q + + +NB. {. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 7{.x) -: 7{.q +(mbxcheck_jmf_ q), (_7{.x) -: _7{.q +(mbxcheck_jmf_ q), ( 2{.x) -: 2{.q +(mbxcheck_jmf_ q), (_2{.x) -: _2{.q +(mbxcheck_jmf_ q), ( 7{.!.y x) -: 7{.!.y q [ y=: <5!:2 <'mean' +(mbxcheck_jmf_ q), (_7{.!.y x) -: _7{.!.y q +(mbxcheck_jmf_ q), ( 2{.!.y x) -: 2{.!.y q +(mbxcheck_jmf_ q), (_2{.!.y x) -: _2{.!.y q +q=: x=: <"0 <"0 i.2 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 7{.x) -: 3 7{.q +(mbxcheck_jmf_ q), (_3 7{.x) -: _3 7{.q +(mbxcheck_jmf_ q), ( 3 2{.x) -: 3 2{.q +(mbxcheck_jmf_ q), (_3 2{.x) -: _3 2{.q +(mbxcheck_jmf_ q), ( 3 7{.!.y x) -: 3 7{.!.y q [ y=: <5!:2 <'mean' +(mbxcheck_jmf_ q), (_3 7{.!.y x) -: _3 7{.!.y q +(mbxcheck_jmf_ q), ( 3 2{.!.y x) -: 3 2{.!.y q +(mbxcheck_jmf_ q), (_3 2{.!.y x) -: _3 2{.!.y q + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +r=: y=: <(1;2);3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (10{.!.y x) -: 10{.!.y q +(mbxcheck_jmf_ q), (10{.!.y x) -: 10{.!.r x +(mbxcheck_jmf_ q), (10{.!.y x) -: 10{.!.r q + + +NB. {: ------------------------------------------------------------------ + +q=: x=: (?10 2 3$#x){x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ({:x) -: {:q +(mbxcheck_jmf_ q), ({:"1 x) -: {:"1 q +(mbxcheck_jmf_ q), ({:"2 x) -: {:"2 q +f=: 3 : '{:y' +(mbxcheck_jmf_ q), (f x) -: f q +(mbxcheck_jmf_ q), (f"1 x) -: f"1 q +(mbxcheck_jmf_ q), (f"2 x) -: f"2 q + + +NB. {:: ----------------------------------------------------------------- + +q=: x=: 5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ({::x) -: {::q +(mbxcheck_jmf_ q), (j{::x) -: j{::q [ j=: 0;0;1 +(mbxcheck_jmf_ q), (j{::&.><x) -: j{::&.><q [ j=: < S:1{::q +(mbxcheck_jmf_ q), (< S: 0 q) -: j{::&.><q [ j=: < S:1{::q + +q=: x=: 0;0;0;0 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{::y) -: q {:: y=: 5!:2 <'g' + +q=: x=: < S: 1 {:: 5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x{::&.><y) -: q {::&.> <y=: 5!:2 <'g' + + +NB. } ------------------------------------------------------------------- + +q=: x=: (?20$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum. boustrophedonic jet' +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{x) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +q=: (j{x) (i.#q)}q +x=: (j{x) (i.#x)}x +(mbxcheck_jmf_ q), x -: q + +q=: x=: (?7 2 3$#x){x=: (<5!:2 <'g'),;:'Cogito, ergo sum. boustrophedonic jet' +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{x) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +x=: (j{q) (i.#x)}x +q=: (j{q) (i.#q)}q +(mbxcheck_jmf_ q), x -: q +j=: ?$~#x +q=: (j{x) (i.#q)}q +x=: (j{x) (i.#x)}x +(mbxcheck_jmf_ q), x -: q + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +t=: <"0 i.12 +t=: (<q) 1}t +q=: (<'abc') 2}q +t -: (<0),(<q),<"0 ] 2+i.10 +mbxcheck_jmf_ q +q=: (<'ergo') 2}q +t -: (<0),(<x),<"0 ] 2+i.10 + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +q=: (<q) 1}q +x=: (<x) 1}x +(mbxcheck_jmf_ q), x -: q +q=: (<,',') 1}q +x=: (<,',') 1}x +(mbxcheck_jmf_ q), x -: q + +q=: x=: 0;1 +(mbxcheck_jmf_ q), x -: q +q=: (i.&.>10000 4200) 0 1}q +x=: (i.&.>10000 4200) 0 1}x +(mbxcheck_jmf_ q), x -: q + +q=: x=: 0;1;(2000$a:);3 +(mbxcheck_jmf_ q), x -: q + +q=: (<2) 2}q +x=: (<2) 2}x +(mbxcheck_jmf_ q), x -: q + +q=: (<i.30000) 0}q +x=: (<i.30000) 0}x +(mbxcheck_jmf_ q), x -: q + +q=: <"0 i.5 +x=: <"0 i.5 +y=: (<3e6$'boustrophedonic')2}<"0 'abc' +'allocation error' -: ex 'q=: y 0 1 2}q' +(mbxcheck_jmf_ q), x -: q + +y=: 3 4 5 ?@$ 100 +q=: x=: <(<2);1 3 +(_5 x}y) -: _5 q}y +mbxcheck_jmf_ q + +q=: x=: <"1 ]5 3 ?@$ $y +(_5 x}y) -: _5 q}y +mbxcheck_jmf_ q + +q=: x=: (<1;2 3),<0;2 1 +(_5 x}y) -: _5 q}y +mbxcheck_jmf_ q + +q=: x=: ;:'one two three four five' +y=: ;:'eins zwei drei vier funf' +t=: 5 ?@$ 2 +(t}q,:y) -: t}x,:y +t=: t+2-2 +(t}q,:y) -: t}x,:y +mbxcheck_jmf_ q +q=: t}q,:y +mbxcheck_jmf_ q + + +NB. }. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 7}.x) -: 7}.q +(mbxcheck_jmf_ q), (_7}.x) -: _7}.q +(mbxcheck_jmf_ q), ( 2}.x) -: 2}.q +(mbxcheck_jmf_ q), (_2}.x) -: _2}.q +q=: x=: <"0 <"0 i.5 3 4 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( 3 1}.x) -: 3 1}.q +(mbxcheck_jmf_ q), (_3 1}.x) -: _3 1}.q +(mbxcheck_jmf_ q), ( 3 _2}.x) -: 3 _2}.q +(mbxcheck_jmf_ q), (_3 _2}.x) -: _3 _2}.q + +q=: x=: (<"0 ?5$10) ,. +&.>i.5 10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (f"1 x) -: f"1 q [ ".'f=: >@{. $ }.' +(mbxcheck_jmf_ q), (j f"_1 x) -: j f"_1 q [ j=: ?5$10 [ ".'f=: [ {. ] ' +(mbxcheck_jmf_ q), (({."1 x) f"_1 x) -: ({."1 q) f"_1 q [ ".'f=: >@[ {. ] ' +q=: x=: (<"0 ?5$10) ,. <"0 +&.>i.5 10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (f"1 x) -: f"1 q [ ".'f=: >@{. $ }.' +(mbxcheck_jmf_ q), (j f"_1 x) -: j f"_1 q [ j=: ?5$10 [ ".'f=: [ {. ] ' +(mbxcheck_jmf_ q), (({."1 x) f"_1 x) -: ({."1 q) f"_1 q [ ".'f=: >@[ {. ] ' + + +NB. }: ------------------------------------------------------------------ + +q=: x=: (?10 2 3$#x){x=: <"0 (<5!:2 <'g') , ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (}:x) -: }:q +(mbxcheck_jmf_ q), (}:"0 x) -: }:"0 q +(mbxcheck_jmf_ q), (}:"1 x) -: }:"1 q +(mbxcheck_jmf_ q), (}:"2 x) -: }:"2 q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbx6.ijs @@ -0,0 +1,109 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. ". ------------------------------------------------------------------ + +q=: x=: ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (".'x') -: ".'q' +(mbxcheck_jmf_ q), (".'|.x') -: ".'|.q' + + +NB. ": ------------------------------------------------------------------ + +q=: x=: <"0 (<5!:2 <'g'),;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (":x) -: ":q +(mbxcheck_jmf_ q), (0 1":x) -: 0 1":q +(mbxcheck_jmf_ q), (0 1":2 3$x) -: 0 1":2 3$q + + +NB. ` ------------------------------------------------------------------- + +q=: x=: 1: ` (* $:@<:) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q),(x@.*"0 j) -: q@.*"0 j=: ?40$30 + +q=: x=: +`% +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q),(x/j) -: q/j=: 1+?30$30 + +q=: x=: ('a'&;)`('b'&;)`('c'&;) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q),(x;._1 j) -: q;._1 j=: ' bou stro phe don ic' + +q=: x=: ('a'&;)`('b'&;)`('c'&;) +r=: y=: ('a'&;)`('b'&;) +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ r), (x`y) -: x`r +(mbxcheck_jmf_ r), (x`y) -: q`y +(mbxcheck_jmf_ r), (x`y) -: q`r + + +NB. @. ------------------------------------------------------------------ + +q=: x=: +`-`* +(x@.2 0 1) -: q@.2 0 1 +mbxcheck_jmf_ q + +q=: x=: 0;2;1 +(+`-`*@.x) -: +`-`*@.q +mbxcheck_jmf_ q + + +NB. &.> ----------------------------------------------------------------- + +q=: x=: ;:'Cogito, ergo sum. boustrophedonic chthonic' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ($&.> x) -: $&.> q +(mbxcheck_jmf_ q), (|.&.> x) -: |.&.> q +(mbxcheck_jmf_ q), (3|.&.> x) -: 3|.&.> q +(mbxcheck_jmf_ q), (x i.&.>'o') -: q i.&.>'o' +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.x) ,&.>{:q +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.q) ,&.>{:x +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.q) ,&.>{:q +(mbxcheck_jmf_ q), ((0{x) ,&.>x) -: (0{x) ,&.>q +(mbxcheck_jmf_ q), ((0{x) ,&.>x) -: (0{q) ,&.>x +(mbxcheck_jmf_ q), ((0{x) ,&.>x) -: (0{q) ,&.>q +(mbxcheck_jmf_ q), (x,&.> 0{x) -: x ,&.>0{q +(mbxcheck_jmf_ q), (x,&.> 0{x) -: q ,&.>0{x +(mbxcheck_jmf_ q), (x,&.> 0{x) -: q ,&.>0{q +(mbxcheck_jmf_ q), (x,&.>x) -: x ,&.>q +(mbxcheck_jmf_ q), (x,&.>x) -: q ,&.>x +(mbxcheck_jmf_ q), (x,&.>x) -: q ,&.>q +(mbxcheck_jmf_ q), (x,&.>|.x) -: x ,&.>|.q +(mbxcheck_jmf_ q), (x,&.>|.x) -: q ,&.>|.x +(mbxcheck_jmf_ q), (x,&.>|.x) -: q ,&.>|.q + +q=: x=: (<5!:2 <'g'), <"0 ;:'Cogito, ergo sum. boustrophedonic chthonic' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ($&.> x) -: $&.> q +(mbxcheck_jmf_ q), (|.&.> x) -: |.&.> q +(mbxcheck_jmf_ q), (3|.&.> x) -: 3|.&.> q +(mbxcheck_jmf_ q), (x i.&.>'o') -: q i.&.>'o' +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.x) ,&.>{:q +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.q) ,&.>{:x +(mbxcheck_jmf_ q), (({.x),&.>{:x)-: ({.q) ,&.>{:q +(mbxcheck_jmf_ q), ((0{x),&.>x) -: (0{x) ,&.>q +(mbxcheck_jmf_ q), ((0{x),&.>x) -: (0{q) ,&.>x +(mbxcheck_jmf_ q), ((0{x),&.>x) -: (0{q) ,&.>q +(mbxcheck_jmf_ q), (x,&.> 0{x) -: x ,&.>0{q +(mbxcheck_jmf_ q), (x,&.> 0{x) -: q ,&.>0{x +(mbxcheck_jmf_ q), (x,&.> 0{x) -: q ,&.>0{q +(mbxcheck_jmf_ q), (x,&.>x) -: x ,&.>q +(mbxcheck_jmf_ q), (x,&.>x) -: q ,&.>x +(mbxcheck_jmf_ q), (x,&.>x) -: q ,&.>q +(mbxcheck_jmf_ q), (x,&.>|.x) -: x ,&.>|.q +(mbxcheck_jmf_ q), (x,&.>|.x) -: q ,&.>|.x +(mbxcheck_jmf_ q), (x,&.>|.x) -: q ,&.>|.q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbxah.ijs @@ -0,0 +1,54 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. A. ------------------------------------------------------------------ + +q=: x=: <"0 (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (j A. x) -: j A. q [ j=: ?20$#x + + +NB. C. ------------------------------------------------------------------ + +q=: x=: (1,0<?50$4) <;.1]51?100 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (C.x) -: C.q +(mbxcheck_jmf_ q), (x C.y) -: q C.y=: ?100$1e6 +(mbxcheck_jmf_ q), ((<0 _1) C. x)-: (<0 _1) C. q + + +NB. e. ------------------------------------------------------------------ + +q=: x=: (?50$#x){x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (e. x) -: e. q +(mbxcheck_jmf_ q), (e.!.0 x) -: e.!.0 q +q=: x=: (?50$#x){x=: <"1 ?10 3$5 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (e. x) -: e. q +(mbxcheck_jmf_ q), (e.!.0 x) -: e.!.0 q + +q=: x=: (?50$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +r=: (j=: ?30$+:#x){q,t=: <"0 ?(#x)$1e5 +y=: j{x,t +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x e. y) -: q e. r +(mbxcheck_jmf_ q), (x e. y) -: q e. y +(mbxcheck_jmf_ q), (x e. y) -: x e. r +f=: e. +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +(mbxcheck_jmf_ q), (x e.!.0 y) -: q e.!.0 r +(mbxcheck_jmf_ q), (x e.!.0 y) -: q e.!.0 y +(mbxcheck_jmf_ q), (x e.!.0 y) -: x e.!.0 r +f=: e.!.0 +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbxip.ijs @@ -0,0 +1,159 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. i. ------------------------------------------------------------------ + +q=: x=: (?50$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i. x) -: q i. q +(mbxcheck_jmf_ q), (x i. x) -: q i. x +(mbxcheck_jmf_ q), (x i. x) -: x i. q +f=: i. +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 x +(mbxcheck_jmf_ q), (x i.!.0 x) -: x i.!.0 q +f=: i.!.0 +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +q=: x=: (?50$#x){x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i. x) -: q i. q +(mbxcheck_jmf_ q), (x i. x) -: q i. x +(mbxcheck_jmf_ q), (x i. x) -: x i. q +f=: i. +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 x +(mbxcheck_jmf_ q), (x i.!.0 x) -: x i.!.0 q +f=: i.!.0 +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +q=: x=: (?60$#x){x=: <"0 ] 10 3$(<5!:2 <'g'),+&.>?29$1e6 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i. x) -: q i. q +(mbxcheck_jmf_ q), (x i. x) -: q i. x +(mbxcheck_jmf_ q), (x i. x) -: x i. q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 q +(mbxcheck_jmf_ q), (x i.!.0 x) -: q i.!.0 x +(mbxcheck_jmf_ q), (x i.!.0 x) -: x i.!.0 q + +q=: x=: <"1 ] 100 3 ?@$ 5 +(i.!.0~ x) -: i.!.0~q +mbxcheck_jmf_ q + + +NB. i: ------------------------------------------------------------------ + +q=: x=: (?50$#x){x=: (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i: x) -: q i: q +(mbxcheck_jmf_ q), (x i: x) -: q i: x +(mbxcheck_jmf_ q), (x i: x) -: x i: q +f=: i: +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 x +(mbxcheck_jmf_ q), (x i:!.0 x) -: x i:!.0 q +f=: i:!.0 +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +q=: x=: (?50$#x){x=: <"0 (<5!:2 <'g') 1};:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i: x) -: q i: q +(mbxcheck_jmf_ q), (x i: x) -: q i: x +(mbxcheck_jmf_ q), (x i: x) -: x i: q +f=: i: +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 x +(mbxcheck_jmf_ q), (x i:!.0 x) -: x i:!.0 q +f=: i:!.0 +(mbxcheck_jmf_ q), (x f"1 0 x) -: q f"1 0 q +q=: x=: (?60$#x){x=: <"0 ] 10 3$(<5!:2 <'g'),+&.>?29$1e6 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x i: x) -: q i: q +(mbxcheck_jmf_ q), (x i: x) -: q i: x +(mbxcheck_jmf_ q), (x i: x) -: x i: q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 q +(mbxcheck_jmf_ q), (x i:!.0 x) -: q i:!.0 x +(mbxcheck_jmf_ q), (x i:!.0 x) -: x i:!.0 q + + +NB. I. ------------------------------------------------------------------ + +q=: x=: /:~ <"0 ]89 ?@$ 79 +r=: y=: <"0 ]97 ?@$ 89 +(x I. y) -: q I. y +(x I. y) -: x I. r +(x I. y) -: q I. r +mbxcheck_jmf_ q +mbxcheck_jmf_ r + +q=: x=: /:~ <"0 ]89 3 ?@$ 5 +r=: y=: <"0 ]97 3 ?@$ 5 +(x I. y) -: q I. y +(x I. y) -: x I. r +(x I. y) -: q I. r +mbxcheck_jmf_ q +mbxcheck_jmf_ r + + +NB. L. ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (L. x) -: L. q +(mbxcheck_jmf_ q), (L.&.>x) -: L.&.> q + + +NB. L: ------------------------------------------------------------------ + +q=: x=: (<5!:2 <'g'), ;:'Cogito, ergo sum.' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (# L: _1 x) -: # L: _1 q +(mbxcheck_jmf_ q), (": L: 0 x) -: ": L: 0 q +(mbxcheck_jmf_ q), (x ,L: 1 x) -: x ,L: 1 q +(mbxcheck_jmf_ q), (x ,L: 1 x) -: q ,L: 1 x +(mbxcheck_jmf_ q), (x ,L: 1 x) -: q ,L: 1 q + + +NB. p. ------------------------------------------------------------------ + +y=: -: _10+?4 5$20 +q=: x=: < ?3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y +q=: x=: 2; ?3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y +q=: x=: < o. _5+?3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y +q=: x=: 2;o. _5+?3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y +q=: x=: < j./_5+?2 3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y +q=: x=: 2;j./_5+?2 3$10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (p. x) -: p. q +(mbxcheck_jmf_ q), (x p. y) -: q p. y + +q=: y=: <3.5 11 +x=: <11 22 33 ,. 2 3 5 ,. 1 3 7 +(x p. y) -: x p. q +mbxcheck_jmf_ q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbxqz.ijs @@ -0,0 +1,52 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. s: ------------------------------------------------------------------ + +q=: x=: ;:'Cogito, ergo sum. ignorance apathy' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), ( s: x) -: s: q +(mbxcheck_jmf_ q), (< s: x) -: < s: q +(mbxcheck_jmf_ q), (x;s: x) -: x ; s: q +(mbxcheck_jmf_ q), (x;s: x) -: q ; s: x +(mbxcheck_jmf_ q), (x;s: x) -: q ; s: q + +q=: x=: 0 s: 10 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 10 s: q +(mbxcheck_jmf_ q), x -: 0 s: 10 +(mbxcheck_jmf_ q), q -: 0 s: 10 + + +NB. S: ------------------------------------------------------------------ + +q=: x=: 5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (< S: 0 x) -: < S: 0 q +(mbxcheck_jmf_ q), (x;S: 0 x) -: x ; S: 0 q +(mbxcheck_jmf_ q), (x;S: 0 x) -: q ; S: 0 x +(mbxcheck_jmf_ q), (x;S: 0 x) -: q ; S: 0 q + +q=: x=: 5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: x) -: (x (; <@;) S: 0 1 {:: q) +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: x) -: (q (; <@;) S: 0 1 {:: x) +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: x) -: (q (; <@;) S: 0 1 {:: q) + +q=: x=: 5!:2 <'g' +r=: y=: 5!:2 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ r), y -: r +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: y) -: (x (; <@;) S: 0 1 {:: r) +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: y) -: (q (; <@;) S: 0 1 {:: y) +(mbxcheck_jmf_ q), (x (; <@;) S: 0 1 {:: y) -: (q (; <@;) S: 0 1 {:: r) + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmbxx.ijs @@ -0,0 +1,230 @@ +NB. mapped boxed arrays ------------------------------------------------- + +0!:0 <testpath,'gmbx.ijs' + + +NB. 1!: ----------------------------------------------------------------- + +q=: x=: <'asdf' +t=: ": ?20$1e6 +t 1!:2 x + +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (1!:1 x) -: 1!:1 q + +(mbxcheck_jmf_ q), 1 [ t 1!:2 q + +(mbxcheck_jmf_ q), 1 [ t 1!:3 q + +(mbxcheck_jmf_ q), (1!:4 x) -: 1!:4 q + +q=: x=: 'asdf';2 13 +(mbxcheck_jmf_ q), (1!:11 x) -: 1!:11 q + +q=: x=: 'asdf';3 +y=: 'foo upon thee' +(y 1!:12 x) -: y 1!:12 q +q=: x=: 'asdf';3,#y +y -: 1!:11 q +mbxcheck_jmf_ q + +q=: <'asdf' +(mbxcheck_jmf_ q), 1 [ 1!:55 q + + +NB. 3!: ----------------------------------------------------------------- + +q=: x=: <"0 (?2 12$2){(<5!:2 <'g'),< i.2 3 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), q -: 3!:2 (3!:1) q +(mbxcheck_jmf_ q), x -: 3!:2 (3!:1) q +(mbxcheck_jmf_ q), q -: 3!:2 (3!:3) q +(mbxcheck_jmf_ q), x -: 3!:2 (3!:3) q +q=: x=: <"0 <"0 ?2 3 4$1e6 +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), q -: 3!:2 (3!:1) q +(mbxcheck_jmf_ q), x -: 3!:2 (3!:1) q +(mbxcheck_jmf_ q), q -: 3!:2 (3!:3) q +(mbxcheck_jmf_ q), x -: 3!:2 (3!:3) q + + +NB. 4!: ----------------------------------------------------------------- + +q=: x=: ;:'g mean junkfoo' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (4!:0 x) -: 4!:0 q + +q=: x=: ;:'g mean junkfoo' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (4!:4 x) -: 4!:4 q + +q=: x=: t=: ;:'junkfoo t' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 1 1 -: 4!:55 q + + +NB. 5!: ----------------------------------------------------------------- + +q=: x=: <'mean' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (5!:1 x) -: 5!:1 q +(mbxcheck_jmf_ q), (5!:2 x) -: 5!:2 q +(mbxcheck_jmf_ q), (5!:4 x) -: 5!:4 q +(mbxcheck_jmf_ q), (5!:5 x) -: 5!:5 q +(mbxcheck_jmf_ q), (5!:6 x) -: 5!:6 q + +q=: x=: (5!:2 <'g'); ;:'avuncular kakistocracy hermeneutics' +(mbxcheck_jmf_ q), (5!:1 <'x') -: 5!:1 <'q' +(mbxcheck_jmf_ q), (5!:2 <'x') -: 5!:2 <'q' +(mbxcheck_jmf_ q), (5!:4 <'x') -: 5!:4 <'q' +(mbxcheck_jmf_ q), (5!:5 <'x') -: 5!:5 <'q' +(mbxcheck_jmf_ q), (5!:6 <'x') -: 5!:6 <'q' + + +NB. 7!: ----------------------------------------------------------------- + +q=: x=: 5!:1 <'mean' +(mbxcheck_jmf_ q), x -: q +(7!:5 <'q') >: 7!:5 <'x' + +q=: x=: (;:'Cogito, ergo sum.'), {:: 5!:1 <'mean' +(mbxcheck_jmf_ q), x -: q +(7!:5 <'q') >: 7!:5 <'x' + +q=: x=: 5!:1 <'g' +(mbxcheck_jmf_ q), x -: q +(7!:5 <'q') >: 7!:5 <'x' + +q=: x=: (;:'Cogito, ergo sum.'), {:: 5!:1 <'g' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (7!:5 <'q') >: 7!:5 <'x' + +q=: x=: ;:'base z' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), (7!:6 q) -: 7!:6 x + + +NB. 8!: ----------------------------------------------------------------- + +q=: x=: <"0 ]7 ?@$ 0 +('' (8!:0) x) -: '' (8!:0) q +('' (8!:1) x) -: '' (8!:1) q +('' (8!:2) x) -: '' (8!:2) q +mbxcheck_jmf_ q + +q=: x=: <'c4' +y=: 3 4 ?@$ 0 +(x 8!:0 y) -: q 8!:0 y +(x 8!:1 y) -: q 8!:1 y +(x 8!:2 y) -: q 8!:2 y +mbxcheck_jmf_ q + + +NB. 9!: ----------------------------------------------------------------- + +q=: x=: 9!:8 '' +9!:9 q +mbxcheck_jmf_ q + +k=: 9!:42 '' + +9!:43 ]1 +q=: x=: 9!:44 '' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 9!:45 q +9!:43 ]2 +q=: x=: 9!:44 '' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 9!:45 q +9!:43 ]3 +q=: x=: 9!:44 '' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 9!:45 q +9!:43 ]4 +q=: x=: 9!:44 '' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 9!:45 q +9!:43 ]0 +q=: x=: 9!:44 '' +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), 9!:45 q + +9!:43 k + + +NB. 15!: ---------------------------------------------------------------- + +NB. see gdll.ijs + +load'dll' + +3 : 0 '' +if. 0=4!:0<'libtsdll' do. 1[lib=: libtsdll return. end. +t=. >IF64{'32';'64' +s=. >(UNAME-:'Darwin'){'.so';'.dylib' +if. IFUNIX do. + lib=: jpath '~home/dev/j/tsdll/libtsdll',t,s +else. + if. IF64 do. + lib=: '\dev\j\p_tsdll\release64\tsdll.dll' + else. + lib=: '\dev\j\p_tsdll\release\tsdll.dll' + end. +end. +lib=: lib,' ' +1 +) + +dcd=: 4 : '(lib,x) cd y' + +q=: x=: 1.1;2.2 +('ddd d d d' dcd x) -: 'ddd d d d' dcd q +mbxcheck_jmf_ q + +add=: mema 2*IF64{4 8 +3 4 memw add,0,2,JINT +q=: x=: (,2);2;<<add +('xbasic x *x x *x' dcd x) -: 'xbasic x *x x *x' dcd q +mbxcheck_jmf_ q +0=memf add + +q=: x=: ;:'q' +(15!:6 x) -: 15!:6 q +mbxcheck_jmf_ q + +'domain error' -: 15!:6 etx <'dcd' + +4!:55 ;:'add dcd lib' + + +NB. 18!: ---------------------------------------------------------------- + +q=: x=: <'xyz' +r=: y=: ;:'bou stro phedonic' +abc_xyz_ =: ?10$100 + +(mbxcheck_jmf_ q), x -: q +(mbxcheck_jmf_ q), y -: r +(mbxcheck_jmf_ q), (abc__x) -: abc__q +(mbxcheck_jmf_ q), (18!:2 x) -: 18!:2 q +(mbxcheck_jmf_ q), (y 18!:2 x) -: r 18!:2 q +(mbxcheck_jmf_ q), (18!:2 x) -: 18!:2 q +(mbxcheck_jmf_ q), (18!:55 x) -: 18!:55 q + +18!:55 y + + +NB. 128!: --------------------------------------------------------------- + +q=: x=: _306674912;1234567 +y=: 'assiduously avoid any and all asinine alliterations' +(x 128!:3 y) -: q 128!:3 y +mbxcheck_jmf_ q + + +1 [ unmap_jmf_ 'q' +1 [ unmap_jmf_ 'r' + +4!:55 ;:'f f1 g j k mean q r t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gmean.ijs @@ -0,0 +1,45 @@ +NB. (+/%#)"r ------------------------------------------------------------ + +mean=: 3 : '(+/y)%#y' + +f=: 4 : 0 + r=: x + yy=: y + assert. (mean"r -: (+/%#)"r) y + if. r do. + assert. (mean"r -: (+/%#)"r) 0{."r y + assert. (mean"r -: (+/%#)"r) 1{."r y + assert. (mean"r -: (+/%#)"r) 2{."r y + assert. (mean"r -: (+/%#)"r) 3{."r y + end. + 1 +) + +0 1 2 3 f"0 _ t=: 13 17 37 ?@$ 2 +0 1 2 3 f"0 _ t=: 13 17 37 ?@$ 2000 +0 1 2 3 f"0 _ t=: 13 17 37 ?@$ 4e8 +0 1 2 3 f"0 _ t=: 0.1 * 13 17 37 ?@$ 1e4 +0 1 2 3 f"0 _ t=: j./ 2 13 17 37 ?@$ 1e4 +0 1 2 3 f"0 _ t=: x: 13 17 37 ?@$ 1e4 +0 1 2 3 f"0 _ t=: 3r7 * 13 17 37 ?@$ 1e4 + + 1 2 3 f"0 _ t=: $. (13 17 37 ?@$ 2000) * 13 17 37 ?@$ 2 + 1 2 3 f"0 _ t=: $. 0.1 * (13 17 37 ?@$ 2000) * 13 17 37 ?@$ 2 + + +NB. (+/%#)/. ------------------------------------------------------------ + +f=: 4 : 0 + xx=: x {~ 1000 ?@$ #x + yy=: y {~ 1000 ?@$ #y + assert. xx (mean/. -: (+/%#)/.) yy + 1 +) + +f&>/~ 0 1;(i.100);(1e7*i.100);0.1*i.100 +(0 1;(i.100);1e7*i.100) f&>/ (<200 2) ?@$&.> 2 2e9 0 + + +4!:55 ;:'f mean r t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gmemo.ijs @@ -0,0 +1,39 @@ +NB. M. ------------------------------------------------------------------ + +fib=: 3 : 0 M. + if. 1>:y do. y else. (fib y-1)+fib y-2 end. +) + +fibr=: 3 : 0 + if. 1>:y do. y else. (fibr y-1)+fibr y-2 end. +) + +(fib -: fibr)"0 i.15 + +NB. pn implements recurrence relation by Euler, equation 11 in +NB. http://mathworld.wolfram.com/PartitionFunctionP.html + +rec=: 3 : 0 + _1>.y--:k*"1 ] _1 1+/3*k=. 1+i.1+<.%:y*0.6666666 +) + +pn=: 3 : 0 M. + if. 0>:y do. 0=y else. -/+/pn"0 rec y end. +) + +pnx=: 3 : 0 + if. 0>:y do. 0=y else. -/+/pnx"0 rec y end. +) + +(pn -: pnx)"0 i.15 + +combr=: 4 : 0 M. NB. All size x combinations of i.y + if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x combr&.<: y),1+x combr y-1 end. +) + +(comb -: combr)/"1 (<:/"1 t)#t=. ,/>{;~i.9 + + +4!:55 ;:'combr fib fibr pn pnx rec t' + +
new file mode 100644 --- /dev/null +++ b/test/gmmf.ijs @@ -0,0 +1,120 @@ +NB. memory mapped files ------------------------------------------------- + +1 [ 18!:4 <'base' [ load 'jmf' +1 [ unmapall_jmf_ '' + +fdir =: 1!:0 +fread =: 1!:1 +fwrite=: 1!:2 +ferase=: 1!:55 + +f0 =: <jpath '~temp\t.txt' + +t=: 'testing testing 1 2 3' +t fwrite f0 +t -: fread f0 + +JCHAR map_jmf_ 'abc';f0 NB. map abc to file characters +abc -: t +abc=: |.abc +abc -: |. t + +NB.! ebi 'file access error' -: fread etx f0 + +0 -: unmap_jmf_ 'abc' + +(|.t) -: fread f0 + +t=: 'testing testing 1 2 3' +t fwrite f0 +t -: fread f0 +JCHAR map_jmf_ 'abc';f0 NB. map abc to file characters +abc -: t +2 = >(<(({."1 t) i. <'abc_base_');9){t=: showmap_jmf_ '' +4!:55 ;:'abc' +1 = >(<(({."1 t) i. <'abc_base_');9){t=: showmap_jmf_ '' +0 -: unmap_jmf_ 'abc' +-. (<'abc_base_') e. {."1 t=: showmap_jmf_ '' + +ferase f0 + +f=: <jpath '~temp\jdata.jmf' +1 [ createjmf_jmf_ f,<1000 NB. 1000 bytes for data +t=: fdir f +1 = #t ++./ ({.{.t) E.&> f + +map_jmf_ 'jdata';f NB. map jdata to jmf file +'' -: jdata +0 -: 4!:0 <'jdata' + +t=: ?2 20$1e6 +jdata=: t +t -: jdata +0 -: unmap_jmf_ 'jdata' +_1 = 4!:0 <'jdata' + +map_jmf_ 'jdata';f +0 -: 4!:0 <'jdata' +t -: jdata + +jdata=: 1000$'abcd' +'allocation error' -: ex 'jdata=: 1001$''zxcv''' NB. too much data for file + +jdata=: 3 3$'abcd' +jdata=: 'xxx' 1} jdata NB. amend in-place +jdata -: 3 3$'abcxxxcda' + +jdata=: i. 2 3 +additem_jmf_ 'jdata' +3 = #jdata +jdata=: 23 (_1)} jdata +jdata -: (i.2 3),23 + +t=: showmap_jmf_'' NB. mapping information + +((<1;0){t) = <'jdata_base_' +((<1;1){t) = f +((<1;8){t) = <,1000 + +0 -: unmap_jmf_ 'jdata' NB. 0 result is success +1 -: # showmap_jmf_ '' + +x=: 10?1e6 +map_jmf_ 'jdata';f +jdata=: x +abc=: jdata +abc -: x +3 = >(<(({."1 t) i. <'jdata_base_'),9){t=: showmap_jmf_ 'jdata' +2 -: unmap_jmf_ 'jdata' +2 = >(<(({."1 t) i. <'jdata_base_'),9){t=: showmap_jmf_ 'jdata' +4!:55 ;:'abc' +1 = >(<(({."1 t) i. <'jdata_base_'),9){t=: showmap_jmf_ 'jdata' +0 -: unmap_jmf_ 'jdata' + +map_jmf_ 'jdata'; (>f); ''; 1 NB. read-only +x -: jdata +'read-only data' -: ex 'jdata=: 1 2 3' +0 -: unmap_jmf_ 'jdata' + +x=: 'Professors in New England guard the glory that was Greece' +x fwrite f +JCHAR map_jmf_ 'jdata';f +jdata -: x +0 -: unmap_jmf_ 'jdata' +JINT map_jmf_ 'jdata';f +4 -: 3!:0 jdata +0 -: unmap_jmf_ 'jdata' + +(JCHAR;2 5) map_jmf_ 'jdata';f +jdata -: ((<.(#x)%10),2 5)$x +0 -: unmap_jmf_ 'jdata' + +ferase f + +18!:55 <'jmf' + + +4!:55 ;:'f f0 fdir ferase fread fwrite i jdata t x ' + +
new file mode 100644 --- /dev/null +++ b/test/gmnom.ijs @@ -0,0 +1,141 @@ +NB. x p. y multinomials ------------------------------------------------- + +p1=: 4 : 0 " 1 0 + ((>y)^/e) +/ .* c [ 'c e'=. |:>x +) + +pn=: 4 : 0 " 1 0 + t=. >x + c=. {."1 t + e=. }."1 t + ((>y) */ .^|:e) +/ .* c +) + +NB. Boolean + +(<x=.?5 2$2) (p1 -: p.) y=. ?7$2 +(<x=.?5 2$2) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.?5 2$2) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.?5 2$2) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.?5 2$2) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.?5 2$2) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. integer + +(<x=.?5 2$10 6) (p1 -: p.) y=. ?7$2 +(<x=.?5 2$10 6) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.?5 2$10 6) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.?5 2$10 6) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.?5 2$10 6) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.?5 2$10 6) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. real + +(<x=.-:?5 2$10 6) (p1 -: p.) y=. ?7$2 +(<x=.-:?5 2$10 6) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.-:?5 2$10 6) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.-:?5 2$10 6) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.-:?5 2$10 6) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.-:?5 2$10 6) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. complex + +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. ?7$2 +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.j./?2 5 2$10 6) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. extended integer + +(<x=.?5 2$10 6x) (p1 -: p.) y=. ?7$2 +(<x=.?5 2$10 6x) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.?5 2$10 6x) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.?5 2$10 6x) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.?5 2$10 6x) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.?5 2$10 6x) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. rational + +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. ?7$2 +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. _7+?2 3 4$13 +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. o._7+?3 4$13 +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. r._7+?2 1 4$13 +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. _7+?2 1 4$13x +(<x=.1r2 0+"1?5 2$10 6x) (p1 -: p.) y=. %/y+0=y=._7+?2 3 4$13x + +NB. Boolean + +(<x=.?5 4$2) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.?5 4$2) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.?5 4$2) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.?5 4$2) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.?5 4$2) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.?5 4$2) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +NB. integer + +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.?5 4$20 4 4 4) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +NB. real + +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.-:?5 4$20 4 4 4) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +NB. complex + +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.j./?2 5 4$20 4 4 4) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +NB. extended integer + +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.?5 4$20 4 4 4x) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +NB. rational + +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 ?7 3$2 +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 ] _7+?2 3 3$13 +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 o._7+?3 3$13 +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 r._7+?2 1 3$13 +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 _7+?2 1 3$13x +(<x=.1r2 0 0 0+"1?5 4$20 4 4 4) (pn -: p.) y=. <"1 %/y+0=y=._7+?2 3 3$13x + +'domain error' -: (<2 3$'abc') p. etx 3 +'domain error' -: (<2 3$<3 ) p. etx 3 +'domain error' -: (<i.3 2) p. etx 'ab' +'domain error' -: ('a';_3 7) p. etx 4 5 +'domain error' -: (3;'abc') p. etx 4 5 +'domain error' -: (3;<<1 2 3) p. etx 4 5 +'domain error' -: ((<3);2 3) p. etx 4 5 + +'length error' -: (<i.4 3) p. etx <3 4 5 +'length error' -: (<i.4 3) p. etx <,3 +'length error' -: (<i.4 3) p. etx 3 4;5 6;,7 + +'rank error' -: (3 4;1 2 3) p. etx 4 5 +'rank error' -: (3;i.2 3) p. etx 4 5 + + +NB. x p.!.s y ----------------------------------------------------------- + + +4!:55 ;:'x y p1 pn' \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/gn.ijs @@ -0,0 +1,10 @@ +NB. NB. ----------------------------------------------------------------- + +NB. Don't tread on me! +NB. NB. .. .: :. .: NB. NB not: 3_4_5_ _. +1 [ 'NB. not comment' NB. this is a comment +".'1 NB. huh? don''t tread on me!' +".'NB. nothing but comment' +1 + +
new file mode 100644 --- /dev/null +++ b/test/gnan.ijs @@ -0,0 +1,289 @@ +NB. NaN ----------------------------------------------------------------- + +t=. }.&.> 3.4 _ __; 3j4 _ __; 34x _ __ ; 3r4 _ __ +pinf=: {.&.> t +ninf=: {:&.> t +inf =: pinf,ninf +zero=: 0 ; -&.>~ 2 ; 3.4 ; 3j4 ; 3x ; 3r4 +znan=: {. _. 3j4 + +NB. =<>_ +*-% ^$~| .:,; #!/\ []{} "`@&? + + +NB. =<>_ ---------------------------------------------------------------- + +=&>/~ pinf +=&>/~ ninf +-. pinf =&>/ ninf + + +NB. +*-% ---------------------------------------------------------------- + +(<'NaN error') = pinf + etx&.>/ ninf +(<'NaN error') = ninf + etx&.>/ pinf + +'NaN error' -: (1$.1e9;0;_) + etx 1$.1e9;0;__ + +(<'NaN error') = inf +.etx&.>/ x=: 20 ?@$ 2 +(<'NaN error') = inf +.etx&.>/~ x +(<'NaN error') = inf +.etx&.>/ x=: 0, _5e3+20 ?@$ 1e4 +(<'NaN error') = inf +.etx&.>/~ x +(<'NaN error') = inf +.etx&.>/ x=: 0, o. _5e3+20 ?@$ 1e4 +(<'NaN error') = inf +.etx&.>/~ x +(<'NaN error') = inf +.etx&.>/ x=: 0, r. _5e3+20 ?@$ 1e4 +(<'NaN error') = inf +.etx&.>/~ x +(<'NaN error') = inf +.etx&.>/ x=: 0, _5000 +20 ?@$ 10000x +(<'NaN error') = inf +.etx&.>/~ x +(<'NaN error') = inf +.etx&.>/ x=: 0, 4%~_5000 +20 ?@$ 10000x +(<'NaN error') = inf +.etx&.>/~ x + +'domain error' -: _. +: etx 1 +'domain error' -: 0 +: etx _. + +(<0) = zero *&.>/ inf +(<0) = inf *&.>/ zero + +NB. x=: 4{. 2 (3!:3) 0j1 +NB. t=: _4{. 2 (3!:3) _. __ 0 _ +NB. y=: 3!:2&.> (<x),&.> (,{;~i.#t){&.><t +NB. (<0) = zero *&.> / y +NB. (<0) = zero *&.> /~ y + +(<'NaN error') = * etx&.> j./~ _ __ + +'NaN error' -: 3j4 * etx _j__ +'NaN error' -: 3j_4 * etx _j_ + +(<'NaN error') = inf *.etx&.>/ x=: 20 ?@$ 2 +(<'NaN error') = inf *.etx&.>/~ x +(<'NaN error') = inf *.etx&.>/ x=: 0, _5e3+20 ?@$ 1e4 +(<'NaN error') = inf *.etx&.>/~ x +(<'NaN error') = inf *.etx&.>/ x=: 0, o. _5e3+20 ?@$ 1e4 +(<'NaN error') = inf *.etx&.>/~ x +(<'NaN error') = inf *.etx&.>/ x=: 0, r. _5e3+20 ?@$ 1e4 +(<'NaN error') = inf *.etx&.>/~ x +(<'NaN error') = inf *.etx&.>/ x=: 0, _5000 +20 ?@$ 10000x +(<'NaN error') = inf *.etx&.>/~ x +(<'NaN error') = inf *.etx&.>/ x=: 0, 4%~_5000 +20 ?@$ 10000x +(<'NaN error') = inf *.etx&.>/~ x + +'domain error' -: _. *: etx 1 +'domain error' -: 0 *: etx _. + +(<'NaN error') = pinf - etx&.>/ pinf +(<'NaN error') = ninf - etx&.>/ ninf + +'NaN error' -: (1$.1e9;0;_) - etx 1$.1e9;0;_ + +(<0) = zero %&.>/ zero + +(<'NaN error') = % etx&.>/~ inf + +'NaN error' -: (1$.1e9;0;_) % etx 1$.1e9;0;__ + +0j_ _ -: %: __ _ +0j_ _ -: %: }. 3j4 __ _ + + +NB. ^$~| ---------------------------------------------------------------- + +0 = ^ __ +0 = ^ {. __ 3j4 + +(<'NaN error') = ^. etx&.>/~ zero + +NB. funny business if moved as doubles +(a.{~32$240 255) -: 32 $ 240 255{a. + +(($zero)$,:inf) -: zero |&.>/ inf + +(<'NaN error') = inf | etx&.>/~ x=: 1+7 ?@$ 40 +(<'NaN error') = inf | etx&.>/~ x=: - 1+7 ?@$ 40 +(<'NaN error') = inf | etx&.>/~ x=: 100%~ 1+7 ?@$ 40 +(<'NaN error') = inf | etx&.>/~ x=: _100%~ 1+7 ?@$ 40 +(<'NaN error') = inf | etx&.>/~ x=: r. 7 ?@$ 40 +(<'NaN error') = inf | etx&.>/~ x=: 1+7 ?@$ 40x +(<'NaN error') = inf | etx&.>/~ x=: - 1+7 ?@$ 40x +(<'NaN error') = inf | etx&.>/~ x=: 100%~ 1+7 ?@$ 40x +(<'NaN error') = inf | etx&.>/~ x=: _100%~ 1+7 ?@$ 40x + +x ="1 pinf |&>/ x=: 1+7 ?@$ 40 +x ="1 pinf |&>/ x=: 100%~ 1+7 ?@$ 40 +x ="1 pinf |&>/ x=: 1+7 ?@$ 40x +x ="1 pinf |&>/ x=: 100%~ 1+7 ?@$ 40x + +pinf = pinf |&.>/ x=: - 1+7 ?@$ 40 +pinf = pinf |&.>/ x=: _100%~ 1+7 ?@$ 40 +pinf = pinf |&.>/ x=: - 1+7 ?@$ 40x +pinf = pinf |&.>/ x=: _100%~ 1+7 ?@$ 40x + +ninf = ninf |&.>/ x=: 1+7 ?@$ 40 +ninf = ninf |&.>/ x=: 100%~ 1+7 ?@$ 40 +ninf = ninf |&.>/ x=: 1+7 ?@$ 40x +ninf = ninf |&.>/ x=: 100%~ 1+7 ?@$ 40x + +x ="1 ninf |&>/ x=: - 1+7 ?@$ 40 +x ="1 ninf |&>/ x=: _100%~ 1+7 ?@$ 40 +x ="1 ninf |&>/ x=: - 1+7 ?@$ 40x +x ="1 ninf |&>/ x=: _100%~ 1+7 ?@$ 40x + + +NB. .:,; ---------------------------------------------------------------- + +'NaN error' -: _ _ +/ .* etx 1 _1 +'NaN error' -: _ __ +/ .* etx 1 1 + +x=: o. 3 4 ?@$ 2 +y=: _ 1 2 3 4 {~ 4 5 ?@$ 5 +(x +/ .* y) -: x +/@(*"1 _) y + +f=: +/ @ (*"1 _) +x=: 11 23 $ _ (43 ?@$ 253)} (253 ?@$ 0) * 253 ?@$ 2 +y=: 23 13 $ _ (43 ?@$ 299)} (299 ?@$ 0) * 299 ?@$ 2 +x (f -: +/ .*) y + +det=: -/ .* + +x=: x;(x+-~0j5);x: x=: (2 2$_ __ 1 1) ({;~0 1)}=i.4 +_ = det & > (2 2;3 3;4 4) {.&.>/ x +x=: x;(x+-~0j5);x: x=: (2 2$__ _ 1 1) ({;~0 1)}=i.4 +__ = det & > (2 2;3 3;4 4) {.&.>/ x +x=: x;(x+-~0j5);x: x=: (2 2$_ _ 1 1) ({;~0 1)}=i.4 +(<'NaN error') = det etx&.> (2 2;3 3;4 4) {.&.>/ x + +3j4 _. _. _. -:&(3!:1) 3j4 , _. _. _. + +(<'NaN error') = (<1 0) +/;.1 etx&.> pinf ,&.>/ ninf +(<'NaN error') = (<1 0) %/;.1 etx&.> pinf ,&.>/ ninf + +(<'NaN error') = (<1 0) ([: ; <@(+/\);.1) etx&.> pinf ,&.>/ ninf + + +NB. #!/\ ---------------------------------------------------------------- + +NB. funny business if moved as doubles +(2#_1e6 _1e6) -: _1e6 _1e6 _1e6 _1e6 +(3 2$_834524) -: 1 0 1 0 1 # 5 2$_834524 +(3 8$240 255{a.) -: 1 0 1 0 1 # 5 8$240 255{a. + +(<'NaN error') = ! etx&.>/~ pinf +(<'NaN error') = ! etx&.>/~ ninf + +8 -: (3!:0) _. +16 -: (3!:0) _. 3j4 + +x -:&(3!:1) (3!:2) 3!:1 x=: _. __ _12.34 0 45.678 _ +x -:&(3!:1) (3!:2) 3!:1 x=: _. __ _12.34 0 45.678 _ 3j4 + +x -:&(3!:1) _1 (3!:5) 1 (3!:5) x=: 3 4 _. +x -:&(3!:1) _2 (3!:5) 2 (3!:5) x=: 3 4 _. + +((i.1e4) e. i) -: (128!:5) _. i}1e4 ?@$ 0 [ i=: 200 ?@$ 1e4 +0 0 0 -: (128!:5) 0 1 2 +0 0 0 -: (128!:5) 'abc' + +(<'NaN error') = +/ etx&.> pinf ,&.>/ ninf +(<'NaN error') = -/ etx&.> ,&.>/~ pinf +(<'NaN error') = -/ etx&.> ,&.>/~ ninf +(<'NaN error') = %/ etx&.> ,&.>/~ inf + +'NaN error' -: +/ etx _ __ (2?1e9)}1$.1e9 +'NaN error' -: -/ etx _ (2?1e9)}1$.1e9 +'NaN error' -: %/ etx _ (2?1e9)}1$.1e9;0;1.5-0.5 + +(<'NaN error') = (+/%#)etx&.> pinf ,&.>/ ninf +(<'NaN error') = (+/%#)etx&.> (<2 3) ,&.> pinf ,&.>/ ninf + +(<'NaN error') = +//. etx&.> 2 2&$@(1&,)&.> pinf ,&.>/ ninf + +(<'NaN error') = (<1 1) +//.@(*/) etx&.> pinf ,&.>/ ninf + +(<'NaN error') = (<'aa') +//. etx&.> pinf ,&.>/ ninf + +(<'NaN error') = (<'aa') (+/%#)/. etx&.> pinf ,&.>/ ninf + +(<'NaN error') = +/\ etx&.> pinf ,&.>/ ninf +(<'NaN error') = -/\ etx&.> ,&.>/~ pinf +(<'NaN error') = -/\ etx&.> ,&.>/~ ninf +(<'NaN error') = %/\ etx&.> ,&.>/~ inf + +'NaN error' -: 3 +/\ etx _ 4 __ 5 +'NaN error' -: 3 (+/%#)\ etx _ 4 __ 5 + +2 _ _ _ 5 -: 3 (+/%#)\ 1 2 3 _ 4 5 6 +(<,_ ) = 3 +/\ &.> 3#&.> pinf +(<,__) = 3 +/\ &.> 3#&.> ninf +(<,_ ) = 3 (+/%#)\&.> 3#&.> pinf +(<,__) = 3 (+/%#)\&.> 3#&.> ninf + +(<'NaN error') = +/\. etx&.> pinf ,&.>/ ninf +(<'NaN error') = -/\. etx&.> ,&.>/~ pinf +(<'NaN error') = -/\. etx&.> ,&.>/~ ninf +(<'NaN error') = %/\. etx&.> ,&.>/~ inf + +3 (+/\. -: +/&>@(<\.)) 3 1 4 _ 1 4 9 +_2 (+/\. -: +/&>@(<\.)) 3 1 4 _ 1 4 9 + + +NB. []{} ---------------------------------------------------------------- + + +NB. "`@&? --------------------------------------------------------------- + +'_.' -: ": _. +'_.' -: ": znan + +(<,'_') = ":&.> pinf +(<'__') = ":&.> ninf + +x=: 1 _1 ; 3.5 _3.5 ; 3j4 _3j_4; 3 _3x ; 3r5 _3r5 +(<'NaN error') = x +/@:* etx&.>/ 2#&.>inf + +x=: 2#&.> 2; 3.5 ; 3j4 ; _3x ; 3r5 +(<'NaN error') = x -/@:* etx&.>/ 2#&.>inf + +(<0) = zero +/@:*&.>/ pinf ,&.>/ ninf + +'NaN error' -: +/@, etx 2 2$1 _ __ +'NaN error' -: +/@, etx $. 2 2$1 _ __ + +'domain error' -: ? etx _. 4 +'domain error' -: _. ? etx 5 +'domain error' -: 5 ? etx _. +'domain error' -: _. ? etx _. + + +NB. a-z ----------------------------------------------------------------- + +'NaN error' -: _ __ H. '' etx 1 +'NaN error' -: _ _ H. '' etx _1 + +'NaN error' -: _ __ H. '' etx 1+-~0j5 +'NaN error' -: _ _ H. '' etx _1+-~0j5 + +'domain error' -: i. etx _. + +'NaN error' -: 0 _1 1 p. etx _ +'NaN error' -: 0 1 1 p. etx __ +'NaN error' -: 5 _ _ p. etx _1 +_ = 5 _ _ p. 1 + +t=: (i:12) o. etx&.>/ , j./~ __ 0 _ +-. +./@('_.'&E.)@":&> t + +_1 1 = 7 o. _1e9 1e9 +_1 1 = 7 o. __ _ + +((i: 12) o. etx&.> _ ) = (i:12) o. etx&.> {. _ 0j1 +((i: 12) o. etx&.> __) = (i:12) o. etx&.> {. __ 0j1 + +'NaN error' -: _ _ p.!.1 etx _1 +'NaN error' -: _ __ p.!.1 etx 1 + +'NaN error' -: x: etx _. +'NaN error' -: x: etx 3 4 _. + + +4!:55 ;:'d det f i inf ninf pinf t x y zero znan' + +
new file mode 100644 --- /dev/null +++ b/test/gnum.ijs @@ -0,0 +1,58 @@ +NB. numeric constants --------------------------------------------------- + +3j4 -: ". '3j4' +1 _2 3j4 -: ". '1 _2 3j4' + +0.34 -: ". '0.34' +3j4 0.34 -: ". '3j4 0.34' + +x -: ". ": x=:?3 4$10000 +x -: ". ": x=:_1e4+?3 4$2e4 +x -: ". ": x=:j./?2 3 4$10000 +x -: ". ": x=:j./_1e4+?2 3 4$2e4 + +x -: ". ": ,.x=: _1e9+?20$2e9 +x -: ". ":!.16 ,.x=:o._1e9+?20$2e9 +x -: ". ":!.16 ,.x=:j./ _1e9+?2 20$2e9 + +(^1 2) -: ". '1x1 1x2 ' +((^1),1+%:_1) -: ". '1x1 1j1 ' +((^1),o.1) -: ". '1x1 1p1 ' + +((o.1)^1 2) -: ". '1p1 1p2' + +2b111 5b312 -: ". '2b111 5b312 ' +2b111 5b312 -: ". '2b111 5b312 ' + +0j4 _5 -: ". '4ad90 5ar3.14159265358979' + +((%3),_0.25) -: ". ' 1r3 _1r4' + +eq=: -:&(3!:1) +1 2 _ 3.4 eq ". '1 2 _ 3.4' +1 2 _ 3j4 eq ". '1 2 _ 3j4' +1 2 __ 3.4 eq ". '1 2 __ 3.4' +1 2 __ 3j4 eq ". '1 2 __ 3j4' +1 2 _. 3.4 eq ". '1 2 _. 3.4' +1 2 _. 3j4 eq ". '1 2 _. 3j4' + +'_. 3' -: ": _. 3 +'_. 3' -: ": _. 3.0 +'_. 3' -: ": _. 3j0 +'_. 3.14159' -: ": _. 1p1 +'_. 2.71828' -: ": _. 1x1 + +x=: 1e4 ?@$ IF64{2e9 9e18 +x eq ". ": x +(-x) eq ". ": -x + +(4=type x) *. 0 = (- y) - x=: ". '_',": y=: 2^IF64{31 63x +(4=type x) *. 0 = (<:y) - x=: ". ": <: y=: 2^IF64{31 63x + +'ill-formed number' -: ". etx '3ee4' +'ill-formed number' -: ". etx '3jj4' + + +4!:55 ;:'eq x y' + +
new file mode 100644 --- /dev/null +++ b/test/gnvv.ijs @@ -0,0 +1,22 @@ +NB. N V0 V1 ------------------------------------------------------------- + +lr=: 1 : '5!:5 <''u''' + +'5 >. #' -: (5 >.#) lr +'(i.8) , 8:' -: ((i.8) , 8:) lr + + +NB. N V0 V1 inverses ---------------------------------------------------- + +testx=: 2 : '(x b._1) -: 5!:5<''y''' + +(3 * ]) testx ((%3) * ] ) +([: +: 3 * ]) testx ((%3) * -:) +(3 * 4 + 5 * 6 + 7 * ] ) testx ( (%7) * _6 + (%5) * _4 + (%3) * ]) +(3 * 4 + [: *: 6 + 7 * ] ) testx ( (%7) * _6 + [: %: _4 + (%3) * ]) +(3 * 4 + [: *: 6 + 7 * +:) testx ([: -: (%7) * _6 + [: %: _4 + (%3) * ]) + + +4!:55 ;:'lr testx' + +
new file mode 100644 --- /dev/null +++ b/test/go.ijs @@ -0,0 +1,345 @@ +NB. x o.y for x e.i.13 -------------------------------------------------- + +z =: (_10+?20$20) j. _4+?20$20 +x =: 0.1 * _50+?20$100 + +cir0 =: -.&.(*~) +sin =: (^ -:@- ^@-)&.j. +cos =: (^ -:@+ ^@-)@j. +tan =: %/&(1 2&(o./)) +cir4 =: >:&.(*~) +sinh =: ^ -:@- ^@- +cosh =: ^ -:@+ ^@- +tanh =: %/&(5 6&(o./)) +cir8 =: -&>:&.(*~) + +1e_8 > >./|,(cir0 z) - 0 o.z +1e_8 > >./|,(cir0 x) - 0 o.x + +1e_8 > >./|,(sin z) - 1 o.z +1e_8 > >./|,(sin x) - 1 o.x +1e_8 > | 0.841470984807896 - 1 o.1 + +1e_8 > >./|,(cos z) - 2 o.z +1e_8 > >./|,(cos x) - 2 o.x +1e_8 > | 0.540302305868139 - 2 o.1 + +1e_8 > >./|,(tan z) - 3 o.z +1e_8 > >./|,(tan x) - 3 o.x +1e_8 > >./| 0.54630249 1255.7655915 - 3 o.0.5 1.57 + +1e_8 > >./|,(cir4 z) - 4 o.z +1e_8 > >./|,(cir4 x) - 4 o.x + +1e_8 > >./|,(sinh z) - 5 o.z +1e_8 > >./|,(sinh x) - 5 o.x +1e_8 > | 1.601919080 - 5 o.1.25 + +1e_8 > >./|,(cosh z) - 6 o.z +1e_8 > >./|,(cosh x) - 6 o.x +1e_8 > | 1.543080635 - 6 o.1 + +1e_8 > >./|,(tanh z) - 7 o.z +1e_8 > >./|,(tanh x) - 7 o.x +1e_8 > | 0.86924933 - 7 o.1.33 + +1e_8 > >./|,(cir8 z) - 8 o.z +1e_8 > >./|,(cir8 x) - 8 o.x + +1e_8 > >./|,z - _9 _11 +/ . o. 9 11 o./z +1e_8 > >./|,x - _9 _11 +/ . o. 9 11 o./x + +1e_8 > >./|,z - _10 _12 */ . o. 10 12 o./z +1e_8 > >./|,x - _10 _12 */ . o. 10 12 o./x + +8 -: type 1 2 o. 1.5 +8 -: type 1 2 3 o. 1.5 + + +NB. x o.y for x e.-i.13 ------------------------------------------------- + +sin =: 1&o. +asin =: _1&o. +cos =: 2&o. +acos =: _2&o. +tan =: 3&o. +atan =: _3&o. +cir4m =: 3 : '(>:y)*%:(<:y)%(>:y)' +sinh =: 5&o. +asinh =: _5&o. +cosh =: 6&o. +acosh =: _6&o. +tanh =: 7&o. +atanh =: _7&o. +cir8m =: %:&.-&>:&(*~) + +z =: ^0j0.1*?20$100 +x =: 0.02*_50+?20$100 + +1e_8 > >./|,z - sin asin z +1e_8 > >./|,x - sin asin x +1e_8 > >./|,z - asin sin z +1e_8 > >./|,x - asin sin x +1e_8 > /| 0.789 - asin 0.7096490720426565 + +z =: z * _1^0>9 o.z=:^0j0.1*?20$100 +x =: 0.02*_50+?20$100 + +1e_8 > >./|, z - cos acos z +1e_8 > >./|, x - cos acos x +1e_8 > >./, (|z - acos cos z) <. | (-z) - acos cos -z +1e_8 > >./, (|x - acos cos x) <. | (-x) - acos cos -x +1e_8 > | 0.696 - acos 0.767412932432449 + +z =: r.?20$100 +x =: 0.001 * _1500+?20$3000 + +1e_8 > >./|,z - tan atan z +1e_8 > >./|,x - tan atan x +1e_8 > >./|,z - atan tan z +1e_8 > >./|,x - atan tan x +1e_8 > | 0.572852247673 - atan 0.645 + +1e_8 > >./|,(cir4m z) - _4 o.z +1e_8 > >./|,(cir4m x) - _4 o.x + +z =: r.?20$100 +x =: 0.001 * _1e4+?20$1e5 + +1e_8 > >./|, z - sinh asinh z +1e_8 > >./|, x - sinh asinh x +1e_8 > >./|, z - asinh sinh z +1e_8 > >./|, x - asinh sinh x +1e_8 > >./| 3.9 5.9 - asinh 24.691103597 182.51736421 + +a =: (r.?10$100),i.9 +a =: a *_1^0>9 o.a +b =: _9}.a + +1e_8 > >./|, a - cosh acosh a +1e_8 > >./|, b - acosh cosh b +1e_8 > >./| 1.19 5.8 - acosh 1.795651236 165.151293732 + +a =: ^0j0.1*?18$100 + +1e_8 > >./|,a - atanh tanh a + +x=: 1.99188402916 2.22881178784 +y=: 201.71315737028 201.71563612246 +1e_8 > >./| 1.44 6 - atanh (%/x),%/y + +1e_8 > >./|,(cir8m a) - _8 o.a + + +NB. circle functions of the form f&.j. --------------------------------- + +sin =: 1&o. +cos =: 2&o. +tan =: 3&o. + +sinh =: 5&o. +cosh =: 6&o. +tanh =: 7&o. + +asin =: _1&o. +acos =: _2&o. +atan =: _3&o. + +asinh =: _5&o. +acosh =: _6&o. +atanh =: _7&o. + +jsinh =: sin&.j. +jcosh =: cos@ j. +jasin =: asinh&.j. +jatan =: atanh&.j. + +a=:r.?20$1000 + +(sinh -: jsinh) a +(cosh -: jcosh) a +(asin -: jasin) a +(atan -: jatan) a + + +NB. o. ------------------------------------------------------------------ + +a =: (_4+?20$10) j. _4+?20$10 +(o.a) -: a*o.1 + +p =: (0 4+/1 2 3)o.0.35 +q =: 0.3428978074554513492 0.93937271284737892 0.36502849 +q =: q,: 0.357189729 1.061877819 0.33637554 +1e_8 > >./|, p - q + +x =: 0.01*(+ 0j1&*)/_400+?2$900 +(2 3 o. x) -: (}.3j4 2 3) o. x +(1 2 o. x) -: (}.3.5 1 2) o. x +(5 o. x) -: ({:3j4 5) o. x +(6 o. x) -: ({:3.7 6) o. x +(1 o. a) -: (4-3) o. a + + +NB. model of x o. y ---------------------------------------------------- +NB. See Chapter 4 of Abramowitz and Stegun [1964]. + +pi =: o.1 +sin =: 1&o. NB. a function in the C library +cos =: 2&o. NB. a function in the C library +sinh =: 5&o. NB. a function in the C library +cosh =: 6&o. NB. a function in the C library + +cir0 =: 1&+ %:@* 1&- +zp4 =: -&0j1 %:@* +&0j1 +zp8 =: 0j1&+ %:@* 0j1&- +zm4 =: +&1 * -&1 %:@% +&1 +real =: -:@(++) +imag =: %&0j2@(-+) +zarc =: 0j_1&*@^.@*`0: @. (0&=) + +zsin =: ((sin@[ * cosh@]) j. ( cos@[ * sinh@]))/@+. +zcos =: ((cos@[ * cosh@]) j. (-@sin@[ * sinh@]))/@+. +ztan =: zsin % zcos +zsinh =: zsin&.j. +zcosh =: zcos@j. +ztanh =: ztan&.j. + +zasin =: zasinh&.j. +zacos =: (-:pi)&-@zasin +zatan =: zatanh&.j. +zasinh =: (^.@+ zp4)`($:&.-) @. (0&>@real) +zacosh =: ]`(j.@|@imag)@.(0&>@real) @ (^.@+ zm4) +zatanh =: 1&+ -:@^.@% 1&- + +cirp =: (cir0@])`(zsin@])`(zcos@])`(ztan@])`(zp4@])`(zsinh@])`(zcosh@])`(ztanh@])`(zp8@])`(real@])`(|@])`(imag@])`(zarc@]) @. [ +cirm =: (cir0@])`(zasin@])`(zacos@])`(zatan@])`(zm4@])`(zasinh@])`(zacosh@])`(zatanh@])`(-@zp8@])`]`(+@])`(j.@])`(r.@]) @. (|@[) +circle =: cirp`cirm @. (0&>@[) " 0 + +a =: r.?20$1000 +( i.13) (o./ = circle/) a +(-i.13) (o./ = circle/) a + +'domain error' -: o. etx 'Opposable Thumbs' +'domain error' -: o. etx ;:'sui generis' + +'domain error' -: 'a' o. etx 3.4 +'domain error' -: 3.5 o. etx 3.4 +'domain error' -: 3j5 o. etx 3.4 +'domain error' -: (<4) o. etx 3.4 +'domain error' -: 17 o. etx 2 +'domain error' -: _17 o. etx 2 + +'domain error' -: 1 o. etx 'abc' +'domain error' -: 1 o. etx <'abc' + +'length error' -: 2 3 o. etx 0.5 0.4 0.3 + + +NB. o. on extreme arguments --------------------------------------------- + +'limit error' -: 1 o. etx 9e9 +'limit error' -: 1 o. etx o. 9e9 +'limit error' -: 1 o. etx {. 9e9 0j1 +'limit error' -: 1 o. etx _9e9 +'limit error' -: 1 o. etx o._9e9 +'limit error' -: 1 o. etx {._9e9 0j1 +'limit error' -: 1 o. etx _ +'limit error' -: 1 o. etx {._ 0j1 +'limit error' -: 1 o. etx __ +'limit error' -: 1 o. etx {.__ 0j1 +'limit error' -: 1 o. etx 1e9j2 +'limit error' -: 1 o. etx _1e9j2 + +(j. -:^600) -: 1 o. 0j600 +(j.--:^600) -: 1 o. 0j_600 + +NB. A&S 4.3.55 sin z = sin x cosh y + i cos x sinh y +((_*1 o. x) j. _ * 2 o. x) = 1 o. x j. 999 [ x=: i:6 +((_*1 o. x) j. __ * 2 o. x) = 1 o. x j. _999 [ x=: i:6 + +'limit error' -: 2 o. etx 9e9 +'limit error' -: 2 o. etx o. 9e9 +'limit error' -: 2 o. etx {. 9e9 0j1 +'limit error' -: 2 o. etx _9e9 +'limit error' -: 2 o. etx o._9e9 +'limit error' -: 2 o. etx {._9e9 0j1 +'limit error' -: 2 o. etx _ +'limit error' -: 2 o. etx {._ 0j1 +'limit error' -: 2 o. etx __ +'limit error' -: 2 o. etx {.__ 0j1 +'limit error' -: 2 o. etx 1e9j2 +'limit error' -: 2 o. etx _1e9j2 + +(-:^600) -: 2 o. 0j600 +(-:^600) -: 2 o. 0j_600 + +NB. A&S 4.3.56 cos z = cos x cosh y - i sin x sinh y +((_*2 o. x) j. __ * 1 o. x) = 2 o. x j. 999 [ x=: i:6 +((_*2 o. x) j. _ * 1 o. x) = 2 o. x j. _999 [ x=: i:6 + +'limit error' -: 3 o. etx 9e9 +'limit error' -: 3 o. etx o. 9e9 +'limit error' -: 3 o. etx {. 9e9 0j1 +'limit error' -: 3 o. etx _9e9 +'limit error' -: 3 o. etx o._9e9 +'limit error' -: 3 o. etx {._9e9 0j1 +'limit error' -: 3 o. etx _ +'limit error' -: 3 o. etx __ +'limit error' -: 3 o. etx 1e9j2 +'limit error' -: 3 o. etx _1e9j2 + +_ = 5 o. 1000 +_ = 5 o. {. 1000 0j5 +_ = 5 o. _ +_ = 5 o. {. _ 0j5 +__ = 5 o. _1000 +__ = 5 o. {._1000 0j5 +__ = 5 o. __ +__ = 5 o. {.__ 0j5 + +'limit error' -: 5 o. etx 2j1e9 +'limit error' -: 5 o. etx 2j_1e9 + +((_ * 2 o. y) j. _ * 1 o. y) = 5 o. 999 j. y=: i:6 +((__ * 2 o. y) j. _ * 1 o. y) = 5 o. _999 j. y=: i:6 + +_ = 6 o. 1000 +_ = 6 o. {. 1000 0j5 +_ = 6 o. _ +_ = 6 o. {. _ 0j5 +_ = 6 o. _1000 +_ = 6 o. {._1000 0j5 +_ = 6 o. __ +_ = 6 o. {.__ 0j5 + +'limit error' -: 6 o. etx 2j1e9 +'limit error' -: 6 o. etx 2j_1e9 + +((_ * 2 o. y) j. _ * 1 o. y) = 6 o. 999 j. y=: i:6 +((_ * 2 o. y) j. __ * 1 o. y) = 6 o. _999 j. y=: i:6 + +1 -: 7 o. 1000 +1 -: 7 o. _ +_1 -: 7 o. _1000 +_1 -: 7 o. __ + +1 -: 7 o. 710j2 +1 -: 7 o. 710j1e9 +_1 -: 7 o. _710j2 +_1 -: 7 o. _710j1e9 + +'limit error' -: 7 o. etx 2j6e8 +'limit error' -: 7 o. etx 2j_6e8 + +0.5p1 _0.5p1 -: _3 o. 1e16 _1e16 +0.5p1 _0.5p1 -: _3 o. _ __ +(0*x)={:"1 +. _3 o. x=:1e_10*_5000+?4 5$1e4 + + +4!:55 ;:'a acos acosh asin asinh atan atanh b cir0 cir4 ' +4!:55 ;:'cir4m cir8 cir8m circle cirm cirp cos cosh imag ' +4!:55 ;:'jasin jatan jcosh jsinh p pi q real sin sinh ' +4!:55 ;:'tan tanh x y z zacos zacosh zarc zasin zasinh zatan ' +4!:55 ;:'zatanh zcos zcosh zm4 zp4 zp8 zsin zsinh ztan ztanh ' + +
new file mode 100644 --- /dev/null +++ b/test/goi.ijs @@ -0,0 +1,60 @@ +NB. o./ B --------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./ -: cir/ ) x=. ? 23$2 +(o./ -: cir/ ) x=. ?3 23$2 +(o./"1 -: cir/"1) x +(o./ -: cir/ ) x=. ?7 5 23$2 +(o./"1 -: cir/"1) x +(o./"2 -: cir/"2) x + +(o./ -: cir/ ) x=. ? 24$2 +(o./ -: cir/ ) x=. ?4 12$2 +(o./"1 -: cir/"1) x +(o./ -: cir/ ) x=. ?4 2 8$2 +(o./"1 -: cir/"1) x +(o./"2 -: cir/"2) x + + +NB. o./ I --------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./ -: cir/ ) x=. _5+? 3$13 +(o./ -: cir/ ) x=. _5+?2 3$13 +(o./"1 -: cir/"1) x +(o./ -: cir/ ) x=. _3+?2 3 3$7 +(o./"1 -: cir/"1) x +(o./"2 -: cir/"2) x + + +NB. o./ D --------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./ -: cir/ ) x=. [&.o. _5+?2 $13 +(o./ -: cir/ ) x=. [&.o. _5+?2 3$13 +(o./"1 -: cir/"1) x +(o./ -: cir/ ) x=. [&.o. _5+?2 3 3$13 +(o./"1 -: cir/"1) x +(o./"2 -: cir/"2) x + + +NB. o./ Z --------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./ -: cir/ ) x=.[&.j._5+?2 $13 +(o./ -: cir/ ) x=.[&.j._5+?2 3$13 +(o./"1 -: cir/"1) x +(o./ -: cir/ ) x=.[&.j._5+?2 3 3$13 +(o./"1 -: cir/"1) x +(o./"2 -: cir/"2) x + +'domain error' -: o./ etx 'eleemosynary' +'domain error' -: o./ etx ;:'quod erat demonstratum' + +4!:55 ;:'cir x' + +
new file mode 100644 --- /dev/null +++ b/test/goox.ijs @@ -0,0 +1,36 @@ +NB. order of execution -------------------------------------------------- + +g=: 3 : 0 + y + : + x,y +) + +f=: 3 : 0 + y [ xx=: xx,'f',y + : + x,y [ xx=: xx,'f',x,y +) + +h=: 3 : 0 + y [ xx=: xx,'h',y + : + x,y [ xx=: xx,'h',x,y +) + +'bb' -: (f g h) 'b' [ xx=: $0 +xx -: 'hbfb' + +'abab' -: 'a' (f g h) 'b' [ xx=: $0 +xx -: 'habfab' + +'ab' -: 'a' g&h 'b' [ xx=: $0 +xx -: 'hbha' + +'ab' -: 'a' g&:h 'b' [ xx=: $0 +xx -: 'hbha' + + +4!:55 ;:'f g h xx' + +
new file mode 100644 --- /dev/null +++ b/test/gop.ijs @@ -0,0 +1,29 @@ +NB. o./\ B -------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./\"1 -: cir/\"1) #:i.16 + +(o./\ -: cir/\ ) x=.0<? 13$4 +(o./\ -: cir/\ ) x=.0<?7 13$4 +(o./\"1 -: cir/\"1) x +(o./\ -: cir/\ ) x=.0<?3 5 13$4 +(o./\"1 -: cir/\"1) x +(o./\"2 -: cir/\"2) x + +(o./\ -: cir/\ ) x=.0<? 16$4 +(o./\ -: cir/\ ) x=.0<?8 16$4 +(o./\"1 -: cir/\"1) x +(o./\ -: cir/\ ) x=.0<?2 4 16$4 +(o./\"1 -: cir/\"1) x +(o./\"2 -: cir/\"2) x + +(,'j') -: o./\'j' +(,<'ace') -: o./\<'ace' + +'domain error' -: o./\ etx 'sesquipedalian' +'domain error' -: o./\ etx ;:'super cali fragi listic espi ali do cious' + +4!:55 ;:'cir x' + +
new file mode 100644 --- /dev/null +++ b/test/gos.ijs @@ -0,0 +1,63 @@ +NB. o./\. B ------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./\. -: cir/\. ) x=. ? 23$2 +(o./\. -: cir/\. ) x=. ?3 23$2 +(o./\."1 -: cir/\."1) x +(o./\. -: cir/\. ) x=. ?7 5 23$2 +(o./\."1 -: cir/\."1) x +(o./\."2 -: cir/\."2) x + +(o./\. -: cir/\. ) x=. ? 24$2 +(o./\. -: cir/\. ) x=. ?4 12$2 +(o./\."1 -: cir/\."1) x +(o./\. -: cir/\. ) x=. ?4 2 8$2 +(o./\."1 -: cir/\."1) x +(o./\."2 -: cir/\."2) x + + +NB. o./\. I ------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./\. -: cir/\. ) x=. _12+? 2$25 +(o./\. -: cir/\. ) x=. _12+?2 2$25 +(o./\."1 -: cir/\."1) x +(o./\. -: cir/\. ) x=. _12+?2 2 2$25 +(o./\."1 -: cir/\."1) x +(o./\."2 -: cir/\."2) x + + +NB. o./\. D ------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./\. -: cir/\. ) x=. [&.o. _7+? 2$15 +(o./\. -: cir/\. ) x=. [&.o. _7+?2 2$15 +(o./\."1 -: cir/\."1) x +(o./\. -: cir/\. ) x=. [&.o. _7+?2 2 2$15 +(o./\."1 -: cir/\."1) x +(o./\."2 -: cir/\."2) x + + +NB. o./\. Z ------------------------------------------------------------- + +cir=. 4 : 'x o. y' + +(o./\. -: cir/\. ) x=.[&.j._7+? 2$15 +(o./\. -: cir/\. ) x=.[&.j._7+?2 2$15 +(o./\."1 -: cir/\."1) x +(o./\. -: cir/\. ) x=.[&.j._7+?2 2 2$15 +(o./\."1 -: cir/\."1) x +(o./\."2 -: cir/\."2) x + +(,'j') -: o./\. 'j' +(,<123) -: o./\. <123 + +'domain error' -: o./\. etx 'eleemosynary' +'domain error' -: o./\. etx ;:'quod erat demonstratum' + +4!:55 ;:'cir x' + +
new file mode 100644 --- /dev/null +++ b/test/gpco.ijs @@ -0,0 +1,101 @@ +NB. p: ------------------------------------------------------------------ + +pt =. 1&< *. *./@(0&~:)@(2&}.@i.@>:@<.@%: |/ ]) + +(p: i.25) -: (pt"0 # ]) i.100 +(p: i.25) -: p:"0 i.25 +1 = #@q: p:i.5 20 + +v =.p:i.2000 +({&v -: p:) ?2 $2000 +({&v -: p:) ?20 $2000 +({&v -: p:) ?200 $2000 +({&v -: p:) ?2000$2000 + +2147483629 -: p: 105097563 +2147483647 -: p: 105097564 +(<._1+2^31) -: p: 105097564 + +NB. LeVeque, Fundamentals of Number Theory, Addison-Wesley, 1977, p. 5. + +0 1 -: 1e1 < p: _1 0+ 4 +0 1 -: 1e2 < p: _1 0+ 25 +0 1 -: 1e3 < p: _1 0+ 168 +0 1 -: 1e4 < p: _1 0+ 1229 +0 1 -: 1e5 < p: _1 0+ 9592 +0 1 -: 1e6 < p: _1 0+ 78498 +0 1 -: 1e7 < p: _1 0+ 664579 +0 1 -: 1e8 < p: _1 0+ 5761455 +0 1 -: 1e9 < p: _1 0+ 50847534 + +4 = 3!:0 p: 100 +4 = 3!:0 p: {.100 4.5 +64 = 3!:0 p: 100x +64 = 3!:0 p: 100r1 + +'domain error' -: p: etx _1 +'domain error' -: p: etx <.-2^31 +'domain error' -: p: etx '5' +'domain error' -: p: etx <12 +'domain error' -: p: etx 3.4 +'domain error' -: p: etx 3j4 + +'limit error' -: p: etx 1e30 +'limit error' -: p: etx 10^30x + +P100 =: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 +plt100 =: P100&< # P100"_ + +0 0 0 0 0 -: p:^:_1 ] _1 _2 0 1 2 +(p:^:_1 t) -: p:^:_1 >. t=: o. 3 4?@$ 20 + +mask =: [ $&> ($ - {. 1:)&.>@] +sieve =: ] , [: }. -.@(+./)@mask # >:@i.@[ +plt =: plt100 ` (sieve $:@>:@<.@%:) @. (100&<) + +(plt -: i.&.(p:^:_1))"0 i.5 20 +(plt -: i.&.(p:^:_1))"0 ]100*i.5 20 + +plt1=: 3 : 0 + m=. y-1 + z=. m (>: # ]) 2 3 5 + if. 5>:y do. return. end. + b=. 1 0:}m $ 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 + r=. <.%:m + while. r>:j=.1+b i. 0 do. + z=. z,j + b=. b +. m$(-j){.1 + end. + z=. z,1+(-.b)#i.m +) + +(plt1 -: i.&.(p:^:_1))"0 i.5 20 +(plt1 -: i.&.(p:^:_1))"0 ]100*i.5 20 + + +NB. p: Goldbach's conjecture -------------------------------------------- + +Goldbach=: 3 : 0 + j =. }. i.<:-:y + z =. (1+#j)$2 + p =. i.&.(p:^:_1) y + pt=. 1 p}y$0 + i =. 1 + whilst. #j=. (-.c)#j do. + c=. pt {~ (4++:j)-i{p + z=. (i{p) (c#j)}z + i=. >:i + end. + (4+i.@<:&.-:y) (,. ,. -) z +) + +t=: Goldbach n=: 4+2*?1e5 +($t) -: (<:-:n),3 +({."1 t) -: 4+i.@<:&.-: n +({."1 t) -: +/"1 }."1 t +*./ , (}."1 t) e. i.&.(p:^:_1) n + + +4!:55 ;:'Goldbach mask n P100 plt plt1 plt100 pt sieve t v' + +
new file mode 100644 --- /dev/null +++ b/test/gpco2.ijs @@ -0,0 +1,131 @@ +NB. p: dyad ------------------------------------------------------------- + +isprime=: (1 = #@q:) :: 0: "0 + +( 1&p: -: isprime ) x=: 1+2*100 ?@$ 2e5 +( 0&p: -: -.@(1&p:)) x +(_1&p: -: p:^:_1 ) x + +x=: <._1+2^31 +(1&p: -: isprime) x- i.50 +(1&p: -: isprime) x- i.50x +(1&p: -: isprime) x-2*i.50 +(1&p: -: isprime) x-2*i.50x +(1&p: -: isprime) x+ i:50 +(1&p: -: isprime) x+2*i:50 + +1 p: x=: p: 10 ?@$ 1e7 +1 p: x=: {:@q: 10 #. 6 18 ?@$ 10x + +1 0 0 -: 1 p: 2x 1r2 1r3 + +x=: i: 30 +b=: x e. i.&.(p:^:_1) 30 +b -: 1 p: x=: i: 30 +b -: 1 p: x: x +b -: 1 p: x+-~0.5 +b -: 1 p: x+-~0j5 +b -: 1 p: x+-~1r5 + +f1=: 3 : 0 + c=. 4 p: y + assert. c -: 4 p: x: y + assert. 1 p: c + assert. 0 p: ; (1+y) +&.> i.&.>c-1+y + 1 +) + +2 3 -: 4 p: __ 2 +2 3 -: 4 p: __ 2x +(($x)$2) -: 4 p: x=: 100 ?@$ 2 +(p: i.x) -: 4&p:^:(<x) 2 [ x=: ?200 + +f1 x=: 100 ?@$ 1e8 +f1 x=: p: 100 ?@$ 1e6 + +2147483659x -: 4 p: 2147483647 +0 = 1 p: 2147483647x+1+i.11 + +2147483629 -: _4 p: 2147483647 +0 = 1 p: 2147483629x+1+i.17 + +f2=: 3 : 0 + c=. _4 p: y + assert. c -: _4 p: x: y + assert. 1 p: c + assert. 0 p: ; (1+c) +&.> i.&.>y-1+c + 1 +) + +f2 x=: 3+100 ?@$ 1e8 +f2 x=: p: 1+100 ?@$ 1e6 + +(_4 p: 2.1) -: _4 p: 3 + +tot=: 3 : '+/1=y+.i.y' " 0 +0 1 1 = 5 p: 0 1 2 +(tot -: 5&p:) i.4 5 +(tot -: 5&p:) i.4 5x +(tot -: 5&p:) x=: 100 ?@$ 1000 + +tot=: 3 : 0 " 0 + 'p e'=. __ q: y + */(p-1)*p^e-1 +) + +(tot -: 5&p:) x=: 100 ?@$ 2e9 +(tot -: 5&p:) x=: 1 + */"1 ] 5 10 ?@$ 100x + +x=: 100 +y=: +/1000$0.1 +c=: _4 _1 0 1 2 3 4 5 +(c p:&.>x) -: c p:&.>y + +'4&p:' -: _4&p: b. _1 +'p:' -: _1&p: b. _1 +'*/@(^/)"2 :.(2&p:)' -: 2&p: b. _1 +'*/' -: 3&p: b. _1 +'_4&p:' -: 4&p: b. _1 + +'domain error' -: 12 p: etx 4 5 6 +'domain error' -: _2 p: etx 4 5 6 +'domain error' -: 3j4 p: etx 4 5 6 +'domain error' -: 1r2 p: etx 4 5 6 +'domain error' -: '1' p: etx 4 5 6 +'domain error' -: (<1) p: etx 4 5 6 + +'domain error' -: 1 p: etx '123' +'domain error' -: 1 p: etx u: '123' +'domain error' -: 1 p: etx 1;2;3 + +'domain error' -: 1 p: etx 13x _ +'domain error' -: 1 p: etx 13x __ +'domain error' -: 1 p: etx 1.3 _ +'domain error' -: 1 p: etx 1.3 __ +'domain error' -: 1 p: etx 1j3 _ +'domain error' -: 1 p: etx 1j3 __ + +'domain error' -: 4 p: etx 2 3j4 +'domain error' -: 4 p: etx '234' +'domain error' -: 4 p: etx 2;34 +'domain error' -: 4 p: etx u: 2 3 4 + +'domain error' -: _4 p: etx 4 3 2 +'domain error' -: _4 p: etx 4 3 2x +'domain error' -: _4 p: etx 1.9 12 +'domain error' -: _4 p: etx _5 12 +'domain error' -: _4 p: etx _5 12x +'domain error' -: _4 p: etx 0 1 0 0 +'domain error' -: _4 p: etx '456' +'domain error' -: _4 p: etx 1 2 3j4 +'domain error' -: _4 p: etx u: 2 3 4 + +'domain error' -: 5 p: etx 2 3 4 _5 +'domain error' -: 5 p: etx 2 3 4 _5x + +'rank error' -: 0 1 p: etx 4 5 6 + + +4!:55 ;:'b c f1 f2 isprime tot x y' + +
new file mode 100644 --- /dev/null +++ b/test/gpcoinv.ijs @@ -0,0 +1,34 @@ +NB. p:^:_1 -------------------------------------------------------------- + +f =. p:^:_1 + +([ -: f@:p:) x=.i.200 +([ -: f@:p:) x=.?500$400 +([ -: f@:p:) x=.1e6*>:i.105 + +v =. p: i.200 +(f -: +/@(v&<)"0) x=.i.500 +(f -: +/@(v&<)"0) x=.?500${:v + +(i.@2: -: [ <: p:@(_1 0&+)@f)"0 x=.(v{~?20$#v)-.2 +(i.@2: -: [ <: p:@(_1 0&+)@f)"0 x=.?5$2e9 + +105097564 = f <._1+2^31 + +NB. LeVeque, Fundamentals of Number Theory, Addison-Wesley, 1977, p. 5. + +0 = f 1e0 +4 = f 1e1 +25 = f 1e2 +168 = f 1e3 +1229 = f 1e4 +9592 = f 1e5 +78498 = f 1e6 +664579 = f 1e7 +5761455 = f 1e8 +50847534 = f 1e9 + + +4!:55 ;:'f v x' + +
new file mode 100644 --- /dev/null +++ b/test/gpdd.ijs @@ -0,0 +1,38 @@ +NB. p.. y --------------------------------------------------------------- + +2 6 12 -: p.. 1 2 3 4 + +(,0) -: p.. 3j4 +(,0) -: p.. i.0 +(,0) -: p.. '' + +(,!6 ) -: p..^:6 ]7 $1 +(,!88x) -: p..^:88 ]89$1x + +( 2&o. t. i.10x) -: p.. 1&o. t. i.11x +(-@(1&o.) t. i.10x) -: p.. 2&o. t. i.11x +( 6&o. t. i.10x) -: p.. 5&o. t. i.11x +( 5&o. t. i.10x) -: p.. 6&o. t. i.11x + + +'domain error' -: p.. etx 'abc' + + +NB. x p.. y ------------------------------------------------------------- + +(1 2 1.5,4%3) -: 1 p.. 2 3 4 +(1 2 3r2 4r3) -: 1 p.. 2 3 4x + +x -: ({.x) p.. p.. x=: ?10$100 + +(%!i.10x) -: p../10$1x + + +'domain error' -: 3 p.. etx 'abc' +'domain error' -: 'x' p.. etx 3 4 +'domain error' -: (<4) p.. etx 3 4 + + +4!:55 ;:'x' + +
new file mode 100644 --- /dev/null +++ b/test/gpi.ijs @@ -0,0 +1,17 @@ +NB. pi ------------------------------------------------------------------ + +NB. pi and the common mean (AGM, arithmetic-geometric mean) +NB. see http://www.shef.ac.uk/~puremath/theorems/amgm.html + +am=: +/ % # +gm=: */ %:~ # +cm=: [: {. (am,gm)^:_ + +t=: (am,gm)^:(i.10) 1,%%:2 +'a b'=: |: t +(o.1) e. (}. 2**:a) % }: 1 - +/\ (2^i.#a) * a-&*:b + + +4!:55 ;:'a am b cm gm t' + +
new file mode 100644 --- /dev/null +++ b/test/gpick.ijs @@ -0,0 +1,32 @@ +NB. {:: ----------------------------------------------------------------- + +boxed=: (32&=)@(3!:0) +cat =: { @: (i.&.>) @: $ + +pick=: >@({&>/)@(<"0@|.@[ , <@]) " 1 _ + +map =: a:&mapp +mapp=: 4 : 'if. boxed y do. (<"0 x,&.><"0 cat y) mapp&.> y else. >x end.' + +sz =: 3 : '>spread_temp' +si =: 3 : 'y [ spread_temp=:$0' +sc =: 3 : '0: spread_temp=:spread_temp,<y' +S =: 2 : 'sz@(sc@x L: y)&si' + +t=: 5!:2 <'pick' + +({:: -: map) t +({:: -: map) cat L:0 t + +(< S: 0 -: < S 0) t +(< S: 0 -: < S 0) ,~^:5 t +(< S: 1 -: < S 1) {:: t +(< S: 1 -: < S 1) {:: cat L: 0 t + +(< S: 0 t) -: (< S: 1 {::t){::&.><t +(<@": S: 0 t) -: (;:5!:5 <'pick') -. ;:'()' + + +4!:55 ;:'boxed cat map mapp pick S sc spread_temp si sz t' + +
new file mode 100644 --- /dev/null +++ b/test/gpoly.ijs @@ -0,0 +1,325 @@ +NB. p. y ---------------------------------------------------------------- + +test =: 3 : 0 + c=: y + x=: 1024 %~ _500+? 40$10000 + z=: j./1024 %~ _500+?2 40$10000 + r=: p. c + d=: p. r + assert. *./ 1e_6 > c (+/@:|@[ %~ |@]) c p. >{:r + assert. *./ 1e_13 > c %&(+/@:|)~ -/c,:d + assert. (c p. z) -:!.1e_12 r p. z + assert. (c p. z) -:!.1e_12 d p. z + assert. (c p. x) -:!.1e_12 r p. x + assert. (c p. x) -:!.1e_12 d p. x + assert. (p. c) -: p. c,0 0 0 0 0 + 1 +) + +test _10+?11$25 +test _10+?10$25 +test _10+? 9$25 + +test j./_10+?2 11$25 +test j./_10+?2 10$25 +test j./_10+?2 9$25 + +4!:55 ;:'c d r x z' + +(1;n$_1) -: p. n!~i.>:n=:>:?15 +(n!~i.>:n) -: p. <n$_1 +((|.(1+n)$1 _1)*n!~i.>:n) -: p. <n$1 + +1e_14 > | (p.&< p. ]) r=:1 0 1 +1e_14 > | (p.&< p. ]) r=:1 0 1 1 +1e_14 > | (p.&< p. ]) r=:2 3 4 +1e_14 > | (p.&< p. ]) r=:2 3 4 5 +1e_14 > | (p.&< p. ]) r=:2 3 4.5 +1e_14 > | (p.&< p. ]) r=:2 3 4.5 6 +1e_14 > | (p.&< p. ]) r=:1j2 3j4 5 +1e_14 > | (p.&< p. ]) r=:1j2 3j4 5 6 +1e_14 > | (p.&< p. ]) r=:5j7 5j_7 1j2 + +(p.<r) -: p. ({.1 1 );}.2, r=:_7+?3$20 +(p.<r) -: p. ({.1 1 );}.2.5,r +(p.<r) -: p. ({.1 1 );}.2j5,r +(p.<r) -: p. ({.1 2 );}.2, r +(p.<r) -: p. ({.1 2 );}.2.5,r +(p.<r) -: p. ({.1 2 );}.2j5,r +(p.<r) -: p. ({.1 2 );}.2, r +(p.<r) -: p. ({.1 2 );}.2.5,r +(p.<r) -: p. ({.1 2 );}.2j5,r +(p.<r) -: p. ({.1 2.5);}.2, r +(p.<r) -: p. ({.1 2.5);}.2.5,r +(p.<r) -: p. ({.1 2.5);}.2j5,r +(p.<r) -: p. ({.1 2j5);}.2, r +(p.<r) -: p. ({.1 2j5);}.2.5,r +(p.<r) -: p. ({.1 2j5);}.2j5,r + +(0;'') -: p. '' +(0;'') -: p. i.0 +(0;'') -: p. 0$<'' +(0;'') -: p. 0 +(0;'') -: p. ,0 +(0;'') -: p. 0 0 0 0 0 + +(1;,r) -: p. 1,~-r=:o._400+?1000 +(1;,r) -: p. 1,~-r=:r._400+?1000 + +f =: 3 : ('''a b c''=.|.y'; '(+:a)%~-b(+,-)%:(*:b)-4*a*c') +(f -:&(/:~) >@{:@p.) c=:(0.1*_500+?2$2000),>:?500 +(f -:&(/:~) >@{:@p.) c=:r.(0.1*_500+?2$2000),>:?500 + +(-: p.^:2) 0j1 0j1 +(-: p.^:2) 3j4;i._4 + +(,1) -: p. <'' +(,1) -: p. <i.0 +(,1) -: p. a: + +'domain error' -: p. etx 'abcd' +'domain error' -: p. etx <'abcd' +'domain error' -: p. etx <<3 4 5 +'domain error' -: p. etx 4;'abcd' +'domain error' -: p. etx 4;<<2 3 4 +'domain error' -: p. etx 'a' ;3 4 5 6 +'domain error' -: p. etx (<3);3 4 5 6 +'domain error' -: p. etx 4 +'domain error' -: p. etx 4 0 0 0 0 + +'length error' -: p. etx 3;4 5 6;7 8 9 10 + +'rank error' -: p. etx 3;i.3 4 +'rank error' -: p. etx 3;i.0 0 +'rank error' -: p. etx (,3);3 4 5 6 +'rank error' -: p. etx '';3 4 5 6 +'rank error' -: p. etx 2 3;3 4 5 6 + + +NB. "difficult" roots --------------------------------------------------- + +NB. examples from Nakano, Yamashita, and Nishikawa, Vector 21.2, Spring 2005 + +c=: '' +c=: c,< _4 6 _3 1 +c=: c,< _9 9 _3 1 +c=: c,< _2 6 _6 1 +c=: c,< _18 18 _6 1 +c=: c,< _3 9 _9 1 +c=: c,< _12 18 _9 1 +c=: c,< _1 6 _12 1 +c=: c,< _4 12 _12 1 +c=: c,< _9 18 _12 1 +c=: c,< _5 15 _15 1 +c=: c,< _20 30 _15 1 +c=: c,< 12 _30 27 _10 1 +c=: c,< 2 _3 _3 6 0 _3 1 +c=: c,< 175 210 99 _40 _33 _10 1 0 1 +r=: >@{:@p.&.> c +1e_12 > c >./@:|@:p.&> r + +c=: 1 50000 1 NB. Andrew Nikitin +r=: >{:p. c +1e_6 > >./ | c p. r + +test=: 3 : 0 NB. finding roots exactly + assert. r1 -:!.0&(/:~) r=: >{:p. c=: p. <r1=: y + 1 +) + +test 2,10$1 +test 1r2,10$1r3 +test 1024,10$1r2 +test 4 5#1r2 1r3 +test 4 5#1r3 1r2 +test 1+i.20 NB. Wilkinson monster + +ptimes=: +//.@(*/) NB. polynomial multiplication +c=: (p.<3j4 3j_4) ptimes p. <1r2,8$1r3 +r=: >{:p. c +NB. r -:&(/:~) 3j4 3j_4,1r2,8$1r3 + + +NB. p. roots of unity --------------------------------------------------- + +rou =: ^@:j.@:o.@:+:@(%~i.) +rov =: >@{:@p.@(_1&,)@({.&1)@- +rs =: \: +. + +1e_12 > (rou (>./)@(<./)@:|@(-/) rov)"0 >:i.10 + +err =: - %&(+/)&:| ] +f =: p.@<@rou +g =: _1&,@({.&1)@- + +1e_11 >| (f err g)"0 >:i.10 + + +NB. x p. y -------------------------------------------------------------- + +pc =: ([ +/@:* i.@#@[ ^~ ])"1 0 +pr =: (>@{.@[ * >@{:@[ */@:-~ ])"1 0 +fc =: *./@,@:(p. -: pc) +fr =: *./@,@:(p. -: pr) + +NB. Boolean + +(x=:?5$2) fc y=:?7$2 +(x=:?5$2) fc y=:_7+?2 3 4$13 +(x=:?2$2) fc y=:o._7+?3 4$13 +(x=:?6$2) fc y=:r._7+?2 1 4$13 + +NB. integer + +(x=:_5+?5$11) fc y=:?7$2 +(x=:_5+?5$11) fc y=:_7+?2 3 4$13 +(x=:_5+?2$11) fc y=:o._7+?3 4$13 +(x=:_5+?6$11) fc y=:r._7+?2 1 4$13 + +NB. real + +(x=:_2.5+?5$11) fc y=:?7$2 +(x=:_2.5+?5$11) fc y=:_7+?2 3 4$13 +(x=:_2.5+?2$11) fc y=:o._7+?3 4$13 +(x=:o._4+?6$11) fc y=:r._7+?2 1 4$13 + +NB. complex + +(x=:j./_5+?2 5$11) fc y=:?7$2 +(x=:r.?5$110) fc y=:_7+?2 3 4$13 +(x=:r.?2$110) fc y=:o._7+?3 4$13 +(x=:r._4+?6$11) fc y=:r._7+?2 1 4$13 + +'' fc y=:?3 4$2 +'' fc y=:?3 4 1$100 +'' fc y=:o.?3 4$100 +'' fc y=:r.?3 4$100 + +($0) fc y=:?3 4$2 +($0) fc y=:?3 4 1$100 +($0) fc y=:o.?3 4$100 +($0) fc y=:r.?3 4$100 + +(( <1 2 3) p. x) -: (1;1 2 3) p. x=:?2 3 4$100 +((,<1 2 3) p. x) -: (1;1 2 3) p. x=:?2 3 4$100 + +((2 ;1r7) p. x) -: 2 * x-1r7 [ x=: ?2 3 4$100 +((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: ?2 3 4$100 +((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: ?2 3 4$100 + +((2 ;1r7) p. x) -: 2 * x-1r7 [ x=: o.?2 3 4$100 +((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: o.?2 3 4$100 +((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: o.?2 3 4$100 + +((2 ;1r7) p. x) -: 2 * x-1r7 [ x=: j./?2 3 4$100 +((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: j./?2 3 4$100 +((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: j./?2 3 4$100 + +(i.2 3) fc"1 i.5 + +x=: 2 5 ?@$ 10 +y=: 2 ?@$ 12 +x (p."2 1 -: p."1 0"2 1) y + +'domain error' -: 'abc' p. etx 3 +'domain error' -: 4 5 6 p. etx 'ab' +'domain error' -: 1 2 3 p. etx <4 5 6 +'domain error' -: 1 2 3 p. etx <3;4 5 6 +'domain error' -: (3;4 5) p. etx 'ab' +'domain error' -: ('a';_3 7) p. etx 4 5 +'domain error' -: (3;'abc') p. etx 4 5 +'domain error' -: (3;<<1 2 3) p. etx 4 5 +'domain error' -: ((<3);2 3) p. etx 4 5 + +'length error' -: (i.2 4) p. etx 3 4 5 +'length error' -: (3;4 5;6 7) p. etx 1 2 3 4 + +'rank error' -: (3 4;1 2 3) p. etx 4 5 +'rank error' -: (3;i.2 3) p. etx 4 5 + + +NB. x p.!.s y ----------------------------------------------------------- + +f =: 4 : '+/x*y^!.s i.#x' +g =: 4 : '+/x*}:1,*/\y+(i.#x)*/s' + +x=:-:_10+?7$20 +y=:0.25*_15+?4$30 + +(x p.!.s y) -: x f"1 0 y [ s=:_1 +(x p.!.s y) -: x g"1 0 y +(x p.!.s y) -: x f"1 0 y [ s=:3j4 +(x p.!.s y) -: x g"1 0 y + +'domain error' -: ex 'p.!.(<234)' +'domain error' -: ex 'p.!.''x''' + +'domain error' -: 'abc' p.!.1 etx 5 +'domain error' -: 2 3 4 p.!.1 etx 'x' +'domain error' -: (<2 3)p.!.1 etx 5 + +'length error' -: (i.2 3) p.!.1 etx 4 5 6 + + +NB. p. model ------------------------------------------------------------ + +NB. Reference: Press et al., "Numerical Recipes in C" + +mt =: i.@0: NB. empty vector constant function +boxed=: (32&=)@(3!:0) NB. 1 iff boxed +div =: % (+ 0&=) NB. like % but avoids division by 0 + +n =: <:@#@[ NB. degree +d1 =: }.@(* i.@#)@[ pdot ] NB. 1st derivative +d2 =: 2&}.@(* +:@(2&!)@i.@#)@[ pdot ] NB. 2nd derivative +g =: d1 % pdot +h =: *:@g - d2 % pdot +sq =: [: %: (n-1:) * (n * h) - *:@g +emm =: {.@\:@:| { ] NB. element with maximum magnitude +del =: n div [: emm g (+,-) sq NB. corrective term +delta=: del`0:@.(0&=@pdot) NB. corrective term, or 0 if at root +lg =: ] - delta NB. one iteration of Laguerre's method + +root =: lg^:_ >@{. lg^:_ 0: NB. one root using Laguerre's method +rem =: _2&}.@[ , _2&{@[ + _1&{@[ * ] NB. remainder from one trial division +dfl =: mt`((rem$:]),{:@[)@.(1&<@#@[) NB. deflate by linear factor +step =: root ((dfl~>@{.) ; (,>@{:)) ] NB. update one root +rfc =: [ step^:n [;mt NB. roots from coefficients + +pm =: [: +//. */ NB. polynomial multiplication +cfr =: {.@>@{. * [: pm/ -@>@{: ,. 1: NB. coefficients from roots + +pdot1=: rfc`cfr @. boxed NB. model of p. monad + +evc =: [ +/ .* ] ^ i.@#@[ NB. evaluate w.r.t. coefficients +evr =: [: */ >@{.@[ , ] - >@{:@[ NB. evaluate w.r.t. roots +pdot2=: evc`evr @. (boxed@[) NB. model of p. dyad + +pdot =: pdot1 : pdot2 " 1 1 0 NB. model of p. + +x=: (_5+?4$12),1 +r=: _5+?5$12 +c=: {.(_5+?5$12)-.0 +y=: 0.01*_100+? 20$200 +z=: j./0.01*_100+?2 20$200 + +NB. a=: p. x +NB. b=: pdot x +NB. (>{.a) = >{.b +NB. a=:>{:a +NB. b=:>{:b +NB. (($a)-:$b) *. (*./a e. b) *. *./b e. a + +NB. (p. -: pdot) c;r +NB. x (p. -: pdot) y +NB. x (p. -: pdot) z +NB. (c;r) (p. -: pdot) y +NB. (c;r) (p. -: pdot) z + + +4!:55 ;:'a b boxed c cfr d d1 d2 del delta dfl ' +4!:55 ;:'div emm err evc evr f fc fr g h ' +4!:55 ;:'lg mt n p pc pdot pdot1 pdot2 pm pr ptimes r r1' +4!:55 ;:'rem rfc root rou rov rs s sq step test x y z ' + +
new file mode 100644 --- /dev/null +++ b/test/gq.ijs @@ -0,0 +1,641 @@ +NB. rational numbers ---------------------------------------------------- + +rat =: 128&=@type +xint=: 64&=@type +fl =: 8&=@type +cmpx=: 16&=@type + + +NB. = ------------------------------------------------------------------- + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$5 +(a=/b) -: a ( [ =/ x:@]) b +(a=/b) -: a (x:@[ =/ ]) b +(a=/b) -: a (x:@[ =/ x:@]) b + +a=. _50+?13$100 +b=. b,-b=.%/1+?2 20$5 +(a=/b) -: a ( [ =/ x:@]) b +(a=/b) -: a (x:@[ =/ ]) b +(a=/b) -: a (x:@[ =/ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a= b) -: a ( [ = x:@]) b +(a= b) -: a (x:@[ = ]) b +(a= b) -: a (x:@[ = x:@]) b +(a=/b) -: a ( [ =/ x:@]) b +(a=/b) -: a (x:@[ =/ ]) b +(a=/b) -: a (x:@[ =/ x:@]) b + +1 0 1 -: 1r2 3r4 2r5 = 0.5 3j4 0.4 +0 0 0 -: 1r2 = 'abc' +0 0 0 -: 1r2 = ;:'foo upon thee' + + +NB. < ------------------------------------------------------------------- + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a</b) -: a ( [ </ x:@]) b +(a</b) -: a (x:@[ </ ]) b +(a</b) -: a (x:@[ </ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a</b) -: a ( [ </ x:@]) b +(a</b) -: a (x:@[ </ ]) b +(a</b) -: a (x:@[ </ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a< b) -: a ( [ < x:@]) b +(a< b) -: a (x:@[ < ]) b +(a< b) -: a (x:@[ < x:@]) b +(a</b) -: a ( [ </ x:@]) b +(a</b) -: a (x:@[ </ ]) b +(a</b) -: a (x:@[ </ x:@]) b + +'domain error' -: 1r2 < etx 3j4 +'domain error' -: 1r2 < etx 'a' +'domain error' -: 1r2 < etx <12 +'domain error' -: 3j4 < etx 1r3 +'domain error' -: 'a' < etx 1r3 +'domain error' -: (<12)< etx 1r3 + + +NB. <. ------------------------------------------------------------------ + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a<./b) -: a ( [ <./ x:@]) b +(a<./b) -: a (x:@[ <./ ]) b +(a<./b) -: a (x:@[ <./ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a<./b) -: a ( [ <./ x:@]) b +(a<./b) -: a (x:@[ <./ ]) b +(a<./b) -: a (x:@[ <./ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a<. b) -: a ( [ <. x:@]) b +(a<. b) -: a (x:@[ <. ]) b +(a<. b) -: a (x:@[ <. x:@]) b +(a<./b) -: a ( [ <./ x:@]) b +(a<./b) -: a (x:@[ <./ ]) b +(a<./b) -: a (x:@[ <./ x:@]) b + +'domain error' -: 1r2 <. etx 3j4 +'domain error' -: 1r2 <. etx 'a' +'domain error' -: 1r2 <. etx <12 +'domain error' -: 3j4 <. etx 1r3 +'domain error' -: 'a' <. etx 1r3 +'domain error' -: (<12)<. etx 1r3 + + +NB. <: ------------------------------------------------------------------ + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a<:/b) -: a ( [ <:/ x:@]) b +(a<:/b) -: a (x:@[ <:/ ]) b +(a<:/b) -: a (x:@[ <:/ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a<:/b) -: a ( [ <:/ x:@]) b +(a<:/b) -: a (x:@[ <:/ ]) b +(a<:/b) -: a (x:@[ <:/ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a<: b) -: a ( [ <: x:@]) b +(a<: b) -: a (x:@[ <: ]) b +(a<: b) -: a (x:@[ <: x:@]) b +(a<:/b) -: a ( [ <:/ x:@]) b +(a<:/b) -: a (x:@[ <:/ ]) b +(a<:/b) -: a (x:@[ <:/ x:@]) b + +'domain error' -: 1r2 <: etx 3j4 +'domain error' -: 1r2 <: etx 'a' +'domain error' -: 1r2 <: etx <12 +'domain error' -: 3j4 <: etx 1r3 +'domain error' -: 'a' <: etx 1r3 +'domain error' -: (<12)<: etx 1r3 + + +NB. > ------------------------------------------------------------------- + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a>/b) -: a ( [ >/ x:@]) b +(a>/b) -: a (x:@[ >/ ]) b +(a>/b) -: a (x:@[ >/ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a>/b) -: a ( [ >/ x:@]) b +(a>/b) -: a (x:@[ >/ ]) b +(a>/b) -: a (x:@[ >/ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a>/b) -: a ( [ >/ x:@]) b +(a>/b) -: a (x:@[ >/ ]) b +(a>/b) -: a (x:@[ >/ x:@]) b + +'domain error' -: 1r2 > etx 3j4 +'domain error' -: 1r2 > etx 'a' +'domain error' -: 1r2 > etx <12 +'domain error' -: 3j4 > etx 1r3 +'domain error' -: 'a' > etx 1r3 +'domain error' -: (<12)> etx 1r3 + + +NB. >. ------------------------------------------------------------------ + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a>./b) -: a ( [ >./ x:@]) b +(a>./b) -: a (x:@[ >./ ]) b +(a>./b) -: a (x:@[ >./ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a>./b) -: a ( [ >./ x:@]) b +(a>./b) -: a (x:@[ >./ ]) b +(a>./b) -: a (x:@[ >./ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a>./b) -: a ( [ >./ x:@]) b +(a>./b) -: a (x:@[ >./ ]) b +(a>./b) -: a (x:@[ >./ x:@]) b + +'domain error' -: 1r2 >. etx 3j4 +'domain error' -: 1r2 >. etx 'a' +'domain error' -: 1r2 >. etx <12 +'domain error' -: 3j4 >. etx 1r3 +'domain error' -: 'a' >. etx 1r3 +'domain error' -: (<12)>. etx 1r3 + + +NB. >: ------------------------------------------------------------------ + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$20 +(a>:/b) -: a ( [ >:/ x:@]) b +(a>:/b) -: a (x:@[ >:/ ]) b +(a>:/b) -: a (x:@[ >:/ x:@]) b + +a=. _5000+?13$10000 +b=. b,-b=.%/1+?2 20$20 +(a>:/b) -: a ( [ >:/ x:@]) b +(a>:/b) -: a (x:@[ >:/ ]) b +(a>:/b) -: a (x:@[ >:/ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a>: b) -: a ( [ >: x:@]) b +(a>: b) -: a (x:@[ >: ]) b +(a>: b) -: a (x:@[ >: x:@]) b +(a>:/b) -: a ( [ >:/ x:@]) b +(a>:/b) -: a (x:@[ >:/ ]) b +(a>:/b) -: a (x:@[ >:/ x:@]) b + +'domain error' -: 1r2 >: etx 3j4 +'domain error' -: 1r2 >: etx 'a' +'domain error' -: 1r2 >: etx <12 +'domain error' -: 3j4 >: etx 1r3 +'domain error' -: 'a' >: etx 1r3 +'domain error' -: (<12)>: etx 1r3 + + +NB. + ------------------------------------------------------------------- + + 11r6 -: 1r2 + 4r3 + _5r6 -: 1r2 + _4r3 + 5r6 -: _1r2 + 4r3 +_11r6 -: _1r2 + _4r3 + +(fl y) *. 6 -: y=. 5r2 + 3.5 +(fl y) *. 6 -: y=. 2.5 + 7r2 +(rat y) *. 6 -: y=. 5r2 + 7r2 + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 + +*./ 1e_14 > , (a+/b) - a (x:@[ +/ x:@]) b +*./ 1e_14 > , (a+/b) - a ( [ +/ x:@]) b +*./ 1e_14 > , (a+/b) - a (x:@[ +/ ]) b + +(+/%x) -: +/ % x: x=.1+i.12 + +'domain error' -: 1r2 + etx 'a' +'domain error' -: 1r2 + etx <12 +'domain error' -: 'a' + etx 1r3 +'domain error' -: (<12)+ etx 1r3 + + +NB. +. ------------------------------------------------------------------ +NB. +: ------------------------------------------------------------------ + +NB. * ------------------------------------------------------------------- + + 2r3 -: 1r2 * 4r3 +_2r3 -: 1r2 * _4r3 +_2r3 -: _1r2 * 4r3 + 2r3 -: _1r2 * _4r3 + +(fl y) *. 8.75 -: y=. 5r2 * 3.5 +(fl y) *. 8.75 -: y=. 2.5 * 7r2 +(rat y) *. 35r4 -: y=. 5r2 * 7r2 + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 + +(a*/b) -: a (x:@[ */ x:@]) b +(a*/b) -: a ( [ */ x:@]) b +(a*/b) -: a (x:@[ */ ]) b + +1e_16 > | (*/%x) - */ % x: x=.1+i.9 + +'domain error' -: 1r2 * etx 'a' +'domain error' -: 1r2 * etx <12 +'domain error' -: 'a' * etx 1r3 +'domain error' -: (<12)* etx 1r3 + + +NB. *. ------------------------------------------------------------------ +NB. *: ------------------------------------------------------------------ + +NB. - ------------------------------------------------------------------- + + _5r6 -: 1r2 - 4r3 + 11r6 -: 1r2 - _4r3 +_11r6 -: _1r2 - 4r3 + 5r6 -: _1r2 - _4r3 + +(fl y) *. _1 -: y=. 5r2 - 3.5 +(fl y) *. _1 -: y=. 2.5 - 7r2 +(rat y) *. _1 -: y=. 5r2 - 7r2 + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 + +*./ 1e_14 > , (a-/b) - a (x:@[ -/ x:@]) b +*./ 1e_14 > , (a-/b) - a ( [ -/ x:@]) b +*./ 1e_14 > , (a-/b) - a (x:@[ -/ ]) b + +(-/%x) -: -/ % x: x=.1+i.12 + +'domain error' -: 1r2 - etx 'a' +'domain error' -: 1r2 - etx <12 +'domain error' -: 'a' - etx 1r3 +'domain error' -: (<12)- etx 1r3 + + +NB. % ------------------------------------------------------------------- + + 3r8 -: 1r2 % 4r3 +_3r8 -: 1r2 % _4r3 +_3r8 -: _1r2 % 4r3 + 3r8 -: _1r2 % _4r3 + +(fl y) *. (5%7) -: y=. 5r2 % 3.5 +(fl y) *. (5%7) -: y=. 2.5 % 7r2 +(rat y) *. 5r7 -: y=. 5r2 % 7r2 + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 + +(a%/b) -:!.1e_13 a (x:@[ %/ x:@]) b +(a%/b) -:!.1e_13 a ( [ %/ x:@]) b +(a%/b) -:!.1e_13 a (x:@[ %/ ]) b + +(%/%x) -: %/ % x: x=.1+i.12 + +0 = 0 % 0r1 +_ = 4 % 0r1 +__ = _4 % 0r1 + +64 = type 0r1 +64 = type 0 % 0r1 +(4%x+2.5-2.5) -: 4 % x=.1 2 3 4 0r1 +128 = type 4 % x + +'domain error' -: 1r2 % etx 'a' +'domain error' -: 1r2 % etx <12 +'domain error' -: 'a' % etx 1r3 +'domain error' -: (<12)% etx 1r3 + + +NB. %. ------------------------------------------------------------------ + +Hilbert=: x: @: % @: >: @: (+/~) @: i. + +(=i.#h) -: h +/ .* %. h=. Hilbert 5 +(=i.#h) -: h +/ .* %. h=. Hilbert 6 +(=i.#h) -: h +/ .* %. h=. Hilbert 7 + +(%. -: %.@:x:) i.8 +(%. -: %.@:x:) ,8 +(%. -: %.@:x:) 8 +(%. -: %.@:x:) i.0 +1e_13 > >./| , (%. - %.@:x:) x=._50+?7 7$100 +1e_13 > >./| , (%. - %.@:x:) x=._50+?7 5$100 + +'domain error' -: %. etx 3 3$1r2 + + +NB. %: ------------------------------------------------------------------ + +(%: 2.5) -: %: 5r2 +(%:_2.5) -: %:_5r2 +(%: 25 ) -: %: 25r1 + +(%:_1 ) -: %: _1r1 +(%:_0.5) -: %: _1r2 + +(3 %: 8) -: 3 %: 8r1 + +rat %: *: 7r2 +7r2 -: %: *: 7r2 +(%: 3.5) -: %: 7r2 +(%:_3.5) -: %:_7r2 + + +NB. ^ ------------------------------------------------------------------- + +(^ 2.5) -: ^ 5r2 +(^ _2.5) -: ^ _5r2 + +(xint x) *. 0r1 = x=. 0r1 ^ 1 +(xint x) *. 0r1 = x=. 0r1 ^ 5 +(xint x) *. 0r1 = x=. 0r1 ^ 5x +(rat x) *. 0r1 = x=. 0r1 ^ 5r2 +(rat x) *. 0r1 = x=. 0r1 ^ 1 2 3 5r2 + +(fl x) *. 0 = x=. 0r1 ^ 1p1 + +(xint x) *. 1r1 = x=. 0r1 ^ 0 +(xint x) *. 1r1 = x=. 0r1 ^ 0x +(xint x) *. 1r1 = x=. 0r1 ^ 0r1 + +(xint x) *. 1r1 = x=. 1r1 ^ 5 +(xint x) *. 1r1 = x=. 1r1 ^ 5x +(rat x) *. 1r1 = x=. 1r1 ^ 5r2 +(xint x) *. 1r1 = x=. 1r1 ^ _5 +(rat x) *. 1r1 = x=. 1r1 ^ _5r2 +(xint x) *. 1r1 = x=. 1r1 ^ 0 +(xint x) *. 1r1 = x=. 1r1 ^ _5+i.11 + +(fl x) *. 1 = x=. 1r1 ^ 1p1 + +_ -: 0r1 ^ _5r1 +_ -: 0r1 ^ _5r2 +0 0 0 0 _ -: 0r1 ^ 1 2 3 4 _5r1 +0 0 0 0 _ -: 0r1 ^ 1 2 3 4 _5r2 + +stope=: 1 : 0 + : + */x+m*i.y +) + +(2 ^!.1r2 i.10) -: 2 (1r2 stope)"0 i.10 +(2 ^!.1r2 i.10) -: 2 ^!.0.5 i.10 +(3r4 ^!.0.5 i.10) -: 3r4 (0.5 stope)"0 i.10 +(3r4 ^!.0.5 i.10) -: 0.75 ^!.0.5 i.10 + + +NB. $ ------------------------------------------------------------------- + +(12 $'abcd') -: 12r1 $ 'abcd' +(12 3$'abcd') -: (12 3r1)$ 'abcd' + +'domain error' -: 12r7 $ etx 'abcd' +'domain error' -: 3 12r7 $ etx 'abcd' + + +NB. ~. ------------------------------------------------------------------ + +NB. ~: ------------------------------------------------------------------ + +a=. ?13$2 +b=. b,-b=.%/1+?2 20$5 +(a~:/b) -: a ( [ ~:/ x:@]) b +(a~:/b) -: a (x:@[ ~:/ ]) b +(a~:/b) -: a (x:@[ ~:/ x:@]) b + +a=. _50+?13$100 +b=. b,-b=.%/1+?2 20$5 +(a~:/b) -: a ( [ ~:/ x:@]) b +(a~:/b) -: a (x:@[ ~:/ ]) b +(a~:/b) -: a (x:@[ ~:/ x:@]) b + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 +(a~: b) -: a ( [ ~: x:@]) b +(a~: b) -: a (x:@[ ~: ]) b +(a~: b) -: a (x:@[ ~: x:@]) b +(a~:/b) -: a ( [ ~:/ x:@]) b +(a~:/b) -: a (x:@[ ~:/ ]) b +(a~:/b) -: a (x:@[ ~:/ x:@]) b + +0 1 0 -: 1r2 3r4 2r5 ~: 0.5 3j4 0.4 +1 1 1 -: 1r2 ~: 'abc' +1 1 1 -: 1r2 ~: ;:'foo upon thee' + + +NB. | ------------------------------------------------------------------- + +a=. a,-a=.%/1+?2 20$20 +b=. b,-b=.%/1+?2 20$20 + +(| x: a) -: x: | a +(| a) -: | &. x: a + +1e_13> |, (x: a|/b) - a |/&:x: b +1e_13> |, ( a|/b) - a |/&.x: b + +x -: 0r1 | x=.0r1 _5r2 5r2 1234567890123456789r7777 _1234567890123456789r7777 + + +NB. . ------------------------------------------------------------------- + +(-/ .* -: -/ .*@:x:) x=._500+? 3 3$1000 +(-/ .* -: -/ .*@:x:) x=. %/1+?2 3 3$1000 + +(+/ .* -: +/ .*@:x:) x=._500+? 3 3$1000 +(+/ .* -: +/ .*@:x:) x=. %/1+?2 3 3$1000 + +Hilbert=: x: @: % @: >: @: (+/~) @: i. +f =: i.&.(p:^:_1)@+: +g =: ~.@q:@%@(-/ .*)@Hilbert + +(f -: g)"0 i.4 5 + + +NB. : ------------------------------------------------------------------- + +f=: 3 : 0 + if. y do. 'ja' else. 'nein' end. +) + +'ja' -: f 3r1 +'ja' -: f 1r777777777 0 0 0 +'nein' -: f 0r1 5r1 + + +NB. , ------------------------------------------------------------------- + +(rat x) *. 512 3r2 -: x=. 512,3r2 +(rat x) *. 5r2 3r1 -: x=. 5r2,3 +(rat x) *. 5r1 3r2 -: x=. 5x ,3r2 +(rat x) *. 5r2 3r1 -: x=. 5r2,3x +(rat x) *. 5r2 3r1 -: x=. 5r2,3 +(rat x) *. 5r2 3r4 -: x=. 5r2,3r4 + +(fl x) *. 2.5 3.4 -: x=. 5r2,3.4 +(fl x) *. 2.5 3.4 -: x=. 2.5,17r5 +(fl x) *. 1 2 3.4 2.5 _0.2 -: x=. 1 2 3.4, 5r2 _1r5 +(fl x) *. 2.5 _0.2 1 2 3.4 -: x=. 1 2 3.4,~5r2 _1r5 + +(cmpx x) *. 2.5 3j4 -: x=. 5r2,3j4 +(cmpx x) *. 2j5 3.4 -: x=. 2j5,17r5 +(cmpx x) *. 1 2 3j4 2.5 _0.2 -: x=. 1 2 3j4, 5r2 _1r5 +(cmpx x) *. 2.5 _0.2 1 2 3j4 -: x=. 1 2 3j4,~5r2 _1r5 + +'domain error' -: 5r2 , etx 'abc' +'domain error' -: 'abc' , etx 5r2 +'domain error' -: 5r2 , etx <'x' +'domain error' -: (<'x'), etx 5r2 + + +NB. # ------------------------------------------------------------------- + +(2#y) -: 2r1#y=.?10$10000 +(x#1r2 _3r4) -: x: x#0.5 _0.75 [ x=.?2$1000 + +'domain error' -: 1r2 # etx 3 4 5 + + +NB. #. ------------------------------------------------------------------ +NB. #: ------------------------------------------------------------------ +NB. ! ------------------------------------------------------------------- + +120x -: ! 5r1 +(!i.10) -: ! 0r1 1r1 2r1 3r1 4r1 5r1 6r1 7r1 8r1 9r1 + +(!2.5) -: ! 5r2 + + +NB. 3!:x ---------------------------------------------------------------- + +128 = type 1r2 3r4 + +ir =: 3!:1 +ri =: 3!:2 +hex=: 3!:3 + +x -: ri ir x=. %/*: x:1+?2 4 5$1000000 +x -: ri hex x + + +NB. /: ------------------------------------------------------------------ + +(0.66;2r3;0.67) -: /:~ 2r3; 0.66 ; 0.67 + + +NB. \: ------------------------------------------------------------------ + +(0.67;2r3;0.66) -: \:~ 2r3; 0.66 ; 0.67 + + +NB. { ------------------------------------------------------------------- + +({x;y) -: x ,&.>/ y [ x=.0 1 0 1 [ y=. 5r2 _1r5 +({x;y) -: x ,&.>/ y [ x=.1 2 314 [ y=. 5r2 _1r5 +({x;y) -: x ,&.>/ y [ x=.1 2 31x [ y=. 5r2 _1r5 +({x;y) -: x ,&.>/ y [ x=.1 2 3.4 [ y=. 5r2 _1r5 +({x;y) -: x ,&.>/ y [ x=.1 2 3j4 [ y=. 5r2 _1r5 + +'domain error' -: { etx 1r2 3r4 ; 'abc' +'domain error' -: { etx 1r2 3r4 ; <1;2;3 + + +NB. ". ------------------------------------------------------------------ +NB. extended integer comparisons ---------------------------------------- +NB. A. ------------------------------------------------------------------ +NB. e. ------------------------------------------------------------------ + + +NB. i. ------------------------------------------------------------------ + +(i.5) -: i. 5r1 + +'domain error' -: i. etx 5r2 +'domain error' -: i. etx 12345678901234567890r1 + + +x=.?1000$1000 +y=. (1000?1000){x + +(x i. x) -: x i.&:x: x +(x i. y) -: x i.&:x: y + +x=.?1000 3$1000 +y=. (1000?1000){x + +(x i. x) -: x i.&:x: x +(x i. y) -: x i.&:x: y + + +NB. o. ------------------------------------------------------------------ + +0 = ( o. 2%3) - o. 2r3 + +0 = (1 o. 2%3) - 1 o. 2r3 +0 = (2 o. 2%3) - 2 o. 2r3 +0 = (3 o. 2%3) - 3 o. 2r3 +0 = (4 o. 2%3) - 4 o. 2r3 +0 = (5 o. 2%3) - 5 o. 2r3 +0 = (6 o. 2%3) - 6 o. 2r3 +0 = (7 o. 2%3) - 7 o. 2r3 + + +NB. p. ------------------------------------------------------------------ + +r=. 1r2 2 4 +c=. _4 11 _13r2 1r1 + +(rat y) *. c -: y=.p. <r +(rat y) *. (314*c) -: y=.p. 314;r +(fl y) *. (3.4*c) -: y=.p. 3.4;r +(cmpx y) *. (3j4*c) -: y=.p. 3j4;r + +0r1 = c p. r +0r1 = (<r) p. r + +'domain error' -: p. etx 'a';r +'domain error' -: p. etx 1r2;'abc' + +1 2 3 4 (p.!.1r2 -: p.!.0.5) 5 +1 2 3 4 (p.!._2r1 -: p.!._2 ) 5 + + +NB. q: ------------------------------------------------------------------ + +(q: x) -: q: x: x=.?1e9 + +'domain error' -: q: etx 5r2 +'domain error' -: q: etx _9r1 + + +4!:55 ;:'a b c cmpx f g fl h hex Hilbert ir' +4!:55 ;:'r rat ri stope x xint y' + +
new file mode 100644 --- /dev/null +++ b/test/gq101.ijs @@ -0,0 +1,26 @@ +NB. rational numbers +. ------------------------------------------------- + +gcd=: 4 : 0 " 0 + x=. |x + y=. |y + while. r=. y|x do. + x=. y + y=. r + end. +) + +x=: %/ 0 1x + ?2 100$2e9 +y=: %/ 0 1x + ?2 100$2e9 + +x (+. -: gcd) y +0 (+. -: gcd) y +x (+. -: gcd) 0 +x (+. -: gcd) x + +x=: (+%)/\90$1x +(i{x) (+. -: gcd) j{x [ i=: ?10$#x [ j=: ?10$#x + + +4!:55 ;:'gcd i j x y' + +
new file mode 100644 --- /dev/null +++ b/test/gq132.ijs @@ -0,0 +1,61 @@ +NB. %: ------------------------------------------------------------------ + +rat =: 128&=@type + +(%: 2.5) -: %: 5r2 +(%:_2.5) -: %:_5r2 +(%: 25 ) -: %: 25r1 + +(%:_1 ) -: %: _1r1 +(%:_0.5) -: %: _1r2 + +(3 %: 8) -: 3 %: 8r1 + +rat %: *: 7r2 +7r2 -: %: *: 7r2 +(%: 3.5) -: %: 7r2 +(%:_3.5) -: %:_7r2 + + + +NB. %: ------------------------------------------------------------------ + +NB. Pell Equation +NB. Integer solutions of 1=(x^2)-N*(y^2), N not a perfect square + +NB. continued fraction expansion of %:N +NB. do computations in Z[%:N] + +cfsqrt=: 3 : 0 + N=. y + p=. 0x + q=. 1x + r=. %:N + assert. r~:<.r NB. not a perfect square + m0=. <.q%~p+r + z=. $0 + while. 1 do. + m=. <.q%~p+r + t=. (m*q)-p + q=. q%~N-*:p-m*q + p=. t + if. m=2*m0 do. x: z return. end. + z=. z, m + end. +) + +test=: 3 : 0 + N=: y + v=: cfsqrt N + 'xx yy'=: 2 x: (+%)/v + (xx^2) - N*yy^2 +) + +*./ 1 _1 e.~ t=. test"0 (-. <.&.:%:) i.100 + +*./ 1 _1 e.~ t=. test 1+*:1+?1000 + + +4!:55 ;:'cfsqrt N rat t test v xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gq201.ijs @@ -0,0 +1,81 @@ +NB. ^. on extended integers and rational numbers ------------------------ + +test=: 4 : 0 + assert. y -: x ^. x ^ x: y + assert. (<:y)= x <.@^. <: x^ x: y + assert. y = x <.@^. >: x^ x: y + assert. y = x >.@^. <: x^ x: y + assert. (>:y)= x >.@^. >: x^ x: y + 1 +) + +2 test y=: 2+10 10?@$300 +3 test y +10 test y +16 test y + +12345 test 17 +12345678 test 23 + +31 -: 2 ^. x=:*/31$x: 2 +31 -: 2 <.@^. x +31 -: 2 >.@^. x +30 -: 2 <.@^.<:x +31 -: 2 >.@^.<:x +31 -: 2 <.@^.>:x +32 -: 2 >.@^.>:x + +0 -: 314159 <.@^. x: 1 +0 -: 314159 >.@^. x: 1 + +y1=: (1-1e4)+10 11 ?@$ 2e4-1 +y2=: (1-1e8)+10 11 ?@$ 2e8-1 +y3=: (1-1e9)+10 11 ?@$ 2e9-1 + +(t=.2+($y1)?@$50) (<.!.0@^. -: <.@^.&.x:) |y1+0=y1 +(t=.2+($y2)?@$50) (<.!.0@^. -: <.@^.&.x:) |y2+0=y2 +(t=.2+($y3)?@$50) (<.!.0@^. -: <.@^.&.x:) |y3+0=y3 + +(t=.2+($y1)?@$50) (>.!.0@^. -: >.@^.&.x:) |y1+0=y1 +(t=.2+($y2)?@$50) (>.!.0@^. -: >.@^.&.x:) |y2+0=y2 +(t=.2+($y3)?@$50) (>.!.0@^. -: >.@^.&.x:) |y3+0=y3 + +1 = 16x <.@^. {. 123 0.5 + +0 = 0x ^. _5 5 +__ = 1 5 6 7 ^. 0x +__ 0 _ _ = 1x ^. 0 1 2 3 + +(^. 2.5) -: ^. 5r2 + +(3.7 ^. 2.5) -: 3.7 ^. 5r2 +(3.7 ^. 2.5) -: 37r10 ^. 2.5 +(3.7 ^. 2.5) -: 37r10 ^. 5r2 + +(2048*^.2) -: ^. 2x ^2048 +(2048*^.0.5) -: ^. 1r2^2048 +(+/^.>:i.1000) -: ^. !1000x + +1000 -: 10 ^. 10x^1000 +2048 -: 2 ^. 2x^2048 + +phi=: -:>:%:5 +((^.phi)%~+/^.>:i.1000) -: phi^.!1000x +((^.phi)%~300*^.100%3 ) -: phi^.100r3^300 + +test=: 4 : 0 + xx=: x + yy=: y + assert. xx (^. = ^.&x:) yy + assert. xx (^. = ^.&x:) -yy + assert. (-xx) (^. = ^.&x:) yy + assert. (-xx) (^. = ^.&x:) -yy + 1 +) + +(0.07;1;1.5;2;7.8;10) test&>/ 0;0.1;1;2;2.11;1234;1234.5 + + +4!:55 ;:'phi t test x xx y y1 y2 y3 yy' + +
new file mode 100644 --- /dev/null +++ b/test/gqco.ijs @@ -0,0 +1,154 @@ +NB. q: ------------------------------------------------------------------ + +f =: = */ +g =: (,. -: q:)@~.@] + +'' -: q: 1 NB. Jeffrey Shallit +(i.($x),0) -: q: x=:$0 +(i.($x),0) -: q: x=:i.?~5 + +x (f *. g) q: x=:2 +x (f *. g) q: x=:*/2#2 3 5 7 11 13 +x (f *. g) q: x=:2^30 + +*./ x (f *. g)&> q:&.> x=:2+i.1000 +*./ x (f *. g)&> q:&.> x=:2+?40$<._1+2^31 +*./ x (f *. g)&> q:&.> x=:y^<.2.147e9^.~ y=:p:i.15 +*./ x (f *. g)&> q:&.> x=:*/\p: i.9 +*./ x (f *. g)&> q:&.> x=:(<._1+2^31)-i.40 +*./ x (f *. g)&> q:&.> x=:p: 1e6*>:i.105 + +x -: */"1 [ 1>.q: x=:1+?4 5$1e7 +x -: */"1 [ 1>.q:"0 x +(q: x) -: >q:&.> x + +n = */ q: n=: */ 3,29$2 + +'domain error' -: q: etx 0 +'domain error' -: q: etx '1234' +'domain error' -: q: etx _19 +'domain error' -: q: etx 3.4 +'domain error' -: q: etx 3j4 +'domain error' -: q: etx <12345 + + +NB. q: model ------------------------------------------------------------ + +max =: 1&>. @ (>./) @ , +pn =: <. @ (1.3&*) @ (% 1&>.@^.) +primes=: p: @ i. @ pn @ %: @ max +pa =: [ #~ 0: = | + +qa =: 4 : 0 + z=.p=.x pa r=.y + while. #p do. z=.z,p=.p pa r=.<.r%*/p end. + /:~z,r-.1 +) + +qco =: primes qa"1 0 ] + +(q: -: qco) 1 +(q: -: qco) >:i.10 5 +(q: -: qco) x=:1+?20$2e9 + + +NB. q: dyad ------------------------------------------------------------- + +2 0 2 1 -: _ q: 700 +2 0 2 1 0 -: 5 q: 700 + +'' -: _ q: 1 +'' -: 0 q: 1 +(,0) -: 1 q: 1 +0 0 -: 2 q: 1 + +(-: [&.(40&q:))"0 x=:1+?2 10$100 + +x -: (p:i.{:$y) */ .^"1 y=:_ q: x=:>:i.10 10 +x -: (p:i.{:$y) */ .^"1 y=:50 q: x +x -: (p:i.{:$y) */ .^"1 y=:_ q: x=:>:?10 2 7$10000 +x -: (p:i.{:$y) */ .^"1 y=:(1+p:^:_1 >./x) q: x=:>:?200$10000 + +(_ q: x) (<\@[ -: >:@i.@#@[ q:&.> ]) x=:*/>:?4$215 +(_ q: x) (<\@[ -: >:@i.@#@[ q:&.> ]) x=:*/>:?4$215 + +64 -: 3!:0 q: !100x +64 -: 3!:0 ] _ q: !100x + +300 3 -: 2 q: 27*2^300x +(i.0) -: 0 q: 1+2^1000x + + +NB. q: ------------------------------------------------------------------ + +phi =: * -.@%@~.&.q: NB. Euler's totient function + +1 = phi 1 +(p-1) -: phi"0 p=:p: i.20 +x=:b#x [ y=:b#y [ b=:1=x+.y=:?100$2e4 [ x=:>:?100$1e5 +(phi"0 x*y) -: x *&phi"0 y + +f =: 1: #. 1: = (+.i.) +*./ (f -: phi)"0 x=:>:i.200 +*./ (f -: phi)"0 x=:>:?10$1e4 + +odometer =: #: i.@(*/) +divisors =: /:~ @ (~. */ .^"1 odometer@:>:@(#/.~)) @ q: + +t2 =: [ -: +/@phi@divisors +*./ t2"0 x=:>:i.200 +*./ t2"0 x=:>:?10$2e9 + +d0=: [: +/ 0: = >:@i. | ] NB. number of divisors of n +d1=: >:@#/.~ &. q: +d2=: >:@#;.1 @ ~: &. q: +d3=: */ @: >: @: (_&q:) + +(d0 -: d1)"0 >:i.10 20 +(d0 -: d1)"0 x=:>:?10 10$1e4 +(d1 -: d2)"0 >:i.10 20 +(d1 -: d2)"0 x=:>:?10 10$1e6 +(d2 -: d3)"0 >:i.10 20 +(d2 -: d3)"0 x=:>:?10 10$1e6 + +39001250856960000x -: d3 !100x + +'domain error' -: 'a' q: etx 123 +'domain error' -: 3j5 q: etx 123 +'domain error' -: (<3)q: etx 123 + +'domain error' -: 1 q: etx 'a' +'domain error' -: 1 q: etx 0 +'domain error' -: 1 q: etx _35 +'domain error' -: 1 q: etx 3.5 +'domain error' -: 1 q: etx 3j5 +'domain error' -: 1 q: etx <35 + + +NB. q: on large integers ------------------------------------------------ + +f=: 3 : 0 + v=: q: y + assert. y=*/v + assert. v -: /:~ v + assert. (, -: q:)"0 v + 1 +) + +f x=: */ x: p: 10^i.5 +f x=: */ x: p: 10^i.6 +f x=: */ x: p: 10^i.7 +f x=: */ x: p: 10^i.8 +f x=: */ x: p: 1e7,10 ?@$ 1228 +f x=: */ x: p: 2 ?@$ 1e8 +f x=: 10 #. 18 ?@$ 10x +f x=: */ p: 1e8+0 1 2x + +f x=: 1.3e13 +f x=: 252097800629 + + +4!:55 ;:'b d0 d1 d2 d3 divisors f g max odometer p pa phi pn primes' +4!:55 ;:'qa qco t2 x y ' + +
new file mode 100644 --- /dev/null +++ b/test/gqnonrat.ijs @@ -0,0 +1,102 @@ +NB. rational approximations of non-rational functions ------------------- + +NB. e f x -- compute f x within error e +NB. n f0 x -- n terms of series for f x +NB. e nf x -- number of terms required for error e and f x + +exp0 =: ] ([: +/ ^ % !@]) i.@[ +ln0 =: 4 : '+: +/ i %~ (%/y+_1 1)^i=. 1+2*i.x' NB. AS 4.1.27 +sin0 =: ] ([: -/ ^ % !@]) >:@+:@i.@[ +cos0 =: ] ([: -/ ^ % !@]) +:@i.@[ + +nexp=: 4 : '2x + (^.x) (> i. 1:) (i*^.y)-+/\^.i=.1+i.200' +nsin=: 4 : '1x + >. !@>:@+:^:_1 %x' +ncos=: 4 : '1x + >. !@ +:^:_1 %x' + +nln =: 4 : 0 + r=. |%/(x:^:_1 y)+_1 1 + k=. 1+2*i.1+>.-:r^.-:x + 1x + (-:x) (> i. 1:) k%~r^k +) + +sin=: nsin sin0 ] +cos=: ncos cos0 ] +exp=: nexp exp0 ] + +NB. (ln x*y) = (ln x)+(ln y) +NB. (ln x^e) = e * ln x + +ln=: 4 : 0 + assert. 0<y + e=. <.2^.x:^:_1 y + r=. (x: y) % 2x^e + a=.b=.0 + if. 1~:r do. a=. (x nln r) ln0 r end. + if. 0~:e do. b=. e*(x nln 2) ln0 2x end. + a+b +) + +sqrt=: 4 : 0 + -:@(+(x:y)&%)^:x x:%:y +) + +'2.7182818284590452353602874713526624977572' -: 0j40 ": 1e_40 exp 1x +'1.010050167084168058' -: 0j18 ": 1e_18 exp 1r100 +'1.105170918075647625' -: 0j18 ": 1e_18 exp 1r10 +'1.221402758160169834' -: 0j18 ": 1e_18 exp 2r10 +'1.349858807576003104' -: 0j18 ": 1e_18 exp 3r10 +'1.491824697641270318' -: 0j18 ": 1e_18 exp 4r10 +'1.648721270700128147' -: 0j18 ": 1e_18 exp 5r10 +'1.822118800390508975' -: 0j18 ": 1e_18 exp 6r10 +'2.013752707470476522' -: 0j18 ": 1e_18 exp 7r10 +'2.225540928492467605' -: 0j18 ": 1e_18 exp 8r10 +'2.459603111156949664' -: 0j18 ": 1e_18 exp 9r10 + +'0.8414709848078965066525023216302989996226' -: 0j40 ": 1e_40 sin 1x +'0.09983341664682815230681' -: 0j23 ": 1e_23 sin 1r10 +'0.19866933079506121545941' -: 0j23 ": 1e_23 sin 2r10 +'0.29552020666133957510532' -: 0j23 ": 1e_23 sin 3r10 +'0.38941834230865049166631' -: 0j23 ": 1e_23 sin 4r10 +'0.47942553860420300027329' -: 0j23 ": 1e_23 sin 5r10 +'0.56464247339503535720095' -: 0j23 ": 1e_23 sin 6r10 +'0.64421768723769105367261' -: 0j23 ": 1e_23 sin 7r10 +'0.71735609089952276162717' -: 0j23 ": 1e_23 sin 8r10 +'0.78332690962748338846138' -: 0j23 ": 1e_23 sin 9r10 + +'0.5403023058681397174009366074429766037323' -: 0j40 ": 1e_40 cos 1x +'0.99500416527802576609556' -: 0j23 ": 1e_23 cos 1r10 +'0.98006657784124163112420' -: 0j23 ": 1e_23 cos 2r10 +'0.95533648912560601964231' -: 0j23 ": 1e_23 cos 3r10 +'0.92106099400288508279853' -: 0j23 ": 1e_23 cos 4r10 +'0.87758256189037271611628' -: 0j23 ": 1e_23 cos 5r10 +'0.82533561490967829724095' -: 0j23 ": 1e_23 cos 6r10 +'0.76484218728448842625586' -: 0j23 ": 1e_23 cos 7r10 +'0.69670670934716542092075' -: 0j23 ": 1e_23 cos 8r10 +'0.62160996827066445648472' -: 0j23 ": 1e_23 cos 9r10 + +'0.6931471805599453094172321214581765680755' -: 0j40 ": 1e_40 ln 2 +'1.0986122886681096913952452369225257046475' -: 0j40 ": 1e_40 ln 3 +'2.3025850929940456840179914546843642076011' -: 0j40 ": 1e_40 ln 10 + + +NB. notes --------------------------------------------------------------- + +sin0 =: ] ([: -/ ^ % !@]) >:@+:@i.@[ +nsin=: 4 : '1x + >. !@>:@+:^:_1 %x' +sin=: nsin sin0 ] + +1: 0 : 0 + Identities to reduce sin(x) for any x to + sin(y) or cos(y) where (0<:y)*.(y<:0.25p1) + sin(x+2*n*1p1) = sin(x) + sin(x) = sin(1p1-x) + sin(-x) = -sin(x) + sin(0.5p1+x) = cos(x) + sin(0.5p1-x) = cos(x) + +) + + +4!:55 ;:'cos cos0 exp exp0 ln ln0 ncos nexp nln nsin sin sin0 sqrt' + +
new file mode 100644 --- /dev/null +++ b/test/gr.ijs @@ -0,0 +1,32 @@ +NB. r. ------------------------------------------------------------------ + +rdot =. ^@j. : (* ^@j.) + +(r. -: rdot) 0.1*_500+?10 20$1000 +(r. -: rdot) (?40$100)*^j.?40$100 + +a =. 0.1 * _500 + ?10 20$1000 +b =. 0.1 * _500 + ?10 20$1000 +a (r. -: rdot) b +(j.a) (r. -: rdot) j.b +(3 r. b ) -: 3*^0j1*b +(a r. _4) -: a*^0j1*_4 + +1e_8 > >./| c-[&.r. c=.(_1^?200$2)*(o.1)|0.001*?200$10000 + +'domain error' -: r. etx 'abc' +'domain error' -: r. etx <'abc' + +'domain error' -: 'abc' r. etx 3 +'domain error' -: 'abc' r.~etx 3 +'domain error' -: 4 r. etx <'abc' +'domain error' -: 4 r.~etx <'abc' + +'length error' -: 3 4 r. etx 5 6 7 +'length error' -: 3 4 r.~etx 5 6 7 +'length error' -: 3 4 r. etx i.3 4 +'length error' -: 3 4 r.~etx i.3 4 + +4!:55 ;: 'a b c rdot' + +
new file mode 100644 --- /dev/null +++ b/test/gr1.ijs @@ -0,0 +1,45 @@ +NB. 2r3 ----------------------------------------------------------------- + +rat =: 128&=@type +intx=: 64&=@type +int =: 4&=@type +fl =: 8&=@type +cmpx=: 16&=@type + +5r2 -: 10r4 +5r2 -: _5r_2 +_5r2 -: 5r_2 +0r1 -: 0r7 +0r1 -: 0r_7 +0r1 -: 0r12345678901234567890 +0r1 -: 0r_12345678901234567890 + +0r1 -: 0r0 +0r1 -: 0r9 +0r1 -: 0r_9 + +(fl x) *. 1 2 3.2 -: x=. 1 4r2 3.2 +(fl x) *. 1 2 0.03 -: x=. 1 4r2 3e_2 +(int x) *. 1 2 300 -: x=. 1 4r2 3e2 +(fl x) *. 1 2 3e20 -: x=. 1 4r2 3e20 +(cmpx x) *. 1 2 3j2 -: x=. 1 4r2 3j2 +(intx x) *. 1r1 2r1 _3r1 -: x=. 1 2r1 _3x + +(rat x) *. 1 0.5 _ -: x=. 1 1r2 _ +(rat x) *. 1 0.5 __ -: x=. 1 1r2 __ +(rat x) *. 1 0.5 _ 1.25 -: x=. 1 1r2 _ 5r4 +(rat x) *. 1 0.5 __ 1.25 -: x=. 1 1r2 __ 5r4 +(rat x) *. _ 1.25 1 0.5 -: x=. _ 5r4 1 1r2 +(rat x) *. __ 1.25 1 0.5 -: x=. __ 5r4 1 1r2 + +(fl x) *. 1 0.5 _. -:&(3!:1) x=. 1 1r2 _. +(fl x) *. 1 0.5 _. 1.25 -:&(3!:1) x=. 1 1r2 _. 5r4 +(fl x) *. _. 1.25 1 0.5 -:&(3!:1) x=. _. 5r4 1 1r2 + +(rat x) *. 0.5 _ -: x=. 1r2 3r0 +(rat x) *. 0.5 __ -: x=. 1r2 _3r0 + + +4!:55 ;:'cmpx fl int intx rat x' + +
new file mode 100644 --- /dev/null +++ b/test/grefcount.ijs @@ -0,0 +1,88 @@ +NB. reference count ------------------------------------------------------ + +x=: 89$<'x=: 11 22 33' +(89 3$11 22 33) -: t=: ".&> x +x -: 11 22 33 + +f=: 3 : 0 + x=: 11 22 33 + y +) + +x=: 7$<'x=: 11 22 33' +(7#,:'x=: 11 22 33') -: t=: f&> x +x -: 11 22 33 + +x=: 89$<'x=: 11 22 33' +(i.89 0 0) -: t=: 0!:0&> x +x -: 11 22 33 + +x=: 89$<<'x' +(89$1) -: t=: 4!:55&> x +_1 = 4!:0 <'x' + +x=: 89$<'x=: 11 22 33' +(,89) -: $ t=: 6!:2&> x +x -: 11 22 33 + +x=: 89$<'x=: 11 22 33' +(,89) -: $ t=: 7!:2&> x +x -: 11 22 33 + +x=: 89$<'x=: +/' +(89$66) -: t=: x 128!:2&> <11 22 33 +'+/' -: (5!:5 <'x') + +cycle=: 1: @: (i.&.>) @: (50 ?@$ 1000"_) +NB. force cycling thru lots of small memory blocks + +f0=: 3 : 0 + a=. i.10 + t=. (a=. 123) ] a + cycle 0 + t +) + +(i.10) -: t=: f0 0 + +f1=: 3 : 0 + a=. <"0 i.10 + t=. (a=. 123) ] a + cycle 0 + t +) + +(<"0 i.10) -: t=: f1 0 + +f2=: 3 : 0 + a=. <"0 i.10 + t=. (4!:55 <'a') ] a + cycle 0 + t +) + +(<"0 i.10) -: t=: f2 0 + +f3=: 3 : 'z=. 0 [ g3 0 for_i. i.y do. z=. z+i end. z' +g3=: 3 : 'cycle (f3=: +/) 1 2' +(2!100) -: t=: f3 100 +'+/' -: 5!:5 <'f3' + +f4=: 3 : 'z=. 0 [ g4 0 for_i. i.y do. z=. z+i end. z' +g4=: 3 : 'cycle 4!:55 <''f4''' +(2!100) -: t=: f4 100 +_1 = 4!:0 <'f4' + +f5=: (g5 +/@i.@] ]) +g5=: ".@('cycle (f5=: *:) 1 2'"_) +(2!100) -: t=: f5 100 +'*:' -: 5!:5 <'f5' + +f6=: (g6 +/@i.@] ]) +g6=: cycle@(4!:55)@<@('f6'"_) +(2!100) -: t=: f6 100 +_1 = 4!:0 <'f6' + + +4!:55 ;:'cycle f f0 f1 f2 f3 g3 f4 g4 f5 g5 f6 g6 t x' +
new file mode 100644 --- /dev/null +++ b/test/gs.ijs @@ -0,0 +1,13 @@ +NB. S: ------------------------------------------------------------------ + +phi=. * -.@%@~.&.q: NB. Euler's totient function +t=. 5!:2 <'phi' + +(;:'* -.@%@~.&.q:') -: < S: 0 t + +'domain error' -: ] S: 1 etx 1;<<1 2 3 +'domain error' -: ; S: 2 etx 1;<<1 2 3 + +4!:55 ;:'phi t' + +
new file mode 100644 --- /dev/null +++ b/test/gsco.ijs @@ -0,0 +1,340 @@ +NB. s: ------------------------------------------------------------------ + +x0=: ' Cogito , ergo sum.' +y0=: s: x0 +y0 -: s: x0 +y0 -: _1 s: x0 +y0 -: _2 s: 1|.x0 +y0 -: _4 s: >;:x0 + +z0=: ;:x0 +(s:^:_1 y0) -: z0 +(1 s: y0) -: ;'`',&.>z0 +(2 s: y0) -: ;z0,&.>{.a. +(3 s: y0) -: z0,&>((>./ - ]) #&>z0)$&.>{.a. +(4 s: y0) -: >z0 +(5 s: y0) -: z0 +(, -: _1&s:@(1&s:)) y0 +(, -: _2&s:@(2&s:)) y0 +(] -: _3&s:@(3&s:)) y0 +(] -: _4&s:@(4&s:)) y0 +(] -: _5&s:@(5&s:)) y0 +(] -: _6&s:@(6&s:)) y0 + +x1=: ":"0 ?133$12000 +y1=: s: x1 +y0 -: s: x0 +y1 -: s: x1 + +z1=: (<"1 x1)-.&.>' ' +(s:^:_1 y1) -: z1 +(1 s: y1) -: ;'`',&.>z1 +(2 s: y1) -: ;z1,&.>{.a. +(3 s: y1) -: z1,&>((>./ - ]) #&>z1)$&.>{.a. +(4 s: y1) -: x1 +(5 s: y1) -: z1 +(, -: _1&s:@(1&s:)) y1 +(, -: _2&s:@(2&s:)) y1 +(] -: _3&s:@(3&s:)) y1 +(] -: _4&s:@(4&s:)) y1 +(] -: _5&s:@(5&s:)) y1 +(] -: _6&s:@(6&s:)) y1 + +x=: ;:'anaphoric boustrophedonic chthonic epigrammatic metonymic oxymoronic' +x2=: x,&.>/":&.>?100$150 +y2=: s: x2 +y0 -: s: x0 +y1 -: s: x1 +y2 -: s: x2 + +(s:^:_1 y2) -: x2 +(1 s: y2) -: ;,'`',&.>x2 +(2 s: y2) -: ;,x2,&.>{.a. +(3 s: y2) -: x2,&>((>./@, - ]) #&>x2)$&.>{.a. +(4 s: y2) -: >x2 +(5 s: y2) -: x2 +(, -: _1&s:@(1&s:)) y2 +(, -: _2&s:@(2&s:)) y2 +(] -: _3&s:@(3&s:)) y2 +(] -: _4&s:@(4&s:)) y2 +(] -: _5&s:@(5&s:)) y2 +(] -: _6&s:@(6&s:)) y2 + +(,1) -: $ s: ' singleton' + +(s: '') -: 0$ s: ' ab c' + + +NB. s: fill ------------------------------------------------------------- + +(,1) -: $ s: ' ' +({.s: ' ') -: {: 5{.s: ' ab c' +0 = 6 s: s: ' ' + +(2 4$s: ' 0 1 2 3 4 5 ') -: > (s: ' 0 1 2 3'); s: ' 4 5' +(2 4$s: ' 0 1 2 3 4 5 ') -: s:"1 (<;._1 ' 0 1 2 3'),:<;._1 ' 4 5' + + +NB. 0 s: y -------------------------------------------------------------- + +0 s: 11 + +t=: 0 s: 0 +4 -: type t +0 = #$t +1 <: t + +t=: 0 s: 1 +4 -: type t +0 = #$t +1 <: t + +t=: 0 s: 2 +4 -: type t +2 = #$t +(0 s: 0) <: #t +*./ (0<:i) *. i<: 0 s: 1 [ i=: (0 s: 0){.+/"1 (0 1){"1 t + +t=: 0 s: 3 +2 -: type t +1 = #$t +(0 s: 1) <: #t + +t=: 0 s: 4 +4 -: type t +1 = #$t +(0 s: 0) <: #t +*./ (_1=t) +. (0<:t)*.t<0 s: 0 + +t=: 0 s: 5 +4 -: type t +0 = #$t +(0 <: t) *. (t < 0 s: 0) + +t=: 0 s: 6 +4 -: type t +0 = #$t +0 <: t + +t=: 0 s: 7 +4 -: type t +0 = #$t +0 <: t + +t=: 0 s: 10 +32 -: type t +1 = #$t +(,8) -: $t +t -: 0 s:&.>i.8 + +0 s: 11 + +t=: 0 s: 12 +4 -: type t +1 = #$t +(,0 s: 0) -: $t +*./ 1 <: t +(0 s: 0) >: >./t + + +NB. 1 s: y -------------------------------------------------------------- + +x=: (;:'now is the time') ,&.>/ ":&.>?100$1e4 +y=: s: x +(;,'`',&.>x) -: 1 s: y +(,y) -: _1 s: ;,'*',&.>x + +t=: 1 s: y +2 -: type t +1 = #$t +'`' -: {.t + +x=: <"1 ] 97+?31 13 4$26 +x=: (?($x)$4){.&.>x +(, x{&.><a.) -: 5 s: _1 s: (; 32,&.>x){a. + +(0$s: ' a') -: _1 s: '' + + +NB. 2 s: y -------------------------------------------------------------- + +x=: (;:'bou stro phe don ic') ,&.>/ ":&.>?2 25$1e4 +y=: s: x +(;,x,&.>{.a.) -: 2 s: y +(,y) -: _2 s: ;,x,&.>'*' + +t=: 2 s: y +2 -: type t +1 = #$t +({.a.) -: {:t + +x=: <"1 ] 97+?31 13 4$26 +x=: (?($x)$4){.&.>x +(, x{&.><a.) -: 5 s: _2 s: (; x,&.>0){a. + +(0$s: ' a') -: _2 s: '' + + +NB. 3 s: y -------------------------------------------------------------- + +x=: (;:'el eem o syn ary') ,&.>/ ":&.>?2 3 4$1e4 +y=: s: x +m=: >./,i=: #&>x +(>x,&.>(m-i)$&.>{.a.) -: 3 s: y +y -: _3 s: >x,&.>(m-i)$&.>{.a. + +t=: 3 s: y +2 -: type t +(($x),m) = $t +(>x,&.>(m-i)$&.>{.a.) -: t + +x=: <"1 ] 97+?31 13 4$26 +x=: (?($x)$4){.&.>x +(x{&.><a.) -: 5 s: _3 s: (>x){a. + + +NB. 4 s: y -------------------------------------------------------------- + +x=: (;:'el eem o syn ary') ,&.>/ ":&.>?2 3 4$1e4 +y=: s: x +(>x) -: 4 s: y +y -: _4 s: >x + +t=: 4 s: y +2 -: type t +(($x),>./,#&>x) = $t +(>x) -: t + +x=: <"1 ] 97+?31 13 4$26 +x=: (?($x)$4){.&.>x +(x{&.><a.) -: 5 s: _4 s: >x{&.><a. + + +NB. 5 s: y -------------------------------------------------------------- + +x=: (;:'el eem o syn ary') ,&.>/ ":&.>?2 3 4$1e4 +y=: s: x +x -: 5 s: y +y -: _5 s: x + +t=: 5 s: y +32 -: type t +($y) = $t +x -: t + + +NB. 6 s: y -------------------------------------------------------------- + +x=: (;:'el eem o syn ary') ,&.>/ ":&.>?2 3 4$1e4 +y=: s: x + +t =: 6 s: y +4 -: type t +($y) = $t +y -: _6 s: t +*./ (0<:t) *.t< 0 s: 0 + + +NB. 7 s: y -------------------------------------------------------------- + +x=: (;:'el eem o syn ary') ,&.>/ ":&.>?2 3 4$1e4 +y=: s: x + +t =: 7 s: y +4 -: type t +($y) = $t + + +NB. 10 s: y ------------------------------------------------------------- + +0 s: 11 + +x=: 0 s: 10 + +'domain error' -: 10 s: etx ($x)$0 1 +'domain error' -: 10 s: etx ($x)$1 2 3 4 +'domain error' -: 10 s: etx ($x)$1 2 3.4 +'domain error' -: 10 s: etx ($x)$1 2 3j4 +'domain error' -: 10 s: etx ($x)$1 2 3r4 +'domain error' -: 10 s: etx ($x)$1 2 3 4x +'domain error' -: 10 s: etx ($x)$' 2 3 4' + +'domain error' -: 10 s: etx }.x +'domain error' -: 10 s: etx }:x +'domain error' -: 10 s: etx ,:x +'domain error' -: 10 s: etx {.x + +'domain error' -: 10 s: etx x 0}~< 'a' +'domain error' -: 10 s: etx x 0}~< 100002.4 +'domain error' -: 10 s: etx x 0}~< 100002j4 +'domain error' -: 10 s: etx x 0}~< 100002r4 +'domain error' -: 10 s: etx x 0}~< ({.x),&.>0 +'domain error' -: 10 s: etx x 0}~< 1+#>2{x +'domain error' -: 10 s: etx x 0}~< 1+#>4{x +'domain error' -: 10 s: etx x 0}~< _1e6 + +'domain error' -: 10 s: etx x 1}~< 'a' +'domain error' -: 10 s: etx x 1}~< 100002.4 +'domain error' -: 10 s: etx x 1}~< 100002j4 +'domain error' -: 10 s: etx x 1}~< 100002r4 +'domain error' -: 10 s: etx x 1}~< (1{x),&.>0 +'domain error' -: 10 s: etx x 1}~< 1+#>3{x + +'domain error' -: 10 s: etx x 3}~< 1234 +'domain error' -: 10 s: etx x 3}~< ,:>2{x +'domain error' -: 10 s: etx x 3}~< ($>2{x)$'2' +'domain error' -: 10 s: etx x 3}~< ($>2{x)$2.3 +'domain error' -: 10 s: etx x 3}~< ($>2{x)$2j3 +'domain error' -: 10 s: etx x 3}~< ($>2{x)$2r3 +'domain error' -: 10 s: etx x 3}~< }:"1 >2{x +'domain error' -: 10 s: etx x 3}~< (>2{x),.0 + + +NB. s: errors ----------------------------------------------------------- + +'domain error' -: s: etx 0 1 +'domain error' -: s: etx 0 1 2 3 +'domain error' -: s: etx 0 1 2.3 +'domain error' -: s: etx 0 1 2j3 +'domain error' -: s: etx 0 1 2 3x +'domain error' -: s: etx 0 1 2r3 + +'domain error' -: s: etx 'abc';0 1 +'domain error' -: s: etx 'abc';0 1 2 3 +'domain error' -: s: etx 'abc';0 1 2.3 +'domain error' -: s: etx 'abc';0 1 2j3 +'domain error' -: s: etx 'abc';0 1 2 3x +'domain error' -: s: etx 'abc';0 1 2r3 + +'domain error' -: 77 s: etx s: ' a b c' +'domain error' -: _39 s: etx s: ' a b c' +'domain error' -: 'a' s: etx s: ' a b c' +'domain error' -: 2.3 s: etx s: ' a b c' +'domain error' -: 2j3 s: etx s: ' a b c' +'domain error' -: 2r3 s: etx s: ' a b c' +'domain error' -: (<2)s: etx s: ' a b c' + +'domain error' -: 1 s: etx ' a bc d' +'domain error' -: 2 s: etx ' a bc d' +'domain error' -: 3 s: etx ' a bc d' +'domain error' -: 4 s: etx ' a bc d' +'domain error' -: 5 s: etx ' a bc d' + +'domain error' -: 0 s: etx 413 +'domain error' -: 0 s: etx 4.3 +'domain error' -: 0 s: etx 4j3 +'domain error' -: 0 s: etx 4r3 +'domain error' -: 0 s: etx 'abc' +'domain error' -: _9 s: etx 0 + +'domain error' -: ex ' 0&s: b. _1' +'domain error' -: ex ' 7&s: b. _1' +'domain error' -: ex '_7&s: b. _1' + +'rank error' -: s: etx 'abc';2 3$'foobar' +'rank error' -: 1 2 s: etx s: ' a bc' + + +4!:55 ;:'i m t x x0 x1 x2 y y0 y1 y2 z0 z1' + +
new file mode 100644 --- /dev/null +++ b/test/gsco1.ijs @@ -0,0 +1,60 @@ +NB. s: ------------------------------------------------------------------ + +0 s: 11 +data=: 0 s: 10 + +a=: ;:'A AAPL AMAT AMD AMZN ATT BA CRA CSCO DELL F GE GM HWP IBM INTC' +a=: a,;:'JDSU LLY LU MOT MSFT NOK NT PFE PG QCOM RMBS T XRX YHOO' +b=: ;:'NY SF LDN TOK HK FF TOR' +c=: ;:'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec' +d=: <;._1 ' 00 01 02 03 04 05 06 07 08 09' +e=: ;:'open high low close' + +t=: }.@;&.>{' ',&.>&.>a;b;c;d;<e + +q=: ":&.>?100$1e9 + +1 [ ":&.>t +1 [ ":&.>q +d=:p=:s=: 911 +b0=: 911 +b1=: 911 +s0=: 7!:3 '' +s1=: 7!:3 '' + +s0=: 7!:3 '' +b0=: 7!:0 '' + +s=: s: t +t -: 5 s: s +0 s: 11 + +d=: 0 s: 10 +(3!:1 d) 1!:2 <'foo.x' + +p=: s: q +q -: 5 s: p +0 s: 11 + +d -: 3!:2 (1!:1) <'foo.x' +10 s: d +0 s: 11 +d -: 0 s: 10 +t -: 5 s: s + +1!:55 <'foo.x' + +10 s: data +0 s: 11 + +d=:p=:s=: 911 +s1=: 7!:3 '' +b1=: 7!:0 '' + +b0 -: b1 +NB. IF64 +. s0 -: s1 + + +4!:55 ;:'a b b0 b1 c d data e p q s s0 s1 t' + +
new file mode 100644 --- /dev/null +++ b/test/gsco2.ijs @@ -0,0 +1,845 @@ +NB. s: ------------------------------------------------------------------ + +NB. create test data set + +x=: s: 'wxyz',&.>/":&.>?20$123 +y=: s: 'abcd',&.>/":&.>?20$110 +a=: {. s: ' 4' + +t=: ;:'anaphoric chthonic metonymic oxymoronic sardonic' +u=: ~. s: , t ,&.>/":&.>":&.>?10$50 +v=: /:/: u + +i=: ?3 5 7$#u +j=: ?3 5 $#u + +f=: {.s: ' ' + + +NB. = ------------------------------------------------------------------- + +(=&({&u) -: =&({&v)) i +(=&({&u) -: =&({&v)) j +(=&({&u) -: =&({&v)) ,j +(=&({&u) -: =&({&v)) '' ($,) j + +i (= &({&u) -: = &({&v)) j +i (=/ &({&u) -: =/ &({&v)) j +i (="2 1&({&u) -: ="2 1&({&v)) j + +(=/ &({&u) -: =/ &({&v)) 2{. j +(=/"1&({&u) -: =/"1&({&v)) 2{."1 j +(=/"2&({&u) -: =/"2&({&v)) 2{."2 j + +(($i)$0) -: (i{u) = i{v +(($i)$0) -: (i{u) = i{a.{~?( $u)$#a. +(($i)$0) -: (i{u) = i{ ?( $u)$2 +(($i)$0) -: (i{u) = i{ ?( $u)$1e6 +(($i)$0) -: (i{u) = i{ o.?( $u)$1e6 +(($i)$0) -: (i{u) = i{j./ ?(2,$u)$1e6 +(($i)$0) -: (i{u) = i{ ?( $u)$12000x +(($i)$0) -: (i{u) = i{ %/ ?(2,$u)$12000x + +'domain error' -: =/\ etx y +'domain error' -: =/\.etx y + + +NB. < ------------------------------------------------------------------- + +q=: (<x) ,<y +x -: >0{q +y -: >1{q + +i (< &({&u) -: < &({&v)) j +i (</ &({&u) -: </ &({&v)) j +i (<"2 1&({&u) -: <"2 1&({&v)) j + +(</ &({&u) -: </ &({&v)) 2{. j +(</"1&({&u) -: </"1&({&v)) 2{."1 j +(</"2&({&u) -: </"2&({&v)) 2{."2 j + +(>@:< -: ]) i{u +(>@:< -: ]) j{u + +'domain error' -: 3 < etx y +'domain error' -: y < etx 3 + +'domain error' -: </\ etx y +'domain error' -: </\.etx y + + +NB. <. ------------------------------------------------------------------ + +(<./ &({&u) -: {&u@(<./ &.({&v))) j +(<./ "1&({&u) -: {&u@(<./ "1&.({&v))) j +(<./ "2&({&u) -: {&u@(<./ "2&.({&v))) j + +(<./\ &({&u) -: {&u@(<./\ &.({&v))) j +(<./\ "1&({&u) -: {&u@(<./\ "1&.({&v))) j +(<./\ "2&({&u) -: {&u@(<./\ "2&.({&v))) j + +(<./\. &({&u) -: {&u@(<./\. &.({&v))) j +(<./\."1&({&u) -: {&u@(<./\."1&.({&v))) j +(<./\."2&({&u) -: {&u@(<./\."2&.({&v))) j + +i (<. &({&u) -: {&u@(<. &.({&v))) j +i (<."2 1&({&u) -: {&u@(<."2 1&.({&v))) j + +i (<./ &({&u) -: {&u@(<./ &.({&v))) j +i (<./"1 &({&u) -: {&u@(<./"1 &.({&v))) j +i (<./"2 &({&u) -: {&u@(<./"2 &.({&v))) j + +'domain error' -: <. etx y +'domain error' -: 3 <. etx y +'domain error' -: y <. etx 3 + + +NB. <: ------------------------------------------------------------------ + +i (<: &({&u) -: <: &({&v)) j +i (<:/ &({&u) -: <:/ &({&v)) j +i (<:"2 1&({&u) -: <:"2 1&({&v)) j + +(<:/ &({&u) -: <:/ &({&v)) 2{. j +(<:/"1&({&u) -: <:/"1&({&v)) 2{."1 j +(<:/"2&({&u) -: <:/"2&({&v)) 2{."2 j + +'domain error' -: <: etx y + +'domain error' -: 3 <: etx y +'domain error' -: y <: etx 3 + +'domain error' -: <:/\ etx y +'domain error' -: <:/\.etx y + + +NB. > ------------------------------------------------------------------- + +q=: x;y +x -: >0{q +y -: >1{q + +(>a;x) -: (($x){.a) ,: x +(>y;a) -: y ,: ($y){.a + +i (> &({&u) -: > &({&v)) j +i (>/ &({&u) -: >/ &({&v)) j +i (>"2 1&({&u) -: >"2 1&({&v)) j + +(>/ &({&u) -: >/ &({&v)) 2{. j +(>/"1&({&u) -: >/"1&({&v)) 2{."1 j +(>/"2&({&u) -: >/"2&({&v)) 2{."2 j + +'domain error' -: > etx 0 ;y +'domain error' -: > etx 2 ;y +'domain error' -: > etx 2.4 ;y +'domain error' -: > etx 2j4 ;y +'domain error' -: > etx 2r4 ;y +'domain error' -: > etx (<2);y +'domain error' -: > etx '22';y +'domain error' -: > etx y ;0 +'domain error' -: > etx y ;2 +'domain error' -: > etx y ;2.4 +'domain error' -: > etx y ;2j4 +'domain error' -: > etx y ;2r4 +'domain error' -: > etx y ;'22' +'domain error' -: > etx y ;<2 +'domain error' -: 3 > etx y +'domain error' -: y > etx 3 + +'domain error' -: 3 > etx y +'domain error' -: y > etx 3 + +'domain error' -: >/\ etx y +'domain error' -: >/\.etx y + + +NB. >. ------------------------------------------------------------------ + +(>./ &({&u) -: {&u@(>./ &.({&v))) j +(>./ "1&({&u) -: {&u@(>./ "1&.({&v))) j +(>./ "2&({&u) -: {&u@(>./ "2&.({&v))) j + +(>./\ &({&u) -: {&u@(>./\ &.({&v))) j +(>./\ "1&({&u) -: {&u@(>./\ "1&.({&v))) j +(>./\ "2&({&u) -: {&u@(>./\ "2&.({&v))) j + +(>./\. &({&u) -: {&u@(>./\. &.({&v))) j +(>./\."1&({&u) -: {&u@(>./\."1&.({&v))) j +(>./\."2&({&u) -: {&u@(>./\."2&.({&v))) j + +i (>. &({&u) -: {&u@(>. &.({&v))) j +i (>."2 1&({&u) -: {&u@(>."2 1&.({&v))) j + +i (>./ &({&u) -: {&u@(>./ &.({&v))) j +i (>./"1 &({&u) -: {&u@(>./"1 &.({&v))) j +i (>./"2 &({&u) -: {&u@(>./"2 &.({&v))) j + +'domain error' -: >. etx y +'domain error' -: 3 >. etx y +'domain error' -: y >. etx 3 + + +NB. >: ------------------------------------------------------------------ + +i (>: &({&u) -: >: &({&v)) j +i (>:/ &({&u) -: >:/ &({&v)) j +i (>:"2 1&({&u) -: >:"2 1&({&v)) j + +(>:/ &({&u) -: >:/ &({&v)) 2{. j +(>:/"1&({&u) -: >:/"1&({&v)) 2{."1 j +(>:/"2&({&u) -: >:/"2&({&v)) 2{."2 j + +'domain error' -: >: etx y + +'domain error' -: 3 >: etx y +'domain error' -: y >: etx 3 + +'domain error' -: >:/\ etx y +'domain error' -: >:/\.etx y + + +NB. + ------------------------------------------------------------------- + +'domain error' -: + etx y + +'domain error' -: 3 + etx y +'domain error' -: y + etx 3 + + +NB. +. ------------------------------------------------------------------ + +'domain error' -: +. etx y + +'domain error' -: 3 +. etx y +'domain error' -: y +. etx 3 +'domain error' -: x +. etx y + + +NB. +: ------------------------------------------------------------------ + +'domain error' -: +: etx y + +'domain error' -: 1 +: etx x +'domain error' -: x +: etx 1 + + +NB. - ------------------------------------------------------------------- + +'domain error' -: - etx y + +'domain error' -: 3 - etx y +'domain error' -: y - etx 3 +'domain error' -: x - etx y + + +NB. -. ------------------------------------------------------------------ + +'domain error' -: -. etx y + +(s=: ?300 $#u) (-.&({&u) -: ({&u)@-.) t=: ?30 $#u +(s=: ?200 2 $#u) (-.&({&u) -: ({&u)@-.) t=: ?20 2 $#u +(s=: ?100 2 3$#u) (-.&({&u) -: ({&u)@-.) t=: ?10 2 3$#u + + +NB. -: ------------------------------------------------------------------ + +'domain error' -: -: etx y + + +NB. * ------------------------------------------------------------------- + +'domain error' -: * etx y + +'domain error' -: 3 * etx y +'domain error' -: y * etx 3 + + +NB. *. ------------------------------------------------------------------ + +'domain error' -: *. etx y + +'domain error' -: 3 *. etx y +'domain error' -: y *. etx 3 + + +NB. *: ------------------------------------------------------------------ + +'domain error' -: *: etx y + +'domain error' -: 1 *: etx f +'domain error' -: (s:' ')*: etx 1 + + +NB. % ------------------------------------------------------------------- + +'domain error' -: % etx y + +'domain error' -: 3 % etx y +'domain error' -: y % etx 3 +'domain error' -: x % etx y + + +NB. %. ------------------------------------------------------------------ + +'domain error' -: %. etx u{~?10 3$#u + +'domain error' -: (?10$1e6) %. etx u{~?10 3$#u +'domain error' -: (u{~?7 7$#u) %. etx ?7 7$1e5 +'domain error' -: (u{~?7 7$#u) %. etx u{~?7 7$#u + + +NB. %: ------------------------------------------------------------------ + +'domain error' -: %: etx y + +'domain error' -: 3 %: etx y +'domain error' -: y %: etx 3 +'domain error' -: x %: etx y + + +NB. ^ ------------------------------------------------------------------- + +'domain error' -: ^ etx y + +'domain error' -: 3 ^ etx y +'domain error' -: y ^ etx 3 +'domain error' -: x ^ etx y + + +NB. ^. ------------------------------------------------------------------ + +'domain error' -: ^. etx y + +'domain error' -: 3 ^. etx y +'domain error' -: y ^. etx 3 +'domain error' -: x ^. etx y + + +NB. ^: ------------------------------------------------------------------ + +'domain error' -: ex '+:^:y 2 3' + + +NB. $ ------------------------------------------------------------------- + +($&({&u) -: $&({&v)) i +($&({&u) -: $&({&v)) j +($&({&u) -: $&({&v)) ,j +($&({&u) -: $&({&v)) '' ($,) j + +2 3 4 (($ {&u) -: {&u@$) i +2 3 4 (($ {&u) -: {&u@$) j +2 3 4 (($ {&u) -: {&u@$) ,j + +'' (($ {&u) -: {&u@$) i +'' (($ {&u) -: {&u@$) j +'' (($ {&u) -: {&u@$) ,j + +'domain error' -: a $ etx i.4 5 + + +NB. ~. ------------------------------------------------------------------ + +(~.&({&u) -: {&u&~.) i +(~.&({&u) -: {&u&~.) j +(~.&({&u) -: {&u&~.) ,j +(~.&({&u) -: {&u&~.) '' ($,) j + + +NB. ~: ------------------------------------------------------------------ + +(~:&({&u) -: ~:&({&v)) i +(~:&({&u) -: ~:&({&v)) j +(~:&({&u) -: ~:&({&v)) ,j +(~:&({&u) -: ~:&({&v)) '' ($,) j + +i (~: &({&u) -: ~: &({&v)) j +i (~:/&({&u) -: ~:/&({&v)) j + +i (~:"2 1&({&u) -: ~:"2 1&({&v)) j + +(($i)$1) -: (i{u) ~: i{v +(($i)$1) -: (i{u) ~: i{a.{~?( $u)$#a. +(($i)$1) -: (i{u) ~: i{ ?( $u)$2 +(($i)$1) -: (i{u) ~: i{ ?( $u)$1e6 +(($i)$1) -: (i{u) ~: i{ o.?( $u)$1e6 +(($i)$1) -: (i{u) ~: i{j./ ?(2,$u)$1e6 +(($i)$1) -: (i{u) ~: i{ ?( $u)$12000x +(($i)$1) -: (i{u) ~: i{ %/ ?(2,$u)$12000x + +'domain error' -: ~:/\ etx y +'domain error' -: ~:/\.etx y + + +NB. | ------------------------------------------------------------------- + +'domain error' -: | etx y + +'domain error' -: 3 | etx y +'domain error' -: y | etx 3 +'domain error' -: x | etx y + + +NB. |. ------------------------------------------------------------------ + +(|. &({&u) -: ({&u)&(|. )) i +(|. &({&u) -: ({&u)&(|. )) j +(|."1&({&u) -: ({&u)&(|."1)) i +(|."1&({&u) -: ({&u)&(|."1)) j +(|."2&({&u) -: ({&u)&(|."2)) i +(|."2&({&u) -: ({&u)&(|."2)) j + +3 ((|. {&u) -: ({&u)@:(|. )) ?31 2 5 $#u +3 ((|. {&u) -: ({&u)@:(|. )) ?31 2 5 7$#u +3 ((|."1 {&u) -: ({&u)@:(|."1)) ?31 2 5 $#u +3 ((|."1 {&u) -: ({&u)@:(|."1)) ?31 2 5 7$#u +3 _1 ((|."2 {&u) -: ({&u)@:(|."2)) ?31 2 5 $#u +3 _1 ((|."2 {&u) -: ({&u)@:(|."2)) ?31 2 5 7$#u + +'domain error' -: a |. etx i.4 5 + + +NB. : ------------------------------------------------------------------- + +'domain error' -: ex 'a : ''o.y.''' +'domain error' -: ex '3 : y' + + +NB. , ------------------------------------------------------------------- + +(,&({&u) -: {&u@,) i +(,&({&u) -: {&u@,) j +(,&({&u) -: {&u@,) '' ($,) j + +i (,&({&u) -: {&(f,u)@,&:>:) j +(,i) (,&({&u) -: {&u@,) ,j + +'domain error' -: 0 , etx y +'domain error' -: 2 , etx y +'domain error' -: 2.4 , etx y +'domain error' -: 2j4 , etx y +'domain error' -: 2x , etx y +'domain error' -: 2r4 , etx y +'domain error' -: '3' , etx y +'domain error' -: (<3), etx y + +'domain error' -: y , etx 0 +'domain error' -: y , etx 2 +'domain error' -: y , etx 2.4 +'domain error' -: y , etx 2j4 +'domain error' -: y , etx 2x +'domain error' -: y , etx 2r4 +'domain error' -: y , etx '3' +'domain error' -: y , etx <3 + + +NB. ,. ------------------------------------------------------------------ + +i (,&({&u) -: {&(f,u)@,&:>:) j + +'domain error' -: 0 ,. etx y +'domain error' -: 2 ,. etx y +'domain error' -: 2.4 ,. etx y +'domain error' -: 2j4 ,. etx y +'domain error' -: 2x ,. etx y +'domain error' -: 2r4 ,. etx y +'domain error' -: '3' ,. etx y +'domain error' -: (<3),. etx y + +'domain error' -: y ,. etx 0 +'domain error' -: y ,. etx 2 +'domain error' -: y ,. etx 2.4 +'domain error' -: y ,. etx 2j4 +'domain error' -: y ,. etx 2x +'domain error' -: y ,. etx 2r4 +'domain error' -: y ,. etx '3' +'domain error' -: y ,. etx <3 + + +NB. ,: ------------------------------------------------------------------ + +'domain error' -: 0 ,: etx y +'domain error' -: 2 ,: etx y +'domain error' -: 2.4 ,: etx y +'domain error' -: 2j4 ,: etx y +'domain error' -: 2x ,: etx y +'domain error' -: 2r4 ,: etx y +'domain error' -: '3' ,: etx y +'domain error' -: (<3),: etx y + +'domain error' -: y ,: etx 0 +'domain error' -: y ,: etx 2 +'domain error' -: y ,: etx 2.4 +'domain error' -: y ,: etx 2j4 +'domain error' -: y ,: etx 2x +'domain error' -: y ,: etx 2r4 +'domain error' -: y ,: etx '3' +'domain error' -: y ,: etx <3 + + +NB. ; ------------------------------------------------------------------- + +'domain error' -: ; etx 0 ;y +'domain error' -: ; etx 2 ;y +'domain error' -: ; etx 2.4 ;y +'domain error' -: ; etx 2j4 ;y +'domain error' -: ; etx 2r4 ;y +'domain error' -: ; etx (<2);y +'domain error' -: ; etx '22';y + +'domain error' -: ; etx y ;0 +'domain error' -: ; etx y ;2 +'domain error' -: ; etx y ;2.4 +'domain error' -: ; etx y ;2j4 +'domain error' -: ; etx y ;2r4 +'domain error' -: ; etx y ;'22' +'domain error' -: ; etx y ;<2 + + +NB. ;. ------------------------------------------------------------------ + +(<;.1@({&u) -: {&u&.>@(<;.1)) ?5000$#u + +(< ;. 1@({&u) -: {&u&.> @( <;. 1) ) ,i +(# ;. 1@({&u) -: ( #;. 1) ) ,i +({.;. 1@({&u) -: {&u @({.;. 1) ) ,i +( ,;. 1@({&u) -: {&(f,u)@( ,;. 1)@:>:) ,i +( ];. 1@({&u) -: {&(f,u)@( ];. 1)@:>:) ,i + +(< ;._1@({&u) -: {&u&.> @( <;._1) ) ,i +(# ;._1@({&u) -: ( #;._1) ) ,i +( ,;._1@({&u) -: {&(f,u)@( ,;._1)@:>:) ,i +( ];._1@({&u) -: {&(f,u)@( ];._1)@:>:) ,i + +(< ;. 2@({&u) -: {&u&.> @( <;. 2) ) ,i +(# ;. 2@({&u) -: ( #;. 2) ) ,i +({.;. 2@({&u) -: {&u @({.;. 2) ) ,i +( ,;. 2@({&u) -: {&(f,u)@( ,;. 2)@:>:) ,i +( ];. 2@({&u) -: {&(f,u)@( ];. 2)@:>:) ,i + +(< ;._2@({&u) -: {&u&.> @( <;._2) ) ,i +(# ;._2@({&u) -: ( #;._2) ) ,i +( ,;._2@({&u) -: {&(f,u)@( ,;._2)@:>:) ,i +( ];._2@({&u) -: {&(f,u)@( ];._2)@:>:) ,i + + +NB. # ------------------------------------------------------------------- + +(#&({&u) -: #&({&v)) i +(#&({&u) -: #&({&v)) j + +(?(0{$i)$5) ((# {&u) -: {&u@: # ) i +(?(1{$i)$5) ((#"1 _1 {&u) -: {&u@:(#"1 _1)) i + +((3#0{t),(4#f),5#1{t) -: 3j4 5#t=: 0 1{u + +'domain error' -: a # etx 3 +'domain error' -: a # etx y +'domain error' -: a # etx y + + +NB. #. ------------------------------------------------------------------ + +'domain error' -: #. etx y + +'domain error' -: 3 #. etx y +'domain error' -: y #. etx 3 +'domain error' -: x #. etx y + + +NB. #: ------------------------------------------------------------------ + +'domain error' -: #: etx y + +'domain error' -: 3 #: etx y +'domain error' -: y #: etx 3 +'domain error' -: x #: etx y + + +NB. ! ------------------------------------------------------------------- + +'domain error' -: ! etx y + +'domain error' -: 3 ! etx y +'domain error' -: y ! etx 3 +'domain error' -: x ! etx y + + +NB. !. ------------------------------------------------------------------ + +'domain error' -: ex '=!.({.a)' + + +NB. !: ------------------------------------------------------------------ + +65536 = 3!:0 i{u + +(i{u) -: 3!:2 (3!:1) i{u +(i{u) -: 3!:2 (3!:3) i{u + +(-: 3!:2 @( 3!:1 )) x +(-: 3!:2 @( 3!:1 )) y +(-: 3!:2 @( 3!:1 )) a +(-: 3!:2 @( 3!:1 )) f + +(-: 3!:2 @( 3!:1 )) 1 2 3;x +(-: 3!:2 @( 3!:1 )) x;1 2 3 +(-: 3!:2 @( 3!:1 )) (5 s: x);<<<<x +(-: 3!:2 @( 3!:1 )) a;x + +(-: 3!:2 @(0&(3!:1))) x +(-: 3!:2 @(0&(3!:1))) y +(-: 3!:2 @(0&(3!:1))) a +(-: 3!:2 @(0&(3!:1))) f + +(-: 3!:2 @(1&(3!:1))) x +(-: 3!:2 @(1&(3!:1))) y +(-: 3!:2 @(1&(3!:1))) a +(-: 3!:2 @(1&(3!:1))) f + +(-: 3!:2 @( 3!:3 )) x +(-: 3!:2 @( 3!:3 )) y +(-: 3!:2 @( 3!:3 )) a +(-: 3!:2 @( 3!:3 )) f + +x -: (5!:1 <'x') 5!:0 +y -: (5!:1 <'y') 5!:0 +a -: (5!:1 <'a') 5!:0 +f -: (5!:1 <'f') 5!:0 + +t -: ". 5!:5 <'t' [ t=: '' ($,) u +t -: ". 5!:5 <'t' [ t=: i{u +t -: ". 5!:5 <'t' [ t=: f + +'domain error' -: ex 'a!:3' +'domain error' -: ex 'a!:y' +'domain error' -: ex '3!:a' + + +NB. /: ------------------------------------------------------------------ + +(/: -: /:&(5&s:)) u +(/: -: /:&(5&s:)) (?1000$#u){u +(/: -: /:&(5&s:)) (?1000$#x){x + +(/:&({&u) -: /:&({&v)) t=: ?300 $#u +(/:&({&u) -: /:&({&v)) t=: ?200 3$#u +(/:&({&u) -: /:&({&v)) t=: ?100 2 3$#u + +(/:~&({&u) -: (/:@({&v) { {&u)) t=: ?300 $#u +(/:~&({&u) -: (/:@({&v) { {&u)) t=: ?200 3$#u +(/:~&({&u) -: (/:@({&v) { {&u)) t=: ?100 2 3$#u + +t=: s: '';'ab';('ab',0{a.);('ab',0 0{a.);'ab ';'ab ';'ab ' +(/:"1 -: /:"1&({&t)) k=: (? 31&$) #t + +q=: 0 1 0;(s: ' 0 1 0');'010';<<"0 '010' +p=: (i.!#q) A. i.#q +(/:"1 p) -: /: "1 p{q +q -:"1 /:~"1 p{q + + +NB. \: ------------------------------------------------------------------ + +(\:&({&u) -: \:&({&v)) t=: ?300 $#u +(\:&({&u) -: \:&({&v)) t=: ?200 3$#u +(\:&({&u) -: \:&({&v)) t=: ?100 2 3$#u + +(\:~&({&u) -: (\:@({&v) { {&u)) t=: ?300 $#u +(\:~&({&u) -: (\:@({&v) { {&u)) t=: ?200 3$#u +(\:~&({&u) -: (\:@({&v) { {&u)) t=: ?100 2 3$#u + +t=: s: '';'ab';('ab',0{a.);('ab',0 0{a.);'ab ';'ab ';'ab ' +(\:"1 -: \:"1&({&t)) k=: (? 31&$) #t + +q=: 0 1 0;(s: ' 0 1 0');'010';<<"0 '010' +p=: (i.!#q) A. i.#q +(\:"1 p) -: \: "1 p{q +(|.q) -:"1 \:~"1 p{q + + +NB. { ------------------------------------------------------------------- + +'domain error' -: { etx 0 ;y +'domain error' -: { etx 2 ;y +'domain error' -: { etx 2.4 ;y +'domain error' -: { etx 2j4 ;y +'domain error' -: { etx 2r4 ;y +'domain error' -: { etx (<2);y +'domain error' -: { etx '22';y +'domain error' -: { etx y ;0 +'domain error' -: { etx y ;2 +'domain error' -: { etx y ;2.4 +'domain error' -: { etx y ;2j4 +'domain error' -: { etx y ;2r4 +'domain error' -: { etx y ;'22' +'domain error' -: { etx y ;<2 + + +NB. {. ------------------------------------------------------------------ + +((3 ($,)u), 2$f) -: 5{.3 ($,) u +((3 ($,)u),~2$f) -: _5{.3 ($,) u + +'domain error' -: a {. etx i.12 + + +NB. }. ------------------------------------------------------------------ + +'domain error' -: a }. etx i.12 + + +NB. ". ------------------------------------------------------------------ + +'domain error' -: ". etx x + +'domain error' -: 3 ". etx x +'domain error' -: a ". etx '3142' + + +NB. ": ------------------------------------------------------------------ + +2 -: 3!:0 ":x +(1>.#$x) -: #$ ":x + +'domain error' -: 3 ": etx x +'domain error' -: a ": etx i.3 4 + + +NB. ? ------------------------------------------------------------------- + +'domain error' -: ? etx y + +'domain error' -: 3 ? etx y +'domain error' -: y ? etx 3 +'domain error' -: x ? etx y + + +NB. ?. ------------------------------------------------------------------ + +'domain error' -: ?. etx y + +'domain error' -: 3 ?. etx y +'domain error' -: y ?. etx 3 +'domain error' -: x ?. etx y + +NB. A. ------------------------------------------------------------------ + +'domain error' -: A. etx y + +'domain error' -: y A. etx 3 +'domain error' -: x A. etx y + + +NB. C. ------------------------------------------------------------------ + +'domain error' -: C. etx y + +'domain error' -: y C. etx 3 +'domain error' -: x C. etx y + + +NB. e. ------------------------------------------------------------------ + +i (e.&({&u) -: e.&({&v)) i +t (e.&({&u) -: e.&({&v)) (?#t) A. t=: ?100 2 3$#u +t (e.&({&u) -: e.&({&v))~(?2 3 4$#t){t +j (e.&({&u) -: e.&({&v)) j + +(2 3$0) -: (i{u) e.~t=: ?(2 3,}.$i)$#i +(2 3$0) -: (i{u) e.~t=: (2 3,}.$i)$'xyz' + + +NB. i. ------------------------------------------------------------------ + +i (i.&({&u) -: i.&({&v)) i +t (i.&({&u) -: i.&({&v)) (?#t) A. t=: ?100 2 3$#u +t (i.&({&u) -: i.&({&v)) (?2 3 4$#t){t +j (i.&({&u) -: i.&({&v)) j + +(2 3$#i) -: (i{u) i. t=: ?(2 3,}.$i)$#i +(2 3$#i) -: (i{u) i. t=: (2 3,}.$i)$'xyz' + +(,i) (i.&({&u) -: i.&({&v))"_ 0 (?20 10$*/$i){,i + +'domain error' -: i. etx i{u + + +NB. i: ------------------------------------------------------------------ + +i (i:&({&u) -: i:&({&v)) i +t (i:&({&u) -: i:&({&v)) (?#t) A. t=: ?100 2 3$#u +t (i:&({&u) -: i:&({&v)) (?2 3 4$#t){t +j (i:&({&u) -: i:&({&v)) j + +(2 3$#i) -: (i{u) i: t=: ?(2 3,}.$i)$#i +(2 3$#i) -: (i{u) i: t=: (2 3,}.$i)$'xyz' + +(,i) (i:&({&u) -: i:&({&v))"_ 0 (?20 10$*/$i){,i + +'domain error' -: i: etx i{u + + +NB. j. ------------------------------------------------------------------ + +'domain error' -: j. etx y + +'domain error' -: 3 j. etx y +'domain error' -: y j. etx 3 +'domain error' -: x j. etx y + + +NB. o. ------------------------------------------------------------------ + +'domain error' -: o. etx y + +'domain error' -: 3 o. etx y +'domain error' -: y o. etx 3 +'domain error' -: x o. etx y + + +NB. p. ------------------------------------------------------------------ + +'domain error' -: p. etx y + +'domain error' -: 3 p. etx y +'domain error' -: y p. etx 3 +'domain error' -: x p. etx y + + +NB. p: ------------------------------------------------------------------ + +'domain error' -: p: etx y + + +NB. q: ------------------------------------------------------------------ + +'domain error' -: q: etx y + +'domain error' -: 3 q: etx y +'domain error' -: y q: etx 3 +'domain error' -: x q: etx y + + +NB. r. ------------------------------------------------------------------ + +'domain error' -: r. etx y + +'domain error' -: 3 r. etx y +'domain error' -: y r. etx 3 +'domain error' -: x r. etx y + + +NB. x: ------------------------------------------------------------------ + +'domain error' -: x: etx y + +'domain error' -: y x: etx 3 +'domain error' -: 3 x: etx y +'domain error' -: x x: etx y + + +4!:55 ;:'a f i j k p q s t u v x y' + +
new file mode 100644 --- /dev/null +++ b/test/gscou.ijs @@ -0,0 +1,63 @@ +NB. s: with unicode ----------------------------------------------------- + +c=: ' a b cd chthonic boustrophedonic octothorpe' +t=: s: c +s=: s: u: c +s -: t +s -:&(6&s:) t +(1 s: s) -: ; '`'&, &.><;._1 c +(2 s: s) -: ; ,&(0{a.)&.><;._1 c +(3 s: s) -: (<;._1 c) ,&> ((>./ - ])#;.1 c)$&.>0{a. +(4 s: s) -: (<;._1 c) ,&> ((>./ - ])#;.1 c)$&.>' ' +(5 s: s) -: <;._1 c + +d=: ' triskaidekaphobia paronomasia tasis litotes metonymic' +t=: s,s: d +(1 s: t) -: ; '`'&, &.><;._1 c,d +(2 s: t) -: ; ,&(0{a.)&.><;._1 c,d +(3 s: t) -: (<;._1 c,d) ,&> ((>./ - ])#;.1 c,d)$&.>0{a. +(4 s: t) -: (<;._1 c,d) ,&> ((>./ - ])#;.1 c,d)$&.>' ' +(5 s: t) -: <;._1 c,d + +i=: ?~#t +(1 s: i{t) -: ; i{'`'&, &.><;._1 c,d +(2 s: i{t) -: ; i{,&(0{a.)&.><;._1 c,d +(3 s: i{t) -: i{(<;._1 c,d) ,&> ((>./ - ])#;.1 c,d)$&.>0{a. +(4 s: i{t) -: i{(<;._1 c,d) ,&> ((>./ - ])#;.1 c,d)$&.>' ' +(5 s: i{t) -: i{ <;._1 c,d + +0 s: 11 +10 s: 0 s: 10 +0 s: 11 + +c=: ' zeugma deesis acyron meiosis bdelygma chiasmus' +s=: s: u: c +t=: s: c +s -: t +s -:&(6&s:) t +(1 s: s) -: ; '`'&, &.><;._1 c +(2 s: s) -: ; ,&(0{a.)&.><;._1 c +(3 s: s) -: (<;._1 c) ,&> ((>./ - ])#;.1 c)$&.>0{a. +(4 s: s) -: (<;._1 c) ,&> ((>./ - ])#;.1 c)$&.>' ' +(5 s: s) -: <;._1 c + +0 s: 11 + +s -: s: ];._1 u: c +s -: s: <;._1 u: c +s -: _1 s: u: c +s -: _2 s: 1|.u: c +s -: _3 s: (<;._1 u: c) ,&> ((>./ - ])#;._1 c)$&.>u: 0 +s -: _4 s: ];._1 u: c +s -: _5 s: <;._1 u: c + +0 s: 11 + +1 [ s: <u: 'force even alignment ',":?1e9 +1 [ s: <u: 'force padding ',":?1e9 +0 s: 11 + + +4!:55 ;:'c d i s t u' + +
new file mode 100644 --- /dev/null +++ b/test/gsdot.ijs @@ -0,0 +1,19 @@ +NB. S: ------------------------------------------------------------------ + +phi=: * -.@%@~.&.q: NB. Euler's totient function +t=: 5!:2 <'phi' + +(;:'* -.@%@~.&.q:') -: < S: 0 t + +(0 0;0 0) -: (] S: 0) L: 1 t=: 2 $ <0;0 +(0 0;0 0) -: (] S: 0) L: _1 t=: 2 $ <0;0 +(0 0;0 0) -: > L: 1 t=: 2 $ <0;0 + + +'domain error' -: ] S: 1 etx 1;<<1 2 3 +'domain error' -: ; S: 2 etx 1;<<1 2 3 + + +4!:55 ;:'phi t' + +
new file mode 100644 --- /dev/null +++ b/test/gselect.ijs @@ -0,0 +1,155 @@ +NB. select. ------------------------------------------------------------- + +f0=: 3 : 0 + select. y + case. 1 do. i.1 + case. 2 do. i.2 + case. 3 do. i.3 + case. 4 do. i.4 + end. +) + +(i. -: f0)"0 >:?4 5$4 +(i.0 0) -: f0 0 +(i.0 0) -: f0 5 + +f1=: 3 : 0 + t=. '' + select. y + fcase. 1 do. t=.t,<i.1 + fcase. 2 do. t=.t,<i.2 + fcase. 3 do. t=.t,<i.3 + fcase. 4 do. t=.t,<i.4 + end. +) + +(i.&.>1 2 3 4) -: f1 1 +(i.&.> 2 3 4) -: f1 2 +(i.&.> 3 4) -: f1 3 +(i.&.> ,4) -: f1 4 + +'' -: f1 0 +'' -: f1 5 + +f2=: 3 : 0 + select. y + case. 1;2 do. i.1 + case. 3 do. i.2 + case. 4;5 do. i.3 + case. 6 do. i.4 + end. +) + +(i.1) -: f2 1 +(i.1) -: f2 2 +(i.2) -: f2 3 +(i.3) -: f2 4 +(i.3) -: f2 5 +(i.4) -: f2 6 +(i.0 0) -: f2 0 +(i.0 0) -: f2 7 + +f3=: 3 : 0 + select. y + case. 'a' do. i.1 + case. 'b' do. i.2 + case. do. i.3 + end. +) + +(i.1) -: f3 'a' +(i.1) -: f3 'a';'b' +(i.2) -: f3 'b' +(i.3) -: f3 'c' +(i.3) -: f3 'x' + +f4=: 4 : 0 + select. + if. -.x e. 1 2 3 4 do. x=.1 end. + x + case. 1 do. s=.0 for_i. i.y do. s=.s+i end. + case. 2 do. s=.1 for. i.y,0 do. s=.+:s end. + case. 3 do. s=.$0 for_j. i.y do. s=.s,j end. + case. 4 do. s=.0 while. 1<y do. s=.>:s [ y=.-:y end. + end. +) + +(2&! -: 1&f4)"0 x=:?4 5$100 +(2&^ -: 2&f4)"0 x=:?4 5$20 +(i. -: 3&f4)"0 x=:?4 5$100 +(>.@(2&^.) -: 4&f4)"0 x=:1+?4 5$1000 +(1 f4 9) -: 0 f4 9 +(1 f4 9) -: 5 f4 9 + +f5=: 3 : 0 + t=. '' + select. y + case. 1 do. t=.t,<i.1 + fcase. 2 do. t=.t,<i.2 + case. 3 do. t=.t,<i.3 + fcase. 4 do. t=.t,<i.4 + end. +) + +(i.&.>,1 ) -: f5 1 +(i.&.>2 3) -: f5 2 +(i.&.>,3 ) -: f5 3 +(i.&.>,4 ) -: f5 4 + +'control error' -: ex '3 : ''select. do. end.'' ' +'control error' -: ex '3 : ''select. y end.'' ' +'control error' -: ex '3 : ''select. y case. 1 end.'' ' +'control error' -: ex '3 : ''select. y fcase. 1 end.'' ' + +g1=: 3 : 0 + select. if. y do. y end. + case. 1 do. i.1 + case. 2 do. i.2 + end. +) + +(i.1) -: g1 1 +(i.2) -: g1 2 +'control error' -: g1 etx 0 + +g2=: 3 : 0 + select. foobar + case. 1 do. i.1 + case. 2 do. i.2 + end. +) + +'control error' -: g2 etx 3 + +g3=: 3 : 0 +select. y + case. 1 do. 'one' + case. + do. 'two' + case. 3 do. 'three' +end. +) + +'one' -: g3 1 + +'control error' -: g3 etx 2 +'control error' -: g3 etx 3 +'control error' -: g3 etx 4 + +g4=: 3 : 0 +select. y + case. 1 do. 'one' + case. undef123 do. 'two' + case. 3 do. 'three' +end. +) + +'one' -: g4 1 + +'control error' -: g4 etx 2 +'control error' -: g4 etx 3 +'control error' -: g4 etx 4 + + +4!:55 ;:'f0 f1 f2 f3 f4 f5 g1 g2 g3 g4 x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp.ijs @@ -0,0 +1,230 @@ +NB. $. ------------------------------------------------------------------ + +s=: $. x=: 7 3 5 ?@$ 5 +t=: $. y=: 7 3 5 ?@$ 5 + +(s=t) -: x=y + +'nonce error' -: < etx s +(s<t) -: x<y + +(<.s) -: <.x +(s<.t) -: x<.y + +(<:s) -: <:x +(s<:t) -: x<:y + +(>s) -: >x +(s>t) -: x>y + +(>.s) -: >.x +(s>.t) -: x>.y + +(>:s) -: >:x +(s>:t) -: x>:y + +(+s) -: +x +(s+t) -: x+y + +(+.s) -: +.x +(s+.t) -: x+.y + +(+:s) -: +:x +((2|s)+:(2|t)) -: (2|x)+:2|y + +(*s) -: *x +(s*t) -: x*y + +(*.s) -: *.x +(s*.t) -: x*.y + +(*:s) -: *:x +((2|s)*:(2|t)) -: (2|x)*:2|y + +(-s) -: -x +(s-t) -: x-y + +(-.s) -: -.x + +(-:s) -: -:x +s -: x + +(%s) -: %x +(s%t) -: x%y + +NB. %. CDOMINO, VERB, minv, mdiv, + +(%:s) -: %:x +(s%:t) -: x%:y + +(^s) -: ^x +(s^t) -: x^y + +(^.s) -: ^.x +'NaN error' -: s^. etx t + +NB. ^: CPOWOP, CONJ, 0L, powop, +NB. $ CDOLLAR, VERB, shape, reitem, +NB. $. CSPARSE, VERB, sparse1, sparse2, +NB. $: CSELF, VERB, self1, self2, +NB. ~ CTILDE, ADV, swap, 0L, + +(s~:t) -: x~:y + +(|s) -: |x +(s|t) -: x|y + +(|.s) -: |.x +(3|.s) -: 3|.x + +NB. |: CCANT, VERB, cant1, cant2, +NB. . CDOT, CONJ, 0L, dot, +NB. .. CEVEN, CONJ, 0L, even, +NB. .: CODD, CONJ, 0L, odd, +NB. : CCOLON, CONJ, 0L, colon, +NB. :. COBVERSE,CONJ, 0L, obverse, +NB. :: CADVERSE,CONJ, 0L, adverse, + +(,s) -: ,x +(s,t) -: x,y + +(,.s) -: ,.x +(s,.t) -: x,.y + +(,: s) -: ,: x +(s,:t) -: x,:y + +(;s) -: ;x +'nonce error' -: s ; etx t + +NB. ;. CCUT, CONJ, 0L, cut, +NB. ;: CWORDS, VERB, words, 0L, + +(#s) -: #x +(3#s) -: 3#x + +'nonce error' -: #. etx t +'nonce error' -: 3 #. etx t +'nonce error' -: s #. etx 3 +'nonce error' -: s #. etx t + +'nonce error' -: #: etx t + +'nonce error' -: 3 #: etx t +'nonce error' -: s #: etx 3 +'nonce error' -: s #: etx t + +(!s) -: !x +(s!t) -: x!y + +NB. !. CFIT, CONJ, 0L, fit, +NB. !: CIBEAM, CONJ, 0L, foreign, + +(+/s) -: +/x +NB. (s +/ t) -: x +/ y + +NB. /. CSLDOT, ADV, sldot, 0L, +NB. /: CGRADE, VERB, grade1, grade2, +NB. \ CBSLASH, ADV, bslash, 0L, +NB. \. CBSDOT, ADV, bsdot, 0L, +NB. \: CDGRADE, VERB, dgrade1, dgrade2, + +([s) -: [x +(s[t) -: x[y + +NB. [: CCAP, VERB, 0L, 0L, + +(]s) -: ]x +(s]t) -: x]y + +'nonce error' -: { etx s +(i{s) -: i{x [ i=: <"1 ?(2 3,#$s)$$s + +({.s) -: {.x +(3 4{.s) -: 3 4{.x + +({:s) -: {:x + +'nonce error' -: i} etx s [ i=: ?(}.$s)$#s +(33 (<"1 i)}s) -: 33 (<"1 i)}x [ i=: ?(7,#$s)$$s + +(}.s) -: }.x +(5 1}.s) -: 5 1}.x + +(}:s) -: }:x + +NB. " CQQ, CONJ, 0L, qq, +NB. ". CEXEC, VERB, exec1, exec2, +NB. ": CTHORN, VERB, thorn1, thorn2, +NB. ` CGRAVE, CONJ, 0L, tie, +NB. `: CGRCO, CONJ, 0L, evger, +NB. @ CAT, CONJ, 0L, atop, +NB. @. CATDOT, CONJ, 0L, agenda, +NB. @: CATCO, CONJ, 0L, atco, +NB. & CAMP, CONJ, 0L, amp, + +'nonce error' -: $.&.> etx 1 2;3 4 5 +'nonce error' -: 1 $.&.> etx 1 2;3 4 5 + +NB. &: CAMPCO, CONJ, 0L, ampco, + +NB. 'domain error' -: ? etx 1+s +NB. 'domain error' -: 2 ? etx 2+s + +NB. 'domain error' -: ?. etx 1+s +NB. 'domain error' -: 2 ?. etx 2+s + +NB. {:: CFETCH, VERB, map, fetch, +NB. }:: CEMEND, ADV, emend, 0L, +NB. A. CATOMIC, VERB, adot1, adot2, +NB. b. CBDOT, ADV, bdot, 0L, +NB. c. CEIGEN, VERB, eig1, eig2, +NB. C. CCYCLE, VERB, cdot1, cdot2, +NB. d. CDDOT, CONJ, 0L, ddot, +NB. D. CDCAP, CONJ, 0L, dcap, +NB. D: CDCAPCO, CONJ, 0L, dcapco, + +'nonce error' -: e. etx t + +NB. E. CEBAR, VERB, 0L, ebar, +NB. f. CFIX, ADV, fix, 0L, +NB. H. CHGEOM, CONJ, 0L, hgeom, + +(i.2 3) -: i. $. 2 3 + +(i:2 3) -: i: $. 2 3 + +NB. I. CICAP, ADV, icap, 0L, + +(j.s) -: j. x +(s j. t) -: x j. y + +NB. L. CLDOT, VERB, level1, 0, + +'nonce error' -: $. L: 0 etx 1 2 ;3 4 5 +'nonce error' -: 1 $. L: 0 etx 1 2 ;3 4 5 + +(o.s) -: o.x +(1 o. s) -: 1 o. x +(2 o. s) -: 2 o. x + +NB. p. CPOLY, VERB, poly1, poly2, +NB. p: CPCO, VERB, prime, 0, +NB. q: CQCO, VERB, factor, qcol2, + +(r.s) -: r. x +(s r. t) -: x r. y + +NB. S: CSCO, CONJ, 0L, sco, +NB. t. CTDOT, ADV, tdot, 0L, +NB. t: CTCO, ADV, tco, 0L, +NB. T. CTCAP, CONJ, 0L, tcap, + +'nonce error' -: x: etx s +'nonce error' -: 1 x: etx s +'nonce error' -: 2 x: etx s + + +4!:55 ;:'i s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp0.ijs @@ -0,0 +1,189 @@ +NB. < ------------------------------------------------------------------- + +(scheck <. $.x), (<. -: <.&.$.) x=: _10+? 405$2 +(scheck <. $.x), (<. -: <.&.$.) x=: _10+? 3 4 5$21 +(scheck <. $.x), (<. -: <.&.$.) x=: o._10+? 3 4 5$21 +(scheck <. $.x), (<. -: <.&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. <. $. 0 1 0 +0 -: 3 $. <. $. 2 3 4 +0 -: 3 $. <. $. 2 3.4 +0 -: 3 $. <. $. 2 3j4 + +f=: 4 : '(scheck t) *. (p<q) -: t=: ((2;x)$.p) < (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 < etx $. 3j4 5 + + +NB. <. ------------------------------------------------------------------ + +(scheck <. $.x), (<. -: <.&.$.) x=: _10+? 405$2 +(scheck <. $.x), (<. -: <.&.$.) x=: _10+? 3 4 5$21 +(scheck <. $.x), (<. -: <.&.$.) x=: o._10+? 3 4 5$21 +(scheck <. $.x), (<. -: <.&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. <. $. 0 1 0 +0 -: 3 $. <. $. 2 3 4 +0 -: 3 $. <. $. 2 3.4 +0 -: 3 $. <. $. 2 3j4 + +f=: 4 : '(scheck t) *. (p<.q) -: t=: ((2;x)$.p) <. (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 <. etx $. 3j4 5 + + +NB. <: ------------------------------------------------------------------ + +(scheck <: $.x), (<: -: <:&.$.) x=: _10+? 405$2 +(scheck <: $.x), (<: -: <:&.$.) x=: _10+? 3 4 5$21 +(scheck <: $.x), (<: -: <:&.$.) x=: o._10+? 3 4 5$21 +(scheck <: $.x), (<: -: <:&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck <: $.x), (<: -: <:&.$.) x=: (_10+?60$21),<.-2^31 + +_1 -: 3 $. <: $. 0 1 0 +_1 -: 3 $. <: $. 2 3 4 +_1 -: 3 $. <: $. 2 3.4 +_1 -: 3 $. <: $. 2 3j4 + +f=: 4 : '(scheck t) *. (p<:q) -: t=: ((2;x)$.p) <: (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 <: etx $. 3j4 5 + + +NB. > ------------------------------------------------------------------- + +f=: 4 : '(scheck t) *. (p>q) -: t=: ((2;x)$.p) > (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 > etx $. 3j4 5 + + +NB. >. ------------------------------------------------------------------ + +(scheck >. $.x), (>. -: >.&.$.) x=: _10+? 405$2 +(scheck >. $.x), (>. -: >.&.$.) x=: _10+? 3 4 5$21 +(scheck >. $.x), (>. -: >.&.$.) x=: o._10+? 3 4 5$21 +(scheck >. $.x), (>. -: >.&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. >. $. 0 1 0 +0 -: 3 $. >. $. 2 3 4 +0 -: 3 $. >. $. 2 3.4 +0 -: 3 $. >. $. 2 3j4 + +f=: 4 : '(scheck t) *. (p>.q) -: t=: ((2;x)$.p) >. (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 >. etx $. 3j4 5 + + +NB. >: ------------------------------------------------------------------ + +(scheck >: $.x), (>: -: >:&.$.) x=: _10+? 405$2 +(scheck >: $.x), (>: -: >:&.$.) x=: _10+? 3 4 5$21 +(scheck >: $.x), (>: -: >:&.$.) x=: o._10+? 3 4 5$21 +(scheck >: $.x), (>: -: >:&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck >: $.x), (>: -: >:&.$.) x=: (_10+?60$21),<._1+2^31 + +1 -: 3 $. >: $. 0 1 0 +1 -: 3 $. >: $. 2 3 4 +1 -: 3 $. >: $. 2 3.4 +1 -: 3 $. >: $. 2 3j4 + +f=: 4 : '(scheck t) *. (p>:q) -: t=: ((2;x)$.p) >: (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +'domain error' -: 1 2 >: etx $. 3j4 5 + + +4!:55 ;:'c f p q r t x y z' + +
new file mode 100644 --- /dev/null +++ b/test/gsp000.ijs @@ -0,0 +1,51 @@ +NB. = monad ------------------------------------------------------------- + +f=: 3 : '(scheck t) *. (=p) -: t=: =s=: (2;y)$.p' + +c=: ; (i.1+r) <"1@comb&.>r=: 4 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$2 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * o. ? 50 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * j./?2 50 4 5 3$100 + +c=: ; (i.1+r) <"1@comb&.>r=: 3 +f&> c [ p=: ?100 4 5$1000 +f&> c [ p=: 0 (0)} ?100 4 5$1000 +f&> c [ p=: 0 (9)} ?100 4 5$1000 +f&> c [ p=: 0 * ?100 4 5$1000 +f&> c [ p=: (?200$100) { ?100 4 5$1000 +f&> c [ p=: (?200$100) {(?100 4$2) * ?100 4 5$1000 + +(=$.p) -: =p=: i.0 +(=$.p) -: =p=: i.0 5 +(=$.p) -: =p=: i.5 0 + + +NB. = dyad ------------------------------------------------------------- + +f=: 4 : '(scheck t) *. (p=q) -: t=: ((2;x)$.p) = (2;y)$.q' + +p=: ?2 4 5 3$2 +q=: ?2 4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?2 4 5 3$4 +q=: ?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?2 4 5 3$4 +q=: o.?2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: j./?2 2 4 5 3$4 +q=: j./?2 2 4 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c f p q r s t' + +
new file mode 100644 --- /dev/null +++ b/test/gsp1.ijs @@ -0,0 +1,91 @@ +NB. -. ------------------------------------------------------------------ + +(scheck -. $.x), (-. -: -.&.$.) x=: _10+? 405$2 +(scheck -. $.x), (-. -: -.&.$.) x=: _10+? 3 4 5$21 +(scheck -. $.x), (-. -: -.&.$.) x=: o._10+? 3 4 5$21 +(scheck -. $.x), (-. -: -.&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck -. $.x), (-. -: -.&.$.) x=: (_10+?60$21),<.-_1+2^31 + +1 -: 3 $. -. $. 0 1 0 +1 -: 3 $. -. $. 2 3 4 +1 -: 3 $. -. $. 2 3.4 +1 -: 3 $. -. $. 2 3j4 + +s=: $. d=: ?2 3 4$2 +(-.d) -: x=: -. s +scheck x +1024 -: type x + + +NB. %. ------------------------------------------------------------------ + +ti=: }. @ }: @ (,/) @ (,."_1 +/&_1 0 1) @ i. NB. indices for tridiagonal system + +g=: 3 : '(_500+?(_2+3*y)$1000) (<"1 ti y)} $. 1$.2$y' +h=: 3 : '_500+?y$1000' + +1e_13 >. >./ | (y=: h 8) (%. -: (%.$.)) x=: g 8 +1e_13 >. >./ | (y=: h 9) (%. -: (%.$.)) x=: g 9 +1e_13 >. >./ | (y=: h 10) (%. -: (%.$.)) x=: g 10 +1e_13 >. >./ | (y=: h 11) (%. -: (%.$.)) x=: g 11 + +1e_13 >. >./ | (y=: h 8) (%. -: (%.$.)) x=: 0.01*g 8 +1e_13 >. >./ | (y=: h 9) (%. -: (%.$.)) x=: 0.01*g 9 +1e_13 >. >./ | (y=: h 10) (%. -: (%.$.)) x=: 0.01*g 10 +1e_13 >. >./ | (y=: h 11) (%. -: (%.$.)) x=: 0.01*g 11 + +1e_13 >. >./ | (y=: h 8) (%. -: (%.$.)) x=: (g 8) j. g 8 +1e_13 >. >./ | (y=: h 9) (%. -: (%.$.)) x=: (g 9) j. g 9 +1e_13 >. >./ | (y=: h 10) (%. -: (%.$.)) x=: (g 10) j. g 10 +1e_13 >. >./ | (y=: h 11) (%. -: (%.$.)) x=: (g 11) j. g 11 + +'nonce error' -: %. etx $. ?7 7$2 +'nonce error' -: %. etx $. ?7 7$20 +'nonce error' -: %. etx $. o.?7 7$20 +'nonce error' -: %. etx $. j.?7 7$20 + +'length error' -: (?10$100) %. etx g 9 + + +NB. %: ------------------------------------------------------------------ + +(scheck %: $.x), (%: -: %:&.$.) x=: _10+? 405$2 +(scheck %: $.x), (%: -: %:&.$.) x=: _10+? 3 4 5$21 +(scheck %: $.x), (%: -: %:&.$.) x=: o._10+? 3 4 5$21 +(scheck %: $.x), (%: -: %:&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck %: $.x), (%: -: %:&.$.) x=: ? 3 4 5$21 +(scheck %: $.x), (%: -: %:&.$.) x=:o.? 3 4 5$21 + +0 -: 3 $. %: $. 1 1 1 +0 -: 3 $. %: $. 2 3 4 +0 -: 3 $. %: $. 2 3.4 +0 -: 3 $. %: $. 2 3j4 + +f=: 4 : '(p%q) -: ((2;x)$.p) % (2;y)$.q' + +p=: ?4 5 3$2 +q=: ?4 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 5 3$4 +q=: ?4 5 3$1000 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 5 3$4 +q=: o.?4 5 3$1000 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ? 4 5 3$4 +q=: j./?2 4 5 3$1000 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'a c d f g h p q r s t ti x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp100.ijs @@ -0,0 +1,100 @@ +NB. + ------------------------------------------------------------------- + +f=: 3 : '(scheck q) *. (+xx) -: q=. +s=: (2;y)$.xx' + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+ 405 ?@$ 2 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+ 3 4 5 ?@$ 21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: o._10+ 3 4 5 ?@$ 21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=:j./o._10+2 3 4 5 ?@$ 21 + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: (_10+?60$21),<.-2^31 + +0 -: 3 $. + $. 0 1 0 +0 -: 3 $. + $. 2 3 4 +0 -: 3 $. + $. 2 3.4 +0 -: 3 $. + $. 2 3j4 + +f=: 4 : '(scheck t) *. (p+q) -: t=: ((2;x)$.p) + (2;y)$.q' +g=: 3 : '(scheck t) *. (p+a) -: t=: ((2;y)$.p) + a' + +p=: (7 5 ?@$ 2) * 7 5 3 ?@$ 10 +q=: (7 5 ?@$ 2) * 7 5 3 ?@$ 10 +a=: ?2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (4 2 5 ?@$ 2) * 4 2 5 3 ?@$ 4 +q=: (4 2 5 ?@$ 2) * 4 2 5 3 ?@$ 4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (4 2 5 ?@$ 2) * 4 2 5 3 ?@$ 4e7 +q=: (4 2 5 ?@$ 2) * 4 2 5 3 ?@$ 4e7 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (4 2 5 ?@$ 2) * o.4 2 5 3 ?@$ 4 +q=: (4 2 5 ?@$ 2) * o.4 2 5 3 ?@$ 4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (4 5 ?@$ 2) * j./2 4 5 3 ?@$ 4 +q=: (4 5 ?@$ 2) * j./2 4 5 3 ?@$ 4 +a=: j./?2e6 2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +f=: 4 : 0 + s=: (2;x)$.xx + t=: (2;y)$.yy + q=. s +"2 t + (q-: xx+"2 yy) *. scheck q +) + +c=: ; (i.1+r) <"1@comb&.>r=:4 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (7 4 3 ?@$ 2) * 7 4 3 5 ?@$ 100 +yy=: (7 3 ?@$ 2) * 7 3 5 ?@$ 100 +c f&>/d + +xx=: (7 4 3 ?@$ 2) * 7 4 3 5 ?@$ 100 +yy=: (7 3 $ 0) * 7 3 5 ?@$ 100 +c f&>/d + +xx=: (7 4 3 $ 0) * 7 4 3 5 ?@$ 100 +yy=: (7 3 ?@$ 2) * 7 3 5 ?@$ 100 +c f&>/d + +xx=: (7 4 3 $ 0) * 7 4 3 5 ?@$ 100 +yy=: (7 3 ?@$ 0) * 7 3 5 ?@$ 100 +c f&>/d + +xx=: (7 3 ?@$ 2) * 7 3 5 ?@$ 100 +yy=: (7 4 3 ?@$ 2) * 7 4 3 5 ?@$ 100 +d f&>/c + +xx=: (7 3 ?@$ 2) * 7 3 5 ?@$ 100 +yy=: (7 4 3 $ 0) * 7 4 3 5 ?@$ 100 +d f&>/c + +xx=: (7 3 $ 0) * 7 3 5 ?@$ 100 +yy=: (7 4 3 ?@$ 2) * 7 4 3 5 ?@$ 100 +d f&>/c + +xx=: ( 7 3$0) * 7 3 5 ?@$ 100 +yy=: ( 7 4 3$0) * 7 4 3 5 ?@$ 100 +d f&>/c + + +4!:55 ;:'a c d f g p q r s t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp101.ijs @@ -0,0 +1,50 @@ +NB. +. ------------------------------------------------------------------ + +f=: 3 : '(+.q) -: +.(2;y)$.q' + +q=: ?2 4 7 5 3$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$q +f&> c + +q=: j./ ?2 2 4 7 5 3$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$q +f&> c + +(+.3j3+i.2 3) -: +. 3j3+$.i.2 3 + +'non-unique sparse elements' -: +. etx 3j4+$.i.2 3 + +f=: 4 : '(p+.q) -: ((2;x)$.p) +. (2;y)$.q' +g=: 3 : '(a+.q) -: a +. (2;y)$.q' + +p=: (?2 4 7$2) * ?2 4 7 3$2 +q=: (?2 4 7$2) * ?2 4 7 3$2 +a=: ?2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 5$2) * ?4 5 3$4e6 +q=: (?4 5$2) * ?4 5 3$4e6 +a=: ?1e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 5$2) * o.?4 5 3$4 +q=: (?4 5$2) * o.?4 5 3$4 +a=: o.?16 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 5$2) * j./?2 4 5 3$4 +q=: (?4 5$2) * j./?2 4 5 3$4 +a=: j./?26 26 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + + +4!:55 ;:'a c f g p q r' +
new file mode 100644 --- /dev/null +++ b/test/gsp102.ijs @@ -0,0 +1,30 @@ +NB. +: ------------------------------------------------------------------ + +(scheck +: $.x), (+: -: +:&.$.) x=: _10+? 405$2 +(scheck +: $.x), (+: -: +:&.$.) x=: _10+? 3 4 5$21 +(scheck +: $.x), (+: -: +:&.$.) x=: o._10+? 3 4 5$21 +(scheck +: $.x), (+: -: +:&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck +: $.x), (+: -: +:&.$.) x=: (_10+?60$21),1.1e9 + +0 -: 3 $. +: $. 0 1 0 +0 -: 3 $. +: $. 2 3 4 +0 -: 3 $. +: $. 2 3.4 +0 -: 3 $. +: $. 2 3j4 + +f=: 4 : '(p+:q) -: ((2;x)$.p) +: (2;y)$.q' + +p=: ?2 3 4$2 +q=: ?2 3 4$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 2 5 3$2 +q=: ?4 2 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c f p q x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp110.ijs @@ -0,0 +1,100 @@ +NB. * ------------------------------------------------------------------- + +f=: 3 : '(*./scheck q) *. (*xx) -: q=. *s=: (2;y)$.xx' + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 405$2 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: o._10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=:j./o._10+?2 3 4 5$21 + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: (_10+?60$21),<.-2^31 + +0 -: 3 $. * $. 0 1 0 +0 -: 3 $. * $. 2 3 4 +0 -: 3 $. * $. 2 3.4 +0 -: 3 $. * $. 2 3j4 + +f=: 4 : '(p*q) -: ((2;x)$.p) * (2;y)$.q' +g=: 3 : '(p*a) -: ((2;y)$.p) * a' + +p=: (?7 5$2) * ?7 5 3$10 +q=: (?7 5$2) * ?7 5 3$10 +a=: ?2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * ?4 2 5 3$4 +q=: (?4 2 5$2) * ?4 2 5 3$4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * ?4 2 5 3$4e7 +q=: (?4 2 5$2) * ?4 2 5 3$4e7 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * o.?4 2 5 3$4 +q=: (?4 2 5$2) * o.?4 2 5 3$4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 5$2) * j./?2 4 5 3$4 +q=: (?4 5$2) * j./?2 4 5 3$4 +a=: j./?2e6 2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +f=: 4 : 0 + s=: (2;x)$.xx + t=: (2;y)$.yy + q=. s *"2 t + (q-: xx*"2 yy) *. *./scheck q +) + +c=: ; (i.1+r) <"1@comb&.>r=:4 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (?5 4 3$2) * ?5 4 3 6$100 +yy=: (?5 3$2) * ?5 3 6$100 +c f&>/d + +xx=: (?5 4 3$2) * ?5 4 3 6$100 +yy=: ( 5 3$0) * ?5 3 6$100 +c f&>/d + +xx=: ( 5 4 3$0) * ?5 4 3 6$100 +yy=: (?5 3$2) * ?5 3 6$100 +c f&>/d + +xx=: ( 5 4 3$0) * ?5 4 3 6$100 +yy=: ( 5 3$0) * ?5 3 6$100 +c f&>/d + +xx=: (?5 3$2) * ?5 3 6$100 +yy=: (?5 4 3$2) * ?5 4 3 6$100 +d f&>/c + +xx=: (?5 3$2) * ?5 3 6$100 +yy=: ( 5 4 3$0) * ?5 4 3 6$100 +d f&>/c + +xx=: ( 5 3$0) * ?5 3 6$100 +yy=: (?5 4 3$2) * ?5 4 3 6$100 +d f&>/c + +xx=: ( 5 3$0) * ?5 3 6$100 +yy=: ( 5 4 3$0) * ?5 4 3 6$100 +d f&>/c + + +4!:55 ;:'a c d f g p q r s t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp111.ijs @@ -0,0 +1,50 @@ +NB. *. ------------------------------------------------------------------ + +f=: 3 : '(*.q) -: *.(2;y)$.q' + +q=: ? 2 4 5 3$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$q +f&> c + +q=: j./ ?2 2 4 5 3$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$q +f&> c + +(*.3ar3+i.2 3) -: *. 3ar3+$.i.2 3 + +'non-unique sparse elements' -: *. etx 3ar4+$.i.2 3 + +f=: 4 : '(p*.q) -: ((2;x)$.p) *. (2;y)$.q' +g=: 3 : '(a*.q) -: a *. (2;y)$.q' + +p=: (?2 4 5$2) * ?2 4 5 3$2 +q=: (?2 4 5$2) * ?2 4 5 3$2 +a=: ?2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?7 5$2) * ?7 5 3$4e6 +q=: (?7 5$2) * ?7 5 3$4e6 +a=: ?1e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?7 5$2) * o.?7 5 3$4 +q=: (?7 5$2) * o.?7 5 3$4 +a=: o.?16 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?7 5$2) * j./?2 7 5 3$4 +q=: (?7 5$2) * j./?2 7 5 3$4 +a=: j./?26 26 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + + +4!:55 ;:'a c f g p q r' +
new file mode 100644 --- /dev/null +++ b/test/gsp112.ijs @@ -0,0 +1,30 @@ +NB. *: ------------------------------------------------------------------ + +(scheck *: $.x), (*: -: *:&.$.) x=: _10+? 405$2 +(scheck *: $.x), (*: -: *:&.$.) x=: _10+? 3 4 5$21 +(scheck *: $.x), (*: -: *:&.$.) x=: o._10+? 3 4 5$21 +(scheck *: $.x), (*: -: *:&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck *: $.x), (*: -: *:&.$.) x=: (_10+?60$21),1.1e9 + +0 -: 3 $. *: $. 0 1 0 +0 -: 3 $. *: $. 2 3 4 +0 -: 3 $. *: $. 2 3.4 +0 -: 3 $. *: $. 2 3j4 + +f=: 4 : '(p*:q) -: ((2;x)$.p) *: (2;y)$.q' + +p=: ?2 3 4$2 +q=: ?2 3 4$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 2 5 3$2 +q=: ?4 2 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c f p q x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp120.ijs @@ -0,0 +1,105 @@ +NB. - monad ------------------------------------------------------------- + +f=: 3 : '(scheck q) *. (-xx) -: q=. -s=: (2;y)$.xx' + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: ? 405$2 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: o._10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=:j./o._10+?2 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: (_10+?60$21),<.-2^31 + +g=: 4 : '(scheck q) *. (-$.^:_1 s) -: q=. -s=: (3;x)$.(2;y)$.xx' + +1 g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: ? 405$2 +_5 6 7 g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 3 4 5$21 +_5 6.7 g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: o._10+? 3 4 5$21 +_5 6j7 g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: j./_10+?2 3 4 5$21 + + +0 -: 3 $. - $. 0 1 0 +0 -: 3 $. - $. 2 3 4 +0 -: 3 $. - $. 2 3.4 +0 -: 3 $. - $. 2 3j4 + +NB. - dyad -------------------------------------------------------------- + +f=: 4 : '(scheck t) *. (p-q) -: t=: ((2;x)$.p) - (2;y)$.q' +g=: 4 : '(scheck t) *. (p-x) -: t=: ((2;y)$.p) - x' +h=: 4 : '(scheck t) *. (x-p) -: t=: x - ((2;y)$.p)' + +p=: (?7 5$2) * ?7 5 3$2 +q=: (?7 5$2) * ?7 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +(1;2;_2.3;2j3) g&>/c +(1;2;_2.3;2j3) h&>/c + +p=: (?4 2 5$2) * ?4 2 5 3$4 +q=: (?4 2 5$2) * ?4 2 5 3$4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +(1;2;_2.3;2j3) g&>/c +(1;2;_2.3;2j3) h&>/c + +p=: (?4 2 5$2) * o.?4 2 5 3$4 +q=: (?4 2 5$2) * o.?4 2 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +(1;2;_2.3;2j3) g&>/c +(1;2;_2.3;2j3) h&>/c + +p=: (?7 5$2) * j./?2 7 5 3$4 +q=: (?7 5$2) * j./?2 7 5 3$4 +a=: j./?2e6 2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +(1;2;_2.3;2j3) g&>/c +(1;2;_2.3;2j3) h&>/c + +f=: 4 : 0 + s=: (2;x)$.xx + t=: (2;y)$.yy + q=. s -"2 t + (q-: xx-"2 yy) *. scheck q +) + +c=: ; (i.1+r) <"1@comb&.>r=:4 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (?5 4 2$2) * ?5 4 2 6$100 +yy=: (?5 2$2) * ?5 2 6$100 +c f&>/d + +xx=: (?5 4 2$2) * ?5 4 2 6$100 +yy=: ( 5 2$0) * ?5 2 6$100 +c f&>/d + +xx=: ( 5 4 2$0) * ?5 4 2 6$100 +yy=: (?5 2$2) * ?5 2 6$100 +c f&>/d + +xx=: ( 5 4 2$0) * ?5 4 2 6$100 +yy=: ( 5 2$0) * ?5 2 6$100 +c f&>/d + +xx=: (?5 2$2) * ?5 2 6$100 +yy=: (?5 4 2$2) * ?5 4 2 6$100 +d f&>/c + +xx=: (?5 2$2) * ?5 2 6$100 +yy=: ( 5 4 2$0) * ?5 4 2 6$100 +d f&>/c + +xx=: ( 5 2$0) * ?5 2 6$100 +yy=: (?5 4 2$2) * ?5 4 2 6$100 +d f&>/c + +xx=: ( 5 2$0) * ?5 2 6$100 +yy=: ( 5 4 2$0) * ?5 4 2 6$100 +d f&>/c + + +4!:55 ;:'a c d f g h p q r s t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp122.ijs @@ -0,0 +1,92 @@ +NB. -: ------------------------------------------------------------------ + +(scheck -: $.x), (-: -: -:&.$.) x=: _10+? 405$2 +(scheck -: $.x), (-: -: -:&.$.) x=: _10+? 3 4 5$21 +(scheck -: $.x), (-: -: -:&.$.) x=: o._10+? 3 4 5$21 +(scheck -: $.x), (-: -: -:&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. -: $. 0 1 0 +0 -: 3 $. -: $. 2 3 4 +0 -: 3 $. -: $. 2 3.4 +0 -: 3 $. -: $. 2 3j4 + +x -: (3;17)$.x=: $. 1+?3 4 5$100 + +f=: 4 : '((2;x)$.s) -: (2;y)$.s' + +d=: ?6 4 5 3$7 +s=: $. d +d -: s + +c=: ; (i.1+r) <"1@comb&.>r=:#$s +f&>/~c + +x=: 2 3$0 +y=: 0 * $.i.2 3 +x -: y +x -:~ y +((3;5)$.$.x) -: 5 + y +((3;5)$.$.x) -:~ 5 + y + +x=: 0*$.?4 10$2 +y=: 0*$.?4 10$2 +x -: y +(x+5) -: y+10%2 +((3;0)$.x) -: (3;o.0)$.y + +x=: 20 (<1 2)}1$.3 4;0 1;10 +y=: 10 (<2 3)}1$.3 4;0 1;20 +0 = x -: y +0 = y -: x + +x=: (3;10) $. $. 3 4$100 +y=: (3;20) $. $. 3 4$100 +x -: y +y -: x + +x=: $. 4 4 4 +y=: (3;4)$.$. 0 4 4 +x -: y +y -: x + +x=: ?17 41$5 +y=: ?17 41$5 +s=: ($.x) = $.y +t=: $. x=y +s -: t + +x=: 1$.1e8 2e8 3e8;0 1;o.0 +y=: 1$.1e8 2e8 3e8;0 1;o.0 +x -: y + +NB. non-covered data in a must match we + +p=: 1+?6 7 5 3$10 + +f=: 3 : '((5 1#0 88)+(5 1#1 0)*p) -: s=: (3;88)$.(2;y)$.(5 1#1 0)*p' +g=: 3 : '((5 1#0 88)+(5 1#1 0)*p) -:~s=: (3;88)$.(2;y)$.(5 1#1 0)*p' +f&>0;0 1;0 1 2;0 1 2 3 +g&>0;0 1;0 1 2;0 1 2 3 + +NB. unequal sparse element but complete coverage in sparse data + +p=: ?6 7 5 3$10 + +f=: 3 : '(1+p) -: s=: (3;88)$.(2;y)$.1+p' +g=: 3 : '(1+p) -:~s=: (3;88)$.(2;y)$.1+p' +f&>c=: ; (i.1+r) <"1@comb&.>r=:#$p +g&>c + +NB. same indices but different values + +p=: ?6 7 5 3$10 + +f=: 3 : '-. (2*p) -: s=: (2;y)$.p' +g=: 3 : '-. (2*p) -:~ s=: (2;y)$.p' +f&>c=: ; (i.1+r) <"1@comb&.>r=:#$p +g&>c + + +4!:55 ;:'c d f g p q r s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp130.ijs @@ -0,0 +1,100 @@ +NB. % ------------------------------------------------------------------- + +f=: 3 : '(*./scheck q) *. (%xx) -: q=. %s=: (2;y)$.xx' + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 405$2 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: _10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: o._10+? 3 4 5$21 +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=:j./o._10+?2 3 4 5$21 + +f&> c=: ; (i.1+r) <"1@comb&.>r=:#$xx=: (_10+?60$21),<.-2^31 + +0 -: 3 $. + $. 0 1 0 +0 -: 3 $. + $. 2 3 4 +0 -: 3 $. + $. 2 3.4 +0 -: 3 $. + $. 2 3j4 + +f=: 4 : '(p%q) -: ((2;x)$.p) % (2;y)$.q' +g=: 3 : '(p%a) -: ((2;y)$.p) % a' + +p=: (?7 5$2) * ?7 5 3$10 +q=: (?7 5$2) * ?7 5 3$10 +a=: ?2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * ?4 2 5 3$4 +q=: (?4 2 5$2) * ?4 2 5 3$4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * ?4 2 5 3$4e7 +q=: (?4 2 5$2) * ?4 2 5 3$4e7 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 2 5$2) * o.?4 2 5 3$4 +q=: (?4 2 5$2) * o.?4 2 5 3$4 +a=: ?2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +p=: (?4 5$2) * j./?2 4 5 3$4 +q=: (?4 5$2) * j./?2 4 5 3$4 +a=: j./?2e6 2e6 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c +g&>c + +f=: 4 : 0 + s=: (2;x)$.xx + t=: (2;y)$.yy + q=. s %"2 t + (q-: xx%"2 yy) *. *./scheck q +) + +c=: ; (i.1+r) <"1@comb&.>r=:4 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (?5 2 3$2) * ?5 2 3 7$100 +yy=: (?5 3$2) * ?5 3 7$100 +c f&>/d + +xx=: (?5 2 3$2) * ?5 2 3 7$100 +yy=: ( 5 3$0) * ?5 3 7$100 +c f&>/d + +xx=: ( 5 2 3$0) * ?5 2 3 7$100 +yy=: (?5 3$2) * ?5 3 7$100 +c f&>/d + +xx=: ( 5 2 3$0) * ?5 2 3 7$100 +yy=: ( 5 3$0) * ?5 3 7$100 +c f&>/d + +xx=: (?5 3$2) * ?5 3 7$100 +yy=: (?5 2 3$2) * ?5 2 3 7$100 +d f&>/c + +xx=: (?5 3$2) * ?5 3 7$100 +yy=: ( 5 2 3$0) * ?5 2 3 7$100 +d f&>/c + +xx=: ( 5 3$0) * ?5 3 7$100 +yy=: (?5 2 3$2) * ?5 2 3 7$100 +d f&>/c + +xx=: ( 5 3$0) * ?5 3 7$100 +yy=: ( 5 2 3$0) * ?5 2 3 7$100 +d f&>/c + + +4!:55 ;:'a c d f g p q r s t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp2.ijs @@ -0,0 +1,151 @@ +NB. ^ ------------------------------------------------------------------- + +(scheck ^ $.x), (^ -: ^&.$.) x=: _10+? 405$2 +(scheck ^ $.x), (^ -: ^&.$.) x=: _10+? 3 4 5$21 +(scheck ^ $.x), (^ -: ^&.$.) x=: o._10+? 3 4 5$21 +(scheck ^ $.x), (^ -: ^&.$.) x=:j./o._10+?2 3 4 5$21 + +1 -: 3 $. ^ $. 0 1 0 +1 -: 3 $. ^ $. 2 3 4 +1 -: 3 $. ^ $. 2 3.4 +1 -: 3 $. ^ $. 2 3j4 + +f=: 4 : '(p^q) -: ((2;x)$.p) ^ (2;y)$.q' + +p=: ?4 3 5 2$2 +q=: ?4 3 5 2$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 3 5 2$4 +q=: ?4 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?3 5 2$4 +q=: o.?3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: j./?2 3 5 2$4 +q=: j./?2 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +NB. ^. ------------------------------------------------------------------ + +(scheck ^. $.x), (^. -: ^.&.$.) x=: _10+? 405$2 +(scheck ^. $.x), (^. -: ^.&.$.) x=: _10+? 3 4 5$21 +(scheck ^. $.x), (^. -: ^.&.$.) x=: o._10+? 3 4 5$21 +(scheck ^. $.x), (^. -: ^.&.$.) x=:j./o._10+?2 3 4 5$21 + +__ -: 3 $. ^. $. 0 1 0 +__ -: 3 $. ^. $. 2 3 4 +__ -: 3 $. ^. $. 2 3.4 +__ -: 3 $. ^. $. 2 3j4 + +f=: 4 : '(p^.q) -: ((2;x)$.p) ^. (2;y)$.q' + +p=: ?3 5 2$2 +q=: ?3 5 2$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +(<'NaN error') = f etx &.>/~c + + +NB. $ ------------------------------------------------------------------- + +d=: ?3 4 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : 0 + a=: 5,(-x){.$d + s=: a ($,)"(1,x) (2;y)$.d + *./ (scheck s), s-: a ($,)"(1,x) d +) + +(i.>:r) f&>/ c + +f=: 4 : 0 + a=: 2 + s=: a ($,)"(1,x) (2;y)$.d + *./ (scheck s), s-: a ($,)"(1,x) d +) + +(i.>:r) f&>/ c + +f=: 4 : 0 + a=: 1+?>.1.5*(>.1.2*x){.($d),r$2 + s=: (2;y)$.d + t=: a ($,)"(1,x) s + b=. t -: a ($,)"(1,x) d + if. 0=#$t do. b else. *./ (scheck t), b end. +) + +(i.>:r) f&>/ c + +f=: 4 : 0 + b=. ('' ($,)"(1,x) d) -: t=. '' ($,)"(1,x) (2;y)$.d + if. 4096=type t do. b=. b*. scheck t end. +) + +(i.>:r) f&>/ c [ d=: (?3 4 5$2) * ?3 4 5 2$4 +(i.>:r) f&>/ c [ d=: 0*d + +'length error' -: '' ($,) etx $. i.2 3 0 + + +NB. | ------------------------------------------------------------------- + +(scheck | $.x), (| -: |&.$.) x=: _10+? 405$2 +(scheck | $.x), (| -: |&.$.) x=: _10+? 3 4 5$21 +(scheck | $.x), (| -: |&.$.) x=: o._10+? 3 4 5$21 +(scheck | $.x), (| -: |&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck | $.x), (| -: |&.$.) x=: (_10+?60$21),<.-2^31 + +0 -: 3 $. | $. 0 1 0 +0 -: 3 $. | $. 2 3 4 +0 -: 3 $. | $. 2 3.4 +0 -: 3 $. | $. 2 3j4 + +f=: 4 : '(p|q) -: ((2;x)$.p) | (2;y)$.q' + +p=: ?6 5 2$2 +q=: ?6 5 2$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?6 5 2$4 +q=: ?6 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?3 5 2$4 +q=: o.?3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: j./?2 3 5 2$4 +q=: j./?2 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +NB. |: ------------------------------------------------------------------ + +x=: ?7 6 5 4 3 2$3 + +f=: 3 : 0 " 0 + r=: #$x + c=: (1+?r)?r + p=: ?~r + (p|:x) -: p|:(2;c)$.x +) + +f"0 i.4 10 + + +4!:55 ;:'a c d f g i p q r s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp221.ijs @@ -0,0 +1,35 @@ +NB. ~. ------------------------------------------------------------------ + +f=: 3 : '(scheck t) *. (~.p) -: t=: ~.s=: (2;y)$.p' + +c=: ; (i.1+r) <"1@comb&.>r=: 4 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$2 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * o. ? 50 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * j./?2 50 4 5 3$100 + +c=: ; (i.1+r) <"1@comb&.>r=: 3 +f&> c [ p=: ?100 4 5$1000 +f&> c [ p=: 0 (0)} ?100 4 5$1000 +f&> c [ p=: 0 (9)} ?100 4 5$1000 +f&> c [ p=: 0 * ?100 4 5$1000 +f&> c [ p=: (?200$100) { ?100 4 5$1000 +f&> c [ p=: (?200$100) {(?100 4$2) * ?100 4 5$1000 + +(~.$.p) -: ~.p=: i.0 +(~.$.p) -: ~.p=: i.0 5 +(~.$.p) -: ~.p=: i.5 0 + +p=: ?100$1e9 +q=: (?100$20){?20 5$10 +s=: q p}1 $. 1e9 5 ; 0 ; 2-2 +t=: ~.s +scheck t +($t) -: $~.0,q +(2$.t) -: ,0 +(3$.t) -: 0 +(4$.t) -: ,. (i.#t)-.{.(i.1+#p) -. p +(5$.t) -: ~.q/:p + + +4!:55 ;:'c f p q r s t' \ No newline at end of file
new file mode 100644 --- /dev/null +++ b/test/gsp222.ijs @@ -0,0 +1,66 @@ +NB. ~: monad ------------------------------------------------------------ + +f=: 3 : '(scheck t) *. (~:p) -: t=: ~:s=: (2;y)$.p' + +c=: ; (i.1+r) <"1@comb&.>r=: 4 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$2 +f&> c [ p=: (?200$100) { (?100 4 5$2) * ? 100 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * o. ? 50 4 5 3$100 +f&> c [ p=: (?100$ 50) { (? 50 4 5$2) * j./?2 50 4 5 3$100 + +c=: ; (i.1+r) <"1@comb&.>r=: 3 +f&> c [ p=: ?100 4 5$1000 +f&> c [ p=: 0 (0)} ?100 4 5$1000 +f&> c [ p=: 0 (9)} ?100 4 5$1000 +f&> c [ p=: 0 * ?100 4 5$1000 +f&> c [ p=: (?200$100) { ?100 4 5$1000 +f&> c [ p=: (?200$100) {(?100 4$2) * ?100 4 5$1000 + +(~:$.p) -: ~:p=: i.0 +(~:$.p) -: ~:p=: i.0 5 +(~:$.p) -: ~:p=: i.5 0 + +p=: ?100$1e9 +q=: (?100$20){?20 5$10 +s=: q p}1 $. 1e9 5 ; 0 ; 2-2 +t=: ~:s +scheck t +($t) -: ,#s +(2$.t) -: ,0 +(3$.t) -: 0 +(4$.t) -: ,. /:~ ~. (s i.5$0) , (~:q/:p)#p/:p +(5$.t) -: (#4$.t)$1 + +s=: 4 (0)}1 $. 10 ; 0 ; 5 +(~:s) -: ~:0$.s +scheck ~:s + + +NB. ~: dyad ------------------------------------------------------------- + +f=: 4 : '(p~:q) -: ((2;x)$.p) ~: (2;y)$.q' + +p=: ?4 3 5 2$2 +q=: ?4 3 5 2$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?4 3 5 2$4 +q=: ?4 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?4 3 5 2$4 +q=: o.?4 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: j./?2 3 5 2$4 +q=: j./?2 3 5 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c f p q r s t' + +
new file mode 100644 --- /dev/null +++ b/test/gsp231.ijs @@ -0,0 +1,78 @@ +NB. |. ------------------------------------------------------------------ + +(scheck |. $.x), (|. -: |.&.$.) x=: _10+? 405$2 +(scheck |. $.x), (|. -: |.&.$.) x=: _10+? 3 4 5$21 +(scheck |. $.x), (|. -: |.&.$.) x=: o._10+? 3 4 5$21 +(scheck |. $.x), (|. -: |.&.$.) x=:j./o._10+?2 3 4 5$21 + +(scheck |.y), (|.x) -: |.y=:(2;0 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;1 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;2 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;0 1 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;0 2 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;1 0 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;1 2 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;2 0 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;2 1 )$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;0 1 2)$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;0 2 1)$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;1 0 2)$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;1 2 0)$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;2 0 1)$. x=:_2+?5 7 11$5 +(scheck |.y), (|.x) -: |.y=:(2;2 1 0)$. x=:_2+?5 7 11$5 + +(scheck |."0 y), (|."0 x) -: |."0 y=:(2;a=:(>:?4)?4)$. x=: _2+?3 5 7 11$5 +(scheck |."1 y), (|."1 x) -: |."1 y=:(2;a=:(>:?4)?4)$. x=: _2+?3 5 7 11$5 +(scheck |."2 y), (|."2 x) -: |."2 y=:(2;a=:(>:?4)?4)$. x=: _2+?3 5 7 11$5 +(scheck |."3 y), (|."3 x) -: |."3 y=:(2;a=:(>:?4)?4)$. x=: _2+?3 5 7 11$5 + +s=: 11 7 5 +x=: _3+?s$5 + +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;0 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;1 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;2 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;0 1 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;0 2 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;1 0 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;1 2 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;2 0 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;2 1 )$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;0 1 2)$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;0 2 1)$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;1 0 2)$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;1 2 0)$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;2 0 1)$. x +(scheck r|.y), (r|.x) -: $.^:_1 (r=:((#r){.$y)-~r=:?((?4)$+:s))|.y=:(2;2 1 0)$. x + +x=:_3+?7 5 4 3 2$5 + +f=: 3 : 0 + s=: $x + r=: #s + i=: ((#i){.s)-~i=:?(?1+r)$1+4*s + a=: (?1+r)?r + (i|.x) -: i|.(2;a)$.x +) + +f"0 i.4 10 + +d=: (?7 5 11$3) * ?7 5 11 3$10 +c=: ; (i.1+r) <"1@comb&.> r=: #s=: $d + +f=: 4 : 0 + r=: x + i=: _50+?((-r)}.s)$100 + (i|."(0,r) d) -: i|."(0,r) (2;y)$.d +) + +'domain error' -: 3.4 |. etx $. i.2 3 4 +'domain error' -: 3j4 |. etx $. i.2 3 4 +'domain error' -: 3r4 |. etx $. i.2 3 4 +'domain error' -: '345' |. etx $. i.2 3 4 +'domain error' -: (<3 4)|. etx $. i.2 3 4 + +'length error' -: (i.4) |. etx $. i.2 3 4 + + +4!:55 ;:'a f i r s x y'
new file mode 100644 --- /dev/null +++ b/test/gsp320.ijs @@ -0,0 +1,52 @@ +NB. , ------------------------------------------------------------------- + +a=: (?11 5 7$2) * ?11 5 7 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$a + +f=: 4 : '(*./ scheck t) *. (,"x a) -: t=: ,"x s=:(2;y)$.a' +(i.>:r) f&>/ c + +s=: 1 $. 2e9 3 4;0;0 +s=: (?7 3 4$4) (?7$2e9)}s +scheck s +scheck ,"2 s + +'limit error' -: , etx 1 $.(3$ 2e9);0 1 2;0 +'limit error' -: ,"2 etx 1 $.(>IF64{2 4 2e9;2 1e10 2e9);0 1 2;0 + +d=: (?6 3 5$2) * ?6 3 5 2$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : '((d,"r 0) -: s,"r 0) *. ( 0,"r d) -: 0,"r s=:(2;y)$.d [ r=:x' +g=: 4 : '((d,"r 99) -: s,"r 99) *. (99,"r d) -: 99,"r s=:(2;y)$.d [ r=:x' +h=: 4 : '(((97+d),"r 99) -: (97+s),"r 99) *. (99,"r 97+d) -: 99,"r 97+s=:(2;y)$.d [ r=:x' + +(i.1+#$d) f&>/c +(i.1+#$d) g&>/c +(i.1+#$d) h&>/c + +'limit error' -: 3 , etx 1$. _1+2^IF64{31 63 +'limit error' -: (1$._1+2^IF64{31 63) , etx 3 + +f=: 4 : '(a ,"r b) -: (s=: (2;x)$.a) ,"r t=: (2;y)$.b' +h=: 4 : '(a ,"r&(97&+) b) -: (s=: (2;y)$.a) ,"r&(97&+) t=: (2;y)$.b' + +c=: ; (i.1+r) <"1@comb&.>r=:#$a=: (?2 5 3$2) * ?2 5 3 4$5 +d=: ; (i.1+r) <"1@comb&.>r=:#$b=: (?2 5 3$2) * ?2 5 3 4$5 + +c f&>/ d [ r=: 0 +c f&>/ d [ r=: 1 +c f&>/ d [ r=: 2 +c f&>/ d [ r=: 3 +c f&>/ d [ r=: 4 + +c h&>/ d [ r=: 0 +c h&>/ d [ r=: 1 +c h&>/ d [ r=: 2 +c h&>/ d [ r=: 3 +c h&>/ d [ r=: 4 + + +4!:55 ;:'a b c d f g h r s t' + +
new file mode 100644 --- /dev/null +++ b/test/gsp321.ijs @@ -0,0 +1,37 @@ +NB. ,. ------------------------------------------------------------------- + +f=: 4 : '(*./ scheck t) *. (,."x d) -: t=: ,."x s=:(2;y)$.d' +d=: (?5 7$2) * ?5 7 3 2$4 + +(i.>:r) f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d + +s=: 1 $. 2e9 3 4;0;0 +s=: (?7 3 4$4) (?7$2e9)}s +scheck s +scheck ,."2 s + +'limit error' -: ,. etx 1 $.(4$2e9);0 1 2;0 +'limit error' -: ,."3 etx 1 $.(>IF64{2 1 4 2e9;2 1 1e10 2e9);0 1 2;0 + +f=: 4 : '(a ,."r b) -: (s=: (2;x)$.a) ,."r t=: (2;y)$.b' +h=: 4 : '(a ,."r&(97&+) b) -: (s=: (2;y)$.a) ,."r&(97&+) t=: (2;y)$.b' + +c=: ; (i.1+r) <"1@comb&.>r=:#$a=: (?2 5 3$2) * ?2 5 3 4$5 +d=: ; (i.1+r) <"1@comb&.>r=:#$b=: (?2 5 3$2) * ?2 5 3 4$5 + +c f&>/d [ r=: 0 +c f&>/d [ r=: 1 +c f&>/d [ r=: 2 +c f&>/d [ r=: 3 +c f&>/d [ r=: 4 + +c h&>/d [ r=: 0 +c h&>/d [ r=: 1 +c h&>/d [ r=: 2 +c h&>/d [ r=: 3 +c h&>/d [ r=: 4 + + +4!:55 ;:'a b c d f g h r s t' + +
new file mode 100644 --- /dev/null +++ b/test/gsp322.ijs @@ -0,0 +1,30 @@ +NB. ,: ------------------------------------------------------------------ + +a=: ?5 7 3 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$a + +f=: 4 : '*./ (scheck t), (,:"x a) -: t=:,:"x s=:(2;y)$.a' +(i.>:r) f&>/ c + +f=: 4 : '(a ,:"r b) -: (s=: (2;x)$.a) ,:"r t=: (2;y)$.b' +h=: 4 : '(a ,:"r&(97&+) b) -: (s=: (2;y)$.a) ,:"r&(97&+) t=: (2;y)$.b' + +c=: ; (i.1+r) <"1@comb&.>r=:#$a=: (?2 5 3$2) * ?2 5 3 4$5 +d=: ; (i.1+r) <"1@comb&.>r=:#$b=: (?2 5 3$2) * ?2 5 3 4$5 + +c f&>/ d [ r=: 0 +c f&>/ d [ r=: 1 +c f&>/ d [ r=: 2 +c f&>/ d [ r=: 3 +c f&>/ d [ r=: 4 + +c h&>/ d [ r=: 0 +c h&>/ d [ r=: 1 +c h&>/ d [ r=: 2 +c h&>/ d [ r=: 3 +c h&>/ d [ r=: 4 + + +4!:55 ;:'a b c d f g h r s t' + +
new file mode 100644 --- /dev/null +++ b/test/gsp331.ijs @@ -0,0 +1,71 @@ +NB. #;.n ---------------------------------------------------------------- + +f=: 3 : 0 + assert. (#;. 1 q) -: #;. 1 qs=: (2;y)$.q + assert. (#;._1 q) -: #;._1 qs + assert. (#;. 2 q) -: #;. 2 qs + assert. (#;._2 q) -: #;._2 qs + 1 +) + +f&>'';0 [ q=: ?1000$2 +f&>'';0 [ q=: 0=?1000$10 +f&>'';0 [ q=: 1, 0=?1000$10 +f&>'';0 [ q=: 0, 0=?1000$10 +f&>'';0 [ q=: 1,~0=?1000$10 +f&>'';0 [ q=: 0,~0=?1000$10 + +j=: ?1000$2e9 +s=: 1 j}1$.2e9;0;0 +(#;.1~s) -: 2 -~/\(/:~j),#s + + +NB. f;.n ---------------------------------------------------------------- + +f=: 1 : 0 + : + assert. (scheck t) *. (x u;. 1 y) -: t=: x u;. 1 $. y + assert. (scheck t) *. (x u;. 1 y) -: t=: x u;. 1 (2;0)$. y + assert. (scheck t) *. (x u;. 1 y) -: t=: x u;. 1 (2;1)$. y + assert. (scheck t) *. (x u;._1 y) -: t=: x u;._1 $. y + assert. (scheck t) *. (x u;._1 y) -: t=: x u;._1 (2;0)$. y + assert. (scheck t) *. (x u;._1 y) -: t=: x u;._1 (2;1)$. y + assert. (scheck t) *. (x u;. 2 y) -: t=: x u;. 2 $. y + assert. (scheck t) *. (x u;. 2 y) -: t=: x u;. 2 (2;0)$. y + assert. (scheck t) *. (x u;. 2 y) -: t=: x u;. 2 (2;1)$. y + assert. (scheck t) *. (x u;._2 y) -: t=: x u;._2 $. y + assert. (scheck t) *. (x u;._2 y) -: t=: x u;._2 (2;0)$. y + assert. (scheck t) *. (x u;._2 y) -: t=: x u;._2 (2;1)$. y + 1 +) + +n=: 211 +p +/ f q [ p=: ?n$2 [ q=: (?n$2) * ?(n,3)$5 +p ] f q +p +/ f q [ p=: 0=?n$5 [ q=: (?n$2) * ?(n,3)$5 +p ] f q +p +/ f q [ p=: 0<?n$5 [ q=: (?n$2) * ?(n,3)$5 +p ] f q + +classify=: 4 : 0 + (#x) }. (+/\i<#x) i}i=. /:x,y +) + +cut1=: 1 : 0 + : + i=. (4$.x) classify 4$.y + s=. (i~:}:_1,i) u ;.1 (5$.y) + ((0 e. i)}. s) (<:~.(0~:i)#i)}1 $. (+/x);0;-~{.s +) + +i=: ?1000$2e9 +j=: ?5000$2e9 +x=: ?5000$2e9 +p=: 1 i}1$.2e9;0;0 +q=: x j}1$.2e9;0;2-2 +(p +/;.1 q) -: p +/ cut1 q + + +4!:55 ;:'classify cut1 f i j n p q qs s t x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp400.ijs @@ -0,0 +1,132 @@ +NB. boolean # ----------------------------------------------------------- + +d=: (?13 13 13$2) * ?13 13 13 13$100 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : '(scheck t) *. (b #"(1,x) d) -: t=: b #"(1,x) s=: (2;y)$.d' +(i.1+r) f&>/ c [ b=: ?13$2 +(i.1+r) f&>/ c [ b=: $. ?13$2 +(i.1+r) f&>/ c [ b=: -. $. ?13$2 + +f=: 3 : '(b #"(1,y) d) -: ($.^:_1 b) #"(1,y) d' +f"0 i.1+r [ b=: $.?13$2 +f"0 i.1+r [ b=: -.$.?13$2 + +f=: 4 : '(b #"(1,x) (2;y)$.d) -: ($.^:_1 b) #"(1,x) d' +(i.1+r) f&>/ c [ b=: $.?13$2 +(i.1+r) f&>/ c [ b=: (3;1)$.1=$.?13$5 + +i=: /:~ 1e3 ? 1e9 +b=: 1 i}1 $. 1e9 ; 0 ; 0 +j=: /:~ ~.(?2e3$2e3){i,?1000$1e9 +d=: ?((#j),3)$1000 +s=: d j}1 $. 1e9 3 ; 0 ; 2-2 +t=: b#s +scheck t +t -: (i e. j)&#^:_1 (j e. i)#d + +i=: /:~ 1e3 ? 1e9 +b=: 0 i}1 $. 1e9 ; 0 ; 1 +j=: /:~ ~.(?2e3$2e3){i,?1000$1e9 +d=: ?((#j),3)$1000 +s=: d j}1 $. 1e9 3 ; 0 ; 2-2 +t=: b#s +scheck t +($t) -: (+/b),3 +(5$.t) -: (-. j e. i)#d + +'length error' -: ($. 0 1 0) # etx $. i.4 3 +'length error' -: ($. 1 0 1) #"1 etx $. i.3 4 + + +NB. integer # ----------------------------------------------------------- + +d=: (?9 9 9$2) * ?9 9 9 9$100 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : '(scheck t) *. (a #"(1,x) d) -: t=: a #"(1,x) s=: (2;y)$.d' +(i.1+r) f&>/ c [ a=: ?9$5 +(i.1+r) f&>/ c [ a=: $. ?9$5 +(i.1+r) f&>/ c [ a=: $. ]&.o. ?9$5 + +i=: /:~ 1e3 ? 1e9 +x=: ?1e3$5 +a=: x i}1 $. 1e9 ; 0 ; 2-2 +j=: /:~ ~.(?2e3$2e3){i,?1000$1e9 +d=: ?((#j),3)$1000 +s=: d j}1 $. 1e9 3 ; 0 ; 0 +t=: a#s +scheck t +($t) -: (+/a),{:$s +(5$.t) -: ((i i. j){x,0)#d + +'domain error' -: ($. 2 3 _1 ) # etx $. 3 4 5 + +'limit error' -: ($. >IF64{1e9 2e9;4e18 6e18) # etx $. 3 4 + +'length error' -: ($. 1 2 3) # etx $. i.4 3 +'length error' -: ($. 1 2 3) #"1 etx $. i.3 4 + + +NB. complex # ----------------------------------------------------------- + +d=: (?7 7 7$2) * ?7 7 7 7$100 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : '(scheck t) *. (a #"(1,x) d) -: t=: a #"(1,x) s=: (2;y)$.d' +(i.1+r) f&>/ c [ a=: (0<?7$3) * j./?2 7$5 +(i.1+r) f&>/ c [ a=: $. (0<?7$3) * j./?2 7$5 + +i=: /:~ 1e3 ? 1e9 +x=: j./?2 1e3$5 +a=: x i}1 $. 1e9 ; 0 ; 2-2 +j=: /:~ ~.(?2e3$2e3){i,?1000$1e9 +d=: ?((#j),3)$1000 +s=: d j}1 $. 1e9 3 ; 0 ; 0 +t=: a#s +scheck t +($t) -: (+/@,+.a),{:$s +(5$.t) -: 0 0 0 -.~ ((i i. j){x,0)#d + +'domain error' -: ($. 2 3 _1j4) # etx $. 3 4 5 +'domain error' -: ($. 2 3j_2 4) # etx $. 3 4 5 + +'limit error' -: ($. >IF64{1e9 0j2e9; 4e18 0j6e18) # etx $. 3 4 + +'length error' -: ($. 1 2 3j2) # etx $. i.4 3 +'length error' -: ($. 1 2 3j2) #"1 etx $. i.3 4 + + +NB. # with scalars ------------------------------------------------------ + +d=: (?5 7 11$2) * ?5 7 11 13$100 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 4 : '(scheck t) *. (a #"(1,x) d) -: t=: a#"(1,x) s=: (2;y)$.d' +(i.1+r) f&>/ c [ a=: 0 +(i.1+r) f&>/ c [ a=: 1 + +(i.1+r) f&>/ c [ a=: 3 +(i.1+r) f&>/ c [ a=: 2-2 +(i.1+r) f&>/ c [ a=: 1.5-0.5 +(i.1+r) f&>/ c [ a=: o.0 + +(i.1+r) f&>/ c [ a=: 0j3 +(i.1+r) f&>/ c [ a=: 3j2 + +(d#5) -: a#5 [ a=: $. d=: (0<?13$3) * ? 13$2 +(d#5) -: a#5 [ a=: $. d=: (0<?13$3) * ? 13$5 +(d#5) -: a#5 [ a=: $. d=: (0<?13$3) * j./?2 13$5 + +i=: /:~ 1e3 ? 5e8 +x=: ?1e3$100 +s=: x i}1 $. 5e8 ; 0 ; 2-2 +t=: 3 # s +scheck t +t -: (3#x) (,(3*i)+/i.3)} 1 $. 15e8 ; 0 ; 2-2 + +'limit error' -: 5 # etx 1 $. (IF64{1e9 3e18);0;0 + +4!:55 ;:'a b c d f g h i j r s t x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp410.ijs @@ -0,0 +1,42 @@ +NB. ! ------------------------------------------------------------------- + +(scheck ! $.x), (! -: !&.$.) x=: _10+? 405$2 +(scheck ! $.x), (! -: !&.$.) x=: _10+? 3 4 5$21 +(scheck ! $.x), (! -: !&.$.) x=: o._10+? 3 4 5$21 +(scheck ! $.x), (! -: !&.$.) x=:j./o._10+?2 3 4 5$21 + +1 -: 3 $. ! $. 0 1 0 +1 -: 3 $. ! $. 2 3 4 +1 -: 3 $. ! $. 2 3.4 +1 -: 3 $. ! $. 2 3j4 + +(!e) -: 3 $. ! (3;e=: ?20 ) $. $. 1 2 3 +(!e) -: 3 $. ! (3;e=:o. ?5 ) $. $. 1 2 3 +(!e) -: 3 $. ! (3;e=:j./?10 10) $. $. 1 2 3 + +f=: 4 : '(p!q) -: ((2;x)$.p) ! (2;y)$.q' + +p=: ?7 5 3$2 +q=: ?7 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?7 5 3$4 +q=: ?7 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: o.?7 5 3$4 +q=: o.?7 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: j./?2 5 3 2$4 +q=: j./?2 5 3 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c d f p q r x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp412.ijs @@ -0,0 +1,22 @@ +NB. !: ------------------------------------------------------------------ + +f=: 0 !:($.0) +f=: ($.0)!: 0 +f=: ($.0)!:($.0) + +f=: 0 !:($.2) +f=: ($.0)!: 2 +f=: ($.0)!:($.2) + +f=: 3 !:($.0) +f=: ($.3)!: 0 +f=: ($.3)!:($.0) + +f=: 4 !:($.2) +f=: ($.4)!: 2 +f=: ($.4)!:($.2) + + +4!:55 ;:'f' + +
new file mode 100644 --- /dev/null +++ b/test/gsp420.ijs @@ -0,0 +1,252 @@ +NB. / ------------------------------------------------------------------- + +(=/x ) -: =/$.x=: ?1000$2 +(=/1,x) -: =/$.1,x +(=/0,x) -: =/$.0,x +(=/x+.0=x) -: =/(3;1)$.$.x=:?1000$2 + +(<./x) -: <./$.x=: ?1000$2 +(<./x) -: <./$.x=: _10+?1000$21 +(<./x) -: <./$.x=: o. _10+?1000$21 +(<./x+c*0=x) -: <./ (3;c=:_20+?40)$.$.x=: _10+?1000$21 + +(>./x) -: >./$.x=: ?1000$2 +(>./x) -: >./$.x=: _10+?1000$21 +(>./x) -: >./$.x=: o. _10+?1000$21 +(>./x+c*0=x) -: >./ (3;c=:_20+?40)$.$.x=: _10+?1000$21 + +(+/x) -: +/$.x=: ? 1000$2 +(+/x) -: +/$.x=: _10+? 1000$21 +(+/x) -: +/$.x=: o. _10+? 1000$21 +(+/x) -: +/$.x=: j./_10+?2 1000$21 +(+/x) -: +/$.x=: ( _5+?1000$21),<._1+2^31 +(+/x) -: +/$.x=: (_15+?1000$21),<.- 2^31 +(+/x+c*0=x) -: +/ (3;c=:_20+?40)$.$.x=: _10+?1000$21 +(+/ x) -: +/ $.x=: ?2 3 4 5$2e9 +(+/"1 x) -: +/"1 $.x=: ?2 3 4 5$2e9 +(+/"2 x) -: +/"2 $.x=: ?2 3 4 5$2e9 +(+/"3 x) -: +/"3 $.x=: ?2 3 4 5$2e9 + +(+./x) -: +./$.x=:?1000$2 +(+./x+.0=x) -: +./(3;1)$.$.x=:?1000$2 + +(*/x) -: */$.x=: ? 7$2 +(*/x) -: */$.x=: _10+? 7$21 +(*/x) -: */$.x=: o. _10+? 7$21 +(*/x) -: */$.x=: j./_10+?2 7$21 +(*/x) -: */$.x=: ( _5+?7$21),<._1+2^31 +(*/x) -: */$.x=: (_15+?7$21),<.- 2^31 +(*/x+c*0=x) -: */ (3;c=:_20+?40)$.$.x=: _10+?7$21 + +(*./x) -: *./$.x=:?1000$2 +(*./x+.0=x) -: *./(3;1)$.$.x=:?1000$2 + +(~:/x) -: ~:/$.x=: ?1000$2 +(~:/x+.0=x) -: ~:/(3;1)$.$.x=:?1000$2 + + +f=: 1 : (':'; '(scheck t) *. (u/"x d) -: t=: u/"x s=:(2;y)$.d') + +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?11 5 4 3 2$5 +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: 1+?11 5 4 3 2$5 +(>:i.r) >.f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?11 5 4 3 2$5 +(>:i.r) <.f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?11 5 4 3 2$5 +(>:i.r) = f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?11 5 4 3 2$2 +(>:i.r) ~:f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?11 5 4 3 2$2 +(>:i.r) +.f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?11 5 4 3 2$2 +(>:i.r) *.f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?11 5 4 3 2$2 + +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: 11 5 4 3 2$0 +(>:i.r) +.f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: 11 5 4 3 2$0 + +0 -: + / 1 $. 20 ; 0 ; 2-2 +40 -: + / 1 $. 20 ; 0 ; 2 +0 -: * / 1 $. 5 ; 0 ; 2-2 +1 -: * / 1 $. 5 ; 0 ; 2-1 +32 -: * / 1 $. 5 ; 0 ; 2 +17 -: >./ 1 $. 19 ; 0 ; 17 +_7 -: <./ 1 $. 19 ; 0 ; _7 + +1 -: = / 1 $. 20 ; 0 ; 0 +0 -: = / 1 $. 19 ; 0 ; 0 +1 -: = / 1 $. 20 ; 0 ; 1 +1 -: = / 1 $. 19 ; 0 ; 1 + +0 -: ~:/ 1 $. 20 ; 0 ; 0 +0 -: ~:/ 1 $. 19 ; 0 ; 0 +0 -: ~:/ 1 $. 20 ; 0 ; 1 +1 -: ~:/ 1 $. 19 ; 0 ; 1 + +0 -: +./ 1 $. 20 ; 0 ; 0 +1 -: +./ 1 $. 20 ; 0 ; 1 +0 -: *./ 1 $. 20 ; 0 ; 0 +1 -: *./ 1 $. 20 ; 0 ; 1 + +g=: 1 : (':'; '(scheck t) *. (u/"x $.^:_1 s) -: t=: u/"x s=:(3;e)$.(2;y)$.d') + +(>:i.r) + g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?8 6 5 3 2$5 [ e=: 17 +(>:i.r) + g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?8 6 5 3 2$5 [ e=: _7 +(>:i.r) * g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?8 6 5 3 2$5 [ e=: 2 +(>:i.r) * g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?8 6 5 3 2$5 [ e=: _1 +(>:i.r) +.g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?8 6 5 3 2$2 [ e=: 1 +(>:i.r) *.g&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?8 6 5 3 2$2 [ e=: 1 + + +NB. f/@, ---------------------------------------------------------------- + +f=: 1 : 0 + s=: (2;y)$.d + x=.u/,d + (x -: u/@, s) *. (x -: u/@:,s) *. (x -: u/&, s) *. x -: u/&:, s +) + += f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 11$2 += f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 12$2 +~: f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 11$2 +~: f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 12$2 ++. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 11$2 ++. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 12$2 +*. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 11$2 +*. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 12$2 +<. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _1e9+?7 3 5 11$2e9 +>. f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _1e9+?7 3 5 12$2e9 ++ f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _1e9+?7 3 5 11$2e9 +* f&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: 1+?7 3 5 12$10 + +g=: 1 : 0 + s=:(3;e)$.(2;y)$.d + x=. u/, $.^:_1 s + (x -: u/@, s) *. (x -: u/@:,s) *. (x -: u/&, s) *. x -: u/&:, s +) + += g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 15$2 [ e=: 1 += g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 16$2 [ e=: 1 +~: g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 17$2 [ e=: 1 +~: g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 18$2 [ e=: 1 ++. g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 15$2 [ e=: 1 ++. g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 16$2 [ e=: 1 +*. g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 17$2 [ e=: 1 +*. g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 18$2 [ e=: 1 ++ g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?7 3 5 11$5 [ e=: 17 ++ g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?7 3 5 12$5 [ e=: _7 +* g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 13$5 [ e=: 2 +* g&> c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?7 3 5 14$5 [ e=: _1 + +(+/@, s) -: +/,s=: $. 1e8*i.3 4 +(*/@, s) -: */,s=: $. 100+i.3 4 + + +NB. f/ over axis of length 2 -------------------------------------------- + +f=: 1 : 0 + : + s=: (2;y)$.d + assert. ((0{"x d) u (1{"x d)) -: t=: u/"x s + assert. scheck s + assert. scheck t + 1 +) + +(>:i.r) = f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) = f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) = f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) = f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) < f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) < f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) < f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) <. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) <. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) <. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) <: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) <: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) <: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) > f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) > f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) > f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) >. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) >. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) >. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) >: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) >: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) >: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 + +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: (_1+?2 2 2 2 2$3)*1e6+2^30 +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) + f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) +. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) +. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) +. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) +. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) +: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 + +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: (_1+?2 2 2 2 2$2)*1e7 +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) * f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) *. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) *. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) *. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) *. f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) *: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 + +(>:i.r) - f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) - f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) - f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: (_1+?2 2 2 2 2$3)*1e6+2^30 +(>:i.r) - f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) - f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) % f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) % f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) % f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: (_1+?2 2 2 2 2$3)*1e6+2^30 +(>:i.r) % f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) % f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) ^ f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) ^ f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) ^ f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) ^ f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) ~: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) ~: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) ~: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) ~: f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) | f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) | f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) | f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) | f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + +(>:i.r) ! f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: ?2 2 2 2 2$2 +(>:i.r) ! f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=: _2+?2 2 2 2 2$5 +(>:i.r) ! f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:o._2+?2 2 2 2 2$5 +(>:i.r) ! f&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d=:r._2+?2 2 2 2 2$5 + + +NB. ,/ ------------------------------------------------------------------ + +f=: 4 : '(scheck t) -: (,/"x d) -: t=: ,/"x s=:(2;y)$.d' + +d=: (?11 5$2) * ?11 5 2 7$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: (1+i.r) f&>/ c + +'limit error' -: ,/ etx $. 0$~>IF64{1e5 1e6 0;1e10 2e9 0 + + +4!:55 ;:'b c d e f g r s x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp421.ijs @@ -0,0 +1,46 @@ +NB. #/. ----------------------------------------------------------------- + +d=: (?1000$2) * ?1000 2 3$10 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 3 : 'assert. (#/.~ d) -: #/.~ s=: (2;y)$.d' +f&> c + +f=: 3 : 'assert. (#/.~ $.^:_1 s) -: #/.~ s=: (b=: ?1000 2$ 2) * (2;y)$.d' +f&> c + +f=: 3 : 'assert. (#/.~ $.^:_1 s) -: #/.~ s=: (b=: 0=?1000 2$10) * (2;y)$.d' +f&> c + +'length error' -: ($. i.9) #/.~ etx i.8 +'length error' -: ($. i.9) #/.~ etx 1 + +i=: 1+?1e3$2e9 +x=: ?1e3$100 +s=: x i} 1 $. 2e9 ; 0 ; 2-2 +t=: #/.~ s +b=: 0~:x +t -: ((#s)-+/b),#/.~ (b#x)/:b#i + + +NB. f/. ----------------------------------------------------------------- + +d=: (?947 2$2) * ?947 2 3$8 +c=: ; (i.1+r) <"1@comb&.>r=:#$d +y=: ?((#d),4)$1000 + +f=: 1 : (':'; '(d u/.y) -: s u/.y [ s=: (2;x)$.d') +c < f&> <y +c +/ f&> <y +c |. f&> <y + +j=: ?100$~#d +f=: 1 : (':'; '((0 j}d) u/.y) -: s u/.y [ s=: 0 j}(2;x)$.d') +c < f&> <y +c +/ f&> <y +c |. f&> <y + + +4!:55 ;:'b c d f i j r s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp422.ijs @@ -0,0 +1,68 @@ +NB. /: monad ------------------------------------------------------------ + +f=: 4 : 0 + assert. (/: x) -: /: y + assert. (/:"1 x) -: /:"1 y + assert. (/:"2 x) -: /:"2 y + for_i. i.#y do. assert. (/: i{x) -: /: i{y end. + 1 +) + +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * ? 5 10 3$2 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * _2 +? 5 10 3$5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * o. _2 +? 5 10 3$5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * j./ _2 +? 2 5 10 3$5 +x f y [ x=: (2;0)$.y + +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * ? 5 10 3$2 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * _2e5+? 5 10 3$5e5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * o. _2e5+? 5 10 3$5e5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * j./ _2e5+? 2 5 10 3$5e5 +x f y [ x=: (2;0)$.y + +f=: 4 : '(/:"x xx) -: /:"x s=: (2;y)$.xx' +c=: ; (i.1+r) <"1@comb&.>r=:4 + +(1+i.r) f&>/ c [ xx=: ? 7 11 13 17$2 +(1+i.r) f&>/ c [ xx=: _2 +? 7 11 13 17$5 +(1+i.r) f&>/ c [ xx=: o. _2 +? 7 11 13 17$5 +(1+i.r) f&>/ c [ xx=: j./_2 +?2 7 11 13 17$5 + +(1+i.r) f&>/ c [ xx=: _2e5+? 7 11 13 17$2e5 +(1+i.r) f&>/ c [ xx=: o. _2e5+? 7 11 13 17$5e5 +(1+i.r) f&>/ c [ xx=: j./_2e5+?2 7 11 13 17$5e5 + +(1+i.r) f&>/ c [ xx=: 7 11 13 17$0 + + +NB. /: dyad ------------------------------------------------------------- + +f=: 4 : 0 + assert. (a/:y) -: a/:(2;x)$.y + 1 +) + +n=: 100 +y=: (?(n,2)$2) * ?(n,2 3)$1000 +c=: ; (i.1+r) <"1@comb&.>r=: #$y + +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + +y=: (?(n,2)$2) * o.?(n,2 3)$1000 +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + +y=: (?(n,2)$2) * ?(n,2 3)$2 +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + + +4!:55 ;:'a c f n r s xx y' +
new file mode 100644 --- /dev/null +++ b/test/gsp431.ijs @@ -0,0 +1,86 @@ +NB. \. ------------------------------------------------------------------ + +f =: 1 : (':'; '(u/\."x d ) -: $.^:_1 u/\."x (2;y)$.d ') +f2=: 2 : (':'; '(u/\."x d+0=d) -: $.^:_1 u/\."x (3;n)$.(2;y)$.d+0=d') + +rk=: #@$ +g =: i. @ >: @ rk +h =: ; @ (i.@>: <"1@comb&.> ]) @ rk + +(g = f&>/ h) d=: ? 5 7 6 2$2 +(g = f&>/ h) d=: _2+? 5 3 4 2$5 +(g = f&>/ h) d=: o. _2+? 5 3 4 2$5 +(g = f&>/ h) d=: j./_2+?2 5 3 4 2$5 + +(g < f&>/ h) d=: ? 5 7 6 2$2 +(g < f&>/ h) d=: _2+? 5 3 4 2$5 +(g < f&>/ h) d=: o. _2+? 5 3 4 2$5 + +(g <.f&>/ h) d=: ? 5 7 6 2$2 +(g <.f&>/ h) d=: _2+? 5 7 6 2$5 +(g <.f&>/ h) d=: o. _2+? 5 7 6 2$5 + +(g > f&>/ h) d=: ? 5 7 6 2$2 +(g > f&>/ h) d=: _2+? 5 3 4 2$5 +(g > f&>/ h) d=: o. _2+? 5 3 4 2$5 + +(g >.f&>/ h) d=: ? 5 7 6 2$2 +(g >.f&>/ h) d=: _2+? 5 7 6 2$5 +(g >.f&>/ h) d=: o. _2+? 5 7 6 2$5 + +(g + f&>/ h) d=: ? 5 7 6 2$2 +(g + f&>/ h) d=: _2+? 5 7 6 2$5 +(g + f&>/ h) d=: o. _2+? 5 7 6 2$5 +(g + f&>/ h) d=: j./_2+?2 5 3 6 2$5 + +(g +.f&>/ h) d=: ? 5 7 6 2$2 +(g +.f&>/ h) d=: _2+? 5 3 4 2$5 +(g +.f&>/ h) d=: o. _2+? 5 3 4 2$5 +(g +.f&>/ h) d=: j./_2+?2 5 3 4 2$5 + +(g +:f&>/ h) d=: ? 5 7 6 2$2 + +(g *.f&>/ h) d=: ? 5 7 6 2$2 +(g *.f&>/ h) d=: _2+? 5 3 4 2$5 +(g *.f&>/ h) d=: o. _2+? 5 3 4 2$5 +(g *.f&>/ h) d=: j./_2+?2 5 3 4 2$5 + +(g *:f&>/ h) d=: ? 5 7 6 2$2 + +(g - f&>/ h) d=: ? 5 7 6 2$2 +(g - f&>/ h) d=: _2+? 5 7 6 2$5 +(g - f&>/ h) d=: o. _2+? 5 7 6 2$5 +(g - f&>/ h) d=: j./_2+?2 5 3 6 2$5 + +(g ~:f&>/ h) d=: ? 5 7 6 2$2 +(g ~:f&>/ h) d=: _2+? 5 7 6 2$5 +(g ~:f&>/ h) d=: o. _2+? 5 7 6 2$5 +(g ~:f&>/ h) d=: j./_2+?2 5 3 6 2$5 + +(g = f2 1&>/ h) d=: ? 5 7 6 2$2 +(g = f2 1&>/ h) d=: _2+? 5 3 6 2$5 +(g = f2 1&>/ h) d=: o. _2+? 5 3 6 2$5 +(g = f2 1&>/ h) d=: j./_2+?2 5 3 6 2$5 + +(g * f2 1&>/ h) d=: ? 5 3 6 2$2 +(g * f2 1&>/ h) d=: _2+? 5 3 6 2$5 +(g * f2 1&>/ h) d=: o. _2+? 5 3 6 2$5 +(g * f2 1&>/ h) d=: j./_2+?2 5 3 6 2$5 + +(g % f2 1&>/ h) d=: ? 5 3 6 2$2 +(g % f2 1&>/ h) d=: _2+? 5 3 6 2$5 +(g % f2 1&>/ h) d=: o. _2+? 5 3 6 2$5 +(g % f2 1&>/ h) d=: j./_2+?2 5 3 6 2$5 + +d=: $.^:_1 s=: 1$.7 11 13;0 1 2;_1 +(+/\. d) -: +/\. s +(+/\."1 d) -: +/\."1 s +(+/\."2 d) -: +/\."2 s +(-/\. d) -: -/\. s +(-/\."1 d) -: -/\."1 s +(-/\."2 d) -: -/\."2 s + + +4!:55 ;:'d f f2 g h rk s' + +
new file mode 100644 --- /dev/null +++ b/test/gsp432.ijs @@ -0,0 +1,70 @@ +NB. \: monad ------------------------------------------------------------ + +f=: 4 : 0 + assert. (\: x) -: \: y + assert. (\:"1 x) -: \:"1 y + assert. (\:"2 x) -: \:"2 y + for_i. i.#y do. assert. (\: i{x) -: \: i{y end. + 1 +) + +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * ? 5 10 3$2 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * _2 +? 5 10 3$5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * o. _2 +? 5 10 3$5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$1 0 0) * j./ _2 +? 2 5 10 3$5 +x f y [ x=: (2;0)$.y + +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * ? 5 10 3$2 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * _2e5+? 5 10 3$5e5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * o. _2e5+? 5 10 3$5e5 +x f y [ x=: (2;0)$.y +x f y [ x=: $. y=: ((?10$2), 0, 1, 0 ,: 10$0 0 1) * j./ _2e5+? 2 5 10 3$5e5 +x f y [ x=: (2;0)$.y + +f=: 4 : '(\:"x xx) -: \:"x s=: (2;y)$.xx' +c=: ; (i.1+r) <"1@comb&.>r=:4 + +(1+i.r) f&>/ c [ xx=: ? 7 11 13 17$2 +(1+i.r) f&>/ c [ xx=: _2 +? 7 11 13 17$5 +(1+i.r) f&>/ c [ xx=: o. _2 +? 7 11 13 17$5 +(1+i.r) f&>/ c [ xx=: j./_2 +?2 7 11 13 17$5 + +(1+i.r) f&>/ c [ xx=: _2e5+? 7 11 13 17$2e5 +(1+i.r) f&>/ c [ xx=: o. _2e5+? 7 11 13 17$5e5 +(1+i.r) f&>/ c [ xx=: j./_2e5+?2 7 11 13 17$5e5 + +(1+i.r) f&>/ c [ xx=: 7 11 13 17$0 + + +NB. \: dyad ------------------------------------------------------------- + +f=: 4 : 0 + assert. (a\:y) -: a\:(2;x)$.y + 1 +) + +n=: 100 +y=: (?(n,2)$2) * ?(n,2 3)$1000 +c=: ; (i.1+r) <"1@comb&.>r=: #$y + +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + +y=: (?(n,2)$2) * o.?(n,2 3)$1000 +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + +y=: (?(n,2)$2) * ?(n,2 3)$2 +c f&> <y [ a=: ?(n,4)$1000 +c f&> <y [ a=: $.?(n,4)$1000 + + +4!:55 ;:'a c f n r s xx y' + + +
new file mode 100644 --- /dev/null +++ b/test/gsp520.ijs @@ -0,0 +1,97 @@ +NB. { ------------------------------------------------------------------- + +f=: 3 : '(i{d) -: $.^:_1 i{(2;y)$.s' +d=: ?6 5 4 3 2$100 +s=: $.d +i=: ?2 4$6 + +f"1 ] 1 comb 5 +f"1 ] 2 comb 5 +f"1 ] 3 comb 5 +f"1 ] 4 comb 5 +f"1 ] 5 comb 5 + +r=: 3 +f=: 3 : '(i{"r d) -: $.^:_1 i{"r (2;y)$.s' +d=: ?6 5 4 3 2$100 +s=: $.d +i=: ?2 4 1$(-r){$s + +f"1 ] 1 comb 5 +f"1 ] 2 comb 5 +f"1 ] 3 comb 5 +f"1 ] 4 comb 5 +f"1 ] 5 comb 5 + +r=: 4 +f=: 3 : '(i{"r d) -: $.^:_1 i{"r (2;y)$.s' +d=: ?6 5 4 3 2$100 +s=: $.d +i=: ?2 1 4$(-r){$s + +f"1 ] 1 comb 5 +f"1 ] 2 comb 5 +f"1 ] 3 comb 5 +f"1 ] 4 comb 5 +f"1 ] 5 comb 5 + +d=: ? 11 7 8 3 2$4 + +f=: 4 : '(y{"(_,x) d) -: $.^:_1 y{"(_,x) s' +h=: 3 : '*./ ; g&.> >:i.#$s=:(2;y)$.d' + +g=: 3 : 'y f"0 i.(-y){$d' +h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +g=: 3 : 'y f ?2 3 4$(-y){$d' +h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +d=: ? 11 7 3 2$4 +f=: 3 : '(y{d) -: $.^:_1 y{s' +g=: 3 : '?&.> (>:@?&.>(?n$5)$&.>4)$&.>n{.s [ n=.1+?#s=. $y' +h=: 3 : 'f <i=:g s=:(2;y)$.d' +h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +s=: $. ?11 7 3 2$4 +((<<"0 i){s) -: (<i){s [ i=: ?}:$s + +(0{x) -: 0{$.x=: 2 4 0 8 16 24 +(2{x) -: 2{$.x +(0{x) -: 0{(2;'')$.x +(2{x) -: 2{(2;'')$.x +(i{x) -: (i=: <?$x){$.x=: ?2 3 4$3 + +d=: ?11 5 7 3 2$4 +f=: 3 : '(y{d) -: y{s' +g=: 4 : '?((>:?(?5)$5),x)$x{.$y' +h=: 4 : 'f i=:<"1 x g s=:(2;y)$.d' +(>:i.r) h&>/ c=: ; (i.1+r) <"1@comb&.>r=:#$d + +0 -: (<r$<0){$.(>:i.r)$0 [ r=: 1 +0 -: (<r$<0){$.(>:i.r)$0 [ r=: 2 +0 -: (<r$<0){$.(>:i.r)$0 [ r=: 3 +0 -: (<r$<0){$.(>:i.r)$0 [ r=: 4 +0 -: (<r$<0){$.(>:i.r)$0 [ r=: 5 + +d=: (?11 5 7$2)*?11 5 7 3 2$4 +h=: 3 : 's -: i{s=:(2;y)$.d' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +h&>c [ i=: <'' +h&>c [ i=: <$0 + +'domain error' -: 'abc' { etx $. i.2 3 + +'rank error' -: (<2 3$<0){ etx $. i.2 3 + +'length error' -: (<2;3;4) { etx $. i.5 6 + +'index error' -: 2 { etx $. i.2 3 +'index error' -: _3 { etx $. i.2 3 +'index error' -: (<'ab') { etx $. i.2 3 +'index error' -: (<2;'a') { etx $. i.2 3 + + +4!:55 ;:'c d f g h i r s x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp520sd.ijs @@ -0,0 +1,37 @@ +NB. x{y for sparse x, dense y ------------------------------------------- + +p=: (?7 3 5$2) * ?7 3 5 4$10 +c=: ; (i.1+r) <"1@comb&.>r=:#$p + +f=: 4 : '(scheck t) *. (p{"(_,x) q) -: t=. ((2;y)$.p) {"(_,x) q' + +1 2 3 f&>/c [ q=: (-1+$q){.q=: ? 9 10 12$2 +1 2 3 f&>/c [ q=: (-1+$q){.q=: ? 9 10 12$100 +1 2 3 f&>/c [ q=: (-1+$q){.q=: o. ? 9 10 12$100 +1 2 3 f&>/c [ q=: (-1+$q){.q=: j./?2 9 10 12$100 + +f=: 3 : '(scheck t) *. ((0*p){"_ 0 q) -: t=. (0*(2;y)$.p) {"_ 0 q' + +f&> c [ q=: 1 1 1 +f&> c [ q=: 2 3$?2e6 +f&> c [ q=: 2 1 3$o.?2e6 +f&> c [ q=: 2 1 1 3$j./?2$2e6 + +'nonce error' -: ($.i.2 3) { etx 'abcdef' +'nonce error' -: ($.i.2 3) { etx ;:'a b c d e f' +'nonce error' -: ($.i.2 3) { etx i.7x +'nonce error' -: ($.i.2 3) { etx 9 % 1+i.7x +'nonce error' -: ($.i.2 3) { etx s: ' a b c d e f' + +'domain error' -: ($.o.i.2 3) { etx i.9 + +'index error' -: ($.i.2 3) { etx i.4 +'index error' -: ((3;6)$.$.i.2 3) { etx i.6 + +'non-unique sparse elements' -: ($.i.2 3){ etx i.6 3 +'non-unique sparse elements' -: ($.i.2 3){"2 1 etx i.2 6 + + +4!:55 ;:'c f p q r' + +
new file mode 100644 --- /dev/null +++ b/test/gsp520ss.ijs @@ -0,0 +1,31 @@ +NB. x{y for sparse x, sparse y ------------------------------------------ + +p=: (?6 3$2) * ?6 3 4$7 +q=: (?11 7 9$2) * 0,?10 7 9 8$124 +pc=: ; (i.1+pr) <"1@comb&.>pr=:#$p +qc=: ; (i.1+qr) <"1@comb&.>qr=:#$q + +f=: 4 : '(scheck z) *. (p{q) -: z=: (s=: (2;x)$.p) { t=:(2;y)$.q' +pc f&>/ qc + +f=: 4 : '(scheck z) *. (p{"_ 1 q) -: z=: (s=: (2;x)$.p) {"_ 1 t=:(2;y)$.q' +pc f&>/ qc [ q=: (0,7$1)*"1 (?11 7 9$2) * ?11 7 9 8$124 + +f=: 4 : '(scheck z) *. (p{"_ 2 q) -: z=: (s=: (2;x)$.p) {"_ 2 t=:(2;y)$.q' +pc f&>/ qc [ q=: (0,8$1)*"2 (?11 7 9$2) * ?11 7 9 8$124 + +f=: 4 : '(scheck z) *. (p{"_ 3 q) -: z=: (s=: (2;x)$.p) {"_ 3 t=:(2;y)$.q' +pc f&>/ qc [ q=: (0,6$1)*"3 (?11 7 9$2) * ?11 7 9 8$124 + +'domain error' -: ($.o.i.2 3) { etx $.i.9 + +'index error' -: ($.i.2 3) { etx $.0,i.3 5 +'index error' -: ((3;6)$.$.i.2 3) { etx $.0,i.5 2 1 + +'non-unique sparse elements' -: ($.i.2 3){ etx $.i.6 3 +'non-unique sparse elements' -: ($.i.2 3){"2 1 etx $.i.2 6 + + +4!:55 ;:'f p pc pr q qc qr s t z' + +
new file mode 100644 --- /dev/null +++ b/test/gsp521.ijs @@ -0,0 +1,53 @@ +NB. {. ------------------------------------------------------------------- + +(scheck x{.$.y), (x=:_5 _10+?12 24) ({. -: {.&.$.) y=: ? 12 24 3$2 +(scheck x{.$.y), (x=:_5 _10+?12 24) ({. -: {.&.$.) y=: _10+? 12 24 3$21 +(scheck x{.$.y), (x=:_5 _10+?12 24) ({. -: {.&.$.) y=: o._10+? 12 24 3$21 +(scheck x{.$.y), (x=:_5 _10+?12 24) ({. -: {.&.$.) y=: j./o._10+?2 12 24 3$21 + +(scheck x{.$.y), (x=:0 ) ({. -: {.&.$.) y=: ? 12 24 3$2 +(scheck x{.$.y), (x=:3 2 0 ) ({. -: {.&.$.) y=: _10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 0 3 ) ({. -: {.&.$.) y=: o._10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 0 ) ({. -: {.&.$.) y=: j./o._10+?2 12 24 3$21 + +(scheck x{.$.y), (x=:_ ) ({. -: {.&.$.) y=: ? 12 24 3$2 +(scheck x{.$.y), (x=:3 2 _ ) ({. -: {.&.$.) y=: _10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 _ 3 ) ({. -: {.&.$.) y=: o._10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 _ ) ({. -: {.&.$.) y=: j./o._10+?2 12 24 3$21 + +(scheck x{.$.y), (x=:__ ) ({. -: {.&.$.) y=: ? 12 24 3$2 +(scheck x{.$.y), (x=:3 2 __) ({. -: {.&.$.) y=: _10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 __ 3) ({. -: {.&.$.) y=: o._10+? 12 24 3$21 +(scheck x{.$.y), (x=:2 __ ) ({. -: {.&.$.) y=: j./o._10+?2 12 24 3$21 + +(x {.!.e y) -: $.^:_1 (x=: 10 20){. (3;e=:?100)$.$.y=: 2 3 5$1 +(x {.!.e y) -: $.^:_1 (x=: 10 20){. (3;e=:?100)$.$.y=: 1+?2 3 5$21 +(x {.!.e y) -: $.^:_1 (x=: 10 20){. (3;e=:?100)$.$.y=: o. 1+?2 3 5$21 +(x {.!.e y) -: $.^:_1 (x=: 10 20){. (3;e=:?100)$.$.y=: j./1+?2 3 5$21 + +(scheck x{."1$.y), (x=:12 -~?25 ) ({."1 -: {."1&.$.) y=:_10+?12 24 3$21 +(scheck x{."2$.y), (x=:12 24 -~?25 49 ) ({."2 -: {."2&.$.) y=:_10+?12 24 3$21 +(scheck x{."3$.y), (x=:12 24 3-~?25 49 7) ({."3 -: {."3&.$.) y=:_10+?12 24 3$21 + +x=: _1 2 +y=: 10*i.2 3 4 +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;0 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;1 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;2 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;0 1 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;0 2 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;1 0 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;1 2 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;2 0 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;2 1 )$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;0 1 2)$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;0 2 1)$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;1 0 2)$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;1 2 0)$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;2 0 1)$.$.y +(scheck x{.t), (x{.y) -: $.^:_1 x{.t=: (2;2 1 0)$.$.y + + +4!:55 ;:'e t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp530i.ijs @@ -0,0 +1,120 @@ +NB. } integer indices ---------------------------------------------------- + +d=: ?11 5 7 3 2$4 + +f=: 4 : '(x y}d) -: $.^:_1 x y}s' +h=: 4 : 'x f i=:g s=:(2;y)$.d' + +g=: 3 : '(>:?5$5) ?@$ #s' +0 h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +g=: 3 : '(>:?3$2) ?@$ #s' +0 h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +g=: 3 : '(>:?5$5) ?@$ #s' +99 h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +g=: 3 : '(>:?3$2) ?@$ #s' +99 h&>c=: ; (i.1+r) <"1@comb&.>r=:#$d + +d=: (?23 5$2) * ?23 5 7 3 2$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$d +f=: 3 : '(a i}d) -: $.^:_1 a i}s [ a=:h i=:g s=:(2;y)$.d' +g=: 3 : '(>:?4$4) ?@$ #d' + +h=: 3 : '(}.$d) ?@$ 10' +] b=: f&>c + +h=: 3 : '(($i),}.$d) ?@$ 10' +] b=: f&>c + +g=: 3 : '?#d' NB. scalar index +h=: 3 : '?(}.$d)$5' NB. dense replacement data +] b=: f&>c + +g=: 3 : '?#d' NB. scalar index +h=: 3 : '$.?(}.$d)$5' NB. sparse replacement data +] b=: f&>c + +s=: $. d=: 1 0 1 0 1 * 10*i.5 3 +(1 2 3 (0)}d) -: 1 2 3 (0)}s +(1 2 3 (1)}d) -: 1 2 3 (1)}s +(1 2 3 (2)}d) -: 1 2 3 (2)}s +(1 2 3 (3)}d) -: 1 2 3 (3)}s +(1 2 3 (4)}d) -: 1 2 3 (4)}s + + +NB. amend in place ------------------------------------------------------- + +d=: (0=?37$3)*?37 1000$1000 +s=: (2;0)$.d + +i=: ,(?5$#i){i=: 4$.s +(IF64{9000 12000) > t=: 7!:2 's=: 0 i}s' +s -: d=: 0 i}d +scheck s + +i=: ,(?5$#i){i=: 4$.s +x=: ?((#i),{:$s)$1000 +(IF64{9000 12000) > t=: 7!:2 's=: x i}s' +s -: d=: x i}d +scheck s + +i=: (?5$#i){i=:(i.37)-.,4$.s +x=: ?((#i),{:$s)$1000 +s=: x i}s NB. not in place +s -: d=: x i}d +scheck s + + +NB. amend in place with sparse replacement data -------------------------- + +d=: (0=?23456$10)*?23456 10$1000 +s=: (2;0)$.d + +i=: ,(?5$#i){i=: 4$.s +x=: $. (?($x)$2)*x=: ?($i{s)$1000 +(IF64{40000 80000) > t=: 7!:2 's=: x i}s' +s -: d=: x i}d +scheck s + +i=: (?5$#i){i=:(i.#s)-.,4$.s +x=: (?($x)$2)*x=: ?($i{s)$1000 +s=: x i}s NB. not in place +s -: d=: x i}d +scheck s + + +NB. sparse replacement data ---------------------------------------------- + +d=: (?23 5$2) * ?23 5 3 2 4$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 3 : '(a i}d) -: ($.a) i}s=:(2;y)$.d [ a=: g i' +g=: 3 : '?($y{d)$7' +m=: #d + +] b=: f&>c [ i=: m-~? 3$+:m +] b=: f&>c [ i=: m-~? 6$+:m +] b=: f&>c [ i=: m-~?24$+:m +] b=: f&>c [ i=: m-~?48$+:m + +s=: 1$.5 6;'';123 +d=: 5 6$123 +i=: ?2$5 +x=: ?($i{d)$1000 +s -: d +(x i}d) -: x i}s + +'domain error' -: (3 4$'x') 2 0} etx $.i.2 3 4 +'domain error' -: (3 4$<4 ) 2 0} etx $.i.2 3 4 + +'index error' -: (i.2 3) 4 0} etx $.i.4 2 3 +'index error' -: (i.2 3) _5 0} etx $.i.4 2 3 + +'length error' -: (i.2 3) 2 0} etx $.i.4 3 2 + + +4!:55 ;:'a b c d f g h i m r s t x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp530l.ijs @@ -0,0 +1,161 @@ +NB. } index list --------------------------------------------------------- + +d=: (?23 5$2)*?23 5 7 3 2$4 + +f=: 3 : '(0 i}d) -: 0 i}s=:(2;y)$.d' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: f&>c [ i=: <?@( 12&$)&.>1{.$d +] b=: f&>c [ i=: <?@( 2 6&$)&.>2{.$d +] b=: f&>c [ i=: <?@(2 2 3&$)&.>3{.$d +] b=: f&>c [ i=: <?@( 4 3&$)&.>4{.$d +] b=: f&>c [ i=: <?@(1 3 3&$)&.>5{.$d + +] b=: f&>c [ i=: <'' +] b=: f&>c [ i=: <a:;?3$5 +] b=: f&>c [ i=: <a:;a:;?4$7 +] b=: f&>c [ i=: <a:;a:;a:;?2$3 +] b=: f&>c [ i=: <a:;a:;a:;a:;?2 + +] b=: f&>c [ i=: <<i.0 +] b=: f&>c [ i=: <a:;i.0 +] b=: f&>c [ i=: <a:;a:;i.0 +] b=: f&>c [ i=: <a:;a:;a:;i.0 +] b=: f&>c [ i=: <a:;a:;a:;a:i.0 + +d=: (?23 5$2)*?23 5 7 3 2$4 + +f=: 4 : '(x i}d) -: x i}s=:(2;y)$.d' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: 99 f&>c [ i=: <?@( 12&$)&.>1{.$d +] b=: 99 f&>c [ i=: <?@( 2 6&$)&.>2{.$d +] b=: 99 f&>c [ i=: <?@(2 2 3&$)&.>3{.$d +] b=: 99 f&>c [ i=: <?@( 4 3&$)&.>4{.$d +] b=: 99 f&>c [ i=: <?@(1 3 3&$)&.>5{.$d + +] b=: 99 f&>c [ i=: <'' +] b=: 99 f&>c [ i=: <a:;?3$5 +] b=: 99 f&>c [ i=: <a:;a:;?4$7 +] b=: 99 f&>c [ i=: <a:;a:;a:;?2$3 +] b=: 99 f&>c [ i=: <a:;a:;a:;a:;?2 + +] b=: 99 f&>c [ i=: <<i.0 +] b=: 99 f&>c [ i=: <a:;i.0 +] b=: 99 f&>c [ i=: <a:;a:;i.0 +] b=: 99 f&>c [ i=: <a:;a:;a:;i.0 +] b=: 99 f&>c [ i=: <a:;a:;a:;a:i.0 + +d=: (?23 5$2)*?23 5 7 3 2$4 + +f=: 3 : '(a i}d) -: a i}s=:(2;y)$.d [ a=: ?($i{d)$100' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: f&>c [ i=: <?@( 12&$)&.>1{.$d +] b=: f&>c [ i=: <?@( 2 6&$)&.>2{.$d +] b=: f&>c [ i=: <?@(2 2 3&$)&.>3{.$d +] b=: f&>c [ i=: <?@( 4 3&$)&.>4{.$d +] b=: f&>c [ i=: <?@(1 3 3&$)&.>5{.$d + +] b=: f&>c [ i=: <'' +] b=: f&>c [ i=: <a:;?3$5 +] b=: f&>c [ i=: <a:;a:;?4$7 +] b=: f&>c [ i=: <a:;a:;a:;?2$3 +] b=: f&>c [ i=: <a:;a:;a:;a:;?2 + +] b=: f&>c [ i=: <<i.0 +] b=: f&>c [ i=: <a:;i.0 +] b=: f&>c [ i=: <a:;a:;i.0 +] b=: f&>c [ i=: <a:;a:;a:;i.0 +] b=: f&>c [ i=: <a:;a:;a:;a:i.0 + +d=: (?23 5$2)*?23 5 7 3 2$4 +f=: 3 : '(100+d) -: (100+d) i}s=:(2;y)$.d' + +f&>c [ i=: <'' +f&>c [ i=: <$0 + + +NB. amend in place ------------------------------------------------------- + +d=: (0=?7 5$3)*?7 5 1000$1000 +s=: (2;0 1)$.d + +i=: <"0 (?#i){i=: 4$.s +9000 > 7!:2 's=: 0 (<i,<1 3 5)}s' +s -: d=: 0 (<i,<1 3 5)}d +scheck s + +i=: <"0 (?#i){i=: 4$.s +(IF64{9000 18000) > t=: 7!:2 's=: 7 8 9 (<i,<1 3 5)}s' +s -: d=: 7 8 9 (<i,<1 3 5)}d +scheck s + +i=: <"0 (?#i){i=:(7 5#:i.35)-.4$.s +s=: 7 8 9 (<i,<1 3 5)}s NB. not in place +s -: d=: 7 8 9 (<i,<1 3 5)}d +scheck s + + +NB. amend in place with sparse replacement data -------------------------- + +d=: (0=?7 5$3)*?7 5 1000$1000 +s=: (2;0 1)$.d + +i=: <"0 (?#i){i=: 4$.s +x=: $. 7 8 9 +(IF64{9000 18000) > t=: 7!:2 's=: x (<i,<1 3 5)}s' +s -: d=: x (<i,<1 3 5)}d +scheck s + +i=: <"0 (?#i){i=:(7 5#:i.35)-.4$.s +s=: x (<i,<1 3 5)}s NB. not in place +s -: d=: x (<i,<1 3 5)}d +scheck s + + +NB. sparse replacement data ---------------------------------------------- + +d=: (?23 5$2) * ?23 5 3 2 4$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 3 : '(a i}d) -: ($.a) i}s=:(2;y)$.d [ a=: g i' +g=: 3 : '($y{d) ?@$ 7' + +] b=: f&>c [ i=: < ?&.> 2 3&$&.>i{.$d [ i=: 1 +] b=: f&>c [ i=: < ?&.> 2 3&$&.>i{.$d [ i=: 2 +] b=: f&>c [ i=: < ?&.> 2 3&$&.>i{.$d [ i=: 3 +] b=: f&>c [ i=: < ?&.> 2 3&$&.>i{.$d [ i=: 4 +] b=: f&>c [ i=: < ?&.> 2 3&$&.>i{.$d [ i=: 5 + +] b=: f&>c [ i=: < ?&.> (>:?i$7)$&.>i{.$d [ i=: 1 +] b=: f&>c [ i=: < ?&.> (>:?i$7)$&.>i{.$d [ i=: 2 +] b=: f&>c [ i=: < ?&.> (>:?i$7)$&.>i{.$d [ i=: 3 +] b=: f&>c [ i=: < ?&.> (>:?i$7)$&.>i{.$d [ i=: 4 +] b=: f&>c [ i=: < ?&.> (>:?i$7)$&.>i{.$d [ i=: 5 + +] b=: f&>c [ i=: < ?&.> (>:?i$25 4)$&.>i{.$d [ i=: 1 +] b=: f&>c [ i=: < ?&.> (>:?i$25 4)$&.>i{.$d [ i=: 2 +] b=: f&>c [ i=: < ?&.> (>:?i$25 4)$&.>i{.$d [ i=: 3 +] b=: f&>c [ i=: < ?&.> (>:?i$25 4)$&.>i{.$d [ i=: 4 +] b=: f&>c [ i=: < ?&.> (>:?i$25 4)$&.>i{.$d [ i=: 5 + +s=: 1$.5 6;'';123 +d=: 5 6$123 +i=: <(?2$5);?3 2$6 +x=: ?($i{d)$1000 +s -: d +(x i}d) -: x i}s + +'domain error' -: (3 4$'x') (<2 0;i.3 )} etx $.i.2 3 4 +'domain error' -: (3 4$<4 ) (<2 0;i.3 )} etx $.i.2 3 4 + +'index error' -: (i.2 3) (< 4 0;0;i.3)} etx $.i.4 2 3 +'index error' -: (i.2 3) (<_5 0;0;i.3)} etx $.i.4 2 3 + +'length error' -: (i.2 3) (<2 0;2 1 0 )} etx $.i.4 3 2 + + +4!:55 ;:'a b c d f g i r s t x' + +
new file mode 100644 --- /dev/null +++ b/test/gsp530n.ijs @@ -0,0 +1,180 @@ +NB. } scattered amendment ------------------------------------------------ + +d=: (?23 5$2)*?23 5 7 3 2$4 + +f=: 3 : '(0 i}d) -: 0 i}s=:(2;y)$.d' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: f&>c [ i=: <"1 ? 12 1$1{.$d +] b=: f&>c [ i=: <"1 ? 2 6 2$2{.$d +] b=: f&>c [ i=: <"1 ?2 2 3 3$3{.$d +] b=: f&>c [ i=: <"1 ? 4 3 4$4{.$d +] b=: f&>c [ i=: <"1 ?1 3 3 5$5{.$d + +d=: (?23 5$2)*?23 5 7 3 2$4 + +f=: 3 : '(999 i}d) -: 999 i}s=:(2;y)$.d' +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +] b=: f&>c [ i=: <"1 ? 12 1$1{.$d +] b=: f&>c [ i=: <"1 ? 2 6 2$2{.$d +] b=: f&>c [ i=: <"1 ?2 2 3 3$3{.$d +] b=: f&>c [ i=: <"1 ? 4 3 4$4{.$d +] b=: f&>c [ i=: <"1 ?1 3 3 5$5{.$d + +d=: (?23 5$2) * ?23 5 3 2 4$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d +g=: 3 : '($y{d) ?@$ 7' + +f=: 3 : '(a i}d) -: a i}s=:(2;y)$.d [ a=: g i' +] b=: f&>c [ i=: <"1 ? 12 1$1{.$d +] b=: f&>c [ i=: <"1 ? 2 6 2$2{.$d +] b=: f&>c [ i=: <"1 ?2 2 3 3$3{.$d +] b=: f&>c [ i=: <"1 ? 4 3 4$4{.$d +] b=: f&>c [ i=: <"1 ?1 3 3 5$5{.$d + +f=: 4 : '(a i}d) -: a i}s=: (2;x)$.d [ a=: g i=: x h y' + +h=: 4 : '<"1 v#:(>:?2*n)?@$n=. */v=. y{.$d' +] b=: |: c f&>/ >:i.#$d + +h=: 4 : '<"1 v#:5 7 4 ?@$n=. */v=. y{.$d' +] b=: |: c f&>/ >:i.#$d + +f=: 3 : '(a i}d) -: a i}s=:(2;y)$.d' +i=: <?#d NB. single index +] b=: f&>c [ a=: ?(}.$d)$5 NB. dense replacement data +] b=: f&>c [ a=: $.?(}.$d)$5 NB. sparse replacement data + + +NB. amend in place ------------------------------------------------------- + +d=: (0=?7 5$3)*?7 5 1000$1000 +s=: (2;0 1)$.d + +i=: <"1 ?15 2$7 5 +(IF64{9000 18000) > t=: 7!:2 's=: 0 i}s' +s -: d=: 0 i}d +scheck s + +i=: <"1 ?75 3$7 5 1000 +(IF64{9000 18000) > t=: 7!:2 's=: 0 i}s' +s -: d=: 0 i}d +scheck s + +i=: <"1 (?4$1000),.~(?4$#i){i=:4$.s +x=: ?(#i)$1e6 +(IF64{9000 18000) > t=: 7!:2 's=: x i}s' +s -: d=: x i}d +scheck s + +i=: <"1 (?4$1000),.~(?4$#i){i=: (7 5#:i.35)-.4$.s +x=: ?(#i)$1e6 +s=: x i}s NB. not in place +s -: d=: x i}d +scheck s + + +NB. amend in place for sparse replacement data --------------------------- + +d=: (0=?7 5$3)*?7 5 1000$1000 +s=: (2;0 1)$.d + +i=: <"1 (?375$#x){x=: 4$.s +a=: $. ($i{d)$3 +(IF64{30000 50000) > t=: 7!:2 's=: a i}s' +s -: d=: a i}d +scheck s + +i=: <"1 (?4$1000),.~(?4$#x){x=:4$.s +a=: $.?(#i)$1e6 +(IF64{30000 50000) > t=: 7!:2 's=: a i}s' +s -: d=: a i}d +scheck s + +i=: <"1 (?4$1000),.~(?4$#i){i=: (7 5#:i.35)-.4$.s +a=: $. ?(#i)$1e6 +s=: a i}s NB. not in place +s -: d=: a i}d +scheck s + + +NB. sparse replacement data ---------------------------------------------- + +d=: (?23 5$2) * ?23 5 3 2 4$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d +g=: 3 : '?($y{d)$7' + +f=: 3 : '(a i}d) -: ($.a) i}s=:(2;y)$.d [ a=: g i' + +] b=: f&>c [ i=: <"1 ? 12 1$1{.$d +] b=: f&>c [ i=: <"1 ? 2 6 2$2{.$d +] b=: f&>c [ i=: <"1 ?2 2 3 3$3{.$d +] b=: f&>c [ i=: <"1 ? 4 3 4$4{.$d +] b=: f&>c [ i=: <"1 ?1 3 3 5$5{.$d + +f=: 4 : '(a i}d) -: ($.a) i}s=: (2;x)$.d [ a=: g i=: x h y' + +h=: 4 : '<"1 v#:(>:?2*n)?@$n=. */v=. y{.$d' +] b=: |: c f&>/ >:i.#$d + +h=: 4 : '<"1 v#:3 4 5?@$n=. */v=. y{.$d' +] b=: |: c f&>/ >:i.#$d + +s=: 1$.5 6;'';123 +d=: 5 6$123 +i=: <"1 ?3 2$5 6 +x=: ?($i{d)$1000 +s -: d +(x i}d) -: x i}s + +case=: 3 : 0 + select. y + case. 0 do. + d=: i.4 3 2 + i=: 3,&.>0 1 2 + case. 1 do. + d=: 4{. i.3 3 4 2 + i=: 3 ,&.>0 1 2 + case. 2 do. + d=: 4{. i. 3 3 4 2 + i=: 3 ,&.>0 1 2 + case. 3 do. + d=: 4{. ?. 3 3 4 2$4 + i=: <"1 ?.5 2 3 4 3$4 3 4 + case. 4 do. + d=: ? 11 7 3 4 2$4 + i=: <"1 ?500 5$$d + end. + s=. $i{d + e=: (?.s$2)*100+?.s$50 + ca=: ; (i.1+r) <"1@comb&.> r=: #$e + cw=: ; (i.1+r) <"1@comb&.> r=: #$d + 1 +) + +g=: 4 : '((2;x)$.e) i} (2;y)$.d' +f=: 4 : '(e i}d) -: x g y' +h=: 4 : '((2;y)$.e i}d) ; x g y' + +case 0 +*./, b=: ca f&>/cw +case 1 +*./, b=: ca f&>/cw +case 2 +*./, b=: ca f&>/cw +case 3 +*./, b=: ca f&>/cw +case 4 +*./, b=: ca f&>/cw + +'domain error' -: 'abc' (0 0;1 1;2 2)} etx $.i.4 5 + +'index error' -: 999 (0 1;2 4) } etx $.i.3 4 + +'length error' -: (i.3 4) (2;3) } etx (2;0 1)$. i.4 5 + + +4!:55 ;:'a b c ca case cw d e f g h i m r s t x y' + +
new file mode 100644 --- /dev/null +++ b/test/gsp531.ijs @@ -0,0 +1,19 @@ +NB. }. ------------------------------------------------------------------- + +(scheck x}.$.y), (x=:_5 _10+?12 24) (}. -: }.&.$.) y=: ? 12 24 3$2 +(scheck x}.$.y), (x=:_5 _10+?12 24) (}. -: }.&.$.) y=: _10+? 12 24 3$21 +(scheck x}.$.y), (x=:_5 _10+?12 24) (}. -: }.&.$.) y=: o._10+? 12 24 3$21 +(scheck x}.$.y), (x=:_5 _10+?12 24) (}. -: }.&.$.) y=: j./o._10+?2 12 24 3$21 + +(scheck x}.$.y), 100 (}. -: }.&.$.) y=: ? 12 24 3$2 +(scheck x}.$.y), 3 _100 (}. -: }.&.$.) y=: _10+? 12 24 3$21 +(scheck x}.$.y), _9 90 3(}. -: }.&.$.) y=: o._10+? 12 24 3$21 +(scheck x}.$.y), 200 (}. -: }.&.$.) y=: j./o._10+?2 12 24 3$21 + +(scheck x}."1]$.y), (x=:12 -~?25 ) (}."1 -: }."1&.$.) y=:_10+?12 24 3$21 +(scheck x}."2]$.y), (x=:12 24 -~?25 49 ) (}."2 -: }."2&.$.) y=:_10+?12 24 3$21 +(scheck x}."3]$.y), (x=:12 24 3-~?25 49 7) (}."3 -: }."3&.$.) y=:_10+?12 24 3$21 + + +4!:55 ;:'x y' +
new file mode 100644 --- /dev/null +++ b/test/gsp5x5.ijs @@ -0,0 +1,50 @@ +NB. 5!:5 sparse arrays -------------------------------------------------- + +test=: 3 : 0 + yy=: y + xx=: ". 5!:5 <'y' + assert. xx -:&type yy + assert. scheck xx + assert. xx -: yy + 1 +) + +test x=: 1$.3 4 5;0 1;0 +test x=: 1$.3 4 5;0 1;-~2 +test x=: 1$.3 4 5;0 1;-~2.1 +test x=: 1$.3 4 5;0 1;-~2j1 + +test x=: $. 3 4 5 ?@$ 5 +test o. x +test x=: $. 10 ?@$ 5 + +r=: #$d=: (2 3 5 ?@$ 2) * 2 3 5 7 9 ?@$ 2 +c=: (i.1+r) comb&.> r +c ([: */ (2&;@[ test@$. ])"1 _)&><d + +r=: #$d=: (2 3 5 ?@$ 4) * 2 3 5 7 9 ?@$ 10 +c=: (i.1+r) comb&.> r +c ([: */ (2&;@[ test@$. ])"1 _)&><d + +r=: #$d=: (2 3 5 ?@$ 4) * 2 3 5 7 9 ?@$ 0 +c=: (i.1+r) comb&.> r +c ([: */ (2&;@[ test@$. ])"1 _)&><d + + +NB. 5!:5 empty sparse arrays -------------------------------------------- + +s=: 0 (?#s)}s=: ?10$5 +test 1$.s +test 1$.s;'' +test 1$.s;i.#s +test 1$.s;5?#s +test 1$.s;(i.#s);0 +test 1$.s;(5?#s);0 +test 1$.s;(5?#s);-~4 +test 1$.s;(5?#s);-~4.1 +test 1$.s;(5?#s);-~4j1 + + +4!:55 ;:'c d r s test x xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp6.ijs @@ -0,0 +1,18 @@ +NB. ": ------------------------------------------------------------------ + +(<;._1 '/domain error/nonce error') e.~< ($.4$0j4) ": etx i.3 4 +(<;._1 '/domain error/nonce error') e.~< ( 4$0j4) ": etx $.i.3 4 + + +NB. ? ------------------------------------------------------------------- + +(<;._1 '/domain error/nonce error') e.~< ? etx $. 10$10 +(<;._1 '/domain error/nonce error') e.~< 5 ? etx $. 10$10 + + +NB. ?. ------------------------------------------------------------------ + +(<;._1 '/domain error/nonce error') e.~< ?. etx $. 10$10 +(<;._1 '/domain error/nonce error') e.~< 5 ?. etx $. 10$10 + +
new file mode 100644 --- /dev/null +++ b/test/gsp600.ijs @@ -0,0 +1,139 @@ +NB. " monad ------------------------------------------------------------- + +d=: (13 5 7?@$2)*13 5 7?@$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +double=: 3 : '+.y' + +f=: 3 : 0 + b=. (double"0 d) -: t=. double"0 s=:(2;y)$.d + if. b *. 0<#$t do. *./ scheck t else. b end. +) + +f&>c + +A=: 1 : 0 + : + b=. (u"x d) -: t=. u"x s=:(2;y)$.d + if. b *. 0<#$t do. *./ scheck t else. b end. +) + +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +ravel=: 3 : ', y' +sum =: 3 : '+/y' +rev =: 3 : '|.y' +mean =: +/ % # + +(i.>:r) ] A&>/ c +(i.>:r) sum A&>/ c +(i.>:r) ravel A&>/ c +(i.>:r) rev A&>/ c +(i.>:r) # A&>/ c +(i.>:r) mean A&>/ c + +d=: 2 3 4$0 +c=: ; (i.1+r) <"1@comb&.>r=:#$d +(i.>:r) mean A&>/c + +($"2 x) -: $"2 $. x=:2 3 3$12 + +(<1 0) 10 11&(4 : 'x o. y') A&>/c + +'non-unique sparse elements' -: $"2 etx $. 2 3 4$12 + + +NB. " dyad -------------------------------------------------------------- + +A2=: 1 : 0 + : + xx=: (2;x)$.x0 + yy=: (2;y)$.y0 + b=. (x0 u"r y0) -: t=: xx u"r yy + if. b *. 0<#$t do.*./ scheck t else. b end. +) + +minus=: 4 : 'x - y' +cat =: 4 : 'x , y' +rot =: 4 : 'x |. y' + +x0=: (13 5?@$2)*13 5 7?@$500 +y0=: (13 5?@$2)*13 5 7?@$500 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 + +minus A2&>/~c [ r=: 0 +minus A2&>/~c [ r=: 1 +minus A2&>/~c [ r=: 2 +minus A2&>/~c [ r=: 3 + +cat A2&>/~c [ r=: 0 +cat A2&>/~c [ r=: 1 +cat A2&>/~c [ r=: 2 +cat A2&>/~c [ r=: 3 + +x0=: (13 5 7?@$2)*13 5 7?@$5 +y0=: 13 5 7 $0 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 + +minus A2&>/~c [ r=: 0 +minus A2&>/~c [ r=: 1 +minus A2&>/~c [ r=: 2 +minus A2&>/~c [ r=: 3 + +cat A2&>/~c [ r=: 0 +cat A2&>/~c [ r=: 1 +cat A2&>/~c [ r=: 2 +cat A2&>/~c [ r=: 3 + +x0=: 13 5 7 $0 +y0=: (13 5 7?@$2)*13 5 7?@$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 + +minus A2&>/~c [ r=: 0 +minus A2&>/~c [ r=: 1 +minus A2&>/~c [ r=: 2 +minus A2&>/~c [ r=: 3 + +cat A2&>/~c [ r=: 0 +cat A2&>/~c [ r=: 1 +cat A2&>/~c [ r=: 2 +cat A2&>/~c [ r=: 3 + +x0=: 13 5 7$0 +y0=: 13 5 7$0 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 + +minus A2&>/~c [ r=: 0 +minus A2&>/~c [ r=: 1 +minus A2&>/~c [ r=: 2 +minus A2&>/~c [ r=: 3 + +cat A2&>/~c [ r=: 0 +cat A2&>/~c [ r=: 1 +cat A2&>/~c [ r=: 2 +cat A2&>/~c [ r=: 3 + +x0=: (13 5 ?@$2)*13 5 ?@$5 +y0=: (13 5 7?@$2)*13 5 7?@$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 +d=: ; (i.1+r) <"1@comb&.>r=:#$y0 +c rot A2&>/ d [ r=: 0 1 + +x0=: (13 ?@$2)*13 2 ?@$5 +y0=: (13 7?@$2)*13 7 17?@$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$x0 +d=: ; (i.1+r) <"1@comb&.>r=:#$y0 +c rot A2&>/ d [ r=: 1 2 + +f=: 3 : 0 + (10 11 o."1 0 xx) -: 10 11 o."1 0 s=: (2;y)$.xx +) + +xx=: (13 7?@$2)*13 7 4 2?@$5 +c=: ; (i.1+r) <"1@comb&.>r=:#$xx +f&>c + + +4!:55 ;:'A A2 c cat d double f mean minus q r ravel rev rot s sum t x x0 xx y y0 yy' + +
new file mode 100644 --- /dev/null +++ b/test/gsp600a.ijs @@ -0,0 +1,99 @@ +NB. " agreement --------------------------------------------------------- + +f=: 4 : 0 + s=: (2;x)$.xx + t=: (2;y)$.yy + b=. (xx cat"1 yy) -: q=: s cat"1 t + if. b *. 0<#$q do. *./ scheck q else. b end. +) + +cat =: 4 : 'x , y' + +c=: ; (i.1+r) <"1@comb&.>r=:3 +d=: ; (i.1+r) <"1@comb&.>r=:2 + +xx=: (?7 2$2)*?7 2 2$1000 +yy=: (?7 2$2)*?7 2 $1000 +c f&>/d + +xx=: (0=?17 4$5)*?17 4 2$1000 +yy=: (0=?17 4$5)*?17 4 $1000 +c f&>/d + +xx=: (0=?17 4$5)*?17 4 2$1000 +yy=: 17 4 $0 +c f&>/d + +xx=: 17 4 2$0 +yy=: (0=?17 4$5)*?17 4 $1000 +c f&>/d + +xx=: 17 4 2$0 +yy=: 17 4 $0 +c f&>/d + +c=: ; (i.1+r) <"1@comb&.>r=:2 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (?7 2$2)*?7 2 $1000 +yy=: (?7 2$2)*?7 2 2$1000 +c f&>/d + +xx=: (0=?17 4$5)*?17 4 $1000 +yy=: (0=?17 4$5)*?17 4 2$1000 +c f&>/d + +xx=: (0=?17 4$5)*?17 4 $1000 +yy=: 17 4 2$0 +c f&>/d + +xx=: 17 4 $0 +yy=: (0=?17 4$5)*?17 4 2$1000 +c f&>/d + +xx=: 17 4 $0 +yy=: 17 4 2$0 +c f&>/d + +c=: ; (i.1+r) <"1@comb&.>r=:4 +d=: ; (i.1+r) <"1@comb&.>r=:3 + +xx=: (0=?11 3 2$6)*?11 3 2 4$1000 +yy=: (0=?11 3 $6)*?11 3 5$1000 +c f&>/d + +xx=: (0=?11 3 2$6)*?11 3 2 4$1000 +yy=: ( 11 3 $0)*?11 3 5$1000 +c f&>/d + +xx=: ( 11 3 2$0)*?11 3 2 4$1000 +yy=: (0=?11 3 $6)*?11 3 5$1000 +c f&>/d + +xx=: ( 11 3 2$0)*?11 3 2 4$1000 +yy=: ( 11 3 $0)*?11 3 5$1000 +c f&>/d + +c=: ; (i.1+r) <"1@comb&.>r=:3 +d=: ; (i.1+r) <"1@comb&.>r=:4 + +xx=: (0=?11 3 $6)*?11 3 5$1000 +yy=: (0=?11 3 2$6)*?11 3 2 4$1000 +c f&>/d + +xx=: ( 11 3 $0)*?11 3 5$1000 +yy=: (0=?11 3 2$6)*?11 3 2 4$1000 +c f&>/d + +xx=: (0=?11 3 $6)*?11 3 5$1000 +yy=: ( 11 3 2$0)*?11 3 2 4$1000 +c f&>/d + +xx=: ( 11 3 $0)*?11 3 5$1000 +yy=: ( 11 3 2$0)*?11 3 2 4$1000 +c f&>/d + + +4!:55 ;:'c cat d f q r s t xx yy' + +
new file mode 100644 --- /dev/null +++ b/test/gspi.ijs @@ -0,0 +1,304 @@ +NB. (dense vector) i. sparse , also i: ---------------------------------- + +df=: $.^:_1 + +f=: 4 : 0 + qs=: (3;x)$.(2;y)$.q + assert. (scheck t) *. (p i. df qs) -: t=. p i. qs + assert. (scheck t) *. (p i: df qs) -: t=. p i: qs + 1 +) + +q=: (?7 5$2) * ?7 5 8$50 +c=: ; (i.1+r) <"1@comb&.>r=:#$q + +0 99 f&>/ c [ p=: ?47$50 +0 99 f&>/ c [ p=: ?47$2 +0 99 f&>/ c [ p=: ]&.o.?47$50 +0 99 f&>/ c [ p=: ]&.j.?47$50 +0 99 f&>/ c [ p=: 'kakistocratic meconium' + +p=: 1+?47$50 +0 99 f&>/ c [ q=: (?7 5 3$2) * ?7 5 3 8$2 +0 99 f&>/ c [ q=: (?7 5 3$2) * ?7 5 3 8$50 +0 99 f&>/ c [ q=: ]&.o. (?7 5 3$2) * ?7 5 3 8$50 +0 99 f&>/ c [ q=: ]&.j. (?7 5 3$2) * ?7 5 3 8$50 + +p=: (?47$2) * ?47$50 +0 99 f&>/ c [ q=: (?7 5 3$2) * ?7 5 3 8$2 +0 99 f&>/ c [ q=: (?7 5 3$2) * ?7 5 3 8$50 +0 99 f&>/ c [ q=: ]&.o. (?7 5 3$2) * ?7 5 3 8$50 +0 99 f&>/ c [ q=: ]&.j. (?7 5 3$2) * ?7 5 3 8$50 + + +NB. (sparse vector) i. sparse , also i: --------------------------------- + +f=: 4 : 0 + qs=: (3;x)$.(2;y)$.q + assert. (scheck t) *. (ps i.&df qs) -: t=. ps i. qs + assert. (scheck t) *. (ps i:&df qs) -: t=. ps i: qs + 1 +) + +q=: (?7 5$2) * ?7 5 8$50 +c=: ; (i.1+r) <"1@comb&.>r=:#$q + +0 99 f&>/ c [ ps=: $. ?47$50 +0 99 f&>/ c [ ps=: $. ?47$2 +0 99 f&>/ c [ ps=: $. ]&.o.?47$50 +0 99 f&>/ c [ ps=: $. ]&.j.?47$50 + +f=: 4 : 0 + ps=: (3;pe)$.(2;x)$.p + qs=: (3;qe)$.(2;y)$.q + assert. (scheck t) *. (ps i.&df qs) -: t=. ps i. qs + assert. (scheck t) *. (ps i:&df qs) -: t=. ps i: qs + 1 +) + +p=: (?47$2) * ?47$50 +('';0) f&>/ c [ pe=: 0 [ qe=: 0 +('';0) f&>/ c [ pe=: 0 [ qe=: 99 +('';0) f&>/ c [ pe=: 99 [ qe=: 0 +('';0) f&>/ c [ pe=: 99 [ qe=: 99 + +p=: 1+?47$50 +('';0) f&>/ c [ pe=: 0 [ qe=: 0 +('';0) f&>/ c [ pe=: 0 [ qe=: 99 +('';0) f&>/ c [ pe=: 99 [ qe=: 0 +('';0) f&>/ c [ pe=: 99 [ qe=: 99 + +p=: (1+?47$50),0 0 0 +('';0) f&>/ c [ pe=: 0 [ qe=: 0 +('';0) f&>/ c [ pe=: 0 [ qe=: 99 +('';0) f&>/ c [ pe=: 99 [ qe=: 0 +('';0) f&>/ c [ pe=: 99 [ qe=: 99 + +p=: 0 0 0,(1+?47$50) +('';0) f&>/ c [ pe=: 0 [ qe=: 0 +('';0) f&>/ c [ pe=: 0 [ qe=: 99 +('';0) f&>/ c [ pe=: 99 [ qe=: 0 +('';0) f&>/ c [ pe=: 99 [ qe=: 99 + +ps=: 0 (?5$10)}$. ?10$4 +(i.~ps) -: i.~ df ps +(i:~ps) -: i:~ df ps + +f=: 4 : 0 + ps=: $. x + qs=: $. y + assert. (ps i. qs) -: x i. y + assert. (ps i: qs) -: x i: y + 1 +) +0 f ?4 5$2 +1 f ?4 5$10 +(,0) f ?20$2 +(,0) f ?20$10 +(,1) f ?20$2 +(,1) f ?20$10 + + +NB. (sparse vector) i. dense , also i: ---------------------------------- + +f=: 4 : 0 + ps=: (3;x)$.(2;y)$.p + assert. ((df ps) i. q) -: ps i. q + assert. ((df ps) i: q) -: ps i: q + 1 +) + +q=: (?7 5$2) * ?7 5 8$50 + +p=: (?47$2) * ?47$50 +0 f 0 +0 f '' +99 f 0 +99 f '' + +p=: 1+?47$50 +0 f 0 +0 f '' +99 f 0 +99 f '' + +((df ps) i. 0) -: ps i. 0 [ ps=: $. (1+?47$50), 0 0 0 +((df ps) i. 0) -: ps i. 0 [ ps=: $. (1+?47$50),~0 0 0 +((df ps) i. 0) -: ps i. 0 [ ps=: 0 (17)}$. 1+?47$50 + +((df ps) i: 0) -: ps i: 0 [ ps=: $. (1+?47$50), 0 0 0 +((df ps) i: 0) -: ps i: 0 [ ps=: $. (1+?47$50),~0 0 0 +((df ps) i: 0) -: ps i: 0 [ ps=: 0 (17)}$. 1+?47$50 + +p=: (?47$2) * ?47$50 + +0 f 0 [ q=: 0 +0 f '' +99 f 0 +99 f '' +0 f 0 [ q=: (?#p){p +0 f '' +99 f 0 +99 f '' +0 f 0 [ q=: 99 +0 f '' +99 f 0 +99 f '' +0 f 0 [ q=: 123456 +0 f '' +99 f 0 +99 f '' + +0 f 0 [ q=: s: ' foo upon thee' +0 f '' +99 f 0 +99 f '' +0 f 0 [ q=: ' foo upon thee' +0 f '' +99 f 0 +99 f '' +0 f 0 [ q=: ;:'Cogito, ergo sum.' +0 f '' +99 f 0 +99 f '' + +d=: df s=: 0(2)}$. i.5 +(s i. 0) -: d i. 0 +(s i: 0) -: d i: 0 + + +NB. i. and i: on general dense or sparse arguments ---------------------- + +f=: 4 : 0 + (x=3$.t) *. (i:~ y) -: t=. i:~ $. y +) + +d=: i.8 2 +8 f d +7 f 8{.5{.d +2 f _8{.5{.d +7 f 0*d +0 f i.0 2 + +2 = 3 $. i:~ $.0 (2)}i.8 2 +6 = 3 $. i:~ 0 (6)}$.0 (0)}i.8 2 + +f0=: 4 : 0 + ps=: (2;x)$.p + qs=: (2;y)$.q + assert. (p i. q) -: i=. ps i. qs + assert. (p i: q) -: j=. ps i: qs + if. #$i do. assert. (scheck i) *. (scheck j) end. + assert. (scheck i) *. (p i. p) -: i=. ps i. ps + assert. (scheck i) *. (p i: p) -: i=. ps i: ps + 1 +) + +f1=: 4 : 0 + ps=: (2;x)$.p + assert. (p i. q) -: i=. ps i. q + assert. (p i: q) -: j=. ps i: q + if. #$i do. assert. (scheck i) *. (scheck j) end. + 1 +) + +f2=: 4 : 0 + qs=: (2;x)$.q + assert. (p i. q) -: i=. p i. qs + assert. (p i: q) -: j=. p i: qs + if. #$i do. assert. (scheck i) *. (scheck j) end. + 1 +) + +f3=: 4 : 0 + ps=: (2;x)$.p + qs=: (2;y)$.q + assert. (p i.!.0 q) -: i=. ps i.!.0 qs + assert. (p i:!.0 q) -: j=. ps i:!.0 qs + if. #$i do. assert. (scheck i) *. (scheck j) end. + assert. (scheck i) *. (p i.!.0 p) -: i=. ps i.!.0 ps + assert. (scheck i) *. (p i:!.0 p) -: i=. ps i:!.0 ps + 1 +) + + +p=: (?100 2$2) * ?100 2 3$10 +q=: (?200$150){p,(?50 2$2) * ?50 2 3$10 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +d=: ; (i.1+s) <"1@comb&.>s=:#$q + +c f0&>/d +c f1&>/0 +0 f2&>/d +c f3&>/d + +c f0&>/d [ p=: p*1.5-0.5 [ q=: q*1.5-0.5 +c f1&>/0 +0 f2&>/d +c f3&>/d + +c f0&>/d [ p=: p*1j5-0j5 [ q=: q*1j5-0j5 +c f1&>/0 +0 f2&>/d +c f3&>/d + +p=: (?100 2$2) * ?100 2 3$10 +q=: (?150){p,(?50 2$2) * ?50 2 3$10 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +d=: ; (i.1+s) <"1@comb&.>s=:#$q + +c f0&>/d +c f1&>/0 +0 f2&>/d +c f3&>/d + +c f0&>/d [ p=: p*1.5-0.5 [ q=: q*1.5-0.5 +c f1&>/0 +0 f2&>/d +c f3&>/d + +c f0&>/d [ p=: p*1j5-0j5 [ q=: q*1j5-0j5 +c f1&>/0 +0 f2&>/d +c f3&>/d + +d=: (i.6 2),.99 +s=: 8 $. (3;99) $. $. d +s=: 11 (<2 2)}s +s=: 99 (<2 2)}s +d=: $.^:_1 s + +(d i. d) -: s i. (3;99)$. $. d +(d i: d) -: s i: (3;99)$. $. d + +s=: 0 (?5$10)}$.?10 3$4 +(i.~s) -: i.~ df s +(i:~s) -: i:~ df s + +s=: 0 (0 1 2)} $. 5 2?@$20 +(df i.~s) -: i.~ df s +(df i:~s) -: i:~ df s + +t=: 0 (2 3 4)} $. 5 2 ?@$ 20 +(df i.~t) -: i.~ df t +(df i:~t) -: i:~ df t + +d=: (?1009$2) * ?1009 2 3$10 +c=: ; (i.1+r) <"1@comb&.>r=:#$d + +f=: 3 : 'assert. (i.~ $.^:_1 s) -: i.~ s=: (b=: ?((#d),2)$2) * (2;y)$.d' +f&> c + +f=: 3 : 'assert. (i.~ $.^:_1 s) -: i.~ s=: (b=: 0=?((#d),2)$5) * (2;y)$.d' +f&> c + +f=: 3 : 'assert. (i:~ $.^:_1 s) -: i:~ s=: (b=: ?((#d),2)$2) * (2;y)$.d' +f&> c + +f=: 3 : 'assert. (i:~ $.^:_1 s) -: i:~ s=: (b=: 0=?((#d),2)$5) * (2;y)$.d' +f&> c + + +4!:55 ;:'b c d df f f0 f1 f2 f3 f4 p pe ps q qe qs r s x' + +
new file mode 100644 --- /dev/null +++ b/test/gspj.ijs @@ -0,0 +1,16 @@ +NB. j. ------------------------------------------------------------------ + +(scheck j. $.x), (j. -: j.&.$.) x=: _10+? 405$2 +(scheck j. $.x), (j. -: j.&.$.) x=: _10+? 3 4 5$21 +(scheck j. $.x), (j. -: j.&.$.) x=: o._10+? 3 4 5$21 +(scheck j. $.x), (j. -: j.&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. j. $. 0 1 0 +0 -: 3 $. j. $. 2 3 4 +0 -: 3 $. j. $. 2 3.4 +0 -: 3 $. j. $. 2 3j4 + + +4!:55 ;:'x' + +
new file mode 100644 --- /dev/null +++ b/test/gspo.ijs @@ -0,0 +1,38 @@ +NB. o. ------------------------------------------------------------------ + +(scheck o. $.x), (o. -: o.&.$.) x=: _10+? 405$2 +(scheck o. $.x), (o. -: o.&.$.) x=: _10+? 3 4 5$21 +(scheck o. $.x), (o. -: o.&.$.) x=: o._10+? 3 4 5$21 +(scheck o. $.x), (o. -: o.&.$.) x=:j./o._10+?2 3 4 5$21 + +0 -: 3 $. o. $. 0 1 0 +0 -: 3 $. o. $. 2 3 4 +0 -: 3 $. o. $. 2 3.4 +0 -: 3 $. o. $. 2 3j4 + +f=: 4 : '(p o. q) -: ((2;x)$.p) o. (2;y)$.q' + +p=: ?7 5 3$2 +q=: ?7 5 3$2 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?7 5 3$8 +q=: ?7 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ?7 5 3$8 +q=: o.?7 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + +p=: ? 7 5 3$8 +q=: j./?2 7 5 3$4 +c=: ; (i.1+r) <"1@comb&.>r=:#$p +f&>/~c + + +4!:55 ;:'c f p q r x' + +
new file mode 100644 --- /dev/null +++ b/test/gspr.ijs @@ -0,0 +1,16 @@ +NB. r. ------------------------------------------------------------------ + +(scheck r. $.x), (r. -: r.&.$.) x=: _10+? 405$2 +(scheck r. $.x), (r. -: r.&.$.) x=: _10+? 3 4 5$21 +(scheck r. $.x), (r. -: r.&.$.) x=: o._10+? 3 4 5$21 +(scheck r. $.x), (r. -: r.&.$.) x=:j./o._10+?2 3 4 5$21 + +1 -: 3 $. r. $. 0 1 0 +1 -: 3 $. r. $. 2 3 4 +1 -: 3 $. r. $. 2 3.4 +1 -: 3 $. r. $. 2 3j4 + + +4!:55 ;:'x' + +
new file mode 100644 --- /dev/null +++ b/test/gspx.ijs @@ -0,0 +1,90 @@ +NB. 3!: ----------------------------------------------------------------- + +1024 -: 3!:0 $. ?10 $2 +4096 -: 3!:0 $. ?10 3 $20 +8192 -: 3!:0 $.o.?10 3 4$20 +16384 -: 3!:0 $.j.?10 2 $20 + +x=: 1$.1e8 2e8 3e8;0 1;o.0 +x -: 3!:2 (3!:1) x +x -: 3!:2 (3!:3) x + +c=: ; (i.1+r) <"1@comb&.>r=:4 + +f=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) (3!:1) s=:(2;y)$.d' +g=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) (3!:3) s=:(2;y)$.d' + +f&>c [ d=: (?5 7 $2) * ?(r$5 7 3 2)$4 +g&>c +f&>c [ d=: o. d +g&>c +f&>c [ d=: (?(_2}.$d)$2) * j./?(2,$d)$4 +g&>c +f&>c [ d=: (?(_2}.$d)$2) * ?($d)$2 +g&>c + +f=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 0&(3!:1) s=:(2;y)$.d' +g=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 0&(3!:3) s=:(2;y)$.d' + +f&>c [ d=: (?(_2}.$d)$2) * ?(r$5 7 3 2)$4 +g&>c +f&>c [ d=: o. d +g&>c +f&>c [ d=: (?(_2}.$d)$2) * j./?(2,$d)$4 +g&>c +f&>c [ d=: (?(_2}.$d)$2) * ?($d)$2 +g&>c + +f=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 1&(3!:1) s=:(2;y)$.d' +g=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 1&(3!:3) s=:(2;y)$.d' + +f&>c [ d=: (?(_2}.$d)$2) * ?(r$5 7 3 2)$4 +g&>c +f&>c [ d=: o. d +g&>c +f&>c [ d=: (?(_2}.$d)$2) * j./?(2,$d)$4 +g&>c +f&>c [ d=: (?(_2}.$d)$2) * ?($d)$2 +g&>c + +f=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 10&(3!:1) s=:(2;y)$.d' +g=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 10&(3!:3) s=:(2;y)$.d' + +f&>c [ d=: (?(_2}.$d)$2) * ?(r$5 7 3 2)$4 +g&>c +f&>c [ d=: o. d +g&>c +f&>c [ d=: (?(_2}.$d)$2) * j./?(2,$d)$4 +g&>c +f&>c [ d=: (?(_2}.$d)$2) * ?($d)$2 +g&>c + +f=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 11&(3!:1) s=:(2;y)$.d' +g=: 3 : '(*./ scheck t) *. d -: t=: (3!:2) 11&(3!:3) s=:(2;y)$.d' + +f&>c [ d=: (?(_2}.$d)$2) * ?(r$5 7 3 2)$4 +g&>c +f&>c [ d=: o. d +g&>c +f&>c [ d=: (?(_2}.$d)$2) * j./?(2,$d)$4 +g&>c +f&>c [ d=: (?(_2}.$d)$2) * ?($d)$2 +g&>c + + +NB. 128!: --------------------------------------------------------------- + +'nonce error' -: 128!:0 etx $. ?10 3$2 +'nonce error' -: 128!:0 etx $. ?10 3$20 +'nonce error' -: 128!:0 etx $.o.?10 3$20 +'nonce error' -: 128!:0 etx $.j.?10 3$20 + +('nonce error';'non-unique sparse elements') e.~< 128!:1 etx $. ?10 10$2 +('nonce error';'non-unique sparse elements') e.~< 128!:1 etx $. ?10 10$20 +('nonce error';'non-unique sparse elements') e.~< 128!:1 etx $.o.?10 10$20 +('nonce error';'non-unique sparse elements') e.~< 128!:1 etx $.j.?10 10$20 + + +4!:55 ;:'c d f g r s t x' + +
new file mode 100644 --- /dev/null +++ b/test/gstack.ijs @@ -0,0 +1,81 @@ +NB. stack issues (function call limit) ---------------------------------- + +0 0 $ 0 : 0 +The recursion limit is constrained by the stack size available to +the J executable file. Crashes due to stack errors can be overcome +by increasing the stack size. Under Windows, the stack size can be +queried and set as follows: + + dumpbin /headers c:\j601\j.exe + editbin /stack:6000000 c:\j601\j.exe + +The stack size is called "size of stack reserve" in the dumpbin output. +The stack space can also be interrogated in J as follows: + + ss=: 256 #. a. i. +&3 2 1 0@[ { 1!:1@] + 368 ss <'c:\j601\j.exe' +5000000 + 360 ss <'c:\j504\j.exe' +5000000 + +The right argument to ss is the name of the J executable file; the left +argument is the location in the file of the 4-byte word that specifies +the stack size. (The location varies with the file, and the word is in +reverse byte order for Windows.) +) + +NB. f=: 3 : 'f c=:>:y' +'stack error' -: (f=: 3 : 'f y' ) etx 0 +'stack error' -: (f=: 3 : '0!:0 ''f 0''') etx 0 +'stack error' -: (f=: 3 : '".''f y''' ) etx 0 +'stack error' -: (f=: 3 : '6!:2 ''f y''') etx 0 +'stack error' -: (f=: 3 : '7!:2 ''f y''') etx 0 + +'stack error' -: (f=: f + >:) etx 0 +'stack error' -: (f=: >: + f ) etx 0 + +f5=: 0: :. (f5^:_1) +'stack error' -: f5^:_1 etx 0 +'stack error' -: 0 f5^:_1 etx 0 + +f6=: + :: f6 +'stack error' -: ex '2 3 f6 4 5 6' + +NB. ". t=: '".t [ c=:>:c' [ c=: 0 +'stack error' -: ex '".t' [ t=: '".t' +'stack error' -: ex '6!:2 t' [ t=: '6!:2 t' +'stack error' -: ex '7!:2 t' [ t=: '7!:2 t' +'stack error' -: ex '0!:0 t' [ t=: '0!:0 t' + +(+/i.1+c) -: (0:`(+ $:@<:)@.*) c=: 1700 +'stack error' -: 0:`([: $: %)@.* etx 5 + +1000 < c=: $:@>: :: <: 0 +'stack error' -: ex '$:@>: 0' +'stack error' -: ex '$:@,@>: 0' +'stack error' -: ex '$:@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@,@,@,@,@>: 0' +'stack error' -: ex '$:@,@,@,@,@,@,@,@,@,@,@>: 0' + +'stack error' -: ex '($: + >:) 0' +'stack error' -: ex '(>: + $:) 0' + +'stack error' -: ex 'ff^:] gg&0~`hh' +'stack error' -: ex '* ^:] +&0~`- ' +'stack error' -: ex '* ^:] +^:]`- ' +'stack error' -: ex 't} t=: +^:]`-' +'stack error' -: ex 't`:0 t=: +^:]`-' + +'stack error' -: ex '128!:2~ ''128!:2~''' +'stack error' -: ex 't 128!:2 ;~t' [ t=: '0&{:: ([ 128!:2 ;) 1&{::' + + +4!:55 ;:'c f f5 f6 g t' + +
new file mode 100644 --- /dev/null +++ b/test/gt.ijs @@ -0,0 +1,239 @@ +NB. t. ------------------------------------------------------------------ + +(%!i.5) = ^ t. i.5 +1 1 0 0 0 = >: t. i.5 +_1 1 0 0 0 = <: t. i.5 +0 _1 0 0 0 = - t. i.5 +1 _1 0 0 0 = -. t. i.5 +0 2 0 0 0 = +: t. i.5 +0 0.5 0 0 0 = -: t. i.5 +0 0 1 0 0 = *: t. i.5 +0 0j1 0 0 0 = j. t. i.5 +0 1p1 0 0 0 = o. t. i.5 +_9 0 0 0 0 = _9: t. i.5 +_8 0 0 0 0 = _8: t. i.5 +_7 0 0 0 0 = _7: t. i.5 +_6 0 0 0 0 = _6: t. i.5 +_5 0 0 0 0 = _5: t. i.5 +_4 0 0 0 0 = _4: t. i.5 +_3 0 0 0 0 = _3: t. i.5 +_2 0 0 0 0 = _2: t. i.5 +_1 0 0 0 0 = _1: t. i.5 +0 0 0 0 0 = 0: t. i.5 +1 0 0 0 0 = 1: t. i.5 +2 0 0 0 0 = 2: t. i.5 +3 0 0 0 0 = 3: t. i.5 +4 0 0 0 0 = 4: t. i.5 +5 0 0 0 0 = 5: t. i.5 +6 0 0 0 0 = 6: t. i.5 +7 0 0 0 0 = 7: t. i.5 +8 0 0 0 0 = 8: t. i.5 +9 0 0 0 0 = 9: t. i.5 + +17.5 0 0 0 0 = 17.5"0 t. i.5 + +3 1 0 0 0 = 3&+ t. i.5 +_7.1 1 0 0 0 = +&_7.1 t. i.5 +9 1 0 0 0 = -&_9 t. i.5 +9 1 0 0 0 = -&_9 t. i.5 +0 _1.3 0 0 0 = _1.3&* t. i.5 +0 3.21 0 0 0 = *&3.21 t. i.5 +0 4 0 0 0 = %&0.25 t. i.5 +3 0j1 0 0 0 = 3&j. t. i.5 +0j4 1 0 0 0 = j.&4 t. i.5 +1 0 0 0 0 = ^&0 t. i.5 +0 1 0 0 0 = ^&1 t. i.5 +0 0 1 0 0 = ^&2 t. i.5 +0 0 0 1 0 = ^&3 t. i.5 +0 0 0 0 1 = ^&4 t. i.5 +(y,0) = y&p. t. i.5 [ y=:_50+?4$100 +(p. r) = r&p. t. i.5 [ r=:(>:?10);_5+?4$20 + +f=: ^&3 + (_3:**:) + (3:*]) + _1: +_1 3 _3 1 0 = f t. i.5 +f=: ^&3 + (_3 **:) + (3 *]) + _1: +_1 3 _3 1 0 = f t. i.5 + +f =: ! %~ p.@<@i. +g =: 3 : 'y&! t. i.1+y' +(f -: g)"0 x: i.3 5 + +f =: i.@>: ! ] +g =: 3 : '(<y$_1)&p. t. i.@>:y' +(f -: g)"0 i.3 5 + +(3.2&^ = (3.2&^ t.i.20)&p.) x=:(2^_10)*?2 10$1000 + +s=: (2^_10)*_1000+?2000 +c=: (2^ _4)*_10+?5$20 +f=: c&(p.!.s) +x=: j./(2^_7)*_50+?2 2 10$100 +1e_8 > (f x) %&|~ (f - f T. (#c)) x + +'domain error' -: ex '1.2&! t.' +'domain error' -: ex 'p.&1 t.' + +'rank error' -: ex '(1 2 3"_ * *:) t.' +'rank error' -: ex '(1 2 3 * *:) t.' + +'length error' -: ex '1 2 3 t.' +'length error' -: ex '+`-`* t.' + + +NB. f@g t. ------------------------------------------------------------- + +p=: (8 %~ _10+?4$20)&p. +q=: (8 %~ _10+?3$20)&p. +sin =: 1&o. + +(p@q =!.1e_11 p@q T. 20) x=: (2^ _8)*_200+?30$400 +(q@p =!.1e_11 q@p T. 20) x + +(p@sin =!.1e_11 p@sin T. 40) x=: (2^_10)*_600+?30$1200 +(q@sin =!.1e_11 q@sin T. 40) x +(p@:^ =!.1e_11 p@:^ T. 40) x +(q@:^ =!.1e_11 q@:^ T. 40) x + + +NB. %@f t. ------------------------------------------------------------- + +pp =: [: +//. */ +1e_11 > 1 -&(m&{.) p pp q=:%@(p&p.) t. i.m [ p=:>:?n$10 [ m=: +:n=: 5 +1e_11 > 1 -&(m&{.) p pp q=:%@(p&p.) t. i.m [ p=:1,}._9+?n$19 [ m=: +:n=: >:?10 + +1 1 2 3 5 8 13 21 34 55 89 = %@(1 _1 _1&p.) t. i.11x + +0 1 1 2 3 5 8 13 21 34 55 89 = (0 1&p. % 1 _1 _1&p.) t. i.12x +0 1 1 2 3 5 8 13 21 34 55 89 = (%-.-*:) t. i.12x + +1 3 3 1 0 0 0 0 0 0 -: (1 5 10 10 5 1&p. % 1 2 1&p.) t. i.10 + +((n$1 _1)*^ t. i.n) = %@^ t. i.n=: 8 + +rp =: 1 : '%@(x&p.) t.' + +(1 ^i.n) = 1 _1 rp i.n=:20 +(2 ^i.n) = 1 _2 rp i.n +(_2 ^i.n) = 1 2 rp i.n +(2.71^i.n) = 1 _2.71 rp i.n +(0j1 ^i.n) = 1 0j_1 rp i.n +(c ^i.n) = (1,-c) rp i.n=:?20 [ c=:(_1^?2)*1+(2^_8)*?1e3 + +(n$1 ) = 1 _1 rp i.n=:20 +(n$1 0 ) = 1 0 _1 rp i.n +(0=k|i.n) = (1,(-k){._1) rp i.n=:?40 [ k=:?20 + +(n{.1 ) = 1 rp i.n=:20 +(n$1 ) = 1 _1 rp i.n +(>:i.n) = 1 _2 1 rp i.n +(+/\^:0 n{.1) = %@((1 _1&pp^:0 [ 1)&p.) t.i.n +(+/\^:1 n{.1) = %@((1 _1&pp^:1 [ 1)&p.) t.i.n +(+/\^:2 n{.1) = %@((1 _1&pp^:2 [ 1)&p.) t.i.n +(+/\^:k n{.1) = %@((1 _1&pp^:k [ 1)&p.) t.i.n=:?40 [ k=:?12 + +tangent=: 3 : 0 NB. tangent numbers from 0 to y Tn+1(x)=(1+x^2)Tn'(x) + f=. [: +//. 1 0 1"_ */ [: }. [ * i.@# + {."1 f^:(i.>:y) 0 1x +) + +B=: 3 : 0 NB. Bernoulli numbers from 0 to y + t=. 1,}.}:tangent y + (* $&_1 _1 1 1@#) _1,t*n*%(* <:)2x^n=. >:i.#t +) + +(B@<:@# -: ! * (% <:@^) t.) i.13x +(B@<:@# -: (% <:@^) t:) i.13x + + +NB. %:@f t. ------------------------------------------------------------ + +taysqrt=: 4 : 0 + n=. x + a=. (1+n){.y + c=. n{.%:{.a + d=. %2*{.c + i=. 0 + while. n>i=.>:i do. c=. c i}~ d * (i{a) - (+/ .* |.) }.i{.c end. + c +) + +pp=: [: +//. */ + +NB. *** c=: _5+?7$20 +NB. *** d=: %:@(c&p.) t. i.20 +NB. *** d -: 20 taysqrt c +NB. *** c -: (#c){. +//.@(*/)~ d +NB. *** 1e_12 > | (#c)}. 20{.+//.@(*/)~ d + + +NB. f^:n t. ------------------------------------------------------------ + +(>:^: 3 t. -: >:@>:@>: t.) i.2 10 +(>:^:_3 t. -: <:@<:@<: t.) i.2 10 + +f=: (1+?3$5)&p. +(f^:4 t. -: f@f@f@f t.) i.4 10 + + +NB. t. circle functions ----------------------------------------------- + +sin =: 1&o. +cos =: 2&o. +sinh =: 5&o. +cosh =: 6&o. +asin =: _1&o. +atan =: _3&o. +asinh =: _5&o. +atanh =: _7&o. + +0 1 0 _1 0 1 0 _1 0 1 -: sin t: i.10 +0 1 0 _1 0 1 0 _1 0 1 -: ^ .: - &.j. t: i.10 +0 1 0 _1 0 1 0 _1 0 1 -: (0j2"0 %~ ^@j. - ^@-@j.) t: i.10 +0 1 0 _1 0 1 0 _1 0 1 -: (* '' H. 3r2@(_1r4&*)@*:)t: i.10 + +1 0 _1 0 1 0 _1 0 1 0 -: cos t: i.10 +1 0 _1 0 1 0 _1 0 1 0 -: ^@j. .. - t: i.10 +1 0 _1 0 1 0 _1 0 1 0 -: ( 2: %~ ^@j. + ^@-@j.) t: i.10 +1 0 _1 0 1 0 _1 0 1 0 -: '' H. 1r2@(_1r4&*)@*: t: i.10 + +0 1 0 1 0 1 0 1 0 1 -: sinh t: i.10 +0 1 0 1 0 1 0 1 0 1 -: ^ .: - t: i.10 +0 1 0 1 0 1 0 1 0 1 -: (2: %~ ^ - ^@-) t: i.10 +0 1 0 1 0 1 0 1 0 1 -: (* '' H. 3r2@(1r4&*)@*:) t: i.10 + +1 0 1 0 1 0 1 0 1 0 -: cosh t: i.10 +1 0 1 0 1 0 1 0 1 0 -: ^ .. - t: i.10 +1 0 1 0 1 0 1 0 1 0 -: (2: %~ ^ + ^@-) t: i.10 +1 0 1 0 1 0 1 0 1 0 -: '' H. 1r2@(1r4&*)@*: t: i.10 + +1e_16 > | (20{.1) - (*:@cos + *:@sin ) t. i.20 +1e_16 > | (20{.1) - (*:@cosh - *:@sinh) t. i.20 +1e_16 > | (20{.1) - ((cos ^2:) + (sin ^2:)) t. i.20 +1e_16 > | (20{.1) - ((cosh^2:) - (sinh^2:)) t. i.20 + +(sin = sin T. 20) x=: (2^_6)*_50+?2 10$100 +(cos = cos T. 20) x=: (2^_6)*_50+?2 10$100 +(sinh = sinh T. 20) x=: (2^_6)*_50+?2 10$100 +(cosh = cosh T. 20) x=: (2^_6)*_50+?2 10$100 + +(asin =!.1e_12 asin T. 20) x=: (2^_10)*?2 10$250 +(atan =!.1e_12 atan T. 20) x=: (2^_10)*?2 10$250 +(asinh =!.1e_12 asinh T. 20) x=: (2^_10)*?2 10$250 +(atanh =!.1e_12 atanh T. 20) x=: (2^_10)*?2 10$250 + +d=: [: 1e_13&>@| - % (+0&=)@] +x=: (2^_7)*_1e2+?20$2e2 +(f T. 20 d f=:sin + cos) x +(f T. 20 d f=:sin - cos) x +(f T. 20 d f=:sin * cos) x +(f T. 20 d f=:cos * ^ ) x +(f T. 80 d f=:sin % cos) x + +phi=: -:%:5 +0 1 1 2 3 5 8 13 21 34 55 89 -: (^@-: * sinh&.(phi&*)) t: i.12 + + +4!:55 ;:'asin asinh atan atanh B c cos cosh d f g k ' +4!:55 ;:'m n p phi pp q r rp s sin sinh tangent taysqrt x y ' + +
new file mode 100644 --- /dev/null +++ b/test/gthrow.ijs @@ -0,0 +1,158 @@ +NB. throw./catcht. ------------------------------------------------------ + +f=: 3 : 0 + if. y do. + throw. + end. + 0 +) + +(<'throw.') e. {:"1 t=: 1 (5!:7) <'f' + +f=: 3 : 0 + try. + 1 + 2 + 3 + catcht. + 4 + end. + : + try. 5 catcht. 6 end. +) + +(;:'try. catcht.') e. {:"1 t=: 1 (5!:7) <'f' + +(;:'try. catcht.') e. {:"1 t=: 2 (5!:7) <'f' + +main=: 3 : 0 + try. + sub y + catcht. + select. type_jthrow_ + case. 'aaaa' do. 'catcht aaaa' + case. 'bbb' do. 'catcht bbb' + case. 'cc' do. 'catcht cc' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + return. + end. +) + +sub=: 3 : 0 + if. y<0 do. type_jthrow_=: 'aaaa' throw. end. + if. y<4 do. type_jthrow_=: 'bbb' throw. end. + if. y<8 do. type_jthrow_=: 'cc' throw. end. + if. y=99 do. type_jthrow_=: 'd' throw. end. + (":y),' not cut back' +) + +'catcht aaaa' -: main _1 +'catcht bbb' -: main 2 +'catcht cc' -: main 6 +'10 not cut back' -: main 10 + +sub _1 NB. throw without catcht + +main1=: 3 : 0 NB. throw with adverse + try. + sub :: 0: y + catcht. + select. type_jthrow_ + case. 'aaaa' do. 'catcht aaaa' + case. 'bbb' do. 'catcht bbb' + case. 'cc' do. 'catcht cc' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + return. + end. +) + +'catcht aaaa' -: main1 _1 +'catcht bbb' -: main1 2 +'catcht cc' -: main1 6 +'10 not cut back' -: main1 10 + +main2=: 3 : 0 NB. throw with try/catch + try. + *'a' + catch. + try. + sub y + catcht. + select. type_jthrow_ + case. 'aaaa' do. 'catcht aaaa' + case. 'bbb' do. 'catcht bbb' + case. 'cc' do. 'catcht cc' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + return. + end. + end. +) + +'catcht aaaa' -: main2 _1 +'catcht bbb' -: main2 2 +'catcht cc' -: main2 6 +'10 not cut back' -: main2 10 + +main3=: 3 : 0 + try. + main4 y + catcht. + select. type_jthrow_ + case. 'd' do. 'catcht d' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + return. + end. +) + +main4=: 3 : 0 NB. catcht at multiple levels + try. + sub y + catcht. + select. type_jthrow_ + case. 'aaaa' do. 'catcht aaaa' + case. 'bbb' do. 'catcht bbb' + case. 'cc' do. 'catcht cc' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + end. +) + +'catcht aaaa' -: main3 _1 +'catcht bbb' -: main3 2 +'catcht cc' -: main3 6 +'catcht d' -: main3 99 +'10 not cut back' -: main3 10 + +main5=: 3 : 0 NB. catcht at multiple levels + try. + if. y<0 do. type_jthrow_=: 'aaaa' throw. end. + if. y<4 do. type_jthrow_=: 'bbb' throw. end. + if. y<8 do. type_jthrow_=: 'cc' throw. end. + if. y=99 do. type_jthrow_=: 'd' throw. end. + (":y),' not cut back' + catcht. + select. type_jthrow_ + case. 'aaaa' do. 'catcht aaaa' + case. 'bbb' do. 'catcht bbb' + case. 'cc' do. 'catcht cc' + case. do. throw. NB. handled by higher-level catcht. (if any) + end. + end. +) + +'catcht aaaa' -: main5 _1 +'catcht bbb' -: main5 2 +'catcht cc' -: main5 6 +'catcht d' -: main5 99 +'10 not cut back' -: main5 10 + +18!:55 <'jthrow' + + +4!:55 ;:'f main main1 main2 main3 main4 main5 sub t' + +
new file mode 100644 --- /dev/null +++ b/test/gtrain.ijs @@ -0,0 +1,105 @@ +NB. (# i.@#) ------------------------------------------------------------ + +NB. (# i.@#) y on boolean y is recognized as a special phrase by the interpreter + +f=: # i.@# + +g=: 3 : 0 + y # i.#y + : + x # i.#y +) + +(f -: g) ?1e4$2 +(f -: g) 1=?1e4$10 +(f -: g) 1e4$1 +(f -: g) 1e4$0 +(f -: g) 0 +(f -: g) 1 +(f -: g) ,0 +(f -: g) ,1 + +(f -: g) 2-1=?1e4$10 +(f -: g) ?20$20 +(f -: g) j./?2 20$20 + +(f -: g)&> #:&.> i.16 16 +(f -: g)&> ? &.> (100+i.4 5)$&.>2 + +(f -: g) ?100$2 +(f -: g) ?100$3 +(f -: g) ?0$2 +(f -: g) ?0$3 +(f -: g) 0,100$1 +(f -: g) 0,101$1 +(f -: g) 0,102$1 +(f -: g) 0,103$1 +(f -: g) 0,104$1 + +(?200$5) (f -:g) 200$'triskaidekaphobia' +(j./?2 200$5) (f -:g) 200$'triskaidekaphobia' + +i=: 1e3 ? 1e9 +b=: 1 i}1 $. 1e9 ; 0 ; 0 +(/:~ i) -: (# i.@#) b + + +NB. ({ ,) -------------------------------------------------------------- + +f=: { , +g=: 4 : 'x { , y' + +(?*/$x) (f -: g) x=: ?10 10 10$2 +(?2 3$*/$x) (f -: g) x=: ?10 10 10$2 + +(?*/$x) (f -: g) x=: ?7 11 13$2e9 +(?2 3$*/$x) (f -: g) x=: ?7 11 13$2e9 + +(?*/$x) (f -: g) x=: o.?2 3 5 7 11$2e6 +(?2 3$*/$x) (f -: g) x=: o.?2 3 5 7 11$2e6 + +'index error' -: 29 ({,) etx i.2 3 4 + + +NB. ({. ,) -------------------------------------------------------------- + +f=: {. , +g=: 4 : 'x {. , y' + +((- ?@+:)*/$x) (f -: g) x=: ?10 10 10$2 +((- ?@+:)*/$x) (f -: g) x=: ?7 11 13$2e9 +((- ?@+:)*/$x) (f -: g) x=: o.?2 3 5 7 11$2e6 + + +NB. (}. ,) -------------------------------------------------------------- + +f=: }. , +g=: 4 : 'x }. , y' + +((- ?@+:)*/$x) (f -: g) x=: ?10 10 10$2 +((- ?@+:)*/$x) (f -: g) x=: ?7 11 13$2e9 +((- ?@+:)*/$x) (f -: g) x=: o.?2 3 5 7 11$2e6 + + +NB. (e. ,) -------------------------------------------------------------- + +f=: e. , +g=: 4 : 'x e. , y' + +1 (f -: g) ?10 10 10$2 +(?2 3$2) (f -: g) ?10 10 10$2 +(?2 3$9) (f -: g) ?10 10 10$2 + +'x' (f -: g) a.{~?10 10 10$#a. +(a.{~?2 3$#a.) (f -: g) a.{~?10 10 10$#a. +(?2 3$9) (f -: g) a.{~?10 10 10$#a. + + +NB. adverb adverb trains ------------------------------------------------ + +'syntax error' -: ex ' + ((1 : ''/'') \)' + + +4!:55 ;:'b f g i x' + +
new file mode 100644 --- /dev/null +++ b/test/gtry.ijs @@ -0,0 +1,322 @@ +NB. try/catch ----------------------------------------------------------- + +fa =: 3 : 'try. 3+y catch. ''bad'' end.' + +(3+x) -: fa x=:?20$10000 +(3+x) -: fa x=:j.&?~10$1000 + +'bad' -: fa 'abc' +'bad' -: fa <1 2 3 + +fb =: 3 : (':'; 'try. x+y catch. ''bad'' end.') + +(3+x) -: 3 fb x=:?20$10000 +(3+x) -: 3 fb x=:j.&?~10$1000 + +'bad' -: 1 2 fb 3 4 5 +'bad' -: 3 fb 'abc' +'bad' -: 3 fb <1 2 3 + +fc =: 3 : 'while. try. a catch. b end. do. c end.' NB. checking parser + +fd =: 3 : 0 + : + try. + try. 3+y catch. 7+x end. + catch. + 'x and y are both bad' + end. +) + +(3+y) -: (x=:?100) fd (y=:?100) +(7+x) -: (x=:?100) fd 'triskaidekaphobia' +'x and y are both bad' -: 'foo' fd 'bar' + +write =: 1!:2 +erase =: 1!:55 + +fe =: 3 : 0 + try. + erase y + 'ok' + catch. + 'bad' + end. +) + +'ex temporanus' write <'foo.x' +'ok' -: fe <'foo.x' +'bad' -: fe 123 + +fg =: 3 : 'try. 1!:55 <y catch. end. 1' +'dichlorodiphenoltrichloroethane' write <'foo.x' +fg 'foo.x' +fg 'nonexistent' +fg 3j4 + +fh =: 3 : 0 + try. + if. 0<:y do. 'positive' return. else. t=.'negative' end. + catch. + t=.'caught' + end. + 'it is ',t +) + +'positive' -: fh 7 +'it is negative' -: fh _2 +'it is caught' -: fh 'huh?' + +fi=: 3 : 0 + try. + if. 3*y do. 1 else. 0 end. + catch. + 'caught' + end. +) + +1 -: fi 3 +0 -: fi 0 +'caught' -: fi 'asdf' + +fj =: 3 : 'try. goo y catch. ''caught'' end.' +goo=: 3 : 'if. 3*y do. 1 else. 0 end.' + +1 -: fj 3 +0 -: fj 0 +'caught' -: fj 'asdf' + +f=: 4 : 0 + try. + x+y + catchd. + 'in catchd.' + end. +) + +7 8 -: 2 3 f 5 +'in catchd.' -: 2 3 f etx 4 5 6 + +f=: 4 : 0 + try. + x+y + catcht. + 'in catcht.' + end. +) + +f=: 3 : 0 + z=. $0 + for_x. y do. + try. + if. 2|x do. z=.z,2*x else. *'error' end. + catcht. + 'in catcht' + catch. + z=. z,_999 + end. + end. +) + +(f x) -: _999 ((0=2|x)#i.#x)} 2*x=: ?40$100 + +f=: 3 : 0 + t=. 1 + while. t do. + try. break. catch. end. + t =. 0 + end. + t +) + +1 -: f 0 + +NB. check that break. goes to 1 + the enclosing while./end. + +x=: 1 (5!:7) <'f' +y=: 2{"1 x +(1+y i: <'end.') = 1{>1{(y i. <'break.'){x + +f=: 3 : 'try. 1+<2 catch. end.' +(i.0 0) -: f :: 2: '' + +f=: 3 : 0 + try. if. 0-:y do. 3 : 'throw.' 0 else. >:y end. + catch. y=. 2#y + catcht. y=. 3#y + end. +) + +0 0 0 -: f 0 +2 -: f 1 +(2#'abc') -: f 'abc' + + +NB. catcht. check for errors ---------------------------------------------- + +t=: 0 : 0 + 1 2 3 + try. + 4 + 5 + end. + 7 +) + +'control error' -: ex '3 : t' NB. 0 catches + +t=: 0 : 0 + 1 2 3 + try. + 4 + catcht. + 4 5 6 + catch. + 7 + catcht. + 8 + end. + 7 +) + +'control error' -: ex '3 : t' NB. multiple catches 1 + +t=: 0 : 0 + 1 2 3 + try. + 4 + catch. + 4 5 6 + catch. + 7 + catcht. + 8 + end. + 7 +) + +'control error' -: ex '3 : t' NB. multiple catches 2 + +t=: 0 : 0 + 1 2 3 + try. + 4 + catch. + 4 5 6 + catchd. + 7 + catchd. + 8 + end. + 7 +) + +'control error' -: ex '3 : t' NB. multiple catches 3 + +t=: 0 : 0 + if. y do. + catcht. + 4 5 6 + end. + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in do/end + +t=: 0 : 0 + if. + catcht. + 4 5 6 + end. + do. + 7 + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in if/do + +t=: 0 : 0 + if. y do. + 7 + else. + catcht. + 4 5 6 + end. + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in else/end + +t=: 0 : 0 + if. y do. + 7 + elseif. 2*y do. + catcht. + 4 5 6 + end. + elseif. 1 do. + 8 + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in do/elseif + +t=: 0 : 0 + for. i. y do. + catcht. + 4 5 6 + end. + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in fordo/end + +t=: 0 : 0 + while. y do. + catcht. + 4 5 6 + end. + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in whiledo/end + +t=: 0 : 0 + whilst. y do. + catcht. + 4 5 6 + end. + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in whilstdo/end + +t=: 0 : 0 + try. + catcht. + 4 5 6 + end. + catch. + 7 + end. +) + +'control error' -: ex '3 : t' NB. catcht nested in try/catch + +t=: 0 : 0 + try. + 1 2 3 + catcht. + 4 5 6 + end. + 7 8 9 + end. + 10 11 12 +) + +'control error' -: ex '3 : t' NB. catcht nested in try + + +4!:55 ;:'erase f fa fb fc fd fe ff fg fh fi fj goo sub t write x y' + +
new file mode 100644 --- /dev/null +++ b/test/gu.ijs @@ -0,0 +1,559 @@ +NB. Unicode 2-byte characters ------------------------------------------- + +UTYPE=: 131072 NB. type code for Unicode + +domerr=: 1 : 0 + if. 1 e. y do. + assert. 'domain error' -: u etx u: 'abcd' + end. + if. 2 e. y do. + assert. 'domain error' -: 2 u etx u: 'abc' + assert. 'domain error' -: (u: 'xyz') u etx 2 + assert. 'domain error' -: (u: 'xyz') u etx u: 'abc' + end. + if. 'l' e. y do. + assert. 'domain error' -: (u: 'ab') u etx i.2 3 + end. + if. 'r' e. y do. + assert. 'domain error' -: 2 3 4 u etx u: 'abc' + end. + 1 +) + + +NB. u: ------------------------------------------------------------------ + +x=: u: i=: _65536+2 3 4 ?@$ 2*65536 +($x) -: $i +UTYPE -: type x +(65536|i) -: 3 u: x + +x=: u: t=: a.{~ i=: ?2 3 4$#a. +($x) -: $i +UTYPE -: type x +x -: t +t -: 1 u: x +i -: 3 u: x + +x=: u: y=: u: i=: _65536+2 3 4?@$ 2*65536 +($x) -: $i +UTYPE -: type x +(65536|i) -: 3 u: x +x -: y +(3!:1 x) -: 3!:1 y + +x=: a.{~?3 5 7 2$#a. +y=: 6 u: x +($y) -: (}:$x),-:{:$x + +lr=: 1 : '5!:5 <''u''' +2&u: lr -: 1&u: b. _1 +1&u: lr -: 2&u: b. _1 +4&u: lr -: 3&u: b. _1 +3&u: lr -: 4&u: b. _1 + +'domain error' -: u: etx 0 1.2 +'domain error' -: u: etx 0 1j2 +'domain error' -: u: etx 0 1r2 +'domain error' -: u: etx 0 1;2 + +'domain error' -: 0 u: etx 0 1 2 +'domain error' -: _1 u: etx 0 1 2 +'domain error' -: _2 u: etx 0 1 2 +'domain error' -: _3 u: etx 0 1 2 +'domain error' -: _4 u: etx 0 1 2 + +'domain error' -: 0 u: etx 'abc' +'domain error' -: _1 u: etx 'abc' +'domain error' -: _2 u: etx 'abc' +'domain error' -: _3 u: etx 'abc' +'domain error' -: _4 u: etx 'abc' + +'index error' -: 4 u: etx 1 2 3 65536 + +'length error' -: 6 u: etx 'abc' +'length error' -: 6 u: etx 'abcde' + + +NB. errors in various primitives ---------------------------------------- + +< domerr 2 +<. domerr 1 2 +<: domerr 1 2 +> domerr 2 +>. domerr 1 2 +>: domerr 1 2 ++ domerr 1 2 ++. domerr 1 2 ++: domerr 1 2 +* domerr 1 2 +*. domerr 1 2 +*: domerr 1 2 +- domerr 1 2 +-. domerr 1 +-: domerr 1 +% domerr 1 2 +%. domerr 1 2 +%: domerr 1 2 +^ domerr 1 2 +^. domerr 1 2 +$ domerr 'l' +$. domerr 1 2 +| domerr 1 2 +|. domerr 'l' +|: domerr 'l' ++/ .* domerr 1 2 +<;.1 domerr 'l' +#. domerr 1 2 +#: domerr 1 2 +! domerr 1 2 +]\ domerr 'l' +]\. domerr 'l' +{ domerr 'l' +{. domerr 'l' +}. domerr 'l' +? domerr 1 2 +?. domerr 1 2 +? @$ domerr 2 +? @# domerr 2 +?.@$ domerr 2 +?.@# domerr 2 +i. domerr 1 +i: domerr 1 +j. domerr 1 2 +o. domerr 1 2 +p. domerr 1 2 +p: domerr 1 +q: domerr 1 2 +r. domerr 1 2 +x: domerr 1 2 + + +NB. = ------------------------------------------------------------------- + +x=: u: i=: t{~?2 3 41$#t=: ?19$65536 +y=: u: j=: t{~?2 3 41$#t +z=: u: k=: t{~?2 3 $#t + +(=x) -: =i +(=y) -: =j +(=z) -: =k + +(x = y ) -: i = j +(x = z ) -: i = k +(x =/ z ) -: i =/ k +(x ="2 {.y) -: i ="2 {.j + +x=: u: y=: a.{~?2 3 4$#a. +UTYPE -: type x +2 -: type y +*./@, x = y + + +NB. < ------------------------------------------------------------------- + +x=: u: a.{~?257##a. +x -: >< x +x -: ><"0 x + + +NB. > ------------------------------------------------------------------- + +x=: u: i=: t{~?2 3 41$#t=: ?19$65536 +y=: u: j=: t{~?2 3 41$#t +z=: a.{~ ? 2 3$#a. + +(>x;y) -: u: >i;j +(>x;z) -: x ,: ($x){.,:z + +'domain error' -: > etx x;0 1 0 +'domain error' -: > etx x;1 2 3 +'domain error' -: > etx x;1 2.3 +'domain error' -: > etx x;1 2j3 +'domain error' -: > etx x;1 2 3x +'domain error' -: > etx x;1 2r3 +'domain error' -: > etx x;<<2 3 + + +NB. -. ------------------------------------------------------------------ + +x=: u: i=: t{~?41$#t=: ?41 7 3$65536 +y=: u: j=: t{~?23$#t +(x -. y) -: u: i -. j + +x=: u: i=: t{~?41$#t=: a.{~ ?41 7 3$256 +y=: u: j=: t{~?41$#t + +(x -. y) -: u: i -. j +(x -. y) -: u: i -. y +(x -. y) -: u: x -. j + +(x -."1 y) -: u: i -."1 j +(x -."1 y) -: u: i -."1 y +(x -."1 y) -: u: x -."1 j + +(x -."2 y) -: u: i -."2 j +(x -."2 y) -: u: i -."2 y +(x -."2 y) -: u: x -."2 j + + +NB. -: ------------------------------------------------------------------ + +x=: u: y=: a.{~?317##a. +x -: ,x +x -: y + + +NB. $ -------------------------------------------------------------------- + +(31 $ u: i) -: u: 31 $ i=: ?7$65536 +(31 4 $ u: i) -: u: 31 4 $ i=: ?7$65536 +(31 4 5 $ u: i) -: u: 31 4 5 $ i=: ?7$65536 + + +NB. ~ -------------------------------------------------------------------- + +f=: +/ +45 -: (u: 'f')~ i.10 + + +NB. ~. ------------------------------------------------------------------- + +(~. u: i) -: u: ~. i=: t{~?541 $#t=: ?97$65536 +(~. u: i) -: u: ~. i=: t{~?541 3$#t=: ?13$65536 +(~. u: i) -: u: ~. i=: t{~?541 2 3$#t=: ? 5$65536 + +(~.t) -: ~.t,u: t=: a.{~?100 $#a. +(~.t) -: ~.t,u: t=: a.{~?200 3$#a. + +(~.t) -: ~.t,u:&.>t=: <"_1 a.{~ ?100 $#a. +(~.t) -: ~.t,u:&.>t=: <"_1 a.{~97+?200 3$3 + + +NB. ~: ------------------------------------------------------------------ + +x=: u: i=: t{~?2 3 41$#t=: ?19$65536 +y=: u: j=: t{~?2 3 41$#t +z=: u: k=: t{~?2 3 $#t + +(x ~: y ) -: i ~: j +(x ~: z ) -: i ~: k +(x ~:/ z ) -: i ~:/ k +(x ~:"2 {.y) -: i ~:"2 {.j + +x=: u: y=: a.{~?2 3 4$#a. +UTYPE -: type x +2 -: type y +-. +./@, x ~: y + + +NB. |. ------------------------------------------------------------------- + +x=: u: i=: t{~?41 2 3$#t=: ?119$65536 +(|. x) -: u: |. i +(|."1 x) -: u: |."1 i +(|."2 x) -: u: |."2 i + +(j|. x) -: u: j|. i [ j=: ?0{$x +(j|."1 x) -: u: j|."1 i [ j=: ?1{$x +(j|."2 x) -: u: j|."2 i [ j=: ?2{$x + + +NB. |: ------------------------------------------------------------------- + +x=: u: i=: t{~?2 3 5 7 11$#t=: ?119$65536 +(|: x) -: u: |: i +(|:"1 x) -: u: |:"1 i +(|:"2 x) -: u: |:"2 i + +(j|:x) -: u: j|:i [ j=: ?~#$x +(j|:x) -: u: j|:i [ j=: ?~#$x +(j|:x) -: u: j|:i [ j=: ?~#$x + +(j|:x) -: u: j|:i [ j=: C. ?~#$x +(j|:x) -: u: j|:i [ j=: C. ?~#$x +(j|:x) -: u: j|:i [ j=: C. ?~#$x + + +NB. : ------------------------------------------------------------------- + +x -: 0 : x=: 'super duper stare decisis' + +f=: 1 : (u: 'u/') +45 -: +f i.10 + +f=: 2 : (u: 'u&.:v') +5 -: +/ f *: 3 4 + +f=: 3 : (u: '(* f@<:)^:(1<y) 1>.y') +1 1 120 720 -: f"0 ]0 1 5 6 + +f=: 3 : (u:&.> 't=.y+1';'t*t') +25 -: f 4 + +f=: 4 : (u: 'x+y') +45 -: f/ i.10 + +f=: 13 : (u: 'x*y') +120 -: f/1+i.5 + + +NB. ;. ------------------------------------------------------------------ + +x=: ' boustrophedonic triskaidekaphobia deipnosophist chthonic' +(< ;.1 u: x) -: u:&.> <;.1 x +([ ;.1 u: x) -: u: [;.1 x +(, ;.1 u: x) -: u: ,;.1 x +(# ;.1 u: x) -: #;.1 x +(<@}.;.1 u: x) -: u:&.> <@}.;.1 x +(<@}:;.1 u: x) -: u:&.> <@}:;.1 x + + +NB. ;: ------------------------------------------------------------------ + +(;: -: ;:@u:) '3+4' +(;: -: ;:@u:) '+' + +0 $ 0 : 0 +sq=: 4 2 2$ 1 1 2 1 1 0 2 2 2 0 3 0 1 2 2 0 +x=: 0;sq;''''=a. +(x&;: -: x&;:@u:) '''The Power of the Powerlesss'' by Havel' +) + +'domain error' -: ;: etx (u: 257),'3+4' + + +NB. 0!: ----------------------------------------------------------------- + +0!:0 u: 'x=: i.2 3 4' +x -: i.2 3 4 + + +NB. 1!: ----------------------------------------------------------------- + +(1!:0 '*.*') -: 1!:0 u: '*.*' +x=: ' triskaidekaphobia deipnosophist boustrophedonic octothorpe' +(8 u: u: x) 1!:2 <8 u: u: 'asdf' +x -: 1!:1 <8 u: u: 'asdf' + +x=: u: ?237$65536 +x 1!:2 <'asdf' +x -: 6 u: 1!:1 <'asdf' +x -: 6 u: 1!:1 <8 u: u: 'asdf' + +x=: 'everything not forbidden is mandatory' +x 1!:2 <8 u: u: 'asdf' +x -: 1!:1 <8 u: u: 'asdf' +'01234' 1!:3 <8 u: 'asdf' +(x,'01234') -: 1!:1 <8 u: u: 'asdf' +(5+#x) -: 1!:4 <8 u: u: 'asdf' + +3 : 0 '' + if. (9!:12 '') e. 6 do. NB. do only if PC + assert. (1!:6@< -: 1!:6@<@(8&u:)@u:) 'asdf' + assert. (1!:6 <'asdf') 1!:6 <8 u: u: 'asdf' + assert. (1!:7@< -: 1!:7@<@(8&u:)@u:) 'asdf' + assert. (1!:7 <'asdf') -: 1!:7 <8 u: u: 'asdf' + end. + 1 +) + +'01234' -: 1!:11 (8 u: 'asdf');(#x),5 +'abcde' 1!:12 (8 u: 'asdf');#x +'abcde' -: 1!:11 (8 u: 'asdf');(#x),5 + +t=: 1!:21 <8 u: u: 'asdf' ++./@('asdf'&E.)&> {:"1 (1!:20) '' +1!:22 t + +1!:55 <8 u: u: 'asdf' + + +NB. 3!:n ---------------------------------------------------------------- + +UTYPE -: 3!:0 u: 'abc' + +f=: 3 : 0 + assert. y -: (3!:2) 00 (3!:1) y + assert. y -: (3!:2) 01 (3!:1) y + assert. y -: (3!:2) 10 (3!:1) y + assert. y -: (3!:2) 11 (3!:1) y + assert. y -: (3!:2) 00 (3!:3) y + assert. y -: (3!:2) 01 (3!:3) y + assert. y -: (3!:2) 10 (3!:3) y + assert. y -: (3!:2) 11 (3!:3) y + 1 +) + +f x=: u: 0 +f x=: u: 65535 +f x=: u: ?257 $65536 +f x=: u: ?257 2 $65536 +f x=: u: ?257 2 3 $65536 +f x=: u: ?257 2 3 5$65536 +f x=: u: ?257 2147483647 2e9 2e9 2e9 0$65536 + + +NB. /: ------------------------------------------------------------------ + +(/: i) -: /: x=: u: i=: ? 313 1$65536 +(/: i) -: /: x=: u: i=: ? 313 2$65536 +(/: i) -: /: x=: u: i=: ? 313 3$65536 +(/: i) -: /: x=: u: i=: ? 313 4$65536 +(/: i) -: /: x=: u: i=: ? 313 5$65536 +(/: i) -: /: x=: u: i=: ? 313 6$65536 + +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 1$65536 +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 2$65536 +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 3$65536 +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 4$65536 +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 5$65536 +(/:"2 i) -: /:"2 x=: u: i=: ?7 313 6$65536 + +(/: i) -: /: x=: u: i=: ?13 1231$65536 +(/: i) -: /: x=: u: i=: ?13 1232$65536 +(/: i) -: /: x=: u: i=: ?13 1233$65536 +(/: i) -: /: x=: u: i=: ?13 1234$65536 +(/: i) -: /: x=: u: i=: ?13 1235$65536 +(/: i) -: /: x=: u: i=: ?13 1236$65536 + +(/:"1 i) -: /:"1 x=: u: i=: ?13 1231$65536 +(/:"1 i) -: /:"1 x=: u: i=: ?13 1232$65536 +(/:"1 i) -: /:"1 x=: u: i=: ?13 1233$65536 +(/:"1 i) -: /:"1 x=: u: i=: ?13 1234$65536 +(/:"1 i) -: /:"1 x=: u: i=: ?13 1235$65536 +(/:"1 i) -: /:"1 x=: u: i=: ?13 1236$65536 + + +NB. \: ------------------------------------------------------------------ + +(\: i) -: \: x=: u: i=: ? 313 1$65536 +(\: i) -: \: x=: u: i=: ? 313 2$65536 +(\: i) -: \: x=: u: i=: ? 313 3$65536 +(\: i) -: \: x=: u: i=: ? 313 4$65536 +(\: i) -: \: x=: u: i=: ? 313 5$65536 +(\: i) -: \: x=: u: i=: ? 313 6$65536 + +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 1$65536 +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 2$65536 +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 3$65536 +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 4$65536 +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 5$65536 +(\:"2 i) -: \:"2 x=: u: i=: ?7 313 6$65536 + +(\: i) -: \: x=: u: i=: ?13 1231$65536 +(\: i) -: \: x=: u: i=: ?13 1232$65536 +(\: i) -: \: x=: u: i=: ?13 1233$65536 +(\: i) -: \: x=: u: i=: ?13 1234$65536 +(\: i) -: \: x=: u: i=: ?13 1235$65536 +(\: i) -: \: x=: u: i=: ?13 1236$65536 + +(\:"1 i) -: \:"1 x=: u: i=: ?13 1231$65536 +(\:"1 i) -: \:"1 x=: u: i=: ?13 1232$65536 +(\:"1 i) -: \:"1 x=: u: i=: ?13 1233$65536 +(\:"1 i) -: \:"1 x=: u: i=: ?13 1234$65536 +(\:"1 i) -: \:"1 x=: u: i=: ?13 1235$65536 +(\:"1 i) -: \:"1 x=: u: i=: ?13 1236$65536 + + +NB. ". ------------------------------------------------------------------ + +3 4 5 -: ". u: '3 4 5' +3 4 5 -: _1 ". u: '3 4 5' + + +NB. E. ------------------------------------------------------------------ + +x=: a.{~(a.i.'a')+? 31$26 +y=: x ((?19$y-&#x)+/i.#x)}y=: a.{~(a.i.'a')+?3111$26 +(x E. y) -: x E.&u: y + +x=: ? 31$65536 +y=: x ((?19$y-&#x)+/i.#x)}y=: ?9111$65536 +(x E. y) -: x E.&u: y + + +NB. i. ------------------------------------------------------------------ + +x=: u: i=: t{~?257$#t=: ?19$65536 +y=: u: j=: t{~?521$#t +(x i. y) -: i i. j +(y i. x) -: j i. i + +x=: u: i=: t{~?257$#t=: a. +y=: u: j=: t{~?521$#t +(x i. y) -: i i. j +(y i. x) -: j i. i + +x=: u: i=: t{~?257 2 3$#t=: ?7$65536 +y=: u: j=: t{~?521 2 3$#t +(x i. y) -: i i. j +(y i. x) -: j i. i + +x=: u: i=: t{~?257 2 3$#t=: a. +y=: u: j=: t{~?521 2 3$#t +(x i. y) -: i i. j +(y i. x) -: j i. i + +x=: a.{~97+?10$26 +y=: u: x +(x i. 1{x) -: y i. 1{y +(x i. 'x') -: y i. u: 'x' +(x i. '9') -: y i. u: '9' + +(t i.&:> t,t) -: t i. t, u:&.>t=: <"_1 a.{~ ?100 $#a. +(t i.&:> t,t) -: t i. t,~u:&.>t +(t i.&:> t,t) -: (u:&.>t) i. t, u:&.>t +(t i.&:> t,t) -: (u:&.>t) i. t,~u:&.>t + +(t i.&:> t,t) -: t i. t, u:&.>t=: <"_1 a.{~97+?100 3$3 +(t i.&:> t,t) -: t i. t,~u:&.>t +(t i.&:> t,t) -: (u:&.>t) i. t, u:&.>t +(t i.&:> t,t) -: (u:&.>t) i. t,~u:&.>t + +f=: 3 : 'a.{~ ?(y,6)$#a. ' +g=: 3 : 'u: ?(y,6)$65536' + + +NB. i: ------------------------------------------------------------------ + +x=: u: i=: t{~?257$#t=: ?19$65536 +y=: u: j=: t{~?521$#t +(x i: y) -: i i: j +(y i: x) -: j i: i + +x=: u: i=: t{~?257$#t=: a. +y=: u: j=: t{~?521$#t +(x i: y) -: i i: j +(y i: x) -: j i: i + +x=: u: i=: t{~?257 2 3$#t=: ?7$65536 +y=: u: j=: t{~?521 2 3$#t +(x i: y) -: i i: j +(y i: x) -: j i: i + +x=: u: i=: t{~?257 2 3$#t=: a. +y=: u: j=: t{~?521 2 3$#t +(x i: y) -: i i: j +(y i: x) -: j i: i + +x=: a.{~97+?10$26 +y=: u: x +(x i: 1{x) -: y i: 1{y +(x i: 'x') -: y i: u: 'x' +(x i: '9') -: y i: u: '9' + +(t i:&:> t,t) -: t i: t, u:&.>t=: <"_1 a.{~ ?100 $#a. +(t i:&:> t,t) -: t i: t,~u:&.>t +(t i:&:> t,t) -: (u:&.>t) i: t, u:&.>t +(t i:&:> t,t) -: (u:&.>t) i: t,~u:&.>t + +(t i:&:> t,t) -: t i: t, u:&.>t=: <"_1 a.{~97+?100 3$3 +(t i:&:> t,t) -: t i: t,~u:&.>t +(t i:&:> t,t) -: (u:&.>t) i: t, u:&.>t +(t i:&:> t,t) -: (u:&.>t) i: t,~u:&.>t + + +4!:55 ;:'domerr f g i j k lr sq t UTYPE x y z' + +
new file mode 100644 --- /dev/null +++ b/test/gunderai.ijs @@ -0,0 +1,101 @@ +NB. u&.(a.&i.) ---------------------------------------------------------- + +s=: 1000 ?@$ 256 +t=: 13 47 ?@$ 256 + +f=: 256|>: +(a.{~ f s) -: f f.&.(a.&i.) a.{~s +(a.{~ f t) -: f f.&.(a.&i.) a.{~t + +f=: 256|<: +(a.{~ f s) -: f f.&.(a.&i.) a.{~s +(a.{~ f t) -: f f.&.(a.&i.) a.{~t + +f=: - +(a.{~ f s) -: f f.&.(a.&i.) a.{~s +(a.{~ f t) -: f f.&.(a.&i.) a.{~t + +p=: 22 (2?256)} 123 (22 b.) i.256 +f=: {&p +(a.{~ f s) -: f f.&.(a.&i.) a.{~s +(a.{~ f t) -: f f.&.(a.&i.) a.{~t + +test1=: 4 : 0 " 0 + assert. (a.{~ y x b. s) -: y&(x b.) &.(a.&i.) a.{~s + assert. (a.{~ y x b. t) -: y&(x b.) &.(a.&i.) a.{~t + assert. (a.{~ s x b. y) -: (x b.)&y&.(a.&i.) a.{~s + assert. (a.{~ t x b. y) -: (x b.)&y&.(a.&i.) a.{~t + assert. (a.{~ y x b. s) -: ((a.{~y x b. i.256) {~ a.i.]) a.{~s + assert. (a.{~ y x b. t) -: ((a.{~y x b. i.256) {~ a.i.]) a.{~t + assert. (a.{~ s x b. y) -: ((a.{~(i.256) x b. y ) {~ a.i.]) a.{~s + assert. (a.{~ t x b. y) -: ((a.{~(i.256) x b. y ) {~ a.i.]) a.{~t + 1 +) + +*./ , (16+i.16) test1/ i.256 + + +NB. x m b.&.(a.&i.) y ------------------------------------------------- + +test2=: 3 : 0 " 0 + g=: y b. + f=: y b.&.(a.&i.) + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 47 ?@$ 256 [ q=: 13 47 ?@$ 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 47 ?@$ 256 [ q=: ? 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: ? 256 [ q=: 13 47 ?@$ 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 47 ?@$ 256 [ q=: 13 ?@$ 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 ?@$ 256 [ q=: 13 47 ?@$ 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 48 ?@$ 256 [ q=: 13 ?@$ 256 + assert. (a.{~p g q) -: (p{a.) f q{a. [ p=: 13 ?@$ 256 [ q=: 13 48 ?@$ 256 + 1 +) + +test2 16+i.16 + +NB. x0=: a. {~ 10 100000 ?@$ 256 +NB. x1=: a. {~ 10 100001 ?@$ 256 +NB. y =: a. {~ 10 ?@$ 256 +NB. t0=: 6!:2 'x0 22 b.&.(a.&i.) y' +NB. t1=: 6!:2 'x1 22 b.&.(a.&i.) y' +NB. 1.2 < t1 % t0 + +NB. x0=: a. {~ (?256) 23 b. i.256 +NB. x1=: a. {~ ?~ 256 +NB. y =: a. {~ 5e5 ?@$ 256 +NB. t0=: 6!:2 '(x0 {~ a. i. ]) y' +NB. t1=: 6!:2 '(x1 {~ a. i. ]) y' +NB. 2 < t1 % t0 + + +NB. x m b./&.(a.&i.) y ------------------------------------------------- + +test3=: 3 : 0 " 0 + g=: y b./ + f=: y b./&.(a.&i.) + assert. (a.{~g q) -: f q{a. [ q=: 31 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 32 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 63 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 64 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 17 31 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 17 32 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 13 63 ?@$ 256 + assert. (a.{~g q) -: f q{a. [ q=: 13 64 ?@$ 256 + 1 +) + +test3 16+i.16 + +NB. y =: a. {~ (1+5e5) ?@$ 256 +NB. t0=: 6!:2 ' 22 b./&.(a.i.]) y' +NB. t1=: 6!:2 'a.{~22 b./ a.i. y' +NB. 2 < t1 % t0 + +NB. y =: a. {~ 1373 61 ?@$ 256 +NB. t0=: 6!:2 ' 27 b./&.(a.i.]) y' +NB. t1=: 6!:2 'a.{~27 b./ a.i. y' +NB. 2 < t1 % t0 + + +4!:55 ;:'f g p q s t t0 t1 test1 test2 test3 x0 x1 y' + +
new file mode 100644 --- /dev/null +++ b/test/gwhile.ijs @@ -0,0 +1,143 @@ +NB. while --------------------------------------------------------------- + +fa =. 3 : 0 + : + z=.1 + a=.x + n=.y + while. n do. + if. 2|n do. z=.z*a end. + a=.*:a + n=.<.-:n + end. + z + ) + +3 (^ = fa) 7 +3 (^ = fa)"0 i.7 +_3.1 (^ = fa)"0 ?5$100 +0 (^ = fa)"0 ?5$50 + +fb =. 3 : 0 + z=.1 + while. y do. + y=.<:y + z =.+:z + end. +) + +(2&^ = fb)"0 x=.?10$25 + +fc =. 3 : 0 + z=.1 + while. 1 do. + if. 0=y do. break. end. + y=.<:y + z =.+:z + end. +) + +(2&^ = fc)"0 i.8 + +fd =. 3 : 0 + z=.1 + while. 1 do. + z=.+:z + y=.<:y + if. 0<y do. continue. end. + break. + end. + z +) + +(2&^ = fd)"0 x=.>:?10$25 + +fe =. 3 : 0 + z=.1 + y=.>:y + while. y=.<:y do. + z=.+:z + end. + z +) + +(2&^ = fe)"0 >:i.8 + +gcd =. 3 : 0 NB. (x+.y)=+/(x,y)*x gcd y + : + m=.x,1 0 + n=.y,0 1 + while. {.m do. n=.t [ m=.n-m*<.n %&{. t=.m end. + }.n +) + +(+./ -: [ +/ .* gcd/)"1 x=.?3 10 2$1000 + + +NB. whilst -------------------------------------------------------------- + +ga =. 3 : 0 + : + z=.1 + a=.x + n=.y + whilst. n do. + if. 2|n do. z=.z*a end. + a=.*:a + n=.<.-:n + end. + z +) + +3 (^ = ga) 7 +*./ 3 (^ = ga)"0 x=.>:i.7 +*./ _3.1 (^ = ga)"0 x=.>:?5$100 +*./ 0 (^ = ga)"0 x=.>:?5$50 + +gb =. 3 : 0 + z=.1 + whilst. y do. + y=.<:y + z =.+:z + end. +) + +(2&^ = gb)"0 x=.>:?10$26 + +gc =. 3 : 0 + z=.1 + whilst. 1 do. + if. 0=y do. break. end. + y=.<:y + z =.+:z + end. +) + +(2&^ = gc)"0 x=.>:?10$27 + +gd =. 3 : 0 + z=.1 + whilst. 1 do. + z=.+:z + y=.<:y + if. 0<y do. continue. end. + break. + end. + z +) + +(2&^ = gd)"0 x=.>:?10$27 + +ge =. 3 : 0 + whilst. z do. + z=.y + y=.<:y + end. + z +) + +0 -: ge 0 + +4!:55 ;:'fa fb fc fd fe ga gb gc gcd gd ge x' + +
new file mode 100644 --- /dev/null +++ b/test/gx.ijs @@ -0,0 +1,35 @@ +NB. x. ------------------------------------------------------------------ + +old=: 9!:48 '' +9!:49]1 + +jnc =: 4!:0 +jnl =: 4!:1 + +x. =. i.12 +0 -: jnc <'x.' +(<'x.') e. jnl i.4 + +x. =. 1 : 'x./\' +1 -: jnc <'x.' +(<'x.') e. jnl i.4 + +x. =. 2 : 'x.&y. + x.@y.' +2 -: jnc <'x.' +(<'x.') e. jnl i.4 + +x. =. +/ +3 -: jnc <'x.' +(<'x.') e. jnl i.4 + +4!:55 <'x.' +_1 -: jnc <'x.' +-. (<'x.') e. jnl i.4 + +4!:55 ;:'x.' + +9!:49 old + +4!:55 ;:'jnc jnl old' + +
new file mode 100644 --- /dev/null +++ b/test/gx132.ijs @@ -0,0 +1,36 @@ +NB. %: on extended integers --------------------------------------------- + +0 1 _ -: 0x %: 0 1 2x +0 1 _ -: 0 %: 0 1 2 + +(i:5) (%: -: %:&x:) 0 +(i:5) (%: -: %:&x:) 1 + +0 (%: -: %:&x:) i.5 +1 (%: -: %:&x:) i:5 + +2 (%: -: %:&x:) - 0 1 +2 (%: -: %:&x:) - 4 5 6 +3 (%: -: %:&x:) - 0 1 +3 (%: -: %:&x:) - 4 5 6 + +test=: 4 : 0 + n=: x: x + r=: x: y + yy=: r^n + assert. r = n %: yy + assert. (r-1) = n <.@%: yy-1 + assert. (r+1) = n >.@%: yy+1 + 1 +) + +test/ 1+?100 1000x +test/ 1+2 1* ?100 1000x +test/ 1+2 1*1+?100 1000x + +5 6x test"0 ] 11^309x +12343 12344x test"0 ] 2x + +4!:55 ;:'n r test yy' + +
new file mode 100644 --- /dev/null +++ b/test/gxco.ijs @@ -0,0 +1,89 @@ +NB. x: ------------------------------------------------------------------ + +(x: 4) -: x: {: 3.4 4 +(x: 4) -: x: {: 3j4 4 + +7r2 -: x: 3.5 +3r5 -: x: 3r5 +7r100 -: x: 0.07 +271r100 -: x: 2.71 + +64 -: type x: 0 +64 -: type x: 1 +64 -: type x: 0 1 +64 -: type x: _5 999999 +64 -: type x: 2147483647 _2147483648 0 9 + +128 -: type x: -~2.5 +128 -: type x: o. 0 +128 -: type x: 1 2 3 4 5 6.5 + +128 -: type x: _ +128 -: type x: __ + +(2^ 53x) = x: 2^ 53 +(2^_53x) = x: 2^_53 +(=<.) x: !20+i.30 +(=<.) % x: % !20+i.30 + +'domain error' -: x: etx 3j5 +'domain error' -: x: etx '345' +'domain error' -: x: etx <1 2 3 + +NB. 'domain error' -: x: etx _. + +'domain error' -: 'a' x: etx 1.5 +'domain error' -: 3.4 x: etx 1.5 +'domain error' -: 3j4 x: etx 1.5 +'domain error' -: 3 x: etx 1.5 +'domain error' -: _3 x: etx 1.5 +'domain error' -: 0 x: etx 1.5 + +(0 1 0 1 ,. 1x) -: 2 x: 0 1 0 1 +(1 2 3 4 ,. 1x) -: 2 x: 1 2 3 4 +(3 5 7 9 ,. 2x) -: 2 x: 1 2 3 4+0.5 +(1 2 3 4 ,. 1x) -: 2 x: 1 2 3 4+-~0j1 + +((,%) ! 10*i.10) -: x:^:_1 (,%) ! 10*i.10x +(12345 % ! 10*i.10) -: x:^:_1 ] 12345 % ! 10*i.10x + +(= x:) ,1 _1 */ 1e43 1e_43 +(= x:) ,1 _1 */ 2^137 _137 + +(": -: ":@(+&(-~1r2)))@x:"0 ] ,1 _1 */ 1e43 1e_43 +(": -: ":@(+&(-~1r2)))@x:"0 ] ,1 _1 */ 2^137 _137 + +'domain error' -: 0.5 = etx 10^309x +'domain error' -: 0.5 = etx - 10^309x + +'ill-formed number' -: ex '1x ___' + + +NB. x: conversion from rationals to floats ------------------------------ + +f=: 3 : 0 + p=: (_1^10000 ?@$ 2) * 10000 ?@$ y + q=: 1 + 10000 ?@$ y + d=: (p%q) - p %&x: q + assert. 0=d + 1 +) + +f"0 ]2*10^2 3 9 + +f1=: 3 : 0 + p=: (_1^1000 ?@$ 2) * 1000 ?@$ y + q=: 2+($p) ?@$ 20 + e=: (_1^($p) ?@$ 2)*q^x:<._350*q^.10 + d=: p - _1 x: p + e + assert. 0 = d + 1 +) + +NB. f1"0 ]10^2 3 9 +f1"0 ]10^2 3 + + +4!:55 ;:'d f f1 p q' + +
new file mode 100644 --- /dev/null +++ b/test/gxco1.ijs @@ -0,0 +1,869 @@ +NB. extended precision integers ----------------------------------------- + +NB. create test data + +x1=: (1-1e4)+10 11 ?@$ 2e4-1 +y1=: (1-1e4)+10 11 ?@$ 2e4-1 +x2=: (1-1e8)+10 11 ?@$ 2e8-1 +y2=: (1-1e8)+10 11 ?@$ 2e8-1 +x3=: (1-1e9)+10 11 ?@$ 2e9-1 +y3=: (1-1e9)+10 11 ?@$ 2e9-1 + + +NB. = ------------------------------------------------------------------- + +x1 (= -: =&.x:) y1 +x1 (= -: =&.x:) y2 +x1 (= -: =&.x:) y3 +x2 (= -: =&.x:) y1 +x2 (= -: =&.x:) y2 +x2 (= -: =&.x:) y3 +0 (= -: =&.x:) y1 +0 (= -: =&.x:) y2 +0 (= -: =&.x:) y3 + +x1 (= -: =&.x:) x=:x1+($x1) ?@$ 2 +x2 (= -: =&.x:) x=:x2+($x2) ?@$ 2 +x3 (= -: =&.x:) x=:x3+($x3) ?@$ 2 + +(($x3)$0) -: x3 = ($x3)$a. +(($x3)$0) -: x3 = ($x3)$a: + +(= -: =@:x:) y1 +(= -: =@:x:) y2 +(= -: =@:x:) y3 + +(= -: =&.x:)~ y1 +(= -: =&.x:)~ y2 +(= -: =&.x:)~ y3 + +0 0 1 -: 3 3.4 4 = x: 4 +0 0 1 -: 3 3j4 4 = x: 4 +0 0 0 -: '3j4' = x: 4 +0 0 0 -: (<"0 'abc') = x: 4 + +(x1=y) -: (x: x1) = y=:x1+0.5*($x1)?@$2 +(x2=y) -: (x: x2) = y=:x2+0.5*($x2)?@$2 +(x3=y) -: (x: x3) = y=:x3+0.5*($x3)?@$2 + +(x1=y) -: (x: x1) = y=:x1+j./(2,$x1)?@$2 +(x2=y) -: (x: x2) = y=:x2+j./(2,$x1)?@$2 +(x3=y) -: (x: x3) = y=:x3+j./(2,$x1)?@$2 + + +NB. < ------------------------------------------------------------------- + +x1 (< -: <&.x:) y1 +x1 (< -: <&.x:) y2 +x1 (< -: <&.x:) y3 +x2 (< -: <&.x:) y1 +x2 (< -: <&.x:) y2 +x2 (< -: <&.x:) y3 +0 (< -: <&.x:) y1 +0 (< -: <&.x:) y2 +0 (< -: <&.x:) y3 + +x1 (< -: <&.x:) x=:x1+($x1)?@$2 +x2 (< -: <&.x:) x=:x2+($x2)?@$2 +x3 (< -: <&.x:) x=:x3+($x3)?@$2 + +(< -: <&.x:)~ y1 +(< -: <&.x:)~ y2 +(< -: <&.x:)~ y3 + +'domain error' -: (x: x1) < etx 3j4 +'domain error' -: (x: x1) < etx 'a' +'domain error' -: (x: x1) < etx <12 + + +NB. <. ------------------------------------------------------------------ + +(<. -: <.&.x:) y1 +(<. -: <.&.x:) y2 +(<. -: <.&.x:) y3 + +x1 (<. -: <.&.x:) y1 +x1 (<. -: <.&.x:) y2 +x2 (<. -: <.&.x:) y1 +x2 (<. -: <.&.x:) y2 +0 (<. -: <.&.x:) y1 +0 (<. -: <.&.x:) y2 + +'domain error' -: (x: x1) <. etx 3j4 +'domain error' -: (x: x1) <. etx 'a' +'domain error' -: (x: x1) <. etx <12 + + +NB. <: ------------------------------------------------------------------ + +(<: -: <:&.x:) y1 +(<: -: <:&.x:) y2 +(<: -: <:&.x:) y3 + +x1 (<: -: <:&.x:) y1 +x1 (<: -: <:&.x:) y2 +x2 (<: -: <:&.x:) y1 +x2 (<: -: <:&.x:) y2 +0 (<: -: <:&.x:) y1 +0 (<: -: <:&.x:) y2 + +'domain error' -: (x: x1) <: etx 3j4 +'domain error' -: (x: x1) <: etx 'a' +'domain error' -: (x: x1) <: etx <12 + + +NB. > ------------------------------------------------------------------- + +x1 (> -: >&.x:) y1 +x1 (> -: >&.x:) y2 +x1 (> -: >&.x:) y3 +x2 (> -: >&.x:) y1 +x2 (> -: >&.x:) y2 +x2 (> -: >&.x:) y3 +0 (> -: >&.x:) y1 +0 (> -: >&.x:) y2 +0 (> -: >&.x:) y3 + +x1 (> -: >&.x:) x=:x1+($x1)?@$2 +x2 (> -: >&.x:) x=:x2+($x2)?@$2 +x3 (> -: >&.x:) x=:x3+($x3)?@$2 + +(> -: >&.x:)~ y1 +(> -: >&.x:)~ y2 +(> -: >&.x:)~ y3 + +(><"0 x1) -: ><"0 x: x1 +(><"1 x1) -: ><"1 x: x1 +(><"0 x2) -: ><"0 x: x2 +(><"1 x2) -: ><"1 x: x2 +(><"0 x3) -: ><"0 x: x3 +(><"1 x3) -: ><"1 x: x3 + +(>(<"_1 x1),<"_1 y1) -: >(<"_1 x: x1),<"_1 y1 + +3.5 4 -: > 3.5; 4x +3j5 4 -: > 3j5; 4x + +'domain error' -: (x: x1) > etx 3j4 +'domain error' -: (x: x1) > etx 'a' +'domain error' -: (x: x1) > etx <12 + +'domain error' -: > etx 'abc';x: 4 +'domain error' -: > etx (<12);x: 4 + + +NB. >. ------------------------------------------------------------------ + +(>. -: >.&.x:) y1 +(>. -: >.&.x:) y2 +(>. -: >.&.x:) y3 + +x1 (>. -: >.&.x:) y1 +x1 (>. -: >.&.x:) y2 +x2 (>. -: >.&.x:) y1 +x2 (>. -: >.&.x:) y2 +0 (>. -: >.&.x:) y1 +0 (>. -: >.&.x:) y2 + +'domain error' -: (x: x1) >. etx 3j4 +'domain error' -: (x: x1) >. etx 'a' +'domain error' -: (x: x1) >. etx <12 + + +NB. >: ------------------------------------------------------------------ + +x1 (>: -: >:&.x:) y1 +x1 (>: -: >:&.x:) y2 +x1 (>: -: >:&.x:) y3 +x2 (>: -: >:&.x:) y1 +x2 (>: -: >:&.x:) y2 +x2 (>: -: >:&.x:) y3 +0 (>: -: >:&.x:) y1 +0 (>: -: >:&.x:) y2 +0 (>: -: >:&.x:) y3 + +x1 (>: -: >:&.x:) x=:x1+($x1)?@$2 +x2 (>: -: >:&.x:) x=:x2+($x2)?@$2 +x3 (>: -: >:&.x:) x=:x3+($x3)?@$2 + +(>: -: >:&.x:)~ y1 +(>: -: >:&.x:)~ y2 +(>: -: >:&.x:)~ y3 + +'domain error' -: (x: x1) >: etx 3j4 +'domain error' -: (x: x1) >: etx 'a' +'domain error' -: (x: x1) >: etx <12 + + +NB. + ------------------------------------------------------------------- + +(+ -: +&.x:) y1 +(+ -: +&.x:) y2 +(+ -: +&.x:) y3 + +x1 (+ -: +&.x:) y1 +x1 (+ -: +&.x:) y2 +x1 (+ -: +&.x:) y3 +x2 (+ -: +&.x:) y1 +x2 (+ -: +&.x:) y2 +x2 (+ -: +&.x:) y3 +x3 (+ -: +&.x:) y1 +x3 (+ -: +&.x:) y2 +x3 (+ -: +&.x:) y3 + +(x1+3.4) -: (x: x1) + 3.4 +(x1+3j4) -: (x: x1) + 3j4 + +'domain error' -: (x: x1) + etx 'a' +'domain error' -: (x: x1) + etx <12 + + +NB. +. ------------------------------------------------------------------ + +(+. -: +.&.x:) y1 +(+. -: +.&.x:) y2 +(+. -: +.&.x:) y3 + +x1 (+. -: +.&.x:) y1 +x1 (+. -: +.&.x:) y2 +x1 (+. -: +.&.x:) y3 +x2 (+. -: +.&.x:) y1 +x2 (+. -: +.&.x:) y2 +x2 (+. -: +.&.x:) y3 +x3 (+. -: +.&.x:) y1 +x3 (+. -: +.&.x:) y2 +x3 (+. -: +.&.x:) y3 + +0 1 1 1 -: 0 0 1 1 +. x: 0 1 0 1 + +(+./~ -: +./~@:x:) _20+i.41 +(+./~ -: +./~@:x:) 1e4+_20+i.41 +(+./~ -: +./~@:x:) 20e4+_20+i.41 +(+./~ -: +./~@:x:) 27e4+_20+i.41 + +(3.5 +. 4) -: 3.5 +. 4x +(3j5 +. 4) -: 3j5 +. 4x + +'domain error' -: (x: x1) +. etx 'a' +'domain error' -: (x: x1) +. etx <12 + + +NB. +: ------------------------------------------------------------------ + +(+: -: +:&.x:) y1 +(+: -: +:&.x:) y2 +(+: -: +:&.x:) y3 + +0 0 1 1 (+: -: +:&.x:) 0 1 0 1 + +'domain error' -: (x: 1 2 3) +: etx x: 0 1 0 +'domain error' -: (x: x1) +: etx 3.4 +'domain error' -: (x: x1) +: etx 3j4 +'domain error' -: (x: x1) +: etx 'a' +'domain error' -: (x: x1) +: etx <12 + + +NB. * ------------------------------------------------------------------- + +x1=: (1-1e4)+10 11?@$2e4-1 +y1=: (1-1e4)+10 11?@$2e4-1 +x2=: (1-1e8)+10 11?@$2e8-1 +y2=: (1-1e8)+10 11?@$2e8-1 +x3=: (1-1e9)+10 11?@$2e9-1 +y3=: (1-1e9)+10 11?@$2e9-1 + +(* -: *&.x:) y1 +(* -: *&.x:) y2 +(* -: *&.x:) y3 + +x1 (* -: *&.x:) y1 +x1 (* -: *&.x:) y2 +x1 (* -: *&.x:) y3 +x2 (* -: *&.x:) y1 +x2 (* -: *&.x:) y2 +x2 (* -: *&.x:) y3 +x3 (* -: *&.x:) y1 +x3 (* -: *&.x:) y2 +x3 (* -: *&.x:) y3 + +x=: */8192$2x +x = *~ */4096$2x +x = *~ */2048$4x +x = *~ */1024$16x +x = *~ */ 512$256x +x = *~ */ 256$65536x +x = *~ */ 128$65536x^2 +x = *~ */ 64$65536x^4 +x = *~ */ 32$65536x^8 + +y=: x: ?10$40 +(y^n) = */@(n&$)"0 y [ n=:?4000 +(y^n) = */@(n&$)"0 y [ n=:?4000 +(y^n) = */@(n&$)"0 y [ n=:?4000 + +(3.5 * 4) -: 3.5 * 4x +(3j5 * 4) -: 3j5 * 4x + +'domain error' -: (x: x1) * etx 'a' +'domain error' -: (x: x1) * etx <12 + + +NB. *. ------------------------------------------------------------------ + +x1=: (1-1e4)+10 11?@$2e4-1 +y1=: (1-1e4)+10 11?@$2e4-1 +y2=: (1-1e8)+10 11?@$2e8-1 +y3=: (1-1e9)+10 11?@$2e9-1 + +x1 (*. -: *.&.x:) y1 +x1 (*. -: *.&.x:) y2 +x1 (*. -: *.&.x:) y3 + +0 0 0 1 -: 0 0 1 1 *. etx x: 0 1 0 1 + +(3.5 *. 4) -: 3.5 *. 4x +(3j5 *. 4) -: 3j5 *. 4x + +'domain error' -: (x: x1) *. etx 'a' +'domain error' -: (x: x1) *. etx <12 + + +NB. *: ------------------------------------------------------------------ + +(*: -: *:&.x:) y1 +(*: -: *:&.x:) y2 +(*: -: *:&.x:) y3 + +0 0 1 1 (*: -: *:&.x:) 0 1 0 1 + +'domain error' -: (x: 1 2 3) *: etx x: 0 1 0 +'domain error' -: (x: x1) *: etx 3.4 +'domain error' -: (x: x1) *: etx 3j4 +'domain error' -: (x: x1) *: etx 'a' +'domain error' -: (x: x1) *: etx <12 + + +NB. - ------------------------------------------------------------------- + +(- -: -&.x:) y1 +(- -: -&.x:) y2 +(- -: -&.x:) y3 + +x1 (- -: -&.x:) y1 +x1 (- -: -&.x:) y2 +x1 (- -: -&.x:) y3 +x2 (- -: -&.x:) y1 +x2 (- -: -&.x:) y2 +x2 (- -: -&.x:) y3 +x3 (- -: -&.x:) y1 +x3 (- -: -&.x:) y2 +x3 (- -: -&.x:) y3 + +(x1 - 3.4) -: (x: x1) - 3.4 +(x1 - 3j4) -: (x: x1) - 3j4 + +'domain error' -: (x: x1) - etx 'a' +'domain error' -: (x: x1) - etx <12 + + +NB. % ------------------------------------------------------------------- + +(<.!.0@% -: <.@%&.x:) y1+0=y1 +(<.!.0@% -: <.@%&.x:) y2+0=y2 +(<.!.0@% -: <.@%&.x:) y3+0=y3 + +(>.!.0@% -: >.@%&.x:) y1+0=y1 +(>.!.0@% -: >.@%&.x:) y2+0=y2 +(>.!.0@% -: >.@%&.x:) y3+0=y3 + +x1 (<.!.0@% -: <.@%&.x:) y1+0=y1 +x1 (<.!.0@% -: <.@%&.x:) y2+0=y2 +x1 (<.!.0@% -: <.@%&.x:) y3+0=y3 +x2 (<.!.0@% -: <.@%&.x:) y1+0=y1 +x2 (<.!.0@% -: <.@%&.x:) y2+0=y2 +x2 (<.!.0@% -: <.@%&.x:) y3+0=y3 +x3 (<.!.0@% -: <.@%&.x:) y1+0=y1 +x3 (<.!.0@% -: <.@%&.x:) y2+0=y2 +x3 (<.!.0@% -: <.@%&.x:) y3+0=y3 + +x1 (>.!.0@% -: >.@%&.x:) y1+0=y1 +x1 (>.!.0@% -: >.@%&.x:) y2+0=y2 +x1 (>.!.0@% -: >.@%&.x:) y3+0=y3 +x2 (>.!.0@% -: >.@%&.x:) y1+0=y1 +x2 (>.!.0@% -: >.@%&.x:) y2+0=y2 +x2 (>.!.0@% -: >.@%&.x:) y3+0=y3 +x3 (>.!.0@% -: >.@%&.x:) y1+0=y1 +x3 (>.!.0@% -: >.@%&.x:) y2+0=y2 +x3 (>.!.0@% -: >.@%&.x:) y3+0=y3 + +(% -: %&.x:)~ y1 +(% -: %&.x:)~ y2 +(% -: %&.x:)~ y3 + +e=:$0 +e -: 2x % '' +e -: 2x % $0 +e -: 2x % 0$a: +e -: 2x <.@% '' +e -: 2x <.@% $0 +e -: 2x <.@% 0$a: +e -: 2x >.@% '' +e -: 2x >.@% $0 +e -: 2x >.@% 0$a: + +_ -: % x: 0 +_ -: 4 % x: 0 +__ -: _4 % x: 0 + + +NB. %: ------------------------------------------------------------------ + +0 -: %: x: 0 +5 -: %: x: 25 +(%: -: %:@x:) *~i.2 10 + +(<.!.0@%: -: <.@%:@x:) i.2 10 +(<.!.0@%: -: <.@%:@x:) 1e3*i.2 10 +(<.!.0@%: -: <.@%:@x:) 1e4*i.2 10 +(<.!.0@%: -: <.@%:@x:) 1e5*i.2 10 +(<.!.0@%: -: <.@%:@x:) 1e8*i.2 10 +(<.!.0@%: -: <.@%:@x:) 1e9*i.2 10 + +(>.!.0@%: -: >.@%:@x:) i.2 10 +(>.!.0@%: -: >.@%:@x:) 1e3*i.2 10 +(>.!.0@%: -: >.@%:@x:) 1e4*i.2 10 +(>.!.0@%: -: >.@%:@x:) 1e5*i.2 10 +(>.!.0@%: -: >.@%:@x:) 1e8*i.2 10 +(>.!.0@%: -: >.@%:@x:) 1e9*i.2 10 + +NB. 0 1 _ -: 0x %: 0 1 2x +NB. 0 1 _ -: 0 %: 0 1 2 + +f=: 3 : '((*~s)<:y)*.y<:*~1+s=.<.@%: y' + +f"0 !x:i.5 10 +f"0 (i.2 10)**/20$x:1e4 + +( %: 2) -: %: x: 2 +(<.@%: _5) -: <.@%: x: _5 +(>.@%: _5) -: >.@%: x: _5 + +root=: 4 : 0 + r=.x + a=.y + f=. ([ * (a&+)@((r-1)&*)@(^&r)) <.@% r&*@(^&r) + f^:_ [1 +) + + +NB. ^ ------------------------------------------------------------------- + +x1 (^ -: ^&.x:) y=:10 11?@$100 +x2 (^ -: ^&.x:) y +x3 (^ -: ^&.x:) y + +1 = 1^x: _3 0 3 +1 = 1^y1 +1 = 1^y2 +1 = 1^y3 +1 = 1^x: 1e50 + +1 0 0 0 0 -: 0 ^ x: i.5 +(0=t) -: 0^t=:|y1 +(0=t) -: 0^t=:|y2 +(0=t) -: 0^t=:|y3 +0 -: 0^x: 1e50 + +x1 (^ -: ^&.x:) t=:($x1)?@$50 +x2 (^ -: ^&.x:) t=:($x2)?@$50 +x3 (^ -: ^&.x:) t=:($x3)?@$50 + +3 (<.!.0@^ -: <.@^&x:) t=:_3+i.7 +_3 (<.!.0@^ -: <.@^&x:) t +3 (>.!.0@^ -: >.@^&x:) t=:_3+i.7 +_3 (>.!.0@^ -: >.@^&x:) t + +f=: 100&|@^ +(2 f e) -: 2 f (20|e)+20*20<e=:(10^100x)+4 5?@$100 +(3 f e) -: 3 f 20|e +(4 f e) -: 4 f (10|e)+10*10<e +(5 f e) -: 5 f 2<.e +(6 f e) -: 6 f ( 5|e)+ 5* 5<e +(7 f e) -: 7 f 4 |e +(8 f e) -: 8 f (20|e)+20*20<e +(9 f e) -: 9 f 10|e + +_ -: 0 ^ _2x +1r9 -: 3 ^ _2x +1r9 -: 3 ^ _2x + +'limit error' -: 2 ^ etx 10^100x + +e0=: 3 : 0 NB. calculate e to y decimal places + k=. 1 + a=. b=. 1x + d=. 10x^y + e=. +:d + whilst. b<e do. + a=. >: a * k + b=. b * k + k=. >:k + end. + (a*d) <.@% b +) + +e1=: 3 : 0 + (+/ , {.) */\. }. (i.y),1x +) + +x=: ^/~ 10%~i:10x +y=: ^/~ 10%~i:9x +y -: 1 1}. _1 _1}.x + + +NB. ~. ------------------------------------------------------------------ + +(~. x) -: ~. x: x=:_1e9+?100$2e9 +(~.<"0 x) -: ~.<"0 x: x + +NB. *** (<"0 ~.x,y) -: ~.(<"0 x: x),<"0 y=.x+0.5*?($x)$2 + + +NB. ~: ------------------------------------------------------------------ + +(x1~:y) -: (x: x1) ~: y=:x1+0.5*($x1)?@$2 +(x2~:y) -: (x: x2) ~: y=:x2+0.5*($x2)?@$2 +(x3~:y) -: (x: x3) ~: y=:x3+0.5*($x3)?@$2 + +(x1~:y) -: (x: x1) ~: y=:x1+j./(2,$x1)?@$2 +(x2~:y) -: (x: x2) ~: y=:x2+j./(2,$x1)?@$2 +(x3~:y) -: (x: x3) ~: y=:x3+j./(2,$x1)?@$2 + +1 1 0 -: 3 3.4 4 ~: x:4 +1 1 0 -: 3 3j4 4 ~: x:4 +1 1 1 -: '3j4' ~:x:4 + + +NB. | ------------------------------------------------------------------- + +(| -: |&.x:) y1 +(| -: |&.x:) y2 +(| -: |&.x:) y3 + +x1 (| -: |&.x:) y1 +x1 (| -: |&.x:) y2 +x1 (| -: |&.x:) y3 +x2 (| -: |&.x:) y1 +x2 (| -: |&.x:) y2 +x2 (| -: |&.x:) y3 +x3 (| -: |&.x:) y1 +x3 (| -: |&.x:) y2 +x3 (| -: |&.x:) y3 + +0 0 0 -: (x: _123 0 1234) | 0 + +x=: 15 15 _15 _15 +y=: 4 _4 4 _4 * x +(x|y) -: x |&.x: y + +(| -: | &.x:) y1 +(| -: | &.x:) y2 +(| -: | &.x:) y3 +(| -: | &.x:) _1e8 _1e4 0 1e4 1e8 + +(| -: | &.x:)~ y1 +(| -: | &.x:)~ y2 +(| -: | &.x:)~ y3 +(| -: | &.x:)~ _1e8 _1e4 0 1e4 1e8 + +(|/~ -: |/~@:x:) _20+i.41 +(|/~ -: |/~@:x:) 1e4+_20+i.41 +(|/~ -: |/~@:x:) 20e4+_20+i.41 +(|/~ -: |/~@:x:) 27e4+_20+i.41 + +(x1 | 3.4) -: (x: x1) | etx 3.4 +(x1 | 3j4) -: (x: x1) | etx 3j4 + +'domain error' -: (x: x1) | etx 'a' +'domain error' -: (x: x1) | etx <12 + + +NB. . ------------------------------------------------------------------- + +x=: _1e6+ 5 13 ?@$ 2e6 +y=: _1e6+13 7 ?@$ 2e6 +x (+/ .* -: +/ .*&.x:) y +x (+/ .* -: +/ .*&.x:) 1 +x (+/ .* -: +/ .*&.x:) 2 +x (+/ .* -: +/@(*"1 _))&:x: y + +((x: x) +/ .* 1) -: (x: x) +/ .* 13$1 +((x: x) +/ .* 2) -: (x: x) +/ .* 13$2 + + +NB. : ------------------------------------------------------------------- + +f=: 3 : 'if. y do. ''non-zero'' else. ''zero'' end.' + +'zero' -: f 0 +'zero' -: f x: 0 + +'non-zero' -: f 12 +'non-zero' -: f x: 12 + + +NB. #. ------------------------------------------------------------------ + +(#. -: #.&:x:) x1 +(#. -: #.&:x:) x2 +(#. -: #.&:x:) x3 + +3 (#. -: #.&:x:) x1 +3 (#. -: #.&:x:) x2 +3 (#. -: #.&:x:) x3 + + +NB. #: ------------------------------------------------------------------ + +(!x:20) -: #. #: !x:20 +(!x:40) -: #. #: !x:40 +(!x:60) -: #. #: !x:60 + +(!x:20) -: 10 #. (90$10) #: !x:20 +(!x:40) -: 10 #. (90$10) #: !x:40 +(!x:60) -: 10 #. (90$10) #: !x:60 + + +NB. ! ------------------------------------------------------------------- + +(! -: !&.x:) i.10 +(!@x: -: */@:>:@i.@x:"0) x=:2 10?@$150 + +(!/~ -: !/~@:x:) _11+i.21 +(i.10) (! -: !&.x:) 2e9 + +min=: [ <. -~ +arg=: |.@(] - i.@min) ,. >:@i.@min +f =: (% +./)@:* +bc =: {. @ (f/) @ arg " 0 + +(x=:1+20?@$20) (! -: bc&.x:) y=:1e9*1+20?@$20 + +ind =: i.@(0&>.)@([ <. -~) +pf =: -.&0 @: , @: q: +num =: pf @ (] - ind) +den =: pf @ (1: + ind) +exp =: , +//. ,&# # 1 _1"_ +bct =: num (exp */@:x:@:# ~.@,) den + +x (! -: bct"0) 10+x=:i.11 +(x=:1+?20$20) (bc&x: -: bct"0&x:) y=:1e6*1+20?@$20 + +bc2=: ((i.@[ -~ ]) %&(*/) >:@i.@[)&x: + +3 (! -: bc2) 4*x:2e9 +10 (! -: bc2) 8*x:2e9 + +(-: */x-0 1) -: 2 ! x=:*/x: 10?@$1e8 + + +NB. 3!:x ---------------------------------------------------------------- + +y=: !x:2 10?@$200 +y -: 3!:2 (3!:1) y + + +NB. /: ------------------------------------------------------------------ + +(/: -: /:@: x:) y=:_100+2000?@$200 +(/: -: /:@:(<"0)@:x:) y +(/: -: /:@: x:) y=:_1e9+2000?@$2e9 +(/: -: /:@:(<"0)@:x:) y + +test=: 4 : '(/:(<"_1 x),<"_1 y) -: /:(<"_1 x: x),<"_1 y' + +(x=:_1e9+100 ?@$2e9) test y=: o._1e9+100 ?@$2e9 +(x=:_1e9+100 2?@$2e9) test y=: -:_1e9+100 ?@$2e9 +(x=:_1e9+100 ?@$2e9) test y=: -:_1e9+100 2?@$2e9 +(x=:_1e9+100 2?@$2e9) test y=: o._1e9+100 2?@$2e9 + + +NB. \: ------------------------------------------------------------------ + +(\: -: \:@: x:) y=:_100+2000?@$200 +(\: -: \:@:(<"0)@:x:) y +(\: -: \:@: x:) y=:_1e9+2000?@$2e9 +(\: -: \:@:(<"0)@:x:) y + +test=: 4 : '(\:(<"_1 x),<"_1 y) -: \:(<"_1 x: x),<"_1 y' + +(x=:_1e9+100 ?@$2e9) test y=: o._1e9+100 ?@$2e9 +(x=:_1e9+100 2?@$2e9) test y=: -:_1e9+100 ?@$2e9 +(x=:_1e9+100 ?@$2e9) test y=: -:_1e9+100 2?@$2e9 +(x=:_1e9+100 2?@$2e9) test y=: o._1e9+100 2?@$2e9 + + +NB. ". ------------------------------------------------------------------ + +(x: y) -: ". ;(":&.>y),&.><'x ' [ y=: +: _1e9+200?@$2e9 +(x: y) -: ". ;(":&.>y),&.><'x ' [ y=: ,y1 +(x: y) -: ". ;(":&.>y),&.><'x ' [ y=: ,y2 +(x: y) -: ". ;(":&.>y),&.><'x ' [ y=: ,y3 + +(x: 123 _99 456789) -: _99 ". '123x foo 456789' + +3.4 45 -: 3.4 ". etx '123x 45' + +'ill-formed number' -: ". etx '1234ex' +'ill-formed number' -: ". etx '123x _x x' +'ill-formed number' -: ". etx '3j4x' +'ill-formed number' -: ". etx '123.4 34x' + + +NB. extended integer comparisons ---------------------------------------- + +x=: 2 2.2 2.5 3 3.5 3.7 4 +y=: _4 _3 _2 _1 0 1 2 3 4 + +x (< -: (< x:)) 3 +x (<: -: (<: x:)) 3 +x (= -: (= x:)) 3 +x (~: -: (~: x:)) 3 +x (>: -: (>: x:)) 3 +x (> -: (> x:)) 3 + +(-x) (< -: (< x:)) _3 +(-x) (<: -: (<: x:)) _3 +(-x) (= -: (= x:)) _3 +(-x) (~: -: (~: x:)) _3 +(-x) (>: -: (>: x:)) _3 +(-x) (> -: (> x:)) _3 + +(x,-x) (< / -: (< x:)"0/) y +(x,-x) (<:/ -: (<: x:)"0/) y +(x,-x) (= / -: (= x:)"0/) y +(x,-x) (~:/ -: (~: x:)"0/) y +(x,-x) (>:/ -: (>: x:)"0/) y +(x,-x) (> / -: (> x:)"0/) y + +3 (< -: x:@[ < ]) x +3 (<: -: x:@[ <: ]) x +3 (= -: x:@[ = ]) x +3 (~: -: x:@[ ~: ]) x +3 (>: -: x:@[ >: ]) x +3 (> -: x:@[ > ]) x + +_3 (< -: x:@[ < ]) -x +_3 (<: -: x:@[ <: ]) -x +_3 (= -: x:@[ = ]) -x +_3 (~: -: x:@[ ~: ]) -x +_3 (>: -: x:@[ >: ]) -x +_3 (> -: x:@[ > ]) -x + +y (< / -: (x:@[ < ])"0/) x,-x +y (<:/ -: (x:@[ <: ])"0/) x,-x +y (= / -: (x:@[ = ])"0/) x,-x +y (~:/ -: (x:@[ ~: ])"0/) x,-x +y (>:/ -: (x:@[ >: ])"0/) x,-x +y (> / -: (x:@[ > ])"0/) x,-x + +x=: 10?@$20 +y=: 0.5*20?@$40 +(x i. y) -: (x: x) i. y +(y i. x) -: y i. x: x + + +NB. A. ------------------------------------------------------------------ + +(<: ! x: #y) = A. |. y=:i.50 + +'index error' -: ( !50x) A. etx i.50 +'index error' -: (->:!50x) A. etx i.50 + + +NB. e. ------------------------------------------------------------------ + +x=:1000?@$500 +y=:0.25 * 1200?@$2000 + +(x e. y) -: (x: x) e. y +(y e. x) -: y e. x: x + + +NB. i. ------------------------------------------------------------------ + +(type -: type@i.) x: 5 +(type -: type@i.) x: 0 +(type -: type@i.) x: 4 5 +(type -: type@i.) x: _4 5 +(type -: type@i.) x: 4 0 + +(x:@i. -: i.@:x:) 5 +(x:@i. -: i.@:x:) 4 5 +(x:@i. -: i.@:x:) _4 5 + +x=:_1e9+400?@$2e9 +y=:x+0.5*($x)?@$2 + +(x i. y) -: (x: x) i. y +(y i. x) -: y i. x: x + +(x i. x) -: (<"0 x: x) i. <"0 x +(x i. x) -: (<"0 x) i. <"0 x: x +(x i. x) -: (<"0 x: x) i. <"0 x: x + +(x i. y) -: (<"0 x: x) i. <"0 y +(x i. y) -: (<"0 x) i. <"0 x: y +(x i. y) -: (<"0 x: x) i. <"0 x: y + + +NB. j. ------------------------------------------------------------------ + +(j. x: x1) -: j. x1 + + +NB. p. ------------------------------------------------------------------ + +x=: _100+7?@$200 +c=: _100+? 200 + +(c;x) (p. -: x:^:_1@(p.x:)) y1 +(c;x) (p. -: x:^:_1@(p.x:)) y2 +(c;x) (p. -: x:^:_1@(p.x:)) y3 + +x (p. -: x:^:_1@:p.&:x:) y1 +x (p. -: x:^:_1@:p.&:x:) y2 +x (p. -: x:^:_1@:p.&:x:) y3 + +(p. 1 2 3 5) -: p. x: 1 2 3 5 + + +NB. q: ------------------------------------------------------------------ + +f=: 3 : 0 + x=. q: y + (y=*/x: x) *. *./x e. p:i.>:p:^:_1 {:x +) + +f !20x +f !30x +f 12345678901234567890x + +18 8 4 2 1 1 1 1 -: _ q: !20x +(!20x) -: */ (p: i.#x)^x:x=: _ q: !20x +(!30x) -: */ (p: i.#x)^x:x=: _ q: !30x + +H =: %@>:@(+/~)@i. NB. Hilbert matrix +det=: -/ .* + +(~.@q:@%@det@H -: i.&.(p:^:_1)@+:) 5x +(~.@q:@%@det@H -: i.&.(p:^:_1)@+:) 6x +(~.@q:@%@det@H -: i.&.(p:^:_1)@+:) 7x +(~.@q:@%@det@H -: i.&.(p:^:_1)@+:) 8x +(~.@q:@%@det@H -: i.&.(p:^:_1)@+:) 9x + + +4!:55 ;:'arg bc bc2 bct c den det e e0 e1 exp f H ind min n' +4!:55 ;:'num pf root t test x x1 x2 x3 y y1 y2 y3' + +
new file mode 100644 --- /dev/null +++ b/test/gxco2.ijs @@ -0,0 +1,68 @@ +NB. extended precision integers ----------------------------------------- + +NB. create test data + +x1=. (1-1e4)+10 11 ?@$ 2e4-1 +y1=. (1-1e4)+10 11 ?@$ 2e4-1 +x2=. (1-1e8)+10 11 ?@$ 2e8-1 +y2=. (1-1e8)+10 11 ?@$ 2e8-1 +x3=. (1-1e9)+10 11 ?@$ 2e9-1 +y3=. (1-1e9)+10 11 ?@$ 2e9-1 + + +NB. o. ------------------------------------------------------------------ + +0x = o. 0x +0x = <.@o. 0x +0x = >.@o. 0x + +0 -: o. x: 0 +0 -: <.@o. x: 0 +0 -: >.@o. x: 0 + +(<.!.0@o. -: <.@o.@x:) y1 +(<.!.0@o. -: <.@o.@x:) y2 +(<.!.0@o. -: <.@o.@x:) y3 + +(>.!.0@o. -: >.@o.@x:) y1 +(>.!.0@o. -: >.@o.@x:) y2 +(>.!.0@o. -: >.@o.@x:) y3 + +31415926535897932384626433832795028841971x = <.@o. 10^40x +31415926535897932384626433832795028841972x = >.@o. 10^40x + +x=. '3 14159 26535 89793 23846 26433 83279 50288 41971 ' +y=. '3 ', , _5 (,&' ')\ }. ": <.@o. 10x^40 +x -: y + +f=. }:@":@(<.@o.) +g=. (<.&# {. [) -: (<.&# {. ]) + +(10x^ 50) g&f 10x^300 +(10x^100) g&f 10x^300 +(10x^150) g&f 10x^300 +(10x^200) g&f 10x^300 + +(o. 1) -: o. 1x +(o. _2) -: o. _2x + +( 0 o. 5) -: 0 o. x: 5 +( 1 o. 5) -: 1 o. x: 5 +( 2 o. 5) -: 2 o. x: 5 +( 3 o. 5) -: 3 o. x: 5 +( 4 o. 5) -: 4 o. x: 5 +( 5 o. 5) -: 5 o. x: 5 +( 6 o. 5) -: 6 o. x: 5 +( 7 o. 5) -: 7 o. x: 5 +(_1 o. 5) -: _1 o. x: 5 +(_2 o. 5) -: _2 o. x: 5 +(_3 o. 5) -: _3 o. x: 5 +(_4 o. 5) -: _4 o. x: 5 +(_5 o. 5) -: _5 o. x: 5 +(_6 o. 5) -: _6 o. x: 5 +(_7 o. 5) -: _7 o. x: 5 + + +4!:55 ;:'f g x x1 x2 x3 y y1 y2 y3' + +
new file mode 100644 --- /dev/null +++ b/test/gxinf.ijs @@ -0,0 +1,253 @@ +NB. x: and infinity ----------------------------------------------------- + +match=: -:&(3!:1) +xi =: x:^:_1 + +( 64=type x), 5 _ -: x=: 5x _ +( 64=type x), 5 _ -: x=: 5r1 _ + +(128 -: type x), _ 1r2 match x=:x: _ 0.5 +(128 -: type x), __ 1r2 match x=:x: __ 0.5 + +(8 -: type x), _ __ 225 match x=:xi _ __ 225x +(8 -: type x), _ __ 2 match x=:xi _ __ 2x +(8 -: type x), _ __ 0.5 match x=:xi _ __ 1r2 + +0r1 -: 5r_ +0r1 -: _5r_ + +'ill-formed number' -: ex ' _r_ ' +'ill-formed number' -: ex ' _r__' +'ill-formed number' -: ex '__r_ ' +'ill-formed number' -: ex '__r__' + + +NB. infinite integers and rationals and comparatives -------------------- + +_ 5x = _ 5x +__ 5x = __ 5x +_ 5r1 = _ 5r1 +__ 5r1 = __ 5r1 +_ 5x = _ 5r1 +__ 5x = __ 5r1 + +0 0 -: _ 2x = 99999x +0 0 -: _ 2x = _99999x +0 0 -: __ 2x = 99999x +0 0 -: __ 2x = _99999x + +pinf=: {. _ 5x +ninf=: {. __ 5x + +pinf > ninf +pinf > _99999x +pinf > - 10^100x +pinf > 0x +pinf > 99999x +pinf > 10^100x + +( 10^100x) > ninf +99999x > ninf +0x > ninf +_99999x > ninf +(- 10^100x) > ninf + +-. pinf > pinf +-. ( 10^100x) > pinf +-. (-10^100x) > pinf +-. ninf > pinf +-. ninf > 0x +-. ninf > ninf + +pinf >: ninf +pinf >: _99999x +pinf >: - 10^100x +pinf >: 0x +pinf >: 99999x +pinf >: 10^100x +pinf >: pinf + +( 10^100x) >: ninf +99999x >: ninf +0x >: ninf +_99999x >: ninf +(- 10^100x) >: ninf +ninf >: ninf + +-. ( 10^100x) >: pinf +-. (-10^100x) >: pinf +-. ninf >: pinf +-. ninf >: 0x + + +NB. infinite integers and rationals and primitives ---------------------- + +_ 5x match _ 2x + _ 3x +_ 5x match _ 2x + 5 3x +_ 5x match _ 2x + _5 3x +__ 5x match __ 2x + __ 3x +__ 5x match __ 2x + 5 3x +__ 5x match __ 2x + _5 3x + +_ 5r2 match _ 2r2 + _ 3r2 +_ 5r2 match _ 2r2 + 5 3r2 +_ 5r2 match _ 2r2 + _5 3r2 +__ 5r2 match __ 2r2 + __ 3r2 +__ 5r2 match __ 2r2 + 5 3r2 +__ 5r2 match __ 2r2 + _5 3r2 + +'NaN error' -: _ 2x + etx __ 5x +'NaN error' -: _ 2r1 + etx __ 5r4 +'NaN error' -: __ 2x + etx _ 5x +'NaN error' -: __ 2r1 + etx _ 5r4 + + +y=: }. 5x _ __ +'NaN error' -: y +. etx 12x +'NaN error' -: y +. etx _12x +'NaN error' -: 12x +. etx y +'NaN error' -: _12x +. etx y +'NaN error' -: y +. etx y +'NaN error' -: y +. etx |.y + +y=: }. 5r1 _ __ +'NaN error' -: y +. etx 12x +'NaN error' -: y +. etx _12x +'NaN error' -: 12x +. etx y +'NaN error' -: _12x +. etx y +'NaN error' -: y +. etx y +'NaN error' -: y +. etx |.y + +_ 5x match _ 8x - __ 3x +_ 5x match _ 8x - 5 3x +_ 5x match _ 8x - _5 3x +__ 5x match __ 8x - _ 3x +__ 5x match __ 8x - 5 3x +__ 5x match __ 8x - _5 3x + +__ _5x match _ 8x -~__ 3x +__ _5x match _ 8x -~ 5 3x +__ _5x match _ 8x -~_5 3x +_ _5x match __ 8x -~ _ 3x +_ _5x match __ 8x -~ 5 3x +_ _5x match __ 8x -~_5 3x + +_ 5r2 match _ 8r2 - __ 3r2 +_ 5r2 match _ 8r2 - 5 3r2 +_ 5r2 match _ 8r2 - _5 3r2 +__ 5r2 match __ 8r2 - _ 3r2 +__ 5r2 match __ 8r2 - 5 3r2 +__ 5r2 match __ 8r2 - _5 3r2 + +__ _5r2 match _ 8r2 -~__ 3r2 +__ _5r2 match _ 8r2 -~ 5 3r2 +__ _5r2 match _ 8r2 -~_5 3r2 +_ _5r2 match __ 8r2 -~ _ 3r2 +_ _5r2 match __ 8r2 -~ 5 3r2 +_ _5r2 match __ 8r2 -~_5 3r2 + +'NaN error' -: _ 2x - etx _ 5x +'NaN error' -: _ 2r1 - etx _ 5r4 +'NaN error' -: __ 2x - etx __ 5x +'NaN error' -: __ 2r1 - etx __ 5r4 + + +_1 = * {. __ 2x +_1 = * {. __ 2r3 +1 = * {. _ 2x +1 = * {. _ 2r3 + +0 0 -: 0 * _ 2x +0 0 -: 0 * __ 2x +0 0 -: 0 * _ 2r5 +0 0 -: 0 * __ 2r5 + + +y=: }. 5x _ __ +'NaN error' -: y *. etx 12x +'NaN error' -: y *. etx _12x +'NaN error' -: 12x *. etx y +'NaN error' -: _12x *. etx y + +x=: {. _ 5x +y=: {. __ 5x + +'NaN error' -: x *. etx x +'NaN error' -: x *. etx y +'NaN error' -: y *. etx x +'NaN error' -: y *. etx y + +y=: }. 5r1 _ __ +'NaN error' -: y *. etx 1r2 +'NaN error' -: y *. etx _1r2 +'NaN error' -: 1r2 *. etx y +'NaN error' -: _1r2 *. etx y + +x=: {. _ 5r2 +y=: {. __ 5r2 + +'NaN error' -: x *. etx x +'NaN error' -: x *. etx y +'NaN error' -: y *. etx x +'NaN error' -: y *. etx y + + 5r0 -: %0x +_5r0 -: -%0x + 5r0 -: %0r1 +_5r0 -: -%0r1 + +x=: {. _ 5x +(64=type y), x = y=: 5x % 0x +(64=type y),(-x) = y=: _5x % 0x +(64=type y), 0x = y=: 5x % x +(64=type y), 0x = y=: _5x % x + +x=: {. _ 5x +y=: {. __ 5x +'NaN error' -: x % etx x +'NaN error' -: x % etx y +'NaN error' -: y % etx x +'NaN error' -: y % etx y + +x=: {. _ 5r2 +y=: {. __ 5r2 +'NaN error' -: x % etx x +'NaN error' -: x % etx y +'NaN error' -: y % etx x +'NaN error' -: y % etx y + + +pinf = | pinf,ninf + +y=: }. 2x _ __ +(<'NaN error') = 5 _5x | etx&.>/ y +(2 2$5 _ __ _5x) -: y |/ 5 _5x +y -: 0x | y + +y=: }. 2r3 _ __ +(<'NaN error') = 5 _5r1 |etx&.>/ y +(2 2$5 _ __ _5r1) -: y |/ 5 _5r1 +y -: 0r1 | y + +_ 2x match ! _ 2x +_ 2x match ! _ 2r1 +_ 2x match ! __ 2x +_ 2x match ! __ 2r1 + +( 64 -: type x), '_ __ 5' -: ": x=:_ __ 5x +(128 -: type x), '_ __ 5r3' -: ": x=:_ __ 5r3 + +'domain error' -: p: etx {. _ 12x +'domain error' -: p: etx {. __ 12x +'domain error' -: p: etx {. _ 12r7 +'domain error' -: p: etx {. __ 12r7 + +'domain error' -: q: etx {. _ 12x +'domain error' -: q: etx {. __ 12x +'domain error' -: q: etx {. _ 12r7 +'domain error' -: q: etx {. __ 12r7 + + +4!:55 ;:'match ninf pinf x xi y' + +
new file mode 100644 --- /dev/null +++ b/test/test.ijs @@ -0,0 +1,29 @@ +NB. utilities for J GPL source release test +NB. assumes J GPL source folder is current directory +NB. see test/tsu.ijs for additional info + +testpath=: jpath (1!:43''),'/test/' NB. 1!:43 current directory +load testpath,'tsu.ijs' + +9!:21[1e8 NB. limit error rather than long memory thrash (g400) +threshold=: 0.1 NB. timer threshold failures less likely +libtsdll=: jpath ' ',~(1!:43''),'/libtsdll.',>(UNAME-:'Darwin'){'so';'dylib' + +LOGFILE=: 2 NB. log to console (2) or file (jpath'~temp\log.log') +LOGIT=: 3 : 'y[(>y)1!:2<LOGFILE' +SNS=: 3 : '(<testpath),each(;:y),each<''.ijs''' NB. script names +BAD=: 3 : '>(-.bad)#y' + +TEST=: (13 : '0!:3 LOGIT y')"0 +TESTX=: (13 : '0!:2 LOGIT y')"0 + +NB. bad=: TEST ddall +NB. BAD ddall + +NB. TESTX SNS 'g120' NB. see g120 details + +NB. TESTX SNS 'g120 gintovfl' NB. see g120 gintovfl details + +NB. ddt=: ddall -. SNS 'g120 gintovfl' NB. remove crashers +NB. bad=: TEST ddt +NB. BAD ddt
new file mode 100644 --- /dev/null +++ b/test/tsu.ijs @@ -0,0 +1,64 @@ +NB. test script utilities ----------------------------------------------- + +1=#$ testpath NB. testpath must already be defined as path to tests (with final / or \) before loading tsu.ijs + +testfiles=: 3 : 0 NB. y. is prefix - e.g., 'g' or 'gm' or 'gs' + testpath&,&.> /:~ {."1 [1!:0 testpath,y,'*.ijs' +) + +ddall =: testfiles 'g' NB. all +ddgmbx =: testfiles 'gmbx' NB. map boxed arrays +ddgsp =: testfiles 'gsp' NB. sparse arrays +ddg =: ddall -. ddgmbx,ddgsp NB. "ordinary" + +etx =: 1 : 'x :: (<:@(13!:11)@i.@0: >@{ 9!:8@i.@0:)' +ex =: ". etx +fex =: }. @ (i.&(10{a.) {. ]) @ (13!:12) @ i. @ 0: @ (0!:110) + +threshold=: 0.75 NB. for timing tests +timer =: 6!:2 + +type =: 3!:0 +imax =: IF64{:: 2147483647; 9223372036854775807 +imin =: (-imax)-1 + +scheck=: 3 : 0 NB. check sparse array + s=. $ y + a=. 2 $. y + e=. 3 $. y + i=. 4 $. y + x=. 5 $. y + + assert. 1 = #$s NB. 0 + assert. s -: <.s NB. 1 + assert. imax >: #s NB. 2 + assert. *./ (0 <: s) *. s <: imax NB. 3 + assert. _ > */s NB. 4 + + assert. 1 = #$a NB. 5 + assert. *./ a e. i.#s NB. 6 + assert. a -: ~.a NB. 7 + + assert. 0 = #$e NB. 8 + assert. (type e) = <. 0.001*type y NB. 9 + assert. (type e) = type x NB. 10 + + assert. 2 = #$i NB. 11 + assert. i -: <.i NB. 12 + assert. imax >: #i NB. 13 + assert. (#i) = #x NB. 14 + assert. ({:$i) = #a NB. 15 + assert. *./, (0<:i) *. i<"1 a{s NB. 16 + assert. i -: ~. i NB. 17 + assert. i -: /:~i NB. 18 + + assert. (#$x) = 1+(#s)-#a NB. 19 + assert. (}.$x) -: ((i.#s)-.a){s NB. 20 + 1 +) + +comb=: 4 : 0 + c=. 1 {.~ - d=. 1+y-x + z=. i.1 0 + for_j. (d-1+y)+/&i.d do. z=. (c#j) ,. z{~;(-c){.&.><i.{.c=. +/\.c end. +)
new file mode 100644 --- /dev/null +++ b/tsdll.c @@ -0,0 +1,133 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +#ifdef _WIN32 +#include <windows.h> +int WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) +{ + return TRUE; +} +typedef wchar_t wc; +#else +#define _stdcall +#define _cdecl +typedef unsigned short wc; +#endif + +#include <stdio.h> + +#if defined(_WIN64) || defined(_UNIX64) +#define SY_64 1 +typedef long long I; +#else +#define SY_64 0 +typedef long I; +#endif + +#define sum {return a[0]=b+c[0]+c[1];} + +typedef double D; +typedef float F; + +// test each integer type +// tests in place s (and i for J64) in place conversion +char _stdcall cbasic(char* a, char b, char* c) sum +wc _stdcall wbasic(wc* a, wc b, wc* c) sum +short _stdcall sbasic(short* a, short b, short* c) sum +int _stdcall ibasic(int* a, int b, int* c) sum +I _stdcall xbasic(I* a, I b, I* c) sum + +// test pointer result +char cd[]="test"; +char* _stdcall pc(){ return cd;} + + +// test d result and *d +double _stdcall dipdpd(int c, double* p, double* pr) +{ + double d=0; int i; + for(i=0; i<c; ++i) + { + *pr=d+=p[i]; + } + return d; +} + +// test f result and *f (convert in place) +float _stdcall fipfpf(int c, float* p, float* pr) +{ + float f=0; int i; + for(i=0; i<c; ++i) + { + *pr=f+=(float)p[i]; + } + return f; +} + +double _stdcall complex(int c, double* j){ return j[c];} + +float _stdcall f(){ return (float)1.5;} +double _stdcall d(){ return (double)1.5;} + +D _stdcall dd(D d0){return d0*2;} +D _stdcall ddd(D d0, D d1){return d0+d1;} +D _stdcall dddd(D d0, D d1, D d2){return d0+d1+d2;} + +D _stdcall dx0(I a,D b) {return a+b;} +D _stdcall dx1(D a,I b) {return a+b;} +D _stdcall dx2(I a,D b,I c) {return a+b+c;} +D _stdcall dx3(D a,I b,D c) {return a+b+c;} +D _stdcall dx4(I a,D b,I c,D d) {return a+b+c+d;} +D _stdcall dx5(D a,I b,D c,I d) {return a+b+c+d;} +D _stdcall dx6(I a,D b,I c,D d,I e) {return a+b+c+d+e;} +D _stdcall dx7(D a,I b,D c,I d,D e) {return a+b+c+d+e;} + +D _stdcall d1(D a,D b,D c,D d,D e,D f,D g,D h){ + return a+b+c+d+e+f+g+h;} + +/* 9 double scalars is error 7 0 in linux64 */ +D _stdcall d1a(D a,D b,D c,D d,D e,D f,D g,D h,D i){ + return a+b+c+d+e+f+g+h+i;} + +I _stdcall d2(D a,D b,D c,D d,D e,D f,D g,D h){ + return (I)(a+b+c+d+e+f+g+h);} + +D _stdcall d3(D a,I b,D c,I d,D e,I f,D g,I h,D i,I j,D k,I l,D m,I n,D o,I p){ + return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;} + +D _stdcall d4(D a,int b,D c,int d,D e,int f,D g,int h,D i,int j,D k,int l,D m,int n,D o,int p){ + return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;} + +D _stdcall d5(D a,I b, D c, I d, D e, I f, D g, D* pd, F* pf, I* px, int* pi){ + return a+b+c+d+e+f+g+pd[0]+pd[1]+pf[0]+pf[1]+px[0]+px[1]+pi[0]+pi[1];} + +F _stdcall f1(F a,F b,F c,F d,F e,F f,F g,F h){ + return a+b+c+d+e+f+g+h;} + +I _stdcall f2(F a,F b,F c,F d,F e,F f,F g,F h){ + return (I)(a+b+c+d+e+f+g+h);} + +F _stdcall f3(F a,I b,F c,I d,F e,I f,F g,I h,F i,I j,F k,I l,F m,I n,F o,I p){ + return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;} + +float _stdcall fff(float f0, float f1){return f0+f1;} + +D _stdcall fd(float f0, D d0, float f1, D d1, float* fp, D* fd){ + fp[0]=f0; fp[1]=f1; fd[0]=d0; fd[1]=d1; + return f0+f1+d0+d1; +} + +// __cdecl - default C calling convention +// __cdecl is the alternate (+ cd flag) calling convention +int _cdecl altinci(int i){return ++i;} + +// '0 procaddress ...' +I _stdcall xbasic_add(){return (I)xbasic;} + +// '1 procindex ...' +typedef I (_stdcall *PROC)(); +I _stdcall objxxx(void* obj,I a,I b){return a+b;} +D _stdcall objddd(void* obj,D a,D b){return a+b;} +//PROC vtable[]={&(PROC)objxxx,&(PROC)objddd}; +PROC vtable[]={(PROC)objxxx,(PROC)objddd}; +PROC* object=vtable; +I _stdcall obj_add(){return(I)&object;}
new file mode 100644 --- /dev/null +++ b/u.c @@ -0,0 +1,258 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Interpreter Utilities */ + +#include "j.h" + + +#if SY_64 + +I jtmult(J jt,I x,I y){B neg;I a,b,c,p,q,qs,r,s,z;static I m=0x00000000ffffffff; + if(!x||!y)R 0; + neg=0>x!=0>y; + if(0>x){x=-x; ASSERT(0<x,EVLIMIT);} p=m&(x>>32); q=m&x; + if(0>y){y=-y; ASSERT(0<y,EVLIMIT);} r=m&(y>>32); s=m&y; + ASSERT(!(p&&r),EVLIMIT); + a=p*s+q*r; qs=q*s; b=m&(qs>>32); c=m&qs; + ASSERT(2147483648>a+b,EVLIMIT); + z=c+((a+b)<<32); + R neg?-z:z; +} + +I jtprod(J jt,I n,I*v){I*u,z; + if(1>n)R 1; + u=v; DO(n, if(!*u++)R 0;); + z=*v++; DO(n-1, z=mult(z,*v++);); + R z; +} + +#else + +I jtmult(J jt,I x,I y){D z=x*(D)y; ASSERT(z<=IMAX,EVLIMIT); R(I)z;} + +I jtprod(J jt,I n,I*v){D z=1; DO(n, z*=(D)v[i];); ASSERT(z<=IMAX,EVLIMIT); R(I)z;} + +#endif + + +#if SY_64 && SY_WIN32 +#pragma message("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Win64 bug workaround") +D jfloor1(D x){D y; + if(-2.0e9<=x&&x<=2.0e9)R floor(x); + if(x<-4.51e15||4.51e15<x)R x; + y=x; *((I*)&y)&=0xffffffffff000000; + R y+floor(x-y); +} /* workaround for Windows 64 bit bug */ +#endif + + +B all0(A w){RZ(w); R !memchr(AV(w),C1,AN(w));} + +B all1(A w){RZ(w); R !memchr(AV(w),C0,AN(w));} + +I jtaii(J jt,A w){I m=IC(w); R m&&!(SPARSE&AT(w))?AN(w)/m:prod(AR(w)-1,1+AS(w));} + +A jtapv(J jt,I n,I b,I m){A z;I j=b-m,p=b+m*(n-1),*x; + GA(z,INT,n,1,0); x=AV(z); + switch(m){ + case 0: DO(n, *x++=b;); break; + case -1: while(j!=p)*x++=--j; break; + case 1: while(j!=p)*x++=++j; break; + default: while(j!=p)*x++=j+=m; + } + R z; +} /* b+m*i.n */ + +B jtb0(J jt,A w){RZ(w); ASSERT(!AR(w),EVRANK); if(!(B01&AT(w)))RZ(w=cvt(B01,w)); R*BAV(w);} + +B*jtbfi(J jt,I n,A w,B p){A t;B*b;I*v; + GA(t,B01,n,1,0); b=BAV(t); + memset(b,!p,n); v=AV(w); DO(AN(w), b[v[i]]=p;); + R b; +} /* boolean mask from integers: p=(i.n)e.w */ + +I bp(I t){ + switch(t){ + case B01: R sizeof(B); + case LIT: case ASGN: case NAME: + R sizeof(C); + case C2T: R sizeof(C2); + case INT: case LPAR: case RPAR: case MARK: case SYMB: + R sizeof(I); + case FL: R sizeof(D); + case CMPX: R sizeof(Z); + case BOX: R sizeof(A); + case XNUM: R sizeof(X); + case RAT: R sizeof(Q); + case SB01: case SINT: case SFL: case SCMPX: case SLIT: case SBOX: + R sizeof(P); + case VERB: case ADV: case CONJ: + R sizeof(V); + case CONW: R sizeof(CW); + case SBT: R sizeof(SB); +#ifdef UNDER_CE + default: R t&XD?sizeof(DX):t&XZ?sizeof(ZX):-1; +#else + case XD: R sizeof(DX); + case XZ: R sizeof(ZX); + default: R -1; +#endif +}} + +I bsum(I n,B*b){I q,z=0;UC*u;UI t,*v; + v=(UI*)b; u=(UC*)&t; q=n/(255*SZI); +#if SY_64 + DO(q, t=0; DO(255, t+=*v++;); z+=u[0]+u[1]+u[2]+u[3]+u[4]+u[5]+u[6]+u[7];); +#else + DO(q, t=0; DO(255, t+=*v++;); z+=u[0]+u[1]+u[2]+u[3];); +#endif + u=(UC*)v; DO(n-q*255*SZI, z+=*u++;); + R z; +} /* sum of boolean vector b */ + +C cf(A w){RZ(w); R*CAV(w);} + +C cl(A w){RZ(w); R*(CAV(w)+AN(w)-1);} + +I jtcoerce2(J jt,A*a,A*w,I mt){I at,at1,t,wt,wt1; + RZ(*a&&*w); + at=AT(*a); at1=AN(*a)?at:0; + wt=AT(*w); wt1=AN(*w)?wt:0; RE(t=maxtype(at1,wt1)); RE(t=maxtype(t,mt)); + if(!t)RE(t=maxtype(at,wt)); + if(t!=at)RZ(*a=cvt(t,*a)); + if(t!=wt)RZ(*w=cvt(t,*w)); + R t; +} + +A jtcstr(J jt,C*s){R str((I)strlen(s),s);} + +B evoke(A w){V*v=VAV(w); R CTILDE==v->id&&v->f&&NAME&AT(v->f);} + +I jti0(J jt,A w){RZ(w=vi(w)); ASSERT(!AR(w),EVRANK); R*AV(w);} + +A jtifb(J jt,I n,B*b){A z;I m,*zv; + m=bsum(n,b); + if(m==n)R IX(n); + GA(z,INT,m,1,0); zv=AV(z); +#if !SY_64 && SY_WIN32 + {I i,q=SZI*(n/SZI),*u=(I*)b; + for(i=0;i<q;i+=SZI)switch(*u++){ + case B0001: *zv++=i+3; break; + case B0010: *zv++=i+2; break; + case B0011: *zv++=i+2; *zv++=i+3; break; + case B0100: *zv++=i+1; break; + case B0101: *zv++=i+1; *zv++=i+3; break; + case B0110: *zv++=i+1; *zv++=i+2; break; + case B0111: *zv++=i+1; *zv++=i+2; *zv++=i+3; break; + case B1000: *zv++=i; break; + case B1001: *zv++=i; *zv++=i+3; break; + case B1010: *zv++=i; *zv++=i+2; break; + case B1011: *zv++=i; *zv++=i+2; *zv++=i+3; break; + case B1100: *zv++=i; *zv++=i+1; break; + case B1101: *zv++=i; *zv++=i+1; *zv++=i+3; break; + case B1110: *zv++=i; *zv++=i+1; *zv++=i+2; break; + case B1111: *zv++=i; *zv++=i+1; *zv++=i+2; *zv++=i+3; + } + b=(B*)u; DO(n%SZI, if(*b++)*zv++=q+i;); + } +#else + DO(n, if(b[i])*zv++=i;); +#endif + R z; +} /* integer vector from boolean mask */ + +F1(jtii){RZ(w); R IX(IC(w));} + +I jtmaxtype(J jt,I s,I t){I u; + u=s|t; + if(!(u&SPARSE))R u&CMPX?CMPX:u&FL?FL:s<t?t:s; + if(s){s=s&SPARSE?s:STYPE(s); ASSERT(s,EVDOMAIN);} + if(t){t=t&SPARSE?t:STYPE(t); ASSERT(t,EVDOMAIN);} + R s<t?t:s; +} + +void mvc(I m,void*z,I n,void*w){I p=n,r;static I k=sizeof(D); + MC(z,w,MIN(p,m)); while(m>p){r=m-p; MC(p+(C*)z,z,MIN(p,r)); p+=p;} +} + +/* // faster but on some compilers runs afoul of things that look like NaNs + // exponent bytes are silently changed by one bit +void mvc(I m,void*z,I n,void*w){I p=n,r;static I k=sizeof(D); + if(m<k||k<n||(I)z%k){MC(z,w,MIN(p,m)); while(m>p){r=m-p; MC(p+(C*)z,z,MIN(p,r)); p+=p;}} + else{C*e,*s;D d[7],d0,*v; + p=0==k%n?8:6==n?24:n*k; // p=lcm(k,n) + e=(C*)d; s=w; DO(p, *e++=s[i%n];); + v=(D*)z; d0=*d; + switch(p){ + case 8: DO(m/p, *v++=d0;); break; + case 24: DO(m/p, *v++=d0; *v++=d[1]; *v++=d[2];); break; + case 40: DO(m/p, *v++=d0; *v++=d[1]; *v++=d[2]; *v++=d[3]; *v++=d[4];); break; + case 56: DO(m/p, *v++=d0; *v++=d[1]; *v++=d[2]; *v++=d[3]; *v++=d[4]; *v++=d[5]; *v++=d[6];); + } + if(r=m%p){s=(C*)v; e=(C*)d; DO(r, *s++=e[i];);} +}} +*/ + +A jtodom(J jt,I r,I n,I*s){A q,z;I j,k,m,*u,*zv; + RE(m=prod(n,s)); k=n*SZI; + GA(z,INT,m*n,2==r?2:n,s); zv=AV(z)-n; + if(2==r){u=AS(z); u[0]=m; u[1]=n;} + if(!(m&&n))R z; + if(1==n)DO(m, *++zv=i;) + else{ + GA(q,INT,n,1,0); u=AV(q); memset(u,C0,k); u[n-1]=-1; + DO(m, ++u[j=n-1]; DO(n, if(u[j]<s[j])break; u[j]=0; ++u[--j];); MC(zv+=n,u,k);); + } + R z; +} + +F1(jtrankle){R!w||AR(w)?w:ravel(w);} + +A jtsc(J jt,I k) {A z; GA(z,INT, 1,0,0); *IAV(z)=k; R z;} +A jtsc4(J jt,I t,I v){A z; GA(z,t, 1,0,0); *IAV(z)=v; R z;} +A jtscb(J jt,B b) {A z; GA(z,B01, 1,0,0); *BAV(z)=b; R z;} +A jtscc(J jt,C c) {A z; GA(z,LIT, 1,0,0); *CAV(z)=c; R z;} +A jtscf(J jt,D x) {A z; GA(z,FL, 1,0,0); *DAV(z)=x; R z;} +A jtscx(J jt,X x) {A z; GA(z,XNUM,1,0,0); *XAV(z)=ca(x); R z;} + +A jtstr(J jt,I n,C*s){A z; GA(z,LIT,n,1,0); MC(AV(z),s,n); R z;} + +F1(jtstr0){A z;C*x;I n; RZ(w); n=AN(w); GA(z,LIT,1+n,1,0); x=CAV(z); MC(x,AV(w),n); x[n]=0; R z;} + +A jtv2(J jt,I a,I b){A z;I*x; GA(z,INT,2,1,0); x=AV(z); *x++=a; *x=b; R z;} + +A jtvci(J jt,I k){A z; GA(z,INT,1,1,0); *IAV(z)=k; R z;} + +A jtvec(J jt,I t,I n,void*v){A z; GA(z,t,n,1,0); MC(AV(z),v,n*bp(t)); R z;} + +F1(jtvi){RZ(w); R INT&AT(w)?w:cvt(INT,w);} + +F1(jtvib){A z;D d,e,*wv;I i,n,*old,p=-IMAX,q=IMAX,*zv; + RZ(w); + old=jt->rank; jt->rank=0; + if(AT(w)&SPARSE)RZ(w=denseit(w)); + switch(AT(w)){ + case INT: z=w; break; + case B01: z=cvt(INT,w); break; + case XNUM: + case RAT: z=cvt(INT,maximum(sc(p),minimum(sc(q),w))); break; + default: + if(!(AT(w)&FL))RZ(w=cvt(FL,w)); + n=AN(w); wv=DAV(w); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + for(i=0;i<n;++i){ + d=wv[i]; e=jfloor(d); + if (d==inf ) zv[i]=q; + else if(d==infm) zv[i]=p; + else if( FEQ(d,e))zv[i]=d<p?p:q<d?q:(I)e; + else if(++e,FEQ(d,e))zv[i]=d<p?p:q<d?q:(I)e; + else ASSERT(0,EVDOMAIN); + }} + jt->rank=old; R z; +} + +F1(jtvip){I*v; RZ(w); if(!(INT&AT(w)))RZ(w=cvt(INT,w)); v=AV(w); DO(AN(w), ASSERT(0<=*v++,EVDOMAIN);); R w;} + +F1(jtvs){RZ(w); ASSERT(1>=AR(w),EVRANK); R LIT&AT(w)?w:cvt(LIT,w);} + /* verify string */
new file mode 100644 --- /dev/null +++ b/v.c @@ -0,0 +1,119 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs */ + +#include "j.h" + + +F1(jttally ){A z; RZ(w); z=sc(IC(w)); R AT(w)&XNUM+RAT?xco1(z):z;} +F1(jtshapex){A z; RZ(w); z=vec(INT,AR(w),AS(w)); R AT(w)&XNUM+RAT?xco1(z):z;} +F1(jtshape ){RZ(w); R vec(INT,AR(w),AS(w));} + +F1(jtravel){A a,c,q,x,y,y0,z;B*b,d;I f,j,m,n,r,*u,*v,wr,*ws,wt,*yv;P*wp,*zp; + RZ(w); + n=AN(w); ws=AS(w); wt=AT(w); d=!(wt&SPARSE); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + RE(m=prod(r,f+ws)); + GA(z,wt,d?n:1,1+f,ws); *(f+AS(z))=m; + if(d){MC(AV(z),AV(w),n*bp(wt)); R RELOCATE(w,z);} + wp=PAV(w); zp=PAV(z); + RZ(b=bfi(wr,SPA(wp,a),1)); + if(memchr(b+f,C1,r)){ + if(memchr(b+f,C0,r)){memset(b+f,C1,r); RZ(w=reaxis(ifb(wr,b),w)); wp=PAV(w); x=SPA(wp,x);} + else RZ(x=ca(SPA(wp,x))); + RZ(a=ifb(1+f,b)); + GA(c,INT,r,1L,0L); v=r+AV(c); j=wr; m=1; DO(r, *--v=m; m*=ws[--j];); + y0=SPA(wp,i); v=AS(y0); m=v[0]; n=v[1]; + RZ(q=pdt(dropr(n-r,y0),c)); + GA(y,INT,m*(1+n-r),2,0); v=AS(y); v[0]=m; v[1]=1+n-r; + yv=AV(y); u=AV(y0); v=AV(q); j=n-r; + DO(m, ICPY(yv,u,j); yv[j]=*v++; yv+=1+j; u+=n;); + }else{RZ(a=ca(SPA(wp,a))); RZ(x=irs1(SPA(wp,x),0L,r,jtravel)); RZ(y=ca(SPA(wp,i)));} + SPB(zp,a,a); + SPB(zp,e,ca(SPA(wp,e))); + SPB(zp,x,x); + SPB(zp,i,y); + R z; +} + +F1(jttable){A z;I f,r,*s,wr,*ws,wt; + RZ(w); + wt=AT(w); ws=AS(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + if(wt&SPARSE){z=irs1(w,0L,r?r-1:0,jtravel); R r?z:irs1(z,0L,0L,jtravel);} + GA(z,wt,AN(w),2+f,ws); s=f+AS(z); + if(r)*(1+s)=prod(r-1,1+f+ws); else *s=*(1+s)=1; + MC(AV(z),AV(w),AN(w)*bp(wt)); + R RELOCATE(w,z); +} + +static A jtlr2(J jt,B left,A a,A w){A z;C*v;I acr,af,ar,*as,c,f,k,n,r,*s,t, + wcr,wf,wr,*ws,zn; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; as=AS(a); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; ws=AS(w); + if(left){if(af>=wf)R rat(a); r=acr; s=af+as; t=AT(a); v=CAV(a); n=AN(a);} + else {if(wf>=af)R rat(w); r=wcr; s=wf+ws; t=AT(w); v=CAV(w); n=AN(w);} + RE(c=af?prod(f=af,as):prod(f=wf,ws)); RE(zn=mult(c,prod(r,s))); + GA(z,t,zn,f+r,af?as:ws); ICPY(f+AS(z),s,r); + k=bp(t); mvc(k*zn,AV(z),k*n,v); + R z; +} + +F2(jtleft2 ){R lr2(1,a,w);} +F2(jtright2){R lr2(0,a,w);} + +F1(jtright1){R rat(w);} + +F1(jtiota){A z;I m,n,*v; + F1RANK(1,jtiota,0); + if(AT(w)&XNUM+RAT)R cvt(XNUM,iota(vi(w))); + RZ(w=vi(w)); n=AN(w); v=AV(w); + if(1==n){m=*v; R 0>m?apv(-m,-m-1,-1L):IX(m);} + RE(m=prod(n,v)); z=reshape(mag(w),IX(ABS(m))); + DO(n, if(0>v[i])z=irs1(z,0L,n-i,jtreverse);); + R z; +} + +F1(jtjico1){A y,z;B b;D d,*v;I c,m,n; + F1RANK(0,jtjico1,0); + RZ(y=cvt(FL,rect(w))); v=DAV(y); d=*v; + RE(m=v[1]?i0(cvt(INT,tail(y))):i0(tymes(mag(w),num[2]))); + ASSERT(0<m||!m&&0==d,EVDOMAIN); + n=(I)jfloor(d+0.1); b=FEQ(d,n); c=(2*ABS(n))/(m?m:1); + if(b&&m*c==2*ABS(n))z=apv(1+m,-n,0>d?-c:c); + else z=plus(scf(0>d?d:-d),tymes(scf(2*ABS(d)/m),apv(1+m,0>d?m:0L,0>d?-1L:1L))); + if(AT(w)&XNUM+RAT)z=cvt(AT(w)&XNUM||equ(w,floor1(w))?XNUM:RAT,z); + R z; +} + +DF1(jtnum1){RZ( w&&self); R VAV(self)->h;} +DF2(jtnum2){RZ(a&&w&&self); R VAV(self)->h;} + +F2(jtfromr ){R irs2(a,w,0L,RMAX,1L,jtfrom );} +F2(jtrepeatr){R irs2(a,w,0L,RMAX,1L,jtrepeat);} + +A jttaker(J jt,I n,A w){R irs2(sc(n),w,0L,RMAX,1L,jttake);} +A jtdropr(J jt,I n,A w){R irs2(sc(n),w,0L,RMAX,1L,jtdrop);} + +F1(jticap){A a,e;I n;P*p; + F1RANK(1,jticap,0); + n=IC(w); + if(SB01&AT(w)){ + p=PAV(w); a=SPA(p,a); e=SPA(p,e); + R *BAV(e)||equ(mtv,a) ? repeat(w,IX(n)) : repeat(SPA(p,x),ravel(SPA(p,i))); + } + R B01&AT(w) ? ifb(n,BAV(w)) : repeat(w,IX(n)); +} + +A jtcharmap(J jt,A w,A x,A y){A z;B bb[256];I k,n,wn;UC c,*u,*v,zz[256]; + RZ(w&&x&&y); + if(!(LIT&AT(w)))R from(indexof(x,w),y); + wn=AN(w); n=MIN(AN(x),AN(y)); u=n+UAV(x); v=n+UAV(y); + k=256; memset(bb,C0,256); if(n<AN(y))memset(zz,*(n+UAV(y)),256); + DO(n, c=*--u; zz[c]=*--v; if(!bb[c]){--k; bb[c]=1;}); + GA(z,LIT,wn,AR(w),AS(w)); v=UAV(z); u=UAV(w); + if(k&&n==AN(y))DO(wn, c=*u++; ASSERT(bb[c],EVINDEX); *v++=zz[c];) + else if(!bitwisecharamp(zz,wn,u,v))DO(wn, *v++=zz[*u++];); + R z; +} /* y {~ x i. w */
new file mode 100644 --- /dev/null +++ b/v0.c @@ -0,0 +1,312 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Polynomial Roots & Polynomial Evaluation */ + +#include "j.h" + + +#define EPS (jt->fuzz) + +#define dplus(x,y) (x+y) +#define dtymes(x,y) (x*y) +#define dnegate(x) (-x) +#define QNEGATE(x) (qminus(zeroQ,x)) + +#define CFR(f,T,xx,fplus,ftymes,fnegate) \ + F2(f){PROLOG;A z;I j,n;T d,*t,*u,*v; \ + n=AN(w); u=(T*)AV(w); \ + GA(z,xx,1+n,1,0); v=(T*)AV(z); *v=*(T*)AV(a); \ + for(j=0;j<n;++j){ \ + d=fnegate(u[j]); t=j+v; *(1+t)=*t; \ + DO(j, *t=fplus(*(t-1),ftymes(d,*t)); --t;); \ + *v=ftymes(d,*v); \ + } \ + RE(z); EPILOG(z); \ + } + +static CFR(jtcfrd,D,FL, dplus,dtymes,dnegate) +static CFR(jtcfrx,X,XNUM,xplus,xtymes, negate) +static CFR(jtcfrq,Q,RAT, qplus,qtymes,QNEGATE) + +static F1(jtrsort){A t,z;D d=jt->ct; + RZ(w); + jt->ct=jt->fuzz; + t=over(mag(w),cant1(rect(w))); + z=dgrade2(w,cant1(irs2(irs2(t,t,0L,1L,1L,jtindexof),t,0L,1L,1L,jtfrom))); + jt->ct=d; + R z; +} + +static F2(jtcfrz){A z;B b=0,p;I j,n;Z c,d,*t,*u,*v; + RZ(w=rsort(w)); + n=AN(w); u=ZAV(w); + GA(z,CMPX,1+n,1,0); v=ZAV(z); *v=c=*ZAV(a); p=!c.im; + for(j=0;j<n;++j){ + d=znegate(u[j]); t=j+v; *(1+t)=*t; + DO(j, *t=zplus(*(t-1),ztymes(d,*t)); --t;); + *v=ztymes(d,*v); + if(p&&d.im)if(b=!b)c=u[j]; else if(p=ZCJ(c,u[j])){t=v; DO(2+j, t++->im=0.0;);} + } + R p>b?cvt(FL,z):z; +} + +static F1(jtcfr){A c,r,*wv;I t,wd; + ASSERT(!AR(w)||2==AN(w),EVLENGTH); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + if(AR(w)){c=WVR(0); r=WVR(1);}else{c=one; r=WVR(0);} + ASSERT(!AR(c)&&1>=AR(r),EVRANK); + ASSERT(NUMERIC&AT(c)&&(!AN(r)||NUMERIC&AT(r)),EVDOMAIN); + t=AN(r)?AT(r):B01; if(t&B01+INT)t=XNUM; RE(t=maxtype(t,AT(c))); + if(t!=AT(c))RZ(c=cvt(t,c)); + if(t!=AT(r))RZ(r=cvt(t,r)); + R t&RAT?cfrq(c,r):t&XNUM?cfrx(c,r):t&CMPX?cfrz(c,r):cfrd(c,r); +} /* coefficients from roots */ + + +static D jtsummag(J jt,A w){A t=aslash(CPLUS,mag(w)); R t?*DAV(t):0.0;} + +/* a is a poly of degree m and x is a root estimate */ +/* improve root estimate x by applying Newton iteration n times */ +/* x - (a p. x) % (p.. a) p. x */ + +static Z jtnewt(J jt,I m,Z*a,Z x,I n){I i,j;D e=EPS/1024.0;Z c,p,q,*v; + c.im=0.0; + for(i=0;i<n;++i){ + p=q=zeroZ; v=a+m; j=m; + DO(m, p=zplus(*v,ztymes(x,p)); c.re=(D)j--; q=zplus(ztymes(c,*v),ztymes(x,q)); --v;); + p=zplus(*a,ztymes(x,p)); + if(e>zmag(p)||e>zmag(q))break; + x=zminus(x,zdiv(p,q)); + } + R x; +} + +static B jtdeflateq(J jt,B k,I m,Q*v,Q x){Q q,r,*u; + u=v+m; q=*u--; DO(m, r=*u--; q=qplus(r,qtymes(q,x));); + RE(0); RZ(QEQ(q,zeroQ)); + u=v+m; q=*u--; DO(m, r=*u; *u--=q; q=qplus(r,qtymes(q,x));); + R 1; +} /* deflate by x which may or may not be a root. result is 1 iff x is a root. k is ignored. */ + +static void jtdeflate(J jt,B k,I m,Z*v,Z x){ + if(k){Z q,r; v+=m; q=*v--; DO(m, r=*v; *v--=q; q=zplus(r,ztymes(q,x)););} + else{D a,b,d,p,q,r; + a=2*x.re; b=-(x.re*x.re+x.im*x.im); + v+=m; p=v--->re; q=v--->re; + DO(m-1, r=v->re; v->re=d=p; v->im=0.0; --v; p=q+d*a; q=r+d*b;); +}} /* deflate by single root (1=k) or by conjugates (0=k) */ + +static Z jtlaguerre(J jt,I m,Z*a,Z x){D ax,e;I i,j;Z b,c,d,g,g2,h,p,q,s,sq,y,zm,zm1; + zm=zrj0((D)m); zm1=zrj0((D)m-1); + for(i=0;;++i){ + ZASSERT(i<400,EVLIMIT); + c=d=zeroZ; b=a[m]; e=zmag(b); ax=zmag(x); + for(j=0;j<m;++j){ + d=zplus(ztymes(x,d),c); /* 2*d is 2nd derivative */ + c=zplus(ztymes(x,c),b); /* c is 1st derivative */ + b=zplus(ztymes(x,b),a[m-j-1]); /* b is poly at x */ + e=zmag(b)+ax*e; + } + if(zmag(b)<=EPS*e)R x; + g=zdiv(c,b); + g2=ztymes(g,g); + h=zminus(g2,zdiv(zplus(d,d),b)); + sq=zsqrt(ztymes(zm1,zminus(ztymes(zm,h),g2))); + p=zplus(g,sq); q=zminus(g,sq); s=zmag(p)>zmag(q)?p:q; + y=x; + x=ZNZ(s)?zminus(x,zdiv(zm,s)):zpow(znegate(zdiv(a[0],a[m])),zrj0(1.0/(D)m)); + if(zmag(zminus(x,y))<=EPS*zmag(x))R x; +}} /* Press et al., "Numerical Recipes in C" */ + +static Q jtmultiple(J jt,D x,Q m){A y;Q q1,q2,q1r2; + q1r2.n=xone; q1r2.d=xplus(xone,xone); + QRE(y=cvt(RAT,scf(x))); + QRE(q1=qplus(q1r2,qtymes(m,*QAV(y)))); + QRE(q2.n=xdiv(q1.n,q1.d,XMFLR)); q2.d=xone; + R qdiv(q2,m); +} /* nearest multiple of m to x */ + +static Q jtmaxdenom(J jt,I n,Q*v){Q z;X*u,x,y; + u=1+(X*)v; x=*u; + DO(n-1, u+=2; y=*u; if(-1==xcompare(x,y))x=y;); + z.n=x; z.d=xone; R z; +} /* maximum denominator in rational vector v */ + +/* find all exact rational roots of a rational polynomial w; return: */ +/* *zz: list of what rational roots are found */ +/* *ww: list of complex coefficients of deflated polynomial */ + +static B jtrfcq(J jt,I m,A w,A*zz,A*ww){A q,x,y,z;B b;I i,j,wt;Q*qv,rdx,rq,*wv,*zv;Z r,*xv,*yv; + wt=AT(w); + ASSERTSYS(wt&B01+INT+FL+XNUM+RAT,"rfcq"); + if(!(wt&RAT))RZ(w=cvt(RAT,w)); wv=QAV(w); + rdx=maxdenom(1+m,wv); + RZ(x=cvt(CMPX,w)); xv=ZAV(x); + RZ(y=take(sc(1+m),x)); yv=ZAV(y); /* deflated complex poly */ + RZ(q=take(sc(1+m),w)); qv=QAV(q); /* deflated rational poly */ + GA(z,RAT,m,1,0); zv=QAV(z); /* exact rational roots */ + i=j=0; + while(i<m){ + r=laguerre(m,xv,laguerre(m-i,yv,zeroZ)); + if(jt->jerr){RESETERR; break;} + RE(rq=multiple(r.re,rdx)); + b=0; + while(deflateq(1,m-j,qv,rq)){*zv++=rq; ++j; b=1;} + if(!b){Q q1; /* more speculative methods */ + q1=rq; q1.n=xone; + rq=qplus (rq,q1); while(deflateq(1,m-j,qv,rq)){*zv++=rq; ++j; b=1;} + rq=qminus(rq,q1); while(deflateq(1,m-j,qv,rq)){*zv++=rq; ++j; b=1;} + } + if(b){AN(q)=*AS(q)=1+m-j; rdx=maxdenom(1+m-j,qv); RZ(y=cvt(CMPX,q)); yv=ZAV(y); i=j;} + else{D c,d; + c=ABS(r.re); d=ABS(r.im); if(d<EPS*c)r.im=0; if(c<EPS*d)r.re=0; + r=newt(m,xv,r,10L); b=!r.im||i==m-1; + deflate(b,m-i,yv,r); i+=2-b; + }} + AN(z)=*AS(z)=j; *zz=z; RZ(*ww=cvt(FL,q)); + R 1; +} /* roots from coefficients, degree m is 2 or more */ + +static A jtrfcz(J jt,I m,A w){A x,y,z;B bb=0,real;D c,d;I i;Z r,*xv,*yv,*zv; + real=CMPX!=AT(w); RZ(x=cvt(CMPX,w)); xv=ZAV(x); + GA(y,CMPX,1+m,1,0); yv=ZAV(y); MC(yv,xv,(1+m)*sizeof(Z)); + GA(z,CMPX, m,1,0); zv=ZAV(z); + if(2==m){Z a2,b,c,d,z2={2,0}; + a2=ztymes(z2,xv[2]); b=znegate(xv[1]); c=xv[0]; + d=zsqrt(zminus(ztymes(b,b),ztymes(z2,ztymes(a2,c)))); + r=zdiv(zplus (b,d),a2); zv[0]=newt(m,xv,r,10L); + r=zdiv(zminus(b,d),a2); zv[1]=newt(m,xv,r,10L); + }else{ + for(i=0;i<m;++i){ + r=laguerre(m,xv,laguerre(m-i,yv,zeroZ)); + if(jt->jerr){RESETERR; bb=1; break;} + if(real){c=ABS(r.im); d=ABS(r.re); if(c<EPS*d)r.im=0; else if(d<EPS*c)r.re=0;} + zv[i]=r=newt(m,xv,r,10L); + if(real&&r.im&&i<m-1){r.im=-r.im; zv[1+i]=r; deflate(0,m-i,yv,r); ++i;} + else deflate(1,m-i,yv,r); + } + if(bb){A x1;D*u; + if(real){RZ(x1=cvt(FL,vec(CMPX,1+m,xv))); u= DAV(x1)+m-1; if(*u)*u*=1+1e-12; else *u=1e-12;} + else {RZ(x1= vec(CMPX,1+m,xv) ); u=&(ZAV(x1)+m-1)->re; if(*u)*u*=1+1e-12; else *u=1e-12;} + RZ(z=rfcz(m,x1)); zv=ZAV(z); + DO(m, zv[i]=newt(m,xv,zv[i],10L);); + }} + if(real){B b=1; DO(m, if(zv[i].im){b=0; break;}); if(b)z=cvt(FL,z);} + R z; +} /* roots from coefficients, degree m is 2 or more */ + +static F1(jtrfc){A r,w1;I m=0,n,t; + n=AN(w); t=AT(w); + if(n){ + ASSERT(t&DENSE&&t&NUMERIC,EVDOMAIN); + RZ(r=jico2(ne(w,zero),one)); m=*AV(r)%n; + ASSERT(m||equ(zero,head(w)),EVDOMAIN); + } + switch(m){ + case 0: R link(zero,mtv); + case 1: r=ravel(negate(aslash(CDIV,take(num[2],w)))); break; + default: if(t&CMPX)r=rfcz(m,w); + else{RZ(rfcq(m,w,&r,&w1)); if(m>AN(r))r=over(r,rfcz(m-AN(r),w1));} + } + R link(from(sc(m),w),rsort(r)); +} + +F1(jtpoly1){A c,e,x; + F1RANK(1L,jtpoly1,0L); + if(!(AN(w)&&BOX&AT(w)))R rfc(w); + x=AAV0(w); + if(1<AN(w)||1>=AR(x))R cfr(w); + ASSERT(2==AR(x),EVRANK); + ASSERT(2==*(1+AS(x)),EVLENGTH); + RZ(c=irs1(x,0L,1L,jthead)); + RZ(e=irs1(x,0L,1L,jttail)); + ASSERT(equ(e,floor1(e))&&all1(le(zero,e)),EVDOMAIN); + R evc(c,e,"x y}(1+>./y)$0"); +} + + +static A jtmnomx(J jt,I m,A w){A s,*wv,x,z=w,*zv;I i,n,r,wd; + RZ(w); + if(BOX&AT(w)){ + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); RZ(s=sc(m)); + GA(z,BOX,n,AR(w),AS(w)); zv=AAV(z); + for(i=0;i<n;++i){ + x=WVR(i); r=AR(x); + ASSERT(1>=r,EVRANK); + ASSERT(!r||m==AN(x),EVLENGTH); + zv[i]=1<m==1<r?x:1<m?reshape(s,x):head(x); + } + RE(z); RZ(z=ope(z)); + } + ASSERT(NUMERIC&AT(z),EVDOMAIN); + R z; +} /* standardize multinomial right arg */ + +static F2(jtpoly2a){A c,e,x;I m; + RZ(a&&w); + m=*(1+AS(a))-1; + ASSERT(AT(a)&NUMERIC,EVDOMAIN); + ASSERT(2==AR(a),EVRANK); + ASSERT(0<m,EVLENGTH); + RZ(c= irs1(a,0L,1L,jthead ) ); + RZ(e=cant1(irs1(a,0L,1L,jtbehead))); + RZ(x=mnomx(m,w)); + R 1==m?pdt(irs2(x,ravel(e),0L,0L,2L,jtexpn2),c):pdt(df2(x,e,dot(slash(ds(CSTAR)),ds(CEXP))),c); +} /* multinomial: (<c,.e0,.e1,.e2) p. <x0,x1,x2, left argument opened */ + +F2(jtpoly2){A c,z;B b;D*ad,d,p,*wd,x,*zd;I an,at,j,t,wn,wt;Z*az,e,q,*wz,y,*zz; + RZ(a&&w); + if(1<AR(a))R rank2ex(a,w,0L,1L,0L,jtpoly2); + an=AN(a); at=AT(a); b=1&&BOX&at; + wn=AN(w); wt=AT(w); + ASSERT(!an||at&NUMERIC+BOX,EVDOMAIN); + ASSERT(!wn||wt&NUMERIC+BOX,EVDOMAIN); + if(!an)R reshape(shape(w),zero); + if(b){A*av=AAV(a);I ad=(I)a*ARELATIVE(a); + ASSERT(2>=an,EVLENGTH); + c=1==an?one:AVR(0); a=AVR(1!=an); + if(1==an&&2==AR(a))R poly2a(a,w); + an=AN(a); at=AT(a); + ASSERT(NUMERIC&(at|AT(c)),EVDOMAIN); + ASSERT(!AR(c),EVRANK); + ASSERT(1>=AR(a),EVRANK); if(!AR(a))RZ(a=ravel(a)); + } + d=0.0; e=zeroZ; + RE(t=maxtype(at,wt)); if(b)RE(t=maxtype(t,AT(c))); if(!(t&XNUM+RAT))RE(t=maxtype(t,FL)); + if(b){RZ(c=cvt(t,c)); d=*DAV(c); e=*ZAV(c);} + if(t!=at)RZ(a=cvt(t,a)); ad=DAV(a); az=ZAV(a); + if(t!=wt)RZ(w=cvt(t,w)); wd=DAV(w); wz=ZAV(w); + j=0; + if(t&FL+CMPX){ + DO(t&FL?an:an+an, x=ad[i]; if(x==inf||x==infm){j=1; break;}); + if(!j)DO(t&FL?wn:wn+wn, x=wd[i]; if(x==inf||x==infm){j=1; break;}); + } + if(!j&&!(t&XNUM+RAT)){GA(z,t,AN(w),AR(w),AS(w)); zd=DAV(z); zz=ZAV(z);} + switch((b?0:3)+(j||t&XNUM+RAT?0:t&FL?1:2)){ + case 0: R tymes(c,df2(negate(a),w,eval("*/@(+/)"))); + case 1: DO(wn, p=d; x=*wd++; DO(an,p*=x-ad[i];); *zd++=p;); break; + case 2: DO(wn, q=e; y=*wz++; DO(an,q=ztymes(q,zminus(y,az[i]));); *zz++=q;); break; + case 3: R df2(w,a,eval("(^/i.@#) +/ .* ]")); + case 4: DO(wn, p=d; x=*wd++; j=an; DO(an,p=ad[--j]+x*p;); *zd++=p;); break; + case 5: DO(wn, q=e; y=*wz++; j=an; DO(an,q=zplus(az[--j],ztymes(y,q));); *zz++=q;); + } + R z; +} /* a p. w */ + + +F1(jtpderiv1){ + F1RANK(1,jtpderiv1,0); + if(AN(w)&&!(NUMERIC&AT(w)))RZ(w=poly1(w)); + R 1>=AN(w) ? apv(1L,0L,0L) : tymes(behead(w),apv(AN(w)-1,1L,1L)); +} /* p.. w */ + +F2(jtpderiv2){ + F2RANK(0,1,jtpderiv2,0); + if(!(NUMERIC&AT(w)))RZ(w=poly1(w)); + ASSERT(NUMERIC&AT(a),EVDOMAIN); + R over(a,divide(w,apv(AN(w),1L,1L))); +} /* a p.. w */ + + +
new file mode 100644 --- /dev/null +++ b/v1.c @@ -0,0 +1,154 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Match Associates */ + +#include "j.h" + + +static B jtmatchsub(J,I,I,I,I,A,A,B*,B,B); +static F2(jtmatchs); + +#define MCS(q,af,wf) ((1<q?16:q?8:0)+(af?2:0)+(wf?1:0)) +#define QLOOP b=b1; DO(q, if(u[i]!=v[i]){b=b0; break;}); *x++=b; +#define EQV(T) \ + {T h,*u=(T*)av,*v=(T*)wv; \ + q=k/sizeof(T); \ + switch(MCS(q,af,wf)){ \ + case MCS(1,0,0): *x++=*u ==*v?b1:b0; break; \ + case MCS(1,0,1): h=*u; if(b1)DO(mn, *x++=h ==*v++;) else DO(mn, *x++=h !=*v++;) break; \ + case MCS(1,1,0): h=*v; if(b1)DO(mn, *x++=*u++==h; ) else DO(mn, *x++=*u++!=h; ); break; \ + case MCS(1,1,1): if(b1){ \ + if(1==n) DO(m, *x++=*u++==*v++; ) \ + else if(af<wf)DO(m, h=*u++; DO(n, *x++=h ==*v++;);) \ + else DO(m, h=*v++; DO(n, *x++=*u++==h; );); \ + }else{ \ + if(1==n) DO(m, *x++=*u++!=*v++; ) \ + else if(af<wf)DO(m, h=*u++; DO(n, *x++=h !=*v++;);) \ + else DO(m, h=*v++; DO(n, *x++=*u++!=h; );); \ + } break; \ + case MCS(2,0,0): QLOOP; break; \ + case MCS(2,0,1): DO(mn, QLOOP; v+=q;); break; \ + case MCS(2,1,0): DO(mn, QLOOP; u+=q; ); break; \ + case MCS(2,1,1): if(1==n) DO(m, QLOOP; u+=q; v+=q;) \ + else if(af<wf)DO(m, DO(n, QLOOP; v+=q;); u+=q;) \ + else DO(m, DO(n, QLOOP; u+=q;); v+=q;); break; \ + }} + +static B eqv(I af,I wf,I m,I n,I k,C*av,C*wv,B*x,B b0,B b1){B b,*xx=x;I c,d,mn=m*n,q; + if (0==k%sizeof(I) )EQV(I) +#if SY_64 + else if(0==k%sizeof(int))EQV(int) +#endif + else if(0==k%sizeof(S) )EQV(S) + else if(1==k) EQV(C) + else{ + c=af?k:0; d=wf?k:0; + if(1==n) DO(m, *x++=memcmp(av,wv,k)?b0:b1; av+=c; wv+=d;) + else if(af<wf)DO(m, DO(n, *x++=memcmp(av,wv,k)?b0:b1; wv+=k;); av+=k;) + else DO(m, DO(n, *x++=memcmp(av,wv,k)?b0:b1; av+=k;); wv+=k;); + } + R mn?xx[mn-1]:b1; +} /* what memcmp should have been */ + +B jtequ(J jt,A a,A w){A x;B b; + RZ(a&&w); + if(a==w)R 1; + if(SPARSE&(AT(a)|AT(w))&&AR(a)&&AR(w)){RZ(x=matchs(a,w)); R*BAV(x);} + R level(a)==level(w)&&matchsub(0L,0L,1L,1L,a,w,&b,C0,C1); +} + +static B jteqf(J jt,A a,A w){A p,q;B b;V*u=VAV(a),*v=VAV(w); + if(!(AT(a)==AT(w)&&u->id==v->id))R 0; + p=u->f; q=v->f; if(!(!p&&!q||p&&q&&matchsub(0L,0L,1L,1L,p,q,&b,C0,C1)))R 0; + p=u->g; q=v->g; if(!(!p&&!q||p&&q&&matchsub(0L,0L,1L,1L,p,q,&b,C0,C1)))R 0; + p=u->h; q=v->h; R !p&&!q||p&&q&&matchsub(0L,0L,1L,1L,p,q,&b,C0,C1); +} + +#define EQA(a,w) matchsub(0L,0L,1L,1L,a,w,&b,C0,C1) +#define EQQ(a,w) (equ(a.n,w.n)&&equ(a.d,w.d)) + +#define INNERT(T,f) \ + {T*u=(T*)av,*v=(T*)wv; \ + if(1==n) DO(m, x[j]=b1; DO(c, if(!f(u[i],v[i])){x[j]=b0; break;}); u+=p; v+=q; ++j; ) \ + else if(af>wf)DO(m, DO(n, x[j]=b1; DO(c, if(!f(u[i],v[i])){x[j]=b0; break;}); u+=p; ++j;); v+=q;) \ + else DO(m, DO(n, x[j]=b1; DO(c, if(!f(u[i],v[i])){x[j]=b0; break;}); v+=q; ++j;); u+=p;) \ + } + +#define INNERT2(aa,ww,f) \ + {A1*u=(A1*)av,*v=(A1*)wv; \ + if(1==n) DO(m, x[j]=b1; DO(c, if(!f((A)AABS(u[i],aa),(A)AABS(v[i],ww))){x[j]=b0; break;}); u+=p; v+=q; ++j; ) \ + else if(af>wf)DO(m, DO(n, x[j]=b1; DO(c, if(!f((A)AABS(u[i],aa),(A)AABS(v[i],ww))){x[j]=b0; break;}); u+=p; ++j;); v+=q;) \ + else DO(m, DO(n, x[j]=b1; DO(c, if(!f((A)AABS(u[i],aa),(A)AABS(v[i],ww))){x[j]=b0; break;}); v+=q; ++j;); u+=p;) \ + } + +static B jtmatchsub(J jt,I af,I wf,I m,I n,A a,A w,B*x,B b0,B b1){B b,c0;C*av,*wv;I at,c,j=0,mn,p,q,t,wt; + p=AR(a)-af; at=AT(a); mn=m&&n?m*n:0; + q=AR(w)-wf; wt=AT(w); RE(t=maxtype(at,wt)); c0=!jt->ct&&t&FL+CMPX; + c=(af>wf?AN(a):AN(w))/(mn?mn:1); b=p!=q||ICMP(af+AS(a),wf+AS(w),p)||c&&!HOMO(at,wt); + if(b||!c||a==w){memset(x,b?b0:b1,mn); R b?b0:b1;} + if(t&FUNC)R eqf(a,w)?b1:b0; + if(t!=at)RZ(a=t&XNUM?xcvt(XMEXMT,a):cvt(t,a)) else if(c0)RZ(a=cvt0(a)); + if(t!=wt)RZ(w=t&XNUM?xcvt(XMEXMT,w):cvt(t,w)) else if(c0)RZ(w=cvt0(w)); + p=af?c:0; av=CAV(a); + q=wf?c:0; wv=CAV(w); + switch(c0?0:t){ + default: R eqv(af,wf,m,n,c*bp(t),av,wv,x,b0,b1); + case FL: INNERT(D,teq); R mn?x[mn-1]:b1; + case CMPX: INNERT(Z,zeq); R mn?x[mn-1]:b1; + case XNUM: INNERT(X,equ); R mn?x[mn-1]:b1; + case RAT: INNERT(Q,EQQ); R mn?x[mn-1]:b1; + case BOX: switch(2*ARELATIVE(a)+ARELATIVE(w)){ + default: INNERT(A,EQA); R mn?x[mn-1]:b1; + case 1: INNERT2(0,w,EQA); R mn?x[mn-1]:b1; + case 2: INNERT2(a,0,EQA); R mn?x[mn-1]:b1; + case 3: INNERT2(a,w,EQA); R mn?x[mn-1]:b1; +}}} + +static F2(jtmatchs){A ae,ax,p,q,we,wx,x;B*b,*pv,*qv;D d;I acr,an=0,ar,c,j,k,m,n,r,*s,*v,wcr,wn=0,wr;P*ap,*wp; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; r=ar; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; jt->rank=0; + if(ar>acr||wr>wcr)R rank2ex(a,w,0L,acr,wcr,jtmatchs); + if(ar!=wr||memcmp(AS(a),AS(w),r*SZI)||!HOMO(AT(a),AT(w)))R zero; + GA(x,B01,r,1L,0L); b=BAV(x); memset(b,C0,r); + if(SPARSE&AT(a)){ap=PAV(a); x=SPA(ap,a); v=AV(x); an=AN(x); DO(an, b[v[i]]=1;);} + if(SPARSE&AT(w)){wp=PAV(w); x=SPA(wp,a); v=AV(x); wn=AN(x); DO(wn, b[v[i]]=1;);} + c=0; DO(r, c+=b[i];); + if(an<c||DENSE&AT(a))RZ(a=reaxis(ifb(r,b),a)); ap=PAV(a); ae=SPA(ap,e); ax=SPA(ap,x); m=*AS(ax); + if(wn<c||DENSE&AT(w))RZ(w=reaxis(ifb(r,b),w)); wp=PAV(w); we=SPA(wp,e); wx=SPA(wp,x); n=*AS(wx); + RZ(x=indexof(SPA(ap,i),SPA(wp,i))); v=AV(x); + GA(p,B01,m,1,0); pv=BAV(p); + GA(q,B01,n,1,0); qv=BAV(q); + memset(pv,C1,m); DO(n, j=*v++; if(j<m)pv[j]=qv[i]=0; else qv[i]=1;); + if(memchr(pv,C1,m)&&!all1(eq(we,repeat(p,ax))))R zero; + if(memchr(qv,C1,n)&&!all1(eq(ae,repeat(q,wx))))R zero; + j=0; DO(m, if(pv[i])++j;); + k=0; DO(n, if(qv[i])++k; qv[i]=!qv[i];); + if(!equ(from(repeat(q,x),ax),repeat(q,wx)))R zero; + x=SPA(ap,a); v=AV(x); s=AS(a); d=1.0; DO(AN(x), d*=s[v[i]];); + R d==m+k&&d==n+j||equ(ae,we)?one:zero; +} /* a -:"r w on sparse arrays */ + + +F2(jtmatch){A z;I af,f,m,n,*s,wf; + RZ(a&&w); + if(SPARSE&(AT(a)|AT(w)))R matchs(a,w); + af=jt->rank?AR(a)-jt->rank[0]:0; + wf=jt->rank?AR(w)-jt->rank[1]:0; jt->rank=0; + if(af>wf){f=af; s=AS(a); RE(m=prod(wf,s)); RE(n=prod(af-wf,wf+s));} + else {f=wf; s=AS(w); RE(m=prod(af,s)); RE(n=prod(wf-af,af+s));} + GA(z,B01,m*n,f,s); matchsub(af,wf,m,n,a,w,BAV(z),C0,C1); + R z; +} /* a -:"r w */ + +F2(jtnotmatch){A z;I af,f,m,n,*s,wf; + RZ(a&&w); + if(SPARSE&(AT(a)|AT(w)))R not(matchs(a,w)); + af=jt->rank?AR(a)-jt->rank[0]:0; + wf=jt->rank?AR(w)-jt->rank[1]:0; jt->rank=0; + if(af>wf){f=af; s=AS(a); RE(m=prod(wf,s)); RE(n=prod(af-wf,wf+s));} + else {f=wf; s=AS(w); RE(m=prod(af,s)); RE(n=prod(wf-af,af+s));} + GA(z,B01,m*n,f,s); matchsub(af,wf,m,n,a,w,BAV(z),C1,C0); + R z; +} /* a -.@-:"r w */
new file mode 100644 --- /dev/null +++ b/v2.c @@ -0,0 +1,716 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Primes and Factoring */ + +#include "j.h" + + +#define MM 25000L /* interval size to look for primes */ +#define PMAX 105097564L /* upper limit of p: ; (_1+2^31) = p: PMAX */ +#define PT 500000L /* interval size in ptt */ + +static A p4792=0; /* p: i.4792 */ + +static I ptt[]={ + 7368791L, 15485867L, 23879539L, 32452867L, 41161751L, + 49979693L, 58886033L, 67867979L, 76918277L, 86028157L, + 95189093L, 104395303L, 113648413L, 122949829L, 132276713L, + 141650963L, 151048973L, 160481219L, 169941223L, 179424691L, /* 10e6 */ + 188943817L, 198491329L, 208055047L, 217645199L, 227254213L, + 236887699L, 246534487L, 256203221L, 265892021L, 275604547L, + 285335587L, 295075153L, 304836293L, 314606891L, 324407131L, + 334214467L, 344032391L, 353868019L, 363720403L, 373587911L, /* 20e6 */ + 383446691L, 393342743L, 403245719L, 413158523L, 423087253L, + 433024253L, 442967117L, 452930477L, 462900953L, 472882049L, + 482873137L, 492876863L, 502895647L, 512927377L, 522960533L, + 533000401L, 543052501L, 553105253L, 563178743L, 573259433L, /* 30e6 */ + 583345003L, 593441861L, 603538541L, 613651369L, 623781269L, + 633910111L, 644047709L, 654188429L, 664338817L, 674506111L, + 684681301L, 694847539L, 705031199L, 715225741L, 725420411L, + 735632797L, 745843009L, 756065179L, 766301759L, 776531419L, /* 40e6 */ + 786760649L, 797003437L, 807247109L, 817504253L, 827772511L, + 838041647L, 848321921L, 858599509L, 868891399L, 879190841L, + 889495223L, 899809363L, 910112683L, 920419823L, 930754037L, + 941083987L, 951421147L, 961748941L, 972092467L, 982451707L, /* 50e6 */ + 992801861L, 1003162837L, 1013526181L, 1023893887L, 1034271001L, + 1044645419L, 1055040229L, 1065433427L, 1075824283L, 1086218501L, + 1096621151L, 1107029839L, 1117444369L, 1127870683L, 1138305547L, + 1148739817L, 1159168537L, 1169604841L, 1180041943L, 1190494771L, /* 60e6 */ + 1200949609L, 1211405387L, 1221863261L, 1232332813L, 1242809783L, + 1253270833L, 1263751141L, 1274224999L, 1284710771L, 1295202523L, + 1305698249L, 1316196209L, 1326697579L, 1337195527L, 1347701867L, + 1358208613L, 1368724913L, 1379256029L, 1389786323L, 1400305369L, /* 70e6 */ + 1410844907L, 1421376533L, 1431916091L, 1442469313L, 1453010737L, + 1463555011L, 1474118929L, 1484670179L, 1495213271L, 1505776963L, + 1516351777L, 1526922017L, 1537493917L, 1548074371L, 1558655507L, + 1569250363L, 1579833509L, 1590425983L, 1601020433L, 1611623887L, /* 80e6 */ + 1622223991L, 1632828059L, 1643429663L, 1654054511L, 1664674819L, + 1675293223L, 1685912299L, 1696528907L, 1707155683L, 1717783153L, + 1728417367L, 1739062387L, 1749701927L, 1760341447L, 1770989611L, + 1781636627L, 1792287229L, 1802933621L, 1813593029L, 1824261419L, /* 90e6 */ + 1834925117L, 1845587717L, 1856264467L, 1866941123L, 1877619461L, + 1888303063L, 1898979371L, 1909662913L, 1920354661L, 1931045239L, + 1941743653L, 1952429177L, 1963130473L, 1973828669L, 1984525423L, + 1995230821L, 2005933283L, 2016634099L, 2027354369L, 2038074751L, /* 100e6 */ + 2048795527L, 2059519673L, 2070248617L, 2080975187L, 2091702673L, + 2102429887L, 2113154951L, 2123895979L, 2134651583L, 2145390539L, +}; /* p: PT*1+i.210 */ + +static I ptn=sizeof(ptt)/SZI; + +static I jtsup(J jt,I n,I*wv){I c,d,j,k; + c=0; DO(n, j=wv[i]; ASSERT(0<=j,EVDOMAIN); if(c<j)c=j;); + ASSERT(c<=PMAX,EVLIMIT); + j=1; k=0; DO(128, if(c<=j)break; j+=j; ++k;); d=c*k; + R k&&c>d?IMAX:MAX(d,135L); +} /* (_1+2^31) <. 135 >. (*>.@(2&^.)) >./ w */ + +static void sieve(I n,I m,B*b,B*u){I i,j,q; + static B t[]={ + 0,1,0,0,0, 0,0,1,0,0, 0,1,0,1,0, 0,0,1,0,1, 0,0,0,1,0, 0,0,0,0,1, + 0,1,0,0,0, 0,0,1,0,0, 0,1,0,1,0, 0,0,1,0,1, 0,0,0,1,0, 0,0,0,0,1}; + mvc(m,b,30L,t+n%30); if(!n)b[1]=0; q=1+(I)sqrt(n+(D)m); + if(n)for(i=7;i<q;i+=2){if(u[i]){j=n%i; j=j?i-j:0; while(j<m){b[j]=0; j+=i;}}} + else for(i=7;i<q;i+=2){if(b[i]){j=i+i; while(j<m){b[j]=0; j+=i;}}} +} /* sieve b for n+i.m, but if 0=n then b=. 0 (2 3 5)}b */ + +static F1(jtprime1){A d,t,y,z;B*b,*u;I c,*dv,e,i,j,k,m,n,p,q,*wv,x,*zv; + RZ(w); + k=0; n=AN(w); wv=AV(w); RE(m=sup(n,wv)); jt->rank=0; JBREAK0; + GA(z,INT,n,AR(w),AS(w)); zv= AV(z); + RZ(d=grade1(ravel(w))); dv= AV(d); + if(p4792){I*u=AV(p4792); c=AN(p4792); while(n>k&&c>(x=wv[dv[k]]))zv[dv[k++]]=u[x];} + else{ + while(n>k&&0==wv[dv[k]])zv[dv[k++]]=2; + while(n>k&&1==wv[dv[k]])zv[dv[k++]]=3; + while(n>k&&2==wv[dv[k]])zv[dv[k++]]=5; + } + if(n==k)R z; + j=3; p=0; e=PT; q=1+(I)sqrt((D)m); x=wv[dv[k]]; + GA(t,B01,q,1,0); u=BAV(t); sieve(0L,q,u,u); + GA(y,B01,MIN(m,MM),1,0); b=BAV(y); + for(;0<=p&&p<m;p+=q){ + if(x>=e){c=x/PT; e=PT*(1+c); c=MIN(c,ptn); if(j<c*PT){j=c*PT; p=ptt[c-1];}} + JBREAK0; q=MIN(MM,m-p); sieve(p,q,b,u); c=j+q/3; + if(x>c)for(i=1-p%2;i<q;i+=2)j+=b[i]; + else for(i=1-p%2;i<q;i+=2) + if(b[i]){while(j==x){zv[dv[k++]]=i+p; if(n==k)R z; x=wv[dv[k]];} ++j;} + } + while(n>k)zv[dv[k++]]=p; R z; +} + +static I rem(D x,I d){R (I)floor(x-d*floor(x/(D)d));} + +static void sieved(D n,I m,B*b){I c,d,e,i,q,r,*u,*v; + static B t[]={ + 0,1,0,0,0, 0,0,1,0,0, 0,1,0,1,0, 0,0,1,0,1, 0,0,0,1,0, 0,0,0,0,1, + 0,1,0,0,0, 0,0,1,0,0, 0,1,0,1,0, 0,0,1,0,1, 0,0,0,1,0, 0,0,0,0,1}; + static I dt[]={1,7,11,13,17,19,23,29}; + c=2*3*5; v=dt+sizeof(dt)/SZI; q=1+(I)sqrt(n+(D)m); + mvc(m,b,30L,t+rem(n,30L)); + for(i=c;i<q;i+=c){ + u=dt; + while(u<v){ + d=i+*u++; r=rem(n,d); e=r?d-r:0; + while(d<m){b[e]=0; e+=d;} + }} +} /* sieve b for n+i.m; n>0; u is mask for primes */ + +static F1(jtprime1d){A d,z;D*wv,x,*zv;I*dv,k,n; + RZ(w); + n=AN(w); wv=DAV(w); + GA(z,FL,n,AR(w),AS(w)); zv=DAV(z); + RZ(d=grade1(ravel(w))); dv=AV(d); + k=0; while(n>k&&(D)PMAX>=wv[dv[k]])++k; + if(k){A y;I*yv; + RZ(y=prime1(cvt(INT,from(take(sc(k),d),ravel(w))))); yv=AV(y); + DO(k, zv[dv[i]]=(D)*yv++;); + } + if(k==n)R z; + DO(n-k, x=wv[dv[i]]; ASSERT(0<=x&&x!=inf,EVDOMAIN);); + ASSERT(0,EVLIMIT); +} + +F1(jtprime){PROLOG;A z;B b=1;I n,p,q,t; + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + n=AN(w); t=AT(w); + if(!(t&INT))RZ(w=pcvt(INT,w)); + if(INT&AT(w)){ + irange(n,AV(w),&p,&q); + if(0<q&&PMAX>=p+q-1){b=0; RZ(z=prime1(w));} + } + if(b)RZ(z=prime1d(FL&AT(w)?w:cvt(FL,w))); + if(t&XNUM+RAT)RZ(z=cvt(XNUM,z)); + EPILOG(z); +} /* p:"r w */ + +static I jtsuq(J jt,I n,I*wv){I c=24; DO(n, c=MAX(c,wv[i]);); R c==0x7fffffff?c:1+c;} + /* 1+24>.>./w */ + +F1(jtplt){PROLOG;A d,t,y,z;B*b,*u,xt;I c,*dv,e,i,j,k,m,n,p,q,*wv,x,*zv; + RZ(w); + xt=1&&AT(w)&XNUM+RAT; + if(!(INT&AT(w)))RZ(w=vi(ceil1(w))); wv=AV(w); JBREAK0; + j=3; k=p=c=0; e=*ptt; n=AN(w); + RE(m=suq(n,wv)); ASSERT(m<=0x7fffffff,EVLIMIT); q=1+(I)sqrt((D)m); + GA(t,B01,q,1,0); u =BAV(t); sieve(0L,q,u,u); + GA(y,B01,MIN(m,MM),1,0); b =BAV(y); + GA(z,INT,n,AR(w),AS(w)); zv= AV(z); + RZ(d=grade1(ravel(w))); dv= AV(d); + while(n>k&&2>=wv[dv[k]])zv[dv[k++]]=0; + while(n>k&&3>=wv[dv[k]])zv[dv[k++]]=1; + while(n>k&&5>=wv[dv[k]])zv[dv[k++]]=2; + if(n==k)EPILOG(z); x=wv[dv[k]]; + for(;0<=p&&p<m;p+=q){ + if(x>=e){ + while(ptn>c&&x>=ptt[c])++c; + if(j<c*PT){p=ptt[c-1]; e=c<ptn?ptt[c]:IMAX; j=c*PT;} + } + JBREAK0; q=MIN(MM,m-p); sieve(p,q,b,u); + if(x>p+q) + for(i=1-p%2;i<q;i+=2)j+=b[i]; + else + for(i=1-p%2;i<q;i+=2)if(b[i]){ + while(x<=p+i){zv[dv[k++]]=j; if(n==k){i=q; break;} x=wv[dv[k]];} + ++j; + }} + while(n>k)zv[dv[k++]]=j; + if(xt)RZ(z=cvt(XNUM,z)); + EPILOG(z); +} /* p:^:_1 w, the number of primes less than w */ + + +static B jtxprimeq(J,I,X); +static F1(jtxprimetest); + +static B pmsk[]={0,0,1,1,0,1,0,1,0,0, 0,1,0,1,0,0,0,1,0,1, 0,0,0,1,0,0,0,0,0,1, 0,1}; + /* indicates which i<32 is prime */ + +static F1(jtiprimetest){A z;B*b;I d,j,n,*pv,q,*v,wn,*wv; + RZ(w); + wn=AN(w); wv=AV(w); pv=AV(p4792); +#if SY_64 + DO(wn, if(2147483647L<wv[i])R xprimetest(cvt(XNUM,w));); +#endif + GA(z,B01,wn,AR(w),AS(w)); b=BAV(z); + for(j=0;j<wn;++j){ + n=*wv++; v=pv; + if(32>n)b[j]=pmsk[MAX(0,n)]; + else{b[j]=1; DO(AN(p4792), d=*v++; q=n/d; if(n==q*d){b[j]=0; break;}else if(q<d)break;);} + } + R z; +} + +static F1(jtxprimetest){A z;B*b,rat;I d,j,q,n,old,*pv,*v,wn,wt,*yv;X r,*wv,x,xmaxint,y; + RZ(w); + wn=AN(w); wt=AT(w); wv=XAV(w); pv=AV(p4792); + rat=1&&wt&RAT; RZ(xmaxint=xc(2147483647L)); RZ(y=xc(-1L)); yv=AV(y); + GA(z,B01,wn,AR(w),AS(w)); b=BAV(z); + for(j=0;j<wn;++j){ + x=*wv++; d=*(AV(x)+AN(x)-1); b[j]=1; v=pv; + if(rat&&xcompare(xone,*wv++)){b[j]=0; continue;} + ASSERT(d!=XPINF&&d!=XNINF,EVDOMAIN); + if(0>=d)b[j]=0; + else if(1==xcompare(x,xmaxint)){ + old=jt->tbase+jt->ttop; + DO(100, *yv=*v++; RZ(r=xrem(y,x)); if(!*AV(r)){b[j]=0; break;}); + if(b[j])RE(b[j]=xprimeq(100L,x)); + tpop(old); + }else{ + n=xint(x); v=pv; + if(32>n)b[j]=pmsk[MAX(0,n)]; + else DO(AN(p4792), d=*v++; q=n/d; if(n==q*d){b[j]=0; break;}else if(q<d)break;); + }} + R z; +} /* prime test for extended integers or rationals */ + +static F1(jtprimetest){A x;D oct;I t; + RZ(w); + t=AT(w); + if(!AN(w)||t&B01)R reshape(shape(w),zero); + switch(t){ + default: ASSERT(0,EVDOMAIN); + case INT: R iprimetest(w); + case RAT: case XNUM: R xprimetest(w); + case FL: case CMPX: + oct=jt->ct; jt->ct=jt->fuzz; x=eq(t&FL?w:conjug(w),floor1(w)); jt->ct=oct; + R xprimetest(cvt(XNUM,tymes(w,x))); +}} /* primality test */ + + +static F1(jtnextprime){A b,fs,x,y;B*bv;I k,n,*xv,*yv;X*wv; + RZ(w); + n=AN(w); + if(!n||B01&AT(w))R reshape(shape(w),num[2]); + ASSERT(NUMERIC&AT(w),EVDOMAIN); + RZ(fs=eval("2&+^:(0&p:)^:_")); + GA(x,INT,n,AR(w),AS(w)); xv=AV(x); + if(INT&AT(w)){B b=1;I*wv=AV(w); + DO(n, k=*wv++; if(k==IMAX){b=0; break;}else *xv++=2>k?2:k+1+(k%2);); + if(b)R rank1ex(x,fs,0L,VAV(fs)->f1); + RZ(w=cvt(XNUM,w)); + } + if(AT(w)&FL+RAT)RZ(w=cvt(XNUM,floor1( w ))); + if(AT(w)&CMPX )RZ(w=cvt(XNUM,floor1(cvt(FL,w)))); + GA(b,B01,n,AR(w),AS(w)); bv=BAV(b); wv=XAV(w); + DO(n, y=*wv++; yv=AV(y); *bv++=0<yv[AN(y)-1]; *xv++=*yv%2?2:1;); + R rank1ex(tymes(b,plus(w,x)),fs,0L,VAV(fs)->f1); +} + +static F1(jtprevprime){A fs,x,y;I k,m,n,*xv,*yv;X*wv; + RZ(w); + n=AN(w); + ASSERT(!n||NUMERIC&AT(w)&&!(B01&AT(w)),EVDOMAIN); + RZ(fs=eval("_2&+^:(0&p:)^:_")); + GA(x,INT,n,AR(w),AS(w)); xv=AV(x); + if(INT&AT(w)){I*wv=AV(w); + DO(n, k=*wv++; ASSERT(2<k,EVDOMAIN); *xv++=3==k?2:k-(1+k%2);); + R rank1ex(x,fs,0L,VAV(fs)->f1); + } + if(AT(w)&FL+RAT)RZ(w=cvt(XNUM,ceil1( w ))); + if(AT(w)&CMPX )RZ(w=cvt(XNUM,ceil1(cvt(FL,w)))); + wv=XAV(w); + DO(n, y=*wv++; yv=AV(y); m=AN(y); k=*yv; ASSERT(0<yv[m-1]&&(1<m||2<k),EVDOMAIN); *xv++=1==m&&3==k?1:1+k%2;); + R rank1ex(minus(w,x),fs,0L,VAV(fs)->f1); +} + +static F1(jttotient){A b,x,z;B*bv,p=0;I k,n,t; + RZ(w); + n=AN(w); t=AT(w); + if(t&B01)R ca(w); + GA(b,B01,n,AR(w),AS(w)); bv=BAV(b); + if(t&INT){I*wv=AV(w),*xv; + GA(x,INT,n,AR(w),AS(w)); xv=AV(x); + DO(n, k=*wv++; ASSERT(0<=k,EVDOMAIN); if(k){*bv++=1; *xv++=k;}else{*bv++=0; *xv++=1; p=1;};); + }else{X*xv,y; + RZ(x=cvt(XNUM,w)); xv=XAV(x); + DO(n, y=xv[i]; k=*(AV(y)+AN(y)-1); ASSERT(0<=k,EVDOMAIN); if(k)*bv++=1; else{*bv++=0; xv[i]=xone; p=1;}); + } + z=cvt(AT(x),df1(x,eval("(- ~:)&.q:"))); + R p?tymes(b,z):z; +} + +/* +MillerRabin=: 100&$: : (4 : 0) " 0 + if. 0=2|y do. 2=y return. end. + if. 74>y do. y e. i.&.(p:^:_1) 74 return. end. + e=. huo y-1 + for_a. x witnesses y do. if. (+./c=y-1) +: 1={:c=. a y&|@^ e do. 0 return. end. end. + 1 +) +*/ + +static B jtspspd(J jt,I b,I n,I d,I h){D a,n1,nn,x; + if(b==n)R 1; + a=1; x=(D)b; nn=(D)n; n1=(D)n-1; + while(d){if(1&d)a=fmod(a*x,nn); x=fmod(x*x,nn); d>>=1;} + if(a==1||a==n1)R 1; + DO(h-1, a=fmod(a*a,nn); if(a==n1)R 1;); + R 0; +} + +static B jtspspx(J jt,I b,I n,I d,I h){I ai,n1;X a,ox,xn; + if(b==n)R 1; + n1=n-1; + ox=jt->xmod; jt->xmod=cvt(XNUM,sc(n)); a=xpow(xc(b),xc(d)); jt->xmod=ox; + ai=xint(a); + if(ai==1||ai==n1)R 1; + xn=xc(n); + DO(h-1, a=xrem(xn,xtymes(a,a)); if(xint(a)==n1)R 1;); + R 0; +} + +static F1(jtdetmr){A z;B*zv;I d,h,i,n,wn,*wv; + RZ(w=vi(w)); + wn=AN(w); wv=AV(w); + GA(z,B01,wn,AR(w),AS(w)); zv=BAV(z); + for(i=0;i<wn;++i){ + n=*wv++; + if(1>=n||!(1&n)||0==n%3||0==n%5){*zv++=0; continue;} + h=0; d=n-1; while(!(1&d)){++h; d>>=1;} + if (n< 9080191)*zv++=spspd(31,n,d,h)&&spspd(73,n,d,h); + else if(n<94906266)*zv++=spspd(2 ,n,d,h)&&spspd( 7,n,d,h)&&spspd(61,n,d,h); + else *zv++=spspx(2 ,n,d,h)&&spspx( 7,n,d,h)&&spspx(61,n,d,h); + } + RE(0); R z; +} /* deterministic Miller-Rabin */ + +F2(jtpco2){A z;B*b;I k; + RZ(a&&w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + RE(k=i0(a)); + switch(k){ + default: ASSERT(0,EVDOMAIN); + case -4: R prevprime(w); + case -1: R plt(w); + case 0: RZ(z=primetest(w)); b=BAV(z); DO(AN(z), *b=!*b; ++b;); R z; + case 1: R primetest(w); + case 2: R qco2(scf(infm),w); + case 3: R factor(w); + case 4: R nextprime(w); + case 5: R totient(w); + case 6: R detmr(w); +}} /* a p: w */ + +static A jtqco2x(J jt,I m,A w){A y;I c,*dv,i,*pv,*yv;X d,q,r,x; + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + if(!(XNUM&AT(w)))RZ(w=cvt(XNUM,w)); + x=*XAV(w); pv=AV(p4792); RZ(d=xc(2L)); dv=AV(d); + GA(y,INT,m,1,0); yv=AV(y); memset(yv,C0,m*SZI); + for(i=0;i<m;++i){ + c=0; *dv=pv[i]; + while(1){RZ(xdivrem(x,d,&q,&r)); if(*AV(r))break; ++c; x=q;} + yv[i]=c; if(1==AN(x)&&1==*AV(x))break; + } + R cvt(XNUM,y); +} /* m q: w where 0<:m and p: m is one xdigit and w is a single extended integer */ + +F2(jtqco2){A q,y,z;B b,bb,xt;I c,j,k,m,*qv,wn,wr,*yv,*zv; + RZ(a&&w); + wn=AN(w); wr=AR(w); b=all1(lt(a,zero)); xt=1&&AT(w)&XNUM+RAT; + if(AR(a)||wr&&(b||xt))R rank2ex(a,w,0L,0L,0L,jtqco2); + if(!b&&xt){RE(m=i0(vib(a))); if(0<=m&&m<1229)R qco2x(m,w);} /* 1229=p:^:_1 XBASE */ + RZ(q=factor(w)); qv=AV(q); + if(b)RZ(a=negate(a)); + bb=equ(a,ainf); + if(b&bb){ /* __ q: w */ + RZ(y=ne(q,curtail(over(zero,q)))); + R lamin2(repeat(y,q),df1(y,cut(ds(CPOUND),one))); + } + RZ(y=vi(plt(q))); yv=AV(y); + k=-1; DO(AN(y), if(k<yv[i])k=yv[i];); ++k; + if(bb)m=k; else RE(m=i0(a)); + if(b){ + q=repeat(ge(y,sc(k-m)),q); + R lamin2(nub(q),df2(q,q,sldot(ds(CPOUND)))); + }else{ + GA(z,INT,wn*m,1+wr,AS(w)); *(AS(z)+wr)=m; zv=AV(z); + memset(zv,C0,AN(z)*SZI); + j=0; c=*(AS(q)+wr); DO(wn, DO(c, if(qv[j]&&m>yv[j])++zv[yv[j]]; ++j;); zv+=m;); + R AT(w)&XNUM+RAT?cvt(XNUM,z):z; +}} /* a q: w for array w */ + +static F1(jtxfactor); + +F1(jtfactor){PROLOG;A y,z;I c,d,i,k,m,n,q,*u,*v,wn,*wv,*zv; + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + if(AT(w)&XNUM+RAT)R xfactor(w); + if(AT(w)&FL+CMPX){ + RZ(y=pcvt(INT,w)); + if(INT&AT(y))w=y; + else{RZ(y=pcvt(XNUM,xco1(w))); ASSERT(XNUM&AT(y),EVDOMAIN); R pcvt(INT,xfactor(y));} + } + RZ(w=vi(w)); + wn=AN(w); wv=AV(w); + n=0; DO(wn, k=wv[i]; ASSERT(0<k,EVDOMAIN); n=MAX(n,k);); +#if SY_64 + if(n>2147483647)R cvt(INT,xfactor(w)); +#endif + u=AV(p4792); c=8*SZI-2; + GA(z,INT,c*wn,1+AR(w),AS(w)); *(AS(z)+AR(w))=c; v=zv=AV(z); + for(i=m=0;i<wn;++i){ + n=*wv++; + DO(AN(p4792), d=u[i]; q=n/d; while(n==q*d){*v++=d; n=q; q/=d;} if(q<d)break;); + if(1<n)*v++=n; + d=v-zv; m=MAX(m,d); zv+=c; while(v<zv)*v++=0; + } + EPILOG(c==m?z:taker(m,z)); +} /* q:"r w */ + + +/* + http://ww2.lafayette.edu/~reiterc/j/vector/factor_ecj.html + Elliptic curve arithmetic and factorization. + factor_ecj.ijs + Cliff Reiter + June 2003 + + Elliptic curves are E=.a,b where (y^2)=(x^3)+(a*x)+b + Moduli are n where n-:0 corresponds to rational arithmetic +*/ + +static B jtsmallprimes(J jt,I n,X x,A*zs,X*zx){A s;I i,m,old,*pv,*sv,*v;X d,q,r; + ASSERT(n<=1229&&n<=AN(p4792),EVLIMIT); + pv=AV(p4792); m=(I)(3.322*XBASEN*AN(x)); + GA(s,INT,m,1,0); v=sv=AV(s); + old=jt->tbase+jt->ttop; + for(i=0;i<n;++i){ + RZ(d=xc(pv[i])); + RZ(xdivrem(x,d,&q,&r)); /* d must have only one "digit" */ + while(!xcompare(r,xzero)){*v++=pv[i]; x=q; RZ(xdivrem(q,d,&q,&r));} + if(-1==xcompare(q,d))break; + gc(x,old); + } + if(1>xcompare(x,xc(99460729L))&&!(1==AN(x)&&1==XDIG(x))){*v++=xint(x); x=xone;} + AN(s)=*AS(s)=v-sv; + RZ(*zs=cvt(XNUM,s)); *zx=x; + R 1; +} /* remove small prime factors */ + +/* if 0=n xprimeq y, then y is certainly composite; and */ +/* if 1=n xprimeq y, then y is prime with a probability of error of 0.25^n */ + +static B jtxprimeq(J jt,I n,X y){A h,om=jt->xmod;B b;I*dv,i,k,old,*pv;X d,m,t,x,y1; + ASSERT(n<=AN(p4792),EVLIMIT); + pv=AV(p4792); + GA(h,XNUM,1,0,0); *XAV(h)=y; jt->xmod=h; + k=0; RZ(t=xc(2L)); RZ(m=y1=xminus(y,xone)); + while(0==*AV(m)%2){++k; RZ(m=xdiv(m,t,XMFLR));} + GA(d,INT,1,1,0); dv=AV(d); + old=jt->tbase+jt->ttop; + for(i=0;i<n;++i){ + *dv=pv[i]; RZ(x=xpow(d,m)); b=1==AN(x)&&1==*AV(x); + DO(k*!b, if(!xcompare(x,y1)){b=1; break;} RZ(x=xrem(y,xsq(x)));); + tpop(old); + if(!b)break; + } + jt->xmod=om; R b; +} /* y assumed to be not in n{.p4792 */ + +static XF1(jtpollard_p_1){A om=jt->xmod;D p,m;I e,i,n,old,*pv;X c,g,z=xone; + n=MIN(1229,AN(p4792)); pv=AV(p4792); m=log((D)pv[n-1]); + RZ(c=xc(2L)); + RZ(jt->xmod=scx(w)); + old=jt->tbase+jt->ttop; + for(i=0;i<n;++i){ + p=(D)pv[i]; e=(I)pow(p,jfloor(m/log(p))); + RZ(c=xpow(c,sc(e))); + RZ(g=xgcd(w,xminus(c,xone))); + if(!equ(g,xone)&&!equ(g,w)){z=g; break;} + gc(c,old); + } + jt->xmod=om; + R z; +} + +static XF1(jtpollard_rho){I i,n,old=jt->tbase+jt->ttop;X g,y1,y2; + n=10000; + RZ(y1=y2=xc(2L)); + for(i=0;i<n;++i){ + RZ(y1=xrem(w,xplus(xone,xsq(y1)))); + RZ(y2=xrem(w,xplus(xone,xsq(xplus(xone,xsq(y2)))))); + RZ(g=xgcd(w,xrem(w,xminus(y2,y1)))); + if(!equ(g,xone)&&!equ(g,w))R g; + gc3(y1,y2,0L,old); + } + R xone; +} + +static B jtranec(J jt,X w,X*zg,X*za,X*zb,X*zx,X*zy){A mm,t;I*tv;X a,aa,b,bb,g,x,y; + g=w; RZ(mm=reshape(sc(3L),sc(IMAX))); + while(!xcompare(g,w)){ + RZ(t=roll(mm)); tv=AV(t); + RZ(x=xc(tv[0])); + RZ(y=xc(tv[1])); + RZ(a=xc(tv[2])); + RZ(b=xrem(w,xminus(xsq(y),xtymes(x,xplus(a,xsq(x)))))); + RZ(aa=xtymes(xc( 4L),xtymes(a,xsq(a)))); + RZ(bb=xtymes(xc(27L), xsq(b) )); + RZ(g=xgcd(w,xplus(aa,bb))); + } + *zg=g; *za=a; *zb=b; *zx=x; *zy=y; + R 1; +} /* random elliptic curve */ + +static A jtdb1b2(J jt,I n,X w){A t,z;D c,d,lg,n1=(D)n-1,p,r;I m,s[2],*v,*zv; + s[0]=n; s[1]=2; GA(z,INT,2*n,2,s); zv=v=AV(z); + RZ(t=cvt(FL,scx(w))); d=*DAV(t); + lg=log(d); c=log(sqrt(d)); r=exp(sqrt(0.5)+sqrt(c*log(c)))/lg; + DO(n, c=lg*pow(r,i/n1); p=c*log(c); if(p>=2147483647)break; *v++=(I)jfloor(c); *v++=(I)p;); + m=(v-zv)/2; ASSERT(m,EVLIMIT); + *AS(z)=m; AN(z)=2*m; + R z; +} + +static B jtecd(J jt,X n,X a,X b,X*q,X*z){I old=jt->tbase+jt->ttop;X m,s,x2,y2,yy,z2; + if(0==xcompare(q[1],xzero)||0==xcompare(q[2],xzero)){z[0]=xzero; z[1]=xone; z[2]=xzero;} + else{ + RZ(m=xplus(xtymes(xc(3L),xsq(q[0])),xtymes(a,xsq(xsq(q[2]))))); + RZ(yy=xsq(q[1])); + RZ(s=xtymes(xc(4L),xtymes(q[0],yy))); + RZ(x2=xplus(xsq(m),xtymes(xc(-2L),s))); + RZ(y2=xplus(xtymes(m,xminus(s,x2)),xtymes(xc(-8L),xsq(yy)))); + RZ(z2=xtymes(xc(2L),xtymes(q[1],q[2]))); + RZ(z[0]=xrem(n,x2)); RZ(z[1]=xrem(n,y2)); RZ(z[2]=xrem(n,z2)); + } + gc3(z[0],z[1],z[2],old); + R 1; +} /* elliptic curve double point (mod proj coord) */ + +static B jteca(J jt,X n,X a,X b,X*p,X*q,X*z){I old=jt->tbase+jt->ttop; + if (0==xcompare(p[2],xzero)){z[0]=q[0]; z[1]=q[1]; z[2]=q[2];} + else if(0==xcompare(q[2],xzero)){z[0]=p[0]; z[1]=p[1]; z[2]=p[2];} + else{X m,r,s1,s2,t,t1,t2,u1,u2,w,w2,x3,y3,z12,z22,z3; + RZ(u1=xtymes(q[0],z12=xsq(p[2]))); RZ(s1=xtymes(q[1],xtymes(p[2],z12))); + RZ(u2=xtymes(p[0],z22=xsq(q[2]))); RZ(s2=xtymes(p[1],xtymes(q[2],z22))); + RZ(w=xminus(u1,u2)); + if(0==xcompare(w,xzero))RZ(ecd(n,a,b,p,z)) + else{ + RZ(r=xminus(s1,s2)); + RZ(t=xplus(u1,u2)); + RZ(m=xplus(s1,s2)); + RZ(w2=xsq(w)); + RZ(x3=xminus(xsq(r),xtymes(t,w2))); + RZ(t1=xtymes(r,xplus(xtymes(xc(-2L),x3),xtymes(t,w2)))); + RZ(t2=xtymes(m,xtymes(w,w2))); + RZ(y3=xdiv(xminus(t1,t2),xc(2L),XMFLR)); + RZ(z3=xtymes(p[2],xtymes(q[2],w))); + RZ(z[0]=xrem(n,x3)); RZ(z[1]=xrem(n,y3)); RZ(z[2]=xrem(n,z3)); + }} + gc3(z[0],z[1],z[2],old); + R 1; +} /* elliptic curve add (mod proj coord) */ + +#if SY_64 +#define BIT0 0x8000000000000000 +#else +#define BIT0 0x80000000 +#endif + +static B jtecm(J jt,X n,X a,X b,I m,X*p,X*z){I old=jt->tbase+jt->ttop; + if(0==m){z[0]=xzero; z[1]=xone; z[2]=xzero;} + else{I k;UI c,d;X pm[3],q[3]; + q[0]=p[0]; q[1]=p[1]; q[2]=p[2]; + pm[0]=p[0]; RZ(pm[1]=xminus(xzero,p[1])); pm[2]=p[2]; + c=(3*m)>>1; d=m>>1; k=8*sizeof(I); + while(!(c&BIT0)){c<<=1; d<<=1; --k;} + c<<=1; d<<=1; --k; + DO(k, RZ(ecd(n,a,b,q,q)); if(BIT0&(c^d))RZ(eca(n,a,b,q,c&BIT0?p:pm,q)); c<<=1; d<<=1;); + z[0]=q[0]; z[1]=q[1]; z[2]=q[2]; + } + gc3(z[0],z[1],z[2],old); + R 1; +} /* scalar mult ladder (mod proj coord) */ + +static B jtecm_s1(J jt,X n,X a,X b,I b1,X*q,X*z){A tt;D d,lg;I dd,m,old=jt->tbase+jt->ttop,*pv;X x[3]; + lg=log((D)b1); RE(m=i0(plt(sc(b1)))); + if(m<=AN(p4792))pv=AV(p4792); else{RZ(tt=prime1(IX(m))); pv=AV(tt);} + x[0]=q[0]; x[1]=q[1]; x[2]=q[2]; + DO(m, d=(D)*pv++; dd=(I)pow(d,jfloor(5e-14+lg/log(d))); RZ(ecm(n,a,b,dd,x,x));); + z[0]=x[0]; z[1]=x[1]; z[2]=x[2]; + gc3(z[0],z[1],z[2],old); + R 1; +} + +static B jtecm_s2(J jt,X n,X a,X b,I b1,I b2,X*q,X*z){A sda,tt;I d,di,i,k,m,old,p0,*pd,*v;X*s1,*sd,*sd0,*sdd,*t,x[3]; + RZ(tt=plt(v2(b1,b2))); v=AV(tt); m=(v[1]-v[0])-1; + RZ(tt=prime1(apv(1+m,v[0],1L))); pd=v=AV(tt); p0=*v; + d=0; DO(m, v[0]=k=-1+(v[1]-v[0])/2; ++v; d=MAX(d,k);); d=MIN(100,1+d); + GA(sda,XNUM,3*d,2,0); sd0=sd=XAV(sda); v=AS(sda); v[0]=d; v[1]=3; + RZ(ecd(n,a,b,q,sd)); s1=t=sd; sd+=3; + DO(d-1, eca(n,a,b,s1,t,sd); t=sd; sd+=3;); sd=sd0; sdd=t; + RZ(ecm(n,a,b,p0,q,x)); + old=jt->tbase+jt->ttop; + for(i=0;i<m;++i){ + di=pd[i]; + DO(di/d, RZ(eca(n,a,b,x,sdd,x));); + RZ(eca(n,a,b,x,sd+3*(di%d),x)); + gc3(x[0],x[1],x[2],old); + } + z[0]=x[0]; z[1]=x[1]; z[2]=x[2]; + R 1; +} + +static XF1(jtfac_ecm){A tt;I b1,b2,*b1b2,i,old,m;X a,b,g,q[3]; + RZ(tt=db1b2(20L,w)); m=IC(tt); b1b2=AV(tt); + old=jt->tbase+jt->ttop; + for(i=0;i<m;++i){ + b1=b1b2[0]; b2=b1b2[1]; b1b2+=2; + ranec(w,&g,&a,&b,q,q+1); q[2]=xone; + if(xcompare(g,xone)&&xcompare(g,w))R g; + RZ(ecm_s1(w,a,b,b1,q,q)); + RZ(g=xgcd(w,q[2])); + if(xcompare(g,xone)&&xcompare(g,w))R g; + if(0==xcompare(g,xone)){ + RZ(ecm_s2(w,a,b,b1,b2,q,q)); + RZ(g=xgcd(w,q[2])); + if(xcompare(g,xone)&&xcompare(g,w))R g; + } + tpop(old); + } + R xone; +} + +static F1(jtxfactor){PROLOG;A z;B b=0;I m;X g,x; + F1RANK(0,jtxfactor,0); + if(!(XNUM&AT(w)))RZ(w=cvt(XNUM,w)); + x=*XAV(w); m=XDIG(x); + ASSERT(m!=XPINF&&m!=XNINF&&0<m,EVDOMAIN); + if(1>xcompare(x,xc(2147483647L)))R xco1(factor(sc(xint(x)))); + RZ(smallprimes(1229L,x,&z,&x)); + while(1==xcompare(x,xc(2147483647L))){ + if(xprimeq(100L,x)){RZ(z=over(z,scx(x))); x=xone; break;} + RZ(g=pollard_p_1(x)); if(g!=xone){RZ(z=over(z,scx(g))); RZ(x=xdiv(x,g,XMFLR)); continue;} + RZ(g=pollard_rho(x)); if(g!=xone){RZ(z=over(z,scx(g))); RZ(x=xdiv(x,g,XMFLR)); continue;} + if(!b){b=1; RZ(rngseeds(sc(jt->rngS[jt->rng]))); RZ(roll(v2(m,m*m)));} + RZ(g=fac_ecm(x)); if(g!=xone){RZ(z=over(z,scx(g))); RZ(x=xdiv(x,g,XMFLR)); continue;} + ASSERT(0,EVNONCE); + } + if(1==xcompare(x,xone))RZ(z=over(z,factor(sc(xint(x))))); + EPILOG(grade2(z,z)); +} + +/* ---------------------------------------------------- */ + +F1(test_ecm){A*wv,z;I wd;X*ab,n,*zv; + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + ASSERT(4==AN(w),EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(XNUM&AT(WVR(0)),EVDOMAIN); ASSERT(1==AR(WVR(0)),EVRANK); ASSERT(2==AN(WVR(0)),EVLENGTH); + ASSERT(XNUM&AT(WVR(1)),EVDOMAIN); ASSERT(0==AR(WVR(1)),EVRANK); + ASSERT(INT&AT(WVR(2)),EVDOMAIN); + ASSERT(XNUM&AT(WVR(3)),EVDOMAIN); + n=*XAV(WVR(1)); + ab=XAV(WVR(0)); + GA(z,XNUM,3,1,0); zv=XAV(z); + RZ(ecm(n,ab[0],ab[1],i0(WVR(2)),XAV(WVR(3)),zv)); + R z; +} + +F1(test_ecm_s1){A*wv,z;I wd;X*ab,n,*zv; + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + ASSERT(4==AN(w),EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(XNUM&AT(WVR(0)),EVDOMAIN); ASSERT(1==AR(WVR(0)),EVRANK); ASSERT(2==AN(WVR(0)),EVLENGTH); + ASSERT(XNUM&AT(WVR(1)),EVDOMAIN); ASSERT(0==AR(WVR(1)),EVRANK); + ASSERT(INT&AT(WVR(2)),EVDOMAIN); + ASSERT(XNUM&AT(WVR(3)),EVDOMAIN); + n=*XAV(WVR(1)); + ab=XAV(WVR(0)); + GA(z,XNUM,3,1,0); zv=XAV(z); + RZ(ecm_s1(n,ab[0],ab[1],i0(WVR(2)),XAV(WVR(3)),zv)); + R z; +} + +F1(test_ecm_s2){A*wv,z;I*b1b2,wd;X*ab,n,*zv; + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + ASSERT(4==AN(w),EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + ASSERT(XNUM&AT(WVR(0)),EVDOMAIN); ASSERT(1==AR(WVR(0)),EVRANK); ASSERT(2==AN(WVR(0)),EVLENGTH); + ASSERT(XNUM&AT(WVR(1)),EVDOMAIN); ASSERT(0==AR(WVR(1)),EVRANK); + ASSERT(INT &AT(WVR(2)),EVDOMAIN); ASSERT(1==AR(WVR(2)),EVRANK); ASSERT(2==AN(WVR(0)),EVLENGTH); + ASSERT(XNUM&AT(WVR(3)),EVDOMAIN); + n=*XAV(WVR(1)); + ab=XAV(WVR(0)); + b1b2=AV(WVR(2)); + GA(z,XNUM,3,1,0); zv=XAV(z); + RZ(ecm_s2(n,ab[0],ab[1],b1b2[0],b1b2[1],XAV(WVR(3)),zv)); + R z; +} + +F1(test_fac_ecm){ + RZ(w); + if(!p4792){RZ(p4792=prime1(IX(4792L))); ACX(p4792);} + ASSERT(!AR(w),EVRANK); + ASSERT(XNUM&AT(w),EVDOMAIN); + R scx(fac_ecm(*XAV(w))); +}
new file mode 100644 --- /dev/null +++ b/va.h @@ -0,0 +1,243 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Macros and Defined Constants for Atomic (Scalar) Verbs */ + +typedef struct {VF f;I cv;} VA2; +typedef struct {VA2 p2[13];VA2 pins[7];VA2 ppfx[7];VA2 psfx[7];} VA; +typedef struct {VA2 p1[6];} UA; + + /* cv - control vector */ +#define VBB (I)1 /* convert arguments to B */ +#define VII (I)2 /* convert arguments to I */ +#define VDD (I)4 /* convert arguments to D */ +#define VZZ (I)8 /* convert arguments to Z */ +#define VXX (I)16 /* convert arguments to XNUM */ +#define VQQ (I)32 /* convert arguments to RAT */ +#define VB (I)256 /* result type B */ +#define VI (I)512 /* result type I */ +#define VD (I)1024 /* result type D */ +#define VZ (I)2048 /* result type Z */ +#define VX (I)4096 /* result type XNUM */ +#define VQ (I)8192 /* result type RAT */ +#define VSB (I)16384 /* result type SBT */ +#define VRD (I)65536 /* convert result to D if possible */ +#define VRI (I)131072 /* convert result to I if possible */ +#define VXEQ (I)262144 /* convert to XNUM for = ~: */ +#define VXCF (I)524288 /* convert to XNUM ceiling/floor */ +#define VXFC (I)1048576 /* convert to XNUM floor/ceiling */ + +#if SY_64 +#define NOT(v) ((v)^0x0101010101010101) +#else +#define NOT(v) ((v)^0x01010101) +#endif + +#define SNOT(v) ((v)^0x0101) +#define INOT(v) ((v)^0x01010101) + +#define AND(u,v) ( u & v) +#define GT(u,v) ( u & ~v) +#define LT(u,v) (~u & v) +#define OR(u,v) ( u | v) +#define NE(u,v) ( u ^ v) +#define GE(u,v) NOT( LT(u,v)) +#define LE(u,v) NOT( GT(u,v)) +#define EQ(u,v) NOT( NE(u,v)) +#define NOR(u,v) NOT( OR(u,v)) +#define NAND(u,v) NOT(AND(u,v)) + +#define IAND AND +#define IGT GT +#define ILT LT +#define IOR OR +#define INE NE +#define IGE(u,v) INOT(ILT(u,v)) +#define ILE(u,v) INOT(IGT(u,v)) +#define IEQ(u,v) INOT(INE(u,v)) +#define INOR(u,v) INOT(IOR(u,v)) +#define INAND(u,v) INOT(IAND(u,v)) + +#define SAND AND +#define SGT GT +#define SLT LT +#define SOR OR +#define SNE NE +#define SGE(u,v) SNOT(ILT(u,v)) +#define SLE(u,v) SNOT(IGT(u,v)) +#define SEQ(u,v) SNOT(INE(u,v)) +#define SNOR(u,v) SNOT(IOR(u,v)) +#define SNAND(u,v) SNOT(IAND(u,v)) + +#define BAND(u,v) (u && v) +#define BGT(u,v) (u > v) +#define BLT(u,v) (u < v) +#define BOR(u,v) (u || v) +#define BNE(u,v) (u != v) +#define BGE(u,v) (u >= v) +#define BLE(u,v) (u <= v) +#define BEQ(u,v) (u == v) +#define BNOR(u,v) (!(u||v)) +#define BNAND(u,v) (!(u&&v)) + +#define PLUS(u,v) ((u)+ (v)) +#define PLUSO(u,v) ((u)+(D)(v)) +#define MINUS(u,v) ((u)- (v)) +#define MINUSO(u,v) ((u)-(D)(v)) +#define TYMES(u,v) ((u)&&(v)?(u)* (v):0) +#define TYMESO(u,v) ((u)&&(v)?(u)*(D)(v):0) +#define DIV(u,v) ((u)||(v)?(u)/(v):0) + +#define SBORDER(v) (SBUV(v)->order) + +#define SBLT(u,v) (SBORDER(u)< SBORDER(v)) +#define SBLE(u,v) (SBORDER(u)<=SBORDER(v)) +#define SBGT(u,v) (SBORDER(u)> SBORDER(v)) +#define SBGE(u,v) (SBORDER(u)>=SBORDER(v)) + +#define SBMIN(u,v) (SBORDER(u)<=SBORDER(v)?(u):(v)) +#define SBMAX(u,v) (SBORDER(u)>=SBORDER(v)?(u):(v)) + +#define BOV(exp) if(exp){er=EWOV; break;} + +#define BW0000(x,y) (0) +#define BW0001(x,y) ( (x)& (y) ) +#define BW0010(x,y) ( (x)&~(y) ) +#define BW0011(x,y) (x) + +#define BW0100(x,y) ( ~(x)& (y) ) +#define BW0101(x,y) (y) +#define BW0110(x,y) ( (x)^ (y) ) +#define BW0111(x,y) ( (x)| (y) ) + +#define BW1000(x,y) (~( (x)| (y))) +#define BW1001(x,y) (~( (x)^ (y))) +#define BW1010(x,y) ( ~(y) ) +#define BW1011(x,y) ( (x)|~(y) ) + +#define BW1100(x,y) ( ~(x) ) +#define BW1101(x,y) ( ~(x)| (y) ) +#define BW1110(x,y) (~( (x)& (y))) +#define BW1111(x,y) (-1) + +#define AHDR1(f,Tz,Tx) void f(J jt, I n,Tz*z,Tx*x) +#define AHDR2(f,Tz,Tx,Ty) void f(J jt,B b,I m, I n,Tz*z,Tx*x,Ty*y) +#define AHDRP(f,Tz,Tx) void f(J jt, I m,I c,I n,Tz*z,Tx*x) +#define AHDRR(f,Tz,Tx) void f(J jt, I m,I c,I n,Tz*z,Tx*x) +#define AHDRS(f,Tz,Tx) void f(J jt, I m,I c,I n,Tz*z,Tx*x) + +/* + b 1 iff cell rank of a <= cell rank of w + m # atoms of in the cell with the smaller rank + n excess # of cell atoms + z pointer to result atoms + x pointer to a atoms + y pointer to w atoms +*/ + +#define AMON(f,Tz,Tx,stmt) AHDR1(f,Tz,Tx){DO(n, {stmt} ++z; ++x;);} + +#define AIFX(f,Tz,Tx,Ty,symb) \ + AHDR2(f,Tz,Tx,Ty){Tx u;Ty v; \ + if(1==n) DO(m, *z++=*x++ symb *y++; ) \ + else if(b)DO(m, u=*x++; DO(n, *z++=u symb *y++;)) \ + else DO(m, v=*y++; DO(n, *z++=*x++ symb v; )); \ + } + +#define AOVF(f,Tz,Tx,Ty,fvv,f1v,fv1) \ + AHDR2(f,I,I,I){C er=0;I u,v,*x1,*y1,*z1; \ + if(1==n) {fvv(m,z,x,y); RER;} \ + else if(b){z1=z; y1=y; DO(m, u=*x++; f1v(n,z,u,y); RER; z=z1+=n; y=y1+=n;);} \ + else {z1=z; x1=x; DO(m, v=*y++; fv1(n,z,x,v); RER; z=z1+=n; x=x1+=n;);} \ + } + +#define APFX(f,Tz,Tx,Ty,pfx) \ + AHDR2(f,Tz,Tx,Ty){Tx u;Ty v; \ + if(1==n) DO(m, *z++=pfx(*x,*y); x++; y++; ) \ + else if(b)DO(m, u=*x++; DO(n, *z++=pfx( u,*y); y++;)) \ + else DO(m, v=*y++; DO(n, *z++=pfx(*x, v); x++; )); \ + } + +#define ANAN(f,Tz,Tx,Ty,pfx) \ + AHDR2(f,Tz,Tx,Ty){Tx u;Ty v; \ + NAN0; \ + if(1==n) DO(m, *z++=pfx(*x,*y); x++; y++; ) \ + else if(b)DO(m, u=*x++; DO(n, *z++=pfx( u,*y); y++;)) \ + else DO(m, v=*y++; DO(n, *z++=pfx(*x, v); x++; )); \ + NAN1V; \ + } + +#define APFY(f,Tz,Tx,Ty,pfx) \ + AHDR2(f,Tz,A,A){A u,v;I c,d; \ + c=jt->rela; \ + d=jt->relw; \ + switch((c?2:0)+(d?1:0)){ \ + case 0: \ + if(1==n) DO(m, *z++=pfx(*x, *y ); x++; y++; ) \ + else if(b)DO(m, u= *x++; DO(n, *z++=pfx(u, *y ); y++;)) \ + else DO(m, v= *y++; DO(n, *z++=pfx(*x, v ); x++; )); \ + R; \ + case 1: \ + if(1==n) DO(m, *z++=pfx(*x, (A)(d+(I)*y)); x++; y++; ) \ + else if(b)DO(m, u= *x++; DO(n, *z++=pfx(u, (A)(d+(I)*y)); y++;)) \ + else DO(m, v=(A)(d+(I)*y++); DO(n, *z++=pfx(*x, v ); x++; )); \ + R; \ + case 2: \ + if(1==n) DO(m, *z++=pfx((A)(c+(I)*x),*y ); x++; y++; ) \ + else if(b)DO(m, u=(A)(c+(I)*x++); DO(n, *z++=pfx(u, *y ); y++;)) \ + else DO(m, v= *y++; DO(n, *z++=pfx((A)(c+(I)*x),v ); x++; )); \ + R; \ + case 3: \ + if(1==n) DO(m, *z++=pfx((A)(c+(I)*x),(A)(d+(I)*y)); x++; y++; ) \ + else if(b)DO(m, u=(A)(c+(I)*x++); DO(n, *z++=pfx(u, (A)(d+(I)*y)); y++;)) \ + else DO(m, v=(A)(d+(I)*y++); DO(n, *z++=pfx((A)(c+(I)*x),v ); x++; )); \ + }} + + +/* Embedded visual tools v3.0 fails perform the z++ on all wince platforms. -KBI */ +#if SY_WINCE +#define ACMP(f,Tz,Tx,Ty,pfx) \ + AHDR2(f,B,Tx,Ty){D u,v; \ + if(1==n) DO(m, u=(D)*x++; v=(D)*y++; *z++=pfx(u,v); ) \ + else if(b)DO(m, u=(D)*x++; DO(n, v=(D)*y++; *z++=pfx(u,v);)) \ + else DO(m, v=(D)*y++; DO(n, u=(D)*x++; *z++=pfx(u,v);)); \ + } +#else +#define ACMP(f,Tz,Tx,Ty,pfx) \ + AHDR2(f,B,Tx,Ty){D u,v; \ + if(1==n) DO(m, u=(D)*x++; v=(D)*y++; *z=pfx(u,v); z++; ) \ + else if(b)DO(m, u=(D)*x++; DO(n, v=(D)*y++; *z=pfx(u,v); z++;)) \ + else DO(m, v=(D)*y++; DO(n, u=(D)*x++; *z=pfx(u,v); z++;)); \ + } +#endif + + +#define BFSUB(xb,yi,pfx,bpfx) \ + {B*a,*p,*yb,*zb;I j,k; \ + a=xb; p=(B*)&u; k=0; \ + if(0==r)for(j=0;j<m;++j){ \ + c=*a++; DO(SZI, p[i]=c;); DO(q, v=*yi++; *zz++=pfx(u,v);); \ + }else for(j=0;j<m;++j){ \ + q=(t-k)/SZI; r=(t-k)%SZI; \ + c=*a++; DO(SZI, p[i]=c;); DO(q, v=*yi++; *zz++=pfx(u,v);); \ + if(0==r)k=0; \ + else{ \ + yb=(B*)yi; zb=(B*)zz; \ + DO(r, d=*yb++; *zb++=bpfx(c,d);); \ + c=*a; k=SZI-r; DO(k, d=*yb++; *zb++=bpfx(c,d);); \ + ++yi; ++zz; \ + }}} + +#define BPFX(f,pfx,bpfx,pfyx,bpfyx) \ + AHDR2(f,B,B,B){B c,d;I dd,q,r,t,u,v,*xx,*yy,*zz; \ + t=1==n?m:n; q=t/SZI; r=t%SZI; \ + xx=(I*)x; yy=(I*)y; zz=(I*)z; \ + if(1==n){ \ + DO(q, u=*xx++; v=*yy++; *zz++=pfx(u,v);); \ + if(r){u=*xx++; v=*yy++; dd=pfx(u,v); MC(zz,&dd,r);} \ + }else if(t<SZI){ \ + if(b)DO(m, c=*x++; DO(n, v=*y++; *z++=bpfx(c,v);)) \ + else DO(m, d=*y++; DO(n, u=*x++; *z++=bpfx(u,d);)); \ + }else if(b)BFSUB(x,yy,pfx, bpfx) \ + else BFSUB(y,xx,pfyx,bpfyx) \ + }
new file mode 100644 --- /dev/null +++ b/va1.c @@ -0,0 +1,125 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Monadic Atomic */ + +#include "j.h" +#include "ve.h" + + +static AMON(floorDI,I,D, {D d=tfloor(*x); *z=(I)d; ASSERTW(d==*z,EWOV);}) +static AMON(floorD, D,D, *z=tfloor(*x);) +static AMON(floorZ, Z,Z, *z=zfloor(*x);) + +static AMON(ceilDI, I,D, {D d=tceil(*x); *z=(I)d; ASSERTW(d==*z,EWOV);}) +static AMON(ceilD, D,D, *z=tceil(*x);) +static AMON(ceilZ, Z,Z, *z=zceil(*x);) + +static AMON(cjugZ, Z,Z, *z=zconjug(*x);) + +static AMON(sgnI, I,I, *z=SGN(*x);) +static AMON(sgnD, I,D, *z=jt->ct>ABS(*x)?0:SGN(*x);) +static AMON(sgnZ, Z,Z, if(jt->ct>zmag(*x))*z=zeroZ; else *z=ztrend(*x);) + +static AMON(sqrtI, D,I, ASSERTW(0<=*x,EWIMAG); *z=sqrt((D)*x);) +static AMON(sqrtD, D,D, ASSERTW(0<=*x,EWIMAG); *z=sqrt( *x);) +static AMON(sqrtZ, Z,Z, *z=zsqrt(*x);) + +static AMON(expB, D,B, *z=*x?2.71828182845904523536:1;) +static AMON(expI, D,I, *z=*x<EMIN?0.0:EMAX<*x?inf:exp((D)*x);) +static AMON(expD, D,D, *z=*x<EMIN?0.0:EMAX<*x?inf:exp( *x);) +static AMON(expZ, Z,Z, *z=zexp(*x);) + +static AMON(logB, D,B, *z=*x?0:infm;) +static AMON(logI, D,I, ASSERTW(0<=*x,EWIMAG); *z=log((D)*x);) +static AMON(logD, D,D, ASSERTW(0<=*x,EWIMAG); *z=log( *x);) +static AMON(logZ, Z,Z, *z=zlog(*x);) + +static AMON(absI, I,I, if(0<=*x)*z=*x; else{ASSERTW(IMIN<*x,EWOV); *z=-*x;}) +static AMON(absD, D,D, *z= ABS(*x);) +static AMON(absZ, D,Z, *z=zmag(*x);) + +static AHDR1(oneB,C,C){memset(z,C1,n);} +static AHDR1(idf ,C,C){} /* dummy */ + +static UC va1fns[]={CFLOOR, CCEIL, CPLUS, CSTAR, CSQRT, CEXP, CLOG, CSTILE, CBANG, CCIRCLE, C0}; + +static UA va1tab[]={ + /* <. */ {{{ idf,VB}, { idf,VI}, {floorDI,VI}, {floorZ,VZ}, { idf,VX}, {floorQ,VX}}}, + /* >. */ {{{ idf,VB}, { idf,VI}, { ceilDI,VI}, { ceilZ,VZ}, { idf,VX}, { ceilQ,VX}}}, + /* + */ {{{ idf,VB}, { idf,VI}, { idf,VD}, { cjugZ,VZ}, { idf,VX}, { idf,VQ}}}, + /* * */ {{{ idf,VB}, { sgnI,VI}, { sgnD,VI}, { sgnZ,VZ}, { sgnX,VX}, { sgnQ,VX}}}, + /* %: */ {{{ idf,VB}, {sqrtI,VD}, { sqrtD,VD}, { sqrtZ,VZ}, {sqrtX,VX}, { sqrtQ,VQ}}}, + /* ^ */ {{{expB,VD}, { expI,VD}, { expD,VD}, { expZ,VZ}, { expX,VX}, { expD,VD+VDD}}}, + /* ^. */ {{{logB,VD}, { logI,VD}, { logD,VD}, { logZ,VZ}, { logX,VX}, { logQD,VD}}}, + /* | */ {{{ idf,VB}, { absI,VI}, { absD,VD}, { absZ,VD}, { absX,VX}, { absQ,VQ}}}, + /* ! */ {{{oneB,VB}, {factI,VD}, { factD,VD}, { factZ,VZ}, {factX,VX}, { factQ,VX}}}, + /* o. */ {{{ 0L,0L}, { 0L,0L}, { 0L,0L}, { 0L,0L}, { pixX,VX}, { 0L,0L}}} +}; + +static A jtva1(J,A,C); + +static A jtva1s(J jt,A w,C id,I cv,VF ado){A e,x,z,ze,zx;B c;C ee;I n,t,zt;P*wp,*zp; + t=atype(cv); zt=rtype(cv); + wp=PAV(w); e=SPA(wp,e); x=SPA(wp,x); c=t&&t!=AT(e); + if(c)RZ(e=cvt(t,e)); GA(ze,zt,1,0, 0 ); ado(jt,1L,AV(ze),AV(e)); + if(c)RZ(e=cvt(t,x)); n=AN(x); GA(zx,zt,n,AR(x),AS(x)); ado(jt,n, AV(zx),AV(x)); + if(jt->jerr){ + if(jt->jerr<=NEVM)R 0; + ee=jt->jerr; RZ(ze=va1(e,id)); + jt->jerr=ee; RZ(zx=va1(x,id)); + }else if(cv&VRI+VRD){RZ(ze=cvz(cv,ze)); RZ(zx=cvz(cv,zx));} + GA(z,STYPE(AT(ze)),1,AR(w),AS(w)); zp=PAV(z); + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,i,ca(SPA(wp,i))); + SPB(zp,e,ze); + SPB(zp,x,zx); + R z; +} + +#define VA1CASE(e,f) (256*(e)+(f)) + +static A jtva1(J jt,A w,C id){A e,z;B b,m;I cv,n,t,wt,zt;P*wp;VA2 p;VF ado; + RZ(w); + n=AN(w); wt=n?AT(w):B01; + ASSERT(wt&NUMERIC,EVDOMAIN); + if(b=1&&wt&SPARSE){wp=PAV(w); e=SPA(wp,e); wt=AT(e);} + if(jt->jerr){ + m=!(wt&XNUM+RAT); + switch(VA1CASE(jt->jerr,id)){ + default: R 0; + case VA1CASE(EWOV, CFLOOR): cv=VD; ado=floorD; break; + case VA1CASE(EWOV, CCEIL ): cv=VD; ado=ceilD; break; + case VA1CASE(EWOV, CSTILE): cv=VD+VDD; ado=absD; break; + case VA1CASE(EWIRR, CSQRT ): cv=VD+VDD; ado=sqrtD; break; + case VA1CASE(EWIRR, CEXP ): cv=VD+VDD; ado=expD; break; + case VA1CASE(EWIRR, CBANG ): cv=VD+VDD; ado=factD; break; + case VA1CASE(EWIRR, CLOG ): cv=VD+VDD*m; ado=m?(VF)logD:(VF)logXD; break; + case VA1CASE(EWIMAG,CSQRT ): cv=VZ+VZZ; ado=sqrtZ; break; + case VA1CASE(EWIMAG,CLOG ): cv=VZ+VZZ*m; ado=m?(VF)logZ:wt&XNUM?(VF)logXZ:(VF)logQZ; + } + RESETERR; + }else{ + p=((va1tab+(strchr(va1fns,id)-(C*)va1fns))->p1)[wt&B01?0:wt&INT?1:wt&FL?2:wt&CMPX?3:wt&XNUM?4:5]; + ado=p.f; cv=p.cv; + } + if(ado==idf)R rat(w); + if(b)R va1s(w,id,cv,ado); + t=atype(cv); zt=rtype(cv); + if(t&&t!=wt)RZ(w=cvt(t,w)); + GA(z,zt,n,AR(w),AS(w)); + ado(jt,n,AV(z),AV(w)); + if(jt->jerr)R NEVM<jt->jerr?va1(w,id):0; + else R cv&VRI+VRD?cvz(cv,z):z; +} + +F1(jtfloor1){R va1(w,CFLOOR);} +F1(jtceil1 ){R va1(w,CCEIL );} +F1(jtconjug){R va1(w,CPLUS );} +F1(jtsignum){R va1(w,CSTAR );} +F1(jtsqroot){R va1(w,CSQRT );} +F1(jtexpn1 ){R va1(w,CEXP );} +F1(jtlogar1){R va1(w,CLOG );} +F1(jtmag ){R va1(w,CSTILE);} +F1(jtfact ){R va1(w,CBANG );} +F1(jtpix ){RZ(w); R XNUM&AT(w)&&(jt->xmode==XMFLR||jt->xmode==XMCEIL)?va1(w,CCIRCLE):tymes(pie,w);}
new file mode 100644 --- /dev/null +++ b/va2.c @@ -0,0 +1,716 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Atomic (Scalar) Dyadic */ + +#include "j.h" +#include "ve.h" + + +static VA va[]={ +/* */ { + {{0,0}, {0,0}, {0,0}, /* BB BI BD */ + {0,0}, {0,0}, {0,0}, /* IB II ID */ + {0,0}, {0,0}, {0,0}, /* DB DI DD */ + {0,0}, {0,0}, {0,0}, {0,0}}, /* ZZ XX QQ Symb */ + {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, /* ins: B I D Z X Q Symb */ + {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, /* pfx: B I D Z X Q Symb */ + {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}} }, /* sfx: B I D Z X Q Symb */ + +/* 10 */ { + {{bw0000II, VI+VII}, {bw0000II, VI+VII}, {bw0000II, VI+VII}, + {bw0000II, VI+VII}, {bw0000II, VI}, {bw0000II, VI+VII}, + {bw0000II, VI+VII}, {bw0000II, VI+VII}, {bw0000II, VI+VII}, + {bw0000II, VI+VII}, {bw0000II, VI+VII}, {bw0000II, VI+VII}, {0,0}}, + {{bw0000insI,VI+VII}, {bw0000insI,VI}}, + {{bw0000pfxI,VI+VII}, {bw0000pfxI,VI}}, + {{bw0000sfxI,VI+VII}, {bw0000sfxI,VI}} }, + +/* 11 */ { + {{bw0001II, VI+VII}, {bw0001II, VI+VII}, {bw0001II, VI+VII}, + {bw0001II, VI+VII}, {bw0001II, VI}, {bw0001II, VI+VII}, + {bw0001II, VI+VII}, {bw0001II, VI+VII}, {bw0001II, VI+VII}, + {bw0001II, VI+VII}, {bw0001II, VI+VII}, {bw0001II, VI+VII}, {0,0}}, + {{bw0001insI,VI+VII}, {bw0001insI,VI}}, + {{bw0001pfxI,VI+VII}, {bw0001pfxI,VI}}, + {{bw0001sfxI,VI+VII}, {bw0001sfxI,VI}} }, + +/* 12 */ { + {{bw0010II, VI+VII}, {bw0010II, VI+VII}, {bw0010II, VI+VII}, + {bw0010II, VI+VII}, {bw0010II, VI}, {bw0010II, VI+VII}, + {bw0010II, VI+VII}, {bw0010II, VI+VII}, {bw0010II, VI+VII}, + {bw0010II, VI+VII}, {bw0010II, VI+VII}, {bw0010II, VI+VII}, {0,0}}, + {{bw0010insI,VI+VII}, {bw0010insI,VI}}, + {{0,0}}, + {{bw0010sfxI,VI+VII}, {bw0010sfxI,VI}} }, + +/* 13 */ { + {{bw0011II, VI+VII}, {bw0011II, VI+VII}, {bw0011II, VI+VII}, + {bw0011II, VI+VII}, {bw0011II, VI}, {bw0011II, VI+VII}, + {bw0011II, VI+VII}, {bw0011II, VI+VII}, {bw0011II, VI+VII}, + {bw0011II, VI+VII}, {bw0011II, VI+VII}, {bw0011II, VI+VII}, {0,0}}, + {{bw0011insI,VI+VII}, {bw0011insI,VI}}, + {{bw0011pfxI,VI+VII}, {bw0011pfxI,VI}}, + {{bw0011sfxI,VI+VII}, {bw0011sfxI,VI}} }, + +/* 14 */ { + {{bw0100II, VI+VII}, {bw0100II, VI+VII}, {bw0100II, VI+VII}, + {bw0100II, VI+VII}, {bw0100II, VI}, {bw0100II, VI+VII}, + {bw0100II, VI+VII}, {bw0100II, VI+VII}, {bw0100II, VI+VII}, + {bw0100II, VI+VII}, {bw0100II, VI+VII}, {bw0100II, VI+VII}, {0,0}}, + {{bw0100insI,VI+VII}, {bw0100insI,VI}}, + {{0,0}}, + {{bw0100sfxI,VI+VII}, {bw0100sfxI,VI}} }, + +/* 15 */ { + {{bw0101II, VI+VII}, {bw0101II, VI+VII}, {bw0101II, VI+VII}, + {bw0101II, VI+VII}, {bw0101II, VI}, {bw0101II, VI+VII}, + {bw0101II, VI+VII}, {bw0101II, VI+VII}, {bw0101II, VI+VII}, + {bw0101II, VI+VII}, {bw0101II, VI+VII}, {bw0101II, VI+VII}, {0,0}}, + {{bw0101insI,VI+VII}, {bw0101insI,VI}}, + {{bw0101pfxI,VI+VII}, {bw0101pfxI,VI}}, + {{bw0101sfxI,VI+VII}, {bw0101sfxI,VI}} }, + +/* 16 */ { + {{bw0110II, VI+VII}, {bw0110II, VI+VII}, {bw0110II, VI+VII}, + {bw0110II, VI+VII}, {bw0110II, VI}, {bw0110II, VI+VII}, + {bw0110II, VI+VII}, {bw0110II, VI+VII}, {bw0110II, VI+VII}, + {bw0110II, VI+VII}, {bw0110II, VI+VII}, {bw0110II, VI+VII}, {0,0}}, + {{bw0110insI,VI+VII}, {bw0110insI,VI}}, + {{bw0110pfxI,VI+VII}, {bw0110pfxI,VI}}, + {{bw0110sfxI,VI+VII}, {bw0110sfxI,VI}} }, + +/* 17 */ { + {{bw0111II, VI+VII}, {bw0111II, VI+VII}, {bw0111II, VI+VII}, + {bw0111II, VI+VII}, {bw0111II, VI}, {bw0111II, VI+VII}, + {bw0111II, VI+VII}, {bw0111II, VI+VII}, {bw0111II, VI+VII}, + {bw0111II, VI+VII}, {bw0111II, VI+VII}, {bw0111II, VI+VII}, {0,0}}, + {{bw0111insI,VI+VII}, {bw0111insI,VI}}, + {{bw0111pfxI,VI+VII}, {bw0111pfxI,VI}}, + {{bw0111sfxI,VI+VII}, {bw0111sfxI,VI}} }, + +/* 18 */ { + {{bw1000II, VI+VII}, {bw1000II, VI+VII}, {bw1000II, VI+VII}, + {bw1000II, VI+VII}, {bw1000II, VI}, {bw1000II, VI+VII}, + {bw1000II, VI+VII}, {bw1000II, VI+VII}, {bw1000II, VI+VII}, + {bw1000II, VI+VII}, {bw1000II, VI+VII}, {bw1000II, VI+VII}, {0,0}}, + {{bw1000insI,VI+VII}, {bw1000insI,VI}}, + {{0,0}}, + {{bw1000sfxI,VI+VII}, {bw1000sfxI,VI}} }, + +/* 19 */ { + {{bw1001II, VI+VII}, {bw1001II, VI+VII}, {bw1001II, VI+VII}, + {bw1001II, VI+VII}, {bw1001II, VI}, {bw1001II, VI+VII}, + {bw1001II, VI+VII}, {bw1001II, VI+VII}, {bw1001II, VI+VII}, + {bw1001II, VI+VII}, {bw1001II, VI+VII}, {bw1001II, VI+VII}, {0,0}}, + {{bw1001insI,VI+VII}, {bw1001insI,VI}}, + {{bw1001pfxI,VI+VII}, {bw1001pfxI,VI}}, + {{bw1001sfxI,VI+VII}, {bw1001sfxI,VI}} }, + +/* 1a */ { + {{bw1010II, VI+VII}, {bw1010II, VI+VII}, {bw1010II, VI+VII}, + {bw1010II, VI+VII}, {bw1010II, VI}, {bw1010II, VI+VII}, + {bw1010II, VI+VII}, {bw1010II, VI+VII}, {bw1010II, VI+VII}, + {bw1010II, VI+VII}, {bw1010II, VI+VII}, {bw1010II, VI+VII}, {0,0}}, + {{bw1010insI,VI+VII}, {bw1010insI,VI}}, + {{0,0}}, + {{bw1010sfxI,VI+VII}, {bw1010sfxI,VI}} }, + +/* 1b */ { + {{bw1011II, VI+VII}, {bw1011II, VI+VII}, {bw1011II, VI+VII}, + {bw1011II, VI+VII}, {bw1011II, VI}, {bw1011II, VI+VII}, + {bw1011II, VI+VII}, {bw1011II, VI+VII}, {bw1011II, VI+VII}, + {bw1011II, VI+VII}, {bw1011II, VI+VII}, {bw1011II, VI+VII}, {0,0}}, + {{bw1011insI,VI+VII}, {bw1011insI,VI}}, + {{0,0}}, + {{bw1011sfxI,VI+VII}, {bw1011sfxI,VI}} }, + +/* 1c */ { + {{bw1100II, VI+VII}, {bw1100II, VI+VII}, {bw1100II, VI+VII}, + {bw1100II, VI+VII}, {bw1100II, VI}, {bw1100II, VI+VII}, + {bw1100II, VI+VII}, {bw1100II, VI+VII}, {bw1100II, VI+VII}, + {bw1100II, VI+VII}, {bw1100II, VI+VII}, {bw1100II, VI+VII}, {0,0}}, + {{bw1100insI,VI+VII}, {bw1100insI,VI}}, + {{0,0}}, + {{bw1100sfxI,VI+VII}, {bw1100sfxI,VI}} }, + +/* 1d */ { + {{bw1101II, VI+VII}, {bw1101II, VI+VII}, {bw1101II, VI+VII}, + {bw1101II, VI+VII}, {bw1101II, VI}, {bw1101II, VI+VII}, + {bw1101II, VI+VII}, {bw1101II, VI+VII}, {bw1101II, VI+VII}, + {bw1101II, VI+VII}, {bw1101II, VI+VII}, {bw1101II, VI+VII}, {0,0}}, + {{bw1101insI,VI+VII}, {bw1101insI,VI}}, + {{0,0}}, + {{bw1101sfxI,VI+VII}, {bw1101sfxI,VI}} }, + +/* 1e */ { + {{bw1110II, VI+VII}, {bw1110II, VI+VII}, {bw1110II, VI+VII}, + {bw1110II, VI+VII}, {bw1110II, VI}, {bw1110II, VI+VII}, + {bw1110II, VI+VII}, {bw1110II, VI+VII}, {bw1110II, VI+VII}, + {bw1110II, VI+VII}, {bw1110II, VI+VII}, {bw1110II, VI+VII}, {0,0}}, + {{bw1110insI,VI+VII}, {bw1110insI,VI}}, + {{0,0}}, + {{bw1110sfxI,VI+VII}, {bw1110sfxI,VI}} }, + +/* 1f */ { + {{bw1111II, VI+VII}, {bw1111II, VI+VII}, {bw1111II, VI+VII}, + {bw1111II, VI+VII}, {bw1111II, VI}, {bw1111II, VI+VII}, + {bw1111II, VI+VII}, {bw1111II, VI+VII}, {bw1111II, VI+VII}, + {bw1111II, VI+VII}, {bw1111II, VI+VII}, {bw1111II, VI+VII}, {0,0}}, + {{bw1111insI,VI+VII}, {bw1111insI,VI}}, + {{bw1111pfxI,VI+VII}, {bw1111pfxI,VI}}, + {{bw1111sfxI,VI+VII}, {bw1111sfxI,VI}} }, + +/* 21 ! */ { + {{leBB, VB }, {binDD,VD+VDD+VRI}, {binDD,VD+VDD}, + {binDD,VD+VDD+VRI}, {binDD,VD+VDD+VRI}, {binDD,VD+VDD}, + {binDD,VD+VDD }, {binDD,VD+VDD }, {binDD,VD }, + {binZZ,VZ+VZZ}, {binXX,VX+VXX}, {binQQ,VX+VQQ}, {0,0}}, + {{leinsB,VB}}, + {{lepfxB,VB}}, + {{lesfxB,VB}} }, + +/* 25 % */ { + {{divBB,VD}, {divBI,VD}, {divBD,VD}, + {divIB,VD}, {divII,VD}, {divID,VD}, + {divDB,VD}, {divDI,VD}, {divDD,VD}, + {divZZ,VZ+VZZ}, {divXX,VX+VXX}, {divQQ,VQ+VQQ}, {0,0}}, + {{divinsD,VD+VDD}, {divinsD,VD+VDD}, {divinsD,VD}, {divinsZ,VZ}}, + {{divpfxD,VD+VDD}, {divpfxD,VD+VDD}, {divpfxD,VD}, {divpfxZ,VZ}}, + {{divsfxD,VD+VDD}, {divsfxD,VD+VDD}, {divsfxD,VD}, {divsfxZ,VZ}} }, + +/* 2a * */ { + {{andBB, VB}, {tymesBI,VI}, {tymesBD,VD}, + {tymesIB,VI}, {tymesII,VI}, {tymesID,VD}, + {tymesDB,VD}, {tymesDI,VD}, {tymesDD,VD}, + {tymesZZ,VZ+VZZ}, {tymesXX,VX+VXX}, {tymesQQ,VQ+VQQ}, {0,0}}, + {{andinsB,VB}, {tymesinsI,VI}, {tymesinsD,VD}, {tymesinsZ,VZ}, {0,0}, {0,0}, {0,0}}, + {{andpfxB,VB}, {tymespfxI,VI}, {tymespfxD,VD}, {tymespfxZ,VZ}, {tymespfxX,VX}, {tymespfxQ,VQ}, {0,0}}, + {{andsfxB,VB}, {tymessfxI,VI}, {tymessfxD,VD}, {tymessfxZ,VZ}, {tymessfxX,VX}, {tymessfxQ,VQ}, {0,0}} }, + +/* 2b + */ { + {{plusBB,VI }, {plusII,VI+VII}, {plusBD,VD}, + {plusII,VI+VII}, {plusII,VI }, {plusID,VD}, + {plusDB,VD }, {plusDI,VD }, {plusDD,VD}, + {plusZZ,VZ+VZZ}, {plusXX,VX+VXX}, {plusQQ,VQ+VQQ}, {0,0}}, + {{plusinsB,VI}, {plusinsI,VI}, {plusinsD,VD}, {plusinsZ,VZ}, {0,0}, {0,0}, {0,0}}, + {{pluspfxB,VI}, {pluspfxI,VI}, {pluspfxD,VD}, {pluspfxZ,VZ}, {pluspfxX,VX}, {pluspfxQ,VQ}, {0,0}}, + {{plussfxB,VI}, {plussfxI,VI}, {plussfxD,VD}, {plussfxZ,VZ}, {plussfxX,VX}, {plussfxQ,VQ}, {0,0}} }, + +/* 2d - */ { + {{minusBB,VI }, {minusII,VI+VII}, {minusBD,VD}, + {minusII,VI+VII}, {minusII,VI }, {minusID,VD}, + {minusDB,VD }, {minusDI,VD }, {minusDD,VD}, + {minusZZ,VZ+VZZ}, {minusXX,VX+VXX}, {minusQQ,VQ+VQQ}, {0,0}}, + {{minusinsB,VI}, {minusinsI,VI}, {minusinsD,VD}, {minusinsZ,VZ}, {0,0}, {0,0}, {0,0}}, + {{minuspfxB,VI}, {minuspfxI,VI}, {minuspfxD,VD}, {minuspfxZ,VZ}, {minuspfxX,VX}, {minuspfxQ,VQ}, {0,0}}, + {{minussfxB,VI}, {minussfxI,VI}, {minussfxD,VD}, {minussfxZ,VZ}, {0,0}, {0,0}, {0,0}} }, + +/* 3c < */ { + {{ltBB,VB}, {ltBI,VB}, {ltBD,VB}, + {ltIB,VB}, {ltII,VB}, {ltID,VB}, + {ltDB,VB}, {ltDI,VB}, {ltDD,VB}, + {ltDD,VB+VDD}, {ltXX,VB+VXFC}, {ltQQ,VB+VQQ}, {ltSS,VB}}, + {{ltinsB,VB}}, + {{ltpfxB,VB}}, + {{ltsfxB,VB}} }, + +/* 3d = */ { + {{eqBB,VB}, {eqBI,VB}, {eqBD,VB}, + {eqIB,VB}, {eqII,VB}, {eqID,VB}, + {eqDB,VB}, {eqDI,VB}, {eqDD,VB}, + {eqZZ,VB+VZZ}, {eqXX,VB+VXEQ}, {eqQQ,VB+VQQ}, {eqII,VB}}, + {{eqinsB,VB}}, + {{eqpfxB,VB}}, + {{eqsfxB,VB}} }, + +/* 3e > */ { + {{gtBB,VB}, {gtBI,VB}, {gtBD,VB}, + {gtIB,VB}, {gtII,VB}, {gtID,VB}, + {gtDB,VB}, {gtDI,VB}, {gtDD,VB}, + {gtDD,VB+VDD}, {gtXX,VB+VXCF}, {gtQQ,VB+VQQ}, {gtSS,VB}}, + {{gtinsB,VB}}, + {{gtpfxB,VB}}, + {{gtsfxB,VB}} }, + +/* 5e ^ */ { + {{geBB, VB}, {powBI,VD}, {powBD,VD}, + {powIB,VI}, {powII,VD}, {powID,VD}, + {powDB,VD}, {powDI,VD}, {powDD,VD}, + {powZZ,VZ+VZZ}, {powXX,VX+VXX}, {powQQ,VQ+VQQ}, {0,0}}, + {{geinsB,VB}}, + {{gepfxB,VB}}, + {{gesfxB,VB}} }, + +/* 7c | */ { + {{ltBB, VB }, {remII,VI+VII}, {remDD,VD+VDD}, + {remII,VI+VII}, {remII,VI }, {remID,VI }, + {remDD,VD+VDD}, {remDD,VD+VDD}, {remDD,VD }, + {remZZ,VZ+VZZ}, {remXX,VX+VXX}, {remQQ,VQ+VQQ}, {0,0}}, + {{ltinsB,VB}}, + {{ltpfxB,VB}}, + {{ltsfxB,VB}} }, + +/* 82 <. */ { + {{andBB,VB}, {minBI,VI}, {minBD,VD}, + {minIB,VI}, {minII,VI}, {minID,VD}, + {minDB,VD}, {minDI,VD}, {minDD,VD}, + {minDD,VD+VDD}, {minXX,VX+VXX}, {minQQ,VQ+VQQ}, {minSS,VSB}}, + {{andinsB,VB}, {mininsI,VI}, {mininsD,VD}, {mininsD,VD+VDD}, {mininsX,VX}, {0,0}, {mininsS,VSB}}, + {{andpfxB,VB}, {minpfxI,VI}, {minpfxD,VD}, {minpfxD,VD+VDD}, {minpfxX,VX}, {minpfxQ,VQ}, {minpfxS,VSB}}, + {{andsfxB,VB}, {minsfxI,VI}, {minsfxD,VD}, {minsfxD,VD+VDD}, {minsfxX,VX}, {minsfxQ,VQ}, {minsfxS,VSB}}}, + +/* 83 <: */ { + {{leBB,VB}, {leBI,VB}, {leBD,VB}, + {leIB,VB}, {leII,VB}, {leID,VB}, + {leDB,VB}, {leDI,VB}, {leDD,VB}, + {leDD,VB+VDD}, {leXX,VB+VXCF}, {leQQ,VB+VQQ}, {leSS,VB}}, + {{leinsB,VB}}, + {{lepfxB,VB}}, + {{lesfxB,VB}} }, + +/* 84 >. */ { + {{ orBB,VB}, {maxBI,VI}, {maxBD,VD}, + {maxIB,VI}, {maxII,VI}, {maxID,VD}, + {maxDB,VD}, {maxDI,VD}, {maxDD,VD}, + {maxDD,VD+VDD}, {maxXX,VX+VXX}, {maxQQ,VQ+VQQ}, {maxSS,VSB}}, + {{orinsB,VB}, {maxinsI,VI}, {maxinsD,VD}, {maxinsD,VD+VDD}, {maxinsX,VX}, {0,0}, {maxinsS,VSB}}, + {{orpfxB,VB}, {maxpfxI,VI}, {maxpfxD,VD}, {maxpfxD,VD+VDD}, {maxpfxX,VX}, {maxpfxQ,VQ}, {maxpfxS,VSB}}, + {{orsfxB,VB}, {maxsfxI,VI}, {maxsfxD,VD}, {maxsfxD,VD+VDD}, {maxsfxX,VX}, {maxsfxQ,VQ}, {maxsfxS,VSB}}}, + +/* 85 >: */ { + {{geBB,VB}, {geBI,VB}, {geBD,VB}, + {geIB,VB}, {geII,VB}, {geID,VB}, + {geDB,VB}, {geDI,VB}, {geDD,VB}, + {geDD,VB+VDD}, {geXX,VB+VXFC}, {geQQ,VB+VQQ}, {geSS,VB}}, + {{geinsB,VB}}, + {{gepfxB,VB}}, + {{gesfxB,VB}} }, + +/* 88 +. */ { + {{ orBB,VB }, {gcdII,VI+VII}, {gcdDD,VD+VDD}, + {gcdII,VI+VII}, {gcdII,VI }, {gcdDD,VD+VDD}, + {gcdDD,VD+VDD}, {gcdDD,VD+VDD}, {gcdDD,VD }, + {gcdZZ,VZ+VZZ}, {gcdXX,VX+VXX}, {gcdQQ,VQ+VQQ}, {0,0}}, + {{orinsB,VB}}, + {{orpfxB,VB}}, + {{orsfxB,VB}} }, + +/* 89 +: */ { + {{norBB,VB }, {norBB,VB+VBB}, {norBB,VB+VBB}, + {norBB,VB+VBB}, {norBB,VB+VBB}, {norBB,VB+VBB}, + {norBB,VB+VBB}, {norBB,VB+VBB}, {norBB,VB+VBB}, + {norBB,VB+VBB}, {norBB,VB+VBB}, {norBB,VB+VBB}, {0,0}}, + {{norinsB,VB}}, + {{norpfxB,VB}}, + {{norsfxB,VB}} }, + +/* 8a *. */ { + {{andBB,VB }, {lcmII,VI+VII}, {lcmDD,VD+VDD}, + {lcmII,VI+VII}, {lcmII,VI }, {lcmDD,VD+VDD}, + {lcmDD,VD+VDD}, {lcmDD,VD+VDD}, {lcmDD,VD }, + {lcmZZ,VZ+VZZ}, {lcmXX,VX+VXX}, {lcmQQ,VQ+VQQ}, {0,0}}, + {{andinsB,VB}}, + {{andpfxB,VB}}, + {{andsfxB,VB}} }, + +/* 8b *: */ { + {{nandBB,VB}, {nandBB,VB+VBB}, {nandBB,VB+VBB}, + {nandBB,VB+VBB}, {nandBB,VB+VBB}, {nandBB,VB+VBB}, + {nandBB,VB+VBB}, {nandBB,VB+VBB}, {nandBB,VB+VBB}, + {nandBB,VB+VBB}, {nandBB,VB+VBB}, {nandBB,VB+VBB}, {0,0}}, + {{nandinsB,VB}}, + {{nandpfxB,VB}}, + {{nandsfxB,VB}} }, + +/* 95 ~: */ { + {{neBB,VB}, {neBI,VB}, {neBD,VB}, + {neIB,VB}, {neII,VB}, {neID,VB}, + {neDB,VB}, {neDI,VB}, {neDD,VB}, + {neZZ,VB+VZZ}, {neXX,VB+VXEQ}, {neQQ,VB+VQQ}, {0,0}}, + {{neinsB,VB}}, + {{nepfxB,VB}}, + {{nesfxB,VB}} }, + +/* d1 o. */ { + {{cirDD,VD+VDD}, {cirDD,VD+VDD}, {cirBD,VD}, + {cirDD,VD+VDD}, {cirDD,VD+VDD}, {cirID,VD}, + {cirDD,VD+VDD}, {cirDD,VD+VDD}, {cirDD,VD}, + {cirZZ,VZ+VZZ+VRD}, {cirDD,VD+VDD}, {cirDD,VD+VDD}, {0,0}}, + {{0,0}}, + {{0,0}}, + {{0,0}} } +}; + +static UC vaptr[256]={ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* 1 */ + 0, 17, 0, 0, 0, 18, 0, 0, 0, 0, 19, 20, 0, 21, 0, 0, /* 2 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 23, 24, 0, /* 3 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, /* 5 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, /* 7 */ + 0, 0, 27, 28, 29, 30, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, /* 8 */ + 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */ + 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */ +}; /* index in va[] for each ID */ +/* 1 2 3 4 5 6 7 8 9 a b c d e f */ + +C jtvaid(J jt,A w){A x;C c;I k;V*v; + v=VAV(w); c=v->id; + if(c==CBDOT){x=v->f; if(INT&AT(x)&&!AR(x)&&(k=*AV(x),16<=k&&k<=31))c=(C)k;} + R vaptr[(UC)c]?c:0; +} + +static A jtva2(J,A,A,C); + +F2(jtbitwise0000){R va2(a,w,(C)16);} +F2(jtbitwise0001){R va2(a,w,(C)17);} +F2(jtbitwise0010){R va2(a,w,(C)18);} +F2(jtbitwise0011){R va2(a,w,(C)19);} + +F2(jtbitwise0100){R va2(a,w,(C)20);} +F2(jtbitwise0101){R va2(a,w,(C)21);} +F2(jtbitwise0110){R va2(a,w,(C)22);} +F2(jtbitwise0111){R va2(a,w,(C)23);} + +F2(jtbitwise1000){R va2(a,w,(C)24);} +F2(jtbitwise1001){R va2(a,w,(C)25);} +F2(jtbitwise1010){R va2(a,w,(C)26);} +F2(jtbitwise1011){R va2(a,w,(C)27);} + +F2(jtbitwise1100){R va2(a,w,(C)28);} +F2(jtbitwise1101){R va2(a,w,(C)29);} +F2(jtbitwise1110){R va2(a,w,(C)30);} +F2(jtbitwise1111){R va2(a,w,(C)31);} + +F2(jteq ){R va2(a,w,CEQ );} +F2(jtlt ){R va2(a,w,CLT );} +F2(jtminimum){R va2(a,w,CMIN );} +F2(jtle ){R va2(a,w,CLE );} +F2(jtgt ){R va2(a,w,CGT );} +F2(jtmaximum){R va2(a,w,CMAX );} +F2(jtge ){R va2(a,w,CGE );} +F2(jtplus ){R va2(a,w,CPLUS );} +F2(jtgcd ){R va2(a,w,CPLUSDOT);} +F2(jtnor ){R va2(a,w,CPLUSCO );} +F2(jttymes ){R va2(a,w,CSTAR );} +F2(jtlcm ){R va2(a,w,CSTARDOT);} +F2(jtnand ){R va2(a,w,CSTARCO );} +F2(jtminus ){R va2(a,w,CMINUS );} +F2(jtdivide ){R va2(a,w,CDIV );} +F2(jtexpn2 ){R va2(a,w,CEXP );} +F2(jtne ){R va2(a,w,CNE );} +F2(jtoutof ){R va2(a,w,CBANG );} +F2(jtcircle ){R va2(a,w,CCIRCLE );} +F2(jtresidue){RZ(a&&w); R INT&AT(w)&&equ(a,num[2])?intmod2(w):va2(a,w,CSTILE);} + +F1(jtnot ){R w&&AT(w)&B01+SB01?va2(zero,w,CEQ):va2(one,w,CMINUS);} +F1(jtnegate){R va2(zero, w, CMINUS);} +F1(jtdecrem){R va2(w, one, CMINUS);} +F1(jtincrem){R va2(one, w, CPLUS );} +F1(jtduble ){R va2(num[2],w, CSTAR );} +F1(jtsquare){R va2(w, w, CSTAR );} +F1(jtrecip ){R va2(one, w, CDIV );} +F1(jthalve ){R va2(w, num[2],CDIV );} + +static void zeroF(J jt,B b,I m,I n,B*z,void*x,void*y){memset(z,C0,m*n);} +static void oneF(J jt,B b,I m,I n,B*z,void*x,void*y){memset(z,C1,m*n);} + +A jtcvz(J jt,I cv,A w){I t; + t=AT(w); + if(cv&VRD&&t!=FL )R pcvt(FL,w); + if(cv&VRI&&t!=INT)R icvt(w); + R w; +} /* convert result */ + +I atype(I cv){ + if(!(cv&VBB+VII+VDD+VZZ+VQQ+VXX+VXEQ+VXCF+VXFC))R 0; + R cv&VBB?B01:cv&VII?INT:cv&VDD?FL:cv&VZZ?CMPX:cv&VQQ?RAT:XNUM; +} /* argument conversion */ + +I rtype(I cv){R cv&VB?B01:cv&VI?INT:cv&VD?FL:cv&VZ?CMPX:cv&VQ?RAT:cv&VX?XNUM:SBT;} + /* result type */ + + +#define VAF(fname,ptr,fp,fm,ft) \ + void fname(J jt,C id,I t,VF*ado,I*cv){VA2*p; \ + if(jt->jerr==EWOV){ \ + jt->jerr=0; \ + *ado=(id==CPLUS?fp:id==CMINUS?fm:ft); \ + *cv=VD; \ + }else if(t&NUMERIC+SBT){ \ + p=(va+vaptr[(UC)id])->ptr+(t&B01?0:t&INT?1:t&FL?2:t&CMPX?3:t&XNUM?4:t&RAT?5:6); \ + *ado=p->f; *cv=p->cv; \ + }else *ado=0; \ + } + +VAF(jtvains,pins, plusinsO,minusinsO,tymesinsO) +VAF(jtvapfx,ppfx, pluspfxO,minuspfxO,tymespfxO) +VAF(jtvasfx,psfx, plussfxO,minussfxO,tymessfxO) + +#define VARCASE(e,c) (70*(e)+(c)) + +B jtvar(J jt,C id,A a,A w,I at,I wt,VF*ado,I*cv){B b;I j,t,x;VA*q;VA2 p; + if(jt->jerr){ + switch(VARCASE(jt->jerr,id)){ + default: R 0; + case VARCASE(EWIMAG,CCIRCLE ): *ado=(VF)cirZZ; *cv=VZ+VZZ+VRD; break; + case VARCASE(EWIMAG,CEXP ): *ado=(VF)powZZ; *cv=VZ+VZZ+VRD; break; + case VARCASE(EWIRR ,CBANG ): *ado=(VF)binDD; *cv=VD+VDD; break; + case VARCASE(EWIRR ,CEXP ): *ado=(VF)powDD; *cv=VD+VDD; break; + case VARCASE(EWRAT ,CDIV ): *ado=(VF)divQQ; *cv=VQ+VQQ; break; + case VARCASE(EWRAT ,CEXP ): *ado=(VF)powQQ; *cv=VQ+VQQ; break; + case VARCASE(EWDIV0,CDIV ): *ado=(VF)divDD; *cv=VD+VDD; break; + case VARCASE(EWOV ,CPLUS ): *ado=(VF)plusIO; *cv=VD+VII; break; + case VARCASE(EWOV ,CMINUS ): *ado=(VF)minusIO; *cv=VD+VII; break; + case VARCASE(EWOV ,CSTAR ): *ado=(VF)tymesIO; *cv=VD+VII; break; + case VARCASE(EWOV ,CPLUSDOT): *ado=(VF)gcdIO; *cv=VD+VII; break; + case VARCASE(EWOV ,CSTARDOT): *ado=(VF)lcmIO; *cv=VD+VII; break; + case VARCASE(EWOV ,CSTILE ): *ado=(VF)remDD; *cv=VD+VDD; break; + } + RESETERR; + }else if(at&NUMERIC&&wt&NUMERIC){ + t=at|wt; b=1&&t&RAT+XNUM+XD+XZ; + j=t&CMPX ? 9 : b ? (t&XZ?13:t&XD?12:t&FL?8:t&RAT?11:10) : + (at&B01?0:at&INT?3:6)+(wt&B01?0:wt&INT?1:2); + q=va+vaptr[(UC)id]; + p=(q->p2)[j]; + *ado=p.f; *cv=x=p.cv; if(b&&t&FL&&!(x&VZZ))*cv+=VDD; + }else{ + b=!HOMO(at,wt); *cv=VB; + jt->rela=ARELATIVE(a)*(I)a; + jt->relw=ARELATIVE(w)*(I)w; + switch(id){ + case CEQ: *ado=b?(VF)zeroF:at&SBT?(VF)eqII:at&BOX?(VF)eqAA: + at&LIT?(wt&LIT?(VF)eqCC:(VF)eqCS):wt&LIT?(VF)eqSC:(VF)eqSS; break; + case CNE: *ado=b?(VF) oneF:at&SBT?(VF)neII:at&BOX?(VF)neAA: + at&LIT?(wt&LIT?(VF)neCC:(VF)neCS):wt&LIT?(VF)neSC:(VF)neSS; break; + default: + ASSERT(at&SBT&&wt&SBT,EVDOMAIN); + q=va+vaptr[(UC)id]; p=(q->p2)[12]; + ASSERT(p.f,EVDOMAIN); + *ado=p.f; *cv=x=p.cv; + }} + R 1; +} /* function and control for rank */ + +static A jtva2(J jt,A a,A w,C id){A z;B b,c,sp=0;C*av,*wv,*zv;I acr,af,ak,an,ar,*as,at,cv,f,m, + mf,n,nf,*oq=jt->rank,r,*s,*sf,t,wcr,wf,wk,wn,wr,*ws,wt,zk,zn,zt;VF ado; + RZ(a&&w); + an=AN(a); ar=AR(a); as=AS(a); at=an?AT(a):B01; + wn=AN(w); wr=AR(w); ws=AS(w); wt=wn?AT(w):B01; + if(id==CEXP&&1==wn&&FL&wt&&0.5==*DAV(w))R sqroot(a); + if(SPARSE&at){sp=1; at=DTYPE(at);} + if(SPARSE&wt){sp=1; wt=DTYPE(wt);} + RZ(var(id,a,w,at,wt,&ado,&cv)); zt=rtype(cv); t=atype(cv); + if(t&&!sp){ + b=1&&t&XNUM; + if(t!=at)RZ(a=b?xcvt(cv&VXEQ?XMEXMT:cv&VXFC?XMFLR:cv&VXCF?XMCEIL:XMEXACT,a):cvt(t,a)); + if(t!=wt)RZ(w=b?xcvt(cv&VXEQ?XMEXMT:cv&VXCF?XMFLR:cv&VXFC?XMCEIL:XMEXACT,w):cvt(t,w)); + } + if(jt->rank){I acn,q,wcn,zcn; + r=jt->rank[0]; acr=MIN(ar,r); af=ar-acr; acn=prod(acr,as+af); + r=jt->rank[1]; wcr=MIN(wr,r); wf=wr-wcr; wcn=prod(wcr,ws+wf); jt->rank=0; + ASSERT(!ICMP(as,ws,MIN(af,wf))&&!ICMP(as+af,ws+wf,MIN(acr,wcr)),EVLENGTH); + c=af<=wf; f=c?wf:af; q=c?af:wf; sf=c?ws:as; + b=acr<=wcr; zcn=b?wcn:acn; m=b?acn:wcn; n=m?zcn/m:0; r=b?wcr:acr; s=b?ws+wf:as+af; + if(zcn){RE(mf=prod(q,sf)); RE(nf=prod(f-q,q+sf));}else mf=nf=0; + if(!sp){RE(zn=mult(mf,mult(nf,zcn))); zk=zcn*bp(zt); ak=acn*bp(AT(a)); wk=wcn*bp(AT(w));} + }else{ + ASSERT(!ICMP(as,ws,MIN(ar,wr)),EVLENGTH); + ak=wk=zk=af=wf=f=c=0; acr=ar; wcr=wr; sf=0; mf=nf=1; + b=ar<=wr; zn=b?wn:an; m=b?an:wn; n=m?zn/m:0; r=b?wr:ar; s=b?ws:as; + } + if(sp){z=vasp(a,w,id,ado,cv,t,zt,af,acr,wf,wcr,f,r); if(!jt->jerr)R z;} + else{ + GA(z,zt,zn,f+r,sf); ICPY(f+AS(z),s,r); + if(!zn)R z; + av=CAV(a); wv=CAV(w); zv=CAV(z); + if(1==nf) DO(mf, ado(jt,b,m,n,zv,av,wv); zv+=zk; av+=ak; wv+=wk;) + else if(c)DO(mf, DO(nf, ado(jt,b,m,n,zv,av,wv); zv+=zk; wv+=wk;); av+=ak;) + else DO(mf, DO(nf, ado(jt,b,m,n,zv,av,wv); zv+=zk; av+=ak; ); wv+=wk;); + if(!jt->jerr)R cv&VRI+VRD?cvz(cv,z):z; + } + R NEVM<jt->jerr?(jt->rank=oq,va2(a,w,id)):0; +} /* scalar fn primitive and f"r main control */ + +/* + acn wcn zcn # atoms in a cell + acr wcr r cell rank + af wf f frame + ak wk zk # bytes in a cell + an wn zn overall # atoms + ar wr f+r overall rank + + b 1 iff cell rank of a <= cell rank of w + c 1 iff frame of a <= frame of w + m # of atoms in the cell with the smaller rank + mf agreed # of frames + n excess # of cell atoms + nf excess # of frames + f max of frame of a, frame of w + q min of frame of a, frame of w + r max of cell rank of a, cell rank of w + s max of cell shape of a, cell shape of w + sf max of frame shape of a, frame shape of w +*/ + + + +static DF2(jtsumattymes){A z;B b;I an,ar,*as,at,m,n,nn,r,*s,t,wn,wr,*ws,wt,zn; + RZ(a&&w&&self); + an=AN(a); ar=AR(a); as=AS(a); at=an?AT(a):B01; + wn=AN(w); wr=AR(w); ws=AS(w); wt=wn?AT(w):B01; + t=maxtype(at,wt); b=ar<=wr; r=b?wr:ar; s=b?ws:as; nn=*s; + zn=(b?wn:an)/nn; m=(b?an:wn)/nn; m=m?m:1; n=zn/m; + switch(t){ + case B01: + {B*av=BAV(a),u,*wv=BAV(w);I*zu,*zv; + GA(z,INT,zn,r-1,1+s); zu=AV(z); + if(1==n){ + zv=zu; DO(m, *zv++ =*av++**wv++;); + DO(nn-1, zv=zu; DO(m, *zv+++=*av++**wv++;);); + }else if(b){ + zv=zu; DO(m, u=*av++; DO(n, *zv++ =u**wv++;);); + DO(nn-1, zv=zu; DO(m, u=*av++; if(u)DO(n, *zv+++=u**wv++;) else wv+=n;);); + }else{ + zv=zu; DO(m, u=*wv++; DO(n, *zv++ =u**av++;);); + DO(nn-1, zv=zu; DO(m, u=*wv++; if(u)DO(n, *zv+++=u**av++;) else av+=n;);); + }} + break; +#if !SY_64 + case INT: + {D u,*zu,*zv;I*av=AV(a),*wv=AV(w); + GA(z,FL,zn,r-1,1+s); zu=DAV(z); + if(1==n){ + zv=zu; DO(m, *zv++ =*av++*(D)*wv++;); + DO(nn-1, zv=zu; DO(m, *zv+++=*av++*(D)*wv++;);); + }else if(b){ + zv=zu; DO(m, u=(D)*av++; DO(n, *zv++ =u**wv++;);); + DO(nn-1, zv=zu; DO(m, u=(D)*av++; if(u)DO(n, *zv+++=u**wv++;) else wv+=n;);); + }else{ + zv=zu; DO(m, u=(D)*wv++; DO(n, *zv++ =u**av++;);); + DO(nn-1, zv=zu; DO(m, u=(D)*wv++; if(u)DO(n, *zv+++=u**av++;) else av+=n;);); + } + RZ(z=icvt(z)); + } + break; +#endif + case FL: + {D*av=DAV(a),u,v,*wv=DAV(w),*zu,*zv; + GA(z,FL,zn,r-1,1+s); zu=DAV(z); + NAN0; + if(1==n){ + zv=zu; DO(m, u=*av++; v=*wv++; *zv++ =u&&v?u*v:0; ); + DO(nn-1, zv=zu; DO(m, u=*av++; v=*wv++; *zv+++=u&&v?u*v:0; );); + }else if(b){ + zv=zu; DO(m, u=*av++; DO(n, v=*wv++; *zv++ =u&&v?u*v:0;);); + DO(nn-1, zv=zu; DO(m, u=*av++; if(u)DO(n, v=*wv++; *zv+++= v?u*v:0;) else wv+=n;);); + }else{ + zv=zu; DO(m, u=*wv++; DO(n, v=*av++; *zv++ =u&&v?u*v:0;);); + DO(nn-1, zv=zu; DO(m, u=*wv++; if(u)DO(n, v=*av++; *zv+++= v?u*v:0;) else av+=n;);); + } + NAN1; + }} + R z; +} /* a +/@:* w for non-scalar a and w */ + +static C sumbf[]={CSTARDOT,CMIN,CSTAR,CPLUSDOT,CMAX,CEQ,CNE,CSTARCO,CPLUSCO,CLT,CLE,CGT,CGE}; + +#define SUMBFLOOPW(BF) \ + {DO(q, memset(tv,C0,p); DO(255, DO(dw,tv[i]+=BF(*u,*v); ++u; ++v;);); DO(zn,zv[i]+=tu[i];)); \ + memset(tv,C0,p); DO(r, DO(dw,tv[i]+=BF(*u,*v); ++u; ++v;);); DO(zn,zv[i]+=tu[i];) ; \ + } +#define SUMBFLOOPX(BF) \ + {DO(q, memset(tv,C0,p); DO(255, DO(dw,tv[i]+=BF(*u,*v); ++u; ++v;); \ + av+=zn; u=(UI*)av; wv+=zn; v=(UI*)wv;); DO(zn,zv[i]+=tu[i];)); \ + memset(tv,C0,p); DO(r, DO(dw,tv[i]+=BF(*u,*v); ++u; ++v;); \ + av+=zn; u=(UI*)av; wv+=zn; v=(UI*)wv;); DO(zn,zv[i]+=tu[i];) ; \ + } +#if SY_ALIGN +#define SUMBFLOOP(BF) SUMBFLOOPW(BF) +#else +#define SUMBFLOOP(BF) if(zn%SZI)SUMBFLOOPX(BF) else SUMBFLOOPW(BF) +#endif + +static A jtsumatgbool(J jt,A a,A w,C id){A t,z;B*av,*wv;I dw,n,p,q,r,*s,zn,*zv;UC*tu;UI*tv,*u,*v; + RZ(a&&w); + s=AS(w); n=*s; + zn=AN(w)/n; dw=(zn+SZI-1)/SZI; p=dw*SZI; + q=n/255; r=n%255; + GA(z,INT,zn,AR(w)-1,1+s); zv=AV(z); memset(zv,C0,zn*SZI); + GA(t,INT,dw,1,0); tu=(UC*)AV(t); tv=(UI*)tu; + av=BAV(a); u=(UI*)av; + wv=BAV(w); v=(UI*)wv; + switch(id){ + case CMIN: + case CSTAR: + case CSTARDOT: SUMBFLOOP(AND ); break; + case CMAX: + case CPLUSDOT: SUMBFLOOP(OR ); break; + case CEQ: SUMBFLOOP(EQ ); break; + case CNE: SUMBFLOOP(NE ); break; + case CSTARCO: SUMBFLOOP(NAND); break; + case CPLUSCO: SUMBFLOOP(NOR ); break; + case CLT: SUMBFLOOP(LT ); break; + case CLE: SUMBFLOOP(LE ); break; + case CGT: SUMBFLOOP(GT ); break; + case CGE: SUMBFLOOP(GE ); break; + } + R z; +} /* a +/@:g w for boolean a,w where a-:&(* /@$)w; see also plusinsB */ + +DF2(jtfslashatg){A fs,gs,y,z;B b,bb,sb=0;C*av,c,d,*wv;I ak,an,ar,*as,at,cv,cvf,m, + n,nn,r,*s,t,wk,wn,wr,*ws,wt,yt,zn,zt;V*sv;VF ado,adof; + RZ(a&&w&&self); + an=AN(a); ar=AR(a); as=AS(a); at=an?AT(a):B01; sv=VAV(self); + wn=AN(w); wr=AR(w); ws=AS(w); wt=wn?AT(w):B01; b=ar<=wr; r=b?wr:ar; s=b?ws:as; nn=r?*s:1; + ASSERT(!ICMP(as,ws,MIN(ar,wr)),EVLENGTH); + if(SPARSE&(at|wt)||!an||!wn||2>nn){b=CFORK==sv->id; R df1(df2(a,w,b?sv->h:sv->g),b?sv->g:sv->f);} + zn=(b?wn:an)/nn; m=(b?an:wn)/nn; m=m?m:1; n=zn/m; + if(CFORK==sv->id){fs=sv->g; gs=sv->h;}else{fs=sv->f; gs=sv->g;} + y=VAV(fs)->f; c=ID(y); d=ID(gs); + RZ(var(d,mtv,mtv,at,wt,&ado, &cv )); yt=rtype(cv ); t=atype(cv); + RZ(var(c,mtv,mtv,yt,yt,&adof,&cvf)); zt=rtype(cvf); + if(c==CPLUS){ + if(at&B01&&wt&B01&&1==n&&(0==zn%SZI||!SY_ALIGN)&&strchr(sumbf,d))R sumatgbool(a,w,d); + if(d==CSTAR){ + if(ar&&wr&&at==wt&&at&B01+FL+(INT*!SY_64))R sumattymes(a,w,self); + if(!ar||!wr){ + z=!ar?tymes(a,df1(w,fs)):tymes(w,df1(a,fs)); + if(jt->jerr==EVNAN)RESETERR else R z; + }} + sb=1&&yt&B01; + } + if(!(sb||yt==zt))R df1(df2(a,w,gs),fs); + if(t){ + bb=1&&t&XNUM; + if(t!=at)RZ(a=bb?xcvt(cv&VXEQ?XMEXMT:cv&VXFC?XMFLR:cv&VXCF?XMCEIL:XMEXACT,a):cvt(t,a)); + if(t!=wt)RZ(w=bb?xcvt(cv&VXEQ?XMEXMT:cv&VXCF?XMFLR:cv&VXFC?XMCEIL:XMEXACT,w):cvt(t,w)); + } + ak=(an/nn)*bp(AT(a)); wk=(wn/nn)*bp(AT(w)); + GA(y,yt,zn,1,0); + GA(z,zt,zn,r-1,1+s); + if(sb){A t;I j,tn,*zv;UC*tc;UI*ti,*yv; /* +/@:g for boolean-valued g */ + av=CAV(a); wv=CAV(w); yv=(UI*)AV(y); zv=AV(z); memset(zv,C0,zn*SZI); + tn=(zn+SZI-1)/SZI; GA(t,INT,tn,1,0); tc=(UC*)AV(t); ti=(UI*)tc; + for(j=nn;0<j;j-=255){ + memset(ti,C0,tn*SZI); + DO(MIN(j,255), ado(jt,b,m,n,yv,av,wv); av+=ak; wv+=wk; DO(tn,ti[i]+=yv[i];);); + DO(zn, zv[i]+=tc[i];); + }}else{A z1;B p=0;C*yv,*zu,*zv; + av=CAV(a)+ak*(nn-1); wv=CAV(w)+wk*(nn-1); yv=CAV(y); zv=CAV(z); + GA(z1,zt,zn,r-1,1+s); zu=CAV(z1); + ado(jt,b,m,n,zv,av,wv); + DO(nn-1, av-=ak; wv-=wk; ado(jt,b,m,n,yv,av,wv); adof(jt,b,zn,1L,p?zv:zu,yv,p?zu:zv); p=!p;); + if(NEVM<jt->jerr){jt->jerr=0; z=df1(df2(a,w,gs),fs);}else if(p)z=z1; + } + RE(0); R z; +} /* a f/@:g w */
new file mode 100644 --- /dev/null +++ b/va2s.c @@ -0,0 +1,143 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Atomic (Scalar) Dyadic Verbs on Sparse Arrays */ + +#include "j.h" +#include "ve.h" + + +static A jtvaspc(J jt,A a,A w,C id,VF ado,I cv,I t,I zt,I af,I acr,I wf,I wcr,I f,I r){A q;I*as,*v,*ws; + as=AS(a); + ws=AS(w); + GA(q,INT,f+r,1,0); v=AV(q); + if(r>acr){ICPY(v,wf+ws,r); RZ(a=irs2(vec(INT,r-acr,acr+v),a,0L,1L,0L,jtreshape));} + if(r>wcr){ICPY(v,af+as,r); RZ(w=irs2(vec(INT,r-wcr,wcr+v),w,0L,1L,0L,jtreshape));} + R vasp(a,w,id,ado,cv,t,zt,af,r,wf,r,f,r); +} /* prefix agreement on cells */ + +F1(jtvaspz){A e,x,y;B c,*u,*xu,*xv;I j,n,*v,*yu,*yv,xc,yc;P*wp; + if(!(SB01&AT(w)))R w; + wp=PAV(w); + e=SPA(wp,e); c=!*BAV(e); + x=SPA(wp,x); xv=xu=u=BAV(x); xc=aii(x); n=*AS(x); j=0; + y=SPA(wp,i); yv=yu= AV(y); yc=*(1+AS(y)); + if(!(n&&xc&&yc))R w; + while(u=memchr(xv+xc*j,c,xc*(n-j))){ + j=(u-xv)/xc; v=yv+yc*j; + if(v==yu){yu+=yc; xu+=xc;} + else{DO(yc, *yu++=*v++;); if(1<xc){MC(xu,xv+xc*j,xc); xu+=xc;}} + ++j; + } + n=(yu-yv)/yc; + if(1==xc)memset(xv,c,n); + *AS(y)=n; AN(y)=n*yc; + *AS(x)=n; AN(x)=n*xc; + R w; +} /* post processing on result; modifies argument in place */ + +static A jtvasp0(J jt,A a,A w,VF ado,I cv,I t,I zt){A e,x,xx,y,z,ze,zx;B b;I n;P*p,*zp; + if(b=1&&AR(a)){xx=a; y=w;}else{xx=w; y=a;} + p=PAV(xx); e=SPA(p,e); x=SPA(p,x); n=AN(x); + if(t){ + if(t!=AT(x)){RZ(x=cvt(t,x)); RZ(e=cvt(t,e));} + if(t!=AT(y)) RZ(y=cvt(t,y)); + } + GA(ze,zt,1,0, 0 ); ado(jt, 0,1L,1L,AV(ze),b?AV(e):AV(y),b?AV(y):AV(e)); RE(0); + GA(zx,zt,n,AR(x),AS(x)); if(n)ado(jt,!b,1L,n, AV(zx),b?AV(x):AV(y),b?AV(y):AV(x)); RE(0); + if(cv&VRI+VRD){RZ(ze=cvz(cv,ze)); RZ(zx=cvz(cv,zx));} + GA(z,STYPE(AT(zx)),1,AR(xx),AS(xx)); zp=PAV(z); + SPB(zp,a,ca(SPA(p,a))); + SPB(zp,i,ca(SPA(p,i))); + SPB(zp,e,ze); + SPB(zp,x,zx); + R vaspz(z); +} /* one argument is sparse and the other is scalar */ + +/* +static B jtvaspprep(J jt,A a,A w,I t,I af,I acr,I wf,I wcr,I f,I r,A*ae,A*ay,A*ax,A*we,A*wy,A*wx,A*za){ + A aa,e,x,wa;B*b,sa,sw;I c,d,m,n,*u,*v;P*ap,*wp; + sa=1&&AT(a)&SPARSE; + sw=1&&AT(w)&SPARSE; + GA(x,B01,f+r,1,0); b=BAV(x); memset(b,C1,f); memset(b+f,C0,r); + if(sa){ap=PAV(a); aa=SPA(ap,a); u=AV(aa); d=f-af; DO(AN(aa), c=u[i]; if(af<=c)b[c+d]=1;);} + if(sw){wp=PAV(w); wa=SPA(wp,a); v=AV(wa); d=f-wf; DO(AN(wa), c=v[i]; if(wf<=c)b[c+d]=1;);} + GA(x,INT,f+r,1,0); u=AV(x); m=0; DO(af, if(b[i])u[m++]=i;); DO(acr, if(b[f+i])u[m++]=af+i;); + GA(x,INT,f+r,1,0); v=AV(x); n=0; DO(wf, if(b[i])v[n++]=i;); DO(wcr, if(b[f+i])v[n++]=wf+i;); + if(!sa||m!=AN(aa)||memcmp(u,AV(aa),m*SZI))RZ(a=reaxis(vec(INT,m,u),a)); + if(!sw||n!=AN(wa)||memcmp(v,AV(wa),n*SZI))RZ(w=reaxis(vec(INT,n,v),w)); + ap=PAV(a); *ae=e=SPA(ap,e); *ay=SPA(ap,i); *ax=x=SPA(ap,x); if(t&&t!=AT(x)){RZ(*ae=cvt(t,e)); RZ(*ax=cvt(t,x));} + wp=PAV(w); *we=e=SPA(wp,e); *wy=SPA(wp,i); *wx=x=SPA(wp,x); if(t&&t!=AT(x)){RZ(*we=cvt(t,e)); RZ(*wx=cvt(t,x));} + RZ(*za=ifb(f+r,b)); + R 1; +} +*/ + +static B jtvaspeqprep(J jt,A a,A w,I t,I f,I r,A*ae,A*ay,A*ax,A*we,A*wy,A*wx,A*za){ + A aa,e,q,x,wa;B*b,sa,sw;I n,*v;P*p; + sa=1&&AT(a)&SPARSE; + sw=1&&AT(w)&SPARSE; n=f+r; + GA(x,B01,n,1,0); b=BAV(x); memset(b,C0,n); + if(sa){p=PAV(a); aa=SPA(p,a); v=AV(aa); DO(AN(aa), b[v[i]]=1;);} + if(sw){p=PAV(w); wa=SPA(p,a); v=AV(wa); DO(AN(wa), b[v[i]]=1;);} + RZ(*za=q=ifb(n,b)); + if(!sa||!equ(q,aa))RZ(a=reaxis(q,a)); + if(!sw||!equ(q,wa))RZ(w=reaxis(q,w)); + p=PAV(a); *ae=e=SPA(p,e); *ay=SPA(p,i); *ax=x=SPA(p,x); if(t&&t!=AT(x)){RZ(*ae=cvt(t,e)); RZ(*ax=cvt(t,x));} + p=PAV(w); *we=e=SPA(p,e); *wy=SPA(p,i); *wx=x=SPA(p,x); if(t&&t!=AT(x)){RZ(*we=cvt(t,e)); RZ(*wx=cvt(t,x));} + R 1; +} + +static I zcount(A ay,A wy,B ab,B wb){I c,d,i,j,m,n,*u,*v,yc; + v=AS(ay); m=v[0]; yc=v[1]; n=*AS(wy); + i=j=d=0; u=AV(ay); v=AV(wy); + while(m>i&&n>j){ + c=0; DO(yc, if(c=u[i]-v[i])break;); + if(0>c) {u+=yc; ++i; if(wb)++d;} + else if(c){ v+=yc; ++j; if(ab)++d;} + else {u+=yc; ++i; v+=yc; ++j; ++d;} + } + R d+wb*(m-i)+ab*(n-j); +} /* item count for sparse result */ + +#define ADVA axv+=ak; u+=yc; ++i; +#define ADVW wxv+=wk; v+=yc; ++j; +#define FLUSH if(d){c=d*yc; ICPY(zyv,u-c,c); ado(jt,0,d*xc,1L,zxv,axv-d*ak,wxv-d*wk); \ + zxv+=d*zk; zyv+=c; d=0;} + +static A jtvaspeq(J jt,A a,A w,C id,VF ado,I cv,I t,I zt,I f,I r){A ae,ax,ay,we,wx,wy,z,za,ze,zx,zy; + B ab=1,wb=1;C*aev,*axv,*wev,*wxv,*zxv;I ak,c,d,i,j,m,n,*u,*v,wk,xc,yc,zk,*zyv;P*zp; + RZ(vaspeqprep(a,w,t,f,r,&ae,&ay,&ax,&we,&wy,&wx,&za)); + if(id==CSTAR||id==CSTARDOT){ab=!equ(ae,zero); wb=!equ(we,zero);} + v=AS(ay); m=v[0]; yc=v[1]; xc=aii(ax); n=*AS(wy); + aev=CAV(ae); axv=CAV(ax); ak=xc*bp(AT(ax)); + wev=CAV(we); wxv=CAV(wx); wk=xc*bp(AT(wx)); + d=zcount(ay,wy,ab,wb); + GA(zx,zt, d*xc,AR(ax),AS(ax)); *AS(zx)=d; zxv=CAV(zx); zk=xc*bp(zt); + GA(zy,INT,d*yc,2, AS(ay)); *AS(zy)=d; zyv= AV(zy); + i=j=d=0; u=AV(ay); v=AV(wy); + while(m>i&&n>j){ + c=0; DO(yc, if(c=u[i]-v[i])break;); + if(0>c) {FLUSH; if(wb){ICPY(zyv,u,yc); ado(jt,0,1L,xc,zxv,axv,wev); zxv+=zk; zyv+=yc;} ADVA;} + else if(c){FLUSH; if(ab){ICPY(zyv,v,yc); ado(jt,1,1L,xc,zxv,aev,wxv); zxv+=zk; zyv+=yc;} ADVW;} + else {++d; ADVA; ADVW;} + } + FLUSH; + if (wb&&m>i){c=m-i; ICPY(zyv,u,c*yc); ado(jt,0,1L,c*xc,zxv,axv,wev);} + else if(ab&&n>j){c=n-j; ICPY(zyv,v,c*yc); ado(jt,1,1L,c*xc,zxv,aev,wxv);} + GA(ze,zt,1,0,0); ado(jt,0,1L,1L,AV(ze),aev,wev); + RE(0); + if(cv&VRI+VRD){A e,x; RZ(e=cvz(cv,ze)); RZ(x=cvz(cv,zx)); if(AT(e)==AT(x)){ze=e; zx=x;}} + GA(z,STYPE(AT(zx)),1,AR(a),AS(a)); + zp=PAV(z); + SPB(zp,a,za); SPB(zp,e,ze); SPB(zp,i,zy); SPB(zp,x,zx); + R vaspz(z); +} /* frames and cell ranks equal */ + +A jtvasp(J jt,A a,A w,C id,VF ado,I cv,I t,I zt,I af,I acr,I wf,I wcr,I f,I r){A fs,z; + if(!AR(a)||!AR(w))R vasp0(a,w,ado,cv,t,zt); + if((SPARSE&AT(a)||SPARSE&AT(w))&&spmult(&z,a,w,id,af,acr,wf,wcr))R z; + if(af!=wf){RZ(fs=ds(id)); R sprank2(a,w,0L,acr,wcr,VAV(fs)->f2);} + if(acr!=wcr)R vaspc(a,w,id,ado,cv,t,zt,af,acr,wf,wcr,f,r); + R vaspeq(a,w,id,ado,cv,t,zt,f,r); +} /* scalar dyadic fns with one or both arguments sparse */
new file mode 100644 --- /dev/null +++ b/vamultsp.c @@ -0,0 +1,12 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: "Multiplication" on Sparse Arrays */ + +#include "j.h" +#include "ve.h" + + +B jtspmult(J jt,A*z,A a,A w,C id,I af,I acr,I wf,I wcr){ + R 0; +} /* scalar dyadic fns with one or both arguments sparse */
new file mode 100644 --- /dev/null +++ b/vasm.h @@ -0,0 +1,517 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Assembly Routines for Integer + * - with Overflow */ + +/* fvv zv=.xv+yv 0<n */ +/* fv1 zv=.xv+y 0<n */ +/* f1v zv=.x +yv 0<n */ +/* frv zv=.xv+zv 0<n */ +/* fr z =.+/ xv 1<n */ +/* fp zv=.+/\ xv 1<n */ +/* fs zv=.+/\.xv 1<n */ + +#ifndef NOASM /* builder defines NOASM to do I overflow in C instead of asm */ + +#if SY_WIN32 && !SY_64 && !SY_WINCE +#define OVF + +#define PLUSVV(m,z,x,y) \ +{ \ +__asm mov ecx,m \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,y \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm sub edx,4 \ +__asm pvv20: mov eax,[esi+ecx*4] \ +__asm add eax,[edx+ecx*4] \ +__asm jo pvv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop pvv20 \ +__asm jmp pvv40 \ +__asm pvv30: mov er,EWOV \ +__asm pvv40: \ +} + +#define PLUS1V(n,z,u,y) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov edx,u \ +__asm mov esi,y \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm p1v20: mov eax,[esi+ecx*4] \ +__asm add eax,edx \ +__asm jo p1v30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop p1v20 \ +__asm jmp p1v40 \ +__asm p1v30: mov er,EWOV \ +__asm p1v40: \ +} + +#define PLUSV1(n,z,x,v) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,v \ +__asm mov esi,x \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm pv120: mov eax,[esi+ecx*4] \ +__asm add eax,edx \ +__asm jo pv130 \ +__asm mov [edi+ecx*4],eax \ +__asm loop pv120 \ +__asm jmp pv140 \ +__asm pv130: mov er,EWOV \ +__asm pv140: \ +} + +#define PLUSRV(d,z,x) \ +{ \ +__asm mov ecx,d \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm prv20: mov eax,[esi+ecx*4] \ +__asm add eax,[edi+ecx*4] \ +__asm jo prv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop prv20 \ +__asm jmp prv40 \ +__asm prv30: mov er,EWOV \ +__asm prv40: \ +} + +#define PLUSR(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm xor eax,eax \ +__asm pr20: add eax,[esi+ecx*4] \ +__asm jo pr30 \ +__asm loop pr20 \ +__asm mov [edi],eax \ +__asm jmp pr40 \ +__asm pr30: mov er,EWOV \ +__asm pr40: \ +} + +#define PLUSP(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm xor edx,edx \ +__asm xor eax,eax \ +__asm mov ebx,ecx \ +__asm sar ecx,1 \ +__asm pp20: add eax,[esi+edx*4] \ +__asm jo pp30 \ +__asm mov [edi+edx*4],eax \ +__asm inc edx \ +__asm add eax,[esi+edx*4] \ +__asm jo pp30 \ +__asm mov [edi+edx*4],eax \ +__asm inc edx \ +__asm loop pp20 \ +__asm and ebx,1 \ +__asm jz pp40 \ +__asm add eax,[esi+edx*4] \ +__asm jo pp30 \ +__asm mov [edi+edx*4],eax \ +__asm jmp pp40 \ +__asm pp30: mov er,EWOV \ +__asm pp40: \ +} + +#define PLUSS(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm sub edi,4 \ +__asm xor eax,eax \ +__asm ps20: add eax,[esi+ecx*4] \ +__asm jo ps30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop ps20 \ +__asm jmp ps40 \ +__asm ps30: mov er,EWOV \ +__asm ps40: \ +} + + +#define MINUSVV(m,z,x,y) \ +{ \ +__asm mov ecx,m \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,y \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm sub edx,4 \ +__asm mvv20: mov eax,[esi+ecx*4] \ +__asm sub eax,[edx+ecx*4] \ +__asm jo mvv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop mvv20 \ +__asm jmp mvv40 \ +__asm mvv30: mov er,EWOV \ +__asm mvv40: \ +} + +#define MINUS1V(n,z,u,y) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm sub edi,4 \ +__asm mov edx,u \ +__asm mov esi,y \ +__asm sub esi,4 \ +__asm m1v20: mov eax,edx \ +__asm sub eax,[esi+ecx*4] \ +__asm jo m1v30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop m1v20 \ +__asm jmp m1v40 \ +__asm m1v30: mov er,EWOV \ +__asm m1v40: \ +} + +#define MINUSV1(n,z,x,v) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,v \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm mv120: mov eax,[esi+ecx*4] \ +__asm sub eax,edx \ +__asm jo mv130 \ +__asm mov [edi+ecx*4],eax \ +__asm loop mv120 \ +__asm jmp mv140 \ +__asm mv130: mov er,EWOV \ +__asm mv140: \ +} + +#define MINUSRV(d,z,x) \ +{ \ +__asm mov ecx,d \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm mrv20: mov eax,[esi+ecx*4] \ +__asm sub eax,[edi+ecx*4] \ +__asm jo mrv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop mrv20 \ +__asm jmp mrv40 \ +__asm mrv30: mov er,EWOV \ +__asm mrv40: \ +} + +#define MINUSR(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm xor eax,eax \ +__asm mr20: mov edx,[esi+ecx*4] \ +__asm sub edx,eax \ +__asm jo mr30 \ +__asm mov eax,edx \ +__asm loop mr20 \ +__asm mov [edi],eax \ +__asm jmp mr40 \ +__asm mr30: mov er,EWOV \ +__asm mr40: \ +} + +#define MINUSP(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm xor edx,edx \ +__asm xor eax,eax \ +__asm mov ebx,ecx \ +__asm sar ecx,1 \ +__asm mp20: add eax,[esi+edx*4] \ +__asm jo mp30 \ +__asm mov [edi+edx*4],eax \ +__asm inc edx \ +__asm sub eax,[esi+edx*4] \ +__asm jo mp30 \ +__asm mov [edi+edx*4],eax \ +__asm inc edx \ +__asm loop mp20 \ +__asm and ebx,1 \ +__asm jz mp40 \ +__asm add eax,[esi+edx*4] \ +__asm jo mp30 \ +__asm mov [edi+edx*4],eax \ +__asm jmp mp40 \ +__asm mp30: mov er,EWOV \ +__asm mp40: \ +} + +#define MINUSS(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm sub edi,4 \ +__asm xor eax,eax \ +__asm ms20: mov edx,[esi+ecx*4] \ +__asm sub edx,eax \ +__asm jo ms30 \ +__asm mov eax,edx \ +__asm mov [edi+ecx*4],eax \ +__asm loop ms20 \ +__asm jmp ms40 \ +__asm ms30: mov er,EWOV \ +__asm ms40: \ +} + + +#define TYMESVV(m,z,x,y) \ +{ \ +__asm mov ecx,m \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,y \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm sub edx,4 \ +__asm tvv20: mov eax,[esi+ecx*4] \ +__asm imul eax,[edx+ecx*4] \ +__asm jo tvv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop tvv20 \ +__asm jmp tvv40 \ +__asm tvv30: mov er,EWOV \ +__asm tvv40: \ +} + +#define TYMES1V(n,z,u,y) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov edx,u \ +__asm mov esi,y \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm t1v20: mov eax,[esi+ecx*4] \ +__asm imul eax,edx \ +__asm jo t1v30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop t1v20 \ +__asm jmp t1v40 \ +__asm t1v30: mov er,EWOV \ +__asm t1v40: \ +} + +#define TYMESV1(n,z,x,v) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm mov edx,v \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm tv120: mov eax,[esi+ecx*4] \ +__asm imul eax,edx \ +__asm jo tv130 \ +__asm mov [edi+ecx*4],eax \ +__asm loop tv120 \ +__asm jmp tv140 \ +__asm tv130: mov er,EWOV \ +__asm tv140: \ +} + +#define TYMESRV(d,z,x) \ +{ \ +__asm mov ecx,d \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub edi,4 \ +__asm sub esi,4 \ +__asm trv20: mov eax,[esi+ecx*4] \ +__asm imul eax,[edi+ecx*4] \ +__asm jo trv30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop trv20 \ +__asm jmp trv40 \ +__asm trv30: mov er,EWOV \ +__asm trv40: \ +} + +#define TYMESR(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm mov eax,1 \ +__asm tr20: imul eax,[esi+ecx*4] \ +__asm jo tr30 \ +__asm loop tr20 \ +__asm mov [edi],eax \ +__asm jmp tr40 \ +__asm tr30: mov er,EWOV \ +__asm tr40: \ +} + +#define TYMESP(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm xor edx,edx \ +__asm mov eax,1 \ +__asm tp20: imul eax,[esi+edx*4] \ +__asm jo tp30 \ +__asm mov [edi+edx*4],eax \ +__asm inc edx \ +__asm loop tp20 \ +__asm jmp tp40 \ +__asm tp30: mov er,EWOV \ +__asm tp40: \ +} + +#define TYMESS(n,z,x) \ +{ \ +__asm mov ecx,n \ +__asm mov edi,z \ +__asm mov esi,x \ +__asm sub esi,4 \ +__asm sub edi,4 \ +__asm mov eax,1 \ +__asm ts20: imul eax,[esi+ecx*4] \ +__asm jo ts30 \ +__asm mov [edi+ecx*4],eax \ +__asm loop ts20 \ +__asm jmp ts40 \ +__asm ts30: mov er,EWOV \ +__asm ts40: \ +} + +#endif + +#if SY_64 /* win64 and linux64 asm routines */ +#define OVF + +C asmplusvv(I,I*,I*,I*); +C asmminusvv(I,I*,I*,I*); +C asmtymesvv(I,I*,I*,I*); + +C asmplus1v(I,I*,I,I*); +C asmminus1v(I,I*,I,I*); +C asmtymes1v(I,I*,I,I*); + +C asmminusv1(I,I*,I*,I); + +C asmplusr(I,I*,I*); +C asmminusr(I,I*,I*); +C asmtymesr(I,I*,I*); + +C asmplusrv(I,I*,I*); +C asmminusrv(I,I*,I*); +C asmtymesrv(I,I*,I*); + +C asmpluss(I,I*,I*); +C asmminuss(I,I*,I*); +C asmtymess(I,I*,I*); + +C asmplusp(I,I*,I*); +C asmminusp(I,I*,I*); +C asmtymesp(I,I*,I*); + +C asminnerprod(I,I*,I*,I*,I); +C asminnerprodx(I,I*,I,I*); + +#define PLUSVV(m,z,x,y) er=asmplusvv(m,z,x,y) +#define MINUSVV(m,z,x,y) er=asmminusvv(m,z,x,y) +#define TYMESVV(m,z,x,y) er=asmtymesvv(m,z,x,y) + +#define PLUSRV(d,z,x) er=asmplusrv(d,z,x) +#define MINUSRV(d,z,x) er=asmminusrv(d,z,x) +#define TYMESRV(d,z,x) er=asmtymesrv(d,z,x) + +#define PLUS1V(n,z,u,y) er=asmplus1v(n,z,u,y) +#define MINUS1V(n,z,u,y) er=asmminus1v(n,z,u,y) +#define TYMES1V(n,z,u,y) er=asmtymes1v(n,z,u,y) + +#define PLUSV1(n,z,x,v) PLUS1V(n,z,v,x) +#define MINUSV1(n,z,x,v) er=asmminusv1(n,z,x,v) +#define TYMESV1(n,z,x,v) TYMES1V(n,z,v,x) + +#define PLUSR(n,z,x) er=asmplusr(n,z,x) +#define MINUSR(n,z,x) er=asmminusr(n,z,x) +#define TYMESR(n,z,x) er=asmtymesr(n,z,x) + +#define PLUSS(n,z,x) er=asmpluss(n,z,x) +#define MINUSS(n,z,x) er=asmminuss(n,z,x) +#define TYMESS(n,z,x) er=asmtymess(n,z,x) + +#define PLUSP(n,z,x) er=asmplusp(n,z,x) +#define MINUSP(n,z,x) er=asmminusp(n,z,x) +#define TYMESP(n,z,x) er=asmtymesp(n,z,x) + +#endif + +#endif + +/* C routines for platforms without asm support */ +#ifndef OVF + +#if SY_64 +#define DI LD +#else +#define DI D +#endif + +#define PLUSVV(m,z,x,y) {B p; DO(m, p=0>*x; *z=*x+*y; BOV(p==0>*y&&p!=0>*z); z++; x++; y++;);} +#define MINUSVV(m,z,x,y) {B p; DO(m, p=0>*x; *z=*x-*y; BOV(p!=0>*y&&p!=0>*z); z++; x++; y++;);} +#define TYMESVV(m,z,x,y) {DI t; DO(m, t=*x*(DI)*y; *z=(I)t; BOV(t<IMIN||IMAX<t ); z++; x++; y++;);} + +#define PLUS1V(n,z,u,y) {B p=0>u; DO(n, z[i]=u+y[i]; BOV(p==0>y[i]&&p!=0>z[i]););} +#define MINUS1V(n,z,u,y) {B p=0>u; DO(n, z[i]=u-y[i]; BOV(p!=0>y[i]&&p!=0>z[i]););} +#define TYMES1V(n,z,u,y) {DI d=u,t; DO(n, t=d*y[i]; z[i]=(I)t; BOV(t<IMIN||IMAX<t ););} + +#define PLUSV1(n,z,x,v) PLUS1V(n,z,v,x) +#define TYMESV1(n,z,x,v) TYMES1V(n,z,v,x) +#define MINUSV1(n,z,x,v) {B p=0>v; DO(n, z[i]=x[i]-v; BOV(p!=0>x[i]&&p==0>z[i]););} + +#define PLUSP(n,z,x) {B p;I s=0; DO(n, p=0>s; *z=s+=*x; BOV(p==0>*x&&p!=0>s); z++; x++;);} +#define MINUSP(n,z,x) {B p=0;DI t=0; DO(n, t=p?t-*x:t+*x; *z=(I)t; BOV(t<IMIN||IMAX<t ); z++; x++; p=!p;);} +#define TYMESP(n,z,x) {DI t=1; DO(n, t*=*x; *z=(I)t; BOV(t<IMIN||IMAX<t ); z++; x++;);} + +#define PLUSR(n,z,x) {B p;I s=0; DO(n, p=0>s; s+=*x; BOV(p==0>*x&&p!=0>s); x++; ); *z=s;} +#define MINUSR(n,z,x) {B p=0;DI t=0; DO(n, t=p?t-*x:t+*x; BOV(t<IMIN||IMAX<t ); x++; p=!p;); *z=(I)t;} +#define TYMESR(n,z,x) {DI t=1; DO(n, t*=*x; BOV(t<IMIN||IMAX<t ); x++; ); *z=(I)t;} + +#define PLUSRV(d,z,x) {B p; DO(d, p=0>*z; *z+=*x; BOV(p==0>*x&&p!=0>*z); x++; z++;);} +#define MINUSRV(d,z,x) {DI t; DO(d, t=*x-(DI)*z; *z=(I)t; BOV(t<IMIN||IMAX<t ); x++; z++;);} +#define TYMESRV(d,z,x) {DI t; DO(d, t=*x*(DI)*z; *z=(I)t; BOV(t<IMIN||IMAX<t ); x++; z++;);} + +#define PLUSS(n,z,x) {B p;I s=0; x+=n; z+=n; DO(n, --x; p=0>s; *--z=s+=*x; BOV(p==0>*x&&p!=0>s););} +#define MINUSS(n,z,x) {B p;I s=0; x+=n; z+=n; DO(n, --x; p=0>s; *--z=s=*x-s; BOV(p!=0>*x&&p==0>s););} +#define TYMESS(n,z,x) {DI t=1; x+=n; z+=n; DO(n, --x; t*=*x; *--z=(I)t; BOV(t<IMIN||IMAX<t ););} + +#endif
new file mode 100644 --- /dev/null +++ b/vb.c @@ -0,0 +1,192 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Boolean-Valued */ + +#include "j.h" +#include "ve.h" + + +BPFX( andBB, AND ,BAND, AND, BAND ) +BPFX( orBB, OR ,BOR, OR, BOR ) +BPFX(nandBB, NAND,BNAND,NAND,BNAND) +BPFX( norBB, NOR ,BNOR, NOR, BNOR ) + + +F1(jtrazein){R df2(w,box(raze(w)),amp(swap(ds(CEPS)),ds(COPE)));} + + +static F2(jtebarmat){A ya,yw,z;B b,*zv;C*au,*av,*u,*v,*v0,*wu,*wv;I*as,c,i,k,m,n,r,s,si,sj,t,*ws; + RZ(a&&w); + as=AS(a); av=CAV(a); + ws=AS(w); v=v0=wv=CAV(w); + si=as[0]; m=1+ws[0]-si; + sj=as[1]; n=1+ws[1]-sj; + t=AT(w); k=bp(t); c=ws[1]; r=k*c; s=k*sj; + GA(z,B01,AN(w),2,ws); zv=BAV(z); memset(zv,C0,AN(z)); + if(t&B01+LIT+INT||0==jt->ct&&t&FL+CMPX) + for(i=0;i<m;++i){ + DO(n, u=av; b=0; DO(si, if(b=memcmp(u,v,s))break; u+=s; v+=r;); v=v0+=k; zv[i]=!b;); + zv+=c; v=v0=wv+=r; + }else{ + GA(ya,t,sj,1,0); au=CAV(ya); + GA(yw,t,sj,1,0); wu=CAV(yw); + for(i=0;i<m;++i){ + DO(n, u=av; b=0; DO(si, MC(au,u,s); MC(wu,v,s); if(b=!equ(ya,yw) )break; u+=s; v+=r;); v=v0+=k; zv[i]=!b;); + zv+=c; v=v0=wv+=r; + }} + R z; +} /* E. on matrix arguments */ + +static F2(jtebarvec){A y,z;B*zv;C*av,*wv,*yv;I an,k,n,s,t,wn; + RZ(a&&w); + an=AN(a); av=CAV(a); + wn=AN(w); wv=CAV(w); n=1+wn-an; + t=AT(w); k=bp(t); s=k*an; + GA(z,B01,wn,1,0); zv=BAV(z); + if(an&&wn>an)memset(zv+n,C0,wn-n); else memset(zv,C0,wn); + if(t&INT||0==jt->ct&&t&FL+CMPX)DO(n, zv[i]=!memcmp(av,wv,s); wv+=k;) + else{GA(y,t,an,AR(a),0); yv=CAV(y); DO(n, MC(yv,wv,s); zv[i]=equ(a,y); wv+=k;);} + R z; +} /* E. on vector arguments */ + +/* preparations for ebar */ +/* return code meaning: */ +/* >0 is cardinality of range */ +/* <0: */ +/* -1: not homogeneous */ +/* -2: rank is 2 */ +/* -3: rank > 2 */ +/* -4: not discrete type or range too large */ + +static I jtebarprep(J jt,A a,A w,A*za,A*zw,I*zc){I ar,at,c=0,ca,cw,d=IMAX,da,dw,m,n,t,wr,wt; + ar=AR(a); at=AT(a); m=AN(a); + wr=AR(w); wt=AT(w); n=AN(w); + ASSERT(ar==wr||!ar&&1==wr,EVRANK); + if(m&&n&&!HOMO(at,wt))R -1; + if(m&&n)RE(t=maxtype(at,wt)) else t=m?at:n?wt:B01; + if(t!=at)RZ(a=cvt(t,a)); + if(t!=wt)RZ(w=cvt(t,w)); + *za=a; *zw=w; *zc=c; + if(1<wr)R 2==wr?-2:-3; + switch(t){ + case INT: irange(m,AV(a),&ca,&da); if(da)irange(n,AV(w),&cw,&dw); + if(da&&dw){c=MIN(ca,cw); d=MAX(ca+da,cw+dw)-c;} + if(0<c&&c+d<=4*n){d+=c; c=0;} break; + case C2T: d=65536; break; + case LIT: d=256; break; + case B01: d=2; break; + } + R t&B01+LIT+C2T||t&INT&&0<d&&d<=4*n ? d : -4; +} + +#define EBLOOP(T,SUB0,SUB1,ZFUNC) \ + {T*u=(T*)av,*v=(T*)wv; \ + DO(m, yv[SUB0]=m-i;); \ + while(k< p){for(i=0;i<m&&u[i]==v[k+i];++i); ZFUNC; k+=yv[SUB1];} \ + if (k==p){for(i=0;i<m&&u[i]==v[k+i];++i); ZFUNC; } \ + } + +F2(jtebar){PROLOG;A y,z;B*zv;C*av,*wv;I c,d,i,k=0,m,n,p,*yv; + RZ(a&&w); + RE(d=ebarprep(a,w,&a,&w,&c)); + av=CAV(a); m=AN(a); + wv=CAV(w); n=AN(w); p=n-m; + switch(d){ + case -1: R reshape(shape(w),zero); + case -2: R ebarmat(a,w); + case -3: R df2(shape(a),w,cut(amp(a,ds(CMATCH)),num[3])); + case -4: R ebarvec(a,w); + } + GA(z,B01,n,AR(w),0); zv=BAV(z); memset(zv,C0,n); + GA(y,INT,d,1, 0); yv= AV(y); DO(d, yv[i]=1+m;); + switch(AT(w)){ + case INT: if(c)EBLOOP(I, u[i]-c,v[k+m]-c, zv[k]=i==m) + else EBLOOP(I, u[i], v[k+m], zv[k]=i==m); break; + case C2T: EBLOOP(US,u[i], v[k+m], zv[k]=i==m); break; + default: EBLOOP(UC,u[i], v[k+m], zv[k]=i==m); + } + EPILOG(z); +} /* Daniel M. Sunday, CACM 1990 8, 132-142 */ + + +F2(jti1ebar){A y;C*av,*wv;I c,d,i,k=0,m,n,p,*yv; + RZ(a&&w); + RE(d=ebarprep(a,w,&a,&w,&c)); + av=CAV(a); m=AN(a); + wv=CAV(w); n=AN(w); p=n-m; + switch(d){ + case -1: R sc(n); + case -4: R indexof(ebarvec(a,w),one); + } + GA(y,INT,d,1,0); yv=AV(y); DO(d, yv[i]=1+m;); + switch(AT(w)){ + case INT: if(c)EBLOOP(I, u[i]-c,v[k+m]-c, if(i==m)R sc(k)) + else EBLOOP(I, u[i], v[k+m], if(i==m)R sc(k)); break; + case C2T: EBLOOP(US,u[i], v[k+m], if(i==m)R sc(k)); break; + default: EBLOOP(UC,u[i], v[k+m], if(i==m)R sc(k)); + } + R sc(n); +} /* a (E. i. 1:) w where a and w are atoms or lists */ + +F2(jtsumebar){A y;C*av,*wv;I c,d,i,k=0,m,n,p,*yv,z=0; + RZ(a&&w); + RE(d=ebarprep(a,w,&a,&w,&c)); + av=CAV(a); m=AN(a); + wv=CAV(w); n=AN(w); p=n-m; + switch(d){ + case -1: R zero; + case -4: R aslash(CPLUS,ebarvec(a,w)); + } + GA(y,INT,d,1,0); yv=AV(y); DO(d, yv[i]=1+m;); + switch(AT(w)){ + case INT: if(c)EBLOOP(I, u[i]-c,v[k+m]-c, if(i==m)++z) + else EBLOOP(I, u[i], v[k+m], if(i==m)++z); break; + case C2T: EBLOOP(US,u[i], v[k+m], if(i==m)++z); break; + default: EBLOOP(UC,u[i], v[k+m], if(i==m)++z); + } + R sc(z); +} /* a ([: +/ E.) w where a and w are atoms or lists */ + +F2(jtanyebar){A y;C*av,*wv;I c,d,i,k=0,m,n,p,*yv; + RZ(a&&w); + RE(d=ebarprep(a,w,&a,&w,&c)); + av=CAV(a); m=AN(a); + wv=CAV(w); n=AN(w); p=n-m; + switch(d){ + case -1: R zero; + case -4: R aslash(CPLUSDOT,ebarvec(a,w)); + } + GA(y,INT,d,1,0); yv=AV(y); DO(d, yv[i]=1+m;); + switch(AT(w)){ + case INT: if(c)EBLOOP(I, u[i]-c,v[k+m]-c, if(i==m)R one) + else EBLOOP(I, u[i], v[k+m], if(i==m)R one); break; + case C2T: EBLOOP(US,u[i], v[k+m], if(i==m)R one); break; + default: EBLOOP(UC,u[i], v[k+m], if(i==m)R one); + } + R zero; +} /* a ([: +./ E.) w where a and w are atoms or lists */ + +#define IFB1 \ + {if(zu==zv){I m=zu-AV(z); RZ(z=ext(0,z)); zv=m+AV(z); zu=AN(z)+AV(z);} *zv++=k;} + +F2(jtifbebar){A y,z;C*av,*wv;I c,d,i,k=0,m,n,p,*yv,*zu,*zv; + RZ(a&&w); + RE(d=ebarprep(a,w,&a,&w,&c)); + av=CAV(a); m=AN(a); + wv=CAV(w); n=AN(w); p=n-m; + switch(d){ + case -1: R mtv; + case -4: R icap(ebarvec(a,w)); + } + GA(z,INT,MAX(22,n/128),1,0); zv=AV(z); zu=zv+AN(z); + GA(y,INT,d,1,0); yv=AV(y); DO(d, yv[i]=1+m;); + switch(AT(w)){ + case INT: if(c)EBLOOP(I, u[i]-c,v[k+m]-c, if(i==m)IFB1) + else EBLOOP(I, u[i], v[k+m], if(i==m)IFB1); break; + case C2T: EBLOOP(US,u[i], v[k+m], if(i==m)IFB1); break; + default: EBLOOP(UC,u[i], v[k+m], if(i==m)IFB1); + } + AN(z)=*AS(z)=zv-AV(z); + R z; +} /* a ([: I. E.) w where a and w are atoms or lists */
new file mode 100644 --- /dev/null +++ b/vbang.c @@ -0,0 +1,163 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: ! */ + +#include "j.h" + + +static Z z1={1, 0}; + +static D coeff[]={ + 0.0, 1.0, 0.5772156649015329, -0.6558780715202538, + -0.0420026350340952, 0.1665386113822915, -0.0421977345555443, + -0.009621971527877, 0.007218943246663, -0.0011651675918591, + -0.0002152416741149, 0.0001280502823882, -0.0000201348547807, + -0.0000012504934821, 0.000001133027232, -0.0000002056338417, + 6.116095e-9, 5.0020075e-9, -1.1812746e-9, + 1.043427e-10, 7.7823e-12, -3.6968e-12, + 5.1e-13, -2.06e-14, -5.4e-15, + 1.4e-15, 1.0e-16 +}; + +static I terms=sizeof(coeff)/sizeof(D); + +static Z jtzhorner(J jt,I n,D*c,Z v){Z s;D*d=n+c; + s=zeroZ; + DO(n, s=zplus(zrj0(*--d),ztymes(v,s));); + R s; +} + +static D dgps(D v){D*d=terms+coeff,s=0.0; DO(terms, s=*--d+v*s;); R 1/s;} + /* Abramowitz & Stegun, 6.1.34 */ + +static Z jtzgps(J jt,Z z){R zdiv(z1,zhorner(terms,coeff,z));} + +static D jtdgamma(J jt,D x){B b;D t; + t=1.0; b=x==jfloor(x); + if(b&&0>=x){ASSERT(x>x-1,EVLIMIT); R x==2*jfloor(x/2)?inf:infm;} + if(0<=x) while(1<x){t*=--x; if(t==inf)R inf;} + else {while(0>x){t*=x++; if(t==inf)R 0.0;} t=1.0/t;} + R b?t:t*dgps(x); +} /* gamma(x) using recurrence formula */ + +static Z jtzgrecur(J jt,Z z){Z t; + t=z1; + if(0<=z.re) while( 0.5<z.re){--z.re; t=ztymes(t,z); if(t.re==inf)R t; } + else {while(-0.5>z.re){t=ztymes(t,z); ++z.re; if(t.re==inf)R zeroZ;} t=zdiv(z1,t);} + R ztymes(t,zgps(z)); +} /* gamma(z) using recurrence formula */ + +static Z jtzgauss(J jt,D n,Z z){D d=1/n;Z p,t; + if(1>=n)R zgrecur(z); + p=ztymes(zpow(zrj0(2*PI),zrj0((1-n)/2)),zpow(zrj0(n),zminus(z,zrj0(0.5)))); + t=zdiv(z,zrj0(n)); + DO((I)n, p=ztymes(p,zgrecur(t)); t.re+=d;); + R p; +} /* Abramowitz & Stegun, 6.1.20 */ + +static Z jtzstirling(J jt,Z z){Z p,q; + static D c[]={1.0, 1.0/12, 1.0/288, -139.0/51840, -571.0/2488320}, + e=2.718281828459045235360287; + p=ztymes(zsqrt(zdiv(zrj0(2*PI),z)),zpow(zdiv(z,zrj0(e)),z)); + q=zhorner(5L,c,zdiv(z1,z)); + R ztymes(p,q); +} /* Abramowitz & Stegun, 6.1.37 */ + +static Z jtzgamma(J jt,Z z){D y=ABS(z.im); + R !y?zrj0(dgamma(z.re)):20<y?zstirling(z):zgauss(ceil(y/0.8660254),z); +} + +AMON(factI, D,I, *z=dgamma(1.0+(D)*x);) +AMON(factD, D,D, *z=_isnan(*x)?*x:dgamma(1.0+*x);) +AMON(factZ, Z,Z, *z=zgamma(zplus(z1,*x));) + + +#define PQLOOP(expr) while(n&&h&&h!=inf&&h!=infm){h*=expr; --n;} + +static D pq(D h,D m,D*c,D*d){D x=*c,y=*d;I n=(I)MIN(m,IMAX); + if(0>=m)R h; + switch(2*(0>x)+(0>y)){ + case 0: if(x!= y)PQLOOP(x--/y--); break; + case 1: if(x!=-y)PQLOOP(x--/y++)else if(m>2*jfloor(0.5*m))h=-h; break; + case 2: if(x!=-y)PQLOOP(x++/y--)else if(m>2*jfloor(0.5*m))h=-h; break; + case 3: if(x!= y)PQLOOP(x++/y++); break; + } + if(0>=*c)*c+=m; else *c-=m; + if(0>=*d)*d+=m; else *d-=m; + R h; +} + +static I signf(D x){R 0<=x||1<=x-2*jfloor(0.5*x)?1:-1;} + /* sign of !x */ + +static D jtdbin(J jt,D x,D y){D c,d,e,h=1.0,p,q,r;I k=0; + c=y; if(0<=c)p=jfloor(c); else{k+=4; ++c; p=jfloor(-c);} + d=y-x; if(0<=d)q=jfloor(d); else{k+=2; ++d; q=jfloor(-d);} + e=x; if(0<=e)r=jfloor(e); else{k+=1; ++e; r=jfloor(-e);} + switch(k){ + case 0: h=pq(h,q,&c,&d); h=pq(h,r,&c,&e); break; + case 1: h=pq(h,p,&c,&d); h=pq(h,r,&e,&d); --e; break; + case 2: h=pq(h,p,&c,&e); h=pq(h,q,&d,&e); --d; break; + case 5: h=pq(h,p,&e,&c); h=pq(h,q,&e,&d); --c; --e; break; + case 6: h=pq(h,p,&d,&c); h=pq(h,r,&d,&e); --c; --d; break; + case 7: h=pq(h,q,&d,&c); h=pq(h,r,&e,&c); --c; --d; --e; break; + } + if(!h)R 0; + if(h==inf||h==infm)R inf*signf(x)*signf(y)*signf(y-x); + R h*dgamma(1+c)/(dgamma(1+d)*dgamma(1+e)); +} /* x and y-x are not negative integers */ + +static D ibin(D x,D y){D d=MIN(x,y-x),p=1; + DO((I)d, p*=y--/d--; if(p==inf)R p;); + R jfloor(0.5+p); +} /* x and y are non-negative integers; x<=y */ + +static Z jtzbin(J jt,Z x,Z y){Z a,b,c; + a=zgamma(zplus(z1,y)); + b=zgamma(zplus(z1,x)); + c=zgamma(zplus(z1,zminus(y,x))); + R zdiv(a,ztymes(b,c)); +} + +#define MOD2(x) ((x)-2*jfloor(0.5*(x))) + +static D jtbindd(J jt,D x,D y){B id,ix,iy;D d; + if(_isnan(x))R x; else if(_isnan(y))R y; + d=y-x; + id=d==jfloor(d); + ix=x==jfloor(x); + iy=y==jfloor(y); + switch(4*(ix&&0>x)+2*(iy&&0>y)+(id&&0>d)){ + default: ASSERTSYS(0,"bindd"); + case 5: /* 1 0 1 */ /* Impossible */ + case 0: /* 0 0 0 */ + case 2: /* 0 1 0 */ R ix&&iy?ibin(x,y):dbin(x,y); + case 3: /* 0 1 1 */ R (MOD2(x)?-1:1)*ibin(x,x-y-1); + case 6: /* 1 1 0 */ R (MOD2(d)?-1:1)*ibin(-1-y,-1-x); + case 1: /* 0 0 1 */ + case 4: /* 1 0 0 */ + case 7: /* 1 1 1 */ R 0; +}} /* P.C. Berry, Sharp APL Reference Manual, 1979, p. 132 */ + +static Z jtbinzz(J jt,Z x,Z y){B id,ix,iy;D rd,rx,ry;Z d; + if(!x.im&&!y.im)R zrj0(bindd(x.re,y.re)); + d=zminus(y,x); + rd=d.re; id=rd==jfloor(rd)&&0==d.im; + rx=x.re; ix=rx==jfloor(rx)&&0==x.im; + ry=y.re; iy=ry==jfloor(ry)&&0==y.im; + switch(4*(ix&&0>rx)+2*(iy&&0>ry)+(id&&0>rd)){ + default: ZASSERT(0,EVSYSTEM); + case 5: /* 1 0 1 */ /* Impossible */ + case 0: /* 0 0 0 */ + case 2: /* 0 1 0 */ R zbin(x,y); + case 3: /* 0 1 1 */ R zrj0((MOD2(rx)?-1:1)*ibin(rx,rx-ry-1)); + case 6: /* 1 1 0 */ R zrj0((MOD2(rd)?-1:1)*ibin(-1-ry,-1-rx)); + case 1: /* 0 0 1 */ + case 4: /* 1 0 0 */ + case 7: /* 1 1 1 */ R zeroZ; +}} + + +ANAN(binDD, D,D,D, bindd) +ANAN(binZZ, Z,Z,Z, binzz)
new file mode 100644 --- /dev/null +++ b/vbit.c @@ -0,0 +1,509 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Bit Type */ + +/* 1 bit per element */ +/* total # elements <: IMAX */ +/* dimension length <: IMAX */ +/* last dimension internally padded with 0s up to fullword */ + +#include "j.h" + +#define bitandBB(x,y) jtbitandBB(jt,(x),(y)) +#define biteqBB(x,y) jtbiteqBB(jt,(x),(y)) +#define biteqII(x,y) jtbiteqII(jt,(x),(y)) +#define biterror(x,y) jtbiterror(jt,(x),(y)) +#define bitgeBB(x,y) jtbitgeBB(jt,(x),(y)) +#define bitgeII(x,y) jtbitgeII(jt,(x),(y)) +#define bitgtBB(x,y) jtbitgtBB(jt,(x),(y)) +#define bitgtII(x,y) jtbitgtII(jt,(x),(y)) +#define bitleBB(x,y) jtbitleBB(jt,(x),(y)) +#define bitleII(x,y) jtbitleII(jt,(x),(y)) +#define bitltBB(x,y) jtbitltBB(jt,(x),(y)) +#define bitltII(x,y) jtbitltII(jt,(x),(y)) +#define bitnandBB(x,y) jtbitnandBB(jt,(x),(y)) +#define bitneBB(x,y) jtbitneBB(jt,(x),(y)) +#define bitneII(x,y) jtbitneII(jt,(x),(y)) +#define bitnorBB(x,y) jtbitnorBB(jt,(x),(y)) +#define bitorBB(x,y) jtbitorBB(jt,(x),(y)) + + +F2(jtbitmatch){B*v;I ar,*as,at,c,d,i,q,r,r1,rc,m,wr,*ws,wt;UC k,p,*u; + RZ(a&&w); + ar=AR(a); as=AS(a); at=AT(a); + wr=AR(w); ws=AS(w); wt=AT(w); + ASSERTSYS(at&BIT||wt&BIT,"bitmatch"); + ASSERT(at&BIT+B01&&wt&BIT+B01,EVNONCE); + if(ar!=wr)R zero; + if(memcmp(as,ws,ar))R zero; + c=ar?as[ar-1]:1; m=c?AN(a)/c:0; d=(c+BW-1)/BW; + q=c/BB; r=c%BB; rc=c%BW; r1=rc?(BW-rc)/BB:0; + if(at&BIT&&wt&BIT)R memcmp(AV(a),AV(w),m*d*SZI)?zero:one; + if(at&BIT){u=UAV(a); v=BAV(w);} + else {u=UAV(w); v=BAV(a);} + for(i=0;i<m;++i){ + DO(q, k=*u++; p=(UC)128; DO(BB, if((1&&*v++)!=(1&&k&p))R zero; p>>=1;);); + if(r){k=*u++; p=(UC)128; DO(r, if((1&&*v++)!=(1&&k&p))R zero; p>>=1;);} + u+=r1; + } + R one; +} + +static UI bitmask(I c){I rc;UI mask; + mask=0; + if(rc=c%BW){ + mask=(~mask)<<(BW-rc); +#if SYS & SYS_LILENDIAN + {UC c,*v=(UC*)&mask;I j=SZI; DO(SZI/2, --j; c=v[i]; v[i]=v[j]; v[j]=c;);} +#endif + } + R mask; +} /* bit mask for an array c columns wide */ + +static F1(jtbitcvt){R cvt(BIT,w);} + +static F1(jtbitvfypad){I c,d,i,m,rc,wn,wr,*ws;UI mask,*u; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + wn=AN(w); wr=AR(w); ws=AS(w); + c=wr?ws[wr-1]:1; m=c?wn/c:0; rc=c%BW; + if(!rc)R w; + d=(c+BW-1)/BW; u=(UI*)AV(w); + mask=~bitmask(c); + for(i=0;i<m;++i){ + ASSERTSYS(!(mask&u[d-1]),"bitvfypad"); + u+=d; + } + R w; +} /* verify that the pad bits in bit array w are zero */ + +static I bitsum(I n,UC*b){I z=0; +#if SY_64 + DO((n+BW-1)/BW, z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++]; + z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++];); +#else + DO((n+BW-1)/BW, z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++]; z+=bitc[*b++];); +#endif + R z; +} /* +/ bit vector */ + + +static F1(jtbitslplus){A t,z;I i,m,mm,n,n1,p,q,*u,wr,*ws,*zv;UC c,*vc,*wv;UI*v,*v0;static UI ptab[256]; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + wr=AR(w); + if(1>=wr)R sc(bitsum(AN(w),UAV(w))); + ws=AS(w); m=*ws; if(m)n=AN(w)/m; else RE(n=prod(wr-1,1+ws)); + GA(z,INT,n,wr-1,1+ws); zv=AV(z); memset(zv,C0,SZI*n); + if(!n)R z; + if(!m){memset(zv,C0,n*SZI); R z;} +#if SY_64 + mm=255; + if(!ptab[1]){UC*v;UI x; v=(UC*)&x; DO(256, c=(UC)i; x=0; DO(8, if(c&(UC)1)v[7-i]=1; c>>=1;); ptab[i]=x;);} +#else + mm=15; + if(!ptab[1]){UI t[8],x; + DO(8, t[i]=0; *((i/2)+(UC*)(i+t))=i%2?0x01:0x10;); + DO(256, c=(UC)i; x=0; DO(8, if(c&(UC)1)x|=t[i]; c>>=1;); ptab[i]=x;); + } +#endif + n1=(n+BW-1)/BW; n1*=SZI; q=(n+BB-1)/BB; + GA(t,INT,q,1,0); v=v0=(UI*)AV(t); wv=UAV(w); + for(i=(m+mm-1)/mm-1;i>=0;--i){ + v=v0; DO(q, *v++=0;); + p=i?mm:m%mm; + DO(p, v=v0; DO(q, *v+++=ptab[*wv++];); wv+=n1-q;); + vc=(UC*)v0; u=zv; DO(n, c=*vc++; *u+++=c>>4; *u+++=c&(UC)0x0f;); + } + R z; +} /* +/ bit vector */ + +static F1(jtbitsland){I n;UI ff,*v; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + n=AN(w); v=(UI*)AV(w); + ff=~(UI)0; + DO(n/BW, if(ff!=*v++)R zero;); + if(n%BW)R *v==bitmask(n)?one:zero; + R one; +} /* *./ bit vector */ + +static F1(jtbitslor){I n;UI*v; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + n=AN(w); v=(UI*)AV(w); + DO(n/BW, if(*v++)R one;); + if(n%BW)R *v&bitmask(n)?one:zero; + R zero; +} /* +./ bit vector */ + +static F1(jtbitslne){I n;UC c,*v; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + n=AN(w); c=0; v=UAV(w); +#if SY_64 + DO((n+BW-1)/BW, c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++];); +#else + DO((n+BW-1)/BW, c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++];); +#endif + R c&(UC)1?one:zero; +} /* ~:/ bit vector */ + +static F1(jtbitsleq){I n;UC c,*v; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + n=AN(w); c=0; v=UAV(w); +#if SY_64 + DO((n+BW-1)/BW, c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++];); +#else + DO((n+BW-1)/BW, c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++]; c^=bitc[*v++];); +#endif + R (n-c)&(UC)1?zero:one; +} /* =/ bit vector */ + + +static F1(jtbitscanand){A z;I c,j,m,n;UC ffc,k,p,*u;UI ff,*v,*zv; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + n=AN(w); v=(UI*)AV(w); + GA(z,BIT,n,AR(w),AS(w)); zv=(UI*)AV(z); + m=(n+BW-1)/BW; j=-1; ff=~(UI)0; + DO(m, if(ff==*v++)*zv++=ff; else{j=i; --v; break;}); + if(0<=j){ + u=(UC*)v; ffc=~(UC)0; + DO(SZI, if(ffc!=*u++){--u; break;}); + c=u-(UC*)v; k=*u; p=0; + DO(BB, if(k&bit[i])p|=bit[i]; else break;); + *zv=ff; u=c+(UC*)zv; *u++=p; + DO((SZI-c)-1, *u++=0;); + DO((m-j)-1, *++zv=0;); + } + R z; +} /* *./\ bit vector */ + +static UC nepfx[256]; +static UC eqpfx[256]; + +static F1(jtbitscanne){A z;I n;UC c,d,p,*v,x,*zv; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + if(!nepfx[255])DO(256, p=(UC)i; c=128; x=d=p&c; DO(7, c>>=1; d|=x=p&c?(x?0:c):(x?c:0);); nepfx[i]=d;); + x=0; n=AN(w); v=UAV(w); + GA(z,BIT,n,AR(w),AS(w)); zv=UAV(z); + DO((n+BB-1)/BB, d=nepfx[*v++]; *zv++=x=1&x?~d:d;); + if(n%BW)*(n/BW+(UI*)AV(z))&=bitmask(n); + R z; +} /* ~:/\ bit vector */ + +static F1(jtbitscaneq){A z;I n;UC c,d,p,*v,x,*zv; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + ASSERT(1>=AR(w),EVNONCE); + if(!eqpfx[255])DO(256, p=(UC)i; c=128; x=d=p&c; DO(7, c>>=1; d|=x=p&c?(x?c:0):(x?0:c);); eqpfx[i]=d;); + x=1; n=AN(w); v=UAV(w); + GA(z,BIT,n,AR(w),AS(w)); zv=UAV(z); + DO((n+BB-1)/BB, d=eqpfx[*v++]; *zv++=x=1&x?d:~d;); + if(n%BW)*(n/BW+(UI*)AV(z))&=bitmask(n); + R z; +} /* =/\ bit vector */ + + +static F1(jtbitnot){A z;I c,m,rc,wn,wr,*ws;UI mask,*u,*zv; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + wn=AN(w); wr=AR(w); ws=AS(w); u=(UI*)AV(w); + c=wr?ws[wr-1]:1; m=c?wn/c:0; rc=c%BW; + mask=bitmask(c); + GA(z,BIT,wn,wr,ws); zv=(UI*)AV(z); + if(rc)DO(m, DO(c/BW, *zv++=~*u++;); *zv++=~*u++&mask;) + else DO(m, DO(c/BW, *zv++=~*u++;);); + R z; +} /* -. bit array */ + +static F1(jtbitravel){A z;I c,m,rw,wn,wr,*ws;UC*wv,*zv; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + wn=AN(w); wr=AR(w); ws=AS(w); wv=UAV(w); + c=wr?ws[wr-1]:1; m=c?wn/c:0; rw=c%BW; + GA(z,BIT,wn,1,0); zv=UAV(z); + if(rw){I j,q,r,r1,t,ti;UC k,y; + q=c/BB; r=c%BB; r1=rw?(BW-rw)/BB:0; + k=0; t=0; ti=BB-t; + for(j=0;j<m;++j){ + if(t)DO(q, y=*wv++; k|=y>>t; *zv++=k; k=y<<ti;) + else if(q){memcpy(zv,wv,q); zv+=q; wv+=q;} + if(r){y=*wv++; k|=y>>t; if(BB<=t+r){*zv++=k; k=y<<ti;} t=(t+r)%BB; ti=BB-t;} + wv+=r1; + } + if(r&&t)*zv++=k; + if(wn%BW)memset(zv,C0,(BW-wn%BW)/BB); + }else memcpy(zv,wv,wn/BB); + R z; +} /* , bit array */ + +static F2(jtbitcat){A z;I an,ar,*as,t,ti,wn,wr,*ws;UC*zv; + RZ(a&&w); + ASSERT(BIT&AT(a)&&BIT&AT(w),EVDOMAIN); + an=AN(a); ar=AR(a); as=AS(a); + wn=AN(w); wr=AR(w); ws=AS(w); + ASSERT(1>=ar&&1>=wr,EVNONCE); + GA(z,BIT,an+wn,1,0); zv=UAV(z); + memcpy(zv,AV(a),SZI*((an+BW-1)/BW)); + zv+=an/BB; + if(t=an%BB){UC k,*wv,y; + ti=BB-t; wv=UAV(w); k=*zv; + DO((wn+BB-1)/BB, y=*wv++; k|=y>>t; *zv++=k; k=y<<ti;); + *zv++=k; + }else memcpy(zv,AV(w),SZI*((wn+BW-1)/BW)); + R z; +} /* bit array , bit array */ + +static F2(jtbitfrom){A z;I an,ar,*as,c,i,j,m,n,q,r,rc,r1,wr,*ws;UC k,*v,*zv; + RZ(a&&w); + ASSERT(INT&AT(a),EVNONCE); + ASSERT(BIT&AT(w),EVDOMAIN); + an=AN(a); ar=AR(a); as=AS(a); wr=AR(w); ws=AS(w); + if(1>=wr){I*u; + c=ar?as[ar-1]:1; m=c?an/c:0; q=c/BB; r=c%BB; rc=c%BW; r1=rc?(BW-rc)/BB:0; + GA(z,BIT,an,ar,as); zv=(UC*)AV(z); + u=AV(a); v=UAV(w); n=AN(w); + for(i=0;i<m;++i){ + DO(q, k=0; DO(BB, j=*u++; if(0>j)j+=n; ASSERT(0<=j&&j<n,EVINDEX); if(v[j/BB]&(UC)128>>j%BB)k|=bit[i];); *zv++=k;); + if(r){k=0; DO(r, j=*u++; if(0>j)j+=n; ASSERT(0<=j&&j<n,EVINDEX); if(v[j/BB]&(UC)128>>j%BB)k|=bit[i];); *zv++=k;} + DO(r1, *zv++=0;); + }}else{A x;I*u,*v,zn,zr,*zv; + zr=ar+wr-1; + GA(x,INT,zr,1,0); u=AV(x); + ICPY(u,as,ar); ICPY(u+ar,1+ws,wr-1); RE(zn=prod(zr,u)); + GA(z,BIT,zn,zr,u); zv=AV(z); + n=*ws; c=(ws[wr-1]+BW-1)/BW; RE(m=mult(prod(wr-2,1+ws),c)); + u=AV(a); v=AV(w); + DO(an, j=*u++; if(0>j)j+=n; ASSERT(0<=j&&j<n,EVINDEX); ICPY(zv,v+j*m,m); zv+=m;); + } + R z; +} /* integer array { bit array */ + + +static F2(jtbiterror){ASSERT(0,EVNONCE);} + +#define BITFBB(f,OP) \ + F2(f){A z;I c,m,mask,rc,wn,wr,*ws;UI*u,*v,*zv; \ + RZ(a&&w); \ + wn=AN(w); wr=AR(w); ws=AS(w); \ + ASSERT(BIT&AT(a)&&BIT&AT(w),EVDOMAIN); \ + ASSERT(wr==AR(a),EVRANK); \ + ASSERT(!memcmp(ws,AS(a),wr),EVLENGTH); \ + c=wr?ws[wr-1]:1; m=c?wn/c:0; rc=c%BW; \ + u=(UI*)AV(a); v=(UI*)AV(w); \ + mask=bitmask(c); \ + GA(z,BIT,wn,wr,ws); zv=(UI*)AV(z); \ + if(rc)DO(m, DO(c/BW, *zv++=OP(*u++,*v++);); *zv++=OP(*u++,*v++)&mask;) \ + else DO(m, DO(c/BW, *zv++=OP(*u++,*v++););); \ + R z; \ + } /* bit array op bit array */ + +#define BITFII(f,OP) \ + F2(f){A z;I an,ar,*as,c,i,m,q,r,rc,r1,*u,*v;UC k,*zv; \ + RZ(a&&w); \ + an=AN(a); ar=AR(a); as=AS(a); \ + ASSERT(INT&AT(a)&&INT&AT(w),EVDOMAIN); \ + ASSERT(AR(a)==AR(w),EVRANK); \ + ASSERT(!memcmp(as,AS(w),ar),EVLENGTH); \ + c=ar?as[ar-1]:1; m=c?an/c:0; q=c/BB; r=c%BB; rc=c%BW; r1=rc?(BW-rc)/BB:0; \ + GA(z,BIT,an,ar,as); zv=(UC*)AV(z); \ + u=AV(a); v=AV(w); zv=(UC*)AV(z); \ + for(i=0;i<m;++i){ \ + DO(q, k=0; DO(BB, if(OP(*u++,*v++))k|=bit[i];); *zv++=k;); \ + if(r){k=0; DO(r, if(OP(*u++,*v++))k|=bit[i];); *zv++=k;} \ + DO(r1, *zv++=0;); \ + } \ + R z; \ + } /* integer array op integer array */ + +#define BITF(f,fBB,fII) \ + F2(f){I at; \ + RZ(a&&w); \ + at=AT(a); \ + ASSERT(at==AT(w)&&at&BIT+INT,EVNONCE); \ + R at&BIT?fBB(a,w):fII(a,w); \ + } + +#define BBEQ(x,y) (~(x^y)) +#define BBLT(x,y) (~x&y) +#define BBLE(x,y) (~x|y) +#define BBGT(x,y) (x&~y) +#define BBGE(x,y) (x|~y) +#define BBOR(x,y) (x|y) +#define BBNOR(x,y) (~(x|y)) +#define BBAND(x,y) (x&y) +#define BBNAND(x,y) (~(x&y)) +#define BBNE(x,y) (x^y) + +#define IILT(x,y) (x< y) +#define IILE(x,y) (x<=y) +#define IIEQ(x,y) (x==y) +#define IIGE(x,y) (x>=y) +#define IIGT(x,y) (x> y) +#define IINE(x,y) (x!=y) + +static BITFBB(jtbiteqBB, BBEQ ) +static BITFBB(jtbitltBB, BBLT ) +static BITFBB(jtbitleBB, BBLE ) +static BITFBB(jtbitgtBB, BBGT ) +static BITFBB(jtbitgeBB, BBGE ) +static BITFBB(jtbitorBB, BBOR ) +static BITFBB(jtbitnorBB, BBNOR ) +static BITFBB(jtbitandBB, BBAND ) +static BITFBB(jtbitnandBB,BBNAND) +static BITFBB(jtbitneBB, BBNE ) + +static BITFII(jtbiteqII,IIEQ) +static BITFII(jtbitltII,IILT) +static BITFII(jtbitleII,IILE) +static BITFII(jtbitgtII,IIGT) +static BITFII(jtbitgeII,IIGE) +static BITFII(jtbitneII,IINE) + +static BITF(jtbiteq, biteqBB, biteqII ) +static BITF(jtbitlt, bitltBB, bitltII ) +static BITF(jtbitle, bitleBB, bitleII ) +static BITF(jtbitgt, bitgtBB, bitgtII ) +static BITF(jtbitge, bitgeBB, bitgeII ) +static BITF(jtbitor, bitorBB, biterror ) +static BITF(jtbitnor, bitnorBB, biterror ) +static BITF(jtbitand, bitandBB, bitandBB ) +static BITF(jtbitnand,bitnandBB,bitnandBB) +static BITF(jtbitne, bitneBB, bitneII ) + +static F1(jtbitgrade){A x;I r,*s; + RZ(w); + ASSERT(BIT&AT(w),EVDOMAIN); + r=AR(w); + ASSERT(2<=r,EVNONCE); + RZ(x=gah(r,w)); + AT(x)=LIT; + s=AS(x); ICPY(s,AS(w),r); s[r-1]=SZI*((s[r-1]+BW-1)/BW); AN(x)=prod(r,s); + R grade1(x); +} /* /: bit array */ + +static F2(jtbitindexof){I j,n;UC*u,y;UI*v,x; + RZ(a&&w); + ASSERT(BIT&AT(a),EVDOMAIN); + ASSERT(1>=AR(a)&&!AR(w),EVNONCE); + if(!(AT(w)&BIT+B01))RZ(w=cvt(BIT,w)); + x=*UAV(w)?0:~(UI)0; + n=AN(a); v=(UI*)AV(a); j=n; + DO((n+BW-1)/BW, if(x!=*v++){j=BW*i; --v; break;}); + if(n!=j){ + u=(UC*)v; y=*(UC*)&x; DO(SZI, if(y!=*u++){j+=i*BB; --u; break;}); + y=x?~*u:*u; + DO(BB, if(y&bit[i]){j+=i; break;}); + } + R sc(j); +} /* bit vector i. 0 or 1 */ + +#define REPSWITCH(c,exp0,exp1) \ + switch(c){ \ + case 0: exp0; exp0; exp0; exp0; break; \ + case 1: exp0; exp0; exp0; exp1; break; \ + case 2: exp0; exp0; exp1; exp0; break; \ + case 3: exp0; exp0; exp1; exp1; break; \ + case 4: exp0; exp1; exp0; exp0; break; \ + case 5: exp0; exp1; exp0; exp1; break; \ + case 6: exp0; exp1; exp1; exp0; break; \ + case 7: exp0; exp1; exp1; exp1; break; \ + case 8: exp1; exp0; exp0; exp0; break; \ + case 9: exp1; exp0; exp0; exp1; break; \ + case 10: exp1; exp0; exp1; exp0; break; \ + case 11: exp1; exp0; exp1; exp1; break; \ + case 12: exp1; exp1; exp0; exp0; break; \ + case 13: exp1; exp1; exp0; exp1; break; \ + case 14: exp1; exp1; exp1; exp0; break; \ + case 15: exp1; exp1; exp1; exp1; break; \ + } + +#define REPDO(T,exp0,exp1) {T*u=(T*)wv,*v=(T*)zv; \ + DO((n+BB-1)/BB, k=*av++; REPSWITCH(k/16, exp0, exp1); REPSWITCH(k%16, exp0, exp1););} + + +static F2(jtbitrepeat){A z;I c,c1,m,n,p,wr,wk,wt;UC*av,k; + RZ(a&&w); + ASSERT(BIT&AT(a),EVDOMAIN); + n=AN(a); av=UAV(a); wr=AR(w); wt=AT(w); + p=AR(w)?*AS(w):1; m=AN(w)/p; c=wr?*(AS(w)+wr-1):1; c1=(c+BW-1)/BW; + wk=wt&BIT?SZI*c1*(m/c):m*bp(wt); + ASSERT(n==p,EVLENGTH); + p=bitsum(n,av); + GA(z,wt,p*m,AR(w),AS(w)); *AS(z)=p; + if(BIT&wt&&1>=wr){I j;UC c,d,*wv,*zv; + wv=UAV(w); zv=UAV(z); j=0; + DO((n+BB-1)/BB, k=*av++; c=*wv++; d=0; DO(BB, if(k&bit[i]){d|=k&bit[i]&c;}); *zv++=d;); + }else{I*wv,*zv; + wv=AV(w); zv=AV(z); + switch(wk){ + case sizeof(C): REPDO(C,u++, *v++=*u++); break; + case sizeof(S): REPDO(S,u++, *v++=*u++); break; + case sizeof(C)*3: REPDO(C,u+=3, (*v++=*u++,*v++=*u++,*v++=*u++)); break; + case sizeof(I): REPDO(I,u++, *v++=*u++); break; + case sizeof(I)*2: REPDO(I,u+=2, (*v++=*u++,*v++=*u++)); break; + case sizeof(I)*3: REPDO(I,u+=3, (*v++=*u++,*v++=*u++,*v++=*u++)); break; + case sizeof(I)*4: REPDO(I,u+=4, (*v++=*u++,*v++=*u++,*v++=*u++,*v++=*u++)); break; + default: REPDO(C,u+=wk,(memcpy(v,u,wk),u+=wk,v+=wk)); + }} + R z; +} /* bit vector # array */ + + +#define BITDEF(f1,f2) fdef(CIBEAM,VERB, f1,f2, w,0L,0L, 0L, RMAX,RMAX,RMAX) +#define BITDEF1(f1) fdef(CIBEAM,VERB, f1,0L, w,0L,0L, 0L, RMAX,RMAX,RMAX) +#define BITDEF2(f2) fdef(CIBEAM,VERB, 0L,f2, w,0L,0L, 0L, RMAX,RMAX,RMAX) + +F1(jtbitadv){A x;V*v; + RZ(w); v=VAV(w); + switch(NOUN&AT(w)?i0(w):v->id){ + default: ASSERT(0,EVDOMAIN); + case 0: R BITDEF1(jtbitcvt); + case 1: R BITDEF1(jtbitvfypad); + case CNOT: R BITDEF1(jtbitnot); + case CGRADE: R BITDEF1(jtbitgrade); + + case CCOMMA: R BITDEF(jtbitravel,jtbitcat); + + case CIOTA: R BITDEF2(jtbitindexof); + case CPOUND: R BITDEF2(jtbitrepeat); + case CPLUSDOT: R BITDEF2(jtbitor); + case CPLUSCO: R BITDEF2(jtbitnor); + case CSTAR: + case CSTARDOT: R BITDEF2(jtbitand); + case CSTARCO: R BITDEF2(jtbitnand); + case CLT: R BITDEF2(jtbitlt); + case CLE: R BITDEF2(jtbitle); + case CEQ: R BITDEF2(jtbiteq); + case CGT: R BITDEF2(jtbitgt); + case CGE: R BITDEF2(jtbitge); + case CNE: R BITDEF2(jtbitne); + case CFROM: R BITDEF2(jtbitfrom); + case CSLASH: + switch(ID(v->f)){ + default: ASSERT(0,EVDOMAIN); + case CEQ: R BITDEF1(jtbitsleq); + case CPLUS: R BITDEF1(jtbitslplus); + case CPLUSDOT: R BITDEF1(jtbitslor); + case CSTARDOT: R BITDEF1(jtbitsland); + case CNE: R BITDEF1(jtbitslne); + } + case CBSLASH: + x=v->f; ASSERT(CSLASH==ID(x),EVDOMAIN); x=VAV(x)->f; + switch(ID(x)){ + default: ASSERT(0,EVDOMAIN); + case CSTARDOT: R BITDEF1(jtbitscanand); + case CNE: R BITDEF1(jtbitscanne); + case CEQ: R BITDEF1(jtbitscaneq); +}}}
new file mode 100644 --- /dev/null +++ b/vcant.c @@ -0,0 +1,89 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Transpose */ + +#include "j.h" + +static F2(jtcanta); + +static A jtcants(J jt,A a,A w,A z){A a1,q,y;B*b,*c;I*u,wr,zr;P*wp,*zp; + RZ(a&&w&&z); + RZ(a=grade1(a)); + wr=AR(w); wp=PAV(w); a1=SPA(wp,a); + zr=AR(z); zp=PAV(z); + ASSERT(wr==zr,EVNONCE); + RZ(b=bfi(wr,a1,1)); + GA(q,B01,wr,1,0); c=BAV(q); u=AV(a); DO(wr, c[i]=b[u[i]];); + SPB(zp,a,ifb(wr,c)); + SPB(zp,e,ca(SPA(wp,e))); + RZ(y=fromr(grade1(indexof(a,a1)),SPA(wp,i))); + RZ(q=grade1(y)); + SPB(zp,i,from(q,y)); + SPB(zp,x,from(q,canta(over(zero,increm(grade1(less(a,a1)))),SPA(wp,x)))); + R z; +} /* w is sparse */ + +#define CANTA(T,exp) \ + {T*u=(T*)zv,*v=(T*)wv; \ + DO(zn, exp; j=r-1; ++tv[j]; d+=mv[j]; \ + while(j&&sv[j]==tv[j]){d+=mv[j-1]-mv[j]*sv[j]; tv[j]=0; ++tv[--j];}); \ + } + +static F2(jtcanta){A m,s,t,z;B b;C*wv,*zv;I*av,c,d,j,k,*mv,r,*sv,*tv,wf,wr,*ws,zn,zr; + RZ(a&&w); + av=AV(a); ws=AS(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; jt->rank=0; + ASSERT(r==AN(a),EVLENGTH); + if(wf=wr-r){ + GA(a,INT,wr,1,0); tv=AV(a); + DO(wf, tv[i]=i;); DO(r, tv[wf+i]=wf+av[i];); + av=tv; + } + zr=0; DO(wr, zr=MAX(zr,av[i]);); zr+=0<wr; + GA(m,INT,zr,1,0); mv=AV(m); + GA(s,INT,zr,1,0); sv=AV(s); + GA(t,INT,wr,1,0); tv=AV(t); + d=1; j=wr; DO(wr, --j; tv[j]=d; d*=ws[j];); + for(j=0,zn=1;j<zr;++j){ + c=IMAX; d=k=0; + DO(wr, if(j==av[i]){k=1; d+=tv[i]; c=MIN(c,ws[i]);}); + ASSERT(k,EVINDEX); + zn*=c; sv[j]=c; mv[j]=d; + } + b=1&&SPARSE&AT(w); + GA(z,AT(w),b?1:zn,zr,sv); + if(b)R cants(a,w,z); if(!zn)R z; + d=1; r=zr; j=wr; DO(wr, --j; if(j!=av[j])break; d*=sv[j]; --r;); + if(1<d)DO(r, mv[i]/=d;); + zn=zn/d; k=d*bp(AT(w)); zv=CAV(z); wv=CAV(w); d=0; memset(tv,C0,r*SZI); + if(r)switch(k){ + default: CANTA(C, MC(u,v+d*k,k); u+=k;); break; + case sizeof(C): CANTA(C, *u++=v[d];); break; + case sizeof(S): CANTA(S, *u++=v[d];); break; + case sizeof(I): CANTA(I, *u++=v[d];); break; +#if !SY_64 && SY_WIN32 + case sizeof(D): CANTA(D, *u++=v[d];); break; +#endif + }else MC(zv,wv,k*zn); + R RELOCATE(w,z); +} /* dyadic transpose in APL\360, a f"(1,r) w where 1>:#$a */ + +F1(jtcant1){I r; + RZ(w); + if(jt->rank){jt->rank[0]=1; r=jt->rank[1];}else r=AR(w); + R canta(apv(r,r-1,-1L),w); +} /* |:"r w */ + +F2(jtcant2){A*av,p,t,y;I ad,j,k,m,n,*pv,q,r,*v; + RZ(a&&w); + q=jt->rank?jt->rank[0]:AR(a); + r=jt->rank?jt->rank[1]:AR(w); jt->rank=0; + if(1<q||q<AR(a))R rank2ex(a,w,0L,MIN(1,q),r,jtcant2); + if(BOX&AT(a)){ + RZ(y=pfill(r,t=raze(a))); v=AV(y); + GA(p,INT,AN(y),1,0); pv=AV(p); + m=AN(a); n=AN(t); av=AAV(a); ad=(I)a*ARELATIVE(a); + j=0; DO(r-n,pv[*v++]=j++;); DO(m, k=AN(AVR(i)); DO(k,pv[*v++]=j;); if(k)++j;); + }else p=pinv(pfill(r,a)); + R r<AR(w) ? irs2(p,w,0L,1L,r,jtcanta) : canta(p,w); +} /* a|:"r w main control */
new file mode 100644 --- /dev/null +++ b/vcat.c @@ -0,0 +1,235 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Catenate and Friends */ + +#include "j.h" + + +static A jtovs0(J jt,B p,I r,A a,A w){A a1,e,q,x,y,z;B*b;I at,*av,c,d,j,k,f,m,n,t,*v,wr,*ws,wt,zr;P*wp,*zp; + ws=AS(w); wr=AR(w); f=wr-r; zr=wr+!r; + ASSERT(IMAX>ws[f],EVLIMIT); + wp=PAV(w); e=SPA(wp,e); x=SPA(wp,x); y=SPA(wp,i); m=*AS(y); + a1=SPA(wp,a); c=AN(a1); av=AV(a1); RZ(b=bfi(zr,a1,1)); + at=AT(a); wt=AT(x); + ASSERT(HOMO(at,wt),EVDOMAIN); + t=maxtype(at,wt); + if(t!=at)RZ(a=cvt(t,a)); + if(t!=wt){RZ(x=cvt(t,x)); RZ(e=cvt(t,e));} + j=k=0; DO(f, if(b[i])++j; else ++k;); + switch(2*b[f]+!equ(a,e)){ + case 0: /* dense and a equal e */ + RZ(y=ca(y)); + RZ(x=p?irs2(x,a,0L,AR(x)-(1+k),0L,jtover):irs2(a,x,0L,0L,AR(x)-(1+k),jtover)); + break; + case 1: /* dense and a not equal to e */ + GA(q,INT,c,1,0); v=AV(q); DO(c, v[i]=ws[av[i]];); RZ(q=odom(2L,c,v)); + if(AN(q)>=AN(y)){ + RZ(z=shape(x)); *AV(z)=*AS(q); + RZ(x=from(grade1(over(y,less(q,y))),over(x,reshape(z,e)))); + y=q; + } + RZ(x=p?irs2(x,a,0L,AR(x)-(1+k),0L,jtover):irs2(a,x,0L,0L,AR(x)-(1+k),jtover)); + break; + case 2: /* sparse and a equals e */ + RZ(y=ca(y)); + if(!p){v=j+AV(y); DO(m, ++*v; v+=c;);} + break; + case 3: /* sparse and a not equal to e */ + GA(q,INT,c,1,0); v=AV(q); DO(c, v[i]=ws[av[i]];); v[j]=1; RZ(q=odom(2L,c,v)); n=*AS(q); + if(p){RZ(y=over(y,q)); v=AV(y)+j+m*c; d=ws[f]; DO(n, *v=d; v+=c;);} + else {RZ(y=over(q,y)); v=AV(y)+j+n*c; DO(m, ++*v; v+=c;);} + RZ(q=shape(x)); *AV(q)=n; RZ(q=reshape(q,a)); RZ(x=p?over(x,q):over(q,x)); + if(f){RZ(q=grade1(y)); RZ(y=from(q,y)); RZ(x=from(q,x));} + } + GA(z,STYPE(t),1,zr,ws); + if(r)++*(f+AS(z)); else *(wr+AS(z))=2; + zp=PAV(z); SPB(zp,a,ifb(zr,b)); SPB(zp,e,e); SPB(zp,i,y); SPB(zp,x,x); + R z; +} /* a,"r w (0=p) or w,"r a (1=p) where a is scalar */ + +static F2(jtovs){A ae,ax,ay,q,we,wx,wy,x,y,z,za,ze;B*ab,*wb,*zb;I acr,ar,*as,at,c,m,n,r,t,*v,wcr,wr,*ws,wt,*zs;P*ap,*wp,*zp; + RZ(a&&w); + at=AT(a); ar=AR(a); acr=jt->rank?jt->rank[0]:ar; + wt=AT(w); wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; jt->rank=0; + if(!ar)R ovs0(0,wcr,a,w); + if(!wr)R ovs0(1,acr,w,a); + if(ar>acr||wr>wcr)R sprank2(a,w,0L,acr,wcr,jtover); + r=MAX(ar,wr); + if(r>ar)RZ(a=reshape(over(apv(r-ar,1L,0L),shape(a)),a)); as=AS(a); + if(r>wr)RZ(w=reshape(over(apv(r-wr,1L,0L),shape(w)),w)); ws=AS(w); + ASSERT(*as<IMAX-*ws,EVLIMIT); + if(!(at&SPARSE)){wp=PAV(w); RZ(a=sparseit(a,SPA(wp,a),SPA(wp,e)));} + if(!(wt&SPARSE)){ap=PAV(a); RZ(w=sparseit(w,SPA(ap,a),SPA(ap,e)));} + ap=PAV(a); RZ(ab=bfi(r,SPA(ap,a),1)); ae=SPA(ap,e); at=AT(ae); + wp=PAV(w); RZ(wb=bfi(r,SPA(wp,a),1)); we=SPA(wp,e); wt=AT(we); + ASSERT(equ(ae,we),EVNONCE); + GA(q,B01,r,1,0); zb=BAV(q); DO(r, zb[i]=ab[i]||wb[i];); RZ(za=ifb(r,zb)); c=AN(za); + GA(q,INT,r,1,0); zs= AV(q); DO(r, zs[i]=MAX(as[i],ws[i]);); + DO(r, if(zb[i]>ab[i]){RZ(a=reaxis(za,a)); break;}); + DO(r, if(zb[i]>wb[i]){RZ(w=reaxis(za,w)); break;}); + *zs=*as; DO(r, if(zs[i]>as[i]){RZ(a=take(q,a)); break;}); + *zs=*ws; DO(r, if(zs[i]>ws[i]){RZ(w=take(q,w)); break;}); + *zs=*as+*ws; t=maxtype(at,wt); + ap=PAV(a); ay=SPA(ap,i); ax=SPA(ap,x); if(t!=at)RZ(ax=cvt(t,ax)); + wp=PAV(w); wy=SPA(wp,i); wx=SPA(wp,x); if(t!=at)RZ(wx=cvt(t,wx)); + GA(z,STYPE(t),1,r,zs); zp=PAV(z); + SPB(zp,a,za); SPB(zp,e,ze=ca(t==at?ae:we)); + if(*zb){ + SPB(zp,x, over(ax,wx)); + SPB(zp,i,y=over(ay,wy)); v=AV(y)+AN(ay); m=*as; DO(*AS(wy), *v+=m; v+=c;); + }else{C*av,*wv,*xv;I am,ak,i,j,k,mn,p,*u,wk,wm,xk,*yv; + i=j=p=0; k=bp(t); + m=*AS(ay); u=AV(ay); av=CAV(ax); am=aii(ax); ak=k*am; + n=*AS(wy); v=AV(wy); wv=CAV(wx); wm=aii(wx); wk=k*wm; mn=m+n; xk=k*(am+wm); + GA(y,INT,mn*c, 2, AS(ay)); yv= AV(y); *AS(y)=mn; + GA(x,t, mn*(am+wm),AR(ax),AS(ax)); xv=CAV(x); *AS(x)=mn; *(1+AS(x))=*zs; mvc(k*AN(x),xv,k,AV(ze)); + while(i<m||j<n){I cmp; + if (i==m)cmp= 1; + else if(j==n)cmp=-1; + else {cmp=0; DO(c, if(u[i]!=v[i]){cmp=u[i]<v[i]?-1:1; break;});} + switch(cmp){ + case -1: ICPY(yv,u,c); u+=c; ++i; memcpy(xv, av,ak); av+=ak; break; + case 0: ICPY(yv,u,c); u+=c; ++i; memcpy(xv, av,ak); av+=ak; ++p; /* fall thru */ + case 1: ICPY(yv,v,c); v+=c; ++j; memcpy(xv+ak,wv,wk); wv+=wk; + } + yv+=c; xv+=xk; + } + SPB(zp,i,p?take(sc(mn-p),y):y); SPB(zp,x,p?take(sc(mn-p),x):x); + } + R z; +} /* a,"r w where a or w or both are sparse */ + + +static C*jtovgmove(J jt,I k,I c,I m,A s,A w,C*x,A z){B b;I d,n,p=c*m,q,*u,*v; + b=ARELATIVE(z); + if(AR(w)){ + n=AN(w); d=AN(s)-AR(w); + if((!n||d)&&!b)mvc(k*p,x,k,jt->fillv); + if(n&&n<p){v=AV(s); *v=m; RZ(w=take(d?vec(INT,AR(w),d+v):s,w));} + if(n){ + if(b){q=ARELATIVE(w)*(I)w-(I)z; u=(I*)x; v=AV(w); DO(AN(w), *u++=q+*v++;);} + else MC(x,AV(w),k*AN(w)); + } + }else{ + if(b){q=*AV(w)+ARELATIVE(w)*(I)w-(I)z; u=(I*)x; DO(p, *u++=q;);} + else mvc(k*p,x,k,AV(w)); + } + R x+k*p; +} /* move an argument into the result area */ + +static F2(jtovg){A s,z;C*x;I ar,*as,c,k,m,n,q,r,*sv,wr,*ws,zn; + RZ(a&&w); + RZ(w=setfv(a,w)); RZ(coerce2(&a,&w,0L)); + ar=AR(a); wr=AR(w); r=ar+wr?MAX(ar,wr):1; + RZ(s=r?vec(INT,r,r==ar?AS(a):AS(w)):num[2]); sv=AV(s); + if(m=MIN(ar,wr)){ + as=ar+AS(a); ws=wr+AS(w); k=r; + DO(m, --as; --ws; sv[--k]=MAX(*as,*ws);); + DO(r-m, sv[i]=MAX(1,sv[i]);); + } + RE(c=prod(r-1,1+sv)); m=r>ar?1:IC(a); n=r>wr?1:IC(w); + RE(zn=mult(c,m+n)); ASSERT(0<=m+n,EVLIMIT); + GA(z,AT(a),zn,r,sv); *AS(z)=m+n; x=CAV(z); k=bp(AT(a)); + if(ARELATIVE(a)||ARELATIVE(w)){AFLAG(z)=AFREL; q=(I)jt->fillv+(I)w-(I)z; mvc(k*zn,x,k,&q);} + RZ(x=ovgmove(k,c,m,s,a,x,z)); + RZ(x=ovgmove(k,c,n,s,w,x,z)); + R z; +} /* a,w general case for array with the same type; jt->rank=0 */ + +static F2(jtovv){A z;I m,t; + t=AT(a); + GA(z,t,AN(a)+AN(w),1,0); + if(t&BOX){A1*u,*v;B p,q,r; + p=ARELATIVE(a); q=ARELATIVE(w); r=p||q; if(r)AFLAG(z)=AFREL; v=A1AV(z); + u=A1AV(a); m=p*(I)a-r*(I)z; DO(AN(a), *v++=m+*u++;); + u=A1AV(w); m=q*(I)w-r*(I)z; DO(AN(w), *v++=m+*u++;); + }else{C*x;I k; + k=bp(t); m=k*AN(a); x=CAV(z); + MC(x, AV(a),m ); + MC(x+m,AV(w),k*AN(w)); + } + R z; +} /* a,w for vectors/scalars with the same type */ + +static void om(I k,I c,I d,I m,I m1,I n,I r,C*u,C*v){I e,km,km1,kn; + e=c/d; km=k*m; km1=k*m1; kn=k*n; + if(!r&&m1!=n)DO(c, mvc(km1,u,kn,v); u+=km;) + else if(1<e){ + if(m1>n)DO(c/e, DO(e, mvc(km1,u,kn,v); u+=km;); v+=kn;) + else DO(c/e, DO(e, MC(u,v,kn); u+=km;); v+=kn;); + }else{ + if(m1>n)DO(c, mvc(km1,u,kn,v); u+=km; v+=kn;) + else DO(c, MC(u,v,kn); u+=km; v+=kn;); +}} /* move an argument into the result area */ + +F2(jtover){A z;B b;C*zv;I acn,acr,af,ar,*as,c,f,k,m,ma,mw,p,q,r,*s,t,wcn,wcr,wf,wr,*ws,zn; + RZ(a&&w); + if(SPARSE&AT(a)||SPARSE&AT(w))R ovs(a,w); + RZ(t=coerce2(&a,&w,0L)); + ar=AR(a); wr=AR(w); + if(!jt->rank&&2>ar&&2>wr)R ovv(a,w); + acr=jt->rank?jt->rank[0]:ar; af=ar-acr; as=AS(a); p=acr?as[ar-1]:1; + wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; ws=AS(w); q=wcr?ws[wr-1]:1; + r=acr+wcr?MAX(acr,wcr):1; + if(2<r||!AN(a)||!AN(w)||2<acr+wcr&&p!=q||ARELATIVE(a)||ARELATIVE(w)){ + jt->rank=0; R rank2ex(a,w,0L,acr,wcr,jtovg); + } + acn=1>=acr?p:p*as[af+acr-2]; ma=!acr&&2==wcr?q:acn; + wcn=1>=wcr?q:q*ws[wf+wcr-2]; mw=!wcr&&2==acr?p:wcn; m=ma+mw; + b=af<=wf; f=b?wf:af; s=b?ws:as; RE(c=prod(f,s)); RE(zn=mult(c,m)); + GA(z,t,zn,f+r,s); zv=CAV(z); s=AS(z)+AR(z)-1; + if(2>r)*s=m; else{*s=acr?p:q; *(s-1)=(1<acr?as[ar-2]:1)+(1<wcr?ws[wr-2]:1);} + k=bp(t); + om(k,c,prod(af,as),m,ma,acn,ar,zv, CAV(a)); + om(k,c,prod(wf,ws),m,mw,wcn,wr,zv+k*ma,CAV(w)); + R z; +} /* overall control, and a,w and a,"r w for cell rank <: 2 */ + +F2(jtstitch){B sp2;I ar,wr; + RZ(a&&w); + ar=AR(a); wr=AR(w); sp2=(SPARSE&AT(a)||SPARSE&AT(w))&&2>=ar&&2>=wr; + ASSERT(!ar||!wr||*AS(a)==*AS(w),EVLENGTH); + R sp2 ? stitchsp2(a,w) : irs2(a,w,0L,ar?ar-1:0,wr?wr-1:0,jtover); +} + +F1(jtlamin1){A x;I*s,*v,wcr,wf,wr; + RZ(w); + wr=wcr=AR(w); if(jt->rank){wcr=MIN(wr,jt->rank[1]); jt->rank=0;} wf=wr-wcr; + GA(x,INT,1+wr,1,0); v=AV(x); + s=AS(w); ICPY(v,s,wf); *(v+wf)=1; ICPY(v+1+wf,s+wf,wcr); + R reshape(x,w); +} /* ,:"r w */ + +F2(jtlamin2){A z;I ar,p,q,wr; + RZ(a&&w); + ar=AR(a); p=jt->rank?jt->rank[0]:ar; + wr=AR(w); q=jt->rank?jt->rank[1]:wr; + if(p)a=irs1(a,0L,p,jtlamin1); + if(q)w=irs1(w,0L,q,jtlamin1); + z=irs2(a,w,0L,p+!!p,q+!!q,jtover); + if(!p&&!q)z=irs1(z,0L,0L,jtlamin1); + R z; +} /* a,:"r w */ + +F2(jtapip){RZ(a&&w); R AC(a)>(AFNJA&AFLAG(a)?2:1)||!(DIRECT&AT(a))?over(a,w):apipx(a,w);} + +F2(jtapipx){A h;C*av,*wv;I ak,at,ar,*as,k,p,*u,*v,wk,wm,wn,wt,wr,*ws; + RZ(a&&w); + at=AT(a); ar=AR(a); as=AS(a); + wt=AT(w); wr=AR(w); ws=AS(w); p=-1; + if(AN(a)&&ar&&ar>=wr&&at>=wt&&5e8>AC(a)){ + p=0; u=as+ar-wr; v=ws; if(ar==wr){++u; ++v;} + DO(wr-(ar==wr), k=*u++-*v++; if(0<k)p=1; else if(0>k){p=-1; break;}); + k=bp(at); ak=k*AN(a); wm=ar==wr?*ws:1; wn=wm*aii(a); wk=k*wn; + } + if(0<=p&&AM(a)>=ak+wk+(1&&at&LAST0)){ + if(at>wt)RZ(w=cvt(at,w)); + if(p){RZ(h=vec(INT,wr,as+ar-wr)); if(ar==wr)*AV(h)=*ws; RZ(w=take(h,w));} + av=ak+CAV(a); wv=CAV(w); + if(wr&&ar>1+wr){RZ(setfv(a,w)); mvc(wk,av,k,jt->fillv);} + if(wr)MC(av,wv,k*AN(w)); else mvc(wk,av,k,wv); + *as+=wm; AN(a)+=wn; if(at&LAST0)*(av+wk)=0; + }else RZ(a=over(a,w)); + R a; +} /* append in place if possible */
new file mode 100644 --- /dev/null +++ b/vcatsp.c @@ -0,0 +1,13 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: ,. on Sparse Arguments of rank 2 or less */ + +#include "j.h" + + +F2(jtstitchsp2){I ar,wr; + RZ(a&&w); + ar=AR(a); wr=AR(w); + R irs2(a,w,0L,ar?ar-1:0,wr?wr-1:0,jtover); +} /* sparse arrays with rank 2 or less */
new file mode 100644 --- /dev/null +++ b/vchar.c @@ -0,0 +1,42 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Character Functions u&(a.&i.) and u&.(a.&i.) */ + +#include "j.h" + + +static APFX(maxC, UC,UC,UC, MAX) +static APFX(minC, UC,UC,UC, MIN) + +static AIFX(ltC, B, UC,UC, < ) +static AIFX(leC, B, UC,UC, <= ) +static AIFX(geC, B, UC,UC, >= ) +static AIFX(gtC, B, UC,UC, > ) + +#define PLUSX + + +DF2(jtcharfn2){A z;B b;C c;I an,ar,*as,m,n,wn,wr,*ws,zn,zt;V*v;VF ado=0; + RZ(a&&w); + v=VAV(self); c=ID(v->f); + if(CUNDER==v->id)switch(c){ + case CMAX: zt=LIT; ado=maxC; break; + case CMIN: zt=LIT; ado=minC; break; + case CAT: z=VAV(v->f)->f; v=VAV(z); if(CAMP==v->id&&256==i0(v->f)&&CSTILE==ID(v->g)); + }else switch(c){ + case CEQ: R eq(a,w); + case CNE: R ne(a,w); + case CLT: zt=B01; ado=ltC; break; + case CLE: zt=B01; ado=leC; break; + case CGE: zt=B01; ado=geC; break; + case CGT: zt=B01; ado=gtC; break; + } + if(!ado)R df2(a,w,self); + an=AN(a); ar=AR(a); as=AS(a); + wn=AN(w); wr=AR(w); ws=AS(w); + ASSERT(!ICMP(as,ws,MIN(ar,wr)),EVLENGTH); + b=ar<=wr; zn=b?wn:an; m=b?an:wn; n=m?zn/m:0; + GA(z,zt,zn,b?wr:ar,b?ws:as); if(!zn)R z; + ado(jt,b,m,n,CAV(z),CAV(a),CAV(w)); + R z; +}
new file mode 100644 --- /dev/null +++ b/vcomp.c @@ -0,0 +1,75 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Comparatives */ + +#include "j.h" +#include "ve.h" +#include "vcomp.h" + + +B jtteq(J jt,D u,D v){D d,s; + if(u==v)R 1; + else R 0<u==0<v && + ((0<u ? (u>v ? (s= u,d=u-v) : (s= v,d=v-u)) + : (u<v ? (s=-u,d=v-u) : (s=-v,d=u-v)) ), d<=s*jt->ct && s!=inf ); +} + +B jttlt(J jt,D u,D v){R u<v && !teq(u,v);} + +D jttfloor(J jt,D v){D x; R v<-4e35||4e35<v ? v : (x=jfloor(0.5+v), x-TGT(x,v));} +D jttceil (J jt,D v){D x; R v<-4e35||4e35<v ? v : (x=jfloor(0.5+v), x+TLT(x,v));} + + +BPFX(eqBB, EQ,BEQ,EQ,BEQ) +BPFX(neBB, NE,BNE,NE,BNE) +BPFX(ltBB, LT,BLT,GT,BGT) +BPFX(leBB, LE,BLE,GE,BGE) +BPFX(geBB, GE,BGE,LE,BLE) +BPFX(gtBB, GT,BGT,LT,BLT) + + AIFX(eqBI, B,B,I, == ) ACMP(eqBD, B,B,D, teq ) +AIFX(eqIB, B,I,B, == ) AIFX(eqII, B,I,I, == ) ACMP(eqID, B,I,D, teq ) +ACMP(eqDB, B,D,B, teq ) ACMP(eqDI, B,D,I, teq ) ACMP(eqDD, B,D,D, teq ) +APFX(eqZZ, B,Z,Z, zeq ) +APFX(eqXX, B,X,X, equ ) +APFX(eqQQ, B,Q,Q, QEQ ) +AIFX(eqCC, B,C,C, == ) AIFX(eqCS, B,UC,US, == ) AIFX(eqSC, B,US,UC, == ) AIFX(eqSS, B,S,S, ==) +APFY(eqAA, B,A,A, equ ) + + AIFX(neBI, B,B,I, != ) ACMP(neBD, B,B,D, !teq ) +AIFX(neIB, B,I,B, != ) AIFX(neII, B,I,I, != ) ACMP(neID, B,I,D, !teq ) +ACMP(neDB, B,D,B, !teq ) ACMP(neDI, B,D,I, !teq ) ACMP(neDD, B,D,D, !teq ) +APFX(neZZ, B,Z,Z, !zeq ) +APFX(neXX, B,X,X, !equ ) +APFX(neQQ, B,Q,Q, !QEQ ) +AIFX(neCC, B,C,C, != ) AIFX(neCS, B,UC,US, != ) AIFX(neSC, B,US,UC, != ) AIFX(neSS, B,S,S, !=) +APFY(neAA, B,A,A, !equ ) + + AIFX(ltBI, B,B,I, < ) ACMP(ltBD, B,B,D, TLT ) +AIFX(ltIB, B,I,B, < ) AIFX(ltII, B,I,I, < ) ACMP(ltID, B,I,D, TLT ) +ACMP(ltDB, B,D,B, TLT ) ACMP(ltDI, B,D,I, TLT ) ACMP(ltDD, B,D,D, TLT ) +APFX(ltXX, B,X,X, -1==xcompare) +APFX(ltQQ, B,Q,Q, QLT ) +APFX(ltSS, B,SB,SB, SBLT) + + AIFX(leBI, B,B,I, <= ) ACMP(leBD, B,B,D, TLE ) +AIFX(leIB, B,I,B, <= ) AIFX(leII, B,I,I, <= ) ACMP(leID, B,I,D, TLE ) +ACMP(leDB, B,D,B, TLE ) ACMP(leDI, B,D,I, TLE ) ACMP(leDD, B,D,D, TLE ) +APFX(leXX, B,X,X, 1!=xcompare) +APFX(leQQ, B,Q,Q, QLE ) +APFX(leSS, B,SB,SB, SBLE) + + AIFX(geBI, B,B,I, >= ) ACMP(geBD, B,B,D, TGE ) +AIFX(geIB, B,I,B, >= ) AIFX(geII, B,I,I, >= ) ACMP(geID, B,I,D, TGE ) +ACMP(geDB, B,D,B, TGE ) ACMP(geDI, B,D,I, TGE ) ACMP(geDD, B,D,D, TGE ) +APFX(geXX, B,X,X, -1!=xcompare) +APFX(geQQ, B,Q,Q, QGE ) +APFX(geSS, B,SB,SB, SBGE) + + AIFX(gtBI, B,B,I, > ) ACMP(gtBD, B,B,D, TGT ) +AIFX(gtIB, B,I,B, > ) AIFX(gtII, B,I,I, > ) ACMP(gtID, B,I,D, TGT ) +ACMP(gtDB, B,D,B, TGT ) ACMP(gtDI, B,D,I, TGT ) ACMP(gtDD, B,D,D, TGT ) +APFX(gtXX, B,X,X, 1==xcompare) +APFX(gtQQ, B,Q,Q, QGT ) +APFX(gtSS, B,SB,SB, SBGT)
new file mode 100644 --- /dev/null +++ b/vcomp.h @@ -0,0 +1,42 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Comparatives */ + +/* See R. Bernecky, Comparison Tolerance, SATN-23, IPSA, 1977-06-10 */ +/* For finite numbers, the following defns hold: */ +/* */ +/* teq(u,v) ABS(u-v)<=ct*MAX(ABS(u),ABS(v)) */ +/* tne(u,v) !teq(u,v) */ +/* tlt(u,v) (u< v)&&tne(u,v) */ +/* tle(u,v) (u<=v)||teq(u,v) */ +/* tge(u,v) (u>=v)||teq(u,v) */ +/* tgt(u,v) (u> v)&&tne(u,v) */ +/* tfloor(v) x=floor(0.5+v), x-tgt(x,v) */ +/* tceil(v) x=floor(0.5+v), x+tlt(x,v) */ + +#define TEQ teq +#define TEQXD(u,v) teq((D)u, v) +#define TEQDX(u,v) teq( u,(D)v) +#define TNE !teq +#define TNEXD !TEQXD +#define TNEDX !TEQDX +#define TLT tlt +#define TLTXD(u,v) tlt((D)(u), v ) +#define TLTDX(u,v) tlt( u,(D)(v)) +#define TLE(u,v) (tlt(u,v) || teq(u,v)) +#define TLEXD(u,v) TLE((D)(u), v ) +#define TLEDX(u,v) TLE( u ,(D)(v)) +#define TGT(u,v) TLT( v , u ) +#define TGTXD(u,v) TLT( v ,(D)(u)) +#define TGTDX(u,v) TLT((D)(v), u ) +#define TGE(u,v) TLE( v , u ) +#define TGEXD(u,v) TLE( v ,(D)(u)) +#define TGEDX(u,v) TLE((D)(v), u ) + +#define ALT(x,y) ((x)< (y)) +#define ALE(x,y) ((x)<=(y)) +#define AEQ(x,y) ((x)==(y)) +#define ANE(x,y) ((x)!=(y)) +#define AGE(x,y) ((x)>=(y)) +#define AGT(x,y) ((x)> (y))
new file mode 100644 --- /dev/null +++ b/vcompsc.c @@ -0,0 +1,588 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Comparatives */ +/* */ +/* Special code for the following cases: */ +/* comp i. 0: i.&0@:comp */ +/* comp i. 1: i.&1@:comp */ +/* comp i: 0: i:&0@:comp */ +/* comp i: 1: i:&1@:comp */ +/* [: + / comp + /@:comp */ +/* [: +./ comp +./@:comp 1: e. comp */ +/* 0: e. comp */ +/* [: I. comp I.@:comp */ +/* where comp is one of the following: */ +/* = ~: < <: >: > E. e. */ + +#include "j.h" +#include "ve.h" +#include "vcomp.h" + + +#define INDF(f,T0,T1,F) \ + static F2(f){I an,n,wn;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + if (!AR(a)){x=*av; DO(n, y=*wv++; if(F(x,y))R sc(i););} \ + else if(!AR(w)){y=*wv; DO(n, x=*av++; if(F(x,y))R sc(i););} \ + else { DO(n, x=*av++; y=*wv++; if(F(x,y))R sc(i););} \ + R sc(n); \ + } + +#define JNDF(f,T0,T1,F) \ + static F2(f){I an,n,wn;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + if (!AR(a)){x=*av; wv+=n; DO(n, y=*--wv; if(F(x,y))R sc(n-1-i););} \ + else if(!AR(w)){y=*wv; av+=n; DO(n, x=*--av; if(F(x,y))R sc(n-1-i););} \ + else {av+=n; wv+=n; DO(n, x=*--av; y=*--wv; if(F(x,y))R sc(n-1-i););} \ + R sc(n); \ + } + +#define SUMF(f,T0,T1,F) \ + static F2(f){I an,m=0,n,wn;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + if (!AR(a)){x=*av; DO(n, y=*wv++; if(F(x,y))++m;);} \ + else if(!AR(w)){y=*wv; DO(n, x=*av++; if(F(x,y))++m;);} \ + else { DO(n, x=*av++; y=*wv++; if(F(x,y))++m;);} \ + R sc(m); \ + } + +#define ANYF(f,T0,T1,F) \ + static F2(f){I an,n,wn;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + if (!AR(a)){x=*av; DO(n, y=*wv++; if(F(x,y))R one;);} \ + else if(!AR(w)){y=*wv; DO(n, x=*av++; if(F(x,y))R one;);} \ + else { DO(n, x=*av++; y=*wv++; if(F(x,y))R one;);} \ + R zero; \ + } + +#define ALLF(f,T0,T1,F) \ + static F2(f){I an,n,wn;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + if (!AR(a)){x=*av; DO(n, y=*wv++; if(!F(x,y))R zero;);} \ + else if(!AR(w)){y=*wv; DO(n, x=*av++; if(!F(x,y))R zero;);} \ + else { DO(n, x=*av++; y=*wv++; if(!F(x,y))R zero;);} \ + R one; \ + } + +#define IFB1 \ + {if(zu==zv){I m=zv-AV(z); RZ(z=ext(0,z)); zv=m+AV(z); zu=AN(z)+AV(z);} *zv++=i;} + +#define IFBF(f,T0,T1,F) \ + static F2(f){A z;I an,n,wn,*zu,*zv;T0*av,x;T1*wv,y; \ + an=AN(a); av=(T0*)AV(a); \ + wn=AN(w); wv=(T1*)AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + RZ(z=exta(INT,1L,1L,MAX(22,n/8))); zv=AV(z); zu=zv+AN(z); \ + if (!AR(a)){x=*av; DO(n, y=*wv++; if(F(x,y))IFB1;);} \ + else if(!AR(w)){y=*wv; DO(n, x=*av++; if(F(x,y))IFB1;);} \ + else { DO(n, x=*av++; y=*wv++; if(F(x,y))IFB1;);} \ + AN(z)=*AS(z)=zv-AV(z); R z; \ + } + + +/* Now define byte-parallel (4 bytes at a time) versions of above */ + +#define JNDBR(yy) if(r&&(y=yy))DO(r, if(yv[r-1-i])R sc(n-1-i);); + +#if SY_64 +#define ASSIGNX(v) {x=*v; xv[1]=xv[2]=xv[3]=xv[4]=xv[5]=xv[6]=xv[7]=xv[0];} +#define INDB3 R sc( i*SZI+(yv[0]?0:yv[1]?1:yv[2]?2:yv[3]?3:yv[4]?4:yv[5]?5:yv[6]?6:7) ); +#define JNDB3 R sc(n-1-(r+i*SZI+(yv[7]?0:yv[6]?1:yv[5]?2:yv[4]?3:yv[3]?4:yv[2]?5:yv[1]?6:7))); +#else +#define ASSIGNX(v) {x=*v; xv[1]=xv[2]=xv[3]=xv[0];} +#define INDB3 R sc( i*SZI+(yv[0]?0:yv[1]?1:yv[2]?2:3) ); +#define JNDB3 R sc(n-1-(r+i*SZI+(yv[3]?0:yv[2]?1:yv[1]?2:3))); +#endif + +#define INDB(f,T0,T1,F) \ + static F2(f){B*xv,*yv;I an,*av,n,q,r,wn,*wv,x,y; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + q=n/SZI; r=n%SZI; \ + xv=(B*)&x; yv=(B*)&y; \ + if (!AR(a)){ASSIGNX(av); DO(q, if(y=F(x, *wv++))INDB3;); y=F(x, *wv);} \ + else if(!AR(w)){ASSIGNX(wv); DO(q, if(y=F(*av++,x ))INDB3;); y=F(*av,x );} \ + else { DO(q, if(y=F(*av++,*wv++))INDB3;); y=F(*av,*wv);} \ + if(y)DO(r, if(yv[i])R sc(i+q*SZI);); \ + R sc(n); \ + } + +#define JNDB(f,T0,T1,F) \ + static F2(f){B*xv,*yv;I an,*av,n,q,r,wn,*wv,x,y; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + q=n/SZI; r=n%SZI; \ + xv=(B*)&x; yv=(B*)&y; \ + if (!AR(a)){ASSIGNX(av); wv+=q; JNDBR(F(x, *wv)); DO(q, if(y=F(x, *--wv))JNDB3;);} \ + else if(!AR(w)){ASSIGNX(wv); av+=q; JNDBR(F(*av,x )); DO(q, if(y=F(*--av,x ))JNDB3;);} \ + else {av+=q; wv+=q; JNDBR(F(*av,*wv)); DO(q, if(y=F(*--av,*--wv))JNDB3;);} \ + R sc(n); \ + } + +#define SUMB(f,T0,T1,F) \ + static F2(f){B*xv;I an,*av,n,p,q,r,r1,wn,*wv,x,z=0;UC*tu;UI t; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + p=n/SZI; q=p/255; r=p%255; r1=n%SZI; \ + xv=(B*)&x; tu=(UC*)&t; \ + if (!AR(a)){ \ + ASSIGNX(av); \ + DO(q, t=0; DO(255, t+=F(x, *wv++);); DO(SZI,z+=tu[i];);); \ + t=0; DO(r, t+=F(x, *wv++);); DO(SZI,z+=tu[i];); x=F(x, *wv); \ + }else if(!AR(w)){ \ + ASSIGNX(wv); \ + DO(q, t=0; DO(255, t+=F(*av++,x );); DO(SZI,z+=tu[i];);); \ + t=0; DO(r, t+=F(*av++,x );); DO(SZI,z+=tu[i];); x=F(*av,x ); \ + }else{ \ + DO(q, t=0; DO(255, t+=F(*av++,*wv++);); DO(SZI,z+=tu[i];);); \ + t=0; DO(r, t+=F(*av++,*wv++);); DO(SZI,z+=tu[i];); x=F(*av,*wv); \ + } \ + DO(r1, z+=xv[i];); \ + R sc(z); \ + } + +#define ANYB(f,T0,T1,F) \ + static F2(f){B*xv; I an,*av,n,p,r1, wn,*wv,x; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + p=n/SZI; r1=n%SZI;; \ + xv=(B*)&x; \ + if (!AR(a)){ASSIGNX(av); DO(p, if( F(x, *wv++))R one; ); x=F(x, *wv);} \ + else if(!AR(w)){ASSIGNX(wv); DO(p, if( F(*av++,x ))R one; ); x=F(*av,x );} \ + else { DO(p, if( F(*av++,*wv++))R one; ); x=F(*av,*wv);} \ + DO(r1, if(xv[i])R one;); \ + R zero; \ + } + +#define ALLB(f,T0,T1,F) \ + static F2(f){B*xv;C*tv;I an,*av,n,p,r1,t,wn,*wv,x; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + p=n/SZI; r1=n%SZI;; \ + xv=(B*)&x; tv=(C*)&t; DO(SZI, tv[i]=1;); \ + if (!AR(a)){ASSIGNX(av); DO(p, if(t!=F(x, *wv++))R zero;); x=F(x, *wv);} \ + else if(!AR(w)){ASSIGNX(wv); DO(p, if(t!=F(*av++,x ))R zero;); x=F(*av,x );} \ + else { DO(p, if(t!=F(*av++,*wv++))R zero;); x=F(*av,*wv);} \ + DO(r1, if(!xv[i])R zero;); \ + R one; \ + } + +#if SY_64 +#define IFB3 \ + {if(zu<zv){I c=zv-AV(z); RZ(z=ext(0,z)); zv=c+AV(z); zu=AV(z)+AN(z)-SZI;} \ + if(yv[0])*zv++= m; \ + if(yv[1])*zv++=1+m; \ + if(yv[2])*zv++=2+m; \ + if(yv[3])*zv++=3+m; \ + if(yv[4])*zv++=4+m; \ + if(yv[5])*zv++=5+m; \ + if(yv[6])*zv++=6+m; \ + if(yv[7])*zv++=7+m; \ + } +#else +#define IFB3 \ + {if(zu<zv){I c=zv-AV(z); RZ(z=ext(0,z)); zv=c+AV(z); zu=AV(z)+AN(z)-SZI;} \ + switch(y){ \ + case B0001: *zv++=3+m; break; \ + case B0010: *zv++=2+m; break; \ + case B0011: *zv++=2+m; *zv++=3+m; break; \ + case B0100: *zv++=1+m; break; \ + case B0101: *zv++=1+m; *zv++=3+m; break; \ + case B0110: *zv++=1+m; *zv++=2+m; break; \ + case B0111: *zv++=1+m; *zv++=2+m; *zv++=3+m; break; \ + case B1000: *zv++=m; break; \ + case B1001: *zv++=m; *zv++=3+m; break; \ + case B1010: *zv++=m; *zv++=2+m; break; \ + case B1011: *zv++=m; *zv++=2+m; *zv++=3+m; break; \ + case B1100: *zv++=m; *zv++=1+m; break; \ + case B1101: *zv++=m; *zv++=1+m; *zv++=3+m; break; \ + case B1110: *zv++=m; *zv++=1+m; *zv++=2+m; break; \ + case B1111: *zv++=m; *zv++=1+m; *zv++=2+m; *zv++=3+m; break; \ + }} +#endif + +#define IFBB(f,T0,T1,F) \ + static F2(f){A z;B*xv,*yv;I an,*av,m=0,n,q,r,wn,*wv,x,y,*zu,*zv; \ + an=AN(a); av=AV(a); \ + wn=AN(w); wv=AV(w); n=AR(a)&&AR(w)?MAX(an,wn):AR(a)?an:wn; \ + q=n/SZI; r=n%SZI; \ + xv=(B*)&x; yv=(B*)&y; \ + RZ(z=exta(INT,1L,1L,MAX(22,n/SZI))); zv=AV(z); zu=zv+AN(z)-SZI; \ + if (!AR(a)){ASSIGNX(av); DO(q, if(y=F(x, *wv++))IFB3; m+=SZI;); y=F(x, *wv);} \ + else if(!AR(w)){ASSIGNX(wv); DO(q, if(y=F(*av++,x ))IFB3; m+=SZI;); y=F(*av,x );} \ + else { DO(q, if(y=F(*av++,*wv++))IFB3; m+=SZI;); y=F(*av,*wv);} \ + if(r&&y){DO(SZI-r, yv[r+i]=0;); IFB3;}; \ + AN(z)=*AS(z)=zv-AV(z); R z; \ + } + +INDB( i0eqBB,B,B,NE ) INDF( i0eqBI,B,I,ANE ) INDF( i0eqBD,B,D,TNEXD) /* = */ +INDF( i0eqIB,I,B,ANE ) INDF( i0eqII,I,I,ANE ) INDF( i0eqID,I,D,TNEXD) +INDF( i0eqDB,D,B,TNEDX) INDF( i0eqDI,D,I,TNEDX) INDF( i0eqDD,D,D,TNE ) + +INDB( i1eqBB,B,B,EQ ) INDF( i1eqBI,B,I,AEQ ) INDF( i1eqBD,B,D,TEQXD) +INDF( i1eqIB,I,B,AEQ ) INDF( i1eqII,I,I,AEQ ) INDF( i1eqID,I,D,TEQXD) +INDF( i1eqDB,D,B,TEQDX) INDF( i1eqDI,D,I,TEQDX) INDF( i1eqDD,D,D,TEQ ) + +JNDB( j0eqBB,B,B,NE ) JNDF( j0eqBI,B,I,ANE ) JNDF( j0eqBD,B,D,TNEXD) +JNDF( j0eqIB,I,B,ANE ) JNDF( j0eqII,I,I,ANE ) JNDF( j0eqID,I,D,TNEXD) +JNDF( j0eqDB,D,B,TNEDX) JNDF( j0eqDI,D,I,TNEDX) JNDF( j0eqDD,D,D,TNE ) + +JNDB( j1eqBB,B,B,EQ ) JNDF( j1eqBI,B,I,AEQ ) JNDF( j1eqBD,B,D,TEQXD) +JNDF( j1eqIB,I,B,AEQ ) JNDF( j1eqII,I,I,AEQ ) JNDF( j1eqID,I,D,TEQXD) +JNDF( j1eqDB,D,B,TEQDX) JNDF( j1eqDI,D,I,TEQDX) JNDF( j1eqDD,D,D,TEQ ) + +SUMB(sumeqBB,B,B,EQ ) SUMF(sumeqBI,B,I,AEQ ) SUMF(sumeqBD,B,D,TEQXD) +SUMF(sumeqIB,I,B,AEQ ) SUMF(sumeqII,I,I,AEQ ) SUMF(sumeqID,I,D,TEQXD) +SUMF(sumeqDB,D,B,TEQDX) SUMF(sumeqDI,D,I,TEQDX) SUMF(sumeqDD,D,D,TEQ ) + +ANYB(anyeqBB,B,B,EQ ) ANYF(anyeqBI,B,I,AEQ ) ANYF(anyeqBD,B,D,TEQXD) +ANYF(anyeqIB,I,B,AEQ ) ANYF(anyeqII,I,I,AEQ ) ANYF(anyeqID,I,D,TEQXD) +ANYF(anyeqDB,D,B,TEQDX) ANYF(anyeqDI,D,I,TEQDX) ANYF(anyeqDD,D,D,TEQ ) + +ALLB(alleqBB,B,B,EQ ) ALLF(alleqBI,B,I,AEQ ) ALLF(alleqBD,B,D,TEQXD) +ALLF(alleqIB,I,B,AEQ ) ALLF(alleqII,I,I,AEQ ) ALLF(alleqID,I,D,TEQXD) +ALLF(alleqDB,D,B,TEQDX) ALLF(alleqDI,D,I,TEQDX) ALLF(alleqDD,D,D,TEQ ) + +IFBB(ifbeqBB,B,B,EQ ) IFBF(ifbeqBI,B,I,AEQ ) IFBF(ifbeqBD,B,D,TEQXD) +IFBF(ifbeqIB,I,B,AEQ ) IFBF(ifbeqII,I,I,AEQ ) IFBF(ifbeqID,I,D,TEQXD) +IFBF(ifbeqDB,D,B,TEQDX) IFBF(ifbeqDI,D,I,TEQDX) IFBF(ifbeqDD,D,D,TEQ ) + +INDB( i0neBB,B,B,EQ ) INDF( i0neBI,B,I,AEQ ) INDF( i0neBD,B,D,TEQXD) /* ~: */ +INDF( i0neIB,I,B,AEQ ) INDF( i0neII,I,I,AEQ ) INDF( i0neID,I,D,TEQXD) +INDF( i0neDB,D,B,TEQDX) INDF( i0neDI,D,I,TEQDX) INDF( i0neDD,D,D,TEQ ) + +INDB( i1neBB,B,B,NE ) INDF( i1neBI,B,I,ANE ) INDF( i1neBD,B,D,TNEXD) +INDF( i1neIB,I,B,ANE ) INDF( i1neII,I,I,ANE ) INDF( i1neID,I,D,TNEXD) +INDF( i1neDB,D,B,TNEDX) INDF( i1neDI,D,I,TNEDX) INDF( i1neDD,D,D,TNE ) + +JNDB( j0neBB,B,B,EQ ) JNDF( j0neBI,B,I,AEQ ) JNDF( j0neBD,B,D,TEQXD) +JNDF( j0neIB,I,B,AEQ ) JNDF( j0neII,I,I,AEQ ) JNDF( j0neID,I,D,TEQXD) +JNDF( j0neDB,D,B,TEQDX) JNDF( j0neDI,D,I,TEQDX) JNDF( j0neDD,D,D,TEQ ) + +JNDB( j1neBB,B,B,NE ) JNDF( j1neBI,B,I,ANE ) JNDF( j1neBD,B,D,TNEXD) +JNDF( j1neIB,I,B,ANE ) JNDF( j1neII,I,I,ANE ) JNDF( j1neID,I,D,TNEXD) +JNDF( j1neDB,D,B,TNEDX) JNDF( j1neDI,D,I,TNEDX) JNDF( j1neDD,D,D,TNE ) + +SUMB(sumneBB,B,B,NE ) SUMF(sumneBI,B,I,ANE ) SUMF(sumneBD,B,D,TNEXD) +SUMF(sumneIB,I,B,ANE ) SUMF(sumneII,I,I,ANE ) SUMF(sumneID,I,D,TNEXD) +SUMF(sumneDB,D,B,TNEDX) SUMF(sumneDI,D,I,TNEDX) SUMF(sumneDD,D,D,TNE ) + +ANYB(anyneBB,B,B,NE ) ANYF(anyneBI,B,I,ANE ) ANYF(anyneBD,B,D,TNEXD) +ANYF(anyneIB,I,B,ANE ) ANYF(anyneII,I,I,ANE ) ANYF(anyneID,I,D,TNEXD) +ANYF(anyneDB,D,B,TNEDX) ANYF(anyneDI,D,I,TNEDX) ANYF(anyneDD,D,D,TNE ) + +ALLB(allneBB,B,B,NE ) ALLF(allneBI,B,I,ANE ) ALLF(allneBD,B,D,TNEXD) +ALLF(allneIB,I,B,ANE ) ALLF(allneII,I,I,ANE ) ALLF(allneID,I,D,TNEXD) +ALLF(allneDB,D,B,TNEDX) ALLF(allneDI,D,I,TNEDX) ALLF(allneDD,D,D,TNE ) + +IFBB(ifbneBB,B,B,NE ) IFBF(ifbneBI,B,I,ANE ) IFBF(ifbneBD,B,D,TNEXD) +IFBF(ifbneIB,I,B,ANE ) IFBF(ifbneII,I,I,ANE ) IFBF(ifbneID,I,D,TNEXD) +IFBF(ifbneDB,D,B,TNEDX) IFBF(ifbneDI,D,I,TNEDX) IFBF(ifbneDD,D,D,TNE ) + +INDB( i0ltBB,B,B,GE ) INDF( i0ltBI,B,I,AGE ) INDF( i0ltBD,B,D,TGEXD) /* < */ +INDF( i0ltIB,I,B,AGE ) INDF( i0ltII,I,I,AGE ) INDF( i0ltID,I,D,TGEXD) +INDF( i0ltDB,D,B,TGEDX) INDF( i0ltDI,D,I,TGEDX) INDF( i0ltDD,D,D,TGE ) + +INDB( i1ltBB,B,B,LT ) INDF( i1ltBI,B,I,ALT ) INDF( i1ltBD,B,D,TLTXD) +INDF( i1ltIB,I,B,ALT ) INDF( i1ltII,I,I,ALT ) INDF( i1ltID,I,D,TLTXD) +INDF( i1ltDB,D,B,TLTDX) INDF( i1ltDI,D,I,TLTDX) INDF( i1ltDD,D,D,TLT ) + +JNDB( j0ltBB,B,B,GE ) JNDF( j0ltBI,B,I,AGE ) JNDF( j0ltBD,B,D,TGEXD) +JNDF( j0ltIB,I,B,AGE ) JNDF( j0ltII,I,I,AGE ) JNDF( j0ltID,I,D,TGEXD) +JNDF( j0ltDB,D,B,TGEDX) JNDF( j0ltDI,D,I,TGEDX) JNDF( j0ltDD,D,D,TGE ) + +JNDB( j1ltBB,B,B,LT ) JNDF( j1ltBI,B,I,ALT ) JNDF( j1ltBD,B,D,TLTXD) +JNDF( j1ltIB,I,B,ALT ) JNDF( j1ltII,I,I,ALT ) JNDF( j1ltID,I,D,TLTXD) +JNDF( j1ltDB,D,B,TLTDX) JNDF( j1ltDI,D,I,TLTDX) JNDF( j1ltDD,D,D,TLT ) + +SUMB(sumltBB,B,B,LT ) SUMF(sumltBI,B,I,ALT ) SUMF(sumltBD,B,D,TLTXD) +SUMF(sumltIB,I,B,ALT ) SUMF(sumltII,I,I,ALT ) SUMF(sumltID,I,D,TLTXD) +SUMF(sumltDB,D,B,TLTDX) SUMF(sumltDI,D,I,TLTDX) SUMF(sumltDD,D,D,TLT ) + +ANYB(anyltBB,B,B,LT ) ANYF(anyltBI,B,I,ALT ) ANYF(anyltBD,B,D,TLTXD) +ANYF(anyltIB,I,B,ALT ) ANYF(anyltII,I,I,ALT ) ANYF(anyltID,I,D,TLTXD) +ANYF(anyltDB,D,B,TLTDX) ANYF(anyltDI,D,I,TLTDX) ANYF(anyltDD,D,D,TLT ) + +ALLB(allltBB,B,B,LT ) ALLF(allltBI,B,I,ALT ) ALLF(allltBD,B,D,TLTXD) +ALLF(allltIB,I,B,ALT ) ALLF(allltII,I,I,ALT ) ALLF(allltID,I,D,TLTXD) +ALLF(allltDB,D,B,TLTDX) ALLF(allltDI,D,I,TLTDX) ALLF(allltDD,D,D,TLT ) + +IFBB(ifbltBB,B,B,LT ) IFBF(ifbltBI,B,I,ALT ) IFBF(ifbltBD,B,D,TLTXD) +IFBF(ifbltIB,I,B,ALT ) IFBF(ifbltII,I,I,ALT ) IFBF(ifbltID,I,D,TLTXD) +IFBF(ifbltDB,D,B,TLTDX) IFBF(ifbltDI,D,I,TLTDX) IFBF(ifbltDD,D,D,TLT ) + +INDB( i0leBB,B,B,GT ) INDF( i0leBI,B,I,AGT ) INDF( i0leBD,B,D,TGTXD) /* <: */ +INDF( i0leIB,I,B,AGT ) INDF( i0leII,I,I,AGT ) INDF( i0leID,I,D,TGTXD) +INDF( i0leDB,D,B,TGTDX) INDF( i0leDI,D,I,TGTDX) INDF( i0leDD,D,D,TGT ) + +INDB( i1leBB,B,B,LE ) INDF( i1leBI,B,I,ALE ) INDF( i1leBD,B,D,TLEXD) +INDF( i1leIB,I,B,ALE ) INDF( i1leII,I,I,ALE ) INDF( i1leID,I,D,TLEXD) +INDF( i1leDB,D,B,TLEDX) INDF( i1leDI,D,I,TLEDX) INDF( i1leDD,D,D,TLE ) + +JNDB( j0leBB,B,B,GT ) JNDF( j0leBI,B,I,AGT ) JNDF( j0leBD,B,D,TGTXD) +JNDF( j0leIB,I,B,AGT ) JNDF( j0leII,I,I,AGT ) JNDF( j0leID,I,D,TGTXD) +JNDF( j0leDB,D,B,TGTDX) JNDF( j0leDI,D,I,TGTDX) JNDF( j0leDD,D,D,TGT ) + +JNDB( j1leBB,B,B,LE ) JNDF( j1leBI,B,I,ALE ) JNDF( j1leBD,B,D,TLEXD) +JNDF( j1leIB,I,B,ALE ) JNDF( j1leII,I,I,ALE ) JNDF( j1leID,I,D,TLEXD) +JNDF( j1leDB,D,B,TLEDX) JNDF( j1leDI,D,I,TLEDX) JNDF( j1leDD,D,D,TLE ) + +SUMB(sumleBB,B,B,LE ) SUMF(sumleBI,B,I,ALE ) SUMF(sumleBD,B,D,TLEXD) +SUMF(sumleIB,I,B,ALE ) SUMF(sumleII,I,I,ALE ) SUMF(sumleID,I,D,TLEXD) +SUMF(sumleDB,D,B,TLEDX) SUMF(sumleDI,D,I,TLEDX) SUMF(sumleDD,D,D,TLE ) + +ANYB(anyleBB,B,B,LE ) ANYF(anyleBI,B,I,ALE ) ANYF(anyleBD,B,D,TLEXD) +ANYF(anyleIB,I,B,ALE ) ANYF(anyleII,I,I,ALE ) ANYF(anyleID,I,D,TLEXD) +ANYF(anyleDB,D,B,TLEDX) ANYF(anyleDI,D,I,TLEDX) ANYF(anyleDD,D,D,TLE ) + +ALLB(allleBB,B,B,LE ) ALLF(allleBI,B,I,ALE ) ALLF(allleBD,B,D,TLEXD) +ALLF(allleIB,I,B,ALE ) ALLF(allleII,I,I,ALE ) ALLF(allleID,I,D,TLEXD) +ALLF(allleDB,D,B,TLEDX) ALLF(allleDI,D,I,TLEDX) ALLF(allleDD,D,D,TLE ) + +IFBB(ifbleBB,B,B,LE ) IFBF(ifbleBI,B,I,ALE ) IFBF(ifbleBD,B,D,TLEXD) +IFBF(ifbleIB,I,B,ALE ) IFBF(ifbleII,I,I,ALE ) IFBF(ifbleID,I,D,TLEXD) +IFBF(ifbleDB,D,B,TLEDX) IFBF(ifbleDI,D,I,TLEDX) IFBF(ifbleDD,D,D,TLE ) + +INDB( i0geBB,B,B,LT ) INDF( i0geBI,B,I,ALT ) INDF( i0geBD,B,D,TLTXD) /* >: */ +INDF( i0geIB,I,B,ALT ) INDF( i0geII,I,I,ALT ) INDF( i0geID,I,D,TLTXD) +INDF( i0geDB,D,B,TLTDX) INDF( i0geDI,D,I,TLTDX) INDF( i0geDD,D,D,TLT ) + +INDB( i1geBB,B,B,GE ) INDF( i1geBI,B,I,AGE ) INDF( i1geBD,B,D,TGEXD) +INDF( i1geIB,I,B,AGE ) INDF( i1geII,I,I,AGE ) INDF( i1geID,I,D,TGEXD) +INDF( i1geDB,D,B,TGEDX) INDF( i1geDI,D,I,TGEDX) INDF( i1geDD,D,D,TGE ) + +JNDB( j0geBB,B,B,LT ) JNDF( j0geBI,B,I,ALT ) JNDF( j0geBD,B,D,TLTXD) +JNDF( j0geIB,I,B,ALT ) JNDF( j0geII,I,I,ALT ) JNDF( j0geID,I,D,TLTXD) +JNDF( j0geDB,D,B,TLTDX) JNDF( j0geDI,D,I,TLTDX) JNDF( j0geDD,D,D,TLT ) + +JNDB( j1geBB,B,B,GE ) JNDF( j1geBI,B,I,AGE ) JNDF( j1geBD,B,D,TGEXD) +JNDF( j1geIB,I,B,AGE ) JNDF( j1geII,I,I,AGE ) JNDF( j1geID,I,D,TGEXD) +JNDF( j1geDB,D,B,TGEDX) JNDF( j1geDI,D,I,TGEDX) JNDF( j1geDD,D,D,TGE ) + +SUMB(sumgeBB,B,B,GE ) SUMF(sumgeBI,B,I,AGE ) SUMF(sumgeBD,B,D,TGEXD) +SUMF(sumgeIB,I,B,AGE ) SUMF(sumgeII,I,I,AGE ) SUMF(sumgeID,I,D,TGEXD) +SUMF(sumgeDB,D,B,TGEDX) SUMF(sumgeDI,D,I,TGEDX) SUMF(sumgeDD,D,D,TGE ) + +ANYB(anygeBB,B,B,GE ) ANYF(anygeBI,B,I,AGE ) ANYF(anygeBD,B,D,TGEXD) +ANYF(anygeIB,I,B,AGE ) ANYF(anygeII,I,I,AGE ) ANYF(anygeID,I,D,TGEXD) +ANYF(anygeDB,D,B,TGEDX) ANYF(anygeDI,D,I,TGEDX) ANYF(anygeDD,D,D,TGE ) + +ALLB(allgeBB,B,B,GE ) ALLF(allgeBI,B,I,AGE ) ALLF(allgeBD,B,D,TGEXD) +ALLF(allgeIB,I,B,AGE ) ALLF(allgeII,I,I,AGE ) ALLF(allgeID,I,D,TGEXD) +ALLF(allgeDB,D,B,TGEDX) ALLF(allgeDI,D,I,TGEDX) ALLF(allgeDD,D,D,TGE ) + +IFBB(ifbgeBB,B,B,GE ) IFBF(ifbgeBI,B,I,AGE ) IFBF(ifbgeBD,B,D,TGEXD) +IFBF(ifbgeIB,I,B,AGE ) IFBF(ifbgeII,I,I,AGE ) IFBF(ifbgeID,I,D,TGEXD) +IFBF(ifbgeDB,D,B,TGEDX) IFBF(ifbgeDI,D,I,TGEDX) IFBF(ifbgeDD,D,D,TGE ) + +INDB( i0gtBB,B,B,LE ) INDF( i0gtBI,B,I,ALE ) INDF( i0gtBD,B,D,TLEXD) /* > */ +INDF( i0gtIB,I,B,ALE ) INDF( i0gtII,I,I,ALE ) INDF( i0gtID,I,D,TLEXD) +INDF( i0gtDB,D,B,TLEDX) INDF( i0gtDI,D,I,TLEDX) INDF( i0gtDD,D,D,TLE ) + +INDB( i1gtBB,B,B,GT ) INDF( i1gtBI,B,I,AGT ) INDF( i1gtBD,B,D,TGTXD) +INDF( i1gtIB,I,B,AGT ) INDF( i1gtII,I,I,AGT ) INDF( i1gtID,I,D,TGTXD) +INDF( i1gtDB,D,B,TGTDX) INDF( i1gtDI,D,I,TGTDX) INDF( i1gtDD,D,D,TGT ) + +JNDB( j0gtBB,B,B,LE ) JNDF( j0gtBI,B,I,ALE ) JNDF( j0gtBD,B,D,TLEXD) +JNDF( j0gtIB,I,B,ALE ) JNDF( j0gtII,I,I,ALE ) JNDF( j0gtID,I,D,TLEXD) +JNDF( j0gtDB,D,B,TLEDX) JNDF( j0gtDI,D,I,TLEDX) JNDF( j0gtDD,D,D,TLE ) + +JNDB( j1gtBB,B,B,GT ) JNDF( j1gtBI,B,I,AGT ) JNDF( j1gtBD,B,D,TGTXD) +JNDF( j1gtIB,I,B,AGT ) JNDF( j1gtII,I,I,AGT ) JNDF( j1gtID,I,D,TGTXD) +JNDF( j1gtDB,D,B,TGTDX) JNDF( j1gtDI,D,I,TGTDX) JNDF( j1gtDD,D,D,TGT ) + +SUMB(sumgtBB,B,B,GT ) SUMF(sumgtBI,B,I,AGT ) SUMF(sumgtBD,B,D,TGTXD) +SUMF(sumgtIB,I,B,AGT ) SUMF(sumgtII,I,I,AGT ) SUMF(sumgtID,I,D,TGTXD) +SUMF(sumgtDB,D,B,TGTDX) SUMF(sumgtDI,D,I,TGTDX) SUMF(sumgtDD,D,D,TGT ) + +ALLB(allgtBB,B,B,GT ) ALLF(allgtBI,B,I,AGT ) ALLF(allgtBD,B,D,TGTXD) +ALLF(allgtIB,I,B,AGT ) ALLF(allgtII,I,I,AGT ) ALLF(allgtID,I,D,TGTXD) +ALLF(allgtDB,D,B,TGTDX) ALLF(allgtDI,D,I,TGTDX) ALLF(allgtDD,D,D,TGT ) + +ANYB(anygtBB,B,B,GT ) ANYF(anygtBI,B,I,AGT ) ANYF(anygtBD,B,D,TGTXD) +ANYF(anygtIB,I,B,AGT ) ANYF(anygtII,I,I,AGT ) ANYF(anygtID,I,D,TGTXD) +ANYF(anygtDB,D,B,TGTDX) ANYF(anygtDI,D,I,TGTDX) ANYF(anygtDD,D,D,TGT ) + +IFBB(ifbgtBB,B,B,GT ) IFBF(ifbgtBI,B,I,AGT ) IFBF(ifbgtBD,B,D,TGTXD) +IFBF(ifbgtIB,I,B,AGT ) IFBF(ifbgtII,I,I,AGT ) IFBF(ifbgtID,I,D,TGTXD) +IFBF(ifbgtDB,D,B,TGTDX) IFBF(ifbgtDI,D,I,TGTDX) IFBF(ifbgtDD,D,D,TGT ) + + +static AF atcompxy[]={ /* table for (B01,INT,FL) vs. (B01,INT,FL) */ + i0eqBB, i0eqBI, i0eqBD, i0eqIB, i0eqII, i0eqID, i0eqDB, i0eqDI, i0eqDD, /* 0 */ + i0neBB, i0neBI, i0neBD, i0neIB, i0neII, i0neID, i0neDB, i0neDI, i0neDD, + i0ltBB, i0ltBI, i0ltBD, i0ltIB, i0ltII, i0ltID, i0ltDB, i0ltDI, i0ltDD, + i0leBB, i0leBI, i0leBD, i0leIB, i0leII, i0leID, i0leDB, i0leDI, i0leDD, + i0geBB, i0geBI, i0geBD, i0geIB, i0geII, i0geID, i0geDB, i0geDI, i0geDD, + i0gtBB, i0gtBI, i0gtBD, i0gtIB, i0gtII, i0gtID, i0gtDB, i0gtDI, i0gtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + i1eqBB, i1eqBI, i1eqBD, i1eqIB, i1eqII, i1eqID, i1eqDB, i1eqDI, i1eqDD, /* 1 */ + i1neBB, i1neBI, i1neBD, i1neIB, i1neII, i1neID, i1neDB, i1neDI, i1neDD, + i1ltBB, i1ltBI, i1ltBD, i1ltIB, i1ltII, i1ltID, i1ltDB, i1ltDI, i1ltDD, + i1leBB, i1leBI, i1leBD, i1leIB, i1leII, i1leID, i1leDB, i1leDI, i1leDD, + i1geBB, i1geBI, i1geBD, i1geIB, i1geII, i1geID, i1geDB, i1geDI, i1geDD, + i1gtBB, i1gtBI, i1gtBD, i1gtIB, i1gtII, i1gtID, i1gtDB, i1gtDI, i1gtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + j0eqBB, j0eqBI, j0eqBD, j0eqIB, j0eqII, j0eqID, j0eqDB, j0eqDI, j0eqDD, /* 2 */ + j0neBB, j0neBI, j0neBD, j0neIB, j0neII, j0neID, j0neDB, j0neDI, j0neDD, + j0ltBB, j0ltBI, j0ltBD, j0ltIB, j0ltII, j0ltID, j0ltDB, j0ltDI, j0ltDD, + j0leBB, j0leBI, j0leBD, j0leIB, j0leII, j0leID, j0leDB, j0leDI, j0leDD, + j0geBB, j0geBI, j0geBD, j0geIB, j0geII, j0geID, j0geDB, j0geDI, j0geDD, + j0gtBB, j0gtBI, j0gtBD, j0gtIB, j0gtII, j0gtID, j0gtDB, j0gtDI, j0gtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + j1eqBB, j1eqBI, j1eqBD, j1eqIB, j1eqII, j1eqID, j1eqDB, j1eqDI, j1eqDD, /* 3 */ + j1neBB, j1neBI, j1neBD, j1neIB, j1neII, j1neID, j1neDB, j1neDI, j1neDD, + j1ltBB, j1ltBI, j1ltBD, j1ltIB, j1ltII, j1ltID, j1ltDB, j1ltDI, j1ltDD, + j1leBB, j1leBI, j1leBD, j1leIB, j1leII, j1leID, j1leDB, j1leDI, j1leDD, + j1geBB, j1geBI, j1geBD, j1geIB, j1geII, j1geID, j1geDB, j1geDI, j1geDD, + j1gtBB, j1gtBI, j1gtBD, j1gtIB, j1gtII, j1gtID, j1gtDB, j1gtDI, j1gtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + sumeqBB,sumeqBI,sumeqBD, sumeqIB,sumeqII,sumeqID, sumeqDB,sumeqDI,sumeqDD, /* 4 */ + sumneBB,sumneBI,sumneBD, sumneIB,sumneII,sumneID, sumneDB,sumneDI,sumneDD, + sumltBB,sumltBI,sumltBD, sumltIB,sumltII,sumltID, sumltDB,sumltDI,sumltDD, + sumleBB,sumleBI,sumleBD, sumleIB,sumleII,sumleID, sumleDB,sumleDI,sumleDD, + sumgeBB,sumgeBI,sumgeBD, sumgeIB,sumgeII,sumgeID, sumgeDB,sumgeDI,sumgeDD, + sumgtBB,sumgtBI,sumgtBD, sumgtIB,sumgtII,sumgtID, sumgtDB,sumgtDI,sumgtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + anyeqBB,anyeqBI,anyeqBD, anyeqIB,anyeqII,anyeqID, anyeqDB,anyeqDI,anyeqDD, /* 5 */ + anyneBB,anyneBI,anyneBD, anyneIB,anyneII,anyneID, anyneDB,anyneDI,anyneDD, + anyltBB,anyltBI,anyltBD, anyltIB,anyltII,anyltID, anyltDB,anyltDI,anyltDD, + anyleBB,anyleBI,anyleBD, anyleIB,anyleII,anyleID, anyleDB,anyleDI,anyleDD, + anygeBB,anygeBI,anygeBD, anygeIB,anygeII,anygeID, anygeDB,anygeDI,anygeDD, + anygtBB,anygtBI,anygtBD, anygtIB,anygtII,anygtID, anygtDB,anygtDI,anygtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + alleqBB,alleqBI,alleqBD, alleqIB,alleqII,alleqID, alleqDB,alleqDI,alleqDD, /* 6 */ + allneBB,allneBI,allneBD, allneIB,allneII,allneID, allneDB,allneDI,allneDD, + allltBB,allltBI,allltBD, allltIB,allltII,allltID, allltDB,allltDI,allltDD, + allleBB,allleBI,allleBD, allleIB,allleII,allleID, allleDB,allleDI,allleDD, + allgeBB,allgeBI,allgeBD, allgeIB,allgeII,allgeID, allgeDB,allgeDI,allgeDD, + allgtBB,allgtBI,allgtBD, allgtIB,allgtII,allgtID, allgtDB,allgtDI,allgtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + + ifbeqBB,ifbeqBI,ifbeqBD, ifbeqIB,ifbeqII,ifbeqID, ifbeqDB,ifbeqDI,ifbeqDD, /* 7 */ + ifbneBB,ifbneBI,ifbneBD, ifbneIB,ifbneII,ifbneID, ifbneDB,ifbneDI,ifbneDD, + ifbltBB,ifbltBI,ifbltBD, ifbltIB,ifbltII,ifbltID, ifbltDB,ifbltDI,ifbltDD, + ifbleBB,ifbleBI,ifbleBD, ifbleIB,ifbleII,ifbleID, ifbleDB,ifbleDI,ifbleDD, + ifbgeBB,ifbgeBI,ifbgeBD, ifbgeIB,ifbgeII,ifbgeID, ifbgeDB,ifbgeDI,ifbgeDD, + ifbgtBB,ifbgtBI,ifbgtBD, ifbgtIB,ifbgtII,ifbgtID, ifbgtDB,ifbgtDI,ifbgtDD, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, + 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, +}; + +INDF( i0eqC,C,C,ANE) INDF( i0neC,C,C,AEQ) +INDF( i1eqC,C,C,AEQ) INDF( i1neC,C,C,ANE) +JNDF( j0eqC,C,C,ANE) JNDF( j0neC,C,C,AEQ) +JNDF( j1eqC,C,C,AEQ) JNDF( j1neC,C,C,ANE) +SUMF(sumeqC,C,C,AEQ) SUMF(sumneC,C,C,ANE) +ALLF(alleqC,C,C,AEQ) ALLF(allneC,C,C,ANE) +ANYF(anyeqC,C,C,AEQ) ANYF(anyneC,C,C,ANE) +IFBF(ifbeqC,C,C,AEQ) IFBF(ifbneC,C,C,ANE) + +static AF atcompC[]={ /* table for LIT vs. LIT */ + i0eqC, i0neC, 0L,0L,0L,0L,0L,0L, + i1eqC, i1neC, 0L,0L,0L,0L,0L,0L, + j0eqC, j0neC, 0L,0L,0L,0L,0L,0L, + j1eqC, j1neC, 0L,0L,0L,0L,0L,0L, + sumeqC, sumneC, 0L,0L,0L,0L,0L,0L, + anyeqC, anyneC, 0L,0L,0L,0L,0L,0L, + alleqC, allneC, 0L,0L,0L,0L,0L,0L, + ifbeqC, ifbneC, 0L,0L,0L,0L,0L,0L, +}; + +INDF( i0eqS,SB,SB,ANE) INDF( i0neS,SB,SB,AEQ) +INDF( i1eqS,SB,SB,AEQ) INDF( i1neS,SB,SB,ANE) +JNDF( j0eqS,SB,SB,ANE) JNDF( j0neS,SB,SB,AEQ) +JNDF( j1eqS,SB,SB,AEQ) JNDF( j1neS,SB,SB,ANE) +SUMF(sumeqS,SB,SB,AEQ) SUMF(sumneS,SB,SB,ANE) +ALLF(alleqS,SB,SB,AEQ) ALLF(allneS,SB,SB,ANE) +ANYF(anyeqS,SB,SB,AEQ) ANYF(anyneS,SB,SB,ANE) +IFBF(ifbeqS,SB,SB,AEQ) IFBF(ifbneS,SB,SB,ANE) + +INDF( i0ltS,SB,SB,SBGE) INDF( i0leS,SB,SB,SBGT) INDF( i0geS,SB,SB,SBLT) INDF( i0gtS,SB,SB,SBLE) +INDF( i1ltS,SB,SB,SBLT) INDF( i1leS,SB,SB,SBLE) INDF( i1geS,SB,SB,SBGE) INDF( i1gtS,SB,SB,SBGT) +JNDF( j0ltS,SB,SB,SBGE) JNDF( j0leS,SB,SB,SBGT) JNDF( j0geS,SB,SB,SBLT) JNDF( j0gtS,SB,SB,SBLE) +JNDF( j1ltS,SB,SB,SBLT) JNDF( j1leS,SB,SB,SBLE) JNDF( j1geS,SB,SB,SBGE) JNDF( j1gtS,SB,SB,SBGT) +SUMF(sumltS,SB,SB,SBLT) SUMF(sumleS,SB,SB,SBLE) SUMF(sumgeS,SB,SB,SBGE) SUMF(sumgtS,SB,SB,SBGT) +ALLF(allltS,SB,SB,SBLT) ALLF(allleS,SB,SB,SBLE) ALLF(allgeS,SB,SB,SBGE) ALLF(allgtS,SB,SB,SBGT) +ANYF(anyltS,SB,SB,SBLT) ANYF(anyleS,SB,SB,SBLE) ANYF(anygeS,SB,SB,SBGE) ANYF(anygtS,SB,SB,SBGT) +IFBF(ifbltS,SB,SB,SBLT) IFBF(ifbleS,SB,SB,SBLE) IFBF(ifbgeS,SB,SB,SBGE) IFBF(ifbgtS,SB,SB,SBGT) + + +static AF atcompSB[]={ /* table for SBT vs. SBT */ + i0eqS, i0neS, i0ltS, i0leS, i0geS, i0gtS, 0L,0L, + i1eqS, i1neS, i1ltS, i1leS, i1geS, i1gtS, 0L,0L, + j0eqS, j0neS, j0ltS, j0leS, j0geS, j0gtS, 0L,0L, + j1eqS, j1neS, j1ltS, j1leS, j1geS, j1gtS, 0L,0L, + sumeqS,sumneS,sumltS,sumleS,sumgeS,sumgtS, 0L,0L, + anyeqS,anyneS,anyltS,anyleS,anygeS,anygtS, 0L,0L, + alleqS,allneS,allltS,allleS,allgeS,allgtS, 0L,0L, + ifbeqS,ifbneS,ifbltS,ifbleS,ifbgeS,ifbgtS, 0L,0L, +}; + + +static F2( jti0eps){R indexofsub( II0EPS,w,a);} +static F2( jti1eps){R indexofsub( II1EPS,w,a);} +static F2( jtj0eps){R indexofsub( IJ0EPS,w,a);} +static F2( jtj1eps){R indexofsub( IJ1EPS,w,a);} +static F2(jtsumeps){R indexofsub(ISUMEPS,w,a);} +static F2(jtanyeps){R indexofsub(IANYEPS,w,a);} +static F2(jtalleps){R indexofsub(IALLEPS,w,a);} +static F2(jtifbeps){R indexofsub(IIFBEPS,w,a);} + +static AF atcompX[]={ /* table for any vs. any */ + 0L,0L,0L,0L,0L,0L, 0L, jti0eps, + 0L,0L,0L,0L,0L,0L, jti1ebar, jti1eps, + 0L,0L,0L,0L,0L,0L, 0L, jtj0eps, + 0L,0L,0L,0L,0L,0L, 0L, jtj1eps, + 0L,0L,0L,0L,0L,0L, jtsumebar, jtsumeps, + 0L,0L,0L,0L,0L,0L, jtanyebar, jtanyeps, + 0L,0L,0L,0L,0L,0L, 0L, jtalleps, + 0L,0L,0L,0L,0L,0L, jtifbebar, jtifbeps, +}; + + +/* f 0 1 2 3 4 5 6 7 */ +/* m = ~: < <: >: > E. e. */ +/* 0 f i. 0: 0 1 2 3 4 5 6 7 */ +/* 1 f i. 1: 8 9 10 11 12 13 14 15 */ +/* 2 f i: 0: 16 17 18 19 20 21 22 23 */ +/* 3 f i: 1: 24 25 26 27 28 29 30 31 */ +/* 4 [: + / f 32 33 34 35 36 37 38 39 */ +/* 5 [: +./ f 40 41 42 43 44 45 46 47 */ +/* 6 [: *./ f 48 49 50 51 52 53 54 55 */ +/* 7 [: I. f 56 57 58 59 60 61 62 63 */ + +AF jtatcompf(J jt,A a,A w,A self){AF f;I ar,at,m,wr,wt; + RZ(a&&w); + at=AT(a); ar=AR(a); + wt=AT(w); wr=AR(w); + m=VAV(self)->flag%256; + if(1<ar||1<wr){if(32<=m&&m<=37||40<=m&&m<=45||48<=m&&m<=53)R(AF)jtfslashatg; RZ(7==m%8);} + ASSERT(AN(a)==AN(w)||!ar||!wr||5<m%8,EVLENGTH); + f=atcompX[m]; + if(!f){ + if(at&B01+INT+FL&&wt&B01+INT+FL)f=atcompxy[9*m+3*(at&B01?0:at&INT?1:2)+(wt&B01?0:wt&INT?1:2)]; + else if(at&LIT&&wt&LIT) f=atcompC[m]; + else if(at&SBT&&wt&SBT) f=atcompSB[m]; + } + R f; +} /* function table look-up for comp i. 1: and i.&1@:comp etc. */ +
new file mode 100644 --- /dev/null +++ b/vd.c @@ -0,0 +1,132 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Domino */ + +#include "j.h" + + +static F1(jtnorm){R sqroot(pdt(w,conjug(w)));} + +F1(jtrinv){PROLOG;A ai,bx,di,z;I m,n,r,*s; + F1RANK(2,jtrinv,0); + r=AR(w); s=AS(w); n=2>r?1:s[1]; m=(1+n)/2; + ASSERT(!r||n==s[0],EVLENGTH); + if(1>=n)R recip(w); + ai=rinv(take(v2(m,m),w)); + di=rinv(drop(v2(m,m),w)); + bx=negate(pdt(ai,pdt(take(v2(m,m-n),w),di))); + z=over(stitch(ai,bx),take(v2(n-m,-n),di)); + EPILOG(z); +} /* R.K.W. Hui, Uses of { and }, APL87, p. 56 */ + +static F1(jtqrr){PROLOG;A a1,q,q0,q1,r,r0,r1,t,*tv,t0,t1,y,z;I m,n,p,*s; + RZ(w); + if(2>AR(w)){p=AN(w); n=m=1;}else{s=AS(w); p=s[0]; n=s[1]; m=(1+n)/2;} + if(1>=n){ + t=norm(ravel(w)); + ASSERT(!AN(w)||!equ(t,zero),EVDOMAIN); + RZ(q=divide(w,t)); + R link(2>AR(q)?table(q):q,reshape(v2(n,n),p?t:one)); + } + RZ(t0=qrr(take(v2(p,m),w))); + tv=AAV(t0); q0=*tv++; r0=*tv; + RZ(a1=drop(v2(0L,m),w)); + RZ(y=pdt(conjug(cant1(q0)),a1)); + RZ(t1=qrr(minus(a1,pdt(q0,y)))); + tv=AAV(t1); q1=*tv++; r1=*tv; + RZ(q=stitch(q0,q1)); + RZ(r=over(stitch(r0,y),take(v2(n-m,-n),r1))); + z=link(q,r); EPILOG(z); +} + +F1(jtqr){A r,z;D c=inf,d=0,x;I n1,n,*s,wr; + F1RANK(2,jtqr,0); + ASSERT(DENSE&AT(w),EVNONCE); + ASSERT(AT(w)&B01+INT+FL+CMPX,EVDOMAIN); + wr=AR(w); s=AS(w); + ASSERT(2>wr||s[0]>=s[1],EVLENGTH); + RZ(z=qrr(w)); r=*(1+AAV(z)); n=*AS(r); n1=1+n; + if(FL&AT(r)){D*v=DAV(r); DO(n, x= ABS(*v); if(x<c)c=x; if(x>d)d=x; v+=n1;);} + else {Z*v=ZAV(r); DO(n, x=zmag(*v); if(x<c)c=x; if(x>d)d=x; v+=n1;);} + ASSERT(!n||c>d*jt->fuzz,EVDOMAIN); + R z; +} + +static F2(jticor){D d,*v;I n; + RZ(a&&w); + d=1; n=1+*AS(a); + v=DAV(a); DO(n-1, d*=*v; v+=n;); d=jfloor(0.5+ABS(d)); + if(!d||d>1e20)R w; + v=DAV(w); DO(AN(w), v[i]=jfloor(0.5+d*v[i])/d;); + R w; +} + +F1(jtminv){PROLOG;A q,r,*v,y,z;I m,n,*s,t,wr; + F1RANK(2,jtminv,0); + t=AT(w); wr=AR(w); s=AS(w); m=wr?s[0]:1; n=1<wr?s[1]:1; + if(!wr)R recip(w); + if(!AN(w)){ASSERT(1==wr||m>=n,EVLENGTH); R cant1(w);} + if(AN(w)&&t&RAT+XNUM){ + ASSERT(m>=n,EVLENGTH); + if(t&XNUM)RZ(w=cvt(RAT,w)); + if(1<wr&&m==n)y=w; else{q=cant1(w); y=pdt(q,w);} + z=drop(v2(0L,n),gausselm(stitch(y,reshape(v2(n,n),take(sc(1+n),xco1(scf(1.0))))))); + if(2>wr)z=tymes(reshape(mtv,z),w); else if(m>n)z=pdt(z,q); + }else{ + RZ(y=qr(w)); v=AAV(y); q=*v++; r=*v; + z=pdt(rinv(r),t&CMPX?conjug(cant1(q)):cant1(q)); + if(t&B01+INT&&2==wr&&m==n)z=icor(r,z); + z=2==wr?z:reshape(shape(w),z); + } + EPILOG(z); +} + +static B jttridiag(J jt,I n,A a,A x){D*av,d,p,*xv;I i,j,n1=n-1; + av=DAV(a); xv=DAV(x); d=xv[0]; + for(i=j=0;i<n1;++i){ + ASSERT(d,EVDOMAIN); + p=xv[j+2]/d; + d=xv[j+3]-=p*xv[j+1]; + av[i+1]-=p*av[i]; + j+=3; + } + ASSERT(d,EVDOMAIN); + i=n-1; j=AN(x)-1; av[i]/=d; + for(i=n-2;i>=0;--i){j-=3; av[i]=(av[i]-xv[j+1]*av[i+1])/xv[j];} + R 1; +} + +static F2(jtmdivsp){A a1,x,y;I at,d,m,n,t,*v,xt;P*wp; + ASSERT(2==AR(w),EVRANK); + v=AS(w); n=v[0]; + ASSERT(n>=v[1]&&n==AN(a),EVLENGTH); + ASSERT(n==v[1],EVNONCE); + wp=PAV(w); x=SPA(wp,x); y=SPA(wp,i); a1=SPA(wp,a); + ASSERT(2==AN(a1),EVNONCE); + v=AV(y); m=*AS(y); + ASSERT(m==3*n-2,EVNONCE); + DO(m, d=*v++; d-=*v++; ASSERT(-1<=d&&d<=1,EVNONCE);); + at=AT(a); xt=AT(x); RE(t=maxtype(at,xt)); RE(t=maxtype(t,FL)); + RZ(a=cvt(t,a)); RZ(x=cvt(t,x)); + if(t&CMPX)RZ(ztridiag(n,a,x)) else RZ(tridiag(n,a,x)); + R a; +} /* currently only handles tridiagonal sparse w */ + + +F2(jtmdiv){PROLOG;A q,r,*v,y,z;B b=0;I t; + F2RANK(RMAX,2,jtmdiv,0); + if(AT(a)&SPARSE)RZ(a=denseit(a)); + t=AT(w); + if(t&SPARSE)R mdivsp(a,w); + if(t&XNUM+RAT)z=minv(w); + else{ + RZ(y=qr(w)); v=AAV(y); q=*v++; r=*v; + z=pdt(rinv(r),t&CMPX?conjug(cant1(q)):cant1(q)); + b=t&B01+INT&&2==AR(w)&&*AS(w)==*(1+AS(w)); + if(b)z=icor(r,z); + } + z=pdt(2>AR(w)?reshape(shape(w),z):z,a); + if(b&&AT(a)&B01+INT)z=icor(r,z); + EPILOG(z); +}
new file mode 100644 --- /dev/null +++ b/vdx.c @@ -0,0 +1,15 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Extended Precision Floating Point */ + +#include "j.h" +#include "ve.h" + + +DXF2(jtdxplus){DX z=zeroDX; + R z; +} + + +APFX(plusDX, DX,DX,DX, dxplus )
new file mode 100644 --- /dev/null +++ b/vdx.h @@ -0,0 +1,12 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Extended Precision Floating Point */ + + +#define DXF1(f) DX f(J jt, DX w) +#define DXF2(f) DX f(J jt,DX a,DX w) + +extern DX zeroDX; + +extern DXF2(jtdxplus);
new file mode 100644 --- /dev/null +++ b/ve.c @@ -0,0 +1,247 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Elementary Functions (Arithmetic, etc.) */ + +#include "j.h" +#include "vasm.h" + +#define DIVI(u,v) (u||v ? u/(D)v : 0.0) +#define DIVBB(u,v) (v?u:u?inf:0.0) + +#define TYMESBX(u,v) (u?v:0) +#define TYMESXB(u,v) (v?u:0) +#define TYMESID(u,v) (u ?u*v:0) +#define TYMESDI(u,v) ( v?u*v:0) +#define TYMESDD(u,v) (u&&v?u*v:0) + +AOVF( plusII, I,I,I, PLUSVV, PLUS1V, PLUSV1) +AOVF(minusII, I,I,I, MINUSVV,MINUS1V,MINUSV1) +AOVF(tymesII, I,I,I, TYMESVV,TYMES1V,TYMESV1) + +APFX( plusIO, D,I,I, PLUSO) +APFX(minusIO, D,I,I, MINUSO) +APFX(tymesIO, D,I,I, TYMESO) + +AIFX( plusBB, I,B,B, + ) /* plusII */ AIFX( plusBD, D,B,D, + ) + /* plusII */ /* plusII */ AIFX( plusID, D,I,D, + ) +AIFX( plusDB, D,D,B, + ) AIFX( plusDI, D,D,I, +) ANAN( plusDD, D,D,D, PLUS) +ANAN( plusZZ, Z,Z,Z, zplus ) + +AIFX(minusBB, I,B,B, - ) /* minusII */ AIFX(minusBD, D,B,D, - ) + /* minusII */ /* minusII */ AIFX(minusID, D,I,D, - ) +AIFX(minusDB, D,D,B, - ) AIFX(minusDI, D,D,I, -) ANAN(minusDD, D,D,D, MINUS) +ANAN(minusZZ, Z,Z,Z, zminus) + + /* andBB */ APFX(tymesBI, I,B,I, TYMESBX) APFX(tymesBD, D,B,D, TYMESBX) +APFX(tymesIB, I,I,B, TYMESXB) /* tymesII */ APFX(tymesID, D,I,D, TYMESID) +APFX(tymesDB, D,D,B, TYMESXB) APFX(tymesDI, D,D,I, TYMESDI) APFX(tymesDD, D,D,D, TYMESDD) +ANAN(tymesZZ, Z,Z,Z, ztymes ) + +APFX( divBB, D,B,B, DIVBB) APFX( divBI, D,B,I, DIVI) APFX( divBD, D,B,D, DIV) +APFX( divIB, D,I,B, DIVI ) APFX( divII, D,I,I, DIVI) APFX( divID, D,I,D, DIV) +APFX( divDB, D,D,B, DIVI ) APFX( divDI, D,D,I, DIVI) ANAN( divDD, D,D,D, DIV) +ANAN( divZZ, Z,Z,Z, zdiv ) + + /* orBB */ APFX( minBI, I,B,I, MIN) APFX( minBD, D,B,D, MIN) +APFX( minIB, I,I,B, MIN) APFX( minII, I,I,I, MIN) APFX( minID, D,I,D, MIN) +APFX( minDB, D,D,B, MIN) APFX( minDI, D,D,I, MIN) APFX( minDD, D,D,D, MIN) +APFX( minSS, SB,SB,SB, SBMIN) + + /* andBB */ APFX( maxBI, I,B,I, MAX) APFX( maxBD, D,B,D, MAX) +APFX( maxIB, I,I,B, MAX) APFX( maxII, I,I,I, MAX) APFX( maxID, D,I,D, MAX) +APFX( maxDB, D,D,B, MAX) APFX( maxDI, D,D,I, MAX) APFX( maxDD, D,D,D, MAX) +APFX( maxSS, SB,SB,SB, SBMAX) + + +static D jtremdd(J jt,D a,D b){D q,x,y; + if(!a)R b; + ASSERT(!INF(b),EVNAN); + if(a==inf )R 0<=b?b:a; + if(a==infm)R 0>=b?b:a; + q=b/a; x=tfloor(q); y=tceil(q); R teq(x,y)?0:b-a*x; +} + +ANAN(remDD, D,D,D, remdd) +ANAN(remZZ, Z,Z,Z, zrem ) + +static I jtremid(J jt,I a,D b){D r;I k; + ASSERT(a&&-9e15<b&&b<9e15,EWOV); + r=b-a*floor(b/a); k=(I)r; + ASSERT(k==r,EWOV); + R k; +} + +APFX(remID, I,I,D, remid) + +static I remii(I a,I b){I r; R!a?b:(r=b%a,0<a?r+a*(0>r):r+a*(0<r));} + +AHDR2(remII,I,I,I){I u,v; + if(1==n) DO(m, *z++=remii(*x,*y); x++; y++; ) + else if(b)DO(m, u=*x++; if(0<=u&&!(u&(u-1))){--u; DO(n, *z++=u&*y++;);} + else DO(n, *z++=remii( u,*y); y++;)) + else DO(m, v=*y++; DO(n, *z++=remii(*x, v); x++; )); +} + + +static I igcd1(I a,I b){R a?igcd1(b%a,a):b;} + +static I jtigcd(J jt,I a,I b){ + if(a>IMIN&&b>IMIN){a=ABS(a); b=ABS(b);} + else{ + if(a==b||!a||!b){jt->jerr=EWOV; R 0;} + if(a==IMIN){b=ABS(b); a=-(a+b);}else{a=ABS(a); b=-(a+b);} + } + R a?igcd1(b%a,a):b; +} + +D jtdgcd(J jt,D a,D b){D a1,b1,t; + a=ABS(a); b=ABS(b); if(a>b){t=a; a=b; b=t;} + ASSERT(inf!=b,EVNAN); + if(!a)R b; + a1=a; b1=b; + while(remdd(a1/jfloor(0.5+a1/a),b1)){t=a; a=remdd(a,b); b=t;} + R a; +} /* D.L. Forkes 1984; E.E. McDonnell 1992 */ +#if SY_64 +#if SY_WIN32 +static I jtilcm(J jt,I a,I b){C er=0;I b1,d,z; + if(a&&b){RZ(d=igcd(a,b)); b1=b/d; TYMESVV(1L,&z,&a,&b1); if(er)jt->jerr=EWOV; R z;}else R 0; +} +#else +static I jtilcm(J jt,I a,I b){LD z;I b1,d; + if(a&&b){RZ(d=igcd(a,b)); b1=b/d; z=a*(LD)b1; if(z<IMIN||IMAX<z)jt->jerr=EWOV; R (I)z;}else R 0; +} +#endif +#else +static I jtilcm(J jt,I a,I b){D z;I b1,d; + if(a&&b){RZ(d=igcd(a,b)); b1=b/d; z=a*(D)b1; if(z<IMIN||IMAX<z)jt->jerr=EWOV; R (I)z;}else R 0; +} +#endif + +#define GCDIO(u,v) (dgcd((D)u,(D)v)) +#define LCMIO(u,v) (dlcm((D)u,(D)v)) + +static D jtdlcm(J jt,D a,D b){ASSERT(!(INF(a)||INF(b)),EVNAN); R a&&b?a*(b/dgcd(a,b)):0;} + +APFX(gcdIO, D,I,I, GCDIO) +APFX(gcdII, I,I,I, igcd ) +APFX(gcdDD, D,D,D, dgcd ) +APFX(gcdZZ, Z,Z,Z, zgcd ) + +APFX(lcmII, I,I,I, ilcm ) +APFX(lcmIO, D,I,I, LCMIO) +APFX(lcmDD, D,D,D, dlcm ) +APFX(lcmZZ, Z,Z,Z, zlcm ) + + +#define GETD {d=*wv++; if(!d){z=0; break;}} +#define INTDIVF(c,d) (0>c==0>d?c/d:c%d?c/d-1:c/d) +#define INTDIVC(c,d) (0>c!=0>d?c/d:c%d?c/d+1:c/d) + +F2(jtintdiv){A z;B b,flr;I an,ar,*as,*av,c,d,j,k,m,n,p,p1,r,*s,wn,wr,*ws,*wv,*zv; + RZ(a&&w); + an=AN(a); ar=AR(a); as=AS(a); av=AV(a); + wn=AN(w); wr=AR(w); ws=AS(w); wv=AV(w); b=ar>=wr; r=b?wr:ar; s=b?as:ws; + ASSERT(!ICMP(as,ws,r),EVLENGTH); + if(an&&wn){m=prod(r,s); n=prod(b?ar-r:wr-r,r+s);}else m=n=0; + GA(z,INT,b?an:wn,b?ar:wr,s); zv=AV(z); + d=wn?*wv:0; p=0<d?d:-d; p1=d==IMIN?p:p-1; flr=XMFLR==jt->xmode; + if(!wr&&p&&!(p&p1)){ + k=0; j=1; while(p>j){++k; j<<=1;} + switch((0<d?0:2)+(flr?0:1)){ + case 0: DO(n, *zv++=*av++>>k;); break; + case 1: DO(n, c=*av++; *zv++=0< c?1+((c-1)>>k):(c+p1)>>k;); break; + case 2: DO(n, c=*av++; *zv++=c>IMIN?-c>>k:-(-c>>k);); break; + case 3: DO(n, c=*av++; *zv++=0<=c?-(c>>k):1+(-(1+c)>>k);); + }}else if(flr){ + if(1==n) DO(m, c=*av++; GETD; *zv++=INTDIVF(c,d); ) + else if(b)DO(m, GETD; DO(n, c=*av++; *zv++=INTDIVF(c,d););) + else DO(m, c=*av++; DO(n, GETD; *zv++=INTDIVF(c,d););) + }else{ + if(1==n) DO(m, c=*av++; GETD; *zv++=INTDIVC(c,d); ) + else if(b)DO(m, GETD; DO(n, c=*av++; *zv++=INTDIVC(c,d););) + else DO(m, c=*av++; DO(n, GETD; *zv++=INTDIVC(c,d););) + } + R z?z:flr?floor1(divide(a,w)):ceil1(divide(a,w)); +} /* <.@% or >.@% on integers */ + + +static F2(jtweight){RZ(a&&w); R df1(behead(over(AR(w)?w:reshape(a,w),one)),bsdot(slash(ds(CSTAR))));} + +F1(jtbase1){A z;B*v;I c,d,m,n,p,r,*s,t,*x; + RZ(w); + n=AN(w); t=AT(w); r=AR(w); s=AS(w); c=r?*(s+r-1):1; + ASSERT(t&DENSE,EVNONCE); + if(c>(SY_64?63:31)||!(t&B01))R pdt(w,weight(sc(c),t&RAT+XNUM?cvt(XNUM,num[2]):num[2])); + if(c)m=n/c; else RE(m=prod(r-1,s)); + GA(z,INT,m,r?r-1:0,s); x=m+AV(z); v=n+BAV(w); + if(c)DO(m, p=0; d=1; DO(c, if(*--v)p+=d; d+=d;); *--x=p;) + else memset(x-m,C0,m*SZI); + R z; +} + +F2(jtbase2){I ar,*as,at,c,t,wr,*ws,wt; + RZ(a&&w); + at=AT(a); ar=AR(a); as=AS(a); + wt=AT(w); wr=AR(w); ws=AS(w); c=wr?*(ws+wr-1):1; t=maxtype(at,wt); + ASSERT(at&DENSE&&wt&DENSE,EVNONCE); + if(!(t&at))RZ(a=cvt(t,a)); + if(!(t&wt))RZ(w=cvt(t,w)); + R 1>=ar?pdt(w,weight(sc(c),a)):rank2ex(w,rank2ex(sc(c),a,0L,0L,1L,jtweight),0L,1L,1L,jtpdt); +} + +F1(jtabase1){A d,z;B*zv;I c,n,p,r,t,*v,x; + RZ(w); + n=AN(w); r=AR(w); t=AT(w); + ASSERT(t&DENSE,EVNONCE); + if(!n||t&B01)R reshape(over(shape(w),n?one:zero),w); + if(!(t&INT)){ + d=df2(num[2],maximum(one,aslash(CMAX,mag(ravel(w)))),atop(ds(CFLOOR),ds(CLOG))); + RZ(z=abase2(reshape(increm(d),num[2]),w)); + R t&FL&&equ(irs1(z,0L,1L,jthead),lt(w,zero))?irs1(z,0L,1L,jtbehead):z; + } + c=x=0; v=AV(w); + DO(n, p=*v++; if(p==IMIN){c=SY_64?64:32; break;} x=x<p?p:x<-p?-p:x;); + if(!c)while(x){x>>=1; ++c;} + c=MAX(1,c); + GA(z,B01,n*c,1+r,AS(w)); *(r+AS(z))=c; + v=n+AV(w); zv=AN(z)+BAV(z); + DO(n, x=*--v; DO(c, *--zv=(B)(x&1); x>>=1;)); + R z; +} + +F2(jtabase2){A z;I an,ar,at,wn,wr,wt,zn; + RZ(a&&w); + an=AN(a); ar=AR(a); at=AT(a); + wn=AN(w); wr=AR(w); wt=AT(w); + ASSERT(at&DENSE&&wt&DENSE,EVNONCE); + if(!ar)R residue(a,w); + if(1==ar&&at&B01+INT&&wt&B01+INT){I*av,d,r,*u,*wv,x,*zv; + RZ(coerce2(&a,&w,INT)); + RE(zn=mult(an,wn)); GA(z,INT,zn,1+wr,AS(w)); *(wr+AS(z))=an; + av=an+AV(a); wv=wn+AV(w); zv=zn+AV(z); + if(2==an&&!av[-2]&&0<(d=av[-1])){I d1,j,k; + k=0; j=1; while(d>j){++k; j<<=1;} d1=d-1; + if(d==j)DO(wn, x=*--wv; *--zv=x&d1; *--zv=x>>k;) + else DO(wn, x=*--wv; if(0<=x){*--zv=x%d; *--zv=x/d;}else{*--zv=d+x%d; *--zv=-1+x/d;}) + }else DO(wn, x=*--wv; u=av; DO(an, d=*--u; *--zv=r=remii(d,x); x=d?(x-r)/d:0;);); + R z; + }else{PROLOG;A y,*zv;C*u,*yv;I k; + F2RANK(1,0,jtabase2,0); + k=bp(at); u=an*k+CAV(a); + GA(y,at, 1, 0,0); yv=CAV(y); + GA(z,BOX,an,1,0); zv=an+AAV(z); + DO(an, MC(yv,u-=k,k); RZ(w=divide(minus(w,*--zv=residue(y,w)),y));); + EPILOG(ope(z)); +}} + +F1(jtintmod2){A z;B*b,*v;I k=SZI,mask,m,n,q,r,*u,*wi; + RZ(w); + n=AN(w); q=n/k; r=n%k; v=BAV(w)+!liln*(k-1); + GA(z,B01,n,AR(w),AS(w)); u=AV(z); + b=(B*)&mask; DO(k, b[i]=1;); + b=(B*)&m; DO(q, DO(k, b[i]=*v; v+=k;); *u++=mask&m;) + b=(B*)u; wi=AV(w)+q*k; DO(r, *b++=1&*wi++?1:0;); + R z; +}
new file mode 100644 --- /dev/null +++ b/ve.h @@ -0,0 +1,302 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Atomic Verbs */ + + +#define ADECL1 AHDR1 +#define ADECL2 AHDR2 +#define ADECLP AHDRP +#define ADECLR AHDRR +#define ADECLS AHDRS + +extern ADECL1( absQ,Q,Q); +extern ADECL1( absX,X,X); +extern ADECL1( ceilQ,X,Q); +extern ADECL1( expX,X,X); +extern ADECL1( factD,D,D); +extern ADECL1( factI,I,I); +extern ADECL1( factQ,X,Q); +extern ADECL1( factX,X,X); +extern ADECL1( factZ,Z,Z); +extern ADECL1(floorQ,X,Q); +extern ADECL1( logX,X,X); +extern ADECL1( logQD,D,Q); +extern ADECL1( logQZ,Z,Q); +extern ADECL1( logXD,D,X); +extern ADECL1( logXZ,Z,X); +extern ADECL1( pixX,X,X); +extern ADECL1( sgnQ,X,Q); +extern ADECL1( sgnX,X,X); +extern ADECL1( sqrtQ,Q,Q); +extern ADECL1( sqrtX,X,X); + +extern ADECLP( andpfxB,B, B ); extern ADECLR( andinsB,B, B ); extern ADECLS( andsfxB,B, B ); +extern ADECLP( divpfxD,D, D ); extern ADECLR( divinsD,D, D ); extern ADECLS( divsfxD,D, D ); +extern ADECLP( divpfxZ,Z, Z ); extern ADECLR( divinsZ,Z, Z ); extern ADECLS( divsfxZ,Z, Z ); +extern ADECLP( eqpfxB,B, B ); extern ADECLR( eqinsB,B, B ); extern ADECLS( eqsfxB,B, B ); +extern ADECLP( gepfxB,B, B ); extern ADECLR( geinsB,B, B ); extern ADECLS( gesfxB,B, B ); +extern ADECLP( gtpfxB,B, B ); extern ADECLR( gtinsB,B, B ); extern ADECLS( gtsfxB,B, B ); +extern ADECLP( lepfxB,B, B ); extern ADECLR( leinsB,B, B ); extern ADECLS( lesfxB,B, B ); +extern ADECLP( ltpfxB,B, B ); extern ADECLR( ltinsB,B, B ); extern ADECLS( ltsfxB,B, B ); +extern ADECLP( maxpfxD,D, D ); extern ADECLR( maxinsD,D, D ); extern ADECLS( maxsfxD,D, D ); +extern ADECLP( maxpfxI,I, I ); extern ADECLR( maxinsI,I, I ); extern ADECLS( maxsfxI,I, I ); +extern ADECLP( maxpfxQ,Q, Q ); extern ADECLS( maxsfxQ,Q, Q ); +extern ADECLP( maxpfxS,SB,SB); extern ADECLR( maxinsS,SB,SB); extern ADECLS( maxsfxS,SB,SB); +extern ADECLP( maxpfxX,X, X ); extern ADECLR( maxinsX,X, X ); extern ADECLS( maxsfxX,X, X ); +extern ADECLP( minpfxD,D, D ); extern ADECLR( mininsD,D, D ); extern ADECLS( minsfxD,D, D ); +extern ADECLP( minpfxI,I, I ); extern ADECLR( mininsI,I, I ); extern ADECLS( minsfxI,I, I ); +extern ADECLP( minpfxQ,Q, Q ); extern ADECLS( minsfxQ,Q, Q ); +extern ADECLP( minpfxS,SB,SB); extern ADECLR( mininsS,SB,SB); extern ADECLS( minsfxS,SB,SB); +extern ADECLP( minpfxX,X, X ); extern ADECLR( mininsX,X, X ); extern ADECLS( minsfxX,X, X ); +extern ADECLP( minuspfxB,I, B ); extern ADECLR( minusinsB,I, B ); extern ADECLS( minussfxB,I, B ); +extern ADECLP( minuspfxD,D, D ); extern ADECLR( minusinsD,D, D ); extern ADECLS( minussfxD,D, D ); +extern ADECLP( minuspfxI,I, I ); extern ADECLR( minusinsI,I, I ); extern ADECLS( minussfxI,I, I ); +extern ADECLP( minuspfxQ,Q, Q ); +extern ADECLP( minuspfxO,D, I ); extern ADECLR( minusinsO,D, I ); extern ADECLS( minussfxO,D, I ); +extern ADECLP( minuspfxX,X, X ); +extern ADECLP( minuspfxZ,Z, Z ); extern ADECLR( minusinsZ,Z, Z ); extern ADECLS( minussfxZ,Z, Z ); +extern ADECLP( nandpfxB,B, B ); extern ADECLR( nandinsB,B, B ); extern ADECLS( nandsfxB,B, B ); +extern ADECLP( nepfxB,B, B ); extern ADECLR( neinsB,B, B ); extern ADECLS( nesfxB,B, B ); +extern ADECLP( orpfxB,B, B ); extern ADECLR( norinsB,B, B ); extern ADECLS( norsfxB,B, B ); +extern ADECLP( norpfxB,B, B ); extern ADECLR( orinsB,B, B ); extern ADECLS( orsfxB,B, B ); +extern ADECLP( pluspfxB,I, B ); extern ADECLR( plusinsB,I, B ); extern ADECLS( plussfxB,I, B ); +extern ADECLP( pluspfxD,D, D ); extern ADECLR( plusinsD,D, D ); extern ADECLS( plussfxD,D, D ); +extern ADECLP( pluspfxI,I, I ); extern ADECLR( plusinsI,I, I ); extern ADECLS( plussfxI,I, I ); +extern ADECLP( pluspfxO,D, I ); extern ADECLR( plusinsO,D, I ); extern ADECLS( plussfxO,D, I ); +extern ADECLP( pluspfxQ,Q, Q ); extern ADECLS( plussfxQ,Q, Q ); +extern ADECLP( pluspfxX,X, X ); extern ADECLS( plussfxX,X, X ); +extern ADECLP( pluspfxZ,Z, Z ); extern ADECLR( plusinsZ,Z, Z ); extern ADECLS( plussfxZ,Z, Z ); +extern ADECLP( tymespfxD,D, D ); extern ADECLR( tymesinsD,D, D ); extern ADECLS( tymessfxD,D, D ); +extern ADECLP( tymespfxI,I, I ); extern ADECLR( tymesinsI,I, I ); extern ADECLS( tymessfxI,I, I ); +extern ADECLP( tymespfxO,D, I ); extern ADECLR( tymesinsO,D, I ); extern ADECLS( tymessfxO,D, I ); +extern ADECLP( tymespfxQ,Q, Q ); extern ADECLS( tymessfxQ,Q, Q ); +extern ADECLP( tymespfxX,X, X ); extern ADECLS( tymessfxX,X, X ); +extern ADECLP( tymespfxZ,Z, Z ); extern ADECLR( tymesinsZ,Z, Z ); extern ADECLS( tymessfxZ,Z, Z ); + +extern ADECLP(bw0000pfxI,UI,UI); extern ADECLR(bw0000insI,UI,UI); extern ADECLS(bw0000sfxI,UI,UI); +extern ADECLP(bw0001pfxI,UI,UI); extern ADECLR(bw0001insI,UI,UI); extern ADECLS(bw0001sfxI,UI,UI); + extern ADECLR(bw0010insI,UI,UI); extern ADECLS(bw0010sfxI,UI,UI); +extern ADECLP(bw0011pfxI,UI,UI); extern ADECLR(bw0011insI,UI,UI); extern ADECLS(bw0011sfxI,UI,UI); + extern ADECLR(bw0100insI,UI,UI); extern ADECLS(bw0100sfxI,UI,UI); +extern ADECLP(bw0101pfxI,UI,UI); extern ADECLR(bw0101insI,UI,UI); extern ADECLS(bw0101sfxI,UI,UI); +extern ADECLP(bw0110pfxI,UI,UI); extern ADECLR(bw0110insI,UI,UI); extern ADECLS(bw0110sfxI,UI,UI); +extern ADECLP(bw0111pfxI,UI,UI); extern ADECLR(bw0111insI,UI,UI); extern ADECLS(bw0111sfxI,UI,UI); + extern ADECLR(bw1000insI,UI,UI); extern ADECLS(bw1000sfxI,UI,UI); +extern ADECLP(bw1001pfxI,UI,UI); extern ADECLR(bw1001insI,UI,UI); extern ADECLS(bw1001sfxI,UI,UI); + extern ADECLR(bw1010insI,UI,UI); extern ADECLS(bw1010sfxI,UI,UI); + extern ADECLR(bw1011insI,UI,UI); extern ADECLS(bw1011sfxI,UI,UI); + extern ADECLR(bw1100insI,UI,UI); extern ADECLS(bw1100sfxI,UI,UI); + extern ADECLR(bw1101insI,UI,UI); extern ADECLS(bw1101sfxI,UI,UI); + extern ADECLR(bw1110insI,UI,UI); extern ADECLS(bw1110sfxI,UI,UI); +extern ADECLP(bw1111pfxI,UI,UI); extern ADECLR(bw1111insI,UI,UI); extern ADECLS(bw1111sfxI,UI,UI); + +extern ADECL2(bw0000II,UI,UI,UI); +extern ADECL2(bw0001II,UI,UI,UI); +extern ADECL2(bw0010II,UI,UI,UI); +extern ADECL2(bw0011II,UI,UI,UI); +extern ADECL2(bw0100II,UI,UI,UI); +extern ADECL2(bw0101II,UI,UI,UI); +extern ADECL2(bw0110II,UI,UI,UI); +extern ADECL2(bw0111II,UI,UI,UI); +extern ADECL2(bw1000II,UI,UI,UI); +extern ADECL2(bw1001II,UI,UI,UI); +extern ADECL2(bw1010II,UI,UI,UI); +extern ADECL2(bw1011II,UI,UI,UI); +extern ADECL2(bw1100II,UI,UI,UI); +extern ADECL2(bw1101II,UI,UI,UI); +extern ADECL2(bw1110II,UI,UI,UI); +extern ADECL2(bw1111II,UI,UI,UI); + +extern ADECL2( andBB,B,B,B); +extern ADECL2( binDD,D,D,D); +extern ADECL2( binQQ,X,Q,Q); +extern ADECL2( binXX,X,X,X); +extern ADECL2( binZZ,Z,Z,Z); +extern ADECL2( cirBD,D,B,D); +extern ADECL2( cirID,D,I,D); +extern ADECL2( cirDD,D,D,D); +extern ADECL2( cirZZ,Z,Z,Z); +extern ADECL2( divBB,D,B,B); +extern ADECL2( divBD,D,B,D); +extern ADECL2( divBI,D,B,I); +extern ADECL2( divDB,D,D,B); +extern ADECL2( divDD,D,D,D); +extern ADECL2( divDI,D,D,I); +extern ADECL2( divIB,D,I,B); +extern ADECL2( divID,D,I,D); +extern ADECL2( divII,D,I,I); +extern ADECL2( divQQ,Q,Q,Q); +extern ADECL2( divXX,X,X,X); +extern ADECL2( divZZ,Z,Z,Z); +extern ADECL2( eqAA,B,A,A); +extern ADECL2( eqBB,B,B,B); +extern ADECL2( eqBD,B,B,D); +extern ADECL2( eqBI,B,B,I); +extern ADECL2( eqCC,B,C,C); +extern ADECL2( eqCS,B,UC,US); +extern ADECL2( eqDB,B,D,B); +extern ADECL2( eqDD,B,D,D); +extern ADECL2( eqDI,B,D,I); +extern ADECL2( eqIB,B,I,B); +extern ADECL2( eqID,B,I,D); +extern ADECL2( eqII,B,I,I); +extern ADECL2( eqQQ,B,Q,Q); +extern ADECL2( eqSC,B,US,UC); +extern ADECL2( eqSS,B,S,S); +extern ADECL2( eqXX,B,X,X); +extern ADECL2( eqZZ,B,Z,Z); +extern ADECL2( gcdDD,D,D,D); +extern ADECL2( gcdII,I,I,I); +extern ADECL2( gcdIO,D,I,I); +extern ADECL2( gcdQQ,Q,Q,Q); +extern ADECL2( gcdXX,X,X,X); +extern ADECL2( gcdZZ,Z,Z,Z); +extern ADECL2( geBB,B,B,B); +extern ADECL2( geBD,B,B,D); +extern ADECL2( geBI,B,B,I); +extern ADECL2( geDB,B,D,B); +extern ADECL2( geDD,B,D,D); +extern ADECL2( geDI,B,D,I); +extern ADECL2( geIB,B,I,B); +extern ADECL2( geID,B,I,D); +extern ADECL2( geII,B,I,I); +extern ADECL2( geQQ,B,Q,Q); +extern ADECL2( geSS,B,SB,SB); +extern ADECL2( geXX,B,X,X); +extern ADECL2( gtBB,B,B,B); +extern ADECL2( gtBD,B,B,D); +extern ADECL2( gtBI,B,B,I); +extern ADECL2( gtDB,B,D,B); +extern ADECL2( gtDD,B,D,D); +extern ADECL2( gtDI,B,D,I); +extern ADECL2( gtIB,B,I,B); +extern ADECL2( gtID,B,I,D); +extern ADECL2( gtII,B,I,I); +extern ADECL2( gtSS,B,SB,SB); +extern ADECL2( gtQQ,B,Q,Q); +extern ADECL2( gtXX,B,X,X); +extern ADECL2( lcmDD,D,D,D); +extern ADECL2( lcmII,I,I,I); +extern ADECL2( lcmIO,D,I,I); +extern ADECL2( lcmQQ,Q,Q,Q); +extern ADECL2( lcmXX,X,X,X); +extern ADECL2( lcmZZ,Z,Z,Z); +extern ADECL2( leBB,B,B,B); +extern ADECL2( leBD,B,B,D); +extern ADECL2( leBI,B,B,I); +extern ADECL2( leDB,B,D,B); +extern ADECL2( leDD,B,D,D); +extern ADECL2( leDI,B,D,I); +extern ADECL2( leIB,B,I,B); +extern ADECL2( leID,B,I,D); +extern ADECL2( leII,B,I,I); +extern ADECL2( leQQ,B,Q,Q); +extern ADECL2( leSS,B,SB,SB); +extern ADECL2( leXX,B,X,X); +extern ADECL2( ltBB,B,B,B); +extern ADECL2( ltBD,B,B,D); +extern ADECL2( ltBI,B,B,I); +extern ADECL2( ltDB,B,D,B); +extern ADECL2( ltDD,B,D,D); +extern ADECL2( ltDI,B,D,I); +extern ADECL2( ltIB,B,I,B); +extern ADECL2( ltID,B,I,D); +extern ADECL2( ltII,B,I,I); +extern ADECL2( ltSS,B,SB,SB); +extern ADECL2( ltQQ,B,Q,Q); +extern ADECL2( ltXX,B,X,X); +extern ADECL2( maxBD,D,B,D); +extern ADECL2( maxBI,I,B,I); +extern ADECL2( maxDB,D,D,B); +extern ADECL2( maxDD,D,D,D); +extern ADECL2( maxDI,D,D,I); +extern ADECL2( maxIB,I,I,B); +extern ADECL2( maxID,I,I,D); +extern ADECL2( maxII,I,I,I); +extern ADECL2( maxQQ,Q,Q,Q); +extern ADECL2( maxSS,SB,SB,SB); +extern ADECL2( maxXX,X,X,X); +extern ADECL2( minBD,D,B,D); +extern ADECL2( minBI,I,B,I); +extern ADECL2( minDB,D,D,B); +extern ADECL2( minDD,D,D,D); +extern ADECL2( minDI,D,D,I); +extern ADECL2( minIB,I,I,B); +extern ADECL2( minID,D,I,D); +extern ADECL2( minII,I,I,I); +extern ADECL2( minQQ,Q,Q,Q); +extern ADECL2( minSS,SB,SB,SB); +extern ADECL2( minXX,X,X,X); +extern ADECL2(minusBB,I,B,B); +extern ADECL2(minusBD,D,B,D); +extern ADECL2(minusDB,D,D,B); +extern ADECL2(minusDD,D,D,D); +extern ADECL2(minusDI,D,D,I); +extern ADECL2(minusID,D,I,D); +extern ADECL2(minusII,I,I,I); +extern ADECL2(minusIO,D,I,I); +extern ADECL2(minusQQ,Q,Q,Q); +extern ADECL2(minusXX,X,X,X); +extern ADECL2(minusZZ,Z,Z,Z); +extern ADECL2( nandBB,B,B,B); +extern ADECL2( neAA,B,A,A); +extern ADECL2( neBB,B,B,B); +extern ADECL2( neBD,B,B,D); +extern ADECL2( neBI,B,B,I); +extern ADECL2( neCC,B,C,C); +extern ADECL2( neCS,B,UC,US); +extern ADECL2( neDB,B,D,B); +extern ADECL2( neDD,B,D,D); +extern ADECL2( neDI,B,D,I); +extern ADECL2( neIB,B,I,B); +extern ADECL2( neID,B,I,D); +extern ADECL2( neII,B,I,I); +extern ADECL2( neQQ,B,Q,Q); +extern ADECL2( neSC,B,US,UC); +extern ADECL2( neSS,B,S,S); +extern ADECL2( neXX,B,X,X); +extern ADECL2( neZZ,B,Z,Z); +extern ADECL2( norBB,B,B,B); +extern ADECL2( orBB,B,B,B); +extern ADECL2( plusBB,I,B,B); +extern ADECL2( plusBD,D,B,D); +extern ADECL2( plusDB,D,D,B); +extern ADECL2( plusDD,D,D,D); +extern ADECL2( plusDI,D,D,I); +extern ADECL2( plusDX,DX,DX,DX); +extern ADECL2( plusID,D,I,D); +extern ADECL2( plusII,I,I,I); +extern ADECL2( plusIO,D,I,I); +extern ADECL2( plusQQ,Q,Q,Q); +extern ADECL2( plusXX,X,X,X); +extern ADECL2( plusZZ,Z,Z,Z); +extern ADECL2( powBD,D,B,D); +extern ADECL2( powBI,D,B,I); +extern ADECL2( powDB,D,D,B); +extern ADECL2( powDD,D,D,D); +extern ADECL2( powDI,D,D,I); +extern ADECL2( powIB,I,I,B); +extern ADECL2( powID,D,I,D); +extern ADECL2( powII,D,I,I); +extern ADECL2( powQQ,Q,Q,Q); +extern ADECL2( powXX,X,X,X); +extern ADECL2( powZZ,Z,Z,Z); +extern ADECL2( remDD,D,D,D); +extern ADECL2( remII,I,I,I); +extern ADECL2( remID,I,I,D); +extern ADECL2( remQQ,Q,Q,Q); +extern ADECL2( remXX,X,X,X); +extern ADECL2( remZZ,Z,Z,Z); +extern ADECL2(tymesBD,D,B,D); +extern ADECL2(tymesBI,I,B,I); +extern ADECL2(tymesDB,D,D,B); +extern ADECL2(tymesDD,D,D,D); +extern ADECL2(tymesDI,D,I,D); +extern ADECL2(tymesIB,I,I,B); +extern ADECL2(tymesID,D,I,D); +extern ADECL2(tymesII,I,I,I); +extern ADECL2(tymesIO,D,I,I); +extern ADECL2(tymesQQ,Q,Q,Q); +extern ADECL2(tymesXX,X,X,X); +extern ADECL2(tymesZZ,Z,Z,Z);
new file mode 100644 --- /dev/null +++ b/vf.c @@ -0,0 +1,293 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Fill-Dependent Verbs */ + +#include "j.h" + + +F2(jtsetfv){A q=jt->fill;I t; + RZ(a&&w); + t=AN(a)?AT(a):AN(w)?AT(w):0; + if(q&&AN(q)){ + RE(t=maxtype(t,AT(q))); + if(t!=AT(q))RZ(q=cvt(t,q)); + if(ARELATIVE(q))RZ(q=cpa(1,q)); + jt->fillv=CAV(q); + }else{if(!t)t=AT(w); fillv(t,1L,jt->fillv0); jt->fillv=jt->fillv0;} + if(ARELATIVE(w)){*(I*)(jt->fillv0)=AREL(*(A*)jt->fillv,w); jt->fillv=jt->fillv0;} + R t==AT(w)?w:cvt(t,w); +} + +F1(jtfiller){A z; RZ(w); GA(z,AT(w),1,0,0); fillv(AT(w),1L,CAV(z)); R z;} + +void fillv(I t,I n,C*v){I k=bp(t); + if (t&RAT )mvc(n*k,v,k,&zeroQ); + else if(t&XNUM )mvc(n*k,v,k,&xzero); + else if(t&NUMERIC+SBT)memset(v,C0,k*n); + else if(t&LIT )memset(v,' ',n); + else if(t&C2T ){US x=32; mvc(n*k,v,k,&x);} + else mvc(n*k,v,k,&mtv); +} + + +static F2(jtrotsp){PROLOG;A q,x,y,z;B bx,by;I acr,af,ar,*av,d,k,m,n,p,*qv,*s,*v,wcr,wf,wr;P*wp,*zp; + RZ(a&&w); + ASSERT(!jt->fill,EVNONCE); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; p=acr?*(af+AS(a)):1; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(1<acr||af)R df2(a,w,qq(qq(ds(CROT),v2(1L,RMAX)),v2(acr,wcr))); + if(!wcr&&1<p){RZ(w=reshape(over(shape(w),apv(p,1L,0L)),w)); wr=wcr=p;} + ASSERT(!wcr||p<=wcr,EVLENGTH); + s=AS(w); + GA(q,INT,wr,1L,0); qv=AV(q); memset(qv,C0,wr*SZI); + RZ(a=vi(a)); v=AV(a); + DO(p, k=v[i]; d=s[wf+i]; qv[wf+i]=!d?0:0<k?k%d:k==IMIN?d-(-d-k)%d:d-(-k)%d;); + wp=PAV(w); a=SPA(wp,a); RZ(y=ca(SPA(wp,i))); m=IC(y); + n=AN(a); RZ(a=paxis(wr,a)); av=AV(a); + RZ(q=from(a,q)); qv=AV(q); + GA(z,AT(w),1,wr,s); zp=PAV(z); + by=0; DO(n, if(qv[ i]){by=1; break;}); + bx=0; DO(wr-n, if(qv[n+i]){bx=1; break;}); + RZ(x=!bx?ca(SPA(wp,x)):irs2(vec(INT,wr-n,n+qv),SPA(wp,x),0L,1L,-1L,jtrotate)); + if(by){ + DO(n, if(k=qv[i]){d=s[av[i]]-k; v=i+AV(y); DO(m, *v<k?(*v+=d):(*v-=k); v+=n;);}); + RZ(q=grade1(y)); RZ(y=from(q,y)); RZ(x=from(q,x)); + } + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,e,ca(SPA(wp,e))); + SPB(zp,x,x); + SPB(zp,i,y); + EPILOG(z); +} /* a|."r w on sparse arrays */ + +#define ROF(r) r=r<-n?-n:n<r?n:r; x=dk*ABS(r); y=e-x; j=0>r?x:0; k=0>r?0:x; +#define ROT(r) r=r%n; x=dk*ABS(r); y=e-x; j=0>r?y:x; k=0>r?x:y; + +static void jtrot(J jt,I m,I c,I n,I k,I p,I*av,C*u,C*v){I dk,e,j,r,x,y; + e=c*k; dk=e/n; if(jt->fill)mvc(m*e,v,k,jt->fillv); + switch((jt->fill?0:2)+(1<p)){ + case 0: r=p?*av:0; ROF(r); DO(m, MC(j+v,k+u,y); u+=e; v+=e;); break; + case 1: DO(m, r=av[i]; ROF(r); MC(j+v,k+u,y); u+=e; v+=e;); break; + case 2: r=p?*av:0; ROT(r); DO(m, MC(v,j+u,k); MC(k+v,u,j); u+=e; v+=e;); break; + case 3: DO(m, r=av[i]; ROT(r); MC(v,j+u,k); MC(k+v,u,j); u+=e; v+=e;); +}} + +/* m # cells + c # atoms in each cell + n # items in each cell + k # bytes in each atom + p length of av + av rotation amount(s) + u source data area + v target data area */ + +F2(jtrotate){A y,z;B b;C*u,*v;I acr,af,ar,*av,k,m,n,p,*s,wcr,wf,wn,wr; + RZ(a&&w); + if(SPARSE&AT(w))R rotsp(a,w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; p=acr?*(af+AS(a)):1; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(1<acr||af&&acr||af&&!wf)R df2(a,w,qq(qq(ds(CROT),v2(1L,RMAX)),v2(acr,wcr))); + if(!wcr&&1<p){RZ(w=reshape(over(shape(w),apv(p,1L,0L)),w)); wr=wcr=p;} + ASSERT(!wcr||p<=wcr,EVLENGTH); + RZ(a=vi(a)); av=AV(a); + RZ(w=setfv(w,w)); u=CAV(w); wn=AN(w); s=AS(w); k=bp(AT(w)); + GA(z,AT(w),wn,wr,s); v=CAV(z); + if(!wn)R z; + m=prod(wf,s); n=wcr?s[wf]:1; + rot(m,wn/m,n,k,1>=p?AN(a):1L,av,u,v); + if(1<p){ + GA(y,AT(w),wn,wr,s); u=CAV(y); + b=0; s+=wf; + DO(p-1, m*=n; n=*++s; rot(m,wn/m,n,k,1L,av+i+1,b?u:v,b?v:u); b=!b;); + z=b?y:z; + } + R RELOCATE(w,z); +} /* a|.!.f"r w */ + + +static F1(jtrevsp){A a,q,x,y,z;I c,f,k,m,n,r,*v,wr;P*wp,*zp; + RZ(w); + ASSERT(!jt->fill,EVNONCE); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; jt->rank=0; + m=*(f+AS(w)); wp=PAV(w); + GA(z,AT(w),1,wr,AS(w)); zp=PAV(z); + a=SPA(wp,a); n=AN(a); RZ(y=ca(SPA(wp,i))); x=SPA(wp,x); + RZ(q=paxis(wr,a)); v=AV(q); DO(wr, if(f==v[i]){k=i; break;}); + if(!r) RZ(x=ca(x)) + else if(k>=n)RZ(x=irs2(apv(m,m-1,-1L),x,0L,1L,wr-k,jtfrom)) + else {v=k+AV(y); c=m-1; DO(IC(y), *v=c-*v; v+=n;); q=grade1(y); RZ(y=from(q,y)); RZ(x=from(q,x));} + SPB(zp,a,ca(a)); + SPB(zp,e,ca(SPA(wp,e))); + SPB(zp,i,y); + SPB(zp,x,x); + R z; +} /* |."r w on sparse arrays */ + +F1(jtreverse){A z;C*wv,*zv;I f,k,m,n,nk,r,*v,*ws,wt,wr; + RZ(w); + if(SPARSE&AT(w))R revsp(w); + if(jt->fill)R rotate(num[-1],w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; + if(!(r&&AN(w))){RZ(z=ca(w)); R ARELATIVE(w)?relocate((I)w-(I)z,z):z;} + wt=AT(w); ws=AS(w); wv=CAV(w); + n=ws[f]; + m=1; DO(f, m*=ws[i];); + k=bp(wt); v=1+f+ws; DO(r-1, k*=*v++;); nk=n*k; + GA(z,wt,AN(w),wr,ws); zv=CAV(z); + switch(k){ + default: {C*s=wv-k,*t; DO(m, t=s+=nk; DO(n, memcpy(zv,t,k); zv+=k; t-=k;););} break; + case sizeof(C): {C*s= wv,*t,*u= zv; DO(m, t=s+=n; DO(n, *u++=*--t;););} break; + case sizeof(S): {S*s=(S*)wv,*t,*u=(S*)zv; DO(m, t=s+=n; DO(n, *u++=*--t;););} break; + case sizeof(I): {I*s=(I*)wv,*t,*u=(I*)zv; DO(m, t=s+=n; DO(n, *u++=*--t;););} break; +#if !SY_64 && SY_WIN32 + case sizeof(D): {D*s=(D*)wv,*t,*u=(D*)zv; DO(m, t=s+=n; DO(n, *u++=*--t;););} break; +#endif + } + R RELOCATE(w,z); +} /* |."r w */ + + +static A jtreshapesp0(J jt,A a,A w,I wf,I wcr){A e,p,x,y,z;B*b,*pv;I c,d,r,*v,wr,*ws;P*wp,*zp; + wr=AR(w); ws=AS(w); + wp=PAV(w); RZ(b=bfi(wr,SPA(wp,a),1)); + RZ(e=ca(SPA(wp,e))); x=SPA(wp,x); y=SPA(wp,i); + v=AS(y); r=v[0]; c=v[1]; d=0; DO(wf, if(b[i])++d;); + if(!wf){if(r&&c){v=AV(y); DO(c, if(v[i])R e;);} R AN(x)?reshape(mtv,x):e;} + GA(z,AT(w),1,wf,ws); + zp=PAV(z); SPB(zp,e,e); SPB(zp,a,ifb(wf,b)); + GA(p,B01,r,1,0); pv=BAV(p); + v=AV(y); + DO(r, *pv=1; DO(c-d, if(v[d+i]){*pv=0; break;}); ++pv; v+=c;); + SPB(zp,i,repeat(p,taker(d,y))); + SPB(zp,x,irs2(mtv,repeat(p,x),0L,1L,wcr-(c-d),jtreshape)); + R z; +} /* '' ($,)"wcr w for sparse w */ + +static A jtreshapesp(J jt,A a,A w,I wf,I wcr){A a1,e,t,x,y,z;B az,*b,wz;I an,*av,c,d,j,m,*u,*v,wr,*ws;P*wp,*zp; + RZ(a=cvt(INT,a)); an=AN(a); av=AV(a); wr=AR(w); ws=AS(w); d=an-wcr; + az=0; DO(an, if(!av[ i])az=1;); + wz=0; DO(wcr, if(!ws[wf+i])wz=1;); + ASSERT(az||!wz,EVLENGTH); + if(!an)R reshapesp0(a,w,wf,wcr); + wp=PAV(w); a1=SPA(wp,a); c=AN(a1); RZ(b=bfi(wr,a1,1)); + RZ(e=ca(SPA(wp,e))); x=SPA(wp,x); y=SPA(wp,i); + u=av+an; v=ws+wr; m=0; DO(MIN(an,wcr-1), if(*--u!=*--v){m=1; break;}); + if(m||an<wcr) R reshapesp(a,irs1(w,0L,wcr,jtravel),wf,1L); + ASSERT(!jt->fill,EVDOMAIN); + GA(z,AT(w),1,wf+an,ws); ICPY(wf+AS(z),av,an); + zp=PAV(z); SPB(zp,e,e); + GA(t,INT,c+d*b[wf],1,0); v=AV(t); + DO(wf, if(b[i])*v++=i;); if(b[wf])DO(d, *v++=wf+i;); j=wf; DO(wcr, if(b[j])*v++=d+j; ++j;); + SPB(zp,a,t); + if(b[wf]){I n,q,r,*v0; /* sparse */ + if(wf!=*AV(a1))R rank2ex(a,w,0L,1L,wcr,jtreshape); + RE(m=prod(1+d,av)); n=IC(y); q=n*(m/ws[wf]); r=m%ws[wf]; + v=AV(y); DO(n, if(r<=*v)break; ++q; v+=c;); + GA(t,INT,q,1,0); u=AV(t); v=v0=AV(y); + m=j=0; DO(q, u[i]=m+*v; v+=c; ++j; if(j==n){j=0; v=v0; m+=ws[wf];}); + SPB(zp,i,stitch(abase2(vec(INT,1+d,av),t),reitem(sc(q),dropr(1L,y)))); + SPB(zp,x,reitem(sc(q),x)); + }else{ /* dense */ + GA(t,INT,an,1,0); v=AV(t); ICPY(v,av,d); m=d; j=wf; DO(wcr, if(!b[j++])v[m++]=av[i+d];); + SPB(zp,i,ca(y)); + SPB(zp,x,irs2(vec(INT,m,v),x,0L,1L,wcr-(an-m),jtreshape)); + } + R z; +} /* a ($,)"wcr w for sparse w and scalar or vector a */ + +F2(jtreshape){A z;B b;C*wv,*zv;I acr,ar,c,k,m,n,p,q,r,*s,t,*u,wcr,wf,wr,*ws,zn; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; ws=AS(w); jt->rank=0; + if(1<acr||acr<ar)R rank2ex(a,w,0L,MIN(1,acr),wcr,jtreshape); + RZ(a=vip(a)); r=AN(a); u=AV(a); + if(SPARSE&AT(w))R reshapesp(a,w,wf,wcr); + RE(m=prod(r,u)); RE(c=prod(wf,ws)); RE(n=c?AN(w)/c:prod(wcr,wf+ws)); + ASSERT(n||!m||jt->fill,EVLENGTH); + b=jt->fill&&m>n; if(b)RZ(w=setfv(w,w)); + t=AT(w); k=bp(t); p=k*m; q=k*n; + RE(zn=mult(c,m)); + GA(z,t,zn,r+wf,0); s=AS(z); ICPY(s,ws,wf); ICPY(wf+s,u,r); + if(!zn)R z; + zv=CAV(z); wv=CAV(w); + if(b)DO(c, mvc(q,zv,q,wv); mvc(p-q,q+zv,k,jt->fillv); zv+=p; wv+=q;) + else DO(c, mvc(p,zv,q,wv); zv+=p; wv+=q;); + R RELOCATE(w,z); +} /* a ($,)"r w */ + +F2(jtreitem){A y;I acr,an,ar,m,r,*v,wcr,wr; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; m=MIN(1,acr); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; r=wcr-1; jt->rank=0; + if(1<acr||acr<ar)R rank2ex(a,w,0L,m,wcr,jtreitem); + if(1>=wcr)y=a; + else{ + RZ(a=vi(a)); an=AN(a); m=1; + GA(y,INT,an+r,1,0); v=AV(y); + ICPY(v,AV(a),an); ICPY(v+an,AS(w)+wr-r,r); + } + R ar==acr&&wr==wcr?reshape(y,w):irs2(y,w,0L,m,wcr,jtreshape); +} /* a $"r w */ + +#if SY_64 +#define EXPAND(T) \ + {T*u=(T*)wv,*v=(T*)zv,x; \ + mvc(sizeof(T),&x,k,jt->fillv); \ + DO(an, if(*av++){ASSERT(wx>(C*)u,EVLENGTH); *v++=*u++;}else *v++=x;); \ + wv=(C*)u; \ + } +#else +#define EXPAND(T) \ + {T*u=(T*)wv,*v=(T*)zv,x; \ + mvc(sizeof(T),&x,k,jt->fillv); \ + for(i=0;i<q;++i)switch(*au++){ \ + case B0000: *v++=x; *v++=x; *v++=x; *v++=x; break; \ + case B0001: ASSERT(wx> (C*)u,EVLENGTH); *v++=x; *v++=x; *v++=x; *v++=*u++; break; \ + case B0010: ASSERT(wx> (C*)u,EVLENGTH); *v++=x; *v++=x; *v++=*u++; *v++=x; break; \ + case B0011: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=x; *v++=x; *v++=*u++; *v++=*u++; break; \ + case B0100: ASSERT(wx> (C*)u,EVLENGTH); *v++=x; *v++=*u++; *v++=x; *v++=x; break; \ + case B0101: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=x; *v++=*u++; *v++=x; *v++=*u++; break; \ + case B0110: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=x; *v++=*u++; *v++=*u++; *v++=x; break; \ + case B0111: ASSERT(wx>2+(C*)u,EVLENGTH); *v++=x; *v++=*u++; *v++=*u++; *v++=*u++; break; \ + case B1000: ASSERT(wx> (C*)u,EVLENGTH); *v++=*u++; *v++=x; *v++=x; *v++=x; break; \ + case B1001: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=*u++; *v++=x; *v++=x; *v++=*u++; break; \ + case B1010: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=*u++; *v++=x; *v++=*u++; *v++=x; break; \ + case B1011: ASSERT(wx>2+(C*)u,EVLENGTH); *v++=*u++; *v++=x; *v++=*u++; *v++=*u++; break; \ + case B1100: ASSERT(wx>1+(C*)u,EVLENGTH); *v++=*u++; *v++=*u++; *v++=x; *v++=x; break; \ + case B1101: ASSERT(wx>2+(C*)u,EVLENGTH); *v++=*u++; *v++=*u++; *v++=x; *v++=*u++; break; \ + case B1110: ASSERT(wx>2+(C*)u,EVLENGTH); *v++=*u++; *v++=*u++; *v++=*u++; *v++=x; break; \ + case B1111: ASSERT(wx>3+(C*)u,EVLENGTH); *v++=*u++; *v++=*u++; *v++=*u++; *v++=*u++; break; \ + } \ + if(r){av=(B*)au; DO(r, if(*av++){ASSERT(wx>(C*)u,EVLENGTH); *v++=*u++;}else *v++=x;);} \ + wv=(C*)u; \ + } +#endif + +F2(jtexpand){A z;B*av;C*wv,*wx,*zv;I an,*au,i,k,p,q,r,wc,wk,wn,wt,zn; + RZ(a&&w); + if(!(B01&AT(a)))RZ(a=cvt(B01,a)); + ASSERT(1==AR(a),EVRANK); + RZ(w=setfv(w,w)); + if(!AR(w))R from(a,take(num[-2],w)); + av=BAV(a); an=AN(a); q=an/SZI; r=an%SZI; au=(I*)av; + wv=CAV(w); wn=AN(w); wc=aii(w); wt=AT(w); k=bp(wt); wk=k*wc; wx=wv+wk**AS(w); + RE(zn=mult(an,wc)); + GA(z,wt,zn,AR(w),AS(w)); *AS(z)=an; zv=CAV(z); + switch(wk){ + case sizeof(C): EXPAND(C); break; + case sizeof(S): EXPAND(S); break; + case sizeof(I): EXPAND(I); break; + default: + mvc(k*zn,zv,k,jt->fillv); + for(i=p=0;i<an;++i) + if(*av++)p+=wk; + else{if(p){ASSERT(wx>=wv+p,EVLENGTH); MC(zv,wv,p); wv+=p; zv+=p; p=0;} zv+=wk;} + if(p){ASSERT(wx>=wv+p,EVLENGTH); MC(zv,wv,p); wv+=p;} + } + ASSERT(wx==wv,EVLENGTH); + R z; +} /* a&#^:_1 w or a&#^:_1!.f w */ + + +
new file mode 100644 --- /dev/null +++ b/vfft.c @@ -0,0 +1,66 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Fast Fourier Transform and Friends */ + +#include "j.h" + + +/* + 0 0 8 0 0 0 4 0 0 0 2 0 0 0 1 0 + 1 1 9 0 1 1 5 0 1 1 3 0 1 0 1 8 + 2 2 10 0 2 2 6 0 2 0 2 8 2 2 3 4 + 3 3 11 0 3 3 7 0 3 1 3 8 3 2 3 12 + 4 4 12 0 4 0 4 8 4 4 6 4 4 4 5 2 + 5 5 13 0 5 1 5 8 5 5 7 4 5 4 5 10 + 6 6 14 0 6 2 6 8 6 4 6 12 6 6 7 6 + 7 7 15 0 7 3 7 8 7 5 7 12 7 6 7 14 + 8 0 8 8 8 8 12 4 8 8 10 2 8 8 9 1 + 9 1 9 8 9 9 13 4 9 9 11 2 9 8 9 9 +10 2 10 8 10 10 14 4 10 8 10 10 10 10 11 5 +11 3 11 8 11 11 15 4 11 9 11 10 11 10 11 13 +12 4 12 8 12 8 12 12 12 12 14 6 12 12 13 3 +13 5 13 8 13 9 13 12 13 13 15 6 13 12 13 11 +14 6 14 8 14 10 14 12 14 12 14 14 14 14 15 7 +15 7 15 8 15 11 15 12 15 13 15 14 15 14 15 15 + +pow=: * /\ @ }: @ (1&,) @ $ +FFT=: (# pow pru@#) floop ] +IFT=: # %~ (# pow %@pru@#) floop ] + +floop=: 4 : 0 + k=. 2^.n=. #y. + r=. y. + p=. ,|:i.k$2 NB. |."1&.#: i.n + w=. p{x. NB. (pru n)^p + for_m. <.2^i.-k do. + i=. (2#i.&.(%&(2*m)) n)+/i.m + r=. ,(i{r)+((i+m){r)*(n%m){.w + end. + p{r NB. ,|:(k$2)$r +) +*/ + +#if SY_64 +#define REVBITS(x,y) +#else +#define REVBITS(x,y) {y[3]=revb[x[0]]; y[2]=revb[x[1]]; y[1]=revb[x[2]]; y[0]=revb[x[3]];} +#endif + +static UC revb16[16]={0,8,4,12, 2,10,6,14, 1,9,5,13, 3,11,7,15}; +static UC revb[256]; + +static F1(jtravtranspose){I i,n,s;Z t,*v;UC*iv,*jv;UI j; + n=AN(w); v=ZAV(w); + j=n; s=SY_64?64:32; while(1<j){j>>=1; --s;} + iv=(UC*)&i; jv=(UC*)&j; + if(128!=revb[1])DO(256, revb[i]=16*revb16[i%16]+revb16[i/16];); + for(i=0;i<n;++i){ + REVBITS(iv,jv); j>>=s; + if(j>(UI)i){t=v[i]; v[i]=v[j]; v[j]=t;} + } + R w; +} /* ravel transpose in place: ,|:(#:&.<:#w)$w or (|."1&.#:i.#w){w */ + +static A jtfloop(J jt,A w,I k,B inv){ +}
new file mode 100644 --- /dev/null +++ b/vfrom.c @@ -0,0 +1,333 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: From & Associates. See Hui, Some Uses of { and }, APL87. */ + +#include "j.h" + + +F1(jtcatalog){PROLOG;A b,*wv,x,z,*zv;C*bu,*bv,**pv;I*cv,i,j,k,m=1,n,p,*qv,r=0,*s,t=0,*u,wd; + F1RANK(1,jtcatalog,0); + if(!(AN(w)&&AT(w)&BOX+SBOX))R box(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(n, x=WVR(i); if(AN(x)){p=AT(x); t=t?t:p; ASSERT(HOMO(t,p),EVDOMAIN); RE(t=maxtype(t,p));}); + RE(t=maxtype(B01,t)); k=bp(t); + GA(b,t,n,1,0); bv=CAV(b); + GA(x,INT,n,1,0); qv=AV(x); + GA(x,BOX,n,1,0); pv=(C**)AV(x); + RZ(x=apv(n,0L,0L)); cv=AV(x); + DO(n, x=WVR(i); if(t!=AT(x))RZ(x=cvt(t,x)); r+=AR(x); qv[i]=p=AN(x); RE(m=mult(m,p)); pv[i]=CAV(x);); + GA(z,BOX,m,r,0); zv=AAV(z); s=AS(z); + DO(n, x=WVR(i); u=AS(x); DO(AR(x),*s++=*u++;);); + for(i=0;i<m;i++){ + bu=bv-k; + DO(n, MC(bu+=k,pv[i]+k*cv[i],k);); + DO(n, j=n-1-i; if(qv[j]>++cv[j])break; cv[j]=0;); + RZ(*zv++=ca(b)); + } + EPILOG(z); +} + +#define SETJ(jexp) {j=(jexp); if(0<=j)ASSERT(j<p,EVINDEX) else{j+=p; ASSERT(0<=j,EVINDEX);}} + +#define IFROMLOOP(T) \ + {T *v=(T*)wv,*x=(T*)zv; \ + if(1==an){v+=j; DO(m, *x++=*v; v+=p; );} \ + else DO(m, DO(an, SETJ(av[i]); *x++=v[j];); v+=p; ); \ + } +#define IFROMLOOP2(T,qexp) \ + {T*u,*v=(T*)wv,*x=(T*)zv; \ + q=(qexp); pq=p*q; \ + if(1==an){v+=j*q; DO(m, u=v; DO(q, *x++=*u++;); v+=pq;);} \ + else DO(m, DO(an, SETJ(av[i]); u=v+j*q; DO(q, *x++=*u++;);); v+=pq;); \ + } + +F2(jtifrom){A z;C*wv,*zv;I acr,an,ar,*av,j,k,m,p,pq,q,*s,wcn,wcr,wf,wk,wn,wr,*ws,zn; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(ar>acr)R rank2ex(a,w,0L,acr,wcr,jtifrom); + an=AN(a); wn=AN(w); ws=AS(w); + if(!(INT&AT(a)))RZ(a=cvt(INT,a)); + p=j=wcr?*(ws+wf):1; j=j?j:1; + RE(m=prod(wf,ws)); RE(zn=mult(an,wn/j)); wcn=wn/(m?m:1); k=bp(AT(w))*wcn/j; wk=j*k; + GA(z,AT(w),zn,ar+wr-(0<wcr),ws); + s=AS(z); ICPY(s+wf,AS(a),ar); if(wcr)ICPY(s+wf+ar,1+wf+ws,wcr-1); + av=AV(a); wv=CAV(w); zv=CAV(z); if(an)SETJ(*av); + if(AT(w)&FL+CMPX){if(k==sizeof(D))IFROMLOOP(D) else IFROMLOOP2(D,k/sizeof(D));} + else switch(k){ + case sizeof(C): IFROMLOOP(C); break; + case sizeof(S): IFROMLOOP(S); break; + case sizeof(I): IFROMLOOP(I); break; + default: + if (0==k%sizeof(I))IFROMLOOP2(I,k/sizeof(I)) + else if(0==k%sizeof(S))IFROMLOOP2(S,k/sizeof(S)) + else{S*x,*u; + q=1+k/sizeof(S); + if(1==an){wv+=k*j; DO(m, x=(S*)zv; u=(S*) wv; DO(q, *x++=*u++;); zv+=k; wv+=wk;);} + else DO(m, DO(an, SETJ(av[i]); x=(S*)zv; u=(S*)(wv+k*j); DO(q, *x++=*u++;); zv+=k;); wv+=wk;); + }} + R RELOCATE(w,z); +} /* a{"r w for numeric a */ + +#define BSET(x,y0,y1,y2,y3) *x++=y0; *x++=y1; *x++=y2; *x++=y3; +#define BSETV(b) MC(v,wv+b*k,k); v+=k; + +#if !SY_64 && SY_WIN32 +#define BNNERN(T) \ + {B*au=av;T*v=(T*)wv,v0,v1,*x=(T*)zv; \ + DO(m, v0=v[0]; v1=v[1]; u=(I*)av; DO(q, switch(*u++){ \ + case B0000: BSET(x,v0,v0,v0,v0); break; case B0001: BSET(x,v0,v0,v0,v1); break; \ + case B0010: BSET(x,v0,v0,v1,v0); break; case B0011: BSET(x,v0,v0,v1,v1); break; \ + case B0100: BSET(x,v0,v1,v0,v0); break; case B0101: BSET(x,v0,v1,v0,v1); break; \ + case B0110: BSET(x,v0,v1,v1,v0); break; case B0111: BSET(x,v0,v1,v1,v1); break; \ + case B1000: BSET(x,v1,v0,v0,v0); break; case B1001: BSET(x,v1,v0,v0,v1); break; \ + case B1010: BSET(x,v1,v0,v1,v0); break; case B1011: BSET(x,v1,v0,v1,v1); break; \ + case B1100: BSET(x,v1,v1,v0,v0); break; case B1101: BSET(x,v1,v1,v0,v1); break; \ + case B1110: BSET(x,v1,v1,v1,v0); break; case B1111: BSET(x,v1,v1,v1,v1); break; \ + }); \ + b=(B*)u; DO(r, *x++=*b++?v1:v0;); v+=p;); \ + } +#define BNNERM(T,T1) \ + {B*au=av;T*c,*v=(T*)wv,v0,v1,*x=(T*)zv;T1 vv[16],*y; \ + DO(m, v0=v[0]; v1=v[1]; c=(T*)vv; y=(T1*)x; u=(I*)av; \ + BSET(c,v0,v0,v0,v0); BSET(c,v0,v0,v0,v1); BSET(c,v0,v0,v1,v0); BSET(c,v0,v0,v1,v1); \ + BSET(c,v0,v1,v0,v0); BSET(c,v0,v1,v0,v1); BSET(c,v0,v1,v1,v0); BSET(c,v0,v1,v1,v1); \ + BSET(c,v1,v0,v0,v0); BSET(c,v1,v0,v0,v1); BSET(c,v1,v0,v1,v0); BSET(c,v1,v0,v1,v1); \ + BSET(c,v1,v1,v0,v0); BSET(c,v1,v1,v0,v1); BSET(c,v1,v1,v1,v0); BSET(c,v1,v1,v1,v1); \ + DO(q, switch(*u++){ \ + case B0000: *y++=vv[ 0]; break; case B0001: *y++=vv[ 1]; break; \ + case B0010: *y++=vv[ 2]; break; case B0011: *y++=vv[ 3]; break; \ + case B0100: *y++=vv[ 4]; break; case B0101: *y++=vv[ 5]; break; \ + case B0110: *y++=vv[ 6]; break; case B0111: *y++=vv[ 7]; break; \ + case B1000: *y++=vv[ 8]; break; case B1001: *y++=vv[ 9]; break; \ + case B1010: *y++=vv[10]; break; case B1011: *y++=vv[11]; break; \ + case B1100: *y++=vv[12]; break; case B1101: *y++=vv[13]; break; \ + case B1110: *y++=vv[14]; break; case B1111: *y++=vv[15]; break; \ + }); \ + b=(B*)u; x=(T*)y; DO(r, *x++=*b++?v1:v0;); v+=p;); \ + } +#else +#define BNNERN(T) {T*v=(T*)wv,*x=(T*)zv; DO(m, b=av; DO(an, *x++=*(v+*b++);); v+=p;);} +#define BNNERM(T,T1) BNNERN(T) +#endif + +#define INNER1B(T) {T*v=(T*)wv,*x=(T*)zv; v+=*av; DO(m, *x++=*v; v+=p;);} + +static F2(jtbfrom){A z;B*av,*b;C*wv,*zv;I acr,an,ar,k,m,p,q,r,*s,*u=0,wcn,wcr,wf,wk,wn,wr,*ws,zn; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(ar>acr)R rank2ex(a,w,0L,acr,wcr,jtbfrom); + an=AN(a); wn=AN(w); ws=AS(w); + p=wcr?*(ws+wf):1; q=an/SZI; r=an%SZI; + ASSERT(2<=p||1==p&&all0(a)||!p&&!an,EVINDEX); + p=p?p:1; RE(m=prod(wf,ws)); RE(zn=mult(an,wn/p)); wcn=wn/(m?m:1); k=bp(AT(w))*wcn/p; wk=p*k; + GA(z,AT(w),zn,ar+wr-(0<wcr),ws); + s=AS(z); ICPY(s+wf,AS(a),ar); if(wcr)ICPY(s+wf+ar,1+wf+ws,wcr-1); + av=BAV(a); wv=CAV(w); zv=CAV(z); + switch(k+k+(1==an)){ + case 2*sizeof(I): BNNERN(I); break; + case 2*sizeof(C): BNNERM(C,I); break; + case 1+2*sizeof(C): INNER1B(C); break; + case 1+2*sizeof(S): INNER1B(S); break; + case 1+2*sizeof(I): INNER1B(I); break; + default: + if(1==an){wv+=k**av; DO(m, MC(zv,wv,k); zv+=k; wv+=wk;);} +#if !SY_64 && SY_WIN32 + else{A x;C*v,*xv,*xv00,*xv01,*xv02,*xv03,*xv04,*xv05,*xv06,*xv07,*xv08,*xv09,*xv10,*xv11, + *xv12,*xv13,*xv14,*xv15;I i,j,k4=k*4; + GA(x,LIT,16*k4,1,0); xv=CAV(x); + xv00=xv; xv01=xv+ k4; xv02=xv+ 2*k4; xv03=xv+ 3*k4; + xv04=xv+ 4*k4; xv05=xv+ 5*k4; xv06=xv+ 6*k4; xv07=xv+ 7*k4; + xv08=xv+ 8*k4; xv09=xv+ 9*k4; xv10=xv+10*k4; xv11=xv+11*k4; + xv12=xv+12*k4; xv13=xv+13*k4; xv14=xv+14*k4; xv15=xv+15*k4; + for(i=0;i<m;++i){ + u=(I*)av; v=xv; + BSETV(0); BSETV(0); BSETV(0); BSETV(0); BSETV(0); BSETV(0); BSETV(0); BSETV(1); + BSETV(0); BSETV(0); BSETV(1); BSETV(0); BSETV(0); BSETV(0); BSETV(1); BSETV(1); + BSETV(0); BSETV(1); BSETV(0); BSETV(0); BSETV(0); BSETV(1); BSETV(0); BSETV(1); + BSETV(0); BSETV(1); BSETV(1); BSETV(0); BSETV(0); BSETV(1); BSETV(1); BSETV(1); + BSETV(1); BSETV(0); BSETV(0); BSETV(0); BSETV(1); BSETV(0); BSETV(0); BSETV(1); + BSETV(1); BSETV(0); BSETV(1); BSETV(0); BSETV(1); BSETV(0); BSETV(1); BSETV(1); + BSETV(1); BSETV(1); BSETV(0); BSETV(0); BSETV(1); BSETV(1); BSETV(0); BSETV(1); + BSETV(1); BSETV(1); BSETV(1); BSETV(0); BSETV(1); BSETV(1); BSETV(1); BSETV(1); + for(j=0;j<q;++j,zv+=k4)switch(*u++){ + case B0000: MC(zv,xv00,k4); break; case B0001: MC(zv,xv01,k4); break; + case B0010: MC(zv,xv02,k4); break; case B0011: MC(zv,xv03,k4); break; + case B0100: MC(zv,xv04,k4); break; case B0101: MC(zv,xv05,k4); break; + case B0110: MC(zv,xv06,k4); break; case B0111: MC(zv,xv07,k4); break; + case B1000: MC(zv,xv08,k4); break; case B1001: MC(zv,xv09,k4); break; + case B1010: MC(zv,xv10,k4); break; case B1011: MC(zv,xv11,k4); break; + case B1100: MC(zv,xv12,k4); break; case B1101: MC(zv,xv13,k4); break; + case B1110: MC(zv,xv14,k4); break; case B1111: MC(zv,xv15,k4); break; + } + b=(B*)u; DO(r, MC(zv,wv+k**b++,k); zv+=k;); wv+=wk; + }} +#else + else DO(m, b=av; DO(an, MC(zv,wv+k**b++,k); zv+=k;); wv+=wk;); +#endif + } + R RELOCATE(w,z); +} /* a{"r w for boolean a */ + +A jtfrombu(J jt,A a,A w,I wf){A p,q,z;B b=0;I ar,*as,h,m,r,*u,*v,wcr,wr,*ws; + ar=AR(a); as=AS(a); h=as[ar-1]; + wr=AR(w); ws=AS(w); wcr=wr-wf; + DO(ar, if(!as[i]){b=1; break;}); + DO(wr, if(!ws[i]){b=1; break;}); + if(b){ + GA(z,AT(w),0,wf+(wcr-h)+(ar-1),0); u=AS(z); + v=ws; DO(wf, *u++=*v++;); + v=as; DO(ar-1, *u++=*v++;); + v=ws+wf+h; DO(wcr-h, *u++=*v++;); + R z; + } + GA(p,INT,h,1,0); v=AV(p)+h; u=ws+wf+h; m=1; DO(h, *--v=m; m*=*--u;); + r=wr+1-h; + if(r==wr) + z=irs2(pdt(a,p),w,0L,RMAX,wcr+1-h,jtifrom); + else if(ARELATIVE(w)){ + GA(q,INT,r,1,0); + v=AV(q); ICPY(v,ws,wf); *(v+wf)=m; ICPY(v+wf+1,ws+wf+h,wcr-h); RZ(q=reshape(q,w)); + z=irs2(pdt(a,p),q,0L,RMAX,wcr+1-h,jtifrom); + }else{ + RZ(q=gah(r,w)); v=AS(q); ICPY(v,ws,wf); *(v+wf)=m; ICPY(v+wf+1,ws+wf+h,wcr-h); /* q is reshape(.,w) */ + z=irs2(pdt(a,p),q,0L,RMAX,wcr+1-h,jtifrom); + } + R z; +} /* (<"1 a){"r w, dense w, integer array a */ + +B jtaindex(J jt,A a,A w,I wf,A*ind){A*av,q,z;I ad,an,ar,c,j,k,t,*u,*v,*ws; + RZ(a&&w); + an=AN(a); *ind=0; + if(!an)R 0; + ws=wf+AS(w); ar=AR(a); av=AAV(a); ad=(I)a*ARELATIVE(a); q=AVR(0); c=AN(q); + if(!c)R 0; + ASSERT(c<=AR(w)-wf,EVLENGTH); + GA(z,INT,an*c,1+ar,AS(a)); *(ar+AS(z))=c; v=AV(z); + for(j=0;j<an;++j){ + q=AVR(j); t=AT(q); + if(t&BOX)R 0; + if(!(t&INT))RZ(q=cvt(INT,q)); + if(!(c==AN(q)&&1>=AR(q)))R 0; + u=AV(q); + DO(c, k=u[i]; if(0>k)k+=ws[i]; ASSERT(0<=k&&k<ws[i],EVINDEX); *v++=k;); + } + *ind=z; + R 1; +} /* <"1 a to a where a is an integer index array */ + +static B jtaindex1(J jt,A a,A w,I wf,A*ind){A z;I c,k,n,t,*v,*ws; + RZ(a&&w); + n=AN(a); t=AT(a); *ind=0; + ws=wf+AS(w); c=*(AS(a)+AR(a)-1); + if(!n||!c||t&BOX)R 0; + ASSERT(c<=AR(w)-wf,EVLENGTH); + RZ(z=t&INT?ca(a):cvt(INT,a)); v=AV(z); + DO(n/c, DO(c, k=*v; if(0>k)*v=k+=ws[i]; ASSERT(0<=k&&k<ws[i],EVINDEX); ++v;);); + *ind=z; + R 1; +} /* verify that <"1 a is valid for (<"1 a){w */ + +static A jtafrom2(J jt,A p,A q,A w,I r){A z;C*wv,*zv;I c,d,e,j,k,m,pn,pr,*pv, + qn,qr,*qv,*s,wf,wk,wr,*ws,zn; + wr=AR(w); ws=AS(w); wf=wr-r; wk=bp(AT(w)); + pn=AN(p); pr=AR(p); pv=AV(p); + qn=AN(q); qr=AR(q); qv=AV(q); + RE(m=prod(wf,ws)); RE(c=prod(r,ws+wf)); e=ws[1+wf]; d=c?c/(e*ws[wf]):0; + RE(zn=mult(m,mult(pn,mult(qn,d)))); + GA(z,AT(w),zn,wf+pr+qr+r-2,ws); + s=AS(z)+wf; ICPY(s,AS(p),pr); + s+=pr; ICPY(s,AS(q),qr); + s+=qr; ICPY(s,ws+wf+2,r-2); + wv=CAV(w); zv=CAV(z); + switch(k=d*wk){ + default: {C*v=wv,*x=zv-k;I n=c*wk; + DO(m, DO(pn, j=e*pv[i]; DO(qn, MC(x+=k,v+k*(j+qv[i]),k);)); v+=n;); R z;} +#define INNER2(T) {T*v=(T*)wv,*x=(T*)zv;I n=c/d; \ + DO(m, DO(pn, j=e*pv[i]; DO(qn, *x++=v[j+qv[i]]; )); v+=n;); R z;} + case sizeof(C): INNER2(C); + case sizeof(S): INNER2(S); + case sizeof(I): INNER2(I); +#if !SY_64 && SY_WIN32 + case sizeof(D): INNER2(D); +#endif +}} /* (<p;q){"r w for positive integer arrays p,q */ + +static A jtafi(J jt,I n,A w){A x; + if(!(AN(w)&&BOX&AT(w)))R pind(n,w); + ASSERT(!AR(w),EVINDEX); + x=AAV0(w); + R AN(x)?less(IX(n),pind(n,x)):ace; +} + +static F2(jtafrom){PROLOG;A c,ind,p=0,q,*v,x,y=w;B b=1,bb=1;I acr,ar,cd,i=0,j,k,m,n,pr,r,*s,t,wcr,wf,wr; + RZ(a&&w); + ar=AR(a); acr= jt->rank?jt->rank[0]:ar; + wr=AR(w); wcr=r=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(ar){ + if(ar==acr&&wr==wcr){RE(aindex(a,w,wf,&ind)); if(ind)R frombu(ind,w,wf);} + R wr==wcr?rank2ex(a,w,0L,0L,wcr,jtafrom): + df2(rank1ex(a,0L,acr,jtbox),rank1ex(w,0L,wcr,jtbox),amp(ds(CLBRACE),ds(COPE))); + } + c=AAV0(a); t=AT(c); n=IC(c); v=AAV(c); cd=(I)c*ARELATIVE(c); + k=bp(AT(w)); s=AS(w)+wr-r; + ASSERT(1>=AR(c),EVRANK); + ASSERT(n<=r,EVLENGTH); + if(n&&!(t&BOX)){RE(aindex(a,w,wf,&ind)); if(ind)R frombu(ind,w,wf);} + if(r==wr)for(i=m=pr=0;i<n;++i){ + p=afi(s[i],AADR(cd,v[i])); + if(!(p&&1==AN(p)&&INT&AT(p)))break; + pr+=AR(p); + m+=*AV(p)*prod(r-i-1,1+i+s); + } + if(i){I*ys; + RZ(y=gah(pr+r-i,w)); ys=AS(y); DO(pr, *ys++=1;); ICPY(ys,s+i,r-i); + AM(y)=AN(y)=prod(AR(y),AS(y)); + AK(y)=k*m+CAV(w)-(C*)y; + } + for(;i<n;i+=2){ + j=1+i; if(!p)p=afi(s[i],AADR(cd,v[i])); q=j<n?afi(s[j],AADR(cd,v[j])):ace; if(!(p&&q))break; + if(p!=ace&&q!=ace){b=0; y=afrom2(p,q,y,r-i);} + else if(p!=ace) {b=0; y=irs2(p,y,0L,AR(p),r-i,jtifrom);} + else if(q!=ace) {b=0; y=irs2(q,y,0L,AR(q),r-j,jtifrom);} + p=0; + } + RE(y); if(b){RZ(y=ca(x=y)); RZ(y=RELOCATE(x,y));} EPILOG(y); +} /* a{"r w for boxed index a */ + +F2(jtfrom){I at; + RZ(a&&w); + at=AT(a); + switch((at&SPARSE?2:0)+(AT(w)&SPARSE?1:0)){ + case 0: R at&BOX?afrom(a,w) :at&B01?bfrom(a,w):ifrom(a,w); + case 1: R at&BOX?frombs(a,w) : fromis(a,w); + case 2: R fromsd(a,w); + default: R fromss(a,w); +}} /* a{"r w main control */ + +F2(jtsfrom){A ind; + RE(aindex1(a,w,0L,&ind)); + R !ind?from(irs1(a,0L,1L,jtbox),w):SPARSE&AT(w)?frombsn(ind,w,0L):frombu(ind,w,0L); +} /* (<"1 a){w */ + +static F2(jtmapx){ + RZ(a&&w); + if(!(BOX&AT(w)))R ope(a); + R every2(box0(every2(a,box0(catalog(every(shape(w),0L,jtiota))),0L,jtover)),w,0L,jtmapx); +} + +F1(jtmap){R mapx(ace,w);} + + +F2(jtfetch){A*av,t,x=w;I ad,n; + F2RANK(1,RMAX,jtfetch,0); + if(!(BOX&AT(a)))RZ(a=box(a)); + n=AN(a); av=AAV(a); ad=(I)a*ARELATIVE(a); + if(!n)R w; + DO(n-1, RZ(t=afrom(box(AVR(i)),x)); ASSERT(!AR(t),EVRANK); RZ(x=ope(t));); + RZ(t=afrom(box(AVR(n-1)),x)); + R !AR(t)&&AT(t)&BOX?ope(t):t; +} +
new file mode 100644 --- /dev/null +++ b/vfromsp.c @@ -0,0 +1,192 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: { on sparse arguments */ + +#include "j.h" + + +static A jtfromis1(J jt,A ind,A w,A z,I wf){A a,a1,j1,p,q,x,x1,y,y1;C*xu,*xuu,*xv;I an,*av,c,d, + h,i,*iv,j,*jv,k,m,n,*pv,*qu,*qv,r,s,*u,*v,xk,*yu,*yv;P*wp,*zp; + zp=PAV(z); wp=PAV(w); r=AR(ind); n=AN(ind); + a=SPA(wp,a); an=AN(a); av=AV(a); DO(an, if(wf==av[i]){h=i; break;}); + y=SPA(wp,i); RZ(q=eps(fromr(sc(h),y),ravel(ind))); RZ(y=repeat(q,y)); RZ(x=repeat(q,SPA(wp,x))); + GA(a1,INT,r+an-1,1,0); v=AV(a1); SPB(zp,a,a1); + k=av[h]; u=av; DO(h, *v++=*u++;); DO(r, *v++=k++;); u++; DO(an-1-h, *v++=*u+++r-1;); + if(!r) + if(AR(z)){GA(q,INT,an-1,1,0); v=AV(q); DO(an, if(i!=h)*v++=i;); SPB(zp,i,fromr(q,y)); SPB(zp,x,x); R z;} + else R reshape(mtv,AN(x)?x:SPA(zp,e)); + if(h){q=grade1(fromr(sc(h),y)); RZ(y=ifrom(q,y)); RZ(x=ifrom(q,x));} + RZ(q=odom(2L,r,AS(ind))); iv=AV(q); + m=*AS(y); s=0; j=-1; u=h+AV(y); v=u+an; + GA(p,INT,m,1,0); pv=AV(p); memset(pv,CFF,SZI*m); + GA(q,INT,m,1,0); qu=AV(q); + GA(q,INT,m,1,0); qv=AV(q); + DO(m-1, if(*u!=*v){pv[s]=*u; qu[s]=1+j; qv[s++]=i-j; j=i;} u=v; v+=an;); + if(m){i=m-1; pv[s]=*u; qu[s]=1+j; qv[s++]=i-j;} + RZ(j1=indexof(p,ind)); jv=AV(j1); + c=0; DO(n, if(s>jv[i])c+=qv[jv[i]];); i=aii(x); xk=i*bp(AT(x)); d=AN(a1); + GA(y1,INT, c*d,2, 0 ); v=AS(y1); v[0]=c; v[1]=d; yv= AV(y1); yu= AV(y); + GA(x1,AT(x),c*i,AR(x),AS(x)); *AS(x1)=c; xv=CAV(x1); xu=CAV(x); + for(i=0;i<n;++i){ + k=jv[i]; + if(s>k){ + c=qu[k]; d=qv[k]; xuu=xu+c*xk; u=yu+c*an; + for(j=0;j<d;++j){ + MC(xv,xuu,xk); xv+=xk; xuu+=xk; + DO(h, *yv++=*u++;); DO(r, *yv++=iv[i];); u++; DO(an-1-h, *yv++=*u++;); + }} + iv+=r; + } + if(h){q=grade1(y1); RZ(y1=ifrom(q,y1)); RZ(x1=ifrom(q,x1));} + SPB(zp,i,y1); SPB(zp,x,x1); + R z; +} /* ind{"r w along a sparse axis */ + +F2(jtfromis){A ind,x,z;B*b;I acr,af,an,ar,*av,k,m,*v,wcr,wf,wn,wr,*ws,wt;P*wp,*zp; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(af)R rank2ex(a,w,0L,acr,wcr,jtfromis); + wn=AN(w); ws=AS(w); wt=AT(w); + RZ(ind=pind(wcr?*(ws+wf):1,a)); + GA(z,wt,1L,ar+wr-(0<wcr),ws); v=AS(z); ICPY(v+wf,AS(a),ar); if(wcr)ICPY(v+wf+ar,1+wf+ws,wcr-1); + zp=PAV(z); wp=PAV(w); SPB(zp,e,ca(SPA(wp,e))); + RZ(a=ca(SPA(wp,a))); av=AV(a); an=AN(a); + RZ(b=bfi(wr,a,1)); + if(b[wf])R fromis1(ind,w,z,wf); + m=wcr; DO(wcr, m-=b[wf+i];); RZ(x=irs2(ind,SPA(wp,x),0L,ar,m,jtifrom)); + if(k=ar-1)DO(an, if(av[i]>=wf)av[i]+=k;); + if(AR(z)){SPB(zp,a,a); SPB(zp,x,x); SPB(zp,i,ca(SPA(wp,i))); R z;} + else R AN(x)?reshape(mtv,x):ca(SPA(wp,e)); +} /* a{"r w for numeric a and sparse w */ + +static A jtaaxis(J jt,A w,I wf,A a,I r,I h,I*pp,I*qq,I*rr){A q;B*b,*c,*d;I wr,x,y,z,zr; + wr=AR(w); zr=wr+r-h; + RZ(b=bfi(wr,a,1)); + GA(q,B01,zr,1,0); c=BAV(q); + x=y=z=0; d=b; DO(wf, if(*d++)++x;); DO(h, if(*d++)++y;); DO(wr-wf-h, if(*d++)++z;); + *pp=x; *qq=y; *rr=z; + MC(c,b,wf); memset(c+wf,y?C1:C0,r); MC(c+wf+r,b+wf+h,wr-wf-h); + R ifb(zr,c); +} + +A jtfrombsn(J jt,A ind,A w,I wf){A a,j1,p,q,x,x1,y,y1,ys,z;C*xu,*xuu,*xv; + I an,c,d,h,i,*iv,j,*jv,k,m,n,pp,*pv,qq,*qv,r,rr,s,*u,*v,wr,*ws,xk,*yu,*yv;P*wp,*zp; + RZ(ind&&w); /* need to handle 1==n */ + wr=AR(w); ws=AS(w); + r=AR(ind)-1; v=AS(ind); h=v[r]; n=AN(ind)/h; + RZ(q=odom(2L,r,v)); iv=AV(q)-r; + GA(z,AT(w),1,wr+r-h,0); u=AS(z); ICPY(u,ws,wf); ICPY(u+wf,v,r); ICPY(u+wf+r,ws+wf+h,wr-wf-h); + zp=PAV(z); wp=PAV(w); + SPB(zp,e,ca(SPA(wp,e))); x=SPA(wp,x); y=SPA(wp,i); + a=SPA(wp,a); an=AN(a); SPB(zp,a,aaxis(w,wf,a,r,h,&pp,&qq,&rr)); + if( !qq){SPB(zp,i,ca(y)); SPB(zp,x,frombu(ind,x,AR(x)-(wr-wf-rr))); R z;} + if(h>qq){q=nub(over(a,apv(h,wf,1L))); R frombsn(ind,reaxis(grade2(q,q),w),wf);} + if(1<r)RZ(ind=reshape(v2(n,h),ind)); + RZ(ys=fromr(indexof(a,apv(h,wf,1L)),y)); + RZ(q=eps(ys,ind)); + if(!all1(q)){RZ(ys=repeat(q,ys)); RZ(y=repeat(q,y)); RZ(x=repeat(q,x));} + if(wf){q=grade1(ys); RZ(ys=ifrom(q,ys)); RZ(y=ifrom(q,y)); RZ(x=ifrom(q,x));} + m=*AS(y); + GA(p,INT,m,1,0); pv=AV(p); + GA(q,INT,m,1,0); qv=AV(q); + s=0; j=-1; u=AV(ys); v=u+h; + DO(m-1, if(ICMP(u,v,h)){pv[s]=1+j; qv[s++]=i-j; j=i;} u=v; v+=h;); if(m){pv[s]=1+j; qv[s++]=m-1-j;} + RZ(j1=indexof(ifrom(vec(INT,s,pv),ys),ind)); jv=AV(j1); + c=0; DO(n, if(s>jv[i])c+=qv[jv[i]];); + i=aii(x); j=AN(SPA(zp,a)); xk=i*bp(AT(x)); + GA(y1,INT, c*j,2, 0 ); v=AS(y1); v[0]=c; v[1]=j; yv= AV(y1); yu= AV(y); + GA(x1,AT(x),c*i,AR(x),AS(x)); *AS(x1)=c; xv=CAV(x1); xu=CAV(x); + for(i=0;i<n;++i){ + k=jv[i]; iv+=r; + if(s>k){ + c=pv[k]; d=qv[k]; xuu=xu+c*xk; u=yu+c*an; + for(j=0;j<d;++j){ + MC(xv,xuu,xk); xv+=xk; xuu+=xk; + DO(pp, *yv++=*u++;); DO(r, *yv++=iv[i];); u+=qq; DO(rr, *yv++=*u++;); + }}} + if(wf){q=grade1(y1); RZ(y1=ifrom(q,y1)); RZ(x1=ifrom(q,x1));} + SPB(zp,i,y1); SPB(zp,x,x1); + R z; +} /* (<"1 ind){w, sparse w and integer array ind */ + +static A jtfrombs1(J jt,A ind,A w,I wf){A*iv,x,y,z;I id,j,m,n,old,wr,wcr; + RZ(ind&&w); + if(!(BOX&AT(ind))){ASSERT(!AN(ind)||NUMERIC&AT(ind),EVINDEX); RZ(ind=every(ind,0L,jtright1));} + n=AN(ind); iv=AAV(ind); id=(I)ind*ARELATIVE(ind); wr=AR(w); wcr=wr-wf; + ASSERT(1>=AR(ind),EVRANK); + ASSERT(n<=wr-wf,EVLENGTH); + j=n; DO(n, --j; x=AADR(id,iv[j]); if(BOX&AT(x)&&!AR(x)&&(y=AAV0(x),!AN(y)&&1==AR(y)))--n; else break;); + z=w; old=jt->tbase+jt->ttop; + for(j=0;j<n;++j){ + x=AADR(id,iv[j]); + if(BOX&AT(x)){ + ASSERT(!AR(x),EVINDEX); + x=AAV0(x); m=*(wf+j+AS(w)); + if(!AN(x))continue; + RZ(x=less(IX(m),pind(m,x))); + } + RZ(z=irs2(x,z,0L,RMAX,wcr-j,jtfromis)); gc(z,old); + } + R z; +} /* (<ind){"r w, sparse w */ + +F2(jtfrombs){A ind;I acr,af,ar,wcr,wf,wr; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + ASSERT(!af,EVNONCE); + if(ar){RE(aindex(a,w,wf,&ind)); ASSERT(ind,EVNONCE); R frombsn(ind,w,wf);} + else R frombs1(AAV0(a),w,wf); +} /* a{"r w for boxed a and sparse w */ + +F2(jtfromsd){A e,x,z;I acr,af,ar,*v,wcr,wf,wr,*ws;P*ap,*zp; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(af)R sprank2(a,w,0L,acr,wcr,jtfrom); + ASSERT(AT(w)&B01+INT+FL+CMPX,EVNONCE); + ap=PAV(a); ws=AS(w); + GA(z,STYPE(AT(w)),1L,ar+wr-(0<wcr),ws); zp=PAV(z); + v=AS(z); ICPY(v+wf,AS(a),ar); if(wcr)ICPY(v+wf+ar,1+wf+ws,wcr-1); + RZ(x=irs2(SPA(ap,e),w,0L,0L,wcr,jtifrom)); RZ(e=reshape(mtv,x)); + ASSERT(all1(eq(e,x)),EVSPARSE); + SPB(zp,e,e); + SPB(zp,a,wf?plus(sc(wf),SPA(ap,a)):SPA(ap,a)); + SPB(zp,i,SPA(ap,i)); + if(wf){ + RZ(x=irs2(SPA(ap,x),w,0L,RMAX,wcr,jtifrom)); + RZ(x=cant2(less(IX(AR(x)),sc(wf)),x)); + SPB(zp,x,x); + }else SPB(zp,x,ifrom(SPA(ap,x),w)); + R z; +} /* a{"r w, sparse a, dense w */ + +F2(jtfromss){A e,x,y,z;B*b;I acr,af,ar,c,d,k,m,n,p,*u,*v,wcr,wf,wr,*ws,*yv;P*ap,*wp,*xp,*zp; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(af)R sprank2(a,w,0L,acr,wcr,jtfrom); + ASSERT(DTYPE(AT(w))&B01+INT+FL+CMPX,EVNONCE); + ap=PAV(a); wp=PAV(w); ws=AS(w); + GA(z,AT(w),1L,ar+wr-(0<wcr),ws); zp=PAV(z); + v=AS(z); ICPY(v+wf,AS(a),ar); if(wcr)ICPY(v+wf+ar,1+wf+ws,wcr-1); + RZ(x=irs2(SPA(ap,e),w,0L,0L,wcr,jtfrom)); RZ(e=reshape(mtv,x)); + ASSERT(all1(denseit(eq(e,x))),EVSPARSE); + SPB(zp,e,e); + x=SPA(ap,a); if(ar>AN(x)){RZ(a=reaxis(IX(ar),a)); ap=PAV(a);} + x=SPA(wp,a); n=AN(x); RZ(b=bfi(wr,x,1)); + if(wcr&&!b[wf]){b[wf]=1; ++n; RZ(w=reaxis(ifb(wr,b),w)); wp=PAV(w);} + GA(x,INT,ar+n-!!wcr,1,0); v=AV(x); + DO(wf, if(b[i])*v++=i;); DO(ar, *v++=wf+i;); DO(wcr-1, if(b[i+wf+1])*v++=wf+ar+i;); + SPB(zp,a,x); + RZ(x=irs2(SPA(ap,x),w,0L,RMAX,wcr,jtfrom)); xp=PAV(x); + y=SPA(xp,i); u=AV(y); c=*(1+AS(y)); m=*AS(y); k=0; DO(wf, if(b[i])++k;); + y=SPA(ap,i); v=AV(y); d=*(1+AS(y)); n=c+d-1; p=c-(1+k); + GA(y,INT,m*n,2,0); *AS(y)=m; *(1+AS(y))=n; yv=AV(y); + DO(m, if(k)ICPY(yv,u,k); ICPY(yv+k,v+d*u[k],d); if(p)ICPY(yv+k+d,u+1+k,p); yv+=n; u+=c;); + SPB(zp,i,y); + SPB(zp,x,SPA(xp,x)); + R z; +} /* a{"r w, sparse a, sparse w */
new file mode 100644 --- /dev/null +++ b/vg.c @@ -0,0 +1,372 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Grades */ + +#include "j.h" +#include "vg.h" + + +/************************************************************************/ +/* */ +/* merge sort with special code for n<:5 */ +/* */ +/************************************************************************/ + +static void jtmsmerge(J jt,I n,I*u,I*v){I m,q,*x,*xx,*y,*yy,*z;int c; + q=n/2; z=v; + x=u; xx=u+q-1; + y=u+q; yy=u+n-1; + while(1){ + c=CALL1(jt->comp,*x,*y); + if(0<c){*z++=*y++; if(y>yy){m=z-v; z=u+m; DO(1+xx-x, *z++=*x++;); DO(m, *u++=*v++;); break;}} + else {*z++=*x++; if(x>xx){m=z-v; DO(m, *u++=*v++;); break;}} +}} + +#define VS(i,j) (0<CALL1(jt->comp,u[i],u[j])) +#define XC(i,j) {q=u[i]; u[i]=u[j]; u[j]=q;} +#define P3(i,j,k) {ui=u[i]; uj=u[j]; uk=u[k]; u[0]=ui; u[1]=uj; u[2]=uk;} +#define P5(i,j,k,l,m) {ui=u[i]; uj=u[j]; uk=u[k]; ul=u[l]; um=u[m]; \ + u[0]=ui; u[1]=uj; u[2]=uk; u[3]=ul; u[4]=um;} + +void jtmsort(J jt,I n,I*u,I*v){I a,b,c,d,q,ui,uj,uk,ul,um; + switch(n){ + case 2: + if(VS(0,1))XC(0,1); + break; + case 3: + if(VS(0,1))XC(0,1); + if(VS(1,2))if(VS(0,2))P3(2,0,1) else XC(1,2); + break; + case 4: + if(VS(0,1))XC(0,1); + if(VS(2,3))XC(2,3); + if(VS(1,3)){XC(0,2); XC(1,3);} + if(VS(1,2))if(VS(0,2))P3(2,0,1) else XC(1,2); + break; + case 5: + if(VS(0,1))XC(0,1); + if(VS(2,3))XC(2,3); + if(VS(1,3)){XC(0,2); XC(1,3);} + if(VS(4,1))if(VS(4,3)){a=0; b=1; c=3; d=4;}else{a=0; b=1; c=4; d=3;} + else if(VS(4,0)){a=0; b=4; c=1; d=3;}else{a=4; b=0; c=1; d=3;} + if(VS(2,b)){if(3!=c)if(VS(2,c))P5(a,b,c,2,d) else P5(a,b,2,c,d);} + else { if(VS(2,a))P5(a,2,b,c,d) else P5(2,a,b,c,d);} + break; + default: + if(5<n){ + q=n/2; + msort(q, u, v); + msort(n-q,u+q,v); + msmerge(n,u,v); +}}} + + +#define GF(f) B f(J jt,I m,I c,I n,A w,I*zv) + +/* m - # cells (# individual grades to do) */ +/* c - # atoms in a cell */ +/* n - length of sort axis */ +/* w - array to be graded */ +/* zv - result values */ + +static GF(jtgrx){A x;I ck,d,t,*xv; + t=AT(w); ck=c*bp(t); + jt->compk=ck/n; d=c/n; jt->compn=d; jt->compv=CAV(w); jt->compw=w; + switch(t){ + case BOX: jt->comp=ARELATIVE(w)?compr:compa; break; + case C2T: jt->comp=compu; break; + case INT: jt->comp=c==n?compi1:compi; break; + case FL: jt->comp=c==n?compd1:compd; break; + case CMPX: jt->comp=compd; jt->compn=2*d; break; + case XNUM: jt->comp=compx; break; + case RAT: jt->comp=compq; break; + default: jt->comp=compc; + } + GA(x,INT,n,1,0); xv=AV(x); /* work area for msmerge() */ + DO(m, DO(n, zv[i]=i;); msort(n,zv,xv); jt->compv+=ck; zv+=n;); + R !jt->jerr; +} /* grade"r w on general w */ + +/* grcol: grade/sort a halfword of an integer or a double */ +/* d: # of possible different halfwords (65536 or 32768) */ +/* c: smallest halfword value (0 or 32768) */ +/* yv: halfword buckets work area */ +/* n: # of sort elements */ +/* xv: input permutation of sort elements */ +/* zv: output permutation */ +/* m: # of halfwords in a sort element (2 or 4) */ +/* u: ptr to sort elements */ +/* up: 1 if sort up; 0 if sort down */ +/* split: 1 iff do split pass of halfword range */ +/* sort: 1 if sort; 0 if grade */ + +void grcol(I d,I c,I*yv,I n,I*xv,I*zv,const I m,US*u,int up,int split,int sort){ + D*xx,*zz;I k,s,*t;US*v; + s=0; memset(c+yv,C0,d*SZI); + v=u; + DO(n, ++yv[*v]; v+=m;); + switch(up+2*split){ + case 0: t=yv+c+d; DO(d, --t; if(k=*t){*t=s; s+=k;}); break; + case 1: t=yv+c-1; DO(d, ++t; if(k=*t){*t=s; s+=k;}); break; + case 2: t=yv+c+d/2; DO(d/2, --t; if(k=*t){*t=s; s+=k;}); + t=yv+c+d ; DO(d/2, --t; if(k=*t){*t=s; s+=k;}); break; + case 3: t=yv+c+d/2-1; DO(d/2, ++t; if(k=*t){*t=s; s+=k;}); + t=yv+c -1; DO(d/2, ++t; if(k=*t){*t=s; s+=k;}); + } + v=u; + if(sort){ + if(2==m) DO(n, zv[yv[*v ]++]=xv[i]; v+=m;) + else {zz=(D*)zv; xx=(D*)xv; DO(n, zz[yv[*v ]++]=xx[i]; v+=m;);} + }else if(!xv) DO(n, zv[yv[*v ]++]= i ; v+=m;) + else DO(n, zv[yv[v[m*xv[i]]]++]=xv[i]; ); +} + +static GF(jtgrd){A x,y;B b;D*v,*wv;I d,e,*g,*h,i,k,p,q,*xv,*yv;int up;US*u; + if(!(c==n&&n>65536/3.5))R grx(m,c,n,w,zv); + p=65536; q=p/2; up=1==jt->compgt; wv=DAV(w); + GA(y,INT,p,1,0); yv=AV(y); + GA(x,INT,n,1,0); xv=AV(x); +#if SYS & SYS_LILENDIAN + d= 1; e=0; +#else + d=-1; e=3; +#endif + for(i=0;i<m;++i){ + u=e+(US*)wv; + v=wv; k=0; DO(n, if(0>*v++)++k;); b=0<k&&k<n; + g=b?xv:zv; h=b?zv:xv; + grcol(p, 0L, yv,n,0L,h,sizeof(D)/sizeof(US),u+0*d,k==n?!up:up,0,0); + grcol(p, 0L, yv,n,h, g,sizeof(D)/sizeof(US),u+1*d,k==n?!up:up,0,0); + grcol(p, 0L, yv,n,g, h,sizeof(D)/sizeof(US),u+2*d,k==n?!up:up,0,0); + grcol(b?p:q,k==n?q:0,yv,n,h, g,sizeof(D)/sizeof(US),u+3*d,k==n?!up:up,0,0); + if(b){D d;I j,m,*u,*v,*vv; + if(up){ICPY(k+zv, xv,n-k); u=zv; v=n+xv;} + else {ICPY( zv,k+xv,n-k); u=zv+n-k; v=k+xv;} + j=0; d=wv[*(v-1)]; + DO(1+k, --v; if(d!=wv[*v]){vv=1+v; m=i-j; DO(m, *u++=*vv++;); j=i; d=wv[*v];}); + } + wv+=c; zv+=n; + } + R 1; +} /* grade"r w on real w; main code here is for c==n */ + +static GF(jtgri1){A x,y;I*wv;I d,e,i,p,*xv,*yv;int up;US*u; + p=65536; up=1==jt->compgt; wv=AV(w); + GA(y,INT,p,1,0); yv=AV(y); + GA(x,INT,n,1,0); xv=AV(x); + e=SY_64?3:1; +#if SYS & SYS_LILENDIAN + d= 1; +#else + d=-1; +#endif + for(i=0;i<m;++i){ + u=e*(-1==d)+(US*)wv; + grcol(p,0L,yv,n,0L,xv,sizeof(I)/sizeof(US),u, up,0,0); +#if SY_64 + grcol(p,0L,yv,n,xv,zv,sizeof(I)/sizeof(US),u+1*d,up,0,0); + grcol(p,0L,yv,n,zv,xv,sizeof(I)/sizeof(US),u+2*d,up,0,0); +#endif + grcol(p,0L,yv,n,xv,zv,sizeof(I)/sizeof(US),u+e*d,up,1,0); + wv+=c; zv+=n; + } + R 1; +} /* grade"r w on integer w where c==n */ + +void irange(I n,I*v,I*base,I*top){I d,i,m=n/2,p,q,x,y; + if(n>m+m)p=q=*v++; else if(n){q=IMAX; p=IMIN;}else p=q=0; + for(i=0;i<m;++i){ + x=*v++; y=*v++; + if(x<y){if(x<q)q=x; if(p<y)p=y;} + else {if(y<q)q=y; if(p<x)p=x;} + } + *base=q; d=p-q; *top=0>d||d==IMAX?0:1+d; +} /* min and max in 1.5*n comparisons */ + +F1(jtmaxmin){I base,top; + RZ(w); + ASSERT(INT&AT(w),EVDOMAIN); + irange(AN(w),AV(w),&base,&top); + R v2(base,base+top-1); +} + +static GF(jtgri){A x,y;B b,up;I d,e,*g,*h,i,j,k,p,ps,q,s,*v,*wv,*xv,*yv; + wv=AV(w); d=c/n; k=4*n; + irange(AN(w),wv,&q,&p); + if(!p||k<p||(0.69*d*(p+2*n))>n*log((D)n))R c==n&&n>65536/1.5?gri1(m,c,n,w,zv):grx(m,c,n,w,zv); + if(0<q&&q<k-p){p+=q; q=0;} + GA(y,INT,p,1,0); yv=AV(y); ps=p*SZI; up=1==jt->compgt; + if(1<d){GA(x,INT,n,1,0); xv=AV(x);} + for(i=0;i<m;++i){ + s=0; j=p; memset(yv,C0,ps); + v=wv+d-1; + if(q) DO(n, ++yv[*v-q]; v+=d;) + else DO(n, ++yv[*v ]; v+=d;); + if(up)DO(p, if(k=yv[i]){yv[i]=s; s+=k;}) + else DO(p, --j; if(k=yv[j]){yv[j]=s; s+=k;}); + v=wv+d-1; + if(q) DO(n, zv[yv[*v-q]++]=i; v+=d;) + else DO(n, zv[yv[*v ]++]=i; v+=d;); + v=wv+d-1; + for(e=d-2,b=0;0<=e;--e){ + --v; + if(b){g=xv; h=zv; b=0;}else{g=zv; h=xv; b=1;} + s=0; j=p; memset(yv,C0,ps); + if(q) DO(n, ++yv[*(v+d*g[i])-q];) + else DO(n, ++yv[*(v+d*g[i]) ];); + if(up)DO(p, if(k=yv[i]){yv[i]=s; s+=k;}) + else DO(p, --j; if(k=yv[j]){yv[j]=s; s+=k;}); + if(q) DO(n, h[yv[*(v+d*g[i])-q]++]=g[i];) + else DO(n, h[yv[*(v+d*g[i]) ]++]=g[i];); + } + if(b)DO(n, zv[i]=xv[i];); + wv+=c; zv+=n; + } + R 1; +} /* grade"r w on small-range integers w */ + + +#define DOCOL1(p,iicalc0,iicalc1,ind,vinc) \ + {I*g,*h, j=p-1,k,s=0;UC*v; \ + if(b){g=xv; h=zv; b=0;}else{g=zv; h=xv; b=1;} \ + memset(yv,C0,ps); \ + v=vv; DO(n, ++yv[iicalc0]; v+=d;); \ + if(up)DO(p, k=yv[i]; yv[i ]=s; s+=k;) \ + else DO(p, k=yv[j]; yv[j--]=s; s+=k;); \ + v=vv; DO(n, h[yv[iicalc1]++]=ind; vinc;); \ + } + +#define DOCOL4(p,iicalc0,iicalc1,ind,vinc) \ + {I*g,*h,ii,j=p-1,k,s=0;UC*v; \ + if(b){g=xv; h=zv; b=0;}else{g=zv; h=xv; b=1;} \ + memset(yv,C0,ps); \ + v=vv; DO(n, IND4(iicalc0); ++yv[ii]; v+=d;); \ + if(up)DO(p, k=yv[i]; yv[i ]=s; s+=k;) \ + else DO(p, k=yv[j]; yv[j--]=s; s+=k;); \ + v=vv; DO(n, IND4(iicalc1); h[yv[ii]++]=ind; vinc;); \ + } + +static GF(jtgrb){A x;B b,up;I d,i,p,ps,q,*xv,yv[16];UC*vv,*wv; + if(c>4*n*log((D)n))R grx(m,c,n,w,zv); + d=c/n; q=d/4; p=16; ps=p*SZI; wv=UAV(w); up=1==jt->compgt; + if(1<q){GA(x,INT,n,1,0); xv=AV(x);} + for(i=0;i<m;++i){ + vv=wv+d; b=1&&q%2; + if(q){ vv-=4; DOCOL4(p, *(int*)v, *(int*)v, i, v+=d);} + DO(q-1, vv-=4; DOCOL4(p, *(int*)v, *(int*)(v+d*g[i]),g[i],v );); + wv+=c; zv+=n; + } + R 1; +} /* grade"r w on boolean w, works 4 columns at a time (d%4 guaranteed to be 0)*/ + +static GF(jtgrc){A x;B b,q,up;I d,e,i,p,ps,*xv,yv[256];UC*vv,*wv; + d=C2T&AT(w)?2*c/n:c/n; + if(d>log((D)n))R grx(m,c,n,w,zv); + p=B01&AT(w)?2:256; ps=p*SZI; wv=UAV(w); up=1==jt->compgt; + q=C2T&AT(w) && SYS&SYS_LILENDIAN; + if(1<d){GA(x,INT,n,1,0); xv=AV(x);} + for(i=0;i<m;++i){ + b=(B)(d%2); if(q){e=-3; vv=wv+d-2;}else{e=-1; vv=wv+d-1;} + DOCOL1(p,*v,*v, i, v+=d); if(q)e=1==e?-3:1; + DO(d-1, vv+=e; DOCOL1(p,*v,v[d*g[i]],g[i],v ); if(q)e=1==e?-3:1;); + wv+=d*n; zv+=n; + } + R 1; +} /* grade"r w on boolean or char or unicode w */ + +static GF(jtgrs){R gri(m,c,n,sborder(w),zv);} + /* grade"r w on symbols w */ + +F2(jtgrade1p){PROLOG;A x,z;I n,*s,*xv,*zv; + s=AS(w); n=s[0]; jt->compn=s[1]-1; jt->compk=SZI*s[1]; + jt->comp=compp; jt->compsyv=AV(a); jt->compv=CAV(w); + GA(z,INT,n,1,0); zv=AV(z); DO(n, zv[i]=i;); + GA(x,INT,n,1,0); xv=AV(x); + msort(n,zv,xv); + EPILOG(z); +} /* /:(}:a){"1 w , permutation a, integer matrix w */ + + +/************************************************************************/ +/* */ +/* /: and \: main control */ +/* */ +/************************************************************************/ + +F1(jtgr1){PROLOG;A z;I c,f,m,n,r,*s,t,wr,zn; + RZ(w); + t=AT(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; jt->rank=0; + f=wr-r; s=AS(w); m=prod(f,s); c=m?AN(w)/m:prod(r,f+s); n=r?s[f]:1; + RE(zn=mult(m,n)); GA(z,INT,zn,1+f,s); if(!r)*(AS(z)+f)=1; + if(!c||1>=n)R reshape(shape(z),IX(n)); + if (t&B01&&0==(c/n)%4)RZ(grb(m,c,n,w,AV(z))) + else if(t&SBT )RZ(grs(m,c,n,w,AV(z))) + else if(t&FL )RZ(grd(m,c,n,w,AV(z))) + else if(t&INT )RZ(gri(m,c,n,w,AV(z))) + else if(t&IS1BYTE+C2T )RZ(grc(m,c,n,w,AV(z))) + else RZ(grx(m,c,n,w,AV(z))); + EPILOG(z); +} /* grade"r w main control for dense w */ + +#define GBEGIN(G,L) A z;int ogt=jt->compgt,olt=jt->complt; jt->compgt=G; jt->complt=L +#define GEND(z) jt->compgt=ogt; jt->complt=olt; R z + +F1(jtgrade1 ){GBEGIN( 1,-1); RZ( w); z=SPARSE&AT(w)?grd1sp( w):gr1( w); GEND(z);} +F1(jtdgrade1){GBEGIN(-1, 1); RZ( w); z=SPARSE&AT(w)?grd1sp( w):gr1( w); GEND(z);} +F2(jtgrade2 ){GBEGIN( 1,-1); RZ(a&&w); z=SPARSE&AT(w)?grd2sp(a,w):gr2(a,w); GEND(z);} +F2(jtdgrade2){GBEGIN(-1, 1); RZ(a&&w); z=SPARSE&AT(w)?grd2sp(a,w):gr2(a,w); GEND(z);} + + +#define OSGT(i,j) (u[i]>u[j]) + +#define SORT4 \ + switch(n){ \ + case 2: \ + if(OSGT(0,1))XC(0,1); break; \ + case 3: \ + if(OSGT(0,1))XC(0,1); \ + if(OSGT(1,2))if(OSGT(0,2))P3(2,0,1) else XC(1,2); break; \ + case 4: \ + if(OSGT(0,1))XC(0,1); \ + if(OSGT(2,3))XC(2,3); \ + if(OSGT(1,3)){XC(0,2); XC(1,3);} \ + if(OSGT(1,2))if(OSGT(0,2))P3(2,0,1) else XC(1,2); \ + } + +#define OSLOOP(T,ATOMF) \ +{T p0,p1,q,*tv,*u,ui,uj,uk,*v,*wv; \ + tv=wv=(T*)AV(w); \ + while(1){ \ + if(4>=n){u=tv; SORT4; R ATOMF(tv[j]);} \ + p0=tv[qv[i]%n]; ++i; if(i==qn)i=0; \ + p1=tv[qv[i]%n]; ++i; if(i==qn)i=0; if(p0>p1){q=p0; p0=p1; p1=q;} \ + if(p0==p1){m0=m1=0; v=tv; DO(n, if(p0>*v)++m0; ++v;);} \ + else {m0=m1=0; v=tv; DO(n, if(p0>*v)++m0; else if(p1>*v)++m1; ++v;);} \ + c=m0+m1; m=j<m0?m0:j<c?m1:n-c; \ + if(t)u=v=tv; else{GA(t,wt,m,1,0); u=tv=(T*)AV(t); v=wv;} \ + if (j<m0){ DO(n, if(*v<p0 )*u++=*v; ++v;); n=m;} \ + else if(j<c ){j-=m0; DO(n, if(p0<=*v&&*v<p1)*u++=*v; ++v;); n=m;} \ + else if(c ){j-=c; DO(n, if(p1<=*v )*u++=*v; ++v;); n=m;} \ + else{DO(n, if(p1<*v)*u++=*v; ++v;); m=u-tv; c=n-m; if(j<c)R ATOMF(p1); j-=c; n=m;} \ + }} + +F2(jtordstat){A q,t=0;I c,i=0,j,m,m0,m1,n,qn=53,*qv,wt; + RZ(a&&w); + n=AN(w); wt=AT(w); + if(!(!AR(a)&&AT(a)&B01+INT&&4<n&&1==AR(w)&&wt&FL+INT))R from(a,grade2(w,w)); + RE(j=i0(a)); if(0>j)j+=n; + ASSERT(0<=j&&j<n,EVINDEX); + RZ(q=df2(sc(qn),sc(IMAX),atop(ds(CQUERY),ds(CDOLLAR)))); qv=AV(q); + if(wt&FL)OSLOOP(D,scf) else OSLOOP(I,sc); +} /* a{/:~w */ + +F2(jtordstati){A t;I j,n,wt; + RZ(a&&w); + n=AN(w); wt=AT(w); + if(!(!AR(a)&&AT(a)&B01+INT&&4<n&&1==AR(w)&&wt&FL+INT))R from(a,grade1(w)); + RZ(t=ordstat(a,w)); + if(wt&FL){D p=*DAV(t),*v=DAV(w); DO(n, if(p==*v++){j=i; break;});} + else {I p=* AV(t),*v= AV(w); DO(n, if(p==*v++){j=i; break;});} + R sc(j); +} /* a {/:w */
new file mode 100644 --- /dev/null +++ b/vg.h @@ -0,0 +1,56 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Grades */ + + +extern F1(jtgr1); +extern F2(jtgr2); +extern F1(jtgrd1sp); +extern F2(jtgrd2sp); + +extern int compa(J,I,I); +extern int compc(J,I,I); +extern int compd(J,I,I); +extern int compd1(J,I,I); +extern int compi(J,I,I); +extern int compi1(J,I,I); +extern int compp(J,I,I); +extern int compq(J,I,I); +extern int compr(J,I,I); +extern int compu(J,I,I); +extern int compx(J,I,I); + +extern int compspdsB(J,I,I); +extern int compspdsD(J,I,I); +extern int compspdsI(J,I,I); +extern int compspdsZ(J,I,I); + +extern int compspssB(J,I,I); +extern int compspssD(J,I,I); +extern int compspssI(J,I,I); +extern int compspssZ(J,I,I); + +extern void grcol(I,I,I*,I,I*,I*,const I,US*,int,int,int); + +extern void jtmsort(J,I,I*,I*); + +#define IND2(x) \ + switch(x){ \ + case BS00: ii=0; break; \ + case BS01: ii=1; break; \ + case BS10: ii=2; break; \ + case BS11: ii=3; \ + } + +#define IND4(x) \ + switch(x){ \ + case B0000: ii=0; break; case B1000: ii= 8; break; \ + case B0001: ii=1; break; case B1001: ii= 9; break; \ + case B0010: ii=2; break; case B1010: ii=10; break; \ + case B0011: ii=3; break; case B1011: ii=11; break; \ + case B0100: ii=4; break; case B1100: ii=12; break; \ + case B0101: ii=5; break; case B1101: ii=13; break; \ + case B0110: ii=6; break; case B1110: ii=14; break; \ + case B0111: ii=7; break; case B1111: ii=15; \ + }
new file mode 100644 --- /dev/null +++ b/vgauss.c @@ -0,0 +1,113 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Gaussian Elimination */ + +#include "j.h" + + +F1(jtgausselm){A t;C*tv;I c,e,i,j,m,old,r,r1,*s;Q p,*u,*v,*x; + F1RANK(2,jtgausselm,0); + ASSERT(RAT&AT(w),EVNONCE); + ASSERT(2==AR(w),EVRANK); + s=AS(w); r=s[0]; c=s[1]; r1=MIN(r,c); v=QAV(w); m=c*bp(AT(w)); + GA(t,LIT,m,1,0); tv=CAV(t); + old=jt->tbase+jt->ttop; + for(j=0;j<r1;++j){ + e=-1; u=v+c*j+j; DO(r-j, if(XDIG(u->n)){e=i+j; break;} u+=c;); /* find pivot row */ + ASSERT(0<=e,EVDOMAIN); + x=v+c*j; + if(j!=e){u=v+c*e; MC(tv,x,m); MC(x,u,m); MC(u,tv,m);} /* interchange rows e and j */ + p=x[j]; DO(c, x[i]=qdiv(x[i],p);); + for(i=0;i<r;++i){ + if(i==j)continue; + u=v+c*i; p=u[j]; /* pivot */ + DO(c, u[i]=qminus(u[i],qtymes(p,x[i]));); + } + gc(w,old); + } + R w; +} /* Gaussian elimination in place */ + +static F1(jtdetr){A t,z;C*tv;I c,e,g=1,i,j,k,m,old,r,*s;Q d,p,*u,*v,*x; + RZ(w); + s=AS(w); r=s[0]; c=s[1]; + v=QAV(w); + m=c*sizeof(Q); GA(t,LIT,m,1,0); tv=CAV(t); + old=jt->tbase+jt->ttop; + for(j=0;j<r;++j){ + e=-1; u=v+c*j+j; DO(r-j, if(XDIG(u->n)){e=i+j; break;} u+=c;); /* find pivot row */ + if(0>e)R cvt(RAT,zero); + x=v+c*j; + if(j!=e){u=v+c*e; MC(tv,x,m); MC(x,u,m); MC(u,tv,m); g=-g;} /* interchange rows e and j */ + i=XDIG(x[j].n); if(i==XPINF||i==XNINF)R mark; + for(i=j+1;i<r;++i){ + u=v+c*i; + if(XDIG(u[j].n)){p=qdiv(u[j],x[j]); for(k=j+1;k<r;++k)u[k]=qminus(u[k],qtymes(p,x[k]));} + } + gc(w,old); + } + d=0<g?*v:qminus(zeroQ,*v); u=v+1+c; DO(r-1, d=qtymes(d,*u); u+=1+c;); + RE(0); + GA(z,RAT,1,0,0); *QAV(z)=d; R z; +} /* determinant on rational matrix; works in place */ + +static F1(jtdetd){D g,h,p,q,*u,*v,*x,*y,z=1.0;I c,d,e,i,j,k,r,*s; + RZ(w); + s=AS(w); r=s[0]; c=s[1]; v=DAV(w); + NAN0; + for(j=0;j<r;++j){ + x=v+c*j; u=x+j; h=0.0; + DO(r-j, k=i; DO(c-j, g=ABS(*u); if(h<g){h=g; d=j+k; e=j+i;} ++u;); u+=j;); /* find pivot, maximum abs element */ + if(h==inf)R mark; + if(0==h)R scf(0.0); + if(j!=d){u=v+c*d+j; y=x+j; DO(c-j, q=*u; *u=*y; *y=q; ++u; ++y; ); z=-z;} /* interchange rows j and d */ + if(j!=e){u=x+e; y=x+j; DO(r-j, q=*u; *u=*y; *y=q; u+=c; y+=c;); z=-z;} /* interchange cols j and e */ + q=x[j]; z*=q; JBREAK0; + for(i=j+1;i<r;++i){ + u=v+c*i; + if(u[j]){p=u[j]/q; for(k=j+1;k<r;++k)u[k]-=p*x[k];} + }} + NAN1; + R scf(z); +} /* determinant on real matrix; works in place */ + +#define ZABT(v) ((v).re*(v).re+(v).im*(v).im) + +static F1(jtdetz){A t;D g,h;I c,d,e,i,j,k,r,*s;Z p,q,*u,*v,*x,*y,z; + RZ(w); + z.re=1.0; z.im=0.0; + s=AS(w); r=s[0]; c=s[1]; v=ZAV(w); + NAN0; + for(j=0;j<r;++j){ + x=v+c*j; u=x+j; h=0.0; + DO(r-j, k=i; DO(c-j, g=ZABT(*u); if(h<g){h=g; d=j+k; e=j+i;} ++u;); u+=j;); /* find pivot, maximum abs element */ + if(h==inf)R mark; + if(0==h)R scf(0.0); + if(j!=d){u=v+c*d; DO(c-j, q=u[j+i]; u[j+i]=x[j+i]; x[j+i]=q;); z=zminus(zeroZ,z);} /* interchange rows j and d */ + if(j!=e){u=v+c*j+e; y=v+c*j+j; DO(r-j, q=*u; *u=*y; *y=q; u+=c; y+=c;); z=zminus(zeroZ,z);} /* interchange cols j and e */ + q=x[j]; z=ztymes(z,q); + for(i=j+1;i<r;++i){ + u=v+c*i; + if(ZNZ(u[j])){p=zdiv(u[j],q); for(k=j+1;k<r;++k)u[k]=zminus(u[k],ztymes(p,x[k]));} + }} + NAN1; RE(0); + GA(t,CMPX,1,0,0); *ZAV(t)=z; R t; +} /* determinant on complex matrix; works in place */ + +F1(jtgaussdet){A z;I*s; + RZ(w); + ASSERT(2==AR(w),EVRANK); + s=AS(w); + ASSERT(s[0]==s[1],EVLENGTH); + switch(AT(w)){ + default: ASSERT(0,EVDOMAIN); + case B01: + case INT: R detd(cvt(FL,w)); + case FL: z=detd(ca(w)); break; + case CMPX: z=detz(ca(w)); break; + case XNUM: z=detr(cvt(RAT,w)); break; + case RAT: z=detr(ca(w)); + } + R z==mark?detxm(w,eval("-/ .*")):z; +} /* determinant on square matrix */
new file mode 100644 --- /dev/null +++ b/vgcomp.c @@ -0,0 +1,132 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Grade -- Compare */ +/* the result of a CF comparison fn is 1 if (a{w)>(b{w), -1 otherwise */ + +#include "j.h" +#include "vg.h" + + +#define CF(f) int f(J jt,I a,I b) + +#define COMPDCLP(T) T*x=(T*)(jt->compv+a*jt->compk),*y=(T*)(jt->compv+b*jt->compk) +#define COMPDCLQ(T) T*x=(T*)av,*y=(T*)wv +#define COMPLOOP(T,m) {COMPDCLP(T); DO(m, if(x[i]>y[i])R jt->compgt; else if(x[i]<y[i])R jt->complt;);} +#define COMPLOOQ(T,m) {COMPDCLQ(T); DO(m, if(x[i]>y[i])R jt->compgt; else if(x[i]<y[i])R jt->complt;);} +#define COMPLOOPF(T,m,f) {COMPDCLP(T);int j; DO(m, if(j=f(x[i],y[i]))R j;);} +#define COMPLOOPR(T,m,f) {COMPDCLP(T);int j; DO(m, if(j=f((A)AABS(x[i],jt->compw),(A)AABS(y[i],jt->compw)))R j;);} +#define COMPLOOPG(T,m,f) {COMPDCLP(T);int j; DO(m, if(j=f(x[i],y[i]))R 0<j?jt->compgt:jt->complt;);} +#define COMPLOOQG(T,m,f) {COMPDCLQ(T);int j; DO(m, if(j=f(x[i],y[i]))R 0<j?jt->compgt:jt->complt;);} + +CF(compc){COMPLOOP (UC,jt->compn); R a>b?1:-1;} +CF(compu){COMPLOOP (US,jt->compn); R a>b?1:-1;} +CF(compi){COMPLOOP (I, jt->compn); R a>b?1:-1;} +CF(compd){COMPLOOP (D, jt->compn); R a>b?1:-1;} +CF(compa){COMPLOOPF(A, jt->compn,compare ); R a>b?1:-1;} +CF(compr){COMPLOOPR(A1,jt->compn,compare ); R a>b?1:-1;} +CF(compx){COMPLOOPG(X, jt->compn,xcompare); R a>b?1:-1;} +CF(compq){COMPLOOPG(Q, jt->compn,QCOMP ); R a>b?1:-1;} + +CF(compi1){I p=*(a+(I*)jt->compv),q=*(b+(I*)jt->compv); R p>q?jt->compgt:p<q?jt->complt:a>b?1:-1;} +CF(compd1){D p=*(a+(D*)jt->compv),q=*(b+(D*)jt->compv); R p>q?jt->compgt:p<q?jt->complt:a>b?1:-1;} + +CF(compp){COMPDCLP(I);I*cv=jt->compsyv,xi,yi; + DO(jt->compn, xi=x[cv[i]]; yi=y[cv[i]]; if(xi>yi)R 1; else if(xi<yi)R -1;); + R a>b?1:-1; +} + +int jtcompare(J jt,A a,A w){C*av,*wv;I ar,an,*as,at,c,d,j,m,t,wn,wr,*ws,wt; + RZ(a&&w); + an=AN(a); at=an?AT(a):B01; ar=AR(a); as=AS(a); + wn=AN(w); wt=wn?AT(w):B01; wr=AR(w); ws=AS(w); RE(t=maxtype(at,wt)); + if(!HOMO(at,wt))R at&BOX?jt->compgt:wt&BOX?jt->complt:at&JCHAR?jt->compgt:wt&JCHAR?jt->complt: + at&SBT?jt->compgt:jt->complt; + if(ar!=wr)R ar>wr?jt->compgt:jt->complt; + if(1<ar&&ICMP(1+as,1+ws,ar)){A s;I*v; + GA(s,INT,ar,1,0); v=AV(s); + DO(ar, v[i]=MAX(as[i],ws[i]);); v[0]=MIN(as[0],ws[0]); + RZ(a=take(s,a)); an=wn=AN(a); + RZ(w=take(s,w)); + } + m=MIN(an,wn); + if(t&XNUM+RAT&&(at&FL+CMPX||wt&FL+CMPX)){A p,q;B*u,*v; + RZ(p=lt(a,w)); u=BAV(p); + RZ(q=gt(a,w)); v=BAV(q); + DO(m, if(u[i])R jt->complt; else if(v[i])R jt->compgt;); + }else{ + if(t!=at)RZ(a=cvt(t,a)); + if(t!=wt)RZ(w=cvt(t,w)); + av=CAV(a); wv=CAV(w); + switch(t){ + default: COMPLOOQ (UC,m ); break; + case C2T: COMPLOOQ (US,m ); break; + case INT: COMPLOOQ (I, m ); break; + case FL: COMPLOOQ (D, m ); break; + case CMPX: COMPLOOQ (D, m+m); break; + case XNUM: COMPLOOQG(X, m, xcompare); break; + case RAT: COMPLOOQG(Q, m, QCOMP ); break; + case BOX: switch(2*ARELATIVE(a)+ARELATIVE(w)){ + case 0: {COMPDCLQ(A);int j; DO(m, if(j=compare( x[i], y[i] ))R j;);} break; + case 1: {COMPDCLQ(A);int j; DO(m, if(j=compare( x[i], (A)AABS(y[i],w)))R j;);} break; + case 2: {COMPDCLQ(A);int j; DO(m, if(j=compare((A)AABS(x[i],a), y[i] ))R j;);} break; + case 3: {COMPDCLQ(A);int j; DO(m, if(j=compare((A)AABS(x[i],a),(A)AABS(y[i],w)))R j;);} break; + }}} + if(1>=ar)R an>wn?jt->compgt:an<wn?jt->complt:0; + DO(j=ar, --j; c=as[j]; d=ws[j]; if(c>d)R jt->compgt; else if (c<d)R jt->complt;); + R 0; +} /* compare 2 arbitrary dense arrays; _1 0 1 per a<w, a=w, a>w */ + + +#define COMPSPSS(f,T,e1init,esel) \ + CF(f){I c,ia,ib,na,nb,p,*tv,wf,xc,*ya,*yb,yc,*yv;int gt=jt->compgt,lt=jt->complt;T e,e1,*xa,*xb,*xv; \ + e=*(T*)jt->compsev; e1=e1init; \ + wf=jt->compswf; tv=jt->compstv; \ + yv=jt->compsyv+wf+1; yc=jt->compsyc; p=yc-1-wf; \ + xv=(T*)jt->compsxv; xc=jt->compsxc; \ + ia=tv[a]; na=tv[1+a]; xa=xv+xc*ia; \ + ib=tv[b]; nb=tv[1+b]; xb=xv+xc*ib; \ + while(1){ \ + switch((ia<na?2:0)+(ib<nb)){ \ + case 0: R a>b?1:-1; \ + case 1: c= 1; break; \ + case 2: c=-1; break; \ + case 3: c= 0; ya=yv+yc*ia; yb=yv+yc*ib; DO(p, if(c=ya[i]-yb[i]){c=0>c?-1:1; break;}); \ + } \ + switch(c){ \ + case -1: DO(xc, if(xa[i] <(esel))R lt; else if(xa[i] >(esel))R gt;); xa+=xc; ++ia; break; \ + case 1: DO(xc, if((esel)<xb[i] )R lt; else if((esel)>xb[i] )R gt;); xb+=xc; ++ib; break; \ + case 0: DO(xc, if(xa[i] <xb[i] )R lt; else if(xa[i] >xb[i] )R gt;); xa+=xc; ++ia; xb+=xc; ++ib; \ + }}} + +#define COMPSPDS(f,T,e1init,esel) \ + CF(f){I c,ia,ib,n,na,nb,p,*tv,xc,*ya,*yb,yc,*yv;int gt=jt->compgt,lt=jt->complt;T e,e1,*xa,*xb,*xv; \ + tv=jt->compstv; \ + e=*(T*)jt->compsev; e1=e1init; \ + tv=jt->compstv; n=jt->compn; \ + yv=jt->compsyv+1; yc=jt->compsyc; p=yc-1; \ + xv=n*jt->compsi+(T*)jt->compsxv; xc=jt->compsxc; \ + ia=tv[a]; na=tv[1+a]; xa=xv+xc*ia; \ + ib=tv[b]; nb=tv[1+b]; xb=xv+xc*ib; \ + while(1){ \ + switch((ia<na?2:0)+(ib<nb)){ \ + case 0: R a>b?1:-1; \ + case 1: c= 1; break; \ + case 2: c=-1; break; \ + case 3: c= 0; ya=yv+yc*ia; yb=yv+yc*ib; DO(p, if(c=ya[i]-yb[i]){c=0>c?-1:1; break;}); \ + } \ + switch(c){ \ + case -1: DO(n, if(xa[i] <(esel))R lt; else if(xa[i] >(esel))R gt;); xa+=xc; ++ia; break; \ + case 1: DO(n, if((esel)<xb[i] )R lt; else if((esel)>xb[i] )R gt;); xb+=xc; ++ib; break; \ + case 0: DO(n, if(xa[i] <xb[i] )R lt; else if(xa[i] >xb[i] )R gt;); xa+=xc; ++ia; xb+=xc; ++ib; \ + }}} + +COMPSPDS(compspdsB,B,0, e ) +COMPSPDS(compspdsI,I,0, e ) +COMPSPDS(compspdsD,D,0, e ) +COMPSPDS(compspdsZ,D,*(1+(D*)jt->compsev),i%2?e1:e) + +COMPSPSS(compspssB,B,0, e ) +COMPSPSS(compspssI,I,0, e ) +COMPSPSS(compspssD,D,0, e ) +COMPSPSS(compspssZ,D,*(1+(D*)jt->compsev),i%2?e1:e)
new file mode 100644 --- /dev/null +++ b/vgranking.c @@ -0,0 +1,121 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Grade -- monad /:@/:"r on dense arguments */ + +#include "j.h" +#include "vg.h" + + +#define RANKINGSUMSCAN \ + {I s,*u; s=0; u=yv; DO(p, if(*u){t=*u; *u=s; s+=t;} ++u;);} +#define RANKINGLOOP(T) \ + {T*v=(T*)wv; DO(n, ++yu[*v++];); RANKINGSUMSCAN; v=(T*)wv; DO(n, *zv++=yu[*v++]++;);} + +static A jtrankingb(J jt,A w,I wf,I wcr,I m,I n,I k){A z;C*wv;I i,j,p,t,yv[16],*zv; + p=2==k?4:16; wv=CAV(w); + GA(z,INT,m*n,1+wf,AS(w)); if(!wcr)*(AS(z)+wf)=1; zv=AV(z); + if(2==k){US*v; + for(i=0;i<m;++i){ + memset(yv,C0,p*SZI); + for(j=0,v=(US*)wv;j<n;++j)switch(*v++){ + case BS00: ++yv[0]; break; + case BS01: ++yv[1]; break; + case BS10: ++yv[2]; break; + case BS11: ++yv[3]; break; + } + RANKINGSUMSCAN; + for(j=0,v=(US*)wv;j<n;++j)switch(*v++){ + case BS00: *zv++=yv[0]++; break; + case BS01: *zv++=yv[1]++; break; + case BS10: *zv++=yv[2]++; break; + case BS11: *zv++=yv[3]++; break; + } + wv+=n*k; + }}else{int*v; + for(i=0;i<m;++i){ + memset(yv,C0,p*SZI); + for(j=0,v=(int*)wv;j<n;++j)switch(*v++){ + case B0000: ++yv[ 0]; break; + case B0001: ++yv[ 1]; break; + case B0010: ++yv[ 2]; break; + case B0011: ++yv[ 3]; break; + case B0100: ++yv[ 4]; break; + case B0101: ++yv[ 5]; break; + case B0110: ++yv[ 6]; break; + case B0111: ++yv[ 7]; break; + case B1000: ++yv[ 8]; break; + case B1001: ++yv[ 9]; break; + case B1010: ++yv[10]; break; + case B1011: ++yv[11]; break; + case B1100: ++yv[12]; break; + case B1101: ++yv[13]; break; + case B1110: ++yv[14]; break; + case B1111: ++yv[15]; break; + } + RANKINGSUMSCAN; + for(j=0,v=(int*)wv;j<n;++j)switch(*v++){ + case B0000: *zv++=yv[ 0]++; break; + case B0001: *zv++=yv[ 1]++; break; + case B0010: *zv++=yv[ 2]++; break; + case B0011: *zv++=yv[ 3]++; break; + case B0100: *zv++=yv[ 4]++; break; + case B0101: *zv++=yv[ 5]++; break; + case B0110: *zv++=yv[ 6]++; break; + case B0111: *zv++=yv[ 7]++; break; + case B1000: *zv++=yv[ 8]++; break; + case B1001: *zv++=yv[ 9]++; break; + case B1010: *zv++=yv[10]++; break; + case B1011: *zv++=yv[11]++; break; + case B1100: *zv++=yv[12]++; break; + case B1101: *zv++=yv[13]++; break; + case B1110: *zv++=yv[14]++; break; + case B1111: *zv++=yv[15]++; break; + } + wv+=n*k; + }} + R z; +} /* /:@/: w where w is boolean and items have length 2 or 4 */ + +F1(jtranking){A y,z;C*wv;I i,k,m,n,p=0,q=0,t,wcr,wf,wk,wr,*ws,wt,*yu,*yv,*zv; + RZ(w); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + wt=AT(w); wv=CAV(w); + ws=AS(w); n=wcr?ws[wf]:1; RE(m=prod(wf,ws)); + if(!AN(w))R m?reitem(vec(INT,wf,ws),iota(v2(1L,n))):reshape(vec(INT,1+wf,ws),zero); + wk=bp(wt); k=wk*(wcr?prod(wcr-1,ws+wf+1):1); + if(wt&B01&&(k==2||k==sizeof(int)))R rankingb(w,wf,wcr,m,n,k); + else switch(k){ + case 1: p=wt&B01?2:256; break; + case 2: p=65536; break; + case sizeof(int): + if(wt&INT){irange(AN(w)/(k/wk),(I*)wv,&q,&p); if(!(65536>p||0.69*(p+2*n)<n*log((D)n)))p=0;} + } + if(!p){ + RZ(y=irs1(w,0L,wcr,jtgrade1)); yv=AV(y); + GA(z,INT,m*n,1+wf,ws); if(!wcr)*(AS(z)+wf)=1; zv=AV(z); + DO(m, DO(n, zv[*yv++]=i;); zv+=n;); + R z; + } + GA(z,INT,m*n,1+wf,ws); if(!wcr)*(AS(z)+wf)=1; zv=AV(z); + GA(y,INT,p,1,0); yv=AV(y); yu=yv-q; + for(i=0;i<m;++i){ + memset(yv,C0,p*SZI); + switch(k){ + case sizeof(int): RANKINGLOOP(int); break; + case sizeof(C): RANKINGLOOP(UC); break; +#if SYS & SYS_LILENDIAN + case sizeof(S): + if(wt&IS1BYTE){I c,d,s,t,*u;US*v; + v=(US*)wv; DO(n, ++yu[*v++];); + s=0; DO(256, c=0; d=i; DO(256, u=yv+(c+d); c+=256; if(*u){t=*u; *u=s; s+=t;});); + v=(US*)wv; DO(n, *zv++=yu[*v++]++;); + }else RANKINGLOOP(US); +#else + case sizeof(S): RANKINGLOOP(US); +#endif + } + wv+=n*k; + } + R z; +}
new file mode 100644 --- /dev/null +++ b/vgsort.c @@ -0,0 +1,178 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Grade -- dyad /: and \: where a==w */ + +#include "j.h" +#include "vg.h" + + +#define SF(f) A f(J jt,I m,I c,I n,A w) + +/* m - # cells (# individual grades to do) */ +/* c - # atoms in a cell */ +/* n - length of sort axis */ +/* w - array to be graded */ + +static SF(jtsortb){A z;B up,*u,*v;I i,s; + GA(z,AT(w),AN(w),AR(w),AS(w)); v=BAV(z); + up=1==jt->compgt; u=BAV(w); + for(i=0;i<m;++i){ + s=bsum(n,u); + if(up){memset(v,C0,n-s); memset(v+n-s,C1,s );} + else {memset(v,C1,s ); memset(v+s, C0,n-s);} + u+=n; v+=n; + } + R z; +} /* w grade"1 w on boolean */ + +static SF(jtsortb2){A z;B up;I i,ii,j,p,yv[4];US*v,*wv,x,zz[4]; + GA(z,AT(w),AN(w),AR(w),AS(w)); v=(US*)AV(z); + wv=(US*)AV(w); p=4; up=1==jt->compgt; + DO(p, yv[i]=0;); + zz[0]=BS00; zz[1]=BS01; zz[2]=BS10; zz[3]=BS11; + for(i=0;i<m;++i){ + DO(n, IND2(*wv++); ++yv[ii];); + if(up){j=0; DO(p, x=zz[j]; DO(yv[j], *v++=x;); yv[j]=0; ++j;);} + else {j=p-1; DO(p, x=zz[j]; DO(yv[j], *v++=x;); yv[j]=0; --j;);} + } + R z; +} /* w grade"r w on 2-byte boolean items */ + +static SF(jtsortb4){A z;B up;I i,ii,j,p,yv[16];UINT*v,*wv,x,zz[16]; + GA(z,AT(w),AN(w),AR(w),AS(w)); v=(UINT*)AV(z); + wv=(UINT*)AV(w); p=16; up=1==jt->compgt; + DO(p, yv[i]=0;); + zz[ 0]=B0000; zz[ 1]=B0001; zz[ 2]=B0010; zz[ 3]=B0011; + zz[ 4]=B0100; zz[ 5]=B0101; zz[ 6]=B0110; zz[ 7]=B0111; + zz[ 8]=B1000; zz[ 9]=B1001; zz[10]=B1010; zz[11]=B1011; + zz[12]=B1100; zz[13]=B1101; zz[14]=B1110; zz[15]=B1111; + for(i=0;i<m;++i){ + DO(n, IND4(*wv++); ++yv[ii];); + if(up){j=0; DO(p, x=zz[j]; DO(yv[j], *v++=x;); yv[j]=0; ++j;);} + else {j=p-1; DO(p, x=zz[j]; DO(yv[j], *v++=x;); yv[j]=0; --j;);} + } + R z; +} /* w grade"r w on 4-byte boolean items */ + +static SF(jtsortc){A z;B up;I i,p,yv[256];UC j,*wv,*v; + GA(z,AT(w),AN(w),AR(w),AS(w)); v=UAV(z); + wv=UAV(w); p=LIT&AT(w)?256:2; up=1==jt->compgt; + DO(p, yv[i]=0;); + for(i=0;i<m;++i){ + DO(n, ++yv[*wv++];); + if(up){j=0; DO(p, DO(yv[j], *v++=j;); yv[j]=0; ++j;);} + else {j=(UC)(p-1); DO(p, DO(yv[j], *v++=j;); yv[j]=0; --j;);} + } + R z; +} /* w grade"1 w on boolean or character */ + +static SF(jtsortc2){A y,z;B up;I i,p,*yv;US j,k,*wv,*v; + GA(z,AT(w),AN(w),AR(w),AS(w)); v=(US*)AV(z); + wv=(US*)AV(w); p=65536; up=1==jt->compgt; + GA(y,INT,p,1,0); yv=AV(y); + DO(p, yv[i]=0;); + for(i=0;i<m;++i){ + DO(n, ++yv[*wv++];); + if(C2T&AT(w)||!liln){ + if(up){j=0; DO(p, DO(yv[j], *v++=j;); yv[j]=0; ++j;);} + else {j=(US)(p-1); DO(p, DO(yv[j], *v++=j;); yv[j]=0; --j;);} + }else{ + if(up){k=0; DO(256, j=k; DO(256, DO(yv[j], *v++=j;); yv[j]=0; j+=256;); ++k;);} + else {k=(US)(p-1); DO(256, j=k; DO(256, DO(yv[j], *v++=j;); yv[j]=0; j-=256;); --k;);} + }} + R z; +} /* w grade"1 w on 2-byte character or unicode items */ + + +static SF(jtsorti1); + +static SF(jtsorti){A y,z;B up;D p1;I i,j,p,ps,q,s,*wv,*yv,*zv; + wv=AV(w); + irange(AN(w),wv,&q,&p); p1=(D)p; + if(!p||256<p&&0.69*(p1+2*n)>n*log((D)n))R 3000<n?sorti1(m,n,n,w):irs2(gr1(w),w,0L,1L,1L,jtfrom); + if(0<q&&p1+q<4*n){p+=q; q=0;} + GA(y,INT,p,1,0); yv=AV(y); ps=p*SZI; up=1==jt->compgt; + GA(z,AT(w),AN(w),AR(w),AS(w)); zv=AV(z); + memset(yv,C0,ps); + for(i=0;i<m;++i){ + if(q)DO(n, ++yv[*wv++-q];) + else DO(n, ++yv[*wv++ ];); + switch(2*up+(1&&q)){ + case 0: j=p-1; DO(p, s=yv[j]; yv[j]=0; DO(s, *zv++=j ;); --j;); break; + case 1: j=p-1; DO(p, s=yv[j]; yv[j]=0; DO(s, *zv++=j+q;); --j;); break; + case 2: j=0; DO(p, s=yv[j]; yv[j]=0; DO(s, *zv++=j ;); ++j;); break; + case 3: j=0; DO(p, s=yv[j]; yv[j]=0; DO(s, *zv++=j+q;); ++j;); break; + }} + R z; +} /* w grade"1 w on small-range integers */ + +static SF(jtsorti1){A x,y,z;I*wv;I d,e,i,p,q,*xv,*yv,*zv;int up; + GA(z,AT(w),AN(w),AR(w),AS(w)); zv=AV(z); + p=65536; up=1==jt->compgt; wv=AV(w); + GA(y,INT,p,1,0); yv=AV(y); + GA(x,INT,n,1,0); xv=AV(x); + e=SY_64?3:1; +#if SYS & SYS_LILENDIAN + d= 1; +#else + d=-1; +#endif + q=e*(-1==d); + for(i=0;i<m;++i){ + grcol(p,0L,yv,n,wv,xv,sizeof(I)/sizeof(US), q+(US*)wv,up,0,1); +#if SY_64 + grcol(p,0L,yv,n,xv,zv,sizeof(I)/sizeof(US),1*d+q+(US*)xv,up,0,1); + grcol(p,0L,yv,n,zv,xv,sizeof(I)/sizeof(US),2*d+q+(US*)zv,up,0,1); +#endif + grcol(p,0L,yv,n,xv,zv,sizeof(I)/sizeof(US),e*d+q+(US*)xv,up,1,1); + wv+=c; zv+=n; + } + R z; +} /* w grade"r w on large-range integers */ + +static SF(jtsortd){A x,y,z;B b;D*g,*h,*xu,*wv,*zu;I d,e,i,k,p,q,*yv;int up; + if(n<8000)R irs2(gr1(w),w,0L,1L,1L,jtfrom); + GA(z,AT(w),AN(w),AR(w),AS(w)); + p=65536; q=p/2; up=1==jt->compgt; wv=DAV(w); zu=DAV(z); + GA(y,INT,p,1,0); yv=AV(y); + GA(x,FL, n,1,0); xu=DAV(x); +#if SYS & SYS_LILENDIAN + d= 1; e=0; +#else + d=-1; e=3; +#endif + for(i=0;i<m;++i){ + g=wv; k=0; DO(n, if(0>*g++)++k;); b=0<k&&k<n; + g=b?xu:zu; h=b?zu:xu; + grcol(p, 0L, yv,n,(I*)wv,(I*)h,sizeof(D)/sizeof(US),e+0*d+(US*)wv,k==n?!up:up,0,1); + grcol(p, 0L, yv,n,(I*)h, (I*)g,sizeof(D)/sizeof(US),e+1*d+(US*)h ,k==n?!up:up,0,1); + grcol(p, 0L, yv,n,(I*)g, (I*)h,sizeof(D)/sizeof(US),e+2*d+(US*)g ,k==n?!up:up,0,1); + grcol(b?p:q,k==n?q:0,yv,n,(I*)h, (I*)g,sizeof(D)/sizeof(US),e+3*d+(US*)h ,k==n?!up:up,0,1); + if(b){ + g=zu; + if(up){h=n+xu; DO(k, *g++=*--h;); h= xu; DO(n-k, *g++=*h++;);} + else {h=k+xu; DO(n-k, *g++=*h++;); h=k+xu; DO(k, *g++=*--h;);} + } + wv+=c; zu+=n; + } + R z; +} /* w grade"1 w on real w */ + +F2(jtgr2){PROLOG;A z=0;I acr,d,f,m,n,*s,t,wcr; + RZ(a&&w); + acr=jt->rank?jt->rank[0]:AR(a); + wcr=jt->rank?jt->rank[1]:AR(w); t=AT(w); + f=AR(w)-wcr; s=AS(w); m=prod(f,s); n=s[f]; d=bp(t)*prod(wcr-1,1+f+s); + if(a==w&&acr==wcr){ + if (1==d &&t&B01&&0==n%SZI) RZ(z=sortb (m,n,n,w)) + else if(1==d) RZ(z=sortc (m,n,n,w)) + else if(2==d &&t&B01) RZ(z=sortb2(m,n,n,w)) + else if(2==d &&t&LIT+C2T&&30000<n)RZ(z=sortc2(m,n,n,w)) + else if(4==d &&t&B01) RZ(z=sortb4(m,n,n,w)) + else if(1==wcr&&t&INT) RZ(z=sorti (m,n,n,w)) + else if(1==wcr&&t&FL ) RZ(z=sortd (m,n,n,w)); + } + if(!z)RZ(z=irs2(gr1(w),a,0L,1L,acr,jtfrom)); + EPILOG(z); +} /* a grade"r w main control for dense w */
new file mode 100644 --- /dev/null +++ b/vgsp.c @@ -0,0 +1,245 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Grades on Sparse Arrays */ + +#include "j.h" +#include "vg.h" + + +/************************************************************************/ +/* */ +/* monad /: and \: on sparse right arguments */ +/* */ +/************************************************************************/ + +static B jtspsscell(J jt,A w,I wf,I wcr,A*zc,A*zt){A c,t,y;B b; + I cn,*cv,j,k,m,n,p,*s,tn,*tv,*u,*u0,*v,*v0;P*wp; + wp=PAV(w); s=AS(w); p=3+s[wf]; + y=SPA(wp,i); s=AS(y); m=s[0]; n=s[1]; + u0=AV(y); u=u0+n; + v0=u0+wf; v=v0+n; + if(!m){*zt=*zc=mtv; R 1;} + GA(t,INT,2+2*m,1,0); tv=AV(t); tv[0]=tv[1]=0; tn=2; + GA(c,INT, 2*m,2,0); cv=AV(c); cv[0]=0; cn=0; *(1+AS(c))=2; + for(j=1;j<m;++j){ + b=1; + for(k=0;k<wf;++k) + if(u0[k]!=u[k]){ + tv[tn++]=j; tv[tn++]=j; cv[1+cn]=tn-cv[cn]; + if(p==tn-cv[cn]){++cv[cn]; cv[1+cn]-=2;} + cn+=2; + cv[cn]=tn-2; u0=u; v0=v; b=0; + break; + } + if(b&&*v0!=*v){tv[tn++]=j; v0=v;} + u+=n; v+=n; + } + tv[tn++]=m; tv[tn++]=m; cv[1+cn]=tn-cv[cn]; + if(p==tn-cv[cn]){++cv[cn]; cv[1+cn]-=2;} + cn+=2; + AN(t)= *AS(t)=tn; *zt=t; /* cell divisions (row indices in y) */ + AN(c)=cn; *AS(c)=cn/2; *zc=c; /* item divisions (indices in t, # of elements) */ + R 1; +} /* frame: all sparse; cell: 1 or more sparse, then dense */ + +static A jtgrd1spz(J jt,A w,I wf,I wcr){A z;I*ws,zn; + ws=AS(w); + RE(zn=prod(wf+!!wcr,ws)); + GA(z,INT,zn,1+wf,ws); if(!wcr)*(AS(z)+wf)=1; + R z; +} /* allocate result for grd1sp__ */ + +static void sp1merge0(I n,I n1,I yc,I*zv,I*xv,I*yv,I*tv){I c,d=n1-1,h,i,j,k,p,q,*v=zv; + DO(n1, if(0==xv[i]){j=i; break;}); /* lower limit for zero items */ + DO(n1, if(d==xv[i]){k=i; break;}); /* upper limit for zero items */ + DO(j, *v++=yv[yc*tv[xv[i]]];); /* items less than zero */ + p=1+j; c=k>p?yv[yc*tv[xv[p]]]:-1; + q=1; h= yv[yc*tv[q ]] ; /* merge indexed zero items ... */ + for(i=0;i<n;++i) /* ... with omitted zero items */ + if(h==i){++q; if(d==q)break; h=yv[yc*tv[q]];} + else{while(k>p&&i>c){*v++=c; ++p; c=k>p?yv[yc*tv[xv[p]]]:-1;} *v++=i;} + DO(k-p, *v++=yv[yc*tv[xv[p+ i]]];); /* rest of indexed zero items */ + DO(n-h-1, *v++=h+1+i;); /* rest of omitted zero items */ + DO(d-k, *v++=yv[yc*tv[xv[k+1+i]]];); /* items greater than zero */ +} /* merge grade result xv with omitted zero items into zv */ + +#define ADVANCE(dv) {I j=wf; while(++dv[--j],dv[j]==ws[j])dv[j]=0;} + +static A jtgrd1spss(J jt,A w,I wf,I wcr){A c,d,t,x,y,z;I cn,*cv,*dv,i,n,n1,*tv,*u,*ws,wt,*xv,yc,*yv,*zv;P*wp; + wp=PAV(w); wt=AT(w); ws=AS(w); n=wcr?ws[wf]:1; + RZ(z=grd1spz(w,wf,wcr)); zv=AV(z); + x=SPA(wp,e); jt->compsev=CAV(x); + y=SPA(wp,i); jt->compsyv=yv=AV(y); jt->compsyc=yc=*(1+AS(y)); + x=SPA(wp,x); jt->compsxv=CAV(x); jt->compsxc=aii(x)*(wt&SCMPX?2:1); + jt->compw=w; jt->compswf=wf; jt->comp=wt&SB01?compspssB:wt&SINT?compspssI:wt&SFL?compspssD:compspssZ; + RZ(spsscell(w,wf,wcr,&c,&t)); + tv=AV(t); cv=AV(c); cn=AN(c); + GA(x,INT,2+n,1,0); xv=AV(x); /* work area for msmerge() */ + RZ(d=apv(wf,0L,0L)); dv=AV(d); /* odometer for frame */ + for(i=0;i<cn;i+=2){ + jt->compstv=u=tv+cv[i]; n1=cv[1+i]-1; + while(ICMP(dv,yv+yc**u,wf)){DO(n, zv[i]=i;); zv+=n; ADVANCE(dv);} + if(u[0]<u[1]){DO(n1, zv[i]=i;); msort(n1,zv,xv);} + else {DO(n1, xv[i]=i;); msort(n1,xv,zv); sp1merge0(n,n1,yc,zv,xv,yv+wf,u);} + zv+=n; ADVANCE(dv); + } + DO(AN(z)/n-(zv-AV(z))/n, DO(n, zv[i]=i;); zv+=n;); + RE(0); + R z; +} /* grade"r w , sparse frame, sparse cell */ + +static A jtgrd1spsd(J jt,A w,I wf,I wcr){A d,t,y,z;I*dv,i,n,p,*tv,yc,*ws,*ys,*yv,*zv;P*wp; + wp=PAV(w); ws=AS(w); n=wcr?ws[wf]:1; + RZ(z=grd1spz(w,wf,wcr)); zv=AV(z); + RZ(t=irs1(SPA(wp,x),0L,wcr,jtgr1)); tv=AV(t); /* grade dense cells */ + RZ(d=apv(wf,0L,0L)); dv=AV(d); /* odometer for frame */ + y=SPA(wp,i); ys=AS(y); p=ys[0]; yc=ys[1]; yv=AV(y); + for(i=0;i<p;++i){ /* now merge dense & sparse cells */ + while(ICMP(dv,yv,wf)){DO(n, zv[i]=i;); zv+=n; ADVANCE(dv);} + DO(n, zv[i]=tv[i];); + yv+=yc; tv+=n; zv+=n; ADVANCE(dv); + } + DO(AN(z)/n-(zv-AV(z))/n, DO(n, zv[i]=i;); zv+=n;); + R z; +} /* grade"r w , sparse frame, dense cell */ + +static B jtspdscell(J jt,A w,I wf,I wcr,A*zc,A*zt){A c,t,y;I*cv,m,n,p,*s,tn,*tv,*v,*v0;P*wp; + wp=PAV(w); s=AS(w); p=3+s[wf]; + y=SPA(wp,i); s=AS(y); m=s[0]; n=s[1]; + v0=AV(y); v=v0+n; + if(!m){*zt=*zc=mtv; R 1;} + GA(t,INT,2+m,1,0); tv=AV(t); tv[0]=tv[1]=0; tn=2; + GA(c,INT,2, 2,0); cv=AV(c); cv[0]=0; *(1+AS(c))=2; + DO(m-1, if(*v0!=*v){tv[tn++]=1+i; v0=v;} v+=n;); + tv[tn++]=m; tv[tn++]=m; cv[1]=tn; + if(p==tn){++cv[0]; cv[1]-=2;} + AN(t)= *AS(t)=tn; *zt=t; /* cell divisions (row indices in y) */ + AN(c)=2; *AS(c)=1; *zc=c; /* item divisions (indices in t, # of elements) */ + R 1; +} /* frame: all dense; cell: 1 or more sparse, then dense */ + +static A jtgrd1spds(J jt,A w,I wf,I wcr){A c,t,x,y,z;I*cv,m,n,n1,p,*tv,*ws,wt,*xv,yc,*yv,*zv;P*wp; + wp=PAV(w); wt=AT(w); ws=AS(w); n=wcr?ws[wf]:1; RE(m=prod(wf,ws)); + RZ(z=grd1spz(w,wf,wcr)); zv=AV(z); + x=SPA(wp,e); jt->compsev=CAV(x); + y=SPA(wp,i); jt->compsyv=yv=AV(y); jt->compsyc=yc=*(1+AS(y)); + x=SPA(wp,x); jt->compsxv=CAV(x); jt->compsxc=p=aii(x)*(wt&SCMPX?2:1); jt->compn=p/m; + jt->comp=wt&SB01?compspdsB:wt&SINT?compspdsI:wt&SFL?compspdsD:compspdsZ; + RZ(spdscell(w,wf,wcr,&c,&t)); + if(!AN(c)){DO(m, DO(n, zv[i]=i;); zv+=n;); R z;} + cv=AV(c); n1=cv[1]-1; jt->compstv=tv=cv[0]+AV(t); + GA(x,INT,MAX(n,1+n1),1,0); xv=AV(x); /* work area for msmerge() */ + if(cv[0])DO(m, jt->compsi=i; DO(n1, zv[i]=i;); msort(n1,zv,xv); zv+=n;) + else DO(m, jt->compsi=i; DO(n1, xv[i]=i;); msort(n1,xv,zv); sp1merge0(n,n1,yc,zv,xv,yv,tv); zv+=n;); + R z; +} /* grade"r w , dense frame, sparse cell */ + +static A jtgrd1spdd(J jt,A w,I wf,I wcr){A x;I n,*ws;P*wp; + wp=PAV(w); ws=AS(w); n=wcr?ws[wf]:1; + x=SPA(wp,x); + R AN(x)?irs1(from(num[0],x),0L,wcr,jtgr1):reshape(vec(INT,1+wf,ws),apv(n,0L,1L)); +} /* grade"r w , dense frame, dense cell */ + +/* sparse right argument: */ +/* frame axes: all sparse or all dense */ +/* cell axes: 0 or more sparse axes, then dense axes */ + +F1(jtgrd1sp){PROLOG;A z;B b,c,*wb;I j,m,wcr,wf,wr;P*wp; + RZ(w); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + wp=PAV(w); + RZ(wb=bfi(wr,SPA(wp,a),1)); + m=0; j=wr; b=c=0; + DO(wf, if(wb[i])++m;); if(1<=m&&m<wf){c=1; memset(wb,C1,wf);} + DO(wcr, --j; if(wb[j])b=1; else if(b){c=1; wb[j]=1;}); + if(c)RZ(w=reaxis(ifb(wr,wb),w)); + switch(2*wb[0]+wb[wf]){ + case 0: /* dense dense */ z=grd1spdd(w,wf,wcr); break; + case 1: /* dense sparse */ z=grd1spds(w,wf,wcr); break; + case 2: /* sparse dense */ z=grd1spsd(w,wf,wcr); break; + case 3: /* sparse sparse */ z=grd1spss(w,wf,wcr); break; + } + EPILOG(z); +} /* grade"r w for sparse w */ + + +/************************************************************************/ +/* */ +/* dyad /: and \: sparse right arguments */ +/* */ +/************************************************************************/ + +#define SP2RENUM(ix,nx,yx,tx) \ + {I ii,nn=(nx),pp,qq,*tu=(tx),*yu=(yx); \ + for(ii=(ix);ii<nn;++ii,++m){ \ + pp=xv[ii]; qq=yc*(tu[pp]-1); \ + DO(tu[1+pp]-tu[pp], yu[qq+=yc]=m;); \ + }} + +static void sp2merge0(I n,I n1,I yc,I*zyv,I*xv,I*yv,I*tv){I c,d=n1-1,h,i,j,k,m=0,p,q; + DO(n1, if(0==xv[i]){j=i; break;}); /* lower limit for zero items */ + DO(n1, if(d==xv[i]){k=i; break;}); /* upper limit for zero items */ + SP2RENUM(0,j,zyv,tv); /* items less than zero */ + p=1+j; c=k>p?yv[yc*tv[xv[p]]]:-1; + q=1; h= yv[yc*tv[q ]] ; /* merge indexed zero items ... */ + for(i=0;i<n;++i) /* ... with omitted zero items */ + if(h==i){++q; if(d==q)break; h=yv[yc*tv[q]];} + else{while(k>p&&i>c){SP2RENUM(p,1+p,zyv,tv); ++p; c=k>p?yv[yc*tv[xv[p]]]:-1;} ++m;} + SP2RENUM(p, k, zyv,tv); /* rest of indexed zero items */ + m+=n-h-1; /* rest of omitted zero items */ + SP2RENUM(1+k,n1,zyv,tv); /* items greater than zero */ +} /* merge grade result xv with omitted zero items into zv */ + +static A jtgrd2spss(J jt,A w,I wf,I wcr){A c,t,x,y,z,zy; + I cn,*cv,i,j,m,n,n1,*tv,*u,*ws,wt,*xu,*xv,yc,*yv,*zyv;P*wp,*zp; + RZ(z=ca(w)); zp=PAV(z); + wp=PAV(w); wt=AT(w); ws=AS(w); n=wcr?ws[wf]:1; + x=SPA(wp,e); jt->compsev=CAV(x); + y=SPA(wp,i); jt->compsyv=yv=AV(y); jt->compsyc=yc=*(1+AS(y)); + x=SPA(wp,x); jt->compsxv=CAV(x); jt->compsxc=aii(x)*(wt&SCMPX?2:1); + jt->compw=w; jt->compswf=wf; jt->comp=wt&SB01?compspssB:wt&SINT?compspssI:wt&SFL?compspssD:compspssZ; + RZ(spsscell(w,wf,wcr,&c,&t)); + tv=AV(t); cv=AV(c); cn=AN(c); + m=0; j=1; DO(cn, m=MAX(m,cv[j]); j+=2;); + GA(x,INT,m,1,0); xu=AV(x); /* work area for msmerge() */ + GA(x,INT,m,1,0); xv=AV(x); /* work area for msmerge() */ + zy=SPA(zp,i); zyv=AV(zy); + for(i=0;i<cn;i+=2){ + jt->compstv=u=tv+cv[i]; n1=cv[1+i]-1; m=0; + DO(n1, xv[i]=i;); msort(n1,xv,xu); + if(u[0]<u[1])SP2RENUM(0,n1,zyv+wf,u) + else sp2merge0(n,n1,yc,zyv+wf,xv,yv+wf,u); + } + RZ(x=grade1(zy)); SPB(zp,i,from(x,zy)); SPB(zp,x,from(x,SPA(zp,x))); + R z; +} /* sparse frame, sparse cell */ + +static A jtgrd2spsd(J jt,A w,I wf,I wcr){A x,z;P*zp; + RZ(z=ca(w)); zp=PAV(z); + x=SPA(zp,x); + SPB(zp,x,irs2(irs1(x,0L,-1L,jtgr1),x,0L,1L,-1L,jtfrom)); + R z; +} /* sparse frame, dense cell */ + +F2(jtgrd2sp){PROLOG;A z;B b,c,*wb;I acr,af,am,ar,*as,j,m,wcr,wf,wm,wr,*ws;P*wp; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[1]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + as=AS(a); am=acr?as[af]:1; + ws=AS(w); wm=wcr?ws[wf]:1; + ASSERT(am<=wm,EVINDEX); + wp=PAV(w); + RZ(wb=bfi(wr,SPA(wp,a),1)); + m=0; j=wr; b=c=0; + DO(wf, if(wb[i])++m;); if(1<=m&&m<wf){c=1; memset(wb,C1,wf);} + DO(wcr, --j; if(wb[j])b=1; else if(b){c=1; wb[j]=1;}); + if(c){b=a==w; RZ(w=reaxis(ifb(wr,wb),w)); if(b)a=w;} + switch((2*wb[0]+wb[wf])*(a==w&&af==wf&&acr==wcr)){ + default: z=irs2(irs1(w,0L,wcr,jt->compgt==1?jtgrade1:jtdgrade1),a,0L,RMAX,acr,jtfrom); break; + case 2: /* sparse dense */ z=grd2spsd(w,wf,wcr); break; + case 3: /* sparse sparse */ z=grd2spss(w,wf,wcr); break; + } + EPILOG(z); +} /* a grade"r w for sparse w */ +
new file mode 100644 --- /dev/null +++ b/vi.c @@ -0,0 +1,740 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Index-of */ + +#include "j.h" + + +I ptab[]={ + 53, 113, 241, 499, 1013, + 2029, 4079, 8179, 16369, 32749, + 65521, 131059, 262133, 524269, 1048559, + 2097133, 4194287, 8388593, 16777199, 33554393, + 67108837, 134217689, 268435399, 536870879 +}; + +I nptab=sizeof(ptab)/SZI; + +/* Floating point (type D) byte order: */ +/* Archimedes 3 2 1 0 7 6 5 4 */ +/* VAX 1 0 3 2 5 4 7 6 */ +/* little endian 7 6 5 4 3 2 1 0 */ +/* ThinkC MAC universal 0 1 0 1 2 3 4 5 6 7 8 9 */ +/* ThinkC MAC 6888x 0 1 _ _ 2 3 4 5 6 7 8 9 */ +/* normal 0 1 2 3 4 5 6 7 ... */ + +#if SYS & SYS_LILENDIAN +#define MSW 1 /* most significant word */ +#define LSW 0 /* least significant word */ +#else +#define MSW 0 +#define LSW 1 +#endif + +static void ctmask(J jt){DI p,x,y;UINT c,d,e,m,q; + p.d=PI; /* pi itself */ + x.d=PI*(1-jt->ct); /* lower bound */ + y.d=PI/(1-jt->ct); /* upper bound */ + c=p.i[MSW]; d=p.i[LSW]; m=0; + if(c==x.i[MSW]){e=x.i[LSW]; m =(d&~e)|(~d&e);} + if(c==y.i[MSW]){e=y.i[LSW]; m|=(d&~e)|(~d&e);} + q=m; + while(m){m>>=1; q|=m;} /* q=:+./\m as a bit vector */ + jt->ctmask=~(UI)q; +} /* 1 iff significant wrt comparison tolerance */ + + +/* hic: hash a string of length k */ +/* hicx: hash the bytes of string v indicated by hin/hiv */ +/* hic2: hash the low order bytes of a string of length k (k even) */ +/* hicw: hash a word (32 bit or 64 bit depending on CPU) */ + + UI hic ( I k,UC*v){UI z=0; DO(k, z=(i+1000003)**v++ ^z<<1; ); R z;} + +static UI hicnz( I k,UC*v){UI z=0;UC c; DO(k, c=*v++; if(c&&c!=255)z=(i+1000003)*c^z<<1;); R z;} + +static UI hicx(J jt,I k,UC*v){UI z=0;I*u=jt->hiv; DO(jt->hin, z=(i+1000003)*v[*u++]^z<<1; ); R z;} + +#if SYS & SYS_LILENDIAN + UI hic2( I k,UC*v){UI z=0; DO(k/2, z=(i+1000003)**v ^z<<1; v+=2;); R z;} +#else + UI hic2( I k,UC*v){UI z=0; ++v; DO(k/2, z=(i+1000003)**v ^z<<1; v+=2;); R z;} +#endif + +#if SY_64 +#define hicw(v) (10495464745870458733U**(UI*)(v)) +static UI jthid(J jt,D d){R 10495464745870458733U*(jt->ctmask&*(I*)&d);} +#else +#define hicw(v) (2838338383U**(U*)(v)) +static UI jthid(J jt,D d){DI x; x.d=d; R 888888883U*(x.i[LSW]&jt->ctmask)+2838338383U*x.i[MSW];} +#endif + + +static UI jthia(J jt,D hct,A y){UC*yv;D d;I n,t;Q*u; + n=AN(y); t=AT(y); yv=UAV(y); + if(!n||t&BOX)R hic(AR(y)*SZI,(UC*)AS(y)); + switch(t){ + case LIT: R hic(n,yv); + case C2T: R hic2(2*n,yv); + case SBT: R hic(n*SZI,yv); + case B01: d=*(B*)yv; break; + case INT: d=(D)*(I*)yv; break; + case FL: + case CMPX: d=*(D*)yv; break; + case XNUM: d=xdouble(*(X*)yv); break; + case RAT: u=(Q*)yv; d=xdouble(u->n)/xdouble(u->d); + } + R hid(d*hct); +} + +static UI jthiau(J jt,A y){I m,n;UC*v=UAV(y);UI z=2038074751;X*u,x; + m=n=AN(y); + if(!n)R 0; + switch(AT(y)){ + case RAT: m+=n; /* fall thru */ + case XNUM: u=XAV(y); DO(m, x=*u++; v=UAV(x); z+=hicnz(AN(x)*SZI,UAV(x));); R z; + case INT: z =hicnz(n *SZI,UAV(y)); R z; + default: R hic(n*bp(AT(y)),UAV(y)); +}} + +static UI hix(X*v){A y=*v; R hic(AN(y)*SZI,(UC*)AV(y));} +static UI hiq(Q*v){A y=v->n; R hic(AN(y)*SZI,(UC*)AV(y));} + + +static B jteqx(J jt,I n,X*u,X*v){DO(n, if(!equ(*u,*v))R 0; ++u; ++v;); R 1;} +static B jteqq(J jt,I n,Q*u,Q*v){DO(n, if(!QEQ(*u,*v))R 0; ++u; ++v;); R 1;} +static B jteqd(J jt,I n,D*u,D*v){DO(n, if(!teq(*u,*v))R 0; ++u; ++v;); R 1;} +static B jteqz(J jt,I n,Z*u,Z*v){DO(n, if(!zeq(*u,*v))R 0; ++u; ++v;); R 1;} + +static B jteqa(J jt,I n,A*u,A*v,I c,I d){DO(n, if(!equ(AADR(c,*u),AADR(d,*v)))R 0; ++u; ++v;); R 1;} + +/* + mode one of the following: + 0 IIDOT i. a w rank + 1 IICO i: a w rank + 2 INUBSV ~: w rank + 3 INUB ~. w + 4 ILESS -. a w + 5 INUBI I.@~: w + 6 IEPS e. a w rank + 7 II0EPS e.i.0: a w + 8 II1EPS e.i.1: a w + 9 IJ0EPS e.i:0: a w + 10 IJ1EPS e.i:1: a w + 11 ISUMEPS [:+ /e. a w + 12 IANYEPS [:+./e. a w + 13 IALLEPS [:*./e. a w + 14 IIFBEPS I.@e. a w + 30 IPHIDOT i. a w prehashed + 31 IPHICO i: a w prehashed + 34 IPHLESS -. a w prehashed + 36 IPHEPS e. a w prehashed + 37 IPHI0EPS e.i.0: a w prehashed + 38 IPHI1EPS e.i.1: a w prehashed + 39 IPHJ0EPS e.i:0: a w prehashed + 40 IPHJ1EPS e.i:1: a w prehashed + 41 IPHSUMEPS [:+ /e. a w prehashed + 42 IPHANYEPS [:+./e. a w prehashed + 43 IPHALLEPS [:*./e. a w prehashed + 44 IPHIFBEPS I.@e. a w prehashed + m target axis length + n target item # elements + c # target items in a right arg cell + k target item # bytes + acr left rank + wcr right rank + ac # left arg cells + wc # right arg cells + ak # bytes left arg cells, or 0 if only one cell + wk # bytes right arg cells, or 0 if only one cell + a left arg + w right arg, or mark for m&i. or m&i: or e.&n or -.&n + hp pointer to hash table or to 0 + z result +*/ + +#define IOF(f) A f(J jt,I mode,I m,I n,I c,I k,I acr,I wcr,I ac,I wc,I ak,I wk,A a,A w,A*hp,A z) +#define IODECL(T) A h=*hp;B*zb;C*zc;D t1=1.0;I t=sizeof(T),acn=ak/t,cn=k/t,hj,*hv=AV(h),j,l,p=AN(h), \ + wcn=wk/t,*zi,*zv=AV(z);T*av=(T*)AV(a),*v,*wv=(T*)AV(w);UI pm=p +#define FIND(exp) while(m>(hj=hv[j])&&(exp)){++j; if(j==p)j=0;} +#define RDECL I ad=(I)a*ARELATIVE(a),wd=(I)w*ARELATIVE(w) +#define ZISHAPE *AS(z)=AN(z)=zi-zv +#define ZCSHAPE *AS(z)=(zc-(C*)zv)/k; AN(z)=n**AS(z) +#define ZUSHAPE(T) *AS(z)= zu-(T*)zv; AN(z)=n**AS(z) + + +#define XDOA(hash,exp,inc) {d=ad; v=av; DO(m, j=(hash)%pm; FIND(exp); if(m==hj)hv[j]=i; inc;);} +#define XDQA(hash,exp,dec) {d=ad; v=av+cn*(m-1); DQ(m, j=(hash)%pm; FIND(exp); if(m==hj)hv[j]=i; dec;);} +#define XDO(hash,exp,inc,stmt) {d=wd; v=wv; DO(cm, j=(hash)%pm; FIND(exp); stmt; inc;);} +#define XDQ(hash,exp,dec,stmt) {d=wd; v=wv+cn*(c-1); DQ(cm, j=(hash)%pm; FIND(exp); stmt; dec;);} + +#define XMV(hash,exp,inc,stmt) \ + if(k==SZI){XDO(hash,exp,inc,if(m==hj){*zi++=*(I*)v; stmt;}); zc=(C*)zi;} \ + else XDO(hash,exp,inc,if(m==hj){MC(zc,v,k); zc+=k; stmt;}); + +#define IOFX(T,f,hash,exp,inc,dec) \ + IOF(f){RDECL;IODECL(T);B b;I cm,d,md,s;UC*u=0; \ + md=mode<IPHOFFSET?mode:mode-IPHOFFSET; \ + b=a==w&&ac==wc&&(mode==IIDOT||mode==IICO||mode==INUBSV||mode==INUB||mode==INUBI); \ + zb=(B*)zv; zc=(C*)zv; zi=zv; cm=w==mark?0:c; \ + for(l=0;l<ac;++l,av+=acn,wv+=wcn){ \ + if(mode<IPHOFFSET){DO(p,hv[i]=m;); if(!b){if(mode==IICO)XDQA(hash,exp,dec) else XDOA(hash,exp,inc);}} \ + switch(md){ \ + case IIDOT: if(b){ XDO(hash,exp,inc,*zv++=m==hj?(hv[j]=i):hj);} \ + else XDO(hash,exp,inc,*zv++=hj); break; \ + case IICO: if(b){zi=zv+=c; XDQ(hash,exp,dec,*--zi=m==hj?(hv[j]=i):hj);} \ + else XDO(hash,exp,inc,*zv++=hj); break; \ + case INUBSV: XDO(hash,exp,inc,*zb++=m==hj?(hv[j]=i,1):0); break; \ + case INUB: XMV(hash,exp,inc,hv[j]=i); ZCSHAPE; break; \ + case ILESS: XMV(hash,exp,inc,0 ); ZCSHAPE; break; \ + case INUBI: XDO(hash,exp,inc,if(m==hj)*zi++=hv[j]=i); ZISHAPE; break; \ + case IEPS: XDO(hash,exp,inc,*zb++=m>hj); break; \ + case II0EPS: s=c; XDO(hash,exp,inc,if(m==hj){s=i; break;}); *zi++=s; break; \ + case II1EPS: s=c; XDO(hash,exp,inc,if(m> hj){s=i; break;}); *zi++=s; break; \ + case IJ0EPS: s=c; XDQ(hash,exp,dec,if(m==hj){s=i; break;}); *zi++=s; break; \ + case IJ1EPS: s=c; XDQ(hash,exp,dec,if(m> hj){s=i; break;}); *zi++=s; break; \ + case ISUMEPS: s=0; XDO(hash,exp,inc,if(m> hj)++s; ); *zi++=s; break; \ + case IANYEPS: s=0; XDO(hash,exp,inc,if(m> hj){s=1; break;}); *zb++=1&&s; break; \ + case IALLEPS: s=1; XDO(hash,exp,inc,if(m==hj){s=0; break;}); *zb++=1&&s; break; \ + case IIFBEPS: s=c; XDO(hash,exp,inc,if(m> hj)*zi++=i ); ZISHAPE; break; \ + }} \ + R z; \ + } + +static IOFX(A,jtioax1,hia(t1,AADR(d,*v)),!equ(AADR(d,*v),AADR(ad,av[hj])),++v, --v ) /* boxed exact 1-element item */ +static IOFX(A,jtioau, hiau(AADR(d,*v)), !equ(AADR(d,*v),AADR(ad,av[hj])),++v, --v ) /* boxed uniform type */ +static IOFX(X,jtiox, hix(v), !eqx(n,v,av+n*hj), v+=cn, v-=cn) /* extended integer */ +static IOFX(Q,jtioq, hiq(v), !eqq(n,v,av+n*hj), v+=cn, v-=cn) /* rational number */ +static IOFX(C,jtioc, hic(k,(UC*)v), memcmp(v,av+k*hj,k), v+=cn, v-=cn) /* boolean, char, or integer */ +static IOFX(C,jtiocx, hicx(jt,k,(UC*)v), memcmp(v,av+k*hj,k), v+=cn, v-=cn) /* boolean, char, or integer */ +static IOFX(I,jtioi, hicw(v), *v!=av[hj], ++v, --v ) + + +#define HID(y) (888888883U*y.i[LSW]+2838338383U*y.i[MSW]) +#define MASK(dd,xx) {dd.d=xx; dd.i[LSW]&=jt->ctmask;} +#define THASHA(expa) {x=*(D*)v; MASK(dx,x); j=HID(dx)%pm; FIND(expa); if(m==hj)hv[j]=i;} +#define THASHBX(expa) {j=hia(t1,AADR(d,*v))%pm; FIND(expa); if(m==hj)hv[j]=i;} + +#define TFINDXY(expa,expw) \ + {x=*(D*)v; \ + MASK(dl,x*tl); j= HID(dl)%pm; FIND(expw); il=ir=hj; \ + MASK(dr,x*tr); if(dr.d!=dl.d){j= HID(dr)%pm; FIND(expw); ir=hj;} \ + } +#define TFINDYY(expa,expw) \ + {x=*(D*)v; \ + MASK(dx,x ); j=jx=HID(dx)%pm; jt->ct=0.0; FIND(expa); jt->ct=ct; if(m==hj)hv[j]=i; \ + MASK(dl,x*tl); j=dl.d==dx.d?jx:HID(dl)%pm; FIND(expw); il=ir=hj; \ + MASK(dr,x*tr); if(dr.d!=dl.d){j=dr.d==dx.d?jx:HID(dr)%pm; FIND(expw); ir=hj;} \ + } +#define TFINDY1(expa,expw) \ + {x=*(D*)v; \ + MASK(dx,x ); j=jx=HID(dx)%pm; FIND(expa); if(m==hj)hv[j]=i; \ + MASK(dl,x*tl); j=dl.d==dx.d?jx:HID(dl)%pm; FIND(expw); il=ir=hj; \ + MASK(dr,x*tr); if(dr.d!=dl.d){j=dr.d==dx.d?jx:HID(dr)%pm; FIND(expw); ir=hj;} \ + } +#define TFINDBX(expa,expw) \ + {jx=j=hia(tl,AADR(d,*v))%pm; FIND(expw); il=ir=hj; \ + j=hia(tr,AADR(d,*v))%pm; if(j!=jx){FIND(expw); ir=hj;} \ + } +#define TDO(FXY,FYY,expa,expw,stmt) \ + switch(4*bx+2*b+(k==sizeof(D))){ \ + default: DO(c, FXY(expa,expw); stmt; v+=cn;); break; \ + case 1: DO(c, FXY(expa,expw); stmt; ++v; ); break; \ + case 2: DO(c, FYY(expa,expw); stmt; v+=cn;); break; \ + case 3: DO(c, FYY(expa,expw); stmt; ++v; ); \ + } +#define TDQ(FXY,FYY,expa,expw,stmt) \ + v+=cn*(c-1); \ + switch(4*bx+2*b+(k==sizeof(D))){ \ + default: DQ(c, FXY(expa,expw); stmt; v-=cn;); break; \ + case 1: DQ(c, FXY(expa,expw); stmt; --v; ); break; \ + case 2: DQ(c, FYY(expa,expw); stmt; v-=cn;); break; \ + case 3: DQ(c, FYY(expa,expw); stmt; --v; ); \ + } +#define TMV(FXY,FYY,expa,expw,prop) \ + switch(4*bx+2*b+(k==sizeof(D))){ \ + default: DO(c, FXY(expa,expw); if(prop){MC(zc,v,k); zc+=k;}; v+=cn;); break; \ + case 1: DO(c, FXY(expa,expw); if(prop)*zd++=*(D*)v; ++v; ); zc=(C*)zd; break; \ + case 2: DO(c, FYY(expa,expw); if(prop){MC(zc,v,k); zc+=k;}; v+=cn;); break; \ + case 3: DO(c, FYY(expa,expw); if(prop)*zd++=*(D*)v; ++v; ); zc=(C*)zd; \ + } + + +#define IOFT(T,f,FA,FXY,FYY,expa,expw) \ + IOF(f){RDECL;IODECL(T);B b,bx;D ct=jt->ct,tl=1-jt->ct,tr=1/tl,x,*zd;DI dl,dr,dx;I d,e,il,ir,jx,md,s; \ + md=mode<IPHOFFSET?mode:mode-IPHOFFSET; \ + b=a==w&&ac==wc&&(mode==IIDOT||mode==IICO||mode==INUBSV||mode==INUB||mode==INUBI); \ + zb=(B*)zv; zc=(C*)zv; zd=(D*)zv; zi=zv; e=cn*(m-1); bx=1&&BOX&AT(a); \ + jx=0; dl.d=dr.d=dx.d=x=0.0; \ + for(l=0;l<ac;++l,av+=acn,wv+=wcn){ \ + if(mode<IPHOFFSET){ \ + DO(p,hv[i]=m;); \ + if(bx||!b){ \ + d=ad; v=av; jt->ct=0.0; \ + if(IICO==mode){v+=e; DQ(m, FA(expa); v-=cn;);}else DO(m, FA(expa); v+=cn;); \ + jt->ct=ct; if(w==mark)break; \ + }} \ + d=wd; v=wv; \ + switch(md){ \ + case IIDOT: TDO(FXY,FYY,expa,expw,*zv++=MIN(il,ir)); break; \ + case IICO: zv+=c; TDQ(FXY,FYY,expa,expw,*--zv=m==il?ir:m==ir?il:MAX(il,ir)); zv+=c; break; \ + case INUBSV: TDO(FXY,FYY,expa,expw,*zb++=i==MIN(il,ir)); break; \ + case INUB: TMV(FXY,FYY,expa,expw,i==MIN(il,ir)); ZCSHAPE; break; \ + case ILESS: TMV(FXY,FYY,expa,expw,m==il&&m==ir); ZCSHAPE; break; \ + case INUBI: TDO(FXY,FYY,expa,expw,if(i==MIN(il,ir))*zi++=i;); ZISHAPE; break; \ + case IEPS: TDO(FXY,FYY,expa,expw,*zb++=m>il||m>ir ); break; \ + case II0EPS: s=c; TDO(FXY,FYY,expa,expw,if(m==il&&m==ir){s=i; break;}); *zi++=s; break; \ + case II1EPS: s=c; TDO(FXY,FYY,expa,expw,if(m> il||m> ir){s=i; break;}); *zi++=s; break; \ + case IJ0EPS: s=c; TDQ(FXY,FYY,expa,expw,if(m==il&&m==ir){s=i; break;}); *zi++=s; break; \ + case IJ1EPS: s=c; TDQ(FXY,FYY,expa,expw,if(m> il||m> ir){s=i; break;}); *zi++=s; break; \ + case ISUMEPS: s=0; TDO(FXY,FYY,expa,expw,if(m> il||m> ir)++s ); *zi++=s; break; \ + case IANYEPS: s=0; TDO(FXY,FYY,expa,expw,if(m> il||m> ir){s=1; break;}); *zb++=1&&s; break; \ + case IALLEPS: s=1; TDO(FXY,FYY,expa,expw,if(m==il&&m==ir){s=0; break;}); *zb++=1&&s; break; \ + case IIFBEPS: TDO(FXY,FYY,expa,expw,if(m> il||m> ir)*zi++=i ); ZISHAPE; break; \ + }} \ + R z; \ + } + +static IOFT(Z,jtioz, THASHA, TFINDXY,TFINDYY,memcmp(v,av+n*hj,n*2*sizeof(D)), !eqz(n,v,av+n*hj) ) +static IOFT(Z,jtioz1,THASHA, TFINDXY,TFINDYY,memcmp(v,av+n*hj, 2*sizeof(D)), !zeq( *v,av[hj] ) ) +static IOFT(D,jtiod, THASHA, TFINDXY,TFINDYY,memcmp(v,av+n*hj,n* sizeof(D)), !eqd(n,v,av+n*hj) ) +static IOFT(D,jtiod1,THASHA, TFINDXY,TFINDY1,x!=av[hj], !teq(x,av[hj] ) ) +static IOFT(A,jtioa, THASHBX,TFINDBX,TFINDBX,!eqa(n,v,av+n*hj,d,ad), !eqa(n,v,av+n*hj,d,ad) ) +static IOFT(A,jtioa1,THASHBX,TFINDBX,TFINDBX,!equ(AADR(d,*v),AADR(ad,av[hj])),!equ(AADR(d,*v),AADR(ad,av[hj]))) + + +#define SDO(v0) if(mode<IPHOFFSET){B v1=!(v0); memset(hv,v0,p); u=av; DO(m, hb[*u++]=v1;);} +#define SDOA if(mode<IPHOFFSET){DO(p,hv[i]=m; ); u=av; DO(m,hu[*u++]=i;);} +#define SDQA if(mode<IPHOFFSET){DO(p,hv[i]=m; ); u=av+m; DQ(m,hu[*--u]=i;);} + +#define SDOW(stmt) {u=wv; DO(cm, stmt;);} + +#define SCOZ(hh,zz,vv) {u=wv; DO(cm, zz=hh[*u++]; );} +#define SCOZ1(hh,zz,vv) {u=wv; DO(cm, x=*u++; zz=min<=x&&x<max?hh[x]:vv;);} + +#define SCOW(hh,stmt) {u=wv; DO(cm, if( hh[ *u++]){stmt;});} +#define SCOWX(hh,stmt) {u=wv; DO(cm, if( hh[x=*u++]){stmt;});} +#define SCOW1(hh,stmt) {u=wv; DO(cm, x=*u++; if(min<=x&&x< max&&hh[x ]){stmt;});} +#define SCOW0(hh,stmt) {u=wv; DO(cm, x=*u++; if(x<min ||max<=x||hh[x ]){stmt;});} + +#define SCQW(hh,stmt) {u=wv+c; DQ(cm, if( hh[ *--u]){stmt;});} +#define SCQW1(hh,stmt) {u=wv+c; DQ(cm, x=*--u; if(min<=x&&x< max&&hh[x ]){stmt;});} +#define SCQW0(hh,stmt) {u=wv+c; DQ(cm, x=*--u; if(x<min ||max<=x||hh[x ]){stmt;});} + +#define IOFSMALLRANGE(f,T,COZ1,COW0,COW1,COWX,CQW0,CQW1) \ + IOF(f){A h=*hp;B b,*hb,*zb;I cm,e,*hu,*hv,l,max,md,min,p,s,*v,*zi,*zv;T*av,*u,*wv,x,*zu; \ + md=mode<IPHOFFSET?mode:mode-IPHOFFSET; b=(mode==IIDOT||mode==IICO)&&a==w&&ac==wc; \ + av=(T*)AV(a); wv=(T*)AV(w); zv=zi=AV(z); zb=(B*)zv; zu=(T*)zv; \ + p=AN(h); min=jt->min; max=p+min; hv=AV(h); hb=(B*)hv-min; hu=hv-min; \ + e=1==wc?0:c; cm=w==mark?0:c; \ + for(l=0;l<ac;++l,av+=m,wv+=e){ \ + if(b){ \ + if(mode==IIDOT){DO(p,hv[i]=-1;); u=wv; DO(m, v=hu+*u++; if(0>*v)*v=i; *zv++=*v;); } \ + else {DO(p,hv[i]=-1;); u=wv+m; zv+=m; DQ(m, v=hu+*--u; if(0>*v)*v=i; *--zv=*v;); zv+=m;} \ + }else switch(md){ \ + case INUBSV: memset(hv,C1,p); SDOW(if(*zb++=hb[x=*u++])hb[x]=0); break; \ + case INUB: memset(hv,C1,p); SDOW(if(hb[x=*u++]){*zu++=x; hb[x]=0;}); ZUSHAPE(T); break; \ + case INUBI: memset(hv,C1,p); SDOW(if(hb[x=*u++]){*zi++=i; hb[x]=0;}); ZISHAPE; break; \ + case IIDOT: SDQA; COZ1(hu, *zv++, m); break; \ + case IICO: SDOA; COZ1(hu, *zv++, m); break; \ + case IEPS: SDO(C0); COZ1(hb, *zb++, 0); break; \ + case ILESS: SDO(C1); COWX(hb, *zu++=x ); ZUSHAPE(T); break; \ + case II0EPS: SDO(C1); s=c; COW0(hb, s=i; break); *zv++=s; break; \ + case II1EPS: SDO(C0); s=c; COW1(hb, s=i; break); *zv++=s; break; \ + case IJ0EPS: SDO(C1); s=c; CQW0(hb, s=i; break); *zv++=s; break; \ + case IJ1EPS: SDO(C0); s=c; CQW1(hb, s=i; break); *zv++=s; break; \ + case IANYEPS: SDO(C0); s=0; COW1(hb, s=1; break); *zb++=1&&s; break; \ + case IALLEPS: SDO(C1); s=1; COW0(hb, s=0; break); *zb++=1&&s; break; \ + case ISUMEPS: SDO(C0); s=0; COW1(hb, ++s ); *zv++=s; break; \ + case IIFBEPS: SDO(C0); COW1(hb, *zi++=i ); ZISHAPE; break; \ + }} \ + R z; \ + } + +static IOFSMALLRANGE(jtio1,UC,SCOZ, SCOW, SCOW, SCOWX,SCQW, SCQW ) /* 1-byte items */ +static IOFSMALLRANGE(jtio2,US,SCOZ, SCOW, SCOW, SCOWX,SCQW, SCQW ) /* 2-byte items */ +static IOFSMALLRANGE(jtio4,I ,SCOZ1,SCOW0,SCOW1,SCOW0,SCQW0,SCQW1) /* word size items */ + + +#define SCDO(T,xe,exp) \ + {T*av=(T*)u,*v0=(T*)v,*wv=(T*)v,x; \ + switch(mode){ \ + case IIDOT: DO(ac, DO(c, x=(xe); j=0; while(m>j &&(exp))++j; *zv++=j; wv+=q;); av+=p; if(1==wc)wv=v0;); break; \ + case IICO: DO(ac, DO(c, x=(xe); j=m-1; while(0<=j&&(exp))--j; *zv++=0>j?m:j; wv+=q;); av+=p; if(1==wc)wv=v0;); break; \ + case IEPS: DO(ac, DO(c, x=(xe); j=0; while(m>j &&(exp))++j; *zb++=m>j; wv+=q;); av+=p; if(1==wc)wv=v0;); break; \ + }} + +static IOF(jtiosc){B*zb;I j,p,q,*u,*v,zn,*zv; + p=1<ac?m:0; q=1<wc||1<c; + zn=AN(z); + zv=AV(z); zb=(B*)zv; u=AV(a); v=AV(w); + switch(AT(a)){ + default: SCDO(C, *wv,x!=av[j] ); break; + case C2T: SCDO(S, *wv,x!=av[j] ); break; + case CMPX: SCDO(Z, *wv,!zeq(x, av[j])); break; + case XNUM: SCDO(A, *wv,!equ(x, av[j])); break; + case RAT: SCDO(Q, *wv,!QEQ(x, av[j])); break; + case INT: SCDO(I, *wv,x!=av[j] ); break; + case SBT: SCDO(SB,*wv,x!=av[j] ); break; + case BOX: {RDECL; SCDO(A, AADR(wd,*wv),!equ(x,AADR(ad,av[j])));} break; + case FL: if(0==jt->ct)SCDO(D, *wv,x!=av[j]) + else SCDO(D, *wv,!teq(x,av[j])); + } + R z; +} /* right argument cell is scalar; only for modes IIDOT IICO IEPS */ + + +static B jtusebs(J jt,A a,I ac,I m){A*av,x;I ad,t; + if(!(BOX&AT(a)&&0==jt->ct))R 0; + av=AAV(a); ad=(I)a*ARELATIVE(a); + DO(ac*m, x=AVR(i); t=AT(x); if(t&BOX+CMPX||1<AN(x)&&t&NUMERIC)R 1;); + R 0; +} /* n (# elements in a target item) is assumed to be 1 */ + +static A jtnodupgrade(J jt,A a,I acr,I ac,I acn,I ad,I n,I m,B b,B bk){A*av,h,*u,*v;I*hi,*hu,*hv,l,m1,q; + RZ(h=irs1(a,0L,acr,jtgrade1)); hv=AV(h)+bk*(m-1); av=AAV(a); + if(!b)for(l=0;l<ac;++l,av+=acn,hv+=m){ + hi=hv; q=*hi; u=av+n*q; + if(bk){hu=--hi; DO(m-1, q=*hi--; v=av+n*q; if(!eqa(n,u,v,ad,ad)){u=v; *hu--=q;}); m1=hv-hu; if(m>m1)hv[1-m]=1-m1;} + else {hu=++hi; DO(m-1, q=*hi++; v=av+n*q; if(!eqa(n,u,v,ad,ad)){u=v; *hu++=q;}); m1=hu-hv; if(m>m1)hv[m-1]=1-m1;} + } + R h; +} + +#define BSLOOPAA(hiinc,zstmti,zstmt1,zstmt0) \ + {A*u=av,*v;I*hi=hv,p,q; \ + p=*hiinc; u=av+n*p; zstmti; \ + DO(m-1, q=*hiinc; v=av+n*q; if(eqa(n,u,v,ad,ad))zstmt1; else{u=v; zstmt0;}); \ + } + +#define BSLOOPAWX(ii,icmp,iinc,uinc,zstmt) \ + {A*u=wv+n*(ii),*v;I i,j,p,q;int t; \ + for(i=ii;icmp;iinc,uinc){ \ + p=0; q=m1; \ + while(p<=q){ \ + t=0; j=(p+q)/2; v=av+n*hu[j]; \ + DO(n, if(t=compare(AADR(wd,u[i]),AADR(ad,v[i])))break;); \ + if(0<t)p=j+1; else q=t?j-1:-2; \ + } \ + zstmt; \ + }} + +#define BSLOOPAW(zstmt) BSLOOPAWX(0 ,i< c,++i,u+=n,zstmt) +#define BSLOOQAW(zstmt) BSLOOPAWX(c-1,i>=0,--i,u-=n,zstmt) + +static IOF(jtiobs){A*av,h=*hp,*wv,y;B b,bk,*yb,*zb;C*zc;I acn,ad,*hu,*hv,l,m1,md,s,wcn,wd,*zi,*zv; + bk=mode==IICO||mode==IJ0EPS||mode==IJ1EPS||mode==IPHICO||mode==IPHJ0EPS||mode==IPHJ1EPS; + b=a==w&&ac==wc&&(mode==IIDOT||mode==IICO||mode==INUB||mode==INUBSV||mode==INUBI); + if(mode==INUB||mode==INUBI){GA(y,B01,m,1,0); yb=BAV(y);} + md=w==mark?-1:mode<IPHOFFSET?mode:mode-IPHOFFSET; + av=AAV(a); ad=(I)a*ARELATIVE(a); acn=ak/sizeof(A); + wv=AAV(w); wd=(I)w*ARELATIVE(w); wcn=wk/sizeof(A); + zi=zv=AV(z); zb=(B*)zv; zc=(C*)zv; + if(mode<IPHOFFSET)RZ(*hp=h=nodupgrade(a,acr,ac,acn,ad,n,m,b,bk)); + if(w==mark)R mark; + hv=AV(h)+bk*(m-1); jt->complt=-1; jt->compgt=1; + for(l=0;l<ac;++l,av+=acn,wv+=wcn,hv+=m){ + s=hv[bk?1-m:m-1]; m1=0>s?-s:m-1; hu=hv-m1*bk; + if(b)switch(md){ + case IIDOT: BSLOOPAA(hi++,zv[p]=p,zv[q]=p,zv[q]=p=q); zv+=m; break; + case IICO: BSLOOPAA(hi--,zv[p]=p,zv[q]=p,zv[q]=p=q); zv+=m; break; + case INUBSV: BSLOOPAA(hi++,zb[p]=1,zb[q]=0,zb[q]=1 ); zb+=m; break; + case INUB: BSLOOPAA(hi++,yb[p]=1,yb[q]=0,yb[q]=1 ); DO(m, if(yb[i]){MC(zc,av+i*n,k); zc+=k;}); ZCSHAPE; break; + case INUBI: BSLOOPAA(hi++,yb[p]=1,yb[q]=0,yb[q]=1 ); DO(m, if(yb[i])*zi++=i;); ZISHAPE; break; + }else switch(md){ + case IIDOT: BSLOOPAW(*zv++=-2==q?hu[j]:m); break; + case IICO: BSLOOPAW(*zv++=-2==q?hu[j]:m); break; + case IEPS: BSLOOPAW(*zb++=-2==q); break; + case ILESS: BSLOOPAW(if(-2< q){MC(zc,u,k); zc+=k;}); ZCSHAPE; break; + case II0EPS: s=m; BSLOOPAW(if(-2< q){s=i; break;}); *zi++=s; break; + case IJ0EPS: s=m; BSLOOQAW(if(-2< q){s=i; break;}); *zi++=s; break; + case II1EPS: s=m; BSLOOPAW(if(-2==q){s=i; break;}); *zi++=s; break; + case IJ1EPS: s=m; BSLOOQAW(if(-2==q){s=i; break;}); *zi++=s; break; + case IANYEPS: s=0; BSLOOPAW(if(-2==q){s=1; break;}); *zb++=1&&s; break; + case IALLEPS: s=1; BSLOOPAW(if(-2< q){s=0; break;}); *zb++=1&&s; break; + case ISUMEPS: s=0; BSLOOPAW(if(-2==q)++s); *zi++=s; break; + case IIFBEPS: BSLOOPAW(if(-2==q)*zi++=i); ZISHAPE; break; + }} + R z; +} /* a i.!.0 w on boxed a,w by grading and binary search */ + +static I jtutype(J jt,A w,I c){A*wv,x;I m,t,wd; + if(!AN(w))R 1; + m=AN(w)/c; wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(c, t=0; DO(m, x=WVR(i); if(AN(x)){if(t)RZ(t==AT(x)) else{t=AT(x); if(t&FL+CMPX+BOX)R 0;}});); + R t; +} /* return type if opened atoms of cells of w has uniform type, else 0. c is # of cells */ + +I hsize(I m){I q=m+m,*v=ptab; DO(nptab-1, if(q<=*v)break; ++v;); R*v;} + + +A jtindexofsub(J jt,I mode,A a,A w){PROLOG;A h=0,hi=mtv,z=mtv;AF fn;B mk=w==mark,th; + I ac,acr,af,ak,ar,*as,at,c,f,f1,k,k1,m,n,p,r,*s,ss,t,wc,wcr,wf,wk,wr,*ws,wt,zn; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + as=AS(a); at=AT(a); + ws=AS(w); wt=AT(w); + if(mk){f=af; s=as; r=acr-1; f1=wcr-r;} + else{ + f=af?af:wf; s=af?as:ws; r=acr?acr-1:0; f1=wcr-r; + if(0>f1||ICMP(as+af+1,ws+wf+f1,r)){I f0,*v; + m=acr?as[af]:1; f0=MAX(0,f1); RE(zn=mult(prod(f,s),prod(f0,ws+wf))); + switch(mode){ + case IIDOT: + case IICO: GA(z,INT,zn,f+f0,s); if(af)ICPY(f+AS(z),ws+wf,f0); v=AV(z); DO(zn, *v++=m;); R z; + case IEPS: GA(z,B01,zn,f+f0,s); if(af)ICPY(f+AS(z),ws+wf,f0); memset(BAV(z),C0,zn); R z; + case ILESS: R ca(w); + case IIFBEPS: R mtv; + case IANYEPS: case IALLEPS: case II0EPS: R zero; + case ISUMEPS: R sc(0L); + case II1EPS: case IJ1EPS: R sc(zn); + case IJ0EPS: R sc(zn-1); + case INUBSV: case INUB: case INUBI: ASSERTSYS(0,"indexofsub"); // impossible + }}} + if(at&SPARSE||wt&SPARSE){ + if(1>=acr)R af?sprank2(a,w,0L,acr,RMAX,jtindexof):wt&SPARSE?iovxs(mode,a,w):iovsd(mode,a,w); + if(af||wf)R sprank2(a,w,0L,acr,wcr,jtindexof); + switch((at&SPARSE?2:0)+(wt&SPARSE?1:0)){ + case 1: EPILOG(indexofxx(mode,a,w)); + case 2: EPILOG(indexofxx(mode,a,w)); + case 3: EPILOG(indexofss(mode,a,w)); + }} + m=acr?as[af]:1; n=acr?prod(acr-1,as+af+1):1; RE(zn=mult(prod(f,s),prod(f1,ws+wf))); + RE(t=mk?at:maxtype(at,wt)); k1=bp(t); k=n*k1; th=HOMO(at,wt); jt->min=ss=0; + ac=prod(af,as); ak=ac?k1*AN(a)/ac:0; + wc=prod(wf,ws); wk=wc?k1*AN(w)/wc:0; c=1<ac?wk/k:zn; wk*=1<wc; + if(th&&t!=at)RZ(a=t&XNUM?xcvt(XMEXMT,a):cvt(t,a)) else if(t&FL+CMPX )RZ(a=cvt0(a)); + if(th&&t!=wt)RZ(w=t&XNUM?xcvt(XMEXMT,w):cvt(t,w)) else if(t&FL+CMPX&&a!=w)RZ(w=cvt0(w)); + if(AT(a)&INT+SBT&&k==SZI){I r; irange(AN(a)*k1/SZI,AV(a),&r,&ss); if(ss){jt->min=r;}} + p=1==k?(t&B01?2:256):2==k?(t&B01?258:65536):k==SZI&&ss&&ss<2.1*MAX(m,c)?ss:hsize(m); + if(!mk)switch(mode){I q; + case IIDOT: + case IICO: GA(z,INT,zn,f+f1, s); if(af)ICPY(f+AS(z),ws+wf,f1); break; + case INUBSV: GA(z,B01,zn,f+f1+!acr,s); if(af)ICPY(f+AS(z),ws+wf,f1); if(!acr)*(AS(z)+AR(z)-1)=1; break; + case INUB: q=MIN(m,p); GA(z,t,mult(q,aii(a)),MAX(1,wr),ws); *AS(z)=q; break; + case ILESS: GA(z,t,AN(w),MAX(1,wr),ws); break; + case IEPS: GA(z,B01,zn,f+f1, s); if(af)ICPY(f+AS(z),ws+wf,f1); break; + case INUBI: q=MIN(m,p); GA(z,INT,q,1,0); break; + case IIFBEPS: GA(z,INT,c,1,0); break; + case IANYEPS: case IALLEPS: + GA(z,B01,1,0,0); break; + case II0EPS: case II1EPS: case IJ0EPS: case IJ1EPS: case ISUMEPS: + GA(z,INT,1,0,0); break; + } + if(!(mk||m&&n&&zn&&th))switch(mode){ + case IIDOT: R reshape(shape(z),sc(n?m:0 )); + case IICO: R reshape(shape(z),sc(n?m:m-1)); + case INUBSV: R reshape(shape(z),take(sc(m),one)); + case INUB: AN(z)=0; *AS(z)=m?1:0; R z; + case ILESS: if(m)AN(z)=*AS(z)=0; else MC(AV(z),AV(w),k1*AN(w)); R z; + case IEPS: R reshape(shape(z),m&&(!n||th)?one:zero); + case INUBI: R m?iv0:mtv; + case II0EPS: R sc(n?0L :c ); + case II1EPS: R sc(n?c :0L ); + case IJ0EPS: R sc(n?MAX(0,c-1):c ); + case IJ1EPS: R sc(n?c :MAX(0,c-1)); + case ISUMEPS: R sc(n?0L :c ); + case IANYEPS: R n?zero:one; + case IALLEPS: R c&&n?zero:one; + case IIFBEPS: R n?mtv :IX(c); + } + if(a!=w&&!mk&&1==acr&&(1==wc||ac==wc)&&(D)m*n*zn<13*((D)m*n+zn)&&(mode==IIDOT||mode==IICO||mode==IEPS)){ + fn=jtiosc; + }else{B b=0==jt->ct;I ht=INT,t1; + if(!b&&t&BOX+FL+CMPX)ctmask(jt); + if (t&BOX) fn=b&&(1<n||usebs(a,ac,m))?jtiobs:1<n?jtioa:b?jtioax1: + (t1=utype(a,ac))&&(mk||a==w||t1==utype(w,wc))?jtioau:jtioa1; + else if(t&XNUM) fn=jtiox; + else if(t&RAT ) fn=jtioq; + else if(1==k) {fn=jtio1; if(!(mode==IIDOT||mode==IICO))ht=B01;} + else if(2==k) {fn=jtio2; if(!(mode==IIDOT||mode==IICO))ht=B01;} + else if(k==SZI&&!(t&FL)){if(p==ss){fn=jtio4; if(!(mode==IIDOT||mode==IICO))ht=B01;}else fn=jtioi;} + else fn=b||t&B01+JCHAR+INT+SBT?jtioc:1==n?(t&FL?jtiod1:jtioz1):t&FL?jtiod:jtioz; + if(fn!=jtiobs)GA(h,ht,p,1,0); + } + if(fn==jtioc){A x;B*b;C*u,*v;I*d,q; + GA(x,B01,k,1,0); b=BAV(x); memset(b,C1,k); + q=k; u=CAV(a); v=u+k; + DO(ac*(m-1), DO(k, if(u[i]!=*v&&b[i]){b[i]=0; --q;} ++v;); if(!q)break;); + if(q){jt->hin=k-q; GA(hi,INT,k-q,1,0); jt->hiv=d=AV(hi); DO(k, if(!b[i])*d++=i;); fn=jtiocx;} + } + RZ(fn(jt,mode,m,n,c,k,acr,wcr,ac,wc,ak,wk,a,w,&h,z)); + if(mk){A x,*zv;I*xv,ztype; + GA(z,BOX,3,1,0); zv=AAV(z); + GA(x,INT,6,1,0); xv=AV(x); + switch(mode){ + default: ztype=0; break; /* integer vector */ + case ILESS: ztype=1; break; /* type/shape from arg */ + case IEPS: ztype=2; break; /* boolean vector */ + case IANYEPS: case IALLEPS: ztype=3; break; /* boolean scalar */ + case ISUMEPS: + case II0EPS: case II1EPS: + case IJ0EPS: case IJ1EPS: ztype=4; /* integer scalar */ + } + xv[0]=mode; xv[1]=n; xv[2]=k; xv[3]=jt->min; xv[4]=(I)fn; xv[5]=ztype; + zv[0]=x; zv[1]=h; zv[2]=hi; + } + EPILOG(z); +} /* a i."r w main control */ + +A jtindexofprehashed(J jt,A a,A w,A hs){A h,hi,*hv,x,z;AF fn;I ar,*as,at,c,f1,k,m,mode,n, + r,t,*xv,wr,*ws,wt,ztype; + RZ(a&&w&&hs); + hv=AAV(hs); x=hv[0]; h=hv[1]; hi=hv[2]; + xv=AV(x); mode=xv[0]; n=xv[1]; k=xv[2]; jt->min=xv[3]; fn=(AF)xv[4]; ztype=xv[5]; + ar=AR(a); as=AS(a); at=AT(a); t=at; m=ar?*as:1; + wr=AR(w); ws=AS(w); wt=AT(w); + if(1==ztype)r=wr?wr-1:0; + else r=ar?ar-1:0; + f1=wr-r; + ASSERT(r<=ar&&0<=f1,EVRANK); + ASSERT(!ICMP(as+ar-r,ws+f1,r),EVLENGTH); + RE(c=prod(f1,ws)); + if(mode==ILESS&&(t!=wt||AFLAG(w)&AFNJA+AFREL||n!=aii(w)))R less(w,a); + if(!(m&&n&&c&&HOMO(t,wt)&&t>=wt))R indexofsub(mode,a,w); + switch(ztype){ + case 0: GA(z,INT,c, f1, ws); break; + case 1: GA(z,wt, AN(w),1+r,ws); break; + case 2: GA(z,B01,c, f1, ws); break; + case 3: GA(z,B01,1, 0, 0 ); break; + case 4: GA(z,INT,1, 0, 0 ); break; + } + jt->hin=AN(hi); jt->hiv=AV(hi); + if(t!=wt)RZ(w=cvt(t,w)) else if(t&FL+CMPX)RZ(w=cvt0(w)); + R fn(jt,mode+IPHOFFSET,m,n,c,k,AR(a),AR(w),(I)1,(I)1,(I)0,(I)0,a,w,&h,z); +} + +F2(jtindexof){R indexofsub(IIDOT,a,w);} + /* a i."r w */ + +F2(jtjico2){R indexofsub(IICO,a,w);} + /* a i:"r w */ + +F1(jtnubsieve){ + RZ(w); + if(SPARSE&AT(w))R nubsievesp(w); + if(jt->rank)jt->rank[0]=jt->rank[1]; + R indexofsub(INUBSV,w,w); +} /* ~:"r w */ + +F1(jtnub){ + RZ(w); + if(SPARSE&AT(w)||AFLAG(w)&AFNJA+AFREL)R repeat(nubsieve(w),w); + R indexofsub(INUB,w,w); +} /* ~.w */ + +F2(jtless){A x=w;I ar,at,k,r,*s,wr,*ws,wt; + RZ(a&&w); + at=AT(a); ar=AR(a); + wt=AT(w); wr=AR(w); r=MAX(1,ar); + if(ar>1+wr)R ca(a); + if(wr&&r!=wr){RZ(x=gah(r,w)); s=AS(x); ws=AS(w); k=ar>wr?0:1+wr-r; *s=prod(k,ws); ICPY(1+s,k+ws,r-1);} + R !(at&SPARSE)&&HOMO(at,wt)&&at==maxtype(at,wt)&&!(AFLAG(a)&AFNJA+AFREL)?indexofsub(ILESS,x,a): + repeat(not(eps(a,x)),a); +} /* a-.w */ + +F2(jteps){I l,r,rv[2]; + RZ(a&&w); + rv[0]=r=jt->rank?jt->rank[1]:AR(w); + rv[1]=l=jt->rank?jt->rank[0]:AR(a); jt->rank=0; + if(SPARSE&AT(a)+AT(w))R lt(irs2(w,a,0L,r,l,jtindexof),sc(r?*(AS(w)+AR(w)-r):1)); + jt->rank=rv; + R indexofsub(IEPS,w,a); +} /* a e."r w */ + +F1(jtnubind){ + RZ(w); + R SPARSE&AT(w)?icap(nubsieve(w)):indexofsub(INUBI,w,w); +} /* I.@~: w */ + +F1(jtnubind0){A z;D oldct=jt->ct; + RZ(w); + jt->ct=0.0; z=SPARSE&AT(w)?icap(nubsieve(w)):indexofsub(INUBI,w,w); jt->ct=oldct; + R z; +} /* I.@(~:!.0) w */ + + +F1(jtsclass){A e,x,xy,y,z;I c,j,m,n,*v;P*p; + RZ(w); + if(!AR(w))R reshape(v2(1L,1L),one); + n=IC(w); + RZ(x=indexof(w,w)); + if(DENSE&AT(w))R atab(CEQ,repeat(eq(IX(n),x),x),x); + p=PAV(x); e=SPA(p,e); y=SPA(p,i); RZ(xy=stitch(SPA(p,x),y)); + if(n>*AV(e))RZ(xy=over(xy,stitch(e,less(IX(n),y)))); + RZ(xy=grade2(xy,xy)); v=AV(xy); + c=*AS(xy); + m=j=-1; DO(c, if(j!=*v){j=*v; ++m;} *v=m; v+=2;); + GA(z,SB01,1,2,0); v=AS(z); v[0]=1+m; v[1]=n; + p=PAV(z); + SPB(p,a,v2(0L,1L)); + SPB(p,e,zero); + SPB(p,i,xy); + SPB(p,x,reshape(sc(c),one)); + R z; +} + + +#define IOCOLF(f) void f(J jt,I m,I c,I d,A a,A w,A z,A h) +#define IOCOLDECL(T) D tl=1-jt->ct,tr=1/tl,x; \ + I hj,*hv=AV(h),i,j,jr,l,p=AN(h),*u,*zv=AV(z); \ + T*av=(T*)AV(a),*v,*wv=(T*)AV(w);UI pm=p + +#define IOCOLFT(T,f,hasha,hashl,hashr,exp) \ + IOCOLF(f){IOCOLDECL(T); \ + for(l=0;l<c;++l){ \ + DO(p, hv[i]=m;); \ + v=av; DO(m, j=(hasha)%pm; FIND(exp); if(m==hj)hv[j]=i; v+=c;); \ + v=wv; u=zv; \ + for(i=0;i<d;++i){ \ + x=*(D*)v; \ + j=jr=(hashl)%pm; FIND(exp); *u=hj; \ + j= (hashr)%pm; if(j!=jr){FIND(exp); *u=MIN(*u,hj);} \ + v+=c; u+=c; \ + } \ + ++av; ++wv; ++zv; \ + }} + +#define JOCOLFT(T,f,hasha,hashl,hashr,exp) \ + IOCOLF(f){IOCOLDECL(T);I q; \ + for(l=0;l<c;++l){ \ + DO(p, hv[i]=m;); \ + v=av+c*(m-1); DQ(m, j=(hasha)%pm; FIND(exp); if(m==hj)hv[j]=i; v-=c;); \ + v=wv; u=zv; \ + for(i=0;i<d;++i){ \ + x=*(D*)v; \ + j=jr=(hashl)%pm; FIND(exp); *u=q=hj; \ + j= (hashr)%pm; if(j!=jr){FIND(exp); if(m>hj&&(hj>q||q==m))*u=hj;} \ + v+=c; u+=c; \ + } \ + ++av; ++wv; ++zv; \ + }} + +static IOCOLFT(D,jtiocold,hid(*v), hid(tl*x),hid(tr*x),!teq(*v,av[c*hj])) +static IOCOLFT(Z,jtiocolz,hid(*(D*)v),hid(tl*x),hid(tr*x),!zeq(*v,av[c*hj])) + +static JOCOLFT(D,jtjocold,hid(*v), hid(tl*x),hid(tr*x),!teq(*v,av[c*hj])) +static JOCOLFT(Z,jtjocolz,hid(*(D*)v),hid(tl*x),hid(tr*x),!zeq(*v,av[c*hj])) + +A jtiocol(J jt,I mode,A a,A w){A h,z;I ar,at,c,d,m,p,t,wr,*ws,wt;void(*fn)(); + RZ(a&&w); + ASSERT(0!=jt->ct,EVNONCE); + at=AT(a); ar=AR(a); m=*AS(a); c=aii(a); + wt=AT(w); wr=AR(w); ws=AS(w); + d=1; DO(1+wr-ar, d*=ws[i];); + RE(t=maxtype(at,wt)); + if(t!=at)RZ(a=cvt(t,a)); + if(t!=wt)RZ(w=cvt(t,w)); + p=hsize(m); + GA(h,INT,p,1,0); + GA(z,INT,AN(w),wr,ws); + switch(t){ + default: ASSERT(0,EVNONCE); + case FL: fn=mode==IICO?jtjocold:jtiocold; ctmask(jt); break; + case CMPX: fn=mode==IICO?jtjocolz:jtiocolz; ctmask(jt); break; + } + fn(jt,m,c,d,a,w,z,h); + R z; +} /* a i."1 &.|:w or a i:"1 &.|:w */
new file mode 100644 --- /dev/null +++ b/viix.c @@ -0,0 +1,161 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Interval Index, mostly by Binary Search */ + +#include "j.h" + + +#define BXLOOP(T) \ + {T*wv=(T*)AV(w),x; \ + switch((4*descend)+(0<=p?2:0)+(0<=q)){ \ + case 1: DO(m, *zv++=n*(1<*wv++);); break; /* q */ \ + case 2: DO(m, *zv++=n*(0<*wv++);); break; /* p */ \ + case 3: DO(m, x=*wv++; *zv++=x<=0?0:x<=1?q:n;); break; /* p q */ \ + case 7: DO(m, x=*wv++; *zv++=x>=1?0:x>=0?p:n;); /* p q */ \ + }} + +static B jtiixBX(J jt,I n,I m,A a,A w,I*zv){B*av,*b,descend;I p,q; + av=BAV(a); descend=av[0]>av[n-1]; + b=memchr(av,C0,n); p=b?b-av:-1; + b=memchr(av,C1,n); q=b?b-av:-1; + switch(AT(w)){ + case INT: BXLOOP(I); break; + case FL: BXLOOP(D); break; + case B01: + b=BAV(w); + switch((4*descend)+(0<=p?2:0)+(0<=q)){ + case 1: memset(zv,C0,m*SZI); break; /* q */ + case 2: DO(m, *zv++=n* *b++;); break; /* p */ + case 3: DO(m, *zv++=q* *b++;); break; /* p q */ + case 7: DO(m, *zv++=p*!*b++;); /* p q */ + }} + R 1; +} /* a I."r w where a is a boolean list */ + +static B jtiixI(J jt,I n,I m,A a,A w,I*zv){A t;B ascend;I*av,j,p,q,*tv,*u,*v,*vv,*wv,x,y; + av=AV(a); wv=AV(w); + p=av[0]; q=av[n-1]; ascend=p<=q; if(!ascend){x=p; p=q; q=x;} + GA(t,INT,1+q-p,1,0); v=AV(t); tv=v-p; vv=v+AN(t); + if(ascend){u=av; x=*u++; *v++=j=0; DO(n-1, ++j; y=*u++; ASSERT(p<=y&&y<=q&&vv>=v+y-x,EVDOMAIN); DO(y-x, *v++=j;); x=y;);} + else {u=av+n-1; x=*u--; j=n; DO(n-1, --j; y=*u--; ASSERT(p<=y&&y<=q&&vv>=v+y-x,EVDOMAIN); DO(y-x, *v++=j;); x=y;);} + if(ascend)DO(m, x=*wv++; *zv++=x<=p?0:q<x?n:tv[x];) + else DO(m, x=*wv++; *zv++=x>=q?0:p>x?n:tv[x];); + R 1; +} /* a I. w where a is a list of small range integers */ + +#define COMPVLOOP(T,c) \ + {T*u=(T*)uu,*v=(T*)vv; DO(c, if(*u!=*v){cc=*u<*v?-1:1; break;} ++u; ++v;);} +#define COMPVLOOF(T,c,COMP) \ + {T*u=(T*)uu,*v=(T*)vv; DO(c, if(cc=COMP(*u,*v))break; ++u; ++v;);} + +#define MID(k,p,q) k=(UI)(p+q)>>1 /* beware integer overflow */ + +#define BSLOOP1(CMP) \ + p=0; q=n-1; y=*wv++; \ + while(p<=q){MID(k,p,q); CMP; \ + if(b)q=k-1; else p=k+1;} +#define BSLOOPN(NE,CMP) \ + p=0; q=n-1; \ + while(p<=q){MID(k,p,q); u=av+c*k; v=wv; b=1; DO(c, x=*u++; y=*v++; if(NE){CMP; break;}); \ + if(b)q=k-1; else p=k+1;} + +#define BSLOOP(Ta,Tw) \ + {Ta*av=(Ta*)AV(a),*u,x; \ + Tw*wv=(Tw*)AV(w),*v,y; \ + switch((1==c?0:2)+(1==ge)){ \ + case 0: DO(m, BSLOOP1(b=av[k]>=y); *zv++=1+q; ); break; \ + case 1: DO(m, BSLOOP1(b=av[k]<=y); *zv++=1+q; ); break; \ + case 2: DO(m, BSLOOPN(x!=y,b=x>y); *zv++=1+q; wv+=c;); break; \ + case 3: DO(m, BSLOOPN(x!=y,b=x<y); *zv++=1+q; wv+=c;); break; \ + }} + +#define BSLOOF(Ta,Tw,COMP) \ + {Ta*av=(Ta*)AV(a),*u,x; \ + Tw*wv=(Tw*)AV(w),*v,y; \ + if(1==c) DO(m, BSLOOP1(b=ge!=COMP(av[k],y)); *zv++=1+q; ) \ + else DO(m, BSLOOPN(cc=COMP(x,y),b=gt==cc); *zv++=1+q; wv+=c;); \ + } + +#define TT(s,t) (7*(s)+(t)) + +F2(jticap2){A*av,*wv,z;B b;C*uu,*vv;I ad,ar,*as,at,c,ck,cm,ge,gt,j,k,m,n,p,q,r,t,*u,*v,wd,wr,*ws,wt,*zv;int cc; + RZ(a&&w); + ar=AR(a); at=AT(a); as=AS(a); n=ar?*as:1; r=ar?ar-1:0; + wr=AR(w); wt=AT(w); ws=AS(w); b=!AN(a)||!AN(w); + ASSERT(r<=wr,EVRANK); + u=as+ar; v=ws+wr; DO(r, ASSERT(*--u==*--v,EVLENGTH);); + ASSERT(b||HOMO(at,wt),EVDOMAIN); + ASSERT(b||at&DENSE&&wt&DENSE,EVNONCE); + t=maxtype(at,wt); + RE(m=prod(wr-r,ws)); RE(c=prod(r,ws+wr-r)); + GA(z,INT,m,wr-r,ws); zv=AV(z); + if(!m||!n||!c){DO(m, *zv++=0;); R z;} + if(1==c){ + if(at&B01&&wt&B01+INT+FL){RZ(iixBX(n,m,a,w,zv)); R z;} + if(at&INT&&wt&INT){D r; + v=AV(a); r=(D)v[n-1]-(D)v[0]; if(0>r)r=-r; + if(m+r<1.4*m*log((D)n)){RZ(iixI(n,m,a,w,zv)); R z;} + }} + jt->complt=-1; jt->compgt=1; cc=0; uu=CAV(a); vv=CAV(a)+bp(at)*c*(n-1); + switch(at){ + default: ASSERT(0,EVNONCE); + case B01: COMPVLOOP(B, c); break; + case LIT: COMPVLOOP(UC,c); break; + case INT: COMPVLOOP(I, c); break; + case FL: COMPVLOOP(D, c); break; + case CMPX: COMPVLOOP(D, c+c); break; + case C2T: COMPVLOOP(US,c); break; + case XNUM: COMPVLOOF(X, c, xcompare); break; + case RAT: COMPVLOOF(Q, c, qcompare); break; + case BOX: + av=AAV(a); ad=(I)a*ARELATIVE(a); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(c, if(cc=compare(AVR(i),AVR(i+c*(n-1))))break;); + } + ge=cc; gt=-ge; + switch(TT(at,wt)){ + case TT(B01, B01 ): BSLOOP(C, C ); break; + case TT(B01, INT ): BSLOOP(C, I ); break; + case TT(B01, FL ): BSLOOP(C, D ); break; + case TT(LIT, C2T ): BSLOOP(UC,US); break; +#if SYS & SYS_LILENDIAN + case TT(LIT, LIT ): BSLOOP(UC,UC); break; +#else + case TT(LIT, LIT ): if(1&c){BSLOOP(UC,UC); break;}else c>>=1; /* fall thru */ +#endif + case TT(C2T, C2T ): BSLOOP(US,US); break; + case TT(C2T, LIT ): BSLOOP(US,UC); break; + case TT(INT, B01 ): BSLOOP(I, C ); break; + case TT(INT, INT ): BSLOOP(I, I ); break; + case TT(INT, FL ): BSLOOP(I, D ); break; + case TT(FL, B01 ): BSLOOP(D, C ); break; + case TT(FL, INT ): BSLOOP(D, I ); break; + case TT(CMPX,CMPX): c+=c; /* fall thru */ + case TT(FL, FL ): BSLOOP(D, D ); break; + case TT(XNUM,XNUM): BSLOOF(X, X, xcompare); break; + case TT(RAT, RAT ): BSLOOF(Q, Q, qcompare); break; + case TT(BOX, BOX ): + for(j=0,cm=c*m;j<cm;j+=c){ + p=0; q=n-1; + while(p<=q){ + MID(k,p,q); ck=c*k; b=1; + DO(c, if(cc=compare(AVR(i+ck),WVR(i+j))){b=gt==cc; break;}); + if(b)q=k-1; else p=k+1; + } + *zv++=1+q; + } + break; + default: + ASSERT(at!=wt,EVNONCE); + if(t!=at)RZ(a=cvt(t,a)); + if(t!=wt)RZ(w=cvt(t,w)); + switch(t){ + case CMPX: c+=c; /* fall thru */ + case FL: BSLOOP(D,D); break; + case XNUM: BSLOOF(X,X, xcompare); break; + case RAT: BSLOOF(Q,Q, qcompare); break; + default: ASSERT(0,EVNONCE); + }} + R z; +} /* a I."r w */
new file mode 100644 --- /dev/null +++ b/visp.c @@ -0,0 +1,197 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Index-of on Sparse Arrays */ + +#include "j.h" + + +static I jtioev(J jt,I mode,A a){A ae,ax,ay,p;B*pv;I j,k,m,n,*yv;P*ap; + ap=PAV(a); + ae=SPA(ap,e); + ay=SPA(ap,i); yv=AV(ay); + ax=SPA(ap,x); m=k=AN(ax); n=j=*AS(a); + RZ(p=eq(ax,ae)); pv=BAV(p); + switch((AN(ay)?2:0)+(1==mode)){ + case 0: DO(m, if( pv[i])R i;); R m; + case 1: DO(m, --k; if( pv[k])R k;); R n-!m; + case 2: DO(m, if(i!=yv[i]||pv[i])R i;); R m; + default: DO(m, --j; --k; if(j!=yv[k]||pv[k])R j;); R m==n?n:n-m-1; +}} /* index of sparse element */ + +A jtiovxs(J jt,I mode,A a,A w){A e,x,z;B h;I at,t,wt;P*ap=0,*wp,*zp; + at=AT(a); if(SPARSE&at){at=DTYPE(at); ap=PAV(a);} + wt=DTYPE(AT(w)); wp=PAV(w); + if(h=HOMO(at,wt))t=maxtype(at,wt); + GA(z,SINT,1L,AR(w),AS(w)); zp=PAV(z); + SPB(zp,a,SPA(wp,a)); + SPB(zp,i,SPA(wp,i)); + e=SPA(wp,e); if(h&&t!=wt)RZ(e=cvt(t,e)); + x=SPA(wp,x); if(h&&t!=wt)RZ(x=cvt(t,x)); + if(ap){A ae,ax,ay,p,q;B b=0,*pv;I j,k,m,n,*v,*yv; + ay=SPA(ap,i); yv=AV(ay); + ae=SPA(ap,e); if(h&&t!=at)RZ(ae=cvt(t,ae)); + ax=SPA(ap,x); if(h&&t!=at)RZ(ax=cvt(t,ax)); if(!AN(ay))RZ(ax=ravel(ax)); + m=AN(ax); n=*AS(a); + j=ioev(mode,a); + if(equ(ae,e))SPB(zp,e,sc(j)) + else{RE(k=i0(indexofsub(mode,ax,e))); SPB(zp,e,sc(AN(ay)?(m>k?yv[k]:n):k));} + RZ(q=indexofsub(mode,ax,x)); v=AV(q); + if(AN(ay)||AN(SPA(ap,a))){ + DO(AN(x), k=*v; *v++=m>k?yv[k]:n;); + if(j<n){RZ(p=eq(ae,x)); pv=BAV(p); v=AV(q); DO(AN(x), if(pv[i])*v=j; ++v;);} + } + SPB(zp,x,q); + }else{ + if(h&&t!=at)RZ(a=cvt(t,a)); + SPB(zp,e,indexofsub(mode,a,e)); + SPB(zp,x,indexofsub(mode,a,x)); + } + R z; +} /* vector i. sparse */ + +A jtiovsd(J jt,I mode,A a,A w){A ae,ax,ay,p,z;B h,*pv;I at,j,m,n,t,wt,*v,*yv;P*ap; + ap=PAV(a); ax=SPA(ap,x); ay=SPA(ap,i); + if(!AN(ay))R indexofsub(mode,ravel(ax),w); + m=AN(ax); n=*AS(a); yv=AV(ay); ae=SPA(ap,e); + at=DTYPE(AT(a)); wt=AT(w); if(h=HOMO(at,wt))t=maxtype(at,wt); + if(h&&t!=wt)RZ(w=cvt(t,w)); + j=ioev(mode,a); + RZ(z=indexofsub(mode,ax,w)); v=AV(z); + RZ(p=eq(ae,w)); pv=BAV(p); + DO(AN(w), *v=pv[i]?j:m>*v?yv[*v]:n; ++v;); + R z; +} /* (sparse vector) i. dense */ + + +A jtindexofxx(J jt,I mode,A a,A w){A x;B*b,*c,s;I ar,d,j,m,n,wr;P*p; + RZ(a&&w); + s=1&&SPARSE&AT(a); ar=AR(a); wr=AR(w); d=wr-ar; + if(s){p=PAV(a); m=ar; n=wr;} + else {p=PAV(w); m=wr; n=ar;} + RZ(b=bfi(m,SPA(p,a),1)); b[0]=1; + GA(x,B01,n,1,0); c=BAV(x); + if(s)DO(d, c[i]=1;); + j=0; DO(MIN(ar,wr), ++j; c[n-j]=b[m-j];); + R indexofss(mode,s?a:reaxis(ifb(n,c),a),s?reaxis(ifb(n,c),w):w); +} /* dense i. sparse or sparse i. dense; 1<AR(a) */ + +static F1(jtifdz){I m; + RZ(w); + m=bp(AT(w))/sizeof(I); AN(w)*=m; *(1+AS(w))*=m; + AT(w)=INT; + R w; +} /* INT from FL or CMPX, in place */ + +static A jtioe(J jt,I mode,A w){A b,j,p,y;I c,jn,*jv,k,n;P*wp; + wp=PAV(w); + n=*AS(w); y=SPA(wp,i); + if(!AN(y))R sc(1==mode?(n?n-1:0):0); + RZ(b=eq(SPA(wp,e),SPA(wp,x))); + if(2<AR(b)){*(1+AS(b))=aii(b); AR(b)=2;} + if(1<AR(b))RZ(b=aslash1(CSTARDOT,b)); /* b=. *./@,"_1 (3$.w)=5$.w */ + RZ(y=irs2(zero,y,0L,0L,1L,jtfrom)); + RZ(p=df2(y,b,sldot(slash(ds(CSTARDOT))))); + RZ(j=repeat(not(p),repeat(ne(y,curtail(over(num[-1],y))),y))); + jn=AN(j); jv=AV(j); + if(n==jn)k=n; + else{ + if(1==mode){k=*jv-1; jv+=jn-1; c=n; DO(jn, --c; if(c!=*jv--){k=c; break;});} /* i: */ + else {k=1+jv[jn-1]; DO(jn, if(i!=*jv++){k=i; break;});} /* i. */ + } + R sc(k); +} /* index of sparse item; leading axis is sparse */ + +static B jtioresparse(J jt,B aw,A*za,A*zw){A a,e,w;B*ab,ac=0,*wb,wc=0;I ar,j,wr;P*ap,*wp; + a=*za; ar=AR(a); ap=PAV(a); RZ(ab=bfi(ar,SPA(ap,a),1)); + if(!*ab)*ab=ac=1; + if(aw){ + w=*zw; wr=AR(w); wp=PAV(w); + e=SPA(ap,e); if(!equ(e,SPA(wp,e))){RZ(w=rezero(e,w)); wp=PAV(w);} + RZ(wb=bfi(wr,SPA(wp,a),1)); + j=wr-ar; DO(ar-1, ++j; if(ab[1+i]<wb[j])ab[1+i]=ac=1; else if(ab[1+i]>wb[j])wb[j]=wc=1;); + DO(1+wr-ar, if(!wb[i])wb[i]=wc=1;); + } + if( ac)RZ(*za=reaxis(ifb(ar,ab),a)); + if(aw&&wc)RZ(*zw=reaxis(ifb(wr,wb),w)); + R 1; +} /* harmonize sparse elements and sparse axes for a and w */ + +static B jtiopart(J jt,A w,I r,I mm,I*zc,A*zi,A*zj,A*zx){A b,f,wx,x,wy,y;B*bv; + I c=*zc,d,i,j,k,m,n,nd,p,q,wr,*v,*xv;P*wp; + wr=AR(w); d=wr-r; + wp=PAV(w); wy=SPA(wp,i); wx=SPA(wp,x); n=AR(wx)-1; + RZ(b=not(irs2(wx,reshape(vec(INT,n,1+AS(wx)),SPA(wp,e)),0L,n,n,jtmatch))); + if(!all1(b)){RZ(wx=repeat(b,wx)); RZ(wy=repeat(b,wy));} + v=AV(wy); m=*AS(wy); n=*(1+AS(wy)); nd=n-d; + GA(b,B01,m,1,0); bv=BAV(b); + if (0==d){memset(bv,C0,m); if(m)*bv=1;} + else if(1==d){j=-1; DO(m, bv[i]=j!=*v; j=*v; v+=n;);} + else{ + GA(x,INT,d,1,0); xv=AV(x); *xv=-1; + DO(m, bv[i]=0; DO(d, if(xv[i]!=v[i]){bv[i]=1; j=i; DO(d-j, xv[j]=v[j]; ++j;); break;}); v+=n;) + } + if(m){RZ(f=cut(ds(CCOMMA),one)); RZ(y=df2(b,dropr(d,wy),f)); RZ(x=df2(b,wx,f));} + else{y=mtm; RZ(x=reshape(v2(0L,prod(r,AS(w)+wr-r)),wx));} + if(0>c)*zc=c=*(1+AS(y)); + else if(c!=*(1+AS(y))){RZ(y=taker(c,y)); RZ(x=taker((c/(n-d))*aii(wx),x));} + v=AV(y); k=0; q=*AS(y); + for(i=0;i<q;++i){ + j=k; k=1+j; while(k<m&&!bv[k])++k; p=nd*(k-j); + if(c<p)*v=mm; else DO(c-p, v[p+i]=mm;); + v+=c; + } + RZ(*zi=repeat(b,taker(d,wy))); + *zj=y; + *zx=x; + R 1; +} + +A jtindexofss(J jt,I mode,A a,A w){A ai,aj,ax,wi,wj,wx,x,y,z;B aw=a!=w;I ar,c,m,mm,n,r,*u,*v,wr;P*ap,*wp,*zp; + RZ(a&&w); + ar=AR(a); ap=PAV(a); + wr=AR(w); wp=PAV(w); r=1+wr-ar; + RZ(ioresparse(aw,&a,&w)); + v=AS(a); n=*v++; mm=-1; DO(ar-1, mm=MAX(mm,v[i]);); + c=-1; RZ(iopart(a,ar-1,mm,&c,&ai,&aj,&ax)); + if(aw)RZ(iopart(w,ar-1,mm,&c,&wi,&wj,&wx)); + switch(aw?(FL+CMPX&maxtype(AT(ax),AT(wx))?3:1):FL+CMPX&AT(ax)?2:0){ + case 0: x=stitch(aj,ax); break; + case 1: x=stitch(aj,ax); y=stitch(wj,wx); break; + case 2: x=stitch(aj,jt->ct?iocol(mode,ax,ax):ifdz(ax)); break; + case 3: x=stitch(aj,jt->ct?iocol(mode,ax,ax):ifdz(ax)); + y=stitch(wj,jt->ct?iocol(mode,ax,wx):ifdz(wx)); + } + RZ(x=indexofsub(mode,x,aw?y:x)); u=AV(x); + m=*AS(ai); v=AV(ai); + if(aw)DO(AN(x), u[i]=m>u[i]?v[u[i]]:n;) + else DO(AN(x), u[i]=v[u[i]];); + if(!r)R AN(x)?sc(*u):ioe(mode,a); + GA(z,SINT,1,r,AS(w)); zp=PAV(z); + SPB(zp,a,IX(r)); + SPB(zp,e,ioe(mode,a)); + SPB(zp,i,aw?wi:ai); + SPB(zp,x,x); + R z; +} /* sparse i. sparse */ + +F1(jtnubsievesp){A e,x,y,z;I c,j,m,n,r,*s,*u,*v,*vv,wr,*yv;P*p; + RZ(w); + wr=AR(w); r=jt->rank?jt->rank[1]:wr; jt->rank=0; + n=r?*(AS(w)+wr-r):1; + if(r<wr)R irs2(IX(n),irs2(w,w,0L,r,r,jtindexof),0L,1L,r?1L:0L,jteq); + RZ(x=indexof(w,w)); p=PAV(x); + y=SPA(p,i); u=AV(y); c=*AS(y); + x=SPA(p,x); v=AV(x); + e=SPA(p,e); j=*AV(e); m=j<n; + DO(c, m+=u[i]==v[i];); + GA(y,INT,m,2,0); s=AS(y); s[0]=m; s[1]=1; vv=yv=AV(y); + if(c)DO(c, if(u[i]==v[i]){if(j<u[i]){*vv++=j; j=n;} *vv++=u[i];}) + if(m&&vv<yv+m)*vv=j; + GA(z,SB01,1,1,&n); p=PAV(z); + SPB(p,a,iv0); + SPB(p,e,zero); + SPB(p,i,y); + SPB(p,x,reshape(sc(m),one)); + R z; +}
new file mode 100644 --- /dev/null +++ b/vm.c @@ -0,0 +1,130 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: "Mathematical" Functions (Irrational, Transcendental, etc.) */ + +#include "j.h" +#include "ve.h" + +static D jtintpow(J jt,D x,I n){D r=1; + if(0>n){x=1/x; if(n==IMIN){r=x; n=IMAX;} else n=-n;} + while(n){if(1&n)r*=x; x*=x; n>>=1;} + R r; +} /* x^n where x is real and n is integral */ + +static D jtpospow(J jt,D x,D y){ + if(0==y)R 1.0; + if(0==x)R 0<y?0.0:inf; + if(0<x){ + if(y== inf)R 1<x?inf:1>x?0.0:1.0; + if(y==-inf)R 1<x?0.0:1>x?inf:1.0; + R exp(y*log(x)); + } + if(y==-inf){ASSERT(-1>x,EVDOMAIN); R 0.0;} + if(y== inf){ASSERT(-1<x,EVDOMAIN); R 0.0;} + jt->jerr=EWIMAG; + R 0; +} /* x^y where x and y are real and x is non-negative */ + +#define POWXB(u,v) (v?u:1) +#define POWBX(u,v) (u?1.0:v<0?inf:!v) +#define POWII(u,v) intpow((D)u,v) +#define POWID(u,v) pospow((D)u,v) + +APFX(powBI, D,B,I, POWBX ) +APFX(powBD, D,B,D, POWBX ) +APFX(powIB, I,I,B, POWXB ) +APFX(powII, D,I,I, POWII ) +APFX(powID, D,I,D, POWID ) +APFX(powDB, D,D,B, POWXB ) +APFX(powDI, D,D,I, intpow) +APFX(powDD, D,D,D, pospow) +APFX(powZZ, Z,Z,Z, zpow ) + +ANAN(cirZZ, Z,Z,Z, zcir ) + +static void jtcirx(J jt,I n,I k,D*z,D*y){D p,t; + NAN0; + switch(k){ + default: ASSERTW(0,EWIMAG); + case 0: DO(n, t=*y++; ASSERTW( -1.0<=t&&t<=1.0, EWIMAG ); *z++=sqrt(1.0-t*t);); break; + case 1: DO(n, t=*y++; ASSERTW(-THMAX<t&&t<THMAX,EVLIMIT); *z++=sin(t);); break; + case 2: DO(n, t=*y++; ASSERTW(-THMAX<t&&t<THMAX,EVLIMIT); *z++=cos(t);); break; + case 3: DO(n, t=*y++; ASSERTW(-THMAX<t&&t<THMAX,EVLIMIT); *z++=tan(t);); break; + case 4: DO(n, t=*y++; *z++=t<-1e8?-t:1e8<t?t:sqrt(t*t+1.0);); break; + case 5: DO(n, t=*y++; *z++=t<-EMAX2?infm:EMAX2<t?inf:sinh(t);); break; + case 6: DO(n, t=*y++; *z++=t<-EMAX2|| EMAX2<t?inf:cosh(t);); break; + case 7: DO(n, t=*y++; *z++=t<-TMAX?-1:TMAX<t?1:tanh(t);); break; + case -1: DO(n, t=*y++; ASSERTW( -1.0<=t&&t<=1.0, EWIMAG ); *z++=asin(t);); break; + case -2: DO(n, t=*y++; ASSERTW( -1.0<=t&&t<=1.0, EWIMAG ); *z++=acos(t);); break; + case -3: DO(n, *z++=atan(*y++);); break; + case -4: DO(n, t=*y++; ASSERTW(t<=-1.0||1.0<=t, EWIMAG ); *z++=t<-1e8||1e8<t?t:t==-1?0:(t+1)*sqrt((t-1)/(t+1));); break; + case -5: p=log(2.0); + DO(n, t=*y++; *z++=1.0e8<t?p+log(t):-7.8e3>t?-(p+log(-t)):log(t+sqrt(t*t+1.0));); break; + case -6: p=log(2.0); + DO(n, t=*y++; ASSERTW( 1.0<=t, EWIMAG ); *z++=1.0e8<t?p+log(t):log(t+sqrt(t*t-1.0));); break; + case -7: DO(n, t=*y++; ASSERTW( -1.0<=t&&t<=1.0, EWIMAG ); *z++=0.5*log((1.0+t)/(1.0-t));); break; + case 9: DO(n, *z++=*y++;); break; + case 10: DO(n, t=*y++; *z++=ABS(t);); break; + case 11: DO(n, *z++=0.0;); break; + case 12: DO(n, *z++=0<=*y++?0.0:PI;); break; + } + NAN1V; +} + +AHDR2(cirBD,D,B,D){ASSERTW(b&&1==m,EWIMAG); cirx(n,(I)*x,z,y);} +AHDR2(cirID,D,I,D){ASSERTW(b&&1==m,EWIMAG); cirx(n, *x,z,y);} + +AHDR2(cirDD,D,D,D){I k=(I)jfloor(0.5+*x); + ASSERTW(k==*x,EVDOMAIN); + ASSERTW(b&&1==m,EWIMAG); + cirx(n,k,z,y); +} + + +F2(jtlogar2){A z;I t; + RZ(a&&w); + t=maxtype(AT(a),AT(w)); + if(!(t&XNUM)||jt->xmode==XMEXACT){jt->xmode=XMEXACT; R divide(logar1(w),logar1(a));} + z=rank2ex(cvt(XNUM,a),cvt(XNUM,w),0L,0L,0L,jtxlog2a); + if(z)R z; + if(jt->jerr==EWIMAG||jt->jerr==EWIRR){RESETERR; jt->xmode=XMEXACT; R divide(logar1(w),logar1(a));} + R 0; +} + +F2(jtroot){A z;I t; + RZ(a&&w); + t=maxtype(AT(a),AT(w)); + if(!(t&XNUM))R expn2(cvt(t,w),recip(cvt(t,a))); + z=rank2ex(cvt(XNUM,a),cvt(XNUM,w),0L,0L,0L,jtxroota); + switch(jt->jerr){ + case EWIMAG: RESETERR; R expn2(cvt(CMPX,w),recip(cvt(CMPX,a))); + case EWIRR: RESETERR; R expn2(cvt(FL, w),recip(cvt(FL, a))); + default: R z; +}} + +F1(jtjdot1){R tymes(a0j1,w);} +F2(jtjdot2){R plus(a,tymes(a0j1,w));} +F1(jtrdot1){R expn1(jdot1(w));} +F2(jtrdot2){R tymes(a,rdot1(w));} + + +F1(jtpolar){RZ(w); R cvt(SPARSE&AT(w)?SFL:FL,df2(v2(10L,12L),w,qq(ds(CCIRCLE),v2(1L,0L))));} + +F1(jtrect){A e,z;B b;I r,t;P*wp,*zp;Z c; + RZ(w); + t=AT(w); r=AR(w); jt->rank=0; + ASSERT(!AN(w)||t&NUMERIC,EVDOMAIN); + if(t&CMPX){GA(z,FL,2*AN(w),1+r,AS(w)); *(AS(z)+r)=2; MC(AV(z),AV(w),AN(z)*sizeof(D)); R z;} + else if(t&SPARSE){ + b=1&&t&SCMPX; + GA(z,b?SFL:t,1,1+r,AS(w)); *(AS(z)+r)=2; + wp=PAV(w); zp=PAV(z); + if(b){e=SPA(wp,e); c=*ZAV(e); ASSERT(FEQ(c.re,c.im),EVSPARSE); SPB(zp,e,scf(c.re));} + else SPB(zp,e,ca(SPA(wp,e))); + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,i,ca(SPA(wp,i))); + SPB(zp,x,rect(SPA(wp,x))); + R z; + }else R df2(w,zero,qq(ds(CCOMMA),zero)); +}
new file mode 100644 --- /dev/null +++ b/vo.c @@ -0,0 +1,261 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Box & Open */ + +#include "j.h" + + +I level(A w){A*wv;I d,j,wd; + if(!(AN(w)&&AT(w)&BOX+SBOX))R 0; + d=0; wv=AAV(w); wd=(I)w*ARELATIVE(w); + DO(AN(w), j=level(WVR(i)); if(d<j)d=j;); + R 1+d; +} + +F1(jtlevel1){RZ(w); R sc(level(w));} + +F1(jtbox0){R irs1(w,0L,0L,jtbox);} + +F1(jtbox){A y,z,*zv;C*wv,*yv;I f,k,m,n,r,wr,*ws; + RZ(w); + ASSERT(!(SPARSE&AT(w)),EVNONCE); + ws=AS(w); wr=AR(w); r=jt->rank?jt->rank[1]:wr; f=wr-r; + RE(n=prod(f,ws)); if(n)m=AN(w)/n; else RE(m=prod(r,f+ws)); + k=m*bp(AT(w)); wv=CAV(w); + GA(z,BOX,n,f,ws); zv=AAV(z); + if(f){ + GA(y,AT(w),m,r,f+ws); yv=CAV(y); + if(ARELATIVE(w)){A*v=(A*)wv;A1*u=(A1*)yv; DO(n, DO(m, u[i]=AABS(*v++,w);); RZ(zv[i]=ca(y)););} + else DO(n, MC(yv,wv,k); wv+=k; RZ(zv[i]=ca(y));); + }else RZ(*zv=rat(w)); + R z; +} /* <"r w */ + +F1(jtboxopen){RZ(w); R AN(w)&&BOX&AT(w)?rat(w):box(w);} + +F2(jtlink){RZ(a&&w); R over(box(a),AN(w)&&AT(w)&BOX?rat(w):box(w));} + +static B povtake(A a,A w,C*x){B b;C*v;I d,i,j,k,m,n,p,q,r,*s,*ss,*u,*uu,y; + RZ(w); + r=AR(w); n=AN(w); k=bp(AT(w)); v=CAV(w); + if(1>=r){MC(x,v,k*n); R 1;} + m=AN(a); u=AV(a); s=AS(w); + p=0; d=1; DO(r, if(u[m-1-i]==s[r-1-i]){d*=s[r-1-i]; ++p;}else break;); + b=0; DO(r-p, if(b=1<s[i])break;); + if(!b){MC(x,v,k*n); R 1;} + k*=d; n/=d; ss=s+r-p; uu=u+m-p; + for(i=0;i<n;++i){ + y=0; d=1; q=i; /* y=.a#.((-$a){.(($a)$1),$w)#:i */ + s=ss; u=uu; DO(r-p, j=*--s; y+=q%j*d; d*=*--u; q/=j;); + MC(x+y*k,v,k); v+=k; + } + R 1; +} + +static B jtopes1(J jt,B**zb,A*za,A*ze,I*zm,A cs,A w){A a,e=0,q,*wv,x;B*b;I i,k,m=0,n,*v,wcr;P*p; + n=AN(w); wcr=AN(cs); wv=AAV(w); + GA(x,B01,wcr,1,0); b=BAV(x); memset(b,C0,wcr); + for(i=0;i<n;++i) + if(q=wv[i],SPARSE&AT(q)){ + p=PAV(q); x=SPA(p,x); m+=*AS(x); + if(!e)e=SPA(p,e); else ASSERT(equ(e,SPA(p,e)),EVSPARSE); + k=wcr-AR(q); DO(k, b[i]=1;); a=SPA(p,a); v=AV(a); DO(AN(a), b[k+*v++]=1;); + } + RZ(*za=ifb(wcr,b)); /* union of sparse axes */ + *zb=b; /* mask corresp. to sparse axes */ + *ze=e?e:zero; /* sparse element */ + *zm=m; /* estimate # of non-sparse cells */ + R 1; +} + +static B jtopes2(J jt,A*zx,A*zy,B*b,A a,A e,A q,I wcr){A x;B*c;I dt,k,r,*s,t;P*p; + dt=AT(e); r=AR(q); k=wcr-r; t=AT(q); + if(t&SPARSE){ + p=PAV(q); + RZ(c=bfi(r,SPA(p,a),1)); + DO(r, if(b[k+i]!=c[i]){RZ(q=reaxis(ifb(r,k+b),q)); break;}); + }else{ + if(k){ + GA(x,t,AN(q),wcr,0); s=AS(x); DO(k, *s++=1;); ICPY(s,AS(q),r); + MC(AV(x),AV(q),AN(q)*bp(t)); q=x; + } + RZ(q=sparseit(t&dt?q:cvt(dt,q),a,e)); + } + p=PAV(q); + x=SPA(p,x); if(!(dt&AT(x)))RZ(x=cvt(dt,x)); + *zx=x; /* data cells */ + *zy=SPA(p,i); /* corresp. index matrix */ + R 1; +} + +static A jtopes(J jt,I zt,A cs,A w){A a,d,e,sh,t,*wv,x,x1,y,y1,z;B*b;C*xv;I an,*av,c,dk,dt,*dv,i,j,k,m,m1,n, + p,*s,*v,wcr,wr,xc,xk,yc,*yv,*zs;P*zp; + n=AN(w); wr=AR(w); wv=AAV(w); wcr=AN(cs); dt=DTYPE(zt); dk=bp(dt); + RZ(opes1(&b,&a,&e,&m,cs,w)); an=AN(a); av=AV(a); + GA(z,zt,1L,wr+wcr,0); zs=AS(z); ICPY(zs,AS(w),wr); ICPY(zs+wr,AV(cs),wcr); + zp=PAV(z); c=wcr-an; yc=wr+an; + SPB(zp,e,e=cvt(dt,e)); + GA(t,INT,yc, 1L,0L); v=AV(t); DO(wr, v[i]=i;); DO(an, v[wr+i]=wr+av[i];); SPB(zp,a,t); + GA(sh,INT,1+c,1L,0L); s=AV(sh); s[0]=m; j=1; DO(wcr, if(!b[i])s[j++]=zs[wr+i];); + RE(xc=prod(c,1+s)); xk=xc*dk; + GA(d,INT,wr,1,0); dv=AV(d); memset(dv,C0,wr*SZI); + RE(i=mult(m,xc)); GA(x,dt, i,1+c,s); xv=CAV(x); mvc(m*xk,xv,dk,AV(e)); + RE(i=mult(m,yc)); GA(y,INT,i,2L, 0L); v=AS(y); *v=m; v[1]=yc; yv=AV(y); memset(yv,C0,SZI*i); + for(i=p=0;i<n;++i){ + RZ(opes2(&x1,&y1,b,a,e,wv[i],wcr)); v=AS(y1); m1=v[0]; k=v[1]; + if(m<p+m1){ + j=m; m=(i<n-1?m+m:0)+p+m1; + RZ(x=take(sc(m),x)); xv=CAV(x)+p*xk; mvc(xk*(m-j),xv,dk,AV(e)); + RZ(y=take(sc(m),y)); yv= AV(y)+p*yc; + } + for(j=wr-1;j;--j)if(dv[j]==zs[j]){dv[j]=0; ++dv[j-1];}else break; + v=AV(y1); DO(m1, ICPY(yv,dv,wr); ICPY(yv+yc-k,v,k); yv+=yc; v+=k;); + if(memcmp(1+AS(x1),1+s,SZI*c)){*s=m1; povtake(sh,x1,xv);} else MC(xv,AV(x1),m1*xk); + ++dv[wr-1]; xv+=m1*xk; p+=m1; + } + SPB(zp,x,p==m?x:take(sc(p),x)); + SPB(zp,i,p==m?y:take(sc(p),y)); + R z; +} + +F1(jtope){PROLOG;A cs,*v,y,z;B b,c,h=1;C*x;I d,i,k,m,n,*p,q=RMAX,r=0,*s,t=0,*u,zn; + RZ(w); + n=AN(w); v=AAV(w); b=ARELATIVE(w); + if(!(n&&BOX&AT(w)))R ca(w); /* {GA(z,B01,0L,1+AR(w),AS(w)); *(AR(w)+AS(w))=0; R z;} */ + if(!AR(w))R b?(A)AABS(*v,w):*v; + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; + q=MIN(q,AR(y)); + r=MAX(r,AR(y)); + if(AN(y)){ + k=AT(y); t=t?t:k; m=t|k; + if(t!=k){h=0; ASSERT(HOMO(t,k)&&!(m&SPARSE&&m&XNUM+RAT),EVDOMAIN); t=maxtype(t,k);} + }} + if(!t)DO(n, y=b?(A)AABS(v[i],w):v[i]; k=AT(y); RE(t=maxtype(t,k));); + GA(cs,INT,r,1,0); u=AV(cs); DO(r-q, u[i]=1;); p=u+r-q; DO(q, p[i]=0;); + DO(n, y=b?(A)AABS(v[i],w):v[i]; s=AS(y); p=u+r-AR(y); DO(AR(y),p[i]=MAX(p[i],s[i]););); + if(t&SPARSE)RZ(z=opes(t,cs,w)) + else{ + RE(m=prod(r,u)); RE(zn=mult(n,m)); k=bp(t); q=m*k; + GA(z,t,zn,r+AR(w),AS(w)); ICPY(AS(z)+AR(w),u,r); x=CAV(z); + c=b&&t&BOX; + if(c){AFLAG(z)=AFREL; p=AV(z); d=AREL(mtv,z); DO(zn, *p++=d;);} else fillv(t,zn,x); + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; + if(ARELATIVE(y))RZ(y=relocate((I)y-c*(I)z,ca(y))); + if(h&&1>=r) MC(x,AV(y),k*AN(y)); + else if(t==AT(y)&&m==AN(y))MC(x,AV(y),q); + else if(AN(y)) RZ(povtake(cs,t==AT(y)?y:cvt(t,y),x)); + x+=q; + }} + EPILOG(z); +} + +static A jtrazeg(J jt,A w,I t,I n,I r,A*v,B zb){A h,h1,x,y,*yv,z,*zv;B b;C*zu;I c=0,d,i,j,k,m,p,q,*s,*v1,yr,*ys; + k=bp(t); d=SZI*(r-1); b=ARELATIVE(w); + GA(h,INT,r,1,0); s=AV(h); memset(s,C0,r*SZI); + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; yr=AR(y); ys=AS(y); c+=r==yr?*ys:1; ASSERT(0<=c,EVLIMIT); j=r-yr; + if(!yr)continue; + DO(j, s[i]=MAX(1, s[i]); ); + DO(yr, s[j]=MAX(ys[i],s[j]); ++j;); + } + *s=c; m=prod(r,s); p=c?k*m/c:0; + GA(h1,INT,r,1,0); v1=AV(h1); + GA(z,t,m,r,s); if(zb)AFLAG(z)=AFREL; + zu=CAV(z); zv=AAV(z); + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; + if(t!=AT(y))RZ(y=cvt(t,y)); + yr=AR(y); ys=AS(y); + if(!yr){ + if(t&BOX){x=(A)(*AV(y)+ARELATIVE(y)*(I)y-zb*(I)z); DO(p/SZA, *zv++=x;);} + else {mvc(p,zu,k,AV(y)); zu+=p;} + continue; + } + if(j=r-yr){DO(j,v1[i]=1;); ICPY(j+v1,ys,yr); RZ(y=reshape(h1,y));} + if(memcmp(1+s,1+AS(y),d)){*s=IC(y); RZ(y=take(h,y));} + if(t&BOX){yv=AAV(y); q=ARELATIVE(y)*(I)y-zb*(I)z; DO(AN(y), *zv++=(A)((I)yv[i]+q););} + else {j=k*AN(y); MC(zu,AV(y),j); zu+=j;} + } + R z; +} /* raze general case */ + +F1(jtraze){A*v,y,*yv,z,*zv;B b,zb;C*zu;I d,i,k,m=0,n,q,r=1,*s=0,t=0,yt; + RZ(w); + n=AN(w); v=AAV(w); b=ARELATIVE(w); zb=b; + if(!n)R mtv; + if(!(BOX&AT(w)))R ravel(w); + if(1==n){RZ(z=b?(A)AABS(*v,w):*v); R AR(z)?z:ravel(z);} + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; m+=d=AN(y); r=MAX(r,AR(y)); + if(d){ + yt=AT(y); + if(t){ASSERT(HOMO(t,yt),EVDOMAIN); t=maxtype(t,yt);}else t=yt; + zb=zb||ARELATIVE(y); + }} + if(!t)DO(n, y=b?(A)AABS(v[i],w):v[i]; t=MAX(t,AT(y));); + k=bp(t); + if(1<r)R razeg(w,t,n,r,v,zb); + GA(z,t,m,r,0); if(zb&&!(t&DIRECT))AFLAG(z)=AFREL; + zu=CAV(z); zv=AAV(z); + for(i=0;i<n;++i){ + y=b?(A)AABS(v[i],w):v[i]; + if(AN(y)){ + if(t&BOX){yv=AAV(y); q=ARELATIVE(y)*(I)y-zb*(I)z; DO(AN(y), *zv++=(A)((I)yv[i]+q););} + else {if(t!=AT(y))RZ(y=cvt(t,y)); d=k*AN(y); MC(zu,AV(y),d); zu+=d;} + }} + R z; +} + +F1(jtrazeh){A*wv,y,z;C*xv,*yv,*zv;I c=0,ck,dk,i,k,n,p,r,*s,t,wd; + RZ(w); + ASSERT(BOX&AT(w),EVDOMAIN); + if(!AR(w))R ope(w); + n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); y=WVR(0); p=IC(y); t=AT(y); k=bp(t); + DO(n, y=WVR(i); r=AR(y); ASSERT(p==IC(y),EVLENGTH); ASSERT(r&&r<=2&&t==AT(y),EVNONCE); c+=1==r?1:*(1+AS(y));); + GA(z,t,p*c,2,0); s=AS(z); *s=p; *(1+s)=c; + zv=CAV(z); ck=c*k; + for(i=0;i<n;++i){ + y=WVR(i); dk=1==AR(y)?k:k**(1+AS(y)); xv=zv; zv+=dk; + if(!dk)continue; + if(wd&&t&BOX)RZ(y=car(y)); + yv=CAV(y); + switch(0==(I)xv%dk&&0==ck%dk?dk:0){ + case sizeof(I): {I*u,*v=(I*)yv; DO(p, u=(I*)xv; *u=*v++; xv+=ck;);} break; + case sizeof(S): {S*u,*v=(S*)yv; DO(p, u=(S*)xv; *u=*v++; xv+=ck;);} break; + case sizeof(C): DO(p, *xv=*yv++; xv+=ck;); break; + default: DO(p, MC(xv,yv,dk); yv+=dk; xv+=ck;); + }} + R z; +} /* >,.&.>/,w */ + + +#define EXTZ if(vv<=d+v){m=v-CAV(z); RZ(z=ext(0,z)); v=m+CAV(z); vv=CAV(z)+k*AN(z);} + +F2(jtrazefrom){A*wv,y,z;B b;C*v,*vv;I an,c,d,i,j,k,m,n,r,*s,t,*u,wn; + RZ(a&&w); + an=AN(a); wn=AN(w); + if(b=NUMERIC&AT(a)&&1==AR(a)&&BOX&AT(w)&&!ARELATIVE(w)&&1==AR(w)&&1<wn&&an>10*wn){ + wv=AAV(w); y=*wv; r=AR(y); s=1+AS(y); n=B01&AT(a)?2:wn; + for(i=m=t=0;b&&i<n;++i){ + y=wv[i]; b=r==AR(y)&&!(1<r&&ICMP(s,1+AS(y),r-1)); + if(AN(y)){m+=AN(y); if(t)b=b&&t==AT(y); else t=AT(y);} + }} + if(!(b&&t&DIRECT))R raze(from(a,w)); + c=aii(y); k=bp(t); + RZ(z=exta(t,r,c,(I)((1.2*an*m)/(n*c)))); u=AS(z); *u++=AN(z)/c; DO(r-1, *u++=*s++;); + v=CAV(z); vv=v+k*AN(z); + if(B01&AT(a)){B*av=BAV(a); + for(i=0;i<an;++i){ + y=wv[*av++]; d=k*AN(y); EXTZ; MC(v,AV(y),d); v+=d; + }}else{I*av; + RZ(a=vi(a)); av=AV(a); + for(i=0;i<an;++i){ + j=*av++; if(0>j){j+=wn; ASSERT(0<=j,EVINDEX);}else ASSERT(j<wn,EVINDEX); + y=wv[j]; d=k*AN(y); EXTZ; MC(v,AV(y),d); v+=d; + }} + AN(z)=(v-CAV(z))/k; *AS(z)=AN(z)/c; + R z; +} /* a ;@:{ w */
new file mode 100644 --- /dev/null +++ b/vp.c @@ -0,0 +1,136 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Permutations */ + +#include "j.h" + + +static I jtord(J jt,A w){I j,n,*v,z; + RZ(w); + n=AN(w); z=-n; + if(n){if(!(INT&AT(w)))RZ(w=cvt(INT,w)); v=AV(w); DO(n, j=*v++; if(z<j)z=j;); ++z;} + R z; +} + +F1(jtpinv){I m=0,n,*v; + F1RANK(1,jtpinv,0); + RZ(w=vi(w)); + n=AN(w); v=AV(w); + DO(n, m=0>v[i]?MAX(m,-1-v[i]):MAX(m,v[i]);); m+=0<n; + R indexof(pfill(m,w),IX(m)); +} /* permutation inverse */ + +A jtpind(J jt,I n,A w){A z;I j,m,*v; + RE(n); RZ(w); + m=-n; + RZ(z=ca(vi(w))); v=AV(z); + DO(AN(z), j=*v; ASSERT(m<=j&&j<n,EVINDEX); *v++=0>j?j+n:j;); + R z; +} /* positive indices */ + +A jtpfill(J jt,I n,A w){PROLOG;A b,z;B*bv,*v;I*wv,*zv; + RZ(w=pind(n,w)); wv=AV(w); + GA(z,INT,n,1,0); zv=AV(z); + GA(b,B01,n,1,0); bv=BAV(b); memset(bv,C1,n); + DO(AN(w), v=bv+wv[i]; ASSERT(*v,EVINDEX); *v=0;); + DO(n, if(bv[i])*zv++=i;); ICPY(zv,wv,AN(w)); + EPILOG(z); +} + +static F1(jtcfd){A b,q,x,z,*zv;B*bv;I c,i,j,n,*qv,*u,*v,zn; + RZ(w); + if(c=1&&INT&AT(w)){ + n=AN(w); v=AV(w); + GA(b,B01,1+n,1,0); bv=BAV(b); memset(bv,C0,n); + DO(n, j=v[i]; if(j<0||n<=j||bv[j]){c=0; break;} bv[j]=1;); + } + if(!c){n=ord(w); RZ(w=pfill(n,w)); v=AV(w); GA(b,B01,1+n,1,0);} + bv=BAV(b); memset(bv,C0,1+n); ++bv; + i=0; j=n-1; zn=(I)(log((D)n)+1.6); + GA(q,INT,n, 1,0); qv= AV(q); + GA(z,BOX,zn,1,0); zv=AAV(z); + while(1){ + while(bv[j])--j; if(0>j)break; + u=qv; c=j; + do{bv[c]=1; *u++=c; c=v[c];}while(c!=j); + if(i==zn){RZ(z=ext(0,z)); zv=AAV(z); zn=AN(z);} + RZ(zv[i++]=vec(INT,u-qv,qv)); + } + AN(z)=*AS(z)=zn=i; j=zn-1; DO(zn/2, x=zv[i]; zv[i]=zv[j]; zv[j]=x; --j;); + R z; +} /* cycle from direct */ + +static A jtdfc(J jt,I n,A w){PROLOG;A b,q,*wv,z;B*bv;I c,j,qn,*qv,*x,wd; + RE(n); RZ(w); + ASSERT(0<=n,EVINDEX); + GA(b,B01,n,1,0); bv=BAV(b); memset(bv,C1,n); + RZ(z=IX(n)); x=AV(z); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + for(j=AN(w)-1;0<=j;j--){ + RZ(q=pind(n,WVR(j))); qv=AV(q); qn=AN(q); + if(!qn)continue; + DO(qn, ASSERT(bv[qv[i]],EVINDEX); bv[qv[i]]=0;); DO(qn,bv[qv[i]]=1;); + c=x[qv[0]]; DO(qn-1,x[qv[i]]=x[qv[i+1]];); x[qv[qn-1]]=c; + } + EPILOG(z); +} /* direct from cycle */ + +F1(jtcdot1){F1RANK(1,jtcdot1,0); R BOX&AT(w)?dfc(ord(raze(w)),w):cfd(w);} + +F2(jtcdot2){A p; + F2RANK(1,RMAX,jtcdot2,0); + RZ(p=BOX&AT(a)?dfc(IC(w),a):pfill(IC(w),a)); + R AR(w)?from(p,w):w; +} + +F1(jtpparity){A x,y,z;B p,*u;I i,j,k,m,n,r,*s,*v,*zv; + RZ(x=cvt(INT,w)); + r=AR(x); s=AS(x); n=r?*(s+r-1):1; RE(m=prod(r-1,s)); v=AV(x); + GA(y,B01,n,1,0); u=BAV(y); + GA(z,INT,m,r?r-1:0,s); zv=AV(z); + for(i=0;i<m;++i){ + j=p=0; memset(u,C1,n); + DO(n, k=v[i]; if(0>k)v[i]=k+=n; if(0<=k&&k<n&&u[k])u[k]=0; else{j=1+n; break;}); + for(;j<n;++j)if(j!=v[j]){k=j; DO(n-j-1, ++k; if(j==v[k]){v[k]=v[j]; p=!p; break;});} + zv[i]=p?-1:j==n; + v+=n; + } + R z; +} /* permutation parity; # interchanges to get i.n */ + +static F1(jtdfr){A z;I c,d,i,j,m,n,*v,*x; + RZ(w); + n=*(AS(w)+AR(w)-1); m=n?AN(w)/n:0; v=AV(w); + GA(z,INT,AN(w),AR(w),AS(w)); x=AV(z); + for(i=0;i<m;++i){ + DO(n, x[i]=i;); + DO(n-1, j=i; c=x[j+v[j]]; DO(1+v[j], d=x[j+i]; x[j+i]=c; c=d;);); + x+=n; v+=n; + } + R z; +} /* direct from reduced */ + +static F1(jtrfd){A z;I j,k,n,r,*s,*x; + RZ(z=ca(w)); x=AV(z); + r=AR(w); s=AS(w); + if(n=s[r-1])DO(AN(w)/n, j=n-1; ++x; DO(n-1, k=0; DO(j--, k+=*x>x[i];); *x++=k;);); + R z; +} /* reduced from direct */ + +F1(jtadot1){A y;I n; + F1RANK(1,jtadot1,0); + RZ(y=BOX&AT(w)?cdot1(w):pfill(ord(w),w)); + n=IC(y); + R base2(cvt(XNUM,apv(n,n,-1L)),rfd(y)); +} + +F2(jtadot2){A m,p;I n; + RZ(a&&w); + n=IC(w); p=sc(n); if(XNUM&AT(a))p=cvt(XNUM,p); RZ(m=fact(p)); + ASSERT(all1(le(negate(m),a))&&all1(lt(a,m)),EVINDEX); + if(!AR(w)){RZ(vi(a)); R ca(w);} + RZ(p=dfr(vi(abase2(apv(n,n,-1L),a)))); + R equ(w,IX(n))?p:from(p,w); +} +
new file mode 100644 --- /dev/null +++ b/vq.c @@ -0,0 +1,132 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Rational Numbers */ + +#include "j.h" +#include "ve.h" + + +QF1(jtqstd){I d,n;Q z;X g; + QRZ(w.n&&w.d&&!jt->jerr); + n=XDIG(w.n); d=XDIG(w.d); z.d=xone; + if(0>d){QRE(w.n=negate(w.n)); QRE(w.d=negate(w.d)); n=-n; d=-d;} + if(!n){z.n=xzero; R z;} + if(!d){z.n=vci(0<n?XPINF:XNINF); R z;} + if(d==XPINF){QASSERT(n!=XPINF&&n!=XNINF,EVNAN); R zeroQ;} + if(n==XPINF||n==XNINF){z.n=w.n; R z;} + QRE(g=xgcd(w.n,w.d)); + if(QX1(g))R w; + z.n=xdiv(w.n,g,XMEXACT); + z.d=xdiv(w.d,g,XMEXACT); + R z; +} + +QF2(jtqplus){PROLOG;Q z; + z.n=xplus(xtymes(a.n,w.d),xtymes(w.n,a.d)); + z.d=xtymes(a.d,w.d); + QEPILOG(z); +} + +QF2(jtqminus){PROLOG;Q z; + z.n=xminus(xtymes(a.n,w.d),xtymes(w.n,a.d)); + z.d=xtymes(a.d,w.d); + QEPILOG(z); +} + +QF2(jtqtymes){PROLOG;Q z; + z.n=xtymes(a.n,w.n); + z.d=xtymes(a.d,w.d); + QEPILOG(z); +} + +QF2(jtqdiv){PROLOG;Q z; + z.n=xtymes(a.n,w.d); + z.d=xtymes(a.d,w.n); + QEPILOG(z); +} + +static QF2(jtqrem){PROLOG;I c,d;Q m,q,z; + c=XDIG(a.n); + d=XDIG(w.n); + if(!c)R w; + QASSERT(!(d==XPINF||d==XNINF),EVNAN); + if(c==XPINF)R 0<=d?w:a; + if(c==XNINF)R 0>=d?w:a; + q=qdiv(w,a); + m.n=xtymes(a.n,xdiv(q.n,q.d,XMFLR)); m.d=a.d; + z=qminus(w,m); + QEPILOG(z); +} + +static QF2(jtqgcd){PROLOG;Q z; + QRE(z.n=xgcd(a.n,w.n)); + QRE(z.d=xlcm(a.d,w.d)); + QEPILOG(z); +} + +static QF2(jtqlcm){R qtymes(a,qdiv(w,qgcd(a,w)));} + +static QF2(jtqpow){PROLOG;B c;I p,q,s;Q t,z;X d; + QRE(1); + t=a; d=w.n; z.n=z.d=xone; + p=XDIG(a.n); q=XDIG(w.n); c=QX1(w.d); + if(p==XPINF||p==XNINF){ + QASSERT(0<p||q!=XPINF,EVDOMAIN); + z.n=vci(!q?1L:0>q?0L:0<p?p:1&(*AV(w.n))?XNINF:XPINF); + R z; + } + if(q==XPINF||q==XNINF){ + s=xcompare(mag(a.n),a.d); + QASSERT(0<=p||0>s&&q==XPINF||0<s&&q==XNINF,EVDOMAIN); + z.n=vci(!s?1L:!p&&0>q||0<s&&p&&0<q||0>s&&0>q?XPINF:0L); + R z; + } + QASSERT(c||0<=p,EWIMAG); + QASSERT(c||QX1(a.d)&&1==AN(a.n)&&(0==p||1==p),EWIRR); + if(0>XDIG(d)){QRE(d=negate(d)); QRE(t=qdiv(z,t));} + if(1>xcompare(d,xc(IMAX))){I e; + QRE(e=xint(d)); + while(e){if(1&e)QRE(z=qtymes(z,t)); QRE(t=qtymes(t,t)); e>>=1;} + }else{X e=d,x2; + QRE(x2=xc(2L)); + while(XDIG(e)){ + if(1&*AV(e))QRE(z=qtymes(z,t)); + QRE(t=qtymes(t,t)); + QRE(e=xdiv(e,x2,XMFLR)); + }} + QEPILOG(z); +} + +int jtqcompare(J jt,Q a,Q w){R QCOMP(a,w);} + +static X jtqbin(J jt,Q a,Q w){ASSERT(QX1(a.d)&&QX1(w.d),EWIRR); R xbin(a.n,w.n);} + +static D jtqlogd1(J jt,Q w){ASSERT(0<=XDIG(w.n),EWIMAG); R xlogabs(w.n)-xlogabs(w.d);} + +static Z jtqlogz1(J jt,Q w){Z z; z.re=xlogabs(w.n)-xlogabs(w.d); z.im=0>XDIG(w.n)?PI:0.0; R z;} + + +#define QSQRT(x) z->n=xsqrt(x->n); z->d=xsqrt(x->d); if(jt->jerr)R; +#define QFACT(x) ASSERTW(QX1(x->d),EWIRR); *z=xfact(x->n); + +AMON(floorQ, X,Q, *z=xdiv(x->n,x->d,XMFLR );) +AMON( ceilQ, X,Q, *z=xdiv(x->n,x->d,XMCEIL);) +AMON( sgnQ, X,Q, *z=xsgn(x->n); ) +AMON( absQ, Q,Q, z->n=mag(x->n); z->d=x->d;) +AMON( sqrtQ, Q,Q, QSQRT(x)) +AMON( factQ, X,Q, QFACT(x)) +AMON( logQD, D,Q, *z=qlogd1(*x);) +AMON( logQZ, Z,Q, *z=qlogz1(*x);) + +APFX( maxQQ, Q,Q,Q, QMAX ) +APFX( minQQ, Q,Q,Q, QMIN ) +APFX( plusQQ, Q,Q,Q, qplus ) +APFX(minusQQ, Q,Q,Q, qminus) +APFX(tymesQQ, Q,Q,Q, qtymes) +APFX( divQQ, Q,Q,Q, qdiv ) +APFX( gcdQQ, Q,Q,Q, qgcd ) +APFX( lcmQQ, Q,Q,Q, qlcm ) +APFX( remQQ, Q,Q,Q, qrem ) +APFX( powQQ, Q,Q,Q, qpow ) +APFX( binQQ, X,Q,Q, qbin )
new file mode 100644 --- /dev/null +++ b/vq.h @@ -0,0 +1,31 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Rational Numbers */ + + +#define QF1(f) Q f(J jt, Q w) +#define QF2(f) Q f(J jt,Q a,Q w) +#define QASSERT(b,e) {if(!(b)){jsignal(e); R zeroQ;}} +#define QEPILOG(q) {Q z9; z9=(qstd(q)); gc3(z9.n,z9.d,0L,_ttop); R z9;} +#define QRE(exp) {if((exp),jt->jerr)R zeroQ;} +#define QRZ(exp) {if(!(exp)) R zeroQ;} +#define QX1(x) (1==AN(x)&&1==XDIG(x)) + +#define QEQ(x,y) (equ((x).n,(y).n)&&equ((x).d,(y).d)) +#define QCOMP(x,y) (xcompare(xtymes((x).n,(y).d),xtymes((y).n,(x).d))) +#define QLT(x,y) (0> QCOMP(x,y)) +#define QLE(x,y) (0>=QCOMP(x,y)) +#define QGT(x,y) (0< QCOMP(x,y)) +#define QGE(x,y) (0<=QCOMP(x,y)) +#define QMAX(x,y) (QGE(x,y)?x:y) +#define QMIN(x,y) (QLE(x,y)?x:y) + +extern QF1(jtqstd); + +extern QF2(jtqdiv); +extern QF2(jtqminus); +extern QF2(jtqplus); +extern QF2(jtqtymes); + +extern Q zeroQ;
new file mode 100644 --- /dev/null +++ b/vrand.c @@ -0,0 +1,800 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Random Numbers */ + +#include "j.h" + +#define NRNG 5 /* # of available RNGs (excluding 0) */ +#define SMI 0 /* sum of all RNGs */ +#define GBI 1 /* gb_flip, Knuth 1994 */ +#define MTI 2 /* Mersenne Twister, Matsumoto & Nishimura, 2002 */ +#define DXI 3 /* DX-1597-4d, Deng, 2005 */ +#define MRI 4 /* MRG32k3a, L'Ecuyer, 1999 */ + +#define x31 ((UI)0x80000000) +#define x63 ((UI)0x8000000000000000) +#define X32 2.32830643653869628906e-10 +#define X52 2.22044604925031308085e-16 +#define X64 5.42101086242752217004e-20 + +#define NEXT (jt->rngf(jt)) + +#if SY_64 +#define INITD {sh=mk=1;} +#define NEXTD1 ((0.5+X52/2)+X64*(I)(NEXT&(UI)0xfffffffffffff000)) +#define NEXTD0 NEXTD1 +#else +#define INITD {sh=32-jt->rngw; mk=0x003fffff>>(2-sh);} +#define NEXTD1 ((0.5+X52/2)+X32*((int)NEXT<<sh)+X52*(mk&(int)NEXT)) +#define NEXTD0 ((0.5+X52/2)+X32* (int)NEXT +X52*(mk&(int)NEXT)) +#endif + +#if SY_64 /* m<x, greatest multiple of m less than x */ +#define GMOF(m,x) ( x63+(x63-(2*(x63%m))%m)) +#else +#define GMOF(m,x) (x ? x-x%m : x31+(x31-(2*(x31%m))%m)) +#endif + + +/* ----------------------------------------------------------------------- */ +/* linear congruential generator */ +/* Lehmer, D.H., Proceedings, 2nd Symposium on Large-Scale Digital */ +/* Calculating Machinery, Harvard University Press, 1951, pp. 141-146. */ + +static void lcg(I n,I*v,I seed){D c=16807.0,p=2147483647.0,x=(D)seed; + DO(n, x*=c; x-=p*(I)(x/p); *v++=(I)x;); +} + +F1(jtlcg_test){A x;I n=1597,*v; + ASSERTMTV(w); + GA(x,INT,n,1,0); v=AV(x); + lcg(n,v,1L); + ASSERTSYS(v[ 0]== 16807L, "lcg_test 0"); + ASSERTSYS(v[ 1]== 282475249L, "lcg_test 1"); + ASSERTSYS(v[ 2]==1622650073L, "lcg_test 2"); + ASSERTSYS(v[ 3]== 984943658L, "lcg_test 3"); + ASSERTSYS(v[ 4]==1144108930L, "lcg_test 4"); + ASSERTSYS(v[1592]==1476003502L, "lcg_test 1592"); + ASSERTSYS(v[1593]==1607251617L, "lcg_test 1593"); + ASSERTSYS(v[1594]==2028614953L, "lcg_test 1594"); + ASSERTSYS(v[1595]==1481135299L, "lcg_test 1595"); + ASSERTSYS(v[1596]==1958017916L, "lcg_test 1596"); + R one; +} + + +/* ----------------------------------------------------------------------- */ +/* gb_flip routines from D.E. Knuth's "The Stanford GraphBase" */ + +#define GBN 56 + +#define mod_diff(x,y) (((x)-(y))&0x7fffffffL) /* difference modulo 2^31 */ +#define two_to_the_31 (0x80000000L) + +static UI jtgb_flip_cycle(J jt){I*A=(I*)jt->rngv;register I*i,*j; + for(i=&A[1],j=&A[32];j<=&A[55];i++,j++)*i=mod_diff(*i,*j); + for( j=&A[1 ];i<=&A[55];i++,j++)*i=mod_diff(*i,*j); + jt->rngi=54; + R (UI)A[55]; +} + +#if SY_64 +static UI jtgb_next(J jt){UI a,b,c; + a= jt->rngi ? jt->rngv[jt->rngi--] : gb_flip_cycle(); + b= jt->rngi ? jt->rngv[jt->rngi--] : gb_flip_cycle(); + c= jt->rngi ? jt->rngv[jt->rngi--] : gb_flip_cycle(); + R a+(b<<31)+(c<<33&0xc000000000000000UL); +} +#else +static UI jtgb_next(J jt){R jt->rngi ? jt->rngv[jt->rngi--] : gb_flip_cycle();} +#endif + +static void jtgb_init(J jt,UI s){I*A;register I i,next=1,prev,seed; + A=(I*)jt->rngv; next=1; prev=seed=(I)s; + seed=prev=mod_diff(prev,0); /* strip off the sign */ + A[0]=0; A[55]=prev; + for (i=21; i; i=(i+21)%55) { + A[i]=next; + next=mod_diff(prev,next); + if(seed&1)seed=0x40000000+(seed>>1); else seed>>=1; /* cyclic shift right 1 */ + next=mod_diff(next,seed); + prev=A[i]; + } + gb_flip_cycle(); + gb_flip_cycle(); + gb_flip_cycle(); + gb_flip_cycle(); + gb_flip_cycle(); + jt->rngi=54; +} + +static I jtgb_unif_rand(J jt,I m){ + register UI r,t=two_to_the_31-(two_to_the_31 % m); + do r=gb_next(); while(t<=r); + R r%m; +} + +F1(jtgb_test){I j=jt->rng; + ASSERTMTV(w); + RZ(rngselects(sc(GBI))); + gb_init(-314159); + ASSERTSYS(gb_next()==119318998,"gb_test 0"); + DO(133, gb_next();); + ASSERTSYS(gb_unif_rand(0x55555555L)==748103812,"gb_test 1"); + RZ(rngselects(sc(j))); + R one; +} + + +/* ----------------------------------------------------------------------- */ +/* + A C-program for MT19937, with initialization improved 2002/1/26. + Coded by Takuji Nishimura and Makoto Matsumoto. + + Before using, initialize the state by using init_genrand(seed) + or init_by_array(init_key, key_length). + + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Any feedback is very welcome. + http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html + email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) +*/ + +/* Period parameters */ + +#if SY_64 +#define MTN 312 +#define MTM 156 +#define MATRIX_A 0xB5026F5AA96619E9ULL +#define UM 0xFFFFFFFF80000000ULL /* Most significant 33 bits */ +#else +#define MTN 624 +#define MTM 397 +#define MATRIX_A 0x9908b0dfUL /* constant vector a */ +#define UM 0x80000000UL /* most significant w-r bits */ +#endif +#define LM 0x7fffffffUL /* least significant r bits */ + +/* initializes mt[MTN] with a seed */ +static void jtmt_init(J jt,UI s){I i;UI*mt=jt->rngv; + mt[0]= s; + for (i=1; i<MTN; i++) +#if SY_64 + mt[i] = (6364136223846793005ULL * (mt[i-1] ^ (mt[i-1] >> 62)) + i); +#else + mt[i] = (1812433253UL * (mt[i-1] ^ (mt[i-1] >> 30)) + i); +#endif + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array mt[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + jt->rngi=MTN; +} + +static void jtmt_init_by_array(J jt,UI init_key[], I key_length){I i,j,k;UI*mt=jt->rngv; + mt_init((UI)19650218); + i=1; j=0; k=MTN>key_length?MTN:key_length; + for(; k; k--) { +#if SY_64 + mt[i] = (mt[i] ^ (mt[i-1]^mt[i-1]>>62)*3935559000370003845ULL)+init_key[j]+j; /* non linear */ +#else + mt[i] = (mt[i] ^ (mt[i-1]^mt[i-1]>>30)*1664525UL )+init_key[j]+j; /* non linear */ +#endif + i++; j++; + if(i>=MTN){mt[0]=mt[MTN-1]; i=1;} + if(j>=key_length)j=0; + } + for (k=MTN-1; k; k--) { +#if SY_64 + mt[i] = (mt[i] ^ (mt[i-1]^mt[i-1]>>62)*2862933555777941757ULL)-i; /* non linear */ +#else + mt[i] = (mt[i] ^ (mt[i-1]^mt[i-1]>>30)*1566083941UL )-i; /* non linear */ +#endif + i++; + if (i>=MTN) { mt[0] = mt[MTN-1]; i=1; } + } +#if SY_64 + mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */ +#else + mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ +#endif +} + +/* generates a random 32-or 64-bit number */ +static UI jtmt_next(J jt){UI*mt=jt->rngv,*u,*v,*w,y; + if (MTN<=jt->rngi) { /* generate MTN words at one time */ + v=1+mt; w=MTM+mt; + u=mt; DO(MTN-MTM, y=(*u&UM)|(*v++&LM); *u++=*w++^(y>>1)^MATRIX_A*(y&0x1UL);); + w=mt; DO(MTM-1, y=(*u&UM)|(*v++&LM); *u++=*w++^(y>>1)^MATRIX_A*(y&0x1UL);); + v=mt; y=(*u&UM)|(*v++&LM); *u++=*w++^(y>>1)^MATRIX_A*(y&0x1UL); + jt->rngi=0; + } + y = mt[jt->rngi++]; +#if SY_64 + y ^= (y >> 29) & 0x5555555555555555ULL; + y ^= (y << 17) & 0x71D67FFFEDA60000ULL; + y ^= (y << 37) & 0xFFF7EEE000000000ULL; + y ^= (y >> 43); +#else + y ^= (y >> 11); + y ^= (y << 7) & 0x9d2c5680UL; + y ^= (y << 15) & 0xefc60000UL; + y ^= (y >> 18); +#endif + R y; +} + +#if SY_64 +F1(jtmt_test){I j=jt->rng;UI init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL},x; + ASSERTMTV(w); + RZ(rngselects(sc(MTI))); + mt_init_by_array(init,(I)4); + x=mt_next(); + ASSERTSYS(x==7266447313870364031ULL, "mt_test64 0"); + DO(998, mt_next();); + x=mt_next(); + ASSERTSYS(x== 994412663058993407ULL, "mt_test64 1"); + RZ(rngselects(sc(j))); + R one; +} +#else +F1(jtmt_test){I j=jt->rng;UI init[4]={0x123, 0x234, 0x345, 0x456},x; + ASSERTMTV(w); + RZ(rngselects(sc(MTI))); + mt_init_by_array(init,(I)4); + x=mt_next(); + ASSERTSYS(x==1067595299UL, "mt_test32 0"); + DO(998, mt_next();); + x=mt_next(); + ASSERTSYS(x==3460025646UL, "mt_test32 1"); + RZ(rngselects(sc(j))); + R one; +} +#endif + +/* ----------------------------------------------------------------------- */ +/* DX-1597-4d */ +/* Deng, L.Y., Efficient and Portable Multiple Recursive Generators of */ +/* Large Order, ACM Transactions on Modelling and Computer Simulations 15, */ +/* 2005, pp. 1-13. */ + +#define DXM 2147483647UL +#define DXB 1073741362UL +#define DXBD 1073741362.0 +#define DXN 1597 + +#if SY_64 +static UI jtdx_next30(J jt){I j;UI*u,*v,*vv,r,x; + j=jt->rngi; v=vv=j+jt->rngv; u=DXN+jt->rngv; + r =*v; v+=532; if(v>=u)v-=DXN; + r+=*v; v+=532; if(v>=u)v-=DXN; + r+=*v; v+=532; if(v>=u)v-=DXN; + r+=*v; + *vv=x=(r*DXB)%DXM; + ++j; jt->rngi=j==DXN?0:j; + R x; +} + +static UI jtdx_next(J jt){UI a,b,c; + a=dx_next30()&0x000000003fffffff; + b=dx_next30()&0x000000003fffffff;; + c=dx_next30()&0x000000003fffffff;; + R a|b<<30|c<<34&0xf000000000000000UL; +} +#else +static UI jtdx_next(J jt){I j;UI*u,*v,*vv,r,x; + j=jt->rngi; v=vv=j+jt->rngv; u=DXN+jt->rngv; + r =*v; v+=532; if(v>=u)v-=DXN; + r+=*v; r=(r&DXM)+(r>>31); v+=532; if(v>=u)v-=DXN; + r+=*v; r=(r&DXM)+(r>>31); v+=532; if(v>=u)v-=DXN; + r+=*v; r=(r&DXM)+(r>>31); + x=(DXM&r*DXB)+(UI)((r*DXBD)/2147483648.0); + *vv=x=(x&DXM)+(x>>31); + ++j; jt->rngi=j==DXN?0:j; + R x; +} +#endif + +static void jtdx_init(J jt,UI s){lcg(DXN,jt->rngv,s); jt->rngi=0;} + +F1(jtdx_test){I j=jt->rng,x; + ASSERTMTV(w); + RZ(rngselects(sc(DXI))); dx_init(1UL); + x=dx_next(); ASSERTSYS(x== 221240004UL, "dx_test 0"); + x=dx_next(); ASSERTSYS(x==2109349384UL, "dx_test 1"); + x=dx_next(); ASSERTSYS(x== 527768079UL, "dx_test 2"); + x=dx_next(); ASSERTSYS(x== 238300266UL, "dx_test 3"); + x=dx_next(); ASSERTSYS(x==1495348915UL, "dx_test 4"); + RZ(rngselects(sc(j))); + R one; +} + + +/* ----------------------------------------------------------------------- */ +/* MRG32k3a */ +/* L'Ecuyer, P., Good parameters and implementation for combined multiple */ +/* recursive random number generators, Operations Research 47, 1999, */ +/* pp. 159-164. */ + +#define MRN 6 + +#if SY_64 +#define MRM0 4294967087UL /* _209+2^32 */ +#define MRM1 4294944443UL /* _22853+2^32 */ + +static UI jtmr_next31(J jt){I d,j,*v=jt->rngv,x,y; + switch(j=jt->rngi){ + case 0: x=1403580*v[1]-810728*v[0]; y=527612*v[5]-1370589*v[3]; jt->rngi=1; break; + case 1: x=1403580*v[2]-810728*v[1]; y=527612*v[3]-1370589*v[4]; jt->rngi=2; break; + case 2: x=1403580*v[0]-810728*v[2]; y=527612*v[4]-1370589*v[5]; jt->rngi=0; + } + x%=MRM0; if(x<0)x+=MRM0; v[j ]=x; + y%=MRM1; if(y<0)y+=MRM1; v[j+3]=y; + d=(x-y)%MRM0; if(d<0)d+=MRM0; + R d; +} + +static UI jtmr_next(J jt){UI a,b,c; + a=mr_next31()&0x000000007fffffff; + b=mr_next31()&0x000000007fffffff; + c=mr_next31()&0x000000007fffffff; + R a+(b<<31)+(c<<33&0xc000000000000000UL); +} + +#else + +#define MRM0 4294967087.0 /* _209+2^32 */ +#define MRM1 4294944443.0 /* _22853+2^32 */ + +static UI jtmr_next(J jt){D d,*v=(D*)jt->rngv,x,y;I j,k; + switch(j=jt->rngi){ + case 0: x=1403580.0*v[1]-810728.0*v[0]; y=527612.0*v[5]-1370589.0*v[3]; jt->rngi=1; break; + case 1: x=1403580.0*v[2]-810728.0*v[1]; y=527612.0*v[3]-1370589.0*v[4]; jt->rngi=2; break; + case 2: x=1403580.0*v[0]-810728.0*v[2]; y=527612.0*v[4]-1370589.0*v[5]; jt->rngi=0; + } + k=(I)(x/MRM0); x-=k*MRM0; if(x<0.0)x+=MRM0; v[j ]=x; + k=(I)(y/MRM1); y-=k*MRM1; if(y<0.0)y+=MRM1; v[j+3]=y; + d=x-y; + k=(I)(d/MRM0); d-=k*MRM0; if(d<0.0)d+=MRM0; + R (UI)d; +} +#endif + +static void jtmr_init(J jt,UI s){D*v=(D*)jt->rngv;I t[MRN]; + lcg(MRN,t,s); + DO(MRN, *v++=(D)t[i];); + jt->rngi=0; +} + +F1(jtmr_test){I j=jt->rng,x; + ASSERTMTV(w); + RZ(rngselects(sc(MRI))); mr_init(1UL); + x=mr_next(); ASSERTSYS(x==3293966663UL, "mr_test 0"); + x=mr_next(); ASSERTSYS(x==3129388991UL, "mr_test 1"); + x=mr_next(); ASSERTSYS(x==2530141948UL, "mr_test 2"); + x=mr_next(); ASSERTSYS(x==1065433470UL, "mr_test 3"); + x=mr_next(); ASSERTSYS(x==1177634463UL, "mr_test 4"); + DO(40, mr_next();); + x=mr_next(); ASSERTSYS(x==1134399356UL, "mr_test 45"); + x=mr_next(); ASSERTSYS(x== 630832201UL, "mr_test 46"); + x=mr_next(); ASSERTSYS(x==2411464992UL, "mr_test 47"); + x=mr_next(); ASSERTSYS(x== 762439568UL, "mr_test 48"); + x=mr_next(); ASSERTSYS(x==3245142153UL, "mr_test 49"); + RZ(rngselects(sc(j))); + R one; +} + + +/* ----------------------------------------------------------------------- */ +/* sum of all RNGs */ + +static UI jtsm_next(J jt){UI x; + jt->rngi=jt->rngI0[GBI]; jt->rngv=jt->rngV0[GBI]; x =gb_next(); jt->rngI0[GBI]=jt->rngi; + jt->rngi=jt->rngI0[MTI]; jt->rngv=jt->rngV0[MTI]; x+=mt_next(); jt->rngI0[MTI]=jt->rngi; + jt->rngi=jt->rngI0[DXI]; jt->rngv=jt->rngV0[DXI]; x+=dx_next(); jt->rngI0[DXI]=jt->rngi; + jt->rngi=jt->rngI0[MRI]; jt->rngv=jt->rngV0[MRI]; x+=mr_next(); jt->rngI0[MRI]=jt->rngi; + R x; +} + +static void jtsm_init(J jt,UI s){ + jt->rngv=jt->rngV0[GBI]; gb_init(s); jt->rngI0[GBI]=jt->rngi; + jt->rngv=jt->rngV0[MTI]; mt_init(s); jt->rngI0[MTI]=jt->rngi; + jt->rngv=jt->rngV0[DXI]; dx_init(s); jt->rngI0[DXI]=jt->rngi; + jt->rngv=jt->rngV0[MRI]; mr_init(s); jt->rngI0[MRI]=jt->rngi; +} + +/* ----------------------------------------------------------------------- */ + +F1(jtrngraw){A z;I n,*v; + RE(n=i0(w)); + ASSERT(0<=n,EVDOMAIN); + GA(z,INT,n,1,0); v=AV(z); + DO(n, *v++=NEXT;); + R z; +} + +B jtrnginit(J jt){ + DO(NRNG, jt->rngV[i]=jt->rngV0[i]=0;); + jt->rngF[0]=jtsm_next; jt->rngS[0]=16807; + jt->rngF[1]=jtgb_next; jt->rngS[1]=16807; + jt->rngF[2]=jtmt_next; jt->rngS[2]=16807; + jt->rngF[3]=jtdx_next; jt->rngS[3]=16807; + jt->rngF[4]=jtmr_next; jt->rngS[4]=16807; + jt->rngM[0]=SY_64?0:0; /* % 2^32 */ + jt->rngM[1]=SY_64?0:2147483648UL; /* % 2^31 */ + jt->rngM[2]=0; /* % 2^32 */ + jt->rngM[3]=SY_64?0:2147483648UL; /* % _1+2^31 */ /* fudge; should be _1+2^31 */ + jt->rngM[4]=SY_64?0:4294967087UL; /* % _209+2^32 */ + jt->rngI0[GBI]=54; + rngselects(num[2]); + R 1; +} + +F1(jtrngselectq){ASSERTMTV(w); R sc(jt->rng);} + +static B jtrngga(J jt,I i,UI**vv){ + if(vv[i]){jt->rngv=vv[i]; jt->rngi=jt->rngI[i];} + else{A x;I n,t;VF f; + switch(i){ + case GBI: t=INT; n=GBN; f=jtgb_init; break; + case MTI: t=INT; n=MTN; f=jtmt_init; break; + case DXI: t=INT; n=DXN; f=jtdx_init; break; + case MRI: t=FL; n=MRN; f=jtmr_init; + } + GA(x,t,n,1,0); ra(x); vv[i]=jt->rngv=AV(x); + f(jt,jt->rngS[i]); jt->rngI[i]=jt->rngi; + } + R 1; +} + +F1(jtrngselects){I i;UI**vv=jt->rngV; + RE(i=i0(w)); + ASSERT(0<=i&&i<NRNG,EVDOMAIN); + jt->rngI[jt->rng]=jt->rngi; + switch(jt->rng=i){ + case SMI: vv=jt->rngV0; jt->rngw=SY_64?64:32; + RZ(rngga(GBI,vv)); RZ(rngga(MTI,vv)); RZ(rngga(DXI,vv)); RZ(rngga(MRI,vv)); break; + case GBI: RZ(rngga(i, vv)); jt->rngw=SY_64?64:31; break; + case MTI: RZ(rngga(i, vv)); jt->rngw=SY_64?64:32; break; + case DXI: RZ(rngga(i, vv)); jt->rngw=SY_64?64:30; break; + case MRI: RZ(rngga(i, vv)); jt->rngw=SY_64?64:31; + } + jt->rngf=jt->rngF[jt->rng]; + R mtv; +} + +F1(jtrngstateq){A x=0,z,*zv;D*u=0;I n;UI*v; + ASSERTMTV(w); + switch(jt->rng){ + case SMI: + GA(z,BOX,9,1,0); zv=AAV(z); + RZ(*zv++=zero); + RZ(*zv++=sc(jt->rngI0[GBI])); RZ(*zv++=vec(INT,GBN,jt->rngV0[GBI])); + RZ(*zv++=sc(jt->rngI0[MTI])); RZ(*zv++=vec(INT,MTN,jt->rngV0[MTI])); + RZ(*zv++=sc(jt->rngI0[DXI])); RZ(*zv++=vec(INT,DXN,jt->rngV0[DXI])); +#if SY_64 + RZ(*zv++=sc(jt->rngI0[MRI])); RZ(*zv++=vec(INT,MRN,jt->rngV0[MRI])); +#else + u=(D*)jt->rngV0[MRI]; GA(x,INT,MRN,1,0); v=AV(x); DO(MRN, v[i]=(UI)u[i];); + RZ(*zv++=sc(jt->rngI0[MRI])); *zv++=x; +#endif + R z; + case GBI: n=GBN; v=jt->rngv; break; + case MTI: n=MTN; v=jt->rngv; break; + case DXI: n=DXN; v=jt->rngv; break; +#if SY_64 + case MRI: n=MRN; v=jt->rngv; break; +#else + case MRI: n=MRN; u=(D*)jt->rngv; GA(x,INT,n,1,0); v=AV(x); DO(n, v[i]=(UI)u[i];); +#endif + } + GA(z,BOX,3,1,0); zv=AAV(z); + RZ(*zv++=sc(jt->rng)); RZ(*zv++=sc(jt->rngi)); RZ(*zv++=vec(INT,n,v)); + R z; +} + +static B jtrngstates1(J jt,I j,I n,UI**vv,I i,I k,A x,B p){D*u;UI*xv; + RZ(x=vi(x)); xv=AV(x); + ASSERT(1==AR(x),EVRANK); + ASSERT(n==AN(x),EVLENGTH); + ASSERT(i<=k&&k<n+(j==MTI),EVINDEX); + if(p)DO(n, ASSERT(x31>xv[i],EVDOMAIN);); + if(SY_64||j!=MRI)ICPY(vv[j],xv,n); else{u=(D*)vv[j]; DO(n, u[i]=(D)xv[i];);} + jt->rngi=k; + R 1; +} + +F1(jtrngstates){A*wv;I k,wd;UI**vv=jt->rngV; + RZ(w); + ASSERT(1==AR(w),EVRANK); + ASSERT(BOX&AT(w),EVDOMAIN); + ASSERT(2<=AN(w),EVLENGTH); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + RZ(rngselects(WVR(0))); /* changes jt->rng */ + ASSERT(AN(w)==(jt->rng?3:9),EVLENGTH); + switch(jt->rng){ + case SMI: vv=jt->rngV0; + RE(k=i0(WVR(1))); RZ(rngstates1(GBI,GBN,vv,1,k,WVR(2),1)); jt->rngI0[GBI]=k; + RE(k=i0(WVR(3))); RZ(rngstates1(MTI,MTN,vv,0,k,WVR(4),0)); jt->rngI0[MTI]=k; + RE(k=i0(WVR(5))); RZ(rngstates1(DXI,DXN,vv,0,k,WVR(6),1)); jt->rngI0[DXI]=k; + RE(k=i0(WVR(7))); RZ(rngstates1(MRI,MRN,vv,0,k,WVR(8),0)); jt->rngI0[MRI]=k; + break; + case GBI: RE(k=i0(WVR(1))); RZ(rngstates1(GBI,GBN,vv,1,k,WVR(2),1)); break; + case MTI: RE(k=i0(WVR(1))); RZ(rngstates1(MTI,MTN,vv,0,k,WVR(2),0)); break; + case DXI: RE(k=i0(WVR(1))); RZ(rngstates1(DXI,DXN,vv,0,k,WVR(2),1)); break; + case MRI: RE(k=i0(WVR(1))); RZ(rngstates1(MRI,MRN,vv,0,k,WVR(2),0)); + } + R mtv; +} + +F1(jtrngseedq){ASSERTMTV(w); R jt->rngseed?jt->rngseed:sc(jt->rngS[jt->rng]);} + +F1(jtrngseeds){I k,r; + RZ(w=vi(w)); k=*AV(w); r=AR(w); + if(r){ + ASSERT(1==r&&MTI==jt->rng,EVRANK); + fa(jt->rngseed); ra(jt->rngseed=w); + mt_init_by_array(AV(w),AN(w)); + }else switch(jt->rng){ + case SMI: ASSERT(k,EVDOMAIN); sm_init(k); break; + case GBI: gb_init(k); break; + case MTI: mt_init((UI)k); break; + case DXI: ASSERT(k,EVDOMAIN); dx_init(k); break; + case MRI: ASSERT(k,EVDOMAIN); mr_init(k); + } + jt->rngS[jt->rng]=k; + if(!r&&jt->rngseed){fa(jt->rngseed); jt->rngseed=0;} + R mtv; +} + + +static F2(jtrollksub){A z;I an,*av,k,m1,n,p,q,r,sh;UI j,m,mk,s,t,*u,x=jt->rngM[jt->rng]; + RZ(a&&w); + an=AN(a); RE(m1=i0(w)); ASSERT(0<=m1,EVDOMAIN); m=m1; + RZ(a=vip(a)); av=AV(a); RE(n=prod(an,av)); + GA(z,0==m?FL:2==m?B01:INT,n,an,av); u=(UI*)AV(z); + if(!m){D*v=DAV(z); INITD; if(sh)DO(n, *v++=NEXTD1;)else DO(n, *v++=NEXTD0;);} + else if(2==m){ + p=jt->rngw; p-=p%4; q=n/p; r=n%p; +#if SY_64 + mk=(UI)0x0101010101010101; +#else + mk=0x01010101; +#endif + if(28==p)DO(q, t=NEXT; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; + *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t;) + else DO(q, t=NEXT; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; + *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t; t>>=1; *u++=mk&t;); + if(r){B*c=(B*)u; DO(r, *c++=1&&1&NEXT;);} + }else{ + r=n; s=GMOF(m,x); if(s==x)s=0; + k=0; j=1; while(m>j){++k; j<<=1;} + if(k&&j==m){ /* m=2^k but is not 1 or 2 */ + p=jt->rngw/k; q=n/p; r=n%p; mk=m-1; + switch((s?2:0)+(1<p)){ + case 0: DO(q, t=NEXT; *u++=mk&t; ); break; + case 1: DO(q, t=NEXT; DO(p, *u++=mk&t; t>>=k;);); break; + case 2: DO(q, while(s<=(t=NEXT)); *u++=mk&t; ); break; + case 3: DO(q, while(s<=(t=NEXT)); DO(p, *u++=mk&t; t>>=k;);); + }} + if(r&&s)DO(r, while(s<=(t=NEXT)); *u++=t%m;) else DO(r, *u++=NEXT%m;); + } + R z; +} + +DF2(jtrollk){A g;V*sv; + RZ(a&&w&&self); + sv=VAV(self); g=sv->h?sv->h:sv->g; + if(AT(w)&XNUM+RAT||!(!AR(w)&&1>=AR(a)&&(g==ds(CDOLLAR)||1==AN(a))))R roll(df2(a,w,g)); + R rollksub(a,vi(w)); +} /* ?@$ or ?@# or [:?$ or [:?# */ + + +static X jtxrand(J jt,X x){A q,z;I c,d,i,n,*qv,*xv,*zv; + n=AN(x); xv=AV(x); i=n-1; + GA(z,INT,n,1,0); zv=AV(z); + while(0<=i){ + c=xv[i]; + if(i==n-1){RZ(q=roll(repeat(v2(n-1,1L),v2(XBASE,1<n?1+c:c)))); qv=AV(q);} + zv[i]=d=qv[i]; + if (d< c){ICPY(zv,qv,i); i=-1;} + else if(d==c)--i; + else if(d> c)i=n-1; + } + i=n-1; while(0<=i&&!zv[i])--i; AN(z)=*AS(z)=0>i?1:1+i; + R z; +} /* ?x where x is a single strictly positive extended integer */ + +static F1(jtrollxnum){A z;B c=0;I d,n;X*u,*v,x; + if(!(AT(w)&XNUM))RZ(w=cvt(XNUM,w)); + n=AN(w); v=XAV(w); + GA(z,XNUM,n,AR(w),AS(w)); u=XAV(z); + DO(n, x=*v++; d=XDIG(x); ASSERT(0<=d,EVDOMAIN); if(d)RZ(*u++=xrand(x)) else{*u++=iv0; c=1;}); + if(c){D*d;I mk,sh; + INITD; + RZ(z=cvt(FL,z)); d=DAV(z); v=XAV(w); + DO(n, x=*v++; if(!XDIG(x))*d=sh?NEXTD1:NEXTD0; ++d;); + } + R z; +} /* ?n$x where x is extended integer */ + + +static F1(jtrollbool){A z;B*v;D*u;I n,sh;UINT mk; + n=AN(w); v=BAV(w); INITD; + GA(z,FL,n,AR(w),AS(w)); u=DAV(z); + if(sh)DO(n, *u++=*v++?0.0:NEXTD1;) + else DO(n, *u++=*v++?0.0:NEXTD0;) + R z; +} /* ?n$x where x is boolean */ + +static A jtroll2(J jt,A w,B*b){A z;I j,n,p,q,r,*v;UI mk,t,*zv; + *b=0; n=AN(w); v=AV(w); + p=jt->rngw; p-=p%4; q=n/p; r=n%p; +#if SY_64 + mk=(UI)0x0101010101010101; +#else + mk=0x01010101; +#endif + GA(z,B01,n,AR(w),AS(w)); zv=(UI*)AV(z); + if(28==p)for(j=0;j<q;++j){ + t=NEXT; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; + }else for(j=0;j<q;++j){ + t=NEXT; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; t>>=1; + if(!(2==*v++&&2==*v++&&2==*v++&&2==*v++))R mark; *zv++=mk&t; + } + if(r){B*c=(B*)zv; DO(r, if(2!=*v++)R mark; *c++=1&&1&NEXT;);} + *b=1; R z; +} /* ?n$x where x is 2, maybe */ + +static A jtrollnot0(J jt,A w,B*b){A z;I j,m1,n,*u,*v;UI m,s,t,x=jt->rngM[jt->rng]; + *b=0; n=AN(w); + if(n){v=AV(w); m1=*v++; j=1; DO(n-1, if(m1!=*v++){j=0; break;});} + if(n&&j)RZ(z=rollksub(shape(w),sc(m1))) + else{ + GA(z,INT,n,AR(w),AS(w)); + v=AV(w); u=AV(z); + for(j=0;j<n;++j){ + m1=*v++; if(!m1)R mark; ASSERT(0<=m1,EVDOMAIN); m=m1; + s=GMOF(m,x); t=NEXT; if(s)while(s<=t)t=NEXT; *u++=t%m; + }} + *b=1; R z; +} /* ?n$x where x is not 0, maybe */ + +static A jtrollany(J jt,A w,B*b){A z;D*u;I j,m1,n,sh,*v;UI m,mk,s,t,x=jt->rngM[jt->rng]; + *b=0; n=AN(w); v=AV(w); INITD; + GA(z,FL,n,AR(w),AS(w)); u=DAV(z); + for(j=0;j<n;++j){ + m1=*v++; ASSERT(0<=m1,EVDOMAIN); m=m1; + if(0==m)*u++=sh?NEXTD1:NEXTD0; + else{s=GMOF(m,x); t=NEXT; if(s)while(s<=t)t=NEXT; *u++=(D)(t%m);} + } + *b=1; R z; +} /* ?s$x where x can be anything and 1<#x */ + +F1(jtroll){A z;B b=0;I m,wt; + RZ(w); + wt=AT(w); + ASSERT(wt&DENSE,EVDOMAIN); + if(!AN(w)){GA(z,B01,0,AR(w),AS(w)); R z;} + if(wt&B01)R rollbool(w); + if(wt&XNUM+RAT)R rollxnum(w); + RZ(w=vi(w)); m=*AV(w); + if( 2==m)RZ(z=roll2 (w,&b)); + if(!b&&0!=m)RZ(z=rollnot0(w,&b)); + if(!b )RZ(z=rollany (w,&b)); + R z&&!(FL&AT(z))&&wt&XNUM+RAT?xco1(z):z; +} + +F2(jtdeal){A h,y,z;I at,d,*hv,i,i1,j,k,m,n,p,q,*v,wt,*yv,*zv;UI c,s,t,x=jt->rngM[jt->rng]; + RZ(a&&w); + at=AT(a); wt=AT(w); + ASSERT(at&DENSE&at&&wt&DENSE,EVDOMAIN); + F2RANK(0,0,jtdeal,0); + RE(m=i0(a)); RE(c=n=i0(w)); + ASSERT(0<=m&&m<=n,EVDOMAIN); + if(0==m)z=mtv; + else if(m<n/5.0||x<=(UI)n){ + p=hsize(m); GA(h,INT,p,1,0); hv=AV(h); DO(p, hv[i]=0;); + GA(y,INT,2+2*m,1,0); yv=AV(y); d=2; + GA(z,INT,m,1,0); zv=AV(z); + for(i=0;i<m;++i){ + s=GMOF(c,x); t=NEXT; if(s)while(s<=t)t=NEXT; j=i+t%c--; + q=i%p; while(hv[q]&&(v=yv+hv[q],i!=*v))q=(1+q)%p; i1=hv[q]?v[1]:i; + q=j%p; while(hv[q]&&(v=yv+hv[q],j!=*v))q=(1+q)%p; + if(hv[q]){++v; *zv++=*v; *v=i1;} + else{v=yv+d; *zv++=*v++=j; *v=i1; hv[q]=d; d+=2;} + }}else{ + RZ(z=apv(n,0L,1L)); zv=AV(z); + DO(m, s=GMOF(c,x); t=NEXT; if(s)while(s<=t)t=NEXT; j=i+t%c--; k=zv[i]; zv[i]=zv[j]; zv[j]=k;); + AN(z)=*AS(z)=m; + } + R at&XNUM+RAT||wt&XNUM+RAT?xco1(z):z; +} + + +#define FXSDECL A z;I i,j=jt->rng;UI*v=jt->rngV[GBI]; +#define FXSDO {i=j==GBI?jt->rngi:jt->rngI[GBI]; \ + if(!jt->rngfxsv){GA(z,INT,GBN,1,0); ra(z); jt->rngfxsv=AV(z);} \ + jt->rngV[GBI]=jt->rngfxsv; rngselects(sc(GBI)); gb_init(16807);} +#define FXSOD {jt->rngV[GBI]=v; jt->rngI[GBI]=jt->rngi=i; rngselects(sc(j));} + +F1(jtrollx ){FXSDECL; RZ(w); FXSDO; z=roll(w); FXSOD; R z;} +F2(jtdealx ){FXSDECL; F2RANK(0,0,jtdealx,0); FXSDO; z=deal(a,w); FXSOD; R z;} +DF2(jtrollkx){FXSDECL; RZ(a&&w&&self); FXSDO; z=rollk(a,w,self); FXSOD; R z;} + + +/* +static F1(jtroll){A z;D rl=jt->rl;static D dm=16807,p=2147483647L;I c,n,*v,*x; + RZ(w); + n=AN(w); v=AV(w); + RZ(z=reshape(shape(w),num[2])); x=AV(z); + if(ICMP(v,x,n)) + DO(n, c=*v++; ASSERT(0<c,EVDOMAIN); rl=fmod(rl*dm,p); *x++=(I)jfloor(rl*c/p);) + else{B*x;D q=p/2; + GA(z,B01,n,AR(w),AS(w)); x=BAV(z); + DO(n, rl=fmod(rl*dm,p); *x++=rl>q;); + } + jt->rl=(I)rl; + R z; +} /* P.C. Berry, Sharp APL Reference Manual, 1979, p. 126. */ + +/* +static A jtbigdeal(J jt,I m,I n){A t,x,y; + RZ(x=sc((I)jfloor(1.11*m))); + RZ(y=sc(n)); + do{RZ(t=nub(roll(reshape(x,y))));}while(m>AN(t)); + R vec(INT,m,AV(t)); +} /* E.E. McDonnell circa 1966, small m and large n */ + +/* +static A jtdeal(J jt,I m,I n){A y;D rl=jt->rl;static D dm=16807,p=2147483647L;I j,k,*yv; + if(m<0.01*n)R bigdeal(m,n); + RZ(y=apv(n,n-1,-1L)); yv=AV(y); + DO(m, rl=fmod(rl*dm,p); j=i+(I)jfloor(rl*(n-i)/(1+p)); k=yv[i]; yv[i]=yv[j]; yv[j]=k;); + jt->rl=(I)rl; + R vec(INT,m,yv); +} /* P.C. Berry, Sharp APL Reference Manual, 1979, p. 178. */
new file mode 100644 --- /dev/null +++ b/vrep.c @@ -0,0 +1,275 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: a#"r w */ + +#include "j.h" + + +#define REPF(f) A f(J jt,A a,A w,I wf,I wcr) + + +static REPF(jtrepzdx){A p,q,x;P*wp; + RZ(a&&w); + if(SPARSE&AT(w)){wp=PAV(w); x=SPA(wp,e);} + else x=jt->fill&&AN(jt->fill)?jt->fill:filler(w); + RZ(p=repeat(ravel(rect(a)),ravel(stitch(IX(wcr?*(wf+AS(w)):1),num[-1])))); + RZ(q=irs2(w,x,0L,wcr,0L,jtover)); + R irs2(p,q,0L,1L,wcr+!wcr,jtfrom); +} /* (dense complex) # (dense or sparse) */ + +static REPF(jtrepzsx){A q,x,y;I c,d,j,k=-1,m,p=0,*qv,*xv,*yv;P*ap; + RZ(a&&w); + ap=PAV(a); x=SPA(ap,x); m=AN(x); + if(!AN(SPA(ap,a)))R repzdx(ravel(x),w,wf,wcr); + y=SPA(ap,i); yv=AV(y); + RZ(x=cvt(INT,vec(FL,2*m,AV(x)))); xv=AV(x); + if(equ(zero,SPA(ap,e))){ + k=c=*(wf+AS(w)); + if(!wf&&SPARSE&AT(w)){A a,y;I m,n,q,*v;P*wp; + wp=PAV(w); a=SPA(wp,a); + if(AN(a)&&!*AV(a)){ + y=SPA(wp,i); v=AS(y); m=v[0]; n=v[1]; v=AV(y); + k=m?v[(m-1)*n]+1:0; q=0; + DO(m, if(q==*v)++q; else if(q<*v){k=q; break;} v+=n;); + }} + ASSERT(k<=IMAX-1,EVLIMIT); + if(c==k)RZ(w=irs2(sc(1+k),w,0L,0L,wcr,jttake)); + DO(2*m, ASSERT(0<=xv[i],EVDOMAIN); p+=xv[i]; ASSERT(0<=p,EVLIMIT);); + GA(q,INT,p,1,0); qv=AV(q); + DO(m, c=*xv++; d=*xv++; j=yv[i]; DO(c, *qv++=j;); DO(d, *qv++=k;);); + R irs2(q,w,0L,1L,wcr,jtfrom); + } + ASSERT(0,EVNONCE); +} /* (sparse complex) #"r (dense or sparse) */ + + +#define REPB(T) \ + {T*u,*v=(T*)zv; \ + for(i=0;i<c;++i){ \ + u=i*m+(T*)wv; \ + for(j=0,iv=(I*)b;j<q;++j,u+=SZI)switch(*iv++){ \ + case B0001: *v++=u[3]; break; \ + case B0010: *v++=u[2]; break; \ + case B0011: *v++=u[2]; *v++=u[3]; break; \ + case B0100: *v++=u[1]; break; \ + case B0101: *v++=u[1]; *v++=u[3]; break; \ + case B0110: *v++=u[1]; *v++=u[2]; break; \ + case B0111: *v++=u[1]; *v++=u[2]; *v++=u[3]; break; \ + case B1000: *v++=u[0]; break; \ + case B1001: *v++=u[0]; *v++=u[3]; break; \ + case B1010: *v++=u[0]; *v++=u[2]; break; \ + case B1011: *v++=u[0]; *v++=u[2]; *v++=u[3]; break; \ + case B1100: *v++=u[0]; *v++=u[1]; break; \ + case B1101: *v++=u[0]; *v++=u[1]; *v++=u[3]; break; \ + case B1110: *v++=u[0]; *v++=u[1]; *v++=u[2]; break; \ + case B1111: *v++=u[0]; *v++=u[1]; *v++=u[2]; *v++=u[3]; \ + } \ + if(r){B*c=(B*)iv; DO(r, if(c[i])*v++=u[i];);} \ + }} + +#if !SY_64 && SY_WIN32 +static REPF(jtrepbdx){A z;B*b;C*wv,*zv;I c,i,*iv,j,k,m,p,q,r,zn; + RZ(a&&w); + if(SPARSE&AT(w))R irs2(ifb(AN(a),BAV(a)),w,0L,1L,wcr,jtfrom); + m=AN(a); q=m/SZI; r=m%SZI; + ASSERT(m==*(wf+AS(w)),EVLENGTH); + b=BAV(a); p=bsum(m,b); zn=m?p*(AN(w)/m):0; + ASSERT(0<=zn,EVLIMIT); + GA(z,AT(w),zn,AR(w),AS(w)); *(wf+AS(z))=p; + wv=CAV(w); zv=CAV(z); + RE(c=prod(wf,AS(w))); + if(zn)switch(k=AN(w)/(c*m)*bp(AT(w)),FL&AT(w)||k!=sizeof(D)?k:0){ + case sizeof(C): REPB(C); break; + case sizeof(S): REPB(S); break; + case sizeof(I): REPB(I); break; + case sizeof(D): REPB(D); break; + default: {C*u;I k1=k,k2=k*2,k3=k*3,k4=k*4,km=k*m; + for(i=0;i<c;++i){ + u=i*km+wv; + for(j=0,iv=(I*)b;j<q;++j,u+=k4)switch(*iv++){ + case B0001: MC(zv,k3+u,k1); zv+=k1; break; + case B0010: MC(zv,k2+u,k1); zv+=k1; break; + case B0011: MC(zv,k2+u,k2); zv+=k2; break; + case B0100: MC(zv,k1+u,k1); zv+=k1; break; + case B0101: MC(zv,k1+u,k1); zv+=k1; MC(zv,k3+u,k1); zv+=k1; break; + case B0110: MC(zv,k1+u,k2); zv+=k2; break; + case B0111: MC(zv,k1+u,k3); zv+=k3; break; + case B1000: MC(zv, u,k1); zv+=k1; break; + case B1001: MC(zv, u,k1); zv+=k1; MC(zv,k3+u,k1); zv+=k1; break; + case B1010: MC(zv, u,k1); zv+=k1; MC(zv,k2+u,k1); zv+=k1; break; + case B1011: MC(zv, u,k1); zv+=k1; MC(zv,k2+u,k2); zv+=k2; break; + case B1100: MC(zv, u,k2); zv+=k2; break; + case B1101: MC(zv, u,k2); zv+=k2; MC(zv,k3+u,k1); zv+=k1; break; + case B1110: MC(zv, u,k3); zv+=k3; break; + case B1111: MC(zv, u,k4); zv+=k4; + } + if(r){B*c=(B*)iv; DO(r, if(c[i]){MC(zv,u+i*k,k); zv+=k;});} + }}} + R RELOCATE(w,z); +} /* (dense boolean)#"r (dense or sparse) */ +#else +static REPF(jtrepbdx){A z;B*b;C*wv,*zv;I c,k,m,p,zn; + RZ(a&&w); + if(SPARSE&AT(w))R irs2(ifb(AN(a),BAV(a)),w,0L,1L,wcr,jtfrom); + m=AN(a); + b=BAV(a); p=bsum(m,b); zn=m?p*(AN(w)/m):0; + ASSERT(0<=zn,EVLIMIT); + GA(z,AT(w),zn,AR(w),AS(w)); *(wf+AS(z))=p; + wv=CAV(w); zv=CAV(z); + if(!zn)R z; + RE(c=prod(wf,AS(w))); k=AN(w)/(c*m)*bp(AT(w)); + DO(c, DO(m, if(b[i]){MC(zv,wv,k); zv+=k;} wv+=k;);); + R RELOCATE(w,z); +} /* (dense boolean)#"r (dense or sparse) */ +#endif + +static REPF(jtrepbsx){A ai,c,d,e,g,q,x,wa,wx,wy,y,y1,z,zy;B*b;I*dv,*gv,j,m,n,*u,*v,*v0;P*ap,*wp,*zp; + RZ(a&&w); + ap=PAV(a); e=SPA(ap,e); + y=SPA(ap,i); u=AV(y); + x=SPA(ap,x); n=AN(x); b=BAV(x); + if(!AN(SPA(ap,a)))R irs2(ifb(n,b),w,0L,1L,wcr,jtfrom); + if(!*BAV(e)){ + GA(q,INT,n,1,0); v=v0=AV(q); + DO(n, if(*b++)*v++=u[i];); + AN(q)=*AS(q)=v-v0; + R irs2(q,w,0L,1L,wcr,jtfrom); + } + wp=PAV(w); + if(DENSE&AT(w)||all0(eq(sc(wf),SPA(wp,a)))){RZ(q=denseit(a)); R irs2(ifb(AN(q),BAV(q)),w,0L,1L,wcr,jtfrom);} + wa=SPA(wp,a); wy=SPA(wp,i); wx=SPA(wp,x); + RZ(q=aslash(CPLUS,a)); + GA(z,AT(w),1,AR(w),AS(w)); *(wf+AS(z))=m=*AV(q); + RZ(c=indexof(wa,sc(wf))); + RZ(y1=fromr(c,wy)); + RZ(q=not(eps(y1,ravel(repeat(not(x),y))))); + m=*AS(a)-m; + GA(ai,INT,m,1,0); v=AV(ai); DO(n, if(!*b++)*v++=u[i];); + RZ(g=grade1(over(ai,repeat(q,y1)))); gv=AV(g); + GA(d,INT,AN(y1),1,0); dv=AV(d); j=0; DO(AN(g), if(m>gv[i])++j; else dv[gv[i]-m]=j;); + RZ(zy=repeat(q,wy)); v=AV(zy)+*AV(c); m=*(1+AS(zy)); DO(*AS(zy), *v-=dv[i]; v+=m;); + zp=PAV(z); + SPB(zp,a,ca(wa)); + SPB(zp,e,SPA(wp,e)); + SPB(zp,i,zy); + SPB(zp,x,repeat(q,wx)); + R z; +} /* (sparse boolean) #"r (dense or sparse) */ + +static REPF(jtrepidx){A y;I j,m,p=0,*v,*x; + RZ(a&&w); + RZ(a=vi(a)); x=AV(a); + m=*AS(a); + DO(m, ASSERT(0<=x[i],EVDOMAIN); p+=x[i]; ASSERT(0<=p,EVLIMIT);); + GA(y,INT,p,1,0); v=AV(y); + DO(m, j=i; DO(x[j], *v++=j;);); + R irs2(y,w,0L,1L,wcr,jtfrom); +} /* (dense integer) #"r (dense or sparse) */ + +static REPF(jtrepisx){A e,q,x,y;I c,j,m,p=0,*qv,*xv,*yv;P*ap; + RZ(a&&w); + ap=PAV(a); e=SPA(ap,e); + y=SPA(ap,i); yv=AV(y); + x=SPA(ap,x); if(!(INT&AT(x)))RZ(x=cvt(INT,x)); xv=AV(x); + if(!AN(SPA(ap,a)))R repidx(ravel(x),w,wf,wcr); + if(!*AV(e)){ + m=AN(x); + DO(m, ASSERT(0<=xv[i],EVDOMAIN); p+=xv[i]; ASSERT(0<=p,EVLIMIT);); + GA(q,INT,p,1,0); qv=AV(q); + DO(m, c=xv[i]; j=yv[i]; DO(c, *qv++=j;);); + R irs2(q,w,0L,1L,wcr,jtfrom); + } + ASSERT(0,EVNONCE); +} /* (sparse integer) #"r (dense or sparse) */ + + +static REPF(jtrep1d){A z;C*wv,*zv;I c,k,m,n,p=0,q,t,*ws,zk,zn; + RZ(a&&w); + t=AT(a); m=AN(a); ws=AS(w); n=wcr?ws[wf]:1; + if(t&CMPX){ + if(wcr)R repzdx(from(apv(n,0L,0L),a),w, wf,wcr); + else R repzdx(a,irs2(apv(m,0L,0L),w,0L,1L,0L,jtfrom),wf,1L ); + } + if(t&B01){B*x=BAV(a); DO(m,p+=x[i];);} + else{I*x; + RZ(a=vi(a)); x=AV(a); + DO(m, ASSERT(0<=x[i],EVDOMAIN); p+=x[i]; ASSERT(0<=p,EVLIMIT);); + } + RE(q=mult(p,n)); + RE(zn=n?mult(q,AN(w)/n):0); + GA(z,AT(w),zn,AR(w)+!wcr,ws); *(wf+AS(z))=q; + if(!zn)R z; + wv=CAV(w); zv=CAV(z); + RE(c=prod(wf,ws)); k=AN(w)/(c*n)*bp(AT(w)); zk=p*k; + DO(c*n, mvc(zk,zv,k,wv); zv+=zk; wv+=k;); + R RELOCATE(w,z); +} /* scalar #"r dense or dense #"0 dense */ + +static B jtrep1sa(J jt,A a,I*c,I*d){A x;B b;I*v; + b=1&&AT(a)&CMPX; + if(b)RZ(x=rect(a)) else x=a; + if(AR(a)){ASSERT(equ(one,aslash(CSTARDOT,le(zero,ravel(x)))),EVDOMAIN); RZ(x=aslash(CPLUS,x));} + if(!(INT&AT(x)))RZ(x=cvt(INT,x)); + v=AV(x); *c=v[0]; *d=b?v[1]:0; + ASSERT(0<=*c&&0<=*d,EVDOMAIN); + R 1; +} /* process a in a#"0 w */ + +static REPF(jtrep1s){A ax,e,x,y,z;B*b;I c,d,cd,j,k,m,n,p,q,*u,*v,wr,*ws;P*wp,*zp; + RZ(a&&w); + if(AT(a)&SCMPX)R rep1d(denseit(a),w,wf,wcr); + RE(rep1sa(a,&c,&d)); cd=c+d; + if(DENSE&AT(w))R rep1d(d?jdot2(sc(c),sc(d)):sc(c),w,wf,wcr); + wr=AR(w); ws=AS(w); n=wcr?*(wf+ws):1; RE(m=mult(n,cd)); + wp=PAV(w); e=SPA(wp,e); ax=SPA(wp,a); y=SPA(wp,i); x=SPA(wp,x); + GA(z,AT(w),1,wr+!wcr,ws); *(wf+AS(z))=m; zp=PAV(z); + RE(b=bfi(wr,ax,1)); + if(wcr&&b[wf]){ /* along sparse axis */ + u=AS(y); p=u[0]; q=u[1]; u=AV(y); + RZ(x=repeat(sc(c),x)); + RZ(y=repeat(sc(c),y)); + if(p&&1<c){ + j=0; DO(wf, j+=b[i];); v=j+AV(y); + if(AN(ax)==1+j){u+=j; DO(p, m=cd**u; u+=q; DO(c, *v=m+i; v+=q;););} + else{A xx;I h,i,j1=1+j,*uu; + GA(xx,INT,j1,1,0); uu=AV(xx); + k=0; DO(j1, uu[i]=u[i];); + for(i=0;i<p;++i,u+=q) + if(ICMP(uu,u,j1)||i==p-1){ + h=(i==p-1)+i-k; k=i; m=cd*uu[j]; + DO(j1, uu[i]=u[i];); + DO(h, DO(c, *v=m+i; v+=q;);); + } + RZ(xx=grade1(y)); + RZ(x=from(xx,x)); + RZ(y=from(xx,y)); + }}}else{A xx; /* along dense axis */ + j=0; DO(wcr, j+=!b[wf+i];); + RZ(y=ca(y)); + if(d){xx=jt->fill; jt->fill=e;} + x=irs2(AR(a)&&CMPX&AT(a)?a:d?jdot2(sc(c),sc(d)):sc(c),x,0L,1L,j,jtrepeat); + if(d)jt->fill=xx; + RZ(x); + } + SPB(zp,e,e); + SPB(zp,a,ax); + SPB(zp,i,y); + SPB(zp,x,x); + R z; +} /* scalar #"r sparse or sparse #"0 (dense or sparse) */ + + +F2(jtrepeat){B ab,wb;I acr,ar,at,m,wcr,wf,wr,wt; + RZ(a&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + at=AT(a); ab=1&&at&DENSE; + wt=AT(w); wb=1&&wt&DENSE; + if(1<acr||acr<ar)R rank2ex(a,w,0L,MIN(1,acr),wcr,jtrepeat); + ASSERT(!acr||!wcr||(m=*AS(a),m==*(wf+AS(w))),EVLENGTH); + if(!acr||!wcr)R ab&&wb?rep1d(a,w,wf,wcr):rep1s(a,w,wf,wcr); + if(at&CMPX+SCMPX)R ab?repzdx(a,w,wf,wcr):repzsx(a,w,wf,wcr); + if(at&B01 +SB01 )R ab?repbdx(a,w,wf,wcr):repbsx(a,w,wf,wcr); + /* integer */ R ab?repidx(a,w,wf,wcr):repisx(a,w,wf,wcr); +} /* a#"r w main control */
new file mode 100644 --- /dev/null +++ b/vs.c @@ -0,0 +1,351 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: $. Sparse Arrays */ + +#include "j.h" + + +B jtscheck(J jt,A w){A a,e,x,y;I r,*s,t;P*p; + RZ(w); + r=AR(w); s=AS(w); t=AT(w); + if(t&DENSE)R 1; + ASSERTSYS(r,"scheck rank"); + DO(r, ASSERTSYS(0<=s[i],"scheck shape");); + p=PAV(w); a=SPA(p,a); e=SPA(p,e); y=SPA(p,i); x=SPA(p,x); + ASSERTSYS(a,"scheck a missing"); + ASSERTSYS(e,"scheck e missing"); + ASSERTSYS(y,"scheck i missing"); + ASSERTSYS(x,"scheck x missing"); + ASSERTSYS(1==AR(a),"scheck a rank"); + ASSERTSYS(all1(eps(a,IX(r))),"scheck a index"); + ASSERTSYS(equ(a,nub(a)),"scheck a unique"); + ASSERTSYS(!AR(e),"scheck e rank"); + ASSERTSYS(AT(e)==DTYPE(t),"scheck e type"); + ASSERTSYS(AT(e)==AT(x),"scheck e/x type"); + ASSERTSYS(2==AR(y),"scheck i rank"); + ASSERTSYS(INT&AT(y),"scheck i type"); + ASSERTSYS(IC(y)==IC(x),"scheck i/x tally"); + ASSERTSYS(*(1+AS(y))==IC(a),"scheck i/a length"); + ASSERTSYS(equ(y,nub(y)),"scheck i unique"); + ASSERTSYS(all1(le(zero,y)),"scheck i negative"); + ASSERTSYS(all1(irs2(y,from(a,shape(w)),0L,1L,1L,jtlt)),"scheck i index"); + ASSERTSYS(equ(grade1(y),IX(*AS(y))),"scheck i sorted"); + ASSERTSYS(AR(x)==1+r-AN(a),"scheck x rank"); + ASSERTSYS(equ(behead(shape(x)),from(less(IX(r),a),shape(w))),"scheck x shape"); + R 1; +} /* assertions on sparse array w */ + +static A jtselm(J jt,I t){R t&NUMERIC?cvt(t,zero):t&BOX?ace:chr[' '];} + +A jtpaxis(J jt,I r,A a){A y,z;B*b;I j,*u,*v; + RZ(a); + if(!(INT&AT(a)))RZ(a=cvt(INT,a)); + u=AV(a); + GA(y,B01,r,1,0); b=BAV(y); + memset(b,C0,r); DO(AN(a), j=u[i]; b[0>j?j+r:j]=1;); + GA(z,INT,r,1,0); v= AV(z); + DO(r, if( b[i])*v++=i;); + DO(r, if(!b[i])*v++=i;); + R z; +} /* permuted axes per sparse axes specification a */ + +static A jtvaxis(J jt,I r,A a){A y;B*b;I j,n,*v; + RZ(a=cvt(INT,a)); + n=AN(a); v=AV(a); + ASSERT(1>=AR(a),EVRANK); + GA(y,B01,r,1,0); b=BAV(y); memset(b,C0,r); + DO(n, j=v[i]; if(0>j)j+=r; ASSERT(0<=j&&j<r&&!b[j],EVINDEX); b[j]=1;); + R ifb(r,b); +} /* standardize axes to be non-negative, sorted */ + +A jtdaxis(J jt,I r,A a){R less(IX(r),a);} + /* dense axes relative to sparse axes a */ + +static A jtsparse1a(J jt,A s,A a,A e,A y,A x){A z;B*b;I an,*av,et,r,*sv,t,*v;P*p; + RZ(s&&a&&e); + RZ(s=vi(s)); r=AN(s); sv=AV(s); + ASSERT(1>=AR(s),EVRANK); + ASSERT(r,EVLENGTH); + ASSERT(r<=RMAX,EVLIMIT); + DO(r, ASSERT(0<=sv[i],EVDOMAIN);); + RZ(a=vaxis(r,a==mark?IX(r):a)); an=AN(a); av=AV(a); + if(e==mark)RZ(e=scf(0.0)); + ASSERT(!AR(e),EVRANK); + et=AT(e); + ASSERT(!(et&LIT+BOX),EVNONCE); + ASSERT(STYPE(et),EVDOMAIN); + RZ(b=bfi(r,a,0)); + if(y==mark){ + GA(y,INT,0L,2L,0L); v=AS(y); v[0]=0; v[1]=an; + GA(x,et,0L,1+r-an,0L); v=AS(x); v[0]=0; DO(r, if(b[i])*++v=sv[i];); + }else{A q,x1,y1;C*xu,*xv;I i,j,k,m,n,*qv,*u,*yu,*yv; + ASSERT(2==AR(y),EVRANK); + ASSERT(an==*(1+AS(y)),EVLENGTH); + if(!(INT&AT(y)))RZ(y=cvt(INT,y)); + GA(q,INT,an,1,0); qv=AV(q); + DO(an, qv[i]=sv[av[i]];); + u=AV(y); + DO(*AS(y), DO(an, j=*u++; ASSERT(0<=j&&j<qv[i],EVINDEX););); + ASSERT(AR(x)==1+r-an,EVRANK); + v=AS(x); DO(r, if(b[i]){j=*++v; ASSERT(j==sv[i],EVLENGTH);}); + ASSERT(*AS(x)==*AS(y),EVLENGTH); + ASSERT(HOMO(et,AT(x)),EVDOMAIN); + t=maxtype(et,AT(x)); + if(t!=et )RZ(e=cvt(t,e)); + if(t!=AT(x))RZ(x=cvt(t,x)); + n=*AS(y)-1; u=AV(y); v=an+u; + for(i=0;i<n;++i){ + j=0; + DO(an, if(u[i]<v[i]){j=-1; break;}else if(u[i]>v[i]){j=1; break;}); + if(0<=j)break; + u+=an; v+=an; + } + if(n&&0<=j){ + m=aii(x); k=m*bp(t); + RZ(q=grade1(y)); qv=AV(q); + GA(y1,INT,AN(y),AR(y),AS(y)); yv= AV(y1); yu= AV(y); ICPY(yv,yu+an**qv,an); + GA(x1,t, AN(x),AR(x),AS(x)); xv=CAV(x1); xu=CAV(x); MC(xv,xu+k**qv,k); + for(i=0;i<n;++i){ + ++qv; v=yu+an**qv; + DO(an, if(yv[i]<v[i]){yv+=an; ICPY(yv,v,an); xv+=k; MC(xv,xu+k**qv,k); break;}); + } + yv+=an; AN(y1)=yv-AV(y1); *AS(y1)=AN(y1)/an; y=y1; + xv+=k; *AS(x1)=(xv-CAV(x1))/k; AN(x1)=m**AS(x1); x=x1; + }} + t=STYPE(AT(x)); + ASSERT(t,EVDOMAIN); + GA(z,t,1,r,sv); p=PAV(z); + SPB(p,a,a); + SPB(p,e,e); + SPB(p,i,y); + SPB(p,x,x); + R z; +} + +A jtsparseit(J jt,A w,A a,A e){PROLOG;A ax,c,x,y,z;B b,*cv;I cm,cn,m,n,r,*s,t,*u,*v,wn;P*p; + RZ(w&&a&&e); + r=AR(w); t=AT(w); wn=AN(w); n=AN(a); + ASSERT(!(t&LIT+BOX),EVNONCE); + ASSERT(STYPE(t),EVDOMAIN); + if(!r){ASSERT(!AN(a),EVINDEX); R ca(w);} + RZ(z=sparse1a(shape(w),a,e,mark,mark)); p=PAV(z); + RZ(ax=paxis(r,a)); + GA(y,INT,r,1,0); s=AV(y); + u=AV(ax); v=AS(w); DO(r, s[i]=v[u[i]];); + RE(m=prod(n,s)); b=equ(a,IX(r)); + RZ(x=gah(1+r-n,b?w:cant2(ax,w))); v=AS(x); *v=m; if(r>n)ICPY(1+v,n+s,r-n); + b=b&&SB01&AT(z)&&equ(e,zero); c=w; + if(!b)RZ(c=not(irs2(reshape(vec(INT,r-n,n+s),SPA(p,e)),x,0L,RMAX,-1L,jtmatch))); + cn=AN(c); cv=BAV(c); cm=bsum(cn,cv); + /* RZ(y=abase2(vec(INT,n,s),repeat(c,IX(cn)))); */ + GA(y,INT,cm*n,2,0); u=AS(y); *u++=cm; *u=n; + if(cm){I d,e,k,q,*sn,*yv; + k=cn-1; cv+=cn; yv=AN(y)+AV(y); sn=s+n; d=*(sn-1); e=*(sn-2); + switch(n){ + case 1: cv=BAV(c); yv=AV(y); DO(cn, if(*cv++)*yv++=i;); break; + case 2: DO(cn, if(*--cv){q=k-i; *--yv=q%d; *--yv=q/d;}); break; + case 3: DO(cn, if(*--cv){q=k-i; *--yv=q%d; q/=d; *--yv=q%e; *--yv=q/e;}); break; + default: DO(cn, if(*--cv){q=k-i; u=sn; DO(n, d=*--u; *--yv=q%d; q/=d;);}); + }} + SPB(p,i,y); + SPB(p,x,b?reshape(sc(cm),one):repeat(c,x)); + EPILOG(z); +} + +F1(jtdenseit){A a,e,q,s1,x,y,z;B b;C*xv,*zv;I an,ck,k,n,r,t,*s,xn,*yv;P*wp; + RZ(w); + r=AR(w); t=AT(w); + if(!r||t&DENSE)R ca(w); + t=DTYPE(t); + wp=PAV(w); a=SPA(wp,a); e=SPA(wp,e); x=SPA(wp,x); y=SPA(wp,i); + xn=AN(x); an=AN(a); b=equ(a,IX(an)); + if(!an||!xn)R reshape(shape(w),xn?x:e); + if(b)s=AS(w); else{RZ(q=over(a,less(IX(r),a))); RZ(s1=from(q,shape(w))); s=AV(s1);} + RE(n=prod(r,s)); + GA(z,t,n,r,s); zv=CAV(z); xv=CAV(x); + if(1<an)RZ(y=base2(vec(INT,an,s),y)); yv=AV(y); + k=bp(t); ck=k*aii(x); mvc(k*n,zv,k,AV(e)); + DO(IC(y), MC(zv+ck**yv,xv,ck); ++yv; xv+=ck;); + R b?z:cant2(pinv(q),z); +} /* $.^:_1 */ + +F2(jtreaxis){A a1,e,p,q,x,y,z;B*b;I c,d,j,k,m,r,*u,*v,*ws,wt;P*wp,*zp; + RZ(a&&w); + wt=AT(w); + if(wt&DENSE)R sparseit(w,a,selm(wt)); + r=AR(w); ws=AS(w); wp=PAV(w); + GA(z,wt,1L,r,ws); zp=PAV(z); + SPB(zp,a,a1=vaxis(r,a)); + SPB(zp,e,e=ca(SPA(wp,e))); + a=SPA(wp,a); x=SPA(wp,x); y=SPA(wp,i); m=*AS(y); + if(all1(eps(a,a1))){I*s; /* old is subset of new */ + RZ(p=eps(daxis(r,a),a1)); b=BAV(p); + GA(q,INT,1+r,1,0); u=AV(q); j=1; + GA(q,INT,1+r,1,0); v=AV(q); k=0; + s=AS(x); c=1; DO(AN(p), d=s[1+i]; if(b[i]){c*=d; v[k++]=d;}else u[j++]=d;); *u=c*m; + RZ(x=reshape(vec(INT,j,u),cant2(increm(dgrade1(p)),x))); + RZ(q=not(irs2(x,reshape(vec(INT,AR(x)-1,1+AS(x)),e),0L,-1L,RMAX,jtmatch))); + SPB(zp,x,x=repeat(q,x)); + RZ(y=stitch(repeat(sc(c),y),reshape(v2(c*m,k),abase2(vec(INT,k,v),IX(c))))); + RZ(p=grade1(over(a,less(a1,a)))); + if(equ(p,IX(AN(p))))SPB(zp,i,repeat(q,y)) + else{y=fromr(p,repeat(q,y)); q=grade1(y); SPB(zp,i,from(q,y)); SPB(zp,x,from(q,x));} + R z; + } + if(all1(eps(a1,a))){A x1,y1;B*pv;C*s,*t;I g,h,*iv,n; /* new is subset of old */ + c=AN(a); d=AN(a1); + RZ(p=eps(a,a1)); + RZ(y=fromr(dgrade1(p),y)); + RZ(q=grade1(y)); RZ(y=from(q,y)); RZ(x=from(q,x)); + GA(q,B01,m,1,0); b=BAV(q); n=0; + if(m){b[m-1]=1; n=1; u=AV(y); DO(m-1, if(b[i]=1&&ICMP(u,u+c,d))++n; u+=c;);} + GA(q,INT,1+r,1,0); u=AV(q); + j=0; v=AV(a); pv=BAV(p); DO(AN(p), if(!pv[i])u[j++]=ws[v[i]];); + RE(prod(j,u)); u[j]=k=1; DO(c-d, --j; u[j]=k*=u[j];); + RZ(q=pdt(take(v2(m,d-c),y),vec(INT,c-d,1+u))); iv=AV(q); + RZ(p=over(less(a,a1),daxis(r,a))); v=AV(p); + *u=n; j=1; DO(AN(p), u[j++]=ws[*v++];); RE(h=prod(1+r-d,u)); + GA(x1,AT(x),h,1+r-d,u); t=CAV(x1); s=CAV(x); + GA(y1,INT,n*d,2,0); *AS(y1)=n; *(1+AS(y1))=d; v= AV(y1); u= AV(y); + k=bp(AT(x)); g=k*aii(x); h=k*aii(x1); mvc(k*AN(x1),t,k,AV(e)); + DO(m, MC(t+g*iv[i],s,g); s+=g; if(b[i]){ICPY(v,u+i*c,d); v+=d; t+=h;}); + SPB(zp,i,y1); SPB(zp,x,cant2(increm(indexof(p,daxis(r,a1))),x1)); + R z; + } + R reaxis(a1,reaxis(over(a,less(a1,a)),w)); +} /* (2;a)$.w */ + +static A jtaxbytes1(J jt,I t,I an,I m,I xr,I*xs){I k,z; + k=bp(t); + z =SZI*AH+SZI*(an+xr)+sizeof(P); + z+=SZI*AH+k; + z+=SZI*AH+SZI*(1+xr)+k*m*prod(xr,xs); + z+=SZI*AH+SZI*2+SZI*m*an; + R sc(z); +} + +static F2(jtaxbytes){A a1,e,p,q,x;B*b;I c,d,j,m,n=0,r,*u,*v,*ws,wt;P*wp; + RZ(a&&w); + r=AR(w); ws=AS(w); wt=AT(w); + GA(q,INT,r,1,0); u=AV(q); j=0; + RZ(a1=vaxis(r,a)); d=AN(a1); + if(wt&SPARSE){wp=PAV(w); a=SPA(wp,a); e=SPA(wp,e); x=SPA(wp,x); c=1;} + else { a=mtv; RZ(e=selm(wt)); x=w; c=0;} + if(all1(eps(a,a1))){ /* old is subset of new */ + RZ(p=eps(daxis(r,a),a1)); b=BAV(p); + v=c+AS(x); DO(AN(p), if(!b[i])u[j++]=v[i];); + RZ(q=irs2(cant2(plus(sc(c),dgrade1(p)),x),reshape(vec(INT,j,u),e),0L,j,j,jtmatch)); + b=BAV(q); n=AN(q); DO(n, if(*b++)--n;); + R axbytes1(AT(e),d,n,j,u); + } + if(all1(eps(a1,a))){A y=SPA(wp,i); /* new is subset of old */ + RZ(y=fromr(indexof(a,a1),y)); + RZ(y=grade2(y,y)); + if(m=*AS(y)){n=1; u=AV(y); DO(m-1, if(ICMP(u,u+d,d))++n; u+=d;);} + RZ(p=over(less(a,a1),daxis(r,a))); v=AV(p); + DO(AN(p), u[j++]=ws[*v++];); + R axbytes1(AT(e),d,n,j,u); + } + R axbytes(a1,reaxis(over(a,less(a1,a)),w)); +} /* bytes required for (2;a)$.w */ + +static F2(jtaxtally){A a1,e,p,q,x;B*b;I c,d,j,m,n=0,r,*u,*v,*ws,wt;P*wp; + RZ(a&&w); + r=AR(w); ws=AS(w); wt=AT(w); + GA(q,INT,r,1,0); u=AV(q); j=0; + RZ(a1=vaxis(r,a)); d=AN(a1); + if(wt&SPARSE){wp=PAV(w); a=SPA(wp,a); e=SPA(wp,e); x=SPA(wp,x); c=1;} + else { a=mtv; RZ(e=selm(wt)); x=w; c=0;} + if(all1(eps(a,a1))){ /* old is subset of new */ + RZ(p=eps(daxis(r,a),a1)); b=BAV(p); + v=c+AS(x); DO(AN(p), if(!b[i])u[j++]=v[i];); + RZ(q=irs2(cant2(plus(sc(c),dgrade1(p)),x),reshape(vec(INT,j,u),e),0L,j,j,jtmatch)); + b=BAV(q); n=AN(q); DO(n, if(*b++)--n;); + R sc(n); + } + if(all1(eps(a1,a))){A y=SPA(wp,i); /* new is subset of old */ + RZ(y=fromr(indexof(a,a1),y)); + RZ(y=grade2(y,y)); + if(m=*AS(y)){n=1; u=AV(y); DO(m-1, if(ICMP(u,u+d,d))++n; u+=d;);} + R sc(n); + } + R axtally(a1,reaxis(over(a,less(a1,a)),w)); +} /* #4$.(2;a)$.w */ + +F2(jtrezero){A x,z;I at,t,wt,zt;P*wp,*zp; + RZ(a&&w); + at=AT(a); wp=PAV(w); x=SPA(wp,x); wt=AT(x); + ASSERT(!AR(a),EVRANK); + ASSERT(HOMO(at,wt),EVDOMAIN); + RE(t=maxtype(at,wt)); zt=STYPE(t); + ASSERT(zt,EVDOMAIN); + GA(z,zt,1,AR(w),AS(w)); zp=PAV(z); + SPB(zp,e,t==at?ca(a):cvt(t,a)); + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,i,ca(SPA(wp,i))); + SPB(zp,x,t==wt?ca(x):cvt(t,x)); + R z; +} /* respecify the sparse element */ + +F1(jtunzero){A e,q,x,z;I r;P*wp,*zp; + RZ(w); + wp=PAV(w); e=SPA(wp,e); x=SPA(wp,x); r=AR(x)-1; + GA(z,AT(w),1,AR(w),AS(w)); zp=PAV(z); + RZ(q=not(irs2(x,reshape(vec(INT,r,1+AS(x)),e),0L,r,r,jtmatch))); + SPB(zp,x,repeat(q,x)); + SPB(zp,i,repeat(q,SPA(wp,i))); + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,e,ca(e)); + R z; +} /* remove completely sparse cells */ + +static F1(jtsparsep1){A*wv;I n=0,wd=0; + RZ(w); + ASSERT(1>=AR(w),EVRANK); + if(BOX&AT(w)){n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); ASSERT(1<=n&&n<=3||5==n,EVLENGTH);} + R sparse1a(0<n?WVR(0):w,1<n?WVR(1):mark,2<n?WVR(2):mark,3<n?WVR(3):mark,4<n?WVR(4):mark); +} + +static F1(jtsparsen1){A*u,z;P*p; + RZ(w); + ASSERT(SPARSE&AT(w),EVDOMAIN); + GA(z,BOX,3,1,0); u=AAV(z); p=PAV(w); + u[0]=shape(w); u[1]=ca(SPA(p,a)); u[2]=ca(SPA(p,e)); + RE(0); R z; +} + +F1(jtsparse1){ + RZ(w); + if(!AR(w)||SPARSE&AT(w))R ca(w); + R sparseit(w,IX(AR(w)),selm(AT(w))); +} /* $. y */ + +F2(jtsparse2){A*av,q=0;B b;I ad,j,k,t,*v;P*p; + RZ(a&&w); + if(BOX&AT(a)){ + ASSERT(1==AR(a),EVRANK); + ASSERT(2==AN(a),EVLENGTH); + av=AAV(a); ad=(I)a*ARELATIVE(a); a=AVR(0); q=AVR(1); + } + RZ(a=cvt(INT,a)); + ASSERT(1>=AR(a),EVRANK); + v=AV(a); k=*v; + ASSERT(2==k||!AR(a),EVRANK); + ASSERT(2>=AN(a),EVLENGTH); + p=PAV(w); t=AT(w); b=1&&t&SPARSE; + ASSERT(b||0<=k&&k<=2,EVDOMAIN); + switch(k){ + case 0: ASSERT(!q,EVDOMAIN); R t&SPARSE?denseit(w):sparse1(w); + case 1: ASSERT(!q,EVDOMAIN); R sparsep1(w); + case -1: ASSERT(!q,EVDOMAIN); R sparsen1(w); + case 2: + if(AR(a)){j=v[1]; ASSERT(q&&(1==j||2==j),EVDOMAIN); R 1==j?axbytes(q,w):axtally(q,w);} + if(q)R reaxis(q,w); else if(b)R rat(SPA(p,a)); else{ASSERT(STYPE(t),EVDOMAIN); R IX(AR(w));} + case 3: R q?rezero(q,w):rat(SPA(p,e)); + case 4: ASSERT(!q,EVDOMAIN); R rat(SPA(p,i)); + case 5: ASSERT(!q,EVDOMAIN); R rat(SPA(p,x)); + case 7: ASSERT(!q,EVDOMAIN); R sc(IC(SPA(p,i))); + case 8: ASSERT(!q,EVDOMAIN); R unzero(w); + default: ASSERT(0,EVDOMAIN); +}} /* x $. y */
new file mode 100644 --- /dev/null +++ b/vsb.c @@ -0,0 +1,669 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: s: */ + +#include "j.h" + + +/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ + +#define BLACK 0 +#define RED 1 +#define ROOT (jt->sbroot) +#define FILLFACTOR (jt->sbfillfactor) +#define GAP (jt->sbgap) + +static const SBU sentinel = {0,0,0,BLACK,0,0,0,IMIN,0,0}; + +/* #define TMP */ +#ifdef TMP +#include <time.h> +static int tmp_lr=0; +static int tmp_rr=0; +static int tmp_lt=0; +static int tmp_while=0; +static int tmp_node=0; +static int tmp_reorder=0; +static int tmp_moves=0; +static int tmp_imax=0; +static int tmp_rhit=0; +static int tmp_lhit=0; +static clock_t clo; +static D tickk=1.0/CLOCKS_PER_SEC; +#endif + + +/* implementation dependend declarations */ +typedef enum { + STATUS_OK, + STATUS_MEM_EXHAUSTED, + STATUS_DUPLICATE_KEY, + STATUS_KEY_NOT_FOUND +} statusEnum; + + +#ifdef TMP +#define NODE(a) (tmp_node++,a+jt->sbuv) +#else +#define NODE(a) (a+jt->sbuv) +#endif + +#define NODEM(a,b) (jt->sbuv[a].b) +#define LEFT(a) NODEM(a,left) +#define RIGHT(a) NODEM(a,right) +#define ORDER(a) NODEM(a,order) +#define INDEX(a) NODEM(a,i) +#define LENGTH(a) NODEM(a,n) +#define HASH(a) NODEM(a,h) +#define COLOR(a) NODEM(a,color) +#define DOWN(a) NODEM(a,down) +#define UP(a) NODEM(a,up) +#define PARENT(a) NODEM(a,parent) +#define GRANDPARENT(a) (PARENT(PARENT(a))) +#define ISLEFTCHILD(x) (x == LEFT(PARENT(x))) +#define ISRIGHTCHILD(x) (x == RIGHT(PARENT(x))) +#define compLT(a,b) Vcompare(jt,a,b) +#define compEQ(a,b) ( a == b ) + + + +#ifdef TMP +static void showdepth(J jt, I node, int **ptr, I* size, I depth) +{ + if(LEFT(node) == 0) { + (*ptr) = realloc((*ptr), sizeof(I)*((*size)+1)); + (*ptr)[(*size)++]=depth; + } + else showdepth(jt, LEFT(node), ptr, size, depth+1); + + if(RIGHT(node) == 0) { + (*ptr) = realloc((*ptr), sizeof(I)*((*size)+1)); + (*ptr)[(*size)++]=depth; + } + else showdepth(jt, RIGHT(node), ptr, size, depth+1); +} +#endif + +static __inline int Vcompare(J jt,I a,I b){I m,n;SBU*u,*v;UC*s,*t;U2*p,*q; +#ifdef TMP + tmp_lt++; +#endif + u=a+jt->sbuv; m=u->n; s=(UC*)(jt->sbsv+u->i); + v=b+jt->sbuv; n=v->n; t=(UC*)(jt->sbsv+v->i); + switch((SBC2&u->flag?2:0)+(SBC2&v->flag?1:0)){ + case 0: { DO(MIN(m,n), if(*s!=*t)R *s<*t; ++s; ++t;);} break; + case 1: { q=(U2*)t; n/=2; DO(MIN(m,n), if(*s!=*q)R *s<*q; ++s; ++q;);} break; + case 2: {p=(U2*)s; m/=2; DO(MIN(m,n), if(*p!=*t)R *p<*t; ++p; ++t;);} break; + case 3: {p=(U2*)s; q=(U2*)t; m/=2; n/=2; DO(MIN(m,n), if(*p!=*q)R *p<*q; ++p; ++q;);} + } + R m<n; +} + +static __inline void rotateLeft(J jt, I x) {I y; +#ifdef TMP + tmp_lr++; +#endif + /*************************** + * rotate node x to left * + ***************************/ + y = RIGHT(x); + if (RIGHT(x)= LEFT(y)) PARENT(LEFT(y)) = x; /* establish x->right link */ + if (y) PARENT(y) = PARENT(x); /* establish y->parent link */ + if (PARENT(x) == 0) ROOT = y; + else if (ISLEFTCHILD(x)) LEFT (PARENT(x))= y; + else RIGHT(PARENT(x))= y; + if (LEFT(y) = x) PARENT(x) = y; /* link x and y */ +} + + +static __inline void rotateRight(J jt, I x) {I y; +#ifdef TMP + tmp_rr++; +#endif + /*************************** + * rotate node x to right * + ***************************/ + y = LEFT(x); + if (LEFT(x)= RIGHT(y)) PARENT(RIGHT(y))= x; /* establish x->left link */ + if (y) PARENT(y) = PARENT(x); /* establish y->parent link */ + if (PARENT(x) == 0) ROOT = y; + else if (ISRIGHTCHILD(x)) RIGHT(PARENT(x))= y; + else LEFT (PARENT(x))= y; + if (RIGHT(y)= x) PARENT(x) = y; /* link x and y */ +} + +static __inline void insertFixup(J jt, I x) {B b;I y; + + /************************************* + * maintain Red-Black tree balance * + * after inserting node x * + *************************************/ + + /* check Red-Black properties */ + /* the repositioning is necessary to propogate the rebalancing */ + while (x != ROOT && COLOR(PARENT(x)) == RED) { +#ifdef TMP + tmp_while++; +#endif + if (ISLEFTCHILD(PARENT(x))) { /* we have a violation */ + y = RIGHT(GRANDPARENT(x)); /* uncle */ + b = COLOR(y)==BLACK; /* uncle is BLACK */ + if (b && ISRIGHTCHILD(x)) {x=PARENT(x); rotateLeft(jt,x);} + COLOR(PARENT(x)) = BLACK; + COLOR(GRANDPARENT(x)) = RED; + if (b) rotateRight(jt, GRANDPARENT(x)); + else {COLOR(y)=BLACK; x=GRANDPARENT(x);} + }else { /* mirror image of above code */ + y = LEFT(GRANDPARENT(x)); /* uncle */ + b = COLOR(y)==BLACK; /* uncle is BLACK */ + if (b && ISLEFTCHILD(x)) {x=PARENT(x); rotateRight(jt,x);} + COLOR(PARENT(x)) = BLACK; + COLOR(GRANDPARENT(x)) = RED; + if (b) rotateLeft(jt, GRANDPARENT(x)); + else {COLOR(y)=BLACK; x=GRANDPARENT(x);} + }} + COLOR(ROOT) = BLACK; +} + +static statusEnum insert(J jt, I key) { + I current,dist,i,keep1,keep2,lorder,parent,rorder,to_the_left,to_the_right;SBU *x; +#ifdef TMP + static I icount=0; +#endif + + if (key < 0) R STATUS_KEY_NOT_FOUND; + + /*********************************************** + * allocate node for data and insert in tree * + ***********************************************/ + + /* find future parent */ + current = ROOT; /* jt-> root points to the int value of the root symbol */ + parent = to_the_left = to_the_right = 0; + + while (current != 0) { + if (compEQ(key, current))return STATUS_DUPLICATE_KEY; + parent = current; + if(compLT(key, current)){to_the_right=current; current= LEFT(current);} + else {to_the_left =current; current=RIGHT(current);} + } + +#ifdef TMP + icount++; + if (icount==10000&&0) {I corder,running; + icount=running=corder=0; + do { + ORDER(running)=corder; + corder+=FILLFACTOR; + running=UP(running); + } while(running); + } +#endif + + /* get the new node */ + + lorder = to_the_left ? ORDER(to_the_left) : 0; + rorder = to_the_right ? ORDER(to_the_right) : lorder + 2 * FILLFACTOR; + + if(rorder-lorder<2) { /* if(rorder-lorder<(2*GAP)) { */ + i=0; + /*parameter GAP is TWICE the difference in order numbers we want after re-ordering*/ + while(to_the_right&&to_the_left&&(ORDER(to_the_right)-ORDER(to_the_left))<(GAP*++i)){ + keep1=to_the_left; to_the_left =DOWN(to_the_left); + keep2=to_the_right; to_the_right=UP (to_the_right); + } + +#ifdef TMP + if(!to_the_left )UP(0) =keep1,i++,tmp_lhit++ ; + if(!to_the_right)DOWN(0)=keep2,i++,tmp_rhit++; + tmp_imax=__max(i,tmp_imax); + tmp_moves+=2*i; + tmp_reorder++; +#else + if(!to_the_left )UP(0) =keep1,i++; + if(!to_the_right)DOWN(0)=keep2,i++; +#endif + + lorder= to_the_left ? ORDER(to_the_left ) : rorder-2*i*FILLFACTOR; + rorder= to_the_right ? ORDER(to_the_right) : lorder+2*i*FILLFACTOR; + dist = (rorder-lorder)/(2*i); + + while(--i) { + to_the_left =UP (to_the_left); lorder+=dist; ORDER(to_the_left )=lorder; + to_the_right=DOWN(to_the_right); rorder-=dist; ORDER(to_the_right)=rorder; + } + } + + x = NODE(key); + x->parent= parent; + x->left = 0; + x->right = 0; + x->color = RED; + x->order = (rorder+lorder)/2; + x->up = to_the_right; DOWN(to_the_right)=key; + x->down = to_the_left; UP(to_the_left) =key; + + /* insert node in tree */ + if (0==parent) ROOT =key; + else if(compLT(key, parent))LEFT(parent) =key; + else RIGHT(parent)=key; + + insertFixup(jt, key); + + return STATUS_OK; +} + +/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ + +static I jtsbextend(J jt,I n,C*s,UI h,I hi){A x;I c,*hv,j,p;SBU*v; + c=jt->sbun; + if(c==*AS(jt->sbu)){ /* extend sbu unique symbols */ + RZ(x=ext(1,jt->sbu)); jt->sbu=x; jt->sbuv=(SBU*)AV(x); + } + if(AN(jt->sbs)<n+jt->sbsn){ /* extend sbs strings */ + GA(x,LIT,2*(n+jt->sbsn),1,0); MC(CAV(x),jt->sbsv,jt->sbsn); + fa(jt->sbs); ra(x); jt->sbs=x; jt->sbsv=CAV(x); + } + if(AN(jt->sbh)<2*c){ /* extend sbh hash table */ + p=2*AN(jt->sbh); DO(64, if(p<=ptab[i]){p=ptab[i]; break;}); + RZ(x=apv(p,-1L,0L)); hv=AV(x); v=jt->sbuv; + DO(c, j=v++->h%p; while(0<=hv[j])j=(1+j)%p; hv[j]=i;); + fa(jt->sbh); ra(x); jt->sbh=x; jt->sbhv= AV(x); + hi=h%p; /* new hi wrt new sbh size */ + while(0<=hv[hi])hi=(1+hi)%p; + } + R hi; +} + +static SB jtsbinsert(J jt,B c2,I n,C*s,UI h,I hi){I c,m,p;SBU*u; + c=jt->sbun; /* cardinality */ + m=jt->sbsn; /* existing # chars in sbs */ + p=c2&&m%2; /* pad for alignment */ + RE(hi=sbextend(n+p,s,h,hi)); /* extend global tables as req'd*/ + MC(SBSV(m+p),s,n); /* copy string into sbs */ + u=SBUV(c); u->i=m+p; u->n=n; u->h=h; /* index/length/hash */ + u->flag=c2?SBC2:0; + ASSERTSYS(STATUS_OK==insert(jt,c),"sbinsert"); + (jt->sbhv)[hi]=c; /* make sbh point to new symbol */ + ++jt->sbun; /* # unique symbols */ + jt->sbsn+=n+p; /* # chars in sbs */ + R(SB)c; +} /* insert new symbol */ + +static SB jtsbprobe(J jt,B c2,I n,C*s){B b;C*t;I hi,hn,ui;SBU*u;UI h; + h=c2?hic2(n,(UC*)s):hic(n,(UC*)s); + hn=AN(jt->sbh); /* size of hast table */ + hi=h%hn; /* index into hash table */ + while(1){ + ui=(jt->sbhv)[hi]; /* index into unique symbols */ + if(0>ui)R sbinsert(c2,n,s,h,hi); /* new symbol */ + u=SBUV(ui); + if(h==u->h){ /* old symbol, maybe */ + t=SBSV(u->i); + switch((c2?2:0)+(u->flag&SBC2?1:0)){ + case 1: if(n==u->n/2){C2*q=(C2*)t; b=1; DO(n, if(s[i]!=q[i]){b=0; break;}); if(b)R(SB)ui;} + case 2: if(n==u->n*2){C2*q=(C2*)s; b=1; DO(n/2, if(t[i]!=q[i]){b=0; break;}); if(b)R(SB)ui;} + case 3: + case 0: if(n==u->n&&!memcmp(t,s,n))R(SB)ui; break; + }} + hi=(1+hi)%hn; /* next hash table index */ +}} /* insert new symbol or get existing symbol */ + + +static A jtsbunstr(J jt,I q,A w){A z;B c2;I i,j,m,wn;SB*zv; + RZ(w); + if(!AN(w))R vec(SBT,0L,0L); + ASSERT(AT(w)&LIT+C2T,EVDOMAIN); + ASSERT(1>=AR(w),EVRANK); + c2=1&&AT(w)&C2T; wn=AN(w); + if(c2){C2 c,*wv=(C2*)AV(w); + c=wv[q==-1?0:wn-1]; + m=0; DO(wn, if(c==wv[i])++m;); + GA(z,SBT,m,1,0); zv=SBAV(z); + if(q==-1){for(i=j=1;i<=wn;++i)if(c==wv[i]||i==wn){RE(*zv++=sbprobe(c2,2*(i-j),(C*)(j+wv))); j=i+1;}} + else {for(i=j=0;i< wn;++i)if(c==wv[i] ){RE(*zv++=sbprobe(c2,2*(i-j),(C*)(j+wv))); j=i+1;}} + }else{C c,*wv=CAV(w); + c=wv[q==-1?0:wn-1]; + m=0; DO(wn, if(c==wv[i])++m;); + GA(z,SBT,m,1,0); zv=SBAV(z); + if(q==-1){for(i=j=1;i<=wn;++i)if(c==wv[i]||i==wn){RE(*zv++=sbprobe(c2,i-j,j+wv)); j=i+1;}} + else {for(i=j=0;i< wn;++i)if(c==wv[i] ){RE(*zv++=sbprobe(c2,i-j,j+wv)); j=i+1;}} + } + R z; +} /* monad s: on leading (_1=q) or trailing (_2=q) character separated strings */ + +static A jtsbunlit(J jt,C cx,A w){A z;B c2;I i,m,wc,wr,*ws;SB*zv; + RZ(w); + ASSERT(!AN(w)||AT(w)&LIT+C2T,EVDOMAIN); + ASSERT(1<AR(w),EVRANK); + c2=1&&AT(w)&C2T; wr=AR(w); ws=AS(w); wc=ws[wr-1]; + RE(m=wc?AN(w)/wc:prod(wr-1,ws)); + GA(z,SBT,m,wr-1,ws); zv=SBAV(z); + if(!wc)memset(zv,C0,m*sizeof(SB)); + else if(c2){C2 c=(C2)cx,*s,*wv=(C2*)AV(w); + for(i=0;i<m;++i){ + s=wc+wv; DO(wc, if(c!=*--s)break;); /* exclude trailing "blanks" */ + RE(*zv++=sbprobe(c2,2*((c!=*s)+s-wv),(C*)wv)); + wv+=wc; + }}else{C c=cx,*s,*wv=CAV(w); + for(i=0;i<m;++i){ + s=wc+wv; DO(wc, if(c!=*--s)break;); /* exclude trailing "blanks" */ + RE(*zv++=sbprobe(c2,(c!=*s)+s-wv,wv)); + wv+=wc; + }} + R z; +} /* each row of literal array w less the trailing "blanks" is a symbol */ + +static F1(jtsbunbox){A*wv,x,z;B c2;I i,m,n,wd;SB*zv; + RZ(w); + ASSERT(!AN(w)||BOX&AT(w),EVDOMAIN); + m=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(z,SBT,m,AR(w),AS(w)); zv=SBAV(z); + for(i=0;i<m;++i){ + x=WVR(i); n=AN(x); c2=1&&AT(x)&C2T; + ASSERT(!n||AT(x)&LIT+C2T,EVDOMAIN); + ASSERT(1>=AR(x),EVRANK); + RE(*zv++=sbprobe(c2,c2?n+n:n,CAV(x))); + } + R z; +} /* each element of boxed array w is a string */ + +static F1(jtsbunind){A z;I j,n,*zv; + RZ(z=cvt(INT,w)); + zv=AV(z); n=jt->sbun; + DO(AN(w), j=*zv++; ASSERT(0<=j&&j<n,EVINDEX);); + AT(z)=SBT; + R z; +} /* w is a numeric array of symbol indices */ + +#ifdef TMP +F1(jtsb1){ + A abc; + clo=clock(); + RZ(w); + switch(AT(w)){ + default: ASSERT(0,EVDOMAIN); + case C2T: + case LIT: abc=(1>=AR(w)?sbunstr(-1L,w):sbunlit(' ',w)); break; + case BOX: abc=(sbunbox(w)); + } + clo-=clock(); + R abc; +} +#else +F1(jtsb1){ + RZ(w); + switch(AT(w)){ + default: ASSERT(0,EVDOMAIN); + case C2T: + case LIT: R 1>=AR(w)?sbunstr(-1L,w):sbunlit(' ',w); + case BOX: R sbunbox(w); +}} /* monad s: main control */ +#endif + + +F1(jtsborder){A z;I n,*zv;SB*v; + RZ(w); + n=AN(w); v=SBAV(w); + ASSERT(!n||SBT&AT(w),EVDOMAIN); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + DO(n, *zv++=SBUV(*v++)->order;); + R z; +} /* order numbers for symbol array w */ + +static F1(jtsbbox){A z,*zv;C*s;I n;SB*v;SBU*u; + RZ(w); + n=AN(w); v=SBAV(w); + ASSERT(!n||SBT&AT(w),EVDOMAIN); + GA(z,BOX,n,AR(w),AS(w)); zv=AAV(z); + DO(n, u=SBUV(*v++); s=SBSV(u->i); RZ(*zv++=SBC2&u->flag?vec(C2T,u->n/2,s):str(u->n,s));); + R z; +} /* boxed strings for symbol array w */ + +#define C2FSB(zv,u,q,m,c) \ + {C*s=SBSV(u->i);I k=u->n; \ + if(SBC2&u->flag){MC(zv,s,k); zv+=k/=2;}else DO(k, *zv++=*s++;); \ + if(2==q)*zv++=c; else if(3==q)DO(m-k, *zv++=c;); \ + } + +static A jtsbstr(J jt,I q,A w){A z;B c2=0;C c;I m,n;SB*v,*v0;SBU*u; + RZ(w); + m=n=AN(w); v=v0=SBAV(w); c=1==q?'`':C0; + ASSERT(!n||SBT&AT(w),EVDOMAIN); + DO(n, u=SBUV(*v++); if(u->flag&SBC2){c2=1; m+=u->n/2;}else m+=u->n;); + v=v0; + GA(z,c2?C2T:LIT,m,1,0); + if(c2){C2*zv; + zv=(C2*)AV(z); + if(1==q)*zv++=c; + DO(n-1, u=SBUV(*v++); C2FSB(zv,u,2,0,c);); + if(n){ u=SBUV(*v++); C2FSB(zv,u,q,0,c);} + }else{C*zv; + zv=CAV(z); + if(1==q)*zv++=c; + DO(n-1, u=SBUV(*v++); MC(zv,SBSV(u->i),u->n); zv+=u->n; *zv++=c;); + if(n){ u=SBUV(*v++); MC(zv,SBSV(u->i),u->n); zv+=u->n; if(2==q)*zv=c;} + } + R z; +} /* leading (1=q) or trailing (2=q) separated string for symbol array w */ + +static A jtsblit(J jt,C c,A w){A z;B c2=0;I k,m=0,n;SB*v,*v0;SBU*u; + RZ(w); + n=AN(w); v=v0=SBAV(w); + ASSERT(!n||SBT&AT(w),EVDOMAIN); + DO(n, u=SBUV(*v++); k=u->n; if(u->flag&SBC2){c2=1; k/=2;} if(m<k)m=k;); + v=v0; + GA(z,c2?C2T:LIT,n*m,1+AR(w),AS(w)); *(AR(w)+AS(z))=m; + if(c2){C2*zv=(C2*)AV(z); DO(n, u=SBUV(*v++); C2FSB(zv,u,3,m,c););} + else {C*zv=CAV(z); memset(zv,c,n*m); DO(n, u=SBUV(*v++); MC(zv,SBSV(u->i),u->n); zv+=m;);} + R z; +} /* literal array for symbol array w padded with c */ + + +static F1(jtsbhashstat){A z;I j,k,n,p,*zv;SBU*v; + n=jt->sbun; v=jt->sbuv; p=AN(jt->sbh); + GA(z,INT,n,1,0); zv=AV(z); + DO(n, j=v++->h%p; k=1; while(i!=(jt->sbhv)[j]){j=(j+1)%p; ++k;} *zv++=k;); + R z; +} /* # queries in hash table for each unique symbol */ + +static A jtsbcheck1(J jt,A una,A sna,A u,A s,A h,A roota,A ff,A gp){PROLOG;A x,*xv,y; + B b,*dnv,*lfv,*rtv,*upv;C*ptv,*sv;I c,f,g,hn,*hv,i,j,r,sn,un,*yv;SBU*uv,*v; + RZ(una&&sna&&u&&s&&h); + ASSERTD(!AR(una),"c atom"); /* cardinality */ + ASSERTD(INT&AT(una),"c integer"); + c=*AV(una); + ASSERTD(0<=c,"c non-negative"); + ASSERTD(!AR(sna),"sn atom"); /* string length */ + ASSERTD(INT&AT(sna),"sn integer"); + sn=*AV(sna); + ASSERTD(0<=sn,"sn non-negative"); /* root */ + ASSERTD(!AR(roota),"root atom"); + ASSERTD(INT&AT(roota),"root integer"); + r=*AV(roota); + ASSERTD(0<=r,"root non-negative"); + ASSERTD(r<c,"root bounded by c"); + ASSERTD(!AR(ff),"ff atom"); /* fill factor */ + ASSERTD(INT&AT(ff),"ff integer"); + f=*AV(ff); + ASSERTD(0<=f,"ff non-negative"); + ASSERTD(!AR(gp),"gap atom"); /* gap */ + ASSERTD(INT&AT(gp),"gap integer"); + g=*AV(gp); + ASSERTD(0<=g,"gap non-negative"); + ASSERTD(g<f,"gap bounded by ff"); + sv=CAV(s); + un=*AS(u); uv=(SBU*)AV(u); + hn= AN(h); hv=AV(h); + ASSERTD(2==AR(u),"u matrix"); + ASSERTD(INT&AT(u),"u integer"); + ASSERTD(*(1+AS(u))==sizeof(SBU)/SZI,"u #columns"); + ASSERTD(c<=un,"c bounded by #u"); + ASSERTD(1==AR(s),"s vector"); + ASSERTD(LIT&AT(s),"s literal"); + ASSERTD(sn<=AN(s),"sn bounded by #s"); + ASSERTD(1==AR(h),"h vector"); + ASSERTD(INT&AT(h),"h integer"); + ASSERTD(c<=AN(h),"c bounded by #h"); + ASSERTD(equ(vec(INT,1L,&hn),factor(sc(hn))),"#h prime"); + b=0; DO(AN(h), j=hv[i]; if(-1==j)b=1; else ASSERTD(0<=j&&j<c,"h index");); + ASSERTD(b,"h full"); + GA(x,B01,c,1,0); lfv=BAV(x); memset(lfv,C0,c); + GA(x,B01,c,1,0); rtv=BAV(x); memset(rtv,C0,c); + GA(x,B01,c,1,0); dnv=BAV(x); memset(dnv,C0,c); + GA(x,B01,c,1,0); upv=BAV(x); memset(upv,C0,c); + GA(x,LIT,c,1,0); ptv=CAV(x); memset(ptv,C0,c); ptv[0]=1; + GA(x,BOX,c,1,0); xv=AAV(x); RZ(xv[0]=str(uv->n,sv+uv->i)); + GA(y,INT,c,1,0); yv= AV(y); yv[0]=uv->order; + for(i=1,v=1+uv;i<c;++i,++v){B c2;I ord,vi,vn;UC*vc;UI k; + c2=1&&v->flag&SBC2; + vi=v->i; + vn=v->n; + vc=(UC*)(sv+vi); + ASSERTD(0<=vi&&vi<=sn,"u index"); + ASSERTD(!(c2&&vi%2),"u index alignment"); + ASSERTD(0<=vn&&!(c2&&vn%2),"u length"); + ASSERTD(sn>=vi+vn,"u index/length"); + k=(c2?hic2:hic)(vn,vc); + ASSERTD(k==v->h,"u hash"); + j=k%hn; while(i!=hv[j]&&0<=hv[j])j=(1+j)%hn; + ASSERTD(i==hv[j],"u/h mismatch"); + ASSERTD(BLACK==v->color||RED==v->color,"u color"); + RZ(xv[i]=c2?vec(C2T,vn/2,vc):str(vn,vc)); + yv[i]=ord=v->order; + j=v->parent; ASSERTD( 0<=j&&j<c&&2>=++ptv[j],"u parent"); + j=v->left; ASSERTD(!j||0<=j&&j<c&&1>=++lfv[j]&& ord>(j+uv)->order ,"u left" ); + j=v->right; ASSERTD(!j||0<=j&&j<c&&1>=++rtv[j]&& ord<(j+uv)->order ,"u right" ); + j=v->down; ASSERTD( 0<=j&&j<c&&1>=++dnv[j]&&(!j||ord>(j+uv)->order),"u predecessor"); + j=v->up; ASSERTD( 0<=j&&j<c&&1>=++upv[j]&&(!j||ord<(j+uv)->order),"u successor" ); + } + ASSERTD(equ(grade1(x),grade1(y)),"u order"); + EPILOG(one); +} + +static F1(jtsbcheck){R sbcheck1(sc(jt->sbun),sc(jt->sbsn),jt->sbu,jt->sbs,jt->sbh,sc(ROOT),sc(FILLFACTOR),sc(GAP));} + +static F1(jtsbsetdata){A h,s,u,*wv,x;I wd; + RZ(w); + ASSERTD(BOX&AT(w),"arg type"); + ASSERTD(1==AR(w), "arg rank"); + ASSERTD(8==AN(w), "arg length"); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + RZ(sbcheck1(WVR(0),WVR(1),WVR(2),WVR(3),WVR(4),WVR(5),WVR(6),WVR(7))); + jt->sbun=*AV(WVR(0)); + jt->sbsn=*AV(WVR(1)); + RZ(x=ra(ca(WVR(2)))); u=jt->sbu; jt->sbu=x; jt->sbuv=(SBU*)AV(x); + RZ(x=ra(ca(WVR(3)))); s=jt->sbs; jt->sbs=x; jt->sbsv= CAV(x); + RZ(x=ra(ca(WVR(4)))); h=jt->sbh; jt->sbh=x; jt->sbhv= AV(x); + ROOT =*AV(WVR(5)); + FILLFACTOR=*AV(WVR(6)); + GAP =*AV(WVR(7)); + fa(u); fa(s); fa(h); + R one; +} + +static F1(jtsbgetdata){A z,*zv; + GA(z,BOX,8,1,0); zv=AAV(z); + RZ(zv[0]=sc(jt->sbun)); + RZ(zv[1]=sc(jt->sbsn)); + RZ(zv[2]=ca(jt->sbu)); + RZ(zv[3]=ca(jt->sbs)); + RZ(zv[4]=ca(jt->sbh)); + RZ(zv[5]=sc(ROOT)); + RZ(zv[6]=sc(FILLFACTOR)); + RZ(zv[7]=sc(GAP)); + R z; +} + +F2(jtsb2){A z;I j,k,n; +#ifdef TMP + I*zv; +#endif + RZ(a&&w); + RE(j=i0(a)); n=AN(w); + ASSERT(!(1<=j&&j<=7)||!n||SBT&AT(w),EVDOMAIN); + switch(j){ + default: ASSERT(0,EVDOMAIN); + case 0: + RE(k=i0(w)); + switch(k){ + default: ASSERT(0,EVDOMAIN); + case 0: R sc(jt->sbun); + case 1: R sc(jt->sbsn); + case 2: R ca(jt->sbu); + case 3: R ca(jt->sbs); + case 4: R ca(jt->sbh); + case 5: R sc(ROOT); + case 6: R sc(FILLFACTOR); + case 7: R sc(GAP); + case 10: R sbgetdata(zero); + case 11: R sbcheck(zero); + case 12: R sbhashstat(zero); + } + case 1: R sbstr(1L,w); + case -1: R sbunstr(-1L,w); + case 2: R sbstr(2L,w); + case -2: R sbunstr(-2L,w); + case 3: R sblit(C0,w); + case -3: R sbunlit(C0,w); + case 4: R sblit(' ',w); + case -4: R sbunlit(' ',w); + case 5: R sbbox(w); + case -5: R sbunbox(w); + case 6: RZ(z=ca(w)); AT(z)=INT; R z; + case -6: R sbunind(w); + case 7: R sborder(w); + case 10: R sbsetdata(w); + case 16: GAP = 4; R sc(GAP); + case 17: GAP++; ASSERT(FILLFACTOR>GAP,EVLIMIT); R sc(GAP); + case 18: GAP--; R sc(GAP); + case 19: FILLFACTOR=1024; R sc(FILLFACTOR); + case 20: FILLFACTOR*=2; R sc(FILLFACTOR); + case 21: FILLFACTOR/=2; ASSERT(FILLFACTOR>GAP,EVLIMIT); R sc(FILLFACTOR); +#ifdef TMP + case 22: + GA(z,INT,10,1,0); zv=AV(z); + zv[0] = tmp_lr = 0; + zv[1] = tmp_rr = 0; + zv[2] = tmp_lt = 0; + zv[3] = tmp_while = 0; + zv[4] = tmp_node = 0; + zv[5] = tmp_reorder = 0; + zv[6] = tmp_moves = 0; + zv[7] = tmp_imax = 0; + zv[8] = tmp_lhit; + zv[9] = tmp_rhit; + R z; + case 23: + GA(z,INT,10,1,0); + zv[0] = tmp_lr; + zv[1] = tmp_rr; + zv[2] = tmp_lt; + zv[3] = tmp_while; + zv[4] = tmp_node; + zv[5] = tmp_reorder; + zv[6] = tmp_moves; + zv[7] = tmp_imax; + zv[8] = tmp_lhit; + zv[9] = tmp_rhit; + R z; + case 24: R sc((I)clo); + case 25: R scf(tickk); +#endif +}} + + +B jtsbtypeinit(J jt){A x;I c=sizeof(SBU)/SZI,s[2]; + s[0]=2000; s[1]=c; + GA(x,LIT,20000,1,0); jt->sbs=x; jt->sbsv= CAV(x); jt->sbsn=0; + RZ(x=apv(ptab[5],-1L,0L)); jt->sbh=x; jt->sbhv= AV(x); + GA(x,INT,*s*c,2,s); jt->sbu=x; jt->sbuv=(SBU*)AV(x); + GAP=15; /* TWICE the difference in order numbers we want after re-ordering */ + FILLFACTOR=1024; + ROOT=0; /* initialize binary tree; initialize the empty symbol (used as fill) */ + jt->sbuv[0]=sentinel; + jt->sbun=1; + *jt->sbhv=0; + R 1; +} /* initialize global data for SBT datatype */
new file mode 100644 --- /dev/null +++ b/vt.c @@ -0,0 +1,131 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Take and Drop */ + +#include "j.h" + + +F1(jtbehead ){R drop(one, w);} +F1(jtcurtail){R drop(num[-1],w);} + +F1(jtshift1){R drop(num[-1],over(one,w));} + +static A jttk0(J jt,B b,A a,A w){A z;I k,m=0,n,p,r,*s,*u; + r=AR(w); n=AN(a); u=AV(a); + if(!b){RE(m=prod(n,u)); ASSERT(m>IMIN,EVLIMIT); RE(m=mult(ABS(m),prod(r-n,n+AS(w))));} + GA(z,AT(w),m,r,AS(w)); + s=AS(z); DO(n, p=u[i]; ASSERT(p>IMIN,EVLIMIT); *s++=ABS(p);); + if(m){k=bp(AT(w)); mvc(k*m,AV(z),k,jt->fillv);} + R z; +} + +static F2(jttks){PROLOG;A a1,q,x,y,z;B b,c;I an,m,r,*s,*u,*v;P*wp,*zp; + an=AN(a); u=AV(a); r=AR(w); s=AS(w); + GA(z,AT(w),1,r,s); v=AS(z); DO(an, v[i]=ABS(u[i]);); + zp=PAV(z); wp=PAV(w); + if(an<=r){RZ(a=vec(INT,r,s)); ICPY(AV(a),u,an);} + a1=SPA(wp,a); RZ(q=paxis(r,a1)); m=AN(a1); + RZ(a=from(q,a )); u=AV(a); + RZ(y=from(q,shape(w))); s=AV(y); + b=0; DO(r-m, if(b=u[i+m]!=s[i+m])break;); + c=0; DO(m, if(c=u[i ]!=s[i ])break;); + if(b){jt->fill=SPA(wp,e); x=irs2(vec(INT,r-m,m+u),SPA(wp,x),0L,1L,-1L,jttake); jt->fill=0; RZ(x);} + else x=SPA(wp,x); + if(c){A j;C*xv,*yv;I d,i,*iv,*jv,k,n,t; + d=0; t=AT(x); k=bp(t)*aii(x); + q=SPA(wp,i); n=IC(q); + GA(j,INT,AN(q),AR(q),AS(q)); jv= AV(j); iv= AV(q); + GA(y,t, AN(x),AR(x),AS(x)); yv=CAV(y); xv=CAV(x); + for(i=0;i<n;++i){ + c=0; DO(m, t=u[i]; if(c=0>t?iv[i]<t+s[i]:iv[i]>=t)break;); + if(!c){++d; MC(yv,xv,k); yv+=k; DO(m, t=u[i]; *jv++=0>t?iv[i]-(t+s[i]):iv[i];);} + iv+=m; xv+=k; + } + SPB(zp,i,d<n?take(sc(d),j):j); SPB(zp,x,d<n?take(sc(d),y):y); + }else{SPB(zp,i,ca(SPA(wp,i))); SPB(zp,x,b?x:ca(x));} + SPB(zp,a,ca(SPA(wp,a))); + SPB(zp,e,ca(SPA(wp,e))); + EPILOG(z); +} /* take on sparse array w */ + +static F2(jttk){PROLOG;A y,z;B b=0;C*yv,*zv;I c,d,dy,dz,e,i,k,m,n,p,q,r,*s,t,*u; + n=AN(a); u=AV(a); r=AR(w); s=AS(w); t=AT(w); + if(t&SPARSE)R tks(a,w); + DO(n, if(!u[i]){b=1; break;}); if(!b)DO(r-n, if(!s[n+i]){b=1; break;}); + if(b||!AN(w))R tk0(b,a,w); + k=bp(t); z=w; c=q=1; + for(i=0;i<n;++i){ + c*=q; p=u[i]; q=ABS(p); m=s[i]; + if(q!=m){ + RE(d=mult(AN(z)/m,q)); GA(y,t,d,r,AS(z)); *(i+AS(y))=q; + if(q>m)mvc(k*AN(y),CAV(y),k,jt->fillv); + d=AN(z)/(m*c)*k; e=d*MIN(m,q); + dy=d*q; yv=CAV(y); if(0>p&&q>m)yv+=d*(q-m); + dz=d*m; zv=CAV(z); if(0>p&&m>q)zv+=d*(m-q); + DO(c, MC(yv,zv,e); yv+=dy; zv+=dz;); + b=1; z=y; + }} + if(!b)z=ca(w); + EPILOG(RELOCATE(w,z)); +} + +F2(jttake){A s,t;D*av,d;I acr,af,ar,n,*tv,*v,wcr,wf,wr; + RZ(a&&w); + if(SPARSE&AT(a))RZ(a=denseit(a)); + if(!(SPARSE&AT(w)))RZ(w=setfv(w,w)); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(af||1<acr)R rank2ex(a,w,0L,af?acr:1L,wcr,jttake); + n=AN(a); + ASSERT(!wcr||n<=wcr,EVLENGTH); + if(AT(a)&B01+INT)RZ(s=a=vi(a)) + else{ + RZ(t=vib(a)); + if(!(AT(a)&FL))RZ(a=cvt(FL,a)); + av=DAV(a); tv=AV(t); v=wf+AS(w); + DO(n, d=av[i]; if(d==IMIN)tv[i]=(I)d; else if(INF(d))tv[i]=wcr?v[i]:1;) + s=a=t; + } + if(!wcr||wf){ + RZ(s=vec(INT,wf+n,AS(w))); v=wf+AV(s); + if(!wcr){DO(n,v[i]=1;); RZ(w=reshape(s,w));} + ICPY(v,AV(a),n); + } + R tk(s,w); +} + +F2(jtdrop){A s;I acr,af,ar,d,m,n,*u,*v,wcr,wf,wr; + RZ((a=vib(a))&&w); + ar=AR(a); acr=jt->rank?jt->rank[0]:ar; af=ar-acr; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + if(af||1<acr)R rank2ex(a,w,0L,af?acr:1L,wcr,jtdrop); + n=AN(a); u=AV(a); + ASSERT(!wcr||n<=wcr,EVLENGTH); + if(wcr){RZ(s=shape(w)); v=wf+AV(s); DO(n, d=u[i]; m=v[i]; v[i]=d<-m?0:d<0?d+m:d<m?d-m:0;);} + else{GA(s,INT,wr+n,1,0); v=AV(s); ICPY(v,AS(w),wf); v+=wf; DO(n, v[i]=!u[i];); RZ(w=reshape(s,w));} + R tk(s,w); +} + + +static F1(jtrsh0){A x,y;I wcr,wf,wr,*ws; + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; jt->rank=0; + ws=AS(w); + RZ(x=vec(INT,wr-1,ws)); ICPY(wf+AV(x),ws+wf+1,wcr-1); + RZ(w=setfv(w,w)); GA(y,AT(w),1,0,0); MC(AV(y),jt->fillv,bp(AT(w))); + R reshape(x,y); +} + +F1(jthead){I wcr,wf,wr; + RZ(w); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; + R !wcr||*(wf+AS(w))? from(num[ 0],w) : + SPARSE&AT(w)?irs2(num[0],take(num[ 1],w),0L,0L,wcr,jtfrom):rsh0(w); +} + +F1(jttail){I wcr,wf,wr; + RZ(w); + wr=AR(w); wcr=jt->rank?jt->rank[1]:wr; wf=wr-wcr; + R !wcr||*(wf+AS(w))?from(num[-1],w) : + SPARSE&AT(w)?irs2(num[0],take(num[-1],w),0L,0L,wcr,jtfrom):rsh0(w); +}
new file mode 100644 --- /dev/null +++ b/vu.c @@ -0,0 +1,91 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Unicode (2-byte unsigned characters) */ + +#include "j.h" + + +B jtvc1(J jt,I n,US*v){DO(n, RZ(255>=*v++);); R 1;} + /* verify that 2-byte chars have high-order 0 bytes */ + +A jttoc1(J jt,B h,A w){A z;C*wv,*zv;I n; + RZ(w); + if(LIT&AT(w))R ca(w); + n=AN(w); wv=CAV(w); + ASSERT(!n||C2T&AT(w),EVDOMAIN); + GA(z,LIT,n,AR(w),AS(w)); zv=CAV(z); +#if SYS & SYS_LILENDIAN + if(h)DO(n, *zv++=*wv++; wv++;) else DO(n, *zv++=*wv++; ASSERT(!*wv++,EVDOMAIN);) +#else + if(h)DO(n, wv++; *zv++=*wv++;) else DO(n, ASSERT(!*wv++,EVDOMAIN); *zv++=*wv++;) +#endif + R z; +} /* convert 2-byte chars to 1-byte chars; 0==h iff high order byte must be 0 */ + +static F1(jttoc2){A z;C*wv,*zv;I n; + RZ(w); + if(C2T&AT(w))R ca(w); + n=AN(w); wv=CAV(w); + ASSERT(!n||LIT&AT(w),EVDOMAIN); + GA(z,C2T,n,AR(w),AS(w)); zv=CAV(z); +#if SYS & SYS_LILENDIAN + DO(n, *zv++=*wv++; *zv++=0;); +#else + DO(n, *zv++=0; *zv++=*wv++;); +#endif + R z; +} /* convert 1-byte chars to 2-byte chars */ + +static F1(jttoc2e){A z;I m,n,r; + RZ(w); + n=AN(w); r=AR(w); + ASSERT(r,EVRANK); + ASSERT(!n||LIT&AT(w),EVDOMAIN); + m=*(AS(w)+r-1); + ASSERT(0==m%2,EVLENGTH); + GA(z,C2T,n/2,r,AS(w)); *(AS(z)+r-1)=m/2; + memcpy(AV(z),AV(w),n); + R z; +} /* convert pairs of 1-byte chars to 2-byte chars */ + +static F1(jtifc2){A z;I n,t,*zv; + RZ(w); + n=AN(w); t=AT(w); + ASSERT(!n||t&JCHAR,EVDOMAIN); + GA(z,INT,n,AR(w),AS(w)); zv=AV(z); + if(t&LIT){UC*v=(UC*)AV(w); DO(n, *zv++=*v++;);} + else {US*v=(US*)AV(w); DO(n, *zv++=*v++;);} + R z; +} /* integers from 1- or 2-byte chars */ + +static F1(jtc2fi){A z;I j,n,*v;US*zv; + RZ(w=vi(w)); + n=AN(w); v=AV(w); + GA(z,C2T,n,AR(w),AS(w)); zv=(US*)AV(z); + DO(n, j=*v++; ASSERT(SMIN<=j&&j<=SMAX,EVINDEX); *zv++=(US)j;); + R z; +} /* 2-byte chars from integers */ + +F1(jtuco1){I t; + RZ(w); + t=AT(w); + ASSERT(!AN(w)||t&JCHAR+NUMERIC,EVDOMAIN); + R t&NUMERIC?c2fi(w):t&C2T?ca(w):toc2(w); +} /* copy 2-byte chars; convert 1-byte to 2-byte */ + + +F2(jtuco2){I j; + RZ(a&&w); + RE(j=i0(a)); + switch(j){ + case 1: R toc1(1,w); + case 2: R toc2(w); + case 3: R ifc2(w); + case 4: R c2fi(w); + case 5: R toc1(0,w); + case 6: R toc2e(w); + case 7: R toutf16(w); + case 8: R toutf8(w); + default: ASSERT(0,EVDOMAIN); +}}
new file mode 100644 --- /dev/null +++ b/vx.c @@ -0,0 +1,498 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Extended Precision Integers */ + +#include "j.h" +#include "ve.h" + + +X jtxev1(J jt,A w,C*s){A y; + RZ(y=df1(cvt(XNUM,w),eval(s))); + ASSERTSYS(!AR(y),"xev1"); + if(!(XNUM&AT(y)))RZ(y=cvt(XNUM,y)); + R*XAV(y); +} + +X jtxev2(J jt,A a,A w,C*s){A y; + RZ(y=df2(cvt(XNUM,a),cvt(XNUM,w),eval(s))); + ASSERTSYS(!AR(y),"xev2"); + if(!(XNUM&AT(y)))RZ(y=cvt(XNUM,y)); + R*XAV(y); +} + +X jtxc(J jt,I n){I m=1,p,*zv;X z; + p=n; while(p/=XBASE)++m; + GA(z,INT,m,1,0); zv=AV(z); + p=n; DO(m, zv[i]=p%XBASE; p/=XBASE;); + R z; +} /* n is non-negative */ + +D xdouble(X w){D z=0;I c,n,*v; + n=AN(w); v=n+AV(w); c=*--v; + if(c==XPINF)R inf; else if(c==XNINF)R infm; + DO(n, z=*v--+z*XBASE;); + R z; +} + +I jtxint(J jt,X w){I c,n,*v,z; + n=AN(w); v=AV(w); v+=n; c=z=*--v; + ASSERT(n<=XIDIG&&c!=XPINF&&c!=XNINF,EVDOMAIN); + DO(n-1, z=*--v+z*XBASE;); + ASSERT((c<0)==(z<0),EVDOMAIN); + R z; +} + +XF1(jtxstd){A z;B b;I c=0,d,i,j,k,m=XBASE,n,*zv; + RZ(w); + n=AN(w); RZ(z=ca(w)); zv=AV(z); + b=0; j=n; DO(n, --j; if(zv[j]){b=0<zv[j]; break;}); + if(b) for(i=0;i<n;++i){ + k=zv[i]+=c; + if (0> k){c=-1-(-k)/m; zv[i]=d=m-(-k)%m; if(d== m){zv[i]=0; ++c;}} + else if(m<= k){c=k/m; zv[i]=k%m;} + else c=0; + }else for(i=0;i<n;++i){ + k=zv[i]+=c; + if (0< k){c=1+k/m; zv[i]=d=(k%m)-m; if(d==-m){zv[i]=0; --c;}} + else if(m<=-k){c=-(-k)/m; zv[i]=-(-k)%m;} + else c=0; + } + if(c)R over(z,sc(c)); + j=n-1; while(j&&!zv[j])--j; ++j; + R j==n?z:vec(INT,j,zv); +} /* convert to standard form */ + +int jtxcompare(J jt,X a,X w){I*av,j,m,n,x,y,*wv;int s,t; + RE(1); + m=AN(a); av=AV(a); x=av[m-1]; s=SGN(x); + n=AN(w); wv=AV(w); y=wv[n-1]; t=SGN(y); + if(s!=t)R s?s:-t; + if(1==m&&(x==XPINF||x==XNINF))R 0<x? !(1==n&&y==XPINF):-!(1==n&&y==XNINF); + if(1==n&&(y==XPINF||y==XNINF))R 0<y?-!(1==m&&x==XPINF): !(1==m&&x==XNINF); + if(m!=n)R m>n?s:-s; + j=m; DO(m, --j; if(av[j]!=wv[j])R av[j]>wv[j]?1:-1;); + R 0; +} /* _1 0 1 depending on whether a<w, a=w, a>w */ + + +XF1(jtxsgn){I x=XDIG(w); R xc(SGN(x));} + +XF2(jtxplus){PROLOG;A z;I an,*av,c,d,m,n,wn,*wv,*zv; + RZ(a&&w); + an=AN(a); av=AV(a); c=av[an-1]; + wn=AN(w); wv=AV(w); d=wv[wn-1]; + if(c==XPINF||c==XNINF||d==XPINF||d==XNINF){ + ASSERT(!(c==XPINF&&d==XNINF||c==XNINF&&d==XPINF),EVNAN); + R vci(c==XPINF||d==XPINF?XPINF:XNINF); + } + m=MAX(an,wn); n=MIN(an,wn); + GA(z,INT,m,1,0); zv=AV(z); + DO(n, *zv++=*av+++*wv++;); + if(m>n)ICPY(zv,an>wn?av:wv,m-n); + EPILOG(xstd(z)); +} + +XF2(jtxminus){PROLOG;A z;I an,*av,c,d,m,n,wn,*wv,*zv; + RZ(a&&w); + an=AN(a); av=AV(a); c=av[an-1]; + wn=AN(w); wv=AV(w); d=wv[wn-1]; + if(c==XPINF||c==XNINF||d==XPINF||d==XNINF){ + ASSERT(c!=d,EVNAN); + R vci(c==XPINF||d==XNINF?XPINF:XNINF); + } + m=MAX(an,wn); n=MIN(an,wn); + GA(z,INT,m,1,0); zv=AV(z); + DO(n, *zv++=*av++-*wv++;); + if(m>n){if(an>wn)ICPY(zv,av,m-n); else DO(m-n, *zv++=-*wv++;);} + EPILOG(xstd(z)); +} + +XF2(jtxtymes){A z;I an,*av,c,d,e,i,j,m=XBASE,n,*v,wn,*wv,*zv; + RZ(a&&w); + an=AN(a); av=AV(a); c=av[an-1]; + wn=AN(w); wv=AV(w); d=wv[wn-1]; + if(!c||!d)R xzero; + if(c==XPINF||c==XNINF||d==XPINF||d==XNINF)R vci(0<c*d?XPINF:XNINF); + n=an+wn; GA(z,INT,n,1,0); zv=v=AV(z); memset(zv,C0,n*SZI); + for(i=0;i<an;++i,++zv){ + if(c=av[i])for(j=0;j<wn;++j){ + d=zv[j]+=c*wv[j]; + if (m<= d){e= d /m; zv[j]-=e*m; zv[1+j]+=e;} + else if(m<=-d){e=(-d)/m; zv[j]+=e*m; zv[1+j]-=e;} + }} + R v[n-1]?z:vec(INT,v[n-2]?n-1:1,v); +} + +static X jtshift10(J jt,I e,X w){A z;I c,d,k,m,n,q,r,*wv,*zv; + n=AN(w); wv=AV(w); c=wv[n-1]; + q=e/XBASEN; r=e%XBASEN; d=0==r?1:1==r?10:2==r?100:1000; + m=n+q+(XBASE<=c*d); + GA(z,INT,m,1,0); zv=AV(z); + DO(q, *zv++=0;); + if(r){c=0; DO(n, k=c+d**wv++; *zv++=k%XBASE; c=k/XBASE;); if(c)*zv=c;} + else DO(n, *zv++=*wv++;); + R z; +} /* w*10^e, positive w */ + +B jtxdivrem(J jt,X a,X w,X*qz,X*rz){B b,c;I*av,d,j,n,*qv,r,y;X q; + j=n=AN(a); av=AV(a); b=0<=av[n-1]; + y=*AV(w); c=0<=y; if(!c)y=-y; r=0; + GA(q,INT,n,1,0); qv=AV(q); + switch(2*b+c){ + case 0: DO(n, --j; d=r*XBASE-av[j]; r=d%y; qv[j]= d/y ;); r=-r; break; + case 1: DO(n, --j; d=r*XBASE-av[j]; r=d%y; qv[j]=-(d/y);); r=r?y-r:0; break; + case 2: DO(n, --j; d=r*XBASE+av[j]; r=d%y; qv[j]=-(d/y);); r=r?r-y:0; break; + case 3: DO(n, --j; d=r*XBASE+av[j]; r=d%y; qv[j]= d/y ;); break; + } + if(r&&b!=c){--qv[0]; DO(n-1, if(qv[i]>-XBASE)break; qv[i]=0; --qv[1+i];);} + if(1<n&&!qv[n-1])AN(q)=*AS(q)=n-1; + *qz=q; *rz=vec(INT,1L,&r); R 1; +} /* (<.a%w),(w|a) where w has a single "digit" and is nonzero */ + +X jtxdiv(J jt,X a,X w,I mode){PROLOG;B di;I an,*av,c,c0,d,e,k,s,u[2],u1,wn,*wv,yn;X q,r,y; + RZ(a&&w&&!jt->jerr); + an=AN(a); av=AV(a); c=c0=av[an-1]; + wn=AN(w); wv=AV(w); d= wv[wn-1]; di=d==XPINF||d==XNINF; + if(c&&!d)R vci(0<c?XPINF:XNINF); + if(c==XPINF||c==XNINF){ASSERT(!di,EVNAN); R vci(0<c*d?XPINF:XNINF);} + if(di)R xzero; + if(1==wn&&d){I*v; + RZ(xdivrem(a,w,&q,&r)); + if(!*AV(r)||mode==XMFLR)R q; + ASSERT(mode==XMCEIL,EWRAT); + v=AV(q); ++*v; + R XBASE>*v?q:xstd(q); + } + switch((0<=c?2:0)+(0<=d)){ + case 0: R xdiv(negate(a),negate(w),mode); + case 1: R negate(xdiv(negate(a),w,mode==XMFLR?XMCEIL:mode==XMCEIL?XMFLR:mode)); + case 2: R negate(xdiv(a,negate(w),mode==XMFLR?XMCEIL:mode==XMCEIL?XMFLR:mode)); + default: + if(1!=(e=xcompare(a,w))){ + ASSERT(!(c&&e&&mode==XMEXACT),EWRAT); + d=c&&(mode||!e); + R vec(INT,1L,&d); + } + if(1<an)c=av[an-2]+c*XBASE; + if(1<wn)d=wv[wn-2]+d*XBASE; + e=c>=d?c/d:(I)((XBASE*(D)c)/d); u[0]=e%XBASE; u[1]=u1=e/XBASE; + RZ(q=vec(INT,u1?2L:1L,u)); + RZ(y=xtymes(w,q)); yn=AN(y); e=*(AV(y)+yn-1); + k=c0>=e?c0/e:e/c0; + k=k<=3?0:k>3162?4:3<k&&k<=32?1:32<k&&k<=316?2:3; + s=XBASEN*(an-yn)+(c0>=e?k:-k); + if(s){q=shift10(s,q); y=shift10(s,y);} + EPILOG(xplus(q,xdiv(xminus(a,y),w,mode))); +}} /* <.a%w (mode=XMFLR) or >.a%w (mode=XMCEIL) or a%w (mode=XMEXACT) */ + +XF2(jtxrem){I c,d,e;X q,r,y; + RZ(a&&w); + c=XDIG(a); d=XDIG(w); + if(!c)R w; + ASSERT(!(d==XPINF||d==XNINF),EVNAN); + if(c==XPINF)R 0<=d?w:a; + if(c==XNINF)R 0>=d?w:a; + if(1==AN(a)&&c){RZ(xdivrem(w,a,&q,&r)); R r;} + switch((0<=c?2:0)+(0<=d)){ + case 0: R negate(xrem(negate(a),negate(w))); + case 1: y=xrem(negate(a),w); R xcompare(y,xzero)? xplus(a,y):y; + case 2: y=xrem(a,negate(w)); R xcompare(y,xzero)?xminus(a,y):y; + default: R 0<=(e=xcompare(a,w)) ? (e?w:xzero) : xminus(w,xtymes(a,xdiv(w,a,XMFLR))); +}} + +XF2(jtxgcd){I c,d,old;X p,q,t; + RZ(a&&w); + c=XDIG(a); if(0>c)RZ(a=negate(a)); + d=XDIG(w); if(0>d)RZ(w=negate(w)); + ASSERT(!(c==XPINF||c==XNINF||d==XPINF||d==XNINF),EVNAN); + if(!c)R w; + if(!d)R a; + p=a; q=w; old=jt->tbase+jt->ttop; + while(XDIG(p)){ + t=p; + RZ(p=xrem(p,q)); + q=t; + gc3(p,q,0L,old); + } + R q; +} + +XF2(jtxlcm){R xtymes(a,xdiv(w,xgcd(a,w),XMEXACT));} + +static X jtxexp(J jt,X w,I mode){I k,m;X s,y; + RZ(w); + k=XDIG(w); + ASSERT(!k||mode!=XMEXACT,EWIRR); + if(0>k)R xc(mode); + m=(I)(2.71828*xint(w)); k=2; s=xplus(xone,w); y=w; + DO(m, y=xtymes(y,w); s=xplus(xtymes(s,xc(k)),y); ++k;); + R xdiv(s,xev1(apv(1+m,1L,1L),"*/"),mode); +} + +XF2(jtxpow){PROLOG;I c,d,e,r;X m,t,z; + RZ(a&&w); + c=XDIG(a); d=XDIG(w); e=*AV(w); + if(c==XPINF||c==XNINF){ + ASSERT(0<c||d!=XPINF,EVDOMAIN); + R vci(!d?1L:0>d?0L:0<c?c:1&e?XNINF:XPINF); + } + if(d==XPINF||d==XNINF){ + ASSERT(0<=c||d==XNINF,EVDOMAIN); + R vci(1==c&&1==AN(a)?1L:!c&&0>d||c&&0<d?XPINF:0L); + } + if(1==AN(a)&&(1==c||-1==c))R 1==c||0==e%2?xone:xc(-1L); + if(!c){ASSERT(0<=d,EWRAT); R d?xzero:xone;} + if(0>d){ + ASSERT(!jt->xmod,EVDOMAIN); + ASSERT(jt->xmode!=XMEXACT,EWRAT); + r=jt->xmode==XMCEIL; R xc(0<c?r:1&e?r-1:r); + } + t=a; z=xone; m=jt->xmod?*XAV(jt->xmod):0; + if(!m||1>xcompare(w,xc(IMAX))){ + ASSERT(m||2>=AN(w),EVLIMIT); + RE(e=xint(w)); + if(m)while(e){if(1&e)RZ(z=xrem(m,xtymes(z,t))); RZ(t=xrem(m,xsq(t))); e>>=1;} + else while(e){if(1&e)RZ(z= xtymes(z,t) ); RZ(t= xsq(t) ); e>>=1;} + }else{B b;I n,*u,*v;X e; + RZ(e=ca(w)); n=AN(e); v=AV(e); + while(n){ + if(1&*v)RZ(z=xrem(m,xtymes(z,t))); + RZ(t=xrem(m,xtymes(t,t))); + b=1; c=0; u=v+n; + DO(n, d=c+*--u; c=1&d?XBASE:0; *u=d>>1; if(b&=!*u)--n;); /* e=.<.e%2 */ + }} + EPILOG(z); +} + +XF1(jtxsq){R xtymes(w,w);} + +XF1(jtxsqrt){I c,m,n,p,q,*wv;X e,x; + RZ(w); + n=AN(w); wv=AV(w); c=wv[n-1]; + ASSERT(0<=c,EWIMAG); + if(!(1&n))c=wv[n-2]+c*XBASE; + m=(1+n)/2; RZ(x=apv(m,0L,0L)); *(AV(x)+m-1)=(I)sqrt((D)c); + RZ(e=xc(2L)); + p=m*XBASEN; q=0; while(p){++q; p>>=1;} + DO(1+q, RZ(x=xdiv(xplus(x,xdiv(w,x,XMFLR)),e,XMFLR));); + p=xcompare(w,xsq(x)); + switch(jt->xmode){ + default: ASSERTSYS(0,"xsqrt"); + case XMFLR: if(-1==p){--*AV(x); R xstd(x);}else R x; + case XMCEIL: if( 1==p){++*AV(x); R xstd(x);}else R x; + case XMEXACT: + if(!p)R x; + *AV(x)+=p; RZ(x=xstd(x)); + ASSERT(!xcompare(w,xsq(x)),EWIRR); + R x; +}} + +static XF2(jtxroot){A q;D x;I an,*av,c,d,r,wn,*wv;X n,n1,p,t,z; + an=AN(a); av=AV(a); c=av[an-1]; + wn=AN(w); wv=AV(w); d=wv[wn-1]; + ASSERT(0<=d,EWIMAG); + if(1==wn&&(0==d||1==d))R 1==d?xone:0<=c?xzero:vci(XPINF); + if(!c&&0<d)R vci(XPINF); + r=xint(a); if(jt->jerr){RESETERR; R xone;} + if(2==r)R xsqrt(w); + x=xlogabs(w)/r; + if(x<709.78){RZ(q=ceil1(cvt(RAT,scf(exp(x))))); z=*XAV(q);} + else {RZ(q=cvt(XNUM,scf(ceil(x)))); z=xexp(*XAV(q),XMCEIL);} + RZ(n=xc(r)); RZ(n1=xc(r-1)); + RZ(t=xdiv(w,p=xpow(z,n1),XMFLR)); + RZ(z=xdiv(xplus(t,xtymes(z,n1)),n,XMFLR)) + while(1){ + RZ(t=xdiv(w,p=xpow(z,n1),XMFLR)); + if(1>xcompare(z,t))break; + RZ(z=xdiv(xplus(t,xtymes(z,n1)),n,XMFLR)) + } + if(XMFLR==jt->xmode||!xcompare(w,xtymes(z,p)))R z; + if(XMCEIL==jt->xmode)R xplus(z,xone); + ASSERT(0,EWIRR); +} + +D jtxlogabs(J jt,X w){D c;I m,n,*v; + n=AN(w); m=MIN(n,20/XBASEN); v=n+AV(w); + c=0.0; DO(m, c=c*XBASE+(D)*--v;); + R log(ABS(c))+XBASEN*(n-m)*2.3025850929940457; +} + +static XF1(jtxlog1){B b;I c; + c=XDIG(w); b=1==c&&1==AN(w); + ASSERT(0<=c,EWIMAG); + ASSERT(b||jt->xmode!=XMEXACT,EWIRR); + R xc((I)xlogabs(w)+(!b&&jt->xmode==XMCEIL)); +} + +static D jtxlogd1(J jt,X w){ASSERT(0<=XDIG(w),EWIMAG); R xlogabs(w);} + +static Z jtxlogz1(J jt,X w){Z z; z.re=xlogabs(w); z.im=0>XDIG(w)?PI:0.0; R z;} + + +static XF2(jtxlog2sub){ASSERT(0,EVNONCE);} + +static XF2(jtxlog2){D c,d,x,y;I an,*av,j,k,m,n,wn,*wv;X p,q; + RZ(a&&w); + an=AN(a); av=AV(a); c=(D)av[an-1]; if(1<an)c=av[an-2]+c*XBASE; + wn=AN(w); wv=AV(w); d=(D)wv[wn-1]; if(1<wn)d=wv[wn-2]+d*XBASE; + if(2<an)R xlog2sub(a,w); + ASSERT(0<=c,EWIMAG); + if(!c){ASSERT(d,EVDOMAIN); R xzero;} + if(!d){ASSERT(0<c,EVDOMAIN); R vci(XNINF);} + ASSERT(0<d,EVDOMAIN); + if(1==c)R 1==d?xzero:vci(XPINF); + x=log(c)+XBASEN*(2<an?an-2:0)*2.3025850929940457; + y=log(d)+XBASEN*(2<wn?wn-2:0)*2.3025850929940457; + m=n=(I)(y/x+(an<wn)); + RZ(p=q=xpow(a,xc(m))); j=k=xcompare(p,w); + if (0<j){--m; RZ(p=xdiv(p,a,XMEXACT)); j=xcompare(p,w); if(0<j)R xlog2sub(a,w);} + else if(0>j){++n; RZ(q=xtymes(p,a)); k=xcompare(q,w); if(0>k)R xlog2sub(a,w);} + ASSERT(jt->xmode!=XMEXACT||!j||!k,EWIRR); + R xc(!j?m:!k?n:jt->xmode==XMCEIL?n:m); +} + +F2(jtxlog2a){A z; GA(z,XNUM,1L,0L,0L); *XAV(z)=xlog2(*XAV(a),*XAV(w)); RNE(z);} +F2(jtxroota){A z; GA(z,XNUM,1L,0L,0L); *XAV(z)=xroot(*XAV(a),*XAV(w)); RNE(z);} + +XF1(jtxfact){I n; + n=*AV(w); + if(n==XPINF||n==XNINF)R vci(XPINF); + RE(n=xint(w)); + if(0>n)R vci(n%2?XPINF:XNINF); + R xev1(apv(n,1L,1L),"*/"); +} + +static XF2(jtxbinp){PROLOG;D m;I i,n;X c,d,p,q,r,s; + RZ(d=xminus(w,a)); s=1==xcompare(a,d)?d:a; RE(n=xint(s)); + m=xdouble(w); + if(m<=IMAX){ + RZ(p=less(ravel(factor(apv(n,(I)m,-1L))),zero)); + RZ(q=less(ravel(factor(apv(n,1L, 1L))),zero)); + c=over(p,q); + d=repeat(v2(AN(p),AN(q)),v2(1L,-1L)); + EPILOG(xev1(repeat(ev2(c,d,"+//."),nub(c)),"*/")); + }else{ + p=q=xone; r=w; + for(i=0;i<n;++i){ + p=xtymes(p,r); r=xminus(r,xone); + q=xtymes(q,s); s=xminus(s,xone); + d=xgcd(p,q); p=xdiv(p,d,XMEXACT); q=xdiv(q,d,XMEXACT); + if(jt->jerr)R 0; + } + EPILOG(p); +}} /* non-negative x,y; x<=y */ + +XF2(jtxbin){X d,z; + RZ(d=xminus(w,a)); + switch(4*(0>XDIG(a))+2*(0>XDIG(w))+(0>XDIG(d))){ + default: ASSERTSYS(0,"xbin"); + case 2: /* 0 1 0 */ /* Impossible */ + case 5: /* 1 0 1 */ /* Impossible */ + case 1: /* 0 0 1 */ + case 4: /* 1 0 0 */ + case 7: /* 1 1 1 */ R xzero; + case 0: /* 0 0 0 */ R xbinp(a,w); + case 3: /* 0 1 1 */ + z=xbinp(a,xminus(a,xplus(w,xone))); R*AV(a)%2?negate(z):z; + case 6: /* 1 1 0 */ + z=xbinp(xminus(xc(-1L),w),xminus(xc(-1L),a)); R*AV(d)%2?negate(z):z; +}} + +static A jtpiev(J jt,I n,X b){A e;I ek,i,n1=n-1;X bi,e0,e1,*ev,t; + GA(e,XNUM,n,1,0); ev=XAV(e); + bi=e0=e1=xone; + for(i=0,ek=1;i<n1;++i,ek+=3){ + ev[i]=xtymes(e0,xtymes(XCUBE(e1),bi)); + t=xtymes(xc(ek),xtymes(xc(1+ek),xc(2+ek))); + e0=xtymes(e0,t); /* e0 = ! 3*i */ + e1=xtymes(e1,xc(1+i)); /* e1 = ! i */ + bi=xtymes(bi,b); /* bi = b^i */ + } + ev[i]=xtymes(e0,xtymes(XCUBE(e1),bi)); + RE(e); R e; +} + +static XF1(jtxpi){A e;B p;I i,n,n1,sk;X a,b,c,d,*ev,k,f,m,q,s,s0,t; + RZ(w); + if(!XDIG(w))R xzero; + ASSERT(jt->xmode!=XMEXACT,EVDOMAIN); + RZ(a=xc(545140134L)); + RZ(b=XCUBE(xc(640320L))); + RZ(c=xc(13591409L)); + RZ(d=xplus(xc(541681608L),xtymes(xc(10L),xc(600000000L)))); + n1=(13+AN(w)*XBASEN)/14; n=1+n1; + RZ(e=piev(n,b)); ev=XAV(e); m=ev[n1]; + f=xzero; s0=xone; sk=1; + for(i=p=0;;++i,p=!p){ + s=xtymes(s0,xplus(c,xtymes(a,xc(i)))); + t=xdiv(xtymes(s,m),ev[i],XMEXACT); + f=p?xminus(f,t):xplus(f,t); + if(i==n1)break; + DO(6, s0=xtymes(s0,xc(sk++));); RE(s0); /* s0 = ! 6*i */ + } + f=xtymes(d,f); + q=xpow(xc(10L),xc(14*n1)); + k=xtymes(xtymes(a,m),xsqrt(xtymes(b,xsq(q)))); + R xdiv(xtymes(k,w),xtymes(f,q),jt->xmode); +} /* Chudnovsky Bros. */ + +APFX( plusXX, X,X,X, xplus ) +APFX(minusXX, X,X,X, xminus) +APFX(tymesXX, X,X,X, xtymes) +APFX( divXX, X,X,X, XDIV ) +APFX( remXX, X,X,X, xrem ) +APFX( gcdXX, X,X,X, xgcd ) +APFX( lcmXX, X,X,X, xlcm ) +APFX( minXX, X,X,X, XMIN ) +APFX( maxXX, X,X,X, XMAX ) +APFX( powXX, X,X,X, xpow ) +APFX( binXX, X,X,X, xbin ) + +AMON( sgnX, X,X, *z= xsgn(*x);) +AMON(sqrtX, X,X, *z= xsqrt(*x);) +AMON( expX, X,X, *z= xexp(*x,jt->xmode);) +AMON( logX, X,X, *z= xlog1(*x);) +AMON(logXD, D,X, *z=xlogd1(*x);) +AMON(logXZ, Z,X, *z=xlogz1(*x);) +AMON( absX, X,X, *z= mag(*x);) +AMON(factX, X,X, *z= xfact(*x);) +AMON( pixX, X,X, *z= xpi(*x);) + + +F1(jtdigits10){A z;B b=0;I c,m,n,*v,*zv,*zv0;X x; + RZ(w); + if(!AR(w))switch(AT(w)){ + case INT: b=0<=*AV(w); break; + case XNUM: x=*XAV(w); n=AN(x); v=AV(x); b=0<=v[n-1]; break; + case RAT: x=*XAV(w); n=AN(x); v=AV(x); b=0<=v[n-1]&&equ(iv1,QAV(w)->d); + } + if(!b)R rank1ex(thorn1(w),0L,0L,jtexec1); + m=INT&AT(w)?(SY_64?19:10):XBASEN*AN(x); + GA(z,INT,m,1,0); zv=zv0=AV(z); + if(INT&AT(w)){c=*AV(w); *zv++=c%10; while(c/=10)*zv++=c%10;} + else{ + DO(n-1, c=*v++; DO(XBASEN, *zv++=c%10; c/=10;);); + c=*v++; if(c||1==n)*zv++=c%10; while(c/=10)*zv++=c%10; + } + AN(z)=*AS(z)=n=zv-zv0; + zv=zv0; v=zv0+n-1; DO(n/2, c=*zv; *zv++=*v; *v--=c;); /* reverse in place */ + R z; +} /* "."0@": w */ + + +#define DXBODY(exp) DECLG;A y=sv->h,z;I m=jt->xmode; jt->xmode=XMFLR; z=exp; jt->xmode=m; R z +#define DX1(f,exp) DF1(f){DXBODY(exp);} +#define DX2(f,exp) DF2(f){DXBODY(exp);} +#define XT(w) tymes(y,w) + +static DX1(postmult1, XT(CALL1(g1, w,gs))) +static DX2(postmult2, XT(CALL2(g2,a,w,gs))) + +static DX1(premult1, CALL1(g1, XT(w),gs)) +static DX2(premult2, CALL2(g2,XT(a),XT(w),gs)) + +static DX1(ydiv1, CALL2(g2,y, w,gs)) +static DX2(ydiv2, CALL2(g2,XT(a),w,gs)) + +static DX1(ysqrt, CALL1(g1,tymes(w,XT(y)),gs))
new file mode 100644 --- /dev/null +++ b/vx.h @@ -0,0 +1,57 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Extended Precision */ + +#if SY_64 +#define XIDIG 5 /* max # x digits in an integer */ +#else +#define XIDIG 3 +#endif + +#define XBASE (I)10000 +#define XBASEN (I)4 +#define XPINF (I)99999 +#define XNINF (I)-99999 +#define XF1(f) X f(J jt, X w) +#define XF2(f) X f(J jt,X a,X w) +#define XDIG(a) (*(AV(a)+AN(a)-1)) /* leading digit */ +#define XMAX(x,y) (1==xcompare(x,y)?x:y) +#define XMIN(x,y) (1==xcompare(x,y)?y:x) +#define XDIV(x,y) xdiv(x,y,jt->xmode) +#define XCUBE(x) xtymes(x,xtymes(x,x)) + + + +/* values for jt->xmode */ + +#define XMFLR 0 /* floor, round down */ +#define XMCEIL 1 /* ceiling, round up */ +#define XMEXACT 2 /* exact, error if impossible */ +#define XMEXMT 3 /* exact, empty if impossible */ +#define XMRND 4 /* round, round to nearest */ + + +extern XF1(jtxfact); +extern XF1(jtxsgn); +extern XF1(jtxsq); +extern XF1(jtxsqrt); +extern XF1(jtxstd); + +extern XF2(jtxbin); +extern XF2(jtxgcd); +extern XF2(jtxlcm); +extern XF2(jtxminus); +extern XF2(jtxplus); +extern XF2(jtxpow); +extern XF2(jtxtymes); + +extern X jtxc(J,I); +extern int jtxcompare(J,X,X); +extern X jtxdiv(J,X,X,I); +extern B jtxdivrem(J,X,X,X*,X*); +extern X jtxev1(J,A,C*); +extern X jtxev2(J,A,A,C*); +extern I jtxint(J,X); +extern D jtxlogabs(J,X); +extern X jtxrem(J,X,X);
new file mode 100644 --- /dev/null +++ b/vz.c @@ -0,0 +1,282 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Verbs: Complex-Valued Scalar Functions */ + +#include "j.h" + + +static Z zj={0,1}; +static Z z1={1,0}; + +static D hypoth(D u,D v){D p,q,t; MMM(u,v); R INF(p)?inf:p?(t=q/p,p*sqrt(1+t*t)):0;} + +static ZF1(jtzjx){Z z; z.re=-v.im; z.im= v.re; R z;} +static ZF1(jtzmj){Z z; z.re= v.im; z.im=-v.re; R z;} + +Z zrj0(D a){Z z; z.re=a; z.im=0.0; R z;} + +ZS1(jtzconjug, zr=a; zi=-b;) + +ZS2(jtzplus, zr=a+c; zi=b+d;) + +ZS2(jtzminus, zr=a-c; zi=b-d;) + +ZF1(jtztrend){D a,b,t;Z z; + a=v.re; b=v.im; + if(ZOV(v)){a/=2; b/=2;} + t=hypoth(a,b); + if(t<inf){if(!t)++t; z.re=a/t; z.im=b/t;} + else switch((INF(a)?2:0)+INF(b)){ + case 1: z.re=0.0; z.im=SGN(b); break; + case 2: z.re=SGN(a); z.im=0.0; break; + case 3: ZASSERT(0,EVNAN); + } + R z; +} + +ZF2(jtztymes){D a,b,c,d;Z z; + a=u.re; b=u.im; c=v.re; d=v.im; + z.re=TYMES(a,c)-TYMES(b,d); + z.im=TYMES(a,d)+TYMES(b,c); + R z; +} + +ZF2(jtzdiv){ZF2DECL;D t; + if(ZNZ(v)){ + if(ABS(c)<ABS(d)){t=a; a=-b; b=t; t=c; c=-d; d=t;} + a/=c; b/=c; d/=c; t=1+d*d; zr=(a+(b&&d?b*d:0.0))/t; zi=(b-(a&&d?a*d:0))/t; + }else if(ZNZ(u))switch(2*(0>a)+(0>b)){ + case 0: if(a> b)zr= inf; else zi= inf; break; + case 1: if(a>-b)zr= inf; else zi=-inf; break; + case 2: if(a<-b)zr=-inf; else zi= inf; break; + case 3: if(a< b)zr=-inf; else zi=-inf; + } + ZEPILOG; +} + +ZF1(jtznegate){R zminus(zeroZ,v);} + +D zmag(Z v){R hypoth(v.re,v.im);} + +B jtzeq(J jt,Z u,Z v){D a=u.re,b=u.im,c=v.re,d=v.im,p,q; + if(a==c&&b==d)R 1; + if(ZEZ(u)||ZEZ(v)||!jt->ct||(0>a!=0>c&&0>b!=0>d))R 0; + if(ZOV(u)||ZOV(v)){a/=2; b/=2; c/=2; d/=2;} + if(ZUN(u)||ZUN(v)){a*=2; b*=2; c*=2; d*=2;} + p=hypoth(a,b); q=hypoth(c,d); + R p!=inf && q!=inf && hypoth(a-c,b-d)<=jt->ct*MAX(p,q); +} + +ZF1(jtzfloor){D p,q; + ZF1DECL; + zr=jfloor(a); p=a-zr; + zi=jfloor(b); q=b-zi; + if(1<=p+q+jt->ct)if(p>=q)++zr; else ++zi; + ZEPILOG; +} + +ZF1(jtzceil){R znegate(zfloor(znegate(v)));} + +ZF2(jtzrem){D a,b,d;Z q; + if(ZEZ(u))R v; + ZASSERT(!ZINF(v),EVNAN); + if(INF(u.re)&&!u.im&&!v.im){ + if(u.re==inf )R 0<=v.re?v:u; + if(u.re==infm)R 0>=v.re?v:u; + } + ZASSERT(!ZINF(u),EVNONCE); + d=u.re*u.re+u.im*u.im; + a=u.re*v.re+u.im*v.im; q.re=tfloor(0.5+a/d); + b=u.re*v.im-u.im*v.re; q.im=tfloor(0.5+b/d); + R zminus(v,ztymes(u,q)); +} + +ZF2(jtzgcd){D a,b;Z t,z; + ZASSERT(!(ZINF(u)||ZINF(v)),EVNAN); + while(ZNZ(u)){t=zrem(u,v); v.re=u.re; v.im=u.im; u.re=t.re; u.im=t.im;} + z.re=a=v.re; z.im=b=v.im; + switch(2*(0>a)+(0>b)){ + case 0: if(!a){z.re= b; z.im=0;} break; + case 1: z.re=-b; z.im= a; break; + case 2: if(!b){z.re=-a; z.im=0;}else{z.re= b; z.im=-a;} break; + case 3: z.re=-a; z.im=-b; + } + R z; +} + +ZF2(jtzlcm){ZASSERT(!(ZINF(u)||ZINF(v)),EVNAN); R ZEZ(u)||ZEZ(v) ? zeroZ : ztymes(u,zdiv(v,zgcd(u,v)));} + +ZF1(jtzexp){D a,b,c,s,t;Z z; + a=v.re; b=v.im; + if(a<EMIN)z.re=z.im=0.0; + else{ + ZASSERT(-THMAX<b&&b<THMAX,EVLIMIT); + c=cos(b); s=sin(b); + if(a<=EMAX){t=exp(a); z.re=t*c; z.im=t*s;} + else{ + if(!c)z.re=0; else{t=a+log(ABS(c)); t=EMAX<t?inf:exp(t); z.re=0>c?-t:t;} + if(!s)z.im=0; else{t=a+log(ABS(s)); t=EMAX<t?inf:exp(t); z.im=0>s?-t:t;} + }} + R z; +} + +ZF1(jtzlog){ZF1DECL; + zr=b?log(hypoth(a,b)):INF(a)?inf:a?log(hypoth(a,b)):-inf; + zi=a||b?atan2(b,a):0; +#if SY_WINCE_MIPS && !defined(WIN32_PLATFORM_PSPC) + if(!b) zi=a<0?PI : 0; /* atan2(0,v) fails in mips handheld wince - _9^2.5-1.5*/ +#endif + ZEPILOG; +} + +ZF2(jtzpow){ZF2DECL;D m;I n; + if(!a&&!b){z.re=d?0:0>c?inf:!c; z.im=0; R z;} + if(!d&&IMIN<c&&c<=IMAX&&(n=(I)jfloor(c),c==n)){ + if(0>n){u=zdiv(z1,u); n=-n;} + z=z1; + while(n){if(1&n)z=ztymes(z,u); u=ztymes(u,u); n>>=1;} + R z; + } + z=zexp(ztymes(v,zlog(u))); + if(!b&&!d){ + m=jfloor(c); + if(0>a&&c>m&&c==0.5+m)z.re=0; + if(c==m)z.im=0; + } + R z; +} + +ZF1(jtzsqrt){D p,q,t; + ZF1DECL; + MMM(a,b); + if(p){ + t=0.5*q/p; zr=sqrt(ABS(a/2)+p*sqrt(0.25+t*t)); zi=b/(zr+zr); + if(0>a){t=ABS(zi); zi=0>b?-zr:zr; zr=t;} + } + ZEPILOG; +} + + +/* See Abramowitz & Stegun, Handbook of Mathematical Functions, */ +/* National Bureau of Standards, 1964 6. */ + +static ZF1(jtzsin){D a,b,c,s;Z z; + a=v.re; b=v.im; + ZASSERT(-THMAX<a&&a<THMAX,EVLIMIT); + s=sin(a); z.re=s?s*(b<-EMAX2|| EMAX2<b?inf:cosh(b)):0.0; + c=cos(a); z.im=c?c*(b<-EMAX2?infm:EMAX2<b?inf:sinh(b)):0.0; + R z; +} /* 4.3.55 */ + +static ZF1(jtzcos){D a,b,c,s;Z z; + a=v.re; b=v.im; + ZASSERT(-THMAX<a&&a<THMAX,EVLIMIT); + c=cos(a); z.re=c? c*(b<-EMAX2|| EMAX2<b?inf:cosh(b)):0.0; + s=sin(a); z.im=s?-s*(b<-EMAX2?infm:EMAX2<b?inf:sinh(b)):0.0; + R z; +} /* 4.3.56 */ + +static ZF1(jtztan){R zdiv(zsin(v),zcos(v));} + +static ZF1(jtzp4){R zsqrt(zplus(z1,ztymes(v,v)));} + +static ZF1(jtzm4){R 1e16<hypoth(v.re,v.im)?v:ztymes(zplus(v,z1),zsqrt(zdiv(zminus(v,z1),zplus(v,z1))));} + +static ZF1(jtzsinh){R zmj(zsin(zjx(v)));} /* 4.5.7 */ + +static ZF1(jtzcosh){R zcos(zjx(v));} /* 4.5.8 */ + +static ZF1(jtztanh){R v.re<-TMAX?zrj0(-1.0):TMAX<v.re?z1:zdiv(zsinh(v),zcosh(v));} + +static ZF1(jtzp8){R zsqrt(ztymes(zplus(zj,v),zminus(zj,v)));} + +static ZF1(jtzasinh){R 0>v.re ? znegate(zasinh(znegate(v))) : zlog(zplus(v,zp4(v)));} + +static ZF1(jtzacosh){Z z; + z=zlog(zplus(v,zm4(v))); + if(0>=z.re){z.re=0; z.im=ABS(z.im);} + R z; +} + +static ZF1(jtzatanh){R ztymes(zrj0((D)0.5),zlog(zdiv(zplus(z1,v),zminus(z1,v))));} + +static ZF1(jtzatan){ZF1DECL; + if(!b&&(a<-1e13||1e13<a))R zrj0(0<a?PI/2.0:-PI/2.0); + z=zmj(zatanh(zjx(v))); + if(!b)z.im=0; + R z; +} /* 4.4.22 */ + +static ZF1(jtzasin){R !v.im&&-1<=v.re&&v.re<=1?zrj0(asin(v.re)):zmj(zasinh(zjx(v)));} /* 4.4.20 */ + +static ZF1(jtzacos){R zminus(zrj0(PI/2.0),zasin(v));} + +static ZF1(jtzarc){D x,y;Z t,z; + z.re=z.im=0; + t=ztrend(v); x=t.re; y=t.im; + if(0!=x||0!=y)z.re=atan2(y,x); + +#if SY_WINCE_MIPS && !defined(WIN32_PLATFORM_PSPC) + if(!y) z.re=x<0?PI : 0; /* atan2(0,v) fails in mips handheld wince - 12 o. _3 */ +#endif + + R z; +} + +ZF2(jtzcir){D r;I x;Z z; + z=zeroZ; + r=u.re; + x=(I)jfloor(0.5+r); + ZASSERT(-12<=r&&r<=12&&FEQ(x,r)&&!u.im,EVDOMAIN); + switch(x){ + default: ZASSERT(0,EVDOMAIN); + case 0: R zsqrt(ztymes(zplus(z1,v),zminus(z1,v))); + case 1: R zsin(v); case -1: R zasin(v); + case 2: R zcos(v); case -2: R zacos(v); + case 3: R ztan(v); case -3: R zatan(v); + case 4: R zp4(v); case -4: R zm4(v); + case 5: R zsinh(v); case -5: R zasinh(v); + case 6: R zcosh(v); case -6: R zacosh(v); + case 7: R ztanh(v); case -7: R zatanh(v); + case 8: R zp8(v); case -8: R znegate(zp8(v)); + case 9: z.re=v.re; R z; case -9: R v; + case 10: z.re=zmag(v); R z; case -10: R zconjug(v); + case 11: z.re=v.im; R z; case -11: R zjx(v); + case 12: R zarc(v); case -12: R zexp(zjx(v)); +}} + +B jtztridiag(J jt,I n,A a,A x){I i,j,n1=n-1;Z*av,d,p,*xv; + av=ZAV(a); xv=ZAV(x); d=xv[0]; + for(i=j=0;i<n1;++i){ + ASSERT(ZNZ(d),EVDOMAIN); + p=zdiv(xv[j+2],d); + xv[j+3]=d=zminus(xv[j+3],ztymes(p,xv[j+1])); + av[i+1]= zminus(av[i+1],ztymes(p,av[i] )); + j+=3; + } + ASSERT(ZNZ(d),EVDOMAIN); + i=n-1; j=AN(x)-1; av[i]=zdiv(av[i],d); + for(i=n-2;i>=0;--i){j-=3; av[i]=zdiv(zminus(av[i],ztymes(xv[j+1],av[i+1])),xv[j]);} + R 1; +} + +DF1(jtexppi){A z;B b;D r,th,y;I k;Z*v,t; + F1RANK(0,jtexppi,0); + if(!(CMPX&AT(w)))R expn1(pix(w)); + v=ZAV(w); r=exp(PI*v->re); y=v->im; if(b=0>y)y=-y; + th=y-2*(I)(y/2); k=(I)(2*th); if(k!=2*th)k=-1; else if(b&&k)k=4-k; + if(!(0<=k&&k<=3))R expn1(pix(w)); + switch(k){ + case 0: t.re= r; t.im= 0; break; + case 1: t.re= 0; t.im= r; break; + case 2: t.re=-r; t.im= 0; break; + case 3: t.re= 0; t.im=-r; break; + } + GA(z,CMPX,1,0,0); *ZAV(z)=t; R z; +} /* special code for ^@o. */ + + +ZF1(jtznonce1){ZASSERT(0,EVNONCE);} + +ZF2(jtznonce2){ZASSERT(0,EVNONCE);}
new file mode 100644 --- /dev/null +++ b/vz.h @@ -0,0 +1,63 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Complex Numbers */ + + +#define THMAX 5.9631365372958016e8 +#define EMAX 709.78271289338409 +#define EMIN -744.44007192138126 +#define EMAX2 710.47586007394398 +#define TMAX 19.066172834610153 + +/* THMAX: 2p1*2^b%2 where b is # bits in significand */ +/* EMAX: largest number where _>^EMAX; 1024*^.2 */ +/* EMIN: smallest number where 0<^EMIN; _1074*^.2 */ +/* EMAX2: largest number where _>cosh EMAX2; EMAX+^.2 */ +/* TMAX: smallest number where 1=tanh TMAX */ + +#define ZF1DECL Z z;D zr=0.0,zi=0.0,a=v.re,b=v.im +#define ZF2DECL Z z;D zr=0.0,zi=0.0,a=u.re,b=u.im,c=v.re,d=v.im +#define ZEPILOG z.re=zr; z.im=zi; R z +#define ZF1(f) Z f(J jt,Z v) +#define ZF2(f) Z f(J jt,Z u,Z v) +#define ZS1(f,stmts) ZF1(f){ZF1DECL; stmts; ZEPILOG;} +#define ZS2(f,stmts) ZF2(f){ZF2DECL; stmts; ZEPILOG;} +#define MMM(a,b) {p=ABS(a); q=ABS(b); if(p<q){D t=p; p=q; q=t;}} + +#define ZASSERT(b,e) {if(!(b)){jsignal(e); R zeroZ;}} +#define ZNZ(v) ( (v).re||(v).im ) +#define ZEZ(v) (!((v).re||(v).im)) +#define ZINF(v) (inf==(v).re||inf==(v).im||infm==(v).re||infm==(v).im) +#define ZCJ(u,v) ((u).re==(v).re && (u).im==-(v).im) +#define ZOV(v) (ABS((v).re)> OVERFLOW||ABS((v).im)> OVERFLOW) +#define ZUN(v) (ABS((v).re)<UNDERFLOW||ABS((v).im)<UNDERFLOW) +#define ZRE(x,y) ((x).re*(y).re-(x).im*(y).im) +#define ZIM(x,y) ((x).re*(y).im+(x).im*(y).re) + +extern ZF1(jtzceil); +extern ZF1(jtzconjug); +extern ZF1(jtzexp); +extern ZF1(jtzlog); +extern ZF1(jtznegate); +extern ZF1(jtznonce1); +extern ZF1(jtzsqrt); +extern ZF1(jtztrend); +extern ZF1(jtzfloor); + +extern ZF2(jtzcir); +extern ZF2(jtzdiv); +extern ZF2(jtzgcd); +extern ZF2(jtzlcm); +extern ZF2(jtzminus); +extern ZF2(jtznonce2); +extern ZF2(jtzplus); +extern ZF2(jtzpow); +extern ZF2(jtzrem); +extern ZF2(jtztymes); + +extern B jtzeq(J,Z,Z); +extern B jtztridiag(J,I,A,A); + +extern D zmag(Z); +extern Z zrj0(D);
new file mode 100644 --- /dev/null +++ b/w.c @@ -0,0 +1,308 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Words: Word Formation */ + +#include "j.h" +#include "w.h" + +#define SS 0 /* space */ +#define SX 1 /* other */ +#define SA 2 /* alphanumeric */ +#define SN 3 /* N */ +#define SNB 4 /* NB */ +#define SNZ 5 /* NB. */ +#define S9 6 /* numeric */ +#define SQ 7 /* quote */ +#define SQQ 8 /* even quotes */ +#define SZ 9 /* trailing comment */ + +#define EI 1 /* emit (b,i-1); b=.i */ +#define EN 2 /* b=.i */ + +typedef struct {C new,effect;} ST; + +static ST state[10][9]={ +/*SS */ {{SX,EN},{SS,0 },{SA,EN},{SN,EN},{SA,EN},{S9,EN},{SX,EN},{SX,EN},{SQ,EN}}, +/*SX */ {{SX,EI},{SS,EI},{SA,EI},{SN,EI},{SA,EI},{S9,EI},{SX,0 },{SX,0 },{SQ,EI}}, +/*SA */ {{SX,EI},{SS,EI},{SA,0 },{SA,0 },{SA,0 },{SA,0 },{SX,0 },{SX,0 },{SQ,EI}}, +/*SN */ {{SX,EI},{SS,EI},{SA,0 },{SA,0 },{SNB,0},{SA,0 },{SX,0 },{SX,0 },{SQ,EI}}, +/*SNB*/ {{SX,EI},{SS,EI},{SA,0 },{SA,0 },{SA,0 },{SA,0 },{SNZ,0},{SX,0 },{SQ,EI}}, +/*SNZ*/ {{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SX,0 },{SX,0 },{SZ,0 }}, +/*S9 */ {{SX,EI},{SS,EI},{S9,0 },{S9,0 },{S9,0 },{S9,0 },{S9,0 },{SX,0 },{SQ,EI}}, +/*SQ */ {{SQ,0 },{SQ,0 },{SQ,0 },{SQ,0 },{SQ,0 },{SQ,0 },{SQ,0 },{SQ,0 },{SQQ,0}}, +/*SQQ*/ {{SX,EI},{SS,EI},{SA,EI},{SN,EI},{SA,EI},{S9,EI},{SX,EI},{SX,EI},{SQ,0 }}, +/*SZ */ {{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 },{SZ,0 }} +}; +/* CX CS CA CN CB C9 CD CC CQ */ + +F1(jtwordil){A z;C e,nv,s,t=0;I b,i,m,n,*x,xb,xe;ST p;UC*v; + RZ(w); + nv=0; s=SS; + n=AN(w); v=UAV(w); GA(z,INT,1+n+n,1,0); x=1+AV(z); + for(i=0;i<n;++i){ + p=state[s][wtype[v[i]]]; e=p.effect; + if(e==EI){ + t&=s==S9; + if(t){if(!nv){nv=1; xb=b;} xe=i;} + else{if(nv){nv=0; *x++=xb; *x++=xe-xb;} *x++=b; *x++=i-b;} + } + s=p.new; + if(e){b=i; t=s==S9;} + } + if(s==SQ){jsignal3(EVOPENQ,w,b); R 0;} + t&=s==S9; + if(t){*x++=xb=nv?xb:b; *x++=n-xb;} + else{if(nv){*x++=xb; *x++=xe-xb;} if(s!=SS){*x++=b; *x++=n-b;}} + m=x-AV(z); *AV(z)=s==SZ||s==SNZ?-m/2:m/2; + R z; +} /* word index & length; z is (# words),(i0,l0),(i1,l1),... */ + +/* locals in wordil: */ +/* b: beginning index of current word */ +/* e: current effect */ +/* i: index of current character being scanned */ +/* m: 2 * actual number of words */ +/* n: length of input string w */ +/* nv: 1 iff numeric constant vector being built */ +/* p: state table entry per current state & character */ +/* s: current state */ +/* t: 1 iff current state is S9 */ +/* v: ptr to input string */ +/* x: ptr to current element of z being computed */ +/* xb: beginning index of current numeric vector */ +/* xe: end index of current numeric vector */ +/* z: result; maximum of n words */ + +F1(jtwords){A t,*x,z;C*s;I k,n,*y; + F1RANK(1,jtwords,0); + RZ(w=vs(w)); + RZ(t=wordil(w)); + s=CAV(w); y=AV(t); n=*y++; n=0>n?-n:n; + GA(z,BOX,n,1,0); x=AAV(z); + DO(n, k=*y++; RZ(*x++=str(*y++,s+k));); + R z; +} + + +static A jtconstr(J jt,I n,C*s){A z;C b,c,p,*t,*x;I m=0; + p=0; t=s; DO(n-2, c=*++t; b=c==CQUOTE; if(!b||p)m++; p=b&&!p;); + if(0==m)R aqq; else if(1==m&&(z=chr[(UC)s[1]]))R z; + GA(z,LIT,m,1!=m,0); x=CAV(z); + p=0; t=s; DO(n-2, c=*++t; b=c==CQUOTE; if(!b||p)*x++=c; p=b&&!p;); + R z; +} + +#define TNAME(i) (NAME&AT(v[i])) +#define TASGN(i) (ASGN&AT(v[i])) +#define TRBRACE(i) (y=v[i], CRBRACE==ID(y)) +#define TVERB(i,c) (y=v[i], c ==ID(y)) +#define TAIA(i,j) (TASGN(1) && TNAME(i) && TNAME(j) && AN(v[i])==AN(v[j]) && \ + !memcmp(NAV(v[i])->s,NAV(v[j])->s,AN(v[i]))) + +F2(jtenqueue){A*v,*x,y,z;B b;C d,e,p,*s,*wi;I i,n,*u,wl;UC c; + RZ(a&&w); + s=CAV(w); u=AV(a); n=*u++; n=0>n?-(1+n):n; + GA(z,BOX,n,1,0); x=v=AAV(z); + for(i=0;i<n;i++){ + wi=s+*u++; wl=*u++; c=e=*wi; p=ctype[c]; b=0; + if(1<wl){d=*(wi+wl-1); if(b=p!=C9&&d==CESC1||d==CESC2)e=spellin(wl,wi);} + if(128>c&&(y=ds(e)))*x++=y; + else if(e==CFCONS)RZ(*x++=FCONS(connum(wl-1,wi))) + else switch(b?0:p){ + default: jsignal3(EVSPELL,w,wi-s); R 0; + case C9: RZ(*x++=connum(wl,wi)); break; + case CQ: RZ(*x++=constr(wl,wi)); break; + case CA: ASSERTN(vnm(wl,wi),EVILNAME,nfs(wl,wi)); RZ(*x++=nfs(wl,wi)); + }} + if(6<=n && TAIA(0,n-1) && ((b=TRBRACE(n-2)) || RPAR&AT(v[n-2])&&TRBRACE(n-3))){I c,j,p,q; + /* abc=:pqr xyz}abc or abc=:pqr (xyz})abc */ + j=2; p=q=0; + DO(n-j, y=v[j++]; c=AT(y); if(c&LPAR)++p; else if(c&RPAR)--p; if(!p)break;); + DO(n-j, y=v[j++]; c=AT(y); if(c&LPAR)++q; else if(c&RPAR)--q; if(!q)break;); + if(!p&&!q&&j>=n-2)v[b+n-3]=ds(CAMIP); + }else if(5<=n && TAIA(0,2)){ + if(TVERB(3,CCOMMA) && !(AT(v[4])&ADV+CONJ) && + !(AT(v[4])&NAME&&(y=symbrd(v[4]),jt->etxn=jt->jerr=0,y)&&AT(y)&ADV+CONJ)) + v[3]=ds(CAPIP); /* abc=: abc,blah */ + else if(7<=n&&!(AT(v[3])&VERB+ADV+CONJ)){I c,j,q; + /* abc=:abc xyz}~ pqr */ + j=3; q=0; + DO(n-j, y=v[j++]; c=AT(y); if(c&LPAR)++q; else if(c&RPAR)--q; if(!q)break;); + if(!q&&j<n-2&&TRBRACE(j)&&v[1+j]==ds(CTILDE))v[j]=ds(CAMIP); + }}else if(7<=n && TNAME(0) && TASGN(1) && TNAME(2) && TRBRACE(3) && TVERB(n-2,CLAMIN)){A p,*yv,z1;I c,j,k,m; + /* abc=: pqr}x,y,:z */ + b=1; m=(n-3)/2; + j=4; DO(m, if(!TNAME(j) ){b=0; break;} j+=2;); + j=5; if(b)DO(m-2, if(!TVERB(j,CCOMMA)){b=0; break;} j+=2;); + if(b){ + GA(z1,BOX,4,1,0); x=AAV(z1); + GA(y,BOX,m+3,1,0); yv=AAV(y); + c=-1; k=AN(v[0]); s=NAV(v[0])->s; + j=4; DO(m, yv[i]=p=v[j]; j+=2; if(AN(p)&&!memcmp(s,NAV(p)->s,k))c=i;); + yv[m]=v[2]; RZ(yv[m+1]=sc(c)); yv[m+2]=z; + x[0]=v[0]; x[1]=v[1]; x[2]=ds(CCASEV); x[3]=y; + R z1; + }} + R z; +} /* produce boxed list of words suitable for parsing */ + +/* locals in enqueue: */ +/* b: 1 iff current word is a primitive spelled with . or : */ +/* c: first character in current word */ +/* d: last character in current word */ +/* e: first character in current word, after spellin */ +/* i: index of current word */ +/* n: number of words */ +/* p: character type of current character */ +/* s: ptr to value part of input string w */ +/* u: ptr to value part of word index & length info a */ +/* v: ptr to value part of z */ +/* wi: index of current word in input string */ +/* wl: length of current word */ +/* x: ptr to result word being built */ +/* y: array temp */ +/* z: result array of boxed list of words */ + + +F1(jttokens){R enqueue(wordil(w),w);} + + +#define CHKJ(j) ASSERT(0<=(j),EVINDEX); +#define EXTZ(T,p) while(uu<p+u){k=u-(T*)AV(z); RZ(z=ext(0,z)); u=k+(T*)AV(z); uu=(T*)AV(z)+AN(z);} + +#define EMIT0c(T,j,i,r,c) {CHKJ(j); p=(i)-(j); EXTZ(T,1); RZ(*u++=str(p,(j)+wv));} +#define EMIT0b(T,j,i,r,c) {CHKJ(j); p=(i)-(j); EXTZ(T,1); RZ(*u++=vec(B01,p,(j)+wv));} +#define EMIT0x(T,j,i,r,c) {CHKJ(j); p=(i)-(j); EXTZ(T,1); GA(x,t0,p*wm,wr,AS(w0)); \ + *AS(x)=p; MC(AV(x),wv0+wk*(j),wk*p); *u++=x;} +#define EMIT1(T,j,i,r,c) {CHKJ(j); p=(i)-(j); cc=(j)+wv; DO(p, *u++=*cc++;);} +#define EMIT1x(T,j,i,r,c) {CHKJ(j); p=wk*((i)-(j)); MC(u,wv0+j*wk,p); u+=p;} +#define EMIT2(T,j,i,r,c) {CHKJ(j); p=(i)-(j); EXTZ(T,2); *u++=(j); *u++=p;} +#define EMIT3(T,j,i,r,c) {CHKJ(j); EXTZ(T,1); *u++=(c)+q*(r);} +#define EMIT4(T,j,i,r,c) {CHKJ(j); p=(i)-(j); EXTZ(T,3); *u++=(j); *u++=p; *u++=(c)+q*(r);} +#define EMIT5(T,j,x,r,c) {if(0>(j))i=n;} + +#define DO_ONE(T,EMIT) \ + switch(e=v[1]){ \ + case 6: i=n; break; \ + case 2: case 3: if(0<=vi){EMIT(T,vj,vi,vr,vc); vi=vr=-1;} EMIT(T,j,i,r,c); j=2==e?i:-1; break; \ + case 4: case 5: if(r!=vr){if(0<=vi)EMIT(T,vj,vi,vr,vc); vj=j; vr=r; vc=c;} vi=i; j=4==e?i:-1; break; \ + case 1: j=i; \ + } + +#define ZVAx {} +#define ZVA5 {*zv++=i; *zv++=j; *zv++=r; *zv++=c; *zv++=v[0]; *zv++=v[1];} + +#define FSMF(T,zt,zr,zm,cexp,EMIT,ZVA) \ + {T*u,*uu; \ + RZ(z=exta((zt),(zr),(zm),1==f||5==f?n:n/3)); \ + if(1<(zr)){I*s=AS(z); s[1]=(zm); if(1==f&&2<wr)ICPY(1+s,1+AS(w0),wr-1);} \ + zv=AV(z); u=(T*)zv; uu=u+AN(z); \ + for(;i<n;++i,r=*v){c=(cexp); v=sv+2*(c+r*q); ZVA; DO_ONE(T,EMIT);} \ + if(6!=e){ \ + if(0<=d) {c=d; v=sv+2*(c+r*q); ZVA; DO_ONE(T,EMIT);} \ + else{ \ + if(0<=vi )EMIT(T,vj,r==vr?n:vi,vr,vc); \ + if(r!=vr&&0<=j)EMIT(T,j,n,r,c); \ + }} \ + if(5==f)u=(T*)zv; \ + i=AN(z); AN(z)=j=u-(T*)AV(z); *AS(z)=j/(zm); if(i>3*j)RZ(z=ca(z)); \ + } + +static A jtfsmdo(J jt,I f,A s,A m,I*ijrd,A w,A w0){A x,z;C*cc,*wv0; + I c,d,e,i,j,k,*mv,n,p,q,r,*sv,t,t0,*v,vc,vi,vj,vr,wk,wm,wr,*zv; + n=IC(w); t=AT(w); + q=*(1+AS(s)); + sv=AV(s); mv=AV(m); + i=ijrd[0]; j=ijrd[1]; r=ijrd[2]; d=ijrd[3]; vi=vj=vr=vc=-1; + if(t&INT){t0=AT(w0); wr=AR(w0); wm=aii(w0); wk=wm*bp(AT(w0)); wv0=CAV(w0);} + switch(f+(t&B01?0:t&LIT?10:20)){ + case 0: {B *wv=BAV(w); FSMF(A,BOX,1, 1, wv[i] ,EMIT0b,ZVAx);} break; + case 1: {B *wv=UAV(w); FSMF(B,B01,1, 1, wv[i] ,EMIT1, ZVAx);} break; + case 2: {B *wv=BAV(w); FSMF(I,INT,2, 2, wv[i] ,EMIT2, ZVAx);} break; + case 3: {B *wv=BAV(w); FSMF(I,INT,1, 1, wv[i] ,EMIT3, ZVAx);} break; + case 4: {B *wv=BAV(w); FSMF(I,INT,2, 3, wv[i] ,EMIT4, ZVAx);} break; + case 5: {B *wv=BAV(w); FSMF(I,INT,2, 6, wv[i] ,EMIT5, ZVA5);} break; + + case 10: {UC*wv=UAV(w); FSMF(A,BOX,1, 1,mv[wv[i]],EMIT0c,ZVAx);} break; + case 11: {UC*wv=UAV(w); FSMF(C,LIT,1, 1,mv[wv[i]],EMIT1, ZVAx);} break; + case 12: {UC*wv=UAV(w); FSMF(I,INT,2, 2,mv[wv[i]],EMIT2, ZVAx);} break; + case 13: {UC*wv=UAV(w); FSMF(I,INT,1, 1,mv[wv[i]],EMIT3, ZVAx);} break; + case 14: {UC*wv=UAV(w); FSMF(I,INT,2, 3,mv[wv[i]],EMIT4, ZVAx);} break; + case 15: {UC*wv=UAV(w); FSMF(I,INT,2, 6,mv[wv[i]],EMIT5, ZVA5);} break; + + case 20: {I *wv= AV(w); FSMF(A,BOX,1, 1, wv[i] ,EMIT0x,ZVAx);} break; + case 21: {I *wv= AV(w); FSMF(C,t0, wr,wm, wv[i] ,EMIT1x,ZVAx);} break; + case 22: {I *wv= AV(w); FSMF(I,INT,2, 2, wv[i] ,EMIT2, ZVAx);} break; + case 23: {I *wv= AV(w); FSMF(I,INT,1, 1, wv[i] ,EMIT3, ZVAx);} break; + case 24: {I *wv= AV(w); FSMF(I,INT,2, 3, wv[i] ,EMIT4, ZVAx);} break; + case 25: {I *wv= AV(w); FSMF(I,INT,2, 6, wv[i] ,EMIT5, ZVA5);} + } + R z; +} + +F1(jtfsmvfya){PROLOG;A a,*av,m,s,x,z,*zv;I ad,an,c,e,f,ijrd[4],k,p,q,*sv,*v; + RZ(a=w); + ASSERT(1==AR(a),EVRANK); + ASSERT(BOX&AT(a),EVDOMAIN); + an=AN(a); av=AAV(a); ad=(I)a*ARELATIVE(a); + ASSERT(2<=an&&an<=4,EVLENGTH); + RE(f=i0(AVR(0))); + ASSERT(0<=f&&f<=5,EVINDEX); + RZ(s=vi(AVR(1))); sv=AV(s); + ASSERT(3==AR(s),EVRANK); + v=AS(s); p=v[0]; q=v[1]; ASSERT(2==v[2],EVLENGTH); + v=sv; DO(p*q, k=*v++; e=*v++; ASSERT(0<=k&&k<p&&0<=e&&e<=6,EVINDEX);); + ijrd[0]=0; ijrd[1]=-1; ijrd[2]=0; ijrd[3]=-1; + if(4==an){I d,i,j,n,r; + RZ(x=vi(AVR(3))); n=AN(x); v=AV(x); + ASSERT(1==AR(x),EVRANK); + ASSERT(4>=n,EVLENGTH); + if(1<=n) ijrd[0]=i=*v++; + if(2<=n){ijrd[1]=j=*v++; ASSERT(j==-1||0<=j&&j<i,EVINDEX);} + if(3<=n){ijrd[2]=r=*v++; ASSERT( 0<=r&&r<p,EVINDEX);} + if(4==n){ijrd[3]=d=*v++; ASSERT(d==-1||0<=d&&d<q,EVINDEX);} + } + m=2==an?mtv:AVR(2); c=AN(m); + ASSERT(1>=AR(m),EVRANK); + if(!c&&1==AR(m)){ /* m is empty; w must be integer vector */ } + else if(NUMERIC&AT(m)){ + ASSERT(c==AN(alp),EVLENGTH); + RZ(m=vi(m)); v=AV(m); DO(c, k=v[i]; ASSERT(0<=k&&k<q,EVINDEX);); + }else ASSERT(BOX&AT(m),EVDOMAIN); + GA(z,BOX,4,1,0); zv=AAV(z); + RZ(zv[0]=sc(f)); zv[1]=s; zv[2]=m; RZ(zv[3]=vec(INT,4L,ijrd)); + R z; +} /* check left argument of x;:y */ + +static A jtfsm0(J jt,A a,A w,C chka){PROLOG;A*av,m,s,x,w0=w;B b;I ad,c,f,*ijrd,k,md,n,p,q,*v; + RZ(a&&w); + if(chka)RZ(a=fsmvfya(a)); + av=AAV(a); ad=(I)a*ARELATIVE(a); + f=i0(AVR(0)); s=AVR(1); m=AVR(2); ijrd=AV(AVR(3)); + n=AN(w); v=AS(s); p=v[0]; q=v[1]; + ASSERT(0<=ijrd[0]&&ijrd[0]<n,EVINDEX); + b=1>=AR(w)&&(!n||LIT&AT(w)); c=AN(m); + if(!c&&1==AR(m)){ + ASSERT(1>=AR(w),EVRANK); + if(!(B01&AT(w))){RZ(w=w0=vi(w)); v=AV(w); DO(n, k=v[i]; ASSERT(0<=k&&k<q,EVINDEX););} + }else if(NUMERIC&AT(m)){ + ASSERT(b,EVDOMAIN); + ASSERT(1>=AR(w),EVRANK); + }else{A*mv,t,y;I j,r; + ASSERT(BOX&AT(m),EVDOMAIN); + RZ(y=raze(m)); r=AR(y); k=AN(y); + ASSERT(r==AR(w)||r==1+AR(w),EVRANK); + GA(x,INT,1+k,1,0); v=AV(x); v[k]=c; mv=AAV(m); md=(I)m*ARELATIVE(m); + DO(c, j=i; t=AADR(md,mv[i]); if(r&&r==AR(t))DO(*AS(t), *v++=j;) else *v++=j;); + if(b){RZ(m=from(indexof(y,alp),x)); v=AV(m); DO(AN(alp), k=v[i]; ASSERT(0<=k&&k<q,EVINDEX););} + else {ASSERT(q>c,EVINDEX); RZ(w=from(indexof(y,w),x));} + } + EPILOG(fsmdo(f,s,m,ijrd,w,w0)); +} + +F2(jtfsm){R fsm0(a,w,1);} + /* x;:y */ + +DF1(jtfsmfx){RZ(w&&self); R fsm0(VAV(self)->f,w,0);} + /* x&;: y */
new file mode 100644 --- /dev/null +++ b/w.h @@ -0,0 +1,33 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Words */ + +#define CBBLOCK 1 /* control word types */ +#define CTBLOCK 2 +#define CDO 3 +#define CIF 4 +#define CELSE 5 +#define CEND 6 +#define CWHILE 7 +#define CWHILST 8 +#define CELSEIF 9 +#define CTRY 10 +#define CCATCH 11 +#define CBREAK 12 +#define CCONT 13 +#define CLABEL 14 +#define CGOTO 15 +#define CRETURN 16 +#define CFOR 17 +#define CDOF 18 +#define CBREAKF 19 +#define CSELECT 20 +#define CCASE 21 +#define CFCASE 22 +#define CDOSEL 23 +#define CENDSEL 24 +#define CASSERT 25 +#define CTHROW 26 +#define CCATCHD 27 +#define CCATCHT 28
new file mode 100644 --- /dev/null +++ b/wc.c @@ -0,0 +1,304 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Words: Control Words */ + +#include "j.h" +#include "w.h" + +#define CTESTB (CIF+CELSEIF+CSELECT+CWHILE+CWHILST+CFOR+CCASE+CFCASE) +#define CWCASE(x,y) (x+256*y) +#define CWASSERT(b) if(!(b))R i + + +static A jtcongotoblk(J jt,I n,CW*con){A z;CW*d=con;I i,j,k,*u,*v; + GA(z,INT,2*n,2,0); v=AS(z); v[0]=n; v[1]=2; + u=v=AV(z); + for(i=j=0;i<n;++i,++d){ + *u++=-1; *u++=-1; + switch(d->type){ + case CEND: + v[k]=i; while(0<k&&0<v[k])k-=2; break; + case CCASE: case CCATCH: case CDO: case CELSE: case CELSEIF: case CFCASE: + v[k]=i; /* fall thru */ + case CFOR: case CIF: case CSELECT: case CTRY: case CWHILE: case CWHILST: + v[j]=i; k=1+j; j+=2; + }} + R z; +} /* compute blocks for goto checking */ + +static I jtcongotochk(J jt,I i,I j,A x){I k,n,*v; + n=*AS(x); v=AV(x); + for(k=0;k<n;++k,v+=2)if(v[0]<=j&&j<=v[1]&&!(v[0]<=i&&i<=v[1]))R i; + R -1; +} /* i: goto; j: label; return -1 if ok or i if bad */ + +#define LABELEQU(m,s,e) (CLABEL==e->type&&(x=lv[e->i],!memcmp(s,6+CAV(x),m))) + +static I jtcongoto(J jt,I n,CW*con,A*lv){A x,z;C*s;CW*d=con,*e;I i,j,k,m; + RZ(z=congotoblk(n,con)); + for(i=0;i<n;++i,++d) + if(CGOTO==d->type){ + x=lv[d->i]; s=5+CAV(x); m=0; while('.'!=s[m])++m; ++m; + e=con-1; j=-1; + DO(n, ++e; if(LABELEQU(m,s,e)){j=1+i; d->go=(US)j; break;}); + CWASSERT(0<=j); + e=con+j-1; + for(k=j;k<n;++k){++e; if(LABELEQU(m,s,e)){i=k; CWASSERT(0);}} + if(0<=congotochk(i,j-1,z))R i; + } + R -1; +} /* same result as conall */ + + +/* conend - end encountered (but select end handled separately) */ +/* same result as conall */ +/* b i p end. */ +/* c j q 1st word before end. */ +/* d k r 2nd word before end. */ +/* each triplet (b,i,p) is ptr, stack index, code (ptr->type) */ + +static I conend(I i,I j,I k,CW*b,CW*c,CW*d,I p,I q,I r){I e,m,t; + e=1+i; + CWASSERT(c); c->go=(US)e; + switch(CWCASE(r,q)){ + default: CWASSERT(0); + case CWCASE(CDO,CELSE): + case CWCASE(CIF,CDO): break; + case CWCASE(CELSEIF,CDO): CWASSERT(d); d->go=(US)e; break; + case CWCASE(CWHILST,CDO): CWASSERT(d); d->go=(US)(1+j); + case CWCASE(CWHILE,CDO): + CWASSERT(b&&d); b->go=(US)(1+k); m=i-k-1; /* break. and continue. */ + DO(m, ++d; t=d->type; if(SMAX==d->go)d->go=t==CBREAK? (US)e :t==CCONT?(US)(1+k):(US)SMAX;); + break; + case CWCASE(CFOR,CDOF): + CWASSERT(b&&d); b->go=(US)j; m=i-k-1; /* break. and continue. */ + DO(m, ++d; t=d->type; if(SMAX==d->go)d->go=t==CBREAK?(d->type=CBREAKF,(US)e):t==CCONT?(US)j :(US)SMAX;); + } + R -1; +} + +static I conendtry(I e,I top,I stack[],CW*con){CW*v;I c[3],d[4],i=-1,j,k=0,m,t=0;US ii; + c[0]=c[1]=c[2]=-1; d[k++]=e; + while(top&&t!=CTRY){ + j=stack[--top]; + switch(t=(j+con)->type){ + case CTRY: break; + case CCATCH: CWASSERT(0>c[0]); c[0]=d[k++]=j; break; + case CCATCHD: CWASSERT(0>c[1]); c[1]=d[k++]=j; break; + case CCATCHT: CWASSERT(0>c[2]); c[2]=d[k++]=j; break; + default: CWASSERT(0); + }} + CWASSERT(t==CTRY&&1<k); + (j+con)->go=(US)d[k-1]; /* try. */ + m=k; DO(k-1, --m; (d[m]+con)->go=(US)d[m-1];); /* catchx. */ + (e+con)->go=(US)(1+e); /* end. */ + m=d[k-1]; + if (0<=c[0]){ii=(US)(1+c[0]); v=j+con; DO(m-j-1, ++v; if(SMAX==v->go&&CBREAK!=v->type)v->go=ii;);} + else if(0<=c[1]){ii=(US)(1+c[1]); v=j+con; DO(m-j-1, ++v; if(SMAX==v->go&&CBREAK!=v->type)v->go=ii;);} + R top; +} /* result is new value of top */ + +static I conendsel(I i,I top,I stack[],CW*con){I c=i-1,d=0,j,ot=top,t; + while(1){ + j=stack[--top]; t=(j+con)->type; + if(t==CSELECT)break; + if(t==CDOSEL){d=j; (j+con)->go=(US)(1+c);} + else{ + c=j; (j+con)->go=(US)i; + if(d==1+j)(d+con)->go=(US)(1+d); + if(t==CFCASE&&top<ot-2)(stack[2+top]+con)->go=(US)(1+stack[3+top]); + }} + (c+con)->go=(US)(1+c); + R top; +} /* result is new value of top */ + +static I jtconall(J jt,I n,CW*con){A y;CW*b=0,*c=0,*d=0;I e,i,j,k,p=0,q,r,*stack,tb=0,top=0,wb=0; + GA(y,INT,n,1,0); stack=AV(y); + for(i=0;i<n;++i){ + q=r=0; e=1+i; b=i+con; p=b->type; + if(0<top){j=stack[top-1]; c=j+con; q=c->type;} + if(1<top){k=stack[top-2]; d=k+con; r=d->type;} + switch(p){ + case CBBLOCK: if(tb)b->type=CTBLOCK; break; + case CLABEL: b->go=(US)e; break; + case CTRY: + case CCATCH: + case CCATCHD: + case CCATCHT: stack[top++]=i; break; + case CCONT: + case CBREAK: CWASSERT(wb); break; + case CFOR: + case CWHILE: + case CWHILST: ++wb; + case CSELECT: + case CIF: stack[top++]=i; ++tb; break; + case CCASE: + case CFCASE: + CWASSERT(q==CSELECT||q==CDOSEL); + stack[top++]=i; if(q==CDOSEL)++tb; + break; + case CDO: + CWASSERT(testb[q]); + b->type=q==CFOR?CDOF:q==CCASE||q==CFCASE?CDOSEL:CDO; + stack[top++]=i; --tb; + break; + case CELSEIF: + CWASSERT(q==CDO); + c->go=(US)e; + if(r==CELSEIF)d->go=(US)i; + top-=2; stack[top++]=i; ++tb; + break; + case CELSE: + CWASSERT(r==CIF&&q==CDO); + c->go=(US)e; + stack[top-2]=stack[top-1]; stack[top-1]=i; + break; + case CEND: + switch(q){ + case CDOSEL: + top=conendsel(i,top,stack,con); CWASSERT(0<=top); b->type=CENDSEL; break; + case CCATCH: case CCATCHD: case CCATCHT: + CWASSERT(1<=top); + top=conendtry(i,top,stack,con); CWASSERT(0<=top); break; + default: + top-=2; + if(r==CWHILE||r==CWHILST||r==CFOR)--wb; + CWASSERT(0>conend(i,j,k,b,c,d,p,q,r)); + }}} + R top?stack[top-1]:-1; +} /* modifies con; return -1 if OK or index of bad con entry */ + +A jtspellcon(J jt,I c){ + switch(c){ + default: ASSERTSYS(0,"spellcon"); + case CASSERT: R cstr("assert."); + case CBBLOCK: R cstr("bblock."); + case CBREAK: + case CBREAKF: R cstr("break."); + case CCASE: R cstr("case."); + case CCATCH: R cstr("catch."); + case CCATCHD: R cstr("catchd."); + case CCATCHT: R cstr("catcht."); + case CCONT: R cstr("continue."); + case CDO: + case CDOF: + case CDOSEL: R cstr("do."); + case CELSE: R cstr("else."); + case CELSEIF: R cstr("elseif."); + case CEND: + case CENDSEL: R cstr("end."); + case CFCASE: R cstr("fcase."); + case CFOR: R cstr("for."); + case CGOTO: R cstr("goto_."); + case CIF: R cstr("if."); + case CLABEL: R cstr("label_."); + case CRETURN: R cstr("return."); + case CSELECT: R cstr("select."); + case CTBLOCK: R cstr("tblock."); + case CTHROW: R cstr("throw."); + case CTRY: R cstr("try."); + case CWHILE: R cstr("while."); + case CWHILST: R cstr("whilst."); +}} + +static I jtconword(J jt,I n,C*s){ + if(2<n&&'.'==*(s+n-1))switch(*s){ + case 'a': if(!strncmp(s,"assert.", n))R CASSERT; break; + case 'b': if(!strncmp(s,"break.", n))R CBREAK; break; + case 'c': if(!strncmp(s,"case.", n))R CCASE; + if(!strncmp(s,"continue.",n))R CCONT; + if(!strncmp(s,"catch.", n))R CCATCH; + if(!strncmp(s,"catchd.", n))R CCATCHD; + if(!strncmp(s,"catcht.", n))R CCATCHT; break; + case 'd': if(!strncmp(s,"do.", n))R CDO; break; + case 'e': if(!strncmp(s,"end.", n))R CEND; + if(!strncmp(s,"else.", n))R CELSE; + if(!strncmp(s,"elseif.", n))R CELSEIF; break; + case 'f': if(!strncmp(s,"for.", n))R CFOR; + if(!strncmp(s,"for_", 4L)){ASSERTN(vnm(n-5,4+s),EVILNAME,nfs(n-5,4+s)); R CFOR;} + if(!strncmp(s,"fcase.", n))R CFCASE; break; + case 'g': if(!strncmp(s,"goto_", 5L))R CGOTO; break; + case 'i': if(!strncmp(s,"if.", n))R CIF; break; + case 'l': if(!strncmp(s,"label_", 6L))R CLABEL; break; + case 'r': if(!strncmp(s,"return.", n))R CRETURN; break; + case 's': if(!strncmp(s,"select.", n))R CSELECT; break; + case 't': if(!strncmp(s,"throw.", n))R CTHROW; + if(!strncmp(s,"try.", n))R CTRY; break; + case 'w': if(!strncmp(s,"while.", n))R CWHILE; + if(!strncmp(s,"whilst.", n))R CWHILST; break; + } + R 0; +} + +static F1(jtgetsen){A y,z,*z0,*zv;C*s;I i,j,k=-1,m,n,*v; + RZ(y=wordil(w)); + v=AV(y); /* pairs, (index, len) */ + n=2**v++; /* count of pair element */ + n=0>n?-(2+n):n; /* remove NB. pair */ + GA(z,BOX,n/2,1,0); z0=zv=AAV(z); /* list of ctrls & sentences */ + s=CAV(w); /* text of entire string */ + for(i=0;i<n;i+=2){ + j=v[i]; m=v[1+i]; /* index & length of this word*/ + if(0>k)k=j; /* index of sentence */ + if(conword(m,j+s)){ + if(k<j)RZ(*zv++=str(j-k,k+s)); /* emit sentence in progress */ + RZ(*zv++=str(m,j+s)); /* emit ctrl */ + k=-1; + }} + if(0<=k)RZ(*zv++=str(j+m-k,k+s)); /* emit sentence if any */ + R vec(BOX,zv-z0,z0); +} /* partition by controls */ + +/* preparse - return tokenized lines and control information */ +/* argument is a list of boxed explicit defn lines */ +/* result is 1 iff try is seen */ +/* zl - list of lines of tokens */ +/* zc - corresp list of control info */ +/* control info has 3 I values for each line */ +/* control info values - type, goto linenum, source linenum */ + +#define ASSERTCW(b,j) {if(!(b)){I jj=(j); jsignal3(EVCTRL,wv[jj],jj); R 0;}} + +B jtpreparse(J jt,A w,A*zl,A*zc){PROLOG;A c,l,*lv,*v,w0,w1,*wv,x,y;B b=0,try=0; + C*s;CW*d,*cv;I as=0,i,j,k,m,n,p,q,yn; + RZ(w); + p=AN(w); wv=AAV(w); + ASSERT(p<SMAX,EVLIMIT); + RZ(c=exta(CONW,1L,1L,3*p)); cv=(CW*)AV(c); n=0; /* ctrl info */ + RZ(l=exta(BOX, 1L,1L,5*p)); lv= AAV(l); m=0; /* tokens */ + for(i=0;i<p;++i){ + RZ(y=getsen(wv[i])); yn=AN(y); v=AAV(y); + for(j=0;j<yn;++j){ + if(n==AN(c)){RZ(c=ext(0,c)); cv=(CW*)AV(c);} + w0=v[j]; /* sentence text */ + RZ(w1=wordil(w0)); /* get wordlen again */ + s=CAV(w0); + k=conword(*(2+AV(w1)),s); /* what kind of word? */ + if(k==CTRY)try=1; /* try is seen */ + if(k==CASSERT){ASSERTCW(!as,i ); as=1;} + else if(1==as){ASSERTCW(!k, i-1); as=2; --n;} + d=n+cv; /* address control info */ + d->type=k?(C)k:2==as?CASSERT:CBBLOCK;/* control type */ + d->source=(US)i; /* source line number */ + d->go= !k||k==CCONT||k==CBREAK||k==CTHROW ? (US)SMAX : k==CRETURN ? (US)SMAX-1 : (US)(1+n); + b|=k==CGOTO; /* goto seen? */ + if(!k)RZ(x=enqueue(w1,w0)) else x=k==CLABEL||k==CGOTO||k==CFOR&&4<AN(w0)?w0:0L; + q=k?1&&x:AN(x); + ASSERT(q<SMAX,EVLIMIT); + if(x){ /* tokens of the line */ + while(AN(l)<m+q){RZ(l=ext(0,l)); lv=AAV(l);} + if(k)lv[m]=x; else ICPY(m+lv,AAV(x),q); + } + d->i=m; d->n=(US)q; m+=q; + if(2==as)as=0; + ++n; + }} + RE(0); + ASSERTCW(!as,p-1); + ASSERTCW(!b||0>(i=congoto(n,cv,lv)),(i+cv)->source); + ASSERTCW( 0>(i= conall(n,cv )),(i+cv)->source); + AN(l)=*AS(l)=m; *zl=l; + AN(c)=*AS(c)=n; *zc=c; + R try; +}
new file mode 100644 --- /dev/null +++ b/win/jdll.c @@ -0,0 +1,720 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* J Windows dll and com interface (old jcom.c, jdll.c, jwin32.c) */ + +// Included as part of JDLL server +// Routines here provide services for JEXE object, JDLL object, +// and good old JDLL dll calls + +// Steps required to add a new JEXE method (change names for JDLL) +// 1. add method to methods.odl +// 2. smsrc\tlbdebug.bat to create jexe.tlb and jexeodl.h (also creates jdll.tlb) +// be sure new tlb files are in directory when jreg is run! +// 3. add method to jdllcom.h +// 4. add method declarations (dll and exe) to jdllcomx.cpp (JDoType JDo/*Jdo) +// 5. add method to jdllcomx.cpp (dll and exe sections) +// 6. add method (with J prefix) to jcom.c +// 7. add typedef to jdlltype.h +// 8. add export to jdll.def +// 9. add setting of dll proc address in smj32.dll (getprocaddress) +// 10. run jreg with new tlb files + +#include <windows.h> +#include "..\jsrc\j.h" +#include "..\jsrc\jlib.h" + +void wtom(US* src, I srcn, UC* snk); +int valid(C* psrc, C* psnk); +C* esub(J jt, long ec); + +extern int uniflag; + +I jdo(J, C*); + +#define MAXRANK 60 + +static void tounin(C* src, WCHAR* sink, UI n) +{ + while(n) + { + *sink++ = *src++; + --n; + } + *sink++=0; +} + +void touni(C* src, WCHAR* sink) +{ + while(*src) + *sink++ = *src++; + *sink++=0; +} + +void toasc(WCHAR* src, C* sink) +{ + while(*src) + *sink++ = (char)*src++; + *sink++=0; +} + +int _stdcall JBreak(J jt){ return 0;} + +int _stdcall JIsBusy(J jt){ return 0;} + +#if !SY_WINCE + +//! 64 bit problems - com and dll interface is 32 bit - needs test and thought +static int a2v (J jt, A a, VARIANT *v, int dobstrs) +{ + SAFEARRAY FAR* psa; + SAFEARRAYBOUND rgsabound[MAXRANK]; + int er; + I i,r,k,t,cb,*pi; + VARTYPE vt; + + k=AN(a); + pi=AV(a); + r=AR(a); + t=AT(a); + if(r>MAXRANK) return EVRANK; + if(dobstrs && r<2 && LIT==t) // char scalar or vector returned as BSTR + { + BSTR bstr = SysAllocStringLen(0, (UINT)k); + tounin((C*)pi, bstr, k); + v->vt=VT_BSTR; + v->bstrVal=bstr; + R 0; + } + switch(t) + { + case LIT: + if(!r) {v->vt=VT_UI1; v->bVal = *(C*)pi; return 0;} + vt=VT_UI1; + cb=k*sizeof(char); + break; + + case B01: + if(!r) { + v->vt=VT_BOOL; + v->boolVal = *(B*)pi ? VARIANT_TRUE : VARIANT_FALSE; + return 0; + } + vt=VT_BOOL; + break; + + case INT: + if(!r) {v->vt=VT_I4; v->lVal = (long)(*pi); return 0;} + vt=VT_I4; + cb=k*sizeof(int); + break; + + case FL: + if(!r) {v->vt=VT_R8; v->dblVal = *(D*)pi; return 0;} + vt=VT_R8; + cb=k*sizeof(double); + break; + + case BOX: + if(!r) + { + // Pass a scalar box as a 1-elem VARIANT VT_ARRAY. + // It's marked as such by a lower bound set at -1. + // (All "true" boxed arrays will have the usual lb 0.) + rgsabound[0].lLbound = -1; + rgsabound[0].cElements = 1; + + if ( ! (psa = SafeArrayCreate (VT_VARIANT, 1, rgsabound))) + return EVWSFULL; + if (0!= (er = a2v (jt, *(A*)pi, (VARIANT*)psa->pvData, dobstrs))) + { + SafeArrayDestroy (psa); + return er; + } + v->vt=VT_ARRAY|VT_VARIANT; + v->parray = psa; + return 0; + } + vt=VT_VARIANT; + cb=k*sizeof(A); + break; + + default: + return EVDOMAIN; + } + + + if(1<r && jt->transposeflag) + RE(a=cant1(a)); // undo shape reversal later! + + for(i=0; i<r; ++i) + { + rgsabound[i].lLbound = 0; + // undo shape reversal from cant1() here. + // In case of Transpose(0), the shape is + // still passed in Column-major notation. + rgsabound[i].cElements = (ULONG)AS(a)[r-1-i]; + } + psa = SafeArrayCreate(vt, (UINT)r, rgsabound); + if(!psa) + { + return EVWSFULL; + } + + switch (AT(a)) + { + case B01: + { + VARIANT_BOOL *pv = (VARIANT_BOOL*) psa->pvData; + B *ap = BAV(a); + + while (k--) + *pv++ = *ap++ ? VARIANT_TRUE : VARIANT_FALSE; + break; + } + case BOX: + { + A* ap; + VARIANT *v; + + for (ap=AAV(a), SafeArrayAccessData(psa, &v); + ap<AAV(a)+k; + ++ap, ++v) + { + PROLOG; + er=a2v (jt, *ap, v, dobstrs); + tpop(_ttop); + if (er!=0) + { + SafeArrayUnaccessData (psa); + SafeArrayDestroy (psa); + return er; + } + } + SafeArrayUnaccessData (psa); + break; + } + default: + memcpy(psa->pvData, AV(a), cb); + } + v->vt=VT_ARRAY|vt; + v->parray = psa; + return 0; +} + +int jget(J jt, C* name, VARIANT* v, int dobstr) +{ + A a; + char gn[256]; + I old; + int er; + + if(strlen(name) >= sizeof(gn)) return EVILNAME; + if(valid(name, gn)) return EVILNAME; + RZ(a=symbrd(nfs(strlen(gn),gn))); + old = jt->tbase+jt->ttop; + er = a2v (jt, a, v, dobstr); + tpop (old); + return er; +} + +int _stdcall JGet(J jt, C* name, VARIANT* v) +{ + return jget(jt, name, v, 0); // no bstrs +} + +int _stdcall JGetB(J jt, C* name, VARIANT* v) +{ + return jget(jt, name, v, 1); // do bstrs +} + +// convert a VARIANT to a J array +// returns 0 on error with detail in jerr. +static A v2a(J jt, VARIANT* v, int dobstrs) +{ + A a; + SAFEARRAY* psa; + SAFEARRAYBOUND* pb; + I shape[MAXRANK]; + I k=1,n,r,i; + I* pintsnk; + short* pshortsrc; + unsigned short* pboolsrc; + char* pboolsnk; + VARTYPE t; + int byref; + double* pdoublesnk; + float* pfloatsrc; + +#define OPTREF(v,field) (byref ? *v->p##field : v->field) + + t=v->vt; + byref = t & VT_BYREF; + t = t & ~VT_BYREF; + + if(dobstrs && t == VT_BSTR) + { + BSTR bstr; int len; + + bstr = OPTREF(v,bstrVal); + + if(uniflag) + len=SysStringLen(bstr); + else + len=SysStringByteLen(bstr); + RE(a=ga(LIT, len, 1, 0)); + if(uniflag) + toasc(bstr, (C*)AV(a)); + else + memcpy((C*)AV(a), (C*)bstr, len); + R a; + } + if(t & VT_ARRAY) + { + psa = OPTREF(v,parray); + pb = psa->rgsabound; + r=psa->cDims; + ASSERT(r<=MAXRANK,EVRANK); + for(i=0; i<r; ++i) + { + n = pb[i].cElements; + shape[i] = n; + k *= n; + } + } + else + r = 0; + + switch(t) + { + case VT_VARIANT | VT_ARRAY: + { + A *boxes; + VARIANT* pv; + + // fixup scalar boxes which arrive + // as a 1-elem vector with a lower bound at -1, not 0. + if (pb[0].lLbound == -1) + { + ASSERT(psa->cDims==1 && pb[0].cElements==1, EVDOMAIN); + r = 0; + } + RE(a=ga(BOX, k, r, (I*)&shape)); + ASSERT(S_OK==SafeArrayAccessData(psa, &pv),EVFACE); + boxes = AAV(a); + while(k--) + { + A z; + // Don't use a PROLOG/EPILOG during v2a. + // The z's are not getting their reference + // count set until everything is in place + // and the jset() is done in Jset(). + z = *boxes++ = v2a(jt, pv++, dobstrs); + if (!z) break; + } + SafeArrayUnaccessData(psa); + if (jt->jerr) return 0; + break; + } + case VT_BOOL | VT_ARRAY: + RE(a=ga(B01, k, r, (I*)&shape)); + pboolsrc = (VARIANT_BOOL*)psa->pvData; + pboolsnk = BAV(a); + // J bool returned from VB boolean, a -1 and 0 mess. + // It wouldn't be that bad if the Microsoft folks used their own macros + // and kept an eye an sign extensions. But the way they are + // doing it they are returning at least some TRUEs as value 255 + // instead of VARIANT_TRUE. Therefore, we have to compare against + // VARIANT_FALSE which -we hope- is consistently defined (as 0). + while(k--) + *pboolsnk++ = (*pboolsrc++)!=VARIANT_FALSE; + break; + + case VT_UI1 | VT_ARRAY: + RE(a=ga(LIT, k, r, (I*)&shape)); + memcpy(AV(a), psa->pvData, k * sizeof(char)); + break; + + case VT_I2 | VT_ARRAY: + RE(a=ga(INT, k, r, (I*)&shape)); + pshortsrc = (short*)psa->pvData; + pintsnk = AV(a); + while(k--) + *pintsnk++ = *pshortsrc++; + break; + + case VT_I4 | VT_ARRAY: + RE(a=ga(INT, k, r, (I*)&shape)); + memcpy(AV(a), psa->pvData, k * sizeof(int)); + break; + + case VT_R4 | VT_ARRAY: + RE(a=ga(FL, k, r, (I*)&shape)); + pfloatsrc = (float*)psa->pvData; + pdoublesnk = (double*)AV(a); + while(k--) + *pdoublesnk++ = *pfloatsrc++; + break; + + case VT_R8 | VT_ARRAY: + RE(a=ga(FL, k, r, (I*)&shape)); + memcpy(AV(a), psa->pvData, k * sizeof(double)); + break; + + case VT_UI1: + RE(a=ga(LIT, 1, 0, 0)); + *CAV(a) = OPTREF(v,bVal); + break; + + case VT_BOOL: + RE(a=ga(B01, 1, 0, 0)); + // array case above explains this messy phrase: + *BAV(a) = OPTREF(v,boolVal)!=VARIANT_FALSE; + break; + + case VT_I2: + RE(a=ga(INT, 1, 0, 0)); + *IAV(a) = OPTREF(v,iVal); + break; + + case VT_I4: + RE(a=ga(INT, 1, 0, 0)); + *IAV(a) = OPTREF(v,lVal); + break; + + case VT_R4: + RE(a=ga(FL, 1, 0, 0)); + *DAV(a) = OPTREF(v,fltVal); + break; + + case VT_R8: + RE(a=ga(FL, 1, 0, 0)); + *DAV(a) = OPTREF(v,dblVal); + break; + + default: + ASSERT(0,EVDOMAIN); + } + if(1<r && jt->transposeflag) + { + RE(a=cant1(a)); + DO(r, AS(a)[i]=shape[r-1-i];); + } + return a; +} +#endif wince + +// copy non-nulls only +static void touninx(C* src, WCHAR* sink, UI n) +{ + while(n--) + { + if(*src) + *sink++ = *src++; + else + src++; + } + *sink++=0; +} + +// copy output with nulls deleted, lf to crlf, cr(no lf) to crlf +void fixoutput(char* src, WCHAR* snk, I k) +{ + int i; char c; + + for(i=0; i<k; i++) + { + c = src[i]; + if(c==CCR || c==CLF) + { + *snk++ = CCR; + *snk++ = CLF; + if(c==CCR && (i+1)<k && src[i+1]==CLF) ++i; // skip lf of crlf + } + else + { + if(c) *snk++ = c; + } + } +} + +// adjust space required for output +// nulls -1, lf +1, cr (without lf) +1 +I countoutput(I n, char*s) +{ + I i,k=0; + + for(i=0; i<n; i++) + { + switch(s[i]) + { + case 0: k -= 1; break; // delete nulls + case CLF: k += 1; break; // lf needs a cr + case CCR: + if((i+1)<n && CLF != s[i+1]) + k += 1; // lone cr needs an lf + else + ++i; // skip lf of crlf + } + } + return k; +} + +#if !SY_WINCE +void oleoutput(J jt, I n, char* s) +{ + I k; + + if(!jt->oleop) return; + k = countoutput(n, s); + if(!jt->opbstr) + { + jt->opbstr = SysAllocStringLen(0, (UINT)(n+k)); + fixoutput(s, jt->opbstr, n); + } + else + { + I len = SysStringLen(jt->opbstr); + SysReAllocStringLen(&(BSTR)jt->opbstr, 0, (UINT)(len+n+k)); + fixoutput(s, (BSTR)jt->opbstr + len, n); + } +} + +int jsetx(J jt, C* name, VARIANT* v, int dobstrs) +{ + int er; + I old=jt->tbase+jt->ttop; + char gn[256]; + + // validate name + if(strlen(name) >= sizeof(gn)) return EVILNAME; + if(valid(name, gn)) return EVILNAME; + + er=jt->jerr=0; + jset (gn, v2a(jt, v,dobstrs)); // no bstrs + er=jt->jerr; jt->jerr=0; + tpop(old); + return er; +} + +int _stdcall JSet(J jt, C* name, VARIANT* v) +{ + return jsetx(jt, name, v, 0); // no bstrs +} + +int _stdcall JSetB(J jt, C* name, VARIANT* v) +{ + return jsetx(jt, name, v, 1); // do bstrs +} + +int _stdcall JErrorText(J jt, long ec, VARIANT* v) +{ + C* p; + SAFEARRAY FAR* psa; + SAFEARRAYBOUND rgsabound; + I cb; + + p=esub(jt, ec); + cb=1+strlen(p); // include null + rgsabound.lLbound = 0; + rgsabound.cElements = (ULONG)cb; + psa = SafeArrayCreate(VT_UI1, 1, &rgsabound); + if(!psa) return EVWSFULL; + memcpy(psa->pvData, p, cb); + v->vt = VT_ARRAY | VT_UI1; + v->parray = psa; + return 0; +} + +int _stdcall JClear(J jt){ return 0;}; + +int _stdcall JTranspose(J jt, long b) +{ + jt->transposeflag = b; + return 0; +} + +int _stdcall JErrorTextB(J jt, long ec, VARIANT* v) +{ + C* p; + BSTR bstr; + + p=esub(jt, ec); + bstr = SysAllocStringLen(0, (UINT)strlen(p)); + tounin(p, bstr, strlen(p)); + v->vt=VT_BSTR; + v->bstrVal=bstr; + R 0; +} + +int _stdcall JDoR(J jt, C* p, VARIANT* v) +{ + int e; + + jt->oleop=1; // capture output + jt->opbstr=0; // none so far + e=JDo(jt, p); + jt->oleop=0; + v->vt=VT_BSTR; + v->bstrVal=jt->opbstr; + R e; +} +#endif wince + +// previously in separate file when jdll.c and jcom.c both exisited +char modulepath[_MAX_PATH]; +char dllpath[_MAX_PATH]; +void dllquit(J); +void oleoutput(J,I n,char* s); +HINSTANCE g_hinst; +J g_jt; + +extern C* getlocale(J); +extern void FreeGL(HANDLE hglrc); + + +#if SY_WINCE +void getpath(HINSTANCE hi, C* path) +{ + WCHAR wpath[_MAX_PATH]; WCHAR* p; + + GetModuleFileName(hi, wpath,_MAX_PATH); + p = wcsrchr(wpath, '\\'); + if(!p) p = wcsrchr(wpath, ':'); + *(1+p) = 0; + wtom(wpath,wcslen(wpath),path); +} +#else +void getpath(HINSTANCE hi, C* path) +{ + WCHAR wpath[_MAX_PATH];WCHAR* p; + + GetModuleFileNameW(hi, wpath, _MAX_PATH); + p = wcsrchr(wpath, '\\'); + if(!p) p = wcsrchr(wpath, ':'); + *(1+p) = 0; + wtom(wpath,wcslen(wpath),path); +} +#endif + + +J heapinit(int size) +{ + HANDLE h; + J jt; + + h = HeapCreate(0, size, 0); + if(!h) return 0; + jt = HeapAlloc(h, 0, sizeof(JST)); + if(!jt) + { + HeapDestroy(h); + return 0; + } + memset(jt,0,sizeof(JST)); + jt->heap = h; + return jt; +} + +int WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) +{ + switch (dwReason) + { + case DLL_PROCESS_ATTACH: + g_hinst = hDLL; +/* + { + SYSTEMTIME s; + GetSystemTime(&s); + if(s.wYear != 2000 || 11<s.wMonth) + { + MessageBox(0, "J.DLL beta test period has expired.", "J", MB_OK); + return 0; + } + } +*/ + getpath(0, modulepath); + getpath(hDLL, dllpath); + g_jt=heapinit(10000); + if(!g_jt) R 0; + if(!jtglobinit(g_jt)) {HeapDestroy(g_jt->heap); g_jt=0; R 0;}; + break; + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + + case DLL_PROCESS_DETACH: + if(g_jt) HeapDestroy(g_jt->heap); + break; + } +return TRUE; +} + +J _stdcall JInit() +{ + JST* jt; + + jt=heapinit(1000000); + if(!jt) R 0; + if(!jtjinit2(jt,0,0)) + { + HeapDestroy(jt->heap); + R 0; + }; + return jt; +} + +// clean up at the end of a J instance +int _stdcall JFree(J jt) +{ + + if(!jt) return 0; +#if !SY_WINCE + dllquit(jt); // clean up call dll +#endif + HeapDestroy(jt->heap); + return 0; +} + +// previously in jwin32.c + +#ifndef _JDLL +char dllpath[] = ""; /* dll path is empty */ +#endif + +#ifdef _MAC +#ifdef _DEBUG +LONG _lcbExtraStack = 256*1024; /* more than 215k required in debug */ +#else +LONG _lcbExtraStack = 200*1024; /* 175 fails */ +#endif +#endif + +#if !SY_WINCE +unsigned int getfileattr(char *p) +{ + return GetFileAttributes(p); +} + +int setfileattr(char*p, unsigned int x) +{ + return SetFileAttributes(p, x); +} +#endif + +F1(jtts){A z;D*x;SYSTEMTIME t; + ASSERTMTV(w); + GetLocalTime(&t); + GA(z,FL,6,1,0); x=DAV(z); + x[0]=t.wYear; + x[1]=t.wMonth; + x[2]=t.wDay; + x[3]=t.wHour; + x[4]=t.wMinute; + x[5]=t.wSecond+(D)t.wMilliseconds/1000; + R z; +} +
new file mode 100644 --- /dev/null +++ b/win/jdll.def @@ -0,0 +1,29 @@ +LIBRARY J + +EXPORTS + DllGetClassObject PRIVATE + DllCanUnloadNow PRIVATE + DllRegisterServer PRIVATE + DllUnregisterServer PRIVATE + JBreak @6 + JClear @7 + JDo @8 + JErrorText @9 + JErrorTextM @10 + JFree @11 + JGet @12 + JGetM @13 + JInit @14 + JIsBusy @15 + JSet @16 + JSetM @17 + JSM @18 + JGetLocale @19 + Jga @20 + JTranspose @21 + JErrorTextB @22 + JGetB @23 + JSetB @24 + JDoR @25 + JGetA @26 + JSetA @27
new file mode 100644 --- /dev/null +++ b/win/jdll.h @@ -0,0 +1,699 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + +/* File created by MIDL compiler version 5.01.0164 */ +/* at Thu Jun 22 11:55:16 2000 + */ +/* Compiler settings for default\jdll.idl: + Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext + error checks: allocation ref bounds_check enum stub_data +*/ +//@@MIDL_FILE_HEADING( ) + + +/* verify that the <rpcndr.h> version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 440 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of <rpcndr.h> +#endif // __RPCNDR_H_VERSION__ + +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __jdll_h__ +#define __jdll_h__ + +#ifdef __cplusplus +extern "C"{ +#endif + +/* Forward Declarations */ + +#ifndef __IJDLLServer_FWD_DEFINED__ +#define __IJDLLServer_FWD_DEFINED__ +typedef interface IJDLLServer IJDLLServer; +#endif /* __IJDLLServer_FWD_DEFINED__ */ + + +#ifndef __JDLLServer_FWD_DEFINED__ +#define __JDLLServer_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class JDLLServer JDLLServer; +#else +typedef struct JDLLServer JDLLServer; +#endif /* __cplusplus */ + +#endif /* __JDLLServer_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" + +void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t); +void __RPC_USER MIDL_user_free( void __RPC_FAR * ); + +#ifndef __IJDLLServer_INTERFACE_DEFINED__ +#define __IJDLLServer_INTERFACE_DEFINED__ + +/* interface IJDLLServer */ +/* [oleautomation][dual][unique][helpstring][uuid][object] */ + + +EXTERN_C const IID IID_IJDLLServer; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("21EB05EC-1AB3-11cf-A2AC-8FF70874C460") + IJDLLServer : public IDispatch + { + public: + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Do( + /* [in] */ BSTR input, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Show( + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Log( + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE IsBusy( + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Break( + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Quit( + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Get( + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Set( + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetM( + /* [in] */ BSTR jname, + /* [out] */ long __RPC_FAR *jtype, + /* [out] */ long __RPC_FAR *jrank, + /* [out] */ long __RPC_FAR *jshape, + /* [out] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetM( + /* [in] */ BSTR jname, + /* [in] */ long __RPC_FAR *jtype, + /* [in] */ long __RPC_FAR *jrank, + /* [in] */ long __RPC_FAR *jshape, + /* [in] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ErrorText( + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ErrorTextM( + /* [in] */ long error, + /* [out] */ long __RPC_FAR *text, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Clear( + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Transpose( + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ErrorTextB( + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetB( + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetB( + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE DoR( + /* [in] */ BSTR input, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r) = 0; + + }; + +#else /* C style interface */ + + typedef struct IJDLLServerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )( + IJDLLServer __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )( + IJDLLServer __RPC_FAR * This); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( + IJDLLServer __RPC_FAR * This); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfoCount )( + IJDLLServer __RPC_FAR * This, + /* [out] */ UINT __RPC_FAR *pctinfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfo )( + IJDLLServer __RPC_FAR * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetIDsOfNames )( + IJDLLServer __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID __RPC_FAR *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Invoke )( + IJDLLServer __RPC_FAR * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams, + /* [out] */ VARIANT __RPC_FAR *pVarResult, + /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo, + /* [out] */ UINT __RPC_FAR *puArgErr); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Do )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR input, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Show )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Log )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *IsBusy )( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Break )( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Quit )( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Get )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Set )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetM )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ long __RPC_FAR *jtype, + /* [out] */ long __RPC_FAR *jrank, + /* [out] */ long __RPC_FAR *jshape, + /* [out] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *SetM )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ long __RPC_FAR *jtype, + /* [in] */ long __RPC_FAR *jrank, + /* [in] */ long __RPC_FAR *jshape, + /* [in] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ErrorText )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ErrorTextM )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ long __RPC_FAR *text, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Clear )( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Transpose )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ErrorTextB )( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetB )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *SetB )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + /* [helpstring] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *DoR )( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR input, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + END_INTERFACE + } IJDLLServerVtbl; + + interface IJDLLServer + { + CONST_VTBL struct IJDLLServerVtbl __RPC_FAR *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IJDLLServer_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IJDLLServer_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IJDLLServer_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IJDLLServer_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IJDLLServer_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IJDLLServer_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IJDLLServer_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IJDLLServer_Do(This,input,r) \ + (This)->lpVtbl -> Do(This,input,r) + +#define IJDLLServer_Show(This,b,r) \ + (This)->lpVtbl -> Show(This,b,r) + +#define IJDLLServer_Log(This,b,r) \ + (This)->lpVtbl -> Log(This,b,r) + +#define IJDLLServer_IsBusy(This,r) \ + (This)->lpVtbl -> IsBusy(This,r) + +#define IJDLLServer_Break(This,r) \ + (This)->lpVtbl -> Break(This,r) + +#define IJDLLServer_Quit(This,r) \ + (This)->lpVtbl -> Quit(This,r) + +#define IJDLLServer_Get(This,jname,v,r) \ + (This)->lpVtbl -> Get(This,jname,v,r) + +#define IJDLLServer_Set(This,jname,v,r) \ + (This)->lpVtbl -> Set(This,jname,v,r) + +#define IJDLLServer_GetM(This,jname,jtype,jrank,jshape,jdata,r) \ + (This)->lpVtbl -> GetM(This,jname,jtype,jrank,jshape,jdata,r) + +#define IJDLLServer_SetM(This,jname,jtype,jrank,jshape,jdata,r) \ + (This)->lpVtbl -> SetM(This,jname,jtype,jrank,jshape,jdata,r) + +#define IJDLLServer_ErrorText(This,error,v,r) \ + (This)->lpVtbl -> ErrorText(This,error,v,r) + +#define IJDLLServer_ErrorTextM(This,error,text,r) \ + (This)->lpVtbl -> ErrorTextM(This,error,text,r) + +#define IJDLLServer_Clear(This,r) \ + (This)->lpVtbl -> Clear(This,r) + +#define IJDLLServer_Transpose(This,b,r) \ + (This)->lpVtbl -> Transpose(This,b,r) + +#define IJDLLServer_ErrorTextB(This,error,v,r) \ + (This)->lpVtbl -> ErrorTextB(This,error,v,r) + +#define IJDLLServer_GetB(This,jname,v,r) \ + (This)->lpVtbl -> GetB(This,jname,v,r) + +#define IJDLLServer_SetB(This,jname,v,r) \ + (This)->lpVtbl -> SetB(This,jname,v,r) + +#define IJDLLServer_DoR(This,input,v,r) \ + (This)->lpVtbl -> DoR(This,input,v,r) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Do_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR input, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Do_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Show_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Show_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Log_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Log_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_IsBusy_Proxy( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_IsBusy_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Break_Proxy( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Break_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Quit_Proxy( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Quit_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Get_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Get_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Set_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Set_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_GetM_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ long __RPC_FAR *jtype, + /* [out] */ long __RPC_FAR *jrank, + /* [out] */ long __RPC_FAR *jshape, + /* [out] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_GetM_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_SetM_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ long __RPC_FAR *jtype, + /* [in] */ long __RPC_FAR *jrank, + /* [in] */ long __RPC_FAR *jshape, + /* [in] */ long __RPC_FAR *jdata, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_SetM_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_ErrorText_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_ErrorText_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_ErrorTextM_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ long __RPC_FAR *text, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_ErrorTextM_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Clear_Proxy( + IJDLLServer __RPC_FAR * This, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Clear_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_Transpose_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long b, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_Transpose_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_ErrorTextB_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ long error, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_ErrorTextB_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_GetB_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_GetB_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_SetB_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR jname, + /* [in] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_SetB_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring] */ HRESULT STDMETHODCALLTYPE IJDLLServer_DoR_Proxy( + IJDLLServer __RPC_FAR * This, + /* [in] */ BSTR input, + /* [out] */ VARIANT __RPC_FAR *v, + /* [retval][out] */ long __RPC_FAR *r); + + +void __RPC_STUB IJDLLServer_DoR_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IJDLLServer_INTERFACE_DEFINED__ */ + + + +#ifndef __JDLLServerLib_LIBRARY_DEFINED__ +#define __JDLLServerLib_LIBRARY_DEFINED__ + +/* library JDLLServerLib */ +/* [version][helpstring][uuid] */ + + +EXTERN_C const IID LIBID_JDLLServerLib; + +EXTERN_C const CLSID CLSID_JDLLServer; + +#ifdef __cplusplus + +class DECLSPEC_UUID("21EB05EA-1AB3-11cf-A2AC-8FF70874C460") +JDLLServer; +#endif +#endif /* __JDLLServerLib_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +unsigned long __RPC_USER BSTR_UserSize( unsigned long __RPC_FAR *, unsigned long , BSTR __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER BSTR_UserMarshal( unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, BSTR __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER BSTR_UserUnmarshal(unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, BSTR __RPC_FAR * ); +void __RPC_USER BSTR_UserFree( unsigned long __RPC_FAR *, BSTR __RPC_FAR * ); + +unsigned long __RPC_USER VARIANT_UserSize( unsigned long __RPC_FAR *, unsigned long , VARIANT __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER VARIANT_UserMarshal( unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, VARIANT __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER VARIANT_UserUnmarshal(unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, VARIANT __RPC_FAR * ); +void __RPC_USER VARIANT_UserFree( unsigned long __RPC_FAR *, VARIANT __RPC_FAR * ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif
new file mode 100644 --- /dev/null +++ b/win/jdll.rc @@ -0,0 +1,48 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +// jdll.rc2 - resources App Studio does not edit directly +#ifdef APSTUDIO_INVOKED + #error this file is not editable by App Studio +#endif //APSTUDIO_INVOKED + +#include "winver.h" + +1 typelib jdll.tlb + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 701 + PRODUCTVERSION 701 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG|VS_FF_PRIVATEBUILD|VS_FF_PRERELEASE +#else + FILEFLAGS 0 // final version +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual + BEGIN + VALUE "CompanyName", "Jsoftware Inc.\0" + VALUE "FileDescription", "J\0" + VALUE "FileVersion", "701\0" + VALUE "InternalName", "J\0" + VALUE "LegalCopyright", "Copyright Jsoftware Inc. 2011\0" + VALUE "LegalTrademarks", "J\0" + VALUE "OriginalFilename","J\0" + VALUE "ProductName", "J\0" + VALUE "ProductVersion", "701\0" + VALUE "OLESelfRegister", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + // English language (0x409) and the Windows ANSI codepage (1252) + END +END +
new file mode 100644 --- /dev/null +++ b/win/jdllcom.h @@ -0,0 +1,103 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* included in both J.EXE and J.dll */ + +#ifndef _JCOM_H_ +#define _JCOM_H_ + +#include <windows.h> +#include <ole2.h> +#include <ole2ver.h> + +//Type for an object-destroyed callback +typedef void (*PFNDESTROYED)(void); +typedef LPVOID * PPVOID; + +// HRESULT errors +#define EHRSINGLE (MAKE_HRESULT(S_FALSE, FACILITY_ITF, 0x201)) + +#ifdef _JDLL +#include "jdll.h" +#define SERVERCLASS IJDLLServer +#else +#include "jexe.h" +#define SERVERCLASS IJEXEServer +#endif + +void setguids(); +int reg(BOOL set, LPSTR keys); + +extern char jmodule[]; +extern char jclass[]; +extern char jversion[]; +extern GUID jclsid; +extern GUID jlibid; +extern GUID jiid; + +class CJServer : public SERVERCLASS + { + protected: + ULONG m_cRef; //Object reference count + LPUNKNOWN m_pUnkOuter; //Controlling unknown + PFNDESTROYED m_pfnDestroy; //To call on closure + ITypeInfo *m_pITINeutral; //Type information + void* m_pjst; // J instance data + + public: + CJServer(LPUNKNOWN, PFNDESTROYED); + ~CJServer(void); + BOOL Init(void); + STDMETHODIMP QueryInterface(REFIID, PPVOID); + STDMETHODIMP_(ULONG) AddRef(void); + STDMETHODIMP_(ULONG) Release(void); + + //IDispatch members + STDMETHODIMP GetTypeInfoCount(UINT *); + STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **); + STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID, DISPID *); + STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *); + + //IJServer functions + STDMETHODIMP Do(BSTR, long*); + STDMETHODIMP Break(long*); + STDMETHODIMP IsBusy(long*); + STDMETHODIMP Get(BSTR, VARIANT*, long*); + STDMETHODIMP Set(BSTR, VARIANT*, long*); + STDMETHODIMP GetM(BSTR, long*, long*, long*, long*, long*); + STDMETHODIMP SetM(BSTR, long*, long*, long*, long*, long*); + STDMETHODIMP ErrorText(long, VARIANT*, long*); + STDMETHODIMP ErrorTextM(long, long*, long*); + STDMETHODIMP Clear(long*); + STDMETHODIMP Show(long, long*); + STDMETHODIMP Log(long, long*); + STDMETHODIMP Transpose(long, long*); + STDMETHODIMP Quit(long*); + STDMETHODIMP ErrorTextB(long, VARIANT*, long*); + STDMETHODIMP GetB(BSTR, VARIANT*, long*); + STDMETHODIMP SetB(BSTR, VARIANT*, long*); + STDMETHODIMP DoR(BSTR, VARIANT*, long*); + }; + +void ObjectDestroyed(void); + +class CJServerFactory : public IClassFactory + { + protected: + ULONG m_cRef; + + public: + CJServerFactory(void); + ~CJServerFactory(void); + + //IUnknown members + STDMETHODIMP QueryInterface(REFIID, PPVOID); + STDMETHODIMP_(ULONG) AddRef(void); + STDMETHODIMP_(ULONG) Release(void); + + //IClassFactory members + STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, PPVOID); + STDMETHODIMP LockServer(BOOL); + }; + +#endif //_JCOM_H_
new file mode 100644 --- /dev/null +++ b/win/jdllcomx.cpp @@ -0,0 +1,968 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +// included in both JEXE and JDLL servers + +// #undef _UNICODE +#include "windows.h" +#include "jdllcom.h" +#include "jdlltype.h" +#define EVLENGTH 9 + +#ifdef _JDLL +void showapp(long b){}; +#else +#include "..\smsrc\isi.h" +extern void* pjst; +static int displayflag = 0; +void showapp(long b); +void shutdown(); +extern BOOL quitflag; +#endif + +extern "C" +{ + int _stdcall JFree(void* jt); + void* _stdcall JInit(); + long runit(WCHAR* p, BOOL f); + int uniflag = -1; // -1 not set (unicode), 0 ansi, 1 unicode + HINSTANCE g_hinst; +#ifdef _JDLL + void touni(char* src, WCHAR* sink); + void toasc(WCHAR* src, LPSTR sink); +#endif +} + +#ifdef _JDLL +extern "C" +{ + JDoType JDo; + JBreakType JBreak; + JIsBusyType JIsBusy; + JGetType JGet; + JSetType JSet; + JGetMType JGetM; + JSetMType JSetM; + JErrorTextType JErrorText; + JErrorTextMType JErrorTextM; + JClearType JClear; + JShowType JShow; + JLogType JLog; + JQuitType JQuit; + JTransposeType JTranspose; + JErrorTextBType JErrorTextB; + JGetBType JGetB; + JSetBType JSetB; + JDoRType JDoR; +} +#else + JDoType *JDo; + JBreakType *JBreak; + JIsBusyType *JIsBusy; + JGetType *JGet; + JSetType *JSet; + JGetMType *JGetM; + JSetMType *JSetM; + JErrorTextType *JErrorText; + JErrorTextMType *JErrorTextM; + JClearType *JClear; + JShowType *JShow; + JLogType *JLog; + JQuitType *JQuit; + JTransposeType *JTranspose; + JErrorTextBType *JErrorTextB; + JGetBType *JGetB; + JSetBType *JSetB; + JDoRType *JDoR; +#endif + +char jclass[100] = ""; +char jversion[100] = "3"; + +GUID jclsid; +GUID jlibid; +GUID jiid; + +void setguids() +{ + char d[50]; + WCHAR duni[50]; + char* p; char* q; + char match[]="Class={"; + HRSRC h= FindResourceA(g_hinst, (LPCSTR)MAKEINTRESOURCE(1), "typelib"); + p=(char*)LockResource(LoadResource(g_hinst, h)); + q=p+SizeofResource(g_hinst, h); + while(p<q) + { + p=(char*)memchr(p,match[0],q-p); + if(!p) return; // bad typelib + if(!memcmp(p, match, strlen(match))) break; + ++p; + } + p+=strlen(match); // start of class name + q=strchr(p, '}'); // end of class name + memcpy(jclass, p, q-p); + jclass[p-q]=0; + p=q+2; // start of version + q=strchr(p, '}'); // end of version + memcpy(jversion, p, q-p); + jversion[q-p]=0; + p=q+1; // { at start of CLSD + q=strchr(p, '}'); // } at end of CLSID + memcpy(d,p,1+q-p); + d[1+q-p]=0; + touni(d, duni); + CLSIDFromString(duni, &jclsid); + jlibid=jclsid; + jiid=jclsid; + jlibid.Data1+=1; + jiid.Data1+=2; +} + +int toascn(WCHAR* src, LPSTR snk, int snklen) +{ + LPSTR p; + + if(!uniflag) + { + p = (LPSTR)src; + if((int)strlen(p) > snklen) return EVLENGTH; + strcpy(snk, p); + return 0; + } + while(*src) + { + if(!--snklen) return EVLENGTH; + *snk++ = (char)*src++; + } + *snk++=0; + return 0; +} + +CJServer::CJServer(LPUNKNOWN pUnkOuter, PFNDESTROYED pfnDestroy) +{ + m_cRef=0; + m_pUnkOuter=pUnkOuter; + m_pfnDestroy=pfnDestroy; + m_pITINeutral=NULL; +#ifndef _JDLL + m_pjst=pjst; // J instance data +#endif + + return; +} + +CJServer::~CJServer(void) +{ + if (NULL!=m_pITINeutral) + { + m_pITINeutral->Release(); + m_pITINeutral=NULL; + } + +#ifdef _JDLL + JFree(m_pjst); // free J instance data + m_pjst = 0; +#endif + + return; +} + +STDMETHODIMP CJServer::QueryInterface(REFIID riid, PPVOID ppv) +{ + *ppv=NULL; + + if (IID_IUnknown==riid || jiid==riid + || IID_IDispatch==riid) + *ppv=this; + + if (NULL!=*ppv) + { + ((LPUNKNOWN)*ppv)->AddRef(); + return NOERROR; + } + return ResultFromScode(E_NOINTERFACE); +} + +STDMETHODIMP_(ULONG) CJServer::AddRef(void) +{ + return ++m_cRef; +} + +STDMETHODIMP_(ULONG) CJServer::Release(void) +{ + if (0L!=--m_cRef) + return m_cRef; + + if (NULL!=m_pfnDestroy) + (*m_pfnDestroy)(); + + delete this; + return 0L; +} + +STDMETHODIMP CJServer::GetTypeInfoCount(UINT *pctInfo) +{ + *pctInfo=1; + return NOERROR; +} + +STDMETHODIMP CJServer::GetTypeInfo(UINT itInfo, LCID lcid, ITypeInfo **ppITypeInfo) +{ + HRESULT hr; + ITypeLib *pITypeLib; + ITypeInfo **ppITI=NULL; + + if (0!=itInfo) return TYPE_E_ELEMENTNOTFOUND; + + if (NULL==ppITypeInfo) return E_POINTER; + + *ppITypeInfo=NULL; + switch (PRIMARYLANGID(lcid)) + { + case LANG_NEUTRAL: + case LANG_ENGLISH: + ppITI=&m_pITINeutral; + break; + + default: + return DISP_E_UNKNOWNLCID; + } + + //Load a type lib if we don't have the information already. + if (NULL==*ppITI) + { + hr=LoadRegTypeLib(jlibid, atoi(jversion), 0, PRIMARYLANGID(lcid), &pITypeLib); + if (FAILED(hr)) return hr; + + //Got the type lib, get type info for the interface we want + hr=pITypeLib->GetTypeInfoOfGuid(jiid, ppITI); + pITypeLib->Release(); + if (FAILED(hr)) return hr; + } + + // the type library is still loaded since we have an ITypeInfo from it. + (*ppITI)->AddRef(); + *ppITypeInfo=*ppITI; + return NOERROR; +} + +STDMETHODIMP CJServer::GetIDsOfNames(REFIID riid + , OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID) +{ + HRESULT hr; + ITypeInfo *pTI; + + if (IID_NULL!=riid) + return ResultFromScode(DISP_E_UNKNOWNINTERFACE); + + //Get the right ITypeInfo for lcid. + hr=GetTypeInfo(0, lcid, &pTI); + if (SUCCEEDED(hr)) + { + hr=DispGetIDsOfNames(pTI, rgszNames, cNames, rgDispID); + pTI->Release(); + } + return hr; +} + +STDMETHODIMP CJServer::Invoke(DISPID dispID, REFIID riid + , LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams + , VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) +{ + HRESULT hr; + ITypeInfo *pTI; + LANGID langID=PRIMARYLANGID(lcid); + + if (IID_NULL!=riid) return DISP_E_UNKNOWNINTERFACE; + hr=GetTypeInfo(0, lcid, &pTI); + if (FAILED(hr)) return hr; + + //This is exactly what DispInvoke does--so skip the overhead. + hr=pTI->Invoke((SERVERCLASS *)this, dispID, wFlags + , pDispParams, pVarResult, pExcepInfo, puArgErr); + + //Exception handling is done within ITypeInfo::Invoke + pTI->Release(); + return hr; +} + +#ifdef _JDLL + +// JDLLServer methods +BOOL CJServer::Init(void) +{ + LPUNKNOWN pIUnknown=this; + + if (NULL!=m_pUnkOuter) pIUnknown=m_pUnkOuter; + m_pjst = JInit(); + return m_pjst ? 1 : 0; +} + +STDMETHODIMP CJServer::Do(BSTR input, long *pr) +{ + char line[1000]; + + *pr = toascn(input, line, sizeof line); + if(*pr) return NOERROR; + *pr = JDo(m_pjst, line); + return NOERROR; +} + +STDMETHODIMP CJServer::DoR(BSTR input, VARIANT* v, long *pr) +{ + char line[1000]; + + *pr = toascn(input, line, sizeof line); + if(*pr) return NOERROR; + *pr = JDoR(m_pjst, line, v); + return NOERROR; +} + + +STDMETHODIMP CJServer::Break(long *pr) +{ + *pr = JBreak(m_pjst); + return NOERROR; +} + +STDMETHODIMP CJServer::IsBusy(long *pr) +{ + *pr = 0; // no kblockstate in dll + return NOERROR; +} + +STDMETHODIMP CJServer::GetM(BSTR name, long* jtype, long* jrank, long* jshape, long* jdata, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JGetM(m_pjst, aname, jtype, jrank, jshape, jdata); + return NOERROR; +} + +STDMETHODIMP CJServer::SetM(BSTR name, long* jtype, long* jrank, long* jshape, long* jdata, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JSetM(m_pjst, aname, jtype, jrank, jshape, jdata); + return NOERROR; +} + +STDMETHODIMP CJServer::ErrorTextM(long ec, long* text, long* pr) +{ + *pr = JErrorTextM(m_pjst, ec, text); + return NOERROR; +} + +#else + +// JEXEServer methods +VARIANT* outputvariant; + +BOOL CJServer::Init(void) +{ + LPUNKNOWN pIUnknown=this; + + if (NULL!=m_pUnkOuter) pIUnknown=m_pUnkOuter; + return 1; +} + +STDMETHODIMP CJServer::Do(BSTR input, long *pr) +{ + *pr = runit(input, !displayflag); + return NOERROR; +} + +STDMETHODIMP CJServer::DoR(BSTR input, VARIANT* v, long* pr) +{ + outputvariant=v; // global kludge to capture output + Do(input, pr); + outputvariant = 0; // turn off capture + return NOERROR; +} + + +STDMETHODIMP CJServer::Break(long *pr) +{ + return NOERROR; +} + +STDMETHODIMP CJServer::IsBusy(long *pr) +{ + *pr = 0; + return NOERROR; +} + +STDMETHODIMP CJServer::GetM(BSTR name, long* jtype, long* jrank, long* jshape, long* jdata, long *pr) +{ + *pr = EDCEXE; + return NOERROR; +} + +STDMETHODIMP CJServer::SetM(BSTR name, long* jtype, long* jrank, long* jshape, long* jdata, long *pr) +{ + *pr = EDCEXE; + return NOERROR; +} + +STDMETHODIMP CJServer::ErrorTextM(long ec, long* text, long* pr) +{ + *pr = EDCEXE; + return NOERROR; +} + +#endif // _JDLL + +// following methods are identical for JEXE and JDLL +STDMETHODIMP CJServer::Get(BSTR name, VARIANT* v, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JGet(m_pjst, aname, v); + return NOERROR; +} + +STDMETHODIMP CJServer::Set(BSTR name, VARIANT* v, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JSet(m_pjst, aname, v); + return NOERROR; +} + +STDMETHODIMP CJServer::GetB(BSTR name, VARIANT* v, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JGetB(m_pjst, aname, v); + return NOERROR; +} + +STDMETHODIMP CJServer::SetB(BSTR name, VARIANT* v, long *pr) +{ + char aname[256]; + + *pr = toascn(name, aname, sizeof aname); + if(*pr) return NOERROR; + *pr = JSetB(m_pjst, aname, v); + return NOERROR; +} + +STDMETHODIMP CJServer::Clear(long* pr) +{ + *pr = JClear(m_pjst); + return NOERROR; +} + +STDMETHODIMP CJServer::ErrorText(long ec, VARIANT* v, long* pr) +{ + *pr = JErrorText(m_pjst, ec, v); + return NOERROR; +} + +STDMETHODIMP CJServer::ErrorTextB(long ec, VARIANT* v, long* pr) +{ + *pr = JErrorTextB(m_pjst, ec, v); + return NOERROR; +} + +STDMETHODIMP CJServer::Transpose(long b, long* pr) +{ + *pr = JTranspose(m_pjst, b); + return NOERROR; +} + +STDMETHODIMP CJServer::Show(long b, long* pr) +{ + showapp(b); + *pr = 0; + return NOERROR; +} + +STDMETHODIMP CJServer::Log(long b, long* pr) +{ +#ifndef _JDLL + displayflag= b; +#endif + *pr = 0; + return NOERROR; +} + +STDMETHODIMP CJServer::Quit(long* pr) +{ +#ifndef _JDLL + quitflag = 1; +#endif + *pr = 0; + return NOERROR; +} + +int SetKeyAndNamedValue(BOOL set, LPSTR keys, LPSTR szK, LPSTR szSubkey, LPSTR szV, LPSTR name) +{ + HKEY hKey; long r; char szk[256]; + + strcpy(szk, szK); + if (szSubkey) + { + strcat(szk, "\\"); + strcat(szk, szSubkey); + } + strcat(keys, "\t"); + strcat(keys, szk); + if(!set) return 0; + + r=RegCreateKeyExA(HKEY_CLASSES_ROOT,szk,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL); + if(ERROR_SUCCESS!=r) return r; + + if(szV) + { + r=RegSetValueExA(hKey, name, 0, REG_SZ, (BYTE *)szV, (UINT)((strlen(szV)+1))); + if(ERROR_SUCCESS!=r) return r; + } + + RegCloseKey(hKey); + return 0; +} + +// return 0 success or winerror.h error code - probably no access +int SetKeyAndValue(BOOL set, LPSTR keys, LPSTR szK, LPSTR szSubkey, LPSTR szV) +{ + HKEY hKey; char szk[256]; long r; + + strcpy(szk, szK); + if (szSubkey) + { + strcat(szk, "\\"); + strcat(szk, szSubkey); + } + strcat(keys, "\t"); + strcat(keys, szk); + if(!set) return 0; + + r=RegCreateKeyExA(HKEY_CLASSES_ROOT,szk,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL); + if(ERROR_SUCCESS!=r) return r; + + if (szV) + { + r=RegSetValueExA(hKey, NULL, 0, REG_SZ, (BYTE *)szV, (UINT)((strlen(szV)+1))); + if(ERROR_SUCCESS!=r) return r; + } + RegCloseKey(hKey); + return 0; +} + +#define INTERCLSID "{00020424-0000-0000-C000-000000000046}" +#define setpath(p,t) strcpy(path,p);strcat(path,t); + +// returns 0 or winerror.h error code +int reg(BOOL set, LPSTR keys) +{ + WCHAR szwork[128]; + char szID[128]; + char szCLSID[128]; + char szLIBID[128]; + char iid[128]; + char szLIBTYPELIBID[128]; + char szdir[512]; + char path[256]; + char inter[256]; + char typetext[256]; + char progidcurtext[256]; + char progidtext[256]; + LPSTR p; + char progidcur[100]; + char module[_MAX_PATH]; + int r; + + GetModuleFileNameA(g_hinst, module, sizeof(module)); + +#ifdef _JDLL + char progid[100] = "JDLLServer"; + char producttext[] = "J DLL Server "; +#else + char progid[100] = "JEXEServer"; + char producttext[] = "J EXE Server "; +#endif + + setguids(); + strcat(progid, jclass); + strcpy(progidcur, progid); + strcat(progidcur, "."); + strcat(progidcur, jversion); + + StringFromGUID2(jclsid, szwork, 128); + toasc(szwork, szID); + strcpy(szCLSID, "CLSID\\"); + strcat(szCLSID, szID); + + StringFromGUID2(jlibid, szwork, 128); + toasc(szwork, szLIBID); + strcpy(szLIBTYPELIBID, "TypeLib\\"); + strcat(szLIBTYPELIBID, szLIBID); + + StringFromGUID2(jiid, szwork, 128); + toasc(szwork, iid); + strcpy(inter, "Interface\\"); + strcat(inter, iid); + + strcpy(szdir, module); + p=strrchr(szdir, '\\'); + *p=0; + keys[0]=0; + + strcpy(progidtext, "Jsoftware : "); + strcat(progidtext, producttext); + strcat(progidtext, jclass); + + strcpy(progidcurtext, progidtext); + strcat(progidcurtext, " (version "); + strcat(progidcurtext, jversion); + strcat(progidcurtext, ")"); + +//HKEY_CLASSES_ROOT\JServer.Object = J Server + r=SetKeyAndValue(set, keys, progid, 0, progidtext); + if(r) return r; + +//HKEY_CLASSES_ROOT\JServer.Object\CLSID = {21EB05E0-1AB3-11cf-A2AC-8FF70874C460} + setpath(progid,"\\CLSID"); + r=SetKeyAndValue(set, keys, path, 0, szID); + if(r) return r; + +//HKEY_CLASSES_ROOT\JServer.Object\CurVer = JServer.Object.1 + setpath(progid,"\\CurVer"); + r=SetKeyAndValue(set, keys, path, 0, progidcur); + if(r) return r; + +//HKEY_CLASSES_ROOT\JServer.Object\NotInsertable + setpath(progid,"\\NotInsertable"); + r=SetKeyAndValue(set, keys, path, 0, 0); + if(r) return r; + + +//HKEY_CLASSES_ROOT\JServer.Object.1 = J Server (Ver 1.0) + r=SetKeyAndValue(set, keys, progidcur, 0, progidcurtext); + if(r) return r; + +//HKEY_CLASSES_ROOT\JServer.Object.1\CLSID = {21EB05E0-1AB3-11cf-A2AC-8FF70874C460} + setpath(progidcur,"\\CLSID"); + r=SetKeyAndValue(set, keys, path, 0, szID); + if(r) return r; + +//HKEY_CLASSES_ROOT\JServer.Object.1\NotInsertable + setpath(progidcur, "\\NotInsertable"); + r=SetKeyAndValue(set, keys, path, 0, 0); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460} = J Server (Ver 1.0) + r=SetKeyAndValue(set, keys, szCLSID, 0, progidcurtext); + if(r) return r; + +#ifdef _JDLL +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\InprocServer32 = d:\dev\jcom\jcom\windebug\jserver.dll + r=SetKeyAndValue(set, keys, szCLSID, "InprocServer32", module); + if(r) return r; + + r=SetKeyAndNamedValue(set, keys, szCLSID, "InprocServer32", "Apartment", "ThreadingModel"); + if(r) return r; +#else +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\LocalServer32 = d:\dev\jcom\jcom\windebug\jserver.dll + r=SetKeyAndValue(set, keys, szCLSID, "LocalServer32", module); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\LocalHandler32 = ole32.dll + r=SetKeyAndValue(set, keys, szCLSID, "LocalHandler32", "ole32.dll"); + if(r) return r; +#endif + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\ProgID = JServer.Object.1 + r=SetKeyAndValue(set, keys, szCLSID, "ProgID", progidcur); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\VersionIndependentProgID = JServer.Object + r=SetKeyAndValue(set, keys, szCLSID, "VersionIndependentProgID", progid); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\TypeLib = {21EB05E1-1AB3-11cf-A2AC-8FF70874C460} + r=SetKeyAndValue(set, keys, szCLSID, "TypeLib", szLIBID); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\Programmable + r=SetKeyAndValue(set, keys, szCLSID, "Programmable", 0); + if(r) return r; + +//HKEY_CLASSES_ROOT\CLSID\{21EB05E0-1AB3-11cf-A2AC-8FF70874C460}\NotInsertable + r=SetKeyAndValue(set, keys, szCLSID, "NotInsertable", 0); + if(r) return r; + +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460} = J Server Type Library + strcpy(typetext, producttext); + strcat(typetext, jclass); + strcat(typetext, " Type Library"); + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, 0, typetext); + if(r) return r; + +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460}\DIR = d:\dev\jcom + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, "DIR", szdir); + if(r) return r; + +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460}\HELPDIR = d:\dev\jcom\jcomhelp + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, "HELPDIR", szdir); + if(r) return r; + +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460}\1.0 = J Server (Ver 1.0) Type Library + setpath(jversion, ".0"); + strcpy(typetext, producttext); + strcat(typetext, jclass); + strcat(typetext, " (version "); + strcat(typetext, jversion); + strcat(typetext, ") Type Library"); + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, path, typetext); + if(r) return r; + +// note: key explicity added so we will be able to delete it +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460}\1.0\0 + setpath(jversion, ".0\\0"); + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, path, module); + if(r) return r; + +//HKEY_CLASSES_ROOT\TypeLib\{21EB05E1-1AB3-11cf-A2AC-8FF70874C460}\1.0\0\win32 = d:\dev\jcom\jserver.tlb + setpath(jversion, ".0\\0\\win32"); + r=SetKeyAndValue(set, keys, szLIBTYPELIBID, path, module); + if(r) return r; + +// interface must be registered for VB <set js as New IJEXEServer> + +//HKEY_CLASSES_ROOT\Interface\{21EB05E2-1AB3-11cf-A2AC-8FF70874C460} = IJEXEServer +#ifdef _JDLL + setpath("IJDLLServer", jclass); +#else + setpath("IJEXEServer", jclass); +#endif + r=SetKeyAndValue(set, keys, inter, 0, path); + if(r) return r; + +//HKEY_CLASSES_ROOT\Interface\{21EB05E2-1AB3-11cf-A2AC-8FF70874C460}\ProxyStubClsid = {00020424-0000-0000-C000-000000000046} + r=SetKeyAndValue(set, keys, inter, "ProxyStubClsid", INTERCLSID); + if(r) return r; + +//HKEY_CLASSES_ROOT\Interface\{21EB05E2-1AB3-11cf-A2AC-8FF70874C460}\ProxyStubClsid32 = {00020424-0000-0000-C000-000000000046} + r=SetKeyAndValue(set, keys, inter, "ProxyStubClsid32", INTERCLSID); + if(r) return r; + +//HKEY_CLASSES_ROOT\Interface\{21EB05E2-1AB3-11cf-A2AC-8FF70874C460}\TypeLib = {21EB05E1-1AB3-11cf-A2AC-8FF70874C460} + r=SetKeyAndValue(set, keys, inter, "TypeLib", szLIBID); + if(r) return r; + return 0; +} + +static ULONG g_cObj=0; // object count +static ULONG g_cLock=0; // server locks + +void ObjectDestroyed(void) +{ + g_cObj--; +#ifndef _JDLL + if(!g_cObj && !g_cLock && quitflag) shutdown(); +#endif + return; +} + + +CJServerFactory::CJServerFactory(void) +{ + m_cRef=0L; + return; +} + +CJServerFactory::~CJServerFactory(void) +{ + return; +} + +STDMETHODIMP CJServerFactory::QueryInterface(REFIID riid, PPVOID ppv) +{ + *ppv=NULL; + if (IID_IUnknown==riid || IID_IClassFactory==riid) *ppv=this; + + if (NULL!=*ppv) + { + ((LPUNKNOWN)*ppv)->AddRef(); + return NOERROR; + } + return E_NOINTERFACE; +} + +STDMETHODIMP_(ULONG) CJServerFactory::AddRef(void) +{ + return ++m_cRef; +} + +STDMETHODIMP_(ULONG) CJServerFactory::Release(void) +{ + if (0!=--m_cRef) return m_cRef; + delete this; + return 0; +} + +STDMETHODIMP CJServerFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, PPVOID ppvObj) +{ + CJServer* pObj; + HRESULT hr; + + *ppvObj=NULL; + if (NULL!=pUnkOuter && IID_IUnknown!=riid) + return ResultFromScode(CLASS_E_NOAGGREGATION); + +#ifdef _JDLL +//! java doesn't seem to unload properly +// repeated refresh of calc applet gets cocreate failure on odd times +// but this change isn't right either +// because it reconnects to the same dll +// kludge java fix is to remove following g_cObj line +// if(g_cObj) return MAKE_HRESULT(S_FALSE, FACILITY_ITF, EHRSINGLE); +#else + if(g_cObj) return MAKE_HRESULT(S_FALSE, FACILITY_ITF, EHRSINGLE); +#endif + pObj=new CJServer(pUnkOuter, ObjectDestroyed); + if (NULL==pObj) return E_OUTOFMEMORY; + if (!pObj->Init()) return E_OUTOFMEMORY; + hr=pObj->QueryInterface(riid, ppvObj); + if (FAILED(hr)) + delete pObj; + else + g_cObj++; + return hr; +} + +STDMETHODIMP CJServerFactory::LockServer(BOOL fLock) +{ + if (fLock) + g_cLock++; + else + g_cLock--; + return NOERROR; +} + +#ifdef _JDLL + +HRESULT APIENTRY DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv) +{ + CJServerFactory *pBF; + HRESULT hr; + + setguids(); + if (jclsid!=rclsid) return E_FAIL; + if (IID_IUnknown!=riid && IID_IClassFactory!=riid) return E_NOINTERFACE; + pBF=new CJServerFactory(); + if (NULL==pBF) return E_OUTOFMEMORY; + hr=pBF->QueryInterface(riid, ppv); + if (FAILED(hr)) delete pBF; + return hr; +} + + +STDAPI DllCanUnloadNow(void) +{ + SCODE sc; + + sc=(0L==g_cObj && 0L==g_cLock) ? S_OK : S_FALSE; + return ResultFromScode(sc); +} + +STDAPI DllRegisterServer(void) +{ + char keys[2000]; + return reg(1, keys); +} + +STDAPI DllUnregisterServer(void) +{ + char keys[2000]; + LPSTR p; + + reg(0, keys); // collect the keys we register + p = keys + strlen(keys); + while(p>keys) + { + p=strrchr(keys, '\t'); + *p=0; + int r=RegDeleteKey(HKEY_CLASSES_ROOT, p+1); + if(ERROR_ACCESS_DENIED==r) return 1; // vista requires admin + } + return 0; +} + +#else + +void shutdown(); + +void toasc(WCHAR* src, LPSTR sink); + +static DWORD dwRegCO; +static BOOL coregflag=0; + +BOOL quitflag=0; + + +int registerserver(void) +{ + char keys[2000]; + return reg(1, keys); +} + +int unregisterserver(void) +{ + char keys[2000]; + LPSTR p; + + reg(0, keys); // collect the keys we register + p = keys + strlen(keys); + while(p>keys) + { + p=strrchr(keys, '\t'); + *p=0; + int r=RegDeleteKeyA(HKEY_CLASSES_ROOT, p+1); + if(ERROR_ACCESS_DENIED==r) return 1; // vista requires admin + } + return 0; +} + +CJServerFactory* pFactory; + +// initexeserver - embedding +BOOL initexeserver() +{ + HRESULT hr; + setguids(); + + pFactory=new CJServerFactory(); + if (NULL==pFactory) return 0; + pFactory->AddRef(); // we hold on to this till we quit + + // REGCLS_MULTIPLEUSE allows multiple users (or reconnections) to same task + hr=CoRegisterClassObject(jclsid, pFactory, CLSCTX_LOCAL_SERVER, + REGCLS_SINGLEUSE, &dwRegCO); + // sometimes REGCLS_SINGLEUSE, sometimes REGCLS_MULTIPLEUSE + if (FAILED(hr)) return FALSE; + coregflag = 1; + return TRUE; +} + +void quitexeserver() +{ + if(!coregflag) return; + CoRevokeClassObject(dwRegCO); + pFactory->Release(); +} + +#endif
new file mode 100644 --- /dev/null +++ b/win/jdlltype.h @@ -0,0 +1,21 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +typedef int (_stdcall JDoType)(void*, LPSTR); +typedef int (_stdcall JBreakType)(void*); +typedef int (_stdcall JIsBusyType)(void*); +typedef int (_stdcall JGetType)(void*, LPSTR, VARIANT*); +typedef int (_stdcall JSetType)(void*, LPSTR, VARIANT*); +typedef int (_stdcall JGetMType)(void*, LPSTR, long*, long*, long*, long*); +typedef int (_stdcall JSetMType)(void*, LPSTR, long*, long*, long*, long*); +typedef int (_stdcall JErrorTextType)(void*, long, VARIANT*); +typedef int (_stdcall JErrorTextMType)(void*, long, long*); +typedef int (_stdcall JClearType)(void*); +typedef int (_stdcall JShowType)(void*, long); +typedef int (_stdcall JLogType)(void*, long); +typedef int (_stdcall JQuitType)(void*, long); +typedef int (_stdcall JTransposeType)(void*, long); +typedef int (_stdcall JErrorTextBType)(void*, long, VARIANT* pbstr); +typedef int (_stdcall JGetBType)(void*, LPSTR, VARIANT*); +typedef int (_stdcall JSetBType)(void*, LPSTR, VARIANT*); +typedef int (_stdcall JDoRType)(void*, LPSTR, VARIANT*);
new file mode 100644 --- /dev/null +++ b/wn.c @@ -0,0 +1,275 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Words: Numeric Input Conversion */ + +#include "j.h" + +#if (SYS & SYS_LINUX) +#include <stdlib.h> +#endif + +#define NUMH(f) B f(J jt,I n,C*s,void*vv) + +/* numd floating point number (double) */ +/* numj complex number */ +/* numx extended precision integer */ +/* nume extended precision floating point number (not used) */ +/* numr rational number */ +/* numq nume or numr */ +/* numbpx 3b12 or 3p12 or 3x12 number */ +/* */ +/* numb subfunction of numbpx */ +/* */ +/* converts a single number and assigns into result pointer */ +/* returns 0 if error, 1 if ok */ + +static NUMH(jtnumd){C c,*t;D*v,x,y; + RZ(n); + v=(D*)vv; + if('-'==*s&&3>n) + if(1==n){*v=inf; R 1;} + else{ + c=*(1+s); + if('-'==c){*v=infm; R 1;} + else if('.'==c){*v=jnan; R 1;} + } + x=strtod(s,&t); + if(t<s+n-1&&'r'==*t){y=strtod(1+t,&t); x=y?x/y:0<x?inf:0>x?infm:0;} + R t>=s+n?(*v=x,1):0; +} + +static NUMH(jtnumj){C*t,*ta;D x,y;Z*v; + v=(Z*)vv; + if(t=memchr(s,'j',n))ta=0; else t=ta=memchr(s,'a',n); + RZ(numd(t?t-s:n,s,&x)); + if(t){t+=ta?2:1; RZ(numd(n+s-t,t,&y));} else y=0; + if(ta){C c; + c=*(1+ta); + RZ(0<=x&&(c=='d'||c=='r')); + if(c=='d')y*=PI/180; if(y<=-P2||P2<=y)y-=P2*jfloor(y/P2); if(0>y)y+=P2; + v->re=y==0.5*PI||y==1.5*PI?0:x*cos(y); v->im=y==PI?0:x*sin(y); + }else{v->re=x; v->im=y;} + R 1; +} + +static NUMH(jtnumi){B neg;C*t;I j;static C*dig="0123456789"; + if(neg='-'==*s){++s; --n; RZ(n);} + RZ(19>=n); + j=0; DO(n, RZ(t=memchr(dig,*s++,10L)); j=10*j+(t-dig);); + RZ(0<=j||neg&&j==IMIN); + *(I*)vv=0>j||!neg?j:-j; + R 1; +} /* called only if SY_64 */ + +static NUMH(jtnumx){A y;B b,c;C d,*t;I j,k,m,*yv;X*v;static C*dig="0123456789"; + v=(X*)vv; + d=*(s+n-1); b='-'==*s; c='x'==d||'r'==d; s+=b; + if('-'==d){RZ(2>=n); RZ(*v=vci(1==n?XPINF:XNINF)); R 1;} + n-=b+c; RZ(m=(n+XBASEN-1)/XBASEN); k=n-XBASEN*(m-1); + GA(y,INT,m,1,0); yv=m+AV(y); + DO(m, j=0; DO(k, RZ(t=memchr(dig,*s++,10L)); j=10*j+(t-dig);); *--yv=b?-j:j; k=XBASEN;); + RZ(*v=yv[m-1]?y:xstd(y)); + R 1; +} + +static X jtx10(J jt,I e){A z;I c,m,r,*zv; + m=1+e/XBASEN; r=e%XBASEN; + GA(z,INT,m,1,0); zv=AV(z); + DO(m-1, *zv++=0;); + c=1; DO(r, c*=10;); *zv=c; + R z; +} /* 10^e as a rational number */ + +static NUMH(jtnume){C*t,*td,*te;I e,ne,nf,ni;Q f,i,*v,x,y; + v=(Q*)vv; + nf=0; i.d=iv1; f.d=iv1; + if(te=memchr(s,'e',n)){ne=n-(te-s)-1; e=strtol(1+te,&t,10); RZ(!*t&&10>ne);} + if(td=memchr(s,'.',n)){nf=te?(te-td)-1:n-(td-s)-1; if(nf)RZ(numx(nf,td+1,&f.n));} + ni=td?td-s:te?te-s:n; RZ(numx(ni,s,&i.n)); + x=i; + if(nf){y.n=iv1; y.d=x10(nf); RE(x='-'==*s?qminus(x,qtymes(f,y)):qplus(x,qtymes(f,y)));} + if(te){if(0>e){y.n=iv1; y.d=x10(-e);}else{y.n=x10(e); y.d=iv1;} RE(x=qtymes(x,y));} + *v=x; + R 1; +} + +static NUMH(jtnumr){C c,*t;I m,p,q;Q*v; + v=(Q*)vv; + m=(t=memchr(s,'r',n))?t-s:n; RZ(numx(m,s,&v->n)); v->d=iv1; + if(t){ + c=s[n-1]; RZ('r'!=c&&'x'!=c); + RZ(numx(n-m-1,s+m+1,&v->d)); + p=*AV(v->n); q=*AV(v->d); + RZ(p!=XPINF&&p!=XNINF||q!=XPINF&&q!=XNINF); + RE(*v=qstd(*v)); + } + R 1; +} + +static NUMH(jtnumq){B b=0;C c,*t; + t=s; DO(n, c=*t++; if(c=='e'||c=='.'){b=1; break;}); + R b?nume(n,s,vv):numr(n,s,vv); +} + +static Z zpi={PI,0}; + +static B jtnumb(J jt,I n,C*s,Z*v,Z b){A c,d,y;I k; + static C dig[]="0123456789abcdefghijklmnopqrstuvwxyz";I m=strlen(dig); + if(!n){*v=zeroZ; R 1;} + RZ(d=indexof(str(m,dig),str(n,s))); + RZ(all0(eps(sc(m),d))); + k=sizeof(Z); + GA(c,CMPX,1,0,0); MC(AV(c),&b,k); RZ(y=base2(c,d)); MC(v,AV(y),k); + R 1; +} + +static NUMH(jtnumbpx){B ne,ze;C*t,*u;I k,m;Z b,p,q,*v,x,y; + v=(Z*)vv; + if(t=memchr(s,'b',n)){ + RZ(numbpx(t-s,s,&b)); + ++t; if(ne='-'==*t)++t; + m=k=n+s-t; if(u=memchr(t,'.',m))k=u-t; + RZ(ne||m>(1&&u)); + RZ(numb(k,t,&p,b)); + if(u){ + k=m-(1+k); + if(ze=!(b.re||b.im))b.re=1; + RZ(numb(k,1+u,&q,b)); + if(ze){if(q.re)p.re=inf;} else{DO(k,q=zdiv(q,b);); p=zplus(p,q);} + } + *v=p; if(ne){v->re=-v->re; v->im=-v->im;} + R 1; + } + if(t=memchr(s,'p',n))u=0; else t=u=memchr(s,'x',n); + if(!t)R numj(n,s,v); + RZ(numj(t-s,s,&x)); ++t; RZ(numj(n+s-t,t,&y)); + if(u)*v=ztymes(x,zexp(y)); else *v=ztymes(x,zpow(zpi,y)); + R 1; +} + +/* (n,s) string containing the vector constant */ +/* j: 1 iff contains 1j2 or 1ad2 or 1ar2 */ +/* b: 1 iff has 1b1a or 1p2 or 1x2 (note: must handle 1j3b4) */ +/* x: 1 iff contains 123x */ +/* q: 1 iff contains 3r4 */ +/* ii: 1 iff integer (but not x) */ + +static void jtnumcase(J jt,I n,C*s,B*b,B*j,B*x,B*q,B*ii){B e;C c; + *x=*q=*ii=0; + *j=memchr(s,'j',n)||memchr(s,'a',n); + *b=memchr(s,'b',n)||memchr(s,'p',n); + if(!*j&&!*b){ +#if SY_64 + *ii=1; +#endif + if(memchr(s,'x',n)){*b=*x=1; *ii=0;} + if(memchr(s,'r',n)){*q=1; *ii=0;} + if(!*x&&!*q&!*ii)R; + DO(n, c=s[i]; e=!s[1+i]; if(c=='.'||c=='e'||c=='x'&&!e){*x=*q=*ii=0; R;}); +}} + +A jtconnum(J jt,I n,C*s){PROLOG;A y,z;B b,(*f)(),ii,j,p=1,q,x;C c,*v;I d=0,e,k,m,t,*yv; + if(1==n) {if(k=s[0]-'0',0<=k&&k<=9)R num[ k]; else R ainf;} + else if(2==n&&CSIGN==*s){if(k=s[1]-'0',0<=k&&k<=9)R num[-k];} + RZ(y=str(1+n,s)); s=v=CAV(y); s[n]=0; + GA(y,INT,1+n,1,0); yv=AV(y); + DO(n, c=*v; *v++=c=c==CSIGN?'-':c==CTAB||c==' '?C0:c; b=C0==c; if(p!=b)yv[d++]=i; p=b;); + if(d%2)yv[d++]=n; m=d/2; + numcase(n,s,&b,&j,&x,&q,&ii); + f=q?jtnumq:x?jtnumx:b||j?jtnumbpx:ii?jtnumi:jtnumd; + t=q?RAT :x?XNUM :b||j?CMPX :ii?INT :FL; k=bp(t); + GA(z,t,m,1!=m,0); v=CAV(z); + if(ii){ + DO(m, d=i+i; e=yv[d]; if(!numi(yv[1+d]-e,e+s,v)){ii=0; break;} v+=k;); + if(!ii){t=FL; f=jtnumd; GA(z,t,m,1!=m,0); v=CAV(z);} + } + if(!ii)DO(m, d=i+i; e=yv[d]; ASSERT(f(jt,yv[1+d]-e,e+s,v),EVILNUM); v+=k;); + if(t&FL+CMPX)RZ(z=cvt0(z)); + EPILOG(bcvt(0,z)); +} + + +#define EXEC2F(f,f1,t,T) \ + A f(J jt,A a,A w,I n,I m,I c){A z;B b;C d,*u,*uu,*x,*y;I i,j,k,mc,r;T a0,*zv; \ + i=0; mc=m*c; u=CAV(w); y=u+n; j=c; uu=u+AN(w); if(mc)*(uu-1)=' '; \ + r=AR(w)-(1==c); r=MAX(0,r); \ + GA(z,t,mc,r,AS(w)); if(1<r&&1!=c)*(AS(z)+r-1)=c; zv=(T*)AV(z); \ + RZ(a=cvt(t,a)); a0=*(T*)AV(a); \ + while(i<mc){ \ + while(u<uu&&C0==*u)++u; \ + while(u>=y){while(i<j)zv[i++]=a0; j+=c; y+=n; if(i==mc)R z;} \ + x=strchr(u,C0); if(x<uu)k=x-u; else{*(uu-1)=C0; k=uu-1-u;} \ + b=','==u[0]||','==u[k-1]; \ + x=u; DO(k, d=u[i]; if(','!=d)*x++=d==CSIGN?'-':d;); *x=C0; \ + if(b||!f1(x-u,u,i+zv))zv[i]=a0; \ + ++i; u+=1+k; \ + } \ + R z; \ + } + +static EXEC2F(jtexec2x,numx, XNUM,X) /* note: modifies argument w */ +static EXEC2F(jtexec2q,numq, RAT, Q) +static EXEC2F(jtexec2z,numbpx,CMPX,Z) + +static A jtexec2r(J jt,A a,A w,I n,I m,I c){A z;B b,e;C d,*u,*uu,*v,*x,*y;D a0,*zv;I i,j,mc,r; + i=0; mc=m*c; u=CAV(w); y=u+n; j=c; uu=u+AN(w); + r=AR(w)-(1==c); r=MAX(0,r); + GA(z,FL,mc,r,AS(w)); if(1<r&&1!=c)*(AS(z)+r-1)=c; zv=DAV(z); + RZ(a=cvt(FL,a)); a0=*DAV(a); + while(i<mc){ + while(u<uu&&C0==*u)++u; + while(u>=y){while(i<j)zv[i++]=a0; j+=c; y+=n; if(i==mc)R z;} + zv[i]=strtod(u,&v); + switch(*v){ + case C0: + i++; u=v; continue; + case ',': + b=u==v; x=v; + while(d=*++v)if(','!=d)*x++=d; + if(b||','==*(v-1)){zv[i++]=a0; u=v;}else while(v>x)*x++=C0; + continue; + case '-': + e=u==v; v++; d=*v++; b=e&&C0==*v; + if (e&& C0==d){zv[i++]=inf; u=v;} + else if(b&&'-'==d){zv[i++]=infm; u=v;} + else if(b&&'.'==d){zv[i++]=jnan; u=v;} + else{zv[i++]=a0; --v; while(C0!=*v++); u=v;} + continue; + case 'a': case 'b': case 'j': case 'p': case 'r': case 'x': + if(u!=v)R exec2z(a,w,n,m,c); + default: + zv[i++]=a0; while(C0!=*++v); u=v; + }} + R z; +} + +F2(jtexec2){A z;B b,ii,j,p,q,x;C d,*v;I at,c,i,k,m,n,r,*s; + RZ(a&&w); + ASSERT(!AR(a),EVRANK); + at=AT(a); + ASSERT(at&NUMERIC,EVDOMAIN); + if(!(LIT&AT(w)))RZ(w=toc1(0,w)); + m=n=c=0; r=AR(w); + if(!r||*(AS(w)+r-1)){ + RZ(w=irs2(w,chr[' '],0L,1L,0L,jtover)); /* will be modified in place */ + v=CAV(w); r=AR(w); s=AS(w); n=s[r-1]; m=prod(r-1,s); + for(i=0;i<m;++i){I j; + b=1; k=0; + for(j=0;j<n;++j){ + p=b; d=*v; b=' '==d; + switch(d){ + case ' ': *v=C0; break; + case CSIGN: *v='-'; + } + ++v; if(p>b)++k; + } + if(k>c)c=k; + }} + numcase(m*n,CAV(w),&b,&j,&x,&q,&ii); + if(at&CMPX) z=cvt0(exec2z(a,w,n,m,c)); + else if(q) z= exec2q(a,w,n,m,c); + else if(x&&at&B01+INT+XNUM)z= exec2x(a,w,n,m,c); + else z=cvt0(exec2r(a,w,n,m,c)); + R bcvt(0,z); +}
new file mode 100644 --- /dev/null +++ b/ws.c @@ -0,0 +1,82 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Words: Spelling */ + +#include "j.h" +#include "w.h" + + +static C spell[3][70]={ + '=', '<', '>', '_', '+', '*', '-', '%', + '^', '$', '~', '|', '.', ':', ',', ';', + '#', '@', '/', CBSLASH, '[', ']', '{', '}', + '`', CQQ, '&', '!', '?', 'a', 'A', 'b', + 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'H', + 'i', 'I', 'j', 'L', 'm', 'M', 'n', 'o', + 'p', 'q', 'r', 's', 'S', 't', 'T', 'u', + 'v', 'x', 'y', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', 0, + + CASGN, CFLOOR, CCEIL, 1, CPLUSDOT,CSTARDOT,CNOT, CDOMINO, + CLOG, CSPARSE, CNUB, CREV, CEVEN, COBVERSE,CCOMDOT, CCUT, + CBASE, CATDOT, CSLDOT, CBSDOT, CLEV, CDEX, CTAKE, CDROP, + CGRDOT, CEXEC, CUNDER, CFIT, CQRYDOT, CALP, CATOMIC, CBDOT, + CCDOT, CCYCLE, CDDOT, CDCAP, CEPS, CEBAR, CFIX, CHGEOM, + CIOTA, CICAP, CJDOT, CLDOT, CMDOT, CMCAP, CNDOT, CCIRCLE, + CPOLY, 1, CRDOT, 1, 1, CTDOT, CTCAP, CUDOT, + CVDOT, CXDOT, CYDOT, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, + + CGASGN, CLE, CGE, CFCONS, CPLUSCO, CSTARCO, CMATCH, CROOT, + CPOWOP, CSELF, CNE, CCANT, CODD, CADVERSE,CLAMIN, CWORDS, + CABASE, CATCO, CGRADE, CDGRADE, CCAP, CIDA, CTAIL, CCTAIL, + CGRCO, CTHORN, CAMPCO, CIBEAM, CQRYCO, CACE, 1, 1, + 1, 1, 1, CDCAPCO, 1, 1, 1, 1, + CICO, 1, 1, CLCAPCO, 1, 1, 1, 1, + CPCO, CQCO, 1, CSCO, CSCAPCO, CTCO, 1, CUCO, + 1, CXCO, 1, CFCONS, CFCONS, CFCONS, CFCONS, CFCONS, + CFCONS, CFCONS, CFCONS, CFCONS, CFCONS, 0, +}; + +static C sp3[4][5]={ + CFETCH, CEMEND, CPDERIV, CUNDCO, 0, + '{', '}', 'p', '&', 0, + CESC2, CESC2, CESC1, CESC1, 0, + CESC2, CESC2, CESC1, CESC2, 0, +}; /* trigraphs */ + +C spellin(I n,C*s){C c,d,p=*s,*t;I j; + switch(n){ + case 1: + R p; + case 2: + c=s[1]; j=c==CESC1?1:c==CESC2?2:0; + R j&&(t=(C*)strchr(spell[0],p)) ? spell[j][t-spell[0]] : 0; + case 3: + c=s[1]; d=s[2]; + if(p==CSIGN&&d==CESC2&&'1'<=c&&c<='9')R CFCONS; + if(t=(C*)strchr(sp3[1],p)){j=t-sp3[1]; R c==sp3[2][j]&&d==sp3[3][j]?sp3[0][j]:0;} + default: /* note: fall through */ + R 0; +}} + +void spellit(C c,C*s){C*q;I k; + s[1]=s[2]=0; + if(0<=c&&(UC)c<=127) s[0]=c; + else if(q=(C*)strchr(spell[1],c)){k=q-spell[1]; s[0]=spell[0][k]; s[1]=CESC1;} + else if(q=(C*)strchr(spell[2],c)){k=q-spell[2]; s[0]=spell[0][k]; s[1]=CESC2;} + else if(q=(C*)strchr(sp3[0], c)){k=q-sp3[0]; s[0]=sp3[1][k]; s[1]=sp3[2][k]; s[2]=sp3[3][k];} + else if(CAMIP==c)s[0]='}'; + else if(CAPIP==c)s[0]=','; +} /* spell out ID c in s */ + +A jtspella(J jt,A w){C c,s[3];V*v; + RZ(w); + v=VAV(w); c=v->id; + if(c==CFCONS)R over(thorn1(v->h),chr[':']); + spellit(c,s); + R str(s[2]?3L:s[1]?2L:1L,s); +} + +A jtspellout(J jt,C c){C s[3]; spellit(c,s); R str(s[2]?3L:s[1]?2L:1L,s);}
new file mode 100644 --- /dev/null +++ b/x.c @@ -0,0 +1,241 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos aka Foreign: External, Experimental, & Extra */ + +#include "j.h" +#include "x.h" + +#define SDERIV(id,f1,f2,m,l,r) \ + fdef(id,VERB,secf1,secf2,a,w,v2((I)(f1?f1:jtdomainerr1),(I)(f2?f2:jtdomainerr2)),0L,(I)m,(I)l,(I)r) + +#define SDERI2(id,f1,f2,m,l,r) \ + fdef(id,VERB,f1, secf2,a,w,v2((I)(f1?f1:jtdomainerr1),(I)(f2?f2:jtdomainerr2)),0L,(I)m,(I)l,(I)r) + + +static DF1(secf1){A h=VAV(self)->h; ASSERT(!jt->seclev,EVSECURE); R CALL1((AF)* AV(h) , w,self);} +static DF2(secf2){A h=VAV(self)->h; ASSERT(!jt->seclev,EVSECURE); R CALL2((AF)*(1+AV(h)),a,w,self);} + +static DF1(jtfindrange){I base,n,top; + RZ(w); + n=AN(w); + irange(n,AV(w),&base,&top); + R v2(base,top); +} + +F2(jtforeign){I p,q; + RZ(a&&w); + p=i0(a); q=i0(w); RE(0); + if(11==p)R fdef(CIBEAM,VERB, jtwd,0L, a,w,0L, 0L, 1L,RMAX,RMAX); + if(q<0||XCC<=q)R CDERIV(CIBEAM, 0,0, RMAX,RMAX,RMAX); + switch(XC(p,q)){ + case XC(0, 0): + case XC(0,100): R SDERI2(CIBEAM, jtscm00, jtscm002, RMAX,RMAX,RMAX); + case XC(0, 1): + case XC(0,101): R SDERI2(CIBEAM, jtscm01, jtscm012, RMAX,RMAX,RMAX); + case XC(0, 10): + case XC(0,110): R SDERI2(CIBEAM, jtscm10, jtscm102, RMAX,RMAX,RMAX); + case XC(0, 11): + case XC(0,111): R SDERI2(CIBEAM, jtscm11, jtscm112, RMAX,RMAX,RMAX); + case XC(0,2): R SDERI2(CIBEAM, jtsct1, jtsct2, RMAX,RMAX,RMAX); + case XC(0,3): R SDERI2(CIBEAM, jtscz1, jtscz2, RMAX,RMAX,RMAX); + + case XC(1,0): R SDERIV(CIBEAM, jtjdir, 0, RMAX,0, 0 ); + case XC(1,1): R SDERIV(CIBEAM, jtjfread, 0, 0, 0, 0 ); + case XC(1,2): R SDERIV(CIBEAM, 0, jtjfwrite, 0, RMAX,0 ); + case XC(1,3): R SDERIV(CIBEAM, 0, jtjfappend, 0, RMAX,0 ); + case XC(1,4): R SDERIV(CIBEAM, jtjfsize, 0, 0, 0, 0 ); + case XC(1,5): R SDERIV(CIBEAM, jtjmkdir, 0, 0, 0, 0 ); + case XC(1,6): R SDERIV(CIBEAM, jtjfatt1, jtjfatt2, 0, 1, 0 ); + case XC(1,7): R SDERIV(CIBEAM, jtjfperm1, jtjfperm2, 0, 1, 0 ); + + case XC(1,11): R SDERIV(CIBEAM, jtjiread, 0, 1, 0, 0 ); + case XC(1,12): R SDERIV(CIBEAM, 0, jtjiwrite, 0, RMAX,1 ); + case XC(1,20): R SDERIV(CIBEAM, jtjfiles, 0, RMAX,0, 0 ); + case XC(1,21): R SDERIV(CIBEAM, jtjopen, 0, 0, 0, 0 ); + case XC(1,22): R SDERIV(CIBEAM, jtjclose, 0, 0, 0, 0 ); + +#if (SYS & SYS_DOS+SYS_MACINTOSH) + case XC(1,30): R SDERIV(CIBEAM, jtjlocks, 0, RMAX,0, 0 ); + case XC(1,31): R SDERIV(CIBEAM, jtjlock, 0, 1, 0, 0 ); + case XC(1,32): R SDERIV(CIBEAM, jtjunlock, 0, 1, 0, 0 ); +#endif + + case XC(1,43): R CDERIV(CIBEAM, jtpathcwd, 0, RMAX,0, 0 ); + case XC(1,44): R CDERIV(CIBEAM, jtpathchdir, 0, RMAX,0, 0 ); + case XC(1,46): R CDERIV(CIBEAM, jtpathdll, 0, RMAX,0, 0 ); + + case XC(1,55): R SDERIV(CIBEAM, jtjferase, 0, 0, 0, 0 ); + + case XC(2,0): R SDERIV(CIBEAM, jthost, 0, 1, 0, 0 ); + case XC(2,1): R SDERIV(CIBEAM, jthostne, 0, 1, 0, 0 ); + case XC(2,2): R SDERIV(CIBEAM, jthostio, 0, 1, 0, 0 ); + case XC(2,3): R SDERIV(CIBEAM, jtjwait, 0, 0, 0, 0 ); + case XC(2,5): R SDERIV(CIBEAM, jtjgetenv, 0, 1, 0, 0 ); + case XC(2,6): R SDERIV(CIBEAM, jtjgetpid, 0, 1, 0, 0 ); + case XC(2,55): R SDERIV(CIBEAM, jtjoff, 0, RMAX,0, 0 ); + + case XC(3,0): R CDERIV(CIBEAM, jtstype, 0, RMAX,0, 0 ); + case XC(3,1): R CDERIV(CIBEAM, jtbinrep1, jtbinrep2, RMAX,RMAX,RMAX); + case XC(3,2): R CDERIV(CIBEAM, jtunbin, 0, RMAX,0, 0 ); + case XC(3,3): R CDERIV(CIBEAM, jthexrep1, jthexrep2, RMAX,RMAX,RMAX); + case XC(3,4): R CDERIV(CIBEAM, 0, jtic2, 0, RMAX,RMAX); + case XC(3,5): R CDERIV(CIBEAM, 0, jtfc2, 0, RMAX,RMAX); + case XC(3,6): R CDERIV(CIBEAM, jtlock1, jtlock2, RMAX,RMAX,RMAX); + case XC(3,7): R CDERIV(CIBEAM, jtbit1, jtbit2, RMAX,RMAX,RMAX); + + case XC(4,0): R CDERIV(CIBEAM, jtnc, 0, 0, 0, 0 ); + case XC(4,1): R CDERIV(CIBEAM, jtnl1, jtnl2, RMAX,RMAX,RMAX); + case XC(4,3): R CDERIV(CIBEAM, jtsnl, 0, RMAX,0, 0 ); + case XC(4,4): R CDERIV(CIBEAM, jtscind, 0, 0, 0, 0 ); + case XC(4,5): R CDERIV(CIBEAM, jtnch, 0, RMAX,0, 0 ); + case XC(4,55): R CDERIV(CIBEAM, jtex, 0, 0, 0, 0 ); + + case XC(5,0): R fdef(CIBEAM,ADV, jtfxx,0L, a,w,0L, 0L, 0L, 0L, 0L ); + case XC(5,1): R CDERIV(CIBEAM, jtarx, 0, 0, 0, 0 ); + case XC(5,2): R CDERIV(CIBEAM, jtdrx, 0, 0, 0, 0 ); + case XC(5,4): R CDERIV(CIBEAM, jttrx, 0, 0, 0, 0 ); + case XC(5,5): R CDERIV(CIBEAM, jtlrx, 0, 0, 0, 0 ); + case XC(5,6): R CDERIV(CIBEAM, jtprx, 0, 0, 0, 0 ); + case XC(5,7): R CDERIV(CIBEAM, 0, jtxrx, 0, 0, 0 ); + case XC(5,30): R CDERIV(CIBEAM, 0, jtoutstr, 0, RMAX,RMAX); + + case XC(6,0): R CDERIV(CIBEAM, jtts0, 0, RMAX,0, 0 ); + case XC(6,1): R CDERIV(CIBEAM, jttss, 0, RMAX,0, 0 ); + case XC(6,2): R CDERIV(CIBEAM, jttsit1, jttsit2, 1, 0, 1 ); + case XC(6,3): R CDERIV(CIBEAM, jtdl, 0, 0, 0, 0 ); + case XC(6,4): R CDERIV(CIBEAM, jtparsercalls,0, RMAX,0, 0 ); + case XC(6,8): R CDERIV(CIBEAM, jtqpfreq, 0, RMAX,0, 0 ); + case XC(6,9): R CDERIV(CIBEAM, jtqpctr, 0, RMAX,0, 0 ); + case XC(6,10): R CDERIV(CIBEAM, jtpmarea1, jtpmarea2, RMAX,RMAX,RMAX); + case XC(6,11): R CDERIV(CIBEAM, jtpmunpack, 0, RMAX,0, 0 ); + case XC(6,12): R CDERIV(CIBEAM, jtpmctr, 0, RMAX,0, 0 ); + case XC(6,13): R CDERIV(CIBEAM, jtpmstats, 0, RMAX,0, 0 ); + + case XC(7,0): R CDERIV(CIBEAM, jtsp, 0, RMAX,0, 0 ); + case XC(7,2): R CDERIV(CIBEAM, jtspit, 0, 1, 0, 0 ); + case XC(7,3): R CDERIV(CIBEAM, jtspcount, 0, RMAX,0, 0 ); + case XC(7,5): R CDERIV(CIBEAM, jtspfor, 0, 0, 0, 0 ); + case XC(7,6): R CDERIV(CIBEAM, jtspforloc, 0, 0, 0, 0 ); + + case XC(8,0): R CDERIV(CIBEAM, jtfmt01, jtfmt02, RMAX,RMAX,RMAX); + case XC(8,1): R CDERIV(CIBEAM, jtfmt11, jtfmt12, RMAX,RMAX,RMAX); + case XC(8,2): R CDERIV(CIBEAM, jtfmt21, jtfmt22, RMAX,RMAX,RMAX); + + case XC(9,0): R CDERIV(CIBEAM, jtrngseedq, 0, RMAX,0, 0 ); + case XC(9,1): R CDERIV(CIBEAM, jtrngseeds, 0, RMAX,0, 0 ); + case XC(9,2): R CDERIV(CIBEAM, jtdispq, 0, RMAX,0, 0 ); + case XC(9,3): R CDERIV(CIBEAM, jtdisps, 0, RMAX,0, 0 ); + case XC(9,6): R CDERIV(CIBEAM, jtboxq, 0, RMAX,0, 0 ); + case XC(9,7): R CDERIV(CIBEAM, jtboxs, 0, RMAX,0, 0 ); + case XC(9,8): R CDERIV(CIBEAM, jtevmq, 0, RMAX,0, 0 ); + case XC(9,9): R CDERIV(CIBEAM, jtevms, 0, RMAX,0, 0 ); + case XC(9,10): R CDERIV(CIBEAM, jtppq, 0, RMAX,0, 0 ); + case XC(9,11): R CDERIV(CIBEAM, jtpps, 0, RMAX,0, 0 ); + case XC(9,12): R CDERIV(CIBEAM, jtsysq, 0, RMAX,0, 0 ); + case XC(9,14): R CDERIV(CIBEAM, jtversq, 0, RMAX,0, 0 ); + case XC(9,16): R CDERIV(CIBEAM, jtposq, 0, RMAX,0, 0 ); + case XC(9,17): R CDERIV(CIBEAM, jtposs, 0, RMAX,0, 0 ); + case XC(9,18): R CDERIV(CIBEAM, jtctq, 0, RMAX,0, 0 ); + case XC(9,19): R CDERIV(CIBEAM, jtcts, 0, RMAX,0, 0 ); + case XC(9,20): R CDERIV(CIBEAM, jtmmaxq, 0, RMAX,0, 0 ); + case XC(9,21): R CDERIV(CIBEAM, jtmmaxs, 0, RMAX,0, 0 ); + case XC(9,24): R CDERIV(CIBEAM, jtseclevq, 0, RMAX,0, 0 ); + case XC(9,25): R CDERIV(CIBEAM, jtseclevs, 0, RMAX,0, 0 ); + case XC(9,26): R CDERIV(CIBEAM, jtiepq, 0, RMAX,0, 0 ); + case XC(9,27): R CDERIV(CIBEAM, jtieps, 0, RMAX,0, 0 ); + case XC(9,28): R CDERIV(CIBEAM, jtiepdoq, 0, RMAX,0, 0 ); + case XC(9,29): R CDERIV(CIBEAM, jtiepdos, 0, RMAX,0, 0 ); + case XC(9,32): R CDERIV(CIBEAM, jttlimq, 0, RMAX,0, 0 ); + case XC(9,33): R CDERIV(CIBEAM, jttlims, 0, RMAX,0, 0 ); + case XC(9,34): R CDERIV(CIBEAM, jtassertq, 0, RMAX,0, 0 ); + case XC(9,35): R CDERIV(CIBEAM, jtasserts, 0, RMAX,0, 0 ); + case XC(9,36): R CDERIV(CIBEAM, jtoutparmq, 0, RMAX,0, 0 ); + case XC(9,37): R CDERIV(CIBEAM, jtoutparms, 0, RMAX,0, 0 ); + case XC(9,38): R CDERIV(CIBEAM, jtlocsizeq, 0, RMAX,0, 0 ); + case XC(9,39): R CDERIV(CIBEAM, jtlocsizes, 0, RMAX,0, 0 ); + case XC(9,40): R CDERIV(CIBEAM, jtretcommq, 0, RMAX,0, 0 ); + case XC(9,41): R CDERIV(CIBEAM, jtretcomms, 0, RMAX,0, 0 ); + case XC(9,42): R CDERIV(CIBEAM, jtrngselectq, 0, RMAX,0, 0 ); + case XC(9,43): R CDERIV(CIBEAM, jtrngselects, 0, RMAX,0, 0 ); + case XC(9,44): R CDERIV(CIBEAM, jtrngstateq, 0, RMAX,0, 0 ); + case XC(9,45): R CDERIV(CIBEAM, jtrngstates, 0, RMAX,0, 0 ); + case XC(9,46): R CDERIV(CIBEAM, jtbreakfnq, 0, RMAX,0, 0 ); + case XC(9,47): R CDERIV(CIBEAM, jtbreakfns, 0, RMAX,0, 0 ); + case XC(9,48): R CDERIV(CIBEAM, jtdotnamesq, 0, RMAX,0, 0 ); + case XC(9,49): R CDERIV(CIBEAM, jtdotnamess, 0, RMAX,0, 0 ); + +/* case XC(11,*): handled at beginning */ +/* case XC(12,*): reserved for D.H. Steinbrook tree stuff */ + + case XC(13,0): R CDERIV(CIBEAM, jtdbc, 0, RMAX,0, 0 ); + case XC(13,1): R CDERIV(CIBEAM, jtdbstack, 0, RMAX,0, 0 ); + case XC(13,2): R CDERIV(CIBEAM, jtdbstopq, 0, RMAX,0, 0 ); + case XC(13,3): R CDERIV(CIBEAM, jtdbstops, 0, RMAX,0, 0 ); + case XC(13,4): R CDERIV(CIBEAM, jtdbrun, 0, RMAX,0, 0 ); + case XC(13,5): R CDERIV(CIBEAM, jtdbnext, 0, RMAX,0, 0 ); + case XC(13,6): R CDERIV(CIBEAM, jtdbret, 0, RMAX,0, 0 ); + case XC(13,7): R CDERIV(CIBEAM, jtdbjump, 0, RMAX,0, 0 ); + case XC(13,8): R CDERIV(CIBEAM, jtdbsig1, jtdbsig2, RMAX,RMAX,RMAX); + case XC(13,9): R CDERIV(CIBEAM, jtdbrr1, jtdbrr2, RMAX,RMAX,RMAX); + case XC(13,11): R CDERIV(CIBEAM, jtdberr, 0, RMAX,0, 0 ); + case XC(13,12): R CDERIV(CIBEAM, jtdbetx, 0, RMAX,0, 0 ); + case XC(13,13): R CDERIV(CIBEAM, jtdbcall, 0, RMAX,0, 0 ); + case XC(13,14): R CDERIV(CIBEAM, jtdbtrapq, 0, RMAX,0, 0 ); + case XC(13,15): R CDERIV(CIBEAM, jtdbtraps, 0, RMAX,0, 0 ); + case XC(13,17): R CDERIV(CIBEAM, jtdbq, 0, RMAX,0, 0 ); + case XC(13,18): R CDERIV(CIBEAM, jtdbstackz, 0, RMAX,0, 0 ); + case XC(13,19): R CDERIV(CIBEAM, jtdbcutback, 0, RMAX,0, 0 ); + case XC(13,20): R CDERIV(CIBEAM, jtdbstepover1,jtdbstepover2,RMAX,RMAX,RMAX); + case XC(13,21): R CDERIV(CIBEAM, jtdbstepinto1,jtdbstepinto2,RMAX,RMAX,RMAX); + case XC(13,22): R CDERIV(CIBEAM, jtdbstepout1, jtdbstepout2, RMAX,RMAX,RMAX); + + case XC(13,80): R CDERIV(CIBEAM, jtfindrange, 0, RMAX,0, 0 ); + + case XC(15,0): R SDERIV(CIBEAM, 0, jtcd, 0, 1L, 1L ); + case XC(15,1): R SDERIV(CIBEAM, jtmemr, 0, RMAX,0, 0 ); + case XC(15,2): R SDERIV(CIBEAM, 0, jtmemw, 0, RMAX,RMAX); + case XC(15,3): R SDERIV(CIBEAM, jtmema, 0, RMAX,0, 0 ); + case XC(15,4): R SDERIV(CIBEAM, jtmemf, 0, RMAX,0, 0 ); + case XC(15,5): R SDERIV(CIBEAM, jtcdf, 0, RMAX,0, 0 ); + case XC(15,6): R SDERIV(CIBEAM, jtdllsymget, 0, RMAX,0, 0 ); + case XC(15,7): R SDERIV(CIBEAM, jtdllsymset, 0, RMAX,0, 0 ); + case XC(15,8): R SDERIV(CIBEAM, jtgh15, 0, RMAX,0, 0 ); + case XC(15,9): R SDERIV(CIBEAM, jtfh15, 0, RMAX,0, 0 ); + case XC(15,10): R SDERIV(CIBEAM, jtcder, 0, RMAX,0, 0 ); + case XC(15,11): R SDERIV(CIBEAM, jtcderx, 0, RMAX,0, 0 ); + case XC(15,12): R CDERIV(CIBEAM, jtsmmblks, 0, RMAX,0, 0 ); + case XC(15,13): R CDERIV(CIBEAM, jtcallback, 0, RMAX,0, 0 ); + case XC(15,14): R SDERIV(CIBEAM, jtdllsymdat, 0, RMAX,0, 0 ); + case XC(15,16): R SDERIV(CIBEAM, jtnfes, 0, RMAX,0, 0 ); + case XC(15,17): R SDERIV(CIBEAM, jtcallbackx, 0, RMAX,0, 0 ); + case XC(15,18): R SDERIV(CIBEAM, jtnfeoutstr, 0, RMAX,0, 0 ); + + case XC(18,0): R CDERIV(CIBEAM, jtlocnc, 0, 0, 0, 0 ); + case XC(18,1): R CDERIV(CIBEAM, jtlocnl1, jtlocnl2, RMAX,RMAX,RMAX); + case XC(18,2): R CDERIV(CIBEAM, jtlocpath1, jtlocpath2, 0, 1, 0 ); + case XC(18,3): R CDERIV(CIBEAM, jtloccre1, jtloccre2, RMAX,0, RMAX); + case XC(18,4): R CDERIV(CIBEAM, jtlocswitch, 0, RMAX,0, 0 ); + case XC(18,5): R CDERIV(CIBEAM, jtlocname, 0, RMAX,0, 0 ); + case XC(18,30): R CDERIV(CIBEAM, jtlocmap, 0, RMAX,0, 0 ); + case XC(18,31): R CDERIV(CIBEAM, jtsympool, 0, RMAX,0, 0 ); + case XC(18,55): R CDERIV(CIBEAM, jtlocexmark, 0, 0, 0, 0 ); + + case XC(128,0): R CDERIV(CIBEAM, jtqr, 0, 2, 0, 0 ); + case XC(128,1): R CDERIV(CIBEAM, jtrinv, 0, 2, 0, 0 ); + case XC(128,2): R CDERIV(CIBEAM, 0, jtapplystr, 0, 1, RMAX); + case XC(128,3): R CDERIV(CIBEAM, jtcrc1, jtcrc2, RMAX,RMAX,RMAX); + case XC(128,4): R CDERIV(CIBEAM, jtrngraw, 0, RMAX,0, 0 ); + case XC(128,5): R CDERIV(CIBEAM, jtisnan, 0, RMAX,0, 0 ); + + default: R foreignextra(a,w); +}} + +/* SY_64 double trick - null routines here to avoid optimization */ +#if SY_64 & SY_WIN32 +void double_trick(D a,D b,D c,D d){;} +#endif + +#if SY_64 && (SY_LINUX || SY_MAC) +void double_trick(D a,D b,D c,D d,D e,D f,D g,D h){;} +#endif
new file mode 100644 --- /dev/null +++ b/x.h @@ -0,0 +1,43 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Macros and Defined Constants for !: */ + + +#define XCC 127 +#define XC(m,n) (n+XCC*m) + +#define FAPPEND "ab" +#define FREAD "rb" +#define FUPDATE "r+b" +#define FUPDATEC "w+b" +#define FWRITE "wb" + +#define FLAPPEND L"ab" +#define FLREAD L"rb" +#define FLUPDATE L"r+b" +#define FLUPDATEC L"w+b" +#define FLWRITE L"wb" + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef L_tmpnam +#define L_tmpnam 59 +#endif + +#if SY_WINCE +#define _wmkdir(x) (!CreateDirectory (x,0)) +#define _wrmdir(x) (!RemoveDirectory (x)) +#define _wunlink(x) (!DeleteFile (x)) + +wchar_t *tounibuf(char * src); +char *toascbuf(wchar_t *src); +#endif
new file mode 100644 --- /dev/null +++ b/x15.c @@ -0,0 +1,925 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: DLL call driver */ + +/* +switchcall builds all the required dll calls. +The dll call stack frame is built entirely with I values. +All the int types (char, unicode, short etc) are stacked as I valued. +Pointers are stacked as I values. +Short floats are stacked as I values. +Doubles are stacked as I values (2 for J32 and 1 for J64). + +This gives a fairly good and easy way that is portable across platforms. + +But some architectures don't pass short floats or doubles in the stack +frame and instead passes the first few in registers. + +Mac32 ppc passes floats/doubles with switchcall parms but the 1st 14 must +be put in regs. Mac double_trick does inline asm to load them. +Perhaps this should use win64 trick instead of asm. + +Mac32 intel needs nothing special. + +XP64 pass floats/doubles with switchcall parms. But any floats/doubles +in the 1st 4 positions must be put in the corresponding mmx registers. +The XP64 double_trick puts the 1st four parameters in mmx regs. +XP64 runs no code, it just does a call with 4 doubles to get the mmx +regs loded before the switchcall. + +Linux64/Mac64 pass the 1st 8 float/double args in mmx regs and they are +NOT in the switchcall parameters. Float/double parms after the 1st 8 are +pushed on the stack differently than I parameters and are not supported +by switchcall. More than 8 float/double parameters returns an error. + +Linux64/Mac64 DELIMIT error if more than 8 D arg. Don't know how to do this call. +Treating D as I after the 8th doesn't work. +Treating all D as I if there are more than 8 doesn't work. + +double_trick call must be immediately before SWITCHCALL +otherwise the regs may be used and the parameter lost. +*/ + +#if _WIN32 +#include <windows.h> +#include <windowsx.h> +#else +#include <stdlib.h> +typedef unsigned char BYTE; +#define CALLBACK +#endif + +#include "j.h" + +#define SY_UNIX64 (SY_64 && (SY_LINUX || SY_MAC)) + +#if SY_WINCE +#define HINSTANCE_ERROR 0 +wchar_t *tounibuf(char * src); +char *toascbuf(wchar_t *src); +#endif + +/* unix issues */ +/* if there is only one calling convention then */ +/* ALTCALLINT/DOUBLE routines are not be required */ +/* but the easiest thing to do is to make them be the same */ +/* HMODULE type */ +/* LoadLibrary, GetProcAddress, FreeLibrary routines */ +/* GetLastError and FormatMessage */ + +#if (SYS & SYS_UNIX) + +#include <dlfcn.h> + +#if SYS & SYS_FREEBSD +/* resolve some harmless name clashes */ +#undef atop +#endif + +#undef MAX /* defined in sys/param.h */ +#undef MIN /* defined in sys/param.h */ +#include <sys/param.h> + +typedef void *HMODULE; +typedef char *LPSTR; +typedef I (*FARPROC)(); +#define __stdcall +#define _cdecl +#endif + + +/* windows has 2 dll calling conventions - __stdcall and _cdecl */ +/* __stdcall is used by most DLLs, including all system APIs */ +/* _cdecl is used by some C DLLs and by Fortran */ +/* + flag in cd arg selects the alternate _cdecl convention */ + +typedef I (__stdcall *STDCALLI)(); +typedef I (_cdecl *ALTCALLI)(); +typedef D (__stdcall *STDCALLD)(); +typedef D (_cdecl *ALTCALLD)(); + +#if SY_64 /* J64 requires special float result */ +typedef float (__stdcall *STDCALLF)(); +typedef float (_cdecl *ALTCALLF)(); +#endif + +/* error return codes */ +#define DEOK 0 +#define DEBADLIB 1 +#define DEBADFN 2 +#define DETOOMANY 3 /* too many dlls loaded */ +#define DECOUNT 4 /* too many args or (#args)~:#parms */ +#define DEDEC 5 +#define DEPARM 6 +#define DELIMIT 7 /* linux64 max 8 float/double scalars */ + +#define NCDARGS 32 /* hardwired max number of arguments */ +#define NLIBS 100 /* max number of libraries */ + +#define NLEFTARG (2*NPATH+4+3*(1+NCDARGS)) + /* max length of 15!:0 left argument */ + +#define CDASSERT(p,c) {if(!(p)){jt->dlllasterror=c; ASSERT(0,EVDOMAIN);}} + +typedef struct { + FARPROC fp; /* proc function address */ + HMODULE h; /* library (module) handle */ + I ai; /* argument string index in cdstr */ + I an; /* argument string length */ + I li; /* library name index in cdstr */ + I ln; /* library name length */ + I pi; /* proc name index in cdstr */ + I pn; /* proc name length */ + I n; /* number of arguments (excl. result) */ + I zt; /* result jtype */ + C cc; /* call class: 0x00 or '0' or '1' */ + C zl; /* result type letter */ + B zbx; /* > 1 iff result is boxed */ + B fpreset; /* % 1 iff do FPRESET after call */ + B alternate; /* + 1 iff alternate calling convention */ + B star[NCDARGS]; /* arguments star or not */ + C tletter[NCDARGS]; /* arguments type letters, cwsi etc. */ +} CCT; + +#if SY_64 && SY_WIN32 +void double_trick(D,D,D,D); +#endif + +#if SYS & (SYS & SYS_LINUX) +void double_trick(D,D,D,D,D,D,D,D); +#endif +#if SY_MACPPC +static void double_trick(double*v, I n){I i=0; + for(;i<n;i++) +#define l(a) case (a-1): asm volatile ( "mr r14, %0\nlfd f" #a ", 0(r14)" : : "r" (v+a-1 ) : "f" #a , "r14" ); break; + switch(i) { + l(1) + l(2) + l(3) + l(4) + l(5) + l(6) + l(7) + l(8) + l(9) + l(10) + l(11) + l(12) + l(13) + } +#undef l +} +#endif + +/* +#if SYS & SYS_MACOSX + #define dtrick double_trick(dd,dcnt); +#elif SY_64 && SY_WIN32 + #define dtrick {D*pd=(D*)d; double_trick(pd[0],pd[1],pd[2],pd[3]);} +#elif SY_64 && SY_LINUX + #define dtrick double_trick(dd[0],dd[1],dd[2],dd[3],dd[4],dd[5],dd[6],dd[7]); +#elif 1 + #define dtrick ; +#endif +*/ + +#if SY_64 + #if SY_WIN32 + #define dtrick {D*pd=(D*)d; double_trick(pd[0],pd[1],pd[2],pd[3]);} + #elif SY_UNIX64 + #define dtrick double_trick(dd[0],dd[1],dd[2],dd[3],dd[4],dd[5],dd[6],dd[7]); + #elif SY_MAC + #define dtrick; + #endif +#else + #if SY_WIN32 + #define dtrick ; + #elif SY_LINUX + #define dtrick ; + #elif SY_MACPPC + #define dtrick double_trick(dd,dcnt); + #elif SY_MAC + #define dtrick ; + #endif +#endif + + +#define SWITCHCALL \ + dtrick \ + switch(cnt){ \ + case 0: r = fp(); break; \ + case 1: r = fp(d[0]); break; \ + case 2: r = fp(d[0], d[1]); break; \ + case 3: r = fp(d[0], d[1], d[2]); break; \ + case 4: r = fp(d[0], d[1], d[2], d[3]); break; \ + case 5: r = fp(d[0], d[1], d[2], d[3], d[4]); break; \ + case 6: r = fp(d[0], d[1], d[2], d[3], d[4], d[5]); break; \ + case 7: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6]); break; \ + case 8: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]); break; \ + case 9: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8]); break; \ + case 10: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9]); break; \ + case 11: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10]); break; \ + case 12: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11]); break; \ + case 13: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12]); break; \ + case 14: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13]); break; \ + case 15: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14]); break; \ + case 16: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15]); break; \ + case 17: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16]); break; \ + case 18: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17]); break; \ + case 19: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18]); break; \ + case 20: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19]); break; \ + case 21: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20]); break; \ + case 22: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21]); break; \ + case 23: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22]); break; \ + case 24: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23]); break; \ + case 25: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24]);break; \ + case 26: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25]);break; \ + case 27: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26]);break; \ + case 28: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26],d[27]);break; \ + case 29: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26],d[27],d[28]);break; \ + case 30: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26],d[27],d[28],d[29]);break; \ + case 31: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26],d[27],d[28],d[29],d[30]);break; \ + case 32: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], \ + d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15], \ + d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23], \ + d[24],d[25],d[26],d[27],d[28],d[29],d[30],d[31]);break; \ +} + +static I stdcalli(STDCALLI fp,I*d,I cnt,D*dd,I dcnt){I r; + SWITCHCALL; + R r; +} /* I result */ +static I altcalli(ALTCALLI fp,I*d,I cnt,D*dd,I dcnt){I r; + SWITCHCALL; + R r; +} +static D stdcalld(STDCALLD fp,I*d,I cnt,D*dd,I dcnt){D r; + SWITCHCALL; + R r; +} /* D result */ +static D altcalld(ALTCALLD fp,I*d,I cnt,D*dd,I dcnt){D r; + SWITCHCALL; + R r; +} + +#if SY_64 +static float stdcallf(STDCALLF fp,I*d,I cnt,D*dd,I dcnt){float r; +SWITCHCALL; +R r; +} /* J64 float result */ +static float altcallf(ALTCALLF fp,I*d,I cnt,D*dd,I dcnt){float r; + SWITCHCALL; + R r; +} +#endif + +/* fp - function */ +/* d - address values for call arguments */ +/* cnt - count of values */ +/* zl - result type letter */ +/* v - result data area */ +/* alternate - whether to use alternate calling convention */ + +static void docall(FARPROC fp, I*d, I cnt, D* dd, I dcnt, C zl, I*v, B alternate){ + if(strchr("cwsilx*n",zl)){I r; + r= alternate ? altcalli((ALTCALLI)fp,d,cnt,dd,dcnt) : stdcalli((STDCALLI)fp,d,cnt,dd,dcnt); + switch(zl){ + case 'c': *(C*)v=(C)r; break; + case 'w': *(S*)v=(S)r; break; + case 's': *v=(I)(S)r; break; + case 'i': *v=(I)(int)r; break; + case 'l': + case 'x': + case '*': *v=r; break; + case 'n': *v=0; break; + }} + else +#if !SY_64 + {D r; + r= alternate ? altcalld((ALTCALLD)fp,d,cnt,dd,dcnt) : stdcalld((STDCALLD)fp,d,cnt,dd,dcnt); + *(D*)v=r; + } +#else + {/* the above doesn't work for J64 */ + if(zl=='d'){D r; + r= alternate ? altcalld((ALTCALLD)fp,d,cnt,dd,dcnt) : stdcalld((STDCALLD)fp,d,cnt,dd,dcnt); + *(D*)v=r; + }else{float r; + r= alternate ? altcallf((ALTCALLF)fp,d,cnt,dd,dcnt) : stdcallf((STDCALLF)fp,d,cnt,dd,dcnt); + *(D*)v=(D)r; + }} +#endif +} + +static void convertdown(I*pi,I n,C t){ + if(n)switch(t){ + case 's': {short*pt=(short*)pi; DO(n, pt[i]=(short)pi[i];);} break; + case 'i': {int *pt=(int *)pi; DO(n, pt[i]=(int) pi[i];);} break; + case 'f': {float*pt=(float*)pi;D*pd=(D*)pi; DO(n, pt[i]=(float)pd[i];);} break; +}} /* convert I in place to s or int and d to f */ + +static void convertup(I*pi,I n,C t){I j=n; + if(n)switch(t){ + case 's': {short*pt=(short*)pi; DO(n, --j; pi[j]=(I)pt[j];);} break; + case 'i': {int *pt=(int *)pi; DO(n, --j; pi[j]=(I)pt[j];);} break; + case 'f': {float*pt=(float*)pi;D*pd=(D*)pi; DO(n, --j; pd[j]=(D)pt[j];);} break; +}} /* convert s or int to I and f to d */ + + +/* cache of 15!:0 parsed left arguments */ +/* */ +/* cdarg - append-only table of parsed results */ +/* rows are interpreted by CCT */ +/* when space runs out allocation is doubled */ +/* cdna - # used entries in cdarg */ +/* cdstr - append-only table of 15!:0 left argument strings verbatim */ +/* indexed by ai and an in the CCT struct */ +/* when space runs out allocation is doubled */ +/* cdns - # used chars in cdstr */ +/* cdhash - hash table */ +/* # entries is a prime */ +/* when 2*cdna exceeds # entries allocation is doubled */ +/* table values are indices into cdarg, or -1 */ +/* cdhashl - hash table for libraries (modules) */ +/* cdnl - # used entries in cdhashl */ + +static A jtcdgahash(J jt,I n){A z;I hn,*v; + v=ptab; while(n>*v)++v; hn=*v; + GA(z,INT,hn,1,0); memset(AV(z),CFF,hn*SZI); + R ra(z); +} + +static B jtcdinit(J jt){A x; + RZ(x=exta(LIT,2L,sizeof(CCT),100L )); ra(x); memset(AV(x),C0,AN(x)); jt->cdarg=x; + RZ(x=exta(LIT,1L,1L, 5000L)); ra(x); memset(AV(x),C0,AN(x)); jt->cdstr=x; + RZ(jt->cdhash =cdgahash(4**AS(jt->cdarg))); + RZ(jt->cdhashl=cdgahash(NLIBS )); + jt->cdna=jt->cdns=jt->cdnl=0; + R 1; +} + +static CCT*jtcdlookup(J jt,A a){C*s;CCT*pv;I an,hn,*hv,j,k;UC*av; + hn=AN(jt->cdhash); hv=AV(jt->cdhash); pv=(CCT*)AV(jt->cdarg); s=CAV(jt->cdstr); + an=AN(a); av=UAV(a); j=hic(an,av)%hn; + while(0<=(k=hv[j])){if(an==pv[k].an&&!memcmp(av,s+pv[k].ai,an))R k+pv; j=(j+1)%hn;} + R 0; +} + +static HMODULE jtcdlookupl(J jt,C*av){C*s;CCT*pv;I an,hn,*hv,j,k; + hn=AN(jt->cdhashl); hv=AV(jt->cdhashl); pv=(CCT*)AV(jt->cdarg); s=CAV(jt->cdstr); + an=strlen(av); j=hic(an,av)%hn; + while(0<=(k=hv[j])){if(an==pv[k].ln&&!memcmp(av,s+pv[k].li,an))R pv[k].h; j=(j+1)%hn;} + R 0; +} + +static CCT*jtcdinsert(J jt,A a,CCT*cc){A x;C*s;CCT*pv,*z;I an,hn,*hv,j,k; + an=AN(a); + if(jt->cdns> AN(jt->cdstr)-an)RZ(jt->cdstr=ext(1,jt->cdstr)); + if(jt->cdna==*AS(jt->cdarg)) RZ(jt->cdarg=ext(1,jt->cdarg)); + s=CAV(jt->cdstr); pv=(CCT*)AV(jt->cdarg); + cc->ai=jt->cdns; MC(s+jt->cdns,CAV(a),an); jt->cdns+=an; + z=pv+jt->cdna; MC(z,cc,sizeof(CCT)); k=jt->cdna++; + if(AN(jt->cdhash)<=2*jt->cdna){k=0; RZ(x=cdgahash(2*jt->cdna)); fa(jt->cdhash); jt->cdhash=x;} + hv=AV(jt->cdhash); hn=AN(jt->cdhash); + DO(jt->cdna-k, j=hic(pv[k].an,s+pv[k].ai)%hn; while(0<=hv[j])j=(j+1)%hn; hv[j]=k; ++k;); + R z; +} + + +static CCT*jtcdload(J jt,CCT*cc,C*lib,C*proc){B ha=0;FARPROC f;HMODULE h; + /* not all platforms support GetModuleHandle, so we do it ourselves */ + /* we match on exactly the arg the user supplied */ + /* search path and case can cause us to reload the same dll */ + if(cc->cc){C buf[SY_64?21:12];I k,n; + n=strlen(proc); + CDASSERT(n&&n<sizeof(buf),DEBADFN); + k='_'==*proc?-strtol(1+proc,0L,10):strtol(proc,0L,10); + CDASSERT(k&&'0'==*lib||0<=k&&'1'==*lib,DEBADFN); + sprintf(buf,FMTI,k); if(0>k)*buf='_'; + CDASSERT(!strcmp(proc,buf),DEBADFN); + cc->fp=(FARPROC)k; + R cc; + } + if(h=cdlookupl(lib))cc->h=h; + else{ + CDASSERT(jt->cdnl<NLIBS,DETOOMANY); /* too many dlls loaded */ +#if SY_WIN32 +#if SY_WINCE + h=LoadLibrary(tounibuf(lib)); +#else + h=LoadLibrary(lib); +#endif + CDASSERT((UI)h>HINSTANCE_ERROR,DEBADLIB); +#endif +#if SYS & SYS_UNIX + CDASSERT(h=dlopen((*lib)?lib:0,RTLD_LAZY),DEBADLIB); +#endif + cc->h=h; ha=1; + } +#if SY_WIN32 && !SY_WINCE + f=GetProcAddress(h,'#'==*proc?(LPCSTR)(I)atoi(proc+1):proc); +#endif +#if SY_WINCE + f=GetProcAddress(h,tounibuf(proc)); +#endif +#if (SYS & SYS_UNIX) + f=(FARPROC)dlsym(h,proc); +#endif + CDASSERT(f,DEBADFN); + cc->fp=f; + /* assumes the hash table for libraries (jt->cdhashl) is fixed sized */ + /* assumes cc will be cached as entry number jt->cdna */ + if(ha){I hn,*hv,j; + ++jt->cdnl; hv=AV(jt->cdhashl); hn=AN(jt->cdhashl); + j=hic(cc->ln,lib)%hn; while(0<=hv[j])j=(j+1)%hn; hv[j]=jt->cdna; + } + R cc; +} + +static I cdjtype(C c){R c=='c'?LIT:c=='w'?C2T:c=='j'?CMPX:(c=='f'||c=='d')?FL:c?INT:0;} + /* J type from type letter */ + +/* See "Calling DLLs" chapter in J User Manual */ +/* format of left argument to 15!:0 */ +/* filename procedure [>][+][%] declarations */ +/* e.g. */ +/* opengl32.dll glVertex3d > n d d d */ +/* */ +/* file - aka module aka library */ +/* can also be 0 or 1 */ +/* 0: "procedure" is memory address */ +/* 1: "procedure" is index and */ +/* first parm is address of address of a vtable */ +/* procedure - name of function within library */ +/* > - if result is open (non-boxed) atom */ +/* + - alternate calling convention */ +/* % - execute _fpreset() after dll call */ +/* */ +/* declarations data types */ +/* c LIT char */ +/* w C2T wide char (2 bytes) */ +/* s INT short int (2 bytes) */ +/* i INT int; 4 byte on 32, 8 byte on 64 */ +/* l INT long; error on 32, 8 byte on 64 */ +/* x INT long; 4 byte on 32, 8 byte on 64 */ +/* f FL 4 byte float */ +/* d FL 8 byte float */ +/* j CMPX 16 byte complex (must be preceded by *) */ +/* * pointer */ +/* n INT no result (integer 0) */ + +static CCT*jtcdparse(J jt,A a){C c,lib[NPATH],*p,proc[NPATH],*s,*s0;CCT*cc,cct;I an,der,i,li,pi; + ASSERT(LIT&AT(a),EVDOMAIN); + ASSERT(1>=AR(a),EVRANK); + ASSERT(NLEFTARG>=AN(a),EVLIMIT); + if(cc=cdlookup(a))R cc; + cc=&cct; cc->an=an=AN(a); s=s0=CAV(a); + /* library (module, file) name */ + while(*s==' ')++s; p=*s=='"'?strchr(++s,'"'):strchr(s,' '); li=s-s0; cc->ln=p?p-s:0; + CDASSERT(p&&NPATH>cc->ln,DEBADLIB); + cc->cc=1==cc->ln&&('0'==*s||'1'==*s)?*s:0; + /* procedure name */ + s=p+1+(*p=='"'); + while(*s==' ')++s; p=strchr(s,' '); if(!p)p=s+strlen(s); pi=s-s0; cc->pn=p-s; + CDASSERT(NPATH>cc->pn,DEBADFN); + /* > + % */ + s=p+1; + cc->zbx =1; while(*s==' ')++s; if('>'==*s){cc->zbx =0; ++s;} + cc->alternate=0; while(*s==' ')++s; if('+'==*s){cc->alternate=1; ++s;} + cc->fpreset =0; while(*s==' ')++s; if('%'==*s){cc->fpreset =1; ++s;} + /* result type declaration */ + while(*s==' ')++s; + CDASSERT(*s,DEDEC); + cc->zl=c=*s++; cc->zt=cdjtype(c); + CDASSERT(strchr("cwsilxfd*n",c),DEDEC); + CDASSERT(SY_64||'l'!=c,DEDEC); + if(c=='*' && *s && strchr("cwsilxfdj",*s)) ++s; + CDASSERT(!*s||*s==' ',DEDEC); + /* argument type declarations */ + i=-1; + while(c=*s++){ + if(' '==c)continue; + ++i; der=DEDEC+256*(1+i); + CDASSERT(i<NCDARGS,DECOUNT); + cc->tletter[i]=0; cc->star[i]=0; + CDASSERT(i||'1'!=cc->cc||'x'==c||'*'==c&&(!*s||' '==*s),der); + if('*'==c){cc->star[i]=1; c=*s++; if(!c)break; if(' '==c)continue;} + cc->tletter[i]=c; + CDASSERT(strchr("cwsilxfdj",c),der); + CDASSERT(c!='j'||cc->star[i],der); + if('l'==c){CDASSERT(SY_64,der); cc->tletter[i]='x';} + } + CDASSERT(0<=i||'1'!=cc->cc,DEDEC+256); + MC(lib, s0+li,cc->ln); lib [cc->ln]=0; + MC(proc,s0+pi,cc->pn); proc[cc->pn]=0; + RZ(cc=cdload(cc,lib,proc)); + cc->n=1+i; RZ(cc=cdinsert(a,cc)); cc->li=li+cc->ai; cc->pi=pi+cc->ai; + R cc; +} + +#define CDT(x,y) ((x)+256*(y)) + +static I*jtconvert0(J jt,I zt,I*v,I wt,C*u){D p,q;I k=0;S s; + switch(CDT(zt,wt)){ + default: R 0; + case CDT(FL, B01): *(D*)v=*(B*)u; break; + case CDT(FL, INT): *(D*)v=(D)*(I*)u; break; + case CDT(FL, FL ): *(D*)v=*(D*)u; break; + case CDT(C2T,LIT): *(S*)v=*(C*)u; break; + case CDT(C2T,C2T): *(S*)v=*(S*)u; break; + case CDT(LIT,LIT): *(C*)v=*(C*)u; break; + case CDT(LIT,C2T): s=*(S*)u; if(256<=(US)s)R 0; *(C*)v=(C)s; break; + case CDT(INT,B01): * v=*(B*)u; break; + case CDT(INT,INT): * v=*(I*)u; break; + case CDT(INT,FL ): + p=*(D*)u; q=jfloor(p); + if(p<IMIN*(1+jt->fuzz)||IMAX*(1+jt->fuzz)<p)R 0; +#if SY_64 + if (FEQ(p,q)){k=(I)q; *v=SGN(k)==SGN(q)?k:0>q?IMIN:IMAX;} + else if(++q,FEQ(p,q)){k=(I)q; *v=SGN(k)==SGN(q)?k:0>q?IMIN:IMAX;} + else R 0; +#else + if(FEQ(p,q))*v=(I)q; else if(FEQ(p,1+q))*v=(I)(1+q); else R 0; +#endif + } + R v; +} /* convert a single atom. I from D code adapted from IfromD() in k.c */ + +static B jtcdexec1(J jt,CCT*cc,C*zv0,C*wu,I wk,I wt,I wd){A*wv=(A*)wu,x,y,*zv;B zbx,lit,star; + C c,cipt[NCDARGS],*u;FARPROC fp;float f;I cipcount=0,cipn[NCDARGS],*cipv[NCDARGS],cv0[2], + data[NCDARGS*2],dcnt=0,*dv,i,n,per,t,xn,xr,xt,*xv; D dd[NCDARGS]; + n=cc->n; + CDASSERT(!n||wt&BOX||!(u=memchr(cc->star,C1,n)),DEPARM+256*(u-cc->star)); + zbx=cc->zbx; zv=1+(A*)zv0; dv=data; u=wu; xr=0; + for(i=0;i<n;++i){ + per=DEPARM+i*256; star=cc->star[i]; c=cc->tletter[i]; t=cdjtype(c); + if(wt&BOX){ + x=WVR(i); xt=AT(x); xn=AN(x); xr=AR(x); + CDASSERT(!xr||star,per); /* non-pointers must be scalars */ + lit=star&&xt&LIT&&(c=='s'&&0==xn%2||c=='f'&&0==xn%4); + if(t&&t!=xt&&!(lit||star&&!xr&&xt&BOX)){x=cvt(xt=t,x); CDASSERT(x,per);} + xv=AV(x); if(zbx)*zv++=x; + }else{ + xv=convert0(t,cv0,wt,u); xt=t; u+=wk; + CDASSERT(xv,per); + if(zbx){GA(y,t,1,0,0); MC(AV(y),xv,bp(t)); *zv++=y;} + } + if(star&&!xr&&xt==BOX){ /* scalar boxed integer/boolean scalar is a pointer */ + y=AAV0(x); + CDASSERT(!AR(y)&&AT(y)&B01+INT,per); + if(AT(y)&B01){CDASSERT(0==*BAV(y),per); *dv++=0;}else *dv++=*AV(y); + }else if(star){ + CDASSERT(xr,per); /* pointer can't point at scalar */ + *dv++=(I)xv; /* pointer to J array memory */ + CDASSERT(xt&LIT+C2T+INT+FL+CMPX,per); + if(!lit&&(c=='s'||c=='f'||SY_64&&c=='i')){ + cipv[cipcount]=xv; /* convert in place arguments */ + cipn[cipcount]=xn; + cipt[cipcount]=c; + ++cipcount; + }}else switch(c){ + case 'c': *dv++=*(C*)xv; break; + case 'w': *dv++=*(S*)xv; break; + case 's': *dv++=(S)*xv; break; + case 'i': *dv++=(int)*xv; break; + case 'x': *dv++=*xv; break; + case 'f': +#if SY_MACPPC + dd[dcnt++]=(float)*(D*)xv; +#endif +#if SY_64 && (SY_LINUX || SY_MAC) + {f=(float)*(D*)xv; dd[dcnt]=0; *(float*)(dd+dcnt++)=f;} +#else + f=(float)*(D*)xv; *dv++=*(int*)&f; +#endif + break; + case 'd': +#if SY_MACPPC + dd[dcnt++]=*(D*)xv; +#endif +#if SY_UNIX64 + dd[dcnt++]=*(D*)xv; +#endif +#if !SY_UNIX64 + *dv++=xv[0]; +#if !SY_64 + *dv++=xv[1]; +#endif +#endif + }} +#if SY_UNIX64 + CDASSERT(8>=dcnt,DELIMIT); +#endif + + DO(cipcount, convertdown(cipv[i],cipn[i],cipt[i]);); /* convert I to s and int and d to f as required */ + if(zbx){GA(x,cc->zt,1,0,0); xv=AV(x); *(A*)zv0=x;}else xv=(I*)zv0; + if('1'==cc->cc){fp=(FARPROC)*((I)cc->fp+(I*)*(I*)*data); CDASSERT(fp,DEBADFN);}else fp=cc->fp; + docall(fp, data, dv-data, dd, dcnt, cc->zl, xv, cc->alternate); + + DO(cipcount, convertup(cipv[i],cipn[i],cipt[i]);); /* convert s and int to I and f to d as required */ +#if SY_WIN32 + t= GetLastError(); + if(cc->fpreset)_fpreset(); /* delphi dll (and others) damage fp state */ +#endif +#if SYS&SYS_UNIX + t=errno; +#endif + if(t!=0)jt->getlasterror=t; + R 1; +} + +F2(jtcd){A z;C*tv,*wv,*zv;CCT*cc;I k,m,n,p,q,t,wd,wr,*ws,wt; + RZ(a&&w); + if(!jt->cdarg)RZ(cdinit()); + if(1<AR(a))R rank2ex(a,w,0L,1L,1L,jtcd); + wt=AT(w); wr=AR(w); ws=AS(w); m=wr?prod(wr-1,ws):1; + ASSERT(wt&DENSE,EVDOMAIN); + RZ(cc=cdparse(a)); + n=cc->n; + CDASSERT(n==(wr?ws[wr-1]:1),DECOUNT); + if(cc->zbx){GA(z,BOX,m*(1+n),MAX(1,wr),ws); *(AS(z)+AR(z)-1)=1+n;} + else{CDASSERT('*'!=cc->zl,DEDEC); GA(z,cc->zt,m,MAX(0,wr-1),ws);} + if(m&&n&&!(wt&BOX)){ + t=0; tv=cc->tletter; DO(n, k=cdjtype(*tv++); t=MAX(t,k);); + CDASSERT(HOMO(t,wt),DEPARM); + if(!(wt&B01+INT+FL+LIT+C2T))RZ(w=cvt(wt=t,w)); + } + wv=CAV(w); zv=CAV(z); k=bp(wt); wd=(I)w*ARELATIVE(w); + if(1==m)RZ(cdexec1(cc,zv,wv,k,wt,wd)) + else{p=n*k; q=cc->zbx?sizeof(A)*(1+n):bp(AT(z)); DO(m, RZ(cdexec1(cc,zv,wv,k,wt,wd)); wv+=p; zv+=q;);} + R z; +} /* 15!:0 */ + + +#if SY_WIN32 +#define FREELIB FreeLibrary +#endif +#if (SYS & SYS_UNIX) +#define FREELIB dlclose +#endif + +void dllquit(J jt){CCT*av;I j,*v; + if(!jt->cdarg)R; + v=AV(jt->cdhashl); av=(CCT*)AV(jt->cdarg); + DO(AN(jt->cdhashl), j=*v++; if(0<=j)FREELIB(av[j].h);); + fa(jt->cdarg); jt->cdarg =0; jt->cdna=0; + fa(jt->cdstr); jt->cdstr =0; jt->cdns=0; + fa(jt->cdhash); jt->cdhash =0; + fa(jt->cdhashl); jt->cdhashl=0; jt->cdnl=0; +} /* dllquit - shutdown and cdf clean up dll call resources */ + +F1(jtcdf){ASSERTMTV(w); dllquit(jt); R mtm;} + /* 15!:5 */ + +/* return error info from last cd domain error - resets to DEOK */ +F1(jtcder){I t; ASSERTMTV(w); t=jt->dlllasterror; jt->dlllasterror=DEOK; R v2(t&0xff,t>>8);} + /* 15!:10 */ + +/* return errno info from last cd with errno not equal to 0 - resets to 0 */ +F1(jtcderx){I t;C buf[1024]; + ASSERTMTV(w); t=jt->getlasterror; jt->getlasterror=0; + +#if SY_WIN32 && !SY_WINCE + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, (DWORD)t, + MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), /* Default language */ + buf, sizeof(buf), 0); +#endif + +#if SY_WINCE + { + WCHAR wbuf[1024]; + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, (DWORD)t, + MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), /* Default language */ + wbuf, sizeof(buf), 0); + strcpy(buf,toascbuf(wbuf)); + } +#endif + +#if SYS&SYS_UNIX + {const char *e = dlerror(); strcpy (buf, e?e:"");} +#endif + R link(sc(t),cstr(buf)); +} /* 15!:11 GetLastError information */ + +F1(jtmema){I k; RE(k=i0(w)); R sc((I)MALLOC(k));} /* ce */ + /* 15!:3 memory allocate */ + +F1(jtmemf){I k; RE(k=i0(w)); FREE((void*)k); R zero;} + /* 15!:4 memory free */ + +F1(jtmemr){C*u;I k,m,n,t,*v; + RZ(w); + ASSERT(INT==AT(w),EVDOMAIN); + ASSERT(1==AR(w),EVRANK); + n=AN(w); v=AV(w); + ASSERT(3==n||4==n,EVLENGTH); + m=v[2]; t=3==n?LIT:v[3]; u=(C*)(v[0]+v[1]); + ASSERT(t&LIT+INT+FL+CMPX,EVDOMAIN); + if(-1==m){ASSERT(t&LIT,EVDOMAIN); m=strlen(u);} + k=bp(t); +#if SY_WIN32 + ASSERT(!IsBadReadPtr(u,m*k),EVDOMAIN); +#endif + R vec(t,m,u); +} /* 15!:1 memory read */ + +F2(jtmemw){C*u;I k,m,n,t,*v; + RZ(a&&w); + ASSERT(INT==AT(w),EVDOMAIN); + ASSERT(1==AR(w),EVRANK); + n=AN(w); v=AV(w); + ASSERT(3==n||4==n,EVLENGTH); + m=v[2]; t=3==n?LIT:v[3]; u=(C*)(v[0]+v[1]); + ASSERT(t&LIT+INT+FL+CMPX,EVDOMAIN); + k=bp(t); + ASSERT(m==AN(a)||t&LIT&&1==AR(a)&&(m-1)==AN(a),EVLENGTH); + if(B01==AT(a)&&t==INT) RZ(a=cvt(INT,a)); + ASSERT(t==AT(a),EVDOMAIN); +#if SY_WIN32 + ASSERT(!IsBadWritePtr(u,m*k),EVDOMAIN); +#endif + memcpy(u,AV(a),m*k); + R mtm; +} /* 15!:2 memory write */ + +F1(jtgh15){A z;I k; RE(k=i0(w)); RZ(z=gah(k,0L)); ++AC(z); R sc((I)z);} + /* 15!:8 get header */ + +F1(jtfh15){I k; RE(k=i0(w)); fh((A)k); R zero;} + /* 15!:9 free header */ + +F1(jtdllsymset){RZ(w); R (A)i0(w);} /* do some validation here */ + /* 15!:7 */ + +/* dll callback routines */ +J static cbjt; /* callbacks require jt and can only use the one */ + +I static cbold(I n,I *pi){char d[256],*p;A r;I i; + J jt=cbjt; + strcpy(d, "cdcallback "); + p=d+strlen(d); + for(i=0;i<n;++i){sprintf(p,FMTI,pi[i]); *p=(*p=='-' ? '_':*p);p+=strlen(p);*p++=' ';} + if (!n) { *p++='\''; *p++='\''; } + *p=0; + r=exec1(cstr(d)); + if(!r||AR(r)) R 0; + if(INT==AT(r)) R *AV(r); + if(B01==AT(r)) R *(BYTE*)AV(r); + R 0; +} + +I static cbnew(){A r; + J jt=cbjt; + r=exec1(cstr("cdcallback''")); + if(!r||AR(r)) R 0; + if(INT==AT(r)) R *AV(r); + if(B01==AT(r)) R *(BYTE*)AV(r); + R 0; +} + +/* start of code generated by J script x15_callback.ijs */ +#define CBTYPESMAX 10 /* result and 9 args */ +I static cbx[CBTYPESMAX-1]; +I cbxn=0; + +I static CALLBACK cb0(){I x[]={0};R cbold(0,x);} +I static CALLBACK cb1(I a){I x[]={a};R cbold(1,x);} +I static CALLBACK cb2(I a,I b){I x[]={a,b};R cbold(2,x);} +I static CALLBACK cb3(I a,I b,I c){I x[]={a,b,c};R cbold(3,x);} +I static CALLBACK cb4(I a,I b,I c,I d){I x[]={a,b,c,d};R cbold(4,x);} +I static CALLBACK cb5(I a,I b,I c,I d,I e){I x[]={a,b,c,d,e};R cbold(5,x);} +I static CALLBACK cb6(I a,I b,I c,I d,I e,I f){I x[]={a,b,c,d,e,f};R cbold(6,x);} +I static CALLBACK cb7(I a,I b,I c,I d,I e,I f,I g){I x[]={a,b,c,d,e,f,g};R cbold(7,x);} +I static CALLBACK cb8(I a,I b,I c,I d,I e,I f,I g,I h){I x[]={a,b,c,d,e,f,g,h};R cbold(8,x);} +I static CALLBACK cb9(I a,I b,I c,I d,I e,I f,I g,I h,I i){I x[]={a,b,c,d,e,f,g,h,i};R cbold(9,x);} +I static cbv[]={(I)&cb0,(I)&cb1,(I)&cb2,(I)&cb3,(I)&cb4,(I)&cb5,(I)&cb6,(I)&cb7,(I)&cb8,(I)&cb9}; + +I static CALLBACK cbx0(){cbxn=0;R cbnew();} +I static CALLBACK cbx1(I a){cbxn=1;cbx[0]=a;R cbnew();} +I static CALLBACK cbx2(I a,I b){cbxn=2;cbx[0]=a;cbx[1]=b;R cbnew();} +I static CALLBACK cbx3(I a,I b,I c){cbxn=3;cbx[0]=a;cbx[1]=b;cbx[2]=c;R cbnew();} +I static CALLBACK cbx4(I a,I b,I c,I d){cbxn=4;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;R cbnew();} +I static CALLBACK cbx5(I a,I b,I c,I d,I e){cbxn=5;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;R cbnew();} +I static CALLBACK cbx6(I a,I b,I c,I d,I e,I f){cbxn=6;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;R cbnew();} +I static CALLBACK cbx7(I a,I b,I c,I d,I e,I f,I g){cbxn=7;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;R cbnew();} +I static CALLBACK cbx8(I a,I b,I c,I d,I e,I f,I g,I h){cbxn=8;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;cbx[7]=h;R cbnew();} +I static CALLBACK cbx9(I a,I b,I c,I d,I e,I f,I g,I h,I i){cbxn=9;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;cbx[7]=h;cbx[8]=i;R cbnew();} +I static cbvx[]={(I)&cbx0,(I)&cbx1,(I)&cbx2,(I)&cbx3,(I)&cbx4,(I)&cbx5,(I)&cbx6,(I)&cbx7,(I)&cbx8,(I)&cbx9}; + +#if SY_WIN32 +I static _cdecl cbxalt0(){cbxn=0;R cbnew();} +I static _cdecl cbxalt1(I a){cbxn=1;cbx[0]=a;R cbnew();} +I static _cdecl cbxalt2(I a,I b){cbxn=2;cbx[0]=a;cbx[1]=b;R cbnew();} +I static _cdecl cbxalt3(I a,I b,I c){cbxn=3;cbx[0]=a;cbx[1]=b;cbx[2]=c;R cbnew();} +I static _cdecl cbxalt4(I a,I b,I c,I d){cbxn=4;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;R cbnew();} +I static _cdecl cbxalt5(I a,I b,I c,I d,I e){cbxn=5;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;R cbnew();} +I static _cdecl cbxalt6(I a,I b,I c,I d,I e,I f){cbxn=6;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;R cbnew();} +I static _cdecl cbxalt7(I a,I b,I c,I d,I e,I f,I g){cbxn=7;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;R cbnew();} +I static _cdecl cbxalt8(I a,I b,I c,I d,I e,I f,I g,I h){cbxn=8;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;cbx[7]=h;R cbnew();} +I static _cdecl cbxalt9(I a,I b,I c,I d,I e,I f,I g,I h,I i){cbxn=9;cbx[0]=a;cbx[1]=b;cbx[2]=c;cbx[3]=d;cbx[4]=e;cbx[5]=f;cbx[6]=g;cbx[7]=h;cbx[8]=i;R cbnew();} +I static cbvxalt[]={(I)&cbxalt0,(I)&cbxalt1,(I)&cbxalt2,(I)&cbxalt3,(I)&cbxalt4,(I)&cbxalt5,(I)&cbxalt6,(I)&cbxalt7,(I)&cbxalt8,(I)&cbxalt9}; +#endif +/* end of code generated by J script x15_callback.ijs */ + +F1(jtcallback){ + cbjt=jt; /* callbacks don't work with multiple instances of j */ + RZ(w); + if(LIT&AT(w)) + { + I cnt,alt;C c;C* s; + ASSERT(1>=AR(w),EVRANK); + s=CAV(w); + alt=0; while(*s==' ')++s; if('+'==*s){alt=1; ++s;} +#if !SY_WIN32 + ASSERT(0==alt,EVDOMAIN); +#endif + cnt=0; /* count x's in type declaration (including result) */ + while(c=*s++){ + if(' '==c)continue; + ++cnt; + ASSERT(c=='x',EVDOMAIN); + ASSERT(0==*s||' '==*s,EVDOMAIN); + } + ASSERT(cnt>0&&cnt<CBTYPESMAX,EVDOMAIN); +#if SY_WIN32 + R sc((alt?cbvxalt:cbvx)[--cnt]); /* select callback based on alt * args */ +#else + R sc(cbvx[--cnt]); /* select callback based on alt * args */ +#endif + } + else + { + I k; + RE(k=i0(w)); + ASSERT(k>=0&&k<sizeof(cbv)/SZI, EVINDEX); + R sc(cbv[k]); + } +} /* 15!:13 */ + +F1(jtnfes){I k;I r; + RE(k=i0(w)); + r=jt->nfe; + jt->nfe=k; + R sc(r); +} /* 15!:16 toggle native front end (nfe) state */ + +F1(jtcallbackx){ + ASSERTMTV(w); + R vec(INT,cbxn,cbx); +} /* 15!:17 return x callback arguments */ + +F1(jtnfeoutstr){I k; + RE(k=i0(w)); + ASSERT(0==k,EVDOMAIN); + R cstr(jt->mtyostr?jt->mtyostr:""); +} /* 15!:18 return last jsto output */
new file mode 100644 --- /dev/null +++ b/xa.c @@ -0,0 +1,220 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Miscellaneous */ + +#include "j.h" +#include "x.h" + + +F1(jtassertq){ASSERTMTV(w); R scb(jt->assert);} + +F1(jtasserts){B b; RE(b=b0(w)); jt->assert=b; R mtm;} + +F1(jtboxq){ASSERTMTV(w); R ca(jt->bxa);} + +F1(jtboxs){A x; + RZ(w=vs(w)); + ASSERT(11==*AS(w),EVLENGTH); + x=jt->bxa; RZ(jt->bxa=ra(w)); jt->bx=CAV(jt->bxa); fa(x); + R mtv; +} + +F1(jtctq){ASSERTMTV(w); R scf(jt->ct);} + +F1(jtcts){D d; + ASSERT(!AR(w),EVRANK); + RZ(w=cvt(FL,w)); d=*DAV(w); + ASSERT(0<=d,EVDOMAIN); + ASSERT(d<=5.820766091e-11,EVDOMAIN); + jt->ct=d; + R mtv; +} + +F1(jtdispq){A z; ASSERTMTV(w); GA(z,INT,*jt->disp,1,0); ICPY(AV(z),1+jt->disp,*jt->disp); R z;} + +F1(jtdisps){I n; + RZ(w=vi(w)); + n=AN(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(all1(nubsieve(w)),EVDOMAIN); + ASSERT(all1(eps(w,eval("1 2 4 5 6"))),EVINDEX); + *jt->disp=n; ICPY(1+jt->disp,AV(w),n); + R mtv; +} + +F1(jtdotnamesq){ASSERTMTV(w); R jt->dotnames?one:zero;} + +F1(jtdotnamess){B b,c; + RZ(w); + ASSERT(!AR(w),EVRANK); + if(!(B01&AT(w)))RZ(w=cvt(B01,w)); + c=jt->dotnames; jt->dotnames=b=*BAV(w); + if(c&&!b)ds(CMDOT)=ds(CNDOT)=ds(CUDOT)=ds(CVDOT)=ds(CXDOT)=ds(CYDOT)=0; + else if(!c&&b){ + ds(CMDOT)=mdot; + ds(CNDOT)=ndot; + ds(CUDOT)=udot; + ds(CVDOT)=vdot; + ds(CXDOT)=xdot; + ds(CYDOT)=ydot; + } + R mtv; +} + +F1(jtevmq){ASSERTMTV(w); R behead(jt->evm);} + +F1(jtevms){A t,*tv,*wv; + RZ(w); + ASSERT(1==AR(w),EVRANK); + ASSERT(NEVM==AN(w),EVLENGTH); + ASSERT(BOX&AT(w),EVDOMAIN); + GA(t,BOX,1+NEVM,1,0); tv=AAV(t); + *tv++=mtv; + if(ARELATIVE(w))RZ(w=car(w)); + wv=AAV(w); + DO(NEVM, RZ(*tv++=vs(*wv++));); + ra(t); fa(jt->evm); jt->evm=t; + R mtv; +} + +F1(jtfxx){ + RZ(w); + ASSERT(AT(w)&LIT+BOX,EVDOMAIN); + ASSERT(1>=AR(w),EVRANK); + R fx(ope(w)); +} + +F1(jtiepdoq){ASSERTMTV(w); R scb(jt->iepdo);} + +F1(jtiepdos){B b; RE(b=b0(w)); jt->iepdo=b; R mtm;} + +F1(jtiepq){ + ASSERTMTV(w); + ASSERT(1==AR(w),EVRANK); + ASSERT(!AN(w),EVDOMAIN); + R jt->iep?jt->iep:mtv; +} + +F1(jtieps){ + RZ(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(!AN(w)||AT(w)&LIT,EVDOMAIN); + fa(jt->iep); + RZ(jt->iep=ra(w)); + R mtm; +} + +I prokey=1; /* enabled for 5.01 beta */ + +F1(jtoutparmq){A z;D*u,x;I*v; + ASSERTMTV(w); + if(IMAX==jt->outmaxlen||IMAX==jt->outmaxbefore||IMAX==jt->outmaxafter){ + GA(z,FL, 4,1,0); u=DAV(z); + u[0]=(D)jt->outeol; + x=(D)jt->outmaxlen; u[1]=x==IMAX?inf:x; + x=(D)jt->outmaxbefore; u[2]=x==IMAX?inf:x; + x=(D)jt->outmaxafter; u[3]=x==IMAX?inf:x; + }else{ + GA(z,INT,4,1,0); v= AV(z); + v[0]=jt->outeol; + v[1]=jt->outmaxlen; + v[2]=jt->outmaxbefore; + v[3]=jt->outmaxafter; + } + R z; +} + +F1(jtoutparms){I*v; + RZ(w=vib(w)); + ASSERT(1==AR(w),EVRANK); + ASSERT(4==AN(w),EVLENGTH); + v=AV(w); + ASSERT(0==v[0]||2==v[0],EVINDEX); + ASSERT(0<=v[1],EVDOMAIN); + ASSERT(0<=v[2],EVDOMAIN); + ASSERT(0<=v[3],EVDOMAIN); + jt->outeol =v[0]; + jt->outmaxlen =v[1]; + jt->outmaxbefore=v[2]; + jt->outmaxafter =v[3]; + R mtv; +} + +F1(jtposq){ASSERTMTV(w); R v2(jt->pos[0],jt->pos[1]);} + +F1(jtposs){I n,p,q,*v; + RZ(w=vi(w)); + n=AN(w); v=AV(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(1==n||2==n,EVLENGTH); + if(1==n)p=q=*v; else{p=v[0]; q=v[1];} + ASSERT(0<=p&&p<=2&&0<=q&&q<=2,EVDOMAIN); + jt->pos[0]=p; jt->pos[1]=q; + R mtv; +} + +F1(jtppq){C*end;I k; + ASSERTMTV(w); + k = strtol (3+jt->pp, &end, 10); + R sc(k); +} + +F1(jtpps){I k; + RE(sc(k=i0(w))); ASSERT(0<k,EVDOMAIN); ASSERT(k<=NPP,EVLIMIT); + sprintf(3+jt->pp,FMTI"g", k); + R mtv; +} + +F1(jtretcommq){ASSERTMTV(w); R scb(jt->retcomm);} + +F1(jtretcomms){B b; RE(b=b0(w)); jt->retcomm=b; R mtm;} + +F1(jtseclevq){ASSERTMTV(w); R sc(jt->seclev);} + +F1(jtseclevs){I k; + RE(k=i0(w)); + ASSERT(0==k||1==k,EVDOMAIN); + if(!jt->seclev&&1==k)jt->seclev=k; + R mtm; +} + +F1(jtsysparmq){I k; + RE(k=i0(w)); + switch(k){ + default: ASSERT(0,EVINDEX); + case 0: R sc(jt->fdepn); + case 1: R sc(jt->fdepi); + case 2: R sc(jt->fcalln); + case 3: R sc(jt->fcalli); +}} + +F1(jtsysparms){A*wv;I k,m,wd; + RZ(w); + ASSERT(BOX&AT(w),EVDOMAIN); + ASSERT(1==AR(w),EVRANK); + ASSERT(2==AN(w),EVLENGTH); + wv=AAV(w); wd=(I)w*ARELATIVE(w); + RE(k=i0(WVR(0))); + switch(k){ + default: ASSERT(0,EVINDEX); + case 0: RE(m=i0(WVR(1))); jt->fdepn =m; break; + case 1: ASSERT(0,EVDOMAIN); /* jt->fdepi can not be set */ + case 2: RE(m=i0(WVR(1))); jt->fcalln=m; break; + case 3: ASSERT(0,EVDOMAIN); /* jt->fcalli can not be set */ + } + R mtm; +} + +F1(jtsysq){I j; + ASSERTMTV(w); + switch(SYS){ + case SYS_PC: j=0; break; + case SYS_PC386: j=1; break; + case SYS_PCWIN: j=SY_WIN32 ? (SY_WINCE ? 7 : 6) : 2; break; + case SYS_MACINTOSH: j=3; break; + case SYS_OS2: j=4; break; + default: j=SYS&SYS_UNIX ? 5 : -1; + } + R sc(j); +}
new file mode 100644 --- /dev/null +++ b/xb.c @@ -0,0 +1,341 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Binary Representation */ + +#include "j.h" +#include "x.h" + + +F1(jtstype){RZ(w); R sc(AT(w));} + /* 3!:0 w */ + +/* binary and hex representation formats differ per J version */ +/* pre J6.01 */ +/* (type, flag, #elements, rank, shape; ravel) */ +/* flag is set to 0 for 32 bits and _1 for 64 bits */ +/* J6.01 and later */ +/* (flag, type, #elements, rank, shape; ravel) */ +/* first byte of flag is */ +/* e0 32 bits, reversed byte order */ +/* e1 32 bits, reversed byte order */ +/* e2 64 bits, standard byte order */ +/* e3 64 bits, reversed byte order */ +/* other pre 601 header */ + + +#define WS(d) (d?8:4) /* word size in bytes */ +#define BH(d) (4*WS(d)) /* # non-shape header bytes in A */ +#define BF(d,a) ((C*)(a) ) /* flag */ +#define BT(d,a) ((C*)(a)+ WS(d)) /* type */ +#define BTX(d,pre601,a) ((C*)(a)+ WS(d)*!pre601) +#define BN(d,a) ((C*)(a)+2*WS(d)) /* # elements in ravel */ +#define BR(d,a) ((C*)(a)+3*WS(d)) /* rank */ +#define BS(d,a) ((C*)(a)+4*WS(d)) /* shape */ +#define BV(d,a,r) (BS(d,a)+(r)*WS(d)) /* value */ +#define BU (SYS & SYS_LILENDIAN ? 1 : 0) + + +static I bsize(B d,B tb,I t,I n,I r,I*s){I c,k,m,w,z; + w=WS(d); + z=BH(d)+w*r; + if(t&BIT){ + c=r?s[r-1]:1; m=c?n/c:0; + R z+w*m*((c+w*BB-1)/(w*BB)); + }else{ + k=t&INT+SBT+BOX+XNUM?w:t&RAT?w+w:bp(t); + R z+w*((n*k+(tb&&t&LAST0)+w-1)/w); +}} /* size in byte of binary representation */ + + +/* n: # of words */ +/* v: ptr to result */ +/* u: ptr to argument */ +/* bv: 1 iff v is little-endian */ +/* bu: 1 iff u is little-endian */ +/* dv: 1 iff v is 64-bit */ +/* du: 1 iff u is 64-bit */ + +#define MVCS(a,b,c,d) (8*(a)+4*(b)+2*(c)+(d)) + +static B jtmvw(J jt,C*v,C*u,I n,B bv,B bu,B dv,B du){C c; + switch((dv?8:0)+(du?4:0)+(bv?2:0)+bu){ + case MVCS(0,0,0,0): MC(v,u,n*4); break; + case MVCS(0,0,0,1): DO(n, DO(4, v[3-i]=u[i];); v+=4; u+=4;); break; + case MVCS(0,0,1,0): DO(n, DO(4, v[3-i]=u[i];); v+=4; u+=4;); break; + case MVCS(0,0,1,1): MC(v,u,n*4); break; + case MVCS(0,1,0,0): DO(n, c=0>u[0]?CFF:C0; DO(4, ASSERT(c==u[ i],EVLIMIT); v[i]=u[4+i];); v+=4; u+=8;); break; + case MVCS(0,1,0,1): DO(n, c=0>u[7]?CFF:C0; DO(4, ASSERT(c==u[7-i],EVLIMIT); v[i]=u[3-i];); v+=4; u+=8;); break; + case MVCS(0,1,1,0): DO(n, c=0>u[0]?CFF:C0; DO(4, ASSERT(c==u[3-i],EVLIMIT); v[i]=u[7-i];); v+=4; u+=8;); break; + case MVCS(0,1,1,1): DO(n, c=0>u[7]?CFF:C0; DO(4, ASSERT(c==u[4+i],EVLIMIT); v[i]=u[ i];); v+=4; u+=8;); break; + case MVCS(1,0,0,0): DO(n, c=0>u[0]?CFF:C0; DO(4, v[ i]=c; v[4+i]=u[i];); v+=8; u+=4;); break; + case MVCS(1,0,0,1): DO(n, c=0>u[3]?CFF:C0; DO(4, v[3-i]=c; v[7-i]=u[i];); v+=8; u+=4;); break; + case MVCS(1,0,1,0): DO(n, c=0>u[0]?CFF:C0; DO(4, v[7-i]=c; v[3-i]=u[i];); v+=8; u+=4;); break; + case MVCS(1,0,1,1): DO(n, c=0>u[3]?CFF:C0; DO(4, v[4+i]=c; v[ i]=u[i];); v+=8; u+=4;); break; + case MVCS(1,1,0,0): MC(v,u,n*8); break; + case MVCS(1,1,0,1): DO(n, DO(8, v[7-i]=u[i];); v+=8; u+=8;); break; + case MVCS(1,1,1,0): DO(n, DO(8, v[7-i]=u[i];); v+=8; u+=8;); break; + case MVCS(1,1,1,1): MC(v,u,n*8); break; + } + R 1; +} /* move n words from u to v */ + +static C*jtbrephdr(J jt,B b,B d,A w,A y){A q;I f,r; + q=(A)AV(y); r=AR(w); f=0; + RZ(mvw(BF(d,q),(C*)&f, 1L,b,BU,d,SY_64)); *CAV(y)=d?(b?0xe3:0xe2):(b?0xe1:0xe0); + RZ(mvw(BT(d,q),(C*)&AT(w),1L,b,BU,d,SY_64)); + RZ(mvw(BN(d,q),(C*)&AN(w),1L,b,BU,d,SY_64)); + RZ(mvw(BR(d,q),(C*)&AR(w),1L,b,BU,d,SY_64)); + RZ(mvw(BS(d,q),(C*) AS(w),r, b,BU,d,SY_64)); + R BV(d,q,r); +} + +static A jtbreps(J jt,B b,B d,A w){A q,y,z,*zv;C*v;I c=0,kk,m,n;P*wp; + wp=PAV(w); + n=1+sizeof(P)/SZI; kk=WS(d); + GA(z,BOX,n,1,0); zv=AAV(z); + GA(y,LIT,bsize(d,1,INT,n,AR(w),AS(w)),1,0); + v=brephdr(b,d,w,y); + RZ(mvw(v,(C*)&c,1L,BU,b,d,SY_64)); /* reserved for flag */ + zv[0]=y; m=AN(y); + RZ(zv[1]=q=brep(b,d,SPA(wp,a))); RZ(mvw(v+ kk,(C*)&m,1L,b,BU,d,SY_64)); m+=AN(q); + RZ(zv[2]=q=brep(b,d,SPA(wp,e))); RZ(mvw(v+2*kk,(C*)&m,1L,b,BU,d,SY_64)); m+=AN(q); + RZ(zv[3]=q=brep(b,d,SPA(wp,i))); RZ(mvw(v+3*kk,(C*)&m,1L,b,BU,d,SY_64)); m+=AN(q); + RZ(zv[4]=q=brep(b,d,SPA(wp,x))); RZ(mvw(v+4*kk,(C*)&m,1L,b,BU,d,SY_64)); + R raze(z); +} /* 3!:1 w for sparse w */ + +A jtbrep(J jt,B b,B d,A w){A q,*wv,y,z,*zv;C*u,*v;I e,k,kk,m,n,t,wd; + RZ(w); + e=n=AN(w); t=AT(w); u=CAV(w); k=bp(t); kk=WS(d); + if(t&SPARSE)R breps(b,d,w); + GA(y,LIT,bsize(d,1,t,n,AR(w),AS(w)),1,0); + v=brephdr(b,d,w,y); + if(t&DIRECT)switch(t){ + case SBT: + case INT: RZ(mvw(v,u,n, b,BU,d,SY_64)); R y; + case FL: RZ(mvw(v,u,n, b,BU,1,1 )); R y; + case CMPX: RZ(mvw(v,u,n+n,b,BU,1,1 )); R y; + default: if(n){int*u=(int*)v+(n*k-1)/sizeof(int); *u++=0; *u=0;} + MC(v,u,n*k); R y; + } + if(t&RAT){e+=n; GA(q,XNUM,e,1,0); MC(AV(q),u,n*k);} + else RZ(q=1<AR(w)?ravel(w):w); + m=AN(y); wv=AAV(w); wd=(I)w*ARELATIVE(w); + GA(z,BOX,1+e,1,0); zv=AAV(z); + *zv++=y; + DO(e, RZ(*zv++=q=brep(b,d,WVR(i))); RZ(mvw(v+i*kk,(C*)&m,1L,b,BU,d,SY_64)); m+=AN(q);); + R raze(z); +} /* b iff reverse the bytes; d iff 64-bit */ + +static A jthrep(J jt,B b,B d,A w){A y,z;C c,*hex="0123456789abcdef",*u,*v;I n,s[2]; + RZ(y=brep(b,d,w)); + n=AN(y); s[0]=n/WS(d); s[1]=2*WS(d); + GA(z,LIT,2*n,2,s); + u=CAV(y); v=CAV(z); + DO(n, c=*u++; *v++=hex[(c&0xf0)>>4]; *v++=hex[c&0x0f];); + R z; +} + +F1(jtbinrep1){RZ(w); ASSERT(NOUN&AT(w),EVDOMAIN); R brep(BU,SY_64,w);} /* 3!:1 w */ +F1(jthexrep1){RZ(w); ASSERT(NOUN&AT(w),EVDOMAIN); R hrep(BU,SY_64,w);} /* 3!:3 w */ + +F2(jtbinrep2){I k; + RZ(a&&w); + RE(k=i0(a)); if(10<=k)k-=8; + ASSERT(k<=0||k<=3,EVDOMAIN); + R brep((B)(k%2),(B)(2<=k),w); +} /* a 3!:1 w */ + +F2(jthexrep2){I k; + RZ(a&&w); + RE(k=i0(a)); if(10<=k)k-=8; + ASSERT(k<=0||k<=3,EVDOMAIN); + R hrep((B)(k%2),(B)(2<=k),w); +} /* a 3!:3 w */ + + +static S jtunh(J jt,C c){ + if('0'<=c&&c<='9')R c-'0'; + if('a'<=c&&c<='f')R 10+c-'a'; + ASSERT(0,EVDOMAIN); +} + +static F1(jtunhex){A z;C*u;I c,n;UC p,q,*v; + RZ(w); + c=*(1+AS(w)); + ASSERT(c==8||c==16,EVLENGTH); + n=AN(w)/2; u=CAV(w); + GA(z,LIT,n,1,0); v=UAV(z); + DO(n, p=*u++; q=*u++; *v++=16*unh(p)+unh(q);); + RE(z); R z; +} + +static A jtunbinr(J jt,B b,B d,B pre601,I m,A w){A y,z;C*u=(C*)w,*v;I e,j,kk,n,p,r,*s,t,*vv; + ASSERT(m>BH(d),EVLENGTH); + RZ(mvw((C*)&t,BTX(d,pre601,w),1L,BU,b,SY_64,d)); + RZ(mvw((C*)&n,BN(d,w),1L,BU,b,SY_64,d)); + RZ(mvw((C*)&r,BR(d,w),1L,BU,b,SY_64,d)); + kk=WS(d); v=BV(d,w,r); + ASSERT(t==B01||t==INT||t==FL||t==CMPX||t==BOX||t==XNUM||t==RAT||t==LIT||t==C2T|| + t==SB01||t==SLIT||t==SINT||t==SFL||t==SCMPX||t==SBOX||t==SBT,EVDOMAIN); + ASSERT(0<=n,EVDOMAIN); + ASSERT(0<=r&&r<=RMAX,EVRANK); + p=bsize(d,0,t,n,r,0L); e=t&RAT?n+n:t&SPARSE?1+sizeof(P)/SZI:n; + ASSERT(m>=p,EVLENGTH); + GA(z,t,n,r,0); s=AS(z); + RZ(mvw((C*)s,BS(d,w),r,BU,b,SY_64,d)); + j=1; DO(r, ASSERT(0<=s[i],EVLENGTH); if(t&DENSE)j*=s[i];); + ASSERT(j==n,EVLENGTH); + if(t&BOX+XNUM+RAT+SPARSE){GA(y,INT,e,1,0); vv=AV(y); RZ(mvw((C*)vv,v,e,BU,b,SY_64,d));} + if(t&BOX+XNUM+RAT){A*zv=AAV(z);I i,k=0,*iv; + RZ(y=indexof(y,y)); iv=AV(y); + for(i=0;i<e;++i){ + j=vv[i]; + ASSERT(0<=j&&j<m,EVINDEX); + if(i>iv[i])zv[i]=zv[iv[i]]; + else{while(k<e&&j>=vv[k])++k; zv[i]=unbinr(b,d,pre601,k<e?vv[k]-j:m-j,(A)(u+j));} + }}else if(t&SPARSE){P*zp=PAV(z); + j=vv[1]; ASSERT(0<=j&&j<m,EVINDEX); SPB(zp,a,unbinr(b,d,pre601,vv[2]-j,(A)(u+j))); + j=vv[2]; ASSERT(0<=j&&j<m,EVINDEX); SPB(zp,e,unbinr(b,d,pre601,vv[3]-j,(A)(u+j))); + j=vv[3]; ASSERT(0<=j&&j<m,EVINDEX); SPB(zp,i,unbinr(b,d,pre601,vv[4]-j,(A)(u+j))); + j=vv[4]; ASSERT(0<=j&&j<m,EVINDEX); SPB(zp,x,unbinr(b,d,pre601,m -j,(A)(u+j))); + }else if(n)switch(t){ + case B01: {B c,*zv=BAV(z); DO(n, c=v[i]; ASSERT(c==C0||c==C1,EVDOMAIN); zv[i]=c;);} break; + case SBT: + case INT: RZ(mvw(CAV(z),v,n, BU,b,SY_64,d)); break; + case FL: RZ(mvw(CAV(z),v,n, BU,b,1, 1)); break; + case CMPX: RZ(mvw(CAV(z),v,n+n,BU,b,1, 1)); break; + default: e=n*bp(t); ASSERTSYS(e<=AM(z),"unbinr"); MC(CAV(z),v,e); + } + RE(z); R z; +} /* b iff reverse the bytes; d iff argument is 64-bits */ + +F1(jtunbin){A q;B b,d;C*v;I c,i,k,m,n,r,t; + RZ(w); + ASSERT(LIT&AT(w),EVDOMAIN); + if(2==AR(w))RZ(w=unhex(w)); + ASSERT(1==AR(w),EVRANK); + m=AN(w); + ASSERT(m>=8,EVLENGTH); + q=(A)AV(w); + switch(*CAV(w)){ + case (C)0xe0: R unbinr(0,0,0,m,q); + case (C)0xe1: R unbinr(1,0,0,m,q); + case (C)0xe2: R unbinr(0,1,0,m,q); + case (C)0xe3: R unbinr(1,1,0,m,q); + } + /* code to handle pre 601 headers */ + d=1; v=8+CAV(w); DO(8, if(CFF!=*v++){d=0; break;}); /* detect 64-bit */ + ASSERT(m>=1+BH(d),EVLENGTH); + b=0; + if(!mvw((C*)&t,BTX(d,1,q),1L,BU,0,SY_64,d)){RESETERR; b=1;} /* detect reverse bytes */ + if(!mvw((C*)&n,BN(d,q),1L,BU,0,SY_64,d)){RESETERR; b=1;} + if(!mvw((C*)&r,BR(d,q),1L,BU,0,SY_64,d)){RESETERR; b=1;} + b=b||!(t&NOUN&&0<=n&&0<=r&&(r||1==n)&&m>=BH(d)+r*WS(d)); + if(t&DENSE){ + v=BS(d,q); c=1; + for(i=0;!b&&i<r;++i){ + if(!mvw((C*)&k,v,1L,BU,0,SY_64,d)){RESETERR; b=1;} + v+=WS(d); c*=k; + if(!(0<=k&&(!n||0<=c&&k<=n&&c<=n)))b=1; + } + b=b||n!=c; + } + R unbinr(b,d,1,m,q); +} /* 3!:2 w, inverse for binrep/hexrep */ + + +F2(jtic2){A z;I j,m,n,p,*v,*x,zt;I4*y;S*s;U short*u; + RZ(a&&w); + ASSERT(1>=AR(w),EVRANK); + n=AN(w); + RE(j=i0(a)); + ASSERT(ABS(j)<=2+SY_64,EVDOMAIN); + p=3==j||-3==j?8:2==j||-2==j?4:2; + if(0<j){m=n*p; zt=LIT; if(!(INT&AT(w)))RZ(w=cvt(INT,w));} + else {m=n/p; zt=INT; ASSERT(!n||LIT&AT(w),EVDOMAIN); ASSERT(!(n%p),EVLENGTH);} + GA(z,zt,m,1,0); v=AV(z); x=AV(w); + switch(j){ + default: ASSERT(0,EVDOMAIN); + case -3: ICPY(v,x,m); R z; + case 3: MC(v,x,m); R z; + case -2: y=(I4*)x; DO(m, *v++= *y++;); R z; + case 2: y=(I4*)v; DO(n, *y++=(I4)*x++;); R z; + case -1: s=(S*)x; DO(m, *v++= *s++;); R z; + case 1: s=(S*)v; DO(n, *s++=(S) *x++;); R z; + case 0: u=(U short*)x; DO(m, *v++= *u++;); R z; +}} + +F2(jtfc2){A z;D*x,*v;I j,m,n,p,zt;float*s; + RZ(a&&w); + ASSERT(1>=AR(w),EVRANK); + n=AN(w); + RE(j=i0(a)); + p=2==j||-2==j?sizeof(D):sizeof(float); + if(0<j){m=n*p; zt=LIT; if(!(FL&AT(w)))RZ(w=cvt(FL,w));} + else {m=n/p; zt=FL; ASSERT(!n||LIT&AT(w),EVDOMAIN); ASSERT(!(n%p),EVLENGTH);} + GA(z,zt,m,1,0); v=DAV(z); x=DAV(w); + switch(j){ + default: ASSERT(0,EVDOMAIN); + case -2: MC(v,x,n); R z; + case 2: MC(v,x,m); R z; + case -1: s=(float*)x; DO(m, *v++= *s++;); R z; + case 1: s=(float*)v; DO(n, *s++=(float)*x++;); R z; +}} + + +static B jtisnanq(J jt,A w){A q,*u,x,x1,*xv,y,*yv;D*v;I m,n,t,top,yd; + RZ(w); + GA(x,INT,BOX&AT(w)?2*AN(w):1,1,0); xv=AAV(x); + *xv=w; top=1; + while(top){ + --top; y=xv[top]; n=AN(y); t=AT(y); + if(t&FL+CMPX){v=DAV(y); DO(t&CMPX?n+n:n, if(_isnan(*v++))R 1;);} + else if(t&BOX){ + m=top+n; yv=AAV(y); yd=(I)y*ARELATIVE(y); + if(m>AN(y)){GA(x1,INT,2*m,1,0); u=AAV(x1); ICPY(u,xv,top); fa(x); x=x1; xv=u;} + u=xv+top; DO(n, q=YVR(i); if(AT(q)&FL+CMPX+BOX)*u++=q;); top=u-xv; + }} + R 0; +} + +F1(jtisnan){A*wv,z;B*u;D*v;I n,t,wd; + RZ(w); + n=AN(w); t=AT(w); + ASSERT(t&DENSE,EVNONCE); + GA(z,B01,n,AR(w),AS(w)); u=BAV(z); + if (t&FL ){v=DAV(w); DO(n, *u++=_isnan(*v++););} + else if(t&CMPX){v=DAV(w); DO(n, *u++=_isnan(*v)||_isnan(*(v+1)); v+=2;);} + else if(t&BOX ){wv=AAV(w); wd=(I)w*ARELATIVE(w); DO(n, *u++=isnanq(WVR(i));); RE(0);} + else memset(u,C0,n); + R z; +} + + +F1(jtbit1){A z;B*wv;BT*zv;I c,i,j,n,p,q,r,*s;UI x,y; + RZ(w); + if(!(B01&AT(w)))RZ(w=cvt(B01,w)); + n=AN(w); r=AR(w); wv=BAV(w); s=AS(w); + GA(z,BIT,n,AR(w),AS(w)); zv=(BT*)AV(z); + if(!r)*zv=*wv?'\200':0; + else if(n){ + c=8*SZI; + i=s[r-1]; r= p=n/i; q=i/c; r=i-c*q; + for(i=0;i<p;++i){ + for(j=0;j<q;++j){ + x=0; y=1+(UI)IMAX; + DO(c, if(*wv++)x^=y; y>>=1;); + *zv++=x; + } + x=0; y=1+(UI)IMAX; + DO(r, if(*wv++)x^=y; y>>=1;); + *zv++=x; + } + } + R z; +} /* convert byte booleans to bit booleans */ + +F2(jtbit2){ + ASSERT(0,EVNONCE); +} /* convert byte booleans to bit booleans */
new file mode 100644 --- /dev/null +++ b/xc.c @@ -0,0 +1,20 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Custom */ + +#include "j.h" + + +F2(jtforeignextra){ + RZ(a&&w); + R CDERIV(CIBEAM, 0,0, RMAX,RMAX,RMAX); +} + +F2(jtfixrecursive){A f,g,y; + RZ(a&&w); + RZ(y=lrep(w)); + if(a==one ||a==num[3])RZ(f=colon(num[3], over(y,cstr(" y")) )); + if(a==num[2]||a==num[3])RZ(g=colon(num[4],over(cstr("x "),over(y,cstr(" y"))))); + R a==num[3]?colon(f,g):a==one?f:g; +}
new file mode 100644 --- /dev/null +++ b/xcrc.c @@ -0,0 +1,53 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: CRC calculation */ + +#include "j.h" +#include "x.h" + + +typedef unsigned int II; + +static II crctab[256]; + +static II jtcrcvalidate(J jt,A w){A*wv;B*v;I m,wd;II p,x,z=-1; + RZ(w); + ASSERT(1>=AR(w),EVRANK); + m=AN(w); + if(m&&BOX&AT(w)){ASSERT(2>=m,EVLENGTH); wv=AAV(w); wd=(I)w*ARELATIVE(w); w=WVR(0); if(2==m)RE(z=(II)i0(WVR(1)));} + if(B01&AT(w)){ASSERT(32==AN(w),EVLENGTH); v=BAV(w); p=0; DO(32, p<<=1; if(*v++)p|=1;);} + else RE(p=(II)i0(w)); + DO(256, x=(II)i; DO(8, if(1&x)x=p^x>>1; else x>>=1;); crctab[i]=x;); + R z; +} + +F1(jtcrc1){R crc2(sc(-306674912),w);} + +F2(jtcrc2){I n;II z;UC*v; + RZ(a&&w); + ASSERT(1>=AR(a)&&1>=AR(w),EVRANK); + n=AN(w); v=UAV(w); + ASSERT(!n||LIT&AT(w),EVDOMAIN); + RE(z=crcvalidate(a)); + DO(n, z=z>>8^crctab[255&(z^*v++)];); + R sc((I)z^(I)-1); +} + +F1(jtcrccompile){A h,*hv;II z; + RZ(w); + GA(h,BOX,2,1,0); hv=AAV(h); + RE(z=crcvalidate(w)); + RZ(hv[0]=vec(INT,256L,crctab)); + RZ(hv[1]=sc((I)z)); + R h; +} + +DF1(jtcrcfixedleft){A h,*hv;I n;II*t,z;UC*v; + RZ(w); + h=VAV(self)->h; hv=AAV(h); t=(II*)AV(hv[0]); z=(II)*AV(hv[1]); + n=AN(w); v=UAV(w); + ASSERT(!n||LIT&AT(w),EVDOMAIN); + DO(n, z=z>>8^t[255&(z^*v++)];); + R sc((I)z^(I)-1); +}
new file mode 100644 --- /dev/null +++ b/xd.c @@ -0,0 +1,398 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: file directory, attributes, & permission */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#endif + +#include "j.h" +#include "x.h" + +#if !SY_WINCE +char* toascbuf(char* s){ return s;} +char* tounibuf(char* s){ return s;} +#else +wchar_t* tounibuf(char* src) +{ + static wchar_t buf[2048+1]; + + wchar_t* p=buf; + if(2048>strlen(src)) + { + while(*src) *p++=*src++; + } + *p=0; + return buf; +} + +char *toascbuf(wchar_t *src) +{ + static char buf[2048+1]; + + char* p=buf; + if(2048>wcslen(src)) + { + while(*src) *p++=(char)*src++; + } + *p=0; + return buf; +} +#define _A_NORMAL FILE_ATTRIBUTE_NORMAL +#define _A_RDONLY FILE_ATTRIBUTE_READONLY +#define _A_HIDDEN FILE_ATTRIBUTE_HIDDEN +#define _A_SYSTEM FILE_ATTRIBUTE_SYSTEM +#define _A_VOLID 0 +#define _A_SUBDIR FILE_ATTRIBUTE_DIRECTORY +#define _A_ARCH FILE_ATTRIBUTE_ARCHIVE + +#endif + +#if (SYS & SYS_DOS) + +#if !SY_WINCE +#include <ctype.h> +#include <io.h> +#include <dos.h> +#include <direct.h> +#include <time.h> +#endif + +#ifndef F_OK /* for access() */ +#define F_OK 0x00 +#define X_OK 0x01 +#define W_OK 0x02 +#define R_OK 0x04 +#endif + +#ifndef _A_VOLID +#define _A_VOLID 0x00 +#endif + +#define _A_ALL (_A_NORMAL+_A_RDONLY+_A_HIDDEN+_A_SYSTEM+_A_VOLID+ \ + _A_SUBDIR+_A_ARCH) + +static A jtattv(J jt,U x){A z;C*s; + GA(z,LIT,6,1,0); s=CAV(z); + s[0]=x&_A_RDONLY?'r':'-'; + s[1]=x&_A_HIDDEN?'h':'-'; + s[2]=x&_A_SYSTEM?'s':'-'; + s[3]=x&_A_VOLID ?'v':'-'; + s[4]=x&_A_SUBDIR?'d':'-'; + s[5]=x&_A_ARCH ?'a':'-'; + R z; +} /* convert from 16-bit attributes x into 6-element string */ + +static S jtattu(J jt,A w){C*s;I i,n;S z=0; + RZ(w=vs(w)); + n=AN(w); s=CAV(w); + for(i=0;i<n;++i)switch(s[i]){ + case 'r': z^=_A_RDONLY; break; + case 'h': z^=_A_HIDDEN; break; + case 's': z^=_A_SYSTEM; break; + case 'v': z^=_A_VOLID; break; + case 'd': z^=_A_SUBDIR; break; + case 'a': z^=_A_ARCH; break; + case '-': break; + default: ASSERT(0,EVDOMAIN); + } + R z; +} /* convert from 6-element string into 16-bit attributes */ + +F1(jtfullname){C*s; C dirpath[1000]; + RZ(w=str0(w)); + s=CAV(w); DO(AN(w), if(' '!=*s)break; ++s;); +#if SY_WINCE + if(*s=='\\'||*s=='/') strcpy(dirpath,s); + else {strcpy(dirpath, "\\"); strcat(dirpath,s);} +#else + _fullpath(dirpath,s,NPATH); +#endif + R cstr(dirpath); +} + +#if !SY_WINCE + +F1(jtjfperm1){A y,fn,z;C *s;F f;int x; US *p,*q; + F1RANK(0,jtjfperm1,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=AAV0(w); + RZ(fn=toutf16x(y)); + p=USAV(fn); q=p+AN(fn)-3; + GA(z,LIT,3,1,0); s=CAV(z); + x=_waccess(p,R_OK); if(0>x)R jerrno(); + s[0]=x?'-':'r'; + s[1]=_waccess(p,W_OK)?'-':'w'; + s[2]=wcscmp(q,L"exe")&&wcscmp(q,L"bat")&&wcscmp(q,L"com")?'-':'x'; + R z; +} + +F2(jtjfperm2){A y,fn;C*s;F f;int x=0;US *p; + F2RANK(1,0,jtjfperm2,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=AAV0(w); + RZ(a=vs(a)); ASSERT(3==AN(a),EVLENGTH); + RZ(fn=toutf16x(y)); + s=CAV(y); + p=USAV(fn);; + s=CAV(a); + if('r'==s[0]) x|=S_IREAD; else ASSERT('-'==s[0],EVDOMAIN); + if('w'==s[1]) x|=S_IWRITE; else ASSERT('-'==s[1],EVDOMAIN); + if('x'==s[2]) x|=S_IEXEC; else ASSERT('-'==s[2],EVDOMAIN); + R _wchmod(p,x)?jerrno():mtm; +} + +#else /* SY_WINCE: */ + +F1(jtjfperm1){A y,z;C*p,*q,*s;F f; DWORD attr; + F1RANK(0,jtjfperm1,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=AAV0(w); + p=CAV(y); q=p+AN(y)-3; + GA(z,LIT,3,1,0); s=CAV(z); + if((attr=GetFileAttributes(tounibuf(p)))==0xFFFFFFFF)R jerrno(); + s[0]='r'; + s[1]=attr&FILE_ATTRIBUTE_READONLY?'-':'w'; + s[2]=strcmp(q,"exe")&&strcmp(q,"bat")&&strcmp(q,"com")?'-':'x'; + R z; +} + +F2(jtjfperm2){ASSERT(0,EVNONCE);} + +#endif +#endif + +/* jdir produces a 5-column matrix of boxes: */ +/* 0 name */ +/* 1 time of last write, y m d h m s */ +/* 2 size */ +/* 3 permission -- 0 read 1 write 2 execute */ +/* 4 attributes */ +/* 0 read-only 3 volume label */ +/* 1 hidden 4 directory */ +/* 2 system 5 archive (modified since last back-up) */ + +#if SY_WIN32 + +#include <stdlib.h> + +UINT getfileattr(char *); +int setfileattr(char*, UINT); + +static A jtdir1(J jt,LPWIN32_FIND_DATAW f,C* fn) {A z,*zv;C rwx[3],*s,*t;I n,ts[6]; + FILETIME local_ftime; SYSTEMTIME x; + + FileTimeToLocalFileTime(&f->ftLastWriteTime, &local_ftime); + FileTimeToSystemTime(&local_ftime, &x); + ts[0]=x.wYear; ts[1]=x.wMonth; ts[2]=x.wDay; + ts[3]=x.wHour; ts[4]=x.wMinute; ts[5]=x.wSecond; + s=fn; n=strlen(s); t=s+n-3; + rwx[0]='r'; + rwx[1]=f->dwFileAttributes & FILE_ATTRIBUTE_READONLY ?'-':'w'; + rwx[2]=strcmp(t,"exe")&&strcmp(t,"bat")&&strcmp(t,"com")?'-':'x'; + GA(z,BOX,5,1,0); zv=AAV(z); + RZ(zv[0]=str(n,s)); + RZ(zv[1]=vec(INT,6L,ts)); +#if SY_64 + RZ(zv[2]=sc(((I)f->nFileSizeHigh<<32) + (I)f->nFileSizeLow)); +#else + RZ(zv[2]=sc( (f->nFileSizeHigh || 0>(I)f->nFileSizeLow)?-1:f->nFileSizeLow )); +#endif + RZ(zv[3]=str(3L,rwx)); + RZ(zv[4]=attv((S)f->dwFileAttributes)); + R z; +} + +F1(jtjdir){PROLOG;A z,fn,*zv;I j=0,n=32;HANDLE fh; WIN32_FIND_DATAW f; C fnbuffer[10000]; C* name; + RZ(w); + RZ(w=vs(!AR(w)&&BOX&AT(w)?ope(w):w)); + RZ(fn=jttoutf16x(jt,w)); + fh=FindFirstFileW((US*)CAV(fn),&f); + GA(z,BOX,n,1,0); zv=AAV(z); + if (fh!=INVALID_HANDLE_VALUE) { + do { + jttoutf8x(jt,fnbuffer,sizeof fnbuffer,f.cFileName); + name = fnbuffer; + if(strcmp(name,".")&&strcmp(name,"..")){ + if(j==n){RZ(z=ext(0,z)); n=AN(z); zv=AAV(z);} + RZ(zv[j++]=jtdir1(jt,&f,fnbuffer)); + } + } while (FindNextFileW(fh,&f)); + FindClose(fh); + } + z=j?ope(j<n?vec(BOX,j,zv):z):reshape(v2(0L,5L),ace); + EPILOG(z); +} + +F1(jtjfatt1){A y,fn;F f;U x; + F1RANK(0,jtjfatt1,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=AAV0(w); + RZ(fn=toutf16x(y)); + x=GetFileAttributesW(USAV(fn)); + if(-1!=x) R attv(x); + jsignal(EVFNAME); R 0; +} + +F2(jtjfatt2){A y,fn;F f;U x; + F2RANK(1,0,jtjfatt2,0); + RE(x=attu(a)); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=AAV0(w); + RZ(fn=toutf16x(y)); + if(SetFileAttributesW(USAV(fn), x)) R one; + jsignal(EVFNAME); R 0; +} + +#endif + +#if (SYS & SYS_UNIX) + +/* FIXME: rename J link() function so we can include unistd.h */ +#define R_OK 4 /* Test for read permission. */ +#define W_OK 2 /* Test for write permission. */ +#define X_OK 1 /* Test for execute permission. */ + +#include <sys/stat.h> +#include <dirent.h> +#include <time.h> + +#if SYS&(SYS_SUN4+SYS_SGI) +#include "fnmatch.h" +#else +#include <fnmatch.h> +#endif + + +/* Return mode_t formatted into a static 10-character buffer. */ +static C*modebuf(mode_t m){C c;static C b[11];I t=m; + strcpy(b+1,"rwxrwxrwx"); + DO(9, if(!(m&1))b[9-i]='-'; m>>=1;); + if(t&S_ISUID)b[3]=(b[3]=='x')?'s':'S'; + if(t&S_ISGID)b[6]=(b[6]=='x')?'s':'S'; + if(t&S_ISVTX)b[9]=(b[9]=='x')?'t':'T'; + switch(t&S_IFMT){ + case S_IFBLK: b[0]='b'; break; + case S_IFCHR: b[0]='c'; break; + case S_IFDIR: b[0]='d'; break; +#if !(SYS & SYS_UNIX) + case S_IFFIFO: b[0]='f'; break; /*IVL */ +#endif + case S_IFLNK: b[0]='l'; break; + case S_IFSOCK: b[0]='s'; break; + case S_IFREG: b[0]='-'; break; + default: b[0]='?'; + } + R b; +} + +/* + linux32 stat fails on big files - so it uses stat64 + but can't get it to work with struct stat64 + so struct stat is used (wrong, but seems to work) +*/ + +#if SYS & SYS_LINUX +#define stat stat64 +#endif + + +static int ismatch(J jt,C*pat,C*name){ + strcpy(jt->dirbase,name); if(stat(jt->dirnamebuf,&jt->dirstatbuf))R 0; + if('.'!=*pat && ((!strcmp(name,"."))||(!strcmp(name,".."))))R 0; + if(fnmatch(pat,name,0)) R 0; +/* Set up dirrwx, diratts, and dirmode for this file */ + jt->dirrwx[0]=access(jt->dirnamebuf,R_OK)?'-':'r'; + jt->dirrwx[1]=access(jt->dirnamebuf,W_OK)?'-':'w'; + jt->dirrwx[2]=access(jt->dirnamebuf,X_OK)?'-':'x'; + strcpy(jt->diratts,"------"); + jt->diratts[0]=(jt->dirrwx[0]=='r'&&jt->dirrwx[1]=='-')?'r':'-'; + jt->diratts[1]=('.'==name[0])?'h':'-'; + strcpy(jt->dirmode,modebuf(jt->dirstatbuf.st_mode)); + jt->diratts[4]=('d'==jt->dirmode[0])?'d':'-'; + R 1; +} + +static A jtdir1(J jt,struct dirent*f){A z,*zv;C*s,att[16];I n,ts[6],i,m,sz;S x;struct tm *tm; + tm=localtime(&jt->dirstatbuf.st_mtime); + ts[0]=1900+tm->tm_year; ts[1]=1+tm->tm_mon; ts[2]=tm->tm_mday; + ts[3]=tm->tm_hour; ts[4]=tm->tm_min; ts[5]=tm->tm_sec; + s=f->d_name; n=strlen(s); + GA(z,BOX,6,1,0); zv=AAV(z); + RZ(zv[0]=vec(LIT,n,s)); + RZ(zv[1]=vec(INT,6L,ts)); + sz=jt->dirstatbuf.st_size; + sz=sz<0?-1:sz; + RZ(zv[2]=sc(sz)); + RZ(zv[3]=vec(LIT,3L, jt->dirrwx )); + RZ(zv[4]=vec(LIT, 6L,jt->diratts)); + RZ(zv[5]=vec(LIT,10L,jt->dirmode)); + R z; +} + +F1(jtjdir){PROLOG;A*v,z,*zv;C*dir,*pat,*s,*x;I j=0,n=32;DIR*DP;struct dirent *f; + RZ(w); + RZ(w=str0(vs(!AR(w)&&BOX&AT(w)?ope(w):w))); + s=CAV(w); + if(x=strrchr(s,'/')){dir=s==x?"/":s; pat=x+1; *x=0;}else{dir="."; pat=s;} + if(NULL==(DP=opendir(dir)))R reshape(v2(0L,6L),ace); + /* + * SYSV and BSD have different return types for sprintf(), + * so we use less efficient but portable code. + */ + sprintf(jt->dirnamebuf,"%s/",dir); jt->dirbase=jt->dirnamebuf+strlen(jt->dirnamebuf); f=readdir(DP); + GA(z,BOX,n,1,0); zv=AAV(z); + while(f){ + if(ismatch(jt,pat,f->d_name)){ + if(j==n){RZ(z=ext(0,z)); n=AN(z); zv=AAV(z);} + RZ(zv[j++]=dir1(f)); + } + f=readdir(DP); + } + closedir(DP); + z=j?ope(j<n?vec(BOX,j,zv):z):reshape(v2(0L,6L),ace); + EPILOG(z); +} + + + +F1(jtjfatt1){ASSERT(0,EVNONCE);} +F2(jtjfatt2){ASSERT(0,EVNONCE);} + + +F1(jtjfperm1){A y;F f; + F1RANK(0,jtjfperm1,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=str0(AAV0(w)); + if(0!=stat(CAV(y),&jt->dirstatbuf))R jerrno(); + R vec(LIT,9L,1+modebuf(jt->dirstatbuf.st_mode)); +} + + +static struct tperms {C*c;I p[4];} permtab[]= + { {"-r" ,{0,S_IRUSR}}, + {"-w" ,{0,S_IWUSR}}, + {"-xSs",{0,S_IXUSR,S_ISUID,S_ISUID+S_IXUSR}}, + {"-r" ,{0,S_IRGRP}}, + {"-w" ,{0,S_IWGRP}}, + {"-xSs",{0,S_IXGRP,S_ISGID,S_ISGID+S_IXGRP}}, + {"-r" ,{0,S_IROTH}}, + {"-w" ,{0,S_IWOTH}}, + {"-xTt",{0,S_IXOTH,S_ISVTX,S_ISVTX+S_IXOTH}}, + }; + +F2(jtjfperm2){A y;C*s;F f;int x=0,i;C*m; + F2RANK(1,0,jtjfperm2,0); + RE(f=stdf(w)); if(f)ASSERT(y=fname(sc((I)f)),EVFNUM) else y=str0(AAV0(w)); + RZ(a=vs(a)); ASSERT(9==AN(a),EVLENGTH); s=CAV(a); + for(i=0;i<9;i++) + {ASSERT(NULL!=(m=strchr(permtab[i].c,s[i])),EVDOMAIN); + x|=permtab[i].p[m-permtab[i].c];} + R chmod(CAV(y),x)?jerrno():mtm; +} + + +#endif + +/* ----------------------------------------------------------------------- */ + + +#if ! (SYS & SYS_DOS) +F1(jtfullname){R w;} +#endif
new file mode 100644 --- /dev/null +++ b/xf.c @@ -0,0 +1,316 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Files */ + +/* File functions accept file number or boxed file name or 1 or 2 */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#endif + +#include "j.h" +#include "x.h" + +#if !SY_WIN32 && (SYS & SYS_DOS) +#include <dos.h> +#endif + +#if (SYS & SYS_UNIX) +#include <stdlib.h> +typedef long long INT64; +#endif + +#if SY_WIN32 && !SY_WINCE +#include <direct.h> +#include <io.h> +#endif + + +#if SY_64 +static I fsize(F f){fpos_t z; + RZ(f); +#if SY_WIN32 + _lseeki64(_fileno(f),0,SEEK_END); +#else + fseek(f,0L,SEEK_END); +#endif + fgetpos(f,&z); + R *(I*)&z; +} +#else +static I fsize(F f){ + RZ(f); + if(fseek(f,0L,SEEK_END))R -1; + R ftell(f); +} +#endif + +static A jtrdns(J jt,F f){A za,z;I n;size_t r,tr=0; + GA(za,LIT,n=1024,1,0); clearerr(f); + while(!feof(f) && (r=fread(CAV(za)+tr,sizeof(C),n-tr,f))){ + tr+=r; if(tr==(U)n){RZ(za=ext(0,za));n*=2;} + } + if(tr==(U)n)z=za; + else {GA(z,LIT,tr,1,0); MC(CAV(z),CAV(za),tr);} + R z; +} /* read entire file stream (non-seekable) */ + +A jtrd(J jt,F f,I j,I n){A z;C*x;I p=0;size_t q=1; + RZ(f); + if(0>n){if(j<0) n=-j; else n=fsize(f)-j;} + +#if !SY_WINCE + {INT64 v; v= j+((0>j)?fsize(f):0); fsetpos(f,(fpos_t*)&v);} +#else + fseek(f,(long)(0>j?1+j:j),0>j?SEEK_END:SEEK_SET); +#endif + + clearerr(f); + GA(z,LIT,n,1,0); x=CAV(z); + while(q&&n>p){ + p+=q=fread(p+x,sizeof(C),(size_t)(n-p),f); + if(ferror(f))R jerrno(); + } + R z; +} /* read file f for n bytes at j */ + +static B jtwa(J jt,F f,I j,A w){C*x;I n,p=0;size_t q=1; + RZ(f&&w); + n=AN(w)*(C2T&AT(w)?2:1); x=CAV(w); + +#if !SY_WINCE + {INT64 v; v= j+((0>j)?fsize(f):0); fsetpos(f,(fpos_t*)&v);} +#else + fseek(f,(long)(0>j?1+j:j),0>j?SEEK_END:SEEK_SET); +#endif + + clearerr(f); + while(q&&n>p){ + p+=q=fwrite(p+x,sizeof(C),(size_t)(n-p),f); + if(ferror(f))R jerrno()?1:0; + } + R 1; +} /* write/append string w to file f at j */ + + +F1(jtjfread){A z;F f; + F1RANK(0,jtjfread,0); + RE(f=stdf(w)); + if(f)R 1==(I)f?jgets("\001"):3==(I)f?rdns(stdin):rd(vfn(f),0L,-1L); + RZ(f=jope(w,FREAD)); z=rd(f,0L,-1L); fclose(f); + R z; +} + +F2(jtjfwrite){B b;F f; + F2RANK(RMAX,0,jtjfwrite,0); + if(BOX&AT(w)){ASSERT(1>=AR(a),EVRANK); ASSERT(!AN(a)||AT(a)&LIT+C2T,EVDOMAIN);} + RE(f=stdf(w)); + if(2==(I)f){b=jt->tostdout; jt->tostdout=1; jt->mtyo=MTYOFILE; jpr(a); jt->mtyo=0; jt->tostdout=b; R a;} + if(4==(I)f){R (U)AN(a)!=fwrite(CAV(a),sizeof(C),AN(a),stdout)?jerrno():a;} + if(5==(I)f){R (U)AN(a)!=fwrite(CAV(a),sizeof(C),AN(a),stderr)?jerrno():a;} + if(b=!f)RZ(f=jope(w,FWRITE)) else RE(vfn(f)); + wa(f,0L,a); + if(b)fclose(f);else fflush(f); + RNE(mtm); +} + +F2(jtjfappend){B b;F f; + F2RANK(RMAX,0,jtjfappend,0); + RE(f=stdf(w)); + if(2==(I)f){B b=jt->tostdout; jt->tostdout=1; jpr(a); jt->tostdout=b; R a;} + ASSERT(!AN(a)||AT(a)&LIT+C2T,EVDOMAIN); + ASSERT(1>=AR(a),EVRANK); + if(b=!f)RZ(f=jope(w,FAPPEND)) else RE(vfn(f)); + wa(f,fsize(f),a); + if(b)fclose(f);else fflush(f); + RNE(mtm); +} + +F1(jtjfsize){B b;F f;I m; + F1RANK(0,jtjfsize,0); + RE(f=stdf(w)); + if(b=!f)RZ(f=jope(w,FREAD)) else RE(vfn(f)); + m=fsize(f); + if(b)fclose(f);else fflush(f); + RNE(sc(m)); +} + +static F jtixf(J jt,A w){F f; + ASSERT(2<=AN(w),EVLENGTH); + switch(AT(w)){ + default: ASSERT(0,EVDOMAIN); + case B01: ASSERT(0,EVFNUM); + case BOX: ASSERT(2==AN(w),EVLENGTH); f=stdf(head(w)); break; + case INT: f=(F)*AV(w); ASSERT(2<(UI)f,EVFNUM); + } + R f?vfn(f):f; +} /* process index file arg for file number; 0 if a file name */ + +static B jtixin(J jt,A w,I s,I*i,I*n){A in,*wv;I j,k,m,*u,wd; + if(AT(w)&BOX){wv=AAV(w); wd=(I)w*ARELATIVE(w); RZ(in=vi(WVR(1))); k=AN(in); u=AV(in);} + else{in=w; k=AN(in)-1; u=1+AV(in);} + ASSERT(1>=AR(in),EVRANK); + ASSERT(k&&k<=(n?2:1),EVLENGTH); + j=u[0]; j=0>j?s+j:j; m=1==k?s-j:u[1]; + ASSERT(0<=j&&(!n||j<s&&j+m<=s&&0<=m),EVINDEX); + *i=j; if(n)*n=m; + R 1; +} /* process index file arg for index and length */ + +F1(jtjiread){A z=0;B b;F f;I i,n; + F1RANK(1,jtjiread,0); + RE(f=ixf(w)); if(b=!f)RZ(f=jope(w,FREAD)); + if(ixin(w,fsize(f),&i,&n))z=rd(f,i,n); + if(b)fclose(f);else fflush(f); + R z; +} + +F2(jtjiwrite){B b;F f;I i; + F2RANK(RMAX,1,jtjiwrite,0); + ASSERT(!AN(a)||AT(a)&LIT+C2T,EVDOMAIN); + ASSERT(1>=AR(a),EVRANK); + RE(f=ixf(w)); if(b=!f)RZ(f=jope(w,FUPDATE)); + if(ixin(w,fsize(f),&i,0L))wa(f,i,a); + if(b)fclose(f);else fflush(f); + RNE(mtm); +} + + +#if (SYS & SYS_MACINTOSH) + +static B setparm(C*v,C*ms,HParamBlockRec mp){I n; + n=strlen(v); + ASSERT(n<=NPATH,EVLIMIT); *ms=n; MC(1+ms,v,n); + mp.fileParam.ioNamePtr=ms; + mp.fileParam.ioVRefNum=0; + mp.fileParam.ioDirID =0; + R 1; +} + +#define DIRF(f,fsub) \ + B f(J jt,C*v){C ms[256];HParamBlockRec mp; \ + RZ(setparm(v,ms,mp)); \ + ASSERT(!fsub(&mp,0),EVFACE); \ + R 1; \ + } + +static DIRF(jtmkdir1,PBDirCreate) +static DIRF(jtrmdir1,PBHDelete ) + +static B mkdir(C*v){R!mkdir1(v);} +static B rmdir(C*v){R!rmdir1(v);} + +#endif + + +F1(jtjmkdir){A y,z; + F1RANK(0,jtjmkdir,0); + ASSERT(AT(w)&BOX,EVDOMAIN); + RZ(y=str0(vs(AAV0(w)))); +#if (SYS & SYS_UNIX) + R mkdir(CAV(y),0775)?jerrno():one; +#else + RZ(z=toutf16x(y)); + R _wmkdir((US*)CAV(z))?jerrno():one; +#endif +} + +F1(jtjferase){A y,fn;US*s;I h; + F1RANK(0,jtjferase,0); + RE(h=fnum(w)); + if(h) y=str0(fname(sc(h))); else y=AAV0(w); + ASSERT(y,EVFNUM); + if(h)RZ(jclose(sc(h))); +#if (SYS&SYS_UNIX) + R !unlink(CAV(y))||!rmdir(CAV(y))?one:jerrno(); +#else + RZ(fn=toutf16x(y)); + s=USAV(fn); + R !_wunlink(s)||!_wrmdir(s)?one:jerrno(); +#endif +} /* erase file or directory */ + +F1(jtpathcwd){C path[1+NPATH];US wpath[1+NPATH]; + ASSERTMTV(w); +#if SY_WINCE + &path;&wpath; /* avoid compiler warnings */ + R cstr("\\"); +#else +#if (SYS & SYS_UNIX) + ASSERT(getcwd(path,NPATH),EVFACE); +#else + ASSERT(_wgetcwd(wpath,NPATH),EVFACE); + jttoutf8x(jt,path,NPATH,wpath); +#endif + R cstr(path); +#endif +} + +F1(jtpathchdir){A z; + RZ(w); + ASSERT(1>=AR(w),EVRANK); + ASSERT(AN(w),EVLENGTH); + ASSERT(LIT&AT(w),EVDOMAIN); +#if SY_WINCE + &z; /* avoid compiler warning */ + ASSERT(0,EVFACE); +#else +#if (SYS & SYS_UNIX) + ASSERT(!chdir(CAV(w)),EVFACE); +#else + RZ(z=toutf16x(w)); + _wchdir((US*)CAV(z)); +#endif + R mtv; +#endif +} + +#if SY_WINCE +#define _wgetenv(s) (0) +#endif + +F1(jtjgetenv){ + F1RANK(1,jtjgetenv,0); + ASSERT(LIT&AT(w),EVDOMAIN); +#if (SYS & SYS_UNIX) + { + C*s; + R(s=getenv(CAV(w)))?cstr(s):zero; + } +#else + { + A z; US* us; + RZ(z=toutf16x(w)); + us=_wgetenv((US*)CAV(z)); + if(!us)R zero; + GA(z,C2T,wcslen(us),1,0); + memcpy(USAV(z),us,2*wcslen(us)); + R toutf8(z); + } +#endif + R zero; +} + +F1(jtjgetpid){ + ASSERTMTV(w); +#if SY_WIN32 + R(sc(GetCurrentProcessId())); +#else + R(sc(getpid())); +#endif +} + +#if (SYS & SYS_UNIX) +F1(jtpathdll){ + ASSERTMTV(w); R cstr(""); +} +#else +F1(jtpathdll){char p[MAX_PATH]; extern C dllpath[]; + ASSERTMTV(w); + strcpy(p,dllpath); + if('\\'==p[strlen(p)-1]) p[strlen(p)-1]=0; + R cstr(p); +} +#endif
new file mode 100644 --- /dev/null +++ b/xfmt.c @@ -0,0 +1,554 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: 8!:x formatting stuff */ + +#include "j.h" +#include "x.h" +#include "vcomp.h" /* for TLT & friends */ +#include "dtoa.h" + +static const D ppwrs[10]={1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9}; +static const D npwrs[10]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9}; +static const C*pp="<({["; +static const C*qq=">)}]"; + +#define SUBe subs[0] /* e */ +#define SUBc subs[1] /* , */ +#define SUBd subs[2] /* . */ +#define SUBm subs[3] /* - */ +#define SUBs subs[4] /* * */ + +/* bit flags vector: 2b0001 1111 */ +/* \|/| |||+-- 1 iff exponential notation */ +/* | | ||+--- 1 iff _ */ +/* | | |+---- 1 iff __ */ +/* | | +----- 1 iff _. */ +/* | +------- 1 iff considered to be zero */ +/* +--------- unused, should be 0 */ + +#define BITSe 1 +#define BITS_ 2 +#define BITS__ 4 +#define BITS_d 8 +#define BITSf 14 +#define BITSz 16 + +#define NMODVALS 8 + +#define mC (mods&0x0200) +#define mL (mods&0x0100) +#define mB (mods&0x0080) +#define mD (mods&0x0040) +#define mMN (mods&0x0030) +#define mPQ (mods&0x000c) +#define mR (mods&0x0002) +#define uB (u[1]) +#define uD (u[2]) +#define uM (u[3]) +#define uN (u[4]) +#define uP (u[5]) +#define uQ (u[6]) +#define uR (u[7]) +#define uS (u[8]) + + +static F1(jtfmtbfc){A*u,z;B t;C c,p,q,*s,*wv;I i,j,m,n; + RZ(w); + if(C2T&AT(w))RZ(w=uco2(num[5],w)) + ASSERT(1>=AR(w),EVDOMAIN); + n=AN(w); wv=CAV(w); t=0; m=1; j=0; + for(i=0;i<n;++i){ + c=wv[i]; + if(t){ASSERT(c!=p,EVDOMAIN); if(c==q)t=0;} + else if(c==',')++m; + else if(s=strchr(pp,c)){t=1; p=c; q=qq[s-pp];} + } + ASSERT(!t,EVDOMAIN); + GA(z,BOX,m,1<m,0); u=AAV(z); + for(i=0;i<n;++i){ + c=wv[i]; + if(t){if(c==q)t=0;} + else if(c==','){RZ(*u++=str(i-j,wv+j)); j=i+1;} + else if(s=strchr(pp,c)){t=1; q=qq[s-pp];} + } + RZ(*u=str(n-j,wv+j)); + R z; +} /* format phrases: boxed from char */ + +static B jtfmtcomma(J jt, C *x, I l, I d, C *subs) {C *v,*u;I j,n,c; + n=l-(c=(l-!!d-d)/4); u=x+l-1; + if(v=memchr(x, SUBd, n)){j=n-(v-x); u-=j; memmove(u+1,v,j); v--;} else v=x+n-1; + j=0; + DO(v-x+1, if('0'<=*v&&*v<='9'){if(j==3){*u--=SUBc; j=0;} j++;} *u--=*v--;); + R 1; +} + +static I jtdpone(J jt, B bits, D w){D t; + if(bits&BITSf) R 0; + w=ABS(w); + if(bits&BITSe) w/=pow(10,tfloor(log10(w))); + DO(10, t=npwrs[i]*jfloor(0.5+ppwrs[i]*w); if(TEQ(t,w)) R i; ); + R 9; +} + +static B jtwidthdp(J jt, A a, I *w, I *d){I n,x,y; C *v; + RZ(a&&w&&d); + RZ(a=ca(a)); n=AN(a); v=CAV(a); + DO(n, if(!strchr("0123456789.", *v)) *v=' '; v++;); + + x=strspn(CAV(a), " " ); AK(a)+=x;AM(a)-=x;AN(a)-=x;AS(a)[0]=x; + x=strspn(CAV(a), "0123456789."); + ASSERT(AN(a)-x==(I)strspn(x+CAV(a), " "), EVDOMAIN); + AN(a)=AS(a)[0]=x; + + n=AN(a); v=CAV(a); x=n; + if(n){ + ASSERT(x=strspn(v, "0123456789"), EVDOMAIN); + y=0; DO(x, y=(v[i]-'0')+10*y;); *w=*d=y; + if(n>x) { + ASSERT(v[x]=='.', EVDOMAIN); + ASSERT(n==x+1+(I)strspn(v+x+1, "0123456789"), EVDOMAIN); + y=0; DO(n-x-1, y=(v[x+1+i]-'0')+10*y;); *d=y; + } else *w=-1; + } else *w=*d=-1; + + ASSERT(-1 <= *d && *d <= 9, EVDOMAIN); + R 1; +} /* width and decimal places */ + +/* parse a single boxed format phrase */ +/* result: (width,decimal_places,modifiers);b;d;m;n;p;q;r;s */ +/* where modifiers are 2b11 1111 1111 */ +/* corresponding to cl bdmn pqrs */ +/* b d m n p q r s are the strings to use; s is '' if all defaults */ + +static F1(jtfmtparse){A x,z,*zv;B ml[2+NMODVALS],mod,t;C c,*cu="srqpnmdblc",*cu1="?bdmnpqrs",d,*s,*wv; + I fb,i,j,mi,n,n1,p,q,vals[3]={-1,-1,0}; + RZ(w); + w=AAV0(w); n=AN(w); + GA(z,BOX,1+NMODVALS,1,0); zv=AAV(z); + DO(NMODVALS, zv[1+i]=mtv;); + if(n&&C2T&AT(w))RZ(w=uco2(num[5],w)); + ASSERT(1>=AR(w),EVRANK); + ASSERT(!n||LIT&AT(w),EVDOMAIN); + wv=CAV(w); n1=1+n; t=c=0; fb=0; mi=-1; memset(ml,C1,sizeof(ml)); + for(i=0;i<n1;++i){ + mod=!t; c=wv[i]; + if(i==n)ASSERT(!t,EVDOMAIN) + else{ + if(t){ASSERT(c!=p,EVDOMAIN); if(c==q)t=0;} + else if(s=strchr(pp,c)){mod=0; t=1; p=c; q=qq[s-pp];} + } + if(!mod)continue; /* 1==mod iff not in modifier text <xx>; i.e. c is a modifier letter or 0-9 */ + if(0<=mi){ + d=wv[mi]; + ASSERT(s=strchr(cu,d),EVDOMAIN); + j=s-cu; ASSERT(ml[j],EVDOMAIN); ml[j]=0; fb|=(I)1<<j; + if(s=strchr(cu1,d)){if(i-mi>3)RZ(zv[s-cu1]=str(i-mi-3,wv+mi+2));}else ASSERT(1==i-mi,EVDOMAIN); + } + mi=i; + if('0'<=c&&c<='9'){RZ(widthdp(str(n-i,wv+i),vals,vals+1)); break;} + } + if(mtv!=zv[NMODVALS]){C*cu="e,.-*",*cv,subs[5]; + x=zv[NMODVALS]; n=AN(x); cv=CAV(x); MC(subs,cu,5L); memset(ml,C1,5L); + ASSERT(0==n%2&&10>=n,EVDOMAIN); + DO(n/2, ASSERT(s=strchr(cu,*cv++),EVDOMAIN); j=s-cu; ASSERT(ml[j],EVDOMAIN); ml[j]=0; subs[j]=*cv++;); + RZ(zv[NMODVALS]=str(5L,subs)); + } + vals[2]=fb; RZ(*zv=vec(INT,3,vals)); + R z; +} + +#if SY_WIN32 +typedef __int64 I8; +#else +typedef long long I8; +#endif +typedef union u_DI8_tag { I8 i; D d; } DI8; + +static D jtroundID(J jt,I d,D y){D f,q,c,h;DI8 f8,q8,c8; + q=ppwrs[d]*y; if(q<1) h=2; else h=0; q+=h; + f=jfloor(q); c=-jfloor(-q); + if(f==c) R npwrs[d]*(c-h); + ASSERTSYS(f<=q&&q<=c, "roundID: fqc"); + f8.d=f;q8.d=q;c8.d=c; + ASSERTSYS(0<=f8.i&&0<=q8.i&&0<=c8.i, "roundID: sign"); + if(q8.i-f8.i >= c8.i-q8.i-1) R npwrs[d]*(c-h); + else R npwrs[d]*(f-h); +} /* round a number in not in exponential notation */ + +static D jtafzrndID(J jt,I dp,D y){R SGN(y)*roundID(dp,ABS(y));} + /* round-to-nearest, solve ties by rounding Away From Zero */ + +static D jtexprndID(J jt, I d, D y){I e,s;D f,q,c,x;DI8 f8,y8,c8; + s=SGN(y); e=-(I)jfloor(log10(y=ABS(y))); + if(308 >= ABS(d+e)){e+=d;d=0;} + x=pow(10,(D)e); + q=x*(ppwrs[d]*y); /* avoid overflow to Infinity */ + f=(npwrs[d]* jfloor( q))/x; + c=(npwrs[d]*-jfloor(-q))/x; + if(f==c) R s*c; + /*ASSERTSYS(f<=y && y<=c, "exprndID: fyc");*/ /* why does this fail? */ + f8.d=f; y8.d=y; c8.d=c; + if(y8.i-f8.i >= c8.i-y8.i-1) R s*c; else R s*f; +} /* afzrnd for numbers in exponential notation */ + +static B jtsprintfI(J jt, C *x, I m, I dp, I iw, C *subs) {I r,g; + x+=m-1; + DO(dp, *x--='0';); if(dp) *x--=SUBd; r=dp+!!dp; + g=SGN(iw); iw=ABS(iw); + while(iw){ *x--='0'+(C)(iw%10); iw/=10; r++; } + if(g==0) { *x--='0'; r++; } + R 1; +} + +static B jtsprintfnD(J jt, C *x, I m, I dp, D dw, C *subs) {I nd;int decpt, sign; + if(dw==0) { memset(x, '0', m); if(dp) x[1]=SUBd; R 1; } + if(ABS(dw) < 1) nd=dp; else nd=m-!!dp; + RZ(ecvt(dw,nd,&decpt,&sign,x)); + if(decpt > 0) { + memmove(x+decpt+1, x+decpt, dp); + if(dp) x[decpt]=SUBd; + } else { + memmove(x+2-decpt, x, dp+decpt); + memset(x, '0', 2-decpt); + if(dp) x[1]=SUBd; + } + R 1; +} + +static B jtsprintfeD(J jt, C *x, I m, I dp, D dw, C *subs) {I y,y0;int decpt,sign; + RZ(ecvt(dw,1+dp,&decpt,&sign,x+!!dp)); + if(dp) { x[0]=x[1]; x[1]=SUBd; } + x += 1+!!dp+dp; *x++=SUBe; + if(decpt<0) *x++=SUBm; decpt--; decpt=ABS(decpt); + ASSERTSYS(1000>decpt, "jtsprintfeD: decpt"); + y0=decpt/100; if(y0) *x++='0'+(C)y0; decpt%=100; + y =decpt/10 ; if(y||y0) *x++='0'+(C)y ; decpt%=10; + y =decpt ; *x++='0'+(C)y ; + R 1; +} + +/* the output of jtfmtprecomp looks like this */ +/* z =: base ; strings ; length ; bitflags */ +/* given the following: */ +/* nc =: {: $ y. NB. the number of columns */ +/* nf is the number of format phrases */ +/* if. 1 < nf do. */ +/* base =:(nf,4)$width_0, decimal_places_0, modifiers_0, col_width_0, ... */ +/* else. */ +/* base =:(3+nc)$width, dec_places, mods, col_width_0, col_width_1, ... */ +/* end. */ +/* strings =:(nf,8)$b0;d0;m0;n0;p0;q0;r0;s0; b1;d1; ... */ +/* length =:($y.)$number_length_0_0, number_length_0_1, ... (in w, not */ +/* bitflags=:($y.)$bitflags_0_0, bitflags_0_1, ... column order) */ + +#define mods_coldp 0x40000000 /* applied to modifiers when we're computing this columns # of decimal places */ + +static F2(jtfmtprecomp) {A*as,base,fb,len,strs,*u,z;B*bits,*bw;D dtmp,*dw; + I d,i,*ib,*iw,*iv,maxl,mods,n,nB,nD,nMN,nPQ,nc,nf,*s,wr,*ws,wt; + RZ(a&&w); + nf=1==AR(a)?1:*AS(a); n=AN(w); wt=AT(w); wr=AR(w); ws=AS(w); nc=wr?ws[wr-1]:1; + ASSERT(wt&B01+INT+FL, EVDOMAIN); + if(1<nf){GA(base,INT,nf*4,2,0); s=AS(base); *s++=nf; *s=4;}else GA(base,INT,3+nc,1,0); + GA(strs,BOX,nf*NMODVALS,2,0); s=AS(strs); *s++=nf; *s=NMODVALS; + GA(len, INT,n,wr,ws); + GA(fb, B01,n,wr,ws); memset(BAV(fb),C0,n); + GA(z,BOX,4,1,0); u=AAV(z); *u++=base; *u++=strs; *u++=len; *u++=fb; + ib=AV(base); as=AAV(strs); u=AAV(a); + if(1==nf){MC(ib,AV(*u),SZI*3); memset(ib+3,C0,SZI*nc); MC(as,u+1,SZA*NMODVALS);} + else DO(nf, MC(ib,AV(*u),SZI*3); ib[3]=0; ib+=4; MC(as,u+1,SZA*NMODVALS); as+=NMODVALS; u+=1+NMODVALS;); + bits=BAV(fb); + switch(wt) { + case B01: + bw=BAV(w); ib=AV(base); + DO(n, *bits|=BITSz*!*bw; bits++; bw++;); /* BITSe, BITS_, BITS__, and BITS_d are 0 */ + DO(nf, if(ib[1]==-1)ib[1]=0; ib+=4;); /* boolean always has 0 decimal places: */ + break; + case INT: + iw=AV(w); ib=AV(base); iv=AV(len); /* use len to store dp */ + for(i=0;i<n;++i){ + if(i%nf) ib += 4; else ib=AV(base); + d=ib[1]; + if(d==-1) *bits |= BITSe * (2000000000L < ABS(*iw)); + /* BITS_, BITS__, and BITS_d are 0 */ + *bits |= BITSz*!*iw; + if(d==-1) *iv = dpone(*bits,(D)*iw); + bits++; iw++; iv++; + } + ib=AV(base); iv=AV(len); + for(i=0;i<n;++i){ + if(i%nf) ib += 4; else ib=AV(base); + if(ib[1]==-1) ib[2] |= mods_coldp; + if(ib[2]&mods_coldp && *iv>ib[1]) ib[1]=*iv; + iv++; + } + break; + case FL: + dw=DAV(w); ib=AV(base); iv=AV(len); /* use len to store dp */ + for(i=0;i<n;++i){ + if(i%nf) ib+=4; else ib=AV(base); + d=ib[1]; + dtmp=ABS(*dw); + if(d==-1) *bits |= BITSe*(TNE(0,dtmp) && (TLT(dtmp,1e-9)||TLT(2e9,dtmp))); + *bits |= BITS_ *!memcmp(dw, &inf , SZD)+ + BITS__*!memcmp(dw, &infm, SZD)+ + BITS_d*_isnan(*dw); + if(d==-1) *iv = dpone(*bits,*dw); + else *bits |= BITSz*(TEQ(*dw, 0) || (!(*bits&BITSf+BITSe) && TLT(dtmp, npwrs[d]/2))); + bits++; dw++; iv++; + } + ib=AV(base); iv=AV(len); + for(i=0;i<n;++i){ + if(i%nf) ib+=4; else ib=AV(base); + if(ib[1]==-1) ib[2] |= mods_coldp; + if(ib[2]&mods_coldp&&*iv>ib[1]) ib[1]=*iv; + ASSERTSYS(0<=ib[1]&&9>=ib[1], "jtfmtprecomp: d oob"); + iv++; + } + bits=BAV(fb); dw=DAV(w); ib=AV(base); + DO(n, + if(i%nf) ib+=4; else ib=AV(base); + d=ib[1]; + if(ib[2]&mods_coldp){ + *bits |= BITSz*(TEQ(*dw, 0) || (!(*bits&BITSf+BITSe) && TLT(ABS(*dw), npwrs[d]/2))); + } + bits++; dw++; + ); + } + + iv=AV(len); bits=BAV(fb); + iw=AV(w); dw=DAV(w); maxl=-1; + ib=AV(base); u=AAV(strs)-1; + for(i=0;i<n;i++) { + if(i%nf){ib+=4; u+=NMODVALS;} + else{ib=AV(base);u=AAV(strs)-1;} + nB=AN(uB); nD=AN(uD); nMN=AN(uM)+AN(uN); nPQ=AN(uP)+AN(uQ); + d=ib[1]; mods=ib[2]; + if(*bits&BITSf) { if(mD) *iv=nD; else *iv=2-!!(*bits&BITS_); } + else if(*bits&BITSz) { + if(mB) *iv=nB; + else { + *iv=1+d+!!d; + if(mPQ) (*iv) += nPQ; + } + } else if(*bits&BITSe) { + if(FL&wt) { + if (ABS(*dw) < 1e-99) *iv=2+!!d+d+1+3; + else if(ABS(*dw) < 1 ) *iv=2+!!d+d+1+2; + else if(ABS(*dw) < 1e10 ) *iv=2+!!d+d+ 1; + else if(ABS(*dw) < 1e100) *iv=2+!!d+d+ 2; + else *iv=2+!!d+d+ 3; + if(*dw < 0) { if(mMN) (*iv)+=nMN; else (*iv)++; } + else if(mPQ) (*iv)+=nPQ; + } else { +#if SY_64 + if (ABS(*iw) < 10000000000L) *iv=2+!!d+d+ 1; + else *iv=2+!!d+d+ 2; +#else + *iv=2+!!d+d+ 1; +#endif + if(*iw < 0) { if(mMN) (*iv)+=nMN; else (*iv)++; } + else if(mPQ) (*iv) += nPQ; + } + } else { + if(B01&wt) *iv=1+!!d+d; + else { + if(B01&wt) dtmp=1; if(INT&wt) dtmp=(D)*iw; else dtmp=*dw; + *iv=(I)jfloor(log10(roundID(d,MAX(ABS(dtmp),1)))); + if(mC) (*iv)+=(*iv)/3; + (*iv)+=1+!!d+d; + if(dtmp < 0 && mMN) (*iv)+=nMN; + else if(dtmp < 0) (*iv)++; + else if(mPQ) (*iv)+=nPQ; + } + } + ASSERTSYS(0 <= *iv, "jtfmtprecomp: cell length"); + if(*iv > maxl) maxl=*iv; + if(1<nf && *iv > ib[3]) ib[3]=*iv; + else if(1==nf && *iv > ib[3+i%nc]) ib[3+i%nc]=*iv; + bits++; dw++; iw++; iv++; + } + ib=AV(base); + if(1==nf){if(!ib[0])ib[0]=maxl;}else DO(nf, if(ib[0]==0)ib[0]=ib[3]; ib+=4;); + R z; +} /* format: precomputation to separate the group and column concept */ + +/* a is jtfmtprecomp result */ +/* w is argument to format, but with BO1, INT, or FL type. */ +static A jtfmtallcol(J jt, A a, A w, I mode) {A *a1v,base,fb,len,strs,*u,v,x; + B *bits,*bv;C*cB,*cD,*cM,*cN,*cP,*cQ,*cR,*cv,**cvv,*cx,*subs;D dtmp,*dv; + I coll,d,g,h,i,*ib,*iv,*il,j,k,l,m,mods,n,nB,nD,nM,nN,nP,nQ,nR,nc,nf,t,wr,*ws,y,zs[2]; + RZ(a); u=AAV(a); base=*u++; strs=*u++; len=*u++; fb=*u++; u=0; subs=0; + RZ(w); n=AN(w); t=AT(w); wr=AR(w); ws=AS(w); nc=wr?ws[wr-1]:1; + ASSERT(B01+INT+FL&t, EVDOMAIN); + + nf=1==AR(base)?1:AS(base)[0]; + switch(mode){ + case 0: + GA(x, BOX, n, wr, ws); a1v=AAV(x); il=AV(len); ib=AV(base); + DO(n, + if(i%nf) ib+=4; else ib=AV(base); + if(0<ib[0]) GA(*a1v, LIT, ib[0], 1, 0) + else GA(*a1v, LIT, *il, 1, 0) + memset(CAV(*a1v), ' ', AN(*a1v)); + a1v++; il++; + ); + break; + case 1: + GA(x, BOX, nc, 1, 0); a1v=AAV(x); ib=AV(base); zs[0]=prod(wr-1,ws); + GA(v, LIT, nc*SZA, 1, 0); cvv=(C**)AV(v); + DO(nc, + if(0<ib[0]) zs[1]=ib[0]; + else zs[1]=ib[3+(1<nf?0:i%nc)]; + GA(*a1v, LIT, zs[0]*zs[1], 2, zs); + memset(CAV(*a1v), ' ', AN(*a1v)); + *cvv++=CAV(*a1v); + a1v++; if(1<nf) ib+=4; + ); + cvv=(C**)AV(v); + break; + case 2: + coll=0; ib=AV(base); + DO(nc, if(0<ib[0]) coll+=ib[0]; else coll+=ib[3+(1<nf?0:i%nc)]; + if(1<nf) ib+=4; ); + zs[0]=prod(wr-1,ws); zs[1]=coll; + GA(x, LIT, zs[0]*zs[1], 2, zs); + memset(CAV(x), ' ', AN(x)); + break; + default: ASSERTSYS(0, "jtfmtallcol: mode"); + } + + a1v=AAV(x); cx=CAV(x); il=AV(len); bits=BAV(fb); + bv=BAV(w); iv=IAV(w); dv=DAV(w); + + u=AAV(strs)-1; ib=AV(base); j=h=0; + for(i=0;i<n;i++) { + if(1<nf) { + if(h==nf) h=0; + if(h) { ib += 4; u += NMODVALS; } + else { ib=AV(base); u=AAV(strs)-1; } + } + if(j==nc) j=0; + k=l=ib[0]; d=ib[1]; mods=ib[2]; coll=ib[3+(1==nf)*j]; + nB= AN(uB); nD= AN(uD); nM= AN(uM); nN= AN(uN); nP= AN(uP); nQ= AN(uQ); nR= AN(uR); + cB=CAV(uB); cD=CAV(uD); cM=CAV(uM); cN=CAV(uN); cP=CAV(uP); cQ=CAV(uQ); cR=CAV(uR); + subs=AN(uS)?CAV(uS):"e,.-*"; + switch(mode) { + case 0: v=*a1v; cv=CAV(v); break; + case 1: k=0<l?l:coll; cv=cvv[j]; cvv[j]+=k; break; + case 2: k=0<l?l:coll; cv=cx; cx+=k; break; + default: ASSERTSYS(0, "jtfmtallcol: mode"); + } + if(0<l && l<*il) memset(cv,SUBs,l); + else { + if(0<=l && mL){if(nR)mvc(k,cv,nR,cR); else memset(cv+*il, ' ', l-*il);} + else if(0<=l) {if(nR)mvc(k,cv,nR,cR); else memset(cv, ' ', l-*il); cv+=l-*il;} + if(*bits&BITSf) { + if(mD) MC(cv, cD, nD); + else if(*bits&BITS_ ) { cv[0]='_'; } + else if(*bits&BITS__) { cv[0]='_'; cv[1]='_'; } + else { cv[0]='_'; cv[1]='.'; } + } else if(*bits&BITSz) { + if(mB) MC(cv, cB, nB); + else { + if(mPQ) { MC(cv, cP, nP); MC(cv+*il-nQ, cQ, nQ); } + RZ(sprintfI(cv+nP,*il-nP-nQ,d,0,subs)); + } + } else if(*bits&BITSe) { + dtmp=t&FL?*dv:(D)*iv; + y=dtmp < 0; g=0; + if(dtmp < 0 && mMN) { y=nM; g=nN; } + else if(dtmp>=0 && mPQ) { y=nP; g=nQ; } + RZ(sprintfeD(cv+y,*il-y-g,d,exprndID(d,dtmp),subs)); + if (dtmp< 0 && mMN) { MC(cv, cM, nM); MC(cv+*il-nN, cN, nN); } + else if(dtmp< 0 ) { *cv=SUBm; } + else if(dtmp>=0 && mPQ) { MC(cv, cP, nP); MC(cv+*il-nQ, cQ, nQ); } + } else { + switch(t) { + case B01: + if(mPQ) { MC(cv, cP, nP); MC(cv+*il-nQ, cQ, nQ); } + RZ(sprintfI(cv+nP, *il-nP-nQ, d, *bv, subs)); + break; + case INT: + y=*iv < 0; g=0; + if(*iv < 0 && mMN) { y=nM; g=nN; } + else if(*iv>=0 && mPQ) { y=nP; g=nQ; } + m=*il-y-g; if(mC) m=m-(m-!!d-d)/4; + RZ(sprintfI(cv+y, m, d, *iv, subs)); + if(mC) RZ(fmtcomma(cv+y, *il-y-g, d, subs)); + if (*iv < 0 && mMN) { MC(cv, cM, nM); MC(cv+*il-nN, cN, nN); } + else if(*iv < 0 ) { *cv=SUBm; } + else if(*iv>= 0 && mPQ) { MC(cv, cP, nP); MC(cv+*il-nQ, cQ, nQ); } + break; + case FL: + y=*dv < 0; g=0; + if(*dv < 0 && mMN) { y=nM; g=nN; } + else if(*dv>=0 && mPQ) { y=nP; g=nQ; } + m=*il-y-g; if(mC) m=m-(m-!!d-d)/4; + RZ(sprintfnD(cv+y, m, d, afzrndID(d,*dv), subs)); + if(mC) RZ(fmtcomma(cv+y, *il-y-g, d, subs)); + if (*dv < 0 && mMN) { MC(cv, cM, nM); MC(cv+*il-nN, cN, nN); } + else if(*dv < 0 ) { *cv=SUBm; } + else if(*dv>= 0 && mPQ) { MC(cv, cP, nP); MC(cv+*il-nQ, cQ, nQ); } + break; + }}} + a1v++; il++; bits++; bv++; iv++; dv++; h++; j++; + } + + R x; +} /* format w */ + +static A jtfmtxi(J jt, A a, A w, I mode, I *omode){I lvl; + RZ(a&&w); *omode=0; + if(SPARSE&AT(w)) RZ(w=denseit(w)); + if(!AN(w)) RZ(w=reshape(shape(w),chr[' '])); + if(JCHAR&AT(w)) R df1(w,qq(atop(ds(CBOX),ds(CCOMMA)),one)); + ASSERT(1>=AR(a), EVRANK); + ASSERT(!AN(a) || JCHAR+BOX&AT(a), EVDOMAIN); + if(JCHAR&AT(a)||!AN(a)) RZ(a=fmtbfc(a)); + ASSERT(1>=AR(a), EVRANK); + ASSERT(0==AR(a) || AN(a)==AS(w)[AR(w)-1], EVLENGTH); + /* catch out-of-memory errors from dtoa.c */ + if(setjmp(((struct dtoa_info*)jt->dtoa)->_env))ASSERTSYS(jt->jerr, "dtoa"); + if(lvl=level(w)){A*wv=AAV(w),x;I wd=(I)w*ARELATIVE(w); + ASSERT(1>=lvl, EVDOMAIN); + DO(AN(w), x=WVR(i); ASSERT(1>=AR(x),EVRANK); if(AN(x)){ASSERT(AT(x)&JCHAR+NUMERIC,EVDOMAIN); + ASSERT(!(AR(x)&&AT(x)&NUMERIC),EVRANK);}); + R df2(reitem(shape(w),a),w,amp(foreign(num[8],num[0]), ds(COPE))); + } else { + if(XNUM+RAT+CMPX&AT(w))RZ(w=cvt(FL,w)); + *omode=mode; + R fmtallcol(fmtprecomp(rank1ex(a,0L,0L,jtfmtparse),w),w,mode); +}} /* 8!:x internals */ + /* mode is the requested mode, *omode is the actual mode computed */ + /* mode is 0, 1, or 2 for 8!:0, 8!:1, or 8!:2 */ + /* *omode is either 0 or mode */ + +F2(jtfmt02){I mode; R fmtxi(a,w,0,&mode);} /* 8!:0 dyad */ + +F2(jtfmt12){A z;I mode,r,*s; + RZ(a&&w); + ASSERT(2>=AR(w), EVRANK); + RZ(z=fmtxi(a,w,1,&mode)); + if(mode==1)R z; + r=AR(z); s=AS(z); + z=df1(cant1(2==r?z:reshape(v2(1L,r?*s:1L),z)), qq(atco(ds(CBOX),ds(COPE)),one)); + R ravel(z); +} /* 8!:1 dyad */ + +F2(jtfmt22){A z;I mode,r,*s; + RZ(a&&w); + ASSERT(2>=AR(w), EVRANK); + RZ(z=fmtxi(a,w,2,&mode)); + if(mode==2)R z; + r=AR(z); s=AS(z); + z=df1(cant1(2==r?z:reshape(v2(1L,r?*s:1L),z)), qq(atco(ds(CBOX),ds(COPE)),one)); + RZ(z=ravel(z)); + R *AS(z)?razeh(z):lamin1(z); +} /* 8!:2 dyad */ + +F1(jtfmt01){RZ(w); R fmt02(AR(w)?reshape(sc(*(AS(w)+AR(w)-1)),ace):ace,w);} /* 8!:0 monad */ +F1(jtfmt11){RZ(w); R fmt12(AR(w)?reshape(sc(*(AS(w)+AR(w)-1)),ace):ace,w);} /* 8!:1 monad */ +F1(jtfmt21){RZ(w); R fmt22(AR(w)?reshape(sc(*(AS(w)+AR(w)-1)),ace):ace,w);} /* 8!:2 monad */
new file mode 100644 --- /dev/null +++ b/xh.c @@ -0,0 +1,104 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Host Command Facilities */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#else +#include <unistd.h> +#endif + +#include "j.h" +#include "x.h" + +#if (SYS & SYS_ARCHIMEDES) +#define Wimp_StartTask 0x400DE +extern int os_swi1(I,I); +#endif + + +#if (SYS & SYS_MACINTOSH) + +F1(jthost ){ASSERT(0,EVDOMAIN);} +F1(jthostne){ASSERT(0,EVDOMAIN);} + +#else + +F1(jthost){A z; + F1RANK(1,jthost,0); + RZ(w=vs(w)); +#if (SYS & SYS_PCWIN) + ASSERT(0,EVDOMAIN); +#else +{ + A t;I b;C*fn,*s;F f;I n; + n=AN(w); + GA(t,LIT,n+5+L_tmpnam,1,0); s=CAV(t); + fn=5+n+s; MC(s,AV(w),n); + MC(n+s," > ",5L); {C* t=tmpnam(fn);} + b=!system(s); + if(b){f=fopen(fn,FREAD); z=rd(f,0L,-1L); fclose(f);} + unlink(fn); + ASSERT(b&&f,EVFACE); +} +#endif + R z; +} + +F1(jthostne){C*s; + F1RANK(1,jthostne,0); + RZ(w=vs(w)); + s=CAV(w); +#if SYS & SYS_PCWIN + ASSERT(0,EVNONCE); +#else + { + I b; + b=system(s); +#if !SY_64 && (SYS&SYS_LINUX) + //Java-jnative-j.so system always returns -1 + if(jt->sm==SMJAVA&&-1==b) b=-1==system("")?0:-1; +#endif + b=!b; + ASSERT(b,EVFACE); + } +#endif + R mtv; +} + +#endif + + +#if !(SYS & SYS_UNIX) + +F1(jthostio){ASSERT(0,EVDOMAIN);} +F1(jtjwait ){ASSERT(0,EVDOMAIN);} + +#else + +#define CL(f) {close(f[0]);close(f[1]);} + +F1(jthostio){C*s;A z;F*pz;I fi[2],fo[2],r;int fii[2],foi[2]; + fii[0]=fi[0];fii[1]=fi[1];foi[0]=fo[0];foi[1]=fo[1]; + F1RANK(1,jthostio,0); + RZ(w=vs(w)); + s=CAV(w); GA(z,INT,3,1,0); pz=(F*)AV(z); + if((r=pipe(fii))==-1||pipe(foi)==-1){if(r!=-1)CL(fi); ASSERT(0,EVFACE);} + if(!((pz[1]=fdopen(fi[0],"r"))&&(pz[2]=fdopen(fo[1],"w")))){ + if(pz[1])fclose(pz[1]); CL(fi);CL(fo);} + if(!add2(pz[1],pz[2],s)){fclose(pz[1]);fclose(pz[2]); + CL(fi);CL(fo);} + switch(r=fork()){ + case -1:CL(fi);CL(fo);ASSERT(0,EVFACE); + case 0:close(0);{int i=dup(fo[0]);};close(1);{int i=dup(fi[1]);};CL(fi);CL(fo); + execl("/bin/sh","/bin/sh","-c",s,NULL); exit(-1); + }close(fo[0]);close(fi[1]); + add2(NULL,NULL,NULL); pz[0]=(F)r; + R z; +} + +F1(jtjwait){I k;int s; RE(k=i0(w)); if(-1==waitpid(k,&s,0))jerrno(); R sc(s);} + +#endif
new file mode 100644 --- /dev/null +++ b/xi.c @@ -0,0 +1,14 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Implementation Internals */ + +#include "j.h" +#include "x.h" + + +F1(jtaflag1){RZ(w); R sc(AFLAG(w));} + +F2(jtaflag2){I k; RZ(a&&w); RE(k=i0(a)); AFLAG(w)=k; R w;} + +F1(jthash){RZ(w=vs(w)); R sc(hic(AN(w),UAV(w)));}
new file mode 100644 --- /dev/null +++ b/xl.c @@ -0,0 +1,82 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: File Lock/Unlock */ + +#include "j.h" +#include "x.h" + +#if SY_WINCE || !(SYS & SYS_DOS+SYS_MACINTOSH) +#define LOCK 1 +static B jtdolock(J jt,B lk,F f,I i,I n){ASSERT(0,EVNONCE);} +#endif + +#if SY_WIN32 && SYS&SYS_DOS && !SY_WINCE +#define LOCK 1 +#include <sys/locking.h> + +extern int _locking(int,int,long); + +static B jtdolock(J jt,B lk,F f,I i,I n){I e;long c;fpos_t v; fpos_t q; + c=fgetpos(f,(fpos_t*)&q); + if(0!=c)R (B)jerrno(); + v=i; + c=fsetpos(f,(fpos_t*)&v); + if(0!=c)R (B)jerrno(); + e=_locking(_fileno(f),lk?_LK_NBLCK:_LK_UNLCK,(long)n); + fsetpos(f,(fpos_t*)&q); + R !e?1:errno==EACCES?0:(B)jerrno(); +} +#endif + +#ifndef LOCK +static B jtdolock(J jt,B lk,F f,I i,I n){I e; + e=lk?lock(fileno(f),i,n):unlock(fileno(f),i,n); + R !e?1:errno==EACCES?0:jerrno(); +} +#endif + +#define LKC 3 /* number of columns in jt->flkd table */ + +B jtxlinit(J jt){A x;I*s; + GA(x,INT,20*LKC,2,0); s=AS(x); s[0]=20; s[1]=LKC; ra(x); + jt->flkd=x; + R 1; +} + +F1(jtjlocks){A y; ASSERTMTV(w); y=take(sc(jt->flkn),jt->flkd); R grade2(y,y);} + /* return the locks, a 3-column table of (number,index,length) */ + +F1(jtjlock){B b;I*v; + F1RANK(1,jtjlock,0); + RZ(w=vi(w)); + ASSERT(LKC==AN(w),EVLENGTH); + v=AV(w); RE(vfn((F)*v)); ASSERT(0<=v[1]&&0<=v[2],EVDOMAIN); + if(jt->flkn==*AS(jt->flkd))RZ(jt->flkd=ext(1,jt->flkd)); + RE(b=dolock(1,(F)v[0],v[1],v[2])); + if(!b)R zero; + ICPY(AV(jt->flkd)+LKC*jt->flkn,v,LKC); ++jt->flkn; + R one; +} /* w is (number,index,length); lock the specified region */ + +static A jtunlj(J jt,I j){B b;I*u,*v; + RE(j); + ASSERT(0<=j&&j<jt->flkn,EVINDEX); + u=AV(jt->flkd); v=u+j*LKC; + RE(b=dolock(0,(F)v[0],v[1],v[2])); + if(!b)R zero; + --jt->flkn; + if(j<jt->flkn)ICPY(v,u+jt->flkn*LKC,LKC); else *v=0; + R one; +} /* unlock the j-th entry in jt->flkd */ + +B jtunlk(J jt,I x){I j=0,*v=AV(jt->flkd); + while(j<jt->flkn){while(x==*v)RZ(unlj(j)); ++j; v+=LKC;} + R 1; +} /* unlock all existing locks for file# x */ + +F1(jtjunlock){ + F1RANK(1,jtjunlock,0); + ASSERT(INT&AT(w),EVDOMAIN); + R unlj(i0(indexof(jt->flkd,w))); +} /* w is (number,index,length); unlock the specified region */
new file mode 100644 --- /dev/null +++ b/xo.c @@ -0,0 +1,145 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: File Open/Close */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#ifndef UNDER_CE +#include <io.h> +#include <fcntl.h> +#endif +#endif + +#include "j.h" +#include "x.h" + + +B jtxoinit(J jt){A x; +#if SY_WIN32 && !SY_WINCE + _setmode(_fileno(stdin),_O_BINARY); + _setmode(_fileno(stdout),_O_BINARY); + _setmode(_fileno(stderr),_O_BINARY); +#endif + GA(x,BOX,8,1,0); memset(AV(x),C0,AN(x)*SZI); ra(x); jt->fopa=x; + GA(x,INT,8,1,0); ra(x); jt->fopf=x; + R 1; +} + +F jtvfn(J jt,F x){I*v=AV(jt->fopf); DO(jt->fopn,if(x==(F)*v++)R x;); ASSERT(0,EVFNUM);} + /* check that x is in table of file#s */ + +I jtfnum(J jt,A w){A y;I h,j; + if(AT(w)&B01+INT){ASSERT(h=i0(w),EVFNUM); R h;} + ASSERT(AT(w)&BOX,EVDOMAIN); + y=AAV0(w); + ASSERT(AN(y),EVLENGTH); + if(AT(y)&B01+INT){ASSERT(h=i0(y),EVFNUM); R h;} + RE(j=i0(indexof(vec(BOX,jt->fopn,AAV(jt->fopa)),box(fullname(vs(y)))))); + R j<jt->fopn?*(j+AV(jt->fopf)):0; +} /* file# corresp. to standard argument w */ + +F1(jtfname){I j; + RE(j=i0(indexof(jt->fopf,w))); + R j<jt->fopn?ca(*(j+AAV(jt->fopa))):(A)0; +} /* string name corresp. to file# w */ + +F1(jtjfiles){A y; + ASSERTMTV(w); + RZ(y=vec(INT,jt->fopn,AV(jt->fopf))); + R grade2(stitch(box0(y),vec(BOX,jt->fopn,AV(jt->fopa))),y); +} /* file (number,name) table */ + +F jtjope(J jt,A w,C*mode){A t;F f;I n;static I nf=25; A z; + RZ(w); + ASSERT(BOX&AT(w),EVDOMAIN); + RZ(t=str0(vs(AAV0(w)))); + n=AN(t)-1; + ASSERT(n,EVLENGTH); +#if (SYS&SYS_UNIX) +{ + C* cs=CAV(t); + f=fopen(cs,mode); + if(!f&&errno==ENOENT&&!strcmp(mode,FUPDATE))f=fopen(cs,FUPDATEC); + if(!f&&errno==EACCES&& strcmp(mode,FREAD ))f=fopen(cs,FREAD); +} +#else +{ + US usmode[10]; US*s; I i; + RZ(z=jttoutf16x(jt,t)); + s=(US*)CAV(z); + for(i=0;i<(I)strlen(mode);++i){usmode[i]=(US)mode[i];} + usmode[i]=0; +#if !SY_WINCE + f=_wfopen(s,usmode); + if(!f&&errno==ENOENT&&!wcscmp(usmode,FLUPDATE))f=_wfopen(s,FLUPDATEC); + if(!f&&errno==EACCES&& wcscmp(usmode,FLREAD ))f=_wfopen(s,FLREAD); +#else + { + f=_wfopen(s,usmode); + if(!f&&!wcscmp(usmode,FLUPDATE))f=_wfopen(s,FLUPDATEC); // no errno on wince + if(!f&& wcscmp(usmode,FLREAD ))f=_wfopen(s,FLREAD); + } +#endif +} +#endif + R f?f:(F)jerrno(); +} + +F1(jtjopen){A z;I h; + RZ(w); + if(!AN(w))R w; + if(AR(w))R rank1ex(w,0L,0L,jtjopen); + RE(h=fnum(w)); + if(h){RZ(z=sc(h)); ASSERT(fname(z),EVFNUM); R z;} + else{ + if(jt->fopn==AN(jt->fopf)){RZ(jt->fopa=ext(1,jt->fopa)); RZ(jt->fopf=ext(1,jt->fopf));} + RZ(*(jt->fopn+IAV(jt->fopf))=h=(I)jope(w,FUPDATE)); + RZ(*(jt->fopn+AAV(jt->fopa))=ra(fullname(AAV0(w)))); + ++jt->fopn; + R sc(h); +}} /* open the file named w if necessary; return file# */ + +B jtadd2(J jt,F f1,F f2,C*cmd){A c; + if(f1==NULL) {jt->fopn+=2;R 1;}; + GA(c,LIT,1+strlen(cmd),1,0);MC(CAV(c)+1,cmd,AN(c)-1);cmd=CAV(c); + if(jt->fopn+1>=AN(jt->fopf)){RZ(jt->fopa=ext(1,jt->fopa)); RZ(jt->fopf=ext(1,jt->fopf));} + *cmd='<';RZ(*(jt->fopn+AAV(jt->fopa) )=ra(cstr(cmd))); RZ(*(jt->fopn+IAV(jt->fopf) )=(I)f1); + *cmd='>';RZ(*(jt->fopn+AAV(jt->fopa)+1)=ra(cstr(cmd))); RZ(*(jt->fopn+IAV(jt->fopf)+1)=(I)f2); + fa(c); R 1; +} /* add 2 entries to jt->fopn table (for hostio); null arg commits entries */ + + +F1(jtjclose){A*av;I*iv,j; + RZ(w); + if(!AN(w))R w; + if(AR(w))R rank1ex(w,0L,0L,jtjclose); + RE(j=i0(indexof(jt->fopf,sc(fnum(w))))); ASSERT(j<jt->fopn,EVFNUM); + av=AAV(jt->fopa); iv=IAV(jt->fopf); +#if (SYS & SYS_DOS+SYS_MACINTOSH) + RZ(unlk(iv[j])); +#endif + if(fclose((F)iv[j]))R jerrno(); + --jt->fopn; fa(av[j]); if(j<jt->fopn){av[j]=av[jt->fopn]; iv[j]=iv[jt->fopn];} + R one; +} /* close file# w */ + +F jtstdf(J jt,A w){A y;F f;I n,r,t; + RZ(w); + ASSERT(AN(w),EVLENGTH); + ASSERT(!AR(w),EVRANK); + if(BOX&AT(w)){ + y=AAV0(w); t=AT(y); n=AN(y); r=AR(y); + if(t&LIT){ASSERT(1>=r,EVRANK); ASSERT(n,EVLENGTH); R 0;} +/*! + if(t&C2T){ASSERT(1>=r,EVRANK); ASSERT(n,EVLENGTH); ASSERT(vc1(n,(US*)AV(y)),EVDOMAIN); R 0;} + vc1 can now be killed off +*/ + if(t&B01+INT)R stdf(y); + ASSERT(0,EVDOMAIN); + } + f=(F)i0(w); + ASSERT(f,EVFNUM); + R f; +} /* 0 if w is a boxed file name; n if w is integer or boxed integer */
new file mode 100644 --- /dev/null +++ b/xs.c @@ -0,0 +1,106 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: Scripts */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#endif + +#include "j.h" +#include "x.h" + + +B jtxsinit(J jt){A x; + GA(x,BOX,10,1,0); memset(AV(x),C0,AN(x)*SZI); ra(x); jt->slist=x; + jt->slisti=-1; + R 1; +} + +F1(jtsnl){ASSERTMTV(w); R vec(BOX,jt->slistn,AAV(jt->slist));} + /* 4!:3 list of script names */ + +#if (SYS & SYS_MACINTOSH) +void setftype(C*v,OSType type,OSType crea){C p[256];FInfo f; + __c2p(v,p); + GetFInfo(p,0,&f); + f.fdType=type; f.fdCreator=crea; + SetFInfo(p,0,&f); +} +#endif + +/* line/linf arguments: */ +/* a: left argument for unlock */ +/* w: input file or lines; 1 means keyboard */ +/* si: script index */ +/* ce: 0 stop on error */ +/* 1 continue on error */ +/* 2 stop on error or nonunit result */ +/* 3 ditto, but return 0 or 1 result and */ +/* do not display error */ +/* tso: echo to stdout */ + +static A jtline(J jt,A w,I si,C ce,B tso){A x=mtv,z;B xt=jt->tostdout;DC d,xd=jt->dcs;I old; + if(equ(w,one))R mtm; + RZ(w=vs(w)); + FDEPINC(1); + RZ(d=deba(DCSCRIPT,0L,w,(A)si)); + jt->dcs=d; jt->tostdout=tso&&!jt->seclev; + old=jt->tbase+jt->ttop; + switch(ce){ + case 0: while(x&&!jt->jerr){jt->etxn=0; immex(x=jgets(" ")); tpop(old);} break; + case 1: while(x ){if(!jt->seclev)showerr(); jt->jerr=0; immex(x=jgets(" ")); tpop(old);} break; + case 2: + case 3: while(x&&!jt->jerr){jt->etxn=0; immea(x=jgets(" ")); tpop(old);} + jt->asgn=0; + } + jt->dcs=xd; jt->tostdout=xt; + debz(); + FDEPDEC(1); + if(3==ce){z=jt->jerr?zero:one; RESETERR; R z;}else RNE(mtm); +} + +static A jtlinf(J jt,A a,A w,C ce,B tso){A x,y,z;B lk=0;C*s;I i=-1,n,oldi=jt->slisti,oldk=jt->glock; + RZ(a&&w); + ASSERT(AT(w)&BOX,EVDOMAIN); + if(jt->seclev){ + y=AAV0(w); n=AN(y); s=CAV(y); + ASSERT(LIT&AT(y),EVDOMAIN); + ASSERT(3<n&&!memcmp(s+n-3,".js",3L)||4<n&&!memcmp(s+n-4,".ijs",4L),EVSECURE); + } + RZ(x=jfread(w)); + if(a!=mark||AN(x)&&CFF==*CAV(x)){ + RZ(x=unlock2(a,x)); + ASSERT(CFF!=*CAV(x),EVDOMAIN); + lk=1; + } + RZ(y=fullname(AAV0(w))); + RE(i=i0(indexof(vec(BOX,jt->slistn,AAV(jt->slist)),box(y)))); + if(jt->slistn==i){ + if(jt->slistn==AN(jt->slist))RZ(jt->slist=ext(1,jt->slist)); + RZ(*(jt->slistn+AAV(jt->slist))=ra(y)); + ++jt->slistn; + } + jt->slisti=i; jt->glock=1==jt->glock?1:lk?2:0; + z=line(x,jt->glock?-1L:i,ce,(B)(jt->glock?0:tso)); + jt->slisti=oldi; jt->glock=1==jt->glock?1:oldk; +#if SYS & SYS_PCWIN + if(lk)memset(AV(x),C0,AN(x)); /* security paranoia */ +#endif + R z; +} + +F1(jtscm00 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtscm00, 0); R r?line(w,-1L,0,0):linf(mark,w,0,0);} +F1(jtscm01 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtscm01, 0); R r?line(w,-1L,0,1):linf(mark,w,0,1);} +F1(jtscm10 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtscm10, 0); R r?line(w,-1L,1,0):linf(mark,w,1,0);} +F1(jtscm11 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtscm11, 0); R r?line(w,-1L,1,1):linf(mark,w,1,1);} +F1(jtsct1 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtsct1, 0); R r?line(w,-1L,2,1):linf(mark,w,2,1);} +F1(jtscz1 ){I r; RZ(w); r=1&&AT(w)&LIT+C2T; F1RANK( r,jtscz1, 0); R r?line(w,-1L,3,0):linf(mark,w,3,0);} + +F2(jtscm002){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtscm002,0); R r?line(w,-1L,0,0):linf(a, w,0,0);} +F2(jtscm012){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtscm012,0); R r?line(w,-1L,0,1):linf(a, w,0,1);} +F2(jtscm102){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtscm102,0); R r?line(w,-1L,1,0):linf(a, w,1,0);} +F2(jtscm112){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtscm112,0); R r?line(w,-1L,1,1):linf(a, w,1,1);} +F2(jtsct2 ){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtsct2, 0); R r?line(w,-1L,2,1):linf(a, w,2,1);} +F2(jtscz2 ){I r; RZ(a&&w); r=1&&AT(w)&LIT+C2T; F2RANK(RMAX,r,jtscz2, 0); R r?line(w,-1L,3,0):linf(a, w,3,0);}
new file mode 100644 --- /dev/null +++ b/xt.c @@ -0,0 +1,304 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: time and space */ + +#ifdef _WIN32 +#include <windows.h> +#include <winbase.h> +#endif + +#include "j.h" + +#if !SY_WINCE && (SY_WIN32 || (SYS & SYS_LINUX)) +#include <time.h> +#else +#if (SY_GETTOD && !(SYS&SYS_IBMRS6000)) +#include <sys/time.h> +#endif +#endif + +#if !SY_WIN32 && (SYS & SYS_DOS) +#include <dos.h> +#endif + +#ifndef CLOCKS_PER_SEC +#if (SYS & SYS_UNIX) +#define CLOCKS_PER_SEC 1000000 +#endif +#ifdef CLK_TCK +#define CLOCKS_PER_SEC CLK_TCK +#endif +#endif + + +F1(jtsp){ASSERTMTV(w); R sc(jt->bytes);} + +F1(jtspit){A z;I k; + F1RANK(1,jtspit,0); + jt->bytesmax=k=jt->bytes; + FDEPINC(1); z=exec1(w); FDEPDEC(1); + RZ(z); + R sc(jt->bytesmax-k); +} + +F1(jtparsercalls){ASSERTMTV(w); R sc(jt->parsercalls);} + + +#if SY_WIN32 + /* defined in jdll.c */ +#else +F1(jtts){A z;D*x;struct tm*t;struct timeval tv; + ASSERTMTV(w); + gettimeofday(&tv,NULL); t=localtime((time_t*)&tv.tv_sec); + GA(z,FL,6,1,0); x=DAV(z); + x[0]=t->tm_year+1900; + x[1]=t->tm_mon+1; + x[2]=t->tm_mday; + x[3]=t->tm_hour; + x[4]=t->tm_min; + x[5]=t->tm_sec+(D)tv.tv_usec/1e6; + R z; +} +#endif + +F1(jtts0){A x,z;C s[9],*u,*v,*zv;D*xv;I n,q; + RZ(w); + ASSERT(1>=AR(w),EVRANK); + RZ(x=ts(mtv)); + n=AN(w); xv=DAV(x); + if(!n)R x; + if(!(AT(w)&LIT))RZ(w=cvt(LIT,w)); + GA(z,LIT,n,AR(w),AS(w)); zv=CAV(z); memcpy(zv,CAV(w),n); + q=0; v=zv; DO(n, if('Y'==*v++)++q;); u=2==q?s+2:s; + sprintf(s,FMTI04,(I)xv[0]); v=zv; DO(n, if(*v=='Y'){*v=*u++; if(!*u)break;} ++v;); + sprintf(s,FMTI02,(I)xv[1]); u=s; v=zv; DO(n, if(*v=='M'){*v=*u++; if(!*u)break;} ++v;); + sprintf(s,FMTI02,(I)xv[2]); u=s; v=zv; DO(n, if(*v=='D'){*v=*u++; if(!*u)break;} ++v;); + sprintf(s,FMTI02,(I)xv[3]); u=s; v=zv; DO(n, if(*v=='h'){*v=*u++; if(!*u)break;} ++v;); + sprintf(s,FMTI02,(I)xv[4]); u=s; v=zv; DO(n, if(*v=='m'){*v=*u++; if(!*u)break;} ++v;); + sprintf(s,FMTI05,(I)(1000*xv[5])); u=s; v=zv; DO(n, if(*v=='s'){*v=*u++; if(!*u)break;} ++v;); + R z; +} + + +#if SY_GETTOD +D tod(void){struct timeval t; gettimeofday(&t,NULL); R t.tv_sec+(D)t.tv_usec/1e6;} +#else +#if SY_WINCE +D tod(void){SYSTEMTIME t; GetLocalTime(&t); R t.wSecond+(D)t.wMilliseconds/1e3;} +#else +D tod(void){R(D)clock()/CLOCKS_PER_SEC;} +#endif +#endif + + +#if SY_WIN32 + +typedef LARGE_INTEGER LI; + +static D qpm=4294967296.0; /* 2^32 */ + +D qpf(void){LI n; QueryPerformanceFrequency(&n); R n.LowPart+qpm*n.HighPart;} + +static D qpc(void){LI n; QueryPerformanceCounter(&n); R n.LowPart+qpm*n.HighPart;} + +#else + +D qpf(void){R (D)CLOCKS_PER_SEC;} + +static D qpc(void){R tod()*CLOCKS_PER_SEC;} + +#endif + +/* +// by Mark VanTassel from The Code Project + +__int64 GetMachineCycleCount() +{ + __int64 cycles; + _asm rdtsc; // won't work on 486 or below - only pentium or above + _asm lea ebx,cycles; + _asm mov [ebx],eax; + _asm mov [ebx+4],edx; + return cycles; +} +*/ + + +F1(jttss){ASSERTMTV(w); R scf(tod()-jt->tssbase);} + +F2(jttsit2){A z;D t;I n,old; + F2RANK(0,1,jttsit2,0); + RE(n=i0(a)); + FDEPINC(1); + t=qpc(); + old=jt->tbase+jt->ttop; DO(n, z=exec1(w); if(!z)break; tpop(old);); + t=qpc()-t; + FDEPDEC(1); + RZ(z); + R scf(n?t/(n*pf):0); +} + +F1(jttsit1){R tsit2(one,w);} + +#ifdef _WIN32 +#define sleepms(i) Sleep(i) +#else +#define sleepms(i) sleep((i+500)/1000) +#endif + +F1(jtdl){D m,n,*v;UINT ms,s; + RZ(w=cvt(FL,w)); + n=0; v=DAV(w); DO(AN(w), m=*v++; ASSERT(0<=m,EVDOMAIN); n+=m;); + s=(UINT)jfloor(n); ms=(UINT)jfloor(0.5+1000*(n-s)); +#if SYS & SYS_MACINTOSH + {I t=TickCount()+(I)(60*n); while(t>TickCount())JBREAK0;} +#else + DO(s, sleepms(1000); JBREAK0;); + sleepms(ms); +#endif + R w; +} + + +F1(jtqpfreq){ASSERTMTV(w); R scf(pf);} + +F1(jtqpctr ){ASSERTMTV(w); R scf(qpc());} + +F1(jtpmctr){D x;I q; + RE(q=i0(w)); + ASSERT(jt->pma,EVDOMAIN); + x=q+(D)jt->pmctr; + ASSERT(IMIN<=x&&x<=IMAX,EVDOMAIN); + jt->pmctr=q=(I)x; + R sc(q); +} /* add w to pmctr */ + +static F1(jtpmfree){A x,y;C*c;I m;PM*v;PM0*u; + if(w){ + c=CAV(w); u=(PM0*)c; v=(PM*)(c+sizeof(PM0)); + m=u->wrapped?u->n:u->i; + DO(m, x=v->name; if(x&&NAME==AT(x)&&AN(x)==*AS(x))fa(x); + y=v->loc; if(y&&NAME==AT(y)&&AN(y)==*AS(y))fa(y); ++v;); + fa(w); + } + R one; +} /* free old data area */ + +F1(jtpmarea1){R pmarea2(vec(B01,2L,&zeroZ),w);} + +F2(jtpmarea2){A x;B a0,a1,*av;C*v;I an,n=0,s=sizeof(PM),s0=sizeof(PM0),wn;PM0*u; + RZ(a&&w); + ASSERT(prokey, EVDOMAIN); + RZ(a=cvt(B01,a)); + an=AN(a); + ASSERT(1>=AR(a),EVRANK); + ASSERT(2>=an,EVLENGTH); + av=BAV(a); + a0=0<an?av[0]:0; + a1=1<an?av[1]:0; + RZ(w=vs(w)); + wn=AN(w); + ASSERT(!wn||wn>=s+s0,EVLENGTH); + x=jt->pma; + jt->pmctr=0; + jt->pma=wn?ra(w):0; + RZ(pmfree(x)); + if(wn){ + v=CAV(w); + jt->pmu=u=(PM0*)v; + jt->pmv=(PM*)(s0+v); + jt->pmrec=u->rec=a0; + u->n=n=(wn-s0)/s; + u->i=0; + u->s=jt->bytesmax=jt->bytes; + u->trunc=a1; + u->wrapped=0; + } + R sc(n); +} + +void jtpmrecord(J jt,A name,A loc,I lc,int val){A x,y;B b;PM*v;PM0*u; + u=jt->pmu; + v=jt->pmv+u->i; + if(b=u->wrapped){x=v->name; y=v->loc;} + ++u->i; + if(u->i>u->n){u->wrapped=1; if(u->trunc){u->i=u->n; R;}else u->i=0;} + v->name=name; if(name)++AC(name); + v->loc =loc; if(loc )++AC(loc ); if(b){fa(x); fa(y);} + v->val =val; + v->lc =lc; + v->s=jt->bytesmax-u->s; + u->s=jt->bytesmax=jt->bytes; +#if SY_WIN32 + QueryPerformanceCounter((LI*)v->t); +#else + {D d=tod(); MC(v->t,&d,sizeof(D));} +#endif +} + +F1(jtpmunpack){A*au,*av,c,t,x,z,*zv;B*b;D*dv;I*iv,k,m,n,p,q,wn,*wv;PM*v,*v0,*vq;PM0*u; + RZ(w); + ASSERT(jt->pma,EVDOMAIN); + if(!(INT&AT(w)))RZ(w=cvt(INT,w)); + wn=AN(w); wv=AV(w); + u=(PM0*)AV(jt->pma); p=u->wrapped?u->n-u->i:0; q=u->i; n=p+q; + GA(x,B01,n,1,0); b=BAV(x); memset(b,wn?C0:C1,n); + if(wn){ + DO(wn, k=wv[i]; if(0>k)k+=n; ASSERT(0<=k&&k<n,EVINDEX); b[k]=1;); + m=0; + DO(n, if(b[i])++m;); + }else m=n; + v0=jt->pmv; vq=q+v0; + GA(z,BOX,1+PMCOL,1,0); zv=AAV(z); + GA(t,BOX,2*m,1,0); av=AAV(t); au=m+av; + v=vq; DO(p, if(b[ i]){RZ(*av++=v->name?sfn(0,v->name):mtv); RZ(*au++=v->loc?sfn(0,v->loc):mtv);} ++v;); + v=v0; DO(q, if(b[p+i]){RZ(*av++=v->name?sfn(0,v->name):mtv); RZ(*au++=v->loc?sfn(0,v->loc):mtv);} ++v;); + RZ(x=indexof(t,t)); + RZ(c=eq(x,IX(IC(x)))); + RZ(zv[6]=repeat(c,t)); + RZ(x=indexof(repeat(c,x),x)); iv=AV(x); + RZ(zv[0]=vec(INT,m, iv)); + RZ(zv[1]=vec(INT,m,m+iv)); + GA(t,INT,m,1,0); zv[2]=t; iv=AV(t); v=vq; DO(p, if(b[i])*iv++=(I)v->val; ++v;); v=v0; DO(q, if(b[p+i])*iv++=(I)v->val; ++v;); + GA(t,INT,m,1,0); zv[3]=t; iv=AV(t); v=vq; DO(p, if(b[i])*iv++=v->lc; ++v;); v=v0; DO(q, if(b[p+i])*iv++=v->lc; ++v;); + GA(t,INT,m,1,0); zv[4]=t; iv=AV(t); v=vq; DO(p, if(b[i])*iv++=v->s; ++v;); v=v0; DO(q, if(b[p+i])*iv++=v->s; ++v;); + GA(t,FL, m,1,0); zv[5]=t; dv=DAV(t); +#if SY_WIN32 + v=vq; DO(p, if(b[i] )*dv++=(((LI*)v->t)->LowPart+qpm*((LI*)v->t)->HighPart)/pf; ++v;); + v=v0; DO(q, if(b[p+i])*dv++=(((LI*)v->t)->LowPart+qpm*((LI*)v->t)->HighPart)/pf; ++v;); +#else + v=vq; DO(p, if(b[i] ){MC(dv,v->t,sizeof(D)); ++dv;} ++v;); + v=v0; DO(q, if(b[p+i]){MC(dv,v->t,sizeof(D)); ++dv;} ++v;); +#endif + R z; +} + +F1(jtpmstats){A x,z;I*zv;PM0*u; + ASSERTMTV(w); + GA(z,INT,6,1,0); zv=AV(z); + if(x=jt->pma){ + u=(PM0*)AV(x); + zv[0]=u->rec; + zv[1]=u->trunc; + zv[2]=u->n; + zv[3]=u->wrapped?u->n:u->i; + zv[4]=u->wrapped; + zv[5]=jt->pmctr; + }else zv[0]=zv[1]=zv[2]=zv[3]=zv[4]=zv[5]=0; + R z; +} + + +F1(jttlimq){ASSERTMTV(w); R scf(0.001*jt->timelimit);} + +F1(jttlims){D d; + RZ(w); + ASSERT(!AR(w),EVRANK); + if(!(FL&AT(w)))RZ(w=cvt(FL,w)); + d=*DAV(w); + ASSERT(0<=d,EVDOMAIN); + ASSERT(IMAX>1000*d,EVLIMIT); + jt->timelimit=(UI)(1000*d); + R mtm; +}
new file mode 100644 --- /dev/null +++ b/xu.c @@ -0,0 +1,153 @@ +/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */ +/* License in license.txt. */ +/* */ +/* Xenos: u: conversions */ + +#include "j.h" +#include "x.h" + +// utf-8 to c2v - assumes valid utf-8 data and snk of right size +static void mtow(UC* src, I srcn, US* snk){ US c,c1,c2; + while(srcn--) + { + c=*src++; + if(c<=0x7f) + *snk++=c; + else if((c&0xE0)==0xC0) + { + c1=*src++;--srcn; + *snk++=((c&0x1F)<<6)|(c1&0x3f); + } + else if((c&0xF0)==0xE0) + { + c1=*src++;--srcn; + c2=*src++;--srcn; + *snk++=((c&0x0F)<<12)|((c1&0x3F)<<6)|(c2&0x3f); + } + } +} + +// get size of conversion from utf-8 to c2v +// return -1 if utf-8 invalid +static I mtowsize(UC* src, I srcn){ US c,c1,c2,cf; I r=0; + while(srcn--) + { + c=*src++; + if(c<=0x7f) + ++r; + else if((c&0xE0)==0xC0) + { + if(!srcn) R -1; + c1=*src++;--srcn; + if((c1&0xc0)!=0x80) R -1; + cf=((c&0x1F)<<6)|(c1&0x3f); + if(cf<0x80) R -1; // overlong + ++r; + } + else if((c&0xF0)==0xE0) + { + if(!srcn) R -1; + c1=*src++;--srcn; + if((c1&0xc0)!=0x80) R -1; + if(!srcn) R -1; + c2=*src++;--srcn; + if((c2&0xc0)!=0x80) R -1; + cf=((c&0x0F)<<12)|((c1&0x3F)<<6)|(c2&0x3f); + if(cf<0x800) R -1; // overlong + ++r; + } + else + R -1; + } + R r; +} + +// c2v to utf-8 - assume valid data and snk size is ok +void wtom(US* src, I srcn, UC* snk){ US w; + while(srcn--) + { + w=*src++; + if(w<=0x7f) + *snk++=(C)w; + else if(w<=0x7ff) + { + *snk++=0xc0|(w>>6); + *snk++=0x80|(0x3f&w); + } + else + { + *snk++=0xe0|w>>12; + *snk++=0x80|(0x3f&(w>>6)); + *snk++=0x80|(0x3f&w); + } + } +} + +// get size of conversion from c2v to utf-8 +static I wtomsize(US* src, I srcn){ US w;I r=0; + while(srcn--) + { + w=*src++; + if(w<=0x7f) + ++r; + else if(w<=0x7ff) + r+=2; + else + r+=3; + } + R r; +} + +F1(jttoutf16){A z;I n,t,q,b=0; C* wv; US* c2v; + RZ(w); ASSERT(1>=AR(w),EVRANK); n=AN(w); t=AT(w); wv=CAV(w); + if(!n) {GA(z,LIT,n,1,0); R z;}; // empty lit list + if(LIT&t) + { + DO(n, if(0>*wv++){b=1;break;}); + if(!b){ if(1==AR(w)) {R ca(w);}; GA(z,LIT,1,1,0); *CAV(z)=*CAV(w); R z;} // ascii list unchanged ascii scalar as list + q=mtowsize(CAV(w),n); + ASSERT(q>=0,EVDOMAIN); + GA(z,C2T,q,1,0); + mtow(CAV(w),n,(US*)CAV(z)); + R z; // u16 from u8 + } + else if(C2T&t) + { + c2v=(US*)AV(w); + DO(n, if(127<*c2v++){b=1;break;}); + if(b) R ca(w); // u16 unchanged + GA(z,LIT,n,AR(w),AS(w)); + wv=CAV(z); + c2v=(US*)AV(w); + DO(n, *wv++=(char)*c2v++;); + R z; + } + else + ASSERT(0, EVDOMAIN); +} // 7 u: x - utf16 from LIT or C2T + +F1(jttoutf8){A z;I n,t,q; +RZ(w); ASSERT(1>=AR(w),EVRANK); n=AN(w); t=AT(w); +if(!n) {GA(z,LIT,n,AR(w),AS(w)); R z;}; // empty lit +if(t&LIT) R ca(w); // char unchanged +ASSERT(t&C2T, EVDOMAIN); +q=wtomsize((US*)CAV(w),n); +GA(z,LIT,q,1,0); +wtom((US*)CAV(w),n,CAV(z)); +R z; +} // 8 u: x - utf8 from LIT or C2T + +F1(jttoutf16x){I q;A z; +ASSERT(LIT&AT(w),EVDOMAIN); +q=mtowsize(CAV(w),AN(w)); +ASSERT(q>=0,EVDOMAIN); +GA(z,C2T,q,1,0); +mtow(CAV(w),AN(w),(US*)CAV(z)); +R z; // u16 from u8 +} + +void jttoutf8x(J jt,C* f, I n, US* fw){I q; +q=wtomsize(fw,wcslen(fw)); +wtom(fw,wcslen(fw),f); +f[q]=0; +}