bigOpera
Class BigOpera

java.lang.Object
  extended by bigOpera.BigOpera
All Implemented Interfaces:
java.io.Serializable

public class BigOpera
extends java.lang.Object
implements java.io.Serializable

List numbers by counting the number of ones needed to construct those numbers using the bigO(int, int, int) method and positive integers.

Version:
Bèta 2008/07/04 cannot restart with serialized data
Author:
Fava
See Also:
Serialized Form

Field Summary
private  int[] abLimits
          Default limits to decide when to reduce the operator number c for good.
private  int[] B_MAX
          Array with absolute maximum values b for each c.
(package private)  int cMax
          Maximum operator number.
(package private)  int[][] data
          Simple integer array to store the result data.
(package private)  double obitDeviationTotal
          Sum of deviations of the Obit length from the mean of Obit lengths.
static java.lang.String[] OPERATORS
          Array of supported operators as Strings.
(package private)  boolean PREFER_LOWER_C
          Prefer to record and display those equations that have the lowest c when fingers are equal.
 int PRINT_MULTI_STATS
          Print the totals and gains every 1000th multiple of PRINT_MULTI_STATS inbetween.
 boolean PRINT_OBITS
          Print a second line with the experimental mathematical "Obit" representation of a number.
 java.lang.String serialPath
          File path to serialize this BigOpera object.
(package private) static long serialVersionUID
          The ID 7625597484987L for serialization of this class.
private  java.io.BufferedWriter textWriter
          Writer for storing the console data directly in a user specified file.
(package private)  long[] totals
          Cummulative totals for Vingers values V and bigO stack values W.
(package private)  int Y_MAX
          An absolute maximum set to the results of bigO that can be recorded.
private  int[] yNextVn
          Array to keep track of cummulative Vingers "number of ones" data in the list.
private  int[] yNextWn
          Array to keep track of cummulative bigO stack data in the list.
 
Constructor Summary
BigOpera()
          Default constructor.
 
Method Summary
static int bigO(int a, int b, int c)
          Calculate bigO(a,b,c) for integer types.
 void buildNumbers(int yEnd)
          Start building numbers from where you've ended last time.
static void main(java.lang.String[] args)
          Console method to use this class.
 java.lang.String OBitExpression(int n)
          Get a bigO mathematical bit expression (or "Obit") for a number.
private  void print(java.lang.String line)
          Print some text to the console.
 void printData(int y)
          Print data for the next number constructions with the bigO equation.
 void printFooter(int y)
          Create and print the footer with the totals and statistical percentages.
 void printHeader()
          Create and print the header for the results of bigO equations.
(package private)  void setData(int a, int b, int c, int y)
          Check if a candidate solution for bigO can be stored in the data array.
(package private)  int setModel(int yEnd)
          Set up the data model to store and display new results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialPath

public java.lang.String serialPath
File path to serialize this BigOpera object.
Set to null if serialization is unwanted. Default is "BigOpera.bin"


PRINT_MULTI_STATS

public int PRINT_MULTI_STATS
Print the totals and gains every 1000th multiple of PRINT_MULTI_STATS inbetween.
BigOpera always prints stats at the bottom of the list, even if endY is not a multiple.


PRINT_OBITS

public boolean PRINT_OBITS
Print a second line with the experimental mathematical "Obit" representation of a number.
Eg. 12 = 111111111111
15 = O(3,5,1) = 0111011111011
23 = O(3,O(4,5,1)) = 011100111101111101101
226 = 01000111011111011011011101


PREFER_LOWER_C

boolean PREFER_LOWER_C
Prefer to record and display those equations that have the lowest c when fingers are equal.
By default set to false the order of creation prevails, which favors higher c. The default also minimizes the construction stack counts, eg. 16 9 8 8 2^^3 7 5 4
As less wide c are as yet unrecorded, only the widest fields are effected by this flag.


OPERATORS

public static java.lang.String[] OPERATORS
Array of supported operators as Strings. That is all positive operators { +, *, ^, ^^ }
Call with c as index.


Y_MAX

int Y_MAX
An absolute maximum set to the results of bigO that can be recorded.

An Integer.MAX_VALUE number of integers takes 2^31*4bytes = 8Gb
So it's wise to set it lower. The default is:
Y_MAX = 2097152 => Y_MAX*data.length = 8Mb*6 = 48Mb
Beware: printed data for endY==1000000 contains hundreds of megabytes!


cMax

int cMax
Maximum operator number. Given a maximum of a+b where a>1.
Initially when a+b<11 this cMax = 3 or ^^ because 2^^4 = 2^16 = 65536 = 2^^^3 (same Vingers value too) and 9^^2 = 9^9 = 387420489 and 10^10 > Integer.MAX_VALUE
Then when a+b<33 this is 2 because 2^31 = Integer.MAX_VALUE+1


B_MAX

private int[] B_MAX
Array with absolute maximum values b for each c.
B_MAX = { 524286, 262143, 18, 4 }


abLimits

private int[] abLimits
Default limits to decide when to reduce the operator number c for good. Can be adapted to yEnd later.
If ab in the construction loop gets bigger put cMax--
abLimits[2] for ^ powers is the maximal root plus 2.


serialVersionUID

static final long serialVersionUID
The ID 7625597484987L for serialization of this class.

See Also:
Constant Field Values

textWriter

private java.io.BufferedWriter textWriter
Writer for storing the console data directly in a user specified file. Currently this BufferedWriter is not constructed to append text.

