Java source code for isomer enumeration
import javax.swing.*; // Swing GUI classes are defined here.
import java.awt.event.*; // Event handling class are defined here.
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.ActionListener;
import java.util.Vector;
import java.math.BigInteger;
import java.lang.*;
import java.text.*;
import java.math.*;
import java.io.*;
import java.awt.*;
public class IsocountApplet extends JApplet
{ JTextField display1;
JTextArea display2;
JPanel x = new JPanel();
JButton calculateButton, clearButton, sixteenButton, seventeenButton;
JLabel copyright;
static final String newline = "\n";
int whichone;
public void init()
{
// This method is called by the system before the applet
// appears. It is used here to create the button and add
// it to the "content pane" of the JApplet. An anonymous
// class is used to create an ActionListener for the button.
whichone=16;
calculateButton = new JButton("Calculate");
calculateButton.setBackground(new Color(200,200,255));
display1 = new JTextField();
display1.setEditable(true);
display2 = new JTextArea();
display2.setEditable(false);
JScrollPane scrollPane2 = new JScrollPane(display2);
sixteenButton = new JButton("C16 Disallowed");
sixteenButton.setBackground(new Color(200,200,255));
seventeenButton = new JButton("C17 Disallowed");
seventeenButton.setBackground(new Color(200,200,255));
clearButton = new JButton("Clear Text");
clearButton.setBackground(new Color(200,200,255));
JLabel spiel1 = new JLabel("<html><FONT COLOR=RED><B>Isocount</B></FONT> calculates the total number of structural and stereoisomers for any alkane."
+"<html> It also calculates the number of <FONT COLOR=RED>sterically unreasonable<html></FONT> isomers");
JLabel spiel2 = new JLabel("<html><FONT COLOR=BLUE>(FYI It has been estimated that the universe contains <B>10<sup>80</sup></B> particles!)<FONT>");
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
x.setLayout(gridbag);
x.setBackground(new Color(200,200,255));
c.fill = GridBagConstraints.HORIZONTAL;
JLabel version = new JLabel("<html><p><FONT COLOR=RED> IsoCount version 1.1</FONT></p><p>----------------</p></html>");
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(version, c);
x.add(version);
JLabel instructions1 = new JLabel("<html> Enter the number of carbon atoms: </html>");
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(instructions1, c);
x.add(instructions1);
JLabel instructions2 = new JLabel("<html> Or enter 0 to see the results for the first 200 alkanes...</html>");
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 2;
gridbag.setConstraints(instructions2, c);
x.add(instructions2);
c.gridwidth = 1;
c.gridx = 2;
c.gridy = 1;
gridbag.setConstraints(display1, c);
x.add(display1);
c.gridwidth = 3;
c.ipady = 300;
c.gridx = 0;
c.gridy = 3;
gridbag.setConstraints(scrollPane2, c);
x.add(scrollPane2);
c.ipady = 0;
c.gridx = 0;
c.gridy = 5;
gridbag.setConstraints(clearButton, c);
x.add(clearButton);
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 4;
//c.insets = new Insets(0,10,0,10);
gridbag.setConstraints(calculateButton, c);
x.add(calculateButton);
c.gridwidth = 1;
//c.gridx = 0;
c.gridy = 6;
//c.insets = new Insets(0,10,0,10);
gridbag.setConstraints(sixteenButton, c);
x.add(sixteenButton);
c.gridx = 1;
c.gridy = 6;
//c.insets = new Insets(0,10,0,10);
gridbag.setConstraints(seventeenButton, c);
x.add(seventeenButton);
copyright = new JLabel("<html><p><FONT COLOR=RED> Constructed by R S Paton</FONT></p></html>");
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 7;
gridbag.setConstraints(copyright, c);
x.add(copyright);
calculateButton.addActionListener( new ActionListener()
{ // The "action listener" for the button is defined
// by this nested anonymous class.
public void actionPerformed(ActionEvent evt)
{ // This method is called to respond when the user
// presses the button.
int carbons = Integer.parseInt(display1.getText());
if (whichone==16)
{ if (carbons != 0)
//Main Calculation
{ System.out.println(whichone);
doIsoCount16(carbons);
}
else
//If zero is input do a loop from 2 to 200
{ int n;
for (n= 2; n <= 200; n++)
{ doIsoCount16(n);
}
}
}
if (whichone==17)
{ if (carbons != 0)
//Main Calculation
{ System.out.println(whichone);
doIsoCount17(carbons);
}
else
//If zero is input do a loop from 2 to 200
{ int n;
for (n= 2; n <= 200; n++)
{ doIsoCount17(n);
}
}
}
} // end actionPerformed()
});
display1.addActionListener( new ActionListener()
{ // The "action listener" for the button is defined
// by this nested anonymous class.
public void actionPerformed(ActionEvent evt)
{ // This method is called to respond when the user
// presses the button.
int carbons = Integer.parseInt(display1.getText());
if (whichone==16)
{ if (carbons != 0)
//Main Calculation
{ System.out.println(whichone);
doIsoCount16(carbons);
}
else
//If zero is input do a loop from 2 to 200
{ int n;
for (n= 2; n <= 200; n++)
{ doIsoCount16(n);
}
}
}
if (whichone==17)
{ if (carbons != 0)
//Main Calculation
{ System.out.println(whichone);
doIsoCount17(carbons);
}
else
//If zero is input do a loop from 2 to 200
{ int n;
for (n= 2; n <= 200; n++)
{ doIsoCount17(n);
}
}
}
} // end actionPerformed()
});
clearButton.addActionListener( new ActionListener()
{ // The "action listener" for the button is defined
// by this nested anonymous class.
public void actionPerformed(ActionEvent evt)
{ display2.setText("");
}
});
sixteenButton.addActionListener( new ActionListener()
{ // The "action listener" for the button is defined
// by this nested anonymous class.
public void actionPerformed(ActionEvent evt)
{ System.out.println("whichone: "+16);
whichone=16;
x.setBackground(new Color(200,200,255));
sixteenButton.setBackground(new Color(200,200,255));
seventeenButton.setBackground(new Color(200,200,255));
clearButton.setBackground(new Color(200,200,255));
calculateButton.setBackground(new Color(200,200,255));
}
});
seventeenButton.addActionListener( new ActionListener()
{ // The "action listener" for the button is defined
// by this nested anonymous class.
public void actionPerformed(ActionEvent evt)
{ System.out.println("whichone: "+17);
whichone=17;
x.setBackground(new Color(200,255,200));
sixteenButton.setBackground(new Color(200,255,200));
seventeenButton.setBackground(new Color(200,255,200));
clearButton.setBackground(new Color(200,255,200));
calculateButton.setBackground(new Color(200,255,200));
}
});
JPanel y = new JPanel();
y.setLayout(new BorderLayout());
y.setBackground(Color.white);
getContentPane().setLayout(new BorderLayout());
getContentPane().add("West", x);
getContentPane().add("Center", y);
} // end init()
//Method Choose calculates Binomial Coefficients
private static BigInteger Choose(BigInteger p, BigInteger q)
{ if(p.compareTo(q)<0) return BigInteger.valueOf(0);
BigInteger result = BigInteger.valueOf(1);
BigInteger numerator = BigInteger.valueOf(1);
BigInteger denominator = BigInteger.valueOf(1);
if (p.compareTo(q)==0) return result;
if (q.compareTo(BigInteger.valueOf(0))==0) return result;
if (p.subtract(BigInteger.valueOf(1)).compareTo(q)==0)
{ result=p;
return result;
}
if (q.compareTo(p.subtract(q))>0)
{ for (BigInteger i = p; i.compareTo(q)>0; i=i.subtract(BigInteger.valueOf(1)))
{ numerator = numerator.multiply(i);
}
denominator = Factorial(p.subtract(q));
result = numerator.divide(denominator);
}
else
{ for (BigInteger i = p; i.compareTo(p.subtract(q))>0; i = i.subtract(BigInteger.valueOf(1)))
{ numerator = numerator.multiply(i);
}
denominator = Factorial(q);
result = numerator.divide(denominator);
}
return result;
}
//End Method Choose
//Method Factorial - Obvious!
private static BigInteger Factorial(BigInteger m)
{ BigInteger result = BigInteger.valueOf(1);
if (m.compareTo(BigInteger.valueOf(0))==0) return result;
if (m.compareTo(BigInteger.valueOf(1))==0) return result;
for (BigInteger i = m; m.compareTo(BigInteger.valueOf(1))>0; m=m.subtract(BigInteger.valueOf(1)))
{ result = result.multiply(m);
}
return result;
}
//End Method Factorial
//Isocount Calculation
public void doIsoCount16(int n)
{ System.out.println("Processing for C"+n+"H"+(2*n+2)+"...");
final int halfn;
int a,b,c,d,i;
//NUMBER OF VIRTUAL STRUCTURAL AND STEREOISOMERS
BigInteger structuralisomers, struct1, struct2, struct3, struct4, struct5, struct6;
structuralisomers = struct1 = struct2 = struct3 = struct4 = struct5 = struct6 = BigInteger.valueOf(0);
BigInteger stereoisomers, stereo1, stereo2, stereo3, stereo4, stereo5, stereo6;
stereoisomers = stereo1 = stereo2 = stereo3 = stereo4 = stereo5 = stereo6 = BigInteger.valueOf(0);
//NUMBER OF ISOMERS WITH ALLOWED BRANCHES (ALL CENTROIDS)
BigInteger GoodBstructuralisomers, GoodBstruct1, GoodBstruct2, GoodBstruct3, GoodBstruct4, GoodBstruct5, GoodBstruct6;
GoodBstructuralisomers = GoodBstruct1 = GoodBstruct2 = GoodBstruct3 = GoodBstruct4 = GoodBstruct5 = GoodBstruct6 = BigInteger.valueOf(0);
BigInteger GoodBstereoisomers, GoodBstereo1, GoodBstereo2, GoodBstereo3, GoodBstereo4, GoodBstereo5, GoodBstereo6;
GoodBstereoisomers = GoodBstereo1 = GoodBstereo2 = GoodBstereo3 = GoodBstereo4 = GoodBstereo5 = GoodBstereo6 = BigInteger.valueOf(0);
//NUMBER OF ISOMERS WITH DISALLOWED CENTROIDS (ALLOWED BRANCHES)
BigInteger BadCstructuralisomers, BadCstruct1, BadCstruct2, BadCstruct3, BadCstruct4, BadCstruct5, BadCstruct6;
BadCstructuralisomers = BadCstruct1 = BadCstruct2 = BadCstruct3 = BadCstruct4 = BadCstruct5 = BadCstruct6= BigInteger.valueOf(0);
BigInteger BadCstereoisomers, BadCstereo1, BadCstereo2, BadCstereo3, BadCstereo4, BadCstereo5, BadCstereo6;
BadCstereoisomers = BadCstereo1 = BadCstereo2 = BadCstereo3 = BadCstereo4 = BadCstereo5 = BadCstereo6 = BigInteger.valueOf(0);
//NUMBER OF ALLOWED ISOMERS = DIFFERENCE OF TWO CALCULATED TERMS (GoodB - BadC)
BigInteger Allowedstructuralisomers = BigInteger.valueOf(0);
BigInteger Allowedstereoisomers = BigInteger.valueOf(0);
//R(n) is as defined by Davies & Freyd - J. Chem. Ed., 66, 278, 1989
//T(n) has a tertiary root
//TT(n) has a tertiary root, each of which itself is a tertiary root i.e. tertiary-tertiary
//Rprime(n), Tprime(n) and TTprime(n) are versions of R(n),T(n) and TT(n) for which no disallowed substructures are present.
BigInteger[] Rstruct;
BigInteger[] Rstereo;
BigInteger[] Sstruct;
BigInteger[] Sstereo;
BigInteger[] Trstruct;
BigInteger[] Trstereo;
BigInteger[] TTstruct;
BigInteger[] TTstereo;
BigInteger[] TSstruct;
BigInteger[] TSstereo;
BigInteger[] Rprimestruct;
BigInteger[] Rprimestereo;
BigInteger[] Sprimestruct;
BigInteger[] Sprimestereo;
BigInteger[] Tprimestruct;
BigInteger[] Tprimestereo;
BigInteger[] TTprimestruct;
BigInteger[] TTprimestereo;
BigInteger[] TSprimestruct;
BigInteger[] TSprimestereo;
if (n%2==0)
{ halfn = n/2;
}
else
{ halfn =n/2+1;
}
Rstruct = new BigInteger[halfn+1];
Rstruct[0] = Rstruct[1] = BigInteger.valueOf(1);
Rstereo = new BigInteger[halfn+1];
Rstereo[0] = Rstereo[1] = BigInteger.valueOf(1);
Sstruct = new BigInteger[halfn+1];
Sstruct[0] = Sstruct[1] = BigInteger.valueOf(0);
Sstereo = new BigInteger[halfn+1];
Sstereo[0] = Sstereo[1] = BigInteger.valueOf(0);
Trstruct = new BigInteger[halfn+1];
Trstruct[0] = Trstruct[1] = BigInteger.valueOf(0);
Trstereo = new BigInteger[halfn+1];
Trstereo[0] = Trstereo[1] = BigInteger.valueOf(0);
TTstruct = new BigInteger[halfn+1];
TTstruct[0] = TTstruct[1] = BigInteger.valueOf(0);
TTstereo = new BigInteger[halfn+1];
TTstereo[0] = TTstereo[1] = BigInteger.valueOf(0);
TSstruct = new BigInteger[halfn+1];
TSstruct[0] = TSstruct[1] = BigInteger.valueOf(0);
TSstereo = new BigInteger[halfn+1];
TSstereo[0] = TSstereo[1] = BigInteger.valueOf(0);
Rprimestruct = new BigInteger[halfn+1];
Rprimestruct[0] = Rprimestruct[1] = BigInteger.valueOf(1);
Rprimestereo = new BigInteger[halfn+1];
Rprimestereo[0] = Rprimestereo[1] = BigInteger.valueOf(1);
Sprimestruct = new BigInteger[halfn+1];
Sprimestruct[0] = Sprimestruct[1] = BigInteger.valueOf(0);
Sprimestereo = new BigInteger[halfn+1];
Sprimestereo[0] = Sprimestereo[1] = BigInteger.valueOf(0);
Tprimestruct = new BigInteger[halfn+1];
Tprimestruct[0] = Tprimestruct[1] = BigInteger.valueOf(0);
Tprimestereo = new BigInteger[halfn+1];
Tprimestereo[0] = Tprimestereo[1] = BigInteger.valueOf(0);
TTprimestruct = new BigInteger[halfn+1];
TTprimestruct[0] = TTprimestruct[1] = BigInteger.valueOf(0);
TTprimestereo = new BigInteger[halfn+1];
TTprimestereo[0] = TTprimestereo[1] = BigInteger.valueOf(0);
TSprimestruct = new BigInteger[halfn+1];
TSprimestruct[0] = TSprimestruct[1] = BigInteger.valueOf(0);
TSprimestereo = new BigInteger[halfn+1];
TSprimestereo[0] = TSprimestereo[1] = BigInteger.valueOf(0);
///////////////////////////////////////////////////////////Begin Enumeration with C16 Filtering/////////////////////////////////////////////////
//Calculations of branch isomerism
for (i = 2; i <= halfn; i++)
{ //Calculation of R(i)
Rstruct[i] = BigInteger.valueOf(0);
Rstereo[i] = BigInteger.valueOf(0);
for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ for (a = 0; a < b; a++)
{ if (a + b + c == i - 1)
{ Rstruct[i] = Rstruct[i].add(Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c])));
Rstereo[i] = Rstereo[i].add((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 0; c <= i - 1; c++)
{ for (a = 0; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ Rstruct[i] = Rstruct[i].add(((Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Rstruct[c])));
Rstereo[i] = Rstereo[i].add(((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Rstruct[i] = Rstruct[i].add((Choose(Rstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Rstereo[i] = Rstereo[i].add((Choose(Rstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[b], BigInteger.valueOf(3))));
}
//Calculation of S(i)
Sstruct[i] = BigInteger.valueOf(0);
Sstereo[i] = BigInteger.valueOf(0);
if (i >= 3)
{ for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ if (b + c == i - 1)
{ Sstruct[i] = Sstruct[i].add(Rstruct[b].multiply(Rstruct[c]));
Sstereo[i] = Sstereo[i].add(((Rstereo[b]).multiply(Rstereo[c])).multiply(BigInteger.valueOf(2)));
}
}
}
for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a == (i - 1))
{ Sstruct[i] = Sstruct[i].add((Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
Sstereo[i] = Sstereo[i].add(((Choose((Rstereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rstereo[a]), BigInteger.valueOf(2)))));
}
}
}
//Tr(i)
Trstruct[i] = BigInteger.valueOf(0);
Trstereo[i] = BigInteger.valueOf(0);
if (i >= 4)
{ for (c = 3; c <= i - 1; c++)
{ for (b = 2; b < c; b++)
{ for (a = 1; a < b; a++)
{ if (a + b + c == i - 1)
{ Trstruct[i] = Trstruct[i].add(Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c])));
Trstereo[i] = Trstereo[i].add((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 1; c <= i - 1; c++)
{ for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ Trstruct[i] = Trstruct[i].add(((Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Rstruct[c])));
Trstereo[i] = Trstereo[i].add(((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Trstruct[i] = Trstruct[i].add((Choose(Rstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Trstereo[i] = Trstereo[i].add((Choose(Rstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[b], BigInteger.valueOf(3))));
}
}
//TT(i)
TTstruct[i] = BigInteger.valueOf(0);
TTstereo[i] = BigInteger.valueOf(0);
if (i >= 13)
{ for (c = 6; c <= i - 1; c++)
{ for (b = 5; b < c; b++)
{ for (a = 4; a < b; a++)
{ if (a + b + c == i - 1)
{ TTstruct[i] = TTstruct[i].add(Trstruct[a].multiply(Trstruct[b].multiply(Trstruct[c])));
TTstereo[i] = TTstereo[i].add((Trstereo[a].multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 4; c <= i - 1; c++)
{ for (a = 4; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ TTstruct[i] = TTstruct[i].add(((Choose(Trstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Trstruct[c])));
TTstereo[i] = TTstereo[i].add(((Choose(Trstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Trstereo[a], BigInteger.valueOf(2)))).multiply(Trstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
TTstruct[i] = TTstruct[i].add((Choose(Trstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TTstereo[i] = TTstereo[i].add((Choose(Trstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Trstereo[b], BigInteger.valueOf(3))));
}
}
//TS(i)
TSstruct[i] = BigInteger.valueOf(0);
TSstereo[i] = BigInteger.valueOf(0);
if (i >= 12)
{ for (c = 5; c <= i - 1; c++)
{ for (b = 4; b < c; b++)
{ for (a = 3; a < b; a++)
{ if (a + b + c == i - 1)
{ //a is secondary, b and c are tetiary
TSstruct[i] = TSstruct[i].add((Sstruct[a]).multiply(Trstruct[b].multiply(Trstruct[c])));
TSstereo[i] = TSstereo[i].add(((Sstereo[a]).multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
//b is secondary, a and c are tertiary
TSstruct[i] = TSstruct[i].add((Sstruct[b]).multiply(Trstruct[c].multiply(Trstruct[a])));
TSstereo[i] = TSstereo[i].add(((Sstereo[b]).multiply(Trstereo[c].multiply(Trstereo[a]))).multiply(BigInteger.valueOf(2)));
//c is secondary, b and c are tertiary
TSstruct[i] = TSstruct[i].add((Sstruct[c]).multiply(Trstruct[a].multiply(Trstruct[b])));
TSstereo[i] = TSstereo[i].add(((Sstereo[c]).multiply(Trstereo[a].multiply(Trstereo[b]))).multiply(BigInteger.valueOf(2)));
//All tertiary
TSstruct[i] = TSstruct[i].add((Trstruct[a]).multiply(Trstruct[b].multiply(Trstruct[c])));
TSstereo[i] = TSstereo[i].add(((Trstereo[a]).multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 3; c <= i - 1; c++)
{ for (a = 3; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ //Both a's are tertiary, c is secondary or tertiary
TSstruct[i] = TSstruct[i].add(((Choose(Trstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Sstruct[c].add(Trstruct[c])))));
TSstereo[i] = TSstereo[i].add(((Choose(Trstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Trstereo[a], BigInteger.valueOf(2)))).multiply((Trstereo[c].add(Sstereo[c]))));
//One a is tertiary, the other secondary, c is tertiary
TSstruct[i] = TSstruct[i].add((Sstruct[a]).multiply(Trstruct[a].multiply(Trstruct[c])));
TSstereo[i] = TSstereo[i].add(((Sstereo[a]).multiply(Trstereo[a].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
//All tertiary
TSstruct[i] = TSstruct[i].add((Choose(Trstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TSstereo[i] = TSstereo[i].add((Choose(Trstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Trstereo[b], BigInteger.valueOf(3))));
//One secondary
TSstruct[i] = TSstruct[i].add(((Choose(Trstruct[b].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Sstruct[b]))));
TSstereo[i] = TSstereo[i].add(((Choose(Trstereo[b].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Trstereo[b], BigInteger.valueOf(2)))).multiply((Trstereo[b])));
}
}
//Rprime(i)
if (i >= 15)
{ Rprimestruct[i] = BigInteger.valueOf(0);
Rprimestereo[i] = BigInteger.valueOf(0);
for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ for (a = 0; a < b; a++)
{ //TYPE 1 DISALLOWED
if (a + b + c == i - 1 && a==0)
{ Rprimestruct[i] = Rprimestruct[i].add((Rprimestruct[a].subtract(TTstruct[a])).multiply((Rprimestruct[b].subtract(TTstruct[b])).multiply((Rprimestruct[c].subtract(TTstruct[c])))));
Rprimestereo[i] = Rprimestereo[i].add(((Rprimestruct[a].subtract(TTstereo[a])).multiply((Rprimestereo[b].subtract(TTstereo[b])).multiply((Rprimestereo[c].subtract(TTstereo[c]))))).multiply(BigInteger.valueOf(2)));
}
//TYPE 2 DISALLOWED
if (a + b + c == i - 1 && a!=0)
{ Rprimestruct[i] = Rprimestruct[i].add((Rprimestruct[a].subtract(TSstruct[a])).multiply((Rprimestruct[b].subtract(TSstruct[b])).multiply((Rprimestruct[c].subtract(TSstruct[c])))));
Rprimestereo[i] = Rprimestereo[i].add(((Rprimestereo[a].subtract(TSstereo[a])).multiply((Rprimestereo[b].subtract(TSstereo[b])).multiply((Rprimestereo[c].subtract(TSstereo[c]))))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 0; c <= i - 1; c++)
{ for (a = 0; a <= ((i - 1) / 2); a++)
{ //TYPE 1 DISALLOWED
if (2 * a + c == (i - 1) && a!=c && c==0 && a!=0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a].subtract(TTstruct[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c]))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a].subtract(TTstereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a].subtract(TTstereo[a])), BigInteger.valueOf(2)))).multiply(Rprimestereo[c]));
}
//TYPE 2 DISALLOWED
if (2 * a + c == (i - 1) && a!=c && c!=0 && a!=0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a].subtract(TSstruct[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TSstruct[c])))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a].subtract(TSstereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a].subtract(TSstereo[a])), BigInteger.valueOf(2)))).multiply(Rprimestereo[c].subtract(TSstereo[c])));
}
//REST
if (2 * a + c == (i - 1) && a!=c && a==0 && c!=0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a]).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c]))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a]), BigInteger.valueOf(2)))).multiply((Rprimestereo[c])));
}
}
}
if ((i - 1) % 3 == 0)
{ //TYPE 1 ALLOWED - NO CONTRIBUTION
//TYPE 2 DISALLOWED
b = (i - 1) / 3;
Rprimestruct[i] = Rprimestruct[i].add((Choose((Rprimestruct[b].subtract(TSstruct[b])).add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Rprimestereo[i] = Rprimestereo[i].add((Choose((Rprimestereo[b].subtract(TSstereo[b])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[b].subtract(TSstereo[b])), BigInteger.valueOf(3))));
}
}
else
{ Rprimestruct[i] = Rstruct[i];
Rprimestereo[i] = Rstereo[i];
}
//Sprime(i)
Sprimestruct[i] = BigInteger.valueOf(0);
Sprimestereo[i] = BigInteger.valueOf(0);
if (i >= 3)
{ for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ if (b + c == i - 1)
{ Sprimestruct[i] = Sprimestruct[i].add(Rprimestruct[b].multiply(Rprimestruct[c]));
Sprimestereo[i] = Sprimestereo[i].add(((Rprimestereo[b]).multiply(Rprimestereo[c])).multiply(BigInteger.valueOf(2)));
}
}
}
for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a == (i - 1))
{ Sprimestruct[i] = Sprimestruct[i].add((Choose(Rprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
Sprimestereo[i] = Sprimestereo[i].add(((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a]), BigInteger.valueOf(2)))));
}
}
}
//Calculation of Tprime(i)
if (i >= 16)
{ Tprimestruct[i] = BigInteger.valueOf(0);
Tprimestereo[i] = BigInteger.valueOf(0);
for (c = 3; c <= i - 1; c++)
{ for (b = 2; b < c; b++)
{ for (a = 1; a < b; a++)
{ if (a + b + c == i - 1 && a!=0)
{ Tprimestruct[i] = Tprimestruct[i].add((Rprimestruct[a].subtract(TTprimestruct[a])).multiply((Rprimestruct[b].subtract(TTprimestruct[b])).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Tprimestereo[i] = Tprimestereo[i].add(((Rprimestereo[a].subtract(TTprimestereo[a])).multiply((Rprimestereo[b].subtract(TTprimestereo[b])).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 1; c <= i - 1; c++)
{ for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a!=c && a!=0 && c!=0)
{ Tprimestruct[i] = Tprimestruct[i].add(((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Tprimestereo[i] = Tprimestereo[i].add(((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Tprimestruct[i] = Tprimestruct[i].add((Choose((Rprimestruct[b].subtract(TTprimestruct[b])).add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Tprimestereo[i] = Tprimestereo[i].add((Choose((Rprimestereo[b].subtract(TTprimestereo[b])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[b].subtract(TTprimestereo[b])), BigInteger.valueOf(3))));
}
}
else
{ Tprimestruct[i] = Trstruct[i];
Tprimestereo[i] = Trstereo[i];
}
//TTprime(i)
TTprimestruct[i] = BigInteger.valueOf(0);
TTprimestereo[i] = BigInteger.valueOf(0);
if (i >= 13)
{ for (c = 6; c <= i - 1; c++)
{ for (b = 5; b < c; b++)
{ for (a = 4; a < b; a++)
{ if (a + b + c == i - 1)
{ TTprimestruct[i] = TTprimestruct[i].add(Tprimestruct[a].multiply(Tprimestruct[b].multiply(Tprimestruct[c])));
TTprimestereo[i] = TTprimestereo[i].add((Tprimestereo[a].multiply(Tprimestereo[b].multiply(Tprimestereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 4; c <= i - 1; c++)
{ for (a = 4; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ TTprimestruct[i] = TTprimestruct[i].add(((Choose(Tprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Tprimestruct[c])));
TTprimestereo[i] = TTprimestereo[i].add(((Choose(Tprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Tprimestereo[a], BigInteger.valueOf(2)))).multiply(Tprimestereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
TTprimestruct[i] = TTprimestruct[i].add((Choose(Tprimestruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TTprimestereo[i] = TTprimestereo[i].add((Choose(Tprimestereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Tprimestereo[b], BigInteger.valueOf(3))));
}
}
//TSprime(i)
TSprimestruct[i] = BigInteger.valueOf(0);
TSprimestereo[i] = BigInteger.valueOf(0);
if (i >= 12)
{ for (c = 5; c <= i - 1; c++)
{ for (b = 4; b < c; b++)
{ for (a = 3; a < b; a++)
{ if (a + b + c == i - 1)
{ //a is secondary, b and c are tetiary
TSprimestruct[i] = TSprimestruct[i].add((Sstruct[a]).multiply(Trstruct[b].multiply(Trstruct[c])));
TSprimestereo[i] = TSprimestereo[i].add(((Sstereo[a]).multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
//b is secondary, a and c are tertiary
TSprimestruct[i] = TSprimestruct[i].add((Sstruct[b]).multiply(Trstruct[c].multiply(Trstruct[a])));
TSprimestereo[i] = TSprimestereo[i].add(((Sstereo[b]).multiply(Trstereo[c].multiply(Trstereo[a]))).multiply(BigInteger.valueOf(2)));
//c is secondary, b and c are tertiary
TSprimestruct[i] = TSprimestruct[i].add((Sstruct[c]).multiply(Trstruct[a].multiply(Trstruct[b])));
TSprimestereo[i] = TSprimestereo[i].add(((Sstereo[c]).multiply(Trstereo[a].multiply(Trstereo[b]))).multiply(BigInteger.valueOf(2)));
//All tertiary
TSprimestruct[i] = TSprimestruct[i].add((Trstruct[a]).multiply(Trstruct[b].multiply(Trstruct[c])));
TSprimestereo[i] = TSprimestereo[i].add(((Trstereo[a]).multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 3; c <= i - 1; c++)
{ for (a = 3; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ //Both a's are tertiary, c is secondary or tertiary
TSprimestruct[i] = TSprimestruct[i].add(((Choose(Tprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Sprimestruct[c].add(Tprimestruct[c])))));
TSprimestereo[i] = TSprimestereo[i].add(((Choose(Tprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Tprimestereo[a], BigInteger.valueOf(2)))).multiply((Tprimestereo[c].add(Sprimestereo[c]))));
//One a is tertiary, the other secondary, c is tertiary
TSprimestruct[i] = TSprimestruct[i].add((Sprimestruct[a]).multiply(Tprimestruct[a].multiply(Tprimestruct[c])));
TSprimestereo[i] = TSprimestereo[i].add(((Sprimestereo[a]).multiply(Tprimestereo[a].multiply(Tprimestereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
//All tertiary
TSprimestruct[i] = TSprimestruct[i].add((Choose(Tprimestruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TSprimestereo[i] = TSprimestereo[i].add((Choose(Tprimestereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Tprimestereo[b], BigInteger.valueOf(3))));
//One secondary
TSprimestruct[i] = TSprimestruct[i].add(((Choose(Tprimestruct[b].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Sprimestruct[b]))));
TSprimestereo[i] = TSprimestereo[i].add(((Choose(Tprimestereo[b].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Tprimestereo[b], BigInteger.valueOf(2)))).multiply((Tprimestereo[b])));
}
}
}
//CALCULATION OF T(n) - VIRTUAL ISOMERS
//CALCULATION OF GOODB(n) - ISOMERS WHICH USE ALLOWED BRANCHES
//TERM 1 - CENTROID EDGE
//n even
if(n%2==0)
{ a = n/2;
struct1=Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
stereo1=Choose(Rstereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
GoodBstruct1=Choose(Rprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
GoodBstereo1=Choose(Rprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
}
else
//n odd
{ struct1=BigInteger.valueOf(0);
stereo1=BigInteger.valueOf(0);
GoodBstruct1=BigInteger.valueOf(0);
GoodBstereo1=BigInteger.valueOf(0);
}
//TERM 2 - ALL BRANCHES DIFFERENT SIZE
for (d=3; d<halfn; d++)
{ for (c=2; c<d; c++)
{ for (b=1; b<c; b++)
{ for(a=0; a<b; a++)
{ if (a+b+c+d==n-1)
{ struct2=struct2.add((Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c].multiply(Rstruct[d])))));
stereo2=stereo2.add(BigInteger.valueOf(2).multiply((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c].multiply(Rstereo[d]))))));
GoodBstruct2=GoodBstruct2.add((Rprimestruct[a].multiply(Rprimestruct[b].multiply(Rprimestruct[c].multiply(Rprimestruct[d])))));
GoodBstereo2=GoodBstereo2.add(BigInteger.valueOf(2).multiply((Rprimestereo[a].multiply(Rprimestereo[b].multiply(Rprimestereo[c].multiply(Rprimestereo[d]))))));
}
}
}
}
}
//TERM 3 - A PAIR
for (d=1; d<halfn; d++)
{ for (c=0; c<d; c++)
{ for (a=0; a<n/2; a++)
{ if (2*a+c+d==n-1&&a!=c&&a!=d)
{ struct3=struct3.add((Choose(Rstruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rstruct[c].multiply(Rstruct[d])));
stereo3=stereo3.add((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c].multiply(Rstereo[d])));
GoodBstruct3=GoodBstruct3.add((Choose(Rprimestruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rprimestruct[c].multiply(Rprimestruct[d])));
GoodBstereo3=GoodBstereo3.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rprimestereo[a], BigInteger.valueOf(2)))).multiply(Rprimestereo[c].multiply(Rprimestereo[d])));
}
}
}
}
//TERM 4 - 2 PAIRS
//n odd
if(((n-1)%2)==0)
{ for (c=1; c<=halfn; c++)
{ for(a=0; a<c; a++)
{ if (2*a+2*c==n-1)
{ struct4=struct4.add(Choose((Rstruct[a].multiply(Rstruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
stereo4=stereo4.add((Choose(Rstereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose(Rstereo[c].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
GoodBstruct4=GoodBstruct4.add(Choose((Rprimestruct[a].multiply(Rprimestruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
GoodBstereo4=GoodBstereo4.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose(Rprimestereo[c].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
}
}
}
//n even
else
{ struct4=BigInteger.valueOf(0);
stereo4=BigInteger.valueOf(0);
GoodBstruct4=BigInteger.valueOf(0);
GoodBstereo4=BigInteger.valueOf(0);
}
//TERM 5 - 3 OF A KIND
for (d=0; d<halfn; d++)
{ for (a=0; a<halfn; a++)
{ if (3*a+d==n-1&&a!=d)
{ struct5=struct5.add(((Choose(Rstruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rstruct[d]));
stereo5=stereo5.add(((Choose(Rstereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[a], BigInteger.valueOf(3)))).multiply(Rstereo[d]));
GoodBstruct5=GoodBstruct5.add(((Choose(Rprimestruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d]));
GoodBstereo5=GoodBstereo5.add(((Choose(Rprimestereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rprimestereo[a], BigInteger.valueOf(3)))).multiply(Rprimestereo[d]));
}
}
}
//TERM 6 - ALL SAME SIZE
//only possible if n-1 is divisible by four
if (((n-1)%4)==0)
{ a=(n-1)/4;
struct6=(Choose(Rstruct[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
stereo6=(Choose(Rstereo[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose(Rstereo[a],BigInteger.valueOf(4))));
GoodBstruct6=(Choose(Rprimestruct[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
GoodBstereo6=(Choose(Rprimestereo[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose(Rprimestereo[a],BigInteger.valueOf(4))));
}
else
{ struct6=BigInteger.valueOf(0);
stereo6=BigInteger.valueOf(0);
GoodBstruct6=BigInteger.valueOf(0);
GoodBstereo6=BigInteger.valueOf(0);
}
//CALCULATION OF BADC(n) - STRUCTURES DISALLOWED DUE TO BAD CENTROIDS
if (n>=16)
{ //FIRST TERM - CENTROID EDGE
if(n%2==0)
{ if (n>=32)
{ a=n/2;
//A1:
//EITHER BOTH BRANCHES ARE TS
BadCstruct1=Choose(TSprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
BadCstereo1=Choose(TSprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
//OR ONE IS TERTIARY(BUT NOT TS) THE OTHER TS
BadCstruct1=BadCstruct1.add(TSprimestruct[a].multiply(Tprimestruct[a].subtract(TSprimestruct[a])));
BadCstereo1=BadCstereo1.add(TSprimestereo[a].multiply(Tprimestereo[a].subtract(TSprimestereo[a])));
//A4:
//ONE BRANCH IS TT THE OTHER SECONDARY
BadCstruct1=BadCstruct1.add(TTprimestruct[a].multiply(Sprimestruct[a]));
BadCstereo1=BadCstereo1.add(TTprimestereo[a].multiply(Sprimestereo[a]));
}
}
else
//n odd
{ BadCstruct1=BigInteger.valueOf(0);
BadCstereo1=BigInteger.valueOf(0);
}
//TERM 2 - ALL BRANCHES DIFFERENT SIZE
for (d=3; d<halfn; d++)
{ for (c=2; c<d; c++)
{ for (b=1; b<c; b++)
{ for(a=0; a<b; a++)
{ if (a+b+c+d==n-1)
{ if (a>=3)
{ //THREE TERTIARY ONE SECONDARY BRANCH, NO TS
BadCstruct2 = BadCstruct2.add(((Tprimestruct[a].subtract(TSprimestruct[a])).multiply((Tprimestruct[b].subtract(TSprimestruct[b])).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply(Sprimestruct[d])))));
BadCstruct2 = BadCstruct2.add(((Tprimestruct[a].subtract(TSprimestruct[a])).multiply((Tprimestruct[b].subtract(TSprimestruct[b])).multiply(Sprimestruct[c].multiply((Tprimestruct[d].subtract(TSprimestruct[d])))))));
BadCstruct2 = BadCstruct2.add(((Tprimestruct[a].subtract(TSprimestruct[a])).multiply(Sprimestruct[b].multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply((Tprimestruct[d].subtract(TSprimestruct[d])))))));
BadCstruct2 = BadCstruct2.add((Sprimestruct[a].multiply((Tprimestruct[b].subtract(TSprimestruct[b])).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply((Tprimestruct[d].subtract(TSprimestruct[d])))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Tprimestereo[a].subtract(TSprimestereo[a])).multiply((Tprimestereo[b].subtract(TSprimestereo[b])).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply(Sprimestereo[d]))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Tprimestereo[a].subtract(TSprimestereo[a])).multiply((Tprimestereo[b].subtract(TSprimestereo[b])).multiply(Sprimestereo[c].multiply((Tprimestereo[d].subtract(TSprimestereo[d]))))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Tprimestereo[a].subtract(TSprimestereo[a])).multiply(Sprimestereo[b].multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply((Tprimestereo[d].subtract(TSprimestereo[d]))))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply((Sprimestereo[a].multiply((Tprimestereo[b].subtract(TSprimestereo[b])).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply((Tprimestereo[d].subtract(TSprimestereo[d]))))))));
//ALL TERTIARY
BadCstruct2 = BadCstruct2.add(((Tprimestruct[a].subtract(TSprimestruct[a])).multiply((Tprimestruct[b].subtract(TSprimestruct[b])).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply((Tprimestruct[d].subtract(TSprimestruct[d])))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Tprimestereo[a].subtract(TSprimestereo[a])).multiply((Tprimestereo[b].subtract(TSprimestereo[b])).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply((Tprimestereo[d].subtract(TSprimestereo[d]))))))));
}
if (a>=1)
{ //THREE NON ZERO AT LEAST ONE TS
BadCstruct2 = BadCstruct2.add((Rprimestruct[a].multiply(Rprimestruct[b].multiply(Rprimestruct[c].multiply(Rprimestruct[d])))));
BadCstruct2 = BadCstruct2.subtract(((Rprimestruct[a].subtract(TSprimestruct[a])).multiply((Rprimestruct[b].subtract(TSprimestruct[b])).multiply((Rprimestruct[c].subtract(TSprimestruct[c])).multiply((Rprimestruct[d].subtract(TSprimestruct[d])))))));
BadCstereo2 = BadCstereo2.add((Rprimestereo[a].multiply(Rprimestereo[b].multiply(Rprimestereo[c].multiply(Rprimestereo[d])))));
BadCstereo2 = BadCstereo2.subtract(((Rprimestereo[a].subtract(TSprimestereo[a])).multiply((Rprimestereo[b].subtract(TSprimestereo[b])).multiply((Rprimestereo[c].subtract(TSprimestereo[c])).multiply((Rprimestereo[d].subtract(TSprimestereo[d])))))));
}
if(a==0)
{ //ONE ZERO BRANCH, AT LEAST ONE TT
BadCstruct2 = BadCstruct2.add((Rprimestruct[a].multiply(Rprimestruct[b].multiply(Rprimestruct[c].multiply(Rprimestruct[d])))));
BadCstruct2 = BadCstruct2.subtract(((Rprimestruct[a].subtract(TTprimestruct[a])).multiply((Rprimestruct[b].subtract(TTprimestruct[b])).multiply((Rprimestruct[c].subtract(TTprimestruct[c])).multiply((Rprimestruct[d].subtract(TTprimestruct[d])))))));
BadCstereo2 = BadCstereo2.add((Rprimestereo[a].multiply(Rprimestereo[b].multiply(Rprimestereo[c].multiply(Rprimestereo[d])))));
BadCstereo2 = BadCstereo2.subtract(((Rprimestereo[a].subtract(TTprimestereo[a])).multiply((Rprimestereo[b].subtract(TTprimestereo[b])).multiply((Rprimestereo[c].subtract(TTprimestereo[c])).multiply((Rprimestereo[d].subtract(TTprimestereo[d])))))));
}
}
}
}
}
}
//TERM 3 - A PAIR
for (d=1; d<halfn; d++)
{ for (c=0; c<d; c++)
{ for (a=0; a<n/2; a++)
{ if (2*a+c+d==n-1&&a!=c&&a!=d)
{ if (a>=4 && c>=3)
{ //THREE TERTIARY ONE SECONDARY BRANCH, NO TS
BadCstruct3 = BadCstruct3.add((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply(Sprimestruct[d])));
BadCstruct3 = BadCstruct3.add((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Sprimestruct[c].multiply((Tprimestruct[d].subtract(TSprimestruct[d])))));
BadCstruct3 = BadCstruct3.add(((Sprimestruct[a].multiply((Tprimestruct[a].subtract(TSprimestruct[a])).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply((Tprimestruct[d].subtract(TSprimestruct[d]))))))));
BadCstereo3 = BadCstereo3.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply(Sprimestereo[d])));
BadCstereo3 = BadCstereo3.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply(Sprimestereo[c].multiply((Tprimestereo[d].subtract(TSprimestereo[d])))));
BadCstereo3 = BadCstereo3.add(BigInteger.valueOf(2).multiply((Sprimestereo[a].multiply((Tprimestereo[a].subtract(TSprimestereo[a])).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply((Tprimestereo[d].subtract(TSprimestereo[d]))))))));
//ALL TERTIARY
BadCstruct3 = BadCstruct3.add((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply((Tprimestruct[d].subtract(TSprimestruct[d])))));
BadCstereo3 = BadCstereo3.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply((Tprimestereo[d].subtract(TSprimestereo[d])))));
}
if (a>=1 && c>=1)
{ //THREE NON ZERO AT LEAST ONE TS
BadCstruct3 = BadCstruct3.add((Choose(Rprimestruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rprimestruct[c].multiply(Rprimestruct[d])));
BadCstereo3 = BadCstereo3.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rprimestereo[a], BigInteger.valueOf(2)))).multiply(Rprimestereo[c].multiply(Rprimestereo[d])));
BadCstruct3 = BadCstruct3.subtract((Choose((Rprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TSprimestruct[c])).multiply((Rprimestruct[d].subtract(TSprimestruct[d])))));
BadCstereo3 = BadCstereo3.subtract((Choose((Rprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Rprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TSprimestereo[c])).multiply((Rprimestereo[d].subtract(TSprimestereo[d])))));
}
if(c==0 && a>=1)
{ //ONE ZERO BRANCH, AT LEAST ONE TT
BadCstruct3 = BadCstruct3.add((Choose(Rprimestruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rprimestruct[c].multiply(Rprimestruct[d])));
BadCstereo3 = BadCstereo3.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rprimestereo[a], BigInteger.valueOf(2)))).multiply(Rprimestereo[c].multiply(Rprimestereo[d])));
BadCstruct3 = BadCstruct3.subtract((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TTprimestruct[c])).multiply((Rprimestruct[d].subtract(TTprimestruct[d])))));
BadCstereo3 = BadCstereo3.subtract((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TTprimestereo[c])).multiply((Rprimestereo[d].subtract(TTprimestereo[d])))));
}
}
}
}
}
//TERM 4 - TWO PAIRS
if(((n-1)%2)==0)
{ for (c=1; c<=halfn; c++)
{ for(a=0; a<c; a++)
{ if (2*a+2*c==n-1)
{ if (a>=3)
{ //THREE TERTIARY ONE SECONDARY BRANCH, NO TS
BadCstruct4 = BadCstruct4.add((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Tprimestruct[c].subtract(TSprimestruct[c])).multiply(Sprimestruct[c])));
BadCstruct4 = BadCstruct4.add((Choose((Tprimestruct[c].subtract(TSprimestruct[c])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Tprimestruct[a].subtract(TSprimestruct[a])).multiply(Sprimestruct[a])));
BadCstereo4 = BadCstereo4.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply((Tprimestereo[c].subtract(TSprimestereo[c])).multiply(Sprimestereo[c])));
BadCstereo4 = BadCstereo4.add((Choose((Tprimestereo[c].subtract(TSprimestereo[c])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[c].subtract(TSprimestereo[c])), BigInteger.valueOf(2)))).multiply((Tprimestereo[a].subtract(TSprimestereo[a])).multiply(Sprimestereo[a])));
//ALL TERTIARY
BadCstruct4 = BadCstruct4.add(Choose(((Tprimestruct[a].subtract(TSprimestruct[a])).multiply((Tprimestruct[c].subtract(TSprimestruct[c])))).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose((Tprimestereo[c].subtract(TSprimestereo[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
if (a>=1)
{ //THREE NON ZERO AT LEAST ONE TS
BadCstruct4 = BadCstruct4.add(Choose((Rprimestruct[a].multiply(Rprimestruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose(Rprimestereo[c].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
BadCstruct4 = BadCstruct4.subtract(Choose(((Rprimestruct[a].subtract(TSprimestruct[a])).multiply((Rprimestruct[c].subtract(TSprimestruct[c])))).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.subtract((Choose((Rprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose((Rprimestereo[c].subtract(TSprimestereo[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
}
}
}
}
else
{ BadCstruct4=BigInteger.valueOf(0);
BadCstereo4=BigInteger.valueOf(0);
}
//TERM 5 - THREE OF A KIND
for (d=0; d<halfn; d++)
{ for (a=0; a<halfn; a++)
{ if (3*a+d==(n-1) && a!=d)
{ if (a>=3 && d>=3)
{ //THREE TERTIARY ONE SECONDARY BRANCH, NO TS
BadCstruct5 = BadCstruct5.add(((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Sprimestruct[d]));
BadCstruct5 = BadCstruct5.add((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Sprimestruct[a].multiply((Tprimestruct[d].subtract(TSprimestruct[d])))));
BadCstereo5 = BadCstereo5.add(((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(3)))).multiply(Sprimestereo[d]));
BadCstereo5 = BadCstereo5.add((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(2)))).multiply(Sprimestereo[a].multiply((Tprimestereo[d].subtract(TSprimestereo[d])))));
//ALL TERTIARY
BadCstruct5 = BadCstruct5.add(((Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply((Tprimestruct[d].subtract(TSprimestruct[d]))));
BadCstereo5 = BadCstereo5.add(((Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(3)))).multiply((Tprimestereo[d].subtract(TSprimestereo[d]))));
}
if (a>=1 && d>=1)
{ //THREE NON ZERO AT LEAST ONE TS
BadCstruct5 = BadCstruct5.add(((Choose(Rprimestruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d]));
BadCstereo5 = BadCstereo5.add(((Choose(Rprimestereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rprimestereo[a], BigInteger.valueOf(3)))).multiply(Rprimestereo[d]));
BadCstruct5 = BadCstruct5.subtract(((Choose((Rprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply((Rprimestruct[d].subtract(TSprimestruct[d]))));
BadCstereo5 = BadCstereo5.subtract(((Choose((Rprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(3)))).multiply((Rprimestereo[d].subtract(TSprimestereo[d]))));
}
if(d==0 && a>=1)
{ //ONE ZERO BRANCH, AT LEAST ONE TT
BadCstruct5 = BadCstruct5.add(((Choose(Rprimestruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d]));
BadCstereo5 = BadCstereo5.add(((Choose(Rprimestereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rprimestereo[a], BigInteger.valueOf(3)))).multiply(Rprimestereo[d]));
BadCstruct5 = BadCstruct5.subtract(((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply((Rprimestruct[d].subtract(TTprimestruct[d]))));
BadCstereo5 = BadCstereo5.subtract(((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(3)))).multiply((Rprimestereo[d].subtract(TTprimestereo[d]))));
}
}
}
}
//TERM 6 - ALL BRANCHES SAME SIZE
if (((n-1)%4)==0)
{ a=(n-1)/4;
if (a>=4)
{ //THREE TERTIARY ONE SECONDARY BRANCH, NO TS
BadCstruct6 = BadCstruct6.add(Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)).multiply(Sprimestruct[a]));
BadCstereo6 = BadCstereo6.add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])), BigInteger.valueOf(3))).multiply(Sprimestereo[a]));
//ALL TERTIARY
BadCstruct6 = BadCstruct6.add(Choose((Tprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 = BadCstereo6.add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose((Tprimestereo[a].subtract(TSprimestereo[a])),BigInteger.valueOf(4))));
}
if (a>=1)
{ //THREE NON ZERO AT LEAST ONE TS
BadCstruct6 = BadCstruct6.add(Choose(Rprimestruct[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 = BadCstereo6.add(Choose(Rprimestereo[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose(Rprimestereo[a],BigInteger.valueOf(4))));
BadCstruct6 = BadCstruct6.subtract(Choose((Rprimestruct[a].subtract(TSprimestruct[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 = BadCstereo6.subtract(Choose((Rprimestereo[a].subtract(TSprimestereo[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose((Rprimestereo[a].subtract(TSprimestereo[a])),BigInteger.valueOf(4))));
}
}
else
{ BadCstruct6=BigInteger.valueOf(0);
BadCstereo6=BigInteger.valueOf(0);
}
}
else
{ BadCstruct1=BadCstruct2=BadCstruct3=BadCstruct4=BadCstruct5=BadCstruct6=BigInteger.valueOf(0);
BadCstereo1=BadCstereo2=BadCstereo3=BadCstereo4=BadCstereo5=BadCstereo6=BigInteger.valueOf(0);
}
//SUMMATION OF INDIVIDUAL TERMS
//VIRTUAL ISOMERS
structuralisomers = struct1.add(struct2.add(struct3.add(struct4.add(struct5.add(struct6)))));
stereoisomers = stereo1.add(stereo2.add(stereo3.add(stereo4.add(stereo5.add(stereo6)))));
//ISOMERS WITH ALLOWED BRANCHES
GoodBstructuralisomers = GoodBstruct1.add(GoodBstruct2.add(GoodBstruct3.add(GoodBstruct4.add(GoodBstruct5.add(GoodBstruct6)))));
GoodBstereoisomers = GoodBstereo1.add(GoodBstereo2.add(GoodBstereo3.add(GoodBstereo4.add(GoodBstereo5.add(GoodBstereo6)))));
//ISOMERS WITH DISALLOWED CENTROIDS (ALLOWED BRANCHES)
BadCstructuralisomers = BadCstruct1.add(BadCstruct2.add(BadCstruct3.add(BadCstruct4.add(BadCstruct5.add(BadCstruct6)))));
BadCstereoisomers = BadCstereo1.add(BadCstereo2.add(BadCstereo3.add(BadCstereo4.add(BadCstereo5.add(BadCstereo6)))));
//ALLOWED ISOMERS
Allowedstructuralisomers = GoodBstructuralisomers.subtract(BadCstructuralisomers);
Allowedstereoisomers = GoodBstereoisomers.subtract(BadCstereoisomers);
//////////////////////////////////////////////////////////End of Enumeration/////////////////////////////////////////////////
//TEXT OUTPUT IN GUI
double decimal = 0.0;
double nextdigit = 0.0;
String temp = "";
int ndigits = 0;
display2.append("C"+n+"H"+(2*n+2)+newline);
display2.append("--------------------------------------"+newline);
display2.append(structuralisomers+" ");
temp = structuralisomers.toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("possible structural isomers, EXCLUDING optical isomers "+newline);
display2.append(structuralisomers.subtract(Allowedstructuralisomers)+" ");
temp = (structuralisomers.subtract(Allowedstructuralisomers)).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("of these are sterically unfavourable"+newline);
display2.append("Leaving "+Allowedstructuralisomers+" ");
temp = (Allowedstructuralisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append(" allowed structural isomers"+newline);
display2.append("--------------------------------------"+newline);
display2.append(stereoisomers+" ");
temp = (stereoisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("possible structural isomers, INCLUDING optical isomers "+newline);
display2.append(stereoisomers.subtract(Allowedstereoisomers)+" ");
temp = (stereoisomers.subtract(Allowedstereoisomers)).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("of these are sterically unfavourable"+newline);
display2.append("Leaving "+Allowedstereoisomers+" ");
temp = (Allowedstereoisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append(" allowed structural isomers"+newline);
display2.append("//////////////////////////////////////"+newline);
display2.setCaretPosition(display2.getDocument().getLength());
}
//End Isocount Calculation
//Isocount Calculation
public void doIsoCount17(int n)
{ System.out.println("Processing for C"+n+"H"+(2*n+2)+"...");
final int halfn;
int a,b,c,d,i;
//NUMBER OF THEORETICALLY POSSIBLE STRUCTURAL- AND STEREOISOMERS
BigInteger structuralisomers, struct1, struct2, struct3, struct4, struct5, struct6;
structuralisomers = struct1 = struct2 = struct3 = struct4 = struct5 = struct6 = BigInteger.valueOf(0);
BigInteger stereoisomers, stereo1, stereo2, stereo3, stereo4, stereo5, stereo6;
stereoisomers = stereo1 = stereo2 = stereo3 = stereo4 = stereo5 = stereo6 = BigInteger.valueOf(0);
//NUMBER OF ISOMERS WITH ALLOWED BRANCHES (ALL CENTROIDS)
BigInteger GoodBstructuralisomers, GoodBstruct1, GoodBstruct2, GoodBstruct3, GoodBstruct4, GoodBstruct5, GoodBstruct6;
GoodBstructuralisomers = GoodBstruct1 = GoodBstruct2 = GoodBstruct3 = GoodBstruct4 = GoodBstruct5 = GoodBstruct6 = BigInteger.valueOf(0);
BigInteger GoodBstereoisomers, GoodBstereo1, GoodBstereo2, GoodBstereo3, GoodBstereo4, GoodBstereo5, GoodBstereo6;
GoodBstereoisomers = GoodBstereo1 = GoodBstereo2 = GoodBstereo3 = GoodBstereo4 = GoodBstereo5 = GoodBstereo6 = BigInteger.valueOf(0);
//NUMBER OF ISOMERS WITH DISALLOWED CENTROIDS (ALLOWED BRANCHES)
BigInteger BadCstructuralisomers, BadCstruct1, BadCstruct2, BadCstruct3, BadCstruct4, BadCstruct5, BadCstruct6;
BadCstructuralisomers = BadCstruct1 = BadCstruct2 = BadCstruct3 = BadCstruct4 = BadCstruct5 = BadCstruct6= BigInteger.valueOf(0);
BigInteger BadCstereoisomers, BadCstereo1, BadCstereo2, BadCstereo3, BadCstereo4, BadCstereo5, BadCstereo6;
BadCstereoisomers = BadCstereo1 = BadCstereo2 = BadCstereo3 = BadCstereo4 = BadCstereo5 = BadCstereo6 = BigInteger.valueOf(0);
//NUMBER OF ALLOWED ISOMERS = DIFFERENCE OF TWO CALCULATED TERMS (GoodB - BadC)
BigInteger Allowedstructuralisomers = BigInteger.valueOf(0);
BigInteger Allowedstereoisomers = BigInteger.valueOf(0);
//Temporary terms used in summation
BigInteger structterm1, structterm2, structterm3, structterm4, structterm5, structterm6;
structterm1 = structterm2 = structterm3 = structterm4 = structterm5 = structterm6 = BigInteger.valueOf(0);
BigInteger stereoterm1, stereoterm2, stereoterm3, stereoterm4, stereoterm5, stereoterm6;
stereoterm1 = stereoterm2 = stereoterm3 = stereoterm4 = stereoterm5 = stereoterm6 = BigInteger.valueOf(0);
//R(n) is as defined by Davies & Freyd - J. Chem. Ed., 66, 278, 1989
//T(n) has a tertiary root
//TT(n) has a tertiary root, each of which itself is a tertiary root i.e. tertiary-tertiary
//Rprime(n), Tprime(n) and TTprime(n) are versions of R(n),T(n) and TT(n) for which no disallowed substructures are present.
BigInteger[] Rstruct;
BigInteger[] Rstereo;
BigInteger[] Trstruct;
BigInteger[] Trstereo;
BigInteger[] TTstruct;
BigInteger[] TTstereo;
BigInteger[] Rprimestruct;
BigInteger[] Rprimestereo;
BigInteger[] Tprimestruct;
BigInteger[] Tprimestereo;
BigInteger[] TTprimestruct;
BigInteger[] TTprimestereo;
if (n%2==0)
{ halfn = n/2;
}
else
{ halfn =n/2+1;
}
Rstruct = new BigInteger[halfn+1];
Rstruct[0] = Rstruct[1] = BigInteger.valueOf(1);
Rstereo = new BigInteger[halfn+1];
Rstereo[0] = Rstereo[1] = BigInteger.valueOf(1);
Trstruct = new BigInteger[halfn+1];
Trstruct[0] = Trstruct[1] = BigInteger.valueOf(0);
Trstereo = new BigInteger[halfn+1];
Trstereo[0] = Trstereo[1] = BigInteger.valueOf(0);
TTstruct = new BigInteger[halfn+1];
TTstruct[0] = TTstruct[1] = BigInteger.valueOf(0);
TTstereo = new BigInteger[halfn+1];
TTstereo[0] = TTstereo[1] = BigInteger.valueOf(0);
Rprimestruct = new BigInteger[halfn+1];
Rprimestruct[0] = Rprimestruct[1] = BigInteger.valueOf(1);
Rprimestereo = new BigInteger[halfn+1];
Rprimestereo[0] = Rprimestereo[1] = BigInteger.valueOf(1);
Tprimestruct = new BigInteger[halfn+1];
Tprimestruct[0] = Tprimestruct[1] = BigInteger.valueOf(0);
Tprimestereo = new BigInteger[halfn+1];
Tprimestereo[0] = Tprimestereo[1] = BigInteger.valueOf(0);
TTprimestruct = new BigInteger[halfn+1];
TTprimestruct[0] = TTprimestruct[1] = BigInteger.valueOf(0);
TTprimestereo = new BigInteger[halfn+1];
TTprimestereo[0] = TTprimestereo[1] = BigInteger.valueOf(0);
///////////////////////////////////////////////////////////Begin Enumeration with C17 Filtering/////////////////////////////////////////////////
for (i = 2; i <= halfn; i++)
{ //Calculation of R(i)
for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ for (a = 0; a < b; a++)
{ if (a + b + c == i - 1)
{ Rstruct[i] = Rstruct[i].add(Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c])));
Rstereo[i] = Rstereo[i].add((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 0; c <= i - 1; c++)
{ for (a = 0; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ Rstruct[i] = Rstruct[i].add(((Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Rstruct[c])));
Rstereo[i] = Rstereo[i].add(((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Rstruct[i] = Rstruct[i].add((Choose(Rstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Rstereo[i] = Rstereo[i].add((Choose(Rstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[b], BigInteger.valueOf(3))));
}
//Calculation of T(i)
Trstruct[i] = BigInteger.valueOf(0);
Trstereo[i] = BigInteger.valueOf(0);
if (i >= 4)
{ for (c = 3; c <= i - 1; c++)
{ for (b = 2; b < c; b++)
{ for (a = 1; a < b; a++)
{ if (a + b + c == i - 1)
{ Trstruct[i] = Trstruct[i].add(Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c])));
Trstereo[i] = Trstereo[i].add((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 1; c <= i - 1; c++)
{ for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ Trstruct[i] = Trstruct[i].add(((Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Rstruct[c])));
Trstereo[i] = Trstereo[i].add(((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Trstruct[i] = Trstruct[i].add((Choose(Rstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Trstereo[i] = Trstereo[i].add((Choose(Rstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[b], BigInteger.valueOf(3))));
}
}
//Calculation of TT(i)
TTstruct[i] = BigInteger.valueOf(0);
TTstereo[i] = BigInteger.valueOf(0);
if (i >= 13)
{ for (c = 6; c <= i - 1; c++)
{ for (b = 5; b < c; b++)
{ for (a = 4; a < b; a++)
{ if (a + b + c == i - 1)
{ TTstruct[i] = TTstruct[i].add(Trstruct[a].multiply(Trstruct[b].multiply(Trstruct[c])));
TTstereo[i] = TTstereo[i].add((Trstereo[a].multiply(Trstereo[b].multiply(Trstereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 4; c <= i - 1; c++)
{ for (a = 4; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ TTstruct[i] = TTstruct[i].add(((Choose(Trstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Trstruct[c])));
TTstereo[i] = TTstereo[i].add(((Choose(Trstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Trstereo[a], BigInteger.valueOf(2)))).multiply(Trstereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
TTstruct[i] = TTstruct[i].add((Choose(Trstruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TTstereo[i] = TTstereo[i].add((Choose(Trstereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Trstereo[b], BigInteger.valueOf(3))));
}
}
//Calculation of Rprime(i)
//Ensure it is both allowed at the root, and canonical roots themselves are allowed
if (i >= 16)
{ Rprimestruct[i] = BigInteger.valueOf(0);
Rprimestereo[i] = BigInteger.valueOf(0);
for (c = 2; c <= i - 1; c++)
{ for (b = 1; b < c; b++)
{ for (a = 0; a < b; a++)
{ if (a + b + c == i - 1 && a!=0)
{ Rprimestruct[i] = Rprimestruct[i].add((Rprimestruct[a].subtract(TTprimestruct[a])).multiply((Rprimestruct[b].subtract(TTprimestruct[b])).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Rprimestereo[i] = Rprimestereo[i].add(((Rprimestereo[a].subtract(TTprimestereo[a])).multiply((Rprimestereo[b].subtract(TTprimestereo[b])).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))))).multiply(BigInteger.valueOf(2)));
}
if (a + b + c == i - 1 && a==0)
{ Rprimestruct[i] = Rprimestruct[i].add((Rprimestruct[a]).multiply((Rprimestruct[b]).multiply((Rprimestruct[c]))));
Rprimestereo[i] = Rprimestereo[i].add(((Rprimestereo[a]).multiply((Rprimestereo[b]).multiply((Rprimestereo[c])))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 0; c <= i - 1; c++)
{ for (a = 0; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a!=c && a!=0 && c!=0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))));
}
if (2 * a + c == (i - 1) && a!=c && a==0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a]).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c]))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a]), BigInteger.valueOf(2)))).multiply((Rprimestereo[c])));
}
if (2 * a + c == (i - 1) && a!=c && c==0)
{ Rprimestruct[i] = Rprimestruct[i].add(((Choose((Rprimestruct[a]).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c]))));
Rprimestereo[i] = Rprimestereo[i].add(((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a]), BigInteger.valueOf(2)))).multiply((Rprimestereo[c])));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Rprimestruct[i] = Rprimestruct[i].add((Choose((Rprimestruct[b].subtract(TTprimestruct[b])).add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Rprimestereo[i] = Rprimestereo[i].add((Choose((Rprimestereo[b].subtract(TTprimestereo[b])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[b].subtract(TTprimestereo[b])), BigInteger.valueOf(3))));
}
}
else
{ Rprimestruct[i] = Rstruct[i];
Rprimestereo[i] = Rstereo[i];
}
//Calculation of Tprime(i)
if (i >= 16)
{ Tprimestruct[i] = BigInteger.valueOf(0);
Tprimestereo[i] = BigInteger.valueOf(0);
for (c = 3; c <= i - 1; c++)
{ for (b = 2; b < c; b++)
{ for (a = 1; a < b; a++)
{ if (a + b + c == i - 1 && a!=0)
{ Tprimestruct[i] = Tprimestruct[i].add((Rprimestruct[a].subtract(TTprimestruct[a])).multiply((Rprimestruct[b].subtract(TTprimestruct[b])).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Tprimestereo[i] = Tprimestereo[i].add(((Rprimestereo[a].subtract(TTprimestereo[a])).multiply((Rprimestereo[b].subtract(TTprimestereo[b])).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 1; c <= i - 1; c++)
{ for (a = 1; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a!=c && a!=0 && c!=0)
{ Tprimestruct[i] = Tprimestruct[i].add(((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TTprimestruct[c])))));
Tprimestereo[i] = Tprimestereo[i].add(((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TTprimestereo[c]))));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
Tprimestruct[i] = Tprimestruct[i].add((Choose((Rprimestruct[b].subtract(TTprimestruct[b])).add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
Tprimestereo[i] = Tprimestereo[i].add((Choose((Rprimestereo[b].subtract(TTprimestereo[b])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[b].subtract(TTprimestereo[b])), BigInteger.valueOf(3))));
}
}
else
{ Tprimestruct[i] = Trstruct[i];
Tprimestereo[i] = Trstereo[i];
}
//TTprime(i)
TTprimestruct[i] = BigInteger.valueOf(0);
TTprimestereo[i] = BigInteger.valueOf(0);
if (i >= 13)
{ for (c = 6; c <= i - 1; c++)
{ for (b = 5; b < c; b++)
{ for (a = 4; a < b; a++)
{ if (a + b + c == i - 1)
{ TTprimestruct[i] = TTprimestruct[i].add(Tprimestruct[a].multiply(Tprimestruct[b].multiply(Tprimestruct[c])));
TTprimestereo[i] = TTprimestereo[i].add((Tprimestereo[a].multiply(Tprimestereo[b].multiply(Tprimestereo[c]))).multiply(BigInteger.valueOf(2)));
}
}
}
}
for (c = 4; c <= i - 1; c++)
{ for (a = 4; a <= ((i - 1) / 2); a++)
{ if (2 * a + c == (i - 1) && a != c)
{ TTprimestruct[i] = TTprimestruct[i].add(((Choose(Tprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Tprimestruct[c])));
TTprimestereo[i] = TTprimestereo[i].add(((Choose(Tprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).add(Choose(Tprimestereo[a], BigInteger.valueOf(2)))).multiply(Tprimestereo[c]));
}
}
}
if ((i - 1) % 3 == 0)
{ b = (i - 1) / 3;
TTprimestruct[i] = TTprimestruct[i].add((Choose(Tprimestruct[b].add(BigInteger.valueOf(2)),BigInteger.valueOf(3))));
TTprimestereo[i] = TTprimestereo[i].add((Choose(Tprimestereo[b].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Tprimestereo[b], BigInteger.valueOf(3))));
}
}
}
//CALCULATION OF T(n) - PAPER ISOMERS
//CALCULATION OF GOODB(n) - ISOMERS WHICH ARE NOT DISALLOWED BY CRITERION B
//TERM 1 - CENTROID EDGE
//n even
if(n%2==0)
{ a = n/2;
struct1=Choose(Rstruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
stereo1=Choose(Rstereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
GoodBstruct1=Choose(Rprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
GoodBstereo1=Choose(Rprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
}
else
//n odd
{ struct1=BigInteger.valueOf(0);
stereo1=BigInteger.valueOf(0);
GoodBstruct1=BigInteger.valueOf(0);
GoodBstereo1=BigInteger.valueOf(0);
}
//TERM 2 - ALL BRANCHES DIFFERENT SIZE
for (d=3; d<halfn; d++)
{ for (c=2; c<d; c++)
{ for (b=1; b<c; b++)
{ for(a=0; a<b; a++)
{ if (a+b+c+d==n-1)
{ struct2=struct2.add((Rstruct[a].multiply(Rstruct[b].multiply(Rstruct[c].multiply(Rstruct[d])))));
stereo2=stereo2.add(BigInteger.valueOf(2).multiply((Rstereo[a].multiply(Rstereo[b].multiply(Rstereo[c].multiply(Rstereo[d]))))));
GoodBstruct2=GoodBstruct2.add((Rprimestruct[a].multiply(Rprimestruct[b].multiply(Rprimestruct[c].multiply(Rprimestruct[d])))));
GoodBstereo2=GoodBstereo2.add(BigInteger.valueOf(2).multiply((Rprimestereo[a].multiply(Rprimestereo[b].multiply(Rprimestereo[c].multiply(Rprimestereo[d]))))));
}
}
}
}
}
//TERM 3 - A PAIR
for (d=1; d<halfn; d++)
{ for (c=0; c<d; c++)
{ for (a=0; a<n/2; a++)
{ if (2*a+c+d==n-1&&a!=c&&a!=d)
{ struct3=struct3.add((Choose(Rstruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rstruct[c].multiply(Rstruct[d])));
stereo3=stereo3.add((Choose(Rstereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rstereo[a], BigInteger.valueOf(2)))).multiply(Rstereo[c].multiply(Rstereo[d])));
GoodBstruct3=GoodBstruct3.add((Choose(Rprimestruct[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply(Rprimestruct[c].multiply(Rprimestruct[d])));
GoodBstereo3=GoodBstereo3.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose(Rprimestereo[a], BigInteger.valueOf(2)))).multiply(Rprimestereo[c].multiply(Rprimestereo[d])));
}
}
}
}
//TERM 4 - 2 PAIRS
//n odd
if(((n-1)%2)==0)
{ for (c=1; c<=halfn; c++)
{ for(a=0; a<c; a++)
{ if (2*a+2*c==n-1)
{ struct4=struct4.add(Choose((Rstruct[a].multiply(Rstruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
stereo4=stereo4.add((Choose(Rstereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose(Rstereo[c].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
GoodBstruct4=GoodBstruct4.add(Choose((Rprimestruct[a].multiply(Rprimestruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
GoodBstereo4=GoodBstereo4.add((Choose(Rprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose(Rprimestereo[c].add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
}
}
}
//n even
else
{ struct4=BigInteger.valueOf(0);
stereo4=BigInteger.valueOf(0);
GoodBstruct4=BigInteger.valueOf(0);
GoodBstereo4=BigInteger.valueOf(0);
}
//TERM 5 - 3 OF A KIND
for (d=0; d<halfn; d++)
{ for (a=0; a<halfn; a++)
{ if (3*a+d==n-1&&a!=d)
{ struct5=struct5.add(((Choose(Rstruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rstruct[d]));
stereo5=stereo5.add(((Choose(Rstereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rstereo[a], BigInteger.valueOf(3)))).multiply(Rstereo[d]));
GoodBstruct5=GoodBstruct5.add(((Choose(Rprimestruct[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d]));
GoodBstereo5=GoodBstereo5.add(((Choose(Rprimestereo[a].add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose(Rprimestereo[a], BigInteger.valueOf(3)))).multiply(Rprimestereo[d]));
}
}
}
//TERM 6 - ALL SAME SIZE
//only possible if n-1 is divisible by four
if (((n-1)%4)==0)
{ a=(n-1)/4;
struct6=(Choose(Rstruct[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
stereo6=(Choose(Rstereo[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose(Rstereo[a],BigInteger.valueOf(4))));
GoodBstruct6=(Choose(Rprimestruct[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
GoodBstereo6=(Choose(Rprimestereo[a].add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose(Rprimestereo[a],BigInteger.valueOf(4))));
}
else
{ struct6=BigInteger.valueOf(0);
stereo6=BigInteger.valueOf(0);
GoodBstruct6=BigInteger.valueOf(0);
GoodBstereo6=BigInteger.valueOf(0);
}
//CALCULATION OF BADC(n) - STRUCTURES DISALLOWED DUE TO BAD CENTROIDS (BUT ALLOWED BRANCHES)
//DISALLOWED CENTROIDS BELONG IN EITHER GROUP A1, A2 OR A3
if (n>=17)
{ //FIRST TERM - CENTROID EDGE
if(n%2==0)
{ if (n>=34)
{ a=n/2;
//REQUIRES AT LEAST ONE BRANCH TO BE TERTIARY-TERTIARY
//EITHER BOTH BRANCHES ARE DOUBLE TERTIARY
BadCstruct1=Choose(TTprimestruct[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
BadCstereo1=Choose(TTprimestereo[a].add(BigInteger.valueOf(1)),BigInteger.valueOf(2));
//OR ONE IS TERTIARY(BUT NOT DOUBLE TERTIARY) THE OTHER DOUBLE TERTIARY
BadCstruct1=BadCstruct1.add(TTprimestruct[a].multiply(Tprimestruct[a].subtract(TTprimestruct[a])));
BadCstereo1=BadCstereo1.add(TTprimestereo[a].multiply(Tprimestereo[a].subtract(TTprimestereo[a])));
}
}
else
//n odd
{ BadCstruct1=BigInteger.valueOf(0);
BadCstereo1=BigInteger.valueOf(0);
}
//TERM 2 - ALL BRANCHES DIFFERENT SIZE
for (d=4; d<halfn; d++)
{ for (c=3; c<d; c++)
{ for (b=2; b<c; b++)
{ for(a=1; a<b; a++)
{ if (a+b+c+d==n-1)
{ //ALL TERTIARY BUT NOT TT
if (a>=4)
{ BadCstruct2 = BadCstruct2.add(((Tprimestruct[a].subtract(TTprimestruct[a])).multiply((Tprimestruct[b].subtract(TTprimestruct[b])).multiply((Tprimestruct[c].subtract(TTprimestruct[c])).multiply((Tprimestruct[d].subtract(TTprimestruct[d])))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Tprimestereo[a].subtract(TTprimestereo[a])).multiply((Tprimestereo[b].subtract(TTprimestereo[b])).multiply((Tprimestereo[c].subtract(TTprimestereo[c])).multiply((Tprimestereo[d].subtract(TTprimestereo[d]))))))));
}
//AT LEAST ONE TT, OTHERS NON-ZERO
BadCstruct2 = BadCstruct2.add(((Rprimestruct[a]).multiply((Rprimestruct[b]).multiply((Rprimestruct[c]).multiply((Rprimestruct[d]))))));
BadCstereo2 = BadCstereo2.add(BigInteger.valueOf(2).multiply(((Rprimestereo[a]).multiply((Rprimestereo[b]).multiply((Rprimestereo[c]).multiply((Rprimestereo[d])))))));
BadCstruct2 = BadCstruct2.subtract(((Rprimestruct[a].subtract(TTprimestruct[a])).multiply((Rprimestruct[b].subtract(TTprimestruct[b])).multiply((Rprimestruct[c].subtract(TTprimestruct[c])).multiply((Rprimestruct[d].subtract(TTprimestruct[d])))))));
BadCstereo2 = BadCstereo2.subtract(BigInteger.valueOf(2).multiply(((Rprimestereo[a].subtract(TTprimestereo[a])).multiply((Rprimestereo[b].subtract(TTprimestereo[b])).multiply((Rprimestereo[c].subtract(TTprimestereo[c])).multiply((Rprimestereo[d].subtract(TTprimestereo[d]))))))));
}
}
}
}
}
//TERM 3 - A PAIR
for (d=2; d<halfn; d++)
{ for (c=1; c<d; c++)
{ for (a=1; a<n/2; a++)
{ if (2*a+c+d==n-1&&a!=c&&a!=d)
{ //ALL TERTIARY, BUT NO TT
if (a>=4&&c>=4)
{ BadCstruct3 = BadCstruct3.add((Choose((Tprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Tprimestruct[c].subtract(TTprimestruct[c])).multiply((Tprimestruct[d].subtract(TTprimestruct[d])))));
BadCstereo3 = BadCstereo3.add((Choose((Tprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Tprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Tprimestereo[c].subtract(TTprimestereo[c])).multiply(Tprimestereo[d].subtract(TTprimestereo[d]))));
}
//AT LEAST ONE TT, OTHERS NON-ZERO
BadCstruct3 = BadCstruct3.add((Choose((Rprimestruct[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Rprimestruct[c]).multiply((Rprimestruct[d]))));
BadCstereo3 = BadCstereo3.add((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Rprimestereo[a]), BigInteger.valueOf(2)))).multiply((Rprimestereo[c]).multiply(Rprimestereo[d])));
BadCstruct3 = BadCstruct3.subtract((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2))).multiply((Rprimestruct[c].subtract(TTprimestruct[c])).multiply((Rprimestruct[d].subtract(TTprimestruct[d])))));
BadCstereo3 = BadCstereo3.subtract((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(2)))).multiply((Rprimestereo[c].subtract(TTprimestereo[c])).multiply(Rprimestereo[d].subtract(TTprimestereo[d]))));
}
}
}
}
//TERM 4 - TWO PAIRS
if(((n-1)%2)==0)
{ for (c=2; c<=halfn; c++)
{ for(a=1; a<c; a++)
{ if (2*a+2*c==n-1)
{ //ALL TERTIARY BUT NO TT
if (a>=4&&c>=5)
{ BadCstruct4 = BadCstruct4.add(Choose(((Tprimestruct[a].subtract(TTprimestruct[a])).multiply(Tprimestruct[c].subtract(TTprimestruct[c]))).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.add((Choose((Tprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose((Tprimestereo[c].subtract(TTprimestereo[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
//AT LEAST ONE TT, OTHERS NON-ZERO
BadCstruct4 = BadCstruct4.add(Choose(((Rprimestruct[a]).multiply(Rprimestruct[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.add((Choose((Rprimestereo[a]).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose((Rprimestereo[c]).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
BadCstruct4 = BadCstruct4.subtract(Choose(((Rprimestruct[a].subtract(TTprimestruct[a])).multiply(Rprimestruct[c].subtract(TTprimestruct[c]))).add(BigInteger.valueOf(1)),BigInteger.valueOf(2)));
BadCstereo4 = BadCstereo4.subtract((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))).multiply(Choose((Rprimestereo[c].subtract(TTprimestereo[c])).add(BigInteger.valueOf(1)),BigInteger.valueOf(2))));
}
}
}
}
else
{ BadCstruct4=BigInteger.valueOf(0);
BadCstereo4=BigInteger.valueOf(0);
}
//TERM 5 - THREE OF A KIND
for (d=1; d<halfn; d++)
{ for (a=1; a<halfn; a++)
{ if (3*a+d==n-1&&a!=d)
{ //ALL TERTIARY, NO TT
if (a>=4&&d>=4)
{ BadCstruct5 = BadCstruct5.add(((Choose((Tprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Tprimestruct[d].subtract(TTprimestruct[d])));
BadCstereo5 = BadCstereo5.add(((Choose((Tprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Tprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(3)))).multiply((Tprimestereo[d].subtract(TTprimestereo[d]))));
}
//AT LEAST ONE TT, OTHERS NON-ZERO
BadCstruct5 = BadCstruct5.add(((Choose((Rprimestruct[a]).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d]));
BadCstereo5 = BadCstereo5.add(((Choose((Rprimestereo[a]).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[a]), BigInteger.valueOf(3)))).multiply((Rprimestereo[d])));
BadCstruct5 = BadCstruct5.subtract(((Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3)))).multiply(Rprimestruct[d].subtract(TTprimestruct[d])));
BadCstereo5 = BadCstereo5.subtract(((Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(2)), BigInteger.valueOf(3))).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])), BigInteger.valueOf(3)))).multiply((Rprimestereo[d].subtract(TTprimestereo[d]))));
}
}
}
//TERM 6 - ALL BRANCHES SAME SIZE
if (((n-1)%4)==0)
{ a=(n-1)/4;
//ALL TERTIARY, NO TT
BadCstruct6 =BadCstruct6.add(Choose((Tprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 =BadCstereo6.add(Choose((Tprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose((Tprimestereo[a].subtract(TTprimestereo[a])),BigInteger.valueOf(4))));
//AT LEAST ONE TT, OTHERS NON-ZERO
BadCstruct6 = BadCstruct6.add(Choose((Rprimestruct[a]).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 = BadCstereo6.add(Choose((Rprimestereo[a]).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose((Rprimestereo[a]),BigInteger.valueOf(4))));
BadCstruct6 = BadCstruct6.subtract(Choose((Rprimestruct[a].subtract(TTprimestruct[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)));
BadCstereo6 = BadCstereo6.subtract(Choose((Rprimestereo[a].subtract(TTprimestereo[a])).add(BigInteger.valueOf(3)),BigInteger.valueOf(4)).add(Choose((Rprimestereo[a].subtract(TTprimestereo[a])),BigInteger.valueOf(4))));
}
else
{ BadCstruct6=BigInteger.valueOf(0);
BadCstereo6=BigInteger.valueOf(0);
}
}
//SUMMATION OF INDIVIDUAL TERMS
//VIRTUAL ISOMERS
structuralisomers = struct1.add(struct2.add(struct3.add(struct4.add(struct5.add(struct6)))));
stereoisomers = stereo1.add(stereo2.add(stereo3.add(stereo4.add(stereo5.add(stereo6)))));
//ISOMERS WITH ALLOWED BRANCHES
GoodBstructuralisomers = GoodBstruct1.add(GoodBstruct2.add(GoodBstruct3.add(GoodBstruct4.add(GoodBstruct5.add(GoodBstruct6)))));
GoodBstereoisomers = GoodBstereo1.add(GoodBstereo2.add(GoodBstereo3.add(GoodBstereo4.add(GoodBstereo5.add(GoodBstereo6)))));
//ISOMERS WITH DISALLOWED CENTROIDS, ALLOWED BRANCHES
BadCstructuralisomers = BadCstruct1.add(BadCstruct2.add(BadCstruct3.add(BadCstruct4.add(BadCstruct5.add(BadCstruct6)))));
BadCstereoisomers = BadCstereo1.add(BadCstereo2.add(BadCstereo3.add(BadCstereo4.add(BadCstereo5.add(BadCstereo6)))));
//ALLOWED ISOMERS
Allowedstructuralisomers = GoodBstructuralisomers.subtract(BadCstructuralisomers);
Allowedstereoisomers = GoodBstereoisomers.subtract(BadCstereoisomers);
//////////////////////////////////////////////////////////End of Enumeration/////////////////////////////////////////////////
//TEXT OUTPUT IN GUI
double decimal = 0.0;
double nextdigit = 0.0;
String temp = "";
int ndigits = 0;
display2.append("C"+n+"H"+(2*n+2)+newline);
display2.append("--------------------------------------"+newline);
display2.append(structuralisomers+" ");
temp = structuralisomers.toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("possible structural isomers, EXCLUDING optical isomers "+newline);
display2.append(structuralisomers.subtract(Allowedstructuralisomers)+" ");
temp = (structuralisomers.subtract(Allowedstructuralisomers)).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("of these are sterically unfavourable"+newline);
display2.append("Leaving "+Allowedstructuralisomers+" ");
temp = (Allowedstructuralisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append(" allowed structural isomers"+newline);
display2.append("--------------------------------------"+newline);
display2.append(stereoisomers+" ");
temp = (stereoisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("possible structural isomers, INCLUDING optical isomers "+newline);
display2.append(stereoisomers.subtract(Allowedstereoisomers)+" ");
temp = (stereoisomers.subtract(Allowedstereoisomers)).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append("of these are sterically unfavourable"+newline);
display2.append("Leaving "+Allowedstereoisomers+" ");
temp = (Allowedstereoisomers).toString();
ndigits = temp.length();
if (ndigits>9)
{ decimal = Double.parseDouble(temp.substring(0,8));
nextdigit = Double.parseDouble(temp.substring(8,9));
if (nextdigit>=5.0)
{ decimal=decimal+1.0;
}
display2.append("("+(decimal/10000000)+" E"+(ndigits-1)+") ");
}
display2.append(" allowed structural isomers"+newline);
display2.append("//////////////////////////////////////"+newline);
display2.setCaretPosition(display2.getDocument().getLength());
}
} // end class IsocountApplet
|