/**
 * This class stores commonly used constants and 
 * functions of global character.
 */
public class Globals {
    
	public final static String VERSION = "Ver. 1.1";
    //public final static double PI = 4*Math.atan(1.0); use Math.PI
    public final static double TOLERANCE = 1e-11;
    public final static Complex complexZero = new Complex(0.0);
    public final static Complex complexOne = new Complex(1.0);
    //Pauli matrices and two dim identity
    public final static Complex[][] sigX = 
        {{complexZero, complexOne},
        {complexOne, complexZero}};
    public final static Complex[][] sigY = 
        {{complexZero, new Complex(0.0, -1.0)},
        {new Complex(0.0, 1.0), complexZero}};
    public final static Complex[][] sigZ = 
        {{complexOne, complexZero},
        {complexZero, new Complex(-1.0, 0.0)}};
    public final static Complex[][] id2 = 
        {{complexOne, complexZero},
        {complexZero, complexOne}};
    //one bit Hadamard
    public final static Complex[][] had2 = 
        {{new Complex(1/Math.sqrt(2), 0.0), new Complex(1/Math.sqrt(2), 0.0)},
        {new Complex(1/Math.sqrt(2), 0.0), new Complex(-1/Math.sqrt(2), 0.0)}};
    
    public static double log2(double x){
        return Math.log(x)/Math.log(2);      
    }
    public static double sinc(double x){
    	//sinc(x) 	= sin(x)/x
    	//			=\sum_{k=0}^{\infty} x^{2k}(-1)^k/(2k+1)!

    	double y;
    	if(Math.abs(x)<1e-3){
    		double xSq = x*x;
    		
    		double kSummand = 1;
    		y = 1;    		    		
    		int k = 1;
    		do{
    			kSummand *= -xSq/((2*k+1)*2*k);
    			y += kSummand;
    			k++;
    		}while(Math.abs(kSummand)>1e-15);
    		
    	}else{
    		y = Math.sin(x)/x;
    	}
    	
    	return y;
    	
    }
}
