001    /*
002     * $Id: WeylRelations.java 1894 2008-07-12 13:50:23Z kredel $
003     */
004    
005    package edu.jas.poly;
006    
007    import org.apache.log4j.Logger;
008    
009    import edu.jas.structure.RingElem;
010    
011    
012    /**
013     * Generate Relation Table for Weyl Algebras
014     * Adds the respective relations to the relation table
015     * of the given solvable ring factory. Relations are of the 
016     * form x<sub>j</sub> * x<sub>i</sub> = x<sub>i</sub> x<sub>j</sub> + 1.
017     * @author Heinz Kredel.
018     */
019    
020    public class WeylRelations<C extends RingElem<C>> {
021    
022    
023        /** The factory for the solvable polynomial ring. 
024         */
025        private final GenSolvablePolynomialRing<C> ring;
026    
027    
028        private static final Logger logger = Logger.getLogger(WeylRelations.class);
029    
030    
031        /** The constructor requires a ring factory.
032         * The relation table of this ring is setup to a Weyl Algebra.
033         * @param r solvable polynomial ring factory,
034         * r must have even number of variables.
035         */
036        public WeylRelations(GenSolvablePolynomialRing<C> r) {
037            if ( r == null ) {
038               throw new IllegalArgumentException("WeylRelations, ring == null");
039            }
040            ring = r;
041            if ( ring.nvar <= 1 || (ring.nvar % 2) != 0 ) {
042               throw new IllegalArgumentException("WeylRelations, wrong nvar = "
043                                                  + ring.nvar);
044            }
045        }
046    
047    
048        /** Generates the relation table of this ring.
049         */
050        public void generate() {
051            RelationTable<C> table = ring.table;
052            int r = ring.nvar;
053            int m =  r / 2;
054            //ExpVector z = ring.evzero;
055            GenSolvablePolynomial<C> one  = ring.getONE().clone();
056            GenSolvablePolynomial<C> zero = ring.getZERO().clone();
057            for ( int i = m; i < r; i++ ) {
058                ExpVector f = ExpVector.create(r,i,1); 
059                int j = i - m;
060                ExpVector e = ExpVector.create(r,j,1);
061                ExpVector ef = e.sum(f);
062                GenSolvablePolynomial<C> b = one.multiply(ef);
063                GenSolvablePolynomial<C> rel 
064                    = (GenSolvablePolynomial<C>)b.sum(one);
065                //                = (GenSolvablePolynomial<C>)b.subtract(one);
066                if ( rel.isZERO() ) {
067                   logger.info("ring = " + ring);
068                   logger.info("one  = " + one);
069                   logger.info("zero = " + zero);
070                   logger.info("b    = " + b);
071                   logger.info("rel  = " + rel);
072                   //System.exit(1);
073                   throw new RuntimeException("rel.isZERO()");
074                }
075                //System.out.println("rel = " + rel.toString(ring.vars));
076                table.update(e,f,rel);
077            }
078            if ( logger.isDebugEnabled() ) {
079               logger.debug("\nWeyl relations = " + table);
080            }
081            return;
082        }
083    
084    }