User:Userminusone/CommaFinder.java

From Xenharmonic Wiki
Jump to navigation Jump to search
import java.util.*;

class CommaFinder
{
	public static void main (String[] args)
	{
		LinkedList<Long> subgroup = new LinkedList<Long>();
		subgroup.add(2l);subgroup.add(3l);subgroup.add(13l);
		System.out.println("{| class=\"wikitable sortable\"");
		System.out.println("!Ratio");
		System.out.println("!Cent value");
		System.out.println("!Subgroup");
		System.out.println("!(Subgroup complexity)^2");
		System.out.println("!Esoteric factor");
		System.out.println("|-");
		System.out.println("|[[13/12]]");
		System.out.println("|"+String.format("%.3f",(1200.0*Math.log(13.0/12.0)/Math.log(2))));
		System.out.println("|"+printSubgroup(subgroup));
		System.out.println("|"+String.format("%.7f",complexitySquared(subgroup)));
		System.out.println("|"+String.format("%.3f",esotericFactor(13,12,subgroup)));
		long a = 1;
		long b = 1;
		long c = 13;
		long d = 12;
		long e = 0;
		long f = 0;
		long tempe;
		long tempf;
		long limit;
		long cur;
		LinkedList<String> everything = new LinkedList<String>();

		for(long y=2;y<=8192;y++){
			for(long x=1;x<y;x++){
				subgroup = new LinkedList<Long>();
				limit = 2;
				e = a*y*(c+d)+x*(b*c-a*d);
				tempe = e;
				f = b*y*(c+d)-x*(b*c-a*d);
				tempf = f;
				cur = 2;
				while((cur*cur<=e)||(cur*cur<=f)){
					if((e%cur==0)&&(f%cur==0)){
						e/=cur;
						tempe/=cur;
						f/=cur;
						tempf/=cur;
						cur = 2;
					}else if(tempe%cur==0){
						tempe/=cur;
						if(!subgroup.contains(cur)) {
							subgroup.add(cur);
						}
						if(cur>limit) {
							limit = cur;
						}
						cur = 2;
					}else if(tempf%cur==0){
						tempf/=cur;
						if(!subgroup.contains(cur)) {
							subgroup.add(cur);
						}
						if(cur>limit) {
							limit = cur;
						}
						cur = 2;
					}else{
						cur++;
					}
				}
				if(tempe>tempf) {
					if(tempe>1) {
						if(tempf>1) {
							if(!subgroup.contains(tempf)) {
								subgroup.add(tempf);
							}
						}
						if(!subgroup.contains(tempe)) {
							subgroup.add(tempe);
						}
						if(tempe>limit) {
							limit = tempe;
						}
					}
				}else {
					if(tempf>1) {
						if(tempe>1) {
							if(!subgroup.contains(tempe)) {
								subgroup.add(tempe);
							}
						}
						if(!subgroup.contains(tempf)) {
							subgroup.add(tempf);
						}
						if(tempf>limit) {
							limit = tempf;
						}
					}
				}
				if(limit<=31&&esotericFactor(e,f,subgroup)<=1.5){
					if(!everything.contains(e+"/"+f)){
						System.out.println("|-");
						System.out.println("|[["+e+"/"+f+"]]");
						System.out.println("|"+String.format("%.3f",(1200.0*Math.log((double)e/(double)f)/Math.log(2))));
						System.out.println("|"+printSubgroup(subgroup));
						System.out.println("|"+String.format("%.7f",complexitySquared(subgroup)));
						System.out.println("|"+String.format("%.5f",esotericFactor(e,f,subgroup)));
						everything.add(e+"/"+f);
					}
				}
			}
		}
		System.out.println("|}");
	}

	public static double complexityOf(LinkedList<Long> subgroup) {
		long sum = 0;
		long amt = 1;
		long test = 2;
		long val;
		Iterator<Long> it = subgroup.iterator();
		while(it.hasNext()) {
			val = it.next();
			while(test<val) {
				test++;
				amt*=2;
			}
			sum+=amt;
		}
		return Math.log((double)sum)/Math.log(2.0);
	}

	public static double complexitySquared(LinkedList<Long> subgroup) {
		double temp = complexityOf(subgroup);
		return temp*temp;
	}
	public static double esotericFactor(long num,long den,LinkedList<Long> group) {
		double size = Math.log((double)num/(double)den)/Math.log(2);
		return size*size*Math.log((double)(num*den))/Math.log(2)*complexityOf(group);
	}
	public static String printSubgroup(LinkedList<Long> group) {
		String out = "";
		Iterator<Long> it = group.iterator();
		out+=it.next();
		while(it.hasNext()) {
			out+="."+it.next();
		}
		return out;
	}
}