001/*
002 * $Id: ModGroebnerBaseAbstract.java 4178 2012-09-09 10:45:10Z kredel $
003 */
004
005package edu.jas.gbmod;
006
007
008import java.util.List;
009
010import edu.jas.gb.GroebnerBase;
011import edu.jas.gbufd.GBFactory;
012import edu.jas.poly.GenPolynomial;
013import edu.jas.poly.ModuleList;
014import edu.jas.poly.PolynomialList;
015import edu.jas.structure.GcdRingElem;
016import edu.jas.structure.RingFactory;
017
018
019/**
020 * Module Groebner Bases abstract class. Implements Groebner bases and GB test.
021 * @author Heinz Kredel
022 */
023
024public class ModGroebnerBaseAbstract<C extends GcdRingElem<C>> implements ModGroebnerBase<C> {
025
026
027    //private static final Logger logger = Logger.getLogger(ModGroebnerBase.class);
028
029
030    /**
031     * Used Groebner base algorithm.
032     */
033    protected final GroebnerBase<C> bb;
034
035
036    /**
037     * Constructor.
038     */
039    @Deprecated
040    public ModGroebnerBaseAbstract() {
041        bb = GBFactory.getImplementation();
042    }
043
044
045    /**
046     * Constructor.
047     */
048    public ModGroebnerBaseAbstract(RingFactory<C> cf) {
049        bb = GBFactory.getImplementation(cf);
050    }
051
052
053    /**
054     * Module Groebner base test.
055     */
056    public boolean isGB(int modv, List<GenPolynomial<C>> F) {
057        return bb.isGB(modv, F);
058    }
059
060
061    /**
062     * isGB.
063     * @param M a module basis.
064     * @return true, if M is a Groebner base, else false.
065     */
066    public boolean isGB(ModuleList<C> M) {
067        if (M == null || M.list == null) {
068            return true;
069        }
070        if (M.rows == 0 || M.cols == 0) {
071            return true;
072        }
073        PolynomialList<C> F = M.getPolynomialList();
074        int modv = M.cols; // > 0  
075        return bb.isGB(modv, F.list);
076    }
077
078
079    /**
080     * Groebner base using pairlist class.
081     */
082    public List<GenPolynomial<C>> GB(int modv, List<GenPolynomial<C>> F) {
083        return bb.GB(modv, F);
084    }
085
086
087    /**
088     * GB.
089     * @param M a module basis.
090     * @return GB(M), a Groebner base of M.
091     */
092    public ModuleList<C> GB(ModuleList<C> M) {
093        ModuleList<C> N = M;
094        if (M == null || M.list == null) {
095            return N;
096        }
097        if (M.rows == 0 || M.cols == 0) {
098            return N;
099        }
100
101        PolynomialList<C> F = M.getPolynomialList();
102        int modv = M.cols;
103        List<GenPolynomial<C>> G = bb.GB(modv, F.list);
104        F = new PolynomialList<C>(F.ring, G);
105        N = F.getModuleList(modv);
106        return N;
107    }
108
109}