#include "def.h"
#include "macro.h"

static INT ausgabe_koeff();
static INT write_polynom();




/* es folgen zwei globale variablen */
	INT zeilenposition;
	INT texposition;
	INT texmath_yn; /* 1 in mathmode */ /* 0 not in mathmode */
	INT scanoutput_yn; /* 1 no output */ /* 0 bitte output */

INT print_type(a) OBJECTKIND a;
/* AK 280294 */
	{
	OP b;
	INT erg = OK;
	b = callocobject();
	C_O_K(b,a);
	erg += printobjectkind(b);
	C_O_K(b,EMPTY);
	erg += SYMfreeall(b);
	ENDR("print_type");
	}

INT printobjectkind(a) OP a;
/* AK 270689 V1.0 */ /* AK 020290 V1.1 */ /* AK 130891 V1.3 */
	{
	fprintf(stderr,"kind of object is ");
	if (a == NULL) fprintf(stderr,"NULL\n");
	switch(S_O_K(a))
		{
	case AUG_PART: return(fprintf(stderr,"augpart\n"));
	case BARPERM: return(fprintf(stderr,"barred permutation\n"));
	case BINTREE: return(fprintf(stderr,"bintree\n"));
	case BITVECTOR: return(fprintf(stderr,"bitvector\n"));
	case BRUCH: return(fprintf(stderr,"bruch\n"));
	case COMP: return(fprintf(stderr,"composition\n"));
	case CYCLOTOMIC: return(fprintf(stderr,"cyclotomic\n"));
	case ELM_SYM: return(fprintf(stderr,"elementary symmetric function\n"));
	case FF: return(fprintf(stderr,"finite field element\n"));
	case GRAL: return(fprintf(stderr,"groupalgebra\n"));
	case HOM_SYM: return(fprintf(stderr,"complete symmetric function\n"));
	case INTEGER: return(fprintf(stderr,"integer\n"));
	case KOSTKA: return(fprintf(stderr,"kostka\n"));
	case KRANZ: return(fprintf(stderr,"kranz\n"));
	case KRANZTYPUS: return(fprintf(stderr,"kranztypus\n"));
        case LAURENT: return(fprintf(stderr,"laurent\n"));
	case SYMLIST: return(fprintf(stderr,"list\n"));
	case LONGINT: return(fprintf(stderr,"longint\n"));
	case MATRIX: return(fprintf(stderr,"matrix\n"));
	case MONOM: return(fprintf(stderr,"monom\n"));
	case MONOMIAL: return(fprintf(stderr,"monomial symmetric function\n"));
	case MONOPOLY: return(fprintf(stderr,"monopoly\n"));
	case PARTITION: return(fprintf(stderr,"partition\n"));
	case PERMUTATION: return(fprintf(stderr,"permutation\n"));
	case POLYNOM: return(fprintf(stderr,"polynom\n"));
	case POW_SYM: return(fprintf(stderr,"powersum symmetric function\n"));
	case REIHE: return(fprintf(stderr,"power-series\n"));
	case SCHUR: return(fprintf(stderr,"schur-polynom\n"));
	case SCHUBERT: return(fprintf(stderr,"schubert-polynom\n"));
	case SKEWPARTITION: return(fprintf(stderr,"skewpartition\n"));
	case SQ_RADICAL: return(fprintf(stderr,"square-radical\n"));
	case SYMCHAR: return(fprintf(stderr,"symchar\n"));
	case TABLEAUX: return(fprintf(stderr,"tableaux\n"));
	case VECTOR: return(fprintf(stderr,"vector\n"));
	case INTEGERVECTOR: return(fprintf(stderr,"integervector\n"));
	case 0: return(fprintf(stderr,"empty-object\n"));
	default: fprintf(stderr," %d ",S_O_K(a));
		return(fprintf(stderr,"unknown\n"));
		};
	}

INT ferrers(obj) OP obj;
/* AK 290986 */ /* AK 010889 V1.0 */ /* AK 020290 V1.1 */
/* AK 130891 V1.3 */
	{
	INT erg = OK;
	switch(S_O_K(obj)) {
#ifdef PARTTRUE
		case PARTITION: erg +=  ferrers_partition(obj); break;
#endif /* PARTTRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: erg +=  ferrers_skewpartition(obj); break;
#endif /* SKEWPARTTRUE */
		default:  
			erg += WTO("ferrers",obj); break;
		}
	ENDR("ferrers");
	}


INT scan_printeingabe(text) char *text;
/* AK 250194 */
	{
	extern INT scanoutput_yn; /* 1 no output */ /* 0 bitte output */
	if (scanoutput_yn == (INT) 0)
		return printeingabe(text);
	return OK;
	}

INT printeingabe(text) char *text;
/* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 070291 V1.2 prints to stderr instead to stdout , returns OK */
/* AK 130891 V1.3 */
	{ 
	fprintf(stderr,"%s\n",text); 
	return OK;
	}

