Example #1
0
PtPoly PolySubtraction (PtPoly ppoly1, PtPoly ppoly2)
{
  PtPoly Sub; unsigned int Degree, I, Invert = 0;

  if (!ValidPolys (ppoly1, ppoly2)) return NULL;

  if(ppoly1->Degree < ppoly2->Degree) {
    Degree = ppoly1->Degree ;
    Invert = 1;
  }else{ 
    Degree = ppoly2-> Degree;
  }

  if ((Sub = PolyCopy ((ppoly1->Degree >= ppoly2->Degree) ? ppoly1 : ppoly2)) == NULL) { Error = NO_MEM; return NULL; }

  Error = OK;

  if (Invert) Sub = PolySymmetrical(Sub);
  
  for (I = 0; I <= Degree; I++)
    Sub->Poly[I] = ppoly1->Poly[I] - ppoly2->Poly[I];

  ReducePoly(Sub);

  return Sub;
}
Example #2
0
PtPoly PolyMultiplication (PtPoly ppoly1, PtPoly ppoly2)
{

    if(!ValidPolys(ppoly1,ppoly2))
        return NULL;

    if(ppoly1==NULL || ppoly2==NULL){
        Error = NO_POLY;
        return NULL;
    }

    PtPoly mul;

    int degree = ppoly1->Degree + ppoly2->Degree;

    if((mul = PolyCreate(degree)) == NULL){
        return NULL;
    }

    for (int i = 0; i <= ppoly1->Degree ; ++i) {
        for (int j = 0; j <= ppoly2->Degree ; ++j) {
            mul->Poly[i + j] += ppoly1->Poly[i] * ppoly2->Poly[j];
        }
    }

    Error = OK;

    ReducePoly(mul);

    return mul;

}
Example #3
0
int PolyEquals (PtPoly ppoly1, PtPoly ppoly2)
{
  int I;

  if (!ValidPolys (ppoly1, ppoly2)) return 0;
  
  Error = OK;

  for (I = 0; I <= ppoly1->Degree; I++)
    if (ppoly1->Poly[I] != ppoly2->Poly[I]) return 0;

  return 1;
}
Example #4
0
PtPoly PolyAddition (PtPoly ppoly1, PtPoly ppoly2)
{

    if(!ValidPolys(ppoly1,ppoly2))
        return NULL;

    if(ppoly1==NULL || ppoly2==NULL){
        Error = NO_POLY;
    }

    int smallestDegree;
    int biggestDegree;
    int biggest = 0; /* considera-se o ppoly1 */

    if(ppoly1->Degree > ppoly2->Degree){
        biggestDegree = ppoly1->Degree;
        smallestDegree = ppoly2->Degree;
    }else{
        biggestDegree = ppoly2->Degree;
        smallestDegree = ppoly1->Degree;
        biggest = 1;
    }

    PtPoly sum;

    if((sum = PolyCreate(biggestDegree)) == NULL){
        return NULL;
    }

    for (int i = 0; i <= smallestDegree ; ++i) {
        sum->Poly[i] = ppoly1->Poly[i] + ppoly2->Poly[i];
    }

    for (int j = smallestDegree + 1; j <= biggestDegree; ++j) {
        if(biggest)
            sum->Poly[j] = ppoly2->Poly[j];
        else
            sum->Poly[j] = ppoly1->Poly[j];
    }

    Error = OK;
    ReducePoly(sum);

    return sum;

}
Example #5
0
PtPoly PolySubtraction (PtPoly ppoly1, PtPoly ppoly2)
{

    PtPoly sub;

    /* Check validity of polynomials */
    if (!ValidPolys(ppoly1, ppoly2))
        return NULL;

    int smallestDegree;
    int biggestDegree;
    int biggest = 0; /* considera-se o ppoly1 */

    if(ppoly1->Degree > ppoly2->Degree){
        biggestDegree = ppoly1->Degree;
        smallestDegree = ppoly2->Degree;
    }else{
        biggestDegree = ppoly2->Degree;
        smallestDegree = ppoly1->Degree;
        biggest = 1;
    }

    if((sub = PolyCreate(biggestDegree)) == NULL){
        return NULL;
    }

    for (int i = 0; i <= smallestDegree ; ++i) {
        sub->Poly[i] = ppoly1->Poly[i] - ppoly2->Poly[i];
    }

    for (int j = smallestDegree + 1; j <= biggestDegree; ++j) {
        if (biggest && sub->Poly[j] != 0)
            sub->Poly[j] = ppoly2->Poly[j] * (-1);
        else
            sub->Poly[j] = ppoly1->Poly[j];
    }

    ReducePoly(sub);
    Error = OK;
    return sub;

}
Example #6
0
PtPoly PolyAddition (PtPoly ppoly1, PtPoly ppoly2)
{
  PtPoly Add; unsigned int I, Degree;

  if (!ValidPolys (ppoly1, ppoly2)) return NULL;

  Degree = (ppoly1->Degree < ppoly2->Degree) ? ppoly1->Degree : ppoly2-> Degree;

  if ((Add = PolyCopy ((ppoly1->Degree >= ppoly2->Degree) ? ppoly1 : ppoly2)) == NULL) { Error = NO_MEM; return NULL; }

  Error = OK;

  for (I = 0; I <= Degree; I++){
    Add->Poly[I] = ppoly1->Poly[I] + ppoly2->Poly[I];
  }

  ReducePoly(Add);

  return Add;
}
Example #7
0
PtPoly PolyMultiplication (PtPoly ppoly1, PtPoly ppoly2)
{
  PtPoly Mult; unsigned int I,J,TotalDegree;

  if (!ValidPolys (ppoly1, ppoly2)) return NULL;

  TotalDegree = ppoly1->Degree + ppoly2->Degree;

  if ((Mult = PolyCreate(TotalDegree)) == NULL) { Error = NO_MEM; return NULL; }

  Error = OK;

  for (I = 0; I <= TotalDegree; I++)
    Mult->Poly[I] = 0;

  for (I = 0; I <= ppoly1->Degree; I++ ){
    for(J = 0; J <= ppoly2->Degree; J++)
      Mult->Poly[I+J] += ppoly1->Poly[I] * ppoly2->Poly[J];
  }
  
  ReducePoly(Mult);

  return Mult;
}