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