Researcher/Affiliations

Total Page:16

File Type:pdf, Size:1020Kb

Researcher/Affiliations

Researcher/affiliations Aaron Caldwell, University of North Carolina Wilmington CSC 532 Tagliarini January 29, 2010

Abstract

The purpose of this project was to generate a set of “n” uniformly random numbers using a unary logic table (in this case using {0,1,2}) to produce all different combinations for a given set (A). Within A, all subsets that totaled to an amount differing from each other by no more than 0 or 1 were to be determined.

Given 15 uniformly random integers from 1 to 99, 1001 batches of 3 subsets were found within 14 seconds.

As a contrast, given 22 uniformly random integers from 1 to 99, 110,000 subsets were found within 40 minutes (and the program was still running).

1. Introduction Much like a binary logic value table, a unary logic table may be generated given an understanding of its pattern. The following pattern for a unary logic table of {0,1,2} was noted:

0 0 0 1 0 0 2 0 0 0 1 0 1 1 0 2 1 0 0 2 0 1 2 0 2 2 0

In order to understand and implement the unary pattern, the programmer should note that each sequence (column) is an alternating pattern of 3^0, 3^1, 3^2…..3^n. Using this unary logic value table and correlating it with a table (or array) of uniformly random values allows a program to cycle through all unique combinations of the numbers provided.

2. Background This experiment was essentially an extension of a previously implemented binary logic table. By providing a larger array {0,1,2} of variables for the logic table vs. the original one {0,1} a new method was built based upon the logic of the previous method.

For each “cycle of alternation” of a column in a unary table, the next cycle of alternation should occur 3^(n+1) times. Performing this operations required recursion combined with a loop and an if/else statement to determine whether or not to end the recursion at the base case. This program’s design improved upon the original logic table program design by “outsourcing” operations to methods whenever possible. This improvement made it easier to view the fundamental logic of the algorithm and allows easier interchangeability should a programmer wish to examine a unary logic table for more variables than {0,1,2}.

3. Experimental Design Within Java, two arrays of a user determined size “n” were created. One array was assigned uniformly random integers from 1-99 and the other array will act as a temporary holding location for each line in the logic table.

Unary values, arranged in lines within the logic value table, were generated using a combination of recursion, an if/else statement and a for loop. Recursion allowed for generation of all binary combinations up to 3^n. The if/else statement determined whether or not each recursive cycle was the base case. In order to conserver one step, the base case was the “else” since the base case is the case the minority of the time. The for loop cycled between values of 0, 1 and 2 for each independent variable.

For each line in the logic table a temporary array stored values to a subset from the random set. More specifically, a value of 0, 1 or 2 in a line from the logic table instructed a temporary array to record values from the corresponding locations of an array of uniform random integers. These values were each recorded in subset 0, subset 1 and subset 2 respectively. With the completion of a row, the sum of each subset was tallied and compared to each other. All subsets for each line that totaled to values differing by no more than 0 or 1 were printed to the screen and counted in “batches”. 4. Findings For any given set of “randoms” in the 1-99 range, the total values of subsets would hold steady producing the same amount + or – 1. The number of batches of matched subsets seemed to be the greatest when requesting 3 subsets from around 20-27 randoms. Smaller amounts of random numbers (n<12) rarely had matching subsets, large amounts of randoms (n>27) seemed to run indefinitely.

Some degree of duplication was inherent to this algorithm since a given subset might match more than just 2 other subsets. One given subset A might match B and C but then it was observed that the same subset A would be repeated and match the new different subsets B and C. Also, the numbers present in one subset would be seen again in a different subset. Whether or not this was acceptable duplication might depend on the intent of the program. For example if one were tracking the way populations of animals move, it might be relevant to see when variables (animals) were present in different subsets (regions). The question is: are we seeking numbers in a subset or numbers as a function of a subset?

5. Conclusions Much like the initial logic value program this set of randomly uniform integers produced a widely varying number of subsets depending on the value “n” uniformly random integers. The unary logic program was noticeably slower than the binary logic program given the exponentially more burdensome possibilities given 3 variables instead of 2.

6. Future work It might be interesting to chart the numbers obtained by requesting different numbers of subsets and also to chart the varying number of batches produced for different values of n.

7. References The following students in the class were valuable resources both for their in-class presentations and their helpful hints outside of class:

Mike Komisin Brian Satz Andy Herrmann

Recommended publications