INT sprint(string, obj) char *string; OP obj;
/* AK 020195 */
	{
	INT erg = OK;
	if (obj == NULL)
		{
		erg += NOP("sprint");
		goto spe;
		}
	switch(S_O_K(obj))
		{
		case INTEGER: erg += sprint_integer(string,obj);break;
#ifdef LONGINTTRUE
		case LONGINT: erg += sprint_longint(string,obj);break;
#endif /* LONGINTTRUE */
#ifdef PARTTRUE
		case PARTITION: erg += sprint_partition(string,obj);break;
#endif /* PARTTRUE */

		default: erg += WTO("sprint",obj); break;
		}
spe:
	ENDR("sprint");
	}

INT fprint(of,obj) FILE	*of; OP obj;
/* AK 211186 */ /* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 050891 V1.3 */
	{
	INT erg = OK;
	if (obj == NULL) 
		{
		erg += NOP("fprint");
		goto fe;
		}
	switch(S_O_K(obj))
		{
#ifdef PARTTRUE
		case AUG_PART: 
		case PARTITION:  erg += fprint_partition(of,obj);break;
#endif /* PARTTRUE */
#ifdef BINTREETRUE
		case BINTREE:  erg += fprint_bintree(of,obj);break;
#endif /* BINTREETRUE */
#ifdef BRUCHTRUE
		case BRUCH:  erg += fprint_bruch(of,obj);break;
#endif /* BRUCHTRUE */
#ifdef FFTRUE
		case FF:  erg += fprint_ff(of,obj);break;
#endif /* FFTRUE */
#ifdef INTEGERTRUE
		case INTEGER:  erg += fprint_integer(of,obj);break;
#endif /* INTEGERTRUE */
#ifdef LISTTRUE
		case ELM_SYM: case MONOMIAL: case HOM_SYM: case POW_SYM:
		case GRAL: case MONOPOLY: case POLYNOM: case SCHUBERT:
		case SCHUR: case SYMLIST:  
			erg += fprint_list(of,obj);break;
#endif /* LISTTRUE */
#ifdef LONGINTTRUE
		case LONGINT:  erg += fprint_longint(of,obj);break;
#endif /* LONGINTTRUE */
#ifdef MATRIXTRUE
		case KOSTKA:
		case KRANZTYPUS:
		case MATRIX:  erg += fprint_matrix(of,obj);break;
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM:  erg += fprint_monom(of,obj);break;
#endif /* MONOMTRUE */
#ifdef PERMTRUE
		case PERMUTATION:  erg += fprint_permutation(of,obj);
				break;
#endif /* PERMTRUE */
#ifdef REIHETRUE
		case REIHE:  erg += fprint_reihe(of,obj);
				break;
#endif /* REIHETRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: /*020488 */
			 erg += fprint_skewpartition(of,obj);break;
#endif /* SKEWPARTTRUE */
#ifdef CHARTRUE
		case SYMCHAR: /*110488 */
			 erg += fprint_symchar(of,obj);break;
#endif /* CHARTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: /*020488 */
			 erg += fprint_tableaux(of,obj);break;
#endif /* TABLEAUXTRUE */
#ifdef VECTORTRUE
		case COMP:
		case WORD:
		case KRANZ:
		case INTEGERVECTOR:
		case LAURENT:
		case VECTOR:    erg += fprint_vector(of,obj);break;
		case BITVECTOR:    erg += fprint_bitvector(of,obj);break;
#endif /* VECTORTRUE */
#ifdef	NUMBERTRUE
		case SQ_RADICAL:
		case CYCLOTOMIC:  erg += fprint_number(of,obj);break;
#endif /* NUMBERTRUE */
		case 0: 	
			fprintf(of,"#");
			/* AK 310889 */
			if (of == stdout) 
				zeilenposition++;
		 	break;
		default: erg += WTO("fprint",obj); 
			break;
		};
fe:
	ENDR("fprint");
	}

INT display(obj) OP obj;
/* AK 271087 */ /* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 130891 V1.3 */
	{
	INT erg = OK;
	if (obj == NULL) 
		{
		erg += NOP("display");
		goto de;
		}
	switch(S_O_K(obj))
		{
#ifdef SCHUBERTTRUE
		case SCHUBERT: erg += display_schubert(obj);
			break;
#endif /* SCHUBERTTRUE */
		case 0: return(printf("#\n"));
		default: 
			erg += WTO("display",obj);
			break;
		};
de:
	if (erg != OK)
		EDC("display");
	return erg;
	}
 
INT fprintln(f,obj) FILE *f; OP obj;
/* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 130891 V1.3 */
	{
	INT erg = OK;
	erg += fprint(f,obj); 
	fprintf(f,"\n"); 
	if (f == stdout)
		zeilenposition = 0L;
	ENDR("fprintln");
	}



