Changeset e78f35 in git for kernel/ideals.cc


Ignore:
Timestamp:
Feb 19, 2013, 8:32:57 PM (10 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
2a3743b6431021631dff0bb9d7b7888a205302b1bc03ea6301177ce6360abcfc3922ff0edc5f9a73
Parents:
26e817f3b4db82c0b0a5376b16c2e9648ecf55e3d81e39d347055cad093a2ae53302e036ae2a449c
Message:
Merge pull request #280 from malex984/adapting_commits_from_master_minors

Adapting commits from master minors
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/ideals.cc

    r26e817f re78f35  
    1111
    1212#include <omalloc/omalloc.h>
    13 #include <misc/auxiliary.h>
    14 
    1513
    1614#ifndef NDEBUG
     
    25592557*/
    25602558
    2561 
    2562 
     2559/// keeps the first k (>= 1) entries of the given ideal
     2560/// (Note that the kept polynomials may be zero.)
     2561void idKeepFirstK(ideal id, const int k)
     2562{
     2563   for (int i = IDELEMS(id)-1; i >= k; i--)
     2564   {
     2565      if (id->m[i] != NULL) pDelete(&id->m[i]);
     2566   }
     2567   int kk=k;                                                                                                                 
     2568   if (k==0) kk=1; /* ideals must have at least one element(0)*/                                                             
     2569   pEnlargeSet(&(id->m), IDELEMS(id), kk-IDELEMS(id));                                                                       
     2570   IDELEMS(id) = kk;
     2571}
     2572
     2573/*
     2574* compare the leading terms of a and b
     2575*/
     2576static int tCompare(const poly a, const poly b)
     2577{
     2578  if (b == NULL) return(a != NULL);
     2579  if (a == NULL) return(-1);
     2580
     2581  /* a != NULL && b != NULL */
     2582  int r = pLmCmp(a, b);
     2583  if (r != 0) return(r);
     2584  number h = nSub(pGetCoeff(a), pGetCoeff(b));
     2585  r = -1 + nIsZero(h) + 2*nGreaterZero(h);   /* -1: <, 0:==, 1: > */
     2586  nDelete(&h);
     2587  return(r);
     2588}
     2589
     2590/*
     2591* compare a and b (rev-lex on terms)
     2592*/
     2593static int pCompare(const poly a, const poly b)
     2594{
     2595  int r = tCompare(a, b);
     2596  if (r != 0) return(r);
     2597
     2598  poly aa = a;
     2599  poly bb = b;
     2600  while (r == 0 && aa != NULL && bb != NULL)
     2601  {
     2602    pIter(aa);
     2603    pIter(bb);
     2604    r = tCompare(aa, bb);
     2605  }
     2606  return(r);
     2607}
     2608
     2609typedef struct
     2610{
     2611  poly p;
     2612  int index;
     2613} poly_sort;
     2614
     2615int pCompare_qsort(const void *a, const void *b)
     2616{
     2617  int res = pCompare(((poly_sort *)a)->p, ((poly_sort *)b)->p);
     2618  return(res);
     2619}
     2620
     2621void idSort_qsort(poly_sort *id_sort, int idsize)
     2622{
     2623  qsort(id_sort, idsize, sizeof(poly_sort), pCompare_qsort);
     2624}
     2625
     2626/*2
     2627* ideal id = (id[i])
     2628* if id[i] = id[j] then id[j] is deleted for j > i
     2629*/
     2630void idDelEquals(ideal id)
     2631{
     2632  int idsize = IDELEMS(id);
     2633  poly_sort *id_sort = (poly_sort *)omAlloc0(idsize*sizeof(poly_sort));
     2634  for (int i = 0; i < idsize; i++)
     2635  {
     2636    id_sort[i].p = id->m[i];
     2637    id_sort[i].index = i;
     2638  }
     2639  idSort_qsort(id_sort, idsize);
     2640  int index, index_i, index_j;
     2641  int i = 0;
     2642  for (int j = 1; j < idsize; j++)
     2643  {
     2644    if (id_sort[i].p != NULL && pEqualPolys(id_sort[i].p, id_sort[j].p))
     2645    {
     2646      index_i = id_sort[i].index;
     2647      index_j = id_sort[j].index;
     2648      if (index_j > index_i)
     2649      {
     2650        index = index_j;
     2651      }
     2652      else
     2653      {
     2654        index = index_i;
     2655        i = j;
     2656      }
     2657      pDelete(&id->m[index]);
     2658    }
     2659    else
     2660    {
     2661      i = j;
     2662    }
     2663  }
     2664  omFreeSize((ADDRESS)(id_sort), idsize*sizeof(poly_sort));
     2665}
Note: See TracChangeset for help on using the changeset viewer.