concat the lists h1 and h2 without zeros
| 787 | |
| 788 | /// concat the lists h1 and h2 without zeros |
| 789 | ideal id_SimpleAdd (ideal h1,ideal h2, const ring R) |
| 790 | { |
| 791 | id_Test(h1, R); |
| 792 | id_Test(h2, R); |
| 793 | |
| 794 | if ( idIs0(h1) ) |
| 795 | { |
| 796 | ideal res=id_Copy(h2,R); |
| 797 | if (res->rank<h1->rank) res->rank=h1->rank; |
| 798 | return res; |
| 799 | } |
| 800 | if ( idIs0(h2) ) |
| 801 | { |
| 802 | ideal res=id_Copy(h1,R); |
| 803 | if (res->rank<h2->rank) res->rank=h2->rank; |
| 804 | return res; |
| 805 | } |
| 806 | |
| 807 | int j = IDELEMS(h1)-1; |
| 808 | while ((j >= 0) && (h1->m[j] == NULL)) j--; |
| 809 | |
| 810 | int i = IDELEMS(h2)-1; |
| 811 | while ((i >= 0) && (h2->m[i] == NULL)) i--; |
| 812 | |
| 813 | const int r = si_max(h1->rank, h2->rank); |
| 814 | |
| 815 | ideal result = idInit(i+j+2,r); |
| 816 | |
| 817 | int l; |
| 818 | |
| 819 | for (l=j; l>=0; l--) |
| 820 | result->m[l] = p_Copy(h1->m[l],R); |
| 821 | |
| 822 | j = i+j+1; |
| 823 | for (l=i; l>=0; l--, j--) |
| 824 | result->m[j] = p_Copy(h2->m[l],R); |
| 825 | |
| 826 | return result; |
| 827 | } |
| 828 | |
| 829 | /// insert h2 into h1 (if h2 is not the zero polynomial) |
| 830 | /// return TRUE iff h2 was indeed inserted |
no test coverage detected