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);
295 case LOCALEXPRESSION:
296 case GLOBALEXPRESSION:
300 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
302 SetScratch(AR.infile,&(e->onfile));
308 MesPrint(
"Error in PF_Processor");
312 if ( AC.mparallelflag != PARALLELFLAG ){
317 if ( GetTerm(BHEAD term) <= 0 ) {
319 MesPrint(
"Error condition 1a");
322 MesPrint(
"(2) Expression %d has problems in scratchfile(process)",i);
328 fromspectator = -term[5];
329 PUTZERO(AM.SpectatorFiles[fromspectator-1].readpos);
330 term[5] = AC.cbufnum;
332 else fromspectator = 0;
333 if ( AR.outtohide ) {
334 SeekScratch(AR.hidefile,&position);
335 e->onfile = position;
336 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
339 SeekScratch(AR.outfile,&position);
340 e->onfile = position;
341 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
343 AR.DeferFlag = AC.ComDefer;
345 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
347 AT.BrackBuf = AM.BracketFactors;
348 AT.bracketindexflag = 1;
350 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
352 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
353 if ( ThreadsProcessor(e,LastExpression,fromspectator) ) {
354 MesPrint(
"Error in ThreadsProcessor");
357 if ( AR.outtohide ) {
358 AR.outfile = oldoutfile;
359 AR.hidefile->POfull = AR.hidefile->POfill;
366 AR.MaxDum = AM.IndDum;
369 if ( fromspectator ) size = GetFromSpectator(term,fromspectator-1);
370 else size = GetTerm(BHEAD term);
371 if ( size <= 0 )
break;
372 SeekScratch(curfile,&position);
373 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
377 AN.ninterms++; dd = AN.deferskipped;
378 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
379 if ( GetMoreTerms(term) < 0 ) {
382 SeekScratch(curfile,&position);
384 AT.WorkPointer = term + *term;
385 AN.RepPoint = AT.RepCount + 1;
386 if ( AR.DeferFlag ) {
387 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
388 AR.CurDum = AN.IndDum;
391 AN.IndDum = AM.IndDum;
392 AR.CurDum = ReNumber(BHEAD term);
394 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
396 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
397 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
399 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
400 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
401 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
402 PolyFunClean(BHEAD term);
409 SetScratch(curfile,&position);
410 if ( AR.GetFile == 2 ) {
411 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
412 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
415 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
416 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
420 if ( LastExpression ) {
422 if ( AR.infile->handle >= 0 ) {
423 CloseFile(AR.infile->handle);
424 AR.infile->handle = -1;
425 remove(AR.infile->name);
426 PUTZERO(AR.infile->POposition);
428 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
430 if ( AR.outtohide ) AR.outfile = AR.hidefile;
431 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
432 if ( AR.outtohide ) {
433 AR.outfile = oldoutfile;
434 AR.hidefile->POfull = AR.hidefile->POfill;
436 e->numdummies = AR.MaxDum - AM.IndDum;
439 AR.BracketOn = oldBracketOn;
440 AT.BrackBuf = oldBrackBuf;
441 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
442 poly_factorize_expression(e);
444 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
445 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
446 poly_unfactorize_expression(e);
448 AT.bracketindexflag = oldbracketindexflag;
449 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
450 else e->vflags |= ISZERO;
451 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
452 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
453 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
461 if ( e->status == INTOHIDELEXPRESSION ||
462 e->status == INTOHIDEGEXPRESSION ) {
467 case SKIPLEXPRESSION:
468 case SKIPGEXPRESSION:
473 if ( PF.me != MASTER )
break;
476 SetScratch(AR.infile,&(e->onfile));
477 if ( GetTerm(BHEAD term) <= 0 ) {
479 MesPrint(
"Error condition 1b");
482 MesPrint(
"(3) Expression %d has problems in scratchfile",i);
488 SeekScratch(AR.outfile,&position);
489 e->onfile = position;
490 *AM.S0->sBuffer = 0; firstterm = -1;
492 WORD *oldipointer = AR.CompressPointer;
493 WORD *comprtop = AR.ComprTop;
494 AR.ComprTop = AM.S0->sTop;
495 AR.CompressPointer = AM.S0->sBuffer;
496 if ( firstterm > 0 ) {
497 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
499 else if ( firstterm < 0 ) {
500 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
504 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
507 AR.CompressPointer = oldipointer;
508 AR.ComprTop = comprtop;
509 }
while ( GetTerm(BHEAD term) );
510 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
513 case HIDELEXPRESSION:
514 case HIDEGEXPRESSION:
516 if ( PF.me != MASTER )
break;
519 SetScratch(AR.infile,&(e->onfile));
520 if ( GetTerm(BHEAD term) <= 0 ) {
522 MesPrint(
"Error condition 1c");
525 MesPrint(
"(4) Expression %d has problems in scratchfile",i);
531 SetEndHScratch(AR.hidefile,&position);
532 e->onfile = position;
534 if ( AR.hidefile->handle >= 0 ) {
538 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
539 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
540 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
541 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
543 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
546 *AM.S0->sBuffer = 0; firstterm = -1;
547 cbo = cpo = AM.S0->sBuffer;
549 WORD *oldipointer = AR.CompressPointer;
550 WORD *oldibuffer = AR.CompressBuffer;
551 WORD *comprtop = AR.ComprTop;
552 AR.ComprTop = AM.S0->sTop;
553 AR.CompressPointer = cpo;
554 AR.CompressBuffer = cbo;
555 if ( firstterm > 0 ) {
556 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
558 else if ( firstterm < 0 ) {
559 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
563 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
566 cpo = AR.CompressPointer;
567 cbo = AR.CompressBuffer;
568 AR.CompressPointer = oldipointer;
569 AR.CompressBuffer = oldibuffer;
570 AR.ComprTop = comprtop;
571 }
while ( GetTerm(BHEAD term) );
573 if ( AR.hidefile->handle >= 0 ) {
577 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
578 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
579 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
580 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
582 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
585 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
586 AR.hidefile->POfull = AR.hidefile->POfill;
588 if ( AR.hidefile->handle >= 0 ) {
592 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
593 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
594 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
595 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
597 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
608 if ( e->status == HIDELEXPRESSION ) {
609 e->status = HIDDENLEXPRESSION;
610 AS.OldOnFile[i] = e->onfile;
611 AS.OldNumFactors[i] = Expressions[i].numfactors;
613 if ( e->status == HIDEGEXPRESSION ) {
614 e->status = HIDDENGEXPRESSION;
615 AS.OldOnFile[i] = e->onfile;
616 AS.OldNumFactors[i] = Expressions[i].numfactors;
623 case DROPPEDEXPRESSION:
624 case DROPLEXPRESSION:
625 case DROPGEXPRESSION:
626 case DROPHLEXPRESSION:
627 case DROPHGEXPRESSION:
628 case STOREDEXPRESSION:
629 case HIDDENLEXPRESSION:
630 case HIDDENGEXPRESSION:
631 case SPECTATOREXPRESSION:
639 AT.WorkPointer = term;
641 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
642 for ( i = 0; i < NumExpressions; i++ ) {
649 AT.WorkPointer = term;
650 if ( AM.tracebackflag ) MesCall(
"Processor");
683 WORD *m, *t, *r, retvalue, funflag, j, oldncmod, nexpr;
684 WORD *stop, *t1, *t2, funnum, wilds, tbufnum, stilldirty = 0;
686 CBUF *C = cbuf+AT.ebufnum;
689 VOID *oldcompareroutine = AR.CompareRoutine;
690 WORD oldsorttype = AR.SortType;
693 AT.TMbuff = AM.rbufnum;
700 if ( *t == SUBEXPRESSION ) {
710 #ifdef WHICHSUBEXPRESSION 712 WORD *tmin = t, AN.nbino;
716 if ( AN.BinoScrat == 0 ) {
717 AN.BinoScrat = (UWORD *)Malloc1((AM.MaxTal+2)*
sizeof(UWORD),
"GetBinoScrat");
722 while ( AN.subsubveto == 0 &&
723 *r == SUBEXPRESSION && r < m && r[3] ) {
724 #ifdef WHICHSUBEXPRESSION 727 if ( r[1] == t[1] && r[2] == t[2] && r[4] == t[4] ) {
728 j = t[1] - SUBEXPSIZE;
731 while ( j > 0 && *t1++ == *t2++ ) j--;
739 while ( t1 < t2 ) *r++ = *t1++;
747 while ( t1 < t2 ) *r++ = *t1++;
752 #ifdef WHICHSUBEXPRESSION 754 else if ( t[2] >= 0 ) {
760 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
761 if ( AN.last3 > minval ) {
762 minval = AN.last3; tmin = t;
766 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
769 minval = mm; tmin = t;
772 else if ( t[3] > 0 ) {
773 if ( mm > MAXPOSITIVE )
goto TooMuch;
774 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
775 if ( AN.nbino > 2 )
goto TooMuch;
776 if ( AN.nbino == 2 ) {
777 mm = AN.BinoScrat[1];
778 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
780 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
783 minval = mm; tmin = t;
793 #ifdef WHICHSUBEXPRESSION 794 if ( mnum1 > 1 && t[2] >= 0 ) {
798 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
799 if ( AN.last3 > minval ) {
800 minval = AN.last3; tmin = t;
804 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
807 minval = mm; tmin = t;
810 else if ( t[3] > 0 ) {
811 if ( mm > MAXPOSITIVE ) {
816 MLOCK(ErrorMessageLock);
817 MesPrint(
"Attempt to generate more terms than FORM can count");
818 MUNLOCK(ErrorMessageLock);
821 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
822 if ( AN.nbino > 2 )
goto TooMuch;
823 if ( AN.nbino == 2 ) {
824 mm = AN.BinoScrat[1];
825 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
827 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
830 minval = mm; tmin = t;
839 AR.TePos = WORDDIF(t,term);
841 if ( t[4] == AM.dbufnum && (t+t[1]) < m && t[t[1]] == DOLLAREXPR2 ) {
842 if ( t[t[1]+2] < 0 ) AT.TMdolfac = -t[t[1]+2];
844 AT.TMdolfac = GetDolNum(BHEAD t+t[1],m)+1;
847 else AT.TMdolfac = 0;
850 AR.TePos = WORDDIF(t,term);
864 else if ( *t == EXPRESSION ) {
869 AR.TePos = WORDDIF(t,term);
873 toTMaddr = m = AT.WorkPointer;
888 if ( *t == FROMBRAC ) {
889 WORD *ttstop,*tttstop;
896 AN.Frozen = m = AT.WorkPointer;
904 j = *t; tttstop = t + j;
907 while ( t < ttstop ) {
908 if ( *t == SUBEXPRESSION )
break;
909 if ( *t >= FUNCTION && ( ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) )
break;
910 j = t[1]; NCOPY(m,t,j);
918 while ( t < tttstop ) *m++ = *t++;
919 *AT.WorkPointer = m-AT.WorkPointer;
921 AT.WorkPointer = m + *m;
926 if (
EndSort(BHEAD m,0) < 0 )
goto EndTest;
929 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
931 else if ( m[*m] != 0 ) {
932 MLOCK(ErrorMessageLock);
933 MesPrint(
"Bracket specification in expression should be one single term");
934 MUNLOCK(ErrorMessageLock);
940 *m++ = 1; *m++ = 1; *m++ = 3;
941 *AN.Frozen = m - AN.Frozen;
945 while ( t < tttstop ) *m++ = *t++;
946 *AT.WorkPointer = m-AT.WorkPointer;
948 AT.WorkPointer = m + *m;
949 if ( Normalize(BHEAD m) ) {
950 MLOCK(ErrorMessageLock);
951 MesPrint(
"Error while picking up contents of bracket");
952 MUNLOCK(ErrorMessageLock);
956 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
968 AT.TMaddr = toTMaddr;
971 else if ( *t >= FUNCTION ) {
972 if ( t[0] == EXPONENT ) {
973 if ( t[1] == FUNHEAD+4 && t[FUNHEAD] == -SYMBOL &&
974 t[FUNHEAD+2] == -SNUMBER && t[FUNHEAD+3] < MAXPOWER
975 && t[FUNHEAD+3] > -MAXPOWER ) {
983 while ( m < r ) *t++ = *m++;
984 *term = WORDDIF(t,term);
987 else if ( t[1] == FUNHEAD+ARGHEAD+11 && t[FUNHEAD] == ARGHEAD+9
988 && t[FUNHEAD+ARGHEAD] == 9 && t[FUNHEAD+ARGHEAD+1] == DOTPRODUCT
989 && t[FUNHEAD+ARGHEAD+8] == 3
990 && t[FUNHEAD+ARGHEAD+7] == 1
991 && t[FUNHEAD+ARGHEAD+6] == 1
992 && t[FUNHEAD+ARGHEAD+5] == 1
993 && t[FUNHEAD+ARGHEAD+9] == -SNUMBER
994 && t[FUNHEAD+ARGHEAD+10] < MAXPOWER
995 && t[FUNHEAD+ARGHEAD+10] > -MAXPOWER ) {
998 t[2] = t[FUNHEAD+ARGHEAD+3];
999 t[3] = t[FUNHEAD+ARGHEAD+4];
1000 t[4] = t[FUNHEAD+ARGHEAD+10];
1002 m = t + FUNHEAD+ARGHEAD+11;
1004 while ( m < r ) *t++ = *m++;
1005 *term = WORDDIF(t,term);
1010 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
1011 if ( *t == EXPONENT ) {
1017 if ( *r == -SNUMBER && r[1] < MAXPOWER && r+2 == t+t[1] &&
1018 t[FUNHEAD] > -FUNCTION && ( t[FUNHEAD] != -SNUMBER
1019 || t[FUNHEAD+1] != 0 ) && t[FUNHEAD] != ARGHEAD ) {
1021 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
1022 MLOCK(ErrorMessageLock);
1023 MesPrint(
"Encountered 0^0. Fatal error.");
1024 MUNLOCK(ErrorMessageLock);
1037 t1 =
AddRHS(AT.ebufnum,1);
1041 i = t[FUNHEAD] - ARGHEAD;
1042 while ( (t1 + i + 10) > C->
Top )
1044 while ( --i >= 0 ) *t1++ = *m++;
1047 if ( (t1 + 20) > C->
Top )
1053 C->
rhs[C->numrhs+1] = t1;
1059 *t++ = SUBEXPRESSION;
1065 Important: we may not have enough spots here
1070 do { *t++ = *r++; }
while ( r < m );
1071 *term -= WORDDIF(r,t);
1076 else if ( *t == SUMF1 || *t == SUMF2 ) {
1088 WORD *tstop, lcounter, lcmin, lcmax, lcinc;
1091 if ( r+6 < tstop && r[2] == -SNUMBER && r[4] == -SNUMBER
1092 && ( ( r[0] == -SYMBOL )
1093 || ( r[0] == -INDEX && r[1] >= AM.OffsetIndex
1094 && r[3] >= 0 && r[3] < AM.OffsetIndex
1095 && r[5] >= 0 && r[5] < AM.OffsetIndex ) ) ) {
1096 lcounter = r[0] == -INDEX ? -r[1]: r[1];
1100 if ( *r == -SNUMBER && r+2 < tstop ) {
1105 if ( r < tstop && ( ( *r > 0 && (r+*r) == tstop )
1106 || ( *r <= -FUNCTION && r+1 == tstop )
1107 || ( *r > -FUNCTION && *r < 0 && r+2 == tstop ) ) ) {
1108 m =
AddRHS(AT.ebufnum,1);
1112 while ( (m + i + 10) > C->
Top )
1114 while ( --i >= 0 ) *m++ = *r++;
1117 while ( (m + 20) > C->
Top )
1123 C->
rhs[C->numrhs+1] = m;
1127 if ( *t == SUMF1 ) *m++ = SUMNUM1;
1128 else *m++ = SUMNUM2;
1134 r = C->
rhs[C->numrhs];
1141 if ( *r >= (SUBEXPSIZE+4)
1142 && ABS(*(r+*r-1)) < (*r - 1)
1143 && r[1] == SUBEXPRESSION ) {
1146 *t++ = *r++; *t++ = *r++; *t++ = C->numrhs;
1147 r++; *t++ = *r++; *t++ = AT.ebufnum; r++;
1148 while ( --i >= 0 ) *t++ = *r++;
1151 *t++ = SUBEXPRESSION;
1152 *t++ = 4+SUBEXPSIZE;
1157 if ( lcounter < 0 ) {
1170 while ( m < t2 ) *t++ = *m++;
1171 *term = WORDDIF(t,term);
1172 AN.TeInFun = -C->numrhs;
1175 AT.TMbuff = AT.ebufnum;
1180 if ( functions[funnum-FUNCTION].spec == 0
1181 || ( t[2] & (DIRTYFLAG|MUSTCLEANPRF) ) != 0 ) { funflag = 1; }
1182 if ( *t <= MAXBUILTINFUNCTION ) {
1183 if ( *t <= DELTAP && *t >= THETA ) {
1184 if ( *t == THETA || *t == THETA2 ) {
1185 WORD *tstop, *tt2, kk;
1188 while ( tt2 < tstop ) {
1189 if ( *tt2 > 0 && tt2[1] != 0 )
goto DoSpec;
1192 if ( !AT.RecFlag ) {
1193 if ( ( kk = DoTheta(BHEAD t) ) == 0 ) {
1197 else if ( kk > 0 ) {
1200 while ( m < r ) *t++ = *m++;
1201 *term = WORDDIF(t,term);
1206 else if ( *t == DELTA2 || *t == DELTAP ) {
1207 WORD *tstop, *tt2, kk;
1210 while ( tt2 < tstop ) {
1211 if ( *tt2 > 0 && tt2[1] != 0 )
goto DoSpec;
1214 if ( !AT.RecFlag ) {
1215 if ( ( kk = DoDelta(t) ) == 0 ) {
1219 else if ( kk > 0 ) {
1222 while ( m < r ) *t++ = *m++;
1223 *term = WORDDIF(t,term);
1228 else if ( *t == DISTRIBUTION && t[FUNHEAD] == -SNUMBER
1229 && t[FUNHEAD+1] >= -2 && t[FUNHEAD+1] <= 2
1230 && t[FUNHEAD+2] == -SNUMBER
1231 && t[FUNHEAD+4] <= -FUNCTION
1232 && t[FUNHEAD+5] <= -FUNCTION ) {
1233 WORD *ttt = t+FUNHEAD+6, *tttstop = t+t[1];
1234 while ( ttt < tttstop ) {
1235 if ( *ttt == -DOLLAREXPRESSION )
break;
1238 if ( ttt >= tttstop ) {
1245 else if ( *t == DELTA3 && ((t[1]-FUNHEAD) & 1 ) == 0 ) {
1251 else if ( ( *t == TABLEFUNCTION ) && ( t[FUNHEAD] <= -FUNCTION )
1252 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1253 && ( t[1] >= FUNHEAD+1+2*T->
numind )
1254 && ( t[FUNHEAD+1] == -SYMBOL ) ) {
1258 for ( isp = 0; isp < T->
numind; isp++ ) {
1259 if ( t[FUNHEAD+1+2*isp] != -SYMBOL )
break;
1261 if ( isp >= T->
numind ) {
1268 else if ( *t == TABLEFUNCTION && t[FUNHEAD] <= -FUNCTION
1269 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1270 && ( t[1] == FUNHEAD+2 )
1271 && ( t[FUNHEAD+1] <= -FUNCTION ) ) {
1280 else if ( *t == FACTORIN ) {
1281 if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -DOLLAREXPRESSION ) {
1287 else if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -EXPRESSION ) {
1294 else if ( *t == TERMSINBRACKET ) {
1295 if ( t[1] == FUNHEAD || (
1297 && t[FUNHEAD] == -SNUMBER
1298 && t[FUNHEAD+1] == 0
1338 else if ( *t == EXTRASYMFUN ) {
1339 if ( t[1] == FUNHEAD+2 && (
1340 ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] <= cbuf[AM.sbufnum].numrhs
1341 && t[FUNHEAD+1] > 0 ) ||
1342 ( t[FUNHEAD] == -SYMBOL && t[FUNHEAD+1] < MAXVARIABLES
1343 && t[FUNHEAD+1] >= MAXVARIABLES-cbuf[AM.sbufnum].numrhs ) ) ) {
1349 else if ( t[1] == FUNHEAD ) {
1356 else if ( *t == DIVFUNCTION || *t == REMFUNCTION
1357 || *t == INVERSEFUNCTION || *t == MULFUNCTION
1358 || *t == GCDFUNCTION ) {
1360 int todo = 1, numargs = 0;
1362 while ( tf < t + t[1] ) {
1364 if ( *tf == -DOLLAREXPRESSION ) {
1365 d = Dollars + tf[1];
1366 if ( d->type == DOLWILDARGS ) {
1367 WORD *tterm = AT.WorkPointer, *tw;
1368 WORD *ta = term, *tb = tterm, *tc, *td = term + *term;
1369 while ( ta < t ) *tb++ = *ta++;
1371 while ( ta < tf ) *tb++ = *ta++;
1375 if ( *tw > -FUNCTION ) *tb++ = *tw++;
1380 for ( ia = 0; ia < *tw; ia++ ) *tb++ = *tw++;
1384 while ( ta < t+t[1] ) *tb++ = *ta++;
1386 while ( ta < td ) *tb++ = *ta++;
1387 *tterm = tb - tterm;
1389 int ia, na = *tterm;
1390 ta = tterm; tb = term;
1391 for ( ia = 0; ia < na; ia++ ) *tb++ = *ta++;
1393 if ( tb > AT.WorkTop ) {
1394 MLOCK(ErrorMessageLock);
1398 AT.WorkPointer = tb;
1405 while ( tf < t + t[1] ) {
1407 if ( *tf > 0 && tf[1] != 0 ) todo = 0;
1410 if ( todo && numargs == 2 ) {
1411 if ( *t == DIVFUNCTION ) AN.TeInFun = -9;
1412 else if ( *t == REMFUNCTION ) AN.TeInFun = -10;
1413 else if ( *t == INVERSEFUNCTION ) AN.TeInFun = -11;
1414 else if ( *t == MULFUNCTION ) AN.TeInFun = -14;
1415 else if ( *t == GCDFUNCTION ) AN.TeInFun = -8;
1420 else if ( todo && *t == GCDFUNCTION ) {
1427 else if ( *t == PERMUTATIONS && ( ( t[1] >= FUNHEAD+1
1428 && t[FUNHEAD] <= -FUNCTION ) || ( t[1] >= FUNHEAD+3
1429 && t[FUNHEAD] == -SNUMBER && t[FUNHEAD+2] <= -FUNCTION ) ) ) {
1435 else if ( *t == PARTITIONS ) {
1436 if ( TestPartitions(BHEAD t,&(AT.partitions)) ) {
1437 AT.partitions.where = t-term;
1451 AT.NestPoin->termsize = t;
1452 if ( AT.NestPoin == AT.Nest ) AN.EndNest = t + *t;
1454 oldncmod = AN.ncmod;
1456 if ( *t < FUNCTION ) {
1457 t += t[1];
continue;
1459 if ( AN.ncmod && ( ( AC.modmode & ALSOFUNARGS ) == 0 ) ) {
1460 if ( *t != AR.PolyFun ) AN.ncmod = 0;
1461 else AN.ncmod = oldncmod;
1465 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
1466 if ( ( *t == NUMFACTORS || *t == FIRSTTERM || *t == CONTENTTERM )
1467 && t[1] == FUNHEAD+2 &&
1468 ( t[FUNHEAD] == -EXPRESSION || t[FUNHEAD] == -DOLLAREXPRESSION ) ) {
1475 else if ( functions[funnum-FUNCTION].spec == 0 ) {
1476 AT.NestPoin->funsize = t + 1;
1480 if ( *t > 0 && t[1] ) {
1481 AT.NestPoin->argsize = t;
1486 while ( t < AT.NestPoin[-1].argsize+*(AT.NestPoin[-1].argsize) ) {
1498 if ( ( retvalue =
TestSub(BHEAD t,level) ) != 0 ) {
1511 while ( r < m ) *t++ = *r++;
1516 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 )
1517 t1[2] |= MUSTCLEANPRF;
1522 AN.ncmod = oldncmod;
1535 if ( *t == 0 ) { retvalue = 1;
goto redosize; }
1537 WORD *tend = t + *t, *tt = t+1;
1539 tend -= ABS(tend[-1]);
1540 while ( tt < tend ) {
1541 if ( *tt == SUBEXPRESSION ) {
1542 stilldirty = 1;
break;
1555 while ( r < m ) *t++ = *r++;
1557 t = AT.NestPoin[-1].argsize + ARGHEAD;
1570 t = AT.NestPoin->argsize;
1574 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1576 AR.SortType = SORTHIGHFIRST;
1578 if ( AT.WorkPointer < term + *term )
1579 AT.WorkPointer = term + *term;
1581 while ( t < AT.NestPoin->argsize+*(AT.NestPoin->argsize) ) {
1584 do { *m++ = *t++; }
while ( t < r );
1586 AT.WorkPointer = r + *r;
1587 if ( Normalize(BHEAD r) ) {
1588 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1589 AR.SortType = oldsorttype;
1590 AR.CompareRoutine = oldcompareroutine;
1591 t1[2] |= MUSTCLEANPRF;
1595 if ( AN.ncmod != 0 ) {
1600 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1601 AR.SortType = oldsorttype;
1602 AR.CompareRoutine = oldcompareroutine;
1603 t1[2] |= MUSTCLEANPRF;
1609 if ( AR.PolyFun > 0 ) {
1610 if (
PrepPoly(BHEAD r,1) != 0 )
goto EndTest;
1616 if (
EndSort(BHEAD AT.WorkPointer+ARGHEAD,1) < 0 )
goto EndTest;
1617 m = AT.WorkPointer+ARGHEAD;
1618 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1619 AR.SortType = oldsorttype;
1620 AR.CompareRoutine = oldcompareroutine;
1621 t1[2] |= MUSTCLEANPRF;
1623 while ( *m ) m += *m;
1624 i = WORDDIF(m,AT.WorkPointer);
1625 *AT.WorkPointer = i;
1626 AT.WorkPointer[1] = stilldirty;
1627 if ( ToFast(AT.WorkPointer,AT.WorkPointer) ) {
1629 if ( *m <= -FUNCTION ) { m++; i = 1; }
1630 else { m += 2; i = 2; }
1635 if ( r > AT.WorkTop ) {
1636 MLOCK(ErrorMessageLock);
1640 do { *--r = *--m; }
while ( m > AT.WorkPointer );
1644 stop = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1645 do { *--r = *--m; }
while ( m >= stop );
1648 m = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1650 do { *r++ = *m++; }
while ( m < AN.EndNest );
1652 m = AT.NestPoin->argsize;
1654 while ( --i >= 0 ) *m++ = *r++;
1656 while ( n <= AT.NestPoin ) {
1657 if ( *(n->argsize) > 0 && n != AT.NestPoin )
1660 *(n->termsize) += j;
1665 if ( funnum == DENOMINATOR || funnum == EXPONENT ) {
1666 if ( Normalize(BHEAD term) ) {
1676 AN.ncmod = oldncmod;
1683 AN.ncmod = oldncmod;
1686 else if ( *t == -DOLLAREXPRESSION ) {
1687 if ( *t1 == TERMSINEXPR && t1[1] == FUNHEAD+2 ) {}
1689 if ( AR.Eside != LHSIDE ) {
1690 AN.TeInFun = 1; AR.TePos = 0;
1691 AT.TMbuff = AM.dbufnum; t1[2] |= DIRTYFLAG;
1692 AN.ncmod = oldncmod;
1695 AC.lhdollarflag = 1;
1698 else if ( *t == -TERMSINBRACKET ) {
1699 if ( AR.Eside != LHSIDE ) {
1700 AN.TeInFun = 1; AR.TePos = 0;
1702 AN.ncmod = oldncmod;
1706 else if ( AN.ncmod != 0 && *t == -SNUMBER ) {
1707 if ( AN.ncmod == 1 || AN.ncmod == -1 ) {
1708 isp = (UWORD)(AC.cmod[0]);
1710 if ( ( AC.modmode & POSNEG ) != 0 ) {
1711 if ( isp > (UWORD)(AC.cmod[0])/2 ) isp = isp - (UWORD)(AC.cmod[0]);
1712 else if ( -isp > (UWORD)(AC.cmod[0])/2 ) isp = isp + (UWORD)(AC.cmod[0]);
1715 if ( isp < 0 ) isp += (UWORD)(AC.cmod[0]);
1717 if ( isp <= MAXPOSITIVE && isp >= -MAXPOSITIVE ) {
1724 if ( funnum >= FUNCTION && functions[funnum-FUNCTION].tabl ) {
1730 WORD rhsnumber, *oldwork = AT.WorkPointer, *Tpattern;
1733 T = functions[funnum-FUNCTION].tabl;
1743 Tpattern = T->
pattern[AT.identity];
1747 p = Tpattern + FUNHEAD+1;
1752 if ( T->
numind == 0 ) { isp = 0; }
1754 for ( i = 0; i < T->
numind; i++, t += 2 ) {
1755 if ( *t != -SNUMBER )
break;
1757 if ( i < T->numind )
goto teststrict;
1759 isp = FindTableTree(T,t1+FUNHEAD,2);
1762 teststrict:
if ( T->
strict == -2 ) {
1763 rhsnumber = AM.zerorhs;
1764 tbufnum = AM.zbufnum;
1766 else if ( T->
strict == -3 ) {
1767 rhsnumber = AM.onerhs;
1768 tbufnum = AM.zbufnum;
1770 else if ( T->
strict < 0 )
goto NextFun;
1772 MLOCK(ErrorMessageLock);
1773 MesPrint(
"Element in table is undefined");
1780 for ( i = 0; i < T->
numind; i++ ) {
1781 *p = *t; p+=2; t+=2;
1786 #if ( TABLEEXTENSION == 2 ) 1793 while ( --ii >= 0 ) {
1794 *p = *t; t += 2; p += 2;
1803 while ( --j >= 0 ) {
1804 if ( *t != -SNUMBER )
goto NextFun;
1806 if ( *t < mm->mini || *t > mm->
maxi ) {
1808 MLOCK(ErrorMessageLock);
1809 MesPrint(
"Table boundary check. Argument %d",
1811 showtable: AO.OutFill = AO.OutputLine = (UBYTE *)m;
1816 MUNLOCK(ErrorMessageLock);
1821 i += ( *t - mm->
mini ) * (LONG)(mm->
size);
1829 i *= TABLEEXTENSION;
1832 rhsnumber = AM.zerorhs;
1833 tbufnum = AM.zbufnum;
1835 else if ( T->
strict == -3 ) {
1836 rhsnumber = AM.onerhs;
1837 tbufnum = AM.zbufnum;
1839 else if ( T->
strict < 0 )
goto NextFun;
1841 MLOCK(ErrorMessageLock);
1842 MesPrint(
"Element in table is undefined");
1848 #if ( TABLEEXTENSION == 2 ) 1864 AN.FullProto = T->
prototype[AT.identity];
1868 AN.WildValue = AN.FullProto + SUBEXPSIZE;
1869 AN.WildStop = AN.FullProto+AN.FullProto[1];
1872 AN.RepFunList = AN.EndNest;
1873 AT.WorkPointer = (WORD *)(((UBYTE *)(AN.EndNest)) + AM.MaxTer/2);
1874 if ( AT.WorkPointer >= AT.WorkTop ) {
1875 MLOCK(ErrorMessageLock);
1877 MUNLOCK(ErrorMessageLock);
1881 if ( MatchFunction(BHEAD Tpattern,t1,&wilds) > 0 ) {
1882 AT.WorkPointer = oldwork;
1883 if ( AT.NestPoin != AT.Nest ) {
1884 AN.ncmod = oldncmod;
1889 retvalue = m[2] = rhsnumber;
1898 while ( r < m ) *t++ = *r++;
1904 while ( t >= r ) { t[j] = *t; t--; }
1915 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
1916 AT.TMbuff = tbufnum;
1917 AN.ncmod = oldncmod;
1920 AT.WorkPointer = oldwork;
1924 else if ( ( t[2] & DIRTYFLAG ) != 0 ) {
1927 if ( *t == FUNNYDOLLAR ) {
1928 if ( AR.Eside != LHSIDE ) {
1931 AT.TMbuff = AM.dbufnum;
1932 AN.ncmod = oldncmod;
1935 AC.lhdollarflag = 1;
1941 AN.ncmod = oldncmod;
1946 MLOCK(ErrorMessageLock);
1949 MUNLOCK(ErrorMessageLock);
1972 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
1973 WORD *u, *v, *w, *from, *to,
1974 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
1978 m = r - ABS(*r) + 1;
1981 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
1984 if ( ( term + AR.TePos ) == t ) {
1986 while ( from < t ) *m++ = *from++;
1988 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
1991 *m++ = t[1] + 4 + ARGHEAD;
1997 while ( t < v ) *m++ = *t++;
2003 while ( t < r ) *m++ = *t++;
2004 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2005 *termout = WORDDIF(m,termout);
2009 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec == 0 )
2010 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2015 oldncmod = AN.ncmod;
2017 if ( *t > 0 && t[1] ) {
2018 WORD oldsorttype = AR.SortType;
2021 if ( ( AN.ncmod != 0 )
2022 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2023 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2028 while ( from < t ) {
2029 if ( from == u ) w = m;
2034 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2036 AR.SortType = SORTHIGHFIRST;
2045 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2047 AN.ncmod = oldncmod;
2057 if (
EndSort(BHEAD m,1) < 0 ) {
2058 AN.ncmod = oldncmod;
2061 AR.PolyFun = oldPolyFun;
2062 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2064 AR.SortType = oldsorttype;
2066 while ( *m ) m += *m;
2067 *to = WORDDIF(m,to);
2069 if ( ToFast(to,to) ) {
2070 if ( *to <= -FUNCTION ) m = to+1;
2073 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2076 while ( t < r ) *m++ = *t++;
2077 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2078 *termout = WORDDIF(m,termout);
2079 AR.DeferFlag = olddefer;
2080 AN.ncmod = oldncmod;
2083 else if ( *t == -DOLLAREXPRESSION ) {
2084 if ( AR.Eside == LHSIDE ) {
2086 AC.lhdollarflag = 1;
2094 int nummodopt, dtype = -1;
2095 if ( AS.MultiThreaded ) {
2096 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2097 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2099 if ( nummodopt < NumModOptdollars ) {
2100 dtype = ModOptdollars[nummodopt].type;
2101 if ( dtype == MODLOCAL ) {
2102 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2105 LOCK(d->pthreadslockread);
2110 oldncmod = AN.ncmod;
2111 if ( ( AN.ncmod != 0 )
2112 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2113 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2117 while ( from < t ) {
2118 if ( from == u ) w = m;
2122 switch ( d->type ) {
2124 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2125 *m++ = -SNUMBER; *m++ = d->index;
2127 else { *m++ = -INDEX; *m++ = d->index; }
2130 *m++ = -SNUMBER; *m++ = 0;
break;
2132 if ( d->where[0] == 4 &&
2133 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2135 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2136 else *m++ = -d->where[1];
2145 to = m; r = d->where;
2149 i = *r; NCOPY(m,r,i)
2152 if ( ToFast(to,to) ) {
2153 if ( *to <= -FUNCTION ) m = to+1;
2156 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2170 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2171 AR.PolyFun = oldPolyFun;
2180 while ( *m ) m += *m;
2182 if ( ToFast(to,to) ) {
2183 if ( *to <= -FUNCTION ) m = to+1;
2188 w[1] = w[1] - 2 + (m-to);
2191 to = m; r = d->where;
2193 *m++ = i+4+ARGHEAD; *m++ = 1;
2196 while ( --i >= 0 ) *m++ = *r++;
2197 *m++ = 1; *m++ = 1; *m++ = 3;
2198 if ( ToFast(to,to) ) {
2199 if ( *to <= -FUNCTION ) m = to+1;
2202 w[1] = w[1] - 2 + (m-to);
2205 to = m; r = d->where;
2208 *m++ = *r++; *m++ = 1; r++;
2209 while ( --i >= 0 ) *m++ = *r++;
2211 else if ( *r <= -FUNCTION ) *m++ = *r++;
2212 else { *m++ = *r++; *m++ = *r++; }
2213 w[1] = w[1] - 2 + (m-to);
2216 to = m; r = d->where;
2219 while ( --i >= 0 ) {
2221 *m++ = -VECTOR; *m++ = *r++;
2223 else if ( *r >= AM.OffsetIndex ) {
2224 *m++ = -INDEX; *m++ = *r++;
2226 else { *m++ = -SNUMBER; *m++ = *r++; }
2234 *m++ = *r++; *m++ = 1; r++;
2235 while ( --i >= 0 ) *m++ = *r++;
2237 else if ( *r <= -FUNCTION ) *m++ = *r++;
2238 else { *m++ = *r++; *m++ = *r++; }
2241 w[1] = w[1] - 2 + (m-to);
2245 MLOCK(ErrorMessageLock);
2246 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2247 AC.dollarnames->namebuffer+d->name);
2248 MUNLOCK(ErrorMessageLock);
2250 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2255 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2259 while ( t < r ) *m++ = *t++;
2260 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2261 *termout = WORDDIF(m,termout);
2262 AR.DeferFlag = olddefer;
2263 AN.ncmod = oldncmod;
2267 else if ( *t == -TERMSINBRACKET ) {
2268 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2278 while ( from < t ) {
2279 if ( from == u ) w = m;
2282 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2283 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2286 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2288 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2289 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2294 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2295 *m++ = 6; *m++ = numterms & WORDMASK;
2296 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2301 while ( from < r ) *m++ = *from++;
2302 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2303 *termout = WORDDIF(m,termout);
2310 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec )
2311 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2312 u = t; v = t + t[1];
2315 if ( *t == FUNNYDOLLAR ) {
2316 if ( AR.Eside != LHSIDE ) {
2319 int nummodopt, dtype = -1;
2320 if ( AS.MultiThreaded ) {
2321 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2322 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2324 if ( nummodopt < NumModOptdollars ) {
2325 dtype = ModOptdollars[nummodopt].type;
2326 if ( dtype == MODLOCAL ) {
2327 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2330 LOCK(d->pthreadslockread);
2335 oldncmod = AN.ncmod;
2336 if ( ( AN.ncmod != 0 )
2337 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2338 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2340 while ( from < t ) {
2341 if ( from == u ) w = m;
2345 switch ( d->type ) {
2347 *m++ = d->index;
break;
2352 if ( d->where[0] == 4 && d->where[4] == 0
2353 && d->where[3] == 3 && d->where[2] == 1
2354 && d->where[1] < AM.OffsetIndex ) {
2360 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2362 MLOCK(ErrorMessageLock);
2363 MesPrint(
"$%s has wrong type for tensor substitution",
2364 AC.dollarnames->namebuffer+d->name);
2365 MUNLOCK(ErrorMessageLock);
2366 AN.ncmod = oldncmod;
2371 if ( d->where[0] == -INDEX ) {
2372 *m++ = d->where[1];
break;
2374 else if ( d->where[0] == -VECTOR ) {
2375 *m++ = d->where[1];
break;
2377 else if ( d->where[0] == -MINVECTOR ) {
2382 else if ( d->where[0] == -SNUMBER ) {
2383 if ( d->where[1] >= 0
2384 && d->where[1] < AM.OffsetIndex ) {
2385 *m++ = d->where[1];
break;
2390 if ( d->where[0] > 0 ) {
2391 r = d->where; i = *r++;
2392 while ( --i >= 0 ) *m++ = *r++;
2397 if ( *r == -INDEX ) {
2398 *m++ = r[1]; r += 2;
continue;
2400 else if ( *r == -VECTOR ) {
2401 *m++ = r[1]; r += 2;
continue;
2403 else if ( *r == -MINVECTOR ) {
2404 *m++ = r[1]; r += 2;
2405 sign = -sign;
continue;
2407 else if ( *r == -SNUMBER ) {
2409 && r[1] < AM.OffsetIndex ) {
2410 *m++ = r[1]; r += 2;
continue;
2419 if ( *r == INDEX && r[1] == 3 ) {
2422 else goto wrongtype;
2426 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2428 MLOCK(ErrorMessageLock);
2429 MesPrint(
"$%s is undefined in tensor substitution",
2430 AC.dollarnames->namebuffer+d->name);
2431 MUNLOCK(ErrorMessageLock);
2432 AN.ncmod = oldncmod;
2436 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2438 w[1] = w[1] - 2 + (m-to);
2441 while ( from < term ) *m++ = *from++;
2442 if ( sign < 0 ) m[-1] = -m[-1];
2443 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2444 *termout = m - termout;
2445 AN.ncmod = oldncmod;
2449 AC.lhdollarflag = 1;
2458 MLOCK(ErrorMessageLock);
2459 MesPrint(
"Internal error in InFunction: Function not encountered.");
2460 if ( AM.tracebackflag ) {
2461 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2462 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2464 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2468 while ( --i >= 0 ) {
2469 TalToLine((UWORD)(*termout++));
2470 TokenToLine((UBYTE *)
" ");
2474 MesCall(
"InFunction");
2476 MUNLOCK(ErrorMessageLock);
2480 MLOCK(ErrorMessageLock);
2481 MesCall(
"InFunction");
2482 MUNLOCK(ErrorMessageLock);
2486 MLOCK(ErrorMessageLock);
2487 MesPrint(
"Output term too large. Try to increase MaxTermSize in the setup.");
2488 MesCall(
"InFunction");
2489 MUNLOCK(ErrorMessageLock);
2514 WORD
InsertTerm(
PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout,
2518 WORD *m, *t, *r, i, l2, j;
2519 WORD *u, *v, l1, *coef;
2520 coef = AT.WorkPointer;
2521 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2522 MLOCK(ErrorMessageLock);
2524 MUNLOCK(ErrorMessageLock);
2537 if ( *t == SUBEXPRESSION && t[2] == replac && t[3] && t[4] == extractbuff ) {
2539 while ( *r == SUBEXPRESSION && r[2] == replac && r[3] && r < m && r[4] == extractbuff ) {
2546 do { *m++ = *r++; }
while ( r < t );
2547 if ( t[1] > SUBEXPSIZE ) {
2552 if ( ( l2 = WildFill(BHEAD m,position,t) ) < 0 )
goto InsCall;
2556 i = ( j = ABS(l2) ) - 1;
2558 do { *--r = *--m; }
while ( --i > 0 );
2565 r -= ( j = ABS(l2) );
2567 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2571 while ( t < u && *t == DOLLAREXPR2 ) t += t[1];
2572 ComAct:
if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2573 if ( *r == 1 && r[1] == 1 && j == 3 ) {
2574 if ( l2 < 0 ) l1 = -l1;
2580 if ( MulRat(BHEAD (UWORD *)u,REDLENG(l1),(UWORD *)r,REDLENG(l2),
2581 (UWORD *)m,&l1) )
goto InsCall;
2593 *termout = WORDDIF(m,termout);
2594 if ( (*termout)*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
2595 MLOCK(ErrorMessageLock);
2596 MesPrint(
"Term too complex during substitution. MaxTermSize of %l is too small",AM.MaxTer);
2599 AT.WorkPointer = coef;
2613 do { *m++ = *r++; }
while ( r < t );
2617 r -= ( j = ABS(l2) );
2619 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2624 MLOCK(ErrorMessageLock);
2626 MesCall(
"InsertTerm");
2627 MUNLOCK(ErrorMessageLock);
2651 RENUMBER renumber, WORD *freeze, WORD nexpr)
2655 WORD *stop, *s1, *s2;
2660 stop = (WORD *)(((UBYTE *)(accum)) + 2*AM.MaxTer);
2662 while ( --number >= 0 ) accum += *accum;
2665 oldipointer = AR.CompressPointer;
2667 AR.CompressPointer = oldipointer;
2669 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 )
2671 if ( !l ) { *accum = 0;
return(0); }
2676 while ( r < m && *r != HAAKJE ) r += r[1];
2678 if ( *freeze != 4 ) l = -1;
2694 *m++ = WORDDIF(s2,r) + 3;
2696 while ( r < s2 ) *m++ = *r++;
2697 *m++ = 1; *m++ = 1; *m++ = 3;
2699 if ( Normalize(BHEAD AT.WorkPointer) )
goto PasErr;
2702 while ( --i >= 0 && *m++ == *r++ ) {}
2712 do { *r++ = *m++; }
while ( m < s1 );
2713 *accum = l = WORDDIF(r,accum);
2717 retlength = InCompState;
2721 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 ) {
2722 MLOCK(ErrorMessageLock);
2723 MesCall(
"PasteFile");
2724 MUNLOCK(ErrorMessageLock);
2727 if ( l == 0 ) { *accum = 0;
return(0); }
2728 retlength = InCompState;
2731 if ( accum > stop ) {
2732 MLOCK(ErrorMessageLock);
2733 MesPrint(
"Buffer too small in PasteFile");
2734 MUNLOCK(ErrorMessageLock);
2741 MLOCK(ErrorMessageLock);
2742 MesCall(
"PasteFile");
2743 MUNLOCK(ErrorMessageLock);
2772 WORD *
PasteTerm(
PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby)
2775 WORD *t, *r, x, y, z;
2776 WORD *m, *u, l1, a[2];
2777 m = (WORD *)(((UBYTE *)(accum)) + AM.MaxTer);
2780 while ( --number >= 0 ) accum += *accum;
2781 if ( times == divby ) {
2784 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2792 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2793 if ( divby > times ) { x = divby; y = times; }
2794 else { x = times; y = divby; }
2796 while ( z ) { x = y; y = z; z = x%y; }
2797 if ( y != 1 ) { divby /= y; times /= y; }
2800 if ( MulRat(BHEAD (UWORD *)t,REDLENG(l1),(UWORD *)a,1,(UWORD *)accum,&l1) ) {
2801 MLOCK(ErrorMessageLock);
2802 MesCall(
"PasteTerm");
2803 MUNLOCK(ErrorMessageLock);
2808 if ( x < 0 ) { accum -= x; *accum++ = x - 1; }
2809 else { accum += x; *accum++ = x + 1; }
2810 *u = WORDDIF(accum,u);
2813 MLOCK(ErrorMessageLock);
2814 MesPrint(
"Buffer too small in PasteTerm");
2815 MUNLOCK(ErrorMessageLock);
2837 WORD
FiniTerm(
PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos)
2840 WORD *m, *t, *r, i, numacc, l2, ipp;
2841 WORD *u, *v, l1, *coef = AT.WorkPointer, *oldaccum;
2842 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2843 MLOCK(ErrorMessageLock);
2845 MUNLOCK(ErrorMessageLock);
2854 do { *--r = *--m; }
while ( --i > 0 );
2861 if ( ( ( *t == SUBEXPRESSION && ( *(r=t+t[1]) != SUBEXPRESSION
2862 || r >= m || !r[3] ) ) || *t == EXPRESSION ) && t[2] == number && t[3] ) {
2867 if ( r < t )
do { *m++ = *r++; }
while ( r < t );
2869 if ( numacc >= 0 )
do {
2870 if ( *t == EXPRESSION ) {
2874 if ( *r == WILDCARDS ) {
2877 if ( ( l2 = WildFill(BHEAD m,accum,r) ) < 0 )
goto FiniCall;
2884 else if ( t[1] > SUBEXPSIZE && t[SUBEXPSIZE] != FROMBRAC ) {
2886 if ( ( l2 = WildFill(BHEAD m,accum,t) ) < 0 )
goto FiniCall;
2899 if ( r < v )
do { *m++ = *r++; }
while ( r < v );
2901 if ( *r == 1 && r[1] == 1 && ABS(l2) == 3 ) {
2902 if ( l2 < 0 ) l1 = -l1;
2911 while ( --numacc >= 0 ) {
2913 while ( --i >= 0 ) {
2914 TalToLine((UWORD)(*t++));
2915 TokenToLine((UBYTE *)
" ");
2922 if ( MulRat(BHEAD (UWORD *)coef,l1,(UWORD *)r,l2,(UWORD *)coef,&l1) )
goto FiniCall;
2923 if ( AN.ncmod != 0 && TakeModulus((UWORD *)coef,&l1,AC.cmod,AN.ncmod,UNPACK|AC.modmode) )
goto FiniCall;
2926 }
while ( --numacc >= 0 );
2927 if ( *t == SUBEXPRESSION ) {
2928 while ( t+t[1] < u && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2931 if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2938 if ( *r == SUBEXPRESSION ) {
2940 l1 = (WORD)(cbuf[r[4]].CanCommu[r[2]]);
2942 if ( *t == SUBEXPRESSION &&
2943 t[1] == r[1] && t[2] == r[2] && t[4] == r[4] ) {
2944 i = t[1] - SUBEXPSIZE;
2945 u = r + SUBEXPSIZE; v = t + SUBEXPSIZE;
2947 if ( *v++ != *u++ )
break; i--; }
2952 while ( r < m ) *t++ = *r++;
2957 if ( l1 && cbuf[t[4]].CanCommu[t[2]] )
break;
2958 while ( t+t[1] < m && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2961 if ( *t == SUBEXPRESSION && cbuf[t[4]].CanCommu[t[2]] )
2963 if ( *t >= FUNCTION+WILDOFFSET )
2964 ipp = *t - WILDOFFSET;
2967 && functions[ipp-FUNCTION].commute && l1 )
break;
2968 if ( *t == EXPRESSION )
break;
2981 l2 = ( l2 >= 0 ) ? i: -i;
2983 while ( --i > 0 ) *m++ = *r++;
2985 *termout = WORDDIF(m,termout);
2986 AT.WorkPointer = coef;
2991 AT.WorkPointer = coef;
2995 MLOCK(ErrorMessageLock);
2996 MesCall(
"FiniTerm");
2997 MUNLOCK(ErrorMessageLock);
3006 static WORD zeroDollar[] = { 0, 0 };
3037 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3038 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, retnorm, extractbuff;
3039 int *RepSto = AN.RepPoint, iscopy = 0;
3040 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3041 LONG posisub, oldcpointer, oldacpointer;
3043 WORD numfac[5], idfunctionflag;
3045 int nummodopt, dtype = -1, id;
3047 oldtoprhs = CC->numrhs;
3048 oldcpointer = CC->Pointer - CC->Buffer;
3049 oldatoprhs = CCC->numrhs;
3050 oldacpointer = CCC->Pointer - CCC->Buffer;
3052 if ( ( replac =
TestSub(BHEAD term,level) ) == 0 ) {
3053 if ( applyflag ) { TableReset(); applyflag = 0; }
3062 AN.PolyNormFlag = 0;
3063 AN.idfunctionflag = 0;
3064 if ( ( retnorm = Normalize(BHEAD term) ) != 0 ) {
3065 if ( retnorm > 0 ) {
3066 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3071 idfunctionflag = AN.idfunctionflag;
3072 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3074 if ( AN.PolyNormFlag ) {
3075 if ( AN.PolyFunTodo == 0 ) {
3076 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3077 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3080 WORD oldPolyFunExp = AR.PolyFunExp;
3082 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3083 AT.WorkPointer = term+*term;
3084 AR.PolyFunExp = oldPolyFunExp;
3085 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3086 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3087 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3088 AT.WorkPointer = term+*term;
3089 if ( AN.PolyNormFlag ) {
3090 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3091 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3092 AT.WorkPointer = term+*term;
3097 if ( idfunctionflag > 0 ) {
3098 if ( TakeIDfunction(BHEAD term) ) {
3099 AT.WorkPointer = term + *term;
3103 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3104 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3107 if ( level > AR.Cnumlhs ) {
3108 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3110 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3115 if (
Deferred(BHEAD term,level) )
goto GenCall;
3118 if ( AN.ncmod != 0 ) {
3119 if ( Modulus(term) )
goto GenCall;
3120 if ( !*term )
goto Return0;
3122 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3123 WORD olddummies = AN.IndDum;
3124 AN.IndDum = AM.IndDum;
3125 ReNumber(BHEAD term); Normalize(BHEAD term);
3126 AN.IndDum = olddummies;
3127 if ( !*term )
goto Return0;
3128 olddummies = DetCurDum(BHEAD term);
3129 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3131 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3132 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3134 else if ( AR.PolyFun > 0 ) {
3135 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3137 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3138 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3139 termout = AT.WorkPointer;
3140 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3141 if ( PutBracket(BHEAD term) )
return(-1);
3142 AN.RepPoint = RepSto;
3143 *AT.WorkPointer = 0;
3145 AT.WorkPointer = termout;
3146 CC->numrhs = oldtoprhs;
3147 CC->Pointer = CC->Buffer + oldcpointer;
3148 CCC->numrhs = oldatoprhs;
3149 CCC->Pointer = CCC->Buffer + oldacpointer;
3153 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3154 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3155 *AT.WorkPointer = 0;
3156 AN.RepPoint = RepSto;
3158 CC->numrhs = oldtoprhs;
3159 CC->Pointer = CC->Buffer + oldcpointer;
3160 CCC->numrhs = oldatoprhs;
3161 CCC->Pointer = CCC->Buffer + oldacpointer;
3165 i = C->
lhs[level][0];
3166 if ( i >= TYPECOUNT ) {
3172 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3173 AT.WorkPointer = term + *term;
3178 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3181 level = AC.Labels[C->
lhs[level][2]];
3184 AT.WorkPointer = term + *term;
3194 WORD ic, jc, *ifcode, *jfcode;
3195 jfcode = C->
lhs[level]; jc = jfcode[1];
3196 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3197 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3198 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3199 level = C->
lhs[level][2];
3200 if ( C->
lhs[level][0] != TYPEELIF )
break;
3202 AT.WorkPointer = ifcode;
3205 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3206 level = C->
lhs[level][2];
3207 if ( C->
lhs[level][0] != TYPEELIF )
break;
3213 level = C->
lhs[level][2];
3214 }
while ( C->
lhs[level][0] == TYPEELIF );
3218 level = C->
lhs[level][2];
3222 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3223 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3224 WORD theindex = C->
lhs[level][2];
3225 if ( theindex < 0 ) {
3228 theindex = -theindex;
3229 d = Dollars + theindex;
3230 if ( AS.MultiThreaded ) {
3231 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3232 if ( theindex == ModOptdollars[nummodopt].number )
break;
3234 if ( nummodopt < NumModOptdollars ) {
3235 ddtype = ModOptdollars[nummodopt].type;
3236 if ( ddtype == MODLOCAL ) {
3237 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3240 LOCK(d->pthreadslockread);
3245 theindex = -theindex;
3246 d = Dollars + theindex;
3249 if ( d->type != DOLINDEX
3250 || d->index < AM.OffsetIndex
3251 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3252 MLOCK(ErrorMessageLock);
3253 MesPrint(
"$%s should have been an index" 3254 ,AC.dollarnames->namebuffer+d->name);
3255 AN.currentTerm = term;
3256 MesPrint(
"Current term: %t");
3257 AN.listinprint = printscratch;
3258 printscratch[0] = DOLLAREXPRESSION;
3259 printscratch[1] = theindex;
3261 ,AC.dollarnames->namebuffer+d->name);
3262 MUNLOCK(ErrorMessageLock);
3264 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3268 theindex = d->index;
3270 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3273 cp[1] = SUBEXPSIZE+4;
3278 i = C->
lhs[level][1] - 3;
3280 AR.CompressPointer = cp;
3281 while ( --i >= 0 ) {
3283 termout = AT.WorkPointer;
3284 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3288 while ( --jlhs >= 0 ) {
3289 if ( *m++ != *termout++ )
break;
3292 termout = AT.WorkPointer;
3293 AT.WorkPointer = termout + *termout;
3294 if (
Generator(BHEAD termout,level) )
goto GenCall;
3295 AT.WorkPointer = termout;
3298 AR.CompressPointer = op;
3302 AR.CompressPointer = op;
3307 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3313 AR.CurDum = DetCurDum(BHEAD term);
3314 i = C->
lhs[level][1]-2;
3315 wp = C->
lhs[level] + 2;
3316 cp[1] = SUBEXPSIZE+4*i;
3318 while ( --i >= 0 ) {
3320 if ( theindex < 0 ) {
3323 theindex = -theindex;
3324 d = Dollars + theindex;
3325 if ( AS.MultiThreaded ) {
3326 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3327 if ( theindex == ModOptdollars[nummodopt].number )
break;
3329 if ( nummodopt < NumModOptdollars ) {
3330 ddtype = ModOptdollars[nummodopt].type;
3331 if ( ddtype == MODLOCAL ) {
3332 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3335 LOCK(d->pthreadslockread);
3340 theindex = -theindex;
3341 d = Dollars + theindex;
3343 if ( d->type != DOLINDEX
3344 || d->index < AM.OffsetIndex
3345 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3346 MLOCK(ErrorMessageLock);
3347 MesPrint(
"$%s should have been an index" 3348 ,AC.dollarnames->namebuffer+d->name);
3349 AN.currentTerm = term;
3350 MesPrint(
"Current term: %t");
3351 AN.listinprint = printscratch;
3352 printscratch[0] = DOLLAREXPRESSION;
3353 printscratch[1] = theindex;
3355 ,AC.dollarnames->namebuffer+d->name);
3356 MUNLOCK(ErrorMessageLock);
3358 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3362 theindex = d->index;
3364 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3370 *cp++ = ++AR.CurDum;
3372 ow = AT.WorkPointer;
3373 AR.CompressPointer = cp;
3374 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3375 AR.CompressPointer = op;
3377 for ( j = 0; j < i; j++ ) term[j] = ow[j];
3378 AT.WorkPointer = ow;
3379 ReNumber(BHEAD term);
3383 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3385 AT.WorkPointer = term + *term;
3388 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3389 level = C->
lhs[level][2];
3390 if ( i > 0 )
goto ReStart;
3398 case TYPESPLITFIRSTARG:
3399 case TYPESPLITLASTARG:
3400 case TYPEARGTOEXTRASYMBOL:
3401 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3402 level = C->
lhs[level][2];
3407 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3408 if ( jjj > 0 )
goto ReStart;
3409 level = C->
lhs[level][2];
3412 if ( C->
lhs[level][2] > 0 ) {
3413 MLOCK(ErrorMessageLock);
3414 MesPrint(
"%s",C->
lhs[level]+3);
3415 MUNLOCK(ErrorMessageLock);
3423 AN.currentTerm = term;
3424 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][2] - 3)/2;
3425 AN.listinprint = C->
lhs[level]+3+C->
lhs[level][2];
3426 MLOCK(ErrorMessageLock);
3428 MesPrint((
char *)(C->
lhs[level]+3));
3430 MUNLOCK(ErrorMessageLock);
3436 MLOCK(ErrorMessageLock);
3437 oldFOflag = AM.FileOnlyFlag;
3438 oldPrintType = AO.PrintType;
3439 if ( AC.LogHandle >= 0 ) {
3440 AM.FileOnlyFlag = 1;
3441 AO.PrintType |= PRINTLFILE;
3443 AN.currentTerm = term;
3444 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][2] - 3)/2;
3445 AN.listinprint = C->
lhs[level]+3+C->
lhs[level][2];
3446 MesPrint((
char *)(C->
lhs[level]+3));
3447 AO.PrintType = oldPrintType;
3448 AM.FileOnlyFlag = oldFOflag;
3449 MUNLOCK(ErrorMessageLock);
3453 j = C->
lhs[level][2];
3463 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3464 if ( AC.pfirstnum[ii] == j )
break;
3466 AC.inputnumbers[ii] = AN.ninterms;
3470 if ( AS.MultiThreaded ) {
3472 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3473 if ( AC.pfirstnum[ii] == j )
break;
3475 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3476 LOCK(AP.PreVarLock);
3477 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3478 a = C->
lhs[level]+4;
3479 if ( a[a[-1]] == 0 )
3480 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3483 ,(UBYTE *)(a+a[-1]+1),1);
3487 AC.inputnumbers[ii] = AN.inputnumber;
3489 UNLOCK(AP.PreVarLock);
3494 a = C->
lhs[level]+4;
3495 LOCK(AP.PreVarLock);
3496 if ( a[a[-1]] == 0 )
3497 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3500 ,(UBYTE *)(a+a[-1]+1),1);
3501 UNLOCK(AP.PreVarLock);
3505 AT.WorkPointer = term + *term;
3506 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3507 AT.WorkPointer = term + *term;
3508 if ( *term == 0 )
goto Return0;
3511 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3512 AT.WorkPointer = term + *term;
3515 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3516 WORD oldrepeat = *AN.RepPoint;
3522 AN.cTerm = AN.currentTerm = term;
3523 AT.WorkPointer = term + *term;
3524 *AT.WorkPointer++ = 0;
3525 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3526 AT.WorkPointer = term + *term;
3528 *AN.RepPoint = oldrepeat;
3529 AR.NoCompress = onc;
3530 AR.Eside = oldEside;
3534 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3535 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3536 AT.WorkPointer = term + *term;
3541 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3542 level = C->
lhs[level][2];
3545 retnorm = execterm(BHEAD term,level);
3546 AN.RepPoint = RepSto;
3548 CC->numrhs = oldtoprhs;
3549 CC->Pointer = CC->Buffer + oldcpointer;
3550 CCC->numrhs = oldatoprhs;
3551 CCC->Pointer = CCC->Buffer + oldacpointer;
3554 AT.WorkPointer = term + *term;
3555 AR.CurDum = DetCurDum(BHEAD term);
3557 case TYPEINEXPRESSION:
3558 {WORD *ll = C->
lhs[level];
3559 int numexprs = (int)(ll[1]-3);
3561 while ( numexprs-- >= 0 ) {
3562 if ( *ll == AR.CurExpr )
break;
3565 if ( numexprs < 0 ) level = C->
lhs[level][2];
3569 AT.WorkPointer = term + *term;
3570 if ( DoShuffle(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3572 AT.WorkPointer = term + *term;
3575 AT.WorkPointer = term + *term;
3576 if ( DoStuffle(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3578 AT.WorkPointer = term + *term;
3581 AT.WorkPointer = term + *term;
3582 if ( TestUse(term,level) )
goto GenCall;
3583 AT.WorkPointer = term + *term;
3586 AT.WorkPointer = term + *term;
3587 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3588 AT.WorkPointer = term + *term;
3592 AT.WorkPointer = term + *term;
3602 AT.WorkPointer = term + *term;
3603 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3604 AT.WorkPointer = term + *term;
3607 AT.WorkPointer = term + *term;
3608 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3609 AT.WorkPointer = term + *term;
3612 AT.WorkPointer = term + *term;
3613 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3614 AT.WorkPointer = term + *term;
3616 case TYPEARGIMPLODE:
3617 AT.WorkPointer = term + *term;
3618 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3619 AT.WorkPointer = term + *term;
3621 case TYPEARGEXPLODE:
3622 AT.WorkPointer = term + *term;
3623 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3624 AT.WorkPointer = term + *term;
3626 case TYPEDENOMINATORS:
3627 DenToFunction(term,C->
lhs[level][2]);
3629 case TYPEDROPCOEFFICIENT:
3630 DropCoefficient(BHEAD term);
3633 AT.WorkPointer = term + *term;
3634 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3635 AT.WorkPointer = term + *term;
3636 if ( *term == 0 )
goto Return0;
3638 case TYPETOPOLYNOMIAL:
3639 AT.WorkPointer = term + *term;
3640 termout = AT.WorkPointer;
3641 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3642 if ( *termout == 0 )
goto Return0;
3643 i = termout[0]; t = term; NCOPY(t,termout,i);
3644 AT.WorkPointer = term + *term;
3646 case TYPEFROMPOLYNOMIAL:
3647 AT.WorkPointer = term + *term;
3648 termout = AT.WorkPointer;
3649 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3650 if ( *term == 0 )
goto Return0;
3651 i = termout[0]; t = term; NCOPY(t,termout,i);
3652 AT.WorkPointer = term + *term;
3655 level = TestDoLoop(BHEAD C->
lhs[level],level);
3656 if ( level < 0 )
goto GenCall;
3659 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3660 if ( level < 0 )
goto GenCall;
3662 case TYPEDROPSYMBOLS:
3663 DropSymbols(BHEAD term);
3666 AT.WorkPointer = term + *term;
3667 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3668 AT.WorkPointer = term + *term;
3673 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3675 case TYPETOSPECTATOR:
3676 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3684 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
3685 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3686 if ( i > 0 ) replac =
TestSub(BHEAD term,level);
3688 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
3693 AutoGen: i = *AT.TMout;
3694 t = termout = AT.WorkPointer;
3695 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
3697 while ( --i >= 0 ) *t++ = *accum++;
3698 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
3699 AT.WorkPointer = termout;
3703 if ( applyflag ) { TableReset(); applyflag = 0; }
3707 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
3709 if ( AR.TePos >= 0 )
goto AutoGen;
3710 switch ( AN.TeInFun ) {
3712 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
3715 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
3718 if ( DoTableExpansion(term,level) )
goto GenCall;
3721 if ( FactorIn(BHEAD term,level) )
goto GenCall;
3724 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
3727 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
3730 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
3733 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
3736 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
3739 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
3742 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
3745 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
3748 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
3751 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
3756 termout = AT.WorkPointer;
3757 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3758 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3759 if (
InFunction(BHEAD term,termout) )
goto GenCall;
3760 AT.WorkPointer = termout + *termout;
3763 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3764 AT.WorkPointer = termout;
3767 else if ( replac > 0 ) {
3771 power = -power; tepos = 0;
3773 extractbuff = AT.TMbuff;
3774 if ( extractbuff == AM.dbufnum ) {
3775 d = DolToTerms(BHEAD replac);
3776 if ( d && d->where != 0 ) {
3778 if ( AT.TMdolfac > 0 ) {
3779 if ( AT.TMdolfac == 1 ) {
3780 if ( d->nfactors ) {
3782 numfac[1] = d->nfactors;
3793 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
3794 MLOCK(ErrorMessageLock);
3795 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
3796 if ( d->nfactors == 1 )
3797 MesPrint(
"There is only one factor");
3799 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
3800 MUNLOCK(ErrorMessageLock);
3803 if ( d->nfactors > 1 ) {
3807 dd = Dollars + replac;
3810 int nummodopt, dtype = -1;
3811 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
3812 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3813 if ( replac == ModOptdollars[nummodopt].number )
break;
3815 if ( nummodopt < NumModOptdollars ) {
3816 dtype = ModOptdollars[nummodopt].type;
3817 if ( dtype == MODLOCAL ) {
3818 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
3824 dsize = dd->factors[AT.TMdolfac-2].size;
3830 numfac[1] = d->factors[AT.TMdolfac-2].value;
3835 if ( numfac[1] < 0 ) {
3836 numfac[1] = -numfac[1];
3837 numfac[3] = -numfac[3];
3841 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
3842 (dsize+1)*
sizeof(WORD),
"Copy of factor");
3843 td1 = dd->factors[AT.TMdolfac-2].where;
3845 d->size = dsize; d->type = DOLTERMS;
3846 NCOPY(td2,td1,dsize);
3850 else if ( d->nfactors == 1 ) {
3851 StartBuf = d->where;
3854 MLOCK(ErrorMessageLock);
3855 if ( d->nfactors == 0 ) {
3856 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
3859 MesPrint(
"Internal error. Illegal number of factors for $-variable");
3861 MUNLOCK(ErrorMessageLock);
3866 else StartBuf = d->where;
3869 d = Dollars + replac;
3870 StartBuf = zeroDollar;
3873 i = DetCommu(d->where);
3875 if ( AS.MultiThreaded ) {
3876 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3877 if ( replac == ModOptdollars[nummodopt].number )
break;
3879 if ( nummodopt < NumModOptdollars ) {
3880 dtype = ModOptdollars[nummodopt].type;
3881 if ( dtype != MODLOCAL && dtype != MODSUM ) {
3882 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
3883 MLOCK(ErrorMessageLock);
3884 MesPrint(
"A dollar variable with modoption max or min can have only one term");
3885 MUNLOCK(ErrorMessageLock);
3888 LOCK(d->pthreadslockread);
3895 StartBuf = cbuf[extractbuff].Buffer;
3896 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
3897 i = (WORD)cbuf[extractbuff].CanCommu[replac];
3900 termout = AT.WorkPointer;
3901 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3902 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3903 while ( StartBuf[posisub] ) {
3904 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
3905 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
3906 if (
InsertTerm(BHEAD term,replac,extractbuff,
3907 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
3908 AT.WorkPointer = termout + *termout;
3911 posisub += StartBuf[posisub];
3923 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
3924 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
3925 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3926 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3931 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3933 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
3935 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
3942 StartBuf = cbuf[extractbuff].Buffer;
3945 if ( extractbuff == AT.allbufnum ) {
3946 CBUF *Ce = cbuf + extractbuff;
3950 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
3953 if ( d->nfactors > 1 ) {
3955 for ( j = 0; j < d->nfactors; j++ ) {
3956 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
3958 M_free(d->factors,
"Dollar factors");
3960 M_free(d,
"Copy of dollar variable");
3963 AT.WorkPointer = termout;
3965 else if ( i <= 1 ) {
3967 WORD *same, *ow = AT.WorkPointer;
3968 LONG olpw = AT.posWorkPointer;
3970 WantAddLongs(power1);
3971 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
3972 same = ++AT.WorkPointer;
3973 a = accum = ( AT.WorkPointer += power1+1 );
3974 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3975 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3976 AT.lWorkSpace[posit] = posisub;
3983 if ( StartBuf[AT.lWorkSpace[posit]] ) {
3985 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
3987 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
3988 same[1] = *same + 1;
3989 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
3990 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
3996 i--; posit--; same--;
3999 termout = AT.WorkPointer = a;
4000 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4001 if ( AT.WorkPointer > AT.WorkTop )
4003 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4004 AT.WorkPointer = termout + *termout;
4008 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4009 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4010 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4011 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4015 if (
Generator(BHEAD termout,level) )
goto GenCall;
4017 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4019 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4020 StartBuf = cbuf[extractbuff].Buffer;
4021 i--; posit--; same--;
4025 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4028 if ( d->nfactors > 1 ) {
4030 for ( j = 0; j < d->nfactors; j++ ) {
4031 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4033 M_free(d->factors,
"Dollar factors");
4035 M_free(d,
"Copy of dollar variable");
4038 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4041 LONG posit, olw, olpw = AT.posWorkPointer;
4042 WantAddLongs(power);
4043 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4044 a = accum = AT.WorkPointer;
4045 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4046 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4047 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4053 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4055 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4056 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4060 AT.lWorkSpace[posit--] = posisub;
4064 termout = AT.WorkPointer = a;
4065 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4066 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4067 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4068 AT.WorkPointer = termout + *termout;
4072 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4073 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4074 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4078 if (
Generator(BHEAD termout,level) )
goto GenCall;
4080 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { dtype = 0;
break; }
4082 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4083 StartBuf = cbuf[extractbuff].Buffer;
4088 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4091 if ( d->nfactors > 1 ) {
4093 for ( j = 0; j < d->nfactors; j++ ) {
4094 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4096 M_free(d->factors,
"Dollar factors");
4098 M_free(d,
"Copy of dollar variable");
4101 AT.WorkPointer = accum;
4102 AT.lWorkPointer = olw;
4103 AT.posWorkPointer = olpw;
4108 LONG position, olpw, opw, comprev, extra;
4110 WORD *Freeze, *aa, *dummies;
4114 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4116 SETSTARTPOS(firstpos);
4128 WantAddPointers(power+1);
4129 comprev = opw = AT.pWorkPointer;
4130 AT.pWorkPointer += power+1;
4131 WantAddPositions(power+1);
4132 position = olpw = AT.posWorkPointer;
4133 AT.posWorkPointer += power + 1;
4135 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4137 for ( i = 0; i < power; i++ ) {
4138 PUTZERO(AT.posWorkSpace[position]); position++;
4141 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4142 dummies = AT.WorkPointer;
4143 *dummies++ = AR.CurDum;
4144 AT.WorkPointer += power+2;
4145 accum = AT.WorkPointer;
4146 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4147 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4148 aa = AT.WorkPointer;
4150 i = 0; StartPos = AT.posWorkSpace[position];
4151 dummies[i] = AR.CurDum;
4154 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4155 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4156 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4157 if ( Expressions[replac].numdummies > 0 ) {
4158 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4160 if ( NOTSTARTPOS(firstpos) ) {
4161 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4162 firstpos = AT.posWorkSpace[position];
4173 i++; AT.posWorkSpace[++position] = StartPos;
4174 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4175 dummies[i] = AR.CurDum;
4178 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4179 AR.CurDum = dummies[i];
4183 termout = AT.WorkPointer = a;
4184 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4185 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4186 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4188 AT.WorkPointer = termout + *termout;
4192 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4193 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4198 if (
Generator(BHEAD termout,level) )
goto GenCall;
4201 AR.CurDum = dummies[i];
4204 AT.WorkPointer = aa;
4206 AT.WorkPointer = accum;
4207 AT.posWorkPointer = olpw;
4208 AT.pWorkPointer = opw;
4216 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4217 M_free(renumber->
symb.
lo,
"VarSpace");
4218 M_free(renumber,
"Renumber");
4222 aa = accum = AT.WorkPointer;
4223 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4225 *accum++ = -1; AT.WorkPointer++;
4226 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4227 AT.WorkPointer = aa;
4232 AN.RepPoint = RepSto;
4233 CC->numrhs = oldtoprhs;
4234 CC->Pointer = CC->Buffer + oldcpointer;
4235 CCC->numrhs = oldatoprhs;
4236 CCC->Pointer = CCC->Buffer + oldacpointer;
4240 if ( AM.tracebackflag ) {
4242 MLOCK(ErrorMessageLock);
4243 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4247 while ( --i >= 0 ) {
4248 TalToLine((UWORD)(*termout++));
4249 TokenToLine((UBYTE *)
" ");
4253 MesCall(
"Generator");
4254 MUNLOCK(ErrorMessageLock);
4256 CC->numrhs = oldtoprhs;
4257 CC->Pointer = CC->Buffer + oldcpointer;
4258 CCC->numrhs = oldatoprhs;
4259 CCC->Pointer = CCC->Buffer + oldacpointer;
4262 CC->numrhs = oldtoprhs;
4263 CC->Pointer = CC->Buffer + oldcpointer;
4264 CCC->numrhs = oldatoprhs;
4265 CCC->Pointer = CCC->Buffer + oldacpointer;
4266 MLOCK(ErrorMessageLock);
4268 MUNLOCK(ErrorMessageLock);
4301 char freezestring[] =
"freeze<-xxxx";
4305 WORD *aa, WORD level, WORD *freeze)
4308 POSITION oldposition, startposition;
4309 WORD *acc, *termout, fromfreeze = 0;
4310 WORD *oldipointer = AR.CompressPointer;
4313 WORD oldGetOneFile = AR.GetOneFile;
4314 WORD olddummies = AR.CurDum;
4315 WORD extradummies = Expressions[nexp].numdummies;
4345 type = Expressions[nexp].status;
4346 if ( type == HIDDENLEXPRESSION || type == HIDDENGEXPRESSION
4347 || type == DROPHLEXPRESSION || type == DROPHGEXPRESSION
4348 || type == UNHIDELEXPRESSION || type == UNHIDEGEXPRESSION ) {
4349 AR.GetOneFile = 2; fi = AR.hidefile;
4352 AR.GetOneFile = 0; fi = AR.infile;
4355 PUTZERO(oldposition);
4357 LOCK(AS.inputslock);
4358 SeekFile(fi->
handle,&oldposition,SEEK_CUR);
4359 UNLOCK(AS.inputslock);
4363 SETBASEPOSITION(oldposition,fi->POfill-fi->PObuffer);
4365 if ( freeze && ( Expressions[nexp].bracketinfo != 0 ) ) {
4373 if ( ( brapos = FindBracket(nexp,freeze) ) == 0 )
4375 startposition = *brapos;
4378 startposition = AS.OldOnFile[nexp];
4379 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4384 AR.CompressPointer = oldipointer;
4386 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4387 if ( retval <= 0 )
break;
4392 WORD *t, *m, *r, *mstop;
4405 while ( t < r && *t != HAAKJE ) t += t[1];
4408 if ( fromfreeze )
goto EndExpr;
4415 while ( r < t && m < mstop ) {
4416 if ( *r == *m ) { m++; r++; }
4418 if ( fromfreeze )
goto EndExpr;
4422 if ( r < t || m < mstop ) {
4423 if ( fromfreeze )
goto EndExpr;
4431 while ( t < m ) *r++ = *t++;
4432 *accum = WORDDIF(r,accum);
4434 if ( extradummies > 0 ) {
4435 if ( olddummies > AM.IndDum ) {
4436 MoveDummies(BHEAD accum,olddummies-AM.IndDum);
4438 AR.CurDum = olddummies+extradummies;
4444 AT.WorkPointer = (WORD *)(((UBYTE *)(acc)) + 2*AM.MaxTer);
4445 if ( AT.WorkPointer > AT.WorkTop ) {
4446 MLOCK(ErrorMessageLock);
4448 MUNLOCK(ErrorMessageLock);
4451 if (
FiniTerm(BHEAD term,aa,termout,nexp,0) )
goto PowCall;
4453 MarkPolyRatFunDirty(termout)
4455 AT.WorkPointer = termout + *termout;
4458 if (
Generator(BHEAD termout,level) )
goto PowCall;
4462 if ( acc > AT.WorkTop ) {
4463 MLOCK(ErrorMessageLock);
4465 MUNLOCK(ErrorMessageLock);
4468 if (
DoOnePow(BHEAD term,power,nexp,acc,aa,level,freeze) )
goto PowCall;
4471 AR.CompressPointer = oldipointer;
4476 AR.CompressPointer = oldipointer;
4479 LOCK(AS.inputslock);
4480 SeekFile(fi->
handle,&oldposition,SEEK_SET);
4481 UNLOCK(AS.inputslock);
4482 if ( ISNEGPOS(oldposition) ) {
4483 MLOCK(ErrorMessageLock);
4484 MesPrint(
"File error");
4490 fi->POfill = fi->PObuffer + BASEPOSITION(oldposition);
4492 AR.GetOneFile = oldGetOneFile;
4493 AR.CurDum = olddummies;
4496 MLOCK(ErrorMessageLock);
4500 MesCall(
"DoOnePow");
4501 MUNLOCK(ErrorMessageLock);
4529 WORD *t, *m, *mstop, *tstart, decr, oldb, *termout, i, *oldwork, retval;
4530 WORD *oldipointer = AR.CompressPointer, *oldPOfill = AR.infile->POfill;
4531 WORD oldGetOneFile = AR.GetOneFile;
4533 oldwork = AT.WorkPointer;
4534 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4535 termout = AT.WorkPointer;
4537 startposition = AR.DefPosition;
4541 if ( AR.infile->handle >= 0 ) {
4551 AR.infile->POfill = (WORD *)((UBYTE *)(AR.infile->PObuffer)
4552 +BASEPOSITION(startposition));
4557 t = m = AR.CompressBuffer;
4559 mstop = t - ABS(t[-1]);
4561 while ( *m != HAAKJE && m < mstop ) m += m[1];
4563 AT.WorkPointer = term + *term;
4564 if (
Generator(BHEAD term,level) )
goto DefCall;
4566 AT.WorkPointer = oldwork;
4567 AR.GetOneFile = oldGetOneFile;
4571 decr = WORDDIF(mstop,AR.CompressBuffer)-1;
4572 tstart = AR.CompressPointer + decr;
4574 m = AR.CompressBuffer;
4575 t = AR.CompressPointer;
4589 *tstart = *(AR.CompressPointer)-decr;
4590 AR.CompressPointer = AR.CompressPointer+AR.CompressPointer[0];
4591 if (
InsertTerm(BHEAD term,0,AM.rbufnum,tstart,termout,0) < 0 ) {
4595 AT.WorkPointer = termout + *termout;
4596 if (
Generator(BHEAD termout,level) )
goto DefCall;
4597 AR.CompressPointer = oldipointer;
4598 AT.WorkPointer = termout;
4599 retval = GetOneTerm(BHEAD AT.WorkPointer,AR.infile,&startposition,0);
4600 if ( retval >= 0 ) AR.CompressPointer = oldipointer;
4601 if ( retval <= 0 )
break;
4602 t = AR.CompressPointer;
4603 if ( *t < (1 + decr + ABS(*(t+*t-1))) )
break;
4605 m = AR.CompressBuffer+1;
4606 while ( m < mstop ) {
4607 if ( *m != *t )
goto Thatsit;
4615 if ( AR.infile->handle < 0 ) AR.infile->POfill = oldPOfill;
4617 AR.GetOneFile = oldGetOneFile;
4618 AT.WorkPointer = oldwork;
4621 MLOCK(ErrorMessageLock);
4622 MesCall(
"Deferred");
4623 MUNLOCK(ErrorMessageLock);
4656 WORD count = 0, i, jcoef, ncoef;
4657 WORD *t, *m, *r, *tstop, *
poly = 0, *v, *w, *vv, *ww;
4658 WORD *oldworkpointer = AT.WorkPointer;
4666 if ( AR.PolyFunType == 2 && AR.PolyFunExp != 2 ) {
4667 WORD oldtype = AR.SortType;
4668 AR.SortType = SORTHIGHFIRST;
4669 if ( poly_ratfun_normalize(BHEAD term) != 0 ) Terminate(-1);
4671 oldworkpointer = AT.WorkPointer;
4672 AR.SortType = oldtype;
4678 while ( t < tstop ) {
4679 if ( *t == AR.PolyFun ) {
4680 if ( count > 0 )
return(0);
4686 r = m = term + *term;
4689 if ( count == 0 )
return(0);
4690 else if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) )
4692 else if ( AR.PolyFunType == 2 )
4697 else if ( count == 0 ) {
4702 if ( i == 3 && m[-2] == 1 && (m[-3]&MAXPOSITIVE) == m[-3] ) {
4704 if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4708 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4711 else if ( AR.PolyFunType == 2 ) {
4715 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4723 if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4725 *m++ = FUNHEAD+ARGHEAD+i+1;
4733 else if ( AR.PolyFunType == 2 ) {
4734 WORD *num, *den, size, sign, sizenum, sizeden;
4735 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
4736 else { sign = 1; size = m[-1]; }
4737 num = m - size; size = (size-1)/2; den = num + size;
4738 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
4739 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
4741 AT.PolyAct = WORDDIF(v,term);
4743 *v++ = FUNHEAD + 2*(ARGHEAD+sizenum+sizeden+2);
4745 *v++ = ARGHEAD+2*sizenum+2;
4749 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
4751 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
4752 *v++ = sign*(2*sizenum+1);
4753 *v++ = ARGHEAD+2*sizeden+2;
4757 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
4759 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
4764 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
4772 else if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4779 if ( (
poly[1] == FUNHEAD+2 &&
poly[FUNHEAD+1] == 0
4780 &&
poly[FUNHEAD] == -SNUMBER ) ||
poly[1] == FUNHEAD )
return(1);
4782 if ( t >= r )
return(0);
4783 if ( m[-1] == 3 && *tstop == 1 && tstop[1] == 1 ) {
4788 else if ( *t <= -FUNCTION ) {
4789 if ( t+1 < r )
return(0);
4792 *m++ = FUNHEAD*2+ARGHEAD+i+1;
4794 *m++ = FUNHEAD+ARGHEAD+i+1;
4803 else if ( *t < 0 ) {
4804 if ( t+2 < r )
return(0);
4806 if ( *t == -SNUMBER ) {
4807 if ( t[1] == 0 )
return(1);
4810 m += FUNHEAD+ARGHEAD;
4818 if ( m >= AT.WorkSpace && m < AT.WorkTop )
4820 if ( Normalize(BHEAD v) ) Terminate(-1);
4821 AT.WorkPointer = oldworkpointer;
4823 if ( *v == 4 && v[2] == 1 && (v[1]&MAXPOSITIVE) == v[1] ) {
4827 *m++ = v[3] < 0 ? -v[1] : v[1];
4829 else if ( *v == 0 )
return(1);
4831 *m++ = FUNHEAD+ARGHEAD+*v;
4839 else if ( *t == -SYMBOL ) {
4841 *m++ = FUNHEAD+ARGHEAD+5+i;
4856 if ( t + *t < r )
return(0);
4860 m += ARGHEAD+FUNHEAD-1;
4862 jcoef = i < 0 ? (i+1)>>1:(i-1)>>1;
4871 vstop = vv - ABS(vv[-1]);
4873 while( t < vstop ) {
4874 if ( *t == INDEX )
return(0);
4887 vv = v - ABS(ncoef);
4888 if ( ncoef < 0 ) ncoef++;
4891 while ( t < vv ) *m++ = *t++;
4892 if ( MulRat(BHEAD (UWORD *)vv,ncoef,(UWORD *)tstop,jcoef,
4893 (UWORD *)m,&ncoef) ) Terminate(-1);
4896 if ( ncoef < 0 ) ncoef--;
4899 *ww = WORDDIF(m,ww);
4900 if ( AN.ncmod != 0 ) {
4901 if ( Modulus(ww) ) Terminate(-1);
4902 if ( *ww == 0 )
return(1);
4907 *w = (WORDDIF(m,w))+1;
4908 w[FUNHEAD-1] = w[0] - FUNHEAD;
4912 if ( ToFast(w,w) ) {
4913 if ( *w <= -FUNCTION ) { w[-FUNHEAD+1] = FUNHEAD+1; m = w+1; }
4914 else { w[-FUNHEAD+1] = FUNHEAD+2; m = w+2; }
4919 while ( t < tstop ) *
poly++ = *t++;
4924 else if ( AR.PolyFunType == 2 ) {
4929 WORD *num, *den, size, sign, sizenum, sizeden;
4935 for ( i = 0; i <
poly[1]; i++ ) m[i] =
poly[i];
4937 while ( v < tstop ) *t++ = *v++;
4939 for ( i = 0; i < m[1]; i++ ) t[i] = m[i];
4942 AT.PolyAct = WORDDIF(
poly,term);
4947 if ( m[-1] == 3 && m[-2] == 1 && m[-3] == 1 )
return(0);
4948 if ( AR.PolyFunExp != 1 ) {
4949 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
else { sign = 1; size = m[-1]; }
4950 num = m - size; size = (size-1)/2; den = num + size;
4951 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
4952 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
4955 *v++ = FUNHEAD + 2*(ARGHEAD+sizenum+sizeden+2);
4959 *v++ = ARGHEAD+2*sizenum+2;
4963 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
4965 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
4966 *v++ = sign*(2*sizenum+1);
4967 *v++ = ARGHEAD+2*sizeden+2;
4971 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
4973 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
4982 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
4984 WORD oldtype = AR.SortType;
4985 AR.SortType = SORTHIGHFIRST;
4992 poly_ratfun_normalize(BHEAD term);
4995 AR.SortType = oldtype;
5004 MLOCK(ErrorMessageLock);
5005 MesPrint(
"Illegal value for PolyFunType in PrepPoly");
5006 MUNLOCK(ErrorMessageLock);
5010 AT.PolyAct = WORDDIF(
poly,term);
5011 while ( r < m ) *
poly++ = *r++;
5015 *term = WORDDIF(
poly,term);
5038 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5039 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5040 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0, retval = 0;
5041 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5043 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5046 if ( *t != AR.PolyFun ) {
5048 if ( t == w ) { t += t[1]; w = t; }
5049 else { i = t[1]; NCOPY(w,t,i) }
5053 t2 = t + t[1]; t += FUNHEAD;
5055 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5056 else if ( *t != -SNUMBER )
goto NoLegal;
5059 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5060 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5061 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5062 pow1 += t[ARGHEAD+4];
5067 MLOCK(ErrorMessageLock);
5068 MesPrint(
"Illegal term with divergence in PolyRatFun");
5069 MesCall(
"PolyFunMul");
5070 MUNLOCK(ErrorMessageLock);
5074 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5075 else if ( *t != -SNUMBER )
goto NoLegal;
5078 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5079 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5080 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5081 pow1 -= t[ARGHEAD+4];
5085 if ( t == t2 ) pow += pow1;
5089 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5091 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5092 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5093 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5095 else if ( pow == 1 ) {
5096 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5098 else if ( pow < -1 ) {
5099 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5100 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5101 *w++ = 1; *w++ = 1; *w++ = 3;
5103 else if ( pow == -1 ) {
5104 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5107 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5110 *w++ = 1; *w++ = 1; *w++ = 3;
5112 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5116 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5117 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5118 WORD count1 = 0, count2 = 0, count3;
5119 WORD oldtype = AR.SortType;
5120 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5122 if ( *t == AR.PolyFun ) {
5123 if ( t[2] && dirty == 0 ) {
5127 poly_ratfun_normalize(BHEAD term);
5128 if ( term[0] == 0 )
return(0);
5133 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5134 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5135 if ( count3 == 2 ) {
5137 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5140 AR.SortType = SORTHIGHFIRST;
5141 t2 = t + t[1]; tt2 = t+FUNHEAD;
5142 while ( tt2 < t2 ) {
5144 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5146 while ( tt1 < tt2 ) {
5147 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5148 AT.WorkPointer = ww;
5153 ww = w;
while ( *ww ) ww += *ww;
5154 if ( ww-w != *tt4-ARGHEAD ) {
5159 WORD *r1 = TermMalloc(
"PolyFunMul");
5160 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5161 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5162 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5163 i = ww-w; ww = w; NCOPY(r4,ww,i);
5164 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5165 *r1 = i = r4-r1; r4 = term; r3 = r1;
5167 t[1] += ii; t1 += ii; *tt4 += ii;
5169 TermFree(r1,
"PolyFunMul");
5172 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5177 else if ( *tt2 <= -FUNCTION ) tt2++;
5180 AR.SortType = oldtype;
5186 if ( count1 <= 1 ) {
goto checkaction; }
5187 if ( AR.PolyFunExp == 1 ) {
5188 t = term + *term; t -= ABS(t[-1]);
5189 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5192 AR.SortType = SORTHIGHFIRST;
5195 retval = poly_ratfun_normalize(BHEAD term);
5196 if ( *term == 0 )
return(retval);
5197 AR.SortType = oldtype;
5200 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5202 if ( *t == AR.PolyFun ) {
5203 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5204 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5205 if ( count3 == 2 ) {
5211 if ( count1 >= count2 ) {
5214 if ( *t == AR.PolyFun ) {
5217 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5220 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5229 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5231 if ( action ) retval = action;
5235 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5236 AT.WorkPointer = term + *term;
5237 GETSTOP(term,tstop);
5239 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5240 while ( t < tstop && *t == AR.PolyFun ) {
5241 if ( t[1] > FUNHEAD ) {
5242 if ( t[FUNHEAD] < 0 ) {
5243 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5244 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5245 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5252 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5257 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5260 while ( t < tstop && *t == AR.PolyFun ) {
5261 if ( t[1] > FUNHEAD ) {
5262 if ( t[FUNHEAD] < 0 ) {
5263 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5264 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5265 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5272 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5277 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5285 n1 = 1; arg1 = AT.WorkPointer;
5286 ToGeneral(t,arg1,1);
5287 AT.WorkPointer = arg1 + *arg1;
5291 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5292 while ( t < t1 ) { n1++; t += *t; }
5296 n2 = 1; arg2 = AT.WorkPointer;
5297 ToGeneral(t,arg2,1);
5298 AT.WorkPointer = arg2 + *arg2;
5302 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5303 while ( t < t2 ) { n2++; t += *t; }
5315 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5322 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5324 if ( minp1 > 0 ) minp1 = 0;
5326 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5327 if ( minp1 > 0 ) minp1 = 0;
5330 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5331 if ( t1[4] < minp1 ) minp1 = t1[4];
5334 MesPrint(
"Illegal term in expanded polyratfun.");
5340 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5342 if ( minp2 > 0 ) minp2 = 0;
5344 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5345 if ( minp2 > 0 ) minp2 = 0;
5348 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5349 if ( t2[4] < minp2 ) minp2 = t2[4];
5352 MesPrint(
"Illegal term in expanded polyratfun.");
5357 AR.PolyFunPow += minp1+minp2;
5359 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5360 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5365 while ( t < tt1 ) *m++ = *t++;
5368 while ( t < tt2 ) *m++ = *t++;
5369 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5374 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5375 l3 = REDLENG(m[-1]);
5379 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5381 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5383 if ( l4 == 0 )
continue;
5386 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5388 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5397 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5399 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5402 if ( l3 == 0 )
continue;
5412 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5413 AR.PolyFunPow = OldPolyFunPow;
5420 while ( *t ) t += *t;
5424 while ( t1 < fun1 ) *t++ = *t1++;
5427 *t++ = FUNHEAD+ARGHEAD+n1;
5434 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5435 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5436 else t2[FUNHEAD] = FUNHEAD+1;
5439 t1 = fun1 + fun1[1];
5440 while ( t1 < fun2 ) *t++ = *t1++;
5441 t1 = fun2 + fun2[1];
5443 while ( t1 < t2 ) *t++ = *t1++;
5444 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5445 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5446 MLOCK(ErrorMessageLock);
5447 MesPrint(
"Term too complex. Maybe increasing MaxTermSize can help");
5450 m = term; t = AT.WorkPointer;
5455 AT.WorkPointer = term + *term;
5456 if ( action && noac ) {
5457 if ( Normalize(BHEAD term) )
goto PolyCall;
5458 AT.WorkPointer = term + *term;
5462 MLOCK(ErrorMessageLock);
5464 AR.PolyFunPow = OldPolyFunPow;
5465 MesCall(
"PolyFunMul");
5466 MUNLOCK(ErrorMessageLock);
WORD PrepPoly(PHEAD WORD *term, WORD par)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
int SymbolNormalize(WORD *)
WORD PF_Deferred(WORD *term, WORD level)
int PF_InParallelProcessor(void)
WORD FiniTerm(PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos)
WORD InFunction(PHEAD WORD *term, WORD *termout)
WORD TestSub(PHEAD WORD *term, WORD level)
WORD StoreTerm(PHEAD WORD *)
LONG PasteFile(PHEAD WORD number, WORD *accum, POSITION *position, WORD **accfill, RENUMBER renumber, WORD *freeze, WORD nexpr)
WORD TestMatch(PHEAD WORD *, WORD *)
WORD * PasteTerm(PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby)
WORD Compare1(PHEAD WORD *, WORD *, WORD)
WORD InsertTerm(PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout, WORD tepos)
WORD Deferred(PHEAD WORD *term, WORD level)
WORD PutOut(PHEAD WORD *, POSITION *, FILEHANDLE *, WORD)
WORD PolyFunMul(PHEAD WORD *term)
int CompareSymbols(PHEAD WORD *, WORD *, WORD)
WORD FlushOut(POSITION *, FILEHANDLE *, int)
WORD DoOnePow(PHEAD WORD *term, WORD power, WORD nexp, WORD *accum, WORD *aa, WORD level, WORD *freeze)
int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression)
LONG EndSort(PHEAD WORD *, int)
int PF_BroadcastRHS(void)
WORD Generator(PHEAD WORD *term, WORD level)