001/*
002 * $Id$
003 */
004
005package edu.jas.poly;
006
007
008import org.apache.logging.log4j.Logger;
009import org.apache.logging.log4j.LogManager; 
010
011import edu.jas.structure.RingElem;
012
013
014/**
015 * Generate Relation Table for Weyl Algebras Adds the respective relations to
016 * the relation table of the given solvable ring factory. Relations are of the
017 * form x<sub>j</sub> * x<sub>i</sub> = x<sub>i</sub> x<sub>j</sub> + 1.
018 * Iterated form: R{x1,y1,...,xn,yn; yi*xi = xi yi + 1}.
019 * @author Heinz Kredel
020 */
021
022public class WeylRelationsIterated<C extends RingElem<C>> implements RelationGenerator<C> {
023
024
025    /**
026     * The factory for the solvable polynomial ring.
027     */
028    private final GenSolvablePolynomialRing<C> ring;
029
030
031    private static final Logger logger = LogManager.getLogger(WeylRelationsIterated.class);
032
033
034    /**
035     * The no argument constructor. The relation table of this ring is setup to
036     * a Weyl Algebra.
037     */
038    public WeylRelationsIterated() {
039        ring = null;
040    }
041
042
043    /**
044     * The constructor requires a ring factory. The relation table of this ring
045     * is setup to a Weyl Algebra.
046     * @param r solvable polynomial ring factory, r must have even number of
047     *            variables.
048     */
049    public WeylRelationsIterated(GenSolvablePolynomialRing<C> r) {
050        if (r == null) {
051            throw new IllegalArgumentException("WeylRelations, ring == null");
052        }
053        ring = r;
054        if (ring.nvar <= 1 || (ring.nvar % 2) != 0) {
055            throw new IllegalArgumentException("WeylRelations, wrong nvar = " + ring.nvar);
056        }
057    }
058
059
060    /**
061     * Generates the relation table of this ring. Iterated form:
062     * R{x1,y1,...,xn,yn; yi*xi = xi yi + 1}.
063     */
064    public void generate() {
065        if (ring == null) {
066            throw new IllegalArgumentException("WeylRelations, ring == null");
067        }
068        generate(ring);
069    }
070
071
072    /**
073     * Generates the relation table of this ring. Iterated form:
074     * R{x1,y1,...,xn,yn; yi*xi = xi yi + 1}.
075     * @param ring solvable polynomial ring factory, ring must have even number
076     *            of variables.
077     */
078    public void generate(GenSolvablePolynomialRing<C> ring) {
079        if (ring == null) {
080            throw new IllegalArgumentException("WeylRelations, ring == null");
081        }
082        if (ring.nvar <= 1 || (ring.nvar % 2) != 0) {
083            throw new IllegalArgumentException("WeylRelations, wrong nvar = " + ring.nvar);
084        }
085        RelationTable<C> table = ring.table;
086        int r = ring.nvar;
087        //int m =  r / 2;
088        GenSolvablePolynomial<C> one = ring.getONE().copy();
089        GenSolvablePolynomial<C> zero = ring.getZERO().copy();
090        for (int i = 1; i <= r; i += 2) {
091            ExpVector f = ExpVector.create(r, i, 1);
092            int j = i - 1;
093            ExpVector e = ExpVector.create(r, j, 1);
094            ExpVector ef = e.sum(f);
095            GenSolvablePolynomial<C> b = one.multiply(ef);
096            GenSolvablePolynomial<C> rel = (GenSolvablePolynomial<C>) b.sum(one);
097            //  = (GenSolvablePolynomial<C>)b.subtract(one);
098            if (rel.isZERO()) {
099                logger.info("ring = {}", ring);
100                logger.info("one  = {}", one);
101                logger.info("zero = {}", zero);
102                logger.info("b    = {}", b);
103                logger.info("rel  = {}", rel);
104                //System.exit(1);
105                throw new RuntimeException("rel.isZERO()");
106            }
107            //System.out.println("rel = " + rel.toString(ring.vars));
108            table.update(e, f, rel);
109        }
110        logger.debug("\nWeyl relations = {}", table);
111        return;
112    }
113
114}