codesimian
Class Primes

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.Primes
All Implemented Interfaces:
CodeSimian

public class Primes
extends DefaultCS

contains static functions relevant to PRIME NUMBERS

RANDOM PRIME NUMBER STUFF:

-2 and 0 and 2 are prime. A prime is a number that can not be divided (without a remainder) by any prime less-or-equal than its square-root.

If your goal is to find the largest prime you can, it may be a good idea to square the biggest prime and iterate down from it until you find a prime. Its useless to calculate the primes between the largest prime calculated + 1 and its square - 1, and possibly without the 1s.


Nested Class Summary
static class Primes.DoesItKnowPrimesByIndex
          needs to be tested
 
Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Constructor Summary
Primes()
           
 
Method Summary
 double cost()
          cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively.
 boolean createNewPrimesArray(int quantityOfPrimes)
           
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          Execute this CS and cast to double.
static long[] getPrimes(long indexOfFirstPrimeToReturn, int quantity)
          The prime number 2 is at index 0.
static long[] intArrayToLongArray(int[] a)
           
static boolean isPrime(long possiblePrime)
          Returns with 100% accuracy, true if possiblePrime is a prime number, and false if not.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
static int[] longArrayToIntArray(long[] a)
           
static long nextPrime(long greaterThanThis)
          returns the smallest prime number that is larger than greaterThanThis
 boolean setD(double value)
          all setX functions return setD by default.
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, minP, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setP, setPrevExec, setPType, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Primes

public Primes()
Method Detail

getPrimes

public static long[] getPrimes(long indexOfFirstPrimeToReturn,
                               int quantity)
The prime number 2 is at index 0. 3 is at index 1. 5 is at index 2. 7 is at index 3... example: getPrimes(2,6) returns new long[]{5,7,11,13,17,19}

The method of calculating is, for every number, to check if that number is divisible by 2, then check divisible by 3, then check divisible by 5... It starts at the lowest prime calculated so far and stops when it is divisible or the current prime is more than the square root of the number being tested.

WARNING: I am not an expert on prime numbers. There are much faster ways to calculate primes than this function uses.

TO SAVE MEMORY AND TIME, this function should be modified to only calculate primes up to the square root of the last prime requested (), skip a lot of primes, and start calculating primes at int index (index is quantity of primes not a prime value). The last prime requested can probably be proven to be below a certain equation containing int quantity. Then leave most of this paragraph in the javadoc.


longArrayToIntArray

public static int[] longArrayToIntArray(long[] a)

intArrayToLongArray

public static long[] intArrayToLongArray(int[] a)

isPrime

public static boolean isPrime(long possiblePrime)
Returns with 100% accuracy, true if possiblePrime is a prime number, and false if not. This function can theoretically be evolved by CodeSimian for efficiency, when that system is finished.


nextPrime

public static long nextPrime(long greaterThanThis)
returns the smallest prime number that is larger than greaterThanThis


createNewPrimesArray

public boolean createNewPrimesArray(int quantityOfPrimes)

DForProxy

public double DForProxy()
Description copied from class: CS
Execute this CS and cast to double.

D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, return DForProxy cast to their own type.

For example, J() calls the proxy which calls JForProxy() which calls DForProxy(). D() calls the proxy which calls DForProxy().

By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()

Specified by:
DForProxy in class DefaultCS

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

cost

public double cost()
Description copied from class: CS
cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively. The INTERNAL cost.

One unit of myFuel() costs cost() units of fuel(). Beware of CSs that counterfeit fuel.

Returns 1 by default.

Overrides:
cost in class CS

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

setD

public boolean setD(double value)
Description copied from class: DefaultCS
all setX functions return setD by default. setD returns false by default. Override in subclass. For example, class N has a public variable value, and N.value is set to setToThisValue.

Overrides:
setD in class DefaultCS