001 /* 002 * $Id: CriticalPair.java 3416 2010-12-19 15:45:06Z kredel $ 003 */ 004 005 package edu.jas.gb; 006 007 import java.io.Serializable; 008 009 import edu.jas.structure.RingElem; 010 011 import edu.jas.poly.ExpVector; 012 import edu.jas.poly.GenPolynomial; 013 014 015 /** 016 * Serializable subclass to hold critical pairs of polynomials. 017 * Used also to manage reduction status of the pair. 018 * @param <C> coefficient type 019 * @author Heinz Kredel. 020 */ 021 public class CriticalPair<C extends RingElem<C> > extends AbstractPair<C> 022 implements Serializable { 023 024 protected volatile boolean inReduction; 025 protected volatile GenPolynomial<C> reductum; 026 //public final ExpVector sugar; 027 028 029 /** 030 * CriticalPair constructor. 031 * @param e lcm(lt(pi),lt(pj). 032 * @param pi polynomial i. 033 * @param pj polynomial j. 034 * @param i index of pi. 035 * @param j index pf pj. 036 */ 037 public CriticalPair(ExpVector e, 038 GenPolynomial<C> pi, GenPolynomial<C> pj, 039 int i, int j) { 040 super(e,pi,pj,i,j); 041 inReduction = false; 042 reductum = null; 043 } 044 045 046 /** 047 * toString. 048 */ 049 @Override 050 public String toString() { 051 StringBuffer s = new StringBuffer(super.toString() + "[ "); 052 if ( inReduction ) { 053 s.append("," + inReduction); 054 } 055 if ( reductum != null ) { 056 s.append("," + reductum.leadingExpVector()); 057 } 058 s.append(" ]"); 059 return s.toString(); 060 } 061 062 063 /** 064 * Set in reduction status. 065 * inReduction is set to true. 066 */ 067 public void setInReduction() { 068 if ( inReduction ) { 069 throw new IllegalStateException("already in reduction " + this); 070 } 071 inReduction = true; 072 } 073 074 075 /** 076 * Get in reduction status. 077 * @return true if the polynomial is currently in reduction, else false. 078 */ 079 public boolean getInReduction() { 080 return inReduction; 081 } 082 083 084 /** 085 * Get reduced polynomial. 086 * @return the reduced polynomial or null if not done. 087 */ 088 public GenPolynomial<C> getReductum() { 089 return reductum; 090 } 091 092 093 /** 094 * Set reduced polynomial. 095 * @param r the reduced polynomial. 096 */ 097 public void setReductum(GenPolynomial<C> r) { 098 if ( r == null ) { 099 throw new IllegalArgumentException("reduction null not allowed " + this); 100 } 101 inReduction = false; 102 reductum = r; 103 } 104 105 106 /** 107 * Is reduced to zero. 108 * @return true if the S-polynomial of this CriticalPair 109 * was reduced to ZERO, else false. 110 */ 111 public boolean isZERO() { 112 if ( reductum == null ) { // not jet done 113 return false; 114 } 115 return reductum.isZERO(); 116 } 117 118 119 /** 120 * Is reduced to one. 121 * @return true if the S-polynomial of this CriticalPair was 122 * reduced to ONE, else false. 123 */ 124 public boolean isONE() { 125 if ( reductum == null ) { // not jet done 126 return false; 127 } 128 return reductum.isONE(); 129 } 130 131 } 132