
%  The disposition of the particular mode changers follows the
% manual listing:

%Object type:
%	Ring (default)				SETRINGOBJECT()
%	Module					SETMODULEOBJECT()
%	Two modules (for calculating Tor(*,*))	SETTWOMODULESOBJECT()
%	Factor Algebra ( = Residue class ring)	SETFACTALGOBJECT()
%  Minor variants:
%	Right, Left, 2-sided module?
%	Autoadding of relations?		SETAUTOADDRELATIONSTATE(state)
%		Yes!				AUTOADDRELATIONS()
%		No, absolutely not!		NOAUTOADDRELATIONS()
%		Perhaps, but not right now!	CANCELAUTOADDRELATIONSSETTINGS()
%	Permit linear or constant terms?	SETLOWTERMSHANDLING(state)
%		Yes!				state := SAFE
%		No, since using fast tricks	state := QUICK
%
%Resolution calculations type:
%	None (default)				SETRESOLUTIONTYPE(NIL)
%	Anick					SETRESOLUTIONTYPE(ANICK)
%
%Anick minor modes (only present when the module anick is loaded):
%	In what form is tenspols (Anick resolution elements) printed?
%		Semidistributed			PRINTTENSORPOLSSEMIDISTRIBUTED()
%		(Fully) distributed		PRINTTENSORPOLSDISTRIBUTED()
%	The beginning, tensor sign, and end of a tensor product term:
%					SETTENSPOLPRTSTRINGS(string,string,string)
%	The chain link demarkation string	SETEDGESTRING(string)
%	Should this string be printed?		SETEDGESTRINGPRINTING(boole)
%	Should the Betti numbers of the homology be calculated at each degree end?
%		Yes, and immediately displayed!	      ONFLYBETTI(T)
%		Yes, but not automatically displayed  CALCBETTI(T) + ONFLYBETTI(NIL)
%		No				      CALCBETTI(NIL)
%
%Polynomial ring (or correspondingly for other objects) set-up:
%	Type of ring (or correpondingly);	SETRINGTYPE(),COMMIFY(),
%						NONCOMMIFY()
%	Commutative DEG-REVLEX (default);	COMMIFY(),DEGREVLEXIFY()
%	Commutative DEG-LEX;			  - " -  ,DEGLEXIFY()
%	Commutative MATRIX;			  - " -  ,MATRIXIFY();
%		set the matrix with			SETORDERMATRIX(llint)
%	Non-commutative DEG-LEFTLEX (default);	NONCOMMIFY(),DEGLEFTLEXIFY()
%	Non-commutative ELIM-DEG-LEFTLEX	NONCOMMIFY(),ELIMORDER()
%  Minor variants:
%	Ordinary ( = unit) weights		CLEARWEIGHTS(),SETWEIGHTS()
%	Alternative weights			SETWEIGHTS()
%	Homogenising variable:			SETHOMOGVARIABLE()
%
%Coefficient arithmetics:
%	Characteristic 0, arbitrary integers (default); SETMODULUS(0)
%	Characteristic 0, only inums;		NOBIGNUMS, - " -
%	Characteristic 2;			SETMODULUS(2)
%	Odd characteristic, ordinary inum arithmetics;  SETMODULUS(pr)
%	Odd characteristic, ordinary bignum arithmetics; - " -
%	Odd characteristic, logarithm table inum arithmetics; - " -,
%						MODLOGARITHMS
%	(Arbitrary Reduce Standard Forms;	SETREDUCESFCOEFFS()
%	 only available in bergman-under-reduce)
%
%Fundamental strategy:				SETSTRATEGY(clause)
%	Default, ordinary (Buchberger, Bergman) (with degree first)
%						SETDEFAULTSTRATEGY()
%	Rabbit (jumping back to lower degrees)	SETRABBITSTRATEGY()
%	Staggered with substance (SAWS).	SETSAWSSTRATEGY()
%  Major mode modifications:
%	Work degree by degree (irrespective of order)	SETDEGREEWISE()
%	   Instead, work item for item (NOT compatible with Rabbit or SAWS)
%						SETITEMWISE()
%	Are the found leading monomials of Groebner basis elements stable?
%						SETSTABILITY(T,NIL),
%						STABILISE(),DESTABILISE()
%  Minor mode modifications:
%	    with immediate full autoreduction (default);
%						IMMEDIATEFULLREDUCTION
%	    without immediate full autoreduction;    -  "  -
%	Densely or sparsely performed factoring out of contents:
%						DENSECONTENTS(),
%						SPARSECONTENTS()
%	Ordinary or Hilbert series limit interruption strategy:
%						ORDNGBESTRATEGY(),
%						MINHILBLIMITSTRATEGY()
%	   (or use SETINTERRUPTSTRATEGY)
%	Calculation start and end points:	SETMINDEG(),
%						GETMINDEG(),
%						SETMAXDEG(),
%						GETMAXDEG().
%	Customised strategy procedures read (if defined):
%						SETCUSTSTRATEGY
%	   combined with defining one or more of
%	   CUSTNEWCDEGFIX, CUSTNEWINPUTGBEFIND, CUSTCRITPAIRTONEWGBE,
%	   CUSTENDDEGREE, CUSTENDDEGREECRITPAIRFIND, CUSTITEMCRITPAIRFIND.
%
%Input mode minor modification:
%	(No) case sensitivity in algebraic input SETCASESENSALGIN (NIL/T)
%
%Output mode:
%	Ordinary algebraic form (default):	SETALGOUTMODE(ALG)
%	Lisp form:				SETALGOUTMODE(LISP)
%	Macaulay-like algebraic form:		SETALGOUTMODE(MACAULAY)
%

