/*
 * $Id$
 */

package edu.jas.application;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import edu.jas.poly.PolynomialList;
import edu.jas.poly.OrderedPolynomialList;
import edu.jas.poly.GenPolynomial;
import edu.jas.poly.GenPolynomialRing;
import edu.jas.structure.GcdRingElem;


/**
 * Container for a Groebner system. 
 * It contains a list of colored systems and a
 * list of parametric polynomials representing the 
 * corresponding comprehensive Groebner base.
 * @param  coefficient type
 */
public class GroebnerSystem> {


    private static final Logger logger = Logger.getLogger(GroebnerSystem.class);


    private final boolean debug = logger.isDebugEnabled();


    /**
     * List of colored systems.
     */
    public final List> list;


    /**
     * List of conditions for this Groebner system.
     */
    protected List> conds;


    /**
     * Comprehensive Groebner base for this Groebner system.
     */
    protected PolynomialList> cgb;


    /**
     * Constructor for a Groebner system.
     * @param S a list of colored systems.
     */
    public GroebnerSystem(List> S) {
        this.list = S;
        this.conds = null;
        this.cgb = null;
    }


    /**
     * Get the String representation.
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer("GroebnerSystem: \n");
        boolean first = true;
        for (ColoredSystem cs : list) {
            if ( first ) {
               first = false;
            } else {
               sb.append("\n");
            }
            sb.append( cs.toString() );
        }
        sb.append("Conditions:\n");
        first = true;
        for ( Condition cond : getConditions() ) {
            if ( first ) {
                first = false;
            } else {
                sb.append("\n");
            }
            sb.append( cond.toString() );
        }
        sb.append("\n");
        if ( cgb == null ) {
           sb.append("Comprehensive Groebner Base not jet computed\n");
        } else {
           sb.append("Comprehensive Groebner Base:\n");
           first = true;
           for ( GenPolynomial> p : getCGB() ) {
               if ( first ) {
                  first = false;
               } else {
                  sb.append(",\n");
               }
               sb.append( p.toString() );
           }
           sb.append("\n");
        }
        return sb.toString();
    }


    /**
     * Is this Groebner system equal to other.
     * @param c other Groebner system.
     * @return true, if this is equal to other, else false.
     */
    @Override
    @SuppressWarnings("unchecked")
    public boolean equals(Object c) {
        GroebnerSystem cs = null;
        try {
            cs = (GroebnerSystem) c;
        } catch (ClassCastException e) {
            return false;
        }
        if (cs == null) {
            return false;
        }
        boolean t = list.equals(cs.list);
        return t;
    }


    /**
     * Hash code for this colored system.
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        int h;
        h = list.hashCode();
        return h;
    }


    /**
     * Check invariants. Check if all colored systems are determined and 
     * all invariants are met.
     * @return true, if all invariants are met, else false.
     */
    public boolean checkInvariant() {
        for (ColoredSystem s : list) {
            if (!s.checkInvariant()) {
                return false;
            }
        }
        return true;
    }


    /**
     * Is each colored system completely determined.
     * @return true, if each ColoredSystem is determined, else false.
     */
    public boolean isDetermined() {
        for (ColoredSystem s : list) {
            if (!s.isDetermined()) {
                return false;
            }
        }
        return true;
    }


    /**
     * Get list of conditions determining this Groebner system. 
     * @return list of determining conditions.
     */
    public List> getConditions() {
        if ( conds != null ) {
           return conds;
        }
        List> cd = new ArrayList>( list.size() );
        for (ColoredSystem cs : list) {
            cd.add(cs.condition);
        }
        conds = cd;
        return conds;
    }


    /**
     * Get comprehensive Groebner base. 
     * @return the comprehensive Groebner base for this Groebner system.
     */
    public List>> getCGB() {
        if ( cgb != null ) {
           return cgb.list;
        }
        // assure conditions are collected
        List> unused = getConditions();
        if ( unused.isEmpty() ) { // use for findbugs
            logger.info("unused is empty");
        }
        // combine for CGB
        Set>> Gs 
           = new HashSet>>();
        for (ColoredSystem cs : list) {
            if (debug) {
                if (!cs.isDetermined()) {
                    System.out.println("not determined, cs = " + cs);
                }
                if (!cs.checkInvariant()) {
                    System.out.println("not invariant, cs = " + cs);
                }
            }
            for (ColorPolynomial p : cs.list) {
                GenPolynomial> f = p.getPolynomial();
                Gs.add(f);
            }
        }
        List>> G 
            = new ArrayList>>(Gs);
        GenPolynomialRing> ring = null;
        if ( G.size() > 0 ) {
           ring = G.get(0).ring;
        }
        cgb = new OrderedPolynomialList>(ring,G);
        return G;
    }

}

 

Ads help maintain this website.