Optimizing a function

``````void setup(){
size(256,256);
stroke(255);
for(int i=0;i<65536;i++){
int x=i&255;
int y=i>>8;
float v=boh(x/127.5-1f,y/127.5-1f);
set(x,y,color(v*100,0,200-v*100));
}
float x1=1f;
float x2=-1f;
float c=1e30;
Rnd256 r=new Rnd256();
for(int i=0;i<1000;i++){
float m1=x1+r.mutate();
float m2=x2+r.mutate();
float cm=boh(m1,m2);
if(cm<c){
c=cm;
line((x1+1f)*127.5f,(x2+1f)*127.5f,(m1+1f)*127.5f,(m2+1f)*127.5f);
x1=m1;
x2=m2;
}
}
println(boh(x1,x2));
}
// Bohachevsky function
// min -5.9604645E-8 at 0,0
float boh(float x1,float x2){
return x1*x1+2f*x2*x2-0.3f*cos(3*PI*x1)-0.4f*cos(4*PI*x2)+0.7f;
}

final class Rnd256 {
final long PHI = 0x9E3779B97F4A7C15L;
private long s0, s1, s2, s3;
Rnd256() {
this(System.nanoTime());
}
Rnd256(long seed) {
s0=staffordMix13(seed+PHI);
s1=staffordMix13(seed+2*PHI);
s2=staffordMix13(seed+3*PHI);
s3=staffordMix13(seed+4*PHI);
}
long nextLong() {
long result = s1;
result = Long.rotateLeft(result + (result << 2), 7);
result += result << 3;
final long t = s1 << 17;
s2 ^= s0;
s3 ^= s1;
s1 ^= s2;
s0 ^= s3;
s2 ^= t;
s3 = Long.rotateLeft(s3, 45);
return result;
}
float nextFloat() {
return (nextLong() >>> 40) * 5.9604645E-8f;
}
boolean nextBoolean() {
return nextLong() < 0;
}
int nextIntEx(int ex) {
long r=(nextLong()>>>32)*ex;
return (int)(r>>>32);
}
int nextIntInc(int inc) {
long r=(nextLong()>>>32)*(inc+1L);
return (int)(r>>>32);
}
float mutate() {
int r=(int)nextLong();
r &=0xbfff_ffff;
r |=0x3000_0000;
return Float.intBitsToFloat(r);
}
long staffordMix13(long z) {
z = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9L;
z = (z ^ (z >>> 27)) * 0x94D049BB133111EBL;
return z ^ (z >>> 31);
}
}
``````