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