Changeset 0191db in git
- Timestamp:
- Feb 12, 2003, 7:25:12 PM (21 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 1048e0ca855f8b8edf41222fdf2dc2413b72cfcc
- Parents:
- 9d363683d7f5e1536ff109e59e2c5c8c1b8c3588
- Location:
- Singular
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/tgb.cc
r9d3636 r0191db 6 6 #include "tgb.h" 7 7 #define OM_KEEP 0 8 #define LEN_VAR 18 #define LEN_VAR4 9 9 10 10 #ifdef LEN_VAR1 … … 294 294 295 295 296 static voidadd_to_reductors(calc_dat* c, poly h, int len){296 static int add_to_reductors(calc_dat* c, poly h, int len){ 297 297 assume(lenS_correct(c->strat)); 298 298 … … 307 307 P.p=h; /*p_Copy(h,c->r);*/ 308 308 P.FDeg=pFDeg(P.p,c->r); 309 if (!rField_is_Zp(c->r)) 309 if (!rField_is_Zp(c->r)){ 310 310 pCleardenom(P.p); 311 pContent(P.p); //is a duplicate call, but belongs here 312 } 313 311 314 else 312 315 pNorm(P.p); … … 321 324 if(c->strat->lenSw) 322 325 c->strat->lenSw[i]=pSLength(P.p,len); 323 326 return i; 324 327 325 328 } … … 1441 1444 c->strat->lenS[old_pos]=new_length; 1442 1445 if(c->strat->lenSw) 1443 c->strat->lenS [old_pos]=pSLength(sec_copy,new_length);1446 c->strat->lenSw[old_pos]=pSLength(sec_copy,new_length); 1444 1447 int i=0; 1445 1448 for(i=new_pos;i<old_pos;i++){ … … 1700 1703 // have to do many additional things for consistency 1701 1704 { 1705 if (!rField_is_Zp(c->r)){ 1706 pCleardenom(sec_copy); 1707 pContent(sec_copy); 1708 } 1709 1710 else 1711 pNorm(sec_copy); 1712 1702 1713 int old_pos=j; 1703 1714 new_pos=min(old_pos, new_pos); … … 1705 1716 c->strat->lenS[old_pos]=new_length; 1706 1717 if(c->strat->lenSw) 1707 c->strat->lenS [old_pos]=pSLength(sec_copy,new_length);1718 c->strat->lenSw[old_pos]=pSLength(sec_copy,new_length); 1708 1719 int i=0; 1709 1720 for(i=new_pos;i<old_pos;i++){ … … 2522 2533 return m; 2523 2534 } 2535 2536 2537 struct find_erg{ 2538 int to_reduce_u; 2539 int to_reduce_l; 2540 int reduce_by;//index of reductor 2541 BOOLEAN fromS;//else from los 2542 BOOLEAN swap_roles; //from reduce_by, to_reduce_u if fromS 2543 }; 2544 static int guess_quality(LObject* p, calc_dat* c){ 2545 //looks only on bucket 2546 if (c->is_char0) return kSBucketLength(p->bucket); 2547 return (bucket_guess(p->bucket)); 2548 } 2549 static int quality_of_pos_in_strat_S(int pos, calc_dat* c){ 2550 if (c->is_char0) return c->strat->lenSw[pos]; 2551 return c->strat->lenS[pos]; 2552 } 2553 static int quality(poly p, int len, calc_dat* c){ 2554 if (c->is_char0) return pSLength(p,len); 2555 return pLength(p); 2556 } 2557 static void multi_reduction_lls_trick(LObject** los, int losl,calc_dat* c,find_erg & erg){ 2558 if(erg.fromS){ 2559 if(pLmEqual(c->strat->S[erg.reduce_by],los[erg.to_reduce_u]->p)) 2560 { 2561 int i; 2562 int quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c); 2563 int best=erg.to_reduce_u+1; 2564 for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--){ 2565 int qc=guess_quality(los[i],c); 2566 if (qc<quality_a){ 2567 best=i; 2568 quality_a=qc; 2569 } 2570 } 2571 if(best!=erg.to_reduce_u+1){ 2572 LObject* h=los[erg.to_reduce_u]; 2573 los[erg.to_reduce_u]=los[best]; 2574 los[best]=h; 2575 erg.swap_roles=TRUE; 2576 } 2577 else{ 2578 2579 erg.swap_roles=FALSE; 2580 } 2581 return; 2582 } 2583 else 2584 { 2585 if (erg.to_reduce_u>erg.to_reduce_l){ 2586 int i; 2587 int quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c); 2588 int best=erg.to_reduce_u+1; 2589 for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--){ 2590 int qc=guess_quality(los[i],c); 2591 if (qc<quality_a){ 2592 best=i; 2593 quality_a=qc; 2594 } 2595 } 2596 if(best!=erg.to_reduce_u+1){ 2597 LObject* h=los[erg.to_reduce_l]; 2598 los[erg.to_reduce_l]=los[best]; 2599 los[best]=h; 2600 erg.reduce_by=erg.to_reduce_l; 2601 erg.fromS=FALSE; 2602 erg.to_reduce_l++; 2603 2604 } 2605 } 2606 erg.swap_roles=FALSE; 2607 return; 2608 } 2609 2610 } 2611 else{ 2612 if(erg.reduce_by>erg.to_reduce_u){ 2613 //then lm(rb)>= lm(tru) so = 2614 assume(erg.reduce_by==erg.to_reduce_u+1); 2615 int best=erg.reduce_by; 2616 int quality_a=guess_quality(los[erg.reduce_by],c); 2617 int i; 2618 for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--){ 2619 int qc=guess_quality(los[i],c); 2620 if (qc<quality_a){ 2621 best=i; 2622 quality_a=qc; 2623 } 2624 } 2625 if(best!=erg.reduce_by){ 2626 LObject* h=los[erg.reduce_by]; 2627 los[erg.reduce_by]=los[best]; 2628 los[best]=h; 2629 } 2630 erg.swap_roles=FALSE; 2631 return; 2632 2633 2634 } 2635 else 2636 { 2637 assume(!pLmEqual(los[erg.reduce_by]->p,los[erg.to_reduce_l]->p)); 2638 //further assume, that reduce_by is the above all other polys 2639 //with same leading term 2640 int il=erg.reduce_by; 2641 int quality_a =guess_quality(los[erg.reduce_by],c); 2642 int qc; 2643 while((il>0) && pLmEqual(los[il-1]->p,los[il]->p)){ 2644 il--; 2645 qc=guess_quality(los[il],c); 2646 if (qc<quality_a){ 2647 quality_a=qc; 2648 erg.reduce_by=il; 2649 } 2650 } 2651 erg.swap_roles=FALSE; 2652 } 2653 2654 } 2655 if(erg.swap_roles){ 2656 poly clear_into; 2657 int dummy_len; 2658 int new_length; 2659 int bp=erg.to_reduce_u;//bucket_positon 2660 kBucketClear(los[bp]->bucket,&clear_into,&new_length); 2661 poly p=c->strat->S[erg.reduce_by]; 2662 int j=erg.reduce_by; 2663 int old_length=c->strat->lenS[j];// in view of S 2664 los[bp]->p=p; 2665 kBucketInit(los[bp]->bucket,p,old_length); 2666 int qal=quality(clear_into,new_length,c); 2667 int pos_in_c=-1; 2668 int z; 2669 int new_pos; 2670 new_pos=simple_posInS(c->strat,clear_into,qal,c->is_char0); 2671 assume(new_pos<=j); 2672 for (z=c->n;z;z--) 2673 { 2674 if(p==c->S->m[z-1]) 2675 { 2676 pos_in_c=z-1; 2677 break; 2678 } 2679 } 2680 if(pos_in_c>=0) 2681 { 2682 c->S->m[pos_in_c]=clear_into; 2683 c->lengths[pos_in_c]=new_length; 2684 c_S_element_changed_hook(pos_in_c,c); 2685 } 2686 c->strat->S[j]=clear_into; 2687 c->strat->lenS[j]=new_length; 2688 if(c->strat->lenSw) 2689 c->strat->lenS[j]=qal; 2690 if(c->is_char0) 2691 { 2692 pContent(clear_into); 2693 pCleardenom(clear_into); 2694 } 2695 else 2696 pNorm(clear_into); 2697 if (new_pos<j) 2698 move_forward_in_S(j,new_pos,c->strat,c->is_char0); 2699 2700 } 2701 } 2702 static find_erg multi_reduction_find(LObject** los, int losl,calc_dat* c,int startf){ 2703 kStrategy strat=c->strat; 2704 assume(startf<=losl); 2705 int i=startf; 2706 find_erg erg; 2707 int j; 2708 while(i>=0){ 2709 j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,los[i]); 2710 if(j>=0){ 2711 2712 erg.to_reduce_u=startf; 2713 erg.reduce_by=j; 2714 erg.fromS=TRUE; 2715 int i2; 2716 for(i2=i-1;i2>=0;i2--){ 2717 if(!pLmEqual(los[i]->p,los[i2]->p)) 2718 break; 2719 } 2720 erg.to_reduce_l=i2+1; 2721 return erg; 2722 } 2723 if (j<0){ 2724 //not reduceable, try to use this for reducing higher terms 2725 int i2; 2726 for (i2=i+1;i2<=losl;i2++){ 2727 if (p_LmShortDivisibleBy(los[i]->p,los[i]->sev,los[i2]->p,los[i2]->sev, 2728 c->r)){ 2729 int i3=i2; 2730 while((i3+1<losl) && (pLmEqual(los[i2]->p, los[i3+1]->p))) 2731 i3++; 2732 erg.to_reduce_u=i3; 2733 erg.to_reduce_l=i2; 2734 erg.reduce_by=i; 2735 erg.fromS=FALSE; 2736 return erg; 2737 } 2738 } 2739 i2=i; 2740 while((i2>0)&&(pLmEqual(los[i]->p,los[i2-1]->p))) 2741 i2--; 2742 if(i2!=i){ 2743 2744 erg.to_reduce_u=i-1; 2745 erg.to_reduce_l=i2; 2746 erg.reduce_by=i; 2747 erg.fromS=FALSE; 2748 return erg; 2749 } 2750 2751 i--; 2752 } 2753 } 2754 erg.reduce_by=-1;//error code 2755 return erg; 2756 } 2757 2758 // nicht reduzierbare eintraege in ergebnisliste schreiben 2759 // nullen loeschen 2760 // while(finde_groessten leitterm reduzierbar(c,erg)){ 2761 2762 static int multi_reduction_clear_zeroes(LObject** los, int losl) 2763 { 2764 int deleted=0; 2765 int i=0; 2766 while(i<losl) 2767 { 2768 if(los[i]->p==NULL){ 2769 delete los[i];//here we assume los are constructed with new 2770 int j; 2771 for(j=i+1;j<losl-deleted;j++) 2772 { 2773 los[j-1]=los[j]; 2774 } 2775 deleted++; 2776 } 2777 else 2778 i++; 2779 } 2780 return deleted; 2781 } 2782 2783 static void sort_region_down(LObject** los, int l, int u, calc_dat* c) 2784 { 2785 int i; 2786 for(i=l;i<=u;i++) 2787 { 2788 int j; 2789 for(j=i;j;j--) 2790 { 2791 if(pLmCmp(los[j]->p,los[j-1]->p)==1){ 2792 LObject* h=los[j]; 2793 los[j]=los[j-1]; 2794 los[j-1]=h; 2795 } 2796 else break; 2797 } 2798 } 2799 } 2800 2801 //assume that los is ordered ascending by leading term, all non zero 2802 static void multi_reduction(LObject** los, int & losl, calc_dat* c) 2803 { 2804 2805 //initialize; 2806 assume(c->strat->sl>=0); 2807 assume(losl>0); 2808 int i; 2809 for(i=0;i<losl;i++){ 2810 los[i]->SetShortExpVector(); 2811 los[i]->p=kBucketGetLm(los[i]->bucket); 2812 } 2813 poly h=kBucketGetLm(los[i]->bucket); 2814 kStrategy strat=c->strat; 2815 int curr_pos=losl-1; 2816 2817 2818 // nicht reduzierbare einträge in ergebnisliste schreiben 2819 // nullen loeschen 2820 while(curr_pos>=0){ 2821 find_erg erg=multi_reduction_find(los, losl,c,curr_pos); 2822 if(erg.reduce_by<0) break; 2823 multi_reduction_lls_trick(los,losl,c,erg); 2824 //erweitern? muß noch implementiert werden 2825 int i; 2826 int len; 2827 poly reductor; 2828 if(erg.fromS){ 2829 reductor=strat->S[erg.reduce_by]; 2830 len=strat->lenS[erg.reduce_by]; 2831 2832 } 2833 else 2834 { 2835 //bucket aufloesen reduzieren, neu füllen 2836 2837 kBucketClear(los[erg.reduce_by]->bucket,&reductor,&len); 2838 2839 2840 } 2841 for(i=erg.to_reduce_l;i<=erg.to_reduce_u;i++) 2842 { 2843 assume((!erg.fromS)||(i!=erg.reduce_by)); 2844 number coef=kBucketPolyRed(los[i]->bucket,reductor, 2845 len, 2846 strat->kNoether); 2847 nDelete(&coef); 2848 los[i]->p = kBucketGetLm(los[i]->bucket); 2849 if(los[i]->p!=NULL) 2850 los[i]->SetShortExpVector(); 2851 } 2852 if(!erg.fromS) 2853 kBucketInit(los[erg.reduce_by]->bucket,reductor,len); 2854 2855 int deleted=multi_reduction_clear_zeroes(los, losl); 2856 losl -= deleted; 2857 curr_pos -= deleted; 2858 sort_region_down(los, erg.to_reduce_l, erg.to_reduce_u-deleted, c); 2859 } 2860 return; 2861 } -
Singular/tgb.h
r9d3636 r0191db 105 105 BOOLEAN is_char0; 106 106 }; 107 static int add_to_reductors(calc_dat* c, poly h, int len); 107 108 static int bucket_guess(kBucket* bucket); 108 109 static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
Note: See TracChangeset
for help on using the changeset viewer.