Changeset c81bf7 in git for kernel/ideals.cc
- Timestamp:
- Jan 9, 2013, 3:25:33 PM (10 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
- Children:
- b0a81177e7c506b38836a82dc86bca5774eab0e8
- Parents:
- 9234fbc7d06a2db6993e0fdb4ba27976c1ed5341
- git-author:
- Andreas Steenpass <steenpass@mathematik.uni-kl.de>2013-01-09 15:25:33+01:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2013-02-19 20:27:28+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/ideals.cc
r9234fb rc81bf7 2571 2571 } 2572 2572 2573 /* 2574 * compare the leading terms of a and b 2575 */ 2576 static int tCompare(const poly a, const poly b) 2577 { 2578 if (b == NULL) 2579 { 2580 if (a == NULL) return(0); 2581 2582 return(1); 2583 } 2584 2585 if (a == NULL) return(-1); 2586 2587 /* a != NULL && b != NULL */ 2588 int r = pLmCmp(a, b); 2589 if (r != 0) return(r); 2590 number h = nSub(pGetCoeff(a), pGetCoeff(b)); 2591 r = -1 + nIsZero(h) + 2*nGreaterZero(h); /* -1: <, 0:==, 1: > */ 2592 nDelete(&h); 2593 return(r); 2594 } 2595 2596 /* 2597 * compare a and b (rev-lex on terms) 2598 */ 2599 static int pCompare(const poly a, const poly b) 2600 { 2601 int r = tCompare(a, b); 2602 if (r != 0) return(r); 2603 2604 poly aa = a; 2605 poly bb = b; 2606 while (r == 0 && aa != NULL && bb != NULL) 2607 { 2608 pIter(aa); 2609 pIter(bb); 2610 r = tCompare(aa, bb); 2611 } 2612 return(r); 2613 } 2614 2615 typedef struct 2616 { 2617 poly p; 2618 int index; 2619 } poly_sort; 2620 2621 int pCompare_qsort(const void *a, const void *b) 2622 { 2623 int res = pCompare(((poly_sort *)a)->p, ((poly_sort *)b)->p); 2624 return(res); 2625 } 2626 2627 void idSort_qsort(poly_sort *id_sort, int idsize) 2628 { 2629 qsort(id_sort, idsize, sizeof(poly_sort), pCompare_qsort); 2630 } 2631 2632 /*2 2633 * ideal id = (id[i]) 2634 * if id[i] = id[j] then id[j] is deleted for j > i 2635 */ 2636 void idDelEquals(ideal id) 2637 { 2638 int idsize = IDELEMS(id); 2639 poly_sort *id_sort = (poly_sort *)omAlloc0(idsize*sizeof(poly_sort)); 2640 for (int i = 0; i < idsize; i++) 2641 { 2642 id_sort[i].p = id->m[i]; 2643 id_sort[i].index = i; 2644 } 2645 idSort_qsort(id_sort, idsize); 2646 int index, index_i, index_j; 2647 int i = 0; 2648 for (int j = 1; j < idsize; j++) 2649 { 2650 if (pEqualPolys(id_sort[i].p, id_sort[j].p)) 2651 { 2652 index_i = id_sort[i].index; 2653 index_j = id_sort[j].index; 2654 if (index_j > index_i) 2655 { 2656 index = index_j; 2657 } 2658 else 2659 { 2660 index = index_i; 2661 i = j; 2662 } 2663 if (id->m[index] != NULL) { 2664 pDelete(&id->m[index]); 2665 } 2666 } 2667 else 2668 { 2669 i = j; 2670 } 2671 } 2672 omFreeSize((ADDRESS)(id_sort), idsize*sizeof(poly_sort)); 2673 } 2674
Note: See TracChangeset
for help on using the changeset viewer.