67 WORD *term, *t, i, retval = 0;
70 WORD last, LastExpression;
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;
109 MesPrint(
"Status at the start of Processor (HideLevel = %d)",AC.HideLevel);
110 for ( i = 0; i < NumExpressions; i++ ) {
120 for ( i = NumExpressions-1; i >= 0; i-- ) {
122 if ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION
123 || e->status == HIDELEXPRESSION || e->status == HIDEGEXPRESSION
124 || e->status == SKIPLEXPRESSION || e->status == SKIPGEXPRESSION
125 || e->status == UNHIDELEXPRESSION || e->status == UNHIDEGEXPRESSION
126 || e->status == INTOHIDELEXPRESSION || e->status == INTOHIDEGEXPRESSION
130 for ( i = NumExpressions-1; i >= 0; i-- ) {
131 AS.OldOnFile[i] = Expressions[i].onfile;
132 AS.OldNumFactors[i] = Expressions[i].numfactors;
134 AS.Oldvflags[i] = Expressions[i].vflags;
135 Expressions[i].vflags &= ~(ISUNMODIFIED|ISZERO);
143 if ( AC.partodoflag && AM.totalnumberofthreads > 1 ) {
144 AS.MultiThreaded = 1; AC.mparallelflag = PARALLELFLAG;
146 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
156 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
157 if ( InParallelProcessor() ) {
160 AS.MultiThreaded = OldMultiThreaded;
161 AC.mparallelflag = Oldmparallelflag;
165 if ( AC.RhsExprInModuleFlag && PF.rhsInParallel && AC.mparallelflag == PARALLELFLAG ) {
171 if ( AC.partodoflag > 0 ) {
177 for ( i = 0; i < NumExpressions; i++ ) {
180 if ( AC.partodoflag > 0 && e->partodo > 0 && AM.totalnumberofthreads > 2 ) {
186 if ( AC.partodoflag > 0 && e->partodo > 0 && PF.numtasks > 2 ) {
191 AS.CollectOverFlag = 0;
193 if ( i == last ) LastExpression = 1;
194 else LastExpression = 0;
204 SetScratch(AR.infile,&(e->onfile));
205 if ( GetTerm(BHEAD term) <= 0 ) {
206 MesPrint(
"(1) Expression %d has problems in scratchfile",i);
212 SeekScratch(AR.outfile,&position);
213 e->onfile = position;
214 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
215 AR.DeferFlag = AC.ComDefer;
220 for ( j = 0; j < *t; j++ ) term[j] = t[j];
222 AN.ninterms++; dd = AN.deferskipped;
223 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
224 if ( GetMoreFromMem(term,&t) ) {
228 AT.WorkPointer = term + *term;
229 AN.RepPoint = AT.RepCount + 1;
230 AN.IndDum = AM.IndDum;
231 AR.CurDum = ReNumber(BHEAD term);
232 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
234 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
235 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
243 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
244 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
245 else e->vflags |= ISZERO;
246 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
247 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
248 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
256 switch ( e->status ) {
257 case UNHIDELEXPRESSION:
258 case UNHIDEGEXPRESSION:
261 if ( PF.me == MASTER ) SetScratch(AR.hidefile,&(e->onfile));
263 SetScratch(AR.hidefile,&(e->onfile));
264 AR.InHiBuf = AR.hidefile->POfull-AR.hidefile->POfill;
266 MesPrint(
"Hidefile: onfile: %15p, POposition: %15p, filesize: %15p",&(e->onfile)
267 ,&(AR.hidefile->POposition),&(AR.hidefile->filesize));
268 MesPrint(
"Set hidefile to buffer position %l/%l; AR.InHiBuf = %l" 269 ,(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD)
270 ,(AR.hidefile->POfull-AR.hidefile->PObuffer)*
sizeof(WORD)
275 curfile = AR.hidefile;
277 case INTOHIDELEXPRESSION:
278 case INTOHIDEGEXPRESSION:
280 AR.hidefile->POfill = AR.hidefile->POfull;
281 case LOCALEXPRESSION:
282 case GLOBALEXPRESSION:
286 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
288 SetScratch(AR.infile,&(e->onfile));
294 MesPrint(
"Error in PF_Processor");
298 if ( AC.mparallelflag != PARALLELFLAG ){
303 if ( GetTerm(BHEAD term) <= 0 ) {
305 MesPrint(
"Error condition 1a");
308 MesPrint(
"(2) Expression %d has problems in scratchfile(process)",i);
313 if ( AR.outtohide ) {
314 SeekScratch(AR.hidefile,&position);
315 e->onfile = position;
316 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
319 SeekScratch(AR.outfile,&position);
320 e->onfile = position;
321 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
323 AR.DeferFlag = AC.ComDefer;
325 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
327 AT.BrackBuf = AM.BracketFactors;
328 AT.bracketindexflag = 1;
330 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
332 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
333 if ( ThreadsProcessor(e,LastExpression) ) {
334 MesPrint(
"Error in ThreadsProcessor");
337 if ( AR.outtohide ) {
338 AR.outfile = oldoutfile;
339 AR.hidefile->POfull = AR.hidefile->POfill;
346 AR.MaxDum = AM.IndDum;
348 while ( GetTerm(BHEAD term) ) {
349 SeekScratch(curfile,&position);
350 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
354 AN.ninterms++; dd = AN.deferskipped;
355 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
356 if ( GetMoreTerms(term) < 0 ) {
359 SeekScratch(curfile,&position);
361 AT.WorkPointer = term + *term;
362 AN.RepPoint = AT.RepCount + 1;
363 if ( AR.DeferFlag ) {
364 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
365 AR.CurDum = AN.IndDum;
368 AN.IndDum = AM.IndDum;
369 AR.CurDum = ReNumber(BHEAD term);
371 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
373 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
374 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
376 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
377 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
378 PolyFunClean(BHEAD term);
385 SetScratch(curfile,&position);
386 if ( AR.GetFile == 2 ) {
387 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
388 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
391 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
392 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
396 if ( LastExpression ) {
398 if ( AR.infile->handle >= 0 ) {
399 CloseFile(AR.infile->handle);
400 AR.infile->handle = -1;
401 remove(AR.infile->name);
402 PUTZERO(AR.infile->POposition);
404 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
406 if ( AR.outtohide ) AR.outfile = AR.hidefile;
407 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
408 if ( AR.outtohide ) {
409 AR.outfile = oldoutfile;
410 AR.hidefile->POfull = AR.hidefile->POfill;
412 e->numdummies = AR.MaxDum - AM.IndDum;
415 AR.BracketOn = oldBracketOn;
416 AT.BrackBuf = oldBrackBuf;
417 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
418 poly_factorize_expression(e);
420 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
421 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
422 poly_unfactorize_expression(e);
424 AT.bracketindexflag = oldbracketindexflag;
425 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
426 else e->vflags |= ISZERO;
427 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
428 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
429 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
437 if ( e->status == INTOHIDELEXPRESSION ||
438 e->status == INTOHIDEGEXPRESSION ) {
443 case SKIPLEXPRESSION:
444 case SKIPGEXPRESSION:
449 if ( PF.me != MASTER )
break;
452 SetScratch(AR.infile,&(e->onfile));
453 if ( GetTerm(BHEAD term) <= 0 ) {
455 MesPrint(
"Error condition 1b");
458 MesPrint(
"(3) Expression %d has problems in scratchfile",i);
464 SeekScratch(AR.outfile,&position);
465 e->onfile = position;
466 *AM.S0->sBuffer = 0; firstterm = -1;
468 WORD *oldipointer = AR.CompressPointer;
469 WORD *comprtop = AR.ComprTop;
470 AR.ComprTop = AM.S0->sTop;
471 AR.CompressPointer = AM.S0->sBuffer;
472 if ( firstterm > 0 ) {
473 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
475 else if ( firstterm < 0 ) {
476 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
480 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
483 AR.CompressPointer = oldipointer;
484 AR.ComprTop = comprtop;
485 }
while ( GetTerm(BHEAD term) );
486 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
489 case HIDELEXPRESSION:
490 case HIDEGEXPRESSION:
492 if ( PF.me != MASTER )
break;
495 SetScratch(AR.infile,&(e->onfile));
496 if ( GetTerm(BHEAD term) <= 0 ) {
498 MesPrint(
"Error condition 1c");
501 MesPrint(
"(4) Expression %d has problems in scratchfile",i);
507 SetEndHScratch(AR.hidefile,&position);
508 e->onfile = position;
510 if ( AR.hidefile->handle >= 0 ) {
514 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
515 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
516 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
517 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
519 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
522 *AM.S0->sBuffer = 0; firstterm = -1;
523 cbo = cpo = AM.S0->sBuffer;
525 WORD *oldipointer = AR.CompressPointer;
526 WORD *oldibuffer = AR.CompressBuffer;
527 WORD *comprtop = AR.ComprTop;
528 AR.ComprTop = AM.S0->sTop;
529 AR.CompressPointer = cpo;
530 AR.CompressBuffer = cbo;
531 if ( firstterm > 0 ) {
532 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
534 else if ( firstterm < 0 ) {
535 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
539 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
542 cpo = AR.CompressPointer;
543 cbo = AR.CompressBuffer;
544 AR.CompressPointer = oldipointer;
545 AR.CompressBuffer = oldibuffer;
546 AR.ComprTop = comprtop;
547 }
while ( GetTerm(BHEAD term) );
549 if ( AR.hidefile->handle >= 0 ) {
553 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
554 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
555 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
556 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
558 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
561 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
562 AR.hidefile->POfull = AR.hidefile->POfill;
564 if ( AR.hidefile->handle >= 0 ) {
568 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
569 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
570 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
571 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
573 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
584 if ( e->status == HIDELEXPRESSION ) {
585 e->status = HIDDENLEXPRESSION;
586 AS.OldOnFile[i] = e->onfile;
587 AS.OldNumFactors[i] = Expressions[i].numfactors;
589 if ( e->status == HIDEGEXPRESSION ) {
590 e->status = HIDDENGEXPRESSION;
591 AS.OldOnFile[i] = e->onfile;
592 AS.OldNumFactors[i] = Expressions[i].numfactors;
599 case DROPPEDEXPRESSION:
600 case DROPLEXPRESSION:
601 case DROPGEXPRESSION:
602 case DROPHLEXPRESSION:
603 case DROPHGEXPRESSION:
604 case STOREDEXPRESSION:
605 case HIDDENLEXPRESSION:
606 case HIDDENGEXPRESSION:
614 AT.WorkPointer = term;
616 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
617 for ( i = 0; i < NumExpressions; i++ ) {
624 AT.WorkPointer = term;
625 if ( AM.tracebackflag ) MesCall(
"Processor");
658 WORD *m, *t, *r, retvalue, funflag, j, oldncmod, nexpr;
659 WORD *stop, *t1, *t2, funnum, wilds, tbufnum;
661 CBUF *C = cbuf+AT.ebufnum;
664 VOID *oldcompareroutine = AR.CompareRoutine;
667 AT.TMbuff = AM.rbufnum;
674 if ( *t == SUBEXPRESSION ) {
684 #ifdef WHICHSUBEXPRESSION 686 WORD *tmin = t, AN.nbino;
690 if ( AN.BinoScrat == 0 ) {
691 AN.BinoScrat = (UWORD *)Malloc1((AM.MaxTal+2)*
sizeof(UWORD),
"GetBinoScrat");
696 while ( AN.subsubveto == 0 &&
697 *r == SUBEXPRESSION && r < m && r[3] ) {
698 #ifdef WHICHSUBEXPRESSION 701 if ( r[1] == t[1] && r[2] == t[2] && r[4] == t[4] ) {
702 j = t[1] - SUBEXPSIZE;
705 while ( j > 0 && *t1++ == *t2++ ) j--;
713 while ( t1 < t2 ) *r++ = *t1++;
721 while ( t1 < t2 ) *r++ = *t1++;
726 #ifdef WHICHSUBEXPRESSION 728 else if ( t[2] >= 0 ) {
734 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
735 if ( AN.last3 > minval ) {
736 minval = AN.last3; tmin = t;
740 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
743 minval = mm; tmin = t;
746 else if ( t[3] > 0 ) {
747 if ( mm > MAXPOSITIVE )
goto TooMuch;
748 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
749 if ( AN.nbino > 2 )
goto TooMuch;
750 if ( AN.nbino == 2 ) {
751 mm = AN.BinoScrat[1];
752 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
754 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
757 minval = mm; tmin = t;
767 #ifdef WHICHSUBEXPRESSION 768 if ( mnum1 > 1 && t[2] >= 0 ) {
772 if ( AN.last1 == t[3] && AN.last2 == cbuf[t[4]].NumTerms[t[2]] + t[3] - 1 ) {
773 if ( AN.last3 > minval ) {
774 minval = AN.last3; tmin = t;
778 AN.last1 = t[3]; mm = AN.last2 = cbuf[t[4]].NumTerms[t[2]] + t[3] - 1;
781 minval = mm; tmin = t;
784 else if ( t[3] > 0 ) {
785 if ( mm > MAXPOSITIVE ) {
790 MLOCK(ErrorMessageLock);
791 MesPrint(
"Attempt to generate more terms than FORM can count");
792 MUNLOCK(ErrorMessageLock);
795 GetBinom(AN.BinoScrat,&AN.nbino,(WORD)mm,t[3]);
796 if ( AN.nbino > 2 )
goto TooMuch;
797 if ( AN.nbino == 2 ) {
798 mm = AN.BinoScrat[1];
799 mm = ( mm << BITSINWORD ) + AN.BinoScrat[0];
801 else if ( AN.nbino == 1 ) mm = AN.BinoScrat[0];
804 minval = mm; tmin = t;
813 AR.TePos = WORDDIF(t,term);
815 if ( t[4] == AM.dbufnum && (t+t[1]) < m && t[t[1]] == DOLLAREXPR2 ) {
816 if ( t[t[1]+2] < 0 ) AT.TMdolfac = -t[t[1]+2];
818 AT.TMdolfac = GetDolNum(BHEAD t+t[1],m)+1;
821 else AT.TMdolfac = 0;
824 AR.TePos = WORDDIF(t,term);
838 else if ( *t == EXPRESSION ) {
843 AR.TePos = WORDDIF(t,term);
847 toTMaddr = m = AT.WorkPointer;
862 if ( *t == FROMBRAC ) {
863 WORD *ttstop,*tttstop;
870 AN.Frozen = m = AT.WorkPointer;
878 j = *t; tttstop = t + j;
881 while ( t < ttstop ) {
882 if ( *t == SUBEXPRESSION )
break;
883 if ( *t >= FUNCTION && ( ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) )
break;
884 j = t[1]; NCOPY(m,t,j);
892 while ( t < tttstop ) *m++ = *t++;
893 *AT.WorkPointer = m-AT.WorkPointer;
895 AT.WorkPointer = m + *m;
900 if (
EndSort(BHEAD m,0) < 0 )
goto EndTest;
903 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
905 else if ( m[*m] != 0 ) {
906 MLOCK(ErrorMessageLock);
907 MesPrint(
"Bracket specification in expression should be one single term");
908 MUNLOCK(ErrorMessageLock);
914 *m++ = 1; *m++ = 1; *m++ = 3;
915 *AN.Frozen = m - AN.Frozen;
919 while ( t < tttstop ) *m++ = *t++;
920 *AT.WorkPointer = m-AT.WorkPointer;
922 AT.WorkPointer = m + *m;
923 if ( Normalize(BHEAD m) ) {
924 MLOCK(ErrorMessageLock);
925 MesPrint(
"Error while picking up contents of bracket");
926 MUNLOCK(ErrorMessageLock);
930 *m++ = 4; *m++ = 1; *m++ = 1; *m++ = 3;
942 AT.TMaddr = toTMaddr;
945 else if ( *t >= FUNCTION ) {
946 if ( t[0] == EXPONENT ) {
947 if ( t[1] == FUNHEAD+4 && t[FUNHEAD] == -SYMBOL &&
948 t[FUNHEAD+2] == -SNUMBER && t[FUNHEAD+3] < MAXPOWER
949 && t[FUNHEAD+3] > -MAXPOWER ) {
957 while ( m < r ) *t++ = *m++;
958 *term = WORDDIF(t,term);
961 else if ( t[1] == FUNHEAD+ARGHEAD+11 && t[FUNHEAD] == ARGHEAD+9
962 && t[FUNHEAD+ARGHEAD] == 9 && t[FUNHEAD+ARGHEAD+1] == DOTPRODUCT
963 && t[FUNHEAD+ARGHEAD+8] == 3
964 && t[FUNHEAD+ARGHEAD+7] == 1
965 && t[FUNHEAD+ARGHEAD+6] == 1
966 && t[FUNHEAD+ARGHEAD+5] == 1
967 && t[FUNHEAD+ARGHEAD+9] == -SNUMBER
968 && t[FUNHEAD+ARGHEAD+10] < MAXPOWER
969 && t[FUNHEAD+ARGHEAD+10] > -MAXPOWER ) {
972 t[2] = t[FUNHEAD+ARGHEAD+3];
973 t[3] = t[FUNHEAD+ARGHEAD+4];
974 t[4] = t[FUNHEAD+ARGHEAD+10];
976 m = t + FUNHEAD+ARGHEAD+11;
978 while ( m < r ) *t++ = *m++;
979 *term = WORDDIF(t,term);
984 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
985 if ( *t == EXPONENT ) {
991 if ( *r == -SNUMBER && r[1] < MAXPOWER && r+2 == t+t[1] &&
992 t[FUNHEAD] > -FUNCTION && ( t[FUNHEAD] != -SNUMBER
993 || t[FUNHEAD+1] != 0 ) && t[FUNHEAD] != ARGHEAD ) {
995 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
996 MLOCK(ErrorMessageLock);
997 MesPrint(
"Encountered 0^0. Fatal error.");
998 MUNLOCK(ErrorMessageLock);
1011 t1 = AddRHS(AT.ebufnum,1);
1015 i = t[FUNHEAD] - ARGHEAD;
1016 while ( (t1 + i + 10) > C->
Top )
1017 t1 = DoubleCbuffer(AT.ebufnum,t1);
1018 while ( --i >= 0 ) *t1++ = *m++;
1021 if ( (t1 + 20) > C->
Top )
1022 t1 = DoubleCbuffer(AT.ebufnum,t1);
1027 C->
rhs[C->numrhs+1] = t1;
1033 *t++ = SUBEXPRESSION;
1039 Important: we may not have enough spots here
1044 do { *t++ = *r++; }
while ( r < m );
1045 *term -= WORDDIF(r,t);
1050 else if ( *t == SUMF1 || *t == SUMF2 ) {
1062 WORD *tstop, lcounter, lcmin, lcmax, lcinc;
1065 if ( r+6 < tstop && r[2] == -SNUMBER && r[4] == -SNUMBER
1066 && ( ( r[0] == -SYMBOL )
1067 || ( r[0] == -INDEX && r[1] >= AM.OffsetIndex
1068 && r[3] >= 0 && r[3] < AM.OffsetIndex
1069 && r[5] >= 0 && r[5] < AM.OffsetIndex ) ) ) {
1070 lcounter = r[0] == -INDEX ? -r[1]: r[1];
1074 if ( *r == -SNUMBER && r+2 < tstop ) {
1079 if ( r < tstop && ( ( *r > 0 && (r+*r) == tstop )
1080 || ( *r <= -FUNCTION && r+1 == tstop )
1081 || ( *r > -FUNCTION && *r < 0 && r+2 == tstop ) ) ) {
1082 m = AddRHS(AT.ebufnum,1);
1086 while ( (m + i + 10) > C->
Top )
1087 m = DoubleCbuffer(AT.ebufnum,m);
1088 while ( --i >= 0 ) *m++ = *r++;
1091 while ( (m + 20) > C->
Top )
1092 m = DoubleCbuffer(AT.ebufnum,m);
1097 C->
rhs[C->numrhs+1] = m;
1101 if ( *t == SUMF1 ) *m++ = SUMNUM1;
1102 else *m++ = SUMNUM2;
1108 r = C->
rhs[C->numrhs];
1115 if ( *r >= (SUBEXPSIZE+4)
1116 && ABS(*(r+*r-1)) < (*r - 1)
1117 && r[1] == SUBEXPRESSION ) {
1120 *t++ = *r++; *t++ = *r++; *t++ = C->numrhs;
1121 r++; *t++ = *r++; *t++ = AT.ebufnum; r++;
1122 while ( --i >= 0 ) *t++ = *r++;
1125 *t++ = SUBEXPRESSION;
1126 *t++ = 4+SUBEXPSIZE;
1131 if ( lcounter < 0 ) {
1144 while ( m < t2 ) *t++ = *m++;
1145 *term = WORDDIF(t,term);
1146 AN.TeInFun = -C->numrhs;
1149 AT.TMbuff = AT.ebufnum;
1154 if ( functions[funnum-FUNCTION].spec == 0
1155 || ( t[2] & DIRTYFLAG ) != 0 ) funflag = 1;
1156 if ( *t <= MAXBUILTINFUNCTION ) {
1157 if ( *t == THETA || *t == THETA2 ) {
1158 WORD *tstop, *tt2, kk;
1161 while ( tt2 < tstop ) {
1162 if ( *tt2 > 0 && tt2[1] != 0 ) {
1168 if ( !AT.RecFlag ) {
1169 if ( ( kk = DoTheta(BHEAD t) ) == 0 ) {
1173 else if ( kk > 0 ) {
1176 while ( m < r ) *t++ = *m++;
1177 *term = WORDDIF(t,term);
1182 else if ( *t == DELTA2 || *t == DELTAP ) {
1183 WORD *tstop, *tt2, kk;
1186 while ( tt2 < tstop ) {
1187 if ( *tt2 > 0 && tt2[1] != 0 ) {
1193 if ( !AT.RecFlag ) {
1194 if ( ( kk = DoDelta(t) ) == 0 ) {
1198 else if ( kk > 0 ) {
1201 while ( m < r ) *t++ = *m++;
1202 *term = WORDDIF(t,term);
1207 else if ( *t == DISTRIBUTION && t[FUNHEAD] == -SNUMBER
1208 && t[FUNHEAD+1] >= -2 && t[FUNHEAD+1] <= 2
1209 && t[FUNHEAD+2] == -SNUMBER
1210 && t[FUNHEAD+4] <= -FUNCTION
1211 && t[FUNHEAD+5] <= -FUNCTION ) {
1217 else if ( *t == DELTA3 && ((t[1]-FUNHEAD) & 1 ) == 0 ) {
1223 else if ( ( *t == TABLEFUNCTION ) && ( t[FUNHEAD] <= -FUNCTION )
1224 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1225 && ( t[1] >= FUNHEAD+1+2*T->
numind )
1226 && ( t[FUNHEAD+1] == -SYMBOL ) ) {
1230 for ( isp = 0; isp < T->
numind; isp++ ) {
1231 if ( t[FUNHEAD+1+2*isp] != -SYMBOL )
break;
1233 if ( isp >= T->
numind ) {
1240 else if ( *t == TABLEFUNCTION && t[FUNHEAD] <= -FUNCTION
1241 && ( T = functions[-t[FUNHEAD]-FUNCTION].tabl ) != 0
1242 && ( t[1] == FUNHEAD+2 )
1243 && ( t[FUNHEAD+1] <= -FUNCTION ) ) {
1252 else if ( *t == FACTORIN ) {
1253 if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -DOLLAREXPRESSION ) {
1259 else if ( t[1] == FUNHEAD+2 && t[FUNHEAD] == -EXPRESSION ) {
1266 else if ( *t == TERMSINBRACKET ) {
1267 if ( t[1] == FUNHEAD || (
1269 && t[FUNHEAD] == -SNUMBER
1270 && t[FUNHEAD+1] == 0
1310 else if ( *t == EXTRASYMFUN ) {
1311 if ( t[1] == FUNHEAD+2 && (
1312 ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] <= cbuf[AM.sbufnum].numrhs
1313 && t[FUNHEAD+1] > 0 ) ||
1314 ( t[FUNHEAD] == -SYMBOL && t[FUNHEAD+1] < MAXVARIABLES
1315 && t[FUNHEAD+1] >= MAXVARIABLES-cbuf[AM.sbufnum].numrhs ) ) ) {
1321 else if ( t[1] == FUNHEAD ) {
1328 else if ( *t == GCDFUNCTION ) {
1332 while ( tf < t + t[1] ) {
1333 if ( *tf > 0 && tf[1] != 0 ) todo = 0;
1343 else if ( *t == DIVFUNCTION || *t == REMFUNCTION || *t == INVERSEFUNCTION ) {
1345 int todo = 1, numargs = 0;
1347 while ( tf < t + t[1] ) {
1349 if ( *tf > 0 && tf[1] != 0 ) todo = 0;
1352 if ( todo && numargs == 2 ) {
1353 if ( *t == DIVFUNCTION ) AN.TeInFun = -9;
1354 else if ( *t == REMFUNCTION ) AN.TeInFun = -10;
1355 else if ( *t == INVERSEFUNCTION ) AN.TeInFun = -11;
1368 AT.NestPoin->termsize = t;
1369 if ( AT.NestPoin == AT.Nest ) AN.EndNest = t + *t;
1371 oldncmod = AN.ncmod;
1373 if ( *t < FUNCTION ) {
1374 t += t[1];
continue;
1376 if ( AN.ncmod && ( ( AC.modmode & ALSOFUNARGS ) == 0 ) ) {
1377 if ( *t != AR.PolyFun ) AN.ncmod = 0;
1378 else AN.ncmod = oldncmod;
1382 if ( *t >= FUNCTION + WILDOFFSET ) funnum -= WILDOFFSET;
1383 if ( ( *t == NUMFACTORS || *t == FIRSTTERM || *t == CONTENTTERM )
1384 && t[1] == FUNHEAD+2 &&
1385 ( t[FUNHEAD] == -EXPRESSION || t[FUNHEAD] == -DOLLAREXPRESSION ) ) {
1392 else if ( functions[funnum-FUNCTION].spec == 0 ) {
1393 AT.NestPoin->funsize = t + 1;
1397 if ( *t > 0 && t[1] ) {
1398 AT.NestPoin->argsize = t;
1403 while ( t < AT.NestPoin[-1].argsize+*(AT.NestPoin[-1].argsize) ) {
1415 if ( ( retvalue =
TestSub(BHEAD t,level) ) != 0 ) {
1436 AN.ncmod = oldncmod;
1449 t = AT.NestPoin->argsize;
1453 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1456 if ( AT.WorkPointer < term + *term )
1457 AT.WorkPointer = term + *term;
1459 while ( t < AT.NestPoin->argsize+*(AT.NestPoin->argsize) ) {
1462 do { *m++ = *t++; }
while ( t < r );
1464 AT.WorkPointer = r + *r;
1465 if ( Normalize(BHEAD r) ) {
1468 if ( AN.ncmod != 0 ) {
1480 if (
EndSort(BHEAD AT.WorkPointer+ARGHEAD,0) < 0 )
goto EndTest;
1481 m = AT.WorkPointer+ARGHEAD;
1482 if ( *t1 == AR.PolyFun && AR.PolyFunType == 2 ) {
1483 AR.CompareRoutine = oldcompareroutine;
1485 while ( *m ) m += *m;
1486 i = WORDDIF(m,AT.WorkPointer);
1487 *AT.WorkPointer = i;
1488 AT.WorkPointer[1] = 0;
1489 if ( ToFast(AT.WorkPointer,AT.WorkPointer) ) {
1491 if ( *m <= -FUNCTION ) { m++; i = 1; }
1492 else { m += 2; i = 2; }
1497 if ( r > AT.WorkTop ) {
1498 MLOCK(ErrorMessageLock);
1502 do { *--r = *--m; }
while ( m > AT.WorkPointer );
1506 stop = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1507 do { *--r = *--m; }
while ( m >= stop );
1510 m = AT.NestPoin->argsize+*(AT.NestPoin->argsize);
1512 do { *r++ = *m++; }
while ( m < AN.EndNest );
1514 m = AT.NestPoin->argsize;
1516 while ( --i >= 0 ) *m++ = *r++;
1518 while ( n <= AT.NestPoin ) {
1519 if ( *(n->argsize) > 0 && n != AT.NestPoin )
1522 *(n->termsize) += j;
1527 if ( funnum == DENOMINATOR || funnum == EXPONENT ) {
1528 if ( Normalize(BHEAD term) ) {
1538 AN.ncmod = oldncmod;
1545 AN.ncmod = oldncmod;
1548 else if ( *t == -DOLLAREXPRESSION ) {
1549 if ( *t1 == TERMSINEXPR && t1[1] == FUNHEAD+2 ) {}
1551 if ( AR.Eside != LHSIDE ) {
1552 AN.TeInFun = 1; AR.TePos = 0;
1553 AT.TMbuff = AM.dbufnum; t1[2] |= DIRTYFLAG;
1554 AN.ncmod = oldncmod;
1557 AC.lhdollarflag = 1;
1560 else if ( *t == -TERMSINBRACKET ) {
1561 if ( AR.Eside != LHSIDE ) {
1562 AN.TeInFun = 1; AR.TePos = 0;
1564 AN.ncmod = oldncmod;
1568 else if ( AN.ncmod != 0 && *t == -SNUMBER ) {
1569 if ( AN.ncmod == 1 || AN.ncmod == -1 ) {
1570 isp = (UWORD)(AC.cmod[0]);
1572 if ( ( AC.modmode & POSNEG ) != 0 ) {
1573 if ( isp > (UWORD)(AC.cmod[0])/2 ) isp = isp - (UWORD)(AC.cmod[0]);
1574 else if ( -isp > (UWORD)(AC.cmod[0])/2 ) isp = isp + (UWORD)(AC.cmod[0]);
1577 if ( isp < 0 ) isp += (UWORD)(AC.cmod[0]);
1579 if ( isp <= MAXPOSITIVE && isp >= -MAXPOSITIVE ) {
1586 if ( funnum >= FUNCTION && functions[funnum-FUNCTION].tabl ) {
1592 WORD rhsnumber, *oldwork = AT.WorkPointer, *Tpattern;
1595 T = functions[funnum-FUNCTION].tabl;
1605 Tpattern = T->
pattern[AT.identity];
1609 p = Tpattern + FUNHEAD+1;
1614 for ( i = 0; i < T->
numind; i++, t += 2 ) {
1615 if ( *t != -SNUMBER )
break;
1617 if ( i < T->numind )
goto teststrict;
1619 isp = FindTableTree(T,t1+FUNHEAD,2);
1620 if ( isp < 0 )
goto teststrict;
1622 #if ( TABLEEXTENSION == 2 ) 1629 while ( --ii >= 0 ) {
1630 *p = *t; t += 2; p += 2;
1638 while ( --j >= 0 ) {
1639 if ( *t != -SNUMBER )
goto NextFun;
1641 if ( *t < mm->mini || *t > mm->
maxi ) {
1643 MLOCK(ErrorMessageLock);
1644 MesPrint(
"Table boundary check. Argument %d",
1646 showtable: AO.OutFill = AO.OutputLine = (UBYTE *)m;
1651 MUNLOCK(ErrorMessageLock);
1656 i += ( *t - mm->
mini ) * (LONG)(mm->
size);
1664 i *= TABLEEXTENSION;
1666 teststrict:
if ( T->
strict == -2 ) {
1676 rhsnumber = AM.zerorhs;
1677 tbufnum = AM.zbufnum;
1679 else if ( T->
strict < 0 )
goto NextFun;
1681 MLOCK(ErrorMessageLock);
1682 MesPrint(
"Element in table is undefined");
1688 #if ( TABLEEXTENSION == 2 ) 1704 AN.FullProto = T->
prototype[AT.identity];
1708 AN.WildValue = AN.FullProto + SUBEXPSIZE;
1709 AN.WildStop = AN.FullProto+AN.FullProto[1];
1712 AN.RepFunList = AN.EndNest;
1713 AT.WorkPointer = (WORD *)(((UBYTE *)(AN.EndNest)) + AM.MaxTer/2);
1714 if ( AT.WorkPointer >= AT.WorkTop ) {
1715 MLOCK(ErrorMessageLock);
1717 MUNLOCK(ErrorMessageLock);
1721 if ( MatchFunction(BHEAD Tpattern,t1,&wilds) > 0 ) {
1722 AT.WorkPointer = oldwork;
1723 if ( AT.NestPoin != AT.Nest ) {
1724 AN.ncmod = oldncmod;
1729 retvalue = m[2] = rhsnumber;
1738 while ( r < m ) *t++ = *r++;
1744 while ( t >= r ) { t[j] = *t; t--; }
1755 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
1756 AT.TMbuff = tbufnum;
1757 AN.ncmod = oldncmod;
1760 AT.WorkPointer = oldwork;
1764 else if ( ( t[2] & DIRTYFLAG ) != 0 ) {
1767 if ( *t == FUNNYDOLLAR ) {
1768 if ( AR.Eside != LHSIDE ) {
1771 AT.TMbuff = AM.dbufnum;
1772 AN.ncmod = oldncmod;
1775 AC.lhdollarflag = 1;
1781 AN.ncmod = oldncmod;
1786 MLOCK(ErrorMessageLock);
1789 MUNLOCK(ErrorMessageLock);
1812 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
1813 WORD *u, *v, *w, *from, *to,
1814 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
1818 m = r - ABS(*r) + 1;
1821 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
1824 if ( ( term + AR.TePos ) == t ) {
1826 while ( from < t ) *m++ = *from++;
1828 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
1831 *m++ = t[1] + 4 + ARGHEAD;
1837 while ( t < v ) *m++ = *t++;
1843 while ( t < r ) *m++ = *t++;
1844 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
1845 *termout = WORDDIF(m,termout);
1849 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec == 0 )
1850 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
1855 oldncmod = AN.ncmod;
1857 if ( *t > 0 && t[1] ) {
1861 if ( ( AN.ncmod != 0 )
1862 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
1863 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
1868 while ( from < t ) {
1869 if ( from == u ) w = m;
1874 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
1882 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
1884 AN.ncmod = oldncmod;
1894 if (
EndSort(BHEAD m,1) < 0 ) {
1895 AN.ncmod = oldncmod;
1898 AR.PolyFun = oldPolyFun;
1899 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
1902 while ( *m ) m += *m;
1903 *to = WORDDIF(m,to);
1905 if ( ToFast(to,to) ) {
1906 if ( *to <= -FUNCTION ) m = to+1;
1909 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
1912 while ( t < r ) *m++ = *t++;
1913 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
1914 *termout = WORDDIF(m,termout);
1915 AR.DeferFlag = olddefer;
1916 AN.ncmod = oldncmod;
1919 else if ( *t == -DOLLAREXPRESSION ) {
1920 if ( AR.Eside == LHSIDE ) {
1922 AC.lhdollarflag = 1;
1930 int nummodopt, dtype = -1;
1931 if ( AS.MultiThreaded ) {
1932 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
1933 if ( t[1] == ModOptdollars[nummodopt].number )
break;
1935 if ( nummodopt < NumModOptdollars ) {
1936 dtype = ModOptdollars[nummodopt].type;
1937 if ( dtype == MODLOCAL ) {
1938 d = ModOptdollars[nummodopt].dstruct+AT.identity;
1941 LOCK(d->pthreadslockread);
1946 oldncmod = AN.ncmod;
1947 if ( ( AN.ncmod != 0 )
1948 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
1949 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
1953 while ( from < t ) {
1954 if ( from == u ) w = m;
1958 switch ( d->type ) {
1960 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
1961 *m++ = -SNUMBER; *m++ = d->index;
1963 else { *m++ = -INDEX; *m++ = d->index; }
1966 *m++ = -SNUMBER; *m++ = 0;
break;
1968 if ( d->where[0] == 4 &&
1969 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
1971 if ( d->where[3] >= 0 ) *m++ = d->where[1];
1972 else *m++ = -d->where[1];
1981 to = m; r = d->where;
1985 i = *r; NCOPY(m,r,i)
1988 if ( ToFast(to,to) ) {
1989 if ( *to <= -FUNCTION ) m = to+1;
1992 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2006 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2007 AR.PolyFun = oldPolyFun;
2016 while ( *m ) m += *m;
2018 if ( ToFast(to,to) ) {
2019 if ( *to <= -FUNCTION ) m = to+1;
2024 w[1] = w[1] - 2 + (m-to);
2027 to = m; r = d->where;
2029 *m++ = i+4+ARGHEAD; *m++ = 1;
2032 while ( --i >= 0 ) *m++ = *r++;
2033 *m++ = 1; *m++ = 1; *m++ = 3;
2034 if ( ToFast(to,to) ) {
2035 if ( *to <= -FUNCTION ) m = to+1;
2038 w[1] = w[1] - 2 + (m-to);
2041 to = m; r = d->where;
2044 *m++ = *r++; *m++ = 1; r++;
2045 while ( --i >= 0 ) *m++ = *r++;
2047 else if ( *r <= -FUNCTION ) *m++ = *r++;
2048 else { *m++ = *r++; *m++ = *r++; }
2049 w[1] = w[1] - 2 + (m-to);
2052 to = m; r = d->where;
2055 while ( --i >= 0 ) {
2057 *m++ = -VECTOR; *m++ = *r++;
2059 else if ( *r >= AM.OffsetIndex ) {
2060 *m++ = -INDEX; *m++ = *r++;
2062 else { *m++ = -SNUMBER; *m++ = *r++; }
2070 *m++ = *r++; *m++ = 1; r++;
2071 while ( --i >= 0 ) *m++ = *r++;
2073 else if ( *r <= -FUNCTION ) *m++ = *r++;
2074 else { *m++ = *r++; *m++ = *r++; }
2077 w[1] = w[1] - 2 + (m-to);
2081 MLOCK(ErrorMessageLock);
2082 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2083 AC.dollarnames->namebuffer+d->name);
2084 MUNLOCK(ErrorMessageLock);
2086 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2091 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2095 while ( t < r ) *m++ = *t++;
2096 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2097 *termout = WORDDIF(m,termout);
2098 AR.DeferFlag = olddefer;
2099 AN.ncmod = oldncmod;
2103 else if ( *t == -TERMSINBRACKET ) {
2104 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2114 while ( from < t ) {
2115 if ( from == u ) w = m;
2118 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2119 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2122 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2124 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2125 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2130 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2131 *m++ = 6; *m++ = numterms & WORDMASK;
2132 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2137 while ( from < r ) *m++ = *from++;
2138 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2139 *termout = WORDDIF(m,termout);
2146 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec )
2147 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2148 u = t; v = t + t[1];
2151 if ( *t == FUNNYDOLLAR ) {
2152 if ( AR.Eside != LHSIDE ) {
2155 int nummodopt, dtype = -1;
2156 if ( AS.MultiThreaded ) {
2157 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2158 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2160 if ( nummodopt < NumModOptdollars ) {
2161 dtype = ModOptdollars[nummodopt].type;
2162 if ( dtype == MODLOCAL ) {
2163 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2166 LOCK(d->pthreadslockread);
2171 oldncmod = AN.ncmod;
2172 if ( ( AN.ncmod != 0 )
2173 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2174 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2176 while ( from < t ) {
2177 if ( from == u ) w = m;
2181 switch ( d->type ) {
2183 *m++ = d->index;
break;
2188 if ( d->where[0] == 4 && d->where[4] == 0
2189 && d->where[3] == 3 && d->where[2] == 1
2190 && d->where[1] < AM.OffsetIndex ) {
2196 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2198 MLOCK(ErrorMessageLock);
2199 MesPrint(
"$%s has wrong type for tensor substitution",
2200 AC.dollarnames->namebuffer+d->name);
2201 MUNLOCK(ErrorMessageLock);
2202 AN.ncmod = oldncmod;
2207 if ( d->where[0] == -INDEX ) {
2208 *m++ = d->where[1];
break;
2210 else if ( d->where[0] == -VECTOR ) {
2211 *m++ = d->where[1];
break;
2213 else if ( d->where[0] == -MINVECTOR ) {
2218 else if ( d->where[0] == -SNUMBER ) {
2219 if ( d->where[1] >= 0
2220 && d->where[1] < AM.OffsetIndex ) {
2221 *m++ = d->where[1];
break;
2226 if ( d->where[0] > 0 ) {
2227 r = d->where; i = *r++;
2228 while ( --i >= 0 ) *m++ = *r++;
2233 if ( *r == -INDEX ) {
2234 *m++ = r[1]; r += 2;
continue;
2236 else if ( *r == -VECTOR ) {
2237 *m++ = r[1]; r += 2;
continue;
2239 else if ( *r == -MINVECTOR ) {
2240 *m++ = r[1]; r += 2;
2241 sign = -sign;
continue;
2243 else if ( *r == -SNUMBER ) {
2245 && r[1] < AM.OffsetIndex ) {
2246 *m++ = r[1]; r += 2;
continue;
2255 if ( *r == INDEX && r[1] == 3 ) {
2258 else goto wrongtype;
2262 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2264 MLOCK(ErrorMessageLock);
2265 MesPrint(
"$%s is undefined in tensor substitution",
2266 AC.dollarnames->namebuffer+d->name);
2267 MUNLOCK(ErrorMessageLock);
2268 AN.ncmod = oldncmod;
2272 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2274 w[1] = w[1] - 2 + (m-to);
2277 while ( from < term ) *m++ = *from++;
2278 if ( sign < 0 ) m[-1] = -m[-1];
2279 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) )
goto TooLarge;
2280 *termout = m - termout;
2281 AN.ncmod = oldncmod;
2285 AC.lhdollarflag = 1;
2294 MLOCK(ErrorMessageLock);
2295 MesPrint(
"Internal error in InFunction: Function not encountered.");
2296 if ( AM.tracebackflag ) {
2297 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2298 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2300 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2304 while ( --i >= 0 ) {
2305 TalToLine((UWORD)(*termout++));
2306 TokenToLine((UBYTE *)
" ");
2310 MesCall(
"InFunction");
2312 MUNLOCK(ErrorMessageLock);
2316 MLOCK(ErrorMessageLock);
2317 MesCall(
"InFunction");
2318 MUNLOCK(ErrorMessageLock);
2322 MLOCK(ErrorMessageLock);
2323 MesPrint(
"Output term too large. Try to increase MaxTermSize in the setup.");
2324 MesCall(
"InFunction");
2325 MUNLOCK(ErrorMessageLock);
2350 WORD
InsertTerm(
PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout,
2354 WORD *m, *t, *r, i, l2, j;
2355 WORD *u, *v, l1, *coef;
2356 coef = AT.WorkPointer;
2357 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2358 MLOCK(ErrorMessageLock);
2360 MUNLOCK(ErrorMessageLock);
2373 if ( *t == SUBEXPRESSION && t[2] == replac && t[3] && t[4] == extractbuff ) {
2375 while ( *r == SUBEXPRESSION && r[2] == replac && r[3] && r < m && r[4] == extractbuff ) {
2382 do { *m++ = *r++; }
while ( r < t );
2383 if ( t[1] > SUBEXPSIZE ) {
2388 if ( ( l2 = WildFill(BHEAD m,position,t) ) < 0 )
goto InsCall;
2392 i = ( j = ABS(l2) ) - 1;
2394 do { *--r = *--m; }
while ( --i > 0 );
2401 r -= ( j = ABS(l2) );
2403 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2407 while ( t < u && *t == DOLLAREXPR2 ) t += t[1];
2408 ComAct:
if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2409 if ( *r == 1 && r[1] == 1 && j == 3 ) {
2410 if ( l2 < 0 ) l1 = -l1;
2416 if ( MulRat(BHEAD (UWORD *)u,REDLENG(l1),(UWORD *)r,REDLENG(l2),
2417 (UWORD *)m,&l1) )
goto InsCall;
2429 *termout = WORDDIF(m,termout);
2430 if ( (*termout)*((LONG)
sizeof(WORD)) > AM.MaxTer )
goto InsCall;
2431 AT.WorkPointer = coef;
2445 do { *m++ = *r++; }
while ( r < t );
2449 r -= ( j = ABS(l2) );
2451 if ( t < r )
do { *m++ = *t++; }
while ( t < r );
2456 MLOCK(ErrorMessageLock);
2457 MesCall(
"InsertTerm");
2458 MUNLOCK(ErrorMessageLock);
2482 RENUMBER renumber, WORD *freeze, WORD nexpr)
2486 WORD *stop, *s1, *s2;
2491 stop = (WORD *)(((UBYTE *)(accum)) + 2*AM.MaxTer);
2493 while ( --number >= 0 ) accum += *accum;
2496 oldipointer = AR.CompressPointer;
2498 AR.CompressPointer = oldipointer;
2500 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 )
2502 if ( !l ) { *accum = 0;
return(0); }
2507 while ( r < m && *r != HAAKJE ) r += r[1];
2509 if ( *freeze != 4 ) l = -1;
2525 *m++ = WORDDIF(s2,r) + 3;
2527 while ( r < s2 ) *m++ = *r++;
2528 *m++ = 1; *m++ = 1; *m++ = 3;
2530 if ( Normalize(BHEAD AT.WorkPointer) )
goto PasErr;
2533 while ( --i >= 0 && *m++ == *r++ ) {}
2543 do { *r++ = *m++; }
while ( m < s1 );
2544 *accum = l = WORDDIF(r,accum);
2548 retlength = InCompState;
2552 if ( ( l = GetFromStore(accum,position,renumber,&InCompState,nexpr) ) < 0 ) {
2553 MLOCK(ErrorMessageLock);
2554 MesCall(
"PasteFile");
2555 MUNLOCK(ErrorMessageLock);
2558 if ( l == 0 ) { *accum = 0;
return(0); }
2559 retlength = InCompState;
2562 if ( accum > stop ) {
2563 MLOCK(ErrorMessageLock);
2564 MesPrint(
"Buffer too small in PasteFile");
2565 MUNLOCK(ErrorMessageLock);
2572 MLOCK(ErrorMessageLock);
2573 MesCall(
"PasteFile");
2574 MUNLOCK(ErrorMessageLock);
2603 WORD *
PasteTerm(
PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby)
2606 WORD *t, *r, x, y, z;
2607 WORD *m, *u, l1, a[2];
2608 m = (WORD *)(((UBYTE *)(accum)) + AM.MaxTer);
2611 while ( --number >= 0 ) accum += *accum;
2612 if ( times == divby ) {
2615 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2623 if ( t < r )
do { *accum++ = *t++; }
while ( t < r );
2624 if ( divby > times ) { x = divby; y = times; }
2625 else { x = times; y = divby; }
2627 while ( z ) { x = y; y = z; z = x%y; }
2628 if ( y != 1 ) { divby /= y; times /= y; }
2631 if ( MulRat(BHEAD (UWORD *)t,REDLENG(l1),(UWORD *)a,1,(UWORD *)accum,&l1) ) {
2632 MLOCK(ErrorMessageLock);
2633 MesCall(
"PasteTerm");
2634 MUNLOCK(ErrorMessageLock);
2639 if ( x < 0 ) { accum -= x; *accum++ = x - 1; }
2640 else { accum += x; *accum++ = x + 1; }
2641 *u = WORDDIF(accum,u);
2644 MLOCK(ErrorMessageLock);
2645 MesPrint(
"Buffer too small in PasteTerm");
2646 MUNLOCK(ErrorMessageLock);
2668 WORD
FiniTerm(
PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos)
2671 WORD *m, *t, *r, i, numacc, l2, ipp;
2672 WORD *u, *v, l1, *coef = AT.WorkPointer, *oldaccum;
2673 if ( ( AT.WorkPointer = coef + 2*AM.MaxTal ) > AT.WorkTop ) {
2674 MLOCK(ErrorMessageLock);
2676 MUNLOCK(ErrorMessageLock);
2685 do { *--r = *--m; }
while ( --i > 0 );
2692 if ( ( ( *t == SUBEXPRESSION && ( *(r=t+t[1]) != SUBEXPRESSION
2693 || r >= m || !r[3] ) ) || *t == EXPRESSION ) && t[2] == number && t[3] ) {
2698 if ( r < t )
do { *m++ = *r++; }
while ( r < t );
2700 if ( numacc >= 0 )
do {
2701 if ( *t == EXPRESSION ) {
2705 if ( *r == WILDCARDS ) {
2708 if ( ( l2 = WildFill(BHEAD m,accum,r) ) < 0 )
goto FiniCall;
2715 else if ( t[1] > SUBEXPSIZE && t[SUBEXPSIZE] != FROMBRAC ) {
2717 if ( ( l2 = WildFill(BHEAD m,accum,t) ) < 0 )
goto FiniCall;
2730 if ( r < v )
do { *m++ = *r++; }
while ( r < v );
2732 if ( *r == 1 && r[1] == 1 && ABS(l2) == 3 ) {
2733 if ( l2 < 0 ) l1 = -l1;
2742 while ( --numacc >= 0 ) {
2744 while ( --i >= 0 ) {
2745 TalToLine((UWORD)(*t++));
2746 TokenToLine((UBYTE *)
" ");
2753 if ( MulRat(BHEAD (UWORD *)coef,l1,(UWORD *)r,l2,(UWORD *)coef,&l1) )
goto FiniCall;
2754 if ( AN.ncmod != 0 && TakeModulus((UWORD *)coef,&l1,AC.cmod,AN.ncmod,UNPACK|AC.modmode) )
goto FiniCall;
2757 }
while ( --numacc >= 0 );
2758 if ( *t == SUBEXPRESSION ) {
2759 while ( t+t[1] < u && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2762 if ( t < u )
do { *m++ = *t++; }
while ( t < u );
2769 if ( *r == SUBEXPRESSION ) {
2771 l1 = (WORD)(cbuf[r[4]].CanCommu[r[2]]);
2773 if ( *t == SUBEXPRESSION &&
2774 t[1] == r[1] && t[2] == r[2] && t[4] == r[4] ) {
2775 i = t[1] - SUBEXPSIZE;
2776 u = r + SUBEXPSIZE; v = t + SUBEXPSIZE;
2778 if ( *v++ != *u++ )
break; i--; }
2783 while ( r < m ) *t++ = *r++;
2788 if ( l1 && cbuf[t[4]].CanCommu[t[2]] )
break;
2789 while ( t+t[1] < m && t[t[1]] == DOLLAREXPR2 ) t += t[1];
2792 if ( *t == SUBEXPRESSION && cbuf[t[4]].CanCommu[t[2]] )
2794 if ( *t >= FUNCTION+WILDOFFSET )
2795 ipp = *t - WILDOFFSET;
2798 && functions[ipp-FUNCTION].commute && l1 )
break;
2799 if ( *t == EXPRESSION )
break;
2812 l2 = ( l2 >= 0 ) ? i: -i;
2814 while ( --i > 0 ) *m++ = *r++;
2816 *termout = WORDDIF(m,termout);
2817 AT.WorkPointer = coef;
2822 AT.WorkPointer = coef;
2826 MLOCK(ErrorMessageLock);
2827 MesCall(
"FiniTerm");
2828 MUNLOCK(ErrorMessageLock);
2837 static WORD zeroDollar[] = { 0, 0 };
2868 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
2869 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, retnorm, extractbuff;
2870 int *RepSto = AN.RepPoint, iscopy = 0;
2871 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum;
2872 LONG posisub, oldcpointer;
2876 int nummodopt, dtype = -1, id;
2878 oldtoprhs = CC->numrhs;
2879 oldcpointer = CC->Pointer - CC->Buffer;
2881 if ( ( replac =
TestSub(BHEAD term,level) ) == 0 ) {
2882 if ( applyflag ) { TableReset(); applyflag = 0; }
2884 if ( ( retnorm = Normalize(BHEAD term) ) != 0 ) {
2885 if ( retnorm > 0 ) {
2886 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
2891 if ( !*term )
goto Return0;
2892 if ( AN.PolyNormFlag ) {
2894 if ( !*term )
goto Return0;
2896 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
2897 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
2900 if ( level > AR.Cnumlhs ) {
2901 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
2903 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
2908 if (
Deferred(BHEAD term,level) )
goto GenCall;
2911 if ( AN.ncmod != 0 ) {
2912 if ( Modulus(term) )
goto GenCall;
2913 if ( !*term )
goto Return0;
2915 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
2916 WORD olddummies = AN.IndDum;
2917 AN.IndDum = AM.IndDum;
2918 ReNumber(BHEAD term); Normalize(BHEAD term);
2919 AN.IndDum = olddummies;
2920 if ( !*term )
goto Return0;
2921 olddummies = DetCurDum(BHEAD term);
2922 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
2924 if ( AR.PolyFun > 0 && AR.sLevel <= 0 ) {
2925 if (
PrepPoly(BHEAD term) != 0 )
goto Return0;
2927 if ( AR.sLevel <= 0 && AR.BracketOn ) {
2928 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
2929 termout = AT.WorkPointer;
2930 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
2931 if ( PutBracket(BHEAD term) )
return(-1);
2932 AN.RepPoint = RepSto;
2933 *AT.WorkPointer = 0;
2935 AT.WorkPointer = termout;
2936 CC->numrhs = oldtoprhs;
2937 CC->Pointer = CC->Buffer + oldcpointer;
2941 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
2942 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
2943 *AT.WorkPointer = 0;
2944 AN.RepPoint = RepSto;
2946 CC->numrhs = oldtoprhs;
2947 CC->Pointer = CC->Buffer + oldcpointer;
2951 i = C->
lhs[level][0];
2952 if ( i >= TYPECOUNT ) {
2958 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
2959 AT.WorkPointer = term + *term;
2964 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
2967 level = AC.Labels[C->
lhs[level][2]];
2970 AT.WorkPointer = term + *term;
2980 WORD ic, jc, *ifcode, *jfcode;
2981 jfcode = C->
lhs[level]; jc = jfcode[1];
2982 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
2983 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
2984 while ( !DoIfStatement(BHEAD ifcode,term) ) {
2985 level = C->
lhs[level][2];
2986 if ( C->
lhs[level][0] != TYPEELIF )
break;
2988 AT.WorkPointer = ifcode;
2991 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
2992 level = C->
lhs[level][2];
2993 if ( C->
lhs[level][0] != TYPEELIF )
break;
2999 level = C->
lhs[level][2];
3000 }
while ( C->
lhs[level][0] == TYPEELIF );
3004 level = C->
lhs[level][2];
3008 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3009 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3010 WORD theindex = C->
lhs[level][2];
3011 if ( theindex < 0 ) {
3014 theindex = -theindex;
3015 d = Dollars + theindex;
3016 if ( AS.MultiThreaded ) {
3017 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3018 if ( theindex == ModOptdollars[nummodopt].number )
break;
3020 if ( nummodopt < NumModOptdollars ) {
3021 ddtype = ModOptdollars[nummodopt].type;
3022 if ( ddtype == MODLOCAL ) {
3023 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3026 LOCK(d->pthreadslockread);
3031 theindex = -theindex;
3032 d = Dollars + theindex;
3035 if ( d->type != DOLINDEX
3036 || d->index < AM.OffsetIndex
3037 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3038 MLOCK(ErrorMessageLock);
3039 MesPrint(
"$%s should have been an index" 3040 ,AC.dollarnames->namebuffer+d->name);
3041 AN.currentTerm = term;
3042 MesPrint(
"Current term: %t");
3043 AN.listinprint = printscratch;
3044 printscratch[0] = DOLLAREXPRESSION;
3045 printscratch[1] = theindex;
3047 ,AC.dollarnames->namebuffer+d->name);
3048 MUNLOCK(ErrorMessageLock);
3050 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3054 theindex = d->index;
3056 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3059 cp[1] = SUBEXPSIZE+4;
3064 i = C->
lhs[level][1] - 3;
3066 AR.CompressPointer = cp;
3067 while ( --i >= 0 ) {
3069 termout = AT.WorkPointer;
3070 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3074 while ( --jlhs >= 0 ) {
3075 if ( *m++ != *termout++ )
break;
3078 termout = AT.WorkPointer;
3079 AT.WorkPointer = termout + *termout;
3080 if (
Generator(BHEAD termout,level) )
goto GenCall;
3081 AT.WorkPointer = termout;
3084 AR.CompressPointer = op;
3088 AR.CompressPointer = op;
3093 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3099 AR.CurDum = DetCurDum(BHEAD term);
3100 i = C->
lhs[level][1]-2;
3101 wp = C->
lhs[level] + 2;
3102 cp[1] = SUBEXPSIZE+4*i;
3104 while ( --i >= 0 ) {
3106 if ( theindex < 0 ) {
3109 theindex = -theindex;
3110 d = Dollars + theindex;
3111 if ( AS.MultiThreaded ) {
3112 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3113 if ( theindex == ModOptdollars[nummodopt].number )
break;
3115 if ( nummodopt < NumModOptdollars ) {
3116 ddtype = ModOptdollars[nummodopt].type;
3117 if ( ddtype == MODLOCAL ) {
3118 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3121 LOCK(d->pthreadslockread);
3126 theindex = -theindex;
3127 d = Dollars + theindex;
3129 if ( d->type != DOLINDEX
3130 || d->index < AM.OffsetIndex
3131 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3132 MLOCK(ErrorMessageLock);
3133 MesPrint(
"$%s should have been an index" 3134 ,AC.dollarnames->namebuffer+d->name);
3135 AN.currentTerm = term;
3136 MesPrint(
"Current term: %t");
3137 AN.listinprint = printscratch;
3138 printscratch[0] = DOLLAREXPRESSION;
3139 printscratch[1] = theindex;
3141 ,AC.dollarnames->namebuffer+d->name);
3142 MUNLOCK(ErrorMessageLock);
3144 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3148 theindex = d->index;
3150 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3156 *cp++ = ++AR.CurDum;
3158 ow = AT.WorkPointer;
3159 AR.CompressPointer = cp;
3160 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3161 AR.CompressPointer = op;
3163 for ( j = 0; j < i; j++ ) term[j] = ow[j];
3164 AT.WorkPointer = ow;
3165 ReNumber(BHEAD term);
3169 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3171 AT.WorkPointer = term + *term;
3174 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3175 level = C->
lhs[level][2];
3176 if ( i > 0 )
goto ReStart;
3184 case TYPESPLITFIRSTARG:
3185 case TYPESPLITLASTARG:
3186 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3187 level = C->
lhs[level][2];
3192 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3193 if ( jjj > 0 )
goto ReStart;
3194 level = C->
lhs[level][2];
3197 if ( C->
lhs[level][2] > 0 ) {
3198 MLOCK(ErrorMessageLock);
3199 MesPrint(
"%s",C->
lhs[level]+3);
3200 MUNLOCK(ErrorMessageLock);
3207 AN.currentTerm = term;
3208 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][2] - 3)/2;
3209 AN.listinprint = C->
lhs[level]+3+C->
lhs[level][2];
3210 MLOCK(ErrorMessageLock);
3212 MesPrint((
char *)(C->
lhs[level]+3));
3214 MUNLOCK(ErrorMessageLock);
3220 MLOCK(ErrorMessageLock);
3221 oldFOflag = AM.FileOnlyFlag;
3222 oldPrintType = AO.PrintType;
3223 if ( AC.LogHandle >= 0 ) {
3224 AM.FileOnlyFlag = 1;
3225 AO.PrintType |= PRINTLFILE;
3227 AN.currentTerm = term;
3228 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][2] - 3)/2;
3229 AN.listinprint = C->
lhs[level]+3+C->
lhs[level][2];
3230 MesPrint((
char *)(C->
lhs[level]+3));
3231 AO.PrintType = oldPrintType;
3232 AM.FileOnlyFlag = oldFOflag;
3233 MUNLOCK(ErrorMessageLock);
3237 j = C->
lhs[level][2];
3247 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3248 if ( AC.pfirstnum[ii] == j )
break;
3250 AC.inputnumbers[ii] = AN.ninterms;
3254 if ( AS.MultiThreaded ) {
3256 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3257 if ( AC.pfirstnum[ii] == j )
break;
3259 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3260 LOCK(AP.PreVarLock);
3261 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3262 a = C->
lhs[level]+4;
3263 if ( a[a[-1]] == 0 )
3264 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3267 ,(UBYTE *)(a+a[-1]+1),1);
3271 AC.inputnumbers[ii] = AN.inputnumber;
3273 UNLOCK(AP.PreVarLock);
3278 a = C->
lhs[level]+4;
3279 LOCK(AP.PreVarLock);
3280 if ( a[a[-1]] == 0 )
3281 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3284 ,(UBYTE *)(a+a[-1]+1),1);
3285 UNLOCK(AP.PreVarLock);
3289 AT.WorkPointer = term + *term;
3290 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3291 AT.WorkPointer = term + *term;
3292 if ( *term == 0 )
goto Return0;
3295 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3296 AT.WorkPointer = term + *term;
3299 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3305 AN.cTerm = AN.currentTerm = term;
3306 AT.WorkPointer = term + *term;
3307 *AT.WorkPointer++ = 0;
3308 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3309 AT.WorkPointer = term + *term;
3311 AR.NoCompress = onc;
3312 AR.Eside = oldEside;
3316 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3317 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3318 AT.WorkPointer = term + *term;
3323 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3324 level = C->
lhs[level][2];
3327 retnorm = execterm(BHEAD term,level);
3328 AN.RepPoint = RepSto;
3330 CC->numrhs = oldtoprhs;
3331 CC->Pointer = CC->Buffer + oldcpointer;
3334 AT.WorkPointer = term + *term;
3335 AR.CurDum = DetCurDum(BHEAD term);
3337 case TYPEINEXPRESSION:
3338 {WORD *ll = C->
lhs[level];
3339 int numexprs = (int)(ll[1]-3);
3341 while ( numexprs-- >= 0 ) {
3342 if ( *ll == AR.CurExpr )
break;
3345 if ( numexprs < 0 ) level = C->
lhs[level][2];
3349 AT.WorkPointer = term + *term;
3350 if ( DoShuffle(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3352 AT.WorkPointer = term + *term;
3355 AT.WorkPointer = term + *term;
3356 if ( DoStuffle(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3358 AT.WorkPointer = term + *term;
3361 AT.WorkPointer = term + *term;
3362 if ( TestUse(term,level) )
goto GenCall;
3363 AT.WorkPointer = term + *term;
3366 AT.WorkPointer = term + *term;
3367 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3368 AT.WorkPointer = term + *term;
3372 AT.WorkPointer = term + *term;
3382 AT.WorkPointer = term + *term;
3383 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3384 AT.WorkPointer = term + *term;
3387 AT.WorkPointer = term + *term;
3388 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3389 AT.WorkPointer = term + *term;
3392 AT.WorkPointer = term + *term;
3394 AT.WorkPointer = term + *term;
3396 case TYPEARGIMPLODE:
3397 AT.WorkPointer = term + *term;
3398 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3399 AT.WorkPointer = term + *term;
3401 case TYPEARGEXPLODE:
3402 AT.WorkPointer = term + *term;
3403 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3404 AT.WorkPointer = term + *term;
3406 case TYPEDENOMINATORS:
3407 DenToFunction(term,C->
lhs[level][2]);
3409 case TYPEDROPCOEFFICIENT:
3410 DropCoefficient(BHEAD term);
3413 AT.WorkPointer = term + *term;
3414 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3415 AT.WorkPointer = term + *term;
3416 if ( *term == 0 )
goto Return0;
3418 case TYPETOPOLYNOMIAL:
3419 AT.WorkPointer = term + *term;
3420 termout = AT.WorkPointer;
3421 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3422 if ( *termout == 0 )
goto Return0;
3423 i = termout[0]; t = term; NCOPY(t,termout,i);
3424 AT.WorkPointer = term + *term;
3426 case TYPEFROMPOLYNOMIAL:
3427 AT.WorkPointer = term + *term;
3428 termout = AT.WorkPointer;
3429 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3430 if ( *term == 0 )
goto Return0;
3431 i = termout[0]; t = term; NCOPY(t,termout,i);
3432 AT.WorkPointer = term + *term;
3435 level = TestDoLoop(BHEAD C->
lhs[level],level);
3436 if ( level < 0 )
goto GenCall;
3439 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3440 if ( level < 0 )
goto GenCall;
3442 case TYPEDROPSYMBOLS:
3443 DropSymbols(BHEAD term);
3446 AT.WorkPointer = term + *term;
3447 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3448 AT.WorkPointer = term + *term;
3456 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
3457 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3458 if ( i > 0 ) replac =
TestSub(BHEAD term,level);
3460 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
3465 AutoGen: i = *AT.TMout;
3466 t = termout = AT.WorkPointer;
3467 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
3469 while ( --i >= 0 ) *t++ = *accum++;
3470 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
3471 AT.WorkPointer = termout;
3475 if ( applyflag ) { TableReset(); applyflag = 0; }
3479 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
3481 if ( AR.TePos >= 0 )
goto AutoGen;
3482 switch ( AN.TeInFun ) {
3484 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
3487 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
3490 if ( DoTableExpansion(term,level) )
goto GenCall;
3493 if ( FactorIn(BHEAD term,level) )
goto GenCall;
3496 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
3499 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
3502 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
3505 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
3508 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
3511 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
3514 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
3519 termout = AT.WorkPointer;
3520 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3521 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3522 if (
InFunction(BHEAD term,termout) )
goto GenCall;
3523 AT.WorkPointer = termout + *termout;
3526 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3527 AT.WorkPointer = termout;
3530 else if ( replac > 0 ) {
3534 power = -power; tepos = 0;
3536 extractbuff = AT.TMbuff;
3537 if ( extractbuff == AM.dbufnum ) {
3538 d = DolToTerms(BHEAD replac);
3539 if ( d && d->where != 0 ) {
3541 if ( AT.TMdolfac > 0 ) {
3542 if ( AT.TMdolfac == 1 ) {
3543 if ( d->nfactors ) {
3545 numfac[1] = d->nfactors;
3556 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
3557 MLOCK(ErrorMessageLock);
3558 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
3559 if ( d->nfactors == 1 )
3560 MesPrint(
"There is only one factor");
3562 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
3563 MUNLOCK(ErrorMessageLock);
3566 if ( d->nfactors > 1 ) {
3570 dd = Dollars + replac;
3573 int nummodopt, dtype = -1;
3574 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
3575 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3576 if ( replac == ModOptdollars[nummodopt].number )
break;
3578 if ( nummodopt < NumModOptdollars ) {
3579 dtype = ModOptdollars[nummodopt].type;
3580 if ( dtype == MODLOCAL ) {
3581 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
3587 dsize = dd->factors[AT.TMdolfac-2].size;
3593 numfac[1] = d->factors[AT.TMdolfac-2].value;
3598 if ( numfac[1] < 0 ) {
3599 numfac[1] = -numfac[1];
3600 numfac[3] = -numfac[3];
3604 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
3605 (dsize+1)*
sizeof(WORD),
"Copy of factor");
3606 td1 = dd->factors[AT.TMdolfac-2].where;
3608 d->size = dsize; d->type = DOLTERMS;
3609 NCOPY(td2,td1,dsize);
3613 else if ( d->nfactors == 1 ) {
3614 StartBuf = d->where;
3617 MLOCK(ErrorMessageLock);
3618 if ( d->nfactors == 0 ) {
3619 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
3622 MesPrint(
"Internal error. Illegal number of factors for $-variable");
3624 MUNLOCK(ErrorMessageLock);
3629 else StartBuf = d->where;
3632 d = Dollars + replac;
3633 StartBuf = zeroDollar;
3636 i = DetCommu(d->where);
3638 if ( AS.MultiThreaded ) {
3639 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3640 if ( replac == ModOptdollars[nummodopt].number )
break;
3642 if ( nummodopt < NumModOptdollars ) {
3643 dtype = ModOptdollars[nummodopt].type;
3644 if ( dtype != MODLOCAL && dtype != MODSUM ) {
3645 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
3646 MLOCK(ErrorMessageLock);
3647 MesPrint(
"A dollar variable with modoption max or min can have only one term");
3648 MUNLOCK(ErrorMessageLock);
3651 LOCK(d->pthreadslockread);
3658 StartBuf = cbuf[extractbuff].Buffer;
3659 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
3660 i = (WORD)cbuf[extractbuff].CanCommu[replac];
3663 termout = AT.WorkPointer;
3664 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
3665 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3666 while ( StartBuf[posisub] ) {
3667 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
3668 if (
InsertTerm(BHEAD term,replac,extractbuff,
3669 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
3670 AT.WorkPointer = termout + *termout;
3673 posisub += StartBuf[posisub];
3685 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
3686 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
3687 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3688 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3693 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
3695 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
3697 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
3704 StartBuf = cbuf[extractbuff].Buffer;
3708 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
3711 if ( d->nfactors > 1 ) {
3713 for ( j = 0; j < d->nfactors; j++ ) {
3714 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
3716 M_free(d->factors,
"Dollar factors");
3718 M_free(d,
"Copy of dollar variable");
3721 AT.WorkPointer = termout;
3723 else if ( i <= 1 ) {
3725 WORD *same, *ow = AT.WorkPointer;
3726 LONG olpw = AT.posWorkPointer;
3728 WantAddLongs(power1);
3729 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
3730 same = ++AT.WorkPointer;
3731 a = accum = ( AT.WorkPointer += power1+1 );
3732 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3733 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3734 AT.lWorkSpace[posit] = posisub;
3741 if ( StartBuf[AT.lWorkSpace[posit]] ) {
3743 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
3745 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
3746 same[1] = *same + 1;
3747 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
3748 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
3754 i--; posit--; same--;
3757 termout = AT.WorkPointer = a;
3758 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3759 if ( AT.WorkPointer > AT.WorkTop )
3761 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
3762 AT.WorkPointer = termout + *termout;
3766 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
3767 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
3768 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3769 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3773 if (
Generator(BHEAD termout,level) )
goto GenCall;
3775 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
3777 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
3778 StartBuf = cbuf[extractbuff].Buffer;
3779 i--; posit--; same--;
3783 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
3786 if ( d->nfactors > 1 ) {
3788 for ( j = 0; j < d->nfactors; j++ ) {
3789 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
3791 M_free(d->factors,
"Dollar factors");
3793 M_free(d,
"Copy of dollar variable");
3796 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
3799 LONG posit, olw, olpw = AT.posWorkPointer;
3800 WantAddLongs(power);
3801 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
3802 a = accum = AT.WorkPointer;
3803 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3804 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3805 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
3811 if ( StartBuf[AT.lWorkSpace[posit]] ) {
3813 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
3814 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
3818 AT.lWorkSpace[posit--] = posisub;
3822 termout = AT.WorkPointer = a;
3823 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3824 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3825 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
3826 AT.WorkPointer = termout + *termout;
3830 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); }
3831 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3832 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3836 if (
Generator(BHEAD termout,level) )
goto GenCall;
3838 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
3840 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
3841 StartBuf = cbuf[extractbuff].Buffer;
3846 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslockread); dtype = 0; }
3849 if ( d->nfactors > 1 ) {
3851 for ( j = 0; j < d->nfactors; j++ ) {
3852 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
3854 M_free(d->factors,
"Dollar factors");
3856 M_free(d,
"Copy of dollar variable");
3859 AT.WorkPointer = accum;
3860 AT.lWorkPointer = olw;
3861 AT.posWorkPointer = olpw;
3866 LONG position, olpw, opw, comprev, extra;
3868 WORD *Freeze, *aa, *dummies;
3872 if ( Expressions[replac].status == STOREDEXPRESSION ) {
3874 SETSTARTPOS(firstpos);
3886 WantAddPointers(power+1);
3887 comprev = opw = AT.pWorkPointer;
3888 AT.pWorkPointer += power+1;
3889 WantAddPositions(power+1);
3890 position = olpw = AT.posWorkPointer;
3891 AT.posWorkPointer += power + 1;
3893 AT.pWorkSpace[comprev++] = AR.CompressPointer;
3895 for ( i = 0; i < power; i++ ) {
3896 PUTZERO(AT.posWorkSpace[position]); position++;
3899 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
3900 dummies = AT.WorkPointer;
3901 *dummies++ = AR.CurDum;
3902 AT.WorkPointer += power+2;
3903 accum = AT.WorkPointer;
3904 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3905 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3906 aa = AT.WorkPointer;
3908 i = 0; StartPos = AT.posWorkSpace[position];
3909 dummies[i] = AR.CurDum;
3912 AR.CompressPointer = AT.pWorkSpace[comprev-1];
3913 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
3914 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
3915 if ( Expressions[replac].numdummies > 0 ) {
3916 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
3918 if ( NOTSTARTPOS(firstpos) ) {
3919 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
3920 firstpos = AT.posWorkSpace[position];
3931 i++; AT.posWorkSpace[++position] = StartPos;
3932 AT.pWorkSpace[comprev++] = AR.CompressPointer;
3933 dummies[i] = AR.CurDum;
3936 PUTZERO(AT.posWorkSpace[position]); position--; i--;
3937 AR.CurDum = dummies[i];
3941 termout = AT.WorkPointer = a;
3942 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
3943 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
3944 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
3946 AT.WorkPointer = termout + *termout;
3950 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
3951 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
3956 if (
Generator(BHEAD termout,level) )
goto GenCall;
3959 AR.CurDum = dummies[i];
3962 AT.WorkPointer = aa;
3964 AT.WorkPointer = accum;
3965 AT.posWorkPointer = olpw;
3966 AT.pWorkPointer = opw;
3974 if ( renumber->
symb.
lo != AN.dummyrenumlist )
3975 M_free(renumber->
symb.
lo,
"VarSpace");
3976 M_free(renumber,
"Renumber");
3980 aa = accum = AT.WorkPointer;
3981 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
3983 *accum++ = -1; AT.WorkPointer++;
3984 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
3985 AT.WorkPointer = aa;
3990 AN.RepPoint = RepSto;
3991 CC->numrhs = oldtoprhs;
3992 CC->Pointer = CC->Buffer + oldcpointer;
3996 if ( AM.tracebackflag ) {
3998 MLOCK(ErrorMessageLock);
3999 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4003 while ( --i >= 0 ) {
4004 TalToLine((UWORD)(*termout++));
4005 TokenToLine((UBYTE *)
" ");
4009 MesCall(
"Generator");
4010 MUNLOCK(ErrorMessageLock);
4012 CC->numrhs = oldtoprhs;
4013 CC->Pointer = CC->Buffer + oldcpointer;
4016 CC->numrhs = oldtoprhs;
4017 CC->Pointer = CC->Buffer + oldcpointer;
4018 MLOCK(ErrorMessageLock);
4020 MUNLOCK(ErrorMessageLock);
4053 char freezestring[] =
"freeze<-xxxx";
4057 WORD *aa, WORD level, WORD *freeze)
4060 POSITION oldposition, startposition;
4061 WORD *acc, *termout, fromfreeze = 0;
4062 WORD *oldipointer = AR.CompressPointer;
4065 WORD oldGetOneFile = AR.GetOneFile;
4066 WORD olddummies = AR.CurDum;
4067 WORD extradummies = Expressions[nexp].numdummies;
4097 type = Expressions[nexp].status;
4098 if ( type == HIDDENLEXPRESSION || type == HIDDENGEXPRESSION
4099 || type == DROPHLEXPRESSION || type == DROPHGEXPRESSION
4100 || type == UNHIDELEXPRESSION || type == UNHIDEGEXPRESSION ) {
4101 AR.GetOneFile = 2; fi = AR.hidefile;
4104 AR.GetOneFile = 0; fi = AR.infile;
4107 PUTZERO(oldposition);
4109 LOCK(AS.inputslock);
4110 SeekFile(fi->
handle,&oldposition,SEEK_CUR);
4111 UNLOCK(AS.inputslock);
4115 SETBASEPOSITION(oldposition,fi->POfill-fi->PObuffer);
4117 if ( freeze && ( Expressions[nexp].bracketinfo != 0 ) ) {
4125 if ( ( brapos = FindBracket(nexp,freeze) ) == 0 )
4127 startposition = *brapos;
4130 startposition = AS.OldOnFile[nexp];
4131 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4136 AR.CompressPointer = oldipointer;
4138 retval = GetOneTerm(BHEAD accum,fi,&startposition,0);
4139 if ( retval <= 0 )
break;
4144 WORD *t, *m, *r, *mstop;
4157 while ( t < r && *t != HAAKJE ) t += t[1];
4160 if ( fromfreeze )
goto EndExpr;
4167 while ( r < t && m < mstop ) {
4168 if ( *r == *m ) { m++; r++; }
4170 if ( fromfreeze )
goto EndExpr;
4174 if ( r < t || m < mstop ) {
4175 if ( fromfreeze )
goto EndExpr;
4183 while ( t < m ) *r++ = *t++;
4184 *accum = WORDDIF(r,accum);
4186 if ( extradummies > 0 ) {
4187 if ( olddummies > AM.IndDum ) {
4188 MoveDummies(BHEAD accum,olddummies-AM.IndDum);
4190 AR.CurDum = olddummies+extradummies;
4196 AT.WorkPointer = (WORD *)(((UBYTE *)(acc)) + 2*AM.MaxTer);
4197 if ( AT.WorkPointer > AT.WorkTop ) {
4198 MLOCK(ErrorMessageLock);
4200 MUNLOCK(ErrorMessageLock);
4203 if (
FiniTerm(BHEAD term,aa,termout,nexp,0) )
goto PowCall;
4205 AT.WorkPointer = termout + *termout;
4208 if (
Generator(BHEAD termout,level) )
goto PowCall;
4212 if ( acc > AT.WorkTop ) {
4213 MLOCK(ErrorMessageLock);
4215 MUNLOCK(ErrorMessageLock);
4218 if (
DoOnePow(BHEAD term,power,nexp,acc,aa,level,freeze) )
goto PowCall;
4221 AR.CompressPointer = oldipointer;
4226 AR.CompressPointer = oldipointer;
4229 LOCK(AS.inputslock);
4230 SeekFile(fi->
handle,&oldposition,SEEK_SET);
4231 UNLOCK(AS.inputslock);
4232 if ( ISNEGPOS(oldposition) ) {
4233 MLOCK(ErrorMessageLock);
4234 MesPrint(
"File error");
4240 fi->POfill = fi->PObuffer + BASEPOSITION(oldposition);
4242 AR.GetOneFile = oldGetOneFile;
4243 AR.CurDum = olddummies;
4246 MLOCK(ErrorMessageLock);
4250 MesCall(
"DoOnePow");
4251 MUNLOCK(ErrorMessageLock);
4279 WORD *t, *m, *mstop, *tstart, decr, oldb, *termout, i, *oldwork, retval;
4280 WORD *oldipointer = AR.CompressPointer, *oldPOfill = AR.infile->POfill;
4281 WORD oldGetOneFile = AR.GetOneFile;
4283 oldwork = AT.WorkPointer;
4284 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4285 termout = AT.WorkPointer;
4287 startposition = AR.DefPosition;
4291 if ( AR.infile->handle >= 0 ) {
4301 AR.infile->POfill = (WORD *)((UBYTE *)(AR.infile->PObuffer)
4302 +BASEPOSITION(startposition));
4307 t = m = AR.CompressBuffer;
4309 mstop = t - ABS(t[-1]);
4311 while ( *m != HAAKJE && m < mstop ) m += m[1];
4313 AT.WorkPointer = term + *term;
4314 if (
Generator(BHEAD term,level) )
goto DefCall;
4316 AT.WorkPointer = oldwork;
4317 AR.GetOneFile = oldGetOneFile;
4321 decr = WORDDIF(mstop,AR.CompressBuffer)-1;
4322 tstart = AR.CompressPointer + decr;
4324 m = AR.CompressBuffer;
4325 t = AR.CompressPointer;
4339 *tstart = *(AR.CompressPointer)-decr;
4340 AR.CompressPointer = AR.CompressPointer+AR.CompressPointer[0];
4341 if (
InsertTerm(BHEAD term,0,AM.rbufnum,tstart,termout,0) < 0 ) {
4345 AT.WorkPointer = termout + *termout;
4346 if (
Generator(BHEAD termout,level) )
goto DefCall;
4347 AR.CompressPointer = oldipointer;
4348 AT.WorkPointer = termout;
4349 retval = GetOneTerm(BHEAD AT.WorkPointer,AR.infile,&startposition,0);
4351 if ( retval <= 0 )
break;
4353 AR.CompressPointer = oldipointer;
4354 t = AR.CompressPointer;
4355 if ( *t < (1 + decr + ABS(*(t+*t-1))) )
break;
4357 m = AR.CompressBuffer+1;
4358 while ( m < mstop ) {
4359 if ( *m != *t )
goto Thatsit;
4367 if ( AR.infile->handle < 0 ) AR.infile->POfill = oldPOfill;
4369 AR.GetOneFile = oldGetOneFile;
4370 AT.WorkPointer = oldwork;
4373 MLOCK(ErrorMessageLock);
4374 MesCall(
"Deferred");
4375 MUNLOCK(ErrorMessageLock);
4405 WORD count = 0, i, jcoef, ncoef;
4406 WORD *t, *m, *r, *tstop, *
poly = 0, *v, *w, *vv, *ww;
4407 WORD *oldworkpointer = AT.WorkPointer;
4415 if ( AR.PolyFunType == 2 ) {
4416 if ( poly_ratfun_normalize(BHEAD term) != 0 ) Terminate(-1);
4417 oldworkpointer = AT.WorkPointer;
4423 while ( t < tstop ) {
4424 if ( *t == AR.PolyFun ) {
4425 if ( count > 0 )
return(0);
4431 r = m = term + *term;
4438 if ( i == 3 && m[-2] == 1 && (m[-3]&MAXPOSITIVE) == m[-3] ) {
4440 if ( AR.PolyFunType == 1 ) {
4444 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4447 else if ( AR.PolyFunType == 2 ) {
4451 *m = m[-2-FUNHEAD] < 0 ? -m[-4-FUNHEAD]: m[-4-FUNHEAD];
4459 if ( AR.PolyFunType == 1 ) {
4461 *m++ = FUNHEAD+ARGHEAD+i+1;
4469 else if ( AR.PolyFunType == 2 ) {
4470 WORD *num, *den, size, sign, sizenum, sizeden;
4471 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
4472 else { sign = 1; size = m[-1]; }
4473 num = m - size; size = (size-1)/2; den = num + size;
4474 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
4475 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
4477 AT.PolyAct = WORDDIF(v,term);
4479 *v++ = FUNHEAD + 2*(ARGHEAD+sizenum+sizeden+2);
4481 *v++ = ARGHEAD+2*sizenum+2;
4485 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
4487 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
4488 *v++ = sign*(2*sizenum+1);
4489 *v++ = ARGHEAD+2*sizeden+2;
4493 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
4495 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
4500 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
4508 else if ( AR.PolyFunType == 1 ) {
4514 if ( ( poly[1] == FUNHEAD+2 && poly[FUNHEAD+1] == 0
4515 && poly[FUNHEAD] == -SNUMBER ) || poly[1] == FUNHEAD )
return(1);
4517 if ( t >= r )
return(0);
4518 if ( m[-1] == 3 && *tstop == 1 && tstop[1] == 1 ) {
4523 else if ( *t <= -FUNCTION ) {
4524 if ( t+1 < r )
return(0);
4527 *m++ = FUNHEAD*2+ARGHEAD+i+1;
4529 *m++ = FUNHEAD+ARGHEAD+i+1;
4538 else if ( *t < 0 ) {
4539 if ( t+2 < r )
return(0);
4541 if ( *t == -SNUMBER ) {
4542 if ( t[1] == 0 )
return(1);
4545 m += FUNHEAD+ARGHEAD;
4554 if ( Normalize(BHEAD v) ) Terminate(-1);
4555 AT.WorkPointer = oldworkpointer;
4557 if ( *v == 4 && v[2] == 1 && (v[1]&MAXPOSITIVE) == v[1] ) {
4561 *m++ = v[3] < 0 ? -v[1] : v[1];
4563 else if ( *v == 0 )
return(1);
4565 *m++ = FUNHEAD+ARGHEAD+*v;
4573 else if ( *t == -SYMBOL ) {
4575 *m++ = FUNHEAD+ARGHEAD+5+i;
4590 if ( t + *t < r )
return(0);
4594 m += ARGHEAD+FUNHEAD-1;
4596 jcoef = i < 0 ? (i+1)>>1:(i-1)>>1;
4605 vstop = vv - ABS(vv[-1]);
4607 while( t < vstop ) {
4608 if ( *t == INDEX )
return(0);
4621 vv = v - ABS(ncoef);
4622 if ( ncoef < 0 ) ncoef++;
4625 while ( t < vv ) *m++ = *t++;
4626 if ( MulRat(BHEAD (UWORD *)vv,ncoef,(UWORD *)tstop,jcoef,
4627 (UWORD *)m,&ncoef) ) Terminate(-1);
4630 if ( ncoef < 0 ) ncoef--;
4633 *ww = WORDDIF(m,ww);
4634 if ( AN.ncmod != 0 ) {
4635 if ( Modulus(ww) ) Terminate(-1);
4636 if ( *ww == 0 )
return(1);
4641 *w = (WORDDIF(m,w))+1;
4642 w[FUNHEAD-1] = w[0] - FUNHEAD;
4646 if ( ToFast(w,w) ) {
4647 if ( *w <= -FUNCTION ) { w[-FUNHEAD+1] = FUNHEAD+1; m = w+1; }
4648 else { w[-FUNHEAD+1] = FUNHEAD+2; m = w+2; }
4653 while ( t < tstop ) *poly++ = *t++;
4658 else if ( AR.PolyFunType == 2 ) {
4662 WORD *num, *den, size, sign, sizenum, sizeden;
4667 if ( poly + poly[1] < tstop ) {
4668 for ( i = 0; i < poly[1]; i++ ) m[i] = poly[i];
4669 t = poly; v = poly + poly[1];
4670 while ( v < tstop ) *t++ = *v++;
4672 for ( i = 0; i < m[1]; i++ ) t[i] = m[i];
4675 AT.PolyAct = WORDDIF(poly,term);
4680 if ( m[-1] == 3 && m[-2] == 1 && m[-3] == 1 )
return(0);
4681 if ( m[-1] < 0 ) { sign = -1; size = -m[-1]; }
else { sign = 1; size = m[-1]; }
4682 num = m - size; size = (size-1)/2; den = num + size;
4683 sizenum = size;
while ( num[sizenum-1] == 0 ) sizenum--;
4684 sizeden = size;
while ( den[sizeden-1] == 0 ) sizeden--;
4687 *v++ = FUNHEAD + 2*(ARGHEAD+sizenum+sizeden+2);
4689 *v++ = ARGHEAD+2*sizenum+2;
4693 for ( i = 0; i < sizenum; i++ ) *v++ = num[i];
4695 for ( i = 1; i < sizenum; i++ ) *v++ = 0;
4696 *v++ = sign*(2*sizenum+1);
4697 *v++ = ARGHEAD+2*sizeden+2;
4701 for ( i = 0; i < sizeden; i++ ) *v++ = den[i];
4703 for ( i = 1; i < sizeden; i++ ) *v++ = 0;
4708 *w++ = 1; *w++ = 1; *w++ = 3; *term = w - term;
4709 poly_ratfun_normalize(BHEAD term);
4716 MLOCK(ErrorMessageLock);
4717 MesPrint(
"Illegal value for PolyFunType in PrepPoly");
4718 MUNLOCK(ErrorMessageLock);
4722 AT.PolyAct = WORDDIF(poly,term);
4723 while ( r < m ) *poly++ = *r++;
4727 *term = WORDDIF(poly,term);
4749 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *tt1, *tt2, *arg1, *arg2;
4751 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0;
4752 if ( AR.PolyFunType == 2 ) {
4753 WORD retval, count1 = 0, count2 = 0;
4754 t = term + 1; t1 = term + *term;; t1 -= ABS(t1[-1]);
4756 if ( *t == AR.PolyFun ) { count1++; }
4759 if ( count1 <= 1 )
return(0);
4761 retval = poly_ratfun_normalize(BHEAD term);
4763 t = term + 1; t1 = term + *term;; t1 -= ABS(t1[-1]);
4765 if ( *t == AR.PolyFun ) count2++;
4768 if ( count1 >= count2 ) {
4771 if ( *t == AR.PolyFun ) {
4777 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
4788 AT.WorkPointer = term + *term;
4789 GETSTOP(term,tstop);
4791 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
4792 while ( t < tstop && *t == AR.PolyFun ) {
4793 if ( t[1] > FUNHEAD ) {
4794 if ( t[FUNHEAD] < 0 ) {
4795 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
4796 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
4797 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
4804 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
4809 if ( *t != AR.PolyFun || t >= tstop )
goto done;
4812 while ( t < tstop && *t == AR.PolyFun ) {
4813 if ( t[1] > FUNHEAD ) {
4814 if ( t[FUNHEAD] < 0 ) {
4815 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
4816 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
4817 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
4824 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
4829 if ( *t != AR.PolyFun || t >= tstop )
goto done;
4837 n1 = 1; arg1 = AT.WorkPointer;
4838 ToGeneral(t,arg1,1);
4839 AT.WorkPointer = arg1 + *arg1;
4843 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
4844 while ( t < t1 ) { n1++; t += *t; }
4848 n2 = 1; arg2 = AT.WorkPointer;
4849 ToGeneral(t,arg2,1);
4850 AT.WorkPointer = arg2 + *arg2;
4854 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
4855 while ( t < t2 ) { n2++; t += *t; }
4867 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
4868 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
4873 while ( t < tt1 ) *m++ = *t++;
4876 while ( t < tt2 ) *m++ = *t++;
4877 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
4882 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
4883 l3 = REDLENG(m[-1]);
4887 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
4889 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
4891 if ( l4 == 0 )
continue;
4894 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
4896 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
4905 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
4907 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
4910 if ( l3 == 0 )
continue;
4920 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
4926 while ( *t ) t += *t;
4930 while ( t1 < fun1 ) *t++ = *t1++;
4933 *t++ = FUNHEAD+ARGHEAD+n1;
4940 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
4941 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
4942 else t2[FUNHEAD] = FUNHEAD+1;
4945 t1 = fun1 + fun1[1];
4946 while ( t1 < fun2 ) *t++ = *t1++;
4947 t1 = fun2 + fun2[1];
4949 while ( t1 < t2 ) *t++ = *t1++;
4950 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
4951 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
4952 MLOCK(ErrorMessageLock);
4953 MesPrint(
"Term too complex. Maybe increasing MaxTermSize can help");
4956 m = term; t = AT.WorkPointer;
4961 AT.WorkPointer = term + *term;
4962 if ( action && noac ) {
4963 if ( Normalize(BHEAD term) )
goto PolyCall;
4964 AT.WorkPointer = term + *term;
4968 MLOCK(ErrorMessageLock);
4970 MesCall(
"PolyFunMul");
4971 MUNLOCK(ErrorMessageLock);
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
WORD PrepPoly(PHEAD WORD *term)
int SymbolNormalize(WORD *)
WORD PF_Deferred(WORD *term, WORD level)
int PF_InParallelProcessor(void)
WORD FiniTerm(PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos)
int DollarFactorize(PHEAD WORD)
WORD InFunction(PHEAD WORD *term, WORD *termout)
WORD TestSub(PHEAD WORD *term, WORD level)
WORD StoreTerm(PHEAD WORD *)
LONG PasteFile(PHEAD WORD number, WORD *accum, POSITION *position, WORD **accfill, RENUMBER renumber, WORD *freeze, WORD nexpr)
WORD TestMatch(PHEAD WORD *, WORD *)
WORD * PasteTerm(PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby)
WORD Compare1(PHEAD WORD *, WORD *, WORD)
WORD InsertTerm(PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout, WORD tepos)
WORD Deferred(PHEAD WORD *term, WORD level)
WORD PutOut(PHEAD WORD *, POSITION *, FILEHANDLE *, WORD)
WORD PolyFunMul(PHEAD WORD *term)
int CompareSymbols(PHEAD WORD *, WORD *, WORD)
WORD FlushOut(POSITION *, FILEHANDLE *, int)
WORD DoOnePow(PHEAD WORD *term, WORD power, WORD nexp, WORD *accum, WORD *aa, WORD level, WORD *freeze)
int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression)
LONG EndSort(PHEAD WORD *, int)
int PF_BroadcastRHS(void)
WORD Generator(PHEAD WORD *term, WORD level)