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 ) {
443 poly_factorize_expression(e);
445 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
446 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
447 poly_unfactorize_expression(e);
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 ) {
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 ) {
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 ) {
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;
1066 Important: 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 ) {
1545 while ( r < m ) *t++ = *r++;
1550 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 )
1551 t1[2] |= MUSTCLEANPRF;
1556 AN.ncmod = oldncmod;
1569 if ( *t == 0 ) { retvalue = 1;
goto redosize; }
1571 WORD *tend = t + *t, *tt = t+1;
1573 tend -= ABS(tend[-1]);
1574 while ( tt < tend ) {
1575 if ( *tt == SUBEXPRESSION ) {
1576 stilldirty = 1;
break;
1589 while ( r < m ) *t++ = *r++;
1591 t = AT.NestPoin[-1].argsize + ARGHEAD;
1604 t = AT.NestPoin->argsize;
1608 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1610 AR.SortType = SORTHIGHFIRST;
1612 if ( AT.WorkPointer < term + *term )
1613 AT.WorkPointer = term + *term;
1615 while ( t < AT.NestPoin->argsize+*(AT.NestPoin->argsize) ) {
1618 do { *m++ = *t++; }
while ( t < r );
1620 AT.WorkPointer = r + *r;
1621 if ( Normalize(BHEAD r) ) {
1622 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1623 AR.SortType = oldsorttype;
1624 AR.CompareRoutine = oldcompareroutine;
1625 t1[2] |= MUSTCLEANPRF;
1629 if ( AN.ncmod != 0 ) {
1634 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1635 AR.SortType = oldsorttype;
1636 AR.CompareRoutine = oldcompareroutine;
1637 t1[2] |= MUSTCLEANPRF;
1643 if ( AR.PolyFun > 0 ) {
1644 if (
PrepPoly(BHEAD r,1) != 0 )
goto EndTest;
1650 if (
EndSort(BHEAD AT.WorkPointer+ARGHEAD,1) < 0 )
goto EndTest;
1651 m = AT.WorkPointer+ARGHEAD;
1652 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1653 AR.SortType = oldsorttype;
1654 AR.CompareRoutine = oldcompareroutine;
1655 t1[2] |= MUSTCLEANPRF;
1657 while ( *m ) m += *m;
1658 i = WORDDIF(m,AT.WorkPointer);
1659 *AT.WorkPointer = i;
1660 AT.WorkPointer[1] = stilldirty;
1661 if ( ToFast(AT.WorkPointer,AT.WorkPointer) ) {
1663 if ( *m <= -FUNCTION ) { m++; i = 1; }
1664 else { m += 2; i = 2; }
1669 if ( r > AT.WorkTop ) {
1670 MLOCK(ErrorMessageLock);
1674 do { *--r = *--m; }
while ( m > AT.WorkPointer );
1678 stop = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1679 do { *--r = *--m; }
while ( m >= stop );
1682 m = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1684 do { *r++ = *m++; }
while ( m < AN.EndNest );
1686 m = AT.NestPoin->argsize;
1688 while ( --i >= 0 ) *m++ = *r++;
1690 while ( n <= AT.NestPoin ) {
1691 if ( *(n->argsize) > 0 && n != AT.NestPoin )
1694 *(n->termsize) += j;
1699 if ( funnum == DENOMINATOR || funnum == EXPONENT ) {
1700 if ( Normalize(BHEAD term) ) {
1710 AN.ncmod = oldncmod;
1717 AN.ncmod = oldncmod;
1720 else if ( *t == -DOLLAREXPRESSION ) {
1721 if ( ( *t1 == TERMSINEXPR || *t1 == SIZEOFFUNCTION )
1722 && t1[1] == FUNHEAD+2 ) {}
1724 if ( AR.Eside != LHSIDE ) {
1725 AN.TeInFun = 1; AR.TePos = 0;
1726 AT.TMbuff = AM.dbufnum; t1[2] |= DIRTYFLAG;
1727 AN.ncmod = oldncmod;
1730 AC.lhdollarflag = 1;
1733 else if ( *t == -TERMSINBRACKET ) {
1734 if ( AR.Eside != LHSIDE ) {
1735 AN.TeInFun = 1; AR.TePos = 0;
1737 AN.ncmod = oldncmod;
1741 else if ( AN.ncmod != 0 && *t == -SNUMBER ) {
1742 if ( AN.ncmod == 1 || AN.ncmod == -1 ) {
1743 isp = (UWORD)(AC.cmod[0]);
1745 if ( ( AC.modmode & POSNEG ) != 0 ) {
1746 if ( isp > (UWORD)(AC.cmod[0])/2 ) isp = isp - (UWORD)(AC.cmod[0]);
1747 else if ( -isp > (UWORD)(AC.cmod[0])/2 ) isp = isp + (UWORD)(AC.cmod[0]);
1750 if ( isp < 0 ) isp += (UWORD)(AC.cmod[0]);
1752 if ( isp <= MAXPOSITIVE && isp >= -MAXPOSITIVE ) {
1759 if ( funnum >= FUNCTION && functions[funnum-FUNCTION].tabl ) {
1765 WORD rhsnumber, *oldwork = AT.WorkPointer, *Tpattern;
1768 T = functions[funnum-FUNCTION].tabl;
1778 Tpattern = T->
pattern[AT.identity];
1782 p = Tpattern + FUNHEAD+1;
1787 if ( T->
numind == 0 ) { isp = 0; }
1789 for ( i = 0; i < T->
numind; i++, t += 2 ) {
1790 if ( *t != -SNUMBER )
break;
1792 if ( i < T->numind )
goto teststrict;
1794 isp = FindTableTree(T,t1+FUNHEAD,2);
1797 teststrict:
if ( T->
strict == -2 ) {
1798 rhsnumber = AM.zerorhs;
1799 tbufnum = AM.zbufnum;
1801 else if ( T->
strict == -3 ) {
1802 rhsnumber = AM.onerhs;
1803 tbufnum = AM.zbufnum;
1805 else if ( T->
strict < 0 )
goto NextFun;
1807 MLOCK(ErrorMessageLock);
1808 MesPrint(
"Element in table is undefined");
1815 for ( i = 0; i < T->
numind; i++ ) {
1816 *p = *t; p+=2; t+=2;
1821 #if ( TABLEEXTENSION == 2 )
1828 while ( --ii >= 0 ) {
1829 *p = *t; t += 2; p += 2;
1838 while ( --j >= 0 ) {
1839 if ( *t != -SNUMBER )
goto NextFun;
1841 if ( *t < mm->mini || *t > mm->
maxi ) {
1843 MLOCK(ErrorMessageLock);
1844 MesPrint(
"Table boundary check. Argument %d",
1846 showtable: AO.OutFill = AO.OutputLine = (UBYTE *)m;
1851 MUNLOCK(ErrorMessageLock);
1856 i += ( *t - mm->
mini ) * (LONG)(mm->
size);
1864 i *= TABLEEXTENSION;
1867 rhsnumber = AM.zerorhs;
1868 tbufnum = AM.zbufnum;
1870 else if ( T->
strict == -3 ) {
1871 rhsnumber = AM.onerhs;
1872 tbufnum = AM.zbufnum;
1874 else if ( T->
strict < 0 )
goto NextFun;
1876 MLOCK(ErrorMessageLock);
1877 MesPrint(
"Element in table is undefined");
1883 #if ( TABLEEXTENSION == 2 )
1899 AN.FullProto = T->
prototype[AT.identity];
1903 AN.WildValue = AN.FullProto + SUBEXPSIZE;
1904 AN.WildStop = AN.FullProto+AN.FullProto[1];
1907 AN.RepFunList = AN.EndNest;
1908 AT.WorkPointer = (WORD *)(((UBYTE *)(AN.EndNest)) + AM.MaxTer/2);
1909 if ( AT.WorkPointer >= AT.WorkTop ) {
1910 MLOCK(ErrorMessageLock);
1912 MUNLOCK(ErrorMessageLock);
1916 if ( MatchFunction(BHEAD Tpattern,t1,&wilds) > 0 ) {
1917 AT.WorkPointer = oldwork;
1918 if ( AT.NestPoin != AT.Nest ) {
1919 AN.ncmod = oldncmod;
1924 retvalue = m[2] = rhsnumber;
1933 while ( r < m ) *t++ = *r++;
1939 while ( t >= r ) { t[j] = *t; t--; }
1950 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
1951 AT.TMbuff = tbufnum;
1952 AN.ncmod = oldncmod;
1955 AT.WorkPointer = oldwork;
1959 else if ( ( t[2] & DIRTYFLAG ) != 0 ) {
1962 if ( *t == FUNNYDOLLAR ) {
1963 if ( AR.Eside != LHSIDE ) {
1966 AT.TMbuff = AM.dbufnum;
1967 AN.ncmod = oldncmod;
1970 AC.lhdollarflag = 1;
1976 AN.ncmod = oldncmod;
1981 MLOCK(ErrorMessageLock);
1984 MUNLOCK(ErrorMessageLock);
2007 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2008 WORD *u, *v, *w, *from, *to,
2009 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2013 m = r - ABS(*r) + 1;
2016 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2019 if ( ( term + AR.TePos ) == t ) {
2021 while ( from < t ) *m++ = *from++;
2023 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2026 *m++ = t[1] + 4 + ARGHEAD;
2032 while ( t < v ) *m++ = *t++;
2038 while ( t < r ) *m++ = *t++;
2039 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2040 *termout = WORDDIF(m,termout);
2044 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec == 0 )
2045 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2050 oldncmod = AN.ncmod;
2052 if ( *t > 0 && t[1] ) {
2053 WORD oldsorttype = AR.SortType;
2056 if ( ( AN.ncmod != 0 )
2057 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2058 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2063 while ( from < t ) {
2064 if ( from == u ) w = m;
2069 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2071 AR.SortType = SORTHIGHFIRST;
2080 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2082 AN.ncmod = oldncmod;
2092 if (
EndSort(BHEAD m,1) < 0 ) {
2093 AN.ncmod = oldncmod;
2096 AR.PolyFun = oldPolyFun;
2097 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2099 AR.SortType = oldsorttype;
2101 while ( *m ) m += *m;
2102 *to = WORDDIF(m,to);
2104 if ( ToFast(to,to) ) {
2105 if ( *to <= -FUNCTION ) m = to+1;
2108 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2111 while ( t < r ) *m++ = *t++;
2112 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2113 *termout = WORDDIF(m,termout);
2114 AR.DeferFlag = olddefer;
2115 AN.ncmod = oldncmod;
2118 else if ( *t == -DOLLAREXPRESSION ) {
2119 if ( AR.Eside == LHSIDE ) {
2121 AC.lhdollarflag = 1;
2129 int nummodopt, dtype = -1;
2130 if ( AS.MultiThreaded ) {
2131 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2132 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2134 if ( nummodopt < NumModOptdollars ) {
2135 dtype = ModOptdollars[nummodopt].type;
2136 if ( dtype == MODLOCAL ) {
2137 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2140 LOCK(d->pthreadslockread);
2145 oldncmod = AN.ncmod;
2146 if ( ( AN.ncmod != 0 )
2147 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2148 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2152 while ( from < t ) {
2153 if ( from == u ) w = m;
2157 switch ( d->type ) {
2159 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2160 *m++ = -SNUMBER; *m++ = d->index;
2162 else { *m++ = -INDEX; *m++ = d->index; }
2165 *m++ = -SNUMBER; *m++ = 0;
break;
2167 if ( d->where[0] == 4 &&
2168 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2170 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2171 else *m++ = -d->where[1];
2181 to = m; r = d->where;
2185 i = *r; NCOPY(m,r,i)
2188 if ( ToFast(to,to) ) {
2189 if ( *to <= -FUNCTION ) m = to+1;
2192 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2206 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2207 AR.PolyFun = oldPolyFun;
2216 while ( *m ) m += *m;
2218 if ( ToFast(to,to) ) {
2219 if ( *to <= -FUNCTION ) m = to+1;
2224 w[1] = w[1] - 2 + (m-to);
2227 to = m; r = d->where;
2229 *m++ = i+4+ARGHEAD; *m++ = 1;
2232 while ( --i >= 0 ) *m++ = *r++;
2233 *m++ = 1; *m++ = 1; *m++ = 3;
2234 if ( ToFast(to,to) ) {
2235 if ( *to <= -FUNCTION ) m = to+1;
2238 w[1] = w[1] - 2 + (m-to);
2241 to = m; r = d->where;
2244 *m++ = *r++; *m++ = 1; r++;
2245 while ( --i >= 0 ) *m++ = *r++;
2247 else if ( *r <= -FUNCTION ) *m++ = *r++;
2248 else { *m++ = *r++; *m++ = *r++; }
2249 w[1] = w[1] - 2 + (m-to);
2252 to = m; r = d->where;
2255 while ( --i >= 0 ) {
2257 *m++ = -VECTOR; *m++ = *r++;
2259 else if ( *r >= AM.OffsetIndex ) {
2260 *m++ = -INDEX; *m++ = *r++;
2262 else { *m++ = -SNUMBER; *m++ = *r++; }
2270 *m++ = *r++; *m++ = 1; r++;
2271 while ( --i >= 0 ) *m++ = *r++;
2273 else if ( *r <= -FUNCTION ) *m++ = *r++;
2274 else { *m++ = *r++; *m++ = *r++; }
2277 w[1] = w[1] - 2 + (m-to);
2281 MLOCK(ErrorMessageLock);
2282 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2283 AC.dollarnames->namebuffer+d->name);
2284 MUNLOCK(ErrorMessageLock);
2286 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2291 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2295 while ( t < r ) *m++ = *t++;
2296 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2297 *termout = WORDDIF(m,termout);
2298 AR.DeferFlag = olddefer;
2299 AN.ncmod = oldncmod;
2303 else if ( *t == -TERMSINBRACKET ) {
2304 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2314 while ( from < t ) {
2315 if ( from == u ) w = m;
2318 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2319 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2322 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2324 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2325 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2330 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2331 *m++ = 6; *m++ = numterms & WORDMASK;
2332 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2337 while ( from < r ) *m++ = *from++;
2338 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2339 *termout = WORDDIF(m,termout);
2346 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec )
2347 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2348 u = t; v = t + t[1];
2351 if ( *t == FUNNYDOLLAR ) {
2352 if ( AR.Eside != LHSIDE ) {
2355 int nummodopt, dtype = -1;
2356 if ( AS.MultiThreaded ) {
2357 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2358 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2360 if ( nummodopt < NumModOptdollars ) {
2361 dtype = ModOptdollars[nummodopt].type;
2362 if ( dtype == MODLOCAL ) {
2363 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2366 LOCK(d->pthreadslockread);
2371 oldncmod = AN.ncmod;
2372 if ( ( AN.ncmod != 0 )
2373 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2374 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2376 while ( from < t ) {
2377 if ( from == u ) w = m;
2381 switch ( d->type ) {
2383 *m++ = d->index;
break;
2388 if ( d->where[0] == 4 && d->where[4] == 0
2389 && d->where[3] == 3 && d->where[2] == 1
2390 && d->where[1] < AM.OffsetIndex ) {
2396 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2398 MLOCK(ErrorMessageLock);
2399 MesPrint(
"$%s has wrong type for tensor substitution",
2400 AC.dollarnames->namebuffer+d->name);
2401 MUNLOCK(ErrorMessageLock);
2402 AN.ncmod = oldncmod;
2407 if ( d->where[0] == -INDEX ) {
2408 *m++ = d->where[1];
break;
2410 else if ( d->where[0] == -VECTOR ) {
2411 *m++ = d->where[1];
break;
2413 else if ( d->where[0] == -MINVECTOR ) {
2418 else if ( d->where[0] == -SNUMBER ) {
2419 if ( d->where[1] >= 0
2420 && d->where[1] < AM.OffsetIndex ) {
2421 *m++ = d->where[1];
break;
2426 if ( d->where[0] > 0 ) {
2427 r = d->where; i = *r++;
2428 while ( --i >= 0 ) *m++ = *r++;
2433 if ( *r == -INDEX ) {
2434 *m++ = r[1]; r += 2;
continue;
2436 else if ( *r == -VECTOR ) {
2437 *m++ = r[1]; r += 2;
continue;
2439 else if ( *r == -MINVECTOR ) {
2440 *m++ = r[1]; r += 2;
2441 sign = -sign;
continue;
2443 else if ( *r == -SNUMBER ) {
2445 && r[1] < AM.OffsetIndex ) {
2446 *m++ = r[1]; r += 2;
continue;
2455 if ( *r == INDEX && r[1] == 3 ) {
2458 else goto wrongtype;
2462 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2464 MLOCK(ErrorMessageLock);
2465 MesPrint(
"$%s is undefined in tensor substitution",
2466 AC.dollarnames->namebuffer+d->name);
2467 MUNLOCK(ErrorMessageLock);
2468 AN.ncmod = oldncmod;
2472 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2474 w[1] = w[1] - 2 + (m-to);
2477 while ( from < term ) *m++ = *from++;
2478 if ( sign < 0 ) m[-1] = -m[-1];
2479 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2480 *termout = m - termout;
2481 AN.ncmod = oldncmod;
2485 AC.lhdollarflag = 1;
2494 MLOCK(ErrorMessageLock);
2495 MesPrint(
"Internal error in InFunction: Function not encountered.");
2496 if ( AM.tracebackflag ) {
2497 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2498 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2500 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2504 while ( --i >= 0 ) {
2505 TalToLine((UWORD)(*termout++));
2506 TokenToLine((UBYTE *)
" ");
2510 MesCall(
"InFunction");
2512 MUNLOCK(ErrorMessageLock);
2516 MLOCK(ErrorMessageLock);
2517 MesCall(
"InFunction");
2518 MUNLOCK(ErrorMessageLock);
2522 MLOCK(ErrorMessageLock);
2523 MesPrint(
"Output term too large. Try to increase MaxTermSize in the setup.");
2524 MesCall(
"InFunction");
2525 MUNLOCK(ErrorMessageLock);
2550 WORD
InsertTerm(PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout,
2554 WORD *m, *t, *r, i, l2, j;
2555 WORD *u, *v, l1, *coef;
2556 coef = AT.WorkPointer;
2557 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2558 MLOCK(ErrorMessageLock);
2560 MUNLOCK(ErrorMessageLock);
2573 if ( *t == SUBEXPRESSION && t[2] == replac && t[3] && t[4] == extractbuff ) {
2575 while ( *r == SUBEXPRESSION && r[2] == replac && r[3] && r < m && r[4] == extractbuff ) {
2582 do { *m++ = *r++; }
while ( r < t );
2583 if ( t[1] > SUBEXPSIZE ) {
2588 if ( ( l2 = WildFill(BHEAD m,position,t) ) < 0 )
goto InsCall;
2592 i = ( j = ABS(l2) ) - 1;
2594 do { *--r = *--m; }
while ( --i > 0 );
2601 r -= ( j = ABS(l2) );
2603 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2607 while ( t < u && *t == DOLLAREXPR2 ) t += t[1];
2608 ComAct:
if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2609 if ( *r == 1 && r[1] == 1 && j == 3 ) {
2610 if ( l2 < 0 ) l1 = -l1;
2616 if ( MulRat(BHEAD (UWORD *)u,REDLENG(l1),(UWORD *)r,REDLENG(l2),
2617 (UWORD *)m,&l1) )
goto InsCall;
2629 *termout = WORDDIF(m,termout);
2630 if ( (*termout)*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
2631 MLOCK(ErrorMessageLock);
2632 MesPrint(
"Term too complex during substitution. MaxTermSize of %l is too small",AM.MaxTer);
2635 AT.WorkPointer = coef;
2649 do { *m++ = *r++; }
while ( r < t );
2653 r -= ( j = ABS(l2) );
2655 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2660 MLOCK(ErrorMessageLock);
2662 MesCall(
"InsertTerm");
2663 MUNLOCK(ErrorMessageLock);
2687 RENUMBER renumber, WORD *freeze, WORD nexpr)
2691 WORD *stop, *s1, *s2;
2696 stop = (WORD *)(((UBYTE *)(accum)) + 2*AM.MaxTer);
2698 while ( --number >= 0 ) accum += *accum;
2701 oldipointer = AR.CompressPointer;
2703 AR.CompressPointer = oldipointer;
2705 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 )
2707 if ( !l ) { *accum = 0;
return(0); }
2712 while ( r < m && *r != HAAKJE ) r += r[1];
2714 if ( *freeze != 4 ) l = -1;
2730 *m++ = WORDDIF(s2,r) + 3;
2732 while ( r < s2 ) *m++ = *r++;
2733 *m++ = 1; *m++ = 1; *m++ = 3;
2735 if ( Normalize(BHEAD AT.WorkPointer) )
goto PasErr;
2738 while ( --i >= 0 && *m++ == *r++ ) {}
2748 do { *r++ = *m++; }
while ( m < s1 );
2749 *accum = l = WORDDIF(r,accum);
2753 retlength = InCompState;
2757 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 ) {
2758 MLOCK(ErrorMessageLock);
2759 MesCall(
"PasteFile");
2760 MUNLOCK(ErrorMessageLock);
2763 if ( l == 0 ) { *accum = 0;
return(0); }
2764 retlength = InCompState;
2767 if ( accum > stop ) {
2768 MLOCK(ErrorMessageLock);
2769 MesPrint(
"Buffer too small in PasteFile");
2770 MUNLOCK(ErrorMessageLock);
2777 MLOCK(ErrorMessageLock);
2778 MesCall(
"PasteFile");
2779 MUNLOCK(ErrorMessageLock);
2808 WORD *
PasteTerm(PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby)
2811 WORD *t, *r, x, y, z;
2812 WORD *m, *u, l1, a[2];
2813 m = (WORD *)(((UBYTE *)(accum)) + AM.MaxTer);
2816 while ( --number >= 0 ) accum += *accum;
2817 if ( times == divby ) {
2820 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2828 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2829 if ( divby > times ) { x = divby; y = times; }
2830 else { x = times; y = divby; }
2832 while ( z ) { x = y; y = z; z = x%y; }
2833 if ( y != 1 ) { divby /= y; times /= y; }
2836 if ( MulRat(BHEAD (UWORD *)t,REDLENG(l1),(UWORD *)a,1,(UWORD *)accum,&l1) ) {
2837 MLOCK(ErrorMessageLock);
2838 MesCall(
"PasteTerm");
2839 MUNLOCK(ErrorMessageLock);
2844 if ( x < 0 ) { accum -= x; *accum++ = x - 1; }
2845 else { accum += x; *accum++ = x + 1; }
2846 *u = WORDDIF(accum,u);
2849 MLOCK(ErrorMessageLock);
2850 MesPrint(
"Buffer too small in PasteTerm");
2851 MUNLOCK(ErrorMessageLock);
2873 WORD
FiniTerm(PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos)
2876 WORD *m, *t, *r, i, numacc, l2, ipp;
2877 WORD *u, *v, l1, *coef = AT.WorkPointer, *oldaccum;
2878 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2879 MLOCK(ErrorMessageLock);
2881 MUNLOCK(ErrorMessageLock);
2890 do { *--r = *--m; }
while ( --i > 0 );
2897 if ( ( ( *t == SUBEXPRESSION && ( *(r=t+t[1]) != SUBEXPRESSION
2898 || r >= m || !r[3] ) ) || *t == EXPRESSION ) && t[2] == number && t[3] ) {
2903 if ( r < t )
do { *m++ = *r++; }
while ( r < t );
2905 if ( numacc >= 0 )
do {
2906 if ( *t == EXPRESSION ) {
2910 if ( *r == WILDCARDS ) {
2913 if ( ( l2 = WildFill(BHEAD m,accum,r) ) < 0 )
goto FiniCall;
2920 else if ( t[1] > SUBEXPSIZE && t[SUBEXPSIZE] != FROMBRAC ) {
2922 if ( ( l2 = WildFill(BHEAD m,accum,t) ) < 0 )
goto FiniCall;
2935 if ( r < v )
do { *m++ = *r++; }
while ( r < v );
2937 if ( *r == 1 && r[1] == 1 && ABS(l2) == 3 ) {
2938 if ( l2 < 0 ) l1 = -l1;
2947 while ( --numacc >= 0 ) {
2949 while ( --i >= 0 ) {
2950 TalToLine((UWORD)(*t++));
2951 TokenToLine((UBYTE *)
" ");
2958 if ( MulRat(BHEAD (UWORD *)coef,l1,(UWORD *)r,l2,(UWORD *)coef,&l1) )
goto FiniCall;
2959 if ( AN.ncmod != 0 && TakeModulus((UWORD *)coef,&l1,AC.cmod,AN.ncmod,UNPACK|AC.modmode) )
goto FiniCall;
2962 }
while ( --numacc >= 0 );
2963 if ( *t == SUBEXPRESSION ) {
2964 while ( t+t[1] < u && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2967 if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2974 if ( *r == SUBEXPRESSION ) {
2976 l1 = (WORD)(cbuf[r[4]].CanCommu[r[2]]);
2978 if ( *t == SUBEXPRESSION &&
2979 t[1] == r[1] && t[2] == r[2] && t[4] == r[4] ) {
2980 i = t[1] - SUBEXPSIZE;
2981 u = r + SUBEXPSIZE; v = t + SUBEXPSIZE;
2983 if ( *v++ != *u++ )
break;
2990 while ( r < m ) *t++ = *r++;
2995 if ( l1 && cbuf[t[4]].CanCommu[t[2]] )
break;
2996 while ( t+t[1] < m && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2999 if ( *t == SUBEXPRESSION && cbuf[t[4]].CanCommu[t[2]] )
3001 if ( *t >= FUNCTION+WILDOFFSET )
3002 ipp = *t - WILDOFFSET;
3005 && functions[ipp-FUNCTION].commute && l1 )
break;
3006 if ( *t == EXPRESSION )
break;
3019 l2 = ( l2 >= 0 ) ? i: -i;
3021 while ( --i > 0 ) *m++ = *r++;
3023 *termout = WORDDIF(m,termout);
3024 AT.WorkPointer = coef;
3029 AT.WorkPointer = coef;
3033 MLOCK(ErrorMessageLock);
3034 MesCall(
"FiniTerm");
3035 MUNLOCK(ErrorMessageLock);
3044 static WORD zeroDollar[] = { 0, 0 };
3075 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3076 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, retnorm, extractbuff;
3077 int *RepSto = AN.RepPoint, iscopy = 0;
3078 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3079 LONG posisub, oldcpointer, oldacpointer;
3081 WORD numfac[5], idfunctionflag;
3083 int nummodopt, dtype = -1, id;
3085 oldtoprhs = CC->numrhs;
3086 oldcpointer = CC->Pointer - CC->Buffer;
3087 oldatoprhs = CCC->numrhs;
3088 oldacpointer = CCC->Pointer - CCC->Buffer;
3090 if ( ( replac =
TestSub(BHEAD term,level) ) == 0 ) {
3091 if ( applyflag ) { TableReset(); applyflag = 0; }
3100 AN.PolyNormFlag = 0;
3101 AN.idfunctionflag = 0;
3102 if ( ( retnorm = Normalize(BHEAD term) ) != 0 ) {
3103 if ( retnorm > 0 ) {
3104 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3109 idfunctionflag = AN.idfunctionflag;
3110 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3112 if ( AN.PolyNormFlag ) {
3113 if ( AN.PolyFunTodo == 0 ) {
3114 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3115 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3118 WORD oldPolyFunExp = AR.PolyFunExp;
3120 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3121 AT.WorkPointer = term+*term;
3122 AR.PolyFunExp = oldPolyFunExp;
3123 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3124 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3125 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3126 AT.WorkPointer = term+*term;
3127 if ( AN.PolyNormFlag ) {
3128 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3129 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3130 AT.WorkPointer = term+*term;
3135 if ( idfunctionflag > 0 ) {
3136 if ( TakeIDfunction(BHEAD term) ) {
3137 AT.WorkPointer = term + *term;
3141 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3142 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3145 if ( level > AR.Cnumlhs ) {
3146 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3148 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3153 if (
Deferred(BHEAD term,level) )
goto GenCall;
3156 if ( AN.ncmod != 0 ) {
3157 if ( Modulus(term) )
goto GenCall;
3158 if ( !*term )
goto Return0;
3160 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3161 WORD olddummies = AN.IndDum;
3162 AN.IndDum = AM.IndDum;
3163 ReNumber(BHEAD term); Normalize(BHEAD term);
3164 AN.IndDum = olddummies;
3165 if ( !*term )
goto Return0;
3166 olddummies = DetCurDum(BHEAD term);
3167 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3169 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3170 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3172 else if ( AR.PolyFun > 0 ) {
3173 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3175 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3176 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3177 termout = AT.WorkPointer;
3178 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3179 if ( PutBracket(BHEAD term) )
return(-1);
3180 AN.RepPoint = RepSto;
3181 *AT.WorkPointer = 0;
3183 AT.WorkPointer = termout;
3184 CC->numrhs = oldtoprhs;
3185 CC->Pointer = CC->Buffer + oldcpointer;
3186 CCC->numrhs = oldatoprhs;
3187 CCC->Pointer = CCC->Buffer + oldacpointer;
3191 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3192 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3193 *AT.WorkPointer = 0;
3194 AN.RepPoint = RepSto;
3196 CC->numrhs = oldtoprhs;
3197 CC->Pointer = CC->Buffer + oldcpointer;
3198 CCC->numrhs = oldatoprhs;
3199 CCC->Pointer = CCC->Buffer + oldacpointer;
3203 i = C->
lhs[level][0];
3204 if ( i >= TYPECOUNT ) {
3210 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3211 AT.WorkPointer = term + *term;
3216 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3219 level = AC.Labels[C->
lhs[level][2]];
3222 AT.WorkPointer = term + *term;
3232 WORD ic, jc, *ifcode, *jfcode;
3233 jfcode = C->
lhs[level]; jc = jfcode[1];
3234 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3235 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3236 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3237 level = C->
lhs[level][2];
3238 if ( C->
lhs[level][0] != TYPEELIF )
break;
3240 AT.WorkPointer = ifcode;
3243 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3244 level = C->
lhs[level][2];
3245 if ( C->
lhs[level][0] != TYPEELIF )
break;
3251 level = C->
lhs[level][2];
3252 }
while ( C->
lhs[level][0] == TYPEELIF );
3256 level = C->
lhs[level][2];
3260 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3261 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3262 WORD theindex = C->
lhs[level][2];
3263 if ( theindex < 0 ) {
3266 theindex = -theindex;
3267 d = Dollars + theindex;
3268 if ( AS.MultiThreaded ) {
3269 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3270 if ( theindex == ModOptdollars[nummodopt].number )
break;
3272 if ( nummodopt < NumModOptdollars ) {
3273 ddtype = ModOptdollars[nummodopt].type;
3274 if ( ddtype == MODLOCAL ) {
3275 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3278 LOCK(d->pthreadslockread);
3283 theindex = -theindex;
3284 d = Dollars + theindex;
3287 if ( d->type != DOLINDEX
3288 || d->index < AM.OffsetIndex
3289 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3290 MLOCK(ErrorMessageLock);
3291 MesPrint(
"$%s should have been an index"
3292 ,AC.dollarnames->namebuffer+d->name);
3293 AN.currentTerm = term;
3294 MesPrint(
"Current term: %t");
3295 AN.listinprint = printscratch;
3296 printscratch[0] = DOLLAREXPRESSION;
3297 printscratch[1] = theindex;
3299 ,AC.dollarnames->namebuffer+d->name);
3300 MUNLOCK(ErrorMessageLock);
3302 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3306 theindex = d->index;
3308 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3311 cp[1] = SUBEXPSIZE+4;
3316 i = C->
lhs[level][1] - 3;
3318 AR.CompressPointer = cp;
3319 while ( --i >= 0 ) {
3321 termout = AT.WorkPointer;
3322 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3326 while ( --jlhs >= 0 ) {
3327 if ( *m++ != *termout++ )
break;
3330 termout = AT.WorkPointer;
3331 AT.WorkPointer = termout + *termout;
3332 if (
Generator(BHEAD termout,level) )
goto GenCall;
3333 AT.WorkPointer = termout;
3336 AR.CompressPointer = op;
3340 AR.CompressPointer = op;
3345 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3351 AR.CurDum = DetCurDum(BHEAD term);
3352 i = C->
lhs[level][1]-2;
3353 wp = C->
lhs[level] + 2;
3354 cp[1] = SUBEXPSIZE+4*i;
3356 while ( --i >= 0 ) {
3358 if ( theindex < 0 ) {
3361 theindex = -theindex;
3362 d = Dollars + theindex;
3363 if ( AS.MultiThreaded ) {
3364 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3365 if ( theindex == ModOptdollars[nummodopt].number )
break;
3367 if ( nummodopt < NumModOptdollars ) {
3368 ddtype = ModOptdollars[nummodopt].type;
3369 if ( ddtype == MODLOCAL ) {
3370 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3373 LOCK(d->pthreadslockread);
3378 theindex = -theindex;
3379 d = Dollars + theindex;
3381 if ( d->type != DOLINDEX
3382 || d->index < AM.OffsetIndex
3383 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3384 MLOCK(ErrorMessageLock);
3385 MesPrint(
"$%s should have been an index"
3386 ,AC.dollarnames->namebuffer+d->name);
3387 AN.currentTerm = term;
3388 MesPrint(
"Current term: %t");
3389 AN.listinprint = printscratch;
3390 printscratch[0] = DOLLAREXPRESSION;
3391 printscratch[1] = theindex;
3393 ,AC.dollarnames->namebuffer+d->name);
3394 MUNLOCK(ErrorMessageLock);
3396 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3400 theindex = d->index;
3402 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3408 *cp++ = ++AR.CurDum;
3410 ow = AT.WorkPointer;
3411 AR.CompressPointer = cp;
3412 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3413 AR.CompressPointer = op;
3415 for ( j = 0; j < i; j++ ) term[j] = ow[j];
3416 AT.WorkPointer = ow;
3417 ReNumber(BHEAD term);
3421 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3423 AT.WorkPointer = term + *term;
3426 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3427 level = C->
lhs[level][2];
3428 if ( i > 0 )
goto ReStart;
3436 case TYPESPLITFIRSTARG:
3437 case TYPESPLITLASTARG:
3438 case TYPEARGTOEXTRASYMBOL:
3439 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3440 level = C->
lhs[level][2];
3445 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3446 if ( jjj > 0 )
goto ReStart;
3447 level = C->
lhs[level][2];
3450 if ( C->
lhs[level][2] > 0 ) {
3451 MLOCK(ErrorMessageLock);
3452 MesPrint(
"%s",C->
lhs[level]+3);
3453 MUNLOCK(ErrorMessageLock);
3461 AN.currentTerm = term;
3462 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3463 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3464 MLOCK(ErrorMessageLock);
3466 MesPrint((
char *)(C->
lhs[level]+5));
3468 MUNLOCK(ErrorMessageLock);
3473 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3474 AC.LogHandle = C->
lhs[level][2];
3475 MLOCK(ErrorMessageLock);
3476 oldFOflag = AM.FileOnlyFlag;
3477 oldPrintType = AO.PrintType;
3478 if ( AC.LogHandle >= 0 ) {
3479 AM.FileOnlyFlag = 1;
3480 AO.PrintType |= PRINTLFILE;
3482 AO.PrintType |= C->
lhs[level][3];
3483 AN.currentTerm = term;
3484 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3485 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3486 MesPrint((
char *)(C->
lhs[level]+5));
3487 AO.PrintType = oldPrintType;
3488 AM.FileOnlyFlag = oldFOflag;
3489 MUNLOCK(ErrorMessageLock);
3490 AC.LogHandle = oldLogHandle;
3494 j = C->
lhs[level][2];
3504 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3505 if ( AC.pfirstnum[ii] == j )
break;
3507 AC.inputnumbers[ii] = AN.ninterms;
3511 if ( AS.MultiThreaded ) {
3513 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3514 if ( AC.pfirstnum[ii] == j )
break;
3516 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3517 LOCK(AP.PreVarLock);
3518 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3519 a = C->
lhs[level]+4;
3520 if ( a[a[-1]] == 0 )
3521 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3524 ,(UBYTE *)(a+a[-1]+1),1);
3528 AC.inputnumbers[ii] = AN.inputnumber;
3530 UNLOCK(AP.PreVarLock);
3535 a = C->
lhs[level]+4;
3536 LOCK(AP.PreVarLock);
3537 if ( a[a[-1]] == 0 )
3538 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3541 ,(UBYTE *)(a+a[-1]+1),1);
3542 UNLOCK(AP.PreVarLock);
3546 AT.WorkPointer = term + *term;
3547 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3548 AT.WorkPointer = term + *term;
3549 if ( *term == 0 )
goto Return0;
3552 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3553 AT.WorkPointer = term + *term;
3556 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3557 WORD oldrepeat = *AN.RepPoint;
3563 AN.cTerm = AN.currentTerm = term;
3564 AT.WorkPointer = term + *term;
3565 *AT.WorkPointer++ = 0;
3566 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3567 AT.WorkPointer = term + *term;
3569 *AN.RepPoint = oldrepeat;
3570 AR.NoCompress = onc;
3571 AR.Eside = oldEside;
3575 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3576 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3577 AT.WorkPointer = term + *term;
3582 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3583 level = C->
lhs[level][2];
3586 retnorm = execterm(BHEAD term,level);
3587 AN.RepPoint = RepSto;
3589 CC->numrhs = oldtoprhs;
3590 CC->Pointer = CC->Buffer + oldcpointer;
3591 CCC->numrhs = oldatoprhs;
3592 CCC->Pointer = CCC->Buffer + oldacpointer;
3595 AT.WorkPointer = term + *term;
3596 AR.CurDum = DetCurDum(BHEAD term);
3598 case TYPEINEXPRESSION:
3599 {WORD *ll = C->
lhs[level];
3600 int numexprs = (int)(ll[1]-3);
3602 while ( numexprs-- >= 0 ) {
3603 if ( *ll == AR.CurExpr )
break;
3606 if ( numexprs < 0 ) level = C->
lhs[level][2];
3610 AT.WorkPointer = term + *term;
3611 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3613 AT.WorkPointer = term + *term;
3616 AT.WorkPointer = term + *term;
3617 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3619 AT.WorkPointer = term + *term;
3622 AT.WorkPointer = term + *term;
3623 if ( TestUse(term,level) )
goto GenCall;
3624 AT.WorkPointer = term + *term;
3627 AT.WorkPointer = term + *term;
3628 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3629 AT.WorkPointer = term + *term;
3633 AT.WorkPointer = term + *term;
3643 AT.WorkPointer = term + *term;
3644 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3645 AT.WorkPointer = term + *term;
3648 AT.WorkPointer = term + *term;
3649 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3650 AT.WorkPointer = term + *term;
3653 AT.WorkPointer = term + *term;
3654 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3655 AT.WorkPointer = term + *term;
3657 case TYPEARGIMPLODE:
3658 AT.WorkPointer = term + *term;
3659 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3660 AT.WorkPointer = term + *term;
3662 case TYPEARGEXPLODE:
3663 AT.WorkPointer = term + *term;
3664 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3665 AT.WorkPointer = term + *term;
3667 case TYPEDENOMINATORS:
3668 DenToFunction(term,C->
lhs[level][2]);
3670 case TYPEDROPCOEFFICIENT:
3671 DropCoefficient(BHEAD term);
3674 AT.WorkPointer = term + *term;
3675 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3676 AT.WorkPointer = term + *term;
3677 if ( *term == 0 )
goto Return0;
3679 case TYPETOPOLYNOMIAL:
3680 AT.WorkPointer = term + *term;
3681 termout = AT.WorkPointer;
3682 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3683 if ( *termout == 0 )
goto Return0;
3684 i = termout[0]; t = term; NCOPY(t,termout,i);
3685 AT.WorkPointer = term + *term;
3687 case TYPEFROMPOLYNOMIAL:
3688 AT.WorkPointer = term + *term;
3689 termout = AT.WorkPointer;
3690 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3691 if ( *term == 0 )
goto Return0;
3692 i = termout[0]; t = term; NCOPY(t,termout,i);
3693 AT.WorkPointer = term + *term;
3696 level = TestDoLoop(BHEAD C->
lhs[level],level);
3697 if ( level < 0 )
goto GenCall;
3700 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3701 if ( level < 0 )
goto GenCall;
3703 case TYPEDROPSYMBOLS:
3704 DropSymbols(BHEAD term);
3707 AT.WorkPointer = term + *term;
3708 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3709 AT.WorkPointer = term + *term;
3714 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3716 case TYPETOSPECTATOR:
3717 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3719 case TYPECANONICALIZE:
3720 AT.WorkPointer = term + *term;
3721 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3722 AT.WorkPointer = term + *term;
3723 if ( *term == 0 )
goto Return0;
3726 AT.WorkPointer = term + *term;
3727 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3730 AT.WorkPointer = term + *term;
3731 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3739 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
3740 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3741 if ( i > 0 ) replac =
TestSub(BHEAD term,level);
3743 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
3748 AutoGen: i = *AT.TMout;
3749 t = termout = AT.WorkPointer;
3750 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
3752 while ( --i >= 0 ) *t++ = *accum++;
3753 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
3754 AT.WorkPointer = termout;
3758 if ( applyflag ) { TableReset(); applyflag = 0; }
3762 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
3764 if ( AR.TePos >= 0 )
goto AutoGen;
3765 switch ( AN.TeInFun ) {
3767 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
3770 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
3773 if ( DoTableExpansion(term,level) )
goto GenCall;
3776 if ( FactorIn(BHEAD term,level) )
goto GenCall;
3779 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
3782 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
3785 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
3788 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
3791 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
3794 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
3797 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
3800 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
3803 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
3806 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
3809 if ( GenTopologies(BHEAD term,level) < 0 )
goto GenCall;
3812 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
3817 termout = AT.WorkPointer;
3818 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3819 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3820 if (
InFunction(BHEAD term,termout) )
goto GenCall;
3821 AT.WorkPointer = termout + *termout;
3824 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3825 AT.WorkPointer = termout;
3828 else if ( replac > 0 ) {
3832 power = -power; tepos = 0;
3834 extractbuff = AT.TMbuff;
3835 if ( extractbuff == AM.dbufnum ) {
3836 d = DolToTerms(BHEAD replac);
3837 if ( d && d->where != 0 ) {
3839 if ( AT.TMdolfac > 0 ) {
3840 if ( AT.TMdolfac == 1 ) {
3841 if ( d->nfactors ) {
3843 numfac[1] = d->nfactors;
3854 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
3855 MLOCK(ErrorMessageLock);
3856 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
3857 if ( d->nfactors == 1 )
3858 MesPrint(
"There is only one factor");
3860 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
3861 MUNLOCK(ErrorMessageLock);
3864 if ( d->nfactors > 1 ) {
3868 dd = Dollars + replac;
3871 int nummodopt, dtype = -1;
3872 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
3873 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3874 if ( replac == ModOptdollars[nummodopt].number )
break;
3876 if ( nummodopt < NumModOptdollars ) {
3877 dtype = ModOptdollars[nummodopt].type;
3878 if ( dtype == MODLOCAL ) {
3879 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
3885 dsize = dd->factors[AT.TMdolfac-2].size;
3891 numfac[1] = d->factors[AT.TMdolfac-2].value;
3896 if ( numfac[1] < 0 ) {
3897 numfac[1] = -numfac[1];
3898 numfac[3] = -numfac[3];
3902 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
3903 (dsize+1)*
sizeof(WORD),
"Copy of factor");
3904 td1 = dd->factors[AT.TMdolfac-2].where;
3906 d->size = dsize; d->type = DOLTERMS;
3907 NCOPY(td2,td1,dsize);
3911 else if ( d->nfactors == 1 ) {
3912 StartBuf = d->where;
3915 MLOCK(ErrorMessageLock);
3916 if ( d->nfactors == 0 ) {
3917 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
3920 MesPrint(
"Internal error. Illegal number of factors for $-variable");
3922 MUNLOCK(ErrorMessageLock);
3927 else StartBuf = d->where;
3930 d = Dollars + replac;
3931 StartBuf = zeroDollar;
3934 i = DetCommu(d->where);
3936 if ( AS.MultiThreaded ) {
3937 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3938 if ( replac == ModOptdollars[nummodopt].number )
break;
3940 if ( nummodopt < NumModOptdollars ) {
3941 dtype = ModOptdollars[nummodopt].type;
3942 if ( dtype != MODLOCAL && dtype != MODSUM ) {
3943 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
3944 MLOCK(ErrorMessageLock);
3945 MesPrint(
"A dollar variable with modoption max or min can have only one term");
3946 MUNLOCK(ErrorMessageLock);
3949 LOCK(d->pthreadslockread);
3956 StartBuf = cbuf[extractbuff].Buffer;
3957 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
3958 i = (WORD)cbuf[extractbuff].CanCommu[replac];
3961 termout = AT.WorkPointer;
3962 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3963 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3964 while ( StartBuf[posisub] ) {
3965 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
3966 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
3967 if (
InsertTerm(BHEAD term,replac,extractbuff,
3968 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
3969 AT.WorkPointer = termout + *termout;
3972 posisub += StartBuf[posisub];
3984 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
3985 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
3986 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3987 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3992 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3994 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
3996 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4003 StartBuf = cbuf[extractbuff].Buffer;
4006 if ( extractbuff == AT.allbufnum ) {
4007 CBUF *Ce = cbuf + extractbuff;
4011 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4014 if ( d->nfactors > 1 ) {
4016 for ( j = 0; j < d->nfactors; j++ ) {
4017 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4019 M_free(d->factors,
"Dollar factors");
4021 M_free(d,
"Copy of dollar variable");
4024 AT.WorkPointer = termout;
4026 else if ( i <= 1 ) {
4028 WORD *same, *ow = AT.WorkPointer;
4029 LONG olpw = AT.posWorkPointer;
4031 WantAddLongs(power1);
4032 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4033 same = ++AT.WorkPointer;
4034 a = accum = ( AT.WorkPointer += power1+1 );
4035 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4036 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4037 AT.lWorkSpace[posit] = posisub;
4044 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4046 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4048 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4049 same[1] = *same + 1;
4050 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4051 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4057 i--; posit--; same--;
4060 termout = AT.WorkPointer = a;
4061 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4062 if ( AT.WorkPointer > AT.WorkTop )
4064 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4065 AT.WorkPointer = termout + *termout;
4069 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4070 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4071 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4072 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4076 if (
Generator(BHEAD termout,level) )
goto GenCall;
4078 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4080 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4081 StartBuf = cbuf[extractbuff].Buffer;
4082 i--; posit--; same--;
4086 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4089 if ( d->nfactors > 1 ) {
4091 for ( j = 0; j < d->nfactors; j++ ) {
4092 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4094 M_free(d->factors,
"Dollar factors");
4096 M_free(d,
"Copy of dollar variable");
4099 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4102 LONG posit, olw, olpw = AT.posWorkPointer;
4103 WantAddLongs(power);
4104 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4105 a = accum = AT.WorkPointer;
4106 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4107 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4108 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4114 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4116 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4117 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4121 AT.lWorkSpace[posit--] = posisub;
4125 termout = AT.WorkPointer = a;
4126 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4127 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4128 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4129 AT.WorkPointer = termout + *termout;
4133 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
4134 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4135 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4139 if (
Generator(BHEAD termout,level) )
goto GenCall;
4141 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { dtype = 0;
break; }
4143 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4144 StartBuf = cbuf[extractbuff].Buffer;
4149 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
4152 if ( d->nfactors > 1 ) {
4154 for ( j = 0; j < d->nfactors; j++ ) {
4155 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4157 M_free(d->factors,
"Dollar factors");
4159 M_free(d,
"Copy of dollar variable");
4162 AT.WorkPointer = accum;
4163 AT.lWorkPointer = olw;
4164 AT.posWorkPointer = olpw;
4169 LONG position, olpw, opw, comprev, extra;
4171 WORD *Freeze, *aa, *dummies;
4175 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4177 SETSTARTPOS(firstpos);
4189 WantAddPointers(power+1);
4190 comprev = opw = AT.pWorkPointer;
4191 AT.pWorkPointer += power+1;
4192 WantAddPositions(power+1);
4193 position = olpw = AT.posWorkPointer;
4194 AT.posWorkPointer += power + 1;
4196 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4198 for ( i = 0; i < power; i++ ) {
4199 PUTZERO(AT.posWorkSpace[position]); position++;
4202 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4203 dummies = AT.WorkPointer;
4204 *dummies++ = AR.CurDum;
4205 AT.WorkPointer += power+2;
4206 accum = AT.WorkPointer;
4207 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4208 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4209 aa = AT.WorkPointer;
4211 i = 0; StartPos = AT.posWorkSpace[position];
4212 dummies[i] = AR.CurDum;
4215 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4216 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4217 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4218 if ( Expressions[replac].numdummies > 0 ) {
4219 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4221 if ( NOTSTARTPOS(firstpos) ) {
4222 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4223 firstpos = AT.posWorkSpace[position];
4234 i++; AT.posWorkSpace[++position] = StartPos;
4235 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4236 dummies[i] = AR.CurDum;
4239 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4240 AR.CurDum = dummies[i];
4244 termout = AT.WorkPointer = a;
4245 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4246 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4247 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4249 AT.WorkPointer = termout + *termout;
4253 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4254 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4259 if (
Generator(BHEAD termout,level) )
goto GenCall;
4262 AR.CurDum = dummies[i];
4265 AT.WorkPointer = aa;
4267 AT.WorkPointer = accum;
4268 AT.posWorkPointer = olpw;
4269 AT.pWorkPointer = opw;
4277 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4278 M_free(renumber->
symb.
lo,
"VarSpace");
4279 M_free(renumber,
"Renumber");
4283 aa = accum = AT.WorkPointer;
4284 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4286 *accum++ = -1; AT.WorkPointer++;
4287 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4288 AT.WorkPointer = aa;
4293 AN.RepPoint = RepSto;
4294 CC->numrhs = oldtoprhs;
4295 CC->Pointer = CC->Buffer + oldcpointer;
4296 CCC->numrhs = oldatoprhs;
4297 CCC->Pointer = CCC->Buffer + oldacpointer;
4301 if ( AM.tracebackflag ) {
4303 MLOCK(ErrorMessageLock);
4304 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4308 while ( --i >= 0 ) {
4309 TalToLine((UWORD)(*termout++));
4310 TokenToLine((UBYTE *)
" ");
4314 MesCall(
"Generator");
4315 MUNLOCK(ErrorMessageLock);
4317 CC->numrhs = oldtoprhs;
4318 CC->Pointer = CC->Buffer + oldcpointer;
4319 CCC->numrhs = oldatoprhs;
4320 CCC->Pointer = CCC->Buffer + oldacpointer;
4323 CC->numrhs = oldtoprhs;
4324 CC->Pointer = CC->Buffer + oldcpointer;
4325 CCC->numrhs = oldatoprhs;
4326 CCC->Pointer = CCC->Buffer + oldacpointer;
4327 MLOCK(ErrorMessageLock);
4329 MUNLOCK(ErrorMessageLock);
4362 char freezestring[] =
"freeze<-xxxx";
4365 WORD
DoOnePow(PHEAD WORD *term, WORD power, WORD nexp, WORD * accum,
4366 WORD *aa, WORD level, WORD *freeze)
4369 POSITION oldposition, startposition;
4370 WORD *acc, *termout, fromfreeze = 0;
4371 WORD *oldipointer = AR.CompressPointer;
4374 WORD oldGetOneFile = AR.GetOneFile;
4375 WORD olddummies = AR.CurDum;
4376 WORD extradummies = Expressions[nexp].numdummies;
4406 type = Expressions[nexp].status;
4407 if ( type == HIDDENLEXPRESSION || type == HIDDENGEXPRESSION
4408 || type == DROPHLEXPRESSION || type == DROPHGEXPRESSION
4409 || type == UNHIDELEXPRESSION || type == UNHIDEGEXPRESSION ) {
4410 AR.GetOneFile = 2; fi = AR.hidefile;
4413 AR.GetOneFile = 0; fi = AR.infile;
4416 PUTZERO(oldposition);
4418 LOCK(AS.inputslock);
4419 SeekFile(fi->
handle,&oldposition,SEEK_CUR);
4420 UNLOCK(AS.inputslock);
4424 SETBASEPOSITION(oldposition,fi->POfill-fi->PObuffer);
4426 if ( freeze && ( Expressions[nexp].bracketinfo != 0 ) ) {
4434 if ( ( brapos = FindBracket(nexp,freeze) ) == 0 )
4436 startposition = *brapos;
4439 startposition = AS.OldOnFile[nexp];
4440 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4445 AR.CompressPointer = oldipointer;
4447 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4448 if ( retval <= 0 )
break;
4453 WORD *t, *m, *r, *mstop;
4466 while ( t < r && *t != HAAKJE ) t += t[1];
4469 if ( fromfreeze )
goto EndExpr;
4476 while ( r < t && m < mstop ) {
4477 if ( *r == *m ) { m++; r++; }
4479 if ( fromfreeze )
goto EndExpr;
4483 if ( r < t || m < mstop ) {
4484 if ( fromfreeze )
goto EndExpr;
4492 while ( t < m ) *r++ = *t++;
4493 *accum = WORDDIF(r,accum);
4495 if ( extradummies > 0 ) {
4496 if ( olddummies > AM.IndDum ) {
4497 MoveDummies(BHEAD accum,olddummies-AM.IndDum);
4499 AR.CurDum = olddummies+extradummies;
4505 AT.WorkPointer = (WORD *)(((UBYTE *)(acc)) + 2*AM.MaxTer);
4506 if ( AT.WorkPointer > AT.WorkTop ) {
4507 MLOCK(ErrorMessageLock);
4509 MUNLOCK(ErrorMessageLock);
4512 if (
FiniTerm(BHEAD term,aa,termout,nexp,0) )
goto PowCall;
4514 MarkPolyRatFunDirty(termout)
4516 AT.WorkPointer = termout + *termout;
4519 if (
Generator(BHEAD termout,level) )
goto PowCall;
4523 if ( acc > AT.WorkTop ) {
4524 MLOCK(ErrorMessageLock);
4526 MUNLOCK(ErrorMessageLock);
4529 if (
DoOnePow(BHEAD term,power,nexp,acc,aa,level,freeze) )
goto PowCall;
4532 AR.CompressPointer = oldipointer;
4537 AR.CompressPointer = oldipointer;
4540 LOCK(AS.inputslock);
4541 SeekFile(fi->
handle,&oldposition,SEEK_SET);
4542 UNLOCK(AS.inputslock);
4543 if ( ISNEGPOS(oldposition) ) {
4544 MLOCK(ErrorMessageLock);
4545 MesPrint(
"File error");
4551 fi->POfill = fi->PObuffer + BASEPOSITION(oldposition);
4553 AR.GetOneFile = oldGetOneFile;
4554 AR.CurDum = olddummies;
4557 MLOCK(ErrorMessageLock);
4561 MesCall(
"DoOnePow");
4562 MUNLOCK(ErrorMessageLock);
4590 WORD *t, *m, *mstop, *tstart, decr, oldb, *termout, i, *oldwork, retval;
4591 WORD *oldipointer = AR.CompressPointer, *oldPOfill = AR.infile->POfill;
4592 WORD oldGetOneFile = AR.GetOneFile;
4594 oldwork = AT.WorkPointer;
4595 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4596 termout = AT.WorkPointer;
4598 startposition = AR.DefPosition;
4602 if ( AR.infile->handle >= 0 ) {
4612 AR.infile->POfill = (WORD *)((UBYTE *)(AR.infile->PObuffer)
4613 +BASEPOSITION(startposition));
4618 t = m = AR.CompressBuffer;
4620 mstop = t - ABS(t[-1]);
4622 while ( *m != HAAKJE && m < mstop ) m += m[1];
4624 AT.WorkPointer = term + *term;
4625 if (
Generator(BHEAD term,level) )
goto DefCall;
4627 AT.WorkPointer = oldwork;
4628 AR.GetOneFile = oldGetOneFile;
4632 decr = WORDDIF(mstop,AR.CompressBuffer)-1;
4633 tstart = AR.CompressPointer + decr;
4635 m = AR.CompressBuffer;
4636 t = AR.CompressPointer;
4650 *tstart = *(AR.CompressPointer)-decr;
4651 AR.CompressPointer = AR.CompressPointer+AR.CompressPointer[0];
4652 if (
InsertTerm(BHEAD term,0,AM.rbufnum,tstart,termout,0) < 0 ) {
4656 AT.WorkPointer = termout + *termout;
4657 if (
Generator(BHEAD termout,level) )
goto DefCall;
4658 AR.CompressPointer = oldipointer;
4659 AT.WorkPointer = termout;
4660 retval = GetOneTerm(BHEAD AT.WorkPointer,AR.infile,&startposition,0);
4661 if ( retval >= 0 ) AR.CompressPointer = oldipointer;
4662 if ( retval <= 0 )
break;
4663 t = AR.CompressPointer;
4664 if ( *t < (1 + decr + ABS(*(t+*t-1))) )
break;
4666 m = AR.CompressBuffer+1;
4667 while ( m < mstop ) {
4668 if ( *m != *t )
goto Thatsit;
4676 if ( AR.infile->handle < 0 ) AR.infile->POfill = oldPOfill;
4678 AR.GetOneFile = oldGetOneFile;
4679 AT.WorkPointer = oldwork;
4682 MLOCK(ErrorMessageLock);
4683 MesCall(
"Deferred");
4684 MUNLOCK(ErrorMessageLock);
4717 WORD count = 0, i, jcoef, ncoef;
4718 WORD *t, *m, *r, *tstop, *
poly = 0, *v, *w, *vv, *ww;
4719 WORD *oldworkpointer = AT.WorkPointer;
4727 if ( AR.PolyFunType == 2 && AR.PolyFunExp != 2 ) {
4728 WORD oldtype = AR.SortType;
4729 AR.SortType = SORTHIGHFIRST;
4730 if ( poly_ratfun_normalize(BHEAD term) != 0 ) Terminate(-1);
4732 oldworkpointer = AT.WorkPointer;
4733 AR.SortType = oldtype;
4739 while ( t < tstop ) {
4740 if ( *t == AR.PolyFun ) {
4741 if ( count > 0 )
return(0);
4747 r = m = term + *term;
4750 if ( count == 0 )
return(0);
4751 else if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) )
4753 else if ( AR.PolyFunType == 2 )
4758 else if ( count == 0 ) {
4763 if ( i == 3 && m[-2] == 1 && (m[-3]&MAXPOSITIVE) == m[-3] ) {
4765 if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4769 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4772 else if ( AR.PolyFunType == 2 ) {
4776 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4785 if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4787 *m++ = FUNHEAD+ARGHEAD+i+1;
4795 else if ( AR.PolyFunType == 2 ) {
4796 WORD *num, *den, size, sign, sizenum, sizeden;
4797 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
4798 else { sign = 1; size = m[-1]; }
4799 num = m - size; size = (size-1)/2; den = num + size;
4800 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
4801 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
4803 AT.PolyAct = WORDDIF(v,term);
4808 *v++ = ARGHEAD+2*sizenum+2;
4812 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
4814 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
4815 *v++ = sign*(2*sizenum+1);
4816 if ( ToFast(vm,vm) ) v = vm+2;
4818 *v++ = ARGHEAD+2*sizeden+2;
4822 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
4824 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
4826 if ( ToFast(vm,vm) ) v = vm+2;
4831 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
4839 else if ( AR.PolyFunType == 1 || (AR.PolyFunType == 2 && AR.PolyFunExp == 2) ) {
4846 if ( ( poly[1] == FUNHEAD+2 && poly[FUNHEAD+1] == 0
4847 && poly[FUNHEAD] == -SNUMBER ) || poly[1] == FUNHEAD )
return(1);
4849 if ( t >= r )
return(0);
4850 if ( m[-1] == 3 && *tstop == 1 && tstop[1] == 1 ) {
4855 else if ( *t <= -FUNCTION ) {
4856 if ( t+1 < r )
return(0);
4859 *m++ = FUNHEAD*2+ARGHEAD+i+1;
4861 *m++ = FUNHEAD+ARGHEAD+i+1;
4870 else if ( *t < 0 ) {
4871 if ( t+2 < r )
return(0);
4873 if ( *t == -SNUMBER ) {
4874 if ( t[1] == 0 )
return(1);
4877 m += FUNHEAD+ARGHEAD;
4885 if ( m >= AT.WorkSpace && m < AT.WorkTop )
4887 if ( Normalize(BHEAD v) ) Terminate(-1);
4888 AT.WorkPointer = oldworkpointer;
4890 if ( *v == 4 && v[2] == 1 && (v[1]&MAXPOSITIVE) == v[1] ) {
4894 *m++ = v[3] < 0 ? -v[1] : v[1];
4896 else if ( *v == 0 )
return(1);
4898 *m++ = FUNHEAD+ARGHEAD+*v;
4906 else if ( *t == -SYMBOL ) {
4908 *m++ = FUNHEAD+ARGHEAD+5+i;
4923 if ( t + *t < r )
return(0);
4927 m += ARGHEAD+FUNHEAD-1;
4929 jcoef = i < 0 ? (i+1)>>1:(i-1)>>1;
4938 vstop = vv - ABS(vv[-1]);
4940 while( t < vstop ) {
4941 if ( *t == INDEX )
return(0);
4954 vv = v - ABS(ncoef);
4955 if ( ncoef < 0 ) ncoef++;
4958 while ( t < vv ) *m++ = *t++;
4959 if ( MulRat(BHEAD (UWORD *)vv,ncoef,(UWORD *)tstop,jcoef,
4960 (UWORD *)m,&ncoef) ) Terminate(-1);
4963 if ( ncoef < 0 ) ncoef--;
4966 *ww = WORDDIF(m,ww);
4967 if ( AN.ncmod != 0 ) {
4968 if ( Modulus(ww) ) Terminate(-1);
4969 if ( *ww == 0 )
return(1);
4974 *w = (WORDDIF(m,w))+1;
4975 w[FUNHEAD-1] = w[0] - FUNHEAD;
4979 if ( ToFast(w,w) ) {
4980 if ( *w <= -FUNCTION ) { w[-FUNHEAD+1] = FUNHEAD+1; m = w+1; }
4981 else { w[-FUNHEAD+1] = FUNHEAD+2; m = w+2; }
4986 while ( t < tstop ) *poly++ = *t++;
4991 else if ( AR.PolyFunType == 2 ) {
4996 WORD *num, *den, size, sign, sizenum, sizeden;
5001 if ( poly + poly[1] < tstop ) {
5002 for ( i = 0; i < poly[1]; i++ ) m[i] = poly[i];
5003 t = poly; v = poly + poly[1];
5004 while ( v < tstop ) *t++ = *v++;
5006 for ( i = 0; i < m[1]; i++ ) t[i] = m[i];
5009 AT.PolyAct = WORDDIF(poly,term);
5014 if ( m[-1] == 3 && m[-2] == 1 && m[-3] == 1 )
return(0);
5015 if ( AR.PolyFunExp != 1 ) {
5016 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
else { sign = 1; size = m[-1]; }
5017 num = m - size; size = (size-1)/2; den = num + size;
5018 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
5019 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
5022 *v++ = FUNHEAD + 2*(ARGHEAD+sizenum+sizeden+2);
5026 *v++ = ARGHEAD+2*sizenum+2;
5030 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
5032 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
5033 *v++ = sign*(2*sizenum+1);
5034 *v++ = ARGHEAD+2*sizeden+2;
5038 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
5040 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
5049 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
5051 WORD oldtype = AR.SortType;
5052 AR.SortType = SORTHIGHFIRST;
5059 poly_ratfun_normalize(BHEAD term);
5062 AR.SortType = oldtype;
5071 MLOCK(ErrorMessageLock);
5072 MesPrint(
"Illegal value for PolyFunType in PrepPoly");
5073 MUNLOCK(ErrorMessageLock);
5077 AT.PolyAct = WORDDIF(poly,term);
5078 while ( r < m ) *poly++ = *r++;
5082 *term = WORDDIF(poly,term);
5105 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5106 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5107 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0, retval = 0;
5108 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5110 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5113 if ( *t != AR.PolyFun ) {
5115 if ( t == w ) { t += t[1]; w = t; }
5116 else { i = t[1]; NCOPY(w,t,i) }
5120 t2 = t + t[1]; t += FUNHEAD;
5122 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5123 else if ( *t != -SNUMBER )
goto NoLegal;
5126 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5127 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5128 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5129 pow1 += t[ARGHEAD+4];
5134 MLOCK(ErrorMessageLock);
5135 MesPrint(
"Illegal term with divergence in PolyRatFun");
5136 MesCall(
"PolyFunMul");
5137 MUNLOCK(ErrorMessageLock);
5141 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5142 else if ( *t != -SNUMBER )
goto NoLegal;
5145 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5146 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5147 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5148 pow1 -= t[ARGHEAD+4];
5152 if ( t == t2 ) pow += pow1;
5156 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5158 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5159 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5160 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5162 else if ( pow == 1 ) {
5163 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5165 else if ( pow < -1 ) {
5166 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5167 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5168 *w++ = 1; *w++ = 1; *w++ = 3;
5170 else if ( pow == -1 ) {
5171 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5174 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5177 *w++ = 1; *w++ = 1; *w++ = 3;
5179 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5183 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5184 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5185 WORD count1 = 0, count2 = 0, count3;
5186 WORD oldtype = AR.SortType;
5187 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5189 if ( *t == AR.PolyFun ) {
5190 if ( t[2] && dirty == 0 ) {
5194 poly_ratfun_normalize(BHEAD term);
5195 if ( term[0] == 0 )
return(0);
5200 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5201 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5202 if ( count3 == 2 ) {
5204 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5207 AR.SortType = SORTHIGHFIRST;
5208 t2 = t + t[1]; tt2 = t+FUNHEAD;
5209 while ( tt2 < t2 ) {
5211 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5213 while ( tt1 < tt2 ) {
5214 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5215 AT.WorkPointer = ww;
5220 ww = w;
while ( *ww ) ww += *ww;
5221 if ( ww-w != *tt4-ARGHEAD ) {
5226 WORD *r1 = TermMalloc(
"PolyFunMul");
5227 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5228 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5229 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5230 i = ww-w; ww = w; NCOPY(r4,ww,i);
5231 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5232 *r1 = i = r4-r1; r4 = term; r3 = r1;
5234 t[1] += ii; t1 += ii; *tt4 += ii;
5236 TermFree(r1,
"PolyFunMul");
5239 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5244 else if ( *tt2 <= -FUNCTION ) tt2++;
5247 AR.SortType = oldtype;
5253 if ( count1 <= 1 ) {
goto checkaction; }
5254 if ( AR.PolyFunExp == 1 ) {
5255 t = term + *term; t -= ABS(t[-1]);
5256 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5259 AR.SortType = SORTHIGHFIRST;
5262 retval = poly_ratfun_normalize(BHEAD term);
5263 if ( *term == 0 )
return(retval);
5264 AR.SortType = oldtype;
5267 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5269 if ( *t == AR.PolyFun ) {
5270 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5271 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5272 if ( count3 == 2 ) {
5278 if ( count1 >= count2 ) {
5281 if ( *t == AR.PolyFun ) {
5284 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5287 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5296 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5298 if ( action ) retval = action;
5302 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5303 AT.WorkPointer = term + *term;
5304 GETSTOP(term,tstop);
5306 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5307 while ( t < tstop && *t == AR.PolyFun ) {
5308 if ( t[1] > FUNHEAD ) {
5309 if ( t[FUNHEAD] < 0 ) {
5310 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5311 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5312 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5319 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5324 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5327 while ( t < tstop && *t == AR.PolyFun ) {
5328 if ( t[1] > FUNHEAD ) {
5329 if ( t[FUNHEAD] < 0 ) {
5330 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5331 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5332 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5339 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5344 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5352 n1 = 1; arg1 = AT.WorkPointer;
5353 ToGeneral(t,arg1,1);
5354 AT.WorkPointer = arg1 + *arg1;
5358 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5359 while ( t < t1 ) { n1++; t += *t; }
5363 n2 = 1; arg2 = AT.WorkPointer;
5364 ToGeneral(t,arg2,1);
5365 AT.WorkPointer = arg2 + *arg2;
5369 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5370 while ( t < t2 ) { n2++; t += *t; }
5382 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5389 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5391 if ( minp1 > 0 ) minp1 = 0;
5393 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5394 if ( minp1 > 0 ) minp1 = 0;
5397 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5398 if ( t1[4] < minp1 ) minp1 = t1[4];
5401 MesPrint(
"Illegal term in expanded polyratfun.");
5407 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5409 if ( minp2 > 0 ) minp2 = 0;
5411 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5412 if ( minp2 > 0 ) minp2 = 0;
5415 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5416 if ( t2[4] < minp2 ) minp2 = t2[4];
5419 MesPrint(
"Illegal term in expanded polyratfun.");
5424 AR.PolyFunPow += minp1+minp2;
5426 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5427 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5432 while ( t < tt1 ) *m++ = *t++;
5435 while ( t < tt2 ) *m++ = *t++;
5436 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5441 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5442 l3 = REDLENG(m[-1]);
5446 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5448 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5450 if ( l4 == 0 )
continue;
5453 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5455 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5464 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5466 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5469 if ( l3 == 0 )
continue;
5479 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5480 AR.PolyFunPow = OldPolyFunPow;
5487 while ( *t ) t += *t;
5491 while ( t1 < fun1 ) *t++ = *t1++;
5494 *t++ = FUNHEAD+ARGHEAD+n1;
5501 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5502 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5503 else t2[FUNHEAD] = FUNHEAD+1;
5506 t1 = fun1 + fun1[1];
5507 while ( t1 < fun2 ) *t++ = *t1++;
5508 t1 = fun2 + fun2[1];
5510 while ( t1 < t2 ) *t++ = *t1++;
5511 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5512 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5513 MLOCK(ErrorMessageLock);
5514 MesPrint(
"Term too complex. Maybe increasing MaxTermSize can help");
5517 m = term; t = AT.WorkPointer;
5522 AT.WorkPointer = term + *term;
5523 if ( action && noac ) {
5524 if ( Normalize(BHEAD term) )
goto PolyCall;
5525 AT.WorkPointer = term + *term;
5529 MLOCK(ErrorMessageLock);
5531 AR.PolyFunPow = OldPolyFunPow;
5532 MesCall(
"PolyFunMul");
5533 MUNLOCK(ErrorMessageLock);
WORD Compare1(WORD *, WORD *, WORD)
WORD CompareSymbols(WORD *, WORD *, WORD)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
WORD InFunction(PHEAD WORD *, WORD *)
WORD PrepPoly(PHEAD WORD *, WORD)
int SymbolNormalize(WORD *)
WORD PolyFunMul(PHEAD WORD *)
WORD PF_Deferred(WORD *term, WORD level)
int PF_InParallelProcessor(void)
WORD InsertTerm(PHEAD WORD *, WORD, WORD, WORD *, WORD *, WORD)
WORD FiniTerm(PHEAD WORD *, WORD *, WORD *, WORD, WORD)
WORD StoreTerm(PHEAD WORD *)
WORD TestMatch(PHEAD WORD *, WORD *)
WORD DoOnePow(PHEAD WORD *, WORD, WORD, WORD *, WORD *, WORD, WORD *)
LONG PasteFile(PHEAD WORD, WORD *, POSITION *, WORD **, RENUMBER, WORD *, WORD)
WORD Deferred(PHEAD WORD *, WORD)
WORD PutOut(PHEAD WORD *, POSITION *, FILEHANDLE *, WORD)
WORD TestSub(PHEAD WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
WORD * PasteTerm(PHEAD WORD, WORD *, WORD *, WORD, WORD)
WORD FlushOut(POSITION *, FILEHANDLE *, int)
int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression)
LONG EndSort(PHEAD WORD *, int)
int PF_BroadcastRHS(void)