67 WORD *term, *t, i, size;
71 WORD last, LastExpression, fromspectator;
73 CBUF *C = cbuf+AC.cbufnum;
75 CBUF *CC = cbuf+AT.ebufnum;
78 WORD oldBracketOn = AR.BracketOn;
79 WORD *oldBrackBuf = AT.BrackBuf;
80 WORD oldbracketindexflag = AT.bracketindexflag;
82 int OldMultiThreaded = AS.MultiThreaded, Oldmparallelflag = AC.mparallelflag;
84 if ( CC->numrhs > 0 || CC->numlhs > 0 ) {
86 w = CC->
rhs; i = CC->numrhs;
87 do { *w++ = 0; }
while ( --i > 0 );
90 w = CC->
lhs; i = CC->numlhs;
91 do { *w++ = 0; }
while ( --i > 0 );
93 CC->numlhs = CC->numrhs = 0;
94 ClearTree(AT.ebufnum);
98 if ( NumExpressions == 0 )
return(0);
100 AR.CompressPointer = AR.CompressBuffer;
101 AR.NoCompress = AC.NoCompress;
102 term = AT.WorkPointer;
103 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer) ) > AT.WorkTop ) {
109 if ( AC.CollectFun ) AR.DeferFlag = 0;
113 MesPrint(
"Status at the start of Processor (HideLevel = %d)",AC.HideLevel);
114 for ( i = 0; i < NumExpressions; i++ ) {
124 for ( i = NumExpressions-1; i >= 0; i-- ) {
126 if ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION
127 || e->status == HIDELEXPRESSION || e->status == HIDEGEXPRESSION
128 || e->status == SKIPLEXPRESSION || e->status == SKIPGEXPRESSION
129 || e->status == UNHIDELEXPRESSION || e->status == UNHIDEGEXPRESSION
130 || e->status == INTOHIDELEXPRESSION || e->status == INTOHIDEGEXPRESSION
134 for ( i = NumExpressions-1; i >= 0; i-- ) {
135 AS.OldOnFile[i] = Expressions[i].onfile;
136 AS.OldNumFactors[i] = Expressions[i].numfactors;
138 AS.Oldvflags[i] = Expressions[i].vflags;
139 AS.Olduflags[i] = Expressions[i].uflags;
140 Expressions[i].vflags &= ~(ISUNMODIFIED|ISZERO);
148 if ( AC.partodoflag && AM.totalnumberofthreads > 1 ) {
149 AS.MultiThreaded = 1; AC.mparallelflag = PARALLELFLAG;
151 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
161 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
162 if ( InParallelProcessor() ) {
165 AS.MultiThreaded = OldMultiThreaded;
166 AC.mparallelflag = Oldmparallelflag;
170 if ( AC.RhsExprInModuleFlag && PF.rhsInParallel && (AC.mparallelflag == PARALLELFLAG || AC.partodoflag) ) {
176 if ( AC.partodoflag > 0 ) {
182 for ( i = 0; i < NumExpressions; i++ ) {
184 if ( AC.InnerTest ) {
185 if ( StrCmp(AC.TestValue,(UBYTE *)INNERTEST) == 0 ) {
186 MesPrint(
"Testing(Processor): value = %s",AC.TestValue);
192 if ( AC.partodoflag > 0 && e->partodo > 0 && AM.totalnumberofthreads > 2 ) {
198 if ( AC.partodoflag > 0 && e->partodo > 0 && PF.numtasks > 2 ) {
203 AS.CollectOverFlag = 0;
205 if ( i == last ) LastExpression = 1;
206 else LastExpression = 0;
216 SetScratch(AR.infile,&(e->onfile));
217 if ( GetTerm(BHEAD term) <= 0 ) {
218 MesPrint(
"(1) Expression %d has problems in scratchfile",i);
224 SeekScratch(AR.outfile,&position);
225 e->onfile = position;
226 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
227 AR.DeferFlag = AC.ComDefer;
232 for ( j = 0; j < *t; j++ ) term[j] = t[j];
234 AN.ninterms++; dd = AN.deferskipped;
235 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
236 if ( GetMoreFromMem(term,&t) ) {
240 AT.WorkPointer = term + *term;
241 AN.RepPoint = AT.RepCount + 1;
242 AN.IndDum = AM.IndDum;
243 AR.CurDum = ReNumber(BHEAD term);
244 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
246 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
247 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
249 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
256 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
257 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
258 else e->vflags |= ISZERO;
259 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
260 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
261 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
269 switch ( e->status ) {
270 case UNHIDELEXPRESSION:
271 case UNHIDEGEXPRESSION:
274 if ( PF.me == MASTER ) SetScratch(AR.hidefile,&(e->onfile));
276 SetScratch(AR.hidefile,&(e->onfile));
277 AR.InHiBuf = AR.hidefile->POfull-AR.hidefile->POfill;
279 MesPrint(
"Hidefile: onfile: %15p, POposition: %15p, filesize: %15p",&(e->onfile)
280 ,&(AR.hidefile->POposition),&(AR.hidefile->filesize));
281 MesPrint(
"Set hidefile to buffer position %l/%l; AR.InHiBuf = %l"
282 ,(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD)
283 ,(AR.hidefile->POfull-AR.hidefile->PObuffer)*
sizeof(WORD)
288 curfile = AR.hidefile;
290 case INTOHIDELEXPRESSION:
291 case INTOHIDEGEXPRESSION:
298 SetEndHScratch(AR.hidefile,&position);
300 case LOCALEXPRESSION:
301 case GLOBALEXPRESSION:
305 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
307 SetScratch(AR.infile,&(e->onfile));
313 MesPrint(
"Error in PF_Processor");
317 if ( AC.mparallelflag != PARALLELFLAG ){
322 if ( GetTerm(BHEAD term) <= 0 ) {
324 MesPrint(
"Error condition 1a");
327 MesPrint(
"(2) Expression %d has problems in scratchfile(process)",i);
333 fromspectator = -term[5];
334 PUTZERO(AM.SpectatorFiles[fromspectator-1].readpos);
335 term[5] = AC.cbufnum;
337 else fromspectator = 0;
338 if ( AR.outtohide ) {
339 SeekScratch(AR.hidefile,&position);
340 e->onfile = position;
341 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
344 SeekScratch(AR.outfile,&position);
345 e->onfile = position;
346 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
348 AR.DeferFlag = AC.ComDefer;
350 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
352 AT.BrackBuf = AM.BracketFactors;
353 AT.bracketindexflag = 1;
355 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
357 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
358 if ( ThreadsProcessor(e,LastExpression,fromspectator) ) {
359 MesPrint(
"Error in ThreadsProcessor");
362 if ( AR.outtohide ) {
363 AR.outfile = oldoutfile;
364 AR.hidefile->POfull = AR.hidefile->POfill;
371 AR.MaxDum = AM.IndDum;
374 if ( fromspectator ) size = GetFromSpectator(term,fromspectator-1);
375 else size = GetTerm(BHEAD term);
376 if ( size <= 0 )
break;
377 SeekScratch(curfile,&position);
378 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
382 AN.ninterms++; dd = AN.deferskipped;
383 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
384 if ( GetMoreTerms(term) < 0 ) {
387 SeekScratch(curfile,&position);
389 AT.WorkPointer = term + *term;
390 AN.RepPoint = AT.RepCount + 1;
391 if ( AR.DeferFlag ) {
392 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
393 AR.CurDum = AN.IndDum;
396 AN.IndDum = AM.IndDum;
397 AR.CurDum = ReNumber(BHEAD term);
399 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
401 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
402 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
404 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
405 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
406 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
407 PolyFunClean(BHEAD term);
414 SetScratch(curfile,&position);
415 if ( AR.GetFile == 2 ) {
416 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
417 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
420 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
421 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
425 if ( LastExpression ) {
427 if ( AR.infile->handle >= 0 ) {
428 CloseFile(AR.infile->handle);
429 AR.infile->handle = -1;
430 remove(AR.infile->name);
431 PUTZERO(AR.infile->POposition);
433 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
435 if ( AR.outtohide ) AR.outfile = AR.hidefile;
436 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
437 if ( AR.outtohide ) {
438 AR.outfile = oldoutfile;
439 AR.hidefile->POfull = AR.hidefile->POfill;
441 e->numdummies = AR.MaxDum - AM.IndDum;
444 AR.BracketOn = oldBracketOn;
445 AT.BrackBuf = oldBrackBuf;
446 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
449 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
450 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
453 AT.bracketindexflag = oldbracketindexflag;
454 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
455 else e->vflags |= ISZERO;
456 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
457 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
458 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
466 if ( e->status == INTOHIDELEXPRESSION ||
467 e->status == INTOHIDEGEXPRESSION ) {
472 case SKIPLEXPRESSION:
473 case SKIPGEXPRESSION:
478 if ( PF.me != MASTER )
break;
481 SetScratch(AR.infile,&(e->onfile));
482 if ( GetTerm(BHEAD term) <= 0 ) {
484 MesPrint(
"Error condition 1b");
487 MesPrint(
"(3) Expression %d has problems in scratchfile",i);
493 SeekScratch(AR.outfile,&position);
494 e->onfile = position;
495 *AM.S0->sBuffer = 0; firstterm = -1;
497 WORD *oldipointer = AR.CompressPointer;
498 WORD *comprtop = AR.ComprTop;
499 AR.ComprTop = AM.S0->sTop;
500 AR.CompressPointer = AM.S0->sBuffer;
501 if ( firstterm > 0 ) {
502 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
504 else if ( firstterm < 0 ) {
505 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
509 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
512 AR.CompressPointer = oldipointer;
513 AR.ComprTop = comprtop;
514 }
while ( GetTerm(BHEAD term) );
515 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
518 case HIDELEXPRESSION:
519 case HIDEGEXPRESSION:
521 if ( PF.me != MASTER )
break;
524 SetScratch(AR.infile,&(e->onfile));
525 if ( GetTerm(BHEAD term) <= 0 ) {
527 MesPrint(
"Error condition 1c");
530 MesPrint(
"(4) Expression %d has problems in scratchfile",i);
536 SetEndHScratch(AR.hidefile,&position);
537 e->onfile = position;
539 if ( AR.hidefile->handle >= 0 ) {
543 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
544 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
545 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
546 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
548 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
551 *AM.S0->sBuffer = 0; firstterm = -1;
552 cbo = cpo = AM.S0->sBuffer;
554 WORD *oldipointer = AR.CompressPointer;
555 WORD *oldibuffer = AR.CompressBuffer;
556 WORD *comprtop = AR.ComprTop;
557 AR.ComprTop = AM.S0->sTop;
558 AR.CompressPointer = cpo;
559 AR.CompressBuffer = cbo;
560 if ( firstterm > 0 ) {
561 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
563 else if ( firstterm < 0 ) {
564 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
568 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
571 cpo = AR.CompressPointer;
572 cbo = AR.CompressBuffer;
573 AR.CompressPointer = oldipointer;
574 AR.CompressBuffer = oldibuffer;
575 AR.ComprTop = comprtop;
576 }
while ( GetTerm(BHEAD term) );
578 if ( AR.hidefile->handle >= 0 ) {
582 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
583 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
584 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
585 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
587 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
590 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
591 AR.hidefile->POfull = AR.hidefile->POfill;
593 if ( AR.hidefile->handle >= 0 ) {
597 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
598 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
599 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
600 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
602 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
613 if ( e->status == HIDELEXPRESSION ) {
614 e->status = HIDDENLEXPRESSION;
615 AS.OldOnFile[i] = e->onfile;
616 AS.OldNumFactors[i] = Expressions[i].numfactors;
618 if ( e->status == HIDEGEXPRESSION ) {
619 e->status = HIDDENGEXPRESSION;
620 AS.OldOnFile[i] = e->onfile;
621 AS.OldNumFactors[i] = Expressions[i].numfactors;
628 case DROPPEDEXPRESSION:
629 case DROPLEXPRESSION:
630 case DROPGEXPRESSION:
631 case DROPHLEXPRESSION:
632 case DROPHGEXPRESSION:
633 case STOREDEXPRESSION:
634 case HIDDENLEXPRESSION:
635 case HIDDENGEXPRESSION:
636 case SPECTATOREXPRESSION:
644 AT.WorkPointer = term;
646 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
647 for ( i = 0; i < NumExpressions; i++ ) {
654 AT.WorkPointer = term;
655 if ( AM.tracebackflag ) MesCall(
"Processor");
2163 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2164 WORD *u, *v, *w, *from, *to,
2165 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2169 m = r - ABS(*r) + 1;
2172 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2175 if ( ( term + AR.TePos ) == t ) {
2177 while ( from < t ) *m++ = *from++;
2179 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2182 *m++ = t[1] + 4 + ARGHEAD;
2188 while ( t < v ) *m++ = *t++;
2194 while ( t < r ) *m++ = *t++;
2195 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2196 MLOCK(ErrorMessageLock);
2197 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2198 MUNLOCK(ErrorMessageLock);
2201 *termout = WORDDIF(m,termout);
2205 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec <= 0 )
2206 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2211 oldncmod = AN.ncmod;
2213 if ( *t > 0 && t[1] ) {
2214 WORD oldsorttype = AR.SortType;
2217 if ( ( AN.ncmod != 0 )
2218 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2219 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2223 LONG copy = t - from;
2224 const LONG size = t - u;
2225 NCOPY(m, from, copy);
2229 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2231 AR.SortType = SORTHIGHFIRST;
2240 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2242 AN.ncmod = oldncmod;
2252 if (
EndSort(BHEAD m,1) < 0 ) {
2253 AN.ncmod = oldncmod;
2256 AR.PolyFun = oldPolyFun;
2257 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2258 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2259 AR.SortType = oldsorttype;
2261 while ( *m ) m += *m;
2262 *to = WORDDIF(m,to);
2264 if ( ToFast(to,to) ) {
2265 if ( *to <= -FUNCTION ) m = to+1;
2268 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2271 while ( t < r ) *m++ = *t++;
2272 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2273 MLOCK(ErrorMessageLock);
2274 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2275 MUNLOCK(ErrorMessageLock);
2278 *termout = WORDDIF(m,termout);
2279 AR.DeferFlag = olddefer;
2280 AN.ncmod = oldncmod;
2283 else if ( *t == -DOLLAREXPRESSION ) {
2284 if ( AR.Eside == LHSIDE ) {
2286 AC.lhdollarflag = 1;
2294 int nummodopt, dtype = -1;
2295 if ( AS.MultiThreaded ) {
2296 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2297 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2299 if ( nummodopt < NumModOptdollars ) {
2300 dtype = ModOptdollars[nummodopt].type;
2301 if ( dtype == MODLOCAL ) {
2302 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2305 LOCK(d->pthreadslock);
2310 oldncmod = AN.ncmod;
2311 if ( ( AN.ncmod != 0 )
2312 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2313 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2316 LONG copy = t - from;
2317 const LONG size = t - u;
2318 NCOPY(m, from, copy);
2321 switch ( d->type ) {
2323 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2324 *m++ = -SNUMBER; *m++ = d->index;
2326 else { *m++ = -INDEX; *m++ = d->index; }
2329 *m++ = -SNUMBER; *m++ = 0;
break;
2331 if ( d->where[0] == 4 &&
2332 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2334 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2335 else *m++ = -d->where[1];
2345 to = m; r = d->where;
2349 i = *r; NCOPY(m,r,i)
2352 if ( ToFast(to,to) ) {
2353 if ( *to <= -FUNCTION ) m = to+1;
2356 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2365 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2370 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2371 AR.PolyFun = oldPolyFun;
2372 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2380 while ( *m ) m += *m;
2382 if ( ToFast(to,to) ) {
2383 if ( *to <= -FUNCTION ) m = to+1;
2388 w[1] = w[1] - 2 + (m-to);
2391 to = m; r = d->where;
2393 *m++ = i+4+ARGHEAD; *m++ = 1;
2396 while ( --i >= 0 ) *m++ = *r++;
2397 *m++ = 1; *m++ = 1; *m++ = 3;
2398 if ( ToFast(to,to) ) {
2399 if ( *to <= -FUNCTION ) m = to+1;
2402 w[1] = w[1] - 2 + (m-to);
2405 to = m; r = d->where;
2408 *m++ = *r++; *m++ = 1; r++;
2409 while ( --i >= 0 ) *m++ = *r++;
2411 else if ( *r <= -FUNCTION ) *m++ = *r++;
2412 else { *m++ = *r++; *m++ = *r++; }
2413 w[1] = w[1] - 2 + (m-to);
2416 to = m; r = d->where;
2419 while ( --i >= 0 ) {
2421 *m++ = -VECTOR; *m++ = *r++;
2423 else if ( *r >= AM.OffsetIndex ) {
2424 *m++ = -INDEX; *m++ = *r++;
2426 else { *m++ = -SNUMBER; *m++ = *r++; }
2434 *m++ = *r++; *m++ = 1; r++;
2435 while ( --i >= 0 ) *m++ = *r++;
2437 else if ( *r <= -FUNCTION ) *m++ = *r++;
2438 else { *m++ = *r++; *m++ = *r++; }
2441 w[1] = w[1] - 2 + (m-to);
2445 MLOCK(ErrorMessageLock);
2446 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2447 AC.dollarnames->namebuffer+d->name);
2448 MUNLOCK(ErrorMessageLock);
2450 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
2455 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
2459 while ( t < r ) *m++ = *t++;
2460 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2461 MLOCK(ErrorMessageLock);
2462 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2463 MUNLOCK(ErrorMessageLock);
2466 *termout = WORDDIF(m,termout);
2467 AR.DeferFlag = olddefer;
2468 AN.ncmod = oldncmod;
2472 else if ( *t == -TERMSINBRACKET ) {
2473 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2482 LONG copy = t - from;
2483 const LONG size = t - u;
2484 NCOPY(m, from, copy);
2486 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2487 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2490 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2492 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2493 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2498 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2499 *m++ = 6; *m++ = numterms & WORDMASK;
2500 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2505 while ( from < r ) *m++ = *from++;
2506 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2507 MLOCK(ErrorMessageLock);
2508 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2509 MUNLOCK(ErrorMessageLock);
2512 *termout = WORDDIF(m,termout);
2519 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec > 0 )
2520 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2521 u = t; v = t + t[1];
2524 if ( *t == FUNNYDOLLAR ) {
2525 if ( AR.Eside != LHSIDE ) {
2528 int nummodopt, dtype = -1;
2529 if ( AS.MultiThreaded ) {
2530 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2531 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2533 if ( nummodopt < NumModOptdollars ) {
2534 dtype = ModOptdollars[nummodopt].type;
2535 if ( dtype == MODLOCAL ) {
2536 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2539 LOCK(d->pthreadslock);
2544 oldncmod = AN.ncmod;
2545 if ( ( AN.ncmod != 0 )
2546 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2547 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2549 LONG copy = t - from;
2550 const LONG size = t - u;
2551 NCOPY(m, from, copy);
2554 switch ( d->type ) {
2556 *m++ = d->index;
break;
2561 if ( d->where[0] == 4 && d->where[4] == 0
2562 && d->where[3] == 3 && d->where[2] == 1
2563 && d->where[1] < AM.OffsetIndex ) {
2569 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
2571 MLOCK(ErrorMessageLock);
2572 MesPrint(
"$%s has wrong type for tensor substitution",
2573 AC.dollarnames->namebuffer+d->name);
2574 MUNLOCK(ErrorMessageLock);
2575 AN.ncmod = oldncmod;
2580 if ( d->where[0] == -INDEX ) {
2581 *m++ = d->where[1];
break;
2583 else if ( d->where[0] == -VECTOR ) {
2584 *m++ = d->where[1];
break;
2586 else if ( d->where[0] == -MINVECTOR ) {
2591 else if ( d->where[0] == -SNUMBER ) {
2592 if ( d->where[1] >= 0
2593 && d->where[1] < AM.OffsetIndex ) {
2594 *m++ = d->where[1];
break;
2599 if ( d->where[0] > 0 ) {
2600 r = d->where; i = *r++;
2601 while ( --i >= 0 ) *m++ = *r++;
2606 if ( *r == -INDEX ) {
2607 *m++ = r[1]; r += 2;
continue;
2609 else if ( *r == -VECTOR ) {
2610 *m++ = r[1]; r += 2;
continue;
2612 else if ( *r == -MINVECTOR ) {
2613 *m++ = r[1]; r += 2;
2614 sign = -sign;
continue;
2616 else if ( *r == -SNUMBER ) {
2618 && r[1] < AM.OffsetIndex ) {
2619 *m++ = r[1]; r += 2;
continue;
2628 if ( *r == INDEX && r[1] == 3 ) {
2631 else goto wrongtype;
2635 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
2637 MLOCK(ErrorMessageLock);
2638 MesPrint(
"$%s is undefined in tensor substitution",
2639 AC.dollarnames->namebuffer+d->name);
2640 MUNLOCK(ErrorMessageLock);
2641 AN.ncmod = oldncmod;
2645 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
2647 w[1] = w[1] - 2 + (m-to);
2650 while ( from < term ) *m++ = *from++;
2651 if ( sign < 0 ) m[-1] = -m[-1];
2652 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2653 MLOCK(ErrorMessageLock);
2654 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2655 MUNLOCK(ErrorMessageLock);
2658 *termout = m - termout;
2659 AN.ncmod = oldncmod;
2663 AC.lhdollarflag = 1;
2672 MLOCK(ErrorMessageLock);
2673 MesPrint(
"Internal error in InFunction: Function not encountered.");
2674 if ( AM.tracebackflag ) {
2675 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2676 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2678 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2682 while ( --i >= 0 ) {
2683 TalToLine((UWORD)(*termout++));
2684 TokenToLine((UBYTE *)
" ");
2688 MesCall(
"InFunction");
2690 MUNLOCK(ErrorMessageLock);
2694 MLOCK(ErrorMessageLock);
2695 MesCall(
"InFunction");
2696 MUNLOCK(ErrorMessageLock);
2700 MLOCK(ErrorMessageLock);
2701 MesCall(
"InFunction");
2702 MUNLOCK(ErrorMessageLock);
3252 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3253 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, extractbuff;
3255 int *RepSto = AN.RepPoint, iscopy = 0;
3256 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3257 LONG posisub, oldcpointer, oldacpointer;
3259 WORD numfac[5], idfunctionflag;
3261 int nummodopt, dtype = -1, id;
3263 oldtoprhs = CC->numrhs;
3264 oldcpointer = CC->Pointer - CC->Buffer;
3265 oldatoprhs = CCC->numrhs;
3266 oldacpointer = CCC->Pointer - CCC->Buffer;
3268 if ( ( replac = TestSub(BHEAD term,level) ) == 0 ) {
3269 if ( applyflag ) { TableReset(); applyflag = 0; }
3278 AN.PolyNormFlag = 0;
3279 AN.idfunctionflag = 0;
3280 if ( ( ret = Normalize(BHEAD term) ) != 0 ) {
3282 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3287 idfunctionflag = AN.idfunctionflag;
3288 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3290 if ( AN.PolyNormFlag ) {
3291 if ( AN.PolyFunTodo == 0 ) {
3292 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3293 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3296 WORD oldPolyFunExp = AR.PolyFunExp;
3298 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3299 AT.WorkPointer = term+*term;
3300 AR.PolyFunExp = oldPolyFunExp;
3301 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3302 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3303 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3304 AT.WorkPointer = term+*term;
3305 if ( AN.PolyNormFlag ) {
3306 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3307 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3308 AT.WorkPointer = term+*term;
3313 if ( idfunctionflag > 0 ) {
3314 if ( TakeIDfunction(BHEAD term) ) {
3315 AT.WorkPointer = term + *term;
3319 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3320 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3323 if ( level > AR.Cnumlhs ) {
3324 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3326 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3332 if (
Deferred(BHEAD term,level) )
goto GenCall;
3336 if ( AN.ncmod != 0 ) {
3337 if ( Modulus(term) )
goto GenCall;
3338 if ( !*term )
goto Return0;
3340 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3341 WORD olddummies = AN.IndDum;
3342 AN.IndDum = AM.IndDum;
3343 ReNumber(BHEAD term);
3344 Normalize(BHEAD term);
3345 AN.IndDum = olddummies;
3346 if ( !*term )
goto Return0;
3347 olddummies = DetCurDum(BHEAD term);
3348 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3350 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3351 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3353 else if ( AR.PolyFun > 0 ) {
3354 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3356 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3357 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3358 termout = AT.WorkPointer;
3359 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3360 if ( PutBracket(BHEAD term) )
return(-1);
3361 AN.RepPoint = RepSto;
3362 *AT.WorkPointer = 0;
3364 AT.WorkPointer = termout;
3365 CC->numrhs = oldtoprhs;
3366 CC->Pointer = CC->Buffer + oldcpointer;
3367 CCC->numrhs = oldatoprhs;
3368 CCC->Pointer = CCC->Buffer + oldacpointer;
3372 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3373 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3374 *AT.WorkPointer = 0;
3375 AN.RepPoint = RepSto;
3377 CC->numrhs = oldtoprhs;
3378 CC->Pointer = CC->Buffer + oldcpointer;
3379 CCC->numrhs = oldatoprhs;
3380 CCC->Pointer = CCC->Buffer + oldacpointer;
3384 i = C->
lhs[level][0];
3385 if ( i >= TYPECOUNT ) {
3391 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3392 AT.WorkPointer = term + *term;
3397 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3400 level = AC.Labels[C->
lhs[level][2]];
3403 AT.WorkPointer = term + *term;
3413 WORD ic, jc, *ifcode, *jfcode;
3414 jfcode = C->
lhs[level]; jc = jfcode[1];
3415 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3416 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3417 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3418 level = C->
lhs[level][2];
3419 if ( C->
lhs[level][0] != TYPEELIF )
break;
3421 AT.WorkPointer = ifcode;
3424 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3425 level = C->
lhs[level][2];
3426 if ( C->
lhs[level][0] != TYPEELIF )
break;
3432 level = C->
lhs[level][2];
3433 }
while ( C->
lhs[level][0] == TYPEELIF );
3437 level = C->
lhs[level][2];
3441 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3442 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3443 WORD theindex = C->
lhs[level][2];
3444 if ( theindex < 0 ) {
3447 theindex = -theindex;
3448 d = Dollars + theindex;
3449 if ( AS.MultiThreaded ) {
3450 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3451 if ( theindex == ModOptdollars[nummodopt].number )
break;
3453 if ( nummodopt < NumModOptdollars ) {
3454 ddtype = ModOptdollars[nummodopt].type;
3455 if ( ddtype == MODLOCAL ) {
3456 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3459 LOCK(d->pthreadslock);
3464 theindex = -theindex;
3465 d = Dollars + theindex;
3468 if ( d->type != DOLINDEX
3469 || d->index < AM.OffsetIndex
3470 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3471 MLOCK(ErrorMessageLock);
3472 MesPrint(
"$%s should have been an index"
3473 ,AC.dollarnames->namebuffer+d->name);
3474 AN.currentTerm = term;
3475 MesPrint(
"Current term: %t");
3476 AN.listinprint = printscratch;
3477 printscratch[0] = DOLLAREXPRESSION;
3478 printscratch[1] = theindex;
3480 ,AC.dollarnames->namebuffer+d->name);
3481 MUNLOCK(ErrorMessageLock);
3483 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
3487 theindex = d->index;
3489 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
3492 cp[1] = SUBEXPSIZE+4;
3497 i = C->
lhs[level][1] - 3;
3499 AR.CompressPointer = cp;
3500 while ( --i >= 0 ) {
3502 termout = AT.WorkPointer;
3503 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3507 while ( --jlhs >= 0 ) {
3508 if ( *m++ != *termout++ )
break;
3511 termout = AT.WorkPointer;
3512 AT.WorkPointer = termout + *termout;
3513 if (
Generator(BHEAD termout,level) )
goto GenCall;
3514 AT.WorkPointer = termout;
3517 AR.CompressPointer = op;
3521 AR.CompressPointer = op;
3526 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3532 AR.CurDum = DetCurDum(BHEAD term);
3533 i = C->
lhs[level][1]-2;
3534 wp = C->
lhs[level] + 2;
3535 cp[1] = SUBEXPSIZE+4*i;
3537 while ( --i >= 0 ) {
3539 if ( theindex < 0 ) {
3542 theindex = -theindex;
3543 d = Dollars + theindex;
3544 if ( AS.MultiThreaded ) {
3545 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3546 if ( theindex == ModOptdollars[nummodopt].number )
break;
3548 if ( nummodopt < NumModOptdollars ) {
3549 ddtype = ModOptdollars[nummodopt].type;
3550 if ( ddtype == MODLOCAL ) {
3551 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3554 LOCK(d->pthreadslock);
3559 theindex = -theindex;
3560 d = Dollars + theindex;
3562 if ( d->type != DOLINDEX
3563 || d->index < AM.OffsetIndex
3564 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3565 MLOCK(ErrorMessageLock);
3566 MesPrint(
"$%s should have been an index"
3567 ,AC.dollarnames->namebuffer+d->name);
3568 AN.currentTerm = term;
3569 MesPrint(
"Current term: %t");
3570 AN.listinprint = printscratch;
3571 printscratch[0] = DOLLAREXPRESSION;
3572 printscratch[1] = theindex;
3574 ,AC.dollarnames->namebuffer+d->name);
3575 MUNLOCK(ErrorMessageLock);
3577 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
3581 theindex = d->index;
3583 if ( ddtype > 0 && ddtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
3589 *cp++ = ++AR.CurDum;
3591 ow = AT.WorkPointer;
3592 AR.CompressPointer = cp;
3593 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3594 AR.CompressPointer = op;
3596 WORD term_changed = 0;
3597 for ( j = 0; j < i; j++ ) {
3598 if ( term[j] != ow[j] ) term_changed = 1;
3602 if ( term_changed ) *AN.RepPoint = 1;
3603 AT.WorkPointer = ow;
3608 ReNumber(BHEAD term);
3612 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3614 AT.WorkPointer = term + *term;
3617 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3618 level = C->
lhs[level][2];
3619 if ( i > 0 )
goto ReStart;
3627 case TYPESPLITFIRSTARG:
3628 case TYPESPLITLASTARG:
3629 case TYPEARGTOEXTRASYMBOL:
3630 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3631 level = C->
lhs[level][2];
3636 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3637 if ( jjj > 0 )
goto ReStart;
3638 level = C->
lhs[level][2];
3641 if ( C->
lhs[level][2] > 0 ) {
3642 MLOCK(ErrorMessageLock);
3643 MesPrint(
"%s",C->
lhs[level]+3);
3644 MUNLOCK(ErrorMessageLock);
3652 AN.currentTerm = term;
3653 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3654 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3655 MLOCK(ErrorMessageLock);
3657 MesPrint((
char *)(C->
lhs[level]+5));
3659 MUNLOCK(ErrorMessageLock);
3664 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3665 AC.LogHandle = C->
lhs[level][2];
3666 MLOCK(ErrorMessageLock);
3667 oldFOflag = AM.FileOnlyFlag;
3668 oldPrintType = AO.PrintType;
3669 if ( AC.LogHandle >= 0 ) {
3670 AM.FileOnlyFlag = 1;
3671 AO.PrintType |= PRINTLFILE;
3673 AO.PrintType |= C->
lhs[level][3];
3674 AN.currentTerm = term;
3675 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3676 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3677 MesPrint((
char *)(C->
lhs[level]+5));
3678 AO.PrintType = oldPrintType;
3679 AM.FileOnlyFlag = oldFOflag;
3680 MUNLOCK(ErrorMessageLock);
3681 AC.LogHandle = oldLogHandle;
3685 j = C->
lhs[level][2];
3695 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3696 if ( AC.pfirstnum[ii] == j )
break;
3698 AC.inputnumbers[ii] = AN.ninterms;
3702 if ( AS.MultiThreaded ) {
3704 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3705 if ( AC.pfirstnum[ii] == j )
break;
3707 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3708 LOCK(AP.PreVarLock);
3709 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3710 a = C->
lhs[level]+4;
3711 if ( a[a[-1]] == 0 )
3712 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3715 ,(UBYTE *)(a+a[-1]+1),1);
3719 AC.inputnumbers[ii] = AN.inputnumber;
3721 UNLOCK(AP.PreVarLock);
3726 a = C->
lhs[level]+4;
3727 LOCK(AP.PreVarLock);
3728 if ( a[a[-1]] == 0 )
3729 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3732 ,(UBYTE *)(a+a[-1]+1),1);
3733 UNLOCK(AP.PreVarLock);
3737 AT.WorkPointer = term + *term;
3738 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3739 AT.WorkPointer = term + *term;
3740 if ( *term == 0 )
goto Return0;
3743 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3744 AT.WorkPointer = term + *term;
3747 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3748 WORD oldrepeat = *AN.RepPoint;
3754 AN.cTerm = AN.currentTerm = term;
3755 AT.WorkPointer = term + *term;
3756 *AT.WorkPointer++ = 0;
3757 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3758 AT.WorkPointer = term + *term;
3760 *AN.RepPoint = oldrepeat;
3761 AR.NoCompress = onc;
3762 AR.Eside = oldEside;
3766 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3767 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3768 AT.WorkPointer = term + *term;
3773 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3774 level = C->
lhs[level][2];
3777 ret = execterm(BHEAD term,level);
3778 AN.RepPoint = RepSto;
3780 CC->numrhs = oldtoprhs;
3781 CC->Pointer = CC->Buffer + oldcpointer;
3782 CCC->numrhs = oldatoprhs;
3783 CCC->Pointer = CCC->Buffer + oldacpointer;
3786 AT.WorkPointer = term + *term;
3787 AR.CurDum = DetCurDum(BHEAD term);
3789 case TYPEINEXPRESSION:
3790 {WORD *ll = C->
lhs[level];
3791 int numexprs = (int)(ll[1]-3);
3793 while ( numexprs-- >= 0 ) {
3794 if ( *ll == AR.CurExpr )
break;
3797 if ( numexprs < 0 ) level = C->
lhs[level][2];
3801 AT.WorkPointer = term + *term;
3802 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3804 AT.WorkPointer = term + *term;
3807 AT.WorkPointer = term + *term;
3808 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3810 AT.WorkPointer = term + *term;
3813 AT.WorkPointer = term + *term;
3814 if ( TestUse(term,level) )
goto GenCall;
3815 AT.WorkPointer = term + *term;
3818 AT.WorkPointer = term + *term;
3819 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3820 AT.WorkPointer = term + *term;
3824 AT.WorkPointer = term + *term;
3835 AT.WorkPointer = term + *term;
3836 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3837 AT.WorkPointer = term + *term;
3839 if ( *term == 0 )
goto Return0;
3840 if ( *term != lter ) *AN.RepPoint = 1;
3845 AT.WorkPointer = term + *term;
3846 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3847 AT.WorkPointer = term + *term;
3848 if ( *term != lter ) *AN.RepPoint = 1;
3852 AT.WorkPointer = term + *term;
3853 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3854 AT.WorkPointer = term + *term;
3856 case TYPEARGIMPLODE:
3857 AT.WorkPointer = term + *term;
3858 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3859 AT.WorkPointer = term + *term;
3861 case TYPEARGEXPLODE:
3862 AT.WorkPointer = term + *term;
3863 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3864 AT.WorkPointer = term + *term;
3866 case TYPEDENOMINATORS:
3867 if ( DenToFunction(term,C->
lhs[level][2]) )
goto ReStart;
3869 case TYPEDROPCOEFFICIENT:
3870 DropCoefficient(BHEAD term);
3873 AT.WorkPointer = term + *term;
3874 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3875 AT.WorkPointer = term + *term;
3876 if ( *term == 0 )
goto Return0;
3878 case TYPETOPOLYNOMIAL:
3879 AT.WorkPointer = term + *term;
3880 termout = AT.WorkPointer;
3881 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3882 if ( *termout == 0 )
goto Return0;
3883 i = termout[0]; t = term; NCOPY(t,termout,i);
3884 AT.WorkPointer = term + *term;
3886 case TYPEFROMPOLYNOMIAL:
3887 AT.WorkPointer = term + *term;
3888 termout = AT.WorkPointer;
3889 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3890 if ( *term == 0 )
goto Return0;
3891 i = termout[0]; t = term; NCOPY(t,termout,i);
3892 AT.WorkPointer = term + *term;
3895 level = TestDoLoop(BHEAD C->
lhs[level],level);
3896 if ( level < 0 )
goto GenCall;
3899 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3900 if ( level < 0 )
goto GenCall;
3902 case TYPEDROPSYMBOLS:
3903 DropSymbols(BHEAD term);
3906 AT.WorkPointer = term + *term;
3907 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3908 AT.WorkPointer = term + *term;
3913 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3915 case TYPETOSPECTATOR:
3916 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3918 case TYPECANONICALIZE:
3919 AT.WorkPointer = term + *term;
3920 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3921 AT.WorkPointer = term + *term;
3922 if ( *term == 0 )
goto Return0;
3925 AT.WorkPointer = term + *term;
3926 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3929 AT.WorkPointer = term + *term;
3930 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3932 case TYPESETUSERFLAG:
3933 Expressions[AR.CurExpr].uflags |= 1 << (C->
lhs[level][2]);
3935 case TYPECLEARUSERFLAG:
3936 Expressions[AR.CurExpr].uflags &= ~(1 << (C->
lhs[level][2]));
3939 AT.WorkPointer = term + *term;
3940 if ( AllLoops(BHEAD term,level) )
goto GenCall;
3943 AT.WorkPointer = term + *term;
3944 if ( AllPaths(BHEAD term,level) )
goto GenCall;
3948 AT.WorkPointer = term + *term;
3949 if ( C->
lhs[level][2] == MZV
3950 || C->
lhs[level][2] == EULER
3951 || C->
lhs[level][2] == MZVHALF
3952 || C->
lhs[level][2] == ALLMZVFUNCTIONS
3954 if ( EvaluateEuler(BHEAD term,level,C->
lhs[level][2]) )
goto GenCall;
3957 if ( EvaluateFun(BHEAD term,level,C->
lhs[level]) )
goto GenCall;
3972 AT.WorkPointer = term + *term;
3973 if ( ToFloat(BHEAD term,level) )
goto GenCall;
3976 AT.WorkPointer = term + *term;
3977 if ( ToRat(BHEAD term,level) )
goto GenCall;
3979 case TYPESTRICTROUNDING:
3980 AT.WorkPointer = term + *term;
3981 if ( StrictRounding(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
goto GenCall;
3984 AT.WorkPointer = term + *term;
3985 if ( Chop(BHEAD term,level) )
goto GenCall;
3994 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
3995 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3996 if ( i > 0 ) replac = TestSub(BHEAD term,level);
3998 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
4003AutoGen: i = *AT.TMout;
4004 t = termout = AT.WorkPointer;
4005 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
4007 while ( --i >= 0 ) *t++ = *accum++;
4008 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
4009 AT.WorkPointer = termout;
4013 if ( applyflag ) { TableReset(); applyflag = 0; }
4016 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
4018 if ( AR.TePos >= 0 )
goto AutoGen;
4019 switch ( AN.TeInFun ) {
4021 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
4024 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
4027 if ( DoTableExpansion(term,level) )
goto GenCall;
4030 if ( FactorIn(BHEAD term,level) )
goto GenCall;
4033 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
4036 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
4039 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
4042 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
4045 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
4048 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
4051 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
4054 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
4057 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
4060 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
4063 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
4068 termout = AT.WorkPointer;
4069 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4070 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4071 if (
InFunction(BHEAD term,termout) )
goto GenCall;
4072 AT.WorkPointer = termout + *termout;
4075 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4076 AT.WorkPointer = termout;
4079 else if ( replac > 0 ) {
4083 power = -power; tepos = 0;
4085 extractbuff = AT.TMbuff;
4086 if ( extractbuff == AM.dbufnum ) {
4087 d = DolToTerms(BHEAD replac);
4088 if ( d && d->where != 0 ) {
4090 if ( AT.TMdolfac > 0 ) {
4091 if ( AT.TMdolfac == 1 ) {
4092 if ( d->nfactors ) {
4094 numfac[1] = d->nfactors;
4105 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
4106 MLOCK(ErrorMessageLock);
4107 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
4108 if ( d->nfactors == 1 )
4109 MesPrint(
"There is only one factor");
4111 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
4112 MUNLOCK(ErrorMessageLock);
4115 if ( d->nfactors > 1 ) {
4119 dd = Dollars + replac;
4122 int nummodopt, dtype = -1;
4123 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
4124 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4125 if ( replac == ModOptdollars[nummodopt].number )
break;
4127 if ( nummodopt < NumModOptdollars ) {
4128 dtype = ModOptdollars[nummodopt].type;
4129 if ( dtype == MODLOCAL ) {
4130 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
4136 dsize = dd->factors[AT.TMdolfac-2].size;
4142 numfac[1] = d->factors[AT.TMdolfac-2].value;
4147 if ( numfac[1] < 0 ) {
4148 numfac[1] = -numfac[1];
4149 numfac[3] = -numfac[3];
4153 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
4154 (dsize+1)*
sizeof(WORD),
"Copy of factor");
4155 td1 = dd->factors[AT.TMdolfac-2].where;
4157 d->size = dsize; d->type = DOLTERMS;
4158 NCOPY(td2,td1,dsize);
4162 else if ( d->nfactors == 1 ) {
4163 StartBuf = d->where;
4166 MLOCK(ErrorMessageLock);
4167 if ( d->nfactors == 0 ) {
4168 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
4171 MesPrint(
"Internal error. Illegal number of factors for $-variable");
4173 MUNLOCK(ErrorMessageLock);
4178 else StartBuf = d->where;
4181 d = Dollars + replac;
4182 StartBuf = zeroDollar;
4185 i = DetCommu(d->where);
4187 if ( AS.MultiThreaded ) {
4188 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4189 if ( replac == ModOptdollars[nummodopt].number )
break;
4191 if ( nummodopt < NumModOptdollars ) {
4192 dtype = ModOptdollars[nummodopt].type;
4193 if ( dtype != MODLOCAL && dtype != MODSUM ) {
4194 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
4195 MLOCK(ErrorMessageLock);
4196 MesPrint(
"A dollar variable with modoption max or min can have only one term");
4197 MUNLOCK(ErrorMessageLock);
4200 LOCK(d->pthreadslock);
4207 StartBuf = cbuf[extractbuff].Buffer;
4208 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
4209 i = (WORD)cbuf[extractbuff].CanCommu[replac];
4212 termout = AT.WorkPointer;
4213 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4214 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4215 while ( StartBuf[posisub] ) {
4216 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
4217 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
4218 if (
InsertTerm(BHEAD term,replac,extractbuff,
4219 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
4220 AT.WorkPointer = termout + *termout;
4223 posisub += StartBuf[posisub];
4235 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); }
4236 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
4237 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4238 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4243 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4245 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4247 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4254 StartBuf = cbuf[extractbuff].Buffer;
4257 if ( extractbuff == AT.allbufnum ) {
4258 CBUF *Ce = cbuf + extractbuff;
4262 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); dtype = 0; }
4265 if ( d->nfactors > 1 ) {
4267 for ( j = 0; j < d->nfactors; j++ ) {
4268 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4270 M_free(d->factors,
"Dollar factors");
4272 M_free(d,
"Copy of dollar variable");
4275 AT.WorkPointer = termout;
4277 else if ( i <= 1 ) {
4279 WORD *same, *ow = AT.WorkPointer;
4280 LONG olpw = AT.posWorkPointer;
4282 WantAddLongs(power1);
4283 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4284 same = ++AT.WorkPointer;
4285 a = accum = ( AT.WorkPointer += power1+1 );
4286 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4287 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4288 AT.lWorkSpace[posit] = posisub;
4295 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4297 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4299 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4300 same[1] = *same + 1;
4301 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4302 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4308 i--; posit--; same--;
4311 termout = AT.WorkPointer = a;
4312 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4313 if ( AT.WorkPointer > AT.WorkTop )
4315 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4316 AT.WorkPointer = termout + *termout;
4320 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); }
4321 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4322 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4323 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4327 if (
Generator(BHEAD termout,level) )
goto GenCall;
4329 if ( dtype > 0 && dtype != MODLOCAL ) { dtype = 0;
break; }
4331 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4332 StartBuf = cbuf[extractbuff].Buffer;
4333 i--; posit--; same--;
4337 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); dtype = 0; }
4340 if ( d->nfactors > 1 ) {
4342 for ( j = 0; j < d->nfactors; j++ ) {
4343 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4345 M_free(d->factors,
"Dollar factors");
4347 M_free(d,
"Copy of dollar variable");
4350 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4353 LONG posit, olw, olpw = AT.posWorkPointer;
4354 WantAddLongs(power);
4355 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4356 a = accum = AT.WorkPointer;
4357 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4358 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4359 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4365 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4367 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4368 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4372 AT.lWorkSpace[posit--] = posisub;
4376 termout = AT.WorkPointer = a;
4377 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4378 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4379 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4380 AT.WorkPointer = termout + *termout;
4384 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); }
4385 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4386 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4390 if (
Generator(BHEAD termout,level) )
goto GenCall;
4392 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { dtype = 0;
break; }
4394 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4395 StartBuf = cbuf[extractbuff].Buffer;
4400 if ( dtype > 0 && dtype != MODLOCAL && dtype != MODSUM ) { UNLOCK(d->pthreadslock); dtype = 0; }
4403 if ( d->nfactors > 1 ) {
4405 for ( j = 0; j < d->nfactors; j++ ) {
4406 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4408 M_free(d->factors,
"Dollar factors");
4410 M_free(d,
"Copy of dollar variable");
4413 AT.WorkPointer = accum;
4414 AT.lWorkPointer = olw;
4415 AT.posWorkPointer = olpw;
4420 LONG position, olpw, opw, comprev, extra;
4422 WORD *Freeze, *aa, *dummies;
4426 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4428 SETSTARTPOS(firstpos);
4440 WantAddPointers(power+1);
4441 comprev = opw = AT.pWorkPointer;
4442 AT.pWorkPointer += power+1;
4443 WantAddPositions(power+1);
4444 position = olpw = AT.posWorkPointer;
4445 AT.posWorkPointer += power + 1;
4447 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4449 for ( i = 0; i < power; i++ ) {
4450 PUTZERO(AT.posWorkSpace[position]); position++;
4453 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4454 dummies = AT.WorkPointer;
4455 *dummies++ = AR.CurDum;
4456 AT.WorkPointer += power+2;
4457 accum = AT.WorkPointer;
4458 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4459 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4460 aa = AT.WorkPointer;
4462 i = 0; StartPos = AT.posWorkSpace[position];
4463 dummies[i] = AR.CurDum;
4466 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4467 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4468 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4469 if ( Expressions[replac].numdummies > 0 ) {
4470 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4472 if ( NOTSTARTPOS(firstpos) ) {
4473 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4474 firstpos = AT.posWorkSpace[position];
4485 i++; AT.posWorkSpace[++position] = StartPos;
4486 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4487 dummies[i] = AR.CurDum;
4490 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4491 AR.CurDum = dummies[i];
4495 termout = AT.WorkPointer = a;
4496 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4497 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4498 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4500 AT.WorkPointer = termout + *termout;
4504 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4505 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4510 if (
Generator(BHEAD termout,level) )
goto GenCall;
4513 AR.CurDum = dummies[i];
4516 AT.WorkPointer = aa;
4518 AT.WorkPointer = accum;
4519 AT.posWorkPointer = olpw;
4520 AT.pWorkPointer = opw;
4528 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4529 M_free(renumber->
symb.
lo,
"VarSpace");
4530 M_free(renumber,
"Renumber");
4534 aa = accum = AT.WorkPointer;
4535 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4537 *accum++ = -1; AT.WorkPointer++;
4538 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4539 AT.WorkPointer = aa;
4544 AN.RepPoint = RepSto;
4545 CC->numrhs = oldtoprhs;
4546 CC->Pointer = CC->Buffer + oldcpointer;
4547 CCC->numrhs = oldatoprhs;
4548 CCC->Pointer = CCC->Buffer + oldacpointer;
4552 if ( AM.tracebackflag ) {
4554 MLOCK(ErrorMessageLock);
4555 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4559 while ( --i >= 0 ) {
4560 TalToLine((UWORD)(*termout++));
4561 TokenToLine((UBYTE *)
" ");
4565 MesCall(
"Generator");
4566 MUNLOCK(ErrorMessageLock);
4568 CC->numrhs = oldtoprhs;
4569 CC->Pointer = CC->Buffer + oldcpointer;
4570 CCC->numrhs = oldatoprhs;
4571 CCC->Pointer = CCC->Buffer + oldacpointer;
4574 CC->numrhs = oldtoprhs;
4575 CC->Pointer = CC->Buffer + oldcpointer;
4576 CCC->numrhs = oldatoprhs;
4577 CCC->Pointer = CCC->Buffer + oldacpointer;
4578 MLOCK(ErrorMessageLock);
4580 MUNLOCK(ErrorMessageLock);
5356 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5357 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5358 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0;
5360 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5362 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5365 if ( *t != AR.PolyFun ) {
5367 if ( t == w ) { t += t[1]; w = t; }
5368 else { i = t[1]; NCOPY(w,t,i) }
5372 t2 = t + t[1]; t += FUNHEAD;
5374 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5375 else if ( *t != -SNUMBER )
goto NoLegal;
5378 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5379 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5380 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5381 pow1 += t[ARGHEAD+4];
5386 MLOCK(ErrorMessageLock);
5387 MesPrint(
"Illegal term with divergence in PolyRatFun");
5388 MesCall(
"PolyFunMul");
5389 MUNLOCK(ErrorMessageLock);
5393 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5394 else if ( *t != -SNUMBER )
goto NoLegal;
5397 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5398 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5399 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5400 pow1 -= t[ARGHEAD+4];
5404 if ( t == t2 ) pow += pow1;
5408 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5410 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5411 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5412 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5414 else if ( pow == 1 ) {
5415 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5417 else if ( pow < -1 ) {
5418 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5419 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5420 *w++ = 1; *w++ = 1; *w++ = 3;
5422 else if ( pow == -1 ) {
5423 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5426 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5429 *w++ = 1; *w++ = 1; *w++ = 3;
5431 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5435 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5436 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5437 WORD count1 = 0, count2 = 0, count3;
5438 WORD oldtype = AR.SortType;
5439 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5441 if ( *t == AR.PolyFun ) {
5442 if ( t[2] && dirty == 0 ) {
5447 if ( term[0] == 0 )
return(0);
5452 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5453 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5454 if ( count3 == 2 ) {
5456 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5459 AR.SortType = SORTHIGHFIRST;
5460 t2 = t + t[1]; tt2 = t+FUNHEAD;
5461 while ( tt2 < t2 ) {
5463 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5465 while ( tt1 < tt2 ) {
5466 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5467 AT.WorkPointer = ww;
5472 ww = w;
while ( *ww ) ww += *ww;
5473 if ( ww-w != *tt4-ARGHEAD ) {
5478 WORD *r1 = TermMalloc(
"PolyFunMul");
5479 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5480 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5481 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5482 i = ww-w; ww = w; NCOPY(r4,ww,i);
5483 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5484 *r1 = i = r4-r1; r4 = term; r3 = r1;
5486 t[1] += ii; t1 += ii; *tt4 += ii;
5488 TermFree(r1,
"PolyFunMul");
5491 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5496 else if ( *tt2 <= -FUNCTION ) tt2++;
5499 AR.SortType = oldtype;
5505 if ( count1 <= 1 ) {
goto checkaction; }
5506 if ( AR.PolyFunExp == 1 ) {
5507 t = term + *term; t -= ABS(t[-1]);
5508 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5511 AR.SortType = SORTHIGHFIRST;
5515 if ( *term == 0 )
return(retval);
5516 AR.SortType = oldtype;
5519 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5521 if ( *t == AR.PolyFun ) {
5522 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5523 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5524 if ( count3 == 2 ) {
5530 if ( count1 >= count2 ) {
5533 if ( *t == AR.PolyFun ) {
5536 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5539 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5548 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5550 if ( action ) retval = action;
5554 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5555 AT.WorkPointer = term + *term;
5556 GETSTOP(term,tstop);
5558 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5559 while ( t < tstop && *t == AR.PolyFun ) {
5560 if ( t[1] > FUNHEAD ) {
5561 if ( t[FUNHEAD] < 0 ) {
5562 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5563 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5564 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5571 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5576 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5579 while ( t < tstop && *t == AR.PolyFun ) {
5580 if ( t[1] > FUNHEAD ) {
5581 if ( t[FUNHEAD] < 0 ) {
5582 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5583 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5584 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5591 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5596 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5604 n1 = 1; arg1 = AT.WorkPointer;
5605 ToGeneral(t,arg1,1);
5606 AT.WorkPointer = arg1 + *arg1;
5610 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5611 while ( t < t1 ) { n1++; t += *t; }
5615 n2 = 1; arg2 = AT.WorkPointer;
5616 ToGeneral(t,arg2,1);
5617 AT.WorkPointer = arg2 + *arg2;
5621 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5622 while ( t < t2 ) { n2++; t += *t; }
5634 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5641 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5643 if ( minp1 > 0 ) minp1 = 0;
5645 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5646 if ( minp1 > 0 ) minp1 = 0;
5649 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5650 if ( t1[4] < minp1 ) minp1 = t1[4];
5653 MesPrint(
"Illegal term in expanded polyratfun.");
5659 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5661 if ( minp2 > 0 ) minp2 = 0;
5663 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5664 if ( minp2 > 0 ) minp2 = 0;
5667 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5668 if ( t2[4] < minp2 ) minp2 = t2[4];
5671 MesPrint(
"Illegal term in expanded polyratfun.");
5676 AR.PolyFunPow += minp1+minp2;
5678 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5679 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5684 while ( t < tt1 ) *m++ = *t++;
5687 while ( t < tt2 ) *m++ = *t++;
5688 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5693 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5694 l3 = REDLENG(m[-1]);
5698 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5700 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5702 if ( l4 == 0 )
continue;
5705 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5707 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5716 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5718 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5721 if ( l3 == 0 )
continue;
5731 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5732 AR.PolyFunPow = OldPolyFunPow;
5739 while ( *t ) t += *t;
5743 while ( t1 < fun1 ) *t++ = *t1++;
5746 *t++ = FUNHEAD+ARGHEAD+n1;
5753 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5754 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5755 else t2[FUNHEAD] = FUNHEAD+1;
5758 t1 = fun1 + fun1[1];
5759 while ( t1 < fun2 ) *t++ = *t1++;
5760 t1 = fun2 + fun2[1];
5762 while ( t1 < t2 ) *t++ = *t1++;
5763 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5764 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5765 MLOCK(ErrorMessageLock);
5766 MesPrint(
"Term too complex (%d words). MaxTermSize (%l words) is too small.", n1, AM.MaxTer/(LONG)
sizeof(WORD) );
5769 m = term; t = AT.WorkPointer;
5774 AT.WorkPointer = term + *term;
5775 if ( action && noac ) {
5776 if ( Normalize(BHEAD term) )
goto PolyCall;
5777 AT.WorkPointer = term + *term;
5781 MLOCK(ErrorMessageLock);
5783 AR.PolyFunPow = OldPolyFunPow;
5784 MesCall(
"PolyFunMul");
5785 MUNLOCK(ErrorMessageLock);