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