INT print(obj) OP obj;
/* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 130891 V1.3 */
	{
	INT erg = OK;
	if (zeilenposition > 60L)
		{ 
		printf("\n"); 
		zeilenposition = 0L; 
		};
	erg += fprint(stdout,obj);
	ENDR("print");
	}



INT println(obj) OP obj;
/* AK 270689 V1.0 */ /* AK 020290 V1.1 */
/* AK 130891 V1.3 */
	{
	INT erg = OK;
	erg += print(obj); 
	printf("\n");
	zeilenposition = (INT)0;
	ENDR("println");
	}


INT skip_comment()
{
	int i;
/* here we insert code to implement comments *//* AK 210395 */
sa:
        i = getc(stdin);
        if (i == EOF)
                return error("scan:EOF encountered");
        else if (i==' ') goto sa;
        else if (i=='\t') goto sa;
        else if (i=='#') /* comments til the end of line */
                {
                while ((i=getc(stdin)) != '\n');
                goto sa;
                }
        else ungetc(i,stdin);
}


INT scan(kind,obj) OBJECTKIND kind; OP obj;
/* AK 270787 */ /* AK 280689 V1.0 */ /* AK 020290 V1.1 */ /* AK 050891 V1.3 */
	{
	INT erg = OK;

	if (obj == NULL) 
		return NOP("scan");
	if (not EMPTYP(obj)) 
		erg += freeself(obj);

	switch(kind)
		{
#ifdef BRUCHTRUE
		case BRUCH: erg += scan_bruch(obj); break;
#endif /* BRUCHTRUE */
#ifdef CYCLOTRUE
		case CYCLOTOMIC: erg += scan_cyclo(obj); break;
#endif /* CYCLOTRUE */
#ifdef ELMSYMTRUE
		case ELM_SYM: erg += scan_elmsym(obj); break;
#endif /* ELMSYMTRUE */
#ifdef GRALTRUE
		case GRAL: erg += scan_gral(obj); break;
#endif /* GRALTRUE */
#ifdef FFTRUE
		case FF: erg += scan_ff(obj); break;
#endif /* FFTRUE */
#ifdef HOMSYMTRUE
		case HOM_SYM: erg += scan_homsym(obj); break;
#endif /* HOMSYMTRUE */
#ifdef INTEGERTRUE
		case INTEGER: erg += scan_integer(obj); break;
#endif /* INTEGERTRUE */
#ifdef VECTORTRUE
		case INTEGERVECTOR: erg += scan_integervector(obj); break;
#endif /* VECTORTRUE */
#ifdef MATRIXTRUE
		case INTEGERMATRIX: erg += scan_integermatrix(obj); break;
#endif /* MATRIXTRUE */
#ifdef KOSTKATRUE
		case KOSTKA: erg += scan_kostka(obj); break;
#endif /* KOSTKATRUE */
#ifdef KRANZTRUE
		case KRANZ: erg += scan_kranz(obj); break;
#endif /* KRANZTRUE */
#ifdef LAURENTTRUE
                case LAURENT: erg += scan_laurent(obj); break;
#endif /* LAURENTTRUE */
#ifdef LISTTRUE
		case SYMLIST: erg += scan_list(obj,(OBJECTKIND)0); break;
#endif /* LISTTRUE */
#ifdef LONGINTTRUE
		case LONGINT: erg += scan_longint(obj); break;
#endif /* LONGINTTRUE */
#ifdef MATRIXTRUE
		case KRANZTYPUS:
			erg += scan_matrix(obj);
			C_O_K(obj,KRANZTYPUS);
			break;
		case MATRIX: erg += scan_matrix(obj); break;
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM: erg += scan_monom(obj); break;
#endif /* MONOMTRUE */
#ifdef MONOMIALTRUE
		case MONOMIAL: erg += scan_monomial(obj); break;
#endif /* MONOMIALTRUE */
#ifdef MONOPOLYTRUE
		case MONOPOLY: erg += scan_monopoly(obj); break;
#endif /* MONOPOLYTRUE */
#ifdef PARTTRUE
		case PARTITION: erg += scan_partition(obj); break;
#endif /* PARTTRUE */
#ifdef PERMTRUE
		case BARPERM:	erg += scan_bar(obj); break;
		case PERMUTATION: erg += scan_permutation(obj); break;
#endif /* PERMTRUE */
#ifdef POLYTRUE
		case FASTPOLYNOM: erg += scan_fastpolynom(obj); break;
		case POLYNOM: erg += scan_polynom(obj); break;
#endif /* POLYTRUE */
#ifdef POWSYMTRUE
		case POW_SYM: erg += scan_powsym(obj); break;
#endif /* POWSYMTRUE */
#ifdef REIHETRUE
		case REIHE: erg += scan_reihe(obj); break;
#endif /* REIHETRUE */
#ifdef SCHUBERTTRUE
		case SCHUBERT: erg += scan_schubert(obj); break;
#endif /* SCHUBERTTRUE */
#ifdef SCHURTRUE
		case SCHUR: erg += scan_schur(obj); break;
#endif /* SCHURTRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: erg += scan_skewpartition(obj); break;
#endif /* SKEWPARTTRUE */
#ifdef SQRADTRUE
		case SQ_RADICAL: erg += scan_sqrad(obj); break;
#endif /* SQRADTRUE */
#ifdef CHARTRUE
		case SYMCHAR: erg += scan_symchar(obj); break;
#endif /* CHARTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: erg += scan_tableaux(obj); break;
#endif /* TABLEAUXTRUE */
#ifdef VECTORTRUE
		case VECTOR: erg += scan_vector(obj); break;
		case BITVECTOR: erg += scan_bitvector(obj); break;
#endif /* VECTORTRUE */
#ifdef WORDTRUE
		case WORD: erg += scan_word(obj); break;
#endif /* WORDTRUE */
		default:
			{
			fprintf(stderr,"kind = %d\n",kind);
			error("scan:wrong type");
			return(ERROR);
			}
		};
	ENDR("scan");
	}

