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