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