INT sscan(t,kind,obj) char *t; OBJECTKIND kind; OP obj;
/* AK 301293 */
	{
	INT erg = OK;
	if (obj == NULL) 
		return NOP("sscan");
	if (not EMPTYP(obj)) 
		erg += freeself(obj);
	switch(kind)
		{
#ifdef INTEGERTRUE
		case INTEGER: erg += sscan_integer(t,obj); break;
#endif /* INTEGERTRUE */
#ifdef VECTORTRUE
		case INTEGERVECTOR: erg += sscan_integervector(t,obj); break;
#endif /* VECTORTRUE */
#ifdef LONGINTTRUE
		case LONGINT: erg += sscan_longint(t,obj); break;
#endif /* LONGINTTRUE */
#ifdef PARTTRUE
		case PARTITION: erg += sscan_partition(t,obj); break;
#endif /* PARTTRUE */
#ifdef PERMTRUE
		case BARPERM: erg += sscan_bar(t,obj); break;
		case PERMUTATION: erg += sscan_permutation(t,obj); break;
#endif /* PERMTRUE */
#ifdef SCHURTRUE
		case SCHUR: erg += sscan_schur(t,obj); break;
#endif /* SCHURTRUE */

#ifdef UNDEF
#ifdef BRUCHTRUE
		case BRUCH: erg += sscan_bruch(t,obj); break;
#endif /* BRUCHTRUE */
#ifdef CYCLOTRUE
		case CYCLOTOMIC: erg += sscan_cyclo(t,obj); break;
#endif /* CYCLOTRUE */
#ifdef ELMSYMTRUE
		case ELM_SYM: erg += sscan_elmsym(t,obj); break;
#endif /* ELMSYMTRUE */
#ifdef GRALTRUE
		case GRAL: erg += sscan_gral(t,obj); break;
#endif /* GRALTRUE */
#ifdef FFTRUE
		case FF: erg += sscan_ff(t,obj); break;
#endif /* FFTRUE */
#ifdef HOMSYMTRUE
		case HOM_SYM: erg += sscan_homsym(t,obj); break;
#endif /* HOMSYMTRUE */
#ifdef MATRIXTRUE
		case INTEGERMATRIX: erg += sscan_integermatrix(t,obj); break;
#endif /* MATRIXTRUE */
#ifdef KOSTKATRUE
		case KOSTKA: erg += sscan_kostka(t,obj); break;
#endif /* KOSTKATRUE */
#ifdef KRANZTRUE
		case KRANZ: erg += sscan_kranz(t,obj); break;
#endif /* KRANZTRUE */
#ifdef LISTTRUE
		case SYMLIST: erg += sscan_list(t,obj); break;
#endif /* LISTTRUE */
#ifdef MATRIXTRUE
		case KRANZTYPUS:
			erg += sscan_matrix(t,obj);
			C_O_K(obj,KRANZTYPUS);
			break;
		case MATRIX: erg += sscan_matrix(t,obj); break;
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM: erg += sscan_monom(t,obj); break;
#endif /* MONOMTRUE */
#ifdef MONOMIALTRUE
		case MONOMIAL: erg += sscan_monomial(t,obj); break;
#endif /* MONOMIALTRUE */
#ifdef MONOPOLYTRUE
		case MONOPOLY: erg += sscan_monopoly(t,obj); break;
#endif /* MONOPOLYTRUE */
#ifdef POLYTRUE
		case FASTPOLYNOM: erg += sscan_fastpolynom(t,obj); break;
		case POLYNOM: erg += sscan_polynom(t,obj); break;
#endif /* POLYTRUE */
#ifdef POWSYMTRUE
		case POW_SYM: erg += sscan_powsym(t,obj); break;
#endif /* POWSYMTRUE */
#ifdef REIHETRUE
		case REIHE: erg += sscan_reihe(t,obj); break;
#endif /* REIHETRUE */
#ifdef SCHUBERTTRUE
		case SCHUBERT: erg += sscan_schubert(t,obj); break;
#endif /* SCHUBERTTRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: erg += sscan_skewpartition(t,obj); break;
#endif /* SKEWPARTTRUE */
#ifdef SQRADTRUE
		case SQ_RADICAL: erg += sscan_sqrad(t,obj); break;
#endif /* SQRADTRUE */
#ifdef CHARTRUE
		case SYMCHAR: erg += sscan_symchar(t,obj); break;
#endif /* CHARTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: erg += sscan_tableaux(t,obj); break;
#endif /* TABLEAUXTRUE */
#ifdef VECTORTRUE
		case VECTOR: erg += sscan_vector(t,obj); break;
#endif /* VECTORTRUE */
#ifdef WORDTRUE
		case WORD: erg += sscan_word(t,obj); break;
#endif /* WORDTRUE */
#endif /* UNDEF */
		default:
			{
			fprintf(stderr,"kind = %d\n",kind);
			error("sscan:wrong type");
			return(ERROR);
			}
		};
	ENDR("sscan");
	}