%Output time modes should be brought here: Degreewise and/or itemwise
%and/or finally.
%

%  Minor mode modifications:
%	Collect common factors to exponents (default):
%						EXPTSPRINTMODE()
%	Print each factor separately:		NOEXPTSPRINTMODE()
%
%	If the associated monomial ring Poincare-Betti series is calculated
%	degree by degree, should it be printed automatically or not:
%					SETIMMEDIATEASSOCRINGPBDISPLAY(NIL/T)
%	Should existing files if possible be overwritten?
%						SETOVERWRITE(NIL/T)
%	Customised display procedures read (if defined):
%						SETCUSTDISPLAY
%	   combined with defining one or more of
%	   CUSTDISPLAYINIT, DEGREEENDDISPLAY, CUSTCLEARCDEGDISPLAY,
%	   CUSTCLEARCDEGOBSTRDISPLAY, and HSERIESMINCRITDISPLAY.
%
%Debugging mode modifications:
%	If an alertchannel is open, and called by FILEALERT with second
%	argument MAYBE, should the channel be closed?  SETDIRECTALERTCLOSING (NIL/T)
%	Setup checkers print (not) failure information as warnings to the
%	write selected channel.			SETCHECKFAILUREDISPLAY(NIL/T)
%	The following option should only be turned on, if bergman is
%	compiled under Psl or Reduce:
%	Should we cause continuable error loops at entries and exits
%	of procedures which are traced by MYTRACE or MYTR1?
%						SETACTIVETRACEBREAKS(NIL/T)

%   Mode influencing user available switches - a complete list.
%   (However, note that we plan to replace them by mode changers!)



%  Major mode modifications:
%	Work degree by degree (irrespective of order)	SETDEGREEWISE()
%	   Instead, work item for item (NOT compatible with Rabbit or SAWS)
%						SETITEMWISE()
%	Are the found leading monomials of Groebner basis elements stable?
%						SETSTABILITY(T,NIL),
%						STABILISE(),DESTABILISE()

(DefineSWLHFEXPR SETPROCESS (GETPROCESS) !$!#ProcessingGbes!#!*)

(SETQ !$!#ProcessingGbes!#!*
 '((DEGREEWISE . SETDEGREEWISE)
   (ITEMWISE . SETITEMWISE)))

