All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.jas.application.IdealWithComplexAlgebraicRoots Maven / Gradle / Ivy

The newest version!
/*
 * $Id: IdealWithComplexAlgebraicRoots.java 4050 2012-07-25 17:14:32Z kredel $
 */

package edu.jas.application;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import edu.jas.arith.BigDecimal;
import edu.jas.arith.Rational;
import edu.jas.poly.Complex;
import edu.jas.poly.ComplexRing;
import edu.jas.poly.GenPolynomial;
//import edu.jas.root.RealAlgebraicNumber;
import edu.jas.structure.GcdRingElem;
import edu.jas.structure.RingElem;


/**
 * Container for Ideals together with univariate polynomials and complex algebraic
 * roots.
 * @author Heinz Kredel
 */
public class IdealWithComplexAlgebraicRoots & Rational>
        extends IdealWithUniv {


    /**
     * The list of complex algebraic roots.
     */
    public final List>>> can;


    /**
     * The list of decimal approximations of the complex algebraic roots.
     */
    protected List>> droots = null;


    /**
     * Constructor not for use.
     */
    protected IdealWithComplexAlgebraicRoots() {
        throw new IllegalArgumentException("do not use this constructor");
    }


    /**
     * Constructor.
     * @param id the ideal
     * @param up the list of univariate polynomials
     * @param cr the list of complex algebraic roots
     */
    public IdealWithComplexAlgebraicRoots(Ideal id, List> up,
            List>>> cr) {
        super(id, up);
        can = cr;
    }


    /**
     * Constructor.
     * @param iu the ideal with univariate polynomials
     * @param cr the list of real algebraic roots
     */
    public IdealWithComplexAlgebraicRoots(IdealWithUniv iu, List>>> cr) {
        super(iu.ideal, iu.upolys);
        can = cr;
    }


    /**
     * String representation of the ideal.
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer(super.toString() + "\ncomplex roots:\n");
        sb.append("[");
        boolean f1 = true;
        for (List>> lr : can) {
            if (!f1) {
                sb.append(", ");
            } else {
                f1 = false;
            }
            sb.append("[");
            boolean f2 = true;
            for (Complex> rr : lr) {
                if (!f2) {
                    sb.append(", ");
                } else {
                    f2 = false;
                }
                sb.append(rr.ring.toScript());
            }
            sb.append("]");
        }
        sb.append("]");
        if (droots != null) {
            sb.append("\ndecimal complex root approximation:\n");
            for (List> d : droots) {
                sb.append(d.toString());
                sb.append("\n");
            }
        }
        return sb.toString();
    }


    /**
     * Get a scripting compatible string representation.
     * @return script compatible representation for this Element.
     * @see edu.jas.structure.Element#toScript()
     */
    @Override
    public String toScript() {
        // Python case
        return super.toScript() + ",  " + can.toString();
    }


    /**
     * Get decimal approximation of the real root tuples.
     */
    public synchronized List>> decimalApproximation() {
        if (this.droots != null) {
            return droots;
        }
        List>> rroots = new ArrayList>>();
        ComplexRing cfac = new ComplexRing(new BigDecimal());
        for (List>> rri : this.can) {
            List> r = new ArrayList>();
            for (Complex> rr : rri) {
                BigDecimal dr = new BigDecimal(rr.getRe().magnitude());
                BigDecimal di = new BigDecimal(rr.getIm().magnitude());
                Complex d = new Complex(cfac,dr,di);
                r.add(d);
            }
            rroots.add(r);
        }
        droots = rroots;
        return rroots;
    }


    /**
     * compute decimal approximation of the real root tuples.
     */
    public void doDecimalApproximation() {
        List>> unused = decimalApproximation();
        if ( unused.isEmpty() ) { // use for findbugs
            System.out.println("unused is empty");
        }
        return;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy