| 53 | /// compressing two polynomials F and G, M is used for compressing, |
| 54 | /// N to reverse the compression |
| 55 | static int myCompress (const CanonicalForm& F, const CanonicalForm& G, CFMap & M, |
| 56 | CFMap & N, bool topLevel) |
| 57 | { |
| 58 | int n= tmax (F.level(), G.level()); |
| 59 | int * degsf= NEW_ARRAY(int,n + 1); |
| 60 | int * degsg= NEW_ARRAY(int,n + 1); |
| 61 | |
| 62 | for (int i = 0; i <= n; i++) |
| 63 | degsf[i]= degsg[i]= 0; |
| 64 | |
| 65 | degsf= degrees (F, degsf); |
| 66 | degsg= degrees (G, degsg); |
| 67 | |
| 68 | int both_non_zero= 0; |
| 69 | int f_zero= 0; |
| 70 | int g_zero= 0; |
| 71 | int both_zero= 0; |
| 72 | int Flevel=F.level(); |
| 73 | int Glevel=G.level(); |
| 74 | |
| 75 | if (topLevel) |
| 76 | { |
| 77 | for (int i= 1; i <= n; i++) |
| 78 | { |
| 79 | if (degsf[i] != 0 && degsg[i] != 0) |
| 80 | { |
| 81 | both_non_zero++; |
| 82 | continue; |
| 83 | } |
| 84 | if (degsf[i] == 0 && degsg[i] != 0 && i <= Glevel) |
| 85 | { |
| 86 | f_zero++; |
| 87 | continue; |
| 88 | } |
| 89 | if (degsg[i] == 0 && degsf[i] && i <= Flevel) |
| 90 | { |
| 91 | g_zero++; |
| 92 | continue; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (both_non_zero == 0) |
| 97 | { |
| 98 | DELETE_ARRAY(degsf); |
| 99 | DELETE_ARRAY(degsg); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | // map Variables which do not occur in both polynomials to higher levels |
| 104 | int k= 1; |
| 105 | int l= 1; |
| 106 | for (int i= 1; i <= n; i++) |
| 107 | { |
| 108 | if (degsf[i] != 0 && degsg[i] == 0 && i <= Flevel) |
| 109 | { |
| 110 | if (k + both_non_zero != i) |
| 111 | { |
| 112 | M.newpair (Variable (i), Variable (k + both_non_zero)); |