(DE GETPROCESS ()
 (COND	(!*!&DegreeWise!# 'DEGREEWISE)
	(T 'ITEMWISE)) )

(DE SETDEGREEWISE ()
 (PROG	(rt !*USERMODE !*REDEFMSG)
	(SETQ rt !*!&DegreeWise!#)
	(COPYD 'DEGORITEMLIST2LIST 'DEGLIST2LIST)
	(COPYD 'SortlPol 'DegSortlPol)
	(MainDegreewise)
	(StratDegreewise)
	(ReductDegreewise)
	(EVAL (LIST 'SETSTABILITY (GETSTABILITY)))
	(ON !&DegreeWise!#)
	(RETURN rt)
 ))

(DE SETITEMWISE ()
 (PROG	(rt !*USERMODE !*REDEFMSG)
	(SETQ rt !*!&DegreeWise!#)
	(COPYD 'DEGORITEMLIST2LIST 'IBIDNOOPFCN)
	(COPYD 'SortlPol 'ItemSortlPol)
	(MainItemwise)
	(StratItemwise)
	(ReductItemwise)
	(EVAL (LIST 'SETSTABILITY (GETSTABILITY)))
	(OFF !&DegreeWise!#)
	(RETURN rt)
 ))


(DE STABILISE ()
 (PROG	(rt !*USERMODE !*REDEFMSG)
	(SETQ rt (GETSTABILITY))
	(MainStabilise)
	(StratStabilise)
	(ReductStabilise)
	(ON !&!#Stable!#)
	(RETURN rt) ))

(DE DESTABILISE ()
 (PROG	(rt !*USERMODE !*REDEFMSG)
	(SETQ rt (GETSTABILITY))
	(MainDestabilise)
	(StratDestabilise)
	(ReductDestabilise)
	(OFF !&!#Stable!#)
	(RETURN rt) ))

%# GETSTABILITY () : boolean;
(DE GETSTABILITY ()  (PROGN !*!&!#Stable!#))


%# SETSTABILITY (sexpr) : boolean ; FEXPR
(DF SETSTABILITY (u)
 (COND	((OR (NOT u) (AND (PAIRP u) (OR (NOT (CAR u)) (EQ (CAR u) 'OFF))))
	 (DESTABILISE))
	(T
	 (STABILISE)) ))

% Initialisation:

(SETQ !*!&!#Stable!# T)

%# GETDEGREEPRINTOUTPUT (sexpr) : boolean ;
(DE GETDEGREEPRINTOUTPUT () (PROGN !*DEGREEPRINTOUTPUT))

%# SETDEGREEPRINTOUTPUT (sexpr) : boolean ; FEXPR
(DF SETDEGREEPRINTOUTPUT (u)
 (PROG	(rt)
	(SETQ rt (GETDEGREEPRINTOUTPUT))
	(COND ((OR (NOT u)
		   (AND (PAIRP u) (OR (NOT (CAR u)) (EQ (CAR u) 'OFF))))
	       (OFF DEGREEPRINTOUTPUT))
	      (T
	       (ON DEGREEPRINTOUTPUT)))
	(RETURN rt) ))


%# GETITEMPRINTOUTPUT (sexpr) : boolean ;
(DE GETITEMPRINTOUTPUT () (PROGN !$!&ItemPrinting!#))

%# SETITEMPRINTOUTPUT (sexpr) : boolean ; FEXPR
(DF SETITEMPRINTOUTPUT (u)
 (PROG	(rt)
	(SETQ rt (GETITEMPRINTOUTPUT))
	(COND ((OR (NOT u)
		   (AND (PAIRP u) (OR (NOT (CAR u)) (EQ (CAR u) 'OFF))))
	       (SETQ !$!&ItemPrinting!# NIL))
	      ((OR (EQ u 'MAYBE)
		   (AND (PAIRP u) (EQ (CAR u) 'MAYBE)))
	       (SETQ !$!&ItemPrinting!# 'MAYBE))
	      (T
	       (SETQ !$!&ItemPrinting!# T)))
	(RETURN rt) ))


%# GETSAVEDEGREE (sexpr) : boolean ;
(DE GETSAVEDEGREE () (PROGN !*SAVEDEGREE))

%# SETSAVEDEGREE (sexpr) : boolean ; FEXPR
(DF SETSAVEDEGREE (u)
 (PROG	(rt)
	(SETQ rt (GETSAVEDEGREE))
	(COND ((OR (NOT u)
		   (AND (PAIRP u) (OR (NOT (CAR u)) (EQ (CAR u) 'OFF))))
	       (OFF SAVEDEGREE))
	      (T
	       (ON SAVEDEGREE)))
	(RETURN rt) ))


From inout:

(DF DEGREEOUTPREPARE (fil)
 (COND	((NOT fil)
	 (SETSAVEDEGREE T)
	 (SETQ GBasOutChan NIL))
	((NOT (PAIRP fil))
	 (PRIN2 "***** Bad input to DEGREEOUTPREPARE") (TERPRI))
	(T
	 (SETSAVEDEGREE T)
	 (SETQ GBasOutChan (CHECKOUTFILE (CAR fil))))) )


From main:


In stabledegGROEBNERKERNEL:

 MlEnd
  (COND ((AND (GETCUSTSTRATEGY) (DEFP 'CUSTENDDEGREE) (CUSTENDDEGREE))
	 (GO Ml)))
  (MAPC (CDR cGBasis) (FUNCTION FixGbe))
  (COND (!*CUSTSHOW (DEGREEENDDISPLAY))
	((COND (!*PBSERIES (TDEGREECALCULATEPBSERIES cDeg))))
	(!*SAVEDEGREE (DEGREEOUTPUT)))


%# GROEBNERFINISH () : - ;
(DE GROEBNERFINISH ()
  (COND ((AND (GETSAVEDEGREE) (EQ (GETPROCESS) 'DEGREEWISE))
	 (ENDDEGREEOUTPUT))
	((AND (GETITEMPRINTOUTPUT)
	      (OR (EQ (GETPROCESS) 'ITEMWISE) (EQ (GETITEMPRINTOUTPUT) T)))
	 (ENDITEMOUTPUT))
	((NOT !*CUSTSHOW)
	 (BIGOUTPUT))) )


Similarly, but less updated, STAGGERKERNEL and STAGGERFINISH, in stg:

(DE STAGGERFINISH ()
 (PROG	(OldChan)
	(COND (!*SAVEDEGREE (STAGGERENDDEGREEOUTPUT)))
	(MAPC (CDR GBasis)
	      (FUNCTION (LAMBDA (mon)
				(DestructRedor2Redand (Mpt mon)))))
	(AUTOREDUCESTAGGEROUTPUT)
	(COND (!&!*StgFinalOutputChan
	       (SETQ OldChan (WRS !&!*StgFinalOutputChan))))
	(COND (!*DEGREEPRINTOUTPUT
	       (DEGREEBIGOUTPUT DegGBasis))
	      (T
	       (BIGOUTPUT)))
	(PRIN2 "Done") (TERPRI)
	(COND (OldChan
	       (CLOSE (WRS OldChan)))) ))