OBJECTKIND scanobjectkind()
/* routine zum einlesen des objecttyps 160787 */
/* AK 280689 V1.0 */ /* AK 020290 V1.1 */
/* AK 070291 V1.2 works with stderr instead of stdin */
/* AK 130891 V1.3 */
	{
	INT erg;
	INT i = 0L;
	
	printeingabe("enter kind of object");
	/* hier sind neue objecttypen einzufuegen */
	
#ifdef INTEGERTRUE
	fprintf(stderr,"integer     [1]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* INTEGERTRUE */
#ifdef VECTORTRUE
	fprintf(stderr,"vector      [2]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* VECTORTRUE */
#ifdef PARTTRUE
	fprintf(stderr,"partition   [3]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* PARTTRUE */
#ifdef BRUCHTRUE
	fprintf(stderr,"bruch       [4]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* BRUCHTRUE */
#ifdef PERMTRUE
	fprintf(stderr,"permutation [6]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* PERMTRUE */
#ifdef SKEWPARTTRUE
	fprintf(stderr,"skewpart    [7]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* SKEWPARTTRUE */
#ifdef TABLEAUXTRUE
	fprintf(stderr,"tableaux    [8]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* TABLEAUXTRUE */
#ifdef POLYTRUE
	fprintf(stderr,"polynom     [9]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* POLYTRUE */
#ifdef SCHURTRUE
	fprintf(stderr,"schurfunk  [10]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* SCHURTRUE */
#ifdef MATRIXTRUE
	fprintf(stderr,"matrix     [11]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* MATRIXTRUE */
#ifdef HOMSYMTRUE
	fprintf(stderr,"homsym     [13]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* HOMSYMTRUE */
#ifdef SCHUBERTTRUE
	fprintf(stderr,"schubert   [14]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* SCHUBERTTRUE */
#ifdef KOSTKATRUE
	fprintf(stderr,"kostka     [16]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* KOSTKATRUE */
#ifdef CHARTRUE
	fprintf(stderr,"symchar    [18]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* CHARTRUE */
#ifdef WORDTRUE
	fprintf(stderr,"word       [19]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* WORDTRUE */
#ifdef LISTTRUE
	fprintf(stderr,"list       [20]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* LISTTRUE */
#ifdef LONGINTTRUE
	fprintf(stderr,"longint    [22]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* LONGINTTRUE */
#ifdef POWSYMTRUE
	fprintf(stderr,"powersum   [28]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* POWSYMTRUE */
#ifdef MONOMIALTRUE
	fprintf(stderr,"mon. sym.  [29]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* MONOMIALTRUE */
#ifdef GRALTRUE
	fprintf(stderr,"groupalg.  [32]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* GRALTRUE */
#ifdef ELMSYMTRUE
	fprintf(stderr,"elm. sym.  [33]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* ELMSYMTRUE */
#ifdef FFTRUE
	fprintf(stderr,"fin. field [35]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* FFTRUE */
#ifdef REIHETRUE
	fprintf(stderr,"reihe      [36]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* REIHETRUE */
#ifdef CYCLOTRUE
	fprintf(stderr,"cyclotomic [41]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* CYCLOTRUE */
#ifdef MONOPOLYTRUE
	fprintf(stderr,"monopoly   [42]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* MONOPOLYTRUE */
#ifdef SQRADTRUE
	fprintf(stderr,"radical    [43]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* SQRADTRUE */
	fprintf(stderr,"bitvector  [44]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#ifdef LAURENTTRUE
	fprintf(stderr,"laurent    [45]"); 
	if (i++ == 4L)fprintf(stderr,"\n"),i=0L;
#endif /* LAURENTTRUE */

	fprintf(stderr,"\nwhat kind:? ");
	scanf("%ld",&erg);
	return (OBJECTKIND)erg;
	}

INT objectread(f,obj) FILE *f; OP obj;
/* AK 131086 */ /* AK 280689 V1.0 */ /* AK 160190 V1.1 */ /* AK 020591 V1.2 */
/* AK 090891 V1.3 */
	{
	OBJECTKIND kind;
	INT c,erg=OK;
	if (f == NULL)
		return error("objectread:NULL file pointer");
	if (not EMPTYP(obj)) 
		erg += freeself(obj);
	fscanf(f,"%ld",&c);
	kind = (OBJECTKIND)c;
	switch(kind)
		{
		case (OBJECTKIND)0:	
			break;
#ifdef BRUCHTRUE
		case BRUCH: erg += objectread_bruch(f,obj);break;
#endif /* BRUCHTRUE */
#ifdef INTEGERTRUE
		case INTEGER: erg += objectread_integer(f,obj);break;
#endif /* INTEGERTRUE */
#ifdef LISTTRUE
		case GRAL: case HOM_SYM: case POW_SYM: case MONOMIAL:
		case ELM_SYM: case SCHUR: case MONOPOLY: case POLYNOM:
		case SCHUBERT: case SYMLIST: 	
			erg += objectread_list(f,obj);
			    C_O_K(obj,kind); break;
#endif /* LISTTRUE */
#ifdef LONGINTTRUE
		case LONGINT: erg += objectread_longint(f,obj);break;
#endif /* LONGINTTRUE */
#ifdef MATRIXTRUE
		case MATRIX: erg += objectread_matrix(f,obj);break;
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM: erg += objectread_monom(f,obj);break;
#endif /* MONOMTRUE */
#ifdef	NUMBERTRUE
		case SQ_RADICAL: erg += OBJECTREAD_SQRAD(f,obj);break;
		case CYCLOTOMIC: erg += OBJECTREAD_CYCLO(f,obj);break;
#endif /* NUMBERTRUE */
#ifdef PARTTRUE
		case PARTITION: erg += objectread_partition(f,obj);break;
#endif /* PARTTRUE */
#ifdef PERMTRUE
		case PERMUTATION: erg += objectread_permutation(f,obj);break;
#endif /* PERMTRUE */
#ifdef CHARTRUE
		case SYMCHAR: erg += objectread_symchar(f,obj);break;
#endif /* CHARTRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: erg += objectread_skewpartition(f,obj);
					break;
#endif /* SKEWPARTTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: erg += objectread_tableaux(f,obj); break;
#endif /* TABLEAUXTRUE */
#ifdef VECTORTRUE
		case INTEGERVECTOR:
		case VECTOR: erg += objectread_vector(f,obj); 
				C_O_K(obj,c);
				break;
		case BITVECTOR: erg += objectread_bv(f,obj); break;
#endif /* VECTORTRUE */
		default:  
			printobjectkind(obj);
			erg += error("objectread:wrong type"); 
			
		};
	ENDR("objectread");
	}

INT objectwrite(f,obj) FILE *f; OP obj;
/* AK 131086 */ /* AK 280689 V1.0 */ /* AK 160190 V1.1 */
/* AK 090891 V1.3 */
	{
	INT erg = OK;
	if (f == NULL)
		return error("objectwrite:NULL file pointer");
	switch(S_O_K(obj))
		{
		case 0: fprintf(f," %ld ",0L); return(OK);
#ifdef BRUCHTRUE
		case BRUCH: erg += objectwrite_bruch(f,obj);break;
#endif /* BRUCHTRUE */
#ifdef INTEGERTRUE
		case INTEGER: erg += objectwrite_integer(f,obj);break;
#endif /* INTEGERTRUE */
#ifdef LISTTRUE
		case GRAL: case HOM_SYM: case POW_SYM:
		case ELM_SYM: case MONOMIAL: case SCHUR: case MONOPOLY:
		case POLYNOM: case SCHUBERT: case SYMLIST: 
			erg += objectwrite_list(f,obj);break;
#endif /* LISTTRUE */
#ifdef LONGINTTRUE
		case LONGINT: erg += objectwrite_longint(f,obj);break;
#endif /* LONGINTTRUE */
#ifdef MATRIXTRUE
		case KRANZTYPUS: /* AK 220492 */
		case MATRIX:  erg += objectwrite_matrix(f,obj);break;
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM: erg += objectwrite_monom(f,obj);break;
#endif /* MONOMTRUE */
#ifdef	NUMBERTRUE
		case SQ_RADICAL:
		case CYCLOTOMIC: erg += objectwrite_number(f,obj);break;
#endif /* NUMBERTRUE */
#ifdef PARTTRUE
		case PARTITION: erg += objectwrite_partition(f,obj);break;
#endif /* PARTTRUE */
#ifdef PERMTRUE
		case PERMUTATION:erg += objectwrite_permutation(f,obj);break;
#endif /* PERMTRUE */
#ifdef CHARTRUE
		case SYMCHAR:erg += objectwrite_symchar(f,obj);break;
#endif /* CHARTRUE */
#ifdef SKEWPARTTRUE
		case SKEWPARTITION: erg += objectwrite_skewpartition(f,obj);
				break;
#endif /* SKEWPARTTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: erg += objectwrite_tableaux(f,obj);break;
#endif /* TABLEAUXTRUE */
#ifdef VECTORTRUE
		case INTEGERVECTOR:
		case VECTOR: erg += objectwrite_vector(f,obj);break;
		case BITVECTOR: erg += objectwrite_bv(f,obj); break;
#endif
		default:
			{
			printobjectkind(obj);
			return error("objectwrite:wrong type");
			}
		};
	ENDR("objectwrite");
	}


INT tex(obj) OP obj;
/* tex-output of the object obj */
/* AK 101187 */ /* AK 060789 V1.0 */ /* AK 020290 V1.1 */
/* AK 300791 V1.3 */	
	{
	INT erg = OK;
	/* es folgen zwei sonderfaelle */
	if (obj == NULL) 
		return error("tex:obj == NULL");

	if (EMPTYP(obj)) return(OK);
		/* d.h. ein leeres object erzeugt keine ausgabe A.K. 101187 */

	switch(S_O_K(obj))
		{
#ifdef BRUCHTRUE
		case BRUCH: erg +=  tex_bruch(obj);break;
#endif /* BRUCHTRUE */
#ifdef CYCLOTRUE
		case CYCLOTOMIC: erg += tex_cyclo(obj); break;
#endif /* CYCLOTRUE */
#ifdef INTEGERTRUE
		case INTEGER: erg +=  tex_integer(obj);break;
#endif /* INTEGERTRUE */
#ifdef LONGINTTRUE
		case LONGINT: erg +=  tex_longint(obj); break;
#endif /* LONGINTTRUE */
#ifdef MONOPOLYTRUE
		case MONOPOLY: erg +=  tex_monopoly(obj); break;
#endif /* MONOPOLYTRUE */
#ifdef SCHUBERTTRUE
		case SCHUBERT: erg +=  tex_schubert(obj); break;
#endif /* SCHUBERTTRUE */
#ifdef SCHURTRUE
		case SCHUR:erg +=  tex_schur(obj); break;
#endif /* SCHURTRUE */
#ifdef CHARTRUE
		case SYMCHAR: erg += tex_symchar(obj); break;
#endif /* CHARTRUE */
		case GRAL:
#ifdef LISTTRUE
		case SYMLIST: erg += tex_list(obj);break;
#endif /* LISTTRUE */
#ifdef MATRIXTRUE
		case KOSTKA:
		case MATRIX: erg += tex_matrix(obj);break;
			
#endif /* MATRIXTRUE */
#ifdef MONOMTRUE
		case MONOM: erg += tex_monom(obj);break;
#endif /* MONOMTRUE */
#ifdef PARTTRUE
		case PARTITION: erg+= tex_partition(obj);break;
#endif /* PARTTRUE */
#ifdef PERMTRUE
		case PERMUTATION: erg+= tex_permutation(obj);break;
#endif /* PERMTRUE */
#ifdef POLYTRUE
		case POLYNOM: erg+= tex_polynom(obj);break;
#endif /* POLYTRUE */
#ifdef TABLEAUXTRUE
		case TABLEAUX: erg+= tex_tableaux(obj);break;
#endif /* TABLEAUXTRUE */
#ifdef SQRADTRUE
		case SQ_RADICAL: erg += tex_sqrad(obj);break;
#endif /* SQRADTRUE */
#ifdef VECTORTRUE
		case INTEGERVECTOR:
		case VECTOR: erg += tex_vector(obj);break;
#endif /* VECTORTRUE */
		default:
			{
			/* der fehlerfall */
			printobjectkind(obj); 
			return error("tex:wrong type");
			}
		};
	if (erg != OK)
		{
		error("tex: error during computation");
		}
	return erg;
	}


#ifdef MATRIXTRUE 
#ifdef POLYTRUE
INT latex_glm_dar(M) OP	M;
/* RH */
/* AK 280192 output to texout */
{
	INT	i;
	INT	j;
	INT	k;
	INT	var = 1L;

	OP 	moddy	=	callocobject();	
	OP 	rest	=	callocobject();	
	OP	vier	=	callocobject();

	if(S_M_LI(M) >= 10) var = 1L;
	M_I_I(var,vier);
	ganzdiv(S_M_L(M),vier,moddy);
	mult(moddy,vier,vier);
	sub(S_M_L(M),vier,rest);

	if(S_I_I(moddy) != 0L)
	{
	fprintf(texout,"$$\n");
	fprintf(texout,"\\left[\n");
	for(i=0L;i<S_I_I(moddy);++i)
	{
			if(i != 0L)	
			{
				fprintf(texout,"$$\n");
				fprintf(texout,"\\left.\n");
			}
			fprintf(texout,"\\begin{array}{l");
			for(j=1L;j<var;++j) fprintf(texout,"|l");
			fprintf(texout,"}\n");
			for(j=0L;j<S_M_HI(M);++j)
			{
				for(k=0L;k<var;++k)
				{
					write_polynom(S_M_IJ(M,j,var*i+k));
					if(k != var-1L) fprintf(texout," & ");
				    else 
							if(j != S_M_HI(M)-1L) 
								fprintf(texout,"\\\\\\hline\n");
							else	
								fprintf(texout,"\\\\\n");
				}
			}
			fprintf(texout,"\\end{array}\n");
			if(i < S_I_I(moddy)-1L)
			{
			fprintf(texout,"\\right.\n");
			fprintf(texout,"$$\n");
			}
			else
			if(i < S_I_I(moddy))
			{
				if(S_I_I(rest) != 0L)
				{
					fprintf(texout,"\\right.\n");
					fprintf(texout,"$$\n");
				}
				else
				{
					fprintf(texout,"\\right]\n");
					fprintf(texout,"$$\n");
				}
			}
	}
	}
	if(S_I_I(rest) != 0L)
	{
	fprintf(texout,"\n\\bigskip\n");
	fprintf(texout,"$$\n");
	if(S_I_I(moddy) != 0)
		fprintf(texout,"\\left.\n");
	else
		fprintf(texout,"\\left[\n");
	fprintf(texout,"\\begin{array}{l");
	for(j=1L;j<S_I_I(rest)-1L;++j)
		fprintf(texout,"|l");
	fprintf(texout,"|l}\n");
	for(j=0L;j<S_M_HI(M);++j)
	{
		for(k=0L;k<S_I_I(rest);++k)
		{
			write_polynom(S_M_IJ(M,j,var*S_I_I(moddy)+k));
			if(k != S_I_I(rest)-1L) fprintf(texout," & ");
			else 
				if(j != S_M_HI(M)-1L) fprintf(texout,"\\\\\\hline\n");
				else	fprintf(texout,"\\\\\n");
		}
	}
	fprintf(texout,"\\end{array}\n");
	fprintf(texout,"\\right]\n");
	fprintf(texout,"$$\n");
	}

	SYMfreeall(moddy);
	SYMfreeall(rest);
	SYMfreeall(vier);
	return OK;
}
#endif /* POLYTRUE */
#endif /* MATRIXTRUE */

#ifdef POLYTRUE
static INT write_polynom(poly) OP	poly;
/* AK 280192 output to texout */
{
	INT	k,l;
	OP	z = poly;

	while(z != NULL)
	{
		if(!nullp(s_po_k(z)) && !emptyp(s_po_k(z)))	
		{
			ausgabe_koeff(s_po_k(z));
			for(k=0L;k<S_M_HI(s_po_s(z));++k)
			{
				for(l=0L;l<S_M_LI(s_po_s(z));++l)
					if(S_M_IJI(s_po_s(z),k,l) > 0L)

						if(S_M_IJI(s_po_s(z),k,l) == 1L)
							fprintf(texout,"x_{%d %d} ",k+1L,l+1L);
						else
							fprintf(texout,"x_{%d %d}^{%d} ",k+1L,l+1L,S_M_IJI(s_po_s(z),k,l));
			}
			if(S_PO_N(z) != NULL)	
			{
				fprintf(texout,"+");
			}
		}
		z = S_PO_N(z);
	}
	return OK;
}
#endif /* POLYTRUE */

static INT ausgabe_koeff(k) OP	k;
/* AK 280192 output to texout */
{
			switch(S_O_K(k))
			{ 
				case INTEGER: 
				{
					if(S_I_I(k) == 1L)
						break;

					if(S_I_I(k) == -1L)
					{
						fprintf(texout,"-");
						break;
					}
					print(k);
					break;
				}
#ifdef BRUCHTRUE
				case BRUCH: 
				{
					kuerzen(k);
					fprintf(texout,"\\frac{");
					ausgabe_koeff(S_B_O(k));
					fprintf(texout,"}{");
					ausgabe_koeff(S_B_U(k));
					fprintf(texout,"}");
					break;
				}
#endif /* BRUCHTRUE */
#ifdef NUMBERTRUE
				case SQ_RADICAL: 
				{
					OP	ptr = S_N_S(k);
					while(ptr != NULL)
					{
					fprintf(texout,"\\sqrt{");
					ausgabe_koeff(S_PO_S(ptr));
					fprintf(texout,"}");
					ptr = S_L_N(ptr);
					}
					break;
				}
#endif /* NUMBERTRUE */
				default:
				{
				printobjectkind(k);
				error("unknown type of coefficient !!!\n");
				break;
				}
			}
return OK;
}

