package math.equation;

import math.number.NumberComplex;

/**
 * quotient ( a(x) + b(x)i ) / ( c(x) + d(x)i )
 * @author Daniel Weschke
 */
public class RationalPolynomialComplex {
	
	/**
	 * Dividend / numerator
	 */
	private PolynomialComplex a;
	
	/**
	 * Divisor / denominator
	 */
	private PolynomialComplex b;
	
	public RationalPolynomialComplex(){
	}
	
	public RationalPolynomialComplex(RationalPolynomial f){
		setDivident(new PolynomialComplex(f.a));
		b = new PolynomialComplex(f.b);
	}
	
	public RationalPolynomialComplex(String cpol){
    	String[] ri = cpol.split(";");
    	int size = ri.length;
    	if(size == 1){
    		setDivident(new PolynomialComplex(ri[0]));
//    		b = new ComplexPolynomial();
    	}
    	if(size == 2){
    		setDivident(new PolynomialComplex(ri[0]));
    		b = new PolynomialComplex(ri[1]);
    	}
	}
	
	public RationalPolynomialComplex(PolynomialComplex a, PolynomialComplex b){
		this.a = a;
		this.b = b;
	}
	
	public NumberComplex evaluate(double x){
		return a.evaluate(x).over(b.evaluate(x));
//		return new RationalComplex(a.evaluate(x),b.evaluate(x)));
	}
	
	public double mod(double x){
		return a.mod(x)/b.mod(x);
	}
	
	public double argd(double x){
		return evaluate(x).argd();
	}

	public PolynomialComplex getDivident() {
		return a;
	}

	public void setDivident(PolynomialComplex a) {
		this.a = a;
	}

	public PolynomialComplex getDivisor() {
		return b;
	}

	public void setDivisor(PolynomialComplex b) {
		this.b = b;
	}
    
    /**
     * set the symbolic of all polynomials
     * @param symb symbolic
     */
    public void setSymbolic(String symb){
    	a.setSymbolic(symb);
    	b.setSymbolic(symb);
    }
    
	@Override
	public String toString(){
		String p = ""+getDivident();
		String q = ""+b;
		int size = p.length() > q.length() ? p.length() : q.length();
		String sep = "";
		for(int i=0; i<size; i++)
			sep += "-";
		String s = p+"\n";
		if(b.getRe().getCoef(0) != 1 || b.getRe().degree() != 0) s += sep+"\n" + q+"\n";
		return s;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RationalPolynomialComplex cpol = new RationalPolynomialComplex("10; 576 240 24 0");
		cpol.setSymbolic("ω");
		System.out.println(cpol);
		NumberComplex cn = cpol.evaluate(0.125);
		System.out.println(cn);
		System.out.println(cn.mod());
		System.out.println(cn.argd());
	}
}
