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