// create1polyonym() creates a single-variable polyonym ('polyonym') from a double-variable polyonym ('polyonym2') from position 'point' with variable 'v' void create1polyonym(Polyonym2 * polyonym2, Polyonym * polyonym, char v, int point){ int i=0,j=0,set=0; if(v=='x'){ j=point; set=0; while(i<=getDegree2(polyonym2, 'y')){ if(get_polymatrix2(polyonym2,j,i)!=0){set=i;} i++; } polyonym->d=set; polyonym->matrix=NULL; polyonym->matrix=malloc(sizeof(double)*(set+1)); if(polyonym->matrix==NULL){perror("Single Polyonym matrix malloc!");free(polyonym);exit(0);} i=0; while(i<=set){ (polyonym->matrix)[i]=get_polymatrix2(polyonym2,j,i); i++; } polyonym->var='y'; } else if(v=='y'){ i=point; set=0; while(j<=getDegree2(polyonym2, 'x')){ if(get_polymatrix2(polyonym2,j,i)!=0){set=j;} j++; } polyonym->d=set; polyonym->matrix=NULL; polyonym->matrix=malloc(sizeof(double)*(set+1)); if(polyonym->matrix==NULL){perror("Single Polyonym matrix malloc!");free(polyonym);exit(0);} j=0; while(j<=set){ (polyonym->matrix)[j]=get_polymatrix2(polyonym2,j,i); j++; } polyonym->var='x'; } }
// createsylvester() creates a Sylvester struct ('sylvester') and its matrix is filled with single-variable Polyonym structs that derive from 'p1' and 'p2' or from a zero-value Polyonym2 struct void createsylvester (Sylvester ** sylvester, Polyonym2 * p1, Polyonym2 * p2) { int degP1x=0, degP2x=0, degP1y=0, degP2y=0, dim=0, maxX=0, maxY=0, counter1=0, counter2=0, i=0, j=0, m=0, n=0; char hidden; Polyonym2 * ZeroPoly=NULL; createpolyonym2("0", &ZeroPoly, 0); (*sylvester)=NULL; (*sylvester)=malloc(sizeof(struct Sylvester)); if ((*sylvester)==NULL) {perror("Sylvester malloc!");exit(0);} degP1x=getDegree2(p1, 'x'); degP2x=getDegree2(p2, 'x'); degP1y=getDegree2(p1, 'y'); degP2y=getDegree2(p2, 'y'); if (degP1x>=degP2x) { maxX=degP1x; } else { maxX=degP2x; } if (degP1y>=degP2y) { maxY=degP1y; } else { maxY=degP2y; } if (maxX>=maxY) { hidden='y'; dim=degP1x+degP2x; } else { hidden='x'; dim=degP1y+degP2y; } (*sylvester)->hidden=hidden; (*sylvester)->dim=dim; printf("-Sylvester:\n"); printf("Dimension is: %d and the ", (*sylvester)->dim); if (hidden=='x') { if (degP1x>=degP2x && degP2y!=0 ) { (*sylvester)->degree=degP1x; } else { (*sylvester)->degree=degP2x; } } else { if (degP1y>=degP2y && degP2x!=0 ) { (*sylvester)->degree=degP1y; } else { (*sylvester)->degree=degP2y; } } printf("hidden variable is %c with degree %d\n",hidden,(*sylvester)->degree); printf("---------------------------------------------\n"); (*sylvester)->matrix=NULL; (*sylvester)->matrix=malloc(sizeof(Polyonym *)*dim); if ((*sylvester)->matrix==NULL) {perror("Sylvester matrix malloc!");exit(0);} for (i=0 ; i<dim ; i++) { (*sylvester)->matrix[i]=NULL; (*sylvester)->matrix[i]=malloc(sizeof(Polyonym)*dim); if ((*sylvester)->matrix[i]==NULL) {perror("Sylvester matrix malloc!");exit(0);} } counter1=0; counter2=0; m=dim-1; for (i=0 ; i<dim ; i++) { n=dim-1; if ((*sylvester)->hidden=='x') { if (i<degP2y) { if (counter1==0) { for (j=0 ; j<=degP1y ; j++) { create1polyonym(p1, &((*sylvester)->matrix[m][n]), 'y', j); n--; } for (j=degP1y+1 ; j<degP1y+degP2y ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } } else { for(j=0 ; j<counter1 ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } for (j=counter1 ; j<=degP1y+counter1 ; j++) { create1polyonym(p1, &((*sylvester)->matrix[m][n]), 'y', j-counter1); n--; } for (j=degP1y+counter1+1 ; j<degP1y+degP2y ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } } counter1++; } else { if (counter2==0) { for (j=0 ; j<=degP2y ; j++) { create1polyonym(p2, &((*sylvester)->matrix[m][n]), 'y', j); n--; } for (j=degP2y+1 ; j<degP1y+degP2y ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } } else { for(j=0 ; j<counter2 ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } for (j=counter2 ; j<=degP2y+counter2 ; j++) { create1polyonym(p2, &((*sylvester)->matrix[m][n]), 'y', j-counter2); n--; } for (j=degP2y+counter2+1 ; j<degP1y+degP2y ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'y', 0); n--; } } counter2++; } } else { if (i<degP2x) { if (counter1==0) { for (j=0 ; j<=degP1x ; j++) { create1polyonym(p1, &((*sylvester)->matrix[m][n]), 'x', j); n--; } for (j=degP1x+1 ; j<degP1x+degP2x ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } } else { for(j=0 ; j<counter1 ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } for (j=counter1 ; j<=degP1x+counter1 ; j++) { create1polyonym(p1, &((*sylvester)->matrix[m][n]), 'x', j-counter1); n--; } for (j=degP1x+counter1+1 ; j<degP1x+degP2x ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } } counter1++; } else { if (counter2==0) { for (j=0 ; j<=degP2x ; j++) { create1polyonym(p2, &((*sylvester)->matrix[m][n]), 'x', j); n--; } for (j=degP2x+1 ; j<degP1x+degP2x ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } } else { for(j=0 ; j<counter2 ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } for (j=counter2 ; j<=degP2x+counter2 ; j++) { create1polyonym(p2, &((*sylvester)->matrix[m][n]), 'x', j-counter2); n--; } for (j=degP2x+counter2+1 ; j<degP1x+degP2x ; j++) { create1polyonym(ZeroPoly, &((*sylvester)->matrix[m][n]), 'x', 0); n--; } } counter2++; } } m--; } deletepoly2(ZeroPoly); return; }