67 WORD *term, *t, i, retval = 0, size;
70 WORD last, LastExpression, fromspectator;
72 CBUF *C = cbuf+AC.cbufnum;
74 CBUF *CC = cbuf+AT.ebufnum;
77 WORD oldBracketOn = AR.BracketOn;
78 WORD *oldBrackBuf = AT.BrackBuf;
79 WORD oldbracketindexflag = AT.bracketindexflag;
81 int OldMultiThreaded = AS.MultiThreaded, Oldmparallelflag = AC.mparallelflag;
83 if ( CC->numrhs > 0 || CC->numlhs > 0 ) {
85 w = CC->
rhs; i = CC->numrhs;
86 do { *w++ = 0; }
while ( --i > 0 );
89 w = CC->
lhs; i = CC->numlhs;
90 do { *w++ = 0; }
while ( --i > 0 );
92 CC->numlhs = CC->numrhs = 0;
93 ClearTree(AT.ebufnum);
97 if ( NumExpressions == 0 )
return(0);
99 AR.CompressPointer = AR.CompressBuffer;
100 AR.NoCompress = AC.NoCompress;
101 term = AT.WorkPointer;
102 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer) ) > AT.WorkTop )
return(MesWork());
106 if ( AC.CollectFun ) AR.DeferFlag = 0;
110 MesPrint(
"Status at the start of Processor (HideLevel = %d)",AC.HideLevel);
111 for ( i = 0; i < NumExpressions; i++ ) {
121 for ( i = NumExpressions-1; i >= 0; i-- ) {
123 if ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION
124 || e->status == HIDELEXPRESSION || e->status == HIDEGEXPRESSION
125 || e->status == SKIPLEXPRESSION || e->status == SKIPGEXPRESSION
126 || e->status == UNHIDELEXPRESSION || e->status == UNHIDEGEXPRESSION
127 || e->status == INTOHIDELEXPRESSION || e->status == INTOHIDEGEXPRESSION
131 for ( i = NumExpressions-1; i >= 0; i-- ) {
132 AS.OldOnFile[i] = Expressions[i].onfile;
133 AS.OldNumFactors[i] = Expressions[i].numfactors;
135 AS.Oldvflags[i] = Expressions[i].vflags;
136 Expressions[i].vflags &= ~(ISUNMODIFIED|ISZERO);
144 if ( AC.partodoflag && AM.totalnumberofthreads > 1 ) {
145 AS.MultiThreaded = 1; AC.mparallelflag = PARALLELFLAG;
147 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
157 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
158 if ( InParallelProcessor() ) {
161 AS.MultiThreaded = OldMultiThreaded;
162 AC.mparallelflag = Oldmparallelflag;
166 if ( AC.RhsExprInModuleFlag && PF.rhsInParallel && (AC.mparallelflag == PARALLELFLAG || AC.partodoflag) ) {
172 if ( AC.partodoflag > 0 ) {
178 for ( i = 0; i < NumExpressions; i++ ) {
180 if ( AC.InnerTest ) {
181 if ( StrCmp(AC.TestValue,(UBYTE *)INNERTEST) == 0 ) {
182 MesPrint(
"Testing(Processor): value = %s",AC.TestValue);
188 if ( AC.partodoflag > 0 && e->partodo > 0 && AM.totalnumberofthreads > 2 ) {
194 if ( AC.partodoflag > 0 && e->partodo > 0 && PF.numtasks > 2 ) {
199 AS.CollectOverFlag = 0;
201 if ( i == last ) LastExpression = 1;
202 else LastExpression = 0;
212 SetScratch(AR.infile,&(e->onfile));
213 if ( GetTerm(BHEAD term) <= 0 ) {
214 MesPrint(
"(1) Expression %d has problems in scratchfile",i);
220 SeekScratch(AR.outfile,&position);
221 e->onfile = position;
222 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
223 AR.DeferFlag = AC.ComDefer;
228 for ( j = 0; j < *t; j++ ) term[j] = t[j];
230 AN.ninterms++; dd = AN.deferskipped;
231 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
232 if ( GetMoreFromMem(term,&t) ) {
236 AT.WorkPointer = term + *term;
237 AN.RepPoint = AT.RepCount + 1;
238 AN.IndDum = AM.IndDum;
239 AR.CurDum = ReNumber(BHEAD term);
240 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
242 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
243 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
245 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
252 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
253 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
254 else e->vflags |= ISZERO;
255 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
256 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
257 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
265 switch ( e->status ) {
266 case UNHIDELEXPRESSION:
267 case UNHIDEGEXPRESSION:
270 if ( PF.me == MASTER ) SetScratch(AR.hidefile,&(e->onfile));
272 SetScratch(AR.hidefile,&(e->onfile));
273 AR.InHiBuf = AR.hidefile->POfull-AR.hidefile->POfill;
275 MesPrint(
"Hidefile: onfile: %15p, POposition: %15p, filesize: %15p",&(e->onfile)
276 ,&(AR.hidefile->POposition),&(AR.hidefile->filesize));
277 MesPrint(
"Set hidefile to buffer position %l/%l; AR.InHiBuf = %l"
278 ,(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD)
279 ,(AR.hidefile->POfull-AR.hidefile->PObuffer)*
sizeof(WORD)
284 curfile = AR.hidefile;
286 case INTOHIDELEXPRESSION:
287 case INTOHIDEGEXPRESSION:
294 SetEndHScratch(AR.hidefile,&position);
296 case LOCALEXPRESSION:
297 case GLOBALEXPRESSION:
301 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
303 SetScratch(AR.infile,&(e->onfile));
309 MesPrint(
"Error in PF_Processor");
313 if ( AC.mparallelflag != PARALLELFLAG ){
318 if ( GetTerm(BHEAD term) <= 0 ) {
320 MesPrint(
"Error condition 1a");
323 MesPrint(
"(2) Expression %d has problems in scratchfile(process)",i);
329 fromspectator = -term[5];
330 PUTZERO(AM.SpectatorFiles[fromspectator-1].readpos);
331 term[5] = AC.cbufnum;
333 else fromspectator = 0;
334 if ( AR.outtohide ) {
335 SeekScratch(AR.hidefile,&position);
336 e->onfile = position;
337 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
340 SeekScratch(AR.outfile,&position);
341 e->onfile = position;
342 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
344 AR.DeferFlag = AC.ComDefer;
346 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
348 AT.BrackBuf = AM.BracketFactors;
349 AT.bracketindexflag = 1;
351 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
353 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
354 if ( ThreadsProcessor(e,LastExpression,fromspectator) ) {
355 MesPrint(
"Error in ThreadsProcessor");
358 if ( AR.outtohide ) {
359 AR.outfile = oldoutfile;
360 AR.hidefile->POfull = AR.hidefile->POfill;
367 AR.MaxDum = AM.IndDum;
370 if ( fromspectator ) size = GetFromSpectator(term,fromspectator-1);
371 else size = GetTerm(BHEAD term);
372 if ( size <= 0 )
break;
373 SeekScratch(curfile,&position);
374 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
378 AN.ninterms++; dd = AN.deferskipped;
379 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
380 if ( GetMoreTerms(term) < 0 ) {
383 SeekScratch(curfile,&position);
385 AT.WorkPointer = term + *term;
386 AN.RepPoint = AT.RepCount + 1;
387 if ( AR.DeferFlag ) {
388 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
389 AR.CurDum = AN.IndDum;
392 AN.IndDum = AM.IndDum;
393 AR.CurDum = ReNumber(BHEAD term);
395 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
397 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
398 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
400 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
401 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
402 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
403 PolyFunClean(BHEAD term);
410 SetScratch(curfile,&position);
411 if ( AR.GetFile == 2 ) {
412 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
413 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
416 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
417 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
421 if ( LastExpression ) {
423 if ( AR.infile->handle >= 0 ) {
424 CloseFile(AR.infile->handle);
425 AR.infile->handle = -1;
426 remove(AR.infile->name);
427 PUTZERO(AR.infile->POposition);
429 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
431 if ( AR.outtohide ) AR.outfile = AR.hidefile;
432 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
433 if ( AR.outtohide ) {
434 AR.outfile = oldoutfile;
435 AR.hidefile->POfull = AR.hidefile->POfill;
437 e->numdummies = AR.MaxDum - AM.IndDum;
440 AR.BracketOn = oldBracketOn;
441 AT.BrackBuf = oldBrackBuf;
442 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
445 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
446 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
449 AT.bracketindexflag = oldbracketindexflag;
450 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
451 else e->vflags |= ISZERO;
452 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
453 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
454 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
462 if ( e->status == INTOHIDELEXPRESSION ||
463 e->status == INTOHIDEGEXPRESSION ) {
468 case SKIPLEXPRESSION:
469 case SKIPGEXPRESSION:
474 if ( PF.me != MASTER )
break;
477 SetScratch(AR.infile,&(e->onfile));
478 if ( GetTerm(BHEAD term) <= 0 ) {
480 MesPrint(
"Error condition 1b");
483 MesPrint(
"(3) Expression %d has problems in scratchfile",i);
489 SeekScratch(AR.outfile,&position);
490 e->onfile = position;
491 *AM.S0->sBuffer = 0; firstterm = -1;
493 WORD *oldipointer = AR.CompressPointer;
494 WORD *comprtop = AR.ComprTop;
495 AR.ComprTop = AM.S0->sTop;
496 AR.CompressPointer = AM.S0->sBuffer;
497 if ( firstterm > 0 ) {
498 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
500 else if ( firstterm < 0 ) {
501 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
505 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
508 AR.CompressPointer = oldipointer;
509 AR.ComprTop = comprtop;
510 }
while ( GetTerm(BHEAD term) );
511 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
514 case HIDELEXPRESSION:
515 case HIDEGEXPRESSION:
517 if ( PF.me != MASTER )
break;
520 SetScratch(AR.infile,&(e->onfile));
521 if ( GetTerm(BHEAD term) <= 0 ) {
523 MesPrint(
"Error condition 1c");
526 MesPrint(
"(4) Expression %d has problems in scratchfile",i);
532 SetEndHScratch(AR.hidefile,&position);
533 e->onfile = position;
535 if ( AR.hidefile->handle >= 0 ) {
536 POSITION possize,pos;
539 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
540 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
541 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
542 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
544 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
547 *AM.S0->sBuffer = 0; firstterm = -1;
548 cbo = cpo = AM.S0->sBuffer;
550 WORD *oldipointer = AR.CompressPointer;
551 WORD *oldibuffer = AR.CompressBuffer;
552 WORD *comprtop = AR.ComprTop;
553 AR.ComprTop = AM.S0->sTop;
554 AR.CompressPointer = cpo;
555 AR.CompressBuffer = cbo;
556 if ( firstterm > 0 ) {
557 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
559 else if ( firstterm < 0 ) {
560 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
564 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
567 cpo = AR.CompressPointer;
568 cbo = AR.CompressBuffer;
569 AR.CompressPointer = oldipointer;
570 AR.CompressBuffer = oldibuffer;
571 AR.ComprTop = comprtop;
572 }
while ( GetTerm(BHEAD term) );
574 if ( AR.hidefile->handle >= 0 ) {
575 POSITION possize,pos;
578 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
579 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
580 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
581 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
583 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
586 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
587 AR.hidefile->POfull = AR.hidefile->POfill;
589 if ( AR.hidefile->handle >= 0 ) {
590 POSITION possize,pos;
593 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
594 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
595 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
596 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
598 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
609 if ( e->status == HIDELEXPRESSION ) {
610 e->status = HIDDENLEXPRESSION;
611 AS.OldOnFile[i] = e->onfile;
612 AS.OldNumFactors[i] = Expressions[i].numfactors;
614 if ( e->status == HIDEGEXPRESSION ) {
615 e->status = HIDDENGEXPRESSION;
616 AS.OldOnFile[i] = e->onfile;
617 AS.OldNumFactors[i] = Expressions[i].numfactors;
624 case DROPPEDEXPRESSION:
625 case DROPLEXPRESSION:
626 case DROPGEXPRESSION:
627 case DROPHLEXPRESSION:
628 case DROPHGEXPRESSION:
629 case STOREDEXPRESSION:
630 case HIDDENLEXPRESSION:
631 case HIDDENGEXPRESSION:
632 case SPECTATOREXPRESSION:
640 AT.WorkPointer = term;
642 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
643 for ( i = 0; i < NumExpressions; i++ ) {
650 AT.WorkPointer = term;
651 if ( AM.tracebackflag ) MesCall(
"Processor");
684 WORD *m, *t, *r, retvalue, funflag, j, oldncmod, nexpr;
685 WORD *stop, *t1, *t2, funnum, wilds, tbufnum, stilldirty = 0;
687 CBUF *C = cbuf+AT.ebufnum;
690 COMPARE oldcompareroutine = AR.CompareRoutine;
691 WORD oldsorttype = AR.SortType;
694 AT.TMbuff = AM.rbufnum;
701 if ( *t == SUBEXPRESSION ) {
711#ifdef WHICHSUBEXPRESSION
713 WORD *tmin = t, AN.nbino;
717 if ( AN.BinoScrat == 0 ) {
718 AN.BinoScrat = (UWORD *)Malloc1((AM.MaxTal+2)*
sizeof(UWORD),
"GetBinoScrat");
723 while ( AN.subsubveto == 0 &&
724 *r == SUBEXPRESSION && r < m && r[3] ) {
725#ifdef WHICHSUBEXPRESSION
728 if ( r[1] == t[1] && r[2] == t[2] && r[4] == t[4] ) {
729 j = t[1] - SUBEXPSIZE;
732 while ( j > 0 && *t1++ == *t2++ ) j--;
740 while ( t1 < t2 ) *r++ = *t1++;
748 while ( t1 < t2 ) *r++ = *t1++;
753#ifdef WHICHSUBEXPRESSION
755 else if ( t[2] >= 0 ) {
761 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
762 if ( AN.last3 > minval ) {
763 minval = AN.last3; tmin = t;
767 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
770 minval = mm; tmin = t;
773 else if ( t[3] > 0 ) {
774 if ( mm > MAXPOSITIVE )
goto TooMuch;
775 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
776 if ( AN.nbino > 2 )
goto TooMuch;
777 if ( AN.nbino == 2 ) {
778 mm = AN.BinoScrat[1];
779 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
781 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
784 minval = mm; tmin = t;
794#ifdef WHICHSUBEXPRESSION
795 if ( mnum1 > 1 && t[2] >= 0 ) {
799 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
800 if ( AN.last3 > minval ) {
801 minval = AN.last3; tmin = t;
805 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
808 minval = mm; tmin = t;
811 else if ( t[3] > 0 ) {
812 if ( mm > MAXPOSITIVE ) {
817 MLOCK(ErrorMessageLock);
818 MesPrint(
"Attempt to generate more terms than FORM can count");
819 MUNLOCK(ErrorMessageLock);
822 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
823 if ( AN.nbino > 2 )
goto TooMuch;
824 if ( AN.nbino == 2 ) {
825 mm = AN.BinoScrat[1];
826 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
828 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
831 minval = mm; tmin = t;
840 AR.TePos = WORDDIF(t,term);
842 if ( t[4] == AM.dbufnum && (t+t[1]) < m && t[t[1]] == DOLLAREXPR2 ) {
843 if ( t[t[1]+2] < 0 ) AT.TMdolfac = -t[t[1]+2];
845 AT.TMdolfac = GetDolNum(BHEAD t+t[1],m)+1;
848 else AT.TMdolfac = 0;
851 AR.TePos = WORDDIF(t,term);
865 else if ( *t == EXPRESSION ) {
870 AR.TePos = WORDDIF(t,term);
874 toTMaddr = m = AT.WorkPointer;
889 if ( *t == FROMBRAC ) {
890 WORD *ttstop,*tttstop;
897 AN.Frozen = m = AT.WorkPointer;
905 j = *t; tttstop = t + j;
908 while ( t < ttstop ) {
909 if ( *t == SUBEXPRESSION )
break;
910 if ( *t >= FUNCTION && ( ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) )
break;
911 j = t[1]; NCOPY(m,t,j);
919 while ( t < tttstop ) *m++ = *t++;
920 *AT.WorkPointer = m-AT.WorkPointer;
922 AT.WorkPointer = m + *m;
927 if (
EndSort(BHEAD m,0) < 0 )
goto EndTest;
930 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
932 else if ( m[*m] != 0 ) {
933 MLOCK(ErrorMessageLock);
934 MesPrint(
"Bracket specification in expression should be one single term");
935 MUNLOCK(ErrorMessageLock);
941 *m++ = 1; *m++ = 1; *m++ = 3;
942 *AN.Frozen = m - AN.Frozen;
946 while ( t < tttstop ) *m++ = *t++;
947 *AT.WorkPointer = m-AT.WorkPointer;
949 AT.WorkPointer = m + *m;
950 if ( Normalize(BHEAD m) ) {
951 MLOCK(ErrorMessageLock);
952 MesPrint(
"Error while picking up contents of bracket");
953 MUNLOCK(ErrorMessageLock);
957 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
969 AT.TMaddr = toTMaddr;
972 else if ( *t >= FUNCTION ) {
973 if ( t[0] == EXPONENT ) {
974 if ( t[1] == FUNHEAD+4 && t[FUNHEAD] == -SYMBOL &&
975 t[FUNHEAD+2] == -SNUMBER && t[FUNHEAD+3] < MAXPOWER
976 && t[FUNHEAD+3] > -MAXPOWER ) {
984 while ( m < r ) *t++ = *m++;
985 *term = WORDDIF(t,term);
988 else if ( t[1] == FUNHEAD+ARGHEAD+11 && t[FUNHEAD] == ARGHEAD+9
989 && t[FUNHEAD+ARGHEAD] == 9 && t[FUNHEAD+ARGHEAD+1] == DOTPRODUCT
990 && t[FUNHEAD+ARGHEAD+8] == 3
991 && t[FUNHEAD+ARGHEAD+7] == 1
992 && t[FUNHEAD+ARGHEAD+6] == 1
993 && t[FUNHEAD+ARGHEAD+5] == 1
994 && t[FUNHEAD+ARGHEAD+9] == -SNUMBER
995 && t[FUNHEAD+ARGHEAD+10] < MAXPOWER
996 && t[FUNHEAD+ARGHEAD+10] > -MAXPOWER ) {
999 t[2] = t[FUNHEAD+ARGHEAD+3];
1000 t[3] = t[FUNHEAD+ARGHEAD+4];
1001 t[4] = t[FUNHEAD+ARGHEAD+10];
1003 m = t + FUNHEAD+ARGHEAD+11;
1005 while ( m < r ) *t++ = *m++;
1006 *term = WORDDIF(t,term);
1011 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
1012 if ( *t == EXPONENT ) {
1018 if ( *r == -SNUMBER && r[1] < MAXPOWER && r+2 == t+t[1] &&
1019 t[FUNHEAD] > -FUNCTION && ( t[FUNHEAD] != -SNUMBER
1020 || t[FUNHEAD+1] != 0 ) && t[FUNHEAD] != ARGHEAD ) {
1022 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
1023 MLOCK(ErrorMessageLock);
1024 MesPrint(
"Encountered 0^0. Fatal error.");
1025 MUNLOCK(ErrorMessageLock);
1038 t1 =
AddRHS(AT.ebufnum,1);
1042 i = t[FUNHEAD] - ARGHEAD;
1043 while ( (t1 + i + 10) > C->
Top )
1045 while ( --i >= 0 ) *t1++ = *m++;
1048 if ( (t1 + 20) > C->
Top )
1054 C->
rhs[C->numrhs+1] = t1;
1060 *t++ = SUBEXPRESSION;
1066Important: we may not have enough spots here
1071 do { *t++ = *r++; }
while ( r < m );
1072 *term -= WORDDIF(r,t);
1077 else if ( *t == SUMF1 || *t == SUMF2 ) {
1089 WORD *tstop, lcounter, lcmin, lcmax, lcinc;
1092 if ( r+6 < tstop && r[2] == -SNUMBER && r[4] == -SNUMBER
1093 && ( ( r[0] == -SYMBOL )
1094 || ( r[0] == -INDEX && r[1] >= AM.OffsetIndex
1095 && r[3] >= 0 && r[3] < AM.OffsetIndex
1096 && r[5] >= 0 && r[5] < AM.OffsetIndex ) ) ) {
1097 lcounter = r[0] == -INDEX ? -r[1]: r[1];
1101 if ( *r == -SNUMBER && r+2 < tstop ) {
1106 if ( r < tstop && ( ( *r > 0 && (r+*r) == tstop )
1107 || ( *r <= -FUNCTION && r+1 == tstop )
1108 || ( *r > -FUNCTION && *r < 0 && r+2 == tstop ) ) ) {
1109 m =
AddRHS(AT.ebufnum,1);
1113 while ( (m + i + 10) > C->
Top )
1115 while ( --i >= 0 ) *m++ = *r++;
1118 while ( (m + 20) > C->
Top )
1124 C->
rhs[C->numrhs+1] = m;
1128 if ( *t == SUMF1 ) *m++ = SUMNUM1;
1129 else *m++ = SUMNUM2;
1135 r = C->
rhs[C->numrhs];
1142 if ( *r >= (SUBEXPSIZE+4)
1143 && ABS(*(r+*r-1)) < (*r - 1)
1144 && r[1] == SUBEXPRESSION ) {
1147 *t++ = *r++; *t++ = *r++; *t++ = C->numrhs;
1148 r++; *t++ = *r++; *t++ = AT.ebufnum; r++;
1149 while ( --i >= 0 ) *t++ = *r++;
1152 *t++ = SUBEXPRESSION;
1153 *t++ = 4+SUBEXPSIZE;
1158 if ( lcounter < 0 ) {
1171 while ( m < t2 ) *t++ = *m++;
1172 *term = WORDDIF(t,term);
1173 AN.TeInFun = -C->numrhs;
1176 AT.TMbuff = AT.ebufnum;
1181 else if ( *t == TOPOLOGIES ) {
1186 t1 = t+FUNHEAD; t2 = t+t[1];
1187 if ( *t1 == -SNUMBER && t1[1] >= 0 &&
1188 t1[2] == -SNUMBER && ( t1[3] >= 0 || t1[3] == -2 ) &&
1189 t1[4] == -SETSET && Sets[t1[5]].type == CNUMBER &&
1190 t1[6] == -SETSET && Sets[t1[7]].type == CVECTOR &&
1191 t1[8] == -SETSET && Sets[t1[9]].type == CVECTOR &&
1193 if ( t1+10 == t2 || ( t1+12 <= t2 && ( t1[10] == -SNUMBER ||
1194 ( t1[10] == -SETSET &&
1195 Sets[t1[5]].last-Sets[t1[5]].first ==
1196 Sets[t1[11]].last-Sets[t1[11]].first ) ) ) ) {
1204 else if ( *t == DIAGRAMS ) {
1206 if ( functions[funnum-FUNCTION].spec == 0
1207 || ( t[2] & (DIRTYFLAG|MUSTCLEANPRF) ) != 0 ) { funflag = 1; }
1208 if ( *t <= MAXBUILTINFUNCTION ) {
1209 if ( *t <= DELTAP && *t >= THETA ) {
1210 if ( *t == THETA || *t == THETA2 ) {
1211 WORD *tstop, *tt2, kk;
1214 while ( tt2 < tstop ) {
1215 if ( *tt2 > 0 && tt2[1] != 0 )
goto DoSpec;
1218 if ( !AT.RecFlag ) {
1219 if ( ( kk = DoTheta(BHEAD t) ) == 0 ) {
1223 else if ( kk > 0 ) {
1226 while ( m < r ) *t++ = *m++;
1227 *term = WORDDIF(t,term);
1232 else if ( *t == DELTA2 || *t == DELTAP ) {
1233 WORD *tstop, *tt2, kk;
1236 while ( tt2 < tstop ) {
1237 if ( *tt2 > 0 && tt2[1] != 0 )
goto DoSpec;
1240 if ( !AT.RecFlag ) {
1241 if ( ( kk = DoDelta(t) ) == 0 ) {
1245 else if ( kk > 0 ) {
1248 while ( m < r ) *t++ = *m++;
1249 *term = WORDDIF(t,term);
1254 else if ( *t == DISTRIBUTION && t[FUNHEAD] == -SNUMBER
1255 && t[FUNHEAD+1] >= -2 && t[FUNHEAD+1] <= 2
1256 && t[FUNHEAD+2] == -SNUMBER
1257 && t[FUNHEAD+4] <= -FUNCTION
1258 && t[FUNHEAD+5] <= -FUNCTION ) {
1259 WORD *ttt = t+FUNHEAD+6, *tttstop = t+t[1];
1260 while ( ttt < tttstop ) {
1261 if ( *ttt == -DOLLAREXPRESSION )
break;
1264 if ( ttt >= tttstop ) {
1271 else if ( *t == DELTA3 && ((t[1]-FUNHEAD) & 1 ) == 0 ) {
1277 else if ( ( *t == TABLEFUNCTION ) && ( t[FUNHEAD] <= -FUNCTION )
1278 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1279 && ( t[1] >= FUNHEAD+1+2*T->
numind )
1280 && ( t[FUNHEAD+1] == -SYMBOL ) ) {
1284 for ( isp = 0; isp < T->
numind; isp++ ) {
1285 if ( t[FUNHEAD+1+2*isp] != -SYMBOL )
break;
1287 if ( isp >= T->
numind ) {
1294 else if ( *t == TABLEFUNCTION && t[FUNHEAD] <= -FUNCTION
1295 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1296 && ( t[1] == FUNHEAD+2 )
1297 && ( t[FUNHEAD+1] <= -FUNCTION ) ) {
1306 else if ( *t == FACTORIN ) {
1307 if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -DOLLAREXPRESSION ) {
1313 else if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -EXPRESSION ) {
1320 else if ( *t == TERMSINBRACKET ) {
1321 if ( t[1] == FUNHEAD || (
1323 && t[FUNHEAD] == -SNUMBER
1324 && t[FUNHEAD+1] == 0
1364 else if ( *t == EXTRASYMFUN ) {
1365 if ( t[1] == FUNHEAD+2 && (
1366 ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] <= cbuf[AM.sbufnum].numrhs
1367 && t[FUNHEAD+1] > 0 ) ||
1368 ( t[FUNHEAD] == -SYMBOL && t[FUNHEAD+1] < MAXVARIABLES
1369 && t[FUNHEAD+1] >= MAXVARIABLES-cbuf[AM.sbufnum].numrhs ) ) ) {
1375 else if ( t[1] == FUNHEAD ) {
1382 else if ( *t == DIVFUNCTION || *t == REMFUNCTION
1383 || *t == INVERSEFUNCTION || *t == MULFUNCTION
1384 || *t == GCDFUNCTION ) {
1386 int todo = 1, numargs = 0;
1388 while ( tf < t + t[1] ) {
1390 if ( *tf == -DOLLAREXPRESSION ) {
1391 d = Dollars + tf[1];
1392 if ( d->type == DOLWILDARGS ) {
1393 WORD *tterm = AT.WorkPointer, *tw;
1394 WORD *ta = term, *tb = tterm, *tc, *td = term + *term;
1395 while ( ta < t ) *tb++ = *ta++;
1397 while ( ta < tf ) *tb++ = *ta++;
1401 if ( *tw > -FUNCTION ) *tb++ = *tw++;
1406 for ( ia = 0; ia < *tw; ia++ ) *tb++ = *tw++;
1410 while ( ta < t+t[1] ) *tb++ = *ta++;
1412 while ( ta < td ) *tb++ = *ta++;
1413 *tterm = tb - tterm;
1415 int ia, na = *tterm;
1416 ta = tterm; tb = term;
1417 for ( ia = 0; ia < na; ia++ ) *tb++ = *ta++;
1419 if ( tb > AT.WorkTop ) {
1420 MLOCK(ErrorMessageLock);
1424 AT.WorkPointer = tb;
1431 while ( tf < t + t[1] ) {
1433 if ( *tf > 0 && tf[1] != 0 ) todo = 0;
1436 if ( todo && numargs == 2 ) {
1437 if ( *t == DIVFUNCTION ) AN.TeInFun = -9;
1438 else if ( *t == REMFUNCTION ) AN.TeInFun = -10;
1439 else if ( *t == INVERSEFUNCTION ) AN.TeInFun = -11;
1440 else if ( *t == MULFUNCTION ) AN.TeInFun = -14;
1441 else if ( *t == GCDFUNCTION ) AN.TeInFun = -8;
1446 else if ( todo && numargs == 3 ) {
1447 if ( *t == DIVFUNCTION ) AN.TeInFun = -9;
1448 else if ( *t == REMFUNCTION ) AN.TeInFun = -10;
1449 else if ( *t == GCDFUNCTION ) AN.TeInFun = -8;
1454 else if ( todo && *t == GCDFUNCTION ) {
1461 else if ( *t == PERMUTATIONS && ( ( t[1] >= FUNHEAD+1
1462 && t[FUNHEAD] <= -FUNCTION ) || ( t[1] >= FUNHEAD+3
1463 && t[FUNHEAD] == -SNUMBER && t[FUNHEAD+2] <= -FUNCTION ) ) ) {
1469 else if ( *t == PARTITIONS ) {
1470 if ( TestPartitions(t,&(AT.partitions)) ) {
1471 AT.partitions.where = t-term;
1485 AT.NestPoin->termsize = t;
1486 if ( AT.NestPoin == AT.Nest ) AN.EndNest = t + *t;
1488 oldncmod = AN.ncmod;
1490 if ( *t < FUNCTION ) {
1491 t += t[1];
continue;
1493 if ( AN.ncmod && ( ( AC.modmode & ALSOFUNARGS ) == 0 ) ) {
1494 if ( *t != AR.PolyFun ) AN.ncmod = 0;
1495 else AN.ncmod = oldncmod;
1499 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
1500 if ( ( *t == NUMFACTORS || *t == FIRSTTERM || *t == CONTENTTERM )
1501 && t[1] == FUNHEAD+2 &&
1502 ( t[FUNHEAD] == -EXPRESSION || t[FUNHEAD] == -DOLLAREXPRESSION ) ) {
1509 else if ( functions[funnum-FUNCTION].spec == 0 ) {
1510 AT.NestPoin->funsize = t + 1;
1514 if ( *t > 0 && t[1] ) {
1515 AT.NestPoin->argsize = t;
1520 while ( t < AT.NestPoin[-1].argsize+*(AT.NestPoin[-1].argsize) ) {
1532 if ( ( retvalue =
TestSub(BHEAD t,level) ) != 0 ) {
1557 while ( r < m ) *t++ = *r++;
1559 while ( n < AT.NestPoin ) {
1562 *(n->termsize) -= i;
1570 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 )
1571 t1[2] |= MUSTCLEANPRF;
1576 AN.ncmod = oldncmod;
1589 if ( *t == 0 ) { retvalue = 1;
goto redosize; }
1591 WORD *tend = t + *t, *tt = t+1;
1593 tend -= ABS(tend[-1]);
1594 while ( tt < tend ) {
1595 if ( *tt == SUBEXPRESSION ) {
1596 stilldirty = 1;
break;
1611 while ( r < m ) *t++ = *r++;
1612 t = AT.NestPoin[-1].argsize + ARGHEAD;
1614 while ( n < AT.NestPoin ) {
1617 *(n->termsize) -= i;
1633 t = AT.NestPoin->argsize;
1637 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1639 AR.SortType = SORTHIGHFIRST;
1641 if ( AT.WorkPointer < term + *term )
1642 AT.WorkPointer = term + *term;
1644 while ( t < AT.NestPoin->argsize+*(AT.NestPoin->argsize) ) {
1647 do { *m++ = *t++; }
while ( t < r );
1649 AT.WorkPointer = r + *r;
1650 if ( Normalize(BHEAD r) ) {
1651 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1652 AR.SortType = oldsorttype;
1653 AR.CompareRoutine = oldcompareroutine;
1654 t1[2] |= MUSTCLEANPRF;
1658 if ( AN.ncmod != 0 ) {
1663 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1664 AR.SortType = oldsorttype;
1665 AR.CompareRoutine = oldcompareroutine;
1666 t1[2] |= MUSTCLEANPRF;
1672 if ( AR.PolyFun > 0 ) {
1673 if (
PrepPoly(BHEAD r,1) != 0 )
goto EndTest;
1679 if (
EndSort(BHEAD AT.WorkPointer+ARGHEAD,1) < 0 )
goto EndTest;
1680 m = AT.WorkPointer+ARGHEAD;
1681 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1682 AR.SortType = oldsorttype;
1683 AR.CompareRoutine = oldcompareroutine;
1684 t1[2] |= MUSTCLEANPRF;
1686 while ( *m ) m += *m;
1687 i = WORDDIF(m,AT.WorkPointer);
1688 *AT.WorkPointer = i;
1689 AT.WorkPointer[1] = stilldirty;
1690 if ( ToFast(AT.WorkPointer,AT.WorkPointer) ) {
1692 if ( *m <= -FUNCTION ) { m++; i = 1; }
1693 else { m += 2; i = 2; }
1698 if ( r > AT.WorkTop ) {
1699 MLOCK(ErrorMessageLock);
1703 do { *--r = *--m; }
while ( m > AT.WorkPointer );
1707 stop = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1708 do { *--r = *--m; }
while ( m >= stop );
1711 m = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1713 do { *r++ = *m++; }
while ( m < AN.EndNest );
1715 m = AT.NestPoin->argsize;
1717 while ( --i >= 0 ) *m++ = *r++;
1719 while ( n <= AT.NestPoin ) {
1720 if ( *(n->argsize) > 0 && n != AT.NestPoin )
1723 *(n->termsize) += j;
1728 if ( funnum == DENOMINATOR || funnum == EXPONENT ) {
1729 if ( Normalize(BHEAD term) ) {
1739 AN.ncmod = oldncmod;
1746 AN.ncmod = oldncmod;
1749 else if ( *t == -DOLLAREXPRESSION ) {
1750 if ( ( *t1 == TERMSINEXPR || *t1 == SIZEOFFUNCTION )
1751 && t1[1] == FUNHEAD+2 ) {}
1753 if ( AR.Eside != LHSIDE ) {
1754 AN.TeInFun = 1; AR.TePos = 0;
1755 AT.TMbuff = AM.dbufnum; t1[2] |= DIRTYFLAG;
1756 AN.ncmod = oldncmod;
1759 AC.lhdollarflag = 1;
1762 else if ( *t == -TERMSINBRACKET ) {
1763 if ( AR.Eside != LHSIDE ) {
1764 AN.TeInFun = 1; AR.TePos = 0;
1766 AN.ncmod = oldncmod;
1770 else if ( AN.ncmod != 0 && *t == -SNUMBER ) {
1771 if ( AN.ncmod == 1 || AN.ncmod == -1 ) {
1772 isp = (UWORD)(AC.cmod[0]);
1774 if ( ( AC.modmode & POSNEG ) != 0 ) {
1775 if ( isp > (UWORD)(AC.cmod[0])/2 ) isp = isp - (UWORD)(AC.cmod[0]);
1776 else if ( -isp > (UWORD)(AC.cmod[0])/2 ) isp = isp + (UWORD)(AC.cmod[0]);
1779 if ( isp < 0 ) isp += (UWORD)(AC.cmod[0]);
1781 if ( isp <= MAXPOSITIVE && isp >= -MAXPOSITIVE ) {
1788 if ( funnum >= FUNCTION && functions[funnum-FUNCTION].tabl ) {
1794 WORD rhsnumber, *oldwork = AT.WorkPointer, *Tpattern;
1797 T = functions[funnum-FUNCTION].tabl;
1807 Tpattern = T->
pattern[AT.identity];
1811 p = Tpattern + FUNHEAD+1;
1816 if ( T->
numind == 0 ) { isp = 0; }
1818 for ( i = 0; i < T->
numind; i++, t += 2 ) {
1819 if ( *t != -SNUMBER )
break;
1821 if ( i < T->numind )
goto teststrict;
1823 isp = FindTableTree(T,t1+FUNHEAD,2);
1826teststrict:
if ( T->
strict == -2 ) {
1827 rhsnumber = AM.zerorhs;
1828 tbufnum = AM.zbufnum;
1830 else if ( T->
strict == -3 ) {
1831 rhsnumber = AM.onerhs;
1832 tbufnum = AM.zbufnum;
1834 else if ( T->
strict < 0 )
goto NextFun;
1836 MLOCK(ErrorMessageLock);
1837 MesPrint(
"Element in table is undefined");
1844 for ( i = 0; i < T->
numind; i++ ) {
1845 *p = *t; p+=2; t+=2;
1850#if ( TABLEEXTENSION == 2 )
1857 while ( --ii >= 0 ) {
1858 *p = *t; t += 2; p += 2;
1867 while ( --j >= 0 ) {
1868 if ( *t != -SNUMBER )
goto NextFun;
1870 if ( *t < mm->mini || *t > mm->
maxi ) {
1872 MLOCK(ErrorMessageLock);
1873 MesPrint(
"Table boundary check. Argument %d",
1875showtable: AO.OutFill = AO.OutputLine = (UBYTE *)m;
1880 MUNLOCK(ErrorMessageLock);
1885 i += ( *t - mm->
mini ) * (LONG)(mm->
size);
1893 i *= TABLEEXTENSION;
1896 rhsnumber = AM.zerorhs;
1897 tbufnum = AM.zbufnum;
1899 else if ( T->
strict == -3 ) {
1900 rhsnumber = AM.onerhs;
1901 tbufnum = AM.zbufnum;
1903 else if ( T->
strict < 0 )
goto NextFun;
1905 MLOCK(ErrorMessageLock);
1906 MesPrint(
"Element in table is undefined");
1912#if ( TABLEEXTENSION == 2 )
1928 AN.FullProto = T->
prototype[AT.identity];
1932 AN.WildValue = AN.FullProto + SUBEXPSIZE;
1933 AN.WildStop = AN.FullProto+AN.FullProto[1];
1936 AN.RepFunList = AN.EndNest;
1937 AT.WorkPointer = (WORD *)(((UBYTE *)(AN.EndNest)) + AM.MaxTer/2);
1938 if ( AT.WorkPointer >= AT.WorkTop ) {
1939 MLOCK(ErrorMessageLock);
1941 MUNLOCK(ErrorMessageLock);
1945 if ( MatchFunction(BHEAD Tpattern,t1,&wilds) > 0 ) {
1946 AT.WorkPointer = oldwork;
1947 if ( AT.NestPoin != AT.Nest ) {
1948 AN.ncmod = oldncmod;
1953 retvalue = m[2] = rhsnumber;
1962 while ( r < m ) *t++ = *r++;
1968 while ( t >= r ) { t[j] = *t; t--; }
1979 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
1980 AT.TMbuff = tbufnum;
1981 AN.ncmod = oldncmod;
1984 AT.WorkPointer = oldwork;
1988 else if ( ( t[2] & DIRTYFLAG ) != 0 ) {
1991 if ( *t == FUNNYDOLLAR ) {
1992 if ( AR.Eside != LHSIDE ) {
1995 AT.TMbuff = AM.dbufnum;
1996 AN.ncmod = oldncmod;
1999 AC.lhdollarflag = 1;
2005 AN.ncmod = oldncmod;
2010 MLOCK(ErrorMessageLock);
2013 MUNLOCK(ErrorMessageLock);
2036 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2037 WORD *u, *v, *w, *from, *to,
2038 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2042 m = r - ABS(*r) + 1;
2045 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2048 if ( ( term + AR.TePos ) == t ) {
2050 while ( from < t ) *m++ = *from++;
2052 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2055 *m++ = t[1] + 4 + ARGHEAD;
2061 while ( t < v ) *m++ = *t++;
2067 while ( t < r ) *m++ = *t++;
2068 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2069 *termout = WORDDIF(m,termout);
2073 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec == 0 )
2074 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2079 oldncmod = AN.ncmod;
2081 if ( *t > 0 && t[1] ) {
2082 WORD oldsorttype = AR.SortType;
2085 if ( ( AN.ncmod != 0 )
2086 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2087 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2092 while ( from < t ) {
2093 if ( from == u ) w = m;
2098 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2100 AR.SortType = SORTHIGHFIRST;
2109 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2111 AN.ncmod = oldncmod;
2121 if (
EndSort(BHEAD m,1) < 0 ) {
2122 AN.ncmod = oldncmod;
2125 AR.PolyFun = oldPolyFun;
2126 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2128 AR.SortType = oldsorttype;
2130 while ( *m ) m += *m;
2131 *to = WORDDIF(m,to);
2133 if ( ToFast(to,to) ) {
2134 if ( *to <= -FUNCTION ) m = to+1;
2137 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2140 while ( t < r ) *m++ = *t++;
2141 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2142 *termout = WORDDIF(m,termout);
2143 AR.DeferFlag = olddefer;
2144 AN.ncmod = oldncmod;
2147 else if ( *t == -DOLLAREXPRESSION ) {
2148 if ( AR.Eside == LHSIDE ) {
2150 AC.lhdollarflag = 1;
2156 DOLLARS d = Dollars + t[1];
2158 int nummodopt, dtype = -1;
2159 if ( AS.MultiThreaded ) {
2160 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2161 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2163 if ( nummodopt < NumModOptdollars ) {
2164 dtype = ModOptdollars[nummodopt].type;
2165 if ( dtype == MODLOCAL ) {
2166 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2169 LOCK(d->pthreadslockread);
2174 oldncmod = AN.ncmod;
2175 if ( ( AN.ncmod != 0 )
2176 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2177 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2181 while ( from < t ) {
2182 if ( from == u ) w = m;
2186 switch ( d->type ) {
2188 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2189 *m++ = -SNUMBER; *m++ = d->index;
2191 else { *m++ = -INDEX; *m++ = d->index; }
2194 *m++ = -SNUMBER; *m++ = 0;
break;
2196 if ( d->where[0] == 4 &&
2197 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2199 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2200 else *m++ = -d->where[1];
2210 to = m; r = d->where;
2214 i = *r; NCOPY(m,r,i)
2217 if ( ToFast(to,to) ) {
2218 if ( *to <= -FUNCTION ) m = to+1;
2221 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2235 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2236 AR.PolyFun = oldPolyFun;
2245 while ( *m ) m += *m;
2247 if ( ToFast(to,to) ) {
2248 if ( *to <= -FUNCTION ) m = to+1;
2253 w[1] = w[1] - 2 + (m-to);
2256 to = m; r = d->where;
2258 *m++ = i+4+ARGHEAD; *m++ = 1;
2261 while ( --i >= 0 ) *m++ = *r++;
2262 *m++ = 1; *m++ = 1; *m++ = 3;
2263 if ( ToFast(to,to) ) {
2264 if ( *to <= -FUNCTION ) m = to+1;
2267 w[1] = w[1] - 2 + (m-to);
2270 to = m; r = d->where;
2273 *m++ = *r++; *m++ = 1; r++;
2274 while ( --i >= 0 ) *m++ = *r++;
2276 else if ( *r <= -FUNCTION ) *m++ = *r++;
2277 else { *m++ = *r++; *m++ = *r++; }
2278 w[1] = w[1] - 2 + (m-to);
2281 to = m; r = d->where;
2284 while ( --i >= 0 ) {
2286 *m++ = -VECTOR; *m++ = *r++;
2288 else if ( *r >= AM.OffsetIndex ) {
2289 *m++ = -INDEX; *m++ = *r++;
2291 else { *m++ = -SNUMBER; *m++ = *r++; }
2299 *m++ = *r++; *m++ = 1; r++;
2300 while ( --i >= 0 ) *m++ = *r++;
2302 else if ( *r <= -FUNCTION ) *m++ = *r++;
2303 else { *m++ = *r++; *m++ = *r++; }
2306 w[1] = w[1] - 2 + (m-to);
2310 MLOCK(ErrorMessageLock);
2311 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2312 AC.dollarnames->namebuffer+d->name);
2313 MUNLOCK(ErrorMessageLock);
2315 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2320 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2324 while ( t < r ) *m++ = *t++;
2325 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2326 *termout = WORDDIF(m,termout);
2327 AR.DeferFlag = olddefer;
2328 AN.ncmod = oldncmod;
2332 else if ( *t == -TERMSINBRACKET ) {
2333 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2343 while ( from < t ) {
2344 if ( from == u ) w = m;
2347 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2348 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2351 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2353 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2354 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2359 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2360 *m++ = 6; *m++ = numterms & WORDMASK;
2361 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2366 while ( from < r ) *m++ = *from++;
2367 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2368 *termout = WORDDIF(m,termout);
2375 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec )
2376 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2377 u = t; v = t + t[1];
2380 if ( *t == FUNNYDOLLAR ) {
2381 if ( AR.Eside != LHSIDE ) {
2382 DOLLARS d = Dollars + t[1];
2384 int nummodopt, dtype = -1;
2385 if ( AS.MultiThreaded ) {
2386 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2387 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2389 if ( nummodopt < NumModOptdollars ) {
2390 dtype = ModOptdollars[nummodopt].type;
2391 if ( dtype == MODLOCAL ) {
2392 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2395 LOCK(d->pthreadslockread);
2400 oldncmod = AN.ncmod;
2401 if ( ( AN.ncmod != 0 )
2402 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2403 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2405 while ( from < t ) {
2406 if ( from == u ) w = m;
2410 switch ( d->type ) {
2412 *m++ = d->index;
break;
2417 if ( d->where[0] == 4 && d->where[4] == 0
2418 && d->where[3] == 3 && d->where[2] == 1
2419 && d->where[1] < AM.OffsetIndex ) {
2425 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2427 MLOCK(ErrorMessageLock);
2428 MesPrint(
"$%s has wrong type for tensor substitution",
2429 AC.dollarnames->namebuffer+d->name);
2430 MUNLOCK(ErrorMessageLock);
2431 AN.ncmod = oldncmod;
2436 if ( d->where[0] == -INDEX ) {
2437 *m++ = d->where[1];
break;
2439 else if ( d->where[0] == -VECTOR ) {
2440 *m++ = d->where[1];
break;
2442 else if ( d->where[0] == -MINVECTOR ) {
2447 else if ( d->where[0] == -SNUMBER ) {
2448 if ( d->where[1] >= 0
2449 && d->where[1] < AM.OffsetIndex ) {
2450 *m++ = d->where[1];
break;
2455 if ( d->where[0] > 0 ) {
2456 r = d->where; i = *r++;
2457 while ( --i >= 0 ) *m++ = *r++;
2462 if ( *r == -INDEX ) {
2463 *m++ = r[1]; r += 2;
continue;
2465 else if ( *r == -VECTOR ) {
2466 *m++ = r[1]; r += 2;
continue;
2468 else if ( *r == -MINVECTOR ) {
2469 *m++ = r[1]; r += 2;
2470 sign = -sign;
continue;
2472 else if ( *r == -SNUMBER ) {
2474 && r[1] < AM.OffsetIndex ) {
2475 *m++ = r[1]; r += 2;
continue;
2484 if ( *r == INDEX && r[1] == 3 ) {
2487 else goto wrongtype;
2491 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2493 MLOCK(ErrorMessageLock);
2494 MesPrint(
"$%s is undefined in tensor substitution",
2495 AC.dollarnames->namebuffer+d->name);
2496 MUNLOCK(ErrorMessageLock);
2497 AN.ncmod = oldncmod;
2501 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2503 w[1] = w[1] - 2 + (m-to);
2506 while ( from < term ) *m++ = *from++;
2507 if ( sign < 0 ) m[-1] = -m[-1];
2508 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2509 *termout = m - termout;
2510 AN.ncmod = oldncmod;
2514 AC.lhdollarflag = 1;
2523 MLOCK(ErrorMessageLock);
2524 MesPrint(
"Internal error in InFunction: Function not encountered.");
2525 if ( AM.tracebackflag ) {
2526 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2527 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2529 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2533 while ( --i >= 0 ) {
2534 TalToLine((UWORD)(*termout++));
2535 TokenToLine((UBYTE *)
" ");
2539 MesCall(
"InFunction");
2541 MUNLOCK(ErrorMessageLock);
2545 MLOCK(ErrorMessageLock);
2546 MesCall(
"InFunction");
2547 MUNLOCK(ErrorMessageLock);
2551 MLOCK(ErrorMessageLock);
2552 MesPrint(
"Output term too large. Try to increase MaxTermSize in the setup.");
2553 MesCall(
"InFunction");
2554 MUNLOCK(ErrorMessageLock);
3104 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3105 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, retnorm, extractbuff;
3106 int *RepSto = AN.RepPoint, iscopy = 0;
3107 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3108 LONG posisub, oldcpointer, oldacpointer;
3110 WORD numfac[5], idfunctionflag;
3112 int nummodopt, dtype = -1, id;
3114 oldtoprhs = CC->numrhs;
3115 oldcpointer = CC->Pointer - CC->Buffer;
3116 oldatoprhs = CCC->numrhs;
3117 oldacpointer = CCC->Pointer - CCC->Buffer;
3119 if ( ( replac =
TestSub(BHEAD term,level) ) == 0 ) {
3120 if ( applyflag ) { TableReset(); applyflag = 0; }
3129 AN.PolyNormFlag = 0;
3130 AN.idfunctionflag = 0;
3131 if ( ( retnorm = Normalize(BHEAD term) ) != 0 ) {
3132 if ( retnorm > 0 ) {
3133 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3138 idfunctionflag = AN.idfunctionflag;
3139 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3141 if ( AN.PolyNormFlag ) {
3142 if ( AN.PolyFunTodo == 0 ) {
3143 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3144 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3147 WORD oldPolyFunExp = AR.PolyFunExp;
3149 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3150 AT.WorkPointer = term+*term;
3151 AR.PolyFunExp = oldPolyFunExp;
3152 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3153 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3154 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3155 AT.WorkPointer = term+*term;
3156 if ( AN.PolyNormFlag ) {
3157 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3158 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3159 AT.WorkPointer = term+*term;
3164 if ( idfunctionflag > 0 ) {
3165 if ( TakeIDfunction(BHEAD term) ) {
3166 AT.WorkPointer = term + *term;
3170 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3171 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3174 if ( level > AR.Cnumlhs ) {
3175 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3177 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3182 if (
Deferred(BHEAD term,level) )
goto GenCall;
3185 if ( AN.ncmod != 0 ) {
3186 if ( Modulus(term) )
goto GenCall;
3187 if ( !*term )
goto Return0;
3189 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3190 WORD olddummies = AN.IndDum;
3191 AN.IndDum = AM.IndDum;
3192 ReNumber(BHEAD term);
3193 Normalize(BHEAD term);
3194 AN.IndDum = olddummies;
3195 if ( !*term )
goto Return0;
3196 olddummies = DetCurDum(BHEAD term);
3197 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3199 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3200 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3202 else if ( AR.PolyFun > 0 ) {
3203 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3205 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3206 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3207 termout = AT.WorkPointer;
3208 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3209 if ( PutBracket(BHEAD term) )
return(-1);
3210 AN.RepPoint = RepSto;
3211 *AT.WorkPointer = 0;
3213 AT.WorkPointer = termout;
3214 CC->numrhs = oldtoprhs;
3215 CC->Pointer = CC->Buffer + oldcpointer;
3216 CCC->numrhs = oldatoprhs;
3217 CCC->Pointer = CCC->Buffer + oldacpointer;
3221 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3222 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3223 *AT.WorkPointer = 0;
3224 AN.RepPoint = RepSto;
3226 CC->numrhs = oldtoprhs;
3227 CC->Pointer = CC->Buffer + oldcpointer;
3228 CCC->numrhs = oldatoprhs;
3229 CCC->Pointer = CCC->Buffer + oldacpointer;
3233 i = C->
lhs[level][0];
3234 if ( i >= TYPECOUNT ) {
3240 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3241 AT.WorkPointer = term + *term;
3246 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3249 level = AC.Labels[C->
lhs[level][2]];
3252 AT.WorkPointer = term + *term;
3262 WORD ic, jc, *ifcode, *jfcode;
3263 jfcode = C->
lhs[level]; jc = jfcode[1];
3264 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3265 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3266 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3267 level = C->
lhs[level][2];
3268 if ( C->
lhs[level][0] != TYPEELIF )
break;
3270 AT.WorkPointer = ifcode;
3273 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3274 level = C->
lhs[level][2];
3275 if ( C->
lhs[level][0] != TYPEELIF )
break;
3281 level = C->
lhs[level][2];
3282 }
while ( C->
lhs[level][0] == TYPEELIF );
3286 level = C->
lhs[level][2];
3290 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3291 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3292 WORD theindex = C->
lhs[level][2];
3293 if ( theindex < 0 ) {
3296 theindex = -theindex;
3297 d = Dollars + theindex;
3298 if ( AS.MultiThreaded ) {
3299 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3300 if ( theindex == ModOptdollars[nummodopt].number )
break;
3302 if ( nummodopt < NumModOptdollars ) {
3303 ddtype = ModOptdollars[nummodopt].type;
3304 if ( ddtype == MODLOCAL ) {
3305 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3308 LOCK(d->pthreadslockread);
3313 theindex = -theindex;
3314 d = Dollars + theindex;
3317 if ( d->type != DOLINDEX
3318 || d->index < AM.OffsetIndex
3319 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3320 MLOCK(ErrorMessageLock);
3321 MesPrint(
"$%s should have been an index"
3322 ,AC.dollarnames->namebuffer+d->name);
3323 AN.currentTerm = term;
3324 MesPrint(
"Current term: %t");
3325 AN.listinprint = printscratch;
3326 printscratch[0] = DOLLAREXPRESSION;
3327 printscratch[1] = theindex;
3329 ,AC.dollarnames->namebuffer+d->name);
3330 MUNLOCK(ErrorMessageLock);
3332 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3336 theindex = d->index;
3338 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3341 cp[1] = SUBEXPSIZE+4;
3346 i = C->
lhs[level][1] - 3;
3348 AR.CompressPointer = cp;
3349 while ( --i >= 0 ) {
3351 termout = AT.WorkPointer;
3352 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3356 while ( --jlhs >= 0 ) {
3357 if ( *m++ != *termout++ )
break;
3360 termout = AT.WorkPointer;
3361 AT.WorkPointer = termout + *termout;
3362 if (
Generator(BHEAD termout,level) )
goto GenCall;
3363 AT.WorkPointer = termout;
3366 AR.CompressPointer = op;
3370 AR.CompressPointer = op;
3375 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3381 AR.CurDum = DetCurDum(BHEAD term);
3382 i = C->
lhs[level][1]-2;
3383 wp = C->
lhs[level] + 2;
3384 cp[1] = SUBEXPSIZE+4*i;
3386 while ( --i >= 0 ) {
3388 if ( theindex < 0 ) {
3391 theindex = -theindex;
3392 d = Dollars + theindex;
3393 if ( AS.MultiThreaded ) {
3394 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3395 if ( theindex == ModOptdollars[nummodopt].number )
break;
3397 if ( nummodopt < NumModOptdollars ) {
3398 ddtype = ModOptdollars[nummodopt].type;
3399 if ( ddtype == MODLOCAL ) {
3400 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3403 LOCK(d->pthreadslockread);
3408 theindex = -theindex;
3409 d = Dollars + theindex;
3411 if ( d->type != DOLINDEX
3412 || d->index < AM.OffsetIndex
3413 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3414 MLOCK(ErrorMessageLock);
3415 MesPrint(
"$%s should have been an index"
3416 ,AC.dollarnames->namebuffer+d->name);
3417 AN.currentTerm = term;
3418 MesPrint(
"Current term: %t");
3419 AN.listinprint = printscratch;
3420 printscratch[0] = DOLLAREXPRESSION;
3421 printscratch[1] = theindex;
3423 ,AC.dollarnames->namebuffer+d->name);
3424 MUNLOCK(ErrorMessageLock);
3426 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3430 theindex = d->index;
3432 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3438 *cp++ = ++AR.CurDum;
3440 ow = AT.WorkPointer;
3441 AR.CompressPointer = cp;
3442 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3443 AR.CompressPointer = op;
3445 for ( j = 0; j < i; j++ ) term[j] = ow[j];
3446 AT.WorkPointer = ow;
3447 ReNumber(BHEAD term);
3451 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3453 AT.WorkPointer = term + *term;
3456 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3457 level = C->
lhs[level][2];
3458 if ( i > 0 )
goto ReStart;
3466 case TYPESPLITFIRSTARG:
3467 case TYPESPLITLASTARG:
3468 case TYPEARGTOEXTRASYMBOL:
3469 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3470 level = C->
lhs[level][2];
3475 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3476 if ( jjj > 0 )
goto ReStart;
3477 level = C->
lhs[level][2];
3480 if ( C->
lhs[level][2] > 0 ) {
3481 MLOCK(ErrorMessageLock);
3482 MesPrint(
"%s",C->
lhs[level]+3);
3483 MUNLOCK(ErrorMessageLock);
3491 AN.currentTerm = term;
3492 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3493 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3494 MLOCK(ErrorMessageLock);
3496 MesPrint((
char *)(C->
lhs[level]+5));
3498 MUNLOCK(ErrorMessageLock);
3503 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3504 AC.LogHandle = C->
lhs[level][2];
3505 MLOCK(ErrorMessageLock);
3506 oldFOflag = AM.FileOnlyFlag;
3507 oldPrintType = AO.PrintType;
3508 if ( AC.LogHandle >= 0 ) {
3509 AM.FileOnlyFlag = 1;
3510 AO.PrintType |= PRINTLFILE;
3512 AO.PrintType |= C->
lhs[level][3];
3513 AN.currentTerm = term;
3514 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3515 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3516 MesPrint((
char *)(C->
lhs[level]+5));
3517 AO.PrintType = oldPrintType;
3518 AM.FileOnlyFlag = oldFOflag;
3519 MUNLOCK(ErrorMessageLock);
3520 AC.LogHandle = oldLogHandle;
3524 j = C->
lhs[level][2];
3534 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3535 if ( AC.pfirstnum[ii] == j )
break;
3537 AC.inputnumbers[ii] = AN.ninterms;
3541 if ( AS.MultiThreaded ) {
3543 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3544 if ( AC.pfirstnum[ii] == j )
break;
3546 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3547 LOCK(AP.PreVarLock);
3548 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3549 a = C->
lhs[level]+4;
3550 if ( a[a[-1]] == 0 )
3551 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3554 ,(UBYTE *)(a+a[-1]+1),1);
3558 AC.inputnumbers[ii] = AN.inputnumber;
3560 UNLOCK(AP.PreVarLock);
3565 a = C->
lhs[level]+4;
3566 LOCK(AP.PreVarLock);
3567 if ( a[a[-1]] == 0 )
3568 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3571 ,(UBYTE *)(a+a[-1]+1),1);
3572 UNLOCK(AP.PreVarLock);
3576 AT.WorkPointer = term + *term;
3577 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3578 AT.WorkPointer = term + *term;
3579 if ( *term == 0 )
goto Return0;
3582 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3583 AT.WorkPointer = term + *term;
3586 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3587 WORD oldrepeat = *AN.RepPoint;
3593 AN.cTerm = AN.currentTerm = term;
3594 AT.WorkPointer = term + *term;
3595 *AT.WorkPointer++ = 0;
3596 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3597 AT.WorkPointer = term + *term;
3599 *AN.RepPoint = oldrepeat;
3600 AR.NoCompress = onc;
3601 AR.Eside = oldEside;
3605 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3606 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3607 AT.WorkPointer = term + *term;
3612 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3613 level = C->
lhs[level][2];
3616 retnorm = execterm(BHEAD term,level);
3617 AN.RepPoint = RepSto;
3619 CC->numrhs = oldtoprhs;
3620 CC->Pointer = CC->Buffer + oldcpointer;
3621 CCC->numrhs = oldatoprhs;
3622 CCC->Pointer = CCC->Buffer + oldacpointer;
3625 AT.WorkPointer = term + *term;
3626 AR.CurDum = DetCurDum(BHEAD term);
3628 case TYPEINEXPRESSION:
3629 {WORD *ll = C->
lhs[level];
3630 int numexprs = (int)(ll[1]-3);
3632 while ( numexprs-- >= 0 ) {
3633 if ( *ll == AR.CurExpr )
break;
3636 if ( numexprs < 0 ) level = C->
lhs[level][2];
3640 AT.WorkPointer = term + *term;
3641 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3643 AT.WorkPointer = term + *term;
3646 AT.WorkPointer = term + *term;
3647 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3649 AT.WorkPointer = term + *term;
3652 AT.WorkPointer = term + *term;
3653 if ( TestUse(term,level) )
goto GenCall;
3654 AT.WorkPointer = term + *term;
3657 AT.WorkPointer = term + *term;
3658 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3659 AT.WorkPointer = term + *term;
3663 AT.WorkPointer = term + *term;
3673 AT.WorkPointer = term + *term;
3674 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3675 AT.WorkPointer = term + *term;
3678 AT.WorkPointer = term + *term;
3679 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3680 AT.WorkPointer = term + *term;
3683 AT.WorkPointer = term + *term;
3684 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3685 AT.WorkPointer = term + *term;
3687 case TYPEARGIMPLODE:
3688 AT.WorkPointer = term + *term;
3689 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3690 AT.WorkPointer = term + *term;
3692 case TYPEARGEXPLODE:
3693 AT.WorkPointer = term + *term;
3694 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3695 AT.WorkPointer = term + *term;
3697 case TYPEDENOMINATORS:
3698 if ( DenToFunction(term,C->
lhs[level][2]) )
goto ReStart;
3700 case TYPEDROPCOEFFICIENT:
3701 DropCoefficient(BHEAD term);
3704 AT.WorkPointer = term + *term;
3705 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3706 AT.WorkPointer = term + *term;
3707 if ( *term == 0 )
goto Return0;
3709 case TYPETOPOLYNOMIAL:
3710 AT.WorkPointer = term + *term;
3711 termout = AT.WorkPointer;
3712 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3713 if ( *termout == 0 )
goto Return0;
3714 i = termout[0]; t = term; NCOPY(t,termout,i);
3715 AT.WorkPointer = term + *term;
3717 case TYPEFROMPOLYNOMIAL:
3718 AT.WorkPointer = term + *term;
3719 termout = AT.WorkPointer;
3720 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3721 if ( *term == 0 )
goto Return0;
3722 i = termout[0]; t = term; NCOPY(t,termout,i);
3723 AT.WorkPointer = term + *term;
3726 level = TestDoLoop(BHEAD C->
lhs[level],level);
3727 if ( level < 0 )
goto GenCall;
3730 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3731 if ( level < 0 )
goto GenCall;
3733 case TYPEDROPSYMBOLS:
3734 DropSymbols(BHEAD term);
3737 AT.WorkPointer = term + *term;
3738 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3739 AT.WorkPointer = term + *term;
3744 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3746 case TYPETOSPECTATOR:
3747 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3749 case TYPECANONICALIZE:
3750 AT.WorkPointer = term + *term;
3751 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3752 AT.WorkPointer = term + *term;
3753 if ( *term == 0 )
goto Return0;
3756 AT.WorkPointer = term + *term;
3757 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3760 AT.WorkPointer = term + *term;
3761 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3769 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
3770 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3771 if ( i > 0 ) replac =
TestSub(BHEAD term,level);
3773 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
3778AutoGen: i = *AT.TMout;
3779 t = termout = AT.WorkPointer;
3780 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
3782 while ( --i >= 0 ) *t++ = *accum++;
3783 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
3784 AT.WorkPointer = termout;
3788 if ( applyflag ) { TableReset(); applyflag = 0; }
3792 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
3794 if ( AR.TePos >= 0 )
goto AutoGen;
3795 switch ( AN.TeInFun ) {
3797 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
3800 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
3803 if ( DoTableExpansion(term,level) )
goto GenCall;
3806 if ( FactorIn(BHEAD term,level) )
goto GenCall;
3809 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
3812 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
3815 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
3818 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
3821 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
3824 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
3827 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
3830 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
3833 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
3836 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
3839 if ( GenTopologies(BHEAD term,level) < 0 )
goto GenCall;
3842 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
3847 termout = AT.WorkPointer;
3848 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3849 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3850 if (
InFunction(BHEAD term,termout) )
goto GenCall;
3851 AT.WorkPointer = termout + *termout;
3854 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3855 AT.WorkPointer = termout;
3858 else if ( replac > 0 ) {
3862 power = -power; tepos = 0;
3864 extractbuff = AT.TMbuff;
3865 if ( extractbuff == AM.dbufnum ) {
3866 d = DolToTerms(BHEAD replac);
3867 if ( d && d->where != 0 ) {
3869 if ( AT.TMdolfac > 0 ) {
3870 if ( AT.TMdolfac == 1 ) {
3871 if ( d->nfactors ) {
3873 numfac[1] = d->nfactors;
3884 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
3885 MLOCK(ErrorMessageLock);
3886 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
3887 if ( d->nfactors == 1 )
3888 MesPrint(
"There is only one factor");
3890 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
3891 MUNLOCK(ErrorMessageLock);
3894 if ( d->nfactors > 1 ) {
3898 dd = Dollars + replac;
3901 int nummodopt, dtype = -1;
3902 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
3903 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3904 if ( replac == ModOptdollars[nummodopt].number )
break;
3906 if ( nummodopt < NumModOptdollars ) {
3907 dtype = ModOptdollars[nummodopt].type;
3908 if ( dtype == MODLOCAL ) {
3909 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
3915 dsize = dd->factors[AT.TMdolfac-2].size;
3921 numfac[1] = d->factors[AT.TMdolfac-2].value;
3926 if ( numfac[1] < 0 ) {
3927 numfac[1] = -numfac[1];
3928 numfac[3] = -numfac[3];
3932 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
3933 (dsize+1)*
sizeof(WORD),
"Copy of factor");
3934 td1 = dd->factors[AT.TMdolfac-2].where;
3936 d->size = dsize; d->type = DOLTERMS;
3937 NCOPY(td2,td1,dsize);
3941 else if ( d->nfactors == 1 ) {
3942 StartBuf = d->where;
3945 MLOCK(ErrorMessageLock);
3946 if ( d->nfactors == 0 ) {
3947 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
3950 MesPrint(
"Internal error. Illegal number of factors for $-variable");
3952 MUNLOCK(ErrorMessageLock);
3957 else StartBuf = d->where;
3960 d = Dollars + replac;
3961 StartBuf = zeroDollar;
3964 i = DetCommu(d->where);
3966 if ( AS.MultiThreaded ) {
3967 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3968 if ( replac == ModOptdollars[nummodopt].number )
break;
3970 if ( nummodopt < NumModOptdollars ) {
3971 dtype = ModOptdollars[nummodopt].type;
3972 if ( dtype != MODLOCAL && dtype != MODSUM ) {
3973 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
3974 MLOCK(ErrorMessageLock);
3975 MesPrint(
"A dollar variable with modoption max or min can have only one term");
3976 MUNLOCK(ErrorMessageLock);
3979 LOCK(d->pthreadslockread);
3986 StartBuf = cbuf[extractbuff].Buffer;
3987 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
3988 i = (WORD)cbuf[extractbuff].CanCommu[replac];
3991 termout = AT.WorkPointer;
3992 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3993 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3994 while ( StartBuf[posisub] ) {
3995 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
3996 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
3997 if (
InsertTerm(BHEAD term,replac,extractbuff,
3998 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
3999 AT.WorkPointer = termout + *termout;
4002 posisub += StartBuf[posisub];
4014 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4015 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
4016 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4017 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4022 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4024 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4026 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4033 StartBuf = cbuf[extractbuff].Buffer;
4036 if ( extractbuff == AT.allbufnum ) {
4037 CBUF *Ce = cbuf + extractbuff;
4041 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4044 if ( d->nfactors > 1 ) {
4046 for ( j = 0; j < d->nfactors; j++ ) {
4047 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4049 M_free(d->factors,
"Dollar factors");
4051 M_free(d,
"Copy of dollar variable");
4054 AT.WorkPointer = termout;
4056 else if ( i <= 1 ) {
4058 WORD *same, *ow = AT.WorkPointer;
4059 LONG olpw = AT.posWorkPointer;
4061 WantAddLongs(power1);
4062 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4063 same = ++AT.WorkPointer;
4064 a = accum = ( AT.WorkPointer += power1+1 );
4065 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4066 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4067 AT.lWorkSpace[posit] = posisub;
4074 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4076 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4078 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4079 same[1] = *same + 1;
4080 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4081 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4087 i--; posit--; same--;
4090 termout = AT.WorkPointer = a;
4091 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4092 if ( AT.WorkPointer > AT.WorkTop )
4094 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4095 AT.WorkPointer = termout + *termout;
4099 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4100 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4101 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4102 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4106 if (
Generator(BHEAD termout,level) )
goto GenCall;
4108 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4110 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4111 StartBuf = cbuf[extractbuff].Buffer;
4112 i--; posit--; same--;
4116 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4119 if ( d->nfactors > 1 ) {
4121 for ( j = 0; j < d->nfactors; j++ ) {
4122 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4124 M_free(d->factors,
"Dollar factors");
4126 M_free(d,
"Copy of dollar variable");
4129 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4132 LONG posit, olw, olpw = AT.posWorkPointer;
4133 WantAddLongs(power);
4134 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4135 a = accum = AT.WorkPointer;
4136 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4137 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4138 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4144 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4146 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4147 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4151 AT.lWorkSpace[posit--] = posisub;
4155 termout = AT.WorkPointer = a;
4156 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4157 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4158 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4159 AT.WorkPointer = termout + *termout;
4163 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4164 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4165 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4169 if (
Generator(BHEAD termout,level) )
goto GenCall;
4171 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { dtype = 0;
break; }
4173 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4174 StartBuf = cbuf[extractbuff].Buffer;
4179 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4182 if ( d->nfactors > 1 ) {
4184 for ( j = 0; j < d->nfactors; j++ ) {
4185 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4187 M_free(d->factors,
"Dollar factors");
4189 M_free(d,
"Copy of dollar variable");
4192 AT.WorkPointer = accum;
4193 AT.lWorkPointer = olw;
4194 AT.posWorkPointer = olpw;
4199 LONG position, olpw, opw, comprev, extra;
4201 WORD *Freeze, *aa, *dummies;
4205 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4207 SETSTARTPOS(firstpos);
4219 WantAddPointers(power+1);
4220 comprev = opw = AT.pWorkPointer;
4221 AT.pWorkPointer += power+1;
4222 WantAddPositions(power+1);
4223 position = olpw = AT.posWorkPointer;
4224 AT.posWorkPointer += power + 1;
4226 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4228 for ( i = 0; i < power; i++ ) {
4229 PUTZERO(AT.posWorkSpace[position]); position++;
4232 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4233 dummies = AT.WorkPointer;
4234 *dummies++ = AR.CurDum;
4235 AT.WorkPointer += power+2;
4236 accum = AT.WorkPointer;
4237 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4238 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4239 aa = AT.WorkPointer;
4241 i = 0; StartPos = AT.posWorkSpace[position];
4242 dummies[i] = AR.CurDum;
4245 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4246 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4247 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4248 if ( Expressions[replac].numdummies > 0 ) {
4249 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4251 if ( NOTSTARTPOS(firstpos) ) {
4252 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4253 firstpos = AT.posWorkSpace[position];
4264 i++; AT.posWorkSpace[++position] = StartPos;
4265 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4266 dummies[i] = AR.CurDum;
4269 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4270 AR.CurDum = dummies[i];
4274 termout = AT.WorkPointer = a;
4275 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4276 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4277 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4279 AT.WorkPointer = termout + *termout;
4283 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4284 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4289 if (
Generator(BHEAD termout,level) )
goto GenCall;
4292 AR.CurDum = dummies[i];
4295 AT.WorkPointer = aa;
4297 AT.WorkPointer = accum;
4298 AT.posWorkPointer = olpw;
4299 AT.pWorkPointer = opw;
4307 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4308 M_free(renumber->
symb.
lo,
"VarSpace");
4309 M_free(renumber,
"Renumber");
4313 aa = accum = AT.WorkPointer;
4314 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4316 *accum++ = -1; AT.WorkPointer++;
4317 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4318 AT.WorkPointer = aa;
4323 AN.RepPoint = RepSto;
4324 CC->numrhs = oldtoprhs;
4325 CC->Pointer = CC->Buffer + oldcpointer;
4326 CCC->numrhs = oldatoprhs;
4327 CCC->Pointer = CCC->Buffer + oldacpointer;
4331 if ( AM.tracebackflag ) {
4333 MLOCK(ErrorMessageLock);
4334 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4338 while ( --i >= 0 ) {
4339 TalToLine((UWORD)(*termout++));
4340 TokenToLine((UBYTE *)
" ");
4344 MesCall(
"Generator");
4345 MUNLOCK(ErrorMessageLock);
4347 CC->numrhs = oldtoprhs;
4348 CC->Pointer = CC->Buffer + oldcpointer;
4349 CCC->numrhs = oldatoprhs;
4350 CCC->Pointer = CCC->Buffer + oldacpointer;
4353 CC->numrhs = oldtoprhs;
4354 CC->Pointer = CC->Buffer + oldcpointer;
4355 CCC->numrhs = oldatoprhs;
4356 CCC->Pointer = CCC->Buffer + oldacpointer;
4357 MLOCK(ErrorMessageLock);
4359 MUNLOCK(ErrorMessageLock);
5135 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5136 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5137 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0, retval = 0;
5138 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5140 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5143 if ( *t != AR.PolyFun ) {
5145 if ( t == w ) { t += t[1]; w = t; }
5146 else { i = t[1]; NCOPY(w,t,i) }
5150 t2 = t + t[1]; t += FUNHEAD;
5152 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5153 else if ( *t != -SNUMBER )
goto NoLegal;
5156 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5157 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5158 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5159 pow1 += t[ARGHEAD+4];
5164 MLOCK(ErrorMessageLock);
5165 MesPrint(
"Illegal term with divergence in PolyRatFun");
5166 MesCall(
"PolyFunMul");
5167 MUNLOCK(ErrorMessageLock);
5171 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5172 else if ( *t != -SNUMBER )
goto NoLegal;
5175 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5176 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5177 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5178 pow1 -= t[ARGHEAD+4];
5182 if ( t == t2 ) pow += pow1;
5186 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5188 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5189 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5190 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5192 else if ( pow == 1 ) {
5193 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5195 else if ( pow < -1 ) {
5196 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5197 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5198 *w++ = 1; *w++ = 1; *w++ = 3;
5200 else if ( pow == -1 ) {
5201 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5204 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5207 *w++ = 1; *w++ = 1; *w++ = 3;
5209 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5213 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5214 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5215 WORD count1 = 0, count2 = 0, count3;
5216 WORD oldtype = AR.SortType;
5217 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5219 if ( *t == AR.PolyFun ) {
5220 if ( t[2] && dirty == 0 ) {
5225 if ( term[0] == 0 )
return(0);
5230 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5231 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5232 if ( count3 == 2 ) {
5234 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5237 AR.SortType = SORTHIGHFIRST;
5238 t2 = t + t[1]; tt2 = t+FUNHEAD;
5239 while ( tt2 < t2 ) {
5241 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5243 while ( tt1 < tt2 ) {
5244 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5245 AT.WorkPointer = ww;
5250 ww = w;
while ( *ww ) ww += *ww;
5251 if ( ww-w != *tt4-ARGHEAD ) {
5256 WORD *r1 = TermMalloc(
"PolyFunMul");
5257 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5258 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5259 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5260 i = ww-w; ww = w; NCOPY(r4,ww,i);
5261 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5262 *r1 = i = r4-r1; r4 = term; r3 = r1;
5264 t[1] += ii; t1 += ii; *tt4 += ii;
5266 TermFree(r1,
"PolyFunMul");
5269 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5274 else if ( *tt2 <= -FUNCTION ) tt2++;
5277 AR.SortType = oldtype;
5283 if ( count1 <= 1 ) {
goto checkaction; }
5284 if ( AR.PolyFunExp == 1 ) {
5285 t = term + *term; t -= ABS(t[-1]);
5286 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5289 AR.SortType = SORTHIGHFIRST;
5293 if ( *term == 0 )
return(retval);
5294 AR.SortType = oldtype;
5297 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5299 if ( *t == AR.PolyFun ) {
5300 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5301 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5302 if ( count3 == 2 ) {
5308 if ( count1 >= count2 ) {
5311 if ( *t == AR.PolyFun ) {
5314 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5317 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5326 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5328 if ( action ) retval = action;
5332 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5333 AT.WorkPointer = term + *term;
5334 GETSTOP(term,tstop);
5336 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5337 while ( t < tstop && *t == AR.PolyFun ) {
5338 if ( t[1] > FUNHEAD ) {
5339 if ( t[FUNHEAD] < 0 ) {
5340 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5341 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5342 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5349 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5354 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5357 while ( t < tstop && *t == AR.PolyFun ) {
5358 if ( t[1] > FUNHEAD ) {
5359 if ( t[FUNHEAD] < 0 ) {
5360 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5361 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5362 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5369 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5374 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5382 n1 = 1; arg1 = AT.WorkPointer;
5383 ToGeneral(t,arg1,1);
5384 AT.WorkPointer = arg1 + *arg1;
5388 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5389 while ( t < t1 ) { n1++; t += *t; }
5393 n2 = 1; arg2 = AT.WorkPointer;
5394 ToGeneral(t,arg2,1);
5395 AT.WorkPointer = arg2 + *arg2;
5399 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5400 while ( t < t2 ) { n2++; t += *t; }
5412 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5419 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5421 if ( minp1 > 0 ) minp1 = 0;
5423 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5424 if ( minp1 > 0 ) minp1 = 0;
5427 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5428 if ( t1[4] < minp1 ) minp1 = t1[4];
5431 MesPrint(
"Illegal term in expanded polyratfun.");
5437 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5439 if ( minp2 > 0 ) minp2 = 0;
5441 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5442 if ( minp2 > 0 ) minp2 = 0;
5445 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5446 if ( t2[4] < minp2 ) minp2 = t2[4];
5449 MesPrint(
"Illegal term in expanded polyratfun.");
5454 AR.PolyFunPow += minp1+minp2;
5456 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5457 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5462 while ( t < tt1 ) *m++ = *t++;
5465 while ( t < tt2 ) *m++ = *t++;
5466 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5471 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5472 l3 = REDLENG(m[-1]);
5476 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5478 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5480 if ( l4 == 0 )
continue;
5483 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5485 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5494 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5496 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5499 if ( l3 == 0 )
continue;
5509 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5510 AR.PolyFunPow = OldPolyFunPow;
5517 while ( *t ) t += *t;
5521 while ( t1 < fun1 ) *t++ = *t1++;
5524 *t++ = FUNHEAD+ARGHEAD+n1;
5531 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5532 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5533 else t2[FUNHEAD] = FUNHEAD+1;
5536 t1 = fun1 + fun1[1];
5537 while ( t1 < fun2 ) *t++ = *t1++;
5538 t1 = fun2 + fun2[1];
5540 while ( t1 < t2 ) *t++ = *t1++;
5541 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5542 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5543 MLOCK(ErrorMessageLock);
5544 MesPrint(
"Term too complex. Maybe increasing MaxTermSize can help");
5547 m = term; t = AT.WorkPointer;
5552 AT.WorkPointer = term + *term;
5553 if ( action && noac ) {
5554 if ( Normalize(BHEAD term) )
goto PolyCall;
5555 AT.WorkPointer = term + *term;
5559 MLOCK(ErrorMessageLock);
5561 AR.PolyFunPow = OldPolyFunPow;
5562 MesCall(
"PolyFunMul");
5563 MUNLOCK(ErrorMessageLock);