See Also:
main(java.lang.String[]), print(java.lang.String)

data

int[][] data
Simple integer array to store the result data. Keeps the number of Java array objects on the heap to a minimum.
Assigns different data to each primary indexes as follows:
  1. The Vingers value V1 for +*   is the number of ones needed to create a number with + and *
  2. V2 for +*^   is the number of ones needed to create a number with c={0,1,2}
  3. Vn for +*^..   is the number of ones needed to create a number with c>=0
  4. a   first operant in last equation with least V
  5. b   second operant in last equation with least V
  6. c   operator number of last equation with least V
  7. Counts the number of bigO operations W1 passed in its +* construction stack.
  8. Counts the number of bigO operations W2 passed in its +*^ construction stack.
  9. Counts the number of bigO operations Wn passed in its widest +*^.. construction stack.
The array is initialized with data of number 0 and 1 (printing starts at one). Increase the array size when needed, with setModel(int).


totals

long[] totals
Cummulative totals for Vingers values V and bigO stack values W. From these the percentage gain from allowing a wider operator can be calculated.
totals is indexed as follows:
  1. Data total of V1 for +*
  2. Data total of V2 for +*^
  3. Data total of Vn for +*^..
  4. Data total of W1 for +*
  5. Data total of W2 for +*^
  6. Data total of Wn for +*^..
  7. The total String length of the Obit number representations.


obitDeviationTotal

double obitDeviationTotal
Sum of deviations of the Obit length from the mean of Obit lengths.
Build the total deviation from the mean as we go at printData(int) to display Obit trends at each call to printFooter(int).


yNextVn

private int[] yNextVn
Array to keep track of cummulative Vingers "number of ones" data in the list. Index 0 be y, index 1 be the highest widest V value thus far. Set to highlight "~" the start of higher V at number y in printData(int).


yNextWn

private int[] yNextWn
Array to keep track of cummulative bigO stack data in the list. Index 0 be y, index 1 be the highest widest W value thus far. Set to highlight "~" the start of higher W at number y in printData(int).

Constructor Detail

BigOpera

public BigOpera()
Default constructor.

Method Detail

setModel

int setModel(int yEnd)
Set up the data model to store and display new results.
Prints header for new data. Increases the array size of the secondary arrays of data to accomodate more numbers.

Parameters:
yEnd - the last result as to be calculated by buildNumbers(int).
Returns:
index if the model was set up and can be expanded by new data
-1 if all data upto yEnd has already been collected
Throws:
java.lang.IllegalArgumentException - if yEnd > Y_MAX

buildNumbers

public void buildNumbers(int yEnd)
Start building numbers from where you've ended last time.

Parameters:
yEnd - the result y = bigO(a,b,c) upto where to build number space

setData

void setData(int a,
             int b,
             int c,
             int y)
Check if a candidate solution for bigO can be stored in the data array.
If a solution uses less Vingers in its "minimum operant" construction setData() stores it for all operants >= c

Parameters:
a - first bigO operant
b - second bigO operant
c - bigO operator number
y - the result y = bigO(a,b,c)

bigO

public static int bigO(int a,
                       int b,
                       int c)
Calculate bigO(a,b,c) for integer types.

Parameters:
a - first number
b - second number
c - operator number
Returns:
the result as an int number,
or Integer.MAX_VALUE = 2^31-1 = 2147483647 if the result is too big or Integer.MIN_VALUE = -2^31 = -2147483648 if the result is too small
Throws:
java.lang.ArithmeticException - if the calculation is impossible or unsupported or if the result is not exactly integer
Note that ^... operations never throw this exception for positive b

printHeader

public void printHeader()
Create and print the header for the results of bigO equations.
Does not print initial data.


printData

public void printData(int y)
Print data for the next number constructions with the bigO equation.

Parameters:
y - the data for number y that has to printed next
Throws:
java.lang.IllegalStateException - if data is missing

printFooter

public void printFooter(int y)
Create and print the footer with the totals and statistical percentages.

Parameters:
y - can be the yEnd or some inbetween statistics request

print

private void print(java.lang.String line)
Print some text to the console.

Parameters:
line - one or two lines of text

OBitExpression

public java.lang.String OBitExpression(int n)
Get a bigO mathematical bit expression (or "Obit") for a number.
A small enough number will be a straight String of ones, eg. "5 = 11111", but larger numbers have a more succint mathematical expression starting with the prefix "0" to distinguish a matBit number that's created with bigO.
Each bigO has 3 arguments, where c is expressed as: 1=+ 11=* 111=^ 1111=^^ 11111=^^^
A series of "0" means a nesting of bigO inside itself, as in 30 = 3+3^3 = 0111001110111011101
This is a test method - a binary bit representation of an integer will usually be smaller, eg. 30 = 11110

Parameters:
n - any natural number n >= 0
Returns:
the expression in "mathematical bits" where every zero is a comma and every one adds 1 to a number.
Throws:
java.lang.IllegalArgumentException - if n > MIN_ONES and no data is available for it (MIN_ONES = 26)

main

public static void main(java.lang.String[] args)
Console method to use this class.

If the serialPath is specified this method tries to deserialize a file, and serializes a file at serialPath with all data when it's done.

Parameters:
args - the 1st argument should be an end number yEnd,
the 2nd optional argument is a file path to store data as text, like so:
java bigOpera/BigOpera 10000 "operadata.txt"
Throws:
java.lang.SecurityException - if the security manager doesn't allow files to be read