001/*
002 * $Id$
003 */
004
005package edu.jas.poly;
006
007
008import java.util.ArrayList;
009import java.util.List;
010
011
012/**
013 * ExpVectorByte implements exponent vectors for polynomials using arrays of
014 * byte as storage unit. This class is used by ExpVector internally, there is no
015 * need to use this class directly.
016 * @see ExpVector
017 * @author Heinz Kredel
018 */
019
020public final class ExpVectorByte extends ExpVector
021/*implements AbelianGroupElem<ExpVectorByte>*/{
022
023
024    /**
025     * The data structure is an array of byte.
026     */
027    /*package*/final byte[] val;
028
029
030    /**
031     * Largest byte.
032     */
033    public static final long maxByte = (long) Byte.MAX_VALUE / 2;
034
035
036    /**
037     * Smallest byte.
038     */
039    public static final long minByte = (long) Byte.MIN_VALUE / 2;
040
041
042    /**
043     * Constructor for ExpVector.
044     * @param n length of exponent vector.
045     */
046    public ExpVectorByte(int n) {
047        this(new byte[n]);
048    }
049
050
051    /**
052     * Constructor for ExpVector. Sets exponent i to e.
053     * @param n length of exponent vector.
054     * @param i index of exponent to be set.
055     * @param e exponent to be set.
056     */
057    public ExpVectorByte(int n, int i, byte e) {
058        this(n);
059        val[i] = e;
060    }
061
062
063    /**
064     * Constructor for ExpVector. Sets exponent i to e.
065     * @param n length of exponent vector.
066     * @param i index of exponent to be set.
067     * @param e exponent to be set.
068     */
069    public ExpVectorByte(int n, int i, long e) {
070        this(n);
071        if (e >= maxByte || e <= minByte) {
072            throw new IllegalArgumentException("exponent to large: " + e);
073        }
074        val[i] = (byte) e;
075    }
076
077
078    /**
079     * Internal constructor for ExpVector. Sets val.
080     * @param v internal representation array.
081     */
082    protected ExpVectorByte(byte[] v) {
083        super();
084        val = v;
085    }
086
087
088    /**
089     * Constructor for ExpVector. Sets val, converts from long array.
090     * @param v long representation array.
091     */
092    public ExpVectorByte(long[] v) {
093        this(v.length);
094        for (int i = 0; i < v.length; i++) {
095            if (v[i] >= maxByte || v[i] <= minByte) {
096                throw new IllegalArgumentException("exponent to large: " + v[i]);
097            }
098            val[i] = (byte) v[i];
099        }
100    }
101
102
103    /**
104     * Constructor for ExpVector. Converts a String representation to an
105     * ExpVector. Accepted format = (1,2,3,4,5,6,7).
106     * @param s String representation.
107     */
108    public ExpVectorByte(String s) throws NumberFormatException {
109        super();
110        // first format = (1,2,3,4,5,6,7)
111        List<Byte> exps = new ArrayList<Byte>();
112        s = s.trim();
113        int b = s.indexOf('(');
114        int e = s.indexOf(')', b + 1);
115        String teil;
116        int k;
117        byte a;
118        if (b >= 0 && e >= 0) {
119            b++;
120            while ((k = s.indexOf(',', b)) >= 0) {
121                teil = s.substring(b, k);
122                a = Byte.parseByte(teil);
123                exps.add(Byte.valueOf(a));
124                b = k + 1;
125            }
126            if (b <= e) {
127                teil = s.substring(b, e);
128                a = Byte.parseByte(teil);
129                exps.add(Byte.valueOf(a));
130            }
131            int length = exps.size();
132            val = new byte[length];
133            for (int j = 0; j < length; j++) {
134                val[j] = exps.get(j).byteValue();
135            }
136        } else {
137            // not implemented
138            val = null;
139            // length = -1;
140            //Vector names = new Vector();
141            //vars = s;
142        }
143    }
144
145
146    /**
147     * Value of other.
148     * @param e other ExpVector.
149     * @return value in sub class of ExpVector.
150     */
151    //@Override
152    public static ExpVector valueOf(ExpVector e) {
153        return new ExpVectorByte(e.getVal());
154    }
155
156
157    /**
158     * Clone this.
159     * @see java.lang.Object#clone()
160     */
161    @Override
162    public ExpVectorByte copy() {
163        byte[] w = new byte[val.length];
164        System.arraycopy(val, 0, w, 0, val.length);
165        return new ExpVectorByte(w);
166    }
167
168
169    /**
170     * Get the exponent vector.
171     * @return val as long.
172     */
173    @Override
174    public long[] getVal() {
175        long v[] = new long[val.length];
176        for (int i = 0; i < val.length; i++) {
177            v[i] = val[i];
178        }
179        return v;
180    }
181
182
183    /**
184     * Get the exponent at position i.
185     * @param i position.
186     * @return val[i].
187     */
188    @Override
189    public long getVal(int i) {
190        return val[i];
191    }
192
193
194    /**
195     * Set the exponent at position i to e.
196     * @param i
197     * @param e
198     * @return old val[i].
199     */
200    @Override
201    protected long setVal(int i, long e) {
202        byte x = val[i];
203        if (e >= maxByte || e <= minByte) {
204            throw new IllegalArgumentException("exponent to large: " + e);
205        }
206        val[i] = (byte) e;
207        hash = -1; // beware of race condition
208        return x;
209    }
210
211
212    /**
213     * Set the exponent at position i to e.
214     * @param i
215     * @param e
216     * @return old val[i].
217     */
218    protected byte setVal(int i, byte e) {
219        byte x = val[i];
220        val[i] = e;
221        hash = -1; // beware of race condition
222        return x;
223    }
224
225
226    /**
227     * Get the length of this exponent vector.
228     * @return val.length.
229     */
230    @Override
231    public int length() {
232        return val.length;
233    }
234
235
236    /**
237     * Extend variables. Used e.g. in module embedding. Extend this by i
238     * elements and set val[j] to e.
239     * @param i number of elements to extend.
240     * @param j index of element to be set.
241     * @param e new exponent for val[j].
242     * @return extended exponent vector.
243     */
244    @Override
245    public ExpVectorByte extend(int i, int j, long e) {
246        byte[] w = new byte[val.length + i];
247        System.arraycopy(val, 0, w, i, val.length);
248        if (j >= i) {
249            throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid");
250        }
251        if (e >= maxByte || e <= minByte) {
252            throw new IllegalArgumentException("exponent to large: " + e);
253        }
254        w[j] = (byte) e;
255        return new ExpVectorByte(w);
256    }
257
258
259    /**
260     * Extend lower variables. Extend this by i lower elements and set val[j] to
261     * e.
262     * @param i number of elements to extend.
263     * @param j index of element to be set.
264     * @param e new exponent for val[j].
265     * @return extended exponent vector.
266     */
267    @Override
268    public ExpVectorByte extendLower(int i, int j, long e) {
269        byte[] w = new byte[val.length + i];
270        System.arraycopy(val, 0, w, 0, val.length);
271        if (j >= i) {
272            throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid");
273        }
274        w[val.length + j] = (byte) e;
275        return new ExpVectorByte(w);
276    }
277
278
279    /**
280     * Contract variables. Used e.g. in module embedding. Contract this to len
281     * elements.
282     * @param i position of first element to be copied.
283     * @param len new length.
284     * @return contracted exponent vector.
285     */
286    @Override
287    public ExpVectorByte contract(int i, int len) {
288        if (i + len > val.length) {
289            throw new IllegalArgumentException("len " + len + " > val.len " + val.length);
290        }
291        byte[] w = new byte[len];
292        System.arraycopy(val, i, w, 0, len);
293        return new ExpVectorByte(w);
294    }
295
296
297    /**
298     * Reverse variables. Used e.g. in opposite rings.
299     * @return reversed exponent vector.
300     */
301    @Override
302    public ExpVectorByte reverse() {
303        byte[] w = new byte[val.length];
304        for (int i = 0; i < val.length; i++) {
305            w[i] = val[val.length - 1 - i];
306        }
307        return new ExpVectorByte(w);
308    }
309
310
311    /**
312     * Reverse lower j variables. Used e.g. in opposite rings. Reverses the
313     * first j-1 variables, the rest is unchanged.
314     * @param j index of first variable reversed.
315     * @return reversed exponent vector.
316     */
317    @Override
318    public ExpVectorByte reverse(int j) {
319        if (j < 0 || j > val.length) {
320            return this;
321        }
322        byte[] w = new byte[val.length];
323        for (int i = 0; i < j; i++) {
324            w[i] = val[i];
325        }
326        for (int i = j; i < val.length; i++) {
327            w[i] = val[val.length + j - 1 - i];
328        }
329        return new ExpVectorByte(w);
330    }
331
332
333    /**
334     * Combine with ExpVector. Combine this with the other ExpVector V.
335     * @param V the other exponent vector.
336     * @return combined exponent vector.
337     */
338    @Override
339    public ExpVectorByte combine(ExpVector V) {
340        if (V == null || V.length() == 0) {
341            return this;
342        }
343        ExpVectorByte Vi = (ExpVectorByte) V;
344        if (val.length == 0) {
345            return Vi;
346        }
347        byte[] w = new byte[val.length + Vi.val.length];
348        System.arraycopy(val, 0, w, 0, val.length);
349        System.arraycopy(Vi.val, 0, w, val.length, Vi.val.length);
350        return new ExpVectorByte(w);
351    }
352
353
354    /**
355     * Permutation of exponent vector.
356     * @param P permutation.
357     * @return P(e).
358     */
359    @Override
360    public ExpVectorByte permutation(List<Integer> P) {
361        byte[] w = new byte[val.length];
362        int j = 0;
363        for (Integer i : P) {
364            w[j++] = val[i];
365        }
366        return new ExpVectorByte(w);
367    }
368
369
370    /**
371     * Get the string representation.
372     * @see java.lang.Object#toString()
373     */
374    @Override
375    public String toString() {
376        return super.toString() + ":byte";
377    }
378
379
380    /**
381     * Comparison with any other object.
382     * @see java.lang.Object#equals(java.lang.Object)
383     */
384    @Override
385    public boolean equals(Object B) {
386        if (!(B instanceof ExpVectorByte)) {
387            return false;
388        }
389        ExpVectorByte b = (ExpVectorByte) B;
390        int t = this.invLexCompareTo(b);
391        //System.out.println("equals: this = " + this + " B = " + B + " t = " + t);
392        return (0 == t);
393    }
394
395
396    /**
397     * hashCode for this exponent vector.
398     * @see java.lang.Object#hashCode() Only for findbugs.
399     */
400    @Override
401    public int hashCode() {
402        return super.hashCode();
403    }
404
405
406    /**
407     * ExpVector absolute value.
408     * @return abs(this).
409     */
410    @Override
411    public ExpVectorByte abs() {
412        byte[] u = val;
413        byte[] w = new byte[u.length];
414        for (int i = 0; i < u.length; i++) {
415            if (u[i] >= 0L) {
416                w[i] = u[i];
417            } else {
418                w[i] = (byte) (-u[i]);
419            }
420        }
421        return new ExpVectorByte(w);
422        //return EVABS(this);
423    }
424
425
426    /**
427     * ExpVector negate.
428     * @return -this.
429     */
430    @Override
431    public ExpVectorByte negate() {
432        byte[] u = val;
433        byte[] w = new byte[u.length];
434        for (int i = 0; i < u.length; i++) {
435            w[i] = (byte) (-u[i]);
436        }
437        return new ExpVectorByte(w);
438        // return EVNEG(this);
439    }
440
441
442    /**
443     * ExpVector summation.
444     * @param V
445     * @return this+V.
446     */
447    @Override
448    public ExpVectorByte sum(ExpVector V) {
449        byte[] u = val;
450        byte[] v = ((ExpVectorByte) V).val;
451        byte[] w = new byte[u.length];
452        for (int i = 0; i < u.length; i++) {
453            w[i] = (byte) (u[i] + v[i]);
454        }
455        return new ExpVectorByte(w);
456        // return EVSUM(this, V);
457    }
458
459
460    /**
461     * ExpVector subtract. Result may have negative entries.
462     * @param V
463     * @return this-V.
464     */
465    @Override
466    public ExpVectorByte subtract(ExpVector V) {
467        byte[] u = val;
468        byte[] v = ((ExpVectorByte) V).val;
469        byte[] w = new byte[u.length];
470        for (int i = 0; i < u.length; i++) {
471            w[i] = (byte) (u[i] - v[i]);
472        }
473        return new ExpVectorByte(w);
474        //return EVDIF(this, V);
475    }
476
477
478    /**
479     * ExpVector multiply by scalar.
480     * @param s scalar
481     * @return s*this.
482     */
483    @Override
484    public ExpVectorByte scalarMultiply(long s) {
485        if (s >= maxByte || s <= minByte) {
486            throw new IllegalArgumentException("scalar to large: " + s);
487        }
488        byte[] u = val;
489        byte[] w = new byte[u.length];
490        byte sb = (byte) s;
491        for (int i = 0; i < u.length; i++) {
492            w[i] = (byte) (sb * u[i]);
493        }
494        return new ExpVectorByte(w);
495    }
496
497
498    /**
499     * ExpVector substitution. Clone and set exponent to d at position i.
500     * @param i position.
501     * @param d new exponent.
502     * @return substituted ExpVector.
503     */
504    public ExpVectorByte subst(int i, byte d) {
505        ExpVectorByte V = this.copy();
506        //long e = 
507        V.setVal(i, d);
508        return V;
509        //return EVSU(this, i, d);
510    }
511
512
513    /**
514     * ExpVector substitution. Clone and set exponent to d at position i.
515     * @param i position.
516     * @param d new exponent.
517     * @return substituted ExpVector.
518     */
519    @Override
520    public ExpVectorByte subst(int i, long d) {
521        ExpVectorByte V = this.copy();
522        //long e = 
523        V.setVal(i, d);
524        return V;
525        //return EVSU(this, i, d);
526    }
527
528
529    /**
530     * ExpVector signum.
531     * @return 0 if this is zero, -1 if some entry is negative, 1 if no entry is
532     *         negative and at least one entry is positive.
533     */
534    @Override
535    public int signum() {
536        int t = 0;
537        byte[] u = val;
538        for (int i = 0; i < u.length; i++) {
539            if (u[i] < 0) {
540                return -1;
541            }
542            if (u[i] > 0) {
543                t = 1;
544            }
545        }
546        return t;
547        //return EVSIGN(this);
548    }
549
550
551    /**
552     * ExpVector total degree.
553     * @return sum of all exponents.
554     */
555    @Override
556    public long totalDeg() {
557        long t = 0;
558        byte[] u = val; // U.val;
559        for (int i = 0; i < u.length; i++) {
560            t += u[i];
561        }
562        return t;
563        //return EVTDEG(this);
564    }
565
566
567    /**
568     * ExpVector maximal degree.
569     * @return maximal exponent.
570     */
571    @Override
572    public long maxDeg() {
573        long t = 0;
574        byte[] u = val;
575        for (int i = 0; i < u.length; i++) {
576            if (u[i] > t) {
577                t = u[i];
578            }
579        }
580        return t;
581        //return EVMDEG(this);
582    }
583
584
585    /**
586     * ExpVector minimal degree.
587     * @return minimal exponent.
588     */
589    @Override
590    public long minDeg() {
591        long t = Byte.MAX_VALUE;
592        byte[] u = val;
593        for (int i = 0; i < u.length; i++) {
594            if (u[i] < t) {
595                t = u[i];
596            }
597        }
598        return t;
599    }
600
601
602    /**
603     * ExpVector weighted degree.
604     * @param w weights.
605     * @return weighted sum of all exponents.
606     */
607    @Override
608    public long weightDeg(long[][] w) {
609        if (w == null || w.length == 0) {
610            return totalDeg(); // assume weight 1 
611        }
612        long t = 0;
613        byte[] u = val;
614        for (int j = 0; j < w.length; j++) {
615            long[] wj = w[j];
616            for (int i = 0; i < u.length; i++) {
617                t += wj[i] * u[i];
618            }
619        }
620        return t;
621    }
622
623
624    /**
625     * ExpVector weighted degree.
626     * @param w weights.
627     * @return weighted sum of all exponents.
628     */
629    @Override
630    public long weightDeg(long[] w) {
631        if (w == null || w.length == 0) {
632            return totalDeg(); // assume weight 1 
633        }
634        long t = 0;
635        byte[] u = val;
636        for (int i = 0; i < w.length; i++) {
637             t += w[i] * u[i];
638        }
639        return t;
640    }
641
642
643    /**
644     * ExpVector least common multiple.
645     * @param V
646     * @return component wise maximum of this and V.
647     */
648    @Override
649    public ExpVectorByte lcm(ExpVector V) {
650        byte[] u = val;
651        byte[] v = ((ExpVectorByte) V).val;
652        byte[] w = new byte[u.length];
653        for (int i = 0; i < u.length; i++) {
654            w[i] = (u[i] >= v[i] ? u[i] : v[i]);
655        }
656        return new ExpVectorByte(w);
657        //return EVLCM(this, V);
658    }
659
660
661    /**
662     * ExpVector greatest common divisor.
663     * @param V
664     * @return component wise minimum of this and V.
665     */
666    @Override
667    public ExpVectorByte gcd(ExpVector V) {
668        byte[] u = val;
669        byte[] v = ((ExpVectorByte) V).val;
670        byte[] w = new byte[u.length];
671        for (int i = 0; i < u.length; i++) {
672            w[i] = (u[i] <= v[i] ? u[i] : v[i]);
673        }
674        return new ExpVectorByte(w);
675        //return EVGCD(this, V);
676    }
677
678
679    /**
680     * ExpVector dependent variables.
681     * @return number of indices where val has positive exponents.
682     */
683    public int dependentVariables() {
684        int l = 0;
685        for (int i = 0; i < val.length; i++) {
686            if (val[i] > 0) {
687                l++;
688            }
689        }
690        return l;
691    }
692
693
694    /**
695     * ExpVector dependency on variables.
696     * @return array of indices where val has positive exponents.
697     */
698    @Override
699    public int[] dependencyOnVariables() {
700        byte[] u = val;
701        int l = dependentVariables();
702        int[] dep = new int[l];
703        if (l == 0) {
704            return dep;
705        }
706        int j = 0;
707        for (int i = 0; i < u.length; i++) {
708            if (u[i] > 0) {
709                dep[j] = i;
710                j++;
711            }
712        }
713        return dep;
714    }
715
716
717    /**
718     * ExpVector multiple test. Test if this is component wise greater or equal
719     * to V.
720     * @param V
721     * @return true if this is a multiple of V, else false.
722     */
723    @Override
724    public boolean multipleOf(ExpVector V) {
725        byte[] u = val;
726        byte[] v = ((ExpVectorByte) V).val;
727        boolean t = true;
728        for (int i = 0; i < u.length; i++) {
729            if (u[i] < v[i]) {
730                return false;
731            }
732        }
733        return t;
734        //return EVMT(this, V);
735    }
736
737
738    /**
739     * ExpVector compareTo.
740     * @param V
741     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
742     */
743    @Override
744    public int compareTo(ExpVector V) {
745        return this.invLexCompareTo(V);
746    }
747
748
749    /**
750     * ExpVector inverse lexicographical compareTo.
751     * @param V
752     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
753     */
754    @Override
755    public int invLexCompareTo(ExpVector V) {
756        byte[] u = val;
757        byte[] v = ((ExpVectorByte) V).val;
758        int t = 0;
759        for (int i = 0; i < u.length; i++) {
760            if (u[i] > v[i])
761                return 1;
762            if (u[i] < v[i])
763                return -1;
764        }
765        return t;
766        //return EVILCP(this, V);
767    }
768
769
770    /**
771     * ExpVector inverse lexicographical compareTo.
772     * @param V
773     * @param begin
774     * @param end
775     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
776     */
777    @Override
778    public int invLexCompareTo(ExpVector V, int begin, int end) {
779        byte[] u = val;
780        byte[] v = ((ExpVectorByte) V).val;
781        if (begin < 0) {
782            begin = 0;;
783        }
784        if (end >= val.length) {
785            end = val.length;
786        }
787        int t = 0;
788        for (int i = begin; i < end; i++) {
789            if (u[i] > v[i])
790                return 1;
791            if (u[i] < v[i])
792                return -1;
793        }
794        return t;
795        //return EVILCP(this, V, begin, end);
796    }
797
798
799    /**
800     * ExpVector inverse graded lexicographical compareTo.
801     * @param V
802     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
803     */
804    @Override
805    public int invGradCompareTo(ExpVector V) {
806        byte[] u = val;
807        byte[] v = ((ExpVectorByte) V).val;
808        int t = 0;
809        int i;
810        for (i = 0; i < u.length; i++) {
811            if (u[i] > v[i]) {
812                t = 1;
813                break;
814            }
815            if (u[i] < v[i]) {
816                t = -1;
817                break;
818            }
819        }
820        if (t == 0) {
821            return t;
822        }
823        long up = 0;
824        long vp = 0;
825        for (int j = i; j < u.length; j++) {
826            up += u[j];
827            vp += v[j];
828        }
829        if (up > vp) {
830            t = 1;
831        } else {
832            if (up < vp) {
833                t = -1;
834            }
835        }
836        return t;
837        //return EVIGLC(this, V);
838    }
839
840
841    /**
842     * ExpVector inverse graded lexicographical compareTo.
843     * @param V
844     * @param begin
845     * @param end
846     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
847     */
848    @Override
849    public int invGradCompareTo(ExpVector V, int begin, int end) {
850        byte[] u = val;
851        byte[] v = ((ExpVectorByte) V).val;
852        if (begin < 0) {
853            begin = 0;;
854        }
855        if (end >= val.length) {
856            end = val.length;
857        }
858        int t = 0;
859        int i;
860        for (i = begin; i < end; i++) {
861            if (u[i] > v[i]) {
862                t = 1;
863                break;
864            }
865            if (u[i] < v[i]) {
866                t = -1;
867                break;
868            }
869        }
870        if (t == 0) {
871            return t;
872        }
873        long up = 0;
874        long vp = 0;
875        for (int j = i; j < end; j++) {
876            up += u[j];
877            vp += v[j];
878        }
879        if (up > vp) {
880            t = 1;
881        } else {
882            if (up < vp) {
883                t = -1;
884            }
885        }
886        return t;
887        //return EVIGLC(this, V, begin, end);
888    }
889
890
891    /**
892     * ExpVector reverse inverse lexicographical compareTo.
893     * @param V
894     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
895     */
896    @Override
897    public int revInvLexCompareTo(ExpVector V) {
898        byte[] u = val;
899        byte[] v = ((ExpVectorByte) V).val;
900        int t = 0;
901        for (int i = u.length - 1; i >= 0; i--) {
902            if (u[i] > v[i])
903                return 1;
904            if (u[i] < v[i])
905                return -1;
906        }
907        return t;
908        //return EVRILCP(this, V);
909    }
910
911
912    /**
913     * ExpVector reverse inverse lexicographical compareTo.
914     * @param V
915     * @param begin
916     * @param end
917     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
918     */
919    @Override
920    public int revInvLexCompareTo(ExpVector V, int begin, int end) {
921        byte[] u = val;
922        byte[] v = ((ExpVectorByte) V).val;
923        if (begin < 0) {
924            begin = 0;;
925        }
926        if (end >= val.length) {
927            end = val.length;
928        }
929        int t = 0;
930        for (int i = end - 1; i >= begin; i--) {
931            if (u[i] > v[i])
932                return 1;
933            if (u[i] < v[i])
934                return -1;
935        }
936        return t;
937        //return EVRILCP(this, V, begin, end);
938    }
939
940
941    /**
942     * ExpVector reverse inverse graded compareTo.
943     * @param V
944     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
945     */
946    @Override
947    public int revInvGradCompareTo(ExpVector V) {
948        byte[] u = val;
949        byte[] v = ((ExpVectorByte) V).val;
950        int t = 0;
951        int i;
952        for (i = u.length - 1; i >= 0; i--) {
953            if (u[i] > v[i]) {
954                t = 1;
955                break;
956            }
957            if (u[i] < v[i]) {
958                t = -1;
959                break;
960            }
961        }
962        if (t == 0) {
963            return t;
964        }
965        long up = 0;
966        long vp = 0;
967        for (int j = i; j >= 0; j--) {
968            up += u[j];
969            vp += v[j];
970        }
971        if (up > vp) {
972            t = 1;
973        } else {
974            if (up < vp) {
975                t = -1;
976            }
977        }
978        return t;
979        //return EVRIGLC(this, V);
980    }
981
982
983    /**
984     * ExpVector reverse inverse graded compareTo.
985     * @param V
986     * @param begin
987     * @param end
988     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
989     */
990    @Override
991    public int revInvGradCompareTo(ExpVector V, int begin, int end) {
992        byte[] u = val;
993        byte[] v = ((ExpVectorByte) V).val;
994        if (begin < 0) {
995            begin = 0;;
996        }
997        if (end >= val.length) {
998            end = val.length;
999        }
1000        int t = 0;
1001        int i;
1002        for (i = end - 1; i >= begin; i--) {
1003            if (u[i] > v[i]) {
1004                t = 1;
1005                break;
1006            }
1007            if (u[i] < v[i]) {
1008                t = -1;
1009                break;
1010            }
1011        }
1012        if (t == 0) {
1013            return t;
1014        }
1015        long up = 0;
1016        long vp = 0;
1017        for (int j = i; j >= begin; j--) {
1018            up += u[j];
1019            vp += v[j];
1020        }
1021        if (up > vp) {
1022            t = 1;
1023        } else {
1024            if (up < vp) {
1025                t = -1;
1026            }
1027        }
1028        return t;
1029        //return EVRIGLC(this, V, begin, end);
1030    }
1031
1032
1033    /**
1034     * ExpVector inverse total degree lexicographical compareTo.
1035     * @param V
1036     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
1037     */
1038    @Override
1039    public int invTdegCompareTo(ExpVector V) {
1040        throw new UnsupportedOperationException("not implemented for byte ExpVector");
1041    }
1042
1043
1044    /**
1045     * ExpVector reverse lexicographical inverse total degree compareTo.
1046     * @param V
1047     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
1048     */
1049    @Override
1050    public int revLexInvTdegCompareTo(ExpVector V) {
1051        throw new UnsupportedOperationException("not implemented for byte ExpVector");
1052    }
1053
1054
1055    /**
1056     * ExpVector inverse weighted lexicographical compareTo.
1057     * @param w weight array.
1058     * @param V
1059     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
1060     */
1061    @Override
1062    public int invWeightCompareTo(long[][] w, ExpVector V) {
1063        byte[] u = val;
1064        byte[] v = ((ExpVectorByte) V).val;
1065        int t = 0;
1066        int i;
1067        for (i = 0; i < u.length; i++) {
1068            if (u[i] > v[i]) {
1069                t = 1;
1070                break;
1071            }
1072            if (u[i] < v[i]) {
1073                t = -1;
1074                break;
1075            }
1076        }
1077        if (t == 0) {
1078            return t;
1079        }
1080        for (int k = 0; k < w.length; k++) {
1081            long[] wk = w[k];
1082            long up = 0;
1083            long vp = 0;
1084            for (int j = i; j < u.length; j++) {
1085                up += wk[j] * u[j];
1086                vp += wk[j] * v[j];
1087            }
1088            if (up > vp) {
1089                return 1;
1090            } else if (up < vp) {
1091                return -1;
1092            }
1093        }
1094        return t;
1095        //return EVIWLC(w, this, V);
1096    }
1097
1098
1099    /**
1100     * ExpVector inverse weighted lexicographical compareTo.
1101     * @param w weight array.
1102     * @param V
1103     * @param begin
1104     * @param end
1105     * @return 0 if U == V, -1 if U &lt; V, 1 if U &gt; V.
1106     */
1107    @Override
1108    public int invWeightCompareTo(long[][] w, ExpVector V, int begin, int end) {
1109        byte[] u = val;
1110        byte[] v = ((ExpVectorByte) V).val;
1111        if (begin < 0) {
1112            begin = 0;;
1113        }
1114        if (end >= val.length) {
1115            end = val.length;
1116        }
1117        int t = 0;
1118        int i;
1119        for (i = begin; i < end; i++) {
1120            if (u[i] > v[i]) {
1121                t = 1;
1122                break;
1123            }
1124            if (u[i] < v[i]) {
1125                t = -1;
1126                break;
1127            }
1128        }
1129        if (t == 0) {
1130            return t;
1131        }
1132        for (int k = 0; k < w.length; k++) {
1133            long[] wk = w[k];
1134            long up = 0;
1135            long vp = 0;
1136            for (int j = i; j < end; j++) {
1137                up += wk[j] * u[j];
1138                vp += wk[j] * v[j];
1139            }
1140            if (up > vp) {
1141                return 1;
1142            } else if (up < vp) {
1143                return -1;
1144            }
1145        }
1146        return t;
1147        //return EVIWLC(w, this, V, begin, end);
1148    }
1149
1150}